@zenfs/core 0.0.12 → 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 (54) hide show
  1. package/dist/ApiError.d.ts +52 -15
  2. package/dist/ApiError.js +77 -50
  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 +154 -147
  7. package/dist/backends/AsyncStore.d.ts +29 -28
  8. package/dist/backends/AsyncStore.js +375 -482
  9. package/dist/backends/FolderAdapter.js +8 -19
  10. package/dist/backends/InMemory.d.ts +16 -13
  11. package/dist/backends/InMemory.js +29 -14
  12. package/dist/backends/Locked.d.ts +8 -28
  13. package/dist/backends/Locked.js +74 -224
  14. package/dist/backends/OverlayFS.d.ts +26 -34
  15. package/dist/backends/OverlayFS.js +303 -511
  16. package/dist/backends/SyncStore.d.ts +54 -72
  17. package/dist/backends/SyncStore.js +159 -161
  18. package/dist/backends/backend.d.ts +45 -29
  19. package/dist/backends/backend.js +83 -13
  20. package/dist/backends/index.d.ts +6 -7
  21. package/dist/backends/index.js +5 -6
  22. package/dist/browser.min.js +21 -6
  23. package/dist/browser.min.js.map +4 -4
  24. package/dist/emulation/callbacks.d.ts +119 -113
  25. package/dist/emulation/callbacks.js +129 -92
  26. package/dist/emulation/constants.js +1 -1
  27. package/dist/emulation/dir.d.ts +55 -0
  28. package/dist/emulation/dir.js +104 -0
  29. package/dist/emulation/fs.d.ts +1 -2
  30. package/dist/emulation/fs.js +0 -1
  31. package/dist/emulation/index.d.ts +3 -0
  32. package/dist/emulation/index.js +3 -0
  33. package/dist/emulation/promises.d.ts +265 -145
  34. package/dist/emulation/promises.js +526 -383
  35. package/dist/emulation/shared.d.ts +20 -6
  36. package/dist/emulation/shared.js +22 -23
  37. package/dist/emulation/streams.d.ts +102 -0
  38. package/dist/emulation/streams.js +55 -0
  39. package/dist/emulation/sync.d.ts +98 -69
  40. package/dist/emulation/sync.js +280 -133
  41. package/dist/file.d.ts +175 -173
  42. package/dist/file.js +257 -273
  43. package/dist/filesystem.d.ts +71 -244
  44. package/dist/filesystem.js +67 -472
  45. package/dist/index.d.ts +7 -44
  46. package/dist/index.js +22 -75
  47. package/dist/inode.d.ts +37 -28
  48. package/dist/inode.js +123 -65
  49. package/dist/stats.d.ts +91 -36
  50. package/dist/stats.js +138 -110
  51. package/dist/utils.d.ts +26 -13
  52. package/dist/utils.js +79 -107
  53. package/package.json +7 -4
  54. package/readme.md +2 -40
@@ -1,45 +1,19 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  // disable no-unused-vars since BaseFileSystem uses them a lot
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var _a;
13
3
  import { ApiError, ErrorCode } from './ApiError.js';
14
- import { FileFlag, ActionType } from './file.js';
15
- import * as path from './emulation/path.js';
16
- import { encode } from './utils.js';
17
4
  /**
18
- * Structure for a filesystem. **All** ZenFS FileSystems must implement
19
- * this.
5
+ * Structure for a filesystem. All ZenFS FileSystems must implement this.
20
6
  *
21
- * ### Argument Assumptions
7
+ * This class includes some default implementations
22
8
  *
23
- * You can assume the following about arguments passed to each API method:
9
+ * Assume the following about arguments passed to each API method:
24
10
  *
25
- * - Every path is an absolute path. `.`, `..`, and other items
26
- * are resolved into an absolute form.
27
- * - All arguments are present. Any optional arguments at the Node API level
28
- * have been passed in with their default values.
11
+ * - Every path is an absolute path. `.`, `..`, and other items are resolved into an absolute form.
12
+ * - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
29
13
  */
30
14
  export class FileSystem {
31
- constructor(options) {
32
- // unused
33
- }
34
- }
35
- /**
36
- * Basic filesystem class. Most filesystems should extend this class, as it
37
- * provides default implementations for a handful of methods.
38
- */
39
- export class BaseFileSystem extends FileSystem {
40
- constructor(options) {
41
- super();
42
- this._ready = Promise.resolve(this);
15
+ static get Name() {
16
+ return this.name;
43
17
  }
44
18
  get metadata() {
45
19
  return {
@@ -47,490 +21,111 @@ export class BaseFileSystem extends FileSystem {
47
21
  readonly: false,
48
22
  synchronous: false,
49
23
  supportsProperties: false,
50
- supportsLinks: false,
51
24
  totalSpace: 0,
52
25
  freeSpace: 0,
53
26
  };
54
27
  }
55
- whenReady() {
56
- return this._ready;
57
- }
58
- /**
59
- * Opens the file at path p with the given flag. The file must exist.
60
- * @param p The path to open.
61
- * @param flag The flag to use when opening the file.
62
- */
63
- openFile(p, flag, cred) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- throw new ApiError(ErrorCode.ENOTSUP);
66
- });
67
- }
68
- /**
69
- * Create the file at path p with the given mode. Then, open it with the given
70
- * flag.
71
- */
72
- createFile(p, flag, mode, cred) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- throw new ApiError(ErrorCode.ENOTSUP);
75
- });
76
- }
77
- open(p, flag, mode, cred) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- try {
80
- const stats = yield this.stat(p, cred);
81
- switch (flag.pathExistsAction()) {
82
- case ActionType.THROW_EXCEPTION:
83
- throw ApiError.EEXIST(p);
84
- case ActionType.TRUNCATE_FILE:
85
- // NOTE: In a previous implementation, we deleted the file and
86
- // re-created it. However, this created a race condition if another
87
- // asynchronous request was trying to read the file, as the file
88
- // would not exist for a small period of time.
89
- const fd = yield this.openFile(p, flag, cred);
90
- if (!fd)
91
- throw new Error('BFS has reached an impossible code path; please file a bug.');
92
- yield fd.truncate(0);
93
- yield fd.sync();
94
- return fd;
95
- case ActionType.NOP:
96
- return this.openFile(p, flag, cred);
97
- default:
98
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
99
- }
100
- // File exists.
101
- }
102
- catch (e) {
103
- // File does not exist.
104
- switch (flag.pathNotExistsAction()) {
105
- case ActionType.CREATE_FILE:
106
- // Ensure parent exists.
107
- const parentStats = yield this.stat(path.dirname(p), cred);
108
- if (parentStats && !parentStats.isDirectory()) {
109
- throw ApiError.ENOTDIR(path.dirname(p));
110
- }
111
- return this.createFile(p, flag, mode, cred);
112
- case ActionType.THROW_EXCEPTION:
113
- throw ApiError.ENOENT(p);
114
- default:
115
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
116
- }
117
- }
118
- });
119
- }
120
- access(p, mode, cred) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- throw new ApiError(ErrorCode.ENOTSUP);
123
- });
124
- }
125
- accessSync(p, mode, cred) {
126
- throw new ApiError(ErrorCode.ENOTSUP);
127
- }
128
- rename(oldPath, newPath, cred) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- throw new ApiError(ErrorCode.ENOTSUP);
131
- });
132
- }
133
- renameSync(oldPath, newPath, cred) {
134
- throw new ApiError(ErrorCode.ENOTSUP);
135
- }
136
- stat(p, cred) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- throw new ApiError(ErrorCode.ENOTSUP);
139
- });
140
- }
141
- statSync(p, cred) {
142
- throw new ApiError(ErrorCode.ENOTSUP);
143
- }
144
- /**
145
- * Opens the file at path p with the given flag. The file must exist.
146
- * @param p The path to open.
147
- * @param flag The flag to use when opening the file.
148
- * @return A File object corresponding to the opened file.
149
- */
150
- openFileSync(p, flag, cred) {
151
- throw new ApiError(ErrorCode.ENOTSUP);
28
+ constructor(options) {
29
+ // unused
152
30
  }
153
31
  /**
154
- * Create the file at path p with the given mode. Then, open it with the given
155
- * flag.
32
+ * Test whether or not the given path exists by checking with the file system.
156
33
  */
157
- createFileSync(p, flag, mode, cred) {
158
- throw new ApiError(ErrorCode.ENOTSUP);
159
- }
160
- openSync(p, flag, mode, cred) {
161
- // Check if the path exists, and is a file.
162
- let stats;
34
+ async exists(path, cred) {
163
35
  try {
164
- stats = this.statSync(p, cred);
36
+ await this.stat(path, cred);
37
+ return true;
165
38
  }
166
39
  catch (e) {
167
- // File does not exist.
168
- switch (flag.pathNotExistsAction()) {
169
- case ActionType.CREATE_FILE:
170
- // Ensure parent exists.
171
- const parentStats = this.statSync(path.dirname(p), cred);
172
- if (!parentStats.isDirectory()) {
173
- throw ApiError.ENOTDIR(path.dirname(p));
174
- }
175
- return this.createFileSync(p, flag, mode, cred);
176
- case ActionType.THROW_EXCEPTION:
177
- throw ApiError.ENOENT(p);
178
- default:
179
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
180
- }
181
- }
182
- if (!stats.hasAccess(mode, cred)) {
183
- throw ApiError.EACCES(p);
184
- }
185
- // File exists.
186
- switch (flag.pathExistsAction()) {
187
- case ActionType.THROW_EXCEPTION:
188
- throw ApiError.EEXIST(p);
189
- case ActionType.TRUNCATE_FILE:
190
- // Delete file.
191
- this.unlinkSync(p, cred);
192
- // Create file. Use the same mode as the old file.
193
- // Node itself modifies the ctime when this occurs, so this action
194
- // will preserve that behavior if the underlying file system
195
- // supports those properties.
196
- return this.createFileSync(p, flag, stats.mode, cred);
197
- case ActionType.NOP:
198
- return this.openFileSync(p, flag, cred);
199
- default:
200
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
40
+ return false;
201
41
  }
202
42
  }
203
- unlink(p, cred) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- throw new ApiError(ErrorCode.ENOTSUP);
206
- });
207
- }
208
- unlinkSync(p, cred) {
209
- throw new ApiError(ErrorCode.ENOTSUP);
210
- }
211
- rmdir(p, cred) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- throw new ApiError(ErrorCode.ENOTSUP);
214
- });
215
- }
216
- rmdirSync(p, cred) {
217
- throw new ApiError(ErrorCode.ENOTSUP);
218
- }
219
- mkdir(p, mode, cred) {
220
- return __awaiter(this, void 0, void 0, function* () {
221
- throw new ApiError(ErrorCode.ENOTSUP);
222
- });
223
- }
224
- mkdirSync(p, mode, cred) {
225
- throw new ApiError(ErrorCode.ENOTSUP);
226
- }
227
- readdir(p, cred) {
228
- return __awaiter(this, void 0, void 0, function* () {
229
- throw new ApiError(ErrorCode.ENOTSUP);
230
- });
231
- }
232
- readdirSync(p, cred) {
233
- throw new ApiError(ErrorCode.ENOTSUP);
234
- }
235
- exists(p, cred) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- try {
238
- yield this.stat(p, cred);
239
- return true;
240
- }
241
- catch (e) {
242
- return false;
243
- }
244
- });
245
- }
246
- existsSync(p, cred) {
43
+ /**
44
+ * Test whether or not the given path exists by checking with the file system.
45
+ */
46
+ existsSync(path, cred) {
247
47
  try {
248
- this.statSync(p, cred);
48
+ this.statSync(path, cred);
249
49
  return true;
250
50
  }
251
51
  catch (e) {
252
52
  return false;
253
53
  }
254
54
  }
255
- realpath(p, cred) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- if (this.metadata.supportsLinks) {
258
- // The path could contain symlinks. Split up the path,
259
- // resolve any symlinks, return the resolved string.
260
- const splitPath = p.split(path.sep);
261
- // TODO: Simpler to just pass through file, find sep and such.
262
- for (let i = 0; i < splitPath.length; i++) {
263
- const addPaths = splitPath.slice(0, i + 1);
264
- splitPath[i] = path.join(...addPaths);
265
- }
266
- return splitPath.join(path.sep);
267
- }
268
- else {
269
- // No symlinks. We just need to verify that it exists.
270
- if (!(yield this.exists(p, cred))) {
271
- throw ApiError.ENOENT(p);
272
- }
273
- return p;
274
- }
275
- });
55
+ }
56
+ /**
57
+ * Implements the asynchronous API in terms of the synchronous API.
58
+ */
59
+ export class SyncFileSystem extends FileSystem {
60
+ get metadata() {
61
+ return { ...super.metadata, synchronous: true };
276
62
  }
277
- realpathSync(p, cred) {
278
- if (this.metadata.supportsLinks) {
279
- // The path could contain symlinks. Split up the path,
280
- // resolve any symlinks, return the resolved string.
281
- const splitPath = p.split(path.sep);
282
- // TODO: Simpler to just pass through file, find sep and such.
283
- for (let i = 0; i < splitPath.length; i++) {
284
- const addPaths = splitPath.slice(0, i + 1);
285
- splitPath[i] = path.join(...addPaths);
286
- }
287
- return splitPath.join(path.sep);
288
- }
289
- else {
290
- // No symlinks. We just need to verify that it exists.
291
- if (this.existsSync(p, cred)) {
292
- return p;
293
- }
294
- else {
295
- throw ApiError.ENOENT(p);
296
- }
297
- }
63
+ async ready() {
64
+ return this;
298
65
  }
299
- truncate(p, len, cred) {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- const fd = yield this.open(p, FileFlag.getFileFlag('r+'), 0o644, cred);
302
- try {
303
- yield fd.truncate(len);
304
- }
305
- finally {
306
- yield fd.close();
307
- }
308
- });
66
+ async rename(oldPath, newPath, cred) {
67
+ return this.renameSync(oldPath, newPath, cred);
309
68
  }
310
- truncateSync(p, len, cred) {
311
- const fd = this.openSync(p, FileFlag.getFileFlag('r+'), 0o644, cred);
312
- // Need to safely close FD, regardless of whether or not truncate succeeds.
313
- try {
314
- fd.truncateSync(len);
315
- }
316
- finally {
317
- fd.closeSync();
318
- }
69
+ async stat(path, cred) {
70
+ return this.statSync(path, cred);
319
71
  }
320
- readFile(fname, flag, cred) {
321
- return __awaiter(this, void 0, void 0, function* () {
322
- // Get file.
323
- const fd = yield this.open(fname, flag, 0o644, cred);
324
- try {
325
- const stat = yield fd.stat();
326
- // Allocate buffer.
327
- const buf = new Uint8Array(stat.size);
328
- yield fd.read(buf, 0, stat.size, 0);
329
- yield fd.close();
330
- return buf;
331
- }
332
- finally {
333
- yield fd.close();
334
- }
335
- });
72
+ async createFile(path, flag, mode, cred) {
73
+ return this.createFileSync(path, flag, mode, cred);
336
74
  }
337
- readFileSync(fname, flag, cred) {
338
- // Get file.
339
- const fd = this.openSync(fname, flag, 0o644, cred);
340
- try {
341
- const stat = fd.statSync();
342
- // Allocate buffer.
343
- const buf = new Uint8Array(stat.size);
344
- fd.readSync(buf, 0, stat.size, 0);
345
- fd.closeSync();
346
- return buf;
347
- }
348
- finally {
349
- fd.closeSync();
350
- }
351
- }
352
- writeFile(fname, data, flag, mode, cred) {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- // Get file.
355
- const fd = yield this.open(fname, flag, mode, cred);
356
- try {
357
- if (typeof data === 'string') {
358
- data = encode(data);
359
- }
360
- // Write into file.
361
- yield fd.write(data, 0, data.length, 0);
362
- }
363
- finally {
364
- yield fd.close();
365
- }
366
- });
75
+ async openFile(path, flag, cred) {
76
+ return this.openFileSync(path, flag, cred);
367
77
  }
368
- writeFileSync(fname, data, flag, mode, cred) {
369
- // Get file.
370
- const fd = this.openSync(fname, flag, mode, cred);
371
- try {
372
- if (typeof data === 'string') {
373
- data = encode(data);
374
- }
375
- // Write into file.
376
- fd.writeSync(data, 0, data.length, 0);
377
- }
378
- finally {
379
- fd.closeSync();
380
- }
78
+ async unlink(path, cred) {
79
+ return this.unlinkSync(path, cred);
381
80
  }
382
- appendFile(fname, data, flag, mode, cred) {
383
- return __awaiter(this, void 0, void 0, function* () {
384
- const fd = yield this.open(fname, flag, mode, cred);
385
- try {
386
- if (typeof data === 'string') {
387
- data = encode(data);
388
- }
389
- yield fd.write(data, 0, data.length, null);
390
- }
391
- finally {
392
- yield fd.close();
393
- }
394
- });
81
+ async rmdir(path, cred) {
82
+ return this.rmdirSync(path, cred);
395
83
  }
396
- appendFileSync(fname, data, flag, mode, cred) {
397
- const fd = this.openSync(fname, flag, mode, cred);
398
- try {
399
- if (typeof data === 'string') {
400
- data = encode(data);
401
- }
402
- fd.writeSync(data, 0, data.length, null);
403
- }
404
- finally {
405
- fd.closeSync();
406
- }
84
+ async mkdir(path, mode, cred) {
85
+ return this.mkdirSync(path, mode, cred);
407
86
  }
408
- chmod(p, mode, cred) {
409
- return __awaiter(this, void 0, void 0, function* () {
410
- throw new ApiError(ErrorCode.ENOTSUP);
411
- });
87
+ async readdir(path, cred) {
88
+ return this.readdirSync(path, cred);
412
89
  }
413
- chmodSync(p, mode, cred) {
414
- throw new ApiError(ErrorCode.ENOTSUP);
90
+ async link(srcpath, dstpath, cred) {
91
+ return this.linkSync(srcpath, dstpath, cred);
415
92
  }
416
- chown(p, new_uid, new_gid, cred) {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- throw new ApiError(ErrorCode.ENOTSUP);
419
- });
93
+ async sync(path, data, stats) {
94
+ return this.syncSync(path, data, stats);
420
95
  }
421
- chownSync(p, new_uid, new_gid, cred) {
96
+ }
97
+ export class AsyncFileSystem extends FileSystem {
98
+ renameSync(oldPath, newPath, cred) {
422
99
  throw new ApiError(ErrorCode.ENOTSUP);
423
100
  }
424
- utimes(p, atime, mtime, cred) {
425
- return __awaiter(this, void 0, void 0, function* () {
426
- throw new ApiError(ErrorCode.ENOTSUP);
427
- });
428
- }
429
- utimesSync(p, atime, mtime, cred) {
101
+ statSync(path, cred) {
430
102
  throw new ApiError(ErrorCode.ENOTSUP);
431
103
  }
432
- link(srcpath, dstpath, cred) {
433
- return __awaiter(this, void 0, void 0, function* () {
434
- throw new ApiError(ErrorCode.ENOTSUP);
435
- });
436
- }
437
- linkSync(srcpath, dstpath, cred) {
104
+ createFileSync(path, flag, mode, cred) {
438
105
  throw new ApiError(ErrorCode.ENOTSUP);
439
106
  }
440
- symlink(srcpath, dstpath, type, cred) {
441
- return __awaiter(this, void 0, void 0, function* () {
442
- throw new ApiError(ErrorCode.ENOTSUP);
443
- });
444
- }
445
- symlinkSync(srcpath, dstpath, type, cred) {
107
+ openSync(path, flags, mode, cred) {
446
108
  throw new ApiError(ErrorCode.ENOTSUP);
447
109
  }
448
- readlink(p, cred) {
449
- return __awaiter(this, void 0, void 0, function* () {
450
- throw new ApiError(ErrorCode.ENOTSUP);
451
- });
452
- }
453
- readlinkSync(p, cred) {
110
+ openFileSync(path, flag, cred) {
454
111
  throw new ApiError(ErrorCode.ENOTSUP);
455
112
  }
456
- }
457
- _a = BaseFileSystem;
458
- BaseFileSystem.Name = _a.name;
459
- /**
460
- * Implements the asynchronous API in terms of the synchronous API.
461
- */
462
- export class SynchronousFileSystem extends BaseFileSystem {
463
- get metadata() {
464
- return Object.assign(Object.assign({}, super.metadata), { synchronous: true });
465
- }
466
- access(p, mode, cred) {
467
- return __awaiter(this, void 0, void 0, function* () {
468
- return this.accessSync(p, mode, cred);
469
- });
470
- }
471
- rename(oldPath, newPath, cred) {
472
- return __awaiter(this, void 0, void 0, function* () {
473
- return this.renameSync(oldPath, newPath, cred);
474
- });
475
- }
476
- stat(p, cred) {
477
- return __awaiter(this, void 0, void 0, function* () {
478
- return this.statSync(p, cred);
479
- });
480
- }
481
- open(p, flags, mode, cred) {
482
- return __awaiter(this, void 0, void 0, function* () {
483
- return this.openSync(p, flags, mode, cred);
484
- });
485
- }
486
- unlink(p, cred) {
487
- return __awaiter(this, void 0, void 0, function* () {
488
- return this.unlinkSync(p, cred);
489
- });
490
- }
491
- rmdir(p, cred) {
492
- return __awaiter(this, void 0, void 0, function* () {
493
- return this.rmdirSync(p, cred);
494
- });
495
- }
496
- mkdir(p, mode, cred) {
497
- return __awaiter(this, void 0, void 0, function* () {
498
- return this.mkdirSync(p, mode, cred);
499
- });
500
- }
501
- readdir(p, cred) {
502
- return __awaiter(this, void 0, void 0, function* () {
503
- return this.readdirSync(p, cred);
504
- });
505
- }
506
- chmod(p, mode, cred) {
507
- return __awaiter(this, void 0, void 0, function* () {
508
- return this.chmodSync(p, mode, cred);
509
- });
113
+ unlinkSync(path, cred) {
114
+ throw new ApiError(ErrorCode.ENOTSUP);
510
115
  }
511
- chown(p, new_uid, new_gid, cred) {
512
- return __awaiter(this, void 0, void 0, function* () {
513
- return this.chownSync(p, new_uid, new_gid, cred);
514
- });
116
+ rmdirSync(path, cred) {
117
+ throw new ApiError(ErrorCode.ENOTSUP);
515
118
  }
516
- utimes(p, atime, mtime, cred) {
517
- return __awaiter(this, void 0, void 0, function* () {
518
- return this.utimesSync(p, atime, mtime, cred);
519
- });
119
+ mkdirSync(path, mode, cred) {
120
+ throw new ApiError(ErrorCode.ENOTSUP);
520
121
  }
521
- link(srcpath, dstpath, cred) {
522
- return __awaiter(this, void 0, void 0, function* () {
523
- return this.linkSync(srcpath, dstpath, cred);
524
- });
122
+ readdirSync(path, cred) {
123
+ throw new ApiError(ErrorCode.ENOTSUP);
525
124
  }
526
- symlink(srcpath, dstpath, type, cred) {
527
- return __awaiter(this, void 0, void 0, function* () {
528
- return this.symlinkSync(srcpath, dstpath, type, cred);
529
- });
125
+ linkSync(srcpath, dstpath, cred) {
126
+ throw new ApiError(ErrorCode.ENOTSUP);
530
127
  }
531
- readlink(p, cred) {
532
- return __awaiter(this, void 0, void 0, function* () {
533
- return this.readlinkSync(p, cred);
534
- });
128
+ syncSync(path, data, stats) {
129
+ throw new ApiError(ErrorCode.ENOTSUP);
535
130
  }
536
131
  }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * ZenFS's main module. This is exposed in the browser via the ZenFS global.
3
3
  */
4
- import fs from './emulation/fs.js';
5
- import { FileSystem, type BFSOneArgCallback, type BFSCallback } from './filesystem.js';
4
+ import * as fs from './emulation/index.js';
5
+ import { FileSystem } from './filesystem.js';
6
6
  import { backends } from './backends/index.js';
7
+ import { type Backend, type BackendConfig } from './backends/backend.js';
7
8
  /**
8
9
  * Initializes ZenFS with the given file systems.
9
10
  */
@@ -14,55 +15,17 @@ export declare function initialize(mounts: {
14
15
  * Defines a mapping of mount points to their configurations
15
16
  */
16
17
  export interface ConfigMapping {
17
- [mountPoint: string]: FileSystem | FileSystemConfiguration | keyof typeof backends;
18
+ [mountPoint: string]: FileSystem | BackendConfig | keyof typeof backends | Backend;
18
19
  }
19
20
  /**
20
21
  * A configuration for ZenFS
21
22
  */
22
- export type Configuration = FileSystem | FileSystemConfiguration | ConfigMapping;
23
+ export type Configuration = FileSystem | BackendConfig | ConfigMapping;
23
24
  /**
24
- * Creates a file system with the given configuration, and initializes ZenFS with it.
25
- * See the FileSystemConfiguration type for more info on the configuration object.
25
+ * Creates filesystems with the given configuration, and initializes ZenFS with it.
26
+ * See the Configuration type for more info on the configuration object.
26
27
  */
27
28
  export declare function configure(config: Configuration): Promise<void>;
28
- export declare function configure(config: Configuration, cb: BFSOneArgCallback): void;
29
- /**
30
- * Asynchronously creates a file system with the given configuration, and initializes ZenFS with it.
31
- * See the FileSystemConfiguration type for more info on the configuration object.
32
- * Note: unlike configure, the .then is provided with the file system
33
- */
34
- /**
35
- * Specifies a file system backend type and its options.
36
- *
37
- * Individual options can recursively contain FileSystemConfiguration objects for
38
- * option values that require file systems.
39
- *
40
- * For example, to mirror Dropbox to Storage with AsyncMirror, use the following
41
- * object:
42
- *
43
- * ```javascript
44
- * var config = {
45
- * fs: "AsyncMirror",
46
- * options: {
47
- * sync: {fs: "Storage"},
48
- * async: {fs: "Dropbox", options: {client: anAuthenticatedDropboxSDKClient }}
49
- * }
50
- * };
51
- * ```
52
- *
53
- * The option object for each file system corresponds to that file system's option object passed to its `Create()` method.
54
- */
55
- export interface FileSystemConfiguration {
56
- fs: string;
57
- options?: object;
58
- }
59
- /**
60
- * Retrieve a file system with the given configuration. Will return a promise if invoked without a callback
61
- * @param config A FileSystemConfiguration object. See FileSystemConfiguration for details.
62
- * @param cb Called when the file system is constructed, or when an error occurs.
63
- */
64
- export declare function getFileSystem(config: FileSystemConfiguration): Promise<FileSystem>;
65
- export declare function getFileSystem(config: FileSystemConfiguration, cb: BFSCallback<FileSystem>): void;
66
29
  export * from './backends/index.js';
67
30
  export * from './backends/AsyncStore.js';
68
31
  export * from './backends/SyncStore.js';