@fnndsc/salsa 4.5.7 → 4.6.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 +0 -2
- package/dist/compute/index.d.ts +0 -9
- package/dist/compute/index.js +0 -16
- package/dist/compute/index.js.map +1 -1
- package/dist/dag/feedData.js +166 -73
- package/dist/dag/feedData.js.map +1 -1
- package/dist/dag/feedLoad.d.ts +1 -1
- package/dist/dag/feedLoad.js +6 -4
- package/dist/dag/feedLoad.js.map +1 -1
- package/dist/dicom/pixels.js +95 -36
- package/dist/dicom/pixels.js.map +1 -1
- package/dist/dicom/series.d.ts +4 -1
- package/dist/dicom/series.js +80 -31
- package/dist/dicom/series.js.map +1 -1
- package/dist/dicom/tags.d.ts +28 -0
- package/dist/dicom/tags.js +30 -0
- package/dist/dicom/tags.js.map +1 -1
- package/dist/files/copy.d.ts +197 -0
- package/dist/files/copy.js +636 -0
- package/dist/files/copy.js.map +1 -0
- package/dist/files/copyFolder.d.ts +103 -0
- package/dist/files/copyFolder.js +199 -0
- package/dist/files/copyFolder.js.map +1 -0
- package/dist/files/create.d.ts +178 -0
- package/dist/files/create.js +444 -0
- package/dist/files/create.js.map +1 -0
- package/dist/files/download.d.ts +188 -0
- package/dist/files/download.js +541 -0
- package/dist/files/download.js.map +1 -0
- package/dist/files/index.d.ts +69 -141
- package/dist/files/index.js +184 -535
- package/dist/files/index.js.map +1 -1
- package/dist/files/listing.d.ts +132 -0
- package/dist/files/listing.js +179 -0
- package/dist/files/listing.js.map +1 -0
- package/dist/files/move.d.ts +125 -0
- package/dist/files/move.js +334 -0
- package/dist/files/move.js.map +1 -0
- package/dist/files/pathMapper.d.ts +24 -1
- package/dist/files/pathMapper.js +108 -47
- package/dist/files/pathMapper.js.map +1 -1
- package/dist/files/proof.d.ts +315 -0
- package/dist/files/proof.js +574 -0
- package/dist/files/proof.js.map +1 -0
- package/dist/files/removal.d.ts +223 -0
- package/dist/files/removal.js +318 -0
- package/dist/files/removal.js.map +1 -0
- package/dist/files/replace.d.ts +175 -0
- package/dist/files/replace.js +582 -0
- package/dist/files/replace.js.map +1 -0
- package/dist/files/upload.d.ts +205 -0
- package/dist/files/upload.js +478 -0
- package/dist/files/upload.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +45 -32
- package/dist/index.js.map +1 -1
- package/dist/jobs/index.d.ts +1 -1
- package/dist/jobs/index.js +1 -2
- package/dist/jobs/index.js.map +1 -1
- package/dist/jobs/jobOps.d.ts +0 -13
- package/dist/jobs/jobOps.js +0 -37
- package/dist/jobs/jobOps.js.map +1 -1
- package/dist/pacs/anonymise.d.ts +17 -36
- package/dist/pacs/anonymise.js +29 -67
- package/dist/pacs/anonymise.js.map +1 -1
- package/dist/pipelines/index.d.ts +1 -13
- package/dist/pipelines/index.js +0 -38
- package/dist/pipelines/index.js.map +1 -1
- package/dist/pipelines/invocation.js +321 -167
- package/dist/pipelines/invocation.js.map +1 -1
- package/dist/pipelines/manifest.js.map +1 -1
- package/dist/pipelines/packages.d.ts +11 -8
- package/dist/pipelines/packages.js +253 -77
- package/dist/pipelines/packages.js.map +1 -1
- package/dist/plugins/adminToken.d.ts +67 -0
- package/dist/plugins/adminToken.js +77 -0
- package/dist/plugins/adminToken.js.map +1 -0
- package/dist/plugins/index.d.ts +0 -7
- package/dist/plugins/index.js +0 -16
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/peer_search.d.ts +0 -15
- package/dist/plugins/peer_search.js +0 -25
- package/dist/plugins/peer_search.js.map +1 -1
- package/dist/plugins/plugin_add.d.ts +14 -2
- package/dist/plugins/plugin_add.js +42 -13
- package/dist/plugins/plugin_add.js.map +1 -1
- package/dist/plugins/plugin_docker.d.ts +25 -0
- package/dist/plugins/plugin_docker.js +33 -0
- package/dist/plugins/plugin_docker.js.map +1 -1
- package/dist/plugins/plugin_register.d.ts +0 -10
- package/dist/plugins/plugin_register.js +3 -54
- package/dist/plugins/plugin_register.js.map +1 -1
- package/dist/plugins/plugin_sync.js +45 -22
- package/dist/plugins/plugin_sync.js.map +1 -1
- package/dist/plugins/plugin_validate.js +47 -13
- package/dist/plugins/plugin_validate.js.map +1 -1
- package/dist/plugins/store_import.d.ts +0 -9
- package/dist/plugins/store_import.js +3 -29
- package/dist/plugins/store_import.js.map +1 -1
- package/dist/retrieve/task.d.ts +137 -0
- package/dist/retrieve/task.js +41 -0
- package/dist/retrieve/task.js.map +1 -0
- package/dist/retrieve/watch.d.ts +2 -118
- package/dist/retrieve/watch.js +452 -321
- package/dist/retrieve/watch.js.map +1 -1
- package/dist/vfs/providers/etc.d.ts +6 -4
- package/dist/vfs/providers/etc.js +12 -4
- package/dist/vfs/providers/etc.js.map +1 -1
- package/dist/vfs/providers/native.d.ts +116 -39
- package/dist/vfs/providers/native.js +291 -347
- package/dist/vfs/providers/native.js.map +1 -1
- package/dist/vfs/providers/pacs.d.ts +29 -3
- package/dist/vfs/providers/pacs.js +303 -73
- package/dist/vfs/providers/pacs.js.map +1 -1
- package/dist/vfs/providers/pacs_content.js +22 -6
- package/dist/vfs/providers/pacs_content.js.map +1 -1
- package/dist/vfs/providers/proc/backfill.d.ts +46 -0
- package/dist/vfs/providers/proc/backfill.js +147 -0
- package/dist/vfs/providers/proc/backfill.js.map +1 -0
- package/dist/vfs/providers/proc/book.d.ts +176 -0
- package/dist/vfs/providers/proc/book.js +73 -0
- package/dist/vfs/providers/proc/book.js.map +1 -0
- package/dist/vfs/providers/proc/catchup.d.ts +69 -0
- package/dist/vfs/providers/proc/catchup.js +125 -0
- package/dist/vfs/providers/proc/catchup.js.map +1 -0
- package/dist/vfs/providers/proc/feedIndex.d.ts +146 -0
- package/dist/vfs/providers/proc/feedIndex.js +354 -0
- package/dist/vfs/providers/proc/feedIndex.js.map +1 -0
- package/dist/vfs/providers/proc/feedTopology.d.ts +85 -0
- package/dist/vfs/providers/proc/feedTopology.js +192 -0
- package/dist/vfs/providers/proc/feedTopology.js.map +1 -0
- package/dist/vfs/providers/proc/locate.d.ts +60 -0
- package/dist/vfs/providers/proc/locate.js +103 -0
- package/dist/vfs/providers/proc/locate.js.map +1 -0
- package/dist/vfs/providers/proc/path.d.ts +50 -0
- package/dist/vfs/providers/proc/path.js +106 -0
- package/dist/vfs/providers/proc/path.js.map +1 -0
- package/dist/vfs/providers/proc/roster.d.ts +95 -0
- package/dist/vfs/providers/proc/roster.js +425 -0
- package/dist/vfs/providers/proc/roster.js.map +1 -0
- package/dist/vfs/providers/proc/rows.d.ts +120 -0
- package/dist/vfs/providers/proc/rows.js +181 -0
- package/dist/vfs/providers/proc/rows.js.map +1 -0
- package/dist/vfs/providers/proc/subtree.d.ts +73 -0
- package/dist/vfs/providers/proc/subtree.js +125 -0
- package/dist/vfs/providers/proc/subtree.js.map +1 -0
- package/dist/vfs/providers/proc/sweep.d.ts +89 -0
- package/dist/vfs/providers/proc/sweep.js +297 -0
- package/dist/vfs/providers/proc/sweep.js.map +1 -0
- package/dist/vfs/providers/proc.d.ts +47 -346
- package/dist/vfs/providers/proc.js +349 -1806
- package/dist/vfs/providers/proc.js.map +1 -1
- package/dist/vfs/providers/share.js +4 -1
- package/dist/vfs/providers/share.js.map +1 -1
- package/package.json +3 -3
- package/dist/pacs/resultDecode.d.ts +0 -13
- package/dist/pacs/resultDecode.js +0 -19
- package/dist/pacs/resultDecode.js.map +0 -1
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Making what is not there yet, on proof that nothing holds its name.
|
|
4
|
+
*
|
|
5
|
+
* A folder is made, and a file is stored, only once a whole proof of the
|
|
6
|
+
* path says nothing holds it (`pathHolders_answer`, made fresh on the one
|
|
7
|
+
* client the act is bound to). A proof that could not be made is never
|
|
8
|
+
* read as a free name. A file already there is replaced, kept, or refused,
|
|
9
|
+
* as the caller asked (`file_store` of `./replace.js`), and a folder or
|
|
10
|
+
* several holders at the name refuse the write.
|
|
11
|
+
*
|
|
12
|
+
* CUBE makes a folder's missing parents with it, in one request; before it
|
|
13
|
+
* is asked, every folder on the way is proved, up to the root: each missing
|
|
14
|
+
* one absent, and every one that is there exactly one folder, the parent
|
|
15
|
+
* already there included. A folder already there is taken as one (by
|
|
16
|
+
* `files_mkdir`, as a placed write's parent, as `mkdir`'s parent) only on
|
|
17
|
+
* the same proof of the way above it. A file met on the way is `ENOTDIR`; a folder and
|
|
18
|
+
* a file (or two of either) sharing a name on the way is `EPERM`, and
|
|
19
|
+
* nothing is made. A path already held is `EEXIST`, carrying what the proof
|
|
20
|
+
* found there (`vfs_failHeld`). A post whose answer said nothing, with a
|
|
21
|
+
* folder found there after, is a folder there whose maker is not known:
|
|
22
|
+
* the act succeeds and says so (a warning), never claiming it made it.
|
|
23
|
+
*
|
|
24
|
+
* Key components:
|
|
25
|
+
* - files_mkdir: make a folder (and its parents) unless something else holds it.
|
|
26
|
+
* - files_create: store content at a path nothing holds (create-only).
|
|
27
|
+
* - files_touch: make a file, or leave one already there as it is; with content, write it.
|
|
28
|
+
* - file_place: store content with its parent proved (made, when asked), a file there replaced, kept or refused.
|
|
29
|
+
* - path_mkdir / path_mkdirTree: the native mount's `mkdir` and `mkdir -p`.
|
|
30
|
+
*
|
|
31
|
+
* Typical usage:
|
|
32
|
+
* ```ts
|
|
33
|
+
* const made: boolean = await files_mkdir('/home/ada/new/deeper');
|
|
34
|
+
* const placed: VfsOutcome<PlaceReceipt> = await file_place('/home/ada/out/q.csv', new Blob([csv]), { existing: 'refuse', parent: 'make' });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Dependencies: the proofs of `./proof.js` and `./move.js`, the proved
|
|
38
|
+
* write of `./replace.js`, and cumin's `chrisIO` (the session's client,
|
|
39
|
+
* bound as a `HolderClient`: a folder made, an upload). Paths are absolute
|
|
40
|
+
* CUBE paths; one written without its leading slash is read from the root.
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k;
|
|
46
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
47
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
48
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
49
|
+
}
|
|
50
|
+
Object.defineProperty(o, k2, desc);
|
|
51
|
+
}) : (function(o, m, k, k2) {
|
|
52
|
+
if (k2 === undefined) k2 = k;
|
|
53
|
+
o[k2] = m[k];
|
|
54
|
+
}));
|
|
55
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
56
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
57
|
+
}) : function(o, v) {
|
|
58
|
+
o["default"] = v;
|
|
59
|
+
});
|
|
60
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
61
|
+
var ownKeys = function(o) {
|
|
62
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
63
|
+
var ar = [];
|
|
64
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
65
|
+
return ar;
|
|
66
|
+
};
|
|
67
|
+
return ownKeys(o);
|
|
68
|
+
};
|
|
69
|
+
return function (mod) {
|
|
70
|
+
if (mod && mod.__esModule) return mod;
|
|
71
|
+
var result = {};
|
|
72
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
73
|
+
__setModuleDefault(result, mod);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
})();
|
|
77
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
+
exports.path_mkdir = path_mkdir;
|
|
79
|
+
exports.path_mkdirTree = path_mkdirTree;
|
|
80
|
+
exports.files_mkdir = files_mkdir;
|
|
81
|
+
exports.files_create = files_create;
|
|
82
|
+
exports.files_touch = files_touch;
|
|
83
|
+
exports.file_place = file_place;
|
|
84
|
+
const path = __importStar(require("path"));
|
|
85
|
+
const cumin_1 = require("@fnndsc/cumin");
|
|
86
|
+
const fond_1 = require("@fnndsc/fond");
|
|
87
|
+
const move_js_1 = require("./move.js");
|
|
88
|
+
const proof_js_1 = require("./proof.js");
|
|
89
|
+
const replace_js_1 = require("./replace.js");
|
|
90
|
+
/**
|
|
91
|
+
* The session's client, bound for one act.
|
|
92
|
+
*
|
|
93
|
+
* @param target - The path, for the words.
|
|
94
|
+
* @returns The binding, or null (the reason stacked).
|
|
95
|
+
*/
|
|
96
|
+
async function actClient_bind(target) {
|
|
97
|
+
const bound = await cumin_1.chrisIO.holderClient_bind();
|
|
98
|
+
if (bound.ok)
|
|
99
|
+
return bound.value;
|
|
100
|
+
cumin_1.errorStack.stack_push('error', `Could not make ${target}: there is no connection to CUBE. Nothing was made.`);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The failure a proof met, as an outcome.
|
|
105
|
+
*
|
|
106
|
+
* @param answer - The failed proof.
|
|
107
|
+
* @returns `ENOTDIR` for a file on the way, `EIO` otherwise, with the stacked reason.
|
|
108
|
+
*/
|
|
109
|
+
function proofFailure_outcome(answer) {
|
|
110
|
+
return (0, fond_1.vfs_failFromStack)(answer.notDirectory ? 'ENOTDIR' : 'EIO');
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Says a folder post that came to a folder there whose maker is not known:
|
|
114
|
+
* CUBE's answer said nothing, so this act may have made it or found it.
|
|
115
|
+
*
|
|
116
|
+
* @param target - The folder.
|
|
117
|
+
* @param posted - What the post came to.
|
|
118
|
+
*/
|
|
119
|
+
function folderPosted_say(target, posted) {
|
|
120
|
+
if (posted !== 'present')
|
|
121
|
+
return;
|
|
122
|
+
cumin_1.errorStack.stack_push('warning', `${target} is there now, but CUBE did not answer the request to make it: whether this made it or found it there is not known`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Asks CUBE to make a folder proved free, on the act's client.
|
|
126
|
+
*
|
|
127
|
+
* @param acts - The client the act is bound to.
|
|
128
|
+
* @param target - The folder.
|
|
129
|
+
* @returns Done: made, or there with its maker unknown (`present`, and
|
|
130
|
+
* said); or why not (`EEXIST` CUBE said it was there already, `EIO`).
|
|
131
|
+
*/
|
|
132
|
+
async function folderProved_post(acts, target) {
|
|
133
|
+
const made = (0, fond_1.vfsOutcome_convertFromResult)(await acts.folder_create(target), 'EIO');
|
|
134
|
+
if (!made.ok)
|
|
135
|
+
return made;
|
|
136
|
+
if (made.value === 'existed')
|
|
137
|
+
return (0, fond_1.vfs_fail)('EEXIST');
|
|
138
|
+
folderPosted_say(target, made.value);
|
|
139
|
+
return made.value === 'present' ? (0, fond_1.vfs_okPresent)(true) : (0, fond_1.vfs_ok)(true);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Makes one folder, its parent a folder that is there (`mkdir`): on proof
|
|
143
|
+
* that nothing holds the path, and that its parent is a folder.
|
|
144
|
+
*
|
|
145
|
+
* @param target - The folder's absolute path.
|
|
146
|
+
* @returns Done (`present` when CUBE did not answer and the folder is
|
|
147
|
+
* there, its maker unknown), or why not (`EEXIST` anything there,
|
|
148
|
+
* `ENOENT` no parent, `ENOTDIR` a file on the way, `EPERM`, `EIO`).
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const made: VfsOutcome = await path_mkdir('/home/ada/new');
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
async function path_mkdir(target) {
|
|
156
|
+
const acts = await actClient_bind(target);
|
|
157
|
+
if (acts === null)
|
|
158
|
+
return (0, fond_1.vfs_failFromStack)('EIO');
|
|
159
|
+
const there = await (0, proof_js_1.pathHolders_answer)(target, acts);
|
|
160
|
+
if (there.kind === 'error')
|
|
161
|
+
return proofFailure_outcome(there);
|
|
162
|
+
if (there.kind !== 'absent')
|
|
163
|
+
return (0, fond_1.vfs_fail)('EEXIST');
|
|
164
|
+
const parent = await (0, move_js_1.parentFolder_prove)(acts, target);
|
|
165
|
+
if (!parent.ok)
|
|
166
|
+
return parent;
|
|
167
|
+
const way = await treeWay_prove(acts, target);
|
|
168
|
+
if (!way.ok)
|
|
169
|
+
return way;
|
|
170
|
+
return folderProved_post(acts, target);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Every folder on the way to a folder a tree is made at, proved on the
|
|
174
|
+
* act's client, from its parent up to the root: each missing one absent,
|
|
175
|
+
* and each one there exactly one folder (the first found, the parent
|
|
176
|
+
* included, does not end the walk: twins further up refuse it too).
|
|
177
|
+
*
|
|
178
|
+
* @param acts - The client the act is bound to.
|
|
179
|
+
* @param target - The folder to be made.
|
|
180
|
+
* @returns Done, or why not (`ENOTDIR` a file or a link on the way, `EPERM`
|
|
181
|
+
* several holders sharing a name on the way, `EIO` a proof not made, or
|
|
182
|
+
* one that finds nothing above a folder it found).
|
|
183
|
+
*/
|
|
184
|
+
async function treeWay_prove(acts, target) {
|
|
185
|
+
let found = false;
|
|
186
|
+
for (let at = path.posix.dirname(target); at !== '/'; at = path.posix.dirname(at)) {
|
|
187
|
+
const above = await (0, proof_js_1.pathHolders_answer)(at, acts);
|
|
188
|
+
if (above.kind === 'error')
|
|
189
|
+
return proofFailure_outcome(above);
|
|
190
|
+
if (above.kind === 'absent') {
|
|
191
|
+
if (found)
|
|
192
|
+
return (0, fond_1.vfs_fail)('EIO', `Cannot check the way to ${target}: nothing holds ${at}, above a folder found there`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (above.kind === 'ambiguous')
|
|
196
|
+
return (0, fond_1.vfs_fail)('EPERM', `${(0, proof_js_1.holders_describe)(above.holders)} share ${at}, and no folder is made under it`);
|
|
197
|
+
if (above.holder.kind !== 'dir')
|
|
198
|
+
return (0, fond_1.vfs_fail)('ENOTDIR', `Not a directory: a ${above.holder.kind} holds ${at}, where a folder is needed`);
|
|
199
|
+
found = true;
|
|
200
|
+
}
|
|
201
|
+
return (0, fond_1.vfs_ok)(true);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Makes a folder and its missing parents (`mkdir -p`), in CUBE's one
|
|
205
|
+
* request: on proof that nothing holds the path, and that every folder on
|
|
206
|
+
* the way is one folder or proved absent ({@link treeWay_prove}). A path
|
|
207
|
+
* already held is said only once the way to it is proved too, since `-p`
|
|
208
|
+
* takes a folder there as done.
|
|
209
|
+
*
|
|
210
|
+
* @param target - The folder's absolute path.
|
|
211
|
+
* @returns Done (`present` when CUBE did not answer and the folder is
|
|
212
|
+
* there, its maker unknown), or why not (`EEXIST` anything there,
|
|
213
|
+
* carrying what holds it, null when CUBE said a folder arrived; `ENOTDIR`
|
|
214
|
+
* a file on the way, `EPERM` twins on the way, `EIO`).
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* const made: VfsOutcome = await path_mkdirTree('/home/ada/new/deeper/still');
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
async function path_mkdirTree(target) {
|
|
222
|
+
const acts = await actClient_bind(target);
|
|
223
|
+
if (acts === null)
|
|
224
|
+
return (0, fond_1.vfs_failFromStack)('EIO');
|
|
225
|
+
const there = await (0, proof_js_1.pathHolders_answer)(target, acts);
|
|
226
|
+
if (there.kind === 'error')
|
|
227
|
+
return proofFailure_outcome(there);
|
|
228
|
+
const way = await treeWay_prove(acts, target);
|
|
229
|
+
if (!way.ok)
|
|
230
|
+
return way;
|
|
231
|
+
if (there.kind !== 'absent')
|
|
232
|
+
return (0, fond_1.vfs_failHeld)((0, proof_js_1.pathProof_convertToHolderProof)(there));
|
|
233
|
+
const made = await folderProved_post(acts, target);
|
|
234
|
+
return !made.ok && made.errno === 'EEXIST' ? (0, fond_1.vfs_failHeld)(null) : made;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Makes a folder at a path, and its missing parents, unless something other
|
|
238
|
+
* than a folder holds it: a folder already there is a success, as CUBE
|
|
239
|
+
* calls it; a file or a link there, several holders, a file above it, a
|
|
240
|
+
* name on the way that several things share, or a path that could not be
|
|
241
|
+
* proved is not, and nothing is made.
|
|
242
|
+
*
|
|
243
|
+
* @param folderPath - The folder's CUBE path.
|
|
244
|
+
* @returns True when a folder is at the path; false otherwise, with the
|
|
245
|
+
* reason on the error stack.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const made: boolean = await files_mkdir('/home/ada/new');
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
async function files_mkdir(folderPath) {
|
|
253
|
+
const target = path.posix.resolve('/', folderPath);
|
|
254
|
+
const acts = await actClient_bind(target);
|
|
255
|
+
if (acts === null)
|
|
256
|
+
return false;
|
|
257
|
+
const there = await (0, proof_js_1.pathHolders_answer)(target, acts);
|
|
258
|
+
if (there.kind === 'error') {
|
|
259
|
+
if (there.notDirectory)
|
|
260
|
+
cumin_1.errorStack.stack_push('error', `Not a directory: a file holds a folder above ${target}`);
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const folder = there.kind === 'held' && there.holder.kind === 'dir';
|
|
264
|
+
if (!folder && there.kind !== 'absent') {
|
|
265
|
+
pathHeld_say(there, target);
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
// A folder already there is one only on a way proved whole, as a folder made would be.
|
|
269
|
+
const way = await treeWay_prove(acts, target);
|
|
270
|
+
if (!way.ok) {
|
|
271
|
+
if (way.reason !== undefined)
|
|
272
|
+
cumin_1.errorStack.stack_push('error', way.reason);
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
if (folder)
|
|
276
|
+
return true;
|
|
277
|
+
const made = await acts.folder_create(target);
|
|
278
|
+
if (made.ok)
|
|
279
|
+
folderPosted_say(target, made.value);
|
|
280
|
+
return made.ok;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Says what already holds a path a folder was asked at: one holder, or
|
|
284
|
+
* several (twins).
|
|
285
|
+
*
|
|
286
|
+
* @param there - The path's proof: held by something, or by several.
|
|
287
|
+
* @param target - The path.
|
|
288
|
+
*/
|
|
289
|
+
function pathHeld_say(there, target) {
|
|
290
|
+
const what = there.kind === 'held' ? `a ${there.holder.kind}` : (0, proof_js_1.holders_describe)(there.holders);
|
|
291
|
+
cumin_1.errorStack.stack_push('error', `File exists: ${what} already ${there.kind === 'held' ? 'holds' : 'hold'} ${target}`);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Content as the Blob an upload takes.
|
|
295
|
+
*
|
|
296
|
+
* @param content - Text, bytes, or a Blob already.
|
|
297
|
+
* @returns The same content as a Blob.
|
|
298
|
+
*/
|
|
299
|
+
function content_convertToBlob(content) {
|
|
300
|
+
if (typeof content === 'string')
|
|
301
|
+
return new Blob([content]);
|
|
302
|
+
if (Buffer.isBuffer(content))
|
|
303
|
+
return new Blob([new Uint8Array(content)]);
|
|
304
|
+
return content;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Stores content at a path nothing holds, create-only: a file already
|
|
308
|
+
* there, a folder, several holders, or a path that could not be proved
|
|
309
|
+
* free, and nothing is written.
|
|
310
|
+
*
|
|
311
|
+
* @param content - The content (text, bytes, or a Blob).
|
|
312
|
+
* @param pathStr - The file's CUBE path.
|
|
313
|
+
* @returns True when the path holds the content; false otherwise, with the
|
|
314
|
+
* reason on the error stack.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* const created: boolean = await files_create('hello', '/home/ada/hello.txt');
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
async function files_create(content, pathStr) {
|
|
322
|
+
const target = path.posix.resolve('/', pathStr);
|
|
323
|
+
const acts = await actClient_bind(target);
|
|
324
|
+
if (acts === null)
|
|
325
|
+
return false;
|
|
326
|
+
return (await (0, replace_js_1.file_store)(acts, target, content_convertToBlob(content), 'refuse')).ok;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Makes a file (`touch`): a file already at the path is left as it is,
|
|
330
|
+
* and a missing one is made empty. With content, the file is written whole
|
|
331
|
+
* ({@link file_write}): made, or its content replaced. A folder, a link or
|
|
332
|
+
* several holders at the path, or a path that could not be proved, and
|
|
333
|
+
* nothing is written. A projection's file (a feed's note under /proc) is
|
|
334
|
+
* written through the projection that owns it, and takes text.
|
|
335
|
+
*
|
|
336
|
+
* @param written - The CUBE path; one written without its leading slash is
|
|
337
|
+
* read from the root.
|
|
338
|
+
* @param content - The content to write, when there is any.
|
|
339
|
+
* @returns True when done; false otherwise, with the reason on the error stack.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* const touched: boolean = await files_touch('/home/ada/notes.txt');
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
async function files_touch(written, content) {
|
|
347
|
+
// One name, from the root, for every question asked of the path: whether
|
|
348
|
+
// a projection owns it, what holds it, and where the bytes go.
|
|
349
|
+
const target = path.posix.resolve('/', written);
|
|
350
|
+
const { vfsDispatcher } = await import('../vfs/dispatcher.js');
|
|
351
|
+
if (vfsDispatcher.path_isVirtual(target)) {
|
|
352
|
+
if (typeof content !== 'string') {
|
|
353
|
+
cumin_1.errorStack.stack_push('error', `touch: ${target}: a projected file takes text (--withContents)`);
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
return (0, fond_1.vfsOutcome_convertToResult)(await vfsDispatcher.write(target, content), 'write', target).ok;
|
|
357
|
+
}
|
|
358
|
+
if (content !== undefined)
|
|
359
|
+
return (0, replace_js_1.file_write)(target, content_convertToBlob(content));
|
|
360
|
+
const acts = await actClient_bind(target);
|
|
361
|
+
if (acts === null)
|
|
362
|
+
return false;
|
|
363
|
+
return (await (0, replace_js_1.file_store)(acts, target, new Blob(['']), 'keep')).ok;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* A write's failure, its reason the newest error it left (taken off the
|
|
367
|
+
* stack), every other message it left kept there.
|
|
368
|
+
*
|
|
369
|
+
* @param mark - The stack's mark from before the write.
|
|
370
|
+
* @param errno - Why, as an errno.
|
|
371
|
+
* @returns The outcome.
|
|
372
|
+
*/
|
|
373
|
+
function writeFailure_take(mark, errno) {
|
|
374
|
+
const left = cumin_1.errorStack.checkpoint_drain(mark);
|
|
375
|
+
const newest = left.map((message) => message.type).lastIndexOf('error');
|
|
376
|
+
cumin_1.errorStack.stack_restore(left.filter((_message, index) => index !== newest));
|
|
377
|
+
const reason = newest < 0 ? undefined : left[newest];
|
|
378
|
+
return reason === undefined ? (0, fond_1.vfs_fail)(errno) : (0, fond_1.vfs_fail)(errno, reason.message.replace(/^\[[^\]]*\]\s*\|\s*/, ''));
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Whether a file's parent is a folder, proved; made when asked and nothing
|
|
382
|
+
* holds it, every folder on the way proved first ({@link treeWay_prove}).
|
|
383
|
+
*
|
|
384
|
+
* @param acts - The client the write is bound to.
|
|
385
|
+
* @param target - The file's path.
|
|
386
|
+
* @param parent - `require` a folder there, or `make` one.
|
|
387
|
+
* @returns The folder made (null when it was there); or why not.
|
|
388
|
+
*/
|
|
389
|
+
async function placeParent_settle(acts, target, parent) {
|
|
390
|
+
const folder = path.posix.dirname(target);
|
|
391
|
+
const above = await (0, proof_js_1.pathHolders_answer)(folder, acts);
|
|
392
|
+
if (above.kind === 'error')
|
|
393
|
+
return proofFailure_outcome(above);
|
|
394
|
+
if (above.kind === 'ambiguous')
|
|
395
|
+
return (0, fond_1.vfs_fail)('EPERM', `${(0, proof_js_1.holders_describe)(above.holders)} share ${folder}, and nothing is written into it`);
|
|
396
|
+
if (above.kind === 'held' && above.holder.kind !== 'dir')
|
|
397
|
+
return (0, fond_1.vfs_fail)('ENOTDIR');
|
|
398
|
+
if (above.kind === 'absent' && parent === 'require')
|
|
399
|
+
return (0, fond_1.vfs_fail)('ENOENT');
|
|
400
|
+
// A parent already there is written into only on a way proved whole, as one made would be.
|
|
401
|
+
const way = await treeWay_prove(acts, folder);
|
|
402
|
+
if (!way.ok)
|
|
403
|
+
return way;
|
|
404
|
+
if (above.kind === 'held')
|
|
405
|
+
return (0, fond_1.vfs_ok)(null);
|
|
406
|
+
const made = (0, fond_1.vfsOutcome_convertFromResult)(await acts.folder_create(folder), 'EIO');
|
|
407
|
+
if (!made.ok)
|
|
408
|
+
return made;
|
|
409
|
+
folderPosted_say(folder, made.value);
|
|
410
|
+
return (0, fond_1.vfs_ok)(made.value === 'made' ? folder : null);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Stores content at a path, its parent proved a folder first (or made, when
|
|
414
|
+
* asked and nothing holds it), and a file already at the path replaced,
|
|
415
|
+
* kept or refused, as asked. Every proof and act goes to one client, the
|
|
416
|
+
* session's when the write began.
|
|
417
|
+
*
|
|
418
|
+
* @param written - The CUBE path; one written without its leading slash is read from the root.
|
|
419
|
+
* @param content - The content.
|
|
420
|
+
* @param options - What becomes of a file there, and of a missing parent.
|
|
421
|
+
* @returns What was done and the folder made, or why not (`ENOENT` no
|
|
422
|
+
* parent, `ENOTDIR`, `EEXIST` a file refused, `EISDIR`, `EPERM`, `EIO`),
|
|
423
|
+
* the write's own reason when it gave one.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* const placed: VfsOutcome<PlaceReceipt> = await file_place('/home/ada/out/q.csv', new Blob([csv]), { existing: 'refuse', parent: 'make' });
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
async function file_place(written, content, options) {
|
|
431
|
+
const target = path.posix.resolve('/', written);
|
|
432
|
+
const acts = await actClient_bind(target);
|
|
433
|
+
if (acts === null)
|
|
434
|
+
return (0, fond_1.vfs_failFromStack)('EIO');
|
|
435
|
+
const parent = await placeParent_settle(acts, target, options.parent);
|
|
436
|
+
if (!parent.ok)
|
|
437
|
+
return parent;
|
|
438
|
+
const mark = cumin_1.errorStack.checkpoint_mark();
|
|
439
|
+
const stored = await (0, replace_js_1.file_store)(acts, target, content_convertToBlob(content), options.existing);
|
|
440
|
+
if (!stored.ok)
|
|
441
|
+
return writeFailure_take(mark, stored.errno);
|
|
442
|
+
return (0, fond_1.vfs_ok)({ done: stored.value, created: parent.value });
|
|
443
|
+
}
|
|
444
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/files/create.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GH,gCAWC;AAgDD,wCAUC;AAkBD,kCAwBC;AAyCD,oCAKC;AAoBD,kCAgBC;AA8DD,gCAUC;AAlXD,2CAA6B;AAE7B,yCAA0H;AAC1H,uCAA0L;AAE1L,uCAA+C;AAC/C,yCAA2K;AAC3K,6CAAuF;AAiCvF;;;;;GAKG;AACH,KAAK,UAAU,cAAc,CAAC,MAAc;IAC1C,MAAM,KAAK,GAAyB,MAAM,eAAO,CAAC,iBAAiB,EAAE,CAAC;IACtE,IAAI,KAAK,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC;IACjC,kBAAU,CAAC,UAAU,CAAC,OAAO,EAAE,kBAAkB,MAAM,qDAAqD,CAAC,CAAC;IAC9G,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAoB;IAChD,OAAO,IAAA,wBAAiB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,MAAc,EAAE,MAAoB;IAC5D,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO;IACjC,kBAAU,CAAC,UAAU,CAAC,SAAS,E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AM,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Downloading ChRIS files to this machine: planning where each lands, and writing it there.
|
|
3
|
+
*
|
|
4
|
+
* Every local place comes from fond: the destination the operator named is placed as theirs
|
|
5
|
+
* (`operatorFolder_place` / `operatorFile_place`), and every name that came from CUBE (a source's own name, a row
|
|
6
|
+
* inside a folder downloaded, a parent's name for two sources that share one) is placed under it with
|
|
7
|
+
* `placed_child`. Rows are held to the folder they were listed in (./listing) before anything is walked or
|
|
8
|
+
* fetched. Bytes are written only by fond's writer, owner-only (0600). A name that cannot be placed is refused,
|
|
9
|
+
* counted failed with its reason, and the rest of the batch goes on.
|
|
10
|
+
*
|
|
11
|
+
* The behaviour is chili's (which now calls this): an existing local file is not replaced without `force` or the
|
|
12
|
+
* operator's yes; a folder source keeps its own name below the destination unless it ends with `/` (its contents
|
|
13
|
+
* merge into the destination); several sources go into one folder, two that share a name each under their
|
|
14
|
+
* parent's name; a file that fails is tried once more and the rest continue.
|
|
15
|
+
*
|
|
16
|
+
* Key components:
|
|
17
|
+
* - download_one: one source to a destination (a file, or a folder kept or merged).
|
|
18
|
+
* - download_many: several sources into one folder.
|
|
19
|
+
* - DownloadOptions, DownloadSummary, DownloadProgressEvent: the contract callers render.
|
|
20
|
+
*
|
|
21
|
+
* Typical usage:
|
|
22
|
+
* ```ts
|
|
23
|
+
* const summary: DownloadSummary = await download_one('/home/me/study', './study', { confirm, onNotice });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Dependencies: fond (places, writer), cumin (transfer pool), ./listing, ./index (streams), ./fileLookup.
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/
|
|
30
|
+
import { type ListedRow } from './listing.js';
|
|
31
|
+
/**
|
|
32
|
+
* Download summary statistics.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* if (summary.failedCount > 0) exitCode_set(1);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface DownloadSummary {
|
|
40
|
+
/** When it started (ms since the epoch). */
|
|
41
|
+
startTime: number;
|
|
42
|
+
/** When it ended. */
|
|
43
|
+
endTime: number;
|
|
44
|
+
/** Files it set out to download (refused ones included). */
|
|
45
|
+
totalFiles: number;
|
|
46
|
+
/** Files written. */
|
|
47
|
+
transferredCount: number;
|
|
48
|
+
/** Files that failed or were refused a place. */
|
|
49
|
+
failedCount: number;
|
|
50
|
+
/** Bytes written. */
|
|
51
|
+
transferSize: number;
|
|
52
|
+
/** Seconds it took. */
|
|
53
|
+
duration: number;
|
|
54
|
+
/** Bytes per second. */
|
|
55
|
+
speed: number;
|
|
56
|
+
/** The ChRIS paths that failed (after their retry, or refused a place), in the order they ended. */
|
|
57
|
+
failedPaths: string[];
|
|
58
|
+
/** Files a cancel left undownloaded. */
|
|
59
|
+
cancelledCount: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Download progress fact emitted to callers that want to render progress.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* onProgress: (event: DownloadProgressEvent) => sink.progress_write(event)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export interface DownloadProgressEvent {
|
|
70
|
+
/** Always a download. */
|
|
71
|
+
operation: 'download';
|
|
72
|
+
/** Always a transfer. */
|
|
73
|
+
kind: 'transfer';
|
|
74
|
+
/** Where it is. */
|
|
75
|
+
phase: 'scanning' | 'transferring' | 'complete' | 'failed';
|
|
76
|
+
/** What to show. */
|
|
77
|
+
label?: string;
|
|
78
|
+
/** How far: files or bytes. */
|
|
79
|
+
current?: number;
|
|
80
|
+
/** Of how many. */
|
|
81
|
+
total?: number;
|
|
82
|
+
/** As a percentage. */
|
|
83
|
+
percent?: number;
|
|
84
|
+
/** What `current` counts. */
|
|
85
|
+
unit?: 'files' | 'bytes';
|
|
86
|
+
/** Running, done, or failed. */
|
|
87
|
+
status?: 'running' | 'done' | 'error';
|
|
88
|
+
}
|
|
89
|
+
/** Asks the operator's yes; throws to decline. */
|
|
90
|
+
export type DownloadConfirm = (message: string) => Promise<void>;
|
|
91
|
+
/** Shows a live notice on a channel. */
|
|
92
|
+
export type DownloadNotice = (message: string, channel: 'status' | 'err') => void;
|
|
93
|
+
/** Shows a progress fact. */
|
|
94
|
+
export type DownloadProgress = (event: DownloadProgressEvent) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Options for a download.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const options: DownloadOptions = { force: false, confirm, onNotice, jobs: 8, signal };
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export interface DownloadOptions {
|
|
104
|
+
/** Replace what stands without asking. */
|
|
105
|
+
force?: boolean;
|
|
106
|
+
/** Confirms replacement or merge at the local destination; throws to decline. Absent: a needed yes refuses. */
|
|
107
|
+
confirm?: DownloadConfirm;
|
|
108
|
+
/** Reports a live notice on the caller's chosen channel. Absent: notices go to the error stack. */
|
|
109
|
+
onNotice?: DownloadNotice;
|
|
110
|
+
/** Reports progress facts. */
|
|
111
|
+
onProgress?: DownloadProgress;
|
|
112
|
+
/** How many files move at once; the transfer pool's default when absent. */
|
|
113
|
+
jobs?: number;
|
|
114
|
+
/** The line's abort signal: a cancel starts no more files and stops those in flight. */
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A CUBE path refused a place here, and why.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const refused: RefusedRemote = { remote: '/home/me/x/../y', reason: 'not a name directly inside' };
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export interface RefusedRemote {
|
|
126
|
+
/** The store path. */
|
|
127
|
+
remote: string;
|
|
128
|
+
/** Why. */
|
|
129
|
+
reason: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Downloads one ChRIS file or folder to the local destination.
|
|
133
|
+
*
|
|
134
|
+
* @param remote - The resolved ChRIS path (a trailing `/` on a folder merges its contents into the destination).
|
|
135
|
+
* @param destination - The local destination as the operator typed it.
|
|
136
|
+
* @param options - Download options.
|
|
137
|
+
* @returns The summary.
|
|
138
|
+
* @throws {Error} When the destination cannot be used, the operator declines, or a single file fails.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* await download_one('/home/me/study', './study', { confirm, onNotice });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function download_one(remote: string, destination: string, options?: DownloadOptions): Promise<DownloadSummary>;
|
|
146
|
+
/**
|
|
147
|
+
* Downloads several exact ChRIS paths into one local folder: a folder keeps its own name below it, a file goes
|
|
148
|
+
* in by its own name, and two that share a name each go under their parent's name (said).
|
|
149
|
+
*
|
|
150
|
+
* @param sources - The resolved ChRIS paths.
|
|
151
|
+
* @param destination - The local folder.
|
|
152
|
+
* @param options - Download options.
|
|
153
|
+
* @returns The summary.
|
|
154
|
+
* @throws {Error} When no sources are given, the destination is not a folder, or the operator declines.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* await download_many(['/home/me/a.nii', '/home/me/b.nii'], './out', { confirm, onNotice });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function download_many(sources: readonly string[], destination: string, options?: DownloadOptions): Promise<DownloadSummary>;
|
|
162
|
+
/**
|
|
163
|
+
* The rows of a folder a surface on another machine is handed (it places them itself): each with its name inside
|
|
164
|
+
* the folder, held to the listing rule; refusals returned.
|
|
165
|
+
*
|
|
166
|
+
* @param remote - The folder.
|
|
167
|
+
* @returns The rows and the refusals.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const { rows, refused } = await deliveryRows_list('/home/me/study');
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function deliveryRows_list(remote: string): Promise<DeliveryRows>;
|
|
175
|
+
/**
|
|
176
|
+
* The files of a folder handed to a surface, and the rows refused.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const listed: DeliveryRows = await deliveryRows_list('/home/me/study');
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export interface DeliveryRows {
|
|
184
|
+
/** The files, each with its name inside the folder. */
|
|
185
|
+
rows: ListedRow[];
|
|
186
|
+
/** The rows refused. */
|
|
187
|
+
refused: RefusedRemote[];
|
|
188
|
+
}
|