tricache 1.0.2 → 2.0.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 (101) hide show
  1. package/README.md +78 -90
  2. package/dashboards/tricache-alerts.yaml +80 -4
  3. package/dashboards/tricache-grafana.json +54 -1
  4. package/dashboards/tricache-inventory.rules.yml +21 -0
  5. package/dist/{cache-service-CWI4jkS7.d.cts → cache-service-BV5T8-20.d.cts} +122 -21
  6. package/dist/cache-service-UZXOQGEY.js +14 -0
  7. package/dist/{cache-service-B108FzER.d.ts → cache-service-tpyrXvlH.d.ts} +122 -21
  8. package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
  9. package/dist/{chunk-H4GFLQ26.js → chunk-KV7KISK2.js} +47 -1
  10. package/dist/{chunk-WYF7NOAT.js → chunk-MB3DMVWN.js} +2111 -543
  11. package/dist/{chunk-OYDU3SMI.js → chunk-RBJRTGFK.js} +5 -0
  12. package/dist/chunk-S5N65I45.js +17 -0
  13. package/dist/cli.cjs +2454 -572
  14. package/dist/cli.js +186 -11
  15. package/dist/dashboard/index.d.cts +2 -2
  16. package/dist/dashboard/index.d.ts +2 -2
  17. package/dist/drizzle/index.cjs +2335 -571
  18. package/dist/drizzle/index.d.cts +2 -2
  19. package/dist/drizzle/index.d.ts +2 -2
  20. package/dist/drizzle/index.js +6 -2
  21. package/dist/edge/index.cjs +145 -43
  22. package/dist/edge/index.d.cts +11 -4
  23. package/dist/edge/index.d.ts +11 -4
  24. package/dist/edge/index.js +118 -43
  25. package/dist/hono/index.cjs +2322 -569
  26. package/dist/hono/index.d.cts +2 -2
  27. package/dist/hono/index.d.ts +2 -2
  28. package/dist/hono/index.js +2 -2
  29. package/dist/{hono-C886ok3X.d.cts → hono-CMv2VdQ6.d.cts} +18 -5
  30. package/dist/{hono-3rDMYVtY.d.ts → hono-Dvq04kX9.d.ts} +18 -5
  31. package/dist/http/index.cjs +2323 -570
  32. package/dist/http/index.d.cts +3 -3
  33. package/dist/http/index.d.ts +3 -3
  34. package/dist/http/index.js +4 -4
  35. package/dist/index.cjs +2554 -620
  36. package/dist/index.d.cts +88 -23
  37. package/dist/index.d.ts +88 -23
  38. package/dist/index.js +873 -16
  39. package/dist/{murmur3-CMGw9PbV.d.cts → murmur3-DF8BFRnu.d.cts} +1 -0
  40. package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.ts} +1 -0
  41. package/dist/nestjs/index.cjs +2292 -574
  42. package/dist/nestjs/index.d.cts +19 -5
  43. package/dist/nestjs/index.d.ts +19 -5
  44. package/dist/nestjs/index.js +25 -19
  45. package/dist/next/index.cjs +2306 -571
  46. package/dist/next/index.d.cts +8 -2
  47. package/dist/next/index.d.ts +8 -2
  48. package/dist/next/index.js +36 -9
  49. package/dist/prisma/index.cjs +26 -25
  50. package/dist/prisma/index.d.cts +2 -2
  51. package/dist/prisma/index.d.ts +2 -2
  52. package/dist/prisma/index.js +14 -25
  53. package/dist/serialize-worker.cjs +162 -39
  54. package/dist/serialize-worker.js +9 -7
  55. package/dist/{types-BA4pz1A0.d.cts → types-F8vRWMrE.d.cts} +162 -45
  56. package/dist/{types-BA4pz1A0.d.ts → types-F8vRWMrE.d.ts} +162 -45
  57. package/package.json +21 -2
  58. package/src/adapters/auto-pipeliner.ts +52 -11
  59. package/src/cache-service.ts +1537 -415
  60. package/src/cli.ts +2 -9
  61. package/src/codec.ts +3 -3
  62. package/src/compression.ts +39 -16
  63. package/src/cross-region.ts +1 -1
  64. package/src/disk-tier.ts +283 -43
  65. package/src/drizzle/index.ts +2 -1
  66. package/src/edge/adapters/cloudflare-do.ts +25 -10
  67. package/src/edge/adapters/cloudflare-kv.ts +12 -9
  68. package/src/edge/adapters/upstash.ts +27 -11
  69. package/src/edge/cache.ts +59 -17
  70. package/src/edge/types.ts +15 -5
  71. package/src/encryption.ts +50 -18
  72. package/src/env.d.ts +1 -1
  73. package/src/errors.ts +12 -0
  74. package/src/http/utils.ts +6 -0
  75. package/src/index.ts +6 -0
  76. package/src/latency-watchdog.ts +5 -1
  77. package/src/nestjs/decorators.ts +11 -6
  78. package/src/nestjs/tricache.module.ts +2 -1
  79. package/src/nestjs/tricache.store.ts +21 -9
  80. package/src/nestjs/types.ts +1 -1
  81. package/src/next/cache-handler.ts +24 -4
  82. package/src/next/types.ts +4 -0
  83. package/src/origin-capacity.ts +134 -0
  84. package/src/prisma/index.ts +14 -32
  85. package/src/remote-snapshot.ts +37 -27
  86. package/src/serialize-worker.ts +8 -5
  87. package/src/sigv4-snapshot-adapter.ts +37 -27
  88. package/src/smart-memory-cache.ts +62 -22
  89. package/src/types.ts +92 -35
  90. package/src/utils/config-comparison.ts +29 -0
  91. package/src/utils/lz4-size.ts +74 -0
  92. package/src/utils/namespace-key.ts +48 -0
  93. package/src/utils/query-key.ts +13 -0
  94. package/src/utils/snapshot-transfer.ts +83 -0
  95. package/src/utils/work-limits.ts +73 -0
  96. package/src/utils/write-revision.ts +4 -0
  97. package/src/wasm/bloom-filter-wasm.ts +16 -1
  98. package/src/worker-pool.ts +28 -8
  99. package/src/wtiny-lfu.ts +62 -14
  100. package/dist/cache-service-GYPZFB7O.js +0 -12
  101. package/dist/chunk-VNRDL5RA.js +0 -666
@@ -1,5 +1,5 @@
1
- import { C as CacheOptions, f as CachePriority } from '../types-BA4pz1A0.cjs';
2
- import { C as CacheService } from '../cache-service-CWI4jkS7.cjs';
1
+ import { C as CacheOptions, f as CachePriority } from '../types-F8vRWMrE.cjs';
2
+ import { C as CacheService } from '../cache-service-BV5T8-20.cjs';
3
3
  import { EventEmitter } from 'node:events';
4
4
  import 'crypto';
5
5
 
@@ -138,7 +138,8 @@ declare class TriCacheStore extends EventEmitter implements NestCacheStore {
138
138
  * Set an item in the cache.
139
139
  * @param key - Cache key
140
140
  * @param value - Cache value
141
- * @param ttl - TTL in milliseconds (0 = indefinite / default engine TTL)
141
+ * @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
142
+ * `0` means indefinite; positive values are converted to seconds.
142
143
  */
143
144
  set<T>(key: string, value: T, ttl?: number): Promise<T>;
144
145
  /**
@@ -181,6 +182,12 @@ declare class TriCacheStore extends EventEmitter implements NestCacheStore {
181
182
  */
182
183
  ttl(key: string): Promise<number | undefined>;
183
184
  wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
185
+ /**
186
+ * Translate a cache-manager millisecond TTL into engine seconds using the same
187
+ * contract as `set()`: omitted keeps the engine default, `0` means indefinite,
188
+ * and positive values convert exactly (sub-second values round up).
189
+ */
190
+ private _ttlSeconds;
184
191
  cacheId(): string;
185
192
  get stores(): unknown[];
186
193
  clear(): Promise<boolean>;
@@ -221,9 +228,16 @@ interface CacheableOptions {
221
228
  * Example: (id: string) => `user:${id}`
222
229
  */
223
230
  key?: string | ((...args: any[]) => string);
224
- /** TTL in seconds (or milliseconds if specified / detected). Default: 300 s. */
231
+ /**
232
+ * TTL value. Unit is controlled by `ttlUnit` and defaults to seconds.
233
+ * Default: 300 s.
234
+ */
225
235
  ttl?: number;
226
- /** Explicit time unit for the ttl option. Default: 'seconds'. */
236
+ /**
237
+ * Explicit time unit for `ttl`. Default: `'seconds'`.
238
+ * There is no implicit unit detection: `ttl: 5000` is 5,000 seconds unless
239
+ * `ttlUnit: 'milliseconds'` is set.
240
+ */
227
241
  ttlUnit?: 'seconds' | 'milliseconds';
228
242
  /** Stale-While-Revalidate grace period in seconds. */
229
243
  swr?: number;
@@ -1,5 +1,5 @@
1
- import { C as CacheOptions, f as CachePriority } from '../types-BA4pz1A0.js';
2
- import { C as CacheService } from '../cache-service-B108FzER.js';
1
+ import { C as CacheOptions, f as CachePriority } from '../types-F8vRWMrE.js';
2
+ import { C as CacheService } from '../cache-service-tpyrXvlH.js';
3
3
  import { EventEmitter } from 'node:events';
4
4
  import 'crypto';
5
5
 
@@ -138,7 +138,8 @@ declare class TriCacheStore extends EventEmitter implements NestCacheStore {
138
138
  * Set an item in the cache.
139
139
  * @param key - Cache key
140
140
  * @param value - Cache value
141
- * @param ttl - TTL in milliseconds (0 = indefinite / default engine TTL)
141
+ * @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
142
+ * `0` means indefinite; positive values are converted to seconds.
142
143
  */
143
144
  set<T>(key: string, value: T, ttl?: number): Promise<T>;
144
145
  /**
@@ -181,6 +182,12 @@ declare class TriCacheStore extends EventEmitter implements NestCacheStore {
181
182
  */
182
183
  ttl(key: string): Promise<number | undefined>;
183
184
  wrap<T>(key: string, fetch: () => T | Promise<T>, ttl?: number, refreshThreshold?: number): Promise<T>;
185
+ /**
186
+ * Translate a cache-manager millisecond TTL into engine seconds using the same
187
+ * contract as `set()`: omitted keeps the engine default, `0` means indefinite,
188
+ * and positive values convert exactly (sub-second values round up).
189
+ */
190
+ private _ttlSeconds;
184
191
  cacheId(): string;
185
192
  get stores(): unknown[];
186
193
  clear(): Promise<boolean>;
@@ -221,9 +228,16 @@ interface CacheableOptions {
221
228
  * Example: (id: string) => `user:${id}`
222
229
  */
223
230
  key?: string | ((...args: any[]) => string);
224
- /** TTL in seconds (or milliseconds if specified / detected). Default: 300 s. */
231
+ /**
232
+ * TTL value. Unit is controlled by `ttlUnit` and defaults to seconds.
233
+ * Default: 300 s.
234
+ */
225
235
  ttl?: number;
226
- /** Explicit time unit for the ttl option. Default: 'seconds'. */
236
+ /**
237
+ * Explicit time unit for `ttl`. Default: `'seconds'`.
238
+ * There is no implicit unit detection: `ttl: 5000` is 5,000 seconds unless
239
+ * `ttlUnit: 'milliseconds'` is set.
240
+ */
227
241
  ttlUnit?: 'seconds' | 'milliseconds';
228
242
  /** Stale-While-Revalidate grace period in seconds. */
229
243
  swr?: number;
@@ -1,11 +1,9 @@
1
- import "../chunk-VNRDL5RA.js";
2
1
  import {
3
- CacheService
4
- } from "../chunk-WYF7NOAT.js";
5
- import "../chunk-UBWLPKTI.js";
6
- import "../chunk-JNSLMK4Q.js";
7
- import "../chunk-UGD4VEPD.js";
8
- import "../chunk-H4GFLQ26.js";
2
+ CacheService,
3
+ INDEFINITE_TTL_SECONDS
4
+ } from "../chunk-MB3DMVWN.js";
5
+ import "../chunk-EJXG7WO6.js";
6
+ import "../chunk-KV7KISK2.js";
9
7
 
10
8
  // src/nestjs/tricache.store.ts
11
9
  import { EventEmitter } from "events";
@@ -28,11 +26,11 @@ var TriCacheStore = class extends EventEmitter {
28
26
  * Set an item in the cache.
29
27
  * @param key - Cache key
30
28
  * @param value - Cache value
31
- * @param ttl - TTL in milliseconds (0 = indefinite / default engine TTL)
29
+ * @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
30
+ * `0` means indefinite; positive values are converted to seconds.
32
31
  */
33
32
  async set(key, value, ttl) {
34
- const ttlSeconds = typeof ttl === "number" && ttl > 0 ? ttl / 1e3 : ttl === 0 ? 0 : void 0;
35
- await this.cache.set(key, value, ttlSeconds);
33
+ await this.cache.set(key, value, this._ttlSeconds(ttl) ?? 300);
36
34
  return value;
37
35
  }
38
36
  /**
@@ -61,10 +59,7 @@ var TriCacheStore = class extends EventEmitter {
61
59
  if (entries.length === 0) return [];
62
60
  const batch = {};
63
61
  for (const e of entries) {
64
- batch[e.key] = {
65
- value: e.value,
66
- ttl: typeof e.ttl === "number" && e.ttl > 0 ? e.ttl / 1e3 : e.ttl === 0 ? 0 : void 0
67
- };
62
+ batch[e.key] = { value: e.value, ttl: this._ttlSeconds(e.ttl) ?? 300 };
68
63
  }
69
64
  await this.cache.mset(batch);
70
65
  return entries;
@@ -93,10 +88,23 @@ var TriCacheStore = class extends EventEmitter {
93
88
  return rem !== null ? rem * 1e3 : void 0;
94
89
  }
95
90
  async wrap(key, fetch, ttl, refreshThreshold) {
96
- const seconds = ttl === void 0 ? 0 : ttl / 1e3;
91
+ const seconds = this._ttlSeconds(ttl);
97
92
  const refreshAhead = ttl && refreshThreshold ? Math.max(0, Math.min(1, (ttl - refreshThreshold) / ttl)) : void 0;
98
93
  return this.cache.wrap(key, async () => await fetch(), { ttl: seconds, refreshAhead });
99
94
  }
95
+ /**
96
+ * Translate a cache-manager millisecond TTL into engine seconds using the same
97
+ * contract as `set()`: omitted keeps the engine default, `0` means indefinite,
98
+ * and positive values convert exactly (sub-second values round up).
99
+ */
100
+ _ttlSeconds(ttl) {
101
+ if (ttl === void 0) return void 0;
102
+ if (typeof ttl !== "number" || !Number.isFinite(ttl) || ttl < 0) {
103
+ throw new TypeError("TriCacheStore TTL must be a finite non-negative number of milliseconds");
104
+ }
105
+ if (ttl === 0) return INDEFINITE_TTL_SECONDS;
106
+ return Math.max(1e-3, ttl / 1e3);
107
+ }
100
108
  cacheId() {
101
109
  return `tricache:${this.cache.options.namespace ?? "default"}`;
102
110
  }
@@ -270,10 +278,8 @@ function Cacheable(options = {}) {
270
278
  const key = typeof options.key === "function" ? options.key(...args) : typeof options.key === "string" ? options.key : `${className}:${methodName}:${JSON.stringify(args)}`;
271
279
  let ttlSeconds = options.ttl ?? 300;
272
280
  const rawTtl = options.ttl;
273
- if (typeof rawTtl === "number") {
274
- if (options.ttlUnit === "milliseconds" || rawTtl >= 1e3 && rawTtl % 1e3 === 0 && options.ttlUnit !== "seconds") {
275
- ttlSeconds = rawTtl / 1e3;
276
- }
281
+ if (typeof rawTtl === "number" && options.ttlUnit === "milliseconds") {
282
+ ttlSeconds = rawTtl / 1e3;
277
283
  }
278
284
  const tags = typeof options.tags === "function" ? options.tags(...args) : options.tags;
279
285
  const dependsOn = typeof options.dependsOn === "function" ? options.dependsOn(...args) : options.dependsOn;