@astrale-os/kernel-dsl 1.0.0-beta.20 → 1.0.0-beta.22
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/v1/builder/index.d.ts +2 -1
- package/dist/v1/builder/lowering/value/zod.js +30 -0
- package/dist/v1/builder/policy/authoring.d.ts +1 -10
- package/dist/v1/builder/policy/authoring.js +6 -14
- package/dist/v1/builder/policy/legacy/edge.d.ts +28 -0
- package/dist/v1/builder/policy/legacy/edge.js +16 -0
- package/dist/v1/domain/create.js +5 -5
- package/dist/v1/domain/model/input.d.ts +14 -10
- package/dist/v1/domain/projection/classes.js +8 -8
- package/dist/v1/domain/validation/create.d.ts +1 -15
- package/dist/v1/domain/validation/create.js +19 -22
- package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
- package/dist/v1/language/value/regexp/unicode.js +1 -1
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +5 -4
- package/dist/v1/schema/admission/callable.d.ts +1 -1
- package/dist/v1/schema/resolution/domain.d.ts +1 -1
- package/dist/v1/schema/validation/domain.json-schema.js +27 -2
- package/dist/v1/schema/validation/domain.structure.d.ts +49 -46
- package/dist/v1/schema/validation/domain.structure.js +140 -50
- package/package.json +3 -3
|
@@ -20,7 +20,8 @@ export type { ClassRuleChecks, CreateRuleChecks, EdgeRuleChecks, } from '../lang
|
|
|
20
20
|
export type { AuthoredPropertyProjection, AuthoredMethodProjection, ClassIdentityProjection, ClassOwnerProjection, ClassReferenceProjection, } from './class/projection.js';
|
|
21
21
|
export type { PathAuthoring } from './value/path.js';
|
|
22
22
|
export type { Lazy } from './schema/lazy.js';
|
|
23
|
-
export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds,
|
|
23
|
+
export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
|
|
24
|
+
export type { PolicyEdgeInput } from './policy/legacy/edge.js';
|
|
24
25
|
export type { AutoOptions, AutoProperty, Property, PropertyFieldInput as PropertyField, PropertyOptions, ValueSchemaInput, } from './class/property.js';
|
|
25
26
|
export type { CorePropertyInput } from './schema/projection.js';
|
|
26
27
|
export type { ClassProjection, FunctionProjection, MethodProjection, PropertyProjection, } from './schema/projection.js';
|
|
@@ -35,6 +35,7 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
|
|
|
35
35
|
path,
|
|
36
36
|
zodSchema: source,
|
|
37
37
|
});
|
|
38
|
+
keepLoweredShape(source, jsonSchema);
|
|
38
39
|
}
|
|
39
40
|
},
|
|
40
41
|
});
|
|
@@ -62,6 +63,28 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
|
|
|
62
63
|
diagnostics: [],
|
|
63
64
|
};
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The lowering keeps one spelling per contract, whatever Zod version renders it, so that a Domain
|
|
68
|
+
* built from unchanged source keeps its schema digest. Every node lowers as its own Zod schema: a
|
|
69
|
+
* union by `anyOf`, an intersection by `allOf`, a tuple by its `prefixItems` and rest alone. Zod
|
|
70
|
+
* 4.6 compacts bare-type unions into a `type` array, folds object intersections, and closes tuples;
|
|
71
|
+
* the marker leaves no node bare, so the first two do not apply, and the tuple bounds are removed.
|
|
72
|
+
* `copyZodJson` drops the marker.
|
|
73
|
+
*/
|
|
74
|
+
function keepLoweredShape(schema, jsonSchema) {
|
|
75
|
+
const def = getSchemaDefinition(schema);
|
|
76
|
+
if (def?.type === 'tuple' && Array.isArray(def.items)) {
|
|
77
|
+
if (jsonSchema.items === false)
|
|
78
|
+
delete jsonSchema.items;
|
|
79
|
+
if (jsonSchema.maxItems === def.items.length)
|
|
80
|
+
delete jsonSchema.maxItems;
|
|
81
|
+
if (typeof jsonSchema.minItems === 'number' && jsonSchema.minItems <= def.items.length) {
|
|
82
|
+
delete jsonSchema.minItems;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
jsonSchema[LOWERED_NODE] = true;
|
|
86
|
+
}
|
|
87
|
+
const LOWERED_NODE = '~astrale-lowered-node';
|
|
65
88
|
function copyZodJson(value) {
|
|
66
89
|
if (value === null || ['boolean', 'number', 'string'].includes(typeof value))
|
|
67
90
|
return value;
|
|
@@ -74,6 +97,8 @@ function copyZodJson(value) {
|
|
|
74
97
|
for (const key of Reflect.ownKeys(value)) {
|
|
75
98
|
if (typeof key === 'symbol')
|
|
76
99
|
throw new TypeError('Zod emitted symbol-keyed schema metadata.');
|
|
100
|
+
if (key === LOWERED_NODE)
|
|
101
|
+
continue;
|
|
77
102
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
78
103
|
if (descriptor === undefined)
|
|
79
104
|
continue;
|
|
@@ -117,6 +142,11 @@ function inspectZodSchema(root, pointer, position) {
|
|
|
117
142
|
if (def.coerce === true) {
|
|
118
143
|
diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', schemaPointer, 'Zod coercion changes the accepted input domain and is not serializable as JSON Schema.'));
|
|
119
144
|
}
|
|
145
|
+
if (type === 'record' && isZodType(def.keyType)) {
|
|
146
|
+
if (getSchemaDefinition(def.keyType)?.type === 'number') {
|
|
147
|
+
diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', `${schemaPointer}/propertyNames`, 'Zod number record keys accept the member names that spell a number, which V1 states by no portable pattern.'));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
120
150
|
inspectCheck(def, schemaPointer, diagnostics);
|
|
121
151
|
if (Array.isArray(def.checks)) {
|
|
122
152
|
def.checks.forEach((check, index) => {
|
|
@@ -7,16 +7,7 @@ import type { EdgeClassReferenceInput, NodeClassReferenceInput } from '../class/
|
|
|
7
7
|
import type { AuthoringValue } from '../schema/handle.js';
|
|
8
8
|
import type { Lazy } from '../schema/lazy.js';
|
|
9
9
|
import type { ResolveLazy } from '../schema/projection/identity.js';
|
|
10
|
-
|
|
11
|
-
* @deprecated Name the ends by their roles: `edge(classValue, { [role]: term }, { repeat })`
|
|
12
|
-
* lowers to this same pattern.
|
|
13
|
-
*/
|
|
14
|
-
export interface PolicyEdgeInput {
|
|
15
|
-
readonly source: CanonicalPolicyPatternTerm;
|
|
16
|
-
readonly class: EdgeClassReferenceInput;
|
|
17
|
-
readonly target: CanonicalPolicyPatternTerm;
|
|
18
|
-
readonly repeat?: PolicyEdgeRepeat;
|
|
19
|
-
}
|
|
10
|
+
import type { PolicyEdgeInput } from './legacy/edge.js';
|
|
20
11
|
/** How many Edges of the Class a path between the two terms crosses, both bounds included. */
|
|
21
12
|
export interface PolicyEdgeRepeat {
|
|
22
13
|
readonly min: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertKnownKeys, escapeToken, fail } from '../schema/diagnostic.js';
|
|
2
2
|
import { authoringValue } from '../schema/handle.js';
|
|
3
|
+
import { acceptLegacyEdge } from './legacy/edge.js';
|
|
3
4
|
const declarations = new WeakMap();
|
|
4
5
|
const compositions = new WeakSet();
|
|
5
6
|
export function policyDeclaration(value) {
|
|
@@ -57,8 +58,11 @@ function variableIds() {
|
|
|
57
58
|
}
|
|
58
59
|
function edge(options, args) {
|
|
59
60
|
const pointer = `${options.pointer}/match/edge`;
|
|
60
|
-
if (args[1] === undefined)
|
|
61
|
-
|
|
61
|
+
if (args[1] === undefined) {
|
|
62
|
+
const input = acceptLegacyEdge(args[0], pointer);
|
|
63
|
+
const ref = options.resolveEdgeClass(input.class, `${options.pointer}/match/class`);
|
|
64
|
+
return edgePattern(input.source, ref, input.target, input.repeat);
|
|
65
|
+
}
|
|
62
66
|
const [classValue, ends, edgeOptions] = args;
|
|
63
67
|
const ref = options.resolveEdgeClass(classValue, `${options.pointer}/match/class`);
|
|
64
68
|
const [sourceRole, targetRole] = options.edgeRoles(ref);
|
|
@@ -76,18 +80,6 @@ function edge(options, args) {
|
|
|
76
80
|
}
|
|
77
81
|
return edgePattern(sourceTerm, ref, targetTerm, edgeOptions?.repeat);
|
|
78
82
|
}
|
|
79
|
-
function legacyEdge(options, input, pointer) {
|
|
80
|
-
// Typed callers cannot pass an Edge Class without ends; untyped ones can, and `kind` is read
|
|
81
|
-
// without `in` so a primitive still reaches `assertKnownKeys`.
|
|
82
|
-
if (typeof input === 'function' || input.kind === 'edge') {
|
|
83
|
-
fail('BUILDER_POLICY', pointer, 'edge(classValue, ends) names both ends by their roles.');
|
|
84
|
-
}
|
|
85
|
-
assertKnownKeys(input, ['source', 'class', 'target', 'repeat']);
|
|
86
|
-
if (input.repeat !== undefined)
|
|
87
|
-
assertKnownKeys(input.repeat, ['min', 'max']);
|
|
88
|
-
const ref = options.resolveEdgeClass(input.class, `${options.pointer}/match/class`);
|
|
89
|
-
return edgePattern(input.source, ref, input.target, input.repeat);
|
|
90
|
-
}
|
|
91
83
|
/** The term of one role. An own key holding `undefined` passes through, as it always has. */
|
|
92
84
|
function endTerm(ends, role, pointer, missing) {
|
|
93
85
|
if (!Object.hasOwn(ends, role))
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Edge pattern a Policy named by side, `edge({ source, class, target, repeat })`, before its
|
|
3
|
+
* ends were keyed by the roles of the Edge Class. The canonical `edge(...)` lowers what this accepts
|
|
4
|
+
* as it lowers the role form.
|
|
5
|
+
*
|
|
6
|
+
* Retirement: once no supported SDK, CLI, Shell or Admin builds a Policy with
|
|
7
|
+
* `edge({ source, class, target })`, delete this folder, its re-export in `../../index.ts`, the
|
|
8
|
+
* `edge(input)` overload of `PolicyPatternContext` and the branch of `edge` in `../authoring.ts`
|
|
9
|
+
* that calls `acceptLegacyEdge`.
|
|
10
|
+
*/
|
|
11
|
+
import type { PolicyPatternTerm } from '../../../language/policy/model/policy.js';
|
|
12
|
+
import type { EdgeClassReferenceInput } from '../../class/input.js';
|
|
13
|
+
import type { PolicyEdgeRepeat } from '../authoring.js';
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Name the ends by their roles: `edge(classValue, { [role]: term }, { repeat })`
|
|
16
|
+
* lowers to this same pattern.
|
|
17
|
+
*/
|
|
18
|
+
export interface PolicyEdgeInput {
|
|
19
|
+
readonly source: PolicyPatternTerm;
|
|
20
|
+
readonly class: EdgeClassReferenceInput;
|
|
21
|
+
readonly target: PolicyPatternTerm;
|
|
22
|
+
readonly repeat?: PolicyEdgeRepeat;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `edge(classValue, { [role]: term }, { repeat })`. Refuses an Edge Class passed
|
|
26
|
+
* without ends and a field the side form does not have.
|
|
27
|
+
*/
|
|
28
|
+
export declare function acceptLegacyEdge(input: PolicyEdgeInput, pointer: string): PolicyEdgeInput;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assertKnownKeys, fail } from '../../schema/diagnostic.js';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `edge(classValue, { [role]: term }, { repeat })`. Refuses an Edge Class passed
|
|
4
|
+
* without ends and a field the side form does not have.
|
|
5
|
+
*/
|
|
6
|
+
export function acceptLegacyEdge(input, pointer) {
|
|
7
|
+
// Typed callers cannot pass an Edge Class without ends; untyped ones can, and `kind` is read
|
|
8
|
+
// without `in` so a primitive still reaches `assertKnownKeys`.
|
|
9
|
+
if (typeof input === 'function' || input.kind === 'edge') {
|
|
10
|
+
fail('BUILDER_POLICY', pointer, 'edge(classValue, ends) names both ends by their roles.');
|
|
11
|
+
}
|
|
12
|
+
assertKnownKeys(input, ['source', 'class', 'target', 'repeat']);
|
|
13
|
+
if (input.repeat !== undefined)
|
|
14
|
+
assertKnownKeys(input.repeat, ['min', 'max']);
|
|
15
|
+
return input;
|
|
16
|
+
}
|
package/dist/v1/domain/create.js
CHANGED
|
@@ -123,7 +123,7 @@ function createDefinitions(declarations, classesByKey, input) {
|
|
|
123
123
|
continue;
|
|
124
124
|
if (isFunctionDefinition(definition)) {
|
|
125
125
|
const key = Key.of(definition.ref);
|
|
126
|
-
const
|
|
126
|
+
const { fields, validateInput, validateInputField, validateOutput } = input.validation.callable(key);
|
|
127
127
|
const resolved = Object.freeze({
|
|
128
128
|
ref: definition.ref,
|
|
129
129
|
key,
|
|
@@ -134,11 +134,11 @@ function createDefinitions(declarations, classesByKey, input) {
|
|
|
134
134
|
...(definition.admission === undefined ? {} : { admission: definition.admission }),
|
|
135
135
|
auth: definition.auth,
|
|
136
136
|
policy: definition.policy,
|
|
137
|
-
...(
|
|
137
|
+
...(fields === undefined ? {} : { inputFields: fields }),
|
|
138
138
|
definition,
|
|
139
|
-
validateInput
|
|
140
|
-
validateInputField
|
|
141
|
-
validateOutput
|
|
139
|
+
validateInput,
|
|
140
|
+
validateInputField,
|
|
141
|
+
validateOutput,
|
|
142
142
|
});
|
|
143
143
|
definitionsByKey.set(key, resolved);
|
|
144
144
|
continue;
|
|
@@ -22,14 +22,18 @@ export interface DomainInput {
|
|
|
22
22
|
}
|
|
23
23
|
/** Already-bound validation semantics supplied by source compilation or compiled loading. */
|
|
24
24
|
export interface DomainValidation {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
property(key: PropertyKey): PropertyValidation;
|
|
26
|
+
callable(key: AddressKey.Callable): CallableValidation;
|
|
27
|
+
}
|
|
28
|
+
export interface PropertyValidation {
|
|
29
|
+
readonly ordering?: OrderingKind;
|
|
30
|
+
validate(input: unknown): readonly Diagnostic[];
|
|
31
|
+
/** The admitted program `validate` evaluates. */
|
|
32
|
+
program(): ValueProgram;
|
|
33
|
+
}
|
|
34
|
+
export interface CallableValidation {
|
|
35
|
+
readonly fields?: readonly string[];
|
|
36
|
+
validateInput(input: unknown, options?: Options): readonly Diagnostic[];
|
|
37
|
+
validateInputField(field: string, input: unknown): readonly Diagnostic[];
|
|
38
|
+
validateOutput(output: unknown): readonly Diagnostic[];
|
|
35
39
|
}
|
|
@@ -38,15 +38,15 @@ export function createClasses(definitions, validation) {
|
|
|
38
38
|
const ownProperties = [];
|
|
39
39
|
for (const [name, propertyDefinition] of Object.entries(definition.properties)) {
|
|
40
40
|
const propertyKey = PropertyKeyValue.of(ref, name);
|
|
41
|
-
const ordering = validation.
|
|
41
|
+
const { ordering, validate, program } = validation.property(propertyKey);
|
|
42
42
|
const property = Object.freeze({
|
|
43
43
|
owner: shell,
|
|
44
44
|
name,
|
|
45
45
|
key: propertyKey,
|
|
46
46
|
definition: propertyDefinition,
|
|
47
47
|
...(ordering === undefined ? {} : { ordering }),
|
|
48
|
-
validate
|
|
49
|
-
program
|
|
48
|
+
validate,
|
|
49
|
+
program,
|
|
50
50
|
});
|
|
51
51
|
ownProperties.push(property);
|
|
52
52
|
effectiveProperties.set(property.key, property);
|
|
@@ -59,7 +59,7 @@ export function createClasses(definitions, validation) {
|
|
|
59
59
|
if (definition.kind === 'node') {
|
|
60
60
|
for (const [name, methodDefinition] of Object.entries(definition.methods)) {
|
|
61
61
|
const methodKey = MethodKeyValue.of(ref, name);
|
|
62
|
-
const
|
|
62
|
+
const { fields, validateInput, validateInputField, validateOutput } = validation.callable(methodKey);
|
|
63
63
|
const method = Object.freeze({
|
|
64
64
|
owner: shell,
|
|
65
65
|
name,
|
|
@@ -78,11 +78,11 @@ export function createClasses(definitions, validation) {
|
|
|
78
78
|
static: methodDefinition.static,
|
|
79
79
|
abstract: methodDefinition.abstract,
|
|
80
80
|
executable: isMethodExecutable(definition, methodDefinition),
|
|
81
|
-
...(
|
|
81
|
+
...(fields === undefined ? {} : { inputFields: fields }),
|
|
82
82
|
definition: methodDefinition,
|
|
83
|
-
validateInput
|
|
84
|
-
validateInputField
|
|
85
|
-
validateOutput
|
|
83
|
+
validateInput,
|
|
84
|
+
validateInputField,
|
|
85
|
+
validateOutput,
|
|
86
86
|
});
|
|
87
87
|
(methodDefinition.static ? ownStaticMethods : ownInstanceMethods).push(method);
|
|
88
88
|
}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import type { Options } from '@astrale-os/kernel-dsl/value';
|
|
2
1
|
import type { Key, PropertyKey } from '../../addressing/index.js';
|
|
3
2
|
import type { Diagnostic } from '../../language/validation/diagnostic.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type { OrderingKind } from '../../language/value/ordering.js';
|
|
6
|
-
import type { DomainValidation } from '../model/input.js';
|
|
7
|
-
export interface PropertyValidation {
|
|
8
|
-
readonly ordering?: OrderingKind;
|
|
9
|
-
validate(input: unknown): readonly Diagnostic[];
|
|
10
|
-
program(): ValueProgram;
|
|
11
|
-
}
|
|
12
|
-
export interface CallableValidation {
|
|
13
|
-
readonly fields?: readonly string[];
|
|
14
|
-
validateInput(input: unknown, options?: Options): readonly Diagnostic[];
|
|
15
|
-
validateInputField(field: string, input: unknown): readonly Diagnostic[];
|
|
16
|
-
validateOutput(output: unknown): readonly Diagnostic[];
|
|
17
|
-
}
|
|
3
|
+
import type { CallableValidation, DomainValidation, PropertyValidation } from '../model/input.js';
|
|
18
4
|
/**
|
|
19
5
|
* Build the one Domain-level router shared by source resolution and compiled loading. The Domain
|
|
20
6
|
* built from the same entries asks only for the Properties and Callables they declare.
|
|
@@ -3,30 +3,27 @@
|
|
|
3
3
|
* built from the same entries asks only for the Properties and Callables they declare.
|
|
4
4
|
*/
|
|
5
5
|
export function createDomainValidation(properties, callables) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new TypeError(`Callable ${key} is absent.`);
|
|
16
|
-
return target;
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
property: (key) => properties.get(key) ?? absentProperty(key),
|
|
8
|
+
callable: (key) => callables.get(key) ?? absentCallable(key),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
// An absent entry fails only when it is asked to validate, never when it is looked up.
|
|
12
|
+
function absentProperty(key) {
|
|
13
|
+
const absent = () => {
|
|
14
|
+
throw new TypeError(`Property ${key} is absent.`);
|
|
17
15
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
callableExists: (key) => callables.has(key),
|
|
24
|
-
callableInput: (key, input, options) => callableOf(key).validateInput(input, options),
|
|
25
|
-
callableFields: (key) => callables.get(key)?.fields,
|
|
26
|
-
callableInputField: (key, field, input) => callableOf(key).validateInputField(field, input),
|
|
27
|
-
callableOutput: (key, output) => callableOf(key).validateOutput(output),
|
|
16
|
+
return Object.freeze({ validate: absent, program: absent });
|
|
17
|
+
}
|
|
18
|
+
function absentCallable(key) {
|
|
19
|
+
const absent = () => {
|
|
20
|
+
throw new TypeError(`Callable ${key} is absent.`);
|
|
28
21
|
};
|
|
29
|
-
return Object.freeze(
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
validateInput: absent,
|
|
24
|
+
validateInputField: absent,
|
|
25
|
+
validateOutput: absent,
|
|
26
|
+
});
|
|
30
27
|
}
|
|
31
28
|
export function unknownInputField(field) {
|
|
32
29
|
return [
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
|
|
3
3
|
* ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
|
|
4
4
|
*
|
|
5
|
-
* The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26
|
|
5
|
+
* The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
|
|
6
6
|
* `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
|
|
7
7
|
* its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
|
|
8
8
|
* Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
|
|
3
3
|
* ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
|
|
4
4
|
*
|
|
5
|
-
* The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26
|
|
5
|
+
* The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
|
|
6
6
|
* `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
|
|
7
7
|
* its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
|
|
8
8
|
* Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
|
|
@@ -572,9 +572,9 @@
|
|
|
572
572
|
},
|
|
573
573
|
"core-slug": {
|
|
574
574
|
"type": "string",
|
|
575
|
+
"pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$",
|
|
575
576
|
"minLength": 1,
|
|
576
|
-
"maxLength": 100
|
|
577
|
-
"pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$"
|
|
577
|
+
"maxLength": 100
|
|
578
578
|
},
|
|
579
579
|
"create-policy": {
|
|
580
580
|
"anyOf": [
|
|
@@ -1522,9 +1522,9 @@
|
|
|
1522
1522
|
},
|
|
1523
1523
|
"origin": {
|
|
1524
1524
|
"type": "string",
|
|
1525
|
+
"pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$",
|
|
1525
1526
|
"minLength": 3,
|
|
1526
|
-
"maxLength": 253
|
|
1527
|
-
"pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"
|
|
1527
|
+
"maxLength": 253
|
|
1528
1528
|
},
|
|
1529
1529
|
"path-annotation": {
|
|
1530
1530
|
"type": "object",
|
|
@@ -2183,6 +2183,7 @@
|
|
|
2183
2183
|
"$ref": "#/$defs/incident-endpoint"
|
|
2184
2184
|
}
|
|
2185
2185
|
],
|
|
2186
|
+
"items": false,
|
|
2186
2187
|
"minItems": 2,
|
|
2187
2188
|
"maxItems": 2
|
|
2188
2189
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassRef } from '../../addressing/index.js';
|
|
2
|
-
import type { CallableValidation } from '../../domain/
|
|
2
|
+
import type { CallableValidation } from '../../domain/model/input.js';
|
|
3
3
|
import type { CallableDefinition } from '../../language/callable/model/callable.js';
|
|
4
4
|
import type { DomainSchema } from '../model/schema.js';
|
|
5
5
|
/** One admitted callable contract and the validators of its exact owner environment. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SourceDomain } from '../../domain/model/domain.js';
|
|
2
|
-
import type { CallableValidation } from '../../domain/
|
|
2
|
+
import type { CallableValidation } from '../../domain/model/input.js';
|
|
3
3
|
import type { JsonSchema } from '../../language/value/model/schema.js';
|
|
4
4
|
import type { ValueSchemaRegistry } from '../../language/value/reference/registry.js';
|
|
5
5
|
import type { DomainSchema } from '../model/schema.js';
|
|
@@ -2,7 +2,7 @@ import { toJSONSchema } from 'zod';
|
|
|
2
2
|
import { VALUE_RULES } from '../../language/validation/rule.js';
|
|
3
3
|
import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
4
4
|
import { RULES } from '../rule.js';
|
|
5
|
-
import { domainSchemaStructure, documentJsonSchema, structureRules, } from './domain.structure.js';
|
|
5
|
+
import { domainSchemaStructure, documentJsonSchema, structureRules, VARIANTS, } from './domain.structure.js';
|
|
6
6
|
import { jsonValueJsonSchema, jsonValueRules, } from './json.json-schema.js';
|
|
7
7
|
import { valueSchemaJsonSchema, valueSchemaRules, } from './value.json-schema.js';
|
|
8
8
|
/** The checks the published document names, each with its stage and the positions it constrains. */
|
|
@@ -37,6 +37,8 @@ export function domainSchemaJsonSchema() {
|
|
|
37
37
|
rendered.maxItems = def.items.length;
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
|
+
stateVariantsByAnyOf(root);
|
|
41
|
+
stateVariantsByAnyOf($defs);
|
|
40
42
|
const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
|
|
41
43
|
if (unnamed.length > 0) {
|
|
42
44
|
throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
|
|
@@ -153,9 +155,32 @@ function isStated(schema, check) {
|
|
|
153
155
|
}
|
|
154
156
|
/** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
|
|
155
157
|
function statementOf(schema) {
|
|
156
|
-
const { id: _id, description: _description, ...statement } = documentJsonSchema._map.get(schema) ?? {};
|
|
158
|
+
const { id: _id, description: _description, [VARIANTS]: _variants, ...statement } = documentJsonSchema._map.get(schema) ?? {};
|
|
157
159
|
return Object.keys(statement).length > 0 ? statement : undefined;
|
|
158
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Zod renders an exclusive union by `oneOf`. The structure's `variants` are exclusive only for their
|
|
163
|
+
* diagnostics: they never overlap, so the document states them by `anyOf`, in place, as any union.
|
|
164
|
+
*/
|
|
165
|
+
function stateVariantsByAnyOf(value) {
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
for (const item of value)
|
|
168
|
+
stateVariantsByAnyOf(item);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (value === null || typeof value !== 'object')
|
|
172
|
+
return;
|
|
173
|
+
const schema = value;
|
|
174
|
+
if (schema[VARIANTS] !== undefined) {
|
|
175
|
+
const entries = Object.entries(schema).filter(([key]) => key !== VARIANTS);
|
|
176
|
+
for (const key of Object.keys(schema))
|
|
177
|
+
delete schema[key];
|
|
178
|
+
for (const [key, entry] of entries)
|
|
179
|
+
schema[key === 'oneOf' ? 'anyOf' : key] = entry;
|
|
180
|
+
}
|
|
181
|
+
for (const entry of Object.values(schema))
|
|
182
|
+
stateVariantsByAnyOf(entry);
|
|
183
|
+
}
|
|
159
184
|
/**
|
|
160
185
|
* Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
|
|
161
186
|
* removed; every `maxLength` counts UTF-16 code units, the length the structure measures.
|
|
@@ -12,8 +12,11 @@ import type { DomainSchemaIR } from '../model/schema.js';
|
|
|
12
12
|
export type JsonSchemaAnnotation = zodCore.JSONSchema.JSONSchema & {
|
|
13
13
|
readonly id?: string;
|
|
14
14
|
readonly 'x-astrale-rule'?: StructureRule;
|
|
15
|
+
readonly [VARIANTS]?: true;
|
|
15
16
|
};
|
|
16
17
|
export declare const documentJsonSchema: zodCore.$ZodRegistry<JsonSchemaAnnotation, zodCore.$ZodType<unknown, unknown, zodCore.$ZodTypeInternals<unknown, unknown>>>;
|
|
18
|
+
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
19
|
+
export declare const VARIANTS = "x-astrale-variants";
|
|
17
20
|
/**
|
|
18
21
|
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
19
22
|
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
@@ -101,7 +104,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
101
104
|
name: import("zod").ZodString;
|
|
102
105
|
}, zodCore.$strict>>;
|
|
103
106
|
properties: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
104
|
-
schema: import("zod").
|
|
107
|
+
schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
105
108
|
required: import("zod").ZodBoolean;
|
|
106
109
|
auto: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
107
110
|
on: ZodType<["create" | "update", ...("create" | "update")[]], ["create" | "update", ...("create" | "update")[]], zodCore.$ZodTypeInternals<["create" | "update", ...("create" | "update")[]], ["create" | "update", ...("create" | "update")[]]>>;
|
|
@@ -119,13 +122,13 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
119
122
|
}, zodCore.$strict>>;
|
|
120
123
|
methods: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
121
124
|
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
122
|
-
input: import("zod").
|
|
125
|
+
input: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
123
126
|
output: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
124
127
|
mode: import("zod").ZodLiteral<"value">;
|
|
125
|
-
schema: import("zod").
|
|
128
|
+
schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
126
129
|
}, zodCore.$strict>, import("zod").ZodObject<{
|
|
127
130
|
mode: import("zod").ZodLiteral<"stream">;
|
|
128
|
-
item: import("zod").
|
|
131
|
+
item: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
129
132
|
}, zodCore.$strict>, import("zod").ZodObject<{
|
|
130
133
|
mode: import("zod").ZodLiteral<"binary">;
|
|
131
134
|
}, zodCore.$strict>], "mode">;
|
|
@@ -140,11 +143,8 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
140
143
|
authenticated: "authenticated";
|
|
141
144
|
authorized: "authorized";
|
|
142
145
|
}>;
|
|
143
|
-
policy: import("zod").ZodOptional<import("zod").
|
|
146
|
+
policy: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
|
|
144
147
|
kind: "self";
|
|
145
|
-
} | {
|
|
146
|
-
kind: "input";
|
|
147
|
-
field: string;
|
|
148
148
|
} | {
|
|
149
149
|
kind: "ref";
|
|
150
150
|
ref: {
|
|
@@ -176,11 +176,11 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
176
176
|
kind: "view";
|
|
177
177
|
name: string;
|
|
178
178
|
};
|
|
179
|
-
}>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
|
|
180
|
-
kind: "self";
|
|
181
179
|
} | {
|
|
182
180
|
kind: "input";
|
|
183
181
|
field: string;
|
|
182
|
+
}>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
|
|
183
|
+
kind: "self";
|
|
184
184
|
} | {
|
|
185
185
|
kind: "ref";
|
|
186
186
|
ref: {
|
|
@@ -212,6 +212,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
212
212
|
kind: "view";
|
|
213
213
|
name: string;
|
|
214
214
|
};
|
|
215
|
+
} | {
|
|
216
|
+
kind: "input";
|
|
217
|
+
field: string;
|
|
215
218
|
}>, unknown>>]>>;
|
|
216
219
|
static: import("zod").ZodBoolean;
|
|
217
220
|
abstract: import("zod").ZodBoolean;
|
|
@@ -236,9 +239,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
236
239
|
auth: "anonymous" | "authenticated" | "authorized";
|
|
237
240
|
policy?: true | PolicyCheckExpression<PolicyRef, {
|
|
238
241
|
kind: "self";
|
|
239
|
-
} | {
|
|
240
|
-
kind: "input";
|
|
241
|
-
field: string;
|
|
242
242
|
} | {
|
|
243
243
|
kind: "ref";
|
|
244
244
|
ref: {
|
|
@@ -270,6 +270,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
270
270
|
kind: "view";
|
|
271
271
|
name: string;
|
|
272
272
|
};
|
|
273
|
+
} | {
|
|
274
|
+
kind: "input";
|
|
275
|
+
field: string;
|
|
273
276
|
}> | undefined;
|
|
274
277
|
static: boolean;
|
|
275
278
|
abstract: boolean;
|
|
@@ -316,9 +319,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
316
319
|
auth: "anonymous" | "authenticated" | "authorized";
|
|
317
320
|
policy?: true | PolicyCheckExpression<PolicyRef, {
|
|
318
321
|
kind: "self";
|
|
319
|
-
} | {
|
|
320
|
-
kind: "input";
|
|
321
|
-
field: string;
|
|
322
322
|
} | {
|
|
323
323
|
kind: "ref";
|
|
324
324
|
ref: {
|
|
@@ -350,6 +350,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
350
350
|
kind: "view";
|
|
351
351
|
name: string;
|
|
352
352
|
};
|
|
353
|
+
} | {
|
|
354
|
+
kind: "input";
|
|
355
|
+
field: string;
|
|
353
356
|
}> | undefined;
|
|
354
357
|
static: boolean;
|
|
355
358
|
abstract: boolean;
|
|
@@ -381,7 +384,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
381
384
|
}, zodCore.$strict>>;
|
|
382
385
|
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
383
386
|
policies: import("zod").ZodObject<{
|
|
384
|
-
read: import("zod").ZodOptional<import("zod").
|
|
387
|
+
read: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
|
|
385
388
|
origin: import("zod").ZodString;
|
|
386
389
|
kind: import("zod").ZodLiteral<"policy">;
|
|
387
390
|
name: import("zod").ZodString;
|
|
@@ -452,7 +455,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
452
455
|
name: string;
|
|
453
456
|
};
|
|
454
457
|
}>, unknown>>]>>;
|
|
455
|
-
traverse: import("zod").ZodOptional<import("zod").
|
|
458
|
+
traverse: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
|
|
456
459
|
origin: import("zod").ZodString;
|
|
457
460
|
kind: import("zod").ZodLiteral<"policy">;
|
|
458
461
|
name: import("zod").ZodString;
|
|
@@ -523,7 +526,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
523
526
|
name: string;
|
|
524
527
|
};
|
|
525
528
|
}>, unknown>>]>>;
|
|
526
|
-
create: import("zod").ZodOptional<import("zod").
|
|
529
|
+
create: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
|
|
527
530
|
kind: "ref";
|
|
528
531
|
ref: {
|
|
529
532
|
origin: string;
|
|
@@ -586,7 +589,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
586
589
|
name: string;
|
|
587
590
|
};
|
|
588
591
|
}>, unknown>>]>>;
|
|
589
|
-
update: import("zod").ZodOptional<import("zod").
|
|
592
|
+
update: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
|
|
590
593
|
origin: import("zod").ZodString;
|
|
591
594
|
kind: import("zod").ZodLiteral<"policy">;
|
|
592
595
|
name: import("zod").ZodString;
|
|
@@ -657,7 +660,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
657
660
|
name: string;
|
|
658
661
|
};
|
|
659
662
|
}>, unknown>>]>>;
|
|
660
|
-
delete: import("zod").ZodOptional<import("zod").
|
|
663
|
+
delete: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
|
|
661
664
|
origin: import("zod").ZodString;
|
|
662
665
|
kind: import("zod").ZodLiteral<"policy">;
|
|
663
666
|
name: import("zod").ZodString;
|
|
@@ -759,7 +762,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
759
762
|
once: "once";
|
|
760
763
|
}>>;
|
|
761
764
|
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
762
|
-
schema: import("zod").
|
|
765
|
+
schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
763
766
|
}, zodCore.$strict>>;
|
|
764
767
|
constraints: import("zod").ZodObject<{
|
|
765
768
|
noSelf: import("zod").ZodOptional<import("zod").ZodLiteral<true>>;
|
|
@@ -802,7 +805,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
802
805
|
directed: "directed";
|
|
803
806
|
undirected: "undirected";
|
|
804
807
|
}>;
|
|
805
|
-
endpoints: import("zod").
|
|
808
|
+
endpoints: import("zod").ZodXor<readonly [import("zod").ZodObject<{
|
|
806
809
|
source: import("zod").ZodObject<{
|
|
807
810
|
role: import("zod").ZodString;
|
|
808
811
|
accepts: ZodType<[{
|
|
@@ -987,7 +990,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
987
990
|
}>;
|
|
988
991
|
}, zodCore.$strict>], null>]>;
|
|
989
992
|
policies: import("zod").ZodObject<{
|
|
990
|
-
read: import("zod").ZodOptional<import("zod").
|
|
993
|
+
read: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
|
|
991
994
|
origin: import("zod").ZodString;
|
|
992
995
|
kind: import("zod").ZodLiteral<"policy">;
|
|
993
996
|
name: import("zod").ZodString;
|
|
@@ -1058,7 +1061,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
1058
1061
|
name: string;
|
|
1059
1062
|
};
|
|
1060
1063
|
}>, unknown>>]>>;
|
|
1061
|
-
traverse: import("zod").ZodOptional<import("zod").
|
|
1064
|
+
traverse: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
|
|
1062
1065
|
origin: import("zod").ZodString;
|
|
1063
1066
|
kind: import("zod").ZodLiteral<"policy">;
|
|
1064
1067
|
name: import("zod").ZodString;
|
|
@@ -1129,7 +1132,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
1129
1132
|
name: string;
|
|
1130
1133
|
};
|
|
1131
1134
|
}>, unknown>>]>>;
|
|
1132
|
-
create: import("zod").ZodOptional<import("zod").
|
|
1135
|
+
create: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
|
|
1133
1136
|
origin: import("zod").ZodString;
|
|
1134
1137
|
kind: import("zod").ZodLiteral<"policy">;
|
|
1135
1138
|
name: import("zod").ZodString;
|
|
@@ -1200,7 +1203,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
1200
1203
|
name: string;
|
|
1201
1204
|
};
|
|
1202
1205
|
}>, unknown>>]>>;
|
|
1203
|
-
update: import("zod").ZodOptional<import("zod").
|
|
1206
|
+
update: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
|
|
1204
1207
|
origin: import("zod").ZodString;
|
|
1205
1208
|
kind: import("zod").ZodLiteral<"policy">;
|
|
1206
1209
|
name: import("zod").ZodString;
|
|
@@ -1271,7 +1274,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
1271
1274
|
name: string;
|
|
1272
1275
|
};
|
|
1273
1276
|
}>, unknown>>]>>;
|
|
1274
|
-
delete: import("zod").ZodOptional<import("zod").
|
|
1277
|
+
delete: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
|
|
1275
1278
|
origin: import("zod").ZodString;
|
|
1276
1279
|
kind: import("zod").ZodLiteral<"policy">;
|
|
1277
1280
|
name: import("zod").ZodString;
|
|
@@ -7310,10 +7313,10 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7310
7313
|
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
7311
7314
|
output: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
7312
7315
|
mode: import("zod").ZodLiteral<"value">;
|
|
7313
|
-
schema: import("zod").
|
|
7316
|
+
schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
7314
7317
|
}, zodCore.$strict>, import("zod").ZodObject<{
|
|
7315
7318
|
mode: import("zod").ZodLiteral<"stream">;
|
|
7316
|
-
item: import("zod").
|
|
7319
|
+
item: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
7317
7320
|
}, zodCore.$strict>, import("zod").ZodObject<{
|
|
7318
7321
|
mode: import("zod").ZodLiteral<"binary">;
|
|
7319
7322
|
}, zodCore.$strict>], "mode">;
|
|
@@ -7328,11 +7331,8 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7328
7331
|
authenticated: "authenticated";
|
|
7329
7332
|
authorized: "authorized";
|
|
7330
7333
|
}>;
|
|
7331
|
-
policy: import("zod").ZodOptional<import("zod").
|
|
7334
|
+
policy: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
|
|
7332
7335
|
kind: "self";
|
|
7333
|
-
} | {
|
|
7334
|
-
kind: "input";
|
|
7335
|
-
field: string;
|
|
7336
7336
|
} | {
|
|
7337
7337
|
kind: "ref";
|
|
7338
7338
|
ref: {
|
|
@@ -7364,11 +7364,11 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7364
7364
|
kind: "view";
|
|
7365
7365
|
name: string;
|
|
7366
7366
|
};
|
|
7367
|
-
}>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
|
|
7368
|
-
kind: "self";
|
|
7369
7367
|
} | {
|
|
7370
7368
|
kind: "input";
|
|
7371
7369
|
field: string;
|
|
7370
|
+
}>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
|
|
7371
|
+
kind: "self";
|
|
7372
7372
|
} | {
|
|
7373
7373
|
kind: "ref";
|
|
7374
7374
|
ref: {
|
|
@@ -7400,12 +7400,15 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7400
7400
|
kind: "view";
|
|
7401
7401
|
name: string;
|
|
7402
7402
|
};
|
|
7403
|
+
} | {
|
|
7404
|
+
kind: "input";
|
|
7405
|
+
field: string;
|
|
7403
7406
|
}>, unknown>>]>>;
|
|
7404
|
-
input: import("zod").
|
|
7407
|
+
input: import("zod").ZodXor<readonly [import("zod").ZodObject<{
|
|
7405
7408
|
mode: import("zod").ZodLiteral<"binary">;
|
|
7406
|
-
metadata: import("zod").
|
|
7409
|
+
metadata: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
|
|
7407
7410
|
maximumBytes: import("zod").ZodNumber;
|
|
7408
|
-
}, zodCore.$strict>, import("zod").
|
|
7411
|
+
}, zodCore.$strict>, import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>]>;
|
|
7409
7412
|
ref: import("zod").ZodObject<{
|
|
7410
7413
|
origin: import("zod").ZodString;
|
|
7411
7414
|
kind: import("zod").ZodLiteral<"function">;
|
|
@@ -7431,9 +7434,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7431
7434
|
auth: "anonymous" | "authenticated" | "authorized";
|
|
7432
7435
|
policy?: true | PolicyCheckExpression<PolicyRef, {
|
|
7433
7436
|
kind: "self";
|
|
7434
|
-
} | {
|
|
7435
|
-
kind: "input";
|
|
7436
|
-
field: string;
|
|
7437
7437
|
} | {
|
|
7438
7438
|
kind: "ref";
|
|
7439
7439
|
ref: {
|
|
@@ -7465,6 +7465,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7465
7465
|
kind: "view";
|
|
7466
7466
|
name: string;
|
|
7467
7467
|
};
|
|
7468
|
+
} | {
|
|
7469
|
+
kind: "input";
|
|
7470
|
+
field: string;
|
|
7468
7471
|
}> | undefined;
|
|
7469
7472
|
input: boolean | Record<string, JsonValue> | {
|
|
7470
7473
|
mode: "binary";
|
|
@@ -7525,9 +7528,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7525
7528
|
auth: "anonymous" | "authenticated" | "authorized";
|
|
7526
7529
|
policy?: true | PolicyCheckExpression<PolicyRef, {
|
|
7527
7530
|
kind: "self";
|
|
7528
|
-
} | {
|
|
7529
|
-
kind: "input";
|
|
7530
|
-
field: string;
|
|
7531
7531
|
} | {
|
|
7532
7532
|
kind: "ref";
|
|
7533
7533
|
ref: {
|
|
@@ -7559,6 +7559,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7559
7559
|
kind: "view";
|
|
7560
7560
|
name: string;
|
|
7561
7561
|
};
|
|
7562
|
+
} | {
|
|
7563
|
+
kind: "input";
|
|
7564
|
+
field: string;
|
|
7562
7565
|
}> | undefined;
|
|
7563
7566
|
input: boolean | Record<string, JsonValue> | {
|
|
7564
7567
|
mode: "binary";
|
|
@@ -7606,7 +7609,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7606
7609
|
kind: import("zod").ZodLiteral<"policy">;
|
|
7607
7610
|
name: import("zod").ZodString;
|
|
7608
7611
|
}, zodCore.$strict>;
|
|
7609
|
-
expression: import("zod").
|
|
7612
|
+
expression: import("zod").ZodXor<readonly [import("zod").ZodObject<{
|
|
7610
7613
|
match: ZodType<PolicyPatternExpression, unknown, zodCore.$ZodTypeInternals<PolicyPatternExpression, unknown>>;
|
|
7611
7614
|
}, zodCore.$strict>, import("zod").ZodObject<{
|
|
7612
7615
|
allOf: ZodType<[{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple,
|
|
1
|
+
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple, xor, } from 'zod';
|
|
2
2
|
import { PropertyKey as SemanticPropertyKey } from '../../addressing/index.js';
|
|
3
3
|
import { CORE_SLUG_PATTERN, DEPENDENCY_ALIAS_PATTERN, DOMAIN_ORIGIN_PATTERN, DOMAIN_REVISION_PATTERN, MEMBER_NAME_PATTERN, PROPERTY_KEY_PATTERN, } from '../../addressing/patterns.js';
|
|
4
4
|
import { MEDIA_TYPE_PATTERN } from '../../language/class/model/data.js';
|
|
@@ -9,6 +9,18 @@ import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
|
9
9
|
import { SchemaError, diagnostic, } from '../diagnostic.js';
|
|
10
10
|
import { DOMAIN_FORMAT, DOMAIN_VERSION } from '../model/format.js';
|
|
11
11
|
export const documentJsonSchema = registry();
|
|
12
|
+
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
13
|
+
export const VARIANTS = 'x-astrale-variants';
|
|
14
|
+
/**
|
|
15
|
+
* A union of disjoint variants. It is exclusive (`xor`) so that zod reports the issues of every
|
|
16
|
+
* variant, from which `matchedVariant` decides what a refused value reports. Its variants never
|
|
17
|
+
* overlap, so JSON Schema states it as any union, by `anyOf`.
|
|
18
|
+
*/
|
|
19
|
+
function variants(options, annotation = {}) {
|
|
20
|
+
const union = xor(options);
|
|
21
|
+
documentJsonSchema.add(union, { ...annotation, [VARIANTS]: true });
|
|
22
|
+
return union;
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
14
26
|
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
@@ -25,9 +37,7 @@ export const structureRules = {
|
|
|
25
37
|
};
|
|
26
38
|
// The pattern refuses `__proto__`, which zod skips before any key check (`lostProtoKeys`).
|
|
27
39
|
const RESERVED_DEPENDENCY_ALIASES = ['prototype', 'constructor'];
|
|
28
|
-
const originSchema =
|
|
29
|
-
.min(3)
|
|
30
|
-
.max(253)
|
|
40
|
+
const originSchema = boundedString(3, 253)
|
|
31
41
|
.regex(DOMAIN_ORIGIN_PATTERN)
|
|
32
42
|
.register(documentJsonSchema, { id: 'origin' });
|
|
33
43
|
const memberNameSchema = string()
|
|
@@ -49,25 +59,15 @@ const propertyKeySchema = string()
|
|
|
49
59
|
params: { structureCode: 'STRUCTURE_PROPERTY_KEY' },
|
|
50
60
|
})
|
|
51
61
|
.register(documentJsonSchema, { id: 'property-key', pattern: PROPERTY_KEY_PATTERN.source });
|
|
52
|
-
const coreSlugSchema =
|
|
53
|
-
.min(1)
|
|
54
|
-
.max(100)
|
|
62
|
+
const coreSlugSchema = boundedString(1, 100)
|
|
55
63
|
.regex(CORE_SLUG_PATTERN)
|
|
56
64
|
.register(documentJsonSchema, { id: 'core-slug' });
|
|
57
65
|
const revisionSchema = string()
|
|
58
66
|
.regex(DOMAIN_REVISION_PATTERN)
|
|
59
67
|
.register(documentJsonSchema, { id: 'revision' });
|
|
60
|
-
const descriptionSchema =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.register(documentJsonSchema, { id: 'description' });
|
|
64
|
-
const iconSchema = string()
|
|
65
|
-
.min(metadata.icon.minLength)
|
|
66
|
-
.max(metadata.icon.maxLength)
|
|
67
|
-
.register(documentJsonSchema, { id: 'icon' });
|
|
68
|
-
const domainNameSchema = string()
|
|
69
|
-
.min(metadata.name.minLength)
|
|
70
|
-
.max(metadata.name.maxLength)
|
|
68
|
+
const descriptionSchema = boundedString(metadata.description.minLength, metadata.description.maxLength, 'description');
|
|
69
|
+
const iconSchema = boundedString(metadata.icon.minLength, metadata.icon.maxLength, 'icon');
|
|
70
|
+
const domainNameSchema = boundedString(metadata.name.minLength, metadata.name.maxLength)
|
|
71
71
|
.refine(metadata.isDomainNameText, {
|
|
72
72
|
message: 'Expected one trimmed line of text.',
|
|
73
73
|
params: { structureCode: 'STRUCTURE_DOMAIN_NAME' },
|
|
@@ -77,12 +77,14 @@ const domainNameSchema = string()
|
|
|
77
77
|
description: 'The display name of the Domain: one trimmed line of text.',
|
|
78
78
|
pattern: metadata.DOMAIN_NAME_TEXT_PATTERN.source,
|
|
79
79
|
});
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// of
|
|
80
|
+
// The parsed document cannot keep a `__proto__` member, which the structure therefore refuses: a
|
|
81
|
+
// closed object reports it as an unknown key, and a record, which skips it, by `lostProtoKeys`. The
|
|
82
|
+
// JSON Schema refuses it by the fields of a closed object and the pattern of a record's names; a
|
|
83
|
+
// record of any string states it here, by its property names.
|
|
83
84
|
const PROTO_KEY = '__proto__';
|
|
85
|
+
const PROTO_KEY_MESSAGE = 'A member named __proto__ is refused: the parsed document cannot keep it.';
|
|
84
86
|
const anyKeyRecord = { propertyNames: { not: { const: PROTO_KEY } } };
|
|
85
|
-
const jsonValueSchema = lazy(() =>
|
|
87
|
+
const jsonValueSchema = lazy(() => variants([
|
|
86
88
|
nullSchema(),
|
|
87
89
|
boolean(),
|
|
88
90
|
number(),
|
|
@@ -91,14 +93,14 @@ const jsonValueSchema = lazy(() => union([
|
|
|
91
93
|
record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord),
|
|
92
94
|
])).register(documentJsonSchema, { id: 'json-value' });
|
|
93
95
|
const jsonObjectSchema = record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord);
|
|
94
|
-
const jsonSchemaSchema =
|
|
96
|
+
const jsonSchemaSchema = variants([boolean(), jsonObjectSchema], {
|
|
95
97
|
id: 'value-schema',
|
|
96
98
|
description: 'A value schema of the dialect https://schemas.astrale.ai/dsl/v1/value-schema. The structure admits any boolean or object; the language admits its keywords.',
|
|
97
99
|
});
|
|
98
100
|
const dataDeclarationSchema = strictObject({
|
|
99
101
|
mediaType: string().regex(MEDIA_TYPE_PATTERN).register(documentJsonSchema, { id: 'media-type' }),
|
|
100
102
|
});
|
|
101
|
-
const stateNameSchema =
|
|
103
|
+
const stateNameSchema = boundedString(1);
|
|
102
104
|
// A custom check reads the relation in place: a record would copy it and drop a `__proto__` state.
|
|
103
105
|
const stateTransitionsSchema = custom(isStateTransitions, {
|
|
104
106
|
message: 'Expected each non-empty state to map non-empty events to non-empty states.',
|
|
@@ -210,12 +212,12 @@ const edgeConstraintsSchema = strictObject({
|
|
|
210
212
|
// A tuple names distinct fields: endpoints, the slug and Properties by key. Normalization puts
|
|
211
213
|
// them, and the tuples, in canonical order (`compareEdgeUniqueFields`). No tuple is spelled by the
|
|
212
214
|
// absence of the field, never by an empty list: one spelling per meaning, one revision.
|
|
213
|
-
const edgeUniqueFieldSchema =
|
|
215
|
+
const edgeUniqueFieldSchema = variants([
|
|
214
216
|
literal('source'),
|
|
215
217
|
literal('target'),
|
|
216
218
|
literal('slug'),
|
|
217
219
|
strictObject({ property: propertyKeySchema }),
|
|
218
|
-
]
|
|
220
|
+
], { id: 'edge-unique-field' });
|
|
219
221
|
const edgeUniqueSchema = nonEmpty(uniqueTupleSet(nonEmpty(uniqueArray(edgeUniqueFieldSchema))));
|
|
220
222
|
// A Node tuple names distinct Properties by key, which normalization puts in code-point order, as
|
|
221
223
|
// it does the tuples (`compareNodeUniqueTuples`). Two orders of one set of keys are one tuple.
|
|
@@ -240,15 +242,15 @@ const policyVariableSelectorSchema = discriminatedUnion('kind', [
|
|
|
240
242
|
strictObject({ kind: literal('any') }),
|
|
241
243
|
strictObject({ kind: literal('satisfies'), class: classRefSchema }),
|
|
242
244
|
]).register(documentJsonSchema, { id: 'policy-variable-selector' });
|
|
243
|
-
const policyVariableSchema =
|
|
245
|
+
const policyVariableSchema = variants([
|
|
244
246
|
strictObject({ variable: policyPatternVariableSchema, class: classRefSchema }),
|
|
245
247
|
strictObject({ variable: policyPatternVariableSchema, selector: policyVariableSelectorSchema }),
|
|
246
|
-
]
|
|
248
|
+
], { id: 'policy-variable' });
|
|
247
249
|
const policyRepeatSchema = strictObject({
|
|
248
250
|
min: number().int().min(0).max(limits.policy.repetition),
|
|
249
251
|
max: number().int().min(0).max(limits.policy.repetition),
|
|
250
252
|
}).register(documentJsonSchema, { id: 'policy-repeat' });
|
|
251
|
-
const policyPatternExpressionSchema = lazy(() =>
|
|
253
|
+
const policyPatternExpressionSchema = lazy(() => variants([
|
|
252
254
|
strictObject({
|
|
253
255
|
sameNode: strictObject({ left: policyPatternNodeSchema, right: policyPatternNodeSchema }),
|
|
254
256
|
}),
|
|
@@ -284,7 +286,7 @@ const classRuleObjectSchema = discriminatedUnion('kind', [
|
|
|
284
286
|
]).register(documentJsonSchema, { id: 'class-rule-object' });
|
|
285
287
|
/** The recursive Policy check grammar, over the objects one use site admits. */
|
|
286
288
|
function policyChecksSchema(objectSchema, id) {
|
|
287
|
-
const checks = lazy(() =>
|
|
289
|
+
const checks = lazy(() => variants([
|
|
288
290
|
strictObject({ sameNode: strictObject({ left: objectSchema, right: objectSchema }) }),
|
|
289
291
|
strictObject({ check: policyRefSchema, object: objectSchema }),
|
|
290
292
|
strictObject({ allOf: nonEmpty(array(checks)) }),
|
|
@@ -336,9 +338,9 @@ const callableShape = {
|
|
|
336
338
|
execution: callableExecutionSchema.optional(),
|
|
337
339
|
admission: callableAdmissionSchema.optional(),
|
|
338
340
|
auth: enumeration(['anonymous', 'authenticated', 'authorized']),
|
|
339
|
-
policy:
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
policy: variants([literal(true), policyCheckExpressionSchema], {
|
|
342
|
+
id: 'callable-policy',
|
|
343
|
+
}).optional(),
|
|
342
344
|
};
|
|
343
345
|
const authorizedPolicy = {
|
|
344
346
|
if: { properties: { auth: { enum: ['anonymous', 'authenticated'] } }, required: ['auth'] },
|
|
@@ -356,13 +358,15 @@ const methodRecordSchema = record(memberNameSchema, methodDeclarationSchema).reg
|
|
|
356
358
|
id: 'method-record',
|
|
357
359
|
});
|
|
358
360
|
// Each slot spells one constant: the other one is what its absence already means.
|
|
359
|
-
const observationPolicySchema =
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const createPolicySchema =
|
|
361
|
+
const observationPolicySchema = variants([literal(false), policyRefSchema, classRuleChecksSchema], {
|
|
362
|
+
id: 'observation-policy',
|
|
363
|
+
});
|
|
364
|
+
const writePolicySchema = variants([literal(true), policyRefSchema, classRuleChecksSchema], {
|
|
365
|
+
id: 'write-policy',
|
|
366
|
+
});
|
|
367
|
+
const createPolicySchema = variants([literal(true), createRuleChecksSchema], {
|
|
368
|
+
id: 'create-policy',
|
|
369
|
+
});
|
|
366
370
|
const nodeClassPoliciesSchema = strictObject({
|
|
367
371
|
read: observationPolicySchema.optional(),
|
|
368
372
|
traverse: observationPolicySchema.optional(),
|
|
@@ -405,7 +409,7 @@ const edgeClassSchema = strictObject({
|
|
|
405
409
|
constraints: edgeConstraintsSchema,
|
|
406
410
|
unique: edgeUniqueSchema.optional(),
|
|
407
411
|
orientation: enumeration(['directed', 'undirected']),
|
|
408
|
-
endpoints:
|
|
412
|
+
endpoints: variants([directedEdgeEndpointsSchema, undirectedEdgeEndpointsSchema]),
|
|
409
413
|
policies: edgeClassPoliciesSchema,
|
|
410
414
|
})
|
|
411
415
|
.refine((edge) => (edge.orientation === 'undirected') === Array.isArray(edge.endpoints), {
|
|
@@ -442,7 +446,7 @@ const classDeclarationSchema = discriminatedUnion('kind', [
|
|
|
442
446
|
]).register(documentJsonSchema, { id: 'class-definition' });
|
|
443
447
|
const functionContractShape = {
|
|
444
448
|
...callableShape,
|
|
445
|
-
input:
|
|
449
|
+
input: variants([binaryInputSchema, valueFunctionInputSchema]),
|
|
446
450
|
};
|
|
447
451
|
const functionDefinitionSchema = strictObject({
|
|
448
452
|
ref: functionRefSchema,
|
|
@@ -452,7 +456,7 @@ const functionDefinitionSchema = strictObject({
|
|
|
452
456
|
.register(documentJsonSchema, { id: 'function-definition', ...authorizedPolicy });
|
|
453
457
|
// A callable contract has the structure of a Function declaration without its ref, wherever it is.
|
|
454
458
|
const callableContractSchema = strictObject(functionContractShape).refine((callable) => callable.auth === 'authorized' || callable.policy === undefined, callablePolicyIssue('function'));
|
|
455
|
-
const policyExpressionSchema =
|
|
459
|
+
const policyExpressionSchema = variants([
|
|
456
460
|
strictObject({
|
|
457
461
|
match: policyPatternExpressionSchema,
|
|
458
462
|
}),
|
|
@@ -516,17 +520,16 @@ export function parseDomainSchemaStructure(input) {
|
|
|
516
520
|
return modelOf(result.data);
|
|
517
521
|
}
|
|
518
522
|
/**
|
|
519
|
-
* Each `__proto__` member of the input that the parsed document lost. Zod skips that member in
|
|
520
|
-
*
|
|
521
|
-
*
|
|
523
|
+
* Each `__proto__` member of the input that the parsed document lost. Zod skips that member in a
|
|
524
|
+
* record, so the structure would accept the document without it; it refuses the document instead.
|
|
525
|
+
* A closed object reports the member itself, as an unknown key. A State's transitions are read in
|
|
526
|
+
* place and keep the member.
|
|
522
527
|
*/
|
|
523
528
|
function lostProtoKeys(input, parsed, path) {
|
|
524
529
|
if (!isObject(input) || !isObject(parsed))
|
|
525
530
|
return [];
|
|
526
531
|
const lost = Object.hasOwn(input, PROTO_KEY) && !Object.hasOwn(parsed, PROTO_KEY)
|
|
527
|
-
? [
|
|
528
|
-
diagnostic('STRUCTURE_PROTO_KEY', pointer([...path, PROTO_KEY]), 'A member named __proto__ is refused: the parsed document cannot keep it.'),
|
|
529
|
-
]
|
|
532
|
+
? [diagnostic('STRUCTURE_PROTO_KEY', pointer([...path, PROTO_KEY]), PROTO_KEY_MESSAGE)]
|
|
530
533
|
: [];
|
|
531
534
|
return [
|
|
532
535
|
...lost,
|
|
@@ -592,6 +595,44 @@ function isRecord(input) {
|
|
|
592
595
|
function isObject(input) {
|
|
593
596
|
return input !== null && typeof input === 'object';
|
|
594
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* A string of `minimum` to `maximum` UTF-16 code units, the length the language measures, stated in
|
|
600
|
+
* JSON Schema as `minLength` and `maxLength` under the rule `length-in-utf16-code-units`. Zod's own
|
|
601
|
+
* string bounds count code points, which would admit twice the code units of the bound.
|
|
602
|
+
*/
|
|
603
|
+
function boundedString(minimum, maximum, id) {
|
|
604
|
+
return string()
|
|
605
|
+
.check((payload) => {
|
|
606
|
+
const length = payload.value.length;
|
|
607
|
+
if (length < minimum) {
|
|
608
|
+
payload.issues.push({
|
|
609
|
+
code: 'too_small',
|
|
610
|
+
origin: 'string',
|
|
611
|
+
minimum,
|
|
612
|
+
inclusive: true,
|
|
613
|
+
input: payload.value,
|
|
614
|
+
continue: true,
|
|
615
|
+
message: `Expected at least ${minimum} UTF-16 code units.`,
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
else if (maximum !== undefined && length > maximum) {
|
|
619
|
+
payload.issues.push({
|
|
620
|
+
code: 'too_big',
|
|
621
|
+
origin: 'string',
|
|
622
|
+
maximum,
|
|
623
|
+
inclusive: true,
|
|
624
|
+
input: payload.value,
|
|
625
|
+
continue: true,
|
|
626
|
+
message: `Expected at most ${maximum} UTF-16 code units.`,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
.register(documentJsonSchema, {
|
|
631
|
+
...(id === undefined ? {} : { id }),
|
|
632
|
+
minLength: minimum,
|
|
633
|
+
...(maximum === undefined ? {} : { maxLength: maximum }),
|
|
634
|
+
});
|
|
635
|
+
}
|
|
595
636
|
/** At least one item, which `min(1)` proves: the output is typed as the non-empty tuple it is. */
|
|
596
637
|
function nonEmpty(list) {
|
|
597
638
|
return list.min(1);
|
|
@@ -638,7 +679,14 @@ function canonicalJson(value) {
|
|
|
638
679
|
}
|
|
639
680
|
function diagnosticsForIssue(issue, input) {
|
|
640
681
|
if (issue.code === 'unrecognized_keys') {
|
|
641
|
-
return issue.keys.map((key) =>
|
|
682
|
+
return issue.keys.map((key) => key === PROTO_KEY
|
|
683
|
+
? diagnostic('STRUCTURE_PROTO_KEY', pointer([...issue.path, key]), PROTO_KEY_MESSAGE)
|
|
684
|
+
: diagnostic('STRUCTURE_UNKNOWN_FIELD', pointer([...issue.path, key]), `Unknown field ${JSON.stringify(key)}.`));
|
|
685
|
+
}
|
|
686
|
+
if (issue.code === 'invalid_union') {
|
|
687
|
+
const matched = matchedVariant(issue);
|
|
688
|
+
if (matched !== undefined)
|
|
689
|
+
return matched.flatMap((inner) => diagnosticsForIssue(inner, input));
|
|
642
690
|
}
|
|
643
691
|
// A record key refused by a refinement reports that refinement, at the key.
|
|
644
692
|
const refinement = issue.code === 'invalid_key' ? issue.issues.find(isRefinement) : undefined;
|
|
@@ -649,6 +697,48 @@ function diagnosticsForIssue(issue, input) {
|
|
|
649
697
|
diagnostic(structureCode(issue, input), pointer(issue.path), structureMessage(issue, input)),
|
|
650
698
|
];
|
|
651
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* The issues of the one variant a refused union value has the shape of, or none: a union reports
|
|
702
|
+
* `STRUCTURE_UNION` unless exactly one variant refuses the value only by checks (bounds, formats,
|
|
703
|
+
* refinements, or a `__proto__` member). A refused union in a variant counts as checks when it
|
|
704
|
+
* resolves to one variant itself. The structure's unions are exclusive (`xor`), so zod reports each
|
|
705
|
+
* variant's issues and this rule, not zod's choice among them, decides what is reported.
|
|
706
|
+
*/
|
|
707
|
+
function matchedVariant(issue) {
|
|
708
|
+
const candidates = issue.errors.flatMap((variant) => {
|
|
709
|
+
const checks = checksOnly(variant);
|
|
710
|
+
return checks === undefined ? [] : [checks];
|
|
711
|
+
});
|
|
712
|
+
const [only] = candidates;
|
|
713
|
+
if (candidates.length !== 1 || only === undefined)
|
|
714
|
+
return undefined;
|
|
715
|
+
return only.map((inner) => ({ ...inner, path: [...issue.path, ...inner.path] }));
|
|
716
|
+
}
|
|
717
|
+
function checksOnly(issues) {
|
|
718
|
+
const checks = [];
|
|
719
|
+
for (const issue of issues) {
|
|
720
|
+
if (issue.code === 'invalid_union') {
|
|
721
|
+
const matched = matchedVariant(issue);
|
|
722
|
+
if (matched === undefined)
|
|
723
|
+
return undefined;
|
|
724
|
+
checks.push(...matched);
|
|
725
|
+
}
|
|
726
|
+
else if (CHECK_CODES.has(issue.code) ||
|
|
727
|
+
(issue.code === 'unrecognized_keys' && issue.keys.every((key) => key === PROTO_KEY))) {
|
|
728
|
+
checks.push(issue);
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return checks;
|
|
735
|
+
}
|
|
736
|
+
const CHECK_CODES = new Set([
|
|
737
|
+
'custom',
|
|
738
|
+
'invalid_format',
|
|
739
|
+
'too_big',
|
|
740
|
+
'too_small',
|
|
741
|
+
]);
|
|
652
742
|
function isRefinement(issue) {
|
|
653
743
|
return issue.code === 'custom';
|
|
654
744
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-dsl",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.22",
|
|
4
4
|
"description": "Astrale Kernel DSL - Schema authoring, inference, and IR serialization",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -102,13 +102,13 @@
|
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"@noble/hashes": "2.3.0",
|
|
104
104
|
"jsonc-parser": "3.3.1",
|
|
105
|
-
"zod": "4.
|
|
105
|
+
"zod": "4.6.7"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
109
109
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
110
110
|
"ajv": "^8.20.0",
|
|
111
|
-
"re2js": "2.8.
|
|
111
|
+
"re2js": "2.8.7",
|
|
112
112
|
"typescript": "~6.0.3",
|
|
113
113
|
"vitest": "^5.0.1",
|
|
114
114
|
"yaml": "2.9.0"
|