UNPKG

@nodefony/monitoring-bundle

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