@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.
Files changed (113) hide show
  1. package/dist/v1/builder/class/authoring.js +0 -3
  2. package/dist/v1/builder/lowering/policy.js +4 -24
  3. package/dist/v1/builder/lowering/schema/context.js +0 -3
  4. package/dist/v1/builder/lowering/value/compile.js +24 -21
  5. package/dist/v1/builder/lowering/value/zod.js +10 -4
  6. package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
  7. package/dist/v1/bundle/codec.js +50 -67
  8. package/dist/v1/bundle/diagnostic.d.ts +1 -1
  9. package/dist/v1/bundle/structure.js +2 -2
  10. package/dist/v1/compiled/admission/accept.js +6 -6
  11. package/dist/v1/compiled/admission/closure.js +16 -33
  12. package/dist/v1/compiled/admission/diagnostic.d.ts +8 -0
  13. package/dist/v1/compiled/admission/diagnostic.js +33 -0
  14. package/dist/v1/compiled/admission/semantics/class.js +11 -7
  15. package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
  16. package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
  17. package/dist/v1/compiled/admission/wire/callable.js +13 -19
  18. package/dist/v1/compiled/admission/wire/class.js +6 -9
  19. package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
  20. package/dist/v1/compiled/admission/wire/entry.js +8 -13
  21. package/dist/v1/compiled/admission/wire/policy.js +4 -3
  22. package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
  23. package/dist/v1/compiled/admission/wire/program.js +39 -44
  24. package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
  25. package/dist/v1/compiled/admission/wire/property.js +8 -5
  26. package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
  27. package/dist/v1/compiled/admission/wire/value.js +0 -7
  28. package/dist/v1/compiled/codec/json.js +4 -3
  29. package/dist/v1/compiled/compiler/compile.js +10 -29
  30. package/dist/v1/compiled/diagnostic.d.ts +1 -1
  31. package/dist/v1/compiled/loader/load.js +2 -7
  32. package/dist/v1/domain/model/input.d.ts +2 -2
  33. package/dist/v1/domain/validation/create.d.ts +3 -1
  34. package/dist/v1/domain/validation/create.js +13 -8
  35. package/dist/v1/language/callable/resolved.d.ts +3 -3
  36. package/dist/v1/language/chain.d.ts +7 -0
  37. package/dist/v1/language/chain.js +24 -0
  38. package/dist/v1/language/class/inheritance.js +0 -2
  39. package/dist/v1/language/cycle.d.ts +10 -0
  40. package/dist/v1/language/cycle.js +30 -0
  41. package/dist/v1/language/limits.d.ts +19 -0
  42. package/dist/v1/language/limits.js +17 -0
  43. package/dist/v1/language/policy/analysis/budgets.js +17 -13
  44. package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
  45. package/dist/v1/language/policy/analysis/composition.js +11 -0
  46. package/dist/v1/language/suspended.d.ts +7 -0
  47. package/dist/v1/language/suspended.js +23 -0
  48. package/dist/v1/language/value/compile/fields.js +12 -8
  49. package/dist/v1/language/value/compile/load.d.ts +5 -0
  50. package/dist/v1/language/value/compile/load.js +13 -0
  51. package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
  52. package/dist/v1/language/value/evaluate/assertions.js +49 -8
  53. package/dist/v1/language/value/evaluate/evaluator.js +107 -105
  54. package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
  55. package/dist/v1/language/value/evaluate/preparation.js +100 -47
  56. package/dist/v1/language/value/evaluate/program.d.ts +2 -2
  57. package/dist/v1/language/value/evaluate/program.js +5 -5
  58. package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
  59. package/dist/v1/language/value/evaluate/validate.js +9 -9
  60. package/dist/v1/language/value/evaluate/validity.optimization.js +4 -3
  61. package/dist/v1/language/value/inclusion/assertions.js +7 -8
  62. package/dist/v1/language/value/inclusion/equivalence.js +4 -2
  63. package/dist/v1/language/value/inclusion/evidence.js +2 -2
  64. package/dist/v1/language/value/inclusion/includes.d.ts +13 -4
  65. package/dist/v1/language/value/inclusion/includes.js +34 -5
  66. package/dist/v1/language/value/inclusion/location.js +10 -7
  67. package/dist/v1/language/value/ordering.js +62 -70
  68. package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
  69. package/dist/v1/language/value/profile/canonicalize.js +64 -83
  70. package/dist/v1/language/value/profile/json.validate.d.ts +13 -3
  71. package/dist/v1/language/value/profile/json.validate.js +18 -6
  72. package/dist/v1/language/value/reference/closure.js +3 -2
  73. package/dist/v1/language/value/reference/recursion.js +7 -26
  74. package/dist/v1/language/value/reference/references.d.ts +3 -1
  75. package/dist/v1/language/value/reference/references.js +7 -7
  76. package/dist/v1/language/value/syntax/walk.d.ts +5 -0
  77. package/dist/v1/language/value/syntax/walk.js +14 -0
  78. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +1 -1
  79. package/dist/v1/schema/admission/accept.d.ts +3 -1
  80. package/dist/v1/schema/admission/accept.js +4 -1
  81. package/dist/v1/schema/analysis/class.d.ts +4 -0
  82. package/dist/v1/schema/analysis/class.js +24 -2
  83. package/dist/v1/schema/canonical/revision.d.ts +4 -1
  84. package/dist/v1/schema/canonical/revision.js +4 -1
  85. package/dist/v1/schema/compatibility/comparators/classes.js +22 -22
  86. package/dist/v1/schema/compatibility/context.d.ts +5 -2
  87. package/dist/v1/schema/compatibility/context.js +8 -6
  88. package/dist/v1/schema/compatibility/meaning/footprint.js +1 -2
  89. package/dist/v1/schema/compatibility/model.d.ts +1 -1
  90. package/dist/v1/schema/compatibility/references.d.ts +0 -3
  91. package/dist/v1/schema/compatibility/references.js +1 -9
  92. package/dist/v1/schema/compatibility/structure/requirements.js +4 -6
  93. package/dist/v1/schema/compatibility/walk.js +2 -2
  94. package/dist/v1/schema/diagnostic.d.ts +1 -1
  95. package/dist/v1/schema/normalization/domain.js +8 -4
  96. package/dist/v1/schema/resolution/context.js +6 -7
  97. package/dist/v1/schema/resolution/domain.js +3 -11
  98. package/dist/v1/schema/rule.js +10 -3
  99. package/dist/v1/schema/validation/class.js +1 -1
  100. package/dist/v1/schema/validation/core.js +16 -8
  101. package/dist/v1/schema/validation/domain.js +20 -3
  102. package/dist/v1/schema/validation/policy/budgets.d.ts +5 -1
  103. package/dist/v1/schema/validation/policy/budgets.js +8 -1
  104. package/dist/v1/schema/validation/policy/references.js +5 -25
  105. package/dist/value/accept.d.ts +3 -3
  106. package/dist/value/canonical.js +2 -2
  107. package/dist/value/equal.d.ts +9 -1
  108. package/dist/value/equal.js +37 -3
  109. package/dist/value/index.d.ts +1 -1
  110. package/dist/value/limits.d.ts +11 -0
  111. package/package.json +1 -1
  112. package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
  113. package/dist/v1/compiled/admission/wire/pattern.js +0 -111
@@ -1,12 +1,34 @@
1
- import { json } from '@astrale-os/kernel-dsl/value';
1
+ import { equal } from '@astrale-os/kernel-dsl/value';
2
2
  import { Key, PropertyKey } from '../../addressing/index.js';
3
3
  import { definitionRefIndex } from '../../addressing/ordering.js';
4
4
  import { composeMethods } from '../../language/callable/composition.js';
5
+ import { chainDepths } from '../../language/chain.js';
6
+ import { limits } from '../../language/limits.js';
5
7
  import { canonicalizeValueSchema } from '../../language/value/profile/canonicalize.js';
6
8
  import { escapePointerToken } from '../../language/value/syntax/pointer.js';
7
9
  import { diagnostic } from '../diagnostic.js';
8
10
  const formatDefinitionRef = Key.of;
11
+ /**
12
+ * A refusal at each Class past the limit. A dependency was accepted under the same limit and each
13
+ * of its Classes reads only its own closure, so such a Class is always one of the candidate. A
14
+ * direct parent is at depth 1. Every other walk of inheritance runs on the call stack, under this.
15
+ */
16
+ function validateInheritanceDepth(environment) {
17
+ const depths = chainDepths(environment.definitions.values(), ({ declaration }) => declaration.extends.flatMap((parent) => environment.resolveAny(parent) ?? []));
18
+ return [...depths].flatMap(([{ ref }, depth]) => depth > limits.inheritance.depth
19
+ ? [
20
+ diagnostic('DV_INHERITANCE_LIMITS', `/classes/${escapePointerToken(ref.name)}/extends`, `Class ${formatDefinitionRef(ref)} has ${depth} parents on its longest chain, over the maximum ${limits.inheritance.depth}.`),
21
+ ]
22
+ : []);
23
+ }
24
+ /**
25
+ * Compose every Class from its parents, unless a chain of parents is past its limit: then nothing
26
+ * is composed, since composing holds each Class's ancestors and walks them on the call stack.
27
+ */
9
28
  export function analyzeDefinitions(environment) {
29
+ const pastLimit = validateInheritanceDepth(environment);
30
+ if (pastLimit.length > 0)
31
+ return Object.freeze({ definitions: new Map(), diagnostics: Object.freeze(pastLimit) });
10
32
  const diagnostics = [];
11
33
  const result = new Map();
12
34
  const visiting = new Set();
@@ -134,7 +156,7 @@ function mergeMethods(owner, declaration, parents, report) {
134
156
  }
135
157
  /** The exact signature required by abstract Method composition. */
136
158
  export function sameMethodSignature(left, right) {
137
- return json.serialize(methodSignature(left)) === json.serialize(methodSignature(right));
159
+ return equal(methodSignature(left), methodSignature(right));
138
160
  }
139
161
  /**
140
162
  * Shared canonical signature used by admission and compatibility explanations. The execution
@@ -6,7 +6,10 @@ interface CanonicalDomainSchema {
6
6
  readonly revision: Revision;
7
7
  }
8
8
  export declare function canonicalDomainSchema(value: DomainSchema): CanonicalDomainSchema;
9
- /** Internal acceptance seam. The caller must establish whole-Domain validity first. */
9
+ /**
10
+ * Internal acceptance seam. The caller must establish the structure first; canonicalization judges
11
+ * nothing further, so the result is an accepted Schema only once whole-Domain validity holds too.
12
+ */
10
13
  export declare function canonicalDomainSchemaAfterValidation(value: DomainSchemaIR): CanonicalDomainSchema;
11
14
  export declare function revisionOfDomainSchema(schema: DomainSchema): Revision;
12
15
  export {};
@@ -7,7 +7,10 @@ const revisions = new WeakMap();
7
7
  export function canonicalDomainSchema(value) {
8
8
  return canonicalDomainSchemaAfterValidation(value);
9
9
  }
10
- /** Internal acceptance seam. The caller must establish whole-Domain validity first. */
10
+ /**
11
+ * Internal acceptance seam. The caller must establish the structure first; canonicalization judges
12
+ * nothing further, so the result is an accepted Schema only once whole-Domain validity holds too.
13
+ */
11
14
  export function canonicalDomainSchemaAfterValidation(value) {
12
15
  const schema = asDomainSchema(normalizeDomainSchema(value));
13
16
  const bytes = json.encode(schema);
@@ -27,31 +27,31 @@ export function classMeaning(context, coordinate, level, onto) {
27
27
  ancestors,
28
28
  });
29
29
  const covering = coveringTuples(context, declaration);
30
- const meaning = {
31
- coordinate: 'class',
32
- level: level,
33
- ...fieldsOf({ declaration, roles: CLASS_FIELDS, level }),
34
- ...(covering.length === 0 ? {} : { unique: covering }),
35
- ...(level === 'inherit'
30
+ // The fields whose meaning is not their declared value; `CLASS_FIELDS` decides which count.
31
+ const normalized = {
32
+ ...declaration,
33
+ extends: onto === undefined
34
+ ? ancestors
35
+ : onto.ancestors.filter((ancestor) => ancestors.includes(ancestor)),
36
+ policies: Object.fromEntries(Object.entries(declaration.policies)
37
+ .filter(([, policy]) => policy !== undefined)
38
+ .map(([role, policy]) => [role, classPolicyMeaning(policy)])),
39
+ ...(declaration.kind === 'node'
36
40
  ? {
37
- extends: onto === undefined
38
- ? ancestors
39
- : onto.ancestors.filter((ancestor) => ancestors.includes(ancestor)),
40
- policies: Object.fromEntries(Object.entries(declaration.policies)
41
- .filter(([, policy]) => policy !== undefined)
42
- .map(([role, policy]) => [role, classPolicyMeaning(policy)])),
43
- ...(declaration.kind === 'node'
44
- ? {
45
- data: analysis.data === undefined
46
- ? null
47
- : {
48
- owner: keyForDefinitionRef(analysis.data.owner),
49
- declaration: analysis.data.declaration,
50
- },
51
- }
52
- : { endpoints: declaration.endpoints, constraints: declaration.constraints }),
41
+ data: analysis.data === undefined
42
+ ? null
43
+ : {
44
+ owner: keyForDefinitionRef(analysis.data.owner),
45
+ declaration: analysis.data.declaration,
46
+ },
53
47
  }
54
48
  : {}),
49
+ ...(covering.length === 0 ? {} : { unique: covering }),
50
+ };
51
+ const meaning = {
52
+ coordinate: 'class',
53
+ level: level,
54
+ ...fieldsOf({ declaration: normalized, roles: CLASS_FIELDS, level }),
55
55
  };
56
56
  return { meaning: deepFreeze(meaning), requirement };
57
57
  }
@@ -1,7 +1,6 @@
1
1
  import type { ClassRef, DefinitionRef, Key as SemanticKey } from '../../addressing/index.js';
2
2
  import type { DefinitionAnalysis, EffectiveMethod } from '../analysis/class.js';
3
3
  import type { DomainSchema } from '../model/schema.js';
4
- import { SchemaError } from '../diagnostic.js';
5
4
  /** One accepted root with its exact closure and a memoized Definition analysis per owner. */
6
5
  export interface Context {
7
6
  readonly schemas: ReadonlyMap<string, DomainSchema>;
@@ -16,4 +15,8 @@ export declare function effectiveDefinition(context: Context, owner: DomainSchem
16
15
  /** Effective Methods are keyed by name; a coordinate names one by its exact Method Key. */
17
16
  export declare function effectiveMethod(analysis: DefinitionAnalysis, key: SemanticKey): EffectiveMethod | undefined;
18
17
  export declare function requireOwner(context: Context, ref: DefinitionRef, key: SemanticKey): DomainSchema;
19
- export declare function contextInvalid(message: string, key: SemanticKey): SchemaError;
18
+ /**
19
+ * Acceptance proved every reference of a Domain against the closure it retains, so what a comparison
20
+ * reaches from one has a meaning there. Its absence is a defect here and no answer about a document.
21
+ */
22
+ export declare function retainedContextDefect(key: SemanticKey): TypeError;
@@ -1,7 +1,6 @@
1
1
  import { MethodKey } from '../../addressing/index.js';
2
2
  import { definitionRefIndex } from '../../addressing/ordering.js';
3
3
  import { analyzeDefinitions } from '../analysis/class.js';
4
- import { SchemaError, diagnostic } from '../diagnostic.js';
5
4
  import { knownDomainClosure, lookupForDomainClosure } from '../resolution/closure.js';
6
5
  import { buildDomainResolutionContext } from '../resolution/context.js';
7
6
  /**
@@ -39,11 +38,14 @@ export function effectiveMethod(analysis, key) {
39
38
  }
40
39
  export function requireOwner(context, ref, key) {
41
40
  const owner = context.schemas.get(ref.origin);
42
- if (owner === undefined) {
43
- throw contextInvalid(`Retained acceptance context cannot resolve ${key}.`, key);
44
- }
41
+ if (owner === undefined)
42
+ throw retainedContextDefect(key);
45
43
  return owner;
46
44
  }
47
- export function contextInvalid(message, key) {
48
- return new SchemaError([diagnostic('DM_DEPENDENCY_CONTEXT_INVALID', '', message, key)]);
45
+ /**
46
+ * Acceptance proved every reference of a Domain against the closure it retains, so what a comparison
47
+ * reaches from one has a meaning there. Its absence is a defect here and no answer about a document.
48
+ */
49
+ export function retainedContextDefect(key) {
50
+ return new TypeError(`Retained acceptance context has no meaning for ${key}.`);
49
51
  }
@@ -1,4 +1,4 @@
1
- import { callableReferences, classReferences, inherits, memberReferences, valueReferences, } from '../references.js';
1
+ import { callableReferences, classReferences, inherits, memberReferences } from '../references.js';
2
2
  import { walkReferences } from '../walk.js';
3
3
  /** Meaning follows complete callable contracts through the exact authored reference closure. */
4
4
  export function compareFootprint({ context, report, }) {
@@ -10,7 +10,6 @@ export function compareFootprint({ context, report, }) {
10
10
  reach(...classReferences(subject, true));
11
11
  return inherits(usage) ? 'class.inherit' : 'class.reference';
12
12
  case 'property':
13
- reach(...valueReferences(subject));
14
13
  return 'property';
15
14
  case 'method':
16
15
  reach(...callableReferences(subject));
@@ -7,7 +7,7 @@ export type Fingerprint = `sha256:${string}`;
7
7
  * The codes a comparison request is refused with: the request, not a Schema, is invalid. A
8
8
  * `schema.Error` carries them beside the codes of a refused Schema document.
9
9
  */
10
- export type DiagnosticCode = 'DM_CAPABILITY_INVALID' | 'DM_DEPENDENCY_CONTEXT_INVALID' | 'DM_DEPENDENCY_NOT_RETAINED' | 'DM_MEMBER_ORIGIN_MISMATCH' | 'DM_MEMBER_ROOT_INVALID';
10
+ export type DiagnosticCode = 'DM_CAPABILITY_INVALID' | 'DM_DEPENDENCY_NOT_RETAINED' | 'DM_MEMBER_ORIGIN_MISMATCH' | 'DM_MEMBER_ROOT_INVALID';
11
11
  /** Inputs carry accepted schemas; a dependency's source is always its retained exact context. */
12
12
  export interface ComparisonRequest {
13
13
  readonly scope: {
@@ -23,9 +23,6 @@ export declare function rootReferences(schema: DomainSchema): readonly Reference
23
23
  */
24
24
  export declare function policyReliance(schema: DomainSchema, origin: Key.Origin): readonly Reference[];
25
25
  /** Existing DSL collectors own reference syntax. These functions attach comparison provenance. */
26
- export declare function valueReferences(subject: Extract<ResolvedSubject, {
27
- kind: 'property';
28
- }>): readonly Reference[];
29
26
  export declare function callableReferences(subject: Extract<ResolvedSubject, {
30
27
  kind: 'method';
31
28
  }>): readonly Reference[];
@@ -1,6 +1,6 @@
1
1
  import { Key } from '../../addressing/index.js';
2
2
  import { revisionOfDomainSchema } from '../canonical/revision.js';
3
- import { collectCallableContractRefs, collectCallableRefs, collectClassPolicyRefs, collectCoreRefs, collectEndpointRefs, collectPolicyDefinitionRefs, collectValueDefinitionRefs, coreEndpointDefinitionRef, } from '../resolution/origins.js';
3
+ import { collectCallableContractRefs, collectCallableRefs, collectClassPolicyRefs, collectCoreRefs, collectEndpointRefs, collectPolicyDefinitionRefs, coreEndpointDefinitionRef, } from '../resolution/origins.js';
4
4
  import { classCoordinate, keyForDefinitionRef, memberCoordinate, methodCoordinate, propertyCoordinate, } from './coordinate.js';
5
5
  export function schemaIdentity(schema) {
6
6
  return Object.freeze({ origin: schema.origin, revision: revisionOfDomainSchema(schema) });
@@ -31,9 +31,6 @@ export function rootReferences(schema) {
31
31
  const key = keyForDefinitionRef(declaration.ref);
32
32
  const add = collector(schema, result, key);
33
33
  declaration.extends.forEach((ref) => add(ref, 'extends'));
34
- for (const [name, field] of Object.entries(declaration.properties)) {
35
- collectValueDefinitionRefs(field.schema, collector(schema, result, propertyCoordinate(declaration.ref, name).key));
36
- }
37
34
  collectClassPolicyRefs(declaration, add);
38
35
  if (declaration.kind === 'edge')
39
36
  collectEndpointRefs(declaration, add);
@@ -81,11 +78,6 @@ export function policyReliance(schema, origin) {
81
78
  return [...result.values()];
82
79
  }
83
80
  /** Existing DSL collectors own reference syntax. These functions attach comparison provenance. */
84
- export function valueReferences(subject) {
85
- const result = [];
86
- collectValueDefinitionRefs(subject.field.schema, collector(subject.schema, result, subject.coordinate.key));
87
- return result;
88
- }
89
81
  export function callableReferences(subject) {
90
82
  const result = [];
91
83
  collectCallableContractRefs(subject.method.declaration, collector(subject.schema, result, subject.coordinate.key));
@@ -2,10 +2,10 @@ import { inheritanceOf } from '../../../language/class/inheritance.js';
2
2
  import { inheritanceMeaning } from '../comparators/classes.js';
3
3
  import { compareFacet } from '../comparators/index.js';
4
4
  import { fingerprintMeaning } from '../comparators/values.js';
5
- import { contextInvalid } from '../context.js';
5
+ import { retainedContextDefect } from '../context.js';
6
6
  import { methodCoordinate } from '../coordinate.js';
7
7
  import { closedParents } from '../extension.js';
8
- import { callableReferences, classReferences, inherits, memberReferences, usageOf, valueReferences, } from '../references.js';
8
+ import { callableReferences, classReferences, inherits, memberReferences, usageOf, } from '../references.js';
9
9
  import { walkReferences } from '../walk.js';
10
10
  /** Structure follows data and abstract obligations; concrete IO never expands its requirements. */
11
11
  export function compareRequirements({ context, report, }) {
@@ -23,7 +23,6 @@ export function compareRequirements({ context, report, }) {
23
23
  }
24
24
  return inherits(usage) ? 'class.inherit' : 'class.reference';
25
25
  case 'property':
26
- reach(...valueReferences(subject));
27
26
  return 'property';
28
27
  case 'method':
29
28
  if (usage.relation !== 'abstract')
@@ -55,7 +54,7 @@ function compareReliance({ context, report, }) {
55
54
  for (const reference of context.reliance) {
56
55
  const pair = context.pair(reference.coordinate);
57
56
  if (pair.source === undefined)
58
- throw contextInvalid(`Retained acceptance context has no meaning for ${reference.coordinate.key}.`, reference.coordinate.key);
57
+ throw retainedContextDefect(reference.coordinate.key);
59
58
  const facet = reference.coordinate.kind === 'method' ? 'method.object' : 'class.endpoints';
60
59
  const { before, after } = compareFacet({ context, pair, facet });
61
60
  if (before !== undefined &&
@@ -79,12 +78,11 @@ function compareExtension({ context, report, }) {
79
78
  if (closed.size === 0)
80
79
  return;
81
80
  for (const reference of context.roots) {
82
- if (reference.usage.relation !== 'extends' || !closed.has(reference.coordinate.key))
81
+ if (!closed.has(reference.coordinate.key))
83
82
  continue;
84
83
  const pair = context.pair(reference.coordinate);
85
84
  if (pair.target?.kind !== 'class')
86
85
  continue;
87
- report.note(reference);
88
86
  report.record({
89
87
  pair,
90
88
  facet: 'class.inheritance',
@@ -1,7 +1,7 @@
1
1
  import { Key } from '../../addressing/index.js';
2
2
  import { compareAddedProperties, compareLostProperties } from './comparators/classes.js';
3
3
  import { compareFacet } from './comparators/index.js';
4
- import { contextInvalid } from './context.js';
4
+ import { retainedContextDefect } from './context.js';
5
5
  /**
6
6
  * Follow the reference closure from the roots once per coordinate and usage relation. `expand`
7
7
  * names the facet a reached subject is compared under and `reach`es what it references; a subject
@@ -23,7 +23,7 @@ export function walkReferences({ context, report }, expand, required = () => tru
23
23
  const pair = context.pair(coordinate);
24
24
  const subject = pair.source;
25
25
  if (subject === undefined)
26
- throw contextInvalid(`Retained acceptance context has no meaning for ${coordinate.key}.`, coordinate.key);
26
+ throw retainedContextDefect(coordinate.key);
27
27
  const facet = expand(subject, reference, reach);
28
28
  if (Key.origin(coordinate.key) !== context.source.origin)
29
29
  continue;
@@ -2,7 +2,7 @@ import type { DiagnosticCode as LanguageDiagnosticCode } from '../language/valid
2
2
  import type { Diagnostic as LanguageDiagnostic } from '../language/validation/diagnostic.js';
3
3
  import type { DiagnosticCode as CompatibilityDiagnosticCode } from './compatibility/model.js';
4
4
  /** The codes a Schema document is refused with, one per rule of `RULES`. */
5
- export type SchemaDiagnosticCode = 'DV_ACCEPTANCE_CONTEXT' | 'DV_CALLABLE_ADMISSION' | 'DV_CALLABLE_AUTH' | 'DV_CALLABLE_IO' | 'DV_CLASS_ABSTRACT' | 'DV_CLASS_ACYCLIC' | 'DV_CLASS_INHERITANCE' | 'DV_CLASS_KIND' | 'DV_CORE_EDGE_CLASS' | 'DV_CORE_EDGE_CONSTRAINTS' | 'DV_CORE_EDGE_KEY' | 'DV_CORE_EDGE_PROPERTIES' | 'DV_CORE_EDGE_UNIQUE' | 'DV_CORE_NODE_CLASS' | 'DV_CORE_NODE_PROPERTIES' | 'DV_CORE_NODE_UNIQUE' | 'DV_CORE_REF' | 'DV_DATA_COMPOSITION' | 'DV_DEPENDENCY_ACYCLIC' | 'DV_DEPENDENCY_DIRECT' | 'DV_DEPENDENCY_EXACT' | 'DV_DEPENDENCY_LIMITS' | 'DV_DEPENDENCY_REVISION_COHERENCE' | 'DV_DEPENDENCY_UNIQUE' | 'DV_EDGE_ACCEPTS' | 'DV_EDGE_CLASS_COMPOSITION' | 'DV_EDGE_FOREIGN_MINIMUM' | 'DV_EDGE_LIFETIME' | 'DV_EDGE_ROLE' | 'DV_EDGE_UNIQUE' | 'DV_ENTRYPOINT' | 'DV_JSON_VALUE' | 'DV_METHOD_ABSTRACT' | 'DV_METHOD_COMPOSITION' | 'DV_NODE_UNIQUE' | 'DV_PROPERTY_AUTO' | 'DV_PROPERTY_IMMUTABLE' | 'DV_PROPERTY_STATE' | 'DV_REF_RESOLVES' | 'DV_VALUE_SCHEMA' | 'PL_BUDGET' | 'PL_COMPOSITION' | 'PL_CONNECTIVITY' | 'PL_REF' | 'PL_REPEAT' | 'PL_TARGET' | 'PL_TYPING' | 'PL_USE' | 'PL_VARIABLE_SCOPE' | 'STRUCTURE_BINARY_INPUT' | 'STRUCTURE_CALLABLE_POLICY_AUTH' | 'STRUCTURE_DEPENDENCY_ALIAS' | 'STRUCTURE_DOMAIN_NAME' | 'STRUCTURE_DUPLICATE_ITEM' | 'STRUCTURE_EDGE_BLOB' | 'STRUCTURE_EDGE_ORIENTATION' | 'STRUCTURE_FORMAT' | 'STRUCTURE_KEY' | 'STRUCTURE_MAXIMUM' | 'STRUCTURE_MINIMUM' | 'STRUCTURE_PROPERTY_KEY' | 'STRUCTURE_PROTO_KEY' | 'STRUCTURE_REQUIRED' | 'STRUCTURE_STATE_TRANSITIONS' | 'STRUCTURE_TYPE' | 'STRUCTURE_UNION' | 'STRUCTURE_UNKNOWN_FIELD' | 'STRUCTURE_VALUE' | 'UNSUPPORTED_DOCUMENT_FORMAT' | 'UNSUPPORTED_DSL_VERSION';
5
+ export type SchemaDiagnosticCode = 'DV_ACCEPTANCE_CONTEXT' | 'DV_CALLABLE_ADMISSION' | 'DV_CALLABLE_AUTH' | 'DV_CALLABLE_IO' | 'DV_CLASS_ABSTRACT' | 'DV_CLASS_ACYCLIC' | 'DV_CLASS_INHERITANCE' | 'DV_CLASS_KIND' | 'DV_CORE_EDGE_CLASS' | 'DV_CORE_EDGE_CONSTRAINTS' | 'DV_CORE_EDGE_KEY' | 'DV_CORE_EDGE_PROPERTIES' | 'DV_CORE_EDGE_UNIQUE' | 'DV_CORE_NODE_CLASS' | 'DV_CORE_NODE_PROPERTIES' | 'DV_CORE_NODE_UNIQUE' | 'DV_CORE_REF' | 'DV_DATA_COMPOSITION' | 'DV_DEPENDENCY_ACYCLIC' | 'DV_DEPENDENCY_DIRECT' | 'DV_DEPENDENCY_EXACT' | 'DV_DEPENDENCY_LIMITS' | 'DV_DEPENDENCY_REVISION_COHERENCE' | 'DV_DEPENDENCY_UNIQUE' | 'DV_EDGE_ACCEPTS' | 'DV_EDGE_CLASS_COMPOSITION' | 'DV_EDGE_FOREIGN_MINIMUM' | 'DV_EDGE_LIFETIME' | 'DV_EDGE_ROLE' | 'DV_EDGE_UNIQUE' | 'DV_ENTRYPOINT' | 'DV_INHERITANCE_LIMITS' | 'DV_JSON_VALUE' | 'DV_METHOD_ABSTRACT' | 'DV_METHOD_COMPOSITION' | 'DV_NODE_UNIQUE' | 'DV_PROPERTY_AUTO' | 'DV_PROPERTY_IMMUTABLE' | 'DV_PROPERTY_STATE' | 'DV_REF_RESOLVES' | 'DV_VALUE_SCHEMA' | 'PL_BUDGET' | 'PL_COMPOSITION' | 'PL_CONNECTIVITY' | 'PL_REF' | 'PL_REPEAT' | 'PL_TARGET' | 'PL_TYPING' | 'PL_USE' | 'PL_VARIABLE_SCOPE' | 'STRUCTURE_BINARY_INPUT' | 'STRUCTURE_CALLABLE_POLICY_AUTH' | 'STRUCTURE_DEPENDENCY_ALIAS' | 'STRUCTURE_DOMAIN_NAME' | 'STRUCTURE_DUPLICATE_ITEM' | 'STRUCTURE_EDGE_BLOB' | 'STRUCTURE_EDGE_ORIENTATION' | 'STRUCTURE_FORMAT' | 'STRUCTURE_KEY' | 'STRUCTURE_MAXIMUM' | 'STRUCTURE_MINIMUM' | 'STRUCTURE_PROPERTY_KEY' | 'STRUCTURE_PROTO_KEY' | 'STRUCTURE_REQUIRED' | 'STRUCTURE_STATE_TRANSITIONS' | 'STRUCTURE_TYPE' | 'STRUCTURE_UNION' | 'STRUCTURE_UNKNOWN_FIELD' | 'STRUCTURE_VALUE' | 'UNSUPPORTED_DOCUMENT_FORMAT' | 'UNSUPPORTED_DSL_VERSION';
6
6
  /**
7
7
  * A Schema refuses a document with its own codes, and a comparison request with the
8
8
  * compatibility codes. `pointer` names the position the refused rule applies to, in the document
@@ -4,7 +4,6 @@ import { isBinaryInput } from '../../language/callable/model/callable.js';
4
4
  import { compareEdgeUniqueFields, compareEdgeUniqueTuples, compareNodeUniqueTuples, } from '../../language/class/unique.js';
5
5
  import { CLASS_OPERATIONS } from '../../language/policy/model/policy.js';
6
6
  import { normalizeClassRule, normalizePolicyChecks, normalizePolicyExpression, } from '../../language/policy/normalization/normalize.js';
7
- import { admitStateTopology } from '../../language/state/topology.js';
8
7
  import { canonicalizeValueSchema } from '../../language/value/profile/canonicalize.js';
9
8
  export function normalizeDomainSchema(schema) {
10
9
  const classes = mapRecord(schema.classes, canonicalizeClass);
@@ -180,9 +179,14 @@ function canonicalizeProperty(value) {
180
179
  }),
181
180
  ...(value.immutable === undefined ? {} : { immutable: value.immutable }),
182
181
  ...(value.description === undefined ? {} : { description: value.description }),
183
- ...(value.state === undefined
184
- ? {}
185
- : { state: admitStateTopology(value.state) }),
182
+ ...(value.state === undefined ? {} : { state: canonicalizeStateTopology(value.state) }),
183
+ };
184
+ }
185
+ /** Orders a topology the structure shaped; only validation judges what it declares. */
186
+ function canonicalizeStateTopology(value) {
187
+ return {
188
+ initial: value.initial,
189
+ transitions: mapRecord(value.transitions, (events) => mapRecord(events, (target) => target)),
186
190
  };
187
191
  }
188
192
  function canonicalizeDirectedEndpoints(value) {
@@ -1,5 +1,6 @@
1
1
  import { definitionRefIndex } from '../../addressing/ordering.js';
2
2
  import { DOMAIN_REVISION_PATTERN } from '../../addressing/patterns.js';
3
+ import { chainDepths } from '../../language/chain.js';
3
4
  import { limits } from '../../language/limits.js';
4
5
  import { escapePointerToken } from '../../language/value/syntax/pointer.js';
5
6
  import { revisionOfDomainSchema } from '../canonical/revision.js';
@@ -79,7 +80,6 @@ function loadDependencyClosure(candidate, dependencies, lookup, diagnostics) {
79
80
  {
80
81
  schema: candidate,
81
82
  key: `${candidate.origin}\u0000candidate`,
82
- depth: 0,
83
83
  edges: Object.entries(candidate.dependencies),
84
84
  index: 0,
85
85
  },
@@ -128,11 +128,6 @@ function loadDependencyClosure(candidate, dependencies, lookup, diagnostics) {
128
128
  }
129
129
  continue;
130
130
  }
131
- const depth = frame.depth + 1;
132
- if (depth > limits.dependency.depth) {
133
- diagnostics.push(diagnostic('DV_DEPENDENCY_LIMITS', pointer, `Dependency depth ${depth} exceeds the maximum ${limits.dependency.depth}.`));
134
- continue;
135
- }
136
131
  const key = `${dependency.origin}\u0000${dependency.revision}`;
137
132
  if (visited.has(key))
138
133
  continue;
@@ -140,11 +135,15 @@ function loadDependencyClosure(candidate, dependencies, lookup, diagnostics) {
140
135
  frames.push({
141
136
  schema: nested,
142
137
  key,
143
- depth,
144
138
  edges: Object.entries(nested.dependencies),
145
139
  index: 0,
146
140
  });
147
141
  }
142
+ const depths = chainDepths([candidate], (schema) => Object.values(schema.dependencies).flatMap(({ origin }) => dependencies.get(origin) ?? []));
143
+ const depth = depths.get(candidate);
144
+ if (depth > limits.dependency.depth) {
145
+ diagnostics.push(diagnostic('DV_DEPENDENCY_LIMITS', '/dependencies', `Dependency depth ${depth} exceeds the maximum ${limits.dependency.depth}.`));
146
+ }
148
147
  }
149
148
  function validateDependencyUse(candidate, directOrigins, diagnostics) {
150
149
  // Each reference that cannot resolve is reported where it is written; the dependency it lacks
@@ -1,11 +1,10 @@
1
1
  import { Key, MethodKey, PropertyKey } from '../../addressing/index.js';
2
2
  import { compareUnicode } from '../../addressing/ordering.js';
3
3
  import { createDomain, createSourceDomain } 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 { isBinaryInput } from '../../language/callable/model/callable.js';
6
6
  import { inputFieldNodes } from '../../language/value/compile/fields.js';
7
7
  import { prepareValueSchema } from '../../language/value/evaluate/preparation.js';
8
- import { validateValueProgram } from '../../language/value/evaluate/program.js';
9
8
  import { validateJsonInstance, validatePreparedInstance, } from '../../language/value/evaluate/validate.js';
10
9
  import { classifyPreparedOrdering } from '../../language/value/ordering.js';
11
10
  import { revisionOfDomainSchema } from '../canonical/revision.js';
@@ -98,15 +97,8 @@ export function callableValidation(input, output, registry, patterns) {
98
97
  return Object.freeze({
99
98
  ...(fields === undefined ? {} : { fields: Object.freeze(Object.keys(fields)) }),
100
99
  validateInput: (value, options) => validatePreparedInstance(prepared.value, value, options),
101
- validateInputField(field, value) {
102
- const nodes = fields?.[field];
103
- return nodes === undefined
104
- ? unknownInputField(field)
105
- : validateValueProgram(inputProgram, value, nodes);
106
- },
107
- validateOutput: (value) => output === undefined
108
- ? []
109
- : validateJsonInstance(output, value, registry, '', patterns),
100
+ validateInputField: (field, value) => validateInputField(inputProgram, fields, field, value),
101
+ validateOutput: (value) => output === undefined ? [] : validateJsonInstance(output, value, registry, '', patterns),
110
102
  });
111
103
  }
112
104
  function definitionsOf(schema) {
@@ -9,7 +9,7 @@ const CHECKS = [
9
9
  ];
10
10
  const DEPENDENCIES = ['/dependencies/{alias}', '/dependencies'];
11
11
  const count = (value) => value.toLocaleString('en-US');
12
- const { dependency, policy } = limits;
12
+ const { dependency, inheritance, policy } = limits;
13
13
  const at = (field) => [
14
14
  `/functions/{function}${field}`,
15
15
  `/classes/{class}/methods/{method}${field}`,
@@ -131,7 +131,7 @@ export const RULES = deepFreeze({
131
131
  DV_DEPENDENCY_LIMITS: {
132
132
  stage: 'context',
133
133
  positions: ['/dependencies', '/dependencies/{alias}'],
134
- statement: `A Domain has at most ${dependency.direct} direct dependencies, a closure of at most ${dependency.closure} Domains and a dependency depth of at most ${dependency.depth}.`,
134
+ statement: `A Domain has at most ${dependency.direct} direct dependencies, a closure of at most ${dependency.closure} Domains and a longest chain of at most ${dependency.depth} dependencies.`,
135
135
  limits: ['dependency.direct', 'dependency.closure', 'dependency.depth'],
136
136
  },
137
137
  DV_DEPENDENCY_REVISION_COHERENCE: {
@@ -182,10 +182,17 @@ export const RULES = deepFreeze({
182
182
  positions: ['/entrypoint'],
183
183
  statement: 'The entrypoint names a View its Domain declares.',
184
184
  },
185
+ DV_INHERITANCE_LIMITS: {
186
+ stage: 'context',
187
+ positions: ['/classes/{class}/extends'],
188
+ statement: `A Class has at most ${inheritance.depth} parents on its longest chain of parents, those of its dependencies included.`,
189
+ limits: ['inheritance.depth'],
190
+ },
185
191
  DV_JSON_VALUE: {
186
192
  stage: 'structure',
187
193
  positions: ANY,
188
- statement: `The document is portable JSON: as text, UTF-8 that parses, within ${count(defaultLimits.maxBytes)} bytes, with no byte-order mark and no repeated member name; as a value, null, booleans, finite numbers other than negative zero, strings, arrays and plain objects, with no string or member name that holds U+0000 or a lone surrogate or exceeds ${count(defaultLimits.maxStringBytes)} bytes of UTF-8, at most ${count(defaultLimits.maxDepth)} nested arrays and objects, and at most ${count(defaultLimits.maxMembers)} members and items in all.`,
194
+ statement: `The document is portable JSON: as text, UTF-8 that parses, within ${count(defaultLimits.maxBytes)} bytes, with no byte-order mark and no repeated member name; as a value, null, booleans, finite numbers other than negative zero, strings, arrays and plain objects, with no string or member name that holds U+0000 or a lone surrogate or exceeds ${count(defaultLimits.maxStringBytes)} bytes of UTF-8, at most ${count(defaultLimits.maxDepth)} nested arrays and objects, and at most ${count(defaultLimits.maxMembers)} members and items in all. A Bundle holds a closure whole, so as a whole it holds at most ${count(limits.closure.members)} members and items, and each Domain in it the limits above.`,
195
+ limits: ['closure.members'],
189
196
  conditions: ['#/$defs/portable-string/not'],
190
197
  },
191
198
  DV_METHOD_ABSTRACT: {
@@ -17,7 +17,7 @@ const formatDefinitionRef = Key.of;
17
17
  * registry; each dependency's is built at most once, so the Classes share them.
18
18
  */
19
19
  export function validateDefinitions(environment, analysis, registry) {
20
- const diagnostics = [...analysis.diagnostics];
20
+ const diagnostics = [];
21
21
  const schema = environment.candidate;
22
22
  let scope;
23
23
  const registries = new Map([[schema.origin, registry]]);
@@ -6,7 +6,7 @@ import { coveringEdgeUniqueTuples, coveringNodeUniqueTuples, edgeUniqueKeys, nod
6
6
  import { checkCoreEdgeSet, checkHeldKeys, coreEndpointsSatisfy, DOMAIN_ENDPOINT_CLASS, } from '../../language/core/facts.js';
7
7
  import { policyObjectKey, policyObjectOrigin, projectedMemberClass, } from '../../language/policy/model/policy.js';
8
8
  import { validateJsonInstance } from '../../language/value/evaluate/validate.js';
9
- import { escapePointerToken } from '../../language/value/syntax/pointer.js';
9
+ import { appendPointer, escapePointerToken } from '../../language/value/syntax/pointer.js';
10
10
  import { diagnostic, valueDiagnostic } from '../diagnostic.js';
11
11
  import { classSatisfies } from './class.js';
12
12
  const formatDefinitionRef = Key.of;
@@ -134,18 +134,26 @@ function endpointSatisfies(environment, endpoint, accepts) {
134
134
  return classSatisfies(environment, endpoint.classRef, accepts);
135
135
  }
136
136
  function validateCreationProperties(definition, properties, registry, code, pointer, diagnostics) {
137
- const schema = {
137
+ const fields = [...definition.properties].filter(([, field]) => field.auto === undefined);
138
+ // Which Properties the fact holds is judged apart from their values: a Property's schema is the
139
+ // root of its own local references, here as at a write, so it is never nested in another schema.
140
+ const held = {
138
141
  type: 'object',
139
- properties: Object.fromEntries([...definition.properties]
140
- .filter(([, field]) => field.auto === undefined)
141
- .map(([name, field]) => [name, field.schema])),
142
- required: [...definition.properties]
143
- .filter(([, field]) => field.required && field.auto === undefined)
142
+ properties: Object.fromEntries(fields.map(([name]) => [name, true])),
143
+ required: fields
144
+ .filter(([, field]) => field.required)
144
145
  .map(([name]) => name)
145
146
  .sort(compareUnicode),
146
147
  additionalProperties: false,
147
148
  };
148
- for (const refusal of validateJsonInstance(schema, properties, registry, pointer)) {
149
+ const refusals = validateJsonInstance(held, properties, registry, pointer);
150
+ for (const [name, field] of fields) {
151
+ if (!Object.hasOwn(properties, name))
152
+ continue;
153
+ const at = appendPointer(pointer, name);
154
+ refusals.push(...validateJsonInstance(field.schema, properties[name], registry, at));
155
+ }
156
+ for (const refusal of refusals) {
149
157
  diagnostics.push(valueDiagnostic(code, refusal));
150
158
  }
151
159
  }
@@ -11,15 +11,32 @@ import { validateViews } from './view.js';
11
11
  export function validateDomainSchemaSemantics(schema, lookup) {
12
12
  const context = buildDomainResolutionContext(schema, lookup);
13
13
  const analysis = analyzeDefinitions(context);
14
+ // Past the inheritance limit no Class is composed, and the rules below read the composition.
15
+ if (analysis.diagnostics.some(({ code }) => code === 'DV_INHERITANCE_LIMITS')) {
16
+ return Object.freeze({
17
+ context,
18
+ analysis,
19
+ diagnostics: Object.freeze(orderAndDeduplicate([...context.diagnostics, ...analysis.diagnostics])),
20
+ });
21
+ }
14
22
  const registry = createValueSchemaRegistry(context);
23
+ const valueRefusals = validateEmbeddedValueSchemas(schema, registry);
24
+ // The Class and Core rules read every Property value schema as admitted. A reference with no
25
+ // target is the one refusal they can read, and it may only mean a dependency this context lacks.
26
+ const readable = valueRefusals.every(({ valueCode }) => valueCode === 'VS_REFERENCE_RESOLUTION');
15
27
  const diagnostics = [
16
28
  ...context.diagnostics,
17
- ...validateEmbeddedValueSchemas(schema, registry),
18
- ...validateDefinitions(context, analysis, registry),
29
+ ...analysis.diagnostics,
30
+ ...valueRefusals,
19
31
  ...validateContracts(schema, registry),
20
32
  ...validatePolicies(context, analysis),
21
33
  ...validateViews(context),
22
- ...validateCore(context, analysis, registry),
34
+ ...(readable
35
+ ? [
36
+ ...validateDefinitions(context, analysis, registry),
37
+ ...validateCore(context, analysis, registry),
38
+ ]
39
+ : []),
23
40
  ];
24
41
  return Object.freeze({
25
42
  context,
@@ -26,7 +26,11 @@ export interface PolicyMeasures {
26
26
  export declare function measurePolicies(input: unknown): PolicyMeasures;
27
27
  /** The measures of one structured document, from its Policies once normalized. */
28
28
  export declare function measureDomainPolicies(schema: DomainSchemaIR, normalized?: ReadonlyMap<string, PolicyExpression>): PolicyMeasures;
29
- /** `PL_BUDGET`: every measure of the document within `limits.policy`. */
29
+ /**
30
+ * `PL_BUDGET`: every measure of the document within `limits.policy`. Typing expands what stays in
31
+ * `normalized`, and a Policy without a measure within them has no bound on its expansion, so it
32
+ * leaves: it is refused here or by `PL_REF` or `PL_COMPOSITION`, and whatever composes it with it.
33
+ */
30
34
  export declare function validatePolicyBudgets(context: PolicyValidationContext): void;
31
35
  /**
32
36
  * `PL_BUDGET` for one check tree at `pointer`, from its measure: the document's trees, and the
@@ -35,11 +35,18 @@ export function measureDomainPolicies(schema, normalized = normalizedPolicies(sc
35
35
  }
36
36
  return deepFreeze({ policies, unmeasured, checks });
37
37
  }
38
- /** `PL_BUDGET`: every measure of the document within `limits.policy`. */
38
+ /**
39
+ * `PL_BUDGET`: every measure of the document within `limits.policy`. Typing expands what stays in
40
+ * `normalized`, and a Policy without a measure within them has no bound on its expansion, so it
41
+ * leaves: it is refused here or by `PL_REF` or `PL_COMPOSITION`, and whatever composes it with it.
42
+ */
39
43
  export function validatePolicyBudgets(context) {
40
44
  const measures = measureDomainPolicies(context.environment.candidate, context.normalized);
45
+ for (const name of measures.unmeasured)
46
+ context.normalized.delete(name);
41
47
  for (const [name, measure] of Object.entries(measures.policies)) {
42
48
  for (const limit of exceededLimits(measure)) {
49
+ context.normalized.delete(name);
43
50
  context.add('PL_BUDGET', `/policies/${escapePointerToken(name)}`, REFUSAL[limit](measure));
44
51
  }
45
52
  }