@stackone/transport 1.11.1 → 1.13.0
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.d.mts +147 -58
- package/dist/index.d.ts +146 -57
- package/dist/index.js +13 -13
- package/dist/index.mjs +15 -15
- package/package.json +1 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{deepCopy as e,delay as t,exponentialBackoffInMS as n,generateRequestId as r,getContentHash as i,isFunction as a,isFutureUnixTimestamp as o,isMissing as s,isNumber as c,isObject as l,isString as u,notMissing as d}from"@stackone/utils";import*as f from"redis";import p,{isAxiosError as m}from"axios";import h from"node:http";import{randomUUID as g}from"crypto";import{clearTimeout as _}from"node:timers";import v from"jsonpath";import y from"qs";import{safeEvaluate as b}from"@stackone/expressions";var x=Object.create,S=Object.defineProperty,C=Object.getOwnPropertyDescriptor,ee=Object.getOwnPropertyNames,te=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty,T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ne=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=ee(t),a=0,o=i.length,s;a<o;a++)s=i[a],!w.call(e,s)&&s!==n&&S(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=C(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:x(te(e)),ne(t||!e||!e.__esModule?S(n,`default`,{value:e,enumerable:!0}):n,e));const re=e=>{switch(e.type){case`basic`:return D(e);case`bearer`:return O(e);default:throw Error(`Invalid authentication type`)}},D=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n,i=Buffer.from(`${e}:${t}`).toString(r);return{authorization:`Basic ${i}`}},O=({token:e,includeBearer:t=!0})=>({authorization:`${t?`Bearer `:``}${e}`});var ie=class{locks;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);if(r&&i){i.push({lock:n,unlock:t});let e=i.length-2;await i[e].lock}else 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 ae=1e3,oe=100,se=60,ce=6e4,le=se,ue=ce,de=ce*10,fe=oe,pe=10;let me=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var he=class{config;instantiator;dataStore;lockManager;expiryMap;evictionFrequency;staleDataThreshold;truncateThreshold;truncationPercentage;logger;typeGuard;dispose;evictionInterval;lastAccessedAt=Date.now();constructor(e={}){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 ie,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??ue,this.staleDataThreshold=e?.staleDataThreshold??de,this.truncateThreshold=e?.truncateThreshold??fe,this.truncationPercentage=e?.truncationPercentage??pe,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 setData({key:e,value:t,cacheTTL:n=le}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),d(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*ae,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{(d(this.typeGuard)&&this.typeGuard(t)||s(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!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){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)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/oe;(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);let i=this.dataStore.size;return{dataStoreSize:e,prunedDataStoreSize:i}}startEvictionTask(){if(d(this.evictionInterval))return;let e=async()=>{let t;try{let n=this.lastAccessedAt+this.staleDataThreshold,r=Date.now();if(n<r){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:me.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if(d(t?.dataStoreSize)&&d(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&(clearTimeout(this.evictionInterval),this.evictionInterval=void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return d(this.evictionInterval)&&d(this.dataStore)&&d(this.expiryMap)&&d(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()),i=r.filter(t=>t.includes(e)),a=[],o=t?parseInt(t,10):0;for(let e=o;e<n+o;e++){let t=i[e];if(!t)break;let r=await this.getData(t);if(r&&a.push(r),a.length>=n)break}return{items:a,cursor:a.length<n?void 0:(o+n).toString()}}};const ge=1e3,_e=6e4;let ve=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var ye=class{executorMethodStore=null;promiseStore=null;logger;eventClientConfig=null;executorMethodStoreConfig=null;pendingPromiseStoreConfig=null;constructor(e,t,n){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 he(i),this.promiseStore=new he(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/ge;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 d(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);s(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??_e),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:ve.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){d(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):d(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return l(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}};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 A=async(e,t)=>{try{let n=await be.build(e,t);return n??void 0}catch(e){let n=e;t?.error({message:`Error building Cache Manager`,error:n,code:k.RedisClientError,category:`buildRedisClientInstance`});return}};var be=class e{#redisClient;#logger;static async build({getRedisClient:t=f.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s){let c=new e;c.#logger=s;try{c.#redisClient=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let s=Se(e.name,c.#logger);return xe(c.#redisClient,s),await c.#redisClient.connect(),c}catch(t){let n=t;return c.#logger?.error({message:`Error building Cache Manager.`,error:n,code:k.RedisClientError,category:e.name}),null}}#parseData(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#isRedisClientAvailable())return null;try{let e=await this.#redisClient.get(t);if(!e)return null;let n=this.#parseData(e);return u(n)?e:n}catch(t){let n=t;return this.#logger?.error({message:`Error getting data`,error:n,code:k.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#isRedisClientAvailable())return!1;try{let e=u(n)?n:JSON.stringify(n);return await this.#redisClient.set(t,e,{EX:r}),d(i)&&await this.#redisClient.sAdd(i,[t]),!0}catch(t){let n=t;return this.#logger?.error({message:`Error setting data`,error:n,code:k.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#logger?.error({message:`Error executing script`,error:n,code:k.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.scriptLoad(t)}catch(t){let n=t;return this.#logger?.error({message:`Error loading script`,error:n,code:k.RedisClientScriptLoadError,category:e.name}),null}}async#executeCounterCommand(t,n,r){if(!this.#isRedisClientAvailable())return null;if(!Number.isFinite(r)||r<=0)return this.#logger?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:k.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=await this.#redisClient.multiExecutor(e),a=i?.[0];return typeof a==`number`?a:null}catch(n){let r=n;return this.#logger?.error({message:`Error executing ${t} operation`,error:r,code:k.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#executeCounterCommand(`incr`,e,t)}async decrement(e,t){return this.#executeCounterCommand(`decr`,e,t)}async subscribe(t,n){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pSubscribe(t,n),!0}catch(n){let r=n;return this.#logger?.error({message:`Error subscribing to ${t}`,error:r,code:k.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pUnsubscribe(t),!0}catch(n){let r=n;return this.#logger?.error({message:`Error unsubscribing from ${t}`,error:r,code:k.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#isRedisClientAvailable())return null;try{let r=await this.#redisClient.publish(t,n);return r===0&&this.#logger?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#logger?.error({message:`Error publishing to ${t}`,error:r,code:k.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#isRedisClientAvailable()?this.#redisClient:null}#isRedisClientAvailable(){let t=this.#redisClient.isReady&&this.#redisClient.isOpen;return t||this.#logger?.error({message:`Redis Client is not ready.`,category:e.name,code:k.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#redisClient.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);d(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#logger?.error({message:`Error listing data`,error:n,code:k.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#isRedisClientAvailable())return!1;let n=await this.#redisClient.del(t);return n===0&&this.#logger?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#logger?.error({message:`Error deleting data`,error:n,code:k.RedisClientDeleteError,category:e.name}),!1}}};const xe=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},Se=(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 Ce=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});var we=class{cacheClient=null;scriptMap=new Map;logger;scripts;redisClientConfig;constructor(e){this.scripts=e}async initialize({redisClientConfig:e,logger:t,scriptMap:n},...r){this.redisClientConfig=e,this.logger=t,this.cacheClient=await A(this.redisClientConfig,this.logger)??null,await this.loadScripts(this.scripts,n),await this.additionalInitialization(...r)}async additionalInitialization(...e){}async loadScripts(e,t){d(t)&&(this.scriptMap=t);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);d(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.constructor.name,code:Ce.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{await this.isReady()||await this.initialize({redisClientConfig:this.redisClientConfig,logger:this.logger,scriptMap:this.scriptMap});let r=this.scriptMap?.get(e);if(s(r))throw Error(`Script for ${e} not found`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.constructor.name,context:{keys:t,args:n},error:r,code:Ce.ScriptManagerExecutionError}),r}}async isReady(){return d(this.cacheClient)}},Te=class e{options={getCacheClient:A};subscriptionMap=null;subscriptionClient=null;logger;constructor(e){this.options={...this.options,...e}}async initialize(t=this.options){let{config:n,getCacheClient:r,logger:i}=t;if(this.logger=i,this.subscriptionMap=new he({instantiator:`${t?.instantiator}(${this.constructor.name})`,evictionFrequency:t?.subscriptionTTL,staleDataThreshold:t?.staleSubscriptionsThreshold,truncateThreshold:t?.truncateThreshold,truncationPercentage:t?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),d(n))this.subscriptionClient=await r?.(n,this.logger)??null,this.logger?.info({message:`${e.name} initialized for ${t.instantiator}.`,category:e.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=i(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 d(this.subscriptionClient)&&d(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const Ee=6e4,De=15e3,Oe=!1,ke=6e4,Ae=15e3,je=1e4,Me=1;let Ne=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),Pe=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});const Fe={[Pe.rPush]:`
|
|
1
|
+
import{delay as e,exponentialBackoffInMS as t,generateRequestId as n,getContentHash as r,isFunction as i,isFutureUnixTimestamp as a,isMissing as o,isNumber as s,isObject as c,isString as l,notMissing as u}from"@stackone/utils";import*as d from"redis";import f,{isAxiosError as p}from"axios";import m from"node:https";import{randomUUID as h}from"crypto";import{clearTimeout as g}from"node:timers";import _ from"jsonpath";import v from"qs";import{safeEvaluate as y}from"@stackone/expressions";var b=Object.create,x=Object.defineProperty,S=Object.getOwnPropertyDescriptor,C=Object.getOwnPropertyNames,ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty,w=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),T=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=C(t),a=0,o=i.length,s;a<o;a++)s=i[a],!te.call(e,s)&&s!==n&&x(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=S(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:b(ee(e)),T(t||!e||!e.__esModule?x(n,`default`,{value:e,enumerable:!0}):n,e));const ne=e=>{switch(e.type){case`basic`:return re(e);case`bearer`:return D(e);default:throw Error(`Invalid authentication type`)}},re=({username:e=``,password:t=``,encoding:n=`base64`})=>{let r=n,i=Buffer.from(`${e}:${t}`).toString(r);return{authorization:`Basic ${i}`}},D=({token:e,includeBearer:t=!0})=>({authorization:`${t?`Bearer `:``}${e}`});var O=class{locks;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);if(r&&i){i.push({lock:n,unlock:t});let e=i.length-2;await i[e].lock}else 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 ie=1e3,ae=100,oe=60,se=6e4,ce=oe,le=se,ue=se*10,de=ae,fe=10;let pe=function(e){return e.MemoryStorePruneError=`MemoryStorePruneError`,e}({});var me=class{config;instantiator;dataStore;lockManager;expiryMap;evictionFrequency;staleDataThreshold;truncateThreshold;truncationPercentage;logger;typeGuard;dispose;evictionInterval;lastAccessedAt=Date.now();constructor(e={}){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 O,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??le,this.staleDataThreshold=e?.staleDataThreshold??ue,this.truncateThreshold=e?.truncateThreshold??de,this.truncationPercentage=e?.truncationPercentage??fe,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 setData({key:e,value:t,cacheTTL:n=ce}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),u(this.typeGuard)&&!this.typeGuard(t))return!1;let r=n*ie,i=Date.now()+r;return await this.lockManager.withLock(e,async()=>{(u(this.typeGuard)&&this.typeGuard(t)||o(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,i)}),!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){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)}return this.dataStore.delete(e)})}async pruneExpiredKeys(){let e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;let n=[],r=0;this.dataStore.forEach(async(e,i)=>{let a=Date.now(),o=this.expiryMap.get(i)??0,s=this.truncateThreshold*this.truncationPercentage/ae;(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);let i=this.dataStore.size;return{dataStoreSize:e,prunedDataStoreSize:i}}startEvictionTask(){if(u(this.evictionInterval))return;let e=async()=>{let t;try{let n=this.lastAccessedAt+this.staleDataThreshold,r=Date.now();if(n<r){this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:`MemoryStore`}),this.close();return}t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:`Error during pruning expired keys:`,category:`MemoryStore`,error:t,code:pe.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if(u(t?.dataStoreSize)&&u(t?.prunedDataStoreSize)){let{dataStoreSize:e,prunedDataStoreSize:n}=t,r=e-n;this.logger?.debug({message:`Pruned ${r} expired keys, ${n} remain, scheduling next prune.`,category:`MemoryStore`,context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&(clearTimeout(this.evictionInterval),this.evictionInterval=void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return u(this.evictionInterval)&&u(this.dataStore)&&u(this.expiryMap)&&u(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:n}){let r=Array.from(this.dataStore.keys()),i=r.filter(t=>t.includes(e)),a=[],o=t?parseInt(t,10):0;for(let e=o;e<n+o;e++){let t=i[e];if(!t)break;let r=await this.getData(t);if(r&&a.push(r),a.length>=n)break}return{items:a,cursor:a.length<n?void 0:(o+n).toString()}}};const he=1e3,ge=6e4;let _e=function(e){return e.EventClientResolveError=`EventClientResolveError`,e}({});var ve=class{executorMethodStore=null;promiseStore=null;logger;eventClientConfig=null;executorMethodStoreConfig=null;pendingPromiseStoreConfig=null;constructor(e,t,n){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 me(i),this.promiseStore=new me(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/he;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 u(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);o(n)&&(await this.setPendingEvent(e,this.eventClientConfig?.defaultTimeoutMS??ge),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:_e.EventClientResolveError})}}async defaultExecutorMethodDispose(e,t){u(t?.resolve)?t.resolve(this.eventClientConfig?.timeoutResolveValue):u(t?.reject)&&t.reject(Error(`Event key: ${e} was not resolved or the event was disposed`))}defaultExecutorMethodTypeGuard(e){return c(e)&&e.hasOwnProperty(`resolve`)&&e.hasOwnProperty(`reject`)}async defaultPendingPromiseDispose(e,t){t instanceof Promise&&t?.finally(()=>{})}defaultPendingPromiseTypeGuard(e){return e instanceof Promise}};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 ye=async(e,t)=>{try{let n=await be.build(e,t);return n??void 0}catch(e){let n=e;t?.error({message:`Error building Cache Manager`,error:n,code:k.RedisClientError,category:`buildRedisClientInstance`});return}};var be=class e{#redisClient;#logger;static async build({getRedisClient:t=d.createClient,host:n,port:r,tls:i,reconnect:a=!0,database:o},s){let c=new e;c.#logger=s;try{c.#redisClient=t({socket:{reconnectStrategy:a?e=>Math.min(e*20,5e3):!1,host:n,port:r,tls:i},database:o,disableOfflineQueue:!0});let s=Se(e.name,c.#logger);return xe(c.#redisClient,s),await c.#redisClient.connect(),c}catch(t){let n=t;return c.#logger?.error({message:`Error building Cache Manager.`,error:n,code:k.RedisClientError,category:e.name}),null}}#parseData(e){try{return JSON.parse(e)}catch{return e}}async getData(t){if(!this.#isRedisClientAvailable())return null;try{let e=await this.#redisClient.get(t);if(!e)return null;let n=this.#parseData(e);return l(n)?e:n}catch(t){let n=t;return this.#logger?.error({message:`Error getting data`,error:n,code:k.RedisClientReadError,category:e.name}),null}}async setData({key:t,value:n,cacheTTL:r,groupKey:i}){if(!this.#isRedisClientAvailable())return!1;try{let e=l(n)?n:JSON.stringify(n);return await this.#redisClient.set(t,e,{EX:r}),u(i)&&await this.#redisClient.sAdd(i,[t]),!0}catch(t){let n=t;return this.#logger?.error({message:`Error setting data`,error:n,code:k.RedisClientWriteError,category:e.name}),!1}}async executeScript({sha1:t,keys:n,args:r}){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.evalSha(t,{keys:n,arguments:r})}catch(t){let n=t;return this.#logger?.error({message:`Error executing script`,error:n,code:k.RedisClientScriptExecuteError,category:e.name}),null}}async loadScript(t){if(!this.#isRedisClientAvailable())return null;try{return await this.#redisClient.scriptLoad(t)}catch(t){let n=t;return this.#logger?.error({message:`Error loading script`,error:n,code:k.RedisClientScriptLoadError,category:e.name}),null}}async#executeCounterCommand(t,n,r){if(!this.#isRedisClientAvailable())return null;if(!Number.isFinite(r)||r<=0)return this.#logger?.error({message:`Invalid cacheTTL parameter`,category:e.name,code:k.RedisClientInvalidTTL}),null;try{let e=[{args:[t,n]},{args:[`expire`,n,r.toString()]}],i=await this.#redisClient.multiExecutor(e),a=i?.[0];return typeof a==`number`?a:null}catch(n){let r=n;return this.#logger?.error({message:`Error executing ${t} operation`,error:r,code:k.RedisClientCommandError,category:e.name}),null}}async increment(e,t){return this.#executeCounterCommand(`incr`,e,t)}async decrement(e,t){return this.#executeCounterCommand(`decr`,e,t)}async subscribe(t,n){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pSubscribe(t,n),!0}catch(n){let r=n;return this.#logger?.error({message:`Error subscribing to ${t}`,error:r,code:k.RedisClientSubscribeError,category:e.name}),!1}}async unsubscribe(t){if(!this.#isRedisClientAvailable())return!1;try{return await this.#redisClient.pUnsubscribe(t),!0}catch(n){let r=n;return this.#logger?.error({message:`Error unsubscribing from ${t}`,error:r,code:k.RedisClientUnsubscribeError,category:e.name}),!1}}async publish(t,n){if(!this.#isRedisClientAvailable())return null;try{let r=await this.#redisClient.publish(t,n);return r===0&&this.#logger?.debug({message:`No subscribers found for channel ${t}`,category:e.name}),r}catch(n){let r=n;return this.#logger?.error({message:`Error publishing to ${t}`,error:r,code:k.RedisClientPublishError,category:e.name}),null}}getClient(){return this.#isRedisClientAvailable()?this.#redisClient:null}#isRedisClientAvailable(){let t=this.#redisClient.isReady&&this.#redisClient.isOpen;return t||this.#logger?.error({message:`Redis Client is not ready.`,category:e.name,code:k.RedisClientRedisNotReady}),t}async listData({partialKey:t,limit:n,cursor:r}){try{let e=r?parseInt(r,10):0,i=await this.#redisClient.sScan(t,e,{COUNT:n}),a=[];for(let e of i.members){let t=await this.getData(e);u(t)&&a.push(t)}return{items:a,cursor:i.cursor>0?i.cursor.toString():void 0}}catch(t){let n=t;return this.#logger?.error({message:`Error listing data`,error:n,code:k.RedisClientListError,category:e.name}),{items:null}}}async deleteData(t){try{if(!this.#isRedisClientAvailable())return!1;let n=await this.#redisClient.del(t);return n===0&&this.#logger?.debug({message:`No keys deleted for ${t}`,category:e.name}),n>0}catch(t){let n=t;return this.#logger?.error({message:`Error deleting data`,error:n,code:k.RedisClientDeleteError,category:e.name}),!1}}};const xe=(e,t)=>{t.forEach(({eventName:t,listener:n})=>{e.on(t,n)})},Se=(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 Ce=function(e){return e.ScriptManagerExecutionError=`ScriptManagerExecutionError`,e.ScriptManagerLoadingError=`ScriptManagerLoadingError`,e}({});var we=class{cacheClient=null;scriptMap=new Map;logger;scripts;redisClientConfig;constructor(e){this.scripts=e}async initialize({redisClientConfig:e,logger:t,scriptMap:n},...r){this.redisClientConfig=e,this.logger=t,this.cacheClient=await ye(this.redisClientConfig,this.logger)??null,await this.loadScripts(this.scripts,n),await this.additionalInitialization(...r)}async additionalInitialization(...e){}async loadScripts(e,t){u(t)&&(this.scriptMap=t);for(let[t,n]of Object.entries(e)){let e=await this.cacheClient?.loadScript?.(n);u(e)?this.scriptMap?.set(t,e):this.logger?.error({message:`Error loading script ${t}`,category:this.constructor.name,code:Ce.ScriptManagerLoadingError})}}async executeScript(e,t,n){try{await this.isReady()||await this.initialize({redisClientConfig:this.redisClientConfig,logger:this.logger,scriptMap:this.scriptMap});let r=this.scriptMap?.get(e);if(o(r))throw Error(`Script for ${e} not found`);return await this.cacheClient?.executeScript?.({sha1:r,keys:t,args:n})??null}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error executing script ${e}: ${r.message}`,category:this.constructor.name,context:{keys:t,args:n},error:r,code:Ce.ScriptManagerExecutionError}),r}}async isReady(){return u(this.cacheClient)}},Te=class e{options={getCacheClient:ye};subscriptionMap=null;subscriptionClient=null;logger;constructor(e){this.options={...this.options,...e}}async initialize(t=this.options){let{config:n,getCacheClient:r,logger:i}=t;if(this.logger=i,this.subscriptionMap=new me({instantiator:`${t?.instantiator}(${this.constructor.name})`,evictionFrequency:t?.subscriptionTTL,staleDataThreshold:t?.staleSubscriptionsThreshold,truncateThreshold:t?.truncateThreshold,truncationPercentage:t?.truncationPercentage,typeGuard:e=>typeof e==`string`,dispose:async e=>{await this.subscriptionClient?.unsubscribe?.(e)}}),u(n))this.subscriptionClient=await r?.(n,this.logger)??null,this.logger?.info({message:`${e.name} initialized for ${t.instantiator}.`,category:e.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),i=r(t.toString());return await this.subscriptionMap?.setData({key:e,value:i}),n===i?!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 u(this.subscriptionClient)&&u(this.subscriptionMap)}close(){this.subscriptionMap?.close(),this.subscriptionMap=null,this.subscriptionClient=null}};const Ee=6e4,De=15e3,Oe=!1,ke=6e4,Ae=15e3,je=1e4,Me=1;let Ne=function(e){return e.QueueManagerInitializationError=`QueueManagerInitializationError`,e.QueueManagerJoinAndWaitTurnError=`QueueManagerJoinAndWaitTurnError`,e.QueueManagerLengthError=`QueueManagerLengthError`,e.QueueManagerPopError=`QueueManagerPopError`,e}({}),Pe=function(e){return e.rPush=`rPush`,e.lPush=`lPush`,e.lPop=`lPop`,e.llen=`llen`,e}({});const Fe={[Pe.rPush]:`
|
|
2
2
|
local queueLength = redis.call('RPUSH', KEYS[1], ARGV[1])
|
|
3
3
|
|
|
4
4
|
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
|
@@ -14,7 +14,7 @@ import{deepCopy as e,delay as t,exponentialBackoffInMS as n,generateRequestId as
|
|
|
14
14
|
local queueKey = KEYS[1]
|
|
15
15
|
|
|
16
16
|
return redis.call("lpop", queueKey)
|
|
17
|
-
`,[Pe.llen]:`return redis.call("llen", KEYS[1])`};var Ie=class e extends we{static instance=null;static asyncInstanceInit=null;static logger;static config;logger=void 0;subscriptionManager=null;eventClient=null;static async getInstance(t,n,r){if(
|
|
17
|
+
`,[Pe.llen]:`return redis.call("llen", KEYS[1])`};var Ie=class e extends we{static instance=null;static asyncInstanceInit=null;static logger;static config;logger=void 0;subscriptionManager=null;eventClient=null;static async getInstance(t,n,r){if(u(e.instance))return e.instance;e.config=u(t)?t:e.config;let i=e.config;if(o(i))throw Error(`Redis client configuration is required to initialize QueueManager.`);return o(e.asyncInstanceInit)&&(e.asyncInstanceInit=(async()=>{try{let t=new e(Fe);return t.logger=n??e.logger,await t.initialize({redisClientConfig:i,logger:n,scriptMap:r}),e.instance=t,t}catch(t){throw e.logger?.error({message:`Error initializing QueueManager: ${t}`,category:e.name,code:Ne.QueueManagerInitializationError}),t}finally{e.asyncInstanceInit=null}})()),e.asyncInstanceInit}async additionalInitialization(){let t=this.logger??e.logger,n=e.config;if(o(n))throw Error(`Redis client configuration is required to initialize QueueManager.`);this.cacheClient=await ye(n,t)??null,this.subscriptionManager=new Te({config:n,instantiator:e.name,subscriptionTTL:ke,truncateThreshold:je,truncationPercentage:Me}),await this.subscriptionManager?.initialize(),this.eventClient=new ve({instantiator:e.name,timeoutResolveValue:Oe},{instantiator:e.name,evictionFrequency:Ae,truncateThreshold:je,truncationPercentage:Me},{instantiator:e.name,evictionFrequency:Ae,truncateThreshold:je,truncationPercentage:Me}),this.logger?.info({category:e.name,message:`QueueManager initialized.`})}async joinAndWaitTurn(t,n,r,i,a=!0){await this.readyCheck();try{let e=`${t}:${n}`;await this.subscriptionManager?.subscribe(e,async(r,i)=>{if(i.includes(e)&&i.includes(n)){let e=`${t}:${r}`;return this.eventClient?.resolveEvent(e,!0)}});let o=await this.executeScript(r?Pe.lPush:Pe.rPush,[t],[n,Ee.toString()]),s=o===1,c=a?!s:!0;return c&&await this.eventClient?.waitForEvent(e,De),await this.eventClient?.deleteEvent(e),await i(t,n)}catch(r){throw r instanceof Error&&this.logger?.error({message:`Error in joinAndWaitTurn`,category:e.name,error:r,code:Ne.QueueManagerJoinAndWaitTurnError,context:{queueName:t,value:n}}),r}}async pop(t){await this.readyCheck();try{return await this.executeScript(Pe.lPop,[t],[])}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in pop`,category:e.name,error:n,code:Ne.QueueManagerPopError,context:{queueName:t}}),n}}async length(t){await this.readyCheck();try{return await this.executeScript(Pe.llen,[t],[])}catch(n){throw n instanceof Error&&this.logger?.error({message:`Error in length`,category:e.name,error:n,code:Ne.QueueManagerLengthError,context:{queueName:t}}),n}}async readyCheck(){if(!await this.isReady()){let t=e.config;if(o(t))throw Error(`Redis client configuration is required to initialize QueueManager.`);await this.initialize({redisClientConfig:t,logger:e.logger,scriptMap:this.scriptMap})}}async isReady(){return u(e.asyncInstanceInit)&&await e.asyncInstanceInit,u(this.subscriptionManager)&&u(this.cacheClient)&&u(this.scriptMap)&&this.scriptMap.size>0}close(){this.subscriptionManager?.close(),this.cacheClient=null,this.scriptMap?.clear(),e.instance=null}};const Le=5,Re=12e4,ze=1e4,Be=1,Ve=60,He=90,Ue=`__keyevent@0__:`,We=`${Ue}set`,Ge=`${Ue}expire`,Ke=`${Ue}expired`,qe=`${Ue}srem`,Je=`config_check_test_key`,Ye=[We,Ge,Ke],Xe=1,Ze=2500,Qe={mainMaxConcurrency:30};let $e=function(e){return e.ConcurrencyManagerInitializationError=`ConcurrencyManagerInitializationError`,e.ConcurrencyManagerRedisEventsEmitError=`ConcurrencyManagerRedisEventsEmitError`,e.ConcurrencyManagerRegistrationFailed=`ConcurrencyManagerRegistrationFailed`,e}({}),et=function(e){return e.tryConcurrency=`tryConcurrency`,e.removeFromSet=`removeFromSet`,e.publishNextItem=`publishNextItem`,e}({});const tt={[et.tryConcurrency]:`
|
|
18
18
|
local requestId = KEYS[1]
|
|
19
19
|
local targetKey = KEYS[2]
|
|
20
20
|
local queueKey = KEYS[3]
|
|
@@ -114,9 +114,9 @@ import{deepCopy as e,delay as t,exponentialBackoffInMS as n,generateRequestId as
|
|
|
114
114
|
|
|
115
115
|
redis.call('publish', nextItemKey, nextItem)
|
|
116
116
|
end
|
|
117
|
-
`};var nt=class e extends we{static instance=null;static asyncInstanceInit=null;static hasValidRedisConfig=!1;static lastInitFailure=null;static RETRY_WINDOW_MS=1e4;static logger;static initConfig=null;subscriptionManager=null;queueManager=null;generateUUID;static async getInstance(t,n,i,a){if(d(e.instance))return e.instance;let o=Date.now();if(e.lastInitFailure&&o-e.lastInitFailure<e.RETRY_WINDOW_MS)throw Error(`ConcurrencyManager initialization failed recently — retrying too soon.`);return s(e.asyncInstanceInit)&&(s(e.initConfig)?e.initConfig={config:t,logger:n,scriptMap:i,generateUUID:a??r}:(t??=e.initConfig.config,n??=e.initConfig.logger,i??=e.initConfig.scriptMap,a??=e.initConfig.generateUUID),this.logger=n??e.logger,e.asyncInstanceInit=(async()=>{try{let r=new e(tt);if(s(t))throw Error(`Redis client configuration is required to initialize ConcurrencyManager.`);if(await r.initialize({redisClientConfig:t,logger:n,scriptMap:i},a),e.hasValidRedisConfig)this.logger?.info({category:e.name,message:`ConcurrencyManager initialized.`});else throw e.lastInitFailure=Date.now(),e.asyncInstanceInit=null,Error(`Redis is not configured correctly or was too slow to respond.`);return e.instance=r,e.lastInitFailure=null,r}catch(t){throw e.logger?.error({message:`Error initializing ConcurrencyManager: ${t}`,category:e.name,error:t,code:$e.ConcurrencyManagerInitializationError}),t}})()),e.asyncInstanceInit}async additionalInitialization(t){this.generateUUID=t??r;let n=e.initConfig?.config;if(s(n))throw Error(`Redis client configuration is required to initialize ConcurrencyManager.`);this.subscriptionManager=new Te({config:n,logger:e.logger,instantiator:e.name,subscriptionTTL:Re,truncateThreshold:ze,truncationPercentage:Be}),await this.subscriptionManager?.initialize(),e.hasValidRedisConfig=await this.checkRedisEventsEmit(),this.cacheClient=await A(n,e.logger)??null,this.queueManager=await Ie.getInstance(n,e.logger)}async addTestSubscription(t,n,r,i){return s(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(t,async(a,o)=>{o===t&&a.includes(n)&&(r.push(o),r.includes(We)&&r.includes(Ge)&&r.includes(Ke)&&(i(),this.logger?.info({category:e.name,message:`Redis events are being emitted.`,context:{receivedEventCount:r.length}}),r.length=0))})}async checkRedisEventsEmit(){let t=[],n=async(e,n)=>{let r=()=>e(!0),i=this.generateUUID(),a=`${Je}:${i}`,o=(await Promise.all(Ye.map(async e=>this.addTestSubscription(e,a,t,r)))).every(Boolean);if(!o)return n(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:a,value:`test`,cacheTTL:Xe}),setTimeout(()=>{n(Error(`Timeout waiting for Redis events to emit.`))},Ze)};try{return await new Promise(n)}catch(n){return this.logger?.error({category:e.name,message:`Redis events failed to emit.`,context:{receivedEventCount:t.length,reason:n?.message},error:n,code:$e.ConcurrencyManagerRedisEventsEmitError}),!1}}async isRedisConfigured(){return await this.readyCheck(),e.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){await this.readyCheck();let n=await this.subscriptionManager?.subscribe(Ke,async(n,r)=>{r===Ke&&n.includes(t)&&n.includes(e)&&await this.releaseRequest(e,t)});return n??!1}async subscribeToSetRemoval(e,t){await this.readyCheck();let n=await this.subscriptionManager?.subscribe(qe,async(n,r)=>{r===qe&&n.includes(e)&&await this.executeScript(et.publishNextItem,[t],[])});return n??!1}async registerRequest(r,i,a,o){await this.readyCheck();let s=`concurrency:${r}`,c=`queue:${r}`,l=i.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(o??``):o?.includes(e.urlPattern))?.subPoolKey,u=d(l)?`${s}-${l}`:s,{mainMaxConcurrency:f,subPools:p}=i,m=[{key:s,maxConcurrency:f},...p?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${s}-${t}`,maxConcurrency:n}})??[]],h=m.map(e=>e.key),g=m.map(e=>e.maxConcurrency),[_,v]=await Promise.all([this.subscribeToLeaseExpiry(a,u),this.subscribeToSetRemoval(u,c)]),y={requestId:a,targetConcurrencyKey:u,leaseSubscription:_,setRemovalSubscription:v,queueKey:c},[b,x]=await this.executeScript(et.tryConcurrency,[a,u,c,...h],[Ve.toString(),f.toString(),He.toString(),...g.map(String)])??[];if(b)return{...y,joinCondition:`optimistic`,failureReason:x};let S=0,C=[];for(;S<Le;){let r=S>1,[i,o]=await this.queueManager?.joinAndWaitTurn(c,a,r,async(e,t)=>await this.executeScript(et.tryConcurrency,[a,u,c,...h],[Ve.toString(),f.toString(),He.toString(),...g.map(String)]),!1)??[!1,``];if(d(o)&&o!==``&&C.push(o),S++,i)return S>1&&this.logger?.warning({category:e.name,message:`Register request succeeded after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`attempts`,failureMessages:C}}),{...y,joinCondition:`attempts`};let s=n(S,100);await t(s)}return this.logger?.error({category:e.name,message:`Failed to register request after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`failed`,failureMessages:C},code:$e.ConcurrencyManagerRegistrationFailed}),{...y,joinCondition:`failed`}}async releaseRequest(e,t){return await this.readyCheck(),u(t)&&u(e)?!!await this.executeScript(et.removeFromSet,[t],[e]):!1}async readyCheck(){await e.getInstance()}static async isReady(){try{let t=await e.getInstance();return t.subscriptionManager!==null&&t.cacheClient!==null&&t.scriptMap!==null&&t.scriptMap.size>0&&e.hasValidRedisConfig}catch{return!1}}static close(){let t=e.instance;d(t)&&(t.subscriptionManager?.close(),t.queueManager?.close(),t.cacheClient=null,t.scriptMap?.clear()),e.asyncInstanceInit=null,e.hasValidRedisConfig=!1,e.lastInitFailure=null,e.instance=null,e.initConfig=null}};const rt=Object.freeze({status:`aborted`});function j(e,t,n){function r(n,r){var i;for(let a in Object.defineProperty(n,`_zod`,{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r),o.prototype)a in n||Object.defineProperty(n,a,{value:o.prototype[a].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}const it=Symbol(`zod_brand`);var at=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};const ot={};function st(e){return e&&Object.assign(ot,e),ot}function ct(e){let t=Object.values(e).filter(e=>typeof e==`number`),n=Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t);return n}function lt(e,t){return typeof t==`bigint`?t.toString():t}function ut(e){let t=!1;return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}}}}function dt(e){return e==null}function ft(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function pt(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r,a=Number.parseInt(e.toFixed(i).replace(`.`,``)),o=Number.parseInt(t.toFixed(i).replace(`.`,``));return a%o/10**i}function M(e,t,n){let r=!1;Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function mt(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function ht(e){return JSON.stringify(e)}const gt=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function _t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const vt=ut(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{let e=Function;return new e(``),!0}catch{return!1}});function yt(e){if(_t(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(_t(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}const bt=new Set([`string`,`number`,`symbol`]);function xt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function St(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function N(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Ct(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const wt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Tt(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;n[e]=r.shape[e]}return St(e,{...e._zod.def,shape:n,checks:[]})}function Et(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;delete n[e]}return St(e,{...e._zod.def,shape:n,checks:[]})}function Dt(e,t){if(!yt(t))throw Error(`Invalid input to extend: expected a plain object`);let n={...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return mt(this,`shape`,n),n},checks:[]};return St(e,n)}function Ot(e,t){return St(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return mt(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function kt(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t]}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return St(t,{...t._zod.def,shape:i,checks:[]})}function At(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=new e({type:`nonoptional`,innerType:r[t]})}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return St(t,{...t._zod.def,shape:i,checks:[]})}function jt(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Mt(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Nt(e){return typeof e==`string`?e:e?.message}function Pt(e,t,n){let r={...e,path:e.path??[]};if(!e.message){let i=Nt(e.inst?._zod.def?.error?.(e))??Nt(t?.error?.(e))??Nt(n.customError?.(e))??Nt(n.localeError?.(e))??`Invalid input`;r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Ft(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function It(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Lt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),Object.defineProperty(e,`message`,{get(){return JSON.stringify(t,lt,2)},enumerable:!0})},Rt=j(`$ZodError`,Lt),zt=j(`$ZodError`,Lt,{Parent:Error});function Bt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Vt(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i],a=i===t.path.length-1;a?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}const Ht=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new at;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>Pt(e,a,st())));throw gt(t,i?.callee),t}return o.value},Ut=Ht(zt),Wt=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>Pt(e,a,st())));throw gt(t,i?.callee),t}return o.value},Gt=Wt(zt),Kt=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new at;return a.issues.length?{success:!1,error:new(e??Rt)(a.issues.map(e=>Pt(e,i,st())))}:{success:!0,data:a.value}},qt=Kt(zt),Jt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>Pt(e,i,st())))}:{success:!0,data:a.value}},Yt=Jt(zt),Xt=/^[cC][^\s-]{8,}$/,Zt=/^[0-9a-z]+$/,Qt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,$t=/^[0-9a-vA-V]{20}$/,en=/^[A-Za-z0-9]{27}$/,tn=/^[a-zA-Z0-9_-]{21}$/,nn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,rn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,an=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,on=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,sn=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function cn(){return new RegExp(sn,`u`)}const ln=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,un=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,dn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,fn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,pn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,mn=/^[A-Za-z0-9_-]*$/,hn=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,gn=/^\+(?:[0-9]){6,14}[0-9]$/,_n=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,vn=RegExp(`^${_n}$`);function yn(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`,n=typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;return n}function bn(e){return RegExp(`^${yn(e)}$`)}function xn(e){let t=yn({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${_n}T(?:${r})$`)}const Sn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Cn=/^\d+$/,wn=/^-?\d+(?:\.\d+)?/i,Tn=/^[^A-Z]*$/,En=/^[^a-z]*$/,P=j(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Dn={number:`number`,bigint:`bigint`,object:`date`},On=j(`$ZodCheckLessThan`,(e,t)=>{P.init(e,t);let n=Dn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),kn=j(`$ZodCheckGreaterThan`,(e,t)=>{P.init(e,t);let n=Dn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),An=j(`$ZodCheckMultipleOf`,(e,t)=>{P.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);let r=typeof n.value==`bigint`?n.value%t.value===BigInt(0):pt(n.value,t.value)===0;r||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),jn=j(`$ZodCheckNumberFormat`,(e,t)=>{P.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=wt[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Cn)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),Mn=j(`$ZodCheckMaxLength`,(e,t)=>{P.init(e,t),e._zod.when=e=>{let t=e.value;return!dt(t)&&t.length!==void 0},e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i<=t.maximum)return;let a=Ft(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Nn=j(`$ZodCheckMinLength`,(e,t)=>{P.init(e,t),e._zod.when=e=>{let t=e.value;return!dt(t)&&t.length!==void 0},e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i>=t.minimum)return;let a=Ft(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Pn=j(`$ZodCheckLengthEquals`,(e,t)=>{P.init(e,t),e._zod.when=e=>{let t=e.value;return!dt(t)&&t.length!==void 0},e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=Ft(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Fn=j(`$ZodCheckStringFormat`,(e,t)=>{var n,r;P.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),In=j(`$ZodCheckRegex`,(e,t)=>{Fn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Ln=j(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Tn,Fn.init(e,t)}),Rn=j(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=En,Fn.init(e,t)}),zn=j(`$ZodCheckIncludes`,(e,t)=>{P.init(e,t);let n=xt(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Bn=j(`$ZodCheckStartsWith`,(e,t)=>{P.init(e,t);let n=RegExp(`^${xt(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Vn=j(`$ZodCheckEndsWith`,(e,t)=>{P.init(e,t);let n=RegExp(`.*${xt(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Hn=j(`$ZodCheckOverwrite`,(e,t)=>{P.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var Un=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e,n=t.split(`
|
|
117
|
+
`};var nt=class r extends we{static instance=null;static asyncInstanceInit=null;static hasValidRedisConfig=!1;static lastInitFailure=null;static RETRY_WINDOW_MS=1e4;static logger;static initConfig=null;subscriptionManager=null;queueManager=null;generateUUID;static async getInstance(e,t,i,a){if(u(r.instance))return r.instance;let s=Date.now();if(r.lastInitFailure&&s-r.lastInitFailure<r.RETRY_WINDOW_MS)throw Error(`ConcurrencyManager initialization failed recently — retrying too soon.`);return o(r.asyncInstanceInit)&&(o(r.initConfig)?r.initConfig={config:e,logger:t,scriptMap:i,generateUUID:a??n}:(e??=r.initConfig.config,t??=r.initConfig.logger,i??=r.initConfig.scriptMap,a??=r.initConfig.generateUUID),this.logger=t??r.logger,r.asyncInstanceInit=(async()=>{try{let n=new r(tt);if(o(e))throw Error(`Redis client configuration is required to initialize ConcurrencyManager.`);if(await n.initialize({redisClientConfig:e,logger:t,scriptMap:i},a),r.hasValidRedisConfig)this.logger?.info({category:r.name,message:`ConcurrencyManager initialized.`});else throw r.lastInitFailure=Date.now(),r.asyncInstanceInit=null,Error(`Redis is not configured correctly or was too slow to respond.`);return r.instance=n,r.lastInitFailure=null,n}catch(e){throw r.logger?.error({message:`Error initializing ConcurrencyManager: ${e}`,category:r.name,error:e,code:$e.ConcurrencyManagerInitializationError}),e}})()),r.asyncInstanceInit}async additionalInitialization(e){this.generateUUID=e??n;let t=r.initConfig?.config;if(o(t))throw Error(`Redis client configuration is required to initialize ConcurrencyManager.`);this.subscriptionManager=new Te({config:t,logger:r.logger,instantiator:r.name,subscriptionTTL:Re,truncateThreshold:ze,truncationPercentage:Be}),await this.subscriptionManager?.initialize(),r.hasValidRedisConfig=await this.checkRedisEventsEmit(),this.cacheClient=await ye(t,r.logger)??null,this.queueManager=await Ie.getInstance(t,r.logger)}async addTestSubscription(e,t,n,i){return o(this.subscriptionManager)?!1:this.subscriptionManager.subscribe(e,async(a,o)=>{o===e&&a.includes(t)&&(n.push(o),n.includes(We)&&n.includes(Ge)&&n.includes(Ke)&&(i(),this.logger?.info({category:r.name,message:`Redis events are being emitted.`,context:{receivedEventCount:n.length}}),n.length=0))})}async checkRedisEventsEmit(){let e=[],t=async(t,n)=>{let r=()=>t(!0),i=this.generateUUID(),a=`${Je}:${i}`,o=(await Promise.all(Ye.map(async t=>this.addTestSubscription(t,a,e,r)))).every(Boolean);if(!o)return n(Error(`Failed to subscribe to event channels.`));await this.cacheClient?.setData({key:a,value:`test`,cacheTTL:Xe}),setTimeout(()=>{n(Error(`Timeout waiting for Redis events to emit.`))},Ze)};try{return await new Promise(t)}catch(t){return this.logger?.error({category:r.name,message:`Redis events failed to emit.`,context:{receivedEventCount:e.length,reason:t?.message},error:t,code:$e.ConcurrencyManagerRedisEventsEmitError}),!1}}async isRedisConfigured(){return await this.readyCheck(),r.hasValidRedisConfig}async subscribeToLeaseExpiry(e,t){await this.readyCheck();let n=await this.subscriptionManager?.subscribe(Ke,async(n,r)=>{r===Ke&&n.includes(t)&&n.includes(e)&&await this.releaseRequest(e,t)});return n??!1}async subscribeToSetRemoval(e,t){await this.readyCheck();let n=await this.subscriptionManager?.subscribe(qe,async(n,r)=>{r===qe&&n.includes(e)&&await this.executeScript(et.publishNextItem,[t],[])});return n??!1}async registerRequest(n,i,a,o){await this.readyCheck();let s=`concurrency:${n}`,c=`queue:${n}`,l=i.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(o??``):o?.includes(e.urlPattern))?.subPoolKey,d=u(l)?`${s}-${l}`:s,{mainMaxConcurrency:f,subPools:p}=i,m=[{key:s,maxConcurrency:f},...p?.map(e=>{let{subPoolKey:t,maxConcurrency:n}=e;return{key:`${s}-${t}`,maxConcurrency:n}})??[]],h=m.map(e=>e.key),g=m.map(e=>e.maxConcurrency),[_,v]=await Promise.all([this.subscribeToLeaseExpiry(a,d),this.subscribeToSetRemoval(d,c)]),y={requestId:a,targetConcurrencyKey:d,leaseSubscription:_,setRemovalSubscription:v,queueKey:c},[b,x]=await this.executeScript(et.tryConcurrency,[a,d,c,...h],[Ve.toString(),f.toString(),He.toString(),...g.map(String)])??[];if(b)return{...y,joinCondition:`optimistic`,failureReason:x};let S=0,C=[];for(;S<Le;){let n=S>1,[i,o]=await this.queueManager?.joinAndWaitTurn(c,a,n,async(e,t)=>await this.executeScript(et.tryConcurrency,[a,d,c,...h],[Ve.toString(),f.toString(),He.toString(),...g.map(String)]),!1)??[!1,``];if(u(o)&&o!==``&&C.push(o),S++,i)return S>1&&this.logger?.warning({category:r.name,message:`Register request succeeded after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`attempts`,failureMessages:C}}),{...y,joinCondition:`attempts`};let s=t(S,100);await e(s)}return this.logger?.error({category:r.name,message:`Failed to register request after ${S} attempts.`,context:{...y,registerAttempts:S,joinCondition:`failed`,failureMessages:C},code:$e.ConcurrencyManagerRegistrationFailed}),{...y,joinCondition:`failed`}}async releaseRequest(e,t){return await this.readyCheck(),l(t)&&l(e)?!!await this.executeScript(et.removeFromSet,[t],[e]):!1}async readyCheck(){await r.getInstance()}static async isReady(){try{let e=await r.getInstance();return e.subscriptionManager!==null&&e.cacheClient!==null&&e.scriptMap!==null&&e.scriptMap.size>0&&r.hasValidRedisConfig}catch{return!1}}static close(){let e=r.instance;u(e)&&(e.subscriptionManager?.close(),e.queueManager?.close(),e.cacheClient=null,e.scriptMap?.clear()),r.asyncInstanceInit=null,r.hasValidRedisConfig=!1,r.lastInitFailure=null,r.instance=null,r.initConfig=null}};Object.freeze({status:`aborted`});function A(e,t,n){function r(n,r){var i;for(let a in Object.defineProperty(n,`_zod`,{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r),o.prototype)a in n||Object.defineProperty(n,a,{value:o.prototype[a].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}Symbol(`zod_brand`);var rt=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};const it={};function at(e){return e&&Object.assign(it,e),it}function ot(e){let t=Object.values(e).filter(e=>typeof e==`number`),n=Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t);return n}function st(e,t){return typeof t==`bigint`?t.toString():t}function ct(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function lt(e){return e==null}function ut(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function dt(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r,a=Number.parseInt(e.toFixed(i).replace(`.`,``)),o=Number.parseInt(t.toFixed(i).replace(`.`,``));return a%o/10**i}function j(e,t,n){Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}throw Error(`cached value already set`)},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function ft(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function pt(e){return JSON.stringify(e)}const mt=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const gt=ct(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{let e=Function;return new e(``),!0}catch{return!1}});function _t(e){if(ht(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(ht(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}const vt=new Set([`string`,`number`,`symbol`]);function yt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function bt(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function M(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function xt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const St={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ct(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;n[e]=r.shape[e]}return bt(e,{...e._zod.def,shape:n,checks:[]})}function wt(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;delete n[e]}return bt(e,{...e._zod.def,shape:n,checks:[]})}function Tt(e,t){if(!_t(t))throw Error(`Invalid input to extend: expected a plain object`);let n={...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return ft(this,`shape`,n),n},checks:[]};return bt(e,n)}function Et(e,t){return bt(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return ft(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function Dt(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t]}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return bt(t,{...t._zod.def,shape:i,checks:[]})}function Ot(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=new e({type:`nonoptional`,innerType:r[t]})}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return bt(t,{...t._zod.def,shape:i,checks:[]})}function kt(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function At(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function jt(e){return typeof e==`string`?e:e?.message}function Mt(e,t,n){let r={...e,path:e.path??[]};if(!e.message){let i=jt(e.inst?._zod.def?.error?.(e))??jt(t?.error?.(e))??jt(n.customError?.(e))??jt(n.localeError?.(e))??`Invalid input`;r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Nt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Pt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Ft=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),Object.defineProperty(e,`message`,{get(){return JSON.stringify(t,st,2)},enumerable:!0}),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},It=A(`$ZodError`,Ft),Lt=A(`$ZodError`,Ft,{Parent:Error});function Rt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function zt(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i],a=i===t.path.length-1;a?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}const Bt=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new rt;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>Mt(e,a,at())));throw mt(t,i?.callee),t}return o.value},Vt=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>Mt(e,a,at())));throw mt(t,i?.callee),t}return o.value},Ht=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new rt;return a.issues.length?{success:!1,error:new(e??It)(a.issues.map(e=>Mt(e,i,at())))}:{success:!0,data:a.value}},Ut=Ht(Lt),Wt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>Mt(e,i,at())))}:{success:!0,data:a.value}},Gt=Wt(Lt),Kt=/^[cC][^\s-]{8,}$/,qt=/^[0-9a-z]+$/,Jt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Yt=/^[0-9a-vA-V]{20}$/,Xt=/^[A-Za-z0-9]{27}$/,Zt=/^[a-zA-Z0-9_-]{21}$/,Qt=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,$t=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,en=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,tn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,nn=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function rn(){return new RegExp(nn,`u`)}const an=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,on=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,sn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ln=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,un=/^[A-Za-z0-9_-]*$/,dn=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,fn=/^\+(?:[0-9]){6,14}[0-9]$/,pn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,mn=RegExp(`^${pn}$`);function hn(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`,n=typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;return n}function gn(e){return RegExp(`^${hn(e)}$`)}function _n(e){let t=hn({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${pn}T(?:${r})$`)}const vn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},yn=/^\d+$/,bn=/^-?\d+(?:\.\d+)?/i,xn=/^[^A-Z]*$/,Sn=/^[^a-z]*$/,N=A(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Cn={number:`number`,bigint:`bigint`,object:`date`},wn=A(`$ZodCheckLessThan`,(e,t)=>{N.init(e,t);let n=Cn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Tn=A(`$ZodCheckGreaterThan`,(e,t)=>{N.init(e,t);let n=Cn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),En=A(`$ZodCheckMultipleOf`,(e,t)=>{N.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);let r=typeof n.value==`bigint`?n.value%t.value===BigInt(0):dt(n.value,t.value)===0;r||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Dn=A(`$ZodCheckNumberFormat`,(e,t)=>{N.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=St[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=yn)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),On=A(`$ZodCheckMaxLength`,(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!lt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i<=t.maximum)return;let a=Nt(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),kn=A(`$ZodCheckMinLength`,(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!lt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i>=t.minimum)return;let a=Nt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),An=A(`$ZodCheckLengthEquals`,(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!lt(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=Nt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),jn=A(`$ZodCheckStringFormat`,(e,t)=>{var n,r;N.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Mn=A(`$ZodCheckRegex`,(e,t)=>{jn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Nn=A(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=xn,jn.init(e,t)}),Pn=A(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Sn,jn.init(e,t)}),Fn=A(`$ZodCheckIncludes`,(e,t)=>{N.init(e,t);let n=yt(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),In=A(`$ZodCheckStartsWith`,(e,t)=>{N.init(e,t);let n=RegExp(`^${yt(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Ln=A(`$ZodCheckEndsWith`,(e,t)=>{N.init(e,t);let n=RegExp(`.*${yt(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Rn=A(`$ZodCheckOverwrite`,(e,t)=>{N.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var zn=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e,n=t.split(`
|
|
118
118
|
`).filter(e=>e),r=Math.min(...n.map(e=>e.length-e.trimStart().length)),i=n.map(e=>e.slice(r)).map(e=>` `.repeat(this.indent*2)+e);for(let e of i)this.content.push(e)}compile(){let e=Function,t=this?.args,n=this?.content??[``],r=[...n.map(e=>` ${e}`)];return new e(...t,r.join(`
|
|
119
|
-
`))}};const
|
|
119
|
+
`))}};const Bn={major:4,minor:0,patch:0},P=A(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Bn;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=kt(e),i;for(let a of t){if(a._zod.def.when){let t=a._zod.def.when(e);if(!t)continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new rt;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o;let n=e.issues.length;n!==t&&(r||=kt(e,t))});else{let n=e.issues.length;if(n===t)continue;r||=kt(e,t)}}return i?i.then(()=>e):e};e._zod.run=(n,i)=>{let a=e._zod.parse(n,i);if(a instanceof Promise){if(i.async===!1)throw new rt;return a.then(e=>t(e,r,i))}return t(a,r,i)}}e[`~standard`]={validate:t=>{try{let n=Ut(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Gt(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}}),Vn=A(`$ZodString`,(e,t)=>{P.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??vn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),F=A(`$ZodStringFormat`,(e,t)=>{jn.init(e,t),Vn.init(e,t)}),Hn=A(`$ZodGUID`,(e,t)=>{t.pattern??=$t,F.init(e,t)}),Un=A(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8},n=e[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=en(n)}else t.pattern??=en();F.init(e,t)}),Wn=A(`$ZodEmail`,(e,t)=>{t.pattern??=tn,F.init(e,t)}),Gn=A(`$ZodURL`,(e,t)=>{F.init(e,t),e._zod.check=n=>{try{let r=n.value,i=new URL(r),a=i.href;t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:dn.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),!r.endsWith(`/`)&&a.endsWith(`/`)?n.value=a.slice(0,-1):n.value=a;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Kn=A(`$ZodEmoji`,(e,t)=>{t.pattern??=rn(),F.init(e,t)}),qn=A(`$ZodNanoID`,(e,t)=>{t.pattern??=Zt,F.init(e,t)}),Jn=A(`$ZodCUID`,(e,t)=>{t.pattern??=Kt,F.init(e,t)}),Yn=A(`$ZodCUID2`,(e,t)=>{t.pattern??=qt,F.init(e,t)}),Xn=A(`$ZodULID`,(e,t)=>{t.pattern??=Jt,F.init(e,t)}),Zn=A(`$ZodXID`,(e,t)=>{t.pattern??=Yt,F.init(e,t)}),Qn=A(`$ZodKSUID`,(e,t)=>{t.pattern??=Xt,F.init(e,t)}),$n=A(`$ZodISODateTime`,(e,t)=>{t.pattern??=_n(t),F.init(e,t)}),er=A(`$ZodISODate`,(e,t)=>{t.pattern??=mn,F.init(e,t)}),tr=A(`$ZodISOTime`,(e,t)=>{t.pattern??=gn(t),F.init(e,t)}),nr=A(`$ZodISODuration`,(e,t)=>{t.pattern??=Qt,F.init(e,t)}),rr=A(`$ZodIPv4`,(e,t)=>{t.pattern??=an,F.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv4`})}),ir=A(`$ZodIPv6`,(e,t)=>{t.pattern??=on,F.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv6`}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),ar=A(`$ZodCIDRv4`,(e,t)=>{t.pattern??=sn,F.init(e,t)}),or=A(`$ZodCIDRv6`,(e,t)=>{t.pattern??=cn,F.init(e,t),e._zod.check=n=>{let[r,i]=n.value.split(`/`);try{if(!i)throw Error();let e=Number(i);if(`${e}`!==i||e<0||e>128)throw Error();new URL(`http://[${r}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function sr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const cr=A(`$ZodBase64`,(e,t)=>{t.pattern??=ln,F.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64`}),e._zod.check=n=>{sr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function lr(e){if(!un.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`),n=t.padEnd(Math.ceil(t.length/4)*4,`=`);return sr(n)}const ur=A(`$ZodBase64URL`,(e,t)=>{t.pattern??=un,F.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64url`}),e._zod.check=n=>{lr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),dr=A(`$ZodE164`,(e,t)=>{t.pattern??=fn,F.init(e,t)});function fr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const pr=A(`$ZodJWT`,(e,t)=>{F.init(e,t),e._zod.check=n=>{fr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),mr=A(`$ZodNumber`,(e,t)=>{P.init(e,t),e._zod.pattern=e._zod.bag.pattern??bn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),hr=A(`$ZodNumber`,(e,t)=>{Dn.init(e,t),mr.init(e,t)}),gr=A(`$ZodUnknown`,(e,t)=>{P.init(e,t),e._zod.parse=e=>e}),_r=A(`$ZodNever`,(e,t)=>{P.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function vr(e,t,n){e.issues.length&&t.issues.push(...At(n,e.issues)),t.value[n]=e.value}const yr=A(`$ZodArray`,(e,t)=>{P.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>vr(t,n,e))):vr(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function br(e,t,n){e.issues.length&&t.issues.push(...At(n,e.issues)),t.value[n]=e.value}function xr(e,t,n,r){e.issues.length?r[n]===void 0?n in r?t.value[n]=void 0:t.value[n]=e.value:t.issues.push(...At(n,e.issues)):e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}const Sr=A(`$ZodObject`,(e,t)=>{P.init(e,t);let n=ct(()=>{let e=Object.keys(t.shape);for(let n of e)if(!(t.shape[n]instanceof P))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=xt(t.shape);return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});j(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=e=>{let t=new zn([`shape`,`payload`,`ctx`]),r=n.value,i=e=>{let t=pt(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of r.keys)a[e]=`key_${o++}`;t.write(`const newResult = {}`);for(let e of r.keys)if(r.optionalKeys.has(e)){let n=a[e];t.write(`const ${n} = ${i(e)};`);let r=pt(e);t.write(`
|
|
120
120
|
if (${n}.issues.length) {
|
|
121
121
|
if (input[${r}] === undefined) {
|
|
122
122
|
if (${r} in input) {
|
|
@@ -138,8 +138,8 @@ import{deepCopy as e,delay as t,exponentialBackoffInMS as n,generateRequestId as
|
|
|
138
138
|
`)}else{let n=a[e];t.write(`const ${n} = ${i(e)};`),t.write(`
|
|
139
139
|
if (${n}.issues.length) payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
140
140
|
...iss,
|
|
141
|
-
path: iss.path ? [${
|
|
142
|
-
})));`),t.write(`newResult[${ht(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=_t,o=!ot.jitless,s=vt,c=o&&s.value,l=t.catchall,u;e._zod.parse=(s,d)=>{u??=n.value;let f=s.value;if(!a(f))return s.issues.push({expected:`object`,code:`invalid_type`,input:f,inst:e}),s;let p=[];if(o&&c&&d?.async===!1&&d.jitless!==!0)i||=r(t.shape),s=i(s,d);else{s.value={};let e=u.shape;for(let t of u.keys){let n=e[t],r=n._zod.run({value:f[t],issues:[]},d),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?p.push(r.then(e=>i?Tr(e,s,t,f):wr(e,s,t))):i?Tr(r,s,t,f):wr(r,s,t)}}if(!l)return p.length?Promise.all(p).then(()=>s):s;let m=[],h=u.keySet,g=l._zod,_=g.def.type;for(let e of Object.keys(f)){if(h.has(e))continue;if(_===`never`){m.push(e);continue}let t=g.run({value:f[e],issues:[]},d);t instanceof Promise?p.push(t.then(t=>wr(t,s,e))):wr(t,s,e)}return m.length&&s.issues.push({code:`unrecognized_keys`,keys:m,input:f,inst:e}),p.length?Promise.all(p).then(()=>s):s}});function Dr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Pt(e,r,st())))}),t}const Or=j(`$ZodUnion`,(e,t)=>{F.init(e,t),M(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),M(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),M(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),M(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>ft(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>Dr(t,n,e,r)):Dr(a,n,e,r)}}),kr=j(`$ZodIntersection`,(e,t)=>{F.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>jr(e,t,n)):jr(e,i,a)}});function Ar(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(yt(e)&&yt(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Ar(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Ar(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function jr(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),jt(e))return e;let r=Ar(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Mr=j(`$ZodEnum`,(e,t)=>{F.init(e,t);let n=ct(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>bt.has(typeof e)).map(e=>typeof e==`string`?xt(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),Nr=j(`$ZodTransform`,(e,t)=>{F.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new at;return e.value=r,e}}),Pr=j(`$ZodOptional`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),M(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ft(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),Fr=j(`$ZodNullable`,(e,t)=>{F.init(e,t),M(e._zod,`optin`,()=>t.innerType._zod.optin),M(e._zod,`optout`,()=>t.innerType._zod.optout),M(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ft(e.source)}|null)$`):void 0}),M(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Ir=j(`$ZodDefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Lr(e,t)):Lr(r,t)}});function Lr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Rr=j(`$ZodPrefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),zr=j(`$ZodNonOptional`,(e,t)=>{F.init(e,t),M(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Br(t,e)):Br(i,e)}});function Br(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Vr=j(`$ZodCatch`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,M(e._zod,`optout`,()=>t.innerType._zod.optout),M(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Pt(e,n,st()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Pt(e,n,st()))},input:e.value}),e.issues=[]),e)}}),Hr=j(`$ZodPipe`,(e,t)=>{F.init(e,t),M(e._zod,`values`,()=>t.in._zod.values),M(e._zod,`optin`,()=>t.in._zod.optin),M(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Ur(e,t,n)):Ur(r,t,n)}});function Ur(e,t,n){return jt(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Wr=j(`$ZodReadonly`,(e,t)=>{F.init(e,t),M(e._zod,`propValues`,()=>t.innerType._zod.propValues),M(e._zod,`values`,()=>t.innerType._zod.values),M(e._zod,`optin`,()=>t.innerType._zod.optin),M(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Gr):Gr(r)}});function Gr(e){return e.value=Object.freeze(e.value),e}const Kr=j(`$ZodCustom`,(e,t)=>{P.init(e,t),F.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>qr(t,n,r,e));qr(i,n,r,e)}});function qr(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(It(e))}}const Jr=Symbol(`ZodOutput`),Yr=Symbol(`ZodInput`);var Xr=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}remove(e){return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function Zr(){return new Xr}const Qr=Zr();function $r(e,t){return new e({type:`string`,...N(t)})}function ei(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function ti(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function ni(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function ri(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function ii(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function ai(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...N(t)})}function oi(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...N(t)})}function si(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function ci(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function li(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function ui(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function di(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...N(t)})}function fi(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...N(t)})}function pi(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function mi(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function hi(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function gi(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function _i(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function vi(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function yi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function bi(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function xi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function Si(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function Ci(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function wi(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function Ti(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function Ei(e,t){return new e({type:`number`,checks:[],...N(t)})}function Di(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function Oi(e){return new e({type:`unknown`})}function ki(e,t){return new e({type:`never`,...N(t)})}function Ai(e,t){return new On({check:`less_than`,...N(t),value:e,inclusive:!1})}function ji(e,t){return new On({check:`less_than`,...N(t),value:e,inclusive:!0})}function Mi(e,t){return new kn({check:`greater_than`,...N(t),value:e,inclusive:!1})}function Ni(e,t){return new kn({check:`greater_than`,...N(t),value:e,inclusive:!0})}function Pi(e,t){return new An({check:`multiple_of`,...N(t),value:e})}function Fi(e,t){let n=new Mn({check:`max_length`,...N(t),maximum:e});return n}function Ii(e,t){return new Nn({check:`min_length`,...N(t),minimum:e})}function Li(e,t){return new Pn({check:`length_equals`,...N(t),length:e})}function Ri(e,t){return new In({check:`string_format`,format:`regex`,...N(t),pattern:e})}function zi(e){return new Ln({check:`string_format`,format:`lowercase`,...N(e)})}function Bi(e){return new Rn({check:`string_format`,format:`uppercase`,...N(e)})}function Vi(e,t){return new zn({check:`string_format`,format:`includes`,...N(t),includes:e})}function Hi(e,t){return new Bn({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function Ui(e,t){return new Vn({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function Wi(e){return new Hn({check:`overwrite`,tx:e})}function Gi(e){return Wi(t=>t.normalize(e))}function Ki(){return Wi(e=>e.trim())}function qi(){return Wi(e=>e.toLowerCase())}function Ji(){return Wi(e=>e.toUpperCase())}function Yi(e,t,n){return new e({type:`array`,element:t,...N(n)})}function Xi(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...N(n)});return r}const Zi=j(`ZodISODateTime`,(e,t)=>{rr.init(e,t),R.init(e,t)});function Qi(e){return Si(Zi,e)}const $i=j(`ZodISODate`,(e,t)=>{ir.init(e,t),R.init(e,t)});function ea(e){return Ci($i,e)}const ta=j(`ZodISOTime`,(e,t)=>{ar.init(e,t),R.init(e,t)});function na(e){return wi(ta,e)}const ra=j(`ZodISODuration`,(e,t)=>{or.init(e,t),R.init(e,t)});function ia(e){return Ti(ra,e)}const aa=(e,t)=>{Rt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Vt(e,t)},flatten:{value:t=>Bt(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})},oa=j(`ZodError`,aa),sa=j(`ZodError`,aa,{Parent:Error}),ca=Ht(sa),la=Wt(sa),ua=Kt(sa),da=Jt(sa),L=j(`ZodType`,(e,t)=>(F.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>St(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>ca(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>ua(e,t,n),e.parseAsync=async(t,n)=>la(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>da(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(yo(t,n)),e.superRefine=t=>e.check(bo(t)),e.overwrite=t=>e.check(Wi(t)),e.optional=()=>to(e),e.nullable=()=>ro(e),e.nullish=()=>to(ro(e)),e.nonoptional=t=>lo(e,t),e.array=()=>Ua(e),e.or=t=>qa([e,t]),e.and=t=>Ya(e,t),e.transform=t=>mo(e,$a(t)),e.default=t=>ao(e,t),e.prefault=t=>so(e,t),e.catch=t=>fo(e,t),e.pipe=t=>mo(e,t),e.readonly=()=>go(e),e.describe=t=>{let n=e.clone();return Qr.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Qr.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Qr.get(e);let n=e.clone();return Qr.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),fa=j(`_ZodString`,(e,t)=>{Gn.init(e,t),L.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Ri(...t)),e.includes=(...t)=>e.check(Vi(...t)),e.startsWith=(...t)=>e.check(Hi(...t)),e.endsWith=(...t)=>e.check(Ui(...t)),e.min=(...t)=>e.check(Ii(...t)),e.max=(...t)=>e.check(Fi(...t)),e.length=(...t)=>e.check(Li(...t)),e.nonempty=(...t)=>e.check(Ii(1,...t)),e.lowercase=t=>e.check(zi(t)),e.uppercase=t=>e.check(Bi(t)),e.trim=()=>e.check(Ki()),e.normalize=(...t)=>e.check(Gi(...t)),e.toLowerCase=()=>e.check(qi()),e.toUpperCase=()=>e.check(Ji())}),pa=j(`ZodString`,(e,t)=>{Gn.init(e,t),fa.init(e,t),e.email=t=>e.check(ei(ha,t)),e.url=t=>e.check(oi(va,t)),e.jwt=t=>e.check(xi(Na,t)),e.emoji=t=>e.check(si(ya,t)),e.guid=t=>e.check(ti(ga,t)),e.uuid=t=>e.check(ni(_a,t)),e.uuidv4=t=>e.check(ri(_a,t)),e.uuidv6=t=>e.check(ii(_a,t)),e.uuidv7=t=>e.check(ai(_a,t)),e.nanoid=t=>e.check(ci(ba,t)),e.guid=t=>e.check(ti(ga,t)),e.cuid=t=>e.check(li(xa,t)),e.cuid2=t=>e.check(ui(Sa,t)),e.ulid=t=>e.check(di(Ca,t)),e.base64=t=>e.check(vi(Aa,t)),e.base64url=t=>e.check(yi(ja,t)),e.xid=t=>e.check(fi(wa,t)),e.ksuid=t=>e.check(pi(Ta,t)),e.ipv4=t=>e.check(mi(Ea,t)),e.ipv6=t=>e.check(hi(Da,t)),e.cidrv4=t=>e.check(gi(Oa,t)),e.cidrv6=t=>e.check(_i(ka,t)),e.e164=t=>e.check(bi(Ma,t)),e.datetime=t=>e.check(Qi(t)),e.date=t=>e.check(ea(t)),e.time=t=>e.check(na(t)),e.duration=t=>e.check(ia(t))});function ma(e){return $r(pa,e)}const R=j(`ZodStringFormat`,(e,t)=>{I.init(e,t),fa.init(e,t)}),ha=j(`ZodEmail`,(e,t)=>{Jn.init(e,t),R.init(e,t)}),ga=j(`ZodGUID`,(e,t)=>{Kn.init(e,t),R.init(e,t)}),_a=j(`ZodUUID`,(e,t)=>{qn.init(e,t),R.init(e,t)}),va=j(`ZodURL`,(e,t)=>{Yn.init(e,t),R.init(e,t)}),ya=j(`ZodEmoji`,(e,t)=>{Xn.init(e,t),R.init(e,t)}),ba=j(`ZodNanoID`,(e,t)=>{Zn.init(e,t),R.init(e,t)}),xa=j(`ZodCUID`,(e,t)=>{Qn.init(e,t),R.init(e,t)}),Sa=j(`ZodCUID2`,(e,t)=>{$n.init(e,t),R.init(e,t)}),Ca=j(`ZodULID`,(e,t)=>{er.init(e,t),R.init(e,t)}),wa=j(`ZodXID`,(e,t)=>{tr.init(e,t),R.init(e,t)}),Ta=j(`ZodKSUID`,(e,t)=>{nr.init(e,t),R.init(e,t)}),Ea=j(`ZodIPv4`,(e,t)=>{sr.init(e,t),R.init(e,t)}),Da=j(`ZodIPv6`,(e,t)=>{cr.init(e,t),R.init(e,t)}),Oa=j(`ZodCIDRv4`,(e,t)=>{lr.init(e,t),R.init(e,t)}),ka=j(`ZodCIDRv6`,(e,t)=>{ur.init(e,t),R.init(e,t)}),Aa=j(`ZodBase64`,(e,t)=>{fr.init(e,t),R.init(e,t)}),ja=j(`ZodBase64URL`,(e,t)=>{mr.init(e,t),R.init(e,t)}),Ma=j(`ZodE164`,(e,t)=>{hr.init(e,t),R.init(e,t)}),Na=j(`ZodJWT`,(e,t)=>{_r.init(e,t),R.init(e,t)}),Pa=j(`ZodNumber`,(e,t)=>{vr.init(e,t),L.init(e,t),e.gt=(t,n)=>e.check(Mi(t,n)),e.gte=(t,n)=>e.check(Ni(t,n)),e.min=(t,n)=>e.check(Ni(t,n)),e.lt=(t,n)=>e.check(Ai(t,n)),e.lte=(t,n)=>e.check(ji(t,n)),e.max=(t,n)=>e.check(ji(t,n)),e.int=t=>e.check(La(t)),e.safe=t=>e.check(La(t)),e.positive=t=>e.check(Mi(0,t)),e.nonnegative=t=>e.check(Ni(0,t)),e.negative=t=>e.check(Ai(0,t)),e.nonpositive=t=>e.check(ji(0,t)),e.multipleOf=(t,n)=>e.check(Pi(t,n)),e.step=(t,n)=>e.check(Pi(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Fa(e){return Ei(Pa,e)}const Ia=j(`ZodNumberFormat`,(e,t)=>{yr.init(e,t),Pa.init(e,t)});function La(e){return Di(Ia,e)}const Ra=j(`ZodUnknown`,(e,t)=>{br.init(e,t),L.init(e,t)});function za(){return Oi(Ra)}const Ba=j(`ZodNever`,(e,t)=>{xr.init(e,t),L.init(e,t)});function Va(e){return ki(Ba,e)}const Ha=j(`ZodArray`,(e,t)=>{Cr.init(e,t),L.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Ii(t,n)),e.nonempty=t=>e.check(Ii(1,t)),e.max=(t,n)=>e.check(Fi(t,n)),e.length=(t,n)=>e.check(Li(t,n)),e.unwrap=()=>e.element});function Ua(e,t){return Yi(Ha,e,t)}const Wa=j(`ZodObject`,(e,t)=>{Er.init(e,t),L.init(e,t),M(e,`shape`,()=>t.shape),e.keyof=()=>Za(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:za()}),e.loose=()=>e.clone({...e._zod.def,catchall:za()}),e.strict=()=>e.clone({...e._zod.def,catchall:Va()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Dt(e,t),e.merge=t=>Ot(e,t),e.pick=t=>Tt(e,t),e.omit=t=>Et(e,t),e.partial=(...t)=>kt(eo,e,t[0]),e.required=(...t)=>At(co,e,t[0])});function Ga(e,t){let n={type:`object`,get shape(){return mt(this,`shape`,{...e}),this.shape},...N(t)};return new Wa(n)}const Ka=j(`ZodUnion`,(e,t)=>{Or.init(e,t),L.init(e,t),e.options=t.options});function qa(e,t){return new Ka({type:`union`,options:e,...N(t)})}const Ja=j(`ZodIntersection`,(e,t)=>{kr.init(e,t),L.init(e,t)});function Ya(e,t){return new Ja({type:`intersection`,left:e,right:t})}const Xa=j(`ZodEnum`,(e,t)=>{Mr.init(e,t),L.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Xa({...t,checks:[],...N(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Xa({...t,checks:[],...N(r),entries:i})}});function Za(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Xa({type:`enum`,entries:n,...N(t)})}const Qa=j(`ZodTransform`,(e,t)=>{Nr.init(e,t),L.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(It(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(It(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function $a(e){return new Qa({type:`transform`,transform:e})}const eo=j(`ZodOptional`,(e,t)=>{Pr.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType});function to(e){return new eo({type:`optional`,innerType:e})}const no=j(`ZodNullable`,(e,t)=>{Fr.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ro(e){return new no({type:`nullable`,innerType:e})}const io=j(`ZodDefault`,(e,t)=>{Ir.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ao(e,t){return new io({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const oo=j(`ZodPrefault`,(e,t)=>{Rr.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType});function so(e,t){return new oo({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const co=j(`ZodNonOptional`,(e,t)=>{zr.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType});function lo(e,t){return new co({type:`nonoptional`,innerType:e,...N(t)})}const uo=j(`ZodCatch`,(e,t)=>{Vr.init(e,t),L.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function fo(e,t){return new uo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const po=j(`ZodPipe`,(e,t)=>{Hr.init(e,t),L.init(e,t),e.in=t.in,e.out=t.out});function mo(e,t){return new po({type:`pipe`,in:e,out:t})}const ho=j(`ZodReadonly`,(e,t)=>{Wr.init(e,t),L.init(e,t)});function go(e){return new ho({type:`readonly`,innerType:e})}const _o=j(`ZodCustom`,(e,t)=>{Kr.init(e,t),L.init(e,t)});function vo(e,t){let n=new P({check:`custom`,...N(t)});return n._zod.check=e,n}function yo(e,t={}){return Xi(_o,e,t)}function bo(e,t){let n=vo(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(It(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(It(r))}},e(t.value,t)),t);return n}const xo=Ga({receivedStatus:Fa(),targetStatus:Fa(),message:ma().optional(),condition:ma().optional()}),So={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`};var Co=class e extends Error{response;constructor(t,n){super(n),this.name=`HttpResponseError`,this.response=t,this.message=n??`HTTP error: ${t.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}},wo=class{static createInstance({interceptors:e,instanceConfig:t,httpAgentConfig:n,logger:r,context:i}){let a=new h.Agent(n),o=p.create({...t,httpAgent:a});if(e){let t={axiosInstance:o,logger:r,context:i};this.applyInterceptors(o,e,t)}return o}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t,a=[{type:`request`,configs:r},{type:`response`,configs:i}];a.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 d(e)&&a(e)&&typeof e(t)==`function`?e(t):e??null}};const To=300;var Eo=class e{static instance=null;static logger=null;dataStore=null;constructor(e){this.initialize(e)}static getInstance(t){return s(e.instance)&&(e.instance=new e(t)),e.instance}initialize(t){this.dataStore=new he({instantiator:e.name,logger:t,typeGuard:e=>d(e)}),e.logger=t??null,e.logger?.info({category:e.name,message:`InstanceManager initialized.`})}async get(t){return this.ensureReady(),await e.getInstance().dataStore?.getData(t)??null}async set(t,n,r){return this.ensureReady(),await e.getInstance().dataStore?.setData({key:t,value:n,cacheTTL:d(r)?r:To})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return d(this?.dataStore)}close(){e.instance=null,this.dataStore=null}};const Do=Eo.getInstance(),Oo=()=>{let e=e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)};return e};let ko=function(e){return e.RateLimitManagerInitializationError=`RateLimitManagerInitializationError`,e}({});const Ao=7.5,jo={mainRatelimit:25};let Mo=function(e){return e.incr=`incr`,e}({});const No={[Mo.incr]:`
|
|
141
|
+
path: iss.path ? [${pt(e)}, ...iss.path] : [${pt(e)}]
|
|
142
|
+
})));`),t.write(`newResult[${pt(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=ht,o=!it.jitless,s=gt,c=o&&s.value,l=t.catchall,u;e._zod.parse=(s,d)=>{u??=n.value;let f=s.value;if(!a(f))return s.issues.push({expected:`object`,code:`invalid_type`,input:f,inst:e}),s;let p=[];if(o&&c&&d?.async===!1&&d.jitless!==!0)i||=r(t.shape),s=i(s,d);else{s.value={};let e=u.shape;for(let t of u.keys){let n=e[t],r=n._zod.run({value:f[t],issues:[]},d),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?p.push(r.then(e=>i?xr(e,s,t,f):br(e,s,t))):i?xr(r,s,t,f):br(r,s,t)}}if(!l)return p.length?Promise.all(p).then(()=>s):s;let m=[],h=u.keySet,g=l._zod,_=g.def.type;for(let e of Object.keys(f)){if(h.has(e))continue;if(_===`never`){m.push(e);continue}let t=g.run({value:f[e],issues:[]},d);t instanceof Promise?p.push(t.then(t=>br(t,s,e))):br(t,s,e)}return m.length&&s.issues.push({code:`unrecognized_keys`,keys:m,input:f,inst:e}),p.length?Promise.all(p).then(()=>s):s}});function Cr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Mt(e,r,at())))}),t}const wr=A(`$ZodUnion`,(e,t)=>{P.init(e,t),j(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),j(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),j(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),j(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>ut(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>Cr(t,n,e,r)):Cr(a,n,e,r)}}),Tr=A(`$ZodIntersection`,(e,t)=>{P.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>Dr(e,t,n)):Dr(e,i,a)}});function Er(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(_t(e)&&_t(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Er(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Er(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Dr(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),kt(e))return e;let r=Er(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Or=A(`$ZodEnum`,(e,t)=>{P.init(e,t);let n=ot(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>vt.has(typeof e)).map(e=>typeof e==`string`?yt(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),kr=A(`$ZodTransform`,(e,t)=>{P.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new rt;return e.value=r,e}}),Ar=A(`$ZodOptional`,(e,t)=>{P.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,j(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),j(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ut(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),jr=A(`$ZodNullable`,(e,t)=>{P.init(e,t),j(e._zod,`optin`,()=>t.innerType._zod.optin),j(e._zod,`optout`,()=>t.innerType._zod.optout),j(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ut(e.source)}|null)$`):void 0}),j(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Mr=A(`$ZodDefault`,(e,t)=>{P.init(e,t),e._zod.optin=`optional`,j(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Nr(e,t)):Nr(r,t)}});function Nr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Pr=A(`$ZodPrefault`,(e,t)=>{P.init(e,t),e._zod.optin=`optional`,j(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Fr=A(`$ZodNonOptional`,(e,t)=>{P.init(e,t),j(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Ir(t,e)):Ir(i,e)}});function Ir(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Lr=A(`$ZodCatch`,(e,t)=>{P.init(e,t),e._zod.optin=`optional`,j(e._zod,`optout`,()=>t.innerType._zod.optout),j(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Mt(e,n,at()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Mt(e,n,at()))},input:e.value}),e.issues=[]),e)}}),Rr=A(`$ZodPipe`,(e,t)=>{P.init(e,t),j(e._zod,`values`,()=>t.in._zod.values),j(e._zod,`optin`,()=>t.in._zod.optin),j(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>zr(e,t,n)):zr(r,t,n)}});function zr(e,t,n){return kt(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Br=A(`$ZodReadonly`,(e,t)=>{P.init(e,t),j(e._zod,`propValues`,()=>t.innerType._zod.propValues),j(e._zod,`values`,()=>t.innerType._zod.values),j(e._zod,`optin`,()=>t.innerType._zod.optin),j(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Vr):Vr(r)}});function Vr(e){return e.value=Object.freeze(e.value),e}const Hr=A(`$ZodCustom`,(e,t)=>{N.init(e,t),P.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Ur(t,n,r,e));Ur(i,n,r,e)}});function Ur(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Pt(e))}}Symbol(`ZodOutput`),Symbol(`ZodInput`);var Wr=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function Gr(){return new Wr}const Kr=Gr();function qr(e,t){return new e({type:`string`,...M(t)})}function Jr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...M(t)})}function Yr(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...M(t)})}function Xr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...M(t)})}function Zr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...M(t)})}function Qr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...M(t)})}function $r(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...M(t)})}function ei(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...M(t)})}function ti(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...M(t)})}function ni(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...M(t)})}function ri(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...M(t)})}function ii(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...M(t)})}function ai(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...M(t)})}function oi(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...M(t)})}function si(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...M(t)})}function ci(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...M(t)})}function li(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...M(t)})}function ui(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...M(t)})}function di(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...M(t)})}function fi(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...M(t)})}function pi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...M(t)})}function mi(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...M(t)})}function hi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...M(t)})}function gi(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...M(t)})}function _i(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...M(t)})}function vi(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...M(t)})}function yi(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...M(t)})}function bi(e,t){return new e({type:`number`,checks:[],...M(t)})}function xi(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...M(t)})}function Si(e){return new e({type:`unknown`})}function Ci(e,t){return new e({type:`never`,...M(t)})}function wi(e,t){return new wn({check:`less_than`,...M(t),value:e,inclusive:!1})}function Ti(e,t){return new wn({check:`less_than`,...M(t),value:e,inclusive:!0})}function Ei(e,t){return new Tn({check:`greater_than`,...M(t),value:e,inclusive:!1})}function Di(e,t){return new Tn({check:`greater_than`,...M(t),value:e,inclusive:!0})}function Oi(e,t){return new En({check:`multiple_of`,...M(t),value:e})}function ki(e,t){let n=new On({check:`max_length`,...M(t),maximum:e});return n}function Ai(e,t){return new kn({check:`min_length`,...M(t),minimum:e})}function ji(e,t){return new An({check:`length_equals`,...M(t),length:e})}function Mi(e,t){return new Mn({check:`string_format`,format:`regex`,...M(t),pattern:e})}function Ni(e){return new Nn({check:`string_format`,format:`lowercase`,...M(e)})}function Pi(e){return new Pn({check:`string_format`,format:`uppercase`,...M(e)})}function Fi(e,t){return new Fn({check:`string_format`,format:`includes`,...M(t),includes:e})}function Ii(e,t){return new In({check:`string_format`,format:`starts_with`,...M(t),prefix:e})}function Li(e,t){return new Ln({check:`string_format`,format:`ends_with`,...M(t),suffix:e})}function Ri(e){return new Rn({check:`overwrite`,tx:e})}function zi(e){return Ri(t=>t.normalize(e))}function Bi(){return Ri(e=>e.trim())}function Vi(){return Ri(e=>e.toLowerCase())}function Hi(){return Ri(e=>e.toUpperCase())}function Ui(e,t,n){return new e({type:`array`,element:t,...M(n)})}function Wi(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...M(n)});return r}const Gi=A(`ZodISODateTime`,(e,t)=>{$n.init(e,t),L.init(e,t)});function Ki(e){return gi(Gi,e)}const qi=A(`ZodISODate`,(e,t)=>{er.init(e,t),L.init(e,t)});function Ji(e){return _i(qi,e)}const Yi=A(`ZodISOTime`,(e,t)=>{tr.init(e,t),L.init(e,t)});function Xi(e){return vi(Yi,e)}const Zi=A(`ZodISODuration`,(e,t)=>{nr.init(e,t),L.init(e,t)});function Qi(e){return yi(Zi,e)}const $i=(e,t)=>{It.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>zt(e,t)},flatten:{value:t=>Rt(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})};A(`ZodError`,$i);const ea=A(`ZodError`,$i,{Parent:Error}),ta=Bt(ea),na=Vt(ea),ra=Ht(ea),ia=Wt(ea),I=A(`ZodType`,(e,t)=>(P.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>bt(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>ta(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>ra(e,t,n),e.parseAsync=async(t,n)=>na(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ia(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(fo(t,n)),e.superRefine=t=>e.check(po(t)),e.overwrite=t=>e.check(Ri(t)),e.optional=()=>Ja(e),e.nullable=()=>Xa(e),e.nullish=()=>Ja(Xa(e)),e.nonoptional=t=>no(e,t),e.array=()=>Ia(e),e.or=t=>Ba([e,t]),e.and=t=>Ha(e,t),e.transform=t=>oo(e,Ka(t)),e.default=t=>Qa(e,t),e.prefault=t=>eo(e,t),e.catch=t=>io(e,t),e.pipe=t=>oo(e,t),e.readonly=()=>co(e),e.describe=t=>{let n=e.clone();return Kr.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Kr.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Kr.get(e);let n=e.clone();return Kr.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),aa=A(`_ZodString`,(e,t)=>{Vn.init(e,t),I.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Mi(...t)),e.includes=(...t)=>e.check(Fi(...t)),e.startsWith=(...t)=>e.check(Ii(...t)),e.endsWith=(...t)=>e.check(Li(...t)),e.min=(...t)=>e.check(Ai(...t)),e.max=(...t)=>e.check(ki(...t)),e.length=(...t)=>e.check(ji(...t)),e.nonempty=(...t)=>e.check(Ai(1,...t)),e.lowercase=t=>e.check(Ni(t)),e.uppercase=t=>e.check(Pi(t)),e.trim=()=>e.check(Bi()),e.normalize=(...t)=>e.check(zi(...t)),e.toLowerCase=()=>e.check(Vi()),e.toUpperCase=()=>e.check(Hi())}),oa=A(`ZodString`,(e,t)=>{Vn.init(e,t),aa.init(e,t),e.email=t=>e.check(Jr(ca,t)),e.url=t=>e.check(ei(da,t)),e.jwt=t=>e.check(hi(Ea,t)),e.emoji=t=>e.check(ti(fa,t)),e.guid=t=>e.check(Yr(la,t)),e.uuid=t=>e.check(Xr(ua,t)),e.uuidv4=t=>e.check(Zr(ua,t)),e.uuidv6=t=>e.check(Qr(ua,t)),e.uuidv7=t=>e.check($r(ua,t)),e.nanoid=t=>e.check(ni(pa,t)),e.guid=t=>e.check(Yr(la,t)),e.cuid=t=>e.check(ri(ma,t)),e.cuid2=t=>e.check(ii(ha,t)),e.ulid=t=>e.check(ai(ga,t)),e.base64=t=>e.check(fi(Ca,t)),e.base64url=t=>e.check(pi(wa,t)),e.xid=t=>e.check(oi(_a,t)),e.ksuid=t=>e.check(si(va,t)),e.ipv4=t=>e.check(ci(ya,t)),e.ipv6=t=>e.check(li(ba,t)),e.cidrv4=t=>e.check(ui(xa,t)),e.cidrv6=t=>e.check(di(Sa,t)),e.e164=t=>e.check(mi(Ta,t)),e.datetime=t=>e.check(Ki(t)),e.date=t=>e.check(Ji(t)),e.time=t=>e.check(Xi(t)),e.duration=t=>e.check(Qi(t))});function sa(e){return qr(oa,e)}const L=A(`ZodStringFormat`,(e,t)=>{F.init(e,t),aa.init(e,t)}),ca=A(`ZodEmail`,(e,t)=>{Wn.init(e,t),L.init(e,t)}),la=A(`ZodGUID`,(e,t)=>{Hn.init(e,t),L.init(e,t)}),ua=A(`ZodUUID`,(e,t)=>{Un.init(e,t),L.init(e,t)}),da=A(`ZodURL`,(e,t)=>{Gn.init(e,t),L.init(e,t)}),fa=A(`ZodEmoji`,(e,t)=>{Kn.init(e,t),L.init(e,t)}),pa=A(`ZodNanoID`,(e,t)=>{qn.init(e,t),L.init(e,t)}),ma=A(`ZodCUID`,(e,t)=>{Jn.init(e,t),L.init(e,t)}),ha=A(`ZodCUID2`,(e,t)=>{Yn.init(e,t),L.init(e,t)}),ga=A(`ZodULID`,(e,t)=>{Xn.init(e,t),L.init(e,t)}),_a=A(`ZodXID`,(e,t)=>{Zn.init(e,t),L.init(e,t)}),va=A(`ZodKSUID`,(e,t)=>{Qn.init(e,t),L.init(e,t)}),ya=A(`ZodIPv4`,(e,t)=>{rr.init(e,t),L.init(e,t)}),ba=A(`ZodIPv6`,(e,t)=>{ir.init(e,t),L.init(e,t)}),xa=A(`ZodCIDRv4`,(e,t)=>{ar.init(e,t),L.init(e,t)}),Sa=A(`ZodCIDRv6`,(e,t)=>{or.init(e,t),L.init(e,t)}),Ca=A(`ZodBase64`,(e,t)=>{cr.init(e,t),L.init(e,t)}),wa=A(`ZodBase64URL`,(e,t)=>{ur.init(e,t),L.init(e,t)}),Ta=A(`ZodE164`,(e,t)=>{dr.init(e,t),L.init(e,t)}),Ea=A(`ZodJWT`,(e,t)=>{pr.init(e,t),L.init(e,t)}),Da=A(`ZodNumber`,(e,t)=>{mr.init(e,t),I.init(e,t),e.gt=(t,n)=>e.check(Ei(t,n)),e.gte=(t,n)=>e.check(Di(t,n)),e.min=(t,n)=>e.check(Di(t,n)),e.lt=(t,n)=>e.check(wi(t,n)),e.lte=(t,n)=>e.check(Ti(t,n)),e.max=(t,n)=>e.check(Ti(t,n)),e.int=t=>e.check(Aa(t)),e.safe=t=>e.check(Aa(t)),e.positive=t=>e.check(Ei(0,t)),e.nonnegative=t=>e.check(Di(0,t)),e.negative=t=>e.check(wi(0,t)),e.nonpositive=t=>e.check(Ti(0,t)),e.multipleOf=(t,n)=>e.check(Oi(t,n)),e.step=(t,n)=>e.check(Oi(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Oa(e){return bi(Da,e)}const ka=A(`ZodNumberFormat`,(e,t)=>{hr.init(e,t),Da.init(e,t)});function Aa(e){return xi(ka,e)}const ja=A(`ZodUnknown`,(e,t)=>{gr.init(e,t),I.init(e,t)});function Ma(){return Si(ja)}const Na=A(`ZodNever`,(e,t)=>{_r.init(e,t),I.init(e,t)});function Pa(e){return Ci(Na,e)}const Fa=A(`ZodArray`,(e,t)=>{yr.init(e,t),I.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Ai(t,n)),e.nonempty=t=>e.check(Ai(1,t)),e.max=(t,n)=>e.check(ki(t,n)),e.length=(t,n)=>e.check(ji(t,n)),e.unwrap=()=>e.element});function Ia(e,t){return Ui(Fa,e,t)}const La=A(`ZodObject`,(e,t)=>{Sr.init(e,t),I.init(e,t),j(e,`shape`,()=>t.shape),e.keyof=()=>Wa(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ma()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ma()}),e.strict=()=>e.clone({...e._zod.def,catchall:Pa()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Tt(e,t),e.merge=t=>Et(e,t),e.pick=t=>Ct(e,t),e.omit=t=>wt(e,t),e.partial=(...t)=>Dt(qa,e,t[0]),e.required=(...t)=>Ot(to,e,t[0])});function Ra(e,t){let n={type:`object`,get shape(){return ft(this,`shape`,{...e}),this.shape},...M(t)};return new La(n)}const za=A(`ZodUnion`,(e,t)=>{wr.init(e,t),I.init(e,t),e.options=t.options});function Ba(e,t){return new za({type:`union`,options:e,...M(t)})}const Va=A(`ZodIntersection`,(e,t)=>{Tr.init(e,t),I.init(e,t)});function Ha(e,t){return new Va({type:`intersection`,left:e,right:t})}const Ua=A(`ZodEnum`,(e,t)=>{Or.init(e,t),I.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ua({...t,checks:[],...M(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ua({...t,checks:[],...M(r),entries:i})}});function Wa(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Ua({type:`enum`,entries:n,...M(t)})}const Ga=A(`ZodTransform`,(e,t)=>{kr.init(e,t),I.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Pt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(Pt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Ka(e){return new Ga({type:`transform`,transform:e})}const qa=A(`ZodOptional`,(e,t)=>{Ar.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ja(e){return new qa({type:`optional`,innerType:e})}const Ya=A(`ZodNullable`,(e,t)=>{jr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Xa(e){return new Ya({type:`nullable`,innerType:e})}const Za=A(`ZodDefault`,(e,t)=>{Mr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Qa(e,t){return new Za({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const $a=A(`ZodPrefault`,(e,t)=>{Pr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function eo(e,t){return new $a({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const to=A(`ZodNonOptional`,(e,t)=>{Fr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType});function no(e,t){return new to({type:`nonoptional`,innerType:e,...M(t)})}const ro=A(`ZodCatch`,(e,t)=>{Lr.init(e,t),I.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function io(e,t){return new ro({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const ao=A(`ZodPipe`,(e,t)=>{Rr.init(e,t),I.init(e,t),e.in=t.in,e.out=t.out});function oo(e,t){return new ao({type:`pipe`,in:e,out:t})}const so=A(`ZodReadonly`,(e,t)=>{Br.init(e,t),I.init(e,t)});function co(e){return new so({type:`readonly`,innerType:e})}const lo=A(`ZodCustom`,(e,t)=>{Hr.init(e,t),I.init(e,t)});function uo(e){let t=new N({check:`custom`});return t._zod.check=e,t}function fo(e,t={}){return Wi(lo,e,t)}function po(e){let t=uo(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(Pt(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(Pt(r))}},e(n.value,n)));return t}const mo=Ra({receivedStatus:Oa(),targetStatus:Oa(),message:sa().optional(),condition:sa().optional()}),ho={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`};var go=class e extends Error{response;constructor(t,n){super(n),this.name=`HttpResponseError`,this.response=t,this.message=n??`HTTP error: ${t.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.name} [${this.response.status}]${e}`}},_o=class{static createInstance({interceptors:e,instanceConfig:t,httpsAgentConfig:n,logger:r,context:i,requestConfig:a}){let o=new m.Agent(n),s=f.create({...t,httpsAgent:o});if(e){let t={axiosInstance:s,logger:r,context:i,requestConfig:a};this.applyInterceptors(s,e,t)}return s}static applyInterceptors(e,t,n){let{requestConfigs:r=[],responseConfigs:i=[]}=t,a=[{type:`request`,configs:r},{type:`response`,configs:i}];a.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 u(e)&&i(e)&&typeof e(t)==`function`?e(t):e??null}};const vo=300;var yo=class e{static instance=null;static logger=null;dataStore=null;constructor(e){this.initialize(e)}static getInstance(t){return o(e.instance)&&(e.instance=new e(t)),e.instance}initialize(t){this.dataStore=new me({instantiator:e.name,logger:t,typeGuard:e=>u(e)}),e.logger=t??null,e.logger?.info({category:e.name,message:`InstanceManager initialized.`})}async get(t){return this.ensureReady(),await e.getInstance().dataStore?.getData(t)??null}async set(t,n,r){return this.ensureReady(),await e.getInstance().dataStore?.setData({key:t,value:n,cacheTTL:u(r)?r:vo})??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return u(this?.dataStore)}close(){e.instance=null,this.dataStore=null}};const bo=yo.getInstance(),xo=()=>{let e=e=>{let{response:t}=e;return e?.code===`ERR_CANCELED`&&(e.response={...t,status:499,statusText:`Request aborted`}),Promise.reject(e)};return e};let So=function(e){return e.RateLimitManagerInitializationError=`RateLimitManagerInitializationError`,e}({});const Co=7.5,wo={mainRatelimit:25};let To=function(e){return e.incr=`incr`,e}({});const Eo={[To.incr]:`
|
|
143
143
|
local targetKey = KEYS[1]
|
|
144
144
|
local totalLimit = tonumber(ARGV[1])
|
|
145
145
|
|
|
@@ -181,17 +181,17 @@ import{deepCopy as e,delay as t,exponentialBackoffInMS as n,generateRequestId as
|
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
return nil
|
|
184
|
-
`},
|
|
184
|
+
`},Do=1,Oo=1e3,ko=0,Ao=59,jo=.8,Mo=500;var No=class e extends we{static instance=null;static asyncInstanceInit=null;static logger;static initConfig=null;static async getInstance(t,n,r){return u(e.instance)?e.instance:(o(e.asyncInstanceInit)&&(o(e.initConfig)?e.initConfig={config:t,logger:n,scriptMap:r}:(t=e.initConfig.config,n=e.initConfig.logger,r=e.initConfig.scriptMap),this.logger=n??e.logger,e.asyncInstanceInit=(async()=>{try{let i=new e(Eo);if(o(t))throw Error(`Redis client configuration is required to initialize RateLimitManager.`);return await i.initialize({redisClientConfig:t,logger:n,scriptMap:r}),e.instance=i,i}catch(t){throw e.logger?.error({message:`Error initializing RateLimitManager: ${t}`,category:e.name,code:So.RateLimitManagerInitializationError}),t}finally{e.asyncInstanceInit=null}})()),e.asyncInstanceInit)}async getDynamicMaxWaitTime(e,t,n,r=Ao,i=jo,a=Mo){await this.readyCheck();let o=e.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.rateLimit??e.mainRatelimit;if(o<=ko)throw Error(`Requests per second (rps) must be greater than 0.`);let s=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.maxConcurrency??t.mainMaxConcurrency;if(s<=ko)throw Error(`Concurrency must be greater than 0.`);let c=r*i,l=Math.min(o,s/(a/Oo)),u=Do/l,d=Math.max(Co,c*u);return Math.min(c,d)}async getWaitTime(e,t,n){await this.readyCheck();let r=`rateLimit:${e}`,i=t.subPools?.find(e=>e.urlPattern instanceof RegExp?e.urlPattern.test(n??``):n?.includes(e.urlPattern))?.subPoolKey,a=u(i)?`${r}-${i}`:r,{mainRatelimit:o,subPools:s}=t,c=[{key:r,rateLimit:o},...s?.map(e=>{let{subPoolKey:t,rateLimit:n}=e;return{key:`${r}-${t}`,rateLimit:n}})??[]],l=c.map(e=>e.key),d=c.map(e=>e.rateLimit);return await this.executeScript(To.incr,[a,...l],[o.toString(),...d.map(String)])??0}async readyCheck(){await e.getInstance()}static async isReady(){try{let t=await e.getInstance();return u(t.cacheClient)&&u(t.scriptMap)}catch{return!1}}static close(){let t=e.instance;u(t)&&(t.cacheClient=null,t.scriptMap?.clear()),e.asyncInstanceInit=null,e.instance=null,e.initConfig=null}};const Po=(e,t,n,r)=>{let i=Error(e);return i.config={...t,headers:{}},i.code=n,i.response=r,i.isAxiosError=!0,i},Fo=(e,t,n)=>{let r=t.signal;return r?r.aborted?Promise.reject(Po(`Request aborted`,t,`ERR_CANCELED`,n)):new Promise((i,a)=>{let o=!1,s,c=Po(`Request aborted`,t,`ERR_CANCELED`,n),l=()=>{if(!o){o=!0,s&&g(s);try{r.removeEventListener?.(`abort`,u)}catch{}}},u=()=>{l(),a(c)},d=()=>{l(),i()};try{r.addEventListener?.(`abort`,u,{once:!0})}catch{s=setTimeout(()=>{i()},e);return}if(r.aborted){l(),a(c);return}s=setTimeout(d,e)}):new Promise(t=>setTimeout(t,e))},Io=`checkConcurrencyInterceptor`,Lo=({logger:e,context:t,requestConfig:n})=>{let r=async r=>{if(r.signal?.aborted)return Promise.reject(Po(`Request aborted`,r,`ERR_CANCELED`));if(o(t))e?.warning({category:`HttpClient`,message:`No context for this request - that doesn't seem right.`,context:{interceptor:Io,...r,headers:void 0}});else if(u(t.provider)&&u(t.accountSecureId)){let i=h(),{provider:a,accountSecureId:o}=t,s=n?.rateLimits??wo,c=n?.concurrency??Qe,l=await No.getInstance(),u=await nt.getInstance(),d=await l.getDynamicMaxWaitTime(s,c,r.url),f=async()=>u.registerRequest(`${o}-${a}`,c,i,r.url),p,m=0;for(;m<=d;){let n=Math.floor(Date.now()/1e3),i=await l.getWaitTime(`${o}-${a}`,s,r.url)??0,c=Math.max(i-n,0);if(i===0){p=await f();break}if(await Fo(c*1e3,r),m+=c,m>=d){p=await f(),e?.warning({category:`HttpClient`,message:`Max Wait Time Exceeded for ${a} - Account: ${o}`,context:{...t,interceptor:Io,...r,headers:void 0,dynamicMaxWaitTime:d}});break}}return{...r,requestMetadata:p}}return r};return r},Ro=1,zo=10,Bo=5,Vo=3250368e4,Ho=1e3,Uo=/^\d+(\.\d+)?$/,Wo=1e3,Go=e=>e<Vo?e*Ho:e;var Ko=w(((exports,t)=>{function n(){return t.exports=n=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,n.apply(null,arguments)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports})),qo={epsilon:1e-12,matrix:`Matrix`,number:`number`,precision:64,predictable:!1,randomSeed:null};function R(e){return typeof e==`number`}function Jo(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 Yo(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isComplex===!0||!1}function Xo(e){return e&&typeof e==`object`&&Object.getPrototypeOf(e).isFraction===!0||!1}function Zo(e){return e&&e.constructor.prototype.isUnit===!0||!1}function Qo(e){return typeof e==`string`}var z=Array.isArray;function $o(e){return e&&e.constructor.prototype.isMatrix===!0||!1}function es(e){return Array.isArray(e)||$o(e)}function ts(e){return e&&e.isDenseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function ns(e){return e&&e.isSparseMatrix&&e.constructor.prototype.isMatrix===!0||!1}function rs(e){return e&&e.constructor.prototype.isRange===!0||!1}function os(e){return e&&e.constructor.prototype.isIndex===!0||!1}function ss(e){return typeof e==`boolean`}function cs(e){return e&&e.constructor.prototype.isResultSet===!0||!1}function ls(e){return e&&e.constructor.prototype.isHelp===!0||!1}function us(e){return typeof e==`function`}function ds(e){return e instanceof Date}function fs(e){return e instanceof RegExp}function ps(e){return!!(e&&typeof e==`object`&&e.constructor===Object&&!Yo(e)&&!Xo(e))}function ms(e){return e===null}function hs(e){return e===void 0}function gs(e){return e&&e.isAccessorNode===!0&&e.constructor.prototype.isNode===!0||!1}function _s(e){return e&&e.isArrayNode===!0&&e.constructor.prototype.isNode===!0||!1}function vs(e){return e&&e.isAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function ys(e){return e&&e.isBlockNode===!0&&e.constructor.prototype.isNode===!0||!1}function bs(e){return e&&e.isConditionalNode===!0&&e.constructor.prototype.isNode===!0||!1}function xs(e){return e&&e.isConstantNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ss(e){return e&&e.isFunctionAssignmentNode===!0&&e.constructor.prototype.isNode===!0||!1}function Cs(e){return e&&e.isFunctionNode===!0&&e.constructor.prototype.isNode===!0||!1}function ws(e){return e&&e.isIndexNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ts(e){return e&&e.isNode===!0&&e.constructor.prototype.isNode===!0||!1}function Es(e){return e&&e.isObjectNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ds(e){return e&&e.isOperatorNode===!0&&e.constructor.prototype.isNode===!0||!1}function Os(e){return e&&e.isParenthesisNode===!0&&e.constructor.prototype.isNode===!0||!1}function ks(e){return e&&e.isRangeNode===!0&&e.constructor.prototype.isNode===!0||!1}function As(e){return e&&e.isRelationalNode===!0&&e.constructor.prototype.isNode===!0||!1}function js(e){return e&&e.isSymbolNode===!0&&e.constructor.prototype.isNode===!0||!1}function Ms(e){return e&&e.constructor.prototype.isChain===!0||!1}function Ns(e){var t=typeof e;return t===`object`?e===null?`null`:Jo(e)?`BigNumber`:e.constructor&&e.constructor.name?e.constructor.name:`Object`:t}function Ps(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 Ps(e)});if(e instanceof Date)return new Date(e.valueOf());if(Jo(e))return e;if(ps(e))return Fs(e,Ps);throw TypeError(`Cannot clone: unknown type of value (value: ${e})`)}function Fs(e,t){var n={};for(var r in e)Ls(e,r)&&(n[r]=t(e[r]));return n}function Is(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(!Is(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)||!Is(e[n],t[n]))return!1;for(n in t)if(!(n in e))return!1;return!0}else return e===t}function Ls(e,t){return e&&Object.hasOwnProperty.call(e,t)}function Rs(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 zs=[`Matrix`,`Array`],Bs=[`number`,`BigNumber`,`Fraction`],Vs=E(Ko(),1),Hs=function(e){if(e)throw Error(`The global config is readonly.
|
|
185
185
|
Please create a mathjs instance if you want to change the default configuration.
|
|
186
186
|
Example:
|
|
187
187
|
|
|
188
188
|
import { create, all } from 'mathjs';
|
|
189
189
|
const mathjs = create(all);
|
|
190
190
|
mathjs.config({ number: 'BigNumber' });
|
|
191
|
-
`);return Object.freeze(es)};(0,Js.default)(Ys,es,{MATRIX_OPTIONS:Ks,NUMBER_OPTIONS:qs});var Xs=T((exports,t)=>{(function(n,r){typeof exports==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n[`'typed'`]=r())})(void 0,function(){"use strict";function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{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:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];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(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=Array.isArray(t)?t.join(`,`):t,o=te(a),s=x(o);if(!i||s in e.signatures){let t=e._typedFunctionData.signatureMap.get(s);if(t)return t}let c=o.length,l;if(i){l=[];let t;for(t in e.signatures)l.push(e._typedFunctionData.signatureMap.get(t))}else l=e._typedFunctionData.signatures;for(let e=0;e<c;++e){let t=o[e],n=[],r;for(r of l){let i=E(r.params,e);if(!i||t.restParam&&!i.restParam)continue;if(!i.hasAny){let e=ee(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}if(l=n,l.length===0)break}let u;for(u of l)if(u.params.length<=c)return u;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(o,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(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++){let n=f(r[t].from);if(n.test(e))return r[t].convert(e)}throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=t?e.length>3?e.slice(3):`any`:e,r=n.split(`|`).map(e=>f(e.trim())),i=!1,a=t?`...`:``,o=r.map(function(e){return i=e.isAny||i,a+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}});return{types:o,name:a.slice(0,-1),hasAny:i,hasConversion:!1,restParam:t}}function C(e){let t=e.types.map(e=>e.name),n=le(t),r=e.hasAny,i=e.name,a=n.map(function(e){let t=f(e.from);return r=t.isAny||r,i+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(a),name:i,hasAny:r,hasConversion:a.length>0,restParam:e.restParam}}function ee(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function te(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=S(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 w(e){let t=A(e);return t?t.restParam:!1}function T(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function ne(e){let t,n,r;if(w(e)){t=k(e).map(T);let n=t.length,r=T(A(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=T(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=T(e[0]),r=T(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(T),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function E(e,t){return t<e.length?e[t]:w(e)?A(e):null}function re(e,t){let n=E(e,t);return n?ee(n):new Set}function D(e){return e.conversion===null||e.conversion===void 0}function O(e,t){let n=new Set;return e.forEach(e=>{let r=re(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function ie(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=E(n.params,s),i=T(r);(s<n.params.length||w(n.params))&&i(t[s])&&e.push(n)}),e.length===0){if(i=O(o,s),i.length>0){let e=g(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 w(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=O(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(g(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 ae(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)D(e.types[n])&&(t=Math.min(t,e.types[n].typeIndex));return t}function oe(e){let t=u+1;for(let n=0;n<e.types.length;n++)D(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function se(e,t){if(e.hasAny){if(!t.hasAny)return 1}else if(t.hasAny)return-1;if(e.restParam){if(!t.restParam)return 1}else if(t.restParam)return-1;if(e.hasConversion){if(!t.hasConversion)return 1}else if(t.hasConversion)return-1;let n=ae(e)-ae(t);if(n<0)return-1;if(n>0)return 1;let r=oe(e)-oe(t);return r<0?-1:r>0?1:0}function ce(e,t){let n=e.params,r=t.params,i=A(n),a=A(r),o=w(n),s=w(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1}else if(s&&a.hasAny)return-1;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;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1}else if(s&&a.hasConversion)return-1;if(l!==f)return l-f;if(o){if(!s)return 1}else if(s)return-1;let p=(n.length-r.length)*(o?-1:1);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=se(n[e],r[e]);m.push(t),h+=t}if(h!==0)return h;let g;for(g of m)if(g!==0)return g;return 0}function le(e){if(e.length===0)return[];let t=e.map(f);e.length>1&&t.sort((e,t)=>e.index-t.index);let n=t[0].conversionsTo;if(e.length===1)return n;n=n.concat([]);let r=new Set(e);for(let e=1;e<t.length;++e){let i;for(i of t[e].conversionsTo)r.has(i.from)||(n.push(i),r.add(i.from))}return n}function ue(e,t){let n=t;if(e.some(e=>e.hasConversion)){let r=w(e),i=e.map(de);n=function(){let e=[],n=r?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=i[t](arguments[t]);return r&&(e[n]=arguments[n].map(i[n])),t.apply(this,e)}}let r=n;if(w(e)){let t=e.length-1;r=function(){return n.apply(this,be(arguments,0,t).concat([be(arguments,t)]))}}return r}function de(e){let t,n,r,i,a=[],o=[];switch(e.types.forEach(function(e){e.conversion&&(a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),o.length){case 0:return function(e){return e};case 1:return t=a[0],r=o[0],function(e){return t(e)?r(e):e};case 2:return t=a[0],n=a[1],r=o[0],i=o[1],function(e){return t(e)?r(e):n(e)?i(e):e};default:return function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}}function fe(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(D);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return Se(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function pe(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=re(e,r),i=re(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=w(e),o=w(t);return a?o?r===i:i>=r:o?r>=i:r===i}function me(e){return e.map(e=>De(e)?Te(e.referToSelf.callback):Ee(e)?we(e.referTo.references,e.referTo.callback):e)}function he(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 ge(e,t,n){let r=me(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(De(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(Ee(s)){let n=he(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 _e(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 ve(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&_e(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=te(c);if(!e)continue;i.forEach(function(t){if(pe(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of fe(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(ce);let l=ge(a,o,je),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!w(f[0].params),h=f[1]&&f[1].params.length<=2&&!w(f[1].params),g=f[2]&&f[2].params.length<=2&&!w(f[2].params),_=f[3]&&f[3].params.length<=2&&!w(f[3].params),v=f[4]&&f[4].params.length<=2&&!w(f[4].params),y=f[5]&&f[5].params.length<=2&&!w(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=ne(f[e].params);let S=m?T(f[0].params[0]):t,ee=h?T(f[1].params[0]):t,E=g?T(f[2].params[0]):t,re=_?T(f[3].params[0]):t,D=v?T(f[4].params[0]):t,O=y?T(f[5].params[0]):t,ie=m?T(f[0].params[1]):t,ae=h?T(f[1].params[1]):t,oe=g?T(f[2].params[1]):t,se=_?T(f[3].params[1]):t,le=v?T(f[4].params[1]):t,de=y?T(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=ue(f[e].params,f[e].fn);let me=m?f[0].implementation:n,he=h?f[1].implementation:n,ve=g?f[2].implementation:n,ye=_?f[3].implementation:n,k=v?f[4].implementation:n,A=y?f[5].implementation:n,be=m?f[0].params.length:-1,xe=h?f[1].params.length:-1,Se=g?f[2].params.length:-1,Ce=_?f[3].params.length:-1,we=v?f[4].params.length:-1,Te=y?f[5].params.length:-1,Ee=b?6:0,De=f.length,Oe=f.map(e=>e.test),ke=f.map(e=>e.implementation),Ae=function(){for(let e=Ee;e<De;e++)if(Oe[e](arguments))return ke[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function je(e,t){return arguments.length===be&&S(e)&&ie(t)?me.apply(this,arguments):arguments.length===xe&&ee(e)&&ae(t)?he.apply(this,arguments):arguments.length===Se&&E(e)&&oe(t)?ve.apply(this,arguments):arguments.length===Ce&&re(e)&&se(t)?ye.apply(this,arguments):arguments.length===we&&D(e)&&le(t)?k.apply(this,arguments):arguments.length===Te&&O(e)&&de(t)?A.apply(this,arguments):Ae.apply(this,arguments)}try{Object.defineProperty(je,`name`,{value:e})}catch{}return je.signatures=o,je._typedFunctionData={signatures:f,signatureMap:p},je}function ye(e,t,n){throw ie(e,t,n)}function k(e){return be(e,0,e.length-1)}function A(e){return e[e.length-1]}function be(e,t,n){return Array.prototype.slice.call(e,t,n)}function xe(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function Se(e,t){return Array.prototype.concat.apply([],e.map(t))}function Ce(){let e=k(arguments).map(e=>x(te(e))),t=A(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return we(e,t)}function we(e,t){return{referTo:{references:e,callback:t}}}function Te(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function Ee(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function De(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function Oe(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 ke(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=Oe(t,e[n].name));return t}function Ae(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 je=d;d=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],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=ke(n))),Object.keys(o).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=Oe(r,s)),Ae(i,o)}return ve(r||``,i)},d.create=i,d.createCount=je.createCount,d.onMismatch=ye,d.throwMismatchError=ye,d.createError=ie,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=Ce,d.referToSelf=Te,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function Me(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 d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};Me(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.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,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){Me(e);let t=f(e.to),n=xe(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)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}var a=i();return a})});function Zs(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function Qs(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`},i=r[t],a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!Zs(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(!Zs(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),a=`i${n}`}var o=``;return e<0&&(e=-e,o=`-`),`${o}${i}${e.toString(t)}${a}`}function $s(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),z(t)?r=t:z(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 nc(e,r);case`exponential`:return rc(e,r);case`engineering`:return tc(e,r);case`bin`:return Qs(e,2,i);case`oct`:return Qs(e,8,i);case`hex`:return Qs(e,16,i);case`auto`:return ic(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.`)}}function ec(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 tc(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=ec(e),r=ac(n,t),i=r.exponent,a=r.coefficients,o=i%3==0?i:i<0?i-3-i%3:i-i%3;if(z(t))for(;t>a.length||i-o+1>a.length;)a.push(0);else for(var s=Math.abs(i-o)-(a.length-1),c=0;c<s;c++)a.push(0);for(var l=Math.abs(i-o),u=1;l>0;)u++,l--;var d=a.slice(u).join(``),f=z(t)&&d.length||d.match(/[1-9]/)?`.`+d:``,p=a.slice(0,u).join(``)+f+`e`+(i>=0?`+`:``)+o.toString();return r.sign+p}function nc(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=ec(e),r=typeof t==`number`?ac(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat(oc(o-i.length))),a<0&&(i=oc(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function rc(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=ec(e),r=t?ac(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat(oc(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function ic(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=ec(e),o=t?ac(a,t):a;if(o.exponent<r||o.exponent>=i)return rc(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat(oc(t-s.length))),s=s.concat(oc(c-s.length+1+(s.length<t?t-s.length:0))),s=oc(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function ac(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){var i=r.splice(t,r.length-t);if(i[0]>=5){var a=t-1;for(r[a]++;r[a]===10;)r.pop(),a===0&&(r.unshift(0),n.exponent++,a++),a--,r[a]++}}return n}function oc(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function sc(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}var cc=2**-52||2220446049250313e-31;function lc(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(!Zs(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 uc(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 pc(e,r);case`exponential`:return fc(e,r);case`engineering`:return dc(e,r);case`bin`:return lc(e,2,i);case`oct`:return lc(e,8,i);case`hex`:return lc(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():fc(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.`)}}function dc(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),a=i.toPrecision(t);if(a.indexOf(`e`)!==-1){var o=e.constructor;a=new o(a).toFixed()}return a+`e`+(n>=0?`+`:``)+r.toString()}function fc(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function pc(e,t){return e.toFixed(t)}function mc(e,t){var n=hc(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function hc(e,t){if(typeof e==`number`)return $s(e,t);if(ts(e))return uc(e,t);if(yc(e))return!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString();if(Array.isArray(e))return vc(e,t);if(ss(e))return gc(e);if(typeof e==`function`)return e.syntax?String(e.syntax):`function`;if(e&&typeof e==`object`){if(typeof e.format==`function`)return e.format(t);if(e&&e.toString(t)!=={}.toString())return e.toString(t);var n=Object.keys(e).map(n=>gc(n)+`: `+mc(e[n],t));return`{`+n.join(`, `)+`}`}return String(e)}function gc(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in _c?_c[i]:i,r++}return`"`+n+`"`}var _c={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function vc(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=vc(e[i],t);return n+=`]`,n}else return mc(e,t)}function yc(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function V(e,t,n){if(!(this instanceof V))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}V.prototype=RangeError(),V.prototype.constructor=RangeError,V.prototype.name=`DimensionError`,V.prototype.isDimensionError=!0;function bc(e,t,n){if(!(this instanceof bc))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}bc.prototype=RangeError(),bc.prototype.constructor=RangeError,bc.prototype.name=`IndexError`,bc.prototype.isIndexError=!0;var xc=E($o(),1);function Sc(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function Cc(e,t,n){var r,i=e.length;if(i!==t[n])throw new V(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 V(t.length-1,t.length,`<`);Cc(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new V(t.length+1,t.length,`>`)}function wc(e,t){var n=t.length===0;if(n){if(Array.isArray(e))throw new V(e.length,0)}else Cc(e,t,0)}function H(e,t){if(e!==void 0){if(!z(e)||!Zs(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new bc(e,t)}}function Tc(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);t.forEach(function(e){if(!z(e)||!Zs(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+mc(t)+`)`)}),(z(e)||ts(e))&&(e=[e]);var r=n===void 0?0:n;return Ec(e,t,0,r),e}function Ec(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),Ec(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,Ec(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 Dc(e,t){var n=Nc(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new V(0,r,`!=`);t=Oc(t,r);var i=kc(t);if(r!==i)throw new V(i,r,`!=`);try{return Ac(n,t)}catch(e){throw e instanceof V?new V(i,r,`!=`):e}}function Oc(e,t){var n=kc(e),r=e.slice(),i=-1,a=e.indexOf(i),o=e.indexOf(i,a+1)>=0;if(o)throw Error(`More than one wildcard in sizes`);var s=a>=0,c=t%n===0;if(s)if(c)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function kc(e){return e.reduce((e,t)=>e*t,1)}function Ac(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 jc(e,t,n,r){var i=r||Sc(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=Mc(e,t,0);i.length<t;)i.push(1);return e}function Mc(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]=Mc(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function Nc(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function e(n){Array.isArray(n)?n.forEach(e):t.push(n)}),t}function Pc(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?Pc(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function Fc(e,t,n,r){if(r<n){if(e.length!==t.length)throw new V(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=Fc(e[a],t[a],n,r+1);return i}else return e.concat(t)}function Ic(){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 Fc(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function Lc(){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++)Rc(t[d],a);return a}function Rc(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 zc(e,t){var n=Sc(e);if(Us(n,t))return e;Rc(n,t);var r=Lc(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=Vc(e);n.length<i&&(o=Dc(o,a),n=Sc(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=Bc(o,r[s],s),n=Sc(o));return o}function Bc(e,t,n){return Ic(...Array(t).fill(e),n)}function Vc(e){return(0,xc.default)([],e)}function Hc(e,t,n,r){function i(r){var i=Gs(r,t.map(Gc));return Uc(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Uc(e,t,n){var r=t.filter(e=>!Wc(e)).every(e=>n[e]!==void 0);if(!r){var i=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${i.map(e=>`"${e}"`).join(`, `)}.`)}}function Wc(e){return e&&e[0]===`?`}function Gc(e){return e&&e[0]===`?`?e.slice(1):e}function Kc(e,t){if(Zc(e)&&Yc(e,t))return e[t];throw typeof e[t]==`function`&&Xc(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function qc(e,t,n){if(Zc(e)&&Yc(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function Jc(e,t){return t in e}function Yc(e,t){return!e||typeof e!=`object`?!1:Ws(Qc,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Xc(e,t){return e==null||typeof e[t]!=`function`||Ws(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:Ws($c,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Zc(e){return typeof e==`object`&&e&&e.constructor===Object}var Qc={length:!0,name:!0},$c={toString:!0,valueOf:!0,toLocaleString:!0},el=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return Kc(this.wrappedObject,e)}set(e,t){return qc(this.wrappedObject,e,t),this}has(e){return Jc(this.wrappedObject,e)}};function tl(e){return e?e instanceof Map||e instanceof el||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var nl=E(Xs(),1),rl=function(){return rl=nl.default.create,nl.default},il=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],al=Hc(`typed`,il,function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=rl();return a.clear(),a.addTypes([{name:`number`,test:z},{name:`Complex`,test:ns},{name:`BigNumber`,test:ts},{name:`Fraction`,test:rs},{name:`Unit`,test:os},{name:`identifier`,test:e=>ss&&/^(?:[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:ss},{name:`Chain`,test:zs},{name:`Array`,test:B},{name:`Matrix`,test:cs},{name:`DenseMatrix`,test:us},{name:`SparseMatrix`,test:ds},{name:`Range`,test:fs},{name:`Index`,test:ps},{name:`boolean`,test:ms},{name:`ResultSet`,test:hs},{name:`Help`,test:gs},{name:`function`,test:_s},{name:`Date`,test:vs},{name:`RegExp`,test:ys},{name:`null`,test:xs},{name:`undefined`,test:Ss},{name:`AccessorNode`,test:Cs},{name:`ArrayNode`,test:ws},{name:`AssignmentNode`,test:Ts},{name:`BlockNode`,test:Es},{name:`ConditionalNode`,test:Ds},{name:`ConstantNode`,test:Os},{name:`FunctionNode`,test:As},{name:`FunctionAssignmentNode`,test:ks},{name:`IndexNode`,test:js},{name:`Node`,test:Ms},{name:`ObjectNode`,test:Ns},{name:`OperatorNode`,test:Ps},{name:`ParenthesisNode`,test:Fs},{name:`RangeNode`,test:Is},{name:`RelationalNode`,test:Ls},{name:`SymbolNode`,test:Rs},{name:`Map`,test:tl},{name:`Object`,test:bs}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||ol(e),sc(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(e){return n||sl(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||sl(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function(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(e){return n||sl(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||ll(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(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function(e){t||ol(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function(e){i||ll(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||sl(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function(e){return t||ol(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||ll(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||cl(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function(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&&ls(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&&ls(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 ol(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function sl(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function cl(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function ll(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}
|
|
191
|
+
`);return Object.freeze(qo)};(0,Vs.default)(Hs,qo,{MATRIX_OPTIONS:zs,NUMBER_OPTIONS:Bs});var Us=w(((exports,t)=>{(function(n,r){typeof exports==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n[`'typed'`]=r())})(exports,(function(){"use strict";function e(){return!0}function t(){return!1}function n(){}let r=`Argument is not a typed-function.`;function i(){function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}let o=[{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:a},{name:`null`,test:function(e){return e===null}},{name:`undefined`,test:function(e){return e===void 0}}],s={name:`any`,test:e,isAny:!0},c,l,u=0,d={createCount:0};function f(e){let t=c.get(e);if(t)return t;let n=`Unknown type "`+e+`"`,r=e.toLowerCase(),i;for(i of l)if(i.toLowerCase()===r){n+=`. Did you mean "`+i+`" ?`;break}throw TypeError(n)}function p(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`any`,n=t?f(t).index:l.length,r=[];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(c.has(i))throw TypeError(`Duplicate type name "`+i+`"`);r.push(i),c.set(i,{name:i,test:e[t].test,isAny:e[t].isAny,index:n+t,conversionsTo:[]})}let i=l.slice(n);l=l.slice(0,n).concat(r).concat(i);for(let e=n+r.length;e<l.length;++e)c.get(l[e]).index=e}function m(){c=new Map,l=[],u=0,p([s],!1)}m(),p(o);function h(){let e;for(e of l)c.get(e).conversionsTo=[];u=0}function g(e){let t=l.filter(t=>{let n=c.get(t);return!n.isAny&&n.test(e)});return t.length?t:[`any`]}function _(e){return e&&typeof e==`function`&&`_typedFunctionData`in e}function v(e,t,n){if(!_(e))throw TypeError(r);let i=n&&n.exact,a=Array.isArray(t)?t.join(`,`):t,o=te(a),s=x(o);if(!i||s in e.signatures){let t=e._typedFunctionData.signatureMap.get(s);if(t)return t}let c=o.length,l;if(i){l=[];let t;for(t in e.signatures)l.push(e._typedFunctionData.signatureMap.get(t))}else l=e._typedFunctionData.signatures;for(let e=0;e<c;++e){let t=o[e],n=[],r;for(r of l){let i=ne(r.params,e);if(!i||t.restParam&&!i.restParam)continue;if(!i.hasAny){let e=ee(i);if(t.types.some(t=>!e.has(t.name)))continue}n.push(r)}if(l=n,l.length===0)break}let u;for(u of l)if(u.params.length<=c)return u;throw TypeError(`Signature not found (signature: `+(e.name||`unnamed`)+`(`+x(o,`, `)+`))`)}function y(e,t,n){return v(e,t,n).implementation}function b(e,t){let n=f(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++){let n=f(r[t].from);if(n.test(e))return r[t].convert(e)}throw Error(`Cannot convert `+e+` to `+t)}function x(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`,`;return e.map(e=>e.name).join(t)}function S(e){let t=e.indexOf(`...`)===0,n=t?e.length>3?e.slice(3):`any`:e,r=n.split(`|`).map(e=>f(e.trim())),i=!1,a=t?`...`:``,o=r.map(function(e){return i=e.isAny||i,a+=e.name+`|`,{name:e.name,typeIndex:e.index,test:e.test,isAny:e.isAny,conversion:null,conversionIndex:-1}});return{types:o,name:a.slice(0,-1),hasAny:i,hasConversion:!1,restParam:t}}function C(e){let t=e.types.map(e=>e.name),n=le(t),r=e.hasAny,i=e.name,a=n.map(function(e){let t=f(e.from);return r=t.isAny||r,i+=`|`+e.from,{name:e.from,typeIndex:t.index,test:t.test,isAny:t.isAny,conversion:e,conversionIndex:e.index}});return{types:e.types.concat(a),name:i,hasAny:r,hasConversion:a.length>0,restParam:e.restParam}}function ee(e){return e.typeSet||(e.typeSet=new Set,e.types.forEach(t=>e.typeSet.add(t.name))),e.typeSet}function te(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=S(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 w(e){let t=be(e);return t?t.restParam:!1}function T(t){if(!t||t.types.length===0)return e;if(t.types.length===1)return f(t.types[0].name).test;if(t.types.length===2){let e=f(t.types[0].name).test,n=f(t.types[1].name).test;return function(t){return e(t)||n(t)}}else{let e=t.types.map(function(e){return f(e.name).test});return function(t){for(let n=0;n<e.length;n++)if(e[n](t))return!0;return!1}}}function E(e){let t,n,r;if(w(e)){t=ye(e).map(T);let n=t.length,r=T(be(e)),i=function(e){for(let t=n;t<e.length;t++)if(!r(e[t]))return!1;return!0};return function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return i(e)&&e.length>=n+1}}else if(e.length===0)return function(e){return e.length===0};else if(e.length===1)return n=T(e[0]),function(e){return n(e[0])&&e.length===1};else if(e.length===2)return n=T(e[0]),r=T(e[1]),function(e){return n(e[0])&&r(e[1])&&e.length===2};else return t=e.map(T),function(e){for(let n=0;n<t.length;n++)if(!t[n](e[n]))return!1;return e.length===t.length}}function ne(e,t){return t<e.length?e[t]:w(e)?be(e):null}function re(e,t){let n=ne(e,t);return n?ee(n):new Set}function D(e){return e.conversion===null||e.conversion===void 0}function O(e,t){let n=new Set;return e.forEach(e=>{let r=re(e.params,t),i;for(i of r)n.add(i)}),n.has(`any`)?[`any`]:Array.from(n)}function ie(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=ne(n.params,s),i=T(r);(s<n.params.length||w(n.params))&&i(t[s])&&e.push(n)}),e.length===0){if(i=O(o,s),i.length>0){let e=g(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 w(e.params)?1/0:e.params.length});if(t.length<Math.min.apply(null,c))return i=O(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(g(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 ae(e){let t=l.length+1;for(let n=0;n<e.types.length;n++)D(e.types[n])&&(t=Math.min(t,e.types[n].typeIndex));return t}function oe(e){let t=u+1;for(let n=0;n<e.types.length;n++)D(e.types[n])||(t=Math.min(t,e.types[n].conversionIndex));return t}function se(e,t){if(e.hasAny){if(!t.hasAny)return 1}else if(t.hasAny)return-1;if(e.restParam){if(!t.restParam)return 1}else if(t.restParam)return-1;if(e.hasConversion){if(!t.hasConversion)return 1}else if(t.hasConversion)return-1;let n=ae(e)-ae(t);if(n<0)return-1;if(n>0)return 1;let r=oe(e)-oe(t);return r<0?-1:r>0?1:0}function ce(e,t){let n=e.params,r=t.params,i=be(n),a=be(r),o=w(n),s=w(r);if(o&&i.hasAny){if(!s||!a.hasAny)return 1}else if(s&&a.hasAny)return-1;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;if(o&&i.hasConversion){if(!s||!a.hasConversion)return 1}else if(s&&a.hasConversion)return-1;if(l!==f)return l-f;if(o){if(!s)return 1}else if(s)return-1;let p=(n.length-r.length)*(o?-1:1);if(p!==0)return p;let m=[],h=0;for(let e=0;e<n.length;++e){let t=se(n[e],r[e]);m.push(t),h+=t}if(h!==0)return h;let g;for(g of m)if(g!==0)return g;return 0}function le(e){if(e.length===0)return[];let t=e.map(f);e.length>1&&t.sort((e,t)=>e.index-t.index);let n=t[0].conversionsTo;if(e.length===1)return n;n=n.concat([]);let r=new Set(e);for(let e=1;e<t.length;++e){let i;for(i of t[e].conversionsTo)r.has(i.from)||(n.push(i),r.add(i.from))}return n}function ue(e,t){let n=t;if(e.some(e=>e.hasConversion)){let r=w(e),i=e.map(de);n=function(){let e=[],n=r?arguments.length-1:arguments.length;for(let t=0;t<n;t++)e[t]=i[t](arguments[t]);return r&&(e[n]=arguments[n].map(i[n])),t.apply(this,e)}}let r=n;if(w(e)){let t=e.length-1;r=function(){return n.apply(this,xe(arguments,0,t).concat([xe(arguments,t)]))}}return r}function de(e){let t,n,r,i,a=[],o=[];switch(e.types.forEach(function(e){e.conversion&&(a.push(f(e.conversion.from).test),o.push(e.conversion.convert))}),o.length){case 0:return function(e){return e};case 1:return t=a[0],r=o[0],function(e){return t(e)?r(e):e};case 2:return t=a[0],n=a[1],r=o[0],i=o[1],function(e){return t(e)?r(e):n(e)?i(e):e};default:return function(e){for(let t=0;t<o.length;t++)if(a[t](e))return o[t](e);return e}}}function fe(e){function t(e,n,r){if(n<e.length){let i=e[n],a=[];if(i.restParam){let e=i.types.filter(D);e.length<i.types.length&&a.push({types:e,name:`...`+e.map(e=>e.name).join(`|`),hasAny:e.some(e=>e.isAny),hasConversion:!1,restParam:!0}),a.push(i)}else a=i.types.map(function(e){return{types:[e],name:e.name,hasAny:e.isAny,hasConversion:e.conversion,restParam:!1}});return Ce(a,function(i){return t(e,n+1,r.concat([i]))})}else return[r]}return t(e,0,[])}function pe(e,t){let n=Math.max(e.length,t.length);for(let r=0;r<n;r++){let n=re(e,r),i=re(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=w(e),o=w(t);return a?o?r===i:i>=r:o?r>=i:r===i}function me(e){return e.map(e=>Oe(e)?Ee(e.referToSelf.callback):De(e)?Te(e.referTo.references,e.referTo.callback):e)}function he(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 ge(e,t,n){let r=me(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(Oe(s))r[o]=s.referToSelf.callback(n),r[o].referToSelf=s.referToSelf,i[o]=!0,e=!1;else if(De(s)){let n=he(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 _e(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 ve(e,r){if(d.createCount++,Object.keys(r).length===0)throw SyntaxError(`No signatures provided`);d.warnAgainstDeprecatedThis&&_e(r);let i=[],a=[],o={},s=[],c;for(c in r){if(!Object.prototype.hasOwnProperty.call(r,c))continue;let e=te(c);if(!e)continue;i.forEach(function(t){if(pe(t,e))throw TypeError(`Conflicting signatures "`+x(t)+`" and "`+x(e)+`".`)}),i.push(e);let t=a.length;a.push(r[c]);let n=e.map(C),l;for(l of fe(n)){let e=x(l);s.push({params:l,name:e,fn:t}),l.every(e=>!e.hasConversion)&&(o[e]=t)}}s.sort(ce);let l=ge(a,o,Me),u;for(u in o)Object.prototype.hasOwnProperty.call(o,u)&&(o[u]=l[o[u]]);let f=[],p=new Map;for(u of s)p.has(u.name)||(u.fn=l[u.fn],f.push(u),p.set(u.name,u));let m=f[0]&&f[0].params.length<=2&&!w(f[0].params),h=f[1]&&f[1].params.length<=2&&!w(f[1].params),g=f[2]&&f[2].params.length<=2&&!w(f[2].params),_=f[3]&&f[3].params.length<=2&&!w(f[3].params),v=f[4]&&f[4].params.length<=2&&!w(f[4].params),y=f[5]&&f[5].params.length<=2&&!w(f[5].params),b=m&&h&&g&&_&&v&&y;for(let e=0;e<f.length;++e)f[e].test=E(f[e].params);let S=m?T(f[0].params[0]):t,ee=h?T(f[1].params[0]):t,ne=g?T(f[2].params[0]):t,re=_?T(f[3].params[0]):t,D=v?T(f[4].params[0]):t,O=y?T(f[5].params[0]):t,ie=m?T(f[0].params[1]):t,ae=h?T(f[1].params[1]):t,oe=g?T(f[2].params[1]):t,se=_?T(f[3].params[1]):t,le=v?T(f[4].params[1]):t,de=y?T(f[5].params[1]):t;for(let e=0;e<f.length;++e)f[e].implementation=ue(f[e].params,f[e].fn);let me=m?f[0].implementation:n,he=h?f[1].implementation:n,ve=g?f[2].implementation:n,k=_?f[3].implementation:n,ye=v?f[4].implementation:n,be=y?f[5].implementation:n,xe=m?f[0].params.length:-1,Se=h?f[1].params.length:-1,Ce=g?f[2].params.length:-1,we=_?f[3].params.length:-1,Te=v?f[4].params.length:-1,Ee=y?f[5].params.length:-1,De=b?6:0,Oe=f.length,ke=f.map(e=>e.test),Ae=f.map(e=>e.implementation),je=function(){for(let e=De;e<Oe;e++)if(ke[e](arguments))return Ae[e].apply(this,arguments);return d.onMismatch(e,arguments,f)};function Me(e,t){return arguments.length===xe&&S(e)&&ie(t)?me.apply(this,arguments):arguments.length===Se&&ee(e)&&ae(t)?he.apply(this,arguments):arguments.length===Ce&&ne(e)&&oe(t)?ve.apply(this,arguments):arguments.length===we&&re(e)&&se(t)?k.apply(this,arguments):arguments.length===Te&&D(e)&&le(t)?ye.apply(this,arguments):arguments.length===Ee&&O(e)&&de(t)?be.apply(this,arguments):je.apply(this,arguments)}try{Object.defineProperty(Me,`name`,{value:e})}catch{}return Me.signatures=o,Me._typedFunctionData={signatures:f,signatureMap:p},Me}function k(e,t,n){throw ie(e,t,n)}function ye(e){return xe(e,0,e.length-1)}function be(e){return e[e.length-1]}function xe(e,t,n){return Array.prototype.slice.call(e,t,n)}function Se(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return e[n]}function Ce(e,t){return Array.prototype.concat.apply([],e.map(t))}function we(){let e=ye(arguments).map(e=>x(te(e))),t=be(arguments);if(typeof t!=`function`)throw TypeError(`Callback function expected as last argument`);return Te(e,t)}function Te(e,t){return{referTo:{references:e,callback:t}}}function Ee(e){if(typeof e!=`function`)throw TypeError(`Callback function expected as first argument`);return{referToSelf:{callback:e}}}function De(e){return e&&typeof e.referTo==`object`&&Array.isArray(e.referTo.references)&&typeof e.referTo.callback==`function`}function Oe(e){return e&&typeof e.referToSelf==`object`&&typeof e.referToSelf.callback==`function`}function ke(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 Ae(e){let t;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(_(e[n])||typeof e[n].signature==`string`)&&(t=ke(t,e[n].name));return t}function je(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 Me=d;d=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],o={},s;if(typeof n==`function`?(s=n.name,typeof n.signature==`string`?o[n.signature]=n:_(n)&&(o=n.signatures)):a(n)&&(o=n,t||(s=Ae(n))),Object.keys(o).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=ke(r,s)),je(i,o)}return ve(r||``,i)},d.create=i,d.createCount=Me.createCount,d.onMismatch=k,d.throwMismatchError=k,d.createError=ie,d.clear=m,d.clearConversions=h,d.addTypes=p,d._findType=f,d.referTo=we,d.referToSelf=Ee,d.convert=b,d.findSignature=v,d.find=y,d.isTypedFunction=_,d.warnAgainstDeprecatedThis=!0,d.addType=function(e,t){let n=`any`;t!==!1&&c.has(`Object`)&&(n=`Object`),d.addTypes([e],n)};function Ne(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 d.addConversion=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{override:!1};Ne(e);let n=f(e.to),r=n.conversionsTo.find(t=>t.from===e.from);if(r)if(t&&t.override)d.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,convert:e.convert,index:u++})},d.addConversions=function(e,t){e.forEach(e=>d.addConversion(e,t))},d.removeConversion=function(e){Ne(e);let t=f(e.to),n=Se(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)},d.resolve=function(e,t){if(!_(e))throw TypeError(r);let n=e._typedFunctionData.signatures;for(let e=0;e<n.length;++e)if(n[e].test(t))return n[e];return null},d}var a=i();return a}))}));function Ws(e){return typeof e==`boolean`?!0:isFinite(e)?e===Math.round(e):!1}function Gs(e,t,n){var r={2:`0b`,8:`0o`,16:`0x`},i=r[t],a=``;if(n){if(n<1)throw Error(`size must be in greater than 0`);if(!Ws(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(!Ws(e))throw Error(`Value must be an integer`);e<0&&(e+=2**n),a=`i${n}`}var o=``;return e<0&&(e=-e,o=`-`),`${o}${i}${e.toString(t)}${a}`}function Ks(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),R(t)?r=t:R(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 Ys(e,r);case`exponential`:return Xs(e,r);case`engineering`:return Js(e,r);case`bin`:return Gs(e,2,i);case`oct`:return Gs(e,8,i);case`hex`:return Gs(e,16,i);case`auto`:return Zs(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.`)}}function qs(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 Js(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=qs(e),r=Qs(n,t),i=r.exponent,a=r.coefficients,o=i%3==0?i:i<0?i-3-i%3:i-i%3;if(R(t))for(;t>a.length||i-o+1>a.length;)a.push(0);else for(var s=Math.abs(i-o)-(a.length-1),c=0;c<s;c++)a.push(0);for(var l=Math.abs(i-o),u=1;l>0;)u++,l--;var d=a.slice(u).join(``),f=R(t)&&d.length||d.match(/[1-9]/)?`.`+d:``,p=a.slice(0,u).join(``)+f+`e`+(i>=0?`+`:``)+o.toString();return r.sign+p}function Ys(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=qs(e),r=typeof t==`number`?Qs(n,n.exponent+1+t):n,i=r.coefficients,a=r.exponent+1,o=a+(t||0);return i.length<o&&(i=i.concat($s(o-i.length))),a<0&&(i=$s(-a+1).concat(i),a=1),a<i.length&&i.splice(a,0,a===0?`0.`:`.`),r.sign+i.join(``)}function Xs(e,t){if(isNaN(e)||!isFinite(e))return String(e);var n=qs(e),r=t?Qs(n,t):n,i=r.coefficients,a=r.exponent;i.length<t&&(i=i.concat($s(t-i.length)));var o=i.shift();return r.sign+o+(i.length>0?`.`+i.join(``):``)+`e`+(a>=0?`+`:``)+a}function Zs(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=qs(e),o=t?Qs(a,t):a;if(o.exponent<r||o.exponent>=i)return Xs(e,t);var s=o.coefficients,c=o.exponent;s.length<t&&(s=s.concat($s(t-s.length))),s=s.concat($s(c-s.length+1+(s.length<t?t-s.length:0))),s=$s(-c).concat(s);var l=c>0?c:0;return l<s.length-1&&s.splice(l+1,0,`.`),o.sign+s.join(``)}function Qs(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){var i=r.splice(t,r.length-t);if(i[0]>=5){var a=t-1;for(r[a]++;r[a]===10;)r.pop(),a===0&&(r.unshift(0),n.exponent++,a++),a--,r[a]++}}return n}function $s(e){for(var t=[],n=0;n<e;n++)t.push(0);return t}function ec(e){return e.toExponential().replace(/e.*$/,``).replace(/^0\.?0*|\./,``).length}function tc(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(!Ws(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 nc(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 ac(e,r);case`exponential`:return ic(e,r);case`engineering`:return rc(e,r);case`bin`:return tc(e,2,i);case`oct`:return tc(e,8,i);case`hex`:return tc(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():ic(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.`)}}function rc(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),a=i.toPrecision(t);if(a.indexOf(`e`)!==-1){var o=e.constructor;a=new o(a).toFixed()}return a+`e`+(n>=0?`+`:``)+r.toString()}function ic(e,t){return t===void 0?e.toExponential():e.toExponential(t-1)}function ac(e,t){return e.toFixed(t)}function oc(e,t){var n=sc(e,t);return t&&typeof t==`object`&&`truncate`in t&&n.length>t.truncate?n.substring(0,t.truncate-3)+`...`:n}function sc(e,t){if(typeof e==`number`)return Ks(e,t);if(Jo(e))return nc(e,t);if(dc(e))return!t||t.fraction!==`decimal`?e.s*e.n+`/`+e.d:e.toString();if(Array.isArray(e))return uc(e,t);if(Qo(e))return cc(e);if(typeof e==`function`)return e.syntax?String(e.syntax):`function`;if(e&&typeof e==`object`){if(typeof e.format==`function`)return e.format(t);if(e&&e.toString(t)!=={}.toString())return e.toString(t);var n=Object.keys(e).map(n=>cc(n)+`: `+oc(e[n],t));return`{`+n.join(`, `)+`}`}return String(e)}function cc(e){for(var t=String(e),n=``,r=0;r<t.length;){var i=t.charAt(r);n+=i in lc?lc[i]:i,r++}return`"`+n+`"`}var lc={'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`};function uc(e,t){if(Array.isArray(e)){for(var n=`[`,r=e.length,i=0;i<r;i++)i!==0&&(n+=`, `),n+=uc(e[i],t);return n+=`]`,n}else return oc(e,t)}function dc(e){return e&&typeof e==`object`&&typeof e.s==`number`&&typeof e.n==`number`&&typeof e.d==`number`||!1}function B(e,t,n){if(!(this instanceof B))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}B.prototype=RangeError(),B.prototype.constructor=RangeError,B.prototype.name=`DimensionError`,B.prototype.isDimensionError=!0;function fc(e,t,n){if(!(this instanceof fc))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}fc.prototype=RangeError(),fc.prototype.constructor=RangeError,fc.prototype.name=`IndexError`,fc.prototype.isIndexError=!0;var pc=E(Ko(),1);function mc(e){for(var t=[];Array.isArray(e);)t.push(e.length),e=e[0];return t}function hc(e,t,n){var r,i=e.length;if(i!==t[n])throw new B(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 B(t.length-1,t.length,`<`);hc(e[r],t,a)}}else for(r=0;r<i;r++)if(Array.isArray(e[r]))throw new B(t.length+1,t.length,`>`)}function gc(e,t){var n=t.length===0;if(n){if(Array.isArray(e))throw new B(e.length,0)}else hc(e,t,0)}function V(e,t){if(e!==void 0){if(!R(e)||!Ws(e))throw TypeError(`Index must be an integer (value: `+e+`)`);if(e<0||typeof t==`number`&&e>=t)throw new fc(e,t)}}function _c(e,t,n){if(!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw Error(`Resizing to scalar is not supported`);t.forEach(function(e){if(!R(e)||!Ws(e)||e<0)throw TypeError(`Invalid size, must contain positive integers (size: `+oc(t)+`)`)}),(R(e)||Jo(e))&&(e=[e]);var r=n===void 0?0:n;return vc(e,t,0,r),e}function vc(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),vc(a,t,l,r);for(i=c;i<s;i++)a=[],e[i]=a,vc(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 yc(e,t){var n=Tc(e),r=n.length;if(!Array.isArray(e)||!Array.isArray(t))throw TypeError(`Array expected`);if(t.length===0)throw new B(0,r,`!=`);t=bc(t,r);var i=xc(t);if(r!==i)throw new B(i,r,`!=`);try{return Sc(n,t)}catch(e){throw e instanceof B?new B(i,r,`!=`):e}}function bc(e,t){var n=xc(e),r=e.slice(),i=-1,a=e.indexOf(i),o=e.indexOf(i,a+1)>=0;if(o)throw Error(`More than one wildcard in sizes`);var s=a>=0,c=t%n===0;if(s)if(c)r[a]=-t/n;else throw Error(`Could not replace wildcard, since `+t+` is no multiple of `+-n);return r}function xc(e){return e.reduce((e,t)=>e*t,1)}function Sc(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 Cc(e,t,n,r){var i=r||mc(e);if(n)for(var a=0;a<n;a++)e=[e],i.unshift(1);for(e=wc(e,t,0);i.length<t;)i.push(1);return e}function wc(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]=wc(e[r],t,a)}else for(var o=n;o<t;o++)e=[e];return e}function Tc(e){if(!Array.isArray(e))return e;var t=[];return e.forEach(function e(n){Array.isArray(n)?n.forEach(e):t.push(n)}),t}function Ec(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?Ec(a,t):t(a);if(n===void 0)n=s;else if(n!==s)return`mixed`}return n}function Dc(e,t,n,r){if(r<n){if(e.length!==t.length)throw new B(e.length,t.length);for(var i=[],a=0;a<e.length;a++)i[a]=Dc(e[a],t[a],n,r+1);return i}else return e.concat(t)}function Oc(){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 Dc(e,n,t,0)},e[0]);throw Error(`Wrong number of arguments in function concat`)}function kc(){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++)Ac(t[d],a);return a}function Ac(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 jc(e,t){var n=mc(e);if(Is(n,t))return e;Ac(n,t);var r=kc(n,t),i=r.length,a=[...Array(i-n.length).fill(1),...n],o=Nc(e);n.length<i&&(o=yc(o,a),n=mc(o));for(var s=0;s<i;s++)n[s]<r[s]&&(o=Mc(o,r[s],s),n=mc(o));return o}function Mc(e,t,n){return Oc(...Array(t).fill(e),n)}function Nc(e){return(0,pc.default)([],e)}function Pc(e,t,n,r){function i(r){var i=Rs(r,t.map(Lc));return Fc(e,t,r),n(i)}return i.isFactory=!0,i.fn=e,i.dependencies=t.slice().sort(),r&&(i.meta=r),i}function Fc(e,t,n){var r=t.filter(e=>!Ic(e)).every(e=>n[e]!==void 0);if(!r){var i=t.filter(e=>n[e]===void 0);throw Error(`Cannot create function "${e}", some dependencies are missing: ${i.map(e=>`"${e}"`).join(`, `)}.`)}}function Ic(e){return e&&e[0]===`?`}function Lc(e){return e&&e[0]===`?`?e.slice(1):e}function Rc(e,t){if(Uc(e)&&Vc(e,t))return e[t];throw typeof e[t]==`function`&&Hc(e,t)?Error(`Cannot access method "`+t+`" as a property`):Error(`No access to property "`+t+`"`)}function zc(e,t,n){if(Uc(e)&&Vc(e,t))return e[t]=n,n;throw Error(`No access to property "`+t+`"`)}function Bc(e,t){return t in e}function Vc(e,t){return!e||typeof e!=`object`?!1:Ls(Wc,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Hc(e,t){return e==null||typeof e[t]!=`function`||Ls(e,t)&&Object.getPrototypeOf&&t in Object.getPrototypeOf(e)?!1:Ls(Gc,t)?!0:!(t in Object.prototype||t in Function.prototype)}function Uc(e){return typeof e==`object`&&e&&e.constructor===Object}var Wc={length:!0,name:!0},Gc={toString:!0,valueOf:!0,toLocaleString:!0},Kc=class{constructor(e){this.wrappedObject=e}keys(){return Object.keys(this.wrappedObject)}get(e){return Rc(this.wrappedObject,e)}set(e,t){return zc(this.wrappedObject,e,t),this}has(e){return Bc(this.wrappedObject,e)}};function qc(e){return e?e instanceof Map||e instanceof Kc||typeof e.set==`function`&&typeof e.get==`function`&&typeof e.keys==`function`&&typeof e.has==`function`:!1}var Jc=E(Us(),1),Yc=function(){return Yc=Jc.default.create,Jc.default},Xc=[`?BigNumber`,`?Complex`,`?DenseMatrix`,`?Fraction`],Zc=Pc(`typed`,Xc,function(e){var{BigNumber:t,Complex:n,DenseMatrix:r,Fraction:i}=e,a=Yc();return a.clear(),a.addTypes([{name:`number`,test:R},{name:`Complex`,test:Yo},{name:`BigNumber`,test:Jo},{name:`Fraction`,test:Xo},{name:`Unit`,test:Zo},{name:`identifier`,test:e=>Qo&&/^(?:[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:Qo},{name:`Chain`,test:Ms},{name:`Array`,test:z},{name:`Matrix`,test:$o},{name:`DenseMatrix`,test:ts},{name:`SparseMatrix`,test:ns},{name:`Range`,test:rs},{name:`Index`,test:os},{name:`boolean`,test:ss},{name:`ResultSet`,test:cs},{name:`Help`,test:ls},{name:`function`,test:us},{name:`Date`,test:ds},{name:`RegExp`,test:fs},{name:`null`,test:ms},{name:`undefined`,test:hs},{name:`AccessorNode`,test:gs},{name:`ArrayNode`,test:_s},{name:`AssignmentNode`,test:vs},{name:`BlockNode`,test:ys},{name:`ConditionalNode`,test:bs},{name:`ConstantNode`,test:xs},{name:`FunctionNode`,test:Cs},{name:`FunctionAssignmentNode`,test:Ss},{name:`IndexNode`,test:ws},{name:`Node`,test:Ts},{name:`ObjectNode`,test:Es},{name:`OperatorNode`,test:Ds},{name:`ParenthesisNode`,test:Os},{name:`RangeNode`,test:ks},{name:`RelationalNode`,test:As},{name:`SymbolNode`,test:js},{name:`Map`,test:qc},{name:`Object`,test:ps}]),a.addConversions([{from:`number`,to:`BigNumber`,convert:function(e){if(t||Qc(e),ec(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(e){return n||$c(e),new n(e,0)}},{from:`BigNumber`,to:`Complex`,convert:function(e){return n||$c(e),new n(e.toNumber(),0)}},{from:`Fraction`,to:`BigNumber`,convert:function(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(e){return n||$c(e),new n(e.valueOf(),0)}},{from:`number`,to:`Fraction`,convert:function(e){i||tl(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(e){var t=Number(e);if(isNaN(t))throw Error(`Cannot convert "`+e+`" to a number`);return t}},{from:`string`,to:`BigNumber`,convert:function(e){t||Qc(e);try{return new t(e)}catch{throw Error(`Cannot convert "`+e+`" to BigNumber`)}}},{from:`string`,to:`Fraction`,convert:function(e){i||tl(e);try{return new i(e)}catch{throw Error(`Cannot convert "`+e+`" to Fraction`)}}},{from:`string`,to:`Complex`,convert:function(e){n||$c(e);try{return new n(e)}catch{throw Error(`Cannot convert "`+e+`" to Complex`)}}},{from:`boolean`,to:`number`,convert:function(e){return+e}},{from:`boolean`,to:`BigNumber`,convert:function(e){return t||Qc(e),new t(+e)}},{from:`boolean`,to:`Fraction`,convert:function(e){return i||tl(e),new i(+e)}},{from:`boolean`,to:`string`,convert:function(e){return String(e)}},{from:`Array`,to:`Matrix`,convert:function(e){return r||el(),new r(e)}},{from:`Matrix`,to:`Array`,convert:function(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&&es(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&&es(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 Qc(e){throw Error(`Cannot convert value ${e} into a BigNumber: no class 'BigNumber' provided`)}function $c(e){throw Error(`Cannot convert value ${e} into a Complex number: no class 'Complex' provided`)}function el(){throw Error(`Cannot convert array into a Matrix: no class 'DenseMatrix' provided`)}function tl(e){throw Error(`Cannot convert value ${e} into a Fraction, no class 'Fraction' provided.`)}
|
|
192
192
|
/*!
|
|
193
193
|
|
|
194
|
-
* decimal.js v10.
|
|
194
|
+
* decimal.js v10.6.0
|
|
195
195
|
|
|
196
196
|
* An arbitrary-precision Decimal type for JavaScript.
|
|
197
197
|
|
|
@@ -202,8 +202,8 @@ Example:
|
|
|
202
202
|
* MIT Licence
|
|
203
203
|
|
|
204
204
|
*/
|
|
205
|
-
var ul=9e15,dl=1e9,fl=`0123456789abcdef`,pl=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,ml=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,hl={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ul,maxE:ul,crypto:!1},gl,_l,U=!0,vl=`[DecimalError] `,yl=vl+`Invalid argument: `,bl=vl+`Precision limit exceeded`,xl=vl+`crypto unavailable`,Sl=`[object Decimal]`,W=Math.floor,G=Math.pow,Cl=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,wl=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Tl=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,El=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Dl=1e7,K=7,Ol=9007199254740991,kl=pl.length-1,Al=ml.length-1,q={toStringTag:Sl};q.absoluteValue=q.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Z(e)},q.ceil=function(){return Z(new this.constructor(this),this.e+1,2)},q.clampedTo=q.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(yl+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},q.comparedTo=q.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},q.cosine=q.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())+K,r.rounding=1,n=Nl(r,Zl(r,n)),r.precision=e,r.rounding=t,Z(_l==2||_l==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},q.cubeRoot=q.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(U=!1,a=u.s*G(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=J(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=X(l.plus(u).times(s),l.plus(c),o+2,1),J(s.d).slice(0,o)===(n=J(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(Z(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`)&&(Z(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return U=!0,Z(r,e,d.rounding,t)},q.decimalPlaces=q.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-W(this.e/K))*K,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},q.dividedBy=q.div=function(e){return X(this,new this.constructor(e))},q.dividedToIntegerBy=q.divToInt=function(e){var t=this,n=t.constructor;return Z(X(t,new n(e),0,1,1),n.precision,n.rounding)},q.equals=q.eq=function(e){return this.cmp(e)===0},q.floor=function(){return Z(new this.constructor(this),this.e+1,3)},q.greaterThan=q.gt=function(e){return this.cmp(e)>0},q.greaterThanOrEqualTo=q.gte=function(e){var t=this.cmp(e);return t==1||t===0},q.hyperbolicCosine=q.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/Xl(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=Yl(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 Z(a,o.precision=n,o.rounding=r,!0)},q.hyperbolicSine=q.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=Yl(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Xl(5,e)),i=Yl(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,Z(i,t,n,!0)},q.hyperbolicTangent=q.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,X(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)},q.inverseCosine=q.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?Ll(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()?Ll(t,r,i):new t(0):new t(NaN)},q.inverseHyperbolicCosine=q.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,U=!1,n=n.times(n).minus(1).sqrt().plus(n),U=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)},q.inverseHyperbolicSine=q.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,U=!1,n=n.times(n).plus(1).sqrt().plus(n),U=!0,r.precision=e,r.rounding=t,n.ln())},q.inverseHyperbolicTangent=q.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?Z(new a(i),e,t,!0):(a.precision=n=r-i.e,i=X(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)},q.inverseSine=q.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=Ll(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},q.inverseTangent=q.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<=Al)return o=Ll(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=Al)return o=Ll(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/K+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(U=!1,t=Math.ceil(s/K),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)),U=!0,Z(o,u.precision=d,u.rounding=f,!0)},q.isFinite=function(){return!!this.d},q.isInteger=q.isInt=function(){return!!this.d&&W(this.e/K)>this.d.length-2},q.isNaN=function(){return!this.s},q.isNegative=q.isNeg=function(){return this.s<0},q.isPositive=q.isPos=function(){return this.s>0},q.isZero=function(){return!!this.d&&this.d[0]===0},q.lessThan=q.lt=function(e){return this.cmp(e)<0},q.lessThanOrEqualTo=q.lte=function(e){return this.cmp(e)<1},q.logarithm=q.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(U=!1,s=d+p,o=Wl(l,s),r=t?Il(u,s+10):Wl(e,s),c=X(o,r,s,1),jl(c.d,i=d,f))do if(s+=10,o=Wl(l,s),r=t?Il(u,s+10):Wl(e,s),c=X(o,r,s,1),!a){+J(c.d).slice(i+1,i+15)+1==1e14&&(c=Z(c,d+1,0));break}while(jl(c.d,i+=10,f));return U=!0,Z(c,d,f)},q.minus=q.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 U?Z(e,s,c):e}if(n=W(e.e/K),u=W(p.e/K),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/K),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]=Dl-1;--l[i],l[r]+=Dl}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=Fl(l,n),U?Z(e,s,c):e):new m(c===3?-0:0)},q.modulo=q.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]?Z(new r(n),r.precision,r.rounding):(U=!1,r.modulo==9?(t=X(n,e.abs(),0,3,1),t.s*=e.s):t=X(n,e,0,r.modulo,1),t=t.times(e),U=!0,n.minus(t))},q.naturalExponential=q.exp=function(){return Ul(this)},q.naturalLogarithm=q.ln=function(){return Wl(this)},q.negated=q.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Z(e)},q.plus=q.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)),U?Z(e,s,c):e;if(a=W(d.e/K),r=W(e.e/K),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/K),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)/Dl|0,l[i]%=Dl;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=Fl(l,r),U?Z(e,s,c):e},q.precision=q.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(yl+e);return n.d?(t=Rl(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},q.round=function(){var e=this,t=e.constructor;return Z(new t(e),e.e+1,t.rounding)},q.sine=q.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())+K,r.rounding=1,n=Jl(r,Zl(r,n)),r.precision=e,r.rounding=t,Z(_l>2?n.neg():n,e,t,!0)):new r(NaN)},q.squareRoot=q.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(U=!1,l=Math.sqrt(+o),l==0||l==1/0?(t=J(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(X(o,a,n+2,1)).times(.5),J(a.d).slice(0,n)===(t=J(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(Z(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`)&&(Z(r,c+1,1),e=!r.times(r).eq(o));break}return U=!0,Z(r,c,u.rounding,e)},q.tangent=q.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=X(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Z(_l==2||_l==4?n.neg():n,e,t,!0)):new r(NaN)},q.times=q.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/K)+W(e.e/K),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%Dl|0,t=s/Dl|0;a[i]=(a[i]+t)%Dl|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=Fl(a,n),U?Z(e,d.precision,d.rounding):e},q.toBinary=function(e,t){return Ql(this,2,e,t)},q.toDecimalPlaces=q.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Y(e,0,dl),t===void 0?t=r.rounding:Y(t,0,8),Z(n,e+n.e+1,t))},q.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Pl(r,!0):(Y(e,0,dl),t===void 0?t=i.rounding:Y(t,0,8),r=Z(new i(r),e+1,t),n=Pl(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},q.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=Pl(i):(Y(e,0,dl),t===void 0?t=a.rounding:Y(t,0,8),r=Z(new a(i),e+i.e+1,t),n=Pl(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},q.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=Rl(m)-p.e-1,o=a%K,t.d[0]=G(10,o<0?K+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(yl+s);e=s.gt(t)?a>0?t:l:s}for(U=!1,s=new h(J(m)),u=h.precision,h.precision=a=m.length*K*2;d=X(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=X(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=X(l,r,a,1).minus(p).abs().cmp(X(c,n,a,1).minus(p).abs())<1?[l,r]:[c,n],h.precision=u,U=!0,f},q.toHexadecimal=q.toHex=function(e,t){return Ql(this,16,e,t)},q.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:Y(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&=n.s,e}return e.d[0]?(U=!1,n=X(n,e,0,t,1).times(e),U=!0,Z(n)):(e.s=n.s,n=e),n},q.toNumber=function(){return+this},q.toOctal=function(e,t){return Ql(this,8,e,t)},q.toPower=q.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 Z(s,r,a);if(t=W(e.e/K),t>=e.d.length-1&&(n=l<0?-l:l)<=Ol)return i=Bl(c,s,n,r),e.s<0?new c(1).div(i):Z(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.`+J(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):(U=!1,c.rounding=s.s=1,n=Math.min(12,(t+``).length),i=Ul(e.times(Wl(s,r+n)),r),i.d&&(i=Z(i,r+5,1),jl(i.d,r,a)&&(t=r+10,i=Z(Ul(e.times(Wl(s,t+n)),t),t+5,1),+J(i.d).slice(r+1,r+15)+1==1e14&&(i=Z(i,r+1,0)))),i.s=o,U=!0,c.rounding=a,Z(i,r,a))},q.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Pl(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Y(e,1,dl),t===void 0?t=i.rounding:Y(t,0,8),r=Z(new i(r),e,t),n=Pl(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},q.toSignificantDigits=q.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Y(e,1,dl),t===void 0?t=r.rounding:Y(t,0,8)),Z(new r(n),e,t)},q.toString=function(){var e=this,t=e.constructor,n=Pl(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},q.truncated=q.trunc=function(){return Z(new this.constructor(this),this.e+1,1)},q.valueOf=q.toJSON=function(){var e=this,t=e.constructor,n=Pl(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function J(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=K-r.length,n&&(a+=zl(n)),a+=r;o=e[t],r=o+``,n=K-r.length,n&&(a+=zl(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function Y(e,t,n){if(e!==~~e||e<t||e>n)throw Error(yl+e)}function jl(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=K,i=0):(i=Math.ceil((t+1)/K),t%=K),a=G(10,K-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 Ml(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]+=fl.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 Nl(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Xl(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=Yl(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 X=function(){function e(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 t(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 n(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(r,i,a,o,s,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,ee,te,w,T,ne,E=r.constructor,re=r.s==i.s?1:-1,D=r.d,O=i.d;if(!D||!D[0]||!O||!O[0])return new E(!r.s||!i.s||(D?O&&D[0]==O[0]:!O)?NaN:D&&D[0]==0||!O?re*0:re/0);for(c?(p=1,u=r.e-i.e):(c=Dl,p=K,u=W(r.e/p)-W(i.e/p)),T=O.length,te=D.length,_=new E(re),v=_.d=[],d=0;O[d]==(D[d]||0);d++);if(O[d]>(D[d]||0)&&u--,a==null?(S=a=E.precision,o=E.rounding):S=s?a+(r.e-i.e)+1:a,S<0)v.push(1),m=!0;else{if(S=S/p+2|0,d=0,T==1){for(f=0,O=O[0],S++;(d<te||f)&&S--;d++)C=f*c+(D[d]||0),v[d]=C/O|0,f=C%O|0;m=f||d<te}else{for(f=c/(O[0]+1)|0,f>1&&(O=e(O,f,c),D=e(D,f,c),T=O.length,te=D.length),ee=T,y=D.slice(0,T),b=y.length;b<T;)y[b++]=0;ne=O.slice(),ne.unshift(0),w=O[0],O[1]>=c/2&&++w;do f=0,l=t(O,y,T,b),l<0?(x=y[0],T!=b&&(x=x*c+(y[1]||0)),f=x/w|0,f>1?(f>=c&&(f=c-1),h=e(O,f,c),g=h.length,b=y.length,l=t(h,y,g,b),l==1&&(f--,n(h,T<g?ne:O,g,c))):(f==0&&(l=f=1),h=O.slice()),g=h.length,g<b&&h.unshift(0),n(y,h,b,c),l==-1&&(b=y.length,l=t(O,y,T,b),l<1&&(f++,n(y,T<b?ne:O,b,c))),b=y.length):l===0&&(f++,y=[0]),v[d++]=f,l&&y[0]?y[b++]=D[ee]||0:(y=[D[ee]],b=1);while((ee++<te||y[0]!==void 0)&&S--);m=y[0]!==void 0}v[0]||v.shift()}if(p==1)_.e=u,gl=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,Z(_,s?a+_.e+1:a,o,m)}return _}}();function Z(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+=K,o=t,u=d[f=0],c=u/G(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/K),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=K,o=a-K+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=K,o=a-K+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,(K-t%K)%K),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,K-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]==Dl&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=Dl)break;d[f--]=0,s=1}for(a=d.length;d[--a]===0;)d.pop()}return U&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function Pl(e,t,n){if(!e.isFinite())return Gl(e);var r,i=e.e,a=J(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+zl(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+zl(-i-1)+a,n&&(r=n-o)>0&&(a+=zl(r))):i>=o?(a+=zl(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+zl(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=zl(r))),a}function Fl(e,t){var n=e[0];for(t*=K;n>=10;n/=10)t++;return t}function Il(e,t,n){if(t>kl)throw U=!0,n&&(e.precision=n),Error(bl);return Z(new e(pl),t,1,!0)}function Ll(e,t,n){if(t>Al)throw Error(bl);return Z(new e(ml),t,n,!0)}function Rl(e){var t=e.length-1,n=t*K+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 zl(e){for(var t=``;e--;)t+=`0`;return t}function Bl(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/K+4);for(U=!1;;){if(n%2&&(a=a.times(t),$l(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),$l(t.d,o)}return U=!0,a}function Vl(e){return e.d[e.d.length-1]&1}function Hl(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 Ul(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?(U=!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=Z(a.times(e),c,1),n=n.times(++u),s=o.plus(X(a,n,c,1)),J(s.d).slice(0,c)===J(o.d).slice(0,c)){for(i=d;i--;)o=Z(o.times(o),c,1);if(t==null)if(l<3&&jl(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return Z(o,f.precision=m,p,U=!0);else return f.precision=m,o}o=s}}function Wl(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?(U=!1,u=y):u=t,_.precision=u+=m,n=J(g),r=n.charAt(0),Math.abs(a=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=J(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=Il(_,u+2,y).times(a+``),h=Wl(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?Z(h,y,v,U=!0):h;for(d=h,c=o=h=X(h.minus(1),h.plus(1),u,1),f=Z(h.times(h),u,1),i=3;;){if(o=Z(o.times(f),u,1),l=c.plus(X(o,new _(i),u,1)),J(l.d).slice(0,u)===J(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(Il(_,u+2,y).times(a+``))),c=X(c,new _(p),u,1),t==null)if(jl(c.d,u-m,v,s))_.precision=u+=m,l=o=h=X(d.minus(1),d.plus(1),u,1),f=Z(h.times(h),u,1),i=s=1;else return Z(c,_.precision=y,v,U=!0);else return _.precision=y,c;c=l,i+=2}}function Gl(e){return String(e.s*e.s/0)}function Kl(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)%K,n<0&&(r+=K),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=K;r<i;)e.d.push(+t.slice(r,r+=K));t=t.slice(r),r=K-t.length}else r-=i;for(;r--;)t+=`0`;e.d.push(+t),U&&(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 ql(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),El.test(t))return Kl(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(wl.test(t))n=16,t=t.toLowerCase();else if(Cl.test(t))n=2;else if(Tl.test(t))n=8;else throw Error(yl+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=Bl(r,new r(n),a,a*2)),l=Ml(t,n,Dl),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=Fl(l,u),e.d=l,U=!1,o&&(e=X(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?G(2,c):Vu.pow(2,c))),U=!0,e)}function Jl(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Yl(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Xl(5,n)),t=Yl(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 Yl(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/K);for(U=!1,c=n.times(n),s=new e(r);;){if(o=X(s.times(c),new e(t++*t++),u,1),s=i?r.plus(o):r.minus(o),r=X(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 U=!0,o.d.length=d+1,o}function Xl(e,t){for(var n=e;--t;)n*=e;return n}function Zl(e,t){var n,r=t.s<0,i=Ll(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return _l=r?4:1,t;if(n=t.divToInt(i),n.isZero())_l=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return _l=Vl(n)?r?2:3:r?4:1,t;_l=Vl(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Ql(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(Y(n,1,dl),r===void 0?r=p.rounding:Y(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=Gl(e);else{for(u=Pl(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=Ml(Pl(f),10,i),f.e=f.d.length),d=Ml(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=X(e,f,n,r,0,i),d=e.d,a=e.e,l=gl),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+=fl.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=Ml(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=fl.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 $l(e,t){if(e.length>t)return e.length=t,!0}function eu(e){return new this(e).abs()}function tu(e){return new this(e).acos()}function nu(e){return new this(e).acosh()}function ru(e,t){return new this(e).plus(t)}function iu(e){return new this(e).asin()}function au(e){return new this(e).asinh()}function ou(e){return new this(e).atan()}function su(e){return new this(e).atanh()}function cu(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=Ll(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Ll(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Ll(this,a,1).times(.5),n.s=e.s):t.s<0?(this.precision=a,this.rounding=1,n=this.atan(X(e,t,a,1)),t=Ll(this,a,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(X(e,t,a,1)),n}function lu(e){return new this(e).cbrt()}function uu(e){return Z(e=new this(e),e.e+1,2)}function du(e,t,n){return new this(e).clamp(t,n)}function fu(e){if(!e||typeof e!=`object`)throw Error(vl+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,dl,`rounding`,0,8,`toExpNeg`,-ul,0,`toExpPos`,0,ul,`maxE`,0,ul,`minE`,-ul,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=hl[n]),(r=e[n])!==void 0)if(W(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(yl+n+`: `+r);if(n=`crypto`,i&&(this[n]=hl[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(xl);else this[n]=!1;else throw Error(yl+n+`: `+r);return this}function pu(e){return new this(e).cos()}function mu(e){return new this(e).cosh()}function hu(e){var t,n,r;function i(e){var t,n,r,a=this;if(!(a instanceof i))return new i(e);if(a.constructor=i,bu(e)){a.s=e.s,U?!e.d||e.e>i.maxE?(a.e=NaN,a.d=null):e.e<i.minE?(a.e=0,a.d=[0]):(a.e=e.e,a.d=e.d.slice()):(a.e=e.e,a.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){a.s=1/e<0?-1:1,a.e=0,a.d=[0];return}if(e<0?(e=-e,a.s=-1):a.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;U?t>i.maxE?(a.e=NaN,a.d=null):t<i.minE?(a.e=0,a.d=[0]):(a.e=t,a.d=[e]):(a.e=t,a.d=[e]);return}if(e*0!=0){e||(a.s=NaN),a.e=NaN,a.d=null;return}return Kl(a,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),a.s=-1):(n===43&&(e=e.slice(1)),a.s=1),El.test(e)?Kl(a,e):ql(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,Kl(a,e.toString());throw Error(yl+e)}if(i.prototype=q,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=fu,i.clone=hu,i.isDecimal=bu,i.abs=eu,i.acos=tu,i.acosh=nu,i.add=ru,i.asin=iu,i.asinh=au,i.atan=ou,i.atanh=su,i.atan2=cu,i.cbrt=lu,i.ceil=uu,i.clamp=du,i.cos=pu,i.cosh=mu,i.div=gu,i.exp=_u,i.floor=vu,i.hypot=yu,i.ln=xu,i.log=Su,i.log10=wu,i.log2=Cu,i.max=Tu,i.min=Eu,i.mod=Du,i.mul=Ou,i.pow=ku,i.random=Au,i.round=ju,i.sign=Mu,i.sin=Nu,i.sinh=Pu,i.sqrt=Fu,i.sub=Iu,i.sum=Lu,i.tan=Ru,i.tanh=zu,i.trunc=Bu,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 i.config(e),i}function gu(e,t){return new this(e).div(t)}function _u(e){return new this(e).exp()}function vu(e){return Z(e=new this(e),e.e+1,3)}function yu(){var e,t,n=new this(0);for(U=!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 U=!0,new this(1/0);n=t}return U=!0,n.sqrt()}function bu(e){return e instanceof Vu||e&&e.toStringTag===Sl||!1}function xu(e){return new this(e).ln()}function Su(e,t){return new this(e).log(t)}function Cu(e){return new this(e).log(2)}function wu(e){return new this(e).log(10)}function Tu(){return Hl(this,arguments,-1)}function Eu(){return Hl(this,arguments,1)}function Du(e,t){return new this(e).mod(t)}function Ou(e,t){return new this(e).mul(t)}function ku(e,t){return new this(e).pow(t)}function Au(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:Y(e,1,dl),r=Math.ceil(e/K),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(xl);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=K,r&&e&&(i=G(10,K-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-=K)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<K&&(n-=K-r)}return o.e=n,o.d=s,o}function ju(e){return Z(e=new this(e),e.e+1,this.rounding)}function Mu(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Nu(e){return new this(e).sin()}function Pu(e){return new this(e).sinh()}function Fu(e){return new this(e).sqrt()}function Iu(e,t){return new this(e).sub(t)}function Lu(){var e=0,t=arguments,n=new this(t[e]);for(U=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return U=!0,Z(n,this.precision,this.rounding)}function Ru(e){return new this(e).tan()}function zu(e){return new this(e).tanh()}function Bu(e){return Z(e=new this(e),e.e+1,1)}q[Symbol.for(`nodejs.util.inspect.custom`)]=q.toString,q[Symbol.toStringTag]=`Decimal`;var Vu=q.constructor=hu(hl);pl=new Vu(pl),ml=new Vu(ml);var Hu=Vu,Uu=`BigNumber`,Wu=[`?on`,`config`],Gu=Hc(Uu,Wu,e=>{var{on:t,config:n}=e,r=Hu.clone({precision:n.precision,modulo:Hu.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 Q=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Ku=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},qu=function(e){let t=Math.PI/4;if(-t>e||e>t)return Math.cos(e)-1;let n=e*e;return n*(n*(n*(n*(n*(n*(n*(n/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},Ju=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))},Yu=function(){throw SyntaxError(`Invalid Param`)};function Xu(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 Zu={re:0,im:0},Qu=function(e,t){let n=Zu;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 $.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 $.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]):Yu();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&&Yu();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
206
|
-
`||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&
|
|
205
|
+
var nl=9e15,rl=1e9,il=`0123456789abcdef`,al=`2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058`,ol=`3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789`,sl={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-nl,maxE:nl,crypto:!1},cl,ll,H=!0,ul=`[DecimalError] `,dl=ul+`Invalid argument: `,fl=ul+`Precision limit exceeded`,pl=ul+`crypto unavailable`,ml=`[object Decimal]`,U=Math.floor,W=Math.pow,hl=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,gl=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,_l=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,vl=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,yl=1e7,G=7,bl=9007199254740991,xl=al.length-1,Sl=ol.length-1,K={toStringTag:ml};K.absoluteValue=K.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),X(e)},K.ceil=function(){return X(new this.constructor(this),this.e+1,2)},K.clampedTo=K.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(dl+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)},K.comparedTo=K.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},K.cosine=K.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())+G,r.rounding=1,n=Tl(r,Ul(r,n)),r.precision=e,r.rounding=t,X(ll==2||ll==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)},K.cubeRoot=K.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*W(u.s*u,1/3),!a||Math.abs(a)==1/0?(n=q(u.d),e=u.e,(a=(e-n.length+1)%3)&&(n+=a==1||a==-2?`0`:`00`),a=W(n,1/3),e=U((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),q(s.d).slice(0,o)===(n=q(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n==`9999`||!i&&n==`4999`){if(!i&&(X(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`)&&(X(r,e+1,1),t=!r.times(r).times(r).eq(u));break}return H=!0,X(r,e,d.rounding,t)},K.decimalPlaces=K.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-U(this.e/G))*G,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n},K.dividedBy=K.div=function(e){return Y(this,new this.constructor(e))},K.dividedToIntegerBy=K.divToInt=function(e){var t=this,n=t.constructor;return X(Y(t,new n(e),0,1,1),n.precision,n.rounding)},K.equals=K.eq=function(e){return this.cmp(e)===0},K.floor=function(){return X(new this.constructor(this),this.e+1,3)},K.greaterThan=K.gt=function(e){return this.cmp(e)>0},K.greaterThanOrEqualTo=K.gte=function(e){var t=this.cmp(e);return t==1||t===0},K.hyperbolicCosine=K.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/Hl(4,e)).toString()):(e=16,t=`2.3283064365386962890625e-10`),a=Vl(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 X(a,o.precision=n,o.rounding=r,!0)},K.hyperbolicSine=K.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=Vl(a,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/Hl(5,e)),i=Vl(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,X(i,t,n,!0)},K.hyperbolicTangent=K.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)},K.inverseCosine=K.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n===-1?e.isZero()?kl(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()?kl(t,r,i):new t(0):new t(NaN)},K.inverseHyperbolicCosine=K.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)},K.inverseHyperbolicSine=K.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())},K.inverseHyperbolicTangent=K.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?X(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)},K.inverseSine=K.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=kl(a,n+4,r).times(.5),e.s=i.s,e):new a(NaN))},K.inverseTangent=K.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<=Sl)return o=kl(u,d+4,f).times(.25),o.s=l.s,o}else{if(!l.s)return new u(NaN);if(d+4<=Sl)return o=kl(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/G+2|0),e=n;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(H=!1,t=Math.ceil(s/G),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,X(o,u.precision=d,u.rounding=f,!0)},K.isFinite=function(){return!!this.d},K.isInteger=K.isInt=function(){return!!this.d&&U(this.e/G)>this.d.length-2},K.isNaN=function(){return!this.s},K.isNegative=K.isNeg=function(){return this.s<0},K.isPositive=K.isPos=function(){return this.s>0},K.isZero=function(){return!!this.d&&this.d[0]===0},K.lessThan=K.lt=function(e){return this.cmp(e)<0},K.lessThanOrEqualTo=K.lte=function(e){return this.cmp(e)<1},K.logarithm=K.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=Il(l,s),r=t?Ol(u,s+10):Il(e,s),c=Y(o,r,s,1),Cl(c.d,i=d,f))do if(s+=10,o=Il(l,s),r=t?Ol(u,s+10):Il(e,s),c=Y(o,r,s,1),!a){+q(c.d).slice(i+1,i+15)+1==1e14&&(c=X(c,d+1,0));break}while(Cl(c.d,i+=10,f));return H=!0,X(c,d,f)},K.minus=K.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?X(e,s,c):e}if(n=U(e.e/G),u=U(p.e/G),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/G),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]=yl-1;--l[i],l[r]+=yl}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=Dl(l,n),H?X(e,s,c):e):new m(c===3?-0:0)},K.modulo=K.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]?X(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))},K.naturalExponential=K.exp=function(){return Fl(this)},K.naturalLogarithm=K.ln=function(){return Il(this)},K.negated=K.neg=function(){var e=new this.constructor(this);return e.s=-e.s,X(e)},K.plus=K.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?X(e,s,c):e;if(a=U(d.e/G),r=U(e.e/G),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/G),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)/yl|0,l[i]%=yl;for(t&&(l.unshift(t),++r),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=Dl(l,r),H?X(e,s,c):e},K.precision=K.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(dl+e);return n.d?(t=Al(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t},K.round=function(){var e=this,t=e.constructor;return X(new t(e),e.e+1,t.rounding)},K.sine=K.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())+G,r.rounding=1,n=Bl(r,Ul(r,n)),r.precision=e,r.rounding=t,X(ll>2?n.neg():n,e,t,!0)):new r(NaN)},K.squareRoot=K.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=q(s),(t.length+c)%2==0&&(t+=`0`),l=Math.sqrt(t),c=U((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),q(a.d).slice(0,n)===(t=q(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t==`9999`||!i&&t==`4999`){if(!i&&(X(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`)&&(X(r,c+1,1),e=!r.times(r).eq(o));break}return H=!0,X(r,c,u.rounding,e)},K.tangent=K.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,X(ll==2||ll==4?n.neg():n,e,t,!0)):new r(NaN)},K.times=K.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=U(u.e/G)+U(e.e/G),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%yl|0,t=s/yl|0;a[i]=(a[i]+t)%yl|0}for(;!a[--o];)a.pop();return t?++n:a.shift(),e.d=a,e.e=Dl(a,n),H?X(e,d.precision,d.rounding):e},K.toBinary=function(e,t){return Wl(this,2,e,t)},K.toDecimalPlaces=K.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(J(e,0,rl),t===void 0?t=r.rounding:J(t,0,8),X(n,e+n.e+1,t))},K.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=El(r,!0):(J(e,0,rl),t===void 0?t=i.rounding:J(t,0,8),r=X(new i(r),e+1,t),n=El(r,!0,e+1)),r.isNeg()&&!r.isZero()?`-`+n:n},K.toFixed=function(e,t){var n,r,i=this,a=i.constructor;return e===void 0?n=El(i):(J(e,0,rl),t===void 0?t=a.rounding:J(t,0,8),r=X(new a(i),e+i.e+1,t),n=El(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?`-`+n:n},K.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=Al(m)-p.e-1,o=a%G,t.d[0]=W(10,o<0?G+o:o),e==null)e=a>0?t:l;else{if(s=new h(e),!s.isInt()||s.lt(l))throw Error(dl+s);e=s.gt(t)?a>0?t:l:s}for(H=!1,s=new h(q(m)),u=h.precision,h.precision=a=m.length*G*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},K.toHexadecimal=K.toHex=function(e,t){return Wl(this,16,e,t)},K.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:J(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,X(n)):(e.s=n.s,n=e),n},K.toNumber=function(){return+this},K.toOctal=function(e,t){return Wl(this,8,e,t)},K.toPower=K.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(W(+s,l));if(s=new c(s),s.eq(1))return s;if(r=c.precision,a=c.rounding,e.eq(1))return X(s,r,a);if(t=U(e.e/G),t>=e.d.length-1&&(n=l<0?-l:l)<=bl)return i=Ml(c,s,n,r),e.s<0?new c(1).div(i):X(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=W(+s,l),t=n==0||!isFinite(n)?U(l*(Math.log(`0.`+q(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=Fl(e.times(Il(s,r+n)),r),i.d&&(i=X(i,r+5,1),Cl(i.d,r,a)&&(t=r+10,i=X(Fl(e.times(Il(s,t+n)),t),t+5,1),+q(i.d).slice(r+1,r+15)+1==1e14&&(i=X(i,r+1,0)))),i.s=o,H=!0,c.rounding=a,X(i,r,a))},K.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=El(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(J(e,1,rl),t===void 0?t=i.rounding:J(t,0,8),r=X(new i(r),e,t),n=El(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?`-`+n:n},K.toSignificantDigits=K.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(J(e,1,rl),t===void 0?t=r.rounding:J(t,0,8)),X(new r(n),e,t)},K.toString=function(){var e=this,t=e.constructor,n=El(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?`-`+n:n},K.truncated=K.trunc=function(){return X(new this.constructor(this),this.e+1,1)},K.valueOf=K.toJSON=function(){var e=this,t=e.constructor,n=El(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?`-`+n:n};function q(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=G-r.length,n&&(a+=jl(n)),a+=r;o=e[t],r=o+``,n=G-r.length,n&&(a+=jl(n))}else if(o===0)return`0`;for(;o%10==0;)o/=10;return a+o}function J(e,t,n){if(e!==~~e||e<t||e>n)throw Error(dl+e)}function Cl(e,t,n,r){var i,a,o,s;for(a=e[0];a>=10;a/=10)--t;return--t<0?(t+=G,i=0):(i=Math.ceil((t+1)/G),t%=G),a=W(10,G-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)==W(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)==W(10,t-3)-1,o}function wl(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]+=il.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 Tl(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/Hl(4,n)).toString()):(n=16,i=`2.3283064365386962890625e-10`),e.precision+=n,t=Vl(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 e(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 t(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 n(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(r,i,a,o,s,c){var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,ee,te,w,T,E,ne=r.constructor,re=r.s==i.s?1:-1,D=r.d,O=i.d;if(!D||!D[0]||!O||!O[0])return new ne(!r.s||!i.s||(D?O&&D[0]==O[0]:!O)?NaN:D&&D[0]==0||!O?re*0:re/0);for(c?(p=1,u=r.e-i.e):(c=yl,p=G,u=U(r.e/p)-U(i.e/p)),T=O.length,te=D.length,_=new ne(re),v=_.d=[],d=0;O[d]==(D[d]||0);d++);if(O[d]>(D[d]||0)&&u--,a==null?(S=a=ne.precision,o=ne.rounding):S=s?a+(r.e-i.e)+1:a,S<0)v.push(1),m=!0;else{if(S=S/p+2|0,d=0,T==1){for(f=0,O=O[0],S++;(d<te||f)&&S--;d++)C=f*c+(D[d]||0),v[d]=C/O|0,f=C%O|0;m=f||d<te}else{for(f=c/(O[0]+1)|0,f>1&&(O=e(O,f,c),D=e(D,f,c),T=O.length,te=D.length),ee=T,y=D.slice(0,T),b=y.length;b<T;)y[b++]=0;E=O.slice(),E.unshift(0),w=O[0],O[1]>=c/2&&++w;do f=0,l=t(O,y,T,b),l<0?(x=y[0],T!=b&&(x=x*c+(y[1]||0)),f=x/w|0,f>1?(f>=c&&(f=c-1),h=e(O,f,c),g=h.length,b=y.length,l=t(h,y,g,b),l==1&&(f--,n(h,T<g?E:O,g,c))):(f==0&&(l=f=1),h=O.slice()),g=h.length,g<b&&h.unshift(0),n(y,h,b,c),l==-1&&(b=y.length,l=t(O,y,T,b),l<1&&(f++,n(y,T<b?E:O,b,c))),b=y.length):l===0&&(f++,y=[0]),v[d++]=f,l&&y[0]?y[b++]=D[ee]||0:(y=[D[ee]],b=1);while((ee++<te||y[0]!==void 0)&&S--);m=y[0]!==void 0}v[0]||v.shift()}if(p==1)_.e=u,cl=m;else{for(d=1,f=v[0];f>=10;f/=10)d++;_.e=d+u*p-1,X(_,s?a+_.e+1:a,o,m)}return _}})();function X(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+=G,o=t,u=d[f=0],c=u/W(10,i-o-1)%10|0;else if(f=Math.ceil((a+1)/G),s=d.length,f>=s)if(r){for(;s++<=f;)d.push(0);u=c=0,i=1,a%=G,o=a-G+1}else break out;else{for(u=s=d[f],i=1;s>=10;s/=10)i++;a%=G,o=a-G+i,c=o<0?0:u/W(10,i-o-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(o<0?u:u%W(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/W(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]=W(10,(G-t%G)%G),e.e=-t||0):d[0]=e.e=0,e;if(a==0?(d.length=f,s=1,f--):(d.length=f+1,s=W(10,G-a),d[f]=o>0?(u/W(10,i-o)%W(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]==yl&&(d[0]=1));break}else{if(d[f]+=s,d[f]!=yl)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 El(e,t,n){if(!e.isFinite())return Ll(e);var r,i=e.e,a=q(e.d),o=a.length;return t?(n&&(r=n-o)>0?a=a.charAt(0)+`.`+a.slice(1)+jl(r):o>1&&(a=a.charAt(0)+`.`+a.slice(1)),a=a+(e.e<0?`e`:`e+`)+e.e):i<0?(a=`0.`+jl(-i-1)+a,n&&(r=n-o)>0&&(a+=jl(r))):i>=o?(a+=jl(i+1-o),n&&(r=n-i-1)>0&&(a=a+`.`+jl(r))):((r=i+1)<o&&(a=a.slice(0,r)+`.`+a.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(a+=`.`),a+=jl(r))),a}function Dl(e,t){var n=e[0];for(t*=G;n>=10;n/=10)t++;return t}function Ol(e,t,n){if(t>xl)throw H=!0,n&&(e.precision=n),Error(fl);return X(new e(al),t,1,!0)}function kl(e,t,n){if(t>Sl)throw Error(fl);return X(new e(ol),t,n,!0)}function Al(e){var t=e.length-1,n=t*G+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 jl(e){for(var t=``;e--;)t+=`0`;return t}function Ml(e,t,n,r){var i,a=new e(1),o=Math.ceil(r/G+4);for(H=!1;;){if(n%2&&(a=a.times(t),Gl(a.d,o)&&(i=!0)),n=U(n/2),n===0){n=a.d.length-1,i&&a.d[n]===0&&++a.d[n];break}t=t.times(t),Gl(t.d,o)}return H=!0,a}function Nl(e){return e.d[e.d.length-1]&1}function Pl(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 Fl(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(W(2,d))/Math.LN10*2+5|0,c+=r,n=a=o=new f(1),f.precision=c;;){if(a=X(a.times(e),c,1),n=n.times(++u),s=o.plus(Y(a,n,c,1)),q(s.d).slice(0,c)===q(o.d).slice(0,c)){for(i=d;i--;)o=X(o.times(o),c,1);if(t==null)if(l<3&&Cl(o.d,c-r,p,l))f.precision=c+=10,n=a=s=new f(1),u=0,l++;else return X(o,f.precision=m,p,H=!0);else return f.precision=m,o}o=s}}function Il(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=q(g),r=n.charAt(0),Math.abs(a=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=q(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=Ol(_,u+2,y).times(a+``),h=Il(new _(r+`.`+n.slice(1)),u-m).plus(l),_.precision=y,t==null?X(h,y,v,H=!0):h;for(d=h,c=o=h=Y(h.minus(1),h.plus(1),u,1),f=X(h.times(h),u,1),i=3;;){if(o=X(o.times(f),u,1),l=c.plus(Y(o,new _(i),u,1)),q(l.d).slice(0,u)===q(c.d).slice(0,u))if(c=c.times(2),a!==0&&(c=c.plus(Ol(_,u+2,y).times(a+``))),c=Y(c,new _(p),u,1),t==null)if(Cl(c.d,u-m,v,s))_.precision=u+=m,l=o=h=Y(d.minus(1),d.plus(1),u,1),f=X(h.times(h),u,1),i=s=1;else return X(c,_.precision=y,v,H=!0);else return _.precision=y,c;c=l,i+=2}}function Ll(e){return String(e.s*e.s/0)}function Rl(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)%G,n<0&&(r+=G),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=G;r<i;)e.d.push(+t.slice(r,r+=G));t=t.slice(r),r=G-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 zl(e,t){var n,r,i,a,o,s,c,l,u;if(t.indexOf(`_`)>-1){if(t=t.replace(/(\d)_(?=\d)/g,`$1`),vl.test(t))return Rl(e,t)}else if(t===`Infinity`||t===`NaN`)return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(gl.test(t))n=16,t=t.toLowerCase();else if(hl.test(t))n=2;else if(_l.test(t))n=8;else throw Error(dl+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=Ml(r,new r(n),a,a*2)),l=wl(t,n,yl),u=l.length-1,a=u;l[a]===0;--a)l.pop();return a<0?new r(e.s*0):(e.e=Dl(l,u),e.d=l,H=!1,o&&(e=Y(e,i,s*4)),c&&(e=e.times(Math.abs(c)<54?W(2,c):Nu.pow(2,c))),H=!0,e)}function Bl(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:Vl(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Hl(5,n)),t=Vl(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 Vl(e,t,n,r,i){var a,o,s,c,l=1,u=e.precision,d=Math.ceil(u/G);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 Hl(e,t){for(var n=e;--t;)n*=e;return n}function Ul(e,t){var n,r=t.s<0,i=kl(e,e.precision,1),a=i.times(.5);if(t=t.abs(),t.lte(a))return ll=r?4:1,t;if(n=t.divToInt(i),n.isZero())ll=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(a))return ll=Nl(n)?r?2:3:r?4:1,t;ll=Nl(n)?r?1:4:r?3:2}return t.minus(i).abs()}function Wl(e,t,n,r){var i,a,o,s,c,l,u,d,f,p=e.constructor,m=n!==void 0;if(m?(J(n,1,rl),r===void 0?r=p.rounding:J(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())u=Ll(e);else{for(u=El(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=wl(El(f),10,i),f.e=f.d.length),d=wl(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=cl),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+=il.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=wl(u,i,t),c=d.length;!d[c-1];--c);for(o=1,u=`1.`;o<c;o++)u+=il.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 Gl(e,t){if(e.length>t)return e.length=t,!0}function Kl(e){return new this(e).abs()}function ql(e){return new this(e).acos()}function Jl(e){return new this(e).acosh()}function Yl(e,t){return new this(e).plus(t)}function Xl(e){return new this(e).asin()}function Zl(e){return new this(e).asinh()}function Ql(e){return new this(e).atan()}function $l(e){return new this(e).atanh()}function eu(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=kl(this,a,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?kl(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=kl(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=kl(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 tu(e){return new this(e).cbrt()}function nu(e){return X(e=new this(e),e.e+1,2)}function ru(e,t,n){return new this(e).clamp(t,n)}function iu(e){if(!e||typeof e!=`object`)throw Error(ul+`Object expected`);var t,n,r,i=e.defaults===!0,a=[`precision`,1,rl,`rounding`,0,8,`toExpNeg`,-nl,0,`toExpPos`,0,nl,`maxE`,0,nl,`minE`,-nl,0,`modulo`,0,9];for(t=0;t<a.length;t+=3)if(n=a[t],i&&(this[n]=sl[n]),(r=e[n])!==void 0)if(U(r)===r&&r>=a[t+1]&&r<=a[t+2])this[n]=r;else throw Error(dl+n+`: `+r);if(n=`crypto`,i&&(this[n]=sl[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(pl);else this[n]=!1;else throw Error(dl+n+`: `+r);return this}function au(e){return new this(e).cos()}function ou(e){return new this(e).cosh()}function su(e){var t,n,r;function i(e){var t,n,r,a=this;if(!(a instanceof i))return new i(e);if(a.constructor=i,fu(e)){a.s=e.s,H?!e.d||e.e>i.maxE?(a.e=NaN,a.d=null):e.e<i.minE?(a.e=0,a.d=[0]):(a.e=e.e,a.d=e.d.slice()):(a.e=e.e,a.d=e.d?e.d.slice():e.d);return}if(r=typeof e,r===`number`){if(e===0){a.s=1/e<0?-1:1,a.e=0,a.d=[0];return}if(e<0?(e=-e,a.s=-1):a.s=1,e===~~e&&e<1e7){for(t=0,n=e;n>=10;n/=10)t++;H?t>i.maxE?(a.e=NaN,a.d=null):t<i.minE?(a.e=0,a.d=[0]):(a.e=t,a.d=[e]):(a.e=t,a.d=[e]);return}if(e*0!=0){e||(a.s=NaN),a.e=NaN,a.d=null;return}return Rl(a,e.toString())}if(r===`string`)return(n=e.charCodeAt(0))===45?(e=e.slice(1),a.s=-1):(n===43&&(e=e.slice(1)),a.s=1),vl.test(e)?Rl(a,e):zl(a,e);if(r===`bigint`)return e<0?(e=-e,a.s=-1):a.s=1,Rl(a,e.toString());throw Error(dl+e)}if(i.prototype=K,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=iu,i.clone=su,i.isDecimal=fu,i.abs=Kl,i.acos=ql,i.acosh=Jl,i.add=Yl,i.asin=Xl,i.asinh=Zl,i.atan=Ql,i.atanh=$l,i.atan2=eu,i.cbrt=tu,i.ceil=nu,i.clamp=ru,i.cos=au,i.cosh=ou,i.div=cu,i.exp=lu,i.floor=uu,i.hypot=du,i.ln=pu,i.log=mu,i.log10=gu,i.log2=hu,i.max=_u,i.min=vu,i.mod=yu,i.mul=bu,i.pow=xu,i.random=Su,i.round=Cu,i.sign=wu,i.sin=Tu,i.sinh=Eu,i.sqrt=Du,i.sub=Ou,i.sum=ku,i.tan=Au,i.tanh=ju,i.trunc=Mu,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 i.config(e),i}function cu(e,t){return new this(e).div(t)}function lu(e){return new this(e).exp()}function uu(e){return X(e=new this(e),e.e+1,3)}function du(){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()}function fu(e){return e instanceof Nu||e&&e.toStringTag===ml||!1}function pu(e){return new this(e).ln()}function mu(e,t){return new this(e).log(t)}function hu(e){return new this(e).log(2)}function gu(e){return new this(e).log(10)}function _u(){return Pl(this,arguments,-1)}function vu(){return Pl(this,arguments,1)}function yu(e,t){return new this(e).mod(t)}function bu(e,t){return new this(e).mul(t)}function xu(e,t){return new this(e).pow(t)}function Su(e){var t,n,r,i,a=0,o=new this(1),s=[];if(e===void 0?e=this.precision:J(e,1,rl),r=Math.ceil(e/G),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(pl);else for(;a<r;)s[a++]=Math.random()*1e7|0;for(r=s[--a],e%=G,r&&e&&(i=W(10,G-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-=G)s.shift();for(r=1,i=s[0];i>=10;i/=10)r++;r<G&&(n-=G-r)}return o.e=n,o.d=s,o}function Cu(e){return X(e=new this(e),e.e+1,this.rounding)}function wu(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Tu(e){return new this(e).sin()}function Eu(e){return new this(e).sinh()}function Du(e){return new this(e).sqrt()}function Ou(e,t){return new this(e).sub(t)}function ku(){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,X(n,this.precision,this.rounding)}function Au(e){return new this(e).tan()}function ju(e){return new this(e).tanh()}function Mu(e){return X(e=new this(e),e.e+1,1)}K[Symbol.for(`nodejs.util.inspect.custom`)]=K.toString,K[Symbol.toStringTag]=`Decimal`;var Nu=K.constructor=su(sl);al=new Nu(al),ol=new Nu(ol);var Pu=Nu,Fu=`BigNumber`,Iu=[`?on`,`config`],Lu=Pc(Fu,Iu,e=>{var{on:t,config:n}=e,r=Pu.clone({precision:n.precision,modulo:Pu.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},Ru=function(e){let t=Math.PI/4;if(-t>e||e>t)return Math.cos(e)-1;let n=e*e;return n*(n*(n*(n*(n*(n*(n*(n/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},zu=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))},Bu=function(){throw SyntaxError(`Invalid Param`)};function Vu(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 Hu={re:0,im:0},Uu=function(e,t){let n=Hu;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 $.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 $.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]):Bu();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&&Bu();for(let e=0;e<t.length;e++){let a=t[e];a===` `||a===` `||a===`
|
|
206
|
+
`||(a===`+`?r++:a===`-`?i++:a===`i`||a===`I`?(r+i===0&&Bu(),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))&&Bu(),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&&Bu();break;case`number`:n.im=0,n.re=e;break;default:Bu()}return isNaN(n.re)||isNaN(n.im),n};function $(e,t){if(!(this instanceof $))return new $(e,t);let n=Uu(e,t);this.re=n.re,this.im=n.im}$.prototype={re:0,im:0,sign:function(){let e=zu(this.re,this.im);return new $(this.re/e,this.im/e)},add:function(e,t){let n=Uu(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?$.NAN:$.INFINITY:new $(this.re+n.re,this.im+n.im)},sub:function(e,t){let n=Uu(e,t),r=this.isInfinite(),i=!(isFinite(n.re)&&isFinite(n.im));return r||i?r&&i?$.NAN:$.INFINITY:new $(this.re-n.re,this.im-n.im)},mul:function(e,t){let n=Uu(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?$.NAN:r||i?$.INFINITY:n.im===0&&this.im===0?new $(this.re*n.re,0):new $(this.re*n.re-this.im*n.im,this.re*n.im+this.im*n.re)},div:function(e,t){let n=Uu(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 $.NAN;if(o||r)return $.INFINITY;if(a||i)return $.ZERO;if(n.im===0)return new $(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 $((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 $((this.re+this.im*e)/t,(this.im-this.re*e)/t)}},pow:function(e,t){let n=Uu(e,t),r=this.re===0&&this.im===0,i=n.re===0&&n.im===0;if(i)return $.ONE;if(n.im===0){if(this.im===0&&this.re>0)return new $(this.re**+n.re,0);if(this.re===0)switch((n.re%4+4)%4){case 0:return new $(this.im**+n.re,0);case 1:return new $(0,this.im**+n.re);case 2:return new $(-(this.im**+n.re),0);case 3:return new $(0,-(this.im**+n.re))}}if(r&&n.re>0)return $.ZERO;let a=Math.atan2(this.im,this.re),o=Vu(this.re,this.im),s=Math.exp(n.re*o-n.im*a),c=n.im*o+n.re*a;return new $(s*Math.cos(c),s*Math.sin(c))},sqrt:function(){let e=this.re,t=this.im;if(t===0)return e>=0?new $(Math.sqrt(e),0):new $(0,Math.sqrt(-e));let n=zu(e,t),r=Math.sqrt(.5*(n+Math.abs(e))),i=Math.abs(t)/(2*r);return e>=0?new $(r,t<0?-i:i):new $(i,t<0?-r:r)},exp:function(){let e=Math.exp(this.re);return this.im===0?new $(e,0):new $(e*Math.cos(this.im),e*Math.sin(this.im))},expm1:function(){let e=this.re,t=this.im;return new $(Math.expm1(e)*Math.cos(t)+Ru(t),Math.exp(e)*Math.sin(t))},log:function(){let e=this.re,t=this.im;return t===0&&e>0?new $(Math.log(e),0):new $(Vu(e,t),Math.atan2(t,e))},abs:function(){return zu(this.re,this.im)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){let e=this.re,t=this.im;return new $(Math.sin(e)*Z(t),Math.cos(e)*Q(t))},cos:function(){let e=this.re,t=this.im;return new $(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 $(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 $(-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 $(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 $(Math.sin(e)*Z(t)/n,-Math.cos(e)*Q(t)/n)},asin:function(){let e=this.re,t=this.im,n=new $(t*t-e*e+1,-2*e*t).sqrt(),r=new $(n.re-t,n.im+e).log();return new $(r.im,-r.re)},acos:function(){let e=this.re,t=this.im,n=new $(t*t-e*e+1,-2*e*t).sqrt(),r=new $(n.re-t,n.im+e).log();return new $(Math.PI/2-r.im,r.re)},atan:function(){let e=this.re,t=this.im;if(e===0){if(t===1)return new $(0,1/0);if(t===-1)return new $(0,-1/0)}let n=e*e+(1-t)*(1-t),r=new $((1-t*t-e*e)/n,-2*e/n).log();return new $(-.5*r.im,.5*r.re)},acot:function(){let e=this.re,t=this.im;if(t===0)return new $(Math.atan2(1,e),0);let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).atan():new $(e/n,-t/n).atan()},asec:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new $(0,1/0);let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).acos():new $(e/n,-t/n).acos()},acsc:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new $(Math.PI/2,1/0);let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).asin():new $(e/n,-t/n).asin()},sinh:function(){let e=this.re,t=this.im;return new $(Q(e)*Math.cos(t),Z(e)*Math.sin(t))},cosh:function(){let e=this.re,t=this.im;return new $(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 $(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 $(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 $(-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 $(2*Z(e)*Math.cos(t)/n,-2*Q(e)*Math.sin(t)/n)},asinh:function(){let e=this.im;this.im=-this.re,this.re=e;let t=this.asin();return this.re=-this.im,this.im=e,e=t.re,t.re=-t.im,t.im=e,t},acosh:function(){let e=this.acos();if(e.im<=0){let t=e.re;e.re=-e.im,e.im=t}else{let t=e.im;e.im=-e.re,e.re=t}return e},atanh:function(){let e=this.re,t=this.im,n=e>1&&t===0,r=1-e,i=1+e,a=r*r+t*t,o=a===0?new $(e===-1?0:e/0,t===0?0:t/0):new $((i*r-t*t)/a,(t*r+i*t)/a),s=o.re;return o.re=Vu(o.re,o.im)/2,o.im=Math.atan2(o.im,s)/2,n&&(o.im=-o.im),o},acoth:function(){let e=this.re,t=this.im;if(e===0&&t===0)return new $(0,Math.PI/2);let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).atanh():new $(e/n,-t/n).atanh()},acsch:function(){let e=this.re,t=this.im;if(t===0)return new $(e===0?1/0:Math.log(e+Math.sqrt(e*e+1)),0);let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).asinh():new $(e/n,-t/n).asinh()},asech:function(){let e=this.re,t=this.im;if(this.isZero())return $.INFINITY;let n=e*e+t*t;return n===0?new $(e===0?0:e/0,t===0?0:-t/0).acosh():new $(e/n,-t/n).acosh()},inverse:function(){if(this.isZero())return $.INFINITY;if(this.isInfinite())return $.ZERO;let e=this.re,t=this.im,n=e*e+t*t;return new $(e/n,-t/n)},conjugate:function(){return new $(this.re,-this.im)},neg:function(){return new $(-this.re,-this.im)},ceil:function(e){return e=10**(e||0),new $(Math.ceil(this.re*e)/e,Math.ceil(this.im*e)/e)},floor:function(e){return e=10**(e||0),new $(Math.floor(this.re*e)/e,Math.floor(this.im*e)/e)},round:function(e){return e=10**(e||0),new $(Math.round(this.re*e)/e,Math.round(this.im*e)/e)},equals:function(e,t){let n=Uu(e,t);return Math.abs(n.re-this.re)<=$.EPSILON&&Math.abs(n.im-this.im)<=$.EPSILON},clone:function(){return new $(this.re,this.im)},toString:function(){let e=this.re,t=this.im,n=``;return this.isNaN()?`NaN`:this.isInfinite()?`Infinity`:(Math.abs(e)<$.EPSILON&&(e=0),Math.abs(t)<$.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()}},$.ZERO=new $(0,0),$.ONE=new $(1,0),$.I=new $(0,1),$.PI=new $(Math.PI,0),$.E=new $(Math.E,0),$.INFINITY=new $(1/0,1/0),$.NAN=new $(NaN,NaN),$.EPSILON=1e-15;var Wu=`Complex`,Gu=[],Ku=Pc(Wu,Gu,()=>(Object.defineProperty($,`name`,{value:`Complex`}),$.prototype.constructor=$,$.prototype.type=`Complex`,$.prototype.isComplex=!0,$.prototype.toJSON=function(){return{mathjs:`Complex`,re:this.re,im:this.im}},$.prototype.toPolar=function(){return{r:this.abs(),phi:this.arg()}},$.prototype.format=function(e){var t=``,n=this.im,r=this.re,i=Ks(this.re,e),a=Ks(this.im,e),o=R(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},$.fromPolar=function(e){switch(arguments.length){case 1:var t=arguments[0];if(typeof t==`object`)return $(t);throw TypeError(`Input has to be an object with r and phi keys.`);case 2:var n=arguments[0],r=arguments[1];if(R(n)){if(Zo(r)&&r.hasBase(`ANGLE`)&&(r=r.toNumber(`rad`)),R(r))return new $({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`)}},$.prototype.valueOf=$.prototype.toString,$.fromJSON=function(e){return new $(e)},$.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},$),{isClass:!0}),qu=w(((exports,t)=>{
|
|
207
207
|
/**
|
|
208
208
|
* @license Fraction.js v4.3.0 20/08/2023
|
|
209
209
|
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
|
|
@@ -211,12 +211,12 @@ var ul=9e15,dl=1e9,fl=`0123456789abcdef`,pl=`2.302585092994045684017991454684364
|
|
|
211
211
|
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
|
|
212
212
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
213
213
|
**/
|
|
214
|
-
(function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n){if(u===`1`)continue;if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r){if(u===`1`)continue;if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof exports==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(void 0)}),rd=E(nd(),1),id=`Fraction`,ad=[],od=Hc(id,ad,()=>(Object.defineProperty(rd.default,`name`,{value:`Fraction`}),rd.default.prototype.constructor=rd.default,rd.default.prototype.type=`Fraction`,rd.default.prototype.isFraction=!0,rd.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},rd.default.fromJSON=function(e){return new rd.default(e)},rd.default),{isClass:!0}),sd=`Matrix`,cd=[],ld=Hc(sd,cd,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function ud(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var dd=`DenseMatrix`,fd=[`Matrix`],pd=Hc(dd,fd,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!ss(t))throw Error(`Invalid datatype: `+t);if(cs(e))e.type===`DenseMatrix`?(this._data=Vs(e._data),this._size=Vs(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&B(e.data)&&B(e.size))this._data=e.data,this._size=e.size,wc(this._data,this._size),this._datatype=t||e.datatype;else if(B(e))this._data=l(e),this._size=Sc(this._data),wc(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Bs(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Pc(this._data,Bs)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!B(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new V(e.length,this._size.length);for(var t=0;t<e.length;t++)H(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];H(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!B(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new V(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],H(a,s.length),s=s[a];return a=e[e.length-1],H(a,s.length),s[a]=t,this};function r(e,t){if(!ps(t))throw TypeError(`Invalid index`);var r=t.isScalar();if(r)return e.get(t.min());var a=t.size();if(a.length!==e._size.length)throw new V(a.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)H(o[c],e._size[c]),H(s[c],e._size[c]);return new n(i(e._data,t,a.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return H(t,e.length),e[t]}).valueOf():o.map(function(a){H(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if(cs(n)?(s=n.size(),n=n.valueOf()):s=Sc(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Us(s,i))try{n=s.length===0?zc([n],i):zc(n,i),s=Sc(n)}catch{}if(i.length<e._size.length)throw new V(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=jc(n,i.length,u,s)}if(!Us(i,s))throw new V(i,s,`>`);var d=t.max().map(function(e){return e+1});c(e,d,r);var f=i.length,p=0;o(e._data,t,n,f,p)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){H(t),e[t]=n[r[0]]}):s.forEach(function(a,s){H(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!ls(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e),i=n?this.clone():this;return s(i,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;B(r);)r=r[0];return r}return e._size=t.slice(0),e._data=Tc(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;n._data=Dc(n._data,e);var r=n._size.reduce((e,t)=>e*t);return n._size=Oc(e,r),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){var e=new n({data:Vs(this._data),size:Vs(this._size),datatype:this._datatype});return e},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=ud(e),i=function n(i,a){return B(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)},a=i(this._data,[]),o=this._datatype===void 0?void 0:Pc(a,Bs);return new n(a,o)},n.prototype.forEach=function(e){var t=this,n=function n(r,i){B(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)};n(this._data,[])},n.prototype[Symbol.iterator]=function*(){var e=function*e(t,n){if(B(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}};yield*e(this._data,[])},n.prototype.rows=function(){var e=[],t=this.size();if(t.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);var r=this._data;for(var i of r)e.push(new n([i],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return Vs(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return mc(this._data,e)},n.prototype.toString=function(){return mc(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(ts(e)&&(e=e.toNumber()),!z(e)||!Zs(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!B(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(ts(e)&&(e=e.toNumber()),!z(e)||!Zs(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(ts(r)&&(r=r.toNumber()),!z(r)||!Zs(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(B(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if(cs(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=ts(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=Tc(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!z(e)||!Zs(e)||!z(t)||!Zs(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return H(e,this._size[0]),H(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return cs(e)?l(e.valueOf()):B(e)?e.map(l):e}return n},{isClass:!0});function md(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return md(e,t,n)}):t(e)}var hd=`isNumeric`,gd=[`typed`],_d=Hc(hd,gd,e=>{var{typed:t}=e;return t(hd,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>md(t,e))})}),vd=`hasNumericValue`,yd=[`typed`,`isNumeric`],bd=Hc(vd,yd,e=>{var{typed:t,isNumeric:n}=e;return t(vd,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),xd=Gu({config:Ys}),Sd=td({}),Cd=od({}),wd=ld({}),Td=pd({Matrix:wd}),Ed=al({BigNumber:xd,Complex:Sd,DenseMatrix:Td,Fraction:Cd}),Dd=_d({typed:Ed}),Od=bd({isNumeric:Dd,typed:Ed});const kd=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},Ad=e=>{let t=Number(e),n=Date.now();if(Number.isNaN(t))return n+Zo;if(!kd(t)&&o(t))return Qo(t);if(kd(t))return n+t;{let e=t*Yo;return n+e}},jd=`ratelimitlimit`,Md=`ratelimitremaining`,Nd=`ratelimitreset`,Pd=`ratelimitconcurrencylimit`,Fd=`ratelimitconcurrencyremaining`,Id=`ratelimitconcurrencyreset`,Ld=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``),i=Od(r)?Number(r):null;t[e]=i}return t},Rd=e=>{let t=Ld(e);return{rateLimitLimit:t[jd],rateLimitRemaining:t[Md],rateLimitReset:Ad(t[Nd]),concurrencyLimit:t[Pd],concurrencyRemaining:t[Fd],concurrencyReset:Ad(t[Id])}},zd=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:o,behaviours:c}=e??{};return[t,n,r,o].some(s)?null:[t,n,r,i,a,o,...c??[]].filter(Boolean).join(`-`)},Bd=(e,t=Ko,n=Go)=>{let r=Date.now();return o(e)||c(e)?Vd(Number(e),r,t,n):ss(e)&&e!==``?Hd(e,r,t,n):n},Vd=(e,t,n=Ko,r=Go)=>{if(e<n)return e;let i=Qo(e);if(i>t){let e=Math.floor((i-t)/Yo);return e>0&&e<n?e:r}return r},Hd=(e,t,n=Ko,r=Go)=>{if(Xo.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/Yo);return e>0&&e<n?e:r}return r};let Ud=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e}({});const Wd=({axiosInstance:e,logger:t,requestConfig:r,context:i})=>{let a=async a=>{let{response:o,config:s}=a,c=s?.signal;if(c?.aborted)return Promise.reject(Vo(`Request aborted`,s,`ERR_CANCELED`,o));let{status:l,retryAfter:u}=Gd(o,i,r,t);if(l===429&&d(s)){let r=Bd(u);if(s._retryCount>=qo)return t?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:u,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,l={...s,_retryCount:c+1},d=u?r*Yo:n(l._retryCount);return t?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:u,calculatedRetryAfter:d}}),await Ho(d*1e3,s,o),e?.request(l)}return Promise.reject(a)};return a},Gd=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:o,data:c}=e??{},{retryafter:u}=Ld(o??{});if(s(i)||s(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:s(e),providerIsMissing:s(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:u??`undefined`}}),{status:a,retryAfter:u};let f=n?.rateLimits?.mappedRateLimitErrors;if(d(f)&&d(c))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:s,retryAfterValue:d}=e;if(t!==a)continue;let f=n??`message`,p=l(c)?v.query(c,f)[0]:c,m=Kd(p,r);if(t===a&&m){let e=d??qd(o,i),t=Jd(e,s);return{status:429,retryAfter:u??t}}}return{status:a,retryAfter:u}},Kd=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,qd=(e,t)=>d(t)&&d(e)?v.query(e,t)[0]:null,Jd=(e,t=`seconds`)=>d(e)?Yd(e,t):null,Yd=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`){let t=typeof e==`string`?parseFloat(e):e;return t/Yo}if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},Xd=`rateLimitErrorInterceptor`,Zd=({axiosInstance:e,logger:t,requestConfig:r,context:i})=>{let a=async a=>{let{response:o,config:c}=a,l=c?.signal;if(s(i)||s(c))return t?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:Xd,...c,headers:void 0}}),Promise.reject(a);let{requestId:u,targetConcurrencyKey:f,leaseSubscription:p,setRemovalSubscription:m}=c?.requestMetadata??{},h=await nt.getInstance(),g=d(u)&&d(f)?await h.releaseRequest(u,f):!1;if(!g&&d(c?.requestMetadata)&&t?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:Xd,requestId:u,targetConcurrencyKey:f,leaseSubscription:p,setRemovalSubscription:m},code:Ud.RateLimiterReleaseRequestFailed}),l?.aborted)return Promise.reject(Vo(`Request aborted`,c,`ERR_CANCELED`,o));let{status:_,retryAfter:v}=Gd(o,i,r,t);if(_===429&&d(c)){let r=Bd(v);if(c._retryCount>=qo)return t?.warning({category:`HttpClient`,message:`Max retries exceeded for ${c.url}. Aborting.`,context:{...i??{},...c.requestMetadata??{},retryAfterHeader:v,retryAfterAsNumber:r}}),Promise.reject(a);let s=c?._retryCount??0,l={...c,_retryCount:s+1},u=v?r*Yo:n(l._retryCount);return t?.debug({category:`HttpClient`,message:`Received 429 error from ${c.url}`,context:{...i,retryAfterHeader:v,calculatedRetryAfter:u}}),await Ho(u*1e3,c,o),e?.request(l)}return Promise.reject(a)};return a},Qd=`rateLimitResponseInterceptor`,$d=({logger:e,context:t})=>{let n=async n=>{let r=n?.config,i=r?.signal;if(s(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{...r,interceptor:Qd,headers:void 0}});else{let t=n?.headers;if(d(t)){let n=Rd(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:Qd,rateLimitHeaders:n}})}let{requestId:a,targetConcurrencyKey:o,leaseSubscription:s,setRemovalSubscription:c}=r?.requestMetadata??{},l=await nt.getInstance(),u=await l.releaseRequest(a,o);if(u||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:Qd,requestId:a,targetConcurrencyKey:o,leaseSubscription:s,setRemovalSubscription:c},code:Ud.RateLimiterReleaseRequestFailed}),i?.aborted)return Promise.reject(Vo(`Request aborted`,r,`ERR_CANCELED`,n))}return n};return n},ef=e=>(e.validateStatus??=e=>e>=200&&e<300,e),tf=[{onFulfilled:ef,onRejected:null,options:void 0}],nf=[{onFulfilled:null,onRejected:Wd},{onFulfilled:null,onRejected:Oo}],rf=[{onFulfilled:ef,onRejected:null,options:void 0},{onFulfilled:Wo,onRejected:null,options:void 0}],af=[{onFulfilled:$d,onRejected:Zd},{onFulfilled:null,onRejected:Oo}];let sf=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const cf=async({logger:e,redisClientConfig:t,context:n}={})=>{let r,{NODE_ENV:i}=process.env,a=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(r=a.includes(`RETRY`)?uf(e,n):lf(e,n),s(n?.service)||s(n?.organizationId)||i===`test`||s(t)||s(e))return r;await Bo.getInstance(t,e);let o=await Bo.isReady(),c=await nt.getInstance(t,e),l=await c.isRedisConfigured(),u=[],f=[];if(a.includes(`CONCURRENCY`)){if(!l)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!o)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);u.push(...rf),f.push(...af)}let p=zd(n);if(s(p))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:d(r)}}),r;let m=await Do.get(p);if(d(m))return m;let h={interceptors:{requestConfigs:u,responseConfigs:f},instanceConfig:{maxBodyLength:1/0},logger:e,context:n},g=wo.createInstance(h);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${p}]`,context:{...n}}),await Do.set(p,g),g}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:d(r)},error:t,code:sf.HttpTransportInstanceCreateError}),d(r)?r:df()}},lf=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return wo.createInstance(n)??df()},uf=(e,t)=>{let n={interceptors:{requestConfigs:tf,responseConfigs:nf},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return wo.createInstance(n)??df()},df=()=>{let e=p.create({maxBodyLength:1/0});return e};var ff=T((exports,t)=>{t.exports=n;function n(e={}){let{ERR_PATHS_MUST_BE_STRINGS:t=()=>`fast-redact - Paths must be (non-empty) strings`,ERR_INVALID_PATH:n=e=>`fast-redact – Invalid path (${e})`}=e;return function({paths:e}){e.forEach(e=>{if(typeof e!=`string`)throw Error(t());try{if(/〇/.test(e))throw Error();let t=(e[0]===`[`?``:`.`)+e.replace(/^\*/,`〇`).replace(/\.\*/g,`.〇`).replace(/\[\*\]/g,`[〇]`);if(/\n|\r|;/.test(t)||/\/\*/.test(t))throw Error();Function(`
|
|
214
|
+
(function(n){"use strict";var r=2e3,i={s:1,n:0,d:1};function a(e,t){if(isNaN(e=parseInt(e,10)))throw h();return e*t}function o(e,t){if(t===0)throw m();var n=Object.create(p.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var r=f(e,t);return n.n=e/r,n.d=t/r,n}function s(e){for(var t={},n=e,r=2,i=4;i<=n;){for(;n%r===0;)n/=r,t[r]=(t[r]||0)+1;i+=1+2*r++}return n===e?t[e]=(t[e]||0)+1:n>1&&(t[n]=(t[n]||0)+1),t}var c=function(e,t){var n=0,r=1,o=1,s=0,c=0,l=0,u=1,d=1,f=0,p=1,_=1,v=1,y=1e7,b;if(e!=null)if(t!==void 0){if(n=e,r=t,o=n*r,n%1!=0||r%1!=0)throw g()}else switch(typeof e){case`object`:if(`d`in e&&`n`in e)n=e.n,r=e.d,`s`in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(r=e[1]);else throw h();o=n*r;break;case`number`:if(e<0&&(o=e,e=-e),e%1==0)n=e;else if(e>0){for(e>=1&&(d=10**Math.floor(1+Math.log(e)/Math.LN10),e/=d);p<=y&&v<=y;)if(b=(f+_)/(p+v),e===b){p+v<=y?(n=f+_,r=p+v):v>p?(n=_,r=v):(n=f,r=p);break}else e>b?(f+=_,p+=v):(_+=f,v+=p),p>y?(n=_,r=v):(n=f,r=p);n*=d}else (isNaN(e)||isNaN(t))&&(r=n=NaN);break;case`string`:if(p=e.match(/\d+|./g),p===null)throw h();if(p[f]===`-`?(o=-1,f++):p[f]===`+`&&f++,p.length===f+1?c=a(p[f++],o):p[f+1]===`.`||p[f]===`.`?(p[f]!==`.`&&(s=a(p[f++],o)),f++,(f+1===p.length||p[f+1]===`(`&&p[f+3]===`)`||p[f+1]===`'`&&p[f+3]===`'`)&&(c=a(p[f],o),u=10**p[f].length,f++),(p[f]===`(`&&p[f+2]===`)`||p[f]===`'`&&p[f+2]===`'`)&&(l=a(p[f+1],o),d=10**p[f+1].length-1,f+=3)):p[f+1]===`/`||p[f+1]===`:`?(c=a(p[f],o),u=a(p[f+2],1),f+=3):p[f+3]===`/`&&p[f+1]===` `&&(s=a(p[f],o),c=a(p[f+2],o),u=a(p[f+4],1),f+=5),p.length<=f){r=u*d,o=n=l+r*s+d*c;break}default:throw h()}if(r===0)throw m();i.s=o<0?-1:1,i.n=Math.abs(n),i.d=Math.abs(r)};function l(e,t,n){for(var r=1;t>0;e=e*e%n,t>>=1)t&1&&(r=r*e%n);return r}function u(e,t){for(;t%2==0;t/=2);for(;t%5==0;t/=5);if(t===1)return 0;for(var n=10%t,i=1;n!==1;i++)if(n=n*10%t,i>r)return 0;return i}function d(e,t,n){for(var r=1,i=l(10,n,t),a=0;a<300;a++){if(r===i)return a;r=r*10%t,i=i*10%t}return 0}function f(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function p(e,t){if(c(e,t),this instanceof p)e=f(i.d,i.n),this.s=i.s,this.n=i.n/e,this.d=i.d/e;else return o(i.s*i.n,i.d)}var m=function(){return Error(`Division by Zero`)},h=function(){return Error(`Invalid argument`)},g=function(){return Error(`Parameters must be integer`)};p.prototype={s:1,n:0,d:1,abs:function(){return o(this.n,this.d)},neg:function(){return o(-this.s*this.n,this.d)},add:function(e,t){return c(e,t),o(this.s*this.n*i.d+i.s*this.d*i.n,this.d*i.d)},sub:function(e,t){return c(e,t),o(this.s*this.n*i.d-i.s*this.d*i.n,this.d*i.d)},mul:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.n,this.d*i.d)},div:function(e,t){return c(e,t),o(this.s*i.s*this.n*i.d,this.d*i.n)},clone:function(){return o(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new p(NaN);if(e===void 0)return o(this.s*this.n%this.d,1);if(c(e,t),i.n===0&&this.d===0)throw m();return o(this.s*(i.d*this.n)%(i.n*this.d),i.d*this.d)},gcd:function(e,t){return c(e,t),o(f(i.n,this.n)*f(i.d,this.d),i.d*this.d)},lcm:function(e,t){return c(e,t),i.n===0&&this.n===0?o(0,1):o(i.n*this.n,f(i.n,this.n)*f(i.d,this.d))},ceil:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=10**(e||0),isNaN(this.n)||isNaN(this.d)?new p(NaN):o(Math.round(e*this.s*this.n/this.d),e)},inverse:function(){return o(this.s*this.d,this.n)},pow:function(e,t){if(c(e,t),i.d===1)return i.s<0?o((this.s*this.d)**+i.n,this.n**+i.n):o((this.s*this.n)**+i.n,this.d**+i.n);if(this.s<0)return null;var n=s(this.n),r=s(this.d),a=1,l=1;for(var u in n){if(u===`1`)continue;if(u===`0`){a=0;break}if(n[u]*=i.n,n[u]%i.d===0)n[u]/=i.d;else return null;a*=u**+n[u]}for(var u in r){if(u===`1`)continue;if(r[u]*=i.n,r[u]%i.d===0)r[u]/=i.d;else return null;l*=u**+r[u]}return i.s<0?o(l,a):o(a,l)},equals:function(e,t){return c(e,t),this.s*this.n*i.d===i.s*i.n*this.d},compare:function(e,t){c(e,t);var n=this.s*this.n*i.d-i.s*i.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e||=.001;for(var t=this.abs(),n=t.toContinued(),r=1;r<n.length;r++){for(var i=o(n[r-1],1),a=r-2;a>=0;a--)i=i.inverse().add(n[a]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return c(e,t),!(!(i.n*this.d)||this.n*i.d%(i.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,n+=` `,r%=i),n+=r,n+=`/`,n+=i),n},toLatex:function(e){var t,n=``,r=this.n,i=this.d;return this.s<0&&(n+=`-`),i===1?n+=r:(e&&(t=Math.floor(r/i))>0&&(n+=t,r%=i),n+=`\\frac{`,n+=r,n+=`}{`,n+=i,n+=`}`),n},toContinued:function(){var e,t=this.n,n=this.d,r=[];if(isNaN(t)||isNaN(n))return r;do r.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return r},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return`NaN`;e||=15;var r=u(t,n),i=d(t,n,r),a=this.s<0?`-`:``;if(a+=t/n|0,t%=n,t*=10,t&&(a+=`.`),r){for(var o=i;o--;)a+=t/n|0,t%=n,t*=10;a+=`(`;for(var o=r;o--;)a+=t/n|0,t%=n,t*=10;a+=`)`}else for(var o=e;t&&o--;)a+=t/n|0,t%=n,t*=10;return a}},typeof exports==`object`?(Object.defineProperty(p,`__esModule`,{value:!0}),p.default=p,p.Fraction=p,t.exports=p):n.Fraction=p})(exports)})),Ju=E(qu(),1),Yu=`Fraction`,Xu=[],Zu=Pc(Yu,Xu,()=>(Object.defineProperty(Ju.default,`name`,{value:`Fraction`}),Ju.default.prototype.constructor=Ju.default,Ju.default.prototype.type=`Fraction`,Ju.default.prototype.isFraction=!0,Ju.default.prototype.toJSON=function(){return{mathjs:`Fraction`,n:this.s*this.n,d:this.d}},Ju.default.fromJSON=function(e){return new Ju.default(e)},Ju.default),{isClass:!0}),Qu=`Matrix`,$u=[],ed=Pc(Qu,$u,()=>{function e(){if(!(this instanceof e))throw SyntaxError(`Constructor must be called with the new operator`)}return e.prototype.type=`Matrix`,e.prototype.isMatrix=!0,e.prototype.storage=function(){throw Error(`Cannot invoke storage on a Matrix interface`)},e.prototype.datatype=function(){throw Error(`Cannot invoke datatype on a Matrix interface`)},e.prototype.create=function(e,t){throw Error(`Cannot invoke create on a Matrix interface`)},e.prototype.subset=function(e,t,n){throw Error(`Cannot invoke subset on a Matrix interface`)},e.prototype.get=function(e){throw Error(`Cannot invoke get on a Matrix interface`)},e.prototype.set=function(e,t,n){throw Error(`Cannot invoke set on a Matrix interface`)},e.prototype.resize=function(e,t){throw Error(`Cannot invoke resize on a Matrix interface`)},e.prototype.reshape=function(e,t){throw Error(`Cannot invoke reshape on a Matrix interface`)},e.prototype.clone=function(){throw Error(`Cannot invoke clone on a Matrix interface`)},e.prototype.size=function(){throw Error(`Cannot invoke size on a Matrix interface`)},e.prototype.map=function(e,t){throw Error(`Cannot invoke map on a Matrix interface`)},e.prototype.forEach=function(e){throw Error(`Cannot invoke forEach on a Matrix interface`)},e.prototype[Symbol.iterator]=function(){throw Error(`Cannot iterate a Matrix interface`)},e.prototype.toArray=function(){throw Error(`Cannot invoke toArray on a Matrix interface`)},e.prototype.valueOf=function(){throw Error(`Cannot invoke valueOf on a Matrix interface`)},e.prototype.format=function(e){throw Error(`Cannot invoke format on a Matrix interface`)},e.prototype.toString=function(){throw Error(`Cannot invoke toString on a Matrix interface`)},e},{isClass:!0});function td(e){return Object.keys(e.signatures||{}).reduce(function(e,t){var n=(t.match(/,/g)||[]).length+1;return Math.max(e,n)},-1)}var nd=`DenseMatrix`,rd=[`Matrix`],id=Pc(nd,rd,e=>{var{Matrix:t}=e;function n(e,t){if(!(this instanceof n))throw SyntaxError(`Constructor must be called with the new operator`);if(t&&!Qo(t))throw Error(`Invalid datatype: `+t);if($o(e))e.type===`DenseMatrix`?(this._data=Ps(e._data),this._size=Ps(e._size),this._datatype=t||e._datatype):(this._data=e.toArray(),this._size=e.size(),this._datatype=t||e._datatype);else if(e&&z(e.data)&&z(e.size))this._data=e.data,this._size=e.size,gc(this._data,this._size),this._datatype=t||e.datatype;else if(z(e))this._data=l(e),this._size=mc(this._data),gc(this._data,this._size),this._datatype=t;else if(e)throw TypeError(`Unsupported type of data (`+Ns(e)+`)`);else this._data=[],this._size=[0],this._datatype=t}n.prototype=new t,n.prototype.createDenseMatrix=function(e,t){return new n(e,t)},Object.defineProperty(n,`name`,{value:`DenseMatrix`}),n.prototype.constructor=n,n.prototype.type=`DenseMatrix`,n.prototype.isDenseMatrix=!0,n.prototype.getDataType=function(){return Ec(this._data,Ns)},n.prototype.storage=function(){return`dense`},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(e,t){return new n(e,t)},n.prototype.subset=function(e,t,n){switch(arguments.length){case 1:return r(this,e);case 2:case 3:return a(this,e,t,n);default:throw SyntaxError(`Wrong number of arguments`)}},n.prototype.get=function(e){if(!z(e))throw TypeError(`Array expected`);if(e.length!==this._size.length)throw new B(e.length,this._size.length);for(var t=0;t<e.length;t++)V(e[t],this._size[t]);for(var n=this._data,r=0,i=e.length;r<i;r++){var a=e[r];V(a,n.length),n=n[a]}return n},n.prototype.set=function(e,t,n){if(!z(e))throw TypeError(`Array expected`);if(e.length<this._size.length)throw new B(e.length,this._size.length,`<`);var r,i,a,o=e.map(function(e){return e+1});c(this,o,n);var s=this._data;for(r=0,i=e.length-1;r<i;r++)a=e[r],V(a,s.length),s=s[a];return a=e[e.length-1],V(a,s.length),s[a]=t,this};function r(e,t){if(!os(t))throw TypeError(`Invalid index`);var r=t.isScalar();if(r)return e.get(t.min());var a=t.size();if(a.length!==e._size.length)throw new B(a.length,e._size.length);for(var o=t.min(),s=t.max(),c=0,l=e._size.length;c<l;c++)V(o[c],e._size[c]),V(s[c],e._size[c]);return new n(i(e._data,t,a.length,0),e._datatype)}function i(e,t,n,r){var a=r===n-1,o=t.dimension(r);return a?o.map(function(t){return V(t,e.length),e[t]}).valueOf():o.map(function(a){V(a,e.length);var o=e[a];return i(o,t,n,r+1)}).valueOf()}function a(e,t,n,r){if(!t||t.isIndex!==!0)throw TypeError(`Invalid index`);var i=t.size(),a=t.isScalar(),s;if($o(n)?(s=n.size(),n=n.valueOf()):s=mc(n),a){if(s.length!==0)throw TypeError(`Scalar expected`);e.set(t.min(),n,r)}else{if(!Is(s,i))try{n=s.length===0?jc([n],i):jc(n,i),s=mc(n)}catch{}if(i.length<e._size.length)throw new B(i.length,e._size.length,`<`);if(s.length<i.length){for(var l=0,u=0;i[l]===1&&s[l]===1;)l++;for(;i[l]===1;)u++,l++;n=Cc(n,i.length,u,s)}if(!Is(i,s))throw new B(i,s,`>`);var d=t.max().map(function(e){return e+1});c(e,d,r);var f=i.length,p=0;o(e._data,t,n,f,p)}return e}function o(e,t,n,r,i){var a=i===r-1,s=t.dimension(i);a?s.forEach(function(t,r){V(t),e[t]=n[r[0]]}):s.forEach(function(a,s){V(a),o(e[a],t,n[s[0]],r,i+1)})}n.prototype.resize=function(e,t,n){if(!es(e))throw TypeError(`Array or Matrix expected`);var r=e.valueOf().map(e=>Array.isArray(e)&&e.length===1?e[0]:e),i=n?this.clone():this;return s(i,r,t)};function s(e,t,n){if(t.length===0){for(var r=e._data;z(r);)r=r[0];return r}return e._size=t.slice(0),e._data=_c(e._data,e._size,n),e}n.prototype.reshape=function(e,t){var n=t?this.clone():this;n._data=yc(n._data,e);var r=n._size.reduce((e,t)=>e*t);return n._size=bc(e,r),n};function c(e,t,n){for(var r=e._size.slice(0),i=!1;r.length<t.length;)r.push(0),i=!0;for(var a=0,o=t.length;a<o;a++)t[a]>r[a]&&(r[a]=t[a],i=!0);i&&s(e,r,n)}n.prototype.clone=function(){var e=new n({data:Ps(this._data),size:Ps(this._size),datatype:this._datatype});return e},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(e){var t=this,r=td(e),i=function n(i,a){return z(i)?i.map(function(e,t){return n(e,a.concat(t))}):r===1?e(i):r===2?e(i,a):e(i,a,t)},a=i(this._data,[]),o=this._datatype===void 0?void 0:Ec(a,Ns);return new n(a,o)},n.prototype.forEach=function(e){var t=this,n=function n(r,i){z(r)?r.forEach(function(e,t){n(e,i.concat(t))}):e(r,i,t)};n(this._data,[])},n.prototype[Symbol.iterator]=function*(){var e=function*e(t,n){if(z(t))for(var r=0;r<t.length;r++)yield*e(t[r],n.concat(r));else yield{value:t,index:n}};yield*e(this._data,[])},n.prototype.rows=function(){var e=[],t=this.size();if(t.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);var r=this._data;for(var i of r)e.push(new n([i],this._datatype));return e},n.prototype.columns=function(){var e=this,t=[],r=this.size();if(r.length!==2)throw TypeError(`Rows can only be returned for a 2D matrix.`);for(var i=this._data,a=function(r){var a=i.map(e=>[e[r]]);t.push(new n(a,e._datatype))},o=0;o<r[1];o++)a(o);return t},n.prototype.toArray=function(){return Ps(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.format=function(e){return oc(this._data,e)},n.prototype.toString=function(){return oc(this._data)},n.prototype.toJSON=function(){return{mathjs:`DenseMatrix`,data:this._data,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(e){if(e){if(Jo(e)&&(e=e.toNumber()),!R(e)||!Ws(e))throw TypeError(`The parameter k must be an integer number`)}else e=0;for(var t=e>0?e:0,r=e<0?-e:0,i=this._size[0],a=this._size[1],o=Math.min(i-r,a-t),s=[],c=0;c<o;c++)s[c]=this._data[c+r][c+t];return new n({data:s,size:[o],datatype:this._datatype})},n.diagonal=function(e,t,r,i){if(!z(e))throw TypeError(`Array expected, size parameter`);if(e.length!==2)throw Error(`Only two dimensions matrix are supported`);if(e=e.map(function(e){if(Jo(e)&&(e=e.toNumber()),!R(e)||!Ws(e)||e<1)throw Error(`Size values must be positive integers`);return e}),r){if(Jo(r)&&(r=r.toNumber()),!R(r)||!Ws(r))throw TypeError(`The parameter k must be an integer number`)}else r=0;var a=r>0?r:0,o=r<0?-r:0,s=e[0],c=e[1],l=Math.min(s-o,c-a),u;if(z(t)){if(t.length!==l)throw Error(`Invalid value array length`);u=function(e){return t[e]}}else if($o(t)){var d=t.size();if(d.length!==1||d[0]!==l)throw Error(`Invalid matrix length`);u=function(e){return t.get([e])}}else u=function(){return t};i||=Jo(u(0))?u(0).mul(0):0;var f=[];if(e.length>0){f=_c(f,e,i);for(var p=0;p<l;p++)f[p+o][p+a]=u(p)}return new n({data:f,size:[s,c]})},n.fromJSON=function(e){return new n(e)},n.prototype.swapRows=function(e,t){if(!R(e)||!Ws(e)||!R(t)||!Ws(t))throw Error(`Row index must be positive integers`);if(this._size.length!==2)throw Error(`Only two dimensional matrix is supported`);return V(e,this._size[0]),V(t,this._size[0]),n._swapRows(e,t,this._data),this},n._swapRows=function(e,t,n){var r=n[e];n[e]=n[t],n[t]=r};function l(e){return $o(e)?l(e.valueOf()):z(e)?e.map(l):e}return n},{isClass:!0});function ad(e,t,n){return e&&typeof e.map==`function`?e.map(function(e){return ad(e,t,n)}):t(e)}var od=`isNumeric`,sd=[`typed`],cd=Pc(od,sd,e=>{var{typed:t}=e;return t(od,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>t=>ad(t,e))})}),ld=`hasNumericValue`,ud=[`typed`,`isNumeric`],dd=Pc(ld,ud,e=>{var{typed:t,isNumeric:n}=e;return t(ld,{boolean:()=>!0,string:function(e){return e.trim().length>0&&!isNaN(Number(e))},any:function(e){return n(e)}})}),fd=Lu({config:Hs}),pd=Ku({}),md=Zu({}),hd=ed({}),gd=id({Matrix:hd}),_d=Zc({BigNumber:fd,Complex:pd,DenseMatrix:gd,Fraction:md}),vd=cd({typed:_d}),yd=dd({isNumeric:vd,typed:_d});const bd=e=>{let t=Number(e);return Number.isNaN(t)?!1:t>=120&&t<=36e4},xd=e=>{let t=Number(e),n=Date.now();if(Number.isNaN(t))return n+Wo;if(!bd(t)&&a(t))return Go(t);if(bd(t))return n+t;{let e=t*Ho;return n+e}},Sd=`ratelimitlimit`,Cd=`ratelimitremaining`,wd=`ratelimitreset`,Td=`ratelimitconcurrencylimit`,Ed=`ratelimitconcurrencyremaining`,Dd=`ratelimitconcurrencyreset`,Od=e=>{let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase().replace(/^x-/,``).replace(/concurren.+-/g,`concurrency-`).replace(/-/g,``),i=yd(r)?Number(r):null;t[e]=i}return t},kd=e=>{let t=Od(e);return{rateLimitLimit:t[Sd],rateLimitRemaining:t[Cd],rateLimitReset:xd(t[wd]),concurrencyLimit:t[Td],concurrencyRemaining:t[Ed],concurrencyReset:xd(t[Dd])}},Ad=e=>{let{accountSecureId:t,service:n,resource:r,subResource:i,childResource:a,action:s,behaviours:c}=e??{};return[t,n,r,s].some(o)?null:[t,n,r,i,a,s,...c??[]].filter(Boolean).join(`-`)},jd=(e,t=zo,n=Ro)=>{let r=Date.now();return a(e)||s(e)?Md(Number(e),r,t,n):Qo(e)&&e!==``?Nd(e,r,t,n):n},Md=(e,t,n=zo,r=Ro)=>{if(e<n)return e;let i=Go(e);if(i>t){let e=Math.floor((i-t)/Ho);return e>0&&e<n?e:r}return r},Nd=(e,t,n=zo,r=Ro)=>{if(Uo.test(e)){let t=parseFloat(e);return t>0&&t<n?t:r}let i=new Date(e);if(Number.isNaN(i.getTime()))return r;let a=i.getTime();if(a>t){let e=Math.floor((a-t)/Ho);return e>0&&e<n?e:r}return r};let Pd=function(e){return e.RateLimiterReleaseRequestFailed=`RateLimiterReleaseRequestFailed`,e}({});const Fd=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>{let a=async a=>{let{response:o,config:s}=a,c=s?.signal;if(c?.aborted)return Promise.reject(Po(`Request aborted`,s,`ERR_CANCELED`,o));let{status:l,retryAfter:d}=Id(o,i,r,n);if(l===429&&u(s)){let r=jd(d);if(s._retryCount>=Bo)return n?.warning({category:`http-transport`,message:`Max retries exceeded for ${s?.url}. Aborting.`,context:{...i??{},retryAfterHeader:d,retryAfterAsNumber:r}}),Promise.reject(a);let c=s._retryCount??0,l={...s,_retryCount:c+1},u=d?r*Ho:t(l._retryCount);return n?.debug({category:`http-transport`,message:`Received 429 error from ${s?.url}`,context:{...i??{},retryAfterHeader:d,calculatedRetryAfter:u}}),await Fo(u*1e3,s,o),e?.request(l)}return Promise.reject(a)};return a},Id=(e,t,n,r)=>{let{provider:i}=t??{},{status:a,headers:s,data:l}=e??{},{retryafter:d}=Od(s??{});if(o(i)||o(e))return r?.warning({category:`http-transport`,message:`Invalid parameters for convertError`,context:{...t,responseIsMissing:o(e),providerIsMissing:o(i),status:e?.status??`undefined`,statusText:e?.statusText??`undefined`,retryafter:d??`undefined`}}),{status:a,retryAfter:d};let f=n?.rateLimits?.mappedRateLimitErrors;if(u(f)&&u(l))for(let e of f){let{errorStatus:t,errorMessagePath:n,errorMessage:r,retryAfterPath:i,retryAfterUnit:o,retryAfterValue:u}=e;if(t!==a)continue;let f=n??`message`,p=c(l)?_.query(l,f)[0]:l,m=Ld(p,r);if(t===a&&m){let e=u??Rd(s,i),t=zd(e,o);return{status:429,retryAfter:d??t}}}return{status:a,retryAfter:d}},Ld=(e,t)=>t instanceof RegExp?t.test(e??``):e?.includes(t)??!1,Rd=(e,t)=>u(t)&&u(e)?_.query(e,t)[0]:null,zd=(e,t=`seconds`)=>u(e)?Bd(e,t):null,Bd=(e,t)=>{if(t===`seconds`)return typeof e==`string`?parseFloat(e):e;if(t===`milliseconds`){let t=typeof e==`string`?parseFloat(e):e;return t/Ho}if(t===`date`){let t=typeof e==`string`&&!isNaN(Number(e))?parseFloat(e):e,n=new Date(t);if(isNaN(n.getTime()))throw Error(`Invalid date value`);return n.getTime()}throw Error(`Invalid type`)},Vd=`rateLimitErrorInterceptor`,Hd=({axiosInstance:e,logger:n,requestConfig:r,context:i})=>{let a=async a=>{let{response:s,config:c}=a,l=c?.signal;if(o(i)||o(c))return n?.warning({category:`HttpClient`,message:`No context or config for this response - that doesn't seem right.`,context:{interceptor:Vd,...c,headers:void 0}}),Promise.reject(a);let{requestId:d,targetConcurrencyKey:f,leaseSubscription:p,setRemovalSubscription:m}=c?.requestMetadata??{},h=await nt.getInstance(),g=u(d)&&u(f)?await h.releaseRequest(d,f):!1;if(!g&&u(c?.requestMetadata)&&n?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{...i,interceptor:Vd,requestId:d,targetConcurrencyKey:f,leaseSubscription:p,setRemovalSubscription:m},code:Pd.RateLimiterReleaseRequestFailed}),l?.aborted)return Promise.reject(Po(`Request aborted`,c,`ERR_CANCELED`,s));let{status:_,retryAfter:v}=Id(s,i,r,n);if(_===429&&u(c)){let r=jd(v);if(c._retryCount>=Bo)return n?.warning({category:`HttpClient`,message:`Max retries exceeded for ${c.url}. Aborting.`,context:{...i??{},...c.requestMetadata??{},retryAfterHeader:v,retryAfterAsNumber:r}}),Promise.reject(a);let o=c?._retryCount??0,l={...c,_retryCount:o+1},u=v?r*Ho:t(l._retryCount);return n?.debug({category:`HttpClient`,message:`Received 429 error from ${c.url}`,context:{...i,retryAfterHeader:v,calculatedRetryAfter:u}}),await Fo(u*1e3,c,s),e?.request(l)}return Promise.reject(a)};return a},Ud=`rateLimitResponseInterceptor`,Wd=({logger:e,context:t})=>{let n=async n=>{let r=n?.config,i=r?.signal;if(o(t))e?.warning({category:`HttpClient`,message:`No context for this response - that doesn't seem right.`,context:{...r,interceptor:Ud,headers:void 0}});else{let t=n?.headers;if(u(t)){let n=kd(t);e?.debug({category:`HttpClient`,message:`Rate limit headers extracted`,context:{interceptor:Ud,rateLimitHeaders:n}})}let{requestId:a,targetConcurrencyKey:o,leaseSubscription:s,setRemovalSubscription:c}=r?.requestMetadata??{},l=await nt.getInstance(),d=await l.releaseRequest(a,o);if(d||e?.error({category:`HttpClient`,message:`Failed to release request from concurrency manager`,context:{interceptor:Ud,requestId:a,targetConcurrencyKey:o,leaseSubscription:s,setRemovalSubscription:c},code:Pd.RateLimiterReleaseRequestFailed}),i?.aborted)return Promise.reject(Po(`Request aborted`,r,`ERR_CANCELED`,n))}return n};return n},Gd=e=>(e.validateStatus??=e=>e>=200&&e<300,e),Kd=[{onFulfilled:Gd,onRejected:null,options:void 0}],qd=[{onFulfilled:null,onRejected:Fd},{onFulfilled:null,onRejected:xo}],Jd=[{onFulfilled:Gd,onRejected:null,options:void 0},{onFulfilled:Lo,onRejected:null,options:void 0}],Yd=[{onFulfilled:Wd,onRejected:Hd},{onFulfilled:null,onRejected:xo}];let Xd=function(e){return e.HttpTransportInstanceCreateError=`HttpTransportInstanceCreateError`,e}({});const Zd=async({logger:e,redisClientConfig:t,context:n,requestConfig:r,httpsAgentConfig:i}={})=>{let a,{NODE_ENV:s}=process.env,c=n?.behaviours??[`CONCURRENCY`,`RETRY`];try{if(a=c.includes(`RETRY`)?$d(e,n):Qd(e,n),o(n?.service)||o(n?.organizationId)||s===`test`||o(t)||o(e))return a;await No.getInstance(t,e);let l=await No.isReady(),d=await nt.getInstance(t,e),f=await d.isRedisConfigured(),p=[],m=[];if(c.includes(`CONCURRENCY`)){if(!f)throw Error(`Concurrency Manager cannot connect to Redis. Cannot create advanced transport instance.`);if(!l)throw Error(`RateLimitManager is not ready. Cannot create advanced transport instance.`);p.push(...Jd),m.push(...Yd)}let h=Ad(n);if(o(h))return e?.warning({category:`http-transport`,message:`Unable to create a key for transport instance - Invalid state. Using base default instance.`,context:{...n,defaultInstanceInitialized:u(a)}}),a;let g=await bo.get(h);if(u(g))return g;let _={interceptors:{requestConfigs:p,responseConfigs:m},instanceConfig:{maxBodyLength:1/0},logger:e,context:n,requestConfig:r,httpsAgentConfig:i},v=_o.createInstance(_);return e?.debug({category:`http-transport`,message:`Creating new Axios instance and caching it for key: [${h}]`,context:{...n}}),await bo.set(h,v),v}catch(t){return e?.error({category:`http-transport`,message:`Failed to create advanced transport instance. Using default instance.`,context:{...n,usingDefaultInstance:u(a)},error:t,code:Xd.HttpTransportInstanceCreateError}),u(a)?a:ef()}},Qd=(e,t)=>{let n={instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return _o.createInstance(n)??ef()},$d=(e,t)=>{let n={interceptors:{requestConfigs:Kd,responseConfigs:qd},instanceConfig:{maxBodyLength:1/0},logger:e,context:t};return _o.createInstance(n)??ef()},ef=()=>{let e=f.create({maxBodyLength:1/0});return e};var tf=w(((exports,t)=>{t.exports=n;function n(e={}){let{ERR_PATHS_MUST_BE_STRINGS:t=()=>`fast-redact - Paths must be (non-empty) strings`,ERR_INVALID_PATH:n=e=>`fast-redact – Invalid path (${e})`}=e;return function({paths:e}){e.forEach(e=>{if(typeof e!=`string`)throw Error(t());try{if(/〇/.test(e))throw Error();let t=(e[0]===`[`?``:`.`)+e.replace(/^\*/,`〇`).replace(/\.\*/g,`.〇`).replace(/\[\*\]/g,`[〇]`);if(/\n|\r|;/.test(t)||/\/\*/.test(t))throw Error();Function(`
|
|
215
215
|
'use strict'
|
|
216
216
|
const o = new Proxy({}, { get: () => o, set: () => { throw Error() } });
|
|
217
217
|
const 〇 = null;
|
|
218
218
|
o${t}
|
|
219
|
-
if ([o${t}].length !== 1) throw Error()`)()}catch{throw Error(n(e))}})}}}),
|
|
219
|
+
if ([o${t}].length !== 1) throw Error()`)()}catch{throw Error(n(e))}})}}})),nf=w(((exports,t)=>{t.exports=/[^.[\]]+|\[((?:.)*?)\]/g})),rf=w(((exports,t)=>{let n=nf();t.exports=r;function r({paths:e}){let t=[];var r=0;let i=e.reduce(function(e,i,a){var o=i.match(n).map(e=>e.replace(/'|"|`/g,``));let s=i[0]===`[`;o=o.map(e=>e[0]===`[`?e.substr(1,e.length-2):e);let c=o.indexOf(`*`);if(c>-1){let e=o.slice(0,c),n=e.join(`.`),i=o.slice(c+1,o.length),a=i.length>0;r++,t.push({before:e,beforeStr:n,after:i,nested:a})}else e[i]={path:o,val:void 0,precensored:!1,circle:``,escPath:JSON.stringify(i),leadingBracket:s};return e},{});return{wildcards:t,wcLen:r,secret:i}}})),af=w(((exports,t)=>{let n=nf();t.exports=r;function r({secret:e,serialize:t,wcLen:n,strict:r,isCensorFct:c,censorFctTakesPath:l},u){let d=Function(`o`,`
|
|
220
220
|
if (typeof o !== 'object' || o == null) {
|
|
221
221
|
${s(r,t)}
|
|
222
222
|
}
|
|
@@ -268,7 +268,7 @@ var ul=9e15,dl=1e9,fl=`0123456789abcdef`,pl=`2.302585092994045684017991454684364
|
|
|
268
268
|
var s = this.serialize(o)
|
|
269
269
|
this.restore(o)
|
|
270
270
|
return s
|
|
271
|
-
`}function s(e,t){return e===!0?`throw Error('fast-redact: primitives cannot be redacted')`:t===!1?`return o`:`return this.serialize(o)`}}),
|
|
271
|
+
`}function s(e,t){return e===!0?`throw Error('fast-redact: primitives cannot be redacted')`:t===!1?`return o`:`return this.serialize(o)`}})),sf=w(((exports,t)=>{t.exports={groupRedact:r,groupRestore:n,nestedRedact:a,nestedRestore:i};function n({keys:e,values:t,target:n}){if(n==null||typeof n==`string`)return;let r=e.length;for(var i=0;i<r;i++){let r=e[i];n[r]=t[i]}}function r(e,t,n,r,i){let a=c(e,t);if(a==null||typeof a==`string`)return{keys:null,values:null,target:a,flat:!0};let o=Object.keys(a),s=o.length,l=t.length,u=i?[...t]:void 0,d=Array(s);for(var f=0;f<s;f++){let e=o[f];d[f]=a[e],i?(u[l]=e,a[e]=n(a[e],u)):r?a[e]=n(a[e]):a[e]=n}return{keys:o,values:d,target:a,flat:!0}}function i(e){for(let t=0;t<e.length;t++){let{target:n,path:r,value:i}=e[t],a=n;for(let e=r.length-1;e>0;e--)a=a[r[e]];a[r[0]]=i}}function a(e,t,n,r,i,a,o){let l=c(t,n);if(l==null)return;let u=Object.keys(l),d=u.length;for(var f=0;f<d;f++){let t=u[f];s(e,l,t,n,r,i,a,o)}return e}function o(e,t){return e==null?!1:`hasOwn`in Object?Object.hasOwn(e,t):Object.prototype.hasOwnProperty.call(e,t)}function s(e,t,n,r,i,a,s,c){let p=i.length,m=p-1,h=n;var g=-1,_,v,y,b=null,x=null,S,C,ee=!1,te=0,w=0,T=u();if(y=_=t[n],typeof _==`object`){for(;_!=null&&++g<p&&(w+=1,n=i[g],b=y,!(n!==`*`&&!x&&!(typeof _==`object`&&n in _)));)if(!(n===`*`&&(x===`*`&&(ee=!0),x=n,g!==m))){if(x){let u=Object.keys(_);for(var E=0;E<u.length;E++){let p=u[E];if(C=_[p],S=n===`*`,ee)T=d(T,p,w),te=g,y=l(C,te-1,n,r,i,a,s,c,h,_,v,y,S,p,g,m,T,e,t[h],w+1);else if(S||typeof C==`object`&&C&&n in C){if(y=S?C:C[n],v=g===m?s?c?a(y,[...r,h,...i]):a(y):a:y,S){let n=f(d(T,p,w),y,t[h]);e.push(n),_[p]=v}else if(C[n]!==v)if(v===void 0&&a!==void 0||o(C,n)&&v===y)T=d(T,p,w);else{T=d(T,p,w);let r=f(d(T,n,w+1),y,t[h]);e.push(r),C[n]=v}}}x=null}else{if(y=_[n],T=d(T,n,w),v=g===m?s?c?a(y,[...r,h,...i]):a(y):a:y,!(o(_,n)&&v===y||v===void 0&&a!==void 0)){let r=f(T,y,t[h]);e.push(r),_[n]=v}_=_[n]}if(typeof _!=`object`)break}}}function c(e,t){for(var n=-1,r=t.length,i=e;i!=null&&++n<r;)i=i[t[n]];return i}function l(e,t,n,r,i,a,s,c,u,p,m,h,g,_,v,y,b,x,S,C){if(t===0&&(g||typeof e==`object`&&e&&n in e)){if(h=g?e:e[n],m=v===y?s?c?a(h,[...r,u,...i]):a(h):a:h,g){let e=f(b,h,S);x.push(e),p[_]=m}else if(e[n]!==m&&!(m===void 0&&a!==void 0||o(e,n)&&m===h)){let t=f(d(b,n,C+1),h,S);x.push(t),e[n]=m}}for(let o in e)typeof e[o]==`object`&&(b=d(b,o,C),l(e[o],t-1,n,r,i,a,s,c,u,p,m,h,g,_,v,y,b,x,S,C+1))}function u(){return{parent:null,key:null,children:[],depth:0}}function d(e,t,n){if(e.depth===n)return d(e.parent,t,n);var r={parent:e,key:t,depth:n,children:[]};return e.children.push(r),r}function f(e,t,n){let r=e,i=[];do i.push(r.key),r=r.parent;while(r.parent!=null);return{path:i,value:t,target:n}}})),cf=w(((exports,t)=>{let{groupRestore:n,nestedRestore:r}=sf();t.exports=i;function i(){return function(){if(this.restore){this.restore.state.secret=this.secret;return}let{secret:e,wcLen:t}=this,i=Object.keys(e),s=a(e,i),c=t>0,l=c?{secret:e,groupRestore:n,nestedRestore:r}:{secret:e};this.restore=Function(`o`,o(s,i,c)).bind(l),this.restore.state=l}}function a(e,t){return t.map(t=>{let{circle:n,escPath:r,leadingBracket:i}=e[t],a=i?``:`.`,o=n?`o.${n} = secret[${r}].val`:`o${a}${t} = secret[${r}].val`,s=`secret[${r}].val = undefined`;return`
|
|
272
272
|
if (secret[${r}].val !== undefined) {
|
|
273
273
|
try { ${o} } catch (e) {}
|
|
274
274
|
${s}
|
|
@@ -290,4 +290,4 @@ var ul=9e15,dl=1e9,fl=`0123456789abcdef`,pl=`2.302585092994045684017991454684364
|
|
|
290
290
|
${r}
|
|
291
291
|
${e}
|
|
292
292
|
return o
|
|
293
|
-
`}}),vf=T((exports,t)=>{t.exports=n;function n(e){let{secret:t,censor:n,compileRestore:r,serialize:i,groupRedact:a,nestedRedact:o,wildcards:s,wcLen:c}=e,l=[{secret:t,censor:n,compileRestore:r}];return i!==!1&&l.push({serialize:i}),c>0&&l.push({groupRedact:a,nestedRedact:o,wildcards:s,wcLen:c}),Object.assign(...l)}}),yf=T((exports,t)=>{let n=ff(),r=mf(),i=hf(),a=_f(),{groupRedact:o,nestedRedact:s}=gf(),c=vf(),l=pf(),u=n(),d=e=>e;d.restore=d;let f=`[REDACTED]`;p.rx=l,p.validator=n,t.exports=p;function p(e={}){let t=Array.from(new Set(e.paths||[])),n=`serialize`in e&&(e.serialize===!1||typeof e.serialize==`function`)?e.serialize:JSON.stringify,l=e.remove;if(l===!0&&n!==JSON.stringify)throw Error(`fast-redact – remove option may only be set when serializer is JSON.stringify`);let p=l===!0?void 0:`censor`in e?e.censor:f,m=typeof p==`function`,h=m&&p.length>1;if(t.length===0)return n||d;u({paths:t,serialize:n,censor:p});let{wildcards:g,wcLen:_,secret:v}=r({paths:t,censor:p}),y=a(),b=`strict`in e?e.strict:!0;return i({secret:v,wcLen:_,serialize:n,strict:b,isCensorFct:m,censorFctTakesPath:h},c({secret:v,censor:p,compileRestore:y,serialize:n,groupRedact:o,nestedRedact:s,wildcards:g,wcLen:_}))}}),bf=E(yf(),1);const xf=[`client_secret`,`access_token`,`refresh_token`,`api_key`,`password`,`job_board_token`,`private_key`,`certificate`,`service_user_token`,`key_id`,`secret_key`,`provhash`,`admin_key`,`session_key`,`id_token`,`authorization`,`bh_rest_token`,`external_trigger_token`,`tempauth`],Sf=[`req.headers.authorization`,`req.headers.cookie`,`req.headers.cookies`,`req.headers["set-cookie"]`,`req.headers["set-cookies"]`,`req.headers.httpsAgent.options.cert`,`req.headers.httpsAgent.options.key`,`req.headers["x-stackone-external-trigger-token"]`,`error.config.headers.authorization`,`error.config.data`,`error.config.headers.cookie`,`error.config.headers.cookies`,`error.config.headers["set-cookie"]`,`error.config.headers["set-cookies"]`,`error.config.httpsAgent.options.cert`,`error.config.httpsAgent.options.key`,`err.config.headers.authorization`,`err.config.data`,`err.config.headers.cookie`,`err.config.headers.cookies`,`err.config.headers["set-cookie"]`,`err.config.headers["set-cookies"]`,`err.config.httpsAgent.options.cert`,`err.config.httpsAgent.options.key`,`res.headers.authorization`,`res.headers.cookie`,`res.headers.cookies`,`res.headers["set-cookie"]`,`res.headers["set-cookies"]`,`res.headers.httpsAgent.options.cert`,`res.headers.httpsAgent.options.key`,`context.credentials`,...xf],Cf=`**redacted**`;let wf=function(e){return e.FULL=`FULL`,e.PARTIAL=`PARTIAL`,e}({});const Tf=e=>Cf,Ef=e=>typeof e==`string`?e.startsWith(Cf)?e:e.length<10?Cf:`${Cf}${e.slice(-5)}`:Cf,Df=(e=[],t=!0)=>{if(!t)return[];let n=e.map(e=>kf(e));return[...e,...n]},Of=(e=[],t=!0)=>{if(!t)return[];let n=new Set;return e.forEach(e=>{if(n.add(e),e.includes(`_`)){let t=e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase());n.add(t)}else{let t=e.replace(/([A-Z])/g,`_$1`).toLowerCase();n.add(t)}}),Array.from(n)},kf=e=>{let t=jf(e);return t||Af(e)},Af=e=>{let t=e.split(`.`);if(t.length<2)return Mf(e);let n=t.pop()??``,r=Mf(n);return[...t,r].join(`.`)},jf=e=>{let t=e.lastIndexOf(`[`),n=e.indexOf(`]`,t);if(t===-1||n===-1)return;let r=e.slice(t,n+1),i=r.replace(/(["'])([^"']*)(["'])/g,(e,t,n)=>n?t+Mf(n)+t:t+t);return`${e.slice(0,t)}${i}${e.slice(n+1)}`},Mf=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,Nf=Df(Sf),Pf=Of(xf),Ff={[wf.FULL]:Tf,[wf.PARTIAL]:Ef},If={[wf.FULL]:(0,bf.default)({paths:Nf,serialize:!1,censor:Ff[wf.FULL]}),[wf.PARTIAL]:(0,bf.default)({paths:Nf,serialize:!1,censor:Ff[wf.PARTIAL]})},Lf=(t,n=wf.FULL)=>s(t)||typeof t!=`object`||!t?t:If[n](e(t)),Rf=(e,t=wf.FULL,n)=>{if(!s(e))try{let n=new URL(e),r=[...n.searchParams].reduce((e,[n,r])=>{let i=n.toLowerCase();return e.set(n,Pf.some(e=>e.toLowerCase()===i)?Ff[t](r):r),e},new URLSearchParams);return`${n.origin}${n.pathname}${r.toString()?`?`+r:``}${n.hash}`}catch(t){return n?.warning({message:`Invalid URL provided, unable to redact`,context:{value:e,error:t},category:`redactUrl`}),e}},zf=(e,t=wf.FULL,n)=>{if(!s(e))try{let[n,r]=e.split(`?`);if(!r)return e;let i=[...new URLSearchParams(r)].reduce((e,[n,r])=>{let i=n.toLowerCase();return e.set(n,Pf.some(e=>e.toLowerCase()===i)?Ff[t](r):r),e},new URLSearchParams);return`${n}?${i}`}catch(t){return n?.warning({message:`Invalid path provided, unable to redact`,context:{value:e,error:t},category:`redactPath`}),e}},Bf=(e,t=wf.FULL)=>{if(!s(e))return typeof e==`string`?Ff[t](e):Object.entries(e).reduce((e,[n,r])=>(e[n]=Pf.some(e=>e.toLowerCase()===n.toLowerCase())?Ff[t](r):r,e),{})};var Vf=class e{#transportFactory;#getRedisClient;#logger;#redisClientConfig;#errorMappingFn;#redisClient;constructor({transportFactory:e=cf,getRedisClient:t=A,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.#transportFactory=e,this.#getRedisClient=t,this.#logger=n,this.#redisClientConfig=r,this.#errorMappingFn=i}#generateCacheKey({url:e,payload:t,method:n,context:r}){let a=20;if(!r?.accountSecureId||r.accountSecureId.length<a||!e||!n)return null;let o=t?i(t):``;return`${r.accountSecureId}-${n.toUpperCase()}${o}-${e}`}async#getCachedResponse({url:t,payload:n,method:r,cacheTTL:i,context:a}){if(!this.#redisClient||!i||i<=0)return null;let o=this.#generateCacheKey({url:t,payload:n,method:r,context:a});if(!o)return null;let s=await this.#redisClient.getData(o);return s?(this.#logger?.debug({category:e.name,message:`Cache hit for key [${o}].`}),s):(this.#logger?.debug({category:e.name,message:`Cache miss for key [${o}].`}),null)}async#cacheResponse({url:t,payload:n,method:r,cacheTTL:i,context:a,response:o}){if(!this.#redisClient||!i||i<=0)return!1;let s=this.#generateCacheKey({url:t,payload:n,method:r,context:a});return s?(this.#logger?.debug({category:e.name,message:`Caching result for key [${s}].`}),this.#redisClient.setData({key:s,value:o,cacheTTL:i*60})):!1}async request({headers:t={},url:n,method:r=`get`,maxRedirects:i=0,responseType:a,cacheTTL:o,context:c,traceId:l,payload:u,httpsAgent:f,httpAgent:p}){try{d(this.#redisClientConfig)&&s(this.#redisClient)&&(this.#redisClient=await this.#getRedisClient(this.#redisClientConfig,this.#logger));let e=this.#normalizeHeaders(t),m=this.#getSafePayload(u,t),h=await this.#getCachedResponse({url:n,payload:m,method:r,cacheTTL:o,context:c});if(h)return{...h,responseTime:new Date};let g=Eo.getInstance(),_=d(l)?await g.get(l):null,v=_?.signal,y=await this.#transportFactory({redisClientConfig:this.#redisClientConfig,logger:this.#logger,context:c}),b=await y.request({headers:e,url:n,method:r,maxRedirects:i,responseType:a,data:m,httpsAgent:f,httpAgent:p,signal:v}),x={data:b.data,status:b.status,body:m,method:r,headers:this.#extractAxiosHeaders(b.headers),requestUrl:n,responseType:b?.config?.responseType,responseTime:new Date};return await this.#cacheResponse({url:n,payload:m,method:r,cacheTTL:o,context:c,response:x}),x}catch(t){let i=t;i.url=Rf(n),this.#logger?.warning({category:e.name,message:`Request error [${r?.toUpperCase()} ${i.url}]: ${i.message}.`,error:i});let a=this.#mapErrorToHttpException(i);throw d(a)?a:t}}async get({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a}){return this.request({url:t,method:`get`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o})}#normalizeHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#extractAxiosHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#isFormUrlEncoded(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#getSafePayload(e,t){if(!(s(e)||l(e)&&Object.keys(e).length===0))return this.#isFormUrlEncoded(t)?y.stringify(e):e}#mapErrorToHttpException(e){if(m(e)&&this.#errorMappingFn)return this.#errorMappingFn(e)}};const Hf=(e,t,n)=>new Vf({redisClientConfig:e,logger:t,errorMappingFn:n});var Uf=class{static httpClientInstance=null;static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=Hf}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const Wf=[`get`,`post`,`put`,`delete`,`patch`],Gf=e=>e.reduce((e,t)=>(Array.isArray(e[t.in][t.name])?e[t.in][t.name]=e[t.in][t.name].concat(t.value):typeof e[t.in][t.name]==`object`&&typeof t.value==`object`?e[t.in][t.name]={...e[t.in][t.name],...t.value}:e[t.in][t.name]=t.in===`body`?t.value:String(t.value),e),{query:{},body:{},headers:{}}),Kf=[`query`,`body`,`headers`],qf=(e,t)=>{if(s(t)||t?.length===0||s(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=b(n,e)===!0;if(s(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??So[t.targetStatus]??`Unknown error`}}return e},Jf=e=>d(e)&&e>=200&&e<=299,Yf=e=>d(e)&&e>=400&&e<=599,Xf=e=>d(e)&&e>=100&&e<=199;var Zf=class{async performRequest({httpClient:e,url:t,method:n,headers:r,body:i,customErrorConfigs:a}){let o;try{o=await e?.request({method:n,url:t,headers:r,maxRedirects:0,payload:i})}catch(e){if(s(e?.response))throw e;o=e.response}let c=qf(o,a);if(Yf(c?.status))throw new Co(c,c.message);return c}},Qf=class{static build(e=`rest`){if(e===`rest`)return new Zf;throw Error(`Unknown request client type: ${e}`)}};export{xo as CUSTOM_ERROR_CONFIG_SCHEMA,nt as ConcurrencyManager,ye as EventClient,Vf as HttpClient,Uf as HttpClientManager,So as HttpErrorMessages,Wf as HttpMethods,Co as HttpResponseError,wo as HttpTransportFactory,Eo as InstanceManager,ie as LockManager,he as MemoryStore,Ie as QueueManager,Bo as RateLimitManager,be as RedisClient,Qf as RequestClientFactory,Kf as RequestParameterLocations,we as ScriptManager,Te as SubscriptionManager,Hf as buildHttpClientInstance,re as createAuthorizationHeaders,cf as getTransportInstance,Yf as isFailedStatusCode,Xf as isInfoStatusCode,Jf as isSuccessStatusCode,Gf as parseRequestParameters};
|
|
293
|
+
`}})),lf=w(((exports,t)=>{t.exports=n;function n(e){let{secret:t,censor:n,compileRestore:r,serialize:i,groupRedact:a,nestedRedact:o,wildcards:s,wcLen:c}=e,l=[{secret:t,censor:n,compileRestore:r}];return i!==!1&&l.push({serialize:i}),c>0&&l.push({groupRedact:a,nestedRedact:o,wildcards:s,wcLen:c}),Object.assign(...l)}})),uf=w(((exports,t)=>{let n=tf(),r=rf(),i=af(),a=cf(),{groupRedact:o,nestedRedact:s}=sf(),c=lf(),l=nf(),u=n(),d=e=>e;d.restore=d;let f=`[REDACTED]`;p.rx=l,p.validator=n,t.exports=p;function p(e={}){let t=Array.from(new Set(e.paths||[])),n=`serialize`in e&&(e.serialize===!1||typeof e.serialize==`function`)?e.serialize:JSON.stringify,l=e.remove;if(l===!0&&n!==JSON.stringify)throw Error(`fast-redact – remove option may only be set when serializer is JSON.stringify`);let p=l===!0?void 0:`censor`in e?e.censor:f,m=typeof p==`function`,h=m&&p.length>1;if(t.length===0)return n||d;u({paths:t,serialize:n,censor:p});let{wildcards:g,wcLen:_,secret:v}=r({paths:t,censor:p}),y=a(),b=`strict`in e?e.strict:!0;return i({secret:v,wcLen:_,serialize:n,strict:b,isCensorFct:m,censorFctTakesPath:h},c({secret:v,censor:p,compileRestore:y,serialize:n,groupRedact:o,nestedRedact:s,wildcards:g,wcLen:_}))}}));const df=[`client_secret`,`access_token`,`refresh_token`,`api_key`,`password`,`job_board_token`,`private_key`,`certificate`,`service_user_token`,`key_id`,`secret_key`,`provhash`,`admin_key`,`session_key`,`id_token`,`authorization`,`bh_rest_token`,`external_trigger_token`,`tempauth`],ff=[`req.headers.authorization`,`req.headers.cookie`,`req.headers.cookies`,`req.headers["set-cookie"]`,`req.headers["set-cookies"]`,`req.headers.httpsAgent.options.cert`,`req.headers.httpsAgent.options.key`,`req.headers["x-stackone-external-trigger-token"]`,`error.config.headers.authorization`,`error.config.data`,`error.config.headers.cookie`,`error.config.headers.cookies`,`error.config.headers["set-cookie"]`,`error.config.headers["set-cookies"]`,`error.config.httpsAgent.options.cert`,`error.config.httpsAgent.options.key`,`err.config.headers.authorization`,`err.config.data`,`err.config.headers.cookie`,`err.config.headers.cookies`,`err.config.headers["set-cookie"]`,`err.config.headers["set-cookies"]`,`err.config.httpsAgent.options.cert`,`err.config.httpsAgent.options.key`,`res.headers.authorization`,`res.headers.cookie`,`res.headers.cookies`,`res.headers["set-cookie"]`,`res.headers["set-cookies"]`,`res.headers.httpsAgent.options.cert`,`res.headers.httpsAgent.options.key`,`context.credentials`,...df],pf=`**redacted**`;let mf=function(e){return e.FULL=`FULL`,e.PARTIAL=`PARTIAL`,e}({});var hf=E(uf());const gf=e=>pf,_f=e=>typeof e==`string`?e.startsWith(pf)?e:e.length<10?pf:`${pf}${e.slice(-5)}`:pf,vf=(e=[],t=!0)=>{if(!t)return[];let n=e.map(e=>bf(e));return[...e,...n]},yf=(e=[],t=!0)=>{if(!t)return[];let n=new Set;return e.forEach(e=>{if(n.add(e),e.includes(`_`)){let t=e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase());n.add(t)}else{let t=e.replace(/([A-Z])/g,`_$1`).toLowerCase();n.add(t)}}),Array.from(n)},bf=e=>{let t=Sf(e);return t||xf(e)},xf=e=>{let t=e.split(`.`);if(t.length<2)return Cf(e);let n=t.pop()??``,r=Cf(n);return[...t,r].join(`.`)},Sf=e=>{let t=e.lastIndexOf(`[`),n=e.indexOf(`]`,t);if(t===-1||n===-1)return;let r=e.slice(t,n+1),i=r.replace(/(["'])([^"']*)(["'])/g,(e,t,n)=>n?t+Cf(n)+t:t+t);return`${e.slice(0,t)}${i}${e.slice(n+1)}`},Cf=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,wf=vf(ff),Tf=yf(df),Ef={[mf.FULL]:gf,[mf.PARTIAL]:_f};mf.FULL,(0,hf.default)({paths:wf,serialize:!1,censor:Ef[mf.FULL]}),mf.PARTIAL,(0,hf.default)({paths:wf,serialize:!1,censor:Ef[mf.PARTIAL]});const Df=(e,t=mf.FULL,n)=>{if(!o(e))try{let n=new URL(e),r=[...n.searchParams].reduce((e,[n,r])=>{let i=n.toLowerCase();return e.set(n,Tf.some(e=>e.toLowerCase()===i)?Ef[t](r):r),e},new URLSearchParams);return`${n.origin}${n.pathname}${r.toString()?`?`+r:``}${n.hash}`}catch(t){return n?.warning({message:`Invalid URL provided, unable to redact`,context:{value:e,error:t},category:`redactUrl`}),e}};var Of=class e{#transportFactory;#getRedisClient;#logger;#redisClientConfig;#errorMappingFn;#redisClient;constructor({transportFactory:e=Zd,getRedisClient:t=ye,logger:n,redisClientConfig:r,errorMappingFn:i}={}){this.#transportFactory=e,this.#getRedisClient=t,this.#logger=n,this.#redisClientConfig=r,this.#errorMappingFn=i}#generateCacheKey({url:e,payload:t,method:n,context:i}){let a=20;if(!i?.accountSecureId||i.accountSecureId.length<a||!e||!n)return null;let o=t?r(t):``;return`${i.accountSecureId}-${n.toUpperCase()}${o}-${e}`}async#getCachedResponse({url:t,payload:n,method:r,cacheTTL:i,context:a}){if(!this.#redisClient||!i||i<=0)return null;let o=this.#generateCacheKey({url:t,payload:n,method:r,context:a});if(!o)return null;let s=await this.#redisClient.getData(o);return s?(this.#logger?.debug({category:e.name,message:`Cache hit for key [${o}].`}),s):(this.#logger?.debug({category:e.name,message:`Cache miss for key [${o}].`}),null)}async#cacheResponse({url:t,payload:n,method:r,cacheTTL:i,context:a,response:o}){if(!this.#redisClient||!i||i<=0)return!1;let s=this.#generateCacheKey({url:t,payload:n,method:r,context:a});return s?(this.#logger?.debug({category:e.name,message:`Caching result for key [${s}].`}),this.#redisClient.setData({key:s,value:o,cacheTTL:i*60})):!1}async request({headers:t={},url:n,method:r=`get`,maxRedirects:i=0,responseType:a,cacheTTL:s,context:c,traceId:l,payload:d,httpsAgent:f,httpAgent:p,requestConfig:m,httpsAgentConfig:h}){try{u(this.#redisClientConfig)&&o(this.#redisClient)&&(this.#redisClient=await this.#getRedisClient(this.#redisClientConfig,this.#logger));let e=this.#normalizeHeaders(t),g=this.#getSafePayload(d,t),_=await this.#getCachedResponse({url:n,payload:g,method:r,cacheTTL:s,context:c});if(_)return{..._,responseTime:new Date};let v=yo.getInstance(),y=u(l)?await v.get(l):null,b=y?.signal,x=await this.#transportFactory({redisClientConfig:this.#redisClientConfig,logger:this.#logger,context:c,requestConfig:m,httpsAgentConfig:h}),S=await x.request({headers:e,url:n,method:r,maxRedirects:i,responseType:a,data:g,httpsAgent:f,httpAgent:p,signal:b}),C={data:S.data,status:S.status,body:g,method:r,headers:this.#extractAxiosHeaders(S.headers),requestUrl:n,responseType:S?.config?.responseType,responseTime:new Date};return await this.#cacheResponse({url:n,payload:g,method:r,cacheTTL:s,context:c,response:C}),C}catch(t){let i=t;i.url=Df(n),this.#logger?.warning({category:e.name,message:`Request error [${r?.toUpperCase()} ${i.url}]: ${i.message}.`,error:i});let a=this.#mapErrorToHttpException(i);throw u(a)?a:t}}async get({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,requestConfig:o}){return this.request({url:t,method:`get`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,requestConfig:o})}async post({headers:e,url:t,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s}){return this.request({url:t,method:`post`,headers:e,maxRedirects:n,cacheTTL:r,context:i,traceId:a,payload:o,requestConfig:s})}#normalizeHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n.toLowerCase()]=e[n]||``}),t}#extractAxiosHeaders(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]||``}),t}#isFormUrlEncoded(e){return e[`content-type`]===`application/x-www-form-urlencoded`}#getSafePayload(e,t){if(!(o(e)||c(e)&&Object.keys(e).length===0))return this.#isFormUrlEncoded(t)?v.stringify(e):e}#mapErrorToHttpException(e){if(p(e)&&this.#errorMappingFn)return this.#errorMappingFn(e)}};const kf=(e,t,n)=>new Of({redisClientConfig:e,logger:t,errorMappingFn:n});var Af=class{static httpClientInstance=null;static async getInstance({redisClientConfig:e,logger:t,errorMappingFn:n,getHttpClient:r=kf}){return this.httpClientInstance??=r(e,t,n),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}};const jf=[`get`,`post`,`put`,`delete`,`patch`],Mf=e=>e.reduce((e,t)=>(Array.isArray(e[t.in][t.name])?e[t.in][t.name]=e[t.in][t.name].concat(t.value):typeof e[t.in][t.name]==`object`&&typeof t.value==`object`?e[t.in][t.name]={...e[t.in][t.name],...t.value}:e[t.in][t.name]=t.in===`body`?t.value:String(t.value),e),{query:{},body:{},headers:{}}),Nf=[`query`,`body`,`headers`],Pf=(e,t)=>{if(o(t)||t?.length===0||o(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=y(n,e)===!0;if(o(n)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??ho[t.targetStatus]??`Unknown error`}}return e},Ff=e=>u(e)&&e>=200&&e<=299,If=e=>u(e)&&e>=400&&e<=599,Lf=e=>u(e)&&e>=100&&e<=199;var Rf=class{async performRequest({httpClient:e,url:t,method:n,headers:r,body:i,customErrorConfigs:a}){let s;try{s=await e?.request({method:n,url:t,headers:r,maxRedirects:0,payload:i})}catch(e){if(o(e?.response))throw e;s=e.response}let c=Pf(s,a);if(If(c?.status))throw new go(c,c.message);return c}},zf=class{static build(e=`rest`){if(e===`rest`)return new Rf;throw Error(`Unknown request client type: ${e}`)}};export{mo as CUSTOM_ERROR_CONFIG_SCHEMA,nt as ConcurrencyManager,ve as EventClient,Of as HttpClient,Af as HttpClientManager,ho as HttpErrorMessages,jf as HttpMethods,go as HttpResponseError,_o as HttpTransportFactory,yo as InstanceManager,O as LockManager,me as MemoryStore,Ie as QueueManager,No as RateLimitManager,be as RedisClient,zf as RequestClientFactory,Nf as RequestParameterLocations,we as ScriptManager,Te as SubscriptionManager,kf as buildHttpClientInstance,ne as createAuthorizationHeaders,Zd as getTransportInstance,If as isFailedStatusCode,Lf as isInfoStatusCode,Ff as isSuccessStatusCode,Mf as parseRequestParameters};
|