UNPKG

altair-static

Version:

Static package for altair graphql client

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