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 2.0.0 to 2.1.0

8

lib/use/express.d.ts
import type { Request, Response } from 'express';
import { HandlerOptions, OperationContext } from '../handler';
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
/**

@@ -10,2 +10,6 @@ * @category Server/express

/**
* @category Server/fetch
*/
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
/**
* The ready-to-use handler for [express](https://expressjs.com).

@@ -46,2 +50,2 @@ *

*/
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Request, RequestContext, Context>): (req: Request, res: Response) => Promise<void>;
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: Request, res: Response) => Promise<void>;

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

// body was parsed by middleware
return req.body;
return resolve(req.body);
}

@@ -67,0 +67,0 @@ let body = '';

import type { FastifyRequest, FastifyReply } from 'fastify';
import { HandlerOptions, OperationContext } from '../handler';
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
/**

@@ -10,2 +10,6 @@ * @category Server/fastify

/**
* @category Server/fetch
*/
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, RequestContext, Context>;
/**
* The ready-to-use handler for [fastify](https://www.fastify.io).

@@ -45,2 +49,2 @@ *

*/
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<FastifyRequest, RequestContext, Context>): (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: FastifyRequest, reply: FastifyReply) => Promise<void>;

@@ -63,3 +63,4 @@ "use strict";

// body was parsed by middleware
return req.body;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- even if fastify incorrectly parsed the body, we cannot re-read it
return resolve(req.body);
}

@@ -66,0 +67,0 @@ let body = '';

@@ -1,2 +0,2 @@

import { HandlerOptions, OperationContext } from '../handler';
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
/**

@@ -11,2 +11,6 @@ * @category Server/fetch

/**
* @category Server/fetch
*/
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
/**
* The ready-to-use fetch handler. To be used with your favourite fetch

@@ -42,2 +46,2 @@ * framework, in a lambda function, or have deploy to the edge.

*/
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Request, RequestContext, Context>, reqCtx?: Partial<RequestContext>): (req: Request) => Promise<Response>;
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>, reqCtx?: Partial<RequestContext>): (req: Request) => Promise<Response>;
/// <reference types="node" />
import type { IncomingMessage, ServerResponse } from 'http';
import { HandlerOptions, OperationContext } from '../handler';
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
/**

@@ -11,2 +11,6 @@ * @category Server/http

/**
* @category Server/fetch
*/
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
/**
* The ready-to-use handler for Node's [http](https://nodejs.org/api/http.html).

@@ -45,2 +49,2 @@ *

*/
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<IncomingMessage, RequestContext, Context>): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
/// <reference types="node" />
import type { Http2ServerRequest, Http2ServerResponse } from 'http2';
import { HandlerOptions, OperationContext } from '../handler';
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
/**

@@ -11,2 +11,6 @@ * @category Server/http2

/**
* @category Server/fetch
*/
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Http2ServerRequest, RequestContext, Context>;
/**
* The ready-to-use handler for Node's [http](https://nodejs.org/api/http2.html).

@@ -45,2 +49,2 @@ *

*/
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Http2ServerRequest, RequestContext, Context>): (req: Http2ServerRequest, res: Http2ServerResponse) => Promise<void>;
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: Http2ServerRequest, res: Http2ServerResponse) => Promise<void>;
{
"name": "graphql-sse",
"version": "2.0.0",
"version": "2.1.0",
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client",

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

},
"packageManager": "yarn@3.3.0",
"packageManager": "yarn@3.4.1",
"main": "lib/index.js",

@@ -91,3 +91,3 @@ "module": "lib/index.mjs",

"build:cjs": "tsc -b tsconfig.cjs.json",
"build:umd": "rollup --bundleConfigAsCjs --config rollup.config.ts --configPlugin typescript && gzip umd/graphql-sse.min.js -c > umd/graphql-sse.min.js.gz",
"build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
"build": "yarn build:esm && yarn build:cjs && yarn build:umd",

@@ -100,36 +100,37 @@ "release": "semantic-release"

"devDependencies": {
"@babel/core": "^7.20.5",
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.2",
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-terser": "^0.2.0",
"@rollup/plugin-typescript": "^10.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/git": "^10.0.1",
"@types/eslint": "^8.4.10",
"@types/eventsource": "^1.1.10",
"@types/express": "^4.17.15",
"@types/glob": "^8.0.0",
"@types/jest": "^29.2.4",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"babel-jest": "^29.3.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"@types/eslint": "^8.21.1",
"@types/eventsource": "^1.1.11",
"@types/express": "^4.17.17",
"@types/glob": "^8.0.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"babel-jest": "^29.4.3",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"express": "^4.18.2",
"fastify": "^4.10.2",
"glob": "^8.0.3",
"fastify": "^4.13.0",
"glob": "^8.1.0",
"graphql": "^16.6.0",
"jest": "^29.3.1",
"prettier": "^2.8.1",
"rollup": "^3.7.5",
"semantic-release": "^19.0.5",
"tslib": "^2.4.1",
"typedoc": "^0.23.23",
"jest": "^29.4.3",
"prettier": "^2.8.4",
"rollup": "^3.16.0",
"rollup-plugin-gzip": "^3.1.0",
"semantic-release": "^20.1.0",
"tslib": "^2.5.0",
"typedoc": "^0.23.25",
"typedoc-plugin-markdown": "^3.14.0",
"typescript": "^4.9.4"
"typescript": "^4.9.5"
}
}

@@ -106,4 +106,4 @@ <div align="center">

// Create an HTTP server using the handler on `/graphql/stream`
const server = http.createServer((req, res) => {
// Create an HTTP/2 server using the handler on `/graphql/stream`
const server = http2.createServer((req, res) => {
if (req.url.startsWith('/graphql/stream')) {

@@ -110,0 +110,0 @@ return handler(req, res);

@@ -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,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||c(e,t)}))})}function c(e,t){try{(n=a[e](t)).value instanceof r?Promise.resolve(n.value.v).then(l,f):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function l(e){c("next",e)}function f(e){c("throw",e)}function u(e,t){e(t),i.shift(),i.length&&c(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)}))}}}function a(e){return"object"==typeof e&&null!==e}const i="x-graphql-event-stream-token";function s(e){if("next"!==e&&"complete"!==e)throw new Error(`Invalid stream event "${e}"`);return e}function c(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 f extends Error{constructor(e){let t,r;var n;a(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 u(e){const{signal:t,url:a,credentials:i,headers:u,body:d,referrer:h,referrerPolicy:y,fetchFn:w,onMessage:b}=e,p={},g={};let v;try{v=await w(a,{signal:t,method:d?"POST":"GET",credentials:i,referrer:h,referrerPolicy:y,headers:Object.assign(Object.assign({},u),{accept:"text/event-stream"}),body:d})}catch(e){throw new f(e)}if(!v.ok)throw new f(v);if(!v.body)throw new Error("Missing response body");let x,m=null;return(async()=>{var e,t,a,i,u;try{const f=function(){let e,t,r,n=!1,o={event:"",data:""},a=[];const i=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=s(o.event),t=c(e,o.data);a.push({event:e,data:t}),o={event:"",data:""}}}else if(r>0){const t=e.subarray(d,f),n=i.decode(t.subarray(0,r)),a=r+(t[r+1]===l.Space?2:1),s=i.decode(t.subarray(a));switch(n){case"event":o.event=s;break;case"data":o.data=o.data?o.data+"\n"+s:s}}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 d,h=!0,y=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)}))}()}(v.body));!(e=(d=await y.next()).done);){i=d.value,h=!1;try{const e=i;if("string"==typeof e)throw m=new Error(`Unexpected string chunk "${e}"`);let t;try{t=f(e)}catch(e){throw m=e}if(!t)continue;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===(u=p[t])||void 0===u||u.proceed()}}finally{h=!0}}}catch(e){t={error:e}}finally{try{h||e||!(a=y.return)||await a.call(y)}finally{if(t)throw t.error}}if(Object.keys(p).length)throw new Error("Connection closed while having active streams")}catch(e){m=!m&&Object.keys(p).length?new f(e):e,null==x||x(m)}finally{Object.values(p).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 p[o],e()};null==n||n.addEventListener("abort",t),p[o]={proceed:t}})))}}finally{delete g[o]}}))}}}e.NetworkError=f,e.TOKEN_HEADER_KEY=i,e.TOKEN_QUERY_KEY="token",e.createClient=function(e){const{singleConnection:t=!1,lazy:r=!0,lazyCloseTimeout:n=0,onNonLazyError:a=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:c=5,retry:l=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,p=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 v,x,m=0,E=null,S=0;async function O(){try{if(g.disposed)throw new Error("Client has been disposed");return await(null!=x?x:x=(async()=>{var t;if(E){if(await l(S),v.signal.aborted)throw new Error("Connection aborted by the client");S++}v=new p;const r=g.onDispose((()=>v.abort()));v.signal.addEventListener("abort",(()=>{r(),x=void 0}));const n="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 a;try{a=await b(n,{signal:v.signal,method:"PUT",credentials:d,referrer:h,referrerPolicy:y,headers:o})}catch(e){throw new f(e)}if(201!==a.status)throw new f(a);const s=await a.text();o[i]=s;const c=await u({signal:v.signal,headers:o,credentials:d,referrer:h,referrerPolicy:y,url:n,fetchFn:b,onMessage:w});return E=null,S=0,c.waitForThrow().catch((()=>x=void 0)),c})())}catch(e){throw x=void 0,e}}return t&&!r&&(async()=>{for(m++;;)try{const{waitForThrow:e}=await O();await e()}catch(e){if(g.disposed)return;if(!(e instanceof f))return null==a?void 0:a(e);if(x=void 0,!c||S>=c)return null==a?void 0:a(e);E=e}})(),{subscribe(a,i){if(!t){const t=new p,r=g.onDispose((()=>{r(),t.abort()}));return(async()=>{var r,n,s,p,g;let v=null,x=0;for(;;)try{if(v){if(await l(x),t.signal.aborted)throw new Error("Connection aborted by the client");x++}const c="function"==typeof e.url?await e.url():e.url;if(t.signal.aborted)throw new Error("Connection aborted by the client");const f="function"==typeof e.headers?await e.headers():null!==(g=e.headers)&&void 0!==g?g:{};if(t.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:O}=await u({signal:t.signal,headers:Object.assign(Object.assign({},f),{"content-type":"application/json; charset=utf-8"}),credentials:d,referrer:h,referrerPolicy:y,url:c,body:JSON.stringify(a),fetchFn:b,onMessage:w});v=null,x=0;try{for(var m,E=!0,S=(n=void 0,o(O()));!(r=(m=await S.next()).done);){p=m.value,E=!1;try{const e=p;i.next(e)}finally{E=!0}}}catch(e){n={error:e}}finally{try{E||r||!(s=S.return)||await s.call(S)}finally{if(n)throw n.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof f))throw e;if(!c||x>=c)throw e;v=e}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>t.abort()}m++;const j=new p,T=g.onDispose((()=>{T(),j.abort()}));return(async()=>{var e,t,l,u;const w=s();a=Object.assign(Object.assign({},a),{extensions:Object.assign(Object.assign({},a.extensions),{operationId:w})});let T=null;for(;;){T=null;try{const{url:r,headers:s,getResults:c}=await O();let x;try{x=await b(r,{signal:j.signal,method:"POST",credentials:d,referrer:h,referrerPolicy:y,headers:Object.assign(Object.assign({},s),{"content-type":"application/json; charset=utf-8"}),body:JSON.stringify(a)})}catch(e){throw new f(e)}if(202!==x.status)throw new f(x);T=async()=>{let e;try{const t=new p,n=g.onDispose((()=>{n(),t.abort()}));e=await b(r+"?operationId="+w,{signal:t.signal,method:"DELETE",credentials:d,referrer:h,referrerPolicy:y,headers:s})}catch(e){throw new f(e)}if(200!==e.status)throw new f(e)};try{for(var I,C=!0,P=(t=void 0,o(c({signal:j.signal,operationId:w})));!(e=(I=await P.next()).done);){u=I.value,C=!1;try{const e=u;i.next(e)}finally{C=!0}}}catch(e){t={error:e}}finally{try{C||e||!(l=P.return)||await l.call(P)}finally{if(t)throw t.error}}return T=null,j.abort()}catch(e){if(j.signal.aborted)return await(null==T?void 0:T());if(!(e instanceof f))throw j.abort(),e;if(r&&(x=void 0),!c||S>=c)throw j.abort(),e;E=e}finally{j.signal.aborted&&0==--m&&(isFinite(n)&&n>0?setTimeout((()=>{m||v.abort()}),n):v.abort())}}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>j.abort()},dispose(){g.dispose()}}},e.isAsyncGenerator=function(e){return a(e)&&"function"==typeof Object(e)[Symbol.asyncIterator]&&"function"==typeof e.return&&"function"==typeof e.throw&&"function"==typeof e.next},e.isAsyncIterable=function(e){return"function"==typeof Object(e)[Symbol.asyncIterator]},e.parseStreamData=c,e.print=function(e){let t=`event: ${e.event}`;return e.data&&(t+=`\ndata: ${JSON.stringify(e.data)}`),t+="\n\n",t},e.validateStreamEvent=s}));
!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||c(e,t)}))})}function c(e,t){try{(n=a[e](t)).value instanceof r?Promise.resolve(n.value.v).then(l,f):u(i[0][2],n)}catch(e){u(i[0][3],e)}var n}function l(e){c("next",e)}function f(e){c("throw",e)}function u(e,t){e(t),i.shift(),i.length&&c(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)}))}}}function a(e){return"object"==typeof e&&null!==e}const i="x-graphql-event-stream-token";function s(e){if("next"!==e&&"complete"!==e)throw new Error(`Invalid stream event "${e}"`);return e}function c(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 f extends Error{constructor(e){let t,r;var n;a(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 u(e){const{signal:t,url:a,credentials:i,headers:u,body:d,referrer:h,referrerPolicy:y,fetchFn:w,onMessage:b}=e,p={},g={};let v;try{v=await w(a,{signal:t,method:d?"POST":"GET",credentials:i,referrer:h,referrerPolicy:y,headers:Object.assign(Object.assign({},u),{accept:"text/event-stream"}),body:d})}catch(e){throw new f(e)}if(!v.ok)throw new f(v);if(!v.body)throw new Error("Missing response body");let x,m=null;return(async()=>{var e,t,a,i,u;try{const f=function(){let e,t,r,n=!1,o={event:"",data:""},a=[];const i=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=s(o.event),t=c(e,o.data);a.push({event:e,data:t}),o={event:"",data:""}}}else if(r>0){const t=e.subarray(d,f),n=i.decode(t.subarray(0,r)),a=r+(t[r+1]===l.Space?2:1),s=i.decode(t.subarray(a));switch(n){case"event":o.event=s;break;case"data":o.data=o.data?o.data+"\n"+s:s}}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 d,h=!0,y=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)}))}()}(v.body));!(e=(d=await y.next()).done);){i=d.value,h=!1;try{const e=i;if("string"==typeof e)throw m=new Error(`Unexpected string chunk "${e}"`);let t;try{t=f(e)}catch(e){throw m=e}if(!t)continue;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===(u=p[t])||void 0===u||u.proceed()}}finally{h=!0}}}catch(e){t={error:e}}finally{try{h||e||!(a=y.return)||await a.call(y)}finally{if(t)throw t.error}}if(Object.keys(p).length)throw new Error("Connection closed while having active streams")}catch(e){m=!m&&Object.keys(p).length?new f(e):e,null==x||x(m)}finally{Object.values(p).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 p[o],e()};null==n||n.addEventListener("abort",t),p[o]={proceed:t}})))}}finally{delete g[o]}}))}}}e.NetworkError=f,e.TOKEN_HEADER_KEY=i,e.TOKEN_QUERY_KEY="token",e.createClient=function(e){const{singleConnection:t=!1,lazy:r=!0,lazyCloseTimeout:n=0,onNonLazyError:a=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:c=5,retry:l=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,p=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 v,x,m=0,E=null,S=0;async function O(){try{if(g.disposed)throw new Error("Client has been disposed");return await(null!=x?x:x=(async()=>{var t;if(E){if(await l(S),v.signal.aborted)throw new Error("Connection aborted by the client");S++}v=new p;const r=g.onDispose((()=>v.abort()));v.signal.addEventListener("abort",(()=>{r(),x=void 0}));const n="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 a;try{a=await b(n,{signal:v.signal,method:"PUT",credentials:d,referrer:h,referrerPolicy:y,headers:o})}catch(e){throw new f(e)}if(201!==a.status)throw new f(a);const s=await a.text();o[i]=s;const c=await u({signal:v.signal,headers:o,credentials:d,referrer:h,referrerPolicy:y,url:n,fetchFn:b,onMessage:w});return E=null,S=0,c.waitForThrow().catch((()=>x=void 0)),c})())}catch(e){throw x=void 0,e}}return t&&!r&&(async()=>{for(m++;;)try{const{waitForThrow:e}=await O();await e()}catch(e){if(g.disposed)return;if(!(e instanceof f))return null==a?void 0:a(e);if(x=void 0,!c||S>=c)return null==a?void 0:a(e);E=e}})(),{subscribe(a,i){if(!t){const t=new p,r=g.onDispose((()=>{r(),t.abort()}));return(async()=>{var r,n,s,p,g;let v=null,x=0;for(;;)try{if(v){if(await l(x),t.signal.aborted)throw new Error("Connection aborted by the client");x++}const c="function"==typeof e.url?await e.url():e.url;if(t.signal.aborted)throw new Error("Connection aborted by the client");const f="function"==typeof e.headers?await e.headers():null!==(g=e.headers)&&void 0!==g?g:{};if(t.signal.aborted)throw new Error("Connection aborted by the client");const{getResults:O}=await u({signal:t.signal,headers:Object.assign(Object.assign({},f),{"content-type":"application/json; charset=utf-8"}),credentials:d,referrer:h,referrerPolicy:y,url:c,body:JSON.stringify(a),fetchFn:b,onMessage:w});v=null,x=0;try{for(var m,E=!0,S=(n=void 0,o(O()));!(r=(m=await S.next()).done);){p=m.value,E=!1;try{const e=p;i.next(e)}finally{E=!0}}}catch(e){n={error:e}}finally{try{E||r||!(s=S.return)||await s.call(S)}finally{if(n)throw n.error}}return t.abort()}catch(e){if(t.signal.aborted)return;if(!(e instanceof f))throw e;if(!c||x>=c)throw e;v=e}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>t.abort()}m++;const j=new p,T=g.onDispose((()=>{T(),j.abort()}));return(async()=>{var e,t,l,u;const w=s();a=Object.assign(Object.assign({},a),{extensions:Object.assign(Object.assign({},a.extensions),{operationId:w})});let T=null;for(;;){T=null;try{const{url:r,headers:n,getResults:s}=await O();let c;try{c=await b(r,{signal:j.signal,method:"POST",credentials:d,referrer:h,referrerPolicy:y,headers:Object.assign(Object.assign({},n),{"content-type":"application/json; charset=utf-8"}),body:JSON.stringify(a)})}catch(e){throw new f(e)}if(202!==c.status)throw new f(c);T=async()=>{let e;try{const t=new p,o=g.onDispose((()=>{o(),t.abort()}));e=await b(r+"?operationId="+w,{signal:t.signal,method:"DELETE",credentials:d,referrer:h,referrerPolicy:y,headers:n})}catch(e){throw new f(e)}if(200!==e.status)throw new f(e)};try{for(var I,C=!0,P=(t=void 0,o(s({signal:j.signal,operationId:w})));!(e=(I=await P.next()).done);){u=I.value,C=!1;try{const e=u;i.next(e)}finally{C=!0}}}catch(e){t={error:e}}finally{try{C||e||!(l=P.return)||await l.call(P)}finally{if(t)throw t.error}}return T=null,j.abort()}catch(e){if(j.signal.aborted)return await(null==T?void 0:T());if(!(e instanceof f))throw j.abort(),e;if(r&&(x=void 0),!c||S>=c)throw j.abort(),e;E=e}finally{j.signal.aborted&&0==--m&&(isFinite(n)&&n>0?setTimeout((()=>{m||v.abort()}),n):v.abort())}}})().then((()=>i.complete())).catch((e=>i.error(e))),()=>j.abort()},dispose(){g.dispose()}}},e.isAsyncGenerator=function(e){return a(e)&&"function"==typeof Object(e)[Symbol.asyncIterator]&&"function"==typeof e.return&&"function"==typeof e.throw&&"function"==typeof e.next},e.isAsyncIterable=function(e){return"function"==typeof Object(e)[Symbol.asyncIterator]},e.parseStreamData=c,e.print=function(e){let t=`event: ${e.event}`;return e.data&&(t+=`\ndata: ${JSON.stringify(e.data)}`),t+="\n\n",t},e.validateStreamEvent=s}));

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

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

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