New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-ws

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-ws - npm Package Compare versions

Comparing version 6.0.0-alpha-35f84572c0898433ae319cdc7c448107fe689d0c to 6.0.0-alpha-51e3405d3aca3d74716845f50a1718682cf05ea8

dist/common-BZ6jfDSg.js

6

dist/client.js

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

import { G as GRAPHQL_TRANSPORT_WS_PROTOCOL, s as stringifyMessage, M as MessageType, C as CloseCode, l as limitCloseReason, p as parseMessage, a as isObject } from './common-C3FuvWlV.js';
export { D as DEPRECATED_GRAPHQL_WS_PROTOCOL, i as isMessage, v as validateMessage } from './common-C3FuvWlV.js';
import { G as GRAPHQL_TRANSPORT_WS_PROTOCOL, s as stringifyMessage, M as MessageType, C as CloseCode, l as limitCloseReason, p as parseMessage, i as isObject } from './common-BZ6jfDSg.js';
export { D as DEPRECATED_GRAPHQL_WS_PROTOCOL, v as validateMessage } from './common-BZ6jfDSg.js';

@@ -29,3 +29,2 @@ function createClient(options) {

shouldRetry = isLikeCloseEvent,
isFatalConnectionProblem,
on,

@@ -304,3 +303,2 @@ webSocketImpl,

if (!shouldRetry(errOrCloseEvent)) throw errOrCloseEvent;
if (isFatalConnectionProblem?.(errOrCloseEvent)) throw errOrCloseEvent;
return retrying = true;

@@ -307,0 +305,0 @@ }

import { ExecutionResult } from 'graphql';
import { C as ConnectionAckMessage, P as PingMessage, a as PongMessage, M as Message, b as ConnectionInitMessage, S as SubscribePayload, I as ID, J as JSONMessageReviver, c as JSONMessageReplacer, D as Disposable, d as Sink } from './server-CgaLfd0V.js';
export { f as CloseCode, k as CompleteMessage, q as Context, e as DEPRECATED_GRAPHQL_WS_PROTOCOL, j as ErrorMessage, i as ExecutionPatchResult, E as ExecutionResult, G as GRAPHQL_TRANSPORT_WS_PROTOCOL, m as GraphQLExecutionContextValue, g as MessageType, N as NextMessage, O as OperationResult, o as Server, n as ServerOptions, h as SubscribeMessage, W as WebSocket, t as handleProtocols, l as isMessage, r as makeServer, p as parseMessage, s as stringifyMessage, v as validateMessage } from './server-CgaLfd0V.js';
import { C as ConnectionAckMessage, P as PingMessage, a as PongMessage, M as Message, b as ConnectionInitMessage, S as SubscribePayload, I as ID, J as JSONMessageReviver, c as JSONMessageReplacer, D as Disposable, d as Sink } from './server-BdSfAnnR.js';
export { f as CloseCode, k as CompleteMessage, o as Context, e as DEPRECATED_GRAPHQL_WS_PROTOCOL, j as ErrorMessage, i as ExecutionPatchResult, E as ExecutionResult, G as GRAPHQL_TRANSPORT_WS_PROTOCOL, l as GraphQLExecutionContextValue, g as MessageType, N as NextMessage, O as OperationResult, n as Server, m as ServerOptions, h as SubscribeMessage, W as WebSocket, r as handleProtocols, q as makeServer, p as parseMessage, s as stringifyMessage, v as validateMessage } from './server-BdSfAnnR.js';

@@ -300,20 +300,2 @@ /**

/**
* @deprecated Use `shouldRetry` instead.
*
* Check if the close event or connection error is fatal. If you return `true`,
* the client will fail immediately without additional retries; however, if you
* return `false`, the client will keep retrying until the `retryAttempts` have
* been exceeded.
*
* The argument is either a WebSocket `CloseEvent` or an error thrown during
* the connection phase.
*
* Beware, the library classifies a few close events as fatal regardless of
* what is returned. They are listed in the documentation of the `retryAttempts`
* option.
*
* @default 'Any non-`CloseEvent`'
*/
isFatalConnectionProblem?: (errOrCloseEvent: unknown) => boolean;
/**
* Register listeners before initialising the client. This way

@@ -320,0 +302,0 @@ * you can ensure to catch all client relevant emitted events.

export { TerminatedCloseEvent, createClient } from './client.js';
export { h as handleProtocols, m as makeServer } from './server-C2VkalQ-.js';
export { C as CloseCode, D as DEPRECATED_GRAPHQL_WS_PROTOCOL, G as GRAPHQL_TRANSPORT_WS_PROTOCOL, M as MessageType, i as isMessage, p as parseMessage, s as stringifyMessage, v as validateMessage } from './common-C3FuvWlV.js';
export { h as handleProtocols, m as makeServer } from './server-Do6Hkqsr.js';
export { C as CloseCode, D as DEPRECATED_GRAPHQL_WS_PROTOCOL, G as GRAPHQL_TRANSPORT_WS_PROTOCOL, M as MessageType, p as parseMessage, s as stringifyMessage, v as validateMessage } from './common-BZ6jfDSg.js';
import 'graphql';
import { WebSocket, WebsocketHandler } from '@fastify/websocket';
import { FastifyRequest } from 'fastify';
import { b as ConnectionInitMessage, n as ServerOptions } from '../../server-CgaLfd0V.js';
import { b as ConnectionInitMessage, m as ServerOptions } from '../../server-BdSfAnnR.js';
import 'graphql';

@@ -5,0 +5,0 @@

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

import { C as CloseCode, l as limitCloseReason, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../../common-C3FuvWlV.js';
import { h as handleProtocols, m as makeServer } from '../../server-C2VkalQ-.js';
import { C as CloseCode, l as limitCloseReason, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../../common-BZ6jfDSg.js';
import { h as handleProtocols, m as makeServer } from '../../server-Do6Hkqsr.js';
import 'graphql';

@@ -4,0 +4,0 @@

import { ServerWebSocket, WebSocketHandler } from 'bun';
import { b as ConnectionInitMessage, n as ServerOptions } from '../server-CgaLfd0V.js';
export { t as handleProtocols } from '../server-CgaLfd0V.js';
import { b as ConnectionInitMessage, m as ServerOptions } from '../server-BdSfAnnR.js';
export { r as handleProtocols } from '../server-BdSfAnnR.js';
import 'graphql';

@@ -5,0 +5,0 @@

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

import { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../common-C3FuvWlV.js';
import { m as makeServer } from '../server-C2VkalQ-.js';
export { h as handleProtocols } from '../server-C2VkalQ-.js';
import { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../common-BZ6jfDSg.js';
import { m as makeServer } from '../server-Do6Hkqsr.js';
export { h as handleProtocols } from '../server-Do6Hkqsr.js';
import 'graphql';

@@ -5,0 +5,0 @@

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

import { b as ConnectionInitMessage, n as ServerOptions } from '../server-CgaLfd0V.js';
export { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../server-CgaLfd0V.js';
import { b as ConnectionInitMessage, m as ServerOptions } from '../server-BdSfAnnR.js';
export { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../server-BdSfAnnR.js';
import 'graphql';

@@ -4,0 +4,0 @@

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

import { C as CloseCode, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../common-C3FuvWlV.js';
export { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../common-C3FuvWlV.js';
import { m as makeServer } from '../server-C2VkalQ-.js';
import { C as CloseCode, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../common-BZ6jfDSg.js';
export { G as GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../common-BZ6jfDSg.js';
import { m as makeServer } from '../server-Do6Hkqsr.js';
import 'graphql';

@@ -5,0 +5,0 @@

import http__default from 'http';
import * as uWS from 'uWebSockets.js';
import { b as ConnectionInitMessage, n as ServerOptions } from '../server-CgaLfd0V.js';
import { b as ConnectionInitMessage, m as ServerOptions } from '../server-BdSfAnnR.js';
import 'graphql';

@@ -5,0 +5,0 @@

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

import { C as CloseCode, l as limitCloseReason } from '../common-C3FuvWlV.js';
import { h as handleProtocols, m as makeServer } from '../server-C2VkalQ-.js';
import { C as CloseCode, l as limitCloseReason } from '../common-BZ6jfDSg.js';
import { h as handleProtocols, m as makeServer } from '../server-Do6Hkqsr.js';
import 'graphql';

@@ -4,0 +4,0 @@

import * as http from 'http';
import WebSocket from 'ws';
export { default as WebSocket } from 'ws';
import { b as ConnectionInitMessage, n as ServerOptions, D as Disposable } from '../server-CgaLfd0V.js';
import { b as ConnectionInitMessage, m as ServerOptions, D as Disposable } from '../server-BdSfAnnR.js';
import 'graphql';

@@ -6,0 +6,0 @@

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

import { C as CloseCode, l as limitCloseReason, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../common-C3FuvWlV.js';
import { h as handleProtocols, m as makeServer } from '../server-C2VkalQ-.js';
import { C as CloseCode, l as limitCloseReason, D as DEPRECATED_GRAPHQL_WS_PROTOCOL } from '../common-BZ6jfDSg.js';
import { h as handleProtocols, m as makeServer } from '../server-Do6Hkqsr.js';
import 'graphql';

@@ -4,0 +4,0 @@

{
"name": "graphql-ws",
"version": "6.0.0-alpha-35f84572c0898433ae319cdc7c448107fe689d0c",
"version": "6.0.0-alpha-51e3405d3aca3d74716845f50a1718682cf05ea8",
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client",

@@ -80,14 +80,13 @@ "type": "module",

"scripts": {
"build": "pkgroll --clean-dist && rollup -c rollup.config.js && gzip umd/graphql-ws.min.js -c > umd/graphql-ws.min.js.gz",
"prepack": "yarn build",
"changeset": "changeset",
"check:format": "prettier --check .",
"format": "yarn check:format --write",
"check:types": "tsc --noEmit",
"format": "yarn check:format --write",
"gendocs": "typedoc --options typedoc.js src/ && node scripts/post-gendocs.js",
"postbuild": "node scripts/fix-declaration-directives.js",
"test": "vitest"
"test": "vitest",
"build": "pkgroll --clean-dist && rollup -c rollup.config.js && gzip umd/graphql-ws.min.js -c > umd/graphql-ws.min.js.gz",
"prepack": "yarn build",
"gendocs": "typedoc --options typedoc.js src/ && node scripts/post-gendocs.js"
},
"peerDependencies": {
"graphql": "^15.9.0 || ^16.9.0"
"graphql": "^15.10.0 || ^16.10.0"
},

@@ -100,10 +99,9 @@ "devDependencies": {

"@rollup/plugin-terser": "^0.4.4",
"@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.5",
"@types/glob": "^8.1.0",
"@types/ws": "^8.5.10",
"@types/ws": "^8.5.13",
"bun-types": "^1.1.4",
"fastify": "^5.2.1",
"glob": "^10.3.12",
"graphql": "^16.9.0",
"graphql": "^16.10.0",
"jsdom": "^25.0.1",

@@ -113,13 +111,10 @@ "pkgroll": "patch:pkgroll@npm%3A2.6.1#~/.yarn/patches/pkgroll-npm-2.6.1-193e78e84e.patch",

"prettier-plugin-sh": "^0.14.0",
"replacestream": "^4.0.3",
"rollup": "^4.30.1",
"subscriptions-transport-ws": "^0.11.0",
"tslib": "^2.6.2",
"typedoc": "^0.25.13",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^5.4.5",
"typedoc": "^0.27.6",
"typedoc-plugin-markdown": "^4.4.1",
"typescript": "^5.7.3",
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.51.0",
"vitest": "^2.1.8",
"ws": "8.12.0"
"ws": "^8.18.0"
}
}

@@ -197,10 +197,2 @@ (function (global, factory) {

}
function isMessage(val) {
try {
validateMessage(val);
return true;
} catch {
return false;
}
}
function parseMessage(data, reviver) {

@@ -241,3 +233,2 @@ return validateMessage(

shouldRetry = isLikeCloseEvent,
isFatalConnectionProblem,
on,

@@ -516,3 +507,2 @@ webSocketImpl,

if (!shouldRetry(errOrCloseEvent)) throw errOrCloseEvent;
if (isFatalConnectionProblem?.(errOrCloseEvent)) throw errOrCloseEvent;
return retrying = true;

@@ -718,3 +708,2 @@ }

exports.createClient = createClient;
exports.isMessage = isMessage;
exports.parseMessage = parseMessage;

@@ -721,0 +710,0 @@ exports.stringifyMessage = stringifyMessage;

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