@fnndsc/fond 0.1.2 → 0.3.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/README.md +24 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/vfs/contract.d.ts +26 -0
- package/dist/vfs/contract.js +195 -0
- package/dist/vfs/contract.js.map +1 -0
- package/dist/vfs/dispatcher.d.ts +208 -0
- package/dist/vfs/dispatcher.js +409 -0
- package/dist/vfs/dispatcher.js.map +1 -0
- package/dist/vfs/fsViews.d.ts +39 -0
- package/dist/vfs/fsViews.js +91 -0
- package/dist/vfs/fsViews.js.map +1 -0
- package/dist/vfs/memory.d.ts +66 -0
- package/dist/vfs/memory.js +282 -0
- package/dist/vfs/memory.js.map +1 -0
- package/dist/vfs/outcome.d.ts +98 -0
- package/dist/vfs/outcome.js +151 -0
- package/dist/vfs/outcome.js.map +1 -0
- package/dist/vfs/provider.d.ts +159 -0
- package/dist/vfs/provider.js +13 -0
- package/dist/vfs/provider.js.map +1 -0
- package/dist/vfs/render.d.ts +73 -0
- package/dist/vfs/render.js +203 -0
- package/dist/vfs/render.js.map +1 -0
- package/dist/vfs/sort.d.ts +18 -0
- package/dist/vfs/sort.js +33 -0
- package/dist/vfs/sort.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @fnndsc/fond
|
|
|
12
12
|
|
|
13
13
|
A backend such as ChRIS (CUBE) brings its own client and its own world. The pieces every layer needs, whatever the backend, live here rather than in a backend's package, so a layer that is not about CUBE can use them without loading CUBE (see [docs/backend-neutral.adoc](https://github.com/FNNDSC/mise/blob/main/docs/backend-neutral.adoc)).
|
|
14
14
|
|
|
15
|
-
fond's one rule: **it depends on nothing in `@fnndsc`**. CI holds it to that (`npm run lint:fond`).
|
|
15
|
+
fond's one rule: **it depends on nothing in `@fnndsc`**. CI holds it to that (`npm run lint:fond`). Its one dependency is `chalk`, for the listing views.
|
|
16
16
|
|
|
17
17
|
## What's in it
|
|
18
18
|
|
|
@@ -21,6 +21,12 @@ fond's one rule: **it depends on nothing in `@fnndsc`**. CI holds it to that (`n
|
|
|
21
21
|
| `Result<T>`, `Ok`, `Err`, `result_isOk`, `result_isErr` | An explicit success-or-failure value. A function returns `Result<T>` rather than `T \| null`, and TypeScript will not let a caller read `.value` until it has checked `.ok`. |
|
|
22
22
|
| `errorStack` | The process-wide message stack that failures are reported on, with context-isolated scopes and checkpoints. |
|
|
23
23
|
| `errorStack_configure`, `errorStack_getAllOfType`, `StackMessage` | Configuration, a convenience reader, and the message type. |
|
|
24
|
+
| `VFSProvider`, `VFSItem`, `CpOptions` | The virtual filesystem's contracts: a mount that claims a path prefix and lists, copies and (optionally) reads, writes, makes, removes and renames under it; the items it lists. |
|
|
25
|
+
| `VFSDispatcher` | Routes each filesystem request to the mount that owns the path, or to a fallback. It knows no backend: a backend registers its mounts and names its fallback. |
|
|
26
|
+
| `vfsItems_sort` | Sorts a listing's items by name, size, date or owner without changing the array given. |
|
|
27
|
+
| `grid_render`, `long_render`, `size_format` | A listing as a terminal shows it: `ls`'s grid and `ls -l`'s long view, and sizes for people. |
|
|
28
|
+
| `ListingLook`, `ItemKindLook`, `LISTING_CORE_KINDS`, `LISTING_LOOK_PLAIN` | How a listing shows: the core's kinds (file, folder, link, mount) and a backend's beside them, each with its long-view mark, and how a name is coloured. |
|
|
29
|
+
| `listingItems_sort` | Sorts a listing by one field; a reversed sort keeps equal items in their order. |
|
|
24
30
|
|
|
25
31
|
## Using `Result`
|
|
26
32
|
|
|
@@ -79,6 +85,23 @@ const reasons: StackMessage[] = errorStack.checkpoint_drain(mark);
|
|
|
79
85
|
|
|
80
86
|
`errorStack_configure({ functionNamePadWidth })` sets how wide the function-name stamp is padded.
|
|
81
87
|
|
|
88
|
+
## The virtual filesystem
|
|
89
|
+
|
|
90
|
+
A session's filesystem is a tree of mounts. Each mount (a `VFSProvider`) claims a path prefix and answers for everything at or under it; the longest prefix that matches at a segment boundary wins, so `/proc/jobs` takes precedence over `/proc`, and `/procs` is not under `/proc`. A path no mount claims goes to the fallback.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { VFSDispatcher, type VFSProvider } from '@fnndsc/fond';
|
|
94
|
+
|
|
95
|
+
const dispatcher: VFSDispatcher = new VFSDispatcher(filesFallback); // what no mount claims
|
|
96
|
+
dispatcher.provider_register(notesMount); // prefix '/notes'
|
|
97
|
+
dispatcher.provider_register(jobsMount); // prefix '/proc/jobs'
|
|
98
|
+
|
|
99
|
+
await dispatcher.list('/proc'); // the mounts beneath it ('jobs'), beside what the fallback holds there
|
|
100
|
+
await dispatcher.read('/notes/today'); // notesMount.read('/notes/today')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Every operation a mount does not offer is refused by name (`mkdir: cannot create directory '/x': Read-only file system`), never silently ignored. A dispatcher built without a fallback refuses any path no mount claims, rather than answering with an empty folder. `pathResolver_register` adds a hook that maps a path to the fallback's own form before the fallback sees it; a copy whose path cannot be resolved fails rather than guessing.
|
|
104
|
+
|
|
82
105
|
## One instance, whoever loads it
|
|
83
106
|
|
|
84
107
|
The error stack only works if the whole process shares one. fond is built as CommonJS, so packages that `require` it (cumin) and packages that `import` it (salsa, brasa, calypso) load the same module and so the same stack. `@fnndsc/cumin` re-exports fond's `Result` and `errorStack` rather than keeping copies, so code that imports them from cumin shares that stack too. If you bundle code that uses fond, keep it to one copy.
|
package/dist/index.d.ts
CHANGED
|
@@ -10,3 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export * from './result.js';
|
|
12
12
|
export * from './errorStack.js';
|
|
13
|
+
export * from './vfs/provider.js';
|
|
14
|
+
export * from './vfs/sort.js';
|
|
15
|
+
export * from './vfs/dispatcher.js';
|
|
16
|
+
export * from './vfs/render.js';
|
|
17
|
+
export * from './vfs/fsViews.js';
|
|
18
|
+
export * from './vfs/outcome.js';
|
|
19
|
+
export * from './vfs/memory.js';
|
|
20
|
+
export * from './vfs/contract.js';
|
package/dist/index.js
CHANGED
|
@@ -26,4 +26,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
*/
|
|
27
27
|
__exportStar(require("./result.js"), exports);
|
|
28
28
|
__exportStar(require("./errorStack.js"), exports);
|
|
29
|
+
__exportStar(require("./vfs/provider.js"), exports);
|
|
30
|
+
__exportStar(require("./vfs/sort.js"), exports);
|
|
31
|
+
__exportStar(require("./vfs/dispatcher.js"), exports);
|
|
32
|
+
__exportStar(require("./vfs/render.js"), exports);
|
|
33
|
+
__exportStar(require("./vfs/fsViews.js"), exports);
|
|
34
|
+
__exportStar(require("./vfs/outcome.js"), exports);
|
|
35
|
+
__exportStar(require("./vfs/memory.js"), exports);
|
|
36
|
+
__exportStar(require("./vfs/contract.js"), exports);
|
|
29
37
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,8CAA4B;AAC5B,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;GASG;AACH,8CAA4B;AAC5B,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The filesystem contract every mount is held to, as cases a test runs.
|
|
3
|
+
*
|
|
4
|
+
* A backend's mount answers the operations fond names with the errno a disk
|
|
5
|
+
* would give: what the core's tools say is decided from that errno, so a
|
|
6
|
+
* mount that answers differently makes them say something untrue. Each case
|
|
7
|
+
* here builds a fresh mount through the driver it is given, seeds it, and
|
|
8
|
+
* throws when the mount breaks the contract. An operation the mount does not
|
|
9
|
+
* offer is skipped, not failed: a read-only mount is a mount.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { VFSProvider } from './provider.js';
|
|
14
|
+
import type { MemorySeed } from './memory.js';
|
|
15
|
+
/** What a test hands the contract: how to make a fresh, seeded mount. */
|
|
16
|
+
export interface VfsContractDriver {
|
|
17
|
+
/** A fresh mount holding exactly what the seed names (parents made as needed), its root at `/`. */
|
|
18
|
+
mount_make(seed: MemorySeed): Promise<VFSProvider>;
|
|
19
|
+
}
|
|
20
|
+
/** One case: its name, and a run that throws on a breach. */
|
|
21
|
+
export interface VfsContractCase {
|
|
22
|
+
name: string;
|
|
23
|
+
run(driver: VfsContractDriver): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** The contract, case by case. */
|
|
26
|
+
export declare const VFS_CONTRACT: ReadonlyArray<VfsContractCase>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VFS_CONTRACT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fails a case.
|
|
6
|
+
*
|
|
7
|
+
* @param what - What was wrong.
|
|
8
|
+
*/
|
|
9
|
+
function breach(what) {
|
|
10
|
+
throw new Error(`contract breach: ${what}`);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Requires a success.
|
|
14
|
+
*
|
|
15
|
+
* @param outcome - The answer.
|
|
16
|
+
* @param what - The operation, for the breach.
|
|
17
|
+
* @returns Its value.
|
|
18
|
+
*/
|
|
19
|
+
function done(outcome, what) {
|
|
20
|
+
if (!outcome.ok)
|
|
21
|
+
breach(`${what} failed with ${outcome.errno}${outcome.reason ? ` (${outcome.reason})` : ''}`);
|
|
22
|
+
return outcome.value;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Requires a failure with one of the errnos named.
|
|
26
|
+
*
|
|
27
|
+
* @param outcome - The answer.
|
|
28
|
+
* @param errnos - The errnos allowed.
|
|
29
|
+
* @param what - The operation, for the breach.
|
|
30
|
+
*/
|
|
31
|
+
function refused(outcome, errnos, what) {
|
|
32
|
+
if (outcome.ok)
|
|
33
|
+
breach(`${what} succeeded; expected ${errnos.join(' or ')}`);
|
|
34
|
+
if (!errnos.includes(outcome.errno))
|
|
35
|
+
breach(`${what} failed with ${outcome.errno}; expected ${errnos.join(' or ')}`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The names a folder lists, sorted.
|
|
39
|
+
*
|
|
40
|
+
* @param mount - The mount.
|
|
41
|
+
* @param folder - The folder.
|
|
42
|
+
* @returns Its entries' names and types, as `name:type`.
|
|
43
|
+
*/
|
|
44
|
+
async function names_of(mount, folder) {
|
|
45
|
+
const listed = await mount.list(folder);
|
|
46
|
+
if (!listed.ok)
|
|
47
|
+
breach(`list ${folder} failed`);
|
|
48
|
+
return listed.value.map((item) => `${item.name}:${item.type}`).sort();
|
|
49
|
+
}
|
|
50
|
+
/** The seed every case starts from. */
|
|
51
|
+
const SEED = {
|
|
52
|
+
'/home/a.txt': 'alpha',
|
|
53
|
+
'/home/docs/b.txt': 'beta',
|
|
54
|
+
'/home/empty': null,
|
|
55
|
+
};
|
|
56
|
+
/** The contract, case by case. */
|
|
57
|
+
exports.VFS_CONTRACT = [
|
|
58
|
+
{
|
|
59
|
+
name: 'lists a folder: its files and folders, each with its type',
|
|
60
|
+
run: async (driver) => {
|
|
61
|
+
const mount = await driver.mount_make(SEED);
|
|
62
|
+
const names = await names_of(mount, '/home');
|
|
63
|
+
for (const expected of ['a.txt:file', 'docs:dir', 'empty:dir']) {
|
|
64
|
+
if (!names.includes(expected))
|
|
65
|
+
breach(`list /home lacks ${expected} (got ${names.join(', ')})`);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'reads a file whole, as text and as bytes; ENOENT for nothing there, EISDIR for a folder',
|
|
71
|
+
run: async (driver) => {
|
|
72
|
+
const mount = await driver.mount_make(SEED);
|
|
73
|
+
if (mount.read) {
|
|
74
|
+
if (done(await mount.read('/home/a.txt'), 'read /home/a.txt') !== 'alpha')
|
|
75
|
+
breach('read /home/a.txt did not give its content');
|
|
76
|
+
refused(await mount.read('/home/missing.txt'), ['ENOENT'], 'read of a missing file');
|
|
77
|
+
refused(await mount.read('/home/docs'), ['EISDIR'], 'read of a folder');
|
|
78
|
+
}
|
|
79
|
+
if (mount.readBinary) {
|
|
80
|
+
const bytes = done(await mount.readBinary('/home/docs/b.txt'), 'readBinary /home/docs/b.txt');
|
|
81
|
+
if (bytes.toString('utf-8') !== 'beta')
|
|
82
|
+
breach('readBinary did not give the file\'s bytes');
|
|
83
|
+
refused(await mount.readBinary('/home/missing.txt'), ['ENOENT'], 'readBinary of a missing file');
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'writes a file whole: a new file, then its content replaced; ENOENT where the folder is missing',
|
|
89
|
+
run: async (driver) => {
|
|
90
|
+
const mount = await driver.mount_make(SEED);
|
|
91
|
+
if (!mount.write)
|
|
92
|
+
return;
|
|
93
|
+
done(await mount.write('/home/new.txt', 'first'), 'write of a new file');
|
|
94
|
+
done(await mount.write('/home/new.txt', 'second'), 'write over an existing file');
|
|
95
|
+
if (mount.read && done(await mount.read('/home/new.txt'), 'read after write') !== 'second') {
|
|
96
|
+
breach('a write did not replace the file\'s content');
|
|
97
|
+
}
|
|
98
|
+
done(await mount.write('/home/a.txt', 'replaced'), 'write over a seeded file');
|
|
99
|
+
if (mount.read && done(await mount.read('/home/a.txt'), 'read after write') !== 'replaced') {
|
|
100
|
+
breach('a write did not replace a seeded file\'s content');
|
|
101
|
+
}
|
|
102
|
+
refused(await mount.write('/home/nowhere/c.txt', 'x'), ['ENOENT'], 'write into a missing folder');
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'makes a folder; EEXIST for anything already there, ENOENT for a missing parent, ENOTDIR beneath a file',
|
|
107
|
+
run: async (driver) => {
|
|
108
|
+
const mount = await driver.mount_make(SEED);
|
|
109
|
+
if (!mount.mkdir)
|
|
110
|
+
return;
|
|
111
|
+
done(await mount.mkdir('/home/made'), 'mkdir /home/made');
|
|
112
|
+
if (!(await names_of(mount, '/home')).includes('made:dir'))
|
|
113
|
+
breach('mkdir did not make the folder');
|
|
114
|
+
refused(await mount.mkdir('/home/docs'), ['EEXIST'], 'mkdir of an existing folder');
|
|
115
|
+
refused(await mount.mkdir('/home/nowhere/deeper'), ['ENOENT'], 'mkdir under a missing parent');
|
|
116
|
+
refused(await mount.mkdir('/home/a.txt'), ['EEXIST'], 'mkdir where a file is');
|
|
117
|
+
refused(await mount.mkdir('/home/a.txt/under'), ['ENOTDIR'], 'mkdir beneath a file');
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'makes a folder and its missing parents in one step where it offers to; EEXIST for anything already there, ENOTDIR beneath a file',
|
|
122
|
+
run: async (driver) => {
|
|
123
|
+
const mount = await driver.mount_make(SEED);
|
|
124
|
+
if (!mount.mkdirTree)
|
|
125
|
+
return;
|
|
126
|
+
done(await mount.mkdirTree('/home/new/deeper/still'), 'mkdirTree under missing parents');
|
|
127
|
+
if (!(await names_of(mount, '/home/new/deeper')).includes('still:dir'))
|
|
128
|
+
breach('mkdirTree did not make the folder');
|
|
129
|
+
refused(await mount.mkdirTree('/home/docs'), ['EEXIST'], 'mkdirTree of an existing folder');
|
|
130
|
+
refused(await mount.mkdirTree('/home/a.txt'), ['EEXIST'], 'mkdirTree where a file is');
|
|
131
|
+
refused(await mount.mkdirTree('/home/a.txt/under/deeper'), ['ENOTDIR'], 'mkdirTree beneath a file');
|
|
132
|
+
if ((await names_of(mount, '/home')).includes('a.txt:dir'))
|
|
133
|
+
breach('mkdirTree made a folder over a file');
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'removes an empty folder; ENOTEMPTY, ENOENT and ENOTDIR as a disk says them',
|
|
138
|
+
run: async (driver) => {
|
|
139
|
+
const mount = await driver.mount_make(SEED);
|
|
140
|
+
if (!mount.rmdir)
|
|
141
|
+
return;
|
|
142
|
+
done(await mount.rmdir('/home/empty'), 'rmdir of an empty folder');
|
|
143
|
+
if ((await names_of(mount, '/home')).includes('empty:dir'))
|
|
144
|
+
breach('rmdir did not remove the folder');
|
|
145
|
+
refused(await mount.rmdir('/home/docs'), ['ENOTEMPTY'], 'rmdir of a folder that holds something');
|
|
146
|
+
refused(await mount.rmdir('/home/missing'), ['ENOENT'], 'rmdir of nothing there');
|
|
147
|
+
refused(await mount.rmdir('/home/a.txt'), ['ENOTDIR'], 'rmdir of a file');
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'renames a file; ENOENT for nothing there; onto an existing file it replaces it or refuses with EEXIST',
|
|
152
|
+
run: async (driver) => {
|
|
153
|
+
const mount = await driver.mount_make(SEED);
|
|
154
|
+
if (!mount.rename)
|
|
155
|
+
return;
|
|
156
|
+
done(await mount.rename('/home/a.txt', '/home/docs/a.txt'), 'rename into a folder');
|
|
157
|
+
const home = await names_of(mount, '/home');
|
|
158
|
+
const docs = await names_of(mount, '/home/docs');
|
|
159
|
+
if (home.includes('a.txt:file') || !docs.includes('a.txt:file'))
|
|
160
|
+
breach('rename did not move the file');
|
|
161
|
+
if (mount.read && done(await mount.read('/home/docs/a.txt'), 'read after rename') !== 'alpha')
|
|
162
|
+
breach('rename lost the file\'s content');
|
|
163
|
+
refused(await mount.rename('/home/missing.txt', '/home/x.txt'), ['ENOENT'], 'rename of nothing there');
|
|
164
|
+
const onto = await mount.rename('/home/docs/a.txt', '/home/docs/b.txt');
|
|
165
|
+
if (!onto.ok)
|
|
166
|
+
refused(onto, ['EEXIST'], 'rename onto an existing file');
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'removes a file; EISDIR for a folder, ENOENT for nothing there',
|
|
171
|
+
run: async (driver) => {
|
|
172
|
+
const mount = await driver.mount_make(SEED);
|
|
173
|
+
if (!mount.rm)
|
|
174
|
+
return;
|
|
175
|
+
done(await mount.rm('/home/a.txt'), 'rm of a file');
|
|
176
|
+
if ((await names_of(mount, '/home')).includes('a.txt:file'))
|
|
177
|
+
breach('rm did not remove the file');
|
|
178
|
+
refused(await mount.rm('/home/docs'), ['EISDIR'], 'rm of a folder');
|
|
179
|
+
refused(await mount.rm('/home/missing.txt'), ['ENOENT'], 'rm of nothing there');
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'removes a folder whole where it offers to; ENOENT for nothing there',
|
|
184
|
+
run: async (driver) => {
|
|
185
|
+
const mount = await driver.mount_make(SEED);
|
|
186
|
+
if (!mount.rmTree)
|
|
187
|
+
return;
|
|
188
|
+
done(await mount.rmTree('/home/docs'), 'rmTree of a folder with a file in it');
|
|
189
|
+
if ((await names_of(mount, '/home')).includes('docs:dir'))
|
|
190
|
+
breach('rmTree did not remove the folder');
|
|
191
|
+
refused(await mount.rmTree('/home/missing'), ['ENOENT'], 'rmTree of nothing there');
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/vfs/contract.ts"],"names":[],"mappings":";;;AA6BA;;;;GAIG;AACH,SAAS,MAAM,CAAC,IAAY;IAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,SAAS,IAAI,CAAI,OAAsB,EAAE,IAAY;IACnD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,GAAG,IAAI,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1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The virtual filesystem's dispatcher: routes each request to the
|
|
3
|
+
* mount that owns the path.
|
|
4
|
+
*
|
|
5
|
+
* Mounts (providers) are registered with a path prefix; the longest prefix
|
|
6
|
+
* that matches at a segment boundary wins, so `/proc/jobs` takes precedence
|
|
7
|
+
* over `/proc`, and `/procs` is not under `/proc`. A path no mount claims
|
|
8
|
+
* goes to the fallback, the provider given to the constructor. The
|
|
9
|
+
* dispatcher itself knows no backend: a backend registers its mounts and
|
|
10
|
+
* names its fallback.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { Result } from "../result.js";
|
|
15
|
+
import { VFSProvider, VFSItem, CpOptions } from "./provider.js";
|
|
16
|
+
import { type VfsOutcome } from "./outcome.js";
|
|
17
|
+
/**
|
|
18
|
+
* Routes filesystem requests to the mount that owns each path, or to the
|
|
19
|
+
* fallback.
|
|
20
|
+
*/
|
|
21
|
+
export declare class VFSDispatcher {
|
|
22
|
+
private providers;
|
|
23
|
+
private defaultProvider;
|
|
24
|
+
private pathResolver?;
|
|
25
|
+
/**
|
|
26
|
+
* @param fallback - The provider for paths no mount claims; one that holds
|
|
27
|
+
* nothing, and says so, when none is given.
|
|
28
|
+
*/
|
|
29
|
+
constructor(fallback?: VFSProvider);
|
|
30
|
+
/**
|
|
31
|
+
* Registers a path resolution hook that maps logical paths to physical paths.
|
|
32
|
+
*
|
|
33
|
+
* @param resolver - The resolver function mapping a logical path to a physical path.
|
|
34
|
+
*/
|
|
35
|
+
pathResolver_register(resolver: (path: string) => Promise<string>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Registers a new VFS Provider.
|
|
38
|
+
*
|
|
39
|
+
* @param provider - The provider instance to register.
|
|
40
|
+
*/
|
|
41
|
+
provider_register(provider: VFSProvider): void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns every registered mount (not the fallback). Used by callers that
|
|
44
|
+
* need to detect parent-of-prefix paths.
|
|
45
|
+
*/
|
|
46
|
+
providers_get(): VFSProvider[];
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the matching provider for a given virtual path.
|
|
49
|
+
*
|
|
50
|
+
* @param pathStr - The absolute virtual path.
|
|
51
|
+
* @returns The matching mount, or the fallback.
|
|
52
|
+
*/
|
|
53
|
+
provider_get(pathStr: string): VFSProvider;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a path belongs to a mount rather than to the fallback.
|
|
56
|
+
*
|
|
57
|
+
* Two shapes count: a path a mount owns (at or under its prefix), and a
|
|
58
|
+
* path that is a strict ancestor of a mount's prefix (`/proc` above
|
|
59
|
+
* `/proc/jobs`), whose only children are the mounts beneath it. The root
|
|
60
|
+
* `/` never counts: it is the fallback's own root.
|
|
61
|
+
*
|
|
62
|
+
* It keeps the fallback from being asked to answer for a path it has no
|
|
63
|
+
* folder behind, which cannot succeed and only fills the error stack once
|
|
64
|
+
* per ancestor a path walk visits.
|
|
65
|
+
*
|
|
66
|
+
* @param pathStr - The absolute (or root-relative) path to classify.
|
|
67
|
+
* @returns True when a mount owns, or is owned by, the path.
|
|
68
|
+
*/
|
|
69
|
+
path_isVirtual(pathStr: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Dispatches directory listing to matched provider.
|
|
72
|
+
* Supports dynamic intermediate parent path synthesis for virtual prefixes.
|
|
73
|
+
*
|
|
74
|
+
* @param pathStr - The absolute virtual path to list.
|
|
75
|
+
* @param options - Sort controls.
|
|
76
|
+
* @returns Promise resolving to Result<VFSItem[]>.
|
|
77
|
+
*/
|
|
78
|
+
list(pathStr: string, options?: {
|
|
79
|
+
sort?: "name" | "size" | "date" | "owner";
|
|
80
|
+
reverse?: boolean;
|
|
81
|
+
}): Promise<Result<VFSItem[]>>;
|
|
82
|
+
/**
|
|
83
|
+
* The path a provider is asked with: as given for a mount, and through
|
|
84
|
+
* the path resolver for the fallback, when one is registered. An
|
|
85
|
+
* operation never proceeds on a guessed path: a path that does not
|
|
86
|
+
* resolve fails the operation.
|
|
87
|
+
*
|
|
88
|
+
* @param provider - The provider the path belongs to.
|
|
89
|
+
* @param pathStr - The path as asked.
|
|
90
|
+
* @param what - How a resolution failure names the path (`source path`, `path`).
|
|
91
|
+
* @param operation - The verb, for the failure's words.
|
|
92
|
+
* @returns The path to ask with, or why the operation cannot proceed.
|
|
93
|
+
*/
|
|
94
|
+
private pathFor_provider;
|
|
95
|
+
/**
|
|
96
|
+
* Copies within or between paths, through the provider that owns the source.
|
|
97
|
+
*
|
|
98
|
+
* @param src - Source path.
|
|
99
|
+
* @param dest - Destination path.
|
|
100
|
+
* @param options - Copy options.
|
|
101
|
+
* @returns Done, or why not.
|
|
102
|
+
*/
|
|
103
|
+
cp(src: string, dest: string, options: CpOptions): Promise<VfsOutcome>;
|
|
104
|
+
/**
|
|
105
|
+
* Reads a file whole, as text, through the provider that owns it.
|
|
106
|
+
*
|
|
107
|
+
* @param pathStr - The absolute path of the file.
|
|
108
|
+
* @returns Its content, or why not (`EROFS` where no read is offered).
|
|
109
|
+
*/
|
|
110
|
+
read(pathStr: string): Promise<VfsOutcome<string>>;
|
|
111
|
+
/**
|
|
112
|
+
* A failed read of a folder says so: whatever the owning mount answered
|
|
113
|
+
* (CUBE's "File not found", a projection's own words, a mount that reads
|
|
114
|
+
* nothing), a path its parent lists as a folder is a directory, as a
|
|
115
|
+
* disk says.
|
|
116
|
+
*
|
|
117
|
+
* @param pathStr - The path read.
|
|
118
|
+
* @param outcome - The read's answer.
|
|
119
|
+
* @returns The answer, or `EISDIR` when it failed on a folder.
|
|
120
|
+
*/
|
|
121
|
+
private readFailure_classify;
|
|
122
|
+
/**
|
|
123
|
+
* Reads a file whole, as bytes, through the provider that owns it.
|
|
124
|
+
*
|
|
125
|
+
* @param pathStr - The absolute path of the file.
|
|
126
|
+
* @returns Its bytes, or why not.
|
|
127
|
+
*/
|
|
128
|
+
readBinary(pathStr: string): Promise<VfsOutcome<Buffer>>;
|
|
129
|
+
/**
|
|
130
|
+
* Writes a file whole, through the provider that owns it; a mount that
|
|
131
|
+
* holds no writable files answers `EROFS`.
|
|
132
|
+
*
|
|
133
|
+
* @param pathStr - The absolute path of the file.
|
|
134
|
+
* @param content - The new content, whole.
|
|
135
|
+
* @returns Done, or why not.
|
|
136
|
+
*/
|
|
137
|
+
write(pathStr: string, content: string | Buffer): Promise<VfsOutcome>;
|
|
138
|
+
/**
|
|
139
|
+
* Makes a folder, through the provider that owns its path.
|
|
140
|
+
*
|
|
141
|
+
* @param pathStr - The absolute path of the new folder.
|
|
142
|
+
* @returns Done, or why not.
|
|
143
|
+
*/
|
|
144
|
+
mkdir(pathStr: string): Promise<VfsOutcome>;
|
|
145
|
+
/**
|
|
146
|
+
* Whether the provider that owns a folder makes it and its parents in one step.
|
|
147
|
+
*
|
|
148
|
+
* @param pathStr - The absolute path of the folder.
|
|
149
|
+
* @returns True when `mkdirTree` is offered there.
|
|
150
|
+
*/
|
|
151
|
+
mkdirTree_offered(pathStr: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Makes a folder and any missing parents in one step, where the owning
|
|
154
|
+
* provider can; elsewhere `EROFS`, and `mkdir -p` walks instead.
|
|
155
|
+
*
|
|
156
|
+
* @param pathStr - The absolute path of the folder.
|
|
157
|
+
* @returns Done, or why not.
|
|
158
|
+
*/
|
|
159
|
+
mkdirTree(pathStr: string): Promise<VfsOutcome>;
|
|
160
|
+
/**
|
|
161
|
+
* Removes an empty folder, through the provider that owns it.
|
|
162
|
+
*
|
|
163
|
+
* @param pathStr - The absolute path of the folder.
|
|
164
|
+
* @returns Done, or why not.
|
|
165
|
+
*/
|
|
166
|
+
rmdir(pathStr: string): Promise<VfsOutcome>;
|
|
167
|
+
/**
|
|
168
|
+
* Renames within one mount; a rename across mounts answers `EXDEV`.
|
|
169
|
+
*
|
|
170
|
+
* @param src - The absolute path now.
|
|
171
|
+
* @param dest - The absolute path it takes.
|
|
172
|
+
* @returns Done, or why not.
|
|
173
|
+
*/
|
|
174
|
+
rename(src: string, dest: string): Promise<VfsOutcome>;
|
|
175
|
+
/**
|
|
176
|
+
* Removes a file or a link, through the provider that owns it.
|
|
177
|
+
*
|
|
178
|
+
* @param pathStr - The absolute path of the entry.
|
|
179
|
+
* @returns Done, or why not.
|
|
180
|
+
*/
|
|
181
|
+
rm(pathStr: string): Promise<VfsOutcome>;
|
|
182
|
+
/**
|
|
183
|
+
* Whether the provider that owns a folder removes it whole in one step.
|
|
184
|
+
*
|
|
185
|
+
* @param pathStr - The absolute path of the folder.
|
|
186
|
+
* @returns True when `rmTree` is offered there.
|
|
187
|
+
*/
|
|
188
|
+
rmTree_offered(pathStr: string): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Removes a folder and everything under it in one step, where the
|
|
191
|
+
* owning provider can; elsewhere `EROFS`, and `rm -r` walks instead.
|
|
192
|
+
*
|
|
193
|
+
* @param pathStr - The absolute path of the folder.
|
|
194
|
+
* @returns Done, or why not.
|
|
195
|
+
*/
|
|
196
|
+
rmTree(pathStr: string): Promise<VfsOutcome>;
|
|
197
|
+
/**
|
|
198
|
+
* Resolves a lazy link through the provider that owns it.
|
|
199
|
+
*
|
|
200
|
+
* This is deliberately distinct from {@link list}: a structural traversal
|
|
201
|
+
* can display an unresolved link without causing its provider to fetch the
|
|
202
|
+
* target from a remote service.
|
|
203
|
+
*
|
|
204
|
+
* @param pathStr - Absolute path of the provider-defined link.
|
|
205
|
+
* @returns The resolved target path, or an error if unsupported or absent.
|
|
206
|
+
*/
|
|
207
|
+
linkTarget_resolve(pathStr: string): Promise<Result<string>>;
|
|
208
|
+
}
|