@larc-iu/plaid-client 0.2.0-alpha.3 → 0.2.0-alpha.30

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 (73) hide show
  1. package/README.md +39 -0
  2. package/package.json +13 -6
  3. package/src/apiAnnotations.d.ts +508 -0
  4. package/src/apiAnnotations.js +543 -0
  5. package/src/apiDocuments.d.ts +569 -0
  6. package/src/apiDocuments.js +551 -0
  7. package/src/apiLayers.d.ts +369 -0
  8. package/src/apiLayers.js +222 -0
  9. package/src/apiMessages.d.ts +293 -0
  10. package/src/apiMessages.js +265 -0
  11. package/src/apiPeople.d.ts +626 -0
  12. package/src/apiPeople.js +698 -0
  13. package/src/apiProject.d.ts +761 -0
  14. package/src/apiProject.js +774 -0
  15. package/src/apiServer.d.ts +455 -0
  16. package/src/apiServer.js +422 -0
  17. package/src/apiVocab.d.ts +456 -0
  18. package/src/apiVocab.js +425 -0
  19. package/src/batch.d.ts +54 -0
  20. package/src/batch.js +323 -0
  21. package/src/batchRef.d.ts +30 -0
  22. package/src/batchRef.js +128 -0
  23. package/src/client.d.ts +1321 -0
  24. package/src/client.js +743 -0
  25. package/src/codepoint.d.ts +94 -0
  26. package/src/codepoint.js +131 -1
  27. package/src/constraints.d.ts +85 -0
  28. package/src/constraints.js +112 -0
  29. package/src/created.d.ts +2 -0
  30. package/src/created.js +29 -0
  31. package/src/documentLock.d.ts +172 -0
  32. package/src/documentLock.js +384 -0
  33. package/src/entryForms.d.ts +63 -0
  34. package/src/entryForms.js +152 -0
  35. package/src/events.d.ts +60 -0
  36. package/src/events.js +271 -0
  37. package/src/families.d.ts +349 -0
  38. package/src/families.js +396 -0
  39. package/src/http.d.ts +233 -0
  40. package/src/http.js +809 -93
  41. package/src/ids.d.ts +26 -0
  42. package/src/ids.js +96 -0
  43. package/src/index.d.ts +101 -0
  44. package/src/index.js +183 -2105
  45. package/src/metadataOps.d.ts +15 -0
  46. package/src/metadataOps.js +124 -0
  47. package/src/operations.d.ts +36 -0
  48. package/src/operations.js +164 -0
  49. package/src/pagination.d.ts +49 -0
  50. package/src/pagination.js +20 -53
  51. package/src/provenance.d.ts +243 -0
  52. package/src/provenance.js +458 -36
  53. package/src/replayed.d.ts +3 -0
  54. package/src/replayed.js +31 -0
  55. package/src/requester.d.ts +60 -0
  56. package/src/requester.js +74 -0
  57. package/src/roles.d.ts +104 -0
  58. package/src/roles.js +64 -2
  59. package/src/serviceSchema.d.ts +337 -0
  60. package/src/serviceSchema.js +177 -60
  61. package/src/services.d.ts +319 -0
  62. package/src/services.js +742 -58
  63. package/src/sse.d.ts +30 -0
  64. package/src/sse.js +80 -3
  65. package/src/testing.d.ts +128 -0
  66. package/src/testing.js +379 -0
  67. package/src/textEdits.d.ts +59 -0
  68. package/src/textEdits.js +234 -0
  69. package/src/transforms.d.ts +25 -0
  70. package/src/transforms.js +11 -1
  71. package/src/types.d.ts +867 -0
  72. package/src/types.js +663 -0
  73. package/index.d.ts +0 -532
@@ -0,0 +1,425 @@
1
+ /**
2
+ * The vocabulary bundles: vocabulary layers and their items, each a factory
3
+ * of the client (client.js installs them).
4
+ */
5
+
6
+ import { auditQuery, bodyOf, configMethods, metadataMethods } from "./families.js";
7
+ import { iterPages, listAll, listPage } from "./pagination.js";
8
+
9
+ /**
10
+ * @typedef {import("./types.js").TextEditOp} TextEditOp
11
+ * @typedef {import("./types.js").TextGap} TextGap
12
+ * @typedef {import("./types.js").MetadataOp} MetadataOp
13
+ * @typedef {import("./types.js").LayerConstraint} LayerConstraint
14
+ * @typedef {import("./types.js").ConstraintWriteOptions} ConstraintWriteOptions
15
+ * @typedef {import("./types.js").ConstraintViolation} ConstraintViolation
16
+ * @typedef {import("./types.js").Requester} Requester
17
+ * @typedef {import("./types.js").BatchRef} BatchRef
18
+ * @typedef {import("./types.js").ServiceParam} ServiceParam
19
+ * @typedef {import("./types.js").ServiceInfo} ServiceInfo
20
+ * @typedef {import("./types.js").DiscoveredService} DiscoveredService
21
+ * @typedef {import("./types.js").ResponseHelper} ResponseHelper
22
+ * @typedef {import("./types.js").ServiceRegistration} ServiceRegistration
23
+ * @typedef {import("./types.js").ServiceStatusEvent} ServiceStatusEvent
24
+ * @typedef {import("./types.js").OperationGroupsBundle} OperationGroupsBundle
25
+ * @typedef {import("./types.js").PlaidClientOptions} PlaidClientOptions
26
+ * @typedef {import("./types.js").OperationKind} OperationKind
27
+ * @typedef {import("./types.js").KeySeed} KeySeed
28
+ * @typedef {import("./types.js").PlaidBatch} PlaidBatch
29
+ * @typedef {import("./types.js").AuditPageOptions} AuditPageOptions
30
+ * @typedef {import("./types.js").VocabItemRestoreSummary} VocabItemRestoreSummary
31
+ * @typedef {import("./types.js").UserDataEntry} UserDataEntry
32
+ * @typedef {import("./types.js").AdminUserDataEntry} AdminUserDataEntry
33
+ * @typedef {import("./types.js").ActivityTallyRow} ActivityTallyRow
34
+ * @typedef {import("./types.js").ConstraintRepair} ConstraintRepair
35
+ * @typedef {import("./types.js").ValueSetRule} ValueSetRule
36
+ * @typedef {import("./types.js").RefusedValues} RefusedValues
37
+ * @typedef {import("./types.js").CommentableType} CommentableType
38
+ * @typedef {import("./types.js").Comment} Comment
39
+ * @typedef {import("./types.js").Guideline} Guideline
40
+ * @typedef {import("./types.js").ClientEventType} ClientEventType
41
+ * @typedef {import("./types.js").ClientEvent} ClientEvent
42
+ * @typedef {import("./types.js").Invite} Invite
43
+ * @typedef {import("./types.js").ServerLimits} ServerLimits
44
+ * @typedef {import("./types.js").ServerHealth} ServerHealth
45
+ * @typedef {import("./types.js").RateLimitBucket} RateLimitBucket
46
+ * @typedef {import("./types.js").RateLimitSnapshot} RateLimitSnapshot
47
+ * @typedef {import("./types.js").BackupStatus} BackupStatus
48
+ * @typedef {import("./types.js").ServerReport} ServerReport
49
+ * @typedef {import("./types.js").LiveLog} LiveLog
50
+ * @typedef {import("./types.js").SSEConnection} SSEConnection
51
+ * @typedef {import("./types.js").SSEStats} SSEStats
52
+ * @typedef {import("./types.js").AtomicValue} AtomicValue
53
+ * @typedef {import("./types.js").Created} Created
54
+ * @typedef {import("./types.js").Project} Project
55
+ * @typedef {import("./types.js").ProjectTextLayer} ProjectTextLayer
56
+ * @typedef {import("./types.js").ProjectTokenLayer} ProjectTokenLayer
57
+ * @typedef {import("./types.js").ProjectSpanLayer} ProjectSpanLayer
58
+ * @typedef {import("./types.js").ProjectRelationLayer} ProjectRelationLayer
59
+ * @typedef {import("./types.js").ProjectVocab} ProjectVocab
60
+ * @typedef {import("./types.js").PlaidDocument} PlaidDocument
61
+ * @typedef {import("./types.js").DocumentTextLayer} DocumentTextLayer
62
+ * @typedef {import("./types.js").DocumentTokenLayer} DocumentTokenLayer
63
+ * @typedef {import("./types.js").DocumentSpanLayer} DocumentSpanLayer
64
+ * @typedef {import("./types.js").PlaidText} PlaidText
65
+ * @typedef {import("./types.js").TextReshape} TextReshape
66
+ * @typedef {import("./types.js").Token} Token
67
+ * @typedef {import("./types.js").Span} Span
68
+ * @typedef {import("./types.js").Relation} Relation
69
+ * @typedef {import("./types.js").VocabItem} VocabItem
70
+ * @typedef {import("./types.js").VocabLink} VocabLink
71
+ * @typedef {import("./types.js").VocabLayer} VocabLayer
72
+ * @typedef {import("./types.js").TextLayer} TextLayer
73
+ * @typedef {import("./types.js").TokenLayer} TokenLayer
74
+ * @typedef {import("./types.js").SpanLayer} SpanLayer
75
+ * @typedef {import("./types.js").RelationLayer} RelationLayer
76
+ * @typedef {import("./types.js").MetadataRecords} MetadataRecords
77
+ * @typedef {import("./types.js").LayerRecords} LayerRecords
78
+ * @typedef {import("./types.js").User} User
79
+ * @typedef {import("./types.js").ProjectListEntry} ProjectListEntry
80
+ * @typedef {import("./types.js").DocumentListEntry} DocumentListEntry
81
+ * @typedef {import("./types.js").ApiToken} ApiToken
82
+ * @typedef {import("./types.js").AuditUser} AuditUser
83
+ * @typedef {import("./types.js").AuditTarget} AuditTarget
84
+ * @typedef {import("./types.js").AuditOp} AuditOp
85
+ * @typedef {import("./types.js").AuditEntry} AuditEntry
86
+ * @typedef {import("./types.js").LockGrant} LockGrant
87
+ * @typedef {import("./types.js").DocumentRestoreSummary} DocumentRestoreSummary
88
+ * @typedef {import("./types.js").RestoreCounts} RestoreCounts
89
+ * @typedef {import("./types.js").OperationGroup} OperationGroup
90
+ * @typedef {import("./types.js").QueryResult} QueryResult
91
+ */
92
+
93
+ /**
94
+ * @template [T=any]
95
+ * @typedef {import("./types.js").Page<T>} Page
96
+ */
97
+
98
+ /** @param {import("./client.js").PlaidClient} client */
99
+ export function vocabLayersApi(client) {
100
+ return {
101
+ /**
102
+ * Get a vocab layer by ID. With `asOf`, the vocabulary as it was at that
103
+ * instant, read from its history: the same shape as the live read, its
104
+ * entries with `includeItems`. A vocabulary that did not exist then is a
105
+ * 404, a malformed or pruned time a 400.
106
+ * @param {string} id - The resource ID
107
+ * @param {boolean} [includeItems] - Include vocab items
108
+ * @param {string} [asOf] - The moment to read at (ISO-8601 instant)
109
+ * @returns {Promise<VocabLayer>}
110
+ */
111
+ get: (id, includeItems, asOf) =>
112
+ client._request("GET", `/api/v1/vocab-layers/${id}`, {
113
+ queryParams: { "include-items": includeItems, "as-of": asOf },
114
+ }),
115
+ /**
116
+ * One entry of the vocabulary as it was at `asOf`, also when it has
117
+ * been deleted since. The same shape as `vocabItems.get`. A 404 when
118
+ * the entry was not in this vocabulary at that time.
119
+ * @param {string} id - The vocabulary ID
120
+ * @param {string} itemId - The entry ID
121
+ * @param {string} asOf - The moment to read at (ISO-8601 instant)
122
+ * @returns {Promise<VocabItem>}
123
+ */
124
+ getItemAt: (id, itemId, asOf) =>
125
+ client._request("GET", `/api/v1/vocab-layers/${id}/items/${itemId}`, {
126
+ queryParams: { "as-of": asOf },
127
+ }),
128
+ /**
129
+ * List all vocab layers accessible to user. Transparently follows
130
+ * pagination cursors and returns the full flat array.
131
+ * @returns {Promise<VocabLayer[]>}
132
+ */
133
+ list: () => listAll(client, "/api/v1/vocab-layers"),
134
+ /**
135
+ * Fetch a single page of vocab layers.
136
+ * @param {object} [opts]
137
+ * @param {number} [opts.limit] - Page size (1..1000; server default 100)
138
+ * @param {string} [opts.cursor] - Opaque cursor from a previous page
139
+ * @returns {Promise<Page<VocabLayer>>}
140
+ */
141
+ listPage: ({ limit, cursor } = {}) =>
142
+ listPage(client, "/api/v1/vocab-layers", {
143
+ limit,
144
+ cursor,
145
+ }),
146
+ /**
147
+ * Async-iterate vocab layers page by page; yields each page's entries array.
148
+ * @param {object} [opts]
149
+ * @param {number} [opts.pageSize] - Per-request page size
150
+ * @returns {AsyncGenerator<VocabLayer[]>}
151
+ */
152
+ iterPages: ({ pageSize } = {}) =>
153
+ iterPages(client, "/api/v1/vocab-layers", {
154
+ pageSize,
155
+ }),
156
+ /**
157
+ * Create a new vocab layer. Note: this also registers the user as a maintainer.
158
+ * @param {string} name - The name
159
+ * @param {string} [auditMessage] - Audit message for this write
160
+ * @param {object} [opts]
161
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
162
+ * @returns {Promise<Created>}
163
+ */
164
+ create: (name, auditMessage, { id } = {}) =>
165
+ client._request("POST", "/api/v1/vocab-layers", {
166
+ auditMessage,
167
+ body: bodyOf({ id, name }),
168
+ }),
169
+ /**
170
+ * Update a vocab layer's name. A new name restates every document
171
+ * linking the vocabulary: their versions are bumped and taken up from
172
+ * X-Document-Versions.
173
+ * @param {string} id - The resource ID
174
+ * @param {string} name - The name
175
+ * @param {string} [auditMessage] - Audit message for this write
176
+ * @returns {Promise<VocabLayer>}
177
+ */
178
+ update: (id, name, auditMessage) =>
179
+ client._request("PATCH", `/api/v1/vocab-layers/${id}`, {
180
+ auditMessage,
181
+ body: bodyOf({ name }),
182
+ }),
183
+ /**
184
+ * Delete a vocab layer.
185
+ * @param {string} id - The resource ID
186
+ * @param {string} [auditMessage] - Audit message for this write
187
+ * @returns {Promise<void>}
188
+ */
189
+ delete: (id, auditMessage) =>
190
+ client._request("DELETE", `/api/v1/vocab-layers/${id}`, { auditMessage }),
191
+ /**
192
+ * Get the audit log of a vocabulary: every change to it or to its
193
+ * entries, folded into entries as the document log is. Links are not
194
+ * listed, they belong to the document they annotate. Transparently
195
+ * follows pagination cursors and returns the full flat array.
196
+ * @param {string} id - The vocabulary ID
197
+ * @param {string} [startTime] - Start of time range
198
+ * @param {string} [endTime] - End of time range
199
+ * @param {string[]|string} [opTypes] - Only return operations of these
200
+ * types, spelled as in an entry's `op/type` (e.g.
201
+ * `['vocab-item/delete', 'vocab-item/restore']`)
202
+ * @param {string} [itemId] - Only the changes that wrote this one entry,
203
+ * each with only its operations that did
204
+ * @param {string[]|string} [kinds] - Only the entries of operations of
205
+ * these kinds (e.g. `['review', 'guess-adoption']`), each whole
206
+ * @returns {Promise<AuditEntry[]>}
207
+ */
208
+ audit: (id, startTime, endTime, opTypes, itemId, kinds) =>
209
+ listAll(client, `/api/v1/vocab-layers/${id}/audit`, {
210
+ query: auditQuery({ startTime, endTime, opTypes, itemId, kinds }),
211
+ }),
212
+ /**
213
+ * One page of the same log, newest-first with `order: "desc"`. Use this
214
+ * rather than audit() wherever the caller wants the recent end of a log
215
+ * that may be long: audit() walks every page before it resolves.
216
+ * @param {string} id - The vocabulary ID
217
+ * @param {object} [opts]
218
+ * @param {string} [opts.startTime] - Only entries at or after this instant
219
+ * @param {string} [opts.endTime] - Only entries at or before this instant
220
+ * @param {string[]|string} [opts.opTypes] - Only these op types
221
+ * @param {OperationKind[]|string} [opts.kinds] - Only the entries of operations of these kinds, each whole
222
+ * @param {"asc"|"desc"} [opts.order] - "desc" pages newest-first
223
+ * @param {number} [opts.limit] - Page size (1..1000; server default 100)
224
+ * @param {string} [opts.cursor] - Opaque cursor from a previous page
225
+ * @param {number} [opts.opsLimit] - Keep only each entry's oldest N
226
+ * operations in `ops` (1..1000). `opCount` on every entry says how
227
+ * many it has
228
+ * @param {string} [opts.entryId] - Read only this entry, not a page
229
+ * @param {string} [opts.itemId] - Only the changes that wrote this one
230
+ * entry, each with only its operations that did
231
+ * @returns {Promise<Page<AuditEntry>>}
232
+ */
233
+ auditPage: (
234
+ id,
235
+ { startTime, endTime, opTypes, kinds, order, limit, cursor, opsLimit, entryId, itemId } = {},
236
+ ) =>
237
+ listPage(client, `/api/v1/vocab-layers/${id}/audit`, {
238
+ limit,
239
+ cursor,
240
+ query: auditQuery({ startTime, endTime, opTypes, kinds, order, opsLimit, entryId, itemId }),
241
+ }),
242
+ /**
243
+ * Put one entry of the vocabulary back as it was at `asOf`, as one
244
+ * operation. A deleted entry comes back under its original id with its
245
+ * form and fields, and a living one has its form and fields set back.
246
+ * Links are not part of an entry: a deleted entry's links come back
247
+ * through each document's own `documents.restore`. Resolves to
248
+ * `{inserted, form, metadata, total}`, `total` 0 when nothing changes.
249
+ * A form set back bumps every linking document, and the new versions
250
+ * come back in X-Document-Versions (or, past fifty documents,
251
+ * X-Document-Versions-Omitted), which the client takes up as on any
252
+ * write. A time when the entry did not exist is a 400. Maintainers of
253
+ * the vocabulary only.
254
+ * @param {string} id - The vocabulary ID
255
+ * @param {string} itemId - The entry ID
256
+ * @param {string} asOf - The moment to go back to (ISO-8601 instant),
257
+ * typically a history entry's `endTime`
258
+ * @param {{dryRun?: boolean}} [options] - `{ dryRun }`: with `dryRun` true nothing
259
+ * is written and the summary says what would change
260
+ * @param {string} [auditMessage] - Custom audit message for this operation
261
+ * @returns {Promise<VocabItemRestoreSummary>}
262
+ */
263
+ restoreItem: (id, itemId, asOf, { dryRun } = {}, auditMessage) =>
264
+ client._request(
265
+ "POST",
266
+ `/api/v1/vocab-layers/${id}/items/${itemId}/restore`,
267
+ {
268
+ queryParams: {
269
+ "as-of": asOf,
270
+ "dry-run": dryRun ? "true" : undefined,
271
+ },
272
+ auditMessage,
273
+ },
274
+ ),
275
+ /**
276
+ * Assign a user as a maintainer for this vocab layer.
277
+ * @param {string} id - The resource ID
278
+ * @param {string} userId - The user ID
279
+ * @param {string} [auditMessage] - Audit message for this write
280
+ * @returns {Promise<void>}
281
+ */
282
+ addMaintainer: (id, userId, auditMessage) =>
283
+ client._request(
284
+ "POST",
285
+ `/api/v1/vocab-layers/${id}/maintainers/${userId}`,
286
+ { auditMessage },
287
+ ),
288
+ /**
289
+ * Remove a user's maintainer privileges for this vocab layer.
290
+ * @param {string} id - The resource ID
291
+ * @param {string} userId - The user ID
292
+ * @param {string} [auditMessage] - Audit message for this write
293
+ * @returns {Promise<void>}
294
+ */
295
+ removeMaintainer: (id, userId, auditMessage) =>
296
+ client._request(
297
+ "DELETE",
298
+ `/api/v1/vocab-layers/${id}/maintainers/${userId}`,
299
+ { auditMessage },
300
+ ),
301
+ ...configMethods(client, "vocab-layers"),
302
+ };
303
+ }
304
+
305
+ /** @param {import("./client.js").PlaidClient} client */
306
+ export function vocabItemsApi(client) {
307
+ return {
308
+ /**
309
+ * Get a vocab item by ID
310
+ * @param {string} id - The resource ID
311
+ * @returns {Promise<VocabItem>}
312
+ */
313
+ get: (id) =>
314
+ client._request("GET", `/api/v1/vocab-items/${id}`),
315
+ /**
316
+ * Create a new vocab item
317
+ * @param {string} vocabLayerId - The vocab layer ID
318
+ * @param {string} form - The vocab item form
319
+ * @param {any} [metadata] - Metadata map. Omit to leave unset; pass null to send JSON null.
320
+ * @param {string} [auditMessage] - Audit message for this write
321
+ * @param {object} [opts]
322
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
323
+ * @returns {Promise<Created>}
324
+ */
325
+ create: (vocabLayerId, form, metadata, auditMessage, { id } = {}) =>
326
+ client._request("POST", "/api/v1/vocab-items", {
327
+ auditMessage,
328
+ body: bodyOf({ id, "vocab-layer-id": vocabLayerId, form, metadata }),
329
+ }),
330
+ /**
331
+ * Update a vocab item's form. A document read carries the entry's form on
332
+ * every link to it, so a rename restates those documents: each has its
333
+ * version bumped, and a strict-mode client picks up their new versions
334
+ * from the response.
335
+ * @param {string} id - The resource ID
336
+ * @param {string} form - The vocab item form
337
+ * @param {string} [auditMessage] - Audit message for this write
338
+ * @returns {Promise<VocabItem>}
339
+ */
340
+ update: (id, form, auditMessage) =>
341
+ client._request("PATCH", `/api/v1/vocab-items/${id}`, {
342
+ auditMessage,
343
+ body: bodyOf({ form }),
344
+ }),
345
+ /**
346
+ * Delete a vocab item, and every link to it. Every document holding one
347
+ * of those links has its version bumped, and a strict-mode client picks
348
+ * up their new versions from the response.
349
+ * @param {string} id - The resource ID
350
+ * @param {string} [auditMessage] - Audit message for this write
351
+ * @param {{expectedLinkCount?: number}} [options] - `expectedLinkCount`: the
352
+ * number of links the caller showed. The delete is refused with a 409 when
353
+ * the entry has any other number of links by then.
354
+ * @returns {Promise<void>}
355
+ */
356
+ delete: (id, auditMessage, { expectedLinkCount } = {}) =>
357
+ client._request("DELETE", `/api/v1/vocab-items/${id}`, {
358
+ auditMessage,
359
+ queryParams: { "expected-link-count": expectedLinkCount },
360
+ }),
361
+ /**
362
+ * Create multiple vocab items in a single operation. Entries may target
363
+ * different vocab layers; the user must have write access to each.
364
+ * @param {Array<{vocabLayerId: string, form: string, metadata?: any}>} body - The vocab items to create
365
+ * @param {string} [auditMessage] - Audit message for this write
366
+ * @returns {Promise<{ids: string[]}>}
367
+ */
368
+ bulkCreate: (body, auditMessage) =>
369
+ client._request("POST", "/api/v1/vocab-items/bulk", {
370
+ auditMessage,
371
+ body,
372
+ }),
373
+ /**
374
+ * Update many vocab items in a single operation: set forms and/or patch
375
+ * metadata.
376
+ * @param {Array<{id: string, form?: string, metadata?: Array<object>}>} body - `form` is set only when the key is present; `metadata` is a list of metadata ops, as for patchMetadata. The entries may lie in several vocab layers; the user must have write access to each. An unknown id refuses the whole update, and an id may appear only once. Only an entry whose form really changes restates the documents linking it, and a strict-mode client picks up their new versions from the response.
377
+ * @param {string} [auditMessage] - Audit message for this write
378
+ * @returns {Promise<{count: number}>} How many vocab items were updated.
379
+ */
380
+ bulkUpdate: (body, auditMessage) =>
381
+ client._request("PATCH", "/api/v1/vocab-items/bulk", {
382
+ auditMessage,
383
+ body,
384
+ }),
385
+ /**
386
+ * Delete multiple vocab items in a single operation. Each item's
387
+ * descendant vocab links are deleted too. Provide an array of IDs.
388
+ *
389
+ * Every document holding one of those links has its version bumped, and
390
+ * a strict-mode client picks up their new versions from the response.
391
+ * @param {string[]} body - The vocab item IDs to delete
392
+ * @param {string} [auditMessage] - Audit message for this write
393
+ * @returns {Promise<void>}
394
+ */
395
+ bulkDelete: (body, auditMessage) =>
396
+ client._request("DELETE", "/api/v1/vocab-items/bulk", {
397
+ auditMessage,
398
+ body,
399
+ }),
400
+ /**
401
+ * Merge entries into this one, in one operation. Every link to a loser
402
+ * moves to the survivor (keeping its id and metadata), except a link on
403
+ * words the survivor is already linked to, which is deleted, and then the
404
+ * losers are deleted. Links are read when the merge runs, so one made
405
+ * after the caller looked moves too. Every loser must be in the
406
+ * survivor's vocabulary, and a loser that is already gone is skipped, so
407
+ * a repeated merge changes nothing. Metadata naming a loser by its id,
408
+ * in the vocabulary's other entries and in the documents of every
409
+ * project it is linked to, is rewritten to name the survivor. A
410
+ * reference to a loser in the survivor's own metadata is the caller's to
411
+ * rewrite, in the same batch.
412
+ * Needs maintainer rights on the vocabulary.
413
+ * @param {string} survivorId - The entry that stays
414
+ * @param {string[]} loserIds - The entries merged into it
415
+ * @param {string} [auditMessage] - Audit message for this write
416
+ * @returns {Promise<{moved: number, duplicates: number, removed: string[]}>}
417
+ */
418
+ merge: (survivorId, loserIds, auditMessage) =>
419
+ client._request("POST", `/api/v1/vocab-items/${survivorId}/merge`, {
420
+ auditMessage,
421
+ body: { losers: loserIds },
422
+ }),
423
+ ...metadataMethods(client, "vocab-items"),
424
+ };
425
+ }
package/src/batch.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * A batch is the client with a different `_request` (see `queueRequest`) and
3
+ * its own copy of the bundles. Everything else resolves to the client through
4
+ * the prototype: the token and base URL, strict mode and the document versions
5
+ * it tracks, the open logical operation.
6
+ * @param {any} client - PlaidClient instance
7
+ * @param {{timeout?: number | null}} [options]
8
+ */
9
+ export function openBatch(client: any, { timeout }?: {
10
+ timeout?: number | null;
11
+ }): any;
12
+ export function submitBatch(batch: any): Promise<any[]>;
13
+ /** The document-version an op's path claims, as a number, or null. */
14
+ export function claimedVersion(path: any): number;
15
+ export function sendChunks(client: any, url: any, ops: any, stamps: any, results: any, groups?: any[], timeout?: any): Promise<void>;
16
+ /**
17
+ * A call made on a batch (see `PlaidClient#batch`). A write of project data is
18
+ * queued as one operation of the batch and answers `{ batched: true }`; its
19
+ * result is the matching entry of what `submit()` resolves to. A read, and a
20
+ * signal marked `outOfBand`, is the client's to make and goes over the wire
21
+ * now, exactly as if it had been made on the client.
22
+ */
23
+ export function queueRequest(batch: any, method: any, path: any, options?: {}): Promise<any>;
24
+ /**
25
+ * POST one batch request (at most MAX_BATCH_OPS operations) through the same
26
+ * send, retries and version learning as every other request. Resolves to one
27
+ * `{ status, headers, body }` per operation, with only the body recased: the
28
+ * headers keep the server's spelling. `key` is the request's Idempotency-Key:
29
+ * a batch whose answer is lost (no response, 502, 504) is sent again under
30
+ * it, and answered from the first send if that landed. A refused batch wrote
31
+ * nothing (it is atomic), so a 503 is retried too. `timeout` is this
32
+ * request's, in place of `batchTimeout` when given.
33
+ *
34
+ * Each sub-response's `X-Document-Versions` is learned, and the batch's own,
35
+ * which holds each document's version after the whole batch, the layer
36
+ * rules' remedies at its end included (a split that deletes a relation
37
+ * crossing the new boundary moves the version once more). The batch's own
38
+ * `X-Document-Versions-Omitted` is not taken up: each sub-response keeps its
39
+ * own list. Every answer notes the server's clock, as a single request's
40
+ * does.
41
+ * @param {object} client - PlaidClient instance
42
+ * @param {string} url
43
+ * @param {object[]} body - The operations
44
+ * @param {{key?: string, timeout?: number | null}} [options]
45
+ */
46
+ export function postBatch(client: object, url: string, body: object[], { key, timeout }?: {
47
+ key?: string;
48
+ timeout?: number | null;
49
+ }): Promise<any>;
50
+ /**
51
+ * The server's cap on operations per batch request (plaid.rest-api.v1.batch).
52
+ * A batch queued past it is submitted as consecutive requests.
53
+ */
54
+ export const MAX_BATCH_OPS: 1000;