@astrale-os/kernel-dsl 0.2.0-beta.25 → 0.2.0-beta.27
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.
|
@@ -2,6 +2,8 @@ import { json } from '@astrale-os/kernel-dsl/value';
|
|
|
2
2
|
import { asDomainSchema } from '../model/schema.js';
|
|
3
3
|
import { digestDomainSchemaBytes } from './domain.digest.js';
|
|
4
4
|
import { canonicalizeDomainSchema } from './domain.js';
|
|
5
|
+
// Only canonical schemas created here own a retained revision, never caller-owned input.
|
|
6
|
+
const revisions = new WeakMap();
|
|
5
7
|
export function canonicalDomainSchema(value) {
|
|
6
8
|
return canonicalDomainSchemaAfterValidation(value);
|
|
7
9
|
}
|
|
@@ -10,8 +12,9 @@ export function canonicalDomainSchemaAfterValidation(value) {
|
|
|
10
12
|
const schema = asDomainSchema(canonicalizeDomainSchema(value));
|
|
11
13
|
const bytes = json.encode(schema);
|
|
12
14
|
const revision = digestDomainSchemaBytes(bytes);
|
|
15
|
+
revisions.set(schema, revision);
|
|
13
16
|
return Object.freeze({ schema, bytes, revision });
|
|
14
17
|
}
|
|
15
18
|
export function revisionOfDomainSchema(schema) {
|
|
16
|
-
return canonicalDomainSchema(schema).revision;
|
|
19
|
+
return revisions.get(schema) ?? canonicalDomainSchema(schema).revision;
|
|
17
20
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { Value } from './types.js';
|
|
1
2
|
import { type Options } from './limits.js';
|
|
2
3
|
/** RFC 8785 canonical JSON for one admitted portable snapshot. */
|
|
3
4
|
export declare function serialize(input: unknown, options?: Options): string;
|
|
5
|
+
/** Serialize a trusted portable value whose default structural admission proof is still valid. */
|
|
6
|
+
export declare function serializeAdmitted(input: Value): string;
|
|
4
7
|
export declare function encode(input: unknown, options?: Options): Uint8Array;
|
package/dist/value/canonical.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { accept } from './accept.js';
|
|
2
2
|
import { BoundaryError } from './error.js';
|
|
3
|
-
import { limitsFor } from './limits.js';
|
|
3
|
+
import { defaultLimits, limitsFor } from './limits.js';
|
|
4
4
|
import { utf8Length } from './unicode.js';
|
|
5
5
|
const encoder = new TextEncoder();
|
|
6
6
|
/** RFC 8785 canonical JSON for one admitted portable snapshot. */
|
|
7
7
|
export function serialize(input, options) {
|
|
8
8
|
const limits = limitsFor(options);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
return serializeSnapshot(accept(input, options), limits.maxBytes);
|
|
10
|
+
}
|
|
11
|
+
/** Serialize a trusted portable value whose default structural admission proof is still valid. */
|
|
12
|
+
export function serializeAdmitted(input) {
|
|
13
|
+
return serializeSnapshot(input, defaultLimits.maxBytes);
|
|
14
|
+
}
|
|
15
|
+
function serializeSnapshot(input, maxBytes) {
|
|
16
|
+
const output = serializeValue(input);
|
|
17
|
+
if (utf8Length(output, maxBytes) > maxBytes) {
|
|
18
|
+
throw new BoundaryError('VALUE_LIMIT', `Canonical JSON exceeds the ${maxBytes}-byte limit`);
|
|
12
19
|
}
|
|
13
20
|
return output;
|
|
14
21
|
}
|
package/dist/value/json.d.ts
CHANGED
package/dist/value/json.js
CHANGED