tricache 0.8.0 → 0.9.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 (44) hide show
  1. package/README.md +4 -2
  2. package/dashboards/prometheus-scrape.yml +18 -0
  3. package/dist/{cache-service-CyLdpo77.d.ts → cache-service-DVvroyqA.d.ts} +16 -1
  4. package/dist/{cache-service-5MZXFIGK.js → cache-service-KI5ACF3F.js} +1 -1
  5. package/dist/chunk-BQRURGGD.js +60 -0
  6. package/dist/chunk-IITRFWHY.js +196 -0
  7. package/dist/{chunk-6PQ5MOWR.js → chunk-PL5J3ZNT.js} +370 -81
  8. package/dist/cli.cjs +392 -84
  9. package/dist/cli.js +22 -4
  10. package/dist/dashboard/index.d.ts +2 -2
  11. package/dist/drizzle/index.cjs +350 -81
  12. package/dist/drizzle/index.d.ts +2 -2
  13. package/dist/drizzle/index.js +1 -1
  14. package/dist/edge/index.cjs +99 -38
  15. package/dist/edge/index.d.ts +3 -3
  16. package/dist/edge/index.js +5 -5
  17. package/dist/hono/index.cjs +7760 -0
  18. package/dist/hono/index.d.ts +91 -0
  19. package/dist/hono/index.js +185 -0
  20. package/dist/{hono-DQRS1Xd7.d.ts → hono-VA9A1m0I.d.ts} +3 -2
  21. package/dist/http/index.cjs +449 -119
  22. package/dist/http/index.d.ts +6 -30
  23. package/dist/http/index.js +9 -59
  24. package/dist/index.cjs +370 -81
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +1 -1
  27. package/dist/nestjs/index.cjs +350 -81
  28. package/dist/nestjs/index.d.ts +2 -2
  29. package/dist/nestjs/index.js +1 -1
  30. package/dist/next/index.cjs +350 -81
  31. package/dist/next/index.d.ts +2 -2
  32. package/dist/next/index.js +1 -1
  33. package/dist/prisma/index.d.ts +2 -2
  34. package/dist/{types-B6krw64X.d.ts → types-B_QkVwJ7.d.ts} +23 -0
  35. package/dist/utils-CEsU_Z0s.d.ts +27 -0
  36. package/package.json +16 -6
  37. package/src/cache-service.ts +302 -35
  38. package/src/cli.ts +21 -4
  39. package/src/edge/hono.ts +123 -42
  40. package/src/hono/index.ts +316 -0
  41. package/src/http/index.ts +5 -0
  42. package/src/ipc-telemetry.ts +29 -1
  43. package/src/types.ts +25 -0
  44. package/dist/chunk-ZTSWCFYO.js +0 -135
@@ -1,34 +1,10 @@
1
- import { C as CacheService } from '../cache-service-CyLdpo77.js';
2
- import { W as WrapOptions } from '../types-B6krw64X.js';
3
- export { C as CachedEdgeHttpResponse, H as HonoEdgeCacheOptions, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoCache } from '../hono-DQRS1Xd7.js';
1
+ import { K as KeyDerivationOptions } from '../utils-CEsU_Z0s.js';
2
+ export { b as buildDeterministicKey, g as generateETag, s as shouldSkipCache } from '../utils-CEsU_Z0s.js';
3
+ import { C as CacheService } from '../cache-service-DVvroyqA.js';
4
+ import { W as WrapOptions } from '../types-B_QkVwJ7.js';
5
+ export { C as CachedEdgeHttpResponse, H as HonoEdgeCacheOptions, b as buildEdgeDeterministicKey, c as computeEdgeETag, h as honoCache } from '../hono-VA9A1m0I.js';
4
6
  import 'crypto';
5
7
 
6
- interface KeyDerivationOptions {
7
- /** Custom key derivation function. Overrides default URL and query string serialization. */
8
- keyGenerator?: (req: any) => string;
9
- /** Optional list of header names (case-insensitive) to include in the cache key. */
10
- headerWhitelist?: string[];
11
- }
12
- /**
13
- * Generates a deterministic HTTP cache key from request method, URL path, sorted query parameters,
14
- * and optional whitelisted headers.
15
- *
16
- * Example:
17
- * GET /api/products?sort=desc&page=2
18
- * GET /api/products?page=2&sort=desc
19
- * Both map to: http:GET:/api/products?page=2&sort=desc
20
- */
21
- declare function buildDeterministicKey(req: any, options?: KeyDerivationOptions): string;
22
- /**
23
- * Checks if request specifies Cache-Control bypass directives (no-cache, no-store)
24
- * or matches a custom skipCache predicate.
25
- */
26
- declare function shouldSkipCache(req: any, customSkip?: (req: any) => boolean): boolean;
27
- /**
28
- * Compute a weak ETag (W/"...") from string, Buffer, or JSON-serializable object.
29
- */
30
- declare function generateETag(data: unknown): string;
31
-
32
8
  interface ExpressCacheOptions extends Omit<WrapOptions, 'tags'>, KeyDerivationOptions {
33
9
  /** TriCache instance. If omitted, lazily resolves the default singleton via CacheService.create(). */
34
10
  cache?: CacheService;
@@ -116,4 +92,4 @@ declare const fastifyCachePlugin: (fastify: any, pluginOpts?: FastifyCacheOption
116
92
  */
117
93
  declare function fastifyCache(options?: FastifyCacheOptions): (first: any, second?: any) => Promise<any>;
118
94
 
119
- export { type CachedFastifyResponse, type CachedHttpResponse, type ExpressCacheOptions, type FastifyCacheOptions, type ExpressCacheOptions as HttpCacheOptions, type KeyDerivationOptions, buildDeterministicKey, createExpressMiddleware, createFastifyPlugin, expressCache, fastifyCache, fastifyCachePlugin, generateETag, shouldSkipCache };
95
+ export { type CachedFastifyResponse, type CachedHttpResponse, type ExpressCacheOptions, type FastifyCacheOptions, type ExpressCacheOptions as HttpCacheOptions, KeyDerivationOptions, createExpressMiddleware, createFastifyPlugin, expressCache, fastifyCache, fastifyCachePlugin };
@@ -1,63 +1,13 @@
1
+ import {
2
+ buildDeterministicKey,
3
+ generateETag,
4
+ shouldSkipCache
5
+ } from "../chunk-BQRURGGD.js";
1
6
  import {
2
7
  buildEdgeDeterministicKey,
3
8
  computeEdgeETag,
4
9
  honoEdgeCache
5
- } from "../chunk-ZTSWCFYO.js";
6
-
7
- // src/http/utils.ts
8
- import crypto from "crypto";
9
- function buildDeterministicKey(req, options) {
10
- if (options?.keyGenerator) {
11
- return options.keyGenerator(req);
12
- }
13
- const method = (req.method || "GET").toUpperCase();
14
- const rawUrl = req.originalUrl || req.url || "/";
15
- const qIdx = rawUrl.indexOf("?");
16
- const path = qIdx >= 0 ? rawUrl.slice(0, qIdx) : rawUrl;
17
- let queryString = "";
18
- if (qIdx >= 0) {
19
- const rawQuery = rawUrl.slice(qIdx + 1);
20
- try {
21
- const params = new URLSearchParams(rawQuery);
22
- params.sort();
23
- queryString = params.toString();
24
- } catch {
25
- queryString = rawQuery;
26
- }
27
- }
28
- let key = `http:${method}:${path}`;
29
- if (queryString) {
30
- key += `?${queryString}`;
31
- }
32
- if (options?.headerWhitelist && options.headerWhitelist.length > 0 && req.headers) {
33
- const sortedHeaders = [...options.headerWhitelist].sort();
34
- for (const h of sortedHeaders) {
35
- const normalizedHeader = h.toLowerCase();
36
- const val = req.headers[normalizedHeader];
37
- if (val !== void 0 && val !== null && val !== "") {
38
- const headerStr = Array.isArray(val) ? val.join(",") : String(val);
39
- key += `|h:${normalizedHeader}=${headerStr}`;
40
- }
41
- }
42
- }
43
- return key;
44
- }
45
- function shouldSkipCache(req, customSkip) {
46
- if (customSkip && customSkip(req)) return true;
47
- const cc = req.headers ? req.headers["cache-control"] || req.headers["Cache-Control"] : void 0;
48
- if (typeof cc === "string") {
49
- const lower = cc.toLowerCase();
50
- if (lower.includes("no-cache") || lower.includes("no-store")) {
51
- return true;
52
- }
53
- }
54
- return false;
55
- }
56
- function generateETag(data) {
57
- const str = typeof data === "string" ? data : Buffer.isBuffer(data) ? data.toString("utf8") : JSON.stringify(data);
58
- const hash = crypto.createHash("sha1").update(str).digest("hex").slice(0, 16);
59
- return `W/"${str.length.toString(16)}-${hash}"`;
60
- }
10
+ } from "../chunk-IITRFWHY.js";
61
11
 
62
12
  // src/http/express.ts
63
13
  function createExpressMiddleware(options = {}) {
@@ -80,7 +30,7 @@ function createExpressMiddleware(options = {}) {
80
30
  }
81
31
  let activeCache = cache;
82
32
  if (!activeCache) {
83
- const { CacheService } = await import("../cache-service-5MZXFIGK.js");
33
+ const { CacheService } = await import("../cache-service-KI5ACF3F.js");
84
34
  activeCache = CacheService.create();
85
35
  }
86
36
  const key = buildDeterministicKey(req, { keyGenerator, headerWhitelist });
@@ -185,7 +135,7 @@ function createFastifyPlugin(options = {}) {
185
135
  const ttl = mergedOpts.ttl ?? 300;
186
136
  let activeCache = mergedOpts.cache;
187
137
  if (!activeCache) {
188
- const { CacheService } = await import("../cache-service-5MZXFIGK.js");
138
+ const { CacheService } = await import("../cache-service-KI5ACF3F.js");
189
139
  activeCache = CacheService.create();
190
140
  }
191
141
  fastify.addHook("onRequest", async (req, reply) => {
@@ -269,7 +219,7 @@ function fastifyCache(options = {}) {
269
219
  if (shouldSkipCache(req, options.skipCache)) return;
270
220
  let activeCache = options.cache;
271
221
  if (!activeCache) {
272
- const { CacheService } = await import("../cache-service-5MZXFIGK.js");
222
+ const { CacheService } = await import("../cache-service-KI5ACF3F.js");
273
223
  activeCache = CacheService.create();
274
224
  }
275
225
  const key = buildDeterministicKey(req, {