Socket
Socket
Sign inDemoInstall

graphql-ws

Package Overview
Dependencies
0
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.1 to 5.1.2

7

CHANGELOG.md

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

## [5.1.2](https://github.com/enisdenjo/graphql-ws/compare/v5.1.1...v5.1.2) (2021-06-09)
### Bug Fixes
* **client:** Return ping's payload through the response pong ([ee6193a](https://github.com/enisdenjo/graphql-ws/commit/ee6193a6b789124f903b4688df8a6c680bbadc81))
## [5.1.1](https://github.com/enisdenjo/graphql-ws/compare/v5.1.0...v5.1.1) (2021-06-09)

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

12

lib/client.js

@@ -184,4 +184,12 @@ "use strict";

// respond with pong on ping
socket.send(common_1.stringifyMessage({ type: common_1.MessageType.Pong }));
emitter.emit('pong', false, undefined);
socket.send(common_1.stringifyMessage(message.payload
? {
type: common_1.MessageType.Pong,
payload: message.payload,
}
: {
type: common_1.MessageType.Pong,
// payload is completely absent if not provided
}));
emitter.emit('pong', false, message.payload);
}

@@ -188,0 +196,0 @@ return; // ping and pongs can be received whenever

2

package.json
{
"name": "graphql-ws",
"version": "5.1.1",
"version": "5.1.2",
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client",

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

@@ -311,4 +311,12 @@ (function (global, factory) {

// respond with pong on ping
socket.send(stringifyMessage({ type: exports.MessageType.Pong }));
emitter.emit('pong', false, undefined);
socket.send(stringifyMessage(message.payload
? {
type: exports.MessageType.Pong,
payload: message.payload,
}
: {
type: exports.MessageType.Pong,
// payload is completely absent if not provided
}));
emitter.emit('pong', false, message.payload);
}

@@ -315,0 +323,0 @@ return; // ping and pongs can be received whenever

@@ -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=Object.prototype.hasOwnProperty;function o(e){return"object"==typeof e&&null!==e}function t(e,o){return n.call(e,o)}function r(e,t){return n.call(e,t)&&o(e[t])}function a(e,o){return n.call(e,o)&&"string"==typeof e[o]}const i="graphql-transport-ws";var s;function c(n){if(o(n)){if(!a(n,"type"))return!1;switch(n.type){case e.MessageType.ConnectionInit:return!t(n,"payload")||void 0===n.payload||o(n.payload);case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:return!t(n,"payload")||void 0===n.payload||o(n.payload);case e.MessageType.Subscribe:return a(n,"id")&&r(n,"payload")&&(!t(n.payload,"operationName")||void 0===n.payload.operationName||null===n.payload.operationName||"string"==typeof n.payload.operationName)&&a(n.payload,"query")&&(!t(n.payload,"variables")||void 0===n.payload.variables||null===n.payload.variables||r(n.payload,"variables"))&&(!t(n.payload,"extensions")||void 0===n.payload.extensions||null===n.payload.extensions||r(n.payload,"extensions"));case e.MessageType.Next:return a(n,"id")&&r(n,"payload");case e.MessageType.Error:return a(n,"id")&&(i=n.payload,Array.isArray(i)&&i.length>0&&i.every((e=>"message"in e)));case e.MessageType.Complete:return a(n,"id");default:return!1}}var i;return!1}function l(e,n){if(c(e))return e;if("string"!=typeof e)throw new Error("Message not parsable");const o=JSON.parse(e,n);if(!c(o))throw new Error("Invalid message");return o}function p(e,n){if(!c(e))throw new Error("Cannot stringify invalid message");return JSON.stringify(e,n)}function d(e){return o(e)&&"code"in e&&"reason"in e}e.MessageType=void 0,(s=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",s.ConnectionAck="connection_ack",s.Ping="ping",s.Pong="pong",s.Subscribe="subscribe",s.Next="next",s.Error="error",s.Complete="complete",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=i,e.createClient=function(n){const{url:o,connectionParams:t,lazy:r=!0,onNonLazyError:a=console.error,lazyCloseTimeout:s=0,keepAlive:c=0,disablePong:y,retryAttempts:u=5,retryWait:f=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:g=(e=>!d(e)),on:m,webSocketImpl:x,generateID:w=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)}))},jsonMessageReplacer:v,jsonMessageReviver:b}=n;let M;if(x){if(!("function"==typeof(T=x)&&"constructor"in T&&"CLOSED"in T&&"CLOSING"in T&&"CONNECTING"in T&&"OPEN"in T))throw new Error("Invalid WebSocket implementation provided");M=x}else"undefined"!=typeof WebSocket?M=WebSocket:"undefined"!=typeof global?M=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(M=window.WebSocket||window.MozWebSocket);var T;if(!M)throw new Error("WebSocket implementation missing");const h=M,S=(()=>{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==m?void 0:m.connecting)?[m.connecting]:[],connected:(null==m?void 0:m.connected)?[m.connected]:[],ping:(null==m?void 0:m.ping)?[m.ping]:[],pong:(null==m?void 0:m.pong)?[m.pong]:[],message:(null==m?void 0:m.message)?[e.emit,m.message]:[e.emit],closed:(null==m?void 0:m.closed)?[m.closed]:[],error:(null==m?void 0:m.error)?[m.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 P,C=0,N=!1,E=0,O=!1;async function k(){const[n,r]=await(null!=P?P:P=new Promise(((n,r)=>(async()=>{if(N){if(await f(E),!C)return P=void 0,r({code:1e3,reason:"All Subscriptions Gone"});E++}S.emit("connecting");const a=new h("function"==typeof o?await o():o,i);let s;function d(){isFinite(c)&&c>0&&(clearTimeout(s),s=setTimeout((()=>{a.readyState===h.OPEN&&(a.send(p({type:e.MessageType.Ping})),S.emit("ping",!1,void 0))}),c))}a.onerror=e=>{S.emit("error",e)},a.onclose=e=>{P=void 0,clearTimeout(s),S.emit("closed",e),r(e)},a.onopen=async()=>{try{a.send(p({type:e.MessageType.ConnectionInit,payload:"function"==typeof t?await t():t},v)),d()}catch(e){a.close(4400,e instanceof Error?e.message:new Error(e).message)}};let u=!1;a.onmessage=({data:o})=>{try{const t=l(o,b);if(S.emit("message",t),"ping"===t.type||"pong"===t.type)return S.emit(t.type,!0,t.payload),void("pong"===t.type?d():y||(a.send(p({type:e.MessageType.Pong})),S.emit("pong",!1,void 0)));if(u)return;if(t.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${t.type}`);u=!0,S.emit("connected",a,t.payload),N=!1,E=0,n([a,new Promise(((e,n)=>a.addEventListener("close",n)))])}catch(e){a.close(4400,e instanceof Error?e.message:new Error(e).message)}}})())));n.readyState===h.CLOSING&&await r;let a=()=>{};const d=new Promise((e=>a=e));return[n,a,Promise.race([d.then((()=>{if(!C){const e=()=>n.close(1e3,"Normal Closure");isFinite(s)&&s>0?setTimeout((()=>{C||n.readyState!==h.OPEN||e()}),s):e()}})),r])]}function W(e){if(d(e)&&[1002,1011,4400,4401,4409,4429].includes(e.code))throw e;if(O)return!1;if(d(e)&&1e3===e.code)return C>0;if(!u||E>=u)throw e;if(g(e))throw e;return N=!0}return r||(async()=>{for(C++;;)try{const[,,e]=await k();await e}catch(e){try{if(!W(e))return}catch(e){return null==a?void 0:a(e)}}})(),{on:S.on,subscribe(n,o){const t=w();let r=!1,a=!1,i=()=>{C--,r=!0};return(async()=>{for(C++;;)try{const[s,c,l]=await k();if(r)return c();const d=S.onMessage(t,(n=>{switch(n.type){case e.MessageType.Next:return void o.next(n.payload);case e.MessageType.Error:return a=!0,r=!0,o.error(n.payload),void i();case e.MessageType.Complete:return r=!0,void i()}}));return s.send(p({id:t,type:e.MessageType.Subscribe,payload:n},v)),i=()=>{r||s.readyState!==h.OPEN||s.send(p({id:t,type:e.MessageType.Complete},v)),C--,r=!0,c()},void await l.finally(d)}catch(e){if(!W(e))return}})().catch(o.error).then((()=>{a||o.complete()})),()=>{r||i()}},async dispose(){if(O=!0,P){const[e]=await P;e.close(1e3,"Normal Closure")}}}},e.isMessage=c,e.parseMessage=l,e.stringifyMessage=p,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=Object.prototype.hasOwnProperty;function o(e){return"object"==typeof e&&null!==e}function t(e,o){return n.call(e,o)}function r(e,t){return n.call(e,t)&&o(e[t])}function a(e,o){return n.call(e,o)&&"string"==typeof e[o]}const i="graphql-transport-ws";var s;function c(n){if(o(n)){if(!a(n,"type"))return!1;switch(n.type){case e.MessageType.ConnectionInit:return!t(n,"payload")||void 0===n.payload||o(n.payload);case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:return!t(n,"payload")||void 0===n.payload||o(n.payload);case e.MessageType.Subscribe:return a(n,"id")&&r(n,"payload")&&(!t(n.payload,"operationName")||void 0===n.payload.operationName||null===n.payload.operationName||"string"==typeof n.payload.operationName)&&a(n.payload,"query")&&(!t(n.payload,"variables")||void 0===n.payload.variables||null===n.payload.variables||r(n.payload,"variables"))&&(!t(n.payload,"extensions")||void 0===n.payload.extensions||null===n.payload.extensions||r(n.payload,"extensions"));case e.MessageType.Next:return a(n,"id")&&r(n,"payload");case e.MessageType.Error:return a(n,"id")&&(i=n.payload,Array.isArray(i)&&i.length>0&&i.every((e=>"message"in e)));case e.MessageType.Complete:return a(n,"id");default:return!1}}var i;return!1}function l(e,n){if(c(e))return e;if("string"!=typeof e)throw new Error("Message not parsable");const o=JSON.parse(e,n);if(!c(o))throw new Error("Invalid message");return o}function p(e,n){if(!c(e))throw new Error("Cannot stringify invalid message");return JSON.stringify(e,n)}function d(e){return o(e)&&"code"in e&&"reason"in e}e.MessageType=void 0,(s=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",s.ConnectionAck="connection_ack",s.Ping="ping",s.Pong="pong",s.Subscribe="subscribe",s.Next="next",s.Error="error",s.Complete="complete",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=i,e.createClient=function(n){const{url:o,connectionParams:t,lazy:r=!0,onNonLazyError:a=console.error,lazyCloseTimeout:s=0,keepAlive:c=0,disablePong:y,retryAttempts:u=5,retryWait:g=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:f=(e=>!d(e)),on:m,webSocketImpl:x,generateID:w=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)}))},jsonMessageReplacer:v,jsonMessageReviver:b}=n;let M;if(x){if(!("function"==typeof(T=x)&&"constructor"in T&&"CLOSED"in T&&"CLOSING"in T&&"CONNECTING"in T&&"OPEN"in T))throw new Error("Invalid WebSocket implementation provided");M=x}else"undefined"!=typeof WebSocket?M=WebSocket:"undefined"!=typeof global?M=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(M=window.WebSocket||window.MozWebSocket);var T;if(!M)throw new Error("WebSocket implementation missing");const h=M,S=(()=>{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==m?void 0:m.connecting)?[m.connecting]:[],connected:(null==m?void 0:m.connected)?[m.connected]:[],ping:(null==m?void 0:m.ping)?[m.ping]:[],pong:(null==m?void 0:m.pong)?[m.pong]:[],message:(null==m?void 0:m.message)?[e.emit,m.message]:[e.emit],closed:(null==m?void 0:m.closed)?[m.closed]:[],error:(null==m?void 0:m.error)?[m.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 P,C=0,N=!1,E=0,O=!1;async function k(){const[n,r]=await(null!=P?P:P=new Promise(((n,r)=>(async()=>{if(N){if(await g(E),!C)return P=void 0,r({code:1e3,reason:"All Subscriptions Gone"});E++}S.emit("connecting");const a=new h("function"==typeof o?await o():o,i);let s;function d(){isFinite(c)&&c>0&&(clearTimeout(s),s=setTimeout((()=>{a.readyState===h.OPEN&&(a.send(p({type:e.MessageType.Ping})),S.emit("ping",!1,void 0))}),c))}a.onerror=e=>{S.emit("error",e)},a.onclose=e=>{P=void 0,clearTimeout(s),S.emit("closed",e),r(e)},a.onopen=async()=>{try{a.send(p({type:e.MessageType.ConnectionInit,payload:"function"==typeof t?await t():t},v)),d()}catch(e){a.close(4400,e instanceof Error?e.message:new Error(e).message)}};let u=!1;a.onmessage=({data:o})=>{try{const t=l(o,b);if(S.emit("message",t),"ping"===t.type||"pong"===t.type)return S.emit(t.type,!0,t.payload),void("pong"===t.type?d():y||(a.send(p(t.payload?{type:e.MessageType.Pong,payload:t.payload}:{type:e.MessageType.Pong})),S.emit("pong",!1,t.payload)));if(u)return;if(t.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${t.type}`);u=!0,S.emit("connected",a,t.payload),N=!1,E=0,n([a,new Promise(((e,n)=>a.addEventListener("close",n)))])}catch(e){a.close(4400,e instanceof Error?e.message:new Error(e).message)}}})())));n.readyState===h.CLOSING&&await r;let a=()=>{};const d=new Promise((e=>a=e));return[n,a,Promise.race([d.then((()=>{if(!C){const e=()=>n.close(1e3,"Normal Closure");isFinite(s)&&s>0?setTimeout((()=>{C||n.readyState!==h.OPEN||e()}),s):e()}})),r])]}function W(e){if(d(e)&&[1002,1011,4400,4401,4409,4429].includes(e.code))throw e;if(O)return!1;if(d(e)&&1e3===e.code)return C>0;if(!u||E>=u)throw e;if(f(e))throw e;return N=!0}return r||(async()=>{for(C++;;)try{const[,,e]=await k();await e}catch(e){try{if(!W(e))return}catch(e){return null==a?void 0:a(e)}}})(),{on:S.on,subscribe(n,o){const t=w();let r=!1,a=!1,i=()=>{C--,r=!0};return(async()=>{for(C++;;)try{const[s,c,l]=await k();if(r)return c();const d=S.onMessage(t,(n=>{switch(n.type){case e.MessageType.Next:return void o.next(n.payload);case e.MessageType.Error:return a=!0,r=!0,o.error(n.payload),void i();case e.MessageType.Complete:return r=!0,void i()}}));return s.send(p({id:t,type:e.MessageType.Subscribe,payload:n},v)),i=()=>{r||s.readyState!==h.OPEN||s.send(p({id:t,type:e.MessageType.Complete},v)),C--,r=!0,c()},void await l.finally(d)}catch(e){if(!W(e))return}})().catch(o.error).then((()=>{a||o.complete()})),()=>{r||i()}},async dispose(){if(O=!0,P){const[e]=await P;e.close(1e3,"Normal Closure")}}}},e.isMessage=c,e.parseMessage=l,e.stringifyMessage=p,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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc