@zenfs/core 0.11.1 → 0.12.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 (48) hide show
  1. package/dist/backends/fetch.d.ts +20 -33
  2. package/dist/backends/fetch.js +48 -93
  3. package/dist/backends/index/fs.d.ts +49 -0
  4. package/dist/backends/index/fs.js +86 -0
  5. package/dist/backends/index/index.d.ts +37 -0
  6. package/dist/backends/index/index.js +82 -0
  7. package/dist/backends/locked.d.ts +1 -1
  8. package/dist/backends/locked.js +34 -34
  9. package/dist/backends/memory.d.ts +1 -1
  10. package/dist/backends/port/fs.d.ts +1 -1
  11. package/dist/backends/port/fs.js +2 -1
  12. package/dist/backends/port/rpc.js +3 -1
  13. package/dist/backends/store/fs.d.ts +5 -5
  14. package/dist/backends/store/fs.js +1 -1
  15. package/dist/browser.min.js +4 -4
  16. package/dist/browser.min.js.map +4 -4
  17. package/dist/emulation/promises.js +1 -2
  18. package/dist/emulation/sync.js +24 -40
  19. package/dist/file.d.ts +1 -1
  20. package/dist/file.js +2 -2
  21. package/dist/filesystem.d.ts +6 -6
  22. package/dist/filesystem.js +11 -10
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/mutex.d.ts +1 -1
  26. package/dist/mutex.js +11 -11
  27. package/dist/stats.d.ts +10 -10
  28. package/package.json +1 -1
  29. package/scripts/make-index.js +39 -24
  30. package/src/backends/fetch.ts +52 -110
  31. package/src/backends/index/fs.ts +113 -0
  32. package/src/backends/index/index.ts +98 -0
  33. package/src/backends/index/readme.md +3 -0
  34. package/src/backends/locked.ts +34 -34
  35. package/src/backends/memory.ts +1 -1
  36. package/src/backends/port/fs.ts +2 -1
  37. package/src/backends/port/rpc.ts +2 -1
  38. package/src/backends/store/fs.ts +5 -5
  39. package/src/emulation/promises.ts +1 -2
  40. package/src/emulation/sync.ts +23 -41
  41. package/src/file.ts +2 -2
  42. package/src/filesystem.ts +18 -17
  43. package/src/index.ts +1 -1
  44. package/src/mutex.ts +11 -11
  45. package/src/stats.ts +10 -10
  46. package/dist/backends/Index.d.ts +0 -204
  47. package/dist/backends/Index.js +0 -410
  48. package/src/backends/Index.ts +0 -504
@@ -13,7 +13,7 @@ import { Mutex } from '../mutex.js';
13
13
  export class LockedFS {
14
14
  constructor(fs) {
15
15
  this.fs = fs;
16
- this._mu = new Mutex();
16
+ this.mutex = new Mutex();
17
17
  }
18
18
  async ready() {
19
19
  await this.fs.ready();
@@ -25,127 +25,127 @@ export class LockedFS {
25
25
  };
26
26
  }
27
27
  async rename(oldPath, newPath, cred) {
28
- await this._mu.lock(oldPath);
28
+ await this.mutex.lock(oldPath);
29
29
  await this.fs.rename(oldPath, newPath, cred);
30
- this._mu.unlock(oldPath);
30
+ this.mutex.unlock(oldPath);
31
31
  }
32
32
  renameSync(oldPath, newPath, cred) {
33
- if (this._mu.isLocked(oldPath)) {
33
+ if (this.mutex.isLocked(oldPath)) {
34
34
  throw ErrnoError.With('EBUSY', oldPath, 'rename');
35
35
  }
36
36
  return this.fs.renameSync(oldPath, newPath, cred);
37
37
  }
38
38
  async stat(path, cred) {
39
- await this._mu.lock(path);
39
+ await this.mutex.lock(path);
40
40
  const stats = await this.fs.stat(path, cred);
41
- this._mu.unlock(path);
41
+ this.mutex.unlock(path);
42
42
  return stats;
43
43
  }
44
44
  statSync(path, cred) {
45
- if (this._mu.isLocked(path)) {
45
+ if (this.mutex.isLocked(path)) {
46
46
  throw ErrnoError.With('EBUSY', path, 'stat');
47
47
  }
48
48
  return this.fs.statSync(path, cred);
49
49
  }
50
50
  async openFile(path, flag, cred) {
51
- await this._mu.lock(path);
51
+ await this.mutex.lock(path);
52
52
  const fd = await this.fs.openFile(path, flag, cred);
53
- this._mu.unlock(path);
53
+ this.mutex.unlock(path);
54
54
  return fd;
55
55
  }
56
56
  openFileSync(path, flag, cred) {
57
- if (this._mu.isLocked(path)) {
57
+ if (this.mutex.isLocked(path)) {
58
58
  throw ErrnoError.With('EBUSY', path, 'openFile');
59
59
  }
60
60
  return this.fs.openFileSync(path, flag, cred);
61
61
  }
62
62
  async createFile(path, flag, mode, cred) {
63
- await this._mu.lock(path);
63
+ await this.mutex.lock(path);
64
64
  const fd = await this.fs.createFile(path, flag, mode, cred);
65
- this._mu.unlock(path);
65
+ this.mutex.unlock(path);
66
66
  return fd;
67
67
  }
68
68
  createFileSync(path, flag, mode, cred) {
69
- if (this._mu.isLocked(path)) {
69
+ if (this.mutex.isLocked(path)) {
70
70
  throw ErrnoError.With('EBUSY', path, 'createFile');
71
71
  }
72
72
  return this.fs.createFileSync(path, flag, mode, cred);
73
73
  }
74
74
  async unlink(path, cred) {
75
- await this._mu.lock(path);
75
+ await this.mutex.lock(path);
76
76
  await this.fs.unlink(path, cred);
77
- this._mu.unlock(path);
77
+ this.mutex.unlock(path);
78
78
  }
79
79
  unlinkSync(path, cred) {
80
- if (this._mu.isLocked(path)) {
80
+ if (this.mutex.isLocked(path)) {
81
81
  throw ErrnoError.With('EBUSY', path, 'unlink');
82
82
  }
83
83
  return this.fs.unlinkSync(path, cred);
84
84
  }
85
85
  async rmdir(path, cred) {
86
- await this._mu.lock(path);
86
+ await this.mutex.lock(path);
87
87
  await this.fs.rmdir(path, cred);
88
- this._mu.unlock(path);
88
+ this.mutex.unlock(path);
89
89
  }
90
90
  rmdirSync(path, cred) {
91
- if (this._mu.isLocked(path)) {
91
+ if (this.mutex.isLocked(path)) {
92
92
  throw ErrnoError.With('EBUSY', path, 'rmdir');
93
93
  }
94
94
  return this.fs.rmdirSync(path, cred);
95
95
  }
96
96
  async mkdir(path, mode, cred) {
97
- await this._mu.lock(path);
97
+ await this.mutex.lock(path);
98
98
  await this.fs.mkdir(path, mode, cred);
99
- this._mu.unlock(path);
99
+ this.mutex.unlock(path);
100
100
  }
101
101
  mkdirSync(path, mode, cred) {
102
- if (this._mu.isLocked(path)) {
102
+ if (this.mutex.isLocked(path)) {
103
103
  throw ErrnoError.With('EBUSY', path, 'mkdir');
104
104
  }
105
105
  return this.fs.mkdirSync(path, mode, cred);
106
106
  }
107
107
  async readdir(path, cred) {
108
- await this._mu.lock(path);
108
+ await this.mutex.lock(path);
109
109
  const files = await this.fs.readdir(path, cred);
110
- this._mu.unlock(path);
110
+ this.mutex.unlock(path);
111
111
  return files;
112
112
  }
113
113
  readdirSync(path, cred) {
114
- if (this._mu.isLocked(path)) {
114
+ if (this.mutex.isLocked(path)) {
115
115
  throw ErrnoError.With('EBUSY', path, 'readdir');
116
116
  }
117
117
  return this.fs.readdirSync(path, cred);
118
118
  }
119
119
  async exists(path, cred) {
120
- await this._mu.lock(path);
120
+ await this.mutex.lock(path);
121
121
  const exists = await this.fs.exists(path, cred);
122
- this._mu.unlock(path);
122
+ this.mutex.unlock(path);
123
123
  return exists;
124
124
  }
125
125
  existsSync(path, cred) {
126
- if (this._mu.isLocked(path)) {
126
+ if (this.mutex.isLocked(path)) {
127
127
  throw ErrnoError.With('EBUSY', path, 'exists');
128
128
  }
129
129
  return this.fs.existsSync(path, cred);
130
130
  }
131
131
  async link(srcpath, dstpath, cred) {
132
- await this._mu.lock(srcpath);
132
+ await this.mutex.lock(srcpath);
133
133
  await this.fs.link(srcpath, dstpath, cred);
134
- this._mu.unlock(srcpath);
134
+ this.mutex.unlock(srcpath);
135
135
  }
136
136
  linkSync(srcpath, dstpath, cred) {
137
- if (this._mu.isLocked(srcpath)) {
137
+ if (this.mutex.isLocked(srcpath)) {
138
138
  throw ErrnoError.With('EBUSY', srcpath, 'link');
139
139
  }
140
140
  return this.fs.linkSync(srcpath, dstpath, cred);
141
141
  }
142
142
  async sync(path, data, stats) {
143
- await this._mu.lock(path);
143
+ await this.mutex.lock(path);
144
144
  await this.fs.sync(path, data, stats);
145
- this._mu.unlock(path);
145
+ this.mutex.unlock(path);
146
146
  }
147
147
  syncSync(path, data, stats) {
148
- if (this._mu.isLocked(path)) {
148
+ if (this.mutex.isLocked(path)) {
149
149
  throw ErrnoError.With('EBUSY', path, 'sync');
150
150
  }
151
151
  return this.fs.syncSync(path, data, stats);
@@ -27,5 +27,5 @@ export declare const InMemory: {
27
27
  };
28
28
  readonly create: ({ name }: {
29
29
  name?: string;
30
- }) => StoreFS;
30
+ }) => StoreFS<InMemoryStore>;
31
31
  };
@@ -79,7 +79,7 @@ export declare class PortFS extends PortFS_base {
79
79
  /**
80
80
  * @hidden
81
81
  */
82
- _sync: import("../store/fs.js").StoreFS;
82
+ _sync: import("../store/fs.js").StoreFS<import("../memory.js").InMemoryStore>;
83
83
  /**
84
84
  * Constructs a new PortFS instance that connects with ZenFS running on
85
85
  * the specified port.
@@ -39,7 +39,8 @@ export class PortFile extends File {
39
39
  throw ErrnoError.With('ENOSYS', this.path, 'PortFile.write');
40
40
  }
41
41
  async read(buffer, offset, length, position) {
42
- return (await this.rpc('read', buffer, offset, length, position));
42
+ const result = await this.rpc('read', buffer, offset, length, position);
43
+ return result;
43
44
  }
44
45
  readSync() {
45
46
  throw ErrnoError.With('ENOSYS', this.path, 'PortFile.read');
@@ -17,10 +17,12 @@ export function request(request, { port, timeout = 1000, fs } = {}) {
17
17
  const id = Math.random().toString(16).slice(10);
18
18
  executors.set(id, { resolve, reject, fs });
19
19
  port.postMessage({ ...request, _zenfs: true, id, stack });
20
- setTimeout(() => {
20
+ const _ = setTimeout(() => {
21
21
  const error = new ErrnoError(Errno.EIO, 'RPC Failed');
22
22
  error.stack += stack;
23
23
  reject(error);
24
+ if (typeof _ == 'object')
25
+ _.unref();
24
26
  }, timeout);
25
27
  });
26
28
  }
@@ -5,20 +5,20 @@ import { type Ino, Inode } from '../../inode.js';
5
5
  import { type Stats, FileType } from '../../stats.js';
6
6
  import type { Store, Transaction } from './store.js';
7
7
  /**
8
- * A synchronous key-value file system. Uses a SyncStore to store the data.
8
+ * A file system which uses a key-value store.
9
9
  *
10
10
  * We use a unique ID for each node in the file system. The root node has a fixed ID.
11
11
  * @todo Introduce Node ID caching.
12
12
  * @todo Check modes.
13
13
  * @internal
14
14
  */
15
- export declare class StoreFS extends FileSystem {
15
+ export declare class StoreFS<T extends Store = Store> extends FileSystem {
16
16
  private $store;
17
- protected get store(): Store;
18
- protected _store?: Store;
17
+ protected get store(): T;
18
+ protected _store?: T;
19
19
  private _initialized;
20
20
  ready(): Promise<void>;
21
- constructor($store: Store | Promise<Store>);
21
+ constructor($store: T | Promise<T>);
22
22
  metadata(): FileSystemMetadata;
23
23
  /**
24
24
  * Delete all contents stored in the file system.
@@ -8,7 +8,7 @@ import { FileType } from '../../stats.js';
8
8
  import { encodeDirListing, encode, decodeDirListing } from '../../utils.js';
9
9
  const maxInodeAllocTries = 5;
10
10
  /**
11
- * A synchronous key-value file system. Uses a SyncStore to store the data.
11
+ * A file system which uses a key-value store.
12
12
  *
13
13
  * We use a unique ID for each node in the file system. The root node has a fixed ID.
14
14
  * @todo Introduce Node ID caching.