@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.
- package/dist/__sw__.js +642 -642
- package/dist/{child_process-hmVqFcF7.cjs → child_process-B9qsOKHs.cjs} +7434 -7434
- package/dist/child_process-B9qsOKHs.cjs.map +1 -0
- package/dist/{child_process-D6oDN2MX.js → child_process-PY34i_6n.js} +8233 -8233
- package/dist/child_process-PY34i_6n.js.map +1 -0
- package/dist/{index-BO1i013L.cjs → index-CyhVjVJU.cjs} +38383 -37240
- package/dist/index-CyhVjVJU.cjs.map +1 -0
- package/dist/index-D8Hn2kWU.js +36455 -0
- package/dist/index-D8Hn2kWU.js.map +1 -0
- package/dist/index.cjs +67 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +88 -86
- package/dist/index.mjs +61 -59
- package/dist/memory-handler.d.ts +57 -0
- package/dist/memory-volume.d.ts +157 -147
- package/dist/packages/installer.d.ts +44 -41
- package/dist/persistence/idb-cache.d.ts +7 -0
- package/dist/polyfills/wasi.d.ts +45 -4
- package/dist/script-engine.d.ts +84 -81
- package/dist/sdk/nodepod-process.d.ts +29 -28
- package/dist/sdk/nodepod.d.ts +59 -39
- package/dist/sdk/types.d.ts +64 -53
- package/dist/threading/process-manager.d.ts +1 -1
- package/dist/threading/worker-protocol.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +194 -192
- package/src/memory-handler.ts +168 -0
- package/src/memory-volume.ts +78 -8
- package/src/packages/installer.ts +49 -1
- package/src/packages/version-resolver.ts +421 -411
- package/src/persistence/idb-cache.ts +107 -0
- package/src/polyfills/child_process.ts +2288 -2288
- package/src/polyfills/events.ts +6 -2
- package/src/polyfills/fs.ts +2888 -2888
- package/src/polyfills/http.ts +1450 -1449
- package/src/polyfills/process.ts +27 -1
- package/src/polyfills/stream.ts +1621 -1620
- package/src/polyfills/wasi.ts +1306 -44
- package/src/polyfills/zlib.ts +881 -881
- package/src/request-proxy.ts +716 -716
- package/src/script-engine.ts +444 -118
- package/src/sdk/nodepod-process.ts +94 -86
- package/src/sdk/nodepod.ts +571 -509
- package/src/sdk/types.ts +82 -70
- package/src/syntax-transforms.ts +2 -2
- package/src/threading/offload-worker.ts +383 -383
- package/src/threading/offload.ts +271 -271
- package/src/threading/process-manager.ts +967 -956
- package/src/threading/process-worker-entry.ts +858 -854
- package/src/threading/worker-protocol.ts +358 -358
- package/dist/child_process-D6oDN2MX.js.map +0 -1
- package/dist/child_process-hmVqFcF7.cjs.map +0 -1
- package/dist/index-Ale2oba_.js +0 -35412
- package/dist/index-Ale2oba_.js.map +0 -1
- 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
|
+
}
|