@zenfs/core 0.11.2 → 0.12.1
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/backends/backend.d.ts +15 -5
- package/dist/backends/fetch.d.ts +19 -32
- package/dist/backends/fetch.js +38 -85
- package/dist/backends/index/fs.d.ts +49 -0
- package/dist/backends/index/fs.js +86 -0
- package/dist/backends/index/index.d.ts +42 -0
- package/dist/backends/index/index.js +83 -0
- package/dist/backends/port/fs.d.ts +2 -1
- package/dist/browser.min.js +8 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +33 -11
- package/dist/config.js +16 -7
- package/dist/emulation/async.d.ts +1 -0
- package/dist/emulation/async.js +3 -2
- package/dist/emulation/path.d.ts +4 -1
- package/dist/emulation/promises.js +26 -14
- package/dist/emulation/sync.js +27 -15
- package/dist/file.d.ts +1 -1
- package/dist/file.js +10 -10
- package/dist/filesystem.d.ts +22 -2
- package/dist/filesystem.js +37 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/stats.d.ts +10 -10
- package/dist/stats.js +1 -1
- package/package.json +2 -2
- package/scripts/make-index.js +31 -19
- package/src/backends/backend.ts +15 -6
- package/src/backends/fetch.ts +42 -101
- package/src/backends/index/fs.ts +113 -0
- package/src/backends/index/index.ts +103 -0
- package/src/backends/index/readme.md +3 -0
- package/src/config.ts +62 -21
- package/src/emulation/async.ts +14 -13
- package/src/emulation/path.ts +4 -1
- package/src/emulation/promises.ts +25 -14
- package/src/emulation/sync.ts +29 -18
- package/src/error.ts +1 -1
- package/src/file.ts +11 -10
- package/src/filesystem.ts +106 -51
- package/src/index.ts +1 -1
- package/src/stats.ts +13 -13
- package/dist/backends/Index.d.ts +0 -204
- package/dist/backends/Index.js +0 -410
- package/src/backends/Index.ts +0 -504
package/src/filesystem.ts
CHANGED
|
@@ -30,6 +30,20 @@ export interface FileSystemMetadata {
|
|
|
30
30
|
* The available space
|
|
31
31
|
*/
|
|
32
32
|
freeSpace: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* If set, disables File from using a resizable array buffer.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
noResizableBuffers: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If set, disables caching on async file systems.
|
|
42
|
+
* This means *sync operations will not work*.
|
|
43
|
+
* It has no affect on sync file systems.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
noAsyncCache: boolean;
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
/**
|
|
@@ -44,7 +58,7 @@ export interface FileSystemMetadata {
|
|
|
44
58
|
*/
|
|
45
59
|
export abstract class FileSystem {
|
|
46
60
|
/**
|
|
47
|
-
* Get metadata about the current file
|
|
61
|
+
* Get metadata about the current file system
|
|
48
62
|
*/
|
|
49
63
|
public metadata(): FileSystemMetadata {
|
|
50
64
|
return {
|
|
@@ -52,12 +66,13 @@ export abstract class FileSystem {
|
|
|
52
66
|
readonly: false,
|
|
53
67
|
totalSpace: 0,
|
|
54
68
|
freeSpace: 0,
|
|
69
|
+
noResizableBuffers: false,
|
|
70
|
+
noAsyncCache: false,
|
|
55
71
|
};
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
+
public constructor(options?: object) {}
|
|
61
76
|
|
|
62
77
|
public async ready(): Promise<void> {}
|
|
63
78
|
|
|
@@ -157,7 +172,7 @@ export abstract class FileSystem {
|
|
|
157
172
|
await this.stat(path, cred);
|
|
158
173
|
return true;
|
|
159
174
|
} catch (e) {
|
|
160
|
-
return
|
|
175
|
+
return (e as ErrnoError).code != 'ENOENT';
|
|
161
176
|
}
|
|
162
177
|
}
|
|
163
178
|
|
|
@@ -169,7 +184,7 @@ export abstract class FileSystem {
|
|
|
169
184
|
this.statSync(path, cred);
|
|
170
185
|
return true;
|
|
171
186
|
} catch (e) {
|
|
172
|
-
return
|
|
187
|
+
return (e as ErrnoError).code != 'ENOENT';
|
|
173
188
|
}
|
|
174
189
|
}
|
|
175
190
|
|
|
@@ -198,19 +213,19 @@ export abstract class FileSystem {
|
|
|
198
213
|
* @internal
|
|
199
214
|
*/
|
|
200
215
|
declare abstract class SyncFS extends FileSystem {
|
|
201
|
-
metadata(): FileSystemMetadata;
|
|
202
|
-
ready(): Promise<void>;
|
|
203
|
-
exists(path: string, cred: Cred): Promise<boolean>;
|
|
204
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
205
|
-
stat(path: string, cred: Cred): Promise<Stats>;
|
|
206
|
-
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
207
|
-
openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
208
|
-
unlink(path: string, cred: Cred): Promise<void>;
|
|
209
|
-
rmdir(path: string, cred: Cred): Promise<void>;
|
|
210
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
211
|
-
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
212
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
213
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
216
|
+
public metadata(): FileSystemMetadata;
|
|
217
|
+
public ready(): Promise<void>;
|
|
218
|
+
public exists(path: string, cred: Cred): Promise<boolean>;
|
|
219
|
+
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
220
|
+
public stat(path: string, cred: Cred): Promise<Stats>;
|
|
221
|
+
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
222
|
+
public openFile(path: string, flag: string, cred: Cred): Promise<File>;
|
|
223
|
+
public unlink(path: string, cred: Cred): Promise<void>;
|
|
224
|
+
public rmdir(path: string, cred: Cred): Promise<void>;
|
|
225
|
+
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
226
|
+
public readdir(path: string, cred: Cred): Promise<string[]>;
|
|
227
|
+
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
228
|
+
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
/**
|
|
@@ -268,25 +283,33 @@ export function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
268
283
|
|
|
269
284
|
/**
|
|
270
285
|
* @internal
|
|
286
|
+
* Note: `_*` should be treated like protected.
|
|
287
|
+
* Protected can't be used because of TS quirks however.
|
|
271
288
|
*/
|
|
272
289
|
declare abstract class AsyncFS extends FileSystem {
|
|
273
290
|
/**
|
|
291
|
+
* @access protected
|
|
274
292
|
* @hidden
|
|
275
293
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
294
|
+
_disableSync: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* @access protected
|
|
297
|
+
* @hidden
|
|
298
|
+
*/
|
|
299
|
+
abstract _sync?: FileSystem;
|
|
300
|
+
public queueDone(): Promise<void>;
|
|
301
|
+
public metadata(): FileSystemMetadata;
|
|
302
|
+
public ready(): Promise<void>;
|
|
303
|
+
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
304
|
+
public statSync(path: string, cred: Cred): Stats;
|
|
305
|
+
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
306
|
+
public openFileSync(path: string, flag: string, cred: Cred): File;
|
|
307
|
+
public unlinkSync(path: string, cred: Cred): void;
|
|
308
|
+
public rmdirSync(path: string, cred: Cred): void;
|
|
309
|
+
public mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
310
|
+
public readdirSync(path: string, cred: Cred): string[];
|
|
311
|
+
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
312
|
+
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
290
313
|
}
|
|
291
314
|
|
|
292
315
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -331,14 +354,18 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
331
354
|
|
|
332
355
|
private _isInitialized: boolean = false;
|
|
333
356
|
|
|
334
|
-
|
|
357
|
+
_disableSync: boolean = false;
|
|
358
|
+
|
|
359
|
+
abstract _sync?: FileSystem;
|
|
335
360
|
|
|
336
361
|
public async ready(): Promise<void> {
|
|
337
|
-
await this._sync.ready();
|
|
338
362
|
await super.ready();
|
|
339
|
-
if (this._isInitialized) {
|
|
363
|
+
if (this._isInitialized || this._disableSync) {
|
|
340
364
|
return;
|
|
341
365
|
}
|
|
366
|
+
this.checkSync();
|
|
367
|
+
|
|
368
|
+
await this._sync.ready();
|
|
342
369
|
|
|
343
370
|
try {
|
|
344
371
|
await this.crossCopy('/');
|
|
@@ -349,22 +376,42 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
349
376
|
}
|
|
350
377
|
}
|
|
351
378
|
|
|
379
|
+
public metadata(): FileSystemMetadata {
|
|
380
|
+
return {
|
|
381
|
+
...super.metadata(),
|
|
382
|
+
noAsyncCache: this._disableSync,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
protected checkSync(path?: string, syscall?: string): asserts this is { _sync: FileSystem } {
|
|
387
|
+
if (this._disableSync) {
|
|
388
|
+
throw new ErrnoError(Errno.ENOTSUP, 'Sync caching has been disabled for this async file system', path, syscall);
|
|
389
|
+
}
|
|
390
|
+
if (!this._sync) {
|
|
391
|
+
throw new ErrnoError(Errno.ENOTSUP, 'No sync cache is attached to this async file system', path, syscall);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
352
395
|
public renameSync(oldPath: string, newPath: string, cred: Cred): void {
|
|
396
|
+
this.checkSync(oldPath, 'rename');
|
|
353
397
|
this._sync.renameSync(oldPath, newPath, cred);
|
|
354
398
|
this.queue('rename', oldPath, newPath, cred);
|
|
355
399
|
}
|
|
356
400
|
|
|
357
401
|
public statSync(path: string, cred: Cred): Stats {
|
|
402
|
+
this.checkSync(path, 'stat');
|
|
358
403
|
return this._sync.statSync(path, cred);
|
|
359
404
|
}
|
|
360
405
|
|
|
361
406
|
public createFileSync(path: string, flag: string, mode: number, cred: Cred): PreloadFile<this> {
|
|
407
|
+
this.checkSync(path, 'createFile');
|
|
362
408
|
this._sync.createFileSync(path, flag, mode, cred);
|
|
363
409
|
this.queue('createFile', path, flag, mode, cred);
|
|
364
410
|
return this.openFileSync(path, flag, cred);
|
|
365
411
|
}
|
|
366
412
|
|
|
367
413
|
public openFileSync(path: string, flag: string, cred: Cred): PreloadFile<this> {
|
|
414
|
+
this.checkSync(path, 'openFile');
|
|
368
415
|
const file = this._sync.openFileSync(path, flag, cred);
|
|
369
416
|
const stats = file.statSync();
|
|
370
417
|
const buffer = new Uint8Array(stats.size);
|
|
@@ -373,35 +420,42 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
373
420
|
}
|
|
374
421
|
|
|
375
422
|
public unlinkSync(path: string, cred: Cred): void {
|
|
423
|
+
this.checkSync(path, 'unlinkSync');
|
|
376
424
|
this._sync.unlinkSync(path, cred);
|
|
377
425
|
this.queue('unlink', path, cred);
|
|
378
426
|
}
|
|
379
427
|
|
|
380
428
|
public rmdirSync(path: string, cred: Cred): void {
|
|
429
|
+
this.checkSync(path, 'rmdir');
|
|
381
430
|
this._sync.rmdirSync(path, cred);
|
|
382
431
|
this.queue('rmdir', path, cred);
|
|
383
432
|
}
|
|
384
433
|
|
|
385
434
|
public mkdirSync(path: string, mode: number, cred: Cred): void {
|
|
435
|
+
this.checkSync(path, 'mkdir');
|
|
386
436
|
this._sync.mkdirSync(path, mode, cred);
|
|
387
437
|
this.queue('mkdir', path, mode, cred);
|
|
388
438
|
}
|
|
389
439
|
|
|
390
440
|
public readdirSync(path: string, cred: Cred): string[] {
|
|
441
|
+
this.checkSync(path, 'readdir');
|
|
391
442
|
return this._sync.readdirSync(path, cred);
|
|
392
443
|
}
|
|
393
444
|
|
|
394
445
|
public linkSync(srcpath: string, dstpath: string, cred: Cred): void {
|
|
446
|
+
this.checkSync(srcpath, 'link');
|
|
395
447
|
this._sync.linkSync(srcpath, dstpath, cred);
|
|
396
448
|
this.queue('link', srcpath, dstpath, cred);
|
|
397
449
|
}
|
|
398
450
|
|
|
399
451
|
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void {
|
|
452
|
+
this.checkSync(path, 'sync');
|
|
400
453
|
this._sync.syncSync(path, data, stats);
|
|
401
454
|
this.queue('sync', path, data, stats);
|
|
402
455
|
}
|
|
403
456
|
|
|
404
457
|
public existsSync(path: string, cred: Cred): boolean {
|
|
458
|
+
this.checkSync(path, 'exists');
|
|
405
459
|
return this._sync.existsSync(path, cred);
|
|
406
460
|
}
|
|
407
461
|
|
|
@@ -409,6 +463,7 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
409
463
|
* @internal
|
|
410
464
|
*/
|
|
411
465
|
protected async crossCopy(path: string): Promise<void> {
|
|
466
|
+
this.checkSync(path, 'crossCopy');
|
|
412
467
|
const stats = await this.stat(path, rootCred);
|
|
413
468
|
if (stats.isDirectory()) {
|
|
414
469
|
if (path !== '/') {
|
|
@@ -463,21 +518,21 @@ export function Async<T extends abstract new (...args: any[]) => FileSystem>(FS:
|
|
|
463
518
|
* @internal
|
|
464
519
|
*/
|
|
465
520
|
declare abstract class ReadonlyFS extends FileSystem {
|
|
466
|
-
metadata(): FileSystemMetadata;
|
|
467
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
468
|
-
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
469
|
-
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
470
|
-
createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
471
|
-
unlink(path: string, cred: Cred): Promise<void>;
|
|
472
|
-
unlinkSync(path: string, cred: Cred): void;
|
|
473
|
-
rmdir(path: string, cred: Cred): Promise<void>;
|
|
474
|
-
rmdirSync(path: string, cred: Cred): void;
|
|
475
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
476
|
-
mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
477
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
478
|
-
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
479
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
480
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
521
|
+
public metadata(): FileSystemMetadata;
|
|
522
|
+
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
523
|
+
public renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
524
|
+
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
|
|
525
|
+
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
|
|
526
|
+
public unlink(path: string, cred: Cred): Promise<void>;
|
|
527
|
+
public unlinkSync(path: string, cred: Cred): void;
|
|
528
|
+
public rmdir(path: string, cred: Cred): Promise<void>;
|
|
529
|
+
public rmdirSync(path: string, cred: Cred): void;
|
|
530
|
+
public mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
531
|
+
public mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
532
|
+
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
533
|
+
public linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
534
|
+
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
535
|
+
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
481
536
|
}
|
|
482
537
|
|
|
483
538
|
/**
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './error.js';
|
|
|
2
2
|
export * from './backends/port/fs.js';
|
|
3
3
|
export * from './backends/fetch.js';
|
|
4
4
|
export * from './backends/memory.js';
|
|
5
|
-
export * from './backends/
|
|
5
|
+
export * from './backends/index/fs.js';
|
|
6
6
|
export * from './backends/locked.js';
|
|
7
7
|
export * from './backends/overlay.js';
|
|
8
8
|
export * from './backends/store/fs.js';
|
package/src/stats.ts
CHANGED
|
@@ -14,45 +14,45 @@ export enum FileType {
|
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
export interface StatsLike {
|
|
17
|
+
export interface StatsLike<T extends number | bigint = number | bigint> {
|
|
18
18
|
/**
|
|
19
19
|
* Size of the item in bytes.
|
|
20
20
|
* For directories/symlinks, this is normally the size of the struct that represents the item.
|
|
21
21
|
*/
|
|
22
|
-
size:
|
|
22
|
+
size: T;
|
|
23
23
|
/**
|
|
24
24
|
* Unix-style file mode (e.g. 0o644) that includes the item type
|
|
25
25
|
* Type of the item can be FILE, DIRECTORY, SYMLINK, or SOCKET
|
|
26
26
|
*/
|
|
27
|
-
mode:
|
|
27
|
+
mode: T;
|
|
28
28
|
/**
|
|
29
29
|
* time of last access, in milliseconds since epoch
|
|
30
30
|
*/
|
|
31
|
-
atimeMs:
|
|
31
|
+
atimeMs: T;
|
|
32
32
|
/**
|
|
33
33
|
* time of last modification, in milliseconds since epoch
|
|
34
34
|
*/
|
|
35
|
-
mtimeMs:
|
|
35
|
+
mtimeMs: T;
|
|
36
36
|
/**
|
|
37
37
|
* time of last time file status was changed, in milliseconds since epoch
|
|
38
38
|
*/
|
|
39
|
-
ctimeMs:
|
|
39
|
+
ctimeMs: T;
|
|
40
40
|
/**
|
|
41
41
|
* time of file creation, in milliseconds since epoch
|
|
42
42
|
*/
|
|
43
|
-
birthtimeMs:
|
|
43
|
+
birthtimeMs: T;
|
|
44
44
|
/**
|
|
45
45
|
* the id of the user that owns the file
|
|
46
46
|
*/
|
|
47
|
-
uid:
|
|
47
|
+
uid: T;
|
|
48
48
|
/**
|
|
49
49
|
* the id of the group that owns the file
|
|
50
50
|
*/
|
|
51
|
-
gid:
|
|
51
|
+
gid: T;
|
|
52
52
|
/**
|
|
53
53
|
* the ino
|
|
54
54
|
*/
|
|
55
|
-
ino:
|
|
55
|
+
ino: T;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -71,7 +71,7 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
protected _convert(arg: number | bigint | string | boolean): T {
|
|
74
|
-
return
|
|
74
|
+
return (this._isBigint ? BigInt(arg) : Number(arg)) as T;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
public blocks: T;
|
|
@@ -186,7 +186,7 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
186
186
|
constructor({ atimeMs, mtimeMs, ctimeMs, birthtimeMs, uid, gid, size, mode, ino }: Partial<StatsLike> = {}) {
|
|
187
187
|
const currentTime = Date.now();
|
|
188
188
|
const resolveT = (val: number | bigint | undefined, _default: number) =>
|
|
189
|
-
|
|
189
|
+
typeof val == this._typename ? (val as T) : this._convert(typeof val == this._typename_inverse ? val! : _default);
|
|
190
190
|
this.atimeMs = resolveT(atimeMs, currentTime);
|
|
191
191
|
this.mtimeMs = resolveT(mtimeMs, currentTime);
|
|
192
192
|
this.ctimeMs = resolveT(ctimeMs, currentTime);
|
|
@@ -213,7 +213,7 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
|
|
|
213
213
|
this.blocks = this._convert(Math.ceil(Number(size) / 512));
|
|
214
214
|
// Check if mode also includes top-most bits, which indicate the file's type.
|
|
215
215
|
if ((this.mode & S_IFMT) == 0) {
|
|
216
|
-
this.mode =
|
|
216
|
+
this.mode = (this.mode | this._convert(itemType)) as T;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
package/dist/backends/Index.d.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import type { Cred } from '../cred.js';
|
|
2
|
-
import { NoSyncFile } from '../file.js';
|
|
3
|
-
import { FileSystem } from '../filesystem.js';
|
|
4
|
-
import { Stats } from '../stats.js';
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export type ListingTree = {
|
|
9
|
-
[key: string]: ListingTree | null;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface ListingQueueNode<TData> {
|
|
15
|
-
pwd: string;
|
|
16
|
-
tree: ListingTree;
|
|
17
|
-
parent: IndexDirInode<TData>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A simple class for storing a filesystem index. Assumes that all paths passed
|
|
21
|
-
* to it are *absolute* paths.
|
|
22
|
-
*
|
|
23
|
-
* Can be used as a partial or a full index, although care must be taken if used
|
|
24
|
-
* for the former purpose, especially when directories are concerned.
|
|
25
|
-
*
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export declare class FileIndex<TData> {
|
|
29
|
-
/**
|
|
30
|
-
* Static method for constructing indices from a JSON listing.
|
|
31
|
-
* @param listing Directory listing generated by tools
|
|
32
|
-
* @return A new FileIndex object.
|
|
33
|
-
*/
|
|
34
|
-
static FromListing<T>(listing: ListingTree): FileIndex<T>;
|
|
35
|
-
protected _index: Map<string, IndexDirInode<TData>>;
|
|
36
|
-
/**
|
|
37
|
-
* Constructs a new FileIndex.
|
|
38
|
-
*/
|
|
39
|
-
constructor();
|
|
40
|
-
files(): IndexFileInode<TData>[];
|
|
41
|
-
/**
|
|
42
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
43
|
-
* Creates any needed parent directories.
|
|
44
|
-
* @param path The path to add to the index.
|
|
45
|
-
* @param inode The inode for the
|
|
46
|
-
* path to add.
|
|
47
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
48
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
49
|
-
* different).
|
|
50
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up
|
|
51
|
-
* the new empty directories.
|
|
52
|
-
*/
|
|
53
|
-
add(path: string, inode: IndexInode<TData>): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
56
|
-
* The path is added without special treatment (no joining of adjacent separators, etc).
|
|
57
|
-
* Creates any needed parent directories.
|
|
58
|
-
* @param path The path to add to the index.
|
|
59
|
-
* @param inode The inode for the path to add.
|
|
60
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
61
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
62
|
-
* different).
|
|
63
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up the new empty directories.
|
|
64
|
-
*/
|
|
65
|
-
addFast(path: string, inode: IndexInode<TData>): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Removes the given path. Can be a file or a directory.
|
|
68
|
-
* @return The removed item,
|
|
69
|
-
* or null if it did not exist.
|
|
70
|
-
*/
|
|
71
|
-
remove(path: string): IndexInode<TData> | void;
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves the directory listing of the given path.
|
|
74
|
-
* @return An array of files in the given path, or 'null' if it does not exist.
|
|
75
|
-
*/
|
|
76
|
-
ls(path: string): string[] | void;
|
|
77
|
-
/**
|
|
78
|
-
* Returns the inode of the given item.
|
|
79
|
-
* @return Returns null if the item does not exist.
|
|
80
|
-
*/
|
|
81
|
-
get(path: string): IndexInode<TData> | void | null;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Generic interface for file/directory inodes.
|
|
85
|
-
* Note that Stats objects are what we use for file inodes.
|
|
86
|
-
*/
|
|
87
|
-
export declare abstract class IndexInode<TData> {
|
|
88
|
-
data?: TData | undefined;
|
|
89
|
-
constructor(data?: TData | undefined);
|
|
90
|
-
/**
|
|
91
|
-
* Whether this inode is for a file
|
|
92
|
-
*/
|
|
93
|
-
abstract isFile(): this is IndexFileInode<TData>;
|
|
94
|
-
/**
|
|
95
|
-
* Whether this inode is for a directory
|
|
96
|
-
*/
|
|
97
|
-
abstract isDirectory(): this is IndexDirInode<TData>;
|
|
98
|
-
abstract toStats(): Stats;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Inode for a file. Stores an arbitrary (filesystem-specific) data payload.
|
|
102
|
-
*/
|
|
103
|
-
export declare class IndexFileInode<TData> extends IndexInode<TData> {
|
|
104
|
-
isFile(): boolean;
|
|
105
|
-
isDirectory(): boolean;
|
|
106
|
-
toStats(): Stats;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Inode for a directory. Currently only contains the directory listing.
|
|
110
|
-
*/
|
|
111
|
-
export declare class IndexDirInode<TData> extends IndexInode<TData> {
|
|
112
|
-
/**
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
_listing: Map<string, IndexInode<TData>>;
|
|
116
|
-
isFile(): boolean;
|
|
117
|
-
isDirectory(): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Return a Stats object for this inode.
|
|
120
|
-
* @todo Should probably remove this at some point. This isn't the responsibility of the FileIndex.
|
|
121
|
-
*/
|
|
122
|
-
get stats(): Stats;
|
|
123
|
-
/**
|
|
124
|
-
* Alias of getStats()
|
|
125
|
-
* @todo Remove this at some point. This isn't the responsibility of the FileIndex.
|
|
126
|
-
*/
|
|
127
|
-
toStats(): Stats;
|
|
128
|
-
/**
|
|
129
|
-
* Returns the directory listing for this directory. Paths in the directory are
|
|
130
|
-
* relative to the directory's path.
|
|
131
|
-
* @return The directory listing for this directory.
|
|
132
|
-
*/
|
|
133
|
-
get listing(): string[];
|
|
134
|
-
/**
|
|
135
|
-
* Returns the inode for the indicated item, or null if it does not exist.
|
|
136
|
-
* @param path Name of item in this directory.
|
|
137
|
-
*/
|
|
138
|
-
get(path: string): IndexInode<TData> | void;
|
|
139
|
-
/**
|
|
140
|
-
* Add the given item to the directory listing. Note that the given inode is
|
|
141
|
-
* not copied, and will be mutated by the DirInode if it is a DirInode.
|
|
142
|
-
* @param path Item name to add to the directory listing.
|
|
143
|
-
* @param inode The inode for the
|
|
144
|
-
* item to add to the directory inode.
|
|
145
|
-
* @return True if it was added, false if it already existed.
|
|
146
|
-
*/
|
|
147
|
-
add(path: string, inode: IndexInode<TData>): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Removes the given item from the directory listing.
|
|
150
|
-
* @param path Name of item to remove from the directory listing.
|
|
151
|
-
* @return Returns the item
|
|
152
|
-
* removed, or null if the item did not exist.
|
|
153
|
-
*/
|
|
154
|
-
remove(path: string): IndexInode<TData> | void;
|
|
155
|
-
}
|
|
156
|
-
declare const IndexFS_base: (abstract new (...args: any[]) => {
|
|
157
|
-
metadata(): import("../filesystem.js").FileSystemMetadata;
|
|
158
|
-
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
|
|
159
|
-
renameSync(oldPath: string, newPath: string, cred: Cred): void;
|
|
160
|
-
createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>;
|
|
161
|
-
createFileSync(path: string, flag: string, mode: number, cred: Cred): import("../file.js").File;
|
|
162
|
-
unlink(path: string, cred: Cred): Promise<void>;
|
|
163
|
-
unlinkSync(path: string, cred: Cred): void;
|
|
164
|
-
rmdir(path: string, cred: Cred): Promise<void>;
|
|
165
|
-
rmdirSync(path: string, cred: Cred): void;
|
|
166
|
-
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
|
|
167
|
-
mkdirSync(path: string, mode: number, cred: Cred): void;
|
|
168
|
-
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
169
|
-
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
|
|
170
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
171
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
172
|
-
ready(): Promise<void>;
|
|
173
|
-
stat(path: string, cred: Cred): Promise<Stats>;
|
|
174
|
-
statSync(path: string, cred: Cred): Stats;
|
|
175
|
-
openFile(path: string, flag: string, cred: Cred): Promise<import("../file.js").File>;
|
|
176
|
-
openFileSync(path: string, flag: string, cred: Cred): import("../file.js").File;
|
|
177
|
-
readdir(path: string, cred: Cred): Promise<string[]>;
|
|
178
|
-
readdirSync(path: string, cred: Cred): string[];
|
|
179
|
-
exists(path: string, cred: Cred): Promise<boolean>;
|
|
180
|
-
existsSync(path: string, cred: Cred): boolean;
|
|
181
|
-
}) & typeof FileSystem;
|
|
182
|
-
export declare abstract class IndexFS<TData> extends IndexFS_base {
|
|
183
|
-
protected _index: FileIndex<TData>;
|
|
184
|
-
constructor(index: ListingTree);
|
|
185
|
-
stat(path: string): Promise<Stats>;
|
|
186
|
-
statSync(path: string): Stats;
|
|
187
|
-
openFile(path: string, flag: string, cred: Cred): Promise<NoSyncFile<this>>;
|
|
188
|
-
openFileSync(path: string, flag: string, cred: Cred): NoSyncFile<this>;
|
|
189
|
-
readdir(path: string): Promise<string[]>;
|
|
190
|
-
readdirSync(path: string): string[];
|
|
191
|
-
protected abstract statFileInode(inode: IndexFileInode<TData>, path: string): Promise<Stats>;
|
|
192
|
-
protected abstract statFileInodeSync(inode: IndexFileInode<TData>, path: string): Stats;
|
|
193
|
-
protected abstract openFileInode(inode: IndexFileInode<TData>, path: string, flag: string): Promise<NoSyncFile<this>>;
|
|
194
|
-
protected abstract openFileInodeSync(inode: IndexFileInode<TData>, path: string, flag: string): NoSyncFile<this>;
|
|
195
|
-
}
|
|
196
|
-
export declare abstract class SyncIndexFS<TData> extends IndexFS<TData> {
|
|
197
|
-
protected statFileInode(inode: IndexFileInode<TData>, path: string): Promise<Stats>;
|
|
198
|
-
protected openFileInode(inode: IndexFileInode<TData>, path: string, flag: string): Promise<NoSyncFile<this>>;
|
|
199
|
-
}
|
|
200
|
-
export declare abstract class AsyncIndexFS<TData> extends IndexFS<TData> {
|
|
201
|
-
protected statFileInodeSync(inode: IndexFileInode<TData>, path: string): Stats;
|
|
202
|
-
protected openFileInodeSync(inode: IndexFileInode<TData>, path: string, flag: string): NoSyncFile<this>;
|
|
203
|
-
}
|
|
204
|
-
export {};
|