@zenfs/core 0.9.6 → 0.10.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/AsyncStore.d.ts +3 -2
- package/dist/backends/AsyncStore.js +40 -33
- package/dist/backends/Fetch.d.ts +84 -0
- package/dist/backends/Fetch.js +171 -0
- package/dist/backends/InMemory.d.ts +1 -1
- package/dist/backends/Index.d.ts +7 -10
- package/dist/backends/Index.js +26 -24
- package/dist/backends/Locked.d.ts +11 -11
- package/dist/backends/Locked.js +50 -49
- package/dist/backends/Overlay.js +22 -22
- package/dist/backends/SyncStore.d.ts +6 -6
- package/dist/backends/SyncStore.js +30 -30
- package/dist/backends/backend.d.ts +5 -4
- package/dist/backends/backend.js +6 -6
- package/dist/backends/port/fs.d.ts +124 -0
- package/dist/backends/port/fs.js +241 -0
- package/dist/backends/port/rpc.d.ts +60 -0
- package/dist/backends/port/rpc.js +71 -0
- package/dist/backends/port/store.d.ts +30 -0
- package/dist/backends/port/store.js +142 -0
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +9 -11
- package/dist/config.js +13 -13
- package/dist/emulation/async.d.ts +76 -77
- package/dist/emulation/async.js +45 -45
- package/dist/emulation/dir.js +8 -7
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/path.d.ts +3 -2
- package/dist/emulation/path.js +19 -45
- package/dist/emulation/promises.d.ts +112 -113
- package/dist/emulation/promises.js +167 -173
- package/dist/emulation/shared.d.ts +6 -17
- package/dist/emulation/shared.js +9 -9
- package/dist/emulation/streams.js +3 -2
- package/dist/emulation/sync.d.ts +71 -64
- package/dist/emulation/sync.js +62 -63
- package/dist/{ApiError.d.ts → error.d.ts} +15 -15
- package/dist/error.js +292 -0
- package/dist/file.d.ts +6 -4
- package/dist/file.js +17 -9
- package/dist/filesystem.d.ts +1 -1
- package/dist/filesystem.js +18 -15
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/mutex.js +4 -3
- package/dist/stats.d.ts +7 -7
- package/dist/stats.js +50 -10
- package/dist/utils.d.ts +10 -9
- package/dist/utils.js +15 -15
- package/package.json +5 -5
- package/readme.md +19 -11
- package/src/backends/AsyncStore.ts +42 -36
- package/src/backends/Fetch.ts +230 -0
- package/src/backends/Index.ts +33 -29
- package/src/backends/Locked.ts +50 -49
- package/src/backends/Overlay.ts +24 -24
- package/src/backends/SyncStore.ts +34 -34
- package/src/backends/backend.ts +13 -11
- package/src/backends/port/fs.ts +308 -0
- package/src/backends/port/readme.md +59 -0
- package/src/backends/port/rpc.ts +144 -0
- package/src/backends/port/store.ts +187 -0
- package/src/config.ts +25 -29
- package/src/emulation/async.ts +191 -199
- package/src/emulation/dir.ts +8 -8
- package/src/emulation/index.ts +1 -1
- package/src/emulation/path.ts +25 -49
- package/src/emulation/promises.ts +286 -287
- package/src/emulation/shared.ts +14 -23
- package/src/emulation/streams.ts +9 -8
- package/src/emulation/sync.ts +182 -182
- package/src/{ApiError.ts → error.ts} +91 -89
- package/src/file.ts +23 -13
- package/src/filesystem.ts +26 -22
- package/src/index.ts +4 -1
- package/src/mutex.ts +6 -4
- package/src/stats.ts +32 -23
- package/src/utils.ts +23 -24
- package/tsconfig.json +4 -3
- package/dist/ApiError.js +0 -292
package/src/config.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrnoError, Errno } from './error.js';
|
|
2
2
|
import type { Backend, BackendConfiguration } from './backends/backend.js';
|
|
3
3
|
import { checkOptions, isBackend, isBackendConfig } from './backends/backend.js';
|
|
4
4
|
import * as fs from './emulation/index.js';
|
|
5
|
-
import { setCred, type
|
|
5
|
+
import { setCred, type MountObject } from './emulation/shared.js';
|
|
6
6
|
import { FileSystem } from './filesystem.js';
|
|
7
|
+
import type { AbsolutePath } from './emulation/path.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Configuration for a specific mount point
|
|
10
11
|
*/
|
|
11
|
-
export type MountConfiguration<FS extends FileSystem = FileSystem, TOptions extends object = object> = FS | BackendConfiguration<FS, TOptions
|
|
12
|
+
export type MountConfiguration<FS extends FileSystem = FileSystem, TOptions extends object = object> = FS | BackendConfiguration<Backend<FS, TOptions>> | Backend<FS, TOptions>;
|
|
12
13
|
|
|
13
14
|
function isMountConfig(arg: unknown): arg is MountConfiguration {
|
|
14
15
|
return isBackendConfig(arg) || isBackend(arg) || arg instanceof FileSystem;
|
|
@@ -20,11 +21,11 @@ function isMountConfig(arg: unknown): arg is MountConfiguration {
|
|
|
20
21
|
*/
|
|
21
22
|
export async function resolveMountConfig<FS extends FileSystem, TOptions extends object = object>(config: MountConfiguration<FS, TOptions>, _depth = 0): Promise<FS> {
|
|
22
23
|
if (typeof config !== 'object' || config == null) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid options on mount configuration');
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
if (!isMountConfig(config)) {
|
|
27
|
-
throw new
|
|
28
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid mount configuration');
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
if (config instanceof FileSystem) {
|
|
@@ -32,7 +33,7 @@ export async function resolveMountConfig<FS extends FileSystem, TOptions extends
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
if (isBackend(config)) {
|
|
35
|
-
config = <BackendConfiguration<FS, TOptions
|
|
36
|
+
config = <BackendConfiguration<Backend<FS, TOptions>>>{ backend: config };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
for (const [key, value] of Object.entries(config)) {
|
|
@@ -45,16 +46,16 @@ export async function resolveMountConfig<FS extends FileSystem, TOptions extends
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
if (_depth > 10) {
|
|
48
|
-
throw new
|
|
49
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid configuration, too deep and possibly infinite');
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
config[key] = await resolveMountConfig(value, ++_depth);
|
|
52
|
+
(<Record<string, FileSystem>>config)[key] = await resolveMountConfig(value, ++_depth);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
const { backend } = config;
|
|
55
56
|
|
|
56
57
|
if (!(await backend.isAvailable())) {
|
|
57
|
-
throw new
|
|
58
|
+
throw new ErrnoError(Errno.EPERM, 'Backend not available: ' + backend);
|
|
58
59
|
}
|
|
59
60
|
checkOptions(backend, config);
|
|
60
61
|
const mount = backend.create(config);
|
|
@@ -63,39 +64,34 @@ export async function resolveMountConfig<FS extends FileSystem, TOptions extends
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
+
* Configuration
|
|
67
68
|
*/
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Configuration for the file systems
|
|
76
|
-
*/
|
|
77
|
-
export type Configuration = MountConfiguration | MappingConfiguration;
|
|
69
|
+
export interface Configuration {
|
|
70
|
+
mounts: Record<AbsolutePath, MountConfiguration>;
|
|
71
|
+
uid?: number;
|
|
72
|
+
gid?: number;
|
|
73
|
+
}
|
|
78
74
|
|
|
79
75
|
/**
|
|
80
76
|
* Creates filesystems with the given configuration, and initializes ZenFS with it.
|
|
81
77
|
* @see Configuration for more info on the configuration object.
|
|
82
78
|
*/
|
|
83
|
-
export async function configure(config: Configuration): Promise<void> {
|
|
84
|
-
const uid = 'uid' in config ?
|
|
85
|
-
const gid = 'gid' in config ?
|
|
79
|
+
export async function configure(config: MountConfiguration | Configuration): Promise<void> {
|
|
80
|
+
const uid = 'uid' in config ? config.uid || 0 : 0;
|
|
81
|
+
const gid = 'gid' in config ? config.gid || 0 : 0;
|
|
86
82
|
|
|
87
83
|
if (isMountConfig(config)) {
|
|
88
84
|
// single FS
|
|
89
|
-
config = { '/': config };
|
|
85
|
+
config = { mounts: { '/': config } };
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
for (const [point, value] of Object.entries(config)) {
|
|
93
|
-
if (point
|
|
94
|
-
|
|
88
|
+
for (const [point, value] of Object.entries(config.mounts) as [AbsolutePath, MountConfiguration][]) {
|
|
89
|
+
if (!point.startsWith('/')) {
|
|
90
|
+
throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
|
|
95
91
|
}
|
|
96
|
-
config[point] = await resolveMountConfig(value);
|
|
92
|
+
config.mounts[point] = await resolveMountConfig(value);
|
|
97
93
|
}
|
|
98
94
|
|
|
99
|
-
fs.
|
|
95
|
+
fs.mountObject(config.mounts as MountObject);
|
|
100
96
|
setCred({ uid, gid, suid: uid, sgid: gid, euid: uid, egid: gid });
|
|
101
97
|
}
|