@fnndsc/cumin 3.30.5 → 3.31.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/dist/cache/checkpointWatch.d.ts +36 -0
- package/dist/cache/checkpointWatch.js +83 -0
- package/dist/cache/checkpointWatch.js.map +1 -0
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.js +4 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/listCache.d.ts +54 -2
- package/dist/cache/listCache.js +120 -24
- package/dist/cache/listCache.js.map +1 -1
- package/dist/cache/listCheckpoint.d.ts +5 -8
- package/dist/cache/listCheckpoint.js +17 -28
- package/dist/cache/listCheckpoint.js.map +1 -1
- package/dist/cache/listingInvalidation.js +11 -6
- package/dist/cache/listingInvalidation.js.map +1 -1
- package/dist/cache/procCache.d.ts +11 -0
- package/dist/cache/procCache.js +26 -1
- package/dist/cache/procCache.js.map +1 -1
- package/dist/cache/procCheckpoint.d.ts +11 -6
- package/dist/cache/procCheckpoint.js +280 -86
- package/dist/cache/procCheckpoint.js.map +1 -1
- package/dist/cache/queryIndex.d.ts +11 -0
- package/dist/cache/queryIndex.js +38 -2
- package/dist/cache/queryIndex.js.map +1 -1
- package/dist/cache/queryIndexCheckpoint.d.ts +32 -0
- package/dist/cache/queryIndexCheckpoint.js +180 -30
- package/dist/cache/queryIndexCheckpoint.js.map +1 -1
- package/dist/chrisapi/adapter.d.ts +266 -37
- package/dist/chrisapi/adapter.js +577 -116
- package/dist/chrisapi/adapter.js.map +1 -1
- package/dist/chrisapi/contract.d.ts +20 -20
- package/dist/chrisapi/contract.js +213 -60
- package/dist/chrisapi/contract.js.map +1 -1
- package/dist/chrisapi/cubeRequest.d.ts +198 -0
- package/dist/chrisapi/cubeRequest.js +345 -0
- package/dist/chrisapi/cubeRequest.js.map +1 -0
- package/dist/chrisapi/shape.d.ts +186 -0
- package/dist/chrisapi/shape.js +274 -0
- package/dist/chrisapi/shape.js.map +1 -0
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/compute/computeResources.d.ts +3 -0
- package/dist/compute/computeResources.js +5 -3
- package/dist/compute/computeResources.js.map +1 -1
- package/dist/config/config.d.ts +14 -0
- package/dist/config/config.js +6 -3
- package/dist/config/config.js.map +1 -1
- package/dist/connect/chrisConnection.d.ts +116 -6
- package/dist/connect/chrisConnection.js +418 -74
- package/dist/connect/chrisConnection.js.map +1 -1
- package/dist/connect/identityEpoch.d.ts +263 -0
- package/dist/connect/identityEpoch.js +414 -0
- package/dist/connect/identityEpoch.js.map +1 -0
- package/dist/connect/loginFailure.js +39 -22
- package/dist/connect/loginFailure.js.map +1 -1
- package/dist/context/chrisContext.js +36 -30
- package/dist/context/chrisContext.js.map +1 -1
- package/dist/error/errorStack.d.ts +1 -1
- package/dist/error/errorStack.js +1 -2
- package/dist/error/errorStack.js.map +1 -1
- package/dist/feeds/chrisAccess.d.ts +7 -2
- package/dist/feeds/chrisAccess.js +20 -7
- package/dist/feeds/chrisAccess.js.map +1 -1
- package/dist/feeds/chrisFeed.d.ts +8 -10
- package/dist/feeds/chrisFeed.js +27 -57
- package/dist/feeds/chrisFeed.js.map +1 -1
- package/dist/feeds/chrisTags.d.ts +1 -1
- package/dist/feeds/chrisTags.js +66 -24
- package/dist/feeds/chrisTags.js.map +1 -1
- package/dist/filebrowser/chrisFileBrowser.d.ts +0 -1
- package/dist/filebrowser/chrisFileBrowser.js +3 -5
- package/dist/filebrowser/chrisFileBrowser.js.map +1 -1
- package/dist/filebrowser/chrisFiles.d.ts +0 -1
- package/dist/filebrowser/chrisFiles.js +3 -4
- package/dist/filebrowser/chrisFiles.js.map +1 -1
- package/dist/filebrowser/chrisPACS.d.ts +4 -4
- package/dist/filebrowser/chrisPACS.js +10 -33
- package/dist/filebrowser/chrisPACS.js.map +1 -1
- package/dist/filebrowser/chrisPipeline.js +10 -45
- package/dist/filebrowser/chrisPipeline.js.map +1 -1
- package/dist/groups/chrisGroups.d.ts +3 -0
- package/dist/groups/chrisGroups.js +20 -8
- package/dist/groups/chrisGroups.js.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.js +18 -28
- package/dist/index.js.map +1 -1
- package/dist/io/chrisIO.d.ts +81 -42
- package/dist/io/chrisIO.js +176 -325
- package/dist/io/chrisIO.js.map +1 -1
- package/dist/io/holderClient.d.ts +248 -0
- package/dist/io/holderClient.js +289 -0
- package/dist/io/holderClient.js.map +1 -0
- package/dist/io/holderFolder.d.ts +151 -0
- package/dist/io/holderFolder.js +311 -0
- package/dist/io/holderFolder.js.map +1 -0
- package/dist/io/holderIO.d.ts +258 -0
- package/dist/io/holderIO.js +557 -0
- package/dist/io/holderIO.js.map +1 -0
- package/dist/io/holderRequest.d.ts +299 -0
- package/dist/io/holderRequest.js +447 -0
- package/dist/io/holderRequest.js.map +1 -0
- package/dist/io/holderUpload.d.ts +62 -0
- package/dist/io/holderUpload.js +81 -0
- package/dist/io/holderUpload.js.map +1 -0
- package/dist/io/io.d.ts +12 -0
- package/dist/io/io.js.map +1 -1
- package/dist/io/localUpload.d.ts +59 -0
- package/dist/io/localUpload.js +150 -0
- package/dist/io/localUpload.js.map +1 -0
- package/dist/io/node_io.d.ts +16 -0
- package/dist/io/node_io.js +72 -0
- package/dist/io/node_io.js.map +1 -1
- package/dist/io/streamWatch.js +2 -2
- package/dist/io/streamWatch.js.map +1 -1
- package/dist/io/transferPool.d.ts +150 -0
- package/dist/io/transferPool.js +196 -0
- package/dist/io/transferPool.js.map +1 -0
- package/dist/pacs/chrisPACS.d.ts +3 -9
- package/dist/pacs/chrisPACS.js +102 -61
- package/dist/pacs/chrisPACS.js.map +1 -1
- package/dist/pacs/queryIndexSweep.d.ts +0 -9
- package/dist/pacs/queryIndexSweep.js +45 -41
- package/dist/pacs/queryIndexSweep.js.map +1 -1
- package/dist/path/chrisPath.d.ts +8 -3
- package/dist/path/chrisPath.js +10 -9
- package/dist/path/chrisPath.js.map +1 -1
- package/dist/pipelines/chrisPipeline.d.ts +28 -5
- package/dist/pipelines/chrisPipeline.js +270 -94
- package/dist/pipelines/chrisPipeline.js.map +1 -1
- package/dist/pipelines/pipelineMemo.d.ts +0 -16
- package/dist/pipelines/pipelineMemo.js +0 -27
- package/dist/pipelines/pipelineMemo.js.map +1 -1
- package/dist/plugins/chrisPlugins.d.ts +9 -5
- package/dist/plugins/chrisPlugins.js +97 -58
- package/dist/plugins/chrisPlugins.js.map +1 -1
- package/dist/resources/chrisObjContext.d.ts +7 -11
- package/dist/resources/chrisObjContext.js +7 -42
- package/dist/resources/chrisObjContext.js.map +1 -1
- package/dist/resources/chrisResources.d.ts +186 -74
- package/dist/resources/chrisResources.js +421 -117
- package/dist/resources/chrisResources.js.map +1 -1
- package/dist/resources/resourceShapes.d.ts +109 -0
- package/dist/resources/resourceShapes.js +22 -0
- package/dist/resources/resourceShapes.js.map +1 -0
- package/dist/users/chrisUsers.d.ts +4 -1
- package/dist/users/chrisUsers.js +6 -2
- package/dist/users/chrisUsers.js.map +1 -1
- package/dist/utils/keypair.js +21 -10
- package/dist/utils/keypair.js.map +1 -1
- package/package.json +15 -3
- package/dist/activities/chrisActivity.d.ts +0 -19
- package/dist/activities/chrisActivity.js +0 -29
- package/dist/activities/chrisActivity.js.map +0 -1
- package/dist/jobs/chrisJob.d.ts +0 -43
- package/dist/jobs/chrisJob.js +0 -174
- package/dist/jobs/chrisJob.js.map +0 -1
- package/dist/jobs/index.d.ts +0 -7
- package/dist/jobs/index.js +0 -24
- package/dist/jobs/index.js.map +0 -1
- package/dist/jobs/jobMonitor.d.ts +0 -46
- package/dist/jobs/jobMonitor.js +0 -102
- package/dist/jobs/jobMonitor.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A local file or folder walked for an upload, each file handed to the caller's store.
|
|
3
|
+
*
|
|
4
|
+
* The walk posts nothing itself: every file's content goes to the store the
|
|
5
|
+
* caller gives, at the ChRIS path it lands at. A folder lands under the
|
|
6
|
+
* destination by its own name, as `cp -r` puts it, and every file and
|
|
7
|
+
* folder below it under its own name once: `study/series/scan.txt`
|
|
8
|
+
* uploaded to `/dest` lands at `/dest/study/series/scan.txt`. Nothing is
|
|
9
|
+
* placed anywhere but below the destination: a name that is empty, `.`,
|
|
10
|
+
* `..` or holds a slash refuses what it names, so a folder is handed here
|
|
11
|
+
* by its path resolved (salsa's `files_uploadPath` resolves it).
|
|
12
|
+
*
|
|
13
|
+
* Key components:
|
|
14
|
+
* - LocalFileStore: stores one local file's content at its ChRIS path.
|
|
15
|
+
* - localPath_upload: walk a local file or folder, handing each file to the store.
|
|
16
|
+
*
|
|
17
|
+
* Typical usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const stored: boolean = await localPath_upload(provider, '/tmp/study', '/home/ada', store);
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Dependencies: a local `IStorageProvider` and cumin's error stack, where a
|
|
23
|
+
* failure's reason is left.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import type { IStorageProvider } from "./io.js";
|
|
28
|
+
/**
|
|
29
|
+
* Stores one local file's content at its ChRIS path, for {@link localPath_upload}.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const store: LocalFileStore = async (content: Blob, target: string): Promise<boolean> => plan_store(target, content);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type LocalFileStore = (content: Blob, target: string) => Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Walks a local file or folder for an upload, each file handed to the
|
|
39
|
+
* caller's store (never posted here). A folder lands under the destination
|
|
40
|
+
* by its own name (`cp -r`), a file at the destination path itself. A
|
|
41
|
+
* folder with no name of its own below the destination (the root, or one
|
|
42
|
+
* written `old/..` or `..`, not resolved) is refused and said: it is never
|
|
43
|
+
* placed beside or above the destination.
|
|
44
|
+
*
|
|
45
|
+
* @param provider - The local storage.
|
|
46
|
+
* @param localPath - The local file or folder, read as written.
|
|
47
|
+
* @param remotePath - The ChRIS destination.
|
|
48
|
+
* @param store - Stores one file's content at its ChRIS path; false (its reason stacked) when it did not.
|
|
49
|
+
* @param folderName - The name a folder lands under, when the caller found
|
|
50
|
+
* it (its real path's last name); null when its contents land in the
|
|
51
|
+
* destination itself; left out, the last name of `localPath`.
|
|
52
|
+
* @returns True when every file was stored; false otherwise, with the reasons on the error stack.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const stored: boolean = await localPath_upload(provider, '/tmp/study', '/home/ada', store);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function localPath_upload(provider: IStorageProvider, localPath: string, remotePath: string, store: LocalFileStore, folderName?: string | null): Promise<boolean>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file A local file or folder walked for an upload, each file handed to the caller's store.
|
|
4
|
+
*
|
|
5
|
+
* The walk posts nothing itself: every file's content goes to the store the
|
|
6
|
+
* caller gives, at the ChRIS path it lands at. A folder lands under the
|
|
7
|
+
* destination by its own name, as `cp -r` puts it, and every file and
|
|
8
|
+
* folder below it under its own name once: `study/series/scan.txt`
|
|
9
|
+
* uploaded to `/dest` lands at `/dest/study/series/scan.txt`. Nothing is
|
|
10
|
+
* placed anywhere but below the destination: a name that is empty, `.`,
|
|
11
|
+
* `..` or holds a slash refuses what it names, so a folder is handed here
|
|
12
|
+
* by its path resolved (salsa's `files_uploadPath` resolves it).
|
|
13
|
+
*
|
|
14
|
+
* Key components:
|
|
15
|
+
* - LocalFileStore: stores one local file's content at its ChRIS path.
|
|
16
|
+
* - localPath_upload: walk a local file or folder, handing each file to the store.
|
|
17
|
+
*
|
|
18
|
+
* Typical usage:
|
|
19
|
+
* ```ts
|
|
20
|
+
* const stored: boolean = await localPath_upload(provider, '/tmp/study', '/home/ada', store);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Dependencies: a local `IStorageProvider` and cumin's error stack, where a
|
|
24
|
+
* failure's reason is left.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.localPath_upload = localPath_upload;
|
|
30
|
+
const errorStack_js_1 = require("../error/errorStack.js");
|
|
31
|
+
/**
|
|
32
|
+
* A path one name further down, the folder's spelling kept as written (a
|
|
33
|
+
* local `link/..` is not folded, so a child is read where its folder was
|
|
34
|
+
* listed): a ChRIS path, or a local one.
|
|
35
|
+
*
|
|
36
|
+
* @param folder - The folder, as written.
|
|
37
|
+
* @param name - The name in it, one entry (no slash, not `.` or `..`).
|
|
38
|
+
* @returns The joined path, one slash between.
|
|
39
|
+
*/
|
|
40
|
+
function path_joinOne(folder, name) {
|
|
41
|
+
return folder.endsWith('/') ? folder + name : `${folder}/${name}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Whether a name is one entry below a folder: not empty, not `.` or `..`,
|
|
45
|
+
* and with no slash in it.
|
|
46
|
+
*
|
|
47
|
+
* @param name - The name.
|
|
48
|
+
* @returns True when it lands below the folder it is joined to.
|
|
49
|
+
*/
|
|
50
|
+
function name_isBelow(name) {
|
|
51
|
+
return name.length > 0 && name !== "." && name !== ".." && !name.includes("/");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Says a local entry whose name would land outside the destination.
|
|
55
|
+
*
|
|
56
|
+
* @param localPath - The local file or folder.
|
|
57
|
+
* @param folder - The ChRIS folder it would land in.
|
|
58
|
+
* @returns False, the walk's answer for it.
|
|
59
|
+
*/
|
|
60
|
+
function placeOutside_say(localPath, folder) {
|
|
61
|
+
errorStack_js_1.errorStack.stack_push("error", `Not uploaded: ${localPath} has no name that lands below ${folder}`);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Says why a walk could not go on at a local path.
|
|
66
|
+
*
|
|
67
|
+
* @param localPath - The local file or folder.
|
|
68
|
+
* @param error - What was thrown.
|
|
69
|
+
* @returns False, the walk's answer for it.
|
|
70
|
+
*/
|
|
71
|
+
function walkFailure_say(localPath, error) {
|
|
72
|
+
errorStack_js_1.errorStack.stack_push("error", `Recursive upload failed for ${localPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Hands a local file or folder to the store, landing at exactly the ChRIS
|
|
77
|
+
* path given: a file there, a folder's entries each under it by its own name.
|
|
78
|
+
*
|
|
79
|
+
* @param provider - The local storage.
|
|
80
|
+
* @param localPath - The local file or folder.
|
|
81
|
+
* @param target - The ChRIS path it lands at.
|
|
82
|
+
* @param store - Stores one file's content at its ChRIS path.
|
|
83
|
+
* @param folder - Whether it is a folder, when that is known already.
|
|
84
|
+
* @returns True when every file was stored; false otherwise (stacked): one
|
|
85
|
+
* that failed does not stop its siblings.
|
|
86
|
+
*/
|
|
87
|
+
async function localTree_store(provider, localPath, target, store, folder) {
|
|
88
|
+
try {
|
|
89
|
+
if (!(folder ?? await provider.isDirectory(localPath))) {
|
|
90
|
+
const content = await provider.readBinary(localPath);
|
|
91
|
+
if (!content) {
|
|
92
|
+
errorStack_js_1.errorStack.stack_push("error", `Failed to read local file: ${localPath}`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return await store(new Blob([content]), target);
|
|
96
|
+
}
|
|
97
|
+
let stored = true;
|
|
98
|
+
for (const entry of await provider.readdir(localPath)) {
|
|
99
|
+
const child = path_joinOne(localPath, entry);
|
|
100
|
+
if (!name_isBelow(entry))
|
|
101
|
+
stored = placeOutside_say(child, target);
|
|
102
|
+
else if (!await localTree_store(provider, child, path_joinOne(target, entry), store))
|
|
103
|
+
stored = false;
|
|
104
|
+
}
|
|
105
|
+
return stored;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return walkFailure_say(localPath, error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Walks a local file or folder for an upload, each file handed to the
|
|
113
|
+
* caller's store (never posted here). A folder lands under the destination
|
|
114
|
+
* by its own name (`cp -r`), a file at the destination path itself. A
|
|
115
|
+
* folder with no name of its own below the destination (the root, or one
|
|
116
|
+
* written `old/..` or `..`, not resolved) is refused and said: it is never
|
|
117
|
+
* placed beside or above the destination.
|
|
118
|
+
*
|
|
119
|
+
* @param provider - The local storage.
|
|
120
|
+
* @param localPath - The local file or folder, read as written.
|
|
121
|
+
* @param remotePath - The ChRIS destination.
|
|
122
|
+
* @param store - Stores one file's content at its ChRIS path; false (its reason stacked) when it did not.
|
|
123
|
+
* @param folderName - The name a folder lands under, when the caller found
|
|
124
|
+
* it (its real path's last name); null when its contents land in the
|
|
125
|
+
* destination itself; left out, the last name of `localPath`.
|
|
126
|
+
* @returns True when every file was stored; false otherwise, with the reasons on the error stack.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const stored: boolean = await localPath_upload(provider, '/tmp/study', '/home/ada', store);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
async function localPath_upload(provider, localPath, remotePath, store, folderName) {
|
|
134
|
+
let folder;
|
|
135
|
+
try {
|
|
136
|
+
folder = await provider.isDirectory(localPath);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return walkFailure_say(localPath, error);
|
|
140
|
+
}
|
|
141
|
+
if (!folder)
|
|
142
|
+
return localTree_store(provider, localPath, remotePath, store, false);
|
|
143
|
+
if (folderName === null)
|
|
144
|
+
return localTree_store(provider, localPath, remotePath, store, true);
|
|
145
|
+
const name = folderName ?? provider.basename(localPath);
|
|
146
|
+
if (!name_isBelow(name))
|
|
147
|
+
return placeOutside_say(localPath, remotePath);
|
|
148
|
+
return localTree_store(provider, localPath, path_joinOne(remotePath, name), store, true);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=localUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localUpload.js","sourceRoot":"","sources":["../../src/io/localUpload.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAuHH,4CAYC;AAhID,0DAAoD;AAYpD;;;;;;;;GAQG;AACH,SAAS,YAAY,CAAC,MAAc,EAAE,IAAY;IAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;AACpE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACjF,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,SAAiB,EAAE,MAAc;IACzD,0BAAU,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB,SAAS,iCAAiC,MAAM,EAAE,CAAC,CAAC;IACpG,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,SAAiB,EAAE,KAAc;IACxD,0BAAU,CAAC,UAAU,CAAC,OAAO,EAAE,+BAA+B,SAAS,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACtI,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,eAAe,CAAC,QAA0B,EAAE,SAAiB,EAAE,MAAc,EAAE,KAAqB,EAAE,MAAgB;IACnI,IAAI,CAAC;QACH,IAAI,CAAC,CAAC,MAAM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C;IACjD,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,OAAO,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,OAAO,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACnF,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9F,MAAM,IAAI,GAAW,UAAU,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACxE,OAAO,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAC3F,CAAC"}
|
package/dist/io/node_io.d.ts
CHANGED
|
@@ -18,6 +18,22 @@ export declare class NodeStorageProvider implements IStorageProvider {
|
|
|
18
18
|
read(filepath: string): Promise<string | null>;
|
|
19
19
|
readBinary(filepath: string): Promise<ArrayBuffer | null>;
|
|
20
20
|
write(filepath: string, data: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Writes a credential: the file at 0600 and its folder at 0700, whatever
|
|
23
|
+
* either was before. The mode given to `writeFile` applies only to a file
|
|
24
|
+
* it creates, so both are set again after.
|
|
25
|
+
*
|
|
26
|
+
* @param filepath - The file.
|
|
27
|
+
* @param data - Its text.
|
|
28
|
+
*/
|
|
29
|
+
writePrivate(filepath: string, data: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Makes a credential already on disk, and its folder, its owner's alone
|
|
32
|
+
* when any other reader could reach them.
|
|
33
|
+
*
|
|
34
|
+
* @param filepath - The file; a file that is not there is left alone.
|
|
35
|
+
*/
|
|
36
|
+
private_tighten(filepath: string): Promise<void>;
|
|
21
37
|
remove(filepath: string): Promise<void>;
|
|
22
38
|
mkdir(filepath: string, options?: {
|
|
23
39
|
recursive?: boolean;
|
package/dist/io/node_io.js
CHANGED
|
@@ -46,6 +46,7 @@ exports.NodeStorageProvider = void 0;
|
|
|
46
46
|
const fs_1 = require("fs");
|
|
47
47
|
const path = __importStar(require("path"));
|
|
48
48
|
const os = __importStar(require("os"));
|
|
49
|
+
const crypto_1 = require("crypto");
|
|
49
50
|
/**
|
|
50
51
|
* Type guard for Node.js filesystem errors.
|
|
51
52
|
*/
|
|
@@ -55,6 +56,12 @@ function nodeError_is(error) {
|
|
|
55
56
|
'code' in error &&
|
|
56
57
|
'message' in error);
|
|
57
58
|
}
|
|
59
|
+
/** A credential's file: its owner reads and writes it, nobody else anything. */
|
|
60
|
+
const PRIVATE_FILE_MODE = 0o600;
|
|
61
|
+
/** A credential's folder: its owner alone may enter it. */
|
|
62
|
+
const PRIVATE_FOLDER_MODE = 0o700;
|
|
63
|
+
/** The permission bits of anybody but the owner. */
|
|
64
|
+
const OTHERS_MASK = 0o077;
|
|
58
65
|
/**
|
|
59
66
|
* NodeStorageProvider implements IStorageProvider using Node.js's native 'fs' module.
|
|
60
67
|
* It handles file system operations for reading, writing, and removing files,
|
|
@@ -112,6 +119,71 @@ class NodeStorageProvider {
|
|
|
112
119
|
throw new Error(`Failed to write file ${resolvedPath}: ${message}`);
|
|
113
120
|
}
|
|
114
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Writes a credential: the file at 0600 and its folder at 0700, whatever
|
|
124
|
+
* either was before. The mode given to `writeFile` applies only to a file
|
|
125
|
+
* it creates, so both are set again after.
|
|
126
|
+
*
|
|
127
|
+
* @param filepath - The file.
|
|
128
|
+
* @param data - Its text.
|
|
129
|
+
*/
|
|
130
|
+
async writePrivate(filepath, data) {
|
|
131
|
+
const resolvedPath = this.resolvePath(filepath);
|
|
132
|
+
const dir = path.dirname(resolvedPath);
|
|
133
|
+
await this.mkdir(dir, { recursive: true });
|
|
134
|
+
// The credential never stands in a file anybody else could read: it is
|
|
135
|
+
// written to a new file made private at its creation, in a folder shown
|
|
136
|
+
// private first, and only then takes the old file's place. A file
|
|
137
|
+
// already there, looser, is never written into.
|
|
138
|
+
const fresh = `${resolvedPath}.${process.pid}.${(0, crypto_1.randomBytes)(6).toString("hex")}.new`;
|
|
139
|
+
let made = false;
|
|
140
|
+
try {
|
|
141
|
+
await fs_1.promises.chmod(dir, PRIVATE_FOLDER_MODE);
|
|
142
|
+
if (((await fs_1.promises.stat(dir)).mode & OTHERS_MASK) !== 0)
|
|
143
|
+
throw new Error(`${dir} could not be made its owner's alone`);
|
|
144
|
+
const handle = await fs_1.promises.open(fresh, "wx", PRIVATE_FILE_MODE);
|
|
145
|
+
made = true;
|
|
146
|
+
try {
|
|
147
|
+
await handle.chmod(PRIVATE_FILE_MODE);
|
|
148
|
+
if (((await handle.stat()).mode & OTHERS_MASK) !== 0)
|
|
149
|
+
throw new Error(`${fresh} could not be made its owner's alone`);
|
|
150
|
+
await handle.writeFile(data, "utf-8");
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await handle.close();
|
|
154
|
+
}
|
|
155
|
+
await fs_1.promises.rename(fresh, resolvedPath);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (made)
|
|
159
|
+
await fs_1.promises.unlink(fresh).catch(() => undefined);
|
|
160
|
+
const message = nodeError_is(error) ? error.message : error instanceof Error ? error.message : String(error);
|
|
161
|
+
throw new Error(`Failed to write file ${resolvedPath} privately: ${message}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Makes a credential already on disk, and its folder, its owner's alone
|
|
166
|
+
* when any other reader could reach them.
|
|
167
|
+
*
|
|
168
|
+
* @param filepath - The file; a file that is not there is left alone.
|
|
169
|
+
*/
|
|
170
|
+
async private_tighten(filepath) {
|
|
171
|
+
const resolvedPath = this.resolvePath(filepath);
|
|
172
|
+
try {
|
|
173
|
+
const file = await fs_1.promises.stat(resolvedPath);
|
|
174
|
+
if ((file.mode & OTHERS_MASK) !== 0)
|
|
175
|
+
await fs_1.promises.chmod(resolvedPath, PRIVATE_FILE_MODE);
|
|
176
|
+
const dir = path.dirname(resolvedPath);
|
|
177
|
+
if (((await fs_1.promises.stat(dir)).mode & OTHERS_MASK) !== 0)
|
|
178
|
+
await fs_1.promises.chmod(dir, PRIVATE_FOLDER_MODE);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (nodeError_is(error) && error.code === "ENOENT")
|
|
182
|
+
return;
|
|
183
|
+
const message = nodeError_is(error) ? error.message : String(error);
|
|
184
|
+
throw new Error(`Failed to make ${resolvedPath} private: ${message}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
115
187
|
async remove(filepath) {
|
|
116
188
|
const resolvedPath = this.resolvePath(filepath);
|
|
117
189
|
try {
|
package/dist/io/node_io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node_io.js","sourceRoot":"","sources":["../../src/io/node_io.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,2BAAoC;AACpC,2CAA6B;AAC7B,uCAAyB;
|
|
1
|
+
{"version":3,"file":"node_io.js","sourceRoot":"","sources":["../../src/io/node_io.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,2BAAoC;AACpC,2CAA6B;AAC7B,uCAAyB;AACzB,mCAAqC;AAErC;;GAEG;AACH,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,SAAS,IAAI,KAAK,CACnB,CAAC;AACJ,CAA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
|
77
77
|
fail(error);
|
|
78
78
|
}, stallMs);
|
|
79
|
-
timer.unref
|
|
79
|
+
timer.unref();
|
|
80
80
|
};
|
|
81
81
|
const stop = () => {
|
|
82
82
|
stopped = true;
|
|
@@ -147,7 +147,7 @@ function stream_watchStalls(source, stallMs, what) {
|
|
|
147
147
|
source.destroy(error);
|
|
148
148
|
watched.destroy(error);
|
|
149
149
|
}, stallMs);
|
|
150
|
-
timer.unref
|
|
150
|
+
timer.unref();
|
|
151
151
|
};
|
|
152
152
|
const clock_stop = () => {
|
|
153
153
|
if (timer !== null)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamWatch.js","sourceRoot":"","sources":["../../src/io/streamWatch.ts"],"names":[],"mappings":";;;AAsDA,gDAqEC;AAeD,gDAmCC;AA7KD;;;;;;;;;;;;;;;GAeG;AACH,6CAAyD;AAEzD,yEAAyE;AAC5D,QAAA,eAAe,GAAW,MAAO,CAAC;AAE/C;;;;GAIG;AACH,MAAM,kBAAkB,GAAW,EAAE,GAAG,IAAI,CAAC;AAY7C;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,QAAgB,EAAE,OAAe;IAC9E,MAAM,KAAK,GAAW,IAAI,CAAC,IAAI,CAAC;IAChC,IAAI,KAAK,GAAW,CAAC,CAAC;IACtB,IAAI,KAAK,GAAyC,IAAI,CAAC;IACvD,IAAI,OAAO,GAAY,KAAK,CAAC;IAC7B,IAAI,IAAI,GAA2B,GAAS,EAAE,CAAC,SAAS,CAAC;IACzD,MAAM,WAAW,GAAqD,IAAI,GAAG,EAAE,CAAC;IAChF,MAAM,OAAO,GAAmB,IAAI,OAAO,CAAQ,CAAC,QAAQ,EAAE,MAAM,EAAQ,EAAE;QAC5E,IAAI,GAAG,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,6EAA6E;IAC7E,OAAO,CAAC,KAAK,CAAC,GAAS,EAAE,CAAC,SAAS,CAAC,CAAC;IACr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AK,EAAE,CAAC;IAChB,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,GAAS,EAAE;QAC5B,IAAI,KAAK,KAAK,IAAI;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACxC,KAAK,GAAG,IAAI,CAAC;IACf,CAAC,CAAC;IACF,WAAW,EAAE,CAAC;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAQ,EAAE;QACxC,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC;QACzB,WAAW,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAQ,EAAE;QACxC,UAAU,EAAE,CAAC;QACb,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** How many files move at once when the line and the session say nothing. */
|
|
2
|
+
export declare const TRANSFER_JOBS_DEFAULT: number;
|
|
3
|
+
/** The most files that move at once. */
|
|
4
|
+
export declare const TRANSFER_JOBS_MAX: number;
|
|
5
|
+
/** How many more times a failed file is tried. */
|
|
6
|
+
export declare const TRANSFER_RETRIES: number;
|
|
7
|
+
/**
|
|
8
|
+
* A failure that is not to be tried again: the work may have changed
|
|
9
|
+
* something before it failed, so a second try could act on what the first
|
|
10
|
+
* left half done, and its words (where each copy is) would replace the
|
|
11
|
+
* first's.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* throw new TransferFinalError('Could not rewrite /home/ada/a.txt: the old content is at /home/ada/.a.txt.mise-old-1f2e');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class TransferFinalError extends Error {
|
|
19
|
+
/** @param message - Why the item failed, with whatever a person needs to recover it. */
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The work for one item: moves it, and answers what the caller keeps.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const work: TransferWork<string, number> = async (path: string, signal: AbortSignal): Promise<number> => fetchBytes(path, signal);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type TransferWork<T, R> = (item: T, signal: AbortSignal) => Promise<R>;
|
|
31
|
+
/**
|
|
32
|
+
* One item settled: moved, or failed after its retry.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const settled: TransferSettled<string, number> = { item: '/a', ok: true, value: 3, attempts: 1 };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export type TransferSettled<T, R> = {
|
|
40
|
+
readonly item: T;
|
|
41
|
+
readonly ok: true;
|
|
42
|
+
readonly value: R;
|
|
43
|
+
readonly attempts: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly item: T;
|
|
46
|
+
readonly ok: false;
|
|
47
|
+
readonly reason: string;
|
|
48
|
+
readonly attempts: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* How the pool runs.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const options: TransferPoolOptions<string, number> = { jobs: 8 };
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export interface TransferPoolOptions<T, R> {
|
|
59
|
+
/** How many items move at once: a whole number from 1 to {@link TRANSFER_JOBS_MAX}. */
|
|
60
|
+
readonly jobs: number;
|
|
61
|
+
/** The line's abort signal: once it fires nothing new starts and nothing is retried. */
|
|
62
|
+
readonly signal?: AbortSignal;
|
|
63
|
+
/** How many more times a failed item is tried; {@link TRANSFER_RETRIES} by default. */
|
|
64
|
+
readonly retries?: number;
|
|
65
|
+
/** Told each item as it settles, in the order they end. */
|
|
66
|
+
readonly onSettled?: (settled: TransferSettled<T, R>) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One item that moved, and what its work answered.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const done: TransferDone<string, number> = { item: '/a', value: 3 };
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export interface TransferDone<T, R> {
|
|
77
|
+
/** The item. */
|
|
78
|
+
readonly item: T;
|
|
79
|
+
/** What its work answered. */
|
|
80
|
+
readonly value: R;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* One item that failed after its retry.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const failed: TransferFailure<string> = { item: '/a', reason: 'CUBE answered 500', attempts: 2 };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export interface TransferFailure<T> {
|
|
91
|
+
/** The item. */
|
|
92
|
+
readonly item: T;
|
|
93
|
+
/** Why its last attempt failed. */
|
|
94
|
+
readonly reason: string;
|
|
95
|
+
/** How many times it was tried. */
|
|
96
|
+
readonly attempts: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What the pool came to.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const result: TransferPoolResult<string, number> = { done: [], failed: [], cancelled: [] };
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export interface TransferPoolResult<T, R> {
|
|
107
|
+
/** The items that moved, in the order they ended. */
|
|
108
|
+
readonly done: TransferDone<T, R>[];
|
|
109
|
+
/** The items that failed after their retry, in the order they ended. */
|
|
110
|
+
readonly failed: TransferFailure<T>[];
|
|
111
|
+
/** The items a cancel left unmoved: never started, or stopped in flight. Empty unless the signal fired. */
|
|
112
|
+
readonly cancelled: T[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether a number is a number of jobs the pool takes, and why not.
|
|
116
|
+
*
|
|
117
|
+
* @param jobs - The number.
|
|
118
|
+
* @returns Null when it is one, else the reason in a few words.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* transferJobs_check(8); // null
|
|
123
|
+
* transferJobs_check(40); // 'at most 32'
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function transferJobs_check(jobs: number): string | null;
|
|
127
|
+
/**
|
|
128
|
+
* Runs the work over the items, at most `jobs` at once, each failed item
|
|
129
|
+
* tried once more, unless its failure is a {@link TransferFinalError}.
|
|
130
|
+
*
|
|
131
|
+
* Items start in their order; they end in whatever order they finish, and
|
|
132
|
+
* `onSettled` hears them so. An item whose attempt fails while the signal
|
|
133
|
+
* has fired counts as cancelled, not failed, unless its failure is a
|
|
134
|
+
* {@link TransferFinalError}: that is reported as failed, with its words.
|
|
135
|
+
*
|
|
136
|
+
* @param items - What to move.
|
|
137
|
+
* @param work - Moves one item; throws to fail it.
|
|
138
|
+
* @param options - How many at once, the line's signal, the retries, the settle callback.
|
|
139
|
+
* @returns What moved, what failed and what a cancel left.
|
|
140
|
+
* @throws {RangeError} When `jobs` is not a whole number from 1 to {@link TRANSFER_JOBS_MAX}.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const result: TransferPoolResult<number, number> = await transferPool_run(
|
|
145
|
+
* [1, 2, 3], async (n: number): Promise<number> => n * 2, { jobs: 2 },
|
|
146
|
+
* );
|
|
147
|
+
* result.done.length; // 3
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function transferPool_run<T, R>(items: readonly T[], work: TransferWork<T, R>, options: TransferPoolOptions<T, R>): Promise<TransferPoolResult<T, R>>;
|