@astrale-os/kernel-dsl 1.0.0-beta.26 → 1.0.0-beta.28

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 (96) hide show
  1. package/dist/v1/addressing/ordering.d.ts +2 -2
  2. package/dist/v1/addressing/ordering.js +2 -4
  3. package/dist/v1/builder/index.d.ts +2 -0
  4. package/dist/v1/builder/index.js +1 -0
  5. package/dist/v1/builder/lowering/schema/compile.js +2 -0
  6. package/dist/v1/builder/schema/input.d.ts +3 -0
  7. package/dist/v1/builder/schema/rule.d.ts +316 -0
  8. package/dist/v1/builder/schema/rule.js +192 -0
  9. package/dist/v1/bundle/index.d.ts +2 -0
  10. package/dist/v1/bundle/index.js +1 -0
  11. package/dist/v1/bundle/rule.d.ts +14 -0
  12. package/dist/v1/bundle/rule.js +41 -0
  13. package/dist/v1/compiled/admission/diagnostic.d.ts +14 -0
  14. package/dist/v1/compiled/admission/diagnostic.js +6 -0
  15. package/dist/v1/compiled/admission/revision.js +1 -0
  16. package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -3
  17. package/dist/v1/compiled/admission/semantics/policy/parity.js +8 -13
  18. package/dist/v1/compiled/admission/semantics/policy/pattern.js +3 -5
  19. package/dist/v1/compiled/admission/wire/entry.js +29 -1
  20. package/dist/v1/compiled/admission/wire/policy.js +16 -11
  21. package/dist/v1/compiled/compiler/compile.js +1 -0
  22. package/dist/v1/compiled/index.d.ts +2 -0
  23. package/dist/v1/compiled/index.js +1 -0
  24. package/dist/v1/compiled/model/schema.d.ts +3 -0
  25. package/dist/v1/compiled/rule.d.ts +49 -0
  26. package/dist/v1/compiled/rule.js +169 -0
  27. package/dist/v1/index.d.ts +1 -0
  28. package/dist/v1/language/callable/admission.js +2 -1
  29. package/dist/v1/language/definition/metadata.d.ts +33 -0
  30. package/dist/v1/language/definition/metadata.js +44 -0
  31. package/dist/v1/language/policy/analysis/branches.js +6 -7
  32. package/dist/v1/language/policy/analysis/budgets.js +8 -6
  33. package/dist/v1/language/policy/analysis/checks.js +5 -4
  34. package/dist/v1/language/policy/analysis/composition.js +2 -2
  35. package/dist/v1/language/policy/analysis/typing.js +3 -2
  36. package/dist/v1/language/policy/model/policy.d.ts +22 -0
  37. package/dist/v1/language/policy/model/policy.js +28 -4
  38. package/dist/v1/language/policy/normalization/normalize.js +33 -56
  39. package/dist/v1/language/value/evaluate/assertions.d.ts +2 -2
  40. package/dist/v1/language/value/evaluate/assertions.js +4 -34
  41. package/dist/v1/language/value/evaluate/evaluator.js +10 -15
  42. package/dist/v1/language/value/evaluate/validity.optimization.js +9 -14
  43. package/dist/v1/language/value/files.js +2 -1
  44. package/dist/v1/language/value/ordering.js +1 -3
  45. package/dist/v1/language/value/profile/canonicalize.js +1 -3
  46. package/dist/v1/language/value/syntax/walk.d.ts +2 -0
  47. package/dist/v1/language/value/syntax/walk.js +4 -0
  48. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +36 -0
  49. package/dist/v1/schema/compatibility/api.d.ts +2 -0
  50. package/dist/v1/schema/compatibility/api.js +1 -0
  51. package/dist/v1/schema/compatibility/rule.d.ts +13 -0
  52. package/dist/v1/schema/compatibility/rule.js +23 -0
  53. package/dist/v1/schema/diagnostic.d.ts +1 -1
  54. package/dist/v1/schema/enforcement/changes.d.ts +590 -0
  55. package/dist/v1/schema/enforcement/changes.js +566 -0
  56. package/dist/v1/schema/enforcement/derived.d.ts +236 -0
  57. package/dist/v1/schema/enforcement/derived.js +243 -0
  58. package/dist/v1/schema/enforcement/dispose.d.ts +308 -0
  59. package/dist/v1/schema/enforcement/dispose.js +275 -0
  60. package/dist/v1/schema/enforcement/facts.d.ts +89 -0
  61. package/dist/v1/schema/enforcement/facts.js +70 -0
  62. package/dist/v1/schema/enforcement/fields.d.ts +65 -0
  63. package/dist/v1/schema/enforcement/fields.js +36 -0
  64. package/dist/v1/schema/enforcement/index.d.ts +39 -0
  65. package/dist/v1/schema/enforcement/index.js +10 -0
  66. package/dist/v1/schema/enforcement/install.d.ts +1634 -0
  67. package/dist/v1/schema/enforcement/install.js +1223 -0
  68. package/dist/v1/schema/enforcement/lifecycle.d.ts +87 -0
  69. package/dist/v1/schema/enforcement/lifecycle.js +91 -0
  70. package/dist/v1/schema/enforcement/model.d.ts +253 -0
  71. package/dist/v1/schema/enforcement/model.js +1 -0
  72. package/dist/v1/schema/enforcement/obligations.d.ts +248 -0
  73. package/dist/v1/schema/enforcement/obligations.js +240 -0
  74. package/dist/v1/schema/enforcement/write.d.ts +1314 -0
  75. package/dist/v1/schema/enforcement/write.js +1017 -0
  76. package/dist/v1/schema/index.d.ts +1 -0
  77. package/dist/v1/schema/index.js +1 -0
  78. package/dist/v1/schema/model/schema.d.ts +3 -0
  79. package/dist/v1/schema/normalization/domain.js +13 -0
  80. package/dist/v1/schema/resolution/origins.js +4 -7
  81. package/dist/v1/schema/rule.d.ts +6 -7
  82. package/dist/v1/schema/rule.js +25 -13
  83. package/dist/v1/schema/validation/domain.js +2 -0
  84. package/dist/v1/schema/validation/domain.structure.d.ts +14 -0
  85. package/dist/v1/schema/validation/domain.structure.js +15 -0
  86. package/dist/v1/schema/validation/icon.d.ts +4 -0
  87. package/dist/v1/schema/validation/icon.js +29 -0
  88. package/dist/v1/schema/validation/policy/references.js +5 -11
  89. package/dist/v1/schema/validation/policy/uses.js +3 -8
  90. package/dist/value/canonical.d.ts +16 -1
  91. package/dist/value/canonical.js +90 -33
  92. package/dist/value/index.d.ts +2 -0
  93. package/dist/value/index.js +1 -0
  94. package/dist/value/rule.d.ts +12 -0
  95. package/dist/value/rule.js +50 -0
  96. package/package.json +5 -1
@@ -6,6 +6,12 @@ export { appendPointer as pointer } from '../../language/value/syntax/pointer.js
6
6
  export function invalid(label, code = 'COMPILED_STRUCTURE_INVALID', path = '') {
7
7
  return invalidCompiled(code, `Invalid compiled Schema ${label}.`, path);
8
8
  }
9
+ /** How a refusal names the Policy checks of each use site and, once typed, their object contract. */
10
+ export const POLICY_CHECK_SITE = {
11
+ callable: { name: 'Callable Policy', objects: 'the callable object contract' },
12
+ class: { name: 'Class rule', objects: 'the Class rule object contract' },
13
+ create: { name: 'Create rule' },
14
+ };
9
15
  /** Report a contextual compiled-language violation at its original source pointer. */
10
16
  export function fail(pointer, message) {
11
17
  return invalidCompiled('COMPILED_SOURCE_INVALID', message, pointer);
@@ -10,6 +10,7 @@ function revisionPreimage(entry) {
10
10
  version: 'v1',
11
11
  origin: entry.origin,
12
12
  name: entry.name,
13
+ ...(entry.icon === undefined ? {} : { icon: entry.icon }),
13
14
  ...(entry.entrypoint === undefined ? {} : { entrypoint: entry.entrypoint }),
14
15
  dependencies: entry.dependencies,
15
16
  classes: Object.fromEntries(entry.definitions.classes.map((definition) => [
@@ -1,5 +1,5 @@
1
1
  import { Key } from '../../../../addressing/index.js';
2
- import {} from '../../../../language/policy/model/policy.js';
2
+ import { PolicyComposition, } from '../../../../language/policy/model/policy.js';
3
3
  import { GRAPH_NODE_PATH_SCHEMA_ID } from '../../../../language/value/syntax/node-path/schema.js';
4
4
  import {} from '../../../model/schema.js';
5
5
  import { fail } from '../../diagnostic.js';
@@ -27,8 +27,7 @@ export function validateCallablePolicy(context, entry, expression, inputIndex, f
27
27
  }
28
28
  return;
29
29
  }
30
- const children = 'allOf' in expression ? expression.allOf : expression.anyOf;
31
- children.forEach((child, index) => validateCallablePolicy(context, entry, child, inputIndex, fields, instanceMethod, `${path}/${index}`));
30
+ PolicyComposition.of(expression).operands.forEach((child, index) => validateCallablePolicy(context, entry, child, inputIndex, fields, instanceMethod, `${path}/${index}`));
32
31
  }
33
32
  function isSingleNodePathField(context, entry, inputIndex, field) {
34
33
  const rootValue = entry.values[inputIndex]?.nodes[entry.values[inputIndex].root]?.schema;
@@ -3,10 +3,10 @@ import { branchesOf, targetMode, isConnected, } from '../../../../language/polic
3
3
  import { exceededLimits, measureChecks, policyMeasurer, } from '../../../../language/policy/analysis/budgets.js';
4
4
  import { neverAdmittedClasses, } from '../../../../language/policy/analysis/checks.js';
5
5
  import {} from '../../../../language/policy/analysis/typing.js';
6
- import { CLASS_OPERATIONS, checksNameTheCaller, isClassRuleChecks, } from '../../../../language/policy/model/policy.js';
6
+ import { CLASS_OPERATIONS, checksNameTheCaller, isClassRuleChecks, PolicyComposition, } from '../../../../language/policy/model/policy.js';
7
7
  import { normalizePolicyExpression } from '../../../../language/policy/normalization/normalize.js';
8
8
  import {} from '../../../model/schema.js';
9
- import { fail } from '../../diagnostic.js';
9
+ import { fail, POLICY_CHECK_SITE } from '../../diagnostic.js';
10
10
  import { isCompiledEdge, } from '../context.js';
11
11
  import { callableObjectContracts } from './contracts.js';
12
12
  import { compiledPolicyTyping } from './typing.js';
@@ -84,17 +84,13 @@ export function validatePolicyParity(context, entry, entryIndex, policies, origi
84
84
  function declarationIndex(entry, kind, name) {
85
85
  return entry.definitions[kind].findIndex(({ ref }) => ref.name === name);
86
86
  }
87
- /** How a refusal names the checks of each site and the contract of their objects. */
88
- const SITE = {
89
- callable: { checks: 'Callable Policy checks', objects: 'the callable object contract' },
90
- class: { checks: 'Class rule checks', objects: 'the Class rule object contract' },
91
- };
92
87
  function validatePolicyChecks(context, typing, entry, expression, input, receiver, path, site, edge) {
88
+ const label = POLICY_CHECK_SITE[site];
93
89
  if (!checksNameTheCaller(expression)) {
94
- fail(path, `${SITE[site].checks} must check a Policy on every branch: sameNode alone names no caller.`);
90
+ fail(path, `${label.name} checks must check a Policy on every branch: sameNode alone names no caller.`);
95
91
  }
96
92
  if (exceededLimits(measureChecks(expression)).length > 0) {
97
- fail(path, `${SITE[site].checks} exceed the V1 depth, branch, or leaf budget.`);
93
+ fail(path, `${label.name} checks exceed the V1 depth, branch, or leaf budget.`);
98
94
  }
99
95
  const leaves = new Map();
100
96
  const visit = (value, pointer) => {
@@ -106,8 +102,7 @@ function validatePolicyChecks(context, typing, entry, expression, input, receive
106
102
  return;
107
103
  }
108
104
  if (!('check' in value)) {
109
- const children = 'allOf' in value ? value.allOf : value.anyOf;
110
- children.forEach((child, index) => visit(child, `${pointer}/${index}`));
105
+ PolicyComposition.of(value).operands.forEach((child, index) => visit(child, `${pointer}/${index}`));
111
106
  return;
112
107
  }
113
108
  if (edge !== undefined && value.object.kind === 'self') {
@@ -123,13 +118,13 @@ function validatePolicyChecks(context, typing, entry, expression, input, receive
123
118
  return;
124
119
  const classes = typing.checkLeafClasses(value.check.name, contracts);
125
120
  if (classes === undefined) {
126
- fail(pointer, `Named Policy is incompatible with ${SITE[site].objects}.`);
121
+ fail(pointer, `Named Policy is incompatible with ${label.objects}.`);
127
122
  }
128
123
  leaves.set(value, classes);
129
124
  };
130
125
  visit(expression, path);
131
126
  const [never] = neverAdmittedClasses(expression, leaves);
132
127
  if (never !== undefined) {
133
- fail(path, `${SITE[site].checks} can never admit ${never[0]} of Class ${never[1]}.`);
128
+ fail(path, `${label.name} checks can never admit ${never[0]} of Class ${never[1]}.`);
134
129
  }
135
130
  }
@@ -1,7 +1,7 @@
1
1
  import { Key } from '../../../../addressing/index.js';
2
2
  import { isMethodExecutable } from '../../../../language/callable/executable.js';
3
3
  import { policyVariableClass } from '../../../../language/index.js';
4
- import {} from '../../../../language/policy/model/policy.js';
4
+ import { PolicyComposition, } from '../../../../language/policy/model/policy.js';
5
5
  import {} from '../../../model/schema.js';
6
6
  import { fail } from '../../diagnostic.js';
7
7
  import {} from '../context.js';
@@ -14,8 +14,7 @@ export function validatePolicyExpression(context, entry, expression, path, local
14
14
  validatePattern(context, expression.match, `${path}/match`, new Set(), new Set());
15
15
  return;
16
16
  }
17
- const values = 'allOf' in expression ? expression.allOf : expression.anyOf;
18
- for (const [index, ref] of values.entries()) {
17
+ for (const [index, ref] of PolicyComposition.of(expression).operands.entries()) {
19
18
  if (ref.origin !== entry.origin || ref.kind !== 'policy' || !local.has(ref.name))
20
19
  fail(`${path}/${index}`, 'Named Policy composition must reference a local Policy.');
21
20
  }
@@ -48,8 +47,7 @@ function validatePattern(context, expression, path, scope, declared) {
48
47
  validatePattern(context, expression.exists.where, `${path}/exists/where`, nested, declared);
49
48
  return;
50
49
  }
51
- const values = 'allOf' in expression ? expression.allOf : expression.anyOf;
52
- values.forEach((value, index) => validatePattern(context, value, `${path}/${index}`, scope, declared));
50
+ PolicyComposition.of(expression).operands.forEach((value, index) => validatePattern(context, value, `${path}/${index}`, scope, declared));
53
51
  }
54
52
  function validatePolicyTerm(context, term, path, scope) {
55
53
  if (term.kind === 'ref' && term.ref.kind === 'method')
@@ -17,13 +17,14 @@ import { compiledView } from './view.js';
17
17
  /** Decode one closure entry and verify its exact semantic revision. */
18
18
  export function entry(input, entryIndex, path, machines) {
19
19
  const value = object(input, `closure[${entryIndex}]`, path);
20
- exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path, ['entrypoint', 'patterns']);
20
+ exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path, ['icon', 'entrypoint', 'patterns']);
21
21
  const origin = originValue(value.origin, 'entry origin', `${path}/origin`);
22
22
  const name = string(value.name, 'entry name', `${path}/name`);
23
23
  if (name.length < metadata.name.minLength ||
24
24
  name.length > metadata.name.maxLength ||
25
25
  !metadata.isDomainNameText(name))
26
26
  invalid('entry name', undefined, `${path}/name`);
27
+ const icon = value.icon === undefined ? undefined : domainIcon(value.icon, `${path}/icon`);
27
28
  const entrypoint = value.entrypoint === undefined
28
29
  ? undefined
29
30
  : definitionRef(value.entrypoint, 'view', 'entry entrypoint', `${path}/entrypoint`);
@@ -56,6 +57,7 @@ export function entry(input, entryIndex, path, machines) {
56
57
  origin,
57
58
  revision,
58
59
  name,
60
+ ...(icon === undefined ? {} : { icon }),
59
61
  ...(entrypoint === undefined ? {} : { entrypoint }),
60
62
  dependencies,
61
63
  definitions: {
@@ -93,3 +95,29 @@ export function entry(input, entryIndex, path, machines) {
93
95
  }
94
96
  return accepted;
95
97
  }
98
+ /** Decode the source Domain icon under the same admission as its source schema (DV_DOMAIN_ICON). */
99
+ function domainIcon(input, path) {
100
+ const value = object(input, 'entry icon', path);
101
+ exact(value, [], 'entry icon', path, metadata.DOMAIN_ICON_SIZES);
102
+ const icon = {};
103
+ for (const size of metadata.DOMAIN_ICON_SIZES) {
104
+ if (value[size] === undefined)
105
+ continue;
106
+ const sizePath = `${path}/${size}`;
107
+ const art = object(value[size], 'entry icon size', sizePath);
108
+ exact(art, ['svg'], 'entry icon size', sizePath, ['dark']);
109
+ const drawing = (variant) => {
110
+ const text = string(art[variant], 'entry icon drawing', `${sizePath}/${variant}`);
111
+ if (metadata.domainIconSvgIssue(text, size) !== undefined)
112
+ invalid('entry icon drawing', undefined, `${sizePath}/${variant}`);
113
+ return text;
114
+ };
115
+ icon[size] = {
116
+ svg: drawing('svg'),
117
+ ...(art.dark === undefined ? {} : { dark: drawing('dark') }),
118
+ };
119
+ }
120
+ if (Object.keys(icon).length === 0)
121
+ invalid('entry icon', undefined, path);
122
+ return icon;
123
+ }
@@ -1,9 +1,15 @@
1
1
  import { equal } from '@astrale-os/kernel-dsl/value';
2
2
  import { Key } from '../../../addressing/index.js';
3
+ import { limits } from '../../../language/limits.js';
3
4
  import { normalizeClassRule } from '../../../language/policy/normalization/normalize.js';
4
- import { invalid, pointer } from '../diagnostic.js';
5
+ import { invalid, pointer, POLICY_CHECK_SITE } from '../diagnostic.js';
5
6
  import { definitionRef, policyObjectRef } from './reference.js';
6
7
  import { object, exact, description, array, unique, boundedInteger, integer, memberName, } from './value.js';
8
+ /**
9
+ * The nesting a decoder follows before refusing: a structural guard for the recursion, far above
10
+ * the depths `limits.policy` admits, which the semantic checks enforce.
11
+ */
12
+ const WIRE_DEPTH = 64;
7
13
  /** Decode a named Policy and its expression grammar. */
8
14
  export function compiledPolicy(input, path) {
9
15
  const value = object(input, 'Policy', path);
@@ -14,7 +20,7 @@ export function compiledPolicy(input, path) {
14
20
  return value;
15
21
  }
16
22
  function policyExpression(input, depth, path) {
17
- if (depth > 64)
23
+ if (depth > WIRE_DEPTH)
18
24
  invalid('Policy expression depth', undefined, path);
19
25
  const value = object(input, 'Policy expression', path);
20
26
  if (Object.hasOwn(value, 'match')) {
@@ -31,7 +37,7 @@ function policyExpression(input, depth, path) {
31
37
  unique(refs.map(Key.of), `Policy ${member}`, memberPath);
32
38
  }
33
39
  function policyPattern(input, depth, path) {
34
- if (depth > 64)
40
+ if (depth > WIRE_DEPTH)
35
41
  invalid('Policy pattern depth', undefined, path);
36
42
  const value = object(input, 'Policy pattern', path);
37
43
  if (Object.hasOwn(value, 'sameNode')) {
@@ -49,7 +55,7 @@ function policyPattern(input, depth, path) {
49
55
  exact(exists, ['nodes', 'where'], 'Policy exists', existsPath);
50
56
  const nodesPath = `${existsPath}/nodes`;
51
57
  const nodes = array(exists.nodes, 'Policy variables', nodesPath);
52
- if (nodes.length < 1 || nodes.length > 4)
58
+ if (nodes.length < 1 || nodes.length > limits.policy.variablesPerExists)
53
59
  invalid('Policy variables', undefined, nodesPath);
54
60
  for (const [index, node] of nodes.entries()) {
55
61
  const variablePath = `${nodesPath}/${index}`;
@@ -97,8 +103,9 @@ function policyPattern(input, depth, path) {
97
103
  const repeatPath = `${path}/repeat`;
98
104
  const repeat = object(value.repeat, 'Policy repeat', repeatPath);
99
105
  exact(repeat, ['min', 'max'], 'Policy repeat', repeatPath);
100
- const minimum = boundedInteger(repeat.min, 0, 3, 'Policy repeat minimum', `${repeatPath}/min`);
101
- const maximum = boundedInteger(repeat.max, 0, 3, 'Policy repeat maximum', `${repeatPath}/max`);
106
+ const { repetition } = limits.policy;
107
+ const minimum = boundedInteger(repeat.min, 0, repetition, 'Policy repeat minimum', `${repeatPath}/min`);
108
+ const maximum = boundedInteger(repeat.max, 0, repetition, 'Policy repeat maximum', `${repeatPath}/max`);
102
109
  if (minimum > maximum)
103
110
  invalid('Policy repeat order', undefined, repeatPath);
104
111
  }
@@ -141,12 +148,10 @@ export function classRuleChecks(input, path, site) {
141
148
  invalid('Class rule spelling', undefined, path);
142
149
  }
143
150
  }
144
- /** What a site calls its checks in a refusal. */
145
- const SITE = { callable: 'Callable Policy', class: 'Class rule', create: 'Create rule' };
146
151
  /** Check the recursive Policy check wire grammar of one use site. */
147
152
  function policyCheck(input, depth, path, site = 'callable') {
148
- const name = SITE[site];
149
- if (depth > 64)
153
+ const { name } = POLICY_CHECK_SITE[site];
154
+ if (depth > WIRE_DEPTH)
150
155
  invalid(`${name} depth`, undefined, path);
151
156
  const value = object(input, name, path);
152
157
  if (Object.hasOwn(value, 'sameNode')) {
@@ -174,7 +179,7 @@ function policyCheck(input, depth, path, site = 'callable') {
174
179
  policyCheck(expression, depth + 1, `${memberPath}/${index}`, site);
175
180
  }
176
181
  function policyCheckObject(input, objectPath, site) {
177
- const name = SITE[site];
182
+ const { name } = POLICY_CHECK_SITE[site];
178
183
  const target = object(input, `${name} object`, objectPath);
179
184
  if (target.kind === 'self' && site !== 'create')
180
185
  exact(target, ['kind'], `${name} self`, objectPath);
@@ -111,6 +111,7 @@ function compileEntry(schema, lookup) {
111
111
  origin: schema.origin,
112
112
  revision: revisionOfDomainSchema(schema),
113
113
  name: schema.name,
114
+ ...(schema.icon === undefined ? {} : { icon: schema.icon }),
114
115
  ...(schema.entrypoint === undefined ? {} : { entrypoint: schema.entrypoint }),
115
116
  dependencies: schema.dependencies,
116
117
  definitions: Object.freeze({
@@ -2,6 +2,8 @@ export { acceptCompiledSchema as accept } from './admission/accept.js';
2
2
  export { compile } from './compiler/compile.js';
3
3
  export { decode, encode } from './codec/json.js';
4
4
  export { load } from './loader/load.js';
5
+ export { COMPILED_RULES as RULES, READMITTED_RULES, READMITTED_VALUE_RULES } from './rule.js';
6
+ export type { CompiledRule as Rule, ReadmittedRule } from './rule.js';
5
7
  export { CompiledSchemaError as Error } from './diagnostic.js';
6
8
  export type { CompiledDiagnostic as Diagnostic, CompiledDiagnosticCode as DiagnosticCode, } from './diagnostic.js';
7
9
  export type * from './model/schema.js';
@@ -2,4 +2,5 @@ export { acceptCompiledSchema as accept } from './admission/accept.js';
2
2
  export { compile } from './compiler/compile.js';
3
3
  export { decode, encode } from './codec/json.js';
4
4
  export { load } from './loader/load.js';
5
+ export { COMPILED_RULES as RULES, READMITTED_RULES, READMITTED_VALUE_RULES } from './rule.js';
5
6
  export { CompiledSchemaError as Error } from './diagnostic.js';
@@ -5,6 +5,7 @@ import type { MethodDefinition } from '../../language/callable/model/callable.js
5
5
  import type { ClassDefinition } from '../../language/class/model/class.js';
6
6
  import type { PropertyDefinition } from '../../language/class/model/property.js';
7
7
  import type { CoreDefinition, CoreEdge } from '../../language/core/model/core.js';
8
+ import type { DomainIcon } from '../../language/definition/metadata.js';
8
9
  import type { PolicyDefinition } from '../../language/policy/model/policy.js';
9
10
  import type { IndexedValueProgram, Pattern, RunPattern } from '../../language/value/compile/model.js';
10
11
  import type { OrderingKind } from '../../language/value/ordering.js';
@@ -55,6 +56,8 @@ export interface CompiledSchemaEntry {
55
56
  readonly revision: Revision;
56
57
  /** The source Domain display name. */
57
58
  readonly name: string;
59
+ /** The source Domain presentation icon. */
60
+ readonly icon?: DomainIcon;
58
61
  /** The source Domain entrypoint View. */
59
62
  readonly entrypoint?: ViewRef;
60
63
  readonly dependencies: DomainDependencyMap;
@@ -0,0 +1,49 @@
1
+ import type { BoundaryErrorCode } from '@astrale-os/kernel-dsl/value';
2
+ import type { LimitKey } from '../language/limits.js';
3
+ import type { DiagnosticCode as ValueDiagnosticCode } from '../language/validation/diagnostic.js';
4
+ import type { SchemaDiagnosticCode } from '../schema/diagnostic.js';
5
+ import type { CompiledDiagnosticCode } from './diagnostic.js';
6
+ /** The rule one diagnostic code of a compiled Schema reports. */
7
+ export interface CompiledRule {
8
+ /** The positions its diagnostics point at, as the positions of `schema.Rule`. */
9
+ readonly positions: readonly [string, ...string[]];
10
+ /** The rule, in one plain sentence. */
11
+ readonly statement: string;
12
+ /** The limits of `schema.limits` the rule enforces, by key, where it enforces some. */
13
+ readonly limits?: readonly [LimitKey, ...LimitKey[]];
14
+ }
15
+ /**
16
+ * Every diagnostic code of a compiled Schema with the rule it reports, frozen. A code added here
17
+ * does not compile until it is described.
18
+ */
19
+ export declare const COMPILED_RULES: Readonly<Record<CompiledDiagnosticCode, CompiledRule>>;
20
+ /** How admission of a compiled Schema holds one rule of the language. */
21
+ export type ReadmittedRule = {
22
+ /** A compiled Schema breaking the rule is refused, under one of these codes. */
23
+ readonly kind: 'refused';
24
+ readonly answers: readonly [CompiledDiagnosticCode, ...CompiledDiagnosticCode[]];
25
+ /** The part of the rule a compiled Schema may break and still load. */
26
+ readonly except?: string;
27
+ } | {
28
+ /** The portable value boundary refuses it before admission: `COMPILED_STRUCTURE_INVALID`, caused by one of these. */
29
+ readonly kind: 'portable';
30
+ readonly answers: readonly [BoundaryErrorCode, ...BoundaryErrorCode[]];
31
+ } | {
32
+ /** A compiled Schema has no position for what the rule reads. */
33
+ readonly kind: 'unsayable';
34
+ readonly because: string;
35
+ } | {
36
+ /** A compiled Schema breaking the rule loads, for the reason given. */
37
+ readonly kind: 'unapplied';
38
+ readonly because: string;
39
+ };
40
+ /**
41
+ * Every rule of a source with how admission of a compiled Schema holds it, frozen. A rule added to
42
+ * the language does not compile until it is placed here.
43
+ */
44
+ export declare const READMITTED_RULES: Readonly<Record<SchemaDiagnosticCode, ReadmittedRule>>;
45
+ /**
46
+ * Every rule of a value schema with how admission of a compiled Schema holds it, frozen. A rule added
47
+ * to the value language does not compile until it is placed here.
48
+ */
49
+ export declare const READMITTED_VALUE_RULES: Readonly<Record<Extract<ValueDiagnosticCode, `VS_${string}`>, ReadmittedRule>>;
@@ -0,0 +1,169 @@
1
+ import { deepFreeze } from '../language/freeze.js';
2
+ import { limits } from '../language/limits.js';
3
+ /**
4
+ * Every diagnostic code of a compiled Schema with the rule it reports, frozen. A code added here
5
+ * does not compile until it is described.
6
+ */
7
+ export const COMPILED_RULES = deepFreeze({
8
+ COMPILED_STRUCTURE_INVALID: {
9
+ positions: ['{/path*}'],
10
+ statement: `A compiled Schema is a portable value, has its format and version and exactly the fields of its wire shape, holds each origin once in its closure, spells each Class rule in its normal form, and its root and every pin name a revision of that closure. It holds at most ${limits.closure.members} members and items. An entry past the limits of the canonical encoder has no revision, so it is refused here.`,
11
+ limits: ['closure.members'],
12
+ },
13
+ COMPILED_CANONICAL_MISMATCH: {
14
+ positions: ['/closure/{index}/revision', '/closure/{index}{/path*}/execution/durable'],
15
+ statement: 'A compiled Schema holds the canonical form of what it says: an entry the revision of its own content, a Callable no execution unless durable. What a revision leaves out stands outside this rule: the graph and machines of a value program, the pattern table of an entry, the ordering of a Property and the input fields of a Callable are derived from what the revision covers, so a document saying otherwise loads and answers as that part says.',
16
+ },
17
+ COMPILED_DEPENDENCY_LIMITS: {
18
+ positions: ['/closure', '/closure/{index}/dependencies'],
19
+ statement: `A compiled Schema has a closure of at most ${limits.dependency.closure} Domains, each with at most ${limits.dependency.direct} direct dependencies, at most ${limits.dependency.depth} deep.`,
20
+ limits: ['dependency.closure', 'dependency.direct', 'dependency.depth'],
21
+ },
22
+ COMPILED_SOURCE_INVALID: {
23
+ positions: ['/closure/{index}{/path*}'],
24
+ statement: 'A compiled entry holds the rules of the language `READMITTED_RULES` places under this code: admission applies them to it again.',
25
+ },
26
+ });
27
+ const WIRE = { kind: 'refused', answers: ['COMPILED_STRUCTURE_INVALID'] };
28
+ const SOURCE = { kind: 'refused', answers: ['COMPILED_SOURCE_INVALID'] };
29
+ const WIRE_OR_SOURCE = {
30
+ kind: 'refused',
31
+ answers: ['COMPILED_STRUCTURE_INVALID', 'COMPILED_SOURCE_INVALID'],
32
+ };
33
+ const PORTABLE = {
34
+ kind: 'portable',
35
+ answers: [
36
+ 'VALUE_TYPE',
37
+ 'VALUE_NUMBER',
38
+ 'VALUE_STRING',
39
+ 'VALUE_ARRAY',
40
+ 'VALUE_OBJECT',
41
+ 'VALUE_CYCLE',
42
+ 'VALUE_LIMIT',
43
+ 'VALUE_REFLECTION',
44
+ ],
45
+ };
46
+ /**
47
+ * Every rule of a source with how admission of a compiled Schema holds it, frozen. A rule added to
48
+ * the language does not compile until it is placed here.
49
+ */
50
+ export const READMITTED_RULES = deepFreeze({
51
+ UNSUPPORTED_DOCUMENT_FORMAT: WIRE,
52
+ UNSUPPORTED_DSL_VERSION: WIRE,
53
+ DV_JSON_VALUE: PORTABLE,
54
+ STRUCTURE_BINARY_INPUT: WIRE,
55
+ STRUCTURE_CALLABLE_POLICY_AUTH: WIRE,
56
+ STRUCTURE_DEPENDENCY_ALIAS: WIRE,
57
+ STRUCTURE_DOMAIN_NAME: WIRE,
58
+ STRUCTURE_DUPLICATE_ITEM: WIRE,
59
+ STRUCTURE_EDGE_BLOB: {
60
+ kind: 'unapplied',
61
+ because: 'Admission does not read the value kind of an Edge Property.',
62
+ },
63
+ STRUCTURE_EDGE_ORIENTATION: WIRE,
64
+ STRUCTURE_FORMAT: WIRE,
65
+ STRUCTURE_KEY: WIRE,
66
+ STRUCTURE_MAXIMUM: WIRE,
67
+ STRUCTURE_MINIMUM: WIRE,
68
+ STRUCTURE_PROPERTY_KEY: WIRE_OR_SOURCE,
69
+ STRUCTURE_PROTO_KEY: WIRE,
70
+ STRUCTURE_REQUIRED: WIRE,
71
+ STRUCTURE_STATE_TRANSITIONS: SOURCE,
72
+ STRUCTURE_TYPE: WIRE,
73
+ STRUCTURE_UNION: WIRE,
74
+ STRUCTURE_UNKNOWN_FIELD: WIRE_OR_SOURCE,
75
+ STRUCTURE_VALUE: WIRE,
76
+ DV_ACCEPTANCE_CONTEXT: {
77
+ kind: 'unsayable',
78
+ because: 'A compiled Schema carries its closure, so no acceptance in this process precedes it.',
79
+ },
80
+ DV_CALLABLE_ADMISSION: SOURCE,
81
+ DV_CALLABLE_AUTH: SOURCE,
82
+ DV_CALLABLE_IO: SOURCE,
83
+ DV_CLASS_ABSTRACT: SOURCE,
84
+ DV_CLASS_ACYCLIC: SOURCE,
85
+ DV_CLASS_INHERITANCE: SOURCE,
86
+ DV_CLASS_KIND: SOURCE,
87
+ DV_CORE_EDGE_CLASS: SOURCE,
88
+ DV_CORE_EDGE_CONSTRAINTS: SOURCE,
89
+ DV_CORE_EDGE_KEY: SOURCE,
90
+ DV_CORE_EDGE_PROPERTIES: SOURCE,
91
+ DV_CORE_EDGE_UNIQUE: SOURCE,
92
+ DV_CORE_NODE_CLASS: SOURCE,
93
+ DV_CORE_NODE_PROPERTIES: SOURCE,
94
+ DV_CORE_NODE_UNIQUE: SOURCE,
95
+ DV_CORE_REF: SOURCE,
96
+ DV_DATA_COMPOSITION: SOURCE,
97
+ DV_DEPENDENCY_ACYCLIC: WIRE,
98
+ DV_DEPENDENCY_DIRECT: SOURCE,
99
+ DV_DEPENDENCY_EXACT: WIRE,
100
+ DV_DEPENDENCY_LIMITS: { kind: 'refused', answers: ['COMPILED_DEPENDENCY_LIMITS'] },
101
+ DV_DEPENDENCY_REVISION_COHERENCE: WIRE,
102
+ DV_DEPENDENCY_UNIQUE: WIRE,
103
+ DV_DOMAIN_ICON: WIRE,
104
+ DV_EDGE_ACCEPTS: SOURCE,
105
+ DV_EDGE_CLASS_COMPOSITION: SOURCE,
106
+ DV_EDGE_FOREIGN_MINIMUM: {
107
+ kind: 'unapplied',
108
+ because: 'Admission reads an Edge count only against the Core facts of its entry.',
109
+ },
110
+ DV_EDGE_LIFETIME: {
111
+ kind: 'unapplied',
112
+ because: 'Admission reads `onDelete` only as a value of its position.',
113
+ },
114
+ DV_EDGE_ROLE: WIRE,
115
+ DV_EDGE_UNIQUE: SOURCE,
116
+ DV_ENTRYPOINT: WIRE,
117
+ DV_INHERITANCE_LIMITS: SOURCE,
118
+ DV_METHOD_ABSTRACT: SOURCE,
119
+ DV_METHOD_COMPOSITION: SOURCE,
120
+ DV_NODE_UNIQUE: SOURCE,
121
+ DV_PROPERTY_AUTO: SOURCE,
122
+ DV_PROPERTY_IMMUTABLE: SOURCE,
123
+ DV_PROPERTY_STATE: SOURCE,
124
+ DV_REF_RESOLVES: WIRE_OR_SOURCE,
125
+ DV_VALUE_SCHEMA: {
126
+ kind: 'refused',
127
+ answers: ['COMPILED_STRUCTURE_INVALID', 'COMPILED_SOURCE_INVALID'],
128
+ except: 'Every rule of a value schema but its pattern sources, its numbers and what deriving its graph reads, as `READMITTED_VALUE_RULES` places each.',
129
+ },
130
+ PL_BUDGET: SOURCE,
131
+ PL_COMPOSITION: SOURCE,
132
+ PL_CONNECTIVITY: SOURCE,
133
+ PL_REF: SOURCE,
134
+ PL_REPEAT: WIRE,
135
+ PL_TARGET: SOURCE,
136
+ PL_TYPING: SOURCE,
137
+ PL_USE: SOURCE,
138
+ PL_VARIABLE_SCOPE: SOURCE,
139
+ });
140
+ const VALUE_INDICES = {
141
+ kind: 'unapplied',
142
+ because: 'Admission derives the graph, the machines and the ordering of a value program from its root schema, which it evaluates as it stands.',
143
+ };
144
+ /**
145
+ * Every rule of a value schema with how admission of a compiled Schema holds it, frozen. A rule added
146
+ * to the value language does not compile until it is placed here.
147
+ */
148
+ export const READMITTED_VALUE_RULES = deepFreeze({
149
+ VS_DIALECT: VALUE_INDICES,
150
+ VS_DYNAMIC_FORBIDDEN: VALUE_INDICES,
151
+ VS_KEYWORD_CLOSED: VALUE_INDICES,
152
+ VS_META_SCHEMA: {
153
+ kind: 'refused',
154
+ answers: ['COMPILED_SOURCE_INVALID'],
155
+ except: 'Every other form of a keyword: its graph derives all the same.',
156
+ },
157
+ VS_NUMBER_DOMAIN: PORTABLE,
158
+ VS_PATH_EXTENSION: VALUE_INDICES,
159
+ VS_RECURSION_PRODUCTIVE: SOURCE,
160
+ VS_REFERENCE_FORM: SOURCE,
161
+ VS_REFERENCE_RESOLUTION: SOURCE,
162
+ VS_REGEX_PORTABLE: SOURCE,
163
+ VS_RESOURCE_ID: VALUE_INDICES,
164
+ VS_VALUE_KIND: VALUE_INDICES,
165
+ VS_VALUE_KIND_JSON: {
166
+ kind: 'unapplied',
167
+ because: 'It warns the author of a source, and a compiled Schema has no author to warn.',
168
+ },
169
+ });
@@ -5,6 +5,7 @@ export { isBinaryInput } from './language/callable/model/callable.js';
5
5
  export type { EventOf, StateMachine, StateOf } from './language/state/index.js';
6
6
  export { PropertyValues } from './language/index.js';
7
7
  export * as metadata from './language/definition/metadata.js';
8
+ export type { DomainIcon, DomainIconArt } from './language/definition/metadata.js';
8
9
  export type { AnyResolvedClass, BoundMethodOf, BoundMethodShortcutsOf, CallableResultOf, CallableInputOf, CallableInputModeOf, CallableOutputOf, ClassSatisfactionKeysOf, ClassDefinition, CoreDefinition, CoreEdge, FunctionAuth, FunctionDefinition, Inheritance, BinaryInput, BinaryInputProjection, CallableInputContract, MethodDefinition, MethodOwnerKeyOf, CallablePolicy, ClassPolicy, ClassRuleChecks, ClassRuleObject, ClassWritePolicy, CreateRuleChecks, EdgeClassPolicy, EdgeClassWritePolicy, EdgeRuleChecks, NodeClassCreatePolicy, NodeClassPolicy, NodeClassWritePolicy, PolicyCheckExpression, PolicyDefinition, PropertyImmutability, PropertyInputOf, PropertyAccessOf, PropertyOutputOf, PropertyShortcutsOf, PropertyValuesOf, ResolvedClass, ResolvedCoreDefinition, ResolvedCoreEndpoint, ResolvedData, ResolvedFunction, ExecutableMethod, ResolvedMethod, ResolvedMethodCollection, ResolvedPolicy, ResolvedProperty, ResolvedView, MethodAccessOf, SelfMethodsOf, SelfPropertiesOf, SelfStaticMethodsOf, StaticMethodsOf, ViewDefinition, } from './language/index.js';
9
10
  export { acceptDefinitionRef, callableAddress, ClassKey, equalDefinitionRefs, isDefinitionRef, Key, MethodKey, PropertyKey, } from './addressing/index.js';
10
11
  export type { ClassRef, CoreRef, DefinitionBase, DefinitionKey, DefinitionRef, FunctionRef, MethodAddress, PolicyRef, Revision, ViewRef, } from './addressing/index.js';
@@ -1,4 +1,5 @@
1
1
  import { compareUnicode } from '../../addressing/ordering.js';
2
+ import { PolicyComposition } from '../policy/model/policy.js';
2
3
  /**
3
4
  * The language ceiling of a declared admission age, in seconds. Raising it later widens the
4
5
  * language; lowering it would refuse accepted Schemas.
@@ -37,7 +38,7 @@ function collectInputFields(expression, fields) {
37
38
  }
38
39
  return;
39
40
  }
40
- for (const child of 'allOf' in expression ? expression.allOf : expression.anyOf) {
41
+ for (const child of PolicyComposition.of(expression).operands) {
41
42
  collectInputFields(child, fields);
42
43
  }
43
44
  }
@@ -23,3 +23,36 @@ export declare function isDomainNameText(value: string): boolean;
23
23
  * character `trim` removes, spelled out since `\s` differs between regular expression engines.
24
24
  */
25
25
  export declare const DOMAIN_NAME_TEXT_PATTERN: RegExp;
26
+ /** One drawing of a Domain icon size: inline SVG text, with an optional dark-theme variant. */
27
+ export interface DomainIconArt {
28
+ /** The light-theme drawing, always present. */
29
+ readonly svg: string;
30
+ /** The dark-theme drawing, when the Domain draws one. */
31
+ readonly dark?: string;
32
+ }
33
+ /** A Domain presentation icon: up to three hand-drawn sizes, at least one present. */
34
+ export interface DomainIcon {
35
+ /** Drawn for 16 to 24 px, on a 24 x 24 artboard. */
36
+ readonly small?: DomainIconArt;
37
+ /** Drawn for 28 to 96 px, on a 64 x 64 artboard. */
38
+ readonly medium?: DomainIconArt;
39
+ /** Drawn for 128 px and more, on a 512 x 512 artboard. */
40
+ readonly large?: DomainIconArt;
41
+ }
42
+ /** The sizes of a Domain icon, smallest first: the canonical order of its members. */
43
+ export declare const DOMAIN_ICON_SIZES: readonly ["small", "medium", "large"];
44
+ /** A Domain icon size. */
45
+ export type DomainIconSize = (typeof DOMAIN_ICON_SIZES)[number];
46
+ /** Exact V1 bound, in bytes of UTF-8, of each SVG text of one Domain icon size. */
47
+ export declare const domainIcon: Readonly<{
48
+ readonly small: 8192;
49
+ readonly medium: 32768;
50
+ readonly large: 262144;
51
+ }>;
52
+ /**
53
+ * Why one SVG text is no admissible Domain icon drawing of `size`, or undefined when it is one:
54
+ * within the size's UTF-8 bound, one complete `<svg>` root with a visible vector element, no
55
+ * executable, external or styling content, and no `url(` but a local `url(#id)`. A lexical check,
56
+ * not a parser: a Shell renders the drawing only as an image, never inline.
57
+ */
58
+ export declare function domainIconSvgIssue(svg: string, size: DomainIconSize): string | undefined;
@@ -29,3 +29,47 @@ export function isDomainNameText(value) {
29
29
  export const DOMAIN_NAME_TEXT_PATTERN =
30
30
  // oxlint-disable-next-line no-control-regex
31
31
  /^(?:[^\u0000-\u001f\u007f-\u009f\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff](?:[^\u0000-\u001f\u007f-\u009f\u2028\u2029]*[^\u0000-\u001f\u007f-\u009f\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])?)?$/u;
32
+ /** The sizes of a Domain icon, smallest first: the canonical order of its members. */
33
+ export const DOMAIN_ICON_SIZES = Object.freeze(['small', 'medium', 'large']);
34
+ /** Exact V1 bound, in bytes of UTF-8, of each SVG text of one Domain icon size. */
35
+ export const domainIcon = Object.freeze({ small: 8192, medium: 32768, large: 262144 });
36
+ const SVG_ROOT = /^<svg(?:\s[^>]*)?>[\s\S]*<\/svg>$/u;
37
+ const SVG_ROOT_OPEN = /<svg(?:\s|>)/gu;
38
+ const SVG_ROOT_CLOSE = /<\/svg\s*>/gu;
39
+ const SVG_GRAPHIC = /<(?:circle|ellipse|line|path|polygon|polyline|rect)\b/iu;
40
+ const SVG_UNSAFE = /<\s*(?:animate|discard|embed|foreignObject|iframe|image|object|script|set|style|use)\b|<!DOCTYPE\b|<!ENTITY\b|\son[a-z][\w:.-]*\s*=|\sstyle\s*=|(?:href|xlink:href)\s*=|javascript\s*:/iu;
41
+ // The one admitted `url(`: a reference to an element of the same drawing, by its id.
42
+ const SVG_LOCAL_URL = /url\(#[A-Za-z][A-Za-z0-9_-]*\)/gu;
43
+ const SVG_URL = /url\s*\(/iu;
44
+ /**
45
+ * Why one SVG text is no admissible Domain icon drawing of `size`, or undefined when it is one:
46
+ * within the size's UTF-8 bound, one complete `<svg>` root with a visible vector element, no
47
+ * executable, external or styling content, and no `url(` but a local `url(#id)`. A lexical check,
48
+ * not a parser: a Shell renders the drawing only as an image, never inline.
49
+ */
50
+ export function domainIconSvgIssue(svg, size) {
51
+ const bytes = utf8Length(svg);
52
+ if (bytes === 0)
53
+ return 'is empty';
54
+ if (bytes > domainIcon[size])
55
+ return `exceeds ${domainIcon[size]} bytes of UTF-8`;
56
+ if (!SVG_ROOT.test(svg) ||
57
+ (svg.match(SVG_ROOT_OPEN)?.length ?? 0) !== 1 ||
58
+ (svg.match(SVG_ROOT_CLOSE)?.length ?? 0) !== 1) {
59
+ return 'is not one complete <svg> element';
60
+ }
61
+ if (SVG_UNSAFE.test(svg) || SVG_URL.test(svg.replace(SVG_LOCAL_URL, ''))) {
62
+ return 'holds executable, external or styling content';
63
+ }
64
+ if (!SVG_GRAPHIC.test(svg))
65
+ return 'has no visible vector element';
66
+ return undefined;
67
+ }
68
+ function utf8Length(text) {
69
+ let bytes = 0;
70
+ for (const character of text) {
71
+ const point = character.codePointAt(0);
72
+ bytes += point < 0x80 ? 1 : point < 0x800 ? 2 : point < 0x10000 ? 3 : 4;
73
+ }
74
+ return bytes;
75
+ }