Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-sse

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-sse - npm Package Compare versions

Comparing version 1.2.4 to 1.2.5

36

lib/client.js

@@ -480,9 +480,20 @@ "use strict";

if (typeof chunk === 'string')
throw new Error(`Unexpected string chunk "${chunk}"`);
throw (error = new Error(`Unexpected string chunk "${chunk}"`)); // set error as fatal indicator
// read chunk and if messages are ready, yield them
const msgs = parse(chunk);
let msgs;
try {
msgs = parse(chunk);
}
catch (err) {
throw (error = err); // set error as fatal indicator
}
if (!msgs)
continue;
for (const msg of msgs) {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
try {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
}
catch (err) {
throw (error = err); // set error as fatal indicator
}
const operationId = msg.data && 'id' in msg.data

@@ -504,3 +515,3 @@ ? msg.data.id // StreamDataForID

default:
throw new Error(`Unexpected message event "${msg.event}"`);
throw (error = new Error(`Unexpected message event "${msg.event}"`)); // set error as fatal indicator
}

@@ -521,13 +532,14 @@ (_b = waiting[operationId]) === null || _b === void 0 ? void 0 : _b.proceed();

if (Object.keys(waiting).length) {
throw new NetworkError('Connection closed while having active streams');
throw new Error('Connection closed while having active streams');
}
}
catch (err) {
// non-network errors shouldn't ever have "network" or "stream" in the message, right?
// keyword "network" is for Chrome and keyword "stream" is for Firefox, Safari closes
// the connection and that is handled above by checking for active streams
error =
!(err instanceof NetworkError) && /network|stream/i.test(err)
? new NetworkError(err)
: err;
if (!error && Object.keys(waiting).length) {
// we assume the error is most likely a NetworkError because there are listeners waiting for events.
// additionally, the `error` is another indicator because we set it early if the error is considered fatal
error = new NetworkError(err);
}
else {
error = err;
}
waitingForThrow === null || waitingForThrow === void 0 ? void 0 : waitingForThrow(error);

@@ -534,0 +546,0 @@ }

{
"name": "graphql-sse",
"version": "1.2.4",
"version": "1.2.5",
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client",

@@ -60,3 +60,3 @@ "keywords": [

"type-check": "tsc --noEmit",
"test": "jest",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.js",

@@ -84,8 +84,7 @@ "build:cjs": "tsc -b tsconfig.cjs.json",

"@types/express": "^4.17.13",
"@types/jest": "^28.1.4",
"@types/node-fetch": "^2.6.2",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"babel-jest": "^28.1.2",
"eslint": "^8.18.0",
"@types/jest": "^28.1.6",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"babel-jest": "^28.1.3",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",

@@ -95,15 +94,15 @@ "eslint-plugin-prettier": "^4.2.1",

"express": "^4.18.1",
"fastify": "^3.29.0",
"fastify": "^3.29.1",
"graphql": "^16.5.0",
"jest": "^28.1.2",
"jest-jasmine2": "^28.1.2",
"node-fetch": "^2.6.7",
"jest": "^28.1.3",
"jest-jasmine2": "^28.1.3",
"node-fetch": "^3.2.8",
"prettier": "^2.7.1",
"replacestream": "^4.0.3",
"rollup": "^2.75.7",
"rollup": "^2.77.0",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^19.0.3",
"tslib": "^2.4.0",
"typedoc": "^0.23.2",
"typedoc-plugin-markdown": "^3.13.2",
"typedoc": "^0.23.7",
"typedoc-plugin-markdown": "^3.13.3",
"typescript": "^4.7.4"

@@ -110,0 +109,0 @@ },

@@ -674,9 +674,20 @@ (function (global, factory) {

if (typeof chunk === 'string')
throw new Error(`Unexpected string chunk "${chunk}"`);
throw (error = new Error(`Unexpected string chunk "${chunk}"`)); // set error as fatal indicator
// read chunk and if messages are ready, yield them
const msgs = parse(chunk);
let msgs;
try {
msgs = parse(chunk);
}
catch (err) {
throw (error = err); // set error as fatal indicator
}
if (!msgs)
continue;
for (const msg of msgs) {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
try {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
}
catch (err) {
throw (error = err); // set error as fatal indicator
}
const operationId = msg.data && 'id' in msg.data

@@ -698,3 +709,3 @@ ? msg.data.id // StreamDataForID

default:
throw new Error(`Unexpected message event "${msg.event}"`);
throw (error = new Error(`Unexpected message event "${msg.event}"`)); // set error as fatal indicator
}

@@ -715,13 +726,14 @@ (_b = waiting[operationId]) === null || _b === void 0 ? void 0 : _b.proceed();

if (Object.keys(waiting).length) {
throw new NetworkError('Connection closed while having active streams');
throw new Error('Connection closed while having active streams');
}
}
catch (err) {
// non-network errors shouldn't ever have "network" or "stream" in the message, right?
// keyword "network" is for Chrome and keyword "stream" is for Firefox, Safari closes
// the connection and that is handled above by checking for active streams
error =
!(err instanceof NetworkError) && /network|stream/i.test(err)
? new NetworkError(err)
: err;
if (!error && Object.keys(waiting).length) {
// we assume the error is most likely a NetworkError because there are listeners waiting for events.
// additionally, the `error` is another indicator because we set it early if the error is considered fatal
error = new NetworkError(err);
}
else {
error = err;
}
waitingForThrow === null || waitingForThrow === void 0 ? void 0 : waitingForThrow(error);

@@ -728,0 +740,0 @@ }

@@ -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 p,g=null;return(async()=>{var e,t,a;try{const f=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=f(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}}if(Object.keys(y).length)throw new c("Connection closed while having active streams")}catch(e){g=e instanceof c||!/network|stream/i.test(e)?e:new c(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})}));
!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})}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc