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.1.0 to 1.2.0

21

lib/client.d.ts

@@ -6,7 +6,7 @@ /**

*/
import { RequestParams, Sink, ExecutionResult } from './common';
import { RequestParams, Sink, StreamMessage, ExecutionResult, StreamEvent } from './common';
/** This file is the entry point for browsers, re-export common elements. */
export * from './common';
/** @category Client */
export interface ClientOptions {
export interface ClientOptions<SingleConnection extends boolean = false> {
/**

@@ -26,3 +26,3 @@ * Reuses a single SSE connection for all GraphQL operations.

*/
singleConnection?: boolean;
singleConnection?: SingleConnection;
/**

@@ -40,3 +40,3 @@ * Controls when should the connection be established while using the

*/
lazy?: boolean;
lazy?: SingleConnection extends true ? boolean : never;
/**

@@ -53,3 +53,3 @@ * How long should the client wait before closing the connection after the last oparation has

*/
lazyCloseTimeout?: number;
lazyCloseTimeout?: SingleConnection extends true ? number : never;
/**

@@ -66,3 +66,3 @@ * Used ONLY when the client is in non-lazy mode (`lazy = false`). When

*/
onNonLazyError?: (error: unknown) => void;
onNonLazyError?: SingleConnection extends true ? (error: unknown) => void : never;
/**

@@ -146,2 +146,9 @@ * URL of the GraphQL over SSE server to connect.

retry?: (retries: number) => Promise<void>;
/**
* Browsers show stream messages in the DevTools **only** if they're received through the [native EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource),
* and because `graphql-sse` implements a custom SSE parser - received messages will **not** appear in browser's DevTools.
*
* Use this function if you want to inspect valid messages received through the active SSE connection.
*/
onMessage?: (message: StreamMessage<SingleConnection, StreamEvent>) => void;
}

@@ -176,3 +183,3 @@ /** @category Client */

*/
export declare function createClient(options: ClientOptions): Client;
export declare function createClient<SingleConnection extends boolean = false>(options: ClientOptions<SingleConnection>): Client;
/**

@@ -179,0 +186,0 @@ * A network error caused by the client or an unexpected response from the server.

@@ -83,3 +83,3 @@ "use strict";

Math.floor(Math.random() * (3000 - 300) + 300)));
}, credentials = 'same-origin', } = options;
}, credentials = 'same-origin', onMessage, } = options;
const fetchFn = (options.fetchFn || fetch);

@@ -174,2 +174,3 @@ const AbortControllerImpl = (options.abortControllerImpl ||

fetchFn,
onMessage,
});

@@ -251,2 +252,3 @@ retryingErr = null; // future connects are not retries

fetchFn,
onMessage,
});

@@ -442,3 +444,3 @@ retryingErr = null; // future connects are not retries

async function connect(options) {
const { signal, url, credentials, headers, body, fetchFn } = options;
const { signal, url, credentials, headers, body, fetchFn, onMessage } = options;
const waiting = {};

@@ -481,2 +483,3 @@ const queue = {};

for (const msg of msgs) {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
const operationId = msg.data && 'id' in msg.data

@@ -483,0 +486,0 @@ ? msg.data.id // StreamDataForID

@@ -45,3 +45,3 @@ /**

*/
export interface StreamMessage<ForID extends boolean = false, E extends StreamEvent = StreamEvent> {
export interface StreamMessage<ForID extends boolean, E extends StreamEvent> {
event: E;

@@ -71,5 +71,5 @@ data: ForID extends true ? StreamDataForID<E> : StreamData<E>;

/** @category Common */
export declare type StreamData<E extends StreamEvent = StreamEvent> = E extends 'next' ? ExecutionResult | ExecutionPatchResult : E extends 'complete' ? null : never;
export declare type StreamData<E extends StreamEvent> = E extends 'next' ? ExecutionResult | ExecutionPatchResult : E extends 'complete' ? null : never;
/** @category Common */
export declare type StreamDataForID<E extends StreamEvent = StreamEvent> = E extends 'next' ? {
export declare type StreamDataForID<E extends StreamEvent> = E extends 'next' ? {
id: string;

@@ -81,3 +81,3 @@ payload: ExecutionResult | ExecutionPatchResult;

/** @category Common */
export declare function parseStreamData(e: StreamEvent, data: string): StreamData;
export declare function parseStreamData<ForID extends boolean, E extends StreamEvent>(e: E, data: string): ForID extends true ? StreamDataForID<E> : StreamData<E>;
/**

@@ -84,0 +84,0 @@ * A representation of any set of values over any amount of time.

@@ -220,2 +220,2 @@ /**

export declare function createHandler<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse>(options: HandlerOptions<Request, Response>): Handler<Request, Response>;
export declare function isAsyncGenerator<T = unknown>(val: unknown): val is AsyncGenerator<T>;
export declare function isAsyncGenerator<T>(val: unknown): val is AsyncGenerator<T>;

@@ -6,3 +6,3 @@ /**

*/
import { StreamMessage } from './common';
import { StreamMessage, StreamEvent } from './common';
/**

@@ -15,2 +15,2 @@ * HTTP response chunk parser for graphql-sse's event stream messages.

*/
export declare function createParser(): (chunk: Uint8Array) => (StreamMessage<false> | StreamMessage<true>)[] | void;
export declare function createParser<ForID extends boolean>(): (chunk: Uint8Array) => StreamMessage<ForID, StreamEvent>[] | void;
{
"name": "graphql-sse",
"version": "1.1.0",
"version": "1.2.0",
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client",

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

"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/core": "^7.17.9",
"@babel/plugin-proposal-class-properties": "^7.16.7",

@@ -78,3 +78,3 @@ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",

"@babel/preset-typescript": "^7.16.7",
"@rollup/plugin-typescript": "^8.3.1",
"@rollup/plugin-typescript": "^8.3.2",
"@semantic-release/changelog": "^6.0.1",

@@ -86,6 +86,6 @@ "@semantic-release/git": "^10.0.1",

"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"babel-jest": "^27.5.1",
"eslint": "^8.10.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",

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

"express": "^4.17.3",
"fastify": "^3.27.4",
"fastify": "^3.28.0",
"graphql": "^16.3.0",
"jest": "^27.5.1",
"node-fetch": "^2.6.7",
"prettier": "^2.5.1",
"prettier": "^2.6.2",
"replacestream": "^4.0.3",
"rollup": "^2.70.0",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^19.0.2",
"tslib": "^2.3.1",
"typedoc": "^0.22.13",
"typedoc-plugin-markdown": "^3.11.14",
"typescript": "^4.6.2"
"typedoc": "^0.22.15",
"typedoc-plugin-markdown": "^3.12.0",
"typescript": "^4.6.3"
},

@@ -110,0 +110,0 @@ "resolutions": {

@@ -545,2 +545,16 @@ <div align="center">

<details id="client-debug-messages">
<summary><a href="#client-debug-messages">🔗</a> Client usage with logging of incoming messages (<a href="https://github.com/enisdenjo/graphql-sse/issues/20">browsers don't show them in the DevTools</a>)</summary>
```typescript
import { createClient } from 'graphql-sse';
const client = createClient({
url: 'http://let-me-see.messages:4000/graphql/stream',
onMessage: console.log,
});
```
</details>
<details id="browser">

@@ -547,0 +561,0 @@ <summary><a href="#browser">🔗</a> Client usage in browser</summary>

@@ -279,3 +279,3 @@ (function (global, factory) {

Math.floor(Math.random() * (3000 - 300) + 300)));
}, credentials = 'same-origin', } = options;
}, credentials = 'same-origin', onMessage, } = options;
const fetchFn = (options.fetchFn || fetch);

@@ -370,2 +370,3 @@ const AbortControllerImpl = (options.abortControllerImpl ||

fetchFn,
onMessage,
});

@@ -447,2 +448,3 @@ retryingErr = null; // future connects are not retries

fetchFn,
onMessage,
});

@@ -636,3 +638,3 @@ retryingErr = null; // future connects are not retries

async function connect(options) {
const { signal, url, credentials, headers, body, fetchFn } = options;
const { signal, url, credentials, headers, body, fetchFn, onMessage } = options;
const waiting = {};

@@ -675,2 +677,3 @@ const queue = {};

for (const msg of msgs) {
onMessage === null || onMessage === void 0 ? void 0 : onMessage(msg);
const operationId = msg.data && 'id' in msg.data

@@ -677,0 +680,0 @@ ? msg.data.id // StreamDataForID

@@ -15,2 +15,2 @@ !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";

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}=e,w={},y={};let b;try{b=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(!b.ok)throw new c(b);if(!b.body)throw new Error("Missing response body");let p=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)}}))}()}(b.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){const t=e.data&&"id"in e.data?e.data.id:"";switch(t in y||(y[t]=[]),e.event){case"next":t?y[t].push(e.data.payload):y[t].push(e.data);break;case"complete":y[t].push("complete");break;default:throw new Error(`Unexpected message event "${e.event}"`)}null===(a=w[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){p=e,v&&v(e)}finally{Object.values(w).forEach((({proceed:e})=>e()))}})(),{url:a,headers:d,waitForThrow:()=>new Promise(((e,t)=>{if(p)return t(p);v=t})),getResults(e){var t;return r(this,arguments,(function*(){const{signal:r,operationId:o=""}=null!=e?e:{};try{for(;;){for(;null===(t=y[o])||void 0===t?void 0:t.length;){const e=y[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 w[o],e()};null==r||r.addEventListener("abort",t),w[o]={proceed:t}})))}}finally{delete y[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"}=e,h=e.fetchFn||fetch,w=e.abortControllerImpl||AbortController,y=(()=>{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 b,p,v=0,g=null,x=0;async function m(){try{if(y.disposed)throw new Error("Client has been disposed");return await(null!=p?p:p=(async()=>{var t;if(g){if(await d(x),b.signal.aborted)throw new Error("Connection aborted by the client");x++}b=new w;const n=y.onDispose((()=>b.abort()));b.signal.addEventListener("abort",(()=>{n(),p=void 0}));const r="function"==typeof e.url?await e.url():e.url;if(b.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(b.signal.aborted)throw new Error("Connection aborted by the client");let i;try{i=await h(r,{signal:b.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:b.signal,headers:o,credentials:f,url:r,fetchFn:h});return g=null,x=0,l.waitForThrow().catch((()=>p=void 0)),l})())}catch(e){throw p=void 0,e}}return t&&!n&&(async()=>{for(v++;;)try{const{waitForThrow:e}=await m();await e()}catch(e){if(y.disposed)return;if(!(e instanceof c))return null==i?void 0:i(e);if(!l||x>=l)return null==i?void 0:i(e);g=e}})(),{subscribe(n,a){if(!t){const t=new w,r=y.onDispose((()=>{r(),t.abort()}));return(async()=>{var r,i,s;let w=null,y=0;for(;;)try{if(w){if(await d(y),t.signal.aborted)throw new Error("Connection aborted by the client");y++}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:h});w=null,y=0;try{for(var b,p=(r=void 0,o(v()));!(b=await p.next()).done;){const e=b.value;a.next(e)}}catch(e){r={error:e}}finally{try{b&&!b.done&&(i=p.return)&&await i.call(p)}finally{if(r)throw r.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof c))throw e;if(!l||y>=l)throw e;w=e}})().then((()=>a.complete())).catch((e=>a.error(e))),()=>t.abort()}v++;const i=new w,p=y.onDispose((()=>{p(),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:g}=await m();let x;try{x=await h(s,{signal:i.signal,method:"POST",credentials:f,headers:l,body:JSON.stringify(n)})}catch(e){throw new c(e)}if(202!==x.status)throw new c(x);d=async()=>{let e;try{const t=new w,n=y.onDispose((()=>{n(),t.abort()}));e=await h(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 p,E=(e=void 0,o(g({signal:i.signal,operationId:u})));!(p=await E.next()).done;){const e=p.value;a.next(e)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(t=E.return)&&await t.call(E)}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||x>=l)throw e;g=e}finally{i.signal.aborted&&0==--v&&(isFinite(r)&&r>0?setTimeout((()=>{v||b.abort()}),r):b.abort())}}})().then((()=>a.complete())).catch((e=>a.error(e))),()=>i.abort()},dispose(){y.dispose()}}},e.parseStreamData=s,e.validateStreamEvent=i,Object.defineProperty(e,"__esModule",{value:!0})}));
***************************************************************************** */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})}));

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

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