tricache 1.0.1 → 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 (127) hide show
  1. package/README.md +89 -93
  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-BV5T8-20.d.cts +1064 -0
  6. package/dist/cache-service-UZXOQGEY.js +14 -0
  7. package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
  8. package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
  9. package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
  10. package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
  11. package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
  12. package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
  13. package/dist/chunk-RBJRTGFK.js +94 -0
  14. package/dist/chunk-S5N65I45.js +17 -0
  15. package/dist/cli.cjs +3694 -1070
  16. package/dist/cli.d.cts +12 -0
  17. package/dist/cli.js +210 -14
  18. package/dist/dashboard/index.cjs +111 -29
  19. package/dist/dashboard/index.d.cts +185 -0
  20. package/dist/dashboard/index.d.ts +5 -3
  21. package/dist/dashboard/index.js +1 -1
  22. package/dist/drizzle/index.cjs +3578 -1068
  23. package/dist/drizzle/index.d.cts +46 -0
  24. package/dist/drizzle/index.d.ts +2 -2
  25. package/dist/drizzle/index.js +6 -2
  26. package/dist/edge/index.cjs +368 -162
  27. package/dist/edge/index.d.cts +134 -0
  28. package/dist/edge/index.d.ts +11 -4
  29. package/dist/edge/index.js +314 -155
  30. package/dist/hono/index.cjs +3614 -1087
  31. package/dist/hono/index.d.cts +93 -0
  32. package/dist/hono/index.d.ts +7 -5
  33. package/dist/hono/index.js +16 -9
  34. package/dist/hono-CMv2VdQ6.d.cts +404 -0
  35. package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
  36. package/dist/http/index.cjs +3712 -1124
  37. package/dist/http/index.d.cts +103 -0
  38. package/dist/http/index.d.ts +13 -5
  39. package/dist/http/index.js +92 -43
  40. package/dist/index.cjs +4067 -1252
  41. package/dist/index.d.cts +1071 -0
  42. package/dist/index.d.ts +123 -27
  43. package/dist/index.js +878 -21
  44. package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
  45. package/dist/murmur3-DF8BFRnu.d.ts +99 -0
  46. package/dist/nestjs/index.cjs +3635 -1112
  47. package/dist/nestjs/index.d.cts +299 -0
  48. package/dist/nestjs/index.d.ts +120 -33
  49. package/dist/nestjs/index.js +132 -43
  50. package/dist/next/index.cjs +3704 -1175
  51. package/dist/next/index.d.cts +238 -0
  52. package/dist/next/index.d.ts +39 -11
  53. package/dist/next/index.js +202 -102
  54. package/dist/prisma/index.cjs +29 -18
  55. package/dist/prisma/index.d.cts +62 -0
  56. package/dist/prisma/index.d.ts +2 -2
  57. package/dist/prisma/index.js +17 -18
  58. package/dist/serialize-worker.cjs +162 -39
  59. package/dist/serialize-worker.d.cts +2 -0
  60. package/dist/serialize-worker.js +9 -7
  61. package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
  62. package/dist/types-F8vRWMrE.d.ts +1636 -0
  63. package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
  64. package/dist/utils-Bvzn-rKS.d.ts +29 -0
  65. package/package.json +116 -37
  66. package/src/adapters/auto-pipeliner.ts +150 -26
  67. package/src/adapters/node-redis.ts +106 -27
  68. package/src/cache-service.ts +2215 -793
  69. package/src/cli.ts +25 -14
  70. package/src/codec.ts +3 -3
  71. package/src/compression.ts +39 -16
  72. package/src/cross-region.ts +22 -4
  73. package/src/dashboard/handler.ts +26 -6
  74. package/src/dashboard/html.ts +35 -10
  75. package/src/dashboard/index.ts +35 -13
  76. package/src/dashboard/types.ts +3 -1
  77. package/src/disk-tier.ts +448 -102
  78. package/src/drizzle/index.ts +2 -1
  79. package/src/edge/adapters/cloudflare-do.ts +25 -10
  80. package/src/edge/adapters/cloudflare-kv.ts +12 -9
  81. package/src/edge/adapters/upstash.ts +27 -11
  82. package/src/edge/cache.ts +200 -110
  83. package/src/edge/hono.ts +23 -6
  84. package/src/edge/types.ts +17 -5
  85. package/src/encryption.ts +50 -18
  86. package/src/env.d.ts +1 -1
  87. package/src/errors.ts +12 -0
  88. package/src/hono/index.ts +19 -9
  89. package/src/http/express.ts +62 -17
  90. package/src/http/fastify.ts +35 -21
  91. package/src/http/utils.ts +60 -20
  92. package/src/index.ts +6 -0
  93. package/src/ipc-telemetry.ts +35 -9
  94. package/src/latency-watchdog.ts +5 -1
  95. package/src/nestjs/decorators.ts +11 -6
  96. package/src/nestjs/index.ts +2 -0
  97. package/src/nestjs/keyv-adapter.ts +68 -0
  98. package/src/nestjs/tricache.module.ts +15 -12
  99. package/src/nestjs/tricache.store.ts +69 -26
  100. package/src/nestjs/types.ts +30 -16
  101. package/src/next/cache-handler.ts +151 -53
  102. package/src/next/index.ts +1 -0
  103. package/src/next/types.ts +25 -0
  104. package/src/origin-capacity.ts +134 -0
  105. package/src/prisma/index.ts +17 -24
  106. package/src/remote-snapshot.ts +37 -27
  107. package/src/serialize-worker.ts +8 -5
  108. package/src/sigv4-snapshot-adapter.ts +37 -27
  109. package/src/smart-memory-cache.ts +121 -44
  110. package/src/types.ts +117 -37
  111. package/src/utils/cgroup.ts +12 -0
  112. package/src/utils/config-comparison.ts +29 -0
  113. package/src/utils/deadline.ts +14 -0
  114. package/src/utils/diagnostics.ts +27 -0
  115. package/src/utils/lz4-size.ts +74 -0
  116. package/src/utils/namespace-key.ts +48 -0
  117. package/src/utils/query-key.ts +13 -0
  118. package/src/utils/redis-slot.ts +13 -0
  119. package/src/utils/snapshot-transfer.ts +83 -0
  120. package/src/utils/work-limits.ts +73 -0
  121. package/src/utils/write-revision.ts +4 -0
  122. package/src/wasm/bloom-filter-wasm.ts +25 -5
  123. package/src/worker-pool.ts +44 -15
  124. package/src/wtiny-lfu.ts +82 -20
  125. package/dist/cache-service-MG7PN6MX.js +0 -12
  126. package/dist/chunk-3I5L7K6I.js +0 -704
  127. package/dist/chunk-BQRURGGD.js +0 -60
@@ -0,0 +1,134 @@
1
+ import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-CMv2VdQ6.cjs';
2
+ export { C as CachedEdgeHttpResponse, e as CloudflareR2Bucket, f as CloudflareR2Object, E as EdgeCacheOptions, g as EdgeCacheService, i as EdgeExportSnapshotOptions, j as EdgeGetOptions, k as EdgeHydrateOptions, l as EdgeSnapshotPayload, m as EdgeSnapshotSource, H as HonoEdgeCacheOptions, n as IEdgeBloomFilter, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoEdgeCache } from '../hono-CMv2VdQ6.cjs';
3
+ export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from '../murmur3-DF8BFRnu.cjs';
4
+ import '../types-F8vRWMrE.cjs';
5
+ import 'crypto';
6
+
7
+ type WebCryptoMode = 'aes-256-gcm' | 'aes-128-gcm';
8
+ interface WebCryptoOptions {
9
+ keyBase64: string;
10
+ prevKeyBase64?: string;
11
+ mode?: WebCryptoMode;
12
+ }
13
+ /**
14
+ * Pure Web Crypto API implementation of TriCache AEAD encryption.
15
+ * Compatible with Cloudflare Workers, Fastly Compute, Vercel Edge, Deno, and modern browsers.
16
+ *
17
+ * Interoperates with Node.js `CacheEncryption` by reordering Web Crypto's trailing tag
18
+ * into TriCache's standard wire envelope:
19
+ * Envelope = IV[12] || Tag[16] || Ciphertext[N]
20
+ */
21
+ declare class WebCryptoEncryption {
22
+ readonly isEnabled: boolean;
23
+ private readonly mode;
24
+ private keyPromise;
25
+ private prevKeyPromise;
26
+ constructor(options?: WebCryptoOptions);
27
+ private _importKey;
28
+ /**
29
+ * Encrypts a plaintext string into a TriCache standard wire envelope.
30
+ * Format: `enc:v1:<base64(IV[12] | Tag[16] | Ciphertext)>`
31
+ */
32
+ encrypt(plaintext: string): Promise<string>;
33
+ /**
34
+ * Decrypts a TriCache standard wire envelope into plaintext.
35
+ * Handles envelopes created by both WebCryptoEncryption and Node.js CacheEncryption.
36
+ */
37
+ decrypt(envelopeStr: string): Promise<string>;
38
+ private _decryptWithKey;
39
+ }
40
+
41
+ /**
42
+ * High-performance HTTP-based Redis driver for Upstash.
43
+ * Compatible with pure V8 Edge Isolates (Cloudflare Workers, Vercel Edge, Fastly Compute).
44
+ *
45
+ * Communicates over HTTPS REST with zero native socket dependencies.
46
+ */
47
+ declare class UpstashRedisAdapter implements IEdgeRemoteStorage {
48
+ readonly tagConsistency: "atomic";
49
+ private readonly baseUrl;
50
+ private readonly token;
51
+ private readonly customFetch;
52
+ private readonly dangerouslyFlushDatabase;
53
+ constructor(options: UpstashRedisOptions);
54
+ private _executeCommand;
55
+ private _executePipeline;
56
+ get(key: string): Promise<string | null>;
57
+ set(key: string, value: string, ttlSeconds?: number): Promise<void>;
58
+ delete(key: string): Promise<void>;
59
+ mget(keys: string[]): Promise<(string | null)[]>;
60
+ mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
61
+ scanKeys(prefix: string): AsyncIterable<string>;
62
+ clear(prefix?: string): Promise<void>;
63
+ incrementTagVersion(tag: string): Promise<number>;
64
+ getTagVersion(tag: string): Promise<number>;
65
+ batchGetTagVersions(tags: string[]): Promise<Record<string, number>>;
66
+ }
67
+
68
+ /**
69
+ * Storage adapter for Cloudflare Workers KV.
70
+ *
71
+ * Mitigates Cloudflare KV's strict 60-second TTL floor by wrapping sub-minute
72
+ * TTLs in a lightweight timestamp envelope and validating expiry on read.
73
+ */
74
+ declare class CloudflareKVAdapter implements IEdgeRemoteStorage {
75
+ readonly tagConsistency: "eventual";
76
+ private readonly kv;
77
+ constructor(kv: CloudflareKVNamespace);
78
+ get(key: string): Promise<string | null>;
79
+ set(key: string, value: string, ttlSeconds?: number): Promise<void>;
80
+ delete(key: string): Promise<void>;
81
+ mget(keys: string[]): Promise<(string | null)[]>;
82
+ mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
83
+ scanKeys(prefix: string): AsyncIterable<string>;
84
+ clear(prefix?: string): Promise<void>;
85
+ incrementTagVersion(tag: string): Promise<number>;
86
+ getTagVersion(tag: string): Promise<number>;
87
+ batchGetTagVersions(tags: string[]): Promise<Record<string, number>>;
88
+ }
89
+
90
+ /**
91
+ * Storage adapter for Cloudflare Durable Objects transactional storage (`state.storage`).
92
+ * Enables strongly-consistent edge caching and coordination across edge isolates.
93
+ */
94
+ declare class CloudflareDOStorageAdapter implements IEdgeRemoteStorage {
95
+ readonly tagConsistency: "atomic";
96
+ private readonly storage;
97
+ constructor(storage: CloudflareDOStorage);
98
+ get(key: string): Promise<string | null>;
99
+ set(key: string, value: string, ttlSeconds?: number): Promise<void>;
100
+ delete(key: string): Promise<void>;
101
+ mget(keys: string[]): Promise<(string | null)[]>;
102
+ mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
103
+ scanKeys(prefix: string): AsyncIterable<string>;
104
+ clear(prefix?: string): Promise<void>;
105
+ incrementTagVersion(tag: string): Promise<number>;
106
+ getTagVersion(tag: string): Promise<number>;
107
+ batchGetTagVersions(tags: string[]): Promise<Record<string, number>>;
108
+ }
109
+
110
+ /**
111
+ * Zero-dependency Base64 <-> Uint8Array utilities designed for pure Edge isolates
112
+ * (Cloudflare Workers without nodejs_compat, Deno, Fastly Compute, browsers).
113
+ *
114
+ * Avoids call stack overflow (RangeError: Maximum call stack size exceeded)
115
+ * on payloads > 64 KB by chunking binary data into safe 8 KB slices.
116
+ */
117
+ /**
118
+ * Converts a Uint8Array to a standard Base64 string safely across all JS runtimes.
119
+ */
120
+ declare function uint8ArrayToBase64(bytes: Uint8Array): string;
121
+ /**
122
+ * Converts a Base64 string to a Uint8Array safely across all JS runtimes.
123
+ */
124
+ declare function base64ToUint8Array(base64: string): Uint8Array;
125
+ /**
126
+ * Encodes a UTF-8 string to a Uint8Array using standard TextEncoder.
127
+ */
128
+ declare function utf8ToUint8Array(str: string): Uint8Array;
129
+ /**
130
+ * Decodes a Uint8Array to a UTF-8 string using standard TextDecoder.
131
+ */
132
+ declare function uint8ArrayToUtf8(bytes: Uint8Array): string;
133
+
134
+ export { CloudflareDOStorage, CloudflareDOStorageAdapter, CloudflareKVAdapter, CloudflareKVNamespace, IEdgeRemoteStorage, UpstashRedisAdapter, UpstashRedisOptions, WebCryptoEncryption, type WebCryptoMode, type WebCryptoOptions, base64ToUint8Array, uint8ArrayToBase64, uint8ArrayToUtf8, utf8ToUint8Array };
@@ -1,7 +1,7 @@
1
- import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-DSV2ve66.js';
2
- export { C as CachedEdgeHttpResponse, e as CloudflareR2Bucket, f as CloudflareR2Object, E as EdgeCacheOptions, g as EdgeCacheService, i as EdgeExportSnapshotOptions, j as EdgeGetOptions, k as EdgeHydrateOptions, l as EdgeSnapshotPayload, m as EdgeSnapshotSource, H as HonoEdgeCacheOptions, n as IEdgeBloomFilter, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoEdgeCache } from '../hono-DSV2ve66.js';
3
- export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from '../murmur3-CMGw9PbV.js';
4
- import '../types-Dyip5wAl.js';
1
+ import { I as IEdgeRemoteStorage, U as UpstashRedisOptions, a as CloudflareKVNamespace, d as CloudflareDOStorage } from '../hono-Dvq04kX9.js';
2
+ export { C as CachedEdgeHttpResponse, e as CloudflareR2Bucket, f as CloudflareR2Object, E as EdgeCacheOptions, g as EdgeCacheService, i as EdgeExportSnapshotOptions, j as EdgeGetOptions, k as EdgeHydrateOptions, l as EdgeSnapshotPayload, m as EdgeSnapshotSource, H as HonoEdgeCacheOptions, n as IEdgeBloomFilter, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoEdgeCache } from '../hono-Dvq04kX9.js';
3
+ export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from '../murmur3-DF8BFRnu.js';
4
+ import '../types-F8vRWMrE.js';
5
5
  import 'crypto';
6
6
 
7
7
  type WebCryptoMode = 'aes-256-gcm' | 'aes-128-gcm';
@@ -45,9 +45,11 @@ declare class WebCryptoEncryption {
45
45
  * Communicates over HTTPS REST with zero native socket dependencies.
46
46
  */
47
47
  declare class UpstashRedisAdapter implements IEdgeRemoteStorage {
48
+ readonly tagConsistency: "atomic";
48
49
  private readonly baseUrl;
49
50
  private readonly token;
50
51
  private readonly customFetch;
52
+ private readonly dangerouslyFlushDatabase;
51
53
  constructor(options: UpstashRedisOptions);
52
54
  private _executeCommand;
53
55
  private _executePipeline;
@@ -56,6 +58,7 @@ declare class UpstashRedisAdapter implements IEdgeRemoteStorage {
56
58
  delete(key: string): Promise<void>;
57
59
  mget(keys: string[]): Promise<(string | null)[]>;
58
60
  mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
61
+ scanKeys(prefix: string): AsyncIterable<string>;
59
62
  clear(prefix?: string): Promise<void>;
60
63
  incrementTagVersion(tag: string): Promise<number>;
61
64
  getTagVersion(tag: string): Promise<number>;
@@ -69,6 +72,7 @@ declare class UpstashRedisAdapter implements IEdgeRemoteStorage {
69
72
  * TTLs in a lightweight timestamp envelope and validating expiry on read.
70
73
  */
71
74
  declare class CloudflareKVAdapter implements IEdgeRemoteStorage {
75
+ readonly tagConsistency: "eventual";
72
76
  private readonly kv;
73
77
  constructor(kv: CloudflareKVNamespace);
74
78
  get(key: string): Promise<string | null>;
@@ -76,6 +80,7 @@ declare class CloudflareKVAdapter implements IEdgeRemoteStorage {
76
80
  delete(key: string): Promise<void>;
77
81
  mget(keys: string[]): Promise<(string | null)[]>;
78
82
  mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
83
+ scanKeys(prefix: string): AsyncIterable<string>;
79
84
  clear(prefix?: string): Promise<void>;
80
85
  incrementTagVersion(tag: string): Promise<number>;
81
86
  getTagVersion(tag: string): Promise<number>;
@@ -87,6 +92,7 @@ declare class CloudflareKVAdapter implements IEdgeRemoteStorage {
87
92
  * Enables strongly-consistent edge caching and coordination across edge isolates.
88
93
  */
89
94
  declare class CloudflareDOStorageAdapter implements IEdgeRemoteStorage {
95
+ readonly tagConsistency: "atomic";
90
96
  private readonly storage;
91
97
  constructor(storage: CloudflareDOStorage);
92
98
  get(key: string): Promise<string | null>;
@@ -94,6 +100,7 @@ declare class CloudflareDOStorageAdapter implements IEdgeRemoteStorage {
94
100
  delete(key: string): Promise<void>;
95
101
  mget(keys: string[]): Promise<(string | null)[]>;
96
102
  mset(entries: Record<string, string>, ttlSeconds?: number): Promise<void>;
103
+ scanKeys(prefix: string): AsyncIterable<string>;
97
104
  clear(prefix?: string): Promise<void>;
98
105
  incrementTagVersion(tag: string): Promise<number>;
99
106
  getTagVersion(tag: string): Promise<number>;