@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.
- package/dist/backends/backend.d.ts +19 -15
- package/dist/backends/backend.js +36 -19
- package/dist/backends/cow.d.ts +20 -30
- package/dist/backends/cow.js +83 -192
- package/dist/backends/fetch.d.ts +1 -0
- package/dist/backends/fetch.js +30 -30
- package/dist/backends/index.d.ts +1 -1
- package/dist/backends/index.js +1 -1
- package/dist/backends/memory.d.ts +5 -7
- package/dist/backends/memory.js +2 -3
- package/dist/backends/passthrough.d.ts +19 -23
- package/dist/backends/passthrough.js +98 -288
- package/dist/backends/port.d.ts +220 -0
- package/dist/backends/port.js +328 -0
- package/dist/backends/single_buffer.d.ts +59 -47
- package/dist/backends/single_buffer.js +468 -219
- package/dist/backends/store/fs.d.ts +25 -35
- package/dist/backends/store/fs.js +276 -315
- package/dist/backends/store/store.d.ts +10 -15
- package/dist/backends/store/store.js +11 -10
- package/dist/config.d.ts +3 -12
- package/dist/config.js +17 -19
- package/dist/context.d.ts +8 -21
- package/dist/context.js +33 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/contexts.d.ts +63 -0
- package/dist/internal/contexts.js +15 -0
- package/dist/internal/credentials.d.ts +2 -11
- package/dist/internal/credentials.js +0 -19
- package/dist/internal/devices.d.ts +18 -80
- package/dist/internal/devices.js +103 -316
- package/dist/internal/error.d.ts +9 -204
- package/dist/internal/error.js +19 -288
- package/dist/internal/file_index.d.ts +1 -1
- package/dist/internal/file_index.js +11 -11
- package/dist/internal/filesystem.d.ts +51 -94
- package/dist/internal/filesystem.js +21 -20
- package/dist/internal/index.d.ts +1 -2
- package/dist/internal/index.js +1 -2
- package/dist/internal/index_fs.d.ts +12 -30
- package/dist/internal/index_fs.js +37 -69
- package/dist/internal/inode.d.ts +140 -24
- package/dist/internal/inode.js +515 -66
- package/dist/mixins/async.js +52 -112
- package/dist/mixins/mutexed.d.ts +19 -18
- package/dist/mixins/mutexed.js +62 -64
- package/dist/mixins/readonly.d.ts +7 -6
- package/dist/mixins/readonly.js +24 -18
- package/dist/mixins/sync.js +8 -8
- package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
- package/dist/{vfs/path.js → path.js} +6 -9
- package/dist/polyfills.js +1 -1
- package/dist/readline.d.ts +134 -0
- package/dist/readline.js +623 -0
- package/dist/utils.d.ts +9 -37
- package/dist/utils.js +17 -85
- package/dist/vfs/acl.d.ts +42 -0
- package/dist/vfs/acl.js +268 -0
- package/dist/vfs/async.d.ts +9 -23
- package/dist/vfs/async.js +25 -27
- package/dist/vfs/config.d.ts +6 -18
- package/dist/vfs/config.js +8 -18
- package/dist/vfs/dir.d.ts +3 -3
- package/dist/vfs/dir.js +12 -12
- package/dist/vfs/file.d.ts +106 -0
- package/dist/vfs/file.js +244 -0
- package/dist/vfs/flags.d.ts +19 -0
- package/dist/vfs/flags.js +62 -0
- package/dist/vfs/index.d.ts +4 -10
- package/dist/vfs/index.js +4 -13
- package/dist/vfs/ioctl.d.ts +88 -0
- package/dist/vfs/ioctl.js +409 -0
- package/dist/vfs/promises.d.ts +81 -19
- package/dist/vfs/promises.js +404 -288
- package/dist/vfs/shared.d.ts +7 -37
- package/dist/vfs/shared.js +29 -85
- package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
- package/dist/{stats.js → vfs/stats.js} +11 -66
- package/dist/vfs/streams.d.ts +1 -0
- package/dist/vfs/streams.js +32 -27
- package/dist/vfs/sync.d.ts +3 -3
- package/dist/vfs/sync.js +263 -260
- package/dist/vfs/watchers.d.ts +2 -2
- package/dist/vfs/watchers.js +12 -12
- package/dist/vfs/xattr.d.ts +116 -0
- package/dist/vfs/xattr.js +201 -0
- package/package.json +5 -3
- package/readme.md +1 -1
- package/scripts/test.js +2 -2
- package/tests/assignment.ts +1 -1
- package/tests/backend/config.worker.js +4 -1
- package/tests/backend/fetch.test.ts +3 -0
- package/tests/backend/port.test.ts +19 -33
- package/tests/backend/remote.worker.js +4 -1
- package/tests/backend/single-buffer.test.ts +53 -0
- package/tests/backend/single-buffer.worker.js +30 -0
- package/tests/common/context.test.ts +3 -3
- package/tests/common/handle.test.ts +17 -12
- package/tests/common/mutex.test.ts +9 -9
- package/tests/common/path.test.ts +1 -1
- package/tests/common/readline.test.ts +104 -0
- package/tests/common.ts +4 -19
- package/tests/fetch/fetch.ts +2 -2
- package/tests/fs/append.test.ts +4 -4
- package/tests/fs/directory.test.ts +25 -25
- package/tests/fs/errors.test.ts +15 -19
- package/tests/fs/links.test.ts +4 -3
- package/tests/fs/open.test.ts +4 -21
- package/tests/fs/permissions.test.ts +14 -18
- package/tests/fs/read.test.ts +10 -9
- package/tests/fs/readFile.test.ts +10 -26
- package/tests/fs/rename.test.ts +4 -9
- package/tests/fs/stat.test.ts +8 -8
- package/tests/fs/streams.test.ts +2 -11
- package/tests/fs/times.test.ts +7 -7
- package/tests/fs/truncate.test.ts +8 -36
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +77 -13
- package/tests/fs/xattr.test.ts +85 -0
- package/tests/logs.js +22 -0
- package/tests/setup/context.ts +1 -1
- package/tests/setup/index.ts +3 -3
- package/tests/setup/port.ts +7 -1
- package/dist/backends/port/fs.d.ts +0 -84
- package/dist/backends/port/fs.js +0 -151
- package/dist/backends/port/rpc.d.ts +0 -77
- package/dist/backends/port/rpc.js +0 -100
- package/dist/backends/store/simple.d.ts +0 -20
- package/dist/backends/store/simple.js +0 -13
- package/dist/internal/file.d.ts +0 -359
- package/dist/internal/file.js +0 -751
- package/dist/internal/log.d.ts +0 -133
- package/dist/internal/log.js +0 -218
- package/tests/fs/writeFile.test.ts +0 -70
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { RequiredKeys } from 'utilium';
|
|
2
2
|
import type { FileSystem } from '../internal/filesystem.js';
|
|
3
|
-
type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' |
|
|
3
|
+
type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | string | ((arg: any) => boolean) | {
|
|
4
|
+
[Symbol.hasInstance](instance: any): boolean;
|
|
5
|
+
toString(): string;
|
|
6
|
+
};
|
|
4
7
|
/**
|
|
5
8
|
* Resolves the type of Backend.options from the options interface
|
|
6
9
|
* @category Backends and Configuration
|
|
@@ -8,24 +11,17 @@ type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undef
|
|
|
8
11
|
export type OptionsConfig<T> = {
|
|
9
12
|
[K in keyof T]: {
|
|
10
13
|
/**
|
|
11
|
-
* The
|
|
14
|
+
* The type of the option. Can be a:
|
|
15
|
+
* - string given by `typeof`
|
|
16
|
+
* - string that is the name of the class (e.g. `'Map'`)
|
|
17
|
+
* - object with a `Symbol.hasInstance` property
|
|
18
|
+
* - function that returns a boolean
|
|
12
19
|
*/
|
|
13
20
|
type: OptionType | readonly OptionType[];
|
|
14
|
-
/**
|
|
15
|
-
* Description of the option. Used in error messages and documentation.
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
description?: string;
|
|
19
21
|
/**
|
|
20
22
|
* Whether or not the option is required (optional can be set to null or undefined). Defaults to false.
|
|
21
23
|
*/
|
|
22
24
|
required: K extends RequiredKeys<T> ? true : false;
|
|
23
|
-
/**
|
|
24
|
-
* A custom validation function to check if the option is valid.
|
|
25
|
-
* When async, resolves if valid and rejects if not.
|
|
26
|
-
* When sync, it will throw an error if not valid.
|
|
27
|
-
*/
|
|
28
|
-
validator?(opt: T[K]): void | Promise<void>;
|
|
29
25
|
};
|
|
30
26
|
};
|
|
31
27
|
/**
|
|
@@ -64,7 +60,7 @@ export interface Backend<FS extends FileSystem = FileSystem, TOptions extends ob
|
|
|
64
60
|
* 'false' if the API is unavailable
|
|
65
61
|
*
|
|
66
62
|
*/
|
|
67
|
-
isAvailable?(): boolean | Promise<boolean>;
|
|
63
|
+
isAvailable?(config: TOptions): boolean | Promise<boolean>;
|
|
68
64
|
}
|
|
69
65
|
/**
|
|
70
66
|
* Gets the options type of a backend
|
|
@@ -83,12 +79,20 @@ export type FilesystemOf<T extends Backend> = T extends Backend<infer FS> ? FS :
|
|
|
83
79
|
* @internal
|
|
84
80
|
*/
|
|
85
81
|
export declare function isBackend(arg: unknown): arg is Backend;
|
|
82
|
+
/**
|
|
83
|
+
* Use a function as the type of an option, but don't treat it as a class.
|
|
84
|
+
*
|
|
85
|
+
* Optionally sets the name of a function, useful for error messages.
|
|
86
|
+
* @category Backends and Configuration
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export declare function _fnOpt<const T>(name: string | null | undefined, fn: (arg: T) => boolean): (arg: T) => boolean;
|
|
86
90
|
/**
|
|
87
91
|
* Checks that `options` object is valid for the file system options.
|
|
88
92
|
* @category Backends and Configuration
|
|
89
93
|
* @internal
|
|
90
94
|
*/
|
|
91
|
-
export declare function checkOptions<T extends Backend>(backend: T, options: Record<string, unknown>):
|
|
95
|
+
export declare function checkOptions<T extends Backend>(backend: T, options: Record<string, unknown>): void;
|
|
92
96
|
/**
|
|
93
97
|
* Specifies a file system backend type and its options.
|
|
94
98
|
*
|
package/dist/backends/backend.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents */
|
|
2
|
+
import { withErrno } from 'kerium';
|
|
3
|
+
import { debug, err } from 'kerium/log';
|
|
3
4
|
/**
|
|
4
5
|
* @category Backends and Configuration
|
|
5
6
|
* @internal
|
|
@@ -7,38 +8,54 @@ import { debug, err } from '../internal/log.js';
|
|
|
7
8
|
export function isBackend(arg) {
|
|
8
9
|
return arg != null && typeof arg == 'object' && 'create' in arg && typeof arg.create == 'function';
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Use a function as the type of an option, but don't treat it as a class.
|
|
13
|
+
*
|
|
14
|
+
* Optionally sets the name of a function, useful for error messages.
|
|
15
|
+
* @category Backends and Configuration
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function _fnOpt(name, fn) {
|
|
19
|
+
Object.defineProperty(fn, 'prototype', { value: undefined });
|
|
20
|
+
if (name)
|
|
21
|
+
Object.defineProperty(fn, 'name', { value: name });
|
|
22
|
+
return fn;
|
|
23
|
+
}
|
|
10
24
|
/**
|
|
11
25
|
* Checks that `options` object is valid for the file system options.
|
|
12
26
|
* @category Backends and Configuration
|
|
13
27
|
* @internal
|
|
14
28
|
*/
|
|
15
|
-
export
|
|
29
|
+
export function checkOptions(backend, options) {
|
|
16
30
|
if (typeof options != 'object' || options === null) {
|
|
17
|
-
throw err(
|
|
31
|
+
throw err(withErrno('EINVAL', 'Invalid options'));
|
|
18
32
|
}
|
|
19
33
|
// Check for required options.
|
|
20
34
|
for (const [optName, opt] of Object.entries(backend.options)) {
|
|
21
35
|
const value = options === null || options === void 0 ? void 0 : options[optName];
|
|
22
36
|
if (value === undefined || value === null) {
|
|
23
37
|
if (!opt.required) {
|
|
24
|
-
debug('
|
|
38
|
+
debug('Using default for option: ' + optName);
|
|
25
39
|
continue;
|
|
26
40
|
}
|
|
27
|
-
throw err(
|
|
28
|
-
}
|
|
29
|
-
const isType = (type, _ = value) => (typeof type == 'function' ? value instanceof type : typeof value === type);
|
|
30
|
-
if (Array.isArray(opt.type) ? !opt.type.some(v => isType(v)) : !isType(opt.type)) {
|
|
31
|
-
// The type of the value as a string
|
|
32
|
-
const type = typeof value == 'object' && 'constructor' in value ? value.constructor.name : typeof value;
|
|
33
|
-
// The expected type (as a string)
|
|
34
|
-
const name = (type) => (typeof type == 'function' ? type.name : type);
|
|
35
|
-
const expected = Array.isArray(opt.type) ? `one of ${opt.type.map(name).join(', ')}` : name(opt.type);
|
|
36
|
-
throw err(new ErrnoError(Errno.EINVAL, `Incorrect type for "${optName}": ${type} (expected ${expected})`));
|
|
41
|
+
throw err(withErrno('EINVAL', 'Missing required option: ' + optName));
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
const isType = (type, _ = value) => {
|
|
44
|
+
var _a;
|
|
45
|
+
return typeof type == 'function'
|
|
46
|
+
? Symbol.hasInstance in type && type.prototype
|
|
47
|
+
? value instanceof type
|
|
48
|
+
: type(value)
|
|
49
|
+
: typeof value === type || ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) === type;
|
|
50
|
+
};
|
|
51
|
+
if (Array.isArray(opt.type) ? opt.type.some(v => isType(v)) : isType(opt.type))
|
|
52
|
+
continue;
|
|
53
|
+
// The type of the value as a string
|
|
54
|
+
const type = typeof value == 'object' && 'constructor' in value ? value.constructor.name : typeof value;
|
|
55
|
+
// The expected type (as a string)
|
|
56
|
+
const name = (type) => (typeof type == 'function' ? (type.name != 'type' ? type.name : type.toString()) : type);
|
|
57
|
+
const expected = Array.isArray(opt.type) ? `one of ${opt.type.map(name).join(', ')}` : name(opt.type);
|
|
58
|
+
throw err(withErrno('EINVAL', `Incorrect type for "${optName}": ${type} (expected ${expected})`));
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
61
|
/**
|
package/dist/backends/cow.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { File } from '../internal/file.js';
|
|
2
1
|
import type { CreationOptions, StreamOptions, UsageInfo } from '../internal/filesystem.js';
|
|
3
2
|
import type { InodeLike } from '../internal/inode.js';
|
|
4
|
-
import type { Stats } from '../stats.js';
|
|
5
|
-
import { FileSystem } from '../internal/filesystem.js';
|
|
6
3
|
import { EventEmitter } from 'eventemitter3';
|
|
7
4
|
import { type MountConfiguration } from '../config.js';
|
|
5
|
+
import { FileSystem } from '../internal/filesystem.js';
|
|
8
6
|
/**
|
|
9
7
|
* Configuration options for CoW.
|
|
10
8
|
* @category Backends and Configuration
|
|
@@ -17,16 +15,14 @@ export interface CopyOnWriteOptions {
|
|
|
17
15
|
/** @see {@link Journal} */
|
|
18
16
|
journal?: Journal;
|
|
19
17
|
}
|
|
20
|
-
/**
|
|
21
|
-
* @hidden @deprecated use `CopyOnWriteOptions`
|
|
22
|
-
*/
|
|
23
|
-
export type OverlayOptions = CopyOnWriteOptions;
|
|
24
18
|
declare const journalOperations: readonly ["delete"];
|
|
25
19
|
/**
|
|
20
|
+
* @category Internals
|
|
26
21
|
* @internal
|
|
27
22
|
*/
|
|
28
23
|
export type JournalOperation = (typeof journalOperations)[number];
|
|
29
24
|
/**
|
|
25
|
+
* @category Internals
|
|
30
26
|
* @internal
|
|
31
27
|
*/
|
|
32
28
|
export interface JournalEntry {
|
|
@@ -35,6 +31,7 @@ export interface JournalEntry {
|
|
|
35
31
|
}
|
|
36
32
|
/**
|
|
37
33
|
* Tracks various operations for the CoW backend
|
|
34
|
+
* @category Internals
|
|
38
35
|
* @internal
|
|
39
36
|
*/
|
|
40
37
|
export declare class Journal extends EventEmitter<{
|
|
@@ -54,6 +51,7 @@ export declare class Journal extends EventEmitter<{
|
|
|
54
51
|
/**
|
|
55
52
|
* Using a readable file system as a base, writes are done to a writable file system.
|
|
56
53
|
* @internal
|
|
54
|
+
* @category Internals
|
|
57
55
|
*/
|
|
58
56
|
export declare class CopyOnWriteFS extends FileSystem {
|
|
59
57
|
/** The file system that initially populates this file system. */
|
|
@@ -75,28 +73,28 @@ export declare class CopyOnWriteFS extends FileSystem {
|
|
|
75
73
|
* @todo Consider trying to track information on the writable as well
|
|
76
74
|
*/
|
|
77
75
|
usage(): UsageInfo;
|
|
78
|
-
sync(
|
|
79
|
-
syncSync(
|
|
76
|
+
sync(): Promise<void>;
|
|
77
|
+
syncSync(): void;
|
|
80
78
|
read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
|
|
81
79
|
readSync(path: string, buffer: Uint8Array, offset: number, end: number): void;
|
|
82
80
|
write(path: string, buffer: Uint8Array, offset: number): Promise<void>;
|
|
83
81
|
writeSync(path: string, buffer: Uint8Array, offset: number): void;
|
|
84
82
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
85
83
|
renameSync(oldPath: string, newPath: string): void;
|
|
86
|
-
stat(path: string): Promise<
|
|
87
|
-
statSync(path: string):
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
createFile(path: string,
|
|
91
|
-
createFileSync(path: string,
|
|
84
|
+
stat(path: string): Promise<InodeLike>;
|
|
85
|
+
statSync(path: string): InodeLike;
|
|
86
|
+
touch(path: string, metadata: InodeLike): Promise<void>;
|
|
87
|
+
touchSync(path: string, metadata: InodeLike): void;
|
|
88
|
+
createFile(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
89
|
+
createFileSync(path: string, options: CreationOptions): InodeLike;
|
|
92
90
|
link(srcpath: string, dstpath: string): Promise<void>;
|
|
93
91
|
linkSync(srcpath: string, dstpath: string): void;
|
|
94
92
|
unlink(path: string): Promise<void>;
|
|
95
93
|
unlinkSync(path: string): void;
|
|
96
94
|
rmdir(path: string): Promise<void>;
|
|
97
95
|
rmdirSync(path: string): void;
|
|
98
|
-
mkdir(path: string,
|
|
99
|
-
mkdirSync(path: string,
|
|
96
|
+
mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
97
|
+
mkdirSync(path: string, options: CreationOptions): InodeLike;
|
|
100
98
|
readdir(path: string): Promise<string[]>;
|
|
101
99
|
readdirSync(path: string): string[];
|
|
102
100
|
streamRead(path: string, options: StreamOptions): ReadableStream;
|
|
@@ -125,11 +123,6 @@ export declare class CopyOnWriteFS extends FileSystem {
|
|
|
125
123
|
private copyToWritableSync;
|
|
126
124
|
private copyToWritable;
|
|
127
125
|
}
|
|
128
|
-
/**
|
|
129
|
-
* @hidden @deprecated use `CopyOnWriteFS`
|
|
130
|
-
*/
|
|
131
|
-
export declare class OverlayFS extends CopyOnWriteFS {
|
|
132
|
-
}
|
|
133
126
|
declare const _CopyOnWrite: {
|
|
134
127
|
readonly name: "CopyOnWrite";
|
|
135
128
|
readonly options: {
|
|
@@ -149,21 +142,18 @@ declare const _CopyOnWrite: {
|
|
|
149
142
|
readonly create: (options: CopyOnWriteOptions) => Promise<CopyOnWriteFS>;
|
|
150
143
|
};
|
|
151
144
|
type _CopyOnWrite = typeof _CopyOnWrite;
|
|
152
|
-
export interface CopyOnWrite extends _CopyOnWrite {
|
|
153
|
-
}
|
|
154
145
|
/**
|
|
155
146
|
* Overlay makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
156
147
|
* Deletes are persisted via metadata stored on the writable file system.
|
|
157
148
|
* @category Backends and Configuration
|
|
158
|
-
* @internal
|
|
159
149
|
*/
|
|
160
|
-
export
|
|
161
|
-
export interface Overlay extends _CopyOnWrite {
|
|
150
|
+
export interface CopyOnWrite extends _CopyOnWrite {
|
|
162
151
|
}
|
|
163
152
|
/**
|
|
164
|
-
*
|
|
153
|
+
* Overlay makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
154
|
+
* Deletes are persisted via metadata stored on the writable file system.
|
|
165
155
|
* @category Backends and Configuration
|
|
166
|
-
* @internal
|
|
156
|
+
* @internal
|
|
167
157
|
*/
|
|
168
|
-
export declare const
|
|
158
|
+
export declare const CopyOnWrite: CopyOnWrite;
|
|
169
159
|
export {};
|