tricache 0.6.7 → 0.7.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/LICENSE +1 -1
- package/README.md +480 -22
- package/bin/tricache.js +8 -0
- package/dist/cache-service-AJASH5FX.js +7 -0
- package/dist/cache-service-BblHuF3i.d.ts +1476 -0
- package/dist/chunk-3XQUQBOZ.js +4583 -0
- package/dist/{chunk-FKY5R3CE.js → chunk-PFB5FMEY.js} +126 -4
- package/dist/chunk-UBSR5UYA.js +0 -0
- package/dist/cli.cjs +5181 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +130 -0
- package/dist/drizzle/index.cjs +5161 -0
- package/dist/drizzle/index.d.ts +44 -0
- package/dist/drizzle/index.js +46 -0
- package/dist/http/index.cjs +5289 -0
- package/dist/http/index.d.ts +33 -0
- package/dist/http/index.js +172 -0
- package/dist/index.cjs +1173 -194
- package/dist/index.d.ts +15 -1230
- package/dist/index.js +11 -3705
- package/dist/nestjs/index.cjs +5305 -0
- package/dist/nestjs/index.d.ts +210 -0
- package/dist/nestjs/index.js +250 -0
- package/dist/next/index.cjs +5327 -0
- package/dist/next/index.d.ts +204 -0
- package/dist/next/index.js +274 -0
- package/dist/prisma/index.cjs +122 -0
- package/dist/prisma/index.d.ts +60 -0
- package/dist/prisma/index.js +86 -0
- package/dist/serialize-worker.cjs +177 -13
- package/dist/serialize-worker.js +63 -12
- package/package.json +69 -21
- package/src/cache-service.ts +987 -190
- package/src/cli.ts +143 -0
- package/src/compression.ts +63 -0
- package/src/disk-tier.ts +71 -7
- package/src/drizzle/index.ts +86 -0
- package/src/encryption.ts +56 -5
- package/src/http/index.ts +223 -0
- package/src/index.ts +7 -0
- package/src/nestjs/decorators.ts +161 -0
- package/src/nestjs/index.ts +23 -0
- package/src/nestjs/tricache.module.ts +104 -0
- package/src/nestjs/tricache.store.ts +97 -0
- package/src/nestjs/types.ts +79 -0
- package/src/next/cache-handler.ts +244 -0
- package/src/next/index.ts +37 -0
- package/src/next/isr-handler.ts +105 -0
- package/src/next/types.ts +130 -0
- package/src/prisma/index.ts +151 -0
- package/src/serialize-worker.ts +77 -13
- package/src/smart-memory-cache.ts +22 -8
- package/src/types.ts +172 -2
- package/src/wasm/bloom-filter-wasm.ts +3 -2
- package/src/worker-pool.ts +156 -42
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { W as WrapOptions, C as CacheService } from '../cache-service-BblHuF3i.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* tricache/drizzle — First-class Drizzle ORM query caching wrapper for TriCache.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { withCache } from 'tricache/drizzle';
|
|
8
|
+
*
|
|
9
|
+
* const activeUsers = await withCache(
|
|
10
|
+
* db.select().from(users).where(eq(users.active, true)),
|
|
11
|
+
* { cache, ttl: 300, tags: ['users'] }
|
|
12
|
+
* );
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface DrizzleCacheOptions extends WrapOptions {
|
|
16
|
+
/** TriCache instance to use. If omitted, uses process-level singleton `CacheService.create()`. */
|
|
17
|
+
cache?: CacheService;
|
|
18
|
+
/** Explicit cache key. If omitted, automatically derived from SHA-256 hash of `{ sql, params }`. */
|
|
19
|
+
key?: string;
|
|
20
|
+
}
|
|
21
|
+
interface DrizzleExecutableQuery<T> {
|
|
22
|
+
toSQL(): {
|
|
23
|
+
sql: string;
|
|
24
|
+
params: unknown[];
|
|
25
|
+
};
|
|
26
|
+
execute?(): Promise<T>;
|
|
27
|
+
then?: (onfulfilled?: (value: T) => unknown, onrejected?: (reason: unknown) => unknown) => Promise<unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generate a deterministic SHA-256 hash key for a Drizzle query based on its compiled SQL and parameters.
|
|
31
|
+
*/
|
|
32
|
+
declare function generateDrizzleCacheKey(sqlInfo: {
|
|
33
|
+
sql: string;
|
|
34
|
+
params: unknown[];
|
|
35
|
+
}): string;
|
|
36
|
+
/**
|
|
37
|
+
* Wraps a Drizzle ORM query with TriCache caching.
|
|
38
|
+
*
|
|
39
|
+
* @param query Drizzle query builder or executable query instance.
|
|
40
|
+
* @param options Cache options including TTL, tags, SWR, priority, and optional key.
|
|
41
|
+
*/
|
|
42
|
+
declare function withCache<T>(query: DrizzleExecutableQuery<T>, options?: DrizzleCacheOptions): Promise<T>;
|
|
43
|
+
|
|
44
|
+
export { type DrizzleCacheOptions, type DrizzleExecutableQuery, generateDrizzleCacheKey, withCache };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/drizzle/index.ts
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
function generateDrizzleCacheKey(sqlInfo) {
|
|
4
|
+
const normalized = JSON.stringify(sqlInfo);
|
|
5
|
+
const hash = crypto.createHash("sha256").update(normalized, "utf8").digest("hex").slice(0, 32);
|
|
6
|
+
return `drizzle:${hash}`;
|
|
7
|
+
}
|
|
8
|
+
async function withCache(query, options = {}) {
|
|
9
|
+
const { cache, key, ttl = 300, swr, priority, tags, dependsOn, refreshAhead, xfetchBeta, notFoundTtl } = options;
|
|
10
|
+
let activeCache = cache;
|
|
11
|
+
if (!activeCache) {
|
|
12
|
+
const { CacheService } = await import("../cache-service-AJASH5FX.js");
|
|
13
|
+
activeCache = CacheService.create();
|
|
14
|
+
}
|
|
15
|
+
let cacheKey = key;
|
|
16
|
+
if (!cacheKey) {
|
|
17
|
+
if (typeof query.toSQL === "function") {
|
|
18
|
+
const sqlInfo = query.toSQL();
|
|
19
|
+
cacheKey = generateDrizzleCacheKey(sqlInfo);
|
|
20
|
+
} else {
|
|
21
|
+
throw new Error("tricache/drizzle: query must provide a .toSQL() method or an explicit key option.");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const executeFn = async () => {
|
|
25
|
+
if (typeof query.execute === "function") {
|
|
26
|
+
return await query.execute();
|
|
27
|
+
} else if (typeof query.then === "function") {
|
|
28
|
+
return await query;
|
|
29
|
+
}
|
|
30
|
+
throw new Error("tricache/drizzle: query is neither executable via .execute() nor thenable.");
|
|
31
|
+
};
|
|
32
|
+
return activeCache.wrap(cacheKey, executeFn, {
|
|
33
|
+
ttl,
|
|
34
|
+
swr,
|
|
35
|
+
priority,
|
|
36
|
+
tags,
|
|
37
|
+
dependsOn,
|
|
38
|
+
refreshAhead,
|
|
39
|
+
xfetchBeta,
|
|
40
|
+
notFoundTtl
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
generateDrizzleCacheKey,
|
|
45
|
+
withCache
|
|
46
|
+
};
|