@zenfs/core 1.11.4 → 2.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 (135) hide show
  1. package/dist/backends/backend.d.ts +19 -15
  2. package/dist/backends/backend.js +36 -19
  3. package/dist/backends/cow.d.ts +20 -30
  4. package/dist/backends/cow.js +83 -192
  5. package/dist/backends/fetch.d.ts +1 -0
  6. package/dist/backends/fetch.js +30 -30
  7. package/dist/backends/index.d.ts +1 -1
  8. package/dist/backends/index.js +1 -1
  9. package/dist/backends/memory.d.ts +5 -7
  10. package/dist/backends/memory.js +2 -3
  11. package/dist/backends/passthrough.d.ts +19 -23
  12. package/dist/backends/passthrough.js +98 -288
  13. package/dist/backends/port.d.ts +220 -0
  14. package/dist/backends/port.js +328 -0
  15. package/dist/backends/single_buffer.d.ts +59 -47
  16. package/dist/backends/single_buffer.js +468 -219
  17. package/dist/backends/store/fs.d.ts +25 -35
  18. package/dist/backends/store/fs.js +276 -315
  19. package/dist/backends/store/store.d.ts +10 -15
  20. package/dist/backends/store/store.js +11 -10
  21. package/dist/config.d.ts +3 -12
  22. package/dist/config.js +17 -19
  23. package/dist/context.d.ts +8 -21
  24. package/dist/context.js +33 -10
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +2 -1
  27. package/dist/internal/contexts.d.ts +63 -0
  28. package/dist/internal/contexts.js +15 -0
  29. package/dist/internal/credentials.d.ts +2 -11
  30. package/dist/internal/credentials.js +0 -19
  31. package/dist/internal/devices.d.ts +18 -80
  32. package/dist/internal/devices.js +103 -316
  33. package/dist/internal/error.d.ts +9 -204
  34. package/dist/internal/error.js +19 -288
  35. package/dist/internal/file_index.d.ts +1 -1
  36. package/dist/internal/file_index.js +11 -11
  37. package/dist/internal/filesystem.d.ts +51 -94
  38. package/dist/internal/filesystem.js +21 -20
  39. package/dist/internal/index.d.ts +1 -2
  40. package/dist/internal/index.js +1 -2
  41. package/dist/internal/index_fs.d.ts +12 -30
  42. package/dist/internal/index_fs.js +37 -69
  43. package/dist/internal/inode.d.ts +140 -24
  44. package/dist/internal/inode.js +515 -66
  45. package/dist/mixins/async.js +52 -112
  46. package/dist/mixins/mutexed.d.ts +19 -18
  47. package/dist/mixins/mutexed.js +62 -64
  48. package/dist/mixins/readonly.d.ts +7 -6
  49. package/dist/mixins/readonly.js +24 -18
  50. package/dist/mixins/sync.js +8 -8
  51. package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
  52. package/dist/{vfs/path.js → path.js} +6 -9
  53. package/dist/polyfills.js +1 -1
  54. package/dist/readline.d.ts +134 -0
  55. package/dist/readline.js +623 -0
  56. package/dist/utils.d.ts +9 -37
  57. package/dist/utils.js +17 -85
  58. package/dist/vfs/acl.d.ts +42 -0
  59. package/dist/vfs/acl.js +268 -0
  60. package/dist/vfs/async.d.ts +9 -23
  61. package/dist/vfs/async.js +25 -27
  62. package/dist/vfs/config.d.ts +6 -18
  63. package/dist/vfs/config.js +8 -18
  64. package/dist/vfs/dir.d.ts +3 -3
  65. package/dist/vfs/dir.js +12 -12
  66. package/dist/vfs/file.d.ts +106 -0
  67. package/dist/vfs/file.js +244 -0
  68. package/dist/vfs/flags.d.ts +19 -0
  69. package/dist/vfs/flags.js +62 -0
  70. package/dist/vfs/index.d.ts +4 -10
  71. package/dist/vfs/index.js +4 -13
  72. package/dist/vfs/ioctl.d.ts +88 -0
  73. package/dist/vfs/ioctl.js +409 -0
  74. package/dist/vfs/promises.d.ts +81 -19
  75. package/dist/vfs/promises.js +404 -288
  76. package/dist/vfs/shared.d.ts +7 -37
  77. package/dist/vfs/shared.js +29 -85
  78. package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
  79. package/dist/{stats.js → vfs/stats.js} +11 -66
  80. package/dist/vfs/streams.d.ts +1 -0
  81. package/dist/vfs/streams.js +32 -27
  82. package/dist/vfs/sync.d.ts +3 -3
  83. package/dist/vfs/sync.js +263 -260
  84. package/dist/vfs/watchers.d.ts +2 -2
  85. package/dist/vfs/watchers.js +12 -12
  86. package/dist/vfs/xattr.d.ts +116 -0
  87. package/dist/vfs/xattr.js +201 -0
  88. package/package.json +5 -3
  89. package/readme.md +1 -1
  90. package/scripts/test.js +2 -2
  91. package/tests/assignment.ts +1 -1
  92. package/tests/backend/config.worker.js +4 -1
  93. package/tests/backend/fetch.test.ts +3 -0
  94. package/tests/backend/port.test.ts +19 -33
  95. package/tests/backend/remote.worker.js +4 -1
  96. package/tests/backend/single-buffer.test.ts +53 -0
  97. package/tests/backend/single-buffer.worker.js +30 -0
  98. package/tests/common/context.test.ts +3 -3
  99. package/tests/common/handle.test.ts +17 -12
  100. package/tests/common/mutex.test.ts +9 -9
  101. package/tests/common/path.test.ts +1 -1
  102. package/tests/common/readline.test.ts +104 -0
  103. package/tests/common.ts +4 -19
  104. package/tests/fetch/fetch.ts +2 -2
  105. package/tests/fs/append.test.ts +4 -4
  106. package/tests/fs/directory.test.ts +25 -25
  107. package/tests/fs/errors.test.ts +15 -19
  108. package/tests/fs/links.test.ts +4 -3
  109. package/tests/fs/open.test.ts +4 -21
  110. package/tests/fs/permissions.test.ts +14 -18
  111. package/tests/fs/read.test.ts +10 -9
  112. package/tests/fs/readFile.test.ts +10 -26
  113. package/tests/fs/rename.test.ts +4 -9
  114. package/tests/fs/stat.test.ts +8 -8
  115. package/tests/fs/streams.test.ts +2 -11
  116. package/tests/fs/times.test.ts +7 -7
  117. package/tests/fs/truncate.test.ts +8 -36
  118. package/tests/fs/watch.test.ts +10 -10
  119. package/tests/fs/write.test.ts +77 -13
  120. package/tests/fs/xattr.test.ts +85 -0
  121. package/tests/logs.js +22 -0
  122. package/tests/setup/context.ts +1 -1
  123. package/tests/setup/index.ts +3 -3
  124. package/tests/setup/port.ts +7 -1
  125. package/dist/backends/port/fs.d.ts +0 -84
  126. package/dist/backends/port/fs.js +0 -151
  127. package/dist/backends/port/rpc.d.ts +0 -77
  128. package/dist/backends/port/rpc.js +0 -100
  129. package/dist/backends/store/simple.d.ts +0 -20
  130. package/dist/backends/store/simple.js +0 -13
  131. package/dist/internal/file.d.ts +0 -359
  132. package/dist/internal/file.js +0 -751
  133. package/dist/internal/log.d.ts +0 -133
  134. package/dist/internal/log.js +0 -218
  135. package/tests/fs/writeFile.test.ts +0 -70
@@ -1,61 +1,9 @@
1
- var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
- if (value !== null && value !== void 0) {
3
- if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
- var dispose, inner;
5
- if (async) {
6
- if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
- dispose = value[Symbol.asyncDispose];
8
- }
9
- if (dispose === void 0) {
10
- if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
- dispose = value[Symbol.dispose];
12
- if (async) inner = dispose;
13
- }
14
- if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
- if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
- env.stack.push({ value: value, dispose: dispose, async: async });
17
- }
18
- else if (async) {
19
- env.stack.push({ async: true });
20
- }
21
- return value;
22
- };
23
- var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
- return function (env) {
25
- function fail(e) {
26
- env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
- env.hasError = true;
28
- }
29
- var r, s = 0;
30
- function next() {
31
- while (r = env.stack.pop()) {
32
- try {
33
- if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
- if (r.dispose) {
35
- var result = r.dispose.call(r.value);
36
- if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
- }
38
- else s |= 1;
39
- }
40
- catch (e) {
41
- fail(e);
42
- }
43
- }
44
- if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
- if (env.hasError) throw env.error;
46
- }
47
- return next();
48
- };
49
- })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
- var e = new Error(message);
51
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
- });
1
+ import { withErrno } from 'kerium';
2
+ import { crit, debug, err } from 'kerium/log';
53
3
  import { getAllPrototypes } from 'utilium';
54
4
  import { StoreFS } from '../backends/store/fs.js';
55
- import { Errno, ErrnoError } from '../internal/error.js';
56
- import { LazyFile, parseFlag } from '../internal/file.js';
57
- import { crit, debug, err } from '../internal/log.js';
58
- import { join } from '../vfs/path.js';
5
+ import { isDirectory } from '../internal/inode.js';
6
+ import { join } from '../path.js';
59
7
  /**
60
8
  * Async() implements synchronous methods on an asynchronous file system
61
9
  *
@@ -87,8 +35,8 @@ export function Async(FS) {
87
35
  }
88
36
  async ready() {
89
37
  await super.ready();
90
- await this.queueDone();
91
- if (this._isInitialized || this.attributes.has('no_async'))
38
+ await this._promise;
39
+ if (this._isInitialized || this.attributes.has('no_async_preload'))
92
40
  return;
93
41
  this.checkSync();
94
42
  await this._sync.ready();
@@ -111,83 +59,84 @@ export function Async(FS) {
111
59
  }
112
60
  catch (e) {
113
61
  this._isInitialized = false;
114
- throw crit(e, { fs: this });
62
+ throw crit(e);
115
63
  }
116
64
  }
117
- checkSync(path, syscall) {
118
- if (this.attributes.has('no_async')) {
119
- throw crit(new ErrnoError(Errno.ENOTSUP, 'Sync preloading has been disabled for this async file system', path, syscall), {
120
- fs: this,
121
- });
65
+ checkSync() {
66
+ if (this.attributes.has('no_async_preload')) {
67
+ throw withErrno('ENOTSUP', 'Sync preloading has been disabled for this async file system');
122
68
  }
123
69
  if (!this._sync) {
124
- throw crit(new ErrnoError(Errno.ENOTSUP, 'No sync cache is attached to this async file system', path, syscall), { fs: this });
70
+ throw crit(withErrno('ENOTSUP', 'No sync cache is attached to this async file system'));
125
71
  }
126
72
  }
127
73
  renameSync(oldPath, newPath) {
128
- this.checkSync(oldPath, 'rename');
74
+ this.checkSync();
129
75
  this._sync.renameSync(oldPath, newPath);
130
76
  this._async(this.rename(oldPath, newPath));
131
77
  }
132
78
  statSync(path) {
133
- this.checkSync(path, 'stat');
79
+ this.checkSync();
134
80
  return this._sync.statSync(path);
135
81
  }
136
- createFileSync(path, flag, mode, options) {
137
- this.checkSync(path, 'createFile');
138
- const file = this._sync.createFileSync(path, flag, mode, options);
139
- this._async(this.createFile(path, flag, mode, options));
140
- return new LazyFile(this, path, flag, file.statSync());
82
+ touchSync(path, metadata) {
83
+ this.checkSync();
84
+ this._sync.touchSync(path, metadata);
85
+ this._async(this.touch(path, metadata));
141
86
  }
142
- openFileSync(path, flag) {
143
- this.checkSync(path, 'openFile');
144
- const stats = this._sync.statSync(path);
145
- return new LazyFile(this, path, flag, stats);
87
+ createFileSync(path, options) {
88
+ this.checkSync();
89
+ this._async(this.createFile(path, options));
90
+ return this._sync.createFileSync(path, options);
146
91
  }
147
92
  unlinkSync(path) {
148
- this.checkSync(path, 'unlinkSync');
93
+ this.checkSync();
149
94
  this._sync.unlinkSync(path);
150
95
  this._async(this.unlink(path));
151
96
  }
152
97
  rmdirSync(path) {
153
- this.checkSync(path, 'rmdir');
98
+ this.checkSync();
154
99
  this._sync.rmdirSync(path);
155
100
  this._async(this.rmdir(path));
156
101
  }
157
- mkdirSync(path, mode, options) {
158
- this.checkSync(path, 'mkdir');
159
- this._sync.mkdirSync(path, mode, options);
160
- this._async(this.mkdir(path, mode, options));
102
+ mkdirSync(path, options) {
103
+ this.checkSync();
104
+ this._async(this.mkdir(path, options));
105
+ return this._sync.mkdirSync(path, options);
161
106
  }
162
107
  readdirSync(path) {
163
- this.checkSync(path, 'readdir');
108
+ this.checkSync();
164
109
  return this._sync.readdirSync(path);
165
110
  }
166
111
  linkSync(srcpath, dstpath) {
167
- this.checkSync(srcpath, 'link');
112
+ this.checkSync();
168
113
  this._sync.linkSync(srcpath, dstpath);
169
114
  this._async(this.link(srcpath, dstpath));
170
115
  }
171
- syncSync(path, data, stats) {
172
- this.checkSync(path, 'sync');
173
- this._sync.syncSync(path, data, stats);
174
- this._async(this.sync(path, data, stats));
116
+ async sync() {
117
+ this.checkSync();
118
+ this._sync.syncSync();
119
+ await this._promise;
120
+ }
121
+ syncSync() {
122
+ this.checkSync();
123
+ this._sync.syncSync();
175
124
  }
176
125
  existsSync(path) {
177
- this.checkSync(path, 'exists');
126
+ this.checkSync();
178
127
  return this._sync.existsSync(path);
179
128
  }
180
129
  readSync(path, buffer, offset, end) {
181
- this.checkSync(path, 'read');
130
+ this.checkSync();
182
131
  this._sync.readSync(path, buffer, offset, end);
183
132
  }
184
133
  writeSync(path, buffer, offset) {
185
- this.checkSync(path, 'write');
134
+ this.checkSync();
186
135
  this._sync.writeSync(path, buffer, offset);
187
136
  this._async(this.write(path, buffer, offset));
188
137
  }
189
138
  streamWrite(path, options) {
190
- this.checkSync(path, 'streamWrite');
139
+ this.checkSync();
191
140
  const sync = this._sync.streamWrite(path, options).getWriter();
192
141
  const async = super.streamWrite(path, options).getWriter();
193
142
  return new WritableStream({
@@ -206,28 +155,19 @@ export function Async(FS) {
206
155
  * @internal
207
156
  */
208
157
  async crossCopy(path) {
209
- this.checkSync(path, 'crossCopy');
158
+ this.checkSync();
210
159
  const stats = await this.stat(path);
211
- if (!stats.isDirectory()) {
212
- const env_1 = { stack: [], error: void 0, hasError: false };
213
- try {
214
- const syncFile = __addDisposableResource(env_1, this._sync.createFileSync(path, parseFlag('w'), stats.mode, stats), false);
215
- const buffer = new Uint8Array(stats.size);
216
- await this.read(path, buffer, 0, stats.size);
217
- syncFile.writeSync(buffer, 0, stats.size);
218
- return;
219
- }
220
- catch (e_1) {
221
- env_1.error = e_1;
222
- env_1.hasError = true;
223
- }
224
- finally {
225
- __disposeResources(env_1);
226
- }
160
+ if (!isDirectory(stats)) {
161
+ this._sync.createFileSync(path, stats);
162
+ const buffer = new Uint8Array(stats.size);
163
+ await this.read(path, buffer, 0, stats.size);
164
+ this._sync.writeSync(path, buffer, 0);
165
+ this._sync.touchSync(path, stats);
166
+ return;
227
167
  }
228
168
  if (path !== '/') {
229
- const stats = await this.stat(path);
230
- this._sync.mkdirSync(path, stats.mode, stats);
169
+ this._sync.mkdirSync(path, stats);
170
+ this._sync.touchSync(path, stats);
231
171
  }
232
172
  const promises = [];
233
173
  for (const file of await this.readdir(path)) {
@@ -263,7 +203,7 @@ export function Async(FS) {
263
203
  (_c = (_b = this._sync) === null || _b === void 0 ? void 0 : _b[`${key}Sync`]) === null || _c === void 0 ? void 0 : _c.call(_b, ...args);
264
204
  }
265
205
  catch (e) {
266
- throw err(new ErrnoError(e.errno, e.message + ' (Out of sync!)', e.path, key), { fs: this });
206
+ throw err(withErrno(e.errno, e.message + ' (Out of sync!)'));
267
207
  }
268
208
  return result;
269
209
  };
@@ -1,8 +1,7 @@
1
- import type { File } from '../internal/file.js';
2
- import type { CreationOptions, FileSystem, FileSystemMetadata, StreamOptions, UsageInfo } from '../internal/filesystem.js';
1
+ import type { UUID } from 'node:crypto';
2
+ import type { Concrete } from 'utilium';
3
+ import type { CreationOptions, FileSystem, StreamOptions, UsageInfo } from '../internal/filesystem.js';
3
4
  import type { InodeLike } from '../internal/inode.js';
4
- import type { Stats } from '../stats.js';
5
- import type { Concrete } from '../utils.js';
6
5
  import '../polyfills.js';
7
6
  /**
8
7
  * @category Internals
@@ -27,14 +26,16 @@ export declare class _MutexedFS<T extends FileSystem> implements FileSystem {
27
26
  * @internal
28
27
  */
29
28
  _fs: T;
30
- get id(): number;
29
+ get type(): number;
31
30
  get name(): string;
32
31
  get label(): string | undefined;
33
32
  set label(value: string | undefined);
34
33
  get attributes(): import("utilium").ConstMap<import("../internal/filesystem.js").FileSystemAttributes, keyof import("../internal/filesystem.js").FileSystemAttributes, void> & Map<string, any>;
34
+ get _uuid(): UUID;
35
+ set _uuid(value: UUID);
36
+ get uuid(): UUID;
35
37
  ready(): Promise<void>;
36
38
  usage(): UsageInfo;
37
- metadata(): FileSystemMetadata;
38
39
  /**
39
40
  * The current locks
40
41
  */
@@ -48,13 +49,13 @@ export declare class _MutexedFS<T extends FileSystem> implements FileSystem {
48
49
  * If the path is currently locked, waits for it to be unlocked.
49
50
  * @internal
50
51
  */
51
- lock(path: string, syscall: string): Promise<MutexLock>;
52
+ lock(): Promise<MutexLock>;
52
53
  /**
53
54
  * Locks `path` asynchronously.
54
55
  * If the path is currently locked, an error will be thrown
55
56
  * @internal
56
57
  */
57
- lockSync(path: string, syscall: string): MutexLock;
58
+ lockSync(): MutexLock;
58
59
  /**
59
60
  * Whether `path` is locked
60
61
  * @internal
@@ -62,26 +63,26 @@ export declare class _MutexedFS<T extends FileSystem> implements FileSystem {
62
63
  get isLocked(): boolean;
63
64
  rename(oldPath: string, newPath: string): Promise<void>;
64
65
  renameSync(oldPath: string, newPath: string): void;
65
- stat(path: string): Promise<Stats>;
66
- statSync(path: string): Stats;
67
- openFile(path: string, flag: string): Promise<File>;
68
- openFileSync(path: string, flag: string): File;
69
- createFile(path: string, flag: string, mode: number, options: CreationOptions): Promise<File>;
70
- createFileSync(path: string, flag: string, mode: number, options: CreationOptions): File;
66
+ stat(path: string): Promise<InodeLike>;
67
+ statSync(path: string): InodeLike;
68
+ touch(path: string, metadata: InodeLike): Promise<void>;
69
+ touchSync(path: string, metadata: InodeLike): void;
70
+ createFile(path: string, options: CreationOptions): Promise<InodeLike>;
71
+ createFileSync(path: string, options: CreationOptions): InodeLike;
71
72
  unlink(path: string): Promise<void>;
72
73
  unlinkSync(path: string): void;
73
74
  rmdir(path: string): Promise<void>;
74
75
  rmdirSync(path: string): void;
75
- mkdir(path: string, mode: number, options: CreationOptions): Promise<void>;
76
- mkdirSync(path: string, mode: number, options: CreationOptions): void;
76
+ mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
77
+ mkdirSync(path: string, options: CreationOptions): InodeLike;
77
78
  readdir(path: string): Promise<string[]>;
78
79
  readdirSync(path: string): string[];
79
80
  exists(path: string): Promise<boolean>;
80
81
  existsSync(path: string): boolean;
81
82
  link(srcpath: string, dstpath: string): Promise<void>;
82
83
  linkSync(srcpath: string, dstpath: string): void;
83
- sync(path: string, data?: Uint8Array, stats?: Readonly<InodeLike>): Promise<void>;
84
- syncSync(path: string, data?: Uint8Array, stats?: Readonly<InodeLike>): void;
84
+ sync(): Promise<void>;
85
+ syncSync(): void;
85
86
  read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
86
87
  readSync(path: string, buffer: Uint8Array, offset: number, end: number): void;
87
88
  write(path: string, buffer: Uint8Array, offset: number): Promise<void>;