@zenfs/core 0.9.7 → 0.11.0

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 (90) hide show
  1. package/dist/backends/Index.d.ts +3 -3
  2. package/dist/backends/Index.js +23 -23
  3. package/dist/backends/backend.js +6 -5
  4. package/dist/backends/fetch.d.ts +84 -0
  5. package/dist/backends/fetch.js +170 -0
  6. package/dist/backends/{Locked.d.ts → locked.d.ts} +13 -13
  7. package/dist/backends/{Locked.js → locked.js} +54 -54
  8. package/dist/backends/{InMemory.d.ts → memory.d.ts} +7 -9
  9. package/dist/backends/memory.js +38 -0
  10. package/dist/backends/{Overlay.d.ts → overlay.d.ts} +12 -13
  11. package/dist/backends/{Overlay.js → overlay.js} +105 -110
  12. package/dist/backends/port/fs.d.ts +123 -0
  13. package/dist/backends/port/fs.js +239 -0
  14. package/dist/backends/port/rpc.d.ts +60 -0
  15. package/dist/backends/port/rpc.js +71 -0
  16. package/dist/backends/store/fs.d.ts +169 -0
  17. package/dist/backends/store/fs.js +743 -0
  18. package/dist/backends/store/simple.d.ts +64 -0
  19. package/dist/backends/store/simple.js +111 -0
  20. package/dist/backends/store/store.d.ts +111 -0
  21. package/dist/backends/store/store.js +62 -0
  22. package/dist/browser.min.js +4 -4
  23. package/dist/browser.min.js.map +4 -4
  24. package/dist/config.d.ts +8 -10
  25. package/dist/config.js +11 -11
  26. package/dist/emulation/async.js +6 -6
  27. package/dist/emulation/dir.js +2 -2
  28. package/dist/emulation/index.d.ts +1 -1
  29. package/dist/emulation/index.js +1 -1
  30. package/dist/emulation/path.d.ts +3 -2
  31. package/dist/emulation/path.js +19 -45
  32. package/dist/emulation/promises.d.ts +7 -12
  33. package/dist/emulation/promises.js +144 -146
  34. package/dist/emulation/shared.d.ts +5 -10
  35. package/dist/emulation/shared.js +9 -9
  36. package/dist/emulation/streams.js +3 -3
  37. package/dist/emulation/sync.js +25 -25
  38. package/dist/{ApiError.d.ts → error.d.ts} +13 -15
  39. package/dist/error.js +291 -0
  40. package/dist/file.d.ts +2 -0
  41. package/dist/file.js +11 -5
  42. package/dist/filesystem.d.ts +3 -3
  43. package/dist/filesystem.js +41 -44
  44. package/dist/index.d.ts +7 -6
  45. package/dist/index.js +7 -6
  46. package/dist/inode.d.ts +1 -1
  47. package/dist/mutex.js +2 -1
  48. package/dist/utils.d.ts +8 -7
  49. package/dist/utils.js +11 -12
  50. package/package.json +3 -3
  51. package/readme.md +17 -9
  52. package/src/backends/Index.ts +23 -23
  53. package/src/backends/backend.ts +8 -7
  54. package/src/backends/fetch.ts +229 -0
  55. package/src/backends/{Locked.ts → locked.ts} +55 -55
  56. package/src/backends/memory.ts +44 -0
  57. package/src/backends/{Overlay.ts → overlay.ts} +108 -114
  58. package/src/backends/port/fs.ts +306 -0
  59. package/src/backends/port/readme.md +59 -0
  60. package/src/backends/port/rpc.ts +144 -0
  61. package/src/backends/store/fs.ts +881 -0
  62. package/src/backends/store/readme.md +9 -0
  63. package/src/backends/store/simple.ts +144 -0
  64. package/src/backends/store/store.ts +164 -0
  65. package/src/config.ts +21 -25
  66. package/src/emulation/async.ts +6 -6
  67. package/src/emulation/dir.ts +2 -2
  68. package/src/emulation/index.ts +1 -1
  69. package/src/emulation/path.ts +25 -49
  70. package/src/emulation/promises.ts +150 -159
  71. package/src/emulation/shared.ts +13 -15
  72. package/src/emulation/streams.ts +3 -3
  73. package/src/emulation/sync.ts +28 -28
  74. package/src/{ApiError.ts → error.ts} +89 -90
  75. package/src/file.ts +13 -5
  76. package/src/filesystem.ts +44 -47
  77. package/src/index.ts +7 -6
  78. package/src/inode.ts +1 -1
  79. package/src/mutex.ts +3 -1
  80. package/src/utils.ts +16 -18
  81. package/tsconfig.json +2 -2
  82. package/dist/ApiError.js +0 -292
  83. package/dist/backends/AsyncStore.d.ts +0 -204
  84. package/dist/backends/AsyncStore.js +0 -509
  85. package/dist/backends/InMemory.js +0 -49
  86. package/dist/backends/SyncStore.d.ts +0 -213
  87. package/dist/backends/SyncStore.js +0 -445
  88. package/src/backends/AsyncStore.ts +0 -655
  89. package/src/backends/InMemory.ts +0 -56
  90. package/src/backends/SyncStore.ts +0 -589
@@ -1,3 +1,4 @@
1
+ import { ErrnoError } from '../error.js';
1
2
  import { Mutex } from '../mutex.js';
2
3
  /**
3
4
  * This class serializes access to an underlying async filesystem.
@@ -16,7 +17,6 @@ export class LockedFS {
16
17
  }
17
18
  async ready() {
18
19
  await this.fs.ready();
19
- return this;
20
20
  }
21
21
  metadata() {
22
22
  return {
@@ -31,21 +31,21 @@ export class LockedFS {
31
31
  }
32
32
  renameSync(oldPath, newPath, cred) {
33
33
  if (this._mu.isLocked(oldPath)) {
34
- throw new Error('invalid sync call');
34
+ throw ErrnoError.With('EBUSY', oldPath, 'rename');
35
35
  }
36
36
  return this.fs.renameSync(oldPath, newPath, cred);
37
37
  }
38
- async stat(p, cred) {
39
- await this._mu.lock(p);
40
- const stats = await this.fs.stat(p, cred);
41
- this._mu.unlock(p);
38
+ async stat(path, cred) {
39
+ await this._mu.lock(path);
40
+ const stats = await this.fs.stat(path, cred);
41
+ this._mu.unlock(path);
42
42
  return stats;
43
43
  }
44
- statSync(p, cred) {
45
- if (this._mu.isLocked(p)) {
46
- throw new Error('invalid sync call');
44
+ statSync(path, cred) {
45
+ if (this._mu.isLocked(path)) {
46
+ throw ErrnoError.With('EBUSY', path, 'stat');
47
47
  }
48
- return this.fs.statSync(p, cred);
48
+ return this.fs.statSync(path, cred);
49
49
  }
50
50
  async openFile(path, flag, cred) {
51
51
  await this._mu.lock(path);
@@ -55,7 +55,7 @@ export class LockedFS {
55
55
  }
56
56
  openFileSync(path, flag, cred) {
57
57
  if (this._mu.isLocked(path)) {
58
- throw new Error('invalid sync call');
58
+ throw ErrnoError.With('EBUSY', path, 'openFile');
59
59
  }
60
60
  return this.fs.openFileSync(path, flag, cred);
61
61
  }
@@ -67,66 +67,66 @@ export class LockedFS {
67
67
  }
68
68
  createFileSync(path, flag, mode, cred) {
69
69
  if (this._mu.isLocked(path)) {
70
- throw new Error('invalid sync call');
70
+ throw ErrnoError.With('EBUSY', path, 'createFile');
71
71
  }
72
72
  return this.fs.createFileSync(path, flag, mode, cred);
73
73
  }
74
- async unlink(p, cred) {
75
- await this._mu.lock(p);
76
- await this.fs.unlink(p, cred);
77
- 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);
78
78
  }
79
- unlinkSync(p, cred) {
80
- if (this._mu.isLocked(p)) {
81
- throw new Error('invalid sync call');
79
+ unlinkSync(path, cred) {
80
+ if (this._mu.isLocked(path)) {
81
+ throw ErrnoError.With('EBUSY', path, 'unlink');
82
82
  }
83
- return this.fs.unlinkSync(p, cred);
83
+ return this.fs.unlinkSync(path, cred);
84
84
  }
85
- async rmdir(p, cred) {
86
- await this._mu.lock(p);
87
- await this.fs.rmdir(p, cred);
88
- this._mu.unlock(p);
85
+ async rmdir(path, cred) {
86
+ await this._mu.lock(path);
87
+ await this.fs.rmdir(path, cred);
88
+ this._mu.unlock(path);
89
89
  }
90
- rmdirSync(p, cred) {
91
- if (this._mu.isLocked(p)) {
92
- throw new Error('invalid sync call');
90
+ rmdirSync(path, cred) {
91
+ if (this._mu.isLocked(path)) {
92
+ throw ErrnoError.With('EBUSY', path, 'rmdir');
93
93
  }
94
- return this.fs.rmdirSync(p, cred);
94
+ return this.fs.rmdirSync(path, cred);
95
95
  }
96
- async mkdir(p, mode, cred) {
97
- await this._mu.lock(p);
98
- await this.fs.mkdir(p, mode, cred);
99
- this._mu.unlock(p);
96
+ async mkdir(path, mode, cred) {
97
+ await this._mu.lock(path);
98
+ await this.fs.mkdir(path, mode, cred);
99
+ this._mu.unlock(path);
100
100
  }
101
- mkdirSync(p, mode, cred) {
102
- if (this._mu.isLocked(p)) {
103
- throw new Error('invalid sync call');
101
+ mkdirSync(path, mode, cred) {
102
+ if (this._mu.isLocked(path)) {
103
+ throw ErrnoError.With('EBUSY', path, 'mkdir');
104
104
  }
105
- return this.fs.mkdirSync(p, mode, cred);
105
+ return this.fs.mkdirSync(path, mode, cred);
106
106
  }
107
- async readdir(p, cred) {
108
- await this._mu.lock(p);
109
- const files = await this.fs.readdir(p, cred);
110
- this._mu.unlock(p);
107
+ async readdir(path, cred) {
108
+ await this._mu.lock(path);
109
+ const files = await this.fs.readdir(path, cred);
110
+ this._mu.unlock(path);
111
111
  return files;
112
112
  }
113
- readdirSync(p, cred) {
114
- if (this._mu.isLocked(p)) {
115
- throw new Error('invalid sync call');
113
+ readdirSync(path, cred) {
114
+ if (this._mu.isLocked(path)) {
115
+ throw ErrnoError.With('EBUSY', path, 'readdir');
116
116
  }
117
- return this.fs.readdirSync(p, cred);
117
+ return this.fs.readdirSync(path, cred);
118
118
  }
119
- async exists(p, cred) {
120
- await this._mu.lock(p);
121
- const exists = await this.fs.exists(p, cred);
122
- this._mu.unlock(p);
119
+ async exists(path, cred) {
120
+ await this._mu.lock(path);
121
+ const exists = await this.fs.exists(path, cred);
122
+ this._mu.unlock(path);
123
123
  return exists;
124
124
  }
125
- existsSync(p, cred) {
126
- if (this._mu.isLocked(p)) {
127
- throw new Error('invalid sync call');
125
+ existsSync(path, cred) {
126
+ if (this._mu.isLocked(path)) {
127
+ throw ErrnoError.With('EBUSY', path, 'exists');
128
128
  }
129
- return this.fs.existsSync(p, cred);
129
+ return this.fs.existsSync(path, cred);
130
130
  }
131
131
  async link(srcpath, dstpath, cred) {
132
132
  await this._mu.lock(srcpath);
@@ -135,7 +135,7 @@ export class LockedFS {
135
135
  }
136
136
  linkSync(srcpath, dstpath, cred) {
137
137
  if (this._mu.isLocked(srcpath)) {
138
- throw new Error('invalid sync call');
138
+ throw ErrnoError.With('EBUSY', srcpath, 'link');
139
139
  }
140
140
  return this.fs.linkSync(srcpath, dstpath, cred);
141
141
  }
@@ -146,7 +146,7 @@ export class LockedFS {
146
146
  }
147
147
  syncSync(path, data, stats) {
148
148
  if (this._mu.isLocked(path)) {
149
- throw new Error('invalid sync call');
149
+ throw ErrnoError.With('EBUSY', path, 'sync');
150
150
  }
151
151
  return this.fs.syncSync(path, data, stats);
152
152
  }
@@ -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
  */