graphql-sse
Advanced tools
Comparing version 1.2.5 to 1.3.0
@@ -88,2 +88,24 @@ /** | ||
/** | ||
* A string specifying the referrer of the request. This can be a same-origin URL, about:client, or an empty string. | ||
* | ||
* @default undefined | ||
*/ | ||
referrer?: string; | ||
/** | ||
* Specifies the referrer policy to use for the request. | ||
* | ||
* Possible options are: | ||
* - `no-referrer`: Does not send referrer information along with requests to any origin. | ||
* - `no-referrer-when-downgrade`: Sends full referrerURL for requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL. | ||
* - `same-origin`: Sends full referrerURL as referrer information when making same-origin-referrer requests. | ||
* - `origin`: Sends only the ASCII serialization of the request’s referrerURL when making both same-origin-referrer requests and cross-origin-referrer requests. | ||
* - `strict-origin`: Sends the ASCII serialization of the origin of the referrerURL for requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL | ||
* - `origin-when-cross-origin`: Sends full referrerURL when making same-origin-referrer requests, and only the ASCII serialization of the origin of the request’s referrerURL is sent when making cross-origin-referrer requests | ||
* - `strict-origin-when-cross-origin`: Sends full referrerURL when making same-origin-referrer requests, and only the ASCII serialization of the origin of the request’s referrerURL when making cross-origin-referrer requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL. | ||
* - `unsafe-url`: Sends full referrerURL along for both same-origin-referrer requests and cross-origin-referrer requests. | ||
* | ||
* @default undefined | ||
*/ | ||
referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'; | ||
/** | ||
* HTTP headers to pass along the request. | ||
@@ -90,0 +112,0 @@ * |
@@ -83,3 +83,3 @@ "use strict"; | ||
Math.floor(Math.random() * (3000 - 300) + 300))); | ||
}, credentials = 'same-origin', onMessage, } = options; | ||
}, credentials = 'same-origin', referrer, referrerPolicy, onMessage, } = options; | ||
const fetchFn = (options.fetchFn || fetch); | ||
@@ -158,2 +158,4 @@ const AbortControllerImpl = (options.abortControllerImpl || | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -173,2 +175,4 @@ }); | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
url, | ||
@@ -252,2 +256,4 @@ fetchFn, | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
url, | ||
@@ -316,2 +322,4 @@ body: JSON.stringify(request), | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -338,2 +346,4 @@ body: JSON.stringify(request), | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -454,3 +464,3 @@ }); | ||
async function connect(options) { | ||
const { signal, url, credentials, headers, body, fetchFn, onMessage } = options; | ||
const { signal, url, credentials, headers, body, referrer, referrerPolicy, fetchFn, onMessage, } = options; | ||
const waiting = {}; | ||
@@ -464,2 +474,4 @@ const queue = {}; | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers: Object.assign(Object.assign({}, headers), { accept: 'text/event-stream' }), | ||
@@ -466,0 +478,0 @@ body, |
{ | ||
"name": "graphql-sse", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client", | ||
@@ -71,8 +71,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.18.6", | ||
"@babel/core": "^7.18.9", | ||
"@babel/plugin-proposal-class-properties": "^7.18.6", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.6", | ||
"@babel/plugin-proposal-optional-chaining": "^7.18.6", | ||
"@babel/preset-env": "^7.18.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.9", | ||
"@babel/plugin-proposal-optional-chaining": "^7.18.9", | ||
"@babel/preset-env": "^7.18.9", | ||
"@babel/preset-typescript": "^7.18.6", | ||
@@ -85,4 +85,4 @@ "@rollup/plugin-typescript": "^8.3.3", | ||
"@types/jest": "^28.1.6", | ||
"@typescript-eslint/eslint-plugin": "^5.30.6", | ||
"@typescript-eslint/parser": "^5.30.6", | ||
"@typescript-eslint/eslint-plugin": "^5.30.7", | ||
"@typescript-eslint/parser": "^5.30.7", | ||
"babel-jest": "^28.1.3", | ||
@@ -98,3 +98,3 @@ "eslint": "^8.20.0", | ||
"jest-jasmine2": "^28.1.3", | ||
"node-fetch": "^3.2.8", | ||
"node-fetch": "^3.2.9", | ||
"prettier": "^2.7.1", | ||
@@ -106,3 +106,3 @@ "replacestream": "^4.0.3", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.23.7", | ||
"typedoc": "^0.23.8", | ||
"typedoc-plugin-markdown": "^3.13.3", | ||
@@ -109,0 +109,0 @@ "typescript": "^4.7.4" |
@@ -279,3 +279,3 @@ (function (global, factory) { | ||
Math.floor(Math.random() * (3000 - 300) + 300))); | ||
}, credentials = 'same-origin', onMessage, } = options; | ||
}, credentials = 'same-origin', referrer, referrerPolicy, onMessage, } = options; | ||
const fetchFn = (options.fetchFn || fetch); | ||
@@ -354,2 +354,4 @@ const AbortControllerImpl = (options.abortControllerImpl || | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -369,2 +371,4 @@ }); | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
url, | ||
@@ -448,2 +452,4 @@ fetchFn, | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
url, | ||
@@ -512,2 +518,4 @@ body: JSON.stringify(request), | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -534,2 +542,4 @@ body: JSON.stringify(request), | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers, | ||
@@ -648,3 +658,3 @@ }); | ||
async function connect(options) { | ||
const { signal, url, credentials, headers, body, fetchFn, onMessage } = options; | ||
const { signal, url, credentials, headers, body, referrer, referrerPolicy, fetchFn, onMessage, } = options; | ||
const waiting = {}; | ||
@@ -658,2 +668,4 @@ const queue = {}; | ||
credentials, | ||
referrer, | ||
referrerPolicy, | ||
headers: Object.assign(Object.assign({}, headers), { accept: 'text/event-stream' }), | ||
@@ -660,0 +672,0 @@ body, |
@@ -1,1 +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";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 g,p=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 p=new Error(`Unexpected string chunk "${e}"`);let t;try{t=c(e)}catch(e){throw p=e}if(t)for(const e of t){try{null==w||w(e)}catch(e){throw p=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 p=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}}if(Object.keys(y).length)throw new Error("Connection closed while having active streams")}catch(e){p=!p&&Object.keys(y).length?new c(e):e,null==g||g(p)}finally{Object.values(y).forEach((({proceed:e})=>e()))}})(),{url:a,headers:d,waitForThrow:()=>new Promise(((e,t)=>{if(p)return t(p);g=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(p)throw p;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,g,p=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),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(),g=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((()=>g=void 0)),l})())}catch(e){throw g=void 0,e}}return t&&!n&&(async()=>{for(p++;;)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(g=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:p}=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,g=(n=void 0,o(p()));!(v=await g.next()).done;){const e=v.value;i.next(e)}}catch(e){n={error:e}}finally{try{v&&!v.done&&(r=g.return)&&await r.call(g)}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()}p++;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 g;try{g=await w(n,{signal:S.signal,method:"POST",credentials:f,headers:s,body:JSON.stringify(a)})}catch(e){throw new c(e)}if(202!==g.status)throw new c(g);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&&(g=void 0),!l||m>=l)throw e;x=e}finally{S.signal.aborted&&0==--p&&(isFinite(r)&&r>0?setTimeout((()=>{p||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})})); | ||
!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,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function r(e){return this instanceof r?(this.v=e,this):new r(e)}function n(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,a=n.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(r,n){i.push([e,t,r,n])>1||l(e,t)}))})}function l(e,t){try{(n=a[e](t)).value instanceof r?Promise.resolve(n.value.v).then(c,f):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function c(e){l("next",e)}function f(e){l("throw",e)}function u(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 r,n=e[Symbol.asyncIterator];return n?n.call(e):(e=t(e),r={},o("next"),o("throw"),o("return"),r[Symbol.asyncIterator]=function(){return this},r);function o(t){r[t]=e[t]&&function(r){return new Promise((function(n,o){(function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)})(n,o,(r=e[t](r)).done,r.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,r;var n;(function(e){return"object"==typeof e&&null!==e})(n=e)&&"boolean"==typeof n.ok&&"number"==typeof n.status&&"string"==typeof n.statusText?(r=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=r}}async function f(e){const{signal:t,url:a,credentials:f,headers:u,body:d,referrer:h,referrerPolicy:y,fetchFn:w,onMessage:b}=e,v={},g={};let p;try{p=await w(a,{signal:t,method:d?"POST":"GET",credentials:f,referrer:h,referrerPolicy:y,headers:Object.assign(Object.assign({},u),{accept:"text/event-stream"}),body:d})}catch(e){throw new c(e)}if(!p.ok)throw new c(p);if(!p.body)throw new Error("Missing response body");let x,m=null;return(async()=>{var e,t,a;try{const c=function(){let e,t,r,n=!1,o={event:"",data:""},a=[];const c=new TextDecoder;return function(f){if(void 0===e)e=f,t=0,r=-1;else{const t=new Uint8Array(e.length+f.length);t.set(e),t.set(f,e.length),e=t}const u=e.length;let d=0;for(;t<u;){n&&(e[t]===l.NewLine&&(d=++t),n=!1);let f=-1;for(;t<u&&-1===f;++t)switch(e[t]){case l.Colon:-1===r&&(r=t-d);break;case l.CchunkiageReturn:n=!0;case l.NewLine:f=t}if(-1===f)break;if(d===f){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(r>0){const t=e.subarray(d,f),n=c.decode(t.subarray(0,r)),a=r+(t[r+1]===l.Space?2:1),i=c.decode(t.subarray(a));switch(n){case"event":o.event=i;break;case"data":o.data=o.data?o.data+"\n"+i:i}}d=t,r=-1}if(d===u){e=void 0;const t=[...a];return a=[],t}0!==d&&(e=e.subarray(d),t-=d)}}();try{for(var f,u=o(function(e){if("function"==typeof Object(e)[Symbol.asyncIterator])return e[Symbol.asyncIterator]();return function(){return n(this,arguments,(function*(){const t=e.getReader();let n;do{n=yield r(t.read()),void 0!==n.value&&(yield yield r(n.value))}while(!n.done)}))}()}(p.body));!(f=await u.next()).done;){const e=f.value;if("string"==typeof e)throw m=new Error(`Unexpected string chunk "${e}"`);let t;try{t=c(e)}catch(e){throw m=e}if(t)for(const e of t){try{null==b||b(e)}catch(e){throw m=e}const t=e.data&&"id"in e.data?e.data.id:"";switch(t in g||(g[t]=[]),e.event){case"next":t?g[t].push(e.data.payload):g[t].push(e.data);break;case"complete":g[t].push("complete");break;default:throw m=new Error(`Unexpected message event "${e.event}"`)}null===(a=v[t])||void 0===a||a.proceed()}}}catch(t){e={error:t}}finally{try{f&&!f.done&&(t=u.return)&&await t.call(u)}finally{if(e)throw e.error}}if(Object.keys(v).length)throw new Error("Connection closed while having active streams")}catch(e){m=!m&&Object.keys(v).length?new c(e):e,null==x||x(m)}finally{Object.values(v).forEach((({proceed:e})=>e()))}})(),{url:a,headers:u,waitForThrow:()=>new Promise(((e,t)=>{if(m)return t(m);x=t})),getResults(e){var t;return n(this,arguments,(function*(){const{signal:n,operationId:o=""}=null!=e?e:{};try{for(;;){for(;null===(t=g[o])||void 0===t?void 0:t.length;){const e=g[o].shift();if("complete"===e)return yield r(void 0);yield yield r(e)}if(m)throw m;if(null==n?void 0:n.aborted)throw new Error("Getting results aborted by the client");yield r(new Promise((e=>{const t=()=>{null==n||n.removeEventListener("abort",t),delete v[o],e()};null==n||n.addEventListener("abort",t),v[o]={proceed:t}})))}}finally{delete g[o]}}))}}}e.NetworkError=c,e.TOKEN_HEADER_KEY=a,e.TOKEN_QUERY_KEY="token",e.createClient=function(e){const{singleConnection:t=!1,lazy:r=!0,lazyCloseTimeout:n=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:u=async function(e){let t=1e3;for(let r=0;r<e;r++)t*=2;await new Promise((e=>setTimeout(e,t+Math.floor(2700*Math.random()+300))))},credentials:d="same-origin",referrer:h,referrerPolicy:y,onMessage:w}=e,b=e.fetchFn||fetch,v=e.abortControllerImpl||AbortController,g=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:r=>e?(setTimeout((()=>r()),0),()=>{}):(t.push(r),()=>{t.splice(t.indexOf(r),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();let p,x,m=0,E=null,S=0;async function T(){try{if(g.disposed)throw new Error("Client has been disposed");return await(null!=x?x:x=(async()=>{var t;if(E){if(await u(S),p.signal.aborted)throw new Error("Connection aborted by the client");S++}p=new v;const r=g.onDispose((()=>p.abort()));p.signal.addEventListener("abort",(()=>{r(),x=void 0}));const n="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 b(n,{signal:p.signal,method:"PUT",credentials:d,referrer:h,referrerPolicy:y,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 f({signal:p.signal,headers:o,credentials:d,referrer:h,referrerPolicy:y,url:n,fetchFn:b,onMessage:w});return E=null,S=0,l.waitForThrow().catch((()=>x=void 0)),l})())}catch(e){throw x=void 0,e}}return t&&!r&&(async()=>{for(m++;;)try{const{waitForThrow:e}=await T();await e()}catch(e){if(g.disposed)return;if(!(e instanceof c))return null==i?void 0:i(e);if(x=void 0,!l||S>=l)return null==i?void 0:i(e);E=e}})(),{subscribe(a,i){if(!t){const t=new v,r=g.onDispose((()=>{r(),t.abort()}));return(async()=>{var r,n,s;let v=null,g=0;for(;;)try{if(v){if(await u(g),t.signal.aborted)throw new Error("Connection aborted by the client");g++}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:m}=await f({signal:t.signal,headers:c,credentials:d,referrer:h,referrerPolicy:y,url:l,body:JSON.stringify(a),fetchFn:b,onMessage:w});v=null,g=0;try{for(var p,x=(r=void 0,o(m()));!(p=await x.next()).done;){const e=p.value;i.next(e)}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=x.return)&&await n.call(x)}finally{if(r)throw r.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof c))throw e;if(!l||g>=l)throw e;v=e}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>t.abort()}m++;const O=new v,C=g.onDispose((()=>{C(),O.abort()}));return(async()=>{var e,t;const f=s();a=Object.assign(Object.assign({},a),{extensions:Object.assign(Object.assign({},a.extensions),{operationId:f})});let u=null;for(;;){u=null;try{const{url:r,headers:s,getResults:l}=await T();let x;try{x=await b(r,{signal:O.signal,method:"POST",credentials:d,referrer:h,referrerPolicy:y,headers:s,body:JSON.stringify(a)})}catch(e){throw new c(e)}if(202!==x.status)throw new c(x);u=async()=>{let e;try{const t=new v,n=g.onDispose((()=>{n(),t.abort()}));e=await b(r+"?operationId="+f,{signal:t.signal,method:"DELETE",credentials:d,referrer:h,referrerPolicy:y,headers:s})}catch(e){throw new c(e)}if(200!==e.status)throw new c(e)};try{for(var w,C=(e=void 0,o(l({signal:O.signal,operationId:f})));!(w=await C.next()).done;){const e=w.value;i.next(e)}}catch(t){e={error:t}}finally{try{w&&!w.done&&(t=C.return)&&await t.call(C)}finally{if(e)throw e.error}}return u=null,O.abort()}catch(e){if(O.signal.aborted)return await(null==u?void 0:u());if(!(e instanceof c))throw e;if(r&&(x=void 0),!l||S>=l)throw e;E=e}finally{O.signal.aborted&&0==--m&&(isFinite(n)&&n>0?setTimeout((()=>{m||p.abort()}),n):p.abort())}}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>O.abort()},dispose(){g.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
224850
4012