@zenfs/core 1.9.1 → 1.9.3
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 +6 -0
- package/dist/backends/fetch.js +10 -3
- package/dist/backends/memory.d.ts +1 -0
- package/dist/backends/memory.js +1 -0
- package/dist/backends/overlay.d.ts +1 -0
- package/dist/backends/passthrough.d.ts +4 -0
- package/dist/backends/store/fs.d.ts +1 -0
- package/dist/backends/store/fs.js +1 -0
- 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 -0
- package/dist/config.js +6 -0
- 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 +1 -0
- package/dist/internal/file_index.js +1 -0
- package/dist/internal/filesystem.d.ts +9 -0
- package/dist/internal/filesystem.js +1 -0
- package/dist/internal/index_fs.d.ts +2 -0
- package/dist/internal/index_fs.js +8 -2
- 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/shared.d.ts +4 -1
- package/dist/vfs/shared.js +3 -1
- package/package.json +1 -1
- package/readme.md +4 -0
- package/tests/backend/fetch.test.ts +3 -2
- package/tests/fs/rename.test.ts +1 -1
|
@@ -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;
|
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 = {
|
|
@@ -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;
|
package/dist/backends/memory.js
CHANGED
|
@@ -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;
|
|
@@ -12,6 +12,7 @@ import { WrappedTransaction, type Store } from './store.js';
|
|
|
12
12
|
*
|
|
13
13
|
* @todo Introduce Node ID caching?
|
|
14
14
|
* @todo Check modes?
|
|
15
|
+
* @category Stores and Transactions
|
|
15
16
|
* @internal
|
|
16
17
|
*/
|
|
17
18
|
export declare class StoreFS<T extends Store = Store> 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
|
/**
|
|
@@ -88,11 +92,16 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
88
92
|
}
|
|
89
93
|
/**
|
|
90
94
|
* Configures ZenFS with single mount point /
|
|
95
|
+
* @category Backends and Configuration
|
|
91
96
|
*/
|
|
92
97
|
export declare function configureSingle<T extends Backend>(configuration: MountConfiguration<T>): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* @category Backends and Configuration
|
|
100
|
+
*/
|
|
93
101
|
export declare function addDevice(driver: DeviceDriver, options?: object): Device;
|
|
94
102
|
/**
|
|
95
103
|
* Configures ZenFS with `configuration`
|
|
104
|
+
* @category Backends and Configuration
|
|
96
105
|
* @see Configuration
|
|
97
106
|
*/
|
|
98
107
|
export declare function configure<T extends ConfigMounts>(configuration: Partial<Configuration<T>>): Promise<void>;
|
package/dist/config.js
CHANGED
|
@@ -13,6 +13,7 @@ function isMountConfig(arg) {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Retrieve a file system with `configuration`.
|
|
16
|
+
* @category Backends and Configuration
|
|
16
17
|
* @see MountConfiguration
|
|
17
18
|
*/
|
|
18
19
|
export async function resolveMountConfig(configuration, _depth = 0) {
|
|
@@ -53,6 +54,7 @@ export async function resolveMountConfig(configuration, _depth = 0) {
|
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Configures ZenFS with single mount point /
|
|
57
|
+
* @category Backends and Configuration
|
|
56
58
|
*/
|
|
57
59
|
export async function configureSingle(configuration) {
|
|
58
60
|
if (!isBackendConfig(configuration)) {
|
|
@@ -82,6 +84,9 @@ async function mount(path, mount) {
|
|
|
82
84
|
}
|
|
83
85
|
fs.mount(path, mount);
|
|
84
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* @category Backends and Configuration
|
|
89
|
+
*/
|
|
85
90
|
export function addDevice(driver, options) {
|
|
86
91
|
const devfs = mounts.get('/dev');
|
|
87
92
|
if (!(devfs instanceof DeviceFS))
|
|
@@ -90,6 +95,7 @@ export function addDevice(driver, options) {
|
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
97
|
* Configures ZenFS with `configuration`
|
|
98
|
+
* @category Backends and Configuration
|
|
93
99
|
* @see Configuration
|
|
94
100
|
*/
|
|
95
101
|
export async function configure(configuration) {
|
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 = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Credentials used for various operations.
|
|
3
3
|
* Similar to Linux's cred struct.
|
|
4
|
+
* @category Internals
|
|
4
5
|
* @see https://github.com/torvalds/linux/blob/master/include/linux/cred.h
|
|
5
6
|
*/
|
|
6
7
|
export interface Credentials {
|
|
@@ -15,16 +16,24 @@ export interface Credentials {
|
|
|
15
16
|
*/
|
|
16
17
|
groups: number[];
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @category Internals
|
|
21
|
+
*/
|
|
18
22
|
export declare const credentials: Credentials;
|
|
19
23
|
/**
|
|
20
24
|
* Initialization for a set of credentials
|
|
25
|
+
* @category Internals
|
|
21
26
|
*/
|
|
22
27
|
export interface CredentialInit extends Partial<Credentials> {
|
|
23
28
|
uid: number;
|
|
24
29
|
gid: number;
|
|
25
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @category Internals
|
|
33
|
+
*/
|
|
26
34
|
export declare function createCredentials(source: CredentialInit): Credentials;
|
|
27
35
|
/**
|
|
28
36
|
* Uses credentials from the provided uid and gid.
|
|
37
|
+
* @category Internals
|
|
29
38
|
*/
|
|
30
39
|
export declare function useCredentials(source: CredentialInit): void;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category Internals
|
|
3
|
+
*/
|
|
1
4
|
export const credentials = {
|
|
2
5
|
uid: 0,
|
|
3
6
|
gid: 0,
|
|
@@ -7,6 +10,9 @@ export const credentials = {
|
|
|
7
10
|
egid: 0,
|
|
8
11
|
groups: [],
|
|
9
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* @category Internals
|
|
15
|
+
*/
|
|
10
16
|
export function createCredentials(source) {
|
|
11
17
|
return {
|
|
12
18
|
suid: source.uid,
|
|
@@ -19,6 +25,7 @@ export function createCredentials(source) {
|
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Uses credentials from the provided uid and gid.
|
|
28
|
+
* @category Internals
|
|
22
29
|
*/
|
|
23
30
|
export function useCredentials(source) {
|
|
24
31
|
Object.assign(credentials, createCredentials(source));
|
|
@@ -8,6 +8,7 @@ import { Inode } from './inode.js';
|
|
|
8
8
|
/**
|
|
9
9
|
* A device
|
|
10
10
|
* @todo Maybe add some other device information, like a UUID?
|
|
11
|
+
* @category Internals
|
|
11
12
|
* @privateRemarks
|
|
12
13
|
* UUIDs were considered, however they don't make sense without an easy mechanism for persistence
|
|
13
14
|
*/
|
|
@@ -34,6 +35,9 @@ export interface Device<TData = any> {
|
|
|
34
35
|
*/
|
|
35
36
|
minor: number;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @category Internals
|
|
40
|
+
*/
|
|
37
41
|
export interface DeviceInit<TData = any> {
|
|
38
42
|
data?: TData;
|
|
39
43
|
minor?: number;
|
|
@@ -42,6 +46,7 @@ export interface DeviceInit<TData = any> {
|
|
|
42
46
|
}
|
|
43
47
|
/**
|
|
44
48
|
* A device driver
|
|
49
|
+
* @category Internals
|
|
45
50
|
*/
|
|
46
51
|
export interface DeviceDriver<TData = any> {
|
|
47
52
|
/**
|
|
@@ -108,6 +113,8 @@ export interface DeviceDriver<TData = any> {
|
|
|
108
113
|
* This class only does some simple things:
|
|
109
114
|
* It implements `truncate` using `write` and it has non-device methods throw.
|
|
110
115
|
* It is up to device drivers to implement the rest of the functionality.
|
|
116
|
+
* @category Internals
|
|
117
|
+
* @internal
|
|
111
118
|
*/
|
|
112
119
|
export declare class DeviceFile<TData = any> extends File {
|
|
113
120
|
fs: DeviceFS;
|
|
@@ -137,6 +144,7 @@ export declare class DeviceFile<TData = any> extends File {
|
|
|
137
144
|
}
|
|
138
145
|
/**
|
|
139
146
|
* A temporary file system that manages and interfaces with devices
|
|
147
|
+
* @category Internals
|
|
140
148
|
*/
|
|
141
149
|
export declare class DeviceFS extends StoreFS<InMemoryStore> {
|
|
142
150
|
protected readonly devices: Map<string, Device<any>>;
|
|
@@ -184,6 +192,7 @@ export declare class DeviceFS extends StoreFS<InMemoryStore> {
|
|
|
184
192
|
* Simulates the `/dev/null` device.
|
|
185
193
|
* - Reads return 0 bytes (EOF).
|
|
186
194
|
* - Writes discard data, advancing the file position.
|
|
195
|
+
* @category Internals
|
|
187
196
|
* @internal
|
|
188
197
|
*/
|
|
189
198
|
export declare const nullDevice: DeviceDriver;
|
|
@@ -195,6 +204,7 @@ export declare const nullDevice: DeviceDriver;
|
|
|
195
204
|
* - Reads fill the buffer with zeroes.
|
|
196
205
|
* - Writes discard data but update the file position.
|
|
197
206
|
* - Provides basic file metadata, treating it as a character device.
|
|
207
|
+
* @category Internals
|
|
198
208
|
* @internal
|
|
199
209
|
*/
|
|
200
210
|
export declare const zeroDevice: DeviceDriver;
|
|
@@ -202,6 +212,7 @@ export declare const zeroDevice: DeviceDriver;
|
|
|
202
212
|
* Simulates the `/dev/full` device.
|
|
203
213
|
* - Reads behave like `/dev/zero` (returns zeroes).
|
|
204
214
|
* - Writes always fail with ENOSPC (no space left on device).
|
|
215
|
+
* @category Internals
|
|
205
216
|
* @internal
|
|
206
217
|
*/
|
|
207
218
|
export declare const fullDevice: DeviceDriver;
|
|
@@ -209,11 +220,14 @@ export declare const fullDevice: DeviceDriver;
|
|
|
209
220
|
* Simulates the `/dev/random` device.
|
|
210
221
|
* - Reads return random bytes.
|
|
211
222
|
* - Writes discard data, advancing the file position.
|
|
223
|
+
* @category Internals
|
|
212
224
|
* @internal
|
|
213
225
|
*/
|
|
214
226
|
export declare const randomDevice: DeviceDriver;
|
|
215
227
|
/**
|
|
216
228
|
* Shortcuts for importing.
|
|
229
|
+
* @category Internals
|
|
230
|
+
* @internal
|
|
217
231
|
*/
|
|
218
232
|
export declare const devices: {
|
|
219
233
|
null: DeviceDriver<any>;
|