UNPKG

altair-static

Version:

Static package for altair graphql client

7 lines (4 loc) 18.9 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="67dc43d1-ff9d-5ff2-8961-640bb4d5f10c")}catch(e){}}(); import{a as q}from"./chunk-ANLTCLUB.js";import{A as ye,w as de,x as ve,z as me}from"./chunk-ZYOLZTH5.js";import{c as U}from"./chunk-472WPQLO.js";import{e as Q,f as m,g as he,h as pe,i as E,j}from"./chunk-B7YGBANW.js";var B=m((Ue,W)=>{"use strict";W.exports=b;function b(n){n=n||{},this.ms=n.min||100,this.max=n.max||1e4,this.factor=n.factor||2,this.jitter=n.jitter>0&&n.jitter<=1?n.jitter:0,this.attempts=0}b.prototype.duration=function(){var n=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*n);n=(Math.floor(e*10)&1)==0?n-t:n+t}return Math.min(n,this.max)|0};b.prototype.reset=function(){this.attempts=0};b.prototype.setMin=function(n){this.ms=n};b.prototype.setMax=function(n){this.max=n};b.prototype.setJitter=function(n){this.jitter=n}});var K=m((qe,S)=>{"use strict";var _e=Object.prototype.hasOwnProperty,p="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(p=!1));function be(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function D(n,e,t,i,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var r=new be(t,i||n,o),s=p?p+e:e;return n._events[s]?n._events[s].fn?n._events[s]=[n._events[s],r]:n._events[s].push(r):(n._events[s]=r,n._eventsCount++),n}function C(n,e){--n._eventsCount===0?n._events=new O:delete n._events[e]}function h(){this._events=new O,this._eventsCount=0}h.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)_e.call(t,i)&&e.push(p?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};h.prototype.listeners=function(e){var t=p?p+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var o=0,r=i.length,s=new Array(r);o<r;o++)s[o]=i[o].fn;return s};h.prototype.listenerCount=function(e){var t=p?p+e:e,i=this._events[t];return i?i.fn?1:i.length:0};h.prototype.emit=function(e,t,i,o,r,s){var f=p?p+e:e;if(!this._events[f])return!1;var a=this._events[f],c=arguments.length,u,l;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void 0,!0),c){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,t),!0;case 3:return a.fn.call(a.context,t,i),!0;case 4:return a.fn.call(a.context,t,i,o),!0;case 5:return a.fn.call(a.context,t,i,o,r),!0;case 6:return a.fn.call(a.context,t,i,o,r,s),!0}for(l=1,u=new Array(c-1);l<c;l++)u[l-1]=arguments[l];a.fn.apply(a.context,u)}else{var y=a.length,_;for(l=0;l<y;l++)switch(a[l].once&&this.removeListener(e,a[l].fn,void 0,!0),c){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,t);break;case 3:a[l].fn.call(a[l].context,t,i);break;case 4:a[l].fn.call(a[l].context,t,i,o);break;default:if(!u)for(_=1,u=new Array(c-1);_<c;_++)u[_-1]=arguments[_];a[l].fn.apply(a[l].context,u)}}return!0};h.prototype.on=function(e,t,i){return D(this,e,t,i,!1)};h.prototype.once=function(e,t,i){return D(this,e,t,i,!0)};h.prototype.removeListener=function(e,t,i,o){var r=p?p+e:e;if(!this._events[r])return this;if(!t)return C(this,r),this;var s=this._events[r];if(s.fn)s.fn===t&&(!o||s.once)&&(!i||s.context===i)&&C(this,r);else{for(var f=0,a=[],c=s.length;f<c;f++)(s[f].fn!==t||o&&!s[f].once||i&&s[f].context!==i)&&a.push(s[f]);a.length?this._events[r]=a.length===1?a[0]:a:C(this,r)}return this};h.prototype.removeAllListeners=function(e){var t;return e?(t=p?p+e:e,this._events[t]&&C(this,t)):(this._events=new O,this._eventsCount=0),this};h.prototype.off=h.prototype.removeListener;h.prototype.addListener=h.prototype.on;h.prefixed=p;h.EventEmitter=h;typeof S<"u"&&(S.exports=h)});var J=m(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});function Te(n){return typeof n=="string"}M.default=Te});var H=m(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});function ge(n){return n!==null&&typeof n=="object"}N.default=ge});function R(n){var e,t=n.Symbol;return typeof t=="function"?t.observable?e=t.observable:(e=t("observable"),t.observable=e):e="@@observable",e}var z=Q(()=>{"use strict"});var V={};he(V,{default:()=>we});var T,Ie,we,F=Q(()=>{"use strict";z();typeof self<"u"?T=self:typeof window<"u"?T=window:typeof global<"u"?T=global:typeof module<"u"?T=module:T=Function("return this")();Ie=R(T),we=Ie});var X=m(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.GRAPHQL_SUBSCRIPTIONS=g.GRAPHQL_WS=void 0;var Oe="graphql-ws";g.GRAPHQL_WS=Oe;var Ce="graphql-subscriptions";g.GRAPHQL_SUBSCRIPTIONS=Ce});var Y=m(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.WS_TIMEOUT=I.MIN_WS_TIMEOUT=void 0;var Ee=1e3;I.MIN_WS_TIMEOUT=Ee;var Se=3e4;I.WS_TIMEOUT=Se});var Z=m(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});var Me=(function(){function n(){throw new Error("Static Class")}return n.GQL_CONNECTION_INIT="connection_init",n.GQL_CONNECTION_ACK="connection_ack",n.GQL_CONNECTION_ERROR="connection_error",n.GQL_CONNECTION_KEEP_ALIVE="ka",n.GQL_CONNECTION_TERMINATE="connection_terminate",n.GQL_START="start",n.GQL_DATA="data",n.GQL_ERROR="error",n.GQL_COMPLETE="complete",n.GQL_STOP="stop",n.SUBSCRIPTION_START="subscription_start",n.SUBSCRIPTION_DATA="subscription_data",n.SUBSCRIPTION_SUCCESS="subscription_success",n.SUBSCRIPTION_FAIL="subscription_fail",n.SUBSCRIPTION_END="subscription_end",n.INIT="init",n.INIT_SUCCESS="init_success",n.INIT_FAIL="init_fail",n.KEEP_ALIVE="keepalive",n})();k.default=Me});var re=m(v=>{"use strict";var w=v&&v.__assign||function(){return w=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n},w.apply(this,arguments)},Ne=v&&v.__awaiter||function(n,e,t,i){function o(r){return r instanceof t?r:new t(function(s){s(r)})}return new(t||(t=Promise))(function(r,s){function f(u){try{c(i.next(u))}catch(l){s(l)}}function a(u){try{c(i.throw(u))}catch(l){s(l)}}function c(u){u.done?r(u.value):o(u.value).then(f,a)}c((i=i.apply(n,e||[])).next())})},Re=v&&v.__generator||function(n,e){var t={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,o,r,s;return s={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function f(c){return function(u){return a([c,u])}}function a(c){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,o&&(r=c[0]&2?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,o=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(r=t.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){t.label=c[1];break}if(c[0]===6&&t.label<r[1]){t.label=r[1],r=c;break}if(r&&t.label<r[2]){t.label=r[2],t.ops.push(c);break}r[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(u){c=[6,u],o=0}finally{i=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},$=v&&v.__spreadArrays||function(){for(var n=0,e=0,t=arguments.length;e<t;e++)n+=arguments[e].length;for(var i=Array(n),o=0,e=0;e<t;e++)for(var r=arguments[e],s=0,f=r.length;s<f;s++,o++)i[o]=r[s];return i};Object.defineProperty(v,"__esModule",{value:!0});v.SubscriptionClient=void 0;var ee=typeof global<"u"?global:typeof window<"u"?window:{},ke=ee.WebSocket||ee.MozWebSocket,te=B(),Ae=K(),ne=J(),Le=H(),Pe=(ve(),E(de)),xe=(ye(),E(me)),Ge=(F(),E(V)),Qe=X(),ie=Y(),d=Z(),je=(function(){function n(e,t,i,o){var r=t||{},s=r.connectionCallback,f=s===void 0?void 0:s,a=r.connectionParams,c=a===void 0?{}:a,u=r.minTimeout,l=u===void 0?ie.MIN_WS_TIMEOUT:u,y=r.timeout,_=y===void 0?ie.WS_TIMEOUT:y,A=r.reconnect,ae=A===void 0?!1:A,L=r.reconnectionAttempts,ce=L===void 0?1/0:L,P=r.lazy,ue=P===void 0?!1:P,x=r.inactivityTimeout,le=x===void 0?0:x,G=r.wsOptionArguments,fe=G===void 0?[]:G;if(this.wsImpl=i||ke,!this.wsImpl)throw new Error("Unable to find native implementation, or alternative implementation for WebSocket!");this.wsProtocols=o||Qe.GRAPHQL_WS,this.connectionCallback=f,this.url=e,this.operations={},this.nextOperationId=0,this.minWsTimeout=l,this.wsTimeout=_,this.unsentMessagesQueue=[],this.reconnect=ae,this.reconnecting=!1,this.reconnectionAttempts=ce,this.lazy=!!ue,this.inactivityTimeout=le,this.closedByUser=!1,this.backoff=new te({jitter:.5}),this.eventEmitter=new Ae.EventEmitter,this.middlewares=[],this.client=null,this.maxConnectTimeGenerator=this.createMaxConnectTimeGenerator(),this.connectionParams=this.getConnectionParams(c),this.wsOptionArguments=fe,this.lazy||this.connect()}return Object.defineProperty(n.prototype,"status",{get:function(){return this.client===null?this.wsImpl.CLOSED:this.client.readyState},enumerable:!1,configurable:!0}),n.prototype.close=function(e,t){e===void 0&&(e=!0),t===void 0&&(t=!0),this.clearInactivityTimeout(),this.client!==null&&(this.closedByUser=t,e&&(this.clearCheckConnectionInterval(),this.clearMaxConnectTimeout(),this.clearTryReconnectTimeout(),this.unsubscribeAll(),this.sendMessage(void 0,d.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"),e||this.tryReconnect())},n.prototype.request=function(e){var t,i=this.getObserver.bind(this),o=this.executeOperation.bind(this),r=this.unsubscribe.bind(this),s;return this.clearInactivityTimeout(),t={},t[Ge.default]=function(){return this},t.subscribe=function(f,a,c){var u=i(f,a,c);return s=o(e,function(l,y){l===null&&y===null?u.complete&&u.complete():l?u.error&&u.error(l[0]):u.next&&u.next(y)}),{unsubscribe:function(){s&&(r(s),s=null)}}},t},n.prototype.on=function(e,t,i){var o=this.eventEmitter.on(e,t,i);return function(){o.off(e,t,i)}},n.prototype.onConnected=function(e,t){return this.on("connected",e,t)},n.prototype.onConnecting=function(e,t){return this.on("connecting",e,t)},n.prototype.onDisconnected=function(e,t){return this.on("disconnected",e,t)},n.prototype.onReconnected=function(e,t){return this.on("reconnected",e,t)},n.prototype.onReconnecting=function(e,t){return this.on("reconnecting",e,t)},n.prototype.onError=function(e,t){return this.on("error",e,t)},n.prototype.unsubscribeAll=function(){var e=this;Object.keys(this.operations).forEach(function(t){e.unsubscribe(t)})},n.prototype.applyMiddlewares=function(e){var t=this;return new Promise(function(i,o){var r=function(s,f){var a=function(c){if(c)o(c);else if(s.length>0){var u=s.shift();u&&u.applyMiddleware.apply(f,[e,a])}else i(e)};a()};r($(t.middlewares),t)})},n.prototype.use=function(e){var t=this;return e.map(function(i){if(typeof i.applyMiddleware=="function")t.middlewares.push(i);else throw new Error("Middleware must implement the applyMiddleware function.")}),this},n.prototype.getConnectionParams=function(e){return function(){return new Promise(function(t,i){if(typeof e=="function")try{return t(e.call(null))}catch(o){return i(o)}t(e)})}},n.prototype.executeOperation=function(e,t){var i=this;this.client===null&&this.connect();var o=this.generateOperationId();return this.operations[o]={options:e,handler:t},this.applyMiddlewares(e).then(function(r){i.checkOperationOptions(r,t),i.operations[o]&&(i.operations[o]={options:r,handler:t},i.sendMessage(o,d.default.GQL_START,r))}).catch(function(r){i.unsubscribe(o),t(i.formatErrors(r))}),o},n.prototype.getObserver=function(e,t,i){return typeof e=="function"?{next:function(o){return e(o)},error:function(o){return t&&t(o)},complete:function(){return i&&i()}}:e},n.prototype.createMaxConnectTimeGenerator=function(){var e=this.minWsTimeout,t=this.wsTimeout;return new te({min:e,max:t,factor:1.2})},n.prototype.clearCheckConnectionInterval=function(){this.checkConnectionIntervalId&&(clearInterval(this.checkConnectionIntervalId),this.checkConnectionIntervalId=null)},n.prototype.clearMaxConnectTimeout=function(){this.maxConnectTimeoutId&&(clearTimeout(this.maxConnectTimeoutId),this.maxConnectTimeoutId=null)},n.prototype.clearTryReconnectTimeout=function(){this.tryReconnectTimeoutId&&(clearTimeout(this.tryReconnectTimeoutId),this.tryReconnectTimeoutId=null)},n.prototype.clearInactivityTimeout=function(){this.inactivityTimeoutId&&(clearTimeout(this.inactivityTimeoutId),this.inactivityTimeoutId=null)},n.prototype.setInactivityTimeout=function(){var e=this;this.inactivityTimeout>0&&Object.keys(this.operations).length===0&&(this.inactivityTimeoutId=setTimeout(function(){Object.keys(e.operations).length===0&&e.close()},this.inactivityTimeout))},n.prototype.checkOperationOptions=function(e,t){var i=e.query,o=e.variables,r=e.operationName;if(!i)throw new Error("Must provide a query.");if(!t)throw new Error("Must provide an handler.");if(!ne.default(i)&&!xe.getOperationAST(i,r)||r&&!ne.default(r)||o&&!Le.default(o))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.")},n.prototype.buildMessage=function(e,t,i){var o=i&&i.query?w(w({},i),{query:typeof i.query=="string"?i.query:Pe.print(i.query)}):i;return{id:e,type:t,payload:o}},n.prototype.formatErrors=function(e){return Array.isArray(e)?e:e&&e.errors?this.formatErrors(e.errors):e&&e.message?[e]:[{name:"FormatedError",message:"Unknown error",originalError:e}]},n.prototype.sendMessage=function(e,t,i){this.sendMessageRaw(this.buildMessage(e,t,i))},n.prototype.sendMessageRaw=function(e){switch(this.status){case this.wsImpl.OPEN:var t=JSON.stringify(e);try{JSON.parse(t)}catch{this.eventEmitter.emit("error",new Error("Message must be JSON-serializable. Got: "+e))}this.client.send(t);break;case this.wsImpl.CONNECTING:this.unsentMessagesQueue.push(e);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(e)))}},n.prototype.generateOperationId=function(){return String(++this.nextOperationId)},n.prototype.tryReconnect=function(){var e=this;if(!(!this.reconnect||this.backoff.attempts>=this.reconnectionAttempts)){this.reconnecting||(Object.keys(this.operations).forEach(function(i){e.unsentMessagesQueue.push(e.buildMessage(i,d.default.GQL_START,e.operations[i].options))}),this.reconnecting=!0),this.clearTryReconnectTimeout();var t=this.backoff.duration();this.tryReconnectTimeoutId=setTimeout(function(){e.connect()},t)}},n.prototype.flushUnsentMessagesQueue=function(){var e=this;this.unsentMessagesQueue.forEach(function(t){e.sendMessageRaw(t)}),this.unsentMessagesQueue=[]},n.prototype.checkConnection=function(){if(this.wasKeepAliveReceived){this.wasKeepAliveReceived=!1;return}this.reconnecting||this.close(!1,!0)},n.prototype.checkMaxConnectTimeout=function(){var e=this;this.clearMaxConnectTimeout(),this.maxConnectTimeoutId=setTimeout(function(){e.status!==e.wsImpl.OPEN&&(e.reconnecting=!0,e.close(!1,!0))},this.maxConnectTimeGenerator.duration())},n.prototype.connect=function(){var e,t=this;this.client=new((e=this.wsImpl).bind.apply(e,$([void 0,this.url,this.wsProtocols],this.wsOptionArguments))),this.checkMaxConnectTimeout(),this.client.onopen=function(){return Ne(t,void 0,void 0,function(){var i,o;return Re(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 i=r.sent(),this.sendMessage(void 0,d.default.GQL_CONNECTION_INIT,i),this.flushUnsentMessagesQueue(),[3,4];case 3:return o=r.sent(),this.sendMessage(void 0,d.default.GQL_CONNECTION_ERROR,o),this.flushUnsentMessagesQueue(),[3,4];case 4:return[2]}})})},this.client.onclose=function(){t.closedByUser||t.close(!1,!1)},this.client.onerror=function(i){t.eventEmitter.emit("error",i)},this.client.onmessage=function(i){var o=i.data;t.processReceivedData(o)}},n.prototype.processReceivedData=function(e){var t,i;try{t=JSON.parse(e),i=t.id}catch{throw new Error("Message must be JSON-parseable. Got: "+e)}if([d.default.GQL_DATA,d.default.GQL_COMPLETE,d.default.GQL_ERROR].indexOf(t.type)!==-1&&!this.operations[i]){this.unsubscribe(i);return}switch(t.type){case d.default.GQL_CONNECTION_ERROR:this.connectionCallback&&this.connectionCallback(t.payload);break;case d.default.GQL_CONNECTION_ACK:this.eventEmitter.emit(this.reconnecting?"reconnected":"connected",t.payload),this.reconnecting=!1,this.backoff.reset(),this.maxConnectTimeGenerator.reset(),this.connectionCallback&&this.connectionCallback();break;case d.default.GQL_COMPLETE:var o=this.operations[i].handler;delete this.operations[i],o.call(this,null,null);break;case d.default.GQL_ERROR:this.operations[i].handler(this.formatErrors(t.payload),null),delete this.operations[i];break;case d.default.GQL_DATA:var r=t.payload.errors?w(w({},t.payload),{errors:this.formatErrors(t.payload.errors)}):t.payload;this.operations[i].handler(null,r);break;case d.default.GQL_CONNECTION_KEEP_ALIVE:var s=typeof this.wasKeepAliveReceived>"u";this.wasKeepAliveReceived=!0,s&&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!")}},n.prototype.unsubscribe=function(e){this.operations[e]&&(delete this.operations[e],this.setInactivityTimeout(),this.sendMessage(e,d.default.GQL_STOP,void 0))},n})();v.SubscriptionClient=je});var se=pe(re());var oe=class{onConnected(e,t,i){if(t){console.log("Subscription connection error",t),e.error(t);return}console.log("Connected subscription.")}handle(e){return new U(t=>{if(this.client=new se.SubscriptionClient(e.url,{reconnect:!0,connectionParams:e.additionalParams,connectionCallback:(r,s)=>{this.onConnected(t,r,s)}}),!this.client)throw new Error("Could not create WS client!");let i=Date.now(),o=this.client.request({query:e.query,variables:e.variables,operationName:e.selectedOperation??void 0}).subscribe(q(t,e.url,i));return this.cleanup=o.unsubscribe,()=>{this.destroy()}})}destroy(){return j(this,null,function*(){this.cleanup?.(),this.cleanup=void 0,this.client?.unsubscribeAll(),this.client?.close(),this.client=void 0})}};export{oe as WebsocketRequestHandler}; //# sourceMappingURL=chunk-C3YCLGYT.js.map //# debugId=67dc43d1-ff9d-5ff2-8961-640bb4d5f10c