@scelar/nodepod 1.0.3 → 1.0.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.
Files changed (55) hide show
  1. package/dist/__sw__.js +642 -642
  2. package/dist/{child_process-hmVqFcF7.cjs → child_process-B9qsOKHs.cjs} +7434 -7434
  3. package/dist/child_process-B9qsOKHs.cjs.map +1 -0
  4. package/dist/{child_process-D6oDN2MX.js → child_process-PY34i_6n.js} +8233 -8233
  5. package/dist/child_process-PY34i_6n.js.map +1 -0
  6. package/dist/{index-BO1i013L.cjs → index-CyhVjVJU.cjs} +38383 -37240
  7. package/dist/index-CyhVjVJU.cjs.map +1 -0
  8. package/dist/index-D8Hn2kWU.js +36455 -0
  9. package/dist/index-D8Hn2kWU.js.map +1 -0
  10. package/dist/index.cjs +67 -65
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +88 -86
  13. package/dist/index.mjs +61 -59
  14. package/dist/memory-handler.d.ts +57 -0
  15. package/dist/memory-volume.d.ts +157 -147
  16. package/dist/packages/installer.d.ts +44 -41
  17. package/dist/persistence/idb-cache.d.ts +7 -0
  18. package/dist/polyfills/wasi.d.ts +45 -4
  19. package/dist/script-engine.d.ts +84 -81
  20. package/dist/sdk/nodepod-process.d.ts +29 -28
  21. package/dist/sdk/nodepod.d.ts +59 -39
  22. package/dist/sdk/types.d.ts +64 -53
  23. package/dist/threading/process-manager.d.ts +1 -1
  24. package/dist/threading/worker-protocol.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/src/index.ts +194 -192
  27. package/src/memory-handler.ts +168 -0
  28. package/src/memory-volume.ts +78 -8
  29. package/src/packages/installer.ts +49 -1
  30. package/src/packages/version-resolver.ts +421 -411
  31. package/src/persistence/idb-cache.ts +107 -0
  32. package/src/polyfills/child_process.ts +2288 -2288
  33. package/src/polyfills/events.ts +6 -2
  34. package/src/polyfills/fs.ts +2888 -2888
  35. package/src/polyfills/http.ts +1450 -1449
  36. package/src/polyfills/process.ts +27 -1
  37. package/src/polyfills/stream.ts +1621 -1620
  38. package/src/polyfills/wasi.ts +1306 -44
  39. package/src/polyfills/zlib.ts +881 -881
  40. package/src/request-proxy.ts +716 -716
  41. package/src/script-engine.ts +444 -118
  42. package/src/sdk/nodepod-process.ts +94 -86
  43. package/src/sdk/nodepod.ts +571 -509
  44. package/src/sdk/types.ts +82 -70
  45. package/src/syntax-transforms.ts +2 -2
  46. package/src/threading/offload-worker.ts +383 -383
  47. package/src/threading/offload.ts +271 -271
  48. package/src/threading/process-manager.ts +967 -956
  49. package/src/threading/process-worker-entry.ts +858 -854
  50. package/src/threading/worker-protocol.ts +358 -358
  51. package/dist/child_process-D6oDN2MX.js.map +0 -1
  52. package/dist/child_process-hmVqFcF7.cjs.map +0 -1
  53. package/dist/index-Ale2oba_.js +0 -35412
  54. package/dist/index-Ale2oba_.js.map +0 -1
  55. package/dist/index-BO1i013L.cjs.map +0 -1
@@ -0,0 +1,107 @@
1
+ // IndexedDB-backed cache for node_modules snapshots.
2
+ // Keyed by a hash of the package.json contents so stale caches auto-invalidate.
3
+
4
+ import type { VolumeSnapshot } from '../engine-types';
5
+
6
+ const DB_NAME = 'nodepod-snapshots';
7
+ const STORE_NAME = 'snapshots';
8
+ const DB_VERSION = 1;
9
+ const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
10
+
11
+ export interface IDBSnapshotCache {
12
+ get(packageJsonHash: string): Promise<VolumeSnapshot | null>;
13
+ set(packageJsonHash: string, snapshot: VolumeSnapshot): Promise<void>;
14
+ close(): void;
15
+ }
16
+
17
+ function openDB(): Promise<IDBDatabase | null> {
18
+ if (typeof indexedDB === 'undefined') return Promise.resolve(null);
19
+ return new Promise((resolve) => {
20
+ try {
21
+ const req = indexedDB.open(DB_NAME, DB_VERSION);
22
+ req.onupgradeneeded = () => {
23
+ const db = req.result;
24
+ if (!db.objectStoreNames.contains(STORE_NAME)) {
25
+ db.createObjectStore(STORE_NAME);
26
+ }
27
+ };
28
+ req.onsuccess = () => resolve(req.result);
29
+ req.onerror = () => resolve(null);
30
+ } catch {
31
+ resolve(null);
32
+ }
33
+ });
34
+ }
35
+
36
+ function idbGet(db: IDBDatabase, key: string): Promise<any> {
37
+ return new Promise((resolve, reject) => {
38
+ const tx = db.transaction(STORE_NAME, 'readonly');
39
+ const store = tx.objectStore(STORE_NAME);
40
+ const req = store.get(key);
41
+ req.onsuccess = () => resolve(req.result ?? null);
42
+ req.onerror = () => reject(req.error);
43
+ });
44
+ }
45
+
46
+ function idbPut(db: IDBDatabase, key: string, value: any): Promise<void> {
47
+ return new Promise((resolve, reject) => {
48
+ const tx = db.transaction(STORE_NAME, 'readwrite');
49
+ const store = tx.objectStore(STORE_NAME);
50
+ store.put(value, key);
51
+ tx.oncomplete = () => resolve();
52
+ tx.onerror = () => reject(tx.error);
53
+ });
54
+ }
55
+
56
+ function idbCleanExpired(db: IDBDatabase): void {
57
+ try {
58
+ const tx = db.transaction(STORE_NAME, 'readwrite');
59
+ const store = tx.objectStore(STORE_NAME);
60
+ const req = store.openCursor();
61
+ const now = Date.now();
62
+ req.onsuccess = () => {
63
+ const cursor = req.result;
64
+ if (!cursor) return;
65
+ const entry = cursor.value;
66
+ if (entry?.createdAt && (now - entry.createdAt) > MAX_AGE_MS) {
67
+ cursor.delete();
68
+ }
69
+ cursor.continue();
70
+ };
71
+ } catch { /* best-effort cleanup */ }
72
+ }
73
+
74
+ export async function openSnapshotCache(): Promise<IDBSnapshotCache | null> {
75
+ const db = await openDB();
76
+ if (!db) return null;
77
+
78
+ // Background cleanup of expired entries
79
+ idbCleanExpired(db);
80
+
81
+ return {
82
+ async get(packageJsonHash: string): Promise<VolumeSnapshot | null> {
83
+ try {
84
+ const entry = await idbGet(db, packageJsonHash);
85
+ if (!entry?.snapshot) return null;
86
+ // Check expiry
87
+ if (entry.createdAt && (Date.now() - entry.createdAt) > MAX_AGE_MS) return null;
88
+ return entry.snapshot as VolumeSnapshot;
89
+ } catch {
90
+ return null;
91
+ }
92
+ },
93
+
94
+ async set(packageJsonHash: string, snapshot: VolumeSnapshot): Promise<void> {
95
+ try {
96
+ await idbPut(db, packageJsonHash, {
97
+ snapshot,
98
+ createdAt: Date.now(),
99
+ });
100
+ } catch { /* silently fail — cache is optional */ }
101
+ },
102
+
103
+ close(): void {
104
+ try { db.close(); } catch { /* ignore */ }
105
+ },
106
+ };
107
+ }