@stackone/transport 2.24.0 → 2.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +13 -13
- package/dist/index.d.cts +11 -11
- package/dist/index.d.mts +11 -11
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,configurable:!0}),n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,__commonJSMin=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),__copyProps=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},__toESM=(n,r,a)=>(a=n==null?{}:e(i(n)),__copyProps(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let o=require(`@stackone/utils`),s=require(`redis`);s=__toESM(s);let c=require(`@stackone/expressions`),l=require(`axios`);l=__toESM(l);let u=require(`node:https`);u=__toESM(u);let d=require(`crypto`),f=require(`node:timers`),p=require(`jsonpath-plus`),m=require(`@stackone/redaction`),h=require(`qs`);h=__toESM(h);let g=require(`fast-xml-parser`);const createAuthorizationHeaders=e=>{switch(e.type){case`none`:return{};case`basic`:return createBasicAuthorizationHeader(e);case`bearer`:return createBearerAuthorizationHeader(e);case`oauth2`:return createBearerAuthorizationHeader(e);default:throw Error(`Invalid authentication type`)}},createBasicAuthorizationHeader=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n;return{authorization:`Basic ${Buffer.from(`${e}:${t}`).toString(r)}`}},createBearerAuthorizationHeader=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var LockManager=class{constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);r&&i?(i.push({lock:n,unlock:t}),await i[i.length-2].lock):this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const _=1e3,v=100,y=60,b=6e4,x=60,S=b,C=b*10,w=100,T=10;let E=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var MemoryStore=class{constructor(e={}){this.lastAccessedAt=Date.now(),this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new LockManager,this.expiryMap=e?.expiryMap??new Map,this.groupMap=new Map,this.groupExpiryMap=new Map,this.evictionFrequency=e?.evictionFrequency??6e4,this.staleDataThreshold=e?.staleDataThreshold??6e5,this.truncateThreshold=e?.truncateThreshold??100,this.truncationPercentage=e?.truncationPercentage??10,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async getDataKeysFromGroup(e){this.isReady()||this.initialize(),this.updateLastAccessedAt();let t=this.groupExpiryMap.get(e);return(0,o.notMissing)(t)&&t<=Date.now()?(this.groupMap.delete(e),this.groupExpiryMap.delete(e),[]):Array.from(this.groupMap.get(e)??[])}async setData({key:e,value:t,cacheTTL:n=60,groupKeys:r,groupKeyTTL:i}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),(0,o.notMissing)(this.typeGuard)&&!this.typeGuard(t))return!1;let a=n*_,s=Date.now()+a;if(await this.lockManager.withLock(e,async()=>{((0,o.notMissing)(this.typeGuard)&&this.typeGuard(t)||(0,o.isMissing)(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,s)}),(0,o.notMissing)(r)&&r.length>0){let t=(0,o.notMissing)(i)&&Number.isFinite(i)&&i>0?i*_:void 0;for(let n of r)this.groupMap.has(n)||this.groupMap.set(n,new Set),this.groupMap.get(n)?.add(e),(0,o.notMissing)(t)&&this.groupExpiryMap.set(n,Date.now()+t)}return!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e,t){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}if((0,o.notMissing)(t)&&t.length>0)for(let n of t)this.groupMap.get(n)?.delete(e);return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;return this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/100;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n),{dataStoreSize:e,prunedDataStoreSize:this.dataStore.size}}startEvictionTask(){if((0,o.notMissing)(this.evictionInterval))return;let executePrune=async()=>{let e;try{if(this.lastAccessedAt+this.staleDataThreshold<Date.now()){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}e=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}catch(e){e instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:e,code:E.MemoryStorePruneError}),this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}finally{if((0,o.notMissing)(e?.dataStoreSize)&&(0,o.notMissing)(e?.prunedDataStoreSize)){let{dataStoreSize:t,prunedDataStoreSize:n}=e,r=t-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&=(clearTimeout(this.evictionInterval),void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return(0,o.notMissing)(this.evictionInterval)&&(0,o.notMissing)(this.dataStore)&&(0,o.notMissing)(this.expiryMap)&&(0,o.notMissing)(this.lockManager)}isAvailable(){return this.isReady()}async setTTL(e,t){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),!this.dataStore.has(e)||!Number.isFinite(t)||t<=0)return!1;let n=t*_;return await this.lockManager.withLock(e,async()=>{this.expiryMap.set(e,Date.now()+n)}),!0}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.groupMap.clear(),this.groupExpiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()).filter(t=>t.includes(e)),i=[],a=t?parseInt(t,10):0;for(let e=a;e<n+a;e++){let t=r[e];if(!t)break;let a=await this.getData(t);if(a&&i.push(a),i.length>=n)break}return{items:i,cursor:i.length<n?void 0:(a+n).toString()}}};const ee=1e3,D=6e4;let O=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var EventClient=class{constructor(e,t,n){this.executorMethodStore=null,this.promiseStore=null,this.eventClientConfig=null,this.executorMethodStoreConfig=null,this.pendingPromiseStoreConfig=null,this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new MemoryStore(i),this.promiseStore=new MemoryStore(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/1e3;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return(0,o.notMissing)(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);(0,o.isMissing)(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??6e4),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:O.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){(0,o.notMissing)(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):(0,o.notMissing)(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return(0,o.isObject)(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},AsyncSingleton=class{constructor(){this.instance=null,this.initPromise=null,this.retryTimeout=null,this.status=`uninitialized`,this.initOptions=null,this.initArgs=[]}getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:((0,o.isMissing)(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,(0,o.isMissing)(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let k=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const buildRedisClientInstance=async(e,t,n)=>{try{return await te.build(e,t,n)??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:k.RedisClientError,category:n??`buildRedisClientInstance`});return}};var te=class RedisClient{#e;#t;static async build({getRedisClient:e=s.createClient,host:t,port:n,tls:r,keepAlive:i=3e4,reconnect:a=!0,database:o},c,l){let u=new RedisClient;u.#t=c;try{u.#e=e({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:t,port:n,tls:r,keepAlive:i},database:o,disableOfflineQueue:!0});let s=getDefaultRedisListeners(l??`RedisClient`,u.#t);return addRedisEventHandlers(u.#e,s),await u.#e.connect(),u}catch(e){let t=e;return u.#t?.error({message:`Error building Cache Manager.`,error:t,code:k.RedisClientError,category:l??`RedisClient`}),null}}#n(e){try{return JSON.parse(e)}catch{return e}}async getData(e){if(!this.#i())return null;try{let t=await this.#e.get(e);if(!t)return null;let n=this.#n(t);return(0,o.isString)(n)?t:n}catch(e){let t=e;return this.#t?.error({message:`Error getting data`,error:t,code:k.RedisClientReadError,category:RedisClient.name}),null}}async getDataKeysFromGroup(e){if(!this.#i())return null;try{return await this.#e.sMembers(e)}catch(e){let t=e;return this.#t?.error({message:`Error getting data from group`,error:t,code:k.RedisClientReadError,category:RedisClient.name}),null}}async setData({key:e,value:t,cacheTTL:n,groupKeys:r,groupKeyTTL:i}){if(!this.#i())return!1;try{let a=(0,o.isString)(t)?t:JSON.stringify(t);if(await this.#e.set(e,a,{EX:n}),(0,o.notMissing)(r)&&r.length>0)for(let t of r)await this.#e.sAdd(t,[e]),(0,o.notMissing)(i)&&Number.isFinite(i)&&i>0&&await this.#e.expire(t,i);return!0}catch(e){let t=e;return this.#t?.error({message:`Error setting data`,error:t,code:k.RedisClientWriteError,category:RedisClient.name}),!1}}async setTTL(e,t){if(!this.#i())return!1;if(!Number.isFinite(t)||t<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:RedisClient.name,code:k.RedisClientInvalidTTL}),!1;try{let n=await this.#e.expire(e,t);return n||this.#t?.debug({message:`No keys updated for ${e}`,category:RedisClient.name}),n}catch(e){let t=e;return this.#t?.error({message:`Error resetting data TTL`,error:t,code:k.RedisClientWriteError,category:RedisClient.name}),!1}}async executeScript({sha1:e,keys:t,args:n}){if(!this.#i())return null;try{return await this.#e.evalSha(e,{keys:t,arguments:n})}catch(e){let t=e;throw this.#t?.error({message:`Error executing script`,error:t,code:k.RedisClientScriptExecuteError,category:RedisClient.name}),t}}async loadScript(e){if(!this.#i())return null;try{return await this.#e.scriptLoad(e)}catch(e){let t=e;return this.#t?.error({message:`Error loading script`,error:t,code:k.RedisClientScriptLoadError,category:RedisClient.name}),null}}async scriptExists(e){if(!this.#i())return e.map(()=>!1);try{return(await this.#e.scriptExists(e)).map(e=>!!e)}catch(t){let n=t;return this.#t?.error({message:`Error checking script existence`,error:n,code:k.RedisClientScriptError,category:RedisClient.name}),e.map(()=>!1)}}async#r(e,t,n){if(!this.#i())return null;if(!Number.isFinite(n)||n<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:RedisClient.name,code:k.RedisClientInvalidTTL}),null;try{let r=[{args:[e,t]},{args:[`expire`,t,n.toString()]}],i=(await this.#e.multiExecutor(r))?.[0];return typeof i==`number`?i:null}catch(t){let n=t;return this.#t?.error({message:`Error executing ${e} operation`,error:n,code:k.RedisClientCommandError,category:RedisClient.name}),null}}async increment(e,t){return this.#r(`incr`,e,t)}async decrement(e,t){return this.#r(`decr`,e,t)}async subscribe(e,t){if(!this.#i())return!1;try{return await this.#e.pSubscribe(e,t),!0}catch(t){let n=t;return this.#t?.error({message:`Error subscribing to ${e}`,error:n,code:k.RedisClientSubscribeError,category:RedisClient.name}),!1}}async unsubscribe(e){if(!this.#i())return!1;try{return await this.#e.pUnsubscribe(e),!0}catch(t){let n=t;return this.#t?.error({message:`Error unsubscribing from ${e}`,error:n,code:k.RedisClientUnsubscribeError,category:RedisClient.name}),!1}}async publish(e,t){if(!this.#i())return null;try{let n=await this.#e.publish(e,t);return n===0&&this.#t?.debug({message:`No subscribers found for channel ${e}`,category:RedisClient.name}),n}catch(t){let n=t;return this.#t?.error({message:`Error publishing to ${e}`,error:n,code:k.RedisClientPublishError,category:RedisClient.name}),null}}getClient(){return this.#i()?this.#e:null}isAvailable(){return this.#e.isReady&&this.#e.isOpen}#i(){let e=this.isAvailable();return e||this.#t?.error({message:`Redis Client is not ready.`,category:RedisClient.name,code:k.RedisClientRedisNotReady}),e}async listData({partialKey:e,limit:t,cursor:n}){try{let r=n?parseInt(n,10):0,i=await this.#e.sScan(e,r,{COUNT:t}),a=[];for(let e of i.members){let t=await this.getData(e);(0,o.notMissing)(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(e){let t=e;return this.#t?.error({message:`Error listing data`,error:t,code:k.RedisClientListError,category:RedisClient.name}),{items:null}}}async deleteData(e,t){try{if(!this.#i())return!1;let n=await this.#e.del(e);return n===0&&this.#t?.debug({message:`No keys deleted for ${e}`,category:RedisClient.name}),(0,o.notMissing)(t)&&t.length>0&&(await Promise.allSettled(t.map(t=>this.#e.sRem(t,e)))).forEach((e,n)=>{e.status===`rejected`&&this.#t?.error({message:`Error removing key from group set ${t[n]}`,error:e.reason,code:k.RedisClientDeleteError,category:RedisClient.name})}),n>0}catch(e){let t=e;return this.#t?.error({message:`Error deleting data`,error:t,code:k.RedisClientDeleteError,category:RedisClient.name}),!1}}};const addRedisEventHandlers=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},getDefaultRedisListeners=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:k.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let ne=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});const re=1500;var ScriptManager=class extends AsyncSingleton{constructor(...e){super(...e),this.isInitialConnection=!0,this.reloadInProgress=null,this.lastReloadTime=0}async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let s=t??await buildRedisClientInstance(e,i,this.name);if((0,o.isMissing)(s))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=s,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();(0,o.notMissing)(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){if((0,o.notMissing)(this.reloadInProgress))return this.logger?.info({message:`Script reload already in progress, waiting for completion`,category:this.name}),this.reloadInProgress;if(!((0,o.isMissing)(this.scripts)||Object.keys(this.scripts).length===0)){this.reloadInProgress=this.performReload();try{await this.reloadInProgress}finally{this.reloadInProgress=null}}}async performReload(){this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts),this.lastReloadTime=Date.now()}async loadScripts(e,t){if((0,o.notMissing)(t))for(let[e,n]of t)this.scriptMap.set(e,n);let n=Object.entries(e),r=n.map(([e])=>this.scriptMap.get(e)).filter(o.notMissing),i=new Map;if(r.length>0&&(0,o.notMissing)(this.cacheClient?.scriptExists)){let e=await this.cacheClient.scriptExists(r);if((0,o.notMissing)(e)){r.forEach((t,n)=>{i.set(t,e[n]??!1)});let t=e.filter(Boolean).length;t>0&&this.logger?.info({message:`${t}/${r.length} scripts already exist in Redis; skipping load for existing scripts`,category:this.name})}}for(let[e,t]of n){let n=this.scriptMap.get(e);if(n&&i.get(n))continue;let r=await this.cacheClient?.loadScript?.(t);(0,o.notMissing)(r)?this.scriptMap?.set(e,r):this.logger?.error({message:`Error loading script ${e}`,category:this.name,code:ne.ScriptManagerLoadingError})}}async executeScript(e,t,n){if(!this.isRedisReady())return this.logger?.warning({message:`Redis not ready, cannot execute script ${e}`,category:this.name,context:{keys:t,args:n}}),null;let r=this.scriptMap?.get(e);if((0,o.isMissing)(r))throw this.logger?.error({message:`Script for ${e} not found in script map`,category:this.name,code:ne.ScriptManagerExecutionError}),Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){let i=Date.now()-this.lastReloadTime;if(i<re){let t=re-i;this.logger?.info({message:`Script ${e} not found, reload occurred ${i}ms ago. Waiting ${t}ms before reloading`,category:this.name}),await(0,o.delay)(t)}if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),(0,o.isMissing)(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${i.message}`,category:this.name,context:{keys:t,args:n},error:i,code:ne.ScriptManagerExecutionError}),i}}isRedisReady(){let e=this.cacheClient?.getClient?.();if((0,o.notMissing)(this.cacheClient)&&(0,o.isMissing)(e))return this.logger?.warning({message:`Cache client exists but getClient() returned null - cannot verify Redis readiness`,category:this.name}),!1;let t=e?.isReady&&e?.isOpen;return this.isReady()&&(0,o.notMissing)(this.cacheClient)&&(t??!1)}},SubscriptionManager=class{constructor(e){this.options={getCacheClient:buildRedisClientInstance},this.subscriptionMap=null,this.subscriptionClient=null,this.name=`SubscriptionManager`,this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new MemoryStore({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),(0,o.notMissing)(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),r=(0,o.getContentHash)(t.toString());return await this.subscriptionMap?.setData({key:e,value:r}),n===r?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return(0,o.notMissing)(this.subscriptionClient)&&(0,o.notMissing)(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const ie=6e4,ae=15e3,oe=!1,se=6e4,ce=15e3,le=1e4,ue=1;let de=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),A=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var QueueManager=class extends ScriptManager{constructor(...e){super(...e),this.subscriptionManager=null,this.eventClient=null,this.name=`QueueManager`}async additionalInitialization(){if((0,o.isMissing)(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new SubscriptionManager({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:6e4,truncateThreshold:le,truncationPercentage:1}),await this.subscriptionManager?.initialize(),this.eventClient=new EventClient({instantiator:this.name,timeoutResolveValue:!1},{instantiator:this.name,evictionFrequency:ce,truncateThreshold:le,truncationPercentage:1},{instantiator:this.name,evictionFrequency:ce,truncateThreshold:le,truncationPercentage:1}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?A.lPush:A.rPush,[e],[t,`60000`])===1;return(!i||!o)&&await this.eventClient?.waitForEvent(a,15e3),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:de.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(A.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:de.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(A.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:de.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return(0,o.notMissing)(this.subscriptionManager)&&(0,o.notMissing)(this.cacheClient)&&(0,o.notMissing)(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const fe=5,pe=12e4,me=1e4,he=1,ge=60,_e=90,j=`__keyevent@0__:`,ve=`${j}set`,ye=`${j}expire`,M=`${j}expired`,be=`${j}srem`,xe=`config_check_test_key`,Se=[ve,ye,M],Ce=1,we=2e4,Te={mainMaxConcurrency:30};let N=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e.ConcurrencyManagerPublishNextItemFailed=`ConcurrencyManagerPublishNextItemFailed`,e.ConcurrencyManagerReleaseRequestFailed=`ConcurrencyManagerReleaseRequestFailed`,e}({}),P=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const Ee={[P.tryConcurrency]:`
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,configurable:!0}),n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,__commonJSMin=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),__copyProps=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},__toESM=(n,r,a)=>(a=n==null?{}:e(i(n)),__copyProps(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let o=require(`@stackone/utils`),s=require(`redis`);s=__toESM(s);let c=require(`@stackone/expressions`),l=require(`axios`);l=__toESM(l);let u=require(`node:https`);u=__toESM(u);let d=require(`crypto`),f=require(`node:timers`),p=require(`jsonpath-plus`),m=require(`@stackone/redaction`),h=require(`qs`);h=__toESM(h);let g=require(`fast-xml-parser`);const createAuthorizationHeaders=e=>{switch(e.type){case`none`:return{};case`basic`:return createBasicAuthorizationHeader(e);case`bearer`:return createBearerAuthorizationHeader(e);case`oauth2`:return createBearerAuthorizationHeader(e);default:throw Error(`Invalid authentication type`)}},createBasicAuthorizationHeader=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n;return{authorization:`Basic ${Buffer.from(`${e}:${t}`).toString(r)}`}},createBearerAuthorizationHeader=({token:e,includeBearer:t})=>({authorization:`${t?`Bearer `:``}${e}`});var LockManager=class{constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t,n=new Promise(e=>t=e),r=this.locks.has(e),i=this.locks.get(e);r&&i?(i.push({lock:n,unlock:t}),await i[i.length-2].lock):this.locks.set(e,[{lock:n,unlock:t}])}unlock(e){let t=this.locks.has(e),n=this.locks.get(e);if(t&&n&&n.length>0){let e=n.shift()?.unlock;e?.()}this.queueLength(e)===0&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}};const _=1e3,v=100,y=60,b=6e4,x=60,S=b,C=b*10,w=100,T=10;let E=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var MemoryStore=class{constructor(e={}){this.lastAccessedAt=Date.now(),this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??`Unknown`,this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new LockManager,this.expiryMap=e?.expiryMap??new Map,this.groupMap=new Map,this.groupExpiryMap=new Map,this.evictionFrequency=e?.evictionFrequency??6e4,this.staleDataThreshold=e?.staleDataThreshold??6e5,this.truncateThreshold=e?.truncateThreshold??100,this.truncationPercentage=e?.truncationPercentage??10,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>this.dataStore.get(e)??null)}async getDataKeysFromGroup(e){this.isReady()||this.initialize(),this.updateLastAccessedAt();let t=this.groupExpiryMap.get(e);return(0,o.notMissing)(t)&&t<=Date.now()?(this.groupMap.delete(e),this.groupExpiryMap.delete(e),[]):Array.from(this.groupMap.get(e)??[])}async setData({key:e,value:t,cacheTTL:n=60,groupKeys:r,groupKeyTTL:i}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),(0,o.notMissing)(this.typeGuard)&&!this.typeGuard(t))return!1;let a=n*_,s=Date.now()+a;if(await this.lockManager.withLock(e,async()=>{((0,o.notMissing)(this.typeGuard)&&this.typeGuard(t)||(0,o.isMissing)(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,s)}),(0,o.notMissing)(r)&&r.length>0){let t=(0,o.notMissing)(i)&&Number.isFinite(i)&&i>0?i*_:void 0;for(let n of r)this.groupMap.has(n)||this.groupMap.set(n,new Set),this.groupMap.get(n)?.add(e),(0,o.notMissing)(t)&&this.groupExpiryMap.set(n,Date.now()+t)}return!0}typeGuardBypass(e){return this.logger?.debug({category:`MemoryStore`,message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e,t){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,async()=>{if(this.dispose){let t=this.dataStore.get(e);await this.dispose(e,t)}if((0,o.notMissing)(t)&&t.length>0)for(let n of t)this.groupMap.get(n)?.delete(e);return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;return this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/100;(o<=a||t&&r>=0&&r<=s)&&n.push(this.lockManager.withLock(i,async()=>(this.dispose&&await this.dispose(i,e),this.dataStore.delete(i)))),r++}),await Promise.all(n),{dataStoreSize:e,prunedDataStoreSize:this.dataStore.size}}startEvictionTask(){if((0,o.notMissing)(this.evictionInterval))return;let executePrune=async()=>{let e;try{if(this.lastAccessedAt+this.staleDataThreshold<Date.now()){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}e=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}catch(e){e instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:e,code:E.MemoryStorePruneError}),this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}finally{if((0,o.notMissing)(e?.dataStoreSize)&&(0,o.notMissing)(e?.prunedDataStoreSize)){let{dataStoreSize:t,prunedDataStoreSize:n}=e,r=t-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(executePrune,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&=(clearTimeout(this.evictionInterval),void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return(0,o.notMissing)(this.evictionInterval)&&(0,o.notMissing)(this.dataStore)&&(0,o.notMissing)(this.expiryMap)&&(0,o.notMissing)(this.lockManager)}isAvailable(){return this.isReady()}async setTTL(e,t){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),!this.dataStore.has(e)||!Number.isFinite(t)||t<=0)return!1;let n=t*_;return await this.lockManager.withLock(e,async()=>{this.expiryMap.set(e,Date.now()+n)}),!0}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.groupMap.clear(),this.groupExpiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()).filter(t=>t.includes(e)),i=[],a=t?parseInt(t,10):0;for(let e=a;e<n+a;e++){let t=r[e];if(!t)break;let a=await this.getData(t);if(a&&i.push(a),i.length>=n)break}return{items:i,cursor:i.length<n?void 0:(a+n).toString()}}};const D=1e3,O=6e4;let k=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var EventClient=class{constructor(e,t,n){this.executorMethodStore=null,this.promiseStore=null,this.eventClientConfig=null,this.executorMethodStoreConfig=null,this.pendingPromiseStoreConfig=null,this.eventClientConfig=e,this.executorMethodStoreConfig=t,this.pendingPromiseStoreConfig=n;let r=e?.instantiator?`${e?.instantiator}(${this.constructor.name})`:this.constructor.name,i={logger:this.logger,dispose:this.defaultExecutorMethodDispose,typeGuard:this.defaultExecutorMethodTypeGuard,...this.executorMethodStoreConfig??{},instantiator:r},a={logger:this.logger,dispose:this.defaultPendingPromiseDispose,typeGuard:this.defaultPendingPromiseTypeGuard,...this.pendingPromiseStoreConfig??{},instantiator:r};this.executorMethodStore=new MemoryStore(i),this.promiseStore=new MemoryStore(a)}async setPendingEvent(e,t){let n={resolve:void 0,reject:void 0},r=new Promise((e,t)=>{n.resolve=e,n.reject=t}),i=t/1e3;await this.executorMethodStore?.setData({key:e,value:n,cacheTTL:i}),await this.promiseStore?.setData({key:e,value:r,cacheTTL:i})}async waitForEvent(e,t){let n=await this.promiseStore?.getData(e);return(0,o.notMissing)(n)?n:(await this.setPendingEvent(e,t),this.getPendingEvent(e))}async getPendingEvent(e){return this.promiseStore?.getData(e)??null}async deleteEvent(e){return(await Promise.all([this.promiseStore?.delete(e),this.executorMethodStore?.delete(e)])).every(Boolean)}async resolveEvent(e,t){try{let n=await this.executorMethodStore?.getData(e);(0,o.isMissing)(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??6e4),n=await this.executorMethodStore?.getData(e)),n?.resolve?.(t)}catch(t){t instanceof Error&&this.logger.error({message:`Error handling event for key ${e}: ${t.message}`,category:this.constructor.name,context:{eventKey:e},error:t,code:k.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){(0,o.notMissing)(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):(0,o.notMissing)(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return(0,o.isObject)(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}},AsyncSingleton=class{constructor(){this.instance=null,this.initPromise=null,this.retryTimeout=null,this.status=`uninitialized`,this.initOptions=null,this.initArgs=[]}getRetryDelay(){return 5e3}getSingleton(e){throw Error(`getSingleton method not implemented`)}async getInstance(e,...t){return this.instance?this.instance:((0,o.isMissing)(this.initPromise)&&(this.initOptions=e??null,this.initArgs=t,this.initPromise=this.init(e??null,...t)),this.initPromise)}getInstanceIfReady(){return this.instance}isReady(){return this.status===`ready`}hasInitFailed(){return this.status===`failed`}async init(e,...t){try{let n=await this.initInstance(e,...t);return this.instance=n,this.status=`ready`,n}catch(e){throw this.status=`failed`,this.initPromise=null,(0,o.isMissing)(this.retryTimeout)&&(this.retryTimeout=setTimeout(()=>{this.retryTimeout=null,this.getInstance(this.initOptions,...this.initArgs).catch(()=>{})},this.getRetryDelay())),e}}reset(){this.instance=null,this.initPromise=null,this.initOptions=null,this.status=`uninitialized`,this.retryTimeout&&clearTimeout(this.retryTimeout),this.retryTimeout=null}};let A=function(e){return e.RedisClientError=`RedisClientError`,e.RedisClientCommandError=`RedisClientCommandError`,e.RedisClientDeleteError=`RedisClientDeleteError`,e.RedisClientInvalidTTL=`RedisClientInvalidTTL`,e.RedisClientListError=`RedisClientListError`,e.RedisClientNotInitialized=`RedisClientNotInitialized`,e.RedisClientPublishError=`RedisClientPublishError`,e.RedisClientReadError=`RedisClientReadError`,e.RedisClientRedisNotReady=`RedisClientRedisNotReady`,e.RedisClientScriptError=`RedisClientScriptError`,e.RedisClientScriptExecuteError=`RedisClientScriptExecuteError`,e.RedisClientScriptLoadError=`RedisClientScriptLoadError`,e.RedisClientSubscribeError=`RedisClientSubscribeError`,e.RedisClientUnsubscribeError=`RedisClientUnsubscribeError`,e.RedisClientWriteError=`RedisClientWriteError`,e}({});const buildRedisClientInstance=async(e,t,n)=>{try{return await ee.build(e,t,n)??void 0}catch(e){let r=e;t?.error({message:`Error building Cache Manager`,error:r,code:A.RedisClientError,category:n??`buildRedisClientInstance`});return}};var ee=class RedisClient{#e;#t;static async build({getRedisClient:e=s.createClient,host:t,port:n,tls:r,keepAlive:i=3e4,reconnect:a=!0,database:o},c,l){let u=new RedisClient;u.#t=c;try{u.#e=e({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:t,port:n,tls:r,keepAlive:i},database:o,disableOfflineQueue:!0});let s=getDefaultRedisListeners(l??`RedisClient`,u.#t);return addRedisEventHandlers(u.#e,s),await u.#e.connect(),u}catch(e){let t=e;return u.#t?.error({message:`Error building Cache Manager.`,error:t,code:A.RedisClientError,category:l??`RedisClient`}),null}}#n(e){try{return JSON.parse(e)}catch{return e}}async getData(e){if(!this.#i())return null;try{let t=await this.#e.get(e);if(!t)return null;let n=this.#n(t);return(0,o.isString)(n)?t:n}catch(e){let t=e;return this.#t?.error({message:`Error getting data`,error:t,code:A.RedisClientReadError,category:RedisClient.name}),null}}async getDataKeysFromGroup(e){if(!this.#i())return null;try{return await this.#e.sMembers(e)}catch(e){let t=e;return this.#t?.error({message:`Error getting data from group`,error:t,code:A.RedisClientReadError,category:RedisClient.name}),null}}async setData({key:e,value:t,cacheTTL:n,groupKeys:r,groupKeyTTL:i}){if(!this.#i())return!1;try{let a=(0,o.isString)(t)?t:JSON.stringify(t);if(await this.#e.set(e,a,{EX:n}),(0,o.notMissing)(r)&&r.length>0)for(let t of r)await this.#e.sAdd(t,[e]),(0,o.notMissing)(i)&&Number.isFinite(i)&&i>0&&await this.#e.expire(t,i);return!0}catch(e){let t=e;return this.#t?.error({message:`Error setting data`,error:t,code:A.RedisClientWriteError,category:RedisClient.name}),!1}}async setTTL(e,t){if(!this.#i())return!1;if(!Number.isFinite(t)||t<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:RedisClient.name,code:A.RedisClientInvalidTTL}),!1;try{let n=await this.#e.expire(e,t);return n||this.#t?.debug({message:`No keys updated for ${e}`,category:RedisClient.name}),n}catch(e){let t=e;return this.#t?.error({message:`Error resetting data TTL`,error:t,code:A.RedisClientWriteError,category:RedisClient.name}),!1}}async executeScript({sha1:e,keys:t,args:n}){if(!this.#i())return null;try{return await this.#e.evalSha(e,{keys:t,arguments:n})}catch(e){let t=e;throw this.#t?.error({message:`Error executing script`,error:t,code:A.RedisClientScriptExecuteError,category:RedisClient.name}),t}}async loadScript(e){if(!this.#i())return null;try{return await this.#e.scriptLoad(e)}catch(e){let t=e;return this.#t?.error({message:`Error loading script`,error:t,code:A.RedisClientScriptLoadError,category:RedisClient.name}),null}}async scriptExists(e){if(!this.#i())return e.map(()=>!1);try{return(await this.#e.scriptExists(e)).map(e=>!!e)}catch(t){let n=t;return this.#t?.error({message:`Error checking script existence`,error:n,code:A.RedisClientScriptError,category:RedisClient.name}),e.map(()=>!1)}}async#r(e,t,n){if(!this.#i())return null;if(!Number.isFinite(n)||n<=0)return this.#t?.error({message:`Invalid cacheTTL parameter`,category:RedisClient.name,code:A.RedisClientInvalidTTL}),null;try{let r=[{args:[e,t]},{args:[`expire`,t,n.toString()]}],i=(await this.#e.multiExecutor(r))?.[0];return typeof i==`number`?i:null}catch(t){let n=t;return this.#t?.error({message:`Error executing ${e} operation`,error:n,code:A.RedisClientCommandError,category:RedisClient.name}),null}}async increment(e,t){return this.#r(`incr`,e,t)}async decrement(e,t){return this.#r(`decr`,e,t)}async subscribe(e,t){if(!this.#i())return!1;try{return await this.#e.pSubscribe(e,t),!0}catch(t){let n=t;return this.#t?.error({message:`Error subscribing to ${e}`,error:n,code:A.RedisClientSubscribeError,category:RedisClient.name}),!1}}async unsubscribe(e){if(!this.#i())return!1;try{return await this.#e.pUnsubscribe(e),!0}catch(t){let n=t;return this.#t?.error({message:`Error unsubscribing from ${e}`,error:n,code:A.RedisClientUnsubscribeError,category:RedisClient.name}),!1}}async publish(e,t){if(!this.#i())return null;try{let n=await this.#e.publish(e,t);return n===0&&this.#t?.debug({message:`No subscribers found for channel ${e}`,category:RedisClient.name}),n}catch(t){let n=t;return this.#t?.error({message:`Error publishing to ${e}`,error:n,code:A.RedisClientPublishError,category:RedisClient.name}),null}}getClient(){return this.#i()?this.#e:null}isAvailable(){return this.#e.isReady&&this.#e.isOpen}#i(){let e=this.isAvailable();return e||this.#t?.error({message:`Redis Client is not ready.`,category:RedisClient.name,code:A.RedisClientRedisNotReady}),e}async listData({partialKey:e,limit:t,cursor:n}){try{let r=n?parseInt(n,10):0,i=await this.#e.sScan(e,r,{COUNT:t}),a=[];for(let e of i.members){let t=await this.getData(e);(0,o.notMissing)(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(e){let t=e;return this.#t?.error({message:`Error listing data`,error:t,code:A.RedisClientListError,category:RedisClient.name}),{items:null}}}async deleteData(e,t){try{if(!this.#i())return!1;let n=await this.#e.del(e);return n===0&&this.#t?.debug({message:`No keys deleted for ${e}`,category:RedisClient.name}),(0,o.notMissing)(t)&&t.length>0&&(await Promise.allSettled(t.map(t=>this.#e.sRem(t,e)))).forEach((e,n)=>{e.status===`rejected`&&this.#t?.error({message:`Error removing key from group set ${t[n]}`,error:e.reason,code:A.RedisClientDeleteError,category:RedisClient.name})}),n>0}catch(e){let t=e;return this.#t?.error({message:`Error deleting data`,error:t,code:A.RedisClientDeleteError,category:RedisClient.name}),!1}}};const addRedisEventHandlers=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},getDefaultRedisListeners=(e=`RedisClient`,t)=>[{eventName:`error`,listener:n=>{t?.error({message:`Redis client error ${n.message}`,error:n,code:A.RedisClientError,category:e})}},{eventName:`ready`,listener:()=>{t?.info({message:`Redis client ready`,category:e})}},{eventName:`connect`,listener:()=>{t?.info({message:`Redis client connected`,category:e})}},{eventName:`reconnecting`,listener:()=>{t?.info({message:`Redis client reconnecting`,category:e})}},{eventName:`end`,listener:()=>{t?.info({message:`Redis client disconnected`,category:e})}}];let te=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});const ne=1500;var ScriptManager=class extends AsyncSingleton{constructor(...e){super(...e),this.isInitialConnection=!0,this.reloadInProgress=null,this.lastReloadTime=0}async initInstance({redisClientConfig:e=this.redisClientConfig,cacheClient:t=this.cacheClient,scripts:n=this.scripts,scriptMap:r=this.scriptMap,logger:i=this.logger,additionalArgs:a=this.additionalArgs}){let s=t??await buildRedisClientInstance(e,i,this.name);if((0,o.isMissing)(s))throw Error(`Failed to build Redis client`);return this.redisClientConfig=e,this.logger=i,this.cacheClient=s,this.scripts=n,this.scriptMap=r??new Map,this.additionalArgs=a??[],await this.loadScripts(n,r),this.setupReconnectHandler(),await this.additionalInitialization(...a??[]),this}setupReconnectHandler(){let e=this.cacheClient?.getClient?.();(0,o.notMissing)(e)&&(e.on(`ready`,async()=>{this.isInitialConnection?this.isInitialConnection=!1:(this.logger?.info({message:`Redis reconnected - reloading scripts`,category:this.name}),await this.reloadScripts())}),e.on(`end`,()=>{this.logger?.info({message:`Redis connection closed`,category:this.name})}))}async reloadScripts(){if((0,o.notMissing)(this.reloadInProgress))return this.logger?.info({message:`Script reload already in progress, waiting for completion`,category:this.name}),this.reloadInProgress;if(!((0,o.isMissing)(this.scripts)||Object.keys(this.scripts).length===0)){this.reloadInProgress=this.performReload();try{await this.reloadInProgress}finally{this.reloadInProgress=null}}}async performReload(){this.logger?.info({message:`Reloading ${Object.keys(this.scripts).length} scripts after Redis reconnection`,category:this.name}),this.scriptMap.clear(),await this.loadScripts(this.scripts),this.lastReloadTime=Date.now()}async loadScripts(e,t){if((0,o.notMissing)(t))for(let[e,n]of t)this.scriptMap.set(e,n);let n=Object.entries(e),r=n.map(([e])=>this.scriptMap.get(e)).filter(o.notMissing),i=new Map;if(r.length>0&&(0,o.notMissing)(this.cacheClient?.scriptExists)){let e=await this.cacheClient.scriptExists(r);if((0,o.notMissing)(e)){r.forEach((t,n)=>{i.set(t,e[n]??!1)});let t=e.filter(Boolean).length;t>0&&this.logger?.info({message:`${t}/${r.length} scripts already exist in Redis; skipping load for existing scripts`,category:this.name})}}for(let[e,t]of n){let n=this.scriptMap.get(e);if(n&&i.get(n))continue;let r=await this.cacheClient?.loadScript?.(t);(0,o.notMissing)(r)?this.scriptMap?.set(e,r):this.logger?.error({message:`Error loading script ${e}`,category:this.name,code:te.ScriptManagerLoadingError})}}async executeScript(e,t,n){if(!this.isRedisReady())return this.logger?.warning({message:`Redis not ready, cannot execute script ${e}`,category:this.name,context:{keys:t,args:n}}),null;let r=this.scriptMap?.get(e);if((0,o.isMissing)(r))throw this.logger?.error({message:`Script for ${e} not found in script map`,category:this.name,code:te.ScriptManagerExecutionError}),Error(`Script for ${e} not found`);try{return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(i){if(i instanceof Error&&i.message.includes(`NOSCRIPT`)){let i=Date.now()-this.lastReloadTime;if(i<ne){let t=ne-i;this.logger?.info({message:`Script ${e} not found, reload occurred ${i}ms ago. Waiting ${t}ms before reloading`,category:this.name}),await(0,o.delay)(t)}if(this.logger?.info({message:`Script ${e} not found in Redis, reloading scripts`,category:this.name}),await this.reloadScripts(),r=this.scriptMap?.get(e),(0,o.isMissing)(r))throw Error(`Script for ${e} could not be reloaded`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}throw i instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${i.message}`,category:this.name,context:{keys:t,args:n},error:i,code:te.ScriptManagerExecutionError}),i}}isRedisReady(){let e=this.cacheClient?.getClient?.();if((0,o.notMissing)(this.cacheClient)&&(0,o.isMissing)(e))return this.logger?.warning({message:`Cache client exists but getClient() returned null - cannot verify Redis readiness`,category:this.name}),!1;let t=e?.isReady&&e?.isOpen;return this.isReady()&&(0,o.notMissing)(this.cacheClient)&&(t??!1)}},SubscriptionManager=class{constructor(e){this.options={getCacheClient:buildRedisClientInstance},this.subscriptionMap=null,this.subscriptionClient=null,this.name=`SubscriptionManager`,this.options={...this.options,...e}}async initialize(e=this.options){let{config:t,getCacheClient:n,logger:r}=e;if(this.logger=r,this.subscriptionMap=new MemoryStore({instantiator:`${e?.instantiator}(${this.name})`,evictionFrequency:e?.subscriptionTTL,staleDataThreshold:e?.staleSubscriptionsThreshold,truncateThreshold:e?.truncateThreshold,truncationPercentage:e?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),(0,o.notMissing)(t))this.subscriptionClient=await n?.(t,this.logger,e?.instantiator)??null,this.logger?.info({message:`${this.name} initialized for ${e.instantiator}.`,category:this.name});else throw Error(`SubscriptionManager requires a Redis client configuration.`)}async subscribe(e,t){this.isReady()||await this.initialize(this.options);let n=await this.subscriptionMap?.getData(e),r=(0,o.getContentHash)(t.toString());return await this.subscriptionMap?.setData({key:e,value:r}),n===r?!0:await this.subscriptionClient?.subscribe?.(e,t)??!1}async unsubscribe(e){return this.isReady()||await this.initialize(this.options),this.subscriptionClient?.unsubscribe?.(e)??!1}isReady(){return(0,o.notMissing)(this.subscriptionClient)&&(0,o.notMissing)(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const re=6e4,ie=15e3,ae=!1,oe=6e4,se=15e3,j=1e4,ce=1;let M=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),N=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});var QueueManager=class extends ScriptManager{constructor(...e){super(...e),this.subscriptionManager=null,this.eventClient=null,this.name=`QueueManager`}async additionalInitialization(){if((0,o.isMissing)(this.redisClientConfig))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.subscriptionManager=new SubscriptionManager({config:this.redisClientConfig,instantiator:this.name,subscriptionTTL:6e4,truncateThreshold:j,truncationPercentage:1}),await this.subscriptionManager?.initialize(),this.eventClient=new EventClient({instantiator:this.name,timeoutResolveValue:!1},{instantiator:this.name,evictionFrequency:se,truncateThreshold:j,truncationPercentage:1},{instantiator:this.name,evictionFrequency:se,truncateThreshold:j,truncationPercentage:1}),this.logger?.info({category:this.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(e,t,n,r,i=!0){try{let a=`${e}:${t}`;await this.subscriptionManager?.subscribe(a,async(n,r)=>{if(r.includes(a)&&r.includes(t)){let t=`${e}:${n}`;return this.eventClient?.resolveEvent(t,!0)}});let o=await this.executeScript(n?N.lPush:N.rPush,[e],[t,`60000`])===1;return(!i||!o)&&await this.eventClient?.waitForEvent(a,15e3),await this.eventClient?.deleteEvent(a),await r(e,t)}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:this.name,error:n,code:M.QueueManagerJoinAndWaitTurnError,context:{queueName:e,value:t}}),n}}async pop(e){try{return await this.executeScript(N.lPop,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in pop`,category:this.name,error:t,code:M.QueueManagerPopError,context:{queueName:e}}),t}}async length(e){try{return await this.executeScript(N.llen,[e],[])}catch(t){throw t instanceof Error&&this.logger?.error({message:`Error in length`,category:this.name,error:t,code:M.QueueManagerLengthError,context:{queueName:e}}),t}}isReady(){return(0,o.notMissing)(this.subscriptionManager)&&(0,o.notMissing)(this.cacheClient)&&(0,o.notMissing)(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.scriptMap?.clear()}};const le=5,ue=12e4,de=1e4,fe=1,pe=60,me=90,he=`__keyevent@0__:`,ge=`${he}set`,_e=`${he}expire`,P=`${he}expired`,ve=`${he}srem`,ye=`config_check_test_key`,be=[ge,_e,P],xe=1,Se=2e4,Ce={mainMaxConcurrency:30};let we=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e.ConcurrencyManagerPublishNextItemFailed=`ConcurrencyManagerPublishNextItemFailed`,e.ConcurrencyManagerReleaseRequestFailed=`ConcurrencyManagerReleaseRequestFailed`,e}({}),F=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const Te={[F.tryConcurrency]:`
|
|
2
2
|
local requestId = KEYS[1]
|
|
3
3
|
local targetKey = KEYS[2]
|
|
4
4
|
local queueKey = KEYS[3]
|
|
@@ -75,7 +75,7 @@ var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,co
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
return {success, failureReason}
|
|
78
|
-
`,[
|
|
78
|
+
`,[F.removeFromSet]:`
|
|
79
79
|
local requestId = ARGV[1]
|
|
80
80
|
local targetKey = KEYS[1]
|
|
81
81
|
|
|
@@ -84,7 +84,7 @@ var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,co
|
|
|
84
84
|
|
|
85
85
|
-- Remove the requestId from the targetKey set
|
|
86
86
|
return redis.call('SREM', targetKey, requestId)
|
|
87
|
-
`,[
|
|
87
|
+
`,[F.publishNextItem]:`
|
|
88
88
|
local queueKey = KEYS[1]
|
|
89
89
|
|
|
90
90
|
local nextItem = redis.call('lindex', queueKey, 0)
|
|
@@ -94,14 +94,14 @@ var e=Object.create,t=Object.defineProperty,__name=(e,n)=>t(e,`name`,{value:n,co
|
|
|
94
94
|
|
|
95
95
|
redis.call('publish', nextItemKey, nextItem)
|
|
96
96
|
end
|
|
97
|
-
`};var ConcurrencyManager=class extends ScriptManager{constructor(...e){super(...e),this.hasValidRedisConfig=!1,this.subscriptionManager=null,this.queueManager=null,this.name=`ConcurrencyManager`}async additionalInitialization(e,t){if(this.generateUUID=e??o.generateRequestId,this.subscriptionManager=new SubscriptionManager({config:this.redisClientConfig,logger:this.logger,instantiator:this.name,subscriptionTTL:12e4,truncateThreshold:1e4,truncationPercentage:1}),await this.subscriptionManager?.initialize(),t?.skipStartupCheck)this.hasValidRedisConfig=!0,this.logger?.info({category:this.name,message:`Skipping Redis startup check (skipStartupCheck enabled)`});else if(this.hasValidRedisConfig=await this.checkRedisEventsEmit(),!this.hasValidRedisConfig)throw Error(`Failed to validate Redis configuration for ConcurrencyManager`);if((0,o.isMissing)(this.getSingleton))throw Error(`getSingleton method not available`);this.queueManager=this.getSingleton?.(QueueManager)}async addTestSubscription(e,t,n,r){return(0,o.isMissing)(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(e,async(i,a)=>{a===e&&i.includes(t)&&(n.push(a),n.includes(ve)&&n.includes(ye)&&n.includes(M)&&(r(),n.length=0))})}async checkRedisEventsEmit(){let e=[],t=Date.now(),checkHandler=async(n,r)=>{let checkCallback=()=>{let r=Date.now()-t;this.logger?.info({category:this.name,message:`All Redis events received successfully.`,context:{receivedEventCount:e.length,elapsedTimeMs:r}}),n(!0)},i=`config_check_test_key:${this.generateUUID()}`;if(!(await Promise.all(Se.map(async t=>this.addTestSubscription(t,i,e,checkCallback)))).every(Boolean))return r(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:i,value:`test`,cacheTTL:1}),setTimeout(()=>{let e=Date.now()-t;r(Error(`Timeout waiting for Redis events to emit after ${e}ms.`))},2e4)};try{return await new Promise(checkHandler)}catch(n){let r=Date.now()-t;return this.logger?.error({category:this.name,message:`Redis events failed to emit.`,context:{receivedEventCount:e.length,elapsedTimeMs:r,reason:n?.message},error:n,code:N.ConcurrencyManagerRedisEventsEmitError}),!1}}isRedisConfigured(){return this.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){return await this.subscriptionManager?.subscribe(M,async(n,r)=>{if(r===M&&n.includes(t)&&n.includes(e))try{await this.releaseRequest(e,t)}catch(n){this.logger?.error({message:`Failed to release request on lease expiry - Redis may not be ready`,category:this.name,context:{requestId:e,targetConcurrencyKey:t},error:n,code:N.ConcurrencyManagerReleaseRequestFailed})}})??!1}async subscribeToSetRemoval(e,t){return await this.subscriptionManager?.subscribe(be,async(n,r)=>{if(r===be&&n.includes(e))try{await this.executeScript(P.publishNextItem,[t],[])}catch(n){this.logger?.error({message:`Failed to publish next item from queue - Redis may not be ready`,category:this.name,context:{queueKey:t,targetConcurrencyKey:e},error:n,code:N.ConcurrencyManagerPublishNextItemFailed})}})??!1}async registerRequest(e,t,n,r){let i=`concurrency:${e}`,a=`queue:${e}`,s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(r??``):r?.includes(e.urlPattern))?.subPoolKey,c=(0,o.notMissing)(s)?`${i}-${s}`:i,{mainMaxConcurrency:l,subPools:u}=t,d=[{key:i,maxConcurrency:l},...u?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${i}-${t}`,maxConcurrency:n}})??[]],f=d.map(e=>e.key),p=d.map(e=>e.maxConcurrency),[m,h]=await Promise.all([this.subscribeToLeaseExpiry(n,c),this.subscribeToSetRemoval(c,a)]),g={requestId:n,targetConcurrencyKey:c,leaseSubscription:m,setRemovalSubscription:h,queueKey:a},_=await this.executeScript(P.tryConcurrency,[n,c,a,...f],[`60`,l.toString(),`90`,...p.map(String)]);if((0,o.notMissing)(_)&&_[0])return{...g,joinCondition:`optimistic`,failureReason:_[1]};let v=0,y=[];for(;v<5;){let e=v>1,t=await this.queueManager?.joinAndWaitTurn(a,n,e,async(e,t)=>await this.executeScript(P.tryConcurrency,[n,c,a,...f],[`60`,l.toString(),`90`,...p.map(String)]),!1),r=(0,o.notMissing)(t)?t[0]:!1,i=(0,o.notMissing)(t)?t[1]:``;if((0,o.notMissing)(i)&&i!==``&&y.push(i),v++,r)return v>1&&this.logger?.warning({category:this.name,message:`Register request succeeded after ${v} attempts.`,context:{...g,registerAttempts:v,joinCondition:`attempts`,failureMessages:y}}),{...g,joinCondition:`attempts`};await(0,o.delay)((0,o.exponentialBackoffInMS)(v,100))}return this.logger?.error({category:this.name,message:`Failed to register request after ${v} attempts.`,context:{...g,registerAttempts:v,joinCondition:`failed`,failureMessages:y},code:N.ConcurrencyManagerRegistrationFailed}),{...g,joinCondition:`failed`}}async releaseRequest(e,t){return(0,o.isString)(t)&&(0,o.isString)(e)?!!await this.executeScript(P.removeFromSet,[t],[e]):!1}isReady(){return this.subscriptionManager!==null&&this.cacheClient!==null&&this.scriptMap!==null&&this.scriptMap.size>0&&this.hasValidRedisConfig}close(){this.subscriptionManager?.close(),this.queueManager?.close(),this.scriptMap?.clear(),this.hasValidRedisConfig=!1}};const De={100:`Continue`,101:`Switching Protocols`,102:`Processing`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,499:`Client Closed Request`,500:`Internal server error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,510:`Not Extended`,511:`Network Authentication Required`},translateCustomError=(e,t)=>{if((0,o.isMissing)(t)||t?.length===0||(0,o.isMissing)(e))return{data:e.data,status:e.status,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,message:e.message};let n=t?.filter(t=>t.receivedStatus===e.status);if(n?.length)for(let t of n){let n=t.condition,r=(0,c.safeEvaluate)(n,e)===!0;if((0,o.isMissing)(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??De[t.targetStatus]??`Unknown error`}}return e},Oe=(0,o.zStrictObject)({receivedStatus:o.z.number(),targetStatus:o.z.number(),message:o.z.string().optional(),condition:o.z.string().optional()});var F=class HttpResponseError extends Error{constructor(e,t){super(t),this.name=`HttpResponseError`,this.response=e,this.message=t??`HTTP error: ${e.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,HttpResponseError)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}};const isHttpResponseError=e=>e instanceof Error&&e.name===`HttpResponseError`&&`response`in e&&typeof e.response==`object`&&e.response!==null,safeSerialize=(e,t=new WeakSet)=>{if(typeof e!=`object`||!e)return typeof e==`bigint`?e.toString():e;if(t.has(e))return`[Circular Reference]`;if(e instanceof Date)return e.toISOString();if(Array.isArray(e)){t.add(e);let n=e.map(e=>safeSerialize(e,t));return t.delete(e),n}let n=e,r={};t.add(n);for(let[e,i]of Object.entries(n))r[e]=safeSerialize(i,t);return t.delete(n),r},serializeHttpResponseError=e=>{if(isHttpResponseError(e)){let t=e.response;return{name:e.name,message:e.message,stack:e.stack,response:safeSerialize(t)}}return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:{error:String(e)}};var HttpTransportFactory=class{static createInstance({interceptors:e,instanceConfig:t,httpsAgentConfig:n,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s}){let c=new u.default.Agent(n),d=l.default.create({...t,httpsAgent:c});if(e){let t={axiosInstance:d,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s};this.applyInterceptors(d,e,t)}return d}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t;[{type:`request`,configs:r},{type:`response`,configs:i}].forEach(t=>{let{configs:r,type:i}=t;r.forEach(t=>{let{onFulfilled:r,onRejected:a,options:o}=t;if(i===`request`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n),o];e.interceptors.request.use(...t)}if(i===`response`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n)];e.interceptors.response.use(...t)}})})}static resolveInterceptorInstance(e,t){return(0,o.notMissing)(e)&&(0,o.isFunction)(e)&&typeof e(t)==`function`?e(t):e??null}};const ke=300,Ae=3600*24*7*1e3,je=100;var Me=class InstanceManager{static{this.instance=null}static{this.logger=null}constructor(e={}){this.dataStore=null,this.options=e,this.initialize()}static getInstance(e={}){return(0,o.isMissing)(InstanceManager.instance)&&(InstanceManager.instance=new InstanceManager(e)),InstanceManager.instance}initialize(){let{logger:e,staleDataThreshold:t,truncateThreshold:n}=this.options;this.dataStore=new MemoryStore({instantiator:InstanceManager.name,logger:e,staleDataThreshold:t,truncateThreshold:n,typeGuard:e=>(0,o.notMissing)(e)}),InstanceManager.logger=e??null,InstanceManager.logger?.info({category:InstanceManager.name,message:`InstanceManager initialized.`})}async get(e){return this.ensureReady(),await InstanceManager.getInstance().dataStore?.getData(e)??null}async set(e,t,n){return this.ensureReady(),await InstanceManager.getInstance().dataStore?.setData({key:e,value:t,cacheTTL:(0,o.notMissing)(n)?n:300})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return(0,o.notMissing)(this?.dataStore)}close(){let e=this.dataStore;InstanceManager.instance=null,this.dataStore=null,e?.close?.()}};const Ne=Me.getInstance({staleDataThreshold:6048e5,truncateThreshold:100}),abortErrorInterceptor=()=>__name(e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)},`abortErrorInterceptor`),Pe=7.5,Fe={mainRatelimit:25};let Ie=function(e){return e.incr=`incr`,e}({}),I=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e.RateLimitOrConcurrencyManagerNotInitialized=`RateLimitOrConcurrencyManagerNotInitialized`,e.InterceptorContextNotPresent=`InterceptorContextNotPresent`,e.InterceptorMaxWaitTimeExceeded=`InterceptorMaxWaitTimeExceeded`,e}({});const createAxiosError=(e,t,n,r)=>{let i=Error(e);return i.config={...t,headers:{}},i.code=n,i.response=r,i.isAxiosError=!0,i},abortableDelay=(e,t,n)=>{let r=t.signal;return r?r.aborted?Promise.reject(createAxiosError(`Request aborted`,t,`ERR_CANCELED`,n)):new Promise((i,a)=>{let o=!1,s,c=createAxiosError(`Request aborted`,t,`ERR_CANCELED`,n),cleanup=()=>{if(!o){o=!0,s&&(0,f.clearTimeout)(s);try{r.removeEventListener?.(`abort`,onAbort)}catch{}}},onAbort=()=>{cleanup(),a(c)},onTimeout=()=>{cleanup(),i()};try{r.addEventListener?.(`abort`,onAbort,{once:!0})}catch{s=setTimeout(()=>{i()},e);return}if(r.aborted){cleanup(),a(c);return}s=setTimeout(onTimeout,e)}):new Promise(t=>setTimeout(t,e))},Le=`checkConcurrencyInterceptor`,checkConcurrencyInterceptor=({logger:e,context:t,requestConfig:n,concurrencyManager:r,rateLimitManager:i})=>__name(async a=>{if(a.signal?.aborted)return Promise.reject(createAxiosError(`Request aborted`,a,`ERR_CANCELED`));if((0,o.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this request - that doesn't seem right.`,context:{interceptor:Le,...a,httpsAgent:void 0,headers:void 0,hasContext:(0,o.notMissing)(t),hasConfig:(0,o.notMissing)(a)},code:I.InterceptorContextNotPresent});else if((0,o.isMissing)(i)||(0,o.isMissing)(r))e?.error({category:`HttpClient`,message:`RateLimitManager or ConcurrencyManager is not initialized`,context:{interceptor:Le,...a,httpsAgent:void 0,headers:void 0,rateLimitManagerInitialized:(0,o.notMissing)(i),concurrencyManagerInitialized:(0,o.notMissing)(r)},code:I.RateLimitOrConcurrencyManagerNotInitialized});else if((0,o.notMissing)(t.provider)&&(0,o.notMissing)(t.accountSecureId)){let o=(0,d.randomUUID)(),{provider:s,accountSecureId:c}=t,l=n?.rateLimits??Fe,u=n?.concurrency??Te,f=await i.getDynamicMaxWaitTime(l,u,a.url),register=async()=>r.registerRequest(`${c}-${s}`,u,o,a.url),p,m=0;for(;m<=f;){let n=Math.floor(Date.now()/1e3),r=await i.getWaitTime(`${c}-${s}`,l,a.url)??0,o=Math.max(r-n,0);if(r===0){p=await register();break}if(await abortableDelay(o*1e3,a),m+=o,m>=f){p=await register(),e?.warning({category:`HttpClient`,message:`Max Wait Time Exceeded for ${s} - Account: ${c}`,context:{...t,interceptor:Le,...a,httpsAgent:void 0,headers:void 0,dynamicMaxWaitTime:f},code:I.InterceptorMaxWaitTimeExceeded});break}}return{...a,requestMetadata:p}}return a},`checkConcurrencyInterceptor`),Re=1,ze=10,Be=5,Ve=3250368e4,L=1e3,He=/^\d+(\.\d+)?$/,Ue=1e3,adjustUnixTimestamp=e=>e<3250368e4?e*L:e;var We=__commonJSMin(((e,t)=>{function _extends(){return t.exports=_extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,_extends.apply(null,arguments)}t.exports=_extends,t.exports.__esModule=!0,t.exports.default=t.exports})),Ge={epsilon:1e-12,matrix:`Matrix`,number:`number`,precision:64,predictable:!1,randomSeed:null};function isNumber$1(e){return typeof e==`number`}__name(isNumber$1,`isNumber`);function isBigNumber(e){return!e||typeof e!=`object`||typeof e.constructor!=`function`?!1:e.isBigNumber===!0&&typeof e.constructor.prototype==`object`&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal==`function`&&e.constructor.isDecimal(e)===!0}function isComplex(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function isFraction(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function isUnit(e){return e&&e.constructor.prototype.isUnit===!0||!1}function isString$1(e){return typeof e==`string`}__name(isString$1,`isString`);var R=Array.isArray;function isMatrix(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function isCollection(e){return Array.isArray(e)||isMatrix(e)}function isDenseMatrix(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function isSparseMatrix(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function isRange(e){return e&&e.constructor.prototype.isRange===!0||!1}function isIndex(e){return e&&e.constructor.prototype.isIndex===!0||!1}function isBoolean(e){return typeof e==`boolean`}function isResultSet(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function isHelp(e){return e&&e.constructor.prototype.isHelp===!0||!1}function isFunction(e){return typeof e==`function`}function isDate(e){return e instanceof Date}function isRegExp(e){return e instanceof RegExp}function isObject$2(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!isComplex(e)&&!isFraction(e))}__name(isObject$2,`isObject`);function isNull(e){return e===null}function isUndefined(e){return e===void 0}function isAccessorNode(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function isArrayNode(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function isAssignmentNode(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function isBlockNode(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function isConditionalNode(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function isConstantNode(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function isFunctionAssignmentNode(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function isFunctionNode(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function isIndexNode(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function isNode(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function isObjectNode(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function isOperatorNode(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function isParenthesisNode(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function isRangeNode(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function isRelationalNode(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function isSymbolNode(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function isChain(e){return e&&e.constructor.prototype.isChain===!0||!1}function typeOf(e){var t=typeof e;return t===`object`?e===null?`null`:isBigNumber(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function clone$2(e){var t=typeof e;if(t===`number`||t===`string`||t===`boolean`||e==null)return e;if(typeof e.clone==`function`)return e.clone();if(Array.isArray(e))return e.map(function(e){return clone$2(e)});if(e instanceof Date)return new Date(e.valueOf());if(isBigNumber(e))return e;if(isObject$2(e))return mapObject(e,clone$2);throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}__name(clone$2,`clone`);function mapObject(e,t){var n={};for(var r in e)hasOwnProperty(e,r)&&(n[r]=t(e[r]));return n}function deepStrictEqual(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!deepStrictEqual(e[r],t[r]))return!1;return!0}else if(typeof e==`function`)return e===t;else if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!deepStrictEqual(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function hasOwnProperty(e,t){return e&&Object.hasOwnProperty.call(e,t)}function pickShallow(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],a=e[i];a!==void 0&&(n[i]=a)}return n}var Ke=[`Matrix`,`Array`],qe=[`number`,`BigNumber`,`Fraction`],Je=__toESM(We(),1),Ye=__name(function config$2(e){if(e)throw Error(`The global config is readonly.
|
|
97
|
+
`};var ConcurrencyManager=class extends ScriptManager{constructor(...e){super(...e),this.hasValidRedisConfig=!1,this.subscriptionManager=null,this.queueManager=null,this.name=`ConcurrencyManager`}async additionalInitialization(e,t){if(this.generateUUID=e??o.generateRequestId,this.subscriptionManager=new SubscriptionManager({config:this.redisClientConfig,logger:this.logger,instantiator:this.name,subscriptionTTL:12e4,truncateThreshold:1e4,truncationPercentage:1}),await this.subscriptionManager?.initialize(),t?.skipStartupCheck)this.hasValidRedisConfig=!0,this.logger?.info({category:this.name,message:`Skipping Redis startup check (skipStartupCheck enabled)`});else if(this.hasValidRedisConfig=await this.checkRedisEventsEmit(),!this.hasValidRedisConfig)throw Error(`Failed to validate Redis configuration for ConcurrencyManager`);if((0,o.isMissing)(this.getSingleton))throw Error(`getSingleton method not available`);this.queueManager=this.getSingleton?.(QueueManager)}async addTestSubscription(e,t,n,r){return(0,o.isMissing)(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(e,async(i,a)=>{a===e&&i.includes(t)&&(n.push(a),n.includes(ge)&&n.includes(_e)&&n.includes(P)&&(r(),n.length=0))})}async checkRedisEventsEmit(){let e=[],t=Date.now(),checkHandler=async(n,r)=>{let checkCallback=()=>{let r=Date.now()-t;this.logger?.info({category:this.name,message:`All Redis events received successfully.`,context:{receivedEventCount:e.length,elapsedTimeMs:r}}),n(!0)},i=`config_check_test_key:${this.generateUUID()}`;if(!(await Promise.all(be.map(async t=>this.addTestSubscription(t,i,e,checkCallback)))).every(Boolean))return r(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:i,value:`test`,cacheTTL:1}),setTimeout(()=>{let e=Date.now()-t;r(Error(`Timeout waiting for Redis events to emit after ${e}ms.`))},2e4)};try{return await new Promise(checkHandler)}catch(n){let r=Date.now()-t;return this.logger?.error({category:this.name,message:`Redis events failed to emit.`,context:{receivedEventCount:e.length,elapsedTimeMs:r,reason:n?.message},error:n,code:we.ConcurrencyManagerRedisEventsEmitError}),!1}}isRedisConfigured(){return this.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){return await this.subscriptionManager?.subscribe(P,async(n,r)=>{if(r===P&&n.includes(t)&&n.includes(e))try{await this.releaseRequest(e,t)}catch(n){this.logger?.error({message:`Failed to release request on lease expiry - Redis may not be ready`,category:this.name,context:{requestId:e,targetConcurrencyKey:t},error:n,code:we.ConcurrencyManagerReleaseRequestFailed})}})??!1}async subscribeToSetRemoval(e,t){return await this.subscriptionManager?.subscribe(ve,async(n,r)=>{if(r===ve&&n.includes(e))try{await this.executeScript(F.publishNextItem,[t],[])}catch(n){this.logger?.error({message:`Failed to publish next item from queue - Redis may not be ready`,category:this.name,context:{queueKey:t,targetConcurrencyKey:e},error:n,code:we.ConcurrencyManagerPublishNextItemFailed})}})??!1}async registerRequest(e,t,n,r){let i=`concurrency:${e}`,a=`queue:${e}`,s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(r??``):r?.includes(e.urlPattern))?.subPoolKey,c=(0,o.notMissing)(s)?`${i}-${s}`:i,{mainMaxConcurrency:l,subPools:u}=t,d=[{key:i,maxConcurrency:l},...u?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${i}-${t}`,maxConcurrency:n}})??[]],f=d.map(e=>e.key),p=d.map(e=>e.maxConcurrency),[m,h]=await Promise.all([this.subscribeToLeaseExpiry(n,c),this.subscribeToSetRemoval(c,a)]),g={requestId:n,targetConcurrencyKey:c,leaseSubscription:m,setRemovalSubscription:h,queueKey:a},_=await this.executeScript(F.tryConcurrency,[n,c,a,...f],[`60`,l.toString(),`90`,...p.map(String)]);if((0,o.notMissing)(_)&&_[0])return{...g,joinCondition:`optimistic`,failureReason:_[1]};let v=0,y=[];for(;v<5;){let e=v>1,t=await this.queueManager?.joinAndWaitTurn(a,n,e,async(e,t)=>await this.executeScript(F.tryConcurrency,[n,c,a,...f],[`60`,l.toString(),`90`,...p.map(String)]),!1),r=(0,o.notMissing)(t)?t[0]:!1,i=(0,o.notMissing)(t)?t[1]:``;if((0,o.notMissing)(i)&&i!==``&&y.push(i),v++,r)return v>1&&this.logger?.warning({category:this.name,message:`Register request succeeded after ${v} attempts.`,context:{...g,registerAttempts:v,joinCondition:`attempts`,failureMessages:y}}),{...g,joinCondition:`attempts`};await(0,o.delay)((0,o.exponentialBackoffInMS)(v,100))}return this.logger?.error({category:this.name,message:`Failed to register request after ${v} attempts.`,context:{...g,registerAttempts:v,joinCondition:`failed`,failureMessages:y},code:we.ConcurrencyManagerRegistrationFailed}),{...g,joinCondition:`failed`}}async releaseRequest(e,t){return(0,o.isString)(t)&&(0,o.isString)(e)?!!await this.executeScript(F.removeFromSet,[t],[e]):!1}isReady(){return this.subscriptionManager!==null&&this.cacheClient!==null&&this.scriptMap!==null&&this.scriptMap.size>0&&this.hasValidRedisConfig}close(){this.subscriptionManager?.close(),this.queueManager?.close(),this.scriptMap?.clear(),this.hasValidRedisConfig=!1}};const Ee={100:`Continue`,101:`Switching Protocols`,102:`Processing`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,499:`Client Closed Request`,500:`Internal server error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,510:`Not Extended`,511:`Network Authentication Required`},translateCustomError=(e,t)=>{if((0,o.isMissing)(t)||t?.length===0||(0,o.isMissing)(e))return{data:e.data,status:e.status,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,message:e.message};let n=t?.filter(t=>t.receivedStatus===e.status);if(n?.length)for(let t of n){let n=t.condition,r=(0,c.safeEvaluate)(n,e)===!0;if((0,o.isMissing)(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??Ee[t.targetStatus]??`Unknown error`}}return e},De=(0,o.zStrictObject)({receivedStatus:o.z.number(),targetStatus:o.z.number(),message:o.z.string().optional(),condition:o.z.string().optional()});var Oe=class HttpResponseError extends Error{constructor(e,t){super(t),this.name=`HttpResponseError`,this.response=e,this.message=t??`HTTP error: ${e.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,HttpResponseError)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}};const isHttpResponseError=e=>e instanceof Error&&e.name===`HttpResponseError`&&`response`in e&&typeof e.response==`object`&&e.response!==null,safeSerialize=(e,t=new WeakSet)=>{if(typeof e!=`object`||!e)return typeof e==`bigint`?e.toString():e;if(t.has(e))return`[Circular Reference]`;if(e instanceof Date)return e.toISOString();if(Array.isArray(e)){t.add(e);let n=e.map(e=>safeSerialize(e,t));return t.delete(e),n}let n=e,r={};t.add(n);for(let[e,i]of Object.entries(n))r[e]=safeSerialize(i,t);return t.delete(n),r},serializeHttpResponseError=e=>{if(isHttpResponseError(e)){let t=e.response;return{name:e.name,message:e.message,stack:e.stack,response:safeSerialize(t)}}return e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:{error:String(e)}};var HttpTransportFactory=class{static createInstance({interceptors:e,instanceConfig:t,httpsAgentConfig:n,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s}){let c=new u.default.Agent(n),d=l.default.create({...t,httpsAgent:c});if(e){let t={axiosInstance:d,logger:r,context:i,requestConfig:a,concurrencyManager:o,rateLimitManager:s};this.applyInterceptors(d,e,t)}return d}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t;[{type:`request`,configs:r},{type:`response`,configs:i}].forEach(t=>{let{configs:r,type:i}=t;r.forEach(t=>{let{onFulfilled:r,onRejected:a,options:o}=t;if(i===`request`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n),o];e.interceptors.request.use(...t)}if(i===`response`){let t=[this.resolveInterceptorInstance(r,n),this.resolveInterceptorInstance(a,n)];e.interceptors.response.use(...t)}})})}static resolveInterceptorInstance(e,t){return(0,o.notMissing)(e)&&(0,o.isFunction)(e)&&typeof e(t)==`function`?e(t):e??null}};const ke=300,Ae=3600*24*7*1e3,je=100;var Me=class InstanceManager{static{this.instance=null}static{this.logger=null}constructor(e={}){this.dataStore=null,this.options=e,this.initialize()}static getInstance(e={}){return(0,o.isMissing)(InstanceManager.instance)&&(InstanceManager.instance=new InstanceManager(e)),InstanceManager.instance}initialize(){let{logger:e,staleDataThreshold:t,truncateThreshold:n}=this.options;this.dataStore=new MemoryStore({instantiator:InstanceManager.name,logger:e,staleDataThreshold:t,truncateThreshold:n,typeGuard:e=>(0,o.notMissing)(e)}),InstanceManager.logger=e??null,InstanceManager.logger?.info({category:InstanceManager.name,message:`InstanceManager initialized.`})}async get(e){return this.ensureReady(),await InstanceManager.getInstance().dataStore?.getData(e)??null}async set(e,t,n){return this.ensureReady(),await InstanceManager.getInstance().dataStore?.setData({key:e,value:t,cacheTTL:(0,o.notMissing)(n)?n:300})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return(0,o.notMissing)(this?.dataStore)}close(){let e=this.dataStore;InstanceManager.instance=null,this.dataStore=null,e?.close?.()}};const Ne=Me.getInstance({staleDataThreshold:6048e5,truncateThreshold:100}),abortErrorInterceptor=()=>__name(e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)},`abortErrorInterceptor`),Pe=7.5,Fe={mainRatelimit:25};let Ie=function(e){return e.incr=`incr`,e}({}),I=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e.RateLimitOrConcurrencyManagerNotInitialized=`RateLimitOrConcurrencyManagerNotInitialized`,e.InterceptorContextNotPresent=`InterceptorContextNotPresent`,e.InterceptorMaxWaitTimeExceeded=`InterceptorMaxWaitTimeExceeded`,e}({});const createAxiosError=(e,t,n,r)=>{let i=Error(e);return i.config={...t,headers:{}},i.code=n,i.response=r,i.isAxiosError=!0,i},abortableDelay=(e,t,n)=>{let r=t.signal;return r?r.aborted?Promise.reject(createAxiosError(`Request aborted`,t,`ERR_CANCELED`,n)):new Promise((i,a)=>{let o=!1,s,c=createAxiosError(`Request aborted`,t,`ERR_CANCELED`,n),cleanup=()=>{if(!o){o=!0,s&&(0,f.clearTimeout)(s);try{r.removeEventListener?.(`abort`,onAbort)}catch{}}},onAbort=()=>{cleanup(),a(c)},onTimeout=()=>{cleanup(),i()};try{r.addEventListener?.(`abort`,onAbort,{once:!0})}catch{s=setTimeout(()=>{i()},e);return}if(r.aborted){cleanup(),a(c);return}s=setTimeout(onTimeout,e)}):new Promise(t=>setTimeout(t,e))},Le=`checkConcurrencyInterceptor`,checkConcurrencyInterceptor=({logger:e,context:t,requestConfig:n,concurrencyManager:r,rateLimitManager:i})=>__name(async a=>{if(a.signal?.aborted)return Promise.reject(createAxiosError(`Request aborted`,a,`ERR_CANCELED`));if((0,o.isMissing)(t))e?.warning({category:`HttpClient`,message:`No context for this request - that doesn't seem right.`,context:{interceptor:Le,...a,httpsAgent:void 0,headers:void 0,hasContext:(0,o.notMissing)(t),hasConfig:(0,o.notMissing)(a)},code:I.InterceptorContextNotPresent});else if((0,o.isMissing)(i)||(0,o.isMissing)(r))e?.error({category:`HttpClient`,message:`RateLimitManager or ConcurrencyManager is not initialized`,context:{interceptor:Le,...a,httpsAgent:void 0,headers:void 0,rateLimitManagerInitialized:(0,o.notMissing)(i),concurrencyManagerInitialized:(0,o.notMissing)(r)},code:I.RateLimitOrConcurrencyManagerNotInitialized});else if((0,o.notMissing)(t.provider)&&(0,o.notMissing)(t.accountSecureId)){let o=(0,d.randomUUID)(),{provider:s,accountSecureId:c}=t,l=n?.rateLimits??Fe,u=n?.concurrency??Ce,f=await i.getDynamicMaxWaitTime(l,u,a.url),register=async()=>r.registerRequest(`${c}-${s}`,u,o,a.url),p,m=0;for(;m<=f;){let n=Math.floor(Date.now()/1e3),r=await i.getWaitTime(`${c}-${s}`,l,a.url)??0,o=Math.max(r-n,0);if(r===0){p=await register();break}if(await abortableDelay(o*1e3,a),m+=o,m>=f){p=await register(),e?.warning({category:`HttpClient`,message:`Max Wait Time Exceeded for ${s} - Account: ${c}`,context:{...t,interceptor:Le,...a,httpsAgent:void 0,headers:void 0,dynamicMaxWaitTime:f},code:I.InterceptorMaxWaitTimeExceeded});break}}return{...a,requestMetadata:p}}return a},`checkConcurrencyInterceptor`),Re=1,ze=10,Be=5,Ve=3250368e4,L=1e3,He=/^\d+(\.\d+)?$/,Ue=1e3,adjustUnixTimestamp=e=>e<3250368e4?e*L:e;var We=__commonJSMin(((e,t)=>{function _extends(){return t.exports=_extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,_extends.apply(null,arguments)}t.exports=_extends,t.exports.__esModule=!0,t.exports.default=t.exports})),Ge={epsilon:1e-12,matrix:`Matrix`,number:`number`,precision:64,predictable:!1,randomSeed:null};function isNumber$1(e){return typeof e==`number`}__name(isNumber$1,`isNumber`);function isBigNumber(e){return!e||typeof e!=`object`||typeof e.constructor!=`function`?!1:e.isBigNumber===!0&&typeof e.constructor.prototype==`object`&&e.constructor.prototype.isBigNumber===!0||typeof e.constructor.isDecimal==`function`&&e.constructor.isDecimal(e)===!0}function isComplex(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function isFraction(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function isUnit(e){return e&&e.constructor.prototype.isUnit===!0||!1}function isString$1(e){return typeof e==`string`}__name(isString$1,`isString`);var R=Array.isArray;function isMatrix(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function isCollection(e){return Array.isArray(e)||isMatrix(e)}function isDenseMatrix(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function isSparseMatrix(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function isRange(e){return e&&e.constructor.prototype.isRange===!0||!1}function isIndex(e){return e&&e.constructor.prototype.isIndex===!0||!1}function isBoolean(e){return typeof e==`boolean`}function isResultSet(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function isHelp(e){return e&&e.constructor.prototype.isHelp===!0||!1}function isFunction(e){return typeof e==`function`}function isDate(e){return e instanceof Date}function isRegExp(e){return e instanceof RegExp}function isObject$2(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!isComplex(e)&&!isFraction(e))}__name(isObject$2,`isObject`);function isNull(e){return e===null}function isUndefined(e){return e===void 0}function isAccessorNode(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function isArrayNode(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function isAssignmentNode(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function isBlockNode(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function isConditionalNode(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function isConstantNode(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function isFunctionAssignmentNode(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function isFunctionNode(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function isIndexNode(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function isNode(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function isObjectNode(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function isOperatorNode(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function isParenthesisNode(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function isRangeNode(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function isRelationalNode(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function isSymbolNode(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function isChain(e){return e&&e.constructor.prototype.isChain===!0||!1}function typeOf(e){var t=typeof e;return t===`object`?e===null?`null`:isBigNumber(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function clone$2(e){var t=typeof e;if(t===`number`||t===`string`||t===`boolean`||e==null)return e;if(typeof e.clone==`function`)return e.clone();if(Array.isArray(e))return e.map(function(e){return clone$2(e)});if(e instanceof Date)return new Date(e.valueOf());if(isBigNumber(e))return e;if(isObject$2(e))return mapObject(e,clone$2);throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}__name(clone$2,`clone`);function mapObject(e,t){var n={};for(var r in e)hasOwnProperty(e,r)&&(n[r]=t(e[r]));return n}function deepStrictEqual(e,t){var n,r,i;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(r=0,i=e.length;r<i;r++)if(!deepStrictEqual(e[r],t[r]))return!1;return!0}else if(typeof e==`function`)return e===t;else if(e instanceof Object){if(Array.isArray(t)||!(t instanceof Object))return!1;for(n in e)if(!(n in t)||!deepStrictEqual(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function hasOwnProperty(e,t){return e&&Object.hasOwnProperty.call(e,t)}function pickShallow(e,t){for(var n={},r=0;r<t.length;r++){var i=t[r],a=e[i];a!==void 0&&(n[i]=a)}return n}var Ke=[`Matrix`,`Array`],qe=[`number`,`BigNumber`,`Fraction`],Je=__toESM(We(),1),Ye=__name(function config$2(e){if(e)throw Error(`The global config is readonly.
|
|
98
98
|
Please create a mathjs instance if you want to change the default configuration.
|
|
99
99
|
Example:
|
|
100
100
|
|
|
101
101
|
import { create, all } from 'mathjs';
|
|
102
102
|
const mathjs = create(all);
|
|
103
103
|
mathjs.config({ number: 'BigNumber' });
|
|
104
|
-
`);return Object.freeze(Ge)},`config`);(0,Je.default)(Ye,Ge,{MATRIX_OPTIONS:Ke,NUMBER_OPTIONS:qe});var Xe=__commonJSMin(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.typed=r())})(e,(function(){"use strict";function ok(){return!0}function notOk(){return!1}function undef(){}let e=`Argument is not a typed-function.`;function create(){function isPlainObject$1(e){return typeof e==`object`&&!!e&&e.constructor===Object}__name(isPlainObject$1,`isPlainObject`);let t=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:isPlainObject$1},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],n={name:`any`,test:ok,isAny:!0},r,i,a=0,o={createCount:0};function findType(e){let t=r.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,a=e.toLowerCase(),o;for(o of i)if(o.toLowerCase()===a){n+=`. Did you mean "`+o+`" ?`;break}throw TypeError(n)}function addTypes(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?findType(t).index:i.length,a=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(r.has(i))throw TypeError(`Duplicate type name "`+i+`"`);a.push(i),r.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let o=i.slice(n);i=i.slice(0,n).concat(a).concat(o);for(let e=n+a.length;e<i.length;++e)r.get(i[e]).index=e}function clear(){r=new Map,i=[],a=0,addTypes([n],!1)}clear(),addTypes(t);function clearConversions(){let e;for(e of i)r.get(e).conversionsTo=[];a=0}function findTypeNames(e){let t=i.filter(t=>{let n=r.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function isTypedFunction(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function findSignature(t,n,r){if(!isTypedFunction(t))throw TypeError(e);let i=r&&r.exact,a=parseSignature(Array.isArray(n)?n.join(`,`):n),o=stringifyParams(a);if(!i||o in t.signatures){let e=t._typedFunctionData.signatureMap.get(o);if(e)return e}let s=a.length,c;if(i){c=[];let e;for(e in t.signatures)c.push(t._typedFunctionData.signatureMap.get(e))}else c=t._typedFunctionData.signatures;for(let e=0;e<s;++e){let t=a[e],n=[],r;for(r of c){let i=getParamAtIndex(r.params,e);if(!(!i||t.restParam&&!i.restParam)){if(!i.hasAny){let e=paramTypeSet(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}}if(c=n,c.length===0)break}let l;for(l of c)if(l.params.length<=s)return l;throw TypeError(`Signature not found (signature: `+(t.name||`unnamed`)+`(`+stringifyParams(a,`, `)+`))`)}function find(e,t,n){return findSignature(e,t,n).implementation}function convert(e,t){let n=findType(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++)if(findType(r[t].from).test(e))return r[t].convert(e);throw Error(`Cannot convert `+e+` to `+t)}function stringifyParams(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function parseParam(e){let t=e.indexOf(`...`)===0,n=(t?e.length>3?e.slice(3):`any`:e).split(`|`).map(e=>findType(e.trim())),r=!1,i=t?`...`:``;return{types:n.map(function(e){return r=e.isAny||r,i+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}}),name:i.slice(0,-1),hasAny:r,hasConversion:!1,restParam:t}}function expandParam(e){let t=availableConversions(e.types.map(e=>e.name)),n=e.hasAny,r=e.name,i=t.map(function(e){let t=findType(e.from);return n=t.isAny||n,r+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(i),name:r,hasAny:n,hasConversion:i.length>0,restParam:e.restParam}}function paramTypeSet(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function parseSignature(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=parseParam(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function hasRestParam(e){let t=last(e);return t?t.restParam:!1}function compileTest(e){if(!e||e.types.length===0)return ok;if(e.types.length===1)return findType(e.types[0].name).test;if(e.types.length===2){let t=findType(e.types[0].name).test,n=findType(e.types[1].name).test;return function or(e){return t(e)||n(e)}}else{let t=e.types.map(function(e){return findType(e.name).test});return function or(e){for(let n=0;n<t.length;n++)if(t[n](e))return!0;return!1}}}function compileTests(e){let t,n,r;if(hasRestParam(e)){t=initial(e).map(compileTest);let n=t.length,r=compileTest(last(e)),testRestParam=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function testArgs(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return testRestParam(e)&&e.length>=n+1}}else if(e.length===0)return function testArgs(e){return e.length===0};else if(e.length===1)return n=compileTest(e[0]),function testArgs(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=compileTest(e[0]),r=compileTest(e[1]),function testArgs(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(compileTest),function testArgs(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function getParamAtIndex(e,t){return t<e.length?e[t]:hasRestParam(e)?last(e):null}function getTypeSetAtIndex(e,t){let n=getParamAtIndex(e,t);return n?paramTypeSet(n):new Set}function isExactType(e){return e.conversion===null||e.conversion===void 0}function mergeExpectedParams(e,t){let n=new Set;return e.forEach(e=>{let r=getTypeSetAtIndex(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function createError(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=compileTest(getParamAtIndex(n.params,s));(s<n.params.length||hasRestParam(n.params))&&r(t[s])&&e.push(n)}),e.length===0){if(i=mergeExpectedParams(o,s),i.length>0){let e=findTypeNames(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return hasRestParam(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=mergeExpectedParams(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(findTypeNames(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function getLowestTypeIndex(e){let t=i.length+1;for(let n=0;n<e.types.length;n++)t=Math.min(t,e.types[n].typeIndex);return t}function getLowestConversionIndex(e){let t=a+1;for(let n=0;n<e.types.length;n++)isExactType(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function compareParams(e,t){if(e.hasAny){if(!t.hasAny)return .1}else if(t.hasAny)return-.1;if(e.restParam){if(!t.restParam)return .01}else if(t.restParam)return-.01;let n=getLowestTypeIndex(e)-getLowestTypeIndex(t);if(n<0)return-.001;if(n>0)return .001;let r=getLowestConversionIndex(e),i=getLowestConversionIndex(t);if(e.hasConversion){if(!t.hasConversion)return(1+r)*1e-6}else if(t.hasConversion)return-(1+i)*1e-6;let a=r-i;return a<0?-1e-7:a>0?1e-7:0}function compareSignatures(e,t){let n=e.params,r=t.params,i=last(n),a=last(r),o=hasRestParam(n),s=hasRestParam(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1e7}else if(s&&a.hasAny)return-1e7;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return(c-d)*1e6;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1e5}else if(s&&a.hasConversion)return-1e5;if(l!==f)return(l-f)*1e4;if(o){if(!s)return 1e3}else if(s)return-1e3;let p=(n.length-r.length)*(o?-100:100);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=compareParams(n[e],r[e]);m.push(t),h+=t}if(h!==0)return(h<0?-10:10)+h;let g,_=9,v=_/(m.length+1);for(g of m){if(g!==0)return(g<0?-_:_)+g;_-=v}return 0}function availableConversions(e){if(e.length===0)return[];let t=e.map(findType);if(e.length===1)return t[0].conversionsTo;let n=new Set(e),r=new Set;for(let e=0;e<t.length;++e)for(let i of t[e].conversionsTo)n.has(i.from)||r.add(i.from);let i=[];for(let e of r){let n=a+1,r=null;for(let i=0;i<t.length;++i)for(let a of t[i].conversionsTo)a.from===e&&a.index<n&&(n=a.index,r=a);i.push(r)}return i}function compileArgsPreprocessing(e,t){let n=t,r=``;if(e.some(e=>e.hasConversion)){let i=hasRestParam(e),a=e.map(compileArgConversion);r=a.map(e=>e.name).join(`;`),n=function convertArgs(){let e=[],n=i?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=a[t](arguments[t]);return i&&(e[n]=arguments[n].map(a[n])),t.apply(this,e)}}let i=n;if(hasRestParam(e)){let t=e.length-1;i=function preprocessRestParams(){return n.apply(this,slice(arguments,0,t).concat([slice(arguments,t)]))}}return r&&Object.defineProperty(i,`name`,{value:r}),i}function compileArgConversion(e){let t,n,r,i,a=[],o=[],s=``;e.types.forEach(function(e){e.conversion&&(s+=e.conversion.from+`~>`+e.conversion.to+`,`,a.push(findType(e.conversion.from).test),o.push(e.conversion.convert))}),s=s?s.slice(0,-1):`pass`;let convertor=e=>e;switch(o.length){case 0:break;case 1:t=a[0],r=o[0],convertor=function convertArg(e){return t(e)?r(e):e};break;case 2:t=a[0],n=a[1],r=o[0],i=o[1],convertor=function convertArg(e){return t(e)?r(e):n(e)?i(e):e};break;default:convertor=function convertArg(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}return Object.defineProperty(convertor,`name`,{value:s}),convertor}function splitParams(e){function _splitParams(e,t,n){if(t<e.length){let r=e[t],i=[];if(r.restParam){let e=r.types.filter(isExactType);e.length<r.types.length&&i.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),i.push(r)}else i=r.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return flatMap(i,function(r){return _splitParams(e,t+1,n.concat([r]))})}else return[n]}return _splitParams(e,0,[])}function conflicting(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=getTypeSetAtIndex(e,r),i=getTypeSetAtIndex(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=hasRestParam(e),o=hasRestParam(t);return a?o?r===i:i>=r:o?r>=i:r===i}function clearResolutions(e){return e.map(e=>isReferToSelf(e)?referToSelf(e.referToSelf.callback):isReferTo(e)?makeReferTo(e.referTo.references,e.referTo.callback):e)}function collectResolutions(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function resolveReferences(e,t,n){let r=clearResolutions(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(isReferToSelf(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(isReferTo(s)){let n=collectResolutions(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function validateDeprecatedThis(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function createTypedFunction(e,t){if(o.createCount++,Object.keys(t).length===0)throw SyntaxError(`No signatures provided`);o.warnAgainstDeprecatedThis&&validateDeprecatedThis(t);let n=[],r=[],i={},a=[],s;for(s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let e=parseSignature(s);if(!e)continue;n.forEach(function(t){if(conflicting(t,e))throw TypeError(`Conflicting signatures "`+stringifyParams(t)+`" and "`+stringifyParams(e)+`".`)}),n.push(e);let o=r.length;r.push(t[s]);let c=e.map(expandParam),l;for(l of splitParams(c)){let e=stringifyParams(l);a.push({params:l,name:e,fn:o}),l.every(e=>!e.hasConversion)&&(i[e]=o)}}a.sort(compareSignatures);let c=resolveReferences(r,i,theTypedFn),l;for(l in i)Object.prototype.hasOwnProperty.call(i,l)&&(i[l]=c[i[l]]);let u=[],d=new Map;for(l of a)d.has(l.name)||(l.fn=c[l.fn],u.push(l),d.set(l.name,l));let f=u[0]&&u[0].params.length<=2&&!hasRestParam(u[0].params),p=u[1]&&u[1].params.length<=2&&!hasRestParam(u[1].params),m=u[2]&&u[2].params.length<=2&&!hasRestParam(u[2].params),h=u[3]&&u[3].params.length<=2&&!hasRestParam(u[3].params),g=u[4]&&u[4].params.length<=2&&!hasRestParam(u[4].params),_=u[5]&&u[5].params.length<=2&&!hasRestParam(u[5].params),v=f&&p&&m&&h&&g&&_;for(let e=0;e<u.length;++e)u[e].test=compileTests(u[e].params);let y=f?compileTest(u[0].params[0]):notOk,b=p?compileTest(u[1].params[0]):notOk,x=m?compileTest(u[2].params[0]):notOk,S=h?compileTest(u[3].params[0]):notOk,C=g?compileTest(u[4].params[0]):notOk,w=_?compileTest(u[5].params[0]):notOk,T=f?compileTest(u[0].params[1]):notOk,E=p?compileTest(u[1].params[1]):notOk,ee=m?compileTest(u[2].params[1]):notOk,D=h?compileTest(u[3].params[1]):notOk,O=g?compileTest(u[4].params[1]):notOk,k=_?compileTest(u[5].params[1]):notOk;for(let e=0;e<u.length;++e)u[e].implementation=compileArgsPreprocessing(u[e].params,u[e].fn);let te=f?u[0].implementation:undef,ne=p?u[1].implementation:undef,re=m?u[2].implementation:undef,ie=h?u[3].implementation:undef,ae=g?u[4].implementation:undef,oe=_?u[5].implementation:undef,se=f?u[0].params.length:-1,ce=p?u[1].params.length:-1,le=m?u[2].params.length:-1,ue=h?u[3].params.length:-1,de=g?u[4].params.length:-1,A=_?u[5].params.length:-1,fe=v?6:0,pe=u.length,me=u.map(e=>e.test),he=u.map(e=>e.implementation),ge=function generic$1(){for(let e=fe;e<pe;e++)if(me[e](arguments))return he[e].apply(this,arguments);return o.onMismatch(e,arguments,u)};function theTypedFn(e,t){return arguments.length===se&&y(e)&&T(t)?te.apply(this,arguments):arguments.length===ce&&b(e)&&E(t)?ne.apply(this,arguments):arguments.length===le&&x(e)&&ee(t)?re.apply(this,arguments):arguments.length===ue&&S(e)&&D(t)?ie.apply(this,arguments):arguments.length===de&&C(e)&&O(t)?ae.apply(this,arguments):arguments.length===A&&w(e)&&k(t)?oe.apply(this,arguments):ge.apply(this,arguments)}try{Object.defineProperty(theTypedFn,`name`,{value:e})}catch{}return theTypedFn.signatures=i,theTypedFn._typedFunctionData={signatures:u,signatureMap:d},theTypedFn}function _onMismatch(e,t,n){throw createError(e,t,n)}function initial(e){return slice(e,0,e.length-1)}function last(e){return e[e.length-1]}function slice(e,t,n){return Array.prototype.slice.call(e,t,n)}function findInArray(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function flatMap(e,t){return Array.prototype.concat.apply([],e.map(t))}function referTo(){let e=initial(arguments).map(e=>stringifyParams(parseSignature(e))),t=last(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return makeReferTo(e,t)}function makeReferTo(e,t){return{referTo:{references:e,callback:t}}}function referToSelf(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function isReferTo(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function isReferToSelf(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function checkName(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function getObjectName(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(isTypedFunction(e[n])||typeof e[n].signature==`string`)&&(t=checkName(t,e[n].name));return t}function mergeSignatures(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let s=o;o=__name(function(e){let t=typeof e==`string`,n=t?1:0,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],a={},o;if(typeof n==`function`?(o=n.name,typeof n.signature==`string`?a[n.signature]=n:isTypedFunction(n)&&(a=n.signatures)):isPlainObject$1(n)&&(a=n,t||(o=getObjectName(n))),Object.keys(a).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=checkName(r,o)),mergeSignatures(i,a)}return createTypedFunction(r||``,i)},`typed`),o.create=create,o.createCount=s.createCount,o.onMismatch=_onMismatch,o.throwMismatchError=_onMismatch,o.createError=createError,o.clear=clear,o.clearConversions=clearConversions,o.addTypes=addTypes,o._findType=findType,o.referTo=referTo,o.referToSelf=referToSelf,o.convert=convert,o.findSignature=findSignature,o.find=find,o.isTypedFunction=isTypedFunction,o.warnAgainstDeprecatedThis=!0,o.addType=function(e,t){let n=`any`;t!==!1&&r.has(`Object`)&&(n=`Object`),o.addTypes([e],n)};function _validateConversion(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return o.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};_validateConversion(e);let n=findType(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)o.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,to:n.name,convert:e.convert,index:a++})},o.addConversions=function(e,t){e.forEach(e=>o.addConversion(e,t))},o.removeConversion=function(e){_validateConversion(e);let t=findType(e.to),n=findInArray(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},o.resolve=function(t,n){if(!isTypedFunction(t))throw TypeError(e);let r=t._typedFunctionData.signatures;for(let e=0;e<r.length;++e)if(r[e].test(n))return r[e];return null},o}return create()}))}));function isInteger(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function formatNumberToBase(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`}[t],i=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!isInteger(n))throw Error(`size must be an integer`);if(e>2**(n-1)-1||e<-(2**(n-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!isInteger(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),i=`i${n}`}var a=``;return e<0&&(e=-e,a=`-`),`${a}${r}${e.toString(t)}${i}`}function format$2(e,t){if(typeof t==`function`)return t(e);if(e===1/0)return`Infinity`;if(e===-1/0)return`-Infinity`;if(isNaN(e))return`NaN`;var n=`auto`,r,i;if(t&&(t.notation&&(n=t.notation),isNumber$1(t)?r=t:isNumber$1(t.precision)&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return toFixed$1(e,r);case`exponential`:return toExponential$1(e,r);case`engineering`:return toEngineering$1(e,r);case`bin`:return formatNumberToBase(e,2,i);case`oct`:return formatNumberToBase(e,8,i);case`hex`:return formatNumberToBase(e,16,i);case`auto`:return toPrecision(e,r,t&&t).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}__name(format$2,`format`);function splitNumber(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw SyntaxError(`Invalid number `+e);var n=t[1],r=t[2],i=parseFloat(t[4]||`0`),a=r.indexOf(`.`);i+=a===-1?r.length-1:a-1;var o=r.replace(`.`,``).replace(/^0*/,function(e){return i-=e.length,``}).replace(/0*$/,``).split(``).map(function(e){return parseInt(e)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function toEngineering$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=roundDigits(splitNumber(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(isNumber$1(t))for(;t>i.length||r-a+1>i.length;)i.push(0);else for(var o=Math.abs(r-a)-(i.length-1),s=0;s<o;s++)i.push(0);for(var c=Math.abs(r-a),l=1;c>0;)l++,c--;var u=i.slice(l).join(``),d=isNumber$1(t)&&u.length||u.match(/[1-9]/)?`.`+u:``,f=i.slice(0,l).join(``)+d+`e`+(r>=0?`+`:``)+a.toString();return n.sign+f}__name(toEngineering$1,`toEngineering`);function toFixed$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=splitNumber(e),r=typeof t==`number`?roundDigits(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(zeros(o-i.length))),a<0&&(i=zeros(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}__name(toFixed$1,`toFixed`);function toExponential$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=splitNumber(e),r=t?roundDigits(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(zeros(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}__name(toExponential$1,`toExponential`);function toPrecision(e,t,n){if(isNaN(e)||!isFinite(e))return String(e);var r=n&&n.lowerExp!==void 0?n.lowerExp:-3,i=n&&n.upperExp!==void 0?n.upperExp:5,a=splitNumber(e),o=t?roundDigits(a,t):a;if(o.exponent<r||o.exponent>=i)return toExponential$1(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(zeros(t-s.length))),s=s.concat(zeros(c-s.length+1+(s.length<t?t-s.length:0))),s=zeros(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function roundDigits(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t&&r.splice(t,r.length-t)[0]>=5){var i=t-1;for(r[i]++;r[i]===10;)r.pop(),i===0&&(r.unshift(0),n.exponent++,i++),i--,r[i]++}return n}function zeros(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function digits(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}var Ze=2**-52||2220446049250313e-31;function formatBigNumberToBase(e,t,n){var r=e.constructor,i=new r(2),a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!isInteger(n))throw Error(`size must be an integer`);if(e.greaterThan(i.pow(n-1).sub(1))||e.lessThan(i.pow(n-1).mul(-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!e.isInteger())throw Error(`Value must be an integer`);e.lessThan(0)&&(e=e.add(i.pow(n))),a=`i${n}`}switch(t){case 2:return`${e.toBinary()}${a}`;case 8:return`${e.toOctal()}${a}`;case 16:return`${e.toHexadecimal()}${a}`;default:throw Error(`Base ${t} not supported `)}}function format$1(e,t){if(typeof t==`function`)return t(e);if(!e.isFinite())return e.isNaN()?`NaN`:e.gt(0)?`Infinity`:`-Infinity`;var n=`auto`,r,i;if(t!==void 0&&(t.notation&&(n=t.notation),typeof t==`number`?r=t:t.precision!==void 0&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return toFixed(e,r);case`exponential`:return toExponential(e,r);case`engineering`:return toEngineering(e,r);case`bin`:return formatBigNumberToBase(e,2,i);case`oct`:return formatBigNumberToBase(e,8,i);case`hex`:return formatBigNumberToBase(e,16,i);case`auto`:var a=t&&t.lowerExp!==void 0?t.lowerExp:-3,o=t&&t.upperExp!==void 0?t.upperExp:5;if(e.isZero())return`0`;var s,c=e.toSignificantDigits(r),l=c.e;return s=l>=a&&l<o?c.toFixed():toExponential(e,r),s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}__name(format$1,`format`);function toEngineering(e,t){var n=e.e,r=n%3==0?n:n<0?n-3-n%3:n-n%3,i=e.mul(10**-r).toPrecision(t);if(i.indexOf(`e`)!==-1){var a=e.constructor;i=new a(i).toFixed()}return i+`e`+(n>=0?`+`:``)+r.toString()}function toExponential(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function toFixed(e,t){return e.toFixed(t)}function format(e,t){var n=_format(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function _format(e,t){return typeof e==`number`?format$2(e,t):isBigNumber(e)?format$1(e,t):looksLikeFraction(e)?!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString():Array.isArray(e)?formatArray(e,t):isString$1(e)?stringify(e):typeof e==`function`?e.syntax?String(e.syntax):`function`:e&&typeof e==`object`?typeof e.format==`function`?e.format(t):e&&e.toString(t)!=={}.toString()?e.toString(t):`{`+Object.keys(e).map(n=>stringify(n)+`: `+format(e[n],t)).join(`, `)+`}`:String(e)}function stringify(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Qe?Qe[i]:i,r++}return`"`+n+`"`}var Qe={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function formatArray(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=formatArray(e[i],t);return n+=`]`,n}else return format(e,t)}function looksLikeFraction(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function DimensionError(e,t,n){if(!(this instanceof DimensionError))throw SyntaxError(`Constructor must be called with the new operator`);this.actual=e,this.expected=t,this.relation=n,this.message=`Dimension mismatch (`+(Array.isArray(e)?`[`+e.join(`, `)+`]`:e)+` `+(this.relation||`!=`)+` `+(Array.isArray(t)?`[`+t.join(`, `)+`]`:t)+`)`,this.stack=Error().stack}DimensionError.prototype=RangeError(),DimensionError.prototype.constructor=RangeError,DimensionError.prototype.name=`DimensionError`,DimensionError.prototype.isDimensionError=!0;function IndexError(e,t,n){if(!(this instanceof IndexError))throw SyntaxError(`Constructor must be called with the new operator`);this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.min!==void 0&&this.index<this.min?this.message=`Index out of range (`+this.index+` < `+this.min+`)`:this.max!==void 0&&this.index>=this.max?this.message=`Index out of range (`+this.index+` > `+(this.max-1)+`)`:this.message=`Index out of range (`+this.index+`)`,this.stack=Error().stack}IndexError.prototype=RangeError(),IndexError.prototype.constructor=RangeError,IndexError.prototype.name=`IndexError`,IndexError.prototype.isIndexError=!0;function arraySize(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function _validate(e,t,n){var r,i=e.length;if(i!==t[n])throw new DimensionError(i,t[n]);if(n<t.length-1){var a=n+1;for(r=0;r<i;r++){var o=e[r];if(!Array.isArray(o))throw new DimensionError(t.length-1,t.length,`<`);_validate(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new DimensionError(t.length+1,t.length,`>`)}function validate(e,t){if(t.length===0){if(Array.isArray(e))throw new DimensionError(e.length,0)}else _validate(e,t,0)}function validateIndex(e,t){if(e!==void 0){if(!isNumber$1(e)||!isInteger(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new IndexError(e,t)}}function resize(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);return t.forEach(function(e){if(!isNumber$1(e)||!isInteger(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+format(t)+`)`)}),(isNumber$1(e)||isBigNumber(e))&&(e=[e]),_resize(e,t,0,n===void 0?0:n),e}function _resize(e,t,n,r){var i,a,o=e.length,s=t[n],c=Math.min(o,s);if(e.length=s,n<t.length-1){var l=n+1;for(i=0;i<c;i++)a=e[i],Array.isArray(a)||(a=[a],e[i]=a),_resize(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,_resize(a,t,l,r)}else{for(i=0;i<c;i++)for(;Array.isArray(e[i]);)e[i]=e[i][0];for(i=c;i<s;i++)e[i]=r}}function reshape(e,t){var n=flatten(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new DimensionError(0,r,`!=`);t=processSizesWildcard(t,r);var i=product(t);if(r!==i)throw new DimensionError(i,r,`!=`);try{return _reshape(n,t)}catch(e){throw e instanceof DimensionError?new DimensionError(i,r,`!=`):e}}function processSizesWildcard(e,t){var n=product(e),r=e.slice(),i=-1,a=e.indexOf(i);if(e.indexOf(i,a+1)>=0)throw Error(`More than one wildcard in sizes`);var o=a>=0,s=t%n===0;if(o)if(s)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function product(e){return e.reduce((e,t)=>e*t,1)}function _reshape(e,t){for(var n=e,r,i=t.length-1;i>0;i--){var a=t[i];r=[];for(var o=n.length/a,s=0;s<o;s++)r.push(n.slice(s*a,(s+1)*a));n=r}return n}function unsqueeze(e,t,n,r){var i=r||arraySize(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=_unsqueeze(e,t,0);i.length<t;)i.push(1);return e}function _unsqueeze(e,t,n){var r,i;if(Array.isArray(e)){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=_unsqueeze(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function flatten(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function callback(e){Array.isArray(e)?e.forEach(callback):t.push(e)}),t}function getArrayDataType(e,t){for(var n,r=0,i=0;i<e.length;i++){var a=e[i],o=Array.isArray(a);if(i===0&&o&&(r=a.length),o&&a.length!==r)return;var s=o?getArrayDataType(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function concatRecursive(e,t,n,r){if(r<n){if(e.length!==t.length)throw new DimensionError(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=concatRecursive(e[a],t[a],n,r+1);return i}else return e.concat(t)}function concat(){var e=Array.prototype.slice.call(arguments,0,-1),t=Array.prototype.slice.call(arguments,-1);if(e.length===1)return e[0];if(e.length>1)return e.slice(1).reduce(function(e,n){return concatRecursive(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function broadcastSizes(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t.map(e=>e.length),i=Math.max(...r),a=Array(i).fill(null),o=0;o<t.length;o++)for(var s=t[o],c=r[o],l=0;l<c;l++){var u=i-c+l;s[l]>a[u]&&(a[u]=s[l])}for(var d=0;d<t.length;d++)checkBroadcastingRules(t[d],a);return a}function checkBroadcastingRules(e,t){for(var n=t.length,r=e.length,i=0;i<r;i++){var a=n-r+i;if(e[i]<t[a]&&e[i]>1||e[i]>t[a])throw Error(`shape missmatch: missmatch is found in arg with shape (${e}) not possible to broadcast dimension ${r} with size ${e[i]} to size ${t[a]}`)}}function broadcastTo(e,t){var n=arraySize(e);if(deepStrictEqual(n,t))return e;checkBroadcastingRules(n,t);var r=broadcastSizes(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=clone$1(e);n.length<i&&(o=reshape(o,a),n=arraySize(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=stretch(o,r[s],s),n=arraySize(o));return o}function stretch(e,t,n){return concat(...Array(t).fill(e),n)}function clone$1(e){return(0,Je.default)([],e)}__name(clone$1,`clone`);function factory(e,t,n,r){function assertAndCreate(r){var i=pickShallow(r,t.map(stripOptionalNotation));return assertDependencies(e,t,r),n(i)}return assertAndCreate.isFactory=!0,assertAndCreate.fn=e,assertAndCreate.dependencies=t.slice().sort(),r&&(assertAndCreate.meta=r),assertAndCreate}function assertDependencies(e,t,n){if(!t.filter(e=>!isOptionalDependency(e)).every(e=>n[e]!==void 0)){var r=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${r.map(e=>`"${e}"`).join(`, `)}.`)}}function isOptionalDependency(e){return e&&e[0]===`?`}function stripOptionalNotation(e){return e&&e[0]===`?`?e.slice(1):e}function getSafeProperty(e,t){if(isPlainObject(e)&&isSafeProperty(e,t))return e[t];throw typeof e[t]==`function`&&isSafeMethod(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function setSafeProperty(e,t,n){if(isPlainObject(e)&&isSafeProperty(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function hasSafeProperty(e,t){return t in e}function isSafeProperty(e,t){return!e||typeof e!=`object`?!1:hasOwnProperty($e,t)?!0:!(t in Object.prototype||t in Function.prototype)}function isSafeMethod(e,t){return e==null||typeof e[t]!=`function`||hasOwnProperty(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:hasOwnProperty(et,t)?!0:!(t in Object.prototype||t in Function.prototype)}function isPlainObject(e){return typeof e==`object`&&e&&e.constructor===Object}var $e={length:!0,name:!0},et={toString:!0,valueOf:!0,toLocaleString:!0},ObjectWrappingMap=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return getSafeProperty(this.wrappedObject,e)}set(e,t){return setSafeProperty(this.wrappedObject,e,t),this}has(e){return hasSafeProperty(this.wrappedObject,e)}};function isMap(e){return e?e instanceof Map||e instanceof ObjectWrappingMap||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var tt=__toESM(Xe(),1),nt=function _createTyped(){return nt=tt.default.create,tt.default},rt=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],it=factory(`typed`,rt,function createTyped$1(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=nt();return a.clear(),a.addTypes([{name:`number`,test:isNumber$1},{name:`Complex`,test:isComplex},{name:`BigNumber`,test:isBigNumber},{name:`Fraction`,test:isFraction},{name:`Unit`,test:isUnit},{name:`identifier`,test:e=>isString$1&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])*$/.test(e)},{name:`string`,test:isString$1},{name:`Chain`,test:isChain},{name:`Array`,test:R},{name:`Matrix`,test:isMatrix},{name:`DenseMatrix`,test:isDenseMatrix},{name:`SparseMatrix`,test:isSparseMatrix},{name:`Range`,test:isRange},{name:`Index`,test:isIndex},{name:`boolean`,test:isBoolean},{name:`ResultSet`,test:isResultSet},{name:`Help`,test:isHelp},{name:`function`,test:isFunction},{name:`Date`,test:isDate},{name:`RegExp`,test:isRegExp},{name:`null`,test:isNull},{name:`undefined`,test:isUndefined},{name:`AccessorNode`,test:isAccessorNode},{name:`ArrayNode`,test:isArrayNode},{name:`AssignmentNode`,test:isAssignmentNode},{name:`BlockNode`,test:isBlockNode},{name:`ConditionalNode`,test:isConditionalNode},{name:`ConstantNode`,test:isConstantNode},{name:`FunctionNode`,test:isFunctionNode},{name:`FunctionAssignmentNode`,test:isFunctionAssignmentNode},{name:`IndexNode`,test:isIndexNode},{name:`Node`,test:isNode},{name:`ObjectNode`,test:isObjectNode},{name:`OperatorNode`,test:isOperatorNode},{name:`ParenthesisNode`,test:isParenthesisNode},{name:`RangeNode`,test:isRangeNode},{name:`RelationalNode`,test:isRelationalNode},{name:`SymbolNode`,test:isSymbolNode},{name:`Map`,test:isMap},{name:`Object`,test:isObject$2}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function convert(e){if(t||throwNoBignumber(e),digits(e)>15)throw TypeError(`Cannot implicitly convert a number with >15 significant digits to BigNumber (value: `+e+`). Use function bignumber(x) to convert to BigNumber.`);return new t(e)}},{from:`number`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function convert(e){throw TypeError(`Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.`)}},{from:`Fraction`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function convert(e){i||throwNoFraction(e);var t=new i(e);if(t.valueOf()!==e)throw TypeError(`Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: `+e+`). Use function fraction(x) to convert to Fraction.`);return t}},{from:`string`,to:`number`,convert:function convert(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function convert(e){t||throwNoBignumber(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function convert(e){i||throwNoFraction(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function convert(e){n||throwNoComplex(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function convert(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function convert(e){return t||throwNoBignumber(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function convert(e){return i||throwNoFraction(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function convert(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function convert(e){return r||throwNoMatrix(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function convert(e){return e.valueOf()}}]),a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&isCollection(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&isCollection(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a});function throwNoBignumber(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function throwNoComplex(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function throwNoMatrix(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function throwNoFraction(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var z=9e15,B=1e9,at=`0123456789abcdef`,ot=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,st=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-z,maxE:z,crypto:!1},lt,V,H=!0,ut=`[DecimalError] `,U=ut+`Invalid argument: `,dt=ut+`Precision limit exceeded`,ft=ut+`crypto unavailable`,pt=`[object Decimal]`,W=Math.floor,G=Math.pow,mt=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ht=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,gt=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,_t=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,K=1e7,q=7,vt=9007199254740991,yt=ot.length-1,bt=st.length-1,J={toStringTag:pt};J.absoluteValue=J.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),finalise(e)},J.ceil=function(){return finalise(new this.constructor(this),this.e+1,2)},J.clampedTo=J.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(U+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},J.comparedTo=J.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},J.cosine=J.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+q,r.rounding=1,n=cosine(r,toLessThanHalfPi(r,n)),r.precision=e,r.rounding=t,finalise(V==2||V==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},J.cubeRoot=J.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(H=!1,a=u.s*G(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=digitsToString(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=G(n,1/3),e=W((e+1)/3)-(e%3==(e<0?-1:2)),a==1/0?n=`5e`+e:(n=a.toExponential(),n=n.slice(0,n.indexOf(`e`)+1)+e),r=new d(n),r.s=u.s):r=new d(a.toString()),o=(e=d.precision)+3;;)if(s=r,c=s.times(s).times(s),l=c.plus(u),r=Y(l.plus(u).times(s),l.plus(c),o+2,1),digitsToString(s.d).slice(0,o)===(n=digitsToString(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(finalise(s,e+1,0),s.times(s).times(s).eq(u))){r=s;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)==`5`)&&(finalise(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return H=!0,finalise(r,e,d.rounding,t)},J.decimalPlaces=J.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-W(this.e/q))*q,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},J.dividedBy=J.div=function(e){return Y(this,new this.constructor(e))},J.dividedToIntegerBy=J.divToInt=function(e){var t=this,n=t.constructor;return finalise(Y(t,new n(e),0,1,1),n.precision,n.rounding)},J.equals=J.eq=function(e){return this.cmp(e)===0},J.floor=function(){return finalise(new this.constructor(this),this.e+1,3)},J.greaterThan=J.gt=function(e){return this.cmp(e)>0},J.greaterThanOrEqualTo=J.gte=function(e){var t=this.cmp(e);return t==1||t===0},J.hyperbolicCosine=J.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/tinyPow(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=taylorSeries(o,1,a.times(t),new o(1),!0);for(var c,l=e,u=new o(8);l--;)c=a.times(a),a=s.minus(c.times(u.minus(c.times(u))));return finalise(a,o.precision=n,o.rounding=r,!0)},J.hyperbolicSine=J.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=taylorSeries(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/tinyPow(5,e)),i=taylorSeries(a,2,i,i,!0);for(var o,s=new a(5),c=new a(16),l=new a(20);e--;)o=i.times(i),i=i.times(s.plus(o.times(c.times(o).plus(l))))}return a.precision=t,a.rounding=n,finalise(i,t,n,!0)},J.hyperbolicTangent=J.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Y(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},J.inverseCosine=J.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?getPi(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2)):n===0?e.isNeg()?getPi(t,r,i):new t(0):new t(NaN)},J.inverseHyperbolicCosine=J.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},J.inverseHyperbolicSine=J.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,r.precision=e,r.rounding=t,n.ln())},J.inverseHyperbolicTangent=J.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?finalise(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Y(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},J.inverseSine=J.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=getPi(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},J.inverseTangent=J.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(l.isFinite()){if(l.isZero())return new u(l);if(l.abs().eq(1)&&d+4<=bt)return o=getPi(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=bt)return o=getPi(u,d+4,f).times(.5),o.s=l.s,o}for(u.precision=s=d+10,u.rounding=1,n=Math.min(28,s/q+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(H=!1,t=Math.ceil(s/q),r=1,c=l.times(l),o=new u(l),i=l;e!==-1;)if(i=i.times(c),a=o.minus(i.div(r+=2)),i=i.times(c),o=a.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===a.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),H=!0,finalise(o,u.precision=d,u.rounding=f,!0)},J.isFinite=function(){return!!this.d},J.isInteger=J.isInt=function(){return!!this.d&&W(this.e/q)>this.d.length-2},J.isNaN=function(){return!this.s},J.isNegative=J.isNeg=function(){return this.s<0},J.isPositive=J.isPos=function(){return this.s>0},J.isZero=function(){return!!this.d&&this.d[0]===0},J.lessThan=J.lt=function(e){return this.cmp(e)<0},J.lessThanOrEqualTo=J.lte=function(e){return this.cmp(e)<1},J.logarithm=J.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(H=!1,s=d+p,o=naturalLogarithm(l,s),r=t?getLn10(u,s+10):naturalLogarithm(e,s),c=Y(o,r,s,1),checkRoundingDigits(c.d,i=d,f))do if(s+=10,o=naturalLogarithm(l,s),r=t?getLn10(u,s+10):naturalLogarithm(e,s),c=Y(o,r,s,1),!a){+digitsToString(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=finalise(c,d+1,0));break}while(checkRoundingDigits(c.d,i+=10,f));return H=!0,finalise(c,d,f)},J.minus=J.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return H?finalise(e,s,c):e}if(n=W(e.e/q),u=W(p.e/q),l=l.slice(),a=u-n,a){for(d=a<0,d?(t=l,a=-a,o=f.length):(t=f,n=u,o=l.length),r=Math.max(Math.ceil(s/q),o)+2,a>r&&(a=r,t.length=1),t.reverse(),r=a;r--;)t.push(0);t.reverse()}else{for(r=l.length,o=f.length,d=r<o,d&&(o=r),r=0;r<o;r++)if(l[r]!=f[r]){d=l[r]<f[r];break}a=0}for(d&&(t=l,l=f,f=t,e.s=-e.s),o=l.length,r=f.length-o;r>0;--r)l[o++]=0;for(r=f.length;r>a;){if(l[--r]<f[r]){for(i=r;i&&l[--i]===0;)l[i]=K-1;--l[i],l[r]+=K}l[r]-=f[r]}for(;l[--o]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=getBase10Exponent(l,n),H?finalise(e,s,c):e):new m(c===3?-0:0)},J.modulo=J.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?finalise(new r(n),r.precision,r.rounding):(H=!1,r.modulo==9?(t=Y(n,e.abs(),0,3,1),t.s*=e.s):t=Y(n,e,0,r.modulo,1),t=t.times(e),H=!0,n.minus(t))},J.naturalExponential=J.exp=function(){return naturalExponential(this)},J.naturalLogarithm=J.ln=function(){return naturalLogarithm(this)},J.negated=J.neg=function(){var e=new this.constructor(this);return e.s=-e.s,finalise(e)},J.plus=J.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),H?finalise(e,s,c):e;if(a=W(d.e/q),r=W(e.e/q),l=l.slice(),i=a-r,i){for(i<0?(n=l,i=-i,o=u.length):(n=u,r=a,o=l.length),a=Math.ceil(s/q),o=a>o?a+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=l.length,i=u.length,o-i<0&&(i=o,n=u,u=l,l=n),t=0;i;)t=(l[--i]=l[i]+u[i]+t)/K|0,l[i]%=K;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=getBase10Exponent(l,r),H?finalise(e,s,c):e},J.precision=J.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(U+e);return n.d?(t=getPrecision(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},J.round=function(){var e=this,t=e.constructor;return finalise(new t(e),e.e+1,t.rounding)},J.sine=J.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+q,r.rounding=1,n=sine(r,toLessThanHalfPi(r,n)),r.precision=e,r.rounding=t,finalise(V>2?n.neg():n,e,t,!0)):new r(NaN)},J.squareRoot=J.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(H=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=digitsToString(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=W((c+1)/2)-(c<0||c%2),l==1/0?t=`5e`+c:(t=l.toExponential(),t=t.slice(0,t.indexOf(`e`)+1)+c),r=new u(t)):r=new u(l.toString()),n=(c=u.precision)+3;;)if(a=r,r=a.plus(Y(o,a,n+2,1)).times(.5),digitsToString(a.d).slice(0,n)===(t=digitsToString(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(finalise(a,c+1,0),a.times(a).eq(o))){r=a;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)==`5`)&&(finalise(r,c+1,1),e=!r.times(r).eq(o));break}return H=!0,finalise(r,c,u.rounding,e)},J.tangent=J.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Y(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,finalise(V==2||V==4?n.neg():n,e,t,!0)):new r(NaN)},J.times=J.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=W(u.e/q)+W(e.e/q),c=f.length,l=p.length,c<l&&(a=f,f=p,p=a,o=c,c=l,l=o),a=[],o=c+l,r=o;r--;)a.push(0);for(r=l;--r>=0;){for(t=0,i=c+r;i>r;)s=a[i]+p[r]*f[i-r-1]+t,a[i--]=s%K|0,t=s/K|0;a[i]=(a[i]+t)%K|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=getBase10Exponent(a,n),H?finalise(e,d.precision,d.rounding):e},J.toBinary=function(e,t){return toStringBinary(this,2,e,t)},J.toDecimalPlaces=J.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(checkInt32(e,0,B),t===void 0?t=r.rounding:checkInt32(t,0,8),finalise(n,e+n.e+1,t))},J.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=finiteToString(r,!0):(checkInt32(e,0,B),t===void 0?t=i.rounding:checkInt32(t,0,8),r=finalise(new i(r),e+1,t),n=finiteToString(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},J.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=finiteToString(i):(checkInt32(e,0,B),t===void 0?t=a.rounding:checkInt32(t,0,8),r=finalise(new a(i),e+i.e+1,t),n=finiteToString(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},J.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=getPrecision(m)-p.e-1,o=a%q,t.d[0]=G(10,o<0?q+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(U+s);e=s.gt(t)?a>0?t:l:s}for(H=!1,s=new h(digitsToString(m)),u=h.precision,h.precision=a=m.length*q*2;d=Y(s,t,0,1,1),i=n.plus(d.times(r)),i.cmp(e)!=1;)n=r,r=i,i=l,l=c.plus(d.times(i)),c=i,i=t,t=s.minus(d.times(i)),s=i;return i=Y(e.minus(n),r,0,1,1),c=c.plus(i.times(l)),n=n.plus(i.times(r)),c.s=l.s=p.s,f=Y(l,r,a,1).minus(p).abs().cmp(Y(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,H=!0,f},J.toHexadecimal=J.toHex=function(e,t){return toStringBinary(this,16,e,t)},J.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:checkInt32(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(H=!1,n=Y(n,e,0,t,1).times(e),H=!0,finalise(n)):(e.s=n.s,n=e),n},J.toNumber=function(){return+this},J.toOctal=function(e,t){return toStringBinary(this,8,e,t)},J.toPower=J.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(G(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return finalise(s,r,a);if(t=W(e.e/q),t>=e.d.length-1&&(n=l<0?-l:l)<=vt)return i=intPow(c,s,n,r),e.s<0?new c(1).div(i):finalise(i,r,a);if(o=s.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),s.e==0&&s.d[0]==1&&s.d.length==1)return s.s=o,s}return n=G(+s,l),t=n==0||!isFinite(n)?W(l*(Math.log(`0.`+digitsToString(s.d))/Math.LN10+s.e+1)):new c(n+``).e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(H=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=naturalExponential(e.times(naturalLogarithm(s,r+n)),r),i.d&&(i=finalise(i,r+5,1),checkRoundingDigits(i.d,r,a)&&(t=r+10,i=finalise(naturalExponential(e.times(naturalLogarithm(s,t+n)),t),t+5,1),+digitsToString(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=finalise(i,r+1,0)))),i.s=o,H=!0,c.rounding=a,finalise(i,r,a))},J.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=finiteToString(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(checkInt32(e,1,B),t===void 0?t=i.rounding:checkInt32(t,0,8),r=finalise(new i(r),e,t),n=finiteToString(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},J.toSignificantDigits=J.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(checkInt32(e,1,B),t===void 0?t=r.rounding:checkInt32(t,0,8)),finalise(new r(n),e,t)},J.toString=function(){var e=this,t=e.constructor,n=finiteToString(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},J.truncated=J.trunc=function(){return finalise(new this.constructor(this),this.e+1,1)},J.valueOf=J.toJSON=function(){var e=this,t=e.constructor,n=finiteToString(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function digitsToString(e){var t,n,r,i=e.length-1,a=``,o=e[0];if(i>0){for(a+=o,t=1;t<i;t++)r=e[t]+``,n=q-r.length,n&&(a+=getZeroString(n)),a+=r;o=e[t],r=o+``,n=q-r.length,n&&(a+=getZeroString(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function checkInt32(e,t,n){if(e!==~~e||e<t||e>n)throw Error(U+e)}function checkRoundingDigits(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=q,i=0):(i=Math.ceil((t+1)/q),t%=q),a=G(10,q-t),s=e[i]%a|0,r==null?t<3?(t==0?s=s/100|0:t==1&&(s=s/10|0),o=n<4&&s==99999||n>3&&s==49999||s==5e4||s==0):o=(n<4&&s+1==a||n>3&&s+1==a/2)&&(e[i+1]/a/100|0)==G(10,t-2)-1||(s==a/2||s==0)&&(e[i+1]/a/100|0)==0:t<4?(t==0?s=s/1e3|0:t==1?s=s/100|0:t==2&&(s=s/10|0),o=(r||n<4)&&s==9999||!r&&n>3&&s==4999):o=((r||n<4)&&s+1==a||!r&&n>3&&s+1==a/2)&&(e[i+1]/a/1e3|0)==G(10,t-3)-1,o}function convertBase(e,t,n){for(var r,i=[0],a,o=0,s=e.length;o<s;){for(a=i.length;a--;)i[a]*=t;for(i[0]+=at.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function cosine(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/tinyPow(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=taylorSeries(e,1,t.times(i),new e(1));for(var a=n;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var Y=(function(){function multiplyInteger(e,t,n){var r,i=0,a=e.length;for(e=e.slice();a--;)r=e[a]*t+i,e[a]=r%n|0,i=r/n|0;return i&&e.unshift(i),e}function compare(e,t,n,r){var i,a;if(n!=r)a=n>r?1:-1;else for(i=a=0;i<n;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function subtract(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;)e.shift()}return function(e,t,n,r,i,a){var o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E=e.constructor,ee=e.s==t.s?1:-1,D=e.d,O=t.d;if(!D||!D[0]||!O||!O[0])return new E(!e.s||!t.s||(D?O&&D[0]==O[0]:!O)?NaN:D&&D[0]==0||!O?ee*0:ee/0);for(a?(u=1,s=e.e-t.e):(a=K,u=q,s=W(e.e/u)-W(t.e/u)),w=O.length,S=D.length,m=new E(ee),h=m.d=[],c=0;O[c]==(D[c]||0);c++);if(O[c]>(D[c]||0)&&s--,n==null?(y=n=E.precision,r=E.rounding):y=i?n+(e.e-t.e)+1:n,y<0)h.push(1),d=!0;else{if(y=y/u+2|0,c=0,w==1){for(l=0,O=O[0],y++;(c<S||l)&&y--;c++)b=l*a+(D[c]||0),h[c]=b/O|0,l=b%O|0;d=l||c<S}else{for(l=a/(O[0]+1)|0,l>1&&(O=multiplyInteger(O,l,a),D=multiplyInteger(D,l,a),w=O.length,S=D.length),x=w,g=D.slice(0,w),_=g.length;_<w;)g[_++]=0;T=O.slice(),T.unshift(0),C=O[0],O[1]>=a/2&&++C;do l=0,o=compare(O,g,w,_),o<0?(v=g[0],w!=_&&(v=v*a+(g[1]||0)),l=v/C|0,l>1?(l>=a&&(l=a-1),f=multiplyInteger(O,l,a),p=f.length,_=g.length,o=compare(f,g,p,_),o==1&&(l--,subtract(f,w<p?T:O,p,a))):(l==0&&(o=l=1),f=O.slice()),p=f.length,p<_&&f.unshift(0),subtract(g,f,_,a),o==-1&&(_=g.length,o=compare(O,g,w,_),o<1&&(l++,subtract(g,w<_?T:O,_,a))),_=g.length):o===0&&(l++,g=[0]),h[c++]=l,o&&g[0]?g[_++]=D[x]||0:(g=[D[x]],_=1);while((x++<S||g[0]!==void 0)&&y--);d=g[0]!==void 0}h[0]||h.shift()}if(u==1)m.e=s,lt=d;else{for(c=1,l=h[0];l>=10;l/=10)c++;m.e=c+s*u-1,finalise(m,i?n+m.e+1:n,r,d)}return m}})();function finalise(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor;out:if(t!=null){if(d=e.d,!d)return e;for(i=1,s=d[0];s>=10;s/=10)i++;if(a=t-i,a<0)a+=q,o=t,u=d[f=0],c=u/G(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/q),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=q,o=a-q+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=q,o=a-q+i,c=o<0?0:u/G(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%G(10,i-o-1)),l=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(a>0?o>0?u/G(10,i-o):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,l?(t-=e.e+1,d[0]=G(10,(q-t%q)%q),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=G(10,q-a),d[f]=o>0?(u/G(10,i-o)%G(10,o)|0)*s:0),l)for(;;)if(f==0){for(a=1,o=d[0];o>=10;o/=10)a++;for(o=d[0]+=s,s=1;o>=10;o/=10)s++;a!=s&&(e.e++,d[0]==K&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=K)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return H&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function finiteToString(e,t,n){if(!e.isFinite())return nonFiniteToString(e);var r,i=e.e,a=digitsToString(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+getZeroString(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+getZeroString(-i-1)+a,n&&(r=n-o)>0&&(a+=getZeroString(r))):i>=o?(a+=getZeroString(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+getZeroString(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=getZeroString(r))),a}function getBase10Exponent(e,t){var n=e[0];for(t*=q;n>=10;n/=10)t++;return t}function getLn10(e,t,n){if(t>yt)throw H=!0,n&&(e.precision=n),Error(dt);return finalise(new e(ot),t,1,!0)}function getPi(e,t,n){if(t>bt)throw Error(dt);return finalise(new e(st),t,n,!0)}function getPrecision(e){var t=e.length-1,n=t*q+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function getZeroString(e){for(var t=``;e--;)t+=`0`;return t}function intPow(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/q+4);for(H=!1;;){if(n%2&&(a=a.times(t),truncate(a.d,o)&&(i=!0)),n=W(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),truncate(t.d,o)}return H=!0,a}function isOdd(e){return e.d[e.d.length-1]&1}function maxOrMin(e,t,n){for(var r,i,a=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){a=i;break}r=a.cmp(i),(r===n||r===0&&a.s===n)&&(a=i)}return a}function naturalExponential(e,t){var n,r,i,a,o,s,c,l=0,u=0,d=0,f=e.constructor,p=f.rounding,m=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(H=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(G(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=finalise(a.times(e),c,1),n=n.times(++u),s=o.plus(Y(a,n,c,1)),digitsToString(s.d).slice(0,c)===digitsToString(o.d).slice(0,c)){for(i=d;i--;)o=finalise(o.times(o),c,1);if(t==null)if(l<3&&checkRoundingDigits(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return finalise(o,f.precision=m,p,H=!0);else return f.precision=m,o}o=s}}function naturalLogarithm(e,t){var n,r,i,a,o,s,c,l,u,d,f,p=1,m=10,h=e,g=h.d,_=h.constructor,v=_.rounding,y=_.precision;if(h.s<0||!g||!g[0]||!h.e&&g[0]==1&&g.length==1)return new _(g&&!g[0]?-1/0:h.s==1?g?0:h:NaN);if(t==null?(H=!1,u=y):u=t,_.precision=u+=m,n=digitsToString(g),r=n.charAt(0),Math.abs(a=h.e)<0x5543df729c000){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=digitsToString(h.d),r=n.charAt(0),p++;a=h.e,r>1?(h=new _(`0.`+n),a++):h=new _(r+`.`+n.slice(1))}else return l=getLn10(_,u+2,y).times(a+``),h=naturalLogarithm(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?finalise(h,y,v,H=!0):h;for(d=h,c=o=h=Y(h.minus(1),h.plus(1),u,1),f=finalise(h.times(h),u,1),i=3;;){if(o=finalise(o.times(f),u,1),l=c.plus(Y(o,new _(i),u,1)),digitsToString(l.d).slice(0,u)===digitsToString(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(getLn10(_,u+2,y).times(a+``))),c=Y(c,new _(p),u,1),t==null)if(checkRoundingDigits(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Y(d.minus(1),d.plus(1),u,1),f=finalise(h.times(h),u,1),i=s=1;else return finalise(c,_.precision=y,v,H=!0);else return _.precision=y,c;c=l,i+=2}}function nonFiniteToString(e){return String(e.s*e.s/0)}function parseDecimal(e,t){var n,r,i;for((n=t.indexOf(`.`))>-1&&(t=t.replace(`.`,``)),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%q,n<0&&(r+=q),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=q;r<i;)e.d.push(+t.slice(r,r+=q));t=t.slice(r),r=q-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),H&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function parseOther(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),_t.test(t))return parseDecimal(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(ht.test(t))n=16,t=t.toLowerCase();else if(mt.test(t))n=2;else if(gt.test(t))n=8;else throw Error(U+t);for(a=t.search(/p/i),a>0?(c=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf(`.`),o=a>=0,r=e.constructor,o&&(t=t.replace(`.`,``),s=t.length,a=s-a,i=intPow(r,new r(n),a,a*2)),l=convertBase(t,n,K),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=getBase10Exponent(l,u),e.d=l,H=!1,o&&(e=Y(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?G(2,c):X.pow(2,c))),H=!0,e)}function sine(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:taylorSeries(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/tinyPow(5,n)),t=taylorSeries(e,2,t,t);for(var i,a=new e(5),o=new e(16),s=new e(20);n--;)i=t.times(t),t=t.times(a.plus(i.times(o.times(i).minus(s))));return t}function taylorSeries(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/q);for(H=!1,c=n.times(n),s=new e(r);;){if(o=Y(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Y(o.times(c),new e(t++*t++),u,1),o=s.plus(r),o.d[d]!==void 0){for(a=d;o.d[a]===s.d[a]&&a--;);if(a==-1)break}a=s,s=r,r=o,o=a,l++}return H=!0,o.d.length=d+1,o}function tinyPow(e,t){for(var n=e;--t;)n*=e;return n}function toLessThanHalfPi(e,t){var n,r=t.s<0,i=getPi(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return V=r?4:1,t;if(n=t.divToInt(i),n.isZero())V=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return V=isOdd(n)?r?2:3:r?4:1,t;V=isOdd(n)?r?1:4:r?3:2}return t.minus(i).abs()}function toStringBinary(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(checkInt32(n,1,B),r===void 0?r=p.rounding:checkInt32(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=nonFiniteToString(e);else{for(u=finiteToString(e),o=u.indexOf(`.`),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(u=u.replace(`.`,``),f=new p(1),f.e=u.length-o,f.d=convertBase(finiteToString(f),10,i),f.e=f.d.length),d=convertBase(u,10,i),a=c=d.length;d[--c]==0;)d.pop();if(!d[0])u=m?`0p+0`:`0`;else{if(o<0?a--:(e=new p(e),e.d=d,e.e=a,e=Y(e,f,n,r,0,i),d=e.d,a=e.e,l=lt),o=d[n],s=i/2,l||=d[n+1]!==void 0,l=r<4?(o!==void 0||l)&&(r===0||r===(e.s<0?3:2)):o>s||o===s&&(r===4||l||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,l)for(;++d[--n]>i-1;)d[n]=0,n||(++a,d.unshift(1));for(c=d.length;!d[c-1];--c);for(o=0,u=``;o<c;o++)u+=at.charAt(d[o]);if(m){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)u+=`0`;for(d=convertBase(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=at.charAt(d[o])}else u=u.charAt(0)+`.`+u.slice(1);u=u+(a<0?`p`:`p+`)+a}else if(a<0){for(;++a;)u=`0`+u;u=`0.`+u}else if(++a>c)for(a-=c;a--;)u+=`0`;else a<c&&(u=u.slice(0,a)+`.`+u.slice(a))}u=(t==16?`0x`:t==2?`0b`:t==8?`0o`:``)+u}return e.s<0?`-`+u:u}function truncate(e,t){if(e.length>t)return e.length=t,!0}function abs(e){return new this(e).abs()}function acos(e){return new this(e).acos()}function acosh(e){return new this(e).acosh()}function add(e,t){return new this(e).plus(t)}function asin(e){return new this(e).asin()}function asinh(e){return new this(e).asinh()}function atan(e){return new this(e).atan()}function atanh(e){return new this(e).atanh()}function atan2(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,a=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=getPi(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?getPi(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=getPi(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Y(e,t,a,1)),t=getPi(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Y(e,t,a,1)),n}function cbrt(e){return new this(e).cbrt()}function ceil(e){return finalise(e=new this(e),e.e+1,2)}function clamp(e,t,n){return new this(e).clamp(t,n)}function config(e){if(!e||typeof e!=`object`)throw Error(ut+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,B,`rounding`,0,8,`toExpNeg`,-z,0,`toExpPos`,0,z,`maxE`,0,z,`minE`,-z,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=ct[n]),(r=e[n])!==void 0)if(W(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(U+n+`: `+r);if(n=`crypto`,i&&(this[n]=ct[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<`u`&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(ft);else this[n]=!1;else throw Error(U+n+`: `+r);return this}function cos(e){return new this(e).cos()}function cosh$1(e){return new this(e).cosh()}__name(cosh$1,`cosh`);function clone(e){var t,n,r;function Decimal$1(e){var t,n,r,i=this;if(!(i instanceof Decimal$1))return new Decimal$1(e);if(i.constructor=Decimal$1,isDecimalInstance(e)){i.s=e.s,H?!e.d||e.e>Decimal$1.maxE?(i.e=NaN,i.d=null):e.e<Decimal$1.minE?(i.e=0,i.d=[0]):(i.e=e.e,i.d=e.d.slice()):(i.e=e.e,i.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){i.s=1/e<0?-1:1,i.e=0,i.d=[0];return}if(e<0?(e=-e,i.s=-1):i.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;H?t>Decimal$1.maxE?(i.e=NaN,i.d=null):t<Decimal$1.minE?(i.e=0,i.d=[0]):(i.e=t,i.d=[e]):(i.e=t,i.d=[e]);return}if(e*0!=0){e||(i.s=NaN),i.e=NaN,i.d=null;return}return parseDecimal(i,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),i.s=-1):(n===43&&(e=e.slice(1)),i.s=1),_t.test(e)?parseDecimal(i,e):parseOther(i,e);if(r===`bigint`)return e<0?(e=-e,i.s=-1):i.s=1,parseDecimal(i,e.toString());throw Error(U+e)}if(__name(Decimal$1,`Decimal`),Decimal$1.prototype=J,Decimal$1.ROUND_UP=0,Decimal$1.ROUND_DOWN=1,Decimal$1.ROUND_CEIL=2,Decimal$1.ROUND_FLOOR=3,Decimal$1.ROUND_HALF_UP=4,Decimal$1.ROUND_HALF_DOWN=5,Decimal$1.ROUND_HALF_EVEN=6,Decimal$1.ROUND_HALF_CEIL=7,Decimal$1.ROUND_HALF_FLOOR=8,Decimal$1.EUCLID=9,Decimal$1.config=Decimal$1.set=config,Decimal$1.clone=clone,Decimal$1.isDecimal=isDecimalInstance,Decimal$1.abs=abs,Decimal$1.acos=acos,Decimal$1.acosh=acosh,Decimal$1.add=add,Decimal$1.asin=asin,Decimal$1.asinh=asinh,Decimal$1.atan=atan,Decimal$1.atanh=atanh,Decimal$1.atan2=atan2,Decimal$1.cbrt=cbrt,Decimal$1.ceil=ceil,Decimal$1.clamp=clamp,Decimal$1.cos=cos,Decimal$1.cosh=cosh$1,Decimal$1.div=div,Decimal$1.exp=exp,Decimal$1.floor=floor,Decimal$1.hypot=hypot$1,Decimal$1.ln=ln,Decimal$1.log=log,Decimal$1.log10=log10,Decimal$1.log2=log2,Decimal$1.max=max,Decimal$1.min=min,Decimal$1.mod=mod,Decimal$1.mul=mul,Decimal$1.pow=pow,Decimal$1.random=random,Decimal$1.round=round,Decimal$1.sign=sign,Decimal$1.sin=sin,Decimal$1.sinh=sinh$1,Decimal$1.sqrt=sqrt,Decimal$1.sub=sub,Decimal$1.sum=sum,Decimal$1.tan=tan,Decimal$1.tanh=tanh,Decimal$1.trunc=trunc,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=[`precision`,`rounding`,`toExpNeg`,`toExpPos`,`maxE`,`minE`,`modulo`,`crypto`],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return Decimal$1.config(e),Decimal$1}function div(e,t){return new this(e).div(t)}function exp(e){return new this(e).exp()}function floor(e){return finalise(e=new this(e),e.e+1,3)}function hypot$1(){var e,t,n=new this(0);for(H=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return H=!0,new this(1/0);n=t}return H=!0,n.sqrt()}__name(hypot$1,`hypot`);function isDecimalInstance(e){return e instanceof X||e&&e.toStringTag===pt||!1}function ln(e){return new this(e).ln()}function log(e,t){return new this(e).log(t)}function log2(e){return new this(e).log(2)}function log10(e){return new this(e).log(10)}function max(){return maxOrMin(this,arguments,-1)}function min(){return maxOrMin(this,arguments,1)}function mod(e,t){return new this(e).mod(t)}function mul(e,t){return new this(e).mul(t)}function pow(e,t){return new this(e).pow(t)}function random(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:checkInt32(e,1,B),r=Math.ceil(e/q),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));a<r;)i=t[a],i>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:s[a++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);a<r;)i=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,a):(s.push(i%1e7),a+=4);a=r/4}else throw Error(ft);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=q,r&&e&&(i=G(10,q-e),s[a]=(r/i|0)*i);s[a]===0;a--)s.pop();if(a<0)n=0,s=[0];else{for(n=-1;s[0]===0;n-=q)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<q&&(n-=q-r)}return o.e=n,o.d=s,o}function round(e){return finalise(e=new this(e),e.e+1,this.rounding)}function sign(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function sin(e){return new this(e).sin()}function sinh$1(e){return new this(e).sinh()}__name(sinh$1,`sinh`);function sqrt(e){return new this(e).sqrt()}function sub(e,t){return new this(e).sub(t)}function sum(){var e=0,t=arguments,n=new this(t[e]);for(H=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return H=!0,finalise(n,this.precision,this.rounding)}function tan(e){return new this(e).tan()}function tanh(e){return new this(e).tanh()}function trunc(e){return finalise(e=new this(e),e.e+1,1)}J[Symbol.for(`nodejs.util.inspect.custom`)]=J.toString,J[Symbol.toStringTag]=`Decimal`;var X=J.constructor=clone(ct);ot=new X(ot),st=new X(st);var xt=X,St=`BigNumber`,Ct=[`?on`,`config`],wt=factory(St,Ct,e=>{var{on:t,config:n}=e,r=xt.clone({precision:n.precision,modulo:xt.EUCLID});return r.prototype=Object.create(r.prototype),r.prototype.type=`BigNumber`,r.prototype.isBigNumber=!0,r.prototype.toJSON=function(){return{mathjs:`BigNumber`,value:this.toString()}},r.fromJSON=function(e){return new r(e.value)},t&&t(`config`,function(e,t){e.precision!==t.precision&&r.config({precision:e.precision})}),r},{isClass:!0});const Z=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Q=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},cosm1=e=>{let t=Math.sin(.5*e);return-2*t*t},hypot=function(e,t){return e=Math.abs(e),t=Math.abs(t),e<t&&([e,t]=[t,e]),e<1e8?Math.sqrt(e*e+t*t):(t/=e,e*Math.sqrt(1+t*t))},parser_exit=function(){throw SyntaxError(`Invalid Param`)};function logHypot(e,t){let n=Math.abs(e),r=Math.abs(t);return e===0?Math.log(r):t===0?Math.log(n):n<3e3&&r<3e3?Math.log(e*e+t*t)*.5:(e*=.5,t*=.5,.5*Math.log(e*e+t*t)+Math.LN2)}const Tt={re:0,im:0},parse=function(e,t){let n=Tt;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return Complex$1.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return Complex$1.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):parser_exit();break;case`string`:n.im=n.re=0;let t=e.replace(/_/g,``).match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,i=0;t===null&&parser_exit();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
104
|
+
`);return Object.freeze(Ge)},`config`);(0,Je.default)(Ye,Ge,{MATRIX_OPTIONS:Ke,NUMBER_OPTIONS:qe});var Xe=__commonJSMin(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.typed=r())})(e,(function(){"use strict";function ok(){return!0}function notOk(){return!1}function undef(){}let e=`Argument is not a typed-function.`;function create(){function isPlainObject$1(e){return typeof e==`object`&&!!e&&e.constructor===Object}__name(isPlainObject$1,`isPlainObject`);let t=[{name:`number`,test:function(e){return typeof e==`number`}},{name:`string`,test:function(e){return typeof e==`string`}},{name:`boolean`,test:function(e){return typeof e==`boolean`}},{name:`Function`,test:function(e){return typeof e==`function`}},{name:`Array`,test:Array.isArray},{name:`Date`,test:function(e){return e instanceof Date}},{name:`RegExp`,test:function(e){return e instanceof RegExp}},{name:`Object`,test:isPlainObject$1},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],n={name:`any`,test:ok,isAny:!0},r,i,a=0,o={createCount:0};function findType(e){let t=r.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,a=e.toLowerCase(),o;for(o of i)if(o.toLowerCase()===a){n+=`. Did you mean "`+o+`" ?`;break}throw TypeError(n)}function addTypes(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?findType(t).index:i.length,a=[];for(let t=0;t<e.length;++t){if(!e[t]||typeof e[t].name!=`string`||typeof e[t].test!=`function`)throw TypeError(`Object with properties {name: string, test: function} expected`);let i=e[t].name;if(r.has(i))throw TypeError(`Duplicate type name "`+i+`"`);a.push(i),r.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let o=i.slice(n);i=i.slice(0,n).concat(a).concat(o);for(let e=n+a.length;e<i.length;++e)r.get(i[e]).index=e}function clear(){r=new Map,i=[],a=0,addTypes([n],!1)}clear(),addTypes(t);function clearConversions(){let e;for(e of i)r.get(e).conversionsTo=[];a=0}function findTypeNames(e){let t=i.filter(t=>{let n=r.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function isTypedFunction(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function findSignature(t,n,r){if(!isTypedFunction(t))throw TypeError(e);let i=r&&r.exact,a=parseSignature(Array.isArray(n)?n.join(`,`):n),o=stringifyParams(a);if(!i||o in t.signatures){let e=t._typedFunctionData.signatureMap.get(o);if(e)return e}let s=a.length,c;if(i){c=[];let e;for(e in t.signatures)c.push(t._typedFunctionData.signatureMap.get(e))}else c=t._typedFunctionData.signatures;for(let e=0;e<s;++e){let t=a[e],n=[],r;for(r of c){let i=getParamAtIndex(r.params,e);if(!(!i||t.restParam&&!i.restParam)){if(!i.hasAny){let e=paramTypeSet(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}}if(c=n,c.length===0)break}let l;for(l of c)if(l.params.length<=s)return l;throw TypeError(`Signature not found (signature: `+(t.name||`unnamed`)+`(`+stringifyParams(a,`, `)+`))`)}function find(e,t,n){return findSignature(e,t,n).implementation}function convert(e,t){let n=findType(t);if(n.test(e))return e;let r=n.conversionsTo;if(r.length===0)throw Error(`There are no conversions to `+t+` defined.`);for(let t=0;t<r.length;t++)if(findType(r[t].from).test(e))return r[t].convert(e);throw Error(`Cannot convert `+e+` to `+t)}function stringifyParams(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function parseParam(e){let t=e.indexOf(`...`)===0,n=(t?e.length>3?e.slice(3):`any`:e).split(`|`).map(e=>findType(e.trim())),r=!1,i=t?`...`:``;return{types:n.map(function(e){return r=e.isAny||r,i+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}}),name:i.slice(0,-1),hasAny:r,hasConversion:!1,restParam:t}}function expandParam(e){let t=availableConversions(e.types.map(e=>e.name)),n=e.hasAny,r=e.name,i=t.map(function(e){let t=findType(e.from);return n=t.isAny||n,r+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(i),name:r,hasAny:n,hasConversion:i.length>0,restParam:e.restParam}}function paramTypeSet(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function parseSignature(e){let t=[];if(typeof e!=`string`)throw TypeError(`Signatures must be strings`);let n=e.trim();if(n===``)return t;let r=n.split(`,`);for(let e=0;e<r.length;++e){let n=parseParam(r[e].trim());if(n.restParam&&e!==r.length-1)throw SyntaxError(`Unexpected rest parameter "`+r[e]+`": only allowed for the last parameter`);if(n.types.length===0)return null;t.push(n)}return t}function hasRestParam(e){let t=last(e);return t?t.restParam:!1}function compileTest(e){if(!e||e.types.length===0)return ok;if(e.types.length===1)return findType(e.types[0].name).test;if(e.types.length===2){let t=findType(e.types[0].name).test,n=findType(e.types[1].name).test;return function or(e){return t(e)||n(e)}}else{let t=e.types.map(function(e){return findType(e.name).test});return function or(e){for(let n=0;n<t.length;n++)if(t[n](e))return!0;return!1}}}function compileTests(e){let t,n,r;if(hasRestParam(e)){t=initial(e).map(compileTest);let n=t.length,r=compileTest(last(e)),testRestParam=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function testArgs(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return testRestParam(e)&&e.length>=n+1}}else if(e.length===0)return function testArgs(e){return e.length===0};else if(e.length===1)return n=compileTest(e[0]),function testArgs(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=compileTest(e[0]),r=compileTest(e[1]),function testArgs(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(compileTest),function testArgs(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function getParamAtIndex(e,t){return t<e.length?e[t]:hasRestParam(e)?last(e):null}function getTypeSetAtIndex(e,t){let n=getParamAtIndex(e,t);return n?paramTypeSet(n):new Set}function isExactType(e){return e.conversion===null||e.conversion===void 0}function mergeExpectedParams(e,t){let n=new Set;return e.forEach(e=>{let r=getTypeSetAtIndex(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function createError(e,t,n){let r,i,a=e||`unnamed`,o=n,s;for(s=0;s<t.length;s++){let e=[];if(o.forEach(n=>{let r=compileTest(getParamAtIndex(n.params,s));(s<n.params.length||hasRestParam(n.params))&&r(t[s])&&e.push(n)}),e.length===0){if(i=mergeExpectedParams(o,s),i.length>0){let e=findTypeNames(t[s]);return r=TypeError(`Unexpected type of argument in function `+a+` (expected: `+i.join(` or `)+`, actual: `+e.join(` | `)+`, index: `+s+`)`),r.data={category:`wrongType`,fn:a,index:s,actual:e,expected:i},r}}else o=e}let c=o.map(function(e){return hasRestParam(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=mergeExpectedParams(o,s),r=TypeError(`Too few arguments in function `+a+` (expected: `+i.join(` or `)+`, index: `+t.length+`)`),r.data={category:`tooFewArgs`,fn:a,index:t.length,expected:i},r;let l=Math.max.apply(null,c);if(t.length>l)return r=TypeError(`Too many arguments in function `+a+` (expected: `+l+`, actual: `+t.length+`)`),r.data={category:`tooManyArgs`,fn:a,index:t.length,expectedLength:l},r;let u=[];for(let e=0;e<t.length;++e)u.push(findTypeNames(t[e]).join(`|`));return r=TypeError(`Arguments of type "`+u.join(`, `)+`" do not match any of the defined signatures of function `+a+`.`),r.data={category:`mismatch`,actual:u},r}function getLowestTypeIndex(e){let t=i.length+1;for(let n=0;n<e.types.length;n++)t=Math.min(t,e.types[n].typeIndex);return t}function getLowestConversionIndex(e){let t=a+1;for(let n=0;n<e.types.length;n++)isExactType(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function compareParams(e,t){if(e.hasAny){if(!t.hasAny)return .1}else if(t.hasAny)return-.1;if(e.restParam){if(!t.restParam)return .01}else if(t.restParam)return-.01;let n=getLowestTypeIndex(e)-getLowestTypeIndex(t);if(n<0)return-.001;if(n>0)return .001;let r=getLowestConversionIndex(e),i=getLowestConversionIndex(t);if(e.hasConversion){if(!t.hasConversion)return(1+r)*1e-6}else if(t.hasConversion)return-(1+i)*1e-6;let a=r-i;return a<0?-1e-7:a>0?1e-7:0}function compareSignatures(e,t){let n=e.params,r=t.params,i=last(n),a=last(r),o=hasRestParam(n),s=hasRestParam(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1e7}else if(s&&a.hasAny)return-1e7;let c=0,l=0,u;for(u of n)u.hasAny&&++c,u.hasConversion&&++l;let d=0,f=0;for(u of r)u.hasAny&&++d,u.hasConversion&&++f;if(c!==d)return(c-d)*1e6;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1e5}else if(s&&a.hasConversion)return-1e5;if(l!==f)return(l-f)*1e4;if(o){if(!s)return 1e3}else if(s)return-1e3;let p=(n.length-r.length)*(o?-100:100);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=compareParams(n[e],r[e]);m.push(t),h+=t}if(h!==0)return(h<0?-10:10)+h;let g,_=9,v=_/(m.length+1);for(g of m){if(g!==0)return(g<0?-_:_)+g;_-=v}return 0}function availableConversions(e){if(e.length===0)return[];let t=e.map(findType);if(e.length===1)return t[0].conversionsTo;let n=new Set(e),r=new Set;for(let e=0;e<t.length;++e)for(let i of t[e].conversionsTo)n.has(i.from)||r.add(i.from);let i=[];for(let e of r){let n=a+1,r=null;for(let i=0;i<t.length;++i)for(let a of t[i].conversionsTo)a.from===e&&a.index<n&&(n=a.index,r=a);i.push(r)}return i}function compileArgsPreprocessing(e,t){let n=t,r=``;if(e.some(e=>e.hasConversion)){let i=hasRestParam(e),a=e.map(compileArgConversion);r=a.map(e=>e.name).join(`;`),n=function convertArgs(){let e=[],n=i?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=a[t](arguments[t]);return i&&(e[n]=arguments[n].map(a[n])),t.apply(this,e)}}let i=n;if(hasRestParam(e)){let t=e.length-1;i=function preprocessRestParams(){return n.apply(this,slice(arguments,0,t).concat([slice(arguments,t)]))}}return r&&Object.defineProperty(i,`name`,{value:r}),i}function compileArgConversion(e){let t,n,r,i,a=[],o=[],s=``;e.types.forEach(function(e){e.conversion&&(s+=e.conversion.from+`~>`+e.conversion.to+`,`,a.push(findType(e.conversion.from).test),o.push(e.conversion.convert))}),s=s?s.slice(0,-1):`pass`;let convertor=e=>e;switch(o.length){case 0:break;case 1:t=a[0],r=o[0],convertor=function convertArg(e){return t(e)?r(e):e};break;case 2:t=a[0],n=a[1],r=o[0],i=o[1],convertor=function convertArg(e){return t(e)?r(e):n(e)?i(e):e};break;default:convertor=function convertArg(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}return Object.defineProperty(convertor,`name`,{value:s}),convertor}function splitParams(e){function _splitParams(e,t,n){if(t<e.length){let r=e[t],i=[];if(r.restParam){let e=r.types.filter(isExactType);e.length<r.types.length&&i.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),i.push(r)}else i=r.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return flatMap(i,function(r){return _splitParams(e,t+1,n.concat([r]))})}else return[n]}return _splitParams(e,0,[])}function conflicting(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=getTypeSetAtIndex(e,r),i=getTypeSetAtIndex(t,r),a=!1,o;for(o of i)if(n.has(o)){a=!0;break}if(!a)return!1}let r=e.length,i=t.length,a=hasRestParam(e),o=hasRestParam(t);return a?o?r===i:i>=r:o?r>=i:r===i}function clearResolutions(e){return e.map(e=>isReferToSelf(e)?referToSelf(e.referToSelf.callback):isReferTo(e)?makeReferTo(e.referTo.references,e.referTo.callback):e)}function collectResolutions(e,t,n){let r=[],i;for(i of e){let e=n[i];if(typeof e!=`number`)throw TypeError(`No definition for referenced signature "`+i+`"`);if(e=t[e],typeof e!=`function`)return!1;r.push(e)}return r}function resolveReferences(e,t,n){let r=clearResolutions(e),i=Array(r.length).fill(!1),a=!0;for(;a;){a=!1;let e=!0;for(let o=0;o<r.length;++o){if(i[o])continue;let s=r[o];if(isReferToSelf(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(isReferTo(s)){let n=collectResolutions(s.referTo.references,r,t);n?(r[o]=s.referTo.callback.apply(this,n),r[o].referTo=s.referTo,i[o]=!0,e=!1):a=!0}}if(e&&a)throw SyntaxError(`Circular reference detected in resolving typed.referTo`)}return r}function validateDeprecatedThis(e){let t=/\bthis(\(|\.signatures\b)/;Object.keys(e).forEach(n=>{let r=e[n];if(t.test(r.toString()))throw SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.")})}function createTypedFunction(e,t){if(o.createCount++,Object.keys(t).length===0)throw SyntaxError(`No signatures provided`);o.warnAgainstDeprecatedThis&&validateDeprecatedThis(t);let n=[],r=[],i={},a=[],s;for(s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let e=parseSignature(s);if(!e)continue;n.forEach(function(t){if(conflicting(t,e))throw TypeError(`Conflicting signatures "`+stringifyParams(t)+`" and "`+stringifyParams(e)+`".`)}),n.push(e);let o=r.length;r.push(t[s]);let c=e.map(expandParam),l;for(l of splitParams(c)){let e=stringifyParams(l);a.push({params:l,name:e,fn:o}),l.every(e=>!e.hasConversion)&&(i[e]=o)}}a.sort(compareSignatures);let c=resolveReferences(r,i,theTypedFn),l;for(l in i)Object.prototype.hasOwnProperty.call(i,l)&&(i[l]=c[i[l]]);let u=[],d=new Map;for(l of a)d.has(l.name)||(l.fn=c[l.fn],u.push(l),d.set(l.name,l));let f=u[0]&&u[0].params.length<=2&&!hasRestParam(u[0].params),p=u[1]&&u[1].params.length<=2&&!hasRestParam(u[1].params),m=u[2]&&u[2].params.length<=2&&!hasRestParam(u[2].params),h=u[3]&&u[3].params.length<=2&&!hasRestParam(u[3].params),g=u[4]&&u[4].params.length<=2&&!hasRestParam(u[4].params),_=u[5]&&u[5].params.length<=2&&!hasRestParam(u[5].params),v=f&&p&&m&&h&&g&&_;for(let e=0;e<u.length;++e)u[e].test=compileTests(u[e].params);let y=f?compileTest(u[0].params[0]):notOk,b=p?compileTest(u[1].params[0]):notOk,x=m?compileTest(u[2].params[0]):notOk,S=h?compileTest(u[3].params[0]):notOk,C=g?compileTest(u[4].params[0]):notOk,w=_?compileTest(u[5].params[0]):notOk,T=f?compileTest(u[0].params[1]):notOk,E=p?compileTest(u[1].params[1]):notOk,D=m?compileTest(u[2].params[1]):notOk,O=h?compileTest(u[3].params[1]):notOk,k=g?compileTest(u[4].params[1]):notOk,A=_?compileTest(u[5].params[1]):notOk;for(let e=0;e<u.length;++e)u[e].implementation=compileArgsPreprocessing(u[e].params,u[e].fn);let ee=f?u[0].implementation:undef,te=p?u[1].implementation:undef,ne=m?u[2].implementation:undef,re=h?u[3].implementation:undef,ie=g?u[4].implementation:undef,ae=_?u[5].implementation:undef,oe=f?u[0].params.length:-1,se=p?u[1].params.length:-1,j=m?u[2].params.length:-1,ce=h?u[3].params.length:-1,M=g?u[4].params.length:-1,N=_?u[5].params.length:-1,le=v?6:0,ue=u.length,de=u.map(e=>e.test),fe=u.map(e=>e.implementation),pe=function generic$1(){for(let e=le;e<ue;e++)if(de[e](arguments))return fe[e].apply(this,arguments);return o.onMismatch(e,arguments,u)};function theTypedFn(e,t){return arguments.length===oe&&y(e)&&T(t)?ee.apply(this,arguments):arguments.length===se&&b(e)&&E(t)?te.apply(this,arguments):arguments.length===j&&x(e)&&D(t)?ne.apply(this,arguments):arguments.length===ce&&S(e)&&O(t)?re.apply(this,arguments):arguments.length===M&&C(e)&&k(t)?ie.apply(this,arguments):arguments.length===N&&w(e)&&A(t)?ae.apply(this,arguments):pe.apply(this,arguments)}try{Object.defineProperty(theTypedFn,`name`,{value:e})}catch{}return theTypedFn.signatures=i,theTypedFn._typedFunctionData={signatures:u,signatureMap:d},theTypedFn}function _onMismatch(e,t,n){throw createError(e,t,n)}function initial(e){return slice(e,0,e.length-1)}function last(e){return e[e.length-1]}function slice(e,t,n){return Array.prototype.slice.call(e,t,n)}function findInArray(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function flatMap(e,t){return Array.prototype.concat.apply([],e.map(t))}function referTo(){let e=initial(arguments).map(e=>stringifyParams(parseSignature(e))),t=last(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return makeReferTo(e,t)}function makeReferTo(e,t){return{referTo:{references:e,callback:t}}}function referToSelf(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function isReferTo(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function isReferToSelf(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function checkName(e,t){if(!e)return t;if(t&&t!==e){let n=Error(`Function names do not match (expected: `+e+`, actual: `+t+`)`);throw n.data={actual:t,expected:e},n}return e}function getObjectName(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(isTypedFunction(e[n])||typeof e[n].signature==`string`)&&(t=checkName(t,e[n].name));return t}function mergeSignatures(e,t){let n;for(n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(n in e&&t[n]!==e[n]){let r=Error(`Signature "`+n+`" is defined twice`);throw r.data={signature:n,sourceFunction:t[n],destFunction:e[n]},r}e[n]=t[n]}}let s=o;o=__name(function(e){let t=typeof e==`string`,n=t?1:0,r=t?e:``,i={};for(let e=n;e<arguments.length;++e){let n=arguments[e],a={},o;if(typeof n==`function`?(o=n.name,typeof n.signature==`string`?a[n.signature]=n:isTypedFunction(n)&&(a=n.signatures)):isPlainObject$1(n)&&(a=n,t||(o=getObjectName(n))),Object.keys(a).length===0){let t=TypeError(`Argument to 'typed' at index `+e+` is not a (typed) function, nor an object with signatures as keys and functions as values.`);throw t.data={index:e,argument:n},t}t||(r=checkName(r,o)),mergeSignatures(i,a)}return createTypedFunction(r||``,i)},`typed`),o.create=create,o.createCount=s.createCount,o.onMismatch=_onMismatch,o.throwMismatchError=_onMismatch,o.createError=createError,o.clear=clear,o.clearConversions=clearConversions,o.addTypes=addTypes,o._findType=findType,o.referTo=referTo,o.referToSelf=referToSelf,o.convert=convert,o.findSignature=findSignature,o.find=find,o.isTypedFunction=isTypedFunction,o.warnAgainstDeprecatedThis=!0,o.addType=function(e,t){let n=`any`;t!==!1&&r.has(`Object`)&&(n=`Object`),o.addTypes([e],n)};function _validateConversion(e){if(!e||typeof e.from!=`string`||typeof e.to!=`string`||typeof e.convert!=`function`)throw TypeError(`Object with properties {from: string, to: string, convert: function} expected`);if(e.to===e.from)throw SyntaxError(`Illegal to define conversion from "`+e.from+`" to itself.`)}return o.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};_validateConversion(e);let n=findType(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)o.removeConversion({from:r.from,to:e.to,convert:r.convert});else throw Error(`There is already a conversion from "`+e.from+`" to "`+n.name+`"`);n.conversionsTo.push({from:e.from,to:n.name,convert:e.convert,index:a++})},o.addConversions=function(e,t){e.forEach(e=>o.addConversion(e,t))},o.removeConversion=function(e){_validateConversion(e);let t=findType(e.to),n=findInArray(t.conversionsTo,t=>t.from===e.from);if(!n)throw Error(`Attempt to remove nonexistent conversion from `+e.from+` to `+e.to);if(n.convert!==e.convert)throw Error(`Conversion to remove does not match existing conversion`);let r=t.conversionsTo.indexOf(n);t.conversionsTo.splice(r,1)},o.resolve=function(t,n){if(!isTypedFunction(t))throw TypeError(e);let r=t._typedFunctionData.signatures;for(let e=0;e<r.length;++e)if(r[e].test(n))return r[e];return null},o}return create()}))}));function isInteger(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function formatNumberToBase(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`}[t],i=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!isInteger(n))throw Error(`size must be an integer`);if(e>2**(n-1)-1||e<-(2**(n-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!isInteger(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),i=`i${n}`}var a=``;return e<0&&(e=-e,a=`-`),`${a}${r}${e.toString(t)}${i}`}function format$2(e,t){if(typeof t==`function`)return t(e);if(e===1/0)return`Infinity`;if(e===-1/0)return`-Infinity`;if(isNaN(e))return`NaN`;var n=`auto`,r,i;if(t&&(t.notation&&(n=t.notation),isNumber$1(t)?r=t:isNumber$1(t.precision)&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return toFixed$1(e,r);case`exponential`:return toExponential$1(e,r);case`engineering`:return toEngineering$1(e,r);case`bin`:return formatNumberToBase(e,2,i);case`oct`:return formatNumberToBase(e,8,i);case`hex`:return formatNumberToBase(e,16,i);case`auto`:return toPrecision(e,r,t&&t).replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}__name(format$2,`format`);function splitNumber(e){var t=String(e).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);if(!t)throw SyntaxError(`Invalid number `+e);var n=t[1],r=t[2],i=parseFloat(t[4]||`0`),a=r.indexOf(`.`);i+=a===-1?r.length-1:a-1;var o=r.replace(`.`,``).replace(/^0*/,function(e){return i-=e.length,``}).replace(/0*$/,``).split(``).map(function(e){return parseInt(e)});return o.length===0&&(o.push(0),i++),{sign:n,coefficients:o,exponent:i}}function toEngineering$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=roundDigits(splitNumber(e),t),r=n.exponent,i=n.coefficients,a=r%3==0?r:r<0?r-3-r%3:r-r%3;if(isNumber$1(t))for(;t>i.length||r-a+1>i.length;)i.push(0);else for(var o=Math.abs(r-a)-(i.length-1),s=0;s<o;s++)i.push(0);for(var c=Math.abs(r-a),l=1;c>0;)l++,c--;var u=i.slice(l).join(``),d=isNumber$1(t)&&u.length||u.match(/[1-9]/)?`.`+u:``,f=i.slice(0,l).join(``)+d+`e`+(r>=0?`+`:``)+a.toString();return n.sign+f}__name(toEngineering$1,`toEngineering`);function toFixed$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=splitNumber(e),r=typeof t==`number`?roundDigits(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(zeros(o-i.length))),a<0&&(i=zeros(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}__name(toFixed$1,`toFixed`);function toExponential$1(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=splitNumber(e),r=t?roundDigits(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(zeros(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}__name(toExponential$1,`toExponential`);function toPrecision(e,t,n){if(isNaN(e)||!isFinite(e))return String(e);var r=n&&n.lowerExp!==void 0?n.lowerExp:-3,i=n&&n.upperExp!==void 0?n.upperExp:5,a=splitNumber(e),o=t?roundDigits(a,t):a;if(o.exponent<r||o.exponent>=i)return toExponential$1(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(zeros(t-s.length))),s=s.concat(zeros(c-s.length+1+(s.length<t?t-s.length:0))),s=zeros(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function roundDigits(e,t){for(var n={sign:e.sign,coefficients:e.coefficients,exponent:e.exponent},r=n.coefficients;t<=0;)r.unshift(0),n.exponent++,t++;if(r.length>t&&r.splice(t,r.length-t)[0]>=5){var i=t-1;for(r[i]++;r[i]===10;)r.pop(),i===0&&(r.unshift(0),n.exponent++,i++),i--,r[i]++}return n}function zeros(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function digits(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}var Ze=2**-52||2220446049250313e-31;function formatBigNumberToBase(e,t,n){var r=e.constructor,i=new r(2),a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!isInteger(n))throw Error(`size must be an integer`);if(e.greaterThan(i.pow(n-1).sub(1))||e.lessThan(i.pow(n-1).mul(-1)))throw Error(`Value must be in range [-2^${n-1}, 2^${n-1}-1]`);if(!e.isInteger())throw Error(`Value must be an integer`);e.lessThan(0)&&(e=e.add(i.pow(n))),a=`i${n}`}switch(t){case 2:return`${e.toBinary()}${a}`;case 8:return`${e.toOctal()}${a}`;case 16:return`${e.toHexadecimal()}${a}`;default:throw Error(`Base ${t} not supported `)}}function format$1(e,t){if(typeof t==`function`)return t(e);if(!e.isFinite())return e.isNaN()?`NaN`:e.gt(0)?`Infinity`:`-Infinity`;var n=`auto`,r,i;if(t!==void 0&&(t.notation&&(n=t.notation),typeof t==`number`?r=t:t.precision!==void 0&&(r=t.precision),t.wordSize&&(i=t.wordSize,typeof i!=`number`)))throw Error(`Option "wordSize" must be a number`);switch(n){case`fixed`:return toFixed(e,r);case`exponential`:return toExponential(e,r);case`engineering`:return toEngineering(e,r);case`bin`:return formatBigNumberToBase(e,2,i);case`oct`:return formatBigNumberToBase(e,8,i);case`hex`:return formatBigNumberToBase(e,16,i);case`auto`:var a=t&&t.lowerExp!==void 0?t.lowerExp:-3,o=t&&t.upperExp!==void 0?t.upperExp:5;if(e.isZero())return`0`;var s,c=e.toSignificantDigits(r),l=c.e;return s=l>=a&&l<o?c.toFixed():toExponential(e,r),s.replace(/((\.\d*?)(0+))($|e)/,function(){var e=arguments[2],t=arguments[4];return e===`.`?t:e+t});default:throw Error(`Unknown notation "`+n+`". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.`)}}__name(format$1,`format`);function toEngineering(e,t){var n=e.e,r=n%3==0?n:n<0?n-3-n%3:n-n%3,i=e.mul(10**-r).toPrecision(t);if(i.indexOf(`e`)!==-1){var a=e.constructor;i=new a(i).toFixed()}return i+`e`+(n>=0?`+`:``)+r.toString()}function toExponential(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function toFixed(e,t){return e.toFixed(t)}function format(e,t){var n=_format(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function _format(e,t){return typeof e==`number`?format$2(e,t):isBigNumber(e)?format$1(e,t):looksLikeFraction(e)?!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString():Array.isArray(e)?formatArray(e,t):isString$1(e)?stringify(e):typeof e==`function`?e.syntax?String(e.syntax):`function`:e&&typeof e==`object`?typeof e.format==`function`?e.format(t):e&&e.toString(t)!=={}.toString()?e.toString(t):`{`+Object.keys(e).map(n=>stringify(n)+`: `+format(e[n],t)).join(`, `)+`}`:String(e)}function stringify(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in Qe?Qe[i]:i,r++}return`"`+n+`"`}var Qe={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function formatArray(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=formatArray(e[i],t);return n+=`]`,n}else return format(e,t)}function looksLikeFraction(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function DimensionError(e,t,n){if(!(this instanceof DimensionError))throw SyntaxError(`Constructor must be called with the new operator`);this.actual=e,this.expected=t,this.relation=n,this.message=`Dimension mismatch (`+(Array.isArray(e)?`[`+e.join(`, `)+`]`:e)+` `+(this.relation||`!=`)+` `+(Array.isArray(t)?`[`+t.join(`, `)+`]`:t)+`)`,this.stack=Error().stack}DimensionError.prototype=RangeError(),DimensionError.prototype.constructor=RangeError,DimensionError.prototype.name=`DimensionError`,DimensionError.prototype.isDimensionError=!0;function IndexError(e,t,n){if(!(this instanceof IndexError))throw SyntaxError(`Constructor must be called with the new operator`);this.index=e,arguments.length<3?(this.min=0,this.max=t):(this.min=t,this.max=n),this.min!==void 0&&this.index<this.min?this.message=`Index out of range (`+this.index+` < `+this.min+`)`:this.max!==void 0&&this.index>=this.max?this.message=`Index out of range (`+this.index+` > `+(this.max-1)+`)`:this.message=`Index out of range (`+this.index+`)`,this.stack=Error().stack}IndexError.prototype=RangeError(),IndexError.prototype.constructor=RangeError,IndexError.prototype.name=`IndexError`,IndexError.prototype.isIndexError=!0;function arraySize(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function _validate(e,t,n){var r,i=e.length;if(i!==t[n])throw new DimensionError(i,t[n]);if(n<t.length-1){var a=n+1;for(r=0;r<i;r++){var o=e[r];if(!Array.isArray(o))throw new DimensionError(t.length-1,t.length,`<`);_validate(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new DimensionError(t.length+1,t.length,`>`)}function validate(e,t){if(t.length===0){if(Array.isArray(e))throw new DimensionError(e.length,0)}else _validate(e,t,0)}function validateIndex(e,t){if(e!==void 0){if(!isNumber$1(e)||!isInteger(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new IndexError(e,t)}}function resize(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);return t.forEach(function(e){if(!isNumber$1(e)||!isInteger(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+format(t)+`)`)}),(isNumber$1(e)||isBigNumber(e))&&(e=[e]),_resize(e,t,0,n===void 0?0:n),e}function _resize(e,t,n,r){var i,a,o=e.length,s=t[n],c=Math.min(o,s);if(e.length=s,n<t.length-1){var l=n+1;for(i=0;i<c;i++)a=e[i],Array.isArray(a)||(a=[a],e[i]=a),_resize(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,_resize(a,t,l,r)}else{for(i=0;i<c;i++)for(;Array.isArray(e[i]);)e[i]=e[i][0];for(i=c;i<s;i++)e[i]=r}}function reshape(e,t){var n=flatten(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new DimensionError(0,r,`!=`);t=processSizesWildcard(t,r);var i=product(t);if(r!==i)throw new DimensionError(i,r,`!=`);try{return _reshape(n,t)}catch(e){throw e instanceof DimensionError?new DimensionError(i,r,`!=`):e}}function processSizesWildcard(e,t){var n=product(e),r=e.slice(),i=-1,a=e.indexOf(i);if(e.indexOf(i,a+1)>=0)throw Error(`More than one wildcard in sizes`);var o=a>=0,s=t%n===0;if(o)if(s)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function product(e){return e.reduce((e,t)=>e*t,1)}function _reshape(e,t){for(var n=e,r,i=t.length-1;i>0;i--){var a=t[i];r=[];for(var o=n.length/a,s=0;s<o;s++)r.push(n.slice(s*a,(s+1)*a));n=r}return n}function unsqueeze(e,t,n,r){var i=r||arraySize(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=_unsqueeze(e,t,0);i.length<t;)i.push(1);return e}function _unsqueeze(e,t,n){var r,i;if(Array.isArray(e)){var a=n+1;for(r=0,i=e.length;r<i;r++)e[r]=_unsqueeze(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function flatten(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function callback(e){Array.isArray(e)?e.forEach(callback):t.push(e)}),t}function getArrayDataType(e,t){for(var n,r=0,i=0;i<e.length;i++){var a=e[i],o=Array.isArray(a);if(i===0&&o&&(r=a.length),o&&a.length!==r)return;var s=o?getArrayDataType(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function concatRecursive(e,t,n,r){if(r<n){if(e.length!==t.length)throw new DimensionError(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=concatRecursive(e[a],t[a],n,r+1);return i}else return e.concat(t)}function concat(){var e=Array.prototype.slice.call(arguments,0,-1),t=Array.prototype.slice.call(arguments,-1);if(e.length===1)return e[0];if(e.length>1)return e.slice(1).reduce(function(e,n){return concatRecursive(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function broadcastSizes(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t.map(e=>e.length),i=Math.max(...r),a=Array(i).fill(null),o=0;o<t.length;o++)for(var s=t[o],c=r[o],l=0;l<c;l++){var u=i-c+l;s[l]>a[u]&&(a[u]=s[l])}for(var d=0;d<t.length;d++)checkBroadcastingRules(t[d],a);return a}function checkBroadcastingRules(e,t){for(var n=t.length,r=e.length,i=0;i<r;i++){var a=n-r+i;if(e[i]<t[a]&&e[i]>1||e[i]>t[a])throw Error(`shape missmatch: missmatch is found in arg with shape (${e}) not possible to broadcast dimension ${r} with size ${e[i]} to size ${t[a]}`)}}function broadcastTo(e,t){var n=arraySize(e);if(deepStrictEqual(n,t))return e;checkBroadcastingRules(n,t);var r=broadcastSizes(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=clone$1(e);n.length<i&&(o=reshape(o,a),n=arraySize(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=stretch(o,r[s],s),n=arraySize(o));return o}function stretch(e,t,n){return concat(...Array(t).fill(e),n)}function clone$1(e){return(0,Je.default)([],e)}__name(clone$1,`clone`);function factory(e,t,n,r){function assertAndCreate(r){var i=pickShallow(r,t.map(stripOptionalNotation));return assertDependencies(e,t,r),n(i)}return assertAndCreate.isFactory=!0,assertAndCreate.fn=e,assertAndCreate.dependencies=t.slice().sort(),r&&(assertAndCreate.meta=r),assertAndCreate}function assertDependencies(e,t,n){if(!t.filter(e=>!isOptionalDependency(e)).every(e=>n[e]!==void 0)){var r=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${r.map(e=>`"${e}"`).join(`, `)}.`)}}function isOptionalDependency(e){return e&&e[0]===`?`}function stripOptionalNotation(e){return e&&e[0]===`?`?e.slice(1):e}function getSafeProperty(e,t){if(isPlainObject(e)&&isSafeProperty(e,t))return e[t];throw typeof e[t]==`function`&&isSafeMethod(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function setSafeProperty(e,t,n){if(isPlainObject(e)&&isSafeProperty(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function hasSafeProperty(e,t){return t in e}function isSafeProperty(e,t){return!e||typeof e!=`object`?!1:hasOwnProperty($e,t)?!0:!(t in Object.prototype||t in Function.prototype)}function isSafeMethod(e,t){return e==null||typeof e[t]!=`function`||hasOwnProperty(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:hasOwnProperty(et,t)?!0:!(t in Object.prototype||t in Function.prototype)}function isPlainObject(e){return typeof e==`object`&&e&&e.constructor===Object}var $e={length:!0,name:!0},et={toString:!0,valueOf:!0,toLocaleString:!0},ObjectWrappingMap=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return getSafeProperty(this.wrappedObject,e)}set(e,t){return setSafeProperty(this.wrappedObject,e,t),this}has(e){return hasSafeProperty(this.wrappedObject,e)}};function isMap(e){return e?e instanceof Map||e instanceof ObjectWrappingMap||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var tt=__toESM(Xe(),1),nt=function _createTyped(){return nt=tt.default.create,tt.default},rt=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],it=factory(`typed`,rt,function createTyped$1(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=nt();return a.clear(),a.addTypes([{name:`number`,test:isNumber$1},{name:`Complex`,test:isComplex},{name:`BigNumber`,test:isBigNumber},{name:`Fraction`,test:isFraction},{name:`Unit`,test:isUnit},{name:`identifier`,test:e=>isString$1&&/^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])*$/.test(e)},{name:`string`,test:isString$1},{name:`Chain`,test:isChain},{name:`Array`,test:R},{name:`Matrix`,test:isMatrix},{name:`DenseMatrix`,test:isDenseMatrix},{name:`SparseMatrix`,test:isSparseMatrix},{name:`Range`,test:isRange},{name:`Index`,test:isIndex},{name:`boolean`,test:isBoolean},{name:`ResultSet`,test:isResultSet},{name:`Help`,test:isHelp},{name:`function`,test:isFunction},{name:`Date`,test:isDate},{name:`RegExp`,test:isRegExp},{name:`null`,test:isNull},{name:`undefined`,test:isUndefined},{name:`AccessorNode`,test:isAccessorNode},{name:`ArrayNode`,test:isArrayNode},{name:`AssignmentNode`,test:isAssignmentNode},{name:`BlockNode`,test:isBlockNode},{name:`ConditionalNode`,test:isConditionalNode},{name:`ConstantNode`,test:isConstantNode},{name:`FunctionNode`,test:isFunctionNode},{name:`FunctionAssignmentNode`,test:isFunctionAssignmentNode},{name:`IndexNode`,test:isIndexNode},{name:`Node`,test:isNode},{name:`ObjectNode`,test:isObjectNode},{name:`OperatorNode`,test:isOperatorNode},{name:`ParenthesisNode`,test:isParenthesisNode},{name:`RangeNode`,test:isRangeNode},{name:`RelationalNode`,test:isRelationalNode},{name:`SymbolNode`,test:isSymbolNode},{name:`Map`,test:isMap},{name:`Object`,test:isObject$2}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function convert(e){if(t||throwNoBignumber(e),digits(e)>15)throw TypeError(`Cannot implicitly convert a number with >15 significant digits to BigNumber (value: `+e+`). Use function bignumber(x) to convert to BigNumber.`);return new t(e)}},{from:`number`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function convert(e){throw TypeError(`Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.`)}},{from:`Fraction`,to:`Complex`,convert:function convert(e){return n||throwNoComplex(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function convert(e){i||throwNoFraction(e);var t=new i(e);if(t.valueOf()!==e)throw TypeError(`Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: `+e+`). Use function fraction(x) to convert to Fraction.`);return t}},{from:`string`,to:`number`,convert:function convert(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function convert(e){t||throwNoBignumber(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function convert(e){i||throwNoFraction(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function convert(e){n||throwNoComplex(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function convert(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function convert(e){return t||throwNoBignumber(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function convert(e){return i||throwNoFraction(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function convert(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function convert(e){return r||throwNoMatrix(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function convert(e){return e.valueOf()}}]),a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&isCollection(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a.onMismatch=(e,t,n)=>{var r=a.createError(e,t,n);if([`wrongType`,`mismatch`].includes(r.data.category)&&t.length===1&&isCollection(t[0])&&n.some(e=>!e.params.includes(`,`))){var i=TypeError(`Function '${e}' doesn't apply to matrices. To call it elementwise on a matrix 'M', try 'map(M, ${e})'.`);throw i.data=r.data,i}throw r},a});function throwNoBignumber(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function throwNoComplex(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function throwNoMatrix(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function throwNoFraction(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}var z=9e15,B=1e9,at=`0123456789abcdef`,ot=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,st=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-z,maxE:z,crypto:!1},lt,V,H=!0,ut=`[DecimalError] `,U=ut+`Invalid argument: `,dt=ut+`Precision limit exceeded`,ft=ut+`crypto unavailable`,pt=`[object Decimal]`,W=Math.floor,G=Math.pow,mt=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,ht=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,gt=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,_t=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,K=1e7,q=7,vt=9007199254740991,yt=ot.length-1,bt=st.length-1,J={toStringTag:pt};J.absoluteValue=J.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),finalise(e)},J.ceil=function(){return finalise(new this.constructor(this),this.e+1,2)},J.clampedTo=J.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(U+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},J.comparedTo=J.cmp=function(e){var t,n,r,i,a=this,o=a.d,s=(e=new a.constructor(e)).d,c=a.s,l=e.s;if(!o||!s)return!c||!l?NaN:c===l?o===s?0:!o^c<0?1:-1:c;if(!o[0]||!s[0])return o[0]?c:s[0]?-l:0;if(c!==l)return c;if(a.e!==e.e)return a.e>e.e^c<0?1:-1;for(r=o.length,i=s.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==s[t])return o[t]>s[t]^c<0?1:-1;return r===i?0:r>i^c<0?1:-1},J.cosine=J.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+q,r.rounding=1,n=cosine(r,toLessThanHalfPi(r,n)),r.precision=e,r.rounding=t,finalise(V==2||V==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},J.cubeRoot=J.cbrt=function(){var e,t,n,r,i,a,o,s,c,l,u=this,d=u.constructor;if(!u.isFinite()||u.isZero())return new d(u);for(H=!1,a=u.s*G(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=digitsToString(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=G(n,1/3),e=W((e+1)/3)-(e%3==(e<0?-1:2)),a==1/0?n=`5e`+e:(n=a.toExponential(),n=n.slice(0,n.indexOf(`e`)+1)+e),r=new d(n),r.s=u.s):r=new d(a.toString()),o=(e=d.precision)+3;;)if(s=r,c=s.times(s).times(s),l=c.plus(u),r=Y(l.plus(u).times(s),l.plus(c),o+2,1),digitsToString(s.d).slice(0,o)===(n=digitsToString(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(finalise(s,e+1,0),s.times(s).times(s).eq(u))){r=s;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)==`5`)&&(finalise(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return H=!0,finalise(r,e,d.rounding,t)},J.decimalPlaces=J.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-W(this.e/q))*q,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},J.dividedBy=J.div=function(e){return Y(this,new this.constructor(e))},J.dividedToIntegerBy=J.divToInt=function(e){var t=this,n=t.constructor;return finalise(Y(t,new n(e),0,1,1),n.precision,n.rounding)},J.equals=J.eq=function(e){return this.cmp(e)===0},J.floor=function(){return finalise(new this.constructor(this),this.e+1,3)},J.greaterThan=J.gt=function(e){return this.cmp(e)>0},J.greaterThanOrEqualTo=J.gte=function(e){var t=this.cmp(e);return t==1||t===0},J.hyperbolicCosine=J.cosh=function(){var e,t,n,r,i,a=this,o=a.constructor,s=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return s;n=o.precision,r=o.rounding,o.precision=n+Math.max(a.e,a.sd())+4,o.rounding=1,i=a.d.length,i<32?(e=Math.ceil(i/3),t=(1/tinyPow(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=taylorSeries(o,1,a.times(t),new o(1),!0);for(var c,l=e,u=new o(8);l--;)c=a.times(a),a=s.minus(c.times(u.minus(c.times(u))));return finalise(a,o.precision=n,o.rounding=r,!0)},J.hyperbolicSine=J.sinh=function(){var e,t,n,r,i=this,a=i.constructor;if(!i.isFinite()||i.isZero())return new a(i);if(t=a.precision,n=a.rounding,a.precision=t+Math.max(i.e,i.sd())+4,a.rounding=1,r=i.d.length,r<3)i=taylorSeries(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/tinyPow(5,e)),i=taylorSeries(a,2,i,i,!0);for(var o,s=new a(5),c=new a(16),l=new a(20);e--;)o=i.times(i),i=i.times(s.plus(o.times(c.times(o).plus(l))))}return a.precision=t,a.rounding=n,finalise(i,t,n,!0)},J.hyperbolicTangent=J.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,Y(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},J.inverseCosine=J.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?getPi(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2)):n===0?e.isNeg()?getPi(t,r,i):new t(0):new t(NaN)},J.inverseHyperbolicCosine=J.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},J.inverseHyperbolicSine=J.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,r.precision=e,r.rounding=t,n.ln())},J.inverseHyperbolicTangent=J.atanh=function(){var e,t,n,r,i=this,a=i.constructor;return i.isFinite()?i.e>=0?new a(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=a.precision,t=a.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?finalise(new a(i),e,t,!0):(a.precision=n=r-i.e,i=Y(i.plus(1),new a(1).minus(i),n+e,1),a.precision=e+4,a.rounding=1,i=i.ln(),a.precision=e,a.rounding=t,i.times(.5))):new a(NaN)},J.inverseSine=J.asin=function(){var e,t,n,r,i=this,a=i.constructor;return i.isZero()?new a(i):(t=i.abs().cmp(1),n=a.precision,r=a.rounding,t===-1?(a.precision=n+6,a.rounding=1,i=i.div(new a(1).minus(i.times(i)).sqrt().plus(1)).atan(),a.precision=n,a.rounding=r,i.times(2)):t===0?(e=getPi(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},J.inverseTangent=J.atan=function(){var e,t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding;if(l.isFinite()){if(l.isZero())return new u(l);if(l.abs().eq(1)&&d+4<=bt)return o=getPi(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=bt)return o=getPi(u,d+4,f).times(.5),o.s=l.s,o}for(u.precision=s=d+10,u.rounding=1,n=Math.min(28,s/q+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(H=!1,t=Math.ceil(s/q),r=1,c=l.times(l),o=new u(l),i=l;e!==-1;)if(i=i.times(c),a=o.minus(i.div(r+=2)),i=i.times(c),o=a.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===a.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),H=!0,finalise(o,u.precision=d,u.rounding=f,!0)},J.isFinite=function(){return!!this.d},J.isInteger=J.isInt=function(){return!!this.d&&W(this.e/q)>this.d.length-2},J.isNaN=function(){return!this.s},J.isNegative=J.isNeg=function(){return this.s<0},J.isPositive=J.isPos=function(){return this.s>0},J.isZero=function(){return!!this.d&&this.d[0]===0},J.lessThan=J.lt=function(e){return this.cmp(e)<0},J.lessThanOrEqualTo=J.lte=function(e){return this.cmp(e)<1},J.logarithm=J.log=function(e){var t,n,r,i,a,o,s,c,l=this,u=l.constructor,d=u.precision,f=u.rounding,p=5;if(e==null)e=new u(10),t=!0;else{if(e=new u(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new u(NaN);t=e.eq(10)}if(n=l.d,l.s<0||!n||!n[0]||l.eq(1))return new u(n&&!n[0]?-1/0:l.s==1?n?0:1/0:NaN);if(t)if(n.length>1)a=!0;else{for(i=n[0];i%10==0;)i/=10;a=i!==1}if(H=!1,s=d+p,o=naturalLogarithm(l,s),r=t?getLn10(u,s+10):naturalLogarithm(e,s),c=Y(o,r,s,1),checkRoundingDigits(c.d,i=d,f))do if(s+=10,o=naturalLogarithm(l,s),r=t?getLn10(u,s+10):naturalLogarithm(e,s),c=Y(o,r,s,1),!a){+digitsToString(c.d).slice(i+1,i+15)+1==0x5af3107a4000&&(c=finalise(c,d+1,0));break}while(checkRoundingDigits(c.d,i+=10,f));return H=!0,finalise(c,d,f)},J.minus=J.sub=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.constructor;if(e=new m(e),!p.d||!e.d)return!p.s||!e.s?e=new m(NaN):p.d?e.s=-e.s:e=new m(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(l=p.d,f=e.d,s=m.precision,c=m.rounding,!l[0]||!f[0]){if(f[0])e.s=-e.s;else if(l[0])e=new m(p);else return new m(c===3?-0:0);return H?finalise(e,s,c):e}if(n=W(e.e/q),u=W(p.e/q),l=l.slice(),a=u-n,a){for(d=a<0,d?(t=l,a=-a,o=f.length):(t=f,n=u,o=l.length),r=Math.max(Math.ceil(s/q),o)+2,a>r&&(a=r,t.length=1),t.reverse(),r=a;r--;)t.push(0);t.reverse()}else{for(r=l.length,o=f.length,d=r<o,d&&(o=r),r=0;r<o;r++)if(l[r]!=f[r]){d=l[r]<f[r];break}a=0}for(d&&(t=l,l=f,f=t,e.s=-e.s),o=l.length,r=f.length-o;r>0;--r)l[o++]=0;for(r=f.length;r>a;){if(l[--r]<f[r]){for(i=r;i&&l[--i]===0;)l[i]=K-1;--l[i],l[r]+=K}l[r]-=f[r]}for(;l[--o]===0;)l.pop();for(;l[0]===0;l.shift())--n;return l[0]?(e.d=l,e.e=getBase10Exponent(l,n),H?finalise(e,s,c):e):new m(c===3?-0:0)},J.modulo=J.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?finalise(new r(n),r.precision,r.rounding):(H=!1,r.modulo==9?(t=Y(n,e.abs(),0,3,1),t.s*=e.s):t=Y(n,e,0,r.modulo,1),t=t.times(e),H=!0,n.minus(t))},J.naturalExponential=J.exp=function(){return naturalExponential(this)},J.naturalLogarithm=J.ln=function(){return naturalLogarithm(this)},J.negated=J.neg=function(){var e=new this.constructor(this);return e.s=-e.s,finalise(e)},J.plus=J.add=function(e){var t,n,r,i,a,o,s,c,l,u,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(l=d.d,u=e.d,s=f.precision,c=f.rounding,!l[0]||!u[0])return u[0]||(e=new f(d)),H?finalise(e,s,c):e;if(a=W(d.e/q),r=W(e.e/q),l=l.slice(),i=a-r,i){for(i<0?(n=l,i=-i,o=u.length):(n=u,r=a,o=l.length),a=Math.ceil(s/q),o=a>o?a+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=l.length,i=u.length,o-i<0&&(i=o,n=u,u=l,l=n),t=0;i;)t=(l[--i]=l[i]+u[i]+t)/K|0,l[i]%=K;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=getBase10Exponent(l,r),H?finalise(e,s,c):e},J.precision=J.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(U+e);return n.d?(t=getPrecision(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},J.round=function(){var e=this,t=e.constructor;return finalise(new t(e),e.e+1,t.rounding)},J.sine=J.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+q,r.rounding=1,n=sine(r,toLessThanHalfPi(r,n)),r.precision=e,r.rounding=t,finalise(V>2?n.neg():n,e,t,!0)):new r(NaN)},J.squareRoot=J.sqrt=function(){var e,t,n,r,i,a,o=this,s=o.d,c=o.e,l=o.s,u=o.constructor;if(l!==1||!s||!s[0])return new u(!l||l<0&&(!s||s[0])?NaN:s?o:1/0);for(H=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=digitsToString(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=W((c+1)/2)-(c<0||c%2),l==1/0?t=`5e`+c:(t=l.toExponential(),t=t.slice(0,t.indexOf(`e`)+1)+c),r=new u(t)):r=new u(l.toString()),n=(c=u.precision)+3;;)if(a=r,r=a.plus(Y(o,a,n+2,1)).times(.5),digitsToString(a.d).slice(0,n)===(t=digitsToString(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(finalise(a,c+1,0),a.times(a).eq(o))){r=a;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)==`5`)&&(finalise(r,c+1,1),e=!r.times(r).eq(o));break}return H=!0,finalise(r,c,u.rounding,e)},J.tangent=J.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=Y(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,finalise(V==2||V==4?n.neg():n,e,t,!0)):new r(NaN)},J.times=J.mul=function(e){var t,n,r,i,a,o,s,c,l,u=this,d=u.constructor,f=u.d,p=(e=new d(e)).d;if(e.s*=u.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=W(u.e/q)+W(e.e/q),c=f.length,l=p.length,c<l&&(a=f,f=p,p=a,o=c,c=l,l=o),a=[],o=c+l,r=o;r--;)a.push(0);for(r=l;--r>=0;){for(t=0,i=c+r;i>r;)s=a[i]+p[r]*f[i-r-1]+t,a[i--]=s%K|0,t=s/K|0;a[i]=(a[i]+t)%K|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=getBase10Exponent(a,n),H?finalise(e,d.precision,d.rounding):e},J.toBinary=function(e,t){return toStringBinary(this,2,e,t)},J.toDecimalPlaces=J.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(checkInt32(e,0,B),t===void 0?t=r.rounding:checkInt32(t,0,8),finalise(n,e+n.e+1,t))},J.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=finiteToString(r,!0):(checkInt32(e,0,B),t===void 0?t=i.rounding:checkInt32(t,0,8),r=finalise(new i(r),e+1,t),n=finiteToString(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},J.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=finiteToString(i):(checkInt32(e,0,B),t===void 0?t=a.rounding:checkInt32(t,0,8),r=finalise(new a(i),e+i.e+1,t),n=finiteToString(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},J.toFraction=function(e){var t,n,r,i,a,o,s,c,l,u,d,f,p=this,m=p.d,h=p.constructor;if(!m)return new h(p);if(l=n=new h(1),r=c=new h(0),t=new h(r),a=t.e=getPrecision(m)-p.e-1,o=a%q,t.d[0]=G(10,o<0?q+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(U+s);e=s.gt(t)?a>0?t:l:s}for(H=!1,s=new h(digitsToString(m)),u=h.precision,h.precision=a=m.length*q*2;d=Y(s,t,0,1,1),i=n.plus(d.times(r)),i.cmp(e)!=1;)n=r,r=i,i=l,l=c.plus(d.times(i)),c=i,i=t,t=s.minus(d.times(i)),s=i;return i=Y(e.minus(n),r,0,1,1),c=c.plus(i.times(l)),n=n.plus(i.times(r)),c.s=l.s=p.s,f=Y(l,r,a,1).minus(p).abs().cmp(Y(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,H=!0,f},J.toHexadecimal=J.toHex=function(e,t){return toStringBinary(this,16,e,t)},J.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:checkInt32(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(H=!1,n=Y(n,e,0,t,1).times(e),H=!0,finalise(n)):(e.s=n.s,n=e),n},J.toNumber=function(){return+this},J.toOctal=function(e,t){return toStringBinary(this,8,e,t)},J.toPower=J.pow=function(e){var t,n,r,i,a,o,s=this,c=s.constructor,l=+(e=new c(e));if(!s.d||!e.d||!s.d[0]||!e.d[0])return new c(G(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return finalise(s,r,a);if(t=W(e.e/q),t>=e.d.length-1&&(n=l<0?-l:l)<=vt)return i=intPow(c,s,n,r),e.s<0?new c(1).div(i):finalise(i,r,a);if(o=s.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),s.e==0&&s.d[0]==1&&s.d.length==1)return s.s=o,s}return n=G(+s,l),t=n==0||!isFinite(n)?W(l*(Math.log(`0.`+digitsToString(s.d))/Math.LN10+s.e+1)):new c(n+``).e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(H=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=naturalExponential(e.times(naturalLogarithm(s,r+n)),r),i.d&&(i=finalise(i,r+5,1),checkRoundingDigits(i.d,r,a)&&(t=r+10,i=finalise(naturalExponential(e.times(naturalLogarithm(s,t+n)),t),t+5,1),+digitsToString(i.d).slice(r+1,r+15)+1==0x5af3107a4000&&(i=finalise(i,r+1,0)))),i.s=o,H=!0,c.rounding=a,finalise(i,r,a))},J.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=finiteToString(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(checkInt32(e,1,B),t===void 0?t=i.rounding:checkInt32(t,0,8),r=finalise(new i(r),e,t),n=finiteToString(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},J.toSignificantDigits=J.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(checkInt32(e,1,B),t===void 0?t=r.rounding:checkInt32(t,0,8)),finalise(new r(n),e,t)},J.toString=function(){var e=this,t=e.constructor,n=finiteToString(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},J.truncated=J.trunc=function(){return finalise(new this.constructor(this),this.e+1,1)},J.valueOf=J.toJSON=function(){var e=this,t=e.constructor,n=finiteToString(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function digitsToString(e){var t,n,r,i=e.length-1,a=``,o=e[0];if(i>0){for(a+=o,t=1;t<i;t++)r=e[t]+``,n=q-r.length,n&&(a+=getZeroString(n)),a+=r;o=e[t],r=o+``,n=q-r.length,n&&(a+=getZeroString(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function checkInt32(e,t,n){if(e!==~~e||e<t||e>n)throw Error(U+e)}function checkRoundingDigits(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=q,i=0):(i=Math.ceil((t+1)/q),t%=q),a=G(10,q-t),s=e[i]%a|0,r==null?t<3?(t==0?s=s/100|0:t==1&&(s=s/10|0),o=n<4&&s==99999||n>3&&s==49999||s==5e4||s==0):o=(n<4&&s+1==a||n>3&&s+1==a/2)&&(e[i+1]/a/100|0)==G(10,t-2)-1||(s==a/2||s==0)&&(e[i+1]/a/100|0)==0:t<4?(t==0?s=s/1e3|0:t==1?s=s/100|0:t==2&&(s=s/10|0),o=(r||n<4)&&s==9999||!r&&n>3&&s==4999):o=((r||n<4)&&s+1==a||!r&&n>3&&s+1==a/2)&&(e[i+1]/a/1e3|0)==G(10,t-3)-1,o}function convertBase(e,t,n){for(var r,i=[0],a,o=0,s=e.length;o<s;){for(a=i.length;a--;)i[a]*=t;for(i[0]+=at.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function cosine(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/tinyPow(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=taylorSeries(e,1,t.times(i),new e(1));for(var a=n;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var Y=(function(){function multiplyInteger(e,t,n){var r,i=0,a=e.length;for(e=e.slice();a--;)r=e[a]*t+i,e[a]=r%n|0,i=r/n|0;return i&&e.unshift(i),e}function compare(e,t,n,r){var i,a;if(n!=r)a=n>r?1:-1;else for(i=a=0;i<n;i++)if(e[i]!=t[i]){a=e[i]>t[i]?1:-1;break}return a}function subtract(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;)e.shift()}return function(e,t,n,r,i,a){var o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E=e.constructor,D=e.s==t.s?1:-1,O=e.d,k=t.d;if(!O||!O[0]||!k||!k[0])return new E(!e.s||!t.s||(O?k&&O[0]==k[0]:!k)?NaN:O&&O[0]==0||!k?D*0:D/0);for(a?(u=1,s=e.e-t.e):(a=K,u=q,s=W(e.e/u)-W(t.e/u)),w=k.length,S=O.length,m=new E(D),h=m.d=[],c=0;k[c]==(O[c]||0);c++);if(k[c]>(O[c]||0)&&s--,n==null?(y=n=E.precision,r=E.rounding):y=i?n+(e.e-t.e)+1:n,y<0)h.push(1),d=!0;else{if(y=y/u+2|0,c=0,w==1){for(l=0,k=k[0],y++;(c<S||l)&&y--;c++)b=l*a+(O[c]||0),h[c]=b/k|0,l=b%k|0;d=l||c<S}else{for(l=a/(k[0]+1)|0,l>1&&(k=multiplyInteger(k,l,a),O=multiplyInteger(O,l,a),w=k.length,S=O.length),x=w,g=O.slice(0,w),_=g.length;_<w;)g[_++]=0;T=k.slice(),T.unshift(0),C=k[0],k[1]>=a/2&&++C;do l=0,o=compare(k,g,w,_),o<0?(v=g[0],w!=_&&(v=v*a+(g[1]||0)),l=v/C|0,l>1?(l>=a&&(l=a-1),f=multiplyInteger(k,l,a),p=f.length,_=g.length,o=compare(f,g,p,_),o==1&&(l--,subtract(f,w<p?T:k,p,a))):(l==0&&(o=l=1),f=k.slice()),p=f.length,p<_&&f.unshift(0),subtract(g,f,_,a),o==-1&&(_=g.length,o=compare(k,g,w,_),o<1&&(l++,subtract(g,w<_?T:k,_,a))),_=g.length):o===0&&(l++,g=[0]),h[c++]=l,o&&g[0]?g[_++]=O[x]||0:(g=[O[x]],_=1);while((x++<S||g[0]!==void 0)&&y--);d=g[0]!==void 0}h[0]||h.shift()}if(u==1)m.e=s,lt=d;else{for(c=1,l=h[0];l>=10;l/=10)c++;m.e=c+s*u-1,finalise(m,i?n+m.e+1:n,r,d)}return m}})();function finalise(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor;out:if(t!=null){if(d=e.d,!d)return e;for(i=1,s=d[0];s>=10;s/=10)i++;if(a=t-i,a<0)a+=q,o=t,u=d[f=0],c=u/G(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/q),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=q,o=a-q+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=q,o=a-q+i,c=o<0?0:u/G(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%G(10,i-o-1)),l=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(a>0?o>0?u/G(10,i-o):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,l?(t-=e.e+1,d[0]=G(10,(q-t%q)%q),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=G(10,q-a),d[f]=o>0?(u/G(10,i-o)%G(10,o)|0)*s:0),l)for(;;)if(f==0){for(a=1,o=d[0];o>=10;o/=10)a++;for(o=d[0]+=s,s=1;o>=10;o/=10)s++;a!=s&&(e.e++,d[0]==K&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=K)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return H&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function finiteToString(e,t,n){if(!e.isFinite())return nonFiniteToString(e);var r,i=e.e,a=digitsToString(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+getZeroString(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+getZeroString(-i-1)+a,n&&(r=n-o)>0&&(a+=getZeroString(r))):i>=o?(a+=getZeroString(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+getZeroString(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=getZeroString(r))),a}function getBase10Exponent(e,t){var n=e[0];for(t*=q;n>=10;n/=10)t++;return t}function getLn10(e,t,n){if(t>yt)throw H=!0,n&&(e.precision=n),Error(dt);return finalise(new e(ot),t,1,!0)}function getPi(e,t,n){if(t>bt)throw Error(dt);return finalise(new e(st),t,n,!0)}function getPrecision(e){var t=e.length-1,n=t*q+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function getZeroString(e){for(var t=``;e--;)t+=`0`;return t}function intPow(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/q+4);for(H=!1;;){if(n%2&&(a=a.times(t),truncate(a.d,o)&&(i=!0)),n=W(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),truncate(t.d,o)}return H=!0,a}function isOdd(e){return e.d[e.d.length-1]&1}function maxOrMin(e,t,n){for(var r,i,a=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){a=i;break}r=a.cmp(i),(r===n||r===0&&a.s===n)&&(a=i)}return a}function naturalExponential(e,t){var n,r,i,a,o,s,c,l=0,u=0,d=0,f=e.constructor,p=f.rounding,m=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(H=!1,c=m):c=t,s=new f(.03125);e.e>-2;)e=e.times(s),d+=5;for(r=Math.log(G(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=finalise(a.times(e),c,1),n=n.times(++u),s=o.plus(Y(a,n,c,1)),digitsToString(s.d).slice(0,c)===digitsToString(o.d).slice(0,c)){for(i=d;i--;)o=finalise(o.times(o),c,1);if(t==null)if(l<3&&checkRoundingDigits(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return finalise(o,f.precision=m,p,H=!0);else return f.precision=m,o}o=s}}function naturalLogarithm(e,t){var n,r,i,a,o,s,c,l,u,d,f,p=1,m=10,h=e,g=h.d,_=h.constructor,v=_.rounding,y=_.precision;if(h.s<0||!g||!g[0]||!h.e&&g[0]==1&&g.length==1)return new _(g&&!g[0]?-1/0:h.s==1?g?0:h:NaN);if(t==null?(H=!1,u=y):u=t,_.precision=u+=m,n=digitsToString(g),r=n.charAt(0),Math.abs(a=h.e)<0x5543df729c000){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=digitsToString(h.d),r=n.charAt(0),p++;a=h.e,r>1?(h=new _(`0.`+n),a++):h=new _(r+`.`+n.slice(1))}else return l=getLn10(_,u+2,y).times(a+``),h=naturalLogarithm(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?finalise(h,y,v,H=!0):h;for(d=h,c=o=h=Y(h.minus(1),h.plus(1),u,1),f=finalise(h.times(h),u,1),i=3;;){if(o=finalise(o.times(f),u,1),l=c.plus(Y(o,new _(i),u,1)),digitsToString(l.d).slice(0,u)===digitsToString(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(getLn10(_,u+2,y).times(a+``))),c=Y(c,new _(p),u,1),t==null)if(checkRoundingDigits(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Y(d.minus(1),d.plus(1),u,1),f=finalise(h.times(h),u,1),i=s=1;else return finalise(c,_.precision=y,v,H=!0);else return _.precision=y,c;c=l,i+=2}}function nonFiniteToString(e){return String(e.s*e.s/0)}function parseDecimal(e,t){var n,r,i;for((n=t.indexOf(`.`))>-1&&(t=t.replace(`.`,``)),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%q,n<0&&(r+=q),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=q;r<i;)e.d.push(+t.slice(r,r+=q));t=t.slice(r),r=q-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),H&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function parseOther(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),_t.test(t))return parseDecimal(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(ht.test(t))n=16,t=t.toLowerCase();else if(mt.test(t))n=2;else if(gt.test(t))n=8;else throw Error(U+t);for(a=t.search(/p/i),a>0?(c=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf(`.`),o=a>=0,r=e.constructor,o&&(t=t.replace(`.`,``),s=t.length,a=s-a,i=intPow(r,new r(n),a,a*2)),l=convertBase(t,n,K),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=getBase10Exponent(l,u),e.d=l,H=!1,o&&(e=Y(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?G(2,c):X.pow(2,c))),H=!0,e)}function sine(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:taylorSeries(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/tinyPow(5,n)),t=taylorSeries(e,2,t,t);for(var i,a=new e(5),o=new e(16),s=new e(20);n--;)i=t.times(t),t=t.times(a.plus(i.times(o.times(i).minus(s))));return t}function taylorSeries(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/q);for(H=!1,c=n.times(n),s=new e(r);;){if(o=Y(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=Y(o.times(c),new e(t++*t++),u,1),o=s.plus(r),o.d[d]!==void 0){for(a=d;o.d[a]===s.d[a]&&a--;);if(a==-1)break}a=s,s=r,r=o,o=a,l++}return H=!0,o.d.length=d+1,o}function tinyPow(e,t){for(var n=e;--t;)n*=e;return n}function toLessThanHalfPi(e,t){var n,r=t.s<0,i=getPi(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return V=r?4:1,t;if(n=t.divToInt(i),n.isZero())V=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return V=isOdd(n)?r?2:3:r?4:1,t;V=isOdd(n)?r?1:4:r?3:2}return t.minus(i).abs()}function toStringBinary(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(checkInt32(n,1,B),r===void 0?r=p.rounding:checkInt32(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=nonFiniteToString(e);else{for(u=finiteToString(e),o=u.indexOf(`.`),m?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(u=u.replace(`.`,``),f=new p(1),f.e=u.length-o,f.d=convertBase(finiteToString(f),10,i),f.e=f.d.length),d=convertBase(u,10,i),a=c=d.length;d[--c]==0;)d.pop();if(!d[0])u=m?`0p+0`:`0`;else{if(o<0?a--:(e=new p(e),e.d=d,e.e=a,e=Y(e,f,n,r,0,i),d=e.d,a=e.e,l=lt),o=d[n],s=i/2,l||=d[n+1]!==void 0,l=r<4?(o!==void 0||l)&&(r===0||r===(e.s<0?3:2)):o>s||o===s&&(r===4||l||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,l)for(;++d[--n]>i-1;)d[n]=0,n||(++a,d.unshift(1));for(c=d.length;!d[c-1];--c);for(o=0,u=``;o<c;o++)u+=at.charAt(d[o]);if(m){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)u+=`0`;for(d=convertBase(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=at.charAt(d[o])}else u=u.charAt(0)+`.`+u.slice(1);u=u+(a<0?`p`:`p+`)+a}else if(a<0){for(;++a;)u=`0`+u;u=`0.`+u}else if(++a>c)for(a-=c;a--;)u+=`0`;else a<c&&(u=u.slice(0,a)+`.`+u.slice(a))}u=(t==16?`0x`:t==2?`0b`:t==8?`0o`:``)+u}return e.s<0?`-`+u:u}function truncate(e,t){if(e.length>t)return e.length=t,!0}function abs(e){return new this(e).abs()}function acos(e){return new this(e).acos()}function acosh(e){return new this(e).acosh()}function add(e,t){return new this(e).plus(t)}function asin(e){return new this(e).asin()}function asinh(e){return new this(e).asinh()}function atan(e){return new this(e).atan()}function atanh(e){return new this(e).atanh()}function atan2(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,a=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=getPi(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?getPi(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=getPi(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(Y(e,t,a,1)),t=getPi(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(Y(e,t,a,1)),n}function cbrt(e){return new this(e).cbrt()}function ceil(e){return finalise(e=new this(e),e.e+1,2)}function clamp(e,t,n){return new this(e).clamp(t,n)}function config(e){if(!e||typeof e!=`object`)throw Error(ut+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,B,`rounding`,0,8,`toExpNeg`,-z,0,`toExpPos`,0,z,`maxE`,0,z,`minE`,-z,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=ct[n]),(r=e[n])!==void 0)if(W(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(U+n+`: `+r);if(n=`crypto`,i&&(this[n]=ct[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<`u`&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(ft);else this[n]=!1;else throw Error(U+n+`: `+r);return this}function cos(e){return new this(e).cos()}function cosh$1(e){return new this(e).cosh()}__name(cosh$1,`cosh`);function clone(e){var t,n,r;function Decimal$1(e){var t,n,r,i=this;if(!(i instanceof Decimal$1))return new Decimal$1(e);if(i.constructor=Decimal$1,isDecimalInstance(e)){i.s=e.s,H?!e.d||e.e>Decimal$1.maxE?(i.e=NaN,i.d=null):e.e<Decimal$1.minE?(i.e=0,i.d=[0]):(i.e=e.e,i.d=e.d.slice()):(i.e=e.e,i.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){i.s=1/e<0?-1:1,i.e=0,i.d=[0];return}if(e<0?(e=-e,i.s=-1):i.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;H?t>Decimal$1.maxE?(i.e=NaN,i.d=null):t<Decimal$1.minE?(i.e=0,i.d=[0]):(i.e=t,i.d=[e]):(i.e=t,i.d=[e]);return}if(e*0!=0){e||(i.s=NaN),i.e=NaN,i.d=null;return}return parseDecimal(i,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),i.s=-1):(n===43&&(e=e.slice(1)),i.s=1),_t.test(e)?parseDecimal(i,e):parseOther(i,e);if(r===`bigint`)return e<0?(e=-e,i.s=-1):i.s=1,parseDecimal(i,e.toString());throw Error(U+e)}if(__name(Decimal$1,`Decimal`),Decimal$1.prototype=J,Decimal$1.ROUND_UP=0,Decimal$1.ROUND_DOWN=1,Decimal$1.ROUND_CEIL=2,Decimal$1.ROUND_FLOOR=3,Decimal$1.ROUND_HALF_UP=4,Decimal$1.ROUND_HALF_DOWN=5,Decimal$1.ROUND_HALF_EVEN=6,Decimal$1.ROUND_HALF_CEIL=7,Decimal$1.ROUND_HALF_FLOOR=8,Decimal$1.EUCLID=9,Decimal$1.config=Decimal$1.set=config,Decimal$1.clone=clone,Decimal$1.isDecimal=isDecimalInstance,Decimal$1.abs=abs,Decimal$1.acos=acos,Decimal$1.acosh=acosh,Decimal$1.add=add,Decimal$1.asin=asin,Decimal$1.asinh=asinh,Decimal$1.atan=atan,Decimal$1.atanh=atanh,Decimal$1.atan2=atan2,Decimal$1.cbrt=cbrt,Decimal$1.ceil=ceil,Decimal$1.clamp=clamp,Decimal$1.cos=cos,Decimal$1.cosh=cosh$1,Decimal$1.div=div,Decimal$1.exp=exp,Decimal$1.floor=floor,Decimal$1.hypot=hypot$1,Decimal$1.ln=ln,Decimal$1.log=log,Decimal$1.log10=log10,Decimal$1.log2=log2,Decimal$1.max=max,Decimal$1.min=min,Decimal$1.mod=mod,Decimal$1.mul=mul,Decimal$1.pow=pow,Decimal$1.random=random,Decimal$1.round=round,Decimal$1.sign=sign,Decimal$1.sin=sin,Decimal$1.sinh=sinh$1,Decimal$1.sqrt=sqrt,Decimal$1.sub=sub,Decimal$1.sum=sum,Decimal$1.tan=tan,Decimal$1.tanh=tanh,Decimal$1.trunc=trunc,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=[`precision`,`rounding`,`toExpNeg`,`toExpPos`,`maxE`,`minE`,`modulo`,`crypto`],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return Decimal$1.config(e),Decimal$1}function div(e,t){return new this(e).div(t)}function exp(e){return new this(e).exp()}function floor(e){return finalise(e=new this(e),e.e+1,3)}function hypot$1(){var e,t,n=new this(0);for(H=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return H=!0,new this(1/0);n=t}return H=!0,n.sqrt()}__name(hypot$1,`hypot`);function isDecimalInstance(e){return e instanceof X||e&&e.toStringTag===pt||!1}function ln(e){return new this(e).ln()}function log(e,t){return new this(e).log(t)}function log2(e){return new this(e).log(2)}function log10(e){return new this(e).log(10)}function max(){return maxOrMin(this,arguments,-1)}function min(){return maxOrMin(this,arguments,1)}function mod(e,t){return new this(e).mod(t)}function mul(e,t){return new this(e).mul(t)}function pow(e,t){return new this(e).pow(t)}function random(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:checkInt32(e,1,B),r=Math.ceil(e/q),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));a<r;)i=t[a],i>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:s[a++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);a<r;)i=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,a):(s.push(i%1e7),a+=4);a=r/4}else throw Error(ft);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=q,r&&e&&(i=G(10,q-e),s[a]=(r/i|0)*i);s[a]===0;a--)s.pop();if(a<0)n=0,s=[0];else{for(n=-1;s[0]===0;n-=q)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<q&&(n-=q-r)}return o.e=n,o.d=s,o}function round(e){return finalise(e=new this(e),e.e+1,this.rounding)}function sign(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function sin(e){return new this(e).sin()}function sinh$1(e){return new this(e).sinh()}__name(sinh$1,`sinh`);function sqrt(e){return new this(e).sqrt()}function sub(e,t){return new this(e).sub(t)}function sum(){var e=0,t=arguments,n=new this(t[e]);for(H=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return H=!0,finalise(n,this.precision,this.rounding)}function tan(e){return new this(e).tan()}function tanh(e){return new this(e).tanh()}function trunc(e){return finalise(e=new this(e),e.e+1,1)}J[Symbol.for(`nodejs.util.inspect.custom`)]=J.toString,J[Symbol.toStringTag]=`Decimal`;var X=J.constructor=clone(ct);ot=new X(ot),st=new X(st);var xt=X,St=`BigNumber`,Ct=[`?on`,`config`],wt=factory(St,Ct,e=>{var{on:t,config:n}=e,r=xt.clone({precision:n.precision,modulo:xt.EUCLID});return r.prototype=Object.create(r.prototype),r.prototype.type=`BigNumber`,r.prototype.isBigNumber=!0,r.prototype.toJSON=function(){return{mathjs:`BigNumber`,value:this.toString()}},r.fromJSON=function(e){return new r(e.value)},t&&t(`config`,function(e,t){e.precision!==t.precision&&r.config({precision:e.precision})}),r},{isClass:!0});const Z=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Q=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},cosm1=e=>{let t=Math.sin(.5*e);return-2*t*t},hypot=function(e,t){return e=Math.abs(e),t=Math.abs(t),e<t&&([e,t]=[t,e]),e<1e8?Math.sqrt(e*e+t*t):(t/=e,e*Math.sqrt(1+t*t))},parser_exit=function(){throw SyntaxError(`Invalid Param`)};function logHypot(e,t){let n=Math.abs(e),r=Math.abs(t);return e===0?Math.log(r):t===0?Math.log(n):n<3e3&&r<3e3?Math.log(e*e+t*t)*.5:(e*=.5,t*=.5,.5*Math.log(e*e+t*t)+Math.LN2)}const Tt={re:0,im:0},parse=function(e,t){let n=Tt;if(e==null)n.re=n.im=0;else if(t!==void 0)n.re=e,n.im=t;else switch(typeof e){case`object`:if(`im`in e&&`re`in e)n.re=e.re,n.im=e.im;else if(`abs`in e&&`arg`in e){if(!isFinite(e.abs)&&isFinite(e.arg))return Complex$1.INFINITY;n.re=e.abs*Math.cos(e.arg),n.im=e.abs*Math.sin(e.arg)}else if(`r`in e&&`phi`in e){if(!isFinite(e.r)&&isFinite(e.phi))return Complex$1.INFINITY;n.re=e.r*Math.cos(e.phi),n.im=e.r*Math.sin(e.phi)}else e.length===2?(n.re=e[0],n.im=e[1]):parser_exit();break;case`string`:n.im=n.re=0;let t=e.replace(/_/g,``).match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,i=0;t===null&&parser_exit();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
105
105
|
`||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&parser_exit(),t[e+1]!==` `&&!isNaN(t[e+1])?(n.im+=parseFloat((i%2?`-`:``)+t[e+1]),e++):n.im+=parseFloat((i%2?`-`:``)+`1`),r=i=0):((r+i===0||isNaN(a))&&parser_exit(),t[e+1]===`i`||t[e+1]===`I`?(n.im+=parseFloat((i%2?`-`:``)+a),e++):n.re+=parseFloat((i%2?`-`:``)+a),r=i=0))}r+i>0&&parser_exit();break;case`number`:n.im=0,n.re=e;break;default:parser_exit()}return isNaN(n.re)||isNaN(n.im),n};function Complex$1(e,t){if(!(this instanceof Complex$1))return new Complex$1(e,t);let n=parse(e,t);this.re=n.re,this.im=n.im}__name(Complex$1,`Complex`),Complex$1.prototype={re:0,im:0,sign:function(){let e=hypot(this.re,this.im);return new Complex$1(this.re/e,this.im/e)},add:function(e,t){let n=parse(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Complex$1.NAN:Complex$1.INFINITY:new Complex$1(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=parse(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?Complex$1.NAN:Complex$1.INFINITY:new Complex$1(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=parse(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;return r&&o||i&&a?Complex$1.NAN:r||i?Complex$1.INFINITY:n.im===0&&this.im===0?new Complex$1(this.re*n.re,0):new Complex$1(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=parse(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im)),a=this.re===0&&this.im===0,o=n.re===0&&n.im===0;if(a&&o||r&&i)return Complex$1.NAN;if(o||r)return Complex$1.INFINITY;if(a||i)return Complex$1.ZERO;if(n.im===0)return new Complex$1(this.re/n.re,this.im/n.re);if(Math.abs(n.re)<Math.abs(n.im)){let e=n.re/n.im,t=n.re*e+n.im;return new Complex$1((this.re*e+this.im)/t,(this.im*e-this.re)/t)}else{let e=n.im/n.re,t=n.im*e+n.re;return new Complex$1((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=parse(e,t),r=this.re===0&&this.im===0;if(n.re===0&&n.im===0)return Complex$1.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new Complex$1(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new Complex$1(this.im**+n.re,0);case 1:return new Complex$1(0,this.im**+n.re);case 2:return new Complex$1(-(this.im**+n.re),0);case 3:return new Complex$1(0,-(this.im**+n.re))}}if(r&&n.re>0)return Complex$1.ZERO;let i=Math.atan2(this.im,this.re),a=logHypot(this.re,this.im),o=Math.exp(n.re*a-n.im*i),s=n.im*a+n.re*i;return new Complex$1(o*Math.cos(s),o*Math.sin(s))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new Complex$1(Math.sqrt(e),0):new Complex$1(0,Math.sqrt(-e));let n=hypot(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new Complex$1(r,t<0?-i:i):new Complex$1(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new Complex$1(e,0):new Complex$1(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new Complex$1(Math.expm1(e)*Math.cos(t)+cosm1(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new Complex$1(Math.log(e),0):new Complex$1(logHypot(e,t),Math.atan2(t,e))},abs:function(){return hypot(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new Complex$1(Math.sin(e)*Z(t),Math.cos(e)*Q(t))},cos:function(){let e=this.re,t=this.im;return new Complex$1(Math.cos(e)*Z(t),-Math.sin(e)*Q(t))},tan:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)+Z(t);return new Complex$1(Math.sin(e)/n,Q(t)/n)},cot:function(){let e=2*this.re,t=2*this.im,n=Math.cos(e)-Z(t);return new Complex$1(-Math.sin(e)/n,Q(t)/n)},sec:function(){let e=this.re,t=this.im,n=.5*Z(2*t)+.5*Math.cos(2*e);return new Complex$1(Math.cos(e)*Z(t)/n,Math.sin(e)*Q(t)/n)},csc:function(){let e=this.re,t=this.im,n=.5*Z(2*t)-.5*Math.cos(2*e);return new Complex$1(Math.sin(e)*Z(t)/n,-Math.cos(e)*Q(t)/n)},asin:function(){let e=this.re,t=this.im,n=new Complex$1(t*t-e*e+1,-2*e*t).sqrt(),r=new Complex$1(n.re-t,n.im+e).log();return new Complex$1(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new Complex$1(t*t-e*e+1,-2*e*t).sqrt(),r=new Complex$1(n.re-t,n.im+e).log();return new Complex$1(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new Complex$1(0,1/0);if(t===-1)return new Complex$1(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new Complex$1((1-t*t-e*e)/n,-2*e/n).log();return new Complex$1(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new Complex$1(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).atan():new Complex$1(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Complex$1(0,1/0);let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).acos():new Complex$1(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Complex$1(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).asin():new Complex$1(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new Complex$1(Q(e)*Math.cos(t),Z(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new Complex$1(Z(e)*Math.cos(t),Q(e)*Math.sin(t))},tanh:function(){let e=2*this.re,t=2*this.im,n=Z(e)+Math.cos(t);return new Complex$1(Q(e)/n,Math.sin(t)/n)},coth:function(){let e=2*this.re,t=2*this.im,n=Z(e)-Math.cos(t);return new Complex$1(Q(e)/n,-Math.sin(t)/n)},csch:function(){let e=this.re,t=this.im,n=Math.cos(2*t)-Z(2*e);return new Complex$1(-2*Q(e)*Math.cos(t)/n,2*Z(e)*Math.sin(t)/n)},sech:function(){let e=this.re,t=this.im,n=Math.cos(2*t)+Z(2*e);return new Complex$1(2*Z(e)*Math.cos(t)/n,-2*Q(e)*Math.sin(t)/n)},asinh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new Complex$1(0,0);let t=Math.abs(e),n=Math.log(t+Math.sqrt(t*t+1));return new Complex$1(e<0?-n:n,0)}let n=new Complex$1(e*e-t*t+1,2*e*t).sqrt();return new Complex$1(e+n.re,t+n.im).log()},acosh:function(){let e=this.re,t=this.im;if(t===0){if(e>1)return new Complex$1(Math.log(e+Math.sqrt(e-1)*Math.sqrt(e+1)),0);if(e<-1){let t=Math.sqrt(e*e-1);return new Complex$1(Math.log(-e+t),Math.PI)}return new Complex$1(0,Math.acos(e))}let n=new Complex$1(e-1,t).sqrt(),r=new Complex$1(e+1,t).sqrt();return new Complex$1(e+n.re*r.re-n.im*r.im,t+n.re*r.im+n.im*r.re).log()},atanh:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new Complex$1(0,0);if(e===1)return new Complex$1(1/0,0);if(e===-1)return new Complex$1(-1/0,0);if(-1<e&&e<1)return new Complex$1(.5*Math.log((1+e)/(1-e)),0);if(e>1){let t=(e+1)/(e-1);return new Complex$1(.5*Math.log(t),-Math.PI/2)}let t=(1+e)/(1-e);return new Complex$1(.5*Math.log(-t),Math.PI/2)}let n=1-e,r=1+e,i=n*n+t*t;if(i===0)return new Complex$1(e===-1?0:e/0,t===0?0:t/0);let a=(r*n-t*t)/i,o=(t*n+r*t)/i;return new Complex$1(logHypot(a,o)/2,Math.atan2(o,a)/2)},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new Complex$1(0,Math.PI/2);let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).atanh():new Complex$1(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0){if(e===0)return new Complex$1(1/0,0);let t=1/e;return new Complex$1(Math.log(t+Math.sqrt(t*t+1)),0)}let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).asinh():new Complex$1(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return Complex$1.INFINITY;let n=e*e+t*t;return n===0?new Complex$1(e===0?0:e/0,t===0?0:-t/0).acosh():new Complex$1(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return Complex$1.INFINITY;if(this.isInfinite())return Complex$1.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new Complex$1(e/n,-t/n)},conjugate:function(){return new Complex$1(this.re,-this.im)},neg:function(){return new Complex$1(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new Complex$1(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new Complex$1(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new Complex$1(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=parse(e,t);return Math.abs(n.re-this.re)<=Complex$1.EPSILON&&Math.abs(n.im-this.im)<=Complex$1.EPSILON},clone:function(){return new Complex$1(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<Complex$1.EPSILON&&(e=0),Math.abs(t)<Complex$1.EPSILON&&(t=0),t===0?n+e:(e===0?t<0&&(t=-t,n+=`-`):(n+=e,n+=` `,t<0?(t=-t,n+=`-`):n+=`+`,n+=` `),t!==1&&(n+=t),n+`i`))},toVector:function(){return[this.re,this.im]},valueOf:function(){return this.im===0?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return this.im===0&&this.re===0},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!this.isFinite()}},Complex$1.ZERO=new Complex$1(0,0),Complex$1.ONE=new Complex$1(1,0),Complex$1.I=new Complex$1(0,1),Complex$1.PI=new Complex$1(Math.PI,0),Complex$1.E=new Complex$1(Math.E,0),Complex$1.INFINITY=new Complex$1(1/0,1/0),Complex$1.NAN=new Complex$1(NaN,NaN),Complex$1.EPSILON=1e-15;var Et=`Complex`,Dt=[],Ot=factory(Et,Dt,()=>(Object.defineProperty(Complex$1,`name`,{value:`Complex`}),Complex$1.prototype.constructor=Complex$1,Complex$1.prototype.type=`Complex`,Complex$1.prototype.isComplex=!0,Complex$1.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},Complex$1.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},Complex$1.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=format$2(this.re,e),a=format$2(this.im,e),o=isNumber$1(e)?e:e?e.precision:null;if(o!==null){var s=10**-o;Math.abs(r/n)<s&&(r=0),Math.abs(n/r)<s&&(n=0)}return t=n===0?i:r===0?n===1?`i`:n===-1?`-i`:a+`i`:n<0?n===-1?i+` - i`:i+` - `+a.substring(1)+`i`:n===1?i+` + i`:i+` + `+a+`i`,t},Complex$1.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return Complex$1(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(isNumber$1(n)){if(isUnit(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),isNumber$1(r))return new Complex$1({r:n,phi:r});throw TypeError(`Phi is not a number nor an angle unit.`)}else throw TypeError(`Radius r is not a number.`);default:throw SyntaxError(`Wrong number of arguments in function fromPolar`)}},Complex$1.prototype.valueOf=Complex$1.prototype.toString,Complex$1.fromJSON=function(e){return new Complex$1(e)},Complex$1.compare=function(e,t){return e.re>t.re?1:e.re<t.re?-1:e.im>t.im?1:e.im<t.im?-1:0},Complex$1),{isClass:!0}),kt=__commonJSMin(((e,t)=>{
|
|
106
106
|
/**
|
|
107
107
|
* @license Fraction.js v4.3.0 20/08/2023
|
|
@@ -117,23 +117,23 @@ Example:
|
|
|
117
117
|
`),t=t.replace(/ +(-----END [A-Z0-9 ]+-----)/g,`
|
|
118
118
|
$1`);let n=t.match(/(-----BEGIN [A-Z0-9 ]+-----)\n?([^-]+)(-----END [A-Z0-9 ]+-----)/);if(n){let[,e,r,i]=n;if(!r.includes(`
|
|
119
119
|
`)&&r.includes(` `)){let n=r.replace(/ /g,``);t=`${e}\n${n.match(/.{1,64}/g)?.join(`
|
|
120
|
-
`)??n}\n${i}`}}return t},decodeCertOrKey=e=>{if(!e||e.length===0)return e;let t=normalizePem(e);if(isPemFormat(t))return t;try{let e=Buffer.from(t,`base64`).toString(`utf-8`);return isPemFormat(e)?normalizePem(e):t}catch{return t}},buildHttpsAgent=e=>{if(!e)return;let{certs:t,keys:n}=e;if(!Array.isArray(t)||!Array.isArray(n))return;let r=t.filter(e=>typeof e==`string`&&e.trim().length>0),i=n.filter(e=>typeof e==`string`&&e.trim().length>0);if(r.length===0||i.length===0)return;let a=r.map(decodeCertOrKey),o=i.map(decodeCertOrKey);return new u.default.Agent({cert:a,key:o})},xn={[
|
|
120
|
+
`)??n}\n${i}`}}return t},decodeCertOrKey=e=>{if(!e||e.length===0)return e;let t=normalizePem(e);if(isPemFormat(t))return t;try{let e=Buffer.from(t,`base64`).toString(`utf-8`);return isPemFormat(e)?normalizePem(e):t}catch{return t}},buildHttpsAgent=e=>{if(!e)return;let{certs:t,keys:n}=e;if(!Array.isArray(t)||!Array.isArray(n))return;let r=t.filter(e=>typeof e==`string`&&e.trim().length>0),i=n.filter(e=>typeof e==`string`&&e.trim().length>0);if(r.length===0||i.length===0)return;let a=r.map(decodeCertOrKey),o=i.map(decodeCertOrKey);return new u.default.Agent({cert:a,key:o})},xn={[N.rPush]:`
|
|
121
121
|
local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
|
|
122
122
|
|
|
123
123
|
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
|
124
124
|
|
|
125
125
|
return queueLength
|
|
126
|
-
`,[
|
|
126
|
+
`,[N.lPush]:`
|
|
127
127
|
local queueLength = redis.call('LPUSH', KEYS[1], ARGV[1])
|
|
128
128
|
|
|
129
129
|
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
|
130
130
|
|
|
131
131
|
return queueLength
|
|
132
|
-
`,[
|
|
132
|
+
`,[N.lPop]:`
|
|
133
133
|
local queueKey = KEYS[1]
|
|
134
134
|
|
|
135
135
|
return redis.call("lpop", queueKey)
|
|
136
|
-
`,[
|
|
136
|
+
`,[N.llen]:`return redis.call("llen", KEYS[1])`},Sn={[Ie.incr]:`
|
|
137
137
|
local targetKey = KEYS[1]
|
|
138
138
|
local totalLimit = tonumber(ARGV[1])
|
|
139
139
|
|
|
@@ -175,7 +175,7 @@ $1`);let n=t.match(/(-----BEGIN [A-Z0-9 ]+-----)\n?([^-]+)(-----END [A-Z0-9 ]+--
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
return nil
|
|
178
|
-
`},initializeTransportSystem=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r,skipStartupCheck:i}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let e=[r,{skipStartupCheck:i??!1}],[a,o]=await Promise.all([SingletonManager.prepare(QueueManager,{redisClientConfig:t,scripts:xn,logger:n}),SingletonManager.prepare(RateLimitManager,{redisClientConfig:t,scripts:Sn,logger:n})]),s=await SingletonManager.prepare(ConcurrencyManager,{redisClientConfig:t,scripts:Ee,logger:n,additionalArgs:e}),c=[{name:`ConcurrencyManager`,ready:s.isReady()},{name:`QueueManager`,ready:a.isReady()},{name:`RateLimitManager`,ready:o.isReady()}],l=c.filter(e=>!e.ready);if(l.length>0){let e=l.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:c.map(e=>e.name)}}),{concurrencyManager:s,queueManager:a,rateLimitManager:o}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=SingletonManager.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},shutdownTransportSystem=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=SingletonManager.getIfReady(ConcurrencyManager),n=SingletonManager.getIfReady(QueueManager),r=SingletonManager.getIfReady(RateLimitManager);t?.close(),n?.close(),r?.close(),SingletonManager.reset(ConcurrencyManager),SingletonManager.reset(QueueManager),SingletonManager.reset(RateLimitManager),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},isTransportSystemReady=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},getTransportManagers=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},Cn=__name(e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),`isHttpQueryParamValue`),wn=__name(e=>Array.isArray(e)?e:[e],`toStringArray`),toQueryValue=e=>Array.isArray(e)?e.map(String):String(e),mergeQueryValues=(e,t,n)=>{let r=wn(t);if(Cn(e))return{value:[...wn(e.value),...r],arrayFormat:n??e.arrayFormat};let i=[...wn(e),...r];return n?{value:i,arrayFormat:n}:i},parseQueryParam=(e,t,n)=>{let r=toQueryValue(t);return e===void 0?n?{value:r,arrayFormat:n}:r:mergeQueryValues(e,r,n)},parseBodyParam=(e,t)=>Array.isArray(e)?e.concat(t):typeof e==`object`&&e&&typeof t==`object`&&t?{...e,...t}:t,parseRequestParameters=e=>e.reduce((e,t)=>{if(t.in===`query`){let n=e.query[t.name];e.query[t.name]=parseQueryParam(n,t.value,t.arrayFormat)}else if(t.in===`body`)if(t.spread)Array.isArray(t.value)?Array.isArray(e.body)?e.body=e.body.concat(t.value):e.body=t.value:typeof t.value==`object`&&t.value!==null&&(e.body={...e.body,...t.value});else{let n=e.body[t.name];e.body[t.name]=parseBodyParam(n,t.value)}else e.headers[t.name]=String(t.value);return e},{query:{},body:{},headers:{}}),Tn=[`query`,`body`,`headers`],En=[`repeat`,`brackets`,`comma`,`stringify`],Dn=`@_`,On={ignoreAttributes:!1,attributeNamePrefix:`@_`,suppressBooleanAttributes:!1},kn=new g.XMLBuilder(On),getContentType=e=>{let t=Object.entries(e).find(([e])=>e.toLowerCase()===`content-type`)?.[1];return typeof t==`string`?t.toLowerCase():``},isXmlContentTypeValue=e=>e.includes(`application/xml`)||e.includes(`text/xml`)||/application\/\S+\+xml/.test(e),isXmlContentType=e=>isXmlContentTypeValue(getContentType(e)),serializeBodyToXml=e=>{try{return kn.build(e)}catch(e){throw Error(`Failed to serialize request body to XML: ${e instanceof Error?e.message:String(e)}`)}},serializeRequestBodyForSigning=(e,t={})=>{if(e==null)return``;if(typeof e==`string`)return e;let n=getContentType(t);return n.includes(`application/x-www-form-urlencoded`)?h.default.stringify(e):isXmlContentTypeValue(n)?serializeBodyToXml(e):JSON.stringify(e)},isSuccessStatusCode=e=>(0,o.notMissing)(e)&&e>=200&&e<=299,isFailedStatusCode=e=>(0,o.notMissing)(e)&&e>=400&&e<=599,isInfoStatusCode=e=>(0,o.notMissing)(e)&&e>=100&&e<=199;let An;const getXmlParser=()=>(An??=new g.XMLParser({ignoreAttributes:!1,attributeNamePrefix:`@_`,parseAttributeValue:!1,removeNSPrefix:!1,numberParseOptions:{leadingZeros:!1,hex:!1}}),An);var RestClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c,httpsAgent:l}){let u,d=a;if(isXmlContentType(r))if(typeof a==`string`)d=a;else if(Array.isArray(a))throw Error(`Cannot serialize an array body to XML: XML requires a single root element. Wrap the array in an object with a root key.`);else a!=null&&(d=serializeBodyToXml(a));try{u=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:d,requestConfig:c,httpsAgent:l})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}if(typeof u.data==`string`&&u.data.length>0&&u.headers&&isXmlContentType(u.headers)){let e=g.XMLValidator.validate(u.data);if(e!==!0)throw Error(`Invalid XML response from ${t}: ${e.err.msg} at line ${e.err.line}`);u={...u,data:getXmlParser().parse(u.data)}}let f=translateCustomError(u,s);if(isFailedStatusCode(f?.status))throw new F(f,f.message);return f}},SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;if(l=typeof c?.envelope==`string`?c.envelope:typeof c?.envelope==`object`?jn.build(c.envelope):await buildEnvelope(a,c),g.XMLValidator.validate(l,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};c?.soapAction&&(d.SOAPAction=c.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:l,requestConfig:c})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}let f=Mn.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new F({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let _=translateCustomError(u,s);if(isFailedStatusCode(_?.status))throw new F(_,_.message);return _}};const jn=new g.XMLBuilder(On),Mn=new g.XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if((0,o.notMissing)(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:jn.build(t.envelope);if(g.XMLValidator.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=jn.build(n);if(g.XMLValidator.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await(0,c.evaluate)(e.namespaceIdentifier),namespace:await(0,c.evaluate)(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if((0,o.isMissing)(e)||(0,o.isMissing)(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if((0,o.isMissing)(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if((0,o.isMissing)(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};const arrayFormatToPairs=(e,t,n)=>n===`brackets`?t.map(t=>[`${e}[]`,t]):n===`comma`?[[e,t.join(`,`)]]:n===`stringify`?[[e,JSON.stringify(t)]]:t.map(t=>[e,t]),toStringArray=e=>Array.isArray(e)?e:[e],isHttpQueryParamValue=e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),flattenQueryParams=e=>{if(!e)return[];let t=[];for(let[n,r]of Object.entries(e))r!=null&&(isHttpQueryParamValue(r)?t.push(...arrayFormatToPairs(n,toStringArray(r.value),r.arrayFormat)):t.push(...arrayFormatToPairs(n,toStringArray(r),void 0)));return t},hmac=(e,t)=>(0,d.createHmac)(`sha256`,e).update(t).digest(),hash=e=>(0,d.createHash)(`sha256`).update(e).digest(`hex`),getSigningKey=(e,t,n,r)=>hmac(hmac(hmac(hmac(`AWS4${e}`,t),n),r),`aws4_request`),Nn=__name(e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),`rfc3986Encode`),Pn=__name((e,t)=>e<t?-1:e>t?1:0,`byteCompare`),aws4SigningStrategy=(e,t,n)=>{if(n.strategy!==`aws4`)throw Error(`aws4SigningStrategy invoked with strategy "${n.strategy}" — registry misconfiguration`);let{accessKeyId:r,secretAccessKey:i,sessionToken:a,region:o}=t;if(!r||!i)throw Error(`AWS SigV4 requires accessKeyId and secretAccessKey`);let{service:s,region:c}=n,l=c??o??`us-east-1`,u=new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),f=u.slice(0,8),p=new URL(e.url),m=p.pathname.split(`/`).map(e=>{try{return Nn(decodeURIComponent(e))}catch{return Nn(e)}}).join(`/`)||`/`,h=[];for(let[e,t]of p.searchParams.entries())h.push([e,t]);h.push(...flattenQueryParams(e.query)),h.sort(([e,t],[n,r])=>{let i=Pn(e,n);return i===0?Pn(t,r):i});let g=h.map(([e,t])=>`${Nn(e)}=${Nn(t)}`).join(`&`),_=hash(serializeRequestBodyForSigning(e.body,e.headers??{})),v={host:p.host,"x-amz-content-sha256":_,"x-amz-date":u};a&&(v[`x-amz-security-token`]=a);for(let[t,n]of Object.entries(e.headers??{})){let e=t.toLowerCase();e!==`authorization`&&e!==`x-amz-date`&&e!==`x-amz-content-sha256`&&e!==`x-amz-security-token`&&(v[e]=n)}let y=Object.keys(v).sort(),canonicalHeaderValue=e=>e.trim().replace(/\s+/g,` `),b=y.map(e=>`${e}:${canonicalHeaderValue(v[e])}\n`).join(``),x=y.join(`;`),S=[e.method.toUpperCase(),m,g,b,x,_].join(`
|
|
179
|
-
`),
|
|
180
|
-
`),
|
|
181
|
-
`),_=(0,d.createHmac)(s,r).update(g).digest(`hex`);return{[c]:`${l} ${_}`,"X-Timestamp":u}},In={},registerSigningStrategy=(e,t)=>{In[e]=t},getSigningStrategy=e=>In[e];registerSigningStrategy(`aws4`,aws4SigningStrategy),registerSigningStrategy(`hmac`,hmacSigningStrategy),exports.CUSTOM_ERROR_CONFIG_SCHEMA=
|
|
178
|
+
`},initializeTransportSystem=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r,skipStartupCheck:i}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let e=[r,{skipStartupCheck:i??!1}],[a,o]=await Promise.all([SingletonManager.prepare(QueueManager,{redisClientConfig:t,scripts:xn,logger:n}),SingletonManager.prepare(RateLimitManager,{redisClientConfig:t,scripts:Sn,logger:n})]),s=await SingletonManager.prepare(ConcurrencyManager,{redisClientConfig:t,scripts:Te,logger:n,additionalArgs:e}),c=[{name:`ConcurrencyManager`,ready:s.isReady()},{name:`QueueManager`,ready:a.isReady()},{name:`RateLimitManager`,ready:o.isReady()}],l=c.filter(e=>!e.ready);if(l.length>0){let e=l.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:c.map(e=>e.name)}}),{concurrencyManager:s,queueManager:a,rateLimitManager:o}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=SingletonManager.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},shutdownTransportSystem=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=SingletonManager.getIfReady(ConcurrencyManager),n=SingletonManager.getIfReady(QueueManager),r=SingletonManager.getIfReady(RateLimitManager);t?.close(),n?.close(),r?.close(),SingletonManager.reset(ConcurrencyManager),SingletonManager.reset(QueueManager),SingletonManager.reset(RateLimitManager),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},isTransportSystemReady=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},getTransportManagers=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},Cn=__name(e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),`isHttpQueryParamValue`),wn=__name(e=>Array.isArray(e)?e:[e],`toStringArray`),toQueryValue=e=>Array.isArray(e)?e.map(String):String(e),mergeQueryValues=(e,t,n)=>{let r=wn(t);if(Cn(e))return{value:[...wn(e.value),...r],arrayFormat:n??e.arrayFormat};let i=[...wn(e),...r];return n?{value:i,arrayFormat:n}:i},parseQueryParam=(e,t,n)=>{let r=toQueryValue(t);return e===void 0?n?{value:r,arrayFormat:n}:r:mergeQueryValues(e,r,n)},parseBodyParam=(e,t)=>Array.isArray(e)?e.concat(t):typeof e==`object`&&e&&typeof t==`object`&&t?{...e,...t}:t,parseRequestParameters=e=>e.reduce((e,t)=>{if(t.in===`query`){let n=e.query[t.name];e.query[t.name]=parseQueryParam(n,t.value,t.arrayFormat)}else if(t.in===`body`)if(t.spread)Array.isArray(t.value)?Array.isArray(e.body)?e.body=e.body.concat(t.value):e.body=t.value:typeof t.value==`object`&&t.value!==null&&(e.body={...e.body,...t.value});else{let n=e.body[t.name];e.body[t.name]=parseBodyParam(n,t.value)}else e.headers[t.name]=String(t.value);return e},{query:{},body:{},headers:{}}),Tn=[`query`,`body`,`headers`],En=[`repeat`,`brackets`,`comma`,`stringify`],Dn=`@_`,On={ignoreAttributes:!1,attributeNamePrefix:`@_`,suppressBooleanAttributes:!1},kn=new g.XMLBuilder(On),getContentType=e=>{let t=Object.entries(e).find(([e])=>e.toLowerCase()===`content-type`)?.[1];return typeof t==`string`?t.toLowerCase():``},isXmlContentTypeValue=e=>e.includes(`application/xml`)||e.includes(`text/xml`)||/application\/\S+\+xml/.test(e),isXmlContentType=e=>isXmlContentTypeValue(getContentType(e)),serializeBodyToXml=e=>{try{return kn.build(e)}catch(e){throw Error(`Failed to serialize request body to XML: ${e instanceof Error?e.message:String(e)}`)}},serializeRequestBodyForSigning=(e,t={})=>{if(e==null)return``;if(typeof e==`string`)return e;let n=getContentType(t);return n.includes(`application/x-www-form-urlencoded`)?h.default.stringify(e):isXmlContentTypeValue(n)?serializeBodyToXml(e):JSON.stringify(e)},isSuccessStatusCode=e=>(0,o.notMissing)(e)&&e>=200&&e<=299,isFailedStatusCode=e=>(0,o.notMissing)(e)&&e>=400&&e<=599,isInfoStatusCode=e=>(0,o.notMissing)(e)&&e>=100&&e<=199;let An;const getXmlParser=()=>(An??=new g.XMLParser({ignoreAttributes:!1,attributeNamePrefix:`@_`,parseAttributeValue:!1,removeNSPrefix:!1,numberParseOptions:{leadingZeros:!1,hex:!1}}),An);var RestClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c,httpsAgent:l}){let u,d=a;if(isXmlContentType(r))if(typeof a==`string`)d=a;else if(Array.isArray(a))throw Error(`Cannot serialize an array body to XML: XML requires a single root element. Wrap the array in an object with a root key.`);else a!=null&&(d=serializeBodyToXml(a));try{u=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:d,requestConfig:c,httpsAgent:l})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}if(typeof u.data==`string`&&u.data.length>0&&u.headers&&isXmlContentType(u.headers)){let e=g.XMLValidator.validate(u.data);if(e!==!0)throw Error(`Invalid XML response from ${t}: ${e.err.msg} at line ${e.err.line}`);u={...u,data:getXmlParser().parse(u.data)}}let f=translateCustomError(u,s);if(isFailedStatusCode(f?.status))throw new Oe(f,f.message);return f}},SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;if(l=typeof c?.envelope==`string`?c.envelope:typeof c?.envelope==`object`?jn.build(c.envelope):await buildEnvelope(a,c),g.XMLValidator.validate(l,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};c?.soapAction&&(d.SOAPAction=c.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:l,requestConfig:c})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}let f=Mn.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new Oe({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let _=translateCustomError(u,s);if(isFailedStatusCode(_?.status))throw new Oe(_,_.message);return _}};const jn=new g.XMLBuilder(On),Mn=new g.XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if((0,o.notMissing)(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:jn.build(t.envelope);if(g.XMLValidator.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=jn.build(n);if(g.XMLValidator.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await(0,c.evaluate)(e.namespaceIdentifier),namespace:await(0,c.evaluate)(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if((0,o.isMissing)(e)||(0,o.isMissing)(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if((0,o.isMissing)(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if((0,o.isMissing)(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};const arrayFormatToPairs=(e,t,n)=>n===`brackets`?t.map(t=>[`${e}[]`,t]):n===`comma`?[[e,t.join(`,`)]]:n===`stringify`?[[e,JSON.stringify(t)]]:t.map(t=>[e,t]),toStringArray=e=>Array.isArray(e)?e:[e],isHttpQueryParamValue=e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),flattenQueryParams=e=>{if(!e)return[];let t=[];for(let[n,r]of Object.entries(e))r!=null&&(isHttpQueryParamValue(r)?t.push(...arrayFormatToPairs(n,toStringArray(r.value),r.arrayFormat)):t.push(...arrayFormatToPairs(n,toStringArray(r),void 0)));return t},hmac=(e,t)=>(0,d.createHmac)(`sha256`,e).update(t).digest(),hash=e=>(0,d.createHash)(`sha256`).update(e).digest(`hex`),getSigningKey=(e,t,n,r)=>hmac(hmac(hmac(hmac(`AWS4${e}`,t),n),r),`aws4_request`),Nn=__name(e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),`rfc3986Encode`),Pn=__name((e,t)=>e<t?-1:e>t?1:0,`byteCompare`),aws4SigningStrategy=(e,t,n)=>{if(n.strategy!==`aws4`)throw Error(`aws4SigningStrategy invoked with strategy "${n.strategy}" — registry misconfiguration`);let{accessKeyId:r,secretAccessKey:i,sessionToken:a,region:o}=t;if(!r||!i)throw Error(`AWS SigV4 requires accessKeyId and secretAccessKey`);let{service:s,region:c}=n,l=c??o??`us-east-1`,u=new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),f=u.slice(0,8),p=new URL(e.url),m=p.pathname.split(`/`).map(e=>{try{return Nn(decodeURIComponent(e))}catch{return Nn(e)}}).join(`/`)||`/`,h=[];for(let[e,t]of p.searchParams.entries())h.push([e,t]);h.push(...flattenQueryParams(e.query)),h.sort(([e,t],[n,r])=>{let i=Pn(e,n);return i===0?Pn(t,r):i});let g=h.map(([e,t])=>`${Nn(e)}=${Nn(t)}`).join(`&`),_=serializeRequestBodyForSigning(e.body,e.headers??{}),v=(0,d.createHash)(`sha256`).update(_).digest(),y=v.toString(`hex`),b={host:p.host,"x-amz-content-sha256":y,"x-amz-date":u};a&&(b[`x-amz-security-token`]=a);for(let[t,n]of Object.entries(e.headers??{})){let e=t.toLowerCase();e!==`authorization`&&e!==`x-amz-date`&&e!==`x-amz-content-sha256`&&e!==`x-amz-security-token`&&(b[e]=n)}let x=Object.keys(b).some(e=>e===`content-md5`||e.startsWith(`x-amz-checksum-`)),S=_.length>0&&!x,C;S&&(C=v.toString(`base64`),b[`x-amz-checksum-sha256`]=C);let w=Object.keys(b).sort(),canonicalHeaderValue=e=>e.trim().replace(/\s+/g,` `),T=w.map(e=>`${e}:${canonicalHeaderValue(b[e])}\n`).join(``),E=w.join(`;`),D=[e.method.toUpperCase(),m,g,T,E,y].join(`
|
|
179
|
+
`),O=`${f}/${l}/${s}/aws4_request`,k=[`AWS4-HMAC-SHA256`,u,O,hash(D)].join(`
|
|
180
|
+
`),A={Authorization:`AWS4-HMAC-SHA256 Credential=${r}/${O}, SignedHeaders=${E}, Signature=${(0,d.createHmac)(`sha256`,getSigningKey(i,f,l,s)).update(k).digest(`hex`)}`,"x-amz-date":u,"x-amz-content-sha256":y};return a&&(A[`x-amz-security-token`]=a),C!==void 0&&(A[`x-amz-checksum-sha256`]=C),A},Fn=[`sha256`,`sha512`],isValidAlgorithm=e=>Fn.includes(e),hashPayload=e=>(0,d.createHash)(`sha256`).update(e).digest(`hex`),byteCompare=(e,t)=>e<t?-1:e>t?1:0,rfc3986Encode=e=>encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),hmacSigningStrategy=(e,t,n)=>{if(n.strategy!==`hmac`)throw Error(`hmacSigningStrategy invoked with strategy "${n.strategy}" — registry misconfiguration`);let r=t.secretKey;if(!r)throw Error(`HMAC signing requires secretKey in credentials`);let{algorithm:i,headerName:a,prefix:o}=n;if(i!==void 0&&!isValidAlgorithm(i))throw Error(`Unsupported HMAC algorithm "${i}". Use "sha256" or "sha512".`);let s=i??`sha256`,c=a??`X-Signature`,l=o??`hmac-${s}`,u=new Date().toISOString(),f=new URL(e.url),p=[];for(let[e,t]of f.searchParams.entries())p.push([e,t]);p.push(...flattenQueryParams(e.query)),p.sort(([e,t],[n,r])=>{let i=byteCompare(e,n);return i===0?byteCompare(t,r):i});let m=p.map(([e,t])=>`${rfc3986Encode(e)}=${rfc3986Encode(t)}`).join(`&`),h=hashPayload(serializeRequestBodyForSigning(e.body,e.headers??{})),g=[u,e.method.toUpperCase(),f.pathname,m,h].join(`
|
|
181
|
+
`),_=(0,d.createHmac)(s,r).update(g).digest(`hex`);return{[c]:`${l} ${_}`,"X-Timestamp":u}},In={},registerSigningStrategy=(e,t)=>{In[e]=t},getSigningStrategy=e=>In[e];registerSigningStrategy(`aws4`,aws4SigningStrategy),registerSigningStrategy(`hmac`,hmacSigningStrategy),exports.CUSTOM_ERROR_CONFIG_SCHEMA=De,exports.ConcurrencyManager=ConcurrencyManager,exports.EventClient=EventClient,exports.HttpClient=HttpClient,exports.HttpClientManager=HttpClientManager,exports.HttpErrorMessages=Ee,exports.HttpMethods=bn,exports.HttpResponseError=Oe,exports.HttpTransportFactory=HttpTransportFactory,exports.InstanceManager=Me,exports.LockManager=LockManager,exports.MemoryStore=MemoryStore,exports.QueryArrayFormats=En,exports.QueueManager=QueueManager,exports.RateLimitManager=RateLimitManager,exports.RedisClient=ee,exports.RequestClientFactory=RequestClientFactory,exports.RequestParameterLocations=Tn,exports.ScriptManager=ScriptManager,exports.SubscriptionManager=SubscriptionManager,exports.buildHttpClientInstance=buildHttpClientInstance,exports.buildHttpsAgent=buildHttpsAgent,exports.convertError=convertError,exports.createAuthorizationHeaders=createAuthorizationHeaders,exports.getRetryAfterWaitTime=getRetryAfterWaitTime,exports.getSigningStrategy=getSigningStrategy,exports.getTransportInstance=getTransportInstance,exports.getTransportManagers=getTransportManagers,exports.initializeTransportSystem=initializeTransportSystem,exports.isFailedStatusCode=isFailedStatusCode,exports.isInfoStatusCode=isInfoStatusCode,exports.isSuccessStatusCode=isSuccessStatusCode,exports.isTransportSystemReady=isTransportSystemReady,exports.parseRequestParameters=parseRequestParameters,exports.registerSigningStrategy=registerSigningStrategy,exports.serializeHttpResponseError=serializeHttpResponseError,exports.shutdownTransportSystem=shutdownTransportSystem,exports.superNormalizeHeaders=superNormalizeHeaders,exports.translateCustomError=translateCustomError;
|