@fnndsc/cumin 3.30.6 → 3.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/cache/checkpointWatch.d.ts +36 -0
  2. package/dist/cache/checkpointWatch.js +83 -0
  3. package/dist/cache/checkpointWatch.js.map +1 -0
  4. package/dist/cache/index.d.ts +1 -1
  5. package/dist/cache/index.js +4 -1
  6. package/dist/cache/index.js.map +1 -1
  7. package/dist/cache/listCache.d.ts +54 -2
  8. package/dist/cache/listCache.js +120 -24
  9. package/dist/cache/listCache.js.map +1 -1
  10. package/dist/cache/listCheckpoint.d.ts +5 -8
  11. package/dist/cache/listCheckpoint.js +17 -28
  12. package/dist/cache/listCheckpoint.js.map +1 -1
  13. package/dist/cache/listingInvalidation.js +11 -6
  14. package/dist/cache/listingInvalidation.js.map +1 -1
  15. package/dist/cache/procCache.d.ts +11 -0
  16. package/dist/cache/procCache.js +26 -1
  17. package/dist/cache/procCache.js.map +1 -1
  18. package/dist/cache/procCheckpoint.d.ts +11 -6
  19. package/dist/cache/procCheckpoint.js +280 -86
  20. package/dist/cache/procCheckpoint.js.map +1 -1
  21. package/dist/cache/queryIndex.d.ts +11 -0
  22. package/dist/cache/queryIndex.js +38 -2
  23. package/dist/cache/queryIndex.js.map +1 -1
  24. package/dist/cache/queryIndexCheckpoint.d.ts +32 -0
  25. package/dist/cache/queryIndexCheckpoint.js +180 -30
  26. package/dist/cache/queryIndexCheckpoint.js.map +1 -1
  27. package/dist/chrisapi/adapter.d.ts +266 -37
  28. package/dist/chrisapi/adapter.js +577 -116
  29. package/dist/chrisapi/adapter.js.map +1 -1
  30. package/dist/chrisapi/contract.d.ts +20 -20
  31. package/dist/chrisapi/contract.js +213 -60
  32. package/dist/chrisapi/contract.js.map +1 -1
  33. package/dist/chrisapi/cubeRequest.d.ts +198 -0
  34. package/dist/chrisapi/cubeRequest.js +345 -0
  35. package/dist/chrisapi/cubeRequest.js.map +1 -0
  36. package/dist/chrisapi/shape.d.ts +186 -0
  37. package/dist/chrisapi/shape.js +274 -0
  38. package/dist/chrisapi/shape.js.map +1 -0
  39. package/dist/cli.js +2 -1
  40. package/dist/cli.js.map +1 -1
  41. package/dist/compute/computeResources.d.ts +3 -0
  42. package/dist/compute/computeResources.js +5 -3
  43. package/dist/compute/computeResources.js.map +1 -1
  44. package/dist/config/config.d.ts +14 -0
  45. package/dist/config/config.js +6 -3
  46. package/dist/config/config.js.map +1 -1
  47. package/dist/connect/chrisConnection.d.ts +116 -6
  48. package/dist/connect/chrisConnection.js +418 -74
  49. package/dist/connect/chrisConnection.js.map +1 -1
  50. package/dist/connect/identityEpoch.d.ts +263 -0
  51. package/dist/connect/identityEpoch.js +414 -0
  52. package/dist/connect/identityEpoch.js.map +1 -0
  53. package/dist/connect/loginFailure.js +39 -22
  54. package/dist/connect/loginFailure.js.map +1 -1
  55. package/dist/context/chrisContext.js +36 -30
  56. package/dist/context/chrisContext.js.map +1 -1
  57. package/dist/error/errorStack.d.ts +1 -1
  58. package/dist/error/errorStack.js +1 -2
  59. package/dist/error/errorStack.js.map +1 -1
  60. package/dist/feeds/chrisAccess.d.ts +7 -2
  61. package/dist/feeds/chrisAccess.js +20 -7
  62. package/dist/feeds/chrisAccess.js.map +1 -1
  63. package/dist/feeds/chrisFeed.d.ts +8 -10
  64. package/dist/feeds/chrisFeed.js +27 -57
  65. package/dist/feeds/chrisFeed.js.map +1 -1
  66. package/dist/feeds/chrisTags.d.ts +1 -1
  67. package/dist/feeds/chrisTags.js +66 -24
  68. package/dist/feeds/chrisTags.js.map +1 -1
  69. package/dist/filebrowser/chrisFileBrowser.d.ts +0 -1
  70. package/dist/filebrowser/chrisFileBrowser.js +3 -5
  71. package/dist/filebrowser/chrisFileBrowser.js.map +1 -1
  72. package/dist/filebrowser/chrisFiles.d.ts +0 -1
  73. package/dist/filebrowser/chrisFiles.js +3 -4
  74. package/dist/filebrowser/chrisFiles.js.map +1 -1
  75. package/dist/filebrowser/chrisPACS.d.ts +4 -4
  76. package/dist/filebrowser/chrisPACS.js +10 -33
  77. package/dist/filebrowser/chrisPACS.js.map +1 -1
  78. package/dist/filebrowser/chrisPipeline.js +10 -45
  79. package/dist/filebrowser/chrisPipeline.js.map +1 -1
  80. package/dist/groups/chrisGroups.d.ts +3 -0
  81. package/dist/groups/chrisGroups.js +20 -8
  82. package/dist/groups/chrisGroups.js.map +1 -1
  83. package/dist/index.d.ts +6 -8
  84. package/dist/index.js +17 -28
  85. package/dist/index.js.map +1 -1
  86. package/dist/io/chrisIO.d.ts +81 -42
  87. package/dist/io/chrisIO.js +176 -325
  88. package/dist/io/chrisIO.js.map +1 -1
  89. package/dist/io/holderClient.d.ts +248 -0
  90. package/dist/io/holderClient.js +289 -0
  91. package/dist/io/holderClient.js.map +1 -0
  92. package/dist/io/holderFolder.d.ts +151 -0
  93. package/dist/io/holderFolder.js +311 -0
  94. package/dist/io/holderFolder.js.map +1 -0
  95. package/dist/io/holderIO.d.ts +258 -0
  96. package/dist/io/holderIO.js +557 -0
  97. package/dist/io/holderIO.js.map +1 -0
  98. package/dist/io/holderRequest.d.ts +299 -0
  99. package/dist/io/holderRequest.js +447 -0
  100. package/dist/io/holderRequest.js.map +1 -0
  101. package/dist/io/holderUpload.d.ts +62 -0
  102. package/dist/io/holderUpload.js +81 -0
  103. package/dist/io/holderUpload.js.map +1 -0
  104. package/dist/io/io.d.ts +12 -0
  105. package/dist/io/io.js.map +1 -1
  106. package/dist/io/localUpload.d.ts +59 -0
  107. package/dist/io/localUpload.js +150 -0
  108. package/dist/io/localUpload.js.map +1 -0
  109. package/dist/io/node_io.d.ts +16 -0
  110. package/dist/io/node_io.js +72 -0
  111. package/dist/io/node_io.js.map +1 -1
  112. package/dist/io/streamWatch.js +2 -2
  113. package/dist/io/streamWatch.js.map +1 -1
  114. package/dist/io/transferPool.d.ts +18 -2
  115. package/dist/io/transferPool.js +32 -7
  116. package/dist/io/transferPool.js.map +1 -1
  117. package/dist/pacs/chrisPACS.d.ts +3 -9
  118. package/dist/pacs/chrisPACS.js +102 -61
  119. package/dist/pacs/chrisPACS.js.map +1 -1
  120. package/dist/pacs/queryIndexSweep.d.ts +0 -9
  121. package/dist/pacs/queryIndexSweep.js +45 -41
  122. package/dist/pacs/queryIndexSweep.js.map +1 -1
  123. package/dist/path/chrisPath.d.ts +8 -3
  124. package/dist/path/chrisPath.js +10 -9
  125. package/dist/path/chrisPath.js.map +1 -1
  126. package/dist/pipelines/chrisPipeline.d.ts +28 -5
  127. package/dist/pipelines/chrisPipeline.js +270 -94
  128. package/dist/pipelines/chrisPipeline.js.map +1 -1
  129. package/dist/pipelines/pipelineMemo.d.ts +0 -16
  130. package/dist/pipelines/pipelineMemo.js +0 -27
  131. package/dist/pipelines/pipelineMemo.js.map +1 -1
  132. package/dist/plugins/chrisPlugins.d.ts +9 -5
  133. package/dist/plugins/chrisPlugins.js +97 -58
  134. package/dist/plugins/chrisPlugins.js.map +1 -1
  135. package/dist/resources/chrisObjContext.d.ts +7 -11
  136. package/dist/resources/chrisObjContext.js +7 -42
  137. package/dist/resources/chrisObjContext.js.map +1 -1
  138. package/dist/resources/chrisResources.d.ts +186 -74
  139. package/dist/resources/chrisResources.js +421 -117
  140. package/dist/resources/chrisResources.js.map +1 -1
  141. package/dist/resources/resourceShapes.d.ts +109 -0
  142. package/dist/resources/resourceShapes.js +22 -0
  143. package/dist/resources/resourceShapes.js.map +1 -0
  144. package/dist/users/chrisUsers.d.ts +4 -1
  145. package/dist/users/chrisUsers.js +6 -2
  146. package/dist/users/chrisUsers.js.map +1 -1
  147. package/dist/utils/keypair.js +21 -10
  148. package/dist/utils/keypair.js.map +1 -1
  149. package/package.json +10 -3
  150. package/dist/activities/chrisActivity.d.ts +0 -19
  151. package/dist/activities/chrisActivity.js +0 -29
  152. package/dist/activities/chrisActivity.js.map +0 -1
  153. package/dist/jobs/chrisJob.d.ts +0 -43
  154. package/dist/jobs/chrisJob.js +0 -174
  155. package/dist/jobs/chrisJob.js.map +0 -1
  156. package/dist/jobs/index.d.ts +0 -7
  157. package/dist/jobs/index.js +0 -24
  158. package/dist/jobs/index.js.map +0 -1
  159. package/dist/jobs/jobMonitor.d.ts +0 -46
  160. package/dist/jobs/jobMonitor.js +0 -102
  161. package/dist/jobs/jobMonitor.js.map +0 -1
@@ -0,0 +1,447 @@
1
+ "use strict";
2
+ /**
3
+ * @file CUBE's own address for one thing it holds, and one request there.
4
+ *
5
+ * Every request that acts on a proved holder, or asks after one, goes to an
6
+ * address built here from three things alone: the API root the client was
7
+ * made with, CUBE's route for the kind (CUBE's `core/api.py`), and the
8
+ * proved id. An address a listing row or a search row carried is never
9
+ * asked: it came from a listing, the token goes with every request, and a
10
+ * row whose address names anything else is refused before anything is
11
+ * asked. No request follows a redirect, and none waits longer than
12
+ * chrisapi's own default (30 s).
13
+ *
14
+ * Key components:
15
+ * - StoreKind, StoreHolder: what holds a path, as a proof names it.
16
+ * - itemUrl_build, itemHref_matches, itemHref_refusal: CUBE's address for an item, and a row's address checked against it.
17
+ * - userFilesUrl_build: CUBE's address for a new user file.
18
+ * - folderListUrl_build, folderSearchUrl_build: a folder's own collections, and the search for the folder at a path.
19
+ * - cube_ask: one request, with the client's token, no redirect followed, a deadline held.
20
+ * - answerItem_read, itemFields_read, answerRefusal_read, refusalWords_read, answerList_read: what an answer carries.
21
+ * - itemStatus_probe: what CUBE answers at an item's address.
22
+ *
23
+ * Typical usage:
24
+ * ```ts
25
+ * const url: string | null = itemUrl_build(client, 'file', 41);
26
+ * const answer: CubeAnswer | null = url === null ? null : await cube_ask(client, url, 'GET');
27
+ * ```
28
+ *
29
+ * Dependencies: the chrisapi adapter (the client's token and API root) and
30
+ * the platform's `fetch`.
31
+ *
32
+ * @module
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.REQUEST_TIMEOUT_MS = void 0;
36
+ exports.itemUrl_build = itemUrl_build;
37
+ exports.userFilesUrl_build = userFilesUrl_build;
38
+ exports.folderListUrl_build = folderListUrl_build;
39
+ exports.folderSearchUrl_build = folderSearchUrl_build;
40
+ exports.itemHref_matches = itemHref_matches;
41
+ exports.itemHref_refusal = itemHref_refusal;
42
+ exports.cube_ask = cube_ask;
43
+ exports.answerItem_read = answerItem_read;
44
+ exports.itemFields_read = itemFields_read;
45
+ exports.refusalWords_read = refusalWords_read;
46
+ exports.answerRefusal_read = answerRefusal_read;
47
+ exports.answerList_read = answerList_read;
48
+ exports.itemStatus_probe = itemStatus_probe;
49
+ const adapter_js_1 = require("../chrisapi/adapter.js");
50
+ /** How long one request may take: chrisapi's own default. */
51
+ exports.REQUEST_TIMEOUT_MS = 30000;
52
+ /**
53
+ * Where CUBE acts on one item of a kind, below its API root
54
+ * (`v1/filebrowser/<pk>/`, `v1/userfiles/<pk>/`,
55
+ * `v1/filebrowser/linkfiles/<pk>/`).
56
+ */
57
+ const ITEM_ROUTES = { dir: "filebrowser", file: "userfiles", link: "filebrowser/linkfiles" };
58
+ /**
59
+ * The routes a listing row of a kind may name as its own: the one acted at,
60
+ * and for a file the folder listing's own (`v1/filebrowser/files/<pk>/`),
61
+ * the same file.
62
+ */
63
+ const ROW_ROUTES = {
64
+ dir: ["filebrowser"],
65
+ file: ["userfiles", "filebrowser/files"],
66
+ link: ["filebrowser/linkfiles"],
67
+ };
68
+ /** A kind in an operator's word. */
69
+ const KIND_WORDS = { dir: "folder", file: "file", link: "link" };
70
+ /**
71
+ * An address below the client's API root, for one id.
72
+ *
73
+ * @param client - The client.
74
+ * @param route - The route, below the root.
75
+ * @param id - The id.
76
+ * @returns The address, or null for an id that is not a positive whole number or a client with no usable root.
77
+ */
78
+ function routeUrl_build(client, route, id) {
79
+ if (!Number.isSafeInteger(id) || id <= 0)
80
+ return null;
81
+ const root = (0, adapter_js_1.apiRoot_read)(client);
82
+ return root === null ? null : new URL(`${route}/${String(id)}/`, root).href;
83
+ }
84
+ /**
85
+ * CUBE's own address for one item: the client's API root, the kind's route,
86
+ * and the id.
87
+ *
88
+ * @param client - The client the item was proved with.
89
+ * @param kind - What the item is.
90
+ * @param id - Its id.
91
+ * @returns The address, or null for an id that is not a positive whole number or a client with no usable root.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * itemUrl_build(client, 'link', 5); // 'https://cube/api/v1/filebrowser/linkfiles/5/'
96
+ * ```
97
+ */
98
+ function itemUrl_build(client, kind, id) {
99
+ return routeUrl_build(client, ITEM_ROUTES[kind], id);
100
+ }
101
+ /**
102
+ * CUBE's own address for a new user file: the client's API root and the
103
+ * file route, never the address the root's own answer advertised.
104
+ *
105
+ * @param client - The client the upload is made on.
106
+ * @returns The address, or null for a client with no usable root.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * userFilesUrl_build(client); // 'https://cube/api/v1/userfiles/'
111
+ * ```
112
+ */
113
+ function userFilesUrl_build(client) {
114
+ const root = (0, adapter_js_1.apiRoot_read)(client);
115
+ return root === null ? null : new URL(`${ITEM_ROUTES.file}/`, root).href;
116
+ }
117
+ /**
118
+ * The address of one of a folder's own collections: the folder's address
119
+ * and the collection's name, never the link a row gave. Asked for one row
120
+ * unless a page is named.
121
+ *
122
+ * @param client - The client.
123
+ * @param id - The folder's id.
124
+ * @param list - Which collection.
125
+ * @param page - The page asked for; one row when not given.
126
+ * @returns The address, or null as {@link itemUrl_build}.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * folderListUrl_build(client, 7, 'files'); // 'https://cube/api/v1/filebrowser/7/files/?limit=1'
131
+ * ```
132
+ */
133
+ function folderListUrl_build(client, id, list, page = { limit: 1 }) {
134
+ const folder = itemUrl_build(client, "dir", id);
135
+ if (folder === null)
136
+ return null;
137
+ const url = new URL(`${list}/`, folder);
138
+ url.searchParams.set("limit", String(page.limit));
139
+ if (page.offset !== undefined)
140
+ url.searchParams.set("offset", String(page.offset));
141
+ return url.href;
142
+ }
143
+ /**
144
+ * The address of CUBE's search for the folder at one path.
145
+ *
146
+ * @param client - The client.
147
+ * @param folderPath - The folder's path, as a proof spells it.
148
+ * @returns The address, or null for a client with no usable root.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * folderSearchUrl_build(client, '/home/ada'); // 'https://cube/api/v1/filebrowser/search/?path=%2Fhome%2Fada'
153
+ * ```
154
+ */
155
+ function folderSearchUrl_build(client, folderPath) {
156
+ const root = (0, adapter_js_1.apiRoot_read)(client);
157
+ if (root === null)
158
+ return null;
159
+ const url = new URL("filebrowser/search/", root);
160
+ url.searchParams.set("path", folderPath);
161
+ return url.href;
162
+ }
163
+ /**
164
+ * Whether an address a listing gave is CUBE's own for an item: the client's
165
+ * origin, and exactly one of the kind's routes for that id, with nothing after.
166
+ *
167
+ * @param client - The client.
168
+ * @param kind - What the item is.
169
+ * @param id - Its id.
170
+ * @param href - The address the listing gave.
171
+ * @returns True only for such an address.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * itemHref_matches(client, 'link', 5, 'https://elsewhere/api/v1/filebrowser/linkfiles/5/'); // false
176
+ * ```
177
+ */
178
+ function itemHref_matches(client, kind, id, href) {
179
+ let given;
180
+ try {
181
+ given = new URL(href);
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ if (given.search !== "" || given.hash !== "" || given.username !== "" || given.password !== "")
187
+ return false;
188
+ return ROW_ROUTES[kind].some((route) => {
189
+ const expected = routeUrl_build(client, route, id);
190
+ if (expected === null)
191
+ return false;
192
+ const wanted = new URL(expected);
193
+ return given.origin === wanted.origin && given.pathname === wanted.pathname;
194
+ });
195
+ }
196
+ /**
197
+ * An address's origin, in words.
198
+ *
199
+ * @param href - The address.
200
+ * @returns Its origin, or a word that it has none.
201
+ */
202
+ function origin_describe(href) {
203
+ try {
204
+ return new URL(href).origin;
205
+ }
206
+ catch {
207
+ return "no origin (not an address)";
208
+ }
209
+ }
210
+ /**
211
+ * Why an act on an item is not asked: no address of CUBE's own can be built
212
+ * for it, or its row named another, the refusal naming both origins.
213
+ *
214
+ * @param client - The client.
215
+ * @param holder - The item, as its proof named it.
216
+ * @param act - The act, for the words (`delete`, `move`).
217
+ * @returns The refusal's words, or null when the act may be asked.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * itemHref_refusal(client, { kind: 'file', id: 41, href: 'https://elsewhere/x/' }, 'delete');
222
+ * // "Did not delete file ID 41: its row's address is at https://elsewhere, and CUBE's own for that file is at https://cube; nothing was asked"
223
+ * ```
224
+ */
225
+ function itemHref_refusal(client, holder, act) {
226
+ const word = KIND_WORDS[holder.kind];
227
+ const url = itemUrl_build(client, holder.kind, holder.id);
228
+ const head = `Did not ${act} ${word} ID ${String(holder.id)}`;
229
+ if (url === null)
230
+ return `${head}: no address of CUBE's own can be built for it; nothing was asked`;
231
+ if (holder.href === null || itemHref_matches(client, holder.kind, holder.id, holder.href))
232
+ return null;
233
+ // The row's address is never printed whole: it may carry a user, a query
234
+ // or a fragment. Its origin is all of it said, beside the route expected.
235
+ const given = origin_describe(holder.href);
236
+ const wanted = origin_describe(url);
237
+ const expected = `${ITEM_ROUTES[holder.kind]}/${String(holder.id)}/ at ${wanted}`;
238
+ const where = given === wanted ? `is not CUBE's own for that ${word}, ${expected}` : `is at ${given}, and CUBE's own for that ${word} is ${expected}`;
239
+ return `${head}: its row's address ${where}; nothing was asked`;
240
+ }
241
+ /**
242
+ * The signal one request is ended by: its own deadline, and the caller's.
243
+ *
244
+ * @param signal - The caller's, when given.
245
+ * @returns The two as one.
246
+ */
247
+ function requestSignal_build(signal) {
248
+ const deadline = AbortSignal.timeout(exports.REQUEST_TIMEOUT_MS);
249
+ return signal === undefined ? deadline : AbortSignal.any([deadline, signal]);
250
+ }
251
+ /**
252
+ * A response's body, read as JSON.
253
+ *
254
+ * @param response - The response.
255
+ * @returns The body, or null when there was none or it was not JSON.
256
+ */
257
+ async function body_read(response) {
258
+ try {
259
+ const text = await response.text();
260
+ return text === "" ? null : JSON.parse(text);
261
+ }
262
+ catch {
263
+ return null;
264
+ }
265
+ }
266
+ /**
267
+ * One request to an address of CUBE's own, with the client's token,
268
+ * following no redirect and ending at its deadline.
269
+ *
270
+ * @param client - The client.
271
+ * @param url - The address, built here.
272
+ * @param method - `GET`, `PUT` or `DELETE`.
273
+ * @param asked - A PUT's fields, and a signal that ends the request early.
274
+ * @returns What CUBE answered, or null when no answer came (none could be asked, or none in time).
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * const answer: CubeAnswer | null = await cube_ask(client, url, 'PUT', { template: { path: '/home/ada/new' } });
279
+ * ```
280
+ */
281
+ async function cube_ask(client, url, method, asked = {}) {
282
+ const auth = (0, adapter_js_1.client_authGet)(client);
283
+ const token = auth !== null && typeof auth === "object" ? Reflect.get(auth, "token") : undefined;
284
+ if (typeof token !== "string" || token === "")
285
+ return null;
286
+ const headers = new Headers();
287
+ headers.set("Authorization", `Token ${token}`);
288
+ // What chrisapi itself asks CUBE for, and sends it.
289
+ headers.set("Accept", "application/vnd.collection+json");
290
+ const init = { method, headers, redirect: "manual", signal: requestSignal_build(asked.signal) };
291
+ if (asked.template !== undefined) {
292
+ headers.set("Content-Type", "application/vnd.collection+json");
293
+ const data = Object.entries(asked.template).map(([name, value]) => ({ name, value }));
294
+ init.body = JSON.stringify({ template: { data } });
295
+ }
296
+ try {
297
+ const response = await fetch(url, init);
298
+ return { status: response.status, body: await body_read(response) };
299
+ }
300
+ catch {
301
+ return null;
302
+ }
303
+ }
304
+ /**
305
+ * The collection an answer carries.
306
+ *
307
+ * @param body - The answer's body.
308
+ * @returns The collection, or null when it carries none.
309
+ */
310
+ function collection_read(body) {
311
+ if (body === null || typeof body !== "object")
312
+ return null;
313
+ const collection = Reflect.get(body, "collection");
314
+ return collection !== null && typeof collection === "object" ? collection : null;
315
+ }
316
+ /**
317
+ * The fields of the one item an answer for an item carries: exactly one,
318
+ * since a detail address that answers with none, or with several, has not
319
+ * said which thing it is.
320
+ *
321
+ * @param body - The answer's body.
322
+ * @returns Its fields by name, or null when it carries no item, or more than one.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * answerItem_read(answer.body)?.fname; // 'home/ada/a.txt'
327
+ * ```
328
+ */
329
+ function answerItem_read(body) {
330
+ const items = Reflect.get(collection_read(body) ?? {}, "items");
331
+ return Array.isArray(items) && items.length === 1 ? itemFields_read(items[0]) : null;
332
+ }
333
+ /**
334
+ * The fields of one collection+json item, by name.
335
+ *
336
+ * @param item - The item, as a collection carries it.
337
+ * @returns Its fields, or null when it is no item.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * itemFields_read({ data: [{ name: 'id', value: 7 }] }); // { id: 7 }
342
+ * ```
343
+ */
344
+ function itemFields_read(item) {
345
+ const data = item !== null && typeof item === "object" ? Reflect.get(item, "data") : undefined;
346
+ if (!Array.isArray(data))
347
+ return null;
348
+ const fields = {};
349
+ for (const one of data) {
350
+ if (one === null || typeof one !== "object")
351
+ continue;
352
+ const name = Reflect.get(one, "name");
353
+ if (typeof name === "string")
354
+ fields[name] = Reflect.get(one, "value");
355
+ }
356
+ return fields;
357
+ }
358
+ /**
359
+ * A refusal's words, short: the message of a collection's error, or a body
360
+ * that is no collection; nothing for anything else.
361
+ *
362
+ * @param body - The answer's body.
363
+ * @returns The words, or an empty string.
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * refusalWords_read(answer.body); // '{"path":["This field is required."]}'
368
+ * ```
369
+ */
370
+ function refusalWords_read(body) {
371
+ if (body === null || typeof body !== "object")
372
+ return typeof body === "string" ? body.slice(0, 200) : "";
373
+ const said = collection_read(body) === null ? body : answerRefusal_read(body);
374
+ if (said === body && collection_read(body) !== null)
375
+ return "";
376
+ return (typeof said === "string" ? said : JSON.stringify(said)).slice(0, 200);
377
+ }
378
+ /**
379
+ * What a refusal says, as CUBE's serializers said it: the message of a
380
+ * collection's error, read as JSON when it is (CUBE writes a field's
381
+ * refusals so), else the body as it came.
382
+ *
383
+ * @param body - The refusal's body.
384
+ * @returns What it says.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * answerRefusal_read(answer.body); // { path: ['This field is required.'] }
389
+ * ```
390
+ */
391
+ function answerRefusal_read(body) {
392
+ const error = Reflect.get(collection_read(body) ?? {}, "error");
393
+ const message = error !== null && typeof error === "object" ? Reflect.get(error, "message") : undefined;
394
+ if (typeof message !== "string")
395
+ return body;
396
+ try {
397
+ return JSON.parse(message);
398
+ }
399
+ catch {
400
+ return message;
401
+ }
402
+ }
403
+ /**
404
+ * The page a collection's answer carries.
405
+ *
406
+ * @param body - The answer's body.
407
+ * @returns The page, or null when it carries no items and links to read.
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * const empty: boolean = answerList_read(answer.body)?.items.length === 0;
412
+ * ```
413
+ */
414
+ function answerList_read(body) {
415
+ const collection = collection_read(body);
416
+ if (collection === null)
417
+ return null;
418
+ const items = Reflect.get(collection, "items");
419
+ const links = Reflect.get(collection, "links");
420
+ if (!Array.isArray(items) || !Array.isArray(links))
421
+ return null;
422
+ const more = links.some((link) => link !== null && typeof link === "object" && Reflect.get(link, "rel") === "next");
423
+ const total = Reflect.get(collection, "total");
424
+ return { items, more, total: typeof total === "number" ? total : null };
425
+ }
426
+ /**
427
+ * What CUBE answers at an item's own address, as the client it was proved with.
428
+ *
429
+ * @param client - The client.
430
+ * @param kind - What the item is.
431
+ * @param id - Its id.
432
+ * @param signal - Ends the question early, when given.
433
+ * @returns The HTTP status, or null when it could not be asked.
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * const gone: boolean = (await itemStatus_probe(client, 'file', 41)) === 404;
438
+ * ```
439
+ */
440
+ async function itemStatus_probe(client, kind, id, signal) {
441
+ const url = itemUrl_build(client, kind, id);
442
+ if (url === null)
443
+ return null;
444
+ const answer = await cube_ask(client, url, "GET", signal === undefined ? {} : { signal });
445
+ return answer?.status ?? null;
446
+ }
447
+ //# sourceMappingURL=holderRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holderRequest.js","sourceRoot":"","sources":["../../src/io/holderRequest.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AAqHH,sCAEC;A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AK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,MAAM,IAAI,GAAY,KAAK,CAAC,IAAI,CAAC,CAAC,IAAa,EAAW,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC;IAC/I,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACxD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,IAAe,EAAE,EAAU,EAAE,MAAoB;IACtG,MAAM,GAAG,GAAkB,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3D,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,MAAM,GAAsB,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7G,OAAO,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC;AAChC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @file An upload that answers what CUBE stored, on a client given to it.
3
+ *
4
+ * A caller that goes on to act on what it uploaded (to move it, or to
5
+ * delete it) needs to know which file it is: its id, and the path it
6
+ * actually landed at, which is not always the one asked. The upload is
7
+ * made on the client it is given, so a write bound to one client uploads
8
+ * on that client and no other, at CUBE's own address for user files built
9
+ * from that client's API root, following no redirect.
10
+ *
11
+ * Key components:
12
+ * - UploadReceipt: which file CUBE stored, and where.
13
+ * - file_uploadReceipted: upload, and answer the receipt.
14
+ *
15
+ * Typical usage:
16
+ * ```ts
17
+ * const receipt: Result<UploadReceipt> = await file_uploadReceipted(client, new Blob(['x']), '/home/ada', 'x.txt');
18
+ * ```
19
+ *
20
+ * Dependencies: the chrisapi adapter's upload, the address of
21
+ * `./holderRequest.js`, the stall watch of `./streamWatch.js`, and cumin's error stack, where a failure's reason is
22
+ * left.
23
+ *
24
+ * @module
25
+ */
26
+ import { type Client } from "../chrisapi/adapter.js";
27
+ import { type Result } from "../utils/result.js";
28
+ /**
29
+ * What CUBE stored for an upload: which file, and where.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const receipt: UploadReceipt = { id: 41, path: '/home/ada/uploads/notes.txt' };
34
+ * ```
35
+ */
36
+ export interface UploadReceipt {
37
+ /** The id CUBE gave the stored file. */
38
+ readonly id: number;
39
+ /** The path it was stored at, with a leading slash; not always the one asked for. */
40
+ readonly path: string;
41
+ }
42
+ /**
43
+ * Uploads a file on the client given, and answers what CUBE stored,
44
+ * without touching it after.
45
+ *
46
+ * @param client - The client to upload on.
47
+ * @param fileBlob - The file content.
48
+ * @param uploadDir - The ChRIS folder to upload into.
49
+ * @param filename - The name asked for.
50
+ * @param stillCurrent - Asked immediately before the post, when given: whether
51
+ * the client is still the session's; false posts nothing.
52
+ * @param sent - Told once the post has left, when given (a failure before it
53
+ * left, such as no connection made, tells nothing).
54
+ * @returns The stored file's id and path, or Err with the reason stacked
55
+ * when the upload failed or CUBE's answer names no usable id or path.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const receipt: Result<UploadReceipt> = await file_uploadReceipted(client, new Blob(['x']), '/home/ada', 'x.txt');
60
+ * ```
61
+ */
62
+ export declare function file_uploadReceipted(client: Client, fileBlob: Blob, uploadDir: string, filename: string, stillCurrent?: () => Promise<boolean>, sent?: () => void): Promise<Result<UploadReceipt>>;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * @file An upload that answers what CUBE stored, on a client given to it.
4
+ *
5
+ * A caller that goes on to act on what it uploaded (to move it, or to
6
+ * delete it) needs to know which file it is: its id, and the path it
7
+ * actually landed at, which is not always the one asked. The upload is
8
+ * made on the client it is given, so a write bound to one client uploads
9
+ * on that client and no other, at CUBE's own address for user files built
10
+ * from that client's API root, following no redirect.
11
+ *
12
+ * Key components:
13
+ * - UploadReceipt: which file CUBE stored, and where.
14
+ * - file_uploadReceipted: upload, and answer the receipt.
15
+ *
16
+ * Typical usage:
17
+ * ```ts
18
+ * const receipt: Result<UploadReceipt> = await file_uploadReceipted(client, new Blob(['x']), '/home/ada', 'x.txt');
19
+ * ```
20
+ *
21
+ * Dependencies: the chrisapi adapter's upload, the address of
22
+ * `./holderRequest.js`, the stall watch of `./streamWatch.js`, and cumin's error stack, where a failure's reason is
23
+ * left.
24
+ *
25
+ * @module
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.file_uploadReceipted = file_uploadReceipted;
29
+ const holderRequest_js_1 = require("./holderRequest.js");
30
+ const streamWatch_js_1 = require("./streamWatch.js");
31
+ const adapter_js_1 = require("../chrisapi/adapter.js");
32
+ const errorStack_js_1 = require("../error/errorStack.js");
33
+ const result_js_1 = require("../utils/result.js");
34
+ /**
35
+ * Uploads a file on the client given, and answers what CUBE stored,
36
+ * without touching it after.
37
+ *
38
+ * @param client - The client to upload on.
39
+ * @param fileBlob - The file content.
40
+ * @param uploadDir - The ChRIS folder to upload into.
41
+ * @param filename - The name asked for.
42
+ * @param stillCurrent - Asked immediately before the post, when given: whether
43
+ * the client is still the session's; false posts nothing.
44
+ * @param sent - Told once the post has left, when given (a failure before it
45
+ * left, such as no connection made, tells nothing).
46
+ * @returns The stored file's id and path, or Err with the reason stacked
47
+ * when the upload failed or CUBE's answer names no usable id or path.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const receipt: Result<UploadReceipt> = await file_uploadReceipted(client, new Blob(['x']), '/home/ada', 'x.txt');
52
+ * ```
53
+ */
54
+ async function file_uploadReceipted(client, fileBlob, uploadDir, filename, stillCurrent, sent) {
55
+ const normalizedUploadDir = uploadDir.startsWith('/') ? uploadDir.substring(1) : uploadDir;
56
+ const fullPath = normalizedUploadDir.endsWith('/') ? normalizedUploadDir + filename : `${normalizedUploadDir}/${filename}`;
57
+ const watch = (0, streamWatch_js_1.upload_watchStalls)(fileBlob, filename, streamWatch_js_1.STREAM_STALL_MS);
58
+ const abandon = new AbortController();
59
+ watch.stalled.catch((stall) => { abandon.abort(stall); });
60
+ let uploaded;
61
+ try {
62
+ const upload = { url: (0, holderRequest_js_1.userFilesUrl_build)(client), uploadPath: fullPath, file: watch.file, signal: abandon.signal, stillCurrent };
63
+ uploaded = await (0, adapter_js_1.client_userFileUpload)(client, upload, sent);
64
+ }
65
+ catch (error) {
66
+ const errorMsg = error instanceof Error ? error.message : String(error);
67
+ errorStack_js_1.errorStack.stack_push("error", `Failed to upload file ${filename} to ${uploadDir}: ${errorMsg}`);
68
+ return (0, result_js_1.Err)();
69
+ }
70
+ finally {
71
+ watch.stop();
72
+ }
73
+ const id = uploaded.id;
74
+ const fname = uploaded.fname;
75
+ if (typeof id !== 'number' || !Number.isSafeInteger(id) || id <= 0 || typeof fname !== 'string' || fname === '') {
76
+ errorStack_js_1.errorStack.stack_push("error", `CUBE took ${filename} and did not say which file it made of it`);
77
+ return (0, result_js_1.Err)();
78
+ }
79
+ return (0, result_js_1.Ok)({ id, path: fname.startsWith('/') ? fname : `/${fname}` });
80
+ }
81
+ //# sourceMappingURL=holderUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holderUpload.js","sourceRoot":"","sources":["../../src/io/holderUpload.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;AA2CH,oDA+BC;AAxED,yDAAwD;AACxD,qDAAyF;AACzF,uDAAiG;AACjG,0DAAoD;AACpD,kDAA0D;AAiB1D;;;;;;;;;;;;;;;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,OAAO,EAAE,yBAAyB,QAAQ,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC,CAAC;QACjG,OAAO,IAAA,eAAG,GAAiB,CAAC;IAC9B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,IAAI,EAAE,CAAC;IACf,CAAC;IACD,MAAM,EAAE,GAAY,QAAQ,CAAC,EAAE,CAAC;IAChC,MAAM,KAAK,GAAY,QAAQ,CAAC,KAAK,CAAC;IACtC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAChH,0BAAU,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,QAAQ,2CAA2C,CAAC,CAAC;QACjG,OAAO,IAAA,eAAG,GAAiB,CAAC;IAC9B,CAAC;IACD,OAAO,IAAA,cAAE,EAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC"}
package/dist/io/io.d.ts CHANGED
@@ -8,6 +8,18 @@ export interface IStorageProvider {
8
8
  read(path: string): Promise<string | null>;
9
9
  readBinary(path: string): Promise<ArrayBuffer | null>;
10
10
  write(path: string, data: string): Promise<void>;
11
+ /**
12
+ * Writes a file that only its owner may read, in a folder only its owner
13
+ * may enter, and makes both so if they were already there and looser. For
14
+ * a credential. A provider with no notion of other readers (a browser's
15
+ * storage) may leave it out; `write` is used then.
16
+ */
17
+ writePrivate?(path: string, data: string): Promise<void>;
18
+ /**
19
+ * Makes a file that is already there, and its folder, its owner's alone
20
+ * when they are looser; does nothing when the file is not there.
21
+ */
22
+ private_tighten?(path: string): Promise<void>;
11
23
  remove(path: string): Promise<void>;
12
24
  mkdir(path: string, options?: {
13
25
  recursive?: boolean;
package/dist/io/io.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/io/io.ts"],"names":[],"mappings":";;;AAmBA,2CAAsD;AAA7C,oHAAA,sBAAsB,OAAA"}
1
+ {"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/io/io.ts"],"names":[],"mappings":";;;AA+BA,2CAAsD;AAA7C,oHAAA,sBAAsB,OAAA"}