tricache 0.7.1 → 0.8.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 +21 -21
- package/README.md +87 -1371
- package/dashboards/tricache-alerts.yaml +54 -0
- package/dashboards/tricache-grafana.json +548 -0
- package/dist/cache-service-5MZXFIGK.js +12 -0
- package/dist/cache-service-CyLdpo77.d.ts +871 -0
- package/dist/{chunk-EUGYR7KR.js → chunk-6PQ5MOWR.js} +2871 -490
- package/dist/chunk-7RV5ZVBB.js +1023 -0
- package/dist/{chunk-X5AXHPVD.js → chunk-LJ5QJB5O.js} +90 -5
- package/dist/chunk-QNU7B43J.js +687 -0
- package/dist/chunk-UGD4VEPD.js +138 -0
- package/dist/chunk-XZL45ABR.js +108 -0
- package/dist/chunk-ZTSWCFYO.js +135 -0
- package/dist/cli.cjs +2790 -471
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +103 -5
- package/dist/dashboard/index.cjs +1065 -0
- package/dist/dashboard/index.d.ts +183 -0
- package/dist/dashboard/index.js +22 -0
- package/dist/drizzle/index.cjs +2553 -470
- package/dist/drizzle/index.d.ts +3 -1
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +1498 -0
- package/dist/edge/index.d.ts +127 -0
- package/dist/edge/index.js +1109 -0
- package/dist/hono-DQRS1Xd7.d.ts +370 -0
- package/dist/http/index.cjs +2926 -562
- package/dist/http/index.d.ts +109 -23
- package/dist/http/index.js +220 -72
- package/dist/index.cjs +6936 -2518
- package/dist/index.d.ts +547 -30
- package/dist/index.js +104 -5
- package/dist/murmur3-CMGw9PbV.d.ts +98 -0
- package/dist/nestjs/index.cjs +2494 -463
- package/dist/nestjs/index.d.ts +3 -1
- package/dist/nestjs/index.js +6 -3
- package/dist/next/index.cjs +2517 -483
- package/dist/next/index.d.ts +4 -2
- package/dist/next/index.js +14 -10
- package/dist/prisma/index.d.ts +3 -1
- package/dist/serialize-worker.cjs +5 -4
- package/dist/serialize-worker.js +1 -1
- package/dist/{cache-service-D8tIXmzb.d.ts → types-B6krw64X.d.ts} +596 -659
- package/package.json +34 -6
- package/src/adapters/auto-pipeliner.ts +206 -0
- package/src/adapters/node-redis.ts +370 -0
- package/src/cache-service.ts +1339 -402
- package/src/cli.ts +120 -2
- package/src/codec.ts +72 -0
- package/src/cross-region.ts +245 -0
- package/src/dashboard/handler.ts +392 -0
- package/src/dashboard/html.ts +594 -0
- package/src/dashboard/index.ts +195 -0
- package/src/dashboard/types.ts +96 -0
- package/src/disk-tier.ts +449 -47
- package/src/drizzle/index.ts +86 -86
- package/src/edge/adapters/cloudflare-do.ts +130 -0
- package/src/edge/adapters/cloudflare-kv.ts +115 -0
- package/src/edge/adapters/upstash.ts +143 -0
- package/src/edge/cache.ts +797 -0
- package/src/edge/crypto.ts +182 -0
- package/src/edge/hono.ts +203 -0
- package/src/edge/index.ts +37 -0
- package/src/edge/types.ts +230 -0
- package/src/edge/utils/base64.ts +63 -0
- package/src/edge/utils/murmur3.ts +179 -0
- package/src/encryption.ts +127 -5
- package/src/http/express.ts +195 -0
- package/src/http/fastify.ts +260 -0
- package/src/http/index.ts +39 -258
- package/src/http/utils.ts +92 -0
- package/src/index.ts +149 -47
- package/src/ipc-telemetry.ts +481 -0
- package/src/latency-watchdog.ts +282 -0
- package/src/nestjs/decorators.ts +161 -161
- package/src/nestjs/index.ts +23 -23
- package/src/nestjs/tricache.module.ts +104 -104
- package/src/nestjs/tricache.store.ts +97 -97
- package/src/nestjs/types.ts +79 -79
- package/src/next/cache-handler.ts +12 -9
- package/src/next/index.ts +37 -37
- package/src/next/isr-handler.ts +105 -105
- package/src/next/types.ts +130 -130
- package/src/remote-snapshot.ts +153 -0
- package/src/serialize-worker.ts +120 -120
- package/src/sigv4-snapshot-adapter.ts +260 -0
- package/src/smart-memory-cache.ts +91 -8
- package/src/types.ts +290 -2
- package/src/utils/cgroup.ts +100 -0
- package/src/utils/tracing.ts +54 -0
- package/src/wasm/bloom-filter-wasm.ts +109 -102
- package/src/worker-pool.ts +299 -299
- package/src/wtiny-lfu.ts +624 -0
- package/dist/cache-service-5GATUYAK.js +0 -7
- package/dist/chunk-UBSR5UYA.js +0 -0
|
@@ -15,7 +15,16 @@ var CachePriority = /* @__PURE__ */ ((CachePriority2) => {
|
|
|
15
15
|
})(CachePriority || {});
|
|
16
16
|
|
|
17
17
|
// src/encryption.ts
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createCipheriv,
|
|
20
|
+
createDecipheriv,
|
|
21
|
+
createSecretKey,
|
|
22
|
+
randomFillSync,
|
|
23
|
+
constants,
|
|
24
|
+
publicEncrypt,
|
|
25
|
+
privateDecrypt,
|
|
26
|
+
randomBytes
|
|
27
|
+
} from "crypto";
|
|
19
28
|
var IV_BYTES = 12;
|
|
20
29
|
var TAG_BYTES = 16;
|
|
21
30
|
var PREFIX_256 = "enc:v1:";
|
|
@@ -132,17 +141,17 @@ var CacheEncryption = class {
|
|
|
132
141
|
throw new Error("XOR key must be at least 1 byte");
|
|
133
142
|
}
|
|
134
143
|
this._key = buf;
|
|
135
|
-
if (
|
|
144
|
+
if (resolvedMode !== "xor") {
|
|
136
145
|
this._keyObj = createSecretKey(buf);
|
|
137
146
|
const _wc = createCipheriv(
|
|
138
|
-
|
|
147
|
+
resolvedMode,
|
|
139
148
|
this._keyObj,
|
|
140
|
-
Buffer.alloc(
|
|
149
|
+
Buffer.alloc(resolvedMode === "aes-128-ctr" ? CTR_IV_BYTES : IV_BYTES)
|
|
141
150
|
);
|
|
142
151
|
_wc.update(Buffer.alloc(0));
|
|
143
152
|
_wc.final();
|
|
144
153
|
}
|
|
145
|
-
if (
|
|
154
|
+
if (resolvedMode === "xor") {
|
|
146
155
|
logger.warn(
|
|
147
156
|
"Cache obfuscation enabled (XOR). WARNING: XOR is NOT cryptographic \u2014 use only for dev or non-sensitive data."
|
|
148
157
|
);
|
|
@@ -410,6 +419,81 @@ var CacheEncryption = class {
|
|
|
410
419
|
return plain;
|
|
411
420
|
}
|
|
412
421
|
};
|
|
422
|
+
var MAGIC_ENVELOPE = Buffer.from([84, 82, 73, 67, 69, 78, 86, 49]);
|
|
423
|
+
var EnvelopeEncryption = class {
|
|
424
|
+
static isEnvelope(data) {
|
|
425
|
+
return data.length >= MAGIC_LEN && data.subarray(0, MAGIC_LEN).equals(MAGIC_ENVELOPE);
|
|
426
|
+
}
|
|
427
|
+
static async encrypt(data, options) {
|
|
428
|
+
const dek = randomBytes(32);
|
|
429
|
+
let encryptedKey;
|
|
430
|
+
if (options.kmsEncrypt) {
|
|
431
|
+
encryptedKey = await options.kmsEncrypt(dek);
|
|
432
|
+
} else if (options.publicKey) {
|
|
433
|
+
encryptedKey = publicEncrypt(
|
|
434
|
+
{
|
|
435
|
+
key: options.publicKey,
|
|
436
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
437
|
+
oaepHash: "sha256"
|
|
438
|
+
},
|
|
439
|
+
dek
|
|
440
|
+
);
|
|
441
|
+
} else {
|
|
442
|
+
throw new Error("EnvelopeEncryption: either publicKey or kmsEncrypt must be provided to encrypt");
|
|
443
|
+
}
|
|
444
|
+
const iv = randomBytes(IV_BYTES);
|
|
445
|
+
const cipher = createCipheriv("aes-256-gcm", dek, iv);
|
|
446
|
+
const ct = cipher.update(data);
|
|
447
|
+
cipher.final();
|
|
448
|
+
const tag = cipher.getAuthTag();
|
|
449
|
+
const keyLen = encryptedKey.length;
|
|
450
|
+
const out = Buffer.allocUnsafe(MAGIC_LEN + 4 + keyLen + IV_BYTES + TAG_BYTES + ct.length);
|
|
451
|
+
MAGIC_ENVELOPE.copy(out, 0);
|
|
452
|
+
out.writeUInt32BE(keyLen, MAGIC_LEN);
|
|
453
|
+
encryptedKey.copy(out, MAGIC_LEN + 4);
|
|
454
|
+
iv.copy(out, MAGIC_LEN + 4 + keyLen);
|
|
455
|
+
tag.copy(out, MAGIC_LEN + 4 + keyLen + IV_BYTES);
|
|
456
|
+
ct.copy(out, MAGIC_LEN + 4 + keyLen + IV_BYTES + TAG_BYTES);
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
static async decrypt(data, options) {
|
|
460
|
+
if (!this.isEnvelope(data)) {
|
|
461
|
+
throw new Error("EnvelopeEncryption: invalid header, expected TRICENV1");
|
|
462
|
+
}
|
|
463
|
+
if (data.length < MAGIC_LEN + 4 + IV_BYTES + TAG_BYTES) {
|
|
464
|
+
throw new Error("EnvelopeEncryption: truncated envelope buffer");
|
|
465
|
+
}
|
|
466
|
+
const keyLen = data.readUInt32BE(MAGIC_LEN);
|
|
467
|
+
const minExpected = MAGIC_LEN + 4 + keyLen + IV_BYTES + TAG_BYTES;
|
|
468
|
+
if (data.length < minExpected) {
|
|
469
|
+
throw new Error("EnvelopeEncryption: truncated envelope buffer (key length mismatch)");
|
|
470
|
+
}
|
|
471
|
+
const encryptedKey = data.subarray(MAGIC_LEN + 4, MAGIC_LEN + 4 + keyLen);
|
|
472
|
+
const iv = data.subarray(MAGIC_LEN + 4 + keyLen, MAGIC_LEN + 4 + keyLen + IV_BYTES);
|
|
473
|
+
const tag = data.subarray(MAGIC_LEN + 4 + keyLen + IV_BYTES, MAGIC_LEN + 4 + keyLen + IV_BYTES + TAG_BYTES);
|
|
474
|
+
const ct = data.subarray(MAGIC_LEN + 4 + keyLen + IV_BYTES + TAG_BYTES);
|
|
475
|
+
let dek;
|
|
476
|
+
if (options.kmsDecrypt) {
|
|
477
|
+
dek = await options.kmsDecrypt(encryptedKey);
|
|
478
|
+
} else if (options.privateKey) {
|
|
479
|
+
dek = privateDecrypt(
|
|
480
|
+
{
|
|
481
|
+
key: options.privateKey,
|
|
482
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
483
|
+
oaepHash: "sha256"
|
|
484
|
+
},
|
|
485
|
+
encryptedKey
|
|
486
|
+
);
|
|
487
|
+
} else {
|
|
488
|
+
throw new Error("EnvelopeEncryption: either privateKey or kmsDecrypt must be provided to decrypt");
|
|
489
|
+
}
|
|
490
|
+
const decipher = createDecipheriv("aes-256-gcm", dek, iv);
|
|
491
|
+
decipher.setAuthTag(tag);
|
|
492
|
+
const pt = decipher.update(ct);
|
|
493
|
+
decipher.final();
|
|
494
|
+
return pt;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
413
497
|
|
|
414
498
|
// src/compression.ts
|
|
415
499
|
import zlib from "zlib";
|
|
@@ -470,6 +554,7 @@ export {
|
|
|
470
554
|
consoleLogger,
|
|
471
555
|
CachePriority,
|
|
472
556
|
CacheEncryption,
|
|
557
|
+
EnvelopeEncryption,
|
|
473
558
|
PREFIX_COMPRESSED,
|
|
474
559
|
PREFIX_ENC_COMPRESSED,
|
|
475
560
|
compressBuffer,
|