ruru
Version:
Grafast-flavoured GraphiQL distribution
2 lines • 9.59 kB
JavaScript
export const __webpack_id__=7226;export const __webpack_ids__=[7226];export const __webpack_modules__={17226:(e,t,o)=>{function r(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function n(e){return"object"===r(e)}function i(e,t){return e.length<124?e:t}o.d(t,{createClient:()=>d});const a="graphql-transport-ws";var s=(e=>(e[e.InternalServerError=4500]="InternalServerError",e[e.InternalClientError=4005]="InternalClientError",e[e.BadRequest=4400]="BadRequest",e[e.BadResponse=4004]="BadResponse",e[e.Unauthorized=4401]="Unauthorized",e[e.Forbidden=4403]="Forbidden",e[e.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",e[e.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",e[e.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",e[e.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",e[e.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e))(s||{}),c=(e=>(e.ConnectionInit="connection_init",e.ConnectionAck="connection_ack",e.Ping="ping",e.Pong="pong",e.Subscribe="subscribe",e.Next="next",e.Error="error",e.Complete="complete",e))(c||{});function p(e){if(!n(e))throw new Error(`Message is expected to be an object, but got ${r(e)}`);if(!e.type)throw new Error("Message is missing the 'type' property");if("string"!=typeof e.type)throw new Error(`Message is expects the 'type' property to be a string, but got ${r(e.type)}`);switch(e.type){case"connection_init":case"connection_ack":case"ping":case"pong":if(null!=e.payload&&!n(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${e.payload}"`);break;case"subscribe":if("string"!=typeof e.id)throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${r(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!n(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${r(e.payload)}`);if("string"!=typeof e.payload.query)throw new Error(`"${e.type}" message payload expects the 'query' property to be a string, but got ${r(e.payload.query)}`);if(null!=e.payload.variables&&!n(e.payload.variables))throw new Error(`"${e.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${r(e.payload.variables)}`);if(null!=e.payload.operationName&&"string"!==r(e.payload.operationName))throw new Error(`"${e.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${r(e.payload.operationName)}`);if(null!=e.payload.extensions&&!n(e.payload.extensions))throw new Error(`"${e.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${r(e.payload.extensions)}`);break;case"next":if("string"!=typeof e.id)throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${r(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!n(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${r(e.payload)}`);break;case"error":if("string"!=typeof e.id)throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${r(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(t=e.payload,!(Array.isArray(t)&&t.length>0&&t.every(e=>"message"in e)))throw new Error(`"${e.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(e.payload)}`);break;case"complete":if("string"!=typeof e.id)throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${r(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);break;default:throw new Error(`Invalid message 'type' property "${e.type}"`)}var t;return e}function l(e,t){return p(e),JSON.stringify(e,t)}function d(e){const{url:t,connectionParams:o,lazy:r=!0,onNonLazyError:n=console.error,lazyCloseTimeout:d=0,keepAlive:g=0,disablePong:m,connectionAckWaitTimeout:f=0,retryAttempts:w=5,retryWait:b=async function(e){const t=Math.pow(2,e);await new Promise(e=>setTimeout(e,1e3*t+Math.floor(2700*Math.random()+300)))},shouldRetry:h=u,on:x,webSocketImpl:E,generateID:S=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},jsonMessageReplacer:v,jsonMessageReviver:$}=e;let k;if(E){if(!("function"==typeof(C=E)&&"constructor"in C&&"CLOSED"in C&&"CLOSING"in C&&"CONNECTING"in C&&"OPEN"in C))throw new Error("Invalid WebSocket implementation provided");k=E}else"undefined"!=typeof WebSocket?k=WebSocket:"undefined"!=typeof global?k=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(k=window.WebSocket||window.MozWebSocket);var C;if(!k)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const N=k,I=(()=>{const e=(()=>{const e={};return{on:(t,o)=>(e[t]=o,()=>{delete e[t]}),emit(t){"id"in t&&e[t.id]?.(t)}}})(),t={connecting:x?.connecting?[x.connecting]:[],opened:x?.opened?[x.opened]:[],connected:x?.connected?[x.connected]:[],ping:x?.ping?[x.ping]:[],pong:x?.pong?[x.pong]:[],message:x?.message?[e.emit,x.message]:[e.emit],closed:x?.closed?[x.closed]:[],error:x?.error?[x.error]:[]};return{onMessage:e.on,on(e,o){const r=t[e];return r.push(o),()=>{r.splice(r.indexOf(o),1)}},emit(e,...o){for(const r of[...t[e]])r(...o)}}})();function T(e){const t=[I.on("error",o=>{t.forEach(e=>e()),e(o)}),I.on("closed",o=>{t.forEach(e=>e()),e(o)})]}let A,_,P=0,M=!1,q=0,O=!1;async function R(){clearTimeout(_);const[e,r]=await(A??(A=new Promise((e,r)=>(async()=>{if(M){if(await b(q),!P)return A=void 0,r({code:1e3,reason:"All Subscriptions Gone"});q++}I.emit("connecting",M);const n=new N("function"==typeof t?await t():t,a);let d,u;function w(){isFinite(g)&&g>0&&(clearTimeout(u),u=setTimeout(()=>{n.readyState===N.OPEN&&(n.send(l({type:c.Ping})),I.emit("ping",!1,void 0))},g))}T(e=>{A=void 0,clearTimeout(d),clearTimeout(u),r(e),e instanceof y&&(n.close(4499,"Terminated"),n.onerror=null,n.onclose=null)}),n.onerror=e=>I.emit("error",e),n.onclose=e=>I.emit("closed",e),n.onopen=async()=>{try{I.emit("opened",n);const e="function"==typeof o?await o():o;if(n.readyState!==N.OPEN)return;n.send(l(e?{type:c.ConnectionInit,payload:e}:{type:c.ConnectionInit},v)),isFinite(f)&&f>0&&(d=setTimeout(()=>{n.close(s.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},f)),w()}catch(e){I.emit("error",e),n.close(s.InternalClientError,i(e instanceof Error?e.message:String(e),"Internal client error"))}};let h=!1;n.onmessage=({data:t})=>{try{const o=function(e,t){return p("string"==typeof e?JSON.parse(e,t):e)}(t,$);if(I.emit("message",o),"ping"===o.type||"pong"===o.type)return I.emit(o.type,!0,o.payload),void("pong"===o.type?w():m||(n.send(l(o.payload?{type:c.Pong,payload:o.payload}:{type:c.Pong})),I.emit("pong",!1,o.payload)));if(h)return;if(o.type!==c.ConnectionAck)throw new Error(`First message cannot be of type ${o.type}`);clearTimeout(d),h=!0,I.emit("connected",n,o.payload,M),M=!1,q=0,e([n,new Promise((e,t)=>T(t))])}catch(e){n.onmessage=null,I.emit("error",e),n.close(s.BadResponse,i(e instanceof Error?e.message:String(e),"Bad response"))}}})())));e.readyState===N.CLOSING&&await r;let n=()=>{};const u=new Promise(e=>n=e);return[e,n,Promise.race([u.then(()=>{if(!P){const t=()=>e.close(1e3,"Normal Closure");isFinite(d)&&d>0?_=setTimeout(()=>{e.readyState===N.OPEN&&t()},d):t()}}),r])]}function W(e){if(u(e)&&(t=e.code,![1e3,1001,1006,1005,1012,1013,1014].includes(t)&&t>=1e3&&t<=1999||[s.InternalServerError,s.InternalClientError,s.BadRequest,s.BadResponse,s.Unauthorized,s.SubprotocolNotAcceptable,s.SubscriberAlreadyExists,s.TooManyInitialisationRequests].includes(e.code)))throw e;var t;if(O)return!1;if(u(e)&&1e3===e.code)return P>0;if(!w||q>=w)throw e;if(!h(e))throw e;return M=!0}function j(e,t){const o=S(e);let r=!1,n=!1,i=()=>{P--,r=!0};return(async()=>{for(P++;;)try{const[a,s,p]=await R();if(r)return s();const d=I.onMessage(o,e=>{switch(e.type){case c.Next:return void t.next(e.payload);case c.Error:return n=!0,r=!0,t.error(e.payload),void i();case c.Complete:return r=!0,void i()}});return a.send(l({id:o,type:c.Subscribe,payload:e},v)),i=()=>{r||a.readyState!==N.OPEN||a.send(l({id:o,type:c.Complete},v)),P--,r=!0,s()},void await p.finally(d)}catch(e){if(!W(e))return}})().then(()=>{n||t.complete()}).catch(e=>{t.error(e)}),()=>{r||i()}}return r||(async()=>{for(P++;;)try{const[,,e]=await R();await e}catch(e){try{if(!W(e))return}catch(e){return n?.(e)}}})(),{on:I.on,subscribe:j,iterate(e){const t=[],o={done:!1,error:null,resolve:()=>{}},r=j(e,{next(e){t.push(e),o.resolve()},error(e){o.done=!0,o.error=e,o.resolve()},complete(){o.done=!0,o.resolve()}}),n=async function*(){for(;;){for(t.length||await new Promise(e=>o.resolve=e);t.length;)yield t.shift();if(o.error)throw o.error;if(o.done)return}}();return n.throw=async e=>(o.done||(o.done=!0,o.error=e,o.resolve()),{done:!0,value:void 0}),n.return=async()=>(r(),{done:!0,value:void 0}),n},async dispose(){if(O=!0,A){const[e]=await A;e.close(1e3,"Normal Closure")}},terminate(){A&&I.emit("closed",new y)}}}class y extends Error{name="TerminatedCloseEvent";message="4499: Terminated";code=4499;reason="Terminated";wasClean=!1}function u(e){return n(e)&&"code"in e&&"reason"in e}}};
//# sourceMappingURL=7226.js.map