@zenfs/core 0.10.0 → 0.11.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.
Files changed (63) hide show
  1. package/dist/backends/Index.d.ts +3 -3
  2. package/dist/backends/Index.js +4 -4
  3. package/dist/backends/backend.d.ts +1 -2
  4. package/dist/backends/backend.js +0 -5
  5. package/dist/backends/{Fetch.d.ts → fetch.d.ts} +4 -4
  6. package/dist/backends/{Fetch.js → fetch.js} +6 -7
  7. package/dist/backends/{Locked.d.ts → locked.d.ts} +2 -2
  8. package/dist/backends/{Locked.js → locked.js} +4 -5
  9. package/dist/backends/{InMemory.d.ts → memory.d.ts} +7 -9
  10. package/dist/backends/memory.js +38 -0
  11. package/dist/backends/{Overlay.d.ts → overlay.d.ts} +12 -13
  12. package/dist/backends/{Overlay.js → overlay.js} +98 -103
  13. package/dist/backends/port/fs.d.ts +15 -16
  14. package/dist/backends/port/fs.js +20 -22
  15. package/dist/backends/store/fs.d.ts +169 -0
  16. package/dist/backends/store/fs.js +743 -0
  17. package/dist/backends/store/simple.d.ts +64 -0
  18. package/dist/backends/store/simple.js +111 -0
  19. package/dist/backends/store/store.d.ts +111 -0
  20. package/dist/backends/store/store.js +62 -0
  21. package/dist/browser.min.js +4 -4
  22. package/dist/browser.min.js.map +4 -4
  23. package/dist/config.d.ts +1 -1
  24. package/dist/config.js +1 -1
  25. package/dist/emulation/shared.js +1 -1
  26. package/dist/error.d.ts +0 -1
  27. package/dist/error.js +0 -1
  28. package/dist/file.js +1 -1
  29. package/dist/filesystem.d.ts +3 -3
  30. package/dist/filesystem.js +26 -29
  31. package/dist/index.d.ts +7 -7
  32. package/dist/index.js +7 -7
  33. package/dist/inode.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/backends/Index.ts +4 -4
  36. package/src/backends/backend.ts +3 -7
  37. package/src/backends/{Fetch.ts → fetch.ts} +13 -14
  38. package/src/backends/{Locked.ts → locked.ts} +5 -6
  39. package/src/backends/memory.ts +44 -0
  40. package/src/backends/{Overlay.ts → overlay.ts} +99 -105
  41. package/src/backends/port/fs.ts +24 -26
  42. package/src/backends/store/fs.ts +881 -0
  43. package/src/backends/store/readme.md +9 -0
  44. package/src/backends/store/simple.ts +144 -0
  45. package/src/backends/store/store.ts +164 -0
  46. package/src/config.ts +3 -3
  47. package/src/emulation/shared.ts +1 -1
  48. package/src/error.ts +0 -1
  49. package/src/file.ts +1 -1
  50. package/src/filesystem.ts +29 -32
  51. package/src/index.ts +7 -7
  52. package/src/inode.ts +1 -1
  53. package/dist/backends/AsyncStore.d.ts +0 -204
  54. package/dist/backends/AsyncStore.js +0 -509
  55. package/dist/backends/InMemory.js +0 -49
  56. package/dist/backends/SyncStore.d.ts +0 -213
  57. package/dist/backends/SyncStore.js +0 -445
  58. package/dist/backends/port/store.d.ts +0 -30
  59. package/dist/backends/port/store.js +0 -142
  60. package/src/backends/AsyncStore.ts +0 -655
  61. package/src/backends/InMemory.ts +0 -56
  62. package/src/backends/SyncStore.ts +0 -589
  63. package/src/backends/port/store.ts +0 -187
@@ -147,11 +147,11 @@ export declare class IndexDirInode<TData> extends IndexInode<TData> {
147
147
  add(path: string, inode: IndexInode<TData>): boolean;
148
148
  /**
149
149
  * Removes the given item from the directory listing.
150
- * @param p Name of item to remove from the directory listing.
150
+ * @param path Name of item to remove from the directory listing.
151
151
  * @return Returns the item
152
152
  * removed, or null if the item did not exist.
153
153
  */
154
- remove(p: string): IndexInode<TData> | void;
154
+ remove(path: string): IndexInode<TData> | void;
155
155
  }
156
156
  declare const IndexFS_base: (abstract new (...args: any[]) => {
157
157
  metadata(): import("../filesystem.js").FileSystemMetadata;
@@ -169,7 +169,7 @@ declare const IndexFS_base: (abstract new (...args: any[]) => {
169
169
  linkSync(srcpath: string, dstpath: string, cred: Cred): void;
170
170
  sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
171
171
  syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
172
- ready(): Promise<any>;
172
+ ready(): Promise<void>;
173
173
  stat(path: string, cred: Cred): Promise<Stats>;
174
174
  statSync(path: string, cred: Cred): Stats;
175
175
  openFile(path: string, flag: string, cred: Cred): Promise<import("../file.js").File>;
@@ -287,16 +287,16 @@ export class IndexDirInode extends IndexInode {
287
287
  }
288
288
  /**
289
289
  * Removes the given item from the directory listing.
290
- * @param p Name of item to remove from the directory listing.
290
+ * @param path Name of item to remove from the directory listing.
291
291
  * @return Returns the item
292
292
  * removed, or null if the item did not exist.
293
293
  */
294
- remove(p) {
295
- const item = this._listing.get(p);
294
+ remove(path) {
295
+ const item = this._listing.get(path);
296
296
  if (!item) {
297
297
  return;
298
298
  }
299
- this._listing.delete(p);
299
+ this._listing.delete(path);
300
300
  return item;
301
301
  }
302
302
  }
@@ -33,7 +33,7 @@ export interface Backend<FS extends FileSystem = FileSystem, TOptions extends ob
33
33
  /**
34
34
  * Create a new instance of the backend
35
35
  */
36
- create(options: TOptions): FS;
36
+ create(options: TOptions): FS | Promise<FS>;
37
37
  /**
38
38
  * A name to identify the backend.
39
39
  */
@@ -64,7 +64,6 @@ export declare function isBackend(arg: unknown): arg is Backend;
64
64
  * @internal
65
65
  */
66
66
  export declare function checkOptions<T extends Backend>(backend: T, opts: Partial<OptionsOf<T>> & Record<string, unknown>): Promise<void>;
67
- export declare function createBackend<B extends Backend>(backend: B, options?: Partial<OptionsOf<B>>): Promise<ReturnType<B['create']>>;
68
67
  /**
69
68
  * Specifies a file system backend type and its options.
70
69
  *
@@ -44,11 +44,6 @@ export async function checkOptions(backend, opts) {
44
44
  // Otherwise: All good!
45
45
  }
46
46
  }
47
- export async function createBackend(backend, options = {}) {
48
- await checkOptions(backend, options);
49
- const fs = backend.create(options);
50
- return fs.ready();
51
- }
52
47
  /**
53
48
  * @internal
54
49
  */
@@ -41,7 +41,7 @@ export declare class FetchFS extends AsyncIndexFS<Stats> {
41
41
  readonly prefixUrl: string;
42
42
  protected _init: Promise<void>;
43
43
  protected _initialize(index: string | ListingTree): Promise<void>;
44
- ready(): Promise<this>;
44
+ ready(): Promise<void>;
45
45
  constructor({ index, baseUrl }: FetchOptions);
46
46
  metadata(): FileSystemMetadata;
47
47
  empty(): void;
@@ -57,9 +57,9 @@ export declare class FetchFS extends AsyncIndexFS<Stats> {
57
57
  /**
58
58
  * Asynchronously download the given file.
59
59
  */
60
- protected _fetchFile(p: string, type: 'buffer'): Promise<Uint8Array>;
61
- protected _fetchFile(p: string, type: 'json'): Promise<object>;
62
- protected _fetchFile(p: string, type: 'buffer' | 'json'): Promise<object>;
60
+ protected _fetchFile(path: string, type: 'buffer'): Promise<Uint8Array>;
61
+ protected _fetchFile(path: string, type: 'json'): Promise<object>;
62
+ protected _fetchFile(path: string, type: 'buffer' | 'json'): Promise<object>;
63
63
  /**
64
64
  * Only requests the HEAD content, for the file size.
65
65
  */
@@ -8,8 +8,8 @@ import { FileIndex, AsyncIndexFS } from './Index.js';
8
8
  function convertError(e) {
9
9
  throw new ErrnoError(Errno.EIO, e.message);
10
10
  }
11
- async function fetchFile(p, type) {
12
- const response = await fetch(p).catch(convertError);
11
+ async function fetchFile(path, type) {
12
+ const response = await fetch(path).catch(convertError);
13
13
  if (!response.ok) {
14
14
  throw new ErrnoError(Errno.EIO, 'fetch failed: response returned code ' + response.status);
15
15
  }
@@ -27,8 +27,8 @@ async function fetchFile(p, type) {
27
27
  * Asynchronously retrieves the size of the given file in bytes.
28
28
  * @hidden
29
29
  */
30
- async function fetchSize(p) {
31
- const response = await fetch(p, { method: 'HEAD' }).catch(convertError);
30
+ async function fetchSize(path) {
31
+ const response = await fetch(path, { method: 'HEAD' }).catch(convertError);
32
32
  if (!response.ok) {
33
33
  throw new ErrnoError(Errno.EIO, 'fetch failed: HEAD response returned code ' + response.status);
34
34
  }
@@ -71,7 +71,6 @@ export class FetchFS extends AsyncIndexFS {
71
71
  }
72
72
  async ready() {
73
73
  await this._init;
74
- return this;
75
74
  }
76
75
  constructor({ index = 'index.json', baseUrl = '' }) {
77
76
  super({});
@@ -138,8 +137,8 @@ export class FetchFS extends AsyncIndexFS {
138
137
  }
139
138
  return this.prefixUrl + filePath;
140
139
  }
141
- _fetchFile(p, type) {
142
- return fetchFile(this._getRemotePath(p), type);
140
+ _fetchFile(path, type) {
141
+ return fetchFile(this._getRemotePath(path), type);
143
142
  }
144
143
  /**
145
144
  * Only requests the HEAD content, for the file size.
@@ -16,7 +16,7 @@ export declare class LockedFS<FS extends FileSystem> implements FileSystem {
16
16
  readonly fs: FS;
17
17
  private _mu;
18
18
  constructor(fs: FS);
19
- ready(): Promise<this>;
19
+ ready(): Promise<void>;
20
20
  metadata(): FileSystemMetadata;
21
21
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
22
22
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
@@ -26,7 +26,7 @@ export declare class LockedFS<FS extends FileSystem> implements FileSystem {
26
26
  openFileSync(path: string, flag: string, cred: Cred): File;
27
27
  createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
28
28
  createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
29
- unlink(p: string, cred: Cred): Promise<void>;
29
+ unlink(path: string, cred: Cred): Promise<void>;
30
30
  unlinkSync(path: string, cred: Cred): void;
31
31
  rmdir(path: string, cred: Cred): Promise<void>;
32
32
  rmdirSync(path: string, cred: Cred): void;
@@ -17,7 +17,6 @@ export class LockedFS {
17
17
  }
18
18
  async ready() {
19
19
  await this.fs.ready();
20
- return this;
21
20
  }
22
21
  metadata() {
23
22
  return {
@@ -72,10 +71,10 @@ export class LockedFS {
72
71
  }
73
72
  return this.fs.createFileSync(path, flag, mode, cred);
74
73
  }
75
- async unlink(p, cred) {
76
- await this._mu.lock(p);
77
- await this.fs.unlink(p, cred);
78
- this._mu.unlock(p);
74
+ async unlink(path, cred) {
75
+ await this._mu.lock(path);
76
+ await this.fs.unlink(path, cred);
77
+ this._mu.unlock(path);
79
78
  }
80
79
  unlinkSync(path, cred) {
81
80
  if (this._mu.isLocked(path)) {
@@ -1,17 +1,15 @@
1
1
  import type { Ino } from '../inode.js';
2
- import { SimpleSyncStore, SyncStore, SyncStoreFS, SyncTransaction } from './SyncStore.js';
2
+ import { StoreFS } from './store/fs.js';
3
+ import { SimpleTransaction, type SimpleSyncStore } from './store/simple.js';
3
4
  /**
4
5
  * A simple in-memory store
5
6
  */
6
- export declare class InMemoryStore implements SyncStore, SimpleSyncStore {
7
+ export declare class InMemoryStore extends Map<Ino, Uint8Array> implements SimpleSyncStore {
7
8
  name: string;
8
- private store;
9
9
  constructor(name?: string);
10
- clear(): void;
11
- beginTransaction(): SyncTransaction;
12
- get(key: Ino): Uint8Array | undefined;
13
- put(key: Ino, data: Uint8Array, overwrite: boolean): boolean;
14
- remove(key: Ino): void;
10
+ sync(): Promise<void>;
11
+ clearSync(): void;
12
+ transaction(): SimpleTransaction;
15
13
  }
16
14
  /**
17
15
  * A simple in-memory file system backed by an InMemoryStore.
@@ -29,5 +27,5 @@ export declare const InMemory: {
29
27
  };
30
28
  readonly create: ({ name }: {
31
29
  name?: string;
32
- }) => SyncStoreFS;
30
+ }) => StoreFS;
33
31
  };
@@ -0,0 +1,38 @@
1
+ import { StoreFS } from './store/fs.js';
2
+ import { SimpleTransaction } from './store/simple.js';
3
+ /**
4
+ * A simple in-memory store
5
+ */
6
+ export class InMemoryStore extends Map {
7
+ constructor(name = 'tmp') {
8
+ super();
9
+ this.name = name;
10
+ }
11
+ async sync() { }
12
+ clearSync() {
13
+ this.clear();
14
+ }
15
+ transaction() {
16
+ return new SimpleTransaction(this);
17
+ }
18
+ }
19
+ /**
20
+ * A simple in-memory file system backed by an InMemoryStore.
21
+ * Files are not persisted across page loads.
22
+ */
23
+ export const InMemory = {
24
+ name: 'InMemory',
25
+ isAvailable() {
26
+ return true;
27
+ },
28
+ options: {
29
+ name: {
30
+ type: 'string',
31
+ required: false,
32
+ description: 'The name of the store',
33
+ },
34
+ },
35
+ create({ name }) {
36
+ return new StoreFS(new InMemoryStore(name));
37
+ },
38
+ };
@@ -1,7 +1,7 @@
1
1
  import { FileSystem, FileSystemMetadata } from '../filesystem.js';
2
2
  import { File } from '../file.js';
3
3
  import { Stats } from '../stats.js';
4
- import { LockedFS } from './Locked.js';
4
+ import { LockedFS } from './locked.js';
5
5
  import { Cred } from '../cred.js';
6
6
  /**
7
7
  * Configuration options for OverlayFS instances.
@@ -25,7 +25,7 @@ export interface OverlayOptions {
25
25
  * @internal
26
26
  */
27
27
  export declare class UnlockedOverlayFS extends FileSystem {
28
- ready(): Promise<this>;
28
+ ready(): Promise<void>;
29
29
  private _writable;
30
30
  private _readable;
31
31
  private _isInitialized;
@@ -49,22 +49,22 @@ export declare class UnlockedOverlayFS extends FileSystem {
49
49
  restoreDeletionLog(log: string, cred: Cred): void;
50
50
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
51
51
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
52
- stat(p: string, cred: Cred): Promise<Stats>;
53
- statSync(p: string, cred: Cred): Stats;
52
+ stat(path: string, cred: Cred): Promise<Stats>;
53
+ statSync(path: string, cred: Cred): Stats;
54
54
  openFile(path: string, flag: string, cred: Cred): Promise<File>;
55
55
  openFileSync(path: string, flag: string, cred: Cred): File;
56
56
  createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File>;
57
57
  createFileSync(path: string, flag: string, mode: number, cred: Cred): File;
58
58
  link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
59
59
  linkSync(srcpath: string, dstpath: string, cred: Cred): void;
60
- unlink(p: string, cred: Cred): Promise<void>;
61
- unlinkSync(p: string, cred: Cred): void;
62
- rmdir(p: string, cred: Cred): Promise<void>;
63
- rmdirSync(p: string, cred: Cred): void;
64
- mkdir(p: string, mode: number, cred: Cred): Promise<void>;
65
- mkdirSync(p: string, mode: number, cred: Cred): void;
66
- readdir(p: string, cred: Cred): Promise<string[]>;
67
- readdirSync(p: string, cred: Cred): string[];
60
+ unlink(path: string, cred: Cred): Promise<void>;
61
+ unlinkSync(path: string, cred: Cred): void;
62
+ rmdir(path: string, cred: Cred): Promise<void>;
63
+ rmdirSync(path: string, cred: Cred): void;
64
+ mkdir(path: string, mode: number, cred: Cred): Promise<void>;
65
+ mkdirSync(path: string, mode: number, cred: Cred): void;
66
+ readdir(path: string, cred: Cred): Promise<string[]>;
67
+ readdirSync(path: string, cred: Cred): string[];
68
68
  private deletePath;
69
69
  private updateLog;
70
70
  private _reparseDeletionLog;
@@ -97,7 +97,6 @@ export declare class UnlockedOverlayFS extends FileSystem {
97
97
  * @internal
98
98
  */
99
99
  export declare class OverlayFS extends LockedFS<UnlockedOverlayFS> {
100
- ready(): Promise<this>;
101
100
  /**
102
101
  * @param options The options to initialize the OverlayFS with
103
102
  */