@astrale-os/kernel-dsl 1.0.0-beta.16 → 1.0.0-beta.17
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/class/authoring.js +3 -2
- package/dist/v1/builder/class/input.d.ts +45 -14
- package/dist/v1/builder/index.d.ts +2 -1
- package/dist/v1/builder/lowering/class.d.ts +8 -0
- package/dist/v1/builder/lowering/class.js +40 -16
- package/dist/v1/builder/lowering/schema/compile.js +3 -3
- package/dist/v1/builder/policy/authoring.js +97 -88
- package/dist/v1/bundle/model.js +1 -1
- package/dist/v1/compiled/admission/accept.js +1 -7
- package/dist/v1/compiled/admission/semantics/class.js +2 -3
- package/dist/v1/compiled/admission/semantics/policy/parity.js +25 -13
- package/dist/v1/compiled/admission/wire/class.js +23 -18
- package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
- package/dist/v1/compiled/admission/wire/policy.js +8 -7
- package/dist/v1/compiled/loader/load.js +1 -1
- package/dist/v1/domain/create.js +1 -1
- package/dist/v1/domain/model/input.d.ts +2 -1
- package/dist/v1/domain/projection/classes.js +1 -1
- package/dist/v1/domain/validation/create.d.ts +2 -1
- package/dist/v1/domain/validation/create.js +1 -1
- package/dist/v1/index.d.ts +1 -1
- package/dist/v1/language/callable/resolved.d.ts +11 -2
- package/dist/v1/language/class/model/class.d.ts +17 -5
- package/dist/v1/language/freeze.d.ts +5 -0
- package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
- package/dist/v1/language/policy/analysis/typing.d.ts +1 -0
- package/dist/v1/language/policy/analysis/typing.js +74 -79
- package/dist/v1/language/policy/model/policy.d.ts +44 -4
- package/dist/v1/language/policy/model/policy.js +14 -0
- package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
- package/dist/v1/language/policy/normalization/normalize.js +5 -5
- package/dist/v1/language/validation/rule.d.ts +18 -8
- package/dist/v1/language/validation/rule.js +2 -11
- package/dist/v1/language/value/evaluate/program.d.ts +2 -1
- package/dist/v1/language/value/evaluate/program.js +2 -2
- package/dist/v1/language/value/evaluate/validate.d.ts +2 -2
- package/dist/v1/language/value/evaluate/validate.js +2 -2
- package/dist/v1/language/value/profile/json.validate.d.ts +3 -1
- package/dist/v1/language/value/profile/json.validate.js +3 -2
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +180 -25
- package/dist/v1/schema/admission/callable.js +1 -1
- package/dist/v1/schema/canonical/revision.js +4 -4
- package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
- package/dist/v1/schema/compatibility/comparators/classes.js +4 -4
- package/dist/v1/schema/compatibility/comparators/members.js +1 -1
- package/dist/v1/schema/compatibility/comparators/values.js +2 -2
- package/dist/v1/schema/compatibility/report.js +1 -1
- package/dist/v1/schema/compatibility/versioning/index.js +1 -1
- package/dist/v1/schema/model/schema.js +1 -1
- package/dist/v1/schema/normalization/domain.js +9 -8
- package/dist/v1/schema/resolution/domain.js +1 -1
- package/dist/v1/schema/resolution/origins.js +3 -2
- package/dist/v1/schema/rule.d.ts +8 -20
- package/dist/v1/schema/rule.js +1 -1
- package/dist/v1/schema/validation/class.js +2 -3
- package/dist/v1/schema/validation/domain.json-schema.d.ts +2 -2
- package/dist/v1/schema/validation/domain.json-schema.js +20 -6
- package/dist/v1/schema/validation/domain.structure.d.ts +4765 -1005
- package/dist/v1/schema/validation/domain.structure.js +21 -9
- package/dist/v1/schema/validation/json.json-schema.d.ts +18 -2
- package/dist/v1/schema/validation/json.json-schema.js +14 -4
- package/dist/v1/schema/validation/policy/budgets.d.ts +1 -1
- package/dist/v1/schema/validation/policy/budgets.js +4 -4
- package/dist/v1/schema/validation/policy/uses.d.ts +10 -2
- package/dist/v1/schema/validation/policy/uses.js +26 -13
- package/dist/v1/schema/validation/policy/validate.js +2 -3
- package/dist/v1/schema/validation/value.json-schema.d.ts +4 -6
- package/dist/v1/schema/validation/value.json-schema.js +18 -25
- package/package.json +1 -1
- package/dist/v1/schema/canonical/domain.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.js +0 -5
- package/dist/v1/schema/canonical/domain.js +0 -5
- package/dist/v1/schema/canonical/freeze.d.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compareDefinitionRefs, definitionRefIndex } from '../../addressing/ordering.js';
|
|
2
2
|
import { isBinaryInput } from '../../language/callable/model/callable.js';
|
|
3
|
-
import { isClassRuleChecks, policyVariableClass } from '../../language/policy/model/policy.js';
|
|
3
|
+
import { CLASS_OPERATIONS, isClassRuleChecks, policyVariableClass, } from '../../language/policy/model/policy.js';
|
|
4
4
|
import { isValueObject as isJsonObject } from '../../language/value/model/object.js';
|
|
5
5
|
import { walkSchema } from '../../language/value/syntax/walk.js';
|
|
6
6
|
/** Collect only semantic refs, never strings or objects embedded as JSON data. */
|
|
@@ -58,7 +58,8 @@ export function collectClassRefs(declaration, add) {
|
|
|
58
58
|
Object.values(declaration.methods).forEach((method) => collectCallableRefs(method, add));
|
|
59
59
|
}
|
|
60
60
|
export function collectClassPolicyRefs(declaration, add) {
|
|
61
|
-
for (const
|
|
61
|
+
for (const operation of CLASS_OPERATIONS) {
|
|
62
|
+
const policy = declaration.policies[operation];
|
|
62
63
|
if (isClassRuleChecks(policy))
|
|
63
64
|
collectPolicyCheckRefs(policy, add);
|
|
64
65
|
else if (typeof policy === 'object')
|
package/dist/v1/schema/rule.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { DiagnosticRule } from '../language/validation/rule.js';
|
|
1
2
|
import type { SchemaDiagnosticCode } from './diagnostic.js';
|
|
2
|
-
import { type LimitKey } from '../language/limits.js';
|
|
3
3
|
/**
|
|
4
4
|
* What a rule reads to decide. `structure`: the shape of the document alone. `rule`: the whole
|
|
5
5
|
* document. `context`: the document and its environment, so one document can be accepted in one
|
|
@@ -8,28 +8,16 @@ import { type LimitKey } from '../language/limits.js';
|
|
|
8
8
|
* closure its acceptance retained.
|
|
9
9
|
*/
|
|
10
10
|
export type SchemaRuleStage = 'structure' | 'rule' | 'context';
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The rule one Schema diagnostic code reports. A final `{/path*}` of its positions stands for any
|
|
13
|
+
* further tokens; `{endpoint}` is `source`, `target`, `0` or `1`; `{count}` is `outgoing`,
|
|
14
|
+
* `incoming` or `incident`; `{operation}` is `read` or `traverse`; `{key}` is a Property key. A
|
|
15
|
+
* condition is a fragment such as `#/$defs/edge-class/if`.
|
|
16
|
+
*/
|
|
17
|
+
export interface SchemaRule extends DiagnosticRule {
|
|
13
18
|
readonly stage: SchemaRuleStage;
|
|
14
|
-
/**
|
|
15
|
-
* The positions the rule constrains, which its diagnostics point at: JSON Pointer templates in
|
|
16
|
-
* which a `{name}` token stands for one token of the kind it names and a final `{/path*}` for any
|
|
17
|
-
* further tokens. `{endpoint}` is `source`, `target`, `0` or `1`; `{count}` is `outgoing`,
|
|
18
|
-
* `incoming` or `incident`; `{operation}` is `read` or `traverse`; `{key}` is a Property key.
|
|
19
|
-
*/
|
|
20
|
-
readonly positions: readonly [string, ...string[]];
|
|
21
|
-
/** The rule, in one plain sentence. */
|
|
22
|
-
readonly statement: string;
|
|
23
19
|
/** What the feature the rule guards enforces on data or on calls, where it enforces something. */
|
|
24
20
|
readonly enforces?: string;
|
|
25
|
-
/** The limits of `limits` the rule enforces, by key, where it enforces some. */
|
|
26
|
-
readonly limits?: readonly [LimitKey, ...LimitKey[]];
|
|
27
|
-
/**
|
|
28
|
-
* The conditions of the published JSON Schema of the document that state the rule, where some
|
|
29
|
-
* do: the URI fragment of each `if` or `not` subschema, `#/$defs/edge-class/if`, whose failure
|
|
30
|
-
* refuses a document with this rule's code.
|
|
31
|
-
*/
|
|
32
|
-
readonly conditions?: readonly [string, ...string[]];
|
|
33
21
|
}
|
|
34
22
|
/**
|
|
35
23
|
* Every Schema diagnostic code with the rule it reports. A code added to the DSL does not compile
|
package/dist/v1/schema/rule.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaultLimits } from '@astrale-os/kernel-dsl/value';
|
|
2
|
+
import { deepFreeze } from '../language/freeze.js';
|
|
2
3
|
import { limits } from '../language/limits.js';
|
|
3
|
-
import { deepFreeze } from './canonical/freeze.js';
|
|
4
4
|
const ANY = ['{/path*}'];
|
|
5
5
|
const CHECKS = [
|
|
6
6
|
'/classes/{class}/policies/{operation}{/path*}',
|
|
@@ -34,9 +34,8 @@ export function validateDefinitions(environment, analysis, registry) {
|
|
|
34
34
|
if (!equalDefinitionRefs(declaration.ref, ref)) {
|
|
35
35
|
diagnostics.push(diagnostic('DV_REF_RESOLVES', `${pointer}/ref`, `Class ref must be exactly ${formatDefinitionRef(ref)}.`, formatDefinitionRef(declaration.ref)));
|
|
36
36
|
}
|
|
37
|
-
if (declaration.abstract &&
|
|
38
|
-
(
|
|
39
|
-
diagnostics.push(diagnostic('DV_CLASS_ABSTRACT', `${pointer}/policies`, 'Abstract Classes cannot declare observation Policies.'));
|
|
37
|
+
if (declaration.abstract && Object.keys(declaration.policies).length > 0) {
|
|
38
|
+
diagnostics.push(diagnostic('DV_CLASS_ABSTRACT', `${pointer}/policies`, 'Abstract Classes cannot declare Class Policies.'));
|
|
40
39
|
}
|
|
41
40
|
validateFacet(registry, declaration, pointer, diagnostics);
|
|
42
41
|
validateParents(environment, ref, declaration.kind, declaration.extends, diagnostics);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type core as zodCore } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { type JsonSchema } from './json.json-schema.js';
|
|
3
3
|
/**
|
|
4
4
|
* The JSON Schema of an authored Domain schema document, rendered from the structure the Kernel
|
|
5
5
|
* enforces. Zod derives what it reads; `documentJsonSchema` states each refinement it cannot read,
|
|
@@ -7,7 +7,7 @@ export type JsonSchemaDocument = zodCore.JSONSchema.JSONSchema;
|
|
|
7
7
|
* rendering, so that no check of the structure is dropped silently. Every value schema is in the
|
|
8
8
|
* published dialect and states the profile rules JSON Schema can state; the others are named.
|
|
9
9
|
*/
|
|
10
|
-
export declare function domainSchemaJsonSchema():
|
|
10
|
+
export declare function domainSchemaJsonSchema(): JsonSchema;
|
|
11
11
|
/**
|
|
12
12
|
* Every refinement and custom part of the structure carries its statement in `documentJsonSchema`:
|
|
13
13
|
* the keywords that state it, or its named rule. Only parts zod renders take part.
|
|
@@ -3,10 +3,14 @@ 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
5
|
import { domainSchemaStructure, documentJsonSchema, structureRules, } from './domain.structure.js';
|
|
6
|
-
import { jsonValueJsonSchema, jsonValueRules } from './json.json-schema.js';
|
|
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. */
|
|
9
|
-
const namedRules = {
|
|
9
|
+
const namedRules = {
|
|
10
|
+
...structureRules,
|
|
11
|
+
...jsonValueRules,
|
|
12
|
+
...valueSchemaRules,
|
|
13
|
+
};
|
|
10
14
|
/**
|
|
11
15
|
* The JSON Schema of an authored Domain schema document, rendered from the structure the Kernel
|
|
12
16
|
* enforces. Zod derives what it reads; `documentJsonSchema` states each refinement it cannot read,
|
|
@@ -55,7 +59,7 @@ export function domainSchemaJsonSchema() {
|
|
|
55
59
|
'node-property-definition': { ...nodeProperty, allOf: [values.nodeProperty] },
|
|
56
60
|
...json.definitions,
|
|
57
61
|
...values.definitions,
|
|
58
|
-
}).sort(
|
|
62
|
+
}).sort(byName));
|
|
59
63
|
const document = { ...root, allOf: [json.root] };
|
|
60
64
|
const positions = rulePositions({ ...document, $defs: definitions });
|
|
61
65
|
return {
|
|
@@ -63,8 +67,9 @@ export function domainSchemaJsonSchema() {
|
|
|
63
67
|
$id: 'https://schemas.astrale.ai/dsl/v1/domain-schema',
|
|
64
68
|
title: 'V1 DomainSchema',
|
|
65
69
|
$comment: 'Generated from the structure the Kernel enforces; value schemas are in the dialect https://schemas.astrale.ai/dsl/v1/value-schema. Each check JSON Schema cannot state is named under x-astrale-rules, with its stage and the positions it constrains.',
|
|
66
|
-
'x-astrale-rules': Object.fromEntries(Object.
|
|
67
|
-
|
|
70
|
+
'x-astrale-rules': Object.fromEntries(Object.entries(namedRules)
|
|
71
|
+
.sort(byName)
|
|
72
|
+
.map(([name, { statement, ...rule }]) => {
|
|
68
73
|
const named = { ...rule, stage: stageOf(rule), statement };
|
|
69
74
|
return [name, { ...named, positions: positions.get(name) ?? [] }];
|
|
70
75
|
})),
|
|
@@ -168,8 +173,11 @@ function rulePositions(document) {
|
|
|
168
173
|
const schema = value;
|
|
169
174
|
const rules = schema['x-astrale-rule'];
|
|
170
175
|
if (rules !== undefined) {
|
|
171
|
-
for (const rule of [rules].flat())
|
|
176
|
+
for (const rule of [rules].flat()) {
|
|
177
|
+
if (!isNamedRule(rule))
|
|
178
|
+
throw new Error(`The marker ${String(rule)} names no rule.`);
|
|
172
179
|
note(rule, pointer);
|
|
180
|
+
}
|
|
173
181
|
delete schema['x-astrale-rule'];
|
|
174
182
|
}
|
|
175
183
|
if (typeof schema.maxLength === 'number')
|
|
@@ -181,3 +189,9 @@ function rulePositions(document) {
|
|
|
181
189
|
visit(document, '');
|
|
182
190
|
return positions;
|
|
183
191
|
}
|
|
192
|
+
function isNamedRule(rule) {
|
|
193
|
+
return typeof rule === 'string' && Object.hasOwn(namedRules, rule);
|
|
194
|
+
}
|
|
195
|
+
function byName([left], [right]) {
|
|
196
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
197
|
+
}
|