@warlock.js/cache 5.53.0 → 5.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/cjs/index.cjs +158 -7
  3. package/cjs/index.cjs.map +1 -1
  4. package/esm/cache-manager.d.mts +12 -0
  5. package/esm/cache-manager.d.mts.map +1 -1
  6. package/esm/cache-manager.mjs +18 -0
  7. package/esm/cache-manager.mjs.map +1 -1
  8. package/esm/cached/auto-key.mjs.map +1 -1
  9. package/esm/cached/cached.mjs.map +1 -1
  10. package/esm/cached/normalize-args.mjs.map +1 -1
  11. package/esm/drivers/base-cache-driver.d.mts +11 -0
  12. package/esm/drivers/base-cache-driver.d.mts.map +1 -1
  13. package/esm/drivers/base-cache-driver.mjs +43 -6
  14. package/esm/drivers/base-cache-driver.mjs.map +1 -1
  15. package/esm/drivers/clone-value.mjs.map +1 -1
  16. package/esm/drivers/file-cache-driver.d.mts +7 -0
  17. package/esm/drivers/file-cache-driver.d.mts.map +1 -1
  18. package/esm/drivers/file-cache-driver.mjs +14 -0
  19. package/esm/drivers/file-cache-driver.mjs.map +1 -1
  20. package/esm/drivers/in-memory-tag-index.mjs.map +1 -1
  21. package/esm/drivers/lru-memory-cache-driver.d.mts +4 -0
  22. package/esm/drivers/lru-memory-cache-driver.d.mts.map +1 -1
  23. package/esm/drivers/lru-memory-cache-driver.mjs +13 -0
  24. package/esm/drivers/lru-memory-cache-driver.mjs.map +1 -1
  25. package/esm/drivers/memory-cache-driver.d.mts +4 -0
  26. package/esm/drivers/memory-cache-driver.d.mts.map +1 -1
  27. package/esm/drivers/memory-cache-driver.mjs +13 -0
  28. package/esm/drivers/memory-cache-driver.mjs.map +1 -1
  29. package/esm/drivers/memory-extended-cache-driver.mjs.map +1 -1
  30. package/esm/drivers/mock-cache-driver.d.mts +4 -0
  31. package/esm/drivers/mock-cache-driver.d.mts.map +1 -1
  32. package/esm/drivers/mock-cache-driver.mjs +9 -0
  33. package/esm/drivers/mock-cache-driver.mjs.map +1 -1
  34. package/esm/drivers/null-cache-driver.d.mts +4 -0
  35. package/esm/drivers/null-cache-driver.d.mts.map +1 -1
  36. package/esm/drivers/null-cache-driver.mjs +6 -0
  37. package/esm/drivers/null-cache-driver.mjs.map +1 -1
  38. package/esm/drivers/pg-cache-driver.d.mts +4 -0
  39. package/esm/drivers/pg-cache-driver.d.mts.map +1 -1
  40. package/esm/drivers/pg-cache-driver.mjs +8 -0
  41. package/esm/drivers/pg-cache-driver.mjs.map +1 -1
  42. package/esm/drivers/redis-cache-driver.d.mts +7 -0
  43. package/esm/drivers/redis-cache-driver.d.mts.map +1 -1
  44. package/esm/drivers/redis-cache-driver.mjs +18 -0
  45. package/esm/drivers/redis-cache-driver.mjs.map +1 -1
  46. package/esm/idempotent.mjs.map +1 -1
  47. package/esm/index.d.mts +2 -2
  48. package/esm/index.mjs +2 -2
  49. package/esm/list/memory-cache-list.mjs.map +1 -1
  50. package/esm/metrics.mjs.map +1 -1
  51. package/esm/scoped-cache.d.mts.map +1 -1
  52. package/esm/scoped-cache.mjs +5 -2
  53. package/esm/scoped-cache.mjs.map +1 -1
  54. package/esm/structures/bloom-filter.mjs.map +1 -1
  55. package/esm/structures/cuckoo-filter.mjs.map +1 -1
  56. package/esm/structures/frequency-tracker.mjs.map +1 -1
  57. package/esm/structures/hash.mjs.map +1 -1
  58. package/esm/structures/hyperloglog.mjs.map +1 -1
  59. package/esm/structures/memory-structures-backend.mjs.map +1 -1
  60. package/esm/structures/redis-structures-backend.mjs.map +1 -1
  61. package/esm/structures/sizing.mjs.map +1 -1
  62. package/esm/structures/structures.mjs.map +1 -1
  63. package/esm/structures/types.mjs.map +1 -1
  64. package/esm/structures/unique-counter.mjs.map +1 -1
  65. package/esm/tag-sample.mjs.map +1 -1
  66. package/esm/tagged-cache.mjs.map +1 -1
  67. package/esm/tagged-scoped-cache.mjs.map +1 -1
  68. package/esm/types.d.mts +53 -0
  69. package/esm/types.d.mts.map +1 -1
  70. package/esm/types.mjs.map +1 -1
  71. package/esm/utils.d.mts +6 -0
  72. package/esm/utils.d.mts.map +1 -1
  73. package/esm/utils.mjs +13 -1
  74. package/esm/utils.mjs.map +1 -1
  75. package/llms-full.txt +6 -0
  76. package/package.json +4 -4
  77. package/skills/cache-basics/SKILL.md +1 -0
  78. package/skills/configure-set-options/SKILL.md +2 -0
  79. package/skills/use-cache-namespace/SKILL.md +1 -0
  80. package/skills/use-cache-similarity/SKILL.md +1 -0
  81. package/skills/use-swr/SKILL.md +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"file-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,qBAAqB;;;;;AAM3B,MAAM,iBAAiB;AAEvB,IAAa,kBAAb,cACU,gBAEV;;;cAIgB;;;;;CAKd,AAAO,WAAW,SAA2B;EAC3C,IAAI,CAAC,QAAQ,WACX,MAAM,IAAI,wBACR,2DACF;EAGF,OAAO,MAAM,WAAW,OAAO;CACjC;;;;CAKA,IAAW,YAAY;EACrB,MAAM,YAAY,KAAK,QAAQ;EAE/B,IAAI,OAAO,cAAc,YACvB,OAAO,UAAU;EAGnB,MAAM,IAAI,wBACR,6EACF;CACF;;;;CAKA,IAAW,WAAW;EACpB,MAAM,WAAW,KAAK,QAAQ;EAE9B,IAAI,OAAO,aAAa,YACtB,OAAO,SAAS;EAGlB,OAAO;CACT;;;;;;;;;;;CAYA,AAAU,aAAa,WAA2B;EAGhD,IAAI,cAAc,IAChB,MAAM,IAAI,wBAAwB,8BAA8B;EAGlE,OAAO,KAAK,cAAc,KAAK,iBAAiB,SAAS,CAAC;CAC5D;;;;;CAMA,AAAU,iBAAiB,WAA2B;EACpD,OAAO,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,KAAK;CAClF;;;;;;;;CAS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,MAAgB,aAAa,WAAkC;EAC7D,KAAK,IAAI,YAAY,SAAS;EAE9B,MAAM,gBAAgB,KAAK,aAAa,SAAS;EAEjD,IAAI;GACF,MAAM,qBAAqB,aAAa;GAExC,KAAK,IAAI,WAAW,SAAS;GAE7B,MAAM,KAAK,KAAK,WAAW,EAAE,KAAK,UAAU,CAAC;EAC/C,SAAS,OAAO,CAEhB;CACF;;;;CAKA,MAAa,QAAQ;EACnB,KAAK,IAAI,UAAU;EAEnB,IAAI,KAAK,QAAQ,cACf,MAAM,KAAK,gBAAgB,EAAE;OAE7B,MAAM,qBAAqB,KAAK,SAAS;EAG3C,KAAK,IAAI,SAAS;EAGlB,MAAM,KAAK,KAAK,SAAS;CAC3B;;;;CAKA,MAAa,UAAU;EACrB,KAAK,IAAI,YAAY;EACrB,MAAM,qBAAqB,KAAK,SAAS;EACzC,KAAK,IAAI,WAAW;EACpB,MAAM,KAAK,KAAK,WAAW;CAC7B;AACF;;;;;AAMA,SAAS,eAAe,OAA2B;CACjD,OAAO,OAAO,MAAM,cAAc,YAAY,MAAM,aAAa,KAAK,IAAI;AAC5E;AAEA,SAAS,cAAc,OAAoC;CACzD,IAAI,OAAO,SAAS,UAAU,MAAM;AACtC;AAEA,SAAS,MAAM,IAA2B;CACxC,OAAO,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD"}
1
+ {"version":3,"file":"file-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport type { FileHandle } from \"node:fs/promises\";\nimport {\n atomicWriteJsonAsync,\n ensureDirectoryAsync,\n getJsonFileAsync,\n listDirectoriesAsync,\n removeDirectoryAsync,\n} from \"@warlock.js/fs\";\nimport path from \"path\";\nimport type {\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheTtl,\n FileCacheOptions,\n} from \"../types\";\nimport { CacheConfigurationError, CacheError, CacheUnsupportedError } from \"../types\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\n\n/**\n * How many times an exclusive write (or a compare-and-delete) retries while\n * another caller is removing the same entry.\n */\nconst EXCLUSIVE_ATTEMPTS = 50;\n\n/**\n * A removal guard older than this belongs to a process that died while\n * holding it (the guarded step takes a few milliseconds).\n */\nconst STALE_GUARD_MS = 10_000;\n\nexport class FileCacheDriver\n extends BaseCacheDriver<FileCacheDriver, FileCacheOptions>\n implements CacheDriver<FileCacheDriver, FileCacheOptions>\n{\n /**\n * {@inheritdoc}\n */\n public name = \"file\";\n\n /**\n * {@inheritdoc}\n */\n public setOptions(options: FileCacheOptions) {\n if (!options.directory) {\n throw new CacheConfigurationError(\n \"File driver requires 'directory' option to be configured.\",\n );\n }\n\n return super.setOptions(options);\n }\n\n /**\n * Get the cache directory\n */\n public get directory() {\n const directory = this.options.directory;\n\n if (typeof directory === \"function\") {\n return directory();\n }\n\n throw new CacheConfigurationError(\n \"Cache directory is not defined, please define it in the file driver options\",\n );\n }\n\n /**\n * Get file name\n */\n public get fileName() {\n const fileName = this.options.fileName;\n\n if (typeof fileName === \"function\") {\n return fileName();\n }\n\n return \"cache.json\";\n }\n\n /**\n * Map a parsed cache key (or namespace) to its on-disk directory.\n *\n * The key must become exactly one directory component: `%` and the path\n * separators are percent-encoded so a hostile key (`../../etc`,\n * `..\\\\..\\\\evil`) turns into an inert directory name instead of a path\n * traversal, while distinct keys can never collide after encoding. Dots are\n * left untouched — the `.`-delimited namespace scheme is purely logical and\n * only ever produces a single filesystem component here.\n */\n protected keyDirectory(parsedKey: string): string {\n // An empty key would resolve to the cache root — `remove(\"{}\")` must never\n // be able to wipe it.\n if (parsedKey === \"\") {\n throw new CacheConfigurationError(\"Cache key must not be empty.\");\n }\n\n return this.containedPath(this.encodeKeySegment(parsedKey));\n }\n\n /**\n * Percent-encode a parsed key into an inert, single-component directory\n * name. Dots are left untouched — see {@link keyDirectory}.\n */\n protected encodeKeySegment(parsedKey: string): string {\n return parsedKey.replace(/%/g, \"%25\").replace(/\\//g, \"%2F\").replace(/\\\\/g, \"%5C\");\n }\n\n /**\n * Reverse of {@link encodeKeySegment} — recovers the logical, dot-delimited\n * parsed key from an on-disk directory name. Used by {@link removeNamespace}\n * to test which sibling directories logically belong to a namespace, since\n * dotted keys (`ns.a`) are stored as sibling directories rather than nested\n * ones (see {@link keyDirectory}'s doc comment).\n */\n protected decodeKeySegment(encoded: string): string {\n return encoded.replace(/%2F/g, \"/\").replace(/%5C/g, \"\\\\\").replace(/%25/g, \"%\");\n }\n\n /**\n * Resolve `segment` against the cache root and throw when the result lands\n * outside it — the last line of defense against path traversal, independent\n * of how the key was encoded.\n */\n protected containedPath(segment: string): string {\n const base = path.resolve(this.directory);\n const resolved = path.resolve(base, segment);\n const relative = path.relative(base, resolved);\n\n if (relative === \"..\" || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n throw new CacheError(`Cache key resolves outside the cache directory: \"${segment}\"`);\n }\n\n return resolved;\n }\n\n /**\n * {@inheritdoc}\n *\n * Dotted keys (`ns.a`) are stored as sibling directories, not nested ones\n * (see {@link keyDirectory}) — a directory literally named `<namespace>`\n * rarely exists on its own. Namespace removal therefore has to scan the\n * cache root's immediate children and remove every directory whose\n * *logical* (decoded) name equals the namespace or starts with\n * `<namespace>.`, mirroring the `key = $1 OR key LIKE $2` boundary\n * semantics the `pg` driver already uses for the same contract.\n */\n public async removeNamespace(namespace: string) {\n const parsedNamespace = this.parseKey(namespace);\n\n this.log(\"clearing\", namespace);\n\n try {\n const root = this.containedPath(\"\");\n\n if (parsedNamespace === \"\") {\n await removeDirectoryAsync(root);\n this.log(\"cleared\", namespace);\n return this;\n }\n\n const prefix = `${parsedNamespace}.`;\n const entries = await listDirectoriesAsync(root).catch(() => [] as string[]);\n\n await Promise.all(\n entries.map(async (entryPath) => {\n const decoded = this.decodeKeySegment(path.basename(entryPath));\n\n if (decoded === parsedNamespace || decoded.startsWith(prefix)) {\n await removeDirectoryAsync(entryPath);\n }\n }),\n );\n\n this.log(\"cleared\", namespace);\n } catch (error) {\n //\n }\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n *\n * Reads the entry directory names, so a key whose entry expired but was\n * not read since is still listed; `get()` reports it missing.\n */\n public async listKeys(namespace: string): Promise<string[]> {\n const parsed = this.parseKey(namespace);\n\n try {\n const entries = await listDirectoriesAsync(this.containedPath(\"\")).catch(\n () => [] as string[],\n );\n\n return entries\n .map((entryPath) => this.decodeKeySegment(path.basename(entryPath)))\n .filter((key) => this.inNamespace(key, parsed))\n .map((key) => this.unprefixKey(key));\n } catch {\n return [];\n }\n }\n\n /**\n * {@inheritdoc}\n *\n * `onConflict: \"create\"` is exclusive (temp file + hard link, so `lock()`\n * is safe across concurrent writers). `onConflict: \"update\"` is NOT atomic:\n * the existence probe and the write are separate steps.\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, vector, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n if (vector) {\n throw new CacheUnsupportedError(\n \"'file' driver does not support similarity retrieval — use a memory driver, 'pg' (with pgvector), or 'redis' (with RediSearch).\",\n );\n }\n\n this.log(\"caching\", parsedKey);\n\n const existing =\n onConflict === \"upsert\" || onConflict === \"create\" ? null : await this.get(key);\n const exists = existing !== null;\n\n if (onConflict === \"update\" && !exists) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n return result;\n }\n\n const data = this.prepareDataForStorage(value, ttl, staleAt);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n await ensureDirectoryAsync(fileDirectory);\n\n const filePath = path.resolve(fileDirectory, this.fileName);\n\n if (onConflict === \"create\") {\n const conflict = await this.writeExclusive(filePath, data);\n\n if (conflict) {\n const result: CacheSetResult = { wasSet: false, existing: conflict.existing };\n return result;\n }\n } else {\n await atomicWriteJsonAsync(filePath, data);\n }\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n return result;\n }\n\n return this;\n }\n\n /**\n * Create `filePath` only if it does not exist. Writes a temp file, then\n * hard-links it to the target (EEXIST = already present). An existing but\n * expired entry is removed under the key's removal guard (see\n * {@link withRemovalGuard}), so of several contenders only one can ever\n * win the retried link.\n *\n * Returns `null` when written, or `{ existing }` on conflict.\n */\n protected async writeExclusive(\n filePath: string,\n data: CacheData,\n ): Promise<{ existing: any } | null> {\n const tempPath = `${filePath}.${randomBytes(6).toString(\"hex\")}.tmp`;\n\n try {\n await fs.promises.writeFile(tempPath, JSON.stringify(data, null, 2));\n\n for (let attempt = 0; attempt < EXCLUSIVE_ATTEMPTS; attempt++) {\n try {\n await fs.promises.link(tempPath, filePath);\n return null;\n } catch (error: any) {\n if (error?.code !== \"EEXIST\") {\n throw error;\n }\n }\n\n const current = await this.readEntryFile(filePath);\n\n // Removed between the link and the read: try the link again.\n if (!current) continue;\n\n // Unreadable (corrupt) file: treat as held, never delete it.\n if (!current.entry) return { existing: null };\n\n if (!isExpiredEntry(current.entry)) {\n return { existing: current.entry.data ?? null };\n }\n\n const guarded = await this.withRemovalGuard(filePath, async () => {\n // Re-read inside the guard: only the expired file that was judged\n // is removed, never one written since.\n const latest = await this.readEntryFile(filePath);\n\n if (latest?.entry && latest.inode === current.inode && isExpiredEntry(latest.entry)) {\n await fs.promises.unlink(filePath).catch(ignoreMissing);\n }\n });\n\n // Another contender is removing it: give it a moment, then retry.\n if (!guarded) await delay(1);\n }\n\n return { existing: null };\n } finally {\n await fs.promises.unlink(tempPath).catch(() => undefined);\n }\n }\n\n /**\n * Run `task` while holding the key's removal guard: a `<file>.guard` file\n * created exclusively. Entry files are only ever created by an exclusive\n * link onto a missing path, so while every removal of a live or expired\n * entry by `writeExclusive` / `deleteIfEquals` happens under this guard, no\n * removal can delete an entry another writer has just created.\n *\n * Returns `false` (without running `task`) when another caller holds the\n * guard. A guard left behind by a crashed process is cleared once it is\n * older than {@link STALE_GUARD_MS}.\n */\n protected async withRemovalGuard(filePath: string, task: () => Promise<void>): Promise<boolean> {\n const guardPath = `${filePath}.guard`;\n let handle: FileHandle;\n\n try {\n handle = await fs.promises.open(guardPath, \"wx\");\n } catch (error: any) {\n // The key directory is gone, so is the entry: nothing to remove.\n if (error?.code === \"ENOENT\") return true;\n\n if (error?.code !== \"EEXIST\") throw error;\n\n await this.clearStaleGuard(guardPath);\n\n return false;\n }\n\n try {\n await handle.close();\n await task();\n\n return true;\n } finally {\n await fs.promises.unlink(guardPath).catch(() => undefined);\n }\n }\n\n /**\n * Remove a removal guard whose holder died (older than {@link STALE_GUARD_MS}).\n */\n protected async clearStaleGuard(guardPath: string): Promise<void> {\n try {\n const { mtimeMs } = await fs.promises.stat(guardPath);\n\n if (Date.now() - mtimeMs > STALE_GUARD_MS) {\n await fs.promises.unlink(guardPath).catch(ignoreMissing);\n }\n } catch (error: any) {\n if (error?.code !== \"ENOENT\") throw error;\n }\n }\n\n /**\n * Read an entry file together with its inode, so a later step can tell\n * whether the file at the same path is still the one that was read.\n * `undefined` when the file does not exist; `entry: undefined` when it\n * cannot be parsed.\n */\n protected async readEntryFile(\n filePath: string,\n ): Promise<{ entry: CacheData | undefined; inode: number } | undefined> {\n let handle: FileHandle;\n\n try {\n handle = await fs.promises.open(filePath, \"r\");\n } catch (error: any) {\n if (error?.code === \"ENOENT\") return undefined;\n\n throw error;\n }\n\n try {\n const { ino } = await handle.stat();\n const text = await handle.readFile(\"utf-8\");\n\n try {\n const entry = JSON.parse(text) as CacheData | null;\n\n return { entry: entry && typeof entry === \"object\" ? entry : undefined, inode: ino };\n } catch {\n return { entry: undefined, inode: ino };\n }\n } finally {\n await handle.close();\n }\n }\n\n /**\n * {@inheritdoc}\n *\n * Compare-and-delete under the key's removal guard, so a lock released just\n * as it expired never deletes a successor's lock.\n */\n protected async deleteIfEquals(key: CacheKey, expected: unknown): Promise<boolean> {\n const parsedKey = this.parseKey(key);\n const fileDirectory = this.keyDirectory(parsedKey);\n const filePath = path.resolve(fileDirectory, this.fileName);\n let deleted = false;\n\n for (let attempt = 0; attempt < EXCLUSIVE_ATTEMPTS; attempt++) {\n const guarded = await this.withRemovalGuard(filePath, async () => {\n const current = await this.readEntryFile(filePath);\n\n if (!current?.entry || isExpiredEntry(current.entry) || current.entry.data !== expected) {\n return;\n }\n\n await fs.promises.unlink(filePath).catch(ignoreMissing);\n deleted = true;\n });\n\n if (guarded) break;\n\n await delay(1);\n }\n\n if (!deleted) return false;\n\n // Drop the key directory when nothing else was written into it meanwhile.\n await fs.promises.rmdir(fileDirectory).catch(() => undefined);\n\n this.log(\"removed\", parsedKey);\n await this.emit(\"removed\", { key: parsedKey });\n\n return true;\n }\n\n /**\n * {@inheritdoc}\n *\n * File driver does not yet ship with a file-lock primitive, so concurrent\n * writers could clobber each other. Rather than ship an unsafe default, we\n * throw — consumers can fall back to memory/redis for `update` until a\n * proper file lock lands (tracked in `domains/cache/backlog.md`).\n */\n public async update(): Promise<never> {\n throw new CacheUnsupportedError(\n \"`update()` is not supported on the file driver. Use the memory or redis driver, or wait for the file-lock primitive (see domains/cache/backlog.md).\",\n );\n }\n\n /**\n * {@inheritdoc}\n */\n public async merge(): Promise<never> {\n throw new CacheUnsupportedError(\n \"`merge()` is not supported on the file driver. Use the memory or redis driver.\",\n );\n }\n\n /**\n * Read the raw {@link CacheData} wrapper from disk, including `staleAt`\n * metadata. Returns `null` for missing or expired files — `swr()`\n * consumes this to branch on freshness.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const parsedKey = this.parseKey(key);\n const fileDirectory = this.keyDirectory(parsedKey);\n\n try {\n const entry = (await getJsonFileAsync(path.resolve(fileDirectory, this.fileName))) as\n | CacheData\n | undefined;\n\n if (!entry) {\n return null;\n }\n\n // `Infinity` (no expiry) is written to JSON as `null`; `null <= now`\n // is true, so only a real deadline may count as expired.\n if (typeof entry.expiresAt === \"number\" && entry.expiresAt <= Date.now()) {\n return null;\n }\n\n return entry;\n } catch {\n return null;\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"fetching\", parsedKey);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n let value: CacheData | undefined;\n\n try {\n value = (await getJsonFileAsync(path.resolve(fileDirectory, this.fileName))) as\n | CacheData\n | undefined;\n } catch {\n // Missing file (ENOENT) or corrupt JSON: a plain miss. Never remove the\n // directory here — it may be mid-write by another process.\n value = undefined;\n }\n\n if (value === undefined || value === null || typeof value !== \"object\") {\n this.log(\"notFound\", parsedKey);\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n // Only a successfully parsed but expired entry is removed (inside\n // parseCachedData). The value was just parsed from disk, so it is already\n // a private copy: no clone.\n const result = await this.parseCachedData(parsedKey, value, false);\n\n if (result === null) {\n await this.emit(\"miss\", { key: parsedKey });\n } else {\n await this.emit(\"hit\", { key: parsedKey, value: result });\n }\n\n return result;\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n await this.removeParsed(this.parseKey(key));\n }\n\n /**\n * {@inheritdoc}\n */\n protected async removeParsed(parsedKey: string): Promise<void> {\n this.log(\"removing\", parsedKey);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n try {\n await removeDirectoryAsync(fileDirectory);\n\n this.log(\"removed\", parsedKey);\n // Emit removed event\n await this.emit(\"removed\", { key: parsedKey });\n } catch (error) {\n //\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async flush() {\n this.log(\"flushing\");\n\n if (this.options.globalPrefix) {\n await this.removeNamespace(\"\");\n } else {\n await removeDirectoryAsync(this.directory);\n }\n\n this.log(\"flushed\");\n\n // Emit flushed event\n await this.emit(\"flushed\");\n }\n\n /**\n * {@inheritdoc}\n */\n public async connect() {\n this.log(\"connecting\");\n await ensureDirectoryAsync(this.directory);\n this.log(\"connected\");\n await this.emit(\"connected\");\n }\n}\n\n/**\n * Whether a stored entry is past its deadline. `Infinity` (no expiry) is\n * written to JSON as `null`, so only a real number can be expired.\n */\nfunction isExpiredEntry(entry: CacheData): boolean {\n return typeof entry.expiresAt === \"number\" && entry.expiresAt <= Date.now();\n}\n\nfunction ignoreMissing(error: NodeJS.ErrnoException): void {\n if (error?.code !== \"ENOENT\") throw error;\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,qBAAqB;;;;;AAM3B,MAAM,iBAAiB;AAEvB,IAAa,kBAAb,cACU,gBAEV;;;cAIgB;;;;;CAKd,AAAO,WAAW,SAA2B;EAC3C,IAAI,CAAC,QAAQ,WACX,MAAM,IAAI,wBACR,2DACF;EAGF,OAAO,MAAM,WAAW,OAAO;CACjC;;;;CAKA,IAAW,YAAY;EACrB,MAAM,YAAY,KAAK,QAAQ;EAE/B,IAAI,OAAO,cAAc,YACvB,OAAO,UAAU;EAGnB,MAAM,IAAI,wBACR,6EACF;CACF;;;;CAKA,IAAW,WAAW;EACpB,MAAM,WAAW,KAAK,QAAQ;EAE9B,IAAI,OAAO,aAAa,YACtB,OAAO,SAAS;EAGlB,OAAO;CACT;;;;;;;;;;;CAYA,AAAU,aAAa,WAA2B;EAGhD,IAAI,cAAc,IAChB,MAAM,IAAI,wBAAwB,8BAA8B;EAGlE,OAAO,KAAK,cAAc,KAAK,iBAAiB,SAAS,CAAC;CAC5D;;;;;CAMA,AAAU,iBAAiB,WAA2B;EACpD,OAAO,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,KAAK;CAClF;;;;;;;;CASA,AAAU,iBAAiB,SAAyB;EAClD,OAAO,QAAQ,QAAQ,QAAQ,GAAG,CAAC,CAAC,Q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MAAM,SAAS,YAAY;EAE3B,KAAK,MAAM,OAAO,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC,GACpC,IAAI,QAAQ,aAAa,IAAI,WAAW,MAAM,GAC5C,KAAK,KAAK,OAAO,GAAG;CAG1B;;;;CAKA,AAAO,QAAc;EACnB,KAAK,KAAK,MAAM;CAClB;AACF"}
1
+ {"version":3,"file":"in-memory-tag-index.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/in-memory-tag-index.ts"],"sourcesContent":["/**\n * Tag index for the in-process drivers (memory, memoryExtended, lru, mock).\n *\n * Lives beside the driver's entry storage, never inside it: index sets are not\n * entries, so they are never subject to `maxSize` / LRU eviction or TTL\n * sweeps, and every operation is synchronous — concurrent tagged writes in one\n * process can never drop a member.\n *\n * Keys are the driver-parsed tag keys (`<prefix>.cache.tags.<tag>`); members\n * are the caller's normalized, un-prefixed cache keys.\n */\nexport class InMemoryTagIndex {\n protected readonly sets: Map<string, Set<string>> = new Map();\n\n /**\n * Add members to a tag set, creating it on first use.\n */\n public add(tagKey: string, members: readonly string[]): void {\n if (members.length === 0) {\n return;\n }\n\n let set = this.sets.get(tagKey);\n\n if (!set) {\n set = new Set();\n this.sets.set(tagKey, set);\n }\n\n for (const member of members) {\n set.add(member);\n }\n }\n\n /**\n * The members of a tag set (a copy; empty when the set does not exist).\n */\n public members(tagKey: string): string[] {\n return [...(this.sets.get(tagKey) ?? [])];\n }\n\n /**\n * Up to `count` members of a tag set from a random starting point, without\n * copying the whole set.\n */\n public sample(tagKey: string, count: number): string[] {\n const set = this.sets.get(tagKey);\n\n if (!set || count <= 0) {\n return [];\n }\n\n const skip = set.size > count ? Math.floor(Math.random() * (set.size - count + 1)) : 0;\n const picked: string[] = [];\n let index = 0;\n\n for (const member of set) {\n if (index++ < skip) continue;\n\n picked.push(member);\n\n if (picked.length >= count) break;\n }\n\n return picked;\n }\n\n /**\n * Remove members from a tag set; an emptied set is dropped.\n */\n public remove(tagKey: string, members: readonly string[]): void {\n const set = this.sets.get(tagKey);\n\n if (!set) {\n return;\n }\n\n for (const member of members) {\n set.delete(member);\n }\n\n if (set.size === 0) {\n this.sets.delete(tagKey);\n }\n }\n\n /**\n * Drop a whole tag set.\n */\n public delete(tagKey: string): void {\n this.sets.delete(tagKey);\n }\n\n /**\n * Drop every tag set whose key equals `namespace` or sits under\n * `namespace.` — the same rule the drivers use for entries. An empty\n * namespace clears everything.\n */\n public removeNamespace(namespace: string): void {\n if (namespace === \"\") {\n this.sets.clear();\n\n return;\n }\n\n const prefix = namespace + \".\";\n\n for (const key of [...this.sets.keys()]) {\n if (key === namespace || key.startsWith(prefix)) {\n this.sets.delete(key);\n }\n }\n }\n\n /**\n * Drop every tag set.\n */\n public clear(): void {\n this.sets.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,mBAAb,MAA8B;;8BACwB,IAAI,IAAI;;;;;CAK5D,AAAO,IAAI,QAAgB,SAAkC;EAC3D,IAAI,QAAQ,WAAW,GACrB;EAGF,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM;EAE9B,IAAI,CAAC,KAAK;GACR,sBAAM,IAAI,IAAI;GACd,KAAK,KAAK,IAAI,QAAQ,GAAG;EAC3B;EAEA,KAAK,MAAM,UAAU,SACnB,IAAI,IAAI,MAAM;CAElB;;;;CAKA,AAAO,QAAQ,QAA0B;EACvC,OAAO,CAAC,GAAI,KAAK,KAAK,IAAI,MAAM,KAAK,CAAC,CAAE;CAC1C;;;;;CAMA,AAAO,OAAO,QAAgB,OAAyB;EACrD,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM;EAEhC,IAAI,CAAC,OAAO,SAAS,GACnB,OAAO,CAAC;EAGV,MAAM,OAAO,IAAI,OAAO,QAAQ,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,OAAO,QAAQ,EAAE,IAAI;EACrF,MAAM,SAAmB,CAAC;EAC1B,IAAI,QAAQ;EAEZ,KAAK,MAAM,UAAU,KAAK;GACxB,IAAI,UAAU,MAAM;GAEpB,OAAO,KAAK,MAAM;GAElB,IAAI,OAAO,UAAU,OAAO;EAC9B;EAEA,OAAO;CACT;;;;CAKA,AAAO,OAAO,QAAgB,SAAkC;EAC9D,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM;EAEhC,IAAI,CAAC,KACH;EAGF,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,MAAM;EAGnB,IAAI,IAAI,SAAS,GACf,KAAK,KAAK,OAAO,MAAM;CAE3B;;;;CAKA,AAAO,OAAO,QAAsB;EAClC,KAAK,KAAK,OAAO,MAAM;CACzB;;;;;;CAOA,AAAO,gBAAgB,WAAyB;EAC9C,IAAI,cAAc,IAAI;GACpB,KAAK,KAAK,MAAM;GAEhB;EACF;EAEA,MAAM,SAAS,YAAY;EAE3B,KAAK,MAAM,OAAO,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC,GACpC,IAAI,QAAQ,aAAa,IAAI,WAAW,MAAM,GAC5C,KAAK,KAAK,OAAO,GAAG;CAG1B;;;;CAKA,AAAO,QAAc;EACnB,KAAK,KAAK,MAAM;CAClB;AACF"}
@@ -75,6 +75,10 @@ export declare class LRUMemoryCacheDriver extends BaseCacheDriver<LRUMemoryCache
75
75
  * is how `flush()` scopes cleanup per tenant.
76
76
  */
77
77
  removeNamespace(namespace: string): Promise<string[]>;
78
+ /**
79
+ * {@inheritdoc}
80
+ */
81
+ listKeys(namespace: string): Promise<string[]>;
78
82
  /**
79
83
  * Backing store of `cache.structures`, created on first use.
80
84
  */
@@ -1 +1 @@
1
- {"version":3,"file":"lru-memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;cAoBM;EAeK;EACA;EAfF,MAAM;EACN,MAAM;EACN;;;;;EAKA;;;;;EAKA;EACP,YACS,aACA,YACP;MAOS;;;;;;;;qBAWA,6BACH,gBAAgB,sBAAsB,kCACnC,YAAY,sBAAsB,wBAAwB;;;;EAK9D;;;;YAKG,OAAO,YAAY;;;;YAKnB,UAAU;;;;YAKV,MAAM;;;;YAKN,MAAM;;;;YAKN,kBAAkB,OAAO;;;;EAKnC;;;;EAUO;;;;EAQA;;;;;;;;;EAwCM,gBAAgB,oBAAiB;;;;YA2CpC,iBAAiB;;;;EAKpB,qBAAqB;;;;EASf,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;YA8EO,SAAS,MAAM;;;;YAQf,WAAW,MAAM;;;;YAQjB,QAAQ,MAAM;;;;YAUd;;;;;;;YAcM,SAAS,KAAK,WAAW,QAAQ;;;;;;;YAuBjC,iBAAiB,GAC/B,KAAK,UACL,SAAS,iBACT,gBAAgB,QAAQ,IACxB,sBACA,uBACC,QAAQ;;;;;YAUD,SAAS,oBAAoB;;;;;;;;EAwB1B,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;EA4CU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EAoBtC,KAAK,KAAK,WAAW;;;;EA2BrB,IAAI,KAAK,WAAQ;;;;EA0DjB,OAAO,KAAK,WAAQ;;;;;;EAuBpB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,oBAAoB;;;;EAOhD,UAAU,QAAQ,WAAW;;;;EAO7B,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAS5C,OAAO,KAAK,WAAW;;;;;;;;EAWvB,SAAK;;;;;;;;;;EA0BL,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB;;;;MAwChB;;;;EAOE,cAAU"}
1
+ {"version":3,"file":"lru-memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;cAoBM;EAeK;EACA;EAfF,MAAM;EACN,MAAM;EACN;;;;;EAKA;;;;;EAKA;EACP,YACS,aACA,YACP;MAOS;;;;;;;;qBAWA,6BACH,gBAAgB,sBAAsB,kCACnC,YAAY,sBAAsB,wBAAwB;;;;EAK9D;;;;YAKG,OAAO,YAAY;;;;YAKnB,UAAU;;;;YAKV,MAAM;;;;YAKN,MAAM;;;;YAKN,kBAAkB,OAAO;;;;EAKnC;;;;EAUO;;;;EAQA;;;;;;;;;EAwCM,gBAAgB,oBAAiB;;;;EA2CjC,SAAS,oBAAoB;;;;YAgBhC,iBAAiB;;;;EAKpB,qBAAqB;;;;EASf,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;YA8EO,SAAS,MAAM;;;;YAQf,WAAW,MAAM;;;;YAQjB,QAAQ,MAAM;;;;YAUd;;;;;;;YAcM,SAAS,KAAK,WAAW,QAAQ;;;;;;;YAuBjC,iBAAiB,GAC/B,KAAK,UACL,SAAS,iBACT,gBAAgB,QAAQ,IACxB,sBACA,uBACC,QAAQ;;;;;YAUD,SAAS,oBAAoB;;;;;;;;EAwB1B,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;EA4CU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EAoBtC,KAAK,KAAK,WAAW;;;;EA2BrB,IAAI,KAAK,WAAQ;;;;EA0DjB,OAAO,KAAK,WAAQ;;;;;;EAuBpB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,oBAAoB;;;;EAOhD,UAAU,QAAQ,WAAW;;;;EAO7B,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAS5C,OAAO,KAAK,WAAW;;;;;;;;EAWvB,SAAK;;;;;;;;;;EA0BL,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB;;;;MAyChB;;;;EAOE,cAAU"}
@@ -101,6 +101,15 @@ var LRUMemoryCacheDriver = class extends BaseCacheDriver {
101
101
  /**
102
102
  * {@inheritdoc}
103
103
  */
104
+ async listKeys(namespace) {
105
+ const parsed = this.parseKey(namespace);
106
+ const keys = [];
107
+ for (const [key, node] of this.cache) if (this.inNamespace(key, parsed) && !node.isExpired) keys.push(this.unprefixKey(key));
108
+ return keys;
109
+ }
110
+ /**
111
+ * {@inheritdoc}
112
+ */
104
113
  structuresBackend() {
105
114
  this.structureStore ??= new MemoryStructuresBackend((key) => this.parseKey(key));
106
115
  return this.structureStore;
@@ -426,6 +435,10 @@ var LRUMemoryCacheDriver = class extends BaseCacheDriver {
426
435
  if (!node.vector) continue;
427
436
  if (node.isExpired) continue;
428
437
  if (tagFilter && !tagFilter.has(parsedKey)) continue;
438
+ if (options.filter && !options.filter({
439
+ key: parsedKey,
440
+ value: node.value
441
+ })) continue;
429
442
  const score = cosineSimilarity(vector, node.vector);
430
443
  if (options.threshold !== void 0 && score < options.threshold) continue;
431
444
  let value = node.value;
@@ -1 +1 @@
1
- {"version":3,"file":"lru-memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;;;AAoBA,IAAM,YAAN,MAAgB;CAcd,AAAO,YACL,AAAO,KACP,AAAO,OACP,KACA;EAHO;EACA;cAfuB;cACA;EAiB9B,IAAI,OAAO,QAAQ,UACjB,KAAK,YAAY,KAAK,IAAI,IAAI,MAAM;CAExC;CAEA,IAAW,YAAqB;EAC9B,OAAO,KAAK,cAAc,UAAa,KAAK,YAAY,KAAK,IAAI;CACnE;AACF;;;;;;;AAQA,IAAa,uBAAb,cACU,gBAEV;;;;CAkCE,AAAO,cAAc;EACnB,MAAM;cA/BM;+BAK4B,IAAI,IAAI;kBAKX,IAAI,iBAAiB;cAKhC,IAAI,UAAU,IAAI,IAAI;cAKtB,IAAI,UAAU,IAAI,IAAI;EAahD,KAAK,KAAK;EACV,KAAK,aAAa;CACpB;;;;CAKA,AAAO,OAAO;EACZ,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,KAAK,OAAO,KAAK;CACxB;;;;CAKA,AAAO,eAAe;EAEpB,IAAI,KAAK,iBACP,cAAc,KAAK,eAA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MAAM,YAAY,MAAM,KAAK,eAAe,QAAQ,IAAI;EAExD,MAAM,OAA6B,CAAC;EAEpC,KAAK,MAAM,CAAC,WAAW,SAAS,KAAK,OAAO;GAC1C,IAAI,CAAC,KAAK,QAAQ;GAClB,IAAI,KAAK,WAAW;GACpB,IAAI,aAAa,CAAC,UAAU,IAAI,SAAS,GAAG;GAE5C,MAAM,QAAQ,iBAAiB,QAAQ,KAAK,MAAM;GAElD,IAAI,QAAQ,cAAc,UAAa,QAAQ,QAAQ,WACrD;GAIF,IAAI,QAAa,KAAK;GACtB,IAAI,UAAU,QAAQ,UAAU,QAAW;IACzC,MAAM,IAAI,OAAO;IACjB,IAAI,MAAM,YAAY,MAAM,YAAY,MAAM,WAC5C,QAAQ,gBAAgB,KAAK;GAEjC;GAEA,KAAK,KAAK;IAAE,KAAK;IAAW;IAAO;GAAM,CAAC;EAC5C;EAEA,KAAK,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;EAErC,IAAI,QAAQ,QAAQ,KAAK,KAAK,SAAS,QAAQ,MAC7C,KAAK,SAAS,QAAQ;EAGxB,OAAO;CACT;;;;CAKA,IAAW,WAAW;EACpB,OAAO,KAAK,QAAQ,YAAY;CAClC;;;;CAKA,MAAa,aAAa;EAExB,IAAI,KAAK,iBAAiB;GACxB,cAAc,KAAK,eAAe;GAClC,KAAK,kBAAkB;EACzB;EAEA,MAAM,MAAM,WAAW;CACzB;AACF"}
1
+ {"version":3,"file":"lru-memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"sourcesContent":["import { maskEmailsInText } from \"@warlock.js/logger\";\nimport type {\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheSimilarHit,\n CacheSimilarOptions,\n CacheSwrOptions,\n CacheTtl,\n LRUMemoryCacheOptions,\n} from \"../types\";\nimport { cosineSimilarity, parseTtl } from \"../utils\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\nimport { cloneValue } from \"./clone-value\";\nimport { MemoryStructuresBackend } from \"../structures/memory-structures-backend\";\nimport type { CacheStructuresBackend, StructuresCapable } from \"../structures/types\";\nimport { InMemoryTagIndex } from \"./in-memory-tag-index\";\n\nclass CacheNode {\n public next: CacheNode | null = null;\n public prev: CacheNode | null = null;\n public expiresAt?: number;\n /**\n * Freshness deadline (ms timestamp) — populated by `swr()`. Within\n * `expiresAt > now > staleAt` the entry is \"stale-but-revalidatable.\"\n */\n public staleAt?: number;\n /**\n * Optional embedding vector — populated when the entry was written with\n * `set({ vector })`. Scanned by `similar()`.\n */\n public vector?: number[];\n public constructor(\n public key: string,\n public value: any,\n ttl?: number,\n ) {\n if (ttl && ttl !== Infinity) {\n this.expiresAt = Date.now() + ttl * 1000;\n }\n }\n\n public get isExpired(): boolean {\n return this.expiresAt !== undefined && this.expiresAt < Date.now();\n }\n}\n\n/**\n * LRU Memory Cache Driver\n * The concept of LRU is to remove the least recently used data\n * whenever the cache is full\n * The question that resides here is how to tell the cache is full?\n */\nexport class LRUMemoryCacheDriver\n extends BaseCacheDriver<LRUMemoryCacheDriver, LRUMemoryCacheOptions>\n implements CacheDriver<LRUMemoryCacheDriver, LRUMemoryCacheOptions>, StructuresCapable\n{\n /**\n * {@inheritdoc}\n */\n public name = \"lru\";\n\n /**\n * Cache map\n */\n protected cache: Map<string, CacheNode> = new Map();\n\n /**\n * Tag index, kept out of the LRU list so capacity pressure can never evict it.\n */\n protected tagIndex: InMemoryTagIndex = new InMemoryTagIndex();\n\n /**\n * Head of the cache\n */\n protected head: CacheNode = new CacheNode(\"\", null);\n\n /**\n * Tail of the cache\n */\n protected tail: CacheNode = new CacheNode(\"\", null);\n\n /**\n * Cleanup interval reference\n */\n protected cleanupInterval?: NodeJS.Timeout;\n\n /**\n * {@inheritdoc}\n */\n public constructor() {\n super();\n\n this.init();\n this.startCleanup();\n }\n\n /**\n * Initialize the cache\n */\n public init() {\n this.head.next = this.tail;\n this.tail.prev = this.head;\n }\n\n /**\n * Start the cleanup process for expired items\n */\n public startCleanup() {\n // Clear existing interval if any\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n }\n\n this.cleanupInterval = setInterval(async () => {\n const now = Date.now();\n const expiredKeys: string[] = [];\n\n for (const [key, node] of this.cache) {\n if (node.expiresAt && node.expiresAt <= now) {\n expiredKeys.push(key);\n }\n }\n\n for (const key of expiredKeys) {\n const node = this.cache.get(key);\n if (node) {\n this.removeNode(node);\n this.cache.delete(key);\n this.log(\"expired\", key);\n // Emit expired event\n await this.emit(\"expired\", { key });\n }\n }\n }, 1000);\n\n // do not block the process from exiting\n this.cleanupInterval.unref();\n }\n\n /**\n * {@inheritdoc}\n *\n * Clears every entry whose key starts with the parsed namespace (followed\n * by a dot) or equals it exactly. Called with an empty namespace while a\n * `globalPrefix` is configured, clears everything under the prefix — which\n * is how `flush()` scopes cleanup per tenant.\n */\n public async removeNamespace(namespace: string) {\n const parsedNamespace = this.parseKey(namespace);\n\n this.log(\"clearing\", parsedNamespace || \"(all)\");\n\n const removed: string[] = [];\n\n this.tagIndex.removeNamespace(parsedNamespace);\n\n if (parsedNamespace === \"\") {\n this.structureStore?.clear();\n for (const key of this.cache.keys()) {\n removed.push(key);\n }\n } else {\n const prefix = parsedNamespace + \".\";\n\n this.structureStore?.clearPrefix(prefix);\n\n for (const key of this.cache.keys()) {\n if (key === parsedNamespace || key.startsWith(prefix)) {\n removed.push(key);\n }\n }\n }\n\n for (const key of removed) {\n const node = this.cache.get(key);\n if (node) {\n this.removeNode(node);\n this.cache.delete(key);\n }\n await this.emit(\"removed\", { key });\n }\n\n this.log(\"cleared\", parsedNamespace || \"(all)\");\n\n return removed;\n }\n\n /**\n * {@inheritdoc}\n */\n public async listKeys(namespace: string): Promise<string[]> {\n const parsed = this.parseKey(namespace);\n const keys: string[] = [];\n\n for (const [key, node] of this.cache) {\n if (this.inNamespace(key, parsed) && !node.isExpired) {\n keys.push(this.unprefixKey(key));\n }\n }\n\n return keys;\n }\n\n /**\n * Backing store of `cache.structures`, created on first use.\n */\n protected structureStore?: MemoryStructuresBackend;\n\n /**\n * {@inheritdoc}\n */\n public structuresBackend(): CacheStructuresBackend {\n this.structureStore ??= new MemoryStructuresBackend((key) => this.parseKey(key));\n\n return this.structureStore;\n }\n\n /**\n * {@inheritdoc}\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, vector, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n this.log(\"caching\", parsedKey);\n\n // For conditional writes, check existence via get() so expired entries\n // are treated as missing (get() handles expiry cleanup). The raw `cache.get`\n // node lookup would let stale entries block onConflict: \"create\".\n let existingNode = this.cache.get(parsedKey);\n if (existingNode && existingNode.isExpired) {\n this.removeNode(existingNode);\n this.cache.delete(parsedKey);\n existingNode = undefined;\n }\n\n const exists = Boolean(existingNode);\n\n if (onConflict === \"create\" && exists) {\n const result: CacheSetResult = {\n wasSet: false,\n existing: cloneValue(existingNode!.value),\n };\n return result;\n }\n\n if (onConflict === \"update\" && !exists) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n return result;\n }\n\n if (existingNode) {\n existingNode.value = value;\n if (ttl && ttl !== Infinity) {\n existingNode.expiresAt = Date.now() + ttl * 1000;\n } else {\n existingNode.expiresAt = undefined;\n }\n existingNode.staleAt = staleAt;\n if (vector) {\n existingNode.vector = vector.slice();\n }\n\n this.moveHead(existingNode);\n } else {\n const newNode = new CacheNode(parsedKey, value, ttl);\n newNode.staleAt = staleAt;\n if (vector) {\n newNode.vector = vector.slice();\n }\n\n this.cache.set(parsedKey, newNode);\n\n this.addNode(newNode);\n if (this.cache.size > this.capacity) {\n this.removeTail();\n }\n }\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n return result;\n }\n\n return this;\n }\n\n /**\n * Move the node to the head\n */\n protected moveHead(node: CacheNode) {\n this.removeNode(node);\n this.addNode(node);\n }\n\n /**\n * Remove the node from the cache\n */\n protected removeNode(node: CacheNode) {\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n }\n\n /**\n * Add the node to the head\n */\n protected addNode(node: CacheNode) {\n node.next = this.head.next;\n node.prev = this.head;\n this.head.next!.prev = node;\n this.head.next = node;\n }\n\n /**\n * Remove the tail node\n */\n protected removeTail() {\n const node = this.tail.prev!;\n\n this.removeNode(node);\n\n this.cache.delete(node.key);\n }\n\n /**\n * Read the raw {@link CacheData} wrapper, including `staleAt` metadata.\n * Returns `null` for missing or expired nodes — `swr()` consumes this\n * to branch on freshness without going through `get()`'s clone-and-emit\n * path.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const parsedKey = this.parseKey(key);\n const node = this.cache.get(parsedKey);\n\n if (!node || node.isExpired) {\n return null;\n }\n\n // A copy, as `get()` returns: `swr()` hands this value to the caller, and\n // a caller mutating it must not change the cached entry for everyone.\n return {\n data: cloneValue(node.value),\n expiresAt: node.expiresAt,\n staleAt: node.staleAt,\n };\n }\n\n /**\n * {@inheritdoc}\n *\n * This driver stores the written value by reference, so the callers of a\n * cold-miss fetch get a copy rather than the stored object itself.\n */\n protected async swrFetchAndStore<T>(\n key: CacheKey,\n options: CacheSwrOptions,\n callback: () => Promise<T>,\n freshSeconds: number,\n staleSeconds: number,\n ): Promise<T> {\n const result = await super.swrFetchAndStore(key, options, callback, freshSeconds, staleSeconds);\n\n return cloneValue(result);\n }\n\n /**\n * Live node for `parsedKey`, or `undefined` when missing / expired (an\n * expired node is unlinked). Synchronous.\n */\n protected liveNode(parsedKey: string): CacheNode | undefined {\n const node = this.cache.get(parsedKey);\n\n if (!node) {\n return undefined;\n }\n\n if (node.isExpired) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n\n return undefined;\n }\n\n return node;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read, add and write run synchronously (no `await` in between), so\n * concurrent increments in this process never lose an update. An existing\n * node keeps its expiry; a missing key starts from 0 with the default TTL.\n */\n public async increment(\n key: CacheKey,\n value: number = 1,\n options: { ttl?: CacheTtl } = {},\n ): Promise<number> {\n const ttl = options.ttl === undefined ? this.ttl : parseTtl(options.ttl);\n const parsedKey = this.parseKey(key);\n const node = this.liveNode(parsedKey);\n const current = node ? node.value : 0;\n\n if (typeof current !== \"number\") {\n throw new Error(`Cannot increment non-numeric value for key: ${maskEmailsInText(parsedKey)}`);\n }\n\n const newValue = current + value;\n\n if (node) {\n node.value = newValue;\n if (\n options.ttl !== undefined &&\n !Number.isFinite(node.expiresAt) &&\n Number.isFinite(ttl) &&\n ttl > 0\n ) {\n node.expiresAt = Date.now() + ttl * 1000;\n }\n this.moveHead(node);\n } else {\n const newNode = new CacheNode(parsedKey, newValue, ttl);\n\n this.cache.set(parsedKey, newNode);\n this.addNode(newNode);\n\n if (this.cache.size > this.capacity) {\n this.removeTail();\n }\n }\n\n await this.emit(\"set\", { key: parsedKey, value: newValue, ttl });\n\n return newValue;\n }\n\n /**\n * {@inheritdoc}\n *\n * The deadline moves in place, synchronously.\n */\n public async extend(key: CacheKey, ttl: CacheTtl): Promise<boolean> {\n const seconds = this.resolveExtendTtl(ttl);\n const node = this.liveNode(this.parseKey(key));\n\n if (!node) {\n return false;\n }\n\n node.expiresAt = Number.isFinite(seconds) ? Date.now() + seconds * 1000 : undefined;\n this.moveHead(node);\n\n return true;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read and unlink run synchronously, so a value is handed out exactly once\n * even when concurrent callers pull the same key.\n */\n public async pull(key: CacheKey): Promise<any | null> {\n const parsedKey = this.parseKey(key);\n const node = this.liveNode(parsedKey);\n\n if (!node) {\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n this.removeNode(node);\n this.cache.delete(parsedKey);\n\n const value =\n node.value !== null && typeof node.value === \"object\"\n ? structuredClone(node.value)\n : node.value;\n\n await this.emit(\"hit\", { key: parsedKey, value });\n await this.emit(\"removed\", { key: parsedKey });\n\n return value;\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"fetching\", parsedKey);\n\n const node = this.cache.get(parsedKey);\n\n if (!node) {\n this.log(\"notFound\", parsedKey);\n // Emit miss event\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n // Check if expired\n if (node.isExpired) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n this.log(\"expired\", parsedKey);\n // Emit expired event\n await this.emit(\"expired\", { key: parsedKey });\n // Also emit miss since we're returning null\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n this.moveHead(node);\n\n this.log(\"fetched\", parsedKey);\n\n const value = node.value;\n\n // Apply cloning for immutability protection\n if (value === null || value === undefined) {\n return value;\n }\n\n const type = typeof value;\n if (type === \"string\" || type === \"number\" || type === \"boolean\") {\n // Emit hit event\n await this.emit(\"hit\", { key: parsedKey, value });\n return value;\n }\n\n try {\n const clonedValue = structuredClone(value);\n // Emit hit event\n await this.emit(\"hit\", { key: parsedKey, value: clonedValue });\n return clonedValue;\n } catch (error) {\n this.logError(`Failed to clone cached value for ${parsedKey}`, error);\n throw error;\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"removing\", parsedKey);\n\n const node = this.cache.get(parsedKey);\n\n if (node) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n }\n\n this.log(\"removed\", parsedKey);\n\n // Emit removed event\n await this.emit(\"removed\", { key: parsedKey });\n }\n\n /**\n * {@inheritdoc}\n *\n * Synchronous in-process set, never evicted or expired with the entries.\n */\n public async tagAdd(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.add(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagMembers(tagKey: CacheKey): Promise<string[]> {\n return this.tagIndex.members(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagRemove(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.remove(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagDelete(tagKey: CacheKey): Promise<void> {\n this.tagIndex.delete(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagSample(tagKey: CacheKey, count: number): Promise<string[]> {\n return this.tagIndex.sample(this.parseKey(tagKey), count);\n }\n\n /**\n * {@inheritdoc}\n *\n * A synchronous lookup: no copy, no events, no recency or TTL change.\n */\n public async exists(key: CacheKey): Promise<boolean> {\n return this.liveNode(this.parseKey(key)) !== undefined;\n }\n\n /**\n * {@inheritdoc}\n *\n * When a `globalPrefix` is configured, `flush` scopes itself to that prefix\n * so multi-tenant caches don't accidentally wipe sibling tenants. Without\n * a prefix, clears everything.\n */\n public async flush() {\n this.log(\"flushing\");\n\n if (this.options.globalPrefix) {\n await this.removeNamespace(\"\");\n } else {\n this.cache.clear();\n this.tagIndex.clear();\n this.structureStore?.clear();\n this.init();\n }\n\n this.log(\"flushed\");\n\n await this.emit(\"flushed\");\n }\n\n /**\n * {@inheritdoc}\n *\n * Brute-force O(N) cosine similarity over every cached node that carries a\n * vector. Suitable for development and small in-memory knowledge bases —\n * not for production beyond ~10k entries.\n *\n * @warning Dev-only — O(N) per query.\n */\n public async similar<T = any>(\n vector: number[],\n options: CacheSimilarOptions,\n ): Promise<CacheSimilarHit<T>[]> {\n const tagFilter = await this.getKeysForTags(options.tags);\n\n const hits: CacheSimilarHit<T>[] = [];\n\n for (const [parsedKey, node] of this.cache) {\n if (!node.vector) continue;\n if (node.isExpired) continue;\n if (tagFilter && !tagFilter.has(parsedKey)) continue;\n if (options.filter && !options.filter({ key: parsedKey, value: node.value })) continue;\n\n const score = cosineSimilarity(vector, node.vector);\n\n if (options.threshold !== undefined && score < options.threshold) {\n continue;\n }\n\n // Clone object values to match get() semantics.\n let value: any = node.value;\n if (value !== null && value !== undefined) {\n const t = typeof value;\n if (t !== \"string\" && t !== \"number\" && t !== \"boolean\") {\n value = structuredClone(value);\n }\n }\n\n hits.push({ key: parsedKey, value, score });\n }\n\n hits.sort((a, b) => b.score - a.score);\n\n if (options.topK >= 0 && hits.length > options.topK) {\n hits.length = options.topK;\n }\n\n return hits;\n }\n\n /**\n * Get lru capacity\n */\n public get capacity() {\n return this.options.capacity || 1000;\n }\n\n /**\n * {@inheritdoc}\n */\n public async disconnect() {\n // Clear the cleanup interval to prevent memory leaks\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n this.cleanupInterval = undefined;\n }\n\n await super.disconnect();\n }\n}\n"],"mappings":";;;;;;;;AAoBA,IAAM,YAAN,MAAgB;CAcd,AAAO,YACL,AAAO,KACP,AAAO,OACP,KACA;EAHO;EACA;cAfuB;cACA;EAiB9B,IAAI,OAAO,QAAQ,UACjB,KAAK,YAAY,KAAK,IAAI,IAAI,MAAM;CAExC;CAEA,IAAW,YAAqB;EAC9B,OAAO,KAAK,cAAc,UAAa,KAAK,YAAY,KAAK,IAAI;CACnE;AACF;;;;;;;AAQA,IAAa,uBAAb,cACU,gBAEV;;;;CAkCE,AAAO,cAAc;EACnB,MAAM;cA/BM;+BAK4B,IAAI,IAAI;kBAKX,IAAI,iBAAiB;cAKhC,IAAI,UAAU,IAAI,IAAI;cAKtB,IAAI,UAAU,IAAI,IAAI;EAahD,KAAK,KAAK;EACV,KAAK,aAAa;CACpB;;;;CAKA,AAAO,OAAO;EACZ,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,KAAK,OAAO,KAAK;CACxB;;;;CAKA,AAAO,eAAe;EAEpB,IAAI,KAAK,iBACP,cAAc,KAAK,eAAe;EAGpC,KAAK,kBAAkB,YAAY,YAAY;GAC7C,MAAM,MAAM,KAAK,IAAI;GACrB,MAAM,cAAwB,CAAC;GAE/B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
  removeNamespace(namespace: string): Promise<this>;
96
+ /**
97
+ * {@inheritdoc}
98
+ */
99
+ listKeys(namespace: string): Promise<string[]>;
96
100
  /**
97
101
  * {@inheritdoc}
98
102
  *
@@ -1 +1 @@
1
- {"version":3,"file":"memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-cache-driver.ts"],"mappings":";;;;;;qBA2Ca,0BACH,gBAAgB,mBAAmB,+BAChC,YAAY,mBAAmB,qBAAqB;;;;EAKxD;;;;;;YAOG,SAAS,YAAY;;;;;MAMpB,QAAQ,eAAe;;;;;YAQxB,QAAQ;;;;YAKR,kBAAkB,OAAO;;;;;;;YAQzB,aAAa;;;;;YAMb,UAAU;;;;EAKpB;;;;EASO;;;;;YAwCG,iBAAiB;;;;EAKpB,qBAAqB;;;;YASlB,UAAU;;;;;YAUV,SAAS,oBAAoB;;;;;gBAmBzB;;;;YAWJ,MAAM,mBAAmB,OAAO;;;;;;;YAahC;;;;;;YAOA,OAAO,mBAAmB,OAAO;;;;EAiB9B,gBAAgB,oBAAiB;;;;;;;EAmCjC,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;;;;YA8Da,eAAe,KAAK,UAAU,oBAAoB;;;;;;;;EAoBrD,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;;EAgDU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EA8BtC,KAAK,KAAK,WAAW;;;;EAuBrB,IAAI,KAAK,WAAQ;;;;;;YA8Bd,SAAS,KAAK,WAAW,QAAQ;;;;EAapC,OAAO,KAAK,WAAQ;;;;;;EAkBpB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,oBAAoB;;;;EAOhD,UAAU,QAAQ,WAAW;;;;EAO7B,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAS5C,OAAO,KAAK,WAAW;;;;EAOvB,SAAK;;;;;YAsBR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mCZ,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB;;;;EA6Cd,cAAU"}
@@ -142,6 +142,15 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
142
142
  }
143
143
  /**
144
144
  * {@inheritdoc}
145
+ */
146
+ async listKeys(namespace) {
147
+ const parsed = this.parseKey(namespace);
148
+ const keys = [];
149
+ for (const key of [...this.entries.keys()]) if (this.inNamespace(key, parsed) && this.readLive(key)) keys.push(this.unprefixKey(key));
150
+ return keys;
151
+ }
152
+ /**
153
+ * {@inheritdoc}
145
154
  *
146
155
  * The conditional check and the write run with no `await` in between, so
147
156
  * `onConflict` decisions are atomic within the process.
@@ -405,6 +414,10 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
405
414
  if (tagFilter && !tagFilter.has(parsedKey)) continue;
406
415
  const entry = this.readLive(parsedKey);
407
416
  if (!entry) continue;
417
+ if (options.filter && !options.filter({
418
+ key: parsedKey,
419
+ value: entry.data
420
+ })) continue;
408
421
  const value = cloneValue(entry.data);
409
422
  const score = cosineSimilarity(vector, stored);
410
423
  if (options.threshold !== void 0 && score < options.threshold) continue;
@@ -1 +1 @@
1
- {"version":3,"file":"memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-cache-driver.ts"],"mappings":";;;;;;;;;;;AAsBA,SAAS,WAAc,OAAa;CAClC,IAAI,UAAU,QAAQ,UAAU,QAC9B,OAAO;CAGT,MAAM,OAAO,OAAO;CAEpB,IAAI,SAAS,YAAY,SAAS,YAAY,SAAS,WACrD,OAAO;CAGT,OAAO,gBAAgB,KAAK;AAC9B;;;;;;AAOA,MAAM,mBAAmB;AAEzB,IAAa,oBAAb,cACU,gBAEV;;;;;CAiBE,IAAW,OAAkC;EAC3C,OAAO,OAAO,YAAY,KAAK,OAAO;CACxC;;;;CA8BA,AAAO,cAAc;EACnB,MAAM;cA9CM;iCAO8B,IAAI,IAAI;gCAcZ,IAAI,IAAI;qCAaD,IAAI,IAAI;k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ACvC;GAKF,MAAM,QAAQ,KAAK,SAAS,SAAS;GAErC,IAAI,CAAC,OACH;GAGF,MAAM,QAAa,WAAW,MAAM,IAAI;GAExC,MAAM,QAAQ,iBAAiB,QAAQ,MAAM;GAE7C,IAAI,QAAQ,cAAc,UAAa,QAAQ,QAAQ,WACrD;GAGF,KAAK,KAAK;IAAE,KAAK;IAAW;IAAO;GAAM,CAAC;EAC5C;EAEA,KAAK,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;EAErC,IAAI,QAAQ,QAAQ,KAAK,KAAK,SAAS,QAAQ,MAC7C,KAAK,SAAS,QAAQ;EAGxB,OAAO;CACT;;;;CAKA,MAAa,aAAa;EAExB,IAAI,KAAK,iBAAiB;GACxB,cAAc,KAAK,eAAe;GAClC,KAAK,kBAAkB;EACzB;EAEA,MAAM,MAAM,WAAW;CACzB;AACF"}
1
+ {"version":3,"file":"memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-cache-driver.ts"],"sourcesContent":["import { maskEmailsInText } from \"@warlock.js/logger\";\nimport type {\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheSimilarHit,\n CacheSimilarOptions,\n CacheTtl,\n MemoryCacheOptions,\n} from \"../types\";\nimport { cosineSimilarity, parseTtl } from \"../utils\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\nimport { MemoryStructuresBackend } from \"../structures/memory-structures-backend\";\nimport type { CacheStructuresBackend, StructuresCapable } from \"../structures/types\";\nimport { InMemoryTagIndex } from \"./in-memory-tag-index\";\n\n/**\n * Clone non-primitive values so cached state can't be mutated through\n * references held by callers. Primitives are immutable and returned as-is.\n */\nfunction cloneValue<T>(value: T): T {\n if (value === null || value === undefined) {\n return value;\n }\n\n const type = typeof value;\n\n if (type === \"string\" || type === \"number\" || type === \"boolean\") {\n return value;\n }\n\n return structuredClone(value);\n}\n\n/**\n * Entries a memory driver keeps when `maxSize` is not configured. Past it the\n * least recently used entries are evicted, so request-derived keys cannot\n * grow the heap without bound.\n */\nconst DEFAULT_MAX_SIZE = 10_000;\n\nexport class MemoryCacheDriver\n extends BaseCacheDriver<MemoryCacheDriver, MemoryCacheOptions>\n implements CacheDriver<MemoryCacheDriver, MemoryCacheOptions>, StructuresCapable\n{\n /**\n * {@inheritdoc}\n */\n public name = \"memory\";\n\n /**\n * Flat storage keyed by the parsed key. Insertion order doubles as LRU\n * order (least recently used first) — accessed entries are deleted and\n * re-inserted.\n */\n protected entries: Map<string, CacheData> = new Map();\n\n /**\n * Read-only object view of the stored entries, keyed by parsed key.\n * Kept for introspection; the values are the live stored wrappers.\n */\n public get data(): Record<string, CacheData> {\n return Object.fromEntries(this.entries);\n }\n\n /**\n * Expiry records for entries with a FINITE ttl only (parsed key => expiresAt ms).\n * The sweep iterates just these.\n */\n protected expiry: Map<string, number> = new Map();\n\n /**\n * Cleanup interval reference\n */\n protected cleanupInterval?: NodeJS.Timeout;\n\n /**\n * Parallel vector index keyed by parsedKey. Populated by `set({ vector })`,\n * scanned by `similar()`. Lifetime mirrors the main entry — cleared on\n * `remove`, `flush`, expiry, namespace clear, overwrite without a vector,\n * and LRU eviction.\n */\n protected vectorIndex: Map<string, number[]> = new Map();\n\n /**\n * Tag index, kept apart from `entries`: never evicted by `maxSize`, never\n * swept by TTL, and updated synchronously.\n */\n protected tagIndex: InMemoryTagIndex = new InMemoryTagIndex();\n\n /**\n * {@inheritdoc}\n */\n public constructor() {\n super();\n\n this.startCleanup();\n }\n\n /**\n * Start the cleanup process for entries that carry a finite ttl\n */\n public startCleanup() {\n // Clear existing interval if any\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n }\n\n this.cleanupInterval = setInterval(async () => {\n const now = Date.now();\n const expiredKeys: string[] = [];\n\n for (const [key, expiresAt] of this.expiry) {\n if (expiresAt <= now) {\n expiredKeys.push(key);\n }\n }\n\n for (const key of expiredKeys) {\n // the entry may have been rewritten/slid since the snapshot\n const expiresAt = this.expiry.get(key);\n\n if (expiresAt === undefined || expiresAt > now) {\n continue;\n }\n\n this.dropEntry(key);\n\n this.log(\"expired\", key);\n // Emit expired event\n await this.emit(\"expired\", { key });\n }\n }, 1000);\n\n // do not block the process from exiting\n this.cleanupInterval.unref();\n }\n\n /**\n * Backing store of `cache.structures` (bloom, cuckoo, unique counter,\n * frequency), created on first use.\n */\n protected structureStore?: MemoryStructuresBackend;\n\n /**\n * {@inheritdoc}\n */\n public structuresBackend(): CacheStructuresBackend {\n this.structureStore ??= new MemoryStructuresBackend((key) => this.parseKey(key));\n\n return this.structureStore;\n }\n\n /**\n * Delete an entry and every side record (expiry, vector). Synchronous.\n */\n protected dropEntry(parsedKey: string) {\n this.entries.delete(parsedKey);\n this.expiry.delete(parsedKey);\n this.vectorIndex.delete(parsedKey);\n }\n\n /**\n * Raw, synchronous read of a live entry. An expired entry is deleted and\n * reported as missing. Never slides TTLs, never emits, never touches LRU order.\n */\n protected readLive(parsedKey: string): CacheData | undefined {\n const entry = this.entries.get(parsedKey);\n\n if (!entry) {\n return undefined;\n }\n\n if (entry.expiresAt !== undefined && entry.expiresAt <= Date.now()) {\n this.dropEntry(parsedKey);\n return undefined;\n }\n\n return entry;\n }\n\n /**\n * The entry limit: `maxSize`, or 10,000 when it is not set. `Infinity`\n * (or `0`) means no limit.\n */\n protected get maxSize(): number {\n const configured = this.options?.maxSize;\n\n if (configured === undefined) return DEFAULT_MAX_SIZE;\n\n return configured > 0 ? configured : Infinity;\n }\n\n /**\n * Mark an entry as most recently used (not tracked without a limit).\n */\n protected touch(parsedKey: string, entry: CacheData) {\n if (this.maxSize === Infinity) return;\n\n this.entries.delete(parsedKey);\n this.entries.set(parsedKey, entry);\n }\n\n /**\n * When true, every live read slides the entry's expiration forward by its\n * ttl (the `memoryExtended` driver). Set in a subclass constructor rather\n * than redeclared, so subclasses stay structurally compatible with this\n * class (the `client` type relies on that).\n */\n protected slidingExpiration = false;\n\n /**\n * Invoked on a live read hit, before the value is returned. Runs only from\n * `get()` after the expiry check, so an expired entry is never resurrected,\n * and never from the internal existence check used by `onConflict`.\n */\n protected onRead(parsedKey: string, entry: CacheData) {\n if (!this.slidingExpiration) {\n return;\n }\n\n const rawTtl = entry.ttl ?? this.options.ttl;\n const ttl = rawTtl !== undefined ? parseTtl(rawTtl) : undefined;\n\n if (ttl && Number.isFinite(ttl)) {\n entry.expiresAt = this.getExpiresAt(ttl);\n this.expiry.set(parsedKey, entry.expiresAt as number);\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async removeNamespace(namespace: string) {\n this.log(\"clearing\", namespace);\n\n namespace = this.parseKey(namespace);\n\n this.tagIndex.removeNamespace(namespace);\n\n if (namespace === \"\") {\n this.structureStore?.clear();\n this.entries.clear();\n this.expiry.clear();\n this.vectorIndex.clear();\n } else {\n const prefix = namespace + \".\";\n\n this.structureStore?.clearPrefix(prefix);\n\n for (const key of [...this.entries.keys()]) {\n if (key === namespace || key.startsWith(prefix)) {\n this.dropEntry(key);\n }\n }\n }\n\n this.log(\"cleared\", namespace);\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n */\n public async listKeys(namespace: string): Promise<string[]> {\n const parsed = this.parseKey(namespace);\n const keys: string[] = [];\n\n for (const key of [...this.entries.keys()]) {\n if (this.inNamespace(key, parsed) && this.readLive(key)) {\n keys.push(this.unprefixKey(key));\n }\n }\n\n return keys;\n }\n\n /**\n * {@inheritdoc}\n *\n * The conditional check and the write run with no `await` in between, so\n * `onConflict` decisions are atomic within the process.\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, vector, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n this.log(\"caching\", parsedKey);\n\n // expired entries count as missing (readLive deletes them)\n const existing =\n onConflict === \"create\" || onConflict === \"update\" ? this.readLive(parsedKey) : undefined;\n\n if (onConflict === \"create\" && existing) {\n const result: CacheSetResult = { wasSet: false, existing: cloneValue(existing.data) };\n return result;\n }\n\n if (onConflict === \"update\" && !existing) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n return result;\n }\n\n const data = this.prepareDataForStorage(cloneValue(value), ttl, staleAt);\n\n // delete + set moves the key to the most-recent position\n this.entries.delete(parsedKey);\n this.entries.set(parsedKey, data);\n\n if (data.expiresAt !== undefined && Number.isFinite(data.expiresAt)) {\n this.expiry.set(parsedKey, data.expiresAt);\n } else {\n this.expiry.delete(parsedKey);\n }\n\n if (vector) {\n this.vectorIndex.set(parsedKey, vector.slice());\n } else {\n this.vectorIndex.delete(parsedKey);\n }\n\n this.enforceMaxSize(parsedKey);\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n return result;\n }\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n *\n * The check and the delete run synchronously (no `await` between them), so\n * the compare-and-delete is atomic within the process.\n */\n protected async deleteIfEquals(key: CacheKey, expected: unknown): Promise<boolean> {\n const parsedKey = this.parseKey(key);\n const entry = this.readLive(parsedKey);\n\n if (!entry || entry.data !== expected) {\n return false;\n }\n\n await this.remove(key);\n\n return true;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read, add and write run synchronously (no `await` in between), so\n * concurrent increments in this process never lose an update. An existing\n * entry keeps its expiry; a missing key starts from 0 with the default TTL.\n */\n public async increment(\n key: CacheKey,\n value: number = 1,\n options: { ttl?: CacheTtl } = {},\n ): Promise<number> {\n const ttl = options.ttl === undefined ? this.ttl : parseTtl(options.ttl);\n const parsedKey = this.parseKey(key);\n const entry = this.readLive(parsedKey);\n const current = entry ? entry.data : 0;\n\n if (typeof current !== \"number\") {\n throw new Error(`Cannot increment non-numeric value for key: ${maskEmailsInText(parsedKey)}`);\n }\n\n const newValue = current + value;\n\n if (entry) {\n entry.data = newValue;\n if (\n options.ttl !== undefined &&\n !Number.isFinite(entry.expiresAt) &&\n Number.isFinite(ttl) &&\n ttl > 0\n ) {\n entry.ttl = ttl;\n entry.expiresAt = Date.now() + ttl * 1000;\n this.expiry.set(parsedKey, entry.expiresAt);\n }\n this.touch(parsedKey, entry);\n } else {\n const data = this.prepareDataForStorage(newValue, ttl);\n\n this.entries.set(parsedKey, data);\n\n if (data.expiresAt !== undefined && Number.isFinite(data.expiresAt)) {\n this.expiry.set(parsedKey, data.expiresAt);\n }\n\n this.enforceMaxSize(parsedKey);\n }\n\n await this.emit(\"set\", { key: parsedKey, value: newValue, ttl: entry?.ttl ?? ttl });\n\n return newValue;\n }\n\n /**\n * {@inheritdoc}\n *\n * The deadline moves in place, synchronously, so concurrent callers never\n * interleave with the read.\n */\n public async extend(key: CacheKey, ttl: CacheTtl): Promise<boolean> {\n const seconds = this.resolveExtendTtl(ttl);\n const parsedKey = this.parseKey(key);\n const entry = this.readLive(parsedKey);\n\n if (!entry) {\n return false;\n }\n\n if (Number.isFinite(seconds)) {\n entry.ttl = seconds;\n entry.expiresAt = this.getExpiresAt(seconds);\n this.expiry.set(parsedKey, entry.expiresAt as number);\n } else {\n delete entry.ttl;\n delete entry.expiresAt;\n this.expiry.delete(parsedKey);\n }\n\n this.touch(parsedKey, entry);\n\n return true;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read and delete run synchronously, so a value is handed out exactly once\n * even when concurrent callers pull the same key.\n */\n public async pull(key: CacheKey): Promise<any | null> {\n const parsedKey = this.parseKey(key);\n const entry = this.readLive(parsedKey);\n\n if (!entry) {\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n this.dropEntry(parsedKey);\n\n const value = cloneValue(entry.data);\n\n await this.emit(\"hit\", { key: parsedKey, value });\n await this.emit(\"removed\", { key: parsedKey });\n\n return value;\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"fetching\", parsedKey);\n\n const entry = this.readLive(parsedKey);\n\n if (!entry) {\n this.log(\"notFound\", parsedKey);\n // Emit miss event\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n this.onRead(parsedKey, entry);\n this.touch(parsedKey, entry);\n\n const result = await this.parseCachedData(parsedKey, entry);\n\n // Emit hit event\n await this.emit(\"hit\", { key: parsedKey, value: result });\n\n return result;\n }\n\n /**\n * Read the raw {@link CacheData} wrapper (cloned), including `staleAt` metadata.\n * Returns `null` for missing or expired entries so the SWR flow can branch\n * cleanly. Does not emit `hit`/`miss` events — that's `get()`'s job.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const entry = this.readLive(this.parseKey(key));\n\n if (!entry) {\n return null;\n }\n\n return { ...entry, data: cloneValue(entry.data) };\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"removing\", parsedKey);\n\n this.dropEntry(parsedKey);\n\n this.log(\"removed\", parsedKey);\n\n // Emit removed event\n await this.emit(\"removed\", { key: parsedKey });\n }\n\n /**\n * {@inheritdoc}\n *\n * Synchronous in-process set — concurrent tagged writes never drop members.\n */\n public async tagAdd(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.add(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagMembers(tagKey: CacheKey): Promise<string[]> {\n return this.tagIndex.members(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagRemove(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.remove(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagDelete(tagKey: CacheKey): Promise<void> {\n this.tagIndex.delete(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagSample(tagKey: CacheKey, count: number): Promise<string[]> {\n return this.tagIndex.sample(this.parseKey(tagKey), count);\n }\n\n /**\n * {@inheritdoc}\n *\n * A synchronous lookup: no copy, no events, no recency or TTL change.\n */\n public async exists(key: CacheKey): Promise<boolean> {\n return this.readLive(this.parseKey(key)) !== undefined;\n }\n\n /**\n * {@inheritdoc}\n */\n public async flush() {\n this.log(\"flushing\");\n if (this.options.globalPrefix) {\n await this.removeNamespace(\"\");\n } else {\n this.entries.clear();\n this.expiry.clear();\n this.vectorIndex.clear();\n this.tagIndex.clear();\n this.structureStore?.clear();\n }\n\n this.log(\"flushed\");\n\n // Emit flushed event\n await this.emit(\"flushed\");\n }\n\n /**\n * Evict least recently used entries (Map insertion order) until the size is\n * within `maxSize`. Never evicts `protectedKey` (the key just written).\n */\n protected enforceMaxSize(protectedKey: string) {\n const maxSize = this.maxSize;\n\n if (this.entries.size <= maxSize) {\n return;\n }\n\n // Iterate the live key view (deleting the current key during Map\n // iteration is safe): normally only the oldest key is touched, with no\n // copy of the key list.\n for (const lruKey of this.entries.keys()) {\n if (this.entries.size <= maxSize) {\n break;\n }\n\n if (lruKey === protectedKey) {\n continue;\n }\n\n this.log(\"removing\", lruKey);\n this.dropEntry(lruKey);\n this.log(\"removed\", lruKey);\n }\n }\n\n /**\n * {@inheritdoc}\n *\n * Brute-force O(N) cosine similarity over every entry that was written with\n * `set({ vector })`. Suitable for development and small in-memory knowledge\n * bases — not for production beyond ~10k entries. Use the `pg` driver\n * (with pgvector) or `redis` (with RediSearch) at scale.\n *\n * @warning Dev-only — O(N) per query.\n */\n public async similar<T = any>(\n vector: number[],\n options: CacheSimilarOptions,\n ): Promise<CacheSimilarHit<T>[]> {\n const tagFilter = await this.getKeysForTags(options.tags);\n\n const hits: CacheSimilarHit<T>[] = [];\n\n for (const [parsedKey, stored] of [...this.vectorIndex]) {\n if (tagFilter && !tagFilter.has(parsedKey)) {\n continue;\n }\n\n // Read the entry directly by its already-parsed key — this.get() would\n // parse it again and apply globalPrefix twice, missing every entry.\n const entry = this.readLive(parsedKey);\n\n if (!entry) {\n continue;\n }\n\n if (options.filter && !options.filter({ key: parsedKey, value: entry.data })) {\n continue;\n }\n\n const value: any = cloneValue(entry.data);\n\n const score = cosineSimilarity(vector, stored);\n\n if (options.threshold !== undefined && score < options.threshold) {\n continue;\n }\n\n hits.push({ key: parsedKey, value, score });\n }\n\n hits.sort((a, b) => b.score - a.score);\n\n if (options.topK >= 0 && hits.length > options.topK) {\n hits.length = options.topK;\n }\n\n return hits;\n }\n\n /**\n * {@inheritdoc}\n */\n public async disconnect() {\n // Clear the cleanup interval to prevent memory leaks\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n this.cleanupInterval = undefined;\n }\n\n await super.disconnect();\n }\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,WAAc,OAAa;CAClC,IAAI,UAAU,QAAQ,UAAU,QAC9B,OAAO;CAGT,MAAM,OAAO,OAAO;CAEpB,IAAI,SAAS,YAAY,SAAS,YAAY,SAAS,WACrD,OAAO;CAGT,OAAO,gBAAgB,KAAK;AAC9B;;;;;;AAOA,MAAM,mBAAmB;AAEzB,IAAa,oBAAb,cACU,gBAEV;;;;;CAiBE,IAAW,OAAkC;EAC3C,OAAO,OAAO,YAAY,KAAK,OAAO;CACxC;;;;CA8BA,AAAO,cAAc;EACnB,MAAM;cA9CM;iCAO8B,IAAI,IAAI;gCAcZ,IAAI,IAAI;qCAaD,IAAI,IAAI;kBAMhB,IAAI,iBAAiB;2BAyH9B;EAjH5B,KAAK,aAAa;CACpB;;;;CAKA,AAAO,eAAe;EAEpB,IAAI,KAAK,iBACP,cAAc,KAAK,eAAe;EAGpC,KAAK,kBAAkB,YAAY,YAAY;GAC7C,MAAM,MAAM,KAAK,IAAI;GACrB,MAAM,cAAwB,CAAC;GAE/B,KAAK,MAAM,CAAC,KAAK,cAAc,KAAK,QAClC,IAAI,aAAa,KACf,YAAY,KAAK,GAAG;GAIxB,KAAK,MAAM,OAAO,aAAa;IAE7B,MAAM,YAAY,KAAK,OAAO,IAAI,GAAG;IAErC,IAAI,cAAc,UAAa,YAAY,KACzC;IAGF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AAK,CAAC,GACzE;GAGF,MAAM,QAAa,WAAW,MAAM,IAAI;GAExC,MAAM,QAAQ,iBAAiB,QAAQ,MAAM;GAE7C,IAAI,QAAQ,cAAc,UAAa,QAAQ,QAAQ,WACrD;GAGF,KAAK,KAAK;IAAE,KAAK;IAAW;IAAO;GAAM,CAAC;EAC5C;EAEA,KAAK,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;EAErC,IAAI,QAAQ,QAAQ,KAAK,KAAK,SAAS,QAAQ,MAC7C,KAAK,SAAS,QAAQ;EAGxB,OAAO;CACT;;;;CAKA,MAAa,aAAa;EAExB,IAAI,KAAK,iBAAiB;GACxB,cAAc,KAAK,eAAe;GAClC,KAAK,kBAAkB;EACzB;EAEA,MAAM,MAAM,WAAW;CACzB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"memory-extended-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-extended-cache-driver.ts"],"mappings":";;;;;;;;;;AAUA,IAAa,4BAAb,cACU,kBAEV;CAME,AAAO,cAAc;EACnB,MAAM;cAHM;EAKZ,KAAK,oBAAoB;CAC3B;AACF"}
1
+ {"version":3,"file":"memory-extended-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-extended-cache-driver.ts"],"sourcesContent":["import type { CacheDriver, MemoryExtendedCacheOptions } from \"../types\";\nimport { MemoryCacheDriver } from \"./memory-cache-driver\";\n\n/**\n * Memory driver with a sliding ttl: every live read pushes the entry's\n * expiration forward by its ttl. The sliding itself lives in\n * `MemoryCacheDriver.onRead`, which checks expiry first, so an expired entry\n * is never resurrected and the internal `onConflict` existence check never\n * slides a held lock.\n */\nexport class MemoryExtendedCacheDriver\n extends MemoryCacheDriver\n implements CacheDriver<MemoryExtendedCacheDriver, MemoryExtendedCacheOptions>\n{\n /**\n * {@inheritdoc}\n */\n public name = \"memoryExtended\";\n\n public constructor() {\n super();\n\n this.slidingExpiration = true;\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,4BAAb,cACU,kBAEV;CAME,AAAO,cAAc;EACnB,MAAM;cAHM;EAKZ,KAAK,oBAAoB;CAC3B;AACF"}
@@ -81,6 +81,10 @@ export declare class MockCacheDriver extends BaseCacheDriver<MockCacheDriver, Mo
81
81
  * — the namespace itself and any key with the namespace prefix is removed.
82
82
  */
83
83
  removeNamespace(namespace: string): Promise<void>;
84
+ /**
85
+ * {@inheritdoc}
86
+ */
87
+ listKeys(namespace: string): Promise<string[]>;
84
88
  /**
85
89
  * Standard `set` with full `onConflict` support. Honors scope-default TTL
86
90
  * via {@link BaseCacheDriver.resolveSetOptions}.
@@ -1 +1 @@
1
- {"version":3,"file":"mock-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/mock-cache-driver.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwDa,wBACH,gBAAgB,iBAAiB,6BAC9B,YAAY,iBAAiB;;;;EAKjC;;;;EAKA,SAAS;;;;;WAMA,SAAS,YAAY;;;;YAK3B,UAAU;;;;;;WAOJ,SAAS;;;;;EAMZ,WAAW;;;;EAQX,cAAc;;;;;EASd,gBAAgB,oBAAoB;;;;;EAuBpC,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;YAmDO,WAAW,GAAG,OAAO,IAAI;;;;;EAYtB,IAAI,SAAS,KAAK,WAAW,QAAQ;;;;;YAkCxC,UAAU,oBAAoB;;;;;EAoB3B,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;EAsCU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;EA0BtC,KAAK,SAAS,KAAK,WAAW,QAAQ;;;;;;YA4BnC,SAAS,KAAK,WAAW,QAAQ;;;;EAkBpC,OAAO,KAAK,WAAW;;;;;;EAiBvB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,o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acheDriver = class extends BaseCacheDriver {
83
83
  this.log("cleared", parsed);
84
84
  }
85
85
  /**
86
+ * {@inheritdoc}
87
+ */
88
+ async listKeys(namespace) {
89
+ const parsed = this.parseKey(namespace);
90
+ this.recordCall("listKeys", parsed, [namespace]);
91
+ const now = Date.now();
92
+ return [...this.storage.entries()].filter(([key, data]) => this.inNamespace(key, parsed) && (data.expiresAt === void 0 || data.expiresAt > now)).map(([key]) => this.unprefixKey(key));
93
+ }
94
+ /**
86
95
  * Standard `set` with full `onConflict` support. Honors scope-default TTL
87
96
  * via {@link BaseCacheDriver.resolveSetOptions}.
88
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mock-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/mock-cache-driver.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,IAAa,kBAAb,cACU,gBAEV;;;cAIgB;iBAKqB,CAAC;iCAMc,IAAI,IAAI;kBAKnB,IAAI,iBAAiB;iBAOrB,CAAC;;;;;;CAMxC,MAAa,UAAyB;EACpC,KAAK,WAAW,WAAW,MAAS;EACpC,MAAM,MAAM,QAAQ;CACtB;;;;CAKA,MAAa,aAA4B;EACvC,KAAK,WAAW,cAAc,MAAS;EACvC,MAAM,MAAM,WAAW;CACzB;;;;;CAMA,MAAa,gBAAgB,WAAkC;EAC7D,MAAM,SAAS,KAAK,SAAS,SAAS;EAEtC,KAAK,WAAW,mBAAmB,QAAQ,CAAC,SAAS,CAAC;EACtD,KAAK,IAAI,YAAY,MAAM;EAE3B,MAAM,SAAS,SAAS;EAExB,KAAK,SAAS,gBAAgB,MAAM;EAEpC,KAAK,MAAM,OAAO,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC,GACvC,IAAI,QAAQ,UAAU,IAAI,WAAW,MAAM,GACzC,KAAK,QAAQ,OAAO,GAAG;EAI3B,KAAK,IAAI,WAAW,MAAM;CAC5B;;;;;CAMA,MAAa,I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,AAAO,QAAc;EACnB,KAAK,QAAQ,MAAM;EACnB,KAAK,SAAS,MAAM;EACpB,KAAK,QAAQ,SAAS;CACxB;;;;;CAMA,AAAU,WAAW,WAAmB,KAAyB,OAAkB,CAAC,GAAS;EAC3F,KAAK,QAAQ,KAAK;GAChB;GACA;GACA;GACA,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"mock-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/mock-cache-driver.ts"],"sourcesContent":["import { maskEmailsInText } from \"@warlock.js/logger\";\nimport type {\n CacheCall,\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheTtl,\n MockCacheOptions,\n} from \"../types\";\nimport { parseTtl } from \"../utils\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\nimport { InMemoryTagIndex } from \"./in-memory-tag-index\";\n\n/**\n * In-memory cache driver with introspection helpers, intended for use as a\n * test double in downstream packages.\n *\n * **Role.** Drop-in replacement for any real driver in test setups, with\n * extra surface that makes behavioral assertions easy: every public op gets\n * recorded into {@link MockCacheDriver.callLog}, and {@link wasCalled} /\n * {@link getStored} / {@link reset} let tests verify side effects without\n * pulling in a real Redis / Postgres / file system.\n *\n * **Responsibility.**\n * - Owns: in-memory storage backed by a `Map`, the `callLog`, TTL handling\n * via `parseCachedData`, `onConflict` policies, and tag-index storage.\n * - Does NOT own: similarity retrieval (vectors are recorded into the\n * `callLog` but `similar()` throws — use `MemoryCacheDriver` for tests\n * that need real nearest-neighbor scoring), connection lifecycle\n * (no-op `connect`/`disconnect`), or eviction (no `maxSize`).\n *\n * Register it like any other driver — sub-paths are not part of the\n * package's export convention; the same single barrel ships it next to\n * the production drivers.\n *\n * @example\n * import { cache, MockCacheDriver } from \"@warlock.js/cache\";\n *\n * beforeEach(async () => {\n * cache.setCacheConfigurations({\n * default: \"mock\",\n * drivers: { mock: MockCacheDriver },\n * options: { mock: {} },\n * });\n * await cache.init();\n * });\n *\n * it(\"invalidates the user cache after update\", async () => {\n * await userService.update(42, { name: \"Jane\" });\n *\n * const driver = cache.currentDriver as MockCacheDriver;\n * expect(driver.wasCalled(\"remove\", \"users.42\")).toBe(true);\n * });\n */\nexport class MockCacheDriver\n extends BaseCacheDriver<MockCacheDriver, MockCacheOptions>\n implements CacheDriver<MockCacheDriver, MockCacheOptions>\n{\n /**\n * {@inheritdoc}\n */\n public name = \"mock\";\n\n /**\n * {@inheritdoc}\n */\n public options: MockCacheOptions = {};\n\n /**\n * Storage backing the mock — keyed by post-`parseKey` string. Public-readonly\n * so tests can introspect raw entries when {@link getStored} isn't enough.\n */\n public readonly storage: Map<string, CacheData> = new Map();\n\n /**\n * Tag index, kept apart from {@link storage} (same model as the memory driver).\n */\n protected tagIndex: InMemoryTagIndex = new InMemoryTagIndex();\n\n /**\n * Ordered record of every public operation routed through this driver.\n * Pushed to before each op runs; tests assert via {@link wasCalled} or by\n * inspecting the array directly.\n */\n public readonly callLog: CacheCall[] = [];\n\n /**\n * Standard driver setup. Mirrors the null driver — no connection, no\n * resources to release.\n */\n public async connect(): Promise<void> {\n this.recordCall(\"connect\", undefined);\n await super.connect();\n }\n\n /**\n * Standard driver teardown.\n */\n public async disconnect(): Promise<void> {\n this.recordCall(\"disconnect\", undefined);\n await super.disconnect();\n }\n\n /**\n * Wipe everything under `namespace`. Matches `MemoryCacheDriver` semantics\n * — the namespace itself and any key with the namespace prefix is removed.\n */\n public async removeNamespace(namespace: string): Promise<void> {\n const parsed = this.parseKey(namespace);\n\n this.recordCall(\"removeNamespace\", parsed, [namespace]);\n this.log(\"clearing\", parsed);\n\n const prefix = parsed + \".\";\n\n this.tagIndex.removeNamespace(parsed);\n\n for (const key of [...this.storage.keys()]) {\n if (key === parsed || key.startsWith(prefix)) {\n this.storage.delete(key);\n }\n }\n\n this.log(\"cleared\", parsed);\n }\n\n /**\n * {@inheritdoc}\n */\n public async listKeys(namespace: string): Promise<string[]> {\n const parsed = this.parseKey(namespace);\n\n this.recordCall(\"listKeys\", parsed, [namespace]);\n\n const now = Date.now();\n\n return [...this.storage.entries()]\n .filter(\n ([key, data]) =>\n this.inNamespace(key, parsed) && (data.expiresAt === undefined || data.expiresAt > now),\n )\n .map(([key]) => this.unprefixKey(key));\n }\n\n /**\n * Standard `set` with full `onConflict` support. Honors scope-default TTL\n * via {@link BaseCacheDriver.resolveSetOptions}.\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n this.recordCall(\"set\", parsedKey, [value, ttlOrOptions]);\n this.log(\"caching\", parsedKey);\n\n // Synchronous check + write (no await between) so onConflict is atomic.\n // Expired entries count as missing and are deleted.\n let existing =\n onConflict === \"create\" || onConflict === \"update\" ? this.storage.get(parsedKey) : undefined;\n\n if (existing && existing.expiresAt !== undefined && existing.expiresAt <= Date.now()) {\n this.storage.delete(parsedKey);\n existing = undefined;\n }\n\n if (onConflict === \"create\" && existing) {\n const result: CacheSetResult = { wasSet: false, existing: this.cloneValue(existing.data) };\n\n return result;\n }\n\n if (onConflict === \"update\" && !existing) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n\n return result;\n }\n\n const data = this.prepareDataForStorage(this.cloneValue(value), ttl, staleAt);\n this.storage.set(parsedKey, data);\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n\n return result;\n }\n\n return this;\n }\n\n /**\n * Clone non-primitive values so stored state can't be mutated by callers.\n */\n protected cloneValue<T>(value: T): T {\n if (value === null || value === undefined || typeof value !== \"object\") {\n return value;\n }\n\n return structuredClone(value);\n }\n\n /**\n * Standard `get` with TTL handling. Emits `hit` / `miss` events to keep\n * downstream metrics tests realistic.\n */\n public async get<T = any>(key: CacheKey): Promise<T | null> {\n const parsedKey = this.parseKey(key);\n\n this.recordCall(\"get\", parsedKey);\n this.log(\"fetching\", parsedKey);\n\n const data = this.storage.get(parsedKey);\n\n if (!data) {\n this.log(\"notFound\", parsedKey);\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n const value = await this.parseCachedData(parsedKey, data);\n\n if (value === null) {\n // expired — the parse helper already logged + queued the cleanup\n this.storage.delete(parsedKey);\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n await this.emit(\"hit\", { key: parsedKey, value });\n\n return value as T;\n }\n\n /**\n * Live entry for `parsedKey`, or `undefined` when missing / expired (an\n * expired entry is deleted). Synchronous.\n */\n protected liveEntry(parsedKey: string): CacheData | undefined {\n const entry = this.storage.get(parsedKey);\n\n if (!entry) {\n return undefined;\n }\n\n if (entry.expiresAt !== undefined && entry.expiresAt <= Date.now()) {\n this.storage.delete(parsedKey);\n\n return undefined;\n }\n\n return entry;\n }\n\n /**\n * Synchronous read-add-write (atomic within the process). Keeps an existing\n * entry's expiry; a missing key starts from 0 with the default TTL.\n */\n public async increment(\n key: CacheKey,\n value: number = 1,\n options: { ttl?: CacheTtl } = {},\n ): Promise<number> {\n const ttl = options.ttl === undefined ? this.ttl : parseTtl(options.ttl);\n const parsedKey = this.parseKey(key);\n\n this.recordCall(\"increment\", parsedKey, [value]);\n\n const entry = this.liveEntry(parsedKey);\n const current = entry ? entry.data : 0;\n\n if (typeof current !== \"number\") {\n throw new Error(`Cannot increment non-numeric value for key: ${maskEmailsInText(parsedKey)}`);\n }\n\n const newValue = current + value;\n\n if (entry) {\n entry.data = newValue;\n if (\n options.ttl !== undefined &&\n !Number.isFinite(entry.expiresAt) &&\n Number.isFinite(ttl) &&\n ttl > 0\n ) {\n entry.ttl = ttl;\n entry.expiresAt = Date.now() + ttl * 1000;\n }\n } else {\n this.storage.set(parsedKey, this.prepareDataForStorage(newValue, ttl));\n }\n\n await this.emit(\"set\", { key: parsedKey, value: newValue, ttl });\n\n return newValue;\n }\n\n /**\n * Synchronous in-place deadline reset.\n */\n public async extend(key: CacheKey, ttl: CacheTtl): Promise<boolean> {\n const seconds = this.resolveExtendTtl(ttl);\n const parsedKey = this.parseKey(key);\n\n this.recordCall(\"extend\", parsedKey, [ttl]);\n\n const entry = this.liveEntry(parsedKey);\n\n if (!entry) {\n return false;\n }\n\n if (Number.isFinite(seconds)) {\n entry.ttl = seconds;\n entry.expiresAt = Date.now() + seconds * 1000;\n } else {\n delete entry.ttl;\n delete entry.expiresAt;\n }\n\n return true;\n }\n\n /**\n * Synchronous read-and-delete: a value is handed out exactly once.\n */\n public async pull<T = any>(key: CacheKey): Promise<T | null> {\n const parsedKey = this.parseKey(key);\n\n this.recordCall(\"pull\", parsedKey);\n\n const entry = this.liveEntry(parsedKey);\n\n if (!entry) {\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n this.storage.delete(parsedKey);\n\n const value = this.cloneValue(entry.data) as T;\n\n await this.emit(\"hit\", { key: parsedKey, value });\n await this.emit(\"removed\", { key: parsedKey });\n\n return value;\n }\n\n /**\n * Read the raw {@link CacheData} wrapper from the in-memory `Map`,\n * including `staleAt` metadata. Returns `null` for missing or expired\n * entries — `swr()` consumes this to branch on freshness.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const parsedKey = this.parseKey(key);\n const entry = this.storage.get(parsedKey);\n\n if (!entry) {\n return null;\n }\n\n if (entry.expiresAt !== undefined && entry.expiresAt <= Date.now()) {\n return null;\n }\n\n return { ...entry, data: this.cloneValue(entry.data) };\n }\n\n /**\n * Standard `remove` — drops the entry and emits the `removed` event.\n */\n public async remove(key: CacheKey): Promise<void> {\n const parsedKey = this.parseKey(key);\n\n this.recordCall(\"remove\", parsedKey);\n this.log(\"removing\", parsedKey);\n\n this.storage.delete(parsedKey);\n\n this.log(\"removed\", parsedKey);\n await this.emit(\"removed\", { key: parsedKey });\n }\n\n /**\n * {@inheritdoc}\n *\n * Synchronous in-process set, never evicted or expired with the entries.\n */\n public async tagAdd(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.add(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagMembers(tagKey: CacheKey): Promise<string[]> {\n return this.tagIndex.members(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagRemove(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.remove(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagDelete(tagKey: CacheKey): Promise<void> {\n this.tagIndex.delete(this.parseKey(tagKey));\n }\n\n /**\n * Standard `flush` — wipes the entire mock store + tag index. Does NOT\n * touch the call log; use {@link reset} to clear that as well.\n */\n public async flush(): Promise<void> {\n this.recordCall(\"flush\", undefined);\n this.log(\"flushing\");\n\n this.storage.clear();\n this.tagIndex.clear();\n\n this.log(\"flushed\");\n await this.emit(\"flushed\");\n }\n\n /**\n * Was a given operation invoked? When `key` is provided, the match is\n * post-`parseKey` so callers pass the same key shape they used at the\n * call site — strings or objects, both resolve to the same parsed key.\n *\n * @example\n * driver.wasCalled(\"set\"); // any set\n * driver.wasCalled(\"set\", \"users.42\"); // set on this specific key\n * driver.wasCalled(\"set\", { id: 42 }); // same — object key normalized\n */\n public wasCalled(operation: string, key?: CacheKey): boolean {\n if (key === undefined) {\n return this.callLog.some((call) => call.operation === operation);\n }\n\n const parsedKey = this.parseKey(key);\n\n return this.callLog.some((call) => call.operation === operation && call.key === parsedKey);\n }\n\n /**\n * Return the raw stored value for `key`, bypassing TTL handling and clone\n * protection. Useful when a test wants to assert on the persisted shape\n * (or assert that an entry expired without going through `get`).\n *\n * Returns `undefined` when the key isn't present.\n */\n public getStored<T = any>(key: CacheKey): T | undefined {\n const parsedKey = this.parseKey(key);\n const entry = this.storage.get(parsedKey);\n\n if (!entry) {\n return undefined;\n }\n\n return entry.data as T;\n }\n\n /**\n * Wipe everything — storage, tag index, and the call log. Pair with\n * Vitest's `beforeEach` to get clean isolation between tests.\n */\n public reset(): void {\n this.storage.clear();\n this.tagIndex.clear();\n this.callLog.length = 0;\n }\n\n /**\n * Append a row to {@link callLog}. Internal helper called by every\n * recorded op before the actual work runs.\n */\n protected recordCall(operation: string, key: string | undefined, args: unknown[] = []): void {\n this.callLog.push({\n operation,\n key,\n args,\n timestamp: Date.now(),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,IAAa,kBAAb,cACU,gBAEV;;;cAIgB;iBAKqB,CAAC;iCAMc,IAAI,IAAI;kBAKnB,IAAI,iBAAiB;iBAOrB,CAAC;;;;;;CAMxC,MAAa,UAAyB;EACpC,KAAK,WAAW,WAAW,MAAS;EACpC,MAAM,MAAM,QAAQ;CACtB;;;;CAKA,MAAa,aAA4B;EACvC,KAAK,WAAW,cAAc,MAAS;EACvC,MAAM,MAAM,WAAW;CACzB;;;;;CAMA,MAAa,gBAAgB,WAAkC;EAC7D,MAAM,SAAS,KAAK,SAAS,SAAS;EAEtC,KAAK,WAAW,mBAAmB,QAAQ,CAAC,SAAS,CAAC;EACtD,KAAK,IAAI,YAAY,MAAM;EAE3B,MAAM,SAAS,SAAS;EAExB,KAAK,SAAS,gBAAgB,MAAM;EAEpC,KAAK,MAAM,OAAO,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC,GACvC,IAAI,QAAQ,UAAU,IAAI,WAAW,MAAM,GACzC,KAAK,QAAQ,OAAO,GAAG;EAI3B,KAAK,IAAI,WAAW,MAAM;CAC5B;;;;CAKA,MAAa,SAAS,WAAsC;EAC1D,MAAM,SAAS,KAAK,SAAS,SAAS;EAEtC,KAAK,WAAW,YAAY,QAAQ,CAAC,SAAS,CAAC;EAE/C,MAAM,MAAM,KAAK,IAAI;EAErB,OAAO,CAAC,GAAG,KAAK,QAAQ,QAAQ,CAAC,CAAC,CAC/B,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;;;CASA,AAAO,UAAmB,KAA8B;EACtD,MAAM,YAAY,KAAK,SAAS,GAAG;EACnC,MAAM,QAAQ,KAAK,QAAQ,IAAI,SAAS;EAExC,IAAI,CAAC,OACH;EAGF,OAAO,MAAM;CACf;;;;;CAMA,AAAO,QAAc;EACnB,KAAK,QAAQ,MAAM;EACnB,KAAK,SAAS,MAAM;EACpB,KAAK,QAAQ,SAAS;CACxB;;;;;CAMA,AAAU,WAAW,WAAmB,KAAyB,OAAkB,CAAC,GAAS;EAC3F,KAAK,QAAQ,KAAK;GAChB;GACA;GACA;GACA,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;AACF"}
@@ -41,6 +41,10 @@ export declare class NullCacheDriver extends BaseCacheDriver<NullCacheDriver, Nu
41
41
  * {@inheritdoc}
42
42
  */
43
43
  removeNamespace(namespace: string): Promise<this>;
44
+ /**
45
+ * {@inheritdoc}
46
+ */
47
+ listKeys(_namespace: string): Promise<string[]>;
44
48
  /**
45
49
  * The key as it may appear in a log line: parsed, with email addresses masked
46
50
  */
@@ -1 +1 @@
1
- {"version":3,"file":"null-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/null-cache-driver.ts"],"mappings":";;;;qBAYa,wBACH,gBAAgB,iBAAiB,mCAC9B,YAAY,iBAAiB;;;;EAKjC,SAAS;;;;EAKT;;;;EAKA,MAAM;;;;MAKF;;;;EAOX,YAAmB,UAAS;;;;EAQrB,WAAW,SAAS;;;;EAQpB,SAAS,KAAK;;;;;;EAUR,SACX,MAAM,UACN,eAAe,WAAW,iBAC1B,gBAAgB,eACf;;;;EAOU,gBAAgB,oBAAiB;;;;YAepC,YAAY,KAAK;;;;EAOd,IACX,KAAK,UACL,aACA,gBAAgB,WAAW,kBAC1B;;;;EAaU,IAAI,KAAK,WAAQ;;;;;;EAejB,OAAO,MAAM,UAAU,MAAM,WAAW;;;;EAOxC,OAAO,KAAK,WAAQ;;;;EAWpB,SAAK;;;;;;;EAcL,WAAW;;;;EAOX,WAAO"}
1
+ {"version":3,"file":"null-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/null-cache-driver.ts"],"mappings":";;;;qBAYa,wBACH,gBAAgB,iBAAiB,mCAC9B,YAAY,iBAAiB;;;;EAKjC,SAAS;;;;EAKT;;;;EAKA,MAAM;;;;MAKF;;;;EAOX,YAAmB,UAAS;;;;EAQrB,WAAW,SAAS;;;;EAQpB,SAAS,KAAK;;;;;;EAUR,SACX,MAAM,UACN,eAAe,WAAW,iBAC1B,gBAAgB,eACf;;;;EAOU,gBAAgB,oBAAiB;;;;EAejC,SAAS,qBAAqB;;;;YAOjC,YAAY,KAAK;;;;EAOd,IACX,KAAK,UACL,aACA,gBAAgB,WAAW,kBAC1B;;;;EAaU,IAAI,KAAK,WAAQ;;;;;;EAejB,OAAO,MAAM,UAAU,MAAM,WAAW;;;;EAOxC,OAAO,KAAK,WAAQ;;;;EAWpB,SAAK;;;;;;;EAcL,WAAW;;;;EAOX,WAAO"}
@@ -52,6 +52,12 @@ var NullCacheDriver = class extends BaseCacheDriver {
52
52
  return this;
53
53
  }
54
54
  /**
55
+ * {@inheritdoc}
56
+ */
57
+ async listKeys(_namespace) {
58
+ return [];
59
+ }
60
+ /**
55
61
  * The key as it may appear in a log line: parsed, with email addresses masked
56
62
  */
57
63
  loggableKey(key) {
@@ -1 +1 @@
1
- {"version":3,"file":"null-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/null-cache-driver.ts"],"mappings":";;;;AAYA,IAAa,kBAAb,cACU,gBAEV;;;;CAmBE,IAAW,SAAS;EAClB,OAAO;CACT;;;;CAKA,AAAO,YAAY,UAAyB,CAAC,GAAG;EAC9C,MAAM;iBAvBwB,CAAC;cAKnB;cAKe,CAAC;EAc5B,KAAK,WAAW,OAAO;CACzB;;;;CAKA,AAAO,WAAW,SAAwB;EACxC,KAAK,UAAU;EACf,OAAO;CACT;;;;CAKA,AAAO,SAAS,KAAe;EAE7B,OAAO,MA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CAEtE;AACF"}
1
+ {"version":3,"file":"null-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/null-cache-driver.ts"],"sourcesContent":["import type { GenericObject } from \"@mongez/reinforcements\";\nimport { log, maskEmailsInText } from \"@warlock.js/logger\";\nimport type {\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheTtl,\n NullCacheDriverOptions,\n RememberOptions,\n} from \"../types\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\n\nexport class NullCacheDriver\n extends BaseCacheDriver<NullCacheDriver, NullCacheDriverOptions>\n implements CacheDriver<NullCacheDriver, NullCacheDriverOptions>\n{\n /**\n * Options list\n */\n public options: GenericObject = {};\n\n /**\n * {@inheritdoc}\n */\n public name = \"null\";\n\n /**\n * Cached data\n */\n public data: GenericObject = {};\n\n /**\n * {@inheritdoc}\n */\n public get client() {\n return this;\n }\n\n /**\n * Constructor\n */\n public constructor(options: GenericObject = {}) {\n super();\n this.setOptions(options);\n }\n\n /**\n * {@inheritdoc}\n */\n public setOptions(options: GenericObject) {\n this.options = options;\n return this;\n }\n\n /**\n * {@inheritdoc}\n */\n public parseKey(key: CacheKey) {\n // Real parsed key so the base lock map never merges distinct keys.\n return super.parseKey(key);\n }\n\n /**\n * {@inheritdoc}\n *\n * Nothing is stored, so always run the callback and return its own result.\n */\n public async remember(\n _key: CacheKey,\n _ttlOrOptions: CacheTtl | RememberOptions,\n callback: () => Promise<any>,\n ): Promise<any> {\n return callback();\n }\n\n /**\n * {@inheritdoc}\n */\n public async removeNamespace(namespace: string) {\n if (this.shouldLog) {\n const loggableNamespace = maskEmailsInText(namespace);\n\n log.info(\"cache\", \"clearing namespace\", loggableNamespace);\n\n log.success(\"cache\", \"namespace cleared\", loggableNamespace);\n }\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n */\n public async listKeys(_namespace: string): Promise<string[]> {\n return [];\n }\n\n /**\n * The key as it may appear in a log line: parsed, with email addresses masked\n */\n protected loggableKey(key: CacheKey): string {\n return maskEmailsInText(this.parseKey(key));\n }\n\n /**\n * {@inheritdoc}\n */\n public async set(\n key: CacheKey,\n _value: any,\n _ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n if (this.shouldLog) {\n log.info(\"cache\", \"setting key\", this.loggableKey(key));\n\n log.success(\"cache\", \"key set\", this.loggableKey(key));\n }\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n if (this.shouldLog) {\n log.info(\"cache\", \"fetching\", this.loggableKey(key));\n\n log.success(\"cache\", \"fetched\", this.loggableKey(key));\n }\n\n return null;\n }\n\n /**\n * {@inheritdoc}\n *\n * The null driver stores nothing, so there is never an entry to extend.\n */\n public async extend(_key: CacheKey, _ttl: CacheTtl): Promise<boolean> {\n return false;\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n if (this.shouldLog) {\n log.info(\"cache\", \"removing\", this.loggableKey(key));\n\n log.success(\"cache\", \"removed\", this.loggableKey(key));\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async flush() {\n if (this.shouldLog) {\n log.info(\"cache\", \"flushing\", \"all\");\n\n log.success(\"cache\", \"flushed\", \"all\");\n }\n }\n\n /**\n * {@inheritdoc}\n *\n * The null driver is a black-hole — `similar()` mirrors `get()` and returns\n * an empty result set rather than throwing.\n */\n public async similar(): Promise<any[]> {\n return [];\n }\n\n /**\n * {@inheritdoc}\n */\n public async connect() {\n if (this.shouldLog) {\n log.success(\"cache\", \"connected\", \"Connected to null cache driver\");\n }\n }\n}\n"],"mappings":";;;;AAYA,IAAa,kBAAb,cACU,gBAEV;;;;CAmBE,IAAW,SAAS;EAClB,OAAO;CACT;;;;CAKA,AAAO,YAAY,UAAyB,CAAC,GAAG;EAC9C,MAAM;iBAvBwB,CAAC;cAKnB;cAKe,CAAC;EAc5B,KAAK,WAAW,OAAO;CACzB;;;;CAKA,AAAO,WAAW,SAAwB;EACxC,KAAK,UAAU;EACf,OAAO;CACT;;;;C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O,CAAC;CACV;;;;CAKA,MAAa,UAAU;EACrB,IAAI,KAAK,WACP,IAAI,QAAQ,SAAS,aAAa,gCAAgC;CAEtE;AACF"}
@@ -218,6 +218,10 @@ export declare class PgCacheDriver extends BaseCacheDriver<PgClientLike, PgCache
218
218
  * `<namespace>.` — same boundary semantics as the other drivers.
219
219
  */
220
220
  removeNamespace(namespace: string): Promise<this>;
221
+ /**
222
+ * {@inheritdoc}
223
+ */
224
+ listKeys(namespace: string): Promise<string[]>;
221
225
  /**
222
226
  * {@inheritdoc}
223
227
  *
@@ -1 +1 @@
1
- {"version":3,"file":"pg-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/pg-cache-driver.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA0Da,sBACH,gBAAgB,cAAc,2BAC3B,YAAY,cAAc;;;;EAK9B;;;;;YAMG;;;;;;EAOH,WAAW,SAAS;;;;;;;YAsCX,qBAAqB;;;;;;YA6B3B,aAAa;;;;;gBAQT;;;;;gBAQA,YAAY;;;;;;YASV,eAAe,KAAK,UAAU,oBAAoB;;;;;;;;;;;;;;EAgCrD,OAAO,QAAQ,UAAU,oBAAoB;;;;;;;;EAiC7C,UAAU,QAAQ,UAAU,oBAAoB;;;;;;YAgCnD,aAAa;;;;;EAYV,MAAM,iBAAe;;;;YAaxB;;;;;;;;EAeH;;;;EAuCM,WAAO;;;;;;EAaP,cAAU;;;;EAQV,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;EAuIU,IAAI,KAAK,WAAQ;;;;;;YA2Cd,SAAS,KAAK,WAAW,QAAQ;;;;;YA6CvC,WAAW;;;;;;;;;EAoBR,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;;EA0CU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EAuBtC,KAAK,KAAK,WAAW;;;;;;;;;;;;;EAoCrB,OAAO,SAClB,KAAK,UACL,KAAK,SAAS,aAAa,WA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;;;EAqFE,OAAO,KAAK,WAAW;;;;;;;EAgBvB,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAyB5C,WAAW,MAAM,aAAa;;;;EAuB9B,OAAO,KAAK,WAAQ;;;;;;;EAiBpB,gBAAgB,oBAAiB;;;;EAwBjC,SAAS,oBAAoB;;;;;;;;EA2B7B,SAAK;;;;;;;;;;;;;;;;;EA6BL,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB"}
@@ -629,6 +629,14 @@ var PgCacheDriver = class extends BaseCacheDriver {
629
629
  }
630
630
  /**
631
631
  * {@inheritdoc}
632
+ */
633
+ async listKeys(namespace) {
634
+ const parsed = this.parseKey(namespace);
635
+ const t = this.table;
636
+ return (parsed === "" ? await this.pgClient.query(`SELECT key FROM ${t} WHERE (expires_at IS NULL OR expires_at > now())`) : await this.pgClient.query(`SELECT key FROM ${t} WHERE (key = $1 OR key LIKE $2 ESCAPE '\\') AND (expires_at IS NULL OR expires_at > now())`, [parsed, `${parsed.replace(/\\/g, "\\\\").replace(/_/g, "\\_").replace(/%/g, "\\%")}.%`])).rows.map((row) => this.unprefixKey(row.key));
637
+ }
638
+ /**
639
+ * {@inheritdoc}
632
640
  *
633
641
  * Honors `globalPrefix` — when configured, scopes the flush to entries
634
642
  * under the prefix rather than truncating the entire table (which could