UNPKG

altair-static

Version:

Static package for altair graphql client

7 lines (4 loc) 11.7 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]="b6cc7108-8e46-59c1-8532-e178fb78c4d5")}catch(e){}}(); import{c as v}from"./chunk-472WPQLO.js";import{f as C,h as k}from"./chunk-B7YGBANW.js";var S=C((y,g)=>{"use strict";(function(){var m=this;(function(){(function(){var l=[].slice;this.ActionCable={INTERNAL:{message_types:{welcome:"welcome",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]},WebSocket:window.WebSocket,logger:window.console,createConsumer:function(o){var t;return o==null&&(o=(t=this.getConfig("url"))!=null?t:this.INTERNAL.default_mount_path),new s.Consumer(this.createWebSocketURL(o))},getConfig:function(o){var t;return t=document.head.querySelector("meta[name='action-cable-"+o+"']"),t?.getAttribute("content")},createWebSocketURL:function(o){var t;return o&&!/^wss?:/i.test(o)?(t=document.createElement("a"),t.href=o,t.href=t.href,t.protocol=t.protocol.replace("http","ws"),t.href):o},startDebugging:function(){return this.debugging=!0},stopDebugging:function(){return this.debugging=null},log:function(){var o,t;if(o=1<=arguments.length?l.call(arguments,0):[],this.debugging)return o.push(Date.now()),(t=this.logger).log.apply(t,["[ActionCable]"].concat(l.call(o)))}}}).call(this)}).call(m);var s=m.ActionCable;(function(){(function(){var l=function(o,t){return function(){return o.apply(t,arguments)}};s.ConnectionMonitor=(function(){var o,t,n;e.pollInterval={min:3,max:30},e.staleThreshold=6;function e(i){this.connection=i,this.visibilityDidChange=l(this.visibilityDidChange,this),this.reconnectAttempts=0}return e.prototype.start=function(){if(!this.isRunning())return this.startedAt=t(),delete this.stoppedAt,this.startPolling(),document.addEventListener("visibilitychange",this.visibilityDidChange),s.log("ConnectionMonitor started. pollInterval = "+this.getPollInterval()+" ms")},e.prototype.stop=function(){if(this.isRunning())return this.stoppedAt=t(),this.stopPolling(),document.removeEventListener("visibilitychange",this.visibilityDidChange),s.log("ConnectionMonitor stopped")},e.prototype.isRunning=function(){return this.startedAt!=null&&this.stoppedAt==null},e.prototype.recordPing=function(){return this.pingedAt=t()},e.prototype.recordConnect=function(){return this.reconnectAttempts=0,this.recordPing(),delete this.disconnectedAt,s.log("ConnectionMonitor recorded connect")},e.prototype.recordDisconnect=function(){return this.disconnectedAt=t(),s.log("ConnectionMonitor recorded disconnect")},e.prototype.startPolling=function(){return this.stopPolling(),this.poll()},e.prototype.stopPolling=function(){return clearTimeout(this.pollTimeout)},e.prototype.poll=function(){return this.pollTimeout=setTimeout((function(i){return function(){return i.reconnectIfStale(),i.poll()}})(this),this.getPollInterval())},e.prototype.getPollInterval=function(){var i,c,u,h;return h=this.constructor.pollInterval,u=h.min,c=h.max,i=5*Math.log(this.reconnectAttempts+1),Math.round(o(i,u,c)*1e3)},e.prototype.reconnectIfStale=function(){if(this.connectionIsStale())return s.log("ConnectionMonitor detected stale connection. reconnectAttempts = "+this.reconnectAttempts+", pollInterval = "+this.getPollInterval()+" ms, time disconnected = "+n(this.disconnectedAt)+" s, stale threshold = "+this.constructor.staleThreshold+" s"),this.reconnectAttempts++,this.disconnectedRecently()?s.log("ConnectionMonitor skipping reopening recent disconnect"):(s.log("ConnectionMonitor reopening"),this.connection.reopen())},e.prototype.connectionIsStale=function(){var i;return n((i=this.pingedAt)!=null?i:this.startedAt)>this.constructor.staleThreshold},e.prototype.disconnectedRecently=function(){return this.disconnectedAt&&n(this.disconnectedAt)<this.constructor.staleThreshold},e.prototype.visibilityDidChange=function(){if(document.visibilityState==="visible")return setTimeout((function(i){return function(){if(i.connectionIsStale()||!i.connection.isOpen())return s.log("ConnectionMonitor reopening stale connection on visibilitychange. visbilityState = "+document.visibilityState),i.connection.reopen()}})(this),200)},t=function(){return new Date().getTime()},n=function(i){return(t()-i)/1e3},o=function(i,c,u){return Math.max(c,Math.min(u,i))},e})()}).call(this),(function(){var l,o,t,n,e,i,c=[].slice,u=function(p,r){return function(){return p.apply(r,arguments)}},h=[].indexOf||function(p){for(var r=0,a=this.length;r<a;r++)if(r in this&&this[r]===p)return r;return-1};n=s.INTERNAL,o=n.message_types,t=n.protocols,e=2<=t.length?c.call(t,0,l=t.length-1):(l=0,[]),i=t[l++],s.Connection=(function(){p.reopenDelay=500;function p(r){this.consumer=r,this.open=u(this.open,this),this.subscriptions=this.consumer.subscriptions,this.monitor=new s.ConnectionMonitor(this),this.disconnected=!0}return p.prototype.send=function(r){return this.isOpen()?(this.webSocket.send(JSON.stringify(r)),!0):!1},p.prototype.open=function(){return this.isActive()?(s.log("Attempted to open WebSocket, but existing socket is "+this.getState()),!1):(s.log("Opening WebSocket, current state is "+this.getState()+", subprotocols: "+t),this.webSocket!=null&&this.uninstallEventHandlers(),this.webSocket=new s.WebSocket(this.consumer.url,t),this.installEventHandlers(),this.monitor.start(),!0)},p.prototype.close=function(r){var a,f;if(a=(r??{allowReconnect:!0}).allowReconnect,a||this.monitor.stop(),this.isActive())return(f=this.webSocket)!=null?f.close():void 0},p.prototype.reopen=function(){var r;if(s.log("Reopening WebSocket, current state is "+this.getState()),this.isActive())try{return this.close()}catch(a){return r=a,s.log("Failed to reopen WebSocket",r)}finally{s.log("Reopening WebSocket in "+this.constructor.reopenDelay+"ms"),setTimeout(this.open,this.constructor.reopenDelay)}else return this.open()},p.prototype.getProtocol=function(){var r;return(r=this.webSocket)!=null?r.protocol:void 0},p.prototype.isOpen=function(){return this.isState("open")},p.prototype.isActive=function(){return this.isState("open","connecting")},p.prototype.isProtocolSupported=function(){var r;return r=this.getProtocol(),h.call(e,r)>=0},p.prototype.isState=function(){var r,a;return a=1<=arguments.length?c.call(arguments,0):[],r=this.getState(),h.call(a,r)>=0},p.prototype.getState=function(){var r,a,f;for(a in WebSocket)if(f=WebSocket[a],f===((r=this.webSocket)!=null?r.readyState:void 0))return a.toLowerCase();return null},p.prototype.installEventHandlers=function(){var r,a;for(r in this.events)a=this.events[r].bind(this),this.webSocket["on"+r]=a},p.prototype.uninstallEventHandlers=function(){var r;for(r in this.events)this.webSocket["on"+r]=function(){}},p.prototype.events={message:function(r){var a,f,d,b;if(this.isProtocolSupported())switch(d=JSON.parse(r.data),a=d.identifier,f=d.message,b=d.type,b){case o.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case o.ping:return this.monitor.recordPing();case o.confirmation:return this.subscriptions.notify(a,"connected");case o.rejection:return this.subscriptions.reject(a);default:return this.subscriptions.notify(a,"received",f)}},open:function(){if(s.log("WebSocket onopen event, using '"+this.getProtocol()+"' subprotocol"),this.disconnected=!1,!this.isProtocolSupported())return s.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close:function(r){if(s.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error:function(){return s.log("WebSocket onerror event")}},p})()}).call(this),(function(){var l=[].slice;s.Subscriptions=(function(){function o(t){this.consumer=t,this.subscriptions=[]}return o.prototype.create=function(t,n){var e,i,c;return e=t,i=typeof e=="object"?e:{channel:e},c=new s.Subscription(this.consumer,i,n),this.add(c)},o.prototype.add=function(t){return this.subscriptions.push(t),this.consumer.ensureActiveConnection(),this.notify(t,"initialized"),this.sendCommand(t,"subscribe"),t},o.prototype.remove=function(t){return this.forget(t),this.findAll(t.identifier).length||this.sendCommand(t,"unsubscribe"),t},o.prototype.reject=function(t){var n,e,i,c,u;for(i=this.findAll(t),c=[],n=0,e=i.length;n<e;n++)u=i[n],this.forget(u),this.notify(u,"rejected"),c.push(u);return c},o.prototype.forget=function(t){var n;return this.subscriptions=function(){var e,i,c,u;for(c=this.subscriptions,u=[],e=0,i=c.length;e<i;e++)n=c[e],n!==t&&u.push(n);return u}.call(this),t},o.prototype.findAll=function(t){var n,e,i,c,u;for(i=this.subscriptions,c=[],n=0,e=i.length;n<e;n++)u=i[n],u.identifier===t&&c.push(u);return c},o.prototype.reload=function(){var t,n,e,i,c;for(e=this.subscriptions,i=[],t=0,n=e.length;t<n;t++)c=e[t],i.push(this.sendCommand(c,"subscribe"));return i},o.prototype.notifyAll=function(){var t,n,e,i,c,u,h;for(n=arguments[0],t=2<=arguments.length?l.call(arguments,1):[],c=this.subscriptions,u=[],e=0,i=c.length;e<i;e++)h=c[e],u.push(this.notify.apply(this,[h,n].concat(l.call(t))));return u},o.prototype.notify=function(){var t,n,e,i,c,u,h;for(u=arguments[0],n=arguments[1],t=3<=arguments.length?l.call(arguments,2):[],typeof u=="string"?h=this.findAll(u):h=[u],c=[],e=0,i=h.length;e<i;e++)u=h[e],c.push(typeof u[n]=="function"?u[n].apply(u,t):void 0);return c},o.prototype.sendCommand=function(t,n){var e;return e=t.identifier,this.consumer.send({command:n,identifier:e})},o})()}).call(this),(function(){s.Subscription=(function(){var l;function o(t,n,e){this.consumer=t,n==null&&(n={}),this.identifier=JSON.stringify(n),l(this,e)}return o.prototype.perform=function(t,n){return n==null&&(n={}),n.action=t,this.send(n)},o.prototype.send=function(t){return this.consumer.send({command:"message",identifier:this.identifier,data:JSON.stringify(t)})},o.prototype.unsubscribe=function(){return this.consumer.subscriptions.remove(this)},l=function(t,n){var e,i;if(n!=null)for(e in n)i=n[e],t[e]=i;return t},o})()}).call(this),(function(){s.Consumer=(function(){function l(o){this.url=o,this.subscriptions=new s.Subscriptions(this),this.connection=new s.Connection(this)}return l.prototype.send=function(o){return this.connection.send(o)},l.prototype.connect=function(){return this.connection.open()},l.prototype.disconnect=function(){return this.connection.close({allowReconnect:!1})},l.prototype.ensureActiveConnection=function(){if(!this.connection.isActive())return this.connection.open()},l})()}).call(this)}).call(this),typeof g=="object"&&g.exports?g.exports=s:typeof define=="function"&&define.amd&&define(s)}).call(y)});var w=k(S()),A=class{handle(s){return new v(l=>{let o=Date.now(),t=w.default.createConsumer(s.url);return this.subscription=t.subscriptions.create({channel:typeof s.additionalParams?.channel=="string"?s.additionalParams.channel:"GraphqlChannel",channelId:Math.round(Date.now()+Math.random()*1e5).toString(16)},{connected:function(){this.perform("execute",s)},received:function(n){if(n.result.data||n.result.errors){let e=Date.now();l.next({ok:!0,data:JSON.stringify(n.result),headers:new Headers,status:200,statusText:"OK",url:s.url,requestStartTimestamp:o,requestEndTimestamp:e,responseTimeMs:e-o})}n.more||l.complete()}}),()=>{this.destroy()}})}generateCurl(s){throw new Error("Method not implemented.")}destroy(){this.subscription?.unsubscribe()}};export{A as ActionCableRequestHandler}; //# sourceMappingURL=chunk-YJNGIILY.js.map //# debugId=b6cc7108-8e46-59c1-8532-e178fb78c4d5