@chillicream/nitro-embedded
Version:
Nitro GraphQL IDE
1 lines • 13.6 kB
JavaScript
"use strict";(self.webpackChunknitro=self.webpackChunknitro||[]).push([[282],{85890:(e,t,n)=>{n.d(t,{YR:()=>r,sP:()=>o});n(93967),n(36022),n(54913),n(75885);var i=n(96243),s=n(13295);const o=Object.freeze({});function r(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:i.hd;const r=new Map;for(const s of Object.values(i.xs))r.set(s,a(t,s));let c,l,h,u=Array.isArray(e),d=[e],m=-1,p=[],y=e;const v=[],g=[];do{m++;const e=m===d.length,i=e&&0!==p.length;if(e){if(l=0===g.length?void 0:v[v.length-1],y=h,h=g.pop(),i)if(u){y=y.slice();let e=0;for(const[t,n]of p){const i=t-e;null===n?(y.splice(i,1),e++):y[i]=n}}else{y=Object.defineProperties({},Object.getOwnPropertyDescriptors(y));for(const[e,t]of p)y[e]=t}m=c.index,d=c.keys,p=c.edits,u=c.inArray,c=c.prev}else if(null!=h){if(l=u?m:d[m],y=h[l],null===y||void 0===y)continue;v.push(l)}let a;if(!Array.isArray(y)){var f,T;const n=e?null===(f=r.get(y.kind))||void 0===f?void 0:f.leave:null===(T=r.get(y.kind))||void 0===T?void 0:T.enter;if(a=null===n||void 0===n?void 0:n.call(t,y,l,h,v,g),a===o)break;if(!1===a){if(!e){v.pop();continue}}else if(void 0!==a&&(p.push([l,a]),!e)){if(!(0,s.VJ)(a)){v.pop();continue}y=a}}var b;if(void 0===a&&i&&p.push([l,y]),e)v.pop();else c={inArray:u,index:m,keys:d,edits:p,prev:c},u=Array.isArray(y),d=u?y:null!==(b=n[y.kind])&&void 0!==b?b:[],m=-1,p=[],null!=h&&g.push(h),h=y}while(void 0!==c);return 0!==p.length?p.at(-1)[1]:e}function a(e,t){const n=e[t];return"object"===typeof n?n:"function"===typeof n?{enter:n,leave:void 0}:{enter:e.enter,leave:e.leave}}},41990:(e,t,n)=>{n.r(t),n.d(t,{default:()=>s});const i=function(){var e=[{defaultValue:null,kind:"LocalArgument",name:"stageId"}],t=[{kind:"Variable",name:"id",variableName:"stageId"}],n={alias:null,args:null,kind:"ScalarField",name:"downloadUrl",storageKey:null},i={alias:null,args:null,kind:"ScalarField",name:"tag",storageKey:null},s={alias:null,args:null,kind:"ScalarField",name:"id",storageKey:null};return{fragment:{argumentDefinitions:e,kind:"Fragment",metadata:null,name:"schemaApiFetcherTaskQuery",selections:[{alias:null,args:t,concreteType:"Stage",kind:"LinkedField",name:"stageById",plural:!1,selections:[{alias:null,args:null,concreteType:"PublishedSchemaVersion",kind:"LinkedField",name:"publishedSchema",plural:!1,selections:[{alias:null,args:null,concreteType:"SchemaVersion",kind:"LinkedField",name:"version",plural:!1,selections:[n,i],storageKey:null}],storageKey:null}],storageKey:null}],type:"Query",abstractKey:null},kind:"Request",operation:{argumentDefinitions:e,kind:"Operation",name:"schemaApiFetcherTaskQuery",selections:[{alias:null,args:t,concreteType:"Stage",kind:"LinkedField",name:"stageById",plural:!1,selections:[{alias:null,args:null,concreteType:"PublishedSchemaVersion",kind:"LinkedField",name:"publishedSchema",plural:!1,selections:[{alias:null,args:null,concreteType:"SchemaVersion",kind:"LinkedField",name:"version",plural:!1,selections:[n,i,s],storageKey:null}],storageKey:null},s],storageKey:null}]},params:{id:"8cddc0556879bf1f147b06775d33b192",metadata:{},name:"schemaApiFetcherTaskQuery",operationKind:"query",text:null}}}();i.hash="1359c500cfecb2578c682124e7dad7ec";const s=i},1103:(e,t,n)=>{n.d(t,{D:()=>g});n(62316),n(36022),n(75885);var i=n(28511),s=n(64293),o=n.n(s),r=n(75438),a=n(70807),c=n(19740),l=n(58819),h=n(69278),u=n(30325),d=n(32691),m=n(87357),p=n(65292);const y="undefined"!==typeof n.g?n.g:"undefined"!==typeof window?window:{},v=y.WebSocket||y.MozWebSocket;class g{constructor(e,t,n,i){this.client=void 0,this.operations=void 0,this.url=void 0,this.nextOperationId=void 0,this.connectionParams=void 0,this.minWsTimeout=void 0,this.wsTimeout=void 0,this.unsentMessagesQueue=void 0,this.reconnect=void 0,this.reconnecting=void 0,this.reconnectionAttempts=void 0,this.backoff=void 0,this.connectionCallback=void 0,this.eventEmitter=void 0,this.lazy=void 0,this.inactivityTimeout=void 0,this.inactivityTimeoutId=void 0,this.closedByUser=void 0,this.wsImpl=void 0,this.wsProtocols=void 0,this.wasKeepAliveReceived=void 0,this.tryReconnectTimeoutId=void 0,this.checkConnectionIntervalId=void 0,this.maxConnectTimeoutId=void 0,this.middlewares=void 0,this.maxConnectTimeGenerator=void 0,this.wsOptionArguments=void 0,this.wsOnMessage=void 0;const{connectionCallback:s,connectionParams:a={},minTimeout:c=l.OL,timeout:h=l.nI,reconnect:d=!1,reconnectionAttempts:m=1/0,lazy:p=!1,inactivityTimeout:y=0,wsOptionArguments:g=[],onMessage:f}=t||{};if(this.wsOnMessage=f,this.wsImpl=n||v,!this.wsImpl)throw new Error("Unable to find native implementation, or alternative implementation for WebSocket!");this.wsProtocols=i||u.BS,this.connectionCallback=s,this.url=e,this.operations={},this.nextOperationId=0,this.minWsTimeout=c,this.wsTimeout=h,this.unsentMessagesQueue=[],this.reconnect=d,this.reconnecting=!1,this.reconnectionAttempts=m,this.lazy=!!p,this.inactivityTimeout=y,this.closedByUser=!1,this.backoff=new(o())({jitter:.5}),this.eventEmitter=new r.EventEmitter,this.middlewares=[],this.client=null,this.maxConnectTimeGenerator=this.createMaxConnectTimeGenerator(),this.connectionParams=this.getConnectionParams(a),this.wsOptionArguments=g,this.lazy||this.connect()}get status(){return null===this.client?this.wsImpl.CLOSED:this.client.readyState}close(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];this.clearInactivityTimeout(),null!==this.client&&(this.closedByUser=t,e&&(this.clearCheckConnectionInterval(),this.clearMaxConnectTimeout(),this.clearTryReconnectTimeout(),this.unsubscribeAll(),this.sendMessage(void 0,h.A.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())}request(e){const t=this.getObserver.bind(this),n=this.executeOperation.bind(this),i=this.unsubscribe.bind(this);let s=null;return this.clearInactivityTimeout(),{[p.A](){return this},subscribe(o,r,a){const c=t(o,r,a);return s=n(e,((e,t)=>{null===e&&null===t?c.complete&&c.complete():e?c.error&&c.error(e[0]):c.next&&c.next(t)})),{unsubscribe:()=>{s&&(i(s),s=null)}}}}}on(e,t,n){const i=this.eventEmitter.on(e,t,n);return()=>{i.off(e,t,n)}}onConnected(e,t){return this.on("connected",e,t)}onConnecting(e,t){return this.on("connecting",e,t)}onDisconnected(e,t){return this.on("disconnected",e,t)}onReconnected(e,t){return this.on("reconnected",e,t)}onReconnecting(e,t){return this.on("reconnecting",e,t)}onError(e,t){return this.on("error",e,t)}unsubscribeAll(){Object.keys(this.operations).forEach((e=>{this.unsubscribe(e)}))}applyMiddlewares(e){return new Promise(((t,n)=>{((i,s)=>{const o=r=>{if(r)n(r);else if(i.length>0){const t=i.shift();t&&t.applyMiddleware.apply(s,[e,o])}else t(e)};o()})([...this.middlewares],this)}))}use(e){return e.forEach((e=>{if(!(0,i.Tn)(e.applyMiddleware))throw new Error("Middleware must implement the applyMiddleware function.");this.middlewares.push(e)})),this}getConnectionParams(e){return()=>new Promise(((t,n)=>{if((0,i.Tn)(e))try{return t(e.call(null))}catch(s){return n(s)}t(e)}))}executeOperation(e,t){null===this.client&&this.connect();const n=this.generateOperationId();return this.operations[n]={options:e,handler:t},this.applyMiddlewares(e).then((e=>{this.checkOperationOptions(e,t),this.operations[n]&&(this.operations[n]={options:e,handler:t},this.sendMessage(n,h.A.GQL_START,e))})).catch((e=>{this.unsubscribe(n),t(this.formatErrors(e))})),n}getObserver(e,t,n){return(0,i.Tn)(e)?{next:t=>e(t),error:e=>t&&t(e),complete:()=>n&&n()}:e}createMaxConnectTimeGenerator(){const e=this.minWsTimeout,t=this.wsTimeout;return new(o())({min:e,max:t,factor:1.2})}clearCheckConnectionInterval(){this.checkConnectionIntervalId&&(clearInterval(this.checkConnectionIntervalId),this.checkConnectionIntervalId=null)}clearMaxConnectTimeout(){this.maxConnectTimeoutId&&(clearTimeout(this.maxConnectTimeoutId),this.maxConnectTimeoutId=null)}clearTryReconnectTimeout(){this.tryReconnectTimeoutId&&(clearTimeout(this.tryReconnectTimeoutId),this.tryReconnectTimeoutId=null)}clearInactivityTimeout(){this.inactivityTimeoutId&&(clearTimeout(this.inactivityTimeoutId),this.inactivityTimeoutId=null)}setInactivityTimeout(){this.inactivityTimeout>0&&0===Object.keys(this.operations).length&&(this.inactivityTimeoutId=setTimeout((()=>{0===Object.keys(this.operations).length&&this.close()}),this.inactivityTimeout))}checkOperationOptions(e,t){const{query:n,variables:i,operationName:s}=e;if(!n)throw new Error("Must provide a query.");if(!t)throw new Error("Must provide an handler.");if(!(0,m.A)(n)&&!(0,c.A)(n,s)||s&&!(0,m.A)(s)||i&&!(0,d.A)(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.")}buildMessage(e,t,n){return{id:e,type:t,payload:n&&n.query?{...n,query:"string"===typeof n.query?n.query:(0,a.y)(n.query)}:n}}formatErrors(e){return Array.isArray(e)?e:e&&e.errors?this.formatErrors(e.errors):e&&e.message?[e]:[{name:"FormattedError",message:"Unknown error",originalError:e}]}sendMessage(e,t,n){this.sendMessageRaw(this.buildMessage(e,t,n))}sendMessageRaw(e){switch(this.status){case this.wsImpl.OPEN:let n=JSON.stringify(e);try{JSON.parse(n)}catch(t){this.eventEmitter.emit("error",new Error("Message must be JSON-serializable. Got: ".concat(e)))}this.client.send(n);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)))}}generateOperationId(){return String(++this.nextOperationId)}tryReconnect(){if(!this.reconnect||this.backoff.attempts>=this.reconnectionAttempts)return;this.reconnecting||(Object.keys(this.operations).forEach((e=>{this.unsentMessagesQueue.push(this.buildMessage(e,h.A.GQL_START,this.operations[e].options))})),this.reconnecting=!0),this.clearTryReconnectTimeout();const e=this.backoff.duration();this.tryReconnectTimeoutId=setTimeout((()=>{this.connect()}),e)}flushUnsentMessagesQueue(){this.unsentMessagesQueue.forEach((e=>{this.sendMessageRaw(e)})),this.unsentMessagesQueue=[]}checkConnection(){this.wasKeepAliveReceived?this.wasKeepAliveReceived=!1:this.reconnecting||this.close(!1,!0)}checkMaxConnectTimeout(){this.clearMaxConnectTimeout(),this.maxConnectTimeoutId=setTimeout((()=>{this.status!==this.wsImpl.OPEN&&(this.reconnecting=!0,this.close(!1,!0))}),this.maxConnectTimeGenerator.duration())}connect(){this.client=new this.wsImpl(this.url,this.wsProtocols,...this.wsOptionArguments),this.checkMaxConnectTimeout(),this.client.onopen=async()=>{if(this.status===this.wsImpl.OPEN){this.clearMaxConnectTimeout(),this.closedByUser=!1,this.eventEmitter.emit(this.reconnecting?"reconnecting":"connecting");try{const e=await this.connectionParams();this.sendMessage(void 0,h.A.GQL_CONNECTION_INIT,e),this.flushUnsentMessagesQueue()}catch(e){this.sendMessage(void 0,h.A.GQL_CONNECTION_ERROR,e),this.flushUnsentMessagesQueue()}}},this.client.onclose=()=>{this.closedByUser||this.close(!1,!1)},this.client.onerror=e=>{this.eventEmitter.emit("error",e)},this.client.onmessage=e=>{var t;let{data:n}=e;null===(t=this.wsOnMessage)||void 0===t||t.call(this,n),this.processReceivedData(n)}}processReceivedData(e){let t,n;try{t=JSON.parse(e),n=t.id}catch(i){throw new Error("Message must be JSON-parseable. Got: ".concat(e))}if(-1===[h.A.GQL_DATA,h.A.GQL_COMPLETE,h.A.GQL_ERROR].indexOf(t.type)||this.operations[n])switch(t.type){case h.A.GQL_CONNECTION_ERROR:this.connectionCallback&&this.connectionCallback(t.payload);break;case h.A.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 h.A.GQL_COMPLETE:const e=this.operations[n].handler;delete this.operations[n],e.call(this,null,null);break;case h.A.GQL_ERROR:this.operations[n].handler(this.formatErrors(t.payload),null),delete this.operations[n];break;case h.A.GQL_DATA:const i=t.payload.errors?{...t.payload,errors:this.formatErrors(t.payload.errors)}:t.payload;this.operations[n].handler(null,i);break;case h.A.GQL_CONNECTION_KEEP_ALIVE:const s="undefined"===typeof this.wasKeepAliveReceived;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!")}else this.unsubscribe(n)}unsubscribe(e){this.operations[e]&&(delete this.operations[e],this.setInactivityTimeout(),this.sendMessage(e,h.A.GQL_STOP,void 0))}}},23075:(e,t,n)=>{function i(e){return"api://".concat(e)}n.d(t,{T:()=>i})},56275:(e,t,n)=>{n.d(t,{G:()=>s});var i=n(53768);function s(e){if((0,i.Tn)(e))return e;const t=Array.isArray(e)?[]:{};for(const n in e){const i=e[n];Array.isArray(i)?t[n]=s(i):null===i||"object"!==typeof i||i instanceof Boolean||i instanceof Date||i instanceof Number||i instanceof RegExp||i instanceof String||i instanceof Symbol?t[n]=i:t[n]=s(i)}return t}},75468:(e,t,n)=>{n.d(t,{c:()=>i});n(5084);function i(e){return e.replace(/\/(?=\?)|\/(?=#)|\/$/,"")}},53768:(e,t,n)=>{n.d(t,{Hf:()=>s,Td:()=>i,Tn:()=>o});const i=e=>o(Object(e)[Symbol.asyncIterator]);function s(e){return null!==e&&"object"===typeof e&&!Array.isArray(e)}function o(e){return"function"===typeof e}}}]);