UNPKG

altair-static

Version:

Static package for altair graphql client

6 lines (4 loc) 18.5 kB
!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]="d2b05199-6c28-54ef-b123-712211340dbc")}catch(e){}}(); (self.webpackChunkaltair=self.webpackChunkaltair||[]).push([[684],{88419:O=>{function f(i){this.ms=(i=i||{}).min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}O.exports=f,f.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var a=Math.random(),E=Math.floor(a*this.jitter*i);i=1&Math.floor(10*a)?i+E:i-E}return 0|Math.min(i,this.max)},f.prototype.reset=function(){this.attempts=0},f.prototype.setMin=function(i){this.ms=i},f.prototype.setMax=function(i){this.max=i},f.prototype.setJitter=function(i){this.jitter=i}},45836:O=>{"use strict";var f=Object.prototype.hasOwnProperty,i="~";function a(){}function E(p,u,o){this.fn=p,this.context=u,this.once=o||!1}function R(p,u,o,l,I){if("function"!=typeof o)throw new TypeError("The listener must be a function");var g=new E(o,l||p,I),v=i?i+u:u;return p._events[v]?p._events[v].fn?p._events[v]=[p._events[v],g]:p._events[v].push(g):(p._events[v]=g,p._eventsCount++),p}function N(p,u){0==--p._eventsCount?p._events=new a:delete p._events[u]}function _(){this._events=new a,this._eventsCount=0}Object.create&&(a.prototype=Object.create(null),(new a).__proto__||(i=!1)),_.prototype.eventNames=function(){var o,l,u=[];if(0===this._eventsCount)return u;for(l in o=this._events)f.call(o,l)&&u.push(i?l.slice(1):l);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(o)):u},_.prototype.listeners=function(u){var l=this._events[i?i+u:u];if(!l)return[];if(l.fn)return[l.fn];for(var I=0,g=l.length,v=new Array(g);I<g;I++)v[I]=l[I].fn;return v},_.prototype.listenerCount=function(u){var l=this._events[i?i+u:u];return l?l.fn?1:l.length:0},_.prototype.emit=function(u,o,l,I,g,v){var w=i?i+u:u;if(!this._events[w])return!1;var b,T,d=this._events[w],M=arguments.length;if(d.fn){switch(d.once&&this.removeListener(u,d.fn,void 0,!0),M){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,o),!0;case 3:return d.fn.call(d.context,o,l),!0;case 4:return d.fn.call(d.context,o,l,I),!0;case 5:return d.fn.call(d.context,o,l,I,g),!0;case 6:return d.fn.call(d.context,o,l,I,g,v),!0}for(T=1,b=new Array(M-1);T<M;T++)b[T-1]=arguments[T];d.fn.apply(d.context,b)}else{var t,c=d.length;for(T=0;T<c;T++)switch(d[T].once&&this.removeListener(u,d[T].fn,void 0,!0),M){case 1:d[T].fn.call(d[T].context);break;case 2:d[T].fn.call(d[T].context,o);break;case 3:d[T].fn.call(d[T].context,o,l);break;case 4:d[T].fn.call(d[T].context,o,l,I);break;default:if(!b)for(t=1,b=new Array(M-1);t<M;t++)b[t-1]=arguments[t];d[T].fn.apply(d[T].context,b)}}return!0},_.prototype.on=function(u,o,l){return R(this,u,o,l,!1)},_.prototype.once=function(u,o,l){return R(this,u,o,l,!0)},_.prototype.removeListener=function(u,o,l,I){var g=i?i+u:u;if(!this._events[g])return this;if(!o)return N(this,g),this;var v=this._events[g];if(v.fn)v.fn===o&&(!I||v.once)&&(!l||v.context===l)&&N(this,g);else{for(var w=0,d=[],M=v.length;w<M;w++)(v[w].fn!==o||I&&!v[w].once||l&&v[w].context!==l)&&d.push(v[w]);d.length?this._events[g]=1===d.length?d[0]:d:N(this,g)}return this},_.prototype.removeAllListeners=function(u){var o;return u?this._events[o=i?i+u:u]&&N(this,o):(this._events=new a,this._eventsCount=0),this},_.prototype.off=_.prototype.removeListener,_.prototype.addListener=_.prototype.on,_.prefixed=i,_.EventEmitter=_,O.exports=_},11796:function(O,f,i){"use strict";var a=this&&this.__assign||function(){return a=Object.assign||function(c){for(var t,e=1,n=arguments.length;e<n;e++)for(var s in t=arguments[e])Object.prototype.hasOwnProperty.call(t,s)&&(c[s]=t[s]);return c},a.apply(this,arguments)},E=this&&this.__awaiter||function(c,t,e,n){return new(e||(e=Promise))(function(r,m){function C(y){try{h(n.next(y))}catch(A){m(A)}}function S(y){try{h(n.throw(y))}catch(A){m(A)}}function h(y){y.done?r(y.value):function s(r){return r instanceof e?r:new e(function(m){m(r)})}(y.value).then(C,S)}h((n=n.apply(c,t||[])).next())})},R=this&&this.__generator||function(c,t){var n,s,r,m,e={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return m={next:C(0),throw:C(1),return:C(2)},"function"==typeof Symbol&&(m[Symbol.iterator]=function(){return this}),m;function C(h){return function(y){return function S(h){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,s&&(r=2&h[0]?s.return:h[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,h[1])).done)return r;switch(s=0,r&&(h=[2&h[0],r.value]),h[0]){case 0:case 1:r=h;break;case 4:return e.label++,{value:h[1],done:!1};case 5:e.label++,s=h[1],h=[0];continue;case 7:h=e.ops.pop(),e.trys.pop();continue;default:if(!(r=(r=e.trys).length>0&&r[r.length-1])&&(6===h[0]||2===h[0])){e=0;continue}if(3===h[0]&&(!r||h[1]>r[0]&&h[1]<r[3])){e.label=h[1];break}if(6===h[0]&&e.label<r[1]){e.label=r[1],r=h;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(h);break}r[2]&&e.ops.pop(),e.trys.pop();continue}h=t.call(c,e)}catch(y){h=[6,y],s=0}finally{n=r=0}if(5&h[0])throw h[1];return{value:h[0]?h[1]:void 0,done:!0}}([h,y])}}},N=this&&this.__spreadArrays||function(){for(var c=0,t=0,e=arguments.length;t<e;t++)c+=arguments[t].length;var n=Array(c),s=0;for(t=0;t<e;t++)for(var r=arguments[t],m=0,C=r.length;m<C;m++,s++)n[s]=r[m];return n};Object.defineProperty(f,"__esModule",{value:!0}),f.SubscriptionClient=void 0;var _=typeof global<"u"?global:typeof window<"u"?window:{},p=_.WebSocket||_.MozWebSocket,u=i(88419),o=i(45836),l=i(38679),I=i(25181),g=i(4645),v=i(39466),w=i(34026),d=i(99019),M=i(99509),b=i(80284),T=function(){function c(t,e,n,s){var r=e||{},m=r.connectionCallback,C=void 0===m?void 0:m,S=r.connectionParams,h=void 0===S?{}:S,y=r.minTimeout,A=void 0===y?M.MIN_WS_TIMEOUT:y,P=r.timeout,U=void 0===P?M.WS_TIMEOUT:P,L=r.reconnect,j=void 0!==L&&L,k=r.reconnectionAttempts,W=void 0===k?1/0:k,G=r.lazy,D=void 0!==G&&G,Q=r.inactivityTimeout,B=void 0===Q?0:Q,x=r.wsOptionArguments,K=void 0===x?[]:x;if(this.wsImpl=n||p,!this.wsImpl)throw new Error("Unable to find native implementation, or alternative implementation for WebSocket!");this.wsProtocols=s||d.GRAPHQL_WS,this.connectionCallback=C,this.url=t,this.operations={},this.nextOperationId=0,this.minWsTimeout=A,this.wsTimeout=U,this.unsentMessagesQueue=[],this.reconnect=j,this.reconnecting=!1,this.reconnectionAttempts=W,this.lazy=!!D,this.inactivityTimeout=B,this.closedByUser=!1,this.backoff=new u({jitter:.5}),this.eventEmitter=new o.EventEmitter,this.middlewares=[],this.client=null,this.maxConnectTimeGenerator=this.createMaxConnectTimeGenerator(),this.connectionParams=this.getConnectionParams(h),this.wsOptionArguments=K,this.lazy||this.connect()}return Object.defineProperty(c.prototype,"status",{get:function(){return null===this.client?this.wsImpl.CLOSED:this.client.readyState},enumerable:!1,configurable:!0}),c.prototype.close=function(t,e){void 0===t&&(t=!0),void 0===e&&(e=!0),this.clearInactivityTimeout(),null!==this.client&&(this.closedByUser=e,t&&(this.clearCheckConnectionInterval(),this.clearMaxConnectTimeout(),this.clearTryReconnectTimeout(),this.unsubscribeAll(),this.sendMessage(void 0,b.default.GQL_CONNECTION_TERMINATE,null)),this.client.close(),this.client.onopen=null,this.client.onclose=null,this.client.onerror=null,this.client.onmessage=null,this.client=null,this.eventEmitter.emit("disconnected"),t||this.tryReconnect())},c.prototype.request=function(t){var e,m,n=this.getObserver.bind(this),s=this.executeOperation.bind(this),r=this.unsubscribe.bind(this);return this.clearInactivityTimeout(),(e={})[w.default]=function(){return this},e.subscribe=function(C,S,h){var y=n(C,S,h);return m=s(t,function(A,P){null===A&&null===P?y.complete&&y.complete():A?y.error&&y.error(A[0]):y.next&&y.next(P)}),{unsubscribe:function(){m&&(r(m),m=null)}}},e},c.prototype.on=function(t,e,n){var s=this.eventEmitter.on(t,e,n);return function(){s.off(t,e,n)}},c.prototype.onConnected=function(t,e){return this.on("connected",t,e)},c.prototype.onConnecting=function(t,e){return this.on("connecting",t,e)},c.prototype.onDisconnected=function(t,e){return this.on("disconnected",t,e)},c.prototype.onReconnected=function(t,e){return this.on("reconnected",t,e)},c.prototype.onReconnecting=function(t,e){return this.on("reconnecting",t,e)},c.prototype.onError=function(t,e){return this.on("error",t,e)},c.prototype.unsubscribeAll=function(){var t=this;Object.keys(this.operations).forEach(function(e){t.unsubscribe(e)})},c.prototype.applyMiddlewares=function(t){var e=this;return new Promise(function(n,s){var m,C,S;m=N(e.middlewares),C=e,(S=function(h){if(h)s(h);else if(m.length>0){var y=m.shift();y&&y.applyMiddleware.apply(C,[t,S])}else n(t)})()})},c.prototype.use=function(t){var e=this;return t.map(function(n){if("function"!=typeof n.applyMiddleware)throw new Error("Middleware must implement the applyMiddleware function.");e.middlewares.push(n)}),this},c.prototype.getConnectionParams=function(t){return function(){return new Promise(function(e,n){if("function"==typeof t)try{return e(t.call(null))}catch(s){return n(s)}e(t)})}},c.prototype.executeOperation=function(t,e){var n=this;null===this.client&&this.connect();var s=this.generateOperationId();return this.operations[s]={options:t,handler:e},this.applyMiddlewares(t).then(function(r){n.checkOperationOptions(r,e),n.operations[s]&&(n.operations[s]={options:r,handler:e},n.sendMessage(s,b.default.GQL_START,r))}).catch(function(r){n.unsubscribe(s),e(n.formatErrors(r))}),s},c.prototype.getObserver=function(t,e,n){return"function"==typeof t?{next:function(s){return t(s)},error:function(s){return e&&e(s)},complete:function(){return n&&n()}}:t},c.prototype.createMaxConnectTimeGenerator=function(){return new u({min:this.minWsTimeout,max:this.wsTimeout,factor:1.2})},c.prototype.clearCheckConnectionInterval=function(){this.checkConnectionIntervalId&&(clearInterval(this.checkConnectionIntervalId),this.checkConnectionIntervalId=null)},c.prototype.clearMaxConnectTimeout=function(){this.maxConnectTimeoutId&&(clearTimeout(this.maxConnectTimeoutId),this.maxConnectTimeoutId=null)},c.prototype.clearTryReconnectTimeout=function(){this.tryReconnectTimeoutId&&(clearTimeout(this.tryReconnectTimeoutId),this.tryReconnectTimeoutId=null)},c.prototype.clearInactivityTimeout=function(){this.inactivityTimeoutId&&(clearTimeout(this.inactivityTimeoutId),this.inactivityTimeoutId=null)},c.prototype.setInactivityTimeout=function(){var t=this;this.inactivityTimeout>0&&0===Object.keys(this.operations).length&&(this.inactivityTimeoutId=setTimeout(function(){0===Object.keys(t.operations).length&&t.close()},this.inactivityTimeout))},c.prototype.checkOperationOptions=function(t,e){var n=t.query,s=t.variables,r=t.operationName;if(!n)throw new Error("Must provide a query.");if(!e)throw new Error("Must provide an handler.");if(!l.default(n)&&!v.getOperationAST(n,r)||r&&!l.default(r)||s&&!I.default(s))throw new Error("Incorrect option types. query must be a string or a document,`operationName` must be a string, and `variables` must be an object.")},c.prototype.buildMessage=function(t,e,n){return{id:t,type:e,payload:n&&n.query?a(a({},n),{query:"string"==typeof n.query?n.query:g.print(n.query)}):n}},c.prototype.formatErrors=function(t){return Array.isArray(t)?t:t&&t.errors?this.formatErrors(t.errors):t&&t.message?[t]:[{name:"FormatedError",message:"Unknown error",originalError:t}]},c.prototype.sendMessage=function(t,e,n){this.sendMessageRaw(this.buildMessage(t,e,n))},c.prototype.sendMessageRaw=function(t){switch(this.status){case this.wsImpl.OPEN:var e=JSON.stringify(t);try{JSON.parse(e)}catch{this.eventEmitter.emit("error",new Error("Message must be JSON-serializable. Got: "+t))}this.client.send(e);break;case this.wsImpl.CONNECTING:this.unsentMessagesQueue.push(t);break;default:this.reconnecting||this.eventEmitter.emit("error",new Error("A message was not sent because socket is not connected, is closing or is already closed. Message was: "+JSON.stringify(t)))}},c.prototype.generateOperationId=function(){return String(++this.nextOperationId)},c.prototype.tryReconnect=function(){var t=this;if(this.reconnect&&!(this.backoff.attempts>=this.reconnectionAttempts)){this.reconnecting||(Object.keys(this.operations).forEach(function(n){t.unsentMessagesQueue.push(t.buildMessage(n,b.default.GQL_START,t.operations[n].options))}),this.reconnecting=!0),this.clearTryReconnectTimeout();var e=this.backoff.duration();this.tryReconnectTimeoutId=setTimeout(function(){t.connect()},e)}},c.prototype.flushUnsentMessagesQueue=function(){var t=this;this.unsentMessagesQueue.forEach(function(e){t.sendMessageRaw(e)}),this.unsentMessagesQueue=[]},c.prototype.checkConnection=function(){this.wasKeepAliveReceived?this.wasKeepAliveReceived=!1:this.reconnecting||this.close(!1,!0)},c.prototype.checkMaxConnectTimeout=function(){var t=this;this.clearMaxConnectTimeout(),this.maxConnectTimeoutId=setTimeout(function(){t.status!==t.wsImpl.OPEN&&(t.reconnecting=!0,t.close(!1,!0))},this.maxConnectTimeGenerator.duration())},c.prototype.connect=function(){var t,e=this;this.client=new((t=this.wsImpl).bind.apply(t,N([void 0,this.url,this.wsProtocols],this.wsOptionArguments))),this.checkMaxConnectTimeout(),this.client.onopen=function(){return E(e,void 0,void 0,function(){var n,s;return R(this,function(r){switch(r.label){case 0:if(this.status!==this.wsImpl.OPEN)return[3,4];this.clearMaxConnectTimeout(),this.closedByUser=!1,this.eventEmitter.emit(this.reconnecting?"reconnecting":"connecting"),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.connectionParams()];case 2:return n=r.sent(),this.sendMessage(void 0,b.default.GQL_CONNECTION_INIT,n),this.flushUnsentMessagesQueue(),[3,4];case 3:return s=r.sent(),this.sendMessage(void 0,b.default.GQL_CONNECTION_ERROR,s),this.flushUnsentMessagesQueue(),[3,4];case 4:return[2]}})})},this.client.onclose=function(){e.closedByUser||e.close(!1,!1)},this.client.onerror=function(n){e.eventEmitter.emit("error",n)},this.client.onmessage=function(n){e.processReceivedData(n.data)}},c.prototype.processReceivedData=function(t){var e,n;try{n=(e=JSON.parse(t)).id}catch{throw new Error("Message must be JSON-parseable. Got: "+t)}if(-1===[b.default.GQL_DATA,b.default.GQL_COMPLETE,b.default.GQL_ERROR].indexOf(e.type)||this.operations[n])switch(e.type){case b.default.GQL_CONNECTION_ERROR:this.connectionCallback&&this.connectionCallback(e.payload);break;case b.default.GQL_CONNECTION_ACK:this.eventEmitter.emit(this.reconnecting?"reconnected":"connected",e.payload),this.reconnecting=!1,this.backoff.reset(),this.maxConnectTimeGenerator.reset(),this.connectionCallback&&this.connectionCallback();break;case b.default.GQL_COMPLETE:var s=this.operations[n].handler;delete this.operations[n],s.call(this,null,null);break;case b.default.GQL_ERROR:this.operations[n].handler(this.formatErrors(e.payload),null),delete this.operations[n];break;case b.default.GQL_DATA:var r=e.payload.errors?a(a({},e.payload),{errors:this.formatErrors(e.payload.errors)}):e.payload;this.operations[n].handler(null,r);break;case b.default.GQL_CONNECTION_KEEP_ALIVE:var m=typeof this.wasKeepAliveReceived>"u";this.wasKeepAliveReceived=!0,m&&this.checkConnection(),this.checkConnectionIntervalId&&(clearInterval(this.checkConnectionIntervalId),this.checkConnection()),this.checkConnectionIntervalId=setInterval(this.checkConnection.bind(this),this.wsTimeout);break;default:throw new Error("Invalid message type!")}else this.unsubscribe(n)},c.prototype.unsubscribe=function(t){this.operations[t]&&(delete this.operations[t],this.setInactivityTimeout(),this.sendMessage(t,b.default.GQL_STOP,void 0))},c}();f.SubscriptionClient=T},99509:(O,f)=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0}),f.WS_TIMEOUT=f.MIN_WS_TIMEOUT=void 0,f.MIN_WS_TIMEOUT=1e3,f.WS_TIMEOUT=3e4},80284:(O,f)=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});var i=function(){function a(){throw new Error("Static Class")}return a.GQL_CONNECTION_INIT="connection_init",a.GQL_CONNECTION_ACK="connection_ack",a.GQL_CONNECTION_ERROR="connection_error",a.GQL_CONNECTION_KEEP_ALIVE="ka",a.GQL_CONNECTION_TERMINATE="connection_terminate",a.GQL_START="start",a.GQL_DATA="data",a.GQL_ERROR="error",a.GQL_COMPLETE="complete",a.GQL_STOP="stop",a.SUBSCRIPTION_START="subscription_start",a.SUBSCRIPTION_DATA="subscription_data",a.SUBSCRIPTION_SUCCESS="subscription_success",a.SUBSCRIPTION_FAIL="subscription_fail",a.SUBSCRIPTION_END="subscription_end",a.INIT="init",a.INIT_SUCCESS="init_success",a.INIT_FAIL="init_fail",a.KEEP_ALIVE="keepalive",a}();f.default=i},99019:(O,f)=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0}),f.GRAPHQL_SUBSCRIPTIONS=f.GRAPHQL_WS=void 0,f.GRAPHQL_WS="graphql-ws",f.GRAPHQL_SUBSCRIPTIONS="graphql-subscriptions"},25181:(O,f)=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0}),f.default=function i(a){return null!==a&&"object"==typeof a}},38679:(O,f)=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0}),f.default=function i(a){return"string"==typeof a}},34026:(O,f,i)=>{"use strict";i.r(f),i.d(f,{default:()=>N}),O=i.hmd(O);const N=function a(_){var p,u=_.Symbol;return"function"==typeof u?u.observable?p=u.observable:(p=u("observable"),u.observable=p):p="@@observable",p}(typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:O)},37684:(O,f,i)=>{"use strict";i.r(f),i.d(f,{WebsocketRequestHandler:()=>p});var a=i(35121),E=i(57586),R=i(11796),_=i(49601);class p{onConnected(o,l,I){if(l)return console.log("Subscription connection error",l),void o.error(l);console.log("Connected subscription.")}handle(o){return new E.c(l=>{if(this.client=new R.SubscriptionClient(o.url,{reconnect:!0,connectionParams:o.additionalParams,connectionCallback:(v,w)=>{this.onConnected(l,v,w)}}),!this.client)throw new Error("Could not create WS client!");const I=Date.now(),g=this.client.request({query:o.query,variables:o.variables,operationName:o.selectedOperation??void 0}).subscribe((0,_.G)(l,o.url,I));return this.cleanup=g.unsubscribe,()=>{this.destroy()}})}destroy(){var o=this;return(0,a.A)(function*(){o.cleanup?.(),o.cleanup=void 0,o.client?.unsubscribeAll(),o.client?.close(),o.client=void 0})()}}}}]); //# sourceMappingURL=684.js.map //# debugId=d2b05199-6c28-54ef-b123-712211340dbc