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.
- package/README.md +78 -90
- package/dashboards/tricache-alerts.yaml +80 -4
- package/dashboards/tricache-grafana.json +54 -1
- package/dashboards/tricache-inventory.rules.yml +21 -0
- package/dist/{cache-service-CWI4jkS7.d.cts → cache-service-BV5T8-20.d.cts} +122 -21
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-B108FzER.d.ts → cache-service-tpyrXvlH.d.ts} +122 -21
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-H4GFLQ26.js → chunk-KV7KISK2.js} +47 -1
- package/dist/{chunk-WYF7NOAT.js → chunk-MB3DMVWN.js} +2111 -543
- package/dist/{chunk-OYDU3SMI.js → chunk-RBJRTGFK.js} +5 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +2454 -572
- package/dist/cli.js +186 -11
- package/dist/dashboard/index.d.cts +2 -2
- package/dist/dashboard/index.d.ts +2 -2
- package/dist/drizzle/index.cjs +2335 -571
- package/dist/drizzle/index.d.cts +2 -2
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +145 -43
- package/dist/edge/index.d.cts +11 -4
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +118 -43
- package/dist/hono/index.cjs +2322 -569
- package/dist/hono/index.d.cts +2 -2
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/{hono-C886ok3X.d.cts → hono-CMv2VdQ6.d.cts} +18 -5
- package/dist/{hono-3rDMYVtY.d.ts → hono-Dvq04kX9.d.ts} +18 -5
- package/dist/http/index.cjs +2323 -570
- package/dist/http/index.d.cts +3 -3
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +4 -4
- package/dist/index.cjs +2554 -620
- package/dist/index.d.cts +88 -23
- package/dist/index.d.ts +88 -23
- package/dist/index.js +873 -16
- package/dist/{murmur3-CMGw9PbV.d.cts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.ts} +1 -0
- package/dist/nestjs/index.cjs +2292 -574
- package/dist/nestjs/index.d.cts +19 -5
- package/dist/nestjs/index.d.ts +19 -5
- package/dist/nestjs/index.js +25 -19
- package/dist/next/index.cjs +2306 -571
- package/dist/next/index.d.cts +8 -2
- package/dist/next/index.d.ts +8 -2
- package/dist/next/index.js +36 -9
- package/dist/prisma/index.cjs +26 -25
- package/dist/prisma/index.d.cts +2 -2
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +14 -25
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-BA4pz1A0.d.cts → types-F8vRWMrE.d.cts} +162 -45
- package/dist/{types-BA4pz1A0.d.ts → types-F8vRWMrE.d.ts} +162 -45
- package/package.json +21 -2
- package/src/adapters/auto-pipeliner.ts +52 -11
- package/src/cache-service.ts +1537 -415
- package/src/cli.ts +2 -9
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +1 -1
- package/src/disk-tier.ts +283 -43
- package/src/drizzle/index.ts +2 -1
- package/src/edge/adapters/cloudflare-do.ts +25 -10
- package/src/edge/adapters/cloudflare-kv.ts +12 -9
- package/src/edge/adapters/upstash.ts +27 -11
- package/src/edge/cache.ts +59 -17
- package/src/edge/types.ts +15 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/http/utils.ts +6 -0
- package/src/index.ts +6 -0
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/tricache.module.ts +2 -1
- package/src/nestjs/tricache.store.ts +21 -9
- package/src/nestjs/types.ts +1 -1
- package/src/next/cache-handler.ts +24 -4
- package/src/next/types.ts +4 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +14 -32
- package/src/remote-snapshot.ts +37 -27
- package/src/serialize-worker.ts +8 -5
- package/src/sigv4-snapshot-adapter.ts +37 -27
- package/src/smart-memory-cache.ts +62 -22
- package/src/types.ts +92 -35
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/lz4-size.ts +74 -0
- package/src/utils/namespace-key.ts +48 -0
- package/src/utils/query-key.ts +13 -0
- package/src/utils/snapshot-transfer.ts +83 -0
- package/src/utils/work-limits.ts +73 -0
- package/src/utils/write-revision.ts +4 -0
- package/src/wasm/bloom-filter-wasm.ts +16 -1
- package/src/worker-pool.ts +28 -8
- package/src/wtiny-lfu.ts +62 -14
- package/dist/cache-service-GYPZFB7O.js +0 -12
- package/dist/chunk-VNRDL5RA.js +0 -666
package/dist/next/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CacheService } from '../cache-service-
|
|
2
|
-
import { C as CacheOptions, i as ILogger } from '../types-
|
|
1
|
+
import { C as CacheService } from '../cache-service-BV5T8-20.cjs';
|
|
2
|
+
import { C as CacheOptions, i as ILogger } from '../types-F8vRWMrE.cjs';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -89,6 +89,10 @@ interface NextCacheHandlerOptions extends CacheOptions {
|
|
|
89
89
|
isBuildPhase?: boolean;
|
|
90
90
|
/** Maximum buffered RSC stream size. Default: 16 MiB. */
|
|
91
91
|
maxStreamBytes?: number;
|
|
92
|
+
/** Aggregate buffered input stream bytes per shared cache instance. Default: 64 MiB. Excludes encoded copies and caller-owned streams. */
|
|
93
|
+
maxPendingStreamBytes?: number;
|
|
94
|
+
/** Concurrent stream materializations per shared cache instance. Default: 16. Overflow skips caching and cancels that input stream. */
|
|
95
|
+
maxConcurrentStreams?: number;
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Legacy Next.js IncrementalCache value shape.
|
|
@@ -156,6 +160,8 @@ declare class TriCacheHandler {
|
|
|
156
160
|
protected readonly cache: CacheService;
|
|
157
161
|
protected readonly logger: ILogger;
|
|
158
162
|
private readonly maxStreamBytes;
|
|
163
|
+
private readonly streamBudget;
|
|
164
|
+
private static readonly streamBudgets;
|
|
159
165
|
private readonly pendingSets;
|
|
160
166
|
private readonly observedTags;
|
|
161
167
|
constructor(options?: NextCacheHandlerOptions);
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CacheService } from '../cache-service-
|
|
2
|
-
import { C as CacheOptions, i as ILogger } from '../types-
|
|
1
|
+
import { C as CacheService } from '../cache-service-tpyrXvlH.js';
|
|
2
|
+
import { C as CacheOptions, i as ILogger } from '../types-F8vRWMrE.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -89,6 +89,10 @@ interface NextCacheHandlerOptions extends CacheOptions {
|
|
|
89
89
|
isBuildPhase?: boolean;
|
|
90
90
|
/** Maximum buffered RSC stream size. Default: 16 MiB. */
|
|
91
91
|
maxStreamBytes?: number;
|
|
92
|
+
/** Aggregate buffered input stream bytes per shared cache instance. Default: 64 MiB. Excludes encoded copies and caller-owned streams. */
|
|
93
|
+
maxPendingStreamBytes?: number;
|
|
94
|
+
/** Concurrent stream materializations per shared cache instance. Default: 16. Overflow skips caching and cancels that input stream. */
|
|
95
|
+
maxConcurrentStreams?: number;
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Legacy Next.js IncrementalCache value shape.
|
|
@@ -156,6 +160,8 @@ declare class TriCacheHandler {
|
|
|
156
160
|
protected readonly cache: CacheService;
|
|
157
161
|
protected readonly logger: ILogger;
|
|
158
162
|
private readonly maxStreamBytes;
|
|
163
|
+
private readonly streamBudget;
|
|
164
|
+
private static readonly streamBudgets;
|
|
159
165
|
private readonly pendingSets;
|
|
160
166
|
private readonly observedTags;
|
|
161
167
|
constructor(options?: NextCacheHandlerOptions);
|
package/dist/next/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CacheService
|
|
3
|
-
|
|
2
|
+
CacheService,
|
|
3
|
+
WorkLimit,
|
|
4
|
+
positiveLimit
|
|
5
|
+
} from "../chunk-MB3DMVWN.js";
|
|
4
6
|
import {
|
|
5
7
|
consoleLogger
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-EJXG7WO6.js";
|
|
9
|
+
import "../chunk-KV7KISK2.js";
|
|
8
10
|
|
|
9
11
|
// src/next/cache-handler.ts
|
|
10
12
|
var PRESET_CACHE_LIFE_PROFILES = {
|
|
@@ -38,7 +40,7 @@ function resolveCacheLife(profileOrName) {
|
|
|
38
40
|
}
|
|
39
41
|
return null;
|
|
40
42
|
}
|
|
41
|
-
async function drainStream(stream, maxBytes) {
|
|
43
|
+
async function drainStream(stream, maxBytes, reserveBytes) {
|
|
42
44
|
const reader = stream.getReader();
|
|
43
45
|
const chunks = [];
|
|
44
46
|
let size = 0;
|
|
@@ -49,6 +51,7 @@ async function drainStream(stream, maxBytes) {
|
|
|
49
51
|
if (value) {
|
|
50
52
|
size += value.byteLength;
|
|
51
53
|
if (size > maxBytes) throw new Error("RSC stream exceeds maxStreamBytes");
|
|
54
|
+
if (value.byteLength > 0) reserveBytes(value.byteLength);
|
|
52
55
|
chunks.push(Uint8Array.from(value));
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -70,16 +73,19 @@ function createReadableStream(buffer) {
|
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
|
-
var TriCacheHandler = class {
|
|
76
|
+
var TriCacheHandler = class _TriCacheHandler {
|
|
74
77
|
cache;
|
|
75
78
|
logger;
|
|
76
79
|
maxStreamBytes;
|
|
80
|
+
streamBudget;
|
|
81
|
+
static streamBudgets = /* @__PURE__ */ new WeakMap();
|
|
77
82
|
pendingSets = /* @__PURE__ */ new Map();
|
|
78
83
|
observedTags = /* @__PURE__ */ new Map();
|
|
79
84
|
constructor(options = {}) {
|
|
80
85
|
this.logger = options.logger ?? consoleLogger;
|
|
81
|
-
this.maxStreamBytes = options.maxStreamBytes
|
|
82
|
-
|
|
86
|
+
this.maxStreamBytes = positiveLimit(options.maxStreamBytes, 16 * 1024 * 1024, "maxStreamBytes");
|
|
87
|
+
const maxPendingStreamBytes = positiveLimit(options.maxPendingStreamBytes, 64 * 1024 * 1024, "maxPendingStreamBytes");
|
|
88
|
+
const maxConcurrentStreams = positiveLimit(options.maxConcurrentStreams, 16, "maxConcurrentStreams");
|
|
83
89
|
if (options.tagStrategy && options.tagStrategy !== "generational") throw new Error("Next.js cache handlers require tagStrategy: generational");
|
|
84
90
|
const isBuildPhase = options.isBuildPhase ?? (typeof process !== "undefined" && (process.env.NEXT_PHASE === "phase-production-build" || process.env.NEXT_PHASE === "phase-export"));
|
|
85
91
|
this.cache = CacheService.create({
|
|
@@ -89,6 +95,15 @@ var TriCacheHandler = class {
|
|
|
89
95
|
cloneStrategy: options.cloneStrategy ?? "none",
|
|
90
96
|
disableRedis: isBuildPhase ? true : options.disableRedis
|
|
91
97
|
});
|
|
98
|
+
const existing = _TriCacheHandler.streamBudgets.get(this.cache);
|
|
99
|
+
if (existing && (existing.bytes.maximum !== maxPendingStreamBytes || existing.streams.maximum !== maxConcurrentStreams)) {
|
|
100
|
+
throw new Error("Next handlers sharing one cache must use the same stream admission limits");
|
|
101
|
+
}
|
|
102
|
+
this.streamBudget = existing ?? {
|
|
103
|
+
bytes: new WorkLimit(maxPendingStreamBytes, "Next buffered stream bytes"),
|
|
104
|
+
streams: new WorkLimit(maxConcurrentStreams, "Next concurrent streams")
|
|
105
|
+
};
|
|
106
|
+
_TriCacheHandler.streamBudgets.set(this.cache, this.streamBudget);
|
|
92
107
|
}
|
|
93
108
|
async get(cacheKey, context) {
|
|
94
109
|
let pending = this.pendingSets.get(cacheKey);
|
|
@@ -159,6 +174,8 @@ var TriCacheHandler = class {
|
|
|
159
174
|
finish = resolve;
|
|
160
175
|
});
|
|
161
176
|
this.pendingSets.set(cacheKey, { token, completion });
|
|
177
|
+
const byteReservation = this.streamBudget.bytes.reservation();
|
|
178
|
+
let releaseStream;
|
|
162
179
|
try {
|
|
163
180
|
const canCommit = this.cache.captureMutationFence(cacheKey);
|
|
164
181
|
const entry = await pendingEntry;
|
|
@@ -172,8 +189,16 @@ var TriCacheHandler = class {
|
|
|
172
189
|
);
|
|
173
190
|
if (isStream) {
|
|
174
191
|
try {
|
|
175
|
-
|
|
192
|
+
releaseStream = this.streamBudget.streams.acquire();
|
|
193
|
+
dataToStore = (await drainStream(
|
|
194
|
+
dataToStore,
|
|
195
|
+
this.maxStreamBytes,
|
|
196
|
+
(bytes) => byteReservation.grow(bytes)
|
|
197
|
+
)).toString("base64");
|
|
176
198
|
} catch (streamErr) {
|
|
199
|
+
const stream = entry.value;
|
|
200
|
+
if (!stream.locked) void stream.cancel(streamErr).catch(() => {
|
|
201
|
+
});
|
|
177
202
|
this.logger.debug("Next.js cacheHandler: stream drain failed mid-flight, skipping cache", {
|
|
178
203
|
cacheKey,
|
|
179
204
|
error: streamErr.message
|
|
@@ -231,6 +256,8 @@ var TriCacheHandler = class {
|
|
|
231
256
|
if (!canCommit() || this.pendingSets.get(cacheKey)?.token !== token) return;
|
|
232
257
|
await this.cache.set(cacheKey, stored, remaining / 1e3, void 0, { tags: [] });
|
|
233
258
|
} finally {
|
|
259
|
+
byteReservation.release();
|
|
260
|
+
releaseStream?.();
|
|
234
261
|
finish();
|
|
235
262
|
if (this.pendingSets.get(cacheKey)?.token === token) this.pendingSets.delete(cacheKey);
|
|
236
263
|
}
|
package/dist/prisma/index.cjs
CHANGED
|
@@ -35,6 +35,22 @@ __export(prisma_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(prisma_exports);
|
|
37
37
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
38
|
+
|
|
39
|
+
// src/utils/query-key.ts
|
|
40
|
+
function deterministicStringify(val) {
|
|
41
|
+
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
42
|
+
if (typeof val === "bigint") return `bigint:${val}`;
|
|
43
|
+
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
44
|
+
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
45
|
+
return deterministicStringify(val.toJSON());
|
|
46
|
+
}
|
|
47
|
+
if (val === null || typeof val !== "object") return JSON.stringify(val) ?? "undefined";
|
|
48
|
+
if (Array.isArray(val)) return `[${val.map(deterministicStringify).join(",")}]`;
|
|
49
|
+
const obj = val;
|
|
50
|
+
return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${deterministicStringify(obj[key])}`).join(",")}}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/prisma/index.ts
|
|
38
54
|
var READ_OPERATIONS = /* @__PURE__ */ new Set([
|
|
39
55
|
"findUnique",
|
|
40
56
|
"findUniqueOrThrow",
|
|
@@ -56,23 +72,6 @@ var MUTATION_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
56
72
|
"delete",
|
|
57
73
|
"deleteMany"
|
|
58
74
|
]);
|
|
59
|
-
function deterministicStringify(val) {
|
|
60
|
-
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
61
|
-
if (typeof val === "bigint") return `bigint:${val}`;
|
|
62
|
-
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
63
|
-
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
64
|
-
return deterministicStringify(val.toJSON());
|
|
65
|
-
}
|
|
66
|
-
if (val === null || typeof val !== "object") {
|
|
67
|
-
return JSON.stringify(val) ?? "undefined";
|
|
68
|
-
}
|
|
69
|
-
if (Array.isArray(val)) {
|
|
70
|
-
return `[${val.map(deterministicStringify).join(",")}]`;
|
|
71
|
-
}
|
|
72
|
-
const obj = val;
|
|
73
|
-
const keys = Object.keys(obj).sort();
|
|
74
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${deterministicStringify(obj[k])}`).join(",")}}`;
|
|
75
|
-
}
|
|
76
75
|
function generatePrismaCacheKey(model, operation, args) {
|
|
77
76
|
const normalized = deterministicStringify({ model, operation, args });
|
|
78
77
|
const hash = import_crypto.default.createHash("sha256").update(normalized, "utf8").digest("hex").slice(0, 32);
|
|
@@ -86,23 +85,25 @@ function withTriCache(options) {
|
|
|
86
85
|
$allModels: {
|
|
87
86
|
async $allOperations({ model, operation, args, query }) {
|
|
88
87
|
const modelTag = model.toLowerCase();
|
|
88
|
+
const queryArgs = args ?? {};
|
|
89
|
+
const cacheConfig = queryArgs.cache;
|
|
90
|
+
let cleanArgs = args;
|
|
91
|
+
if (args && Object.prototype.hasOwnProperty.call(args, "cache")) {
|
|
92
|
+
const { cache: _cacheOpt, ...rest } = args;
|
|
93
|
+
cleanArgs = rest;
|
|
94
|
+
}
|
|
89
95
|
if (autoInvalidate && MUTATION_OPERATIONS.has(operation)) {
|
|
90
|
-
const
|
|
91
|
-
const result = await query(cleanMutationArgs);
|
|
96
|
+
const result = await query(cleanArgs);
|
|
92
97
|
await cache.invalidateTag(modelTag);
|
|
93
98
|
return result;
|
|
94
99
|
}
|
|
95
100
|
if (READ_OPERATIONS.has(operation)) {
|
|
96
|
-
const queryArgs = args ?? {};
|
|
97
|
-
const cacheConfig = queryArgs.cache;
|
|
98
101
|
if (cacheConfig === false) {
|
|
99
|
-
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
100
102
|
return query(cleanArgs);
|
|
101
103
|
}
|
|
102
104
|
if (cacheConfig !== void 0 || autoCache) {
|
|
103
105
|
const opts = typeof cacheConfig === "object" && cacheConfig !== null ? cacheConfig : {};
|
|
104
|
-
const
|
|
105
|
-
const key = opts.key ?? generatePrismaCacheKey(model, operation, cleanArgs);
|
|
106
|
+
const key = opts.key ?? generatePrismaCacheKey(model, operation, cleanArgs ?? {});
|
|
106
107
|
const tags = [.../* @__PURE__ */ new Set([modelTag, ...opts.tags ?? []])];
|
|
107
108
|
return cache.wrap(
|
|
108
109
|
key,
|
|
@@ -120,7 +121,7 @@ function withTriCache(options) {
|
|
|
120
121
|
);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
return query(
|
|
124
|
+
return query(cleanArgs);
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
}
|
package/dist/prisma/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CacheService } from '../cache-service-
|
|
2
|
-
import { W as WrapOptions } from '../types-
|
|
1
|
+
import { C as CacheService } from '../cache-service-BV5T8-20.cjs';
|
|
2
|
+
import { W as WrapOptions } from '../types-F8vRWMrE.cjs';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/prisma/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CacheService } from '../cache-service-
|
|
2
|
-
import { W as WrapOptions } from '../types-
|
|
1
|
+
import { C as CacheService } from '../cache-service-tpyrXvlH.js';
|
|
2
|
+
import { W as WrapOptions } from '../types-F8vRWMrE.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/prisma/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deterministicStringify
|
|
3
|
+
} from "../chunk-S5N65I45.js";
|
|
4
|
+
|
|
1
5
|
// src/prisma/index.ts
|
|
2
6
|
import crypto from "crypto";
|
|
3
7
|
var READ_OPERATIONS = /* @__PURE__ */ new Set([
|
|
@@ -21,23 +25,6 @@ var MUTATION_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
21
25
|
"delete",
|
|
22
26
|
"deleteMany"
|
|
23
27
|
]);
|
|
24
|
-
function deterministicStringify(val) {
|
|
25
|
-
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
26
|
-
if (typeof val === "bigint") return `bigint:${val}`;
|
|
27
|
-
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
28
|
-
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
29
|
-
return deterministicStringify(val.toJSON());
|
|
30
|
-
}
|
|
31
|
-
if (val === null || typeof val !== "object") {
|
|
32
|
-
return JSON.stringify(val) ?? "undefined";
|
|
33
|
-
}
|
|
34
|
-
if (Array.isArray(val)) {
|
|
35
|
-
return `[${val.map(deterministicStringify).join(",")}]`;
|
|
36
|
-
}
|
|
37
|
-
const obj = val;
|
|
38
|
-
const keys = Object.keys(obj).sort();
|
|
39
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${deterministicStringify(obj[k])}`).join(",")}}`;
|
|
40
|
-
}
|
|
41
28
|
function generatePrismaCacheKey(model, operation, args) {
|
|
42
29
|
const normalized = deterministicStringify({ model, operation, args });
|
|
43
30
|
const hash = crypto.createHash("sha256").update(normalized, "utf8").digest("hex").slice(0, 32);
|
|
@@ -51,23 +38,25 @@ function withTriCache(options) {
|
|
|
51
38
|
$allModels: {
|
|
52
39
|
async $allOperations({ model, operation, args, query }) {
|
|
53
40
|
const modelTag = model.toLowerCase();
|
|
41
|
+
const queryArgs = args ?? {};
|
|
42
|
+
const cacheConfig = queryArgs.cache;
|
|
43
|
+
let cleanArgs = args;
|
|
44
|
+
if (args && Object.prototype.hasOwnProperty.call(args, "cache")) {
|
|
45
|
+
const { cache: _cacheOpt, ...rest } = args;
|
|
46
|
+
cleanArgs = rest;
|
|
47
|
+
}
|
|
54
48
|
if (autoInvalidate && MUTATION_OPERATIONS.has(operation)) {
|
|
55
|
-
const
|
|
56
|
-
const result = await query(cleanMutationArgs);
|
|
49
|
+
const result = await query(cleanArgs);
|
|
57
50
|
await cache.invalidateTag(modelTag);
|
|
58
51
|
return result;
|
|
59
52
|
}
|
|
60
53
|
if (READ_OPERATIONS.has(operation)) {
|
|
61
|
-
const queryArgs = args ?? {};
|
|
62
|
-
const cacheConfig = queryArgs.cache;
|
|
63
54
|
if (cacheConfig === false) {
|
|
64
|
-
const { cache: _c, ...cleanArgs } = queryArgs;
|
|
65
55
|
return query(cleanArgs);
|
|
66
56
|
}
|
|
67
57
|
if (cacheConfig !== void 0 || autoCache) {
|
|
68
58
|
const opts = typeof cacheConfig === "object" && cacheConfig !== null ? cacheConfig : {};
|
|
69
|
-
const
|
|
70
|
-
const key = opts.key ?? generatePrismaCacheKey(model, operation, cleanArgs);
|
|
59
|
+
const key = opts.key ?? generatePrismaCacheKey(model, operation, cleanArgs ?? {});
|
|
71
60
|
const tags = [.../* @__PURE__ */ new Set([modelTag, ...opts.tags ?? []])];
|
|
72
61
|
return cache.wrap(
|
|
73
62
|
key,
|
|
@@ -85,7 +74,7 @@ function withTriCache(options) {
|
|
|
85
74
|
);
|
|
86
75
|
}
|
|
87
76
|
}
|
|
88
|
-
return query(
|
|
77
|
+
return query(cleanArgs);
|
|
89
78
|
}
|
|
90
79
|
}
|
|
91
80
|
}
|