@creejs/commons-collection
Version:
Commons Collection
1 lines • 73.5 kB
Source Map (JSON)
{"version":3,"file":"index-min.cjs","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../../events/dist/esm/index-min.js","../../lib/time-wheel-cache.js","../../lib/hour24-time-wheel-cache.js","../../lib/index.js"],"sourcesContent":["const t={NOT_FOUND:404,NOT_SUPPORTED:505,NOT_IMPL:501};class r extends Error{static get Code(){return t}static isErrorLike(t){return null!=t&&(\"_\"===t._type&&\"number\"==typeof t.code)}static notFound(t){return new r(`Not Found: ${t}`,404)}static notImpled(){return new r(\"Not Impled Yet\",501)}static notSupported(t){return new r(\"Not Supported:\"+t,505)}static isNotSupported(t){return 505===t?.code}constructor(t,r){super(t),this._type=\"_\",this.code=r}}class e extends Error{static isAggregatedErrorLike(t){return t&&Array.isArray(t.errors)}static isAggregatedError(t){return t instanceof e}constructor(t,r){super(t),this.errors=r??[]}addError(t){this.errors.push(t)}removeError(t){const r=this.errors.indexOf(t);return-1!==r&&(this.errors.splice(r,1),!0)}}var n={constructorName:o,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" Should Not Nil');for(const e of r)if(null!=e)for(const r in e)void 0===t[r]&&(t[r]=e[r]);return t},extend:i,extends:i,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:s,isNode:function(){return!s()},cloneToPlainObject:function(t){if(null==t)return t;if(\"object\"!=typeof t)throw new Error(\"Only Object allowed to clone\");return{...t}},deepCloneToPlainObject:function(t){if(null==t)return t;if(\"object\"!=typeof t)throw new Error(\"Only Object allowed to clone\");return JSON.parse(JSON.stringify(t))}};function o(t){return t?.constructor?.name}function i(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const e of r)if(null!=e)for(const r in e)t[r]=e[r];return t}function s(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var u={isArray:f,isBoolean:a,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:c,isInstance:l,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:m,isPositive:p,isNegative:g,isNotNegative:h,isNil:y,isNullOrUndefined:function(t){return null==t},isNull:w,isUndefined:d,isPlainObject:A,isObject:b,isPromise:E,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:N,isSymbol:$,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:v,isUint8Array:j,isUint8ClampedArray:P,isInt16Array:S,isUint16Array:x,isInt32Array:U,isUint32Array:T,isFloat32Array:I,isFloat64Array:B,isBigInt64Array:k,isBigUint64Array:L,isTypedArray:O,isArrayBuffer:F};function f(t){return Array.isArray(t)}function a(t){return\"boolean\"==typeof t}function c(t){return\"function\"==typeof t}function l(t){return null!=t&&\"object\"==typeof t&&!A(t)}function y(t){return null==t}function p(t){return!!m(t)&&t>0}function h(t){return!!m(t)&&t>=0}function g(t){return!!m(t)&&t<0}function w(t){return null===t}function d(t){return void 0===t}function m(t){return null!=t&&\"number\"==typeof t}function b(t){return null!=t&&\"object\"==typeof t}function A(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function E(t){return null!=t&&\"function\"==typeof t.then}function N(t){return null!=t&&\"string\"==typeof t}function $(t){return null!=t&&\"symbol\"==typeof t}function O(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v(t){return t instanceof Int8Array}function j(t){return t instanceof Uint8Array}function P(t){return t instanceof Uint8ClampedArray}function S(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function I(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function k(t){return t instanceof BigInt64Array}function L(t){return t instanceof BigUint64Array}function F(t){return t instanceof ArrayBuffer}var C={assertNumber:q,assertPositive:_,assertNegative:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Negative: ${t}`)},assertNotNegative:J,assertBoolean:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Boolean: type=${typeof t} value=${Z(t)}`)},assertObject:R,assertPlainObject:function(t,r){if(!A(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not PlainObject: type=${typeof t} value=${Z(t)}`)},assertSymbol:function(t,r){if(!$(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Symbol: type=${typeof t} value=${Z(t)}`)},assertFunction:W,assertInstance:function(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Class Instance: type=${typeof t} value=${Z(t)}`)},assertPromise:H,assertNil:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Neither Null nor Undefined: type=${typeof t} value=${Z(t)}`)},assertNotNil:V,assertNull:function(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Null: type=${typeof t} value=${Z(t)}`)},assertNotNull:function(t,r){if(w(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Should Not Null\")},assertUndefined:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Undefined: type=${typeof t} value=${Z(t)}`)},assertString:M,assertArray:D,assertStringOrSymbol:function(t,r){if(!N(t)&&!$(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not String or Symbol: type=${typeof t} value=${Z(t)}`)},assertInt8Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(k(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(L(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not TypedArray\")},assertArrayBuffer:z};function D(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Array: type=${typeof t} value=${Z(t)}`)}function M(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not String: type=${typeof t} value=${Z(t)}`)}function q(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Number: type=${typeof t} value=${Z(t)}`)}function _(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Positive: ${t}`)}function J(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not \"0 or Positive\": ${t}`)}function R(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Object: type=${typeof t} value=${Z(t)}`)}function W(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Function: type=${typeof t} value=${Z(t)}`)}function H(t,r){if(!E(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Promise: type=${typeof t} value=${Z(t)}`)}function V(t,r){if(y(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Should Not Nil\")}function z(t,r){if(!F(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not ArrayBuffer\")}var G={isEmpty:K,assertNotEmpty:Y,isBlank:Q,assertNotBlank:function(t,r){if(Q(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Is Blank: ${t}`)},capitalize:function(t){if(M(t),0===t.length)return t;const r=t.charAt(0),e=r.toUpperCase();return r===e?t:e+t.slice(1)},decapitalize:function(t){if(M(t),0===t.length)return t;const r=t.charAt(0),e=r.toLowerCase();return r===e?t:e+t.slice(1)},splitWithFixedLength:function(t,r,e=\" \"){if(M(t),q(r),M(e),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,e)];const n=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);n.push(i.padEnd(r,e))}return n},split:function(t,...r){M(t);if(0===t.length)return[];const e=[...r];0===r.length&&r.push(\",\");const n=X(t,...e);if(0===n.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:e}of n)i=t.substring(s,e),o.push(i),s=e+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(M(t),0===r.length)throw new Error(\"At least one marker must be provided\");const e=[];for(const n of new Set(r)){if(K(n))continue;M(n);let r=t.indexOf(n);for(;-1!==r;)e.push({marker:n,index:r}),r=t.indexOf(n,r+n.length)}return e.sort((t,r)=>t.index-r.index),e},findMarkerPositionsRegex:X,substringBefore:function(t,r){if(M(t),M(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(0,e)},substringBeforeLast:function(t,r){if(M(t),M(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(0,e)},substringAfter:function(t,r){if(M(t),M(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringAfterLast:function(t,r){if(M(t),M(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.indexOf(e,n+r.length);if(-1===o)return;return t.substring(n+r.length,o)},substringBetweenGreedy:function(t,r,e){Y(t),Y(r),Y(e);const n=t.indexOf(r);if(-1===n)return;const o=t.lastIndexOf(e);if(-1===o||o<=n)return;return t.substring(n+r.length,o)},substringsBetween:function(t,r,e){Y(t),Y(r),Y(e);const n=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(e,i+r.length);if(-1===s)break;n.push(t.substring(i+r.length,s)),o=s+e.length}return n},safeToString:Z};function K(t){return null==t||(M(t),0===t.length)}function Y(t,r){if(K(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}IsEmpty String: ${t}`)}function Q(t){return null==t||(M(t),0===t.trim().length)}function X(t,...r){if(M(t),0===r.length)throw new Error(\"At least one marker must be provided\");const e=[...new Set(r.filter(t=>null!=t))].map(t=>(M(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),n=new RegExp(e.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=n.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&n.lastIndex++}return o}function Z(t){if(null===t)return\"null\";if(void 0===t)return\"undefined\";let r;try{r=JSON.stringify(t)}catch(e){r=t.toString()}return r}var tt={quiet:function(t,r){W(t);try{const e=t();return E(e)?e.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):e}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){W(t),D(r);try{const e=t();return E(e)?e.catch(t=>r.push(t)):e}catch(t){r.push(t)}}},rt={any:function(t){if(D(t),0===t.length)throw new Error(\"Empty Tasks\");const r=et(),n=[];for(let o=0;o<t.length;o++){const i=t[o];let s;if(u.isPromise(i))s=i;else{if(!u.isFunction(i)){n.push(new Error(`Invalid Task at index ${o}/${t.length-1}: ${i}`));continue}s=ot(i)}s.then(t=>{r.resolve(t)}).catch(o=>{n.push(o),n.length>=t.length&&r.reject(new e(\"All Tasks Failed\",n))})}n.length===t.length&&r.reject(new e(\"All Tasks Failed\",n));return r.promise},defer:et,delay:function(t,r){u.isNumber(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&H(t),q(r=r??1e3);const e=et(),n=Date.now();return t.then((...t)=>{const o=Date.now()-n;o<r?setTimeout(()=>e.resolve(...t),r-o):e.resolve(...t)}).catch(t=>{const o=Date.now()-n;o<r?setTimeout(()=>e.reject(t),r-o):e.reject(t)}),e.promise},timeout:function(t,r,e){H(t),q(r=r??1);const n=et(r,e),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?n.resolve(...t):n.reject(new Error(e??`Promise Timeout: ${r}ms`))}).catch(t=>{!n.resolved&&!n.rejected&&n.reject(t)}),n.promise},allSettled:nt,returnValuePromised:ot,series:async function(t){D(t);const r=[];for(const e of t)if(W(e),u.isFunction(e))r.push(await ot(e));else{if(!u.isPromise(e))throw new Error(`Invalid Task: ${e}`);r.push(await e)}return r},seriesAllSettled:async function(t){D(t);const r=[];for(const e of t){W(e);try{r.push({ok:!0,result:await e()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(D(t),q(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>W(t));const e=[];if(t.length<=r){const r=await Promise.all(t.map(t=>ot(t)));return e.push(...r),e}const n=[];for(const o of t)if(W(o),n.push(o),n.length>=r){const t=await Promise.all(n.map(t=>ot(t)));e.push(...t),n.length=0}if(n.length>0&&n.length<r){const t=await Promise.all(n.map(t=>ot(t)));e.push(...t)}return e},parallelAny:async function(t,r=5,n){if(D(t,\"tasks\"),q(r),0===t.length)throw new Error(\"Empty Tasks\");if(r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);const o=[];let i=0,s=0;const f=et();function a(){if(i>=t.length)return;if(s>r)return;const c=t[i++];let l;s++,l=u.isPromise(c)?c:u.isFunction(c)?ot(c):Promise.reject(new TypeError(`Invalid task: ${typeof c}, Only Promise or Function allowed`)),l.then(t=>{s--,f.resolve(t)}).catch(r=>{o.push(r),o.length>=t.length&&f.pending?f.reject(new e(n??\"All Tasks Failed\",o)):(s--,a())})}const c=Math.min(t.length,r);for(let t=0;t<c;t++)a();return f.promise},parallelAllSettled:async function(t,r=5){if(D(t),q(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>W(t));const e=[];if(t.length<=r){const r=await nt(t.map(t=>ot(t)));return e.push(...r),e}const n=[];for(const o of t)if(n.push(o),n.length>=r){const t=await nt(n.map(t=>ot(t)));e.push(...t),n.length=0}if(n.length>0&&n.length<r){const t=await nt(n.map(t=>ot(t)));e.push(...t)}return e},wait:function(t){J(t);const r={};let e;return r.timerHandler=e=setTimeout(()=>{clearTimeout(e),r._resolve()},t),r.promise=new Promise((t,n)=>{r._resolve=r=>{null!=e&&clearTimeout(e),t(r)}}),r.wakeup=()=>{r._resolve()},r}};function et(t=-1,r){q(t);const e={};let n;return e.pending=!0,e.canceled=!1,e.rejected=!1,e.resolved=!1,t>=0&&(e.timerCleared=!1,e.timerHandler=n=setTimeout(()=>{clearTimeout(n),e.timerCleared=!0,e.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),e.promise=new Promise((t,r)=>{e.resolve=r=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.pending=!1,e.canceled=!1,e.rejected=!1,e.resolved=!0,t(r))},e.reject=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.pending=!1,e.canceled=!1,e.resolved=!1,e.rejected=!0,r(t))}}),e.cancel=e.promise.cancel=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.reject(t??new Error(\"Cancelled\")),e.canceled=e.promise.canceled=!0)},e}async function nt(t){D(t);const r=await Promise.allSettled(t),e=[];for(const t of r)\"fulfilled\"===t.status&&e.push({ok:!0,result:t.value}),\"rejected\"===t.status&&e.push({ok:!1,result:t.reason});return e}function ot(t){try{const r=t();return u.isPromise(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:it}=u;var st={proxy:ut,newProxyInstance:function(t,r,e,n=!0){const o=ut(t,e,n);return Reflect.construct(o,r??[])}};function ut(t,r,e=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!it(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:e}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=e&&\"function\"!=typeof e)throw new TypeError(`Not PropertyHandler.set: type=${typeof e}, value=${JSON.stringify(e)}`)}const n={construct(t,n,o){const i=Reflect.construct(t,n);return new Proxy(e?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,n)}var ft={proxy:function(t,r,e=!0){if(y(t)||!b(t)||f(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(e?Object.preventExtensions(t):t,r??{})}};function at(t){R(t,\"obj\");const r=new Set;let e=t;for(;e&&e!==Object.prototype;){const n=Object.getOwnPropertyNames(e);for(const e of n)\"constructor\"!==e&&\"function\"==typeof t[e]&&r.add(e);e=Object.getPrototypeOf(e)}return[...new Set(r)]}var ct={getMethodsOfClass:function(t){W(t,\"cls\");const r=new Set;let e=t.prototype;for(;e&&e!==Object.prototype;){const t=Object.getOwnPropertyNames(e);for(const n of t)\"constructor\"!==n&&\"function\"==typeof e[n]&&r.add(n);e=Object.getPrototypeOf(e)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){W(t,\"cls\");const r=new Set;let e=t;for(;e&&e!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(e);for(const n of t)\"function\"==typeof e[n]&&r.add(n);e=Object.getPrototypeOf(e)}return[...r]},getMethods:at,getMethodsOfObject:at},lt={startsWith:function(t,r){V(t,\"src\"),V(r,\"searching\");return pt(t.subarray(0,r.length),r)},isSameType:yt,equals:pt};function yt(t,r){return V(t,\"src\"),V(r,\"target\"),o(t)===o(r)}function pt(t,r){if(V(t,\"src\"),V(r,\"target\"),!yt(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(e.getUint8(r)!==n.getUint8(r))return!1;return!0}var ht={readString:function(t,r=0,e){if(z(t),J(r),r>=t.byteLength)return;let n=null;null!=e?(_(e),n=r+e>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,e)):n=new Uint8Array(t,r);return gt.decode(n)},writeString:function(t,r,e=0){z(t,\"buffer\"),M(r,\"str\"),J(e,\"offset\");const n=wt.encode(r),o=n.byteLength;if(e+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${e+o} > ${t.byteLength}`);new Uint8Array(t,e,n.byteLength).set(n)},writeArrayBuffer:function(t,r,e=0,n=0,o){z(t),z(r),q(e),q(n);const i=t.byteLength;if(e<-1*i)e=0;else if(e<0)e+=i;else if(e>=i)throw new Error(`Out of target Bounds: targetOffset(${e}) >= targetLength(${i})`);const s=r.byteLength;if(n<-1*s)n=0;else if(n<0)n+=s;else if(n>=s)throw new Error(`Out of data Bounds: dataOffset(${n}) >= dataArrayBufferLength(${s})`);null!=o&&(_(o,\"dataLength\"),n+o>s&&(o=void 0));const u=new Uint8Array(r,n,o);if(u.byteLength>i-e)throw new Error(`Out of target Bounds: from targetOffset(${e}), No Space to store dataArrayBuffer(${n}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,e)}};const gt=new TextDecoder,wt=new TextEncoder;const dt=1e6;var mt={s2ns:1e9,ms2ns:dt,timestamp:function(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/dt)}return Date.now()},timestamp64:bt,lapseNano:At,lapseMillis:Et,timeoutNano:function(t,r){return At(t)>r},timeoutMillis:function(t,r){return Et(t)>r}};function bt(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*dt)}return BigInt(Date.now()*dt)}function At(t,r){return(r??bt())-t}function Et(t,r){r=r??bt();return BigInt(r-t)/BigInt(dt)}var Nt={first:function(t,r){return D(t,\"arr\"),t[0]??r},chunk:function(t,r){if(D(t,\"array\"),_(r,\"size\"),t.length<=r)return t;const e=[];let n=0;for(;n<t.length;)e.push(t.slice(n,r+n)),n+=r;return e},last:function(t,r){return D(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,e){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(e){if(0!==e(t[n],r[n]))return!1}else if(t[n]!==r[n])return!1;return!0},equalsIgnoreOrder:function(t,r,e){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(e),r.sort(e);for(let n=0;n<t.length;n++)if(e){if(0!==e(t[n],r[n]))return!1}else if(t[n]!==r[n])return!1;return!0}};var $t={_Error:r,AggregatedError:e,LangUtils:n,StringUtils:G,TypeUtils:u,TypeAssert:C,ExecUtils:tt,PromiseUtils:rt,Lang:n,Type:u,Exec:tt,ClassProxyUtils:st,InstanceProxyUtils:ft,ReflectUtils:ct,TypedArrayUtils:lt,ArrayBufferUtils:ht,TimeUtils:mt,ArrayUtils:Nt};export{e as AggregatedError,ht as ArrayBufferUtils,Nt as ArrayUtils,st as ClassProxyUtils,tt as Exec,tt as ExecUtils,ft as InstanceProxyUtils,n as Lang,n as LangUtils,rt as PromiseUtils,ct as ReflectUtils,G as StringUtils,mt as TimeUtils,u as Type,C as TypeAssert,u as TypeUtils,lt as TypedArrayUtils,r as _Error,$t as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * 1. key is the Value stored in CappedSet\n * 2. value is a Node\n * 3. JS Map preserve the insertion order\n * @type {Map<any, Node>}\n */\n this._map = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._map.size\n }\n\n /**\n * get the oldest element\n */\n get oldest () {\n return this._head?.value\n }\n\n /**\n * get the newest element\n */\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._map.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._map.has(value)) {\n const node = this._map.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._map.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._map.has(value)) {\n const node = this._map.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._map.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._map.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._map.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._map.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","var e={isFunction:t,isNil:s};function t(e){return\"function\"==typeof e}function s(e){return null==e}function n(e){return null!=e&&\"string\"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&\"number\"==typeof e}(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,s){if(!t(e))throw new Error(`${s?'\"'+s+'\" ':\"\"}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(s(e))throw new Error((t?'\"'+t+'\" ':\"\")+\"Should Not Nil\")},assertString:function(e,t){if(!n(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!n(e)&&!function(e){return null!=e&&\"symbol\"==typeof e}(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return\"null\";if(void 0===e)return\"undefined\";let t;try{t=JSON.stringify(e)}catch(s){t=e.toString()}return t}new TextDecoder,new TextEncoder;const l=\"DOwner$#$\",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,s=!1){o(e,\"event\"),a(t,\"callback\"),this._event=e,this._callback=t,this._isOnce=!!s,this._owner=void 0}set owner(e){this._owner=e}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this)}catch(e){console.warn(e)}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,\"eventName\"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return[...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return[...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return!1;for(const t of[...this._listeners])t.invoke(...e);return!0}emitOwner(e,...t){if(0===this._listeners.length)return!1;const s=this._owner2Listeners.get(e);if(null==s)return!1;for(const e of[...s])e.invoke(...t);return!0}hasListener(e){return!!h(e)&&this._callbacks.has(e)}hasOwner(e){return!u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,!1,!1)}prependListener(e,t){return this._addListener(e,t,!1,!0)}addOnceListener(e,t){return this._addListener(e,t,!0,!1)}prependOnceListener(e,t){return this._addListener(e,t,!0,!0)}_addListener(e,t,s,n){if(u(e))return!1;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,s);r.owner=t,n?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),!0}removeListener(e){if(u(e))return!1;if(!this._callbacks.has(e))return!1;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return!1;this._callback2Listeners.delete(e);for(const e of t){-1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const s=this._owner2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&this._owner2Listeners.delete(t))}return!0}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:s}=e,n=this._callback2Listeners.get(s);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(s),this._callbacks.delete(s)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r))}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){-1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,s=this._callback2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)))}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=[\"on\",\"once\",\"addListener\",\"prependListener\",\"prependOnceListener\",\"off\",\"offAll\",\"offOwner\",\"removeAllListeners\",\"removeListener\",\"emit\",\"emitOwner\",\"setMaxListeners\",\"getMaxListeners\",\"hasOwner\",\"listeners\",\"listenerCount\",\"eventNames\",\"rawListeners\"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const s of b){const n=t[s];e[s]=n.bind(t)}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10}constructor(){this._name2Event=new Map,this._maxListeners=O}addListener(e,t,s){return this.on(e,t,s)}prependListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,s),this}prependOnceListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,s),this}emit(e,...t){const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emit(...t),!0)}emitOwner(e,t,...s){if(null==t)throw new Error('Missing \"owner\"');const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emitOwner(t,...s),!0)}eventNames(){return[...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,\"eventName\");const s=this._name2Event.get(e);return null==s||s.isEmpty()?0:s.listenerCount(t)}listeners(e){g(e,\"eventName\");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const s=this._name2Event.get(e);return null==s?this:(s.removeListener(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,\"eventName\");const s=this._name2Event.get(e);return null==s?this:(s.removeAllListeners(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,\"owner\");const t=[...this._name2Event.values()];for(const s of t)s.removeAllListeners(e),s.isEmpty()&&this._name2Event.delete(s.name);return this}on(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,s),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`)}once(e,t,s){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,s),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError(\"maxListeners must >=0\");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return!1;for(const t of this._name2Event.values())if(t.hasOwner(e))return!0;return!1}}export{k as EventEmitter,k as default};\n//# sourceMappingURL=index-min.js.map\n","// 3rd\n// internal\nimport { TimeUtils, TypeAssert } from '@creejs/commons-lang'\nimport { EventEmitter } from '@creejs/commons-events'\n// owned\n\n/**\n * @typedef {number} Timestamp\n * @typedef {{\n * tickInterval: number, // ms\n * tickCount: number // ms\n * }} TimeWheelCacheOptions\n */\n\n// module vars\nconst Event = {\n Advance: 'advance',\n Expired: 'expired'\n}\n\n/**\n * Not Found Better Implementation in npmjs.com, so do it by ourselves.\n *\n * Key Points:\n * 1. Basic Atom Unit is \"tick\", 1 tick = 1 tickInterval\n * 3. How many milliseconds does 1 Tick represent is defined by \"tickInterval\"\n * 4. How many Ticks does the Wheel own is defined by \"tickCount\"\n */\nexport default class TimeWheelCache extends EventEmitter {\n get Event () {\n return Event\n }\n\n /**\n * @param {TimeWheelCacheOptions} [options]\n */\n constructor (options) {\n super()\n this.options = options ?? {}\n /**\n * How many milliseconds does one Tick represent\n */\n this._tickInterval = this.options.tickInterval ?? 1000\n /**\n * How many Ticks does the Wheel have\n */\n this._tickCount = this.options.tickCount ?? 60\n /**\n * Slots, one Tick owns one Slot to store key and expire timestamp\n * @type {Map<any, {value: any, slotIndex: number, expireTimestamp: number}>[]}\n */\n this._slots = Array(this._tickCount).fill(undefined).map(() => new Map())\n /**\n * Data Cache\n * @type {Map<any, {value: any, slotIndex: number, expireTimestamp: number}>}\n */\n this._cache = new Map()\n this._currentSlotIndex = 0\n /** @type {NodeJS.Timeout|undefined} */\n this._timer = undefined\n\n // must start it immediately\n this._startAutoEvict()\n }\n\n get tickInterval () {\n return this._tickInterval\n }\n\n get tickCount () {\n return this._tickCount\n }\n\n /**\n * Max Time to Live, atom unit \"millisecond\"\n * @returns {number}\n */\n get maxTtl () {\n if (this._maxTtl == null) {\n this._maxTtl = this._tickCount * this._tickInterval // ms\n }\n return this._maxTtl\n }\n\n assertStarted () {\n if (!this.autoEvictRunning) {\n throw new Error(`${this.constructor.name} is not started`)\n }\n }\n\n get autoEvictRunning () {\n return this._timer != null\n }\n\n _startAutoEvict () {\n this._timer = setInterval(() => this._advance(), this._tickInterval)\n }\n\n _stopAutoEvict () {\n this._timer && clearInterval(this._timer)\n this._timer = undefined\n }\n\n _advance () {\n const nextSlotIndex = (this._currentSlotIndex + 1) % this._tickCount\n const nextSlot = this._slots[nextSlotIndex]\n const currentSlot = this._slots[this._currentSlotIndex]\n this.emit(Event.Advance, this._currentSlotIndex, currentSlot, nextSlot)\n if (currentSlot.size > 0) {\n // clear current slot, and expired data\n for (const key of currentSlot.keys()) {\n const wrapped = this._cache.get(key)\n this._cache.delete(key)\n // @ts-ignore\n this.emit(Event.Expired, key, wrapped.value, wrapped.expireTimestamp)\n }\n currentSlot.clear()\n }\n this._currentSlotIndex = nextSlotIndex\n }\n\n start () {\n if (this.autoEvictRunning) {\n return\n }\n this._startAutoEvict()\n }\n\n stop () {\n if (!this.autoEvictRunning) {\n return\n }\n this._stopAutoEvict()\n }\n\n destroy () {\n this._stopAutoEvict()\n this.clear()\n }\n\n /**\n * 1. \"key\" is not Nil\n * 2. \"value\" is not Nil\n * 3. \"ttl\" must > 0 && <= maxTtl, maxTtl = tickCount * tickInterval\n * * > 0: CAN NOT go to past\n * * < maxTtl: Wheel is Round, eg.\n * * \"Hour Wheel\" has 24 Hour-Tick-Mark\n * * CAN NOT distinguish 24 hours and 48 hours\n * 4. Understand the difference between \"ttl\" and \"timestamp\"\n * * TTL is Indexed from 1\n * * eg. ttl = 60, should be stored in Slot[59]\n * * Timestamp is Indexed from 0\n * @param {any} key\n * @param {any} value\n * @param {number} ttl Time to Live, atom unit \"millisecond\"\n * @returns {boolean}\n */\n set (key, value, ttl) {\n this.assertStarted()\n TypeAssert.assertNotNil(key, 'key')\n TypeAssert.assertNotNil(value, 'value')\n if (ttl <= 0) {\n throw new Error(`Bad ttl \"${ttl}\", must > 0`)\n }\n if (ttl > this.maxTtl) {\n throw new Error(`Bad ttl \"${ttl}\", must <= maxTtl(${this.maxTtl})`)\n }\n // delete existed firstly, Slot may be changed\n if (this._cache.has(key)) {\n this.delete(key)\n }\n // TimeUtils.timestamp() is built on Uptime, not affected by system time change\n const expireTimestamp = TimeUtils.timestamp() + ttl\n // 1 tick at least\n // ttl -1, eg. 1~60s should be stored in Slot[0]\n const ticks = Math.floor((ttl - 1) / this._tickInterval)\n const targetSlotIndex = (this._currentSlotIndex + ticks) % this._tickCount\n const storedItem = { value, slotIndex: targetSlotIndex, expireTimestamp }\n this._slots[targetSlotIndex].set(key, storedItem)\n this._cache.set(key, storedItem)\n return true\n }\n\n /**\n * @param {any} key\n * @returns {boolean}\n */\n delete (key) {\n const wrapped = this._cache.get(key)\n if (!wrapped) {\n return false\n }\n this._cache.delete(key)\n // delete from target slot\n // Time-Wheel may be Minute-Hour-Based, it's too long to leave it in slot\n const { slotIndex } = wrapped\n const targetSlot = this._slots[slotIndex]\n targetSlot.delete(key)\n return true\n }\n\n /**\n * Checks if the cache contains the specified key.\n * @param {any} key - The key to check for existence in the cache.\n * @returns {boolean} - True if the key exists in the cache, false otherwise.\n */\n has (key) {\n const wrapped = this._cache.get(key)\n if (!wrapped) {\n return false\n }\n if (wrapped.expireTimestamp <= TimeUtils.timestamp()) {\n this.delete(key)\n this.emit('expired', key, wrapped.value, wrapped.expireTimestamp)\n return false\n }\n return true\n }\n\n clear () {\n this._cache.clear()\n this._slots.forEach(slot => slot.clear())\n this._currentSlotIndex = 0\n }\n\n /**\n *\n * @param {any} key\n * @returns {any}\n */\n get (key) {\n const wrapped = this._cache.get(key)\n if (!wrapped) {\n return\n }\n if (wrapped.expireTimestamp <= TimeUtils.timestamp()) {\n this.delete(key)\n this.emit('expired', key, wrapped.value, wrapped.expireTimestamp)\n return\n }\n return wrapped.value\n }\n\n size () {\n // current slot may contain expired data\n const slot = this._slots[this._currentSlotIndex]\n if (slot.size > 0) {\n const now = TimeUtils.timestamp()\n for (const [key, { expireTimestamp }] of slot.entries()) {\n if (expireTimestamp <= now) {\n const wrapped = this._cache.get(key)\n // @ts-ignore\n this.emit('expired', key, wrapped.value, wrapped.expireTimestamp)\n slot.delete(key)\n this._cache.delete(key)\n }\n }\n }\n return this._cache.size\n }\n}\n\nexport { TimeWheelCache }\n","// 3rd\n// internal\nimport { TimeUtils } from '@creejs/commons-lang'\nimport { EventEmitter } from '@creejs/commons-events'\n// owned\nimport TimeWheelCache from './time-wheel-cache.js'\n/**\n * @typedef {number} Timestamp\n */\n\n// module vars\nconst SecondInMillisecond = 1_000 // 1s\nconst MinuteInMillisecond = 60_000 // 1m, 60s\nconst HourInMillisecond = 3_600_000 // 1h, 3600s\nconst Hour24InMillisecond = 86_400_000 // 24 hours, 86400s\n\nconst DowngradType = {\n HourToSecond: 'hour->second',\n HourToMinute: 'hour->minute',\n MinuteToSecond: 'minute->second'\n}\n\nconst Event = {\n Downgrade: 'downgrade',\n Expired: 'expired'\n}\n\nconst MaxTtl = Hour24InMillisecond - 1\n\n/**\n * Hour-Minute-Second-Time-Wheel Cache\n * 1. TTL must be less than 24 Hours\n */\nexport default class Hour24TimeWheelCache extends EventEmitter {\n static get DowngradType () {\n return DowngradType\n }\n\n static get Event () {\n return Event\n }\n\n /**\n *\n */\n constructor () {\n super()\n /**\n * Second Wheel:\n * 1. 1 Tick Mark is 1 Second, is 1000 Milliseconds\n * 2. 60 Slots, maximumly, SencondWheel can contain 60 Seconds\n * 3. 60 Seconds should be stored in MinuteWheel\n * * 01 00:00:00.XXX -> 00:00:59.XXX in Slot01 Index00\n * * 02 00:00:01.XXX -> 00:00:01.XXX in Slot02 Index01\n * * 60 00:00:59.XXX -> 00:00:59.XXX in Slot60 Index59\n * @type {TimeWheelCache}\n */\n this._secondWheel = new TimeWheelCache({ tickInterval: SecondInMillisecond, tickCount: 60 })\n /**\n * Minute Wheel:\n * 1. 1 Tick Mark is 1 Minute, is 60 * 1000 Milliseconds\n * 2. 60 Slots, maximumly, MinuteWheel can contain 60 Minutes\n * * 01 00:00:00 -> 00:00:59 in Slot01 Index00\n * * 02 00:01:00 -> 00:01:59 in Slot02 Index01\n * * 60 00:59:00 -> 00:59:59 in Slot60 Index59\n * @type {TimeWheelCache}\n */\n this._minuteWheel = new TimeWheelCache({ tickInterval: MinuteInMillisecond, tickCount: 60 })\n /**\n * Hour Wheel:\n * 1. 1 Tick Mark is 1 Hour, is 60 * 60 * 1000 Milliseconds\n * 2. 24 Slots, maximumly, HourWheel can contain 23:59:59\n * * 01 00:00:00 -> 00:59:59 in Slot01 Index00\n * * 02 01:00:00 -> 01:59:59 in Slot02 Index01\n * * 24 23:00:00 -> 23:59:59 in Slot23 Index23\n * @type {TimeWheelCache}\n */\n this._hourWheel = new TimeWheelCache({ tickInterval: HourInMillisecond, tickCount: 24 })\n /**\n * @type {Map<any, TimeWheelCache>}\n */\n this._cache = new Map()\n this._init()\n }\n\n /**\n * Max Time to Live, atom unit \"millisecond\"\n * @returns {number}\n */\n get maxTtl () {\n return MaxTtl\n }\n\n get autoEvictRunning () {\n return this._secondWheel.autoEvictRunning || this._minuteWheel.autoEvictRunning || this._hourWheel.autoEvictRunning\n }\n\n _init () {\n /**\n * 1. We don't store \"Timetick: < 00:00:01 -> 00:59:59\" into HourWheel, instead, we store them into MinuteWheel\n * 2. When HourWeel advances, take Elements of next Slot, and downgrade them to MinuteWheel\n */\n this._hourWheel.on('advance', (/** @type {number} */currentSlotIndex,\n /** @type {Map<any, {value:any, expireTimestamp: Timestamp}>} */currentSlot,\n /** @type {Map<any, {value:any, expireTimestamp: Timestamp}>} */nextSlot) => {\n for (const [key, { value, expireTimestamp }] of nextSlot) {\n let leftTtl = expireTimestamp - TimeUtils.timestamp()\n let downgradeType\n if (leftTtl <= 0) {\n leftTtl = 1000\n downgradeType = DowngradType.HourToSecond\n this._secondWheel.set(key, value, leftTtl)\n this.emit(Event.Downgrade, key, value, downgradeType, leftTtl)\n } else if (leftTtl < MinuteInMillisecond) {\n downgradeType = DowngradType.HourToSecond\n this._secondWheel.set(key, value, leftTtl)\n this.emit(Event.Downgrade, key, value, downgradeType, leftTtl)\n } else {\n downgradeType = DowngradType.HourToMinute\n this._minuteWheel.set(key, value, leftTtl)\n }\n this._hourWheel.delete(key)\n this.emit(Event.Downgrade, key, value, downgradeType, leftTtl)\n }\n })\n /**\n * 1. We don't store \"Timetick: < 00:01:00 -> 00:01:59\" into MinuteWheel, instead, we store them into SecondWheel\n * 2. When MinuteWheel advances, take Elements of next Slot, and downgrade them to SecondWheel\n */\n this._minuteWheel.on('advance', (/** @type {number} */currentSlotIndex,\n /** @type {Map<any, {value:any, expireTimestamp: Timestamp}>} */currentSlot,\n /** @type {Map<any, {value:any, expireTimestamp: Timestamp}>} */nextSlot) => {\n // console.log('advance', currentSlotIndex)\n for (const [key, { value, expireTimestamp }] of nextSlot) {\n let leftTtl = expireTimestamp - TimeUtils.timestamp()\n if (leftTtl <= 0) {\n leftTtl = 999 // ms\n }\n // console.log('downgrad', key, value, DowngradType.MinuteToSecond, leftTtl)\n this._secondWheel.set(key, value, leftTtl)\n this.emit(Event.Downgrade, key, value, DowngradType.MinuteToSecond, leftTtl)\n this._minuteWheel.delete(key)\n }\n })\n\n this._secondWheel.on('expired', (/** @type {any} */key, /** @type {any} */value, /** @type {Timestamp} */expireTimestamp) => {\n this.emit(Event.Expired, key, value, expireTimestamp)\n })\n }\n\n start () {\n this._secondWheel.start()\n this._minuteWheel.start()\n this._hourWheel.start()\n }\n\n stop () {\n this._secondWheel.stop()\n this._minuteWheel.stop()\n this._hourWheel.stop()\n }\n\n destroy () {\n this._secondWheel.destroy()\n this._minuteWheel.destroy()\n this._hourWheel.destroy()\n }\n\n /**\n * @param {any} key\n * @param {any} value\n * @param {number} ttl Time To Live, unit \"millisencond\", ttl should < 24 Hours\n * @returns {boolean}\n */\n set (key, value, ttl) {\n if (ttl <= 0) {\n throw new Error(`Bad ttl \"${ttl}\", must > 0`)\n }\n /**\n */\n let wheel\n if (ttl < MinuteInMillisecond) { // Timetick: 00:00:01 -> 00:00:59\n wheel = this._secondWheel\n } else if (ttl < HourInMillisecond) { // Timetick: < 00:00:01 -> 00:59:59\n wheel = this._minuteWheel\n } else if (ttl < Hour24InMillisecond) { // Timetick: 01:00:00 -> 23:59:59\n wheel = this._hourWheel\n } else {\n throw new Error('\"ttl\" Should <= Millisencod Of 24 Hours')\n }\n wheel.set(key, value, ttl)\n this._cache.set(key, wheel)\n return true\n }\n\n /**\n * @param {any} key\n * @returns {boolean}\n */\n delete (key) {\n const wheel = this._cache.get(key)\n if (!wheel) {\n return false\n }\n return wheel.delete(key)\n }\n\n /**\n * Checks if the cache contains the specified key.\n * @param {any} key - The key to check for existence in the cache.\n * @returns {boolean} - True if the key exists in the cache, false otherwise.\n */\n has (key) {\n const wheel = this._cache.get(key)\n if (!wheel) { // No wheel, No Data\n return false\n }\n if (wheel.has(key)) { // In Wheel, Has Data\n return true\n }\n // current wheel is second-Wheel, Not existed or expired\n if (wheel === this._secondWheel) {\n return false\n }\n // Not In Wheel, It may be down-graded to lower wheel\n if (wheel === this._hourWheel) { // current wheel is hour, check minute wheel\n return this._minuteWheel.has(key)\n } else if (wheel === this._minuteWheel) { // current wheel is minute, check second wheel\n return this._secondWheel.has(key)\n }\n // It doesn't exist actually\n return false\n }\n\n clear () {\n this._secondWheel.clear()\n this._minuteWheel.clear()\n this._hourWheel.clear()\n this._cache.clear()\n }\n\n /**\n *\n * @param {any} key\n * @returns {any}\n */\n get (key) {\n const wheel = this._cache.get(key)\n if (!wheel) { // No wheel, No Data\n return\n }\n const value = wheel.get(key)\n if (value != null) { // In Wheel, Has Data\n return value\n }\n // current wheel is second-Wheel, Not existed or expired\n if (wheel === this._secondWheel) {\n return\n }\n // Not In Wheel, It may be down-graded to lower wheel\n if (wheel === this._hourWheel) { // current wheel is hour, check minute wheel\n return this._minuteWheel.get(key)\n } else if (wheel === this._minuteWheel) { // current wheel is minute, check second wheel\n return this._secondWheel.get(key)\n }\n // It doesn't exist actually\n return undefined\n }\n\n size () {\n return this._hourWheel.size() + this._minuteWheel.size() + this._secondWheel.size()\n }\n}\n\nexport { Hour24TimeWheelCache, DowngradType, Event }\n","import CappedSet from './capped-set.js'\nimport TimeWheelCache from './time-wheel-cache.js'\nimport Hour24TimeWheelCache from './hour24-time-wheel-cache.js'\n\nexport default { CappedSet, TimeWheelCache, Hour24TimeWheelCache }\nexport { CappedSet, TimeWheelCache, Hour24TimeWheelCache }\n"],"names":["y","t","w","m","A","constructor","Object","N","$","C","assertNumber","r","Error","Z","assertPositive","p","assertNegative","g","assertNotNegative","h","assertBoolean","a","assertObject","b","assertPlainObject","assertSymbol","assertFunction","c","assertInstance","l","assertPromise","then","E","assertNil","assert