@zenfs/core 1.9.2 → 1.9.4
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 +16 -2
- package/dist/backends/backend.js +9 -2
- package/dist/backends/fetch.d.ts +9 -0
- package/dist/backends/fetch.js +13 -3
- package/dist/backends/memory.d.ts +2 -0
- package/dist/backends/memory.js +2 -0
- package/dist/backends/overlay.d.ts +2 -0
- package/dist/backends/overlay.js +1 -0
- package/dist/backends/passthrough.d.ts +4 -0
- package/dist/backends/port/fs.d.ts +8 -2
- package/dist/backends/port/fs.js +6 -0
- package/dist/backends/store/fs.d.ts +2 -4
- package/dist/backends/store/fs.js +2 -4
- package/dist/backends/store/map.d.ts +6 -0
- package/dist/backends/store/map.js +4 -0
- package/dist/backends/store/simple.d.ts +3 -0
- package/dist/backends/store/simple.js +1 -0
- package/dist/backends/store/store.d.ts +12 -1
- package/dist/backends/store/store.js +5 -1
- package/dist/config.d.ts +9 -15
- package/dist/config.js +8 -5
- package/dist/context.d.ts +3 -4
- package/dist/context.js +1 -1
- package/dist/internal/credentials.d.ts +9 -0
- package/dist/internal/credentials.js +7 -0
- package/dist/internal/devices.d.ts +14 -0
- package/dist/internal/devices.js +10 -0
- package/dist/internal/error.d.ts +6 -0
- package/dist/internal/error.js +3 -0
- package/dist/internal/file.d.ts +23 -0
- package/dist/internal/file.js +23 -1
- package/dist/internal/file_index.d.ts +2 -1
- package/dist/internal/file_index.js +2 -1
- package/dist/internal/filesystem.d.ts +9 -0
- package/dist/internal/filesystem.js +1 -0
- package/dist/internal/index_fs.d.ts +3 -1
- package/dist/internal/index_fs.js +7 -3
- package/dist/internal/inode.d.ts +8 -0
- package/dist/internal/inode.js +1 -0
- package/dist/mixins/async.d.ts +6 -2
- package/dist/mixins/async.js +1 -1
- package/dist/mixins/mutexed.d.ts +6 -0
- package/dist/mixins/mutexed.js +6 -0
- package/dist/mixins/readonly.d.ts +1 -0
- package/dist/mixins/readonly.js +1 -0
- package/dist/mixins/shared.d.ts +3 -0
- package/dist/mixins/sync.d.ts +1 -0
- package/dist/mixins/sync.js +1 -0
- package/dist/vfs/promises.d.ts +2 -2
- package/dist/vfs/promises.js +71 -78
- package/dist/vfs/shared.d.ts +14 -1
- package/dist/vfs/shared.js +4 -6
- package/dist/vfs/sync.d.ts +2 -2
- package/dist/vfs/sync.js +48 -48
- package/dist/vfs/types.d.ts +1 -13
- package/package.json +1 -1
- package/readme.md +4 -0
- package/tests/backend/fetch.test.ts +3 -2
- package/dist/vfs/cache.d.ts +0 -46
- package/dist/vfs/cache.js +0 -75
|
@@ -3,6 +3,7 @@ import type { FileSystem } from '../internal/filesystem.js';
|
|
|
3
3
|
type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | (abstract new (...args: any[]) => any);
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the type of Backend.options from the options interface
|
|
6
|
+
* @category Backends and Configuration
|
|
6
7
|
*/
|
|
7
8
|
export type OptionsConfig<T> = {
|
|
8
9
|
[K in keyof T]: {
|
|
@@ -29,6 +30,7 @@ export type OptionsConfig<T> = {
|
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
* Configuration options shared by backends and `Configuration`
|
|
33
|
+
* @category Backends and Configuration
|
|
32
34
|
*/
|
|
33
35
|
export interface SharedConfig {
|
|
34
36
|
/**
|
|
@@ -38,6 +40,7 @@ export interface SharedConfig {
|
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* A backend
|
|
43
|
+
* @category Backends and Configuration
|
|
41
44
|
*/
|
|
42
45
|
export interface Backend<FS extends FileSystem = FileSystem, TOptions extends object = object> {
|
|
43
46
|
/**
|
|
@@ -65,18 +68,24 @@ export interface Backend<FS extends FileSystem = FileSystem, TOptions extends ob
|
|
|
65
68
|
}
|
|
66
69
|
/**
|
|
67
70
|
* Gets the options type of a backend
|
|
71
|
+
* @category Backends and Configuration
|
|
68
72
|
* @internal
|
|
69
73
|
*/
|
|
70
74
|
export type OptionsOf<T extends Backend> = T extends Backend<FileSystem, infer TOptions> ? TOptions : never;
|
|
71
75
|
/**
|
|
72
76
|
* Gets the FileSystem type for a backend
|
|
77
|
+
* @category Backends and Configuration
|
|
73
78
|
* @internal
|
|
74
79
|
*/
|
|
75
80
|
export type FilesystemOf<T extends Backend> = T extends Backend<infer FS> ? FS : never;
|
|
76
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* @category Backends and Configuration
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
77
85
|
export declare function isBackend(arg: unknown): arg is Backend;
|
|
78
86
|
/**
|
|
79
87
|
* Checks that `options` object is valid for the file system options.
|
|
88
|
+
* @category Backends and Configuration
|
|
80
89
|
* @internal
|
|
81
90
|
*/
|
|
82
91
|
export declare function checkOptions<T extends Backend>(backend: T, options: Record<string, unknown>): Promise<void>;
|
|
@@ -86,10 +95,15 @@ export declare function checkOptions<T extends Backend>(backend: T, options: Rec
|
|
|
86
95
|
* Individual options can recursively contain BackendConfiguration objects for values that require file systems.
|
|
87
96
|
*
|
|
88
97
|
* The configuration for each file system corresponds to that file system's option object passed to its `create()` method.
|
|
98
|
+
*
|
|
99
|
+
* @category Backends and Configuration
|
|
89
100
|
*/
|
|
90
101
|
export type BackendConfiguration<T extends Backend> = OptionsOf<T> & Partial<SharedConfig> & {
|
|
91
102
|
backend: T;
|
|
92
103
|
};
|
|
93
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
* @category Backends and Configuration
|
|
107
|
+
*/
|
|
94
108
|
export declare function isBackendConfig<T extends Backend>(arg: unknown): arg is BackendConfiguration<T>;
|
|
95
109
|
export {};
|
package/dist/backends/backend.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Errno, ErrnoError } from '../internal/error.js';
|
|
2
2
|
import { debug, err } from '../internal/log.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* @category Backends and Configuration
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export function isBackend(arg) {
|
|
5
8
|
return arg != null && typeof arg == 'object' && 'create' in arg && typeof arg.create == 'function';
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Checks that `options` object is valid for the file system options.
|
|
12
|
+
* @category Backends and Configuration
|
|
9
13
|
* @internal
|
|
10
14
|
*/
|
|
11
15
|
export async function checkOptions(backend, options) {
|
|
@@ -37,7 +41,10 @@ export async function checkOptions(backend, options) {
|
|
|
37
41
|
// Otherwise: All good!
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* @category Backends and Configuration
|
|
47
|
+
*/
|
|
41
48
|
export function isBackendConfig(arg) {
|
|
42
49
|
return arg != null && typeof arg == 'object' && 'backend' in arg && isBackend(arg.backend);
|
|
43
50
|
}
|
package/dist/backends/fetch.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { IndexFS } from '../internal/index_fs.js';
|
|
|
4
4
|
import type { SharedConfig } from './backend.js';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for FetchFS.
|
|
7
|
+
* @category Backends and Configuration
|
|
7
8
|
*/
|
|
8
9
|
export interface FetchOptions extends SharedConfig {
|
|
9
10
|
/**
|
|
@@ -33,6 +34,11 @@ export declare class FetchFS extends IndexFS {
|
|
|
33
34
|
protected baseUrl: string;
|
|
34
35
|
protected requestInit: RequestInit;
|
|
35
36
|
protected remoteWrite?: boolean | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* @internal @hidden
|
|
39
|
+
*/
|
|
40
|
+
_asyncDone: Promise<unknown>;
|
|
41
|
+
protected _async(p: Promise<unknown>): void;
|
|
36
42
|
constructor(index: Index, baseUrl: string, requestInit?: RequestInit, remoteWrite?: boolean | undefined);
|
|
37
43
|
protected remove(path: string): Promise<void>;
|
|
38
44
|
protected removeSync(path: string): void;
|
|
@@ -67,5 +73,8 @@ declare const _Fetch: {
|
|
|
67
73
|
type _Fetch = typeof _Fetch;
|
|
68
74
|
export interface Fetch extends _Fetch {
|
|
69
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @category Backends and Configuration
|
|
78
|
+
*/
|
|
70
79
|
export declare const Fetch: Fetch;
|
|
71
80
|
export {};
|
package/dist/backends/fetch.js
CHANGED
|
@@ -27,17 +27,24 @@ function parseError(path, fs) {
|
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
29
|
export class FetchFS extends IndexFS {
|
|
30
|
+
_async(p) {
|
|
31
|
+
this._asyncDone = this._asyncDone.then(() => p);
|
|
32
|
+
}
|
|
30
33
|
constructor(index, baseUrl, requestInit = {}, remoteWrite) {
|
|
31
34
|
super(0x206e6673, 'nfs', index);
|
|
32
35
|
this.baseUrl = baseUrl;
|
|
33
36
|
this.requestInit = requestInit;
|
|
34
37
|
this.remoteWrite = remoteWrite;
|
|
38
|
+
/**
|
|
39
|
+
* @internal @hidden
|
|
40
|
+
*/
|
|
41
|
+
this._asyncDone = Promise.resolve();
|
|
35
42
|
}
|
|
36
43
|
async remove(path) {
|
|
37
44
|
await requests.remove(this.baseUrl + path, { warn, cacheOnly: !this.remoteWrite }, this.requestInit);
|
|
38
45
|
}
|
|
39
46
|
removeSync(path) {
|
|
40
|
-
|
|
47
|
+
this._async(requests.remove(this.baseUrl + path, { warn, cacheOnly: !this.remoteWrite }, this.requestInit));
|
|
41
48
|
}
|
|
42
49
|
async read(path, buffer, offset = 0, end) {
|
|
43
50
|
const inode = this.index.get(path);
|
|
@@ -65,7 +72,7 @@ export class FetchFS extends IndexFS {
|
|
|
65
72
|
if (!data)
|
|
66
73
|
throw ErrnoError.With('ENODATA', path, 'read');
|
|
67
74
|
if (missing.length) {
|
|
68
|
-
|
|
75
|
+
this._async(requests.get(this.baseUrl + path, { start: offset, end, size: inode.size, warn }));
|
|
69
76
|
throw ErrnoError.With('EAGAIN', path, 'read');
|
|
70
77
|
}
|
|
71
78
|
buffer.set(data);
|
|
@@ -74,7 +81,7 @@ export class FetchFS extends IndexFS {
|
|
|
74
81
|
await requests.set(this.baseUrl + path, data, { offset, warn, cacheOnly: !this.remoteWrite }, this.requestInit).catch(parseError(path, this));
|
|
75
82
|
}
|
|
76
83
|
writeSync(path, data, offset) {
|
|
77
|
-
|
|
84
|
+
this._async(requests.set(this.baseUrl + path, data, { offset, warn, cacheOnly: !this.remoteWrite }, this.requestInit).catch(parseError(path, this)));
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
const _Fetch = {
|
|
@@ -116,4 +123,7 @@ const _Fetch = {
|
|
|
116
123
|
return fs;
|
|
117
124
|
},
|
|
118
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* @category Backends and Configuration
|
|
128
|
+
*/
|
|
119
129
|
export const Fetch = _Fetch;
|
|
@@ -2,6 +2,7 @@ import { StoreFS } from './store/fs.js';
|
|
|
2
2
|
import { SyncMapTransaction, type SyncMapStore } from './store/map.js';
|
|
3
3
|
/**
|
|
4
4
|
* A simple in-memory store
|
|
5
|
+
* @category Stores and Transactions
|
|
5
6
|
*/
|
|
6
7
|
export declare class InMemoryStore extends Map<number, Uint8Array> implements SyncMapStore {
|
|
7
8
|
readonly label?: string | undefined;
|
|
@@ -30,6 +31,7 @@ export interface InMemory extends _InMemory {
|
|
|
30
31
|
/**
|
|
31
32
|
* A simple in-memory file system backed by an InMemoryStore.
|
|
32
33
|
* Files are not persisted across page loads.
|
|
34
|
+
* @category Backends and Configuration
|
|
33
35
|
*/
|
|
34
36
|
export declare const InMemory: InMemory;
|
|
35
37
|
export {};
|
package/dist/backends/memory.js
CHANGED
|
@@ -2,6 +2,7 @@ import { StoreFS } from './store/fs.js';
|
|
|
2
2
|
import { SyncMapTransaction } from './store/map.js';
|
|
3
3
|
/**
|
|
4
4
|
* A simple in-memory store
|
|
5
|
+
* @category Stores and Transactions
|
|
5
6
|
*/
|
|
6
7
|
export class InMemoryStore extends Map {
|
|
7
8
|
constructor(label) {
|
|
@@ -32,5 +33,6 @@ const _InMemory = {
|
|
|
32
33
|
/**
|
|
33
34
|
* A simple in-memory file system backed by an InMemoryStore.
|
|
34
35
|
* Files are not persisted across page loads.
|
|
36
|
+
* @category Backends and Configuration
|
|
35
37
|
*/
|
|
36
38
|
export const InMemory = _InMemory;
|
|
@@ -5,6 +5,7 @@ import type { InodeLike } from '../internal/inode.js';
|
|
|
5
5
|
import { FileSystem } from '../internal/filesystem.js';
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for OverlayFS instances.
|
|
8
|
+
* @category Backends and Configuration
|
|
8
9
|
*/
|
|
9
10
|
export interface OverlayOptions {
|
|
10
11
|
/**
|
|
@@ -116,6 +117,7 @@ export interface Overlay extends _Overlay {
|
|
|
116
117
|
/**
|
|
117
118
|
* Overlay makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
118
119
|
* Deletes are persisted via metadata stored on the writable file system.
|
|
120
|
+
* @category Backends and Configuration
|
|
119
121
|
* @internal
|
|
120
122
|
*/
|
|
121
123
|
export declare const Overlay: Overlay;
|
package/dist/backends/overlay.js
CHANGED
|
@@ -550,6 +550,7 @@ const _Overlay = {
|
|
|
550
550
|
/**
|
|
551
551
|
* Overlay makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
552
552
|
* Deletes are persisted via metadata stored on the writable file system.
|
|
553
|
+
* @category Backends and Configuration
|
|
553
554
|
* @internal
|
|
554
555
|
*/
|
|
555
556
|
export const Overlay = _Overlay;
|
|
@@ -4,6 +4,10 @@ import { FileSystem } from '../internal/filesystem.js';
|
|
|
4
4
|
import type { InodeLike } from '../internal/inode.js';
|
|
5
5
|
import { Stats } from '../stats.js';
|
|
6
6
|
export type NodeFS = typeof fs;
|
|
7
|
+
/**
|
|
8
|
+
* Passthrough backend options
|
|
9
|
+
* @category Backends and Configuration
|
|
10
|
+
*/
|
|
7
11
|
export interface PassthroughOptions {
|
|
8
12
|
fs: NodeFS;
|
|
9
13
|
prefix?: string;
|
|
@@ -2,12 +2,12 @@ import type { ExtractProperties } from 'utilium';
|
|
|
2
2
|
import type { Inode, InodeLike } from '../..//internal/inode.js';
|
|
3
3
|
import type { MountConfiguration } from '../../config.js';
|
|
4
4
|
import type { File } from '../../internal/file.js';
|
|
5
|
-
import type { CreationOptions,
|
|
5
|
+
import type { CreationOptions, UsageInfo } from '../../internal/filesystem.js';
|
|
6
6
|
import type { Backend, FilesystemOf } from '../backend.js';
|
|
7
7
|
import { FileSystem } from '../../internal/filesystem.js';
|
|
8
8
|
import { Stats } from '../../stats.js';
|
|
9
9
|
import * as RPC from './rpc.js';
|
|
10
|
-
type FSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<any> |
|
|
10
|
+
type FSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<any> | UsageInfo>;
|
|
11
11
|
type FSMethod = keyof FSMethods;
|
|
12
12
|
export type FSRequest<TMethod extends FSMethod = FSMethod> = RPC.Message & {
|
|
13
13
|
[M in TMethod]: {
|
|
@@ -73,6 +73,12 @@ declare const _Port: {
|
|
|
73
73
|
type _Port = typeof _Port;
|
|
74
74
|
export interface Port extends _Port {
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @category Backends and Configuration
|
|
78
|
+
*/
|
|
76
79
|
export declare const Port: Port;
|
|
80
|
+
/**
|
|
81
|
+
* @category Backends and Configuration
|
|
82
|
+
*/
|
|
77
83
|
export declare function resolveRemoteMount<T extends Backend>(port: RPC.Port, config: MountConfiguration<T>, _depth?: number): Promise<FilesystemOf<T>>;
|
|
78
84
|
export {};
|
package/dist/backends/port/fs.js
CHANGED
|
@@ -134,7 +134,13 @@ const _Port = {
|
|
|
134
134
|
return new PortFS(options);
|
|
135
135
|
},
|
|
136
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* @category Backends and Configuration
|
|
139
|
+
*/
|
|
137
140
|
export const Port = _Port;
|
|
141
|
+
/**
|
|
142
|
+
* @category Backends and Configuration
|
|
143
|
+
*/
|
|
138
144
|
export async function resolveRemoteMount(port, config, _depth = 0) {
|
|
139
145
|
const stopAndReplay = RPC.catchMessages(port);
|
|
140
146
|
const fs = await resolveMountConfig(config, _depth);
|
|
@@ -6,12 +6,10 @@ import { Inode, type InodeLike } from '../../internal/inode.js';
|
|
|
6
6
|
import type { Stats } from '../../stats.js';
|
|
7
7
|
import { WrappedTransaction, type Store } from './store.js';
|
|
8
8
|
/**
|
|
9
|
-
* A file system which uses a
|
|
9
|
+
* A file system which uses a `Store`
|
|
10
10
|
*
|
|
11
|
-
* We use a unique ID for each node in the file system. The root node has a fixed ID.
|
|
12
|
-
*
|
|
13
|
-
* @todo Introduce Node ID caching?
|
|
14
11
|
* @todo Check modes?
|
|
12
|
+
* @category Stores and Transactions
|
|
15
13
|
* @internal
|
|
16
14
|
*/
|
|
17
15
|
export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
@@ -63,12 +63,10 @@ import { S_IFDIR, S_IFREG, S_ISGID, S_ISUID, size_max } from '../../vfs/constant
|
|
|
63
63
|
import { basename, dirname, join, parse, relative } from '../../vfs/path.js';
|
|
64
64
|
import { WrappedTransaction } from './store.js';
|
|
65
65
|
/**
|
|
66
|
-
* A file system which uses a
|
|
66
|
+
* A file system which uses a `Store`
|
|
67
67
|
*
|
|
68
|
-
* We use a unique ID for each node in the file system. The root node has a fixed ID.
|
|
69
|
-
*
|
|
70
|
-
* @todo Introduce Node ID caching?
|
|
71
68
|
* @todo Check modes?
|
|
69
|
+
* @category Stores and Transactions
|
|
72
70
|
* @internal
|
|
73
71
|
*/
|
|
74
72
|
export class StoreFS extends FileSystem {
|
|
@@ -2,6 +2,7 @@ import type { Store } from './store.js';
|
|
|
2
2
|
import { AsyncTransaction, SyncTransaction } from './store.js';
|
|
3
3
|
/**
|
|
4
4
|
* An interface for simple synchronous stores that don't have special support for transactions and such, based on `Map`
|
|
5
|
+
* @category Stores and Transactions
|
|
5
6
|
*/
|
|
6
7
|
export interface SyncMapStore extends Store {
|
|
7
8
|
keys(): Iterable<number>;
|
|
@@ -12,6 +13,7 @@ export interface SyncMapStore extends Store {
|
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Transaction for map stores.
|
|
16
|
+
* @category Stores and Transactions
|
|
15
17
|
* @see SyncMapStore
|
|
16
18
|
*/
|
|
17
19
|
export declare class SyncMapTransaction extends SyncTransaction<SyncMapStore> {
|
|
@@ -24,6 +26,7 @@ export declare class SyncMapTransaction extends SyncTransaction<SyncMapStore> {
|
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* An interface for simple asynchronous stores that don't have special support for transactions and such, based on `Map`.
|
|
29
|
+
* @category Stores and Transactions
|
|
27
30
|
*/
|
|
28
31
|
export interface AsyncMap {
|
|
29
32
|
keys(): Iterable<number>;
|
|
@@ -32,6 +35,9 @@ export interface AsyncMap {
|
|
|
32
35
|
set(id: number, data: Uint8Array, offset?: number): Promise<void>;
|
|
33
36
|
delete(id: number): Promise<void>;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @category Stores and Transactions
|
|
40
|
+
*/
|
|
35
41
|
export declare class AsyncMapTransaction<T extends Store & AsyncMap = Store & AsyncMap> extends AsyncTransaction<T> {
|
|
36
42
|
keys(): Promise<Iterable<number>>;
|
|
37
43
|
get(id: number, offset?: number, end?: number): Promise<Uint8Array | undefined>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncTransaction, SyncTransaction } from './store.js';
|
|
2
2
|
/**
|
|
3
3
|
* Transaction for map stores.
|
|
4
|
+
* @category Stores and Transactions
|
|
4
5
|
* @see SyncMapStore
|
|
5
6
|
*/
|
|
6
7
|
export class SyncMapTransaction extends SyncTransaction {
|
|
@@ -22,6 +23,9 @@ export class SyncMapTransaction extends SyncTransaction {
|
|
|
22
23
|
this.store.delete(id);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @category Stores and Transactions
|
|
28
|
+
*/
|
|
25
29
|
export class AsyncMapTransaction extends AsyncTransaction {
|
|
26
30
|
async keys() {
|
|
27
31
|
await this.asyncDone;
|
|
@@ -2,14 +2,17 @@ import type { AsyncMap, SyncMapStore } from './map.js';
|
|
|
2
2
|
import { SyncMapTransaction } from './map.js';
|
|
3
3
|
import type { Store } from './store.js';
|
|
4
4
|
/**
|
|
5
|
+
* @category Stores and Transactions
|
|
5
6
|
* @deprecated Use `MapStore` instead.
|
|
6
7
|
*/
|
|
7
8
|
export type SimpleSyncStore = SyncMapStore;
|
|
8
9
|
/**
|
|
10
|
+
* @category Stores and Transactions
|
|
9
11
|
* @deprecated Use `AsyncMapStore` instead.
|
|
10
12
|
*/
|
|
11
13
|
export type SimpleAsyncStore = AsyncMap & Store;
|
|
12
14
|
/**
|
|
15
|
+
* @category Stores and Transactions
|
|
13
16
|
* @deprecated Use `MapTransaction` instead.
|
|
14
17
|
*/
|
|
15
18
|
export declare class SimpleTransaction extends SyncMapTransaction {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Resource } from 'utilium/cache.js';
|
|
2
2
|
import '../../polyfills.js';
|
|
3
3
|
import type { StoreFS } from './fs.js';
|
|
4
|
+
/**
|
|
5
|
+
* @category Stores and Transactions
|
|
6
|
+
*/
|
|
4
7
|
export type StoreFlag =
|
|
5
8
|
/** The store supports partial reads and writes */
|
|
6
9
|
'partial';
|
|
7
10
|
/**
|
|
8
11
|
* Represents a key-value store.
|
|
12
|
+
* @category Stores and Transactions
|
|
9
13
|
*/
|
|
10
14
|
export interface Store {
|
|
11
15
|
/**
|
|
@@ -51,6 +55,7 @@ export interface Store {
|
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
57
|
* A transaction for a store.
|
|
58
|
+
* @category Stores and Transactions
|
|
54
59
|
*/
|
|
55
60
|
export declare abstract class Transaction<T extends Store = Store> {
|
|
56
61
|
readonly store: T;
|
|
@@ -96,19 +101,24 @@ export declare abstract class Transaction<T extends Store = Store> {
|
|
|
96
101
|
}
|
|
97
102
|
/**
|
|
98
103
|
* Transaction that implements asynchronous operations with synchronous ones
|
|
104
|
+
* @category Stores and Transactions
|
|
99
105
|
*/
|
|
100
106
|
export declare abstract class SyncTransaction<T extends Store = Store> extends Transaction<T> {
|
|
101
107
|
get(id: number, offset: number, end?: number): Promise<Uint8Array | undefined>;
|
|
102
108
|
set(id: number, data: Uint8Array, offset: number): Promise<void>;
|
|
103
109
|
remove(id: number): Promise<void>;
|
|
104
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* @category Stores and Transactions
|
|
113
|
+
*/
|
|
105
114
|
export interface AsyncStore extends Store {
|
|
106
115
|
cache?: Map<number, Resource<number>>;
|
|
107
116
|
}
|
|
108
117
|
/**
|
|
109
118
|
* Transaction that implements synchronous operations with a cache
|
|
110
|
-
*
|
|
119
|
+
* Implementors: You *must* update the cache and wait for `store.asyncDone` in your asynchronous methods.
|
|
111
120
|
* @todo Make sure we handle abortions correctly, especially since the cache is shared between transactions.
|
|
121
|
+
* @category Stores and Transactions
|
|
112
122
|
*/
|
|
113
123
|
export declare abstract class AsyncTransaction<T extends AsyncStore = AsyncStore> extends Transaction<T> {
|
|
114
124
|
protected asyncDone: Promise<unknown>;
|
|
@@ -132,6 +142,7 @@ export declare abstract class AsyncTransaction<T extends AsyncStore = AsyncStore
|
|
|
132
142
|
/**
|
|
133
143
|
* Wraps a transaction with the ability to roll-back changes, among other things.
|
|
134
144
|
* This is used by `StoreFS`
|
|
145
|
+
* @category Stores and Transactions
|
|
135
146
|
* @internal @hidden
|
|
136
147
|
*/
|
|
137
148
|
export declare class WrappedTransaction<T extends Store = Store> {
|
|
@@ -4,6 +4,7 @@ import { err, warn } from '../../internal/log.js';
|
|
|
4
4
|
import '../../polyfills.js';
|
|
5
5
|
/**
|
|
6
6
|
* A transaction for a store.
|
|
7
|
+
* @category Stores and Transactions
|
|
7
8
|
*/
|
|
8
9
|
export class Transaction {
|
|
9
10
|
constructor(store) {
|
|
@@ -12,6 +13,7 @@ export class Transaction {
|
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Transaction that implements asynchronous operations with synchronous ones
|
|
16
|
+
* @category Stores and Transactions
|
|
15
17
|
*/
|
|
16
18
|
export class SyncTransaction extends Transaction {
|
|
17
19
|
/* eslint-disable @typescript-eslint/require-await */
|
|
@@ -27,8 +29,9 @@ export class SyncTransaction extends Transaction {
|
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Transaction that implements synchronous operations with a cache
|
|
30
|
-
*
|
|
32
|
+
* Implementors: You *must* update the cache and wait for `store.asyncDone` in your asynchronous methods.
|
|
31
33
|
* @todo Make sure we handle abortions correctly, especially since the cache is shared between transactions.
|
|
34
|
+
* @category Stores and Transactions
|
|
32
35
|
*/
|
|
33
36
|
export class AsyncTransaction extends Transaction {
|
|
34
37
|
constructor() {
|
|
@@ -89,6 +92,7 @@ export class AsyncTransaction extends Transaction {
|
|
|
89
92
|
/**
|
|
90
93
|
* Wraps a transaction with the ability to roll-back changes, among other things.
|
|
91
94
|
* This is used by `StoreFS`
|
|
95
|
+
* @category Stores and Transactions
|
|
92
96
|
* @internal @hidden
|
|
93
97
|
*/
|
|
94
98
|
export class WrappedTransaction {
|
package/dist/config.d.ts
CHANGED
|
@@ -3,21 +3,25 @@ import type { Device, DeviceDriver } from './internal/devices.js';
|
|
|
3
3
|
import type { LogConfiguration } from './internal/log.js';
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for a specific mount point
|
|
6
|
+
* @category Backends and Configuration
|
|
6
7
|
*/
|
|
7
8
|
export type MountConfiguration<T extends Backend> = FilesystemOf<T> | BackendConfiguration<T> | T;
|
|
8
9
|
/**
|
|
9
10
|
* Retrieve a file system with `configuration`.
|
|
11
|
+
* @category Backends and Configuration
|
|
10
12
|
* @see MountConfiguration
|
|
11
13
|
*/
|
|
12
14
|
export declare function resolveMountConfig<T extends Backend>(configuration: MountConfiguration<T>, _depth?: number): Promise<FilesystemOf<T>>;
|
|
13
15
|
/**
|
|
14
16
|
* An object mapping mount points to backends
|
|
17
|
+
* @category Backends and Configuration
|
|
15
18
|
*/
|
|
16
19
|
export interface ConfigMounts {
|
|
17
20
|
[K: string]: Backend;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Configuration
|
|
24
|
+
* @category Backends and Configuration
|
|
21
25
|
*/
|
|
22
26
|
export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
23
27
|
/**
|
|
@@ -41,21 +45,6 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
41
45
|
* @default false
|
|
42
46
|
*/
|
|
43
47
|
addDevices: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* If true, enables caching stats for certain operations.
|
|
46
|
-
* This should reduce the number of stat calls performed.
|
|
47
|
-
* @experimental
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
cacheStats: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* If true, enables caching realpath output
|
|
53
|
-
*
|
|
54
|
-
* This can increase performance.
|
|
55
|
-
* @experimental
|
|
56
|
-
* @default false
|
|
57
|
-
*/
|
|
58
|
-
cachePaths: boolean;
|
|
59
48
|
/**
|
|
60
49
|
* If true, disables *all* permissions checking.
|
|
61
50
|
*
|
|
@@ -88,11 +77,16 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
88
77
|
}
|
|
89
78
|
/**
|
|
90
79
|
* Configures ZenFS with single mount point /
|
|
80
|
+
* @category Backends and Configuration
|
|
91
81
|
*/
|
|
92
82
|
export declare function configureSingle<T extends Backend>(configuration: MountConfiguration<T>): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* @category Backends and Configuration
|
|
85
|
+
*/
|
|
93
86
|
export declare function addDevice(driver: DeviceDriver, options?: object): Device;
|
|
94
87
|
/**
|
|
95
88
|
* Configures ZenFS with `configuration`
|
|
89
|
+
* @category Backends and Configuration
|
|
96
90
|
* @see Configuration
|
|
97
91
|
*/
|
|
98
92
|
export declare function configure<T extends ConfigMounts>(configuration: Partial<Configuration<T>>): Promise<void>;
|
package/dist/config.js
CHANGED
|
@@ -4,7 +4,6 @@ import { DeviceFS } from './internal/devices.js';
|
|
|
4
4
|
import { Errno, ErrnoError } from './internal/error.js';
|
|
5
5
|
import { FileSystem } from './internal/filesystem.js';
|
|
6
6
|
import { configure as configureLog, crit, err, info } from './internal/log.js';
|
|
7
|
-
import * as cache from './vfs/cache.js';
|
|
8
7
|
import { config } from './vfs/config.js';
|
|
9
8
|
import * as fs from './vfs/index.js';
|
|
10
9
|
import { mounts } from './vfs/shared.js';
|
|
@@ -13,6 +12,7 @@ function isMountConfig(arg) {
|
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* Retrieve a file system with `configuration`.
|
|
15
|
+
* @category Backends and Configuration
|
|
16
16
|
* @see MountConfiguration
|
|
17
17
|
*/
|
|
18
18
|
export async function resolveMountConfig(configuration, _depth = 0) {
|
|
@@ -53,6 +53,7 @@ export async function resolveMountConfig(configuration, _depth = 0) {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Configures ZenFS with single mount point /
|
|
56
|
+
* @category Backends and Configuration
|
|
56
57
|
*/
|
|
57
58
|
export async function configureSingle(configuration) {
|
|
58
59
|
if (!isBackendConfig(configuration)) {
|
|
@@ -82,6 +83,9 @@ async function mount(path, mount) {
|
|
|
82
83
|
}
|
|
83
84
|
fs.mount(path, mount);
|
|
84
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* @category Backends and Configuration
|
|
88
|
+
*/
|
|
85
89
|
export function addDevice(driver, options) {
|
|
86
90
|
const devfs = mounts.get('/dev');
|
|
87
91
|
if (!(devfs instanceof DeviceFS))
|
|
@@ -90,15 +94,14 @@ export function addDevice(driver, options) {
|
|
|
90
94
|
}
|
|
91
95
|
/**
|
|
92
96
|
* Configures ZenFS with `configuration`
|
|
97
|
+
* @category Backends and Configuration
|
|
93
98
|
* @see Configuration
|
|
94
99
|
*/
|
|
95
100
|
export async function configure(configuration) {
|
|
96
|
-
var _a
|
|
101
|
+
var _a;
|
|
97
102
|
const uid = 'uid' in configuration ? configuration.uid || 0 : 0;
|
|
98
103
|
const gid = 'gid' in configuration ? configuration.gid || 0 : 0;
|
|
99
104
|
useCredentials({ uid, gid });
|
|
100
|
-
cache.stats.isEnabled = (_a = configuration.cacheStats) !== null && _a !== void 0 ? _a : false;
|
|
101
|
-
cache.paths.isEnabled = (_b = configuration.cachePaths) !== null && _b !== void 0 ? _b : false;
|
|
102
105
|
config.checkAccess = !configuration.disableAccessChecks;
|
|
103
106
|
config.updateOnRead = !configuration.disableUpdateOnRead;
|
|
104
107
|
config.syncImmediately = !configuration.onlySyncOnClose;
|
|
@@ -109,7 +112,7 @@ export async function configure(configuration) {
|
|
|
109
112
|
for (const [_point, mountConfig] of Object.entries(configuration.mounts).sort(([a], [b]) => (a.length > b.length ? 1 : -1))) {
|
|
110
113
|
const point = _point.startsWith('/') ? _point : '/' + _point;
|
|
111
114
|
if (isBackendConfig(mountConfig)) {
|
|
112
|
-
(
|
|
115
|
+
(_a = mountConfig.disableAsyncCache) !== null && _a !== void 0 ? _a : (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false);
|
|
113
116
|
}
|
|
114
117
|
if (point == '/')
|
|
115
118
|
fs.umount('/');
|
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CredentialInit, Credentials } from './internal/credentials.js';
|
|
|
2
2
|
import * as fs from './vfs/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents some context used for FS operations
|
|
5
|
-
* @
|
|
5
|
+
* @category Backends and Configuration
|
|
6
6
|
*/
|
|
7
7
|
export interface FSContext {
|
|
8
8
|
root: string;
|
|
@@ -10,12 +10,11 @@ export interface FSContext {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* maybe an FS context
|
|
13
|
-
* @experimental @hidden
|
|
14
13
|
*/
|
|
15
14
|
export type V_Context = void | (Partial<FSContext> & object);
|
|
16
15
|
/**
|
|
17
16
|
* Allows you to restrict operations to a specific root path and set of credentials.
|
|
18
|
-
* @
|
|
17
|
+
* @category Backends and Configuration
|
|
19
18
|
*/
|
|
20
19
|
export interface BoundContext extends FSContext {
|
|
21
20
|
fs: typeof fs;
|
|
@@ -23,6 +22,6 @@ export interface BoundContext extends FSContext {
|
|
|
23
22
|
/**
|
|
24
23
|
* Allows you to restrict operations to a specific root path and set of credentials.
|
|
25
24
|
* Note that the default credentials of a bound context are copied from the global credentials.
|
|
26
|
-
* @
|
|
25
|
+
* @category Backends and Configuration
|
|
27
26
|
*/
|
|
28
27
|
export declare function bindContext(root: string, credentials?: CredentialInit): BoundContext;
|
package/dist/context.js
CHANGED
|
@@ -10,7 +10,7 @@ function _bindFunctions(fns, thisValue) {
|
|
|
10
10
|
/**
|
|
11
11
|
* Allows you to restrict operations to a specific root path and set of credentials.
|
|
12
12
|
* Note that the default credentials of a bound context are copied from the global credentials.
|
|
13
|
-
* @
|
|
13
|
+
* @category Backends and Configuration
|
|
14
14
|
*/
|
|
15
15
|
export function bindContext(root, credentials = structuredClone(defaultCredentials)) {
|
|
16
16
|
const ctx = {
|