{"version":3,"file":"index.mjs","sources":["../src/clone.ts","../src/index.ts"],"sourcesContent":["/**\n * Deep-clone wrapper around the native `structuredClone`.\n *\n * `structuredClone` cannot copy functions, Promises, Errors or class instances\n * (their methods become inaccessible after cloning). For those values we fall\n * back to returning the original reference, which matches how typical caches\n * are expected to behave for non-serialisable payloads.\n */\nconst isStructuredCloneable = (value: unknown): boolean => {\n\tif (value === null) return true;\n\tconst t = typeof value;\n\tif (\n\t\tt === 'string' ||\n\t\tt === 'number' ||\n\t\tt === 'boolean' ||\n\t\tt === 'bigint' ||\n\t\tt === 'undefined'\n\t) {\n\t\treturn true;\n\t}\n\tif (t === 'function') return false;\n\tif (t !== 'object') return false;\n\tif (value instanceof Promise) return false;\n\tif (value instanceof Error) return false;\n\treturn true;\n};\n\nconst clone = <T>(value: T): T => {\n\tif (!isStructuredCloneable(value)) {\n\t\treturn value;\n\t}\n\ttry {\n\t\treturn structuredClone(value);\n\t} catch {\n\t\t// Fallback for objects containing non-cloneable parts (functions, etc.)\n\t\treturn value;\n\t}\n};\n\nexport default clone;\n","/**\n * node-internal-cache\n * https://github.com/etroynov/node-internal-cache\n *\n * Released under the MIT license\n * https://github.com/etroynov/node-internal-cache/blob/master/LICENSE\n */\n\nimport { EventEmitter } from 'node:events';\n\nimport clone from './clone';\n\nexport type Key = string | number;\n\nexport interface WrappedValue<T> {\n\t/** absolute expiration timestamp in ms; 0 means never expires */\n\tt: number;\n\t/** stored value */\n\tv: T;\n\t/** marker so set(key, undefined) round-trips correctly */\n\thasValue: boolean;\n}\n\nexport interface ValueSetItem<T = unknown> {\n\tkey: Key;\n\tval: T;\n\tttl?: number;\n}\n\nexport interface Stats {\n\thits: number;\n\tmisses: number;\n\tkeys: number;\n\tksize: number;\n\tvsize: number;\n}\n\nexport interface Options {\n\tforceString?: boolean;\n\tobjectValueSize?: number;\n\tpromiseValueSize?: number;\n\tarrayValueSize?: number;\n\tstdTTL?: number;\n\tcheckperiod?: number;\n\tuseClones?: boolean;\n\tdeleteOnExpire?: boolean;\n\tmaxKeys?: number;\n}\n\ntype ErrorCode =\n\t| 'ENOTFOUND'\n\t| 'ECACHEFULL'\n\t| 'EKEYTYPE'\n\t| 'EKEYSTYPE'\n\t| 'ETTLTYPE';\n\nexport interface CacheError extends Error {\n\tname: string;\n\terrorcode: string;\n\tdata: { type?: string };\n}\n\nconst ERROR_TEMPLATES: Record<ErrorCode, string> = {\n\tENOTFOUND: 'Key `__key` not found',\n\tECACHEFULL: 'Cache max keys amount exceeded',\n\tEKEYTYPE:\n\t\t'The key argument has to be of type `string` or `number`. Found: `__key`',\n\tEKEYSTYPE: 'The keys argument has to be an array.',\n\tETTLTYPE: 'The ttl argument has to be a number.',\n};\n\nconst VALID_KEY_TYPES = ['string', 'number'] as const;\nconst MS_PER_SEC = 1000;\nconst NEVER_EXPIRES = 0;\n\nconst emptyStats = (): Stats => ({\n\thits: 0,\n\tmisses: 0,\n\tkeys: 0,\n\tksize: 0,\n\tvsize: 0,\n});\n\nexport type NodeCacheEvents = {\n\tset: [key: Key, value: unknown];\n\tdel: [key: Key, value: unknown];\n\texpired: [key: Key, value: unknown];\n\tmiss: [key: Key];\n\ttake: [key: Key, value: unknown];\n\tflush: [];\n\tflush_stats: [];\n};\n\ninterface TypedEventEmitter<E> {\n\ton<K extends keyof E & string>(\n\t\tevent: K,\n\t\tlistener: (...args: E[K] extends unknown[] ? E[K] : never) => void,\n\t): this;\n\tonce<K extends keyof E & string>(\n\t\tevent: K,\n\t\tlistener: (...args: E[K] extends unknown[] ? E[K] : never) => void,\n\t): this;\n\toff<K extends keyof E & string>(\n\t\tevent: K,\n\t\tlistener: (...args: E[K] extends unknown[] ? E[K] : never) => void,\n\t): this;\n\temit<K extends keyof E & string>(\n\t\tevent: K,\n\t\t...args: E[K] extends unknown[] ? E[K] : never\n\t): boolean;\n}\n\nclass NodeCache extends (EventEmitter as new () => EventEmitter &\n\tTypedEventEmitter<NodeCacheEvents>) {\n\t/** Cache storage */\n\tdata = new Map<Key, WrappedValue<unknown>>();\n\n\t/** Statistics container */\n\tstats: Stats = emptyStats();\n\n\t/** Resolved options */\n\toptions: Required<Options> = {\n\t\tforceString: false,\n\t\tobjectValueSize: 80,\n\t\tpromiseValueSize: 80,\n\t\tarrayValueSize: 40,\n\t\tstdTTL: 0,\n\t\tcheckperiod: 600,\n\t\tuseClones: true,\n\t\tdeleteOnExpire: true,\n\t\tmaxKeys: -1,\n\t};\n\n\tprivate checkTimeout: NodeJS.Timeout | undefined;\n\tprivate inflight = new Map<Key, Promise<unknown>>();\n\n\tconstructor(options: Options = {}) {\n\t\tsuper();\n\n\t\tthis.options = { ...this.options, ...options };\n\n\t\tthis._checkData();\n\t}\n\n\tget<T = unknown>(key: Key): T | undefined {\n\t\tthis._assertKey(key);\n\n\t\tconst entry = this._liveEntry(key);\n\t\tif (entry !== undefined) {\n\t\t\tthis.stats.hits++;\n\t\t\treturn this._unwrap<T>(entry);\n\t\t}\n\n\t\tthis.emit('miss', key);\n\t\tthis.stats.misses++;\n\t\treturn undefined;\n\t}\n\n\tmget<T = unknown>(keys: Key[]): Record<string, T> {\n\t\tif (!Array.isArray(keys)) {\n\t\t\tthrow this._error('EKEYSTYPE');\n\t\t}\n\n\t\tconst out: Record<string, T> = {};\n\t\tfor (const key of keys) {\n\t\t\tthis._assertKey(key);\n\n\t\t\tconst entry = this._liveEntry(key);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tthis.stats.hits++;\n\t\t\t\tout[String(key)] = this._unwrap<T>(entry) as T;\n\t\t\t} else {\n\t\t\t\tthis.emit('miss', key);\n\t\t\t\tthis.stats.misses++;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\tset<T = unknown>(key: Key, value: T, ttl?: number): boolean {\n\t\tthis._assertKey(key);\n\t\tthis._assertTtl(ttl);\n\n\t\tif (\n\t\t\tthis.options.maxKeys > -1 &&\n\t\t\tthis.stats.keys >= this.options.maxKeys &&\n\t\t\t!this.data.has(key)\n\t\t) {\n\t\t\tthrow this._error('ECACHEFULL');\n\t\t}\n\n\t\tconst processedValue =\n\t\t\tthis.options.forceString && typeof value !== 'string'\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: value;\n\n\t\tconst existing = this.data.get(key);\n\t\tif (existing !== undefined) {\n\t\t\tthis.stats.vsize -= this._getValLength(this._unwrap(existing, false));\n\t\t} else {\n\t\t\tthis.stats.ksize += this._getKeyLength(key);\n\t\t\tthis.stats.keys++;\n\t\t}\n\n\t\tthis.data.set(key, this._wrap(processedValue, this._resolveExpiry(ttl)));\n\t\tthis.stats.vsize += this._getValLength(processedValue);\n\n\t\tthis.emit('set', key, processedValue);\n\t\treturn true;\n\t}\n\n\tfetch<T = unknown>(\n\t\tkey: Key,\n\t\tttlOrValue: number | T | (() => T),\n\t\tmaybeValue?: T | (() => T),\n\t): T {\n\t\tif (this.has(key)) {\n\t\t\treturn this.get<T>(key) as T;\n\t\t}\n\n\t\tconst { ttl, value } = this._parseFetchArgs<T | (() => T)>(\n\t\t\tttlOrValue,\n\t\t\tmaybeValue,\n\t\t);\n\t\tconst result = (\n\t\t\ttypeof value === 'function' ? (value as () => T)() : value\n\t\t) as T;\n\t\tthis.set(key, result, ttl);\n\t\treturn result;\n\t}\n\n\tasync fetchAsync<T>(\n\t\tkey: Key,\n\t\tttlOrFn: number | (() => Promise<T> | T),\n\t\tmaybeFn?: () => Promise<T> | T,\n\t): Promise<T> {\n\t\tif (this.has(key)) {\n\t\t\treturn this.get<T>(key) as T;\n\t\t}\n\n\t\tconst existing = this.inflight.get(key);\n\t\tif (existing !== undefined) {\n\t\t\treturn existing as Promise<T>;\n\t\t}\n\n\t\tconst { ttl, value: fn } = this._parseFetchArgs<() => Promise<T> | T>(\n\t\t\tttlOrFn,\n\t\t\tmaybeFn,\n\t\t);\n\n\t\t// Populate the cache before clearing inflight so that any concurrent\n\t\t// caller arriving after the await sees either the inflight promise or\n\t\t// the freshly populated cache entry, never neither.\n\t\tconst promise = Promise.resolve()\n\t\t\t.then(fn)\n\t\t\t.then((result) => {\n\t\t\t\tthis.set(key, result, ttl);\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.inflight.delete(key);\n\t\t\t});\n\n\t\tthis.inflight.set(key, promise);\n\t\treturn promise;\n\t}\n\n\tmset<T = unknown>(keyValueSet: ValueSetItem<T>[]): boolean {\n\t\tif (\n\t\t\tthis.options.maxKeys > -1 &&\n\t\t\tthis.stats.keys + keyValueSet.length > this.options.maxKeys\n\t\t) {\n\t\t\tthrow this._error('ECACHEFULL');\n\t\t}\n\n\t\tfor (const { key, ttl } of keyValueSet) {\n\t\t\tif (ttl !== undefined && typeof ttl !== 'number') {\n\t\t\t\tthrow this._error('ETTLTYPE');\n\t\t\t}\n\t\t\tthis._assertKey(key);\n\t\t}\n\t\tfor (const { key, val, ttl } of keyValueSet) {\n\t\t\tthis.set(key, val, ttl);\n\t\t}\n\t\treturn true;\n\t}\n\n\tdel(keys: Key | Key[]): number {\n\t\tconst arr = Array.isArray(keys) ? keys : [keys];\n\n\t\tlet delCount = 0;\n\t\tfor (const key of arr) {\n\t\t\tthis._assertKey(key);\n\t\t\tconst entry = this.data.get(key);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tthis.stats.vsize -= this._getValLength(this._unwrap(entry, false));\n\t\t\t\tthis.stats.ksize -= this._getKeyLength(key);\n\t\t\t\tthis.stats.keys--;\n\t\t\t\tdelCount++;\n\t\t\t\tthis.data.delete(key);\n\t\t\t\tthis.emit('del', key, entry.v);\n\t\t\t}\n\t\t}\n\t\treturn delCount;\n\t}\n\n\ttake<T = unknown>(key: Key): T | undefined {\n\t\tthis._assertKey(key);\n\n\t\tconst entry = this._liveEntry(key);\n\t\tif (entry === undefined) {\n\t\t\tthis.emit('miss', key);\n\t\t\tthis.stats.misses++;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.stats.hits++;\n\t\tconst value = this._unwrap<T>(entry);\n\t\tthis.del(key);\n\t\tthis.emit('take', key, value);\n\t\treturn value;\n\t}\n\n\tttl(key: Key, ttl?: number): boolean {\n\t\tif (!key) return false;\n\t\tthis._assertKey(key);\n\t\tthis._assertTtl(ttl);\n\n\t\tconst entry = this._liveEntry(key);\n\t\tif (entry === undefined) return false;\n\n\t\t// Explicit `0` is treated as \"drop the key\" per documented semantics.\n\t\tif (ttl === 0) {\n\t\t\tthis.del(key);\n\t\t\treturn true;\n\t\t}\n\n\t\tconst expiry = this._resolveExpiry(ttl);\n\t\tif (ttl !== undefined && ttl < 0) {\n\t\t\tthis.del(key);\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.data.set(key, this._wrap(entry.v, expiry, false));\n\t\treturn true;\n\t}\n\n\tgetTtl(key: Key): number | undefined {\n\t\tthis._assertKey(key);\n\t\tif (!key) return undefined;\n\t\tconst entry = this._liveEntry(key);\n\t\treturn entry?.t;\n\t}\n\n\tkeys(): string[] {\n\t\treturn Array.from(this.data.keys(), (k) => String(k));\n\t}\n\n\thas(key: Key): boolean {\n\t\treturn this._liveEntry(key) !== undefined;\n\t}\n\n\tgetStats(): Stats {\n\t\treturn this.stats;\n\t}\n\n\tflushAll(startPeriod = true): void {\n\t\tthis.data = new Map();\n\t\tthis.stats = emptyStats();\n\t\tthis._killCheckPeriod();\n\t\tthis._checkData(startPeriod);\n\t\tthis.emit('flush');\n\t}\n\n\tflushStats(): void {\n\t\tthis.stats = emptyStats();\n\t\tthis.emit('flush_stats');\n\t}\n\n\tclose(): void {\n\t\tthis._killCheckPeriod();\n\t}\n\n\t_checkData(startPeriod = true): void {\n\t\tfor (const [key, entry] of this.data) {\n\t\t\tthis._check(key, entry);\n\t\t}\n\n\t\tif (startPeriod && this.options.checkperiod > 0) {\n\t\t\tthis.checkTimeout = setTimeout(\n\t\t\t\t() => this._checkData(startPeriod),\n\t\t\t\tthis.options.checkperiod * MS_PER_SEC,\n\t\t\t);\n\t\t\tthis.checkTimeout.unref?.();\n\t\t}\n\t}\n\n\t_killCheckPeriod(): void {\n\t\tif (this.checkTimeout !== undefined) {\n\t\t\tclearTimeout(this.checkTimeout);\n\t\t\tthis.checkTimeout = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the entry if it exists and has not expired (taking\n\t * `deleteOnExpire` into account); otherwise returns `undefined`.\n\t * Centralises the \"lookup + expiry handling\" path used by get/has/take/etc.\n\t */\n\tprivate _liveEntry(key: Key): WrappedValue<unknown> | undefined {\n\t\tconst entry = this.data.get(key);\n\t\tif (entry === undefined) return undefined;\n\t\treturn this._check(key, entry) ? entry : undefined;\n\t}\n\n\tprivate _check(key: Key, entry: WrappedValue<unknown>): boolean {\n\t\tif (entry.t === NEVER_EXPIRES || entry.t >= Date.now()) {\n\t\t\treturn true;\n\t\t}\n\t\tconst expiredValue = this._unwrap(entry, false);\n\t\tif (this.options.deleteOnExpire) {\n\t\t\tthis.del(key);\n\t\t\tthis.emit('expired', key, expiredValue);\n\t\t\treturn false;\n\t\t}\n\t\tthis.emit('expired', key, expiredValue);\n\t\treturn true;\n\t}\n\n\tprivate _isInvalidKey(key: unknown): boolean {\n\t\treturn !(VALID_KEY_TYPES as readonly string[]).includes(typeof key);\n\t}\n\n\tprivate _assertKey(key: unknown): asserts key is Key {\n\t\tif (this._isInvalidKey(key)) {\n\t\t\tthrow this._error('EKEYTYPE', { type: typeof key });\n\t\t}\n\t}\n\n\tprivate _assertTtl(ttl: unknown): void {\n\t\tif (ttl === undefined || ttl === null) return;\n\t\tif (typeof ttl !== 'number' || Number.isNaN(ttl)) {\n\t\t\tthrow this._error('ETTLTYPE');\n\t\t}\n\t}\n\n\t/**\n\t * Convert a relative TTL (in seconds) into an absolute expiry timestamp.\n\t * `undefined` falls back to `stdTTL`. Returns `0` when the entry should\n\t * never expire.\n\t */\n\tprivate _resolveExpiry(ttl: number | undefined): number {\n\t\tconst seconds = ttl == null ? this.options.stdTTL : ttl;\n\t\tif (seconds === 0) return NEVER_EXPIRES;\n\t\tif (seconds < 0) return Date.now() - 1; // already expired\n\t\treturn Date.now() + seconds * MS_PER_SEC;\n\t}\n\n\tprivate _parseFetchArgs<V>(\n\t\tttlOrValue: number | V,\n\t\tmaybeValue: V | undefined,\n\t): { ttl: number | undefined; value: V } {\n\t\tif (maybeValue === undefined) {\n\t\t\treturn { ttl: undefined, value: ttlOrValue as V };\n\t\t}\n\t\treturn { ttl: ttlOrValue as number, value: maybeValue };\n\t}\n\n\tprivate _wrap<T>(value: T, expiry: number, asClone = true): WrappedValue<T> {\n\t\tconst useClone = this.options.useClones && asClone;\n\t\treturn {\n\t\t\tt: expiry,\n\t\t\tv: useClone ? clone(value) : value,\n\t\t\thasValue: true,\n\t\t};\n\t}\n\n\tprivate _unwrap<T = unknown>(\n\t\tentry: WrappedValue<unknown>,\n\t\tasClone = true,\n\t): T | undefined {\n\t\tif (!entry.hasValue) return undefined;\n\t\tconst useClone = this.options.useClones && asClone;\n\t\treturn (useClone ? clone(entry.v) : entry.v) as T;\n\t}\n\n\tprivate _getKeyLength(key: Key): number {\n\t\treturn String(key).length;\n\t}\n\n\tprivate _getValLength(value: unknown): number {\n\t\tif (typeof value === 'string') return value.length;\n\t\tif (this.options.forceString) return JSON.stringify(value).length;\n\t\tif (Array.isArray(value)) return this.options.arrayValueSize * value.length;\n\t\tif (typeof value === 'number') return 8;\n\t\tif (\n\t\t\tvalue != null &&\n\t\t\ttypeof (value as { then?: unknown }).then === 'function'\n\t\t) {\n\t\t\treturn this.options.promiseValueSize;\n\t\t}\n\t\tif (\n\t\t\ttypeof Buffer !== 'undefined' &&\n\t\t\tBuffer != null &&\n\t\t\tBuffer.isBuffer(value)\n\t\t) {\n\t\t\treturn value.length;\n\t\t}\n\t\tif (value != null && typeof value === 'object') {\n\t\t\treturn this.options.objectValueSize * Object.keys(value as object).length;\n\t\t}\n\t\tif (typeof value === 'boolean') return 8;\n\t\treturn 0;\n\t}\n\n\tprivate _error(type: ErrorCode, data: { type?: string } = {}): CacheError {\n\t\tconst message = ERROR_TEMPLATES[type].replace('__key', data.type ?? '');\n\t\tconst err = new Error(message) as CacheError;\n\t\terr.name = type;\n\t\terr.errorcode = type;\n\t\terr.data = data;\n\t\treturn err;\n\t}\n}\n\nexport default NodeCache;\n"],"names":["e","value","isStructuredCloneable","t","Promise","Error","structuredClone","ERROR_TEMPLATES","VALID_KEY_TYPES","emptyStats","NodeCache","EventEmitter","Map","options","key","entry","undefined","keys","Array","out","String","ttl","processedValue","JSON","existing","ttlOrValue","maybeValue","result","ttlOrFn","maybeFn","fn","promise","keyValueSet","val","arr","delCount","expiry","k","startPeriod","setTimeout","clearTimeout","Date","expiredValue","Number","seconds","asClone","useClone","clone","Buffer","Object","type","data","err"],"mappings":"2CAuCA,IAAAA,EAZc,AAAIC,IACjB,GAAI,CAACC,AApBwB,CAACD,IAC9B,GAAIA,AAAU,OAAVA,EAAgB,MAAO,GAC3B,IAAME,EAAI,OAAOF,QACjB,AACO,WAANE,GACAA,AAAM,WAANA,GACAA,AAAM,YAANA,GACAA,AAAM,WAANA,GACAA,AAAM,cAANA,GAIS,aAANA,GACAA,AAAM,WAANA,IACAF,CAAAA,aAAiBG,OAAM,IACvBH,CAAAA,aAAiBI,KAAI,CAE1B,GAG4BJ,GAC1B,OAAOA,EAER,GAAI,CACH,OAAOK,gBAAgBL,EACxB,CAAE,KAAM,CAEP,OAAOA,CACR,CACD,ECyBMM,EAA6C,CAClD,UAAW,wBACX,WAAY,iCACZ,SACC,0EACD,UAAW,wCACX,SAAU,sCACX,EAEMC,EAAkB,CAAC,SAAU,SAAS,CAItCC,EAAa,IAAc,EAChC,KAAM,EACN,OAAQ,EACR,KAAM,EACN,MAAO,EACP,MAAO,CACR,EA+BA,OAAMC,UAAmBC,EAGxB,KAAO,IAAIC,GAAkC,AAG7C,OAAeH,GAAa,AAG5B,SAA6B,CAC5B,YAAa,GACb,gBAAiB,GACjB,iBAAkB,GAClB,eAAgB,GAChB,OAAQ,EACR,YAAa,IACb,UAAW,GACX,eAAgB,GAChB,QAAS,EACV,CAAE,AAEM,aAAyC,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