graphql-sse
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -137,7 +137,7 @@ /** | ||
* If you have an HTTP/2 server, it is recommended to use the client | ||
* in "distinct connections mode" (`singleConnection = true`) which will | ||
* in "distinct connections mode" (`singleConnection = false`) which will | ||
* create a new SSE connection for each subscribe. This is the default. | ||
* | ||
* However, when dealing with HTTP/1 servers from a browser, consider using | ||
* the "single connection mode" (`singleConnection = false`) which will | ||
* the "single connection mode" (`singleConnection = true`) which will | ||
* use only one SSE connection. | ||
@@ -144,0 +144,0 @@ * |
@@ -47,7 +47,7 @@ "use strict"; | ||
* If you have an HTTP/2 server, it is recommended to use the client | ||
* in "distinct connections mode" (`singleConnection = true`) which will | ||
* in "distinct connections mode" (`singleConnection = false`) which will | ||
* create a new SSE connection for each subscribe. This is the default. | ||
* | ||
* However, when dealing with HTTP/1 servers from a browser, consider using | ||
* the "single connection mode" (`singleConnection = false`) which will | ||
* the "single connection mode" (`singleConnection = true`) which will | ||
* use only one SSE connection. | ||
@@ -275,4 +275,4 @@ * | ||
})() | ||
.catch((err) => sink.error(err)) | ||
.then(() => sink.complete()); | ||
.then(() => sink.complete()) | ||
.catch((err) => sink.error(err)); | ||
return () => control.abort(); | ||
@@ -369,4 +369,4 @@ } | ||
})() | ||
.catch((err) => sink.error(err)) | ||
.then(() => sink.complete()); | ||
.then(() => sink.complete()) | ||
.catch((err) => sink.error(err)); | ||
return () => control.abort(); | ||
@@ -408,3 +408,3 @@ }, | ||
static isResponse(msgOrErrOrResponse) { | ||
return (utils_1.isObject(msgOrErrOrResponse) && | ||
return ((0, utils_1.isObject)(msgOrErrOrResponse) && | ||
'status' in msgOrErrOrResponse && | ||
@@ -441,3 +441,3 @@ 'statusText' in msgOrErrOrResponse); | ||
try { | ||
const parse = parser_1.createParser(); | ||
const parse = (0, parser_1.createParser)(); | ||
try { | ||
@@ -444,0 +444,0 @@ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
@@ -53,3 +53,2 @@ "use strict"; | ||
return reject(err); | ||
// if (err) return resolve(false); | ||
resolve(true); | ||
@@ -189,3 +188,3 @@ }); | ||
try { | ||
query = graphql_1.parse(query); | ||
query = (0, graphql_1.parse)(query); | ||
} | ||
@@ -206,3 +205,3 @@ catch (_a) { | ||
try { | ||
const ast = graphql_1.getOperationAST(args.document, args.operationName); | ||
const ast = (0, graphql_1.getOperationAST)(args.document, args.operationName); | ||
if (!ast) | ||
@@ -254,4 +253,3 @@ throw null; | ||
async function perform() { | ||
let result; | ||
result = operation === 'subscription' ? subscribe(args) : execute(args); | ||
let result = operation === 'subscription' ? subscribe(args) : execute(args); | ||
const maybeResult = await (onOperation === null || onOperation === void 0 ? void 0 : onOperation(req, res, args, result)); | ||
@@ -426,3 +424,3 @@ if (maybeResult) | ||
try { | ||
const data = utils_1.isObject(body) ? body : JSON.parse(String(body)); | ||
const data = typeof body === 'string' ? JSON.parse(body) : body; | ||
params.operationName = data.operationName; | ||
@@ -438,3 +436,3 @@ params.query = data.query; | ||
}; | ||
if (body != null) | ||
if (typeof body === 'string' || (0, utils_1.isObject)(body)) | ||
end(body); | ||
@@ -462,3 +460,3 @@ else { | ||
function isAsyncGenerator(val) { | ||
return (utils_1.isObject(val) && | ||
return ((0, utils_1.isObject)(val) && | ||
typeof Object(val)[Symbol.asyncIterator] === 'function' && | ||
@@ -465,0 +463,0 @@ typeof val.return === 'function' |
@@ -82,4 +82,4 @@ "use strict"; | ||
throw new Error('Missing message event'); | ||
const event = common_1.validateStreamEvent(message.event); | ||
const data = common_1.parseStreamData(event, message.data); | ||
const event = (0, common_1.validateStreamEvent)(message.event); | ||
const data = (0, common_1.parseStreamData)(event, message.data); | ||
pending.push({ | ||
@@ -86,0 +86,0 @@ event, |
{ | ||
"name": "graphql-sse", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client", | ||
@@ -69,35 +69,38 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.15.0", | ||
"@babel/plugin-proposal-class-properties": "^7.14.5", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.14.7", | ||
"@babel/plugin-proposal-optional-chaining": "^7.14.5", | ||
"@babel/preset-env": "^7.15.0", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"@rollup/plugin-typescript": "^8.2.5", | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@types/eventsource": "^1.1.6", | ||
"@babel/core": "^7.16.0", | ||
"@babel/plugin-proposal-class-properties": "^7.16.0", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.16.0", | ||
"@babel/plugin-proposal-optional-chaining": "^7.16.0", | ||
"@babel/preset-env": "^7.16.0", | ||
"@babel/preset-typescript": "^7.16.0", | ||
"@rollup/plugin-typescript": "^8.3.0", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/git": "^10.0.1", | ||
"@types/eventsource": "^1.1.7", | ||
"@types/express": "^4.17.13", | ||
"@types/jest": "^26.0.24", | ||
"@types/node-fetch": "^2.5.12", | ||
"@typescript-eslint/eslint-plugin": "^4.29.3", | ||
"@typescript-eslint/parser": "^4.29.3", | ||
"babel-jest": "^27.0.6", | ||
"eslint": "^7.32.0", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"babel-jest": "^27.3.1", | ||
"eslint": "^8.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eventsource": "^1.1.0", | ||
"graphql": "16.0.0-rc.2.experimental-stream-defer.3", | ||
"jest": "^27.0.6", | ||
"node-fetch": "^2.6.1", | ||
"prettier": "^2.3.2", | ||
"express": "^4.17.1", | ||
"fastify": "^3.22.1", | ||
"graphql": "^16.0.1", | ||
"jest": "^27.3.1", | ||
"node-fetch": "^2.6.6", | ||
"prettier": "^2.4.1", | ||
"replacestream": "^4.0.3", | ||
"rollup": "^2.56.3", | ||
"rollup": "^2.59.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semantic-release": "^17.4.7", | ||
"semantic-release": "^18.0.0", | ||
"tslib": "^2.3.1", | ||
"typedoc": "^0.21.6", | ||
"typedoc-plugin-markdown": "^3.10.4", | ||
"typescript": "4.3.5" | ||
"typedoc": "^0.22.7", | ||
"typedoc-plugin-markdown": "^3.11.3", | ||
"typescript": "^4.4.4" | ||
} | ||
} |
@@ -10,2 +10,4 @@ <div align="center"> | ||
<i>Use [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instead? Check out <b>[graphql-ws](https://github.com/enisdenjo/graphql-ws)</b>!</i> | ||
<br /> | ||
@@ -167,3 +169,3 @@ </div> | ||
const client = createClient({ | ||
// singleConnection: true, use "single connection mode" instead of the default "distinct connection mode" | ||
// singleConnection: true, preferred for HTTP/1 enabled servers. read more below | ||
url: 'http://localhost:4000/graphql/stream', | ||
@@ -170,0 +172,0 @@ }); |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.graphqlSse = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -231,7 +231,7 @@ /*! ***************************************************************************** | ||
* If you have an HTTP/2 server, it is recommended to use the client | ||
* in "distinct connections mode" (`singleConnection = true`) which will | ||
* in "distinct connections mode" (`singleConnection = false`) which will | ||
* create a new SSE connection for each subscribe. This is the default. | ||
* | ||
* However, when dealing with HTTP/1 servers from a browser, consider using | ||
* the "single connection mode" (`singleConnection = false`) which will | ||
* the "single connection mode" (`singleConnection = true`) which will | ||
* use only one SSE connection. | ||
@@ -459,4 +459,4 @@ * | ||
})() | ||
.catch((err) => sink.error(err)) | ||
.then(() => sink.complete()); | ||
.then(() => sink.complete()) | ||
.catch((err) => sink.error(err)); | ||
return () => control.abort(); | ||
@@ -553,4 +553,4 @@ } | ||
})() | ||
.catch((err) => sink.error(err)) | ||
.then(() => sink.complete()); | ||
.then(() => sink.complete()) | ||
.catch((err) => sink.error(err)); | ||
return () => control.abort(); | ||
@@ -746,2 +746,2 @@ }, | ||
}))); | ||
})); |
@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).graphqlSse={})}(this,(function(t){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function e(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(t){return this instanceof n?(this.v=t,this):new n(t)}function r(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,a=r.apply(t,e||[]),i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(t){a[t]&&(o[t]=function(e){return new Promise((function(n,r){i.push([t,e,n,r])>1||c(t,e)}))})}function c(t,e){try{(r=a[t](e)).value instanceof n?Promise.resolve(r.value.v).then(l,u):f(i[0][2],r)}catch(t){f(i[0][3],t)}var r}function l(t){c("next",t)}function u(t){c("throw",t)}function f(t,e){t(e),i.shift(),i.length&&c(i[0][0],i[0][1])}}function o(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=t[Symbol.asyncIterator];return r?r.call(t):(t=e(t),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(e){n[e]=t[e]&&function(n){return new Promise((function(r,o){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,o,(n=t[e](n)).done,n.value)}))}}}function a(t){if("next"!==(t=t)&&"complete"!==t)throw new Error(`Invalid stream event "${t}"`);return t}function i(t,e){if(e)try{e=JSON.parse(e)}catch(t){throw new Error("Invalid stream data")}if("next"===t&&!e)throw new Error('Stream data must be an object for "next" events');return e||null}var s;!function(t){t[t.NewLine=10]="NewLine",t[t.CchunkiageReturn=13]="CchunkiageReturn",t[t.Space=32]="Space",t[t.Colon=58]="Colon"}(s||(s={}));class c extends Error{constructor(t){let e,n;c.isResponse(t)?(n=t,e="Server responded with "+t.status+": "+t.statusText):e=t instanceof Error?t.message:String(t),super(e),this.name=this.constructor.name,this.response=n}static isResponse(t){return"object"==typeof(e=t)&&null!==e&&"status"in t&&"statusText"in t;var e}}async function l(t){const{signal:e,url:l,headers:u,body:f,fetchFn:d}=t,h={},w={};let y;try{y=await d(l,{signal:e,method:f?"POST":"GET",headers:Object.assign(Object.assign({},u),{accept:"text/event-stream"}),body:f})}catch(t){throw new c(t)}if(!y.ok)throw new c(y);if(!y.body)throw new Error("Missing response body");let b=null,p=null;return(async()=>{var t,e,c;try{const f=function(){let t,e,n,r=!1,o={event:"",data:""},c=[];const l=new TextDecoder;return function(u){if(void 0===t)t=u,e=0,n=-1;else{const e=new Uint8Array(t.length+u.length);e.set(t),e.set(u,t.length),t=e}const f=t.length;let d=0;for(;e<f;){r&&(t[e]===s.NewLine&&(d=++e),r=!1);let u=-1;for(;e<f&&-1===u;++e)switch(t[e]){case s.Colon:-1===n&&(n=e-d);break;case s.CchunkiageReturn:r=!0;case s.NewLine:u=e}if(-1===u)break;if(d===u){if(o.event||o.data){if(!o.event)throw new Error("Missing message event");const t=a(o.event),e=i(t,o.data);c.push({event:t,data:e}),o={event:"",data:""}}}else if(n>0){const e=t.subarray(d,u),r=l.decode(e.subarray(0,n)),a=n+(e[n+1]===s.Space?2:1),i=l.decode(e.subarray(a));switch(r){case"event":o.event=i;break;case"data":o.data=o.data?o.data+"\n"+i:i}}d=e,n=-1}if(d===f){t=void 0;const e=[...c];return c=[],e}0!==d&&(t=t.subarray(d),e-=d)}}();try{for(var l,u=o(function(t){if("function"==typeof Object(t)[Symbol.asyncIterator])return(t=t)[Symbol.asyncIterator]();return function(){return r(this,arguments,(function*(){const e=(t=t).getReader();for(;;){const{value:t,done:r}=yield n(e.read());if(r)return yield n(t);yield yield n(t)}}))}()}(y.body));!(l=await u.next()).done;){const t=l.value;if("string"==typeof t)throw new Error(`Unexpected string chunk "${t}"`);const e=f(t);if(e)for(const t of e){const e=t.data&&"id"in t.data?t.data.id:"";switch(e in w||(w[e]=[]),t.event){case"next":e?w[e].push(t.data.payload):w[e].push(t.data);break;case"complete":w[e].push("complete");break;default:throw new Error(`Unexpected message event "${t.event}"`)}null===(c=h[e])||void 0===c||c.proceed()}}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=u.return)&&await e.call(u)}finally{if(t)throw t.error}}}catch(t){b=t,p&&p(t)}finally{Object.values(h).forEach((({proceed:t})=>t()))}})(),{url:l,headers:u,waitForThrow:()=>new Promise(((t,e)=>{if(b)return e(b);p=e})),getResults(t){var e;return r(this,arguments,(function*(){const{signal:r,operationId:o=""}=null!=t?t:{};try{for(;;){for(;null===(e=w[o])||void 0===e?void 0:e.length;){const t=w[o].shift();if("complete"===t)return yield n(void 0);yield yield n(t)}if(b)throw b;if(null==r?void 0:r.aborted)throw new Error("Getting results aborted by the client");yield n(new Promise((t=>{const e=()=>{null==r||r.removeEventListener("abort",e),delete h[o],t()};null==r||r.addEventListener("abort",e),h[o]={proceed:e}})))}}finally{delete w[o]}}))}}}t.NetworkError=c,t.createClient=function(t){const{singleConnection:e=!1,lazy:n=!0,onNonLazyError:r=console.error,generateID:a=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},retryAttempts:i=5,retry:s=async function(t){let e=1e3;for(let n=0;n<t;n++)e*=2;await new Promise((t=>setTimeout(t,e+Math.floor(2700*Math.random()+300))))}}=t,u=t.fetchFn||fetch,f=t.abortControllerImpl||AbortController,d=(()=>{let t=!1;const e=[];return{get disposed(){return t},onDispose:n=>t?(setTimeout((()=>n()),0),()=>{}):(e.push(n),()=>{e.splice(e.indexOf(n),1)}),dispose(){if(!t){t=!0;for(const t of[...e])t()}}}})();let h,w,y=0,b=null,p=0;async function v(){try{if(d.disposed)throw new Error("Client has been disposed");return await(null!=w?w:w=(async()=>{var e;if(b){if(await s(p),h.signal.aborted)throw new Error("Connection aborted by the client");p++}h=new f;const n=d.onDispose((()=>h.abort()));h.signal.addEventListener("abort",(()=>{n(),w=void 0}));const r="function"==typeof t.url?await t.url():t.url;if(h.signal.aborted)throw new Error("Connection aborted by the client");const o="function"==typeof t.headers?await t.headers():null!==(e=t.headers)&&void 0!==e?e:{};if(h.signal.aborted)throw new Error("Connection aborted by the client");let a;try{a=await u(r,{signal:h.signal,method:"PUT",headers:o})}catch(t){throw new c(t)}if(201!==a.status)throw new c(a);const i=await a.text();o["x-graphql-event-stream-token"]=i;const y=await l({signal:h.signal,headers:o,url:r,fetchFn:u});return b=null,p=0,y.waitForThrow().catch((()=>w=void 0)),y})())}catch(t){throw w=void 0,t}}return e&&!n&&(async()=>{for(y++;;)try{const{waitForThrow:t}=await v();await t()}catch(t){if(d.disposed)return;if(!(t instanceof c))return null==r?void 0:r(t);if(!i||p>=i)return null==r?void 0:r(t);b=t}})(),{subscribe(n,r){if(!e){const e=new f,a=d.onDispose((()=>{a(),e.abort()}));return(async()=>{var a,f,d;let h=null,w=0;for(;;)try{if(h){if(await s(w),e.signal.aborted)throw new Error("Connection aborted by the client");w++}const i="function"==typeof t.url?await t.url():t.url;if(e.signal.aborted)throw new Error("Connection aborted by the client");const c="function"==typeof t.headers?await t.headers():null!==(d=t.headers)&&void 0!==d?d:{};if(e.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:p}=await l({signal:e.signal,headers:c,url:i,body:JSON.stringify(n),fetchFn:u});h=null,w=0;try{for(var y,b=(a=void 0,o(p()));!(y=await b.next()).done;){const t=y.value;r.next(t)}}catch(t){a={error:t}}finally{try{y&&!y.done&&(f=b.return)&&await f.call(b)}finally{if(a)throw a.error}}return e.abort()}catch(t){if(e.signal.aborted)return;if(!(t instanceof c))throw t;if(!i||w>=i)throw t;h=t}})().catch((t=>r.error(t))).then((()=>r.complete())),()=>e.abort()}y++;const w=new f,g=d.onDispose((()=>{g(),w.abort()}));return(async()=>{var t,e;const s=a();n=Object.assign(Object.assign({},n),{extensions:Object.assign(Object.assign({},n.extensions),{operationId:s})});let l=null;for(;;){l=null;try{const{url:a,headers:i,getResults:b}=await v();let p;try{p=await u(a,{signal:w.signal,method:"POST",headers:i,body:JSON.stringify(n)})}catch(t){throw new c(t)}if(202!==p.status)throw new c(p);l=async()=>{let t;try{const e=new f,n=d.onDispose((()=>{n(),e.abort()}));t=await u(a+"?operationId="+s,{signal:e.signal,method:"DELETE",headers:i})}catch(t){throw new c(t)}if(200!==t.status)throw new c(t)};try{for(var g,x=(t=void 0,o(b({signal:w.signal,operationId:s})));!(g=await x.next()).done;){const t=g.value;r.next(t)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(e=x.return)&&await e.call(x)}finally{if(t)throw t.error}}return l=null,w.abort()}catch(t){if(w.signal.aborted)return await(null==l?void 0:l());if(!(t instanceof c))throw t;if(!i||p>=i)throw t;b=t}finally{w.signal.aborted&&0==--y&&h.abort()}}})().catch((t=>r.error(t))).then((()=>r.complete())),()=>w.abort()},dispose(){d.dispose()}}},t.parseStreamData=i,t.validateStreamEvent=a,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
***************************************************************************** */function e(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(t){return this instanceof n?(this.v=t,this):new n(t)}function r(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,a=r.apply(t,e||[]),i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(t){a[t]&&(o[t]=function(e){return new Promise((function(n,r){i.push([t,e,n,r])>1||c(t,e)}))})}function c(t,e){try{(r=a[t](e)).value instanceof n?Promise.resolve(r.value.v).then(l,u):f(i[0][2],r)}catch(t){f(i[0][3],t)}var r}function l(t){c("next",t)}function u(t){c("throw",t)}function f(t,e){t(e),i.shift(),i.length&&c(i[0][0],i[0][1])}}function o(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=t[Symbol.asyncIterator];return r?r.call(t):(t=e(t),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(e){n[e]=t[e]&&function(n){return new Promise((function(r,o){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,o,(n=t[e](n)).done,n.value)}))}}}function a(t){if("next"!==(t=t)&&"complete"!==t)throw new Error(`Invalid stream event "${t}"`);return t}function i(t,e){if(e)try{e=JSON.parse(e)}catch(t){throw new Error("Invalid stream data")}if("next"===t&&!e)throw new Error('Stream data must be an object for "next" events');return e||null}var s;!function(t){t[t.NewLine=10]="NewLine",t[t.CchunkiageReturn=13]="CchunkiageReturn",t[t.Space=32]="Space",t[t.Colon=58]="Colon"}(s||(s={}));class c extends Error{constructor(t){let e,n;c.isResponse(t)?(n=t,e="Server responded with "+t.status+": "+t.statusText):e=t instanceof Error?t.message:String(t),super(e),this.name=this.constructor.name,this.response=n}static isResponse(t){return"object"==typeof(e=t)&&null!==e&&"status"in t&&"statusText"in t;var e}}async function l(t){const{signal:e,url:l,headers:u,body:f,fetchFn:d}=t,h={},w={};let y;try{y=await d(l,{signal:e,method:f?"POST":"GET",headers:Object.assign(Object.assign({},u),{accept:"text/event-stream"}),body:f})}catch(t){throw new c(t)}if(!y.ok)throw new c(y);if(!y.body)throw new Error("Missing response body");let b=null,p=null;return(async()=>{var t,e,c;try{const f=function(){let t,e,n,r=!1,o={event:"",data:""},c=[];const l=new TextDecoder;return function(u){if(void 0===t)t=u,e=0,n=-1;else{const e=new Uint8Array(t.length+u.length);e.set(t),e.set(u,t.length),t=e}const f=t.length;let d=0;for(;e<f;){r&&(t[e]===s.NewLine&&(d=++e),r=!1);let u=-1;for(;e<f&&-1===u;++e)switch(t[e]){case s.Colon:-1===n&&(n=e-d);break;case s.CchunkiageReturn:r=!0;case s.NewLine:u=e}if(-1===u)break;if(d===u){if(o.event||o.data){if(!o.event)throw new Error("Missing message event");const t=a(o.event),e=i(t,o.data);c.push({event:t,data:e}),o={event:"",data:""}}}else if(n>0){const e=t.subarray(d,u),r=l.decode(e.subarray(0,n)),a=n+(e[n+1]===s.Space?2:1),i=l.decode(e.subarray(a));switch(r){case"event":o.event=i;break;case"data":o.data=o.data?o.data+"\n"+i:i}}d=e,n=-1}if(d===f){t=void 0;const e=[...c];return c=[],e}0!==d&&(t=t.subarray(d),e-=d)}}();try{for(var l,u=o(function(t){if("function"==typeof Object(t)[Symbol.asyncIterator])return(t=t)[Symbol.asyncIterator]();return function(){return r(this,arguments,(function*(){const e=(t=t).getReader();for(;;){const{value:t,done:r}=yield n(e.read());if(r)return yield n(t);yield yield n(t)}}))}()}(y.body));!(l=await u.next()).done;){const t=l.value;if("string"==typeof t)throw new Error(`Unexpected string chunk "${t}"`);const e=f(t);if(e)for(const t of e){const e=t.data&&"id"in t.data?t.data.id:"";switch(e in w||(w[e]=[]),t.event){case"next":e?w[e].push(t.data.payload):w[e].push(t.data);break;case"complete":w[e].push("complete");break;default:throw new Error(`Unexpected message event "${t.event}"`)}null===(c=h[e])||void 0===c||c.proceed()}}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=u.return)&&await e.call(u)}finally{if(t)throw t.error}}}catch(t){b=t,p&&p(t)}finally{Object.values(h).forEach((({proceed:t})=>t()))}})(),{url:l,headers:u,waitForThrow:()=>new Promise(((t,e)=>{if(b)return e(b);p=e})),getResults(t){var e;return r(this,arguments,(function*(){const{signal:r,operationId:o=""}=null!=t?t:{};try{for(;;){for(;null===(e=w[o])||void 0===e?void 0:e.length;){const t=w[o].shift();if("complete"===t)return yield n(void 0);yield yield n(t)}if(b)throw b;if(null==r?void 0:r.aborted)throw new Error("Getting results aborted by the client");yield n(new Promise((t=>{const e=()=>{null==r||r.removeEventListener("abort",e),delete h[o],t()};null==r||r.addEventListener("abort",e),h[o]={proceed:e}})))}}finally{delete w[o]}}))}}}t.NetworkError=c,t.createClient=function(t){const{singleConnection:e=!1,lazy:n=!0,onNonLazyError:r=console.error,generateID:a=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},retryAttempts:i=5,retry:s=async function(t){let e=1e3;for(let n=0;n<t;n++)e*=2;await new Promise((t=>setTimeout(t,e+Math.floor(2700*Math.random()+300))))}}=t,u=t.fetchFn||fetch,f=t.abortControllerImpl||AbortController,d=(()=>{let t=!1;const e=[];return{get disposed(){return t},onDispose:n=>t?(setTimeout((()=>n()),0),()=>{}):(e.push(n),()=>{e.splice(e.indexOf(n),1)}),dispose(){if(!t){t=!0;for(const t of[...e])t()}}}})();let h,w,y=0,b=null,p=0;async function v(){try{if(d.disposed)throw new Error("Client has been disposed");return await(null!=w?w:w=(async()=>{var e;if(b){if(await s(p),h.signal.aborted)throw new Error("Connection aborted by the client");p++}h=new f;const n=d.onDispose((()=>h.abort()));h.signal.addEventListener("abort",(()=>{n(),w=void 0}));const r="function"==typeof t.url?await t.url():t.url;if(h.signal.aborted)throw new Error("Connection aborted by the client");const o="function"==typeof t.headers?await t.headers():null!==(e=t.headers)&&void 0!==e?e:{};if(h.signal.aborted)throw new Error("Connection aborted by the client");let a;try{a=await u(r,{signal:h.signal,method:"PUT",headers:o})}catch(t){throw new c(t)}if(201!==a.status)throw new c(a);const i=await a.text();o["x-graphql-event-stream-token"]=i;const y=await l({signal:h.signal,headers:o,url:r,fetchFn:u});return b=null,p=0,y.waitForThrow().catch((()=>w=void 0)),y})())}catch(t){throw w=void 0,t}}return e&&!n&&(async()=>{for(y++;;)try{const{waitForThrow:t}=await v();await t()}catch(t){if(d.disposed)return;if(!(t instanceof c))return null==r?void 0:r(t);if(!i||p>=i)return null==r?void 0:r(t);b=t}})(),{subscribe(n,r){if(!e){const e=new f,a=d.onDispose((()=>{a(),e.abort()}));return(async()=>{var a,f,d;let h=null,w=0;for(;;)try{if(h){if(await s(w),e.signal.aborted)throw new Error("Connection aborted by the client");w++}const i="function"==typeof t.url?await t.url():t.url;if(e.signal.aborted)throw new Error("Connection aborted by the client");const c="function"==typeof t.headers?await t.headers():null!==(d=t.headers)&&void 0!==d?d:{};if(e.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:p}=await l({signal:e.signal,headers:c,url:i,body:JSON.stringify(n),fetchFn:u});h=null,w=0;try{for(var y,b=(a=void 0,o(p()));!(y=await b.next()).done;){const t=y.value;r.next(t)}}catch(t){a={error:t}}finally{try{y&&!y.done&&(f=b.return)&&await f.call(b)}finally{if(a)throw a.error}}return e.abort()}catch(t){if(e.signal.aborted)return;if(!(t instanceof c))throw t;if(!i||w>=i)throw t;h=t}})().then((()=>r.complete())).catch((t=>r.error(t))),()=>e.abort()}y++;const w=new f,g=d.onDispose((()=>{g(),w.abort()}));return(async()=>{var t,e;const s=a();n=Object.assign(Object.assign({},n),{extensions:Object.assign(Object.assign({},n.extensions),{operationId:s})});let l=null;for(;;){l=null;try{const{url:a,headers:i,getResults:b}=await v();let p;try{p=await u(a,{signal:w.signal,method:"POST",headers:i,body:JSON.stringify(n)})}catch(t){throw new c(t)}if(202!==p.status)throw new c(p);l=async()=>{let t;try{const e=new f,n=d.onDispose((()=>{n(),e.abort()}));t=await u(a+"?operationId="+s,{signal:e.signal,method:"DELETE",headers:i})}catch(t){throw new c(t)}if(200!==t.status)throw new c(t)};try{for(var g,x=(t=void 0,o(b({signal:w.signal,operationId:s})));!(g=await x.next()).done;){const t=g.value;r.next(t)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(e=x.return)&&await e.call(x)}finally{if(t)throw t.error}}return l=null,w.abort()}catch(t){if(w.signal.aborted)return await(null==l?void 0:l());if(!(t instanceof c))throw t;if(!i||p>=i)throw t;b=t}finally{w.signal.aborted&&0==--y&&h.abort()}}})().then((()=>r.complete())).catch((t=>r.error(t))),()=>w.abort()},dispose(){d.dispose()}}},t.parseStreamData=i,t.validateStreamEvent=a,Object.defineProperty(t,"__esModule",{value:!0})})); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204823
831
35
3615