Initial Sample.
This commit is contained in:
7
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.d.ts
generated
vendored
Normal file
7
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Observable } from "../../index.js";
|
||||
import type { CreateMultipartSubscriptionOptions } from "../shared.js";
|
||||
export declare function createFetchMultipartSubscription(uri: string, { fetch: preferredFetch, headers }?: CreateMultipartSubscriptionOptions): ({ query, variables, }: {
|
||||
query?: string | undefined;
|
||||
variables: undefined | Record<string, any>;
|
||||
}) => Observable<unknown>;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
40
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.js
generated
vendored
Normal file
40
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Observable } from "../../index.js";
|
||||
import { handleError, readMultipartBody, } from "../../../link/http/parseAndCheckHttpResponse.js";
|
||||
import { maybe } from "../../index.js";
|
||||
import { serializeFetchParameter } from "../../../core/index.js";
|
||||
import { generateOptionsForMultipartSubscription } from "../shared.js";
|
||||
var backupFetch = maybe(function () { return fetch; });
|
||||
export function createFetchMultipartSubscription(uri, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, preferredFetch = _b.fetch, headers = _b.headers;
|
||||
return function multipartSubscriptionForwarder(_a) {
|
||||
var query = _a.query, variables = _a.variables;
|
||||
var body = { variables: variables, query: query };
|
||||
var options = generateOptionsForMultipartSubscription(headers || {});
|
||||
return new Observable(function (observer) {
|
||||
try {
|
||||
options.body = serializeFetchParameter(body, "Payload");
|
||||
}
|
||||
catch (parseError) {
|
||||
observer.error(parseError);
|
||||
}
|
||||
var currentFetch = preferredFetch || maybe(function () { return fetch; }) || backupFetch;
|
||||
var observerNext = observer.next.bind(observer);
|
||||
currentFetch(uri, options)
|
||||
.then(function (response) {
|
||||
var _a;
|
||||
var ctype = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
||||
if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
|
||||
return readMultipartBody(response, observerNext);
|
||||
}
|
||||
observer.error(new Error("Expected multipart response"));
|
||||
})
|
||||
.then(function () {
|
||||
observer.complete();
|
||||
})
|
||||
.catch(function (err) {
|
||||
handleError(err, observer);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.js.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utilities/subscriptions/urql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,iBAAiB,GAClB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,uCAAuC,EAAE,MAAM,cAAc,CAAC;AAGvE,IAAM,WAAW,GAAG,KAAK,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;AAEvC,MAAM,UAAU,gCAAgC,CAC9C,GAAW,EACX,EAA2E;QAA3E,qBAAyE,EAAE,KAAA,EAAlE,cAAc,WAAA,EAAE,OAAO,aAAA;IAEhC,OAAO,SAAS,8BAA8B,CAAC,EAM9C;YALC,KAAK,WAAA,EACL,SAAS,eAAA;QAKT,IAAM,IAAI,GAAS,EAAE,SAAS,WAAA,EAAE,KAAK,OAAA,EAAE,CAAC;QACxC,IAAM,OAAO,GAAG,uCAAuC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QAEvE,OAAO,IAAI,UAAU,CAAC,UAAC,QAAQ;YAC7B,IAAI,CAAC;gBACH,OAAO,CAAC,IAAI,GAAG,uBAAuB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAC1D,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC7B,CAAC;YAED,IAAM,YAAY,GAAG,cAAc,IAAI,KAAK,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,IAAI,WAAW,CAAC;YACzE,IAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAElD,YAAa,CAAC,GAAG,EAAE,OAAO,CAAC;iBACxB,IAAI,CAAC,UAAC,QAAQ;;gBACb,IAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,OAAO,0CAAE,GAAG,CAAC,cAAc,CAAC,CAAC;gBAEpD,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACvD,OAAO,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;gBACnD,CAAC;gBAED,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC;iBACD,IAAI,CAAC;gBACJ,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACtB,CAAC,CAAC;iBACD,KAAK,CAAC,UAAC,GAAQ;gBACd,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Observable } from \"../../index.js\";\nimport {\n handleError,\n readMultipartBody,\n} from \"../../../link/http/parseAndCheckHttpResponse.js\";\nimport { maybe } from \"../../index.js\";\nimport { serializeFetchParameter } from \"../../../core/index.js\";\nimport type { Body } from \"../../../link/http/selectHttpOptionsAndBody.js\";\nimport { generateOptionsForMultipartSubscription } from \"../shared.js\";\nimport type { CreateMultipartSubscriptionOptions } from \"../shared.js\";\n\nconst backupFetch = maybe(() => fetch);\n\nexport function createFetchMultipartSubscription(\n uri: string,\n { fetch: preferredFetch, headers }: CreateMultipartSubscriptionOptions = {}\n) {\n return function multipartSubscriptionForwarder({\n query,\n variables,\n }: {\n query?: string;\n variables: undefined | Record<string, any>;\n }) {\n const body: Body = { variables, query };\n const options = generateOptionsForMultipartSubscription(headers || {});\n\n return new Observable((observer) => {\n try {\n options.body = serializeFetchParameter(body, \"Payload\");\n } catch (parseError) {\n observer.error(parseError);\n }\n\n const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;\n const observerNext = observer.next.bind(observer);\n\n currentFetch!(uri, options)\n .then((response) => {\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n }\n\n observer.error(new Error(\"Expected multipart response\"));\n })\n .then(() => {\n observer.complete();\n })\n .catch((err: any) => {\n handleError(err, observer);\n });\n });\n };\n}\n"]}
|
||||
8
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/package.json
generated
vendored
Normal file
8
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@apollo/client/utilities/subscriptions/urql",
|
||||
"type": "module",
|
||||
"main": "urql.cjs",
|
||||
"module": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"sideEffects": false
|
||||
}
|
||||
365
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs
generated
vendored
Normal file
365
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs
generated
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var utilities = require('../..');
|
||||
var tslib = require('tslib');
|
||||
var utils = require('../../../link/utils');
|
||||
var errors = require('../../../errors');
|
||||
var core = require('../../../core');
|
||||
|
||||
function asyncIterator(source) {
|
||||
var _a;
|
||||
var iterator = source[Symbol.asyncIterator]();
|
||||
return _a = {
|
||||
next: function () {
|
||||
return iterator.next();
|
||||
}
|
||||
},
|
||||
_a[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
},
|
||||
_a;
|
||||
}
|
||||
|
||||
function nodeStreamIterator(stream) {
|
||||
var cleanup = null;
|
||||
var error = null;
|
||||
var done = false;
|
||||
var data = [];
|
||||
var waiting = [];
|
||||
function onData(chunk) {
|
||||
if (error)
|
||||
return;
|
||||
if (waiting.length) {
|
||||
var shiftedArr = waiting.shift();
|
||||
if (Array.isArray(shiftedArr) && shiftedArr[0]) {
|
||||
return shiftedArr[0]({ value: chunk, done: false });
|
||||
}
|
||||
}
|
||||
data.push(chunk);
|
||||
}
|
||||
function onError(err) {
|
||||
error = err;
|
||||
var all = waiting.slice();
|
||||
all.forEach(function (pair) {
|
||||
pair[1](err);
|
||||
});
|
||||
!cleanup || cleanup();
|
||||
}
|
||||
function onEnd() {
|
||||
done = true;
|
||||
var all = waiting.slice();
|
||||
all.forEach(function (pair) {
|
||||
pair[0]({ value: undefined, done: true });
|
||||
});
|
||||
!cleanup || cleanup();
|
||||
}
|
||||
cleanup = function () {
|
||||
cleanup = null;
|
||||
stream.removeListener("data", onData);
|
||||
stream.removeListener("error", onError);
|
||||
stream.removeListener("end", onEnd);
|
||||
stream.removeListener("finish", onEnd);
|
||||
stream.removeListener("close", onEnd);
|
||||
};
|
||||
stream.on("data", onData);
|
||||
stream.on("error", onError);
|
||||
stream.on("end", onEnd);
|
||||
stream.on("finish", onEnd);
|
||||
stream.on("close", onEnd);
|
||||
function getNext() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (error)
|
||||
return reject(error);
|
||||
if (data.length)
|
||||
return resolve({ value: data.shift(), done: false });
|
||||
if (done)
|
||||
return resolve({ value: undefined, done: true });
|
||||
waiting.push([resolve, reject]);
|
||||
});
|
||||
}
|
||||
var iterator = {
|
||||
next: function () {
|
||||
return getNext();
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function promiseIterator(promise) {
|
||||
var resolved = false;
|
||||
var iterator = {
|
||||
next: function () {
|
||||
if (resolved)
|
||||
return Promise.resolve({
|
||||
value: undefined,
|
||||
done: true,
|
||||
});
|
||||
resolved = true;
|
||||
return new Promise(function (resolve, reject) {
|
||||
promise
|
||||
.then(function (value) {
|
||||
resolve({ value: value, done: false });
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function readerIterator(reader) {
|
||||
var iterator = {
|
||||
next: function () {
|
||||
return reader.read();
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function isNodeResponse(value) {
|
||||
return !!value.body;
|
||||
}
|
||||
function isReadableStream(value) {
|
||||
return !!value.getReader;
|
||||
}
|
||||
function isAsyncIterableIterator(value) {
|
||||
return !!(utilities.canUseAsyncIteratorSymbol &&
|
||||
value[Symbol.asyncIterator]);
|
||||
}
|
||||
function isStreamableBlob(value) {
|
||||
return !!value.stream;
|
||||
}
|
||||
function isBlob(value) {
|
||||
return !!value.arrayBuffer;
|
||||
}
|
||||
function isNodeReadableStream(value) {
|
||||
return !!value.pipe;
|
||||
}
|
||||
function responseIterator(response) {
|
||||
var body = response;
|
||||
if (isNodeResponse(response))
|
||||
body = response.body;
|
||||
if (isAsyncIterableIterator(body))
|
||||
return asyncIterator(body);
|
||||
if (isReadableStream(body))
|
||||
return readerIterator(body.getReader());
|
||||
if (isStreamableBlob(body)) {
|
||||
return readerIterator(body.stream().getReader());
|
||||
}
|
||||
if (isBlob(body))
|
||||
return promiseIterator(body.arrayBuffer());
|
||||
if (isNodeReadableStream(body))
|
||||
return nodeStreamIterator(body);
|
||||
throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
|
||||
}
|
||||
|
||||
function isNonNullObject(obj) {
|
||||
return obj !== null && typeof obj === "object";
|
||||
}
|
||||
|
||||
function isApolloPayloadResult(value) {
|
||||
return isNonNullObject(value) && "payload" in value;
|
||||
}
|
||||
|
||||
function readMultipartBody(response, nextValue) {
|
||||
var _a;
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
|
||||
var _c, _d;
|
||||
return tslib.__generator(this, function (_e) {
|
||||
switch (_e.label) {
|
||||
case 0:
|
||||
if (TextDecoder === undefined) {
|
||||
throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
|
||||
}
|
||||
decoder = new TextDecoder("utf-8");
|
||||
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
||||
delimiter = "boundary=";
|
||||
boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?
|
||||
contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
|
||||
: "-";
|
||||
boundary = "\r\n--".concat(boundaryVal);
|
||||
buffer = "";
|
||||
iterator = responseIterator(response);
|
||||
running = true;
|
||||
_e.label = 1;
|
||||
case 1:
|
||||
if (!running) return [3 , 3];
|
||||
return [4 , iterator.next()];
|
||||
case 2:
|
||||
_b = _e.sent(), value = _b.value, done = _b.done;
|
||||
chunk = typeof value === "string" ? value : decoder.decode(value);
|
||||
searchFrom = buffer.length - boundary.length + 1;
|
||||
running = !done;
|
||||
buffer += chunk;
|
||||
bi = buffer.indexOf(boundary, searchFrom);
|
||||
while (bi > -1) {
|
||||
message = void 0;
|
||||
_c = [
|
||||
buffer.slice(0, bi),
|
||||
buffer.slice(bi + boundary.length),
|
||||
], message = _c[0], buffer = _c[1];
|
||||
i = message.indexOf("\r\n\r\n");
|
||||
headers = parseHeaders(message.slice(0, i));
|
||||
contentType_1 = headers["content-type"];
|
||||
if (contentType_1 &&
|
||||
contentType_1.toLowerCase().indexOf("application/json") === -1) {
|
||||
throw new Error("Unsupported patch content type: application/json is required.");
|
||||
}
|
||||
body = message.slice(i);
|
||||
if (body) {
|
||||
result = parseJsonBody(response, body);
|
||||
if (Object.keys(result).length > 1 ||
|
||||
"data" in result ||
|
||||
"incremental" in result ||
|
||||
"errors" in result ||
|
||||
"payload" in result) {
|
||||
if (isApolloPayloadResult(result)) {
|
||||
next = {};
|
||||
if ("payload" in result) {
|
||||
next = tslib.__assign({}, result.payload);
|
||||
}
|
||||
if ("errors" in result) {
|
||||
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
|
||||
}
|
||||
nextValue(next);
|
||||
}
|
||||
else {
|
||||
nextValue(result);
|
||||
}
|
||||
}
|
||||
else if (
|
||||
Object.keys(result).length === 1 &&
|
||||
"hasNext" in result &&
|
||||
!result.hasNext) {
|
||||
return [2 ];
|
||||
}
|
||||
}
|
||||
bi = buffer.indexOf(boundary);
|
||||
}
|
||||
return [3 , 1];
|
||||
case 3: return [2 ];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function parseHeaders(headerText) {
|
||||
var headersInit = {};
|
||||
headerText.split("\n").forEach(function (line) {
|
||||
var i = line.indexOf(":");
|
||||
if (i > -1) {
|
||||
var name_1 = line.slice(0, i).trim().toLowerCase();
|
||||
var value = line.slice(i + 1).trim();
|
||||
headersInit[name_1] = value;
|
||||
}
|
||||
});
|
||||
return headersInit;
|
||||
}
|
||||
function parseJsonBody(response, bodyText) {
|
||||
if (response.status >= 300) {
|
||||
var getResult = function () {
|
||||
try {
|
||||
return JSON.parse(bodyText);
|
||||
}
|
||||
catch (err) {
|
||||
return bodyText;
|
||||
}
|
||||
};
|
||||
utils.throwServerError(response, getResult(), "Response not successful: Received status code ".concat(response.status));
|
||||
}
|
||||
try {
|
||||
return JSON.parse(bodyText);
|
||||
}
|
||||
catch (err) {
|
||||
var parseError = err;
|
||||
parseError.name = "ServerParseError";
|
||||
parseError.response = response;
|
||||
parseError.statusCode = response.status;
|
||||
parseError.bodyText = bodyText;
|
||||
throw parseError;
|
||||
}
|
||||
}
|
||||
function handleError(err, observer) {
|
||||
if (err.result && err.result.errors && err.result.data) {
|
||||
observer.next(err.result);
|
||||
}
|
||||
observer.error(err);
|
||||
}
|
||||
|
||||
var defaultHttpOptions = {
|
||||
includeQuery: true,
|
||||
includeExtensions: false,
|
||||
preserveHeaderCase: false,
|
||||
};
|
||||
var defaultHeaders = {
|
||||
accept: "*/*",
|
||||
"content-type": "application/json",
|
||||
};
|
||||
var defaultOptions = {
|
||||
method: "POST",
|
||||
};
|
||||
var fallbackHttpConfig = {
|
||||
http: defaultHttpOptions,
|
||||
headers: defaultHeaders,
|
||||
options: defaultOptions,
|
||||
};
|
||||
|
||||
function generateOptionsForMultipartSubscription(headers) {
|
||||
var options = tslib.__assign(tslib.__assign({}, fallbackHttpConfig.options), { headers: tslib.__assign(tslib.__assign(tslib.__assign({}, (headers || {})), fallbackHttpConfig.headers), { accept: "multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json" }) });
|
||||
return options;
|
||||
}
|
||||
|
||||
var backupFetch = utilities.maybe(function () { return fetch; });
|
||||
function createFetchMultipartSubscription(uri, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, preferredFetch = _b.fetch, headers = _b.headers;
|
||||
return function multipartSubscriptionForwarder(_a) {
|
||||
var query = _a.query, variables = _a.variables;
|
||||
var body = { variables: variables, query: query };
|
||||
var options = generateOptionsForMultipartSubscription(headers || {});
|
||||
return new utilities.Observable(function (observer) {
|
||||
try {
|
||||
options.body = core.serializeFetchParameter(body, "Payload");
|
||||
}
|
||||
catch (parseError) {
|
||||
observer.error(parseError);
|
||||
}
|
||||
var currentFetch = preferredFetch || utilities.maybe(function () { return fetch; }) || backupFetch;
|
||||
var observerNext = observer.next.bind(observer);
|
||||
currentFetch(uri, options)
|
||||
.then(function (response) {
|
||||
var _a;
|
||||
var ctype = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
||||
if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
|
||||
return readMultipartBody(response, observerNext);
|
||||
}
|
||||
observer.error(new Error("Expected multipart response"));
|
||||
})
|
||||
.then(function () {
|
||||
observer.complete();
|
||||
})
|
||||
.catch(function (err) {
|
||||
handleError(err, observer);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.createFetchMultipartSubscription = createFetchMultipartSubscription;
|
||||
//# sourceMappingURL=urql.cjs.map
|
||||
1
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs.map
generated
vendored
Normal file
1
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
365
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs.native.js
generated
vendored
Normal file
365
graphql-subscription/node_modules/@apollo/client/utilities/subscriptions/urql/urql.cjs.native.js
generated
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var utilities = require('../..');
|
||||
var tslib = require('tslib');
|
||||
var utils = require('../../../link/utils');
|
||||
var errors = require('../../../errors');
|
||||
var core = require('../../../core');
|
||||
|
||||
function asyncIterator(source) {
|
||||
var _a;
|
||||
var iterator = source[Symbol.asyncIterator]();
|
||||
return _a = {
|
||||
next: function () {
|
||||
return iterator.next();
|
||||
}
|
||||
},
|
||||
_a[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
},
|
||||
_a;
|
||||
}
|
||||
|
||||
function nodeStreamIterator(stream) {
|
||||
var cleanup = null;
|
||||
var error = null;
|
||||
var done = false;
|
||||
var data = [];
|
||||
var waiting = [];
|
||||
function onData(chunk) {
|
||||
if (error)
|
||||
return;
|
||||
if (waiting.length) {
|
||||
var shiftedArr = waiting.shift();
|
||||
if (Array.isArray(shiftedArr) && shiftedArr[0]) {
|
||||
return shiftedArr[0]({ value: chunk, done: false });
|
||||
}
|
||||
}
|
||||
data.push(chunk);
|
||||
}
|
||||
function onError(err) {
|
||||
error = err;
|
||||
var all = waiting.slice();
|
||||
all.forEach(function (pair) {
|
||||
pair[1](err);
|
||||
});
|
||||
!cleanup || cleanup();
|
||||
}
|
||||
function onEnd() {
|
||||
done = true;
|
||||
var all = waiting.slice();
|
||||
all.forEach(function (pair) {
|
||||
pair[0]({ value: undefined, done: true });
|
||||
});
|
||||
!cleanup || cleanup();
|
||||
}
|
||||
cleanup = function () {
|
||||
cleanup = null;
|
||||
stream.removeListener("data", onData);
|
||||
stream.removeListener("error", onError);
|
||||
stream.removeListener("end", onEnd);
|
||||
stream.removeListener("finish", onEnd);
|
||||
stream.removeListener("close", onEnd);
|
||||
};
|
||||
stream.on("data", onData);
|
||||
stream.on("error", onError);
|
||||
stream.on("end", onEnd);
|
||||
stream.on("finish", onEnd);
|
||||
stream.on("close", onEnd);
|
||||
function getNext() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (error)
|
||||
return reject(error);
|
||||
if (data.length)
|
||||
return resolve({ value: data.shift(), done: false });
|
||||
if (done)
|
||||
return resolve({ value: undefined, done: true });
|
||||
waiting.push([resolve, reject]);
|
||||
});
|
||||
}
|
||||
var iterator = {
|
||||
next: function () {
|
||||
return getNext();
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function promiseIterator(promise) {
|
||||
var resolved = false;
|
||||
var iterator = {
|
||||
next: function () {
|
||||
if (resolved)
|
||||
return Promise.resolve({
|
||||
value: undefined,
|
||||
done: true,
|
||||
});
|
||||
resolved = true;
|
||||
return new Promise(function (resolve, reject) {
|
||||
promise
|
||||
.then(function (value) {
|
||||
resolve({ value: value, done: false });
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function readerIterator(reader) {
|
||||
var iterator = {
|
||||
next: function () {
|
||||
return reader.read();
|
||||
},
|
||||
};
|
||||
if (utilities.canUseAsyncIteratorSymbol) {
|
||||
iterator[Symbol.asyncIterator] = function () {
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
function isNodeResponse(value) {
|
||||
return !!value.body;
|
||||
}
|
||||
function isReadableStream(value) {
|
||||
return !!value.getReader;
|
||||
}
|
||||
function isAsyncIterableIterator(value) {
|
||||
return !!(utilities.canUseAsyncIteratorSymbol &&
|
||||
value[Symbol.asyncIterator]);
|
||||
}
|
||||
function isStreamableBlob(value) {
|
||||
return !!value.stream;
|
||||
}
|
||||
function isBlob(value) {
|
||||
return !!value.arrayBuffer;
|
||||
}
|
||||
function isNodeReadableStream(value) {
|
||||
return !!value.pipe;
|
||||
}
|
||||
function responseIterator(response) {
|
||||
var body = response;
|
||||
if (isNodeResponse(response))
|
||||
body = response.body;
|
||||
if (isAsyncIterableIterator(body))
|
||||
return asyncIterator(body);
|
||||
if (isReadableStream(body))
|
||||
return readerIterator(body.getReader());
|
||||
if (isStreamableBlob(body)) {
|
||||
return readerIterator(body.stream().getReader());
|
||||
}
|
||||
if (isBlob(body))
|
||||
return promiseIterator(body.arrayBuffer());
|
||||
if (isNodeReadableStream(body))
|
||||
return nodeStreamIterator(body);
|
||||
throw new Error("Unknown body type for responseIterator. Please pass a streamable response.");
|
||||
}
|
||||
|
||||
function isNonNullObject(obj) {
|
||||
return obj !== null && typeof obj === "object";
|
||||
}
|
||||
|
||||
function isApolloPayloadResult(value) {
|
||||
return isNonNullObject(value) && "payload" in value;
|
||||
}
|
||||
|
||||
function readMultipartBody(response, nextValue) {
|
||||
var _a;
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
|
||||
var _c, _d;
|
||||
return tslib.__generator(this, function (_e) {
|
||||
switch (_e.label) {
|
||||
case 0:
|
||||
if (TextDecoder === undefined) {
|
||||
throw new Error("TextDecoder must be defined in the environment: please import a polyfill.");
|
||||
}
|
||||
decoder = new TextDecoder("utf-8");
|
||||
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
||||
delimiter = "boundary=";
|
||||
boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?
|
||||
contentType === null || contentType === void 0 ? void 0 : contentType.substring((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(delimiter)) + delimiter.length).replace(/['"]/g, "").replace(/\;(.*)/gm, "").trim()
|
||||
: "-";
|
||||
boundary = "\r\n--".concat(boundaryVal);
|
||||
buffer = "";
|
||||
iterator = responseIterator(response);
|
||||
running = true;
|
||||
_e.label = 1;
|
||||
case 1:
|
||||
if (!running) return [3 , 3];
|
||||
return [4 , iterator.next()];
|
||||
case 2:
|
||||
_b = _e.sent(), value = _b.value, done = _b.done;
|
||||
chunk = typeof value === "string" ? value : decoder.decode(value);
|
||||
searchFrom = buffer.length - boundary.length + 1;
|
||||
running = !done;
|
||||
buffer += chunk;
|
||||
bi = buffer.indexOf(boundary, searchFrom);
|
||||
while (bi > -1) {
|
||||
message = void 0;
|
||||
_c = [
|
||||
buffer.slice(0, bi),
|
||||
buffer.slice(bi + boundary.length),
|
||||
], message = _c[0], buffer = _c[1];
|
||||
i = message.indexOf("\r\n\r\n");
|
||||
headers = parseHeaders(message.slice(0, i));
|
||||
contentType_1 = headers["content-type"];
|
||||
if (contentType_1 &&
|
||||
contentType_1.toLowerCase().indexOf("application/json") === -1) {
|
||||
throw new Error("Unsupported patch content type: application/json is required.");
|
||||
}
|
||||
body = message.slice(i);
|
||||
if (body) {
|
||||
result = parseJsonBody(response, body);
|
||||
if (Object.keys(result).length > 1 ||
|
||||
"data" in result ||
|
||||
"incremental" in result ||
|
||||
"errors" in result ||
|
||||
"payload" in result) {
|
||||
if (isApolloPayloadResult(result)) {
|
||||
next = {};
|
||||
if ("payload" in result) {
|
||||
next = tslib.__assign({}, result.payload);
|
||||
}
|
||||
if ("errors" in result) {
|
||||
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
|
||||
}
|
||||
nextValue(next);
|
||||
}
|
||||
else {
|
||||
nextValue(result);
|
||||
}
|
||||
}
|
||||
else if (
|
||||
Object.keys(result).length === 1 &&
|
||||
"hasNext" in result &&
|
||||
!result.hasNext) {
|
||||
return [2 ];
|
||||
}
|
||||
}
|
||||
bi = buffer.indexOf(boundary);
|
||||
}
|
||||
return [3 , 1];
|
||||
case 3: return [2 ];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function parseHeaders(headerText) {
|
||||
var headersInit = {};
|
||||
headerText.split("\n").forEach(function (line) {
|
||||
var i = line.indexOf(":");
|
||||
if (i > -1) {
|
||||
var name_1 = line.slice(0, i).trim().toLowerCase();
|
||||
var value = line.slice(i + 1).trim();
|
||||
headersInit[name_1] = value;
|
||||
}
|
||||
});
|
||||
return headersInit;
|
||||
}
|
||||
function parseJsonBody(response, bodyText) {
|
||||
if (response.status >= 300) {
|
||||
var getResult = function () {
|
||||
try {
|
||||
return JSON.parse(bodyText);
|
||||
}
|
||||
catch (err) {
|
||||
return bodyText;
|
||||
}
|
||||
};
|
||||
utils.throwServerError(response, getResult(), "Response not successful: Received status code ".concat(response.status));
|
||||
}
|
||||
try {
|
||||
return JSON.parse(bodyText);
|
||||
}
|
||||
catch (err) {
|
||||
var parseError = err;
|
||||
parseError.name = "ServerParseError";
|
||||
parseError.response = response;
|
||||
parseError.statusCode = response.status;
|
||||
parseError.bodyText = bodyText;
|
||||
throw parseError;
|
||||
}
|
||||
}
|
||||
function handleError(err, observer) {
|
||||
if (err.result && err.result.errors && err.result.data) {
|
||||
observer.next(err.result);
|
||||
}
|
||||
observer.error(err);
|
||||
}
|
||||
|
||||
var defaultHttpOptions = {
|
||||
includeQuery: true,
|
||||
includeExtensions: false,
|
||||
preserveHeaderCase: false,
|
||||
};
|
||||
var defaultHeaders = {
|
||||
accept: "*/*",
|
||||
"content-type": "application/json",
|
||||
};
|
||||
var defaultOptions = {
|
||||
method: "POST",
|
||||
};
|
||||
var fallbackHttpConfig = {
|
||||
http: defaultHttpOptions,
|
||||
headers: defaultHeaders,
|
||||
options: defaultOptions,
|
||||
};
|
||||
|
||||
function generateOptionsForMultipartSubscription(headers) {
|
||||
var options = tslib.__assign(tslib.__assign({}, fallbackHttpConfig.options), { headers: tslib.__assign(tslib.__assign(tslib.__assign({}, (headers || {})), fallbackHttpConfig.headers), { accept: "multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json" }) });
|
||||
return options;
|
||||
}
|
||||
|
||||
var backupFetch = utilities.maybe(function () { return fetch; });
|
||||
function createFetchMultipartSubscription(uri, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, preferredFetch = _b.fetch, headers = _b.headers;
|
||||
return function multipartSubscriptionForwarder(_a) {
|
||||
var query = _a.query, variables = _a.variables;
|
||||
var body = { variables: variables, query: query };
|
||||
var options = generateOptionsForMultipartSubscription(headers || {});
|
||||
return new utilities.Observable(function (observer) {
|
||||
try {
|
||||
options.body = core.serializeFetchParameter(body, "Payload");
|
||||
}
|
||||
catch (parseError) {
|
||||
observer.error(parseError);
|
||||
}
|
||||
var currentFetch = preferredFetch || utilities.maybe(function () { return fetch; }) || backupFetch;
|
||||
var observerNext = observer.next.bind(observer);
|
||||
currentFetch(uri, options)
|
||||
.then(function (response) {
|
||||
var _a;
|
||||
var ctype = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
|
||||
if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
|
||||
return readMultipartBody(response, observerNext);
|
||||
}
|
||||
observer.error(new Error("Expected multipart response"));
|
||||
})
|
||||
.then(function () {
|
||||
observer.complete();
|
||||
})
|
||||
.catch(function (err) {
|
||||
handleError(err, observer);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.createFetchMultipartSubscription = createFetchMultipartSubscription;
|
||||
//# sourceMappingURL=urql.cjs.map
|
||||
Reference in New Issue
Block a user