@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
package/src/ids.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A fresh UUIDv7, later than every one this page minted before it.
3
+ * @returns {string}
4
+ */
5
+ export function uuidv7(): string;
6
+ /**
7
+ * A random UUIDv4, for ids that need no order (an operation group, a lock
8
+ * holder). Built on `crypto.getRandomValues`, since `crypto.randomUUID`
9
+ * exists only in a secure context and a page served over plain HTTP from
10
+ * another host than localhost is not one.
11
+ * @returns {string}
12
+ */
13
+ export function uuidv4(): string;
14
+ /**
15
+ * A user id as the server stores it. A user's id is their email address,
16
+ * trimmed of every whitespace, control and format character at either end
17
+ * and lowercased, in NFC before and after (a capital with no composed form,
18
+ * such as J̌, lowercases to one that has one, ǰ), so `Ana@Example.org` and
19
+ * `ana@example.org` name one account. Compare a typed address with an id
20
+ * through this. The rule is core's (`plaid.sql.user/normalize-id`), checked
21
+ * against its case table.
22
+ * Anything but a string comes back unchanged.
23
+ * @param {string} id
24
+ * @returns {string}
25
+ */
26
+ export function normalizeUserId(id: string): string;
package/src/ids.js ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Ids a client mints for what it creates.
3
+ *
4
+ * A create may name the id of the row it makes, so a create sent again after
5
+ * its answer was lost lands under the same id or is told the id is taken
6
+ * (409 with `id-taken`). The server takes only a UUIDv7 (RFC 9562), shaped
7
+ * as its own ids are: a 48-bit millisecond timestamp, a 12-bit counter
8
+ * within the millisecond, then 62 random bits. Reads are id-ordered, so ids
9
+ * minted in one millisecond must still sort in the order they were made.
10
+ */
11
+
12
+ let lastMs = 0;
13
+ let counter = 0;
14
+
15
+ const hex = Array.from({ length: 256 }, (_, i) =>
16
+ i.toString(16).padStart(2, "0"),
17
+ );
18
+
19
+ /**
20
+ * A fresh UUIDv7, later than every one this page minted before it.
21
+ * @returns {string}
22
+ */
23
+ export function uuidv7() {
24
+ const now = Date.now();
25
+ if (now > lastMs) {
26
+ lastMs = now;
27
+ counter = 0;
28
+ } else if (counter < 0xfff) {
29
+ counter += 1;
30
+ } else {
31
+ // This millisecond is full: take the next one rather than repeat an order.
32
+ lastMs += 1;
33
+ counter = 0;
34
+ }
35
+ const b = new Uint8Array(16);
36
+ crypto.getRandomValues(b);
37
+ const high = Math.floor(lastMs / 0x100000000);
38
+ const low = lastMs >>> 0;
39
+ b[0] = (high >>> 8) & 0xff;
40
+ b[1] = high & 0xff;
41
+ b[2] = (low >>> 24) & 0xff;
42
+ b[3] = (low >>> 16) & 0xff;
43
+ b[4] = (low >>> 8) & 0xff;
44
+ b[5] = low & 0xff;
45
+ b[6] = 0x70 | (counter >>> 8);
46
+ b[7] = counter & 0xff;
47
+ b[8] = (b[8] & 0x3f) | 0x80;
48
+ let s = "";
49
+ for (let i = 0; i < 16; i++) {
50
+ s += hex[b[i]];
51
+ if (i === 3 || i === 5 || i === 7 || i === 9) s += "-";
52
+ }
53
+ return s;
54
+ }
55
+
56
+ /**
57
+ * A random UUIDv4, for ids that need no order (an operation group, a lock
58
+ * holder). Built on `crypto.getRandomValues`, since `crypto.randomUUID`
59
+ * exists only in a secure context and a page served over plain HTTP from
60
+ * another host than localhost is not one.
61
+ * @returns {string}
62
+ */
63
+ export function uuidv4() {
64
+ const b = new Uint8Array(16);
65
+ crypto.getRandomValues(b);
66
+ b[6] = (b[6] & 0x0f) | 0x40;
67
+ b[8] = (b[8] & 0x3f) | 0x80;
68
+ let s = "";
69
+ for (let i = 0; i < 16; i++) {
70
+ s += hex[b[i]];
71
+ if (i === 3 || i === 5 || i === 7 || i === 9) s += "-";
72
+ }
73
+ return s;
74
+ }
75
+
76
+ // Whitespace, control and format characters at either end of an id (NBSP,
77
+ // the BOM, zero-width and bidi marks as well as ASCII blanks), as core trims.
78
+ const ID_EDGES = /^[\p{Z}\p{Cc}\p{Cf}]+|[\p{Z}\p{Cc}\p{Cf}]+$/gu;
79
+
80
+ /**
81
+ * A user id as the server stores it. A user's id is their email address,
82
+ * trimmed of every whitespace, control and format character at either end
83
+ * and lowercased, in NFC before and after (a capital with no composed form,
84
+ * such as J̌, lowercases to one that has one, ǰ), so `Ana@Example.org` and
85
+ * `ana@example.org` name one account. Compare a typed address with an id
86
+ * through this. The rule is core's (`plaid.sql.user/normalize-id`), checked
87
+ * against its case table.
88
+ * Anything but a string comes back unchanged.
89
+ * @param {string} id
90
+ * @returns {string}
91
+ */
92
+ export function normalizeUserId(id) {
93
+ return typeof id === "string"
94
+ ? id.normalize("NFC").replace(ID_EDGES, "").toLowerCase().normalize("NFC")
95
+ : id;
96
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,101 @@
1
+ export default PlaidClient;
2
+ export { PlaidClient };
3
+ export { BACKUP_TIMEOUT_MS } from "./apiServer.js";
4
+ export { wasReplayed } from "./replayed.js";
5
+ export { MAX_BATCH_OPS } from "./batch.js";
6
+ export type TextEditOp = import("./types.js").TextEditOp;
7
+ export type TextGap = import("./types.js").TextGap;
8
+ export type MetadataOp = import("./types.js").MetadataOp;
9
+ export type LayerConstraint = import("./types.js").LayerConstraint;
10
+ export type ConstraintWriteOptions = import("./types.js").ConstraintWriteOptions;
11
+ export type ConstraintViolation = import("./types.js").ConstraintViolation;
12
+ export type Requester = import("./types.js").Requester;
13
+ export type BatchRef = import("./types.js").BatchRef;
14
+ export type ServiceParam = import("./types.js").ServiceParam;
15
+ export type ServiceInfo = import("./types.js").ServiceInfo;
16
+ export type DiscoveredService = import("./types.js").DiscoveredService;
17
+ export type ResponseHelper = import("./types.js").ResponseHelper;
18
+ export type ServiceRegistration = import("./types.js").ServiceRegistration;
19
+ export type ServiceStatusEvent = import("./types.js").ServiceStatusEvent;
20
+ export type OperationGroupsBundle = import("./types.js").OperationGroupsBundle;
21
+ export type PlaidClientOptions = import("./types.js").PlaidClientOptions;
22
+ export type OperationKind = import("./types.js").OperationKind;
23
+ export type KeySeed = import("./types.js").KeySeed;
24
+ export type PlaidBatch = import("./types.js").PlaidBatch;
25
+ export type AuditPageOptions = import("./types.js").AuditPageOptions;
26
+ export type VocabItemRestoreSummary = import("./types.js").VocabItemRestoreSummary;
27
+ export type UserDataEntry = import("./types.js").UserDataEntry;
28
+ export type AdminUserDataEntry = import("./types.js").AdminUserDataEntry;
29
+ export type ActivityTallyRow = import("./types.js").ActivityTallyRow;
30
+ export type ConstraintRepair = import("./types.js").ConstraintRepair;
31
+ export type ValueSetRule = import("./types.js").ValueSetRule;
32
+ export type RefusedValues = import("./types.js").RefusedValues;
33
+ export type CommentableType = import("./types.js").CommentableType;
34
+ export type Comment = import("./types.js").Comment;
35
+ export type Guideline = import("./types.js").Guideline;
36
+ export type ClientEventType = import("./types.js").ClientEventType;
37
+ export type ClientEvent = import("./types.js").ClientEvent;
38
+ export type Invite = import("./types.js").Invite;
39
+ export type ServerLimits = import("./types.js").ServerLimits;
40
+ export type ServerHealth = import("./types.js").ServerHealth;
41
+ export type RateLimitBucket = import("./types.js").RateLimitBucket;
42
+ export type RateLimitSnapshot = import("./types.js").RateLimitSnapshot;
43
+ export type BackupStatus = import("./types.js").BackupStatus;
44
+ export type ServerReport = import("./types.js").ServerReport;
45
+ export type LiveLog = import("./types.js").LiveLog;
46
+ export type SSEConnection = import("./types.js").SSEConnection;
47
+ export type SSEStats = import("./types.js").SSEStats;
48
+ export type AtomicValue = import("./types.js").AtomicValue;
49
+ export type Created = import("./types.js").Created;
50
+ export type Project = import("./types.js").Project;
51
+ export type ProjectTextLayer = import("./types.js").ProjectTextLayer;
52
+ export type ProjectTokenLayer = import("./types.js").ProjectTokenLayer;
53
+ export type ProjectSpanLayer = import("./types.js").ProjectSpanLayer;
54
+ export type ProjectRelationLayer = import("./types.js").ProjectRelationLayer;
55
+ export type ProjectVocab = import("./types.js").ProjectVocab;
56
+ export type PlaidDocument = import("./types.js").PlaidDocument;
57
+ export type DocumentTextLayer = import("./types.js").DocumentTextLayer;
58
+ export type DocumentTokenLayer = import("./types.js").DocumentTokenLayer;
59
+ export type DocumentSpanLayer = import("./types.js").DocumentSpanLayer;
60
+ export type PlaidText = import("./types.js").PlaidText;
61
+ export type TextReshape = import("./types.js").TextReshape;
62
+ export type Token = import("./types.js").Token;
63
+ export type Span = import("./types.js").Span;
64
+ export type Relation = import("./types.js").Relation;
65
+ export type VocabItem = import("./types.js").VocabItem;
66
+ export type VocabLink = import("./types.js").VocabLink;
67
+ export type VocabLayer = import("./types.js").VocabLayer;
68
+ export type TextLayer = import("./types.js").TextLayer;
69
+ export type TokenLayer = import("./types.js").TokenLayer;
70
+ export type SpanLayer = import("./types.js").SpanLayer;
71
+ export type RelationLayer = import("./types.js").RelationLayer;
72
+ export type MetadataRecords = import("./types.js").MetadataRecords;
73
+ export type LayerRecords = import("./types.js").LayerRecords;
74
+ export type User = import("./types.js").User;
75
+ export type ProjectListEntry = import("./types.js").ProjectListEntry;
76
+ export type DocumentListEntry = import("./types.js").DocumentListEntry;
77
+ export type ApiToken = import("./types.js").ApiToken;
78
+ export type AuditUser = import("./types.js").AuditUser;
79
+ export type AuditTarget = import("./types.js").AuditTarget;
80
+ export type AuditOp = import("./types.js").AuditOp;
81
+ export type AuditEntry = import("./types.js").AuditEntry;
82
+ export type LockGrant = import("./types.js").LockGrant;
83
+ export type DocumentRestoreSummary = import("./types.js").DocumentRestoreSummary;
84
+ export type RestoreCounts = import("./types.js").RestoreCounts;
85
+ export type OperationGroup = import("./types.js").OperationGroup;
86
+ export type QueryResult = import("./types.js").QueryResult;
87
+ export type Page<T = any> = import("./types.js").Page<T>;
88
+ import { PlaidClient } from "./client.js";
89
+ export { valueSetAllows, violationCountOf, violationsOf } from "./constraints.js";
90
+ export { cpLength, cpSlice, cpSlicer, utf16ToCp, cpIndexOf, composeText } from "./codepoint.js";
91
+ export { composeTextEdits, gapsToOps, applyTextOps } from "./textEdits.js";
92
+ export { PLAID_NAMESPACE, ROLE_KEY, PRESERVE_ON_SPLIT_KEY, SPLIT_ON_SPACE_KEY, IGNORED_TOKENS_KEY, TARTAN_KEY, RESEARCH_KEY, readResearchTelemetry, ROLES, readRole, readIgnoredTokens, findByRole } from "./roles.js";
93
+ export { TASKS, servesTask, filterServicesByTask, getParamSchema, getServiceSummary, buildDefaultValues, coerceParamValues } from "./serviceSchema.js";
94
+ export { ServiceCancelled, createCancelScope, UNKNOWN_OUTCOME, UNREACHABLE } from "./services.js";
95
+ export { REQUESTED_BY, makeRequester, requesterOf } from "./requester.js";
96
+ export { DocumentLock, DocumentLockLost } from "./documentLock.js";
97
+ export { PROV, PROV_STATES, PROVENANCE_KEYS, stampInferred, confirmedInferred, stampContributed, provState, provOrigin, isMachine, isProtected, needsReview, contributeOnEdit, serviceSource, REVIEW_KEY, readReview, reviewsAnyone, projectRole, isReviewed, withReviewedUser, CONFIDENCE_KEY, DEFAULT_CONFIDENCE_THRESHOLD, readConfidenceThreshold, machineProb, isDoubtful, VALUE_PROBS_KEY, FORM_PROBS_KEY, readValueProbs, writerPolicy } from "./provenance.js";
98
+ export { MORPH_TYPES, entryForm, readAffixMarkers, decorateWithAffixMarkers } from "./entryForms.js";
99
+ export { metadataOps, applyMetadataOps, mergeMetadata, isReservedMetadataKey } from "./metadataOps.js";
100
+ export { createdId, createdIds } from "./created.js";
101
+ export { uuidv4, uuidv7, normalizeUserId } from "./ids.js";