@pegasimed.com/pegasi-sail-connect-shared 0.2.0-dev.1 → 0.2.0-dev.2

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 (36) hide show
  1. package/README.md +76 -10
  2. package/dist/authorization/index.d.ts +1 -0
  3. package/dist/authorization/index.d.ts.map +1 -1
  4. package/dist/authorization/index.js +1 -0
  5. package/dist/authorization/index.js.map +1 -1
  6. package/dist/authorization/work-grants.d.ts +151 -0
  7. package/dist/authorization/work-grants.d.ts.map +1 -0
  8. package/dist/authorization/work-grants.js +306 -0
  9. package/dist/authorization/work-grants.js.map +1 -0
  10. package/dist/capabilities/canonical-json.d.ts +3 -0
  11. package/dist/capabilities/canonical-json.d.ts.map +1 -0
  12. package/dist/capabilities/canonical-json.js +83 -0
  13. package/dist/capabilities/canonical-json.js.map +1 -0
  14. package/dist/capabilities/catalog-data.d.ts +386 -221
  15. package/dist/capabilities/catalog-data.d.ts.map +1 -1
  16. package/dist/capabilities/catalog-data.js +401 -226
  17. package/dist/capabilities/catalog-data.js.map +1 -1
  18. package/dist/capabilities/catalog.d.ts.map +1 -1
  19. package/dist/capabilities/catalog.js +4 -4
  20. package/dist/capabilities/catalog.js.map +1 -1
  21. package/dist/capabilities/migration-data.d.ts +51 -27
  22. package/dist/capabilities/migration-data.d.ts.map +1 -1
  23. package/dist/capabilities/migration-data.js +54 -27
  24. package/dist/capabilities/migration-data.js.map +1 -1
  25. package/dist/capabilities/migration.d.ts.map +1 -1
  26. package/dist/capabilities/migration.js +3 -6
  27. package/dist/capabilities/migration.js.map +1 -1
  28. package/dist/capabilities/sha256.d.ts +18 -0
  29. package/dist/capabilities/sha256.d.ts.map +1 -0
  30. package/dist/capabilities/sha256.js +180 -0
  31. package/dist/capabilities/sha256.js.map +1 -0
  32. package/dist/worker-logger.d.ts +46 -4
  33. package/dist/worker-logger.d.ts.map +1 -1
  34. package/dist/worker-logger.js +33 -11
  35. package/dist/worker-logger.js.map +1 -1
  36. package/package.json +3 -3
@@ -0,0 +1,306 @@
1
+ import { OWN_ACCESSOR, appendOwn, ownDataValue, readList } from "../capabilities/list.js";
2
+ import { sha256Base64Url } from "../capabilities/sha256.js";
3
+ // Work grants of the v2 envelope, as Access signs them. Source of truth:
4
+ // pegasi-sail-connect-access-api origin/dev aee642b, src/access-domain.ts:
5
+ // WORK_GRANT_DOMAINS and WORK_GRANT_RELATIONS (41-42), sha256Identity (139-141),
6
+ // workGrantIdentityValue and workGrantId (155-176), validRelation (220-224) and
7
+ // validateGrants in "snapshot" mode plus requireWarehouseVersions (240-342),
8
+ // which is what the signer emits (validateAccessWorkGrants, seed-auth.ts:611-630).
9
+ /** Resource domains of a work grant (access-domain.ts:41). */
10
+ export const WORK_GRANT_DOMAINS = ["clinical-organization", "agenda", "warehouse"];
11
+ /** Relations of a work grant (access-domain.ts:42). */
12
+ export const WORK_GRANT_RELATIONS = ["owner", "administrator", "assigned"];
13
+ /** Longest workGrants list Access signs (access-domain.ts:261). */
14
+ export const MAX_WORK_GRANTS = 256;
15
+ /** Longest resourceId (and parent resourceId) Access accepts (access-domain.ts:294, 306). */
16
+ export const MAX_WORK_GRANT_RESOURCE_ID_LENGTH = 256;
17
+ /** Prefix of every work grant id (access-domain.ts:140). */
18
+ export const WORK_GRANT_ID_PREFIX = "sha256:v1:";
19
+ /**
20
+ * Whether a domain admits a relation (access-domain.ts:220-224): a clinical
21
+ * organization is owned or administered; an agenda or a warehouse is assigned.
22
+ */
23
+ export function isValidWorkGrantRelation(domain, relation) {
24
+ return domain === "clinical-organization" ? relation === "owner" || relation === "administrator" : relation === "assigned";
25
+ }
26
+ // JSON text of one string. JSON.stringify of a primitive string never looks up
27
+ // toJSON (ECMA-262 SerializeJSONProperty: only an Object or a BigInt is asked
28
+ // for toJSON, and the wrapper holder's "" property is its own data property),
29
+ // so a polluted String.prototype.toJSON is never called.
30
+ function jsonString(value) {
31
+ if (typeof value !== "string") {
32
+ throw new TypeError("Work grant identity fields must be strings.");
33
+ }
34
+ return JSON.stringify(value);
35
+ }
36
+ // access-domain.ts:155-168: `JSON.stringify([tenantId, userId, domain,
37
+ // resourceId, relation, parent ? [parent.domain, parent.resourceId] : null])`,
38
+ // built here as text from the JSON of each string. The result is byte-identical
39
+ // for strings, but no array is serialized, so a polluted Array.prototype.toJSON
40
+ // or Object.prototype.toJSON can never run or change the tuple.
41
+ function identityValue(tenantId, userId, domain, resourceId, relation, parentResource) {
42
+ const parent = parentResource ? `[${jsonString(parentResource.domain)},${jsonString(parentResource.resourceId)}]` : "null";
43
+ return `[${jsonString(tenantId)},${jsonString(userId)},${jsonString(domain)},${jsonString(resourceId)},${jsonString(relation)},${parent}]`;
44
+ }
45
+ /**
46
+ * The deterministic id Access gives a work grant (access-domain.ts:139-141,
47
+ * 155-176): `sha256:v1:` followed by the base64url (no padding) SHA-256 of the
48
+ * UTF-8 JSON of `[tenantId, userId, domain, resourceId, relation, parent]`,
49
+ * where parent is `[parentResource.domain, parentResource.resourceId]` or
50
+ * null. In the token, tenantId is the `tenantId` claim and userId the `sub`
51
+ * claim. It validates nothing else (use validateWorkGrantsV2 for token data)
52
+ * and runs anywhere: the SHA-256 is plain TypeScript, without node:crypto.
53
+ * Every identity field (tenantId, userId, domain, resourceId, relation and,
54
+ * when there is a parent, its domain and resourceId) must be a string, read
55
+ * from own data properties; otherwise it throws a TypeError. The tuple is
56
+ * serialized without ever calling a (possibly polluted) toJSON.
57
+ */
58
+ export function workGrantId(tenantId, userId, grant) {
59
+ // Only own data properties count (an inherited or accessor field reads as
60
+ // absent), so a polluted Object.prototype.parentResource never changes the id.
61
+ const own = (record, field) => {
62
+ if (typeof record !== "object" || record === null) {
63
+ return undefined;
64
+ }
65
+ const value = ownDataValue(record, field);
66
+ return value === OWN_ACCESSOR ? undefined : value;
67
+ };
68
+ const parent = own(grant, "parentResource");
69
+ const parentResource = parent ? { domain: own(parent, "domain"), resourceId: own(parent, "resourceId") } : undefined;
70
+ const identity = identityValue(tenantId, userId, own(grant, "domain"), own(grant, "resourceId"), own(grant, "relation"), parentResource);
71
+ return `${WORK_GRANT_ID_PREFIX}${sha256Base64Url(identity)}`;
72
+ }
73
+ /** Stable code of WorkGrantsInvalidError. */
74
+ export const WORK_GRANTS_INVALID = "WORK_GRANTS_INVALID";
75
+ /**
76
+ * Thrown by validateWorkGrantsV2. Carries the stable `code`, the rule
77
+ * (`reason`) and the index of the entry at fault when there is one, never a
78
+ * value of the token. The service maps it to a 401, like a rejection of
79
+ * readInternalAuthorization.
80
+ */
81
+ export class WorkGrantsInvalidError extends Error {
82
+ code = WORK_GRANTS_INVALID;
83
+ reason;
84
+ index;
85
+ constructor(reason, index) {
86
+ super(`Work grants are invalid: ${reason}${index === undefined ? "" : ` at index ${index}`}.`);
87
+ this.name = "WorkGrantsInvalidError";
88
+ this.reason = reason;
89
+ this.index = index;
90
+ }
91
+ }
92
+ const DOMAINS = new Set(WORK_GRANT_DOMAINS);
93
+ const RELATIONS = new Set(WORK_GRANT_RELATIONS);
94
+ // access-domain.ts:276-280 (snapshot mode: warehouse also carries grantVersion).
95
+ const GRANT_FIELDS = new Set(["id", "domain", "resourceId", "relation", "parentResource"]);
96
+ const WAREHOUSE_FIELDS = new Set([...GRANT_FIELDS, "notBefore", "expiresAt", "grantVersion"]);
97
+ const PARENT_FIELDS = new Set(["domain", "resourceId"]);
98
+ // access-domain.ts:284-289: minimum of each validity field.
99
+ const VALIDITY_MINIMUMS = [
100
+ ["grantVersion", 1],
101
+ ["notBefore", 0],
102
+ ["expiresAt", 0]
103
+ ];
104
+ // Thrown inside the validator only and recognised by identity (never with
105
+ // instanceof or a trap of a value the input threw).
106
+ class Invalid extends Error {
107
+ reason;
108
+ index;
109
+ constructor(reason, index) {
110
+ super(reason);
111
+ this.reason = reason;
112
+ this.index = index;
113
+ this.name = "Invalid";
114
+ }
115
+ }
116
+ const INVALIDS = new WeakSet();
117
+ function invalid(reason, index) {
118
+ const error = new Invalid(reason, index);
119
+ INVALIDS.add(error);
120
+ throw error;
121
+ }
122
+ function isPlainRecord(value) {
123
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
124
+ return false;
125
+ }
126
+ const prototype = Object.getPrototypeOf(value);
127
+ return prototype === Object.prototype || prototype === null;
128
+ }
129
+ // The own data properties of a plain record, by name; only string keys of
130
+ // `allowed`, never an accessor. Reads descriptors only (no getter, no get trap).
131
+ function ownFields(record, allowed, index, notAllowed) {
132
+ const fields = new Map();
133
+ for (const key of Reflect.ownKeys(record)) {
134
+ if (typeof key !== "string") {
135
+ invalid("entry-invalid", index);
136
+ }
137
+ if (!allowed.has(key)) {
138
+ invalid(notAllowed, index);
139
+ }
140
+ const value = ownDataValue(record, key);
141
+ if (value === OWN_ACCESSOR) {
142
+ invalid("entry-invalid", index);
143
+ }
144
+ fields.set(key, value);
145
+ }
146
+ return fields;
147
+ }
148
+ // access-domain.ts:293-296 and 302-306: a non-empty string equal to its trim, at most 256 characters.
149
+ function isResourceId(value) {
150
+ return typeof value === "string" && value.length > 0 && value === value.trim() && value.length <= MAX_WORK_GRANT_RESOURCE_ID_LENGTH;
151
+ }
152
+ // Null-prototype frozen record: an absent optional field reads as undefined
153
+ // even under a polluted Object.prototype.
154
+ function nullRecord(fields) {
155
+ return Object.freeze(Object.assign(Object.create(null), fields));
156
+ }
157
+ function readParent(value, domain, index) {
158
+ if (value === undefined) {
159
+ return undefined;
160
+ }
161
+ if (!isPlainRecord(value) || domain === "clinical-organization") {
162
+ return invalid("parent-invalid", index);
163
+ }
164
+ const fields = ownFields(value, PARENT_FIELDS, index, "parent-invalid");
165
+ const resourceId = fields.get("resourceId");
166
+ if (fields.get("domain") !== "clinical-organization" || !isResourceId(resourceId)) {
167
+ return invalid("parent-invalid", index);
168
+ }
169
+ return nullRecord({ domain: "clinical-organization", resourceId });
170
+ }
171
+ function readGrant(item, index, context, identities) {
172
+ if (!isPlainRecord(item)) {
173
+ return invalid("entry-invalid", index);
174
+ }
175
+ // Every own key must be a field the record may have; the domain decides which.
176
+ const all = ownFields(item, WAREHOUSE_FIELDS, index, "field-not-allowed");
177
+ const domain = all.get("domain");
178
+ const relation = all.get("relation");
179
+ if (!DOMAINS.has(domain)) {
180
+ return invalid("domain-invalid", index);
181
+ }
182
+ const grantDomain = domain;
183
+ if (!RELATIONS.has(relation) || !isValidWorkGrantRelation(grantDomain, relation)) {
184
+ return invalid("relation-invalid", index);
185
+ }
186
+ const grantRelation = relation;
187
+ const allowed = grantDomain === "warehouse" ? WAREHOUSE_FIELDS : GRANT_FIELDS;
188
+ for (const key of all.keys()) {
189
+ if (!allowed.has(key)) {
190
+ invalid("field-not-allowed", index);
191
+ }
192
+ }
193
+ const validity = new Map();
194
+ for (const [field, minimum] of VALIDITY_MINIMUMS) {
195
+ if (all.has(field)) {
196
+ const value = all.get(field);
197
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
198
+ invalid("validity-invalid", index);
199
+ }
200
+ validity.set(field, value);
201
+ }
202
+ }
203
+ const notBefore = validity.get("notBefore");
204
+ const expiresAt = validity.get("expiresAt");
205
+ if (notBefore !== undefined && expiresAt !== undefined && notBefore >= expiresAt) {
206
+ invalid("window-invalid", index);
207
+ }
208
+ const grantVersion = validity.get("grantVersion");
209
+ if (grantDomain === "warehouse" && grantVersion === undefined) {
210
+ invalid("grant-version-required", index);
211
+ }
212
+ const resourceId = all.get("resourceId");
213
+ if (!isResourceId(resourceId)) {
214
+ return invalid("resource-id-invalid", index);
215
+ }
216
+ const parentResource = readParent(all.get("parentResource"), grantDomain, index);
217
+ const identity = identityValue(context.tenantId, context.sub, grantDomain, resourceId, grantRelation, parentResource);
218
+ const id = all.get("id");
219
+ if (typeof id !== "string" || id !== `${WORK_GRANT_ID_PREFIX}${sha256Base64Url(identity)}`) {
220
+ return invalid("id-invalid", index);
221
+ }
222
+ // Access merges grants by identity before signing (access-domain.ts:332-337): a duplicate is never signed.
223
+ if (identities.has(identity)) {
224
+ return invalid("duplicate", index);
225
+ }
226
+ identities.add(identity);
227
+ return nullRecord({
228
+ id,
229
+ domain: grantDomain,
230
+ resourceId,
231
+ relation: grantRelation,
232
+ ...(parentResource !== undefined ? { parentResource } : {}),
233
+ ...(grantVersion !== undefined ? { grantVersion } : {}),
234
+ ...(notBefore !== undefined ? { notBefore } : {}),
235
+ ...(expiresAt !== undefined ? { expiresAt } : {})
236
+ });
237
+ }
238
+ function validate(grants, context) {
239
+ const tenantId = isPlainRecord(context) ? ownDataValue(context, "tenantId") : undefined;
240
+ const sub = isPlainRecord(context) ? ownDataValue(context, "sub") : undefined;
241
+ if (typeof tenantId !== "string" || tenantId.length === 0 || typeof sub !== "string" || sub.length === 0) {
242
+ return invalid("context-invalid");
243
+ }
244
+ if (Array.isArray(grants)) {
245
+ const length = ownDataValue(grants, "length");
246
+ if (typeof length === "number" && length > MAX_WORK_GRANTS) {
247
+ return invalid("too-many");
248
+ }
249
+ }
250
+ const read = readList(grants);
251
+ if (read.status !== "ok") {
252
+ return invalid("not-array");
253
+ }
254
+ // Checked again on the copy: a hostile proxy may report one length to the
255
+ // first read and another to readList's.
256
+ if (read.items.length > MAX_WORK_GRANTS) {
257
+ return invalid("too-many");
258
+ }
259
+ const identities = new Set();
260
+ const result = [];
261
+ for (let index = 0; index < read.items.length; index += 1) {
262
+ appendOwn(result, readGrant(read.items[index], index, { tenantId, sub }, identities));
263
+ }
264
+ return Object.freeze(result);
265
+ }
266
+ /**
267
+ * Validates the `workGrants` claim of a v2 token the way Access builds it
268
+ * (access-domain.ts:240-342 in snapshot mode, plus requireWarehouseVersions)
269
+ * and returns it typed. readInternalAuthorization does NOT validate
270
+ * workGrants: it passes the list through, so every service that scopes by work
271
+ * grant (or wants to refuse a token Access would not have signed) calls this
272
+ * with the token's verified `tenantId` and `sub`:
273
+ *
274
+ * - an array of at most MAX_WORK_GRANTS plain records;
275
+ * - each with only id, domain, resourceId, relation and parentResource, plus
276
+ * grantVersion, notBefore and expiresAt for domain warehouse;
277
+ * - domain in WORK_GRANT_DOMAINS and a relation the domain admits
278
+ * (organization owner/administrator, agenda and warehouse assigned);
279
+ * - resourceId a non-empty string without surrounding spaces of at most 256
280
+ * characters; parentResource only `{ domain: "clinical-organization",
281
+ * resourceId }` with the same resourceId rule, and never on an organization;
282
+ * - grantVersion a safe integer >= 1, required on warehouse; notBefore and
283
+ * expiresAt safe integers >= 0 with notBefore < expiresAt;
284
+ * - id equal to workGrantId(tenantId, sub, grant) (the legacy `|`-joined id
285
+ * that Access still reads from storage is never signed, so it is refused);
286
+ * - no two entries with the same identity.
287
+ *
288
+ * Returns a frozen copy in the token's order: frozen null-prototype records
289
+ * with only the fields present. Throws WorkGrantsInvalidError (code
290
+ * WORK_GRANTS_INVALID, a stable `reason` and the entry index) on the first
291
+ * violation, also for a hostile input (proxies, accessors, throwing traps):
292
+ * only own data properties are read, no getter runs and nothing of the input
293
+ * is modified. Pure and without node:crypto: it also runs in a browser.
294
+ */
295
+ export function validateWorkGrantsV2(grants, context) {
296
+ let failure;
297
+ try {
298
+ return validate(grants, context);
299
+ }
300
+ catch (error) {
301
+ // Identity check only: no trap of a value thrown by the input runs here.
302
+ failure = INVALIDS.has(error) ? error : new Invalid("unreadable", undefined);
303
+ }
304
+ throw new WorkGrantsInvalidError(failure.reason, failure.index);
305
+ }
306
+ //# sourceMappingURL=work-grants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-grants.js","sourceRoot":"","sources":["../../src/authorization/work-grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,yEAAyE;AACzE,2EAA2E;AAC3E,iFAAiF;AACjF,gFAAgF;AAChF,6EAA6E;AAC7E,mFAAmF;AAEnF,8DAA8D;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,uBAAuB,EAAE,QAAQ,EAAE,WAAW,C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1D,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAe,EAAE,OAA0B;IAC9E,IAAI,OAAgB,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yEAAyE;QACzE,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAgB,CAAC,CAAC,CAAC,CAAE,KAAiB,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACvG,CAAC;IACD,MAAM,IAAI,sBAAsB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Canonical JSON text of JSON data (see the module comment); never runs toJSON. */
2
+ export declare function canonicalJson(value: unknown): string;
3
+ //# sourceMappingURL=canonical-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../../src/capabilities/canonical-json.ts"],"names":[],"mappings":"AA2EA,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMpD"}
@@ -0,0 +1,83 @@
1
+ // Canonical JSON text for the package's hashes (catalogHash and
2
+ // PERMISSION_MIGRATION.version). For JSON data (null, booleans, finite
3
+ // numbers, strings, arrays and records) it produces the text of
4
+ // `stableStringify` (../stable-json.ts): object keys sorted, undefined
5
+ // properties dropped, undefined array items as null, non-finite numbers as
6
+ // null, functions and symbols skipped. Known differences, absent from the
7
+ // hashed data (test/capabilities/canonical-json.test.ts checks the catalog and
8
+ // the migration have no integer-like, "__proto__" or "toJSON" key, and the
9
+ // hashes always serialize an array or a record):
10
+ // - integer-like keys ("2", "10"): canonicalJson keeps the sorted string order
11
+ // ("10" before "2"); stableStringify's result object lists them in numeric
12
+ // order first;
13
+ // - an own "__proto__" key: canonicalJson writes it; stableStringify's
14
+ // assignment to a plain object drops it;
15
+ // - an own "toJSON" function: canonicalJson skips it like any function value
16
+ // and serializes the record; stableStringify copies it and JSON.stringify
17
+ // then calls it;
18
+ // - at the top level, undefined, a function or a symbol: canonicalJson throws
19
+ // a TypeError; stableStringify returns undefined. Unlike JSON.stringify of an object or
20
+ // array, it never looks up or calls toJSON, so a polluted
21
+ // Object.prototype.toJSON, Array.prototype.toJSON or String.prototype.toJSON
22
+ // cannot change a hash: only primitives are passed to JSON.stringify, and
23
+ // ECMA-262 SerializeJSONProperty asks only an Object or a BigInt for toJSON.
24
+ // A BigInt is refused (JSON.stringify refuses it too) and circular data
25
+ // throws, as in stableStringify.
26
+ //
27
+ // Internal to the package: not exported by any subpath.
28
+ function serialize(value, seen) {
29
+ if (value === null) {
30
+ return "null";
31
+ }
32
+ switch (typeof value) {
33
+ case "string":
34
+ case "boolean":
35
+ return JSON.stringify(value);
36
+ case "number":
37
+ return Number.isFinite(value) ? JSON.stringify(value) : "null";
38
+ case "bigint":
39
+ throw new TypeError("canonicalJson cannot serialize a BigInt.");
40
+ case "object":
41
+ break;
42
+ default:
43
+ // undefined, functions and symbols have no JSON text.
44
+ return undefined;
45
+ }
46
+ const object = value;
47
+ if (seen.has(object)) {
48
+ throw new Error("Cannot stableStringify circular data.");
49
+ }
50
+ seen.add(object);
51
+ let text;
52
+ if (Array.isArray(object)) {
53
+ text = "[";
54
+ for (let index = 0; index < object.length; index += 1) {
55
+ text += `${index > 0 ? "," : ""}${serialize(object[index], seen) ?? "null"}`;
56
+ }
57
+ text += "]";
58
+ }
59
+ else {
60
+ const record = object;
61
+ text = "{";
62
+ let first = true;
63
+ for (const key of Object.keys(record).sort()) {
64
+ const item = serialize(record[key], seen);
65
+ if (item !== undefined) {
66
+ text += `${first ? "" : ","}${JSON.stringify(key)}:${item}`;
67
+ first = false;
68
+ }
69
+ }
70
+ text += "}";
71
+ }
72
+ seen.delete(object);
73
+ return text;
74
+ }
75
+ /** Canonical JSON text of JSON data (see the module comment); never runs toJSON. */
76
+ export function canonicalJson(value) {
77
+ const text = serialize(value, new WeakSet());
78
+ if (text === undefined) {
79
+ throw new TypeError("canonicalJson needs JSON data.");
80
+ }
81
+ return text;
82
+ }
83
+ //# sourceMappingURL=canonical-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../../src/capabilities/canonical-json.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,uEAAuE;AACvE,gEAAgE;AAChE,uEAAuE;AACvE,2EAA2E;AAC3E,0EAA0E;AAC1E,+EAA+E;AAC/E,2EAA2E;AAC3E,iDAAiD;AACjD,+EAA+E;AAC/E,6EAA6E;AAC7E,iBAAiB;AACjB,uEAAuE;AACvE,2CAA2C;AAC3C,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,8EAA8E;AAC9E,0FAA0F;AAC1F,0DAA0D;AAC1D,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,wEAAwE;AACxE,iCAAiC;AACjC,EAAE;AACF,wDAAwD;AAExD,SAAS,SAAS,CAAC,KAAc,EAAE,IAAqB;IACtD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,QAAQ;YACX,OAAO,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