Socket
Socket
Sign inDemoInstall

graphql-ws

Package Overview
Dependencies
1
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.13.1 to 5.14.0

5

lib/client.d.ts

@@ -368,2 +368,7 @@ /**

/**
* Subscribes and iterates over emitted results from the WebSocket
* through the returned async iterator.
*/
iterate<Data = Record<string, unknown>, Extensions = unknown>(payload: SubscribePayload): AsyncIterableIterator<ExecutionResult<Data, Extensions>>;
/**
* Terminates the WebSocket abruptly and immediately.

@@ -370,0 +375,0 @@ *

@@ -21,2 +21,14 @@ "use strict";

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -440,2 +452,63 @@ exports.createClient = void 0;

},
iterate(request) {
const pending = [];
const deferred = {
done: false,
error: null,
resolve: () => {
// noop
},
};
const dispose = this.subscribe(request, {
next(val) {
pending.push(val);
deferred.resolve();
},
error(err) {
deferred.done = true;
deferred.error = err;
deferred.resolve();
},
complete() {
deferred.done = true;
deferred.resolve();
},
});
const iterator = (function iterator() {
return __asyncGenerator(this, arguments, function* iterator_1() {
for (;;) {
if (!pending.length) {
// only wait if there are no pending messages available
yield __await(new Promise((resolve) => (deferred.resolve = resolve)));
}
// first flush
while (pending.length) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
yield yield __await(pending.shift());
}
// then error
if (deferred.error) {
throw deferred.error;
}
// or complete
if (deferred.done) {
return yield __await(void 0);
}
}
});
})();
iterator.throw = async (err) => {
if (!deferred.done) {
deferred.done = true;
deferred.error = err;
deferred.resolve();
}
return { done: true, value: undefined };
};
iterator.return = async () => {
dispose();
return { done: true, value: undefined };
};
return iterator;
},
async dispose() {

@@ -442,0 +515,0 @@ disposed = true;

4

lib/common.d.ts

@@ -8,3 +8,3 @@ /**

/**
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -21,3 +21,3 @@ * @category Common

/**
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -24,0 +24,0 @@ * @category Common

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

/**
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -24,3 +24,3 @@ * @category Common

/**
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -44,3 +44,3 @@ * @category Common

CloseCode[CloseCode["TooManyInitialisationRequests"] = 4429] = "TooManyInitialisationRequests";
})(CloseCode = exports.CloseCode || (exports.CloseCode = {}));
})(CloseCode || (exports.CloseCode = CloseCode = {}));
/**

@@ -61,3 +61,3 @@ * Types of messages allowed to be sent by the client/server over the WS protocol.

MessageType["Complete"] = "complete";
})(MessageType = exports.MessageType || (exports.MessageType = {}));
})(MessageType || (exports.MessageType = MessageType = {}));
/**

@@ -64,0 +64,0 @@ * Validates the message against the GraphQL over WebSocket Protocol.

@@ -398,3 +398,3 @@ /**

*
* Read more about the Protocol in the PROTOCOL.md documentation file.
* Read more about the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -401,0 +401,0 @@ * @category Server

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

*
* Read more about the Protocol in the PROTOCOL.md documentation file.
* Read more about the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -209,12 +209,7 @@ * @category Server

try {
for (var _e = true, operationResult_1 = __asyncValues(operationResult), operationResult_1_1; operationResult_1_1 = await operationResult_1.next(), _a = operationResult_1_1.done, !_a;) {
for (var _e = true, operationResult_1 = __asyncValues(operationResult), operationResult_1_1; operationResult_1_1 = await operationResult_1.next(), _a = operationResult_1_1.done, !_a; _e = true) {
_c = operationResult_1_1.value;
_e = false;
try {
const result = _c;
await emit.next(result, execArgs);
}
finally {
_e = true;
}
const result = _c;
await emit.next(result, execArgs);
}

@@ -221,0 +216,0 @@ }

{
"name": "graphql-ws",
"version": "5.13.1",
"version": "5.14.0",
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client",

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

},
"packageManager": "yarn@3.5.1",
"packageManager": "yarn@3.6.0",
"types": "lib/index.d.ts",

@@ -112,3 +112,3 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/core": "^7.21.8",
"@babel/core": "^7.22.5",
"@babel/plugin-proposal-class-properties": "^7.18.6",

@@ -118,23 +118,23 @@ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",

"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@babel/preset-env": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@fastify/websocket": "^7.2.0",
"@rollup/plugin-terser": "^0.4.1",
"@rollup/plugin-typescript": "^11.1.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/eslint": "^8.37.0",
"@types/eslint": "^8.40.2",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.1",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"@types/jest": "^29.5.2",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"babel-jest": "^29.5.0",
"bun-types": "^0.5.8",
"eslint": "^8.40.0",
"bun-types": "^0.6.9",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"fastify": "^4.17.0",
"fastify": "^4.18.0",
"fastify-websocket": "4.2.2",
"glob": "^10.2.3",
"graphql": "^16.6.0",
"glob": "^10.3.0",
"graphql": "^16.7.0",
"jest": "^29.5.0",

@@ -145,10 +145,10 @@ "jest-environment-jsdom": "^29.5.0",

"replacestream": "^4.0.3",
"rollup": "^3.21.6",
"semantic-release": "^21.0.2",
"rollup": "^3.25.1",
"semantic-release": "^21.0.5",
"subscriptions-transport-ws": "^0.11.0",
"tslib": "^2.5.0",
"typedoc": "^0.24.7",
"tslib": "^2.5.3",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.0.4",
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.24.0",
"typescript": "^5.1.3",
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.30.0",
"ws": "8.12.0",

@@ -155,0 +155,0 @@ "ws7": "npm:ws@^7.5.9"

@@ -7,2 +7,35 @@ (function (global, factory) {

/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
/** @private */

@@ -46,3 +79,3 @@ function extendedTypeof(val) {

/**
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* The WebSocket sub-protocol used for the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -59,3 +92,3 @@ * @category Common

/**
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](/PROTOCOL.md).
* `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md).
*

@@ -637,2 +670,63 @@ * @category Common

},
iterate(request) {
const pending = [];
const deferred = {
done: false,
error: null,
resolve: () => {
// noop
},
};
const dispose = this.subscribe(request, {
next(val) {
pending.push(val);
deferred.resolve();
},
error(err) {
deferred.done = true;
deferred.error = err;
deferred.resolve();
},
complete() {
deferred.done = true;
deferred.resolve();
},
});
const iterator = (function iterator() {
return __asyncGenerator(this, arguments, function* iterator_1() {
for (;;) {
if (!pending.length) {
// only wait if there are no pending messages available
yield __await(new Promise((resolve) => (deferred.resolve = resolve)));
}
// first flush
while (pending.length) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
yield yield __await(pending.shift());
}
// then error
if (deferred.error) {
throw deferred.error;
}
// or complete
if (deferred.done) {
return yield __await(void 0);
}
}
});
})();
iterator.throw = async (err) => {
if (!deferred.done) {
deferred.done = true;
deferred.error = err;
deferred.resolve();
}
return { done: true, value: undefined };
};
iterator.return = async () => {
dispose();
return { done: true, value: undefined };
};
return iterator;
},
async dispose() {

@@ -639,0 +733,0 @@ disposed = true;

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

!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";function o(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function t(e){return"object"===o(e)}function r(e,o){return e.length<124?e:o}const n="graphql-transport-ws";var s,i;function a(r){if(!t(r))throw new Error(`Message is expected to be an object, but got ${o(r)}`);if(!r.type)throw new Error("Message is missing the 'type' property");if("string"!=typeof r.type)throw new Error(`Message is expects the 'type' property to be a string, but got ${o(r.type)}`);switch(r.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:if(null!=r.payload&&!t(r.payload))throw new Error(`"${r.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${r.payload}"`);break;case e.MessageType.Subscribe:if("string"!=typeof r.id)throw new Error(`"${r.type}" message expects the 'id' property to be a string, but got ${o(r.id)}`);if(!r.id)throw new Error(`"${r.type}" message requires a non-empty 'id' property`);if(!t(r.payload))throw new Error(`"${r.type}" message expects the 'payload' property to be an object, but got ${o(r.payload)}`);if("string"!=typeof r.payload.query)throw new Error(`"${r.type}" message payload expects the 'query' property to be a string, but got ${o(r.payload.query)}`);if(null!=r.payload.variables&&!t(r.payload.variables))throw new Error(`"${r.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${o(r.payload.variables)}`);if(null!=r.payload.operationName&&"string"!==o(r.payload.operationName))throw new Error(`"${r.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${o(r.payload.operationName)}`);if(null!=r.payload.extensions&&!t(r.payload.extensions))throw new Error(`"${r.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${o(r.payload.extensions)}`);break;case e.MessageType.Next:if("string"!=typeof r.id)throw new Error(`"${r.type}" message expects the 'id' property to be a string, but got ${o(r.id)}`);if(!r.id)throw new Error(`"${r.type}" message requires a non-empty 'id' property`);if(!t(r.payload))throw new Error(`"${r.type}" message expects the 'payload' property to be an object, but got ${o(r.payload)}`);break;case e.MessageType.Error:if("string"!=typeof r.id)throw new Error(`"${r.type}" message expects the 'id' property to be a string, but got ${o(r.id)}`);if(!r.id)throw new Error(`"${r.type}" message requires a non-empty 'id' property`);if(n=r.payload,!(Array.isArray(n)&&n.length>0&&n.every((e=>"message"in e))))throw new Error(`"${r.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(r.payload)}`);break;case e.MessageType.Complete:if("string"!=typeof r.id)throw new Error(`"${r.type}" message expects the 'id' property to be a string, but got ${o(r.id)}`);if(!r.id)throw new Error(`"${r.type}" message requires a non-empty 'id' property`);break;default:throw new Error(`Invalid message 'type' property "${r.type}"`)}var n;return r}function p(e,o){return a("string"==typeof e?JSON.parse(e,o):e)}function l(e,o){return a(e),JSON.stringify(e,o)}function c(e){return t(e)&&"code"in e&&"reason"in e}e.CloseCode=void 0,(s=e.CloseCode||(e.CloseCode={}))[s.InternalServerError=4500]="InternalServerError",s[s.InternalClientError=4005]="InternalClientError",s[s.BadRequest=4400]="BadRequest",s[s.BadResponse=4004]="BadResponse",s[s.Unauthorized=4401]="Unauthorized",s[s.Forbidden=4403]="Forbidden",s[s.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",s[s.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",s[s.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",s[s.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",s[s.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e.MessageType=void 0,(i=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",i.ConnectionAck="connection_ack",i.Ping="ping",i.Pong="pong",i.Subscribe="subscribe",i.Next="next",i.Error="error",i.Complete="complete",e.DEPRECATED_GRAPHQL_WS_PROTOCOL="graphql-ws",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=n,e.createClient=function(o){const{url:t,connectionParams:s,lazy:i=!0,onNonLazyError:a=console.error,lazyCloseTimeout:d=0,keepAlive:y=0,disablePong:u,connectionAckWaitTimeout:g=0,retryAttempts:m=5,retryWait:f=async function(e){let o=1e3;for(let t=0;t<e;t++)o*=2;await new Promise((e=>setTimeout(e,o+Math.floor(2700*Math.random()+300))))},shouldRetry:b=c,isFatalConnectionProblem:w,on:h,webSocketImpl:C,generateID:x=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const o=16*Math.random()|0;return("x"==e?o:3&o|8).toString(16)}))},jsonMessageReplacer:E,jsonMessageReviver:T}=o;let v;if(C){if(!("function"==typeof(M=C)&&"constructor"in M&&"CLOSED"in M&&"CLOSING"in M&&"CONNECTING"in M&&"OPEN"in M))throw new Error("Invalid WebSocket implementation provided");v=C}else"undefined"!=typeof WebSocket?v=WebSocket:"undefined"!=typeof global?v=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(v=window.WebSocket||window.MozWebSocket);var M;if(!v)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const S=v,$=(()=>{const e=(()=>{const e={};return{on:(o,t)=>(e[o]=t,()=>{delete e[o]}),emit(o){var t;"id"in o&&(null===(t=e[o.id])||void 0===t||t.call(e,o))}}})(),o={connecting:(null==h?void 0:h.connecting)?[h.connecting]:[],opened:(null==h?void 0:h.opened)?[h.opened]:[],connected:(null==h?void 0:h.connected)?[h.connected]:[],ping:(null==h?void 0:h.ping)?[h.ping]:[],pong:(null==h?void 0:h.pong)?[h.pong]:[],message:(null==h?void 0:h.message)?[e.emit,h.message]:[e.emit],closed:(null==h?void 0:h.closed)?[h.closed]:[],error:(null==h?void 0:h.error)?[h.error]:[]};return{onMessage:e.on,on(e,t){const r=o[e];return r.push(t),()=>{r.splice(r.indexOf(t),1)}},emit(e,...t){for(const r of[...o[e]])r(...t)}}})();function N(e){const o=[$.on("error",(t=>{o.forEach((e=>e())),e(t)})),$.on("closed",(t=>{o.forEach((e=>e())),e(t)}))]}let k,P,I=0,A=!1,O=0,R=!1;async function q(){clearTimeout(P);const[o,i]=await(null!=k?k:k=new Promise(((o,i)=>(async()=>{if(A){if(await f(O),!I)return k=void 0,i({code:1e3,reason:"All Subscriptions Gone"});O++}$.emit("connecting");const a=new S("function"==typeof t?await t():t,n);let d,m;function b(){isFinite(y)&&y>0&&(clearTimeout(m),m=setTimeout((()=>{a.readyState===S.OPEN&&(a.send(l({type:e.MessageType.Ping})),$.emit("ping",!1,void 0))}),y))}N((e=>{k=void 0,clearTimeout(d),clearTimeout(m),i(e),c(e)&&4499===e.code&&(a.close(4499,"Terminated"),a.onerror=null,a.onclose=null)})),a.onerror=e=>$.emit("error",e),a.onclose=e=>$.emit("closed",e),a.onopen=async()=>{try{$.emit("opened",a);const o="function"==typeof s?await s():s;if(a.readyState!==S.OPEN)return;a.send(l(o?{type:e.MessageType.ConnectionInit,payload:o}:{type:e.MessageType.ConnectionInit},E)),isFinite(g)&&g>0&&(d=setTimeout((()=>{a.close(e.CloseCode.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")}),g)),b()}catch(o){$.emit("error",o),a.close(e.CloseCode.InternalClientError,r(o instanceof Error?o.message:new Error(o).message,"Internal client error"))}};let w=!1;a.onmessage=({data:t})=>{try{const r=p(t,T);if($.emit("message",r),"ping"===r.type||"pong"===r.type)return $.emit(r.type,!0,r.payload),void("pong"===r.type?b():u||(a.send(l(r.payload?{type:e.MessageType.Pong,payload:r.payload}:{type:e.MessageType.Pong})),$.emit("pong",!1,r.payload)));if(w)return;if(r.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${r.type}`);clearTimeout(d),w=!0,$.emit("connected",a,r.payload),A=!1,O=0,o([a,new Promise(((e,o)=>N(o)))])}catch(o){a.onmessage=null,$.emit("error",o),a.close(e.CloseCode.BadResponse,r(o instanceof Error?o.message:new Error(o).message,"Bad response"))}}})())));o.readyState===S.CLOSING&&await i;let a=()=>{};const m=new Promise((e=>a=e));return[o,a,Promise.race([m.then((()=>{if(!I){const e=()=>o.close(1e3,"Normal Closure");isFinite(d)&&d>0?P=setTimeout((()=>{o.readyState===S.OPEN&&e()}),d):e()}})),i])]}function W(o){if(c(o)&&(t=o.code,![1e3,1001,1006,1005,1012,1013,1013].includes(t)&&t>=1e3&&t<=1999||[e.CloseCode.InternalServerError,e.CloseCode.InternalClientError,e.CloseCode.BadRequest,e.CloseCode.BadResponse,e.CloseCode.Unauthorized,e.CloseCode.SubprotocolNotAcceptable,e.CloseCode.SubscriberAlreadyExists,e.CloseCode.TooManyInitialisationRequests].includes(o.code)))throw o;var t;if(R)return!1;if(c(o)&&1e3===o.code)return I>0;if(!m||O>=m)throw o;if(!b(o))throw o;if(null==w?void 0:w(o))throw o;return A=!0}return i||(async()=>{for(I++;;)try{const[,,e]=await q();await e}catch(e){try{if(!W(e))return}catch(e){return null==a?void 0:a(e)}}})(),{on:$.on,subscribe(o,t){const r=x(o);let n=!1,s=!1,i=()=>{I--,n=!0};return(async()=>{for(I++;;)try{const[a,p,c]=await q();if(n)return p();const d=$.onMessage(r,(o=>{switch(o.type){case e.MessageType.Next:return void t.next(o.payload);case e.MessageType.Error:return s=!0,n=!0,t.error(o.payload),void i();case e.MessageType.Complete:return n=!0,void i()}}));return a.send(l({id:r,type:e.MessageType.Subscribe,payload:o},E)),i=()=>{n||a.readyState!==S.OPEN||a.send(l({id:r,type:e.MessageType.Complete},E)),I--,n=!0,p()},void await c.finally(d)}catch(e){if(!W(e))return}})().then((()=>{s||t.complete()})).catch((e=>{t.error(e)})),()=>{n||i()}},async dispose(){if(R=!0,k){const[e]=await k;e.close(1e3,"Normal Closure")}},terminate(){k&&$.emit("closed",{code:4499,reason:"Terminated",wasClean:!1})}}},e.isMessage=function(e){try{return a(e),!0}catch(e){return!1}},e.parseMessage=p,e.stringifyMessage=l,e.validateMessage=a}));
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";function o(e){return this instanceof o?(this.v=e,this):new o(e)}function t(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(e,t||[]),s=[];return n={},a("next"),a("throw"),a("return"),n[Symbol.asyncIterator]=function(){return this},n;function a(e){i[e]&&(n[e]=function(o){return new Promise((function(t,r){s.push([e,o,t,r])>1||l(e,o)}))})}function l(e,t){try{(r=i[e](t)).value instanceof o?Promise.resolve(r.value.v).then(c,p):d(s[0][2],r)}catch(e){d(s[0][3],e)}var r}function c(e){l("next",e)}function p(e){l("throw",e)}function d(e,o){e(o),s.shift(),s.length&&l(s[0][0],s[0][1])}}function r(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function n(e){return"object"===r(e)}function i(e,o){return e.length<124?e:o}const s="graphql-transport-ws";var a,l;function c(o){if(!n(o))throw new Error(`Message is expected to be an object, but got ${r(o)}`);if(!o.type)throw new Error("Message is missing the 'type' property");if("string"!=typeof o.type)throw new Error(`Message is expects the 'type' property to be a string, but got ${r(o.type)}`);switch(o.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:if(null!=o.payload&&!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${o.payload}"`);break;case e.MessageType.Subscribe:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);if("string"!=typeof o.payload.query)throw new Error(`"${o.type}" message payload expects the 'query' property to be a string, but got ${r(o.payload.query)}`);if(null!=o.payload.variables&&!n(o.payload.variables))throw new Error(`"${o.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${r(o.payload.variables)}`);if(null!=o.payload.operationName&&"string"!==r(o.payload.operationName))throw new Error(`"${o.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${r(o.payload.operationName)}`);if(null!=o.payload.extensions&&!n(o.payload.extensions))throw new Error(`"${o.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${r(o.payload.extensions)}`);break;case e.MessageType.Next:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);break;case e.MessageType.Error:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(t=o.payload,!(Array.isArray(t)&&t.length>0&&t.every((e=>"message"in e))))throw new Error(`"${o.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(o.payload)}`);break;case e.MessageType.Complete:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);break;default:throw new Error(`Invalid message 'type' property "${o.type}"`)}var t;return o}function p(e,o){return c("string"==typeof e?JSON.parse(e,o):e)}function d(e,o){return c(e),JSON.stringify(e,o)}function y(e){return n(e)&&"code"in e&&"reason"in e}e.CloseCode=void 0,(a=e.CloseCode||(e.CloseCode={}))[a.InternalServerError=4500]="InternalServerError",a[a.InternalClientError=4005]="InternalClientError",a[a.BadRequest=4400]="BadRequest",a[a.BadResponse=4004]="BadResponse",a[a.Unauthorized=4401]="Unauthorized",a[a.Forbidden=4403]="Forbidden",a[a.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",a[a.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",a[a.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",a[a.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",a[a.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e.MessageType=void 0,(l=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",l.ConnectionAck="connection_ack",l.Ping="ping",l.Pong="pong",l.Subscribe="subscribe",l.Next="next",l.Error="error",l.Complete="complete",e.DEPRECATED_GRAPHQL_WS_PROTOCOL="graphql-ws",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=s,e.createClient=function(r){const{url:n,connectionParams:a,lazy:l=!0,onNonLazyError:c=console.error,lazyCloseTimeout:u=0,keepAlive:g=0,disablePong:f,connectionAckWaitTimeout:m=0,retryAttempts:b=5,retryWait:h=async function(e){let o=1e3;for(let t=0;t<e;t++)o*=2;await new Promise((e=>setTimeout(e,o+Math.floor(2700*Math.random()+300))))},shouldRetry:w=y,isFatalConnectionProblem:x,on:C,webSocketImpl:v,generateID:E=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const o=16*Math.random()|0;return("x"==e?o:3&o|8).toString(16)}))},jsonMessageReplacer:T,jsonMessageReviver:S}=r;let M;if(v){if(!("function"==typeof($=v)&&"constructor"in $&&"CLOSED"in $&&"CLOSING"in $&&"CONNECTING"in $&&"OPEN"in $))throw new Error("Invalid WebSocket implementation provided");M=v}else"undefined"!=typeof WebSocket?M=WebSocket:"undefined"!=typeof global?M=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(M=window.WebSocket||window.MozWebSocket);var $;if(!M)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const P=M,I=(()=>{const e=(()=>{const e={};return{on:(o,t)=>(e[o]=t,()=>{delete e[o]}),emit(o){var t;"id"in o&&(null===(t=e[o.id])||void 0===t||t.call(e,o))}}})(),o={connecting:(null==C?void 0:C.connecting)?[C.connecting]:[],opened:(null==C?void 0:C.opened)?[C.opened]:[],connected:(null==C?void 0:C.connected)?[C.connected]:[],ping:(null==C?void 0:C.ping)?[C.ping]:[],pong:(null==C?void 0:C.pong)?[C.pong]:[],message:(null==C?void 0:C.message)?[e.emit,C.message]:[e.emit],closed:(null==C?void 0:C.closed)?[C.closed]:[],error:(null==C?void 0:C.error)?[C.error]:[]};return{onMessage:e.on,on(e,t){const r=o[e];return r.push(t),()=>{r.splice(r.indexOf(t),1)}},emit(e,...t){for(const r of[...o[e]])r(...t)}}})();function N(e){const o=[I.on("error",(t=>{o.forEach((e=>e())),e(t)})),I.on("closed",(t=>{o.forEach((e=>e())),e(t)}))]}let k,A,O=0,R=!1,q=0,W=!1;async function j(){clearTimeout(A);const[o,t]=await(null!=k?k:k=new Promise(((o,t)=>(async()=>{if(R){if(await h(q),!O)return k=void 0,t({code:1e3,reason:"All Subscriptions Gone"});q++}I.emit("connecting");const r=new P("function"==typeof n?await n():n,s);let l,c;function u(){isFinite(g)&&g>0&&(clearTimeout(c),c=setTimeout((()=>{r.readyState===P.OPEN&&(r.send(d({type:e.MessageType.Ping})),I.emit("ping",!1,void 0))}),g))}N((e=>{k=void 0,clearTimeout(l),clearTimeout(c),t(e),y(e)&&4499===e.code&&(r.close(4499,"Terminated"),r.onerror=null,r.onclose=null)})),r.onerror=e=>I.emit("error",e),r.onclose=e=>I.emit("closed",e),r.onopen=async()=>{try{I.emit("opened",r);const o="function"==typeof a?await a():a;if(r.readyState!==P.OPEN)return;r.send(d(o?{type:e.MessageType.ConnectionInit,payload:o}:{type:e.MessageType.ConnectionInit},T)),isFinite(m)&&m>0&&(l=setTimeout((()=>{r.close(e.CloseCode.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")}),m)),u()}catch(o){I.emit("error",o),r.close(e.CloseCode.InternalClientError,i(o instanceof Error?o.message:new Error(o).message,"Internal client error"))}};let b=!1;r.onmessage=({data:t})=>{try{const n=p(t,S);if(I.emit("message",n),"ping"===n.type||"pong"===n.type)return I.emit(n.type,!0,n.payload),void("pong"===n.type?u():f||(r.send(d(n.payload?{type:e.MessageType.Pong,payload:n.payload}:{type:e.MessageType.Pong})),I.emit("pong",!1,n.payload)));if(b)return;if(n.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${n.type}`);clearTimeout(l),b=!0,I.emit("connected",r,n.payload),R=!1,q=0,o([r,new Promise(((e,o)=>N(o)))])}catch(o){r.onmessage=null,I.emit("error",o),r.close(e.CloseCode.BadResponse,i(o instanceof Error?o.message:new Error(o).message,"Bad response"))}}})())));o.readyState===P.CLOSING&&await t;let r=()=>{};const l=new Promise((e=>r=e));return[o,r,Promise.race([l.then((()=>{if(!O){const e=()=>o.close(1e3,"Normal Closure");isFinite(u)&&u>0?A=setTimeout((()=>{o.readyState===P.OPEN&&e()}),u):e()}})),t])]}function L(o){if(y(o)&&(t=o.code,![1e3,1001,1006,1005,1012,1013,1013].includes(t)&&t>=1e3&&t<=1999||[e.CloseCode.InternalServerError,e.CloseCode.InternalClientError,e.CloseCode.BadRequest,e.CloseCode.BadResponse,e.CloseCode.Unauthorized,e.CloseCode.SubprotocolNotAcceptable,e.CloseCode.SubscriberAlreadyExists,e.CloseCode.TooManyInitialisationRequests].includes(o.code)))throw o;var t;if(W)return!1;if(y(o)&&1e3===o.code)return O>0;if(!b||q>=b)throw o;if(!w(o))throw o;if(null==x?void 0:x(o))throw o;return R=!0}return l||(async()=>{for(O++;;)try{const[,,e]=await j();await e}catch(e){try{if(!L(e))return}catch(e){return null==c?void 0:c(e)}}})(),{on:I.on,subscribe(o,t){const r=E(o);let n=!1,i=!1,s=()=>{O--,n=!0};return(async()=>{for(O++;;)try{const[a,l,c]=await j();if(n)return l();const p=I.onMessage(r,(o=>{switch(o.type){case e.MessageType.Next:return void t.next(o.payload);case e.MessageType.Error:return i=!0,n=!0,t.error(o.payload),void s();case e.MessageType.Complete:return n=!0,void s()}}));return a.send(d({id:r,type:e.MessageType.Subscribe,payload:o},T)),s=()=>{n||a.readyState!==P.OPEN||a.send(d({id:r,type:e.MessageType.Complete},T)),O--,n=!0,l()},void await c.finally(p)}catch(e){if(!L(e))return}})().then((()=>{i||t.complete()})).catch((e=>{t.error(e)})),()=>{n||s()}},iterate(e){const r=[],n={done:!1,error:null,resolve:()=>{}},i=this.subscribe(e,{next(e){r.push(e),n.resolve()},error(e){n.done=!0,n.error=e,n.resolve()},complete(){n.done=!0,n.resolve()}}),s=function(){return t(this,arguments,(function*(){for(;;){for(r.length||(yield o(new Promise((e=>n.resolve=e))));r.length;)yield yield o(r.shift());if(n.error)throw n.error;if(n.done)return yield o(void 0)}}))}();return s.throw=async e=>(n.done||(n.done=!0,n.error=e,n.resolve()),{done:!0,value:void 0}),s.return=async()=>(i(),{done:!0,value:void 0}),s},async dispose(){if(W=!0,k){const[e]=await k;e.close(1e3,"Normal Closure")}},terminate(){k&&I.emit("closed",{code:4499,reason:"Terminated",wasClean:!1})}}},e.isMessage=function(e){try{return c(e),!0}catch(e){return!1}},e.parseMessage=p,e.stringifyMessage=d,e.validateMessage=c}));

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc