@contello/sdk-client 8.14.0 → 8.15.0-next.1752677404
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -3
- package/dist/index.js +367 -343
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(N,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(N=typeof globalThis<"u"?globalThis:N||self,h(N.ContelloSdkClient={}))})(this,function(N){"use strict";function h(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function O(e){return h(e)==="object"}function ye(e){return Array.isArray(e)&&e.length>0&&e.every(t=>"message"in t)}function K(e,t){return e.length<124?e:t}const he="graphql-transport-ws";var P=(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))(P||{}),v=(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))(v||{});function X(e){if(!O(e))throw new Error(`Message is expected to be an object, but got ${h(e)}`);if(!e.type)throw new Error("Message is missing the 'type' property");if(typeof e.type!="string")throw new Error(`Message is expects the 'type' property to be a string, but got ${h(e.type)}`);switch(e.type){case"connection_init":case"connection_ack":case"ping":case"pong":{if(e.payload!=null&&!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(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${h(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 ${h(e.payload)}`);if(typeof e.payload.query!="string")throw new Error(`"${e.type}" message payload expects the 'query' property to be a string, but got ${h(e.payload.query)}`);if(e.payload.variables!=null&&!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 ${h(e.payload.variables)}`);if(e.payload.operationName!=null&&h(e.payload.operationName)!=="string")throw new Error(`"${e.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${h(e.payload.operationName)}`);if(e.payload.extensions!=null&&!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 ${h(e.payload.extensions)}`);break}case"next":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${h(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 ${h(e.payload)}`);break}case"error":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${h(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!ye(e.payload))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(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${h(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}"`)}return e}function be(e,t){return X(typeof e=="string"?JSON.parse(e,t):e)}function W(e,t){return X(e),JSON.stringify(e,t)}function me(e){const{url:t,connectionParams:r,lazy:n=!0,onNonLazyError:c=console.error,lazyCloseTimeout:i=0,keepAlive:o=0,disablePong:b,connectionAckWaitTimeout:y=0,retryAttempts:T=5,retryWait:g=async function(f){const s=Math.pow(2,f);await new Promise(u=>setTimeout(u,s*1e3+Math.floor(Math.random()*2700+300)))},shouldRetry:w=L,on:l,webSocketImpl:A,generateID:V=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,f=>{const s=Math.random()*16|0;return(f=="x"?s:s&3|8).toString(16)})},jsonMessageReplacer:E,jsonMessageReviver:We}=e;let R;if(A){if(!we(A))throw new Error("Invalid WebSocket implementation provided");R=A}else typeof WebSocket<"u"?R=WebSocket:typeof global<"u"?R=global.WebSocket||global.MozWebSocket:typeof window<"u"&&(R=window.WebSocket||window.MozWebSocket);if(!R)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const j=R,x=(()=>{const a=(()=>{const s={};return{on(u,d){return s[u]=d,()=>{delete s[u]}},emit(u){"id"in u&&s[u.id]?.(u)}}})(),f={connecting:l?.connecting?[l.connecting]:[],opened:l?.opened?[l.opened]:[],connected:l?.connected?[l.connected]:[],ping:l?.ping?[l.ping]:[],pong:l?.pong?[l.pong]:[],message:l?.message?[a.emit,l.message]:[a.emit],closed:l?.closed?[l.closed]:[],error:l?.error?[l.error]:[]};return{onMessage:a.on,on(s,u){const d=f[s];return d.push(u),()=>{d.splice(d.indexOf(u),1)}},emit(s,...u){for(const d of[...f[s]])d(...u)}}})();function ae(a){const f=[x.on("error",s=>{f.forEach(u=>u()),a(s)}),x.on("closed",s=>{f.forEach(u=>u()),a(s)})]}let $,I=0,ue,z=!1,B=0,pe=!1;async function le(){clearTimeout(ue);const[a,f]=await($??($=new Promise((d,k)=>(async()=>{if(z){if(await g(B),!I)return $=void 0,k({code:1e3,reason:"All Subscriptions Gone"});B++}x.emit("connecting",z);const p=new j(typeof t=="function"?await t():t,he);let q,C;function U(){isFinite(o)&&o>0&&(clearTimeout(C),C=setTimeout(()=>{p.readyState===j.OPEN&&(p.send(W({type:v.Ping})),x.emit("ping",!1,void 0))},o))}ae(S=>{$=void 0,clearTimeout(q),clearTimeout(C),k(S),S instanceof Z&&(p.close(4499,"Terminated"),p.onerror=null,p.onclose=null)}),p.onerror=S=>x.emit("error",S),p.onclose=S=>x.emit("closed",S),p.onopen=async()=>{try{x.emit("opened",p);const S=typeof r=="function"?await r():r;if(p.readyState!==j.OPEN)return;p.send(W(S?{type:v.ConnectionInit,payload:S}:{type:v.ConnectionInit},E)),isFinite(y)&&y>0&&(q=setTimeout(()=>{p.close(P.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},y)),U()}catch(S){x.emit("error",S),p.close(P.InternalClientError,K(S instanceof Error?S.message:String(S),"Internal client error"))}};let M=!1;p.onmessage=({data:S})=>{try{const m=be(S,We);if(x.emit("message",m),m.type==="ping"||m.type==="pong"){x.emit(m.type,!0,m.payload),m.type==="pong"?U():b||(p.send(W(m.payload?{type:v.Pong,payload:m.payload}:{type:v.Pong})),x.emit("pong",!1,m.payload));return}if(M)return;if(m.type!==v.ConnectionAck)throw new Error(`First message cannot be of type ${m.type}`);clearTimeout(q),M=!0,x.emit("connected",p,m.payload,z),z=!1,B=0,d([p,new Promise((Ce,ze)=>ae(ze))])}catch(m){p.onmessage=null,x.emit("error",m),p.close(P.BadResponse,K(m instanceof Error?m.message:String(m),"Bad response"))}}})())));a.readyState===j.CLOSING&&await f;let s=()=>{};const u=new Promise(d=>s=d);return[a,s,Promise.race([u.then(()=>{if(!I){const d=()=>a.close(1e3,"Normal Closure");isFinite(i)&&i>0?ue=setTimeout(()=>{a.readyState===j.OPEN&&d()},i):d()}}),f])]}function fe(a){if(L(a)&&(ge(a.code)||[P.InternalServerError,P.InternalClientError,P.BadRequest,P.BadResponse,P.Unauthorized,P.SubprotocolNotAcceptable,P.SubscriberAlreadyExists,P.TooManyInitialisationRequests].includes(a.code)))throw a;if(pe)return!1;if(L(a)&&a.code===1e3)return I>0;if(!T||B>=T||!w(a))throw a;return z=!0}n||(async()=>{for(I++;;)try{const[,,a]=await le();await a}catch(a){try{if(!fe(a))return}catch(f){return c?.(f)}}})();function de(a,f){const s=V(a);let u=!1,d=!1,k=()=>{I--,u=!0};return(async()=>{for(I++;;)try{const[p,q,C]=await le();if(u)return q();const U=x.onMessage(s,M=>{switch(M.type){case v.Next:{f.next(M.payload);return}case v.Error:{d=!0,u=!0,f.error(M.payload),k();return}case v.Complete:{u=!0,k();return}}});p.send(W({id:s,type:v.Subscribe,payload:a},E)),k=()=>{!u&&p.readyState===j.OPEN&&p.send(W({id:s,type:v.Complete},E)),I--,u=!0,q()},await C.finally(U);return}catch(p){if(!fe(p))return}})().then(()=>{d||f.complete()}).catch(p=>{f.error(p)}),()=>{u||k()}}return{on:x.on,subscribe:de,iterate(a){const f=[],s={done:!1,error:null,resolve:()=>{}},u=de(a,{next(k){f.push(k),s.resolve()},error(k){s.done=!0,s.error=k,s.resolve()},complete(){s.done=!0,s.resolve()}}),d=async function*(){for(;;){for(f.length||await new Promise(p=>s.resolve=p);f.length;)yield f.shift();if(s.error)throw s.error;if(s.done)return}}();return d.throw=async k=>(s.done||(s.done=!0,s.error=k,s.resolve()),{done:!0,value:void 0}),d.return=async()=>(u(),{done:!0,value:void 0}),d},async dispose(){if(pe=!0,$){const[a]=await $;a.close(1e3,"Normal Closure")}},terminate(){$&&x.emit("closed",new Z)}}}class Z extends Error{name="TerminatedCloseEvent";message="4499: Terminated";code=4499;reason="Terminated";wasClean=!1}function L(e){return O(e)&&"code"in e&&"reason"in e}function ge(e){return[1e3,1001,1006,1005,1012,1013,1014].includes(e)?!1:e>=1e3&&e<=1999}function we(e){return typeof e=="function"&&"constructor"in e&&"CLOSED"in e&&"CLOSING"in e&&"CONNECTING"in e&&"OPEN"in e}class xe{constructor(t,r){this.createClient=t,this.poolSize=r}clients=[];currentIndex=0;connect(){for(let t=0;t<this.poolSize;t++)this.clients.push(this.createClient(`${t+1}`))}get(){if(this.clients.length===0)throw new Error("Connection pool is empty. Please call connect() first.");const t=this.clients[this.currentIndex];if(this.currentIndex=(this.currentIndex+1)%this.poolSize,!t)throw new Error("No available WebSocket client");return t}disconnect(){this.clients.forEach(t=>t.dispose()),this.clients=[]}}var G=function(e,t){return G=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var c in n)Object.prototype.hasOwnProperty.call(n,c)&&(r[c]=n[c])},G(e,t)};function ee(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");G(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function te(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function D(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),c,i=[],o;try{for(;(t===void 0||t-- >0)&&!(c=n.next()).done;)i.push(c.value)}catch(b){o={error:b}}finally{try{c&&!c.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function J(e,t,r){if(r||arguments.length===2)for(var n=0,c=t.length,i;n<c;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function _(e){return typeof e=="function"}function Se(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var Q=Se(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
|
|
2
|
-
`+r.map(function(n,
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=r}});function
|
|
1
|
+
(function(N,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(N=typeof globalThis<"u"?globalThis:N||self,m(N.ContelloSdkClient={}))})(this,function(N){"use strict";function m(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function $(e){return m(e)==="object"}function he(e){return Array.isArray(e)&&e.length>0&&e.every(t=>"message"in t)}function K(e,t){return e.length<124?e:t}const be="graphql-transport-ws";var T=(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))(T||{}),O=(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))(O||{});function X(e){if(!$(e))throw new Error(`Message is expected to be an object, but got ${m(e)}`);if(!e.type)throw new Error("Message is missing the 'type' property");if(typeof e.type!="string")throw new Error(`Message is expects the 'type' property to be a string, but got ${m(e.type)}`);switch(e.type){case"connection_init":case"connection_ack":case"ping":case"pong":{if(e.payload!=null&&!$(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(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!$(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${m(e.payload)}`);if(typeof e.payload.query!="string")throw new Error(`"${e.type}" message payload expects the 'query' property to be a string, but got ${m(e.payload.query)}`);if(e.payload.variables!=null&&!$(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 ${m(e.payload.variables)}`);if(e.payload.operationName!=null&&m(e.payload.operationName)!=="string")throw new Error(`"${e.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${m(e.payload.operationName)}`);if(e.payload.extensions!=null&&!$(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 ${m(e.payload.extensions)}`);break}case"next":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!$(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${m(e.payload)}`);break}case"error":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!he(e.payload))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(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(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}"`)}return e}function me(e,t){return X(typeof e=="string"?JSON.parse(e,t):e)}function z(e,t){return X(e),JSON.stringify(e,t)}function ge(e){const{url:t,connectionParams:r,lazy:n=!0,onNonLazyError:s=console.error,lazyCloseTimeout:i=0,keepAlive:o=0,disablePong:h,connectionAckWaitTimeout:b=0,retryAttempts:A=5,retryWait:E=async function(f){const c=Math.pow(2,f);await new Promise(u=>setTimeout(u,c*1e3+Math.floor(Math.random()*2700+300)))},shouldRetry:S=D,on:l,webSocketImpl:d,generateID:v=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,f=>{const c=Math.random()*16|0;return(f=="x"?c:c&3|8).toString(16)})},jsonMessageReplacer:g,jsonMessageReviver:Ce}=e;let q;if(d){if(!Ee(d))throw new Error("Invalid WebSocket implementation provided");q=d}else typeof WebSocket<"u"?q=WebSocket:typeof global<"u"?q=global.WebSocket||global.MozWebSocket:typeof window<"u"&&(q=window.WebSocket||window.MozWebSocket);if(!q)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const M=q,x=(()=>{const a=(()=>{const c={};return{on(u,y){return c[u]=y,()=>{delete c[u]}},emit(u){"id"in u&&c[u.id]?.(u)}}})(),f={connecting:l?.connecting?[l.connecting]:[],opened:l?.opened?[l.opened]:[],connected:l?.connected?[l.connected]:[],ping:l?.ping?[l.ping]:[],pong:l?.pong?[l.pong]:[],message:l?.message?[a.emit,l.message]:[a.emit],closed:l?.closed?[l.closed]:[],error:l?.error?[l.error]:[]};return{onMessage:a.on,on(c,u){const y=f[c];return y.push(u),()=>{y.splice(y.indexOf(u),1)}},emit(c,...u){for(const y of[...f[c]])y(...u)}}})();function ue(a){const f=[x.on("error",c=>{f.forEach(u=>u()),a(c)}),x.on("closed",c=>{f.forEach(u=>u()),a(c)})]}let I,R=0,pe,C=!1,L=0,le=!1;async function fe(){clearTimeout(pe);const[a,f]=await(I??(I=new Promise((y,P)=>(async()=>{if(C){if(await E(L),!R)return I=void 0,P({code:1e3,reason:"All Subscriptions Gone"});L++}x.emit("connecting",C);const p=new M(typeof t=="function"?await t():t,be);let j,F;function G(){isFinite(o)&&o>0&&(clearTimeout(F),F=setTimeout(()=>{p.readyState===M.OPEN&&(p.send(z({type:O.Ping})),x.emit("ping",!1,void 0))},o))}ue(k=>{I=void 0,clearTimeout(j),clearTimeout(F),P(k),k instanceof Z&&(p.close(4499,"Terminated"),p.onerror=null,p.onclose=null)}),p.onerror=k=>x.emit("error",k),p.onclose=k=>x.emit("closed",k),p.onopen=async()=>{try{x.emit("opened",p);const k=typeof r=="function"?await r():r;if(p.readyState!==M.OPEN)return;p.send(z(k?{type:O.ConnectionInit,payload:k}:{type:O.ConnectionInit},g)),isFinite(b)&&b>0&&(j=setTimeout(()=>{p.close(T.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},b)),G()}catch(k){x.emit("error",k),p.close(T.InternalClientError,K(k instanceof Error?k.message:String(k),"Internal client error"))}};let W=!1;p.onmessage=({data:k})=>{try{const w=me(k,Ce);if(x.emit("message",w),w.type==="ping"||w.type==="pong"){x.emit(w.type,!0,w.payload),w.type==="pong"?G():h||(p.send(z(w.payload?{type:O.Pong,payload:w.payload}:{type:O.Pong})),x.emit("pong",!1,w.payload));return}if(W)return;if(w.type!==O.ConnectionAck)throw new Error(`First message cannot be of type ${w.type}`);clearTimeout(j),W=!0,x.emit("connected",p,w.payload,C),C=!1,L=0,y([p,new Promise((Be,Fe)=>ue(Fe))])}catch(w){p.onmessage=null,x.emit("error",w),p.close(T.BadResponse,K(w instanceof Error?w.message:String(w),"Bad response"))}}})())));a.readyState===M.CLOSING&&await f;let c=()=>{};const u=new Promise(y=>c=y);return[a,c,Promise.race([u.then(()=>{if(!R){const y=()=>a.close(1e3,"Normal Closure");isFinite(i)&&i>0?pe=setTimeout(()=>{a.readyState===M.OPEN&&y()},i):y()}}),f])]}function de(a){if(D(a)&&(we(a.code)||[T.InternalServerError,T.InternalClientError,T.BadRequest,T.BadResponse,T.Unauthorized,T.SubprotocolNotAcceptable,T.SubscriberAlreadyExists,T.TooManyInitialisationRequests].includes(a.code)))throw a;if(le)return!1;if(D(a)&&a.code===1e3)return R>0;if(!A||L>=A||!S(a))throw a;return C=!0}n||(async()=>{for(R++;;)try{const[,,a]=await fe();await a}catch(a){try{if(!de(a))return}catch(f){return s?.(f)}}})();function ye(a,f){const c=v(a);let u=!1,y=!1,P=()=>{R--,u=!0};return(async()=>{for(R++;;)try{const[p,j,F]=await fe();if(u)return j();const G=x.onMessage(c,W=>{switch(W.type){case O.Next:{f.next(W.payload);return}case O.Error:{y=!0,u=!0,f.error(W.payload),P();return}case O.Complete:{u=!0,P();return}}});p.send(z({id:c,type:O.Subscribe,payload:a},g)),P=()=>{!u&&p.readyState===M.OPEN&&p.send(z({id:c,type:O.Complete},g)),R--,u=!0,j()},await F.finally(G);return}catch(p){if(!de(p))return}})().then(()=>{y||f.complete()}).catch(p=>{f.error(p)}),()=>{u||P()}}return{on:x.on,subscribe:ye,iterate(a){const f=[],c={done:!1,error:null,resolve:()=>{}},u=ye(a,{next(P){f.push(P),c.resolve()},error(P){c.done=!0,c.error=P,c.resolve()},complete(){c.done=!0,c.resolve()}}),y=async function*(){for(;;){for(f.length||await new Promise(p=>c.resolve=p);f.length;)yield f.shift();if(c.error)throw c.error;if(c.done)return}}();return y.throw=async P=>(c.done||(c.done=!0,c.error=P,c.resolve()),{done:!0,value:void 0}),y.return=async()=>(u(),{done:!0,value:void 0}),y},async dispose(){if(le=!0,I){const[a]=await I;a.close(1e3,"Normal Closure")}},terminate(){I&&x.emit("closed",new Z)}}}class Z extends Error{name="TerminatedCloseEvent";message="4499: Terminated";code=4499;reason="Terminated";wasClean=!1}function D(e){return $(e)&&"code"in e&&"reason"in e}function we(e){return[1e3,1001,1006,1005,1012,1013,1014].includes(e)?!1:e>=1e3&&e<=1999}function Ee(e){return typeof e=="function"&&"constructor"in e&&"CLOSED"in e&&"CLOSING"in e&&"CONNECTING"in e&&"OPEN"in e}var J=function(e,t){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[s]=n[s])},J(e,t)};function ee(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");J(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function te(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Q(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=n.next()).done;)i.push(s.value)}catch(h){o={error:h}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function V(e,t,r){if(r||arguments.length===2)for(var n=0,s=t.length,i;n<s;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function _(e){return typeof e=="function"}function re(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var Y=re(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
|
|
2
|
+
`+r.map(function(n,s){return s+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=r}});function ne(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var H=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var h=te(o),b=h.next();!b.done;b=h.next()){var A=b.value;A.remove(this)}}catch(g){t={error:g}}finally{try{b&&!b.done&&(r=h.return)&&r.call(h)}finally{if(t)throw t.error}}else o.remove(this);var E=this.initialTeardown;if(_(E))try{E()}catch(g){i=g instanceof Y?g.errors:[g]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var l=te(S),d=l.next();!d.done;d=l.next()){var v=d.value;try{ie(v)}catch(g){i=i??[],g instanceof Y?i=V(V([],Q(i)),Q(g.errors)):i.push(g)}}}catch(g){n={error:g}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(n)throw n.error}}}if(i)throw new Y(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ie(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&ne(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&ne(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();H.EMPTY;function oe(e){return e instanceof H||e&&"closed"in e&&_(e.remove)&&_(e.add)&&_(e.unsubscribe)}function ie(e){_(e)?e():e.unsubscribe()}var Se={Promise:void 0},xe={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];return setTimeout.apply(void 0,V([e,t],Q(r)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ke(e){xe.setTimeout(function(){throw e})}function se(){}function Pe(e){e()}var ce=function(e){ee(t,e);function t(r){var n=e.call(this)||this;return n.isStopped=!1,r?(n.destination=r,oe(r)&&r.add(n)):n.destination=Oe,n}return t.create=function(r,n,s){return new B(r,n,s)},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(H),ve=function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var r=this.partialObserver;if(r.next)try{r.next(t)}catch(n){U(n)}},e.prototype.error=function(t){var r=this.partialObserver;if(r.error)try{r.error(t)}catch(n){U(n)}else U(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(r){U(r)}},e}(),B=function(e){ee(t,e);function t(r,n,s){var i=e.call(this)||this,o;return _(r)||!r?o={next:r??void 0,error:n??void 0,complete:s??void 0}:o=r,i.destination=new ve(o),i}return t}(ce);function U(e){ke(e)}function Te(e){throw e}var Oe={closed:!0,next:se,error:Te,complete:se},_e=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ae(e){return e}function $e(e){return e.length===0?Ae:e.length===1?e[0]:function(r){return e.reduce(function(n,s){return s(n)},r)}}var Ie=function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(t,r,n){var s=this,i=Ne(t)?t:new B(t,r,n);return Pe(function(){var o=s,h=o.operator,b=o.source;i.add(h?h.call(i,b):b?s._subscribe(i):s._trySubscribe(i))}),i},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(r){t.error(r)}},e.prototype.forEach=function(t,r){var n=this;return r=ae(r),new r(function(s,i){var o=new B({next:function(h){try{t(h)}catch(b){i(b),o.unsubscribe()}},error:i,complete:s});n.subscribe(o)})},e.prototype._subscribe=function(t){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(t)},e.prototype[_e]=function(){return this},e.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return $e(t)(this)},e.prototype.toPromise=function(t){var r=this;return t=ae(t),new t(function(n,s){var i;r.subscribe(function(o){return i=o},function(o){return s(o)},function(){return n(i)})})},e.create=function(t){return new e(t)},e}();function ae(e){var t;return(t=e??Se.Promise)!==null&&t!==void 0?t:Promise}function Re(e){return e&&_(e.next)&&_(e.error)&&_(e.complete)}function Ne(e){return e&&e instanceof ce||Re(e)&&oe(e)}var qe=re(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Me(e,t){return new Promise(function(r,n){var s=new B({next:function(i){r(i),s.unsubscribe()},error:n,complete:function(){n(new qe)}});e.subscribe(s)})}class je{constructor(t,r){this.createClient=t,this.poolSize=r}clients=[];currentIndex=0;connect(){for(let t=0;t<this.poolSize;t++)this.clients.push(this.createClient(`${t+1}`))}get(){if(this.clients.length===0)throw new Error("Connection pool is empty. Please call connect() first.");const t=this.clients[this.currentIndex];if(this.currentIndex=(this.currentIndex+1)%this.poolSize,!t)throw new Error("No available WebSocket client");return t}disconnect(){this.clients.forEach(t=>t.dispose()),this.clients=[]}}const We=(e,t,r)=>r((n,s,i)=>{i&&console.warn("options are not supported yet");const o=n.loc?.source.body;if(!o)throw new Error("No query provided");if(s&&typeof s!="object")throw new Error("Variables must be an object");const h=n.definitions.find(d=>d.kind==="OperationDefinition");if(!h)throw new Error("No operation definition found");const b=h.operation,A=()=>{const d=e();return new Ie(v=>d.subscribe({query:o,variables:s},v))},E={kind:b,operationName:h.name?.value??"",query:o,variables:s||{}},S=(d,v)=>{if(v>=d.length)return A();const g=d[v];return g?.onRequest?g.onRequest(E,()=>S(d,v+1)):S(d,v+1)},l=S(t,0);return b!=="subscription"?Me(l):l});class ze{_pool;_sdk;constructor(t,r){const{url:n,project:s,token:i,client:o,pooling:h}=r,b=`${n}/graphql/projects/${s}`.replace(/^http/i,"ws");this._pool=new je(A=>{const E=Object.freeze({connectionId:A,websocketUrl:b});return ge({url:b,connectionParams:{authorization:`Bearer ${i}`},lazy:!1,keepAlive:3e4,retryAttempts:o?.retryAttempts??3,shouldRetry:()=>!0,jsonMessageReplacer:(S,l)=>{if(!S){let d=l;for(const v of r.middlewares??[])v.onOutgoingMessage&&(d=v.onOutgoingMessage(d));return d}return l},...o?.onError?{onNonLazyError:S=>o.onError(E,S)}:{},on:{...o?.onError?{error:S=>o.onError(E,S)}:{},...o?.onConnected?{connected:()=>o.onConnected(E)}:{},...o?.onClosed?{closed:()=>o.onClosed(E)}:{},...o?.onConnecting?{connecting:()=>o.onConnecting(E)}:{},...o?.onOpened?{opened:()=>o.onOpened(E)}:{},...o?.onMessage?{message:S=>o.onMessage(E,S)}:{},...o?.onPing?{ping:()=>o.onPing(E)}:{},...o?.onPong?{pong:()=>o.onPong(E)}:{}}})},h?.enabled===!1?1:h?.size??5),this._sdk={sdk:We(()=>this._pool.get(),r.middlewares??[],t)}}get sdk(){return this._sdk.sdk}async connect(){this._pool.connect()}async disconnect(){this._pool.disconnect()}}N.ContelloSdkClient=ze,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED