@therms/rpc-client
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -0,1 +1,8 @@ | ||
# [2.7.0](https://bitbucket.org/thermsio/rpc-client-ts/compare/v2.6.0...v2.7.0) (2022-06-14) | ||
### Features | ||
* add sendClientMessageToServer() for sending clientMessage's to RPC-server ([98a3fb4](https://bitbucket.org/thermsio/rpc-client-ts/commits/98a3fb4ecca3251a5f424532aded09129f3a7619)) | ||
# [2.6.0](https://bitbucket.org/thermsio/rpc-client-ts/compare/v2.5.4...v2.6.0) (2022-06-11) | ||
@@ -2,0 +9,0 @@ |
@@ -475,7 +475,32 @@ 'use strict'; | ||
this.pendingPromisesForResponse = {}; | ||
this.serverMessageHandlers = []; | ||
this.websocketId = undefined; | ||
this.name = 'WebSocketTransport'; | ||
this.handleServerMessage = (msg) => { | ||
this.serverMessageHandlers.forEach((handler) => { | ||
try { | ||
handler(msg.serverMessage); | ||
} | ||
catch (err) { | ||
console.warn(`WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling`, msg); | ||
console.error(err); | ||
} | ||
}); | ||
}; | ||
this.isConnected = () => { | ||
return this.connectedToRemote && !!this.websocket; | ||
}; | ||
this.sendClientMessageToServer = (msg) => { | ||
var _a; | ||
let strMsg = msg; | ||
try { | ||
if (typeof strMsg !== 'string') { | ||
strMsg = JSON.stringify(msg); | ||
} | ||
} | ||
catch (err) { | ||
console.warn('WebSocketTransport.sendClientMessage() unable to stringify "msg"', msg); | ||
} | ||
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(strMsg); | ||
}; | ||
this.sendRequest = (call) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -487,3 +512,3 @@ debug('sendRequest', call); | ||
} | ||
return this.send(call); | ||
return this.sendCall(call); | ||
}); | ||
@@ -509,3 +534,3 @@ this.setIdentity = (identity) => __awaiter(this, void 0, void 0, function* () { | ||
this.isWaitingForIdentityConfirmation = true; | ||
this.send({ identity }) | ||
this.sendCall({ identity }) | ||
.then(() => { | ||
@@ -585,2 +610,6 @@ debug('setIdentity with remote complete'); | ||
} | ||
if ('serverMessage' in json) { | ||
this.handleServerMessage(json); | ||
return; | ||
} | ||
const callResponseDTO = new CallResponseDTO(json); | ||
@@ -605,5 +634,5 @@ if (!callResponseDTO.correlationId) { | ||
}); | ||
this.send = (call) => __awaiter(this, void 0, void 0, function* () { | ||
this.sendCall = (call) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
debug('send', call); | ||
debug('sendCall', call); | ||
const correlationId = Math.random().toString(); | ||
@@ -757,2 +786,14 @@ call.correlationId = call.correlationId || correlationId; | ||
}; | ||
this.sendClientMessageToServer = (msg) => { | ||
if (!this.webSocketTransport) { | ||
console.warn('RPCClient.sendClientMessageToServer() unable to send because RPCClient has no websocket configuration'); | ||
return; | ||
} | ||
if (this.webSocketTransport.isConnected()) { | ||
this.webSocketTransport.sendClientMessageToServer(msg); | ||
} | ||
else { | ||
console.info('RPCClient.sendClientMessageToServer() cannot send because the websocket is not connected'); | ||
} | ||
}; | ||
this.setIdentity = (identity) => { | ||
@@ -759,0 +800,0 @@ let newIdentity = lodashEs.cloneDeep(identity); |
@@ -66,2 +66,3 @@ import { CallRequestDTO } from './CallRequestDTO'; | ||
registerWebSocketConnectionStatusChangeListener: (cb: (connected: boolean) => void) => void; | ||
sendClientMessageToServer: (msg: any) => void; | ||
setIdentity: (identity?: RPCClientIdentity | undefined) => void; | ||
@@ -68,0 +69,0 @@ setIdentityMetadata: (metadata?: Record<string, any> | undefined) => void; |
@@ -100,2 +100,14 @@ import { __awaiter } from './node_modules/tslib/tslib.es6.js'; | ||
}; | ||
this.sendClientMessageToServer = (msg) => { | ||
if (!this.webSocketTransport) { | ||
console.warn('RPCClient.sendClientMessageToServer() unable to send because RPCClient has no websocket configuration'); | ||
return; | ||
} | ||
if (this.webSocketTransport.isConnected()) { | ||
this.webSocketTransport.sendClientMessageToServer(msg); | ||
} | ||
else { | ||
console.info('RPCClient.sendClientMessageToServer() cannot send because the websocket is not connected'); | ||
} | ||
}; | ||
this.setIdentity = (identity) => { | ||
@@ -102,0 +114,0 @@ let newIdentity = cloneDeep(identity); |
@@ -18,2 +18,3 @@ import { Transport } from './Transport'; | ||
private pendingPromisesForResponse; | ||
private serverMessageHandlers; | ||
private websocket?; | ||
@@ -23,3 +24,7 @@ private websocketId?; | ||
constructor(options: WebSocketTransportOptions); | ||
handleServerMessage: (msg: { | ||
serverMessage: any; | ||
}) => void; | ||
isConnected: () => boolean; | ||
sendClientMessageToServer: (msg: any) => void; | ||
sendRequest: (call: CallRequestDTO) => Promise<CallResponseDTO>; | ||
@@ -31,3 +36,3 @@ setIdentity: (identity?: RPCClientIdentity) => Promise<void>; | ||
private resetConnection; | ||
private send; | ||
private sendCall; | ||
private setConnectedToRemote; | ||
@@ -34,0 +39,0 @@ } |
@@ -15,7 +15,32 @@ import { __awaiter } from '../node_modules/tslib/tslib.es6.js'; | ||
this.pendingPromisesForResponse = {}; | ||
this.serverMessageHandlers = []; | ||
this.websocketId = undefined; | ||
this.name = 'WebSocketTransport'; | ||
this.handleServerMessage = (msg) => { | ||
this.serverMessageHandlers.forEach((handler) => { | ||
try { | ||
handler(msg.serverMessage); | ||
} | ||
catch (err) { | ||
console.warn(`WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling`, msg); | ||
console.error(err); | ||
} | ||
}); | ||
}; | ||
this.isConnected = () => { | ||
return this.connectedToRemote && !!this.websocket; | ||
}; | ||
this.sendClientMessageToServer = (msg) => { | ||
var _a; | ||
let strMsg = msg; | ||
try { | ||
if (typeof strMsg !== 'string') { | ||
strMsg = JSON.stringify(msg); | ||
} | ||
} | ||
catch (err) { | ||
console.warn('WebSocketTransport.sendClientMessage() unable to stringify "msg"', msg); | ||
} | ||
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(strMsg); | ||
}; | ||
this.sendRequest = (call) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -27,3 +52,3 @@ debug('sendRequest', call); | ||
} | ||
return this.send(call); | ||
return this.sendCall(call); | ||
}); | ||
@@ -49,3 +74,3 @@ this.setIdentity = (identity) => __awaiter(this, void 0, void 0, function* () { | ||
this.isWaitingForIdentityConfirmation = true; | ||
this.send({ identity }) | ||
this.sendCall({ identity }) | ||
.then(() => { | ||
@@ -125,2 +150,6 @@ debug('setIdentity with remote complete'); | ||
} | ||
if ('serverMessage' in json) { | ||
this.handleServerMessage(json); | ||
return; | ||
} | ||
const callResponseDTO = new CallResponseDTO(json); | ||
@@ -145,5 +174,5 @@ if (!callResponseDTO.correlationId) { | ||
}); | ||
this.send = (call) => __awaiter(this, void 0, void 0, function* () { | ||
this.sendCall = (call) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
debug('send', call); | ||
debug('sendCall', call); | ||
const correlationId = Math.random().toString(); | ||
@@ -150,0 +179,0 @@ call.correlationId = call.correlationId || correlationId; |
@@ -1,2 +0,2 @@ | ||
!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,i,n){return new(i||(i=Promise))((function(s,r){function o(t){try{c(n.next(t))}catch(t){r(t)}}function a(t){try{c(n.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}c((n=n.apply(t,e||[])).next())}))}class i{constructor(t){const{args:e,correlationId:i,identity:n,procedure:s,scope:r,version:o}=t;if(this.args=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i||Math.random().toString(),n){if("object"!=typeof n)throw new Error("identity must be an object");if(n.authorization&&"string"!=typeof n.authorization)throw new Error("identity.authorization must be a string");if(n.deviceName&&"string"!=typeof n.deviceName)throw new Error("identity.deviceName must be a string");if(n.metadata&&"object"!=typeof n.metadata)throw new Error("identity.metadata must be a object");this.identity=n}if(s&&"string"!=typeof s)throw new Error("procedure must be string");if(this.procedure=s,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}}class n extends Error{}class s extends Error{}class r extends Error{}function o(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}const a=t=>t.args?`${t.scope}${t.procedure}${t.version}${function(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});var i,n="boolean"==typeof e.cycles&&e.cycles,s=e.cmp&&(i=e.cmp,function(t){return function(e,n){var s={key:e,value:t[e]},r={key:n,value:t[n]};return i(s,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 i,o;if(Array.isArray(e)){for(o="[",i=0;i<e.length;i++)i&&(o+=","),o+=t(e[i])||"null";return o+"]"}if(null===e)return"null";if(-1!==r.indexOf(e)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(e)-1,c=Object.keys(e).sort(s&&s(e));for(o="",i=0;i<c.length;i++){var h=c[i],l=t(e[h]);l&&(o&&(o+=","),o+=JSON.stringify(h)+":"+l)}return r.splice(a,1),"{"+o+"}"}}(t)}(function(t,e={}){if(!o(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:i,compare:n}=e,s=[],r=[],a=t=>{const e=s.indexOf(t);if(-1!==e)return r[e];const i=[];return s.push(t),r.push(i),i.push(...t.map((t=>Array.isArray(t)?a(t):o(t)?c(t):t))),i},c=t=>{const e=s.indexOf(t);if(-1!==e)return r[e];const h={},l=Object.keys(t).sort(n);s.push(t),r.push(h);for(const e of l){const n=t[e];let s;s=i&&Array.isArray(n)?a(n):i&&o(n)?c(n):n,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:s}))}return h};return Array.isArray(t)?i?a(t):t.slice():c(t)}(t.args||{},{deep:!0}))}`:`${t.scope}${t.procedure}${t.version}`;var c="object"==typeof global&&global&&global.Object===Object&&global,h="object"==typeof self&&self&&self.Object===Object&&self,l=c||h||Function("return this")(),u=l.Symbol,d=Object.prototype,p=d.hasOwnProperty,f=d.toString,y=u?u.toStringTag:void 0;var v=Object.prototype.toString;var g=u?u.toStringTag:void 0;function b(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?function(t){var e=p.call(t,y),i=t[y];try{t[y]=void 0;var n=!0}catch(t){}var s=f.call(t);return n&&(e?t[y]=i:delete t[y]),s}(t):function(t){return v.call(t)}(t)}function w(t){return null!=t&&"object"==typeof t}var m=Array.isArray;function _(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function j(t){return t}function S(t){if(!_(t))return!1;var e=b(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var C,O=l["__core-js_shared__"],T=(C=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+C:"";var A=Function.prototype.toString;function I(t){if(null!=t){try{return A.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var k=/^\[object .+?Constructor\]$/,E=Function.prototype,R=Object.prototype,z=E.toString,x=R.hasOwnProperty,M=RegExp("^"+z.call(x).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function L(t){return!(!_(t)||(e=t,T&&T in e))&&(S(t)?M:k).test(I(t));var e}function F(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return L(i)?i:void 0}var P=F(l,"WeakMap"),W=Object.create,U=function(){function t(){}return function(e){if(!_(e))return{};if(W)return W(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function q(t,e,i){switch(i.length){case 0:return t.call(e);case 1:return t.call(e,i[0]);case 2:return t.call(e,i[0],i[1]);case 3:return t.call(e,i[0],i[1],i[2])}return t.apply(e,i)}function D(t,e){var i=-1,n=t.length;for(e||(e=Array(n));++i<n;)e[i]=t[i];return e}var N=Date.now;var B,$,H,G=function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G,V=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(i=e,function(){return i}),writable:!0});var i}:j,K=(B=V,$=0,H=0,function(){var t=N(),e=16-(t-H);if(H=t,e>0){if(++$>=800)return arguments[0]}else $=0;return B.apply(void 0,arguments)}),X=K;var Z=/^(?:0|[1-9]\d*)$/;function Q(t,e){var i=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==i||"symbol"!=i&&Z.test(t))&&t>-1&&t%1==0&&t<e}function Y(t,e,i){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}function tt(t,e){return t===e||t!=t&&e!=e}var et=Object.prototype.hasOwnProperty;function it(t,e,i){var n=t[e];et.call(t,e)&&tt(n,i)&&(void 0!==i||e in t)||Y(t,e,i)}function nt(t,e,i,n){var s=!i;i||(i={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=n?n(i[a],t[a],a,i,t):void 0;void 0===c&&(c=t[a]),s?Y(i,a,c):it(i,a,c)}return i}var st=Math.max;function rt(t,e){return X(function(t,e,i){return e=st(void 0===e?t.length-1:e,0),function(){for(var n=arguments,s=-1,r=st(n.length-e,0),o=Array(r);++s<r;)o[s]=n[e+s];s=-1;for(var a=Array(e+1);++s<e;)a[s]=n[s];return a[e]=i(o),q(t,this,a)}}(t,e,j),t+"")}function ot(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function at(t){return null!=t&&ot(t.length)&&!S(t)}var ct=Object.prototype;function ht(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ct)}function lt(t){return w(t)&&"[object Arguments]"==b(t)}var ut=Object.prototype,dt=ut.hasOwnProperty,pt=ut.propertyIsEnumerable,ft=lt(function(){return arguments}())?lt:function(t){return w(t)&&dt.call(t,"callee")&&!pt.call(t,"callee")},yt=ft;var vt="object"==typeof t&&t&&!t.nodeType&&t,gt=vt&&"object"==typeof module&&module&&!module.nodeType&&module,bt=gt&>.exports===vt?l.Buffer:void 0,wt=(bt?bt.isBuffer:void 0)||function(){return!1},mt={};function _t(t){return function(e){return t(e)}}mt["[object Float32Array]"]=mt["[object Float64Array]"]=mt["[object Int8Array]"]=mt["[object Int16Array]"]=mt["[object Int32Array]"]=mt["[object Uint8Array]"]=mt["[object Uint8ClampedArray]"]=mt["[object Uint16Array]"]=mt["[object Uint32Array]"]=!0,mt["[object Arguments]"]=mt["[object Array]"]=mt["[object ArrayBuffer]"]=mt["[object Boolean]"]=mt["[object DataView]"]=mt["[object Date]"]=mt["[object Error]"]=mt["[object Function]"]=mt["[object Map]"]=mt["[object Number]"]=mt["[object Object]"]=mt["[object RegExp]"]=mt["[object Set]"]=mt["[object String]"]=mt["[object WeakMap]"]=!1;var jt="object"==typeof t&&t&&!t.nodeType&&t,St=jt&&"object"==typeof module&&module&&!module.nodeType&&module,Ct=St&&St.exports===jt&&c.process,Ot=function(){try{var t=St&&St.require&&St.require("util").types;return t||Ct&&Ct.binding&&Ct.binding("util")}catch(t){}}(),Tt=Ot&&Ot.isTypedArray,At=Tt?_t(Tt):function(t){return w(t)&&ot(t.length)&&!!mt[b(t)]},It=Object.prototype.hasOwnProperty;function kt(t,e){var i=m(t),n=!i&&yt(t),s=!i&&!n&&wt(t),r=!i&&!n&&!s&&At(t),o=i||n||s||r,a=o?function(t,e){for(var i=-1,n=Array(t);++i<t;)n[i]=e(i);return n}(t.length,String):[],c=a.length;for(var h in t)!e&&!It.call(t,h)||o&&("length"==h||s&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||Q(h,c))||a.push(h);return a}function Et(t,e){return function(i){return t(e(i))}}var Rt=Et(Object.keys,Object),zt=Object.prototype.hasOwnProperty;function xt(t){return at(t)?kt(t):function(t){if(!ht(t))return Rt(t);var e=[];for(var i in Object(t))zt.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var Mt=Object.prototype.hasOwnProperty;function Lt(t){if(!_(t))return function(t){var e=[];if(null!=t)for(var i in Object(t))e.push(i);return e}(t);var e=ht(t),i=[];for(var n in t)("constructor"!=n||!e&&Mt.call(t,n))&&i.push(n);return i}function Ft(t){return at(t)?kt(t,!0):Lt(t)}var Pt=F(Object,"create");var Wt=Object.prototype.hasOwnProperty;var Ut=Object.prototype.hasOwnProperty;function qt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}function Dt(t,e){for(var i=t.length;i--;)if(tt(t[i][0],e))return i;return-1}qt.prototype.clear=function(){this.__data__=Pt?Pt(null):{},this.size=0},qt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},qt.prototype.get=function(t){var e=this.__data__;if(Pt){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return Wt.call(e,t)?e[t]:void 0},qt.prototype.has=function(t){var e=this.__data__;return Pt?void 0!==e[t]:Ut.call(e,t)},qt.prototype.set=function(t,e){var i=this.__data__;return this.size+=this.has(t)?0:1,i[t]=Pt&&void 0===e?"__lodash_hash_undefined__":e,this};var Nt=Array.prototype.splice;function Bt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}Bt.prototype.clear=function(){this.__data__=[],this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,i=Dt(e,t);return!(i<0)&&(i==e.length-1?e.pop():Nt.call(e,i,1),--this.size,!0)},Bt.prototype.get=function(t){var e=this.__data__,i=Dt(e,t);return i<0?void 0:e[i][1]},Bt.prototype.has=function(t){return Dt(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var i=this.__data__,n=Dt(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this};var $t=F(l,"Map");function Ht(t,e){var i,n,s=t.__data__;return("string"==(n=typeof(i=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==i:null===i)?s["string"==typeof e?"string":"hash"]:s.map}function Gt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}function Jt(t,e){for(var i=-1,n=e.length,s=t.length;++i<n;)t[s+i]=e[i];return t}Gt.prototype.clear=function(){this.size=0,this.__data__={hash:new qt,map:new($t||Bt),string:new qt}},Gt.prototype.delete=function(t){var e=Ht(this,t).delete(t);return this.size-=e?1:0,e},Gt.prototype.get=function(t){return Ht(this,t).get(t)},Gt.prototype.has=function(t){return Ht(this,t).has(t)},Gt.prototype.set=function(t,e){var i=Ht(this,t),n=i.size;return i.set(t,e),this.size+=i.size==n?0:1,this};var Vt=Et(Object.getPrototypeOf,Object),Kt=Function.prototype,Xt=Object.prototype,Zt=Kt.toString,Qt=Xt.hasOwnProperty,Yt=Zt.call(Object);function te(t){var e=this.__data__=new Bt(t);this.size=e.size}te.prototype.clear=function(){this.__data__=new Bt,this.size=0},te.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},te.prototype.get=function(t){return this.__data__.get(t)},te.prototype.has=function(t){return this.__data__.has(t)},te.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Bt){var n=i.__data__;if(!$t||n.length<199)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new Gt(n)}return i.set(t,e),this.size=i.size,this};var ee="object"==typeof t&&t&&!t.nodeType&&t,ie=ee&&"object"==typeof module&&module&&!module.nodeType&&module,ne=ie&&ie.exports===ee?l.Buffer:void 0,se=ne?ne.allocUnsafe:void 0;function re(t,e){if(e)return t.slice();var i=t.length,n=se?se(i):new t.constructor(i);return t.copy(n),n}function oe(){return[]}var ae=Object.prototype.propertyIsEnumerable,ce=Object.getOwnPropertySymbols,he=ce?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var i=-1,n=null==t?0:t.length,s=0,r=[];++i<n;){var o=t[i];e(o,i,t)&&(r[s++]=o)}return r}(ce(t),(function(e){return ae.call(t,e)})))}:oe;var le=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Jt(e,he(t)),t=Vt(t);return e}:oe;function ue(t,e,i){var n=e(t);return m(t)?n:Jt(n,i(t))}function de(t){return ue(t,xt,he)}function pe(t){return ue(t,Ft,le)}var fe=F(l,"DataView"),ye=F(l,"Promise"),ve=F(l,"Set"),ge="[object Map]",be="[object Promise]",we="[object Set]",me="[object WeakMap]",_e="[object DataView]",je=I(fe),Se=I($t),Ce=I(ye),Oe=I(ve),Te=I(P),Ae=b;(fe&&Ae(new fe(new ArrayBuffer(1)))!=_e||$t&&Ae(new $t)!=ge||ye&&Ae(ye.resolve())!=be||ve&&Ae(new ve)!=we||P&&Ae(new P)!=me)&&(Ae=function(t){var e=b(t),i="[object Object]"==e?t.constructor:void 0,n=i?I(i):"";if(n)switch(n){case je:return _e;case Se:return ge;case Ce:return be;case Oe:return we;case Te:return me}return e});var Ie=Ae,ke=Object.prototype.hasOwnProperty;var Ee=l.Uint8Array;function Re(t){var e=new t.constructor(t.byteLength);return new Ee(e).set(new Ee(t)),e}var ze=/\w*$/;var xe=u?u.prototype:void 0,Me=xe?xe.valueOf:void 0;function Le(t,e){var i=e?Re(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function Fe(t,e,i){var n,s,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return Re(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var i=e?Re(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);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 Le(t,i);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(s=t).constructor(s.source,ze.exec(s))).lastIndex=s.lastIndex,r;case"[object Symbol]":return n=t,Me?Object(Me.call(n)):{}}}function Pe(t){return"function"!=typeof t.constructor||ht(t)?{}:U(Vt(t))}var We=Ot&&Ot.isMap,Ue=We?_t(We):function(t){return w(t)&&"[object Map]"==Ie(t)};var qe=Ot&&Ot.isSet,De=qe?_t(qe):function(t){return w(t)&&"[object Set]"==Ie(t)},Ne="[object Arguments]",Be="[object Function]",$e="[object Object]",He={};function Ge(t,e,i,n,s,r){var o,a=1&e,c=2&e,h=4&e;if(i&&(o=s?i(t,n,s,r):i(t)),void 0!==o)return o;if(!_(t))return t;var l=m(t);if(l){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&ke.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return D(t,o)}else{var u=Ie(t),d=u==Be||"[object GeneratorFunction]"==u;if(wt(t))return re(t,a);if(u==$e||u==Ne||d&&!s){if(o=c||d?{}:Pe(t),!a)return c?function(t,e){return nt(t,le(t),e)}(t,function(t,e){return t&&nt(e,Ft(e),t)}(o,t)):function(t,e){return nt(t,he(t),e)}(t,function(t,e){return t&&nt(e,xt(e),t)}(o,t))}else{if(!He[u])return s?t:{};o=Fe(t,u,a)}}r||(r=new te);var p=r.get(t);if(p)return p;r.set(t,o),De(t)?t.forEach((function(n){o.add(Ge(n,e,i,n,t,r))})):Ue(t)&&t.forEach((function(n,s){o.set(s,Ge(n,e,i,s,t,r))}));var f=l?void 0:(h?c?pe:de:c?Ft:xt)(t);return function(t,e){for(var i=-1,n=null==t?0:t.length;++i<n&&!1!==e(t[i],i,t););}(f||t,(function(n,s){f&&(n=t[s=n]),it(o,s,Ge(n,e,i,s,t,r))})),o}He[Ne]=He["[object Array]"]=He["[object ArrayBuffer]"]=He["[object DataView]"]=He["[object Boolean]"]=He["[object Date]"]=He["[object Float32Array]"]=He["[object Float64Array]"]=He["[object Int8Array]"]=He["[object Int16Array]"]=He["[object Int32Array]"]=He["[object Map]"]=He["[object Number]"]=He[$e]=He["[object RegExp]"]=He["[object Set]"]=He["[object String]"]=He["[object Symbol]"]=He["[object Uint8Array]"]=He["[object Uint8ClampedArray]"]=He["[object Uint16Array]"]=He["[object Uint32Array]"]=!0,He["[object Error]"]=He[Be]=He["[object WeakMap]"]=!1;function Je(t){return Ge(t,5)}var Ve,Ke=function(t,e,i){for(var n=-1,s=Object(t),r=i(t),o=r.length;o--;){var a=r[Ve?o:++n];if(!1===e(s[a],a,s))break}return t};function Xe(t,e,i){(void 0!==i&&!tt(t[e],i)||void 0===i&&!(e in t))&&Y(t,e,i)}function Ze(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Qe(t,e,i,n,s,r,o){var a=Ze(t,i),c=Ze(e,i),h=o.get(c);if(h)Xe(t,i,h);else{var l,u=r?r(a,c,i+"",t,e,o):void 0,d=void 0===u;if(d){var p=m(c),f=!p&&wt(c),y=!p&&!f&&At(c);u=c,p||f||y?m(a)?u=a:w(l=a)&&at(l)?u=D(a):f?(d=!1,u=re(c,!0)):y?(d=!1,u=Le(c,!0)):u=[]:function(t){if(!w(t)||"[object Object]"!=b(t))return!1;var e=Vt(t);if(null===e)return!0;var i=Qt.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&Zt.call(i)==Yt}(c)||yt(c)?(u=a,yt(a)?u=function(t){return nt(t,Ft(t))}(a):_(a)&&!S(a)||(u=Pe(c))):d=!1}d&&(o.set(c,u),s(u,c,n,r,o),o.delete(c)),Xe(t,i,u)}}function Ye(t,e,i,n,s){t!==e&&Ke(e,(function(r,o){if(s||(s=new te),_(r))Qe(t,e,o,i,Ye,n,s);else{var a=n?n(Ze(t,o),r,o+"",t,e,s):void 0;void 0===a&&(a=r),Xe(t,o,a)}}),Ft)}var ti,ei=(ti=function(t,e,i){Ye(t,e,i)},rt((function(t,e){var i=-1,n=e.length,s=n>1?e[n-1]:void 0,r=n>2?e[2]:void 0;for(s=ti.length>3&&"function"==typeof s?(n--,s):void 0,r&&function(t,e,i){if(!_(i))return!1;var n=typeof e;return!!("number"==n?at(i)&&Q(e,i.length):"string"==n&&e in i)&&tt(i[e],t)}(e[0],e[1],r)&&(s=n<3?void 0:s,n=1),t=Object(t);++i<n;){var o=e[i];o&&ti(t,o,i,s)}return t})));let ii=null;try{ii=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const ni=t=>ii&&new RegExp(ii).test(t)?(...e)=>console.log(t,...e):()=>{},si=ni("rpc:ClientManager");class ri{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");this.interceptors.response.push(t)},this.addRequestInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");this.interceptors.request.push(t)},this.clearCache=t=>{si("clearCache"),this.cache&&(t?this.cache.setCachedResponse(t,void 0):this.cache.clearCache())},this.getCachedResponse=t=>{var e;return si("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(si("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=t=>e(this,void 0,void 0,(function*(){si("manageClientRequest",t);const i=yield this.interceptRequestMutator(t),n=a(i);if(this.inflightCallsByKey.hasOwnProperty(n))return si("manageClientRequest using an existing in-flight call",n),this.inflightCallsByKey[n].then((e=>{const i=Je(e);return t.correlationId&&(i.correlationId=t.correlationId),i}));const s=(()=>e(this,void 0,void 0,(function*(){const t=yield this.sendRequestWithTransport(i),e=yield this.interceptResponseMutator(t,i);return this.cache&&e&&this.cache.setCachedResponse(i,e),e})))().then((t=>(delete this.inflightCallsByKey[n],t))).catch((t=>{throw delete this.inflightCallsByKey[n],t}));return this.inflightCallsByKey[n]=s,yield s})),this.setIdentity=t=>{si("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.request.length){si("interceptRequestMutator(), original request:",t);for(const t of this.interceptors.request)e=yield t(e)}return e})),this.interceptResponseMutator=(t,i)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){si("interceptResponseMutator",i,t);for(const n of this.interceptors.response)try{e=yield n(e,i)}catch(n){throw si("caught response interceptor, request:",i,"original response:",t,"mutated response:",e),n}}return e})),this.sendRequestWithTransport=t=>e(this,void 0,void 0,(function*(){let e;si("sendRequestWithTransport",t);let i=0;for(;!e&&this.transports[i];){const n=this.transports[i];if(n.isConnected()){si(`sendRequestWithTransport trying ${this.transports[i].name}`,t);try{let i;const s=new Promise(((e,n)=>{i=setTimeout((()=>{n(new r(`Procedure ${t.procedure}`))}),this.options.deadlineMs)}));e=yield Promise.race([s,n.sendRequest(t)]).then((t=>(clearTimeout(i),t)))}catch(t){if(!(t instanceof r||t instanceof s))throw t;si(`sending request with ${this.transports[i].name} failed, trying next transport`),i++}}else i++}if(!e&&!this.transports[i])throw new n(`Procedure ${t.procedure} did not get a response from any transports`);if(!e)throw new n(`Procedure ${t.procedure} did not get a response from the remote`);return e})),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 oi{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}oi.DEFAULT_CACHE_MAX_AGE_MS=3e5,oi.DEFAULT_CACHE_MAX_SIZE=100;const ai="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,ci="function"==typeof AbortController,hi=ci?AbortController:class{constructor(){this.signal=new li}abort(){this.signal.dispatchEvent("abort")}},li=ci?AbortSignal:class{constructor(){this.aborted=!1,this._listeners=[]}dispatchEvent(t){if("abort"===t){this.aborted=!0;const e={type:t,target:this};this.onabort(e),this._listeners.forEach((t=>t(e)),this)}}onabort(){}addEventListener(t,e){"abort"===t&&this._listeners.push(e)}removeEventListener(t,e){"abort"===t&&(this._listeners=this._listeners.filter((t=>t!==e)))}},ui=new Set,di=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;yi(i)&&vi(i,`${t} option`,`options.${e}`,_i)},pi=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(yi(i)){const{prototype:n}=_i,{get:s}=Object.getOwnPropertyDescriptor(n,t);vi(i,`${t} method`,`cache.${e}()`,s)}},fi=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},yi=t=>!ui.has(t),vi=(t,e,i,n)=>{ui.add(t);fi(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,n)},gi=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),bi=t=>gi(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?wi:null:null;class wi extends Array{constructor(t){super(t),this.fill(0)}}class mi{constructor(t){if(0===t)return[];const e=bi(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class _i{constructor(t={}){const{max:e=0,ttl:i,ttlResolution:n=1,ttlAutopurge:s,updateAgeOnGet:r,updateAgeOnHas:o,allowStale:a,dispose:c,disposeAfter:h,noDisposeOnSet:l,noUpdateTTL:u,maxSize:d=0,sizeCalculation:p,fetchMethod:f,noDeleteOnFetchRejection:y}=t,{length:v,maxAge:g,stale:b}=t instanceof _i?{}:t;if(0!==e&&!gi(e))throw new TypeError("max option must be a nonnegative integer");const w=e?bi(e):Array;if(!w)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=d,this.sizeCalculation=p||v,this.sizeCalculation){if(!this.maxSize)throw new TypeError("cannot set sizeCalculation without setting maxSize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=f||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new w(e),this.prev=new w(e),this.head=0,this.tail=0,this.free=new mi(e),this.initialFill=1,this.size=0,"function"==typeof c&&(this.dispose=c),"function"==typeof h?(this.disposeAfter=h,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!l,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!y,0!==this.maxSize){if(!gi(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=gi(n)||0===n?n:1,this.ttlAutopurge=!!s,this.ttl=i||g||0,this.ttl){if(!gi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(0===this.max&&0===this.ttl&&0===this.maxSize)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const t="LRU_CACHE_UNBOUNDED";if(yi(t)){ui.add(t);fi("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,_i)}}b&&di("stale","allowStale"),g&&di("maxAge","ttl"),v&&di("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new wi(this.max),this.starts=new wi(this.max),this.setItemTTL=(t,e)=>{if(this.starts[t]=0!==e?ai.now():0,this.ttls[t]=e,0!==e&&this.ttlAutopurge){const i=setTimeout((()=>{this.isStale(t)&&this.delete(this.keyList[t])}),e+1);i.unref&&i.unref()}},this.updateItemAge=t=>{this.starts[t]=0!==this.ttls[t]?ai.now():0};let t=0;const e=()=>{const e=ai.now();if(this.ttlResolution>0){t=e;const i=setTimeout((()=>t=0),this.ttlResolution);i.unref&&i.unref()}return e};this.getRemainingTTL=i=>{const n=this.keyMap.get(i);return void 0===n?0:0===this.ttls[n]||0===this.starts[n]?1/0:this.starts[n]+this.ttls[n]-(t||e())},this.isStale=i=>0!==this.ttls[i]&&0!==this.starts[i]&&(t||e())-this.starts[i]>this.ttls[i]}updateItemAge(t){}setItemTTL(t,e){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new wi(this.max),this.removeItemSize=t=>this.calculatedSize-=this.sizes[t],this.requireSize=(t,e,i,n)=>{if(!gi(i)){if(!n)throw new TypeError("invalid size value (must be positive integer)");if("function"!=typeof n)throw new TypeError("sizeCalculation must be a function");if(i=n(e,t),!gi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e,i,n)=>{this.sizes[t]=n;const s=this.maxSize-this.sizes[t];for(;this.calculatedSize>s;)this.evict(!0);this.calculatedSize+=this.sizes[t]}}removeItemSize(t){}addItemSize(t,e,i,n){}requireSize(t,e,i,n){if(i||n)throw new TypeError("cannot set size without setting maxSize on cache")}*indexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.tail;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.head);)e=this.prev[e]}*rindexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.head;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.tail);)e=this.next[e]}isValidIndex(t){return this.keyMap.get(this.keyList[t])===t}*entries(){for(const t of this.indexes())yield[this.keyList[t],this.valList[t]]}*rentries(){for(const t of this.rindexes())yield[this.keyList[t],this.valList[t]]}*keys(){for(const t of this.indexes())yield this.keyList[t]}*rkeys(){for(const t of this.rindexes())yield this.keyList[t]}*values(){for(const t of this.indexes())yield this.valList[t]}*rvalues(){for(const t of this.rindexes())yield this.valList[t]}[Symbol.iterator](){return this.entries()}find(t,e={}){for(const i of this.indexes())if(t(this.valList[i],this.keyList[i],this))return this.get(this.keyList[i],e)}forEach(t,e=this){for(const i of this.indexes())t.call(e,this.valList[i],this.keyList[i],this)}rforEach(t,e=this){for(const i of this.rindexes())t.call(e,this.valList[i],this.keyList[i],this)}get prune(){return pi("prune","purgeStale"),this.purgeStale}purgeStale(){let t=!1;for(const e of this.rindexes({allowStale:!0}))this.isStale(e)&&(this.delete(this.keyList[e]),t=!0);return t}dump(){const t=[];for(const e of this.indexes()){const i=this.keyList[e],n={value:this.valList[e]};this.ttls&&(n.ttl=this.ttls[e]),this.sizes&&(n.size=this.sizes[e]),t.unshift([i,n])}return t}load(t){this.clear();for(const[e,i]of t)this.set(e,i.value,i)}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,noDisposeOnSet:n=this.noDisposeOnSet,size:s=0,sizeCalculation:r=this.sizeCalculation,noUpdateTTL:o=this.noUpdateTTL}={}){s=this.requireSize(t,e,s,r);let a=0===this.size?void 0:this.keyMap.get(t);if(void 0===a)a=this.newIndex(),this.keyList[a]=t,this.valList[a]=e,this.keyMap.set(t,a),this.next[this.tail]=a,this.prev[a]=this.tail,this.tail=a,this.size++,this.addItemSize(a,e,t,s),o=!1;else{const i=this.valList[a];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort():n||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(a),this.valList[a]=e,this.addItemSize(a,e,t,s)),this.moveToTail(a)}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),o||this.setItemTTL(a,i),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return 0===this.size?this.tail:this.size===this.max&&0!==this.max?this.evict(!1):0!==this.free.length?this.free.pop():this.initialFill++}pop(){if(this.size){const t=this.valList[this.head];return this.evict(!0),t}}evict(t){const e=this.head,i=this.keyList[e],n=this.valList[e];return this.isBackgroundFetch(n)?n.__abortController.abort():(this.dispose(n,i,"evict"),this.disposeAfter&&this.disposed.push([n,i,"evict"])),this.removeItemSize(e),t&&(this.keyList[e]=null,this.valList[e]=null,this.free.push(e)),this.head=this.next[e],this.keyMap.delete(i),this.size--,e}has(t,{updateAgeOnHas:e=this.updateAgeOnHas}={}){const i=this.keyMap.get(t);return void 0!==i&&!this.isStale(i)&&(e&&this.updateItemAge(i),!0)}peek(t,{allowStale:e=this.allowStale}={}){const i=this.keyMap.get(t);if(void 0!==i&&(e||!this.isStale(i)))return this.valList[i]}backgroundFetch(t,e,i){const n=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(n))return n;const s=new hi,r={signal:s.signal,options:i},o=new Promise((e=>e(this.fetchMethod(t,n,r)))).then((e=>(s.signal.aborted||this.set(t,e,r.options),e)),(n=>{if(this.valList[e]===o){!i.noDeleteOnFetchRejection||void 0===o.__staleWhileFetching?this.delete(t):this.valList[e]=o.__staleWhileFetching}if(o.__returned===o)throw n}));return o.__abortController=s,o.__staleWhileFetching=n,o.__returned=null,void 0===e?(this.set(t,o,r.options),e=this.keyMap.get(t)):this.valList[e]=o,o}isBackgroundFetch(t){return t&&"object"==typeof t&&"function"==typeof t.then&&Object.prototype.hasOwnProperty.call(t,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(t,"__returned")&&(t.__returned===t||null===t.__returned)}async fetch(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,ttl:n=this.ttl,noDisposeOnSet:s=this.noDisposeOnSet,size:r=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL,noDeleteOnFetchRejection:c=this.noDeleteOnFetchRejection}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i});const h={allowStale:e,updateAgeOnGet:i,ttl:n,noDisposeOnSet:s,size:r,sizeCalculation:o,noUpdateTTL:a,noDeleteOnFetchRejection:c};let l=this.keyMap.get(t);if(void 0===l){const e=this.backgroundFetch(t,l,h);return e.__returned=e}{const n=this.valList[l];if(this.isBackgroundFetch(n))return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n;if(!this.isStale(l))return this.moveToTail(l),i&&this.updateItemAge(l),n;const s=this.backgroundFetch(t,l,h);return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet}={}){const n=this.keyMap.get(t);if(void 0!==n){const s=this.valList[n],r=this.isBackgroundFetch(s);if(this.isStale(n))return r?e?s.__staleWhileFetching:void 0:(this.delete(t),e?s:void 0);if(r)return;return this.moveToTail(n),i&&this.updateItemAge(n),s}}connect(t,e){this.prev[e]=t,this.next[t]=e}moveToTail(t){t!==this.tail&&(t===this.head?this.head=this.next[t]:this.connect(this.prev[t],this.next[t]),this.connect(this.tail,t),this.tail=t)}get del(){return pi("del","delete"),this.delete}delete(t){let e=!1;if(0!==this.size){const i=this.keyMap.get(t);if(void 0!==i)if(e=!0,1===this.size)this.clear();else{this.removeItemSize(i);const e=this.valList[i];this.isBackgroundFetch(e)?e.__abortController.abort():(this.dispose(e,t,"delete"),this.disposeAfter&&this.disposed.push([e,t,"delete"])),this.keyMap.delete(t),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return e}clear(){for(const t of this.rindexes({allowStale:!0})){const e=this.valList[t];if(this.isBackgroundFetch(e))e.__abortController.abort();else{const i=this.keyList[t];this.dispose(e,i,"delete"),this.disposeAfter&&this.disposed.push([e,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return pi("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(yi(i)){const{prototype:n}=_i,{get:s}=Object.getOwnPropertyDescriptor(n,t);vi(i,`${t} property`,`cache.${e}`,s)}})("length","size"),this.size}static get AbortController(){return hi}static get AbortSignal(){return li}}var ji=_i;const Si=ni("rpc:InMemoryCache");class Ci{constructor(t){this.clearCache=()=>{var t;Si("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.reset()},this.getCachedResponse=t=>{var e;Si("getCachedResponse, key: ",t);let i=null===(e=this.cachedResponseByParams)||void 0===e?void 0:e.get(a(t));return"string"==typeof i&&(i=JSON.parse(i)),i},this.setCachedResponse=(t,e)=>{var i,n;Si("setCachedResponse",t,e);const s=a(t);if(!e)return null===(i=this.cachedResponseByParams)||void 0===i?void 0:i.del(s);const r=Object.assign({},e);delete r.correlationId,null===(n=this.cachedResponseByParams)||void 0===n||n.set(s,r?JSON.stringify(r):void 0)},this.cachedResponseByParams=new ji({max:(null==t?void 0:t.cacheMaxSize)||Ci.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||Ci.DEFAULT_CACHE_MAX_AGE_MS})}}Ci.DEFAULT_CACHE_MAX_AGE_MS=3e5,Ci.DEFAULT_CACHE_MAX_SIZE=100;class Oi{constructor(t){const{code:e,correlationId:i,data:n,message:s,success:r}=t;if("number"!=typeof e)throw new Error("code must be a number");if(this.code=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i,this.data=n,s&&"string"!=typeof s)throw new Error("message must be a string");if(this.message=s,"boolean"!=typeof r)throw new Error("success must be a boolean");this.success=r}}const Ti=ni("rpc:HTTPTransport");class Ai{constructor(t){this.options=t,this.networkIsConnected=!1,this.name="HttpTransport",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):this.networkIsConnected},this.sendRequest=t=>e(this,void 0,void 0,(function*(){Ti("sendRequest",t);const e=JSON.stringify(Object.assign({identity:this.identity},t)),i=yield null===window||void 0===window?void 0:window.fetch(this.host,{body:e,cache:"default",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"follow",referrerPolicy:"origin"}),n=yield i.text();if(!n)throw new Error("No response received from remote");const s=JSON.parse(n);return new Oi(s)})),this.setIdentity=t=>{Ti("setIdentity",t),this.identity=t},this.host=t.host}}class Ii{constructor(t){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||3e4);this.rejectPromise=t=>{clearTimeout(e),n(t)},this.resolvePromise=t=>{clearTimeout(e),i(t)}}))))}}const ki=t=>new Promise((e=>setTimeout(e,t))),Ei=ni("rpc:WebSocketTransport");class Ri{constructor(t){this.options=t,this.connectedToRemote=!1,this.isWaitingForIdentityConfirmation=!1,this.pendingPromisesForResponse={},this.websocketId=void 0,this.name="WebSocketTransport",this.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.sendRequest=t=>e(this,void 0,void 0,(function*(){for(Ei("sendRequest",t);this.isWaitingForIdentityConfirmation;)Ei("waiting for identity confirmation"),yield ki(100);return this.send(t)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(Ei("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?Ei('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.send({identity:t}).then((()=>{Ei("setIdentity with remote complete")})).catch((t=>{Ei("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):Ei("setIdentity is not connected to remote")})),this.connect=()=>{if(Ei("connect",this.host),this.websocket)return void Ei("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info("WebSocket connected"),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info("WebSocket closed",t.reason):Ei("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 s("Websocket disconnected"))})),t.wasClean||setTimeout((()=>{this.connect()}),1e3)},t.onerror=e=>{this.connectedToRemote?console.error("WebSocket encountered error: ",e):Ei("WebSocket errored, it was not connected to the remote"),t.close()}},this.disconnect=t=>{var e;Ei("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.handleWebSocketMsg=t=>{let e;Ei("handleWebSocketMsg",t);try{e=JSON.parse(t.data)}catch(t){console.error("error parsing WS msg",t)}const i=new Oi(e);if(!i.correlationId)return void console.error("RPCClient WebSocketTransport received unexpected msg from the server, not correlationId found in response.",e);const n=this.pendingPromisesForResponse[i.correlationId];n?n.resolve(i):console.warn("rcvd WS msg/response that doesn't match any pending RPC's",e)},this.resetConnection=()=>e(this,void 0,void 0,(function*(){Ei("resetConnection"),this.disconnect("WebSocketTransport#resetConnection"),yield ki(100),this.connect()})),this.send=t=>e(this,void 0,void 0,(function*(){var e;Ei("send",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let n=new Ii(Ri.DEFAULT_TIMEOUT_MS);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=>{Ei(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},Ei("new WebSocketTransport()"),this.host=t.host,this.connect()}}Ri.DEFAULT_TIMEOUT_MS=1e4;const zi=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}};class xi{constructor(){this.events={},this.publish=(t,i)=>e(this,void 0,void 0,(function*(){const e=this.events[t];e&&e.forEach((function(t){t.call(t,i)}))})),this.subscribe=(t,e)=>{this.events[t]||(this.events[t]=[]),this.events[t].push(e)},this.unsubscribe=(t,e)=>{if(!this.events[t])return;let i=this.events[t].indexOf(e);this.events[t].splice(i)}}}const Mi={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Li{constructor(t){var n,s,r,o,c,h;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new xi,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,n)=>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?zi(t):t,n&&(e.args=n);const s=new i(e);if(!s.procedure&&!s.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');s.identity||(s.identity={}),s.identity=ei(Object.assign({},this.identity),s.identity);const r=yield this.callManager.manageClientRequest(s);if(!r.success)throw r;const o=a(e);return this.vent.publish(o,null==r?void 0:r.data),r})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let i;i="string"==typeof t?zi(t):t,e&&(i.args=e);const n=this.callManager.getCachedResponse(i);if(n)return n},this.getIdentity=()=>this.identity?Je(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 i;return i="string"==typeof t?zi(t):t,function(t){return e.call(Object.assign(Object.assign({},i),{args:t}))}},this.registerResponseInterceptor=t=>{this.callManager.addResponseInterceptor(t)},this.registerRequestInterceptor=t=>{this.callManager.addRequestInterceptor(t)},this.registerWebSocketConnectionStatusChangeListener=t=>{this.webSocketConnectionChangeListeners.push(t)},this.setIdentity=t=>{let e=Je(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const i=Je(this.identity);i.metadata=t,this.identity.metadata=t,this.callManager.setIdentity(i)},!(null===(n=null==t?void 0:t.hosts)||void 0===n?void 0:n.http)&&!(null===(s=null==t?void 0:t.transports)||void 0===s?void 0:s.http))throw new Error(Mi.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(Mi.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(Mi.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new oi(u):new Ci(u);const d=[];(null===(r=t.transports)||void 0===r?void 0:r.websocket)?d.push(t.transports.websocket):(null===(o=null==t?void 0:t.hosts)||void 0===o?void 0:o.websocket)&&(this.webSocketTransport=new Ri({host:t.hosts.websocket,onConnectionStatusChange:this.onWebSocketConnectionStatusChange}),d.push(this.webSocketTransport)),(null===(c=t.transports)||void 0===c?void 0:c.http)?d.push(t.transports.http):(null===(h=null==t?void 0:t.hosts)||void 0===h?void 0:h.http)&&(this.httpTransport=new Ai({host:t.hosts.http}),d.push(this.httpTransport)),this.callManager=new ri({cache:l,deadlineMs:t.deadlineMs||Li.DEFAULT_DEADLINE_MS,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:d})}subscribe(t,e){const i="string"==typeof t.request?zi(t.request):t.request,n=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.subscribe(n,e)}unsubscribe(t,e){const i="string"==typeof t.request?zi(t.request):t.request,n=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.unsubscribe(n,e)}}Li.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=Li,t.RPCResponse=Oi,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!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,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}class i{constructor(t){const{args:e,correlationId:i,identity:s,procedure:n,scope:r,version:o}=t;if(this.args=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i||Math.random().toString(),s){if("object"!=typeof s)throw new Error("identity must be an object");if(s.authorization&&"string"!=typeof s.authorization)throw new Error("identity.authorization must be a string");if(s.deviceName&&"string"!=typeof s.deviceName)throw new Error("identity.deviceName must be a string");if(s.metadata&&"object"!=typeof s.metadata)throw new Error("identity.metadata must be a object");this.identity=s}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}}class s extends Error{}class n extends Error{}class r extends Error{}function o(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}const a=t=>t.args?`${t.scope}${t.procedure}${t.version}${function(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});var i,s="boolean"==typeof e.cycles&&e.cycles,n=e.cmp&&(i=e.cmp,function(t){return function(e,s){var n={key:e,value:t[e]},r={key:s,value:t[s]};return i(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 i,o;if(Array.isArray(e)){for(o="[",i=0;i<e.length;i++)i&&(o+=","),o+=t(e[i])||"null";return o+"]"}if(null===e)return"null";if(-1!==r.indexOf(e)){if(s)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="",i=0;i<c.length;i++){var h=c[i],l=t(e[h]);l&&(o&&(o+=","),o+=JSON.stringify(h)+":"+l)}return r.splice(a,1),"{"+o+"}"}}(t)}(function(t,e={}){if(!o(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:i,compare:s}=e,n=[],r=[],a=t=>{const e=n.indexOf(t);if(-1!==e)return r[e];const i=[];return n.push(t),r.push(i),i.push(...t.map((t=>Array.isArray(t)?a(t):o(t)?c(t):t))),i},c=t=>{const e=n.indexOf(t);if(-1!==e)return r[e];const h={},l=Object.keys(t).sort(s);n.push(t),r.push(h);for(const e of l){const s=t[e];let n;n=i&&Array.isArray(s)?a(s):i&&o(s)?c(s):s,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:n}))}return h};return Array.isArray(t)?i?a(t):t.slice():c(t)}(t.args||{},{deep:!0}))}`:`${t.scope}${t.procedure}${t.version}`;var c="object"==typeof global&&global&&global.Object===Object&&global,h="object"==typeof self&&self&&self.Object===Object&&self,l=c||h||Function("return this")(),u=l.Symbol,d=Object.prototype,p=d.hasOwnProperty,f=d.toString,y=u?u.toStringTag:void 0;var v=Object.prototype.toString;var g=u?u.toStringTag:void 0;function b(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?function(t){var e=p.call(t,y),i=t[y];try{t[y]=void 0;var s=!0}catch(t){}var n=f.call(t);return s&&(e?t[y]=i:delete t[y]),n}(t):function(t){return v.call(t)}(t)}function w(t){return null!=t&&"object"==typeof t}var m=Array.isArray;function _(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function S(t){return t}function j(t){if(!_(t))return!1;var e=b(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var C,T=l["__core-js_shared__"],O=(C=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+C:"";var A=Function.prototype.toString;function k(t){if(null!=t){try{return A.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var I=/^\[object .+?Constructor\]$/,E=Function.prototype,R=Object.prototype,M=E.toString,z=R.hasOwnProperty,x=RegExp("^"+M.call(z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function L(t){return!(!_(t)||(e=t,O&&O in e))&&(j(t)?x:I).test(k(t));var e}function P(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return L(i)?i:void 0}var F=P(l,"WeakMap"),W=Object.create,U=function(){function t(){}return function(e){if(!_(e))return{};if(W)return W(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function q(t,e,i){switch(i.length){case 0:return t.call(e);case 1:return t.call(e,i[0]);case 2:return t.call(e,i[0],i[1]);case 3:return t.call(e,i[0],i[1],i[2])}return t.apply(e,i)}function D(t,e){var i=-1,s=t.length;for(e||(e=Array(s));++i<s;)e[i]=t[i];return e}var N=Date.now;var B,$,H,G=function(){try{var t=P(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=G,V=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(i=e,function(){return i}),writable:!0});var i}:S,K=(B=V,$=0,H=0,function(){var t=N(),e=16-(t-H);if(H=t,e>0){if(++$>=800)return arguments[0]}else $=0;return B.apply(void 0,arguments)}),X=K;var Z=/^(?:0|[1-9]\d*)$/;function Q(t,e){var i=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==i||"symbol"!=i&&Z.test(t))&&t>-1&&t%1==0&&t<e}function Y(t,e,i){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}function tt(t,e){return t===e||t!=t&&e!=e}var et=Object.prototype.hasOwnProperty;function it(t,e,i){var s=t[e];et.call(t,e)&&tt(s,i)&&(void 0!==i||e in t)||Y(t,e,i)}function st(t,e,i,s){var n=!i;i||(i={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=s?s(i[a],t[a],a,i,t):void 0;void 0===c&&(c=t[a]),n?Y(i,a,c):it(i,a,c)}return i}var nt=Math.max;function rt(t,e){return X(function(t,e,i){return e=nt(void 0===e?t.length-1:e,0),function(){for(var s=arguments,n=-1,r=nt(s.length-e,0),o=Array(r);++n<r;)o[n]=s[e+n];n=-1;for(var a=Array(e+1);++n<e;)a[n]=s[n];return a[e]=i(o),q(t,this,a)}}(t,e,S),t+"")}function ot(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function at(t){return null!=t&&ot(t.length)&&!j(t)}var ct=Object.prototype;function ht(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ct)}function lt(t){return w(t)&&"[object Arguments]"==b(t)}var ut=Object.prototype,dt=ut.hasOwnProperty,pt=ut.propertyIsEnumerable,ft=lt(function(){return arguments}())?lt:function(t){return w(t)&&dt.call(t,"callee")&&!pt.call(t,"callee")},yt=ft;var vt="object"==typeof t&&t&&!t.nodeType&&t,gt=vt&&"object"==typeof module&&module&&!module.nodeType&&module,bt=gt&>.exports===vt?l.Buffer:void 0,wt=(bt?bt.isBuffer:void 0)||function(){return!1},mt={};function _t(t){return function(e){return t(e)}}mt["[object Float32Array]"]=mt["[object Float64Array]"]=mt["[object Int8Array]"]=mt["[object Int16Array]"]=mt["[object Int32Array]"]=mt["[object Uint8Array]"]=mt["[object Uint8ClampedArray]"]=mt["[object Uint16Array]"]=mt["[object Uint32Array]"]=!0,mt["[object Arguments]"]=mt["[object Array]"]=mt["[object ArrayBuffer]"]=mt["[object Boolean]"]=mt["[object DataView]"]=mt["[object Date]"]=mt["[object Error]"]=mt["[object Function]"]=mt["[object Map]"]=mt["[object Number]"]=mt["[object Object]"]=mt["[object RegExp]"]=mt["[object Set]"]=mt["[object String]"]=mt["[object WeakMap]"]=!1;var St="object"==typeof t&&t&&!t.nodeType&&t,jt=St&&"object"==typeof module&&module&&!module.nodeType&&module,Ct=jt&&jt.exports===St&&c.process,Tt=function(){try{var t=jt&&jt.require&&jt.require("util").types;return t||Ct&&Ct.binding&&Ct.binding("util")}catch(t){}}(),Ot=Tt&&Tt.isTypedArray,At=Ot?_t(Ot):function(t){return w(t)&&ot(t.length)&&!!mt[b(t)]},kt=Object.prototype.hasOwnProperty;function It(t,e){var i=m(t),s=!i&&yt(t),n=!i&&!s&&wt(t),r=!i&&!s&&!n&&At(t),o=i||s||n||r,a=o?function(t,e){for(var i=-1,s=Array(t);++i<t;)s[i]=e(i);return s}(t.length,String):[],c=a.length;for(var h in t)!e&&!kt.call(t,h)||o&&("length"==h||n&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||Q(h,c))||a.push(h);return a}function Et(t,e){return function(i){return t(e(i))}}var Rt=Et(Object.keys,Object),Mt=Object.prototype.hasOwnProperty;function zt(t){return at(t)?It(t):function(t){if(!ht(t))return Rt(t);var e=[];for(var i in Object(t))Mt.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var xt=Object.prototype.hasOwnProperty;function Lt(t){if(!_(t))return function(t){var e=[];if(null!=t)for(var i in Object(t))e.push(i);return e}(t);var e=ht(t),i=[];for(var s in t)("constructor"!=s||!e&&xt.call(t,s))&&i.push(s);return i}function Pt(t){return at(t)?It(t,!0):Lt(t)}var Ft=P(Object,"create");var Wt=Object.prototype.hasOwnProperty;var Ut=Object.prototype.hasOwnProperty;function qt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}function Dt(t,e){for(var i=t.length;i--;)if(tt(t[i][0],e))return i;return-1}qt.prototype.clear=function(){this.__data__=Ft?Ft(null):{},this.size=0},qt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},qt.prototype.get=function(t){var e=this.__data__;if(Ft){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return Wt.call(e,t)?e[t]:void 0},qt.prototype.has=function(t){var e=this.__data__;return Ft?void 0!==e[t]:Ut.call(e,t)},qt.prototype.set=function(t,e){var i=this.__data__;return this.size+=this.has(t)?0:1,i[t]=Ft&&void 0===e?"__lodash_hash_undefined__":e,this};var Nt=Array.prototype.splice;function Bt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}Bt.prototype.clear=function(){this.__data__=[],this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,i=Dt(e,t);return!(i<0)&&(i==e.length-1?e.pop():Nt.call(e,i,1),--this.size,!0)},Bt.prototype.get=function(t){var e=this.__data__,i=Dt(e,t);return i<0?void 0:e[i][1]},Bt.prototype.has=function(t){return Dt(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var i=this.__data__,s=Dt(i,t);return s<0?(++this.size,i.push([t,e])):i[s][1]=e,this};var $t=P(l,"Map");function Ht(t,e){var i,s,n=t.__data__;return("string"==(s=typeof(i=e))||"number"==s||"symbol"==s||"boolean"==s?"__proto__"!==i:null===i)?n["string"==typeof e?"string":"hash"]:n.map}function Gt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}function Jt(t,e){for(var i=-1,s=e.length,n=t.length;++i<s;)t[n+i]=e[i];return t}Gt.prototype.clear=function(){this.size=0,this.__data__={hash:new qt,map:new($t||Bt),string:new qt}},Gt.prototype.delete=function(t){var e=Ht(this,t).delete(t);return this.size-=e?1:0,e},Gt.prototype.get=function(t){return Ht(this,t).get(t)},Gt.prototype.has=function(t){return Ht(this,t).has(t)},Gt.prototype.set=function(t,e){var i=Ht(this,t),s=i.size;return i.set(t,e),this.size+=i.size==s?0:1,this};var Vt=Et(Object.getPrototypeOf,Object),Kt=Function.prototype,Xt=Object.prototype,Zt=Kt.toString,Qt=Xt.hasOwnProperty,Yt=Zt.call(Object);function te(t){var e=this.__data__=new Bt(t);this.size=e.size}te.prototype.clear=function(){this.__data__=new Bt,this.size=0},te.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},te.prototype.get=function(t){return this.__data__.get(t)},te.prototype.has=function(t){return this.__data__.has(t)},te.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Bt){var s=i.__data__;if(!$t||s.length<199)return s.push([t,e]),this.size=++i.size,this;i=this.__data__=new Gt(s)}return i.set(t,e),this.size=i.size,this};var ee="object"==typeof t&&t&&!t.nodeType&&t,ie=ee&&"object"==typeof module&&module&&!module.nodeType&&module,se=ie&&ie.exports===ee?l.Buffer:void 0,ne=se?se.allocUnsafe:void 0;function re(t,e){if(e)return t.slice();var i=t.length,s=ne?ne(i):new t.constructor(i);return t.copy(s),s}function oe(){return[]}var ae=Object.prototype.propertyIsEnumerable,ce=Object.getOwnPropertySymbols,he=ce?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var i=-1,s=null==t?0:t.length,n=0,r=[];++i<s;){var o=t[i];e(o,i,t)&&(r[n++]=o)}return r}(ce(t),(function(e){return ae.call(t,e)})))}:oe;var le=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Jt(e,he(t)),t=Vt(t);return e}:oe;function ue(t,e,i){var s=e(t);return m(t)?s:Jt(s,i(t))}function de(t){return ue(t,zt,he)}function pe(t){return ue(t,Pt,le)}var fe=P(l,"DataView"),ye=P(l,"Promise"),ve=P(l,"Set"),ge="[object Map]",be="[object Promise]",we="[object Set]",me="[object WeakMap]",_e="[object DataView]",Se=k(fe),je=k($t),Ce=k(ye),Te=k(ve),Oe=k(F),Ae=b;(fe&&Ae(new fe(new ArrayBuffer(1)))!=_e||$t&&Ae(new $t)!=ge||ye&&Ae(ye.resolve())!=be||ve&&Ae(new ve)!=we||F&&Ae(new F)!=me)&&(Ae=function(t){var e=b(t),i="[object Object]"==e?t.constructor:void 0,s=i?k(i):"";if(s)switch(s){case Se:return _e;case je:return ge;case Ce:return be;case Te:return we;case Oe:return me}return e});var ke=Ae,Ie=Object.prototype.hasOwnProperty;var Ee=l.Uint8Array;function Re(t){var e=new t.constructor(t.byteLength);return new Ee(e).set(new Ee(t)),e}var Me=/\w*$/;var ze=u?u.prototype:void 0,xe=ze?ze.valueOf:void 0;function Le(t,e){var i=e?Re(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function Pe(t,e,i){var s,n,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return Re(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var i=e?Re(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);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 Le(t,i);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,Me.exec(n))).lastIndex=n.lastIndex,r;case"[object Symbol]":return s=t,xe?Object(xe.call(s)):{}}}function Fe(t){return"function"!=typeof t.constructor||ht(t)?{}:U(Vt(t))}var We=Tt&&Tt.isMap,Ue=We?_t(We):function(t){return w(t)&&"[object Map]"==ke(t)};var qe=Tt&&Tt.isSet,De=qe?_t(qe):function(t){return w(t)&&"[object Set]"==ke(t)},Ne="[object Arguments]",Be="[object Function]",$e="[object Object]",He={};function Ge(t,e,i,s,n,r){var o,a=1&e,c=2&e,h=4&e;if(i&&(o=n?i(t,s,n,r):i(t)),void 0!==o)return o;if(!_(t))return t;var l=m(t);if(l){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&Ie.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return D(t,o)}else{var u=ke(t),d=u==Be||"[object GeneratorFunction]"==u;if(wt(t))return re(t,a);if(u==$e||u==Ne||d&&!n){if(o=c||d?{}:Fe(t),!a)return c?function(t,e){return st(t,le(t),e)}(t,function(t,e){return t&&st(e,Pt(e),t)}(o,t)):function(t,e){return st(t,he(t),e)}(t,function(t,e){return t&&st(e,zt(e),t)}(o,t))}else{if(!He[u])return n?t:{};o=Pe(t,u,a)}}r||(r=new te);var p=r.get(t);if(p)return p;r.set(t,o),De(t)?t.forEach((function(s){o.add(Ge(s,e,i,s,t,r))})):Ue(t)&&t.forEach((function(s,n){o.set(n,Ge(s,e,i,n,t,r))}));var f=l?void 0:(h?c?pe:de:c?Pt:zt)(t);return function(t,e){for(var i=-1,s=null==t?0:t.length;++i<s&&!1!==e(t[i],i,t););}(f||t,(function(s,n){f&&(s=t[n=s]),it(o,n,Ge(s,e,i,n,t,r))})),o}He[Ne]=He["[object Array]"]=He["[object ArrayBuffer]"]=He["[object DataView]"]=He["[object Boolean]"]=He["[object Date]"]=He["[object Float32Array]"]=He["[object Float64Array]"]=He["[object Int8Array]"]=He["[object Int16Array]"]=He["[object Int32Array]"]=He["[object Map]"]=He["[object Number]"]=He[$e]=He["[object RegExp]"]=He["[object Set]"]=He["[object String]"]=He["[object Symbol]"]=He["[object Uint8Array]"]=He["[object Uint8ClampedArray]"]=He["[object Uint16Array]"]=He["[object Uint32Array]"]=!0,He["[object Error]"]=He[Be]=He["[object WeakMap]"]=!1;function Je(t){return Ge(t,5)}var Ve,Ke=function(t,e,i){for(var s=-1,n=Object(t),r=i(t),o=r.length;o--;){var a=r[Ve?o:++s];if(!1===e(n[a],a,n))break}return t};function Xe(t,e,i){(void 0!==i&&!tt(t[e],i)||void 0===i&&!(e in t))&&Y(t,e,i)}function Ze(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Qe(t,e,i,s,n,r,o){var a=Ze(t,i),c=Ze(e,i),h=o.get(c);if(h)Xe(t,i,h);else{var l,u=r?r(a,c,i+"",t,e,o):void 0,d=void 0===u;if(d){var p=m(c),f=!p&&wt(c),y=!p&&!f&&At(c);u=c,p||f||y?m(a)?u=a:w(l=a)&&at(l)?u=D(a):f?(d=!1,u=re(c,!0)):y?(d=!1,u=Le(c,!0)):u=[]:function(t){if(!w(t)||"[object Object]"!=b(t))return!1;var e=Vt(t);if(null===e)return!0;var i=Qt.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&Zt.call(i)==Yt}(c)||yt(c)?(u=a,yt(a)?u=function(t){return st(t,Pt(t))}(a):_(a)&&!j(a)||(u=Fe(c))):d=!1}d&&(o.set(c,u),n(u,c,s,r,o),o.delete(c)),Xe(t,i,u)}}function Ye(t,e,i,s,n){t!==e&&Ke(e,(function(r,o){if(n||(n=new te),_(r))Qe(t,e,o,i,Ye,s,n);else{var a=s?s(Ze(t,o),r,o+"",t,e,n):void 0;void 0===a&&(a=r),Xe(t,o,a)}}),Pt)}var ti,ei=(ti=function(t,e,i){Ye(t,e,i)},rt((function(t,e){var i=-1,s=e.length,n=s>1?e[s-1]:void 0,r=s>2?e[2]:void 0;for(n=ti.length>3&&"function"==typeof n?(s--,n):void 0,r&&function(t,e,i){if(!_(i))return!1;var s=typeof e;return!!("number"==s?at(i)&&Q(e,i.length):"string"==s&&e in i)&&tt(i[e],t)}(e[0],e[1],r)&&(n=s<3?void 0:n,s=1),t=Object(t);++i<s;){var o=e[i];o&&ti(t,o,i,n)}return t})));let ii=null;try{ii=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const si=t=>ii&&new RegExp(ii).test(t)?(...e)=>console.log(t,...e):()=>{},ni=si("rpc:ClientManager");class ri{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");this.interceptors.response.push(t)},this.addRequestInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");this.interceptors.request.push(t)},this.clearCache=t=>{ni("clearCache"),this.cache&&(t?this.cache.setCachedResponse(t,void 0):this.cache.clearCache())},this.getCachedResponse=t=>{var e;return ni("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(ni("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=t=>e(this,void 0,void 0,(function*(){ni("manageClientRequest",t);const i=yield this.interceptRequestMutator(t),s=a(i);if(this.inflightCallsByKey.hasOwnProperty(s))return ni("manageClientRequest using an existing in-flight call",s),this.inflightCallsByKey[s].then((e=>{const i=Je(e);return t.correlationId&&(i.correlationId=t.correlationId),i}));const n=(()=>e(this,void 0,void 0,(function*(){const t=yield this.sendRequestWithTransport(i),e=yield this.interceptResponseMutator(t,i);return this.cache&&e&&this.cache.setCachedResponse(i,e),e})))().then((t=>(delete this.inflightCallsByKey[s],t))).catch((t=>{throw delete this.inflightCallsByKey[s],t}));return this.inflightCallsByKey[s]=n,yield n})),this.setIdentity=t=>{ni("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.request.length){ni("interceptRequestMutator(), original request:",t);for(const t of this.interceptors.request)e=yield t(e)}return e})),this.interceptResponseMutator=(t,i)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){ni("interceptResponseMutator",i,t);for(const s of this.interceptors.response)try{e=yield s(e,i)}catch(s){throw ni("caught response interceptor, request:",i,"original response:",t,"mutated response:",e),s}}return e})),this.sendRequestWithTransport=t=>e(this,void 0,void 0,(function*(){let e;ni("sendRequestWithTransport",t);let i=0;for(;!e&&this.transports[i];){const s=this.transports[i];if(s.isConnected()){ni(`sendRequestWithTransport trying ${this.transports[i].name}`,t);try{let i;const n=new Promise(((e,s)=>{i=setTimeout((()=>{s(new r(`Procedure ${t.procedure}`))}),this.options.deadlineMs)}));e=yield Promise.race([n,s.sendRequest(t)]).then((t=>(clearTimeout(i),t)))}catch(t){if(!(t instanceof r||t instanceof n))throw t;ni(`sending request with ${this.transports[i].name} failed, trying next transport`),i++}}else i++}if(!e&&!this.transports[i])throw new s(`Procedure ${t.procedure} did not get a response from any transports`);if(!e)throw new s(`Procedure ${t.procedure} did not get a response from the remote`);return e})),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 oi{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}oi.DEFAULT_CACHE_MAX_AGE_MS=3e5,oi.DEFAULT_CACHE_MAX_SIZE=100;const ai="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,ci="function"==typeof AbortController,hi=ci?AbortController:class{constructor(){this.signal=new li}abort(){this.signal.dispatchEvent("abort")}},li=ci?AbortSignal:class{constructor(){this.aborted=!1,this._listeners=[]}dispatchEvent(t){if("abort"===t){this.aborted=!0;const e={type:t,target:this};this.onabort(e),this._listeners.forEach((t=>t(e)),this)}}onabort(){}addEventListener(t,e){"abort"===t&&this._listeners.push(e)}removeEventListener(t,e){"abort"===t&&(this._listeners=this._listeners.filter((t=>t!==e)))}},ui=new Set,di=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;yi(i)&&vi(i,`${t} option`,`options.${e}`,_i)},pi=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(yi(i)){const{prototype:s}=_i,{get:n}=Object.getOwnPropertyDescriptor(s,t);vi(i,`${t} method`,`cache.${e}()`,n)}},fi=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},yi=t=>!ui.has(t),vi=(t,e,i,s)=>{ui.add(t);fi(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,s)},gi=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),bi=t=>gi(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?wi:null:null;class wi extends Array{constructor(t){super(t),this.fill(0)}}class mi{constructor(t){if(0===t)return[];const e=bi(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class _i{constructor(t={}){const{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:r,updateAgeOnHas:o,allowStale:a,dispose:c,disposeAfter:h,noDisposeOnSet:l,noUpdateTTL:u,maxSize:d=0,sizeCalculation:p,fetchMethod:f,noDeleteOnFetchRejection:y}=t,{length:v,maxAge:g,stale:b}=t instanceof _i?{}:t;if(0!==e&&!gi(e))throw new TypeError("max option must be a nonnegative integer");const w=e?bi(e):Array;if(!w)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=d,this.sizeCalculation=p||v,this.sizeCalculation){if(!this.maxSize)throw new TypeError("cannot set sizeCalculation without setting maxSize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=f||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new w(e),this.prev=new w(e),this.head=0,this.tail=0,this.free=new mi(e),this.initialFill=1,this.size=0,"function"==typeof c&&(this.dispose=c),"function"==typeof h?(this.disposeAfter=h,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!l,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!y,0!==this.maxSize){if(!gi(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=gi(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||g||0,this.ttl){if(!gi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(0===this.max&&0===this.ttl&&0===this.maxSize)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const t="LRU_CACHE_UNBOUNDED";if(yi(t)){ui.add(t);fi("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,_i)}}b&&di("stale","allowStale"),g&&di("maxAge","ttl"),v&&di("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new wi(this.max),this.starts=new wi(this.max),this.setItemTTL=(t,e)=>{if(this.starts[t]=0!==e?ai.now():0,this.ttls[t]=e,0!==e&&this.ttlAutopurge){const i=setTimeout((()=>{this.isStale(t)&&this.delete(this.keyList[t])}),e+1);i.unref&&i.unref()}},this.updateItemAge=t=>{this.starts[t]=0!==this.ttls[t]?ai.now():0};let t=0;const e=()=>{const e=ai.now();if(this.ttlResolution>0){t=e;const i=setTimeout((()=>t=0),this.ttlResolution);i.unref&&i.unref()}return e};this.getRemainingTTL=i=>{const s=this.keyMap.get(i);return void 0===s?0:0===this.ttls[s]||0===this.starts[s]?1/0:this.starts[s]+this.ttls[s]-(t||e())},this.isStale=i=>0!==this.ttls[i]&&0!==this.starts[i]&&(t||e())-this.starts[i]>this.ttls[i]}updateItemAge(t){}setItemTTL(t,e){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new wi(this.max),this.removeItemSize=t=>this.calculatedSize-=this.sizes[t],this.requireSize=(t,e,i,s)=>{if(!gi(i)){if(!s)throw new TypeError("invalid size value (must be positive integer)");if("function"!=typeof s)throw new TypeError("sizeCalculation must be a function");if(i=s(e,t),!gi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e,i,s)=>{this.sizes[t]=s;const n=this.maxSize-this.sizes[t];for(;this.calculatedSize>n;)this.evict(!0);this.calculatedSize+=this.sizes[t]}}removeItemSize(t){}addItemSize(t,e,i,s){}requireSize(t,e,i,s){if(i||s)throw new TypeError("cannot set size without setting maxSize on cache")}*indexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.tail;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.head);)e=this.prev[e]}*rindexes({allowStale:t=this.allowStale}={}){if(this.size)for(let e=this.head;this.isValidIndex(e)&&(!t&&this.isStale(e)||(yield e),e!==this.tail);)e=this.next[e]}isValidIndex(t){return this.keyMap.get(this.keyList[t])===t}*entries(){for(const t of this.indexes())yield[this.keyList[t],this.valList[t]]}*rentries(){for(const t of this.rindexes())yield[this.keyList[t],this.valList[t]]}*keys(){for(const t of this.indexes())yield this.keyList[t]}*rkeys(){for(const t of this.rindexes())yield this.keyList[t]}*values(){for(const t of this.indexes())yield this.valList[t]}*rvalues(){for(const t of this.rindexes())yield this.valList[t]}[Symbol.iterator](){return this.entries()}find(t,e={}){for(const i of this.indexes())if(t(this.valList[i],this.keyList[i],this))return this.get(this.keyList[i],e)}forEach(t,e=this){for(const i of this.indexes())t.call(e,this.valList[i],this.keyList[i],this)}rforEach(t,e=this){for(const i of this.rindexes())t.call(e,this.valList[i],this.keyList[i],this)}get prune(){return pi("prune","purgeStale"),this.purgeStale}purgeStale(){let t=!1;for(const e of this.rindexes({allowStale:!0}))this.isStale(e)&&(this.delete(this.keyList[e]),t=!0);return t}dump(){const t=[];for(const e of this.indexes()){const i=this.keyList[e],s={value:this.valList[e]};this.ttls&&(s.ttl=this.ttls[e]),this.sizes&&(s.size=this.sizes[e]),t.unshift([i,s])}return t}load(t){this.clear();for(const[e,i]of t)this.set(e,i.value,i)}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,noDisposeOnSet:s=this.noDisposeOnSet,size:n=0,sizeCalculation:r=this.sizeCalculation,noUpdateTTL:o=this.noUpdateTTL}={}){n=this.requireSize(t,e,n,r);let a=0===this.size?void 0:this.keyMap.get(t);if(void 0===a)a=this.newIndex(),this.keyList[a]=t,this.valList[a]=e,this.keyMap.set(t,a),this.next[this.tail]=a,this.prev[a]=this.tail,this.tail=a,this.size++,this.addItemSize(a,e,t,n),o=!1;else{const i=this.valList[a];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort():s||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(a),this.valList[a]=e,this.addItemSize(a,e,t,n)),this.moveToTail(a)}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),o||this.setItemTTL(a,i),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return 0===this.size?this.tail:this.size===this.max&&0!==this.max?this.evict(!1):0!==this.free.length?this.free.pop():this.initialFill++}pop(){if(this.size){const t=this.valList[this.head];return this.evict(!0),t}}evict(t){const e=this.head,i=this.keyList[e],s=this.valList[e];return this.isBackgroundFetch(s)?s.__abortController.abort():(this.dispose(s,i,"evict"),this.disposeAfter&&this.disposed.push([s,i,"evict"])),this.removeItemSize(e),t&&(this.keyList[e]=null,this.valList[e]=null,this.free.push(e)),this.head=this.next[e],this.keyMap.delete(i),this.size--,e}has(t,{updateAgeOnHas:e=this.updateAgeOnHas}={}){const i=this.keyMap.get(t);return void 0!==i&&!this.isStale(i)&&(e&&this.updateItemAge(i),!0)}peek(t,{allowStale:e=this.allowStale}={}){const i=this.keyMap.get(t);if(void 0!==i&&(e||!this.isStale(i)))return this.valList[i]}backgroundFetch(t,e,i){const s=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(s))return s;const n=new hi,r={signal:n.signal,options:i},o=new Promise((e=>e(this.fetchMethod(t,s,r)))).then((e=>(n.signal.aborted||this.set(t,e,r.options),e)),(s=>{if(this.valList[e]===o){!i.noDeleteOnFetchRejection||void 0===o.__staleWhileFetching?this.delete(t):this.valList[e]=o.__staleWhileFetching}if(o.__returned===o)throw s}));return o.__abortController=n,o.__staleWhileFetching=s,o.__returned=null,void 0===e?(this.set(t,o,r.options),e=this.keyMap.get(t)):this.valList[e]=o,o}isBackgroundFetch(t){return t&&"object"==typeof t&&"function"==typeof t.then&&Object.prototype.hasOwnProperty.call(t,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(t,"__returned")&&(t.__returned===t||null===t.__returned)}async fetch(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,ttl:s=this.ttl,noDisposeOnSet:n=this.noDisposeOnSet,size:r=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL,noDeleteOnFetchRejection:c=this.noDeleteOnFetchRejection}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i});const h={allowStale:e,updateAgeOnGet:i,ttl:s,noDisposeOnSet:n,size:r,sizeCalculation:o,noUpdateTTL:a,noDeleteOnFetchRejection:c};let l=this.keyMap.get(t);if(void 0===l){const e=this.backgroundFetch(t,l,h);return e.__returned=e}{const s=this.valList[l];if(this.isBackgroundFetch(s))return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s;if(!this.isStale(l))return this.moveToTail(l),i&&this.updateItemAge(l),s;const n=this.backgroundFetch(t,l,h);return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet}={}){const s=this.keyMap.get(t);if(void 0!==s){const n=this.valList[s],r=this.isBackgroundFetch(n);if(this.isStale(s))return r?e?n.__staleWhileFetching:void 0:(this.delete(t),e?n:void 0);if(r)return;return this.moveToTail(s),i&&this.updateItemAge(s),n}}connect(t,e){this.prev[e]=t,this.next[t]=e}moveToTail(t){t!==this.tail&&(t===this.head?this.head=this.next[t]:this.connect(this.prev[t],this.next[t]),this.connect(this.tail,t),this.tail=t)}get del(){return pi("del","delete"),this.delete}delete(t){let e=!1;if(0!==this.size){const i=this.keyMap.get(t);if(void 0!==i)if(e=!0,1===this.size)this.clear();else{this.removeItemSize(i);const e=this.valList[i];this.isBackgroundFetch(e)?e.__abortController.abort():(this.dispose(e,t,"delete"),this.disposeAfter&&this.disposed.push([e,t,"delete"])),this.keyMap.delete(t),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return e}clear(){for(const t of this.rindexes({allowStale:!0})){const e=this.valList[t];if(this.isBackgroundFetch(e))e.__abortController.abort();else{const i=this.keyList[t];this.dispose(e,i,"delete"),this.disposeAfter&&this.disposed.push([e,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return pi("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(yi(i)){const{prototype:s}=_i,{get:n}=Object.getOwnPropertyDescriptor(s,t);vi(i,`${t} property`,`cache.${e}`,n)}})("length","size"),this.size}static get AbortController(){return hi}static get AbortSignal(){return li}}var Si=_i;const ji=si("rpc:InMemoryCache");class Ci{constructor(t){this.clearCache=()=>{var t;ji("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.reset()},this.getCachedResponse=t=>{var e;ji("getCachedResponse, key: ",t);let i=null===(e=this.cachedResponseByParams)||void 0===e?void 0:e.get(a(t));return"string"==typeof i&&(i=JSON.parse(i)),i},this.setCachedResponse=(t,e)=>{var i,s;ji("setCachedResponse",t,e);const n=a(t);if(!e)return null===(i=this.cachedResponseByParams)||void 0===i?void 0:i.del(n);const r=Object.assign({},e);delete r.correlationId,null===(s=this.cachedResponseByParams)||void 0===s||s.set(n,r?JSON.stringify(r):void 0)},this.cachedResponseByParams=new Si({max:(null==t?void 0:t.cacheMaxSize)||Ci.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||Ci.DEFAULT_CACHE_MAX_AGE_MS})}}Ci.DEFAULT_CACHE_MAX_AGE_MS=3e5,Ci.DEFAULT_CACHE_MAX_SIZE=100;class Ti{constructor(t){const{code:e,correlationId:i,data:s,message:n,success:r}=t;if("number"!=typeof e)throw new Error("code must be a number");if(this.code=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i,this.data=s,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}}const Oi=si("rpc:HTTPTransport");class Ai{constructor(t){this.options=t,this.networkIsConnected=!1,this.name="HttpTransport",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):this.networkIsConnected},this.sendRequest=t=>e(this,void 0,void 0,(function*(){Oi("sendRequest",t);const e=JSON.stringify(Object.assign({identity:this.identity},t)),i=yield null===window||void 0===window?void 0:window.fetch(this.host,{body:e,cache:"default",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"follow",referrerPolicy:"origin"}),s=yield i.text();if(!s)throw new Error("No response received from remote");const n=JSON.parse(s);return new Ti(n)})),this.setIdentity=t=>{Oi("setIdentity",t),this.identity=t},this.host=t.host}}class ki{constructor(t){this.reject=t=>{this.rejectPromise&&this.rejectPromise(t)},this.resolve=t=>{this.resolvePromise&&this.resolvePromise(t)},this.promise=new Promise(((i,s)=>e(this,void 0,void 0,(function*(){const e=setTimeout((()=>{s(new Error("PromiseWraper timeout"))}),t||3e4);this.rejectPromise=t=>{clearTimeout(e),s(t)},this.resolvePromise=t=>{clearTimeout(e),i(t)}}))))}}const Ii=t=>new Promise((e=>setTimeout(e,t))),Ei=si("rpc:WebSocketTransport");class Ri{constructor(t){this.options=t,this.connectedToRemote=!1,this.isWaitingForIdentityConfirmation=!1,this.pendingPromisesForResponse={},this.serverMessageHandlers=[],this.websocketId=void 0,this.name="WebSocketTransport",this.handleServerMessage=t=>{this.serverMessageHandlers.forEach((e=>{try{e(t.serverMessage)}catch(e){console.warn("WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling",t),console.error(e)}}))},this.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.sendClientMessageToServer=t=>{var e;let i=t;try{"string"!=typeof i&&(i=JSON.stringify(t))}catch(e){console.warn('WebSocketTransport.sendClientMessage() unable to stringify "msg"',t)}null===(e=this.websocket)||void 0===e||e.send(i)},this.sendRequest=t=>e(this,void 0,void 0,(function*(){for(Ei("sendRequest",t);this.isWaitingForIdentityConfirmation;)Ei("waiting for identity confirmation"),yield Ii(100);return this.sendCall(t)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(Ei("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?Ei('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t}).then((()=>{Ei("setIdentity with remote complete")})).catch((t=>{Ei("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):Ei("setIdentity is not connected to remote")})),this.connect=()=>{if(Ei("connect",this.host),this.websocket)return void Ei("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info("WebSocket connected"),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info("WebSocket closed",t.reason):Ei("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 n("Websocket disconnected"))})),t.wasClean||setTimeout((()=>{this.connect()}),1e3)},t.onerror=e=>{this.connectedToRemote?console.error("WebSocket encountered error: ",e):Ei("WebSocket errored, it was not connected to the remote"),t.close()}},this.disconnect=t=>{var e;Ei("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.handleWebSocketMsg=t=>{let e;Ei("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 i=new Ti(e);if(!i.correlationId)return void console.error("RPCClient WebSocketTransport received unexpected msg from the server, not correlationId found in response.",e);const s=this.pendingPromisesForResponse[i.correlationId];s?s.resolve(i):console.warn("rcvd WS msg/response that doesn't match any pending RPC's",e)},this.resetConnection=()=>e(this,void 0,void 0,(function*(){Ei("resetConnection"),this.disconnect("WebSocketTransport#resetConnection"),yield Ii(100),this.connect()})),this.sendCall=t=>e(this,void 0,void 0,(function*(){var e;Ei("sendCall",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let s=new ki(Ri.DEFAULT_TIMEOUT_MS);return null===(e=this.websocket)||void 0===e||e.send(JSON.stringify(t)),this.pendingPromisesForResponse[t.correlationId]=s,yield s.promise.finally((()=>{delete this.pendingPromisesForResponse[t.correlationId]}))})),this.setConnectedToRemote=t=>{Ei(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},Ei("new WebSocketTransport()"),this.host=t.host,this.connect()}}Ri.DEFAULT_TIMEOUT_MS=1e4;const Mi=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}};class zi{constructor(){this.events={},this.publish=(t,i)=>e(this,void 0,void 0,(function*(){const e=this.events[t];e&&e.forEach((function(t){t.call(t,i)}))})),this.subscribe=(t,e)=>{this.events[t]||(this.events[t]=[]),this.events[t].push(e)},this.unsubscribe=(t,e)=>{if(!this.events[t])return;let i=this.events[t].indexOf(e);this.events[t].splice(i)}}}const xi={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Li{constructor(t){var s,n,r,o,c,h;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new zi,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,s)=>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?Mi(t):t,s&&(e.args=s);const n=new i(e);if(!n.procedure&&!n.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');n.identity||(n.identity={}),n.identity=ei(Object.assign({},this.identity),n.identity);const r=yield this.callManager.manageClientRequest(n);if(!r.success)throw r;const o=a(e);return this.vent.publish(o,null==r?void 0:r.data),r})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let i;i="string"==typeof t?Mi(t):t,e&&(i.args=e);const s=this.callManager.getCachedResponse(i);if(s)return s},this.getIdentity=()=>this.identity?Je(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 i;return i="string"==typeof t?Mi(t):t,function(t){return e.call(Object.assign(Object.assign({},i),{args:t}))}},this.registerResponseInterceptor=t=>{this.callManager.addResponseInterceptor(t)},this.registerRequestInterceptor=t=>{this.callManager.addRequestInterceptor(t)},this.registerWebSocketConnectionStatusChangeListener=t=>{this.webSocketConnectionChangeListeners.push(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=Je(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const i=Je(this.identity);i.metadata=t,this.identity.metadata=t,this.callManager.setIdentity(i)},!(null===(s=null==t?void 0:t.hosts)||void 0===s?void 0:s.http)&&!(null===(n=null==t?void 0:t.transports)||void 0===n?void 0:n.http))throw new Error(xi.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(xi.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(xi.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new oi(u):new Ci(u);const d=[];(null===(r=t.transports)||void 0===r?void 0:r.websocket)?d.push(t.transports.websocket):(null===(o=null==t?void 0:t.hosts)||void 0===o?void 0:o.websocket)&&(this.webSocketTransport=new Ri({host:t.hosts.websocket,onConnectionStatusChange:this.onWebSocketConnectionStatusChange}),d.push(this.webSocketTransport)),(null===(c=t.transports)||void 0===c?void 0:c.http)?d.push(t.transports.http):(null===(h=null==t?void 0:t.hosts)||void 0===h?void 0:h.http)&&(this.httpTransport=new Ai({host:t.hosts.http}),d.push(this.httpTransport)),this.callManager=new ri({cache:l,deadlineMs:t.deadlineMs||Li.DEFAULT_DEADLINE_MS,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:d})}subscribe(t,e){const i="string"==typeof t.request?Mi(t.request):t.request,s=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.subscribe(s,e)}unsubscribe(t,e){const i="string"==typeof t.request?Mi(t.request):t.request,s=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.unsubscribe(s,e)}}Li.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=Li,t.RPCResponse=Ti,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=umd.js.map |
{ | ||
"name": "@therms/rpc-client", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "RPC framework, browser client lib", | ||
@@ -5,0 +5,0 @@ "private": false, |
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
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
480841
2760