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.
- package/README.md +89 -93
- 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-BV5T8-20.d.cts +1064 -0
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
- package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
- package/dist/chunk-RBJRTGFK.js +94 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +3694 -1070
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +210 -14
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +3578 -1068
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +368 -162
- package/dist/edge/index.d.cts +134 -0
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +314 -155
- package/dist/hono/index.cjs +3614 -1087
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/hono-CMv2VdQ6.d.cts +404 -0
- package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
- package/dist/http/index.cjs +3712 -1124
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +92 -43
- package/dist/index.cjs +4067 -1252
- package/dist/index.d.cts +1071 -0
- package/dist/index.d.ts +123 -27
- package/dist/index.js +878 -21
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/murmur3-DF8BFRnu.d.ts +99 -0
- package/dist/nestjs/index.cjs +3635 -1112
- package/dist/nestjs/index.d.cts +299 -0
- package/dist/nestjs/index.d.ts +120 -33
- package/dist/nestjs/index.js +132 -43
- package/dist/next/index.cjs +3704 -1175
- package/dist/next/index.d.cts +238 -0
- package/dist/next/index.d.ts +39 -11
- package/dist/next/index.js +202 -102
- package/dist/prisma/index.cjs +29 -18
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +17 -18
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
- package/dist/types-F8vRWMrE.d.ts +1636 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +116 -37
- package/src/adapters/auto-pipeliner.ts +150 -26
- package/src/adapters/node-redis.ts +106 -27
- package/src/cache-service.ts +2215 -793
- package/src/cli.ts +25 -14
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +22 -4
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +448 -102
- 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 +200 -110
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +17 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +62 -17
- package/src/http/fastify.ts +35 -21
- package/src/http/utils.ts +60 -20
- package/src/index.ts +6 -0
- package/src/ipc-telemetry.ts +35 -9
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +15 -12
- package/src/nestjs/tricache.store.ts +69 -26
- package/src/nestjs/types.ts +30 -16
- package/src/next/cache-handler.ts +151 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +25 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +17 -24
- 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 +121 -44
- package/src/types.ts +117 -37
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -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/redis-slot.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 +25 -5
- package/src/worker-pool.ts +44 -15
- package/src/wtiny-lfu.ts +82 -20
- package/dist/cache-service-MG7PN6MX.js +0 -12
- package/dist/chunk-3I5L7K6I.js +0 -704
- package/dist/chunk-BQRURGGD.js +0 -60
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/http/utils.ts
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
function readHttpHeader(headers, name) {
|
|
4
|
+
if (!headers) return void 0;
|
|
5
|
+
if (typeof headers.get === "function") return headers.get(name);
|
|
6
|
+
const lower = name.toLowerCase();
|
|
7
|
+
return headers[lower] ?? headers[name] ?? Object.entries(headers).find(([key]) => key.toLowerCase() === lower)?.[1];
|
|
8
|
+
}
|
|
9
|
+
function hasCacheBypassDirective(value) {
|
|
10
|
+
if (value == null) return false;
|
|
11
|
+
return String(value).split(",").some((part) => /^(?:private|no-cache|no-store)(?:\s*=|\s*$)/i.test(part.trim()));
|
|
12
|
+
}
|
|
13
|
+
function isShareableHttpResponse(status, header, options = {}) {
|
|
14
|
+
if (status === 206 || hasCacheBypassDirective(header("cache-control")) || header("set-cookie")) return false;
|
|
15
|
+
if (String(header("content-type") ?? "").toLowerCase().includes("text/event-stream")) return false;
|
|
16
|
+
const vary = String(header("vary") ?? "").split(",").map((value) => value.trim().toLowerCase()).filter(Boolean);
|
|
17
|
+
const keyedHeaders = new Set(options.headerWhitelist?.map((name) => name.toLowerCase()));
|
|
18
|
+
return !vary.includes("*") && (Boolean(options.keyGenerator) || vary.every((name) => keyedHeaders.has(name)));
|
|
19
|
+
}
|
|
20
|
+
function isCacheableHttpResponse(status, header, options) {
|
|
21
|
+
return status >= 200 && status < 300 && isShareableHttpResponse(status, header, options);
|
|
22
|
+
}
|
|
23
|
+
function matchesETag(header, etag) {
|
|
24
|
+
if (header == null) return false;
|
|
25
|
+
const normalized = etag.replace(/^W\//, "");
|
|
26
|
+
return String(header).split(",").some((value) => value.trim() === "*" || value.trim().replace(/^W\//, "") === normalized);
|
|
27
|
+
}
|
|
28
|
+
function buildDeterministicKey(req, options) {
|
|
29
|
+
if (options?.keyGenerator) {
|
|
30
|
+
return options.keyGenerator(req);
|
|
31
|
+
}
|
|
32
|
+
const method = (req.method || "GET").toUpperCase();
|
|
33
|
+
const rawUrl = req.originalUrl || req.url || "/";
|
|
34
|
+
const qIdx = rawUrl.indexOf("?");
|
|
35
|
+
const path = qIdx >= 0 ? rawUrl.slice(0, qIdx) : rawUrl;
|
|
36
|
+
let queryString = "";
|
|
37
|
+
if (qIdx >= 0) {
|
|
38
|
+
const rawQuery = rawUrl.slice(qIdx + 1);
|
|
39
|
+
try {
|
|
40
|
+
const params = new URLSearchParams(rawQuery);
|
|
41
|
+
params.sort();
|
|
42
|
+
queryString = params.toString();
|
|
43
|
+
} catch {
|
|
44
|
+
queryString = rawQuery;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const authority = readHttpHeader(req.headers, ":authority") ?? readHttpHeader(req.headers, "host");
|
|
48
|
+
if (authority != null && (typeof authority !== "string" || /[\s/\\?#@]/.test(authority))) {
|
|
49
|
+
throw new TypeError("HTTP cache authority must be a single valid host header");
|
|
50
|
+
}
|
|
51
|
+
let key = `http:${method}:${path}`;
|
|
52
|
+
if (authority) key += `|host:${encodeURIComponent(authority.toLowerCase())}`;
|
|
53
|
+
if (queryString) {
|
|
54
|
+
key += `?${queryString}`;
|
|
55
|
+
}
|
|
56
|
+
if (options?.headerWhitelist && options.headerWhitelist.length > 0 && req.headers) {
|
|
57
|
+
const sortedHeaders = [...new Set(options.headerWhitelist.map((h) => h.toLowerCase()))].sort();
|
|
58
|
+
for (const h of sortedHeaders) {
|
|
59
|
+
const normalizedHeader = h.toLowerCase();
|
|
60
|
+
const val = readHttpHeader(req.headers, normalizedHeader);
|
|
61
|
+
if (val !== void 0 && val !== null && val !== "") {
|
|
62
|
+
const headerStr = Array.isArray(val) ? val.join(",") : String(val);
|
|
63
|
+
const identity = /authorization|cookie|token|api-key/.test(normalizedHeader) ? crypto.createHash("sha256").update(headerStr).digest("hex") : encodeURIComponent(headerStr);
|
|
64
|
+
key += `|h:${normalizedHeader}=${identity}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return key;
|
|
69
|
+
}
|
|
70
|
+
function shouldSkipCache(req, customSkip, options = {}) {
|
|
71
|
+
if (customSkip && customSkip(req)) return true;
|
|
72
|
+
if (hasCacheBypassDirective(readHttpHeader(req.headers, "cache-control")) || readHttpHeader(req.headers, "range")) return true;
|
|
73
|
+
const sensitiveHeaders = ["authorization", "cookie", "x-api-key", "x-auth-token"].filter((name) => readHttpHeader(req.headers, name));
|
|
74
|
+
if (sensitiveHeaders.length > 0) {
|
|
75
|
+
if (!options.cacheAuthenticated) return true;
|
|
76
|
+
const keyedHeaders = new Set(options.headerWhitelist?.map((name) => name.toLowerCase()));
|
|
77
|
+
if (!options.keyGenerator && !sensitiveHeaders.every((name) => keyedHeaders.has(name))) return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
function generateETag(data) {
|
|
82
|
+
const bytes = Buffer.isBuffer(data) ? data : Buffer.from(typeof data === "string" ? data : JSON.stringify(data) ?? "", "utf8");
|
|
83
|
+
const hash = crypto.createHash("sha1").update(bytes).digest("hex").slice(0, 16);
|
|
84
|
+
return `W/"${bytes.length.toString(16)}-${hash}"`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
isShareableHttpResponse,
|
|
89
|
+
isCacheableHttpResponse,
|
|
90
|
+
matchesETag,
|
|
91
|
+
buildDeterministicKey,
|
|
92
|
+
shouldSkipCache,
|
|
93
|
+
generateETag
|
|
94
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/utils/query-key.ts
|
|
2
|
+
function deterministicStringify(val) {
|
|
3
|
+
if (val instanceof Date) return `date:${JSON.stringify(val.toISOString())}`;
|
|
4
|
+
if (typeof val === "bigint") return `bigint:${val}`;
|
|
5
|
+
if (val instanceof Uint8Array) return `binary:${Buffer.from(val.buffer, val.byteOffset, val.byteLength).toString("base64")}`;
|
|
6
|
+
if (val && typeof val === "object" && typeof val.toJSON === "function") {
|
|
7
|
+
return deterministicStringify(val.toJSON());
|
|
8
|
+
}
|
|
9
|
+
if (val === null || typeof val !== "object") return JSON.stringify(val) ?? "undefined";
|
|
10
|
+
if (Array.isArray(val)) return `[${val.map(deterministicStringify).join(",")}]`;
|
|
11
|
+
const obj = val;
|
|
12
|
+
return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${deterministicStringify(obj[key])}`).join(",")}}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
deterministicStringify
|
|
17
|
+
};
|