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