@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
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ /**
3
+ * @file The /proc feed index: the roster's full walk and single-feed reads.
4
+ *
5
+ * Walks the owned-and-shared and the public feed collections into the
6
+ * roster, joining a walk already in flight; ensures what one path needs
7
+ * before the provider answers it; and reads, adopts and judges one feed:
8
+ * its row asked of CUBE live, its jobs' status, whether it has settled and
9
+ * where its delta cursor stands.
10
+ *
11
+ * Key components:
12
+ * - procFeeds_index, procCache_build: the full walk of the feed index.
13
+ * - cache_ensure, cacheFor_ensure: what a whole-tree read, or one path, needs.
14
+ * - procFeed_probe, procFeedAbsent_probe, feedMeta_ensure, procFeed_ensureLoaded: one feed, read and adopted.
15
+ * - arrivalsUnseen_mark, rosterTotal_bump: what an arrival changes.
16
+ * - feedCached_isSettled, feedCursor_derive: one feed's jobs, judged.
17
+ *
18
+ * Typical usage:
19
+ * ```typescript
20
+ * await cacheFor_ensure('/proc/jobs/feed_7');
21
+ * ```
22
+ *
23
+ * Dependencies: `@fnndsc/cumin` (cache, feed and instance list contracts), `./book`, `./rows`,
24
+ * `./feedTopology`, `./catchup`, `./path`.
25
+ *
26
+ * @module
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.procFeeds_index = procFeeds_index;
30
+ exports.procCache_build = procCache_build;
31
+ exports.cache_ensure = cache_ensure;
32
+ exports.cacheFor_ensure = cacheFor_ensure;
33
+ exports.procFeed_ensureLoaded = procFeed_ensureLoaded;
34
+ exports.feedMeta_ensure = feedMeta_ensure;
35
+ exports.procFeed_probe = procFeed_probe;
36
+ exports.arrivalsUnseen_mark = arrivalsUnseen_mark;
37
+ exports.procFeedAbsent_probe = procFeedAbsent_probe;
38
+ exports.feedCached_isSettled = feedCached_isSettled;
39
+ exports.feedCursor_derive = feedCursor_derive;
40
+ const cumin_1 = require("@fnndsc/cumin");
41
+ const book_js_1 = require("./book.js");
42
+ const catchup_js_1 = require("./catchup.js");
43
+ const feedTopology_js_1 = require("./feedTopology.js");
44
+ const path_js_1 = require("./path.js");
45
+ const rows_js_1 = require("./rows.js");
46
+ /**
47
+ * Indexes one complete paginated CUBE feed collection into the shared cache.
48
+ *
49
+ * @param page_fetch - Fetches one page of the collection.
50
+ * @param indexed - The feeds indexed so far, keyed by id; this walk adds to it.
51
+ * @returns The collection's total as the walk latched it, or null when no page carried one.
52
+ *
53
+ * @example
54
+ * const total: number | null = await procFeeds_index((params) => feedsPage_get(client, params), indexed);
55
+ */
56
+ async function procFeeds_index(page_fetch, indexed) {
57
+ let total = null;
58
+ for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => page_fetch({ limit, offset }), { pageSize: book_js_1.PAGE })) {
59
+ total = step.total ?? total;
60
+ for (const feed of step.items) {
61
+ const procFeed = (0, rows_js_1.procFeed_create)(feed);
62
+ indexed.set(procFeed.id, procFeed);
63
+ }
64
+ }
65
+ return total;
66
+ }
67
+ /**
68
+ * Builds the feed index, joining a walk already in flight. A cold boot
69
+ * walks it behind the listening daemon (#1280), so a `/proc` read can
70
+ * arrive before it lands: the read waits on that walk instead of starting
71
+ * a second one.
72
+ *
73
+ * @returns IDs whose topology is new, changed, or currently active.
74
+ *
75
+ * @example
76
+ * const targets: number[] = await procCache_build();
77
+ */
78
+ function procCache_build() {
79
+ // The walk that is joined is the session's own identity's. Work begun under another identity, or done as
80
+ // another user, walks for itself into a tree of its own, and neither joins this one nor is joined.
81
+ if (!(0, cumin_1.identityCache_usable)())
82
+ return procCache_buildRun();
83
+ const book = (0, book_js_1.book_get)();
84
+ if (book.procCacheBuildPromise)
85
+ return book.procCacheBuildPromise;
86
+ const build = procCache_buildRun().finally(() => {
87
+ if (book.procCacheBuildPromise === build)
88
+ book.procCacheBuildPromise = null;
89
+ });
90
+ (0, book_js_1.book_get)().procCacheBuildPromise = build;
91
+ return build;
92
+ }
93
+ /**
94
+ * Builds the feed index (fast). Fetches owned/shared and public feeds with job counters.
95
+ * Instance topology is loaded separately via procTopology_warmup().
96
+ *
97
+ * @returns IDs whose topology is new, changed, or currently active.
98
+ * @throws {Error} When not connected.
99
+ */
100
+ async function procCache_buildRun() {
101
+ const cache = (0, cumin_1.procCache_get)();
102
+ const client = await cumin_1.chrisConnection.client_get();
103
+ if (!client) {
104
+ cumin_1.errorStack.stack_push('error', 'procCache_build: not connected');
105
+ throw new Error('not connected');
106
+ }
107
+ const indexed = new Map();
108
+ const ownedTotal = await procFeeds_index((params) => (0, cumin_1.feedsPage_get)(client, params), indexed);
109
+ // Older CUBEs lack a public-feeds endpoint: the contract answers null
110
+ // without a wire call, and an empty first page ends the index loop.
111
+ const publicBefore = indexed.size;
112
+ let publicTotal = await procFeeds_index(async (params) => (await (0, cumin_1.publicFeedsPage_get)(client, params)) ?? { data: [], totalCount: 0 }, indexed);
113
+ // An empty public walk while the cache already holds public feeds is a
114
+ // failed SOURCE, not an authoritative absence: reconciling against it
115
+ // would amputate every public feed from the roster (and the checkpoint
116
+ // watcher would persist the amputation). Keep what we know and say so.
117
+ if (indexed.size === publicBefore) {
118
+ const knownPublic = cache.feeds_find('').filter((feed) => feed.public);
119
+ if (knownPublic.length > 0) {
120
+ cumin_1.errorStack.stack_push('warning', `proc roster: public-feeds source returned nothing while ${knownPublic.length} public feeds are known; keeping them`);
121
+ for (const feed of knownPublic)
122
+ indexed.set(feed.id, feed);
123
+ // No yardstick from a failed source: the next delta takes what it reads.
124
+ publicTotal = null;
125
+ }
126
+ }
127
+ (0, book_js_1.book_get)().rosterTotals = { owned: ownedTotal, public: publicTotal };
128
+ const knownBefore = new Set(cache.feedIDs_get());
129
+ const reconciliationTargets = cache.feeds_reconcile(Array.from(indexed.values()));
130
+ for (const feedID of reconciliationTargets)
131
+ (0, book_js_1.book_get)().feedVisits.delete(feedID);
132
+ // Feeds the walk brought in — created since, or shared to this identity —
133
+ // are annunciated; a first build has no "before", so nothing arrives.
134
+ if (knownBefore.size > 0) {
135
+ const arrived = Array.from(indexed.keys()).filter((feedID) => !knownBefore.has(feedID));
136
+ cache.arrivals_note(arrived);
137
+ await arrivalsUnseen_mark(cache, arrived);
138
+ }
139
+ cache.built_set();
140
+ (0, book_js_1.book_get)().rosterWalkedAt = Date.now();
141
+ // The feeds this walk leaves without topology — arrivals, and a restored
142
+ // roster's feeds whose shards were never written — land behind the prompt.
143
+ (0, catchup_js_1.procTopologyCatchup_roster)(cache);
144
+ return reconciliationTargets;
145
+ }
146
+ /**
147
+ * Ensures the feed index is built, building it on first access.
148
+ *
149
+ * @example
150
+ * await cache_ensure();
151
+ */
152
+ async function cache_ensure() {
153
+ if (!(0, cumin_1.procCache_get)().built) {
154
+ await procCache_build();
155
+ }
156
+ }
157
+ /**
158
+ * Ensures what one path needs. `/proc/jobs` itself needs the whole index. A
159
+ * path naming one feed needs that feed alone: its row is read and kept while
160
+ * the index builds on behind, so a fresh session's `ls /proc/jobs/feed_N` (or
161
+ * a `cd` into its `data`) answers in that feed's time, not every feed's
162
+ * (#1364: minutes before the first line, with the index warming).
163
+ *
164
+ * @param pathStr - The path asked for.
165
+ *
166
+ * @example
167
+ * await cacheFor_ensure('/proc/jobs/feed_7');
168
+ */
169
+ async function cacheFor_ensure(pathStr) {
170
+ const cache = (0, cumin_1.procCache_get)();
171
+ if (cache.built)
172
+ return;
173
+ const { feedID } = (0, path_js_1.procPath_parse)(pathStr.replace(/\/$/, ''));
174
+ if (feedID === null) {
175
+ await cache_ensure();
176
+ return;
177
+ }
178
+ // The index lands behind the prompt; this read does not wait for it.
179
+ procCache_build().catch(() => { });
180
+ if (cache.feed_get(feedID) !== undefined)
181
+ return;
182
+ const client = await cumin_1.chrisConnection.client_get();
183
+ if (!client)
184
+ return;
185
+ const row = await (0, rows_js_1.feedRow_fetch)(client, feedID);
186
+ if (row !== null)
187
+ cache.feed_add((0, rows_js_1.procFeed_create)(row.feed));
188
+ }
189
+ /**
190
+ * Ensures instance topology is loaded for a feed without clearing existing data.
191
+ * Use this from proc find — it respects already-loaded feeds and the in-flight map.
192
+ * Use procCache_refresh(feedID) only when a forced reload is desired.
193
+ */
194
+ async function procFeed_ensureLoaded(feedID) {
195
+ const cache = (0, cumin_1.procCache_get)();
196
+ if (!cache.feed_get(feedID)) {
197
+ cache.feed_add({
198
+ id: feedID, title: `feed_${feedID}`, ownerUsername: '', public: false, creationDate: '',
199
+ finishedJobs: 0, erroredJobs: 0, startedJobs: 0,
200
+ scheduledJobs: 0, cancelledJobs: 0, createdJobs: 0,
201
+ });
202
+ }
203
+ await (0, feedTopology_js_1.feedInstances_ensureLoaded)(feedID);
204
+ }
205
+ /**
206
+ * Ensures a feed's metadata (title + job counters, needed for aggregate status) is cached
207
+ * with real values. No-op when the feed is already present with real metadata; fetches one
208
+ * `getFeeds({id})` only when the feed is missing or a zero-counter placeholder. Does NOT
209
+ * touch instance topology — reuse of the warm cache is the whole point.
210
+ *
211
+ * @param feedID - Feed whose metadata to ensure.
212
+ */
213
+ async function feedMeta_ensure(feedID) {
214
+ const cache = (0, cumin_1.procCache_get)();
215
+ const existing = cache.feed_get(feedID);
216
+ if (existing && existing.creationDate !== '')
217
+ return;
218
+ await procFeed_probe(feedID);
219
+ }
220
+ /**
221
+ * Asks CUBE for one feed, live, and adopts it into the roster: the way a
222
+ * feed shared to this identity, or made public, since the roster was
223
+ * walked is seen when it is asked for by name or id. A feed the roster
224
+ * already holds has its row refreshed. The yardsticks move with an
225
+ * adoption, so the next delta does not walk again for what this ask found.
226
+ *
227
+ * @param feedID - The feed to ask for.
228
+ * @returns The feed as the roster now holds it, or null when CUBE lists it
229
+ * in neither collection for this identity — not shared, or shared to a
230
+ * group the identity is not in.
231
+ * @throws {Error} When not connected.
232
+ */
233
+ async function procFeed_probe(feedID) {
234
+ const cache = (0, cumin_1.procCache_get)();
235
+ const client = await cumin_1.chrisConnection.client_get();
236
+ if (!client)
237
+ throw new Error('not connected');
238
+ const row = await (0, rows_js_1.feedRow_fetch)(client, feedID);
239
+ if (row === null)
240
+ return null;
241
+ const feed = (0, rows_js_1.procFeed_create)(row.feed);
242
+ const known = cache.feed_get(feedID) !== undefined;
243
+ cache.feed_add(feed);
244
+ if (!known) {
245
+ rosterTotal_bump(row.collection);
246
+ // A public feed is in the public collection whichever one listed it first.
247
+ if (feed.public && row.collection === 'owned')
248
+ rosterTotal_bump('public');
249
+ cache.arrivals_note([feedID]);
250
+ await arrivalsUnseen_mark(cache, [feedID]);
251
+ (0, catchup_js_1.procTopologyCatchup_enqueue)([feedID]);
252
+ }
253
+ return feed;
254
+ }
255
+ /**
256
+ * Marks arrivals shared with this identity as NEW since the last visit: a
257
+ * feed another identity owns and has not made public. A feed this
258
+ * identity made is not news to it, and a public feed anyone on CUBE made
259
+ * is not addressed to it; neither is marked.
260
+ *
261
+ * @param cache - The process cache.
262
+ * @param feedIDs - The feeds that just arrived.
263
+ *
264
+ * @example
265
+ * await arrivalsUnseen_mark(cache, [7]);
266
+ */
267
+ async function arrivalsUnseen_mark(cache, feedIDs) {
268
+ if (feedIDs.length === 0)
269
+ return;
270
+ // Who this identity is decides what is news; not knowing, nothing is marked.
271
+ let me = null;
272
+ try {
273
+ me = await cumin_1.chrisConnection.user_get();
274
+ }
275
+ catch {
276
+ return;
277
+ }
278
+ if (me === null)
279
+ return;
280
+ cache.unseen_add(feedIDs.filter((feedID) => {
281
+ const feed = cache.feed_get(feedID);
282
+ return feed !== undefined && !feed.public && feed.ownerUsername !== '' && feed.ownerUsername !== me;
283
+ }));
284
+ }
285
+ /**
286
+ * Asks CUBE for a feed the roster lacks, on a visit to its path, and says
287
+ * on the error stack when the ask itself failed; an absent feed is a null.
288
+ *
289
+ * @param feedID - The feed to ask for.
290
+ * @returns The adopted feed, or null.
291
+ *
292
+ * @example
293
+ * const feed: ProcFeed | null = await procFeedAbsent_probe(7);
294
+ */
295
+ async function procFeedAbsent_probe(feedID) {
296
+ try {
297
+ return await procFeed_probe(feedID);
298
+ }
299
+ catch (error) {
300
+ const msg = error instanceof Error ? error.message : String(error);
301
+ cumin_1.errorStack.stack_push('warning', `proc: asking CUBE for feed_${feedID} failed (${msg})`);
302
+ return null;
303
+ }
304
+ }
305
+ /**
306
+ * Moves one collection's yardstick by one adopted feed; an unknown yardstick stays unknown.
307
+ *
308
+ * @param collection - The collection that gained the feed.
309
+ */
310
+ function rosterTotal_bump(collection) {
311
+ const total = (0, book_js_1.book_get)().rosterTotals[collection];
312
+ if (total !== null)
313
+ (0, book_js_1.book_get)().rosterTotals[collection] = total + 1;
314
+ }
315
+ /**
316
+ * Whether every cached instance of a feed carries a terminal status. A fully
317
+ * settled feed can only change by having work appended to it, which the
318
+ * feed-row counters reveal.
319
+ *
320
+ * @param cache - The process cache.
321
+ * @param feedID - The feed to inspect.
322
+ * @returns True when no cached instance could still change status.
323
+ */
324
+ function feedCached_isSettled(cache, feedID) {
325
+ for (const id of cache.feedInstanceIDs_get(feedID)) {
326
+ const inst = cache.instance_get(id);
327
+ if (inst === undefined || !(0, cumin_1.status_isTerminal)(inst.status))
328
+ return false;
329
+ }
330
+ return true;
331
+ }
332
+ /**
333
+ * Derives a feed's delta cursor from what the cache already holds: the newest
334
+ * start or end timestamp across its instances.
335
+ *
336
+ * @param cache - The process cache.
337
+ * @param feedID - The feed whose rows to scan.
338
+ * @returns The newest timestamp, or null when no row carried one.
339
+ *
340
+ * @example
341
+ * const cursor: string | null = feedCursor_derive(cache, 7);
342
+ */
343
+ function feedCursor_derive(cache, feedID) {
344
+ let newest = null;
345
+ for (const id of cache.feedInstanceIDs_get(feedID)) {
346
+ const inst = cache.instance_get(id);
347
+ if (!inst)
348
+ continue;
349
+ newest = (0, rows_js_1.isoNewest_pick)(newest, inst.startedAt);
350
+ newest = (0, rows_js_1.isoNewest_pick)(newest, inst.finishedAt);
351
+ }
352
+ return newest;
353
+ }
354
+ //# sourceMappingURL=feedIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedIndex.js","sourceRoot":"","sources":["../../../../src/vfs/providers/proc/feedIndex.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAkCH,0CAaC;AAaD,0CAWC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,CAAC,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,GAAG,IAAA,wBAAc,EAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,GAAG,IAAA,wBAAc,EAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @file One feed's jobs: reading a feed's topology into the /proc cache.
3
+ *
4
+ * Walks one feed's plugin instances into ProcCache, off the session's lane
5
+ * and deduped by the cache's in-flight map; evicts a feed for a re-walk;
6
+ * and resolves a job's output folder, which the feed's data facts read.
7
+ *
8
+ * Key components:
9
+ * - feedInstances_ensureStarted, feedInstances_ensureLoaded: a feed's topology, started or awaited.
10
+ * - FeedTopologyReadiness: whether it is in the cache or on its way.
11
+ * - procFeed_evict, procFeed_refreshStart: forget a feed's topology and re-walk it.
12
+ * - instanceOutputPath_ensure: one job's output folder, memoized.
13
+ * - dataFactsIO_get: the data-facts reader over those output folders.
14
+ *
15
+ * Typical usage:
16
+ * ```typescript
17
+ * if (feedInstances_ensureStarted(feedID) === 'pending') return 'pending';
18
+ * ```
19
+ *
20
+ * Dependencies: `@fnndsc/cumin` (cache, instance list contract), `../../../dag/feedData`
21
+ * (data facts), `./book`, `./rows`.
22
+ *
23
+ * @module
24
+ */
25
+ import { type DataFactsIO } from '../../../dag/feedData.js';
26
+ /** Whether a feed's topology is in the cache, or still on its way. */
27
+ export type FeedTopologyReadiness = 'ready' | 'pending';
28
+ /**
29
+ * Ensures a feed's topology walk is at least under way, without waiting for
30
+ * it. Index movement never holds the session's lane: a cold feed's walk is
31
+ * started here and runs detached, deduped by the in-flight map, annunciated
32
+ * by the load register, and committed to the cache when it lands (which
33
+ * emits the feed's change event, the signal a watch answers).
34
+ *
35
+ * @param feedID - The feed whose topology is wanted.
36
+ * @returns `ready` when the cache has it, `pending` when a walk is running.
37
+ */
38
+ export declare function feedInstances_ensureStarted(feedID: number): FeedTopologyReadiness;
39
+ /**
40
+ * Drops one feed's topology from the cache and re-reads its row (job
41
+ * counters), so the next walk starts from nothing the cache remembers
42
+ * about the graph. The roster row STAYS: a feed the identity sees through
43
+ * the public listing is not in the own-feeds endpoint, and a refresh that
44
+ * removed the row and could not re-read it left the feed "not found".
45
+ *
46
+ * @param feedID - The feed to evict.
47
+ *
48
+ * @example
49
+ * await procFeed_evict(7);
50
+ */
51
+ export declare function procFeed_evict(feedID: number): Promise<void>;
52
+ /**
53
+ * The operator's `proc refresh <feed>`: evicts the feed and STARTS its
54
+ * re-walk. The walk is index movement, finished off the lane; the caller
55
+ * answers `pending` and the prompt carries the count.
56
+ *
57
+ * @param feedID - The feed to re-index.
58
+ * @returns `pending` while the walk runs (always, right after an eviction).
59
+ */
60
+ export declare function procFeed_refreshStart(feedID: number): Promise<FeedTopologyReadiness>;
61
+ /**
62
+ * Ensures topology for a feed is loaded.
63
+ * Per-feed loads proceed immediately even while the global sweep is running —
64
+ * instance_add is idempotent so concurrent additions are safe.
65
+ */
66
+ export declare function feedInstances_ensureLoaded(feedID: number): Promise<void>;
67
+ /**
68
+ * Resolves and memoizes the authoritative CFS output directory for one job.
69
+ *
70
+ * @param instanceID - Plugin-instance ID whose output path is needed.
71
+ * @returns Absolute output path, or null when CUBE has not recorded one.
72
+ *
73
+ * @example
74
+ * const outputPath: string | null = await instanceOutputPath_ensure(12);
75
+ */
76
+ export declare function instanceOutputPath_ensure(instanceID: number): Promise<string | null>;
77
+ /**
78
+ * The data-facts reader, with this tree's output paths.
79
+ *
80
+ * @returns The reader over each job's output folder.
81
+ *
82
+ * @example
83
+ * void procDataFacts_feed(feedID, dataFactsIO_get());
84
+ */
85
+ export declare function dataFactsIO_get(): DataFactsIO;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ /**
3
+ * @file One feed's jobs: reading a feed's topology into the /proc cache.
4
+ *
5
+ * Walks one feed's plugin instances into ProcCache, off the session's lane
6
+ * and deduped by the cache's in-flight map; evicts a feed for a re-walk;
7
+ * and resolves a job's output folder, which the feed's data facts read.
8
+ *
9
+ * Key components:
10
+ * - feedInstances_ensureStarted, feedInstances_ensureLoaded: a feed's topology, started or awaited.
11
+ * - FeedTopologyReadiness: whether it is in the cache or on its way.
12
+ * - procFeed_evict, procFeed_refreshStart: forget a feed's topology and re-walk it.
13
+ * - instanceOutputPath_ensure: one job's output folder, memoized.
14
+ * - dataFactsIO_get: the data-facts reader over those output folders.
15
+ *
16
+ * Typical usage:
17
+ * ```typescript
18
+ * if (feedInstances_ensureStarted(feedID) === 'pending') return 'pending';
19
+ * ```
20
+ *
21
+ * Dependencies: `@fnndsc/cumin` (cache, instance list contract), `../../../dag/feedData`
22
+ * (data facts), `./book`, `./rows`.
23
+ *
24
+ * @module
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.feedInstances_ensureStarted = feedInstances_ensureStarted;
28
+ exports.procFeed_evict = procFeed_evict;
29
+ exports.procFeed_refreshStart = procFeed_refreshStart;
30
+ exports.feedInstances_ensureLoaded = feedInstances_ensureLoaded;
31
+ exports.instanceOutputPath_ensure = instanceOutputPath_ensure;
32
+ exports.dataFactsIO_get = dataFactsIO_get;
33
+ const cumin_1 = require("@fnndsc/cumin");
34
+ const book_js_1 = require("./book.js");
35
+ const rows_js_1 = require("./rows.js");
36
+ const feedData_js_1 = require("../../../dag/feedData.js");
37
+ /**
38
+ * Loads instance topology for a single feed: every page of its instance
39
+ * listing, committed to the cache as a whole when the walk lands.
40
+ *
41
+ * @param feedID - The feed to walk.
42
+ * @throws {Error} When not connected, or when a page fails.
43
+ */
44
+ async function feedInstances_load(feedID) {
45
+ const cache = (0, cumin_1.procCache_get)();
46
+ const client = await cumin_1.chrisConnection.client_get();
47
+ if (!client)
48
+ throw new Error('not connected');
49
+ const instances = new Map();
50
+ // A first visit to a large feed is a page walk of a minute or more; the
51
+ // prompt and the status strip carry its progress so it never reads as a
52
+ // hang. The register is cleared on every exit, including failure.
53
+ cache.feedLoad_progress(feedID, 0, 0);
54
+ try {
55
+ // Several pages in flight: the rows are keyed by id and committed as a
56
+ // whole when the walk lands, so the order pages arrive in is nothing
57
+ // to this consumer, and the walk is as long as the slowest page in
58
+ // each window rather than the sum of every page.
59
+ for await (const step of (0, cumin_1.listPages_walkWindowed)((offset, limit) => (0, cumin_1.pluginInstancesPage_get)(client, { feed_id: feedID, limit, offset }), { pageSize: book_js_1.PAGE, inFlight: book_js_1.FEED_WALK_IN_FLIGHT })) {
60
+ for (const instance of step.items)
61
+ instances.set(Number(instance.id), instance);
62
+ cache.feedLoad_progress(feedID, instances.size, step.total ?? 0);
63
+ }
64
+ for (const inst of instances.values())
65
+ cache.instance_add((0, rows_js_1.procInstance_buildFromRow)(inst));
66
+ cache.topologyLoaded_mark(feedID);
67
+ cache.feedLoad_clear(feedID);
68
+ // What the feed's data is: read once, now its root is known.
69
+ void (0, feedData_js_1.procDataFacts_feed)(feedID, dataFactsIO_get());
70
+ }
71
+ catch (error) {
72
+ // A walk that stops names where it stopped and stays annunciated for a
73
+ // minute; the next visit starts again from the beginning.
74
+ cache.feedLoad_fail(feedID, error instanceof Error ? error.message : String(error));
75
+ throw error;
76
+ }
77
+ }
78
+ /**
79
+ * Ensures a feed's topology walk is at least under way, without waiting for
80
+ * it. Index movement never holds the session's lane: a cold feed's walk is
81
+ * started here and runs detached, deduped by the in-flight map, annunciated
82
+ * by the load register, and committed to the cache when it lands (which
83
+ * emits the feed's change event, the signal a watch answers).
84
+ *
85
+ * @param feedID - The feed whose topology is wanted.
86
+ * @returns `ready` when the cache has it, `pending` when a walk is running.
87
+ */
88
+ function feedInstances_ensureStarted(feedID) {
89
+ const cache = (0, cumin_1.procCache_get)();
90
+ if (cache.topologyLoaded_has(feedID))
91
+ return 'ready';
92
+ if (cache.loading_get(feedID) !== undefined)
93
+ return 'pending';
94
+ const walk = feedInstances_load(feedID);
95
+ cache.loading_set(feedID, walk);
96
+ walk
97
+ .catch(() => { })
98
+ .finally(() => { cache.loading_clear(feedID); });
99
+ return 'pending';
100
+ }
101
+ /**
102
+ * Drops one feed's topology from the cache and re-reads its row (job
103
+ * counters), so the next walk starts from nothing the cache remembers
104
+ * about the graph. The roster row STAYS: a feed the identity sees through
105
+ * the public listing is not in the own-feeds endpoint, and a refresh that
106
+ * removed the row and could not re-read it left the feed "not found".
107
+ *
108
+ * @param feedID - The feed to evict.
109
+ *
110
+ * @example
111
+ * await procFeed_evict(7);
112
+ */
113
+ async function procFeed_evict(feedID) {
114
+ const cache = (0, cumin_1.procCache_get)();
115
+ (0, book_js_1.book_get)().feedVisits.delete(feedID);
116
+ cache.feedTopology_evict(feedID);
117
+ const client = await cumin_1.chrisConnection.client_get();
118
+ if (!client)
119
+ return;
120
+ const row = await (0, rows_js_1.feedRow_fetch)(client, feedID);
121
+ if (row)
122
+ cache.feed_add((0, rows_js_1.procFeed_create)(row.feed));
123
+ }
124
+ /**
125
+ * The operator's `proc refresh <feed>`: evicts the feed and STARTS its
126
+ * re-walk. The walk is index movement, finished off the lane; the caller
127
+ * answers `pending` and the prompt carries the count.
128
+ *
129
+ * @param feedID - The feed to re-index.
130
+ * @returns `pending` while the walk runs (always, right after an eviction).
131
+ */
132
+ async function procFeed_refreshStart(feedID) {
133
+ await procFeed_evict(feedID);
134
+ return feedInstances_ensureStarted(feedID);
135
+ }
136
+ /**
137
+ * Ensures topology for a feed is loaded.
138
+ * Per-feed loads proceed immediately even while the global sweep is running —
139
+ * instance_add is idempotent so concurrent additions are safe.
140
+ */
141
+ async function feedInstances_ensureLoaded(feedID) {
142
+ const cache = (0, cumin_1.procCache_get)();
143
+ if (feedInstances_ensureStarted(feedID) === 'ready')
144
+ return;
145
+ const inflight = cache.loading_get(feedID);
146
+ if (inflight)
147
+ await inflight;
148
+ }
149
+ /**
150
+ * Resolves and memoizes the authoritative CFS output directory for one job.
151
+ *
152
+ * @param instanceID - Plugin-instance ID whose output path is needed.
153
+ * @returns Absolute output path, or null when CUBE has not recorded one.
154
+ *
155
+ * @example
156
+ * const outputPath: string | null = await instanceOutputPath_ensure(12);
157
+ */
158
+ async function instanceOutputPath_ensure(instanceID) {
159
+ const cache = (0, cumin_1.procCache_get)();
160
+ const inst = cache.instance_get(instanceID);
161
+ if (!inst)
162
+ return null;
163
+ if (inst.outputPath !== undefined)
164
+ return inst.outputPath;
165
+ const client = await cumin_1.chrisConnection.client_get();
166
+ if (!client)
167
+ return null;
168
+ try {
169
+ const handle = await (0, cumin_1.pluginInstance_get)(client, instanceID);
170
+ const outputPath = (0, rows_js_1.outputPath_normalize)(handle?.data?.output_path);
171
+ cache.outputPath_update(instanceID, outputPath);
172
+ return outputPath;
173
+ }
174
+ catch (error) {
175
+ // "No CFS output path" downstream must not mask a failed fetch.
176
+ const msg = error instanceof Error ? error.message : String(error);
177
+ cumin_1.errorStack.stack_push("warning", `Could not fetch output path for instance ${instanceID}: ${msg}`);
178
+ return null;
179
+ }
180
+ }
181
+ /**
182
+ * The data-facts reader, with this tree's output paths.
183
+ *
184
+ * @returns The reader over each job's output folder.
185
+ *
186
+ * @example
187
+ * void procDataFacts_feed(feedID, dataFactsIO_get());
188
+ */
189
+ function dataFactsIO_get() {
190
+ return (0, feedData_js_1.dataFactsIO_build)(instanceOutputPath_ensure);
191
+ }
192
+ //# sourceMappingURL=feedTopology.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedTopology.js","sourceRoot":"","sources":["../../../../src/vfs/providers/proc/feedTopology.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AA4EH,kEAUC;AAcD,wCAQC;AAUD,sDAGC;AAOD,gEAKC;AAWD,8DAmBC;AAUD,0CAEC;AA7KD,yCAYuB;AAEvB,uCAAgE;AAChE,uCAA0H;AAC1H,0DAAmG;AAEnG;;;;;;GAMG;AACH,KAAK,UAAU,kBAAkB,CAAC,MAAc;IAC9C,MAAM,KAAK,GAAc,IAAA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