UNPKG

8.73 kBJavaScriptView Raw
1"use strict";
2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d42aa18c-0ad1-5c79-969f-529f33c4c81a")}catch(e){}}();
3(self.webpackChunkaltair=self.webpackChunkaltair||[]).push([[295],{57295:(pe,j,I)=>{I.r(j),I.d(j,{GraphQLWsSubscriptionProvider:()=>ae});var g=I(26642),Y=I(29954),_=I(78345);const T=Object.prototype.hasOwnProperty;function x(e){return"object"==typeof e&&null!==e}function O(e,n){return T.call(e,n)}function W(e,n){return T.call(e,n)&&x(e[n])}function w(e,n){return T.call(e,n)&&"string"==typeof e[n]}function H(e,n){return e.length<124?e:n}var p=function(e){return 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||{}),s=function(e){return 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}(s||{});function v(e){if(x(e)){if(!w(e,"type"))return!1;switch(e.type){case s.ConnectionInit:case s.ConnectionAck:case s.Ping:case s.Pong:return!O(e,"payload")||void 0===e.payload||x(e.payload);case s.Subscribe:return w(e,"id")&&W(e,"payload")&&(!O(e.payload,"operationName")||null==e.payload.operationName||"string"==typeof e.payload.operationName)&&w(e.payload,"query")&&(!O(e.payload,"variables")||null==e.payload.variables||W(e.payload,"variables"))&&(!O(e.payload,"extensions")||null==e.payload.extensions||W(e.payload,"extensions"));case s.Next:return w(e,"id")&&W(e,"payload");case s.Error:return w(e,"id")&&function ee(e){return Array.isArray(e)&&e.length>0&&e.every(n=>"message"in n)}(e.payload);case s.Complete:return w(e,"id");default:return!1}}return!1}function N(e,n){if(!v(e))throw new Error("Cannot stringify invalid message");return JSON.stringify(e,n)}function L(e){return x(e)&&"code"in e&&"reason"in e}class ae extends Y.q{createClient(){this.client=function re(e){const{url:n,connectionParams:y,lazy:A=!0,onNonLazyError:z=console.error,lazyCloseTimeout:B=0,keepAlive:F=0,disablePong:ce,connectionAckWaitTimeout:M=0,retryAttempts:J=5,retryWait:se=function(){var t=(0,g.Z)(function*(c){let o=1e3;for(let a=0;a<c;a++)o*=2;yield new Promise(a=>setTimeout(a,o+Math.floor(2700*Math.random()+300)))});return function l(c){return t.apply(this,arguments)}}(),shouldRetry:le=L,isFatalConnectionProblem:Z,on:r,webSocketImpl:D,generateID:ue=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,l=>{const c=16*Math.random()|0;return("x"==l?c:3&c|8).toString(16)})},jsonMessageReplacer:U,jsonMessageReviver:de}=e;let S;if(D){if(!function ie(e){return"function"==typeof e&&"constructor"in e&&"CLOSED"in e&&"CLOSING"in e&&"CONNECTING"in e&&"OPEN"in e}(D))throw new Error("Invalid WebSocket implementation provided");S=D}else typeof WebSocket<"u"?S=WebSocket:typeof global<"u"?S=global.WebSocket||global.MozWebSocket:typeof window<"u"&&(S=window.WebSocket||window.MozWebSocket);if(!S)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const P=S,f=(()=>{const t=(()=>{const c={};return{on:(o,a)=>(c[o]=a,()=>{delete c[o]}),emit(o){var a;"id"in o&&(null===(a=c[o.id])||void 0===a||a.call(c,o))}}})(),l={connecting:r?.connecting?[r.connecting]:[],opened:r?.opened?[r.opened]:[],connected:r?.connected?[r.connected]:[],ping:r?.ping?[r.ping]:[],pong:r?.pong?[r.pong]:[],message:r?.message?[t.emit,r.message]:[t.emit],closed:r?.closed?[r.closed]:[],error:r?.error?[r.error]:[]};return{onMessage:t.on,on(c,o){const a=l[c];return a.push(o),()=>{a.splice(a.indexOf(o),1)}},emit(c,...o){for(const a of[...l[c]])a(...o)}}})();function $(t){const l=[f.on("error",c=>{l.forEach(o=>o()),t(c)}),f.on("closed",c=>{l.forEach(o=>o()),t(c)})]}let m,h=0,C=!1,G=0,K=!1;function V(){return Q.apply(this,arguments)}function Q(){return Q=(0,g.Z)(function*(){const[t,l]=yield m??(m=new Promise((a,b)=>(0,g.Z)(function*(){if(C){if(yield se(G),!h)return m=void 0,b({code:1e3,reason:"All Subscriptions Gone"});G++}f.emit("connecting");const i=new P("function"==typeof n?yield n():n,"graphql-transport-ws");let E,R;function q(){isFinite(F)&&F>0&&(clearTimeout(R),R=setTimeout(()=>{i.readyState===P.OPEN&&(i.send(N({type:s.Ping})),f.emit("ping",!1,void 0))},F))}$(u=>{m=void 0,clearTimeout(E),clearTimeout(R),b(u),L(u)&&4499===u.code&&(i.close(4499,"Terminated"),i.onerror=null,i.onclose=null)}),i.onerror=u=>f.emit("error",u),i.onclose=u=>f.emit("closed",u),i.onopen=(0,g.Z)(function*(){try{f.emit("opened",i);const u="function"==typeof y?yield y():y;if(i.readyState!==P.OPEN)return;i.send(N(u?{type:s.ConnectionInit,payload:u}:{type:s.ConnectionInit},U)),isFinite(M)&&M>0&&(E=setTimeout(()=>{i.close(p.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},M)),q()}catch(u){f.emit("error",u),i.close(p.InternalClientError,H(u instanceof Error?u.message:new Error(u).message,"Internal client error"))}});let k=!1;i.onmessage=({data:u})=>{try{const d=function te(e,n){if(v(e))return e;if("string"!=typeof e)throw new Error("Message not parsable");const y=JSON.parse(e,n);if(!v(y))throw new Error("Invalid message");return y}(u,de);if(f.emit("message",d),"ping"===d.type||"pong"===d.type)return f.emit(d.type,!0,d.payload),void("pong"===d.type?q():ce||(i.send(N(d.payload?{type:s.Pong,payload:d.payload}:{type:s.Pong})),f.emit("pong",!1,d.payload)));if(k)return;if(d.type!==s.ConnectionAck)throw new Error(`First message cannot be of type ${d.type}`);clearTimeout(E),k=!0,f.emit("connected",i,d.payload),C=!1,G=0,a([i,new Promise((be,fe)=>$(fe))])}catch(d){i.onmessage=null,f.emit("error",d),i.close(p.BadResponse,H(d instanceof Error?d.message:new Error(d).message,"Bad response"))}}})()));t.readyState===P.CLOSING&&(yield l);let c=()=>{};const o=new Promise(a=>c=a);return[t,c,Promise.race([o.then(()=>{if(!h){const a=()=>t.close(1e3,"Normal Closure");isFinite(B)&&B>0?setTimeout(()=>{!h&&t.readyState===P.OPEN&&a()},B):a()}}),l])]}),Q.apply(this,arguments)}function X(t){if(L(t)&&(function oe(e){return![1e3,1001,1006,1005,1012,1013,1013].includes(e)&&e>=1e3&&e<=1999}(t.code)||[p.InternalServerError,p.InternalClientError,p.BadRequest,p.BadResponse,p.Unauthorized,p.SubprotocolNotAcceptable,p.SubscriberAlreadyExists,p.TooManyInitialisationRequests].includes(t.code)))throw t;if(K)return!1;if(L(t)&&1e3===t.code)return h>0;if(!J||G>=J||!le(t)||Z?.(t))throw t;return C=!0}return A||(0,g.Z)(function*(){for(h++;;)try{const[,,t]=yield V();yield t}catch(t){try{if(!X(t))return}catch(l){return z?.(l)}}})(),{on:f.on,subscribe(t,l){const c=ue();let o=!1,a=!1,b=()=>{h--,o=!0};return(0,g.Z)(function*(){for(h++;;)try{const[i,E,R]=yield V();if(o)return E();const q=f.onMessage(c,k=>{switch(k.type){case s.Next:return void l.next(k.payload);case s.Error:return a=!0,o=!0,l.error(k.payload),void b();case s.Complete:return o=!0,void b()}});return i.send(N({id:c,type:s.Subscribe,payload:t},U)),b=()=>{!o&&i.readyState===P.OPEN&&i.send(N({id:c,type:s.Complete},U)),h--,o=!0,E()},void(yield R.finally(q))}catch(i){if(!X(i))return}})().then(()=>{a||l.complete()}).catch(i=>{l.error(i)}),()=>{o||b()}},dispose:()=>(0,g.Z)(function*(){if(K=!0,m){const[t]=yield m;t.close(1e3,"Normal Closure")}})(),terminate(){m&&f.emit("closed",{code:4499,reason:"Terminated",wasClean:!1})}}}({url:this.subscriptionUrl,connectionParams:this.connectionParams,lazy:!1,onNonLazyError:n=>{this.extraOptions?.onConnected?.(n,void 0)},on:{connected:()=>{this.extraOptions?.onConnected?.(void 0,void 0)},error:n=>{this.extraOptions?.onConnected?.(n,void 0)}}})}execute(n){if(this.createClient(),!this.client)throw new Error("Could not create subscription client!");return new _.y(y=>{this.cleanup=this.client.subscribe({query:n.query,variables:n.variables,operationName:n.operationName},{next:(...A)=>y.next(...A),error:(...A)=>y.error(...A),complete:()=>y.complete()})})}close(){var n=this;return(0,g.Z)(function*(){try{n.cleanup?.(),n.cleanup=void 0,yield n.client?.dispose(),n.client=void 0}catch(y){console.error(y)}})()}}}}]);
4//# sourceMappingURL=295.js.map
5//# debugId=d42aa18c-0ad1-5c79-969f-529f33c4c81a