@therms/rpc-client
Advanced tools
Comparing version
@@ -355,3 +355,3 @@ 'use strict'; | ||
} | ||
debug$3(`sendRequestWithTransport trying ${this.transports[transportsIndex].name}`, request); | ||
debug$3(`sendRequestWithTransport trying ${transports[transportsIndex].name}`, request); | ||
try { | ||
@@ -570,3 +570,3 @@ let timeout; | ||
this.name = 'WebSocketTransport'; | ||
this.type = exports.TransportType.http; | ||
this.type = exports.TransportType.websocket; | ||
this.isConnected = () => { | ||
@@ -594,4 +594,10 @@ return this.connectedToRemote && !!this.websocket; | ||
debug('sendRequest', call); | ||
let waitCount = 0; | ||
const maxWaitAttempts = 20; | ||
while (this.isWaitingForIdentityConfirmation) { | ||
debug('waiting for identity confirmation'); | ||
waitCount++; | ||
if (waitCount >= maxWaitAttempts) { | ||
throw new CallRequestTransportError('Timed out waiting for identity confirmation'); | ||
} | ||
yield sleep(100); | ||
@@ -686,3 +692,3 @@ } | ||
}; | ||
this._disconnect = (reason) => { | ||
this._disconnect = (reason) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
@@ -695,3 +701,3 @@ debug('_disconnect'); | ||
this.websocketId = undefined; | ||
}; | ||
}); | ||
this.handleServerMessage = (msg) => { | ||
@@ -715,5 +721,6 @@ this.serverMessageHandlers.forEach((handler) => { | ||
catch (e) { | ||
console.error('error parsing WS msg', e); | ||
debug('error parsing WS msg', e); | ||
return; | ||
} | ||
if ('serverMessage' in json) { | ||
if (json && 'serverMessage' in json) { | ||
this.handleServerMessage(json); | ||
@@ -736,9 +743,10 @@ return; | ||
this.resetConnection = () => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
debug('resetConnection'); | ||
this._disconnect('WebSocketTransport#resetConnection'); | ||
if (((_b = (_a = this.options.rpcOptions.transportOptions) === null || _a === void 0 ? void 0 : _a.websocket) === null || _b === void 0 ? void 0 : _b.autoConnect) !== false) { | ||
yield sleep(100); | ||
this._connect(); | ||
const wasConnected = this.isConnected(); | ||
yield this._disconnect('WebSocketTransport#resetConnection'); | ||
if (wasConnected) { | ||
yield sleep(300); | ||
yield this._connect(); | ||
} | ||
return this.isConnected(); | ||
}); | ||
@@ -748,5 +756,11 @@ this.sendCall = (call, opts) => __awaiter(this, void 0, void 0, function* () { | ||
debug('sendCall', call); | ||
const correlationId = Math.random().toString(); | ||
const correlationId = `${Date.now()}-${Math.random().toString()}`; | ||
call.correlationId = call.correlationId || correlationId; | ||
let promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs); | ||
const promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs); | ||
if (!this.isConnected()) { | ||
const error = new CallRequestTransportError('Cannot send message: WebSocket is not connected'); | ||
debug('sendCall failed - websocket not connected', error); | ||
promiseWrapper.reject(error); | ||
return promiseWrapper.promise; | ||
} | ||
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(call)); | ||
@@ -753,0 +767,0 @@ this.pendingPromisesForResponse[call.correlationId] = promiseWrapper; |
@@ -353,3 +353,3 @@ import stringify from 'fast-json-stable-stringify'; | ||
} | ||
debug$3(`sendRequestWithTransport trying ${this.transports[transportsIndex].name}`, request); | ||
debug$3(`sendRequestWithTransport trying ${transports[transportsIndex].name}`, request); | ||
try { | ||
@@ -568,3 +568,3 @@ let timeout; | ||
this.name = 'WebSocketTransport'; | ||
this.type = TransportType.http; | ||
this.type = TransportType.websocket; | ||
this.isConnected = () => { | ||
@@ -592,4 +592,10 @@ return this.connectedToRemote && !!this.websocket; | ||
debug('sendRequest', call); | ||
let waitCount = 0; | ||
const maxWaitAttempts = 20; | ||
while (this.isWaitingForIdentityConfirmation) { | ||
debug('waiting for identity confirmation'); | ||
waitCount++; | ||
if (waitCount >= maxWaitAttempts) { | ||
throw new CallRequestTransportError('Timed out waiting for identity confirmation'); | ||
} | ||
yield sleep(100); | ||
@@ -684,3 +690,3 @@ } | ||
}; | ||
this._disconnect = (reason) => { | ||
this._disconnect = (reason) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
@@ -693,3 +699,3 @@ debug('_disconnect'); | ||
this.websocketId = undefined; | ||
}; | ||
}); | ||
this.handleServerMessage = (msg) => { | ||
@@ -713,5 +719,6 @@ this.serverMessageHandlers.forEach((handler) => { | ||
catch (e) { | ||
console.error('error parsing WS msg', e); | ||
debug('error parsing WS msg', e); | ||
return; | ||
} | ||
if ('serverMessage' in json) { | ||
if (json && 'serverMessage' in json) { | ||
this.handleServerMessage(json); | ||
@@ -734,9 +741,10 @@ return; | ||
this.resetConnection = () => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
debug('resetConnection'); | ||
this._disconnect('WebSocketTransport#resetConnection'); | ||
if (((_b = (_a = this.options.rpcOptions.transportOptions) === null || _a === void 0 ? void 0 : _a.websocket) === null || _b === void 0 ? void 0 : _b.autoConnect) !== false) { | ||
yield sleep(100); | ||
this._connect(); | ||
const wasConnected = this.isConnected(); | ||
yield this._disconnect('WebSocketTransport#resetConnection'); | ||
if (wasConnected) { | ||
yield sleep(300); | ||
yield this._connect(); | ||
} | ||
return this.isConnected(); | ||
}); | ||
@@ -746,5 +754,11 @@ this.sendCall = (call, opts) => __awaiter(this, void 0, void 0, function* () { | ||
debug('sendCall', call); | ||
const correlationId = Math.random().toString(); | ||
const correlationId = `${Date.now()}-${Math.random().toString()}`; | ||
call.correlationId = call.correlationId || correlationId; | ||
let promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs); | ||
const promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs); | ||
if (!this.isConnected()) { | ||
const error = new CallRequestTransportError('Cannot send message: WebSocket is not connected'); | ||
debug('sendCall failed - websocket not connected', error); | ||
promiseWrapper.reject(error); | ||
return promiseWrapper.promise; | ||
} | ||
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(call)); | ||
@@ -751,0 +765,0 @@ this.pendingPromisesForResponse[call.correlationId] = promiseWrapper; |
@@ -24,3 +24,3 @@ import { Transport, TransportType } from './Transport'; | ||
readonly name = "WebSocketTransport"; | ||
readonly type = TransportType['http']; | ||
readonly type = TransportType['websocket']; | ||
constructor(options: WebSocketTransportOptions); | ||
@@ -27,0 +27,0 @@ isConnected: () => boolean; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RPCClient={})}(this,(function(t){"use strict";function e(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))}function s(t){var e="function"==typeof Symbol&&Symbol.iterator,s=e&&t[e],i=0;if(s)return s.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,i=t[Symbol.asyncIterator];return i?i.call(t):(t=s(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(s){e[s]=t[s]&&function(e){return new Promise((function(i,n){(function(t,e,s,i){Promise.resolve(i).then((function(e){t({value:e,done:s})}),e)})(i,n,(e=t[s](e)).done,e.value)}))}}}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(t){const{args:e,correlationId:s,identity:i,procedure:n,scope:r,version:o}=t;if(this.args=e,s&&"string"!=typeof s)throw new Error("correlationId must be a string");if(this.correlationId=s||Math.random().toString(),i){if("object"!=typeof i)throw new Error("identity must be an object");if(i.authorization&&"string"!=typeof i.authorization)throw new Error("identity.authorization must be a string");if(i.deviceName&&"string"!=typeof i.deviceName)throw new Error("identity.deviceName must be a string");if(i.metadata&&"object"!=typeof i.metadata)throw new Error("identity.metadata must be a object");this.identity=i}if(n&&"string"!=typeof n)throw new Error("procedure must be string");if(this.procedure=n,r&&"string"!=typeof r)throw new Error("scope must be string");if(this.scope=r,o&&"string"!=typeof o)throw new Error("version must be string");this.version=o}}function r(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}const o=t=>t.args?`${t.scope}${t.procedure}${t.version}${function(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});var s,i="boolean"==typeof e.cycles&&e.cycles,n=e.cmp&&(s=e.cmp,function(t){return function(e,i){var n={key:e,value:t[e]},r={key:i,value:t[i]};return s(n,r)}}),r=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0!==e){if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);var s,o;if(Array.isArray(e)){for(o="[",s=0;s<e.length;s++)s&&(o+=","),o+=t(e[s])||"null";return o+"]"}if(null===e)return"null";if(-1!==r.indexOf(e)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(e)-1,c=Object.keys(e).sort(n&&n(e));for(o="",s=0;s<c.length;s++){var h=c[s],l=t(e[h]);l&&(o&&(o+=","),o+=JSON.stringify(h)+":"+l)}return r.splice(a,1),"{"+o+"}"}}(t)}(function(t,e={}){if(!r(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:s,compare:i}=e,n=[],o=[],a=t=>{const e=n.indexOf(t);if(-1!==e)return o[e];const s=[];return n.push(t),o.push(s),s.push(...t.map((t=>Array.isArray(t)?a(t):r(t)?c(t):t))),s},c=t=>{const e=n.indexOf(t);if(-1!==e)return o[e];const h={},l=Object.keys(t).sort(i);n.push(t),o.push(h);for(const e of l){const i=t[e];let n;n=s&&Array.isArray(i)?a(i):s&&r(i)?c(i):i,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:n}))}return h};return Array.isArray(t)?s?a(t):t.slice():c(t)}(t.args||{},{deep:!0}))}`:`${t.scope}${t.procedure}${t.version}`;class a{constructor(t){const{code:e,correlationId:s,data:i,message:n,success:r}=t;if("number"!=typeof e)throw new Error("code must be a number");if(this.code=e,s&&"string"!=typeof s)throw new Error("correlationId must be a string");if(this.correlationId=s,this.data=i,n&&"string"!=typeof n)throw new Error("message must be a string");if(this.message=n,"boolean"!=typeof r)throw new Error("success must be a boolean");this.success=r}}class c extends Error{constructor(t,e,s){super(t.message),this.response={code:0,success:!1},this.name="CallResponseError";const{code:i,correlationId:n,message:r}=t;this.response.code=i,this.response.correlationId=n,this.response.data=t.data,this.response.message=`${o(e)} response error: `+(r||"RPC call failed with no message"),this.request=e,this.callOptions=s}}class h extends Error{}var l="object"==typeof global&&global&&global.Object===Object&&global,u="object"==typeof self&&self&&self.Object===Object&&self,d=l||u||Function("return this")(),p=d.Symbol,f=Object.prototype,v=f.hasOwnProperty,y=f.toString,g=p?p.toStringTag:void 0;var b=Object.prototype.toString;var m=p?p.toStringTag:void 0;function w(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?function(t){var e=v.call(t,g),s=t[g];try{t[g]=void 0;var i=!0}catch(t){}var n=y.call(t);return i&&(e?t[g]=s:delete t[g]),n}(t):function(t){return b.call(t)}(t)}function S(t){return null!=t&&"object"==typeof t}var _=Array.isArray;function T(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function C(t){return t}function j(t){if(!T(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var O,A=d["__core-js_shared__"],k=(O=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var E=Function.prototype.toString;function F(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var R=/^\[object .+?Constructor\]$/,x=Function.prototype,z=Object.prototype,M=x.toString,I=z.hasOwnProperty,L=RegExp("^"+M.call(I).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function P(t){return!(!T(t)||(e=t,k&&k in e))&&(j(t)?L:R).test(F(t));var e}function D(t,e){var s=function(t,e){return null==t?void 0:t[e]}(t,e);return P(s)?s:void 0}var W=D(d,"WeakMap"),q=Object.create,B=function(){function t(){}return function(e){if(!T(e))return{};if(q)return q(e);t.prototype=e;var s=new t;return t.prototype=void 0,s}}();function U(t,e){var s=-1,i=t.length;for(e||(e=Array(i));++s<i;)e[s]=t[s];return e}var N=Date.now;var $,H,G,J=function(){try{var t=D(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),V=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(s=e,function(){return s}),writable:!0});var s}:C,X=($=V,H=0,G=0,function(){var t=N(),e=16-(t-G);if(G=t,e>0){if(++H>=800)return arguments[0]}else H=0;return $.apply(void 0,arguments)});var K=/^(?:0|[1-9]\d*)$/;function Z(t,e){var s=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==s||"symbol"!=s&&K.test(t))&&t>-1&&t%1==0&&t<e}function Q(t,e,s){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:s,writable:!0}):t[e]=s}function Y(t,e){return t===e||t!=t&&e!=e}var tt=Object.prototype.hasOwnProperty;function et(t,e,s){var i=t[e];tt.call(t,e)&&Y(i,s)&&(void 0!==s||e in t)||Q(t,e,s)}function st(t,e,s,i){var n=!s;s||(s={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=void 0;void 0===c&&(c=t[a]),n?Q(s,a,c):et(s,a,c)}return s}var it=Math.max;function nt(t,e){return X(function(t,e,s){return e=it(void 0===e?t.length-1:e,0),function(){for(var i=arguments,n=-1,r=it(i.length-e,0),o=Array(r);++n<r;)o[n]=i[e+n];n=-1;for(var a=Array(e+1);++n<e;)a[n]=i[n];return a[e]=s(o),function(t,e,s){switch(s.length){case 0:return t.call(e);case 1:return t.call(e,s[0]);case 2:return t.call(e,s[0],s[1]);case 3:return t.call(e,s[0],s[1],s[2])}return t.apply(e,s)}(t,this,a)}}(t,e,C),t+"")}function rt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function ot(t){return null!=t&&rt(t.length)&&!j(t)}var at=Object.prototype;function ct(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||at)}function ht(t){return S(t)&&"[object Arguments]"==w(t)}var lt=Object.prototype,ut=lt.hasOwnProperty,dt=lt.propertyIsEnumerable,pt=ht(function(){return arguments}())?ht:function(t){return S(t)&&ut.call(t,"callee")&&!dt.call(t,"callee")};var ft="object"==typeof t&&t&&!t.nodeType&&t,vt=ft&&"object"==typeof module&&module&&!module.nodeType&&module,yt=vt&&vt.exports===ft?d.Buffer:void 0,gt=(yt?yt.isBuffer:void 0)||function(){return!1},bt={};function mt(t){return function(e){return t(e)}}bt["[object Float32Array]"]=bt["[object Float64Array]"]=bt["[object Int8Array]"]=bt["[object Int16Array]"]=bt["[object Int32Array]"]=bt["[object Uint8Array]"]=bt["[object Uint8ClampedArray]"]=bt["[object Uint16Array]"]=bt["[object Uint32Array]"]=!0,bt["[object Arguments]"]=bt["[object Array]"]=bt["[object ArrayBuffer]"]=bt["[object Boolean]"]=bt["[object DataView]"]=bt["[object Date]"]=bt["[object Error]"]=bt["[object Function]"]=bt["[object Map]"]=bt["[object Number]"]=bt["[object Object]"]=bt["[object RegExp]"]=bt["[object Set]"]=bt["[object String]"]=bt["[object WeakMap]"]=!1;var wt="object"==typeof t&&t&&!t.nodeType&&t,St=wt&&"object"==typeof module&&module&&!module.nodeType&&module,_t=St&&St.exports===wt&&l.process,Tt=function(){try{var t=St&&St.require&&St.require("util").types;return t||_t&&_t.binding&&_t.binding("util")}catch(t){}}(),Ct=Tt&&Tt.isTypedArray,jt=Ct?mt(Ct):function(t){return S(t)&&rt(t.length)&&!!bt[w(t)]},Ot=Object.prototype.hasOwnProperty;function At(t,e){var s=_(t),i=!s&&pt(t),n=!s&&!i&>(t),r=!s&&!i&&!n&&jt(t),o=s||i||n||r,a=o?function(t,e){for(var s=-1,i=Array(t);++s<t;)i[s]=e(s);return i}(t.length,String):[],c=a.length;for(var h in t)!e&&!Ot.call(t,h)||o&&("length"==h||n&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||Z(h,c))||a.push(h);return a}function kt(t,e){return function(s){return t(e(s))}}var Et=kt(Object.keys,Object),Ft=Object.prototype.hasOwnProperty;function Rt(t){return ot(t)?At(t):function(t){if(!ct(t))return Et(t);var e=[];for(var s in Object(t))Ft.call(t,s)&&"constructor"!=s&&e.push(s);return e}(t)}var xt=Object.prototype.hasOwnProperty;function zt(t){if(!T(t))return function(t){var e=[];if(null!=t)for(var s in Object(t))e.push(s);return e}(t);var e=ct(t),s=[];for(var i in t)("constructor"!=i||!e&&xt.call(t,i))&&s.push(i);return s}function Mt(t){return ot(t)?At(t,!0):zt(t)}var It=D(Object,"create");var Lt=Object.prototype.hasOwnProperty;var Pt=Object.prototype.hasOwnProperty;function Dt(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}function Wt(t,e){for(var s=t.length;s--;)if(Y(t[s][0],e))return s;return-1}Dt.prototype.clear=function(){this.__data__=It?It(null):{},this.size=0},Dt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Dt.prototype.get=function(t){var e=this.__data__;if(It){var s=e[t];return"__lodash_hash_undefined__"===s?void 0:s}return Lt.call(e,t)?e[t]:void 0},Dt.prototype.has=function(t){var e=this.__data__;return It?void 0!==e[t]:Pt.call(e,t)},Dt.prototype.set=function(t,e){var s=this.__data__;return this.size+=this.has(t)?0:1,s[t]=It&&void 0===e?"__lodash_hash_undefined__":e,this};var qt=Array.prototype.splice;function Bt(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}Bt.prototype.clear=function(){this.__data__=[],this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,s=Wt(e,t);return!(s<0)&&(s==e.length-1?e.pop():qt.call(e,s,1),--this.size,!0)},Bt.prototype.get=function(t){var e=this.__data__,s=Wt(e,t);return s<0?void 0:e[s][1]},Bt.prototype.has=function(t){return Wt(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var s=this.__data__,i=Wt(s,t);return i<0?(++this.size,s.push([t,e])):s[i][1]=e,this};var Ut=D(d,"Map");function Nt(t,e){var s,i,n=t.__data__;return("string"==(i=typeof(s=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==s:null===s)?n["string"==typeof e?"string":"hash"]:n.map}function $t(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}function Ht(t,e){for(var s=-1,i=e.length,n=t.length;++s<i;)t[n+s]=e[s];return t}$t.prototype.clear=function(){this.size=0,this.__data__={hash:new Dt,map:new(Ut||Bt),string:new Dt}},$t.prototype.delete=function(t){var e=Nt(this,t).delete(t);return this.size-=e?1:0,e},$t.prototype.get=function(t){return Nt(this,t).get(t)},$t.prototype.has=function(t){return Nt(this,t).has(t)},$t.prototype.set=function(t,e){var s=Nt(this,t),i=s.size;return s.set(t,e),this.size+=s.size==i?0:1,this};var Gt=kt(Object.getPrototypeOf,Object),Jt=Function.prototype,Vt=Object.prototype,Xt=Jt.toString,Kt=Vt.hasOwnProperty,Zt=Xt.call(Object);function Qt(t){var e=this.__data__=new Bt(t);this.size=e.size}Qt.prototype.clear=function(){this.__data__=new Bt,this.size=0},Qt.prototype.delete=function(t){var e=this.__data__,s=e.delete(t);return this.size=e.size,s},Qt.prototype.get=function(t){return this.__data__.get(t)},Qt.prototype.has=function(t){return this.__data__.has(t)},Qt.prototype.set=function(t,e){var s=this.__data__;if(s instanceof Bt){var i=s.__data__;if(!Ut||i.length<199)return i.push([t,e]),this.size=++s.size,this;s=this.__data__=new $t(i)}return s.set(t,e),this.size=s.size,this};var Yt="object"==typeof t&&t&&!t.nodeType&&t,te=Yt&&"object"==typeof module&&module&&!module.nodeType&&module,ee=te&&te.exports===Yt?d.Buffer:void 0,se=ee?ee.allocUnsafe:void 0;function ie(t,e){if(e)return t.slice();var s=t.length,i=se?se(s):new t.constructor(s);return t.copy(i),i}function ne(){return[]}var re=Object.prototype.propertyIsEnumerable,oe=Object.getOwnPropertySymbols,ae=oe?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var s=-1,i=null==t?0:t.length,n=0,r=[];++s<i;){var o=t[s];e(o,s,t)&&(r[n++]=o)}return r}(oe(t),(function(e){return re.call(t,e)})))}:ne;var ce=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Ht(e,ae(t)),t=Gt(t);return e}:ne;function he(t,e,s){var i=e(t);return _(t)?i:Ht(i,s(t))}function le(t){return he(t,Rt,ae)}function ue(t){return he(t,Mt,ce)}var de=D(d,"DataView"),pe=D(d,"Promise"),fe=D(d,"Set"),ve="[object Map]",ye="[object Promise]",ge="[object Set]",be="[object WeakMap]",me="[object DataView]",we=F(de),Se=F(Ut),_e=F(pe),Te=F(fe),Ce=F(W),je=w;(de&&je(new de(new ArrayBuffer(1)))!=me||Ut&&je(new Ut)!=ve||pe&&je(pe.resolve())!=ye||fe&&je(new fe)!=ge||W&&je(new W)!=be)&&(je=function(t){var e=w(t),s="[object Object]"==e?t.constructor:void 0,i=s?F(s):"";if(i)switch(i){case we:return me;case Se:return ve;case _e:return ye;case Te:return ge;case Ce:return be}return e});var Oe=Object.prototype.hasOwnProperty;var Ae=d.Uint8Array;function ke(t){var e=new t.constructor(t.byteLength);return new Ae(e).set(new Ae(t)),e}var Ee=/\w*$/;var Fe=p?p.prototype:void 0,Re=Fe?Fe.valueOf:void 0;function xe(t,e){var s=e?ke(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.length)}function ze(t,e,s){var i,n,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return ke(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var s=e?ke(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.byteLength)}(t,s);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return xe(t,s);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return(r=new(n=t).constructor(n.source,Ee.exec(n))).lastIndex=n.lastIndex,r;case"[object Symbol]":return i=t,Re?Object(Re.call(i)):{}}}function Me(t){return"function"!=typeof t.constructor||ct(t)?{}:B(Gt(t))}var Ie=Tt&&Tt.isMap,Le=Ie?mt(Ie):function(t){return S(t)&&"[object Map]"==je(t)};var Pe=Tt&&Tt.isSet,De=Pe?mt(Pe):function(t){return S(t)&&"[object Set]"==je(t)},We="[object Arguments]",qe="[object Function]",Be="[object Object]",Ue={};function Ne(t,e,s,i,n,r){var o,a=1&e,c=2&e,h=4&e;if(void 0!==o)return o;if(!T(t))return t;var l=_(t);if(l){if(o=function(t){var e=t.length,s=new t.constructor(e);return e&&"string"==typeof t[0]&&Oe.call(t,"index")&&(s.index=t.index,s.input=t.input),s}(t),!a)return U(t,o)}else{var u=je(t),d=u==qe||"[object GeneratorFunction]"==u;if(gt(t))return ie(t,a);if(u==Be||u==We||d&&!n){if(o=c||d?{}:Me(t),!a)return c?function(t,e){return st(t,ce(t),e)}(t,function(t,e){return t&&st(e,Mt(e),t)}(o,t)):function(t,e){return st(t,ae(t),e)}(t,function(t,e){return t&&st(e,Rt(e),t)}(o,t))}else{if(!Ue[u])return n?t:{};o=ze(t,u,a)}}r||(r=new Qt);var p=r.get(t);if(p)return p;r.set(t,o),De(t)?t.forEach((function(i){o.add(Ne(i,e,s,i,t,r))})):Le(t)&&t.forEach((function(i,n){o.set(n,Ne(i,e,s,n,t,r))}));var f=l?void 0:(h?c?ue:le:c?Mt:Rt)(t);return function(t,e){for(var s=-1,i=null==t?0:t.length;++s<i&&!1!==e(t[s],s,t););}(f||t,(function(i,n){f&&(i=t[n=i]),et(o,n,Ne(i,e,s,n,t,r))})),o}Ue[We]=Ue["[object Array]"]=Ue["[object ArrayBuffer]"]=Ue["[object DataView]"]=Ue["[object Boolean]"]=Ue["[object Date]"]=Ue["[object Float32Array]"]=Ue["[object Float64Array]"]=Ue["[object Int8Array]"]=Ue["[object Int16Array]"]=Ue["[object Int32Array]"]=Ue["[object Map]"]=Ue["[object Number]"]=Ue[Be]=Ue["[object RegExp]"]=Ue["[object Set]"]=Ue["[object String]"]=Ue["[object Symbol]"]=Ue["[object Uint8Array]"]=Ue["[object Uint8ClampedArray]"]=Ue["[object Uint16Array]"]=Ue["[object Uint32Array]"]=!0,Ue["[object Error]"]=Ue[qe]=Ue["[object WeakMap]"]=!1;function $e(t){return Ne(t,5)}var He=function(t,e,s){for(var i=-1,n=Object(t),r=s(t),o=r.length;o--;){var a=r[++i];if(!1===e(n[a],a,n))break}return t};function Ge(t,e,s){(void 0!==s&&!Y(t[e],s)||void 0===s&&!(e in t))&&Q(t,e,s)}function Je(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Ve(t,e,s,i,n,r,o){var a=Je(t,s),c=Je(e,s),h=o.get(c);if(h)Ge(t,s,h);else{var l,u=r?r(a,c,s+"",t,e,o):void 0,d=void 0===u;if(d){var p=_(c),f=!p&>(c),v=!p&&!f&&jt(c);u=c,p||f||v?_(a)?u=a:S(l=a)&&ot(l)?u=U(a):f?(d=!1,u=ie(c,!0)):v?(d=!1,u=xe(c,!0)):u=[]:function(t){if(!S(t)||"[object Object]"!=w(t))return!1;var e=Gt(t);if(null===e)return!0;var s=Kt.call(e,"constructor")&&e.constructor;return"function"==typeof s&&s instanceof s&&Xt.call(s)==Zt}(c)||pt(c)?(u=a,pt(a)?u=function(t){return st(t,Mt(t))}(a):T(a)&&!j(a)||(u=Me(c))):d=!1}d&&(o.set(c,u),n(u,c,i,r,o),o.delete(c)),Ge(t,s,u)}}function Xe(t,e,s,i,n){t!==e&&He(e,(function(r,o){if(n||(n=new Qt),T(r))Ve(t,e,o,s,Xe,i,n);else{var a=i?i(Je(t,o),r,o+"",t,e,n):void 0;void 0===a&&(a=r),Ge(t,o,a)}}),Mt)}var Ke,Ze=(Ke=function(t,e,s){Xe(t,e,s)},nt((function(t,e){var s=-1,i=e.length,n=i>1?e[i-1]:void 0,r=i>2?e[2]:void 0;for(n=Ke.length>3&&"function"==typeof n?(i--,n):void 0,r&&function(t,e,s){if(!T(s))return!1;var i=typeof e;return!!("number"==i?ot(s)&&Z(e,s.length):"string"==i&&e in s)&&Y(s[e],t)}(e[0],e[1],r)&&(n=i<3?void 0:n,i=1),t=Object(t);++s<i;){var o=e[s];o&&Ke(t,o,s,n)}return t})));let Qe=null;try{Qe=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const Ye=t=>Qe&&new RegExp(Qe).test(t)?(...e)=>console.log(t,...e):()=>{};class ts extends Error{}class es extends Error{}const ss=Ye("rpc:ClientManager");class is{constructor(t){this.options=t,this.inflightCallsByKey={},this.interceptors={request:[],response:[]},this.addResponseInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.response.push(t),()=>{this.interceptors.response=this.interceptors.response.filter((e=>e!==t))}},this.addRequestInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.request.push(t),()=>{this.interceptors.request=this.interceptors.request.filter((e=>e!==t))}},this.clearCache=t=>{ss("clearCache"),this.cache&&this.cache.clearCache(t)},this.getCachedResponse=t=>{var e;return ss("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(ss("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=(t,s)=>e(this,void 0,void 0,(function*(){ss("manageClientRequest",t);const i=yield this.interceptRequestMutator(t),n=o(i);if(this.inflightCallsByKey.hasOwnProperty(n))return ss("manageClientRequest using an existing in-flight call",n),this.inflightCallsByKey[n].then((e=>{const s=$e(e);return t.correlationId&&(s.correlationId=t.correlationId),s}));const r=(()=>e(this,void 0,void 0,(function*(){var t,e;const n=null===(t=this.options.transportOptions)||void 0===t?void 0:t.preferredTransport,r=null!==(e=null==s?void 0:s.transport)&&void 0!==e?e:n,o=yield this.sendRequestWithTransport(i,Object.assign(Object.assign({},s),{transport:r})),a=yield this.interceptResponseMutator(o,i);return this.cache&&a&&this.cache.setCachedResponse(i,a),a})))().finally((()=>{delete this.inflightCallsByKey[n]}));return this.inflightCallsByKey[n]=r,yield r})),this.setIdentity=t=>{ss("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){var e,s,n,r;let o=t;if(this.interceptors.request.length){ss("interceptRequestMutator(), original request:",t);try{for(var a,c=!0,h=i(this.interceptors.request);!(e=(a=yield h.next()).done);c=!0){r=a.value,c=!1;const t=r;o=yield t(o)}}catch(t){s={error:t}}finally{try{c||e||!(n=h.return)||(yield n.call(h))}finally{if(s)throw s.error}}}return o})),this.interceptResponseMutator=(t,s)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){ss("interceptResponseMutator",s,t);for(const i of this.interceptors.response)try{e=yield i(e,s)}catch(i){throw ss("caught response interceptor, request:",s,"original response:",t,"mutated response:",e),i}}return e})),this.sendRequestWithTransport=(t,s)=>e(this,void 0,void 0,(function*(){var e,i;let n;ss("sendRequestWithTransport",t);let r=0,o=this.transports;if(null==s?void 0:s.transport){const t=this.transports.find((t=>t.type===s.transport));if(!t)throw new h(`Specified Transport "${s.transport}" not available`);o=[t]}for(;!n&&o[r];){const a=o[r];if(a.isConnected()){ss(`sendRequestWithTransport trying ${this.transports[r].name}`,t);try{let e;const i=a.sendRequest(t,s||{}),r=new Promise(((i,n)=>{e=setTimeout((()=>{n(new ts(`Procedure ${t.procedure}`))}),(null==s?void 0:s.timeout)||this.options.deadlineMs)}));n=yield Promise.race([r,i]).finally((()=>{clearTimeout(e)}))}catch(s){if(null===(i=(e=this.options).onTransportRequestError)||void 0===i||i.call(e,s,o[r].type,t),!(s instanceof ts||s instanceof es))throw s;console.warn(`RPCClient ClientManager#sendRequestWithTransport() sending request with ${o[r].name} failed ${o[r+1]?`trying next transport "${o[r+1].name}"`:"no more transports to try"}`),r++}}else r++}if(!n&&!this.transports[r])throw console.error(`RPCClient ClientManager#sendRequestWithTransport() ${t.scope}::${t.procedure}::${t.version} did not get a response from any transports`),new h(`Procedure ${t.procedure} did not get a response from any transports`);if(!n)throw new h(`Procedure ${t.procedure} did not get a response from the remote`);return n})),this.cache=t.cache,t.requestInterceptor&&this.interceptors.request.push(t.requestInterceptor),t.responseInterceptor&&this.interceptors.response.push(t.responseInterceptor),this.transports=t.transports}}class ns{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}ns.DEFAULT_CACHE_MAX_AGE_MS=3e5,ns.DEFAULT_CACHE_MAX_SIZE=100;const rs="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,os=new Set,as="object"==typeof process&&process?process:{},cs=(t,e,s,i)=>{"function"==typeof as.emitWarning?as.emitWarning(t,e,s,i):console.error(`[${s}] ${e}: ${t}`)};let hs=globalThis.AbortController,ls=globalThis.AbortSignal;if(void 0===hs){ls=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},hs=class{constructor(){e()}signal=new ls;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==as.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,cs("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const us=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),ds=t=>us(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?ps:null:null;class ps extends Array{constructor(t){super(t),this.fill(0)}}class fs{heap;length;static#t=!1;static create(t){const e=ds(t);if(!e)return[];fs.#t=!0;const s=new fs(t,e);return fs.#t=!1,s}constructor(t,e){if(!fs.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class vs{#e;#s;#i;#n;#r;#o;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#a;#c;#h;#l;#u;#d;#p;#f;#v;#y;#g;#b;#m;#w;#S;#_;#T;static unsafeExposeInternals(t){return{starts:t.#m,ttls:t.#w,sizes:t.#b,keyMap:t.#h,keyList:t.#l,valList:t.#u,next:t.#d,prev:t.#p,get head(){return t.#f},get tail(){return t.#v},free:t.#y,isBackgroundFetch:e=>t.#C(e),backgroundFetch:(e,s,i,n)=>t.#j(e,s,i,n),moveToTail:e=>t.#O(e),indexes:e=>t.#A(e),rindexes:e=>t.#k(e),isStale:e=>t.#E(e)}}get max(){return this.#e}get maxSize(){return this.#s}get calculatedSize(){return this.#c}get size(){return this.#a}get fetchMethod(){return this.#r}get memoMethod(){return this.#o}get dispose(){return this.#i}get disposeAfter(){return this.#n}constructor(t){const{max:e=0,ttl:s,ttlResolution:i=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:o,allowStale:a,dispose:c,disposeAfter:h,noDisposeOnSet:l,noUpdateTTL:u,maxSize:d=0,maxEntrySize:p=0,sizeCalculation:f,fetchMethod:v,memoMethod:y,noDeleteOnFetchRejection:g,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:w,ignoreFetchAbort:S}=t;if(0!==e&&!us(e))throw new TypeError("max option must be a nonnegative integer");const _=e?ds(e):Array;if(!_)throw new Error("invalid max value: "+e);if(this.#e=e,this.#s=d,this.maxEntrySize=p||this.#s,this.sizeCalculation=f,this.sizeCalculation){if(!this.#s&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==y&&"function"!=typeof y)throw new TypeError("memoMethod must be a function if defined");if(this.#o=y,void 0!==v&&"function"!=typeof v)throw new TypeError("fetchMethod must be a function if specified");if(this.#r=v,this.#_=!!v,this.#h=new Map,this.#l=new Array(e).fill(void 0),this.#u=new Array(e).fill(void 0),this.#d=new _(e),this.#p=new _(e),this.#f=0,this.#v=0,this.#y=fs.create(e),this.#a=0,this.#c=0,"function"==typeof c&&(this.#i=c),"function"==typeof h?(this.#n=h,this.#g=[]):(this.#n=void 0,this.#g=void 0),this.#S=!!this.#i,this.#T=!!this.#n,this.noDisposeOnSet=!!l,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!g,this.allowStaleOnFetchRejection=!!m,this.allowStaleOnFetchAbort=!!w,this.ignoreFetchAbort=!!S,0!==this.maxEntrySize){if(0!==this.#s&&!us(this.#s))throw new TypeError("maxSize must be a positive integer if specified");if(!us(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#F()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=us(i)||0===i?i:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!us(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#R()}if(0===this.#e&&0===this.ttl&&0===this.#s)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#s){const t="LRU_CACHE_UNBOUNDED";if((t=>!os.has(t))(t)){os.add(t);cs("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,vs)}}}getRemainingTTL(t){return this.#h.has(t)?1/0:0}#R(){const t=new ps(this.#e),e=new ps(this.#e);this.#w=t,this.#m=e,this.#x=(s,i,n=rs.now())=>{if(e[s]=0!==i?n:0,t[s]=i,0!==i&&this.ttlAutopurge){const t=setTimeout((()=>{this.#E(s)&&this.#z(this.#l[s],"expire")}),i+1);t.unref&&t.unref()}},this.#M=s=>{e[s]=0!==t[s]?rs.now():0},this.#I=(n,r)=>{if(t[r]){const o=t[r],a=e[r];if(!o||!a)return;n.ttl=o,n.start=a,n.now=s||i();const c=n.now-a;n.remainingTTL=o-c}};let s=0;const i=()=>{const t=rs.now();if(this.ttlResolution>0){s=t;const e=setTimeout((()=>s=0),this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=n=>{const r=this.#h.get(n);if(void 0===r)return 0;const o=t[r],a=e[r];if(!o||!a)return 1/0;return o-((s||i())-a)},this.#E=n=>{const r=e[n],o=t[n];return!!o&&!!r&&(s||i())-r>o}}#M=()=>{};#I=()=>{};#x=()=>{};#E=()=>!1;#F(){const t=new ps(this.#e);this.#c=0,this.#b=t,this.#L=e=>{this.#c-=t[e],t[e]=0},this.#P=(t,e,s,i)=>{if(this.#C(e))return 0;if(!us(s)){if(!i)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof i)throw new TypeError("sizeCalculation must be a function");if(s=i(e,t),!us(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return s},this.#D=(e,s,i)=>{if(t[e]=s,this.#s){const s=this.#s-t[e];for(;this.#c>s;)this.#W(!0)}this.#c+=t[e],i&&(i.entrySize=s,i.totalCalculatedSize=this.#c)}}#L=t=>{};#D=(t,e,s)=>{};#P=(t,e,s,i)=>{if(s||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#a)for(let e=this.#v;this.#q(e)&&(!t&&this.#E(e)||(yield e),e!==this.#f);)e=this.#p[e]}*#k({allowStale:t=this.allowStale}={}){if(this.#a)for(let e=this.#f;this.#q(e)&&(!t&&this.#E(e)||(yield e),e!==this.#v);)e=this.#d[e]}#q(t){return void 0!==t&&this.#h.get(this.#l[t])===t}*entries(){for(const t of this.#A())void 0===this.#u[t]||void 0===this.#l[t]||this.#C(this.#u[t])||(yield[this.#l[t],this.#u[t]])}*rentries(){for(const t of this.#k())void 0===this.#u[t]||void 0===this.#l[t]||this.#C(this.#u[t])||(yield[this.#l[t],this.#u[t]])}*keys(){for(const t of this.#A()){const e=this.#l[t];void 0===e||this.#C(this.#u[t])||(yield e)}}*rkeys(){for(const t of this.#k()){const e=this.#l[t];void 0===e||this.#C(this.#u[t])||(yield e)}}*values(){for(const t of this.#A()){void 0===this.#u[t]||this.#C(this.#u[t])||(yield this.#u[t])}}*rvalues(){for(const t of this.#k()){void 0===this.#u[t]||this.#C(this.#u[t])||(yield this.#u[t])}}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(const s of this.#A()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;if(void 0!==n&&t(n,this.#l[s],this))return this.get(this.#l[s],e)}}forEach(t,e=this){for(const s of this.#A()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;void 0!==n&&t.call(e,n,this.#l[s],this)}}rforEach(t,e=this){for(const s of this.#k()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;void 0!==n&&t.call(e,n,this.#l[s],this)}}purgeStale(){let t=!1;for(const e of this.#k({allowStale:!0}))this.#E(e)&&(this.#z(this.#l[e],"expire"),t=!0);return t}info(t){const e=this.#h.get(t);if(void 0===e)return;const s=this.#u[e],i=this.#C(s)?s.__staleWhileFetching:s;if(void 0===i)return;const n={value:i};if(this.#w&&this.#m){const t=this.#w[e],s=this.#m[e];if(t&&s){const e=t-(rs.now()-s);n.ttl=e,n.start=Date.now()}}return this.#b&&(n.size=this.#b[e]),n}dump(){const t=[];for(const e of this.#A({allowStale:!0})){const s=this.#l[e],i=this.#u[e],n=this.#C(i)?i.__staleWhileFetching:i;if(void 0===n||void 0===s)continue;const r={value:n};if(this.#w&&this.#m){r.ttl=this.#w[e];const t=rs.now()-this.#m[e];r.start=Math.floor(Date.now()-t)}this.#b&&(r.size=this.#b[e]),t.unshift([s,r])}return t}load(t){this.clear();for(const[e,s]of t){if(s.start){const t=Date.now()-s.start;s.start=rs.now()-t}this.set(e,s.value,s)}}set(t,e,s={}){if(void 0===e)return this.delete(t),this;const{ttl:i=this.ttl,start:n,noDisposeOnSet:r=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:a}=s;let{noUpdateTTL:c=this.noUpdateTTL}=s;const h=this.#P(t,e,s.size||0,o);if(this.maxEntrySize&&h>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#z(t,"set"),this;let l=0===this.#a?void 0:this.#h.get(t);if(void 0===l)l=0===this.#a?this.#v:0!==this.#y.length?this.#y.pop():this.#a===this.#e?this.#W(!1):this.#a,this.#l[l]=t,this.#u[l]=e,this.#h.set(t,l),this.#d[this.#v]=l,this.#p[l]=this.#v,this.#v=l,this.#a++,this.#D(l,h,a),a&&(a.set="add"),c=!1;else{this.#O(l);const s=this.#u[l];if(e!==s){if(this.#_&&this.#C(s)){s.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=s;void 0===e||r||(this.#S&&this.#i?.(e,t,"set"),this.#T&&this.#g?.push([e,t,"set"]))}else r||(this.#S&&this.#i?.(s,t,"set"),this.#T&&this.#g?.push([s,t,"set"]));if(this.#L(l),this.#D(l,h,a),this.#u[l]=e,a){a.set="replace";const t=s&&this.#C(s)?s.__staleWhileFetching:s;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update")}if(0===i||this.#w||this.#R(),this.#w&&(c||this.#x(l,i,n),a&&this.#I(a,l)),!r&&this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}return this}pop(){try{for(;this.#a;){const t=this.#u[this.#f];if(this.#W(!0),this.#C(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}}}#W(t){const e=this.#f,s=this.#l[e],i=this.#u[e];return this.#_&&this.#C(i)?i.__abortController.abort(new Error("evicted")):(this.#S||this.#T)&&(this.#S&&this.#i?.(i,s,"evict"),this.#T&&this.#g?.push([i,s,"evict"])),this.#L(e),t&&(this.#l[e]=void 0,this.#u[e]=void 0,this.#y.push(e)),1===this.#a?(this.#f=this.#v=0,this.#y.length=0):this.#f=this.#d[e],this.#h.delete(s),this.#a--,e}has(t,e={}){const{updateAgeOnHas:s=this.updateAgeOnHas,status:i}=e,n=this.#h.get(t);if(void 0!==n){const t=this.#u[n];if(this.#C(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#E(n))return s&&this.#M(n),i&&(i.has="hit",this.#I(i,n)),!0;i&&(i.has="stale",this.#I(i,n))}else i&&(i.has="miss");return!1}peek(t,e={}){const{allowStale:s=this.allowStale}=e,i=this.#h.get(t);if(void 0===i||!s&&this.#E(i))return;const n=this.#u[i];return this.#C(n)?n.__staleWhileFetching:n}#j(t,e,s,i){const n=void 0===e?void 0:this.#u[e];if(this.#C(n))return n;const r=new hs,{signal:o}=s;o?.addEventListener("abort",(()=>r.abort(o.reason)),{signal:r.signal});const a={signal:r.signal,options:s,context:i},c=(i,n=!1)=>{const{aborted:o}=r.signal,c=s.ignoreFetchAbort&&void 0!==i;if(s.status&&(o&&!n?(s.status.fetchAborted=!0,s.status.fetchError=r.signal.reason,c&&(s.status.fetchAbortIgnored=!0)):s.status.fetchResolved=!0),o&&!c&&!n)return h(r.signal.reason);const u=l;return this.#u[e]===l&&(void 0===i?u.__staleWhileFetching?this.#u[e]=u.__staleWhileFetching:this.#z(t,"fetch"):(s.status&&(s.status.fetchUpdated=!0),this.set(t,i,a.options))),i},h=i=>{const{aborted:n}=r.signal,o=n&&s.allowStaleOnFetchAbort,a=o||s.allowStaleOnFetchRejection,c=a||s.noDeleteOnFetchRejection,h=l;if(this.#u[e]===l){!c||void 0===h.__staleWhileFetching?this.#z(t,"fetch"):o||(this.#u[e]=h.__staleWhileFetching)}if(a)return s.status&&void 0!==h.__staleWhileFetching&&(s.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw i};s.status&&(s.status.fetchDispatched=!0);const l=new Promise(((e,i)=>{const o=this.#r?.(t,n,a);o&&o instanceof Promise&&o.then((t=>e(void 0===t?void 0:t)),i),r.signal.addEventListener("abort",(()=>{s.ignoreFetchAbort&&!s.allowStaleOnFetchAbort||(e(void 0),s.allowStaleOnFetchAbort&&(e=t=>c(t,!0)))}))})).then(c,(t=>(s.status&&(s.status.fetchRejected=!0,s.status.fetchError=t),h(t)))),u=Object.assign(l,{__abortController:r,__staleWhileFetching:n,__returned:void 0});return void 0===e?(this.set(t,u,{...a.options,status:void 0}),e=this.#h.get(t)):this.#u[e]=u,u}#C(t){if(!this.#_)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof hs}async fetch(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:r=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:a=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:d=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:f,forceRefresh:v=!1,status:y,signal:g}=e;if(!this.#_)return y&&(y.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:n,status:y});const b={allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:n,ttl:r,noDisposeOnSet:o,size:a,sizeCalculation:c,noUpdateTTL:h,noDeleteOnFetchRejection:l,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:p,ignoreFetchAbort:d,status:y,signal:g};let m=this.#h.get(t);if(void 0===m){y&&(y.fetch="miss");const e=this.#j(t,m,b,f);return e.__returned=e}{const e=this.#u[m];if(this.#C(e)){const t=s&&void 0!==e.__staleWhileFetching;return y&&(y.fetch="inflight",t&&(y.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const n=this.#E(m);if(!v&&!n)return y&&(y.fetch="hit"),this.#O(m),i&&this.#M(m),y&&this.#I(y,m),e;const r=this.#j(t,m,b,f),o=void 0!==r.__staleWhileFetching&&s;return y&&(y.fetch=n?"stale":"refresh",o&&n&&(y.returnedStale=!0)),o?r.__staleWhileFetching:r.__returned=r}}async forceFetch(t,e={}){const s=await this.fetch(t,e);if(void 0===s)throw new Error("fetch() returned undefined");return s}memo(t,e={}){const s=this.#o;if(!s)throw new Error("no memoMethod provided to constructor");const{context:i,forceRefresh:n,...r}=e,o=this.get(t,r);if(!n&&void 0!==o)return o;const a=s(t,o,{options:r,context:i});return this.set(t,a,r),a}get(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:r}=e,o=this.#h.get(t);if(void 0!==o){const e=this.#u[o],a=this.#C(e);return r&&this.#I(r,o),this.#E(o)?(r&&(r.get="stale"),a?(r&&s&&void 0!==e.__staleWhileFetching&&(r.returnedStale=!0),s?e.__staleWhileFetching:void 0):(n||this.#z(t,"expire"),r&&s&&(r.returnedStale=!0),s?e:void 0)):(r&&(r.get="hit"),a?e.__staleWhileFetching:(this.#O(o),i&&this.#M(o),e))}r&&(r.get="miss")}#B(t,e){this.#p[e]=t,this.#d[t]=e}#O(t){t!==this.#v&&(t===this.#f?this.#f=this.#d[t]:this.#B(this.#p[t],this.#d[t]),this.#B(this.#v,t),this.#v=t)}delete(t){return this.#z(t,"delete")}#z(t,e){let s=!1;if(0!==this.#a){const i=this.#h.get(t);if(void 0!==i)if(s=!0,1===this.#a)this.#U(e);else{this.#L(i);const s=this.#u[i];if(this.#C(s)?s.__abortController.abort(new Error("deleted")):(this.#S||this.#T)&&(this.#S&&this.#i?.(s,t,e),this.#T&&this.#g?.push([s,t,e])),this.#h.delete(t),this.#l[i]=void 0,this.#u[i]=void 0,i===this.#v)this.#v=this.#p[i];else if(i===this.#f)this.#f=this.#d[i];else{const t=this.#p[i];this.#d[t]=this.#d[i];const e=this.#d[i];this.#p[e]=this.#p[i]}this.#a--,this.#y.push(i)}}if(this.#T&&this.#g?.length){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}return s}clear(){return this.#U("delete")}#U(t){for(const e of this.#k({allowStale:!0})){const s=this.#u[e];if(this.#C(s))s.__abortController.abort(new Error("deleted"));else{const i=this.#l[e];this.#S&&this.#i?.(s,i,t),this.#T&&this.#g?.push([s,i,t])}}if(this.#h.clear(),this.#u.fill(void 0),this.#l.fill(void 0),this.#w&&this.#m&&(this.#w.fill(0),this.#m.fill(0)),this.#b&&this.#b.fill(0),this.#f=0,this.#v=0,this.#y.length=0,this.#c=0,this.#a=0,this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}}}const ys=Ye("rpc:InMemoryCache");class gs{constructor(t){this.clearCache=t=>{var e,s;ys("clearCache"),t?null===(e=this.cachedResponseByParams)||void 0===e||e.delete(o(t)):null===(s=this.cachedResponseByParams)||void 0===s||s.clear()},this.getCachedResponse=t=>{var e;ys("getCachedResponse, key: ",t);let s=null===(e=this.cachedResponseByParams)||void 0===e?void 0:e.get(o(t));return"string"==typeof s&&(s=JSON.parse(s)),s},this.setCachedResponse=(t,e)=>{var s,i;ys("setCachedResponse",t,e);const n=o(t);if(!e)return null===(s=this.cachedResponseByParams)||void 0===s?void 0:s.delete(n);const r=Object.assign({},e);delete r.correlationId,null===(i=this.cachedResponseByParams)||void 0===i||i.set(n,r?JSON.stringify(r):void 0)},this.cachedResponseByParams=new vs({max:(null==t?void 0:t.cacheMaxSize)||gs.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||gs.DEFAULT_CACHE_MAX_AGE_MS})}}var bs;gs.DEFAULT_CACHE_MAX_AGE_MS=9e5,gs.DEFAULT_CACHE_MAX_SIZE=200,t.TransportType=void 0,(bs=t.TransportType||(t.TransportType={})).http="http",bs.websocket="websocket";const ms=t=>`${t.scope}::${t.procedure}::${t.version}`,ws=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}},Ss=Ye("rpc:HTTPTransport");class _s{constructor(s){this.options=s,this.name="HttpTransport",this.type=t.TransportType.http,this.isConnected=()=>{var t;return"undefined"!=typeof window?!!(null===(t=null===window||void 0===window?void 0:window.navigator)||void 0===t?void 0:t.onLine):"function"==typeof fetch},this.sendRequest=(t,s)=>e(this,void 0,void 0,(function*(){Ss("sendRequest",t);try{const e=JSON.stringify(Object.assign({identity:this.identity},t)),s=yield fetch(this.host,{body:e,cache:"default",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"follow",referrerPolicy:"origin"}),i=yield s.text();if(!i)throw new Error("No response received from remote");const n=JSON.parse(i);return new a(n)}catch(e){throw Ss("sendRequest() error",e),new es(`HTTPTransport request error ${ms(t)} (${null==e?void 0:e.message})`)}})),this.setIdentity=t=>{Ss("setIdentity",t),this.identity=t},this.host=s.host}}class Ts{constructor(t,s){this.reject=t=>{this.rejectPromise&&this.rejectPromise(t)},this.resolve=t=>{this.resolvePromise&&this.resolvePromise(t)},this.promise=new Promise(((i,n)=>e(this,void 0,void 0,(function*(){const e=setTimeout((()=>{n(new Error(`PromiseWraper timeout: ${t}`))}),s||3e4);this.rejectPromise=t=>{clearTimeout(e),n(t)},this.resolvePromise=t=>{clearTimeout(e),i(t)}}))))}}const Cs=t=>new Promise((e=>setTimeout(e,t))),js=Ye("rpc:WebSocketTransport");class Os{constructor(s){var i,n;this.options=s,this.connectedToRemote=!1,this.isWaitingForIdentityConfirmation=!1,this.pendingPromisesForResponse={},this.serverMessageHandlers=[],this.websocketId=void 0,this.name="WebSocketTransport",this.type=t.TransportType.http,this.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.connect=()=>{this._connect()},this.disconnect=()=>{this._disconnect("public disconnect() called")},this.sendClientMessageToServer=t=>{var e;let s=t;try{s=JSON.stringify({clientMessage:t})}catch(e){console.warn('WebSocketTransport.sendClientMessage() unable to stringify "msg"',t)}null===(e=this.websocket)||void 0===e||e.send(s)},this.sendRequest=(t,s)=>e(this,void 0,void 0,(function*(){for(js("sendRequest",t);this.isWaitingForIdentityConfirmation;)js("waiting for identity confirmation"),yield Cs(100);return this.sendCall(t,s)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(js("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?js('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t},{}).then((()=>{js("setIdentity with remote complete")})).catch((t=>{js("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):js("setIdentity is not connected to remote")})),this.subscribeToServerMessages=t=>(this.serverMessageHandlers.push(t),()=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))}),this.unsubscribeFromServerMessages=t=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))},this._connect=()=>{if(js("connect",this.host),this.websocket)return void js("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info(`[${(new Date).toLocaleTimeString()}] WebSocket connected`),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info(`[${(new Date).toLocaleTimeString()}] WebSocket closed`,t.reason||t.code):js("WebSocket closed, it was not connected to the remote"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,this.websocket=void 0,this.websocketId=void 0,Object.entries(this.pendingPromisesForResponse).forEach((([t,e])=>{e.reject(new es("Websocket closed"))})),t.wasClean||setTimeout((()=>{this.connect()}),1e3)},t.onerror=e=>{this.connectedToRemote?console.error("WebSocket encountered error: ",e):js("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>{var e;js("_disconnect"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,null===(e=this.websocket)||void 0===e||e.close(1e3,t),this.websocket=void 0,this.websocketId=void 0},this.handleServerMessage=t=>{this.serverMessageHandlers.forEach((e=>{try{e(t.serverMessage)}catch(s){console.warn("WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling",t,"handler func:",e),console.error(s)}}))},this.handleWebSocketMsg=t=>{let e;js("handleWebSocketMsg",t);try{e=JSON.parse(t.data)}catch(t){console.error("error parsing WS msg",t)}if("serverMessage"in e)return void this.handleServerMessage(e);const s=new a(e);if(!s.correlationId)return void console.error("RPCClient WebSocketTransport received unexpected msg from the server, not correlationId found in response.",e);const i=this.pendingPromisesForResponse[s.correlationId];i?i.resolve(s):console.warn("rcvd WS msg/response that doesn't match any pending RPC's",e)},this.resetConnection=()=>e(this,void 0,void 0,(function*(){var t,e;js("resetConnection"),this._disconnect("WebSocketTransport#resetConnection"),!1!==(null===(e=null===(t=this.options.rpcOptions.transportOptions)||void 0===t?void 0:t.websocket)||void 0===e?void 0:e.autoConnect)&&(yield Cs(100),this._connect())})),this.sendCall=(t,s)=>e(this,void 0,void 0,(function*(){var e;js("sendCall",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let n=new Ts(ms(t),s.timeout||this.options.rpcOptions.deadlineMs);return null===(e=this.websocket)||void 0===e||e.send(JSON.stringify(t)),this.pendingPromisesForResponse[t.correlationId]=n,yield n.promise.finally((()=>{delete this.pendingPromisesForResponse[t.correlationId]}))})),this.setConnectedToRemote=t=>{js(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},js("new WebSocketTransport()"),this.host=s.host,!1!==(null===(n=null===(i=s.rpcOptions.transportOptions)||void 0===i?void 0:i.websocket)||void 0===n?void 0:n.autoConnect)&&this.connect()}}class As{constructor(){this.events={},this.publish=(t,s)=>e(this,void 0,void 0,(function*(){const e=this.events[t];e&&e.forEach((function(t){t.call(t,s)}))})),this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>this.unsubscribe(t,e)),this.unsubscribe=(t,e)=>{if(!this.events[t])return;let s=this.events[t].indexOf(e);this.events[t].splice(s)}}}const ks={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Es{constructor(t){var s,i,r,a,h,l;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new As,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,s,i)=>e(this,void 0,void 0,(function*(){if(!t)throw new Error('RPCClient.call(request) requires a "request" param');let e;e="string"==typeof t?ws(t):t,s&&(e.args=s);const r=new n(e);if(!r.procedure&&!r.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');r.identity||(r.identity={}),r.identity=Ze(Object.assign({},this.identity),r.identity);const a=yield this.callManager.manageClientRequest(r,i);if(!a.success)throw new c(a,r,i);const h=o(e);return this.vent.publish(h,null==a?void 0:a.data),a})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let s;s="string"==typeof t?ws(t):t,e&&(s.args=e);const i=this.callManager.getCachedResponse(s);if(i)return i},this.getIdentity=()=>this.identity?$e(this.identity):this.identity,this.getInFlightCallCount=()=>this.callManager.getInFlightCallCount(),this.getWebSocketConnected=()=>{var t;return!!(null===(t=null==this?void 0:this.webSocketTransport)||void 0===t?void 0:t.isConnected())},this.makeProcedure=t=>{const e=this;let s;return s="string"==typeof t?ws(t):t,function(t){return e.call(Object.assign(Object.assign({},s),{args:t}))}},this.registerResponseInterceptor=t=>this.callManager.addResponseInterceptor(t),this.registerRequestInterceptor=t=>this.callManager.addRequestInterceptor(t),this.registerWebSocketConnectionStatusChangeListener=t=>(this.webSocketConnectionChangeListeners.push(t),()=>{this.webSocketConnectionChangeListeners=this.webSocketConnectionChangeListeners.filter((e=>e!==t))}),this.sendClientMessageToServer=t=>{this.webSocketTransport?this.webSocketTransport.isConnected()?this.webSocketTransport.sendClientMessageToServer(t):console.info("RPCClient.sendClientMessageToServer() cannot send because the websocket is not connected"):console.warn("RPCClient.sendClientMessageToServer() unable to send because RPCClient has no websocket configuration")},this.setIdentity=t=>{let e=$e(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const s=$e(this.identity);s.metadata=t,this.identity.metadata=t,this.callManager.setIdentity(s)},this.transports=()=>({http:this.httpTransport,websocket:this.webSocketTransport}),!(null===(s=null==t?void 0:t.hosts)||void 0===s?void 0:s.http)&&!(null===(i=null==t?void 0:t.transports)||void 0===i?void 0:i.http))throw new Error(ks.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(ks.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(ks.INTERCEPTOR_MUSTBE_FUNC);let u;const d={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};u="browser"==t.cacheType?new ns(d):new gs(d);const p=[];(null===(r=t.transports)||void 0===r?void 0:r.websocket)?p.push(t.transports.websocket):(null===(a=null==t?void 0:t.hosts)||void 0===a?void 0:a.websocket)&&(this.webSocketTransport=new Os({host:t.hosts.websocket,onConnectionStatusChange:this.onWebSocketConnectionStatusChange,rpcOptions:t}),p.push(this.webSocketTransport)),(null===(h=t.transports)||void 0===h?void 0:h.http)?p.push(t.transports.http):(null===(l=null==t?void 0:t.hosts)||void 0===l?void 0:l.http)&&(this.httpTransport=new _s({host:t.hosts.http,rpcOptions:t}),p.push(this.httpTransport)),this.callManager=new is({cache:u,deadlineMs:t.deadlineMs||Es.DEFAULT_DEADLINE_MS,onTransportRequestError:t.onTransportRequestError,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:p,transportOptions:t.transportOptions})}subscribe(t,e){const s="string"==typeof t.request?ws(t.request):t.request,i=o(Object.assign(Object.assign({},s),{args:t.args}));return this.vent.subscribe(i,e)}unsubscribe(t,e){const s="string"==typeof t.request?ws(t.request):t.request,i=o(Object.assign(Object.assign({},s),{args:t.args}));this.vent.unsubscribe(i,e)}subscribeToServerMessages(t){return this.webSocketTransport?this.webSocketTransport.subscribeToServerMessages(t):(console.warn("RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration"),()=>{})}unsubscribeFromServerMessages(t){var e;null===(e=this.webSocketTransport)||void 0===e||e.unsubscribeFromServerMessages(t)}}Es.DEFAULT_DEADLINE_MS=1e4,t.CallRequestTransportError=es,t.CallRequestTransportTimeoutError=ts,t.CallResponseError=c,t.RPCClient=Es,t.RPCResponse=a})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RPCClient={})}(this,(function(t){"use strict";function e(t,e,s,i){return new(s||(s=Promise))((function(n,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))}function s(t){var e="function"==typeof Symbol&&Symbol.iterator,s=e&&t[e],i=0;if(s)return s.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,i=t[Symbol.asyncIterator];return i?i.call(t):(t=s(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(s){e[s]=t[s]&&function(e){return new Promise((function(i,n){(function(t,e,s,i){Promise.resolve(i).then((function(e){t({value:e,done:s})}),e)})(i,n,(e=t[s](e)).done,e.value)}))}}}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(t){const{args:e,correlationId:s,identity:i,procedure:n,scope:r,version:o}=t;if(this.args=e,s&&"string"!=typeof s)throw new Error("correlationId must be a string");if(this.correlationId=s||Math.random().toString(),i){if("object"!=typeof i)throw new Error("identity must be an object");if(i.authorization&&"string"!=typeof i.authorization)throw new Error("identity.authorization must be a string");if(i.deviceName&&"string"!=typeof i.deviceName)throw new Error("identity.deviceName must be a string");if(i.metadata&&"object"!=typeof i.metadata)throw new Error("identity.metadata must be a object");this.identity=i}if(n&&"string"!=typeof n)throw new Error("procedure must be string");if(this.procedure=n,r&&"string"!=typeof r)throw new Error("scope must be string");if(this.scope=r,o&&"string"!=typeof o)throw new Error("version must be string");this.version=o}}function r(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}const o=t=>t.args?`${t.scope}${t.procedure}${t.version}${function(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});var s,i="boolean"==typeof e.cycles&&e.cycles,n=e.cmp&&(s=e.cmp,function(t){return function(e,i){var n={key:e,value:t[e]},r={key:i,value:t[i]};return s(n,r)}}),r=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0!==e){if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);var s,o;if(Array.isArray(e)){for(o="[",s=0;s<e.length;s++)s&&(o+=","),o+=t(e[s])||"null";return o+"]"}if(null===e)return"null";if(-1!==r.indexOf(e)){if(i)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(e)-1,c=Object.keys(e).sort(n&&n(e));for(o="",s=0;s<c.length;s++){var h=c[s],l=t(e[h]);l&&(o&&(o+=","),o+=JSON.stringify(h)+":"+l)}return r.splice(a,1),"{"+o+"}"}}(t)}(function(t,e={}){if(!r(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:s,compare:i}=e,n=[],o=[],a=t=>{const e=n.indexOf(t);if(-1!==e)return o[e];const s=[];return n.push(t),o.push(s),s.push(...t.map((t=>Array.isArray(t)?a(t):r(t)?c(t):t))),s},c=t=>{const e=n.indexOf(t);if(-1!==e)return o[e];const h={},l=Object.keys(t).sort(i);n.push(t),o.push(h);for(const e of l){const i=t[e];let n;n=s&&Array.isArray(i)?a(i):s&&r(i)?c(i):i,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:n}))}return h};return Array.isArray(t)?s?a(t):t.slice():c(t)}(t.args||{},{deep:!0}))}`:`${t.scope}${t.procedure}${t.version}`;class a{constructor(t){const{code:e,correlationId:s,data:i,message:n,success:r}=t;if("number"!=typeof e)throw new Error("code must be a number");if(this.code=e,s&&"string"!=typeof s)throw new Error("correlationId must be a string");if(this.correlationId=s,this.data=i,n&&"string"!=typeof n)throw new Error("message must be a string");if(this.message=n,"boolean"!=typeof r)throw new Error("success must be a boolean");this.success=r}}class c extends Error{constructor(t,e,s){super(t.message),this.response={code:0,success:!1},this.name="CallResponseError";const{code:i,correlationId:n,message:r}=t;this.response.code=i,this.response.correlationId=n,this.response.data=t.data,this.response.message=`${o(e)} response error: `+(r||"RPC call failed with no message"),this.request=e,this.callOptions=s}}class h extends Error{}var l="object"==typeof global&&global&&global.Object===Object&&global,u="object"==typeof self&&self&&self.Object===Object&&self,d=l||u||Function("return this")(),p=d.Symbol,f=Object.prototype,v=f.hasOwnProperty,y=f.toString,g=p?p.toStringTag:void 0;var b=Object.prototype.toString;var m=p?p.toStringTag:void 0;function w(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m in Object(t)?function(t){var e=v.call(t,g),s=t[g];try{t[g]=void 0;var i=!0}catch(t){}var n=y.call(t);return i&&(e?t[g]=s:delete t[g]),n}(t):function(t){return b.call(t)}(t)}function S(t){return null!=t&&"object"==typeof t}var _=Array.isArray;function T(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function C(t){return t}function j(t){if(!T(t))return!1;var e=w(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var O,A=d["__core-js_shared__"],k=(O=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var E=Function.prototype.toString;function F(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var R=/^\[object .+?Constructor\]$/,x=Function.prototype,z=Object.prototype,M=x.toString,I=z.hasOwnProperty,L=RegExp("^"+M.call(I).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function P(t){return!(!T(t)||(e=t,k&&k in e))&&(j(t)?L:R).test(F(t));var e}function D(t,e){var s=function(t,e){return null==t?void 0:t[e]}(t,e);return P(s)?s:void 0}var W=D(d,"WeakMap"),q=Object.create,B=function(){function t(){}return function(e){if(!T(e))return{};if(q)return q(e);t.prototype=e;var s=new t;return t.prototype=void 0,s}}();function U(t,e){var s=-1,i=t.length;for(e||(e=Array(i));++s<i;)e[s]=t[s];return e}var N=Date.now;var $,H,G,J=function(){try{var t=D(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),V=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(s=e,function(){return s}),writable:!0});var s}:C,X=($=V,H=0,G=0,function(){var t=N(),e=16-(t-G);if(G=t,e>0){if(++H>=800)return arguments[0]}else H=0;return $.apply(void 0,arguments)});var K=/^(?:0|[1-9]\d*)$/;function Z(t,e){var s=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==s||"symbol"!=s&&K.test(t))&&t>-1&&t%1==0&&t<e}function Q(t,e,s){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:s,writable:!0}):t[e]=s}function Y(t,e){return t===e||t!=t&&e!=e}var tt=Object.prototype.hasOwnProperty;function et(t,e,s){var i=t[e];tt.call(t,e)&&Y(i,s)&&(void 0!==s||e in t)||Q(t,e,s)}function st(t,e,s,i){var n=!s;s||(s={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=void 0;void 0===c&&(c=t[a]),n?Q(s,a,c):et(s,a,c)}return s}var it=Math.max;function nt(t,e){return X(function(t,e,s){return e=it(void 0===e?t.length-1:e,0),function(){for(var i=arguments,n=-1,r=it(i.length-e,0),o=Array(r);++n<r;)o[n]=i[e+n];n=-1;for(var a=Array(e+1);++n<e;)a[n]=i[n];return a[e]=s(o),function(t,e,s){switch(s.length){case 0:return t.call(e);case 1:return t.call(e,s[0]);case 2:return t.call(e,s[0],s[1]);case 3:return t.call(e,s[0],s[1],s[2])}return t.apply(e,s)}(t,this,a)}}(t,e,C),t+"")}function rt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function ot(t){return null!=t&&rt(t.length)&&!j(t)}var at=Object.prototype;function ct(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||at)}function ht(t){return S(t)&&"[object Arguments]"==w(t)}var lt=Object.prototype,ut=lt.hasOwnProperty,dt=lt.propertyIsEnumerable,pt=ht(function(){return arguments}())?ht:function(t){return S(t)&&ut.call(t,"callee")&&!dt.call(t,"callee")};var ft="object"==typeof t&&t&&!t.nodeType&&t,vt=ft&&"object"==typeof module&&module&&!module.nodeType&&module,yt=vt&&vt.exports===ft?d.Buffer:void 0,gt=(yt?yt.isBuffer:void 0)||function(){return!1},bt={};function mt(t){return function(e){return t(e)}}bt["[object Float32Array]"]=bt["[object Float64Array]"]=bt["[object Int8Array]"]=bt["[object Int16Array]"]=bt["[object Int32Array]"]=bt["[object Uint8Array]"]=bt["[object Uint8ClampedArray]"]=bt["[object Uint16Array]"]=bt["[object Uint32Array]"]=!0,bt["[object Arguments]"]=bt["[object Array]"]=bt["[object ArrayBuffer]"]=bt["[object Boolean]"]=bt["[object DataView]"]=bt["[object Date]"]=bt["[object Error]"]=bt["[object Function]"]=bt["[object Map]"]=bt["[object Number]"]=bt["[object Object]"]=bt["[object RegExp]"]=bt["[object Set]"]=bt["[object String]"]=bt["[object WeakMap]"]=!1;var wt="object"==typeof t&&t&&!t.nodeType&&t,St=wt&&"object"==typeof module&&module&&!module.nodeType&&module,_t=St&&St.exports===wt&&l.process,Tt=function(){try{var t=St&&St.require&&St.require("util").types;return t||_t&&_t.binding&&_t.binding("util")}catch(t){}}(),Ct=Tt&&Tt.isTypedArray,jt=Ct?mt(Ct):function(t){return S(t)&&rt(t.length)&&!!bt[w(t)]},Ot=Object.prototype.hasOwnProperty;function At(t,e){var s=_(t),i=!s&&pt(t),n=!s&&!i&>(t),r=!s&&!i&&!n&&jt(t),o=s||i||n||r,a=o?function(t,e){for(var s=-1,i=Array(t);++s<t;)i[s]=e(s);return i}(t.length,String):[],c=a.length;for(var h in t)!e&&!Ot.call(t,h)||o&&("length"==h||n&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||Z(h,c))||a.push(h);return a}function kt(t,e){return function(s){return t(e(s))}}var Et=kt(Object.keys,Object),Ft=Object.prototype.hasOwnProperty;function Rt(t){return ot(t)?At(t):function(t){if(!ct(t))return Et(t);var e=[];for(var s in Object(t))Ft.call(t,s)&&"constructor"!=s&&e.push(s);return e}(t)}var xt=Object.prototype.hasOwnProperty;function zt(t){if(!T(t))return function(t){var e=[];if(null!=t)for(var s in Object(t))e.push(s);return e}(t);var e=ct(t),s=[];for(var i in t)("constructor"!=i||!e&&xt.call(t,i))&&s.push(i);return s}function Mt(t){return ot(t)?At(t,!0):zt(t)}var It=D(Object,"create");var Lt=Object.prototype.hasOwnProperty;var Pt=Object.prototype.hasOwnProperty;function Dt(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}function Wt(t,e){for(var s=t.length;s--;)if(Y(t[s][0],e))return s;return-1}Dt.prototype.clear=function(){this.__data__=It?It(null):{},this.size=0},Dt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Dt.prototype.get=function(t){var e=this.__data__;if(It){var s=e[t];return"__lodash_hash_undefined__"===s?void 0:s}return Lt.call(e,t)?e[t]:void 0},Dt.prototype.has=function(t){var e=this.__data__;return It?void 0!==e[t]:Pt.call(e,t)},Dt.prototype.set=function(t,e){var s=this.__data__;return this.size+=this.has(t)?0:1,s[t]=It&&void 0===e?"__lodash_hash_undefined__":e,this};var qt=Array.prototype.splice;function Bt(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}Bt.prototype.clear=function(){this.__data__=[],this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,s=Wt(e,t);return!(s<0)&&(s==e.length-1?e.pop():qt.call(e,s,1),--this.size,!0)},Bt.prototype.get=function(t){var e=this.__data__,s=Wt(e,t);return s<0?void 0:e[s][1]},Bt.prototype.has=function(t){return Wt(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var s=this.__data__,i=Wt(s,t);return i<0?(++this.size,s.push([t,e])):s[i][1]=e,this};var Ut=D(d,"Map");function Nt(t,e){var s,i,n=t.__data__;return("string"==(i=typeof(s=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==s:null===s)?n["string"==typeof e?"string":"hash"]:n.map}function $t(t){var e=-1,s=null==t?0:t.length;for(this.clear();++e<s;){var i=t[e];this.set(i[0],i[1])}}function Ht(t,e){for(var s=-1,i=e.length,n=t.length;++s<i;)t[n+s]=e[s];return t}$t.prototype.clear=function(){this.size=0,this.__data__={hash:new Dt,map:new(Ut||Bt),string:new Dt}},$t.prototype.delete=function(t){var e=Nt(this,t).delete(t);return this.size-=e?1:0,e},$t.prototype.get=function(t){return Nt(this,t).get(t)},$t.prototype.has=function(t){return Nt(this,t).has(t)},$t.prototype.set=function(t,e){var s=Nt(this,t),i=s.size;return s.set(t,e),this.size+=s.size==i?0:1,this};var Gt=kt(Object.getPrototypeOf,Object),Jt=Function.prototype,Vt=Object.prototype,Xt=Jt.toString,Kt=Vt.hasOwnProperty,Zt=Xt.call(Object);function Qt(t){var e=this.__data__=new Bt(t);this.size=e.size}Qt.prototype.clear=function(){this.__data__=new Bt,this.size=0},Qt.prototype.delete=function(t){var e=this.__data__,s=e.delete(t);return this.size=e.size,s},Qt.prototype.get=function(t){return this.__data__.get(t)},Qt.prototype.has=function(t){return this.__data__.has(t)},Qt.prototype.set=function(t,e){var s=this.__data__;if(s instanceof Bt){var i=s.__data__;if(!Ut||i.length<199)return i.push([t,e]),this.size=++s.size,this;s=this.__data__=new $t(i)}return s.set(t,e),this.size=s.size,this};var Yt="object"==typeof t&&t&&!t.nodeType&&t,te=Yt&&"object"==typeof module&&module&&!module.nodeType&&module,ee=te&&te.exports===Yt?d.Buffer:void 0,se=ee?ee.allocUnsafe:void 0;function ie(t,e){if(e)return t.slice();var s=t.length,i=se?se(s):new t.constructor(s);return t.copy(i),i}function ne(){return[]}var re=Object.prototype.propertyIsEnumerable,oe=Object.getOwnPropertySymbols,ae=oe?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var s=-1,i=null==t?0:t.length,n=0,r=[];++s<i;){var o=t[s];e(o,s,t)&&(r[n++]=o)}return r}(oe(t),(function(e){return re.call(t,e)})))}:ne;var ce=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Ht(e,ae(t)),t=Gt(t);return e}:ne;function he(t,e,s){var i=e(t);return _(t)?i:Ht(i,s(t))}function le(t){return he(t,Rt,ae)}function ue(t){return he(t,Mt,ce)}var de=D(d,"DataView"),pe=D(d,"Promise"),fe=D(d,"Set"),ve="[object Map]",ye="[object Promise]",ge="[object Set]",be="[object WeakMap]",me="[object DataView]",we=F(de),Se=F(Ut),_e=F(pe),Te=F(fe),Ce=F(W),je=w;(de&&je(new de(new ArrayBuffer(1)))!=me||Ut&&je(new Ut)!=ve||pe&&je(pe.resolve())!=ye||fe&&je(new fe)!=ge||W&&je(new W)!=be)&&(je=function(t){var e=w(t),s="[object Object]"==e?t.constructor:void 0,i=s?F(s):"";if(i)switch(i){case we:return me;case Se:return ve;case _e:return ye;case Te:return ge;case Ce:return be}return e});var Oe=Object.prototype.hasOwnProperty;var Ae=d.Uint8Array;function ke(t){var e=new t.constructor(t.byteLength);return new Ae(e).set(new Ae(t)),e}var Ee=/\w*$/;var Fe=p?p.prototype:void 0,Re=Fe?Fe.valueOf:void 0;function xe(t,e){var s=e?ke(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.length)}function ze(t,e,s){var i,n,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return ke(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var s=e?ke(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.byteLength)}(t,s);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return xe(t,s);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return(r=new(n=t).constructor(n.source,Ee.exec(n))).lastIndex=n.lastIndex,r;case"[object Symbol]":return i=t,Re?Object(Re.call(i)):{}}}function Me(t){return"function"!=typeof t.constructor||ct(t)?{}:B(Gt(t))}var Ie=Tt&&Tt.isMap,Le=Ie?mt(Ie):function(t){return S(t)&&"[object Map]"==je(t)};var Pe=Tt&&Tt.isSet,De=Pe?mt(Pe):function(t){return S(t)&&"[object Set]"==je(t)},We="[object Arguments]",qe="[object Function]",Be="[object Object]",Ue={};function Ne(t,e,s,i,n,r){var o,a=1&e,c=2&e,h=4&e;if(void 0!==o)return o;if(!T(t))return t;var l=_(t);if(l){if(o=function(t){var e=t.length,s=new t.constructor(e);return e&&"string"==typeof t[0]&&Oe.call(t,"index")&&(s.index=t.index,s.input=t.input),s}(t),!a)return U(t,o)}else{var u=je(t),d=u==qe||"[object GeneratorFunction]"==u;if(gt(t))return ie(t,a);if(u==Be||u==We||d&&!n){if(o=c||d?{}:Me(t),!a)return c?function(t,e){return st(t,ce(t),e)}(t,function(t,e){return t&&st(e,Mt(e),t)}(o,t)):function(t,e){return st(t,ae(t),e)}(t,function(t,e){return t&&st(e,Rt(e),t)}(o,t))}else{if(!Ue[u])return n?t:{};o=ze(t,u,a)}}r||(r=new Qt);var p=r.get(t);if(p)return p;r.set(t,o),De(t)?t.forEach((function(i){o.add(Ne(i,e,s,i,t,r))})):Le(t)&&t.forEach((function(i,n){o.set(n,Ne(i,e,s,n,t,r))}));var f=l?void 0:(h?c?ue:le:c?Mt:Rt)(t);return function(t,e){for(var s=-1,i=null==t?0:t.length;++s<i&&!1!==e(t[s],s,t););}(f||t,(function(i,n){f&&(i=t[n=i]),et(o,n,Ne(i,e,s,n,t,r))})),o}Ue[We]=Ue["[object Array]"]=Ue["[object ArrayBuffer]"]=Ue["[object DataView]"]=Ue["[object Boolean]"]=Ue["[object Date]"]=Ue["[object Float32Array]"]=Ue["[object Float64Array]"]=Ue["[object Int8Array]"]=Ue["[object Int16Array]"]=Ue["[object Int32Array]"]=Ue["[object Map]"]=Ue["[object Number]"]=Ue[Be]=Ue["[object RegExp]"]=Ue["[object Set]"]=Ue["[object String]"]=Ue["[object Symbol]"]=Ue["[object Uint8Array]"]=Ue["[object Uint8ClampedArray]"]=Ue["[object Uint16Array]"]=Ue["[object Uint32Array]"]=!0,Ue["[object Error]"]=Ue[qe]=Ue["[object WeakMap]"]=!1;function $e(t){return Ne(t,5)}var He=function(t,e,s){for(var i=-1,n=Object(t),r=s(t),o=r.length;o--;){var a=r[++i];if(!1===e(n[a],a,n))break}return t};function Ge(t,e,s){(void 0!==s&&!Y(t[e],s)||void 0===s&&!(e in t))&&Q(t,e,s)}function Je(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Ve(t,e,s,i,n,r,o){var a=Je(t,s),c=Je(e,s),h=o.get(c);if(h)Ge(t,s,h);else{var l,u=r?r(a,c,s+"",t,e,o):void 0,d=void 0===u;if(d){var p=_(c),f=!p&>(c),v=!p&&!f&&jt(c);u=c,p||f||v?_(a)?u=a:S(l=a)&&ot(l)?u=U(a):f?(d=!1,u=ie(c,!0)):v?(d=!1,u=xe(c,!0)):u=[]:function(t){if(!S(t)||"[object Object]"!=w(t))return!1;var e=Gt(t);if(null===e)return!0;var s=Kt.call(e,"constructor")&&e.constructor;return"function"==typeof s&&s instanceof s&&Xt.call(s)==Zt}(c)||pt(c)?(u=a,pt(a)?u=function(t){return st(t,Mt(t))}(a):T(a)&&!j(a)||(u=Me(c))):d=!1}d&&(o.set(c,u),n(u,c,i,r,o),o.delete(c)),Ge(t,s,u)}}function Xe(t,e,s,i,n){t!==e&&He(e,(function(r,o){if(n||(n=new Qt),T(r))Ve(t,e,o,s,Xe,i,n);else{var a=i?i(Je(t,o),r,o+"",t,e,n):void 0;void 0===a&&(a=r),Ge(t,o,a)}}),Mt)}var Ke,Ze=(Ke=function(t,e,s){Xe(t,e,s)},nt((function(t,e){var s=-1,i=e.length,n=i>1?e[i-1]:void 0,r=i>2?e[2]:void 0;for(n=Ke.length>3&&"function"==typeof n?(i--,n):void 0,r&&function(t,e,s){if(!T(s))return!1;var i=typeof e;return!!("number"==i?ot(s)&&Z(e,s.length):"string"==i&&e in s)&&Y(s[e],t)}(e[0],e[1],r)&&(n=i<3?void 0:n,i=1),t=Object(t);++s<i;){var o=e[s];o&&Ke(t,o,s,n)}return t})));let Qe=null;try{Qe=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const Ye=t=>Qe&&new RegExp(Qe).test(t)?(...e)=>console.log(t,...e):()=>{};class ts extends Error{}class es extends Error{}const ss=Ye("rpc:ClientManager");class is{constructor(t){this.options=t,this.inflightCallsByKey={},this.interceptors={request:[],response:[]},this.addResponseInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.response.push(t),()=>{this.interceptors.response=this.interceptors.response.filter((e=>e!==t))}},this.addRequestInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.request.push(t),()=>{this.interceptors.request=this.interceptors.request.filter((e=>e!==t))}},this.clearCache=t=>{ss("clearCache"),this.cache&&this.cache.clearCache(t)},this.getCachedResponse=t=>{var e;return ss("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(ss("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=(t,s)=>e(this,void 0,void 0,(function*(){ss("manageClientRequest",t);const i=yield this.interceptRequestMutator(t),n=o(i);if(this.inflightCallsByKey.hasOwnProperty(n))return ss("manageClientRequest using an existing in-flight call",n),this.inflightCallsByKey[n].then((e=>{const s=$e(e);return t.correlationId&&(s.correlationId=t.correlationId),s}));const r=(()=>e(this,void 0,void 0,(function*(){var t,e;const n=null===(t=this.options.transportOptions)||void 0===t?void 0:t.preferredTransport,r=null!==(e=null==s?void 0:s.transport)&&void 0!==e?e:n,o=yield this.sendRequestWithTransport(i,Object.assign(Object.assign({},s),{transport:r})),a=yield this.interceptResponseMutator(o,i);return this.cache&&a&&this.cache.setCachedResponse(i,a),a})))().finally((()=>{delete this.inflightCallsByKey[n]}));return this.inflightCallsByKey[n]=r,yield r})),this.setIdentity=t=>{ss("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){var e,s,n,r;let o=t;if(this.interceptors.request.length){ss("interceptRequestMutator(), original request:",t);try{for(var a,c=!0,h=i(this.interceptors.request);!(e=(a=yield h.next()).done);c=!0){r=a.value,c=!1;const t=r;o=yield t(o)}}catch(t){s={error:t}}finally{try{c||e||!(n=h.return)||(yield n.call(h))}finally{if(s)throw s.error}}}return o})),this.interceptResponseMutator=(t,s)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){ss("interceptResponseMutator",s,t);for(const i of this.interceptors.response)try{e=yield i(e,s)}catch(i){throw ss("caught response interceptor, request:",s,"original response:",t,"mutated response:",e),i}}return e})),this.sendRequestWithTransport=(t,s)=>e(this,void 0,void 0,(function*(){var e,i;let n;ss("sendRequestWithTransport",t);let r=0,o=this.transports;if(null==s?void 0:s.transport){const t=this.transports.find((t=>t.type===s.transport));if(!t)throw new h(`Specified Transport "${s.transport}" not available`);o=[t]}for(;!n&&o[r];){const a=o[r];if(a.isConnected()){ss(`sendRequestWithTransport trying ${o[r].name}`,t);try{let e;const i=a.sendRequest(t,s||{}),r=new Promise(((i,n)=>{e=setTimeout((()=>{n(new ts(`Procedure ${t.procedure}`))}),(null==s?void 0:s.timeout)||this.options.deadlineMs)}));n=yield Promise.race([r,i]).finally((()=>{clearTimeout(e)}))}catch(s){if(null===(i=(e=this.options).onTransportRequestError)||void 0===i||i.call(e,s,o[r].type,t),!(s instanceof ts||s instanceof es))throw s;console.warn(`RPCClient ClientManager#sendRequestWithTransport() sending request with ${o[r].name} failed ${o[r+1]?`trying next transport "${o[r+1].name}"`:"no more transports to try"}`),r++}}else r++}if(!n&&!this.transports[r])throw console.error(`RPCClient ClientManager#sendRequestWithTransport() ${t.scope}::${t.procedure}::${t.version} did not get a response from any transports`),new h(`Procedure ${t.procedure} did not get a response from any transports`);if(!n)throw new h(`Procedure ${t.procedure} did not get a response from the remote`);return n})),this.cache=t.cache,t.requestInterceptor&&this.interceptors.request.push(t.requestInterceptor),t.responseInterceptor&&this.interceptors.response.push(t.responseInterceptor),this.transports=t.transports}}class ns{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}ns.DEFAULT_CACHE_MAX_AGE_MS=3e5,ns.DEFAULT_CACHE_MAX_SIZE=100;const rs="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,os=new Set,as="object"==typeof process&&process?process:{},cs=(t,e,s,i)=>{"function"==typeof as.emitWarning?as.emitWarning(t,e,s,i):console.error(`[${s}] ${e}: ${t}`)};let hs=globalThis.AbortController,ls=globalThis.AbortSignal;if(void 0===hs){ls=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},hs=class{constructor(){e()}signal=new ls;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==as.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,cs("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const us=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),ds=t=>us(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?ps:null:null;class ps extends Array{constructor(t){super(t),this.fill(0)}}class fs{heap;length;static#t=!1;static create(t){const e=ds(t);if(!e)return[];fs.#t=!0;const s=new fs(t,e);return fs.#t=!1,s}constructor(t,e){if(!fs.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class vs{#e;#s;#i;#n;#r;#o;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#a;#c;#h;#l;#u;#d;#p;#f;#v;#y;#g;#b;#m;#w;#S;#_;#T;static unsafeExposeInternals(t){return{starts:t.#m,ttls:t.#w,sizes:t.#b,keyMap:t.#h,keyList:t.#l,valList:t.#u,next:t.#d,prev:t.#p,get head(){return t.#f},get tail(){return t.#v},free:t.#y,isBackgroundFetch:e=>t.#C(e),backgroundFetch:(e,s,i,n)=>t.#j(e,s,i,n),moveToTail:e=>t.#O(e),indexes:e=>t.#A(e),rindexes:e=>t.#k(e),isStale:e=>t.#E(e)}}get max(){return this.#e}get maxSize(){return this.#s}get calculatedSize(){return this.#c}get size(){return this.#a}get fetchMethod(){return this.#r}get memoMethod(){return this.#o}get dispose(){return this.#i}get disposeAfter(){return this.#n}constructor(t){const{max:e=0,ttl:s,ttlResolution:i=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:o,allowStale:a,dispose:c,disposeAfter:h,noDisposeOnSet:l,noUpdateTTL:u,maxSize:d=0,maxEntrySize:p=0,sizeCalculation:f,fetchMethod:v,memoMethod:y,noDeleteOnFetchRejection:g,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:w,ignoreFetchAbort:S}=t;if(0!==e&&!us(e))throw new TypeError("max option must be a nonnegative integer");const _=e?ds(e):Array;if(!_)throw new Error("invalid max value: "+e);if(this.#e=e,this.#s=d,this.maxEntrySize=p||this.#s,this.sizeCalculation=f,this.sizeCalculation){if(!this.#s&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==y&&"function"!=typeof y)throw new TypeError("memoMethod must be a function if defined");if(this.#o=y,void 0!==v&&"function"!=typeof v)throw new TypeError("fetchMethod must be a function if specified");if(this.#r=v,this.#_=!!v,this.#h=new Map,this.#l=new Array(e).fill(void 0),this.#u=new Array(e).fill(void 0),this.#d=new _(e),this.#p=new _(e),this.#f=0,this.#v=0,this.#y=fs.create(e),this.#a=0,this.#c=0,"function"==typeof c&&(this.#i=c),"function"==typeof h?(this.#n=h,this.#g=[]):(this.#n=void 0,this.#g=void 0),this.#S=!!this.#i,this.#T=!!this.#n,this.noDisposeOnSet=!!l,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!g,this.allowStaleOnFetchRejection=!!m,this.allowStaleOnFetchAbort=!!w,this.ignoreFetchAbort=!!S,0!==this.maxEntrySize){if(0!==this.#s&&!us(this.#s))throw new TypeError("maxSize must be a positive integer if specified");if(!us(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#F()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=us(i)||0===i?i:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!us(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#R()}if(0===this.#e&&0===this.ttl&&0===this.#s)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#s){const t="LRU_CACHE_UNBOUNDED";if((t=>!os.has(t))(t)){os.add(t);cs("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,vs)}}}getRemainingTTL(t){return this.#h.has(t)?1/0:0}#R(){const t=new ps(this.#e),e=new ps(this.#e);this.#w=t,this.#m=e,this.#x=(s,i,n=rs.now())=>{if(e[s]=0!==i?n:0,t[s]=i,0!==i&&this.ttlAutopurge){const t=setTimeout((()=>{this.#E(s)&&this.#z(this.#l[s],"expire")}),i+1);t.unref&&t.unref()}},this.#M=s=>{e[s]=0!==t[s]?rs.now():0},this.#I=(n,r)=>{if(t[r]){const o=t[r],a=e[r];if(!o||!a)return;n.ttl=o,n.start=a,n.now=s||i();const c=n.now-a;n.remainingTTL=o-c}};let s=0;const i=()=>{const t=rs.now();if(this.ttlResolution>0){s=t;const e=setTimeout((()=>s=0),this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=n=>{const r=this.#h.get(n);if(void 0===r)return 0;const o=t[r],a=e[r];if(!o||!a)return 1/0;return o-((s||i())-a)},this.#E=n=>{const r=e[n],o=t[n];return!!o&&!!r&&(s||i())-r>o}}#M=()=>{};#I=()=>{};#x=()=>{};#E=()=>!1;#F(){const t=new ps(this.#e);this.#c=0,this.#b=t,this.#L=e=>{this.#c-=t[e],t[e]=0},this.#P=(t,e,s,i)=>{if(this.#C(e))return 0;if(!us(s)){if(!i)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof i)throw new TypeError("sizeCalculation must be a function");if(s=i(e,t),!us(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return s},this.#D=(e,s,i)=>{if(t[e]=s,this.#s){const s=this.#s-t[e];for(;this.#c>s;)this.#W(!0)}this.#c+=t[e],i&&(i.entrySize=s,i.totalCalculatedSize=this.#c)}}#L=t=>{};#D=(t,e,s)=>{};#P=(t,e,s,i)=>{if(s||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#a)for(let e=this.#v;this.#q(e)&&(!t&&this.#E(e)||(yield e),e!==this.#f);)e=this.#p[e]}*#k({allowStale:t=this.allowStale}={}){if(this.#a)for(let e=this.#f;this.#q(e)&&(!t&&this.#E(e)||(yield e),e!==this.#v);)e=this.#d[e]}#q(t){return void 0!==t&&this.#h.get(this.#l[t])===t}*entries(){for(const t of this.#A())void 0===this.#u[t]||void 0===this.#l[t]||this.#C(this.#u[t])||(yield[this.#l[t],this.#u[t]])}*rentries(){for(const t of this.#k())void 0===this.#u[t]||void 0===this.#l[t]||this.#C(this.#u[t])||(yield[this.#l[t],this.#u[t]])}*keys(){for(const t of this.#A()){const e=this.#l[t];void 0===e||this.#C(this.#u[t])||(yield e)}}*rkeys(){for(const t of this.#k()){const e=this.#l[t];void 0===e||this.#C(this.#u[t])||(yield e)}}*values(){for(const t of this.#A()){void 0===this.#u[t]||this.#C(this.#u[t])||(yield this.#u[t])}}*rvalues(){for(const t of this.#k()){void 0===this.#u[t]||this.#C(this.#u[t])||(yield this.#u[t])}}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(const s of this.#A()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;if(void 0!==n&&t(n,this.#l[s],this))return this.get(this.#l[s],e)}}forEach(t,e=this){for(const s of this.#A()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;void 0!==n&&t.call(e,n,this.#l[s],this)}}rforEach(t,e=this){for(const s of this.#k()){const i=this.#u[s],n=this.#C(i)?i.__staleWhileFetching:i;void 0!==n&&t.call(e,n,this.#l[s],this)}}purgeStale(){let t=!1;for(const e of this.#k({allowStale:!0}))this.#E(e)&&(this.#z(this.#l[e],"expire"),t=!0);return t}info(t){const e=this.#h.get(t);if(void 0===e)return;const s=this.#u[e],i=this.#C(s)?s.__staleWhileFetching:s;if(void 0===i)return;const n={value:i};if(this.#w&&this.#m){const t=this.#w[e],s=this.#m[e];if(t&&s){const e=t-(rs.now()-s);n.ttl=e,n.start=Date.now()}}return this.#b&&(n.size=this.#b[e]),n}dump(){const t=[];for(const e of this.#A({allowStale:!0})){const s=this.#l[e],i=this.#u[e],n=this.#C(i)?i.__staleWhileFetching:i;if(void 0===n||void 0===s)continue;const r={value:n};if(this.#w&&this.#m){r.ttl=this.#w[e];const t=rs.now()-this.#m[e];r.start=Math.floor(Date.now()-t)}this.#b&&(r.size=this.#b[e]),t.unshift([s,r])}return t}load(t){this.clear();for(const[e,s]of t){if(s.start){const t=Date.now()-s.start;s.start=rs.now()-t}this.set(e,s.value,s)}}set(t,e,s={}){if(void 0===e)return this.delete(t),this;const{ttl:i=this.ttl,start:n,noDisposeOnSet:r=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:a}=s;let{noUpdateTTL:c=this.noUpdateTTL}=s;const h=this.#P(t,e,s.size||0,o);if(this.maxEntrySize&&h>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#z(t,"set"),this;let l=0===this.#a?void 0:this.#h.get(t);if(void 0===l)l=0===this.#a?this.#v:0!==this.#y.length?this.#y.pop():this.#a===this.#e?this.#W(!1):this.#a,this.#l[l]=t,this.#u[l]=e,this.#h.set(t,l),this.#d[this.#v]=l,this.#p[l]=this.#v,this.#v=l,this.#a++,this.#D(l,h,a),a&&(a.set="add"),c=!1;else{this.#O(l);const s=this.#u[l];if(e!==s){if(this.#_&&this.#C(s)){s.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=s;void 0===e||r||(this.#S&&this.#i?.(e,t,"set"),this.#T&&this.#g?.push([e,t,"set"]))}else r||(this.#S&&this.#i?.(s,t,"set"),this.#T&&this.#g?.push([s,t,"set"]));if(this.#L(l),this.#D(l,h,a),this.#u[l]=e,a){a.set="replace";const t=s&&this.#C(s)?s.__staleWhileFetching:s;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update")}if(0===i||this.#w||this.#R(),this.#w&&(c||this.#x(l,i,n),a&&this.#I(a,l)),!r&&this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}return this}pop(){try{for(;this.#a;){const t=this.#u[this.#f];if(this.#W(!0),this.#C(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}}}#W(t){const e=this.#f,s=this.#l[e],i=this.#u[e];return this.#_&&this.#C(i)?i.__abortController.abort(new Error("evicted")):(this.#S||this.#T)&&(this.#S&&this.#i?.(i,s,"evict"),this.#T&&this.#g?.push([i,s,"evict"])),this.#L(e),t&&(this.#l[e]=void 0,this.#u[e]=void 0,this.#y.push(e)),1===this.#a?(this.#f=this.#v=0,this.#y.length=0):this.#f=this.#d[e],this.#h.delete(s),this.#a--,e}has(t,e={}){const{updateAgeOnHas:s=this.updateAgeOnHas,status:i}=e,n=this.#h.get(t);if(void 0!==n){const t=this.#u[n];if(this.#C(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#E(n))return s&&this.#M(n),i&&(i.has="hit",this.#I(i,n)),!0;i&&(i.has="stale",this.#I(i,n))}else i&&(i.has="miss");return!1}peek(t,e={}){const{allowStale:s=this.allowStale}=e,i=this.#h.get(t);if(void 0===i||!s&&this.#E(i))return;const n=this.#u[i];return this.#C(n)?n.__staleWhileFetching:n}#j(t,e,s,i){const n=void 0===e?void 0:this.#u[e];if(this.#C(n))return n;const r=new hs,{signal:o}=s;o?.addEventListener("abort",(()=>r.abort(o.reason)),{signal:r.signal});const a={signal:r.signal,options:s,context:i},c=(i,n=!1)=>{const{aborted:o}=r.signal,c=s.ignoreFetchAbort&&void 0!==i;if(s.status&&(o&&!n?(s.status.fetchAborted=!0,s.status.fetchError=r.signal.reason,c&&(s.status.fetchAbortIgnored=!0)):s.status.fetchResolved=!0),o&&!c&&!n)return h(r.signal.reason);const u=l;return this.#u[e]===l&&(void 0===i?u.__staleWhileFetching?this.#u[e]=u.__staleWhileFetching:this.#z(t,"fetch"):(s.status&&(s.status.fetchUpdated=!0),this.set(t,i,a.options))),i},h=i=>{const{aborted:n}=r.signal,o=n&&s.allowStaleOnFetchAbort,a=o||s.allowStaleOnFetchRejection,c=a||s.noDeleteOnFetchRejection,h=l;if(this.#u[e]===l){!c||void 0===h.__staleWhileFetching?this.#z(t,"fetch"):o||(this.#u[e]=h.__staleWhileFetching)}if(a)return s.status&&void 0!==h.__staleWhileFetching&&(s.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw i};s.status&&(s.status.fetchDispatched=!0);const l=new Promise(((e,i)=>{const o=this.#r?.(t,n,a);o&&o instanceof Promise&&o.then((t=>e(void 0===t?void 0:t)),i),r.signal.addEventListener("abort",(()=>{s.ignoreFetchAbort&&!s.allowStaleOnFetchAbort||(e(void 0),s.allowStaleOnFetchAbort&&(e=t=>c(t,!0)))}))})).then(c,(t=>(s.status&&(s.status.fetchRejected=!0,s.status.fetchError=t),h(t)))),u=Object.assign(l,{__abortController:r,__staleWhileFetching:n,__returned:void 0});return void 0===e?(this.set(t,u,{...a.options,status:void 0}),e=this.#h.get(t)):this.#u[e]=u,u}#C(t){if(!this.#_)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof hs}async fetch(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:r=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:a=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:d=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:f,forceRefresh:v=!1,status:y,signal:g}=e;if(!this.#_)return y&&(y.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:n,status:y});const b={allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:n,ttl:r,noDisposeOnSet:o,size:a,sizeCalculation:c,noUpdateTTL:h,noDeleteOnFetchRejection:l,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:p,ignoreFetchAbort:d,status:y,signal:g};let m=this.#h.get(t);if(void 0===m){y&&(y.fetch="miss");const e=this.#j(t,m,b,f);return e.__returned=e}{const e=this.#u[m];if(this.#C(e)){const t=s&&void 0!==e.__staleWhileFetching;return y&&(y.fetch="inflight",t&&(y.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const n=this.#E(m);if(!v&&!n)return y&&(y.fetch="hit"),this.#O(m),i&&this.#M(m),y&&this.#I(y,m),e;const r=this.#j(t,m,b,f),o=void 0!==r.__staleWhileFetching&&s;return y&&(y.fetch=n?"stale":"refresh",o&&n&&(y.returnedStale=!0)),o?r.__staleWhileFetching:r.__returned=r}}async forceFetch(t,e={}){const s=await this.fetch(t,e);if(void 0===s)throw new Error("fetch() returned undefined");return s}memo(t,e={}){const s=this.#o;if(!s)throw new Error("no memoMethod provided to constructor");const{context:i,forceRefresh:n,...r}=e,o=this.get(t,r);if(!n&&void 0!==o)return o;const a=s(t,o,{options:r,context:i});return this.set(t,a,r),a}get(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:r}=e,o=this.#h.get(t);if(void 0!==o){const e=this.#u[o],a=this.#C(e);return r&&this.#I(r,o),this.#E(o)?(r&&(r.get="stale"),a?(r&&s&&void 0!==e.__staleWhileFetching&&(r.returnedStale=!0),s?e.__staleWhileFetching:void 0):(n||this.#z(t,"expire"),r&&s&&(r.returnedStale=!0),s?e:void 0)):(r&&(r.get="hit"),a?e.__staleWhileFetching:(this.#O(o),i&&this.#M(o),e))}r&&(r.get="miss")}#B(t,e){this.#p[e]=t,this.#d[t]=e}#O(t){t!==this.#v&&(t===this.#f?this.#f=this.#d[t]:this.#B(this.#p[t],this.#d[t]),this.#B(this.#v,t),this.#v=t)}delete(t){return this.#z(t,"delete")}#z(t,e){let s=!1;if(0!==this.#a){const i=this.#h.get(t);if(void 0!==i)if(s=!0,1===this.#a)this.#U(e);else{this.#L(i);const s=this.#u[i];if(this.#C(s)?s.__abortController.abort(new Error("deleted")):(this.#S||this.#T)&&(this.#S&&this.#i?.(s,t,e),this.#T&&this.#g?.push([s,t,e])),this.#h.delete(t),this.#l[i]=void 0,this.#u[i]=void 0,i===this.#v)this.#v=this.#p[i];else if(i===this.#f)this.#f=this.#d[i];else{const t=this.#p[i];this.#d[t]=this.#d[i];const e=this.#d[i];this.#p[e]=this.#p[i]}this.#a--,this.#y.push(i)}}if(this.#T&&this.#g?.length){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}return s}clear(){return this.#U("delete")}#U(t){for(const e of this.#k({allowStale:!0})){const s=this.#u[e];if(this.#C(s))s.__abortController.abort(new Error("deleted"));else{const i=this.#l[e];this.#S&&this.#i?.(s,i,t),this.#T&&this.#g?.push([s,i,t])}}if(this.#h.clear(),this.#u.fill(void 0),this.#l.fill(void 0),this.#w&&this.#m&&(this.#w.fill(0),this.#m.fill(0)),this.#b&&this.#b.fill(0),this.#f=0,this.#v=0,this.#y.length=0,this.#c=0,this.#a=0,this.#T&&this.#g){const t=this.#g;let e;for(;e=t?.shift();)this.#n?.(...e)}}}const ys=Ye("rpc:InMemoryCache");class gs{constructor(t){this.clearCache=t=>{var e,s;ys("clearCache"),t?null===(e=this.cachedResponseByParams)||void 0===e||e.delete(o(t)):null===(s=this.cachedResponseByParams)||void 0===s||s.clear()},this.getCachedResponse=t=>{var e;ys("getCachedResponse, key: ",t);let s=null===(e=this.cachedResponseByParams)||void 0===e?void 0:e.get(o(t));return"string"==typeof s&&(s=JSON.parse(s)),s},this.setCachedResponse=(t,e)=>{var s,i;ys("setCachedResponse",t,e);const n=o(t);if(!e)return null===(s=this.cachedResponseByParams)||void 0===s?void 0:s.delete(n);const r=Object.assign({},e);delete r.correlationId,null===(i=this.cachedResponseByParams)||void 0===i||i.set(n,r?JSON.stringify(r):void 0)},this.cachedResponseByParams=new vs({max:(null==t?void 0:t.cacheMaxSize)||gs.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||gs.DEFAULT_CACHE_MAX_AGE_MS})}}var bs;gs.DEFAULT_CACHE_MAX_AGE_MS=9e5,gs.DEFAULT_CACHE_MAX_SIZE=200,t.TransportType=void 0,(bs=t.TransportType||(t.TransportType={})).http="http",bs.websocket="websocket";const ms=t=>`${t.scope}::${t.procedure}::${t.version}`,ws=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}},Ss=Ye("rpc:HTTPTransport");class _s{constructor(s){this.options=s,this.name="HttpTransport",this.type=t.TransportType.http,this.isConnected=()=>{var t;return"undefined"!=typeof window?!!(null===(t=null===window||void 0===window?void 0:window.navigator)||void 0===t?void 0:t.onLine):"function"==typeof fetch},this.sendRequest=(t,s)=>e(this,void 0,void 0,(function*(){Ss("sendRequest",t);try{const e=JSON.stringify(Object.assign({identity:this.identity},t)),s=yield fetch(this.host,{body:e,cache:"default",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"follow",referrerPolicy:"origin"}),i=yield s.text();if(!i)throw new Error("No response received from remote");const n=JSON.parse(i);return new a(n)}catch(e){throw Ss("sendRequest() error",e),new es(`HTTPTransport request error ${ms(t)} (${null==e?void 0:e.message})`)}})),this.setIdentity=t=>{Ss("setIdentity",t),this.identity=t},this.host=s.host}}class Ts{constructor(t,s){this.reject=t=>{this.rejectPromise&&this.rejectPromise(t)},this.resolve=t=>{this.resolvePromise&&this.resolvePromise(t)},this.promise=new Promise(((i,n)=>e(this,void 0,void 0,(function*(){const e=setTimeout((()=>{n(new Error(`PromiseWraper timeout: ${t}`))}),s||3e4);this.rejectPromise=t=>{clearTimeout(e),n(t)},this.resolvePromise=t=>{clearTimeout(e),i(t)}}))))}}const Cs=t=>new Promise((e=>setTimeout(e,t))),js=Ye("rpc:WebSocketTransport");class Os{constructor(s){var i,n;this.options=s,this.connectedToRemote=!1,this.isWaitingForIdentityConfirmation=!1,this.pendingPromisesForResponse={},this.serverMessageHandlers=[],this.websocketId=void 0,this.name="WebSocketTransport",this.type=t.TransportType.websocket,this.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.connect=()=>{this._connect()},this.disconnect=()=>{this._disconnect("public disconnect() called")},this.sendClientMessageToServer=t=>{var e;let s=t;try{s=JSON.stringify({clientMessage:t})}catch(e){console.warn('WebSocketTransport.sendClientMessage() unable to stringify "msg"',t)}null===(e=this.websocket)||void 0===e||e.send(s)},this.sendRequest=(t,s)=>e(this,void 0,void 0,(function*(){js("sendRequest",t);let e=0;for(;this.isWaitingForIdentityConfirmation;){if(js("waiting for identity confirmation"),e++,e>=20)throw new es("Timed out waiting for identity confirmation");yield Cs(100)}return this.sendCall(t,s)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(js("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?js('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t},{}).then((()=>{js("setIdentity with remote complete")})).catch((t=>{js("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):js("setIdentity is not connected to remote")})),this.subscribeToServerMessages=t=>(this.serverMessageHandlers.push(t),()=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))}),this.unsubscribeFromServerMessages=t=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))},this._connect=()=>{if(js("connect",this.host),this.websocket)return void js("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info(`[${(new Date).toLocaleTimeString()}] WebSocket connected`),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info(`[${(new Date).toLocaleTimeString()}] WebSocket closed`,t.reason||t.code):js("WebSocket closed, it was not connected to the remote"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,this.websocket=void 0,this.websocketId=void 0,Object.entries(this.pendingPromisesForResponse).forEach((([t,e])=>{e.reject(new es("Websocket closed"))})),t.wasClean||setTimeout((()=>{this.connect()}),1e3)},t.onerror=e=>{this.connectedToRemote?console.error("WebSocket encountered error: ",e):js("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>e(this,void 0,void 0,(function*(){var e;js("_disconnect"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,null===(e=this.websocket)||void 0===e||e.close(1e3,t),this.websocket=void 0,this.websocketId=void 0})),this.handleServerMessage=t=>{this.serverMessageHandlers.forEach((e=>{try{e(t.serverMessage)}catch(s){console.warn("WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling",t,"handler func:",e),console.error(s)}}))},this.handleWebSocketMsg=t=>{let e;js("handleWebSocketMsg",t);try{e=JSON.parse(t.data)}catch(t){return void js("error parsing WS msg",t)}if(e&&"serverMessage"in e)return void this.handleServerMessage(e);const s=new a(e);if(!s.correlationId)return void console.error("RPCClient WebSocketTransport received unexpected msg from the server, not correlationId found in response.",e);const i=this.pendingPromisesForResponse[s.correlationId];i?i.resolve(s):console.warn("rcvd WS msg/response that doesn't match any pending RPC's",e)},this.resetConnection=()=>e(this,void 0,void 0,(function*(){js("resetConnection");const t=this.isConnected();return yield this._disconnect("WebSocketTransport#resetConnection"),t&&(yield Cs(300),yield this._connect()),this.isConnected()})),this.sendCall=(t,s)=>e(this,void 0,void 0,(function*(){var e;js("sendCall",t);const i=`${Date.now()}-${Math.random().toString()}`;t.correlationId=t.correlationId||i;const n=new Ts(ms(t),s.timeout||this.options.rpcOptions.deadlineMs);if(!this.isConnected()){const t=new es("Cannot send message: WebSocket is not connected");return js("sendCall failed - websocket not connected",t),n.reject(t),n.promise}return null===(e=this.websocket)||void 0===e||e.send(JSON.stringify(t)),this.pendingPromisesForResponse[t.correlationId]=n,yield n.promise.finally((()=>{delete this.pendingPromisesForResponse[t.correlationId]}))})),this.setConnectedToRemote=t=>{js(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},js("new WebSocketTransport()"),this.host=s.host,!1!==(null===(n=null===(i=s.rpcOptions.transportOptions)||void 0===i?void 0:i.websocket)||void 0===n?void 0:n.autoConnect)&&this.connect()}}class As{constructor(){this.events={},this.publish=(t,s)=>e(this,void 0,void 0,(function*(){const e=this.events[t];e&&e.forEach((function(t){t.call(t,s)}))})),this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>this.unsubscribe(t,e)),this.unsubscribe=(t,e)=>{if(!this.events[t])return;let s=this.events[t].indexOf(e);this.events[t].splice(s)}}}const ks={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Es{constructor(t){var s,i,r,a,h,l;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new As,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,s,i)=>e(this,void 0,void 0,(function*(){if(!t)throw new Error('RPCClient.call(request) requires a "request" param');let e;e="string"==typeof t?ws(t):t,s&&(e.args=s);const r=new n(e);if(!r.procedure&&!r.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');r.identity||(r.identity={}),r.identity=Ze(Object.assign({},this.identity),r.identity);const a=yield this.callManager.manageClientRequest(r,i);if(!a.success)throw new c(a,r,i);const h=o(e);return this.vent.publish(h,null==a?void 0:a.data),a})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let s;s="string"==typeof t?ws(t):t,e&&(s.args=e);const i=this.callManager.getCachedResponse(s);if(i)return i},this.getIdentity=()=>this.identity?$e(this.identity):this.identity,this.getInFlightCallCount=()=>this.callManager.getInFlightCallCount(),this.getWebSocketConnected=()=>{var t;return!!(null===(t=null==this?void 0:this.webSocketTransport)||void 0===t?void 0:t.isConnected())},this.makeProcedure=t=>{const e=this;let s;return s="string"==typeof t?ws(t):t,function(t){return e.call(Object.assign(Object.assign({},s),{args:t}))}},this.registerResponseInterceptor=t=>this.callManager.addResponseInterceptor(t),this.registerRequestInterceptor=t=>this.callManager.addRequestInterceptor(t),this.registerWebSocketConnectionStatusChangeListener=t=>(this.webSocketConnectionChangeListeners.push(t),()=>{this.webSocketConnectionChangeListeners=this.webSocketConnectionChangeListeners.filter((e=>e!==t))}),this.sendClientMessageToServer=t=>{this.webSocketTransport?this.webSocketTransport.isConnected()?this.webSocketTransport.sendClientMessageToServer(t):console.info("RPCClient.sendClientMessageToServer() cannot send because the websocket is not connected"):console.warn("RPCClient.sendClientMessageToServer() unable to send because RPCClient has no websocket configuration")},this.setIdentity=t=>{let e=$e(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const s=$e(this.identity);s.metadata=t,this.identity.metadata=t,this.callManager.setIdentity(s)},this.transports=()=>({http:this.httpTransport,websocket:this.webSocketTransport}),!(null===(s=null==t?void 0:t.hosts)||void 0===s?void 0:s.http)&&!(null===(i=null==t?void 0:t.transports)||void 0===i?void 0:i.http))throw new Error(ks.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(ks.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(ks.INTERCEPTOR_MUSTBE_FUNC);let u;const d={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};u="browser"==t.cacheType?new ns(d):new gs(d);const p=[];(null===(r=t.transports)||void 0===r?void 0:r.websocket)?p.push(t.transports.websocket):(null===(a=null==t?void 0:t.hosts)||void 0===a?void 0:a.websocket)&&(this.webSocketTransport=new Os({host:t.hosts.websocket,onConnectionStatusChange:this.onWebSocketConnectionStatusChange,rpcOptions:t}),p.push(this.webSocketTransport)),(null===(h=t.transports)||void 0===h?void 0:h.http)?p.push(t.transports.http):(null===(l=null==t?void 0:t.hosts)||void 0===l?void 0:l.http)&&(this.httpTransport=new _s({host:t.hosts.http,rpcOptions:t}),p.push(this.httpTransport)),this.callManager=new is({cache:u,deadlineMs:t.deadlineMs||Es.DEFAULT_DEADLINE_MS,onTransportRequestError:t.onTransportRequestError,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:p,transportOptions:t.transportOptions})}subscribe(t,e){const s="string"==typeof t.request?ws(t.request):t.request,i=o(Object.assign(Object.assign({},s),{args:t.args}));return this.vent.subscribe(i,e)}unsubscribe(t,e){const s="string"==typeof t.request?ws(t.request):t.request,i=o(Object.assign(Object.assign({},s),{args:t.args}));this.vent.unsubscribe(i,e)}subscribeToServerMessages(t){return this.webSocketTransport?this.webSocketTransport.subscribeToServerMessages(t):(console.warn("RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration"),()=>{})}unsubscribeFromServerMessages(t){var e;null===(e=this.webSocketTransport)||void 0===e||e.unsubscribeFromServerMessages(t)}}Es.DEFAULT_DEADLINE_MS=1e4,t.CallRequestTransportError=es,t.CallRequestTransportTimeoutError=ts,t.CallResponseError=c,t.RPCClient=Es,t.RPCResponse=a})); |
{ | ||
"name": "@therms/rpc-client", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "RPC framework, browser client lib", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -265,3 +265,3 @@ import { Cache } from '../cache/Cache' | ||
debug( | ||
`sendRequestWithTransport trying ${this.transports[transportsIndex].name}`, | ||
`sendRequestWithTransport trying ${transports[transportsIndex].name}`, | ||
request, | ||
@@ -268,0 +268,0 @@ ) |
@@ -29,3 +29,2 @@ import { Transport, TransportType } from './Transport' | ||
private isWaitingForIdentityConfirmation: boolean = false | ||
// private inFlightCallCount: number = 0; | ||
private pendingPromisesForResponse: { | ||
@@ -39,3 +38,2 @@ [correlationId: string]: PromiseWrapper< | ||
private websocket?: WebSocket | ||
// we keep a connection ID in case the ws connection changes mid-flight for requests | ||
private websocketId?: number = undefined | ||
@@ -45,3 +43,3 @@ | ||
readonly type = TransportType.http | ||
readonly type = TransportType.websocket | ||
@@ -53,3 +51,2 @@ constructor(readonly options: WebSocketTransportOptions) { | ||
if (options.rpcOptions.transportOptions?.websocket?.autoConnect !== false) { | ||
// default to true, auto-connect | ||
this.connect() | ||
@@ -92,5 +89,13 @@ } | ||
let waitCount = 0 | ||
const maxWaitAttempts = 20 // 2 seconds max wait (20 * 100ms) | ||
while (this.isWaitingForIdentityConfirmation) { | ||
debug('waiting for identity confirmation') | ||
waitCount++ | ||
if (waitCount >= maxWaitAttempts) { | ||
throw new CallRequestTransportError( | ||
'Timed out waiting for identity confirmation', | ||
) | ||
} | ||
await sleep(100) | ||
@@ -102,6 +107,2 @@ } | ||
/** | ||
* Set the identity of this WS connection with the server. | ||
* @param identity {RPCClientIdentity} If no identity passed, this method will reset/clear the identity | ||
*/ | ||
public setIdentity = async (identity?: RPCClientIdentity) => { | ||
@@ -225,3 +226,3 @@ debug('setIdentity', identity) | ||
private _disconnect = (reason?: string) => { | ||
private _disconnect = async (reason?: string) => { | ||
debug('_disconnect') | ||
@@ -254,3 +255,3 @@ this.setConnectedToRemote(false) | ||
let json | ||
let json: any | ||
@@ -260,6 +261,8 @@ try { | ||
} catch (e: any) { | ||
console.error('error parsing WS msg', e) | ||
debug('error parsing WS msg', e) | ||
return // Exit early if JSON parsing fails | ||
} | ||
if ('serverMessage' in json) { | ||
// Check if json is defined and has the serverMessage property | ||
if (json && 'serverMessage' in json) { | ||
this.handleServerMessage(json) | ||
@@ -297,10 +300,12 @@ | ||
this._disconnect('WebSocketTransport#resetConnection') | ||
// Store current connection state | ||
const wasConnected = this.isConnected() | ||
if ( | ||
this.options.rpcOptions.transportOptions?.websocket?.autoConnect !== false | ||
) { | ||
await sleep(100) | ||
this._connect() | ||
await this._disconnect('WebSocketTransport#resetConnection') | ||
if (wasConnected) { | ||
await sleep(300) // delay to avoid race conditions | ||
await this._connect() | ||
} | ||
return this.isConnected() | ||
} | ||
@@ -314,7 +319,8 @@ | ||
const correlationId = Math.random().toString() | ||
// Generate a more robust correlation ID using timestamp + random | ||
const correlationId = `${Date.now()}-${Math.random().toString()}` | ||
call.correlationId = call.correlationId || correlationId | ||
let promiseWrapper = new PromiseWrapper< | ||
const promiseWrapper = new PromiseWrapper< | ||
CallResponseDTO, | ||
@@ -327,2 +333,12 @@ CallResponseDTO | CallRequestTransportError | ||
// Check if websocket is connected before sending | ||
if (!this.isConnected()) { | ||
const error = new CallRequestTransportError( | ||
'Cannot send message: WebSocket is not connected', | ||
) | ||
debug('sendCall failed - websocket not connected', error) | ||
promiseWrapper.reject(error) | ||
return promiseWrapper.promise | ||
} | ||
this.websocket?.send(JSON.stringify(call)) | ||
@@ -329,0 +345,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Explicitly Unlicensed Item
License(Experimental) Something was found which is explicitly marked as unlicensed.
Found 1 instance in 1 package
Explicitly Unlicensed Item
License(Experimental) Something was found which is explicitly marked as unlicensed.
Found 1 instance in 1 package
349683
0.83%3951
1.07%