@larc-iu/plaid-client 0.2.0-alpha.23 → 0.2.0-alpha.29

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.
package/index.d.ts DELETED
@@ -1,2026 +0,0 @@
1
- /**
2
- * A config write's compare-and-set. With `expected` present (null or
3
- * undefined for a key that was absent) the write is refused with a 409 when
4
- * the stored value is no longer `expected`.
5
- */
6
- interface ConfigWriteOptions {
7
- expected?: any;
8
- }
9
-
10
- /** A single page of a cursor-paginated collection. */
11
- interface Page<T = any> {
12
- entries: T[];
13
- nextCursor: string | null;
14
- }
15
-
16
- /** One choice for an `enum` / `multiselect` service parameter. */
17
- interface ServiceParamOption {
18
- value: string;
19
- label: string;
20
- }
21
-
22
- /** A single user-controllable argument a service advertises. */
23
- interface ServiceParam {
24
- /** Key the value is sent under in the request payload. */
25
- key: string;
26
- label: string;
27
- type: "string" | "number" | "boolean" | "enum" | "multiselect" | "field";
28
- description?: string;
29
- default?: any;
30
- required?: boolean;
31
- /** Required for `enum` / `multiselect`. */
32
- options?: ServiceParamOption[];
33
- /** `number` only. */
34
- min?: number;
35
- max?: number;
36
- step?: number;
37
- /** `number` only: render as a slider to drag rather than a box to type in. */
38
- slider?: boolean;
39
- /** `string` only. */
40
- placeholder?: string;
41
- multiline?: boolean;
42
- /**
43
- * `field` only: the scope of the project's annotation fields the value names
44
- * one of. A `field` value is a string everywhere else.
45
- */
46
- scope?: "Sentence" | "Word" | "Morpheme";
47
- }
48
-
49
- /** A service's standardized self-description (lives in `extras`). */
50
- interface ServiceExtras {
51
- schemaVersion?: number;
52
- /** Tasks this service serves; from the TASKS vocabulary. */
53
- tasks?: string[];
54
- /** Rich human description (markdown), beyond the short `description`. */
55
- summary?: string;
56
- /** Ordered parameter schema, rendered into a form by the UI. */
57
- parameters?: ServiceParam[];
58
- [key: string]: any;
59
- }
60
-
61
- interface ServiceInfo {
62
- serviceId: string;
63
- serviceName: string;
64
- description: string;
65
- extras?: ServiceExtras;
66
- }
67
-
68
- interface DiscoveredService {
69
- serviceId: string;
70
- serviceName: string;
71
- description: string;
72
- extras: ServiceExtras;
73
- /** true while the service holds an open request channel; false for previously-seen offline services. */
74
- online: boolean;
75
- /** ISO-8601 stamp of when the service was last seen alive, or null/undefined if never persisted. */
76
- lastSeenAt?: string | null;
77
- }
78
-
79
- interface ServiceRegistration {
80
- stop(): void;
81
- /** Still serving, including while retrying a channel through a server restart. */
82
- isRunning(): boolean;
83
- /** Channel open right now, i.e. the server currently sees this service as online. */
84
- isConnected(): boolean;
85
- serviceInfo: ServiceInfo & { extras: any };
86
- }
87
-
88
- /** Connection-state transitions reported by a service registration. */
89
- /** "stopped": the server refused the channel for a reason retrying cannot fix (a revoked token, no write access, no such project), which ends the registration. */
90
- type ServiceStatusEvent = "registered" | "reconnected" | "disconnected" | "stopped";
91
-
92
- interface ResponseHelper {
93
- requestId: string;
94
- requesterId: string | null;
95
- /** True once the requester has asked this request to stop. */
96
- readonly cancelled: boolean;
97
- /**
98
- * Report progress — and a cancellation CHECKPOINT: throws
99
- * `ServiceCancelled` once a stop has been asked for, which is what makes a
100
- * service that already reports progress cancellable for free.
101
- */
102
- progress(percent: number, message: string, extra?: Record<string, any>): void;
103
- /** Stop here if the requester has asked the request to stop. */
104
- raiseIfCancelled(): void;
105
- /** Run `fn` as a stretch that must finish once begun, usually the writes. */
106
- critical<T>(fn: () => T | Promise<T>): Promise<T>;
107
- complete(data: any): void;
108
- /** End the request because it was asked to stop; result carries `stopped: true`. */
109
- stopped(data?: any): void;
110
- error(error: string | Error): void;
111
- }
112
-
113
- /** Thrown inside a handler when the requester has asked it to stop. */
114
- export class ServiceCancelled extends Error {
115
- constructor(message?: string);
116
- }
117
-
118
- /** The key a run's stored record names its requester under. */
119
- export const REQUESTED_BY: "requestedBy";
120
-
121
- /** The person who asked for one service run. Both fields are null when nobody asked. */
122
- export interface Requester {
123
- id: string | null;
124
- name: string | null;
125
- /** `"<text>, requested by <name>"`, or `text` when nobody asked. */
126
- label(text: string): string;
127
- /** `{ id, name }` for a stored report, or null when nobody asked. */
128
- record(): { id: string; name: string | null } | null;
129
- /** A machine stamp's `provDetail` with `requestedBy: <id>` added. */
130
- detail(detail?: Record<string, any>): Record<string, any>;
131
- }
132
-
133
- export function makeRequester(id?: string | null, name?: string | null): Requester;
134
-
135
- /** The requester of one request, from the `requesterId` in a `serve` handler's data, named by display name. */
136
- export function requesterOf(client: { users: { get(id: string): Promise<any> } }, data: any): Promise<Requester>;
137
-
138
- /** The cancellation half of a responseHelper, on its own. */
139
- export function createCancelScope(isCancelled: () => boolean): {
140
- readonly cancelled: boolean;
141
- raiseIfCancelled(): void;
142
- critical<T>(fn: () => T | Promise<T>): Promise<T>;
143
- };
144
-
145
- interface SSEConnection {
146
- close(): void;
147
- getStats(): any;
148
- readyState: number;
149
- /**
150
- * Once CLOSED, why: null when this side closed it. A refused stream's error
151
- * carries the HTTP `status`, and one the server ended is named "StreamClosed".
152
- */
153
- error: (Error & { status?: number }) | null;
154
- }
155
-
156
- interface VocabLinksBundle {
157
- create(
158
- vocabItem: string,
159
- tokens: any[],
160
- metadata?: any,
161
- auditMessage?: string,
162
- opts?: { id?: string },
163
- ): Promise<any>;
164
- bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
165
- bulkDelete(body: any[], auditMessage?: string): Promise<void>;
166
- setMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
167
- deleteMetadata(id: string, auditMessage?: string): Promise<any>;
168
- patchMetadata(id: string, body: MetadataOp[], auditMessage?: string): Promise<any>;
169
- get(id: string): Promise<any>;
170
- delete(id: string, auditMessage?: string): Promise<any>;
171
- }
172
-
173
- /** What `vocabLayers.restoreItem` did, or with `dryRun` would do. */
174
- interface VocabItemRestoreSummary {
175
- /** The entry was gone and came back under its old id. */
176
- inserted: boolean;
177
- /** A living entry's form was set back. */
178
- form: boolean;
179
- /** A living entry's fields were set back. */
180
- metadata: boolean;
181
- /** 0 when nothing changes. */
182
- total: number;
183
- }
184
-
185
- interface VocabLayersBundle {
186
- /** `asOf` reads the vocabulary as it was at that instant. */
187
- get(id: string, includeItems?: boolean, asOf?: string): Promise<any>;
188
- /** One entry as it was at `asOf`, also when it has been deleted since. */
189
- getItemAt(id: string, itemId: string, asOf: string): Promise<any>;
190
- /** `itemId` keeps only the changes that wrote that one entry. */
191
- audit(
192
- id: string,
193
- startTime?: string,
194
- endTime?: string,
195
- opTypes?: string[] | string,
196
- itemId?: string,
197
- kinds?: OperationKind[] | string,
198
- ): Promise<any[]>;
199
- auditPage(id: string, opts?: AuditPageOptions & { itemId?: string }): Promise<Page>;
200
- /** Put one entry back as it was at `asOf`. Maintainers of the vocabulary only. */
201
- restoreItem(
202
- id: string,
203
- itemId: string,
204
- asOf: string,
205
- options?: { dryRun?: boolean },
206
- auditMessage?: string,
207
- ): Promise<VocabItemRestoreSummary>;
208
- delete(id: string, auditMessage?: string): Promise<any>;
209
- update(id: string, name: string, auditMessage?: string): Promise<any>;
210
- setConfig(
211
- id: string,
212
- namespace: string,
213
- configKey: string,
214
- configValue: any,
215
- auditMessage?: string,
216
- options?: ConfigWriteOptions,
217
- ): Promise<any>;
218
- deleteConfig(
219
- id: string,
220
- namespace: string,
221
- configKey: string,
222
- auditMessage?: string,
223
- options?: ConfigWriteOptions,
224
- ): Promise<any>;
225
- list(): Promise<any[]>;
226
- listPage(opts?: { limit?: number; cursor?: string }): Promise<Page>;
227
- iterPages(opts?: { pageSize?: number }): AsyncGenerator<any[]>;
228
- create(name: string, auditMessage?: string, opts?: { id?: string }): Promise<any>;
229
- addMaintainer(
230
- id: string,
231
- userId: string,
232
- auditMessage?: string,
233
- ): Promise<any>;
234
- removeMaintainer(
235
- id: string,
236
- userId: string,
237
- auditMessage?: string,
238
- ): Promise<any>;
239
- }
240
-
241
- interface RelationsBundle {
242
- setMetadata(
243
- relationId: string,
244
- body: any,
245
- auditMessage?: string,
246
- ): Promise<any>;
247
- deleteMetadata(relationId: string, auditMessage?: string): Promise<any>;
248
- patchMetadata(
249
- relationId: string,
250
- body: MetadataOp[],
251
- auditMessage?: string,
252
- ): Promise<any>;
253
- setTarget(
254
- relationId: string,
255
- spanId: string,
256
- auditMessage?: string,
257
- ): Promise<any>;
258
- get(relationId: string): Promise<any>;
259
- delete(relationId: string, auditMessage?: string): Promise<any>;
260
- update(relationId: string, value: any, auditMessage?: string): Promise<any>;
261
- setSource(
262
- relationId: string,
263
- spanId: string,
264
- auditMessage?: string,
265
- ): Promise<any>;
266
- create(
267
- layerId: string,
268
- sourceId: string,
269
- targetId: string,
270
- value: any,
271
- metadata?: any,
272
- auditMessage?: string,
273
- opts?: { id?: string },
274
- ): Promise<any>;
275
- bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
276
- bulkDelete(body: any[], auditMessage?: string): Promise<void>;
277
- bulkUpdate(body: any[], auditMessage?: string): Promise<{ count: number }>;
278
- }
279
-
280
- interface SpanLayersBundle {
281
- setConfig(
282
- spanLayerId: string,
283
- namespace: string,
284
- configKey: string,
285
- configValue: any,
286
- auditMessage?: string,
287
- options?: ConfigWriteOptions,
288
- ): Promise<any>;
289
- deleteConfig(
290
- spanLayerId: string,
291
- namespace: string,
292
- configKey: string,
293
- auditMessage?: string,
294
- options?: ConfigWriteOptions,
295
- ): Promise<any>;
296
- get(spanLayerId: string): Promise<any>;
297
- delete(spanLayerId: string, auditMessage?: string): Promise<any>;
298
- update(
299
- spanLayerId: string,
300
- name: string,
301
- auditMessage?: string,
302
- ): Promise<any>;
303
- create(
304
- tokenLayerId: string,
305
- name: string,
306
- auditMessage?: string,
307
- opts?: { id?: string },
308
- ): Promise<any>;
309
- shift(
310
- spanLayerId: string,
311
- direction: string,
312
- auditMessage?: string,
313
- ): Promise<any>;
314
- setConstraints(
315
- layerId: string,
316
- namespace: string,
317
- constraints: LayerConstraint[],
318
- auditMessage?: string,
319
- options?: ConstraintWriteOptions,
320
- ): Promise<{ constraints: Record<string, LayerConstraint[]> }>;
321
- deleteConstraints(
322
- layerId: string,
323
- namespace: string,
324
- auditMessage?: string,
325
- options?: ConstraintWriteOptions,
326
- ): Promise<any>;
327
- checkConstraints(
328
- layerId: string,
329
- constraints: LayerConstraint[],
330
- ): Promise<{ violations: ConstraintViolation[]; violationCount: number }>;
331
- repairConstraints(
332
- layerId: string,
333
- constraints: LayerConstraint[],
334
- auditMessage?: string,
335
- options?: { document?: string },
336
- ): Promise<{
337
- repaired: { document: string; constraint: string; deleted: number; joined: number }[];
338
- locked: { document: string; lockedBy: string }[];
339
- violations: ConstraintViolation[];
340
- violationCount: number;
341
- }>;
342
- }
343
-
344
- interface SpansBundle {
345
- setTokens(spanId: string, tokens: any[], auditMessage?: string): Promise<any>;
346
- create(
347
- spanLayerId: string,
348
- tokens: any[],
349
- value: any,
350
- metadata?: any,
351
- auditMessage?: string,
352
- opts?: { id?: string },
353
- ): Promise<any>;
354
- get(spanId: string): Promise<any>;
355
- delete(spanId: string, auditMessage?: string): Promise<any>;
356
- update(spanId: string, value: any, auditMessage?: string): Promise<any>;
357
- bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
358
- bulkDelete(body: any[], auditMessage?: string): Promise<void>;
359
- bulkUpdate(body: any[], auditMessage?: string): Promise<{ count: number }>;
360
- setMetadata(spanId: string, body: any, auditMessage?: string): Promise<any>;
361
- deleteMetadata(spanId: string, auditMessage?: string): Promise<any>;
362
- patchMetadata(spanId: string, body: MetadataOp[], auditMessage?: string): Promise<any>;
363
- }
364
-
365
- interface TextsBundle {
366
- setMetadata(textId: string, body: any, auditMessage?: string): Promise<any>;
367
- deleteMetadata(textId: string, auditMessage?: string): Promise<any>;
368
- patchMetadata(textId: string, body: MetadataOp[], auditMessage?: string): Promise<any>;
369
- create(
370
- textLayerId: string,
371
- documentId: string,
372
- body: string,
373
- metadata?: any,
374
- auditMessage?: string,
375
- opts?: { id?: string },
376
- ): Promise<any>;
377
- get(textId: string): Promise<any>;
378
- delete(textId: string, auditMessage?: string): Promise<any>;
379
- /** With `base` (a text's `digest`) the update applies only to that body. */
380
- update(textId: string, body: any, auditMessage?: string, opts?: { base?: string; versioned?: boolean }): Promise<any>;
381
- /** Edits made at the caret; with `base` they apply only to that body. Answers the text with `digest` and `reshape`. */
382
- edit(textId: string, edits: TextEditOp[], auditMessage?: string, opts?: { base?: string; versioned?: boolean }): Promise<any>;
383
- }
384
-
385
- interface UsersBundle {
386
- /** `q` narrows to users whose id or display name contains it (admin or maintainer). */
387
- list(opts?: { q?: string }): Promise<any[]>;
388
- listPage(opts?: { q?: string; limit?: number; cursor?: string }): Promise<Page>;
389
- iterPages(opts?: { q?: string; pageSize?: number }): AsyncGenerator<any[]>;
390
- create(
391
- email: string,
392
- password: string,
393
- isAdmin: boolean,
394
- displayName?: string,
395
- auditMessage?: string,
396
- ): Promise<any>;
397
- audit(
398
- userId: string,
399
- startTime?: string,
400
- endTime?: string,
401
- opTypes?: string[] | string,
402
- kinds?: OperationKind[] | string,
403
- ): Promise<any[]>;
404
- auditPage(userId: string, opts?: AuditPageOptions): Promise<Page>;
405
- get(id: string): Promise<any>;
406
- delete(id: string, auditMessage?: string): Promise<any>;
407
- activate(id: string, auditMessage?: string): Promise<any>;
408
- update(
409
- id: string,
410
- password?: string,
411
- displayName?: string,
412
- isAdmin?: boolean,
413
- auditMessage?: string,
414
- ): Promise<any>;
415
- /** URL for a user's profile picture, usable as an <img> src. Null when avatarHash is explicitly null. */
416
- avatarUrl(id: string, avatarHash?: string | null): string | null;
417
- getAvatar(id: string): Promise<any>;
418
- setAvatar(id: string, file: File | Blob, auditMessage?: string): Promise<any>;
419
- deleteAvatar(id: string, auditMessage?: string): Promise<any>;
420
- }
421
-
422
- interface UserDataEntry {
423
- key: string;
424
- updatedAt: string;
425
- /** Raised by one on every write of the entry. A new entry is 1. */
426
- version: number;
427
- value?: any;
428
- }
429
-
430
- interface UserDataOptions {
431
- prefix?: string;
432
- pattern?: string;
433
- includeValues?: boolean;
434
- }
435
-
436
- /** Private per-user key/value storage (owner or admin only; not audited). */
437
- interface UserDataBundle {
438
- list(
439
- userId: string,
440
- opts?: UserDataOptions & { pageSize?: number },
441
- ): Promise<UserDataEntry[]>;
442
- listPage(
443
- userId: string,
444
- opts?: UserDataOptions & { limit?: number; cursor?: string },
445
- ): Promise<Page<UserDataEntry>>;
446
- iterPages(
447
- userId: string,
448
- opts?: UserDataOptions & { pageSize?: number },
449
- ): AsyncGenerator<UserDataEntry[]>;
450
- get(userId: string, key: string): Promise<UserDataEntry & { value: any }>;
451
- /**
452
- * `version`: write only when the entry is still at this version (0: only
453
- * when there is none). Refused with 409, `error: "version-mismatch"` and the
454
- * stored `version` and `updatedAt` on the error's `responseData`, when
455
- * another write landed since.
456
- */
457
- put(
458
- userId: string,
459
- key: string,
460
- value: any,
461
- opts?: { version?: number },
462
- ): Promise<{ key: string; updatedAt: string; version: number }>;
463
- delete(userId: string, key: string): Promise<any>;
464
- }
465
-
466
- interface CommentFilters {
467
- documentId?: string;
468
- entityType?: CommentableType;
469
- entityId?: string;
470
- }
471
-
472
- /** Entities that can carry a comment. */
473
- type CommentableType =
474
- "document" | "text" | "token" | "span" | "relation" | "vocab-item";
475
-
476
- /**
477
- * One entry in a project's annotation manual: a short Markdown document
478
- * stating a convention the project follows. Read by the people on the
479
- * project, and by the assistant before it proposes anything.
480
- */
481
- interface Guideline {
482
- id: string;
483
- projectId: string;
484
- /** The handle the assistant asks for a guideline by. Not required to be unique. */
485
- title: string;
486
- /** The Markdown text. Present on a single read and on a list made with `includeBodies`. */
487
- body?: string;
488
- /** The body's length in characters. Present on a list made WITHOUT `includeBodies`. */
489
- bodyChars?: number;
490
- /** Whether the assistant is given this one in full on every turn. */
491
- pinned: boolean;
492
- createdAt: string;
493
- updatedAt: string;
494
- }
495
-
496
- interface GuidelinesBundle {
497
- create(
498
- projectId: string,
499
- title: string,
500
- opts?: { body?: string; pinned?: boolean; id?: string },
501
- auditMessage?: string,
502
- ): Promise<{ id: string }>;
503
- get(id: string): Promise<Guideline>;
504
- update(
505
- id: string,
506
- changes?: {
507
- title?: string;
508
- body?: string;
509
- pinned?: boolean;
510
- /** Write only if this is still the stored updatedAt; 409 otherwise. */
511
- expectedUpdatedAt?: string;
512
- },
513
- auditMessage?: string,
514
- ): Promise<Guideline>;
515
- delete(id: string, auditMessage?: string): Promise<any>;
516
- list(
517
- projectId: string,
518
- opts?: { includeBodies?: boolean },
519
- ): Promise<Guideline[]>;
520
- listPage(
521
- projectId: string,
522
- opts?: { includeBodies?: boolean; limit?: number; cursor?: string },
523
- ): Promise<Page<Guideline>>;
524
- iterPages(
525
- projectId: string,
526
- opts?: { includeBodies?: boolean; pageSize?: number },
527
- ): AsyncGenerator<Guideline[]>;
528
- }
529
-
530
- interface Comment {
531
- id: string;
532
- /** The owning project, or null for a comment on a vocabulary entry. */
533
- projectId: string | null;
534
- /** The owning document, or null for a comment on a vocabulary entry. */
535
- documentId: string | null;
536
- /** The owning vocab layer, set only for a comment on a vocabulary entry. */
537
- vocabLayerId: string | null;
538
- entityType: CommentableType;
539
- entityId: string;
540
- /**
541
- * What the comment is about, in words, captured when it was posted. A
542
- * comment outlives its anchor, and this is what is left to show once the
543
- * anchor has been deleted.
544
- */
545
- anchorLabel: string | null;
546
- authorId: string;
547
- body: string;
548
- createdAt: string;
549
- updatedAt: string;
550
- /** True once the body has been rewritten since it was posted. */
551
- edited: boolean;
552
- }
553
-
554
- /** A research-telemetry event type (core manual, "Research telemetry"). */
555
- type ClientEventType =
556
- | "suggestion.shown"
557
- | "suggestion.adopted"
558
- | "suggestion.dismissed"
559
- | "plan.opened";
560
-
561
- interface ClientEventFields {
562
- projectId: string;
563
- documentId?: string;
564
- targetId?: string;
565
- /** Keyed by single lowercase words: value, source, field, written, conversation. */
566
- data?: Record<string, any>;
567
- }
568
-
569
- interface ClientEvent {
570
- id: number;
571
- projectId: string;
572
- documentId: string | null;
573
- userId: string;
574
- type: ClientEventType;
575
- targetId: string | null;
576
- data: Record<string, any> | null;
577
- clientTs: string | null;
578
- ts: string;
579
- }
580
-
581
- interface ClientEventFilters {
582
- types?: ClientEventType | ClientEventType[] | string;
583
- startTime?: string;
584
- endTime?: string;
585
- }
586
-
587
- interface EventsBundle {
588
- /** Buffer one event; never throws. False when not recorded (switch off, a repeat shown). */
589
- record(type: ClientEventType, fields: ClientEventFields): boolean;
590
- flush(): void;
591
- setEnabled(projectId: string, on: boolean): void;
592
- create(
593
- projectId: string,
594
- events: Array<{
595
- type: ClientEventType;
596
- documentId?: string;
597
- targetId?: string;
598
- data?: Record<string, any>;
599
- clientTs?: string;
600
- }>,
601
- ): Promise<{ count: number }>;
602
- list(projectId: string, filters?: ClientEventFilters): Promise<ClientEvent[]>;
603
- listPage(
604
- projectId: string,
605
- opts?: ClientEventFilters & { limit?: number; cursor?: string },
606
- ): Promise<Page<ClientEvent>>;
607
- iterPages(
608
- projectId: string,
609
- opts?: ClientEventFilters & { pageSize?: number },
610
- ): AsyncGenerator<ClientEvent[]>;
611
- }
612
-
613
- interface CommentsBundle {
614
- create(
615
- entityType: CommentableType,
616
- entityId: string,
617
- body: string,
618
- opts?: { anchorLabel?: string; id?: string },
619
- ): Promise<Comment>;
620
- get(id: string): Promise<Comment>;
621
- update(id: string, body: string): Promise<Comment>;
622
- delete(id: string): Promise<any>;
623
- list(projectId: string, filters?: CommentFilters): Promise<Comment[]>;
624
- listPage(
625
- projectId: string,
626
- opts?: CommentFilters & { limit?: number; cursor?: string },
627
- ): Promise<Page<Comment>>;
628
- iterPages(
629
- projectId: string,
630
- opts?: CommentFilters & { pageSize?: number },
631
- ): AsyncGenerator<Comment[]>;
632
- /** `{entityId: count}`; keys are raw entity ids, never key-transformed. */
633
- counts(
634
- projectId: string,
635
- filters?: CommentFilters,
636
- ): Promise<Record<string, number>>;
637
- /** Comments on a vocabulary's entries, oldest first. */
638
- listInVocab(
639
- vocabId: string,
640
- filters?: { entityId?: string },
641
- ): Promise<Comment[]>;
642
- listInVocabPage(
643
- vocabId: string,
644
- opts?: { entityId?: string; limit?: number; cursor?: string },
645
- ): Promise<Page<Comment>>;
646
- iterInVocabPages(
647
- vocabId: string,
648
- opts?: { entityId?: string; pageSize?: number },
649
- ): AsyncGenerator<Comment[]>;
650
- /** `{entryId: count}` over a vocabulary; keys are raw entry ids. */
651
- countsInVocab(
652
- vocabId: string,
653
- filters?: { entityId?: string },
654
- ): Promise<Record<string, number>>;
655
- }
656
-
657
- interface ApiTokensBundle {
658
- list(userId: string): Promise<any[]>;
659
- listPage(
660
- userId: string,
661
- opts?: { limit?: number; cursor?: string },
662
- ): Promise<Page>;
663
- iterPages(
664
- userId: string,
665
- opts?: { pageSize?: number },
666
- ): AsyncGenerator<any[]>;
667
- create(
668
- userId: string,
669
- name: string,
670
- auditMessage?: string,
671
- ): Promise<{ id: string; name: string; token: string }>;
672
- revoke(userId: string, tokenId: string, auditMessage?: string): Promise<any>;
673
- }
674
-
675
- interface Invite {
676
- id: string;
677
- /** "signup" | "password-reset" */
678
- kind: string;
679
- /** "active" | "used" | "expired" | "revoked" | "inactive" */
680
- status: string;
681
- createdBy: string;
682
- createdAt: string;
683
- expiresAt: string;
684
- maxUses: number;
685
- uses: number;
686
- revokedAt: string | null;
687
- note: string | null;
688
- targetUserId: string | null;
689
- grantAdmin: boolean;
690
- projectId: string | null;
691
- projectRole: string | null;
692
- }
693
-
694
- interface InvitePreview {
695
- /** "signup" | "password-reset" */
696
- kind: string;
697
- /** "active" | "used" | "expired" | "revoked" | "inactive" */
698
- status: string;
699
- expiresAt: string;
700
- grantAdmin: boolean;
701
- projectName?: string;
702
- projectRole?: string;
703
- /** Present only for a password reset: the email of the account it belongs to. */
704
- email?: string;
705
- }
706
-
707
- interface CreateInviteOptions {
708
- projectId?: string;
709
- /** "reader" | "writer" | "maintainer" */
710
- projectRole?: string;
711
- grantAdmin?: boolean;
712
- /** Makes this a password reset for that user (admin only). */
713
- targetUserId?: string;
714
- maxUses?: number;
715
- ttlDays?: number;
716
- note?: string;
717
- }
718
-
719
- /** Server limits, as reported by /api/v1/info. An unset limit is absent. */
720
- interface ServerLimits {
721
- mediaFileBytes?: number;
722
- jsonBodyBytes?: number;
723
- batchOperations?: number;
724
- metadataDepth?: number;
725
- metadataKeyCount?: number;
726
- metadataStringLength?: number;
727
- metadataTotalBytes?: number;
728
- userDataValueBytes?: number;
729
- guidelineTitleLength?: number;
730
- guidelineBodyLength?: number;
731
- /** The shortest password the server accepts on any path. */
732
- passwordMinLength?: number;
733
- /** How long a document lock is held before it lapses. */
734
- lockExpirationMs?: number;
735
- }
736
-
737
- interface ServerHealth {
738
- ok: boolean;
739
- version: string;
740
- uptimeMs: number;
741
- audit: { dbSizeMb?: number; auditRows?: number; error?: string };
742
- }
743
-
744
- /** A document lock as the admin lock listing reports it. */
745
- interface DocumentLockInfo {
746
- documentId: string;
747
- userId: string;
748
- expiresAt: number;
749
- }
750
-
751
- interface RateLimitBucket {
752
- ip: string;
753
- userId?: string;
754
- failures: number;
755
- limit: number;
756
- blocked: boolean;
757
- }
758
-
759
- interface RateLimitSnapshot {
760
- windowMs: number;
761
- logins: RateLimitBucket[];
762
- ips: RateLimitBucket[];
763
- invites: RateLimitBucket[];
764
- }
765
-
766
- interface BackupStatus {
767
- enabled: boolean;
768
- directory: string;
769
- retention: number;
770
- time: string;
771
- backups: Array<{ name: string; bytes: number; modified: string }>;
772
- ok?: boolean;
773
- }
774
-
775
- interface ServerReport {
776
- version: string;
777
- jvm: {
778
- uptimeMs: number;
779
- startedAt: string;
780
- java: string;
781
- heapUsed: number;
782
- heapMax: number;
783
- };
784
- database: {
785
- path: string | null;
786
- bytes: number | null;
787
- walBytes: number | null;
788
- slowQueryThresholdMs?: number;
789
- journalMode?: string;
790
- maxPoolSize?: number;
791
- tables: Record<string, number | null>;
792
- };
793
- media: {
794
- directory: string;
795
- files: number;
796
- bytes: number;
797
- orphans: number;
798
- orphanBytes: number;
799
- };
800
- backup: BackupStatus;
801
- settings: Record<string, any>;
802
- }
803
-
804
- /** The signed-in user's sign-ins. Signing in is `PlaidClient.login`. */
805
- interface AuthBundle {
806
- /**
807
- * End every sign-in of this user on every device, this client's included.
808
- * Named API tokens are not affected. Goes out at once even on a batch.
809
- */
810
- logoutEverywhere(): Promise<void>;
811
- }
812
-
813
- /** Server-level facts. `info` is fetched at most once per client. */
814
- interface ServerBundle {
815
- info(): Promise<{ limits: ServerLimits }>;
816
- limits(): Promise<ServerLimits>;
817
- health(): Promise<ServerHealth>;
818
- }
819
-
820
- /** Instance-wide operations. Every method requires a global admin. */
821
- interface AdminBundle {
822
- server(): Promise<ServerReport>;
823
- backup(): Promise<BackupStatus>;
824
- locks(): Promise<{ entries: DocumentLockInfo[] }>;
825
- releaseLock(documentId: string): Promise<{ result: string }>;
826
- rateLimits(): Promise<RateLimitSnapshot>;
827
- clearRateLimits(opts?: {
828
- ip?: string;
829
- userId?: string;
830
- }): Promise<{ result: string }>;
831
- logs(opts?: {
832
- limit?: number;
833
- q?: string;
834
- level?: string;
835
- status?: string;
836
- user?: string;
837
- method?: string;
838
- }): Promise<LiveLog>;
839
- logFile(opts?: {
840
- lines?: number;
841
- }): Promise<{ file: string | null; lines: string[]; error?: string }>;
842
- userData(opts?: AdminUserDataOptions): Promise<AdminUserDataEntry[]>;
843
- userDataPage(
844
- opts?: AdminUserDataOptions & { limit?: number; cursor?: string },
845
- ): Promise<Page<AdminUserDataEntry>>;
846
- }
847
-
848
- /** One HTTP request as the log buffer holds it. */
849
- interface LoggedRequest {
850
- /** Epoch milliseconds. */
851
- ts: number;
852
- method: string;
853
- path: string;
854
- /** Query string with sensitive values replaced, or null. */
855
- query: string | null;
856
- /** Null when the handler threw before producing one. */
857
- status: number | null;
858
- ms: number;
859
- /** Null for a request nobody was authenticated for. */
860
- user: string | null;
861
- ip: string | null;
862
- /** Set when a named API token signed the request. */
863
- token: string | null;
864
- /** Exception class, when the handler threw. */
865
- error: string | null;
866
- }
867
-
868
- /** One log event that was not a request. */
869
- interface LoggedEvent {
870
- ts: number;
871
- level: string;
872
- ns: string;
873
- message: string;
874
- trace?: string;
875
- }
876
-
877
- /**
878
- * The live log. Requests and events are buffered separately, so a burst of
879
- * requests cannot evict an error.
880
- */
881
- interface LiveLog {
882
- requests: {
883
- entries: LoggedRequest[];
884
- /** How many passed the filters, which may exceed what `entries` holds. */
885
- matched: number;
886
- /** How many are buffered in total. */
887
- held: number;
888
- capacity: number;
889
- stats: {
890
- count: number;
891
- failures: number;
892
- serverErrors: number;
893
- p50: number | null;
894
- p95: number | null;
895
- max: number | null;
896
- perMinute: number | null;
897
- oldest: number | null;
898
- newest: number | null;
899
- };
900
- };
901
- events: {
902
- entries: LoggedEvent[];
903
- matched: number;
904
- held: number;
905
- capacity: number;
906
- /** Counts per level of what the search matched, before the level filter. */
907
- byLevel: Record<string, number>;
908
- };
909
- /** Absolute path of the configured log file, or null when logging to stdout. */
910
- file: string | null;
911
- }
912
-
913
- /** Narrowings for the cross-account private-data listing. */
914
- interface AdminUserDataOptions {
915
- /** Only keys starting with this literal head. */
916
- prefix?: string;
917
- /** Only keys matching this GLOB (`*` any run, `?` one character). */
918
- pattern?: string;
919
- includeValues?: boolean;
920
- }
921
-
922
- type AdminUserDataEntry = UserDataEntry & { userId: string };
923
-
924
- /** Options for a single page of any audit log. */
925
- interface AuditPageOptions {
926
- startTime?: string;
927
- endTime?: string;
928
- opTypes?: string[] | string;
929
- /** Only the entries of operations of these kinds, each whole. */
930
- kinds?: OperationKind[] | string;
931
- /** "desc" pages newest-first; a cursor belongs to the direction that made it. */
932
- order?: "asc" | "desc";
933
- limit?: number;
934
- cursor?: string;
935
- /** Keep only each entry's oldest N operations in `ops` (1..1000). Every entry has `opCount`. */
936
- opsLimit?: number;
937
- /** Read only this entry rather than a page. */
938
- entryId?: string;
939
- }
940
-
941
- /** One user's activity over a scope and window. */
942
- interface ActivityTallyRow {
943
- user: { id: string; displayName?: string };
944
- operations: number;
945
- changes: number;
946
- documents: number;
947
- firstTs: string;
948
- lastTs: string;
949
- byDay?: Array<{ date: string; changes: number }>;
950
- }
951
-
952
- /** Instance-wide audit reads and the per-user aggregate. */
953
- interface AuditBundle {
954
- /** Admin only. */
955
- list(opts?: {
956
- startTime?: string;
957
- endTime?: string;
958
- opTypes?: string[] | string;
959
- kinds?: OperationKind[] | string;
960
- }): Promise<any[]>;
961
- /** Admin only. */
962
- listPage(opts?: AuditPageOptions): Promise<Page>;
963
- /** Admin only. */
964
- iterPages(opts?: {
965
- startTime?: string;
966
- endTime?: string;
967
- opTypes?: string[] | string;
968
- kinds?: OperationKind[] | string;
969
- pageSize?: number;
970
- }): AsyncGenerator<any[]>;
971
- /** With projectId, open to that project's maintainers; without one, admin only. */
972
- tally(opts?: {
973
- projectId?: string;
974
- startTime?: string;
975
- endTime?: string;
976
- daily?: boolean;
977
- }): Promise<ActivityTallyRow[]>;
978
- }
979
-
980
- interface InvitesBundle {
981
- list(opts?: { projectId?: string; all?: boolean }): Promise<Invite[]>;
982
- listPage(opts?: {
983
- projectId?: string;
984
- all?: boolean;
985
- limit?: number;
986
- cursor?: string;
987
- }): Promise<Page>;
988
- iterPages(opts?: {
989
- projectId?: string;
990
- all?: boolean;
991
- pageSize?: number;
992
- }): AsyncGenerator<Invite[]>;
993
- /**
994
- * The `code` is returned ONCE and is not recoverable afterward. Needs a
995
- * signed-in session: a named API token cannot mint any invite (403).
996
- */
997
- create(
998
- opts?: CreateInviteOptions,
999
- auditMessage?: string,
1000
- ): Promise<Invite & { code: string }>;
1001
- revoke(id: string, auditMessage?: string): Promise<any>;
1002
- }
1003
-
1004
- interface TokenLayersBundle {
1005
- shift(
1006
- tokenLayerId: string,
1007
- direction: string,
1008
- auditMessage?: string,
1009
- ): Promise<any>;
1010
- create(
1011
- textLayerId: string,
1012
- name: string,
1013
- overlapMode?: string,
1014
- parentTokenLayerId?: string,
1015
- auditMessage?: string,
1016
- opts?: { id?: string },
1017
- ): Promise<any>;
1018
- setConfig(
1019
- tokenLayerId: string,
1020
- namespace: string,
1021
- configKey: string,
1022
- configValue: any,
1023
- auditMessage?: string,
1024
- options?: ConfigWriteOptions,
1025
- ): Promise<any>;
1026
- deleteConfig(
1027
- tokenLayerId: string,
1028
- namespace: string,
1029
- configKey: string,
1030
- auditMessage?: string,
1031
- options?: ConfigWriteOptions,
1032
- ): Promise<any>;
1033
- get(tokenLayerId: string): Promise<any>;
1034
- delete(tokenLayerId: string, auditMessage?: string): Promise<any>;
1035
- update(
1036
- tokenLayerId: string,
1037
- name: string,
1038
- auditMessage?: string,
1039
- ): Promise<any>;
1040
- setConstraints(
1041
- layerId: string,
1042
- namespace: string,
1043
- constraints: LayerConstraint[],
1044
- auditMessage?: string,
1045
- options?: ConstraintWriteOptions,
1046
- ): Promise<{ constraints: Record<string, LayerConstraint[]> }>;
1047
- deleteConstraints(
1048
- layerId: string,
1049
- namespace: string,
1050
- auditMessage?: string,
1051
- options?: ConstraintWriteOptions,
1052
- ): Promise<any>;
1053
- checkConstraints(
1054
- layerId: string,
1055
- constraints: LayerConstraint[],
1056
- ): Promise<{ violations: ConstraintViolation[]; violationCount: number }>;
1057
- repairConstraints(
1058
- layerId: string,
1059
- constraints: LayerConstraint[],
1060
- auditMessage?: string,
1061
- options?: { document?: string },
1062
- ): Promise<{
1063
- repaired: { document: string; constraint: string; deleted: number; joined: number }[];
1064
- locked: { document: string; lockedBy: string }[];
1065
- violations: ConstraintViolation[];
1066
- violationCount: number;
1067
- }>;
1068
- }
1069
-
1070
- /** Handle passed to a `documents.locked()` block. */
1071
- export declare class DocumentLock {
1072
- readonly documentId: string;
1073
- /** The holder id the acquire answered with. */
1074
- readonly lockId: string | null;
1075
- /** The DocumentLockLost if the lock lapsed, else null. */
1076
- readonly lost: DocumentLockLost | null;
1077
- /** Throw if the lock lapsed; call it between steps that have not written. */
1078
- raiseIfLost(): void;
1079
- }
1080
-
1081
- /** The lock a `documents.locked()` block was holding is no longer held. */
1082
- export declare class DocumentLockLost extends Error {
1083
- readonly name: "DocumentLockLost";
1084
- readonly documentId: string;
1085
- readonly cause?: unknown;
1086
- }
1087
-
1088
- interface DocumentsBundle {
1089
- checkLock(documentId: string): Promise<any>;
1090
- /**
1091
- * Take the lock as a new holder. The answer's `lockId` names it:
1092
- * `newLockId` when the client minted one, which makes a retried acquire
1093
- * idempotent and a lost answer releasable.
1094
- */
1095
- acquireLock(
1096
- documentId: string,
1097
- auditMessage?: string,
1098
- newLockId?: string,
1099
- ): Promise<any>;
1100
- /** Renew `lockId`'s lock while it is live. 423 once it has lapsed. */
1101
- renewLock(
1102
- documentId: string,
1103
- lockId: string,
1104
- auditMessage?: string,
1105
- ): Promise<any>;
1106
- releaseLock(
1107
- documentId: string,
1108
- lockId: string,
1109
- auditMessage?: string,
1110
- ): Promise<any>;
1111
- /**
1112
- * Hold the document's lock for the length of `fn`, renewing it while `fn`
1113
- * runs and releasing it on the way out. Rejects with a 423 if it is already
1114
- * held, and with DocumentLockLost if a renewal fails.
1115
- */
1116
- locked<T>(
1117
- documentId: string,
1118
- fn: (lock: DocumentLock) => T | Promise<T>,
1119
- options?: { keepAlive?: boolean },
1120
- ): Promise<T>;
1121
- getMedia(documentId: string): Promise<ArrayBuffer>;
1122
- uploadMedia(
1123
- documentId: string,
1124
- file: File,
1125
- auditMessage?: string,
1126
- options?: {
1127
- /** Called with the bytes sent so far as the file goes up (`total` is null when unknown). */
1128
- onProgress?: (progress: { loaded: number; total: number | null }) => void;
1129
- },
1130
- ): Promise<any>;
1131
- deleteMedia(
1132
- documentId: string,
1133
- auditMessage?: string,
1134
- options?: {
1135
- /** The recording meant, the `?v=` of the document's `mediaUrl`. A 409 when the stored one is another. */
1136
- mediaVersion?: string;
1137
- },
1138
- ): Promise<any>;
1139
- setMetadata(
1140
- documentId: string,
1141
- body: any,
1142
- auditMessage?: string,
1143
- ): Promise<any>;
1144
- deleteMetadata(documentId: string, auditMessage?: string): Promise<any>;
1145
- patchMetadata(
1146
- documentId: string,
1147
- body: MetadataOp[],
1148
- auditMessage?: string,
1149
- ): Promise<any>;
1150
- audit(
1151
- documentId: string,
1152
- startTime?: string,
1153
- endTime?: string,
1154
- opTypes?: string[] | string,
1155
- kinds?: OperationKind[] | string,
1156
- ): Promise<any[]>;
1157
- auditPage(documentId: string, opts?: AuditPageOptions): Promise<Page>;
1158
- /**
1159
- * `asOf` reads the document as it was at that instant. `layers` narrows a
1160
- * body read to the named layers (ids of any kind), and needs `includeBody`.
1161
- */
1162
- get(
1163
- documentId: string,
1164
- includeBody?: boolean,
1165
- asOf?: string,
1166
- layers?: string[] | string,
1167
- ): Promise<any>;
1168
- delete(documentId: string, auditMessage?: string): Promise<any>;
1169
- update(documentId: string, name: string, auditMessage?: string): Promise<any>;
1170
- create(
1171
- projectId: string,
1172
- name: string,
1173
- metadata?: any,
1174
- auditMessage?: string,
1175
- opts?: { id?: string },
1176
- ): Promise<any>;
1177
- /** Copy a document and everything in it into a new document of the same project. */
1178
- copy(
1179
- documentId: string,
1180
- name: string,
1181
- options?: { includeMedia?: boolean; id?: string },
1182
- auditMessage?: string,
1183
- ): Promise<{ id: string; mediaError?: string }>;
1184
- restore(
1185
- documentId: string,
1186
- asOf: string,
1187
- options?: { dryRun?: boolean },
1188
- auditMessage?: string,
1189
- ): Promise<any>;
1190
- }
1191
-
1192
- interface MessagesBundle {
1193
- /** Broadcast to the project's listeners. Never saved and never part of an operation. */
1194
- sendMessage(projectId: string, data: any): Promise<any>;
1195
- listen(
1196
- projectId: string,
1197
- onEvent: (eventType: string, data: any) => void | boolean,
1198
- path?: string,
1199
- ): SSEConnection;
1200
- /** Discover the services seen on a project: online ones plus previously-seen offline ones (check `online`). */
1201
- discoverServices(projectId: string): Promise<DiscoveredService[]>;
1202
- /** Forget a previously-seen (offline) service. Maintainer-only; 409 if currently connected. */
1203
- discardService(projectId: string, serviceId: string): Promise<void>;
1204
- /**
1205
- * Register as a service and handle work requests. The registration reopens
1206
- * its channel whenever it drops, so a server restart needs no service restart.
1207
- */
1208
- serve(
1209
- projectId: string,
1210
- serviceInfo: ServiceInfo,
1211
- onServiceRequest: (data: any, responseHelper: ResponseHelper) => void,
1212
- extras?: any,
1213
- onStatus?: (
1214
- event: ServiceStatusEvent,
1215
- projectId: string,
1216
- detail?: string,
1217
- ) => void,
1218
- ): ServiceRegistration;
1219
- /**
1220
- * Submit work to a service; streams progress to `onProgress`, resolves with
1221
- * the result. Aborting `signal` stops waiting and rejects with an AbortError;
1222
- * the service is not told and finishes its work regardless.
1223
- */
1224
- requestService(
1225
- projectId: string,
1226
- serviceId: string,
1227
- data: any,
1228
- timeout?: number,
1229
- onProgress?: (progress: any) => void,
1230
- signal?: AbortSignal,
1231
- opts?: {
1232
- /** A request id you mint, so you know it before submitting; resubmitting one rejoins that request. */
1233
- requestId?: string;
1234
- /** Called with the request id as soon as the server has taken the request. */
1235
- onAccepted?: (requestId: string) => void;
1236
- /** Other projects the request is about. A delegating service's token reaches `projectId` and those of these the requester can read, nothing else. */
1237
- projectIds?: string[];
1238
- /** Carry no open operation: the service's writes are a group of their own, not part of whatever operation this client has open. */
1239
- noOperation?: boolean;
1240
- },
1241
- ): Promise<any>;
1242
- /**
1243
- * Rejoin a request made earlier: the latest progress is replayed, then the
1244
- * result, or at once if it already finished. Only its submitter (or an
1245
- * admin). Rejects with a 404 when the request is unknown or expired.
1246
- */
1247
- attachServiceRequest(
1248
- projectId: string,
1249
- requestId: string,
1250
- timeout?: number,
1251
- onProgress?: (progress: any) => void,
1252
- signal?: AbortSignal,
1253
- ): Promise<any>;
1254
- /**
1255
- * Ask the service to stop a request made earlier. The request still ends
1256
- * with whatever the service then reports. 404 if unknown or expired, 409
1257
- * once finished.
1258
- */
1259
- cancelServiceRequest(projectId: string, requestId: string): Promise<void>;
1260
- }
1261
-
1262
- interface ProjectsBundle {
1263
- addWriter(id: string, userId: string, auditMessage?: string): Promise<any>;
1264
- removeWriter(id: string, userId: string, auditMessage?: string): Promise<any>;
1265
- addReader(id: string, userId: string, auditMessage?: string): Promise<any>;
1266
- removeReader(id: string, userId: string, auditMessage?: string): Promise<any>;
1267
- setConfig(
1268
- id: string,
1269
- namespace: string,
1270
- configKey: string,
1271
- configValue: any,
1272
- auditMessage?: string,
1273
- options?: ConfigWriteOptions,
1274
- ): Promise<any>;
1275
- deleteConfig(
1276
- id: string,
1277
- namespace: string,
1278
- configKey: string,
1279
- auditMessage?: string,
1280
- options?: ConfigWriteOptions,
1281
- ): Promise<any>;
1282
- addMaintainer(
1283
- id: string,
1284
- userId: string,
1285
- auditMessage?: string,
1286
- ): Promise<any>;
1287
- removeMaintainer(
1288
- id: string,
1289
- userId: string,
1290
- auditMessage?: string,
1291
- ): Promise<any>;
1292
- audit(
1293
- projectId: string,
1294
- startTime?: string,
1295
- endTime?: string,
1296
- opTypes?: string[] | string,
1297
- kinds?: OperationKind[] | string,
1298
- ): Promise<any[]>;
1299
- auditPage(projectId: string, opts?: AuditPageOptions): Promise<Page>;
1300
- /**
1301
- * When the calling user last wrote to each document of the project, as a
1302
- * `{documentId: timestamp}` map; documents they never wrote to are absent.
1303
- * The keys are document ids, so the response is not key-transformed.
1304
- */
1305
- myLastEdits(projectId: string): Promise<Record<string, string>>;
1306
- linkVocab(id: string, vocabId: string, auditMessage?: string): Promise<any>;
1307
- unlinkVocab(id: string, vocabId: string, auditMessage?: string): Promise<any>;
1308
- get(id: string): Promise<any>;
1309
- listDocuments(id: string): Promise<any[]>;
1310
- listDocumentsPage(
1311
- id: string,
1312
- opts?: { limit?: number; cursor?: string },
1313
- ): Promise<Page>;
1314
- iterDocuments(
1315
- id: string,
1316
- opts?: { pageSize?: number },
1317
- ): AsyncGenerator<any[]>;
1318
- update(id: string, name: string, auditMessage?: string): Promise<any>;
1319
- /** The project is gone when this returns, and what it holds is removed on the server afterwards. The timeout defaults to the client's. */
1320
- delete(
1321
- id: string,
1322
- auditMessage?: string,
1323
- options?: { timeout?: number | null },
1324
- ): Promise<any>;
1325
- list(): Promise<any[]>;
1326
- listPage(opts?: { limit?: number; cursor?: string }): Promise<Page>;
1327
- iterPages(opts?: { pageSize?: number }): AsyncGenerator<any[]>;
1328
- create(name: string, auditMessage?: string, opts?: { id?: string }): Promise<any>;
1329
- }
1330
-
1331
- interface TextLayersBundle {
1332
- setConfig(
1333
- textLayerId: string,
1334
- namespace: string,
1335
- configKey: string,
1336
- configValue: any,
1337
- auditMessage?: string,
1338
- options?: ConfigWriteOptions,
1339
- ): Promise<any>;
1340
- deleteConfig(
1341
- textLayerId: string,
1342
- namespace: string,
1343
- configKey: string,
1344
- auditMessage?: string,
1345
- options?: ConfigWriteOptions,
1346
- ): Promise<any>;
1347
- get(textLayerId: string): Promise<any>;
1348
- delete(textLayerId: string, auditMessage?: string): Promise<any>;
1349
- update(
1350
- textLayerId: string,
1351
- name: string,
1352
- auditMessage?: string,
1353
- ): Promise<any>;
1354
- shift(
1355
- textLayerId: string,
1356
- direction: string,
1357
- auditMessage?: string,
1358
- ): Promise<any>;
1359
- create(projectId: string, name: string, auditMessage?: string, opts?: { id?: string }): Promise<any>;
1360
- }
1361
-
1362
- interface VocabItemsBundle {
1363
- setMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
1364
- deleteMetadata(id: string, auditMessage?: string): Promise<any>;
1365
- patchMetadata(id: string, body: MetadataOp[], auditMessage?: string): Promise<any>;
1366
- create(
1367
- vocabLayerId: string,
1368
- form: string,
1369
- metadata?: any,
1370
- auditMessage?: string,
1371
- opts?: { id?: string },
1372
- ): Promise<any>;
1373
- bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
1374
- bulkDelete(body: any[], auditMessage?: string): Promise<void>;
1375
- bulkUpdate(body: any[], auditMessage?: string): Promise<{ count: number }>;
1376
- get(id: string): Promise<any>;
1377
- delete(
1378
- id: string,
1379
- auditMessage?: string,
1380
- options?: { expectedLinkCount?: number },
1381
- ): Promise<any>;
1382
- merge(
1383
- survivorId: string,
1384
- loserIds: string[],
1385
- auditMessage?: string,
1386
- ): Promise<{ moved: number; duplicates: number; removed: string[] }>;
1387
- update(id: string, form: string, auditMessage?: string): Promise<any>;
1388
- }
1389
-
1390
- interface RelationLayersBundle {
1391
- shift(
1392
- relationLayerId: string,
1393
- direction: string,
1394
- auditMessage?: string,
1395
- ): Promise<any>;
1396
- create(
1397
- spanLayerId: string,
1398
- name: string,
1399
- auditMessage?: string,
1400
- opts?: { id?: string },
1401
- ): Promise<any>;
1402
- setConfig(
1403
- relationLayerId: string,
1404
- namespace: string,
1405
- configKey: string,
1406
- configValue: any,
1407
- auditMessage?: string,
1408
- options?: ConfigWriteOptions,
1409
- ): Promise<any>;
1410
- deleteConfig(
1411
- relationLayerId: string,
1412
- namespace: string,
1413
- configKey: string,
1414
- auditMessage?: string,
1415
- options?: ConfigWriteOptions,
1416
- ): Promise<any>;
1417
- get(relationLayerId: string): Promise<any>;
1418
- delete(relationLayerId: string, auditMessage?: string): Promise<any>;
1419
- update(
1420
- relationLayerId: string,
1421
- name: string,
1422
- auditMessage?: string,
1423
- ): Promise<any>;
1424
- setConstraints(
1425
- layerId: string,
1426
- namespace: string,
1427
- constraints: LayerConstraint[],
1428
- auditMessage?: string,
1429
- options?: ConstraintWriteOptions,
1430
- ): Promise<{ constraints: Record<string, LayerConstraint[]> }>;
1431
- deleteConstraints(
1432
- layerId: string,
1433
- namespace: string,
1434
- auditMessage?: string,
1435
- options?: ConstraintWriteOptions,
1436
- ): Promise<any>;
1437
- checkConstraints(
1438
- layerId: string,
1439
- constraints: LayerConstraint[],
1440
- ): Promise<{ violations: ConstraintViolation[]; violationCount: number }>;
1441
- repairConstraints(
1442
- layerId: string,
1443
- constraints: LayerConstraint[],
1444
- auditMessage?: string,
1445
- options?: { document?: string },
1446
- ): Promise<{
1447
- repaired: { document: string; constraint: string; deleted: number; joined: number }[];
1448
- locked: { document: string; lockedBy: string }[];
1449
- violations: ConstraintViolation[];
1450
- violationCount: number;
1451
- }>;
1452
- }
1453
-
1454
- interface TokensBundle {
1455
- create(
1456
- tokenLayerId: string,
1457
- text: string,
1458
- begin: number,
1459
- end: number,
1460
- precedence?: number | null,
1461
- metadata?: any,
1462
- auditMessage?: string,
1463
- opts?: { id?: string },
1464
- ): Promise<any>;
1465
- get(tokenId: string): Promise<any>;
1466
- delete(tokenId: string, auditMessage?: string): Promise<any>;
1467
- update(
1468
- tokenId: string,
1469
- begin?: number,
1470
- end?: number,
1471
- precedence?: number | null,
1472
- auditMessage?: string,
1473
- ): Promise<any>;
1474
- bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
1475
- bulkDelete(body: any[], auditMessage?: string): Promise<void>;
1476
- bulkUpdate(body: any[], auditMessage?: string): Promise<{ count: number }>;
1477
- split(
1478
- tokenId: string,
1479
- position: number,
1480
- auditMessage?: string,
1481
- options?: { id?: string; keep?: "left" | "right" },
1482
- ): Promise<any>;
1483
- merge(
1484
- tokenId: string,
1485
- otherTokenId: string,
1486
- auditMessage?: string,
1487
- ): Promise<any>;
1488
- shift(
1489
- tokenId: string,
1490
- begin?: number,
1491
- end?: number,
1492
- auditMessage?: string,
1493
- ): Promise<any>;
1494
- setMetadata(tokenId: string, body: any, auditMessage?: string): Promise<any>;
1495
- deleteMetadata(tokenId: string, auditMessage?: string): Promise<any>;
1496
- patchMetadata(
1497
- tokenId: string,
1498
- body: MetadataOp[],
1499
- auditMessage?: string,
1500
- ): Promise<any>;
1501
- }
1502
-
1503
- interface PlaidClientOptions {
1504
- /** Per-request timeout in ms (default 30000; 0 or null disables it). */
1505
- timeout?: number | null;
1506
- /**
1507
- * Timeout for batch submissions in ms (default 180000; 0 or null disables it).
1508
- * Batches get their own, longer budget: aborting one does NOT stop the
1509
- * server, which keeps running the transaction and holding the single SQLite
1510
- * write lock. Defaults to `timeout` when that is given and this is not.
1511
- */
1512
- batchTimeout?: number | null;
1513
- /**
1514
- * Delays in ms before sending a keyed write again when its answer was lost
1515
- * (no response, 502 or 504). Default [1000, 3000, 9000].
1516
- */
1517
- retryDelaysMs?: number[];
1518
- /**
1519
- * Fired once when a request returns HTTP 401 (missing/expired/invalid token).
1520
- * Use it to discard the stored token and route back to login. 403 (forbidden)
1521
- * does NOT trigger it.
1522
- */
1523
- onAuthError?: ((error: Error) => void) | null;
1524
- }
1525
-
1526
- /** What kind of operation a logical-operation group is (`?group-kind=`). */
1527
- export type OperationKind =
1528
- | 'assistant-plan'
1529
- | 'service-run'
1530
- | 'import'
1531
- | 'bulk-edit'
1532
- | 'guess-adoption'
1533
- | 'repair'
1534
- | 'review';
1535
-
1536
- export interface OperationGroupsBundle {
1537
- get(id: string): Promise<any>;
1538
- update(id: string, message: string | null): Promise<any>;
1539
- }
1540
-
1541
- /**
1542
- * A batch: the client's bundles, on which every write of project data queues
1543
- * until `submit()`. See `PlaidClient.batch()`.
1544
- */
1545
- export interface PlaidBatch extends PlaidClient {
1546
- /** The client this batch was opened on. */
1547
- readonly client: PlaidClient;
1548
- /** The queued operations, in order. */
1549
- readonly operations: Array<{ path: string; method: string; body?: any }>;
1550
- /**
1551
- * Send the queued operations and resolve to one result per operation, in
1552
- * order. Up to MAX_BATCH_OPS operations go as one atomic request. A larger
1553
- * batch goes as consecutive requests, each atomic on its own, so a failure
1554
- * in a later one leaves the earlier ones committed. The error then carries
1555
- * `committed`, how many operations were saved (0 when none were), and
1556
- * `committedResults`, their results in queue order.
1557
- */
1558
- submit(): Promise<any[]>;
1559
- /** Drop the queued operations without sending them. */
1560
- abort(): void;
1561
- /**
1562
- * A stand-in for the id a queued operation will create, to put in a later
1563
- * operation's body on this batch, so a create and the write that uses it go
1564
- * in one transaction: op n's `id`, or with `index` the k-th of the `ids` a
1565
- * bulk create answers. `opIndex` counts from 0, or from the end when
1566
- * negative (-1, the default, is the op queued last). It goes only in the
1567
- * body of a later write on this batch, at any depth. Anywhere else (a path,
1568
- * another batch, a call made on the client) the client refuses it.
1569
- */
1570
- ref(opIndex?: number, index?: number): BatchRef;
1571
- }
1572
-
1573
- /**
1574
- * See `PlaidBatch.ref`. A marker object, not data: the client takes it out of
1575
- * the body when its write is queued and sends where it was beside the body.
1576
- */
1577
- export interface BatchRef {
1578
- /** The op, counted from 0 in the batch, whose id this stands for. */
1579
- readonly $ref: number;
1580
- /** For a bulk create, which of its ids. */
1581
- readonly index?: number;
1582
- }
1583
-
1584
- export declare class PlaidClient {
1585
- constructor(baseUrl: string, token: string, options?: PlaidClientOptions);
1586
- /** Liveness, version and database size, with no authentication. */
1587
- static health(
1588
- baseUrl: string,
1589
- options?: { timeout?: number | null },
1590
- ): Promise<ServerHealth>;
1591
- /** The limits this server enforces, with no authentication. */
1592
- static info(
1593
- baseUrl: string,
1594
- options?: { timeout?: number | null },
1595
- ): Promise<{ limits: ServerLimits }>;
1596
- static login(
1597
- baseUrl: string,
1598
- userId: string,
1599
- password: string,
1600
- options?: PlaidClientOptions,
1601
- ): Promise<PlaidClient>;
1602
- /** Build the link to hand someone for an invite code. */
1603
- static inviteUrl(appUrl: string, code: string): string;
1604
- /** Describe an invite code with no authentication (for a signup page). */
1605
- static lookupInvite(
1606
- baseUrl: string,
1607
- code: string,
1608
- options?: PlaidClientOptions,
1609
- ): Promise<InvitePreview>;
1610
- /** Redeem an invite code with no authentication; resolves to a logged-in client. */
1611
- static redeemInvite(
1612
- baseUrl: string,
1613
- code: string,
1614
- credentials: { email?: string; password: string; displayName?: string },
1615
- options?: PlaidClientOptions,
1616
- ): Promise<{ client: PlaidClient; userId: string; kind: string }>;
1617
- /** The server's base URL, without a trailing slash. */
1618
- readonly baseUrl: string;
1619
- /** The bearer token every request carries. */
1620
- token: string;
1621
- timeout: number | null;
1622
- batchTimeout: number | null;
1623
- retryDelaysMs: number[] | undefined;
1624
- /** The document strict mode is entered for, or null. */
1625
- readonly strictModeDocumentId: string | null;
1626
- /** The DocumentLockLost of the open `locked()` block whose lock lapsed, or null. Cleared when that block exits. */
1627
- documentLockLost: DocumentLockLost | null;
1628
- /** Fired once on HTTP 401 (see PlaidClientOptions.onAuthError). */
1629
- onAuthError: ((error: Error) => void) | null;
1630
- /** The latest version seen for each document written through this client, keyed by document id. */
1631
- documentVersions: Record<string, number>;
1632
- /** True once a response left its version list out (X-Document-Versions-Omitted, past fifty documents). Every version held was then forgotten, and the strict-mode document's is read again before the next write. */
1633
- documentVersionsOmitted?: boolean;
1634
- /** The server's clock minus this machine's, in ms, from the last response with a Date header, or null before one. */
1635
- serverClockOffsetMs: number | null;
1636
- /** The server's time now, from its last response's Date header (to the second), else this machine's. Judge a time the server stamped, such as an audit entry's `ts`, against this rather than `Date.now()`. */
1637
- serverNow(): Date;
1638
- /** Hear every time a request is sent again: after a 503, or for a keyed write after its answer was lost (no response, 502, 504). Called before the wait. Returns the unsubscribe. */
1639
- onRetry(
1640
- listener: (info: { attempt: number; retries: number; delay: number; error: Error }) => void,
1641
- ): () => void;
1642
-
1643
- // Batches.
1644
- //
1645
- // A batch is a view of the client with the same bundles. A write of project
1646
- // data made on the batch queues; a call made on the client itself always
1647
- // goes over the wire, whatever batches are open, so a write by code that
1648
- // knows nothing about a batch can never land inside it. A read, or a signal
1649
- // that carries no project data (stopping a service request, a service
1650
- // reporting its progress, taking and dropping a document lock, the admin
1651
- // actions on the server itself), goes over the wire even when made on the
1652
- // batch.
1653
- /** Open a batch. Queue writes on it, then `submit()` them (one atomic request up to MAX_BATCH_OPS operations), or `abort()`. Not nestable. */
1654
- batch(): PlaidBatch;
1655
- /** Run `fn` with a batch, then submit it as `submit()` does (or abort if `fn` throws). Resolves to the results array, one entry per queued write. */
1656
- batched(fn: (batch: PlaidBatch) => void | Promise<void>): Promise<any[]>;
1657
-
1658
- // Strict mode methods
1659
- enterStrictMode(documentId: string): void;
1660
- exitStrictMode(): void;
1661
-
1662
- // Logical operations (audit-log grouping). While one is open every write is
1663
- // stamped with its group id so the audit log folds them into one entry.
1664
- // Not atomic; nesting flattens into the outer operation.
1665
- // `kind` is one of OperationKind (the server refuses any other) and `ref`
1666
- // names what the operation came from; nesting keeps the outer ones.
1667
- operationGroup: {
1668
- id: string;
1669
- message: string | null;
1670
- kind: OperationKind | null;
1671
- ref: string | null;
1672
- } | null;
1673
- beginOperation(
1674
- message: string,
1675
- opts?: { groupId?: string; kind?: OperationKind; ref?: string; keys?: KeySeed; minted?: Set<string> },
1676
- ): string;
1677
- /** A seed for the Idempotency-Keys of an operation that may be run again (see beginOperation's `keys`). */
1678
- keySeed(): KeySeed;
1679
- endOperation(message?: string): Promise<void>;
1680
- withOperation<T>(
1681
- message: string,
1682
- fn: (setMessage: (msg: string) => void) => Promise<T> | T,
1683
- opts?: { kind?: OperationKind; ref?: string; groupId?: string; keys?: KeySeed; minted?: Set<string> },
1684
- ): Promise<T>;
1685
- operationGroups: OperationGroupsBundle;
1686
-
1687
- // Query
1688
- query(body: any): Promise<any>;
1689
-
1690
- vocabLinks: VocabLinksBundle;
1691
- vocabLayers: VocabLayersBundle;
1692
- relations: RelationsBundle;
1693
- spanLayers: SpanLayersBundle;
1694
- spans: SpansBundle;
1695
- texts: TextsBundle;
1696
- users: UsersBundle;
1697
- apiTokens: ApiTokensBundle;
1698
- userData: UserDataBundle;
1699
- invites: InvitesBundle;
1700
- server: ServerBundle;
1701
- auth: AuthBundle;
1702
- admin: AdminBundle;
1703
- audit: AuditBundle;
1704
- comments: CommentsBundle;
1705
- events: EventsBundle;
1706
- guidelines: GuidelinesBundle;
1707
- tokenLayers: TokenLayersBundle;
1708
- documents: DocumentsBundle;
1709
- messages: MessagesBundle;
1710
- projects: ProjectsBundle;
1711
- textLayers: TextLayersBundle;
1712
- vocabItems: VocabItemsBundle;
1713
- relationLayers: RelationLayersBundle;
1714
- tokens: TokensBundle;
1715
- }
1716
-
1717
- export default PlaidClient;
1718
-
1719
- // --- Unicode code-point helpers for text offsets ---------------------------
1720
- // Token begin/end offsets are 0-based Unicode code-point indices (not UTF-16).
1721
- /** Number of Unicode code points in `s` (not `s.length`). */
1722
- export function cpLength(s: string): number;
1723
- /** Substring of `s` by code-point indices [begin, end) (end optional). */
1724
- export function cpSlice(s: string, begin: number, end?: number): string;
1725
- /** Prebuilt slicer for many code-point slices of one string (spreads once). */
1726
- export function cpSlicer(s: string): (begin: number, end?: number) => string;
1727
- /** UTF-16 index -> code-point index in `s`. */
1728
- export function utf16ToCp(s: string, u: number): number;
1729
- /** Like indexOf, but the result and `fromCp` are code-point indices; -1 if absent. */
1730
- export function cpIndexOf(s: string, sub: string, fromCp?: number): number;
1731
-
1732
- // --- Text edit operations (code points, running coordinates) ---------------
1733
- /** One op as `PATCH /texts/:id` takes it; each index is in the body the ops before it left. */
1734
- export type TextEditOp =
1735
- | { type: "insert"; index: number; value: string }
1736
- | { type: "delete"; index: number; value: number }
1737
- | { type: "replace"; index: number; length: number; value: string };
1738
- /** Old-body code points [start, end) give way to `value`. */
1739
- export interface TextGap {
1740
- start: number;
1741
- end: number;
1742
- value: string;
1743
- }
1744
- /** The net change of `ops` on `body` as gaps: sorted, never touching, no-op gaps dropped. Throws on a bad op. */
1745
- export function composeTextEdits(body: string, ops: TextEditOp[]): TextGap[];
1746
- /** Gaps as running ops: insert, delete or replace. */
1747
- export function gapsToOps(gaps: TextGap[]): TextEditOp[];
1748
- /** `body` with `ops` applied in turn. Throws on a bad op. */
1749
- export function applyTextOps(body: string, ops: TextEditOp[]): string;
1750
-
1751
- // --- Shared layer-role vocabulary (cross-app interoperability) --------------
1752
- // Substrate layers are tagged with a role at `config.plaid.role` (a scalar) so
1753
- // that different apps can share a project. See the manual, "Layer Interoperability".
1754
- /** The reserved config namespace for cross-app conventions. */
1755
- export const PLAID_NAMESPACE: "plaid";
1756
- /** The config key, under `plaid`, holding a layer's role. */
1757
- export const ROLE_KEY: "role";
1758
- /** Layer config key naming the metadata keys a token born of a SPLIT inherits. */
1759
- export const PRESERVE_ON_SPLIT_KEY: "preserveOnSplit";
1760
- /** Layer config key: a space typed inside a word of the text splits it (see the manual's "Changing a text's body"). */
1761
- export const SPLIT_ON_SPACE_KEY: "splitOnSpace";
1762
-
1763
- /** The server's cap on operations per batch request; a larger batch goes as consecutive requests. */
1764
- export const MAX_BATCH_OPS: 1000;
1765
- /** How long `admin.backup()` waits for the server to finish writing a backup, in ms. */
1766
- export const BACKUP_TIMEOUT_MS: number;
1767
- /** The fixed role inventory; only these values are interoperable across apps. */
1768
- export const ROLES: {
1769
- readonly BASELINE: "baseline";
1770
- readonly SENTENCE: "sentence";
1771
- readonly WORD: "word";
1772
- readonly SYNTACTIC_WORD: "syntactic-word";
1773
- readonly MORPHEME: "morpheme";
1774
- readonly TIME_ALIGNMENT: "time-alignment";
1775
- };
1776
- /** The role recorded on a layer's `config`, or null if none. */
1777
- export function readRole(config?: object): string | null;
1778
- /** The first layer in `layers` carrying the given role, or null. */
1779
- export function findByRole<T extends { config?: object }>(
1780
- layers: T[] | undefined,
1781
- role: string,
1782
- ): T | null;
1783
-
1784
- // --- Service self-description helpers ----------------------------------------
1785
- // Standardize how a service advertises (in `extras`) the tasks it serves, a
1786
- // summary, and a parameter schema — so a UI can offer service selection, an
1787
- // argument form, and a summary at a fixed integration point. See the manual,
1788
- // "Describing a service".
1789
- /** The controlled task vocabulary — the fixed integration-point goals. */
1790
- export const TASKS: {
1791
- readonly TOKENIZE: "tokenize";
1792
- readonly PARSE: "parse";
1793
- readonly TRANSCRIBE: "transcribe";
1794
- readonly LINK_VOCAB: "link-vocab";
1795
- readonly ANALYZE: "analyze";
1796
- readonly DRAFT_GRAPH: "draft-graph";
1797
- readonly TRANSLATE: "translate";
1798
- readonly ASSIST: "assist";
1799
- readonly DETECT_SPEECH: "detect-speech";
1800
- readonly COMPARE: "compare";
1801
- };
1802
- /** Whether a service serves a task (declared `extras.tasks`, legacy id-prefix fallback). */
1803
- export function servesTask(service: DiscoveredService, task: string): boolean;
1804
- /** The discovered services that serve `task`. */
1805
- export function filterServicesByTask(
1806
- services: DiscoveredService[] | undefined,
1807
- task: string,
1808
- ): DiscoveredService[];
1809
- /** The parameter schema a service declares (ordered), or []. */
1810
- export function getParamSchema(service: DiscoveredService): ServiceParam[];
1811
- /** A service's human summary: `extras.summary`, else `description`, else ''. */
1812
- export function getServiceSummary(service: DiscoveredService): string;
1813
- /** Default form values keyed by param key. */
1814
- export function buildDefaultValues(schema: ServiceParam[]): Record<string, any>;
1815
- /** Coerce/validate raw form values against the schema. */
1816
- export function coerceParamValues(
1817
- schema: ServiceParam[],
1818
- raw: Record<string, any>,
1819
- ): { values: Record<string, any>; errors: Record<string, string> };
1820
-
1821
- // --- Provenance ---------------------------------------------------------------
1822
- // Cross-app convention for machine-provided vs human-labeled information,
1823
- // expressed as flat metadata keys on annotation entities. Absent keys = human;
1824
- // { prov: 'inferred', provSource } = machine-made, unverified;
1825
- // + { provConfirmed: true } = machine-made, human-verified. Machine writers may
1826
- // replace unverified machine material but must never touch human/verified
1827
- // material without an explicit overwrite opt-in; any human edit verifies.
1828
- // See the manual, "Provenance".
1829
- type ProvState = "human" | "machine" | "contributed" | "verified";
1830
- export const PROV: {
1831
- readonly key: "prov";
1832
- readonly sourceKey: "provSource";
1833
- readonly confirmedKey: "provConfirmed";
1834
- readonly probKey: "provProb";
1835
- readonly detailKey: "provDetail";
1836
- readonly INFERRED: "inferred";
1837
- readonly CONTRIBUTED: "contributed";
1838
- };
1839
- export const PROV_STATES: {
1840
- readonly HUMAN: "human";
1841
- readonly MACHINE: "machine";
1842
- readonly CONTRIBUTED: "contributed";
1843
- readonly VERIFIED: "verified";
1844
- };
1845
- /** The provenance keys Plaid itself owns — what a split carries and a reshape keeps. */
1846
- export const PROVENANCE_KEYS: readonly string[];
1847
- /** Optional prediction extras: prob = a probability in [0,1] for the chosen value
1848
- * (flat + queryable; omit unless it honestly is one); detail = an open map of
1849
- * producer extras (top-k alternatives, model version, raw scores; keep it small).
1850
- * Both describe the ORIGINAL prediction — check provConfirmed before presenting
1851
- * provProb as confidence in the current value. */
1852
- interface ProvExtras {
1853
- prob?: number;
1854
- detail?: Record<string, any>;
1855
- }
1856
- /** The metadata fragment a machine writer merges into everything it creates. */
1857
- export function stampInferred(
1858
- source: string,
1859
- extras?: ProvExtras,
1860
- ): {
1861
- prov: "inferred";
1862
- provSource: string;
1863
- provProb?: number;
1864
- provDetail?: Record<string, any>;
1865
- };
1866
- /** stampInferred + provConfirmed — for machine material born verified (e.g. imports with upstream approval). */
1867
- export function confirmedInferred(
1868
- source: string,
1869
- extras?: ProvExtras,
1870
- ): {
1871
- prov: "inferred";
1872
- provSource: string;
1873
- provConfirmed: true;
1874
- provProb?: number;
1875
- provDetail?: Record<string, any>;
1876
- };
1877
- /** Classify an entity's metadata into one of the three provenance states. */
1878
- export function provState(metadata: object | null | undefined): ProvState;
1879
- /** Machine-made and not yet human-verified (needs review, replaceable, confirmable). */
1880
- export function isMachine(metadata: object | null | undefined): boolean;
1881
- /** Whether a machine writer must leave this entity alone (human or verified). !isMachine. */
1882
- export function isProtected(metadata: object | null | undefined): boolean;
1883
- /** Canonical provSource for a service: 'service:<serviceId>'. */
1884
- export function serviceSource(serviceId: string): string;
1885
- /** The metadata fragment a contributor's work carries. */
1886
- export function stampContributed(userId: string): {
1887
- prov: "contributed";
1888
- provSource: string;
1889
- };
1890
- /** Where an entity came from, confirmed or not: what a verified entity's tooltip needs. */
1891
- export function provOrigin(
1892
- metadata: object | null | undefined,
1893
- ): null | "inferred" | "contributed";
1894
- /** Whether a verifier still has to look at this entity: machine-made or contributed, unconfirmed. */
1895
- export function needsReview(metadata: object | null | undefined): boolean;
1896
- /** The fragment a CONTRIBUTOR's edit merges in: the contributed stamp, dropping any confirmation. */
1897
- export function contributeOnEdit(
1898
- metadata: object | null | undefined,
1899
- userId: string,
1900
- ): { prov: "contributed"; provSource: string; provConfirmed: null };
1901
- /** Merge a fragment into a local copy, a null value deleting the key: applyMetadataOps(metadata, metadataOps(fragment)), refused where the server would refuse it. Returns a new object. */
1902
- export function mergeMetadata(
1903
- metadata: object | null | undefined,
1904
- fragment: object | null | undefined,
1905
- ): Record<string, any>;
1906
-
1907
- // --- Create responses ---------------------------------------------------------
1908
- /** The id a single create answered with, read off the call's response or its batch result (`{status, body}`). Undefined when it gave none. */
1909
- /** Idempotency-Key seed for an operation run more than once (client.keySeed()). */
1910
- export interface KeySeed {
1911
- seed: string;
1912
- stamps: Map<number, number | null>;
1913
- }
1914
- /** A fresh UUIDv7, for the id of something a client creates. */
1915
- export function uuidv7(): string;
1916
- /** A fresh random UUID (version 4), from crypto.getRandomValues, so it works on any page. */
1917
- export function uuidv4(): string;
1918
- /** Whether a write's answer was replayed from its Idempotency-Key's first send (`Idempotent-Replayed: true`), so it wrote nothing new. Marked on an object or list answer as a non-enumerable `replayed: true`. */
1919
- export function wasReplayed(answer: unknown): boolean;
1920
- export function createdId(result: any): string | undefined;
1921
- /** The ids a bulk create answered with, in input order, read off the call's response or its batch result. Empty when it gave none. */
1922
- export function createdIds(result: any): string[];
1923
-
1924
- // --- Metadata ops -------------------------------------------------------------
1925
- /** One metadata edit: the body of a metadata PATCH is a list of these. */
1926
- export type MetadataOp =
1927
- | { op: "set"; path: string[]; value: any }
1928
- | { op: "delete"; path: string[] };
1929
- /** The ops that set each top-level key of a fragment, a null value deleting it. */
1930
- export function metadataOps(
1931
- fragment: object | null | undefined,
1932
- ): MetadataOp[];
1933
- /** Apply ops to a local copy the way the server does. Returns a new object; throws where the server would refuse. */
1934
- export function applyMetadataOps(
1935
- metadata: object | null | undefined,
1936
- ops: MetadataOp[],
1937
- ): Record<string, any>;
1938
- /** True for a top-level metadata key Plaid keeps for itself (`plaid` and the provenance keys), never a user's field. */
1939
- export function isReservedMetadataKey(key: string): boolean;
1940
-
1941
- // --- Review: whose work is reviewed (a project-config norm) -------------------
1942
- /** The config key, under the `plaid` namespace, holding the review lists. */
1943
- export const REVIEW_KEY: "review";
1944
- /** A project's review lists, normalized. */
1945
- export function readReview(config?: object | null): {
1946
- users: string[];
1947
- roles: string[];
1948
- };
1949
- /** A person's role in a project from its ACL lists; an admin with no entry is a maintainer. */
1950
- export function projectRole(
1951
- project: object | null | undefined,
1952
- userId: string | null | undefined,
1953
- opts?: { isAdmin?: boolean },
1954
- ): "maintainer" | "writer" | "reader" | null;
1955
- /** Whether this person's work is reviewed here: named in review.users, or holding a role in review.roles. */
1956
- export function isReviewed(
1957
- project: object | null | undefined,
1958
- userId: string | null | undefined,
1959
- opts?: { isAdmin?: boolean },
1960
- ): boolean;
1961
- /** The review lists with one person added to or removed from `users`. Pure. */
1962
- export function withReviewedUser(
1963
- review: { users?: string[]; roles?: string[] } | null | undefined,
1964
- userId: string,
1965
- reviewed: boolean,
1966
- ): { users: string[]; roles: string[] };
1967
- /** What one writer's writes carry and what their review gestures act on. */
1968
- export function writerPolicy(contributorId?: string | null): {
1969
- readonly contributorId: string | null;
1970
- readonly isContributor: boolean;
1971
- /** The metadata a NEW entity carries: null for a verifier. */
1972
- readonly createStamp: Record<string, any> | null;
1973
- /** The fragment an EDIT merges, or null when there is nothing to merge. */
1974
- readonly editStamp: (
1975
- metadata: object | null | undefined,
1976
- ) => Record<string, any> | null;
1977
- /** The fragment an explicit confirm gesture merges, or null. */
1978
- readonly confirmStamp: (
1979
- metadata: object | null | undefined,
1980
- ) => Record<string, any> | null;
1981
- /** What an adopted suggestion is written with. */
1982
- readonly adoptStamp: (
1983
- source: string,
1984
- detail?: Record<string, any>,
1985
- ) => Record<string, any>;
1986
- /** Whether this writer's review gesture acts on the entity. */
1987
- readonly reviewable: (metadata: object | null | undefined) => boolean;
1988
- /** The same test over a provState. */
1989
- readonly reviewableState: (state: string) => boolean;
1990
- };
1991
-
1992
- // --- Layer constraints -------------------------------------------------------
1993
- /** A constraint an app declares on a layer, e.g. {type: "value-set", values: ["N"]}. */
1994
- export interface LayerConstraint {
1995
- type:
1996
- | "max-in-degree"
1997
- | "acyclic"
1998
- | "same-ancestor"
1999
- | "single-span"
2000
- | "value-set"
2001
- | "coextensive"
2002
- | "single-link";
2003
- [param: string]: any;
2004
- }
2005
- /** `expected`: the list read for the namespace, null when it was absent. */
2006
- export interface ConstraintWriteOptions {
2007
- expected?: LayerConstraint[] | null;
2008
- }
2009
- /** One violation a 422 lists. */
2010
- export interface ConstraintViolation {
2011
- constraint: string;
2012
- namespace: string | null;
2013
- layer: string;
2014
- layerName: string;
2015
- document: string | null;
2016
- at: string | null;
2017
- ids: string[];
2018
- value?: any;
2019
- parts?: string[];
2020
- }
2021
- /** The camelCased violations of a write refused by a layer constraint, or null. */
2022
- export function violationsOf(err: any): ConstraintViolation[] | null;
2023
- export function valueSetAllows(
2024
- constraint: { values: string[]; delimiters?: string; parts?: "all" | "first" },
2025
- value: any,
2026
- ): boolean;