@astrale-os/kernel-dsl 1.0.0-beta.23 → 1.0.0-beta.25

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.
Files changed (106) hide show
  1. package/dist/v1/builder/lowering/policy.js +4 -24
  2. package/dist/v1/builder/lowering/schema/context.js +0 -3
  3. package/dist/v1/builder/lowering/value/compile.js +24 -21
  4. package/dist/v1/builder/lowering/value/zod.js +10 -4
  5. package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
  6. package/dist/v1/bundle/codec.js +50 -67
  7. package/dist/v1/bundle/diagnostic.d.ts +1 -1
  8. package/dist/v1/bundle/structure.js +2 -2
  9. package/dist/v1/compiled/admission/accept.js +6 -6
  10. package/dist/v1/compiled/admission/closure.js +16 -33
  11. package/dist/v1/compiled/admission/diagnostic.d.ts +8 -0
  12. package/dist/v1/compiled/admission/diagnostic.js +33 -0
  13. package/dist/v1/compiled/admission/semantics/class.js +11 -7
  14. package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
  15. package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
  16. package/dist/v1/compiled/admission/wire/callable.js +13 -19
  17. package/dist/v1/compiled/admission/wire/class.js +6 -9
  18. package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
  19. package/dist/v1/compiled/admission/wire/entry.js +8 -13
  20. package/dist/v1/compiled/admission/wire/policy.js +4 -3
  21. package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
  22. package/dist/v1/compiled/admission/wire/program.js +39 -44
  23. package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
  24. package/dist/v1/compiled/admission/wire/property.js +8 -5
  25. package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
  26. package/dist/v1/compiled/admission/wire/value.js +0 -7
  27. package/dist/v1/compiled/codec/json.js +4 -3
  28. package/dist/v1/compiled/compiler/compile.js +6 -17
  29. package/dist/v1/compiled/diagnostic.d.ts +1 -1
  30. package/dist/v1/compiled/loader/load.js +2 -7
  31. package/dist/v1/domain/model/input.d.ts +2 -2
  32. package/dist/v1/domain/validation/create.d.ts +3 -1
  33. package/dist/v1/domain/validation/create.js +13 -8
  34. package/dist/v1/language/callable/resolved.d.ts +3 -3
  35. package/dist/v1/language/chain.d.ts +7 -0
  36. package/dist/v1/language/chain.js +24 -0
  37. package/dist/v1/language/cycle.d.ts +10 -0
  38. package/dist/v1/language/cycle.js +30 -0
  39. package/dist/v1/language/limits.d.ts +19 -0
  40. package/dist/v1/language/limits.js +17 -0
  41. package/dist/v1/language/policy/analysis/budgets.js +17 -13
  42. package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
  43. package/dist/v1/language/policy/analysis/composition.js +11 -0
  44. package/dist/v1/language/suspended.d.ts +7 -0
  45. package/dist/v1/language/suspended.js +23 -0
  46. package/dist/v1/language/value/compile/fields.js +12 -8
  47. package/dist/v1/language/value/compile/load.d.ts +5 -0
  48. package/dist/v1/language/value/compile/load.js +13 -0
  49. package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
  50. package/dist/v1/language/value/evaluate/assertions.js +49 -8
  51. package/dist/v1/language/value/evaluate/evaluator.js +107 -105
  52. package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
  53. package/dist/v1/language/value/evaluate/preparation.js +100 -47
  54. package/dist/v1/language/value/evaluate/program.d.ts +2 -2
  55. package/dist/v1/language/value/evaluate/program.js +5 -5
  56. package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
  57. package/dist/v1/language/value/evaluate/validate.js +9 -9
  58. package/dist/v1/language/value/evaluate/validity.optimization.js +4 -3
  59. package/dist/v1/language/value/inclusion/equivalence.js +4 -2
  60. package/dist/v1/language/value/inclusion/evidence.js +2 -2
  61. package/dist/v1/language/value/inclusion/includes.d.ts +13 -4
  62. package/dist/v1/language/value/inclusion/includes.js +34 -5
  63. package/dist/v1/language/value/inclusion/location.js +10 -7
  64. package/dist/v1/language/value/ordering.js +62 -70
  65. package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
  66. package/dist/v1/language/value/profile/canonicalize.js +64 -83
  67. package/dist/v1/language/value/profile/json.validate.d.ts +13 -3
  68. package/dist/v1/language/value/profile/json.validate.js +18 -6
  69. package/dist/v1/language/value/reference/closure.js +3 -2
  70. package/dist/v1/language/value/reference/recursion.js +7 -26
  71. package/dist/v1/language/value/reference/references.d.ts +3 -1
  72. package/dist/v1/language/value/reference/references.js +7 -7
  73. package/dist/v1/language/value/syntax/walk.d.ts +5 -0
  74. package/dist/v1/language/value/syntax/walk.js +14 -0
  75. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +1 -1
  76. package/dist/v1/schema/admission/accept.d.ts +3 -1
  77. package/dist/v1/schema/admission/accept.js +4 -1
  78. package/dist/v1/schema/analysis/class.d.ts +4 -0
  79. package/dist/v1/schema/analysis/class.js +24 -2
  80. package/dist/v1/schema/canonical/revision.d.ts +4 -1
  81. package/dist/v1/schema/canonical/revision.js +4 -1
  82. package/dist/v1/schema/compatibility/context.d.ts +5 -2
  83. package/dist/v1/schema/compatibility/context.js +8 -6
  84. package/dist/v1/schema/compatibility/model.d.ts +1 -1
  85. package/dist/v1/schema/compatibility/structure/requirements.js +2 -2
  86. package/dist/v1/schema/compatibility/walk.js +2 -2
  87. package/dist/v1/schema/diagnostic.d.ts +1 -1
  88. package/dist/v1/schema/normalization/domain.js +8 -4
  89. package/dist/v1/schema/resolution/context.js +6 -7
  90. package/dist/v1/schema/resolution/domain.js +3 -11
  91. package/dist/v1/schema/rule.js +10 -3
  92. package/dist/v1/schema/validation/class.js +1 -1
  93. package/dist/v1/schema/validation/core.js +16 -8
  94. package/dist/v1/schema/validation/domain.js +20 -3
  95. package/dist/v1/schema/validation/policy/budgets.d.ts +5 -1
  96. package/dist/v1/schema/validation/policy/budgets.js +8 -1
  97. package/dist/v1/schema/validation/policy/references.js +5 -25
  98. package/dist/value/accept.d.ts +3 -3
  99. package/dist/value/canonical.js +2 -2
  100. package/dist/value/equal.d.ts +9 -1
  101. package/dist/value/equal.js +37 -3
  102. package/dist/value/index.d.ts +1 -1
  103. package/dist/value/limits.d.ts +11 -0
  104. package/package.json +2 -2
  105. package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
  106. package/dist/v1/compiled/admission/wire/pattern.js +0 -111
@@ -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, pointer } from '../diagnostic.js';
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, array } from './value.js';
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 value = object(input, 'Compiled Function', path);
11
- compiledCallable(value, values, false, path);
12
- definitionRef(value.ref, 'function', 'Function ref', `${path}/ref`);
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
- /** Check the shared Function and Method wire grammar. */
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, string, memberName, } from './value.js';
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
- for (const [index, method] of methods.entries())
56
- compiledCallable(method, values, true, `${methodsPath}/${index}`);
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 './pattern.js';
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 { bindValueProgram } from '../../../language/value/compile/load.js';
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', 'patterns'], 'entry', path, ['entrypoint']);
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 patternsPath = `${path}/patterns`;
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, bound, `${classesPath}/${index}`));
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, bound, `${functionsPath}/${index}`));
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
- values,
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 { json } from '@astrale-os/kernel-dsl/value';
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 rule = input;
140
- if (json.serialize(normalizeClassRule(rule)) !== json.serialize(rule))
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 IndexedValueProgram } from '../../model/schema.js';
3
- /** Decode a value program and validate its local node and pattern indices. */
4
- export declare function program(input: JsonValue, programIndex: number, path: string, table: readonly (Pattern | RunPattern)[]): IndexedValueProgram;
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 { isValueObject } from '../../../language/value/model/object.js';
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 { invalid, pointer } from '../diagnostic.js';
5
- import { object, exact, array, index, unique, integer } from './value.js';
6
- /** Decode a value program and validate its local node and pattern indices. */
7
- export function program(input, programIndex, path, table) {
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).map((node, index) => valueNode(node, index, `${nodesPath}/${index}`));
22
+ const nodes = array(value.nodes, 'ValueProgram nodes', nodesPath);
12
23
  const root = index(value.root, nodes.length, 'ValueProgram root', `${path}/root`);
13
- const patternsPath = `${path}/patterns`;
14
- const patterns = array(value.patterns, 'ValueProgram patterns', patternsPath).map((item, position) => index(item, table.length, 'ValueProgram pattern', `${patternsPath}/${position}`));
15
- const sources = patterns.map((index) => table[index].source);
16
- unique(sources, 'patterns', patternsPath);
17
- const available = new Set(sources);
18
- for (const [nodeIndex, node] of nodes.entries()) {
19
- if (isValueObject(node.schema)) {
20
- const required = [node.schema.pattern, node.schema.fullMatch];
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
- schema: value.schema,
47
- children,
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
- /** Decode a Property and re-admit its State and ordering contracts. */
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
- /** Decode a Property and re-admit its State and ordering contracts. */
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
- if (value.ordering !== classifyValueProgramOrdering(values[valueIndex])) {
56
- invalid('Property ordering', 'COMPILED_CANONICAL_MISMATCH', `${path}/ordering`);
57
- }
58
+ const { ordering: _, ...declared } = value;
59
+ const ordering = classifyValueProgramOrdering(values[valueIndex]);
58
60
  return {
59
- ...value,
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 new TextEncoder().encode(json.serialize(schema));
6
+ return compiledDocument(() => json.encode(schema, closureDocument));
5
7
  }
6
8
  export function decode(input) {
7
- const text = typeof input === 'string' ? input : new TextDecoder().decode(input);
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,26 +26,15 @@ export function compile(schema) {
25
26
  }
26
27
  function compileEntry(schema, lookup) {
27
28
  const registry = createDomainValueSchemaRegistry(schema, lookup);
28
- const values = [];
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
39
  const properties = (definition, pointer) => Object.entries(definition.properties)
50
40
  .sort(([left], [right]) => compareCodeUnits(left, right))
@@ -81,7 +71,7 @@ function compileEntry(schema, lookup) {
81
71
  .sort(([left], [right]) => compareCodeUnits(left, right))
82
72
  .map(([name, method]) => {
83
73
  const input = add(method.input, `${pointer}/methods/${name}/input`);
84
- const fields = inputFieldNodes(values[input]);
74
+ const fields = inputFieldNodes(programs[input]);
85
75
  return {
86
76
  name,
87
77
  auth: method.auth,
@@ -112,7 +102,7 @@ function compileEntry(schema, lookup) {
112
102
  maximumBytes: definition.input.maximumBytes,
113
103
  }
114
104
  : inputIndex;
115
- const fields = inputFieldNodes(values[inputIndex]);
105
+ const fields = inputFieldNodes(programs[inputIndex]);
116
106
  return {
117
107
  ref: definition.ref,
118
108
  auth: definition.auth,
@@ -139,7 +129,6 @@ function compileEntry(schema, lookup) {
139
129
  core: Object.freeze(Object.values(schema.core.nodes)),
140
130
  }),
141
131
  facts: Object.freeze({ core: schema.core.edges }),
142
- values: Object.freeze(values),
143
- patterns: Object.freeze([...patternIndices.keys()]),
132
+ ...indexValuePrograms(programs),
144
133
  });
145
134
  }
@@ -1,4 +1,4 @@
1
- export type CompiledDiagnosticCode = 'COMPILED_CANONICAL_MISMATCH' | 'COMPILED_DEPENDENCY_CYCLE' | 'COMPILED_DEPENDENCY_LIMITS' | 'COMPILED_SOURCE_INVALID' | 'COMPILED_STRUCTURE_INVALID';
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, unknownInputField } from '../../domain/validation/create.js';
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 { Options } from '@astrale-os/kernel-dsl/value';
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?: Options): readonly Diagnostic[];
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
- export declare function unknownInputField(field: string): readonly Diagnostic[];
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
- export function unknownInputField(field) {
29
- return [
30
- Object.freeze({
31
- code: 'CALLABLE_INPUT_FIELD_UNKNOWN',
32
- pointer: '',
33
- message: `Input field ${field} is absent.`,
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 { Options } from '@astrale-os/kernel-dsl/value';
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?: Options): readonly Diagnostic[];
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?: Options): readonly Diagnostic[];
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>;
@@ -0,0 +1,24 @@
1
+ import { runSuspended } from './suspended.js';
2
+ /**
3
+ * How many edges the longest chain from each node holds, for every node `nodes` reach: a direct
4
+ * target is at depth 1. A depth limit bounds how long a chain is and not how many chains share a
5
+ * node, so the walk reads each node once, and it holds its own stack. A node read again before its
6
+ * own chain ends sits on a cycle and adds nothing more, so a cycle counts once round.
7
+ */
8
+ export function chainDepths(nodes, targetsOf) {
9
+ const depths = new Map();
10
+ function* depthOf(node) {
11
+ const known = depths.get(node);
12
+ if (known !== undefined)
13
+ return known;
14
+ depths.set(node, 0);
15
+ let depth = 0;
16
+ for (const target of targetsOf(node))
17
+ depth = Math.max(depth, 1 + (yield depthOf(target)));
18
+ depths.set(node, depth);
19
+ return depth;
20
+ }
21
+ for (const node of nodes)
22
+ runSuspended(depthOf(node));
23
+ return depths;
24
+ }
@@ -0,0 +1,10 @@
1
+ /** An edge a depth-first walk took back to a node it has not finished, and the path that reached it. */
2
+ export interface CycleEdge<Node> {
3
+ readonly path: readonly Node[];
4
+ readonly target: Node;
5
+ }
6
+ /**
7
+ * Each edge closing a cycle in a depth-first walk from `roots`, as the walk meets it. A chain can be
8
+ * as long as a document allows, so the walk holds its own stack, and it enters each node once.
9
+ */
10
+ export declare function cycleEdges<Node>(roots: Iterable<Node>, targetsOf: (node: Node) => Iterable<Node>): Generator<CycleEdge<Node>, void, undefined>;