@astrale-os/kernel-dsl 0.2.0-beta.45 → 0.2.0-beta.47

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 (76) hide show
  1. package/dist/v1/addressing/class-key.js +5 -4
  2. package/dist/v1/addressing/method-key.js +3 -2
  3. package/dist/v1/builder/class/property.d.ts +3 -1
  4. package/dist/v1/builder/class/property.js +9 -1
  5. package/dist/v1/builder/lowering/schema/compile.js +1 -1
  6. package/dist/v1/builder/lowering/value/compile.js +3 -0
  7. package/dist/v1/builder/lowering/value/zod.js +11 -2
  8. package/dist/v1/builder/lowering/view.d.ts +2 -2
  9. package/dist/v1/builder/lowering/view.js +2 -14
  10. package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
  11. package/dist/v1/builder/value/full-match.js +6 -3
  12. package/dist/v1/builder/view/authoring.d.ts +3 -7
  13. package/dist/v1/builder/view/authoring.js +5 -2
  14. package/dist/v1/compiled/admission/accept.js +31 -6
  15. package/dist/v1/compiled/admission/semantics.js +49 -16
  16. package/dist/v1/compiled/compiler/compile.js +1 -0
  17. package/dist/v1/compiled/loader/load.js +1 -0
  18. package/dist/v1/domain/create.js +0 -19
  19. package/dist/v1/domain/model/domain.d.ts +0 -1
  20. package/dist/v1/domain/model/input.d.ts +3 -0
  21. package/dist/v1/domain/projection/classes.js +1 -0
  22. package/dist/v1/domain/validation/create.d.ts +2 -0
  23. package/dist/v1/domain/validation/create.js +12 -0
  24. package/dist/v1/language/class/model/property.d.ts +3 -0
  25. package/dist/v1/language/class/resolved.d.ts +3 -0
  26. package/dist/v1/language/index.d.ts +2 -0
  27. package/dist/v1/language/index.js +1 -0
  28. package/dist/v1/language/policy/normalization/normalize.d.ts +4 -0
  29. package/dist/v1/language/policy/normalization/normalize.js +51 -13
  30. package/dist/v1/language/value/inclusion/includes.d.ts +9 -0
  31. package/dist/v1/language/value/inclusion/includes.js +777 -0
  32. package/dist/v1/language/value/profile/rules.js +11 -32
  33. package/dist/v1/language/value/regexp/ast.js +3 -64
  34. package/dist/v1/language/value/regexp/compile.d.ts +25 -2
  35. package/dist/v1/language/value/regexp/compile.js +48 -12
  36. package/dist/v1/language/value/regexp/syntax.d.ts +11 -1
  37. package/dist/v1/language/value/regexp/syntax.js +14 -2
  38. package/dist/v1/language/value/regexp/unicode.d.ts +32 -0
  39. package/dist/v1/language/value/regexp/unicode.js +139 -0
  40. package/dist/v1/language/value/syntax/full-match.js +6 -3
  41. package/dist/v1/language/view/model/view.d.ts +6 -0
  42. package/dist/v1/language/view/resolved.d.ts +2 -2
  43. package/dist/v1/schema/analysis/class.d.ts +2 -1
  44. package/dist/v1/schema/analysis/class.js +1 -0
  45. package/dist/v1/schema/compatibility/comparators/callables.d.ts +7 -0
  46. package/dist/v1/schema/compatibility/comparators/callables.js +13 -0
  47. package/dist/v1/schema/compatibility/comparators/classes.d.ts +18 -0
  48. package/dist/v1/schema/compatibility/comparators/classes.js +54 -0
  49. package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
  50. package/dist/v1/schema/compatibility/comparators/index.js +14 -2
  51. package/dist/v1/schema/compatibility/context.d.ts +6 -2
  52. package/dist/v1/schema/compatibility/context.js +12 -6
  53. package/dist/v1/schema/compatibility/evidence.d.ts +8 -1
  54. package/dist/v1/schema/compatibility/evidence.js +10 -1
  55. package/dist/v1/schema/compatibility/fields.d.ts +2 -0
  56. package/dist/v1/schema/compatibility/fields.js +1 -0
  57. package/dist/v1/schema/compatibility/meaning/footprint.js +3 -1
  58. package/dist/v1/schema/compatibility/meaning/index.js +4 -2
  59. package/dist/v1/schema/compatibility/model.d.ts +11 -6
  60. package/dist/v1/schema/compatibility/references.d.ts +8 -1
  61. package/dist/v1/schema/compatibility/references.js +39 -6
  62. package/dist/v1/schema/compatibility/scope.d.ts +5 -0
  63. package/dist/v1/schema/compatibility/scope.js +5 -2
  64. package/dist/v1/schema/compatibility/structure/index.js +21 -2
  65. package/dist/v1/schema/compatibility/structure/requirements.js +26 -1
  66. package/dist/v1/schema/compatibility/subjects.js +20 -2
  67. package/dist/v1/schema/diagnostic.d.ts +1 -1
  68. package/dist/v1/schema/normalization/domain.js +1 -0
  69. package/dist/v1/schema/resolution/domain.d.ts +4 -1
  70. package/dist/v1/schema/resolution/domain.js +7 -7
  71. package/dist/v1/schema/resolution/origins.d.ts +11 -4
  72. package/dist/v1/schema/resolution/origins.js +7 -8
  73. package/dist/v1/schema/validation/class.d.ts +10 -0
  74. package/dist/v1/schema/validation/class.js +13 -2
  75. package/dist/v1/schema/validation/domain.structure.js +1 -0
  76. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  export { isMethodExecutable } from './callable/executable.js';
2
2
  export { isBinaryInput } from './callable/model/callable.js';
3
+ export { valueProgramIncludes } from './value/inclusion/includes.js';
3
4
  export { stateMachine } from './state/index.js';
4
5
  export { PropertyValues } from './class/property-values.js';
5
6
  export { policyVariableClass, policyVariableSelector, policyObjectKey, policyObjectOrigin, projectedMemberClass, } from './policy/model/policy.js';
@@ -1,4 +1,8 @@
1
1
  import type { PolicyCheckExpression, PolicyExpression, PolicyPatternExpression } from '../model/policy.js';
2
2
  export declare function normalizePolicyExpression(value: PolicyExpression): PolicyExpression;
3
+ /**
4
+ * The fixed point of the single pass: a Pattern the single pass reproduces is returned unchanged,
5
+ * so the canonical form of every Pattern that was already stable keeps its bytes.
6
+ */
3
7
  export declare function normalizePolicyPattern(value: PolicyPatternExpression): PolicyPatternExpression;
4
8
  export declare function normalizePolicyChecks(value: PolicyCheckExpression): PolicyCheckExpression;
@@ -10,7 +10,32 @@ export function normalizePolicyExpression(value) {
10
10
  }
11
11
  return { anyOf: uniqueRefs(value.anyOf) };
12
12
  }
13
+ /**
14
+ * Passes after the first, while one still changes the Pattern. A pass numbers variables by the
15
+ * operands as written, then merges duplicate operands and flattens nested ones, so its result can
16
+ * number differently when normalized again; the next pass numbers that result by itself. One
17
+ * further pass reached the fixed point on every Pattern tested, the other is margin, and a
18
+ * Pattern still changing keeps its last pass rather than failing.
19
+ */
20
+ const SETTLING_PASSES = 2;
21
+ /**
22
+ * The fixed point of the single pass: a Pattern the single pass reproduces is returned unchanged,
23
+ * so the canonical form of every Pattern that was already stable keeps its bytes.
24
+ */
13
25
  export function normalizePolicyPattern(value) {
26
+ let current = normalizePatternOnce(value);
27
+ let encoding = json.serialize(current);
28
+ for (let pass = 0; pass < SETTLING_PASSES; pass++) {
29
+ const next = normalizePatternOnce(current);
30
+ const nextEncoding = json.serialize(next);
31
+ if (nextEncoding === encoding)
32
+ return current;
33
+ current = next;
34
+ encoding = nextEncoding;
35
+ }
36
+ return current;
37
+ }
38
+ function normalizePatternOnce(value) {
14
39
  const rewritten = rewriteVariables(value, canonicalVariableIds(value));
15
40
  return normalizePatternNode(rewritten);
16
41
  }
@@ -71,7 +96,8 @@ function normalizePatternNode(value) {
71
96
  }
72
97
  function canonicalVariableIds(value) {
73
98
  const declarations = new Map();
74
- collectDeclarations(value, declarations);
99
+ const depths = new Map();
100
+ collectDeclarations(value, declarations, depths);
75
101
  const uses = new Map([...declarations.keys()].map((id) => [id, []]));
76
102
  collectUses(value, uses);
77
103
  let colors = declarations;
@@ -89,8 +115,15 @@ function canonicalVariableIds(value) {
89
115
  break;
90
116
  colors = next;
91
117
  }
118
+ // Colors ignore where a variable is declared, so two variables can tie on color although
119
+ // different `exists` declare them, and which of them is numbered first decides which `exists`
120
+ // declares the smaller id. Their declaration depth tells them apart where it differs: operands of
121
+ // equal signature are ordered by their signature over depth-scoped colors before authored order,
122
+ // and the final order compares depth before the authored id (decision
123
+ // `policy-pattern-canonical-ties`). Both keys only order what color and first use leave tied.
124
+ const scoped = new Map([...colors].map(([id, color]) => [id, `${color}@${depths.get(id) ?? 0}`]));
92
125
  const firstUse = new Map();
93
- collectFirstUseKeys(value, colors, firstUse);
126
+ collectFirstUseKeys(value, colors, scoped, firstUse);
94
127
  const ordered = [...declarations.keys()].sort((left, right) => {
95
128
  const byColor = compareUtf8Bytes(colors.get(left) ?? '', colors.get(right) ?? '');
96
129
  if (byColor !== 0)
@@ -98,26 +131,31 @@ function canonicalVariableIds(value) {
98
131
  const byUse = compareUtf8Bytes(firstUse.get(left) ?? '', firstUse.get(right) ?? '');
99
132
  if (byUse !== 0)
100
133
  return byUse;
101
- // A remaining tie is an automorphic binder class: assigning either first
102
- // yields the same recursively sorted canonical Pattern.
134
+ const byDepth = (depths.get(left) ?? 0) - (depths.get(right) ?? 0);
135
+ if (byDepth !== 0)
136
+ return byDepth;
137
+ // A remaining tie keeps the authored order of the ids: such variables were interchangeable in
138
+ // every admissible Pattern checked (`__tests__/canonical.test.ts`).
103
139
  return left - right;
104
140
  });
105
141
  return new Map(ordered.map((id, index) => [id, index]));
106
142
  }
107
- function collectDeclarations(value, result) {
143
+ /** Each declared variable's selector signature and the number of `exists` around its declaration. */
144
+ function collectDeclarations(value, result, depths, depth = 0) {
108
145
  if ('exists' in value) {
109
146
  for (const node of value.exists.nodes) {
110
147
  result.set(node.variable.id, selectorSignature(node));
148
+ depths.set(node.variable.id, depth + 1);
111
149
  }
112
- collectDeclarations(value.exists.where, result);
150
+ collectDeclarations(value.exists.where, result, depths, depth + 1);
113
151
  return;
114
152
  }
115
153
  if ('allOf' in value)
116
154
  for (const child of value.allOf)
117
- collectDeclarations(child, result);
155
+ collectDeclarations(child, result, depths, depth);
118
156
  if ('anyOf' in value)
119
157
  for (const child of value.anyOf)
120
- collectDeclarations(child, result);
158
+ collectDeclarations(child, result, depths, depth);
121
159
  }
122
160
  function collectUses(value, result) {
123
161
  if ('sameNode' in value) {
@@ -155,7 +193,7 @@ function termColor(term, colors) {
155
193
  return `ref:${term.ref.kind === 'method' ? policyObjectKey(term.ref) : definitionRefIndex(term.ref)}`;
156
194
  return term.kind;
157
195
  }
158
- function collectFirstUseKeys(value, colors, result, prefix = '$') {
196
+ function collectFirstUseKeys(value, colors, scoped, result, prefix = '$') {
159
197
  if ('sameNode' in value) {
160
198
  for (const term of [value.sameNode.left, value.sameNode.right]) {
161
199
  if (term.kind !== 'variable')
@@ -182,15 +220,15 @@ function collectFirstUseKeys(value, colors, result, prefix = '$') {
182
220
  return;
183
221
  }
184
222
  if ('exists' in value) {
185
- collectFirstUseKeys(value.exists.where, colors, result, `${prefix}:exists`);
223
+ collectFirstUseKeys(value.exists.where, colors, scoped, result, `${prefix}:exists`);
186
224
  return;
187
225
  }
188
226
  const key = 'allOf' in value ? 'allOf' : 'anyOf';
189
227
  const operands = 'allOf' in value ? value.allOf : value.anyOf;
190
228
  const children = operands
191
- .map((child) => [patternSignature(child, colors), child])
192
- .sort(([left], [right]) => compareUtf8Bytes(left, right));
193
- children.forEach(([, child], index) => collectFirstUseKeys(child, colors, result, `${prefix}:${key}:${index}`));
229
+ .map((child) => [patternSignature(child, colors), patternSignature(child, scoped), child])
230
+ .sort(([left, leftScoped], [right, rightScoped]) => compareUtf8Bytes(left, right) || compareUtf8Bytes(leftScoped, rightScoped));
231
+ children.forEach(([, , child], index) => collectFirstUseKeys(child, colors, scoped, result, `${prefix}:${key}:${index}`));
194
232
  }
195
233
  function patternSignature(value, colors) {
196
234
  if ('sameNode' in value)
@@ -0,0 +1,9 @@
1
+ import type { ValueProgram } from '../compile/model.js';
2
+ /**
3
+ * Whether `outer` admits every value `inner` admits, under the one V1 evaluator.
4
+ *
5
+ * `true` is a proof. `false` only means that no rule proved inclusion: a caller must then decide
6
+ * the values themselves. Each rule relates one assertion of `outer` to evidence carried by
7
+ * `inner`; a finite `inner` is decided exactly by evaluating its candidates.
8
+ */
9
+ export declare function valueProgramIncludes(outer: ValueProgram, inner: ValueProgram): boolean;