@flemist/simple-utils 2.1.6 → 2.1.8

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.
@@ -0,0 +1,17 @@
1
+ "use strict";const ft=require("@flemist/abort-controller-fast"),Tt=require("@flemist/time-controller"),b=require("@flemist/async-utils"),Xt=require("fflate");function Yt(t){if(!t||t.timeout==null)return null;const e=new ft.AbortControllerFast,r=t.timeController??Tt.timeControllerDefault;if(t.timeout){const n=r.setTimeout(()=>{e.abort(new ft.AbortError(`[timeoutAbortController] Timeout error: ${t.timeout}ms`))},t.timeout);e.signal.subscribe(()=>{clearTimeout(n)})}return t.abortSignal?.subscribe(n=>{e.abort(n)}),e}async function nr(t,e){const r=Yt(e);try{return await t(r?.signal??e?.abortSignal??null)}finally{r?.abort()}}class sr{_options;_hasValue=!1;_promiseOrValue=null;constructor(e){this._options=e}run(){if(!this._hasValue){let e=this._options.func();const r=s=>(this._options.persist?this._promiseOrValue=s:(this._promiseOrValue=null,this._hasValue=!1),s),n=s=>{throw this._options.persist||(this._promiseOrValue=null,this._hasValue=!1),s};if(b.isPromiseLike(e))e=e.then(r,n);else if(!this._options.persist)return e;this._promiseOrValue=e,this._hasValue=!0}return this._promiseOrValue}set(e){if(!this._options.persist)throw new Error("[Lazy][set] Cannot set value when persist is false");this._hasValue=!0,this._promiseOrValue=e}}class or{_options;_promiseOrValues=new Map;constructor(e){this._options=e}run(e){if(this._promiseOrValues.has(e))return this._promiseOrValues.get(e);let r=this._options.func(e);const n=o=>(this._options.persist?this._promiseOrValues.set(e,o):this._promiseOrValues.delete(e),o),s=o=>{throw this._options.persist||this._promiseOrValues.delete(e),o};if(b.isPromiseLike(r))r=r.then(n,s);else if(!this._options.persist)return r;return this._promiseOrValues.set(e,r),r}set(e,r){if(!this._options.persist)throw new Error("[LazyWithId][set] Cannot set value when persist is false");this._promiseOrValues.set(e,r)}}class Zt{_lockPromise=null;get hasQueued(){return this._lockPromise!=null}lock(e){if(this._lockPromise)return b.promiseLikeToPromise(this._lockPromise.then(()=>this.lock(e)));const r=e();if(b.isPromiseLike(r)){const n=r.then(()=>{this._lockPromise===n&&(this._lockPromise=null)},()=>{this._lockPromise===n&&(this._lockPromise=null)});this._lockPromise=n}return b.promiseLikeToPromise(r)}}class te{_lockers=new Map;lock(e,r){let n=this._lockers.get(e);n==null&&(n=new Zt,this._lockers.set(e,n));const s=()=>{n.hasQueued||this._lockers.delete(e)};let o;try{o=n.lock(r)}catch(i){throw s(),i}return b.isPromiseLike(o)?o.then(i=>(s(),i),i=>{throw s(),i}):(s(),o)}hasQueued(e){const r=this._lockers.get(e);return r!=null&&r.hasQueued}}var At=(t=>(t[t.none=0]="none",t[t.error=1]="error",t[t.warn=2]="warn",t[t.debug=3]="debug",t))(At||{});async function ir(t){const e=t.abortSignal??null,r=t.timeController??Tt.timeControllerDefault;let n=0;for(;;)try{return await t.func({abortSignal:e})}catch(s){if((t.logLevel==null||t.logLevel>=At.error)&&console.error("[withRetry] error",s),e?.aborted)throw s;const o=t.delay({error:s,retryCount:n++,abortSignal:e});if(o==null||(typeof o=="number"?await b.delay(o,e??void 0,r):await o(),e?.aborted))throw s}}function ur({maxRetries:t,delays:e,isRetriableError:r}){return function({retryCount:s,error:o}){if(s==null||t!=null&&s>=t)return null;if(r==null||r(o)){if(Array.isArray(e))return e[Math.min(s,e.length-1)];{const i=e.mult??2;return Math.min(e.min*i**s,e.max)}}return null}}async function k(t){const e=await Promise.allSettled(t),r=[];return e.forEach(n=>{if(n.status==="fulfilled")r.push(n.value);else throw n.reason}),r}class ee{_options;_statsMap=null;_totalSize=null;_initPromise=null;constructor(e){this._options=e}async loadStatsMap(e){const r=await this._options.storage.getEntries(),n=[];r.forEach((s,o)=>{const i=this._options.converter?this._options.converter.from(s):s;b.isPromiseLike(i)?n.push(i.then(u=>{e(o,u)})):e(o,i)}),await Promise.all(n)}init(){return this._initPromise==null&&(this._initPromise=this._init()),this._initPromise}async _init(){const e=new Map;let r=0;await this.loadStatsMap((n,s)=>{e.set(n,s),r+=s.size}),this._statsMap=e,this._totalSize=r}async getTotalSize(){return await this.init(),this._totalSize}async get(e){return await this.init(),this._statsMap.get(e)??null}async set(e,r){if(await this.init(),r!=null){const n=this._options.converter?await this._options.converter.to(r):r;await this._options.storage.set(e,n);const s=this._statsMap.get(e);this._statsMap.set(e,r),this._totalSize+=r.size-(s?.size??0)}else{await this._options.storage.delete(e);const n=this._statsMap.get(e);n!=null&&(this._statsMap.delete(e),this._totalSize-=n.size)}}async getEntries(){return await this.init(),this._statsMap}}function ar(t,e){return t[1].dateUsed!==e[1].dateUsed?t[1].dateUsed<e[1].dateUsed?-1:1:t[1].size!==e[1].size?t[1].size<e[1].size?-1:1:t[1].dateModified!==e[1].dateModified?t[1].dateModified<e[1].dateModified?-1:1:t[0]!==e[0]?t[0]<e[0]?-1:1:0}class cr{_options;_timeController;_locker;_stats;constructor(e){this._options=e,this._timeController=e.timeController??Tt.timeControllerDefault,this._locker=new te,this._stats=new ee({storage:e.storages.stat,converter:e.converterStat})}async freeUpSpace(e,r,n){if(this._options.totalSize==null)return;const s=this._options.totalSize[0],o=this._options.totalSize[1];if(n>o)throw new Error(`[Cache][freeUpSpace] value size (${n}) exceeds maximum total size (${o})`);let i=await this._stats.getTotalSize();if(i+=n-(r??0),i<=o)return;const u=[],a=await this._stats.getEntries(),c=Array.from(a.entries());c.sort(ar),c.forEach(([l,d])=>{if(l===e||this._locker.hasQueued(l))return;const f=-d.size;(i>o||i+f>s)&&(u.push(this._locker.lock(l,async()=>(await k([this._options.storages.value.delete(l),this._options.storages.error.delete(l)]),this._stats.set(l,null)))),i+=f)}),await k(u)}async getOrCreate(e,r){const n=this._options.converterInput?await this._options.converterInput(e):e;return this._locker.lock(n,async()=>{let s=await this._stats.get(n);if(s==null||this._options.isExpired!=null&&this._options.isExpired(s))await k([this._options.storages.value.delete(n),this._options.storages.error.delete(n),this._stats.set(n,null)]),s=null;else{const[p,f]=await Promise.all([this._options.storages.value.get(n),this._options.storages.error.get(n)]),h=this._timeController.now();if(!s.hasError&&p!=null){const m={...s,dateUsed:h},_=this._options.converterValue?await this._options.converterValue.from(p):p;return await this._stats.set(n,m),_}if(s.hasError&&f!=null){const m={...s,dateUsed:h},_=this._options.converterError?await this._options.converterError.from(f):f;throw await this._stats.set(n,m),_}}let o=null,i=null,u=!1;try{o=await r(e)}catch(p){i=p,u=!0}if(u){const p=this._options.converterError?await this._options.converterError.to(i):i,f=this._options.getSize.error(p)+this._options.getSize.stat();await this.freeUpSpace(n,s?.size,f),await k([this._options.storages.error.set(n,p),this._options.storages.value.delete(n)]);const h=this._timeController.now(),m={dateModified:h,dateUsed:h,size:f,hasError:!0};throw await this._stats.set(n,m),i}const a=this._options.converterValue?await this._options.converterValue.to(o):o,c=this._options.getSize.value(a)+this._options.getSize.stat();await this.freeUpSpace(n,s?.size,c),await k([this._options.storages.value.set(n,a),this._options.storages.error.delete(n)]);const l=this._timeController.now(),d={dateModified:l,dateUsed:l,size:c};return await this._stats.set(n,d),o})}async delete(e){const r=this._options.converterInput?await this._options.converterInput(e):e;return this._locker.lock(r,async()=>{await k([this._options.storages.value.delete(r),this._options.storages.error.delete(r),this._stats.set(r,null)])})}async clear(){const[e,r,n]=await Promise.all([this._options.storages.value.getKeys(),this._options.storages.error.getKeys(),this._options.storages.stat.getKeys()]),s=new Set([...e,...r,...n]),o=[];s.forEach(i=>{const u=this._locker.lock(i,async()=>{const a=[],c=this._options.storages.value.delete(i);b.isPromiseLike(c)&&a.push(c);const l=this._options.storages.error.delete(i);b.isPromiseLike(l)&&a.push(l);const d=this._stats.set(i,null);b.isPromiseLike(d)&&a.push(d),await k(a)});b.isPromiseLike(u)&&o.push(u)}),await k(o)}}class lr{_cache=new Map;set(e,r){this._cache.set(e,r)}get(e){return this._cache.get(e)}delete(e){this._cache.delete(e)}clear(){this._cache.clear()}getKeys(){return Array.from(this._cache.keys())}getEntries(){return new Map(this._cache)}}function xt(t){if(t==null)return null;if(Array.isArray(t)){const e=t.length,r=[];for(let n=0;n<e;n++)r.push(xt(t[n]));return r}if(typeof t=="object"){if(t.constructor&&t.constructor!==Object)return t;const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=xt(t[r]));return e}return t}function H(t,e){if(t===e)return!0;if(t==null)return e==null;if(e==null)return!1;if(Array.isArray(t)){if(!Array.isArray(e))return!1;const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(!H(t[n],e[n]))return!1;return!0}if(typeof t=="object"){if(typeof e!="object"||t.constructor&&t.constructor!==Object||e.constructor&&e.constructor!==Object)return!1;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&!H(t[r],Object.prototype.hasOwnProperty.call(e,r)?e[r]:null))return!1;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&!Object.prototype.hasOwnProperty.call(t,r)&&!H(e[r],null))return!1;return!0}return!1}function fr(t,e){if(t==null||e==null)return t==null==(e==null);if(t.size!==e.size)return!1;for(const[r,n]of t)if(!H(n,e.get(r)))return!1;return!0}function hr(t,e){const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(t[n]!==e[n])return!1;return!0}function ht(t){return!t||typeof t!="object"?t:Array.isArray(t)?t.map(ht):t&&Object.keys(t).sort().reduce((e,r)=>{const n=ht(t[r]);return n!=null&&(e[r]=n),e},{})}function mr(t,e){return Object.defineProperty(t,"name",{value:e,configurable:!0}),t}function re(t){return t=ht(t),JSON.stringify(t??null)}let it=null;function pr(){if(!it){it=new Array(256);for(let t=0;t<256;t++)it[t]=t.toString(16).padStart(2,"0")}return it}function ne(t){const e=pr(),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let s=0,o=r.length;s<o;s++)n+=e[r[s]];return n}let Et=null,se=null,ut=null,oe=null;function dr(){Et||(Et=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),se=new Uint32Array(64),oe=new TextEncoder,ut=new Uint8Array(65536))}function ie(t){if(t==null)return null;dr();const e=Et,r=se,n=oe;let s=ut,o;if(typeof t=="string"){const w=t.length*3;s.length<w+128&&(s=ut=new Uint8Array(w+128));const y=n.encodeInto(t,s);o=s.subarray(0,y.written)}else if(t instanceof Uint8Array)o=t;else if(ArrayBuffer.isView(t))o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else throw new Error(`[sha256Buffer] Unsupported content type: ${typeof t}`);const i=o.length,u=i+72>>>6<<6;s.length<u&&(s=ut=new Uint8Array(u)),o!==s&&s.set(o),s[i]=128;for(let w=i+1;w<u;w++)s[w]=0;const a=i*8,c=a/4294967296|0,l=a|0;s[u-8]=c>>>24,s[u-7]=c>>>16,s[u-6]=c>>>8,s[u-5]=c,s[u-4]=l>>>24,s[u-3]=l>>>16,s[u-2]=l>>>8,s[u-1]=l;let d=1779033703,p=-1150833019,f=1013904242,h=-1521486534,m=1359893119,_=-1694144372,O=528734635,E=1541459225;for(let w=0;w<u;w+=64){for(let S=0;S<16;S++){const x=w+(S<<2);r[S]=s[x]<<24|s[x+1]<<16|s[x+2]<<8|s[x+3]}for(let S=16;S<64;S++){const x=r[S-15],N=r[S-2],bt=(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3,ot=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10;r[S]=r[S-16]+bt+r[S-7]+ot|0}let y=d,T=p,nt=f,_t=h,A=m,st=_,B=O,wt=E;for(let S=0;S<64;S+=4)for(let x=0;x<4;x++){const N=S+x,bt=(A>>>6|A<<26)^(A>>>11|A<<21)^(A>>>25|A<<7),ot=wt+bt+(B^A&(st^B))+e[N]+r[N]|0,rr=((y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10))+(y&T^nt&(y^T))|0;wt=B,B=st,st=A,A=_t+ot|0,_t=nt,nt=T,T=y,y=ot+rr|0}d=d+y|0,p=p+T|0,f=f+nt|0,h=h+_t|0,m=m+A|0,_=_+st|0,O=O+B|0,E=E+wt|0}const M=new Uint8Array(32),K=[d,p,f,h,m,_,O,E];for(let w=0;w<8;w++){const y=K[w],T=w<<2;M[T]=y>>>24,M[T+1]=y>>>16&255,M[T+2]=y>>>8&255,M[T+3]=y&255}return M}function ue(t){const e=ie(t);return e?ne(e):null}function gr(t){const e=re(t);return ue(e)}function yr(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function _r(t,e){return t==null?e:r=>t(r,n=>e(n))}function ae(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function ce(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function le(t,e){return t==null?e:{to:ae((r,n)=>t.to(r,n),(r,n)=>e.to(r,n))}}function fe(t,e){return t==null?e:{from:ce((r,n)=>t.from(r,n),(r,n)=>e.from(r,n))}}function wr(t,e){return t==null?e:{to:le(t,e).to,from:fe(t,e).from}}function he(t,e){return t==null?e:r=>t(r,n=>e(n))}function me(t,e){return t==null?e:r=>t(r,n=>e(n))}function pe(t,e){return t==null?e:{to:he((r,n)=>t.to(r,n),r=>e.to(r))}}function de(t,e){return t==null?e:{from:me((r,n)=>t.from(r,n),r=>e.from(r))}}function br(t,e){return t==null?e:{to:pe(t,e).to,from:de(t,e).from}}const Mt={to:t=>JSON.stringify(t??null,null,2),from:t=>JSON.parse(t)},Q={to:t=>new TextEncoder().encode(t),from:t=>new TextDecoder().decode(t)},Ct={to:t=>{const e=Mt.to(t);return Q.to(e)},from:t=>{const e=Q.from(t);return Mt.from(e)}};async function ge(t,e){return new Promise((r,n)=>{Xt.gzip(t,{level:e.level},(s,o)=>{s?n(s):r(o)})})}function Sr(t){return t[0]===31&&t[1]===139}async function ye(t){return new Promise((e,r)=>{Xt.gunzip(t,(n,s)=>{n?r(n):e(s)})})}function kt(t){return{to:e=>t==null?e:ge(e,t),from:e=>t==null?e:ye(e)}}function Or(t){const e=kt(t);return{to:r=>{const n=Ct.to(r);return e.to(n)},from:async r=>{const n=await e.from(r);return Ct.from(n)}}}function xr(t){return t==null?null:t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&rt;";case'"':return"&quot;";default:return"&#039;"}})}function Er(t){return t==null?null:t?.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&")}function It(t,e,r){const n=e==null?t:new Date(t.toLocaleString("en-US",{timeZone:e})),s=r==null?t:new Date(t.toLocaleString("en-US",{timeZone:r}));return new Date(t.getTime()+s.getTime()-n.getTime())}function _e(t,e){t=It(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),o=t.getUTCHours().toString().padStart(2,"0"),i=t.getUTCMinutes().toString().padStart(2,"0"),u=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s} ${o}:${i}:${u}`}let Mr=0;const St=new WeakMap;function L(t){if(St.has(t))return St.get(t);const e=Mr++;return St.set(t,e),e}function G(t,e,r){if(t==null)return null;if(e==null||t.length<=e)return t;const n=r?.appendEllipsis?"…":"",s=n.length+(r?.appendTruncatedLength?String(t.length).length+2:0),o=Math.max(0,e-s),i=r?.appendTruncatedLength?`(${t.length-o})`:"";return o<=0?i+n:r?.fromStart?i+n+t.slice(t.length-o):t.slice(0,o)+n+i}function qt(t,e){try{return t[e]}catch(r){return"Error: "+(r instanceof Error?r.message:String(r))}}function I(t,e,r,n){const{pretty:s,filter:o,maxDepth:i,maxItems:u,maxStringLength:a,showObjectId:c,showArrayIndex:l,customToString:d}=e??{};if(r==null&&(r=[]),n==null&&(n=new Set),d){const f=d(t,r,h=>I(h,e,r,n));if(f!=null)return G(f,a,e?.truncateOptions)}const p=r.length;if(typeof t=="string")return t=G(t,a,e?.truncateOptions),n.size>0&&(t=JSON.stringify(t)),t;if(t==null||typeof t!="object")return String(t);if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return`${t.constructor?.name??""}#${L(t)}[${t.byteLength}]`;if(t instanceof RegExp)return G(String(t),a,e?.truncateOptions);if(t instanceof Date)return _e(t);if(t instanceof Object){if(n.has(t)||i!=null&&p>=i)return`${t.constructor===Object?"":t.constructor?.name??""}#${L(t)}`;n.add(t)}if(t instanceof Error)return G(t.stack||t.message||String(t),a,e?.truncateOptions);if(Array.isArray(t)){const f=s?" ".repeat(p):"";let h="";c&&(h+=`#${L(t)} `),h+="[";let m=0,_=!1;for(let O=0;O<t.length;O++){if(u!=null&&m>=u){_=!0;break}const E=[...r,String(O)],M=qt(t,O);if(o!=null&&!o(E,M))continue;const K=I(M,e,E,n);m>0&&(h+=","),s&&(h+=`
2
+ `),s&&(h+=`${f} `),l&&(h+=`${O}: `),h+=`${K}`,m++}return _?(m>0&&(h+=","),s?(h+=`
3
+ `,h+=`${f} ...
4
+ `):h+="...",h+=f,h+="]"):(m>0&&s&&(h+=`
5
+ ${f}`),h+="]"),h}if(t instanceof Map){let f="";return c&&(f+=`#${L(t)} `),f+="Map",f+=I(Array.from(t.entries()),e,r,n),f}if(t instanceof Set){let f="";return c&&(f+=`#${L(t)} `),f+="Set",f+=I(Array.from(t.values()),e,r,n),f}{const f=t.constructor===Object?"":t.constructor?.name??"",h=s?" ".repeat(p):"";let m=f?`${f} `:"";c&&(m+=`#${L(t)} `),m+="{";let _=0,O=!1;for(const E in t){if(u!=null&&_>=u){O=!0;break}const M=[...r,E],K=qt(t,E);if(o!=null&&!o(M,K))continue;const w=I(K,e,M,n);_>0&&(m+=","),s&&(m+=`
6
+ `),s&&(m+=`${h} `),m+=`${E}: ${w}`,_++}return O&&(_>0&&(m+=","),s?(m+=`
7
+ `,m+=`${h} ...
8
+ `):m+="...",m+=h),_>0&&s&&!O&&(m+=`
9
+ ${h}`),m+="}",m}}function we(t,e){t=It(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),o=t.getUTCHours().toString().padStart(2,"0"),i=t.getUTCMinutes().toString().padStart(2,"0"),u=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s}_${o}-${i}-${u}`}const $t={to:t=>{const e=I(t,{pretty:!0,maxDepth:10,maxItems:50,maxStringLength:1e3});return Q.to(e)},from:t=>Q.from(t)};function Cr(t){const e=kt(t);return{to:r=>{const n=$t.to(r);return e.to(n)},from:async r=>{const n=await e.from(r);return $t.from(n)}}}const $r={to:t=>Array.from(t.entries()).reduce((e,[r,n])=>(e[r]=n,e),{}),from:t=>new Map(Object.entries(t))},Tr={to:t=>Array.from(t),from:t=>new Set(t)};function be(t,e){return t==null?e:e==null?t:Math.min(t,e)}function Se(t,e){return t==null?e:e==null?t:Math.max(t,e)}function Ar(t,e,r){return Se(be(t,e),r)}function kr(t,e){return(t%e+e)%e}function Ir(t){return function(){let r=t+=1831565813;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),(r^r>>>14)/4294967296+.5}}function vr(){return Math.random()}function Pr(){return Math.random()*2**32>>>0}function Oe(t){return t!=null?Ir(t):vr}class mt{_seed;_rnd;constructor(e){this._seed=e,this._rnd=Oe(e)}get seed(){return this._seed}nextSeed(){return this.next()*2**32>>>0}nextRandom(){return new mt(this.nextSeed())}next(){return this._rnd()}clone(){return new mt(this._seed)}}function vt(t,e,r){if(r==null&&(r=e,e=0),r<=e)throw new Error(`[random][randomFloat] toExclusive (${r}) must be greater than from (${e})`);return t.next()*(r-e)+e}function xe(t,e,r){return Math.floor(vt(t,e,r))}function Nr(t,e){return t.next()<(e??.5)}function Rr(t,e,r){if(Array.isArray(e)){const o=e;e=o.length,r=i=>o[i]}if(!r)throw new Error("[random][randomIndexWeighted] getWeight is required");let n=0;for(let o=0;o<e;o++)n+=r(o);if(n===0)return-1;let s=vt(t,n);for(let o=0;o<e;o++)if(s-=r(o),s<0)return o;return e-1}function Pt(t,e){if(e.length===0)throw new Error("[random][randomItem] items is empty");const r=xe(t,e.length);return e[r]}function zr(t,e,r){if(e.length===0)throw new Error("[random][randomItems] items is empty");const n=[];for(let s=0;s<r;s++)n.push(Pt(t,e));return n}function Dr(t,e,r){let n=Object.values(e);return r&&(n=n.filter(r)),Pt(t,n)}const Ee=1073741789,at=(Ee>>2)-1;function Ur(t=at,e){if(t<=0)throw new Error(`[random][PseudoRandom] count(${t}) must be > 0`);if(t>at)throw new Error(`[random][PseudoRandom] count(${t}) must be <= ${at}`);if(e==null&&(e=Math.floor(Math.random()*t)),e>=t)throw new Error(`[random][PseudoRandom] startFrom(${e}) must be < count(${t})`);let r=e;return function(){return r=(r+Ee)%t,r}}let W=null;function Lr(){const t=Date.now();return W==null||t>W?(W=t,t):(W++,W)}async function jr({url:t,timeout:e}={}){t||(t=typeof window<"u"?"/":"https://google.com");let r;try{const n=new ft.AbortControllerFast;r=e?setTimeout(()=>{n.abort()},e):null;const s=await fetch(t,{method:"HEAD",signal:ft.toAbortSignal(n.signal)}),o=s.headers.get("date");if(!o)throw new Error(`[Now][getDateInet] No date header in response: ${s.status} ${t}`);return new Date(o).getTime()}finally{r&&clearTimeout(r)}}function Kr(t){const e=alert;return window.alert=r=>t(e,r),()=>{window.alert=e}}var F=(t=>(t.log="log",t.warn="warn",t.error="error",t.info="info",t.debug="debug",t.trace="trace",t.assert="assert",t))(F||{});const Jt=Object.values(F);function U(t){return function(){t.apply(console,arguments)}}const Ht={log:U(console.log),warn:U(console.warn),error:U(console.error),info:U(console.info),debug:U(console.debug),trace:U(console.trace),assert:U(console.assert)};function Nt(t){return Jt.forEach(e=>{console[e]=(...r)=>{t(Ht,e,r)}}),()=>{Jt.forEach(e=>{console[e]=Ht[e]})}}function Fr(t){return function(r){let n=null;const o=Nt((u,a,c)=>{try{t(u,a,c)}catch(l){throw n||(n=l),l}}),i=()=>{if(o(),n)throw n};try{const u=r();return b.isPromiseLike(u)?u.then(a=>(i(),a),a=>{throw i(),a}):(i(),u)}catch(u){throw i(),u}}}class Rt{_listeners=new Map;_listenersAdd=new Map;_startStopNotifier;_emit;_update;_unsubscribeNotifier=null;_emitLast;_hasLast;_last=void 0;_emitting=!1;_subscribing=!1;_actionOnCycle;constructor({emitLastEvent:e,startStopNotifier:r,hasLast:n,last:s,actionOnCycle:o}={}){this._startStopNotifier=r??null,this._emit=r?i=>this.emit(i):null,this._update=r?i=>this.update(i):null,this._emitLast=e??!1,this._hasLast=n??!1,this._last=s,this._actionOnCycle=o??!1}get hasLast(){return this._hasLast}get last(){return this._last}get hasListeners(){return this._listeners.size>0}subscribe(e){const r={};if(this._emitting?this._listenersAdd.set(r,e):this._listeners.set(r,e),this._subscribing&&this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular subscription detected");if((this._hasLast||this._subscribing&&this._actionOnCycle==="emitLast")&&e(this._last),this._startStopNotifier&&this._listeners.size+this._listenersAdd.size===1)try{this._subscribing=!0,this._unsubscribeNotifier=this._startStopNotifier(this._emit,this._update)??null}finally{this._subscribing=!1}return()=>{if(this._listeners.delete(r),this._listenersAdd.delete(r),this._startStopNotifier&&this._listeners.size===0&&this._listenersAdd.size===0){const n=this._unsubscribeNotifier;this._unsubscribeNotifier=null,n?.()}}}emit(e){if(this._emitting){if(this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular emit detected");this._actionOnCycle==="emitLast"&&(this._last=e,this._hasLast=!0);return}const r=()=>{this._listenersAdd.size>0&&(this._listenersAdd.forEach((n,s)=>{this._listeners.set(s,n)}),this._listenersAdd.clear()),this._emitting=!1};try{this._emitting=!0,this._emitLast&&(this._last=e,this._hasLast=!0);let n;if(this._listeners.forEach(s=>{const o=s(e);b.isPromiseLike(o)&&(n||(n=[]),n.push(o))}),n)return Promise.all(n).then(r,s=>{throw r(),s});r()}catch(n){throw r(),n}}update(e){if(!this._emitLast)throw new Error("[Rx][Subject] update available only for subjects with emitLastEvent");const r=e(this._last);return this.emit(r)}}function Vr(t,e){return I(t,{maxDepth:5,maxItems:10,...e})}function Br(t){return t.map(e=>e&&typeof e=="object"?Vr(e):e)}function Wr(t){return`${we(new Date)} [${t.level.toUpperCase()}] ${Br(t.args).join(" ")}`}let pt=null,Ot=null;function Me(){return Ot||(Ot=new Rt({startStopNotifier:t=>(pt=t,()=>{pt=null})})),Ot}function Gr(){return Nt((t,e,r)=>{e==="assert"&&r[0]===!0||(e===F.error||e===F.warn||e===F.assert)&&(pt&&pt({date:Date.now(),level:e,args:r}),t[e](...r))})}function qr(t){if(typeof window>"u")return b.EMPTY_FUNC;const{levels:e,predicate:r}=t;return Me().subscribe(n=>{if(e&&!e.includes(n.level))return;const s=n.args.join(`
10
+ `);r&&!r({text:s,message:n})||alert(s)})}function Ce(){let t=new Error().stack;if(t!=null){const e=t.indexOf(`
11
+ `);e!=null&&e>=0&&(t=t.substring(e+1))}return t??""}function Jr(t){return function(...e){const r=Ce();try{return t.apply(this,e)}catch(n){throw n instanceof Error||(n=new Error(String(n))),n.stack=n.stack?n.stack+`
12
+ `+r:r,n}}}function Hr(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"}class Qr{_subjects=new Map;_getLastEvent;constructor({getLastEvent:e}={}){this._getLastEvent=e}subscribe(e,r){let n=this._subjects.get(e);n||(n=new Rt,this._subjects.set(e,n));const s=n.subscribe(r);if(this._getLastEvent){const o=this._getLastEvent(e);r(o)}return()=>{s(),n?.hasListeners||this._subjects.delete(e)}}emit(e,r){const n=this._subjects.get(e);if(n)return n.emit(r)}forEach(e){this._subjects.forEach(e)}observable(e){return{subscribe:r=>this.subscribe(e,r)}}emitter(e){return{emit:r=>this.emit(e,r)}}subject(e){return{subscribe:r=>this.subscribe(e,r),emit:r=>this.emit(e,r)}}}function Xr(t,e,r){return new Promise(n=>{let s=!1,o;function i(l){a?.(),o?.(),s=!0,n(l)}function u(l){a?.(),o?.(),s=!0,n(Promise.reject(l))}const a=r?.subscribe(u);let c=!0;o=t.subscribe(l=>{(!e||e(l,c))&&i(l),c=!1}),s&&o?.()})}class R extends Error{constructor(e){super(e)}}class g{_args;constructor(e){this._args=e&&{...e}}set(e){return this._args={...this._args??{},...e},this}name(e){return this.set({name:e})}toString(e){const r=this._args?.name;return r?typeof r=="string"?r:r(e):this.nameDefault(e)}}function $e(t,e){return I(t,{maxDepth:1,maxItems:5,...e})}function z(t){return t instanceof g}function Z(t){return $e(t)}function dt(t,...e){if(t==null)return"";const r=$e(t,{filter:(n,s)=>{if(n.length===0)return!0;if(n.length!==1)return!1;const o=n[0];return!(o==="name"||o==="expected"||s==null||s===!1||e.includes(o))}});return/^(#\d+\s*)\{}$/.test(r)?"":`(${r})`}function X(t){const{result:e,cause:r,nested:n,error:s}=t;if(s){if(!(s instanceof Error))throw new R(`[test][validateMatchResult] error must be an instance of Error, but it is: ${s}`);if(e!=null)throw new R(`[test][validateMatchResult] result must be null if error is set, but it is: ${e}`);if(r!=null)throw new R(`[test][validateMatchResult] cause must be null if error is set, but it is: ${r}`);if(n!=null)throw new R(`[test][validateMatchResult] nested must be null if error is set, but it is: ${n}`);return t}if(typeof e!="boolean")throw new R(`[test][validateMatchResult] result must be a boolean, but it is: ${e}`);if(typeof r!="string"&&r!=null)throw new R(`[test][validateMatchResult] cause must be a string or null, but it is: ${r}`);if(n!=null&&!(n instanceof Array))throw new R(`[test][validateMatchResult] nested must be an array or null, but it is: ${n}`);return t}function Te(t,e,r){return X({actual:t,expected:e,result:null,cause:null,nested:null,error:r})}function zt(t,e,r){return X({actual:t,expected:e,result:r,cause:null,nested:null,error:null})}function Dt(t,e,r){return typeof r=="boolean"?zt(t,e,r):X(typeof r=="string"?{actual:t,expected:e,result:!1,cause:r,nested:null,error:null}:{actual:t,expected:e,result:r.result,cause:r.cause??null,nested:r.nested??null,error:null})}function C(t,e){try{if(z(e)){const r=e.match(t);return Dt(t,e,r)}return zt(t,e,t===e)}catch(r){return Te(t,e,r)}}class Ut extends g{match(e){const r=this._args.expected,n=C(e,r);return{result:!n.result,nested:[{actualKey:null,result:n}]}}nameDefault(){return"not"}}function Ae(t,e){const r=Lt(t.result,e);return r?{actualKey:t.actualKey,expectedKey:t.expectedKey,result:r}:null}function Lt(t,e){if(e?!t.result:t.result)return null;t.expected instanceof Ut&&(e=!e);let r=null;return t.nested&&t.nested.forEach(n=>{const s=Ae(n,e);s&&(r||(r=[]),r.push(s))}),{actual:t.actual,expected:t.expected,result:t.result,cause:t.cause,nested:r,error:t.error}}function ke(t,e){const r=jt(t.result,e+" ");return`${e}${t.actualKey==null?"| ":t.actualKey+": "}${r}`}function jt(t,e){if(t.result)return t.expected.toString();let r="";t.nested&&(r=t.nested.map(s=>ke(s,e)).join(`
13
+ `));let n=t.cause||"";return r?(n||(n=z(t.expected)?t.expected.toString(t.actual):""),`${n}
14
+ ${r}`):`${n}
15
+ ${e}expected: ${z(t.expected)?t.expected.toString(t.actual):t.expected}
16
+ ${e}actual: ${Z(t.actual)}`}class Kt extends Error{constructor(e){super(e)}}function q(t){return function(r,n){const s=C(t,r);if(s.error)throw s.error;const o=Lt(s,!1);if(!o)return;const i=jt(o,"");console.log(`[test][check] CheckError:
17
+ `+i);const u=new Kt(i);throw n?.(u),u}}function Yr(t){return function(r,n){let s;try{s=t()}catch(o){q(o)(n);return}return b.isPromiseLike(s)?s.then(o=>(q(o)(r),o)).catch(o=>{if(o instanceof Kt)throw o;try{q(o)(n)}catch(i){throw console.error("[test][check] error",i),o}}):(q(s)(r),s)}}const tt=10;class Ft extends g{match(e){if(e==null)return`Expected array, got "${e}"`;if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args?.expected;if(r==null)return!0;const n=this._args?.maxReportItems??tt,s=this._args?.matchType||"equals";if(s==="equals"){if(e.length!==r.length)return`Expected array length to be ${r.length}, got ${e.length}`;let o=!0,i=0,u=0;const a=[];for(let c=0;c<r.length;c++){const l=e[c],d=r[c],p=C(l,d);if(p.result?(i<n&&a.push({actualKey:c,expectedKey:c,result:p}),i++):(u<n&&a.push({actualKey:c,expectedKey:c,result:p}),u++,o=!1),!o&&i>=n&&u>=n)break}return{result:o,nested:a}}if(s==="includes"){let o=!0;const i=[];let u=0,a=0;for(let c=0;c<r.length;c++){const l=r[c];let d=!1;for(let p=0;p<e.length;p++){const f=e[p],h=C(f,l);if(h.result){d=!0,u<n&&i.push({actualKey:p,expectedKey:c,result:h}),u++;break}}if(d||(o=!1,a<n&&i.push({expectedKey:c,result:{result:!1,actual:void 0,expected:l}}),a++),!o&&u>=n&&a>=n)break}return{result:o,nested:i}}return`Unknown matchType "${s}"`}nameDefault(){return`array ${this._args?.matchType||"equals"} ${Z(this._args?.expected)}`}}class Ie extends g{match(){return!0}nameDefault(){return"any"}}class ve extends g{match(e){if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args.expected;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(let a=0;a<e.length;a++){const c=e[a],l=C(c,r);if(l.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:l}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:l}),u++,n=!1),!n&&i>=o&&u>=o)break}return{result:n,nested:s}}nameDefault(){return"array item"}}class Pe extends g{match(e){const{expected:r,convert:n}=this._args,s=C(n(e),r),o=[{result:s}];return{result:s.result,nested:o}}nameDefault(){return"convert"}}class Vt extends g{match(e){const{expected:r,nonStrict:n}=this._args;return n?e==r:e===r}nameDefault(){return`is(${Z(this._args.expected)})`}}class Ne extends g{match(e){if(e==null)return`Expected number, got "${e}"`;if(typeof e!="number")return`Expected number, got "${typeof e}"`;if(this._args==null)return Number.isFinite(e)?!0:"Expected finite number";if(!this._args.allowNaN&&Number.isNaN(e))return"Expected not NaN";if(!this._args.allowInfinity&&!Number.isFinite(e))return"Expected not Infinity";const{min:r,max:n,float:s}=this._args;return!s&&!Number.isInteger(e)?`Expected integer, got "${e}"`:r!=null&&e<r?`Expected number to be >= ${r}, got ${e}`:n!=null&&e>n?`Expected number to be <= ${n}, got ${e}`:!0}nameDefault(){return`number(${dt(this._args)})`}}class Re extends g{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(const a in r){if(!Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a],l=r[a],d=C(c,l);if(d.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:d}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:d}),u++,n=!1),!n&&i>=o&&u>=o)break}if(!this._args?.ignoreExtraKeys)for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a)||Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a];if(u<o&&s.push({actualKey:a,expectedKey:a,result:Dt(c,void 0,"Unexpected key")}),u++,n=!1,u>=o)break}return{result:n,nested:s}}nameDefault(){return"object"+dt(this._args)}}class ze extends g{match(e){if(e==null)return`Expected string, got ${e}`;if(typeof e!="string")return`Expected string, got "${typeof e}"`;if(this._args==null)return!0;const{pattern:r}=this._args;if(r!=null){if(typeof r=="function")return r(e);if(!r.test(e))return!1}return!0}nameDefault(){return this._args?.pattern?`string(${this._args.pattern})`:"string"}}class De extends g{match(e){const r=this._args.expected;return e instanceof r?!0:`Expected instance of "${r}", got "${e}"`}nameDefault(){return`instanceOf(${this._args.expected.name})`}}class Ue extends g{constructor(e){super({...e,expected:e.expected instanceof Set?e.expected:new Set(e.expected)})}match(e){return!!this._args.expected.has(e)}nameDefault(){return`in(${Z(this._args.expected)})`}}class et extends g{match(e){const{type:r,expecteds:n,pipe:s}=this._args;let o=r==="and";const i=[];for(let u=0;u<n.length;u++){const a=n[u],c=C(e,a);if(i.push({actualKey:`<${r} ${u}>`,expectedKey:`<${r} ${u}>`,result:c}),r==="or"){if(c.result&&(o=!0,s))break}else if(r==="and"){if(!c.result&&(o=!1,s))break}else throw new Error(`[test][MatcherFew] Unknown type "${r}"`)}return{result:n.length===0||o,nested:i}}nameDefault(){return this._args.type}}class Le extends g{match(e){const r=this._args.matcher;return z(r)?r.match(e):r(e)}nameDefault(e){const r=this._args.name;return typeof r=="string"?r:r?r(e):"custom"}}class je extends g{match(){return!1}nameDefault(){return"never"}}class Ke extends g{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a))continue;const c=[a,e[a]],l=C(c,r);if(l.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:l}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:l}),u++,n=!1),!n&&i>=o&&u>=o)break}return{result:n,nested:s}}nameDefault(){return"object entries"+dt(this._args)}}class Fe extends g{_hasExpected=!1;_expected=void 0;get expected(){return this._expected}set expected(e){this._expected=e,this._hasExpected=!0}match(e){const r=C(e,this._expected),n=[{result:r}];return{result:r.result,nested:n}}nameDefault(){return"ref"}}function D(t){return new Ft({expected:t})}function Zr(t){return new Ft({expected:t,matchType:"includes"})}function V(){return new Ie}function tn(){return new Fe}function en(t){return new je({name:t})}function rn(t,e){const r=new ve({expected:e});return t==null?r:$(qe(z(t)||typeof t=="number"?t:rt(t)),r).name("array item")}function v(t,e,r){return new Pe({name:t,convert:e,expected:r})}function Ve(t){return new Vt({expected:t,nonStrict:!0})}function Be(t){return new Vt({expected:t,nonStrict:!1})}function Bt(t){return new Ne(t)}function rt(t){return Bt({...t,float:!1})}function nn(t){return Bt({...t,float:!0})}function P(t){return new Re({expected:t})}function ct(t,e,r=null){if(t instanceof g||e&&(t=e(t,r),t instanceof g))return t;if(t==null)return Y();if(Array.isArray(t)){const n=t.map((s,o)=>ct(s,e,o));return D(n)}if(t.constructor===Object){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=ct(t[s],e,s));return P(n)}return t instanceof b.ValueState?Xe({...t,value:ct(t.value,e,"value")}):Be(t)}function sn(t){return P(t).set({ignoreExtraKeys:!0})}function Wt(t){return new ze({pattern:t})}function on(t){return new De({expected:t})}function We(t){return v("typeof",e=>e===null?"null":typeof e,t)}function un(t){return v("constructor",e=>e.constructor,t)}function lt(){return We("boolean")}function Y(){return Ve(null)}function an(){return Qe(Y())}function cn(...t){return new et({expecteds:t,type:"or",pipe:!1})}function ln(...t){return new et({expecteds:t,type:"and",pipe:!1})}function Ge(...t){return new et({expecteds:t,type:"or",pipe:!0})}function $(...t){return new et({expecteds:t,type:"and",pipe:!0})}function j(t,e){return e==null?Ge(Y(),t):e?t:Y()}function qe(t){const e=typeof t=="number"||z(t)?t:rt(t??{min:1});return $(D(),v("length",r=>r.length,e)).name("array length")}function fn(t){const e=typeof t=="number"||z(t)?t:rt(t??{min:1});return $(Wt(),v("length",r=>r.length,e)).name("string length")}function hn(t){return $(P(),t)}function mn(t){return $(D(),t)}function pn(t){return $(P(),v("keys",e=>Object.keys(e),t))}function dn(t){return $(P(),v("values",e=>Object.values(e),t))}function gn(t){return $(P(),v("entries",e=>Object.entries(e),t))}function gt(t){return new Ke({expected:t})}function yn(t){return gt(D([t,V()]))}function _n(t){return gt(D([V(),t]))}function wn(t,e){return gt(D([t,e]))}function bn(t){return $(P(),v("keys not null",e=>Object.keys(e).filter(r=>e[r]!=null),t))}function Je(t){return new Ue({expected:t})}function Sn(t){return Je(Object.values(t))}function Gt(t,e){return new Le({matcher:e,name:t})}const On=Math.ceil(Date.now()-10*365.25*24*60*60*1e3),xn=Math.ceil(Date.now()+10*365.25*24*60*60*1e3);function J(t){return rt({...t,min:t?.min??On,max:t?.max??xn}).name("int date")}function He(t){const e={min:t?.from?.min??t?.common?.min,max:t?.from?.max??t?.common?.max,float:t?.from?.float??t?.common?.float,optional:t?.from?.optional??t?.common?.optional},r={min:t?.to?.min??t?.common?.min,max:t?.to?.max??t?.common?.max,float:t?.to?.float??t?.common?.float,optional:t?.to?.optional??t?.common?.optional};return $(D([e.optional?j(J()):J(),r.optional?j(J()):J()]),Gt("min <= max",n=>n[0]!=null&&n[1]!=null&&n[0]>n[1]?`Expected range to be [min, max], got [${n.join(", ")}]`:!0)).name("range")}function En(t){return He({...t,common:{min:new Date(2020,0,1).getTime(),max:Date.now()+900*1e3,...t?.common}}).name("range date")}function Qe(t){return new Ut({expected:t})}function Mn(){return Wt(/^[\da-f-]{36}|[\da-f]{32}$/i).name("uuid")}function Xe(t){return P({[Symbol.toStringTag]:j(V()),loading:j(lt()),hasValue:j(lt()),value:V(),hasError:j(lt()),error:V(),...t})}function Cn(t){return t!=null&&typeof t=="string"&&(t=new TextEncoder().encode(t).buffer),Gt("array buffer",e=>{if(e==null||typeof e!="object"||typeof e.byteLength!="number")return`Expected array buffer, got "${e}"`;if(t==null)return!0;if(e.byteLength!==t.byteLength)return`Expected array buffer length to be ${t.byteLength}, got ${e.byteLength}`;for(let r=0,n=t.byteLength;r<n;r++)if(e[r]!==t[r])return`Expected array buffer[${r}] to be ${t[r]}, got ${e[r]}`;return!0})}function Qt(t){return t.replace(/\W/g,"").toLowerCase()}function Ye(t){return t instanceof URL?t.searchParams:t instanceof URLSearchParams?t:typeof t=="string"?new URL(t).searchParams:typeof window<"u"?new URL(window.location.href).searchParams:new URLSearchParams}function Ze(t){return t==null?null:(t=t.toLowerCase().trim(),t==="true"||t==="1"||t==="yes"?!0:t==="false"||t==="0"||t==="no"?!1:null)}function tr(t){if(t==null)return null;t=t.trim();const e=parseInt(t,10);return isNaN(e)?null:e}function er(t){if(t==null)return null;t=t.trim();const e=parseFloat(t);return isNaN(e)?null:e}function yt(t,e){const r=Ye(e),n=Qt(t);for(const[s,o]of r.entries())if(Qt(s)===n)return o;return null}function $n(t,e){return Ze(yt(t,e))}function Tn(t,e){return tr(yt(t,e))}function An(t,e){return er(yt(t,e))}exports.Cache=cr;exports.CacheStats=ee;exports.CheckError=Kt;exports.ConsoleMessageLevel=F;exports.Lazy=sr;exports.LazyWithId=or;exports.Locker=Zt;exports.LockerWithId=te;exports.LogLevel=At;exports.MAX_REPORT_ITEMS_DEFAULT=tt;exports.MatchInternalError=R;exports.Matcher=g;exports.MatcherAny=Ie;exports.MatcherArray=Ft;exports.MatcherArrayItem=ve;exports.MatcherConvert=Pe;exports.MatcherCustom=Le;exports.MatcherFew=et;exports.MatcherIn=Ue;exports.MatcherInstanceOf=De;exports.MatcherIs=Vt;exports.MatcherNever=je;exports.MatcherNot=Ut;exports.MatcherNumber=Ne;exports.MatcherObject=Re;exports.MatcherObjectEntry=Ke;exports.MatcherRef=Fe;exports.MatcherString=ze;exports.MemoryStorage=lr;exports.Random=mt;exports.Subject=Rt;exports.SubjectWithId=Qr;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=at;exports.alertConsole=qr;exports.alertReplace=Kr;exports.argsToString=dt;exports.check=q;exports.checkFunc=Yr;exports.compressGzip=ge;exports.consoleIntercept=Gr;exports.consoleMessageToString=Wr;exports.consoleReplace=Nt;exports.convertTimeZone=It;exports.converterErrorToBuffer=$t;exports.converterJson=Mt;exports.converterJsonBuffer=Ct;exports.converterStringToBuffer=Q;exports.createConverterBufferToGzip=kt;exports.createConverterErrorToGzip=Cr;exports.createConverterJsonGzip=Or;exports.createMatchResult=Dt;exports.createMatchResultBoolean=zt;exports.createMatchResultError=Te;exports.createTaskDelayRetry=ur;exports.createUniquePseudoRandom=Ur;exports.dateNowUnique=Lr;exports.decompressGzip=ye;exports.deepCloneJsonLike=xt;exports.deepEqualJsonLike=H;exports.deepEqualJsonLikeMap=fr;exports.equalArray=hr;exports.escapeHtml=xr;exports.escapeRegExp=Er;exports.expectedToString=Z;exports.filterMatchResult=Lt;exports.filterMatchResultNested=Ae;exports.fixStackTrace=Jr;exports.formatAny=I;exports.formatDate=_e;exports.formatDateFileName=we;exports.getConsoleMessages=Me;exports.getDateInet=jr;exports.getHashKey=gr;exports.getJsonKey=re;exports.getNormalizedObject=ht;exports.getObjectId=L;exports.getRandomFunc=Oe;exports.getRandomSeed=Pr;exports.getStackTrace=Ce;exports.isGzipCompressed=Sr;exports.isMatcher=z;exports.isObservable=Hr;exports.mapObjectConverter=$r;exports.match=C;exports.matchAnd=ln;exports.matchAndPipe=$;exports.matchAny=V;exports.matchArray=D;exports.matchArrayBuffer=Cn;exports.matchArrayIncludes=Zr;exports.matchArrayItem=rn;exports.matchArrayLength=qe;exports.matchArrayWith=mn;exports.matchBoolean=lt;exports.matchConstructor=un;exports.matchConvert=v;exports.matchCustom=Gt;exports.matchDeep=ct;exports.matchEnum=Sn;exports.matchFloat=nn;exports.matchIn=Je;exports.matchInstanceOf=on;exports.matchInt=rt;exports.matchIntDate=J;exports.matchIs=Be;exports.matchIsNonStrict=Ve;exports.matchNever=en;exports.matchNot=Qe;exports.matchNotNullish=an;exports.matchNullish=Y;exports.matchNumber=Bt;exports.matchObject=P;exports.matchObjectEntries=gn;exports.matchObjectEntry=gt;exports.matchObjectKey=yn;exports.matchObjectKeyValue=wn;exports.matchObjectKeys=pn;exports.matchObjectKeysNotNull=bn;exports.matchObjectPartial=sn;exports.matchObjectValue=_n;exports.matchObjectValues=dn;exports.matchObjectWith=hn;exports.matchOptional=j;exports.matchOr=cn;exports.matchOrPipe=Ge;exports.matchRange=He;exports.matchRangeDate=En;exports.matchRef=tn;exports.matchResultNestedToString=ke;exports.matchResultToString=jt;exports.matchString=Wt;exports.matchStringLength=fn;exports.matchTypeOf=We;exports.matchUuid=Mn;exports.matchValueState=Xe;exports.max=Se;exports.min=be;exports.minMax=Ar;exports.numberMod=kr;exports.promiseAllWait=k;exports.randomBoolean=Nr;exports.randomEnum=Dr;exports.randomFloat=vt;exports.randomIndexWeighted=Rr;exports.randomInt=xe;exports.randomItem=Pt;exports.randomItems=zr;exports.setArrayConverter=Tr;exports.setFuncName=mr;exports.sha256=ue;exports.sha256Buffer=ie;exports.timeoutAbortController=Yt;exports.toConvertFrom=me;exports.toConvertTo=he;exports.toConvertWithDefaultFrom=ce;exports.toConvertWithDefaultTo=ae;exports.toConverter=br;exports.toConverterFrom=de;exports.toConverterTo=pe;exports.toConverterWithDefault=wr;exports.toConverterWithDefaultFrom=fe;exports.toConverterWithDefaultTo=le;exports.toCorrect=_r;exports.toCorrectWithDefault=yr;exports.toHex=ne;exports.truncateString=G;exports.urlGetBoolean=$n;exports.urlGetFloat=An;exports.urlGetInt=Tn;exports.urlGetParams=Ye;exports.urlGetString=yt;exports.urlParamToBoolean=Ze;exports.urlParamToFloat=er;exports.urlParamToInt=tr;exports.validateMatchResult=X;exports.waitObservable=Xr;exports.withConsoleReplace=Fr;exports.withRetry=ir;exports.withTimeout=nr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/simple-utils",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "Simple simple utils",
5
5
  "sideEffects": false,
6
6
  "types": "build/common/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "require": "./build/node/index.cjs"
35
35
  }
36
36
  },
37
+ "packageManager": "pnpm@10.18.3",
37
38
  "engines": {
38
39
  "node": ">=20"
39
40
  },
@@ -62,6 +63,38 @@
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
66
+ "scripts": {
67
+ "========================= install =========================": "",
68
+ "_prepublishOnly": "run-p audit lint build test:all && npm login",
69
+ "prepare": "node .husky/install.mjs",
70
+ "install:playwright": "pnpm exec playwright install --with-deps",
71
+ "========================= deploy =========================": "",
72
+ "build": "vite build",
73
+ "========================= lint =========================": "",
74
+ "audit": "pnpm audit --prod",
75
+ "lint:es": "eslint .",
76
+ "lint:es:fix": "eslint --fix .",
77
+ "lint": "run-p lint:es",
78
+ "lint:fix": "run-s lint:es:fix",
79
+ "lint-staged": "lint-staged",
80
+ "check:types": "tsc --noEmit",
81
+ "check": "run-p audit check:types lint",
82
+ "========================= test =========================": "",
83
+ "test:node": "vitest --run --config vite.projects.ts --project node --bail 3",
84
+ "test:browser": "vitest --run --config vite.projects.ts --project browser --bail 3",
85
+ "test:chrome": "vitest --run --config vite.projects.ts --project browser --browser chromium --bail 3",
86
+ "test:all": "vitest --run --config vite.projects.ts --bail 3",
87
+ "test": "run-s test:node test:browser",
88
+ "========================= dev =========================": "",
89
+ "kill-node": "taskkill /F /IM node.exe",
90
+ "kill-java": "taskkill /F /IM java.exe",
91
+ "kill-chrome": "taskkill /F /IM chrome.exe",
92
+ "========================= mcp =========================": "",
93
+ "mcp:playwright": "mcp-server-playwright --port 8002 --host local.host --isolated",
94
+ "mcp:tools": "mcp-project-tools",
95
+ "========================= other =========================": "",
96
+ "dep:fix": "tsx tools/dep-fix.ts"
97
+ },
65
98
  "devDependencies": {
66
99
  "@eslint/compat": "1.2.4",
67
100
  "@eslint/eslintrc": "3.2.0",
@@ -69,7 +102,6 @@
69
102
  "@flemist/copy-glob-flat": "0.0.5",
70
103
  "@flemist/mcp-project-tools": "5.0.2",
71
104
  "@flemist/test-utils": "1.0.4",
72
- "@flemist/test-variants": "5.0.8",
73
105
  "@types/eslint": "9.6.1",
74
106
  "@types/node": "22.12.0",
75
107
  "@typescript-eslint/eslint-plugin": "8.19.0",
@@ -100,40 +132,11 @@
100
132
  "@flemist/async-utils": "^1.2.8",
101
133
  "@flemist/pairing-heap": "^1.0.0",
102
134
  "@flemist/priority-queue": "^1.0.1",
135
+ "@flemist/test-variants": "^5.0.8",
103
136
  "@flemist/time-controller": "^1.0.4",
104
137
  "@flemist/time-limits": "^2.0.4",
105
138
  "fflate": "^0.8.2",
106
139
  "picomatch": "^4.0.4",
107
140
  "tslib": ">=2.8.1"
108
- },
109
- "scripts": {
110
- "========================= install =========================": "",
111
- "install:playwright": "pnpm exec playwright install --with-deps",
112
- "========================= deploy =========================": "",
113
- "build": "vite build",
114
- "========================= lint =========================": "",
115
- "audit": "pnpm audit --prod",
116
- "lint:es": "eslint .",
117
- "lint:es:fix": "eslint --fix .",
118
- "lint": "run-p lint:es",
119
- "lint:fix": "run-s lint:es:fix",
120
- "lint-staged": "lint-staged",
121
- "check:types": "tsc --noEmit",
122
- "check": "run-p audit check:types lint",
123
- "========================= test =========================": "",
124
- "test:node": "vitest --run --config vite.projects.ts --project node --bail 3",
125
- "test:browser": "vitest --run --config vite.projects.ts --project browser --bail 3",
126
- "test:chrome": "vitest --run --config vite.projects.ts --project browser --browser chromium --bail 3",
127
- "test:all": "vitest --run --config vite.projects.ts --bail 3",
128
- "test": "run-s test:node test:browser",
129
- "========================= dev =========================": "",
130
- "kill-node": "taskkill /F /IM node.exe",
131
- "kill-java": "taskkill /F /IM java.exe",
132
- "kill-chrome": "taskkill /F /IM chrome.exe",
133
- "========================= mcp =========================": "",
134
- "mcp:playwright": "mcp-server-playwright --port 8002 --host local.host --isolated",
135
- "mcp:tools": "mcp-project-tools",
136
- "========================= other =========================": "",
137
- "dep:fix": "tsx tools/dep-fix.ts"
138
141
  }
139
- }
142
+ }
@@ -1,17 +0,0 @@
1
- "use strict";const ft=require("@flemist/abort-controller-fast"),Ct=require("@flemist/time-controller"),b=require("@flemist/async-utils"),Jt=require("fflate");function Ht(t){if(!t||t.timeout==null)return null;const e=new ft.AbortControllerFast,r=t.timeController??Ct.timeControllerDefault;if(t.timeout){const n=r.setTimeout(()=>{e.abort(new ft.AbortError(`[timeoutAbortController] Timeout error: ${t.timeout}ms`))},t.timeout);e.signal.subscribe(()=>{clearTimeout(n)})}return t.abortSignal?.subscribe(n=>{e.abort(n)}),e}async function Ye(t,e){const r=Ht(e);try{return await t(r?.signal??e?.abortSignal??null)}finally{r?.abort()}}class Ze{_options;_hasValue=!1;_promiseOrValue=null;constructor(e){this._options=e}run(){if(!this._hasValue){let e=this._options.func();const r=s=>(this._options.persist?this._promiseOrValue=s:(this._promiseOrValue=null,this._hasValue=!1),s),n=s=>{throw this._options.persist||(this._promiseOrValue=null,this._hasValue=!1),s};if(b.isPromiseLike(e))e=e.then(r,n);else if(!this._options.persist)return e;this._promiseOrValue=e,this._hasValue=!0}return this._promiseOrValue}set(e){if(!this._options.persist)throw new Error("[Lazy][set] Cannot set value when persist is false");this._hasValue=!0,this._promiseOrValue=e}}class tr{_options;_promiseOrValues=new Map;constructor(e){this._options=e}run(e){if(this._promiseOrValues.has(e))return this._promiseOrValues.get(e);let r=this._options.func(e);const n=o=>(this._options.persist?this._promiseOrValues.set(e,o):this._promiseOrValues.delete(e),o),s=o=>{throw this._options.persist||this._promiseOrValues.delete(e),o};if(b.isPromiseLike(r))r=r.then(n,s);else if(!this._options.persist)return r;return this._promiseOrValues.set(e,r),r}set(e,r){if(!this._options.persist)throw new Error("[LazyWithId][set] Cannot set value when persist is false");this._promiseOrValues.set(e,r)}}class Qt{_lockPromise=null;get hasQueued(){return this._lockPromise!=null}lock(e){if(this._lockPromise)return b.promiseLikeToPromise(this._lockPromise.then(()=>this.lock(e)));const r=e();if(b.isPromiseLike(r)){const n=r.then(()=>{this._lockPromise===n&&(this._lockPromise=null)},()=>{this._lockPromise===n&&(this._lockPromise=null)});this._lockPromise=n}return b.promiseLikeToPromise(r)}}class Xt{_lockers=new Map;lock(e,r){let n=this._lockers.get(e);n==null&&(n=new Qt,this._lockers.set(e,n));const s=()=>{n.hasQueued||this._lockers.delete(e)};let o;try{o=n.lock(r)}catch(i){throw s(),i}return b.isPromiseLike(o)?o.then(i=>(s(),i),i=>{throw s(),i}):(s(),o)}hasQueued(e){const r=this._lockers.get(e);return r!=null&&r.hasQueued}}var $t=(t=>(t[t.none=0]="none",t[t.error=1]="error",t[t.warn=2]="warn",t[t.debug=3]="debug",t))($t||{});async function er(t){const e=t.abortSignal??null,r=t.timeController??Ct.timeControllerDefault;let n=0;for(;;)try{return await t.func({abortSignal:e})}catch(s){if((t.logLevel==null||t.logLevel>=$t.error)&&console.error("[withRetry] error",s),e?.aborted)throw s;const o=t.delay({error:s,retryCount:n++,abortSignal:e});if(o==null||(typeof o=="number"?await b.delay(o,e??void 0,r):await o(),e?.aborted))throw s}}function rr({maxRetries:t,delays:e,isRetriableError:r}){return function({retryCount:s,error:o}){if(s==null||t!=null&&s>=t)return null;if(r==null||r(o)){if(Array.isArray(e))return e[Math.min(s,e.length-1)];{const i=e.mult??2;return Math.min(e.min*i**s,e.max)}}return null}}async function k(t){const e=await Promise.allSettled(t),r=[];return e.forEach(n=>{if(n.status==="fulfilled")r.push(n.value);else throw n.reason}),r}class Yt{_options;_statsMap=null;_totalSize=null;_initPromise=null;constructor(e){this._options=e}async loadStatsMap(e){const r=await this._options.storage.getEntries(),n=[];r.forEach((s,o)=>{const i=this._options.converter?this._options.converter.from(s):s;b.isPromiseLike(i)?n.push(i.then(u=>{e(o,u)})):e(o,i)}),await Promise.all(n)}init(){return this._initPromise==null&&(this._initPromise=this._init()),this._initPromise}async _init(){const e=new Map;let r=0;await this.loadStatsMap((n,s)=>{e.set(n,s),r+=s.size}),this._statsMap=e,this._totalSize=r}async getTotalSize(){return await this.init(),this._totalSize}async get(e){return await this.init(),this._statsMap.get(e)??null}async set(e,r){if(await this.init(),r!=null){const n=this._options.converter?await this._options.converter.to(r):r;await this._options.storage.set(e,n);const s=this._statsMap.get(e);this._statsMap.set(e,r),this._totalSize+=r.size-(s?.size??0)}else{await this._options.storage.delete(e);const n=this._statsMap.get(e);n!=null&&(this._statsMap.delete(e),this._totalSize-=n.size)}}async getEntries(){return await this.init(),this._statsMap}}function nr(t,e){return t[1].dateUsed!==e[1].dateUsed?t[1].dateUsed<e[1].dateUsed?-1:1:t[1].size!==e[1].size?t[1].size<e[1].size?-1:1:t[1].dateModified!==e[1].dateModified?t[1].dateModified<e[1].dateModified?-1:1:t[0]!==e[0]?t[0]<e[0]?-1:1:0}class sr{_options;_timeController;_locker;_stats;constructor(e){this._options=e,this._timeController=e.timeController??Ct.timeControllerDefault,this._locker=new Xt,this._stats=new Yt({storage:e.storages.stat,converter:e.converterStat})}async freeUpSpace(e,r,n){if(this._options.totalSize==null)return;const s=this._options.totalSize[0],o=this._options.totalSize[1];if(n>o)throw new Error(`[Cache][freeUpSpace] value size (${n}) exceeds maximum total size (${o})`);let i=await this._stats.getTotalSize();if(i+=n-(r??0),i<=o)return;const u=[],a=await this._stats.getEntries(),c=Array.from(a.entries());c.sort(nr),c.forEach(([l,d])=>{if(l===e||this._locker.hasQueued(l))return;const f=-d.size;(i>o||i+f>s)&&(u.push(this._locker.lock(l,async()=>(await k([this._options.storages.value.delete(l),this._options.storages.error.delete(l)]),this._stats.set(l,null)))),i+=f)}),await k(u)}async getOrCreate(e,r){const n=this._options.converterInput?await this._options.converterInput(e):e;return this._locker.lock(n,async()=>{let s=await this._stats.get(n);if(s==null||this._options.isExpired!=null&&this._options.isExpired(s))await k([this._options.storages.value.delete(n),this._options.storages.error.delete(n),this._stats.set(n,null)]),s=null;else{const[p,f]=await Promise.all([this._options.storages.value.get(n),this._options.storages.error.get(n)]),h=this._timeController.now();if(!s.hasError&&p!=null){const m={...s,dateUsed:h},_=this._options.converterValue?await this._options.converterValue.from(p):p;return await this._stats.set(n,m),_}if(s.hasError&&f!=null){const m={...s,dateUsed:h},_=this._options.converterError?await this._options.converterError.from(f):f;throw await this._stats.set(n,m),_}}let o=null,i=null,u=!1;try{o=await r(e)}catch(p){i=p,u=!0}if(u){const p=this._options.converterError?await this._options.converterError.to(i):i,f=this._options.getSize.error(p)+this._options.getSize.stat();await this.freeUpSpace(n,s?.size,f),await k([this._options.storages.error.set(n,p),this._options.storages.value.delete(n)]);const h=this._timeController.now(),m={dateModified:h,dateUsed:h,size:f,hasError:!0};throw await this._stats.set(n,m),i}const a=this._options.converterValue?await this._options.converterValue.to(o):o,c=this._options.getSize.value(a)+this._options.getSize.stat();await this.freeUpSpace(n,s?.size,c),await k([this._options.storages.value.set(n,a),this._options.storages.error.delete(n)]);const l=this._timeController.now(),d={dateModified:l,dateUsed:l,size:c};return await this._stats.set(n,d),o})}async delete(e){const r=this._options.converterInput?await this._options.converterInput(e):e;return this._locker.lock(r,async()=>{await k([this._options.storages.value.delete(r),this._options.storages.error.delete(r),this._stats.set(r,null)])})}async clear(){const[e,r,n]=await Promise.all([this._options.storages.value.getKeys(),this._options.storages.error.getKeys(),this._options.storages.stat.getKeys()]),s=new Set([...e,...r,...n]),o=[];s.forEach(i=>{const u=this._locker.lock(i,async()=>{const a=[],c=this._options.storages.value.delete(i);b.isPromiseLike(c)&&a.push(c);const l=this._options.storages.error.delete(i);b.isPromiseLike(l)&&a.push(l);const d=this._stats.set(i,null);b.isPromiseLike(d)&&a.push(d),await k(a)});b.isPromiseLike(u)&&o.push(u)}),await k(o)}}class or{_cache=new Map;set(e,r){this._cache.set(e,r)}get(e){return this._cache.get(e)}delete(e){this._cache.delete(e)}clear(){this._cache.clear()}getKeys(){return Array.from(this._cache.keys())}getEntries(){return new Map(this._cache)}}function xt(t){if(t==null)return null;if(Array.isArray(t)){const e=t.length,r=[];for(let n=0;n<e;n++)r.push(xt(t[n]));return r}if(typeof t=="object"){if(t.constructor&&t.constructor!==Object)return t;const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=xt(t[r]));return e}return t}function H(t,e){if(t===e)return!0;if(t==null)return e==null;if(e==null)return!1;if(Array.isArray(t)){if(!Array.isArray(e))return!1;const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(!H(t[n],e[n]))return!1;return!0}if(typeof t=="object"){if(typeof e!="object"||t.constructor&&t.constructor!==Object||e.constructor&&e.constructor!==Object)return!1;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&!H(t[r],Object.prototype.hasOwnProperty.call(e,r)?e[r]:null))return!1;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&!Object.prototype.hasOwnProperty.call(t,r)&&!H(e[r],null))return!1;return!0}return!1}function ir(t,e){if(t==null||e==null)return t==null==(e==null);if(t.size!==e.size)return!1;for(const[r,n]of t)if(!H(n,e.get(r)))return!1;return!0}function ur(t,e){const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(t[n]!==e[n])return!1;return!0}function ht(t){return!t||typeof t!="object"?t:Array.isArray(t)?t.map(ht):t&&Object.keys(t).sort().reduce((e,r)=>{const n=ht(t[r]);return n!=null&&(e[r]=n),e},{})}function ar(t,e){return Object.defineProperty(t,"name",{value:e,configurable:!0}),t}function Zt(t){return t=ht(t),JSON.stringify(t??null)}let it=null;function cr(){if(!it){it=new Array(256);for(let t=0;t<256;t++)it[t]=t.toString(16).padStart(2,"0")}return it}function te(t){const e=cr(),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let s=0,o=r.length;s<o;s++)n+=e[r[s]];return n}let Et=null,ee=null,ut=null,re=null;function lr(){Et||(Et=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ee=new Uint32Array(64),re=new TextEncoder,ut=new Uint8Array(65536))}function ne(t){if(t==null)return null;lr();const e=Et,r=ee,n=re;let s=ut,o;if(typeof t=="string"){const w=t.length*3;s.length<w+128&&(s=ut=new Uint8Array(w+128));const y=n.encodeInto(t,s);o=s.subarray(0,y.written)}else if(t instanceof Uint8Array)o=t;else if(ArrayBuffer.isView(t))o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else throw new Error(`[sha256Buffer] Unsupported content type: ${typeof t}`);const i=o.length,u=i+72>>>6<<6;s.length<u&&(s=ut=new Uint8Array(u)),o!==s&&s.set(o),s[i]=128;for(let w=i+1;w<u;w++)s[w]=0;const a=i*8,c=a/4294967296|0,l=a|0;s[u-8]=c>>>24,s[u-7]=c>>>16,s[u-6]=c>>>8,s[u-5]=c,s[u-4]=l>>>24,s[u-3]=l>>>16,s[u-2]=l>>>8,s[u-1]=l;let d=1779033703,p=-1150833019,f=1013904242,h=-1521486534,m=1359893119,_=-1694144372,O=528734635,E=1541459225;for(let w=0;w<u;w+=64){for(let S=0;S<16;S++){const x=w+(S<<2);r[S]=s[x]<<24|s[x+1]<<16|s[x+2]<<8|s[x+3]}for(let S=16;S<64;S++){const x=r[S-15],N=r[S-2],bt=(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3,ot=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10;r[S]=r[S-16]+bt+r[S-7]+ot|0}let y=d,A=p,nt=f,_t=h,T=m,st=_,W=O,wt=E;for(let S=0;S<64;S+=4)for(let x=0;x<4;x++){const N=S+x,bt=(T>>>6|T<<26)^(T>>>11|T<<21)^(T>>>25|T<<7),ot=wt+bt+(W^T&(st^W))+e[N]+r[N]|0,Xe=((y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10))+(y&A^nt&(y^A))|0;wt=W,W=st,st=T,T=_t+ot|0,_t=nt,nt=A,A=y,y=ot+Xe|0}d=d+y|0,p=p+A|0,f=f+nt|0,h=h+_t|0,m=m+T|0,_=_+st|0,O=O+W|0,E=E+wt|0}const M=new Uint8Array(32),K=[d,p,f,h,m,_,O,E];for(let w=0;w<8;w++){const y=K[w],A=w<<2;M[A]=y>>>24,M[A+1]=y>>>16&255,M[A+2]=y>>>8&255,M[A+3]=y&255}return M}function se(t){const e=ne(t);return e?te(e):null}function fr(t){const e=Zt(t);return se(e)}function hr(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function mr(t,e){return t==null?e:r=>t(r,n=>e(n))}function oe(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function ie(t,e){return t==null?e:(r,n)=>t(r,s=>e(s,n))}function ue(t,e){return t==null?e:{to:oe((r,n)=>t.to(r,n),(r,n)=>e.to(r,n))}}function ae(t,e){return t==null?e:{from:ie((r,n)=>t.from(r,n),(r,n)=>e.from(r,n))}}function pr(t,e){return t==null?e:{to:ue(t,e).to,from:ae(t,e).from}}function ce(t,e){return t==null?e:r=>t(r,n=>e(n))}function le(t,e){return t==null?e:r=>t(r,n=>e(n))}function fe(t,e){return t==null?e:{to:ce((r,n)=>t.to(r,n),r=>e.to(r))}}function he(t,e){return t==null?e:{from:le((r,n)=>t.from(r,n),r=>e.from(r))}}function dr(t,e){return t==null?e:{to:fe(t,e).to,from:he(t,e).from}}const Mt={to:t=>JSON.stringify(t??null,null,2),from:t=>JSON.parse(t)},Q={to:t=>new TextEncoder().encode(t),from:t=>new TextDecoder().decode(t)},gr={to:t=>{const e=Mt.to(t);return Q.to(e)},from:t=>{const e=Q.from(t);return Mt.from(e)}};function yr(t){return t==null?null:t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&rt;";case'"':return"&quot;";default:return"&#039;"}})}function _r(t){return t==null?null:t?.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&")}function At(t,e,r){const n=e==null?t:new Date(t.toLocaleString("en-US",{timeZone:e})),s=r==null?t:new Date(t.toLocaleString("en-US",{timeZone:r}));return new Date(t.getTime()+s.getTime()-n.getTime())}function me(t,e){t=At(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),o=t.getUTCHours().toString().padStart(2,"0"),i=t.getUTCMinutes().toString().padStart(2,"0"),u=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s} ${o}:${i}:${u}`}let wr=0;const St=new WeakMap;function z(t){if(St.has(t))return St.get(t);const e=wr++;return St.set(t,e),e}function q(t,e,r){if(t==null)return null;if(e==null||t.length<=e)return t;const n=r?.appendEllipsis?"…":"",s=n.length+(r?.appendTruncatedLength?String(t.length).length+2:0),o=Math.max(0,e-s),i=r?.appendTruncatedLength?`(${t.length-o})`:"";return o<=0?i+n:r?.fromStart?i+n+t.slice(t.length-o):t.slice(0,o)+n+i}function Wt(t,e){try{return t[e]}catch(r){return"Error: "+(r instanceof Error?r.message:String(r))}}function I(t,e,r,n){const{pretty:s,filter:o,maxDepth:i,maxItems:u,maxStringLength:a,showObjectId:c,showArrayIndex:l,customToString:d}=e??{};if(r==null&&(r=[]),n==null&&(n=new Set),d){const f=d(t,r,h=>I(h,e,r,n));if(f!=null)return q(f,a,e?.truncateOptions)}const p=r.length;if(typeof t=="string")return t=q(t,a,e?.truncateOptions),n.size>0&&(t=JSON.stringify(t)),t;if(t==null||typeof t!="object")return String(t);if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return`${t.constructor?.name??""}#${z(t)}[${t.byteLength}]`;if(t instanceof RegExp)return q(String(t),a,e?.truncateOptions);if(t instanceof Date)return me(t);if(t instanceof Object){if(n.has(t)||i!=null&&p>=i)return`${t.constructor===Object?"":t.constructor?.name??""}#${z(t)}`;n.add(t)}if(t instanceof Error)return q(t.stack||t.message||String(t),a,e?.truncateOptions);if(Array.isArray(t)){const f=s?" ".repeat(p):"";let h="";c&&(h+=`#${z(t)} `),h+="[";let m=0,_=!1;for(let O=0;O<t.length;O++){if(u!=null&&m>=u){_=!0;break}const E=[...r,String(O)],M=Wt(t,O);if(o!=null&&!o(E,M))continue;const K=I(M,e,E,n);m>0&&(h+=","),s&&(h+=`
2
- `),s&&(h+=`${f} `),l&&(h+=`${O}: `),h+=`${K}`,m++}return _?(m>0&&(h+=","),s?(h+=`
3
- `,h+=`${f} ...
4
- `):h+="...",h+=f,h+="]"):(m>0&&s&&(h+=`
5
- ${f}`),h+="]"),h}if(t instanceof Map){let f="";return c&&(f+=`#${z(t)} `),f+="Map",f+=I(Array.from(t.entries()),e,r,n),f}if(t instanceof Set){let f="";return c&&(f+=`#${z(t)} `),f+="Set",f+=I(Array.from(t.values()),e,r,n),f}{const f=t.constructor===Object?"":t.constructor?.name??"",h=s?" ".repeat(p):"";let m=f?`${f} `:"";c&&(m+=`#${z(t)} `),m+="{";let _=0,O=!1;for(const E in t){if(u!=null&&_>=u){O=!0;break}const M=[...r,E],K=Wt(t,E);if(o!=null&&!o(M,K))continue;const w=I(K,e,M,n);_>0&&(m+=","),s&&(m+=`
6
- `),s&&(m+=`${h} `),m+=`${E}: ${w}`,_++}return O&&(_>0&&(m+=","),s?(m+=`
7
- `,m+=`${h} ...
8
- `):m+="...",m+=h),_>0&&s&&!O&&(m+=`
9
- ${h}`),m+="}",m}}function pe(t,e){t=At(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),o=t.getUTCHours().toString().padStart(2,"0"),i=t.getUTCMinutes().toString().padStart(2,"0"),u=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s}_${o}-${i}-${u}`}const br={to:t=>{const e=I(t,{pretty:!0,maxDepth:10,maxItems:50,maxStringLength:1e3});return Q.to(e)},from:t=>Q.from(t)},Sr={to:t=>Array.from(t.entries()).reduce((e,[r,n])=>(e[r]=n,e),{}),from:t=>new Map(Object.entries(t))},Or={to:t=>Array.from(t),from:t=>new Set(t)};async function xr(t,e){return new Promise((r,n)=>{Jt.gzip(t,{level:e.level},(s,o)=>{s?n(s):r(o)})})}function Er(t){return t[0]===31&&t[1]===139}async function Mr(t){return new Promise((e,r)=>{Jt.gunzip(t,(n,s)=>{n?r(n):e(s)})})}function de(t,e){return t==null?e:e==null?t:Math.min(t,e)}function ge(t,e){return t==null?e:e==null?t:Math.max(t,e)}function Cr(t,e,r){return ge(de(t,e),r)}function $r(t,e){return(t%e+e)%e}function Ar(t){return function(){let r=t+=1831565813;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),(r^r>>>14)/4294967296+.5}}function Tr(){return Math.random()}function kr(){return Math.random()*2**32>>>0}function ye(t){return t!=null?Ar(t):Tr}class mt{_seed;_rnd;constructor(e){this._seed=e,this._rnd=ye(e)}get seed(){return this._seed}nextSeed(){return this.next()*2**32>>>0}nextRandom(){return new mt(this.nextSeed())}next(){return this._rnd()}clone(){return new mt(this._seed)}}function Tt(t,e,r){if(r==null&&(r=e,e=0),r<=e)throw new Error(`[random][randomFloat] toExclusive (${r}) must be greater than from (${e})`);return t.next()*(r-e)+e}function _e(t,e,r){return Math.floor(Tt(t,e,r))}function Ir(t,e){return t.next()<(e??.5)}function vr(t,e,r){if(Array.isArray(e)){const o=e;e=o.length,r=i=>o[i]}if(!r)throw new Error("[random][randomIndexWeighted] getWeight is required");let n=0;for(let o=0;o<e;o++)n+=r(o);if(n===0)return-1;let s=Tt(t,n);for(let o=0;o<e;o++)if(s-=r(o),s<0)return o;return e-1}function kt(t,e){if(e.length===0)throw new Error("[random][randomItem] items is empty");const r=_e(t,e.length);return e[r]}function Pr(t,e,r){if(e.length===0)throw new Error("[random][randomItems] items is empty");const n=[];for(let s=0;s<r;s++)n.push(kt(t,e));return n}function Nr(t,e,r){let n=Object.values(e);return r&&(n=n.filter(r)),kt(t,n)}const we=1073741789,at=(we>>2)-1;function Rr(t=at,e){if(t<=0)throw new Error(`[random][PseudoRandom] count(${t}) must be > 0`);if(t>at)throw new Error(`[random][PseudoRandom] count(${t}) must be <= ${at}`);if(e==null&&(e=Math.floor(Math.random()*t)),e>=t)throw new Error(`[random][PseudoRandom] startFrom(${e}) must be < count(${t})`);let r=e;return function(){return r=(r+we)%t,r}}let B=null;function Dr(){const t=Date.now();return B==null||t>B?(B=t,t):(B++,B)}async function Ur({url:t,timeout:e}={}){t||(t=typeof window<"u"?"/":"https://google.com");let r;try{const n=new ft.AbortControllerFast;r=e?setTimeout(()=>{n.abort()},e):null;const s=await fetch(t,{method:"HEAD",signal:ft.toAbortSignal(n.signal)}),o=s.headers.get("date");if(!o)throw new Error(`[Now][getDateInet] No date header in response: ${s.status} ${t}`);return new Date(o).getTime()}finally{r&&clearTimeout(r)}}function Lr(t){const e=alert;return window.alert=r=>t(e,r),()=>{window.alert=e}}var F=(t=>(t.log="log",t.warn="warn",t.error="error",t.info="info",t.debug="debug",t.trace="trace",t.assert="assert",t))(F||{});const Bt=Object.values(F);function L(t){return function(){t.apply(console,arguments)}}const qt={log:L(console.log),warn:L(console.warn),error:L(console.error),info:L(console.info),debug:L(console.debug),trace:L(console.trace),assert:L(console.assert)};function It(t){return Bt.forEach(e=>{console[e]=(...r)=>{t(qt,e,r)}}),()=>{Bt.forEach(e=>{console[e]=qt[e]})}}function zr(t){return function(r){let n=null;const o=It((u,a,c)=>{try{t(u,a,c)}catch(l){throw n||(n=l),l}}),i=()=>{if(o(),n)throw n};try{const u=r();return b.isPromiseLike(u)?u.then(a=>(i(),a),a=>{throw i(),a}):(i(),u)}catch(u){throw i(),u}}}class vt{_listeners=new Map;_listenersAdd=new Map;_startStopNotifier;_emit;_update;_unsubscribeNotifier=null;_emitLast;_hasLast;_last=void 0;_emitting=!1;_subscribing=!1;_actionOnCycle;constructor({emitLastEvent:e,startStopNotifier:r,hasLast:n,last:s,actionOnCycle:o}={}){this._startStopNotifier=r??null,this._emit=r?i=>this.emit(i):null,this._update=r?i=>this.update(i):null,this._emitLast=e??!1,this._hasLast=n??!1,this._last=s,this._actionOnCycle=o??!1}get hasLast(){return this._hasLast}get last(){return this._last}get hasListeners(){return this._listeners.size>0}subscribe(e){const r={};if(this._emitting?this._listenersAdd.set(r,e):this._listeners.set(r,e),this._subscribing&&this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular subscription detected");if((this._hasLast||this._subscribing&&this._actionOnCycle==="emitLast")&&e(this._last),this._startStopNotifier&&this._listeners.size+this._listenersAdd.size===1)try{this._subscribing=!0,this._unsubscribeNotifier=this._startStopNotifier(this._emit,this._update)??null}finally{this._subscribing=!1}return()=>{if(this._listeners.delete(r),this._listenersAdd.delete(r),this._startStopNotifier&&this._listeners.size===0&&this._listenersAdd.size===0){const n=this._unsubscribeNotifier;this._unsubscribeNotifier=null,n?.()}}}emit(e){if(this._emitting){if(this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular emit detected");this._actionOnCycle==="emitLast"&&(this._last=e,this._hasLast=!0);return}const r=()=>{this._listenersAdd.size>0&&(this._listenersAdd.forEach((n,s)=>{this._listeners.set(s,n)}),this._listenersAdd.clear()),this._emitting=!1};try{this._emitting=!0,this._emitLast&&(this._last=e,this._hasLast=!0);let n;if(this._listeners.forEach(s=>{const o=s(e);b.isPromiseLike(o)&&(n||(n=[]),n.push(o))}),n)return Promise.all(n).then(r,s=>{throw r(),s});r()}catch(n){throw r(),n}}update(e){if(!this._emitLast)throw new Error("[Rx][Subject] update available only for subjects with emitLastEvent");const r=e(this._last);return this.emit(r)}}function jr(t,e){return I(t,{maxDepth:5,maxItems:10,...e})}function Kr(t){return t.map(e=>e&&typeof e=="object"?jr(e):e)}function Fr(t){return`${pe(new Date)} [${t.level.toUpperCase()}] ${Kr(t.args).join(" ")}`}let pt=null,Ot=null;function be(){return Ot||(Ot=new vt({startStopNotifier:t=>(pt=t,()=>{pt=null})})),Ot}function Vr(){return It((t,e,r)=>{e==="assert"&&r[0]===!0||(e===F.error||e===F.warn||e===F.assert)&&(pt&&pt({date:Date.now(),level:e,args:r}),t[e](...r))})}function Wr(t){if(typeof window>"u")return b.EMPTY_FUNC;const{levels:e,predicate:r}=t;return be().subscribe(n=>{if(e&&!e.includes(n.level))return;const s=n.args.join(`
10
- `);r&&!r({text:s,message:n})||alert(s)})}function Se(){let t=new Error().stack;if(t!=null){const e=t.indexOf(`
11
- `);e!=null&&e>=0&&(t=t.substring(e+1))}return t??""}function Br(t){return function(...e){const r=Se();try{return t.apply(this,e)}catch(n){throw n instanceof Error||(n=new Error(String(n))),n.stack=n.stack?n.stack+`
12
- `+r:r,n}}}function qr(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"}class Gr{_subjects=new Map;_getLastEvent;constructor({getLastEvent:e}={}){this._getLastEvent=e}subscribe(e,r){let n=this._subjects.get(e);n||(n=new vt,this._subjects.set(e,n));const s=n.subscribe(r);if(this._getLastEvent){const o=this._getLastEvent(e);r(o)}return()=>{s(),n?.hasListeners||this._subjects.delete(e)}}emit(e,r){const n=this._subjects.get(e);if(n)return n.emit(r)}forEach(e){this._subjects.forEach(e)}observable(e){return{subscribe:r=>this.subscribe(e,r)}}emitter(e){return{emit:r=>this.emit(e,r)}}subject(e){return{subscribe:r=>this.subscribe(e,r),emit:r=>this.emit(e,r)}}}function Jr(t,e,r){return new Promise(n=>{let s=!1,o;function i(l){a?.(),o?.(),s=!0,n(l)}function u(l){a?.(),o?.(),s=!0,n(Promise.reject(l))}const a=r?.subscribe(u);let c=!0;o=t.subscribe(l=>{(!e||e(l,c))&&i(l),c=!1}),s&&o?.()})}class R extends Error{constructor(e){super(e)}}class g{_args;constructor(e){this._args=e&&{...e}}set(e){return this._args={...this._args??{},...e},this}name(e){return this.set({name:e})}toString(e){const r=this._args?.name;return r?typeof r=="string"?r:r(e):this.nameDefault(e)}}function Oe(t,e){return I(t,{maxDepth:1,maxItems:5,...e})}function D(t){return t instanceof g}function Z(t){return Oe(t)}function dt(t,...e){if(t==null)return"";const r=Oe(t,{filter:(n,s)=>{if(n.length===0)return!0;if(n.length!==1)return!1;const o=n[0];return!(o==="name"||o==="expected"||s==null||s===!1||e.includes(o))}});return/^(#\d+\s*)\{}$/.test(r)?"":`(${r})`}function X(t){const{result:e,cause:r,nested:n,error:s}=t;if(s){if(!(s instanceof Error))throw new R(`[test][validateMatchResult] error must be an instance of Error, but it is: ${s}`);if(e!=null)throw new R(`[test][validateMatchResult] result must be null if error is set, but it is: ${e}`);if(r!=null)throw new R(`[test][validateMatchResult] cause must be null if error is set, but it is: ${r}`);if(n!=null)throw new R(`[test][validateMatchResult] nested must be null if error is set, but it is: ${n}`);return t}if(typeof e!="boolean")throw new R(`[test][validateMatchResult] result must be a boolean, but it is: ${e}`);if(typeof r!="string"&&r!=null)throw new R(`[test][validateMatchResult] cause must be a string or null, but it is: ${r}`);if(n!=null&&!(n instanceof Array))throw new R(`[test][validateMatchResult] nested must be an array or null, but it is: ${n}`);return t}function xe(t,e,r){return X({actual:t,expected:e,result:null,cause:null,nested:null,error:r})}function Pt(t,e,r){return X({actual:t,expected:e,result:r,cause:null,nested:null,error:null})}function Nt(t,e,r){return typeof r=="boolean"?Pt(t,e,r):X(typeof r=="string"?{actual:t,expected:e,result:!1,cause:r,nested:null,error:null}:{actual:t,expected:e,result:r.result,cause:r.cause??null,nested:r.nested??null,error:null})}function C(t,e){try{if(D(e)){const r=e.match(t);return Nt(t,e,r)}return Pt(t,e,t===e)}catch(r){return xe(t,e,r)}}class Rt extends g{match(e){const r=this._args.expected,n=C(e,r);return{result:!n.result,nested:[{actualKey:null,result:n}]}}nameDefault(){return"not"}}function Ee(t,e){const r=Dt(t.result,e);return r?{actualKey:t.actualKey,expectedKey:t.expectedKey,result:r}:null}function Dt(t,e){if(e?!t.result:t.result)return null;t.expected instanceof Rt&&(e=!e);let r=null;return t.nested&&t.nested.forEach(n=>{const s=Ee(n,e);s&&(r||(r=[]),r.push(s))}),{actual:t.actual,expected:t.expected,result:t.result,cause:t.cause,nested:r,error:t.error}}function Me(t,e){const r=Ut(t.result,e+" ");return`${e}${t.actualKey==null?"| ":t.actualKey+": "}${r}`}function Ut(t,e){if(t.result)return t.expected.toString();let r="";t.nested&&(r=t.nested.map(s=>Me(s,e)).join(`
13
- `));let n=t.cause||"";return r?(n||(n=D(t.expected)?t.expected.toString(t.actual):""),`${n}
14
- ${r}`):`${n}
15
- ${e}expected: ${D(t.expected)?t.expected.toString(t.actual):t.expected}
16
- ${e}actual: ${Z(t.actual)}`}class Lt extends Error{constructor(e){super(e)}}function G(t){return function(r,n){const s=C(t,r);if(s.error)throw s.error;const o=Dt(s,!1);if(!o)return;const i=Ut(o,"");console.log(`[test][check] CheckError:
17
- `+i);const u=new Lt(i);throw n?.(u),u}}function Hr(t){return function(r,n){let s;try{s=t()}catch(o){G(o)(n);return}return b.isPromiseLike(s)?s.then(o=>(G(o)(r),o)).catch(o=>{if(o instanceof Lt)throw o;try{G(o)(n)}catch(i){throw console.error("[test][check] error",i),o}}):(G(s)(r),s)}}const tt=10;class zt extends g{match(e){if(e==null)return`Expected array, got "${e}"`;if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args?.expected;if(r==null)return!0;const n=this._args?.maxReportItems??tt,s=this._args?.matchType||"equals";if(s==="equals"){if(e.length!==r.length)return`Expected array length to be ${r.length}, got ${e.length}`;let o=!0,i=0,u=0;const a=[];for(let c=0;c<r.length;c++){const l=e[c],d=r[c],p=C(l,d);if(p.result?(i<n&&a.push({actualKey:c,expectedKey:c,result:p}),i++):(u<n&&a.push({actualKey:c,expectedKey:c,result:p}),u++,o=!1),!o&&i>=n&&u>=n)break}return{result:o,nested:a}}if(s==="includes"){let o=!0;const i=[];let u=0,a=0;for(let c=0;c<r.length;c++){const l=r[c];let d=!1;for(let p=0;p<e.length;p++){const f=e[p],h=C(f,l);if(h.result){d=!0,u<n&&i.push({actualKey:p,expectedKey:c,result:h}),u++;break}}if(d||(o=!1,a<n&&i.push({expectedKey:c,result:{result:!1,actual:void 0,expected:l}}),a++),!o&&u>=n&&a>=n)break}return{result:o,nested:i}}return`Unknown matchType "${s}"`}nameDefault(){return`array ${this._args?.matchType||"equals"} ${Z(this._args?.expected)}`}}class Ce extends g{match(){return!0}nameDefault(){return"any"}}class $e extends g{match(e){if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args.expected;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(let a=0;a<e.length;a++){const c=e[a],l=C(c,r);if(l.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:l}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:l}),u++,n=!1),!n&&i>=o&&u>=o)break}return{result:n,nested:s}}nameDefault(){return"array item"}}class Ae extends g{match(e){const{expected:r,convert:n}=this._args,s=C(n(e),r),o=[{result:s}];return{result:s.result,nested:o}}nameDefault(){return"convert"}}class jt extends g{match(e){const{expected:r,nonStrict:n}=this._args;return n?e==r:e===r}nameDefault(){return`is(${Z(this._args.expected)})`}}class Te extends g{match(e){if(e==null)return`Expected number, got "${e}"`;if(typeof e!="number")return`Expected number, got "${typeof e}"`;if(this._args==null)return Number.isFinite(e)?!0:"Expected finite number";if(!this._args.allowNaN&&Number.isNaN(e))return"Expected not NaN";if(!this._args.allowInfinity&&!Number.isFinite(e))return"Expected not Infinity";const{min:r,max:n,float:s}=this._args;return!s&&!Number.isInteger(e)?`Expected integer, got "${e}"`:r!=null&&e<r?`Expected number to be >= ${r}, got ${e}`:n!=null&&e>n?`Expected number to be <= ${n}, got ${e}`:!0}nameDefault(){return`number(${dt(this._args)})`}}class ke extends g{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(const a in r){if(!Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a],l=r[a],d=C(c,l);if(d.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:d}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:d}),u++,n=!1),!n&&i>=o&&u>=o)break}if(!this._args?.ignoreExtraKeys)for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a)||Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a];if(u<o&&s.push({actualKey:a,expectedKey:a,result:Nt(c,void 0,"Unexpected key")}),u++,n=!1,u>=o)break}return{result:n,nested:s}}nameDefault(){return"object"+dt(this._args)}}class Ie extends g{match(e){if(e==null)return`Expected string, got ${e}`;if(typeof e!="string")return`Expected string, got "${typeof e}"`;if(this._args==null)return!0;const{pattern:r}=this._args;if(r!=null){if(typeof r=="function")return r(e);if(!r.test(e))return!1}return!0}nameDefault(){return this._args?.pattern?`string(${this._args.pattern})`:"string"}}class ve extends g{match(e){const r=this._args.expected;return e instanceof r?!0:`Expected instance of "${r}", got "${e}"`}nameDefault(){return`instanceOf(${this._args.expected.name})`}}class Pe extends g{constructor(e){super({...e,expected:e.expected instanceof Set?e.expected:new Set(e.expected)})}match(e){return!!this._args.expected.has(e)}nameDefault(){return`in(${Z(this._args.expected)})`}}class et extends g{match(e){const{type:r,expecteds:n,pipe:s}=this._args;let o=r==="and";const i=[];for(let u=0;u<n.length;u++){const a=n[u],c=C(e,a);if(i.push({actualKey:`<${r} ${u}>`,expectedKey:`<${r} ${u}>`,result:c}),r==="or"){if(c.result&&(o=!0,s))break}else if(r==="and"){if(!c.result&&(o=!1,s))break}else throw new Error(`[test][MatcherFew] Unknown type "${r}"`)}return{result:n.length===0||o,nested:i}}nameDefault(){return this._args.type}}class Ne extends g{match(e){const r=this._args.matcher;return D(r)?r.match(e):r(e)}nameDefault(e){const r=this._args.name;return typeof r=="string"?r:r?r(e):"custom"}}class Re extends g{match(){return!1}nameDefault(){return"never"}}class De extends g{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],o=this._args?.maxReportItems??tt;let i=0,u=0;for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a))continue;const c=[a,e[a]],l=C(c,r);if(l.result?(i<o&&s.push({actualKey:a,expectedKey:a,result:l}),i++):(u<o&&s.push({actualKey:a,expectedKey:a,result:l}),u++,n=!1),!n&&i>=o&&u>=o)break}return{result:n,nested:s}}nameDefault(){return"object entries"+dt(this._args)}}class Ue extends g{_hasExpected=!1;_expected=void 0;get expected(){return this._expected}set expected(e){this._expected=e,this._hasExpected=!0}match(e){const r=C(e,this._expected),n=[{result:r}];return{result:r.result,nested:n}}nameDefault(){return"ref"}}function U(t){return new zt({expected:t})}function Qr(t){return new zt({expected:t,matchType:"includes"})}function V(){return new Ce}function Xr(){return new Ue}function Yr(t){return new Re({name:t})}function Zr(t,e){const r=new $e({expected:e});return t==null?r:$(Fe(D(t)||typeof t=="number"?t:rt(t)),r).name("array item")}function v(t,e,r){return new Ae({name:t,convert:e,expected:r})}function Le(t){return new jt({expected:t,nonStrict:!0})}function ze(t){return new jt({expected:t,nonStrict:!1})}function Kt(t){return new Te(t)}function rt(t){return Kt({...t,float:!1})}function tn(t){return Kt({...t,float:!0})}function P(t){return new ke({expected:t})}function ct(t,e,r=null){if(t instanceof g||e&&(t=e(t,r),t instanceof g))return t;if(t==null)return Y();if(Array.isArray(t)){const n=t.map((s,o)=>ct(s,e,o));return U(n)}if(t.constructor===Object){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=ct(t[s],e,s));return P(n)}return t instanceof b.ValueState?qe({...t,value:ct(t.value,e,"value")}):ze(t)}function en(t){return P(t).set({ignoreExtraKeys:!0})}function Ft(t){return new Ie({pattern:t})}function rn(t){return new ve({expected:t})}function je(t){return v("typeof",e=>e===null?"null":typeof e,t)}function nn(t){return v("constructor",e=>e.constructor,t)}function lt(){return je("boolean")}function Y(){return Le(null)}function sn(){return Be(Y())}function on(...t){return new et({expecteds:t,type:"or",pipe:!1})}function un(...t){return new et({expecteds:t,type:"and",pipe:!1})}function Ke(...t){return new et({expecteds:t,type:"or",pipe:!0})}function $(...t){return new et({expecteds:t,type:"and",pipe:!0})}function j(t,e){return e==null?Ke(Y(),t):e?t:Y()}function Fe(t){const e=typeof t=="number"||D(t)?t:rt(t??{min:1});return $(U(),v("length",r=>r.length,e)).name("array length")}function an(t){const e=typeof t=="number"||D(t)?t:rt(t??{min:1});return $(Ft(),v("length",r=>r.length,e)).name("string length")}function cn(t){return $(P(),t)}function ln(t){return $(U(),t)}function fn(t){return $(P(),v("keys",e=>Object.keys(e),t))}function hn(t){return $(P(),v("values",e=>Object.values(e),t))}function mn(t){return $(P(),v("entries",e=>Object.entries(e),t))}function gt(t){return new De({expected:t})}function pn(t){return gt(U([t,V()]))}function dn(t){return gt(U([V(),t]))}function gn(t,e){return gt(U([t,e]))}function yn(t){return $(P(),v("keys not null",e=>Object.keys(e).filter(r=>e[r]!=null),t))}function Ve(t){return new Pe({expected:t})}function _n(t){return Ve(Object.values(t))}function Vt(t,e){return new Ne({matcher:e,name:t})}const wn=Math.ceil(Date.now()-10*365.25*24*60*60*1e3),bn=Math.ceil(Date.now()+10*365.25*24*60*60*1e3);function J(t){return rt({...t,min:t?.min??wn,max:t?.max??bn}).name("int date")}function We(t){const e={min:t?.from?.min??t?.common?.min,max:t?.from?.max??t?.common?.max,float:t?.from?.float??t?.common?.float,optional:t?.from?.optional??t?.common?.optional},r={min:t?.to?.min??t?.common?.min,max:t?.to?.max??t?.common?.max,float:t?.to?.float??t?.common?.float,optional:t?.to?.optional??t?.common?.optional};return $(U([e.optional?j(J()):J(),r.optional?j(J()):J()]),Vt("min <= max",n=>n[0]!=null&&n[1]!=null&&n[0]>n[1]?`Expected range to be [min, max], got [${n.join(", ")}]`:!0)).name("range")}function Sn(t){return We({...t,common:{min:new Date(2020,0,1).getTime(),max:Date.now()+900*1e3,...t?.common}}).name("range date")}function Be(t){return new Rt({expected:t})}function On(){return Ft(/^[\da-f-]{36}|[\da-f]{32}$/i).name("uuid")}function qe(t){return P({[Symbol.toStringTag]:j(V()),loading:j(lt()),hasValue:j(lt()),value:V(),hasError:j(lt()),error:V(),...t})}function xn(t){return t!=null&&typeof t=="string"&&(t=new TextEncoder().encode(t).buffer),Vt("array buffer",e=>{if(e==null||typeof e!="object"||typeof e.byteLength!="number")return`Expected array buffer, got "${e}"`;if(t==null)return!0;if(e.byteLength!==t.byteLength)return`Expected array buffer length to be ${t.byteLength}, got ${e.byteLength}`;for(let r=0,n=t.byteLength;r<n;r++)if(e[r]!==t[r])return`Expected array buffer[${r}] to be ${t[r]}, got ${e[r]}`;return!0})}function Gt(t){return t.replace(/\W/g,"").toLowerCase()}function Ge(t){return t instanceof URL?t.searchParams:t instanceof URLSearchParams?t:typeof t=="string"?new URL(t).searchParams:typeof window<"u"?new URL(window.location.href).searchParams:new URLSearchParams}function Je(t){return t==null?null:(t=t.toLowerCase().trim(),t==="true"||t==="1"||t==="yes"?!0:t==="false"||t==="0"||t==="no"?!1:null)}function He(t){if(t==null)return null;t=t.trim();const e=parseInt(t,10);return isNaN(e)?null:e}function Qe(t){if(t==null)return null;t=t.trim();const e=parseFloat(t);return isNaN(e)?null:e}function yt(t,e){const r=Ge(e),n=Gt(t);for(const[s,o]of r.entries())if(Gt(s)===n)return o;return null}function En(t,e){return Je(yt(t,e))}function Mn(t,e){return He(yt(t,e))}function Cn(t,e){return Qe(yt(t,e))}exports.Cache=sr;exports.CacheStats=Yt;exports.CheckError=Lt;exports.ConsoleMessageLevel=F;exports.Lazy=Ze;exports.LazyWithId=tr;exports.Locker=Qt;exports.LockerWithId=Xt;exports.LogLevel=$t;exports.MAX_REPORT_ITEMS_DEFAULT=tt;exports.MatchInternalError=R;exports.Matcher=g;exports.MatcherAny=Ce;exports.MatcherArray=zt;exports.MatcherArrayItem=$e;exports.MatcherConvert=Ae;exports.MatcherCustom=Ne;exports.MatcherFew=et;exports.MatcherIn=Pe;exports.MatcherInstanceOf=ve;exports.MatcherIs=jt;exports.MatcherNever=Re;exports.MatcherNot=Rt;exports.MatcherNumber=Te;exports.MatcherObject=ke;exports.MatcherObjectEntry=De;exports.MatcherRef=Ue;exports.MatcherString=Ie;exports.MemoryStorage=or;exports.Random=mt;exports.Subject=vt;exports.SubjectWithId=Gr;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=at;exports.alertConsole=Wr;exports.alertReplace=Lr;exports.argsToString=dt;exports.check=G;exports.checkFunc=Hr;exports.compressGzip=xr;exports.consoleIntercept=Vr;exports.consoleMessageToString=Fr;exports.consoleReplace=It;exports.convertTimeZone=At;exports.converterErrorToBuffer=br;exports.converterJson=Mt;exports.converterJsonBuffer=gr;exports.converterStringToBuffer=Q;exports.createMatchResult=Nt;exports.createMatchResultBoolean=Pt;exports.createMatchResultError=xe;exports.createTaskDelayRetry=rr;exports.createUniquePseudoRandom=Rr;exports.dateNowUnique=Dr;exports.decompressGzip=Mr;exports.deepCloneJsonLike=xt;exports.deepEqualJsonLike=H;exports.deepEqualJsonLikeMap=ir;exports.equalArray=ur;exports.escapeHtml=yr;exports.escapeRegExp=_r;exports.expectedToString=Z;exports.filterMatchResult=Dt;exports.filterMatchResultNested=Ee;exports.fixStackTrace=Br;exports.formatAny=I;exports.formatDate=me;exports.formatDateFileName=pe;exports.getConsoleMessages=be;exports.getDateInet=Ur;exports.getHashKey=fr;exports.getJsonKey=Zt;exports.getNormalizedObject=ht;exports.getObjectId=z;exports.getRandomFunc=ye;exports.getRandomSeed=kr;exports.getStackTrace=Se;exports.isGzipCompressed=Er;exports.isMatcher=D;exports.isObservable=qr;exports.mapObjectConverter=Sr;exports.match=C;exports.matchAnd=un;exports.matchAndPipe=$;exports.matchAny=V;exports.matchArray=U;exports.matchArrayBuffer=xn;exports.matchArrayIncludes=Qr;exports.matchArrayItem=Zr;exports.matchArrayLength=Fe;exports.matchArrayWith=ln;exports.matchBoolean=lt;exports.matchConstructor=nn;exports.matchConvert=v;exports.matchCustom=Vt;exports.matchDeep=ct;exports.matchEnum=_n;exports.matchFloat=tn;exports.matchIn=Ve;exports.matchInstanceOf=rn;exports.matchInt=rt;exports.matchIntDate=J;exports.matchIs=ze;exports.matchIsNonStrict=Le;exports.matchNever=Yr;exports.matchNot=Be;exports.matchNotNullish=sn;exports.matchNullish=Y;exports.matchNumber=Kt;exports.matchObject=P;exports.matchObjectEntries=mn;exports.matchObjectEntry=gt;exports.matchObjectKey=pn;exports.matchObjectKeyValue=gn;exports.matchObjectKeys=fn;exports.matchObjectKeysNotNull=yn;exports.matchObjectPartial=en;exports.matchObjectValue=dn;exports.matchObjectValues=hn;exports.matchObjectWith=cn;exports.matchOptional=j;exports.matchOr=on;exports.matchOrPipe=Ke;exports.matchRange=We;exports.matchRangeDate=Sn;exports.matchRef=Xr;exports.matchResultNestedToString=Me;exports.matchResultToString=Ut;exports.matchString=Ft;exports.matchStringLength=an;exports.matchTypeOf=je;exports.matchUuid=On;exports.matchValueState=qe;exports.max=ge;exports.min=de;exports.minMax=Cr;exports.numberMod=$r;exports.promiseAllWait=k;exports.randomBoolean=Ir;exports.randomEnum=Nr;exports.randomFloat=Tt;exports.randomIndexWeighted=vr;exports.randomInt=_e;exports.randomItem=kt;exports.randomItems=Pr;exports.setArrayConverter=Or;exports.setFuncName=ar;exports.sha256=se;exports.sha256Buffer=ne;exports.timeoutAbortController=Ht;exports.toConvertFrom=le;exports.toConvertTo=ce;exports.toConvertWithDefaultFrom=ie;exports.toConvertWithDefaultTo=oe;exports.toConverter=dr;exports.toConverterFrom=he;exports.toConverterTo=fe;exports.toConverterWithDefault=pr;exports.toConverterWithDefaultFrom=ae;exports.toConverterWithDefaultTo=ue;exports.toCorrect=mr;exports.toCorrectWithDefault=hr;exports.toHex=te;exports.truncateString=q;exports.urlGetBoolean=En;exports.urlGetFloat=Cn;exports.urlGetInt=Mn;exports.urlGetParams=Ge;exports.urlGetString=yt;exports.urlParamToBoolean=Je;exports.urlParamToFloat=Qe;exports.urlParamToInt=He;exports.validateMatchResult=X;exports.waitObservable=Jr;exports.withConsoleReplace=zr;exports.withRetry=er;exports.withTimeout=Ye;