@zenfs/core 0.0.11 → 0.1.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 (40) hide show
  1. package/dist/ApiError.d.ts +1 -1
  2. package/dist/ApiError.js +17 -16
  3. package/dist/backends/AsyncMirror.js +43 -49
  4. package/dist/backends/AsyncStore.js +326 -383
  5. package/dist/backends/FolderAdapter.js +8 -19
  6. package/dist/backends/Locked.d.ts +7 -8
  7. package/dist/backends/Locked.js +97 -143
  8. package/dist/backends/OverlayFS.js +240 -284
  9. package/dist/backends/SyncStore.js +2 -2
  10. package/dist/backends/backend.d.ts +6 -6
  11. package/dist/browser.min.js +23 -6
  12. package/dist/browser.min.js.map +4 -4
  13. package/dist/emulation/callbacks.d.ts +109 -72
  14. package/dist/emulation/callbacks.js +40 -47
  15. package/dist/emulation/dir.d.ts +55 -0
  16. package/dist/emulation/dir.js +104 -0
  17. package/dist/emulation/fs.d.ts +1 -2
  18. package/dist/emulation/fs.js +0 -1
  19. package/dist/emulation/index.d.ts +3 -0
  20. package/dist/emulation/index.js +3 -0
  21. package/dist/emulation/promises.d.ts +71 -50
  22. package/dist/emulation/promises.js +244 -328
  23. package/dist/emulation/shared.d.ts +14 -0
  24. package/dist/emulation/shared.js +4 -3
  25. package/dist/emulation/streams.d.ts +102 -0
  26. package/dist/emulation/streams.js +55 -0
  27. package/dist/emulation/sync.d.ts +81 -52
  28. package/dist/emulation/sync.js +117 -69
  29. package/dist/file.d.ts +11 -5
  30. package/dist/file.js +79 -76
  31. package/dist/filesystem.d.ts +15 -23
  32. package/dist/filesystem.js +186 -273
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.js +39 -53
  35. package/dist/stats.d.ts +80 -27
  36. package/dist/stats.js +142 -93
  37. package/dist/utils.d.ts +2 -4
  38. package/dist/utils.js +80 -77
  39. package/package.json +4 -2
  40. package/readme.md +2 -40
@@ -26,7 +26,7 @@ export declare enum ErrorCode {
26
26
  * @internal
27
27
  */
28
28
  export declare const ErrorStrings: {
29
- [code: string | number]: string;
29
+ [code in ErrorCode]: string;
30
30
  };
31
31
  interface ApiErrorJSON {
32
32
  errno: ErrorCode;
package/dist/ApiError.js CHANGED
@@ -26,22 +26,23 @@ export var ErrorCode;
26
26
  * Strings associated with each error code.
27
27
  * @internal
28
28
  */
29
- export const ErrorStrings = {};
30
- ErrorStrings[ErrorCode.EPERM] = 'Operation not permitted.';
31
- ErrorStrings[ErrorCode.ENOENT] = 'No such file or directory.';
32
- ErrorStrings[ErrorCode.EIO] = 'Input/output error.';
33
- ErrorStrings[ErrorCode.EBADF] = 'Bad file descriptor.';
34
- ErrorStrings[ErrorCode.EACCES] = 'Permission denied.';
35
- ErrorStrings[ErrorCode.EBUSY] = 'Resource busy or locked.';
36
- ErrorStrings[ErrorCode.EEXIST] = 'File exists.';
37
- ErrorStrings[ErrorCode.ENOTDIR] = 'File is not a directory.';
38
- ErrorStrings[ErrorCode.EISDIR] = 'File is a directory.';
39
- ErrorStrings[ErrorCode.EINVAL] = 'Invalid argument.';
40
- ErrorStrings[ErrorCode.EFBIG] = 'File is too big.';
41
- ErrorStrings[ErrorCode.ENOSPC] = 'No space left on disk.';
42
- ErrorStrings[ErrorCode.EROFS] = 'Cannot modify a read-only file system.';
43
- ErrorStrings[ErrorCode.ENOTEMPTY] = 'Directory is not empty.';
44
- ErrorStrings[ErrorCode.ENOTSUP] = 'Operation is not supported.';
29
+ export const ErrorStrings = {
30
+ [ErrorCode.EPERM]: 'Operation not permitted.',
31
+ [ErrorCode.ENOENT]: 'No such file or directory.',
32
+ [ErrorCode.EIO]: 'Input/output error.',
33
+ [ErrorCode.EBADF]: 'Bad file descriptor.',
34
+ [ErrorCode.EACCES]: 'Permission denied.',
35
+ [ErrorCode.EBUSY]: 'Resource busy or locked.',
36
+ [ErrorCode.EEXIST]: 'File exists.',
37
+ [ErrorCode.ENOTDIR]: 'File is not a directory.',
38
+ [ErrorCode.EISDIR]: 'File is a directory.',
39
+ [ErrorCode.EINVAL]: 'Invalid argument.',
40
+ [ErrorCode.EFBIG]: 'File is too big.',
41
+ [ErrorCode.ENOSPC]: 'No space left on disk.',
42
+ [ErrorCode.EROFS]: 'Cannot modify a read-only file system.',
43
+ [ErrorCode.ENOTEMPTY]: 'Directory is not empty.',
44
+ [ErrorCode.ENOTSUP]: 'Operation is not supported.',
45
+ };
45
46
  /**
46
47
  * Represents a ZenFS error. Passed back to applications after a failed
47
48
  * call to the ZenFS API.
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  var _a;
11
2
  import { SynchronousFileSystem } from '../filesystem.js';
12
3
  import { ApiError, ErrorCode } from '../ApiError.js';
@@ -97,14 +88,19 @@ export class AsyncMirror extends SynchronousFileSystem {
97
88
  this._ready = this._initialize();
98
89
  }
99
90
  get metadata() {
100
- return Object.assign(Object.assign({}, super.metadata), { name: AsyncMirror.Name, synchronous: true, supportsProperties: this._sync.metadata.supportsProperties && this._async.metadata.supportsProperties });
91
+ return {
92
+ ...super.metadata,
93
+ name: AsyncMirror.Name,
94
+ synchronous: true,
95
+ supportsProperties: this._sync.metadata.supportsProperties && this._async.metadata.supportsProperties,
96
+ };
101
97
  }
102
98
  _syncSync(fd) {
103
99
  const stats = fd.getStats();
104
- this._sync.writeFileSync(fd.getPath(), fd.getBuffer(), null, FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));
100
+ this._sync.writeFileSync(fd.getPath(), fd.getBuffer(), FileFlag.getFileFlag('w'), stats.mode, stats.getCred(0, 0));
105
101
  this.enqueueOp({
106
102
  apiMethod: 'writeFile',
107
- arguments: [fd.getPath(), fd.getBuffer(), null, fd.getFlag(), stats.mode, stats.getCred(0, 0)],
103
+ arguments: [fd.getPath(), fd.getBuffer(), fd.getFlag(), stats.mode, stats.getCred(0, 0)],
108
104
  });
109
105
  }
110
106
  renameSync(oldPath, newPath, cred) {
@@ -121,7 +117,7 @@ export class AsyncMirror extends SynchronousFileSystem {
121
117
  // Sanity check: Is this open/close permitted?
122
118
  const fd = this._sync.openSync(p, flag, mode, cred);
123
119
  fd.closeSync();
124
- return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p, null, FileFlag.getFileFlag('r'), cred));
120
+ return new MirrorFile(this, p, flag, this._sync.statSync(p, cred), this._sync.readFileSync(p, FileFlag.getFileFlag('r'), cred));
125
121
  }
126
122
  unlinkSync(p, cred) {
127
123
  this._sync.unlinkSync(p, cred);
@@ -174,42 +170,40 @@ export class AsyncMirror extends SynchronousFileSystem {
174
170
  /**
175
171
  * Called once to load up files from async storage into sync storage.
176
172
  */
177
- _initialize() {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- if (!this._isInitialized) {
180
- // First call triggers initialization, the rest wait.
181
- const copyDirectory = (p, mode) => __awaiter(this, void 0, void 0, function* () {
182
- if (p !== '/') {
183
- const stats = yield this._async.stat(p, Cred.Root);
184
- this._sync.mkdirSync(p, mode, stats.getCred());
185
- }
186
- const files = yield this._async.readdir(p, Cred.Root);
187
- for (const file of files) {
188
- yield copyItem(join(p, file));
189
- }
190
- }), copyFile = (p, mode) => __awaiter(this, void 0, void 0, function* () {
191
- const data = yield this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);
192
- this._sync.writeFileSync(p, data, null, FileFlag.getFileFlag('w'), mode, Cred.Root);
193
- }), copyItem = (p) => __awaiter(this, void 0, void 0, function* () {
194
- const stats = yield this._async.stat(p, Cred.Root);
195
- if (stats.isDirectory()) {
196
- yield copyDirectory(p, stats.mode);
197
- }
198
- else {
199
- yield copyFile(p, stats.mode);
200
- }
201
- });
202
- try {
203
- yield copyDirectory('/', 0);
204
- this._isInitialized = true;
173
+ async _initialize() {
174
+ if (!this._isInitialized) {
175
+ // First call triggers initialization, the rest wait.
176
+ const copyDirectory = async (p, mode) => {
177
+ if (p !== '/') {
178
+ const stats = await this._async.stat(p, Cred.Root);
179
+ this._sync.mkdirSync(p, mode, stats.getCred());
180
+ }
181
+ const files = await this._async.readdir(p, Cred.Root);
182
+ for (const file of files) {
183
+ await copyItem(join(p, file));
205
184
  }
206
- catch (e) {
207
- this._isInitialized = false;
208
- throw e;
185
+ }, copyFile = async (p, mode) => {
186
+ const data = await this._async.readFile(p, FileFlag.getFileFlag('r'), Cred.Root);
187
+ this._sync.writeFileSync(p, data, FileFlag.getFileFlag('w'), mode, Cred.Root);
188
+ }, copyItem = async (p) => {
189
+ const stats = await this._async.stat(p, Cred.Root);
190
+ if (stats.isDirectory()) {
191
+ await copyDirectory(p, stats.mode);
192
+ }
193
+ else {
194
+ await copyFile(p, stats.mode);
209
195
  }
196
+ };
197
+ try {
198
+ await copyDirectory('/', 0);
199
+ this._isInitialized = true;
210
200
  }
211
- return this;
212
- });
201
+ catch (e) {
202
+ this._isInitialized = false;
203
+ throw e;
204
+ }
205
+ }
206
+ return this;
213
207
  }
214
208
  enqueueOp(op) {
215
209
  this._queue.push(op);
@@ -239,11 +233,11 @@ AsyncMirror.Options = {
239
233
  sync: {
240
234
  type: 'object',
241
235
  description: 'The synchronous file system to mirror the asynchronous file system to.',
242
- validator: (v) => __awaiter(void 0, void 0, void 0, function* () {
243
- if (!(v === null || v === void 0 ? void 0 : v.metadata.synchronous)) {
236
+ validator: async (v) => {
237
+ if (!v?.metadata.synchronous) {
244
238
  throw new ApiError(ErrorCode.EINVAL, `'sync' option must be a file system that supports synchronous operations`);
245
239
  }
246
- }),
240
+ },
247
241
  },
248
242
  async: {
249
243
  type: 'object',