@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,3 +1,4 @@
1
+ import { runSuspended } from '../suspended.js';
1
2
  import { loadValueProgram } from './compile/load.js';
2
3
  import { prepareValueSchema } from './evaluate/preparation.js';
3
4
  const ALL_JSON_KINDS = new Set([
@@ -26,7 +27,7 @@ export function classifyValueProgramOrdering(program) {
26
27
  }
27
28
  export function classifyPreparedOrdering(compiled) {
28
29
  // An enum orders as the strings it lists; a set is an array.
29
- const candidates = new Set([...new OrderingClassifier(compiled).classify(compiled.root)].map((kind) => kind === 'enum' ? 'string' : kind === 'set' ? 'array' : kind));
30
+ const candidates = new Set([...candidatesOf(compiled)].map((kind) => kind === 'enum' ? 'string' : kind === 'set' ? 'array' : kind));
30
31
  if (candidates.size !== 1)
31
32
  return undefined;
32
33
  const [kind] = candidates;
@@ -61,7 +62,7 @@ export function classifyValueKind(contract, registry) {
61
62
  return classifyPreparedValueKind(prepared.value);
62
63
  }
63
64
  export function classifyPreparedValueKind(compiled) {
64
- const candidates = new Set(new OrderingClassifier(compiled).classify(compiled.root));
65
+ const candidates = new Set(candidatesOf(compiled));
65
66
  candidates.delete('null');
66
67
  if (candidates.size !== 1)
67
68
  return 'json';
@@ -79,81 +80,72 @@ export function classifyPreparedValueKind(compiled) {
79
80
  return 'json';
80
81
  }
81
82
  }
82
- class OrderingClassifier {
83
- compiled;
84
- active = new Set();
85
- cache = new Map();
86
- constructor(compiled) {
87
- this.compiled = compiled;
83
+ /**
84
+ * The candidates at a program's root. References chain to any length, so the classifications waiting
85
+ * on one another run on a stack of their own, never on the call stack.
86
+ */
87
+ function candidatesOf(compiled) {
88
+ const known = new Map();
89
+ function* read(location) {
90
+ const candidates = known.get(location.key);
91
+ if (candidates !== undefined)
92
+ return candidates;
93
+ // A location read again before its classification ends sits on a cycle: it admits anything.
94
+ known.set(location.key, ALL_JSON_KINDS);
95
+ const classified = yield* classifySchema(compiled, location, read);
96
+ known.set(location.key, classified);
97
+ return classified;
88
98
  }
89
- classify(location) {
90
- const cached = this.cache.get(location.key);
91
- if (cached !== undefined)
92
- return cached;
93
- if (this.active.has(location.key))
94
- return ALL_JSON_KINDS;
95
- this.active.add(location.key);
96
- try {
97
- const result = this.classifySchema(location);
98
- this.cache.set(location.key, result);
99
- return result;
100
- }
101
- finally {
102
- this.active.delete(location.key);
99
+ return runSuspended(read(compiled.root));
100
+ }
101
+ function* classifySchema(compiled, location, read) {
102
+ if (location.schema === false)
103
+ return new Set();
104
+ if (location.schema === true)
105
+ return ALL_JSON_KINDS;
106
+ const schema = location.schema;
107
+ let candidates = ALL_JSON_KINDS;
108
+ if (Object.hasOwn(schema, 'x-astrale-value-kind')) {
109
+ if (schema['x-astrale-value-kind'] !== 'instant' || schema.type !== 'string') {
110
+ return new Set();
103
111
  }
112
+ candidates = intersect(candidates, new Set(['instant']));
113
+ }
114
+ const declaredTypes = typesOf(schema.type);
115
+ if (declaredTypes !== undefined)
116
+ candidates = intersect(candidates, declaredTypes);
117
+ if (schema.uniqueItems === true) {
118
+ candidates = new Set([...candidates].map((kind) => (kind === 'array' ? 'set' : kind)));
119
+ }
120
+ if (Object.hasOwn(schema, 'const')) {
121
+ candidates = intersect(candidates, new Set([kindOfValue(schema.const)]));
122
+ }
123
+ if (Array.isArray(schema.enum)) {
124
+ candidates = intersect(candidates, normalize(new Set(schema.enum.map(kindOfValue))));
104
125
  }
105
- classifySchema(location) {
106
- if (location.schema === false)
126
+ if (Object.hasOwn(schema, '$ref')) {
127
+ const target = compiled.reference(location);
128
+ if (target === undefined)
107
129
  return new Set();
108
- if (location.schema === true)
109
- return ALL_JSON_KINDS;
110
- const schema = location.schema;
111
- let candidates = ALL_JSON_KINDS;
112
- if (Object.hasOwn(schema, 'x-astrale-value-kind')) {
113
- if (schema['x-astrale-value-kind'] !== 'instant' || schema.type !== 'string') {
114
- return new Set();
115
- }
116
- candidates = intersect(candidates, new Set(['instant']));
117
- }
118
- const declaredTypes = typesOf(schema.type);
119
- if (declaredTypes !== undefined)
120
- candidates = intersect(candidates, declaredTypes);
121
- if (schema.uniqueItems === true) {
122
- candidates = new Set([...candidates].map((kind) => (kind === 'array' ? 'set' : kind)));
123
- }
124
- if (Object.hasOwn(schema, 'const')) {
125
- candidates = intersect(candidates, new Set([kindOfValue(schema.const)]));
126
- }
127
- if (Array.isArray(schema.enum)) {
128
- candidates = intersect(candidates, normalize(new Set(schema.enum.map(kindOfValue))));
129
- }
130
- if (Object.hasOwn(schema, '$ref')) {
131
- const target = this.compiled.reference(location);
132
- if (target === undefined)
133
- return new Set();
134
- candidates = intersect(candidates, this.classify(target));
135
- }
136
- const allOf = schemaList(schema.allOf);
137
- if (allOf !== undefined) {
138
- for (let index = 0; index < allOf.length; index += 1) {
139
- candidates = intersect(candidates, this.classify(this.child(location, 'allOf', index)));
140
- }
141
- }
142
- for (const keyword of ['anyOf', 'oneOf']) {
143
- const branches = schemaList(schema[keyword]);
144
- if (branches === undefined)
145
- continue;
146
- let admitted = new Set();
147
- for (let index = 0; index < branches.length; index += 1) {
148
- admitted = union(admitted, this.classify(this.child(location, keyword, index)));
149
- }
150
- candidates = intersect(candidates, admitted);
130
+ candidates = intersect(candidates, yield read(target));
131
+ }
132
+ const allOf = schemaList(schema.allOf);
133
+ if (allOf !== undefined) {
134
+ for (let index = 0; index < allOf.length; index += 1) {
135
+ candidates = intersect(candidates, yield read(compiled.child(location, 'allOf', index)));
151
136
  }
152
- return candidates;
153
137
  }
154
- child(location, keyword, index) {
155
- return this.compiled.child(location, keyword, index);
138
+ for (const keyword of ['anyOf', 'oneOf']) {
139
+ const branches = schemaList(schema[keyword]);
140
+ if (branches === undefined)
141
+ continue;
142
+ let admitted = new Set();
143
+ for (let index = 0; index < branches.length; index += 1) {
144
+ admitted = union(admitted, yield read(compiled.child(location, keyword, index)));
145
+ }
146
+ candidates = intersect(candidates, admitted);
156
147
  }
148
+ return candidates;
157
149
  }
158
150
  function typesOf(input) {
159
151
  if (typeof input === 'string')
@@ -1,4 +1,9 @@
1
1
  import type { JsonSchema, ValueSchemaContext } from '../model/schema.js';
2
2
  import type { ValueSchemaRegistry } from '../reference/registry.js';
3
- /** Canonicalizes syntax without rewriting the schema's algebra. Validate first. */
3
+ /**
4
+ * Canonicalizes syntax without rewriting the schema's algebra, and judges nothing: a set repeating a
5
+ * value or naming something else than it declares keeps its members, for validation to refuse.
6
+ */
4
7
  export declare function canonicalizeValueSchema(schema: JsonSchema, context?: ValueSchemaContext, registry?: ValueSchemaRegistry): JsonSchema;
8
+ /** A schema with its members in canonical order at every depth. Arrays keep theirs: it is their meaning. */
9
+ export declare function canonicalizeSchemaMembers(schema: JsonSchema): JsonSchema;
@@ -5,88 +5,72 @@ import { SCHEMA_ARRAY_KEYWORDS, SCHEMA_MAP_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, } f
5
5
  const TYPE_ORDER = ['null', 'boolean', 'integer', 'number', 'string', 'array', 'object'];
6
6
  const TYPE_RANK = new Map(TYPE_ORDER.map((name, index) => [name, index]));
7
7
  const encoder = new TextEncoder();
8
- /** Canonicalizes syntax without rewriting the schema's algebra. Validate first. */
8
+ /**
9
+ * Canonicalizes syntax without rewriting the schema's algebra, and judges nothing: a set repeating a
10
+ * value or naming something else than it declares keeps its members, for validation to refuse.
11
+ */
9
12
  export function canonicalizeValueSchema(schema, context, registry) {
10
13
  void context;
11
14
  void registry;
12
15
  return canonicalizeSchema(schema, true);
13
16
  }
17
+ /** A schema with its members in canonical order at every depth. Arrays keep theirs: it is their meaning. */
18
+ export function canonicalizeSchemaMembers(schema) {
19
+ return canonicalizeJson(schema);
20
+ }
14
21
  function canonicalizeSchema(schema, root) {
15
22
  if (typeof schema === 'boolean')
16
23
  return schema;
17
- const result = {};
18
- for (const keyword of Object.keys(schema).sort()) {
19
- if (root && keyword === '$schema')
20
- continue;
21
- const value = schema[keyword];
22
- if (keyword === 'required' && Array.isArray(value)) {
23
- assertUnique(value, String, 'required');
24
- result[keyword] = [...value].sort((left, right) => compareUnicode(String(left), String(right)));
25
- }
26
- else if (keyword === 'type' && Array.isArray(value)) {
27
- assertUnique(value, String, 'type');
28
- result[keyword] = [...value].sort((left, right) => (TYPE_RANK.get(String(left)) ?? Number.MAX_SAFE_INTEGER) -
29
- (TYPE_RANK.get(String(right)) ?? Number.MAX_SAFE_INTEGER));
30
- }
31
- else if (keyword === 'enum' && Array.isArray(value)) {
32
- const entries = value.map(canonicalizeJson);
33
- assertUnique(entries, json.serialize, 'enum');
34
- result[keyword] = entries.sort(compareCanonicalBytes);
35
- }
36
- else if (keyword === 'dependentRequired' && isJsonObject(value)) {
37
- result[keyword] = canonicalizeDependentRequired(value);
38
- }
39
- else if (keyword === 'x-astrale-path' && isJsonObject(value)) {
40
- result[keyword] = canonicalizePathAnnotation(value);
41
- }
42
- else if (SCHEMA_SINGLE_KEYWORDS.has(keyword) && isJsonSchema(value)) {
43
- result[keyword] = canonicalizeSchema(value, false);
44
- }
45
- else if (SCHEMA_ARRAY_KEYWORDS.has(keyword) && Array.isArray(value)) {
46
- result[keyword] = value.map((entry) => isJsonSchema(entry) ? canonicalizeSchema(entry, false) : canonicalizeJson(entry));
47
- }
48
- else if (SCHEMA_MAP_KEYWORDS.has(keyword) && isJsonObject(value)) {
49
- const schemas = {};
50
- for (const name of Object.keys(value).sort()) {
51
- const entry = value[name];
52
- schemas[name] = isJsonSchema(entry)
53
- ? canonicalizeSchema(entry, false)
54
- : canonicalizeJson(entry);
55
- }
56
- result[keyword] = schemas;
57
- }
58
- else {
59
- result[keyword] = canonicalizeJson(value);
60
- }
61
- }
62
- return result;
24
+ if (!root)
25
+ return mapMembers(schema, canonicalizeKeyword);
26
+ const { $schema: _dialect, ...members } = schema;
27
+ return mapMembers(members, canonicalizeKeyword);
63
28
  }
64
- function canonicalizeDependentRequired(value) {
65
- const result = {};
66
- for (const name of Object.keys(value).sort()) {
67
- const dependencies = value[name];
68
- if (!Array.isArray(dependencies)) {
69
- result[name] = canonicalizeJson(dependencies);
70
- continue;
71
- }
72
- assertUnique(dependencies, String, `dependentRequired.${name}`);
73
- result[name] = [...dependencies].sort((left, right) => compareUnicode(String(left), String(right)));
74
- }
75
- return result;
29
+ /**
30
+ * The members of an object in canonical order, each value mapped. A name is data: `__proto__` stays
31
+ * a member, for validation to judge, where an assignment would have set the prototype.
32
+ */
33
+ function mapMembers(value, map) {
34
+ return Object.fromEntries(Object.keys(value)
35
+ .sort()
36
+ .map((name) => [name, map(name, value[name])]));
76
37
  }
77
- function canonicalizePathAnnotation(value) {
78
- const result = {};
79
- for (const key of Object.keys(value).sort()) {
80
- const entry = value[key];
81
- if (key === 'accepts' && Array.isArray(entry)) {
82
- const accepts = entry.map(canonicalizeJson);
83
- assertUnique(accepts, json.serialize, 'x-astrale-path.accepts');
84
- result[key] = accepts.sort((left, right) => compareDefinitionRefs(left, right));
85
- }
86
- else
87
- result[key] = canonicalizeJson(entry);
38
+ function canonicalizeKeyword(keyword, value) {
39
+ if (keyword === 'required' && isStringList(value))
40
+ return [...value].sort(compareUnicode);
41
+ if (keyword === 'type' && isStringList(value)) {
42
+ return [...value].sort((left, right) => (TYPE_RANK.get(left) ?? Number.MAX_SAFE_INTEGER) -
43
+ (TYPE_RANK.get(right) ?? Number.MAX_SAFE_INTEGER));
44
+ }
45
+ if (keyword === 'enum' && Array.isArray(value)) {
46
+ return value.map(canonicalizeJson).sort(compareCanonicalBytes);
47
+ }
48
+ if (keyword === 'dependentRequired' && isJsonObject(value)) {
49
+ return mapMembers(value, (_, dependencies) => isStringList(dependencies)
50
+ ? [...dependencies].sort(compareUnicode)
51
+ : canonicalizeJson(dependencies));
52
+ }
53
+ if (keyword === 'x-astrale-path' && isJsonObject(value)) {
54
+ return mapMembers(value, canonicalizePathMember);
88
55
  }
89
- return result;
56
+ if (SCHEMA_SINGLE_KEYWORDS.has(keyword))
57
+ return canonicalizeNested(value);
58
+ if (SCHEMA_ARRAY_KEYWORDS.has(keyword) && Array.isArray(value)) {
59
+ return value.map(canonicalizeNested);
60
+ }
61
+ if (SCHEMA_MAP_KEYWORDS.has(keyword) && isJsonObject(value)) {
62
+ return mapMembers(value, (_, entry) => canonicalizeNested(entry));
63
+ }
64
+ return canonicalizeJson(value);
65
+ }
66
+ function canonicalizeNested(entry) {
67
+ return isJsonSchema(entry) ? canonicalizeSchema(entry, false) : canonicalizeJson(entry);
68
+ }
69
+ function canonicalizePathMember(name, member) {
70
+ const canonical = canonicalizeJson(member);
71
+ return name === 'accepts' && Array.isArray(canonical) && canonical.every(isComparableRef)
72
+ ? canonical.sort(compareDefinitionRefs)
73
+ : canonical;
90
74
  }
91
75
  function canonicalizeJson(value) {
92
76
  if (value === null || typeof value === 'boolean' || typeof value === 'string')
@@ -102,10 +86,7 @@ function canonicalizeJson(value) {
102
86
  return value.map(canonicalizeJson);
103
87
  if (!isJsonObject(value))
104
88
  throw new TypeError('Cannot canonicalize a non-JSON value.');
105
- const result = {};
106
- for (const key of Object.keys(value).sort())
107
- result[key] = canonicalizeJson(value[key]);
108
- return result;
89
+ return mapMembers(value, (_, member) => canonicalizeJson(member));
109
90
  }
110
91
  function compareCanonicalBytes(left, right) {
111
92
  const a = encoder.encode(json.serialize(left));
@@ -117,14 +98,14 @@ function compareCanonicalBytes(left, right) {
117
98
  }
118
99
  return a.length - b.length;
119
100
  }
120
- function assertUnique(values, keyOf, name) {
121
- const keys = new Set();
122
- for (const value of values) {
123
- const key = keyOf(value);
124
- if (keys.has(key))
125
- throw new TypeError(`${name} contains a duplicate value.`);
126
- keys.add(key);
127
- }
101
+ function isStringList(value) {
102
+ return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
103
+ }
104
+ function isComparableRef(value) {
105
+ return (isJsonObject(value) &&
106
+ typeof value.origin === 'string' &&
107
+ typeof value.kind === 'string' &&
108
+ typeof value.name === 'string');
128
109
  }
129
110
  function isJsonSchema(value) {
130
111
  return typeof value === 'boolean' || isJsonObject(value);
@@ -1,4 +1,14 @@
1
- import { type Options } from '@astrale-os/kernel-dsl/value';
1
+ import { type StructuralOptions, type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
2
  import type { Diagnostic } from '../../validation/diagnostic.js';
3
- /** Whether `value` is a portable JSON Value, within the portable limits `options` overrides. */
4
- export declare function validateCanonicalJsonDomain(value: unknown, pointer: string, options?: Options): readonly Diagnostic[];
3
+ /**
4
+ * The snapshot of `value` as a portable JSON Value, within the portable limits `options` overrides,
5
+ * or why it is none. What evaluates an instance reads this snapshot and never `value` again: what
6
+ * admission bounded is what is read, under the limits it was bounded by.
7
+ */
8
+ export declare function acceptInstance(value: unknown, pointer: string, options?: StructuralOptions): {
9
+ readonly value: JsonValue;
10
+ } | {
11
+ readonly refusal: Diagnostic;
12
+ };
13
+ /** Whether `value` is a portable JSON Value. */
14
+ export declare function validateCanonicalJsonDomain(value: unknown, pointer: string): readonly Diagnostic[];
@@ -1,15 +1,27 @@
1
1
  import { acceptForRead as acceptJsonValue, BoundaryError as JsonBoundaryError, } from '@astrale-os/kernel-dsl/value';
2
2
  import { diagnostic } from '../../validation/diagnostic.js';
3
- /** Whether `value` is a portable JSON Value, within the portable limits `options` overrides. */
4
- export function validateCanonicalJsonDomain(value, pointer, options) {
3
+ /**
4
+ * The snapshot of `value` as a portable JSON Value, within the portable limits `options` overrides,
5
+ * or why it is none. What evaluates an instance reads this snapshot and never `value` again: what
6
+ * admission bounded is what is read, under the limits it was bounded by.
7
+ */
8
+ export function acceptInstance(value, pointer, options) {
5
9
  try {
6
- acceptJsonValue(value, options);
7
- return [];
10
+ return { value: acceptJsonValue(value, options) };
8
11
  }
9
12
  catch (error) {
10
13
  if (error instanceof JsonBoundaryError) {
11
- return [diagnostic('VS_NUMBER_DOMAIN', `${pointer}${error.pointer}`, error.message)];
14
+ return {
15
+ refusal: diagnostic('VS_NUMBER_DOMAIN', `${pointer}${error.pointer}`, error.message),
16
+ };
12
17
  }
13
- return [diagnostic('VS_META_SCHEMA', pointer, 'Value is outside the JSON data model.')];
18
+ return {
19
+ refusal: diagnostic('VS_META_SCHEMA', pointer, 'Value is outside the JSON data model.'),
20
+ };
14
21
  }
15
22
  }
23
+ /** Whether `value` is a portable JSON Value. */
24
+ export function validateCanonicalJsonDomain(value, pointer) {
25
+ const accepted = acceptInstance(value, pointer);
26
+ return 'refusal' in accepted ? [accepted.refusal] : [];
27
+ }
@@ -1,7 +1,7 @@
1
1
  import { diagnostic } from '../../validation/diagnostic.js';
2
2
  import { isValueObject as isJsonObject } from '../model/object.js';
3
3
  import { hasNodePathAnnotation } from '../syntax/node-path/schema.js';
4
- import { walkSchema } from '../syntax/walk.js';
4
+ import { collectSchemaPointers, walkSchema } from '../syntax/walk.js';
5
5
  import { resolveAddressReference, } from './references.js';
6
6
  export function collectResourceClosure(schema, context, index, pointer) {
7
7
  const diagnostics = [];
@@ -19,6 +19,7 @@ export function collectResourceClosure(schema, context, index, pointer) {
19
19
  const resource = queue.shift();
20
20
  if (resource === undefined)
21
21
  break;
22
+ const pointers = collectSchemaPointers(resource.schema);
22
23
  walkSchema(resource.schema, (location) => {
23
24
  if (!isJsonObject(location.schema) || !Object.hasOwn(location.schema, '$ref'))
24
25
  return;
@@ -27,7 +28,7 @@ export function collectResourceClosure(schema, context, index, pointer) {
27
28
  diagnostics.push(diagnostic('VS_REFERENCE_FORM', refPointer, '$ref must be a string URI-reference.'));
28
29
  return;
29
30
  }
30
- const result = resolveAddressReference(location.schema.$ref, resource, index, refPointer, hasNodePathAnnotation(location.schema));
31
+ const result = resolveAddressReference(location.schema.$ref, resource, pointers, index, refPointer, hasNodePathAnnotation(location.schema));
31
32
  if (result.diagnostic !== undefined)
32
33
  diagnostics.push(result.diagnostic);
33
34
  if (result.resolved === undefined)
@@ -1,3 +1,4 @@
1
+ import { cycleEdges } from '../../cycle.js';
1
2
  import { diagnostic } from '../../validation/diagnostic.js';
2
3
  import { isValueObject as isJsonObject } from '../model/object.js';
3
4
  import { appendPointer } from '../syntax/pointer.js';
@@ -46,30 +47,10 @@ export function validateProductiveRecursion(resources, resolutions) {
46
47
  }
47
48
  });
48
49
  }
49
- const visiting = new Set();
50
- const visited = new Set();
51
- for (const node of adjacency.keys()) {
52
- const cycleAt = findCycle(node, adjacency, visiting, visited);
53
- if (cycleAt !== undefined) {
54
- return [
55
- diagnostic('VS_RECURSION_PRODUCTIVE', diagnosticPointers.get(cycleAt) ?? '', 'Every recursive cycle must cross an instance-consuming schema edge.'),
56
- ];
57
- }
58
- }
59
- return [];
60
- }
61
- function findCycle(node, adjacency, visiting, visited) {
62
- if (visiting.has(node))
63
- return node;
64
- if (visited.has(node))
65
- return undefined;
66
- visiting.add(node);
67
- for (const target of adjacency.get(node) ?? []) {
68
- const cycleAt = findCycle(target, adjacency, visiting, visited);
69
- if (cycleAt !== undefined)
70
- return cycleAt;
71
- }
72
- visiting.delete(node);
73
- visited.add(node);
74
- return undefined;
50
+ const [cycle] = cycleEdges(adjacency.keys(), (node) => adjacency.get(node) ?? []);
51
+ if (cycle === undefined)
52
+ return [];
53
+ return [
54
+ diagnostic('VS_RECURSION_PRODUCTIVE', diagnosticPointers.get(cycle.target) ?? '', 'Every recursive cycle must cross an instance-consuming schema edge.'),
55
+ ];
75
56
  }
@@ -11,7 +11,9 @@ export interface ResolvedAddressReference {
11
11
  readonly resource: SchemaResource;
12
12
  readonly pointer: string;
13
13
  }
14
- export declare function resolveAddressReference(ref: string, from: SchemaResource, index: RegistryIndex, pointer: string, nodePathPlacement: boolean): {
14
+ export declare function resolveAddressReference(ref: string, from: SchemaResource,
15
+ /** The schema locations of `from`, the only targets a local reference has. */
16
+ pointers: ReadonlySet<string>, index: RegistryIndex, pointer: string, nodePathPlacement: boolean): {
15
17
  readonly resolved?: ResolvedAddressReference;
16
18
  readonly diagnostic?: Diagnostic;
17
19
  };
@@ -1,8 +1,9 @@
1
1
  import { diagnostic } from '../../validation/diagnostic.js';
2
2
  import { GRAPH_NODE_PATH_SCHEMA_ID } from '../syntax/node-path/schema.js';
3
- import { parseJsonPointerFragment, resolvePointer, tokensToPointer } from '../syntax/pointer.js';
4
- import { collectSchemaPointers } from '../syntax/walk.js';
5
- export function resolveAddressReference(ref, from, index, pointer, nodePathPlacement) {
3
+ import { parseJsonPointerFragment, tokensToPointer } from '../syntax/pointer.js';
4
+ export function resolveAddressReference(ref, from,
5
+ /** The schema locations of `from`, the only targets a local reference has. */
6
+ pointers, index, pointer, nodePathPlacement) {
6
7
  if (ref === GRAPH_NODE_PATH_SCHEMA_ID) {
7
8
  if (!nodePathPlacement) {
8
9
  return {
@@ -27,16 +28,15 @@ export function resolveAddressReference(ref, from, index, pointer, nodePathPlace
27
28
  diagnostic: diagnostic('VS_REFERENCE_FORM', pointer, 'A local $ref must be a JSON Pointer fragment; anchors are forbidden.', ref),
28
29
  };
29
30
  }
30
- return resolveTarget(from, tokens, pointer, ref);
31
+ return resolveTarget(from, pointers, tokens, pointer, ref);
31
32
  }
32
33
  return {
33
34
  diagnostic: diagnostic('VS_REFERENCE_FORM', pointer, 'A $ref must be a local JSON Pointer or the graph NodePath id at its extension site.', ref),
34
35
  };
35
36
  }
36
- function resolveTarget(resource, tokens, diagnosticPointer, ref) {
37
- const target = resolvePointer(resource.schema, tokens);
37
+ function resolveTarget(resource, pointers, tokens, diagnosticPointer, ref) {
38
38
  const pointer = tokensToPointer(tokens);
39
- if (target === undefined || !collectSchemaPointers(resource.schema).has(pointer)) {
39
+ if (!pointers.has(pointer)) {
40
40
  return {
41
41
  diagnostic: diagnostic('VS_REFERENCE_RESOLUTION', diagnosticPointer, 'The $ref does not resolve to an exact schema location in the registry.', ref),
42
42
  };
@@ -8,5 +8,10 @@ export interface SchemaLocation {
8
8
  export declare function walkSchema(schema: JsonSchema, visit: (location: SchemaLocation) => void, pointer?: string): void;
9
9
  /** Visit each subschema `keyword` holds directly, with its pointer under `pointer`. */
10
10
  export declare function forEachSubschema(keyword: string, value: unknown, pointer: string, visit: (schema: JsonSchema, pointer: string) => void): void;
11
+ /**
12
+ * Whether `keyword`, if it holds subschemas at all, holds nothing else. `forEachSubschema` skips
13
+ * what the meta-schema refuses there, while a reader of an admitted schema counts on every member.
14
+ */
15
+ export declare function holdsOnlySubschemas(keyword: string, value: unknown): boolean;
11
16
  export declare function collectSchemaPointers(schema: JsonSchema): ReadonlySet<string>;
12
17
  export declare function isJsonSchema(value: unknown): value is JsonSchema;
@@ -42,6 +42,20 @@ export function forEachSubschema(keyword, value, pointer, visit) {
42
42
  }
43
43
  }
44
44
  }
45
+ /**
46
+ * Whether `keyword`, if it holds subschemas at all, holds nothing else. `forEachSubschema` skips
47
+ * what the meta-schema refuses there, while a reader of an admitted schema counts on every member.
48
+ */
49
+ export function holdsOnlySubschemas(keyword, value) {
50
+ if (SCHEMA_SINGLE_KEYWORDS.has(keyword))
51
+ return isJsonSchema(value);
52
+ if (SCHEMA_ARRAY_KEYWORDS.has(keyword))
53
+ return Array.isArray(value) && value.every(isJsonSchema);
54
+ if (SCHEMA_MAP_KEYWORDS.has(keyword)) {
55
+ return isJsonObject(value) && Object.values(value).every(isJsonSchema);
56
+ }
57
+ return true;
58
+ }
45
59
  export function collectSchemaPointers(schema) {
46
60
  const pointers = new Set();
47
61
  walkSchema(schema, ({ pointer }) => pointers.add(pointer));
@@ -19,7 +19,7 @@
19
19
  "portable-json": {
20
20
  "code": "DV_JSON_VALUE",
21
21
  "stage": "structure",
22
- "statement": "The document is portable JSON: as text, UTF-8 that parses, within 16,777,216 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 1,048,576 bytes of UTF-8, at most 64 nested arrays and objects, and at most 100,000 members and items in all.",
22
+ "statement": "The document is portable JSON: as text, UTF-8 that parses, within 16,777,216 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 1,048,576 bytes of UTF-8, at most 64 nested arrays and objects, and at most 100,000 members and items in all. A Bundle holds a closure whole, so as a whole it holds at most 1,000,000 members and items, and each Domain in it the limits above.",
23
23
  "positions": [
24
24
  "#/$defs/portable-json"
25
25
  ]
@@ -1,3 +1,5 @@
1
1
  import type { DomainSchemaLookup } from '../dependency/lookup.js';
2
- import type { DomainSchema } from '../model/schema.js';
2
+ import type { DomainSchema, DomainSchemaIR } from '../model/schema.js';
3
3
  export declare function acceptDomainSchema(input: unknown, lookup?: DomainSchemaLookup): DomainSchema;
4
+ /** Hold a document `structureDomainSchema` already read to the semantics of its language. */
5
+ export declare function acceptStructuredDomainSchema(structured: DomainSchemaIR, lookup: DomainSchemaLookup): DomainSchema;
@@ -5,7 +5,10 @@ import { rememberDomainClosure } from '../resolution/closure.js';
5
5
  import { validateDomainSchemaSemantics } from '../validation/domain.js';
6
6
  import { structureDomainSchema } from '../validation/domain.route.js';
7
7
  export function acceptDomainSchema(input, lookup = emptyDomainSchemaLookup()) {
8
- const structured = structureDomainSchema(input);
8
+ return acceptStructuredDomainSchema(structureDomainSchema(input), lookup);
9
+ }
10
+ /** Hold a document `structureDomainSchema` already read to the semantics of its language. */
11
+ export function acceptStructuredDomainSchema(structured, lookup) {
9
12
  const validation = validateDomainSchemaSemantics(structured, lookup);
10
13
  if (validation.diagnostics.length > 0)
11
14
  throw new SchemaError(validation.diagnostics);
@@ -40,6 +40,10 @@ export interface DefinitionAnalysisResult {
40
40
  readonly definitions: ReadonlyMap<string, DefinitionAnalysis>;
41
41
  readonly diagnostics: readonly SchemaDiagnostic[];
42
42
  }
43
+ /**
44
+ * Compose every Class from its parents, unless a chain of parents is past its limit: then nothing
45
+ * is composed, since composing holds each Class's ancestors and walks them on the call stack.
46
+ */
43
47
  export declare function analyzeDefinitions(environment: DomainResolutionContext): DefinitionAnalysisResult;
44
48
  /** The exact signature required by abstract Method composition. */
45
49
  export declare function sameMethodSignature(left: MethodDefinition, right: MethodDefinition): boolean;