@zenfs/core 0.1.0 → 0.2.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 (44) hide show
  1. package/dist/ApiError.d.ts +51 -14
  2. package/dist/ApiError.js +60 -34
  3. package/dist/FileIndex.d.ts +32 -35
  4. package/dist/FileIndex.js +93 -109
  5. package/dist/backends/AsyncMirror.d.ts +42 -43
  6. package/dist/backends/AsyncMirror.js +146 -133
  7. package/dist/backends/AsyncStore.d.ts +29 -28
  8. package/dist/backends/AsyncStore.js +139 -189
  9. package/dist/backends/InMemory.d.ts +16 -13
  10. package/dist/backends/InMemory.js +29 -14
  11. package/dist/backends/Locked.d.ts +8 -28
  12. package/dist/backends/Locked.js +44 -148
  13. package/dist/backends/OverlayFS.d.ts +26 -34
  14. package/dist/backends/OverlayFS.js +208 -371
  15. package/dist/backends/SyncStore.d.ts +54 -72
  16. package/dist/backends/SyncStore.js +159 -161
  17. package/dist/backends/backend.d.ts +45 -29
  18. package/dist/backends/backend.js +83 -13
  19. package/dist/backends/index.d.ts +6 -7
  20. package/dist/backends/index.js +5 -6
  21. package/dist/browser.min.js +5 -7
  22. package/dist/browser.min.js.map +4 -4
  23. package/dist/emulation/callbacks.d.ts +36 -67
  24. package/dist/emulation/callbacks.js +90 -46
  25. package/dist/emulation/constants.js +1 -1
  26. package/dist/emulation/promises.d.ts +228 -129
  27. package/dist/emulation/promises.js +414 -172
  28. package/dist/emulation/shared.d.ts +10 -10
  29. package/dist/emulation/shared.js +18 -20
  30. package/dist/emulation/sync.d.ts +25 -25
  31. package/dist/emulation/sync.js +187 -73
  32. package/dist/file.d.ts +166 -170
  33. package/dist/file.js +199 -218
  34. package/dist/filesystem.d.ts +68 -241
  35. package/dist/filesystem.js +59 -383
  36. package/dist/index.d.ts +7 -44
  37. package/dist/index.js +13 -52
  38. package/dist/inode.d.ts +37 -28
  39. package/dist/inode.js +123 -65
  40. package/dist/stats.d.ts +21 -19
  41. package/dist/stats.js +35 -56
  42. package/dist/utils.d.ts +26 -9
  43. package/dist/utils.js +73 -102
  44. package/package.json +4 -3
@@ -26,10 +26,6 @@ export interface FileSystemMetadata {
26
26
  * Does the FS support properties
27
27
  */
28
28
  supportsProperties: boolean;
29
- /**
30
- * Does the FS support links
31
- */
32
- supportsLinks: boolean;
33
29
  /**
34
30
  * The total space
35
31
  */
@@ -40,31 +36,20 @@ export interface FileSystemMetadata {
40
36
  freeSpace: number;
41
37
  }
42
38
  /**
43
- * Structure for a filesystem. **All** ZenFS FileSystems must implement
44
- * this.
39
+ * Structure for a filesystem. All ZenFS FileSystems must implement this.
45
40
  *
46
- * ### Argument Assumptions
41
+ * This class includes some default implementations
47
42
  *
48
- * You can assume the following about arguments passed to each API method:
43
+ * Assume the following about arguments passed to each API method:
49
44
  *
50
- * - Every path is an absolute path. `.`, `..`, and other items
51
- * are resolved into an absolute form.
52
- * - All arguments are present. Any optional arguments at the Node API level
53
- * have been passed in with their default values.
45
+ * - Every path is an absolute path. `.`, `..`, and other items are resolved into an absolute form.
46
+ * - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
54
47
  */
55
48
  export declare abstract class FileSystem {
56
- static readonly Name: string;
57
- abstract readonly metadata: FileSystemMetadata;
49
+ static get Name(): string;
50
+ get metadata(): FileSystemMetadata;
58
51
  constructor(options?: object);
59
- abstract whenReady(): Promise<this>;
60
- /**
61
- * Asynchronous access.
62
- */
63
- abstract access(p: string, mode: number, cred: Cred): Promise<void>;
64
- /**
65
- * Synchronous access.
66
- */
67
- abstract accessSync(p: string, mode: number, cred: Cred): void;
52
+ abstract ready(): Promise<this>;
68
53
  /**
69
54
  * Asynchronous rename. No arguments other than a possible exception
70
55
  * are given to the completion callback.
@@ -77,163 +62,81 @@ export declare abstract class FileSystem {
77
62
  /**
78
63
  * Asynchronous `stat`.
79
64
  */
80
- abstract stat(p: string, cred: Cred): Promise<Stats>;
65
+ abstract stat(path: string, cred: Cred): Promise<Stats>;
81
66
  /**
82
67
  * Synchronous `stat`.
83
68
  */
84
- abstract statSync(p: string, cred: Cred): Stats;
69
+ abstract statSync(path: string, cred: Cred): Stats;
85
70
  /**
86
- * Asynchronous file open.
87
- * @see http://www.manpagez.com/man/2/open/
88
- * @param flags Handles the complexity of the various file
89
- * modes. See its API for more details.
90
- * @param mode Mode to use to open the file. Can be ignored if the
91
- * filesystem doesn't support permissions.
71
+ * Opens the file at path p with the given flag. The file must exist.
72
+ * @param p The path to open.
73
+ * @param flag The flag to use when opening the file.
92
74
  */
93
- abstract open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
75
+ abstract openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
94
76
  /**
95
- * Synchronous file open.
96
- * @see http://www.manpagez.com/man/2/open/
97
- * @param flags Handles the complexity of the various file
98
- * modes. See its API for more details.
99
- * @param mode Mode to use to open the file. Can be ignored if the
100
- * filesystem doesn't support permissions.
77
+ * Opens the file at path p with the given flag. The file must exist.
78
+ * @param p The path to open.
79
+ * @param flag The flag to use when opening the file.
80
+ * @return A File object corresponding to the opened file.
81
+ */
82
+ abstract openFileSync(path: string, flag: FileFlag, cred: Cred): File;
83
+ /**
84
+ * Create the file at path p with the given mode. Then, open it with the given
85
+ * flag.
101
86
  */
102
- abstract openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;
87
+ abstract createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
88
+ /**
89
+ * Create the file at path p with the given mode. Then, open it with the given
90
+ * flag.
91
+ */
92
+ abstract createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
103
93
  /**
104
94
  * Asynchronous `unlink`.
105
95
  */
106
- abstract unlink(p: string, cred: Cred): Promise<void>;
96
+ abstract unlink(path: string, cred: Cred): Promise<void>;
107
97
  /**
108
98
  * Synchronous `unlink`.
109
99
  */
110
- abstract unlinkSync(p: string, cred: Cred): void;
100
+ abstract unlinkSync(path: string, cred: Cred): void;
111
101
  /**
112
102
  * Asynchronous `rmdir`.
113
103
  */
114
- abstract rmdir(p: string, cred: Cred): Promise<void>;
104
+ abstract rmdir(path: string, cred: Cred): Promise<void>;
115
105
  /**
116
106
  * Synchronous `rmdir`.
117
107
  */
118
- abstract rmdirSync(p: string, cred: Cred): void;
108
+ abstract rmdirSync(path: string, cred: Cred): void;
119
109
  /**
120
110
  * Asynchronous `mkdir`.
121
111
  * @param mode Mode to make the directory using. Can be ignored if
122
112
  * the filesystem doesn't support permissions.
123
113
  */
124
- abstract mkdir(p: string, mode: number, cred: Cred): Promise<void>;
114
+ abstract mkdir(path: string, mode: number, cred: Cred): Promise<void>;
125
115
  /**
126
116
  * Synchronous `mkdir`.
127
117
  * @param mode Mode to make the directory using. Can be ignored if
128
118
  * the filesystem doesn't support permissions.
129
119
  */
130
- abstract mkdirSync(p: string, mode: number, cred: Cred): void;
120
+ abstract mkdirSync(path: string, mode: number, cred: Cred): void;
131
121
  /**
132
122
  * Asynchronous `readdir`. Reads the contents of a directory.
133
123
  *
134
124
  * The callback gets two arguments `(err, files)` where `files` is an array of
135
125
  * the names of the files in the directory excluding `'.'` and `'..'`.
136
126
  */
137
- abstract readdir(p: string, cred: Cred): Promise<string[]>;
127
+ abstract readdir(path: string, cred: Cred): Promise<string[]>;
138
128
  /**
139
129
  * Synchronous `readdir`. Reads the contents of a directory.
140
130
  */
141
- abstract readdirSync(p: string, cred: Cred): string[];
142
- /**
143
- * Test whether or not the given path exists by checking with
144
- * the file system. Then call the callback argument with either true or false.
145
- */
146
- abstract exists(p: string, cred: Cred): Promise<boolean>;
147
- /**
148
- * Test whether or not the given path exists by checking with
149
- * the file system.
150
- */
151
- abstract existsSync(p: string, cred: Cred): boolean;
152
- /**
153
- * Asynchronous `realpath`. The callback gets two arguments
154
- * `(err, resolvedPath)`.
155
- *
156
- * Note that the Node API will resolve `path` to an absolute path.
157
- * @param cache An object literal of mapped paths that can be used to
158
- * force a specific path resolution or avoid additional `fs.stat` calls for
159
- * known real paths. If not supplied by the user, it'll be an empty object.
160
- */
161
- abstract realpath(p: string, cred: Cred): Promise<string>;
162
- /**
163
- * Synchronous `realpath`.
164
- *
165
- * Note that the Node API will resolve `path` to an absolute path.
166
- * @param cache An object literal of mapped paths that can be used to
167
- * force a specific path resolution or avoid additional `fs.stat` calls for
168
- * known real paths. If not supplied by the user, it'll be an empty object.
169
- */
170
- abstract realpathSync(p: string, cred: Cred): string;
171
- /**
172
- * Asynchronous `truncate`.
173
- */
174
- abstract truncate(p: string, len: number, cred: Cred): Promise<void>;
175
- /**
176
- * Synchronous `truncate`.
177
- */
178
- abstract truncateSync(p: string, len: number, cred: Cred): void;
179
- /**
180
- * Asynchronously reads the entire contents of a file.
181
- */
182
- abstract readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
183
- /**
184
- * Synchronously reads the entire contents of a file.
185
- */
186
- abstract readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
187
- /**
188
- * Asynchronously writes data to a file, replacing the file
189
- * if it already exists.
190
- *
191
- * The encoding option is ignored if data is a buffer.
192
- */
193
- abstract writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
194
- /**
195
- * Synchronously writes data to a file, replacing the file
196
- * if it already exists.
197
- *
198
- * The encoding option is ignored if data is a buffer.
199
- */
200
- abstract writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
131
+ abstract readdirSync(path: string, cred: Cred): string[];
201
132
  /**
202
- * Asynchronously append data to a file, creating the file if
203
- * it not yet exists.
133
+ * Test whether or not the given path exists by checking with the file system.
204
134
  */
205
- abstract appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
135
+ exists(path: string, cred: Cred): Promise<boolean>;
206
136
  /**
207
- * Synchronously append data to a file, creating the file if
208
- * it not yet exists.
137
+ * Test whether or not the given path exists by checking with the file system.
209
138
  */
210
- abstract appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
211
- /**
212
- * Asynchronous `chmod`.
213
- */
214
- abstract chmod(p: string, mode: number, cred: Cred): Promise<void>;
215
- /**
216
- * Synchronous `chmod`.
217
- */
218
- abstract chmodSync(p: string, mode: number, cred: Cred): void;
219
- /**
220
- * Asynchronous `chown`.
221
- */
222
- abstract chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;
223
- /**
224
- * Synchronous `chown`.
225
- */
226
- abstract chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void;
227
- /**
228
- * Change file timestamps of the file referenced by the supplied
229
- * path.
230
- */
231
- abstract utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;
232
- /**
233
- * Change file timestamps of the file referenced by the supplied
234
- * path.
235
- */
236
- abstract utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void;
139
+ existsSync(path: string, cred: Cred): boolean;
237
140
  /**
238
141
  * Asynchronous `link`.
239
142
  */
@@ -243,117 +146,41 @@ export declare abstract class FileSystem {
243
146
  */
244
147
  abstract linkSync(srcpath: string, dstpath: string, cred: Cred): void;
245
148
  /**
246
- * Asynchronous `symlink`.
247
- * @param type can be either `'dir'` or `'file'`
248
- */
249
- abstract symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void>;
250
- /**
251
- * Synchronous `symlink`.
252
- * @param type can be either `'dir'` or `'file'`
253
- */
254
- abstract symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void;
255
- /**
256
- * Asynchronous readlink.
257
- */
258
- abstract readlink(p: string, cred: Cred): Promise<string>;
259
- /**
260
- * Synchronous readlink.
261
- */
262
- abstract readlinkSync(p: string, cred: Cred): string;
263
- }
264
- /**
265
- * Basic filesystem class. Most filesystems should extend this class, as it
266
- * provides default implementations for a handful of methods.
267
- */
268
- export declare class BaseFileSystem extends FileSystem {
269
- static readonly Name: string;
270
- protected _ready: Promise<this>;
271
- constructor(options?: {
272
- [key: string]: unknown;
273
- });
274
- get metadata(): FileSystemMetadata;
275
- whenReady(): Promise<this>;
276
- /**
277
- * Opens the file at path p with the given flag. The file must exist.
278
- * @param p The path to open.
279
- * @param flag The flag to use when opening the file.
149
+ * Synchronize the data and stats for path asynchronously
280
150
  */
281
- openFile(p: string, flag: FileFlag, cred: Cred): Promise<File>;
151
+ abstract sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
282
152
  /**
283
- * Create the file at path p with the given mode. Then, open it with the given
284
- * flag.
153
+ * Synchronize the data and stats for path synchronously
285
154
  */
286
- createFile(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
287
- open(p: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
288
- access(p: string, mode: number, cred: Cred): Promise<void>;
289
- accessSync(p: string, mode: number, cred: Cred): void;
290
- rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
291
- renameSync(oldPath: string, newPath: string, cred: Cred): void;
292
- stat(p: string, cred: Cred): Promise<Stats>;
293
- statSync(p: string, cred: Cred): Stats;
294
- /**
295
- * Opens the file at path p with the given flag. The file must exist.
296
- * @param p The path to open.
297
- * @param flag The flag to use when opening the file.
298
- * @return A File object corresponding to the opened file.
299
- */
300
- openFileSync(p: string, flag: FileFlag, cred: Cred): File;
301
- /**
302
- * Create the file at path p with the given mode. Then, open it with the given
303
- * flag.
304
- */
305
- createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;
306
- openSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;
307
- unlink(p: string, cred: Cred): Promise<void>;
308
- unlinkSync(p: string, cred: Cred): void;
309
- rmdir(p: string, cred: Cred): Promise<void>;
310
- rmdirSync(p: string, cred: Cred): void;
311
- mkdir(p: string, mode: number, cred: Cred): Promise<void>;
312
- mkdirSync(p: string, mode: number, cred: Cred): void;
313
- readdir(p: string, cred: Cred): Promise<string[]>;
314
- readdirSync(p: string, cred: Cred): string[];
315
- exists(p: string, cred: Cred): Promise<boolean>;
316
- existsSync(p: string, cred: Cred): boolean;
317
- realpath(p: string, cred: Cred): Promise<string>;
318
- realpathSync(p: string, cred: Cred): string;
319
- truncate(p: string, len: number, cred: Cred): Promise<void>;
320
- truncateSync(p: string, len: number, cred: Cred): void;
321
- readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
322
- readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
323
- writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
324
- writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
325
- appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
326
- appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
327
- chmod(p: string, mode: number, cred: Cred): Promise<void>;
328
- chmodSync(p: string, mode: number, cred: Cred): void;
329
- chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;
330
- chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void;
331
- utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;
332
- utimesSync(p: string, atime: Date, mtime: Date, cred: Cred): void;
333
- link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
334
- linkSync(srcpath: string, dstpath: string, cred: Cred): void;
335
- symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void>;
336
- symlinkSync(srcpath: string, dstpath: string, type: string, cred: Cred): void;
337
- readlink(p: string, cred: Cred): Promise<string>;
338
- readlinkSync(p: string, cred: Cred): string;
155
+ abstract syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
339
156
  }
340
157
  /**
341
158
  * Implements the asynchronous API in terms of the synchronous API.
342
159
  */
343
- export declare class SynchronousFileSystem extends BaseFileSystem {
160
+ export declare abstract class SyncFileSystem extends FileSystem {
344
161
  get metadata(): FileSystemMetadata;
345
- access(p: string, mode: number, cred: Cred): Promise<void>;
162
+ ready(): Promise<this>;
346
163
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
347
- stat(p: string | null, cred: Cred): Promise<Stats>;
348
- open(p: string, flags: FileFlag, mode: number, cred: Cred): Promise<File>;
349
- unlink(p: string, cred: Cred): Promise<void>;
350
- rmdir(p: string, cred: Cred): Promise<void>;
351
- mkdir(p: string, mode: number, cred: Cred): Promise<void>;
352
- readdir(p: string, cred: Cred): Promise<string[]>;
353
- chmod(p: string, mode: number, cred: Cred): Promise<void>;
354
- chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;
355
- utimes(p: string, atime: Date, mtime: Date, cred: Cred): Promise<void>;
164
+ stat(path: string, cred: Cred): Promise<Stats>;
165
+ createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
166
+ openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
167
+ unlink(path: string, cred: Cred): Promise<void>;
168
+ rmdir(path: string, cred: Cred): Promise<void>;
169
+ mkdir(path: string, mode: number, cred: Cred): Promise<void>;
170
+ readdir(path: string, cred: Cred): Promise<string[]>;
356
171
  link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
357
- symlink(srcpath: string, dstpath: string, type: string, cred: Cred): Promise<void>;
358
- readlink(p: string, cred: Cred): Promise<string>;
172
+ sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
173
+ }
174
+ export declare abstract class AsyncFileSystem extends FileSystem {
175
+ renameSync(oldPath: string, newPath: string, cred: Cred): void;
176
+ statSync(path: string, cred: Cred): Stats;
177
+ createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
178
+ openSync(path: string, flags: FileFlag, mode: number, cred: Cred): File;
179
+ openFileSync(path: string, flag: FileFlag, cred: Cred): File;
180
+ unlinkSync(path: string, cred: Cred): void;
181
+ rmdirSync(path: string, cred: Cred): void;
182
+ mkdirSync(path: string, mode: number, cred: Cred): void;
183
+ readdirSync(path: string, cred: Cred): string[];
184
+ linkSync(srcpath: string, dstpath: string, cred: Cred): void;
185
+ syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
359
186
  }