@astrale-os/kernel-dsl 1.0.0-beta.31 → 1.0.0-beta.33
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/callable/authoring.d.ts +2 -2
- package/dist/v1/builder/class/authoring.js +0 -1
- package/dist/v1/builder/class/input.d.ts +3 -5
- package/dist/v1/builder/index.d.ts +1 -1
- package/dist/v1/builder/lowering/class.js +0 -5
- package/dist/v1/builder/lowering/policy.js +24 -6
- package/dist/v1/builder/lowering/value/zod.js +0 -25
- package/dist/v1/builder/policy/authoring.d.ts +33 -7
- package/dist/v1/builder/policy/authoring.js +5 -2
- package/dist/v1/builder/policy/legacy/inputs.d.ts +8 -0
- package/dist/v1/builder/policy/legacy/inputs.js +1 -0
- package/dist/v1/compiled/admission/semantics/class.js +0 -15
- package/dist/v1/compiled/admission/semantics/context.d.ts +1 -2
- package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -2
- package/dist/v1/compiled/admission/semantics/policy/parity.js +26 -3
- package/dist/v1/compiled/admission/semantics/policy/typing.js +2 -0
- package/dist/v1/compiled/admission/wire/class.js +1 -10
- package/dist/v1/compiled/admission/wire/entry.js +5 -2
- package/dist/v1/compiled/admission/wire/policy.js +21 -1
- package/dist/v1/compiled/rule.js +0 -1
- package/dist/v1/domain/projection/classes.js +0 -8
- package/dist/v1/index.d.ts +1 -1
- package/dist/v1/language/callable/admission.js +5 -3
- package/dist/v1/language/class/model/class.d.ts +1 -2
- package/dist/v1/language/class/resolved.d.ts +0 -7
- package/dist/v1/language/index.d.ts +1 -2
- package/dist/v1/language/index.js +1 -1
- package/dist/v1/language/limits.d.ts +2 -0
- package/dist/v1/language/limits.js +2 -0
- package/dist/v1/language/policy/analysis/branches.d.ts +1 -1
- package/dist/v1/language/policy/analysis/branches.js +6 -0
- package/dist/v1/language/policy/analysis/budgets.d.ts +4 -2
- package/dist/v1/language/policy/analysis/budgets.js +18 -3
- package/dist/v1/language/policy/analysis/checks.d.ts +5 -2
- package/dist/v1/language/policy/analysis/checks.js +12 -11
- package/dist/v1/language/policy/analysis/typing.d.ts +15 -2
- package/dist/v1/language/policy/analysis/typing.js +106 -4
- package/dist/v1/language/policy/model/policy.d.ts +13 -0
- package/dist/v1/language/policy/model/policy.js +4 -0
- package/dist/v1/language/policy/normalization/normalize.js +9 -2
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +125 -47
- package/dist/v1/schema/analysis/class.d.ts +0 -8
- package/dist/v1/schema/analysis/class.js +0 -28
- package/dist/v1/schema/compatibility/comparators/classes.d.ts +1 -1
- package/dist/v1/schema/compatibility/comparators/classes.js +1 -11
- package/dist/v1/schema/compatibility/evidence.js +12 -2
- package/dist/v1/schema/compatibility/fields.d.ts +2 -2
- package/dist/v1/schema/compatibility/fields.js +1 -1
- package/dist/v1/schema/diagnostic.d.ts +1 -1
- package/dist/v1/schema/enforcement/changes.d.ts +0 -6
- package/dist/v1/schema/enforcement/changes.js +0 -6
- package/dist/v1/schema/enforcement/derived.d.ts +0 -6
- package/dist/v1/schema/enforcement/derived.js +0 -6
- package/dist/v1/schema/enforcement/fields.d.ts +0 -1
- package/dist/v1/schema/enforcement/fields.js +0 -1
- package/dist/v1/schema/enforcement/write.d.ts +0 -7
- package/dist/v1/schema/enforcement/write.js +0 -7
- package/dist/v1/schema/normalization/domain.js +1 -1
- package/dist/v1/schema/resolution/origins.js +7 -2
- package/dist/v1/schema/rule.js +6 -10
- package/dist/v1/schema/validation/domain.json-schema.js +3 -41
- package/dist/v1/schema/validation/domain.structure.d.ts +5 -10
- package/dist/v1/schema/validation/domain.structure.js +31 -62
- package/dist/v1/schema/validation/policy/budgets.js +2 -1
- package/dist/v1/schema/validation/policy/context.d.ts +1 -0
- package/dist/v1/schema/validation/policy/context.js +3 -0
- package/dist/v1/schema/validation/policy/references.js +4 -1
- package/dist/v1/schema/validation/policy/typing.js +6 -0
- package/dist/v1/schema/validation/policy/uses.js +24 -2
- package/package.json +1 -1
- package/dist/v1/language/class/model/data.d.ts +0 -11
- package/dist/v1/language/class/model/data.js +0 -2
|
@@ -59,6 +59,7 @@ function canonicalizePolicy(value) {
|
|
|
59
59
|
return {
|
|
60
60
|
ref: value.ref,
|
|
61
61
|
...withDescription(value),
|
|
62
|
+
...(value.input === undefined ? {} : { input: value.input }),
|
|
62
63
|
expression: normalizePolicyExpression(value.expression),
|
|
63
64
|
};
|
|
64
65
|
}
|
|
@@ -83,7 +84,6 @@ function canonicalizeClass(value) {
|
|
|
83
84
|
return {
|
|
84
85
|
...base,
|
|
85
86
|
methods: mapRecord(value.methods, canonicalizeMethod),
|
|
86
|
-
...(value.data === undefined ? {} : { data: { mediaType: value.data.mediaType } }),
|
|
87
87
|
...(value.icon === undefined ? {} : { icon: value.icon }),
|
|
88
88
|
policies: canonicalizeClassPolicies(value.policies),
|
|
89
89
|
...(value.unique === undefined ? {} : { unique: canonicalizeNodeUnique(value.unique) }),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { compareDefinitionRefs, definitionRefIndex } from '../../addressing/ordering.js';
|
|
2
2
|
import { isBinaryInput } from '../../language/callable/model/callable.js';
|
|
3
|
+
import { checkBindings } from '../../language/policy/model/policy.js';
|
|
3
4
|
import { CLASS_OPERATIONS, isClassRuleChecks, PolicyComposition, policyVariableClass, } from '../../language/policy/model/policy.js';
|
|
4
5
|
import { isValueObject as isJsonObject } from '../../language/value/model/object.js';
|
|
5
6
|
import { walkSchema } from '../../language/value/syntax/walk.js';
|
|
@@ -88,6 +89,8 @@ export function collectCallableContractRefs(declaration, add) {
|
|
|
88
89
|
collectValueDefinitionRefs(declaration.output.item, add);
|
|
89
90
|
}
|
|
90
91
|
export function collectPolicyDefinitionRefs(declaration, add) {
|
|
92
|
+
for (const ref of Object.values(declaration.input ?? {}))
|
|
93
|
+
add(ref, 'policy');
|
|
91
94
|
collectPolicyExpressionRefs(declaration.expression, add);
|
|
92
95
|
}
|
|
93
96
|
function collectPolicyExpressionRefs(expression, add) {
|
|
@@ -131,8 +134,10 @@ function collectPolicyCheckRefs(expression, add) {
|
|
|
131
134
|
}
|
|
132
135
|
if ('check' in expression) {
|
|
133
136
|
add(expression.check, 'policy');
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
for (const operand of Object.values(checkBindings(expression))) {
|
|
138
|
+
if (operand.kind === 'ref')
|
|
139
|
+
add(operand.ref, 'policy');
|
|
140
|
+
}
|
|
136
141
|
return;
|
|
137
142
|
}
|
|
138
143
|
PolicyComposition.of(expression).operands.forEach((child) => collectPolicyCheckRefs(child, add));
|
package/dist/v1/schema/rule.js
CHANGED
|
@@ -110,11 +110,6 @@ const DECLARED = {
|
|
|
110
110
|
positions: ['/core/edges/{index}/source', '/core/edges/{index}/target'],
|
|
111
111
|
statement: 'A Core Edge endpoint names its Domain or a Definition its Domain declares and projects: a Class, Function, executable Method, Policy, View or Core Node.',
|
|
112
112
|
},
|
|
113
|
-
DV_DATA_COMPOSITION: {
|
|
114
|
-
stage: 'context',
|
|
115
|
-
positions: ['/classes/{class}/extends/{index}', '/classes/{class}/data'],
|
|
116
|
-
statement: 'A Node Class has at most one data declaration, its own or inherited from one declaring Class, and declares none of its own when it inherits one.',
|
|
117
|
-
},
|
|
118
113
|
DV_DEPENDENCY_ACYCLIC: {
|
|
119
114
|
stage: 'context',
|
|
120
115
|
positions: [...DEPENDENCIES],
|
|
@@ -261,8 +256,9 @@ const DECLARED = {
|
|
|
261
256
|
PL_BUDGET: {
|
|
262
257
|
stage: 'rule',
|
|
263
258
|
positions: ['/policies/{policy}', ...CHECKS],
|
|
264
|
-
statement: `A Policy stays within its budgets once expanded: pattern depth ${policy.patternDepth}, ${policy.normalizedBranches} normalized branches, ${policy.edgePredicates} Edge predicates a branch and ${policy.referencedDomains} referenced Domains; and checks within depth ${policy.checkDepth}, ${policy.checkBranches} branches and ${policy.checkLeaves} leaves.`,
|
|
259
|
+
statement: `A Policy declares at most ${policy.inputs} Node inputs and stays within its budgets once expanded: pattern depth ${policy.patternDepth}, ${policy.normalizedBranches} normalized branches, ${policy.edgePredicates} Edge predicates a branch and ${policy.referencedDomains} referenced Domains; and checks within depth ${policy.checkDepth}, ${policy.checkBranches} branches and ${policy.checkLeaves} leaves.`,
|
|
265
260
|
limits: [
|
|
261
|
+
'policy.inputs',
|
|
266
262
|
'policy.patternDepth',
|
|
267
263
|
'policy.normalizedBranches',
|
|
268
264
|
'policy.edgePredicates',
|
|
@@ -317,7 +313,7 @@ const DECLARED = {
|
|
|
317
313
|
stage: 'structure',
|
|
318
314
|
positions: ['/functions/{function}/input'],
|
|
319
315
|
statement: 'A Function input in binary mode is a binary input: it declares its metadata and maximumBytes.',
|
|
320
|
-
conditions: ['#/$defs/function-definition/properties/input/
|
|
316
|
+
conditions: ['#/$defs/function-definition/properties/input/oneOf/1/not'],
|
|
321
317
|
},
|
|
322
318
|
STRUCTURE_CALLABLE_POLICY_AUTH: {
|
|
323
319
|
stage: 'structure',
|
|
@@ -366,7 +362,7 @@ const DECLARED = {
|
|
|
366
362
|
STRUCTURE_FORMAT: {
|
|
367
363
|
stage: 'structure',
|
|
368
364
|
positions: ANY,
|
|
369
|
-
statement: 'A string matches the pattern of its position: an origin, a member name, a revision, a
|
|
365
|
+
statement: 'A string matches the pattern of its position: an origin, a member name, a revision, a dependency alias or a Core slug.',
|
|
370
366
|
},
|
|
371
367
|
STRUCTURE_KEY: {
|
|
372
368
|
stage: 'structure',
|
|
@@ -399,8 +395,8 @@ const DECLARED = {
|
|
|
399
395
|
positions: ANY,
|
|
400
396
|
statement: 'No object of the document has a member named __proto__, except the transitions of a State.',
|
|
401
397
|
conditions: [
|
|
402
|
-
'#/$defs/json-value/
|
|
403
|
-
'#/$defs/value-schema/
|
|
398
|
+
'#/$defs/json-value/oneOf/5/propertyNames/not',
|
|
399
|
+
'#/$defs/value-schema/oneOf/1/propertyNames/not',
|
|
404
400
|
],
|
|
405
401
|
},
|
|
406
402
|
STRUCTURE_REQUIRED: {
|
|
@@ -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,
|
|
5
|
+
import { domainSchemaStructure, documentJsonSchema, structureRules, } 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. */
|
|
@@ -25,20 +25,7 @@ export function domainSchemaJsonSchema() {
|
|
|
25
25
|
io: 'input',
|
|
26
26
|
// Every opaque part is stated or named, as `assertChecksStated` proved.
|
|
27
27
|
unrepresentable: 'any',
|
|
28
|
-
override: ({ zodSchema, jsonSchema: rendered }) => {
|
|
29
|
-
// Zod states the items of a tuple but not its length.
|
|
30
|
-
const def = zodSchema._zod.def;
|
|
31
|
-
if (def.type !== 'tuple')
|
|
32
|
-
return;
|
|
33
|
-
if (def.rest !== null || def.items.some((item) => item._zod.optin === 'optional')) {
|
|
34
|
-
throw new Error('A tuple of the structure has a fixed length.');
|
|
35
|
-
}
|
|
36
|
-
rendered.minItems = def.items.length;
|
|
37
|
-
rendered.maxItems = def.items.length;
|
|
38
|
-
},
|
|
39
28
|
});
|
|
40
|
-
stateVariantsByAnyOf(root);
|
|
41
|
-
stateVariantsByAnyOf($defs);
|
|
42
29
|
const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
|
|
43
30
|
if (unnamed.length > 0) {
|
|
44
31
|
throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
|
|
@@ -155,35 +142,12 @@ function isStated(schema, check) {
|
|
|
155
142
|
}
|
|
156
143
|
/** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
|
|
157
144
|
function statementOf(schema) {
|
|
158
|
-
const { id: _id, description: _description,
|
|
145
|
+
const { id: _id, description: _description, ...statement } = documentJsonSchema._map.get(schema) ?? {};
|
|
159
146
|
return Object.keys(statement).length > 0 ? statement : undefined;
|
|
160
147
|
}
|
|
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
|
-
}
|
|
184
148
|
/**
|
|
185
149
|
* Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
|
|
186
|
-
* removed
|
|
150
|
+
* removed.
|
|
187
151
|
*/
|
|
188
152
|
function rulePositions(document) {
|
|
189
153
|
const positions = new Map();
|
|
@@ -205,8 +169,6 @@ function rulePositions(document) {
|
|
|
205
169
|
}
|
|
206
170
|
delete schema['x-astrale-rule'];
|
|
207
171
|
}
|
|
208
|
-
if (typeof schema.maxLength === 'number')
|
|
209
|
-
note('length-in-utf16-code-units', pointer);
|
|
210
172
|
for (const [key, entry] of Object.entries(schema)) {
|
|
211
173
|
visit(entry, `${pointer}/${escapePointerToken(key)}`);
|
|
212
174
|
}
|
|
@@ -12,11 +12,8 @@ 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;
|
|
16
15
|
};
|
|
17
16
|
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";
|
|
20
17
|
/**
|
|
21
18
|
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
22
19
|
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
@@ -26,10 +23,6 @@ export declare const structureRules: {
|
|
|
26
23
|
readonly code: 'STRUCTURE_DUPLICATE_ITEM';
|
|
27
24
|
readonly statement: 'A unique tuple is a set of fields: two tuples naming the same fields in another order are one tuple, repeated.';
|
|
28
25
|
};
|
|
29
|
-
readonly 'length-in-utf16-code-units': {
|
|
30
|
-
readonly code: 'STRUCTURE_MAXIMUM';
|
|
31
|
-
readonly statement: 'A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.';
|
|
32
|
-
};
|
|
33
26
|
};
|
|
34
27
|
export type StructureRule = keyof typeof structureRules;
|
|
35
28
|
/** Only an authorized callable declares a policy: an anonymous or authenticated one has none. */
|
|
@@ -393,9 +386,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
393
386
|
static: boolean;
|
|
394
387
|
abstract: boolean;
|
|
395
388
|
}>>>;
|
|
396
|
-
data: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
397
|
-
mediaType: import("zod").ZodString;
|
|
398
|
-
}, zodCore.$strict>>;
|
|
399
389
|
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
400
390
|
policies: import("zod").ZodObject<{
|
|
401
391
|
read: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
|
|
@@ -7694,6 +7684,11 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
|
|
|
7694
7684
|
name: string;
|
|
7695
7685
|
}[]]>>;
|
|
7696
7686
|
}, zodCore.$strict>]>;
|
|
7687
|
+
input: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
7688
|
+
origin: import("zod").ZodString;
|
|
7689
|
+
kind: import("zod").ZodLiteral<"class">;
|
|
7690
|
+
name: import("zod").ZodString;
|
|
7691
|
+
}, zodCore.$strict>>>;
|
|
7697
7692
|
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
7698
7693
|
}, zodCore.$strict>>;
|
|
7699
7694
|
views: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
@@ -1,7 +1,6 @@
|
|
|
1
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
|
-
import { MEDIA_TYPE_PATTERN } from '../../language/class/model/data.js';
|
|
5
4
|
import * as metadata from '../../language/definition/metadata.js';
|
|
6
5
|
import { limits } from '../../language/limits.js';
|
|
7
6
|
import { BLOB_VALUE_KIND, isBlobValueSchema } from '../../language/value/model/blob.js';
|
|
@@ -9,16 +8,17 @@ import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
|
9
8
|
import { SchemaError, diagnostic, } from '../diagnostic.js';
|
|
10
9
|
import { DOMAIN_FORMAT, DOMAIN_VERSION } from '../model/format.js';
|
|
11
10
|
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
11
|
/**
|
|
15
|
-
* A union of disjoint variants
|
|
16
|
-
* variant, from which `matchedVariant` decides what a refused value
|
|
17
|
-
*
|
|
12
|
+
* A union of disjoint variants, which JSON Schema states by `oneOf`. It is exclusive (`xor`) so that
|
|
13
|
+
* zod reports the issues of every variant, from which `matchedVariant` decides what a refused value
|
|
14
|
+
* reports: zod's own union reports its one variant that did not abort, and since zod 4.6 an
|
|
15
|
+
* oversized list aborts, so a value of the right shape would report `STRUCTURE_UNION` instead of its
|
|
16
|
+
* bound.
|
|
18
17
|
*/
|
|
19
|
-
function variants(options, annotation
|
|
18
|
+
function variants(options, annotation) {
|
|
20
19
|
const union = xor(options);
|
|
21
|
-
|
|
20
|
+
if (annotation !== undefined)
|
|
21
|
+
documentJsonSchema.add(union, annotation);
|
|
22
22
|
return union;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -30,14 +30,12 @@ export const structureRules = {
|
|
|
30
30
|
code: 'STRUCTURE_DUPLICATE_ITEM',
|
|
31
31
|
statement: 'A unique tuple is a set of fields: two tuples naming the same fields in another order are one tuple, repeated.',
|
|
32
32
|
},
|
|
33
|
-
'length-in-utf16-code-units': {
|
|
34
|
-
code: 'STRUCTURE_MAXIMUM',
|
|
35
|
-
statement: 'A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.',
|
|
36
|
-
},
|
|
37
33
|
};
|
|
38
34
|
// The pattern refuses `__proto__`, which zod skips before any key check (`lostProtoKeys`).
|
|
39
35
|
const RESERVED_DEPENDENCY_ALIASES = ['prototype', 'constructor'];
|
|
40
|
-
const originSchema =
|
|
36
|
+
const originSchema = string()
|
|
37
|
+
.min(3)
|
|
38
|
+
.max(253)
|
|
41
39
|
.regex(DOMAIN_ORIGIN_PATTERN)
|
|
42
40
|
.register(documentJsonSchema, { id: 'origin' });
|
|
43
41
|
const memberNameSchema = string()
|
|
@@ -59,15 +57,25 @@ const propertyKeySchema = string()
|
|
|
59
57
|
params: { structureCode: 'STRUCTURE_PROPERTY_KEY' },
|
|
60
58
|
})
|
|
61
59
|
.register(documentJsonSchema, { id: 'property-key', pattern: PROPERTY_KEY_PATTERN.source });
|
|
62
|
-
const coreSlugSchema =
|
|
60
|
+
const coreSlugSchema = string()
|
|
61
|
+
.min(1)
|
|
62
|
+
.max(100)
|
|
63
63
|
.regex(CORE_SLUG_PATTERN)
|
|
64
64
|
.register(documentJsonSchema, { id: 'core-slug' });
|
|
65
65
|
const revisionSchema = string()
|
|
66
66
|
.regex(DOMAIN_REVISION_PATTERN)
|
|
67
67
|
.register(documentJsonSchema, { id: 'revision' });
|
|
68
|
-
const descriptionSchema =
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const descriptionSchema = string()
|
|
69
|
+
.min(metadata.description.minLength)
|
|
70
|
+
.max(metadata.description.maxLength)
|
|
71
|
+
.register(documentJsonSchema, { id: 'description' });
|
|
72
|
+
const iconSchema = string()
|
|
73
|
+
.min(metadata.icon.minLength)
|
|
74
|
+
.max(metadata.icon.maxLength)
|
|
75
|
+
.register(documentJsonSchema, { id: 'icon' });
|
|
76
|
+
const domainNameSchema = string()
|
|
77
|
+
.min(metadata.name.minLength)
|
|
78
|
+
.max(metadata.name.maxLength)
|
|
71
79
|
.refine(metadata.isDomainNameText, {
|
|
72
80
|
message: 'Expected one trimmed line of text.',
|
|
73
81
|
params: { structureCode: 'STRUCTURE_DOMAIN_NAME' },
|
|
@@ -80,8 +88,8 @@ const domainNameSchema = boundedString(metadata.name.minLength, metadata.name.ma
|
|
|
80
88
|
// The shape of a Domain icon. Its UTF-8 bounds, its SVG grammar and that it draws at least one size
|
|
81
89
|
// are the rule DV_DOMAIN_ICON, which reads each text whole.
|
|
82
90
|
const domainIconArtSchema = strictObject({
|
|
83
|
-
svg:
|
|
84
|
-
dark:
|
|
91
|
+
svg: string().min(1),
|
|
92
|
+
dark: string().min(1).optional(),
|
|
85
93
|
}).register(documentJsonSchema, { id: 'domain-icon-art' });
|
|
86
94
|
const domainIconSchema = strictObject({
|
|
87
95
|
small: domainIconArtSchema.optional(),
|
|
@@ -111,10 +119,7 @@ const jsonSchemaSchema = variants([boolean(), jsonObjectSchema], {
|
|
|
111
119
|
id: 'value-schema',
|
|
112
120
|
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.',
|
|
113
121
|
});
|
|
114
|
-
const
|
|
115
|
-
mediaType: string().regex(MEDIA_TYPE_PATTERN).register(documentJsonSchema, { id: 'media-type' }),
|
|
116
|
-
});
|
|
117
|
-
const stateNameSchema = boundedString(1);
|
|
122
|
+
const stateNameSchema = string().min(1);
|
|
118
123
|
// A custom check reads the relation in place: a record would copy it and drop a `__proto__` state.
|
|
119
124
|
const stateTransitionsSchema = custom(isStateTransitions, {
|
|
120
125
|
message: 'Expected each non-empty state to map non-empty events to non-empty states.',
|
|
@@ -246,6 +251,7 @@ const policyPatternVariableSchema = strictObject({
|
|
|
246
251
|
}).register(documentJsonSchema, { id: 'policy-pattern-variable' });
|
|
247
252
|
const policyPatternNodeSchema = discriminatedUnion('kind', [
|
|
248
253
|
policyPatternSubjectSchema,
|
|
254
|
+
strictObject({ kind: literal('input'), name: memberNameSchema }),
|
|
249
255
|
policyPatternObjectSchema,
|
|
250
256
|
policyPatternSourceSchema,
|
|
251
257
|
policyPatternTargetSchema,
|
|
@@ -303,6 +309,7 @@ function policyChecksSchema(objectSchema, id) {
|
|
|
303
309
|
const checks = lazy(() => variants([
|
|
304
310
|
strictObject({ sameNode: strictObject({ left: objectSchema, right: objectSchema }) }),
|
|
305
311
|
strictObject({ check: policyRefSchema, object: objectSchema }),
|
|
312
|
+
strictObject({ check: policyRefSchema, input: record(memberNameSchema, objectSchema) }),
|
|
306
313
|
strictObject({ allOf: nonEmpty(array(checks)) }),
|
|
307
314
|
strictObject({ anyOf: nonEmpty(array(checks)) }),
|
|
308
315
|
])).register(documentJsonSchema, { id });
|
|
@@ -406,7 +413,6 @@ const nodeClassSchema = strictObject({
|
|
|
406
413
|
extends: uniqueArray(classRefSchema),
|
|
407
414
|
properties: nodePropertyRecordSchema,
|
|
408
415
|
methods: methodRecordSchema,
|
|
409
|
-
data: dataDeclarationSchema.optional(),
|
|
410
416
|
icon: iconSchema.optional(),
|
|
411
417
|
policies: nodeClassPoliciesSchema,
|
|
412
418
|
unique: nodeUniqueSchema.optional(),
|
|
@@ -480,6 +486,7 @@ const policyExpressionSchema = variants([
|
|
|
480
486
|
const policyDefinitionSchema = strictObject({
|
|
481
487
|
ref: policyRefSchema,
|
|
482
488
|
expression: policyExpressionSchema,
|
|
489
|
+
input: record(memberNameSchema, classRefSchema).optional(),
|
|
483
490
|
description: descriptionSchema.optional(),
|
|
484
491
|
}).register(documentJsonSchema, { id: 'policy-definition' });
|
|
485
492
|
const viewTargetSchema = strictObject({ kind: literal('domain') }).register(documentJsonSchema, {
|
|
@@ -610,44 +617,6 @@ function isRecord(input) {
|
|
|
610
617
|
function isObject(input) {
|
|
611
618
|
return input !== null && typeof input === 'object';
|
|
612
619
|
}
|
|
613
|
-
/**
|
|
614
|
-
* A string of `minimum` to `maximum` UTF-16 code units, the length the language measures, stated in
|
|
615
|
-
* JSON Schema as `minLength` and `maxLength` under the rule `length-in-utf16-code-units`. Zod's own
|
|
616
|
-
* string bounds count code points, which would admit twice the code units of the bound.
|
|
617
|
-
*/
|
|
618
|
-
function boundedString(minimum, maximum, id) {
|
|
619
|
-
return string()
|
|
620
|
-
.check((payload) => {
|
|
621
|
-
const length = payload.value.length;
|
|
622
|
-
if (length < minimum) {
|
|
623
|
-
payload.issues.push({
|
|
624
|
-
code: 'too_small',
|
|
625
|
-
origin: 'string',
|
|
626
|
-
minimum,
|
|
627
|
-
inclusive: true,
|
|
628
|
-
input: payload.value,
|
|
629
|
-
continue: true,
|
|
630
|
-
message: `Expected at least ${minimum} UTF-16 code units.`,
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
else if (maximum !== undefined && length > maximum) {
|
|
634
|
-
payload.issues.push({
|
|
635
|
-
code: 'too_big',
|
|
636
|
-
origin: 'string',
|
|
637
|
-
maximum,
|
|
638
|
-
inclusive: true,
|
|
639
|
-
input: payload.value,
|
|
640
|
-
continue: true,
|
|
641
|
-
message: `Expected at most ${maximum} UTF-16 code units.`,
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
})
|
|
645
|
-
.register(documentJsonSchema, {
|
|
646
|
-
...(id === undefined ? {} : { id }),
|
|
647
|
-
minLength: minimum,
|
|
648
|
-
...(maximum === undefined ? {} : { maxLength: maximum }),
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
620
|
/** At least one item, which `min(1)` proves: the output is typed as the non-empty tuple it is. */
|
|
652
621
|
function nonEmpty(list) {
|
|
653
622
|
return list.min(1);
|
|
@@ -19,7 +19,7 @@ export function measurePolicies(input) {
|
|
|
19
19
|
export function measureDomainPolicies(schema, normalized = normalizedPolicies(schema)) {
|
|
20
20
|
const measurePolicy = policyMeasurer(schema.origin, normalized, (ref) => ref.origin === schema.origin &&
|
|
21
21
|
ref.kind === 'policy' &&
|
|
22
|
-
Object.hasOwn(schema.policies, ref.name));
|
|
22
|
+
Object.hasOwn(schema.policies, ref.name), (name) => schema.policies[name]?.input);
|
|
23
23
|
const policies = {};
|
|
24
24
|
const unmeasured = [];
|
|
25
25
|
for (const name of Object.keys(schema.policies)) {
|
|
@@ -68,6 +68,7 @@ export function validateCheckBudget(context, pointer, measure) {
|
|
|
68
68
|
}
|
|
69
69
|
/** How `PL_BUDGET` explains each limit a named Policy exceeds. */
|
|
70
70
|
const REFUSAL = {
|
|
71
|
+
inputs: (measure) => `Policy declares ${measure.inputs} Node inputs. The maximum is ${limits.policy.inputs}.`,
|
|
71
72
|
patternDepth: (measure) => `Expanded Pattern depth ${measure.patternDepth} exceeds ${limits.policy.patternDepth}.`,
|
|
72
73
|
normalizedBranches: () => `Expanded Pattern has more than ${limits.policy.normalizedBranches} normalized branches.`,
|
|
73
74
|
edgePredicates: (measure) => `A normalized branch contains ${measure.edgePredicates} graph predicates; the maximum is ${limits.policy.edgePredicates}.`,
|
|
@@ -15,6 +15,7 @@ export declare class PolicyValidationContext implements PolicyTypingScope {
|
|
|
15
15
|
readonly allNodeClasses: readonly ClassRef[];
|
|
16
16
|
readonly concreteNodeClasses: readonly ClassRef[];
|
|
17
17
|
constructor(environment: DomainResolutionContext, analysis: DefinitionAnalysisResult);
|
|
18
|
+
inputOf(name: string): Readonly<Record<string, ClassRef>> | undefined;
|
|
18
19
|
resolveNodeClass(ref: ClassRef, pointer: string): IndexedClassDefinition | undefined;
|
|
19
20
|
resolveEdge(ref: ClassRef, pointer: string): IndexedClassDefinition | undefined;
|
|
20
21
|
resolvePolicy(ref: PolicyRef, pointer: string): boolean;
|
|
@@ -20,6 +20,9 @@ export class PolicyValidationContext {
|
|
|
20
20
|
.filter((value) => !value.declaration.abstract)
|
|
21
21
|
.map((value) => value.ref);
|
|
22
22
|
}
|
|
23
|
+
inputOf(name) {
|
|
24
|
+
return this.environment.candidate.policies[name]?.input;
|
|
25
|
+
}
|
|
23
26
|
resolveNodeClass(ref, pointer) {
|
|
24
27
|
const resolved = this.environment.resolve(ref);
|
|
25
28
|
if (resolved === undefined || resolved.ref.kind !== 'class' || resolved.kind !== 'node') {
|
|
@@ -12,6 +12,8 @@ export function validatePolicyReferences(context) {
|
|
|
12
12
|
if (!equalDefinitionRefs(declaration.ref, expected)) {
|
|
13
13
|
context.add('DV_REF_RESOLVES', `${pointer}/ref`, `Policy ref must be exactly ${expected.origin}:policy.${expected.name}.`);
|
|
14
14
|
}
|
|
15
|
+
for (const [key, ref] of Object.entries(declaration.input ?? {}))
|
|
16
|
+
context.resolveNodeClass(ref, pointer + '/input/' + key);
|
|
15
17
|
const expression = declaration.expression;
|
|
16
18
|
context.normalized.set(name, normalizePolicyExpression(expression));
|
|
17
19
|
if ('match' in expression)
|
|
@@ -38,7 +40,8 @@ function validateMatch(context, name, pattern, pointer) {
|
|
|
38
40
|
context.add('PL_TARGET', `${pointer}/match`, `Normalized branch ${index} must use object or at least one of source and target, without mixing target modes.`);
|
|
39
41
|
continue;
|
|
40
42
|
}
|
|
41
|
-
if (!isConnected(branch)
|
|
43
|
+
if (!isConnected(branch) ||
|
|
44
|
+
Object.keys(context.environment.candidate.policies[name]?.input ?? {}).some((key) => !branch.terms.has('input:' + key))) {
|
|
42
45
|
context.add('PL_CONNECTIVITY', `${pointer}/match`, `Normalized ${mode} branch ${index} does not connect subject, every referenced protected term, and every scoped term.`);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -6,8 +6,14 @@ export function validatePolicyTyping(context, typing) {
|
|
|
6
6
|
const branches = typing.expandedBranches(name, `$${name}`);
|
|
7
7
|
if (branches === undefined)
|
|
8
8
|
continue;
|
|
9
|
+
if (!typing.validDeclaration(name)) {
|
|
10
|
+
context.add('PL_USE', '/policies/' + escapePointerToken(name), 'Policy branches and operands must agree with the declared input names and Classes.');
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
9
13
|
for (const [index, branch] of branches.entries()) {
|
|
10
14
|
const mode = targetMode(branch);
|
|
15
|
+
if (mode === 'named')
|
|
16
|
+
continue;
|
|
11
17
|
if (mode === undefined) {
|
|
12
18
|
if (!('match' in context.environment.candidate.policies[name].expression)) {
|
|
13
19
|
context.add('PL_TARGET', `/policies/${escapePointerToken(name)}`, `Expanded normalized branch ${index} must use object or at least one of source and target, without mixing target modes.`);
|
|
@@ -113,6 +113,26 @@ function visitChecks(validation, typing, expression, context, pointer, leaves) {
|
|
|
113
113
|
if ('check' in expression) {
|
|
114
114
|
if (!validation.resolvePolicy(expression.check, `${pointer}/check`))
|
|
115
115
|
return;
|
|
116
|
+
if ('input' in expression) {
|
|
117
|
+
const actuals = Object.create(null);
|
|
118
|
+
for (const [key, operand] of Object.entries(expression.input)) {
|
|
119
|
+
const location = pointer + '/input/' + key;
|
|
120
|
+
const contracts = operand.kind === 'self'
|
|
121
|
+
? selfContracts(validation, context, location)
|
|
122
|
+
: operand.kind === 'input'
|
|
123
|
+
? inputContracts(validation, context, operand.field, location)
|
|
124
|
+
: referenceContracts(validation, operand.ref, location);
|
|
125
|
+
if (!contracts)
|
|
126
|
+
return;
|
|
127
|
+
actuals[key] = contracts;
|
|
128
|
+
}
|
|
129
|
+
const classes = typing.namedCheck(expression.check.name, expression.input, actuals);
|
|
130
|
+
if (!classes)
|
|
131
|
+
validation.add('PL_USE', pointer, 'Bindings must supply each declared input with a compatible Node.');
|
|
132
|
+
else
|
|
133
|
+
leaves.set(expression, classes);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
116
136
|
if (expression.object.kind === 'self' && context.edge !== undefined) {
|
|
117
137
|
// An Edge is checked as an Edge Class Policy is: over every concrete endpoint pair.
|
|
118
138
|
if (!typing.policyAcceptsEdgeClass(expression.check.name, context.edge.declaration)) {
|
|
@@ -120,7 +140,9 @@ function visitChecks(validation, typing, expression, context, pointer, leaves) {
|
|
|
120
140
|
return;
|
|
121
141
|
}
|
|
122
142
|
const edge = formatDefinitionRef(context.edge.ref);
|
|
123
|
-
leaves.set(expression,
|
|
143
|
+
leaves.set(expression, [
|
|
144
|
+
{ object: expression.object, accepted: [edge], admitted: new Set([edge]) },
|
|
145
|
+
]);
|
|
124
146
|
return;
|
|
125
147
|
}
|
|
126
148
|
const objectPointer = `${pointer}/object`;
|
|
@@ -136,7 +158,7 @@ function visitChecks(validation, typing, expression, context, pointer, leaves) {
|
|
|
136
158
|
validation.add('PL_USE', pointer, `${formatDefinitionRef(expression.check)} is incompatible with ${SITE[context.site].objects}.`, formatDefinitionRef(expression.check));
|
|
137
159
|
return;
|
|
138
160
|
}
|
|
139
|
-
leaves.set(expression, classes);
|
|
161
|
+
leaves.set(expression, [{ ...classes, object: expression.object }]);
|
|
140
162
|
return;
|
|
141
163
|
}
|
|
142
164
|
const { operator, operands } = PolicyComposition.of(expression);
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Object as JsonObject } from '@astrale-os/kernel-dsl/value';
|
|
2
|
-
/** Canonical lowercase RFC 6838 media type without parameters. */
|
|
3
|
-
export declare const MEDIA_TYPE_PATTERN: RegExp;
|
|
4
|
-
export type MediaType = string;
|
|
5
|
-
/** Schema-level contract for one externally stored Node payload. */
|
|
6
|
-
export type DataDefinition = JsonObject & {
|
|
7
|
-
readonly mediaType: MediaType;
|
|
8
|
-
};
|
|
9
|
-
export interface DataFacet {
|
|
10
|
-
readonly data?: DataDefinition;
|
|
11
|
-
}
|