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

graphql-ws

Package Overview
Dependencies
Maintainers
1
Versions
103
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 4.3.3 to 4.3.4

7

CHANGELOG.md

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

## [4.3.4](https://github.com/enisdenjo/graphql-ws/compare/v4.3.3...v4.3.4) (2021-04-11)
### Bug Fixes
* **client:** Subscriptions acquire locks ([eb6cb2a](https://github.com/enisdenjo/graphql-ws/commit/eb6cb2a0654489e1210a8db93f90bfc3ebfe94e4))
## [4.3.3](https://github.com/enisdenjo/graphql-ws/compare/v4.3.2...v4.3.3) (2021-04-11)

@@ -2,0 +9,0 @@

11

lib/client.js

@@ -120,6 +120,2 @@ "use strict";

async function connect() {
// locks increment only when not retrying because
// the same lock retries connect on abrupt closures
if (!retrying)
locks++;
const [socket, throwOnClose] = await (connecting !== null && connecting !== void 0 ? connecting : (connecting = new Promise((connected, denied) => (async () => {

@@ -177,3 +173,3 @@ if (retrying) {

let release = () => {
// releases this connection lock
// releases this connection
};

@@ -187,4 +183,5 @@ const released = new Promise((resolve) => (release = resolve));

released.then(() => {
// decrement the subscription locks
if (!--locks) {
// if no more connection locks are present, complete the connection
// and if no more are present, complete the connection
const complete = () => socket.close(1000, 'Normal Closure');

@@ -242,2 +239,3 @@ if (isFinite(keepAlive) && keepAlive > 0) {

(async () => {
locks++;
for (;;) {

@@ -270,2 +268,3 @@ try {

(async () => {
locks++;
for (;;) {

@@ -272,0 +271,0 @@ try {

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

@@ -5,0 +5,0 @@ "keywords": [

@@ -218,6 +218,2 @@ (function (global, factory) {

async function connect() {
// locks increment only when not retrying because
// the same lock retries connect on abrupt closures
if (!retrying)
locks++;
const [socket, throwOnClose] = await (connecting !== null && connecting !== void 0 ? connecting : (connecting = new Promise((connected, denied) => (async () => {

@@ -275,3 +271,3 @@ if (retrying) {

let release = () => {
// releases this connection lock
// releases this connection
};

@@ -285,4 +281,5 @@ const released = new Promise((resolve) => (release = resolve));

released.then(() => {
// decrement the subscription locks
if (!--locks) {
// if no more connection locks are present, complete the connection
// and if no more are present, complete the connection
const complete = () => socket.close(1000, 'Normal Closure');

@@ -340,2 +337,3 @@ if (isFinite(keepAlive) && keepAlive > 0) {

(async () => {
locks++;
for (;;) {

@@ -368,2 +366,3 @@ try {

(async () => {
locks++;
for (;;) {

@@ -370,0 +369,0 @@ try {

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";const n="graphql-transport-ws",o=Object.prototype.hasOwnProperty;function t(e){return"object"==typeof e&&null!==e}function r(e,n){return o.call(e,n)}function a(e,n){return o.call(e,n)&&t(e[n])}function i(e,n){return o.call(e,n)&&"string"==typeof e[n]}var s;function c(n){if(t(n)){if(!i(n,"type"))return!1;switch(n.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:return!r(n,"payload")||void 0===n.payload||t(n.payload);case e.MessageType.Subscribe:return i(n,"id")&&a(n,"payload")&&(!r(n.payload,"operationName")||void 0===n.payload.operationName||null===n.payload.operationName||"string"==typeof n.payload.operationName)&&i(n.payload,"query")&&(!r(n.payload,"variables")||void 0===n.payload.variables||null===n.payload.variables||a(n.payload,"variables"));case e.MessageType.Next:return i(n,"id")&&a(n,"payload");case e.MessageType.Error:return i(n,"id")&&(o=n.payload,Array.isArray(o)&&o.length>0&&o.every((e=>"message"in e)));case e.MessageType.Complete:return i(n,"id");default:return!1}}var o;return!1}function l(e){if(c(e))return e;if("string"!=typeof e)throw new Error("Message not parsable");const n=JSON.parse(e);if(!c(n))throw new Error("Invalid message");return n}function d(e){if(!c(e))throw new Error("Cannot stringify invalid message");return JSON.stringify(e)}function p(e){return t(e)&&"code"in e&&"reason"in e}e.MessageType=void 0,(s=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",s.ConnectionAck="connection_ack",s.Subscribe="subscribe",s.Next="next",s.Error="error",s.Complete="complete",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=n,e.createClient=function(o){const{url:t,connectionParams:r,lazy:a=!0,onNonLazyError:i=console.error,keepAlive:s=0,retryAttempts:c=5,retryWait:y=async function(e){let n=1e3;for(let o=0;o<e;o++)n*=2;await new Promise((e=>setTimeout(e,n+Math.floor(2700*Math.random()+300))))},isFatalConnectionProblem:u=(e=>!p(e)),on:f,webSocketImpl:g,generateID:m=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const n=16*Math.random()|0;return("x"==e?n:3&n|8).toString(16)}))}}=o;let w;if(g){if(!("function"==typeof(x=g)&&"constructor"in x&&"CLOSED"in x&&"CLOSING"in x&&"CONNECTING"in x&&"OPEN"in x))throw new Error("Invalid WebSocket implementation provided");w=g}else"undefined"!=typeof WebSocket?w=WebSocket:"undefined"!=typeof global?w=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(w=window.WebSocket||window.MozWebSocket);var x;if(!w)throw new Error("WebSocket implementation missing");const b=w,v=(()=>{const e=(()=>{const e={};return{on:(n,o)=>(e[n]=o,()=>{delete e[n]}),emit(n){var o;"id"in n&&(null===(o=e[n.id])||void 0===o||o.call(e,n))}}})(),n={connecting:(null==f?void 0:f.connecting)?[f.connecting]:[],connected:(null==f?void 0:f.connected)?[f.connected]:[],message:(null==f?void 0:f.message)?[e.emit,f.message]:[e.emit],closed:(null==f?void 0:f.closed)?[f.closed]:[],error:(null==f?void 0:f.error)?[f.error]:[]};return{onMessage:e.on,on(e,o){const t=n[e];return t.push(o),()=>{t.splice(t.indexOf(o),1)}},emit(e,...o){for(const t of n[e])t(...o)}}})();let h,M=0,T=!1,S=0,C=!1;async function E(){T||M++;const[o,a]=await(null!=h?h:h=new Promise(((o,a)=>(async()=>{T&&(await y(S),S++),v.emit("connecting");const i=new b("function"==typeof t?await t():t,n);i.onerror=e=>{v.emit("error",e)},i.onclose=e=>{h=void 0,v.emit("closed",e),a(e)},i.onopen=async()=>{try{i.send(d({type:e.MessageType.ConnectionInit,payload:"function"==typeof r?await r():r}))}catch(e){i.close(4400,e instanceof Error?e.message:new Error(e).message)}};let s=!1;i.onmessage=({data:n})=>{try{const t=l(n);if(v.emit("message",t),s)return;if(t.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${t.type}`);s=!0,v.emit("connected",i,t.payload),S=0,o([i,new Promise(((e,n)=>i.addEventListener("close",n)))])}catch(e){i.close(4400,e instanceof Error?e.message:new Error(e).message)}}})())));let i=()=>{};const c=new Promise((e=>i=e));return[o,i,Promise.race([c.then((()=>{if(!--M){const e=()=>o.close(1e3,"Normal Closure");isFinite(s)&&s>0?setTimeout((()=>{M||o.readyState!==b.OPEN||e()}),s):e()}})),a])]}function N(e){if(p(e)&&[1002,1011,4400,4401,4409,4429].includes(e.code))throw e;if(C||p(e)&&1e3===e.code)return!1;if(!c||S>=c)throw e;if(u(e))throw e;return T=!0}return a||(async()=>{for(;;)try{const[,,e]=await E();await e}catch(e){try{if(!N(e))return}catch(e){return null==i?void 0:i(e)}}})(),{on:v.on,subscribe(n,o){const t=m();let r=!1,a=()=>{r=!0};return(async()=>{for(;;)try{const[i,s,c]=await E();if(r)return s();const l=v.onMessage(t,(n=>{switch(n.type){case e.MessageType.Next:return void o.next(n.payload);case e.MessageType.Error:return r=!0,o.error(n.payload),void a();case e.MessageType.Complete:return r=!0,void a()}}));return i.send(d({id:t,type:e.MessageType.Subscribe,payload:n})),a=()=>{r||i.readyState!==b.OPEN||i.send(d({id:t,type:e.MessageType.Complete})),s()},void await c.finally(l)}catch(e){if(!N(e))return}})().catch(o.error).then(o.complete),()=>a()},async dispose(){if(C=!0,h){const[e]=await h;e.close(1e3,"Normal Closure")}}}},e.isMessage=c,e.parseMessage=l,e.stringifyMessage=d,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";const n="graphql-transport-ws",o=Object.prototype.hasOwnProperty;function t(e){return"object"==typeof e&&null!==e}function r(e,n){return o.call(e,n)}function a(e,n){return o.call(e,n)&&t(e[n])}function i(e,n){return o.call(e,n)&&"string"==typeof e[n]}var s;function c(n){if(t(n)){if(!i(n,"type"))return!1;switch(n.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:return!r(n,"payload")||void 0===n.payload||t(n.payload);case e.MessageType.Subscribe:return i(n,"id")&&a(n,"payload")&&(!r(n.payload,"operationName")||void 0===n.payload.operationName||null===n.payload.operationName||"string"==typeof n.payload.operationName)&&i(n.payload,"query")&&(!r(n.payload,"variables")||void 0===n.payload.variables||null===n.payload.variables||a(n.payload,"variables"));case e.MessageType.Next:return i(n,"id")&&a(n,"payload");case e.MessageType.Error:return i(n,"id")&&(o=n.payload,Array.isArray(o)&&o.length>0&&o.every((e=>"message"in e)));case e.MessageType.Complete:return i(n,"id");default:return!1}}var o;return!1}function l(e){if(c(e))return e;if("string"!=typeof e)throw new Error("Message not parsable");const n=JSON.parse(e);if(!c(n))throw new Error("Invalid message");return n}function d(e){if(!c(e))throw new Error("Cannot stringify invalid message");return JSON.stringify(e)}function p(e){return t(e)&&"code"in e&&"reason"in e}e.MessageType=void 0,(s=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",s.ConnectionAck="connection_ack",s.Subscribe="subscribe",s.Next="next",s.Error="error",s.Complete="complete",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=n,e.createClient=function(o){const{url:t,connectionParams:r,lazy:a=!0,onNonLazyError:i=console.error,keepAlive:s=0,retryAttempts:c=5,retryWait:y=async function(e){let n=1e3;for(let o=0;o<e;o++)n*=2;await new Promise((e=>setTimeout(e,n+Math.floor(2700*Math.random()+300))))},isFatalConnectionProblem:u=(e=>!p(e)),on:f,webSocketImpl:g,generateID:m=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const n=16*Math.random()|0;return("x"==e?n:3&n|8).toString(16)}))}}=o;let w;if(g){if(!("function"==typeof(x=g)&&"constructor"in x&&"CLOSED"in x&&"CLOSING"in x&&"CONNECTING"in x&&"OPEN"in x))throw new Error("Invalid WebSocket implementation provided");w=g}else"undefined"!=typeof WebSocket?w=WebSocket:"undefined"!=typeof global?w=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(w=window.WebSocket||window.MozWebSocket);var x;if(!w)throw new Error("WebSocket implementation missing");const b=w,v=(()=>{const e=(()=>{const e={};return{on:(n,o)=>(e[n]=o,()=>{delete e[n]}),emit(n){var o;"id"in n&&(null===(o=e[n.id])||void 0===o||o.call(e,n))}}})(),n={connecting:(null==f?void 0:f.connecting)?[f.connecting]:[],connected:(null==f?void 0:f.connected)?[f.connected]:[],message:(null==f?void 0:f.message)?[e.emit,f.message]:[e.emit],closed:(null==f?void 0:f.closed)?[f.closed]:[],error:(null==f?void 0:f.error)?[f.error]:[]};return{onMessage:e.on,on(e,o){const t=n[e];return t.push(o),()=>{t.splice(t.indexOf(o),1)}},emit(e,...o){for(const t of n[e])t(...o)}}})();let h,M=0,T=!1,S=0,C=!1;async function E(){const[o,a]=await(null!=h?h:h=new Promise(((o,a)=>(async()=>{T&&(await y(S),S++),v.emit("connecting");const i=new b("function"==typeof t?await t():t,n);i.onerror=e=>{v.emit("error",e)},i.onclose=e=>{h=void 0,v.emit("closed",e),a(e)},i.onopen=async()=>{try{i.send(d({type:e.MessageType.ConnectionInit,payload:"function"==typeof r?await r():r}))}catch(e){i.close(4400,e instanceof Error?e.message:new Error(e).message)}};let s=!1;i.onmessage=({data:n})=>{try{const t=l(n);if(v.emit("message",t),s)return;if(t.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${t.type}`);s=!0,v.emit("connected",i,t.payload),S=0,o([i,new Promise(((e,n)=>i.addEventListener("close",n)))])}catch(e){i.close(4400,e instanceof Error?e.message:new Error(e).message)}}})())));let i=()=>{};const c=new Promise((e=>i=e));return[o,i,Promise.race([c.then((()=>{if(!--M){const e=()=>o.close(1e3,"Normal Closure");isFinite(s)&&s>0?setTimeout((()=>{M||o.readyState!==b.OPEN||e()}),s):e()}})),a])]}function N(e){if(p(e)&&[1002,1011,4400,4401,4409,4429].includes(e.code))throw e;if(C||p(e)&&1e3===e.code)return!1;if(!c||S>=c)throw e;if(u(e))throw e;return T=!0}return a||(async()=>{for(M++;;)try{const[,,e]=await E();await e}catch(e){try{if(!N(e))return}catch(e){return null==i?void 0:i(e)}}})(),{on:v.on,subscribe(n,o){const t=m();let r=!1,a=()=>{r=!0};return(async()=>{for(M++;;)try{const[i,s,c]=await E();if(r)return s();const l=v.onMessage(t,(n=>{switch(n.type){case e.MessageType.Next:return void o.next(n.payload);case e.MessageType.Error:return r=!0,o.error(n.payload),void a();case e.MessageType.Complete:return r=!0,void a()}}));return i.send(d({id:t,type:e.MessageType.Subscribe,payload:n})),a=()=>{r||i.readyState!==b.OPEN||i.send(d({id:t,type:e.MessageType.Complete})),s()},void await c.finally(l)}catch(e){if(!N(e))return}})().catch(o.error).then(o.complete),()=>a()},async dispose(){if(C=!0,h){const[e]=await h;e.close(1e3,"Normal Closure")}}}},e.isMessage=c,e.parseMessage=l,e.stringifyMessage=d,Object.defineProperty(e,"__esModule",{value:!0})}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc