graphql-sse
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -202,2 +202,4 @@ "use strict"; | ||
return onNonLazyError === null || onNonLazyError === void 0 ? void 0 : onNonLazyError(err); | ||
// was a network error, get rid of the current connection to ensure retries | ||
conn = undefined; | ||
// retries are not allowed or we tried to many times, report error | ||
@@ -367,2 +369,7 @@ if (!retryAttempts || retries >= retryAttempts) | ||
throw err; | ||
// was a network error, get rid of the current connection to ensure retries | ||
// but only if the client is running in lazy mode (otherwise the non-lazy lock will get rid of the connection) | ||
if (lazy) { | ||
conn = undefined; | ||
} | ||
// retries are not allowed or we tried to many times, report error | ||
@@ -464,3 +471,3 @@ if (!retryAttempts || retries >= retryAttempts) | ||
let error = null; | ||
let waitingForThrow = null; | ||
let waitingForThrow; | ||
(async () => { | ||
@@ -514,5 +521,5 @@ var e_3, _a; | ||
catch (err) { | ||
error = err; | ||
if (waitingForThrow) | ||
waitingForThrow(err); | ||
// non-network errors shouldn't ever have "network" in the message, right? | ||
error = /network/i.test(err) ? new NetworkError(err) : err; | ||
waitingForThrow === null || waitingForThrow === void 0 ? void 0 : waitingForThrow(error); | ||
} | ||
@@ -577,12 +584,11 @@ finally { | ||
return __asyncGenerator(this, arguments, function* () { | ||
val = val; | ||
const reader = val.getReader(); | ||
for (;;) { | ||
const { value, done } = yield __await(reader.read()); | ||
if (done) | ||
return yield __await(value); | ||
yield yield __await(value); | ||
} | ||
let result; | ||
do { | ||
result = yield __await(reader.read()); | ||
if (result.value !== undefined) | ||
yield yield __await(result.value); | ||
} while (!result.done); | ||
}); | ||
})(); | ||
} |
{ | ||
"name": "graphql-sse", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
}, | ||
"packageManager": "yarn@3.2.0", | ||
"packageManager": "yarn@3.2.1", | ||
"main": "lib/index.js", | ||
@@ -71,9 +71,9 @@ "module": "lib/index.mjs", | ||
"devDependencies": { | ||
"@babel/core": "^7.17.9", | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.17.3", | ||
"@babel/plugin-proposal-optional-chaining": "^7.16.7", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@babel/core": "^7.18.2", | ||
"@babel/plugin-proposal-class-properties": "^7.17.12", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.17.12", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.0", | ||
"@babel/plugin-proposal-optional-chaining": "^7.17.12", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/preset-typescript": "^7.17.12", | ||
"@rollup/plugin-typescript": "^8.3.2", | ||
@@ -84,25 +84,26 @@ "@semantic-release/changelog": "^6.0.1", | ||
"@types/express": "^4.17.13", | ||
"@types/jest": "^27.4.1", | ||
"@types/jest": "^28.1.1", | ||
"@types/node-fetch": "^2.6.1", | ||
"@typescript-eslint/eslint-plugin": "^5.19.0", | ||
"@typescript-eslint/parser": "^5.19.0", | ||
"babel-jest": "^27.5.1", | ||
"eslint": "^8.13.0", | ||
"@typescript-eslint/eslint-plugin": "^5.27.1", | ||
"@typescript-eslint/parser": "^5.27.1", | ||
"babel-jest": "^28.1.1", | ||
"eslint": "^8.17.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eventsource": "^2.0.0", | ||
"express": "^4.17.3", | ||
"fastify": "^3.28.0", | ||
"graphql": "^16.3.0", | ||
"jest": "^27.5.1", | ||
"eventsource": "^2.0.2", | ||
"express": "^4.18.1", | ||
"fastify": "^3.29.0", | ||
"graphql": "^16.5.0", | ||
"jest": "^28.1.1", | ||
"jest-jasmine2": "^28.1.1", | ||
"node-fetch": "^2.6.7", | ||
"prettier": "^2.6.2", | ||
"replacestream": "^4.0.3", | ||
"rollup": "^2.70.1", | ||
"rollup": "^2.75.6", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semantic-release": "^19.0.2", | ||
"tslib": "^2.3.1", | ||
"typedoc": "^0.22.15", | ||
"typedoc-plugin-markdown": "^3.12.0", | ||
"typescript": "^4.6.3" | ||
"semantic-release": "^19.0.3", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.22.17", | ||
"typedoc-plugin-markdown": "^3.12.1", | ||
"typescript": "^4.7.3" | ||
}, | ||
@@ -109,0 +110,0 @@ "resolutions": { |
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
/*! ***************************************************************************** | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -399,2 +399,4 @@ | ||
return onNonLazyError === null || onNonLazyError === void 0 ? void 0 : onNonLazyError(err); | ||
// was a network error, get rid of the current connection to ensure retries | ||
conn = undefined; | ||
// retries are not allowed or we tried to many times, report error | ||
@@ -564,2 +566,7 @@ if (!retryAttempts || retries >= retryAttempts) | ||
throw err; | ||
// was a network error, get rid of the current connection to ensure retries | ||
// but only if the client is running in lazy mode (otherwise the non-lazy lock will get rid of the connection) | ||
if (lazy) { | ||
conn = undefined; | ||
} | ||
// retries are not allowed or we tried to many times, report error | ||
@@ -659,3 +666,3 @@ if (!retryAttempts || retries >= retryAttempts) | ||
let error = null; | ||
let waitingForThrow = null; | ||
let waitingForThrow; | ||
(async () => { | ||
@@ -709,5 +716,5 @@ var e_3, _a; | ||
catch (err) { | ||
error = err; | ||
if (waitingForThrow) | ||
waitingForThrow(err); | ||
// non-network errors shouldn't ever have "network" in the message, right? | ||
error = /network/i.test(err) ? new NetworkError(err) : err; | ||
waitingForThrow === null || waitingForThrow === void 0 ? void 0 : waitingForThrow(error); | ||
} | ||
@@ -772,10 +779,9 @@ finally { | ||
return __asyncGenerator(this, arguments, function* () { | ||
val = val; | ||
const reader = val.getReader(); | ||
for (;;) { | ||
const { value, done } = yield __await(reader.read()); | ||
if (done) | ||
return yield __await(value); | ||
yield yield __await(value); | ||
} | ||
let result; | ||
do { | ||
result = yield __await(reader.read()); | ||
if (result.value !== undefined) | ||
yield yield __await(result.value); | ||
} while (!result.done); | ||
}); | ||
@@ -782,0 +788,0 @@ })(); |
@@ -1,15 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlSse={})}(this,(function(e){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function t(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(e){return this instanceof n?(this.v=e,this):new n(e)}function r(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,a=r.apply(e,t||[]),i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(e){a[e]&&(o[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||l(e,t)}))})}function l(e,t){try{(r=a[e](t)).value instanceof n?Promise.resolve(r.value.v).then(c,u):d(i[0][2],r)}catch(e){d(i[0][3],e)}var r}function c(e){l("next",e)}function u(e){l("throw",e)}function d(e,t){e(t),i.shift(),i.length&&l(i[0][0],i[0][1])}}function o(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=e[Symbol.asyncIterator];return r?r.call(e):(e=t(e),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(t){n[t]=e[t]&&function(n){return new Promise((function(r,o){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,o,(n=e[t](n)).done,n.value)}))}}}const a="x-graphql-event-stream-token";function i(e){if("next"!==(e=e)&&"complete"!==e)throw new Error(`Invalid stream event "${e}"`);return e}function s(e,t){if(t)try{t=JSON.parse(t)}catch(e){throw new Error("Invalid stream data")}if("next"===e&&!t)throw new Error('Stream data must be an object for "next" events');return t||null}var l;!function(e){e[e.NewLine=10]="NewLine",e[e.CchunkiageReturn=13]="CchunkiageReturn",e[e.Space=32]="Space",e[e.Colon=58]="Colon"}(l||(l={}));class c extends Error{constructor(e){let t,n;var r;(function(e){return"object"==typeof e&&null!==e})(r=e)&&"boolean"==typeof r.ok&&"number"==typeof r.status&&"string"==typeof r.statusText?(n=e,t="Server responded with "+e.status+": "+e.statusText):t=e instanceof Error?e.message:String(e),super(t),this.name=this.constructor.name,this.response=n}}async function u(e){const{signal:t,url:a,credentials:u,headers:d,body:f,fetchFn:h,onMessage:w}=e,y={},b={};let p;try{p=await h(a,{signal:t,method:f?"POST":"GET",credentials:u,headers:Object.assign(Object.assign({},d),{accept:"text/event-stream"}),body:f})}catch(e){throw new c(e)}if(!p.ok)throw new c(p);if(!p.body)throw new Error("Missing response body");let g=null,v=null;return(async()=>{var e,t,a;try{const d=function(){let e,t,n,r=!1,o={event:"",data:""},a=[];const c=new TextDecoder;return function(u){if(void 0===e)e=u,t=0,n=-1;else{const t=new Uint8Array(e.length+u.length);t.set(e),t.set(u,e.length),e=t}const d=e.length;let f=0;for(;t<d;){r&&(e[t]===l.NewLine&&(f=++t),r=!1);let u=-1;for(;t<d&&-1===u;++t)switch(e[t]){case l.Colon:-1===n&&(n=t-f);break;case l.CchunkiageReturn:r=!0;case l.NewLine:u=t}if(-1===u)break;if(f===u){if(o.event||o.data){if(!o.event)throw new Error("Missing message event");const e=i(o.event),t=s(e,o.data);a.push({event:e,data:t}),o={event:"",data:""}}}else if(n>0){const t=e.subarray(f,u),r=c.decode(t.subarray(0,n)),a=n+(t[n+1]===l.Space?2:1),i=c.decode(t.subarray(a));switch(r){case"event":o.event=i;break;case"data":o.data=o.data?o.data+"\n"+i:i}}f=t,n=-1}if(f===d){e=void 0;const t=[...a];return a=[],t}0!==f&&(e=e.subarray(f),t-=f)}}();try{for(var c,u=o(function(e){if("function"==typeof Object(e)[Symbol.asyncIterator])return(e=e)[Symbol.asyncIterator]();return function(){return r(this,arguments,(function*(){const t=(e=e).getReader();for(;;){const{value:e,done:r}=yield n(t.read());if(r)return yield n(e);yield yield n(e)}}))}()}(p.body));!(c=await u.next()).done;){const e=c.value;if("string"==typeof e)throw new Error(`Unexpected string chunk "${e}"`);const t=d(e);if(t)for(const e of t){null==w||w(e);const t=e.data&&"id"in e.data?e.data.id:"";switch(t in b||(b[t]=[]),e.event){case"next":t?b[t].push(e.data.payload):b[t].push(e.data);break;case"complete":b[t].push("complete");break;default:throw new Error(`Unexpected message event "${e.event}"`)}null===(a=y[t])||void 0===a||a.proceed()}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(t=u.return)&&await t.call(u)}finally{if(e)throw e.error}}}catch(e){g=e,v&&v(e)}finally{Object.values(y).forEach((({proceed:e})=>e()))}})(),{url:a,headers:d,waitForThrow:()=>new Promise(((e,t)=>{if(g)return t(g);v=t})),getResults(e){var t;return r(this,arguments,(function*(){const{signal:r,operationId:o=""}=null!=e?e:{};try{for(;;){for(;null===(t=b[o])||void 0===t?void 0:t.length;){const e=b[o].shift();if("complete"===e)return yield n(void 0);yield yield n(e)}if(g)throw g;if(null==r?void 0:r.aborted)throw new Error("Getting results aborted by the client");yield n(new Promise((e=>{const t=()=>{null==r||r.removeEventListener("abort",t),delete y[o],e()};null==r||r.addEventListener("abort",t),y[o]={proceed:t}})))}}finally{delete b[o]}}))}}}e.NetworkError=c,e.TOKEN_HEADER_KEY=a,e.TOKEN_QUERY_KEY="token",e.createClient=function(e){const{singleConnection:t=!1,lazy:n=!0,lazyCloseTimeout:r=0,onNonLazyError:i=console.error,generateID:s=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},retryAttempts:l=5,retry:d=async function(e){let t=1e3;for(let n=0;n<e;n++)t*=2;await new Promise((e=>setTimeout(e,t+Math.floor(2700*Math.random()+300))))},credentials:f="same-origin",onMessage:h}=e,w=e.fetchFn||fetch,y=e.abortControllerImpl||AbortController,b=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:n=>e?(setTimeout((()=>n()),0),()=>{}):(t.push(n),()=>{t.splice(t.indexOf(n),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();let p,g,v=0,x=null,m=0;async function E(){try{if(b.disposed)throw new Error("Client has been disposed");return await(null!=g?g:g=(async()=>{var t;if(x){if(await d(m),p.signal.aborted)throw new Error("Connection aborted by the client");m++}p=new y;const n=b.onDispose((()=>p.abort()));p.signal.addEventListener("abort",(()=>{n(),g=void 0}));const r="function"==typeof e.url?await e.url():e.url;if(p.signal.aborted)throw new Error("Connection aborted by the client");const o="function"==typeof e.headers?await e.headers():null!==(t=e.headers)&&void 0!==t?t:{};if(p.signal.aborted)throw new Error("Connection aborted by the client");let i;try{i=await w(r,{signal:p.signal,method:"PUT",credentials:f,headers:o})}catch(e){throw new c(e)}if(201!==i.status)throw new c(i);const s=await i.text();o[a]=s;const l=await u({signal:p.signal,headers:o,credentials:f,url:r,fetchFn:w,onMessage:h});return x=null,m=0,l.waitForThrow().catch((()=>g=void 0)),l})())}catch(e){throw g=void 0,e}}return t&&!n&&(async()=>{for(v++;;)try{const{waitForThrow:e}=await E();await e()}catch(e){if(b.disposed)return;if(!(e instanceof c))return null==i?void 0:i(e);if(!l||m>=l)return null==i?void 0:i(e);x=e}})(),{subscribe(n,a){if(!t){const t=new y,r=b.onDispose((()=>{r(),t.abort()}));return(async()=>{var r,i,s;let y=null,b=0;for(;;)try{if(y){if(await d(b),t.signal.aborted)throw new Error("Connection aborted by the client");b++}const l="function"==typeof e.url?await e.url():e.url;if(t.signal.aborted)throw new Error("Connection aborted by the client");const c="function"==typeof e.headers?await e.headers():null!==(s=e.headers)&&void 0!==s?s:{};if(t.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:v}=await u({signal:t.signal,headers:c,credentials:f,url:l,body:JSON.stringify(n),fetchFn:w,onMessage:h});y=null,b=0;try{for(var p,g=(r=void 0,o(v()));!(p=await g.next()).done;){const e=p.value;a.next(e)}}catch(e){r={error:e}}finally{try{p&&!p.done&&(i=g.return)&&await i.call(g)}finally{if(r)throw r.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof c))throw e;if(!l||b>=l)throw e;y=e}})().then((()=>a.complete())).catch((e=>a.error(e))),()=>t.abort()}v++;const i=new y,g=b.onDispose((()=>{g(),i.abort()}));return(async()=>{var e,t;const u=s();n=Object.assign(Object.assign({},n),{extensions:Object.assign(Object.assign({},n.extensions),{operationId:u})});let d=null;for(;;){d=null;try{const{url:s,headers:l,getResults:x}=await E();let m;try{m=await w(s,{signal:i.signal,method:"POST",credentials:f,headers:l,body:JSON.stringify(n)})}catch(e){throw new c(e)}if(202!==m.status)throw new c(m);d=async()=>{let e;try{const t=new y,n=b.onDispose((()=>{n(),t.abort()}));e=await w(s+"?operationId="+u,{signal:t.signal,method:"DELETE",credentials:f,headers:l})}catch(e){throw new c(e)}if(200!==e.status)throw new c(e)};try{for(var h,g=(e=void 0,o(x({signal:i.signal,operationId:u})));!(h=await g.next()).done;){const e=h.value;a.next(e)}}catch(t){e={error:t}}finally{try{h&&!h.done&&(t=g.return)&&await t.call(g)}finally{if(e)throw e.error}}return d=null,i.abort()}catch(e){if(i.signal.aborted)return await(null==d?void 0:d());if(!(e instanceof c))throw e;if(!l||m>=l)throw e;x=e}finally{i.signal.aborted&&0==--v&&(isFinite(r)&&r>0?setTimeout((()=>{v||p.abort()}),r):p.abort())}}})().then((()=>a.complete())).catch((e=>a.error(e))),()=>i.abort()},dispose(){b.dispose()}}},e.parseStreamData=s,e.validateStreamEvent=i,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlSse={})}(this,(function(e){"use strict";function t(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(e){return this instanceof n?(this.v=e,this):new n(e)}function r(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,a=r.apply(e,t||[]),i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(e){a[e]&&(o[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||l(e,t)}))})}function l(e,t){try{(r=a[e](t)).value instanceof n?Promise.resolve(r.value.v).then(c,u):d(i[0][2],r)}catch(e){d(i[0][3],e)}var r}function c(e){l("next",e)}function u(e){l("throw",e)}function d(e,t){e(t),i.shift(),i.length&&l(i[0][0],i[0][1])}}function o(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=e[Symbol.asyncIterator];return r?r.call(e):(e=t(e),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(t){n[t]=e[t]&&function(n){return new Promise((function(r,o){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,o,(n=e[t](n)).done,n.value)}))}}}const a="x-graphql-event-stream-token";function i(e){if("next"!==e&&"complete"!==e)throw new Error(`Invalid stream event "${e}"`);return e}function s(e,t){if(t)try{t=JSON.parse(t)}catch(e){throw new Error("Invalid stream data")}if("next"===e&&!t)throw new Error('Stream data must be an object for "next" events');return t||null}var l;!function(e){e[e.NewLine=10]="NewLine",e[e.CchunkiageReturn=13]="CchunkiageReturn",e[e.Space=32]="Space",e[e.Colon=58]="Colon"}(l||(l={}));class c extends Error{constructor(e){let t,n;var r;(function(e){return"object"==typeof e&&null!==e})(r=e)&&"boolean"==typeof r.ok&&"number"==typeof r.status&&"string"==typeof r.statusText?(n=e,t="Server responded with "+e.status+": "+e.statusText):t=e instanceof Error?e.message:String(e),super(t),this.name=this.constructor.name,this.response=n}}async function u(e){const{signal:t,url:a,credentials:u,headers:d,body:f,fetchFn:h,onMessage:w}=e,y={},b={};let v;try{v=await h(a,{signal:t,method:f?"POST":"GET",credentials:u,headers:Object.assign(Object.assign({},d),{accept:"text/event-stream"}),body:f})}catch(e){throw new c(e)}if(!v.ok)throw new c(v);if(!v.body)throw new Error("Missing response body");let p,g=null;return(async()=>{var e,t,a;try{const c=function(){let e,t,n,r=!1,o={event:"",data:""},a=[];const c=new TextDecoder;return function(u){if(void 0===e)e=u,t=0,n=-1;else{const t=new Uint8Array(e.length+u.length);t.set(e),t.set(u,e.length),e=t}const d=e.length;let f=0;for(;t<d;){r&&(e[t]===l.NewLine&&(f=++t),r=!1);let u=-1;for(;t<d&&-1===u;++t)switch(e[t]){case l.Colon:-1===n&&(n=t-f);break;case l.CchunkiageReturn:r=!0;case l.NewLine:u=t}if(-1===u)break;if(f===u){if(o.event||o.data){if(!o.event)throw new Error("Missing message event");const e=i(o.event),t=s(e,o.data);a.push({event:e,data:t}),o={event:"",data:""}}}else if(n>0){const t=e.subarray(f,u),r=c.decode(t.subarray(0,n)),a=n+(t[n+1]===l.Space?2:1),i=c.decode(t.subarray(a));switch(r){case"event":o.event=i;break;case"data":o.data=o.data?o.data+"\n"+i:i}}f=t,n=-1}if(f===d){e=void 0;const t=[...a];return a=[],t}0!==f&&(e=e.subarray(f),t-=f)}}();try{for(var u,d=o(function(e){if("function"==typeof Object(e)[Symbol.asyncIterator])return e[Symbol.asyncIterator]();return function(){return r(this,arguments,(function*(){const t=e.getReader();let r;do{r=yield n(t.read()),void 0!==r.value&&(yield yield n(r.value))}while(!r.done)}))}()}(v.body));!(u=await d.next()).done;){const e=u.value;if("string"==typeof e)throw new Error(`Unexpected string chunk "${e}"`);const t=c(e);if(t)for(const e of t){null==w||w(e);const t=e.data&&"id"in e.data?e.data.id:"";switch(t in b||(b[t]=[]),e.event){case"next":t?b[t].push(e.data.payload):b[t].push(e.data);break;case"complete":b[t].push("complete");break;default:throw new Error(`Unexpected message event "${e.event}"`)}null===(a=y[t])||void 0===a||a.proceed()}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(t=d.return)&&await t.call(d)}finally{if(e)throw e.error}}}catch(e){g=/network/i.test(e)?new c(e):e,null==p||p(g)}finally{Object.values(y).forEach((({proceed:e})=>e()))}})(),{url:a,headers:d,waitForThrow:()=>new Promise(((e,t)=>{if(g)return t(g);p=t})),getResults(e){var t;return r(this,arguments,(function*(){const{signal:r,operationId:o=""}=null!=e?e:{};try{for(;;){for(;null===(t=b[o])||void 0===t?void 0:t.length;){const e=b[o].shift();if("complete"===e)return yield n(void 0);yield yield n(e)}if(g)throw g;if(null==r?void 0:r.aborted)throw new Error("Getting results aborted by the client");yield n(new Promise((e=>{const t=()=>{null==r||r.removeEventListener("abort",t),delete y[o],e()};null==r||r.addEventListener("abort",t),y[o]={proceed:t}})))}}finally{delete b[o]}}))}}}e.NetworkError=c,e.TOKEN_HEADER_KEY=a,e.TOKEN_QUERY_KEY="token",e.createClient=function(e){const{singleConnection:t=!1,lazy:n=!0,lazyCloseTimeout:r=0,onNonLazyError:i=console.error,generateID:s=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},retryAttempts:l=5,retry:d=async function(e){let t=1e3;for(let n=0;n<e;n++)t*=2;await new Promise((e=>setTimeout(e,t+Math.floor(2700*Math.random()+300))))},credentials:f="same-origin",onMessage:h}=e,w=e.fetchFn||fetch,y=e.abortControllerImpl||AbortController,b=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:n=>e?(setTimeout((()=>n()),0),()=>{}):(t.push(n),()=>{t.splice(t.indexOf(n),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();let v,p,g=0,x=null,m=0;async function E(){try{if(b.disposed)throw new Error("Client has been disposed");return await(null!=p?p:p=(async()=>{var t;if(x){if(await d(m),v.signal.aborted)throw new Error("Connection aborted by the client");m++}v=new y;const n=b.onDispose((()=>v.abort()));v.signal.addEventListener("abort",(()=>{n(),p=void 0}));const r="function"==typeof e.url?await e.url():e.url;if(v.signal.aborted)throw new Error("Connection aborted by the client");const o="function"==typeof e.headers?await e.headers():null!==(t=e.headers)&&void 0!==t?t:{};if(v.signal.aborted)throw new Error("Connection aborted by the client");let i;try{i=await w(r,{signal:v.signal,method:"PUT",credentials:f,headers:o})}catch(e){throw new c(e)}if(201!==i.status)throw new c(i);const s=await i.text();o[a]=s;const l=await u({signal:v.signal,headers:o,credentials:f,url:r,fetchFn:w,onMessage:h});return x=null,m=0,l.waitForThrow().catch((()=>p=void 0)),l})())}catch(e){throw p=void 0,e}}return t&&!n&&(async()=>{for(g++;;)try{const{waitForThrow:e}=await E();await e()}catch(e){if(b.disposed)return;if(!(e instanceof c))return null==i?void 0:i(e);if(p=void 0,!l||m>=l)return null==i?void 0:i(e);x=e}})(),{subscribe(a,i){if(!t){const t=new y,n=b.onDispose((()=>{n(),t.abort()}));return(async()=>{var n,r,s;let y=null,b=0;for(;;)try{if(y){if(await d(b),t.signal.aborted)throw new Error("Connection aborted by the client");b++}const l="function"==typeof e.url?await e.url():e.url;if(t.signal.aborted)throw new Error("Connection aborted by the client");const c="function"==typeof e.headers?await e.headers():null!==(s=e.headers)&&void 0!==s?s:{};if(t.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:g}=await u({signal:t.signal,headers:c,credentials:f,url:l,body:JSON.stringify(a),fetchFn:w,onMessage:h});y=null,b=0;try{for(var v,p=(n=void 0,o(g()));!(v=await p.next()).done;){const e=v.value;i.next(e)}}catch(e){n={error:e}}finally{try{v&&!v.done&&(r=p.return)&&await r.call(p)}finally{if(n)throw n.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof c))throw e;if(!l||b>=l)throw e;y=e}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>t.abort()}g++;const S=new y,T=b.onDispose((()=>{T(),S.abort()}));return(async()=>{var e,t;const u=s();a=Object.assign(Object.assign({},a),{extensions:Object.assign(Object.assign({},a.extensions),{operationId:u})});let d=null;for(;;){d=null;try{const{url:n,headers:s,getResults:l}=await E();let p;try{p=await w(n,{signal:S.signal,method:"POST",credentials:f,headers:s,body:JSON.stringify(a)})}catch(e){throw new c(e)}if(202!==p.status)throw new c(p);d=async()=>{let e;try{const t=new y,r=b.onDispose((()=>{r(),t.abort()}));e=await w(n+"?operationId="+u,{signal:t.signal,method:"DELETE",credentials:f,headers:s})}catch(e){throw new c(e)}if(200!==e.status)throw new c(e)};try{for(var h,T=(e=void 0,o(l({signal:S.signal,operationId:u})));!(h=await T.next()).done;){const e=h.value;i.next(e)}}catch(t){e={error:t}}finally{try{h&&!h.done&&(t=T.return)&&await t.call(T)}finally{if(e)throw e.error}}return d=null,S.abort()}catch(e){if(S.signal.aborted)return await(null==d?void 0:d());if(!(e instanceof c))throw e;if(n&&(p=void 0),!l||m>=l)throw e;x=e}finally{S.signal.aborted&&0==--g&&(isFinite(r)&&r>0?setTimeout((()=>{g||v.abort()}),r):v.abort())}}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>S.abort()},dispose(){b.dispose()}}},e.parseStreamData=s,e.validateStreamEvent=i,Object.defineProperty(e,"__esModule",{value:!0})})); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
217227
3886
36