@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.
Files changed (158) hide show
  1. package/README.md +0 -2
  2. package/dist/compute/index.d.ts +0 -9
  3. package/dist/compute/index.js +0 -16
  4. package/dist/compute/index.js.map +1 -1
  5. package/dist/dag/feedData.js +166 -73
  6. package/dist/dag/feedData.js.map +1 -1
  7. package/dist/dag/feedLoad.d.ts +1 -1
  8. package/dist/dag/feedLoad.js +6 -4
  9. package/dist/dag/feedLoad.js.map +1 -1
  10. package/dist/dicom/pixels.js +95 -36
  11. package/dist/dicom/pixels.js.map +1 -1
  12. package/dist/dicom/series.d.ts +4 -1
  13. package/dist/dicom/series.js +80 -31
  14. package/dist/dicom/series.js.map +1 -1
  15. package/dist/dicom/tags.d.ts +28 -0
  16. package/dist/dicom/tags.js +30 -0
  17. package/dist/dicom/tags.js.map +1 -1
  18. package/dist/files/copy.d.ts +197 -0
  19. package/dist/files/copy.js +636 -0
  20. package/dist/files/copy.js.map +1 -0
  21. package/dist/files/copyFolder.d.ts +103 -0
  22. package/dist/files/copyFolder.js +199 -0
  23. package/dist/files/copyFolder.js.map +1 -0
  24. package/dist/files/create.d.ts +178 -0
  25. package/dist/files/create.js +444 -0
  26. package/dist/files/create.js.map +1 -0
  27. package/dist/files/download.d.ts +188 -0
  28. package/dist/files/download.js +541 -0
  29. package/dist/files/download.js.map +1 -0
  30. package/dist/files/index.d.ts +69 -141
  31. package/dist/files/index.js +184 -535
  32. package/dist/files/index.js.map +1 -1
  33. package/dist/files/listing.d.ts +132 -0
  34. package/dist/files/listing.js +179 -0
  35. package/dist/files/listing.js.map +1 -0
  36. package/dist/files/move.d.ts +125 -0
  37. package/dist/files/move.js +334 -0
  38. package/dist/files/move.js.map +1 -0
  39. package/dist/files/pathMapper.d.ts +24 -1
  40. package/dist/files/pathMapper.js +108 -47
  41. package/dist/files/pathMapper.js.map +1 -1
  42. package/dist/files/proof.d.ts +315 -0
  43. package/dist/files/proof.js +574 -0
  44. package/dist/files/proof.js.map +1 -0
  45. package/dist/files/removal.d.ts +223 -0
  46. package/dist/files/removal.js +318 -0
  47. package/dist/files/removal.js.map +1 -0
  48. package/dist/files/replace.d.ts +175 -0
  49. package/dist/files/replace.js +582 -0
  50. package/dist/files/replace.js.map +1 -0
  51. package/dist/files/upload.d.ts +205 -0
  52. package/dist/files/upload.js +478 -0
  53. package/dist/files/upload.js.map +1 -0
  54. package/dist/index.d.ts +14 -2
  55. package/dist/index.js +45 -32
  56. package/dist/index.js.map +1 -1
  57. package/dist/jobs/index.d.ts +1 -1
  58. package/dist/jobs/index.js +2 -2
  59. package/dist/jobs/index.js.map +1 -1
  60. package/dist/jobs/jobOps.d.ts +20 -13
  61. package/dist/jobs/jobOps.js +41 -37
  62. package/dist/jobs/jobOps.js.map +1 -1
  63. package/dist/pacs/anonymise.d.ts +17 -36
  64. package/dist/pacs/anonymise.js +29 -67
  65. package/dist/pacs/anonymise.js.map +1 -1
  66. package/dist/pipelines/index.d.ts +1 -13
  67. package/dist/pipelines/index.js +0 -38
  68. package/dist/pipelines/index.js.map +1 -1
  69. package/dist/pipelines/invocation.js +321 -167
  70. package/dist/pipelines/invocation.js.map +1 -1
  71. package/dist/pipelines/manifest.js.map +1 -1
  72. package/dist/pipelines/packages.d.ts +11 -8
  73. package/dist/pipelines/packages.js +253 -77
  74. package/dist/pipelines/packages.js.map +1 -1
  75. package/dist/plugins/adminToken.d.ts +67 -0
  76. package/dist/plugins/adminToken.js +77 -0
  77. package/dist/plugins/adminToken.js.map +1 -0
  78. package/dist/plugins/index.d.ts +0 -7
  79. package/dist/plugins/index.js +0 -16
  80. package/dist/plugins/index.js.map +1 -1
  81. package/dist/plugins/peer_search.d.ts +0 -15
  82. package/dist/plugins/peer_search.js +0 -25
  83. package/dist/plugins/peer_search.js.map +1 -1
  84. package/dist/plugins/plugin_add.d.ts +14 -2
  85. package/dist/plugins/plugin_add.js +42 -13
  86. package/dist/plugins/plugin_add.js.map +1 -1
  87. package/dist/plugins/plugin_docker.d.ts +25 -0
  88. package/dist/plugins/plugin_docker.js +33 -0
  89. package/dist/plugins/plugin_docker.js.map +1 -1
  90. package/dist/plugins/plugin_register.d.ts +0 -10
  91. package/dist/plugins/plugin_register.js +3 -54
  92. package/dist/plugins/plugin_register.js.map +1 -1
  93. package/dist/plugins/plugin_sync.js +45 -22
  94. package/dist/plugins/plugin_sync.js.map +1 -1
  95. package/dist/plugins/plugin_validate.js +47 -13
  96. package/dist/plugins/plugin_validate.js.map +1 -1
  97. package/dist/plugins/store_import.d.ts +0 -9
  98. package/dist/plugins/store_import.js +3 -29
  99. package/dist/plugins/store_import.js.map +1 -1
  100. package/dist/retrieve/task.d.ts +137 -0
  101. package/dist/retrieve/task.js +41 -0
  102. package/dist/retrieve/task.js.map +1 -0
  103. package/dist/retrieve/watch.d.ts +2 -118
  104. package/dist/retrieve/watch.js +452 -321
  105. package/dist/retrieve/watch.js.map +1 -1
  106. package/dist/vfs/providers/etc.d.ts +6 -4
  107. package/dist/vfs/providers/etc.js +12 -4
  108. package/dist/vfs/providers/etc.js.map +1 -1
  109. package/dist/vfs/providers/native.d.ts +116 -39
  110. package/dist/vfs/providers/native.js +291 -347
  111. package/dist/vfs/providers/native.js.map +1 -1
  112. package/dist/vfs/providers/pacs.d.ts +29 -3
  113. package/dist/vfs/providers/pacs.js +303 -73
  114. package/dist/vfs/providers/pacs.js.map +1 -1
  115. package/dist/vfs/providers/pacs_content.js +22 -6
  116. package/dist/vfs/providers/pacs_content.js.map +1 -1
  117. package/dist/vfs/providers/proc/backfill.d.ts +46 -0
  118. package/dist/vfs/providers/proc/backfill.js +147 -0
  119. package/dist/vfs/providers/proc/backfill.js.map +1 -0
  120. package/dist/vfs/providers/proc/book.d.ts +176 -0
  121. package/dist/vfs/providers/proc/book.js +73 -0
  122. package/dist/vfs/providers/proc/book.js.map +1 -0
  123. package/dist/vfs/providers/proc/catchup.d.ts +69 -0
  124. package/dist/vfs/providers/proc/catchup.js +125 -0
  125. package/dist/vfs/providers/proc/catchup.js.map +1 -0
  126. package/dist/vfs/providers/proc/feedIndex.d.ts +146 -0
  127. package/dist/vfs/providers/proc/feedIndex.js +354 -0
  128. package/dist/vfs/providers/proc/feedIndex.js.map +1 -0
  129. package/dist/vfs/providers/proc/feedTopology.d.ts +85 -0
  130. package/dist/vfs/providers/proc/feedTopology.js +192 -0
  131. package/dist/vfs/providers/proc/feedTopology.js.map +1 -0
  132. package/dist/vfs/providers/proc/locate.d.ts +60 -0
  133. package/dist/vfs/providers/proc/locate.js +103 -0
  134. package/dist/vfs/providers/proc/locate.js.map +1 -0
  135. package/dist/vfs/providers/proc/path.d.ts +50 -0
  136. package/dist/vfs/providers/proc/path.js +106 -0
  137. package/dist/vfs/providers/proc/path.js.map +1 -0
  138. package/dist/vfs/providers/proc/roster.d.ts +95 -0
  139. package/dist/vfs/providers/proc/roster.js +425 -0
  140. package/dist/vfs/providers/proc/roster.js.map +1 -0
  141. package/dist/vfs/providers/proc/rows.d.ts +120 -0
  142. package/dist/vfs/providers/proc/rows.js +181 -0
  143. package/dist/vfs/providers/proc/rows.js.map +1 -0
  144. package/dist/vfs/providers/proc/subtree.d.ts +73 -0
  145. package/dist/vfs/providers/proc/subtree.js +125 -0
  146. package/dist/vfs/providers/proc/subtree.js.map +1 -0
  147. package/dist/vfs/providers/proc/sweep.d.ts +89 -0
  148. package/dist/vfs/providers/proc/sweep.js +297 -0
  149. package/dist/vfs/providers/proc/sweep.js.map +1 -0
  150. package/dist/vfs/providers/proc.d.ts +47 -346
  151. package/dist/vfs/providers/proc.js +349 -1806
  152. package/dist/vfs/providers/proc.js.map +1 -1
  153. package/dist/vfs/providers/share.js +4 -1
  154. package/dist/vfs/providers/share.js.map +1 -1
  155. package/package.json +3 -3
  156. package/dist/pacs/resultDecode.d.ts +0 -13
  157. package/dist/pacs/resultDecode.js +0 -19
  158. 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 CUBE-keyed store path without exposing the URL.
14
+ * Builds the identity-keyed store path without exposing the identity.
15
15
  *
16
- * @param cubeUrl - The CUBE API URL the registry belongs to.
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(cubeUrl: string, root?: string): string;
20
+ export declare function pipelinePackagesPath_get(identity: string, root?: string): string;
21
21
  /**
22
- * Restores the store from its durable file for the current CUBE, once per
23
- * key. Missing or invalid files leave the store empty — the sweep refills.
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<void>;
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 CUBE URL. The sweep
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
- const index_js_1 = require("../context/index.js");
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 = 1;
37
+ const PACKAGES_SCHEMA = 2;
31
38
  /** The in-memory store, keyed by pipeline id. */
32
39
  const packages = new Map();
33
- /** The CUBE key the store was restored for; a different CUBE resets it. */
34
- let restoredKey = null;
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
- const cacheHome = process.env['XDG_CACHE_HOME'] ?? (0, path_1.join)((0, os_1.homedir)(), '.cache');
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 CUBE-keyed store path without exposing the URL.
55
+ * Builds the identity-keyed store path without exposing the identity.
42
56
  *
43
- * @param cubeUrl - The CUBE API URL the registry belongs to.
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(cubeUrl, root = packagesRoot_get()) {
48
- const key = (0, crypto_1.createHash)('sha256').update(cubeUrl).digest('hex').slice(0, 16);
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
- /** Resolves the current CUBE's store key, or null when disconnected. */
52
- async function storeKey_get() {
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
- const context = await (0, index_js_1.context_getSingle)();
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
- * Restores the store from its durable file for the current CUBE, once per
74
- * key. Missing or invalid files leave the store empty — the sweep refills.
136
+ * Reads an identity's durable file.
75
137
  *
76
- * @param root - Store directory override (tests).
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 pipelinePackages_restore(root = packagesRoot_get()) {
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 raw = await fs_1.promises.readFile(pipelinePackagesPath_get(key, root), 'utf8');
86
- const parsed = JSON.parse(raw);
87
- const entries = parsed.packages;
88
- if (!Array.isArray(entries))
89
- return;
90
- for (const entry of entries) {
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
- // No file yet, or an unreadable one: the sweep rebuilds it.
152
+ return null;
97
153
  }
98
154
  }
99
155
  /**
100
- * Writes the store durably, atomically, keyed by the current CUBE.
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 key - The CUBE URL key.
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
- const path = pipelinePackagesPath_get(key, root);
107
- const temporaryPath = `${path}.${process.pid}.tmp`;
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
- await fs_1.promises.writeFile(temporaryPath, `${JSON.stringify(file)}\n`, { encoding: 'utf8', mode: 0o600 });
115
- await fs_1.promises.rename(temporaryPath, path);
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 key = await storeKey_get();
126
- if (key === null)
127
- return;
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
- /** @returns Every cached package, sorted by name. */
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":";;AAgEA,4DAGC;AA6BD,4DAgBC;AA4BD,wDAgCC;AAGD,oDAIC;AAQD,oDASC;AApMD;;;;;;;;;;;;;GAaG;AACH,mCAAoC;AACpC,2BAAoC;AACpC,2BAA6B;AAC7B,+BAAqC;AACrC,yCAOuB;AAEvB,+CAAuF;AACvF,kDAAwD;AAcxD,wEAAwE;AACxE,MAAM,eAAe,GAAW,CAAC,CAAC;AAElC,iDAAiD;AACjD,MAAM,QAAQ,GAAiC,IAAI,GAAG,EAAE,CAAC;AAEzD,2EAA2E;AAC3E,I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AA,4BAAoB,GAAE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,IAAA,yBAAiB,GAAE,CAAC;AACvF,CAAC;AAED,gGAAgG;AAChG,SAAgB,oBAAoB;IAClC,IAAI,CAAC,cAAc,EAAE;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,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,GAAG,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}