@astrale-os/kernel-dsl 1.0.0-beta.11 → 1.0.0-beta.13

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 (167) hide show
  1. package/dist/v1/addressing/definition-ref.js +21 -37
  2. package/dist/v1/addressing/ordering.d.ts +2 -0
  3. package/dist/v1/addressing/ordering.js +4 -0
  4. package/dist/v1/addressing/patterns.d.ts +0 -1
  5. package/dist/v1/addressing/patterns.js +0 -5
  6. package/dist/v1/builder/callable/authoring.d.ts +1 -1
  7. package/dist/v1/builder/class/authoring.d.ts +6 -256
  8. package/dist/v1/builder/class/authoring.js +5 -28
  9. package/dist/v1/builder/class/handle.d.ts +27 -0
  10. package/dist/v1/builder/class/handle.js +1 -0
  11. package/dist/v1/builder/class/input.d.ts +129 -0
  12. package/dist/v1/builder/class/projection.d.ts +129 -0
  13. package/dist/v1/builder/class/projection.js +1 -0
  14. package/dist/v1/builder/core/authoring.d.ts +1 -1
  15. package/dist/v1/builder/index.d.ts +3 -1
  16. package/dist/v1/builder/lowering/class.d.ts +1 -1
  17. package/dist/v1/builder/lowering/schema/context.d.ts +2 -1
  18. package/dist/v1/builder/lowering/schema/context.js +2 -4
  19. package/dist/v1/builder/lowering/value/path.d.ts +1 -1
  20. package/dist/v1/builder/lowering/value/path.js +2 -4
  21. package/dist/v1/builder/lowering/value/zod.js +1 -3
  22. package/dist/v1/builder/policy/authoring.d.ts +1 -1
  23. package/dist/v1/builder/schema/define.d.ts +0 -1
  24. package/dist/v1/builder/schema/diagnostic.d.ts +2 -1
  25. package/dist/v1/builder/schema/diagnostic.js +5 -10
  26. package/dist/v1/builder/schema/input.d.ts +1 -1
  27. package/dist/v1/builder/schema/projection/class.d.ts +2 -1
  28. package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
  29. package/dist/v1/builder/schema/projection/identity.d.ts +2 -1
  30. package/dist/v1/builder/schema/projection/property.d.ts +1 -1
  31. package/dist/v1/builder/schema/projection.d.ts +1 -1
  32. package/dist/v1/builder/value/full-match.d.ts +0 -1
  33. package/dist/v1/builder/value/full-match.js +0 -1
  34. package/dist/v1/builder/value/path-metadata.d.ts +1 -1
  35. package/dist/v1/builder/value/path.d.ts +1 -1
  36. package/dist/v1/bundle/codec.js +2 -4
  37. package/dist/v1/bundle/diagnostic.js +3 -7
  38. package/dist/v1/bundle/structure.js +2 -4
  39. package/dist/v1/compiled/admission/diagnostic.d.ts +1 -1
  40. package/dist/v1/compiled/admission/diagnostic.js +1 -3
  41. package/dist/v1/compiled/admission/revision.d.ts +9 -1
  42. package/dist/v1/compiled/admission/revision.js +6 -3
  43. package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
  44. package/dist/v1/compiled/admission/semantics/class.js +4 -8
  45. package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
  46. package/dist/v1/compiled/admission/semantics/core.js +54 -34
  47. package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
  48. package/dist/v1/compiled/admission/semantics/edge.js +6 -65
  49. package/dist/v1/compiled/admission/semantics/policy/callable.js +0 -2
  50. package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
  51. package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
  52. package/dist/v1/compiled/admission/semantics/policy/parity.js +13 -22
  53. package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
  54. package/dist/v1/compiled/admission/semantics/policy/pattern.js +4 -16
  55. package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
  56. package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
  57. package/dist/v1/compiled/compiler/compile.js +6 -8
  58. package/dist/v1/compiled/diagnostic.js +2 -3
  59. package/dist/v1/compiled/loader/load.d.ts +3 -2
  60. package/dist/v1/compiled/loader/load.js +10 -44
  61. package/dist/v1/domain/create.js +3 -5
  62. package/dist/v1/domain/namespace/member-collection.js +4 -6
  63. package/dist/v1/domain/validation/create.d.ts +0 -1
  64. package/dist/v1/domain/validation/create.js +0 -35
  65. package/dist/v1/language/class/inheritance.d.ts +18 -0
  66. package/dist/v1/language/class/inheritance.js +73 -0
  67. package/dist/v1/language/class/property-values.js +2 -4
  68. package/dist/v1/language/core/facts.d.ts +72 -0
  69. package/dist/v1/language/core/facts.js +95 -0
  70. package/dist/v1/language/index.d.ts +1 -0
  71. package/dist/v1/language/index.js +1 -0
  72. package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
  73. package/dist/v1/language/policy/analysis/branches.js +2 -1
  74. package/dist/v1/language/policy/analysis/budgets.d.ts +13 -1
  75. package/dist/v1/language/policy/analysis/budgets.js +104 -0
  76. package/dist/v1/language/policy/analysis/typing.d.ts +48 -0
  77. package/dist/v1/language/policy/analysis/typing.js +338 -0
  78. package/dist/v1/language/validation/diagnostic.d.ts +15 -1
  79. package/dist/v1/language/validation/diagnostic.js +21 -0
  80. package/dist/v1/language/value/compile/fields.js +4 -8
  81. package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
  82. package/dist/v1/language/value/inclusion/arrays.js +85 -0
  83. package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
  84. package/dist/v1/language/value/inclusion/assertions.js +29 -0
  85. package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
  86. package/dist/v1/language/value/inclusion/combinators.js +67 -0
  87. package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
  88. package/dist/v1/language/value/inclusion/equivalence.js +74 -0
  89. package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
  90. package/dist/v1/language/value/inclusion/evidence.js +138 -0
  91. package/dist/v1/language/value/inclusion/includes.d.ts +17 -0
  92. package/dist/v1/language/value/inclusion/includes.js +25 -719
  93. package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
  94. package/dist/v1/language/value/inclusion/keywords.js +31 -0
  95. package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
  96. package/dist/v1/language/value/inclusion/kinds.js +57 -0
  97. package/dist/v1/language/value/inclusion/location.d.ts +24 -0
  98. package/dist/v1/language/value/inclusion/location.js +63 -0
  99. package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
  100. package/dist/v1/language/value/inclusion/numbers.js +41 -0
  101. package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
  102. package/dist/v1/language/value/inclusion/objects.js +190 -0
  103. package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
  104. package/dist/v1/language/value/inclusion/strings.js +29 -0
  105. package/dist/v1/language/value/inclusion/types.d.ts +3 -0
  106. package/dist/v1/language/value/inclusion/types.js +11 -0
  107. package/dist/v1/language/value/ordering.d.ts +9 -0
  108. package/dist/v1/language/value/ordering.js +72 -9
  109. package/dist/v1/language/value/profile/rules.js +5 -7
  110. package/dist/v1/language/value/profile/validate.js +1 -10
  111. package/dist/v1/language/value/reference/recursion.js +2 -22
  112. package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
  113. package/dist/v1/language/value/syntax/pointer.js +5 -2
  114. package/dist/v1/language/value/syntax/walk.d.ts +2 -0
  115. package/dist/v1/language/value/syntax/walk.js +19 -20
  116. package/dist/v1/schema/compatibility/diff.js +2 -4
  117. package/dist/v1/schema/compatibility/meaning/footprint.js +16 -50
  118. package/dist/v1/schema/compatibility/structure/requirements.js +26 -58
  119. package/dist/v1/schema/compatibility/walk.d.ts +17 -0
  120. package/dist/v1/schema/compatibility/walk.js +41 -0
  121. package/dist/v1/schema/diagnostic.js +3 -11
  122. package/dist/v1/schema/resolution/context.js +3 -5
  123. package/dist/v1/schema/validation/callable.js +3 -5
  124. package/dist/v1/schema/validation/class.js +10 -52
  125. package/dist/v1/schema/validation/core.js +65 -199
  126. package/dist/v1/schema/validation/domain.js +1 -10
  127. package/dist/v1/schema/validation/domain.structure.js +2 -4
  128. package/dist/v1/schema/validation/policy/budgets.js +5 -112
  129. package/dist/v1/schema/validation/policy/context.d.ts +5 -3
  130. package/dist/v1/schema/validation/policy/context.js +5 -3
  131. package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
  132. package/dist/v1/schema/validation/policy/objects.js +6 -14
  133. package/dist/v1/schema/validation/policy/references.js +5 -6
  134. package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
  135. package/dist/v1/schema/validation/policy/typing.js +22 -356
  136. package/dist/v1/schema/validation/policy/uses.d.ts +1 -1
  137. package/dist/v1/schema/validation/policy/uses.js +9 -22
  138. package/dist/v1/schema/validation/policy/validate.js +3 -2
  139. package/dist/v1/schema/validation/value-api.d.ts +9 -0
  140. package/dist/v1/schema/validation/value-api.js +23 -1
  141. package/dist/v1/schema/validation/value.js +5 -7
  142. package/dist/v1/schema/validation/view.js +4 -8
  143. package/dist/value/canonical.d.ts +3 -2
  144. package/dist/value/canonical.js +30 -6
  145. package/dist/value/decode.d.ts +7 -0
  146. package/dist/value/decode.js +159 -9
  147. package/dist/value/index.d.ts +1 -1
  148. package/dist/value/json.d.ts +1 -1
  149. package/dist/value/json.js +1 -1
  150. package/dist/value/types.d.ts +6 -0
  151. package/dist/value/unicode.d.ts +2 -1
  152. package/dist/value/unicode.js +2 -0
  153. package/package.json +1 -1
  154. package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
  155. package/dist/v1/compiled/admission/semantics/cardinality.js +0 -128
  156. package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
  157. package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
  158. package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
  159. package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
  160. package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
  161. package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
  162. package/dist/v1/language/class/index.d.ts +0 -8
  163. package/dist/v1/language/class/index.js +0 -1
  164. package/dist/v1/language/core/index.d.ts +0 -2
  165. package/dist/v1/language/value/index.d.ts +0 -11
  166. package/dist/v1/language/value/index.js +0 -8
  167. /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
@@ -0,0 +1,74 @@
1
+ import { jsonEqual } from '../evaluate/assertions.js';
2
+ import { INERT } from './keywords.js';
3
+ import { at, referenceOf, schemaOf } from './location.js';
4
+ /** Keywords whose subschemas the equivalence check compares positionally. */
5
+ const SUBSCHEMA_KEYWORDS = new Set([
6
+ 'additionalProperties',
7
+ 'allOf',
8
+ 'anyOf',
9
+ 'contains',
10
+ 'dependentSchemas',
11
+ 'else',
12
+ 'if',
13
+ 'items',
14
+ 'not',
15
+ 'oneOf',
16
+ 'patternProperties',
17
+ 'prefixItems',
18
+ 'properties',
19
+ 'propertyNames',
20
+ 'then',
21
+ 'unevaluatedItems',
22
+ 'unevaluatedProperties',
23
+ ]);
24
+ /** Whether the two locations are bisimilar: equal assertions over paired subschemas. */
25
+ export function equivalent(inclusion, left, right) {
26
+ const pending = [[left, right]];
27
+ const seen = new Set();
28
+ while (pending.length > 0) {
29
+ const [first, second] = pending.pop();
30
+ const key = inclusion.pair(first, second);
31
+ if (seen.has(key))
32
+ continue;
33
+ seen.add(key);
34
+ const a = schemaOf(first);
35
+ const b = schemaOf(second);
36
+ if (typeof a === 'boolean' || typeof b === 'boolean') {
37
+ if (a !== b)
38
+ return false;
39
+ continue;
40
+ }
41
+ const assertions = assertionKeys(a);
42
+ if (assertions.length !== assertionKeys(b).length)
43
+ return false;
44
+ for (const keyword of assertions) {
45
+ if (!Object.hasOwn(b, keyword) || !jsonEqual(a[keyword], b[keyword]))
46
+ return false;
47
+ }
48
+ const firstChildren = subschemaChildren(first);
49
+ const secondChildren = subschemaChildren(second);
50
+ if (firstChildren.size !== secondChildren.size)
51
+ return false;
52
+ for (const [path, index] of firstChildren) {
53
+ const other = secondChildren.get(path);
54
+ if (other === undefined)
55
+ return false;
56
+ pending.push([at(first.program, index), at(second.program, other)]);
57
+ }
58
+ const firstReference = referenceOf(first);
59
+ const secondReference = referenceOf(second);
60
+ if ((firstReference === undefined) !== (secondReference === undefined))
61
+ return false;
62
+ if (firstReference !== undefined)
63
+ pending.push([firstReference, secondReference]);
64
+ }
65
+ return true;
66
+ }
67
+ function assertionKeys(schema) {
68
+ return Object.keys(schema).filter((keyword) => !INERT.has(keyword) && !SUBSCHEMA_KEYWORDS.has(keyword) && keyword !== '$ref');
69
+ }
70
+ /** Subschema children keyed by their keyword path, without `$defs` or inert annotations. */
71
+ function subschemaChildren(location) {
72
+ const children = location.program.nodes[location.index]?.children ?? {};
73
+ return new Map(Object.entries(children).filter(([path]) => SUBSCHEMA_KEYWORDS.has(path.split('/', 1)[0].replaceAll('~1', '/').replaceAll('~0', '~'))));
74
+ }
@@ -0,0 +1,34 @@
1
+ import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
+ import type { At } from './location.js';
3
+ /** One numeric bound, inclusive unless `exclusive`. */
4
+ export interface Bound {
5
+ readonly value: number;
6
+ readonly exclusive: boolean;
7
+ }
8
+ /** Over-approximation of the values one location admits, collected from its conjuncts. */
9
+ export interface Evidence {
10
+ /** The location, its `$ref` targets and its `allOf` branches, transitively. */
11
+ readonly conjuncts: readonly At[];
12
+ readonly kinds: number;
13
+ /** A finite superset of the admitted values, when one is known. */
14
+ readonly values?: readonly JsonValue[];
15
+ readonly upper?: Bound;
16
+ readonly lower?: Bound;
17
+ readonly multipleOf: readonly number[];
18
+ readonly maxLength?: number;
19
+ readonly minLength: number;
20
+ readonly patterns: ReadonlySet<string>;
21
+ readonly fullMatches: ReadonlySet<string>;
22
+ readonly maxItems?: number;
23
+ readonly minItems: number;
24
+ readonly uniqueItems: boolean;
25
+ readonly maxProperties?: number;
26
+ readonly minProperties: number;
27
+ readonly required: ReadonlySet<string>;
28
+ readonly dependentRequired: ReadonlyMap<string, ReadonlySet<string>>;
29
+ readonly valueKinds: ReadonlySet<string>;
30
+ }
31
+ /** Whether `evidence` may admit a value of one of `kinds`. */
32
+ export declare function has(evidence: Evidence, kinds: number): boolean;
33
+ /** The evidence the conjuncts of `location` carry together. */
34
+ export declare function evidenceOf(location: At): Evidence;
@@ -0,0 +1,138 @@
1
+ import { jsonEqual } from '../evaluate/assertions.js';
2
+ import { isValueObject as isJsonObject } from '../model/object.js';
3
+ import { ANY, OBJECT, STRING, finiteKinds, kindOf, typeMask } from './kinds.js';
4
+ import { conjunctsOf, schemaOf } from './location.js';
5
+ /** Whether `evidence` may admit a value of one of `kinds`. */
6
+ export function has(evidence, kinds) {
7
+ return (evidence.kinds & kinds) !== 0;
8
+ }
9
+ /** The evidence the conjuncts of `location` carry together. */
10
+ export function evidenceOf(location) {
11
+ const conjuncts = conjunctsOf(location);
12
+ let kinds = ANY;
13
+ let values;
14
+ let upper;
15
+ let lower;
16
+ const multipleOf = [];
17
+ let maxLength;
18
+ let minLength = 0;
19
+ const patterns = new Set();
20
+ const fullMatches = new Set();
21
+ let maxItems;
22
+ let minItems = 0;
23
+ let uniqueItems = false;
24
+ let maxProperties;
25
+ let minProperties = 0;
26
+ const required = new Set();
27
+ const dependentRequired = new Map();
28
+ const valueKinds = new Set();
29
+ const narrow = (candidates) => {
30
+ values =
31
+ values === undefined
32
+ ? [...candidates]
33
+ : values.filter((value) => candidates.some((candidate) => jsonEqual(value, candidate)));
34
+ };
35
+ for (const conjunct of conjuncts) {
36
+ const schema = schemaOf(conjunct);
37
+ if (schema === false)
38
+ kinds = 0;
39
+ if (!isJsonObject(schema))
40
+ continue;
41
+ kinds &= typeMask(schema.type);
42
+ if (Object.hasOwn(schema, 'const')) {
43
+ narrow([schema.const]);
44
+ kinds &= kindOf(schema.const);
45
+ }
46
+ if (Array.isArray(schema.enum)) {
47
+ narrow(schema.enum);
48
+ kinds &= schema.enum.reduce((mask, value) => mask | kindOf(value), 0);
49
+ }
50
+ const valueKind = schema['x-astrale-value-kind'];
51
+ if (typeof valueKind === 'string') {
52
+ valueKinds.add(valueKind);
53
+ if (valueKind === 'instant')
54
+ kinds &= STRING;
55
+ if (valueKind === 'blob')
56
+ kinds &= OBJECT;
57
+ }
58
+ upper = tighter(upper, schema.maximum, false, (a, b) => a < b);
59
+ upper = tighter(upper, schema.exclusiveMaximum, true, (a, b) => a < b);
60
+ lower = tighter(lower, schema.minimum, false, (a, b) => a > b);
61
+ lower = tighter(lower, schema.exclusiveMinimum, true, (a, b) => a > b);
62
+ if (typeof schema.multipleOf === 'number')
63
+ multipleOf.push(schema.multipleOf);
64
+ if (typeof schema.maxLength === 'number')
65
+ maxLength = min(maxLength, schema.maxLength);
66
+ if (typeof schema.minLength === 'number')
67
+ minLength = Math.max(minLength, schema.minLength);
68
+ if (typeof schema.pattern === 'string')
69
+ patterns.add(schema.pattern);
70
+ if (typeof schema.fullMatch === 'string')
71
+ fullMatches.add(schema.fullMatch);
72
+ if (typeof schema.maxItems === 'number')
73
+ maxItems = min(maxItems, schema.maxItems);
74
+ if (typeof schema.minItems === 'number')
75
+ minItems = Math.max(minItems, schema.minItems);
76
+ if (schema.uniqueItems === true)
77
+ uniqueItems = true;
78
+ if (typeof schema.maxProperties === 'number') {
79
+ maxProperties = min(maxProperties, schema.maxProperties);
80
+ }
81
+ if (typeof schema.minProperties === 'number') {
82
+ minProperties = Math.max(minProperties, schema.minProperties);
83
+ }
84
+ if (Array.isArray(schema.required)) {
85
+ for (const name of schema.required)
86
+ if (typeof name === 'string')
87
+ required.add(name);
88
+ }
89
+ if (isJsonObject(schema.dependentRequired)) {
90
+ for (const [name, dependencies] of Object.entries(schema.dependentRequired)) {
91
+ if (!Array.isArray(dependencies))
92
+ continue;
93
+ const known = dependentRequired.get(name) ?? new Set();
94
+ for (const dependency of dependencies) {
95
+ if (typeof dependency === 'string')
96
+ known.add(dependency);
97
+ }
98
+ dependentRequired.set(name, known);
99
+ }
100
+ }
101
+ }
102
+ const finite = values === undefined
103
+ ? finiteKinds(kinds)
104
+ : values.filter((value) => (kindOf(value) & kinds) !== 0);
105
+ return Object.freeze({
106
+ conjuncts,
107
+ kinds,
108
+ ...(finite === undefined ? {} : { values: finite }),
109
+ ...(upper === undefined ? {} : { upper }),
110
+ ...(lower === undefined ? {} : { lower }),
111
+ multipleOf,
112
+ ...(maxLength === undefined ? {} : { maxLength }),
113
+ minLength,
114
+ patterns,
115
+ fullMatches,
116
+ ...(maxItems === undefined ? {} : { maxItems }),
117
+ minItems,
118
+ uniqueItems,
119
+ ...(maxProperties === undefined ? {} : { maxProperties }),
120
+ minProperties,
121
+ required,
122
+ dependentRequired,
123
+ valueKinds,
124
+ });
125
+ }
126
+ function tighter(current, value, exclusive, stricter) {
127
+ if (typeof value !== 'number')
128
+ return current;
129
+ if (current === undefined ||
130
+ stricter(value, current.value) ||
131
+ (value === current.value && exclusive)) {
132
+ return { value, exclusive };
133
+ }
134
+ return current;
135
+ }
136
+ function min(current, value) {
137
+ return current === undefined ? value : Math.min(current, value);
138
+ }
@@ -1,4 +1,6 @@
1
1
  import type { ValueProgram } from '../compile/model.js';
2
+ import type { Evidence } from './evidence.js';
3
+ import type { At } from './location.js';
2
4
  /**
3
5
  * Whether `outer` admits every value `inner` admits, under the one V1 evaluator.
4
6
  *
@@ -7,3 +9,18 @@ import type { ValueProgram } from '../compile/model.js';
7
9
  * `inner`; a finite `inner` is decided exactly by evaluating its candidates.
8
10
  */
9
11
  export declare function valueProgramIncludes(outer: ValueProgram, inner: ValueProgram): boolean;
12
+ /** One inclusion question: the decided pairs, the pairs being decided and the evidence cache. */
13
+ export declare class Inclusion {
14
+ private readonly programs;
15
+ private readonly decided;
16
+ private readonly pending;
17
+ private readonly evidenceByAt;
18
+ /** Whether `outer` admits every value `inner` admits; a cyclic premise proves nothing. */
19
+ includes(outer: At, inner: At): boolean;
20
+ /** The evidence of one location, computed once per question. */
21
+ evidence(location: At): Evidence;
22
+ /** A key identifying an ordered pair of locations within this question. */
23
+ pair(outer: At, inner: At): string;
24
+ private decide;
25
+ private location;
26
+ }