tricache 0.8.0 → 1.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 +10 -4
- package/dashboards/prometheus-scrape.yml +18 -0
- package/dist/{cache-service-5MZXFIGK.js → cache-service-26GCO3UU.js} +3 -3
- package/dist/{cache-service-CyLdpo77.d.ts → cache-service-pJ-nFcVj.d.ts} +44 -12
- package/dist/{chunk-XZL45ABR.js → chunk-2AJKEQMZ.js} +54 -1
- package/dist/{chunk-6PQ5MOWR.js → chunk-7SZSQS55.js} +571 -115
- package/dist/chunk-BQRURGGD.js +60 -0
- package/dist/chunk-IITRFWHY.js +196 -0
- package/dist/{chunk-LJ5QJB5O.js → chunk-UBWLPKTI.js} +127 -11
- package/dist/cli.cjs +767 -133
- package/dist/cli.js +24 -6
- package/dist/dashboard/index.d.ts +2 -2
- package/dist/drizzle/index.cjs +734 -132
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +163 -46
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +42 -14
- package/dist/hono/index.cjs +8093 -0
- package/dist/hono/index.d.ts +91 -0
- package/dist/hono/index.js +185 -0
- package/dist/{hono-DQRS1Xd7.d.ts → hono-DuNvciyq.d.ts} +6 -5
- package/dist/http/index.cjs +833 -170
- package/dist/http/index.d.ts +6 -30
- package/dist/http/index.js +9 -59
- package/dist/index.cjs +755 -130
- package/dist/index.d.ts +35 -6
- package/dist/index.js +16 -6
- package/dist/nestjs/index.cjs +725 -130
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +4 -4
- package/dist/next/index.cjs +725 -130
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +3 -3
- package/dist/prisma/index.d.ts +2 -2
- package/dist/serialize-worker.cjs +127 -9
- package/dist/serialize-worker.js +8 -4
- package/dist/{types-B6krw64X.d.ts → types-5HXqBfAf.d.ts} +74 -7
- package/dist/utils-CEsU_Z0s.d.ts +27 -0
- package/package.json +22 -9
- package/src/cache-service.ts +540 -68
- package/src/cli.ts +21 -4
- package/src/compression.ts +193 -15
- package/src/cross-region.ts +1 -1
- package/src/edge/cache.ts +38 -11
- package/src/edge/hono.ts +123 -42
- package/src/env.d.ts +13 -0
- package/src/hono/index.ts +316 -0
- package/src/http/index.ts +5 -0
- package/src/index.ts +9 -1
- package/src/ipc-telemetry.ts +29 -1
- package/src/serialize-worker.ts +6 -2
- package/src/types.ts +68 -5
- package/src/utils/tag-matcher.ts +90 -0
- package/dist/chunk-ZTSWCFYO.js +0 -135
- /package/dist/{chunk-QNU7B43J.js → chunk-VXFTFZ5N.js} +0 -0
package/dist/chunk-ZTSWCFYO.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// src/edge/hono.ts
|
|
2
|
-
async function computeEdgeETag(text) {
|
|
3
|
-
try {
|
|
4
|
-
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
5
|
-
const encoder = new TextEncoder();
|
|
6
|
-
const data = encoder.encode(text);
|
|
7
|
-
const hashBuf = await crypto.subtle.digest("SHA-1", data);
|
|
8
|
-
const hashArr = Array.from(new Uint8Array(hashBuf));
|
|
9
|
-
const hashHex = hashArr.map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
10
|
-
return `W/"${text.length.toString(16)}-${hashHex}"`;
|
|
11
|
-
}
|
|
12
|
-
} catch {
|
|
13
|
-
}
|
|
14
|
-
let h = 0;
|
|
15
|
-
for (let i = 0; i < text.length; i++) {
|
|
16
|
-
h = Math.imul(31, h) + text.charCodeAt(i) | 0;
|
|
17
|
-
}
|
|
18
|
-
return `W/"${text.length.toString(16)}-${Math.abs(h).toString(16)}"`;
|
|
19
|
-
}
|
|
20
|
-
function buildEdgeDeterministicKey(c, options) {
|
|
21
|
-
if (options?.keyGenerator) {
|
|
22
|
-
return options.keyGenerator(c);
|
|
23
|
-
}
|
|
24
|
-
const req = c.req;
|
|
25
|
-
const method = (req.method || "GET").toUpperCase();
|
|
26
|
-
const rawUrl = req.url || "/";
|
|
27
|
-
const qIdx = rawUrl.indexOf("?");
|
|
28
|
-
const path = qIdx >= 0 ? rawUrl.slice(0, qIdx) : rawUrl;
|
|
29
|
-
let queryString = "";
|
|
30
|
-
if (qIdx >= 0) {
|
|
31
|
-
const rawQuery = rawUrl.slice(qIdx + 1);
|
|
32
|
-
try {
|
|
33
|
-
const params = new URLSearchParams(rawQuery);
|
|
34
|
-
params.sort();
|
|
35
|
-
queryString = params.toString();
|
|
36
|
-
} catch {
|
|
37
|
-
queryString = rawQuery;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
let key = `edge:http:${method}:${path}`;
|
|
41
|
-
if (queryString) {
|
|
42
|
-
key += `?${queryString}`;
|
|
43
|
-
}
|
|
44
|
-
if (options?.headerWhitelist && options.headerWhitelist.length > 0 && req.header) {
|
|
45
|
-
const sortedHeaders = [...options.headerWhitelist].sort();
|
|
46
|
-
for (const h of sortedHeaders) {
|
|
47
|
-
const val = req.header(h);
|
|
48
|
-
if (val !== void 0 && val !== null && val !== "") {
|
|
49
|
-
key += `|h:${h.toLowerCase()}=${val}`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return key;
|
|
54
|
-
}
|
|
55
|
-
function honoEdgeCache(options = {}) {
|
|
56
|
-
const {
|
|
57
|
-
cache,
|
|
58
|
-
etag = true,
|
|
59
|
-
ttl = 300,
|
|
60
|
-
swr,
|
|
61
|
-
tags,
|
|
62
|
-
skipCache,
|
|
63
|
-
keyGenerator,
|
|
64
|
-
headerWhitelist
|
|
65
|
-
} = options;
|
|
66
|
-
return async (c, next) => {
|
|
67
|
-
const method = c.req.method;
|
|
68
|
-
if (method !== "GET" && method !== "HEAD") {
|
|
69
|
-
return await next();
|
|
70
|
-
}
|
|
71
|
-
if (skipCache && skipCache(c)) {
|
|
72
|
-
return await next();
|
|
73
|
-
}
|
|
74
|
-
const cc = c.req.header?.("cache-control") || c.req.header?.("Cache-Control");
|
|
75
|
-
if (typeof cc === "string") {
|
|
76
|
-
const lower = cc.toLowerCase();
|
|
77
|
-
if (lower.includes("no-cache") || lower.includes("no-store")) {
|
|
78
|
-
return await next();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (!cache) {
|
|
82
|
-
return await next();
|
|
83
|
-
}
|
|
84
|
-
const key = buildEdgeDeterministicKey(c, { keyGenerator, headerWhitelist });
|
|
85
|
-
const ifNoneMatch = c.req.header?.("if-none-match") || c.req.header?.("If-None-Match");
|
|
86
|
-
const resolvedTags = typeof tags === "function" ? tags(c) : tags;
|
|
87
|
-
const cached = await cache.get(
|
|
88
|
-
key,
|
|
89
|
-
async () => {
|
|
90
|
-
await next();
|
|
91
|
-
const res = c.res;
|
|
92
|
-
if (!res) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
const clone = res.clone();
|
|
96
|
-
const text = await clone.text();
|
|
97
|
-
const statusCode = res.status ?? 200;
|
|
98
|
-
const bodyEtag = etag ? await computeEdgeETag(text) : void 0;
|
|
99
|
-
const contentType = res.headers.get("content-type") || "text/plain; charset=utf-8";
|
|
100
|
-
return {
|
|
101
|
-
body: text,
|
|
102
|
-
contentType,
|
|
103
|
-
etag: bodyEtag,
|
|
104
|
-
status: statusCode
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
ttl,
|
|
108
|
-
{
|
|
109
|
-
swr,
|
|
110
|
-
tags: resolvedTags,
|
|
111
|
-
ctx: c.executionCtx
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
if (!cached) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (typeof cached.status === "number" && (cached.status < 200 || cached.status >= 300)) {
|
|
118
|
-
await cache.delete?.(key);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (cached.etag && ifNoneMatch === cached.etag) {
|
|
122
|
-
return c.body(null, 304, { ETag: cached.etag });
|
|
123
|
-
}
|
|
124
|
-
const headers = {};
|
|
125
|
-
if (cached.etag) headers["ETag"] = cached.etag;
|
|
126
|
-
if (cached.contentType) headers["Content-Type"] = cached.contentType;
|
|
127
|
-
return c.body(cached.body, cached.status ?? 200, headers);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export {
|
|
132
|
-
computeEdgeETag,
|
|
133
|
-
buildEdgeDeterministicKey,
|
|
134
|
-
honoEdgeCache
|
|
135
|
-
};
|
|
File without changes
|