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
4
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.15.0 to 2.16.0

74

dist/cjs.js

@@ -7,3 +7,3 @@ 'use strict';

var lodashEs = require('lodash-es');
var LRU = require('lru-cache');
var lruCache = require('lru-cache');

@@ -13,3 +13,2 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var stringify__default = /*#__PURE__*/_interopDefaultLegacy(stringify);
var LRU__default = /*#__PURE__*/_interopDefaultLegacy(LRU);

@@ -254,10 +253,4 @@ /******************************************************************************

});
const requestPromise = requestPromiseWrapper()
.then((response) => {
const requestPromise = requestPromiseWrapper().finally(() => {
delete this.inflightCallsByKey[key];
return response;
})
.catch((err) => {
delete this.inflightCallsByKey[key];
throw err;
});

@@ -328,2 +321,3 @@ this.inflightCallsByKey[key] = requestPromise;

let timeout;
const transportPromise = transport.sendRequest(request, opts || {});
const deadlinePromise = new Promise((_, reject) => {

@@ -334,9 +328,8 @@ timeout = setTimeout(() => {

});
response = yield Promise.race([
response = (yield Promise.race([
deadlinePromise,
transport.sendRequest(request, opts),
]).then((response) => {
transportPromise,
]).finally(() => {
clearTimeout(timeout);
return response;
});
}));
}

@@ -355,2 +348,3 @@ catch (e) {

if (!response && !this.transports[transportsIndex]) {
console.error(`RPCClient ClientManager#sendRequestWithTransport() ${request.scope}::${request.procedure}::${request.version} did not get a response from any transports`);
throw new CallRequestError(`Procedure ${request.procedure} did not get a response from any transports`);

@@ -411,3 +405,3 @@ }

if (!response) {
return (_a = this.cachedResponseByParams) === null || _a === void 0 ? void 0 : _a.del(requestKey);
return (_a = this.cachedResponseByParams) === null || _a === void 0 ? void 0 : _a.delete(requestKey);
}

@@ -418,3 +412,3 @@ const cachedResponse = Object.assign({}, response);

};
this.cachedResponseByParams = new LRU__default["default"]({
this.cachedResponseByParams = new lruCache.LRUCache({
max: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cacheMaxSize) || InMemoryCache.DEFAULT_CACHE_MAX_SIZE,

@@ -425,4 +419,4 @@ ttl: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cacheMaxAgeMs) || InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS,

}
InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 5;
InMemoryCache.DEFAULT_CACHE_MAX_SIZE = 100;
InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 15;
InMemoryCache.DEFAULT_CACHE_MAX_SIZE = 200;

@@ -492,3 +486,3 @@ class CallResponseDTO {

class PromiseWrapper {
constructor(timeout) {
constructor(description, timeout) {
this.reject = (rejectReturnValue) => {

@@ -506,3 +500,3 @@ if (this.rejectPromise) {

const timer = setTimeout(() => {
reject(new Error('PromiseWraper timeout'));
reject(new Error(`PromiseWraper timeout: ${description}`));
}, timeout || DEFAULT_TIMEOUT);

@@ -523,2 +517,14 @@ this.rejectPromise = (arg) => {

const getRequestShorthand = (request) => {
return `${request.scope}::${request.procedure}::${request.version}`;
};
const parseRequestShorthand = (requestString) => {
const parsed = requestString.split('::');
return {
procedure: parsed[1],
scope: parsed[0] || DEFAULT_REQUEST_SCOPE,
version: parsed[2] || DEFAULT_REQUEST_VERSION,
};
};
const debug = GetDebugLogger('rpc:WebSocketTransport');

@@ -554,3 +560,3 @@ class WebSocketTransport {

};
this.sendRequest = (call) => __awaiter(this, void 0, void 0, function* () {
this.sendRequest = (call, opts) => __awaiter(this, void 0, void 0, function* () {
debug('sendRequest', call);

@@ -561,3 +567,3 @@ while (this.isWaitingForIdentityConfirmation) {

}
return this.sendCall(call);
return this.sendCall(call, opts);
});

@@ -583,3 +589,3 @@ this.setIdentity = (identity) => __awaiter(this, void 0, void 0, function* () {

this.isWaitingForIdentityConfirmation = true;
this.sendCall({ identity })
this.sendCall({ identity }, {})
.then(() => {

@@ -598,3 +604,3 @@ debug('setIdentity with remote complete');

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

@@ -703,3 +709,3 @@ };

});
this.sendCall = (call) => __awaiter(this, void 0, void 0, function* () {
this.sendCall = (call, opts) => __awaiter(this, void 0, void 0, function* () {
var _a;

@@ -709,3 +715,3 @@ debug('sendCall', call);

call.correlationId = call.correlationId || correlationId;
let promiseWrapper = new PromiseWrapper(WebSocketTransport.DEFAULT_TIMEOUT_MS);
let promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs);
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(call));

@@ -732,13 +738,3 @@ this.pendingPromisesForResponse[call.correlationId] = promiseWrapper;

}
WebSocketTransport.DEFAULT_TIMEOUT_MS = 10000;
const parseRequestShorthand = (requestString) => {
const parsed = requestString.split('::');
return {
procedure: parsed[1],
scope: parsed[0] || DEFAULT_REQUEST_SCOPE,
version: parsed[2] || DEFAULT_REQUEST_VERSION,
};
};
class Vent {

@@ -920,2 +916,3 @@ constructor() {

onConnectionStatusChange: this.onWebSocketConnectionStatusChange,
rpcOptions: options,
});

@@ -928,3 +925,6 @@ transports.push(this.webSocketTransport);

else if ((_f = options === null || options === void 0 ? void 0 : options.hosts) === null || _f === void 0 ? void 0 : _f.http) {
this.httpTransport = new HTTPTransport({ host: options.hosts.http });
this.httpTransport = new HTTPTransport({
host: options.hosts.http,
rpcOptions: options,
});
transports.push(this.httpTransport);

@@ -931,0 +931,0 @@ }

import stringify from 'fast-json-stable-stringify';
import { cloneDeep, merge } from 'lodash-es';
import LRU from 'lru-cache';
import { LRUCache } from 'lru-cache';

@@ -243,10 +243,4 @@ /******************************************************************************

});
const requestPromise = requestPromiseWrapper()
.then((response) => {
const requestPromise = requestPromiseWrapper().finally(() => {
delete this.inflightCallsByKey[key];
return response;
})
.catch((err) => {
delete this.inflightCallsByKey[key];
throw err;
});

@@ -317,2 +311,3 @@ this.inflightCallsByKey[key] = requestPromise;

let timeout;
const transportPromise = transport.sendRequest(request, opts || {});
const deadlinePromise = new Promise((_, reject) => {

@@ -323,9 +318,8 @@ timeout = setTimeout(() => {

});
response = yield Promise.race([
response = (yield Promise.race([
deadlinePromise,
transport.sendRequest(request, opts),
]).then((response) => {
transportPromise,
]).finally(() => {
clearTimeout(timeout);
return response;
});
}));
}

@@ -344,2 +338,3 @@ catch (e) {

if (!response && !this.transports[transportsIndex]) {
console.error(`RPCClient ClientManager#sendRequestWithTransport() ${request.scope}::${request.procedure}::${request.version} did not get a response from any transports`);
throw new CallRequestError(`Procedure ${request.procedure} did not get a response from any transports`);

@@ -400,3 +395,3 @@ }

if (!response) {
return (_a = this.cachedResponseByParams) === null || _a === void 0 ? void 0 : _a.del(requestKey);
return (_a = this.cachedResponseByParams) === null || _a === void 0 ? void 0 : _a.delete(requestKey);
}

@@ -407,3 +402,3 @@ const cachedResponse = Object.assign({}, response);

};
this.cachedResponseByParams = new LRU({
this.cachedResponseByParams = new LRUCache({
max: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cacheMaxSize) || InMemoryCache.DEFAULT_CACHE_MAX_SIZE,

@@ -414,4 +409,4 @@ ttl: (cacheOptions === null || cacheOptions === void 0 ? void 0 : cacheOptions.cacheMaxAgeMs) || InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS,

}
InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 5;
InMemoryCache.DEFAULT_CACHE_MAX_SIZE = 100;
InMemoryCache.DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 15;
InMemoryCache.DEFAULT_CACHE_MAX_SIZE = 200;

@@ -481,3 +476,3 @@ class CallResponseDTO {

class PromiseWrapper {
constructor(timeout) {
constructor(description, timeout) {
this.reject = (rejectReturnValue) => {

@@ -495,3 +490,3 @@ if (this.rejectPromise) {

const timer = setTimeout(() => {
reject(new Error('PromiseWraper timeout'));
reject(new Error(`PromiseWraper timeout: ${description}`));
}, timeout || DEFAULT_TIMEOUT);

@@ -512,2 +507,14 @@ this.rejectPromise = (arg) => {

const getRequestShorthand = (request) => {
return `${request.scope}::${request.procedure}::${request.version}`;
};
const parseRequestShorthand = (requestString) => {
const parsed = requestString.split('::');
return {
procedure: parsed[1],
scope: parsed[0] || DEFAULT_REQUEST_SCOPE,
version: parsed[2] || DEFAULT_REQUEST_VERSION,
};
};
const debug = GetDebugLogger('rpc:WebSocketTransport');

@@ -543,3 +550,3 @@ class WebSocketTransport {

};
this.sendRequest = (call) => __awaiter(this, void 0, void 0, function* () {
this.sendRequest = (call, opts) => __awaiter(this, void 0, void 0, function* () {
debug('sendRequest', call);

@@ -550,3 +557,3 @@ while (this.isWaitingForIdentityConfirmation) {

}
return this.sendCall(call);
return this.sendCall(call, opts);
});

@@ -572,3 +579,3 @@ this.setIdentity = (identity) => __awaiter(this, void 0, void 0, function* () {

this.isWaitingForIdentityConfirmation = true;
this.sendCall({ identity })
this.sendCall({ identity }, {})
.then(() => {

@@ -587,3 +594,3 @@ debug('setIdentity with remote complete');

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

@@ -692,3 +699,3 @@ };

});
this.sendCall = (call) => __awaiter(this, void 0, void 0, function* () {
this.sendCall = (call, opts) => __awaiter(this, void 0, void 0, function* () {
var _a;

@@ -698,3 +705,3 @@ debug('sendCall', call);

call.correlationId = call.correlationId || correlationId;
let promiseWrapper = new PromiseWrapper(WebSocketTransport.DEFAULT_TIMEOUT_MS);
let promiseWrapper = new PromiseWrapper(getRequestShorthand(call), opts.timeout || this.options.rpcOptions.deadlineMs);
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(call));

@@ -721,13 +728,3 @@ this.pendingPromisesForResponse[call.correlationId] = promiseWrapper;

}
WebSocketTransport.DEFAULT_TIMEOUT_MS = 10000;
const parseRequestShorthand = (requestString) => {
const parsed = requestString.split('::');
return {
procedure: parsed[1],
scope: parsed[0] || DEFAULT_REQUEST_SCOPE,
version: parsed[2] || DEFAULT_REQUEST_VERSION,
};
};
class Vent {

@@ -909,2 +906,3 @@ constructor() {

onConnectionStatusChange: this.onWebSocketConnectionStatusChange,
rpcOptions: options,
});

@@ -917,3 +915,6 @@ transports.push(this.webSocketTransport);

else if ((_f = options === null || options === void 0 ? void 0 : options.hosts) === null || _f === void 0 ? void 0 : _f.http) {
this.httpTransport = new HTTPTransport({ host: options.hosts.http });
this.httpTransport = new HTTPTransport({
host: options.hosts.http,
rpcOptions: options,
});
transports.push(this.httpTransport);

@@ -920,0 +921,0 @@ }

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

import { RPCClientIdentity } from '../RPCClientIdentity';
import { RPCRequestOptions } from '../RPCClient';
import { RPCClientOptions, RPCRequestOptions } from '../RPCClient';
interface HTTPTransportOptions {
host: string;
rpcOptions: RPCClientOptions;
}

@@ -18,3 +19,3 @@ export declare class HTTPTransport implements Transport {

isConnected: () => boolean;
sendRequest: (call: CallRequestDTO, opts?: RPCRequestOptions) => Promise<CallResponseDTO>;
sendRequest: (call: CallRequestDTO, opts: RPCRequestOptions) => Promise<CallResponseDTO>;
setIdentity: (identity?: RPCClientIdentity) => void;

@@ -21,0 +22,0 @@ }

@@ -8,5 +8,5 @@ import { CallRequestDTO } from '../CallRequestDTO';

name: string;
sendRequest(call: CallRequestDTO, opts?: RPCRequestOptions): Promise<CallResponseDTO>;
sendRequest(call: CallRequestDTO, opts: RPCRequestOptions): Promise<CallResponseDTO>;
setIdentity(identity?: RPCClientIdentity): void;
}
//# sourceMappingURL=Transport.d.ts.map

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

import { RPCClientIdentity } from '../RPCClientIdentity';
import { UnsubscribeCallback } from "../types";
import { UnsubscribeCallback } from '../types';
import { RPCClientOptions, RPCRequestOptions } from '../RPCClient';
interface WebSocketTransportOptions {

@@ -11,6 +12,6 @@ host: string;

onConnectionStatusChange?: (connected: boolean) => void;
rpcOptions: RPCClientOptions;
}
export declare class WebSocketTransport implements Transport {
readonly options: WebSocketTransportOptions;
static DEFAULT_TIMEOUT_MS: number;
private connectedToRemote;

@@ -30,3 +31,3 @@ private readonly host;

sendClientMessageToServer: (msg: any) => void;
sendRequest: (call: CallRequestDTO) => Promise<CallResponseDTO>;
sendRequest: (call: CallRequestDTO, opts: RPCRequestOptions) => Promise<CallResponseDTO>;
setIdentity: (identity?: RPCClientIdentity) => Promise<void>;

@@ -33,0 +34,0 @@ subscribeToServerMessages: (handler: (msg: any) => void) => UnsubscribeCallback;

@@ -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,n){return new(i||(i=Promise))((function(s,r){function o(t){try{c(n.next(t))}catch(t){r(t)}}function a(t){try{c(n.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}c((n=n.apply(t,e||[])).next())}))}function i(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=i(t),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(i){e[i]=t[i]&&function(e){return new Promise((function(n,s){(function(t,e,i,n){Promise.resolve(n).then((function(e){t({value:e,done:i})}),e)})(n,s,(e=t[i](e)).done,e.value)}))}}}class s{constructor(t){const{args:e,correlationId:i,identity:n,procedure:s,scope:r,version:o}=t;if(this.args=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i||Math.random().toString(),n){if("object"!=typeof n)throw new Error("identity must be an object");if(n.authorization&&"string"!=typeof n.authorization)throw new Error("identity.authorization must be a string");if(n.deviceName&&"string"!=typeof n.deviceName)throw new Error("identity.deviceName must be a string");if(n.metadata&&"object"!=typeof n.metadata)throw new Error("identity.metadata must be a object");this.identity=n}if(s&&"string"!=typeof s)throw new Error("procedure must be string");if(this.procedure=s,r&&"string"!=typeof r)throw new Error("scope must be string");if(this.scope=r,o&&"string"!=typeof o)throw new Error("version must be string");this.version=o}}class 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,n="boolean"==typeof e.cycles&&e.cycles,s=e.cmp&&(i=e.cmp,function(t){return function(e,n){var s={key:e,value:t[e]},r={key:n,value:t[n]};return i(s,r)}}),r=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0!==e){if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);var i,o;if(Array.isArray(e)){for(o="[",i=0;i<e.length;i++)i&&(o+=","),o+=t(e[i])||"null";return o+"]"}if(null===e)return"null";if(-1!==r.indexOf(e)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=r.push(e)-1,c=Object.keys(e).sort(s&&s(e));for(o="",i=0;i<c.length;i++){var h=c[i],l=t(e[h]);l&&(o&&(o+=","),o+=JSON.stringify(h)+":"+l)}return r.splice(a,1),"{"+o+"}"}}(t)}(function(t,e={}){if(!c(t)&&!Array.isArray(t))throw new TypeError("Expected a plain object or array");const{deep:i,compare:n}=e,s=[],r=[],o=t=>{const e=s.indexOf(t);if(-1!==e)return r[e];const i=[];return s.push(t),r.push(i),i.push(...t.map((t=>Array.isArray(t)?o(t):c(t)?a(t):t))),i},a=t=>{const e=s.indexOf(t);if(-1!==e)return r[e];const h={},l=Object.keys(t).sort(n);s.push(t),r.push(h);for(const e of l){const n=t[e];let s;s=i&&Array.isArray(n)?o(n):i&&c(n)?a(n):n,Object.defineProperty(h,e,Object.assign(Object.assign({},Object.getOwnPropertyDescriptor(t,e)),{value:s}))}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="[object Null]",m="[object Undefined]",S=p?p.toStringTag:void 0;function _(t){return null==t?void 0===t?m:w:S&&S in Object(t)?function(t){var e=y.call(t,g),i=t[g];try{t[g]=void 0;var n=!0}catch(t){}var s=v.call(t);return n&&(e?t[g]=i:delete t[g]),s}(t):function(t){return b.call(t)}(t)}function j(t){return null!=t&&"object"==typeof t}var C=Array.isArray;function O(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function T(t){return t}var A="[object AsyncFunction]",k="[object Function]",E="[object GeneratorFunction]",I="[object Proxy]";function M(t){if(!O(t))return!1;var e=_(t);return e==k||e==E||e==A||e==I}var x,z=d["__core-js_shared__"],R=(x=/[^.]+$/.exec(z&&z.keys&&z.keys.IE_PROTO||""))?"Symbol(src)_1."+x:"";var F=Function.prototype.toString;function L(t){if(null!=t){try{return F.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var P=/^\[object .+?Constructor\]$/,W=Function.prototype,D=Object.prototype,q=W.toString,U=D.hasOwnProperty,B=RegExp("^"+q.call(U).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function N(t){return!(!O(t)||(e=t,R&&R in e))&&(M(t)?B:P).test(L(t));var e}function $(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return N(i)?i:void 0}var H=$(d,"WeakMap"),G=Object.create,J=function(){function t(){}return function(e){if(!O(e))return{};if(G)return G(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function V(t,e){var i=-1,n=t.length;for(e||(e=Array(n));++i<n;)e[i]=t[i];return e}var K=800,X=16,Z=Date.now;var Q,Y,tt,et=function(){try{var t=$(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),it=et,nt=it?function(t,e){return it(t,"toString",{configurable:!0,enumerable:!1,value:(i=e,function(){return i}),writable:!0});var i}:T,st=(Q=nt,Y=0,tt=0,function(){var t=Z(),e=X-(t-tt);if(tt=t,e>0){if(++Y>=K)return arguments[0]}else Y=0;return Q.apply(void 0,arguments)}),rt=st;var ot=9007199254740991,at=/^(?:0|[1-9]\d*)$/;function ct(t,e){var i=typeof t;return!!(e=null==e?ot:e)&&("number"==i||"symbol"!=i&&at.test(t))&&t>-1&&t%1==0&&t<e}function ht(t,e,i){"__proto__"==e&&it?it(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}function lt(t,e){return t===e||t!=t&&e!=e}var ut=Object.prototype.hasOwnProperty;function dt(t,e,i){var n=t[e];ut.call(t,e)&&lt(n,i)&&(void 0!==i||e in t)||ht(t,e,i)}function pt(t,e,i,n){var s=!i;i||(i={});for(var r=-1,o=e.length;++r<o;){var a=e[r],c=n?n(i[a],t[a],a,i,t):void 0;void 0===c&&(c=t[a]),s?ht(i,a,c):dt(i,a,c)}return i}var ft=Math.max;function yt(t,e){return rt(function(t,e,i){return e=ft(void 0===e?t.length-1:e,0),function(){for(var n=arguments,s=-1,r=ft(n.length-e,0),o=Array(r);++s<r;)o[s]=n[e+s];s=-1;for(var a=Array(e+1);++s<e;)a[s]=n[s];return a[e]=i(o),function(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)}(t,this,a)}}(t,e,T),t+"")}var vt=9007199254740991;function gt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=vt}function bt(t){return null!=t&&gt(t.length)&&!M(t)}var wt=Object.prototype;function mt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||wt)}var St="[object Arguments]";function _t(t){return j(t)&&_(t)==St}var jt=Object.prototype,Ct=jt.hasOwnProperty,Ot=jt.propertyIsEnumerable,Tt=_t(function(){return arguments}())?_t:function(t){return j(t)&&Ct.call(t,"callee")&&!Ot.call(t,"callee")},At=Tt;var kt="object"==typeof t&&t&&!t.nodeType&&t,Et=kt&&"object"==typeof module&&module&&!module.nodeType&&module,It=Et&&Et.exports===kt?d.Buffer:void 0,Mt=(It?It.isBuffer:void 0)||function(){return!1},xt={};function zt(t){return function(e){return t(e)}}xt["[object Float32Array]"]=xt["[object Float64Array]"]=xt["[object Int8Array]"]=xt["[object Int16Array]"]=xt["[object Int32Array]"]=xt["[object Uint8Array]"]=xt["[object Uint8ClampedArray]"]=xt["[object Uint16Array]"]=xt["[object Uint32Array]"]=!0,xt["[object Arguments]"]=xt["[object Array]"]=xt["[object ArrayBuffer]"]=xt["[object Boolean]"]=xt["[object DataView]"]=xt["[object Date]"]=xt["[object Error]"]=xt["[object Function]"]=xt["[object Map]"]=xt["[object Number]"]=xt["[object Object]"]=xt["[object RegExp]"]=xt["[object Set]"]=xt["[object String]"]=xt["[object WeakMap]"]=!1;var Rt="object"==typeof t&&t&&!t.nodeType&&t,Ft=Rt&&"object"==typeof module&&module&&!module.nodeType&&module,Lt=Ft&&Ft.exports===Rt&&l.process,Pt=function(){try{var t=Ft&&Ft.require&&Ft.require("util").types;return t||Lt&&Lt.binding&&Lt.binding("util")}catch(t){}}(),Wt=Pt&&Pt.isTypedArray,Dt=Wt?zt(Wt):function(t){return j(t)&&gt(t.length)&&!!xt[_(t)]},qt=Object.prototype.hasOwnProperty;function Ut(t,e){var i=C(t),n=!i&&At(t),s=!i&&!n&&Mt(t),r=!i&&!n&&!s&&Dt(t),o=i||n||s||r,a=o?function(t,e){for(var i=-1,n=Array(t);++i<t;)n[i]=e(i);return n}(t.length,String):[],c=a.length;for(var h in t)!e&&!qt.call(t,h)||o&&("length"==h||s&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||ct(h,c))||a.push(h);return a}function Bt(t,e){return function(i){return t(e(i))}}var Nt=Bt(Object.keys,Object),$t=Object.prototype.hasOwnProperty;function Ht(t){return bt(t)?Ut(t):function(t){if(!mt(t))return Nt(t);var e=[];for(var i in Object(t))$t.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var Gt=Object.prototype.hasOwnProperty;function Jt(t){if(!O(t))return function(t){var e=[];if(null!=t)for(var i in Object(t))e.push(i);return e}(t);var e=mt(t),i=[];for(var n in t)("constructor"!=n||!e&&Gt.call(t,n))&&i.push(n);return i}function Vt(t){return bt(t)?Ut(t,!0):Jt(t)}var Kt=$(Object,"create");var Xt="__lodash_hash_undefined__",Zt=Object.prototype.hasOwnProperty;var Qt=Object.prototype.hasOwnProperty;var Yt="__lodash_hash_undefined__";function te(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}function ee(t,e){for(var i=t.length;i--;)if(lt(t[i][0],e))return i;return-1}te.prototype.clear=function(){this.__data__=Kt?Kt(null):{},this.size=0},te.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},te.prototype.get=function(t){var e=this.__data__;if(Kt){var i=e[t];return i===Xt?void 0:i}return Zt.call(e,t)?e[t]:void 0},te.prototype.has=function(t){var e=this.__data__;return Kt?void 0!==e[t]:Qt.call(e,t)},te.prototype.set=function(t,e){var i=this.__data__;return this.size+=this.has(t)?0:1,i[t]=Kt&&void 0===e?Yt:e,this};var ie=Array.prototype.splice;function ne(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}ne.prototype.clear=function(){this.__data__=[],this.size=0},ne.prototype.delete=function(t){var e=this.__data__,i=ee(e,t);return!(i<0)&&(i==e.length-1?e.pop():ie.call(e,i,1),--this.size,!0)},ne.prototype.get=function(t){var e=this.__data__,i=ee(e,t);return i<0?void 0:e[i][1]},ne.prototype.has=function(t){return ee(this.__data__,t)>-1},ne.prototype.set=function(t,e){var i=this.__data__,n=ee(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this};var se=$(d,"Map");function re(t,e){var i,n,s=t.__data__;return("string"==(n=typeof(i=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==i:null===i)?s["string"==typeof e?"string":"hash"]:s.map}function oe(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var n=t[e];this.set(n[0],n[1])}}function ae(t,e){for(var i=-1,n=e.length,s=t.length;++i<n;)t[s+i]=e[i];return t}oe.prototype.clear=function(){this.size=0,this.__data__={hash:new te,map:new(se||ne),string:new te}},oe.prototype.delete=function(t){var e=re(this,t).delete(t);return this.size-=e?1:0,e},oe.prototype.get=function(t){return re(this,t).get(t)},oe.prototype.has=function(t){return re(this,t).has(t)},oe.prototype.set=function(t,e){var i=re(this,t),n=i.size;return i.set(t,e),this.size+=i.size==n?0:1,this};var ce=Bt(Object.getPrototypeOf,Object),he="[object Object]",le=Function.prototype,ue=Object.prototype,de=le.toString,pe=ue.hasOwnProperty,fe=de.call(Object);var ye=200;function ve(t){var e=this.__data__=new ne(t);this.size=e.size}ve.prototype.clear=function(){this.__data__=new ne,this.size=0},ve.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},ve.prototype.get=function(t){return this.__data__.get(t)},ve.prototype.has=function(t){return this.__data__.has(t)},ve.prototype.set=function(t,e){var i=this.__data__;if(i instanceof ne){var n=i.__data__;if(!se||n.length<ye-1)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new oe(n)}return i.set(t,e),this.size=i.size,this};var ge="object"==typeof t&&t&&!t.nodeType&&t,be=ge&&"object"==typeof module&&module&&!module.nodeType&&module,we=be&&be.exports===ge?d.Buffer:void 0,me=we?we.allocUnsafe:void 0;function Se(t,e){if(e)return t.slice();var i=t.length,n=me?me(i):new t.constructor(i);return t.copy(n),n}function _e(){return[]}var je=Object.prototype.propertyIsEnumerable,Ce=Object.getOwnPropertySymbols,Oe=Ce?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var i=-1,n=null==t?0:t.length,s=0,r=[];++i<n;){var o=t[i];e(o,i,t)&&(r[s++]=o)}return r}(Ce(t),(function(e){return je.call(t,e)})))}:_e;var Te=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ae(e,Oe(t)),t=ce(t);return e}:_e;function Ae(t,e,i){var n=e(t);return C(t)?n:ae(n,i(t))}function ke(t){return Ae(t,Ht,Oe)}function Ee(t){return Ae(t,Vt,Te)}var Ie=$(d,"DataView"),Me=$(d,"Promise"),xe=$(d,"Set"),ze="[object Map]",Re="[object Promise]",Fe="[object Set]",Le="[object WeakMap]",Pe="[object DataView]",We=L(Ie),De=L(se),qe=L(Me),Ue=L(xe),Be=L(H),Ne=_;(Ie&&Ne(new Ie(new ArrayBuffer(1)))!=Pe||se&&Ne(new se)!=ze||Me&&Ne(Me.resolve())!=Re||xe&&Ne(new xe)!=Fe||H&&Ne(new H)!=Le)&&(Ne=function(t){var e=_(t),i="[object Object]"==e?t.constructor:void 0,n=i?L(i):"";if(n)switch(n){case We:return Pe;case De:return ze;case qe:return Re;case Ue:return Fe;case Be:return Le}return e});var $e=Ne,He=Object.prototype.hasOwnProperty;var Ge=d.Uint8Array;function Je(t){var e=new t.constructor(t.byteLength);return new Ge(e).set(new Ge(t)),e}var Ve=/\w*$/;var Ke=p?p.prototype:void 0,Xe=Ke?Ke.valueOf:void 0;function Ze(t,e){var i=e?Je(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}var Qe="[object Boolean]",Ye="[object Date]",ti="[object Map]",ei="[object Number]",ii="[object RegExp]",ni="[object Set]",si="[object String]",ri="[object Symbol]",oi="[object ArrayBuffer]",ai="[object DataView]",ci="[object Float32Array]",hi="[object Float64Array]",li="[object Int8Array]",ui="[object Int16Array]",di="[object Int32Array]",pi="[object Uint8Array]",fi="[object Uint8ClampedArray]",yi="[object Uint16Array]",vi="[object Uint32Array]";function gi(t,e,i){var n,s,r,o=t.constructor;switch(e){case oi:return Je(t);case Qe:case Ye:return new o(+t);case ai:return function(t,e){var i=e?Je(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);case ci:case hi:case li:case ui:case di:case pi:case fi:case yi:case vi:return Ze(t,i);case ti:return new o;case ei:case si:return new o(t);case ii:return(r=new(s=t).constructor(s.source,Ve.exec(s))).lastIndex=s.lastIndex,r;case ni:return new o;case ri:return n=t,Xe?Object(Xe.call(n)):{}}}function bi(t){return"function"!=typeof t.constructor||mt(t)?{}:J(ce(t))}var wi="[object Map]";var mi=Pt&&Pt.isMap,Si=mi?zt(mi):function(t){return j(t)&&$e(t)==wi},_i="[object Set]";var ji=Pt&&Pt.isSet,Ci=ji?zt(ji):function(t){return j(t)&&$e(t)==_i},Oi=1,Ti=2,Ai=4,ki="[object Arguments]",Ei="[object Function]",Ii="[object GeneratorFunction]",Mi="[object Object]",xi={};function zi(t,e,i,n,s,r){var o,a=e&Oi,c=e&Ti,h=e&Ai;if(i&&(o=s?i(t,n,s,r):i(t)),void 0!==o)return o;if(!O(t))return t;var l=C(t);if(l){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&He.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return V(t,o)}else{var u=$e(t),d=u==Ei||u==Ii;if(Mt(t))return Se(t,a);if(u==Mi||u==ki||d&&!s){if(o=c||d?{}:bi(t),!a)return c?function(t,e){return pt(t,Te(t),e)}(t,function(t,e){return t&&pt(e,Vt(e),t)}(o,t)):function(t,e){return pt(t,Oe(t),e)}(t,function(t,e){return t&&pt(e,Ht(e),t)}(o,t))}else{if(!xi[u])return s?t:{};o=gi(t,u,a)}}r||(r=new ve);var p=r.get(t);if(p)return p;r.set(t,o),Ci(t)?t.forEach((function(n){o.add(zi(n,e,i,n,t,r))})):Si(t)&&t.forEach((function(n,s){o.set(s,zi(n,e,i,s,t,r))}));var f=l?void 0:(h?c?Ee:ke:c?Vt:Ht)(t);return function(t,e){for(var i=-1,n=null==t?0:t.length;++i<n&&!1!==e(t[i],i,t););}(f||t,(function(n,s){f&&(n=t[s=n]),dt(o,s,zi(n,e,i,s,t,r))})),o}xi[ki]=xi["[object Array]"]=xi["[object ArrayBuffer]"]=xi["[object DataView]"]=xi["[object Boolean]"]=xi["[object Date]"]=xi["[object Float32Array]"]=xi["[object Float64Array]"]=xi["[object Int8Array]"]=xi["[object Int16Array]"]=xi["[object Int32Array]"]=xi["[object Map]"]=xi["[object Number]"]=xi[Mi]=xi["[object RegExp]"]=xi["[object Set]"]=xi["[object String]"]=xi["[object Symbol]"]=xi["[object Uint8Array]"]=xi["[object Uint8ClampedArray]"]=xi["[object Uint16Array]"]=xi["[object Uint32Array]"]=!0,xi["[object Error]"]=xi[Ei]=xi["[object WeakMap]"]=!1;var Ri=1,Fi=4;function Li(t){return zi(t,Ri|Fi)}var Pi,Wi=function(t,e,i){for(var n=-1,s=Object(t),r=i(t),o=r.length;o--;){var a=r[Pi?o:++n];if(!1===e(s[a],a,s))break}return t};function Di(t,e,i){(void 0!==i&&!lt(t[e],i)||void 0===i&&!(e in t))&&ht(t,e,i)}function qi(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Ui(t,e,i,n,s,r,o){var a=qi(t,i),c=qi(e,i),h=o.get(c);if(h)Di(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=C(c),f=!p&&Mt(c),y=!p&&!f&&Dt(c);u=c,p||f||y?C(a)?u=a:j(l=a)&&bt(l)?u=V(a):f?(d=!1,u=Se(c,!0)):y?(d=!1,u=Ze(c,!0)):u=[]:function(t){if(!j(t)||_(t)!=he)return!1;var e=ce(t);if(null===e)return!0;var i=pe.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&de.call(i)==fe}(c)||At(c)?(u=a,At(a)?u=function(t){return pt(t,Vt(t))}(a):O(a)&&!M(a)||(u=bi(c))):d=!1}d&&(o.set(c,u),s(u,c,n,r,o),o.delete(c)),Di(t,i,u)}}function Bi(t,e,i,n,s){t!==e&&Wi(e,(function(r,o){if(s||(s=new ve),O(r))Ui(t,e,o,i,Bi,n,s);else{var a=n?n(qi(t,o),r,o+"",t,e,s):void 0;void 0===a&&(a=r),Di(t,o,a)}}),Vt)}var Ni,$i=(Ni=function(t,e,i){Bi(t,e,i)},yt((function(t,e){var i=-1,n=e.length,s=n>1?e[n-1]:void 0,r=n>2?e[2]:void 0;for(s=Ni.length>3&&"function"==typeof s?(n--,s):void 0,r&&function(t,e,i){if(!O(i))return!1;var n=typeof e;return!!("number"==n?bt(i)&&ct(e,i.length):"string"==n&&e in i)&&lt(i[e],t)}(e[0],e[1],r)&&(s=n<3?void 0:s,n=1),t=Object(t);++i<n;){var o=e[i];o&&Ni(t,o,i,s)}return t})));let Hi=null;try{Hi=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const Gi=t=>Hi&&new RegExp(Hi).test(t)?(...e)=>console.log(t,...e):()=>{},Ji=Gi("rpc:ClientManager");class Vi{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=>{Ji("clearCache"),this.cache&&(t?this.cache.setCachedResponse(t,void 0):this.cache.clearCache())},this.getCachedResponse=t=>{var e;return Ji("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(Ji("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=(t,i)=>e(this,void 0,void 0,(function*(){Ji("manageClientRequest",t);const n=yield this.interceptRequestMutator(t),s=h(n);if(this.inflightCallsByKey.hasOwnProperty(s))return Ji("manageClientRequest using an existing in-flight call",s),this.inflightCallsByKey[s].then((e=>{const i=Li(e);return t.correlationId&&(i.correlationId=t.correlationId),i}));const r=(()=>e(this,void 0,void 0,(function*(){const t=yield this.sendRequestWithTransport(n,i),e=yield this.interceptResponseMutator(t,n);return this.cache&&e&&this.cache.setCachedResponse(n,e),e})))().then((t=>(delete this.inflightCallsByKey[s],t))).catch((t=>{throw delete this.inflightCallsByKey[s],t}));return this.inflightCallsByKey[s]=r,yield r})),this.setIdentity=t=>{Ji("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){var e,i,s,r;let o=t;if(this.interceptors.request.length){Ji("interceptRequestMutator(), original request:",t);try{for(var a,c=!0,h=n(this.interceptors.request);!(e=(a=yield h.next()).done);){r=a.value,c=!1;try{const t=r;o=yield t(o)}finally{c=!0}}}catch(t){i={error:t}}finally{try{c||e||!(s=h.return)||(yield s.call(h))}finally{if(i)throw i.error}}}return o})),this.interceptResponseMutator=(t,i)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){Ji("interceptResponseMutator",i,t);for(const n of this.interceptors.response)try{e=yield n(e,i)}catch(n){throw Ji("caught response interceptor, request:",i,"original response:",t,"mutated response:",e),n}}return e})),this.sendRequestWithTransport=(t,i)=>e(this,void 0,void 0,(function*(){let e;Ji("sendRequestWithTransport",t);let n=0;for(;!e&&this.transports[n];){const s=this.transports[n];if(s.isConnected()){Ji(`sendRequestWithTransport trying ${this.transports[n].name}`,t);try{let n;const r=new Promise(((e,s)=>{n=setTimeout((()=>{s(new a(`Procedure ${t.procedure}`))}),(null==i?void 0:i.timeout)||this.options.deadlineMs)}));e=yield Promise.race([r,s.sendRequest(t,i)]).then((t=>(clearTimeout(n),t)))}catch(t){if(!(t instanceof a||t instanceof o))throw t;console.warn(`RPCClient ClientManager#sendRequestWithTransport() sending request with ${this.transports[n].name} failed, trying next transport`),n++}}else n++}if(!e&&!this.transports[n])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 Ki{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}Ki.DEFAULT_CACHE_MAX_AGE_MS=3e5,Ki.DEFAULT_CACHE_MAX_SIZE=100;const Xi="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,Zi="function"==typeof AbortController?AbortController:class{constructor(){this.signal=new tn}abort(t=new Error("This operation was aborted")){this.signal.reason=t,this.signal.dispatchEvent({type:"abort",target:this.signal})}},Qi="function"==typeof AbortSignal,Yi="function"==typeof Zi.AbortSignal,tn=Qi?AbortSignal:Yi?Zi.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(t){"abort"===t.type&&(this.aborted=!0,this.onabort(t),this._listeners.forEach((e=>e(t)),this))}onabort(){}addEventListener(t,e){"abort"===t&&this._listeners.push(e)}removeEventListener(t,e){"abort"===t&&(this._listeners=this._listeners.filter((t=>t!==e)))}},en=new Set,nn=(t,e)=>{const i=`LRU_CACHE_OPTION_${t}`;on(i)&&an(i,`${t} option`,`options.${e}`,dn)},sn=(t,e)=>{const i=`LRU_CACHE_METHOD_${t}`;if(on(i)){const{prototype:n}=dn,{get:s}=Object.getOwnPropertyDescriptor(n,t);an(i,`${t} method`,`cache.${e}()`,s)}},rn=(...t)=>{"object"==typeof process&&process&&"function"==typeof process.emitWarning?process.emitWarning(...t):console.error(...t)},on=t=>!en.has(t),an=(t,e,i,n)=>{en.add(t);rn(`The ${e} is deprecated. Please use ${i} instead.`,"DeprecationWarning",t,n)},cn=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),hn=t=>cn(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?ln:null:null;class ln extends Array{constructor(t){super(t),this.fill(0)}}class un{constructor(t){if(0===t)return[];const e=hn(t);this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class dn{constructor(t={}){const{max:e=0,ttl:i,ttlResolution:n=1,ttlAutopurge:s,updateAgeOnGet:r,updateAgeOnHas:o,allowStale:a,dispose:c,disposeAfter:h,noDisposeOnSet:l,noUpdateTTL:u,maxSize:d=0,maxEntrySize:p=0,sizeCalculation:f,fetchMethod:y,fetchContext:v,noDeleteOnFetchRejection:g,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:w,allowStaleOnFetchAbort:m,ignoreFetchAbort:S}=t,{length:_,maxAge:j,stale:C}=t instanceof dn?{}:t;if(0!==e&&!cn(e))throw new TypeError("max option must be a nonnegative integer");const O=e?hn(e):Array;if(!O)throw new Error("invalid max value: "+e);if(this.max=e,this.maxSize=d,this.maxEntrySize=p||this.maxSize,this.sizeCalculation=f||_,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 O(e),this.prev=new O(e),this.head=0,this.tail=0,this.free=new un(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,this.allowStaleOnFetchRejection=!!w,this.allowStaleOnFetchAbort=!!m,this.ignoreFetchAbort=!!S,0!==this.maxEntrySize){if(0!==this.maxSize&&!cn(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!cn(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!a||!!C,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=cn(n)||0===n?n:1,this.ttlAutopurge=!!s,this.ttl=i||j||0,this.ttl){if(!cn(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(on(t)){en.add(t);rn("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,dn)}}C&&nn("stale","allowStale"),j&&nn("maxAge","ttl"),_&&nn("length","sizeCalculation")}getRemainingTTL(t){return this.has(t,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new ln(this.max),this.starts=new ln(this.max),this.setItemTTL=(t,e,i=Xi.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]?Xi.now():0};let t=0;const e=()=>{const e=Xi.now();if(this.ttlResolution>0){t=e;const i=setTimeout((()=>t=0),this.ttlResolution);i.unref&&i.unref()}return e};this.getRemainingTTL=i=>{const n=this.keyMap.get(i);return void 0===n?0:0===this.ttls[n]||0===this.starts[n]?1/0:this.starts[n]+this.ttls[n]-(t||e())},this.isStale=i=>0!==this.ttls[i]&&0!==this.starts[i]&&(t||e())-this.starts[i]>this.ttls[i]}updateItemAge(t){}setItemTTL(t,e,i){}isStale(t){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new ln(this.max),this.removeItemSize=t=>{this.calculatedSize-=this.sizes[t],this.sizes[t]=0},this.requireSize=(t,e,i,n)=>{if(this.isBackgroundFetch(e))return 0;if(!cn(i)){if(!n)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof n)throw new TypeError("sizeCalculation must be a function");if(i=n(e,t),!cn(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,n){if(i||n)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())this.isBackgroundFetch(this.valList[t])||(yield[this.keyList[t],this.valList[t]])}*rentries(){for(const t of this.rindexes())this.isBackgroundFetch(this.valList[t])||(yield[this.keyList[t],this.valList[t]])}*keys(){for(const t of this.indexes())this.isBackgroundFetch(this.valList[t])||(yield this.keyList[t])}*rkeys(){for(const t of this.rindexes())this.isBackgroundFetch(this.valList[t])||(yield this.keyList[t])}*values(){for(const t of this.indexes())this.isBackgroundFetch(this.valList[t])||(yield this.valList[t])}*rvalues(){for(const t of this.rindexes())this.isBackgroundFetch(this.valList[t])||(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 sn("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],n=this.valList[e],s=this.isBackgroundFetch(n)?n.__staleWhileFetching:n;if(void 0===s)continue;const r={value:s};if(this.ttls){r.ttl=this.ttls[e];const t=Xi.now()-this.starts[e];r.start=Math.floor(Date.now()-t)}this.sizes&&(r.size=this.sizes[e]),t.unshift([i,r])}return t}load(t){this.clear();for(const[e,i]of t){if(i.start){const t=Date.now()-i.start;i.start=Xi.now()-t}this.set(e,i.value,i)}}dispose(t,e,i){}set(t,e,{ttl:i=this.ttl,start:n,noDisposeOnSet:s=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{this.moveToTail(c);const i=this.valList[c];e!==i&&(this.isBackgroundFetch(i)?i.__abortController.abort(new Error("replaced")):s||(this.dispose(i,t,"set"),this.disposeAfter&&this.disposed.push([i,t,"set"])),this.removeItemSize(c),this.valList[c]=e,this.addItemSize(c,r))}if(0===i||0!==this.ttl||this.ttls||this.initializeTTLTracking(),a||this.setItemTTL(c,i,n),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return 0===this.size?this.tail:this.size===this.max&&0!==this.max?this.evict(!1):0!==this.free.length?this.free.pop():this.initialFill++}pop(){if(this.size){const t=this.valList[this.head];return this.evict(!0),t}}evict(t){const e=this.head,i=this.keyList[e],n=this.valList[e];return this.isBackgroundFetch(n)?n.__abortController.abort(new Error("evicted")):(this.dispose(n,i,"evict"),this.disposeAfter&&this.disposed.push([n,i,"evict"])),this.removeItemSize(e),t&&(this.keyList[e]=null,this.valList[e]=null,this.free.push(e)),this.head=this.next[e],this.keyMap.delete(i),this.size--,e}has(t,{updateAgeOnHas:e=this.updateAgeOnHas}={}){const i=this.keyMap.get(t);return void 0!==i&&!this.isStale(i)&&(e&&this.updateItemAge(i),!0)}peek(t,{allowStale:e=this.allowStale}={}){const i=this.keyMap.get(t);if(void 0!==i&&(e||!this.isStale(i))){const t=this.valList[i];return this.isBackgroundFetch(t)?t.__staleWhileFetching:t}}backgroundFetch(t,e,i,n){const s=void 0===e?void 0:this.valList[e];if(this.isBackgroundFetch(s))return s;const r=new Zi;i.signal&&i.signal.addEventListener("abort",(()=>r.abort(i.signal.reason)));const o={signal:r.signal,options:i,context:n},a=(n,s=!1)=>{const{aborted:a}=r.signal,l=i.ignoreFetchAbort&&void 0!==n;return!a||l||s?(this.valList[e]===h&&(void 0===n?h.__staleWhileFetching?this.valList[e]=h.__staleWhileFetching:this.delete(t):this.set(t,n,o.options)),n):c(r.signal.reason)},c=n=>{const{aborted:s}=r.signal,o=s&&i.allowStaleOnFetchAbort,a=o||i.allowStaleOnFetchRejection,c=a||i.noDeleteOnFetchRejection;if(this.valList[e]===h){!c||void 0===h.__staleWhileFetching?this.delete(t):o||(this.valList[e]=h.__staleWhileFetching)}if(a)return h.__staleWhileFetching;if(h.__returned===h)throw n},h=new Promise(((e,n)=>{this.fetchMethod(t,s,o).then((t=>e(t)),n),r.signal.addEventListener("abort",(()=>{i.ignoreFetchAbort&&!i.allowStaleOnFetchAbort||(e(),i.allowStaleOnFetchAbort&&(e=t=>a(t,!0)))}))})).then(a,c);return h.__abortController=r,h.__staleWhileFetching=s,h.__returned=null,void 0===e?(this.set(t,h,o.options),e=this.keyMap.get(t)):this.valList[e]=h,h}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:n=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:o=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:h=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:l=this.allowStaleOnFetchRejection,ignoreFetchAbort:u=this.ignoreFetchAbort,allowStaleOnFetchAbort:d=this.allowStaleOnFetchAbort,fetchContext:p=this.fetchContext,forceRefresh:f=!1,signal:y}={}){if(!this.fetchMethod)return this.get(t,{allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:n});const v={allowStale:e,updateAgeOnGet:i,noDeleteOnStaleGet:n,ttl:s,noDisposeOnSet:r,size:o,sizeCalculation:a,noUpdateTTL:c,noDeleteOnFetchRejection:h,allowStaleOnFetchRejection:l,allowStaleOnFetchAbort:d,ignoreFetchAbort:u,signal:y};let g=this.keyMap.get(t);if(void 0===g){const e=this.backgroundFetch(t,g,v,p);return e.__returned=e}{const n=this.valList[g];if(this.isBackgroundFetch(n))return e&&void 0!==n.__staleWhileFetching?n.__staleWhileFetching:n.__returned=n;if(!f&&!this.isStale(g))return this.moveToTail(g),i&&this.updateItemAge(g),n;const s=this.backgroundFetch(t,g,v,p);return e&&void 0!==s.__staleWhileFetching?s.__staleWhileFetching:s.__returned=s}}get(t,{allowStale:e=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet}={}){const s=this.keyMap.get(t);if(void 0!==s){const r=this.valList[s],o=this.isBackgroundFetch(r);if(this.isStale(s))return o?e?r.__staleWhileFetching:void 0:(n||this.delete(t),e?r:void 0);if(o)return;return this.moveToTail(s),i&&this.updateItemAge(s),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 sn("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(new Error("deleted")):(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(new Error("deleted"));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 sn("reset","clear"),this.clear}get length(){return((t,e)=>{const i=`LRU_CACHE_PROPERTY_${t}`;if(on(i)){const{prototype:n}=dn,{get:s}=Object.getOwnPropertyDescriptor(n,t);an(i,`${t} property`,`cache.${e}`,s)}})("length","size"),this.size}static get AbortController(){return Zi}static get AbortSignal(){return tn}}var pn=dn;const fn=Gi("rpc:InMemoryCache");class yn{constructor(t){this.clearCache=()=>{var t;fn("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.clear()},this.getCachedResponse=t=>{var e;fn("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,n;fn("setCachedResponse",t,e);const s=h(t);if(!e)return null===(i=this.cachedResponseByParams)||void 0===i?void 0:i.del(s);const r=Object.assign({},e);delete r.correlationId,null===(n=this.cachedResponseByParams)||void 0===n||n.set(s,r?JSON.stringify(r):void 0)},this.cachedResponseByParams=new pn({max:(null==t?void 0:t.cacheMaxSize)||yn.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||yn.DEFAULT_CACHE_MAX_AGE_MS})}}yn.DEFAULT_CACHE_MAX_AGE_MS=3e5,yn.DEFAULT_CACHE_MAX_SIZE=100;class vn{constructor(t){const{code:e,correlationId:i,data:n,message:s,success:r}=t;if("number"!=typeof e)throw new Error("code must be a number");if(this.code=e,i&&"string"!=typeof i)throw new Error("correlationId must be a string");if(this.correlationId=i,this.data=n,s&&"string"!=typeof s)throw new Error("message must be a string");if(this.message=s,"boolean"!=typeof r)throw new Error("success must be a boolean");this.success=r}}const gn=Gi("rpc:HTTPTransport");class bn{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,i)=>e(this,void 0,void 0,(function*(){gn("sendRequest",t);const e=JSON.stringify(Object.assign({identity:this.identity},t)),i=yield null===window||void 0===window?void 0:window.fetch(this.host,{body:e,cache:"default",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"follow",referrerPolicy:"origin"}),n=yield i.text();if(!n)throw new Error("No response received from remote");const s=JSON.parse(n);return new vn(s)})),this.setIdentity=t=>{gn("setIdentity",t),this.identity=t},this.host=t.host}}class wn{constructor(t){this.reject=t=>{this.rejectPromise&&this.rejectPromise(t)},this.resolve=t=>{this.resolvePromise&&this.resolvePromise(t)},this.promise=new Promise(((i,n)=>e(this,void 0,void 0,(function*(){const e=setTimeout((()=>{n(new Error("PromiseWraper timeout"))}),t||3e4);this.rejectPromise=t=>{clearTimeout(e),n(t)},this.resolvePromise=t=>{clearTimeout(e),i(t)}}))))}}const mn=t=>new Promise((e=>setTimeout(e,t))),Sn=Gi("rpc:WebSocketTransport");class _n{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(Sn("sendRequest",t);this.isWaitingForIdentityConfirmation;)Sn("waiting for identity confirmation"),yield mn(100);return this.sendCall(t)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(Sn("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?Sn('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t}).then((()=>{Sn("setIdentity with remote complete")})).catch((t=>{Sn("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):Sn("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(Sn("connect",this.host),this.websocket)return void Sn("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):Sn("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):Sn("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>{var e;Sn("_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;Sn("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 vn(e);if(!i.correlationId)return void console.error("RPCClient WebSocketTransport received unexpected msg from the server, not correlationId found in response.",e);const n=this.pendingPromisesForResponse[i.correlationId];n?n.resolve(i):console.warn("rcvd WS msg/response that doesn't match any pending RPC's",e)},this.resetConnection=()=>e(this,void 0,void 0,(function*(){Sn("resetConnection"),this._disconnect("WebSocketTransport#resetConnection"),yield mn(100),this._connect()})),this.sendCall=t=>e(this,void 0,void 0,(function*(){var e;Sn("sendCall",t);const i=Math.random().toString();t.correlationId=t.correlationId||i;let n=new wn(_n.DEFAULT_TIMEOUT_MS);return null===(e=this.websocket)||void 0===e||e.send(JSON.stringify(t)),this.pendingPromisesForResponse[t.correlationId]=n,yield n.promise.finally((()=>{delete this.pendingPromisesForResponse[t.correlationId]}))})),this.setConnectedToRemote=t=>{Sn(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},Sn("new WebSocketTransport()"),this.host=t.host,this.connect()}}_n.DEFAULT_TIMEOUT_MS=1e4;const jn=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}};class Cn{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 On={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class Tn{constructor(t){var i,n,r,o,a,c;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new Cn,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,i,n)=>e(this,void 0,void 0,(function*(){if(!t)throw new Error('RPCClient.call(request) requires a "request" param');let e;e="string"==typeof t?jn(t):t,i&&(e.args=i);const r=new s(e);if(!r.procedure&&!r.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');r.identity||(r.identity={}),r.identity=$i(Object.assign({},this.identity),r.identity);const o=yield this.callManager.manageClientRequest(r,n);if(!o.success)throw o;const a=h(e);return this.vent.publish(a,null==o?void 0:o.data),o})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let i;i="string"==typeof t?jn(t):t,e&&(i.args=e);const n=this.callManager.getCachedResponse(i);if(n)return n},this.getIdentity=()=>this.identity?Li(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?jn(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=Li(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const i=Li(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===(n=null==t?void 0:t.transports)||void 0===n?void 0:n.http))throw new Error(On.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(On.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(On.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new Ki(u):new yn(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 _n({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 bn({host:t.hosts.http}),d.push(this.httpTransport)),this.callManager=new Vi({cache:l,deadlineMs:t.deadlineMs||Tn.DEFAULT_DEADLINE_MS,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:d})}subscribe(t,e){const i="string"==typeof t.request?jn(t.request):t.request,n=h(Object.assign(Object.assign({},i),{args:t.args}));return this.vent.subscribe(n,e)}unsubscribe(t,e){const i="string"==typeof t.request?jn(t.request):t.request,n=h(Object.assign(Object.assign({},i),{args:t.args}));this.vent.unsubscribe(n,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)}}Tn.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=Tn,t.RPCResponse=vn,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")(),f=d.Symbol,p=Object.prototype,v=p.hasOwnProperty,y=p.toString,g=f?f.toStringTag:void 0;var b=Object.prototype.toString;var w="[object Null]",m="[object Undefined]",S=f?f.toStringTag:void 0;function _(t){return null==t?void 0===t?m:w:S&&S in Object(t)?function(t){var e=v.call(t,g),i=t[g];try{t[g]=void 0;var s=!0}catch(t){}var n=y.call(t);return s&&(e?t[g]=i:delete t[g]),n}(t):function(t){return b.call(t)}(t)}function T(t){return null!=t&&"object"==typeof t}var C=Array.isArray;function j(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function O(t){return t}var A="[object AsyncFunction]",k="[object Function]",F="[object GeneratorFunction]",z="[object Proxy]";function E(t){if(!j(t))return!1;var e=_(t);return e==k||e==F||e==A||e==z}var R,x=d["__core-js_shared__"],I=(R=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var M=Function.prototype.toString;function L(t){if(null!=t){try{return M.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var P=/^\[object .+?Constructor\]$/,D=Function.prototype,W=Object.prototype,q=D.toString,B=W.hasOwnProperty,U=RegExp("^"+q.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function N(t){return!(!j(t)||(e=t,I&&I in e))&&(E(t)?U:P).test(L(t));var e}function $(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return N(i)?i:void 0}var G=$(d,"WeakMap"),H=Object.create,J=function(){function t(){}return function(e){if(!j(e))return{};if(H)return H(e);t.prototype=e;var i=new t;return t.prototype=void 0,i}}();function V(t,e){var i=-1,s=t.length;for(e||(e=Array(s));++i<s;)e[i]=t[i];return e}var X=Date.now;var K,Z,Q,Y=function(){try{var t=$(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),tt=Y,et=tt?function(t,e){return tt(t,"toString",{configurable:!0,enumerable:!1,value:(i=e,function(){return i}),writable:!0});var i}:O,it=(K=et,Z=0,Q=0,function(){var t=X(),e=16-(t-Q);if(Q=t,e>0){if(++Z>=800)return arguments[0]}else Z=0;return K.apply(void 0,arguments)}),st=it;var nt=9007199254740991,rt=/^(?:0|[1-9]\d*)$/;function ot(t,e){var i=typeof t;return!!(e=null==e?nt:e)&&("number"==i||"symbol"!=i&&rt.test(t))&&t>-1&&t%1==0&&t<e}function at(t,e,i){"__proto__"==e&&tt?tt(t,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):t[e]=i}function ct(t,e){return t===e||t!=t&&e!=e}var ht=Object.prototype.hasOwnProperty;function lt(t,e,i){var s=t[e];ht.call(t,e)&&ct(s,i)&&(void 0!==i||e in t)||at(t,e,i)}function ut(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?at(i,a,c):lt(i,a,c)}return i}var dt=Math.max;function ft(t,e){return st(function(t,e,i){return e=dt(void 0===e?t.length-1:e,0),function(){for(var s=arguments,n=-1,r=dt(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),function(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)}(t,this,a)}}(t,e,O),t+"")}var pt=9007199254740991;function vt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=pt}function yt(t){return null!=t&&vt(t.length)&&!E(t)}var gt=Object.prototype;function bt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||gt)}function wt(t){return T(t)&&"[object Arguments]"==_(t)}var mt=Object.prototype,St=mt.hasOwnProperty,_t=mt.propertyIsEnumerable,Tt=wt(function(){return arguments}())?wt:function(t){return T(t)&&St.call(t,"callee")&&!_t.call(t,"callee")},Ct=Tt;var jt="object"==typeof t&&t&&!t.nodeType&&t,Ot=jt&&"object"==typeof module&&module&&!module.nodeType&&module,At=Ot&&Ot.exports===jt?d.Buffer:void 0,kt=(At?At.isBuffer:void 0)||function(){return!1},Ft={};function zt(t){return function(e){return t(e)}}Ft["[object Float32Array]"]=Ft["[object Float64Array]"]=Ft["[object Int8Array]"]=Ft["[object Int16Array]"]=Ft["[object Int32Array]"]=Ft["[object Uint8Array]"]=Ft["[object Uint8ClampedArray]"]=Ft["[object Uint16Array]"]=Ft["[object Uint32Array]"]=!0,Ft["[object Arguments]"]=Ft["[object Array]"]=Ft["[object ArrayBuffer]"]=Ft["[object Boolean]"]=Ft["[object DataView]"]=Ft["[object Date]"]=Ft["[object Error]"]=Ft["[object Function]"]=Ft["[object Map]"]=Ft["[object Number]"]=Ft["[object Object]"]=Ft["[object RegExp]"]=Ft["[object Set]"]=Ft["[object String]"]=Ft["[object WeakMap]"]=!1;var Et="object"==typeof t&&t&&!t.nodeType&&t,Rt=Et&&"object"==typeof module&&module&&!module.nodeType&&module,xt=Rt&&Rt.exports===Et&&l.process,It=function(){try{var t=Rt&&Rt.require&&Rt.require("util").types;return t||xt&&xt.binding&&xt.binding("util")}catch(t){}}(),Mt=It&&It.isTypedArray,Lt=Mt?zt(Mt):function(t){return T(t)&&vt(t.length)&&!!Ft[_(t)]},Pt=Object.prototype.hasOwnProperty;function Dt(t,e){var i=C(t),s=!i&&Ct(t),n=!i&&!s&&kt(t),r=!i&&!s&&!n&&Lt(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&&!Pt.call(t,h)||o&&("length"==h||n&&("offset"==h||"parent"==h)||r&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||ot(h,c))||a.push(h);return a}function Wt(t,e){return function(i){return t(e(i))}}var qt=Wt(Object.keys,Object),Bt=Object.prototype.hasOwnProperty;function Ut(t){return yt(t)?Dt(t):function(t){if(!bt(t))return qt(t);var e=[];for(var i in Object(t))Bt.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}var Nt=Object.prototype.hasOwnProperty;function $t(t){if(!j(t))return function(t){var e=[];if(null!=t)for(var i in Object(t))e.push(i);return e}(t);var e=bt(t),i=[];for(var s in t)("constructor"!=s||!e&&Nt.call(t,s))&&i.push(s);return i}function Gt(t){return yt(t)?Dt(t,!0):$t(t)}var Ht=$(Object,"create");var Jt=Object.prototype.hasOwnProperty;var Vt=Object.prototype.hasOwnProperty;function Xt(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=t.length;i--;)if(ct(t[i][0],e))return i;return-1}Xt.prototype.clear=function(){this.__data__=Ht?Ht(null):{},this.size=0},Xt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Xt.prototype.get=function(t){var e=this.__data__;if(Ht){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return Jt.call(e,t)?e[t]:void 0},Xt.prototype.has=function(t){var e=this.__data__;return Ht?void 0!==e[t]:Vt.call(e,t)},Xt.prototype.set=function(t,e){var i=this.__data__;return this.size+=this.has(t)?0:1,i[t]=Ht&&void 0===e?"__lodash_hash_undefined__":e,this};var Zt=Array.prototype.splice;function Qt(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}Qt.prototype.clear=function(){this.__data__=[],this.size=0},Qt.prototype.delete=function(t){var e=this.__data__,i=Kt(e,t);return!(i<0)&&(i==e.length-1?e.pop():Zt.call(e,i,1),--this.size,!0)},Qt.prototype.get=function(t){var e=this.__data__,i=Kt(e,t);return i<0?void 0:e[i][1]},Qt.prototype.has=function(t){return Kt(this.__data__,t)>-1},Qt.prototype.set=function(t,e){var i=this.__data__,s=Kt(i,t);return s<0?(++this.size,i.push([t,e])):i[s][1]=e,this};var Yt=$(d,"Map");function te(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 ee(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 ie(t,e){for(var i=-1,s=e.length,n=t.length;++i<s;)t[n+i]=e[i];return t}ee.prototype.clear=function(){this.size=0,this.__data__={hash:new Xt,map:new(Yt||Qt),string:new Xt}},ee.prototype.delete=function(t){var e=te(this,t).delete(t);return this.size-=e?1:0,e},ee.prototype.get=function(t){return te(this,t).get(t)},ee.prototype.has=function(t){return te(this,t).has(t)},ee.prototype.set=function(t,e){var i=te(this,t),s=i.size;return i.set(t,e),this.size+=i.size==s?0:1,this};var se=Wt(Object.getPrototypeOf,Object),ne="[object Object]",re=Function.prototype,oe=Object.prototype,ae=re.toString,ce=oe.hasOwnProperty,he=ae.call(Object);function le(t){var e=this.__data__=new Qt(t);this.size=e.size}le.prototype.clear=function(){this.__data__=new Qt,this.size=0},le.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},le.prototype.get=function(t){return this.__data__.get(t)},le.prototype.has=function(t){return this.__data__.has(t)},le.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Qt){var s=i.__data__;if(!Yt||s.length<199)return s.push([t,e]),this.size=++i.size,this;i=this.__data__=new ee(s)}return i.set(t,e),this.size=i.size,this};var ue="object"==typeof t&&t&&!t.nodeType&&t,de=ue&&"object"==typeof module&&module&&!module.nodeType&&module,fe=de&&de.exports===ue?d.Buffer:void 0,pe=fe?fe.allocUnsafe:void 0;function ve(t,e){if(e)return t.slice();var i=t.length,s=pe?pe(i):new t.constructor(i);return t.copy(s),s}function ye(){return[]}var ge=Object.prototype.propertyIsEnumerable,be=Object.getOwnPropertySymbols,we=be?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}(be(t),(function(e){return ge.call(t,e)})))}:ye;var me=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ie(e,we(t)),t=se(t);return e}:ye;function Se(t,e,i){var s=e(t);return C(t)?s:ie(s,i(t))}function _e(t){return Se(t,Ut,we)}function Te(t){return Se(t,Gt,me)}var Ce=$(d,"DataView"),je=$(d,"Promise"),Oe=$(d,"Set"),Ae="[object Map]",ke="[object Promise]",Fe="[object Set]",ze="[object WeakMap]",Ee="[object DataView]",Re=L(Ce),xe=L(Yt),Ie=L(je),Me=L(Oe),Le=L(G),Pe=_;(Ce&&Pe(new Ce(new ArrayBuffer(1)))!=Ee||Yt&&Pe(new Yt)!=Ae||je&&Pe(je.resolve())!=ke||Oe&&Pe(new Oe)!=Fe||G&&Pe(new G)!=ze)&&(Pe=function(t){var e=_(t),i="[object Object]"==e?t.constructor:void 0,s=i?L(i):"";if(s)switch(s){case Re:return Ee;case xe:return Ae;case Ie:return ke;case Me:return Fe;case Le:return ze}return e});var De=Pe,We=Object.prototype.hasOwnProperty;var qe=d.Uint8Array;function Be(t){var e=new t.constructor(t.byteLength);return new qe(e).set(new qe(t)),e}var Ue=/\w*$/;var Ne=f?f.prototype:void 0,$e=Ne?Ne.valueOf:void 0;function Ge(t,e){var i=e?Be(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}var He="[object Boolean]",Je="[object Date]",Ve="[object Map]",Xe="[object Number]",Ke="[object RegExp]",Ze="[object Set]",Qe="[object String]",Ye="[object Symbol]",ti="[object ArrayBuffer]",ei="[object DataView]",ii="[object Float32Array]",si="[object Float64Array]",ni="[object Int8Array]",ri="[object Int16Array]",oi="[object Int32Array]",ai="[object Uint8Array]",ci="[object Uint8ClampedArray]",hi="[object Uint16Array]",li="[object Uint32Array]";function ui(t,e,i){var s,n,r,o=t.constructor;switch(e){case ti:return Be(t);case He:case Je:return new o(+t);case ei:return function(t,e){var i=e?Be(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);case ii:case si:case ni:case ri:case oi:case ai:case ci:case hi:case li:return Ge(t,i);case Ve:return new o;case Xe:case Qe:return new o(t);case Ke:return(r=new(n=t).constructor(n.source,Ue.exec(n))).lastIndex=n.lastIndex,r;case Ze:return new o;case Ye:return s=t,$e?Object($e.call(s)):{}}}function di(t){return"function"!=typeof t.constructor||bt(t)?{}:J(se(t))}var fi=It&&It.isMap,pi=fi?zt(fi):function(t){return T(t)&&"[object Map]"==De(t)};var vi=It&&It.isSet,yi=vi?zt(vi):function(t){return T(t)&&"[object Set]"==De(t)},gi=1,bi=2,wi=4,mi="[object Arguments]",Si="[object Function]",_i="[object GeneratorFunction]",Ti="[object Object]",Ci={};function ji(t,e,i,s,n,r){var o,a=e&gi,c=e&bi,h=e&wi;if(i&&(o=n?i(t,s,n,r):i(t)),void 0!==o)return o;if(!j(t))return t;var l=C(t);if(l){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&We.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!a)return V(t,o)}else{var u=De(t),d=u==Si||u==_i;if(kt(t))return ve(t,a);if(u==Ti||u==mi||d&&!n){if(o=c||d?{}:di(t),!a)return c?function(t,e){return ut(t,me(t),e)}(t,function(t,e){return t&&ut(e,Gt(e),t)}(o,t)):function(t,e){return ut(t,we(t),e)}(t,function(t,e){return t&&ut(e,Ut(e),t)}(o,t))}else{if(!Ci[u])return n?t:{};o=ui(t,u,a)}}r||(r=new le);var f=r.get(t);if(f)return f;r.set(t,o),yi(t)?t.forEach((function(s){o.add(ji(s,e,i,s,t,r))})):pi(t)&&t.forEach((function(s,n){o.set(n,ji(s,e,i,n,t,r))}));var p=l?void 0:(h?c?Te:_e:c?Gt:Ut)(t);return function(t,e){for(var i=-1,s=null==t?0:t.length;++i<s&&!1!==e(t[i],i,t););}(p||t,(function(s,n){p&&(s=t[n=s]),lt(o,n,ji(s,e,i,n,t,r))})),o}Ci[mi]=Ci["[object Array]"]=Ci["[object ArrayBuffer]"]=Ci["[object DataView]"]=Ci["[object Boolean]"]=Ci["[object Date]"]=Ci["[object Float32Array]"]=Ci["[object Float64Array]"]=Ci["[object Int8Array]"]=Ci["[object Int16Array]"]=Ci["[object Int32Array]"]=Ci["[object Map]"]=Ci["[object Number]"]=Ci[Ti]=Ci["[object RegExp]"]=Ci["[object Set]"]=Ci["[object String]"]=Ci["[object Symbol]"]=Ci["[object Uint8Array]"]=Ci["[object Uint8ClampedArray]"]=Ci["[object Uint16Array]"]=Ci["[object Uint32Array]"]=!0,Ci["[object Error]"]=Ci[Si]=Ci["[object WeakMap]"]=!1;function Oi(t){return ji(t,5)}var Ai,ki=function(t,e,i){for(var s=-1,n=Object(t),r=i(t),o=r.length;o--;){var a=r[Ai?o:++s];if(!1===e(n[a],a,n))break}return t};function Fi(t,e,i){(void 0!==i&&!ct(t[e],i)||void 0===i&&!(e in t))&&at(t,e,i)}function zi(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}function Ei(t,e,i,s,n,r,o){var a=zi(t,i),c=zi(e,i),h=o.get(c);if(h)Fi(t,i,h);else{var l,u=r?r(a,c,i+"",t,e,o):void 0,d=void 0===u;if(d){var f=C(c),p=!f&&kt(c),v=!f&&!p&&Lt(c);u=c,f||p||v?C(a)?u=a:T(l=a)&&yt(l)?u=V(a):p?(d=!1,u=ve(c,!0)):v?(d=!1,u=Ge(c,!0)):u=[]:function(t){if(!T(t)||_(t)!=ne)return!1;var e=se(t);if(null===e)return!0;var i=ce.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&ae.call(i)==he}(c)||Ct(c)?(u=a,Ct(a)?u=function(t){return ut(t,Gt(t))}(a):j(a)&&!E(a)||(u=di(c))):d=!1}d&&(o.set(c,u),n(u,c,s,r,o),o.delete(c)),Fi(t,i,u)}}function Ri(t,e,i,s,n){t!==e&&ki(e,(function(r,o){if(n||(n=new le),j(r))Ei(t,e,o,i,Ri,s,n);else{var a=s?s(zi(t,o),r,o+"",t,e,n):void 0;void 0===a&&(a=r),Fi(t,o,a)}}),Gt)}var xi,Ii=(xi=function(t,e,i){Ri(t,e,i)},ft((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=xi.length>3&&"function"==typeof n?(s--,n):void 0,r&&function(t,e,i){if(!j(i))return!1;var s=typeof e;return!!("number"==s?yt(i)&&ot(e,i.length):"string"==s&&e in i)&&ct(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&&xi(t,o,i,n)}return t})));let Mi=null;try{Mi=localStorage.getItem("debug")||""}catch(t){"undefined"!=typeof window&&"undefined"!=typeof localStorage&&console.warn("Error checking window.debug")}const Li=t=>Mi&&new RegExp(Mi).test(t)?(...e)=>console.log(t,...e):()=>{},Pi=Li("rpc:ClientManager");class Di{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=>{Pi("clearCache"),this.cache&&(t?this.cache.setCachedResponse(t,void 0):this.cache.clearCache())},this.getCachedResponse=t=>{var e;return Pi("getCachedResponse",t),null===(e=null==this?void 0:this.cache)||void 0===e?void 0:e.getCachedResponse(t)},this.getInFlightCallCount=()=>(Pi("getInFlightCallCount"),Object.keys(this.inflightCallsByKey).length),this.manageClientRequest=(t,i)=>e(this,void 0,void 0,(function*(){Pi("manageClientRequest",t);const s=yield this.interceptRequestMutator(t),n=h(s);if(this.inflightCallsByKey.hasOwnProperty(n))return Pi("manageClientRequest using an existing in-flight call",n),this.inflightCallsByKey[n].then((e=>{const i=Oi(e);return t.correlationId&&(i.correlationId=t.correlationId),i}));const r=(()=>e(this,void 0,void 0,(function*(){const t=yield this.sendRequestWithTransport(s,i),e=yield this.interceptResponseMutator(t,s);return this.cache&&e&&this.cache.setCachedResponse(s,e),e})))().finally((()=>{delete this.inflightCallsByKey[n]}));return this.inflightCallsByKey[n]=r,yield r})),this.setIdentity=t=>{Pi("setIdentity",t),this.transports.forEach((e=>e.setIdentity(t)))},this.interceptRequestMutator=t=>e(this,void 0,void 0,(function*(){var e,i,n,r;let o=t;if(this.interceptors.request.length){Pi("interceptRequestMutator(), original request:",t);try{for(var a,c=!0,h=s(this.interceptors.request);!(e=(a=yield h.next()).done);){r=a.value,c=!1;try{const t=r;o=yield t(o)}finally{c=!0}}}catch(t){i={error:t}}finally{try{c||e||!(n=h.return)||(yield n.call(h))}finally{if(i)throw i.error}}}return o})),this.interceptResponseMutator=(t,i)=>e(this,void 0,void 0,(function*(){let e=t;if(this.interceptors.response.length){Pi("interceptResponseMutator",i,t);for(const s of this.interceptors.response)try{e=yield s(e,i)}catch(s){throw Pi("caught response interceptor, request:",i,"original response:",t,"mutated response:",e),s}}return e})),this.sendRequestWithTransport=(t,i)=>e(this,void 0,void 0,(function*(){let e;Pi("sendRequestWithTransport",t);let s=0;for(;!e&&this.transports[s];){const n=this.transports[s];if(n.isConnected()){Pi(`sendRequestWithTransport trying ${this.transports[s].name}`,t);try{let s;const r=n.sendRequest(t,i||{}),o=new Promise(((e,n)=>{s=setTimeout((()=>{n(new a(`Procedure ${t.procedure}`))}),(null==i?void 0:i.timeout)||this.options.deadlineMs)}));e=yield Promise.race([o,r]).finally((()=>{clearTimeout(s)}))}catch(t){if(!(t instanceof a||t instanceof o))throw t;console.warn(`RPCClient ClientManager#sendRequestWithTransport() sending request with ${this.transports[s].name} failed, trying next transport`),s++}}else s++}if(!e&&!this.transports[s])throw console.error(`RPCClient ClientManager#sendRequestWithTransport() ${t.scope}::${t.procedure}::${t.version} did not get a response from any transports`),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 Wi{constructor(t){this.cacheOptions=t}clearCache(){}getCachedResponse(t){}setCachedResponse(t,e){}}Wi.DEFAULT_CACHE_MAX_AGE_MS=3e5,Wi.DEFAULT_CACHE_MAX_SIZE=100;const qi="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,Bi=new Set,Ui="object"==typeof process&&process?process:{},Ni=(t,e,i,s)=>{"function"==typeof Ui.emitWarning?Ui.emitWarning(t,e,i,s):console.error(`[${i}] ${e}: ${t}`)};let $i=globalThis.AbortController,Gi=globalThis.AbortSignal;if(void 0===$i){Gi=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},$i=class{constructor(){e()}signal=new Gi;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==Ui.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,Ni("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const Hi=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),Ji=t=>Hi(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?Vi:null:null;class Vi extends Array{constructor(t){super(t),this.fill(0)}}class Xi{heap;length;static#t=!1;static create(t){const e=Ji(t);if(!e)return[];Xi.#t=!0;const i=new Xi(t,e);return Xi.#t=!1,i}constructor(t,e){if(!Xi.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class Ki{#e;#i;#s;#n;#r;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#o;#a;#c;#h;#l;#u;#d;#f;#p;#v;#y;#g;#b;#w;#m;#S;#_;static unsafeExposeInternals(t){return{starts:t.#b,ttls:t.#w,sizes:t.#g,keyMap:t.#c,keyList:t.#h,valList:t.#l,next:t.#u,prev:t.#d,get head(){return t.#f},get tail(){return t.#p},free:t.#v,isBackgroundFetch:e=>t.#T(e),backgroundFetch:(e,i,s,n)=>t.#C(e,i,s,n),moveToTail:e=>t.#j(e),indexes:e=>t.#O(e),rindexes:e=>t.#A(e),isStale:e=>t.#k(e)}}get max(){return this.#e}get maxSize(){return this.#i}get calculatedSize(){return this.#a}get size(){return this.#o}get fetchMethod(){return this.#r}get dispose(){return this.#s}get disposeAfter(){return this.#n}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:f=0,sizeCalculation:p,fetchMethod:v,noDeleteOnFetchRejection:y,noDeleteOnStaleGet:g,allowStaleOnFetchRejection:b,allowStaleOnFetchAbort:w,ignoreFetchAbort:m}=t;if(0!==e&&!Hi(e))throw new TypeError("max option must be a nonnegative integer");const S=e?Ji(e):Array;if(!S)throw new Error("invalid max value: "+e);if(this.#e=e,this.#i=d,this.maxEntrySize=f||this.#i,this.sizeCalculation=p,this.sizeCalculation){if(!this.#i&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==v&&"function"!=typeof v)throw new TypeError("fetchMethod must be a function if specified");if(this.#r=v,this.#S=!!v,this.#c=new Map,this.#h=new Array(e).fill(void 0),this.#l=new Array(e).fill(void 0),this.#u=new S(e),this.#d=new S(e),this.#f=0,this.#p=0,this.#v=Xi.create(e),this.#o=0,this.#a=0,"function"==typeof c&&(this.#s=c),"function"==typeof h?(this.#n=h,this.#y=[]):(this.#n=void 0,this.#y=void 0),this.#m=!!this.#s,this.#_=!!this.#n,this.noDisposeOnSet=!!l,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!y,this.allowStaleOnFetchRejection=!!b,this.allowStaleOnFetchAbort=!!w,this.ignoreFetchAbort=!!m,0!==this.maxEntrySize){if(0!==this.#i&&!Hi(this.#i))throw new TypeError("maxSize must be a positive integer if specified");if(!Hi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#F()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!g,this.updateAgeOnGet=!!r,this.updateAgeOnHas=!!o,this.ttlResolution=Hi(s)||0===s?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!Hi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#z()}if(0===this.#e&&0===this.ttl&&0===this.#i)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#i){const t="LRU_CACHE_UNBOUNDED";if((t=>!Bi.has(t))(t)){Bi.add(t);Ni("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,Ki)}}}getRemainingTTL(t){return this.#c.has(t)?1/0:0}#z(){const t=new Vi(this.#e),e=new Vi(this.#e);this.#w=t,this.#b=e,this.#E=(i,s,n=qi.now())=>{if(e[i]=0!==s?n:0,t[i]=s,0!==s&&this.ttlAutopurge){const t=setTimeout((()=>{this.#k(i)&&this.delete(this.#h[i])}),s+1);t.unref&&t.unref()}},this.#R=i=>{e[i]=0!==t[i]?qi.now():0},this.#x=(n,r)=>{if(t[r]){const o=t[r],a=e[r];n.ttl=o,n.start=a,n.now=i||s(),n.remainingTTL=n.now+o-a}};let i=0;const s=()=>{const t=qi.now();if(this.ttlResolution>0){i=t;const e=setTimeout((()=>i=0),this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=n=>{const r=this.#c.get(n);return void 0===r?0:0===t[r]||0===e[r]?1/0:e[r]+t[r]-(i||s())},this.#k=n=>0!==t[n]&&0!==e[n]&&(i||s())-e[n]>t[n]}#R=()=>{};#x=()=>{};#E=()=>{};#k=()=>!1;#F(){const t=new Vi(this.#e);this.#a=0,this.#g=t,this.#I=e=>{this.#a-=t[e],t[e]=0},this.#M=(t,e,i,s)=>{if(this.#T(e))return 0;if(!Hi(i)){if(!s)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof s)throw new TypeError("sizeCalculation must be a function");if(i=s(e,t),!Hi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return i},this.#L=(e,i,s)=>{if(t[e]=i,this.#i){const i=this.#i-t[e];for(;this.#a>i;)this.#P(!0)}this.#a+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#a)}}#I=t=>{};#L=(t,e,i)=>{};#M=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#O({allowStale:t=this.allowStale}={}){if(this.#o)for(let e=this.#p;this.#D(e)&&(!t&&this.#k(e)||(yield e),e!==this.#f);)e=this.#d[e]}*#A({allowStale:t=this.allowStale}={}){if(this.#o)for(let e=this.#f;this.#D(e)&&(!t&&this.#k(e)||(yield e),e!==this.#p);)e=this.#u[e]}#D(t){return void 0!==t&&this.#c.get(this.#h[t])===t}*entries(){for(const t of this.#O())void 0===this.#l[t]||void 0===this.#h[t]||this.#T(this.#l[t])||(yield[this.#h[t],this.#l[t]])}*rentries(){for(const t of this.#A())void 0===this.#l[t]||void 0===this.#h[t]||this.#T(this.#l[t])||(yield[this.#h[t],this.#l[t]])}*keys(){for(const t of this.#O()){const e=this.#h[t];void 0===e||this.#T(this.#l[t])||(yield e)}}*rkeys(){for(const t of this.#A()){const e=this.#h[t];void 0===e||this.#T(this.#l[t])||(yield e)}}*values(){for(const t of this.#O()){void 0===this.#l[t]||this.#T(this.#l[t])||(yield this.#l[t])}}*rvalues(){for(const t of this.#A()){void 0===this.#l[t]||this.#T(this.#l[t])||(yield this.#l[t])}}[Symbol.iterator](){return this.entries()}find(t,e={}){for(const i of this.#O()){const s=this.#l[i],n=this.#T(s)?s.__staleWhileFetching:s;if(void 0!==n&&t(n,this.#h[i],this))return this.get(this.#h[i],e)}}forEach(t,e=this){for(const i of this.#O()){const s=this.#l[i],n=this.#T(s)?s.__staleWhileFetching:s;void 0!==n&&t.call(e,n,this.#h[i],this)}}rforEach(t,e=this){for(const i of this.#A()){const s=this.#l[i],n=this.#T(s)?s.__staleWhileFetching:s;void 0!==n&&t.call(e,n,this.#h[i],this)}}purgeStale(){let t=!1;for(const e of this.#A({allowStale:!0}))this.#k(e)&&(this.delete(this.#h[e]),t=!0);return t}dump(){const t=[];for(const e of this.#O({allowStale:!0})){const i=this.#h[e],s=this.#l[e],n=this.#T(s)?s.__staleWhileFetching:s;if(void 0===n||void 0===i)continue;const r={value:n};if(this.#w&&this.#b){r.ttl=this.#w[e];const t=qi.now()-this.#b[e];r.start=Math.floor(Date.now()-t)}this.#g&&(r.size=this.#g[e]),t.unshift([i,r])}return t}load(t){this.clear();for(const[e,i]of t){if(i.start){const t=Date.now()-i.start;i.start=qi.now()-t}this.set(e,i.value,i)}}set(t,e,i={}){if(void 0===e)return this.delete(t),this;const{ttl:s=this.ttl,start:n,noDisposeOnSet:r=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:a}=i;let{noUpdateTTL:c=this.noUpdateTTL}=i;const h=this.#M(t,e,i.size||0,o);if(this.maxEntrySize&&h>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.delete(t),this;let l=0===this.#o?void 0:this.#c.get(t);if(void 0===l)l=0===this.#o?this.#p:0!==this.#v.length?this.#v.pop():this.#o===this.#e?this.#P(!1):this.#o,this.#h[l]=t,this.#l[l]=e,this.#c.set(t,l),this.#u[this.#p]=l,this.#d[l]=this.#p,this.#p=l,this.#o++,this.#L(l,h,a),a&&(a.set="add"),c=!1;else{this.#j(l);const i=this.#l[l];if(e!==i){if(this.#S&&this.#T(i)?i.__abortController.abort(new Error("replaced")):r||(this.#m&&this.#s?.(i,t,"set"),this.#_&&this.#y?.push([i,t,"set"])),this.#I(l),this.#L(l,h,a),this.#l[l]=e,a){a.set="replace";const t=i&&this.#T(i)?i.__staleWhileFetching:i;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update")}if(0===s||this.#w||this.#z(),this.#w&&(c||this.#E(l,s,n),a&&this.#x(a,l)),!r&&this.#_&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}return this}pop(){try{for(;this.#o;){const t=this.#l[this.#f];if(this.#P(!0),this.#T(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#_&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}}}#P(t){const e=this.#f,i=this.#h[e],s=this.#l[e];return this.#S&&this.#T(s)?s.__abortController.abort(new Error("evicted")):(this.#m||this.#_)&&(this.#m&&this.#s?.(s,i,"evict"),this.#_&&this.#y?.push([s,i,"evict"])),this.#I(e),t&&(this.#h[e]=void 0,this.#l[e]=void 0,this.#v.push(e)),1===this.#o?(this.#f=this.#p=0,this.#v.length=0):this.#f=this.#u[e],this.#c.delete(i),this.#o--,e}has(t,e={}){const{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#c.get(t);if(void 0!==n){const t=this.#l[n];if(this.#T(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#k(n))return i&&this.#R(n),s&&(s.has="hit",this.#x(s,n)),!0;s&&(s.has="stale",this.#x(s,n))}else s&&(s.has="miss");return!1}peek(t,e={}){const{allowStale:i=this.allowStale}=e,s=this.#c.get(t);if(void 0!==s&&(i||!this.#k(s))){const t=this.#l[s];return this.#T(t)?t.__staleWhileFetching:t}}#C(t,e,i,s){const n=void 0===e?void 0:this.#l[e];if(this.#T(n))return n;const r=new $i,{signal:o}=i;o?.addEventListener("abort",(()=>r.abort(o.reason)),{signal:r.signal});const a={signal:r.signal,options:i,context:s},c=(s,n=!1)=>{const{aborted:o}=r.signal,c=i.ignoreFetchAbort&&void 0!==s;if(i.status&&(o&&!n?(i.status.fetchAborted=!0,i.status.fetchError=r.signal.reason,c&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),o&&!c&&!n)return h(r.signal.reason);const u=l;return this.#l[e]===l&&(void 0===s?u.__staleWhileFetching?this.#l[e]=u.__staleWhileFetching:this.delete(t):(i.status&&(i.status.fetchUpdated=!0),this.set(t,s,a.options))),s},h=s=>{const{aborted:n}=r.signal,o=n&&i.allowStaleOnFetchAbort,a=o||i.allowStaleOnFetchRejection,c=a||i.noDeleteOnFetchRejection,h=l;if(this.#l[e]===l){!c||void 0===h.__staleWhileFetching?this.delete(t):o||(this.#l[e]=h.__staleWhileFetching)}if(a)return i.status&&void 0!==h.__staleWhileFetching&&(i.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw s};i.status&&(i.status.fetchDispatched=!0);const l=new Promise(((e,s)=>{const o=this.#r?.(t,n,a);o&&o instanceof Promise&&o.then((t=>e(t)),s),r.signal.addEventListener("abort",(()=>{i.ignoreFetchAbort&&!i.allowStaleOnFetchAbort||(e(),i.allowStaleOnFetchAbort&&(e=t=>c(t,!0)))}))})).then(c,(t=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=t),h(t)))),u=Object.assign(l,{__abortController:r,__staleWhileFetching:n,__returned:void 0});return void 0===e?(this.set(t,u,{...a.options,status:void 0}),e=this.#c.get(t)):this.#l[e]=u,u}#T(t){if(!this.#S)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof $i}async fetch(t,e={}){const{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:r=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:a=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:l=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:d=this.ignoreFetchAbort,allowStaleOnFetchAbort:f=this.allowStaleOnFetchAbort,context:p,forceRefresh:v=!1,status:y,signal:g}=e;if(!this.#S)return y&&(y.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:y});const b={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:r,noDisposeOnSet:o,size:a,sizeCalculation:c,noUpdateTTL:h,noDeleteOnFetchRejection:l,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:f,ignoreFetchAbort:d,status:y,signal:g};let w=this.#c.get(t);if(void 0===w){y&&(y.fetch="miss");const e=this.#C(t,w,b,p);return e.__returned=e}{const e=this.#l[w];if(this.#T(e)){const t=i&&void 0!==e.__staleWhileFetching;return y&&(y.fetch="inflight",t&&(y.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const n=this.#k(w);if(!v&&!n)return y&&(y.fetch="hit"),this.#j(w),s&&this.#R(w),y&&this.#x(y,w),e;const r=this.#C(t,w,b,p),o=void 0!==r.__staleWhileFetching&&i;return y&&(y.fetch=n?"stale":"refresh",o&&n&&(y.returnedStale=!0)),o?r.__staleWhileFetching:r.__returned=r}}get(t,e={}){const{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:r}=e,o=this.#c.get(t);if(void 0!==o){const e=this.#l[o],a=this.#T(e);return r&&this.#x(r,o),this.#k(o)?(r&&(r.get="stale"),a?(r&&i&&void 0!==e.__staleWhileFetching&&(r.returnedStale=!0),i?e.__staleWhileFetching:void 0):(n||this.delete(t),r&&i&&(r.returnedStale=!0),i?e:void 0)):(r&&(r.get="hit"),a?e.__staleWhileFetching:(this.#j(o),s&&this.#R(o),e))}r&&(r.get="miss")}#W(t,e){this.#d[e]=t,this.#u[t]=e}#j(t){t!==this.#p&&(t===this.#f?this.#f=this.#u[t]:this.#W(this.#d[t],this.#u[t]),this.#W(this.#p,t),this.#p=t)}delete(t){let e=!1;if(0!==this.#o){const i=this.#c.get(t);if(void 0!==i)if(e=!0,1===this.#o)this.clear();else{this.#I(i);const e=this.#l[i];this.#T(e)?e.__abortController.abort(new Error("deleted")):(this.#m||this.#_)&&(this.#m&&this.#s?.(e,t,"delete"),this.#_&&this.#y?.push([e,t,"delete"])),this.#c.delete(t),this.#h[i]=void 0,this.#l[i]=void 0,i===this.#p?this.#p=this.#d[i]:i===this.#f?this.#f=this.#u[i]:(this.#u[this.#d[i]]=this.#u[i],this.#d[this.#u[i]]=this.#d[i]),this.#o--,this.#v.push(i)}}if(this.#_&&this.#y?.length){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}return e}clear(){for(const t of this.#A({allowStale:!0})){const e=this.#l[t];if(this.#T(e))e.__abortController.abort(new Error("deleted"));else{const i=this.#h[t];this.#m&&this.#s?.(e,i,"delete"),this.#_&&this.#y?.push([e,i,"delete"])}}if(this.#c.clear(),this.#l.fill(void 0),this.#h.fill(void 0),this.#w&&this.#b&&(this.#w.fill(0),this.#b.fill(0)),this.#g&&this.#g.fill(0),this.#f=0,this.#p=0,this.#v.length=0,this.#a=0,this.#o=0,this.#_&&this.#y){const t=this.#y;let e;for(;e=t?.shift();)this.#n?.(...e)}}}const Zi=Li("rpc:InMemoryCache");class Qi{constructor(t){this.clearCache=()=>{var t;Zi("clearCache"),null===(t=this.cachedResponseByParams)||void 0===t||t.clear()},this.getCachedResponse=t=>{var e;Zi("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;Zi("setCachedResponse",t,e);const n=h(t);if(!e)return null===(i=this.cachedResponseByParams)||void 0===i?void 0:i.delete(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 Ki({max:(null==t?void 0:t.cacheMaxSize)||Qi.DEFAULT_CACHE_MAX_SIZE,ttl:(null==t?void 0:t.cacheMaxAgeMs)||Qi.DEFAULT_CACHE_MAX_AGE_MS})}}Qi.DEFAULT_CACHE_MAX_AGE_MS=9e5,Qi.DEFAULT_CACHE_MAX_SIZE=200;class Yi{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 ts=Li("rpc:HTTPTransport");class es{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,i)=>e(this,void 0,void 0,(function*(){ts("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 Yi(n)})),this.setIdentity=t=>{ts("setIdentity",t),this.identity=t},this.host=t.host}}class is{constructor(t,i){this.reject=t=>{this.rejectPromise&&this.rejectPromise(t)},this.resolve=t=>{this.resolvePromise&&this.resolvePromise(t)},this.promise=new Promise(((s,n)=>e(this,void 0,void 0,(function*(){const e=setTimeout((()=>{n(new Error(`PromiseWraper timeout: ${t}`))}),i||3e4);this.rejectPromise=t=>{clearTimeout(e),n(t)},this.resolvePromise=t=>{clearTimeout(e),s(t)}}))))}}const ss=t=>new Promise((e=>setTimeout(e,t))),ns=t=>{const e=t.split("::");return{procedure:e[1],scope:e[0]||"global",version:e[2]||"1"}},rs=Li("rpc:WebSocketTransport");class os{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,i)=>e(this,void 0,void 0,(function*(){for(rs("sendRequest",t);this.isWaitingForIdentityConfirmation;)rs("waiting for identity confirmation"),yield ss(100);return this.sendCall(t,i)})),this.setIdentity=t=>e(this,void 0,void 0,(function*(){if(rs("setIdentity",t),!t)return this.identity=void 0,void(yield this.resetConnection());this.identity=t,this.connectedToRemote?this.isWaitingForIdentityConfirmation?rs('setIdentity returning early because "this.isWaitingForIdentityConfirmation=true"'):(this.isWaitingForIdentityConfirmation=!0,this.sendCall({identity:t},{}).then((()=>{rs("setIdentity with remote complete")})).catch((t=>{rs("setIdentity with remote error",t)})).finally((()=>{this.isWaitingForIdentityConfirmation=!1}))):rs("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(rs("connect",this.host),this.websocket)return void rs("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):rs("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):rs("WebSocket errored, it was not connected to the remote"),t.close()}},this._disconnect=t=>{var e;rs("_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;rs("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 Yi(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*(){rs("resetConnection"),this._disconnect("WebSocketTransport#resetConnection"),yield ss(100),this._connect()})),this.sendCall=(t,i)=>e(this,void 0,void 0,(function*(){var e;rs("sendCall",t);const s=Math.random().toString();t.correlationId=t.correlationId||s;let n=new is(`${(r=t).scope}::${r.procedure}::${r.version}`,i.timeout||this.options.rpcOptions.deadlineMs);var r;return null===(e=this.websocket)||void 0===e||e.send(JSON.stringify(t)),this.pendingPromisesForResponse[t.correlationId]=n,yield n.promise.finally((()=>{delete this.pendingPromisesForResponse[t.correlationId]}))})),this.setConnectedToRemote=t=>{rs(`setConnectedToRemote: ${t}`),this.connectedToRemote=t,this.options.onConnectionStatusChange&&this.options.onConnectionStatusChange(t),t&&this.identity&&this.setIdentity(this.identity)},rs("new WebSocketTransport()"),this.host=t.host,this.connect()}}class as{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 cs={HTTP_HOST_OR_TRANSPORT_REQUIRED:"http host or tansport is required",INTERCEPTOR_MUSTBE_FUNC:"interceptors must be a function"};class hs{constructor(t){var i,s,r,o,a,c;if(this.options=t,this.webSocketConnectionChangeListeners=[],this.vent=new as,this.onWebSocketConnectionStatusChange=t=>{this.options.onWebSocketConnectionStatusChange&&this.options.onWebSocketConnectionStatusChange(t),this.webSocketConnectionChangeListeners.forEach((e=>e(t)))},this.call=(t,i,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?ns(t):t,i&&(e.args=i);const r=new n(e);if(!r.procedure&&!r.identity)throw new TypeError('RPCClient#call requires a "identity" or "procedure" prop and received neither');r.identity||(r.identity={}),r.identity=Ii(Object.assign({},this.identity),r.identity);const o=yield this.callManager.manageClientRequest(r,s);if(!o.success)throw o;const a=h(e);return this.vent.publish(a,null==o?void 0:o.data),o})),this.clearCache=t=>{this.callManager.clearCache(t)},this.getCallCache=(t,e)=>{let i;i="string"==typeof t?ns(t):t,e&&(i.args=e);const s=this.callManager.getCachedResponse(i);if(s)return s},this.getIdentity=()=>this.identity?Oi(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?ns(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=Oi(t);this.identity=t,this.callManager.setIdentity(e)},this.setIdentityMetadata=t=>{var e;null!==(e=this.identity)&&void 0!==e||(this.identity={});const i=Oi(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(cs.HTTP_HOST_OR_TRANSPORT_REQUIRED);if(t.requestInterceptor&&"function"!=typeof t.requestInterceptor)throw new Error(cs.INTERCEPTOR_MUSTBE_FUNC);if(t.responseInterceptor&&"function"!=typeof t.responseInterceptor)throw new Error(cs.INTERCEPTOR_MUSTBE_FUNC);let l;const u={cacheMaxAgeMs:null==t?void 0:t.cacheMaxAgeMs};l="browser"==t.cacheType?new Wi(u):new Qi(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 os({host:t.hosts.websocket,onConnectionStatusChange:this.onWebSocketConnectionStatusChange,rpcOptions:t}),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 es({host:t.hosts.http,rpcOptions:t}),d.push(this.httpTransport)),this.callManager=new Di({cache:l,deadlineMs:t.deadlineMs||hs.DEFAULT_DEADLINE_MS,requestInterceptor:t.requestInterceptor,responseInterceptor:t.responseInterceptor,transports:d})}subscribe(t,e){const i="string"==typeof t.request?ns(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?ns(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)}}hs.DEFAULT_DEADLINE_MS=1e4,t.RPCClient=hs,t.RPCResponse=Yi,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -5,3 +5,3 @@ export declare class PromiseWrapper<T, E> {

readonly promise: Promise<T>;
constructor(timeout?: number);
constructor(description: string, timeout?: number);
reject: (rejectReturnValue?: E) => any;

@@ -8,0 +8,0 @@ resolve: (resolveReturnValue: T) => void;

import { CallRequestDTO } from '../CallRequestDTO';
export declare const getRequestShorthand: (request: CallRequestDTO) => string;
export declare const parseRequestShorthand: (requestString: string) => CallRequestDTO;
//# sourceMappingURL=request.d.ts.map
{
"name": "@therms/rpc-client",
"version": "2.15.0",
"version": "2.16.0",
"description": "RPC framework, browser client lib",

@@ -29,13 +29,13 @@ "private": false,

"lodash-es": "^4.17.21",
"lru-cache": "^7.8.1"
"lru-cache": "^9.1.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-typescript": "^8.2.0",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^11.0.0",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/commit-analyzer": "^9.0.1",
"@semantic-release/git": "^10.0.0",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/npm": "^10.0.2",
"@semantic-release/release-notes-generator": "^10.0.2",

@@ -45,7 +45,7 @@ "@therms/rpc-server": "^2.0.0",

"@types/fast-json-stable-stringify": "^2.1.0",
"@types/jest": "^27.0.1",
"@types/jest": "^29.5.0",
"@types/lodash-es": "^4.17.4",
"@types/lru-cache": "^7.6.1",
"debug": "^4.3.1",
"jest": "^27.2.0",
"jest": "^29.5.0",
"prettier": "^2.3.0",

@@ -59,8 +59,7 @@ "rollup": "^2.48.0",

"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^19.0.2",
"ts-jest": "^27.0.5",
"semantic-release": "^21.0.1",
"ts-jest": "^29.1.0",
"tslib": "^2.1.0",
"typescript": "^4.2.3",
"update-by-scope": "^1.1.3"
"typescript": "^5.0.3"
}
}

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

import LRU from 'lru-cache'
import { LRUCache as LRU } from 'lru-cache'
import { CallRequestDTO } from '../CallRequestDTO'

@@ -16,4 +16,4 @@ import { CallResponseDTO } from '../CallResponseDTO'

export class InMemoryCache implements Cache {
static DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 5
static DEFAULT_CACHE_MAX_SIZE = 100
static DEFAULT_CACHE_MAX_AGE_MS = 1000 * 60 * 15
static DEFAULT_CACHE_MAX_SIZE = 200

@@ -57,3 +57,3 @@ private cachedResponseByParams: LRU<string, any> | undefined

if (!response) {
return this.cachedResponseByParams?.del(requestKey)
return this.cachedResponseByParams?.delete(requestKey)
}

@@ -60,0 +60,0 @@

@@ -162,14 +162,6 @@ import { Cache } from '../cache/Cache'

const requestPromise = requestPromiseWrapper()
.then((response) => {
delete this.inflightCallsByKey[key]
const requestPromise = requestPromiseWrapper().finally(() => {
delete this.inflightCallsByKey[key]
})
return response
})
.catch((err) => {
delete this.inflightCallsByKey[key]
throw err
})
this.inflightCallsByKey[key] = requestPromise

@@ -257,2 +249,4 @@

const transportPromise = transport.sendRequest(request, opts || {})
const deadlinePromise = new Promise((_, reject) => {

@@ -268,11 +262,8 @@ timeout = setTimeout(() => {

response = await Promise.race([
response = (await Promise.race([
deadlinePromise,
transport.sendRequest(request, opts),
]).then((response) => {
transportPromise,
]).finally(() => {
clearTimeout(timeout)
// the timeout will reject, CallResponseDTO is the only response that will be passed
return response as CallResponseDTO
})
})) as Promise<CallResponseDTO>
} catch (e: any) {

@@ -295,9 +286,9 @@ if (

if (!response && !this.transports[transportsIndex]) {
console.error(
`RPCClient ClientManager#sendRequestWithTransport() ${request.scope}::${request.procedure}::${request.version} did not get a response from any transports`,
)
throw new CallRequestError(
`Procedure ${request.procedure} did not get a response from any transports`,
)
console.error(
`RPCClient ClientManager#sendRequestWithTransport() ${request.scope}::${request.procedure}::${request.version} did not get a response from any transports`,
)
} else if (!response) {

@@ -304,0 +295,0 @@ throw new CallRequestError(

@@ -93,4 +93,6 @@ import { CallRequestDTO } from './CallRequestDTO'

export interface RPCClientOptions {
/** Defaults to memory */
cacheType?: 'browser' | 'memory'
cacheMaxAgeMs?: number
/** Defaults to 10000ms */
deadlineMs?: number

@@ -161,2 +163,3 @@ hosts?: {

onConnectionStatusChange: this.onWebSocketConnectionStatusChange,
rpcOptions: options,
})

@@ -171,3 +174,6 @@

} else if (options?.hosts?.http) {
this.httpTransport = new HTTPTransport({ host: options.hosts.http })
this.httpTransport = new HTTPTransport({
host: options.hosts.http,
rpcOptions: options,
})

@@ -174,0 +180,0 @@ transports.push(this.httpTransport)

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

import { GetDebugLogger } from '../utils/debug-logger'
import { RPCRequestOptions } from '../RPCClient'
import { RPCClientOptions, RPCRequestOptions } from '../RPCClient'

@@ -13,2 +13,3 @@ const debug = GetDebugLogger('rpc:HTTPTransport')

host: string
rpcOptions: RPCClientOptions
}

@@ -38,3 +39,3 @@

call: CallRequestDTO,
opts?: RPCRequestOptions,
opts: RPCRequestOptions,
): Promise<CallResponseDTO> => {

@@ -41,0 +42,0 @@ debug('sendRequest', call)

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

call: CallRequestDTO,
opts?: RPCRequestOptions,
opts: RPCRequestOptions,
): Promise<CallResponseDTO>

@@ -16,0 +16,0 @@

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

import { CallRequestTransportError } from './errors/CallRequestTransportError'
import {UnsubscribeCallback} from "../types";
import { UnsubscribeCallback } from '../types'
import { getRequestShorthand } from '../utils/request'
import { RPCClientOptions, RPCRequestOptions } from '../RPCClient'

@@ -20,7 +22,6 @@ const debug = GetDebugLogger('rpc:WebSocketTransport')

onConnectionStatusChange?: (connected: boolean) => void
rpcOptions: RPCClientOptions
}
export class WebSocketTransport implements Transport {
static DEFAULT_TIMEOUT_MS = 10000
private connectedToRemote: boolean = false

@@ -80,2 +81,3 @@ private readonly host: string

call: CallRequestDTO,
opts: RPCRequestOptions,
): Promise<CallResponseDTO> => {

@@ -90,3 +92,3 @@ debug('sendRequest', call)

return this.sendCall(call)
return this.sendCall(call, opts)
}

@@ -122,3 +124,3 @@

this.sendCall({ identity })
this.sendCall({ identity }, {})
.then(() => {

@@ -135,7 +137,11 @@ debug('setIdentity with remote complete')

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

@@ -288,3 +294,6 @@ }

private sendCall = async (call: CallRequestDTO): Promise<CallResponseDTO> => {
private sendCall = async (
call: CallRequestDTO,
opts: RPCRequestOptions,
): Promise<CallResponseDTO> => {
debug('sendCall', call)

@@ -299,3 +308,6 @@

CallResponseDTO | CallRequestTransportError
>(WebSocketTransport.DEFAULT_TIMEOUT_MS)
>(
getRequestShorthand(call),
opts.timeout || this.options.rpcOptions.deadlineMs,
)

@@ -302,0 +314,0 @@ this.websocket?.send(JSON.stringify(call))

@@ -5,3 +5,3 @@ import { PromiseWrapper } from './PromiseWrapper'

it('can instantiate', () => {
const p = new PromiseWrapper()
const p = new PromiseWrapper('')
p.resolve(null)

@@ -11,3 +11,3 @@ })

it('can creates a promise', (done) => {
const { promise, resolve } = new PromiseWrapper()
const { promise, resolve } = new PromiseWrapper('')

@@ -26,3 +26,3 @@ expect(promise.then).toBeDefined()

it('will timeout', () => {
const { promise } = new PromiseWrapper(1)
const { promise } = new PromiseWrapper('', 1)

@@ -29,0 +29,0 @@ expect(promise).rejects.toThrow(Error)

@@ -9,6 +9,6 @@ const DEFAULT_TIMEOUT = 30000

constructor(timeout?: number) {
constructor(description: string, timeout?: number) {
this.promise = new Promise(async (resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error('PromiseWraper timeout'))
reject(new Error(`PromiseWraper timeout: ${description}`))
}, timeout || DEFAULT_TIMEOUT)

@@ -15,0 +15,0 @@

@@ -7,2 +7,8 @@ import {

export const getRequestShorthand = (
request: CallRequestDTO,
): string => {
return `${request.scope}::${request.procedure}::${request.version}`
}
export const parseRequestShorthand = (

@@ -9,0 +15,0 @@ requestString: string,

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

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