@fnndsc/fond 0.2.0 → 0.4.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 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
 
@@ -24,6 +24,9 @@ fond's one rule: **it depends on nothing in `@fnndsc`**. CI holds it to that (`n
24
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
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
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. |
27
30
 
28
31
  ## Using `Result`
29
32
 
package/dist/index.d.ts CHANGED
@@ -13,3 +13,8 @@ export * from './errorStack.js';
13
13
  export * from './vfs/provider.js';
14
14
  export * from './vfs/sort.js';
15
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
@@ -29,4 +29,9 @@ __exportStar(require("./errorStack.js"), exports);
29
29
  __exportStar(require("./vfs/provider.js"), exports);
30
30
  __exportStar(require("./vfs/sort.js"), exports);
31
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);
32
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;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,sDAAoC"}
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,gBAAgB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/G,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,OAAO,CAAI,OAAsB,EAAE,MAA+B,EAAE,IAAY;IACvF,IAAI,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,GAAG,IAAI,wBAAwB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7E,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QA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AC,EAAE,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC;YACpE,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC,CAAC;QAClF,CAAC;KACF;IACD;QACE,IAAI,EAAE,qEAAqE;QAC3E,GAAG,EAAE,KAAK,EAAE,MAAyB,EAAiB,EAAE;YACtD,MAAM,KAAK,GAAgB,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACzD,IAAI,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO;YAC1B,IAAI,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,sCAAsC,CAAC,CAAC;YAC/E,IAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAAE,MAAM,CAAC,kCAAkC,CAAC,CAAC;YACtG,OAAO,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,yBAAyB,CAAC,CAAC;QACtF,CAAC;KACF;CACF,CAAC"}
@@ -12,7 +12,8 @@
12
12
  * @module
13
13
  */
14
14
  import { Result } from "../result.js";
15
- import { VFSProvider, VFSItem, CpOptions } from "./provider.js";
15
+ import { VFSProvider, VFSItem, CpOptions, type VFSSubtree } from "./provider.js";
16
+ import { type VfsOutcome } from "./outcome.js";
16
17
  /**
17
18
  * Routes filesystem requests to the mount that owns each path, or to the
18
19
  * fallback.
@@ -66,6 +67,14 @@ export declare class VFSDispatcher {
66
67
  * @returns True when a mount owns, or is owned by, the path.
67
68
  */
68
69
  path_isVirtual(pathStr: string): boolean;
70
+ /**
71
+ * Asks the mount that owns a path to answer its whole subtree from what it
72
+ * holds (see {@link VFSProvider.subtree}).
73
+ *
74
+ * @param pathStr - The subtree's root.
75
+ * @returns The answer, or null when the mount cannot give one.
76
+ */
77
+ subtree(pathStr: string): Promise<VFSSubtree | null>;
69
78
  /**
70
79
  * Dispatches directory listing to matched provider.
71
80
  * Supports dynamic intermediate parent path synthesis for virtual prefixes.
@@ -79,63 +88,120 @@ export declare class VFSDispatcher {
79
88
  reverse?: boolean;
80
89
  }): Promise<Result<VFSItem[]>>;
81
90
  /**
82
- * Dispatches copy operation to matched provider.
91
+ * The path a provider is asked with: as given for a mount, and through
92
+ * the path resolver for the fallback, when one is registered. An
93
+ * operation never proceeds on a guessed path: a path that does not
94
+ * resolve fails the operation.
95
+ *
96
+ * @param provider - The provider the path belongs to.
97
+ * @param pathStr - The path as asked.
98
+ * @param what - How a resolution failure names the path (`source path`, `path`).
99
+ * @param operation - The verb, for the failure's words.
100
+ * @returns The path to ask with, or why the operation cannot proceed.
101
+ */
102
+ private pathFor_provider;
103
+ /**
104
+ * Copies within or between paths, through the provider that owns the source.
83
105
  *
84
106
  * @param src - Source path.
85
107
  * @param dest - Destination path.
86
108
  * @param options - Copy options.
87
- * @returns Promise resolving to success boolean.
109
+ * @returns Done, or why not.
110
+ */
111
+ cp(src: string, dest: string, options: CpOptions): Promise<VfsOutcome>;
112
+ /**
113
+ * Reads a file whole, as text, through the provider that owns it.
114
+ *
115
+ * @param pathStr - The absolute path of the file.
116
+ * @returns Its content, or why not (`EROFS` where no read is offered).
117
+ */
118
+ read(pathStr: string): Promise<VfsOutcome<string>>;
119
+ /**
120
+ * A failed read of a folder says so: whatever the owning mount answered
121
+ * (CUBE's "File not found", a projection's own words, a mount that reads
122
+ * nothing), a path its parent lists as a folder is a directory, as a
123
+ * disk says.
124
+ *
125
+ * @param pathStr - The path read.
126
+ * @param outcome - The read's answer.
127
+ * @returns The answer, or `EISDIR` when it failed on a folder.
128
+ */
129
+ private readFailure_classify;
130
+ /**
131
+ * Reads a file whole, as bytes, through the provider that owns it.
132
+ *
133
+ * @param pathStr - The absolute path of the file.
134
+ * @returns Its bytes, or why not.
135
+ */
136
+ readBinary(pathStr: string): Promise<VfsOutcome<Buffer>>;
137
+ /**
138
+ * Writes a file whole, through the provider that owns it; a mount that
139
+ * holds no writable files answers `EROFS`.
140
+ *
141
+ * @param pathStr - The absolute path of the file.
142
+ * @param content - The new content, whole.
143
+ * @returns Done, or why not.
144
+ */
145
+ write(pathStr: string, content: string | Buffer): Promise<VfsOutcome>;
146
+ /**
147
+ * Makes a folder, through the provider that owns its path.
148
+ *
149
+ * @param pathStr - The absolute path of the new folder.
150
+ * @returns Done, or why not.
151
+ */
152
+ mkdir(pathStr: string): Promise<VfsOutcome>;
153
+ /**
154
+ * Whether the provider that owns a folder makes it and its parents in one step.
155
+ *
156
+ * @param pathStr - The absolute path of the folder.
157
+ * @returns True when `mkdirTree` is offered there.
88
158
  */
89
- cp(src: string, dest: string, options: CpOptions): Promise<boolean>;
159
+ mkdirTree_offered(pathStr: string): boolean;
90
160
  /**
91
- * Dispatches file read operation to the matched provider.
161
+ * Makes a folder and any missing parents in one step, where the owning
162
+ * provider can; elsewhere `EROFS`, and `mkdir -p` walks instead.
92
163
  *
93
- * @param pathStr - The absolute virtual path of the file to read.
94
- * @returns A Promise resolving to a Result containing the file contents as a string.
164
+ * @param pathStr - The absolute path of the folder.
165
+ * @returns Done, or why not.
95
166
  */
96
- read(pathStr: string): Promise<Result<string>>;
167
+ mkdirTree(pathStr: string): Promise<VfsOutcome>;
97
168
  /**
98
- * Dispatches a whole-file write to the matched provider: a mount
99
- * that holds writable files (a feed's note) takes the content; any other
100
- * path is refused by name rather than written somewhere it does not live.
169
+ * Removes an empty folder, through the provider that owns it.
101
170
  *
102
- * @param pathStr - The absolute virtual path of the file.
103
- * @param content - The file's new content, whole.
104
- * @returns True when the provider took it.
171
+ * @param pathStr - The absolute path of the folder.
172
+ * @returns Done, or why not.
105
173
  */
174
+ rmdir(pathStr: string): Promise<VfsOutcome>;
106
175
  /**
107
- * Dispatches a folder's making to the matched provider; a mount that
108
- * makes no folders refuses by name.
176
+ * Renames within one mount; a rename across mounts answers `EXDEV`.
109
177
  *
110
- * @param pathStr - The absolute virtual path of the new folder.
111
- * @returns True when the provider made it.
178
+ * @param src - The absolute path now.
179
+ * @param dest - The absolute path it takes.
180
+ * @returns Done, or why not.
112
181
  */
113
- mkdir(pathStr: string): Promise<boolean>;
182
+ rename(src: string, dest: string): Promise<VfsOutcome>;
114
183
  /**
115
- * Dispatches an empty folder's removal to the matched provider; a
116
- * mount that removes no folders refuses by name.
184
+ * Removes a file or a link, through the provider that owns it.
117
185
  *
118
- * @param pathStr - The absolute virtual path of the folder.
119
- * @returns True when the provider removed it.
186
+ * @param pathStr - The absolute path of the entry.
187
+ * @returns Done, or why not.
120
188
  */
121
- rmdir(pathStr: string): Promise<boolean>;
189
+ rm(pathStr: string): Promise<VfsOutcome>;
122
190
  /**
123
- * Dispatches a rename within one mount; a rename across mounts, or in a
124
- * mount that renames nothing, is refused by name.
191
+ * Whether the provider that owns a folder removes it whole in one step.
125
192
  *
126
- * @param src - The absolute virtual path now.
127
- * @param dest - The absolute virtual path it takes.
128
- * @returns True when the provider renamed it.
193
+ * @param pathStr - The absolute path of the folder.
194
+ * @returns True when `rmTree` is offered there.
129
195
  */
130
- rename(src: string, dest: string): Promise<boolean>;
131
- write(pathStr: string, content: string): Promise<boolean>;
196
+ rmTree_offered(pathStr: string): boolean;
132
197
  /**
133
- * Dispatches binary file read operation to the matched provider.
198
+ * Removes a folder and everything under it in one step, where the
199
+ * owning provider can; elsewhere `EROFS`, and `rm -r` walks instead.
134
200
  *
135
- * @param pathStr - The absolute virtual path of the file to read.
136
- * @returns A Promise resolving to a Result containing the file contents as a Buffer.
201
+ * @param pathStr - The absolute path of the folder.
202
+ * @returns Done, or why not.
137
203
  */
138
- readBinary(pathStr: string): Promise<Result<Buffer>>;
204
+ rmTree(pathStr: string): Promise<VfsOutcome>;
139
205
  /**
140
206
  * Resolves a lazy link through the provider that owns it.
141
207
  *