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

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 +457 -0
  16. package/src/apiServer.js +424 -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 +68 -0
  34. package/src/entryForms.js +164 -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,543 @@
1
+ /**
2
+ * The annotation bundles: tokens, spans, relations and vocabulary links,
3
+ * each a factory of the client (client.js installs them).
4
+ */
5
+
6
+ import { bodyOf, metadataMethods } from "./families.js";
7
+
8
+ /**
9
+ * @typedef {import("./types.js").TextEditOp} TextEditOp
10
+ * @typedef {import("./types.js").TextGap} TextGap
11
+ * @typedef {import("./types.js").MetadataOp} MetadataOp
12
+ * @typedef {import("./types.js").LayerConstraint} LayerConstraint
13
+ * @typedef {import("./types.js").ConstraintWriteOptions} ConstraintWriteOptions
14
+ * @typedef {import("./types.js").ConstraintViolation} ConstraintViolation
15
+ * @typedef {import("./types.js").Requester} Requester
16
+ * @typedef {import("./types.js").BatchRef} BatchRef
17
+ * @typedef {import("./types.js").ServiceParam} ServiceParam
18
+ * @typedef {import("./types.js").ServiceInfo} ServiceInfo
19
+ * @typedef {import("./types.js").DiscoveredService} DiscoveredService
20
+ * @typedef {import("./types.js").ResponseHelper} ResponseHelper
21
+ * @typedef {import("./types.js").ServiceRegistration} ServiceRegistration
22
+ * @typedef {import("./types.js").ServiceStatusEvent} ServiceStatusEvent
23
+ * @typedef {import("./types.js").OperationGroupsBundle} OperationGroupsBundle
24
+ * @typedef {import("./types.js").PlaidClientOptions} PlaidClientOptions
25
+ * @typedef {import("./types.js").OperationKind} OperationKind
26
+ * @typedef {import("./types.js").KeySeed} KeySeed
27
+ * @typedef {import("./types.js").PlaidBatch} PlaidBatch
28
+ * @typedef {import("./types.js").AuditPageOptions} AuditPageOptions
29
+ * @typedef {import("./types.js").VocabItemRestoreSummary} VocabItemRestoreSummary
30
+ * @typedef {import("./types.js").UserDataEntry} UserDataEntry
31
+ * @typedef {import("./types.js").AdminUserDataEntry} AdminUserDataEntry
32
+ * @typedef {import("./types.js").ActivityTallyRow} ActivityTallyRow
33
+ * @typedef {import("./types.js").ConstraintRepair} ConstraintRepair
34
+ * @typedef {import("./types.js").ValueSetRule} ValueSetRule
35
+ * @typedef {import("./types.js").RefusedValues} RefusedValues
36
+ * @typedef {import("./types.js").CommentableType} CommentableType
37
+ * @typedef {import("./types.js").Comment} Comment
38
+ * @typedef {import("./types.js").Guideline} Guideline
39
+ * @typedef {import("./types.js").ClientEventType} ClientEventType
40
+ * @typedef {import("./types.js").ClientEvent} ClientEvent
41
+ * @typedef {import("./types.js").Invite} Invite
42
+ * @typedef {import("./types.js").ServerLimits} ServerLimits
43
+ * @typedef {import("./types.js").ServerHealth} ServerHealth
44
+ * @typedef {import("./types.js").RateLimitBucket} RateLimitBucket
45
+ * @typedef {import("./types.js").RateLimitSnapshot} RateLimitSnapshot
46
+ * @typedef {import("./types.js").BackupStatus} BackupStatus
47
+ * @typedef {import("./types.js").ServerReport} ServerReport
48
+ * @typedef {import("./types.js").LiveLog} LiveLog
49
+ * @typedef {import("./types.js").SSEConnection} SSEConnection
50
+ * @typedef {import("./types.js").SSEStats} SSEStats
51
+ * @typedef {import("./types.js").AtomicValue} AtomicValue
52
+ * @typedef {import("./types.js").Created} Created
53
+ * @typedef {import("./types.js").Project} Project
54
+ * @typedef {import("./types.js").ProjectTextLayer} ProjectTextLayer
55
+ * @typedef {import("./types.js").ProjectTokenLayer} ProjectTokenLayer
56
+ * @typedef {import("./types.js").ProjectSpanLayer} ProjectSpanLayer
57
+ * @typedef {import("./types.js").ProjectRelationLayer} ProjectRelationLayer
58
+ * @typedef {import("./types.js").ProjectVocab} ProjectVocab
59
+ * @typedef {import("./types.js").PlaidDocument} PlaidDocument
60
+ * @typedef {import("./types.js").DocumentTextLayer} DocumentTextLayer
61
+ * @typedef {import("./types.js").DocumentTokenLayer} DocumentTokenLayer
62
+ * @typedef {import("./types.js").DocumentSpanLayer} DocumentSpanLayer
63
+ * @typedef {import("./types.js").PlaidText} PlaidText
64
+ * @typedef {import("./types.js").TextReshape} TextReshape
65
+ * @typedef {import("./types.js").Token} Token
66
+ * @typedef {import("./types.js").Span} Span
67
+ * @typedef {import("./types.js").Relation} Relation
68
+ * @typedef {import("./types.js").VocabItem} VocabItem
69
+ * @typedef {import("./types.js").VocabLink} VocabLink
70
+ * @typedef {import("./types.js").VocabLayer} VocabLayer
71
+ * @typedef {import("./types.js").TextLayer} TextLayer
72
+ * @typedef {import("./types.js").TokenLayer} TokenLayer
73
+ * @typedef {import("./types.js").SpanLayer} SpanLayer
74
+ * @typedef {import("./types.js").RelationLayer} RelationLayer
75
+ * @typedef {import("./types.js").MetadataRecords} MetadataRecords
76
+ * @typedef {import("./types.js").LayerRecords} LayerRecords
77
+ * @typedef {import("./types.js").User} User
78
+ * @typedef {import("./types.js").ProjectListEntry} ProjectListEntry
79
+ * @typedef {import("./types.js").DocumentListEntry} DocumentListEntry
80
+ * @typedef {import("./types.js").ApiToken} ApiToken
81
+ * @typedef {import("./types.js").AuditUser} AuditUser
82
+ * @typedef {import("./types.js").AuditTarget} AuditTarget
83
+ * @typedef {import("./types.js").AuditOp} AuditOp
84
+ * @typedef {import("./types.js").AuditEntry} AuditEntry
85
+ * @typedef {import("./types.js").LockGrant} LockGrant
86
+ * @typedef {import("./types.js").DocumentRestoreSummary} DocumentRestoreSummary
87
+ * @typedef {import("./types.js").RestoreCounts} RestoreCounts
88
+ * @typedef {import("./types.js").OperationGroup} OperationGroup
89
+ * @typedef {import("./types.js").QueryResult} QueryResult
90
+ */
91
+
92
+ /**
93
+ * @template [T=any]
94
+ * @typedef {import("./types.js").Page<T>} Page
95
+ */
96
+
97
+ /** @param {import("./client.js").PlaidClient} client */
98
+ export function tokensApi(client) {
99
+ return {
100
+ /**
101
+ * Get a token.
102
+ * @param {string} tokenId - The token ID
103
+ * @returns {Promise<Token>}
104
+ */
105
+ get: (tokenId) =>
106
+ client._request("GET", `/api/v1/tokens/${tokenId}`),
107
+ /**
108
+ * Create a new token in a token layer. Tokens define text substrings
109
+ * using begin and end offsets. Tokens may be zero-width and may overlap.
110
+ * For tokens sharing the same begin, precedence controls the linear
111
+ * ordering.
112
+ *
113
+ * Offsets are 0-based indices in Unicode CODE POINTS (not UTF-16 code
114
+ * units): a supplementary-plane character (emoji, SMP script) is one
115
+ * position. JS strings are UTF-16, so do NOT use `str.length` /
116
+ * `str.substring` to compute offsets — count code points instead
117
+ * (e.g. `[...str].length`, or iterate with `codePointAt`).
118
+ * @param {string} tokenLayerId - The token layer ID
119
+ * @param {string} text - The text ID
120
+ * @param {number} begin - Start offset, inclusive (Unicode code points)
121
+ * @param {number} end - End offset, exclusive (Unicode code points)
122
+ * @param {number} [precedence] - Ordering precedence
123
+ * @param {any} [metadata] - Metadata map. Omit to leave unset; pass null to send JSON null.
124
+ * @param {string} [auditMessage] - Audit message for this write
125
+ * @param {object} [opts]
126
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
127
+ * @returns {Promise<Created>}
128
+ */
129
+ create: (
130
+ tokenLayerId,
131
+ text,
132
+ begin,
133
+ end,
134
+ precedence,
135
+ metadata,
136
+ auditMessage,
137
+ { id } = {},
138
+ ) =>
139
+ client._request("POST", "/api/v1/tokens", {
140
+ auditMessage,
141
+ body: bodyOf({
142
+ id,
143
+ "token-layer-id": tokenLayerId,
144
+ text,
145
+ begin,
146
+ end,
147
+ precedence,
148
+ metadata,
149
+ }),
150
+ }),
151
+ /**
152
+ * Update a token.
153
+ * @param {string} tokenId - The token ID
154
+ * @param {number} [begin] - New start offset, inclusive (Unicode code points)
155
+ * @param {number} [end] - New end offset, exclusive (Unicode code points)
156
+ * @param {?number} [precedence] - Ordering precedence. Omit (undefined)
157
+ * to leave unchanged; pass a number to set; pass null explicitly to
158
+ * CLEAR it (revert to no explicit ordering). bodyOf keeps null but
159
+ * drops undefined, so the three cases map correctly to the server.
160
+ * @param {string} [auditMessage] - Audit message for this write
161
+ * @returns {Promise<Token>}
162
+ */
163
+ update: (tokenId, begin, end, precedence, auditMessage) =>
164
+ client._request("PATCH", `/api/v1/tokens/${tokenId}`, {
165
+ auditMessage,
166
+ body: bodyOf({ begin, end, precedence }),
167
+ }),
168
+ /**
169
+ * Delete a token and remove it from any spans. If this causes a span to
170
+ * have no remaining tokens, the span will also be deleted.
171
+ * @param {string} tokenId - The token ID
172
+ * @param {string} [auditMessage] - Audit message for this write
173
+ * @returns {Promise<void>}
174
+ */
175
+ delete: (tokenId, auditMessage) =>
176
+ client._request("DELETE", `/api/v1/tokens/${tokenId}`, { auditMessage }),
177
+ /**
178
+ * Create multiple tokens in a single operation.
179
+ * @param {Array} body - The tokens to create, each as its single create takes it
180
+ * @param {string} [auditMessage] - Audit message for this write
181
+ * @returns {Promise<{ids: string[]}>} The created entity IDs, in input order.
182
+ */
183
+ bulkCreate: (body, auditMessage) =>
184
+ client._request("POST", "/api/v1/tokens/bulk", { auditMessage, body }),
185
+ /**
186
+ * Delete multiple tokens in a single operation. Provide an array of IDs.
187
+ * @param {Array} body - The IDs of the tokens to delete
188
+ * @param {string} [auditMessage] - Audit message for this write
189
+ * @returns {Promise<void>}
190
+ */
191
+ bulkDelete: (body, auditMessage) =>
192
+ client._request("DELETE", "/api/v1/tokens/bulk", { auditMessage, body }),
193
+ /**
194
+ * Update many tokens in a single operation: patch metadata.
195
+ * @param {Array} body - Objects of the shape `{id, metadata}`. `metadata` is a list of metadata ops, as for patchMetadata. The tokens may lie in several documents of one project; every document touched has its version bumped and every new version comes back in `X-Document-Versions` (past fifty documents, only their number, in `X-Document-Versions-Omitted`). A `document-version` precondition is accepted only when every entry lies in one document. An unknown id refuses the whole update.
196
+ * @param {string} [auditMessage] - Audit message for this write
197
+ * @returns {Promise<{count: number}>} How many tokens were updated.
198
+ */
199
+ bulkUpdate: (body, auditMessage) =>
200
+ client._request("PATCH", "/api/v1/tokens/bulk", {
201
+ auditMessage,
202
+ body,
203
+ }),
204
+ /**
205
+ * Split a token at a Unicode code-point offset. A new token is made for one
206
+ * half and its ID is returned. The original token keeps its ID, spans and
207
+ * vocab-links on the left half, or on the right half with `keep: "right"`.
208
+ * @param {string} tokenId - The token ID
209
+ * @param {number} position - Code-point offset to split at (strictly between begin and end)
210
+ * @param {string} [auditMessage] - Audit message for this write
211
+ * @param {{id?: string, keep?: "left"|"right"}} [options] - `id`: the new
212
+ * token's id, a UUIDv7 this client minted. `keep`: the half the original token
213
+ * (its id, spans, vocab-links, comments and metadata) stays on, `"left"` by
214
+ * default. With `"right"` the new token, whose id is answered, is the left
215
+ * half. A relation layer whose relations must stay inside one token
216
+ * of this layer declares a same-ancestor constraint, and the server deletes
217
+ * the relations the split leaves crossing in the same transaction.
218
+ * @returns {Promise<Created>}
219
+ */
220
+ split: (
221
+ tokenId,
222
+ position,
223
+ auditMessage,
224
+ { id, keep } = {},
225
+ ) =>
226
+ client._request("POST", `/api/v1/tokens/${tokenId}/split`, {
227
+ auditMessage,
228
+ body: bodyOf({ id, keep, position }),
229
+ }),
230
+ /**
231
+ * Merge two tokens. The left token (smaller begin) survives with the combined
232
+ * extent; the right is deleted and its spans/vocab-links are reparented to the left.
233
+ * On partitioning layers the tokens must be adjacent; on non-overlapping layers the
234
+ * merged extent must not engulf a third token.
235
+ * @param {string} tokenId - The anchor token ID
236
+ * @param {string} otherTokenId - The other token to merge in
237
+ * @param {string} [auditMessage] - Audit message for this write
238
+ * @returns {Promise<Token>}
239
+ */
240
+ merge: (tokenId, otherTokenId, auditMessage) =>
241
+ client._request("POST", `/api/v1/tokens/${tokenId}/merge`, {
242
+ auditMessage,
243
+ body: bodyOf({ "other-token-id": otherTokenId }),
244
+ }),
245
+ /**
246
+ * Shift a token's boundary. On partitioning layers the adjacent token is
247
+ * auto-adjusted to preserve the partition; on non-overlapping layers a shift that
248
+ * would create an overlap is rejected.
249
+ * @param {string} tokenId - The token ID
250
+ * @param {number} [begin] - New start offset, inclusive (Unicode code points)
251
+ * @param {number} [end] - New end offset, exclusive (Unicode code points)
252
+ * @param {string} [auditMessage] - Audit message for this write
253
+ * @returns {Promise<Token>}
254
+ */
255
+ shift: (tokenId, begin, end, auditMessage) =>
256
+ client._request("POST", `/api/v1/tokens/${tokenId}/shift`, {
257
+ auditMessage,
258
+ body: bodyOf({ begin, end }),
259
+ }),
260
+ ...metadataMethods(client, "tokens"),
261
+ };
262
+ }
263
+
264
+ /** @param {import("./client.js").PlaidClient} client */
265
+ export function spansApi(client) {
266
+ return {
267
+ /**
268
+ * Get a span by ID.
269
+ * @param {string} spanId - The span ID
270
+ * @returns {Promise<Span>}
271
+ */
272
+ get: (spanId) =>
273
+ client._request("GET", `/api/v1/spans/${spanId}`),
274
+ /**
275
+ * Create a new span. A span holds a primary atomic value and optional
276
+ * metadata, and must at all times be associated with one or more tokens.
277
+ * @param {string} spanLayerId - The span layer ID
278
+ * @param {Array} tokens - The tokens
279
+ * @param {any} value - The value
280
+ * @param {any} [metadata] - Metadata map. Omit to leave unset; pass null to send JSON null.
281
+ * @param {string} [auditMessage] - Audit message for this write
282
+ * @param {object} [opts]
283
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
284
+ * @returns {Promise<Created>}
285
+ */
286
+ create: (spanLayerId, tokens, value, metadata, auditMessage, { id } = {}) =>
287
+ client._request("POST", "/api/v1/spans", {
288
+ auditMessage,
289
+ body: bodyOf({
290
+ id,
291
+ "span-layer-id": spanLayerId,
292
+ tokens,
293
+ value,
294
+ metadata,
295
+ }),
296
+ }),
297
+ /**
298
+ * Update a span's value.
299
+ * @param {string} spanId - The span ID
300
+ * @param {any} value - The value
301
+ * @param {string} [auditMessage] - Audit message for this write
302
+ * @returns {Promise<Span>}
303
+ */
304
+ update: (spanId, value, auditMessage) =>
305
+ client._request("PATCH", `/api/v1/spans/${spanId}`, {
306
+ auditMessage,
307
+ body: bodyOf({ value }),
308
+ }),
309
+ /**
310
+ * Delete a span.
311
+ * @param {string} spanId - The span ID
312
+ * @param {string} [auditMessage] - Audit message for this write
313
+ * @returns {Promise<void>}
314
+ */
315
+ delete: (spanId, auditMessage) =>
316
+ client._request("DELETE", `/api/v1/spans/${spanId}`, { auditMessage }),
317
+ /**
318
+ * Create multiple spans in a single operation.
319
+ * @param {Array} body - The spans to create, each as its single create takes it
320
+ * @param {string} [auditMessage] - Audit message for this write
321
+ * @returns {Promise<{ids: string[]}>} The created entity IDs, in input order.
322
+ */
323
+ bulkCreate: (body, auditMessage) =>
324
+ client._request("POST", "/api/v1/spans/bulk", { auditMessage, body }),
325
+ /**
326
+ * Delete multiple spans in a single operation. Provide an array of IDs.
327
+ * @param {Array} body - The IDs of the spans to delete
328
+ * @param {string} [auditMessage] - Audit message for this write
329
+ * @returns {Promise<void>}
330
+ */
331
+ bulkDelete: (body, auditMessage) =>
332
+ client._request("DELETE", "/api/v1/spans/bulk", { auditMessage, body }),
333
+ /**
334
+ * Update many spans in a single operation: set values and/or patch metadata.
335
+ * @param {Array} body - Objects of the shape `{id, value?, metadata?}`. `value` is set only when the key is present (null sends JSON null); `metadata` is a list of metadata ops, as for patchMetadata. The spans may lie in several documents of one project; every document touched has its version bumped and every new version comes back in `X-Document-Versions` (past fifty documents, only their number, in `X-Document-Versions-Omitted`). A `document-version` precondition is accepted only when every entry lies in one document. An unknown id refuses the whole update.
336
+ * @param {string} [auditMessage] - Audit message for this write
337
+ * @returns {Promise<{count: number}>} How many spans were updated.
338
+ */
339
+ bulkUpdate: (body, auditMessage) =>
340
+ client._request("PATCH", "/api/v1/spans/bulk", {
341
+ auditMessage,
342
+ body,
343
+ }),
344
+ /**
345
+ * Replace tokens for a span.
346
+ * @param {string} spanId - The span ID
347
+ * @param {Array} tokens - The tokens
348
+ * @param {string} [auditMessage] - Audit message for this write
349
+ * @returns {Promise<Span>}
350
+ */
351
+ setTokens: (spanId, tokens, auditMessage) =>
352
+ client._request("PUT", `/api/v1/spans/${spanId}/tokens`, {
353
+ auditMessage,
354
+ body: bodyOf({ tokens }),
355
+ }),
356
+ ...metadataMethods(client, "spans"),
357
+ };
358
+ }
359
+
360
+ /** @param {import("./client.js").PlaidClient} client */
361
+ export function relationsApi(client) {
362
+ return {
363
+ /**
364
+ * Get a relation by ID.
365
+ * @param {string} relationId - The relation ID
366
+ * @returns {Promise<Relation>}
367
+ */
368
+ get: (relationId) =>
369
+ client._request("GET", `/api/v1/relations/${relationId}`),
370
+ /**
371
+ * Create a new relation. A relation is a directed edge between two spans
372
+ * with a value, useful for expressing phenomena such as syntactic or
373
+ * semantic relations.
374
+ * @param {string} relationLayerId - The relation layer ID
375
+ * @param {string} source - The source span ID
376
+ * @param {string} target - The target span ID
377
+ * @param {any} value - The value
378
+ * @param {any} [metadata] - Metadata map. Omit to leave unset; pass null to send JSON null.
379
+ * @param {string} [auditMessage] - Audit message for this write
380
+ * @param {object} [opts]
381
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
382
+ * @returns {Promise<Created>}
383
+ */
384
+ create: (
385
+ relationLayerId,
386
+ source,
387
+ target,
388
+ value,
389
+ metadata,
390
+ auditMessage,
391
+ { id } = {},
392
+ ) =>
393
+ client._request("POST", "/api/v1/relations", {
394
+ auditMessage,
395
+ body: bodyOf({
396
+ id,
397
+ "relation-layer-id": relationLayerId,
398
+ source,
399
+ target,
400
+ value,
401
+ metadata,
402
+ }),
403
+ }),
404
+ /**
405
+ * Update a relation's value.
406
+ * @param {string} relationId - The relation ID
407
+ * @param {any} value - The value
408
+ * @param {string} [auditMessage] - Audit message for this write
409
+ * @returns {Promise<Relation>}
410
+ */
411
+ update: (relationId, value, auditMessage) =>
412
+ client._request("PATCH", `/api/v1/relations/${relationId}`, {
413
+ auditMessage,
414
+ body: bodyOf({ value }),
415
+ }),
416
+ /**
417
+ * Delete a relation.
418
+ * @param {string} relationId - The relation ID
419
+ * @param {string} [auditMessage] - Audit message for this write
420
+ * @returns {Promise<void>}
421
+ */
422
+ delete: (relationId, auditMessage) =>
423
+ client._request("DELETE", `/api/v1/relations/${relationId}`, {
424
+ auditMessage,
425
+ }),
426
+ /**
427
+ * Create multiple relations in a single operation.
428
+ * @param {Array} body - The relations to create, each as its single create takes it
429
+ * @param {string} [auditMessage] - Audit message for this write
430
+ * @returns {Promise<{ids: string[]}>} The created entity IDs, in input order.
431
+ */
432
+ bulkCreate: (body, auditMessage) =>
433
+ client._request("POST", "/api/v1/relations/bulk", { auditMessage, body }),
434
+ /**
435
+ * Delete multiple relations in a single operation. Provide an array of IDs.
436
+ * @param {Array} body - The IDs of the relations to delete
437
+ * @param {string} [auditMessage] - Audit message for this write
438
+ * @returns {Promise<void>}
439
+ */
440
+ bulkDelete: (body, auditMessage) =>
441
+ client._request("DELETE", "/api/v1/relations/bulk", {
442
+ auditMessage,
443
+ body,
444
+ }),
445
+ /**
446
+ * Update many relations in a single operation: set values and/or patch metadata.
447
+ * @param {Array} body - Objects of the shape `{id, value?, metadata?}`. `value` is set only when the key is present (null sends JSON null); `metadata` is a list of metadata ops, as for patchMetadata. The relations may lie in several documents of one project; every document touched has its version bumped and every new version comes back in `X-Document-Versions` (past fifty documents, only their number, in `X-Document-Versions-Omitted`). A `document-version` precondition is accepted only when every entry lies in one document. An unknown id refuses the whole update.
448
+ * @param {string} [auditMessage] - Audit message for this write
449
+ * @returns {Promise<{count: number}>} How many relations were updated.
450
+ */
451
+ bulkUpdate: (body, auditMessage) =>
452
+ client._request("PATCH", "/api/v1/relations/bulk", {
453
+ auditMessage,
454
+ body,
455
+ }),
456
+ /**
457
+ * Update the target span of a relation.
458
+ * @param {string} relationId - The relation ID
459
+ * @param {string} spanId - The span ID
460
+ * @param {string} [auditMessage] - Audit message for this write
461
+ * @returns {Promise<Relation>}
462
+ */
463
+ setTarget: (relationId, spanId, auditMessage) =>
464
+ client._request("PUT", `/api/v1/relations/${relationId}/target`, {
465
+ auditMessage,
466
+ body: bodyOf({ "span-id": spanId }),
467
+ }),
468
+ /**
469
+ * Update the source span of a relation.
470
+ * @param {string} relationId - The relation ID
471
+ * @param {string} spanId - The span ID
472
+ * @param {string} [auditMessage] - Audit message for this write
473
+ * @returns {Promise<Relation>}
474
+ */
475
+ setSource: (relationId, spanId, auditMessage) =>
476
+ client._request("PUT", `/api/v1/relations/${relationId}/source`, {
477
+ auditMessage,
478
+ body: bodyOf({ "span-id": spanId }),
479
+ }),
480
+ ...metadataMethods(client, "relations"),
481
+ };
482
+ }
483
+
484
+ /** @param {import("./client.js").PlaidClient} client */
485
+ export function vocabLinksApi(client) {
486
+ return {
487
+ /**
488
+ * Get a vocab link by ID
489
+ * @param {string} id - The resource ID
490
+ * @returns {Promise<VocabLink>}
491
+ */
492
+ get: (id) =>
493
+ client._request("GET", `/api/v1/vocab-links/${id}`),
494
+ /**
495
+ * Create a new vocab link between tokens and a vocab item.
496
+ * @param {string} vocabItem - The vocab item to link
497
+ * @param {Array} tokens - The tokens to link
498
+ * @param {any} [metadata] - Metadata for the link. Omit to leave unset; pass null to send JSON null.
499
+ * @param {string} [auditMessage] - Audit message for this write
500
+ * @param {object} [opts]
501
+ * @param {string} [opts.id] - The new entity's id, minted by the caller (see uuidv7)
502
+ * @returns {Promise<Created>}
503
+ */
504
+ create: (vocabItem, tokens, metadata, auditMessage, { id } = {}) =>
505
+ client._request("POST", "/api/v1/vocab-links", {
506
+ auditMessage,
507
+ body: bodyOf({ id, "vocab-item": vocabItem, tokens, metadata }),
508
+ }),
509
+ /**
510
+ * Delete a vocab link
511
+ * @param {string} id - The resource ID
512
+ * @param {string} [auditMessage] - Audit message for this write
513
+ * @returns {Promise<void>}
514
+ */
515
+ delete: (id, auditMessage) =>
516
+ client._request("DELETE", `/api/v1/vocab-links/${id}`, { auditMessage }),
517
+ /**
518
+ * Create multiple vocab links in a single operation. Entries may
519
+ * reference different vocab items, but all tokens across the call must
520
+ * belong to one document.
521
+ * @param {Array<{vocabItem: string, tokens: string[], metadata?: any}>} body - The vocab links to create
522
+ * @param {string} [auditMessage] - Audit message for this write
523
+ * @returns {Promise<{ids: string[]}>} The created entity IDs, in input order.
524
+ */
525
+ bulkCreate: (body, auditMessage) =>
526
+ client._request("POST", "/api/v1/vocab-links/bulk", {
527
+ auditMessage,
528
+ body,
529
+ }),
530
+ /**
531
+ * Delete multiple vocab links in a single operation. Provide an array of IDs.
532
+ * @param {string[]} body - The vocab link IDs to delete
533
+ * @param {string} [auditMessage] - Audit message for this write
534
+ * @returns {Promise<void>}
535
+ */
536
+ bulkDelete: (body, auditMessage) =>
537
+ client._request("DELETE", "/api/v1/vocab-links/bulk", {
538
+ auditMessage,
539
+ body,
540
+ }),
541
+ ...metadataMethods(client, "vocab-links"),
542
+ };
543
+ }