@adea-ai/contracts 1.9.0 → 1.9.1
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/dist/canonical-json.d.ts +33 -0
- package/dist/canonical-json.d.ts.map +1 -0
- package/dist/canonical-json.js +63 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic JSON serialization ("canonical JSON") for content digests,
|
|
3
|
+
* idempotency keys, fingerprints and structural equality checks.
|
|
4
|
+
*
|
|
5
|
+
* Pinned semantics:
|
|
6
|
+
*
|
|
7
|
+
* - Object entries are sorted by key in CODE-POINT (UTF-16 code unit) order:
|
|
8
|
+
* `(a, b) => (a < b ? -1 : a > b ? 1 : 0)`.
|
|
9
|
+
* NEVER use `String.prototype.localeCompare` for this ordering: it delegates
|
|
10
|
+
* to ICU and is locale- and ICU-version-dependent. Proven divergence fixture:
|
|
11
|
+
* the keys `['a-b', 'ab', 'a_b', 'Aa', 'a!']` order differently under
|
|
12
|
+
* `localeCompare` than under code-point comparison (ICU collation treats
|
|
13
|
+
* `-`/`_` as variable-weight punctuation), so the same object serializes to
|
|
14
|
+
* different bytes on different hosts and any digest, idempotency key or
|
|
15
|
+
* scope check derived from it can silently break across deployments.
|
|
16
|
+
* - Object entries whose value is `undefined` are omitted (JSON.stringify
|
|
17
|
+
* parity).
|
|
18
|
+
* - Arrays keep their order; `undefined` array elements serialize as `null`
|
|
19
|
+
* (JSON.stringify parity).
|
|
20
|
+
* - Leaves serialize exactly like `JSON.stringify`: finite numbers as JSON
|
|
21
|
+
* numbers, with `NaN`, `Infinity` and `-Infinity` mapped to `null`
|
|
22
|
+
* (JSON.stringify parity) and `-0` normalized to `0` (JSON.stringify parity).
|
|
23
|
+
* - `undefined` at the document root serializes as `null`.
|
|
24
|
+
* - `bigint`, function and symbol values throw `TypeError` (JSON.stringify
|
|
25
|
+
* parity for bigint; functions and symbols are likewise rejected instead of
|
|
26
|
+
* being silently dropped or coerced).
|
|
27
|
+
* - Values must be JSON-compatible plain data: arrays, plain objects
|
|
28
|
+
* (prototype `Object.prototype` or `null`) and JSON leaves. Anything else
|
|
29
|
+
* (Date, Map, Set, class instances, ...) throws `TypeError` rather than
|
|
30
|
+
* serializing to a lossy or implementation-dependent form.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canonicalJsonStringify(value: unknown): string;
|
|
33
|
+
//# sourceMappingURL=canonical-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic JSON serialization ("canonical JSON") for content digests,
|
|
3
|
+
* idempotency keys, fingerprints and structural equality checks.
|
|
4
|
+
*
|
|
5
|
+
* Pinned semantics:
|
|
6
|
+
*
|
|
7
|
+
* - Object entries are sorted by key in CODE-POINT (UTF-16 code unit) order:
|
|
8
|
+
* `(a, b) => (a < b ? -1 : a > b ? 1 : 0)`.
|
|
9
|
+
* NEVER use `String.prototype.localeCompare` for this ordering: it delegates
|
|
10
|
+
* to ICU and is locale- and ICU-version-dependent. Proven divergence fixture:
|
|
11
|
+
* the keys `['a-b', 'ab', 'a_b', 'Aa', 'a!']` order differently under
|
|
12
|
+
* `localeCompare` than under code-point comparison (ICU collation treats
|
|
13
|
+
* `-`/`_` as variable-weight punctuation), so the same object serializes to
|
|
14
|
+
* different bytes on different hosts and any digest, idempotency key or
|
|
15
|
+
* scope check derived from it can silently break across deployments.
|
|
16
|
+
* - Object entries whose value is `undefined` are omitted (JSON.stringify
|
|
17
|
+
* parity).
|
|
18
|
+
* - Arrays keep their order; `undefined` array elements serialize as `null`
|
|
19
|
+
* (JSON.stringify parity).
|
|
20
|
+
* - Leaves serialize exactly like `JSON.stringify`: finite numbers as JSON
|
|
21
|
+
* numbers, with `NaN`, `Infinity` and `-Infinity` mapped to `null`
|
|
22
|
+
* (JSON.stringify parity) and `-0` normalized to `0` (JSON.stringify parity).
|
|
23
|
+
* - `undefined` at the document root serializes as `null`.
|
|
24
|
+
* - `bigint`, function and symbol values throw `TypeError` (JSON.stringify
|
|
25
|
+
* parity for bigint; functions and symbols are likewise rejected instead of
|
|
26
|
+
* being silently dropped or coerced).
|
|
27
|
+
* - Values must be JSON-compatible plain data: arrays, plain objects
|
|
28
|
+
* (prototype `Object.prototype` or `null`) and JSON leaves. Anything else
|
|
29
|
+
* (Date, Map, Set, class instances, ...) throws `TypeError` rather than
|
|
30
|
+
* serializing to a lossy or implementation-dependent form.
|
|
31
|
+
*/
|
|
32
|
+
export function canonicalJsonStringify(value) {
|
|
33
|
+
return serialize(value);
|
|
34
|
+
}
|
|
35
|
+
function compareCodePoint(left, right) {
|
|
36
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
function serialize(value) {
|
|
39
|
+
if (value === undefined || value === null)
|
|
40
|
+
return 'null';
|
|
41
|
+
const type = typeof value;
|
|
42
|
+
if (type === 'string' || type === 'boolean')
|
|
43
|
+
return JSON.stringify(value);
|
|
44
|
+
if (type === 'number') {
|
|
45
|
+
if (!Number.isFinite(value))
|
|
46
|
+
return 'null';
|
|
47
|
+
return JSON.stringify(value);
|
|
48
|
+
}
|
|
49
|
+
if (type === 'bigint' || type === 'function' || type === 'symbol')
|
|
50
|
+
throw new TypeError(`canonicalJsonStringify: cannot serialize ${type} value`);
|
|
51
|
+
if (Array.isArray(value))
|
|
52
|
+
return `[${value.map((entry) => serialize(entry)).join(',')}]`;
|
|
53
|
+
const prototype = Object.getPrototypeOf(value);
|
|
54
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
55
|
+
throw new TypeError('canonicalJsonStringify: value is not JSON-compatible plain data');
|
|
56
|
+
const entries = Object.entries(value)
|
|
57
|
+
.filter(([, entry]) => entry !== undefined)
|
|
58
|
+
.sort(([left], [right]) => compareCodePoint(left, right));
|
|
59
|
+
return `{${entries
|
|
60
|
+
.map(([key, entry]) => `${JSON.stringify(key)}:${serialize(entry)}`)
|
|
61
|
+
.join(',')}}`;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=canonical-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa;IACnD,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAA;IACxD,MAAM,IAAI,GAAG,OAAO,KAAK,CAAA;IACzB,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACzE,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,MAAM,CAAA;QAC1C,OAAO,IAAI,C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":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAE/B,eAAO,MAAM,WAAW,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAE/B,eAAO,MAAM,WAAW,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAE/B,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAE/B,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/contracts",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "Runtime-independent service boundary between Adea and the Control Plane: canonical identifiers, envelopes, Control API schemas, pagination, and versioning.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|