Skip to content

Instantly share code, notes, and snippets.

@jjgonecrypto
Created December 6, 2019 02:03
Show Gist options
  • Save jjgonecrypto/2a816a6b80b0a5cb1de630f4e64bc533 to your computer and use it in GitHub Desktop.
Save jjgonecrypto/2a816a6b80b0a5cb1de630f4e64bc533 to your computer and use it in GitHub Desktop.
window.snxData=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";function i(e){var t,n=e.Symbol;return"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable",t}n.d(t,"a",(function(){return i}))},function(e,t,n){"use strict";(function(t){const i=n(4),r={snx:"https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix",depot:"https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-depot",exchanges:"https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanges",rates:"https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-rates"},o="0x"+"0".repeat(40),s=({api:e,query:{entity:n,selection:r={},properties:o=[]},max:s=1/0})=>{s=Number(s);const a=({skip:c})=>{const u=e=>Object.entries(e).filter(([,e])=>void 0!==e).map(([e,t])=>`${e}:${"object"==typeof t?"{"+u(t)+"}":t}`).join(","),l=c+1e3>s?s%1e3:1e3,f=Object.assign({},r,{first:l,skip:c}),p=`{"query":"{${n}(${u(f)}){${o.join(",")}}}", "variables": null}`;return"object"==typeof t&&"true"===t.env.DEBUG&&console.log(p),i(e,{method:"POST",body:p}).then(e=>e.json()).then(e=>{if(e.errors)throw Error(JSON.stringify(e.errors));const{data:{[n]:t}}=e;return t.length<1e3||Math.min(s,c+t.length)>=s?t:a({skip:c+1e3}).then(e=>t.concat(e))})};return a({skip:0})},a=e=>{const t=e.toString();let n="";for(let e=2;e<t.length;e+=2){const i=t.substr(e,2);"00"!==i&&(n+=String.fromCharCode(parseInt(i,16)))}return n};e.exports={pageResults:s,graphAPIEndpoints:r,depot:{userActions:({network:e="mainnet",user:t,max:n=100})=>s({api:r.depot,query:{entity:"userActions",selection:{orderBy:"timestamp",orderDirection:"desc",where:{network:`\\"${e}\\"`,user:t?`\\"${t}\\"`:void 0}},properties:["id","user","amount","minimum","depositIndex","type","block","timestamp"]},max:n}).then(e=>e.map(({id:e,user:t,amount:n,type:i,minimum:r,depositIndex:o,block:s,timestamp:a})=>({hash:e.split("-")[0],user:t,amount:n/1e18,type:i,minimum:null!==r?Number(r):null,depositIndex:null!==o?Number(o):null,block:Number(s),timestamp:Number(1e3*a),date:new Date(1e3*a)}))).catch(e=>console.error(e)),clearedDeposits:({network:e="mainnet",fromAddress:t,toAddress:n,max:i=100})=>s({api:r.depot,query:{entity:"clearedDeposits",selection:{orderBy:"timestamp",orderDirection:"desc",where:{network:`\\"${e}\\"`,fromAddress:t?`\\"${t}\\"`:void 0,toAddress:n?`\\"${n}\\"`:void 0}},properties:["id","fromAddress","toAddress","fromETHAmount","toAmount","depositIndex","block","timestamp"]},max:i}).then(e=>e.map(({id:e,fromAddress:t,toAddress:n,fromETHAmount:i,toAmount:r,depositIndex:o,block:s,timestamp:a})=>({hash:e.split("-")[0],fromAddress:t,toAddress:n,fromETHAmount:i/1e18,toAmount:r/1e18,depositIndex:null!==o?Number(o):null,block:Number(s),timestamp:Number(1e3*a),date:new Date(1e3*a)}))).catch(e=>console.error(e))},exchanges:{_properties:["id","from","gasPrice","from","fromAmount","fromAmountInUSD","fromCurrencyKey","toCurrencyKey","toAddress","toAmount","toAmountInUSD","feesInUSD","block","timestamp"],_mapSynthExchange:({gasPrice:e,timestamp:t,id:n,from:i,fromAmount:r,block:o,fromAmountInUSD:s,fromCurrencyKey:c,toAddress:u,toAmount:l,toAmountInUSD:f,toCurrencyKey:p,feesInUSD:d})=>({gasPrice:e/1e9,block:Number(o),timestamp:Number(1e3*t),date:new Date(1e3*t),hash:n.split("-")[0],fromAddress:i,fromAmount:r/1e18,fromCurrencyKeyBytes:c,fromCurrencyKey:a(c),fromAmountInUSD:s/1e18,toAmount:l/1e18,toAmountInUSD:f/1e18,toCurrencyKeyBytes:p,toCurrencyKey:a(p),toAddress:u,feesInUSD:d/1e18}),total:({network:e="mainnet"}={})=>s({api:r.exchanges,query:{entity:"totals",selection:{where:{id:`\\"${e}\\"`}},properties:["exchangers","exchangeUSDTally","totalFeesGeneratedInUSD"]},max:1}).then(([{exchangers:e,exchangeUSDTally:t,totalFeesGeneratedInUSD:n}])=>({exchangers:Number(e),exchangeUSDTally:t/1e18,totalFeesGeneratedInUSD:n/1e18})).catch(e=>console.error(e)),since:({network:t="mainnet",max:n=1/0,timestampInSecs:i,minBlock:o,maxBlock:a,fromAddress:c}={})=>s({api:r.exchanges,max:n,query:{entity:"synthExchanges",selection:{orderBy:"timestamp",orderDirection:"desc",where:{network:`\\"${t}\\"`,timestamp_gt:i||void 0,block_gte:o||void 0,block_lte:a||void 0,from:c?`\\"${c}\\"`:void 0}},properties:e.exports.exchanges._properties}}).then(t=>t.map(e.exports.exchanges._mapSynthExchange)).catch(e=>console.error(e)),subscribe(){const t=n(5),{SubscriptionClient:i}=n(6),r=new i("wss://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanges",{reconnect:!0},t).request({query:`subscription { synthExchanges(first: 1, orderBy: timestamp, orderDirection: desc) { ${e.exports.exchanges._properties.join(",")} } }`});return{subscribe:({next:t,error:n,complete:i})=>r.subscribe({next({data:{synthExchanges:n}}){n.map(e.exports.exchanges._mapSynthExchange).forEach(t)},error:n,complete:i})}}},synths:{issuers:({max:e=10}={})=>s({api:r.snx,max:e,query:{entity:"issuers",properties:["id"]}}).then(e=>e.map(({id:e})=>e)).catch(e=>console.error(e)),transfers:({synth:e,from:t,to:n,max:i=100,minBlock:a,maxBlock:c}={})=>s({api:r.snx,max:i,query:{entity:"transfers",selection:{orderBy:"timestamp",orderDirection:"desc",where:{source:e?`\\"${e}\\"`:void 0,source_not:'\\"SNX\\"',from:t?`\\"${t}\\"`:void 0,to:n?`\\"${n}\\"`:void 0,from_not:`\\"${o}\\"`,to_not:`\\"${o}\\"`,block_gte:a||void 0,block_lte:c||void 0}},properties:["id","source","to","from","value","block","timestamp"]}}).then(e=>e.map(({id:e,source:t,block:n,timestamp:i,from:r,to:o,value:s})=>({source:t,block:Number(n),timestamp:Number(1e3*i),date:new Date(1e3*i),hash:e.split("-")[0],from:r,to:o,value:s/1e18}))).catch(e=>console.error(e))},rate:{updates:({synth:e,minBlock:t,maxBlock:n,max:i=100}={})=>s({api:r.rates,max:i,query:{entity:"rateUpdates",selection:{orderBy:"timestamp",orderDirection:"desc",where:{synth:e?`\\"${e}\\"`:void 0,synth_not_in:e?void 0:"["+["SNX","ETH","XDR"].map(e=>`\\"${e}\\"`).join(",")+"]",block_gte:t||void 0,block_lte:n||void 0}},properties:["id","synth","rate","block","timestamp"]}}).then(e=>e.map(({id:e,rate:t,block:n,timestamp:i,synth:r})=>({block:Number(n),synth:r,timestamp:Number(1e3*i),date:new Date(1e3*i),hash:e.split("-")[0],rate:t/1e18}))).catch(e=>console.error(e))},snx:{holders:({max:e=100}={})=>s({api:r.snx,max:e,query:{entity:"snxholders",selection:{orderBy:"collateral",orderDirection:"desc"},properties:["id","collateral"]}}).then(e=>e.map(({id:e,collateral:t})=>({address:e,collateral:t?t/1e18:null}))).catch(e=>console.error(e)),rewards:({max:e=100}={})=>s({api:r.snx,max:e,query:{entity:"rewardEscrowHolders",properties:["id","balanceOf"]}}).then(e=>e.map(({id:e,balanceOf:t})=>({address:e,balance:t/1e18}))).catch(e=>console.error(e)),total:()=>s({api:r.snx,query:{entity:"synthetixes",selection:{where:{id:1}},properties:["issuers","snxHolders"]},max:1}).then(([{issuers:e,snxHolders:t}])=>({issuers:Number(e),snxHolders:Number(t)})).catch(e=>console.error(e)),transfers:({from:e,to:t,max:n=100,minBlock:i,maxBlock:o}={})=>s({api:r.snx,max:n,query:{entity:"transfers",selection:{orderBy:"timestamp",orderDirection:"desc",where:{source:'\\"SNX\\"',from:e?`\\"${e}\\"`:void 0,to:t?`\\"${t}\\"`:void 0,block_gte:i||void 0,block_lte:o||void 0}},properties:["id","to","from","value","block","timestamp"]}}).then(e=>e.map(({id:e,block:t,timestamp:n,from:i,to:r,value:o})=>({block:Number(t),timestamp:Number(1e3*n),date:new Date(1e3*n),hash:e.split("-")[0],from:i,to:r,value:o/1e18}))).catch(e=>console.error(e))}}}).call(this,n(3))},function(e,t){var n,i,r=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(e){n=o}try{i="function"==typeof clearTimeout?clearTimeout:s}catch(e){i=s}}();var c,u=[],l=!1,f=-1;function p(){l&&c&&(l=!1,c.length?u=c.concat(u):f=-1,u.length&&d())}function d(){if(!l){var e=a(p);l=!0;for(var t=u.length;t;){for(c=u,u=[];++f<t;)c&&c[f].run();f=-1,t=u.length}c=null,l=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===s||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function m(e,t){this.fun=e,this.array=t}function h(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new m(e,t)),1!==u.length||l||a(d)},m.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=h,r.addListener=h,r.once=h,r.off=h,r.removeListener=h,r.removeAllListeners=h,r.emit=h,r.prependListener=h,r.prependOnceListener=h,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(e,t){e.exports=window.fetch},function(e,t){e.exports=window.WebSocket},function(e,t,n){"use strict";(function(e){var i=this&&this.__assign||Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},r=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(s,a)}c((i=i.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(t,"__esModule",{value:!0});var s=void 0!==e?e:"undefined"!=typeof window?window:{},a=s.WebSocket||s.MozWebSocket,c=n(7),u=n(8),l=n(9),f=n(10),p=n(16),d=n(17),m=n(11),h=n(13),y=n(14),v=n(15),b=function(){function e(e,t,n,i){var r=t||{},o=r.connectionCallback,s=void 0===o?void 0:o,l=r.connectionParams,f=void 0===l?{}:l,p=r.timeout,d=void 0===p?y.WS_TIMEOUT:p,m=r.reconnect,v=void 0!==m&&m,b=r.reconnectionAttempts,T=void 0===b?1/0:b,E=r.lazy,I=void 0!==E&&E,g=r.inactivityTimeout,O=void 0===g?0:g;if(this.wsImpl=n||a,!this.wsImpl)throw new Error("Unable to find native implementation, or alternative implementation for WebSocket!");this.wsProtocols=i||h.GRAPHQL_WS,this.connectionCallback=s,this.url=e,this.operations={},this.nextOperationId=0,this.wsTimeout=d,this.unsentMessagesQueue=[],this.reconnect=v,this.reconnecting=!1,this.reconnectionAttempts=T,this.lazy=!!I,this.inactivityTimeout=O,this.closedByUser=!1,this.backoff=new c({jitter:.5}),this.eventEmitter=new u.EventEmitter,this.middlewares=[],this.client=null,this.maxConnectTimeGenerator=this.createMaxConnectTimeGenerator(),this.connectionParams=this.getConnectionParams(f),this.lazy||this.connect()}return Object.defineProperty(e.prototype,"status",{get:function(){return null===this.client?this.wsImpl.CLOSED:this.client.readyState},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=!0),void 0===t&&(t=!0),this.clearInactivityTimeout(),null!==this.client&&(this.closedByUser=t,e&&(this.clearCheckConnectionInterval(),this.clearMaxConnectTimeout(),this.clearTryReconnectTimeout(),this.unsubscribeAll(),this.sendMessage(void 0,v.default.GQL_CONNECTION_TERMINATE,null)),this.client.close(),this.client=null,this.eventEmitter.emit("disconnected"),e||this.tryReconnect())},e.prototype.request=function(e){var t,n,i=this.getObserver.bind(this),r=this.executeOperation.bind(this),o=this.unsubscribe.bind(this);return this.clearInactivityTimeout(),(t={})[m.default]=function(){return this},t.subscribe=function(t,s,a){var c=i(t,s,a);return n=r(e,(function(e,t){null===e&&null===t?c.complete&&c.complete():e?c.error&&c.error(e[0]):c.next&&c.next(t)})),{unsubscribe:function(){n&&(o(n),n=null)}}},t},e.prototype.on=function(e,t,n){var i=this.eventEmitter.on(e,t,n);return function(){i.off(e,t,n)}},e.prototype.onConnected=function(e,t){return this.on("connected",e,t)},e.prototype.onConnecting=function(e,t){return this.on("connecting",e,t)},e.prototype.onDisconnected=function(e,t){return this.on("disconnected",e,t)},e.prototype.onReconnected=function(e,t){return this.on("reconnected",e,t)},e.prototype.onReconnecting=function(e,t){return this.on("reconnecting",e,t)},e.prototype.onError=function(e,t){return this.on("error",e,t)},e.prototype.unsubscribeAll=function(){var e=this;Object.keys(this.operations).forEach((function(t){e.unsubscribe(t)}))},e.prototype.applyMiddlewares=function(e){var t=this;return new Promise((function(n,i){var r,o,s;r=t.middlewares.slice(),o=t,(s=function(t){if(t)i(t);else if(r.length>0){var a=r.shift();a&&a.applyMiddleware.apply(o,[e,s])}else n(e)})()}))},e.prototype.use=function(e){var t=this;return e.map((function(e){if("function"!=typeof e.applyMiddleware)throw new Error("Middleware must implement the applyMiddleware function.");t.middlewares.push(e)})),this},e.prototype.getConnectionParams=function(e){return function(){return new Promise((function(t,n){if("function"==typeof e)try{return t(e.call(null))}catch(e){return n(e)}t(e)}))}},e.prototype.executeOperation=function(e,t){var n=this;null===this.client&&this.connect();var i=this.generateOperationId();return this.operations[i]={options:e,handler:t},this.applyMiddlewares(e).then((function(e){n.checkOperationOptions(e,t),n.operations[i]&&(n.operations[i]={options:e,handler:t},n.sendMessage(i,v.default.GQL_START,e))})).catch((function(e){n.unsubscribe(i),t(n.formatErrors(e))})),i},e.prototype.getObserver=function(e,t,n){return"function"==typeof e?{next:function(t){return e(t)},error:function(e){return t&&t(e)},complete:function(){return n&&n()}}:e},e.prototype.createMaxConnectTimeGenerator=function(){var e=this.wsTimeout;return new c({min:1e3,max:e,factor:1.2})},e.prototype.clearCheckConnectionInterval=function(){this.checkConnectionIntervalId&&(clearInterval(this.checkConnectionIntervalId),this.checkConnectionIntervalId=null)},e.prototype.clearMaxConnectTimeout=function(){this.maxConnectTimeoutId&&(clearTimeout(this.maxConnectTimeoutId),this.maxConnectTimeoutId=null)},e.prototype.clearTryReconnectTimeout=function(){this.tryReconnectTimeoutId&&(clearTimeout(this.tryReconnectTimeoutId),this.tryReconnectTimeoutId=null)},e.prototype.clearInactivityTimeout=function(){this.inactivityTimeoutId&&(clearTimeout(this.inactivityTimeoutId),this.inactivityTimeoutId=null)},e.prototype.setInactivityTimeout=function(){var e=this;this.inactivityTimeout>0&&0===Object.keys(this.operations).length&&(this.inactivityTimeoutId=setTimeout((function(){0===Object.keys(e.operations).length&&e.close()}),this.inactivityTimeout))},e.prototype.checkOperationOptions=function(e,t){var n=e.query,i=e.variables,r=e.operationName;if(!n)throw new Error("Must provide a query.");if(!t)throw new Error("Must provide an handler.");if(!l.default(n)&&!d.getOperationAST(n,r)||r&&!l.default(r)||i&&!f.default(i))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.")},e.prototype.buildMessage=function(e,t,n){return{id:e,type:t,payload:n&&n.query?i({},n,{query:"string"==typeof n.query?n.query:p.print(n.query)}):n}},e.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}]},e.prototype.sendMessage=function(e,t,n){this.sendMessageRaw(this.buildMessage(e,t,n))},e.prototype.sendMessageRaw=function(e){switch(this.status){case this.wsImpl.OPEN:var t=JSON.stringify(e);try{JSON.parse(t)}catch(t){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)))}},e.prototype.generateOperationId=function(){return String(++this.nextOperationId)},e.prototype.tryReconnect=function(){var e=this;if(this.reconnect&&!(this.backoff.attempts>=this.reconnectionAttempts)){this.reconnecting||(Object.keys(this.operations).forEach((function(t){e.unsentMessagesQueue.push(e.buildMessage(t,v.default.GQL_START,e.operations[t].options))})),this.reconnecting=!0),this.clearTryReconnectTimeout();var t=this.backoff.duration();this.tryReconnectTimeoutId=setTimeout((function(){e.connect()}),t)}},e.prototype.flushUnsentMessagesQueue=function(){var e=this;this.unsentMessagesQueue.forEach((function(t){e.sendMessageRaw(t)})),this.unsentMessagesQueue=[]},e.prototype.checkConnection=function(){this.wasKeepAliveReceived?this.wasKeepAliveReceived=!1:this.reconnecting||this.close(!1,!0)},e.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())},e.prototype.connect=function(){var e=this;this.client=new this.wsImpl(this.url,this.wsProtocols),this.checkMaxConnectTimeout(),this.client.onopen=function(){return r(e,void 0,void 0,(function(){var e,t;return o(this,(function(n){switch(n.label){case 0:if(this.status!==this.wsImpl.OPEN)return[3,4];this.clearMaxConnectTimeout(),this.closedByUser=!1,this.eventEmitter.emit(this.reconnecting?"reconnecting":"connecting"),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.connectionParams()];case 2:return e=n.sent(),this.sendMessage(void 0,v.default.GQL_CONNECTION_INIT,e),this.flushUnsentMessagesQueue(),[3,4];case 3:return t=n.sent(),this.sendMessage(void 0,v.default.GQL_CONNECTION_ERROR,t),this.flushUnsentMessagesQueue(),[3,4];case 4:return[2]}}))}))},this.client.onclose=function(){e.closedByUser||e.close(!1,!1)},this.client.onerror=function(t){e.eventEmitter.emit("error",t)},this.client.onmessage=function(t){var n=t.data;e.processReceivedData(n)}},e.prototype.processReceivedData=function(e){var t,n;try{n=(t=JSON.parse(e)).id}catch(t){throw new Error("Message must be JSON-parseable. Got: "+e)}if(-1===[v.default.GQL_DATA,v.default.GQL_COMPLETE,v.default.GQL_ERROR].indexOf(t.type)||this.operations[n])switch(t.type){case v.default.GQL_CONNECTION_ERROR:this.connectionCallback&&this.connectionCallback(t.payload);break;case v.default.GQL_CONNECTION_ACK:this.eventEmitter.emit(this.reconnecting?"reconnected":"connected"),this.reconnecting=!1,this.backoff.reset(),this.maxConnectTimeGenerator.reset(),this.connectionCallback&&this.connectionCallback();break;case v.default.GQL_COMPLETE:this.operations[n].handler(null,null),delete this.operations[n];break;case v.default.GQL_ERROR:this.operations[n].handler(this.formatErrors(t.payload),null),delete this.operations[n];break;case v.default.GQL_DATA:var r=t.payload.errors?i({},t.payload,{errors:this.formatErrors(t.payload.errors)}):t.payload;this.operations[n].handler(null,r);break;case v.default.GQL_CONNECTION_KEEP_ALIVE:var o=void 0===this.wasKeepAliveReceived;this.wasKeepAliveReceived=!0,o&&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)},e.prototype.unsubscribe=function(e){this.operations[e]&&(delete this.operations[e],this.setInactivityTimeout(),this.sendMessage(e,v.default.GQL_STOP,void 0))},e}();t.SubscriptionClient=b}).call(this,n(0))},function(e,t){function n(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}e.exports=n,n.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=0==(1&Math.floor(10*t))?e-n:e+n}return 0|Math.min(e,this.max)},n.prototype.reset=function(){this.attempts=0},n.prototype.setMin=function(e){this.ms=e},n.prototype.setMax=function(e){this.max=e},n.prototype.setJitter=function(e){this.jitter=e}},function(e,t,n){"use strict";var i=Object.prototype.hasOwnProperty,r="~";function o(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(e,t,n,i,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new s(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function c(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function u(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(r=!1)),u.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)i.call(e,t)&&n.push(r?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},u.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s},u.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},u.prototype.emit=function(e,t,n,i,o,s){var a=r?r+e:e;if(!this._events[a])return!1;var c,u,l=this._events[a],f=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),f){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,i),!0;case 5:return l.fn.call(l.context,t,n,i,o),!0;case 6:return l.fn.call(l.context,t,n,i,o,s),!0}for(u=1,c=new Array(f-1);u<f;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var p,d=l.length;for(u=0;u<d;u++)switch(l[u].once&&this.removeListener(e,l[u].fn,void 0,!0),f){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,t);break;case 3:l[u].fn.call(l[u].context,t,n);break;case 4:l[u].fn.call(l[u].context,t,n,i);break;default:if(!c)for(p=1,c=new Array(f-1);p<f;p++)c[p-1]=arguments[p];l[u].fn.apply(l[u].context,c)}}return!0},u.prototype.on=function(e,t,n){return a(this,e,t,n,!1)},u.prototype.once=function(e,t,n){return a(this,e,t,n,!0)},u.prototype.removeListener=function(e,t,n,i){var o=r?r+e:e;if(!this._events[o])return this;if(!t)return c(this,o),this;var s=this._events[o];if(s.fn)s.fn!==t||i&&!s.once||n&&s.context!==n||c(this,o);else{for(var a=0,u=[],l=s.length;a<l;a++)(s[a].fn!==t||i&&!s[a].once||n&&s[a].context!==n)&&u.push(s[a]);u.length?this._events[o]=1===u.length?u[0]:u:c(this,o)}return this},u.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&c(this,t)):(this._events=new o,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,e.exports=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return"string"==typeof e}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return null!==e&&"object"==typeof e}},function(e,t,n){"use strict";n.r(t),function(e,i){var r,o=n(1);r="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==e?e:i;var s=Object(o.a)(r);t.default=s}.call(this,n(0),n(12)(e))},function(e,t){e.exports=function(e){if(!e.webpackPolyfill){var t=Object.create(e);t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),Object.defineProperty(t,"exports",{enumerable:!0}),t.webpackPolyfill=1}return t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.GRAPHQL_WS="graphql-ws";t.GRAPHQL_SUBSCRIPTIONS="graphql-subscriptions"},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.WS_TIMEOUT=3e4},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){throw new Error("Static Class")}return e.GQL_CONNECTION_INIT="connection_init",e.GQL_CONNECTION_ACK="connection_ack",e.GQL_CONNECTION_ERROR="connection_error",e.GQL_CONNECTION_KEEP_ALIVE="ka",e.GQL_CONNECTION_TERMINATE="connection_terminate",e.GQL_START="start",e.GQL_DATA="data",e.GQL_ERROR="error",e.GQL_COMPLETE="complete",e.GQL_STOP="stop",e.SUBSCRIPTION_START="subscription_start",e.SUBSCRIPTION_DATA="subscription_data",e.SUBSCRIPTION_SUCCESS="subscription_success",e.SUBSCRIPTION_FAIL="subscription_fail",e.SUBSCRIPTION_END="subscription_end",e.INIT="init",e.INIT_SUCCESS="init_success",e.INIT_FAIL="init_fail",e.KEEP_ALIVE="keepalive",e}();t.default=i},function(e,t,n){"use strict";n.r(t);var i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):void 0;function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var o=10,s=2;function a(e,t){switch(r(e)){case"string":return JSON.stringify(e);case"function":return e.name?"[function ".concat(e.name,"]"):"[function]";case"object":return null===e?"null":function(e,t){if(-1!==t.indexOf(e))return"[Circular]";var n=[].concat(t,[e]),r=function(e){var t=e[String(i)];if("function"==typeof t)return t;if("function"==typeof e.inspect)return e.inspect}(e);if(void 0!==r){var c=r.call(e);if(c!==e)return"string"==typeof c?c:a(c,n)}else if(Array.isArray(e))return function(e,t){if(0===e.length)return"[]";if(t.length>s)return"[Array]";for(var n=Math.min(o,e.length),i=e.length-n,r=[],c=0;c<n;++c)r.push(a(e[c],t));1===i?r.push("... 1 more item"):i>1&&r.push("... ".concat(i," more items"));return"["+r.join(", ")+"]"}(e,n);return function(e,t){var n=Object.keys(e);if(0===n.length)return"{}";if(t.length>s)return"["+function(e){var t=Object.prototype.toString.call(e).replace(/^\[object /,"").replace(/]$/,"");if("Object"===t&&"function"==typeof e.constructor){var n=e.constructor.name;if("string"==typeof n&&""!==n)return n}return t}(e)+"]";return"{ "+n.map((function(n){return n+": "+a(e[n],t)})).join(", ")+" }"}(e,n)}(e,t);default:return String(e)}}var c={Name:[],Document:["definitions"],OperationDefinition:["name","variableDefinitions","directives","selectionSet"],VariableDefinition:["variable","type","defaultValue","directives"],Variable:["name"],SelectionSet:["selections"],Field:["alias","name","arguments","directives","selectionSet"],Argument:["name","value"],FragmentSpread:["name","directives"],InlineFragment:["typeCondition","directives","selectionSet"],FragmentDefinition:["name","variableDefinitions","typeCondition","directives","selectionSet"],IntValue:[],FloatValue:[],StringValue:[],BooleanValue:[],NullValue:[],EnumValue:[],ListValue:["values"],ObjectValue:["fields"],ObjectField:["name","value"],Directive:["name","arguments"],NamedType:["name"],ListType:["type"],NonNullType:["type"],SchemaDefinition:["directives","operationTypes"],OperationTypeDefinition:["type"],ScalarTypeDefinition:["description","name","directives"],ObjectTypeDefinition:["description","name","interfaces","directives","fields"],FieldDefinition:["description","name","arguments","type","directives"],InputValueDefinition:["description","name","type","defaultValue","directives"],InterfaceTypeDefinition:["description","name","directives","fields"],UnionTypeDefinition:["description","name","directives","types"],EnumTypeDefinition:["description","name","directives","values"],EnumValueDefinition:["description","name","directives"],InputObjectTypeDefinition:["description","name","directives","fields"],DirectiveDefinition:["description","name","arguments","locations"],SchemaExtension:["directives","operationTypes"],ScalarTypeExtension:["name","directives"],ObjectTypeExtension:["name","interfaces","directives","fields"],InterfaceTypeExtension:["name","directives","fields"],UnionTypeExtension:["name","directives","types"],EnumTypeExtension:["name","directives","values"],InputObjectTypeExtension:["name","directives","fields"]},u=Object.freeze({});function l(e){return Boolean(e&&"string"==typeof e.kind)}function f(e,t,n){var i=e[t];if(i){if(!n&&"function"==typeof i)return i;var r=n?i.leave:i.enter;if("function"==typeof r)return r}else{var o=n?e.leave:e.enter;if(o){if("function"==typeof o)return o;var s=o[t];if("function"==typeof s)return s}}}function p(e){return function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,i=void 0,r=Array.isArray(e),o=[e],s=-1,p=[],d=void 0,m=void 0,h=void 0,y=[],v=[],b=e;do{var T=++s===o.length,E=T&&0!==p.length;if(T){if(m=0===v.length?void 0:y[y.length-1],d=h,h=v.pop(),E){if(r)d=d.slice();else{for(var I={},g=0,O=Object.keys(d);g<O.length;g++){var x=O[g];I[x]=d[x]}d=I}for(var N=0,_=0;_<p.length;_++){var w=p[_][0],S=p[_][1];r&&(w-=N),r&&null===S?(d.splice(w,1),N++):d[w]=S}}s=i.index,o=i.keys,p=i.edits,r=i.inArray,i=i.prev}else{if(m=h?r?s:o[s]:void 0,null==(d=h?h[m]:b))continue;h&&y.push(m)}var D=void 0;if(!Array.isArray(d)){if(!l(d))throw new Error("Invalid AST Node: "+a(d,[]));var A=f(t,d.kind,T);if(A){if((D=A.call(t,d,m,h,y,v))===u)break;if(!1===D){if(!T){y.pop();continue}}else if(void 0!==D&&(p.push([m,D]),!T)){if(!l(D)){y.pop();continue}d=D}}}void 0===D&&E&&p.push([m,d]),T?y.pop():(i={inArray:r,index:s,keys:o,edits:p,prev:i},o=(r=Array.isArray(d))?d:n[d.kind]||[],s=-1,p=[],h&&v.push(h),h=d)}while(void 0!==i);return 0!==p.length&&(b=p[p.length-1][1]),b}(e,{leave:d})}n.d(t,"print",(function(){return p}));var d={Name:function(e){return e.value},Variable:function(e){return"$"+e.name},Document:function(e){return h(e.definitions,"\n\n")+"\n"},OperationDefinition:function(e){var t=e.operation,n=e.name,i=v("(",h(e.variableDefinitions,", "),")"),r=h(e.directives," "),o=e.selectionSet;return n||r||i||"query"!==t?h([t,h([n,i]),r,o]," "):o},VariableDefinition:function(e){var t=e.variable,n=e.type,i=e.defaultValue,r=e.directives;return t+": "+n+v(" = ",i)+v(" ",h(r," "))},SelectionSet:function(e){return y(e.selections)},Field:function(e){var t=e.alias,n=e.name,i=e.arguments,r=e.directives,o=e.selectionSet;return h([v("",t,": ")+n+v("(",h(i,", "),")"),h(r," "),o]," ")},Argument:function(e){return e.name+": "+e.value},FragmentSpread:function(e){return"..."+e.name+v(" ",h(e.directives," "))},InlineFragment:function(e){var t=e.typeCondition,n=e.directives,i=e.selectionSet;return h(["...",v("on ",t),h(n," "),i]," ")},FragmentDefinition:function(e){var t=e.name,n=e.typeCondition,i=e.variableDefinitions,r=e.directives,o=e.selectionSet;return("fragment ".concat(t).concat(v("(",h(i,", "),")")," ")+"on ".concat(n," ").concat(v("",h(r," ")," "))+o)},IntValue:function(e){return e.value},FloatValue:function(e){return e.value},StringValue:function(e,t){var n=e.value;return e.block?function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=-1===e.indexOf("\n"),r=" "===e[0]||"\t"===e[0],o='"'===e[e.length-1],s=!i||o||n,a="";return!s||i&&r||(a+="\n"+t),a+=t?e.replace(/\n/g,"\n"+t):e,s&&(a+="\n"),'"""'+a.replace(/"""/g,'\\"""')+'"""'}(n,"description"===t?"":" "):JSON.stringify(n)},BooleanValue:function(e){return e.value?"true":"false"},NullValue:function(){return"null"},EnumValue:function(e){return e.value},ListValue:function(e){return"["+h(e.values,", ")+"]"},ObjectValue:function(e){return"{"+h(e.fields,", ")+"}"},ObjectField:function(e){return e.name+": "+e.value},Directive:function(e){return"@"+e.name+v("(",h(e.arguments,", "),")")},NamedType:function(e){return e.name},ListType:function(e){return"["+e.type+"]"},NonNullType:function(e){return e.type+"!"},SchemaDefinition:function(e){var t=e.directives,n=e.operationTypes;return h(["schema",h(t," "),y(n)]," ")},OperationTypeDefinition:function(e){return e.operation+": "+e.type},ScalarTypeDefinition:m((function(e){return h(["scalar",e.name,h(e.directives," ")]," ")})),ObjectTypeDefinition:m((function(e){var t=e.name,n=e.interfaces,i=e.directives,r=e.fields;return h(["type",t,v("implements ",h(n," & ")),h(i," "),y(r)]," ")})),FieldDefinition:m((function(e){var t=e.name,n=e.arguments,i=e.type,r=e.directives;return t+(E(n)?v("(\n",b(h(n,"\n")),"\n)"):v("(",h(n,", "),")"))+": "+i+v(" ",h(r," "))})),InputValueDefinition:m((function(e){var t=e.name,n=e.type,i=e.defaultValue,r=e.directives;return h([t+": "+n,v("= ",i),h(r," ")]," ")})),InterfaceTypeDefinition:m((function(e){var t=e.name,n=e.directives,i=e.fields;return h(["interface",t,h(n," "),y(i)]," ")})),UnionTypeDefinition:m((function(e){var t=e.name,n=e.directives,i=e.types;return h(["union",t,h(n," "),i&&0!==i.length?"= "+h(i," | "):""]," ")})),EnumTypeDefinition:m((function(e){var t=e.name,n=e.directives,i=e.values;return h(["enum",t,h(n," "),y(i)]," ")})),EnumValueDefinition:m((function(e){return h([e.name,h(e.directives," ")]," ")})),InputObjectTypeDefinition:m((function(e){var t=e.name,n=e.directives,i=e.fields;return h(["input",t,h(n," "),y(i)]," ")})),DirectiveDefinition:m((function(e){var t=e.name,n=e.arguments,i=e.repeatable,r=e.locations;return"directive @"+t+(E(n)?v("(\n",b(h(n,"\n")),"\n)"):v("(",h(n,", "),")"))+(i?" repeatable":"")+" on "+h(r," | ")})),SchemaExtension:function(e){var t=e.directives,n=e.operationTypes;return h(["extend schema",h(t," "),y(n)]," ")},ScalarTypeExtension:function(e){return h(["extend scalar",e.name,h(e.directives," ")]," ")},ObjectTypeExtension:function(e){var t=e.name,n=e.interfaces,i=e.directives,r=e.fields;return h(["extend type",t,v("implements ",h(n," & ")),h(i," "),y(r)]," ")},InterfaceTypeExtension:function(e){var t=e.name,n=e.directives,i=e.fields;return h(["extend interface",t,h(n," "),y(i)]," ")},UnionTypeExtension:function(e){var t=e.name,n=e.directives,i=e.types;return h(["extend union",t,h(n," "),i&&0!==i.length?"= "+h(i," | "):""]," ")},EnumTypeExtension:function(e){var t=e.name,n=e.directives,i=e.values;return h(["extend enum",t,h(n," "),y(i)]," ")},InputObjectTypeExtension:function(e){var t=e.name,n=e.directives,i=e.fields;return h(["extend input",t,h(n," "),y(i)]," ")}};function m(e){return function(t){return h([t.description,e(t)],"\n")}}function h(e,t){return e?e.filter((function(e){return e})).join(t||""):""}function y(e){return e&&0!==e.length?"{\n"+b(h(e,"\n"))+"\n}":""}function v(e,t,n){return t?e+t+(n||""):""}function b(e){return e&&" "+e.replace(/\n/g,"\n ")}function T(e){return-1!==e.indexOf("\n")}function E(e){return e&&e.some(T)}},function(e,t,n){"use strict";n.r(t);var i=Object.freeze({NAME:"Name",DOCUMENT:"Document",OPERATION_DEFINITION:"OperationDefinition",VARIABLE_DEFINITION:"VariableDefinition",SELECTION_SET:"SelectionSet",FIELD:"Field",ARGUMENT:"Argument",FRAGMENT_SPREAD:"FragmentSpread",INLINE_FRAGMENT:"InlineFragment",FRAGMENT_DEFINITION:"FragmentDefinition",VARIABLE:"Variable",INT:"IntValue",FLOAT:"FloatValue",STRING:"StringValue",BOOLEAN:"BooleanValue",NULL:"NullValue",ENUM:"EnumValue",LIST:"ListValue",OBJECT:"ObjectValue",OBJECT_FIELD:"ObjectField",DIRECTIVE:"Directive",NAMED_TYPE:"NamedType",LIST_TYPE:"ListType",NON_NULL_TYPE:"NonNullType",SCHEMA_DEFINITION:"SchemaDefinition",OPERATION_TYPE_DEFINITION:"OperationTypeDefinition",SCALAR_TYPE_DEFINITION:"ScalarTypeDefinition",OBJECT_TYPE_DEFINITION:"ObjectTypeDefinition",FIELD_DEFINITION:"FieldDefinition",INPUT_VALUE_DEFINITION:"InputValueDefinition",INTERFACE_TYPE_DEFINITION:"InterfaceTypeDefinition",UNION_TYPE_DEFINITION:"UnionTypeDefinition",ENUM_TYPE_DEFINITION:"EnumTypeDefinition",ENUM_VALUE_DEFINITION:"EnumValueDefinition",INPUT_OBJECT_TYPE_DEFINITION:"InputObjectTypeDefinition",DIRECTIVE_DEFINITION:"DirectiveDefinition",SCHEMA_EXTENSION:"SchemaExtension",SCALAR_TYPE_EXTENSION:"ScalarTypeExtension",OBJECT_TYPE_EXTENSION:"ObjectTypeExtension",INTERFACE_TYPE_EXTENSION:"InterfaceTypeExtension",UNION_TYPE_EXTENSION:"UnionTypeExtension",ENUM_TYPE_EXTENSION:"EnumTypeExtension",INPUT_OBJECT_TYPE_EXTENSION:"InputObjectTypeExtension"});function r(e,t){for(var n=null,r=0,o=e.definitions;r<o.length;r++){var s=o[r];if(s.kind===i.OPERATION_DEFINITION)if(t){if(s.name&&s.name.value===t)return s}else{if(n)return null;n=s}}return n}n.d(t,"getOperationAST",(function(){return r}))}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment