tricache 0.6.4 → 0.6.5

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.
@@ -1,10 +1,3 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
1
  // src/encryption.ts
9
2
  import { createCipheriv, createDecipheriv, createSecretKey, randomFillSync } from "crypto";
10
3
  var IV_BYTES = 12;
@@ -337,6 +330,5 @@ var CacheEncryption = class {
337
330
  };
338
331
 
339
332
  export {
340
- __require,
341
333
  CacheEncryption
342
334
  };
package/dist/index.cjs CHANGED
@@ -44,12 +44,13 @@ module.exports = __toCommonJS(index_exports);
44
44
  var import_ioredis = require("ioredis");
45
45
  var import_msgpackr3 = require("msgpackr");
46
46
  var import_crypto3 = __toESM(require("crypto"), 1);
47
- var import_os = __toESM(require("os"), 1);
47
+ var import_os2 = __toESM(require("os"), 1);
48
48
 
49
49
  // src/worker-pool.ts
50
50
  var import_worker_threads = require("worker_threads");
51
51
  var import_url = require("url");
52
52
  var import_path = require("path");
53
+ var import_os = __toESM(require("os"), 1);
53
54
  var import_fs = require("fs");
54
55
  var import_meta = {};
55
56
  var _workerFile;
@@ -155,12 +156,7 @@ var WorkerPool = class {
155
156
  }
156
157
  };
157
158
  function availableCpus() {
158
- try {
159
- const os2 = require("os");
160
- return os2.availableParallelism?.() ?? os2.cpus().length;
161
- } catch {
162
- return 2;
163
- }
159
+ return import_os.default.availableParallelism?.() ?? import_os.default.cpus().length;
164
160
  }
165
161
 
166
162
  // src/cache-service.ts
@@ -1395,13 +1391,11 @@ var SmartMemoryCache = class {
1395
1391
  var import_fs2 = __toESM(require("fs"), 1);
1396
1392
  var import_path2 = __toESM(require("path"), 1);
1397
1393
  var import_crypto2 = __toESM(require("crypto"), 1);
1398
- var import_module = require("module");
1399
1394
  var import_msgpackr2 = require("msgpackr");
1400
- var import_meta2 = {};
1401
1395
  var _SqliteDB = null;
1402
1396
  try {
1403
- const _req = (0, import_module.createRequire)(import_meta2.url);
1404
- _SqliteDB = _req("node:sqlite").DatabaseSync;
1397
+ const sqlite = process.getBuiltinModule("node:sqlite");
1398
+ _SqliteDB = sqlite?.DatabaseSync ?? null;
1405
1399
  } catch {
1406
1400
  }
1407
1401
  var AES_ALGO = "aes-256-gcm";
@@ -2333,7 +2327,7 @@ var CacheService = class _CacheService {
2333
2327
  // Namespace-isolated defaults: separate dir / snapshot per namespace so
2334
2328
  // two instances with different namespaces never share cache files.
2335
2329
  diskCacheDir: options.diskCacheDir ?? import_path3.default.join(
2336
- import_os.default.tmpdir(),
2330
+ import_os2.default.tmpdir(),
2337
2331
  ns ? `tricache-disk-${ns}` : "tricache-disk"
2338
2332
  ),
2339
2333
  diskMaxBytes: options.diskMaxBytes ?? 500 * 1024 * 1024,
@@ -2344,7 +2338,7 @@ var CacheService = class _CacheService {
2344
2338
  disableRedis: options.disableRedis ?? process.env.NODE_ENV !== "production",
2345
2339
  encryptionKey: encKeyRaw,
2346
2340
  snapshotPath: options.snapshotPath ?? import_path3.default.join(
2347
- import_os.default.tmpdir(),
2341
+ import_os2.default.tmpdir(),
2348
2342
  ns ? `tricache-snapshot-${ns}.msgpack` : "tricache-snapshot.msgpack"
2349
2343
  ),
2350
2344
  snapshotMaxAgeMs: options.snapshotMaxAgeMs ?? DEFAULT_SNAPSHOT_MAX_AGE,
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import {
2
- CacheEncryption,
3
- __require
4
- } from "./chunk-F24NEZGQ.js";
2
+ CacheEncryption
3
+ } from "./chunk-IB4HMBA2.js";
5
4
 
6
5
  // src/cache-service.ts
7
6
  import { Redis as RedisClient, Cluster as RedisCluster } from "ioredis";
8
7
  import { pack as pack3, unpack as unpack3 } from "msgpackr";
9
8
  import crypto2 from "crypto";
10
- import os from "os";
9
+ import os2 from "os";
11
10
 
12
11
  // src/worker-pool.ts
13
12
  import { Worker } from "worker_threads";
14
13
  import { fileURLToPath } from "url";
15
14
  import { dirname, join } from "path";
15
+ import os from "os";
16
16
  import { existsSync } from "fs";
17
17
  var _workerFile;
18
18
  var _workerExecArgv = [];
@@ -117,12 +117,7 @@ var WorkerPool = class {
117
117
  }
118
118
  };
119
119
  function availableCpus() {
120
- try {
121
- const os2 = __require("os");
122
- return os2.availableParallelism?.() ?? os2.cpus().length;
123
- } catch {
124
- return 2;
125
- }
120
+ return os.availableParallelism?.() ?? os.cpus().length;
126
121
  }
127
122
 
128
123
  // src/cache-service.ts
@@ -1026,12 +1021,11 @@ var SmartMemoryCache = class {
1026
1021
  import fs from "fs";
1027
1022
  import path from "path";
1028
1023
  import crypto from "crypto";
1029
- import { createRequire } from "module";
1030
1024
  import { pack as pack2, unpack as unpack2 } from "msgpackr";
1031
1025
  var _SqliteDB = null;
1032
1026
  try {
1033
- const _req = createRequire(import.meta.url);
1034
- _SqliteDB = _req("node:sqlite").DatabaseSync;
1027
+ const sqlite = process.getBuiltinModule("node:sqlite");
1028
+ _SqliteDB = sqlite?.DatabaseSync ?? null;
1035
1029
  } catch {
1036
1030
  }
1037
1031
  var AES_ALGO = "aes-256-gcm";
@@ -1963,7 +1957,7 @@ var CacheService = class _CacheService {
1963
1957
  // Namespace-isolated defaults: separate dir / snapshot per namespace so
1964
1958
  // two instances with different namespaces never share cache files.
1965
1959
  diskCacheDir: options.diskCacheDir ?? path2.join(
1966
- os.tmpdir(),
1960
+ os2.tmpdir(),
1967
1961
  ns ? `tricache-disk-${ns}` : "tricache-disk"
1968
1962
  ),
1969
1963
  diskMaxBytes: options.diskMaxBytes ?? 500 * 1024 * 1024,
@@ -1974,7 +1968,7 @@ var CacheService = class _CacheService {
1974
1968
  disableRedis: options.disableRedis ?? process.env.NODE_ENV !== "production",
1975
1969
  encryptionKey: encKeyRaw,
1976
1970
  snapshotPath: options.snapshotPath ?? path2.join(
1977
- os.tmpdir(),
1971
+ os2.tmpdir(),
1978
1972
  ns ? `tricache-snapshot-${ns}.msgpack` : "tricache-snapshot.msgpack"
1979
1973
  ),
1980
1974
  snapshotMaxAgeMs: options.snapshotMaxAgeMs ?? DEFAULT_SNAPSHOT_MAX_AGE,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CacheEncryption
3
- } from "./chunk-F24NEZGQ.js";
3
+ } from "./chunk-IB4HMBA2.js";
4
4
 
5
5
  // src/serialize-worker.ts
6
6
  import { parentPort, workerData } from "worker_threads";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tricache",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "Three-tier Node.js cache: L1 smart RAM (adaptive LFU/LRU + Count-Min Sketch) → L1.5 NVMe disk spill → L2 Redis/Valkey. Includes AES-256-GCM at-rest encryption, WASM Bloom filter, Stale-While-Revalidate, and thundering-herd prevention.",
5
5
  "keywords": [
6
6
  "cache",
@@ -38,6 +38,7 @@
38
38
  ],
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts src/serialize-worker.ts --format esm,cjs --dts --clean",
41
+ "postbuild": "node --input-type=module -e \"import{rmSync}from'fs';['dist/index.d.cts','dist/serialize-worker.d.cts'].forEach(f=>rmSync(f,{force:true}));\"",
41
42
  "dev": "tsup src/index.ts src/serialize-worker.ts --format esm,cjs --dts --watch",
42
43
  "typecheck": "tsc --noEmit",
43
44
  "test": "vitest run",
package/src/disk-tier.ts CHANGED
@@ -17,7 +17,6 @@
17
17
  import fs from 'fs';
18
18
  import path from 'path';
19
19
  import crypto from 'crypto';
20
- import { createRequire } from 'module';
21
20
  import { pack, unpack } from 'msgpackr';
22
21
  import { DiskCacheEntry, ILogger } from './types.js';
23
22
 
@@ -37,8 +36,11 @@ type _SqliteDB = {
37
36
  };
38
37
  let _SqliteDB: (new (p: string) => _SqliteDB) | null = null;
39
38
  try {
40
- const _req = createRequire(import.meta.url);
41
- _SqliteDB = (_req('node:sqlite') as { DatabaseSync: new (p: string) => _SqliteDB }).DatabaseSync;
39
+ // process.getBuiltinModule is available in Node >= 22.3.0 (within our >=22.13.0 engine
40
+ // requirement). It's synchronous and does not require the esbuild __require shim.
41
+ const sqlite = (process as unknown as { getBuiltinModule(m: string): unknown })
42
+ .getBuiltinModule('node:sqlite') as { DatabaseSync: new (p: string) => _SqliteDB } | undefined;
43
+ _SqliteDB = sqlite?.DatabaseSync ?? null;
42
44
  } catch { /* node:sqlite unavailable — file-only mode */ }
43
45
  // ── Encryption (self-contained to avoid circular import) ─────────────────────
44
46
 
@@ -26,6 +26,7 @@
26
26
  import { Worker } from 'worker_threads';
27
27
  import { fileURLToPath } from 'url';
28
28
  import { dirname, join } from 'path';
29
+ import os from 'os';
29
30
  import type { EncryptionMode } from './encryption.js';
30
31
 
31
32
  // Locate the serialize-worker entry point.
@@ -179,12 +180,6 @@ export class WorkerPool {
179
180
  }
180
181
 
181
182
  function availableCpus(): number {
182
- try {
183
- // Node.js 18.14+ provides `availableParallelism`; fall back to os.cpus().
184
- // eslint-disable-next-line @typescript-eslint/no-require-imports
185
- const os = require('os') as typeof import('os');
186
- return (os as unknown as { availableParallelism?: () => number }).availableParallelism?.() ?? os.cpus().length;
187
- } catch {
188
- return 2;
189
- }
183
+ // Node >= 22.13.0 (engines constraint) always has availableParallelism.
184
+ return os.availableParallelism?.() ?? os.cpus().length;
190
185
  }