@componentor/fs 3.0.11 → 3.0.12
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/README.md +5 -0
- package/dist/index.d.mts +509 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -570,6 +570,11 @@ Make sure `opfsSync` is enabled (it's `true` by default). Files are mirrored to
|
|
|
570
570
|
|
|
571
571
|
## Changelog
|
|
572
572
|
|
|
573
|
+
### v3.0.12 (2026)
|
|
574
|
+
|
|
575
|
+
**Fixes:**
|
|
576
|
+
- Fix `.d.ts` output extension mapping so declaration files resolve correctly
|
|
577
|
+
|
|
573
578
|
### v3.0.11 (2026)
|
|
574
579
|
|
|
575
580
|
**Fixes:**
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the VFS-based filesystem.
|
|
3
|
+
* Mirrors Node.js fs module interfaces.
|
|
4
|
+
*/
|
|
5
|
+
type Encoding = 'utf8' | 'utf-8' | 'ascii' | 'base64' | 'hex' | 'binary';
|
|
6
|
+
interface ReadOptions {
|
|
7
|
+
encoding?: Encoding | null;
|
|
8
|
+
flag?: string;
|
|
9
|
+
}
|
|
10
|
+
interface WriteOptions {
|
|
11
|
+
encoding?: Encoding;
|
|
12
|
+
mode?: number;
|
|
13
|
+
flag?: string;
|
|
14
|
+
flush?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface MkdirOptions {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
mode?: number;
|
|
19
|
+
}
|
|
20
|
+
interface RmdirOptions {
|
|
21
|
+
recursive?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface RmOptions {
|
|
24
|
+
recursive?: boolean;
|
|
25
|
+
force?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface ReaddirOptions {
|
|
28
|
+
encoding?: Encoding | null;
|
|
29
|
+
withFileTypes?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface Stats {
|
|
32
|
+
isFile(): boolean;
|
|
33
|
+
isDirectory(): boolean;
|
|
34
|
+
isBlockDevice(): boolean;
|
|
35
|
+
isCharacterDevice(): boolean;
|
|
36
|
+
isSymbolicLink(): boolean;
|
|
37
|
+
isFIFO(): boolean;
|
|
38
|
+
isSocket(): boolean;
|
|
39
|
+
dev: number;
|
|
40
|
+
ino: number;
|
|
41
|
+
mode: number;
|
|
42
|
+
nlink: number;
|
|
43
|
+
uid: number;
|
|
44
|
+
gid: number;
|
|
45
|
+
rdev: number;
|
|
46
|
+
size: number;
|
|
47
|
+
blksize: number;
|
|
48
|
+
blocks: number;
|
|
49
|
+
atimeMs: number;
|
|
50
|
+
mtimeMs: number;
|
|
51
|
+
ctimeMs: number;
|
|
52
|
+
birthtimeMs: number;
|
|
53
|
+
atime: Date;
|
|
54
|
+
mtime: Date;
|
|
55
|
+
ctime: Date;
|
|
56
|
+
birthtime: Date;
|
|
57
|
+
}
|
|
58
|
+
interface Dirent {
|
|
59
|
+
name: string;
|
|
60
|
+
isFile(): boolean;
|
|
61
|
+
isDirectory(): boolean;
|
|
62
|
+
isBlockDevice(): boolean;
|
|
63
|
+
isCharacterDevice(): boolean;
|
|
64
|
+
isSymbolicLink(): boolean;
|
|
65
|
+
isFIFO(): boolean;
|
|
66
|
+
isSocket(): boolean;
|
|
67
|
+
}
|
|
68
|
+
type PathLike = string;
|
|
69
|
+
interface ReadStreamOptions {
|
|
70
|
+
flags?: string;
|
|
71
|
+
encoding?: Encoding | null;
|
|
72
|
+
fd?: number | null;
|
|
73
|
+
mode?: number;
|
|
74
|
+
autoClose?: boolean;
|
|
75
|
+
emitClose?: boolean;
|
|
76
|
+
start?: number;
|
|
77
|
+
end?: number;
|
|
78
|
+
highWaterMark?: number;
|
|
79
|
+
}
|
|
80
|
+
interface WriteStreamOptions {
|
|
81
|
+
flags?: string;
|
|
82
|
+
encoding?: Encoding;
|
|
83
|
+
fd?: number | null;
|
|
84
|
+
mode?: number;
|
|
85
|
+
autoClose?: boolean;
|
|
86
|
+
emitClose?: boolean;
|
|
87
|
+
start?: number;
|
|
88
|
+
highWaterMark?: number;
|
|
89
|
+
flush?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface WatchOptions {
|
|
92
|
+
persistent?: boolean;
|
|
93
|
+
recursive?: boolean;
|
|
94
|
+
encoding?: Encoding;
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
}
|
|
97
|
+
interface WatchFileOptions {
|
|
98
|
+
persistent?: boolean;
|
|
99
|
+
interval?: number;
|
|
100
|
+
}
|
|
101
|
+
interface WatchEventType {
|
|
102
|
+
eventType: 'rename' | 'change';
|
|
103
|
+
filename: string | null;
|
|
104
|
+
}
|
|
105
|
+
interface FileHandle {
|
|
106
|
+
fd: number;
|
|
107
|
+
read(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<{
|
|
108
|
+
bytesRead: number;
|
|
109
|
+
buffer: Uint8Array;
|
|
110
|
+
}>;
|
|
111
|
+
write(buffer: Uint8Array, offset?: number, length?: number, position?: number | null): Promise<{
|
|
112
|
+
bytesWritten: number;
|
|
113
|
+
buffer: Uint8Array;
|
|
114
|
+
}>;
|
|
115
|
+
readFile(options?: ReadOptions | Encoding | null): Promise<Uint8Array | string>;
|
|
116
|
+
writeFile(data: Uint8Array | string, options?: WriteOptions | Encoding): Promise<void>;
|
|
117
|
+
truncate(len?: number): Promise<void>;
|
|
118
|
+
stat(): Promise<Stats>;
|
|
119
|
+
sync(): Promise<void>;
|
|
120
|
+
datasync(): Promise<void>;
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
interface Dir {
|
|
124
|
+
path: string;
|
|
125
|
+
read(): Promise<Dirent | null>;
|
|
126
|
+
close(): Promise<void>;
|
|
127
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
|
|
128
|
+
}
|
|
129
|
+
interface FSWatcher {
|
|
130
|
+
close(): void;
|
|
131
|
+
ref(): this;
|
|
132
|
+
unref(): this;
|
|
133
|
+
}
|
|
134
|
+
type WatchListener = (eventType: 'rename' | 'change', filename: string | null) => void;
|
|
135
|
+
type WatchFileListener = (curr: Stats, prev: Stats) => void;
|
|
136
|
+
/** Filesystem operating mode:
|
|
137
|
+
* - 'hybrid' (default): VFS binary + bidirectional OPFS sync. Best of both worlds.
|
|
138
|
+
* - 'vfs': VFS binary only, no OPFS mirroring. Fastest, but data lives only in .vfs.bin.
|
|
139
|
+
* - 'opfs': Pure OPFS files, no VFS binary. Slowest but most resilient.
|
|
140
|
+
* Automatically selected as fallback when VFS corruption is detected in hybrid mode.
|
|
141
|
+
*/
|
|
142
|
+
type FSMode = 'hybrid' | 'vfs' | 'opfs';
|
|
143
|
+
/** VFS configuration options */
|
|
144
|
+
interface VFSConfig {
|
|
145
|
+
root?: string;
|
|
146
|
+
/** Filesystem mode. Defaults to 'hybrid'. */
|
|
147
|
+
mode?: FSMode;
|
|
148
|
+
/** @deprecated Use `mode` instead. When set, overrides mode's OPFS sync behavior. */
|
|
149
|
+
opfsSync?: boolean;
|
|
150
|
+
opfsSyncRoot?: string;
|
|
151
|
+
uid?: number;
|
|
152
|
+
gid?: number;
|
|
153
|
+
umask?: number;
|
|
154
|
+
strictPermissions?: boolean;
|
|
155
|
+
sabSize?: number;
|
|
156
|
+
debug?: boolean;
|
|
157
|
+
/** Scope for the internal service worker registration. Defaults to
|
|
158
|
+
* `'./opfs-fs-sw/'` (relative to the SW script URL) so it won't collide
|
|
159
|
+
* with the host application's service worker. */
|
|
160
|
+
swScope?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type AsyncRequestFn = (op: number, path: string, flags?: number, data?: Uint8Array | string | null, path2?: string, fdArgs?: Record<string, unknown>) => Promise<{
|
|
164
|
+
status: number;
|
|
165
|
+
data: Uint8Array | null;
|
|
166
|
+
}>;
|
|
167
|
+
|
|
168
|
+
declare class VFSFileSystem {
|
|
169
|
+
private sab;
|
|
170
|
+
private ctrl;
|
|
171
|
+
private readySab;
|
|
172
|
+
private readySignal;
|
|
173
|
+
private asyncSab;
|
|
174
|
+
private hasSAB;
|
|
175
|
+
private syncWorker;
|
|
176
|
+
private asyncWorker;
|
|
177
|
+
private asyncCallId;
|
|
178
|
+
private asyncPending;
|
|
179
|
+
private readyPromise;
|
|
180
|
+
private resolveReady;
|
|
181
|
+
private rejectReady;
|
|
182
|
+
private initError;
|
|
183
|
+
private isReady;
|
|
184
|
+
private config;
|
|
185
|
+
private tabId;
|
|
186
|
+
private _mode;
|
|
187
|
+
private corruptionError;
|
|
188
|
+
/** Namespace string derived from root — used for lock names, BroadcastChannel, and SW scope
|
|
189
|
+
* so multiple VFS instances with different roots don't collide. */
|
|
190
|
+
private ns;
|
|
191
|
+
private swReg;
|
|
192
|
+
private isFollower;
|
|
193
|
+
private holdingLeaderLock;
|
|
194
|
+
private brokerInitialized;
|
|
195
|
+
private leaderChangeBc;
|
|
196
|
+
private _sync;
|
|
197
|
+
private _async;
|
|
198
|
+
readonly promises: VFSPromises;
|
|
199
|
+
constructor(config?: VFSConfig);
|
|
200
|
+
/** Spawn workers and establish communication */
|
|
201
|
+
private bootstrap;
|
|
202
|
+
/** Use Web Locks API for leader election. The tab that acquires the lock is
|
|
203
|
+
* the leader; all others become followers. When the leader dies, the browser
|
|
204
|
+
* releases the lock and the next waiting tab is promoted. */
|
|
205
|
+
private acquireLeaderLock;
|
|
206
|
+
/** Queue for leader takeover when the current leader's lock is released */
|
|
207
|
+
private waitForLeaderLock;
|
|
208
|
+
/** Send init-leader message to sync-relay worker */
|
|
209
|
+
private sendLeaderInit;
|
|
210
|
+
/** Send init-opfs message to sync-relay for OPFS-direct mode */
|
|
211
|
+
private sendOPFSInit;
|
|
212
|
+
/** Handle VFS corruption: log error, fall back to OPFS-direct mode.
|
|
213
|
+
* The readyPromise will resolve once OPFS mode is ready, but init()
|
|
214
|
+
* will reject with the corruption error to inform the caller. */
|
|
215
|
+
private handleCorruptVFS;
|
|
216
|
+
/** Start as leader — tell sync-relay to init VFS engine + OPFS handle */
|
|
217
|
+
private startAsLeader;
|
|
218
|
+
/** Start as follower — connect to leader via service worker port brokering */
|
|
219
|
+
private startAsFollower;
|
|
220
|
+
/** Send a new port to sync-relay for connecting to the current leader */
|
|
221
|
+
private connectToLeader;
|
|
222
|
+
/** Register the VFS service worker and return the active SW */
|
|
223
|
+
private getServiceWorker;
|
|
224
|
+
/** Register as leader with SW broker (receives follower ports via control channel) */
|
|
225
|
+
private initLeaderBroker;
|
|
226
|
+
/** Promote from follower to leader (after leader tab dies and lock is acquired) */
|
|
227
|
+
private promoteToLeader;
|
|
228
|
+
/** Spawn an inline worker from bundled code */
|
|
229
|
+
private spawnWorker;
|
|
230
|
+
/** Block until workers are ready */
|
|
231
|
+
private ensureReady;
|
|
232
|
+
/** Send a sync request via SAB and wait for response */
|
|
233
|
+
private syncRequest;
|
|
234
|
+
private asyncRequest;
|
|
235
|
+
readFileSync(filePath: string, options?: ReadOptions | Encoding | null): string | Uint8Array;
|
|
236
|
+
writeFileSync(filePath: string, data: string | Uint8Array, options?: WriteOptions | Encoding): void;
|
|
237
|
+
appendFileSync(filePath: string, data: string | Uint8Array, options?: WriteOptions | Encoding): void;
|
|
238
|
+
existsSync(filePath: string): boolean;
|
|
239
|
+
mkdirSync(filePath: string, options?: MkdirOptions | number): string | undefined;
|
|
240
|
+
rmdirSync(filePath: string, options?: RmdirOptions): void;
|
|
241
|
+
rmSync(filePath: string, options?: RmOptions): void;
|
|
242
|
+
unlinkSync(filePath: string): void;
|
|
243
|
+
readdirSync(filePath: string, options?: ReaddirOptions | Encoding | null): string[] | Dirent[];
|
|
244
|
+
statSync(filePath: string): Stats;
|
|
245
|
+
lstatSync(filePath: string): Stats;
|
|
246
|
+
renameSync(oldPath: string, newPath: string): void;
|
|
247
|
+
copyFileSync(src: string, dest: string, mode?: number): void;
|
|
248
|
+
truncateSync(filePath: string, len?: number): void;
|
|
249
|
+
accessSync(filePath: string, mode?: number): void;
|
|
250
|
+
realpathSync(filePath: string): string;
|
|
251
|
+
chmodSync(filePath: string, mode: number): void;
|
|
252
|
+
chownSync(filePath: string, uid: number, gid: number): void;
|
|
253
|
+
utimesSync(filePath: string, atime: Date | number, mtime: Date | number): void;
|
|
254
|
+
symlinkSync(target: string, linkPath: string): void;
|
|
255
|
+
readlinkSync(filePath: string): string;
|
|
256
|
+
linkSync(existingPath: string, newPath: string): void;
|
|
257
|
+
mkdtempSync(prefix: string): string;
|
|
258
|
+
openSync(filePath: string, flags?: string | number, mode?: number): number;
|
|
259
|
+
closeSync(fd: number): void;
|
|
260
|
+
readSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number | null): number;
|
|
261
|
+
writeSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number | null): number;
|
|
262
|
+
fstatSync(fd: number): Stats;
|
|
263
|
+
ftruncateSync(fd: number, len?: number): void;
|
|
264
|
+
fdatasyncSync(fd: number): void;
|
|
265
|
+
watch(filePath: string, options?: WatchOptions | Encoding, listener?: WatchListener): FSWatcher;
|
|
266
|
+
watchFile(filePath: string, optionsOrListener?: WatchFileOptions | WatchFileListener, listener?: WatchFileListener): void;
|
|
267
|
+
unwatchFile(filePath: string, listener?: WatchFileListener): void;
|
|
268
|
+
createReadStream(filePath: string, options?: ReadStreamOptions | string): ReadableStream<Uint8Array>;
|
|
269
|
+
createWriteStream(filePath: string, options?: WriteStreamOptions | string): WritableStream<Uint8Array>;
|
|
270
|
+
flushSync(): void;
|
|
271
|
+
purgeSync(): void;
|
|
272
|
+
/** The current filesystem mode. Changes to 'opfs' on corruption fallback. */
|
|
273
|
+
get mode(): FSMode;
|
|
274
|
+
/** Async init helper — avoid blocking main thread.
|
|
275
|
+
* Rejects with corruption error if VFS was corrupt (but system falls back to OPFS mode).
|
|
276
|
+
* Callers can catch and continue — the fs API works in OPFS mode after rejection. */
|
|
277
|
+
init(): Promise<void>;
|
|
278
|
+
/** Switch the filesystem mode at runtime.
|
|
279
|
+
*
|
|
280
|
+
* Typical flow for IDE corruption recovery:
|
|
281
|
+
* 1. `await fs.init()` throws with corruption error (auto-falls back to opfs)
|
|
282
|
+
* 2. IDE shows warning, user clicks "Repair" → call `repairVFS(root, fs)`
|
|
283
|
+
* 3. After repair: `await fs.setMode('hybrid')` to resume normal VFS+OPFS mode
|
|
284
|
+
*
|
|
285
|
+
* Returns a Promise that resolves when the new mode is ready. */
|
|
286
|
+
setMode(newMode: FSMode): Promise<void>;
|
|
287
|
+
}
|
|
288
|
+
declare class VFSPromises {
|
|
289
|
+
private _async;
|
|
290
|
+
private _ns;
|
|
291
|
+
constructor(asyncRequest: AsyncRequestFn, ns: string);
|
|
292
|
+
readFile(filePath: string, options?: ReadOptions | Encoding | null): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
293
|
+
writeFile(filePath: string, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
|
|
294
|
+
appendFile(filePath: string, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
|
|
295
|
+
mkdir(filePath: string, options?: MkdirOptions | number): Promise<string | undefined>;
|
|
296
|
+
rmdir(filePath: string, options?: RmdirOptions): Promise<void>;
|
|
297
|
+
rm(filePath: string, options?: RmOptions): Promise<void>;
|
|
298
|
+
unlink(filePath: string): Promise<void>;
|
|
299
|
+
readdir(filePath: string, options?: ReaddirOptions | Encoding | null): Promise<string[] | Dirent[]>;
|
|
300
|
+
stat(filePath: string): Promise<Stats>;
|
|
301
|
+
lstat(filePath: string): Promise<Stats>;
|
|
302
|
+
access(filePath: string, mode?: number): Promise<void>;
|
|
303
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
304
|
+
copyFile(src: string, dest: string, mode?: number): Promise<void>;
|
|
305
|
+
truncate(filePath: string, len?: number): Promise<void>;
|
|
306
|
+
realpath(filePath: string): Promise<string>;
|
|
307
|
+
exists(filePath: string): Promise<boolean>;
|
|
308
|
+
chmod(filePath: string, mode: number): Promise<void>;
|
|
309
|
+
chown(filePath: string, uid: number, gid: number): Promise<void>;
|
|
310
|
+
utimes(filePath: string, atime: Date | number, mtime: Date | number): Promise<void>;
|
|
311
|
+
symlink(target: string, linkPath: string): Promise<void>;
|
|
312
|
+
readlink(filePath: string): Promise<string>;
|
|
313
|
+
link(existingPath: string, newPath: string): Promise<void>;
|
|
314
|
+
open(filePath: string, flags?: string | number, mode?: number): Promise<FileHandle>;
|
|
315
|
+
opendir(filePath: string): Promise<Dir>;
|
|
316
|
+
mkdtemp(prefix: string): Promise<string>;
|
|
317
|
+
watch(filePath: string, options?: WatchOptions): AsyncIterable<WatchEventType>;
|
|
318
|
+
flush(): Promise<void>;
|
|
319
|
+
purge(): Promise<void>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* File system constants matching Node.js fs.constants
|
|
324
|
+
*/
|
|
325
|
+
declare const constants: {
|
|
326
|
+
readonly F_OK: 0;
|
|
327
|
+
readonly R_OK: 4;
|
|
328
|
+
readonly W_OK: 2;
|
|
329
|
+
readonly X_OK: 1;
|
|
330
|
+
readonly COPYFILE_EXCL: 1;
|
|
331
|
+
readonly COPYFILE_FICLONE: 2;
|
|
332
|
+
readonly COPYFILE_FICLONE_FORCE: 4;
|
|
333
|
+
readonly O_RDONLY: 0;
|
|
334
|
+
readonly O_WRONLY: 1;
|
|
335
|
+
readonly O_RDWR: 2;
|
|
336
|
+
readonly O_CREAT: 64;
|
|
337
|
+
readonly O_EXCL: 128;
|
|
338
|
+
readonly O_TRUNC: 512;
|
|
339
|
+
readonly O_APPEND: 1024;
|
|
340
|
+
readonly O_SYNC: 4096;
|
|
341
|
+
readonly S_IFMT: 61440;
|
|
342
|
+
readonly S_IFREG: 32768;
|
|
343
|
+
readonly S_IFDIR: 16384;
|
|
344
|
+
readonly S_IFCHR: 8192;
|
|
345
|
+
readonly S_IFBLK: 24576;
|
|
346
|
+
readonly S_IFIFO: 4096;
|
|
347
|
+
readonly S_IFLNK: 40960;
|
|
348
|
+
readonly S_IFSOCK: 49152;
|
|
349
|
+
readonly S_IRWXU: 448;
|
|
350
|
+
readonly S_IRUSR: 256;
|
|
351
|
+
readonly S_IWUSR: 128;
|
|
352
|
+
readonly S_IXUSR: 64;
|
|
353
|
+
readonly S_IRWXG: 56;
|
|
354
|
+
readonly S_IRGRP: 32;
|
|
355
|
+
readonly S_IWGRP: 16;
|
|
356
|
+
readonly S_IXGRP: 8;
|
|
357
|
+
readonly S_IRWXO: 7;
|
|
358
|
+
readonly S_IROTH: 4;
|
|
359
|
+
readonly S_IWOTH: 2;
|
|
360
|
+
readonly S_IXOTH: 1;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Node.js compatible filesystem error classes
|
|
365
|
+
*/
|
|
366
|
+
declare class FSError extends Error {
|
|
367
|
+
code: string;
|
|
368
|
+
errno: number;
|
|
369
|
+
syscall?: string;
|
|
370
|
+
path?: string;
|
|
371
|
+
constructor(code: string, errno: number, message: string, syscall?: string, path?: string);
|
|
372
|
+
}
|
|
373
|
+
declare function createError(code: string, syscall: string, path: string): FSError;
|
|
374
|
+
declare function statusToError(status: number, syscall: string, path: string): FSError;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* VFS Helper Functions
|
|
378
|
+
*
|
|
379
|
+
* Standalone utilities for VFS maintenance:
|
|
380
|
+
* - unpackToOPFS: Export VFS contents to real OPFS files
|
|
381
|
+
* - loadFromOPFS: Rebuild VFS from real OPFS files
|
|
382
|
+
* - repairVFS: Attempt to recover files from a corrupt VFS binary
|
|
383
|
+
*
|
|
384
|
+
* Each function accepts an optional `fs` parameter (a running VFSFileSystem
|
|
385
|
+
* instance). When provided, operations go through the VFS worker which holds
|
|
386
|
+
* the exclusive sync handle on .vfs.bin. This allows these functions to work
|
|
387
|
+
* from the main thread while the VFS is running.
|
|
388
|
+
*
|
|
389
|
+
* When `fs` is NOT provided, spawns a repair worker that uses
|
|
390
|
+
* createSyncAccessHandle for direct disk I/O (no RAM bloat).
|
|
391
|
+
*/
|
|
392
|
+
/**
|
|
393
|
+
* Minimal FS interface accepted by the helper functions.
|
|
394
|
+
* Compatible with VFSFileSystem — avoids circular import.
|
|
395
|
+
*/
|
|
396
|
+
interface FsLike {
|
|
397
|
+
readFileSync(path: string, options?: any): any;
|
|
398
|
+
writeFileSync(path: string, data: any, options?: any): void;
|
|
399
|
+
mkdirSync(path: string, options?: any): any;
|
|
400
|
+
readdirSync(path: string, options?: any): any;
|
|
401
|
+
rmSync(path: string, options?: any): void;
|
|
402
|
+
statSync(path: string): any;
|
|
403
|
+
symlinkSync?(target: string, path: string): void;
|
|
404
|
+
}
|
|
405
|
+
interface UnpackResult {
|
|
406
|
+
files: number;
|
|
407
|
+
directories: number;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Unpack VFS contents to real OPFS files.
|
|
411
|
+
*
|
|
412
|
+
* When `fs` is provided: reads VFS via the running instance (communicates
|
|
413
|
+
* with VFS worker), writes to OPFS additively (no deletions).
|
|
414
|
+
*
|
|
415
|
+
* When `fs` is NOT provided: opens .vfs.bin directly via VFSEngine,
|
|
416
|
+
* clears OPFS (except .vfs.bin), then writes all entries.
|
|
417
|
+
* Requires VFS to be stopped or a Worker context.
|
|
418
|
+
*/
|
|
419
|
+
declare function unpackToOPFS(root?: string, fs?: FsLike): Promise<UnpackResult>;
|
|
420
|
+
interface LoadResult {
|
|
421
|
+
files: number;
|
|
422
|
+
directories: number;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Load all real OPFS files into VFS.
|
|
426
|
+
*
|
|
427
|
+
* When `fs` is provided: reads OPFS files, clears VFS, writes to VFS via
|
|
428
|
+
* the running instance. Never touches .vfs.bin directly.
|
|
429
|
+
*
|
|
430
|
+
* When `fs` is NOT provided: reads OPFS files, deletes .vfs.bin, creates
|
|
431
|
+
* fresh VFS via VFSEngine. Requires VFS to be stopped or a Worker context.
|
|
432
|
+
*/
|
|
433
|
+
declare function loadFromOPFS(root?: string, fs?: FsLike): Promise<LoadResult>;
|
|
434
|
+
interface RepairResult {
|
|
435
|
+
recovered: number;
|
|
436
|
+
lost: number;
|
|
437
|
+
entries: Array<{
|
|
438
|
+
path: string;
|
|
439
|
+
type: 'file' | 'directory' | 'symlink';
|
|
440
|
+
size: number;
|
|
441
|
+
/** true when the inode was found but data blocks were out of bounds (content lost) */
|
|
442
|
+
contentLost?: boolean;
|
|
443
|
+
}>;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Attempt to repair a VFS.
|
|
447
|
+
*
|
|
448
|
+
* When `fs` is provided: rebuilds VFS from OPFS files (non-destructive read
|
|
449
|
+
* of OPFS), then syncs repaired VFS back to OPFS (additive, no deletions).
|
|
450
|
+
* This is the safe path — OPFS is the source of truth.
|
|
451
|
+
*
|
|
452
|
+
* When `fs` is NOT provided: scans raw .vfs.bin for recoverable inodes,
|
|
453
|
+
* creates fresh VFS with recovered data. For corrupt VFS where init failed.
|
|
454
|
+
*/
|
|
455
|
+
declare function repairVFS(root?: string, fs?: FsLike): Promise<RepairResult>;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* POSIX path utilities (browser-compatible).
|
|
459
|
+
* No Node.js dependencies.
|
|
460
|
+
*/
|
|
461
|
+
declare const sep = "/";
|
|
462
|
+
declare const delimiter = ":";
|
|
463
|
+
declare function normalize(p: string): string;
|
|
464
|
+
declare function join(...paths: string[]): string;
|
|
465
|
+
declare function resolve(...paths: string[]): string;
|
|
466
|
+
declare function dirname(p: string): string;
|
|
467
|
+
declare function basename(p: string, ext?: string): string;
|
|
468
|
+
declare function extname(p: string): string;
|
|
469
|
+
declare function isAbsolute(p: string): boolean;
|
|
470
|
+
declare function relative(from: string, to: string): string;
|
|
471
|
+
declare function parse(p: string): {
|
|
472
|
+
root: string;
|
|
473
|
+
dir: string;
|
|
474
|
+
base: string;
|
|
475
|
+
ext: string;
|
|
476
|
+
name: string;
|
|
477
|
+
};
|
|
478
|
+
declare function format(obj: {
|
|
479
|
+
root?: string;
|
|
480
|
+
dir?: string;
|
|
481
|
+
base?: string;
|
|
482
|
+
ext?: string;
|
|
483
|
+
name?: string;
|
|
484
|
+
}): string;
|
|
485
|
+
|
|
486
|
+
declare const path_basename: typeof basename;
|
|
487
|
+
declare const path_delimiter: typeof delimiter;
|
|
488
|
+
declare const path_dirname: typeof dirname;
|
|
489
|
+
declare const path_extname: typeof extname;
|
|
490
|
+
declare const path_format: typeof format;
|
|
491
|
+
declare const path_isAbsolute: typeof isAbsolute;
|
|
492
|
+
declare const path_join: typeof join;
|
|
493
|
+
declare const path_normalize: typeof normalize;
|
|
494
|
+
declare const path_parse: typeof parse;
|
|
495
|
+
declare const path_relative: typeof relative;
|
|
496
|
+
declare const path_resolve: typeof resolve;
|
|
497
|
+
declare const path_sep: typeof sep;
|
|
498
|
+
declare namespace path {
|
|
499
|
+
export { path_basename as basename, path_delimiter as delimiter, path_dirname as dirname, path_extname as extname, path_format as format, path_isAbsolute as isAbsolute, path_join as join, path_normalize as normalize, path_parse as parse, path_relative as relative, path_resolve as resolve, path_sep as sep };
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Create a configured VFS instance */
|
|
503
|
+
declare function createFS(config?: VFSConfig): VFSFileSystem;
|
|
504
|
+
/** Get (or create) the default VFS singleton */
|
|
505
|
+
declare function getDefaultFS(): VFSFileSystem;
|
|
506
|
+
/** Async init helper — avoids blocking main thread */
|
|
507
|
+
declare function init(): Promise<void>;
|
|
508
|
+
|
|
509
|
+
export { type Dir, type Dirent, type Encoding, FSError, type FSMode, type FSWatcher, type FileHandle, type LoadResult, type MkdirOptions, type PathLike, type ReadOptions, type ReadStreamOptions, type ReaddirOptions, type RepairResult, type RmOptions, type RmdirOptions, type Stats, type UnpackResult, type VFSConfig, VFSFileSystem, type WatchEventType, type WatchFileListener, type WatchListener, type WatchOptions, type WriteOptions, type WriteStreamOptions, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path, repairVFS, statusToError, unpackToOPFS };
|
package/package.json
CHANGED