@astrale-os/kernel-dsl 1.0.0-beta.24 → 1.0.0-beta.26
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 +0 -3
- package/dist/v1/builder/lowering/policy.js +4 -24
- package/dist/v1/builder/lowering/schema/context.js +0 -3
- package/dist/v1/builder/lowering/value/compile.js +24 -21
- package/dist/v1/builder/lowering/value/zod.js +10 -4
- package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
- package/dist/v1/bundle/codec.js +50 -67
- package/dist/v1/bundle/diagnostic.d.ts +1 -1
- package/dist/v1/bundle/structure.js +2 -2
- package/dist/v1/compiled/admission/accept.js +6 -6
- package/dist/v1/compiled/admission/closure.js +16 -33
- package/dist/v1/compiled/admission/diagnostic.d.ts +8 -0
- package/dist/v1/compiled/admission/diagnostic.js +33 -0
- package/dist/v1/compiled/admission/semantics/class.js +11 -7
- package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
- package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
- package/dist/v1/compiled/admission/wire/callable.js +13 -19
- package/dist/v1/compiled/admission/wire/class.js +6 -9
- package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
- package/dist/v1/compiled/admission/wire/entry.js +8 -13
- package/dist/v1/compiled/admission/wire/policy.js +4 -3
- package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
- package/dist/v1/compiled/admission/wire/program.js +39 -44
- package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
- package/dist/v1/compiled/admission/wire/property.js +8 -5
- package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
- package/dist/v1/compiled/admission/wire/value.js +0 -7
- package/dist/v1/compiled/codec/json.js +4 -3
- package/dist/v1/compiled/compiler/compile.js +10 -29
- package/dist/v1/compiled/diagnostic.d.ts +1 -1
- package/dist/v1/compiled/loader/load.js +2 -7
- package/dist/v1/domain/model/input.d.ts +2 -2
- package/dist/v1/domain/validation/create.d.ts +3 -1
- package/dist/v1/domain/validation/create.js +13 -8
- package/dist/v1/language/callable/resolved.d.ts +3 -3
- package/dist/v1/language/chain.d.ts +7 -0
- package/dist/v1/language/chain.js +24 -0
- package/dist/v1/language/class/inheritance.js +0 -2
- package/dist/v1/language/cycle.d.ts +10 -0
- package/dist/v1/language/cycle.js +30 -0
- package/dist/v1/language/limits.d.ts +19 -0
- package/dist/v1/language/limits.js +17 -0
- package/dist/v1/language/policy/analysis/budgets.js +17 -13
- package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
- package/dist/v1/language/policy/analysis/composition.js +11 -0
- package/dist/v1/language/suspended.d.ts +7 -0
- package/dist/v1/language/suspended.js +23 -0
- package/dist/v1/language/value/compile/fields.js +12 -8
- package/dist/v1/language/value/compile/load.d.ts +5 -0
- package/dist/v1/language/value/compile/load.js +13 -0
- package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
- package/dist/v1/language/value/evaluate/assertions.js +49 -8
- package/dist/v1/language/value/evaluate/evaluator.js +107 -105
- package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
- package/dist/v1/language/value/evaluate/preparation.js +100 -47
- package/dist/v1/language/value/evaluate/program.d.ts +2 -2
- package/dist/v1/language/value/evaluate/program.js +5 -5
- package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
- package/dist/v1/language/value/evaluate/validate.js +9 -9
- package/dist/v1/language/value/evaluate/validity.optimization.js +4 -3
- package/dist/v1/language/value/inclusion/assertions.js +7 -8
- package/dist/v1/language/value/inclusion/equivalence.js +4 -2
- package/dist/v1/language/value/inclusion/evidence.js +2 -2
- package/dist/v1/language/value/inclusion/includes.d.ts +13 -4
- package/dist/v1/language/value/inclusion/includes.js +34 -5
- package/dist/v1/language/value/inclusion/location.js +10 -7
- package/dist/v1/language/value/ordering.js +62 -70
- package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
- package/dist/v1/language/value/profile/canonicalize.js +64 -83
- package/dist/v1/language/value/profile/json.validate.d.ts +13 -3
- package/dist/v1/language/value/profile/json.validate.js +18 -6
- package/dist/v1/language/value/reference/closure.js +3 -2
- package/dist/v1/language/value/reference/recursion.js +7 -26
- package/dist/v1/language/value/reference/references.d.ts +3 -1
- package/dist/v1/language/value/reference/references.js +7 -7
- package/dist/v1/language/value/syntax/walk.d.ts +5 -0
- package/dist/v1/language/value/syntax/walk.js +14 -0
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +1 -1
- package/dist/v1/schema/admission/accept.d.ts +3 -1
- package/dist/v1/schema/admission/accept.js +4 -1
- package/dist/v1/schema/analysis/class.d.ts +4 -0
- package/dist/v1/schema/analysis/class.js +24 -2
- package/dist/v1/schema/canonical/revision.d.ts +4 -1
- package/dist/v1/schema/canonical/revision.js +4 -1
- package/dist/v1/schema/compatibility/comparators/classes.js +22 -22
- package/dist/v1/schema/compatibility/context.d.ts +5 -2
- package/dist/v1/schema/compatibility/context.js +8 -6
- package/dist/v1/schema/compatibility/meaning/footprint.js +1 -2
- package/dist/v1/schema/compatibility/model.d.ts +1 -1
- package/dist/v1/schema/compatibility/references.d.ts +0 -3
- package/dist/v1/schema/compatibility/references.js +1 -9
- package/dist/v1/schema/compatibility/structure/requirements.js +4 -6
- package/dist/v1/schema/compatibility/walk.js +2 -2
- package/dist/v1/schema/diagnostic.d.ts +1 -1
- package/dist/v1/schema/normalization/domain.js +8 -4
- package/dist/v1/schema/resolution/context.js +6 -7
- package/dist/v1/schema/resolution/domain.js +3 -11
- package/dist/v1/schema/rule.js +10 -3
- package/dist/v1/schema/validation/class.js +1 -1
- package/dist/v1/schema/validation/core.js +16 -8
- package/dist/v1/schema/validation/domain.js +20 -3
- package/dist/v1/schema/validation/policy/budgets.d.ts +5 -1
- package/dist/v1/schema/validation/policy/budgets.js +8 -1
- package/dist/v1/schema/validation/policy/references.js +5 -25
- package/dist/value/accept.d.ts +3 -3
- package/dist/value/canonical.js +2 -2
- package/dist/value/equal.d.ts +9 -1
- package/dist/value/equal.js +37 -3
- package/dist/value/index.d.ts +1 -1
- package/dist/value/limits.d.ts +11 -0
- package/package.json +1 -1
- package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
- package/dist/v1/compiled/admission/wire/pattern.js +0 -111
|
@@ -2,5 +2,8 @@ import { type Value as JsonValue, type Object as JsonObject } from '@astrale-os/
|
|
|
2
2
|
import { type ValueProgram, type CompiledFunction } from '../../model/schema.js';
|
|
3
3
|
/** Decode one Function declaration and its callable contract. */
|
|
4
4
|
export declare function compiledFunction(input: JsonValue, values: readonly ValueProgram[], path: string): CompiledFunction;
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Check the shared Function and Method wire grammar and return the Callable with the fields its input
|
|
7
|
+
* derives. The revision leaves fields out, so the received ones are not read.
|
|
8
|
+
*/
|
|
9
|
+
export declare function compiledCallable(input: JsonValue, values: readonly ValueProgram[], method: boolean, path: string): JsonObject;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import {} from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import { isAdmissionMaxAge } from '../../../language/callable/admission.js';
|
|
3
|
+
import { inputFieldNodes } from '../../../language/value/compile/fields.js';
|
|
3
4
|
import {} from '../../model/schema.js';
|
|
4
|
-
import { invalid
|
|
5
|
+
import { invalid } from '../diagnostic.js';
|
|
5
6
|
import { callablePolicy } from './policy.js';
|
|
6
7
|
import { definitionRef } from './reference.js';
|
|
7
|
-
import { object, exact, memberName, boolean, description, index, integer
|
|
8
|
+
import { object, exact, memberName, boolean, description, index, integer } from './value.js';
|
|
8
9
|
/** Decode one Function declaration and its callable contract. */
|
|
9
10
|
export function compiledFunction(input, values, path) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return value;
|
|
11
|
+
const callable = compiledCallable(input, values, false, path);
|
|
12
|
+
definitionRef(callable.ref, 'function', 'Function ref', `${path}/ref`);
|
|
13
|
+
return callable;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Check the shared Function and Method wire grammar and return the Callable with the fields its input
|
|
17
|
+
* derives. The revision leaves fields out, so the received ones are not read.
|
|
18
|
+
*/
|
|
16
19
|
export function compiledCallable(input, values, method, path) {
|
|
17
20
|
const value = object(input, 'Compiled Callable', path);
|
|
18
21
|
exact(value, method
|
|
@@ -48,18 +51,6 @@ export function compiledCallable(input, values, method, path) {
|
|
|
48
51
|
else {
|
|
49
52
|
inputIndex = index(value.input, values.length, 'Callable input', `${path}/input`);
|
|
50
53
|
}
|
|
51
|
-
if (value.fields !== undefined) {
|
|
52
|
-
const fieldsPath = `${path}/fields`;
|
|
53
|
-
for (const [field, nodes] of Object.entries(object(value.fields, 'Callable fields', fieldsPath))) {
|
|
54
|
-
const fieldPath = pointer(fieldsPath, field);
|
|
55
|
-
const fieldNodes = array(nodes, 'Callable field nodes', fieldPath);
|
|
56
|
-
if (fieldNodes.length === 0)
|
|
57
|
-
invalid('Callable field nodes', undefined, fieldPath);
|
|
58
|
-
for (const [indexValue, node] of fieldNodes.entries()) {
|
|
59
|
-
index(node, values[inputIndex].nodes.length, 'Callable field', `${fieldPath}/${indexValue}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
54
|
const outputPath = `${path}/output`;
|
|
64
55
|
const output = object(value.output, 'Callable output', outputPath);
|
|
65
56
|
if (output.mode === 'binary')
|
|
@@ -97,4 +88,7 @@ export function compiledCallable(input, values, method, path) {
|
|
|
97
88
|
invalid('Callable admission age', 'COMPILED_SOURCE_INVALID', `${admissionPath}/maxAge`);
|
|
98
89
|
}
|
|
99
90
|
}
|
|
91
|
+
const { fields: _, ...declared } = value;
|
|
92
|
+
const fields = inputFieldNodes(values[inputIndex]);
|
|
93
|
+
return fields === undefined ? declared : { ...declared, fields };
|
|
100
94
|
}
|
|
@@ -9,7 +9,7 @@ import { compiledCallable } from './callable.js';
|
|
|
9
9
|
import { classRuleChecks } from './policy.js';
|
|
10
10
|
import { compiledProperty } from './property.js';
|
|
11
11
|
import { definitionRef } from './reference.js';
|
|
12
|
-
import { object, exact, boolean, description, array, unique, boundedString,
|
|
12
|
+
import { object, exact, boolean, description, array, unique, boundedString, memberName, } from './value.js';
|
|
13
13
|
/** Decode one Node or Edge Class with its declared members. */
|
|
14
14
|
export function compiledClass(input, values, path) {
|
|
15
15
|
const value = object(input, 'Compiled Class', path);
|
|
@@ -51,15 +51,12 @@ export function compiledClass(input, values, path) {
|
|
|
51
51
|
if (value.unique !== undefined)
|
|
52
52
|
nodeUniqueTuples(value.unique, `${path}/unique`);
|
|
53
53
|
const methodsPath = `${path}/methods`;
|
|
54
|
-
const methods = array(value.methods, 'Class methods', methodsPath);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
unique(methods.map((method, index) => string(object(method, 'Compiled Method', `${methodsPath}/${index}`).name, 'Method name', `${methodsPath}/${index}/name`)), 'Class Methods', methodsPath);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
classPolicies(value.policies, 'edge', `${path}/policies`);
|
|
61
|
-
edgeContract(value, path);
|
|
54
|
+
const methods = array(value.methods, 'Class methods', methodsPath).map((method, index) => compiledCallable(method, values, true, `${methodsPath}/${index}`));
|
|
55
|
+
unique(methods.map((method) => method.name), 'Class Methods', methodsPath);
|
|
56
|
+
return { ...value, properties, methods };
|
|
62
57
|
}
|
|
58
|
+
classPolicies(value.policies, 'edge', `${path}/policies`);
|
|
59
|
+
edgeContract(value, path);
|
|
63
60
|
return { ...value, properties };
|
|
64
61
|
}
|
|
65
62
|
function classPolicies(input, kind, path) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import { type CompiledSchemaEntry } from '../../model/schema.js';
|
|
3
|
-
import { type Machines } from './
|
|
3
|
+
import { type Machines } from './program.js';
|
|
4
4
|
/** Decode one closure entry and verify its exact semantic revision. */
|
|
5
5
|
export declare function entry(input: JsonValue, entryIndex: number, path: string, machines: Machines): CompiledSchemaEntry;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {} from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import {} from '../../../addressing/index.js';
|
|
3
3
|
import * as metadata from '../../../language/definition/metadata.js';
|
|
4
|
-
import {
|
|
4
|
+
import { indexValuePrograms } from '../../../language/value/compile/load.js';
|
|
5
5
|
import {} from '../../model/schema.js';
|
|
6
|
-
import { invalid, pointer } from '../diagnostic.js';
|
|
6
|
+
import { invalid, pointer, withinEncodingLimits } from '../diagnostic.js';
|
|
7
7
|
import { revisionOfCompiledEntry } from '../revision.js';
|
|
8
8
|
import { compiledFunction } from './callable.js';
|
|
9
9
|
import { compiledClass } from './class.js';
|
|
10
10
|
import { compiledCoreDefinition, compiledCoreEdge } from './core.js';
|
|
11
11
|
import { originValue, revisionValue, dependencyMap } from './dependency.js';
|
|
12
|
-
import { pattern } from './pattern.js';
|
|
13
12
|
import { compiledPolicy } from './policy.js';
|
|
14
13
|
import { program } from './program.js';
|
|
15
14
|
import { definitionRef } from './reference.js';
|
|
@@ -18,7 +17,7 @@ import { compiledView } from './view.js';
|
|
|
18
17
|
/** Decode one closure entry and verify its exact semantic revision. */
|
|
19
18
|
export function entry(input, entryIndex, path, machines) {
|
|
20
19
|
const value = object(input, `closure[${entryIndex}]`, path);
|
|
21
|
-
exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'
|
|
20
|
+
exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path, ['entrypoint', 'patterns']);
|
|
22
21
|
const origin = originValue(value.origin, 'entry origin', `${path}/origin`);
|
|
23
22
|
const name = string(value.name, 'entry name', `${path}/name`);
|
|
24
23
|
if (name.length < metadata.name.minLength ||
|
|
@@ -38,17 +37,14 @@ export function entry(input, entryIndex, path, machines) {
|
|
|
38
37
|
dependencyOrigins.add(dependency.origin);
|
|
39
38
|
}
|
|
40
39
|
const valuesPath = `${path}/values`;
|
|
41
|
-
const
|
|
42
|
-
const patterns = array(value.patterns, 'entry patterns', patternsPath).map((item, index) => pattern(item, index, `${patternsPath}/${index}`, machines));
|
|
43
|
-
const values = array(value.values, 'values', valuesPath).map((item, index) => program(item, index, `${valuesPath}/${index}`, patterns));
|
|
44
|
-
const bound = values.map((value) => bindValueProgram(value, patterns));
|
|
40
|
+
const programs = array(value.values, 'values', valuesPath).map((item, index) => program(item, index, `${valuesPath}/${index}`, machines));
|
|
45
41
|
const definitionsPath = `${path}/definitions`;
|
|
46
42
|
const definitions = object(value.definitions, 'definitions', definitionsPath);
|
|
47
43
|
exact(definitions, ['classes', 'functions', 'policies', 'views', 'core'], 'definitions', definitionsPath);
|
|
48
44
|
const classesPath = `${definitionsPath}/classes`;
|
|
49
|
-
const classes = array(definitions.classes, 'classes', classesPath).map((item, index) => compiledClass(item,
|
|
45
|
+
const classes = array(definitions.classes, 'classes', classesPath).map((item, index) => compiledClass(item, programs, `${classesPath}/${index}`));
|
|
50
46
|
const functionsPath = `${definitionsPath}/functions`;
|
|
51
|
-
const functions = array(definitions.functions, 'functions', functionsPath).map((item, index) => compiledFunction(item,
|
|
47
|
+
const functions = array(definitions.functions, 'functions', functionsPath).map((item, index) => compiledFunction(item, programs, `${functionsPath}/${index}`));
|
|
52
48
|
const factsPath = `${path}/facts`;
|
|
53
49
|
const facts = object(value.facts, 'facts', factsPath);
|
|
54
50
|
exact(facts, ['core'], 'facts', factsPath);
|
|
@@ -72,8 +68,7 @@ export function entry(input, entryIndex, path, machines) {
|
|
|
72
68
|
facts: {
|
|
73
69
|
core: array(facts.core, 'core facts', coreFactsPath).map((item, index) => compiledCoreEdge(item, `${coreFactsPath}/${index}`)),
|
|
74
70
|
},
|
|
75
|
-
|
|
76
|
-
patterns,
|
|
71
|
+
...indexValuePrograms(programs),
|
|
77
72
|
};
|
|
78
73
|
const collections = [
|
|
79
74
|
['classes', accepted.definitions.classes],
|
|
@@ -93,7 +88,7 @@ export function entry(input, entryIndex, path, machines) {
|
|
|
93
88
|
!accepted.definitions.views.some(({ ref, target }) => ref.name === entrypoint.name && target.kind === 'domain'))) {
|
|
94
89
|
invalid('entry entrypoint', undefined, `${path}/entrypoint`);
|
|
95
90
|
}
|
|
96
|
-
if (revisionOfCompiledEntry(accepted) !== revision) {
|
|
91
|
+
if (withinEncodingLimits(path, () => revisionOfCompiledEntry(accepted)) !== revision) {
|
|
97
92
|
invalid('entry revision', 'COMPILED_CANONICAL_MISMATCH', `${path}/revision`);
|
|
98
93
|
}
|
|
99
94
|
return accepted;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { equal } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import { Key } from '../../../addressing/index.js';
|
|
3
3
|
import { normalizeClassRule } from '../../../language/policy/normalization/normalize.js';
|
|
4
4
|
import { invalid, pointer } from '../diagnostic.js';
|
|
@@ -136,9 +136,10 @@ export function callablePolicy(input, path) {
|
|
|
136
136
|
*/
|
|
137
137
|
export function classRuleChecks(input, path, site) {
|
|
138
138
|
policyCheck(input, 0, path, site);
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
139
|
+
const normalized = normalizeClassRule(input);
|
|
140
|
+
if (!equal(normalized, input)) {
|
|
141
141
|
invalid('Class rule spelling', undefined, path);
|
|
142
|
+
}
|
|
142
143
|
}
|
|
143
144
|
/** What a site calls its checks in a refusal. */
|
|
144
145
|
const SITE = { callable: 'Callable Policy', class: 'Class rule', create: 'Create rule' };
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
|
|
2
|
-
import { type Pattern, type RunPattern, type
|
|
3
|
-
/**
|
|
4
|
-
export
|
|
2
|
+
import { type Pattern, type RunPattern, type ValueProgram } from '../../model/schema.js';
|
|
3
|
+
/** The machine compiled from each admitted I-Regexp source, shared by its occurrences. */
|
|
4
|
+
export type Machines = Map<string, Pattern | RunPattern>;
|
|
5
|
+
/**
|
|
6
|
+
* Read a value program as its root schema, the one node the revision covers. JSON gives its members
|
|
7
|
+
* no order, so they are put back in the order the compiler walks. Its graph and its machines are what
|
|
8
|
+
* that schema derives, with the derivation the compiler emits them from. The rest of a received
|
|
9
|
+
* program, and the pattern table of its entry, may come from another compiler, from a host with other
|
|
10
|
+
* Unicode data, or from a forger, and the artifact carries no compiler version that could tell those
|
|
11
|
+
* apart, so they are ignored rather than compared. Generated material executes them without this
|
|
12
|
+
* admission.
|
|
13
|
+
*/
|
|
14
|
+
export declare function program(input: JsonValue, programIndex: number, path: string, machines: Machines): ValueProgram;
|
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
import {} from '@astrale-os/kernel-dsl/value';
|
|
2
|
-
import {
|
|
2
|
+
import { deriveValueGraph } from '../../../language/value/evaluate/preparation.js';
|
|
3
|
+
import { canonicalizeSchemaMembers } from '../../../language/value/profile/canonicalize.js';
|
|
4
|
+
import { compilePattern } from '../../../language/value/regexp/compile.js';
|
|
5
|
+
import { isIRegexp } from '../../../language/value/regexp/syntax.js';
|
|
6
|
+
import { isJsonSchema } from '../../../language/value/syntax/walk.js';
|
|
3
7
|
import {} from '../../model/schema.js';
|
|
4
|
-
import {
|
|
5
|
-
import { object,
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
+
import { fail, invalid } from '../diagnostic.js';
|
|
9
|
+
import { object, array, index } from './value.js';
|
|
10
|
+
/**
|
|
11
|
+
* Read a value program as its root schema, the one node the revision covers. JSON gives its members
|
|
12
|
+
* no order, so they are put back in the order the compiler walks. Its graph and its machines are what
|
|
13
|
+
* that schema derives, with the derivation the compiler emits them from. The rest of a received
|
|
14
|
+
* program, and the pattern table of its entry, may come from another compiler, from a host with other
|
|
15
|
+
* Unicode data, or from a forger, and the artifact carries no compiler version that could tell those
|
|
16
|
+
* apart, so they are ignored rather than compared. Generated material executes them without this
|
|
17
|
+
* admission.
|
|
18
|
+
*/
|
|
19
|
+
export function program(input, programIndex, path, machines) {
|
|
8
20
|
const value = object(input, `values[${programIndex}]`, path);
|
|
9
|
-
exact(value, ['root', 'nodes', 'patterns'], 'ValueProgram', path);
|
|
10
21
|
const nodesPath = `${path}/nodes`;
|
|
11
|
-
const nodes = array(value.nodes, 'ValueProgram nodes', nodesPath)
|
|
22
|
+
const nodes = array(value.nodes, 'ValueProgram nodes', nodesPath);
|
|
12
23
|
const root = index(value.root, nodes.length, 'ValueProgram root', `${path}/root`);
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (isValueObject(node.schema.patternProperties)) {
|
|
22
|
-
required.push(...Object.keys(node.schema.patternProperties));
|
|
23
|
-
}
|
|
24
|
-
for (const source of required) {
|
|
25
|
-
if (typeof source === 'string' && !available.has(source)) {
|
|
26
|
-
invalid('ValueProgram pattern binding', undefined, patternsPath);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const [name, child] of Object.entries(node.children))
|
|
31
|
-
index(child, nodes.length, 'ValueNode child', pointer(`${nodesPath}/${nodeIndex}/children`, name));
|
|
32
|
-
if (node.reference !== undefined)
|
|
33
|
-
index(node.reference, nodes.length, 'ValueNode reference', `${nodesPath}/${nodeIndex}/reference`);
|
|
34
|
-
}
|
|
35
|
-
return { root, nodes, patterns };
|
|
36
|
-
}
|
|
37
|
-
function valueNode(input, nodeIndex, path) {
|
|
38
|
-
const value = object(input, `nodes[${nodeIndex}]`, path);
|
|
39
|
-
exact(value, ['schema', 'children'], 'ValueNode', path, ['reference']);
|
|
40
|
-
const children = {};
|
|
41
|
-
const childrenPath = `${path}/children`;
|
|
42
|
-
for (const [name, child] of Object.entries(object(value.children, 'ValueNode children', childrenPath))) {
|
|
43
|
-
children[name] = integer(child, 'ValueNode child', pointer(childrenPath, name));
|
|
44
|
-
}
|
|
24
|
+
const rootPath = `${nodesPath}/${root}`;
|
|
25
|
+
const { schema } = object(nodes[root], `nodes[${root}]`, rootPath);
|
|
26
|
+
const schemaPath = `${rootPath}/schema`;
|
|
27
|
+
if (!isJsonSchema(schema))
|
|
28
|
+
invalid('ValueNode schema', undefined, schemaPath);
|
|
29
|
+
const derivation = deriveValueGraph(canonicalizeSchemaMembers(schema), schemaPath);
|
|
30
|
+
if ('refusal' in derivation)
|
|
31
|
+
fail(derivation.refusal.pointer, derivation.refusal.message);
|
|
45
32
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
...(value.reference === undefined
|
|
49
|
-
? {}
|
|
50
|
-
: { reference: integer(value.reference, 'reference', `${path}/reference`) }),
|
|
33
|
+
...derivation.graph,
|
|
34
|
+
patterns: derivation.sources.map((source) => machine(source, schemaPath, machines)),
|
|
51
35
|
};
|
|
52
36
|
}
|
|
37
|
+
/** The machine of one source, by the same bounded rules as source resolution. */
|
|
38
|
+
function machine(source, path, machines) {
|
|
39
|
+
let compiled = machines.get(source);
|
|
40
|
+
if (compiled === undefined) {
|
|
41
|
+
if (!isIRegexp(source))
|
|
42
|
+
invalid('Pattern source', 'COMPILED_SOURCE_INVALID', path);
|
|
43
|
+
compiled = compilePattern(source);
|
|
44
|
+
machines.set(source, compiled);
|
|
45
|
+
}
|
|
46
|
+
return compiled;
|
|
47
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import { type ValueProgram, type CompiledClass } from '../../model/schema.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Decode a Property, re-admit its State contract and return it with the ordering its value derives.
|
|
5
|
+
* The revision leaves ordering out, so the received one is not read.
|
|
6
|
+
*/
|
|
4
7
|
export declare function compiledProperty(input: JsonValue, values: readonly ValueProgram[], node: boolean, path: string): CompiledClass['properties'][number];
|
|
@@ -5,7 +5,10 @@ import { classifyValueProgramOrdering } from '../../../language/value/ordering.j
|
|
|
5
5
|
import {} from '../../model/schema.js';
|
|
6
6
|
import { invalid } from '../diagnostic.js';
|
|
7
7
|
import { object, exact, memberName, boolean, description, index, array, unique } from './value.js';
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Decode a Property, re-admit its State contract and return it with the ordering its value derives.
|
|
10
|
+
* The revision leaves ordering out, so the received one is not read.
|
|
11
|
+
*/
|
|
9
12
|
export function compiledProperty(input, values, node, path) {
|
|
10
13
|
const value = object(input, 'Compiled Property', path);
|
|
11
14
|
exact(value, ['name', 'required', 'value'], 'Compiled Property', path, [
|
|
@@ -52,12 +55,12 @@ export function compiledProperty(input, values, node, path) {
|
|
|
52
55
|
}
|
|
53
56
|
state = topology;
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
+
const { ordering: _, ...declared } = value;
|
|
59
|
+
const ordering = classifyValueProgramOrdering(values[valueIndex]);
|
|
58
60
|
return {
|
|
59
|
-
...
|
|
61
|
+
...declared,
|
|
60
62
|
...(state === undefined ? {} : { state }),
|
|
63
|
+
...(ordering === undefined ? {} : { ordering }),
|
|
61
64
|
};
|
|
62
65
|
}
|
|
63
66
|
function propertyAuto(input, path) {
|
|
@@ -23,7 +23,5 @@ export declare function description(input: JsonValue | undefined, label: string,
|
|
|
23
23
|
export declare function unique(values: readonly string[], label: string, path: string): void;
|
|
24
24
|
/** Require an index within the referenced table. */
|
|
25
25
|
export declare function index(input: JsonValue | undefined, length: number, label: string, path: string): number;
|
|
26
|
-
/** Require a Unicode scalar-range bound. */
|
|
27
|
-
export declare function scalar(input: JsonValue | undefined, label: string, path: string): number;
|
|
28
26
|
/** Order wire names independently of the host locale. */
|
|
29
27
|
export declare function compare(left: string, right: string): number;
|
|
@@ -85,13 +85,6 @@ export function index(input, length, label, path) {
|
|
|
85
85
|
invalid(label, undefined, path);
|
|
86
86
|
return value;
|
|
87
87
|
}
|
|
88
|
-
/** Require a Unicode scalar-range bound. */
|
|
89
|
-
export function scalar(input, label, path) {
|
|
90
|
-
const value = integer(input, label, path);
|
|
91
|
-
if (value > 0x10ffff)
|
|
92
|
-
invalid(label, undefined, path);
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
88
|
/** Order wire names independently of the host locale. */
|
|
96
89
|
export function compare(left, right) {
|
|
97
90
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { json } from '@astrale-os/kernel-dsl/value';
|
|
2
|
+
import { closureDocument } from '../../language/limits.js';
|
|
2
3
|
import { acceptCompiledSchema } from '../admission/accept.js';
|
|
4
|
+
import { compiledDocument } from '../admission/diagnostic.js';
|
|
3
5
|
export function encode(schema) {
|
|
4
|
-
return
|
|
6
|
+
return compiledDocument(() => json.encode(schema, closureDocument));
|
|
5
7
|
}
|
|
6
8
|
export function decode(input) {
|
|
7
|
-
|
|
8
|
-
return acceptCompiledSchema(json.decode(text));
|
|
9
|
+
return acceptCompiledSchema(compiledDocument(() => json.decode(input, closureDocument)));
|
|
9
10
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { compareCodeUnits } from '../../addressing/ordering.js';
|
|
2
2
|
import { isBinaryInput } from '../../language/callable/model/callable.js';
|
|
3
3
|
import { inputFieldNodes } from '../../language/value/compile/fields.js';
|
|
4
|
+
import { indexValuePrograms } from '../../language/value/compile/load.js';
|
|
4
5
|
import { prepareValueSchema } from '../../language/value/evaluate/preparation.js';
|
|
5
6
|
import { classifyPreparedOrdering } from '../../language/value/ordering.js';
|
|
6
7
|
import { revisionOfDomainSchema } from '../../schema/canonical/revision.js';
|
|
@@ -25,30 +26,17 @@ export function compile(schema) {
|
|
|
25
26
|
}
|
|
26
27
|
function compileEntry(schema, lookup) {
|
|
27
28
|
const registry = createDomainValueSchemaRegistry(schema, lookup);
|
|
28
|
-
const
|
|
29
|
+
const programs = [];
|
|
29
30
|
const pool = new Map();
|
|
30
|
-
const patternIndices = new Map();
|
|
31
31
|
const prepare = (contract, pointer) => {
|
|
32
32
|
const result = prepareValueSchema(contract, registry, pointer, pool);
|
|
33
33
|
if (!result.compiled)
|
|
34
34
|
throw new TypeError(`Cannot compile ValueSchema: ${result.message}`);
|
|
35
35
|
return result.value;
|
|
36
36
|
};
|
|
37
|
-
const addProgram = (program) =>
|
|
38
|
-
const patterns = program.patterns.map((pattern) => {
|
|
39
|
-
let index = patternIndices.get(pattern);
|
|
40
|
-
if (index === undefined) {
|
|
41
|
-
index = patternIndices.size;
|
|
42
|
-
patternIndices.set(pattern, index);
|
|
43
|
-
}
|
|
44
|
-
return index;
|
|
45
|
-
});
|
|
46
|
-
return values.push(Object.freeze({ ...program, patterns: Object.freeze(patterns) })) - 1;
|
|
47
|
-
};
|
|
37
|
+
const addProgram = (program) => programs.push(program) - 1;
|
|
48
38
|
const add = (contract, pointer) => addProgram(prepare(contract, pointer).program());
|
|
49
|
-
const properties = (definition, pointer) => Object.entries(definition.properties)
|
|
50
|
-
.sort(([left], [right]) => compareCodeUnits(left, right))
|
|
51
|
-
.map(([name, property]) => {
|
|
39
|
+
const properties = (definition, pointer) => Object.entries(definition.properties).map(([name, property]) => {
|
|
52
40
|
const prepared = prepare(property.schema, `${pointer}/properties/${name}/schema`);
|
|
53
41
|
const ordering = classifyPreparedOrdering(prepared);
|
|
54
42
|
return {
|
|
@@ -68,20 +56,16 @@ function compileEntry(schema, lookup) {
|
|
|
68
56
|
mode: value.mode,
|
|
69
57
|
value: add(value.mode === 'value' ? value.schema : value.item, pointer),
|
|
70
58
|
};
|
|
71
|
-
const classes = Object.values(schema.classes)
|
|
72
|
-
.sort((left, right) => compareCodeUnits(left.ref.name, right.ref.name))
|
|
73
|
-
.map((definition) => {
|
|
59
|
+
const classes = Object.values(schema.classes).map((definition) => {
|
|
74
60
|
const pointer = `/classes/${definition.ref.name}`;
|
|
75
61
|
if (definition.kind === 'edge') {
|
|
76
62
|
const { properties: _, ...rest } = definition;
|
|
77
63
|
return { ...rest, properties: properties(definition, pointer) };
|
|
78
64
|
}
|
|
79
65
|
const { properties: _, methods: __, ...rest } = definition;
|
|
80
|
-
const methods = Object.entries(definition.methods)
|
|
81
|
-
.sort(([left], [right]) => compareCodeUnits(left, right))
|
|
82
|
-
.map(([name, method]) => {
|
|
66
|
+
const methods = Object.entries(definition.methods).map(([name, method]) => {
|
|
83
67
|
const input = add(method.input, `${pointer}/methods/${name}/input`);
|
|
84
|
-
const fields = inputFieldNodes(
|
|
68
|
+
const fields = inputFieldNodes(programs[input]);
|
|
85
69
|
return {
|
|
86
70
|
name,
|
|
87
71
|
auth: method.auth,
|
|
@@ -98,9 +82,7 @@ function compileEntry(schema, lookup) {
|
|
|
98
82
|
});
|
|
99
83
|
return { ...rest, properties: properties(definition, pointer), methods };
|
|
100
84
|
});
|
|
101
|
-
const functions = Object.values(schema.functions)
|
|
102
|
-
.sort((left, right) => compareCodeUnits(left.ref.name, right.ref.name))
|
|
103
|
-
.map((definition) => {
|
|
85
|
+
const functions = Object.values(schema.functions).map((definition) => {
|
|
104
86
|
const binary = isBinaryInput(definition.input);
|
|
105
87
|
const inputIndex = add(binary ? definition.input.metadata : definition.input, binary
|
|
106
88
|
? `/functions/${definition.ref.name}/input/metadata`
|
|
@@ -112,7 +94,7 @@ function compileEntry(schema, lookup) {
|
|
|
112
94
|
maximumBytes: definition.input.maximumBytes,
|
|
113
95
|
}
|
|
114
96
|
: inputIndex;
|
|
115
|
-
const fields = inputFieldNodes(
|
|
97
|
+
const fields = inputFieldNodes(programs[inputIndex]);
|
|
116
98
|
return {
|
|
117
99
|
ref: definition.ref,
|
|
118
100
|
auth: definition.auth,
|
|
@@ -139,7 +121,6 @@ function compileEntry(schema, lookup) {
|
|
|
139
121
|
core: Object.freeze(Object.values(schema.core.nodes)),
|
|
140
122
|
}),
|
|
141
123
|
facts: Object.freeze({ core: schema.core.edges }),
|
|
142
|
-
|
|
143
|
-
patterns: Object.freeze([...patternIndices.keys()]),
|
|
124
|
+
...indexValuePrograms(programs),
|
|
144
125
|
});
|
|
145
126
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CompiledDiagnosticCode = 'COMPILED_CANONICAL_MISMATCH' | '
|
|
1
|
+
export type CompiledDiagnosticCode = 'COMPILED_CANONICAL_MISMATCH' | 'COMPILED_DEPENDENCY_LIMITS' | 'COMPILED_SOURCE_INVALID' | 'COMPILED_STRUCTURE_INVALID';
|
|
2
2
|
export interface CompiledDiagnostic<out Code extends CompiledDiagnosticCode = CompiledDiagnosticCode> {
|
|
3
3
|
readonly code: Code;
|
|
4
4
|
readonly pointer: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key, MethodKey, PropertyKey as PropertyKeyValue } from '../../addressing/index.js';
|
|
2
2
|
import { compareUnicode } from '../../addressing/ordering.js';
|
|
3
3
|
import { createDomain } from '../../domain/create.js';
|
|
4
|
-
import { createDomainValidation,
|
|
4
|
+
import { createDomainValidation, validateInputField } from '../../domain/validation/create.js';
|
|
5
5
|
import { bindValueProgram } from '../../language/value/compile/load.js';
|
|
6
6
|
import { validateValueProgram } from '../../language/value/evaluate/program.js';
|
|
7
7
|
import { acceptCompiledSchema } from '../admission/accept.js';
|
|
@@ -108,12 +108,7 @@ function programValidation(programs, properties, propertyOrdering, callables) {
|
|
|
108
108
|
? {}
|
|
109
109
|
: { fields: Object.freeze(Object.keys(callable.fields)) }),
|
|
110
110
|
validateInput: (value, options) => validateValueProgram(input, value, [input.root], options),
|
|
111
|
-
validateInputField(field, value)
|
|
112
|
-
const nodes = callable.fields?.[field];
|
|
113
|
-
return nodes === undefined
|
|
114
|
-
? unknownInputField(field)
|
|
115
|
-
: validateValueProgram(input, value, nodes);
|
|
116
|
-
},
|
|
111
|
+
validateInputField: (field, value) => validateInputField(input, callable.fields, field, value),
|
|
117
112
|
validateOutput: (value) => output === undefined ? [] : validateValueProgram(output, value),
|
|
118
113
|
}));
|
|
119
114
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StructuralOptions } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import type { Key as AddressKey, PropertyKey, Revision } from '../../addressing/index.js';
|
|
3
3
|
import type { DomainDependency, DomainDependencyMap } from '../../addressing/index.js';
|
|
4
4
|
import type { CoreEdge } from '../../language/core/model/core.js';
|
|
@@ -33,7 +33,7 @@ export interface PropertyValidation {
|
|
|
33
33
|
}
|
|
34
34
|
export interface CallableValidation {
|
|
35
35
|
readonly fields?: readonly string[];
|
|
36
|
-
validateInput(input: unknown, options?:
|
|
36
|
+
validateInput(input: unknown, options?: StructuralOptions): readonly Diagnostic[];
|
|
37
37
|
validateInputField(field: string, input: unknown): readonly Diagnostic[];
|
|
38
38
|
validateOutput(output: unknown): readonly Diagnostic[];
|
|
39
39
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Key, PropertyKey } from '../../addressing/index.js';
|
|
2
2
|
import type { Diagnostic } from '../../language/validation/diagnostic.js';
|
|
3
|
+
import type { ValueProgram } from '../../language/value/compile/model.js';
|
|
3
4
|
import type { CallableValidation, DomainValidation, PropertyValidation } from '../model/input.js';
|
|
4
5
|
/**
|
|
5
6
|
* Build the one Domain-level router shared by source resolution and compiled loading. The Domain
|
|
6
7
|
* built from the same entries asks only for the Properties and Callables they declare.
|
|
7
8
|
*/
|
|
8
9
|
export declare function createDomainValidation(properties: ReadonlyMap<PropertyKey, PropertyValidation>, callables: ReadonlyMap<Key.Callable, CallableValidation>): DomainValidation;
|
|
9
|
-
|
|
10
|
+
/** Validate one input field against the nodes its input names it by: only its own names are fields. */
|
|
11
|
+
export declare function validateInputField(input: ValueProgram, fields: Readonly<Record<string, readonly number[]>> | undefined, field: string, value: unknown): readonly Diagnostic[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateValueProgram } from '../../language/value/evaluate/program.js';
|
|
1
2
|
/**
|
|
2
3
|
* Build the one Domain-level router shared by source resolution and compiled loading. The Domain
|
|
3
4
|
* built from the same entries asks only for the Properties and Callables they declare.
|
|
@@ -25,12 +26,16 @@ function absentCallable(key) {
|
|
|
25
26
|
validateOutput: absent,
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/** Validate one input field against the nodes its input names it by: only its own names are fields. */
|
|
30
|
+
export function validateInputField(input, fields, field, value) {
|
|
31
|
+
if (fields === undefined || !Object.hasOwn(fields, field)) {
|
|
32
|
+
return [
|
|
33
|
+
Object.freeze({
|
|
34
|
+
code: 'CALLABLE_INPUT_FIELD_UNKNOWN',
|
|
35
|
+
pointer: '',
|
|
36
|
+
message: `Input field ${field} is absent.`,
|
|
37
|
+
}),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
return validateValueProgram(input, value, fields[field]);
|
|
36
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StructuralOptions } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import type { DefinitionKey, FunctionRef, Key, MethodKey } from '../../addressing/index.js';
|
|
3
3
|
import type { ResolvedClass } from '../class/resolved.js';
|
|
4
4
|
import type { CallablePolicy } from '../policy/model/policy.js';
|
|
@@ -41,7 +41,7 @@ export interface ResolvedMethod<out Input = unknown, out Output = unknown, out S
|
|
|
41
41
|
* The issues of `input` against the callable's input schema, `options` overriding the portable
|
|
42
42
|
* limits it is admitted under: those it crossed the wire under, for a call's input.
|
|
43
43
|
*/
|
|
44
|
-
validateInput(input: unknown, options?:
|
|
44
|
+
validateInput(input: unknown, options?: StructuralOptions): readonly Diagnostic[];
|
|
45
45
|
validateInputField(field: string, input: unknown): readonly Diagnostic[];
|
|
46
46
|
validateOutput(output: unknown): readonly Diagnostic[];
|
|
47
47
|
readonly __input?: Input;
|
|
@@ -71,7 +71,7 @@ export interface ResolvedFunction<out Input = unknown, out Output = unknown, out
|
|
|
71
71
|
* The issues of `input` against the callable's input schema, `options` overriding the portable
|
|
72
72
|
* limits it is admitted under: those it crossed the wire under, for a call's input.
|
|
73
73
|
*/
|
|
74
|
-
validateInput(input: unknown, options?:
|
|
74
|
+
validateInput(input: unknown, options?: StructuralOptions): readonly Diagnostic[];
|
|
75
75
|
validateInputField(field: string, input: unknown): readonly Diagnostic[];
|
|
76
76
|
validateOutput(output: unknown): readonly Diagnostic[];
|
|
77
77
|
readonly __input?: Input;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many edges the longest chain from each node holds, for every node `nodes` reach: a direct
|
|
3
|
+
* target is at depth 1. A depth limit bounds how long a chain is and not how many chains share a
|
|
4
|
+
* node, so the walk reads each node once, and it holds its own stack. A node read again before its
|
|
5
|
+
* own chain ends sits on a cycle and adds nothing more, so a cycle counts once round.
|
|
6
|
+
*/
|
|
7
|
+
export declare function chainDepths<Node>(nodes: Iterable<Node>, targetsOf: (node: Node) => Iterable<Node>): ReadonlyMap<Node, number>;
|