ruru
Version:
Grafast-flavoured GraphiQL distribution
2 lines • 14.2 kB
JavaScript
export const __webpack_esm_id__=9399;export const __webpack_esm_ids__=[9399];export const __webpack_esm_modules__={19399(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){return n(e)&&"function"==typeof Object(e)[Symbol.asyncIterator]&&"function"==typeof e.return}function a(e,t){return e.length<124?e:t}o.d(t,{CloseCode:()=>p,DEPRECATED_GRAPHQL_WS_PROTOCOL:()=>c,GRAPHQL_TRANSPORT_WS_PROTOCOL:()=>s,MessageType:()=>l,TerminatedCloseEvent:()=>g,areGraphQLErrors:()=>k,createClient:()=>m,handleProtocols:()=>T,makeServer:()=>C,parseMessage:()=>u,stringifyMessage:()=>y,validateMessage:()=>d}),o.r(t);const s="graphql-transport-ws",c="graphql-ws";var p=(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))(p||{}),l=(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))(l||{});function d(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 u(e,t){return d("string"==typeof e?JSON.parse(e,t):e)}function y(e,t){return d(e),JSON.stringify(e,t)}function m(e){const{url:t,connectionParams:r,lazy:n=!0,onNonLazyError:i=console.error,lazyCloseTimeout:c=0,keepAlive:d=0,disablePong:m,connectionAckWaitTimeout:w=0,retryAttempts:b=5,retryWait:h=async function(e){const t=Math.pow(2,e);await new Promise(e=>setTimeout(e,1e3*t+Math.floor(2700*Math.random()+300)))},shouldRetry:x=f,on:v,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:C,jsonMessageReviver:T}=e;let k;if(E){if(!("function"==typeof(I=E)&&"constructor"in I&&"CLOSED"in I&&"CLOSING"in I&&"CONNECTING"in I&&"OPEN"in I))throw new Error("Invalid WebSocket implementation provided");k=E}else"undefined"!=typeof WebSocket?k=WebSocket:void 0!==o.g?k=o.g.WebSocket||o.g.MozWebSocket:"undefined"!=typeof window&&(k=window.WebSocket||window.MozWebSocket);var I;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,A=(()=>{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:v?.connecting?[v.connecting]:[],opened:v?.opened?[v.opened]:[],connected:v?.connected?[v.connected]:[],ping:v?.ping?[v.ping]:[],pong:v?.pong?[v.pong]:[],message:v?.message?[e.emit,v.message]:[e.emit],closed:v?.closed?[v.closed]:[],error:v?.error?[v.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 P(e){const t=[A.on("error",o=>{t.forEach(e=>e()),e(o)}),A.on("closed",o=>{t.forEach(e=>e()),e(o)})]}let $,R,_=0,O=!1,M=0,q=!1;async function j(){clearTimeout(R);const[e,o]=await($??($=new Promise((e,o)=>(async()=>{if(O){if(await h(M),!_)return $=void 0,o({code:1e3,reason:"All Subscriptions Gone"});M++}A.emit("connecting",O);const n=new N("function"==typeof t?await t():t,s);let i,c;function f(){isFinite(d)&&d>0&&(clearTimeout(c),c=setTimeout(()=>{n.readyState===N.OPEN&&(n.send(y({type:l.Ping})),A.emit("ping",!1,void 0))},d))}P(e=>{$=void 0,clearTimeout(i),clearTimeout(c),o(e),e instanceof g&&(n.close(4499,"Terminated"),n.onerror=null,n.onclose=null)}),n.onerror=e=>A.emit("error",e),n.onclose=e=>A.emit("closed",e),n.onopen=async()=>{try{A.emit("opened",n);const e="function"==typeof r?await r():r;if(n.readyState!==N.OPEN)return;n.send(y(e?{type:l.ConnectionInit,payload:e}:{type:l.ConnectionInit},C)),isFinite(w)&&w>0&&(i=setTimeout(()=>{n.close(p.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},w)),f()}catch(e){A.emit("error",e),n.close(p.InternalClientError,a(e instanceof Error?e.message:String(e),"Internal client error"))}};let b=!1;n.onmessage=({data:t})=>{try{const o=u(t,T);if(A.emit("message",o),"ping"===o.type||"pong"===o.type)return A.emit(o.type,!0,o.payload),void("pong"===o.type?f():m||(n.send(y(o.payload?{type:l.Pong,payload:o.payload}:{type:l.Pong})),A.emit("pong",!1,o.payload)));if(b)return;if(o.type!==l.ConnectionAck)throw new Error(`First message cannot be of type ${o.type}`);clearTimeout(i),b=!0,A.emit("connected",n,o.payload,O),O=!1,M=0,e([n,new Promise((e,t)=>P(t))])}catch(e){n.onmessage=null,A.emit("error",e),n.close(p.BadResponse,a(e instanceof Error?e.message:String(e),"Bad response"))}}})())));e.readyState===N.CLOSING&&await o;let n=()=>{};const i=new Promise(e=>n=e);return[e,n,Promise.race([i.then(()=>{if(!_){const t=()=>e.close(1e3,"Normal Closure");isFinite(c)&&c>0?R=setTimeout(()=>{e.readyState===N.OPEN&&t()},c):t()}}),o])]}function L(e){if(f(e)&&(t=e.code,![1e3,1001,1006,1005,1012,1013,1014].includes(t)&&t>=1e3&&t<=1999||[p.InternalServerError,p.InternalClientError,p.BadRequest,p.BadResponse,p.Unauthorized,p.SubprotocolNotAcceptable,p.SubscriberAlreadyExists,p.TooManyInitialisationRequests].includes(e.code)))throw e;var t;if(q)return!1;if(f(e)&&1e3===e.code)return _>0;if(!b||M>=b)throw e;if(!x(e))throw e;return O=!0}function W(e,t){const o=S(e);let r=!1,n=!1,i=()=>{_--,r=!0};return(async()=>{for(_++;;)try{const[a,s,c]=await j();if(r)return s();const p=A.onMessage(o,e=>{switch(e.type){case l.Next:return void t.next(e.payload);case l.Error:return n=!0,r=!0,t.error(e.payload),void i();case l.Complete:return r=!0,void i()}});return a.send(y({id:o,type:l.Subscribe,payload:e},C)),i=()=>{r||a.readyState!==N.OPEN||a.send(y({id:o,type:l.Complete},C)),_--,r=!0,s()},void await c.finally(p)}catch(e){if(!L(e))return}})().then(()=>{n||t.complete()}).catch(e=>{t.error(e)}),()=>{r||i()}}return n||(async()=>{for(_++;;)try{const[,,e]=await j();await e}catch(e){try{if(!L(e))return}catch(e){return i?.(e)}}})(),{on:A.on,subscribe:W,iterate(e){const t=[],o={done:!1,error:null,resolve:()=>{}},r=W(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(q=!0,$){const[e]=await $;e.close(1e3,"Normal Closure")}},terminate(){$&&A.emit("closed",new g)}}}class g extends Error{name="TerminatedCloseEvent";message="4499: Terminated";code=4499;reason="Terminated";wasClean=!1}function f(e){return n(e)&&"code"in e&&"reason"in e}var w=o(98195),b=o(8553),h=o(85187),x=o(48255),v=o(57552),E=o(9582),S=o(89911);function C(e){const{schema:t,context:o,roots:r,validate:a,execute:c,subscribe:d,connectionInitWaitTimeout:m=3e3,onConnect:g,onDisconnect:f,onClose:C,onSubscribe:T,onOperation:I,onNext:N,onError:A,onComplete:P,jsonMessageReviver:$,jsonMessageReplacer:R}=e;return{opened(e,_){const O={connectionInitReceived:!1,acknowledged:!1,subscriptions:{},extra:_};if(e.protocol!==s)return e.close(p.SubprotocolNotAcceptable,"Subprotocol not acceptable"),async(e,t)=>{await(C?.(O,e,t))};const M=m>0&&isFinite(m)?setTimeout(()=>{O.connectionInitReceived||e.close(p.ConnectionInitialisationTimeout,"Connection initialisation timeout")},m):null;return e.onMessage(async function(s){let m;try{m=u(s,$)}catch(t){return e.close(p.BadRequest,"Invalid message received")}switch(m.type){case l.ConnectionInit:{if(O.connectionInitReceived)return e.close(p.TooManyInitialisationRequests,"Too many initialisation requests");O.connectionInitReceived=!0,n(m.payload)&&(O.connectionParams=m.payload);const t=await(g?.(O));return!1===t?e.close(p.Forbidden,"Forbidden"):(O.acknowledged=!0,void await e.send(y(n(t)?{type:l.ConnectionAck,payload:t}:{type:l.ConnectionAck},R)))}case l.Ping:return e.onPing?await e.onPing(m.payload):void await e.send(y(m.payload?{type:l.Pong,payload:m.payload}:{type:l.Pong}));case l.Pong:return await(e.onPong?.(m.payload));case l.Subscribe:{if(!O.acknowledged)return e.close(p.Unauthorized,"Unauthorized");const{id:n,payload:s}=m;if(n in O.subscriptions)return e.close(p.SubscriberAlreadyExists,`Subscriber for ${n} already exists`);O.subscriptions[n]=null;const u={next:async(t,{id:o,payload:r},n)=>{const{errors:i,...a}=t,s=await(N?.(O,o,r,n,t));await e.send(y({id:o,type:l.Next,payload:s||{...a,...i?{errors:i.map(e=>e.toJSON())}:{}}},R))},error:async(t,{id:o,payload:r})=>{const n=await(A?.(O,o,r,t));await e.send(y({id:o,type:l.Error,payload:n||t.map(e=>e.toJSON())},R))},complete:async(t,{id:o,payload:r})=>{await(P?.(O,o,r)),t&&await e.send(y({id:o,type:l.Complete},R))}};try{let e;const p=await(T?.(O,m.id,m.payload));if(p){if(k(p))return n in O.subscriptions?await u.error(p,m):void 0;if(Array.isArray(p))throw new Error("Invalid return value from onSubscribe hook, expected an array of GraphQLError objects");e=p}else{if(!t)throw new Error("The GraphQL schema is not provided");const o={operationName:s.operationName,document:(0,w.parse)(s.query),variableValues:s.variables};e={...o,schema:"function"==typeof t?await t(O,n,s,o):t};const r=(a??b.validate)(e.schema,e.document);if(r.length>0)return n in O.subscriptions?await u.error(r,m):void 0}const l=(0,h.getOperationAST)(e.document,e.operationName);if(!l)return n in O.subscriptions?await u.error([new x.GraphQLError("Unable to identify operation")],m):void 0;let y;"rootValue"in e||(e.rootValue=r?.[l.operation]),"contextValue"in e||(e.contextValue="function"==typeof o?await o(O,n,s,e):o),y="subscription"===l.operation?await(d??v.subscribe)(e):await(c??E.execute)(e);const g=await(I?.(O,n,s,e,y));if(g&&(y=g),"function"==typeof Object(y)[Symbol.asyncIterator])if(n in O.subscriptions){O.subscriptions[n]=y;try{for await(const t of y)await u.next(t,m,e)}catch(e){const t=e instanceof Error?e:new Error(String(e));await u.error([S.versionInfo.major>=16?new x.GraphQLError(t.message,{originalError:t}):new x.GraphQLError(t.message,null,null,null,null,t)],m)}}else i(y)&&y.return(void 0);else n in O.subscriptions&&await u.next(y,m,e);await u.complete(n in O.subscriptions,m)}finally{delete O.subscriptions[n]}return}case l.Complete:{const e=O.subscriptions[m.id];return delete O.subscriptions[m.id],void(i(e)&&await e.return(void 0))}default:throw new Error(`Unexpected message of type ${m.type} received`)}}),async(e,t)=>{M&&clearTimeout(M);const o={...O.subscriptions};O.subscriptions={},await Promise.all(Object.values(o).filter(i).map(e=>e.return(void 0))),O.acknowledged&&await(f?.(O,e,t)),await(C?.(O,e,t))}}}}function T(e){switch(!0){case e instanceof Set&&e.has(s):case Array.isArray(e)&&e.includes(s):case"string"==typeof e&&e.split(",").map(e=>e.trim()).includes(s):return s;default:return!1}}function k(e){return Array.isArray(e)&&e.length>0&&e.every(e=>e instanceof x.GraphQLError)}}};
//# sourceMappingURL=9399.js.map