New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@therms/rpc-client

Package Overview
Dependencies
Maintainers
3
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@therms/rpc-client - npm Package Compare versions

Comparing version 2.11.4 to 2.12.0

dist/types.d.ts

58

dist/cjs.js

@@ -39,2 +39,22 @@ 'use strict';

function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
const DEFAULT_REQUEST_SCOPE = 'global';

@@ -179,2 +199,5 @@ const DEFAULT_REQUEST_VERSION = '1';

this.interceptors.response.push(interceptor);
return () => {
this.interceptors.response = this.interceptors.response.filter(cb => cb !== interceptor);
};
};

@@ -185,2 +208,5 @@ this.addRequestInterceptor = (interceptor) => {

this.interceptors.request.push(interceptor);
return () => {
this.interceptors.request = this.interceptors.request.filter(cb => cb !== interceptor);
};
};

@@ -246,8 +272,19 @@ this.clearCache = (request) => {

this.interceptRequestMutator = (originalRequest) => __awaiter(this, void 0, void 0, function* () {
var e_1, _a;
let request = originalRequest;
if (this.interceptors.request.length) {
debug$3('interceptRequestMutator(), original request:', originalRequest);
for (const interceptor of this.interceptors.request) {
request = yield interceptor(request);
try {
for (var _b = __asyncValues(this.interceptors.request), _c; _c = yield _b.next(), !_c.done;) {
const interceptor = _c.value;
request = yield interceptor(request);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}

@@ -542,2 +579,5 @@ return request;

this.serverMessageHandlers.push(handler);
return () => {
this.serverMessageHandlers = this.serverMessageHandlers.filter(cb => cb !== handler);
};
};

@@ -699,2 +739,3 @@ this.unsubscribeFromServerMessages = (handler) => {

this.events[topic].push(handler);
return () => this.unsubscribe(topic, handler);
};

@@ -789,9 +830,12 @@ this.unsubscribe = (topic, handler) => {

this.registerResponseInterceptor = (responseInterceptor) => {
this.callManager.addResponseInterceptor(responseInterceptor);
return this.callManager.addResponseInterceptor(responseInterceptor);
};
this.registerRequestInterceptor = (requestInterceptor) => {
this.callManager.addRequestInterceptor(requestInterceptor);
return this.callManager.addRequestInterceptor(requestInterceptor);
};
this.registerWebSocketConnectionStatusChangeListener = (cb) => {
this.webSocketConnectionChangeListeners.push(cb);
return () => {
this.webSocketConnectionChangeListeners = this.webSocketConnectionChangeListeners.filter(_cb => _cb !== cb);
};
};

@@ -879,3 +923,3 @@ this.sendClientMessageToServer = (msg) => {

const callRequestKey = makeCallRequestKey(Object.assign(Object.assign({}, request), { args: filter.args }));
this.vent.subscribe(callRequestKey, handler);
return this.vent.subscribe(callRequestKey, handler);
}

@@ -892,5 +936,5 @@ unsubscribe(filter, handler) {

console.warn('RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration');
return;
return () => { };
}
this.webSocketTransport.subscribeToServerMessages(handler);
return this.webSocketTransport.subscribeToServerMessages(handler);
}

@@ -897,0 +941,0 @@ unsubscribeFromServerMessages(handler) {

@@ -30,2 +30,22 @@ import stringify from 'fast-json-stable-stringify';

function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
const DEFAULT_REQUEST_SCOPE = 'global';

@@ -170,2 +190,5 @@ const DEFAULT_REQUEST_VERSION = '1';

this.interceptors.response.push(interceptor);
return () => {
this.interceptors.response = this.interceptors.response.filter(cb => cb !== interceptor);
};
};

@@ -176,2 +199,5 @@ this.addRequestInterceptor = (interceptor) => {

this.interceptors.request.push(interceptor);
return () => {
this.interceptors.request = this.interceptors.request.filter(cb => cb !== interceptor);
};
};

@@ -237,8 +263,19 @@ this.clearCache = (request) => {

this.interceptRequestMutator = (originalRequest) => __awaiter(this, void 0, void 0, function* () {
var e_1, _a;
let request = originalRequest;
if (this.interceptors.request.length) {
debug$3('interceptRequestMutator(), original request:', originalRequest);
for (const interceptor of this.interceptors.request) {
request = yield interceptor(request);
try {
for (var _b = __asyncValues(this.interceptors.request), _c; _c = yield _b.next(), !_c.done;) {
const interceptor = _c.value;
request = yield interceptor(request);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}

@@ -533,2 +570,5 @@ return request;

this.serverMessageHandlers.push(handler);
return () => {
this.serverMessageHandlers = this.serverMessageHandlers.filter(cb => cb !== handler);
};
};

@@ -690,2 +730,3 @@ this.unsubscribeFromServerMessages = (handler) => {

this.events[topic].push(handler);
return () => this.unsubscribe(topic, handler);
};

@@ -780,9 +821,12 @@ this.unsubscribe = (topic, handler) => {

this.registerResponseInterceptor = (responseInterceptor) => {
this.callManager.addResponseInterceptor(responseInterceptor);
return this.callManager.addResponseInterceptor(responseInterceptor);
};
this.registerRequestInterceptor = (requestInterceptor) => {
this.callManager.addRequestInterceptor(requestInterceptor);
return this.callManager.addRequestInterceptor(requestInterceptor);
};
this.registerWebSocketConnectionStatusChangeListener = (cb) => {
this.webSocketConnectionChangeListeners.push(cb);
return () => {
this.webSocketConnectionChangeListeners = this.webSocketConnectionChangeListeners.filter(_cb => _cb !== cb);
};
};

@@ -870,3 +914,3 @@ this.sendClientMessageToServer = (msg) => {

const callRequestKey = makeCallRequestKey(Object.assign(Object.assign({}, request), { args: filter.args }));
this.vent.subscribe(callRequestKey, handler);
return this.vent.subscribe(callRequestKey, handler);
}

@@ -883,5 +927,5 @@ unsubscribe(filter, handler) {

console.warn('RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration');
return;
return () => { };
}
this.webSocketTransport.subscribeToServerMessages(handler);
return this.webSocketTransport.subscribeToServerMessages(handler);
}

@@ -888,0 +932,0 @@ unsubscribeFromServerMessages(handler) {

9

dist/manager/ClientManager.d.ts

@@ -8,2 +8,3 @@ import { Cache } from '../cache/Cache';

import { RPCClientIdentity } from '../RPCClientIdentity';
import { UnsubscribeCallback } from "../types";
interface ClientManagerOptions {

@@ -17,4 +18,4 @@ cache?: Cache;

export interface ClientManager {
addResponseInterceptor(interceptor: CallResponseInterceptor): void;
addRequestInterceptor(interceptor: CallRequestInterceptor): void;
addResponseInterceptor(interceptor: CallResponseInterceptor): UnsubscribeCallback;
addRequestInterceptor(interceptor: CallRequestInterceptor): UnsubscribeCallback;
clearCache(request?: CallRequestDTO): void;

@@ -33,4 +34,4 @@ getCachedResponse(request: CallRequestDTO): CallResponseDTO | undefined;

constructor(options: ClientManagerOptions);
addResponseInterceptor: (interceptor: CallResponseInterceptor) => void;
addRequestInterceptor: (interceptor: CallRequestInterceptor) => void;
addResponseInterceptor: (interceptor: CallResponseInterceptor) => UnsubscribeCallback;
addRequestInterceptor: (interceptor: CallRequestInterceptor) => UnsubscribeCallback;
clearCache: (request?: CallRequestDTO<any> | undefined) => void;

@@ -37,0 +38,0 @@ getCachedResponse: (request: CallRequestDTO<any>) => CallResponseDTO<any> | undefined;

@@ -9,2 +9,3 @@ import { CallRequestDTO } from './CallRequestDTO';

import { RPCClientIdentity } from './RPCClientIdentity';
import { UnsubscribeCallback } from "./types";
export interface RPCClient {

@@ -18,5 +19,5 @@ call<Args = any, Data = any>(request: CallRequestDTO<Args> | string, args?: Args): Promise<CallResponseDTO<Data>>;

makeProcedure<Args = any, Data = any>(request: CallRequestDTO<Args> | string): (args?: any) => Promise<CallResponseDTO<Data>>;
registerResponseInterceptor(responseInterceptor: CallResponseInterceptor): void;
registerRequestInterceptor(requestInterceptor: CallRequestInterceptor): void;
registerWebSocketConnectionStatusChangeListener(cb: (connected: boolean) => void): void;
registerResponseInterceptor(responseInterceptor: CallResponseInterceptor): UnsubscribeCallback;
registerRequestInterceptor(requestInterceptor: CallRequestInterceptor): UnsubscribeCallback;
registerWebSocketConnectionStatusChangeListener(cb: (connected: boolean) => void): UnsubscribeCallback;
sendClientMessageToServer(msg: any): void;

@@ -28,4 +29,4 @@ setIdentity(identity?: RPCClientIdentity): void;

args?: any;
}, handler: (response: CallResponseDTO) => void): void;
subscribeToServerMessages(handler: (msg: any) => void): void;
}, handler: (response: CallResponseDTO) => void): UnsubscribeCallback;
subscribeToServerMessages(handler: (msg: any) => void): UnsubscribeCallback;
transports(): {

@@ -75,5 +76,5 @@ http: HTTPTransport | undefined;

makeProcedure: <Args = any, Data = any>(request: string | CallRequestDTO<Args>) => (args?: any) => Promise<CallResponseDTO<Data>>;
registerResponseInterceptor: (responseInterceptor: CallResponseInterceptor) => void;
registerRequestInterceptor: (requestInterceptor: CallRequestInterceptor) => void;
registerWebSocketConnectionStatusChangeListener: (cb: (connected: boolean) => void) => void;
registerResponseInterceptor: (responseInterceptor: CallResponseInterceptor) => UnsubscribeCallback;
registerRequestInterceptor: (requestInterceptor: CallRequestInterceptor) => UnsubscribeCallback;
registerWebSocketConnectionStatusChangeListener: (cb: (connected: boolean) => void) => UnsubscribeCallback;
sendClientMessageToServer: (msg: any) => void;

@@ -80,0 +81,0 @@ setIdentity: (identity?: RPCClientIdentity | undefined) => void;

@@ -5,2 +5,3 @@ import { Transport } from './Transport';

import { RPCClientIdentity } from '../RPCClientIdentity';
import { UnsubscribeCallback } from "../types";
interface WebSocketTransportOptions {

@@ -30,3 +31,3 @@ host: string;

setIdentity: (identity?: RPCClientIdentity) => Promise<void>;
subscribeToServerMessages: (handler: (msg: any) => void) => void;
subscribeToServerMessages: (handler: (msg: any) => void) => UnsubscribeCallback;
unsubscribeFromServerMessages: (handler: (msg: any) => void) => void;

@@ -33,0 +34,0 @@ private _connect;

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RPCClient={})}(this,(function(t){"use strict";function e(t,e,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 E=/^\[object .+?Constructor\]$/,I=Function.prototype,M=Object.prototype,x=I.toString,z=M.hasOwnProperty,R=RegExp("^"+x.call(z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function L(t){return!(!_(t)||(e=t,O&&O in e))&&(j(t)?R:E).test(k(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"),D=Object.create,W=function(){function t(){}return function(e){if(!_(e))return{};if(D)return D(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function U(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 q(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=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}: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),U(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&&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 Et(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 It(t,e){return function(i){return t(e(i))}}var Mt=It(Object.keys,Object),xt=Object.prototype.hasOwnProperty;function zt(t){return at(t)?Et(t):function(t){if(!ht(t))return Mt(t);var e=[];for(var i in Object(t))xt.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var Rt=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&&Rt.call(t,s))&&i.push(s);return i}function Ft(t){return at(t)?Et(t,!0):Lt(t)}var Pt=F(Object,"create");var Dt=Object.prototype.hasOwnProperty;var Wt=Object.prototype.hasOwnProperty;function Ut(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 qt(t,e){for(var i=t.length;i--;)if(tt(t[i][0],e))return i;return-1}Ut.prototype.clear=function(){this.__data__=Pt?Pt(null):{},this.size=0},Ut.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ut.prototype.get=function(t){var e=this.__data__;if(Pt){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return Dt.call(e,t)?e[t]:void 0},Ut.prototype.has=function(t){var e=this.__data__;return Pt?void 0!==e[t]:Wt.call(e,t)},Ut.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 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=qt(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=qt(e,t);return i<0?void 0:e[i][1]},Bt.prototype.has=function(t){return qt(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var i=this.__data__,s=qt(i,t);return s<0?(++this.size,i.push([t,e])):i[s][1]=e,this};var $t=F(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 Ut,map:new($t||Bt),string:new Ut}},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=It(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,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]",Se=k(fe),je=k($t),Ce=k(ye),Te=k(ve),Oe=k(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,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,Ee=Object.prototype.hasOwnProperty;var Ie=l.Uint8Array;function Me(t){var e=new t.constructor(t.byteLength);return new Ie(e).set(new Ie(t)),e}var xe=/\w*$/;var ze=u?u.prototype:void 0,Re=ze?ze.valueOf:void 0;function Le(t,e){var i=e?Me(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function Fe(t,e,i){var s,n,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return Me(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var i=e?Me(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,xe.exec(n))).lastIndex=n.lastIndex,r;case"[object Symbol]":return s=t,Re?Object(Re.call(s)):{}}}function Pe(t){return"function"!=typeof t.constructor||ht(t)?{}:W(Vt(t))}var De=Tt&&Tt.isMap,We=De?_t(De):function(t){return w(t)&&"[object Map]"==ke(t)};var Ue=Tt&&Tt.isSet,qe=Ue?_t(Ue):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]&&Ee.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return q(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?{}:Pe(t),!a)return c?function(t,e){return st(t,le(t),e)}(t,function(t,e){return t&&st(e,Ft(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=Fe(t,u,a)}}r||(r=new te);var p=r.get(t);if(p)return p;r.set(t,o),qe(t)?t.forEach((function(s){o.add(Ge(s,e,i,s,t,r))})):We(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?Ft: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=q(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,Ft(t))}(a):_(a)&&!j(a)||(u=Pe(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)}}),Ft)}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?AbortController:class{constructor(){this.signal=new ui}abort(){this.signal.dispatchEvent("abort")}},hi="function"==typeof AbortSignal,li="function"==typeof ci.AbortSignal,ui=hi?AbortSignal:li?ci.AbortController: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)))}},di=new Set,pi=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;vi(i)&&gi(i,`${t} option`,`options.${e}`,Si)},fi=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(vi(i)){const{prototype:s}=Si,{get:n}=Object.getOwnPropertyDescriptor(s,t);gi(i,`${t} method`,`cache.${e}()`,n)}},yi=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},vi=t=>!di.has(t),gi=(t,e,i,s)=>{di.add(t);yi(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,s)},bi=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),wi=t=>bi(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?mi:null:null;class mi extends Array{constructor(t){super(t),this.fill(0)}}class _i{constructor(t){if(0===t)return[];const e=wi(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class Si{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,maxEntrySize:p=0,sizeCalculation:f,fetchMethod:y,fetchContext:v,noDeleteOnFetchRejection:g,noDeleteOnStaleGet:b}=t,{length:w,maxAge:m,stale:_}=t instanceof Si?{}:t;if(0!==e&&!bi(e))throw new TypeError("max option must be a nonnegative integer");const S=e?wi(e):Array;if(!S)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=d,this.maxEntrySize=p||this.maxSize,this.sizeCalculation=f||w,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=y||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=v,!this.fetchMethod&&void 0!==v)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new S(e),this.prev=new S(e),this.head=0,this.tail=0,this.free=new _i(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=!!g,0!==this.maxEntrySize){if(0!==this.maxSize&&!bi(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!bi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!_,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=bi(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||m||0,this.ttl){if(!bi(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(vi(t)){di.add(t);yi("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,Si)}}_&&pi("stale","allowStale"),m&&pi("maxAge","ttl"),w&&pi("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new mi(this.max),this.starts=new mi(this.max),this.setItemTTL=(t,e,i=ai.now())=>{if(this.starts[t]=0!==e?i: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,i){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new mi(this.max),this.removeItemSize=t=>{this.calculatedSize-=this.sizes[t],this.sizes[t]=0},this.requireSize=(t,e,i,s)=>{if(!bi(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),!bi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e)=>{this.sizes[t]=e;const i=this.maxSize-this.sizes[t];for(;this.calculatedSize>i;)this.evict(!0);this.calculatedSize+=this.sizes[t]}}removeItemSize(t){}addItemSize(t,e){}requireSize(t,e,i,s){if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize 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 fi("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({allowStale:!0})){const i=this.keyList[e],s=this.valList[e],n={value:this.isBackgroundFetch(s)?s.__staleWhileFetching:s};if(this.ttls){n.ttl=this.ttls[e];const t=ai.now()-this.starts[e];n.start=Math.floor(Date.now()-t)}this.sizes&&(n.size=this.sizes[e]),t.unshift([i,n])}return t}load(t){this.clear();for(const[e,i]of t){if(i.start){const t=Date.now()-i.start;i.start=ai.now()-t}this.set(e,i.value,i)}}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,start:s,noDisposeOnSet:n=this.noDisposeOnSet,size:r=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL}={}){if(r=this.requireSize(t,e,r,o),this.maxEntrySize&&r>this.maxEntrySize)return this;let c=0===this.size?void 0:this.keyMap.get(t);if(void 0===c)c=this.newIndex(),this.keyList[c]=t,this.valList[c]=e,this.keyMap.set(t,c),this.next[this.tail]=c,this.prev[c]=this.tail,this.tail=c,this.size++,this.addItemSize(c,r),a=!1;else{const i=this.valList[c];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort():n||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(c),this.valList[c]=e,this.addItemSize(c,r)),this.moveToTail(c)}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),a||this.setItemTTL(c,i,s),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))){const t=this.valList[i];return this.isBackgroundFetch(t)?t.__staleWhileFetching:t}}backgroundFetch(t,e,i,s){const n=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(n))return n;const r=new ci,o={signal:r.signal,options:i,context:s},a=new Promise((e=>e(this.fetchMethod(t,n,o)))).then((e=>(r.signal.aborted||this.set(t,e,o.options),e)),(s=>{if(this.valList[e]===a){!i.noDeleteOnFetchRejection||void 0===a.__staleWhileFetching?this.delete(t):this.valList[e]=a.__staleWhileFetching}if(a.__returned===a)throw s}));return a.__abortController=r,a.__staleWhileFetching=n,a.__returned=null,void 0===e?(this.set(t,a,o.options),e=this.keyMap.get(t)):this.valList[e]=a,a}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,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:o=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:h=this.noDeleteOnFetchRejection,fetchContext:l=this.fetchContext,forceRefresh:u=!1}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s});const d={allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s,ttl:n,noDisposeOnSet:r,size:o,sizeCalculation:a,noUpdateTTL:c,noDeleteOnFetchRejection:h};let p=this.keyMap.get(t);if(void 0===p){const e=this.backgroundFetch(t,p,d,l);return e.__returned=e}{const s=this.valList[p];if(this.isBackgroundFetch(s))return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s;if(!u&&!this.isStale(p))return this.moveToTail(p),i&&this.updateItemAge(p),s;const n=this.backgroundFetch(t,p,d,l);return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet}={}){const n=this.keyMap.get(t);if(void 0!==n){const r=this.valList[n],o=this.isBackgroundFetch(r);if(this.isStale(n))return o?e?r.__staleWhileFetching:void 0:(s||this.delete(t),e?r:void 0);if(o)return;return this.moveToTail(n),i&&this.updateItemAge(n),r}}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 fi("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 fi("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(vi(i)){const{prototype:s}=Si,{get:n}=Object.getOwnPropertyDescriptor(s,t);gi(i,`${t} property`,`cache.${e}`,n)}})("length","size"),this.size}static get AbortController(){return ci}static get AbortSignal(){return ui}}var ji=Si;const Ci=si("rpc:InMemoryCache");class Ti{constructor(t){this.clearCache=()=>{var t;Ci("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.clear()},this.getCachedResponse=t=>{var e;Ci("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;Ci("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 ji({max:(null==t?void 0:t.cacheMaxSize)||Ti.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||Ti.DEFAULT_CACHE_MAX_AGE_MS})}}Ti.DEFAULT_CACHE_MAX_AGE_MS=3e5,Ti.DEFAULT_CACHE_MAX_SIZE=100;class Oi{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 Ai=si("rpc:HTTPTransport");class ki{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*(){Ai("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 Oi(n)})),this.setIdentity=t=>{Ai("setIdentity",t),this.identity=t},this.host=t.host}}class Ei{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))),Mi=si("rpc:WebSocketTransport");class xi{constructor(t){this.options=t,this.connectedToRemote=!1,this.isWaitingForIdentityConfirmation=!1,this.pendingPromisesForResponse={},this.serverMessageHandlers=[],this.websocketId=void 0,this.name="WebSocketTransport",this.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.connect=()=>{this._connect()},this.disconnect=()=>{this._disconnect("public disconnect() called")},this.sendClientMessageToServer=t=>{var e;let i=t;try{i=JSON.stringify({clientMessage: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(Mi("sendRequest",t);this.isWaitingForIdentityConfirmation;)Mi("waiting for identity confirmation"),yield Ii(100);return this.sendCall(t)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(Mi("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?Mi('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t}).then((()=>{Mi("setIdentity with remote complete")})).catch((t=>{Mi("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):Mi("setIdentity is not connected to remote")})),this.subscribeToServerMessages=t=>{this.serverMessageHandlers.push(t)},this.unsubscribeFromServerMessages=t=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))},this._connect=()=>{if(Mi("connect",this.host),this.websocket)return void Mi("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info(`[${(new Date).toLocaleTimeString()}] WebSocket connected`),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info(`[${(new Date).toLocaleTimeString()}] WebSocket closed`,t.reason):Mi("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):Mi("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>{var e;Mi("_disconnect"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,null===(e=this.websocket)||void 0===e||e.close(1e3,t),this.websocket=void 0,this.websocketId=void 0},this.handleServerMessage=t=>{this.serverMessageHandlers.forEach((e=>{try{e(t.serverMessage)}catch(i){console.warn("WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling",t,"handler func:",e),console.error(i)}}))},this.handleWebSocketMsg=t=>{let e;Mi("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 Oi(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*(){Mi("resetConnection"),this._disconnect("WebSocketTransport#resetConnection"),yield Ii(100),this._connect()})),this.sendCall=t=>e(this,void 0,void 0,(function*(){var e;Mi("sendCall",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let s=new Ei(xi.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=>{Mi(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},Mi("new WebSocketTransport()"),this.host=t.host,this.connect()}}xi.DEFAULT_TIMEOUT_MS=1e4;const zi=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}};class Ri{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 Li={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Fi{constructor(t){var s,n,r,o,c,h;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new Ri,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?zi(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?zi(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?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.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)},this.transports=()=>({http:this.httpTransport,websocket:this.webSocketTransport}),!(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(Li.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(Li.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(Li.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new oi(u):new Ti(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 xi({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 ki({host:t.hosts.http}),d.push(this.httpTransport)),this.callManager=new ri({cache:l,deadlineMs:t.deadlineMs||Fi.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,s=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.subscribe(s,e)}unsubscribe(t,e){const i="string"==typeof t.request?zi(t.request):t.request,s=a(Object.assign(Object.assign({},i),{args:t.args}));this.vent.unsubscribe(s,e)}subscribeToServerMessages(t){this.webSocketTransport?this.webSocketTransport.subscribeToServerMessages(t):console.warn("RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration")}unsubscribeFromServerMessages(t){var e;null===(e=this.webSocketTransport)||void 0===e||e.unsubscribeFromServerMessages(t)}}Fi.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=Fi,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())}))}function i(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],s=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,s=t[Symbol.asyncIterator];return s?s.call(t):(t=i(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(i){e[i]=t[i]&&function(e){return new Promise((function(s,n){(function(t,e,i,s){Promise.resolve(s).then((function(e){t({value:e,done:i})}),e)})(s,n,(e=t[i](e)).done,e.value)}))}}}class n{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 r extends Error{}class o extends Error{}class a extends Error{}function c(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}const h=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(!c(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:i,compare:s}=e,n=[],r=[],o=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)?o(t):c(t)?a(t):t))),i},a=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)?o(s):i&&c(s)?a(s):s,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:n}))}return h};return Array.isArray(t)?i?o(t):t.slice():a(t)}(t.args||{},{deep:!0}))}`:`${t.scope}${t.procedure}${t.version}`;var l="object"==typeof global&&global&&global.Object===Object&&global,u="object"==typeof self&&self&&self.Object===Object&&self,d=l||u||Function("return this")(),p=d.Symbol,f=Object.prototype,y=f.hasOwnProperty,v=f.toString,g=p?p.toStringTag:void 0;var b=Object.prototype.toString;var w=p?p.toStringTag:void 0;function m(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?function(t){var e=y.call(t,g),i=t[g];try{t[g]=void 0;var s=!0}catch(t){}var n=v.call(t);return s&&(e?t[g]=i:delete t[g]),n}(t):function(t){return b.call(t)}(t)}function _(t){return null!=t&&"object"==typeof t}var S=Array.isArray;function C(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function j(t){return t}function T(t){if(!C(t))return!1;var e=m(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var O,A=d["__core-js_shared__"],k=(O=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var E=Function.prototype.toString;function I(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var M=/^\[object .+?Constructor\]$/,x=Function.prototype,z=Object.prototype,R=x.toString,L=z.hasOwnProperty,F=RegExp("^"+R.call(L).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function P(t){return!(!C(t)||(e=t,k&&k in e))&&(T(t)?F:M).test(I(t));var e}function D(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return P(i)?i:void 0}var W=D(d,"WeakMap"),q=Object.create,U=function(){function t(){}return function(e){if(!C(e))return{};if(q)return q(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function B(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 N(t,e){var i=-1,s=t.length;for(e||(e=Array(s));++i<s;)e[i]=t[i];return e}var $=Date.now;var H,G,J,V=function(){try{var t=D(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),K=V,X=K?function(t,e){return K(t,"toString",{configurable:!0,enumerable:!1,value:(i=e,function(){return i}),writable:!0});var i}:j,Z=(H=X,G=0,J=0,function(){var t=$(),e=16-(t-J);if(J=t,e>0){if(++G>=800)return arguments[0]}else G=0;return H.apply(void 0,arguments)}),Q=Z;var Y=/^(?:0|[1-9]\d*)$/;function tt(t,e){var i=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==i||"symbol"!=i&&Y.test(t))&&t>-1&&t%1==0&&t<e}function et(t,e,i){"__proto__"==e&&K?K(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}function it(t,e){return t===e||t!=t&&e!=e}var st=Object.prototype.hasOwnProperty;function nt(t,e,i){var s=t[e];st.call(t,e)&&it(s,i)&&(void 0!==i||e in t)||et(t,e,i)}function rt(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?et(i,a,c):nt(i,a,c)}return i}var ot=Math.max;function at(t,e){return Q(function(t,e,i){return e=ot(void 0===e?t.length-1:e,0),function(){for(var s=arguments,n=-1,r=ot(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),B(t,this,a)}}(t,e,j),t+"")}function ct(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function ht(t){return null!=t&&ct(t.length)&&!T(t)}var lt=Object.prototype;function ut(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||lt)}function dt(t){return _(t)&&"[object Arguments]"==m(t)}var pt=Object.prototype,ft=pt.hasOwnProperty,yt=pt.propertyIsEnumerable,vt=dt(function(){return arguments}())?dt:function(t){return _(t)&&ft.call(t,"callee")&&!yt.call(t,"callee")},gt=vt;var bt="object"==typeof t&&t&&!t.nodeType&&t,wt=bt&&"object"==typeof module&&module&&!module.nodeType&&module,mt=wt&&wt.exports===bt?d.Buffer:void 0,_t=(mt?mt.isBuffer:void 0)||function(){return!1},St={};function Ct(t){return function(e){return t(e)}}St["[object Float32Array]"]=St["[object Float64Array]"]=St["[object Int8Array]"]=St["[object Int16Array]"]=St["[object Int32Array]"]=St["[object Uint8Array]"]=St["[object Uint8ClampedArray]"]=St["[object Uint16Array]"]=St["[object Uint32Array]"]=!0,St["[object Arguments]"]=St["[object Array]"]=St["[object ArrayBuffer]"]=St["[object Boolean]"]=St["[object DataView]"]=St["[object Date]"]=St["[object Error]"]=St["[object Function]"]=St["[object Map]"]=St["[object Number]"]=St["[object Object]"]=St["[object RegExp]"]=St["[object Set]"]=St["[object String]"]=St["[object WeakMap]"]=!1;var jt="object"==typeof t&&t&&!t.nodeType&&t,Tt=jt&&"object"==typeof module&&module&&!module.nodeType&&module,Ot=Tt&&Tt.exports===jt&&l.process,At=function(){try{var t=Tt&&Tt.require&&Tt.require("util").types;return t||Ot&&Ot.binding&&Ot.binding("util")}catch(t){}}(),kt=At&&At.isTypedArray,Et=kt?Ct(kt):function(t){return _(t)&&ct(t.length)&&!!St[m(t)]},It=Object.prototype.hasOwnProperty;function Mt(t,e){var i=S(t),s=!i&&gt(t),n=!i&&!s&&_t(t),r=!i&&!s&&!n&&Et(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&&!It.call(t,h)||o&&("length"==h||n&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||tt(h,c))||a.push(h);return a}function xt(t,e){return function(i){return t(e(i))}}var zt=xt(Object.keys,Object),Rt=Object.prototype.hasOwnProperty;function Lt(t){return ht(t)?Mt(t):function(t){if(!ut(t))return zt(t);var e=[];for(var i in Object(t))Rt.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var Ft=Object.prototype.hasOwnProperty;function Pt(t){if(!C(t))return function(t){var e=[];if(null!=t)for(var i in Object(t))e.push(i);return e}(t);var e=ut(t),i=[];for(var s in t)("constructor"!=s||!e&&Ft.call(t,s))&&i.push(s);return i}function Dt(t){return ht(t)?Mt(t,!0):Pt(t)}var Wt=D(Object,"create");var qt=Object.prototype.hasOwnProperty;var Ut=Object.prototype.hasOwnProperty;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])}}function Nt(t,e){for(var i=t.length;i--;)if(it(t[i][0],e))return i;return-1}Bt.prototype.clear=function(){this.__data__=Wt?Wt(null):{},this.size=0},Bt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Bt.prototype.get=function(t){var e=this.__data__;if(Wt){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return qt.call(e,t)?e[t]:void 0},Bt.prototype.has=function(t){var e=this.__data__;return Wt?void 0!==e[t]:Ut.call(e,t)},Bt.prototype.set=function(t,e){var i=this.__data__;return this.size+=this.has(t)?0:1,i[t]=Wt&&void 0===e?"__lodash_hash_undefined__":e,this};var $t=Array.prototype.splice;function Ht(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])}}Ht.prototype.clear=function(){this.__data__=[],this.size=0},Ht.prototype.delete=function(t){var e=this.__data__,i=Nt(e,t);return!(i<0)&&(i==e.length-1?e.pop():$t.call(e,i,1),--this.size,!0)},Ht.prototype.get=function(t){var e=this.__data__,i=Nt(e,t);return i<0?void 0:e[i][1]},Ht.prototype.has=function(t){return Nt(this.__data__,t)>-1},Ht.prototype.set=function(t,e){var i=this.__data__,s=Nt(i,t);return s<0?(++this.size,i.push([t,e])):i[s][1]=e,this};var Gt=D(d,"Map");function Jt(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 Vt(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 Kt(t,e){for(var i=-1,s=e.length,n=t.length;++i<s;)t[n+i]=e[i];return t}Vt.prototype.clear=function(){this.size=0,this.__data__={hash:new Bt,map:new(Gt||Ht),string:new Bt}},Vt.prototype.delete=function(t){var e=Jt(this,t).delete(t);return this.size-=e?1:0,e},Vt.prototype.get=function(t){return Jt(this,t).get(t)},Vt.prototype.has=function(t){return Jt(this,t).has(t)},Vt.prototype.set=function(t,e){var i=Jt(this,t),s=i.size;return i.set(t,e),this.size+=i.size==s?0:1,this};var Xt=xt(Object.getPrototypeOf,Object),Zt=Function.prototype,Qt=Object.prototype,Yt=Zt.toString,te=Qt.hasOwnProperty,ee=Yt.call(Object);function ie(t){var e=this.__data__=new Ht(t);this.size=e.size}ie.prototype.clear=function(){this.__data__=new Ht,this.size=0},ie.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},ie.prototype.get=function(t){return this.__data__.get(t)},ie.prototype.has=function(t){return this.__data__.has(t)},ie.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Ht){var s=i.__data__;if(!Gt||s.length<199)return s.push([t,e]),this.size=++i.size,this;i=this.__data__=new Vt(s)}return i.set(t,e),this.size=i.size,this};var se="object"==typeof t&&t&&!t.nodeType&&t,ne=se&&"object"==typeof module&&module&&!module.nodeType&&module,re=ne&&ne.exports===se?d.Buffer:void 0,oe=re?re.allocUnsafe:void 0;function ae(t,e){if(e)return t.slice();var i=t.length,s=oe?oe(i):new t.constructor(i);return t.copy(s),s}function ce(){return[]}var he=Object.prototype.propertyIsEnumerable,le=Object.getOwnPropertySymbols,ue=le?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}(le(t),(function(e){return he.call(t,e)})))}:ce;var de=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Kt(e,ue(t)),t=Xt(t);return e}:ce;function pe(t,e,i){var s=e(t);return S(t)?s:Kt(s,i(t))}function fe(t){return pe(t,Lt,ue)}function ye(t){return pe(t,Dt,de)}var ve=D(d,"DataView"),ge=D(d,"Promise"),be=D(d,"Set"),we="[object Map]",me="[object Promise]",_e="[object Set]",Se="[object WeakMap]",Ce="[object DataView]",je=I(ve),Te=I(Gt),Oe=I(ge),Ae=I(be),ke=I(W),Ee=m;(ve&&Ee(new ve(new ArrayBuffer(1)))!=Ce||Gt&&Ee(new Gt)!=we||ge&&Ee(ge.resolve())!=me||be&&Ee(new be)!=_e||W&&Ee(new W)!=Se)&&(Ee=function(t){var e=m(t),i="[object Object]"==e?t.constructor:void 0,s=i?I(i):"";if(s)switch(s){case je:return Ce;case Te:return we;case Oe:return me;case Ae:return _e;case ke:return Se}return e});var Ie=Ee,Me=Object.prototype.hasOwnProperty;var xe=d.Uint8Array;function ze(t){var e=new t.constructor(t.byteLength);return new xe(e).set(new xe(t)),e}var Re=/\w*$/;var Le=p?p.prototype:void 0,Fe=Le?Le.valueOf:void 0;function Pe(t,e){var i=e?ze(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function De(t,e,i){var s,n,r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return ze(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var i=e?ze(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 Pe(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,Re.exec(n))).lastIndex=n.lastIndex,r;case"[object Symbol]":return s=t,Fe?Object(Fe.call(s)):{}}}function We(t){return"function"!=typeof t.constructor||ut(t)?{}:U(Xt(t))}var qe=At&&At.isMap,Ue=qe?Ct(qe):function(t){return _(t)&&"[object Map]"==Ie(t)};var Be=At&&At.isSet,Ne=Be?Ct(Be):function(t){return _(t)&&"[object Set]"==Ie(t)},$e="[object Arguments]",He="[object Function]",Ge="[object Object]",Je={};function Ve(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(!C(t))return t;var l=S(t);if(l){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&Me.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return N(t,o)}else{var u=Ie(t),d=u==He||"[object GeneratorFunction]"==u;if(_t(t))return ae(t,a);if(u==Ge||u==$e||d&&!n){if(o=c||d?{}:We(t),!a)return c?function(t,e){return rt(t,de(t),e)}(t,function(t,e){return t&&rt(e,Dt(e),t)}(o,t)):function(t,e){return rt(t,ue(t),e)}(t,function(t,e){return t&&rt(e,Lt(e),t)}(o,t))}else{if(!Je[u])return n?t:{};o=De(t,u,a)}}r||(r=new ie);var p=r.get(t);if(p)return p;r.set(t,o),Ne(t)?t.forEach((function(s){o.add(Ve(s,e,i,s,t,r))})):Ue(t)&&t.forEach((function(s,n){o.set(n,Ve(s,e,i,n,t,r))}));var f=l?void 0:(h?c?ye:fe:c?Dt:Lt)(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]),nt(o,n,Ve(s,e,i,n,t,r))})),o}Je[$e]=Je["[object Array]"]=Je["[object ArrayBuffer]"]=Je["[object DataView]"]=Je["[object Boolean]"]=Je["[object Date]"]=Je["[object Float32Array]"]=Je["[object Float64Array]"]=Je["[object Int8Array]"]=Je["[object Int16Array]"]=Je["[object Int32Array]"]=Je["[object Map]"]=Je["[object Number]"]=Je[Ge]=Je["[object RegExp]"]=Je["[object Set]"]=Je["[object String]"]=Je["[object Symbol]"]=Je["[object Uint8Array]"]=Je["[object Uint8ClampedArray]"]=Je["[object Uint16Array]"]=Je["[object Uint32Array]"]=!0,Je["[object Error]"]=Je[He]=Je["[object WeakMap]"]=!1;function Ke(t){return Ve(t,5)}var Xe,Ze=function(t,e,i){for(var s=-1,n=Object(t),r=i(t),o=r.length;o--;){var a=r[Xe?o:++s];if(!1===e(n[a],a,n))break}return t};function Qe(t,e,i){(void 0!==i&&!it(t[e],i)||void 0===i&&!(e in t))&&et(t,e,i)}function Ye(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function ti(t,e,i,s,n,r,o){var a=Ye(t,i),c=Ye(e,i),h=o.get(c);if(h)Qe(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=S(c),f=!p&&_t(c),y=!p&&!f&&Et(c);u=c,p||f||y?S(a)?u=a:_(l=a)&&ht(l)?u=N(a):f?(d=!1,u=ae(c,!0)):y?(d=!1,u=Pe(c,!0)):u=[]:function(t){if(!_(t)||"[object Object]"!=m(t))return!1;var e=Xt(t);if(null===e)return!0;var i=te.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&Yt.call(i)==ee}(c)||gt(c)?(u=a,gt(a)?u=function(t){return rt(t,Dt(t))}(a):C(a)&&!T(a)||(u=We(c))):d=!1}d&&(o.set(c,u),n(u,c,s,r,o),o.delete(c)),Qe(t,i,u)}}function ei(t,e,i,s,n){t!==e&&Ze(e,(function(r,o){if(n||(n=new ie),C(r))ti(t,e,o,i,ei,s,n);else{var a=s?s(Ye(t,o),r,o+"",t,e,n):void 0;void 0===a&&(a=r),Qe(t,o,a)}}),Dt)}var ii,si=(ii=function(t,e,i){ei(t,e,i)},at((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=ii.length>3&&"function"==typeof n?(s--,n):void 0,r&&function(t,e,i){if(!C(i))return!1;var s=typeof e;return!!("number"==s?ht(i)&&tt(e,i.length):"string"==s&&e in i)&&it(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&&ii(t,o,i,n)}return t})));let ni=null;try{ni=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const ri=t=>ni&&new RegExp(ni).test(t)?(...e)=>console.log(t,...e):()=>{},oi=ri("rpc:ClientManager");class ai{constructor(t){this.options=t,this.inflightCallsByKey={},this.interceptors={request:[],response:[]},this.addResponseInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.response.push(t),()=>{this.interceptors.response=this.interceptors.response.filter((e=>e!==t))}},this.addRequestInterceptor=t=>{if("function"!=typeof t)throw new Error("cannot add interceptor that is not a function");return this.interceptors.request.push(t),()=>{this.interceptors.request=this.interceptors.request.filter((e=>e!==t))}},this.clearCache=t=>{oi("clearCache"),this.cache&&(t?this.cache.setCachedResponse(t,void 0):this.cache.clearCache())},this.getCachedResponse=t=>{var e;return oi("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(oi("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=t=>e(this,void 0,void 0,(function*(){oi("manageClientRequest",t);const i=yield this.interceptRequestMutator(t),s=h(i);if(this.inflightCallsByKey.hasOwnProperty(s))return oi("manageClientRequest using an existing in-flight call",s),this.inflightCallsByKey[s].then((e=>{const i=Ke(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=>{oi("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){var e,i;let n=t;if(this.interceptors.request.length){oi("interceptRequestMutator(), original request:",t);try{for(var r,o=s(this.interceptors.request);!(r=yield o.next()).done;){const t=r.value;n=yield t(n)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(i=o.return)&&(yield i.call(o))}finally{if(e)throw e.error}}}return n})),this.interceptResponseMutator=(t,i)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){oi("interceptResponseMutator",i,t);for(const s of this.interceptors.response)try{e=yield s(e,i)}catch(s){throw oi("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;oi("sendRequestWithTransport",t);let i=0;for(;!e&&this.transports[i];){const s=this.transports[i];if(s.isConnected()){oi(`sendRequestWithTransport trying ${this.transports[i].name}`,t);try{let i;const n=new Promise(((e,s)=>{i=setTimeout((()=>{s(new a(`Procedure ${t.procedure}`))}),this.options.deadlineMs)}));e=yield Promise.race([n,s.sendRequest(t)]).then((t=>(clearTimeout(i),t)))}catch(t){if(!(t instanceof a||t instanceof o))throw t;oi(`sending request with ${this.transports[i].name} failed, trying next transport`),i++}}else i++}if(!e&&!this.transports[i])throw new r(`Procedure ${t.procedure} did not get a response from any transports`);if(!e)throw new r(`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 ci{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}ci.DEFAULT_CACHE_MAX_AGE_MS=3e5,ci.DEFAULT_CACHE_MAX_SIZE=100;const hi="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,li="function"==typeof AbortController?AbortController:class{constructor(){this.signal=new pi}abort(){this.signal.dispatchEvent("abort")}},ui="function"==typeof AbortSignal,di="function"==typeof li.AbortSignal,pi=ui?AbortSignal:di?li.AbortController: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)))}},fi=new Set,yi=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;bi(i)&&wi(i,`${t} option`,`options.${e}`,ji)},vi=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(bi(i)){const{prototype:s}=ji,{get:n}=Object.getOwnPropertyDescriptor(s,t);wi(i,`${t} method`,`cache.${e}()`,n)}},gi=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},bi=t=>!fi.has(t),wi=(t,e,i,s)=>{fi.add(t);gi(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,s)},mi=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),_i=t=>mi(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?Si:null:null;class Si extends Array{constructor(t){super(t),this.fill(0)}}class Ci{constructor(t){if(0===t)return[];const e=_i(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class ji{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,maxEntrySize:p=0,sizeCalculation:f,fetchMethod:y,fetchContext:v,noDeleteOnFetchRejection:g,noDeleteOnStaleGet:b}=t,{length:w,maxAge:m,stale:_}=t instanceof ji?{}:t;if(0!==e&&!mi(e))throw new TypeError("max option must be a nonnegative integer");const S=e?_i(e):Array;if(!S)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=d,this.maxEntrySize=p||this.maxSize,this.sizeCalculation=f||w,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=y||null,this.fetchMethod&&"function"!=typeof this.fetchMethod)throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=v,!this.fetchMethod&&void 0!==v)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(e).fill(null),this.valList=new Array(e).fill(null),this.next=new S(e),this.prev=new S(e),this.head=0,this.tail=0,this.free=new Ci(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=!!g,0!==this.maxEntrySize){if(0!==this.maxSize&&!mi(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!mi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!_,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=mi(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||m||0,this.ttl){if(!mi(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(bi(t)){fi.add(t);gi("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,ji)}}_&&yi("stale","allowStale"),m&&yi("maxAge","ttl"),w&&yi("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new Si(this.max),this.starts=new Si(this.max),this.setItemTTL=(t,e,i=hi.now())=>{if(this.starts[t]=0!==e?i: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]?hi.now():0};let t=0;const e=()=>{const e=hi.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,i){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new Si(this.max),this.removeItemSize=t=>{this.calculatedSize-=this.sizes[t],this.sizes[t]=0},this.requireSize=(t,e,i,s)=>{if(this.isBackgroundFetch(e))return 0;if(!mi(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),!mi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.addItemSize=(t,e)=>{if(this.sizes[t]=e,this.maxSize){const e=this.maxSize-this.sizes[t];for(;this.calculatedSize>e;)this.evict(!0)}this.calculatedSize+=this.sizes[t]}}removeItemSize(t){}addItemSize(t,e){}requireSize(t,e,i,s){if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize 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 vi("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({allowStale:!0})){const i=this.keyList[e],s=this.valList[e],n={value:this.isBackgroundFetch(s)?s.__staleWhileFetching:s};if(this.ttls){n.ttl=this.ttls[e];const t=hi.now()-this.starts[e];n.start=Math.floor(Date.now()-t)}this.sizes&&(n.size=this.sizes[e]),t.unshift([i,n])}return t}load(t){this.clear();for(const[e,i]of t){if(i.start){const t=Date.now()-i.start;i.start=hi.now()-t}this.set(e,i.value,i)}}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,start:s,noDisposeOnSet:n=this.noDisposeOnSet,size:r=0,sizeCalculation:o=this.sizeCalculation,noUpdateTTL:a=this.noUpdateTTL}={}){if(r=this.requireSize(t,e,r,o),this.maxEntrySize&&r>this.maxEntrySize)return this.delete(t),this;let c=0===this.size?void 0:this.keyMap.get(t);if(void 0===c)c=this.newIndex(),this.keyList[c]=t,this.valList[c]=e,this.keyMap.set(t,c),this.next[this.tail]=c,this.prev[c]=this.tail,this.tail=c,this.size++,this.addItemSize(c,r),a=!1;else{const i=this.valList[c];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort():n||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(c),this.valList[c]=e,this.addItemSize(c,r)),this.moveToTail(c)}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),a||this.setItemTTL(c,i,s),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))){const t=this.valList[i];return this.isBackgroundFetch(t)?t.__staleWhileFetching:t}}backgroundFetch(t,e,i,s){const n=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(n))return n;const r=new li,o={signal:r.signal,options:i,context:s},a=new Promise((e=>e(this.fetchMethod(t,n,o)))).then((e=>(r.signal.aborted||this.set(t,e,o.options),e)),(s=>{if(this.valList[e]===a){!i.noDeleteOnFetchRejection||void 0===a.__staleWhileFetching?this.delete(t):this.valList[e]=a.__staleWhileFetching}if(a.__returned===a)throw s}));return a.__abortController=r,a.__staleWhileFetching=n,a.__returned=null,void 0===e?(this.set(t,a,o.options),e=this.keyMap.get(t)):this.valList[e]=a,a}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,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:o=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:h=this.noDeleteOnFetchRejection,fetchContext:l=this.fetchContext,forceRefresh:u=!1}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s});const d={allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:s,ttl:n,noDisposeOnSet:r,size:o,sizeCalculation:a,noUpdateTTL:c,noDeleteOnFetchRejection:h};let p=this.keyMap.get(t);if(void 0===p){const e=this.backgroundFetch(t,p,d,l);return e.__returned=e}{const s=this.valList[p];if(this.isBackgroundFetch(s))return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s;if(!u&&!this.isStale(p))return this.moveToTail(p),i&&this.updateItemAge(p),s;const n=this.backgroundFetch(t,p,d,l);return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet}={}){const n=this.keyMap.get(t);if(void 0!==n){const r=this.valList[n],o=this.isBackgroundFetch(r);if(this.isStale(n))return o?e?r.__staleWhileFetching:void 0:(s||this.delete(t),e?r:void 0);if(o)return;return this.moveToTail(n),i&&this.updateItemAge(n),r}}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 vi("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 vi("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(bi(i)){const{prototype:s}=ji,{get:n}=Object.getOwnPropertyDescriptor(s,t);wi(i,`${t} property`,`cache.${e}`,n)}})("length","size"),this.size}static get AbortController(){return li}static get AbortSignal(){return pi}}var Ti=ji;const Oi=ri("rpc:InMemoryCache");class Ai{constructor(t){this.clearCache=()=>{var t;Oi("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.clear()},this.getCachedResponse=t=>{var e;Oi("getCachedResponse, key: ",t);let i=null===(e=this.cachedResponseByParams)||void 0===e?void 0:e.get(h(t));return"string"==typeof i&&(i=JSON.parse(i)),i},this.setCachedResponse=(t,e)=>{var i,s;Oi("setCachedResponse",t,e);const n=h(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 Ti({max:(null==t?void 0:t.cacheMaxSize)||Ai.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||Ai.DEFAULT_CACHE_MAX_AGE_MS})}}Ai.DEFAULT_CACHE_MAX_AGE_MS=3e5,Ai.DEFAULT_CACHE_MAX_SIZE=100;class ki{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 Ei=ri("rpc:HTTPTransport");class Ii{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*(){Ei("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 ki(n)})),this.setIdentity=t=>{Ei("setIdentity",t),this.identity=t},this.host=t.host}}class Mi{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 xi=t=>new Promise((e=>setTimeout(e,t))),zi=ri("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.isConnected=()=>this.connectedToRemote&&!!this.websocket,this.connect=()=>{this._connect()},this.disconnect=()=>{this._disconnect("public disconnect() called")},this.sendClientMessageToServer=t=>{var e;let i=t;try{i=JSON.stringify({clientMessage: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(zi("sendRequest",t);this.isWaitingForIdentityConfirmation;)zi("waiting for identity confirmation"),yield xi(100);return this.sendCall(t)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(zi("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?zi('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t}).then((()=>{zi("setIdentity with remote complete")})).catch((t=>{zi("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):zi("setIdentity is not connected to remote")})),this.subscribeToServerMessages=t=>(this.serverMessageHandlers.push(t),()=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))}),this.unsubscribeFromServerMessages=t=>{this.serverMessageHandlers=this.serverMessageHandlers.filter((e=>e!==t))},this._connect=()=>{if(zi("connect",this.host),this.websocket)return void zi("connect() returning early, websocket already exists");this.websocketId=Math.random(),this.websocket=new WebSocket(this.host);const t=this.websocket;t.onopen=()=>{console.info(`[${(new Date).toLocaleTimeString()}] WebSocket connected`),this.setConnectedToRemote(!0)},t.onmessage=t=>{this.handleWebSocketMsg(t)},t.onclose=t=>{this.connectedToRemote?console.info(`[${(new Date).toLocaleTimeString()}] WebSocket closed`,t.reason):zi("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 o("Websocket disconnected"))})),t.wasClean||setTimeout((()=>{this.connect()}),1e3)},t.onerror=e=>{this.connectedToRemote?console.error("WebSocket encountered error: ",e):zi("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>{var e;zi("_disconnect"),this.setConnectedToRemote(!1),this.isWaitingForIdentityConfirmation=!1,null===(e=this.websocket)||void 0===e||e.close(1e3,t),this.websocket=void 0,this.websocketId=void 0},this.handleServerMessage=t=>{this.serverMessageHandlers.forEach((e=>{try{e(t.serverMessage)}catch(i){console.warn("WebSocketTransport.handleServerMessage() a serverMessageHandler errored when calling",t,"handler func:",e),console.error(i)}}))},this.handleWebSocketMsg=t=>{let e;zi("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 ki(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*(){zi("resetConnection"),this._disconnect("WebSocketTransport#resetConnection"),yield xi(100),this._connect()})),this.sendCall=t=>e(this,void 0,void 0,(function*(){var e;zi("sendCall",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let s=new Mi(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=>{zi(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},zi("new WebSocketTransport()"),this.host=t.host,this.connect()}}Ri.DEFAULT_TIMEOUT_MS=1e4;const Li=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}};class Fi{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)),this.unsubscribe=(t,e)=>{if(!this.events[t])return;let i=this.events[t].indexOf(e);this.events[t].splice(i)}}}const Pi={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Di{constructor(t){var i,s,r,o,a,c;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new Fi,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,i)=>e(this,void 0,void 0,(function*(){if(!t)throw new Error('RPCClient.call(request) requires a "request" param');let e;e="string"==typeof t?Li(t):t,i&&(e.args=i);const s=new n(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=si(Object.assign({},this.identity),s.identity);const r=yield this.callManager.manageClientRequest(s);if(!r.success)throw r;const o=h(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?Li(t):t,e&&(i.args=e);const s=this.callManager.getCachedResponse(i);if(s)return s},this.getIdentity=()=>this.identity?Ke(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?Li(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.webSocketConnectionChangeListeners=this.webSocketConnectionChangeListeners.filter((e=>e!==t))}),this.sendClientMessageToServer=t=>{this.webSocketTransport?this.webSocketTransport.isConnected()?this.webSocketTransport.sendClientMessageToServer(t):console.info("RPCClient.sendClientMessageToServer() cannot send because the websocket is not connected"):console.warn("RPCClient.sendClientMessageToServer() unable to send because RPCClient has no websocket configuration")},this.setIdentity=t=>{let e=Ke(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const i=Ke(this.identity);i.metadata=t,this.identity.metadata=t,this.callManager.setIdentity(i)},this.transports=()=>({http:this.httpTransport,websocket:this.webSocketTransport}),!(null===(i=null==t?void 0:t.hosts)||void 0===i?void 0:i.http)&&!(null===(s=null==t?void 0:t.transports)||void 0===s?void 0:s.http))throw new Error(Pi.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(Pi.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(Pi.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new ci(u):new Ai(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===(a=t.transports)||void 0===a?void 0:a.http)?d.push(t.transports.http):(null===(c=null==t?void 0:t.hosts)||void 0===c?void 0:c.http)&&(this.httpTransport=new Ii({host:t.hosts.http}),d.push(this.httpTransport)),this.callManager=new ai({cache:l,deadlineMs:t.deadlineMs||Di.DEFAULT_DEADLINE_MS,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:d})}subscribe(t,e){const i="string"==typeof t.request?Li(t.request):t.request,s=h(Object.assign(Object.assign({},i),{args:t.args}));return this.vent.subscribe(s,e)}unsubscribe(t,e){const i="string"==typeof t.request?Li(t.request):t.request,s=h(Object.assign(Object.assign({},i),{args:t.args}));this.vent.unsubscribe(s,e)}subscribeToServerMessages(t){return this.webSocketTransport?this.webSocketTransport.subscribeToServerMessages(t):(console.warn("RPCClient.subscribeToServerMessages() cannot subscribe because RPCClient has no websocket configuration"),()=>{})}unsubscribeFromServerMessages(t){var e;null===(e=this.webSocketTransport)||void 0===e||e.unsubscribeFromServerMessages(t)}}Di.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=Di,t.RPCResponse=ki,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -1,2 +0,2 @@

export declare const GetDebugLogger: (prefix: string) => (...args: any) => void;
export declare const GetDebugLogger: (prefix: string) => (...args: any[]) => void;
//# sourceMappingURL=debug-logger.d.ts.map

@@ -0,7 +1,8 @@

import { UnsubscribeCallback } from "../types";
export declare class Vent {
private events;
publish: (topic: string, data: any) => Promise<void>;
subscribe: (topic: string, handler: (data: any) => void) => void;
subscribe: (topic: string, handler: (data: any) => void) => UnsubscribeCallback;
unsubscribe: (topic: string, handler: (data: any) => void) => void;
}
//# sourceMappingURL=vent.d.ts.map
{
"name": "@therms/rpc-client",
"version": "2.11.4",
"version": "2.12.0",
"description": "RPC framework, browser client lib",

@@ -5,0 +5,0 @@ "private": false,

@@ -14,2 +14,3 @@ import { Cache } from '../cache/Cache'

import { GetDebugLogger } from '../utils/debug-logger'
import {UnsubscribeCallback} from "../types";

@@ -27,4 +28,4 @@ const debug = GetDebugLogger('rpc:ClientManager')

export interface ClientManager {
addResponseInterceptor(interceptor: CallResponseInterceptor): void
addRequestInterceptor(interceptor: CallRequestInterceptor): void
addResponseInterceptor(interceptor: CallResponseInterceptor): UnsubscribeCallback
addRequestInterceptor(interceptor: CallRequestInterceptor): UnsubscribeCallback
clearCache(request?: CallRequestDTO): void

@@ -67,2 +68,6 @@ getCachedResponse(request: CallRequestDTO): CallResponseDTO | undefined

this.interceptors.response.push(interceptor)
return () => {
this.interceptors.response = this.interceptors.response.filter(cb => cb !== interceptor)
}
}

@@ -74,2 +79,6 @@

this.interceptors.request.push(interceptor)
return () => {
this.interceptors.request = this.interceptors.request.filter(cb => cb !== interceptor)
}
}

@@ -170,3 +179,3 @@

for (const interceptor of this.interceptors.request) {
for await (const interceptor of this.interceptors.request) {
request = await interceptor(request)

@@ -173,0 +182,0 @@ }

@@ -16,2 +16,3 @@ import { CallRequestDTO } from './CallRequestDTO'

import { makeCallRequestKey } from './utils/cache-utils'
import {UnsubscribeCallback} from "./types";

@@ -48,9 +49,9 @@ const ERRORS = {

responseInterceptor: CallResponseInterceptor,
): void
): UnsubscribeCallback
registerRequestInterceptor(requestInterceptor: CallRequestInterceptor): void
registerRequestInterceptor(requestInterceptor: CallRequestInterceptor): UnsubscribeCallback
registerWebSocketConnectionStatusChangeListener(
cb: (connected: boolean) => void,
): void
): UnsubscribeCallback

@@ -63,8 +64,9 @@ sendClientMessageToServer(msg: any): void

/** Subscribe a callback handler for a specific RPC call */
subscribe(
filter: { request: CallRequestDTO | string; args?: any },
handler: (response: CallResponseDTO) => void,
): void
): UnsubscribeCallback
subscribeToServerMessages(handler: (msg: any) => void): void
subscribeToServerMessages(handler: (msg: any) => void): UnsubscribeCallback

@@ -76,2 +78,3 @@ transports(): {

/** Unsubscribe a callback handler for a specific RPC call */
unsubscribe(

@@ -284,3 +287,3 @@ filter: { request: CallRequestDTO | string; args?: any },

) => {
this.callManager.addResponseInterceptor(responseInterceptor)
return this.callManager.addResponseInterceptor(responseInterceptor)
}

@@ -291,3 +294,3 @@

) => {
this.callManager.addRequestInterceptor(requestInterceptor)
return this.callManager.addRequestInterceptor(requestInterceptor)
}

@@ -299,2 +302,6 @@

this.webSocketConnectionChangeListeners.push(cb)
return () => {
this.webSocketConnectionChangeListeners = this.webSocketConnectionChangeListeners.filter(_cb => _cb !== cb)
}
}

@@ -345,3 +352,3 @@

this.vent.subscribe(callRequestKey, handler)
return this.vent.subscribe(callRequestKey, handler)
}

@@ -376,6 +383,6 @@

return
return () => {}
}
this.webSocketTransport.subscribeToServerMessages(handler)
return this.webSocketTransport.subscribeToServerMessages(handler)
}

@@ -382,0 +389,0 @@

@@ -9,2 +9,3 @@ import { Transport } from './Transport'

import { CallRequestTransportError } from './errors/CallRequestTransportError'
import {UnsubscribeCallback} from "../types";

@@ -130,4 +131,8 @@ const debug = GetDebugLogger('rpc:WebSocketTransport')

public subscribeToServerMessages = (handler: (msg: any) => void) => {
public subscribeToServerMessages = (handler: (msg: any) => void): UnsubscribeCallback => {
this.serverMessageHandlers.push(handler)
return () => {
this.serverMessageHandlers = this.serverMessageHandlers.filter(cb => cb !== handler)
}
}

@@ -134,0 +139,0 @@

@@ -13,7 +13,7 @@ let lsDebug: string | null | undefined = null

if (new RegExp(lsDebug).test(prefix)) {
return (...args: any) => console.log(prefix, ...args)
return (...args: any[]) => console.log(prefix, ...args)
}
}
return (() => undefined) as (...args: any) => void
return (() => undefined) as (...args: any[]) => void
}

@@ -0,1 +1,3 @@

import {UnsubscribeCallback} from "../types";
export class Vent {

@@ -14,3 +16,3 @@ private events: Record<string, any> = {}

subscribe = (topic: string, handler: (data: any) => void) => {
subscribe = (topic: string, handler: (data: any) => void): UnsubscribeCallback => {
if (!this.events[topic]) {

@@ -22,2 +24,4 @@ this.events[topic] = []

this.events[topic].push(handler)
return () => this.unsubscribe(topic, handler)
}

@@ -24,0 +28,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc