@fnndsc/salsa 4.5.6 → 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 +2 -2
- package/dist/jobs/index.js.map +1 -1
- package/dist/jobs/jobOps.d.ts +20 -13
- package/dist/jobs/jobOps.js +41 -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
|
@@ -11,20 +11,23 @@ export interface PipelinePackage {
|
|
|
11
11
|
manifest: PipelineManifest;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Builds the
|
|
14
|
+
* Builds the identity-keyed store path without exposing the identity.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param identity - The identity the store is kept for (`user@url`).
|
|
17
17
|
* @param root - Store directory override (tests).
|
|
18
18
|
* @returns Versioned store file path.
|
|
19
19
|
*/
|
|
20
|
-
export declare function pipelinePackagesPath_get(
|
|
20
|
+
export declare function pipelinePackagesPath_get(identity: string, root?: string): string;
|
|
21
21
|
/**
|
|
22
|
-
* Restores the store from its durable file for the
|
|
23
|
-
*
|
|
22
|
+
* Restores the store from its durable file for the identity connected,
|
|
23
|
+
* once per identity. An identity with no file of its own (a first run, or
|
|
24
|
+
* one whose store was kept under the CUBE alone before) holds nothing
|
|
25
|
+
* whole until a sweep reads the registry whole: the warm-up runs one.
|
|
24
26
|
*
|
|
25
27
|
* @param root - Store directory override (tests).
|
|
28
|
+
* @returns Whether the store holds the whole registry, so a reader can say when it shows only part.
|
|
26
29
|
*/
|
|
27
|
-
export declare function pipelinePackages_restore(root?: string): Promise<
|
|
30
|
+
export declare function pipelinePackages_restore(root?: string): Promise<boolean>;
|
|
28
31
|
/**
|
|
29
32
|
* The warm-up tail: lists the registry and fetches manifests only for
|
|
30
33
|
* pipelines the store has never seen, then saves. Sequential awaits are the
|
|
@@ -33,12 +36,12 @@ export declare function pipelinePackages_restore(root?: string): Promise<void>;
|
|
|
33
36
|
* @param root - Store directory override (tests).
|
|
34
37
|
*/
|
|
35
38
|
export declare function pipelinePackages_sweep(root?: string): Promise<void>;
|
|
36
|
-
/** @returns Every cached package, sorted by name. */
|
|
39
|
+
/** @returns Every cached package, sorted by name; none for work that may not read the store. */
|
|
37
40
|
export declare function pipelinePackages_all(): PipelinePackage[];
|
|
38
41
|
/**
|
|
39
42
|
* Finds one cached package by id, exact name, or slug.
|
|
40
43
|
*
|
|
41
44
|
* @param specifier - Pipeline id (digits), name, or slug.
|
|
42
|
-
* @returns The package, or null when the store holds no match.
|
|
45
|
+
* @returns The package, or null when the store holds no match or the work may not read it.
|
|
43
46
|
*/
|
|
44
47
|
export declare function pipelinePackage_find(specifier: string): PipelinePackage | null;
|
|
@@ -10,54 +10,117 @@ exports.pipelinePackage_find = pipelinePackage_find;
|
|
|
10
10
|
*
|
|
11
11
|
* A registered pipeline is immutable, so what CUBE knows about it — identity
|
|
12
12
|
* fields and the complete registered manifest — is fetched once, held in
|
|
13
|
-
* memory, and checkpointed to a local file keyed by the
|
|
13
|
+
* memory, and checkpointed to a local file keyed by the identity connected
|
|
14
|
+
* (`user@url`): CUBE lists a locked pipeline only to its owner, so what one
|
|
15
|
+
* user is shown is not another's to restore. The sweep
|
|
14
16
|
* runs as a warm-up tail after the topology index settles: it lists the
|
|
15
17
|
* registry and fetches only pipelines the store has never seen, so the
|
|
16
18
|
* steady-state cost is zero and a fresh daemon restores everything without
|
|
17
19
|
* a wire call. The `/usr/share/packages/<pipeline>` VFS tree and the diagram
|
|
18
20
|
* builder both read from here.
|
|
19
21
|
*
|
|
22
|
+
* The store follows the identity as every cache does: emptied when it
|
|
23
|
+
* changes, and neither read, filled nor written by work done as another
|
|
24
|
+
* user (`sudo`) or begun under an identity since replaced.
|
|
25
|
+
*
|
|
20
26
|
* @module
|
|
21
27
|
*/
|
|
22
28
|
const crypto_1 = require("crypto");
|
|
23
29
|
const fs_1 = require("fs");
|
|
24
|
-
const os_1 = require("os");
|
|
25
30
|
const path_1 = require("path");
|
|
26
31
|
const cumin_1 = require("@fnndsc/cumin");
|
|
32
|
+
const fond_1 = require("@fnndsc/fond");
|
|
27
33
|
const manifest_js_1 = require("./manifest.js");
|
|
28
|
-
|
|
34
|
+
/** Where the store is listed: its kept listings go when which pipelines it holds changes. */
|
|
35
|
+
const PACKAGES_LISTING = '/usr/share/packages';
|
|
29
36
|
/** Bumped when the persisted shape changes; older files are ignored. */
|
|
30
|
-
const PACKAGES_SCHEMA =
|
|
37
|
+
const PACKAGES_SCHEMA = 2;
|
|
31
38
|
/** The in-memory store, keyed by pipeline id. */
|
|
32
39
|
const packages = new Map();
|
|
33
|
-
/**
|
|
34
|
-
let
|
|
40
|
+
/** Whose packages the store holds, or null when it holds nobody's. */
|
|
41
|
+
let held = null;
|
|
42
|
+
/** Who the saved login is, before any change of identity: found once someone is found. */
|
|
43
|
+
let coldKey = null;
|
|
44
|
+
// The store is one identity's: at a change of identity it is emptied, and who is connected is found again.
|
|
45
|
+
(0, cumin_1.identityChange_listen)(() => {
|
|
46
|
+
packages.clear();
|
|
47
|
+
held = null;
|
|
48
|
+
coldKey = null;
|
|
49
|
+
});
|
|
35
50
|
/** Returns the default directory for persistent pipeline-package files. */
|
|
36
51
|
function packagesRoot_get() {
|
|
37
|
-
|
|
38
|
-
return (0, path_1.join)(cacheHome, 'chell', 'pipelines');
|
|
52
|
+
return (0, path_1.join)((0, fond_1.xdgDir_resolve)('cache'), 'chell', 'pipelines');
|
|
39
53
|
}
|
|
40
54
|
/**
|
|
41
|
-
* Builds the
|
|
55
|
+
* Builds the identity-keyed store path without exposing the identity.
|
|
42
56
|
*
|
|
43
|
-
* @param
|
|
57
|
+
* @param identity - The identity the store is kept for (`user@url`).
|
|
44
58
|
* @param root - Store directory override (tests).
|
|
45
59
|
* @returns Versioned store file path.
|
|
46
60
|
*/
|
|
47
|
-
function pipelinePackagesPath_get(
|
|
48
|
-
const key = (0, crypto_1.createHash)('sha256').update(
|
|
61
|
+
function pipelinePackagesPath_get(identity, root = packagesRoot_get()) {
|
|
62
|
+
const key = (0, crypto_1.createHash)('sha256').update(identity).digest('hex').slice(0, 16);
|
|
49
63
|
return (0, path_1.join)(root, `packages-${key}-v${PACKAGES_SCHEMA}.json`);
|
|
50
64
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The saved login the connection was initialised with, or null when it
|
|
67
|
+
* cannot be told (none, no usable token, or a connection that cannot say).
|
|
68
|
+
*
|
|
69
|
+
* @returns `user@url`, or null.
|
|
70
|
+
*/
|
|
71
|
+
async function savedLogin_lookup() {
|
|
53
72
|
try {
|
|
54
|
-
|
|
55
|
-
return context.URL ?? null;
|
|
73
|
+
return await cumin_1.chrisConnection.savedLogin_name();
|
|
56
74
|
}
|
|
57
75
|
catch {
|
|
58
76
|
return null;
|
|
59
77
|
}
|
|
60
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Who the connection is authenticated as: what the store is keyed by.
|
|
81
|
+
* After a change of identity it is the name that change was published
|
|
82
|
+
* with, and null at once after a logout. Before any, it is the saved login
|
|
83
|
+
* the connection was initialised with, while a usable token of its own is
|
|
84
|
+
* held: found once, and kept only when someone was found, so a lookup that
|
|
85
|
+
* found nobody is made again by the next read. Never the selected context,
|
|
86
|
+
* which outlives a logout, may name a user whose login was held for the
|
|
87
|
+
* session only, and may be moved by another process.
|
|
88
|
+
*
|
|
89
|
+
* @returns `user@url`, or null when nobody is authenticated.
|
|
90
|
+
*/
|
|
91
|
+
function storeKey_get() {
|
|
92
|
+
if ((0, cumin_1.identityEpoch_get)() > 0)
|
|
93
|
+
return Promise.resolve((0, cumin_1.identityName_get)());
|
|
94
|
+
if (coldKey !== null)
|
|
95
|
+
return coldKey;
|
|
96
|
+
const lookup = savedLogin_lookup();
|
|
97
|
+
coldKey = lookup;
|
|
98
|
+
void lookup.then((key) => {
|
|
99
|
+
if (key === null && coldKey === lookup)
|
|
100
|
+
coldKey = null;
|
|
101
|
+
});
|
|
102
|
+
return lookup;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether work begun under an epoch may still read or change the store:
|
|
106
|
+
* the identity has not changed since, and the work is not another user's.
|
|
107
|
+
*
|
|
108
|
+
* @param began - The identity epoch the work was begun under.
|
|
109
|
+
* @returns True while the work is the session's current identity's.
|
|
110
|
+
*/
|
|
111
|
+
function work_current(began) {
|
|
112
|
+
return began === (0, cumin_1.identityEpoch_get)() && (0, cumin_1.identityCache_usable)();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether the store holds an identity's packages for work begun under an epoch.
|
|
116
|
+
*
|
|
117
|
+
* @param key - The identity.
|
|
118
|
+
* @param began - The identity epoch the work was begun under.
|
|
119
|
+
* @returns True when the store is that identity's and the work is still current.
|
|
120
|
+
*/
|
|
121
|
+
function store_holds(key, began) {
|
|
122
|
+
return work_current(began) && held !== null && held.key === key && held.epoch === began;
|
|
123
|
+
}
|
|
61
124
|
/** Structurally validates one persisted package entry. */
|
|
62
125
|
function package_check(value) {
|
|
63
126
|
if (!value || typeof value !== 'object')
|
|
@@ -70,49 +133,180 @@ function package_check(value) {
|
|
|
70
133
|
Array.isArray(entry.manifest.rootIDs);
|
|
71
134
|
}
|
|
72
135
|
/**
|
|
73
|
-
*
|
|
74
|
-
* key. Missing or invalid files leave the store empty — the sweep refills.
|
|
136
|
+
* Reads an identity's durable file.
|
|
75
137
|
*
|
|
76
|
-
* @param
|
|
138
|
+
* @param key - The identity.
|
|
139
|
+
* @param root - Store directory.
|
|
140
|
+
* @returns Its valid entries, and whether every row was one; null when there is no file of this identity's to restore.
|
|
77
141
|
*/
|
|
78
|
-
async function
|
|
79
|
-
const key = await storeKey_get();
|
|
80
|
-
if (key === null || key === restoredKey)
|
|
81
|
-
return;
|
|
82
|
-
restoredKey = key;
|
|
83
|
-
packages.clear();
|
|
142
|
+
async function packagesFile_read(key, root) {
|
|
84
143
|
try {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (package_check(entry))
|
|
92
|
-
packages.set(entry.id, entry);
|
|
93
|
-
}
|
|
144
|
+
const parsed = JSON.parse(await fs_1.promises.readFile(pipelinePackagesPath_get(key, root), 'utf8'));
|
|
145
|
+
const file = parsed;
|
|
146
|
+
if (file.identity !== key || !Array.isArray(file.packages))
|
|
147
|
+
return null;
|
|
148
|
+
const entries = file.packages.filter(package_check);
|
|
149
|
+
return { entries, whole: entries.length === file.packages.length };
|
|
94
150
|
}
|
|
95
151
|
catch {
|
|
96
|
-
|
|
152
|
+
return null;
|
|
97
153
|
}
|
|
98
154
|
}
|
|
99
155
|
/**
|
|
100
|
-
*
|
|
156
|
+
* Restores the store for the identity connected, once per identity, and
|
|
157
|
+
* waits for a restore of it already under way.
|
|
158
|
+
*
|
|
159
|
+
* @param root - Store directory.
|
|
160
|
+
* @returns The holding the store is now, or null when the work may not have one.
|
|
161
|
+
*/
|
|
162
|
+
async function store_restore(root) {
|
|
163
|
+
const began = (0, cumin_1.identityEpoch_get)();
|
|
164
|
+
if (!work_current(began))
|
|
165
|
+
return null;
|
|
166
|
+
const key = await storeKey_get();
|
|
167
|
+
// The identity changed while who is connected was being found: nothing of this is taken.
|
|
168
|
+
if (!work_current(began) || key === null)
|
|
169
|
+
return null;
|
|
170
|
+
let holding = held;
|
|
171
|
+
if (holding === null || holding.key !== key || holding.epoch !== began) {
|
|
172
|
+
packages.clear();
|
|
173
|
+
const made = { key, epoch: began, restoring: Promise.resolve(), whole: false, dirty: true };
|
|
174
|
+
held = made;
|
|
175
|
+
made.restoring = packagesStore_fill(made, root);
|
|
176
|
+
holding = made;
|
|
177
|
+
}
|
|
178
|
+
await holding.restoring;
|
|
179
|
+
return held === holding ? holding : null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Restores the store from its durable file for the identity connected,
|
|
183
|
+
* once per identity. An identity with no file of its own (a first run, or
|
|
184
|
+
* one whose store was kept under the CUBE alone before) holds nothing
|
|
185
|
+
* whole until a sweep reads the registry whole: the warm-up runs one.
|
|
186
|
+
*
|
|
187
|
+
* @param root - Store directory override (tests).
|
|
188
|
+
* @returns Whether the store holds the whole registry, so a reader can say when it shows only part.
|
|
189
|
+
*/
|
|
190
|
+
async function pipelinePackages_restore(root = packagesRoot_get()) {
|
|
191
|
+
const holding = await store_restore(root);
|
|
192
|
+
return holding !== null && holding.whole;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Fills the store for an identity from its file, when it has one. A file
|
|
196
|
+
* with a row that could not be read is shown for what it holds, and is not
|
|
197
|
+
* whole: the warm-up sweeps again.
|
|
101
198
|
*
|
|
102
|
-
* @param
|
|
199
|
+
* @param holding - Whose store, as of which epoch.
|
|
200
|
+
* @param root - Store directory.
|
|
201
|
+
*/
|
|
202
|
+
async function packagesStore_fill(holding, root) {
|
|
203
|
+
const file = await packagesFile_read(holding.key, root);
|
|
204
|
+
if (file === null || !store_holds(holding.key, holding.epoch))
|
|
205
|
+
return;
|
|
206
|
+
for (const entry of file.entries)
|
|
207
|
+
packages.set(entry.id, entry);
|
|
208
|
+
holding.whole = file.whole;
|
|
209
|
+
holding.dirty = !file.whole;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Writes the store durably, atomically, keyed by its identity.
|
|
213
|
+
*
|
|
214
|
+
* @param key - The identity.
|
|
103
215
|
* @param root - Store directory override (tests).
|
|
216
|
+
* @returns Whether the commit is confirmed on disk.
|
|
104
217
|
*/
|
|
105
218
|
async function packages_save(key, root = packagesRoot_get()) {
|
|
106
|
-
|
|
107
|
-
const
|
|
219
|
+
// One absolute path for the write, the rename and the cleanup alike, whatever the working directory does meanwhile.
|
|
220
|
+
const path = (0, path_1.resolve)(pipelinePackagesPath_get(key, root));
|
|
108
221
|
const file = {
|
|
109
222
|
schema: PACKAGES_SCHEMA,
|
|
223
|
+
identity: key,
|
|
110
224
|
savedAt: new Date().toISOString(),
|
|
111
225
|
packages: Array.from(packages.values()),
|
|
112
226
|
};
|
|
113
227
|
await fs_1.promises.mkdir((0, path_1.dirname)(path), { recursive: true, mode: 0o700 });
|
|
114
|
-
|
|
115
|
-
|
|
228
|
+
// The one writer of a session's records: a failed write leaves the old file and no temporary.
|
|
229
|
+
return (0, fond_1.recordFile_writeAsync)(path, `${JSON.stringify(file)}\n`, { mode: 0o600 });
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Fetches one registered pipeline's package: its identity and manifest.
|
|
233
|
+
*
|
|
234
|
+
* @param client - The CUBE client.
|
|
235
|
+
* @param record - The registry's record of it.
|
|
236
|
+
* @returns The package, or null when it could not be fetched.
|
|
237
|
+
*/
|
|
238
|
+
async function package_fetch(client, record) {
|
|
239
|
+
const handle = await (0, cumin_1.pipeline_get)(client, record.id);
|
|
240
|
+
if (!handle)
|
|
241
|
+
return null;
|
|
242
|
+
const manifest = await (0, manifest_js_1.pipelineManifestForPipeline_get)(record, handle, { detail: 'registered' });
|
|
243
|
+
if (!manifest.ok)
|
|
244
|
+
return null;
|
|
245
|
+
return {
|
|
246
|
+
id: record.id,
|
|
247
|
+
name: record.name,
|
|
248
|
+
...(typeof record.slug === 'string' ? { slug: record.slug } : {}),
|
|
249
|
+
...(typeof record.authors === 'string' ? { authors: record.authors } : {}),
|
|
250
|
+
...(typeof record.category === 'string' ? { category: record.category } : {}),
|
|
251
|
+
...(typeof record.description === 'string' ? { description: record.description } : {}),
|
|
252
|
+
...(typeof record.locked === 'boolean' ? { locked: record.locked } : {}),
|
|
253
|
+
manifest: manifest.value,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Lists the registry and fetches the pipelines the store has never seen,
|
|
258
|
+
* building the pass apart from the store. Only a whole pass (the listing
|
|
259
|
+
* came whole, and every manifest listed was read) is published: the store
|
|
260
|
+
* becomes exactly that pass and is written if it differs from the file. A
|
|
261
|
+
* pass that is not whole leaves the store as it was, and the next sweep
|
|
262
|
+
* tries again. Nothing is published once the identity has changed.
|
|
263
|
+
*
|
|
264
|
+
* @param holding - Whose store, as of which epoch.
|
|
265
|
+
* @param root - Store directory.
|
|
266
|
+
* @throws {Error} When the file could not be written: the store stays dirty, and the next sweep writes it.
|
|
267
|
+
*/
|
|
268
|
+
async function packages_sweep(holding, root) {
|
|
269
|
+
const listed = await (0, cumin_1.pipelineRegistry_read)();
|
|
270
|
+
if (!listed.ok || !listed.value.whole)
|
|
271
|
+
return;
|
|
272
|
+
const client = await cumin_1.chrisConnection.client_get();
|
|
273
|
+
if (!client || !store_holds(holding.key, holding.epoch))
|
|
274
|
+
return;
|
|
275
|
+
const pass = new Map();
|
|
276
|
+
for (const record of listed.value.records) {
|
|
277
|
+
const known = packages.get(record.id);
|
|
278
|
+
const entry = known ?? await package_fetch(client, record);
|
|
279
|
+
if (!store_holds(holding.key, holding.epoch) || entry === null)
|
|
280
|
+
return;
|
|
281
|
+
pass.set(record.id, entry);
|
|
282
|
+
}
|
|
283
|
+
await store_publish(holding, pass, root);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Makes the store exactly a whole pass over the registry, and writes it
|
|
287
|
+
* when it differs from the file. When which pipelines it holds changes, the
|
|
288
|
+
* kept listings of `/usr/share/packages` and beneath it are dropped.
|
|
289
|
+
*
|
|
290
|
+
* @param holding - Whose store, as of which epoch.
|
|
291
|
+
* @param pass - Every pipeline the whole pass listed, with its package.
|
|
292
|
+
* @param root - Store directory.
|
|
293
|
+
*/
|
|
294
|
+
async function store_publish(holding, pass, root) {
|
|
295
|
+
const changed = pass.size !== packages.size || [...pass.keys()].some((id) => !packages.has(id));
|
|
296
|
+
if (changed) {
|
|
297
|
+
packages.clear();
|
|
298
|
+
for (const [id, entry] of pass)
|
|
299
|
+
packages.set(id, entry);
|
|
300
|
+
holding.dirty = true;
|
|
301
|
+
(0, cumin_1.listCache_get)().cache_invalidateTree(PACKAGES_LISTING);
|
|
302
|
+
}
|
|
303
|
+
holding.whole = true;
|
|
304
|
+
if (!holding.dirty)
|
|
305
|
+
return;
|
|
306
|
+
const written = await packages_save(holding.key, root);
|
|
307
|
+
// A file in place but not confirmed on disk may come back as the one before after a crash: the store stays
|
|
308
|
+
// dirty, and the next sweep writes it again.
|
|
309
|
+
holding.dirty = !written.durable;
|
|
116
310
|
}
|
|
117
311
|
/**
|
|
118
312
|
* The warm-up tail: lists the registry and fetches manifests only for
|
|
@@ -122,52 +316,34 @@ async function packages_save(key, root = packagesRoot_get()) {
|
|
|
122
316
|
* @param root - Store directory override (tests).
|
|
123
317
|
*/
|
|
124
318
|
async function pipelinePackages_sweep(root = packagesRoot_get()) {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
await pipelinePackages_restore(root);
|
|
129
|
-
const listed = await (0, cumin_1.pipelines_list)();
|
|
130
|
-
if (!listed.ok)
|
|
131
|
-
return;
|
|
132
|
-
const client = await cumin_1.chrisConnection.client_get();
|
|
133
|
-
if (!client)
|
|
134
|
-
return;
|
|
135
|
-
let added = false;
|
|
136
|
-
for (const record of listed.value) {
|
|
137
|
-
if (packages.has(record.id))
|
|
138
|
-
continue;
|
|
139
|
-
const handle = await (0, cumin_1.pipeline_get)(client, record.id);
|
|
140
|
-
if (!handle)
|
|
141
|
-
continue;
|
|
142
|
-
const manifest = await (0, manifest_js_1.pipelineManifestForPipeline_get)(record, handle, { detail: 'registered' });
|
|
143
|
-
if (!manifest.ok)
|
|
144
|
-
continue;
|
|
145
|
-
packages.set(record.id, {
|
|
146
|
-
id: record.id,
|
|
147
|
-
name: record.name,
|
|
148
|
-
...(typeof record.slug === 'string' ? { slug: record.slug } : {}),
|
|
149
|
-
...(typeof record.authors === 'string' ? { authors: record.authors } : {}),
|
|
150
|
-
...(typeof record.category === 'string' ? { category: record.category } : {}),
|
|
151
|
-
...(typeof record.description === 'string' ? { description: record.description } : {}),
|
|
152
|
-
...(typeof record.locked === 'boolean' ? { locked: record.locked } : {}),
|
|
153
|
-
manifest: manifest.value,
|
|
154
|
-
});
|
|
155
|
-
added = true;
|
|
156
|
-
}
|
|
157
|
-
if (added)
|
|
158
|
-
await packages_save(key, root);
|
|
319
|
+
const holding = await store_restore(root);
|
|
320
|
+
if (holding !== null)
|
|
321
|
+
await packages_sweep(holding, root);
|
|
159
322
|
}
|
|
160
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* Whether the work now running may read the store: it is the session's
|
|
325
|
+
* current identity's, and the store holds that identity's packages.
|
|
326
|
+
*
|
|
327
|
+
* @returns True when a read may be answered from the store.
|
|
328
|
+
*/
|
|
329
|
+
function store_readable() {
|
|
330
|
+
return (0, cumin_1.identityCache_usable)() && held !== null && held.epoch === (0, cumin_1.identityEpoch_get)();
|
|
331
|
+
}
|
|
332
|
+
/** @returns Every cached package, sorted by name; none for work that may not read the store. */
|
|
161
333
|
function pipelinePackages_all() {
|
|
334
|
+
if (!store_readable())
|
|
335
|
+
return [];
|
|
162
336
|
return Array.from(packages.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
163
337
|
}
|
|
164
338
|
/**
|
|
165
339
|
* Finds one cached package by id, exact name, or slug.
|
|
166
340
|
*
|
|
167
341
|
* @param specifier - Pipeline id (digits), name, or slug.
|
|
168
|
-
* @returns The package, or null when the store holds no match.
|
|
342
|
+
* @returns The package, or null when the store holds no match or the work may not read it.
|
|
169
343
|
*/
|
|
170
344
|
function pipelinePackage_find(specifier) {
|
|
345
|
+
if (!store_readable())
|
|
346
|
+
return null;
|
|
171
347
|
const trimmed = specifier.trim();
|
|
172
348
|
if (/^\d+$/.test(trimmed)) {
|
|
173
349
|
return packages.get(parseInt(trimmed, 10)) ?? null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/pipelines/packages.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/pipelines/packages.ts"],"names":[],"mappings":";;AA2HA,4DAGC;AA6HD,4DAGC;AA6HD,wDAGC;AAaD,oDAKC;AAQD,oDAUC;AAlaD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,mCAAoC;AACpC,2BAAoC;AACpC,+BAA8C;AAC9C,yCAauB;AACvB,uCAAuF;AACvF,+CAAuF;AAmDvF,6FAA6F;AAC7F,MAAM,gBAAgB,GAAW,qBAAqB,CAAC;AAEvD,wEAAwE;AACxE,MAAM,eAAe,GAAW,CAAC,CAAC;AAElC,iDAAiD;AACjD,MAAM,QAAQ,GAAiC,IAAI,GAAG,EAAE,CAAC;AAEzD,sEAAsE;AACtE,IAAI,IAAI,GAAwB,IAAI,CAAC;AAErC,0FAA0F;AAC1F,IAAI,OAAO,GAAkC,IAAI,CAAC;AAElD,2GAA2G;AAC3G,IAAA,6BAAqB,EAAC,GAAS,EAAE;IAC/B,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,IAAI,GAAG,IAAI,CAAC;IACZ,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC,CAAC,CAAC;AAEH,2EAA2E;AAC3E,SAAS,gBAA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AAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CACvC,CAAC,CAAkB,EAAE,CAAkB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CACzE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,SAAiB;IACpD,IAAI,CAAC,cAAc,EAAE;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,OAAO,GAAW,SAAS,CAAC,IAAI,EAAE,CAAC;IACzC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;IACrD,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The admin token a plugin registration is made with.
|
|
3
|
+
*
|
|
4
|
+
* Registering a plugin through CUBE's admin endpoint wants an administrator's
|
|
5
|
+
* token. When admin credentials are given, they are traded for one at the
|
|
6
|
+
* connected CUBE's `auth-token/`; a refusal is a warning on the error stack,
|
|
7
|
+
* and the registration goes on without a token (CUBE then says whether the
|
|
8
|
+
* caller's own session may register).
|
|
9
|
+
*
|
|
10
|
+
* Key components:
|
|
11
|
+
* - AdminLogin: admin credentials with both their parts.
|
|
12
|
+
* - adminCreds_complete: whether credentials name both a username and a password.
|
|
13
|
+
* - adminToken_fetch: trades complete admin credentials for a token.
|
|
14
|
+
*
|
|
15
|
+
* Typical usage:
|
|
16
|
+
* ```ts
|
|
17
|
+
* const adminToken: string | undefined = adminCreds_complete(adminCreds) ? await adminToken_fetch(chrisPlugin, adminCreds) : undefined;
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Credentials that are not complete are not traded at all: the caller goes on to register without waiting.
|
|
21
|
+
*
|
|
22
|
+
* Dependencies: `@fnndsc/cumin` (the plugin group's client, `apiRoot_parse`, `authToken_get`, which follows no redirect with the password, the error stack).
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { ChRISPlugin } from '@fnndsc/cumin';
|
|
27
|
+
import type { AdminCredentials } from './store_import.js';
|
|
28
|
+
/**
|
|
29
|
+
* Admin credentials with both their parts.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const login: AdminLogin = { username: 'chris', password: 'secret' };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface AdminLogin {
|
|
37
|
+
/** The administrator's name. */
|
|
38
|
+
username: string;
|
|
39
|
+
/** Their password. */
|
|
40
|
+
password: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether credentials name both a username and a password: only such are traded for a token.
|
|
44
|
+
*
|
|
45
|
+
* @param adminCreds - The credentials, when given.
|
|
46
|
+
* @returns True when both parts are there and not empty.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* adminCreds_complete({ username: 'chris' }); // false
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function adminCreds_complete(adminCreds: AdminCredentials | undefined): adminCreds is AdminLogin;
|
|
54
|
+
/**
|
|
55
|
+
* Trades admin credentials for a token at the connected CUBE.
|
|
56
|
+
*
|
|
57
|
+
* @param chrisPlugin - The plugin group whose client names the CUBE.
|
|
58
|
+
* @param adminCreds - The credentials, both parts given.
|
|
59
|
+
* @returns The token, or undefined when nobody is connected or CUBE refused
|
|
60
|
+
* them (said as a warning on the error stack).
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const adminToken: string | undefined = await adminToken_fetch(new ChRISPlugin(), { username: 'chris', password: 'secret' });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function adminToken_fetch(chrisPlugin: ChRISPlugin, adminCreds: AdminLogin): Promise<string | undefined>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adminCreds_complete = adminCreds_complete;
|
|
4
|
+
exports.adminToken_fetch = adminToken_fetch;
|
|
5
|
+
/**
|
|
6
|
+
* @file The admin token a plugin registration is made with.
|
|
7
|
+
*
|
|
8
|
+
* Registering a plugin through CUBE's admin endpoint wants an administrator's
|
|
9
|
+
* token. When admin credentials are given, they are traded for one at the
|
|
10
|
+
* connected CUBE's `auth-token/`; a refusal is a warning on the error stack,
|
|
11
|
+
* and the registration goes on without a token (CUBE then says whether the
|
|
12
|
+
* caller's own session may register).
|
|
13
|
+
*
|
|
14
|
+
* Key components:
|
|
15
|
+
* - AdminLogin: admin credentials with both their parts.
|
|
16
|
+
* - adminCreds_complete: whether credentials name both a username and a password.
|
|
17
|
+
* - adminToken_fetch: trades complete admin credentials for a token.
|
|
18
|
+
*
|
|
19
|
+
* Typical usage:
|
|
20
|
+
* ```ts
|
|
21
|
+
* const adminToken: string | undefined = adminCreds_complete(adminCreds) ? await adminToken_fetch(chrisPlugin, adminCreds) : undefined;
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Credentials that are not complete are not traded at all: the caller goes on to register without waiting.
|
|
25
|
+
*
|
|
26
|
+
* Dependencies: `@fnndsc/cumin` (the plugin group's client, `apiRoot_parse`, `authToken_get`, which follows no redirect with the password, the error stack).
|
|
27
|
+
*
|
|
28
|
+
* @module
|
|
29
|
+
*/
|
|
30
|
+
const cumin_1 = require("@fnndsc/cumin");
|
|
31
|
+
/**
|
|
32
|
+
* Whether credentials name both a username and a password: only such are traded for a token.
|
|
33
|
+
*
|
|
34
|
+
* @param adminCreds - The credentials, when given.
|
|
35
|
+
* @returns True when both parts are there and not empty.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* adminCreds_complete({ username: 'chris' }); // false
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function adminCreds_complete(adminCreds) {
|
|
43
|
+
return Boolean(adminCreds && adminCreds.username && adminCreds.password);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Trades admin credentials for a token at the connected CUBE.
|
|
47
|
+
*
|
|
48
|
+
* @param chrisPlugin - The plugin group whose client names the CUBE.
|
|
49
|
+
* @param adminCreds - The credentials, both parts given.
|
|
50
|
+
* @returns The token, or undefined when nobody is connected or CUBE refused
|
|
51
|
+
* them (said as a warning on the error stack).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const adminToken: string | undefined = await adminToken_fetch(new ChRISPlugin(), { username: 'chris', password: 'secret' });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async function adminToken_fetch(chrisPlugin, adminCreds) {
|
|
59
|
+
let adminToken;
|
|
60
|
+
const client = await chrisPlugin.client_get();
|
|
61
|
+
if (client) {
|
|
62
|
+
try {
|
|
63
|
+
// Resolved below the root, never joined as text: a root given without its slash could otherwise name another host.
|
|
64
|
+
const root = (0, cumin_1.apiRoot_parse)(client.url);
|
|
65
|
+
const token = await (0, cumin_1.authToken_get)(new URL('auth-token/', root).href, adminCreds.username, adminCreds.password, root);
|
|
66
|
+
if (token) {
|
|
67
|
+
adminToken = token;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
72
|
+
cumin_1.errorStack.stack_push('warning', `Failed to get admin token: ${msg}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return adminToken;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=adminToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminToken.js","sourceRoot":"","sources":["../../src/plugins/adminToken.ts"],"names":[],"mappings":";;AAuDA,kDAEC;AAeD,4CAsBC;AA9FD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,yCAAmG;AAmBnG;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,UAAwC;IAC1E,OAAO,OAAO,CAAC,UAAU,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,gBAAgB,CAAC,WAAwB,EAAE,UAAsB;IACrF,IAAI,UAA8B,CAAC;IACnC,MAAM,MAAM,GAAkB,MAAM,WAAW,CAAC,UAAU,EAAE,CAAC;IAC7D,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,mHAAmH;YACnH,MAAM,IAAI,GAAQ,IAAA,qBAAa,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,KAAK,GAAW,MAAM,IAAA,qBAAa,EACvC,IAAI,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,IAAI,EACjC,UAAU,CAAC,QAAQ,EACnB,UAAU,CAAC,QAAQ,EACnB,IAAI,CACL,CAAC;YACF,IAAI,KAAK,EAAE,CAAC;gBACV,UAAU,GAAG,KAAK,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,MAAM,GAAG,GAAW,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/D,kBAAU,CAAC,UAAU,CAAC,SAAS,EAAE,8BAA8B,GA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