@zenfs/core 1.11.4 → 2.0.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 (116) hide show
  1. package/dist/backends/backend.d.ts +19 -15
  2. package/dist/backends/backend.js +31 -15
  3. package/dist/backends/cow.d.ts +20 -30
  4. package/dist/backends/cow.js +52 -142
  5. package/dist/backends/fetch.d.ts +1 -0
  6. package/dist/backends/fetch.js +3 -1
  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 -22
  12. package/dist/backends/passthrough.js +85 -160
  13. package/dist/backends/port.d.ts +207 -0
  14. package/dist/backends/port.js +297 -0
  15. package/dist/backends/single_buffer.d.ts +11 -5
  16. package/dist/backends/single_buffer.js +18 -12
  17. package/dist/backends/store/fs.d.ts +11 -27
  18. package/dist/backends/store/fs.js +67 -91
  19. package/dist/backends/store/store.d.ts +7 -12
  20. package/dist/config.d.ts +1 -10
  21. package/dist/config.js +7 -8
  22. package/dist/context.d.ts +8 -21
  23. package/dist/context.js +33 -10
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.js +2 -1
  26. package/dist/internal/contexts.d.ts +63 -0
  27. package/dist/internal/contexts.js +15 -0
  28. package/dist/internal/credentials.d.ts +2 -11
  29. package/dist/internal/credentials.js +0 -19
  30. package/dist/internal/devices.d.ts +18 -80
  31. package/dist/internal/devices.js +76 -279
  32. package/dist/internal/file_index.js +3 -3
  33. package/dist/internal/filesystem.d.ts +31 -89
  34. package/dist/internal/filesystem.js +21 -20
  35. package/dist/internal/index.d.ts +0 -1
  36. package/dist/internal/index.js +0 -1
  37. package/dist/internal/index_fs.d.ts +12 -30
  38. package/dist/internal/index_fs.js +23 -55
  39. package/dist/internal/inode.d.ts +147 -9
  40. package/dist/internal/inode.js +333 -25
  41. package/dist/internal/log.d.ts +19 -13
  42. package/dist/internal/log.js +81 -80
  43. package/dist/mixins/async.js +26 -90
  44. package/dist/mixins/mutexed.d.ts +17 -16
  45. package/dist/mixins/mutexed.js +29 -31
  46. package/dist/mixins/readonly.d.ts +7 -6
  47. package/dist/mixins/readonly.js +6 -0
  48. package/dist/mixins/sync.js +8 -8
  49. package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
  50. package/dist/{vfs/path.js → path.js} +6 -9
  51. package/dist/readline.d.ts +134 -0
  52. package/dist/readline.js +623 -0
  53. package/dist/utils.d.ts +4 -35
  54. package/dist/utils.js +8 -73
  55. package/dist/vfs/acl.d.ts +42 -0
  56. package/dist/vfs/acl.js +249 -0
  57. package/dist/vfs/async.d.ts +7 -21
  58. package/dist/vfs/async.js +19 -19
  59. package/dist/vfs/config.d.ts +6 -18
  60. package/dist/vfs/config.js +8 -18
  61. package/dist/vfs/dir.d.ts +3 -3
  62. package/dist/vfs/dir.js +9 -8
  63. package/dist/vfs/file.d.ts +106 -0
  64. package/dist/vfs/file.js +235 -0
  65. package/dist/vfs/flags.d.ts +19 -0
  66. package/dist/vfs/flags.js +62 -0
  67. package/dist/vfs/index.d.ts +4 -10
  68. package/dist/vfs/index.js +4 -13
  69. package/dist/vfs/ioctl.d.ts +87 -0
  70. package/dist/vfs/ioctl.js +304 -0
  71. package/dist/vfs/promises.d.ts +78 -16
  72. package/dist/vfs/promises.js +273 -122
  73. package/dist/vfs/shared.d.ts +7 -26
  74. package/dist/vfs/shared.js +25 -53
  75. package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
  76. package/dist/{stats.js → vfs/stats.js} +11 -66
  77. package/dist/vfs/streams.d.ts +1 -0
  78. package/dist/vfs/streams.js +24 -19
  79. package/dist/vfs/sync.d.ts +4 -3
  80. package/dist/vfs/sync.js +143 -128
  81. package/dist/vfs/watchers.d.ts +2 -2
  82. package/dist/vfs/watchers.js +6 -6
  83. package/dist/vfs/xattr.d.ts +116 -0
  84. package/dist/vfs/xattr.js +218 -0
  85. package/package.json +3 -3
  86. package/readme.md +1 -1
  87. package/tests/backend/config.worker.js +4 -1
  88. package/tests/backend/fetch.test.ts +3 -0
  89. package/tests/backend/port.test.ts +21 -35
  90. package/tests/backend/remote.worker.js +4 -1
  91. package/tests/backend/single-buffer.test.ts +24 -0
  92. package/tests/common/context.test.ts +1 -1
  93. package/tests/common/handle.test.ts +17 -12
  94. package/tests/common/path.test.ts +1 -1
  95. package/tests/common/readline.test.ts +104 -0
  96. package/tests/common.ts +4 -19
  97. package/tests/fetch/fetch.ts +1 -1
  98. package/tests/fs/links.test.ts +1 -1
  99. package/tests/fs/permissions.test.ts +7 -6
  100. package/tests/fs/readFile.test.ts +3 -3
  101. package/tests/fs/stat.test.ts +6 -6
  102. package/tests/fs/streams.test.ts +2 -11
  103. package/tests/fs/times.test.ts +1 -1
  104. package/tests/fs/xattr.test.ts +85 -0
  105. package/tests/logs.js +22 -0
  106. package/tests/setup/context.ts +1 -1
  107. package/tests/setup/index.ts +3 -3
  108. package/tests/setup/port.ts +1 -1
  109. package/dist/backends/port/fs.d.ts +0 -84
  110. package/dist/backends/port/fs.js +0 -151
  111. package/dist/backends/port/rpc.d.ts +0 -77
  112. package/dist/backends/port/rpc.js +0 -100
  113. package/dist/backends/store/simple.d.ts +0 -20
  114. package/dist/backends/store/simple.js +0 -13
  115. package/dist/internal/file.d.ts +0 -359
  116. package/dist/internal/file.js +0 -751
@@ -1,11 +1,10 @@
1
- import type { FileSystem, FileSystemMetadata } from '../internal/filesystem.js';
2
- import type { StatsLike } from '../stats.js';
1
+ import type { FileSystem } from '../internal/filesystem.js';
2
+ import type { InodeLike } from '../internal/inode.js';
3
3
  import type { Mixin } from './shared.js';
4
4
  /**
5
5
  * @internal
6
6
  */
7
7
  export interface ReadonlyMixin {
8
- metadata(): FileSystemMetadata;
9
8
  rename(oldPath: string, newPath: string): Promise<never>;
10
9
  renameSync(oldPath: string, newPath: string): never;
11
10
  createFile(path: string, flag: string, mode: number): Promise<never>;
@@ -18,10 +17,12 @@ export interface ReadonlyMixin {
18
17
  mkdirSync(path: string, mode: number): never;
19
18
  link(srcpath: string, dstpath: string): Promise<never>;
20
19
  linkSync(srcpath: string, dstpath: string): never;
21
- sync(path: string, data: Uint8Array, stats: Readonly<StatsLike<number>>): Promise<never>;
22
- syncSync(path: string, data: Uint8Array, stats: Readonly<StatsLike<number>>): never;
20
+ touch(path: string, metadata: Readonly<InodeLike>): Promise<never>;
21
+ touchSync(path: string, metadata: Readonly<InodeLike>): never;
22
+ sync(path: string): Promise<never>;
23
+ syncSync(path: string): never;
23
24
  write(path: string, buffer: Uint8Array, offset: number): Promise<never>;
24
- writeSync(path: string, buffer: Uint8Array, offset: number): Promise<never>;
25
+ writeSync(path: string, buffer: Uint8Array, offset: number): never;
25
26
  }
26
27
  /**
27
28
  * Implements the non-readonly methods to throw `EROFS`
@@ -46,6 +46,12 @@ export function Readonly(FS) {
46
46
  linkSync() {
47
47
  throw new ErrnoError(Errno.EROFS);
48
48
  }
49
+ async touch() {
50
+ throw new ErrnoError(Errno.EROFS);
51
+ }
52
+ touchSync() {
53
+ throw new ErrnoError(Errno.EROFS);
54
+ }
49
55
  async sync() {
50
56
  throw new ErrnoError(Errno.EROFS);
51
57
  }
@@ -14,11 +14,11 @@ export function Sync(FS) {
14
14
  async stat(path) {
15
15
  return this.statSync(path);
16
16
  }
17
- async createFile(path, flag, mode, options) {
18
- return this.createFileSync(path, flag, mode, options);
17
+ async touch(path, metadata) {
18
+ return this.touchSync(path, metadata);
19
19
  }
20
- async openFile(path, flag) {
21
- return this.openFileSync(path, flag);
20
+ async createFile(path, options) {
21
+ return this.createFileSync(path, options);
22
22
  }
23
23
  async unlink(path) {
24
24
  return this.unlinkSync(path);
@@ -26,8 +26,8 @@ export function Sync(FS) {
26
26
  async rmdir(path) {
27
27
  return this.rmdirSync(path);
28
28
  }
29
- async mkdir(path, mode, options) {
30
- return this.mkdirSync(path, mode, options);
29
+ async mkdir(path, options) {
30
+ return this.mkdirSync(path, options);
31
31
  }
32
32
  async readdir(path) {
33
33
  return this.readdirSync(path);
@@ -35,8 +35,8 @@ export function Sync(FS) {
35
35
  async link(srcpath, dstpath) {
36
36
  return this.linkSync(srcpath, dstpath);
37
37
  }
38
- async sync(path, data, stats) {
39
- return this.syncSync(path, data, stats);
38
+ async sync(path) {
39
+ return this.syncSync(path);
40
40
  }
41
41
  async read(path, buffer, offset, end) {
42
42
  return this.readSync(path, buffer, offset, end);
@@ -1,15 +1,14 @@
1
1
  import type { ParsedPath } from 'node:path';
2
+ import type { V_Context } from './context.js';
2
3
  export type AbsolutePath = `/${string}`;
3
- export declare let cwd: string;
4
- export declare function cd(path: string): void;
5
4
  export declare const sep = "/";
6
5
  export declare function normalizeString(path: string, allowAboveRoot: boolean): string;
7
6
  export declare function formatExt(ext: string): string;
8
- export declare function resolve(...parts: string[]): AbsolutePath;
7
+ export declare function resolve(this: V_Context, ...parts: (string | undefined)[]): AbsolutePath;
9
8
  export declare function normalize(path: string): string;
10
9
  export declare function isAbsolute(path: string): path is AbsolutePath;
11
10
  export declare function join(...parts: string[]): string;
12
- export declare function relative(from: string, to: string): string;
11
+ export declare function relative(this: V_Context, from: string, to: string): string;
13
12
  export declare function dirname(path: string): string;
14
13
  export declare function basename(path: string, suffix?: string): string;
15
14
  export declare function extname(path: string): string;
@@ -20,10 +20,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
20
  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
21
  USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
- export let cwd = '/';
24
- export function cd(path) {
25
- cwd = resolve(cwd, path);
26
- }
23
+ import { defaultContext } from './internal/contexts.js';
27
24
  export const sep = '/';
28
25
  function validateObject(str, name) {
29
26
  if (typeof str != 'object') {
@@ -103,11 +100,11 @@ export function formatExt(ext) {
103
100
  return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
104
101
  }
105
102
  export function resolve(...parts) {
103
+ var _a;
106
104
  let resolved = '';
107
- for (const part of [...parts.reverse(), cwd]) {
108
- if (!part.length) {
105
+ for (const part of [...parts.reverse(), (_a = this === null || this === void 0 ? void 0 : this.pwd) !== null && _a !== void 0 ? _a : defaultContext.pwd]) {
106
+ if (!(part === null || part === void 0 ? void 0 : part.length))
109
107
  continue;
110
- }
111
108
  resolved = `${part}/${resolved}`;
112
109
  if (part.startsWith('/')) {
113
110
  break;
@@ -154,8 +151,8 @@ export function relative(from, to) {
154
151
  if (from === to)
155
152
  return '';
156
153
  // Trim leading forward slashes.
157
- from = resolve(from);
158
- to = resolve(to);
154
+ from = resolve.call(this, from);
155
+ to = resolve.call(this, to);
159
156
  if (from === to)
160
157
  return '';
161
158
  const fromStart = 1;
@@ -0,0 +1,134 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import type { Abortable } from 'node:events';
3
+ import type * as readline from 'node:readline';
4
+ interface InterfaceEvents {
5
+ close: [];
6
+ line: [input: string];
7
+ pause: [];
8
+ resume: [];
9
+ SIGCONT: [];
10
+ SIGINT: [];
11
+ SIGTSTP: [];
12
+ history: [history: string[]];
13
+ }
14
+ export declare class Interface extends EventEmitter<InterfaceEvents> implements readline.Interface {
15
+ readonly input: NodeJS.ReadableStream;
16
+ readonly output?: NodeJS.WritableStream | undefined;
17
+ readonly terminal: boolean;
18
+ readonly line: string;
19
+ protected _cursor: number;
20
+ get cursor(): number;
21
+ private _buffer;
22
+ private _closed;
23
+ private _paused;
24
+ private _prompt;
25
+ private _history;
26
+ private _historyIndex;
27
+ private _currentLine;
28
+ constructor(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream | undefined, completer?: readline.Completer | readline.AsyncCompleter, terminal?: boolean);
29
+ private _onData;
30
+ /**
31
+ * Closes the interface and removes all event listeners
32
+ */
33
+ close(): void;
34
+ /**
35
+ * Pauses the input stream
36
+ */
37
+ pause(): this;
38
+ /**
39
+ * Resumes the input stream
40
+ */
41
+ resume(): this;
42
+ /**
43
+ * Sets the prompt text
44
+ */
45
+ setPrompt(prompt: string): void;
46
+ /**
47
+ * Gets the current prompt text
48
+ */
49
+ getPrompt(): string;
50
+ /**
51
+ * Displays the prompt to the user
52
+ */
53
+ prompt(preserveCursor?: boolean): void;
54
+ /**
55
+ * Writes data to the interface and handles key events
56
+ */
57
+ write(data: string | Buffer, key?: readline.Key): void;
58
+ private _renderLine;
59
+ /**
60
+ * Asks the user for input with a specified prompt
61
+ */
62
+ question(query: string, callback: (answer: string) => void): void;
63
+ question(query: string, options: Abortable, callback: (answer: string) => void): void;
64
+ /**
65
+ * Gets the current cursor position
66
+ */
67
+ getCursorPos(): {
68
+ rows: number;
69
+ cols: number;
70
+ };
71
+ /**
72
+ * Prepends a listener for the specified event
73
+ */
74
+ prependListener(event: keyof InterfaceEvents, listener: (...args: any[]) => void): this;
75
+ /**
76
+ * Prepends a one-time listener for the specified event
77
+ */
78
+ prependOnceListener(event: keyof InterfaceEvents, listener: (...args: any[]) => void): this;
79
+ /**
80
+ * Sets the maximum number of listeners
81
+ */
82
+ setMaxListeners(): this;
83
+ /**
84
+ * Gets the maximum number of listeners
85
+ */
86
+ getMaxListeners(): number;
87
+ [Symbol.asyncIterator](): AsyncIteratorObject<string>;
88
+ [Symbol.asyncDispose](): Promise<void>;
89
+ rawListeners(event: keyof InterfaceEvents): ((...args: any[]) => void)[];
90
+ }
91
+ /**
92
+ * Creates a readline interface
93
+ * @param input The readable stream to read from
94
+ * @param output The writable stream to write to
95
+ * @param completer The completer function
96
+ * @param terminal Whether to use terminal features
97
+ * @returns A readline interface
98
+ */
99
+ export declare function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: readline.Completer | readline.AsyncCompleter, terminal?: boolean): Interface;
100
+ /**
101
+ * Creates a readline interface from options
102
+ * @param options The options for the interface
103
+ * @returns A readline interface
104
+ */
105
+ export declare function createInterface(options: readline.ReadLineOptions): Interface;
106
+ /**
107
+ * Clear the current line in the terminal
108
+ * @param stream The stream to clear the line on
109
+ * @param dir The direction to clear: -1 for left, 1 for right, 0 for entire line
110
+ */
111
+ export declare function clearLine(stream: NodeJS.WritableStream, dir: number): boolean;
112
+ /**
113
+ * Clear the screen down from the current position
114
+ * @param stream The stream to clear the screen on
115
+ */
116
+ export declare function clearScreenDown(stream: NodeJS.WritableStream): boolean;
117
+ /**
118
+ * Move the cursor in the terminal
119
+ * @param stream The stream to move the cursor on
120
+ * @param dx The number of characters to move horizontally
121
+ * @param dy The number of lines to move vertically
122
+ */
123
+ export declare function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number): boolean;
124
+ /**
125
+ * The `readline.emitKeypressEvents()` method causes the given Readable stream to begin emitting `'keypress'` events corresponding to received input.
126
+ *
127
+ * Optionally, interface specifies a `readline.Interface` instance for which autocompletion is disabled when copy-pasted input is detected.
128
+ *
129
+ * If the `stream` is a TTY, then it must be in raw mode.
130
+ *
131
+ * This is automatically called by any readline instance on its `input` if the `input` is a terminal. Closing the `readline` instance does not stop the `input` from emitting `'keypress'` events.
132
+ */
133
+ export declare function emitKeypressEvents(stream: NodeJS.ReadableStream, readlineInterface?: Interface | readline.Interface): void;
134
+ export {};