@gqless/subscriptions
Advanced tools
Comparing version 1.0.10 to 1.0.11
# @gqless/subscriptions | ||
## 1.0.11 | ||
### Patch Changes | ||
- af6a437: - Rename `GqlessConfig` to `GQlessConfig` (so it's consistent with the new logo) | ||
- Rename `gqlessError` to `GQlessError` | ||
- Remove `endpoint` option from the configuration, and instead always defaults to introspection one | ||
- It's confusing why theres two of them, and the user can change it later by modifying the file anyway | ||
- Updated dependencies [4a3d5ef] | ||
- Updated dependencies [af6a437] | ||
- gqless@2.0.13 | ||
## 1.0.10 | ||
@@ -4,0 +16,0 @@ |
@@ -453,3 +453,3 @@ 'use strict'; | ||
data, | ||
error: gqless.gqlessError.fromGraphQLErrors(errors) | ||
error: gqless.GQlessError.fromGraphQLErrors(errors) | ||
}); | ||
@@ -456,0 +456,0 @@ } else if (data) { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=require("gqless");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}const s=e(require("isomorphic-ws"));function n(){let t,e;return{promise:new Promise(((s,n)=>{t=s,e=n})),resolve:t,reject:e}}class o{constructor(t,{headers:e={},reconnect:s=!0,maxReconnectAttempts:o=1/0,connectionCallback:i,failedConnectionCallback:c,failedReconnectCallback:r,connectionInitPayload:a={},lazy:l=!0}){this.uri=t,this.socket=null,this.operationId=0,this.ready=!1,this.operations=new Map,this.operationsCount={},this.lazy=l,this.subscriptionQueryMap={},this.headers=e,this.tryReconnect=s,this.maxReconnectAttempts=o,this.reconnectAttempts=0,this.connectionCallback=i,this.failedConnectionCallback=c,this.failedReconnectCallback=r,this.connectionInitPayload=a,l||this.connect(),this.connectedPromise=n()}connect(){if(null!==this.socket)return;this.socket=new s.default(this.uri,["graphql-ws"],{headers:this.headers});const t=this.socketReady=n();this.socket.onopen=async()=>{if(this.socket&&this.socket.readyState===s.default.OPEN)try{const e="function"==typeof this.connectionInitPayload?await this.connectionInitPayload():this.connectionInitPayload;this.sendMessage(null,"connection_init",e),t.resolve(!0)}catch(e){this.close(this.tryReconnect,!1),t.resolve(!1)}else t.resolve(!1)},this.socket.onclose=()=>{this.closedByUser||this.close(this.tryReconnect,!1),t.resolve(!1)},this.socket.onerror=()=>{},this.socket.onmessage=async({data:t})=>{await this.handleMessage(t.toString("utf-8"))}}close(t=!1,e=!0){if(this.closedByUser=e,this.ready=!1,this.connectedPromise.resolve(Error("Socket closed!")),null!==this.socket&&(e&&this.unsubscribeAll(),this.socket.close(),this.socket=null,this.reconnecting=!1,t)){this.connectedPromise=n();for(const t of this.operations.keys()){const e=this.operations.get(t);e&&this.operations.set(t,{...e,started:!1})}this.reconnect()}}getReconnectDelay(){const t=100*Math.pow(2,this.reconnectAttempts);return Math.min(t,1e4)}reconnect(){if(this.reconnecting||this.reconnectAttempts>this.maxReconnectAttempts)return this.failedReconnectCallback&&this.failedReconnectCallback();this.reconnectAttempts++,this.reconnecting=!0;const t=this.getReconnectDelay();this.reconnectTimeoutId=setTimeout((()=>{this.connect()}),t)}async unsubscribe(t,e=!1){let s=this.operationsCount[t];if(s--,0===s||e){if(this.operationsCount[t]=0,this.operations.delete(t),await this.sendMessage(t,"stop",null),this.lazy){const t=this;setTimeout((()=>{0===t.operations.size&&this.socket&&t.close()}),2e3)}}else this.operationsCount[t]=s}unsubscribeAll(){for(const t of this.operations.keys())this.unsubscribe(t,!0).catch(console.error)}sendMessage(t,e,s={},n){return new Promise((async(o,i)=>{try{if(this.socketReady){if(!await this.socketReady.promise)return o()}if(!this.socket)return o();this.socket.send(JSON.stringify({id:t,type:e,payload:s,extensions:n}),(t=>{t&&console.error(t),o()})),setTimeout(o,200)}catch(t){i(t)}}))}async handleMessage(t){let e,s,n;try{e=JSON.parse(t),s=e.id}catch(e){throw new Error(`Invalid message received: "${t}" Message must be JSON parsable.`)}switch(s&&(n=this.operations.get(s)),e.type){case"connection_ack":this.reconnecting=!1,this.ready=!0,this.reconnectAttempts=0,this.connectedPromise.resolve();for(const t of this.operations.keys())this.startOperation(t).catch(console.error);this.connectionCallback&&this.connectionCallback();break;case"data":n&&n.handler(e.payload);break;case"error":n&&(n.handler({data:null,errors:[{message:e.payload}]}),this.operations.delete(s));break;case"complete":n&&(n.handler("complete"),this.operations.delete(s));break;case"connection_error":this.close(this.tryReconnect,!1),this.failedConnectionCallback&&await this.failedConnectionCallback(e.payload);break;case"ka":break;default:throw new Error(`Invalid message type: "${e.type}"`)}}async startOperation(t){try{await this.connectedPromise.promise;const e=this.operations.get(t);if(!e)throw Error("Operation not found, "+t);const{started:s,options:n,extensions:o}=e;if(!s){if(!this.ready)return;this.operations.set(t,{...e,started:!0}),await this.sendMessage(t,"start",n,o)}}finally{}}createSubscription(t,e,s,n){this.socket||this.connect(),n||(n=JSON.stringify({query:t,variables:e}));let o,i=this.subscriptionQueryMap[n];try{let r;if(i&&(r=this.operations.get(i)))return r.callbacks.add(s),this.operationsCount[i]=this.operationsCount[i]+1,i;i=String(++this.operationId);const a=new Set([s]);const l={started:!1,options:{query:t,variables:e},handler:function(t){const e={operationId:i,payload:t};for(const t of a)try{t(e)}catch(t){console.error(t)}},callbacks:a};return this.operations.set(i,l),o=this.startOperation(i),this.operationsCount[i]=1,this.subscriptionQueryMap[n]=i,o.then((()=>i))}finally{function c(){setTimeout((()=>{s({operationId:i,payload:"start"})}),0)}o?o.then(c):c()}}}exports.createSubscriptionsClient=function({wsEndpoint:e,...s}){const n=Promise.resolve("string"==typeof e?e:e());let i;const c=new Promise(((t,e)=>{n.then((e=>{const n=new o(e,{...s});i=n,t(n)})).catch(e)})),r=new Map,a=new WeakMap;return{subscribe({query:e,variables:s,events:n,cacheKey:o,selections:l}){let h="NO_ID";const u={query:e,variables:s,operationId:h,selections:l};return i?d(i):c.then((t=>d(t)));function d(i){let c;if(!(c=a.get(n))){const{onData:e,onError:s,onComplete:o,onStart:i}="function"==typeof n?n(u):n;c=function({payload:n,operationId:c}){switch(u.operationId=c,n){case"start":null==i||i();break;case"complete":r.delete(c),null==o||o();break;default:const{data:a,errors:l}=n;null!=l&&l.length?s({data:a,error:t.gqlessError.fromGraphQLErrors(l)}):a&&e(a)}},a.set(n,c)}const d=i.createSubscription(e,s,c,o);return d instanceof Promise?d.then((t=>(u.operationId=h=t,p(t)))):(u.operationId=h=d,p(h));function p(t){return r.set(t,new Set(l)),{unsubscribe:async()=>{await i.unsubscribe(t,!0),r.delete(t)},operationId:t}}}},async unsubscribe(t){const e=i||await c;let s=[];const n=[];t:for(const[o,i]of r.entries())for(const c of t)if(i.has(c)){n.push(o),s.push(e.unsubscribe(o,!0)),r.delete(o);continue t}return s.length&&await Promise.all(s),n},async close(){(i||await c).close()},setConnectionParams(t,e){i?(i.connectionInitPayload=t,e&&i.socket&&i.close(!0)):c.then((s=>{s.connectionInitPayload=t,e&&s.socket&&s.close(!0)})).catch(console.error)}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=require("gqless");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}const s=e(require("isomorphic-ws"));function n(){let t,e;return{promise:new Promise(((s,n)=>{t=s,e=n})),resolve:t,reject:e}}class o{constructor(t,{headers:e={},reconnect:s=!0,maxReconnectAttempts:o=1/0,connectionCallback:i,failedConnectionCallback:c,failedReconnectCallback:r,connectionInitPayload:a={},lazy:l=!0}){this.uri=t,this.socket=null,this.operationId=0,this.ready=!1,this.operations=new Map,this.operationsCount={},this.lazy=l,this.subscriptionQueryMap={},this.headers=e,this.tryReconnect=s,this.maxReconnectAttempts=o,this.reconnectAttempts=0,this.connectionCallback=i,this.failedConnectionCallback=c,this.failedReconnectCallback=r,this.connectionInitPayload=a,l||this.connect(),this.connectedPromise=n()}connect(){if(null!==this.socket)return;this.socket=new s.default(this.uri,["graphql-ws"],{headers:this.headers});const t=this.socketReady=n();this.socket.onopen=async()=>{if(this.socket&&this.socket.readyState===s.default.OPEN)try{const e="function"==typeof this.connectionInitPayload?await this.connectionInitPayload():this.connectionInitPayload;this.sendMessage(null,"connection_init",e),t.resolve(!0)}catch(e){this.close(this.tryReconnect,!1),t.resolve(!1)}else t.resolve(!1)},this.socket.onclose=()=>{this.closedByUser||this.close(this.tryReconnect,!1),t.resolve(!1)},this.socket.onerror=()=>{},this.socket.onmessage=async({data:t})=>{await this.handleMessage(t.toString("utf-8"))}}close(t=!1,e=!0){if(this.closedByUser=e,this.ready=!1,this.connectedPromise.resolve(Error("Socket closed!")),null!==this.socket&&(e&&this.unsubscribeAll(),this.socket.close(),this.socket=null,this.reconnecting=!1,t)){this.connectedPromise=n();for(const t of this.operations.keys()){const e=this.operations.get(t);e&&this.operations.set(t,{...e,started:!1})}this.reconnect()}}getReconnectDelay(){const t=100*Math.pow(2,this.reconnectAttempts);return Math.min(t,1e4)}reconnect(){if(this.reconnecting||this.reconnectAttempts>this.maxReconnectAttempts)return this.failedReconnectCallback&&this.failedReconnectCallback();this.reconnectAttempts++,this.reconnecting=!0;const t=this.getReconnectDelay();this.reconnectTimeoutId=setTimeout((()=>{this.connect()}),t)}async unsubscribe(t,e=!1){let s=this.operationsCount[t];if(s--,0===s||e){if(this.operationsCount[t]=0,this.operations.delete(t),await this.sendMessage(t,"stop",null),this.lazy){const t=this;setTimeout((()=>{0===t.operations.size&&this.socket&&t.close()}),2e3)}}else this.operationsCount[t]=s}unsubscribeAll(){for(const t of this.operations.keys())this.unsubscribe(t,!0).catch(console.error)}sendMessage(t,e,s={},n){return new Promise((async(o,i)=>{try{if(this.socketReady){if(!await this.socketReady.promise)return o()}if(!this.socket)return o();this.socket.send(JSON.stringify({id:t,type:e,payload:s,extensions:n}),(t=>{t&&console.error(t),o()})),setTimeout(o,200)}catch(t){i(t)}}))}async handleMessage(t){let e,s,n;try{e=JSON.parse(t),s=e.id}catch(e){throw new Error(`Invalid message received: "${t}" Message must be JSON parsable.`)}switch(s&&(n=this.operations.get(s)),e.type){case"connection_ack":this.reconnecting=!1,this.ready=!0,this.reconnectAttempts=0,this.connectedPromise.resolve();for(const t of this.operations.keys())this.startOperation(t).catch(console.error);this.connectionCallback&&this.connectionCallback();break;case"data":n&&n.handler(e.payload);break;case"error":n&&(n.handler({data:null,errors:[{message:e.payload}]}),this.operations.delete(s));break;case"complete":n&&(n.handler("complete"),this.operations.delete(s));break;case"connection_error":this.close(this.tryReconnect,!1),this.failedConnectionCallback&&await this.failedConnectionCallback(e.payload);break;case"ka":break;default:throw new Error(`Invalid message type: "${e.type}"`)}}async startOperation(t){try{await this.connectedPromise.promise;const e=this.operations.get(t);if(!e)throw Error("Operation not found, "+t);const{started:s,options:n,extensions:o}=e;if(!s){if(!this.ready)return;this.operations.set(t,{...e,started:!0}),await this.sendMessage(t,"start",n,o)}}finally{}}createSubscription(t,e,s,n){this.socket||this.connect(),n||(n=JSON.stringify({query:t,variables:e}));let o,i=this.subscriptionQueryMap[n];try{let r;if(i&&(r=this.operations.get(i)))return r.callbacks.add(s),this.operationsCount[i]=this.operationsCount[i]+1,i;i=String(++this.operationId);const a=new Set([s]);const l={started:!1,options:{query:t,variables:e},handler:function(t){const e={operationId:i,payload:t};for(const t of a)try{t(e)}catch(t){console.error(t)}},callbacks:a};return this.operations.set(i,l),o=this.startOperation(i),this.operationsCount[i]=1,this.subscriptionQueryMap[n]=i,o.then((()=>i))}finally{function c(){setTimeout((()=>{s({operationId:i,payload:"start"})}),0)}o?o.then(c):c()}}}exports.createSubscriptionsClient=function({wsEndpoint:e,...s}){const n=Promise.resolve("string"==typeof e?e:e());let i;const c=new Promise(((t,e)=>{n.then((e=>{const n=new o(e,{...s});i=n,t(n)})).catch(e)})),r=new Map,a=new WeakMap;return{subscribe({query:e,variables:s,events:n,cacheKey:o,selections:l}){let h="NO_ID";const u={query:e,variables:s,operationId:h,selections:l};return i?d(i):c.then((t=>d(t)));function d(i){let c;if(!(c=a.get(n))){const{onData:e,onError:s,onComplete:o,onStart:i}="function"==typeof n?n(u):n;c=function({payload:n,operationId:c}){switch(u.operationId=c,n){case"start":null==i||i();break;case"complete":r.delete(c),null==o||o();break;default:const{data:a,errors:l}=n;null!=l&&l.length?s({data:a,error:t.GQlessError.fromGraphQLErrors(l)}):a&&e(a)}},a.set(n,c)}const d=i.createSubscription(e,s,c,o);return d instanceof Promise?d.then((t=>(u.operationId=h=t,p(t)))):(u.operationId=h=d,p(h));function p(t){return r.set(t,new Set(l)),{unsubscribe:async()=>{await i.unsubscribe(t,!0),r.delete(t)},operationId:t}}}},async unsubscribe(t){const e=i||await c;let s=[];const n=[];t:for(const[o,i]of r.entries())for(const c of t)if(i.has(c)){n.push(o),s.push(e.unsubscribe(o,!0)),r.delete(o);continue t}return s.length&&await Promise.all(s),n},async close(){(i||await c).close()},setConnectionParams(t,e){i?(i.connectionInitPayload=t,e&&i.socket&&i.close(!0)):c.then((s=>{s.connectionInitPayload=t,e&&s.socket&&s.close(!0)})).catch(console.error)}}}; | ||
//# sourceMappingURL=gqless-subscriptions.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { gqlessError } from 'gqless'; | ||
import { GQlessError } from 'gqless'; | ||
import WebSocket from 'isomorphic-ws'; | ||
@@ -438,3 +438,3 @@ | ||
data, | ||
error: gqlessError.fromGraphQLErrors(errors) | ||
error: GQlessError.fromGraphQLErrors(errors) | ||
}); | ||
@@ -441,0 +441,0 @@ } else if (data) { |
{ | ||
"name": "@gqless/subscriptions", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"homepage": "https://gqless.com", | ||
"author": "PabloSz <pablosaez1995@gmail.com>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gqless/gqless.git" | ||
}, | ||
"author": "GQless <opensource@gqless.com>", | ||
"main": "dist/index.js", | ||
@@ -13,12 +17,5 @@ "module": "dist/gqless-subscriptions.esm.js", | ||
], | ||
"scripts": { | ||
"build": "build gqless-subscriptions", | ||
"prepare": "build gqless-subscriptions", | ||
"postpublish": "gh-release", | ||
"start": "watch gqless-buscriptions", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"isomorphic-ws": "^4.0.1", | ||
"ws": "^7.4.4" | ||
"ws": "^7.4.5" | ||
}, | ||
@@ -28,10 +25,10 @@ "devDependencies": { | ||
"build-utils": "1.0.0", | ||
"gqless": "^2.0.10", | ||
"gqless": "^2.0.13", | ||
"graphql": "^15.5.0", | ||
"test-utils": "^0.1.0", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.2.3" | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
}, | ||
"peerDependencies": { | ||
"gqless": "^2.0.10", | ||
"gqless": "^2.0.13", | ||
"graphql": "^15.5.0" | ||
@@ -43,3 +40,8 @@ }, | ||
} | ||
}, | ||
"scripts": { | ||
"build": "build gqless-subscriptions", | ||
"start": "watch gqless-buscriptions", | ||
"test": "jest" | ||
} | ||
} |
import { | ||
gqlessError, | ||
GQlessError, | ||
Selection, | ||
@@ -97,3 +97,3 @@ SubscribeEvents, | ||
data, | ||
error: gqlessError.fromGraphQLErrors(errors), | ||
error: GQlessError.fromGraphQLErrors(errors), | ||
}); | ||
@@ -100,0 +100,0 @@ } else if (data) { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
97949
0
2
1
Updatedws@^7.4.5