@astrale-os/kernel-dsl 1.0.0-beta.23 → 1.0.0-beta.25
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.
- package/dist/v1/builder/lowering/policy.js +4 -24
- package/dist/v1/builder/lowering/schema/context.js +0 -3
- package/dist/v1/builder/lowering/value/compile.js +24 -21
- package/dist/v1/builder/lowering/value/zod.js +10 -4
- package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
- package/dist/v1/bundle/codec.js +50 -67
- package/dist/v1/bundle/diagnostic.d.ts +1 -1
- package/dist/v1/bundle/structure.js +2 -2
- package/dist/v1/compiled/admission/accept.js +6 -6
- package/dist/v1/compiled/admission/closure.js +16 -33
- package/dist/v1/compiled/admission/diagnostic.d.ts +8 -0
- package/dist/v1/compiled/admission/diagnostic.js +33 -0
- package/dist/v1/compiled/admission/semantics/class.js +11 -7
- package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
- package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
- package/dist/v1/compiled/admission/wire/callable.js +13 -19
- package/dist/v1/compiled/admission/wire/class.js +6 -9
- package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
- package/dist/v1/compiled/admission/wire/entry.js +8 -13
- package/dist/v1/compiled/admission/wire/policy.js +4 -3
- package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
- package/dist/v1/compiled/admission/wire/program.js +39 -44
- package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
- package/dist/v1/compiled/admission/wire/property.js +8 -5
- package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
- package/dist/v1/compiled/admission/wire/value.js +0 -7
- package/dist/v1/compiled/codec/json.js +4 -3
- package/dist/v1/compiled/compiler/compile.js +6 -17
- package/dist/v1/compiled/diagnostic.d.ts +1 -1
- package/dist/v1/compiled/loader/load.js +2 -7
- package/dist/v1/domain/model/input.d.ts +2 -2
- package/dist/v1/domain/validation/create.d.ts +3 -1
- package/dist/v1/domain/validation/create.js +13 -8
- package/dist/v1/language/callable/resolved.d.ts +3 -3
- package/dist/v1/language/chain.d.ts +7 -0
- package/dist/v1/language/chain.js +24 -0
- package/dist/v1/language/cycle.d.ts +10 -0
- package/dist/v1/language/cycle.js +30 -0
- package/dist/v1/language/limits.d.ts +19 -0
- package/dist/v1/language/limits.js +17 -0
- package/dist/v1/language/policy/analysis/budgets.js +17 -13
- package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
- package/dist/v1/language/policy/analysis/composition.js +11 -0
- package/dist/v1/language/suspended.d.ts +7 -0
- package/dist/v1/language/suspended.js +23 -0
- package/dist/v1/language/value/compile/fields.js +12 -8
- package/dist/v1/language/value/compile/load.d.ts +5 -0
- package/dist/v1/language/value/compile/load.js +13 -0
- package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
- package/dist/v1/language/value/evaluate/assertions.js +49 -8
- package/dist/v1/language/value/evaluate/evaluator.js +107 -105
- package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
- package/dist/v1/language/value/evaluate/preparation.js +100 -47
- package/dist/v1/language/value/evaluate/program.d.ts +2 -2
- package/dist/v1/language/value/evaluate/program.js +5 -5
- package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
- package/dist/v1/language/value/evaluate/validate.js +9 -9
- package/dist/v1/language/value/evaluate/validity.optimization.js +4 -3
- package/dist/v1/language/value/inclusion/equivalence.js +4 -2
- package/dist/v1/language/value/inclusion/evidence.js +2 -2
- package/dist/v1/language/value/inclusion/includes.d.ts +13 -4
- package/dist/v1/language/value/inclusion/includes.js +34 -5
- package/dist/v1/language/value/inclusion/location.js +10 -7
- package/dist/v1/language/value/ordering.js +62 -70
- package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
- package/dist/v1/language/value/profile/canonicalize.js +64 -83
- package/dist/v1/language/value/profile/json.validate.d.ts +13 -3
- package/dist/v1/language/value/profile/json.validate.js +18 -6
- package/dist/v1/language/value/reference/closure.js +3 -2
- package/dist/v1/language/value/reference/recursion.js +7 -26
- package/dist/v1/language/value/reference/references.d.ts +3 -1
- package/dist/v1/language/value/reference/references.js +7 -7
- package/dist/v1/language/value/syntax/walk.d.ts +5 -0
- package/dist/v1/language/value/syntax/walk.js +14 -0
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +1 -1
- package/dist/v1/schema/admission/accept.d.ts +3 -1
- package/dist/v1/schema/admission/accept.js +4 -1
- package/dist/v1/schema/analysis/class.d.ts +4 -0
- package/dist/v1/schema/analysis/class.js +24 -2
- package/dist/v1/schema/canonical/revision.d.ts +4 -1
- package/dist/v1/schema/canonical/revision.js +4 -1
- package/dist/v1/schema/compatibility/context.d.ts +5 -2
- package/dist/v1/schema/compatibility/context.js +8 -6
- package/dist/v1/schema/compatibility/model.d.ts +1 -1
- package/dist/v1/schema/compatibility/structure/requirements.js +2 -2
- package/dist/v1/schema/compatibility/walk.js +2 -2
- package/dist/v1/schema/diagnostic.d.ts +1 -1
- package/dist/v1/schema/normalization/domain.js +8 -4
- package/dist/v1/schema/resolution/context.js +6 -7
- package/dist/v1/schema/resolution/domain.js +3 -11
- package/dist/v1/schema/rule.js +10 -3
- package/dist/v1/schema/validation/class.js +1 -1
- package/dist/v1/schema/validation/core.js +16 -8
- package/dist/v1/schema/validation/domain.js +20 -3
- package/dist/v1/schema/validation/policy/budgets.d.ts +5 -1
- package/dist/v1/schema/validation/policy/budgets.js +8 -1
- package/dist/v1/schema/validation/policy/references.js +5 -25
- package/dist/value/accept.d.ts +3 -3
- package/dist/value/canonical.js +2 -2
- package/dist/value/equal.d.ts +9 -1
- package/dist/value/equal.js +37 -3
- package/dist/value/index.d.ts +1 -1
- package/dist/value/limits.d.ts +11 -0
- package/package.json +2 -2
- package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
- package/dist/v1/compiled/admission/wire/pattern.js +0 -111
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { equal } from '@astrale-os/kernel-dsl/value';
|
|
2
|
+
import { runSuspended } from '../../suspended.js';
|
|
1
3
|
import { isCanonicalBlobRef } from '../model/blob.js';
|
|
2
4
|
import { isInstantValue } from '../model/instant.js';
|
|
3
5
|
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
4
6
|
import { appendPointer } from '../syntax/pointer.js';
|
|
5
|
-
import { codePointLength, isMultipleOf,
|
|
7
|
+
import { codePointLength, isMultipleOf, matchesType, unique } from './assertions.js';
|
|
6
8
|
import { evaluation, mergeAnnotations } from './types.js';
|
|
7
9
|
/** Evaluate complete Draft 2020-12 acceptance without dynamic source generation. */
|
|
8
10
|
export function evaluateInstance(compiled, input) {
|
|
9
|
-
return new InstanceEvaluator(compiled).evaluate(compiled.root, input, '');
|
|
11
|
+
return runSuspended(new InstanceEvaluator(compiled).evaluate(compiled.root, input, ''));
|
|
10
12
|
}
|
|
11
13
|
/** Bound per-call retention independently of the size or diversity of an input value. */
|
|
12
14
|
const MAX_CACHED_PATTERN_RESULTS = 256;
|
|
@@ -20,7 +22,7 @@ class InstanceEvaluator {
|
|
|
20
22
|
constructor(compiled) {
|
|
21
23
|
this.compiled = compiled;
|
|
22
24
|
}
|
|
23
|
-
evaluate(location, input, instancePointer) {
|
|
25
|
+
*evaluate(location, input, instancePointer) {
|
|
24
26
|
const key = `${location.key}\u0000${instancePointer}`;
|
|
25
27
|
// propertyNames evaluates the name at the property's value pointer. Cache by the actual
|
|
26
28
|
// input too, retaining one result per repeated sub-problem within this call. A null entry
|
|
@@ -37,45 +39,31 @@ class InstanceEvaluator {
|
|
|
37
39
|
this.resultCache.set(input, byLocation);
|
|
38
40
|
}
|
|
39
41
|
byLocation.set(key, null);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
result = evaluation();
|
|
44
|
-
}
|
|
45
|
-
else if (location.schema === false) {
|
|
46
|
-
result = evaluation([
|
|
47
|
-
invalid(instancePointer, 'false', 'The false schema rejects every value.'),
|
|
48
|
-
]);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
result = this.evaluateObjectSchema(location, location.schema, input, instancePointer);
|
|
52
|
-
}
|
|
42
|
+
const { schema } = location;
|
|
43
|
+
if (typeof schema === 'boolean') {
|
|
44
|
+
const result = evaluation(schema ? [] : [invalid(instancePointer, 'false', 'The false schema rejects every value.')]);
|
|
53
45
|
byLocation.set(key, result);
|
|
54
46
|
return result;
|
|
55
47
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
evaluateObjectSchema(location, schema, input, instancePointer) {
|
|
62
|
-
const failures = [];
|
|
48
|
+
// A set: a location two references reach answers one result, whose failures count once.
|
|
49
|
+
const failures = new Set();
|
|
63
50
|
const properties = new Set();
|
|
64
51
|
const items = new Set();
|
|
65
|
-
const absorbSameLocation = (result) => {
|
|
66
|
-
if (result.valid)
|
|
67
|
-
mergeAnnotations(properties, items, result);
|
|
68
|
-
else
|
|
69
|
-
failures.push(...result.failures);
|
|
70
|
-
};
|
|
71
52
|
if (Object.hasOwn(schema, '$ref')) {
|
|
72
53
|
const target = this.compiled.reference(location);
|
|
73
54
|
if (target === undefined) {
|
|
74
55
|
throw new TypeError('Admitted value schema reference has no prepared resolution.');
|
|
75
56
|
}
|
|
76
|
-
|
|
57
|
+
const result = yield this.evaluate(target, input, instancePointer);
|
|
58
|
+
absorb(result, failures, properties, items);
|
|
59
|
+
}
|
|
60
|
+
if (schema.allOf !== undefined ||
|
|
61
|
+
schema.anyOf !== undefined ||
|
|
62
|
+
schema.oneOf !== undefined ||
|
|
63
|
+
schema.not !== undefined ||
|
|
64
|
+
schema.if !== undefined) {
|
|
65
|
+
yield* this.evaluateCompositions(location, schema, input, instancePointer, failures, properties, items);
|
|
77
66
|
}
|
|
78
|
-
this.evaluateCompositions(location, schema, input, instancePointer, failures, properties, items);
|
|
79
67
|
this.evaluateCommonAssertions(schema, input, instancePointer, failures);
|
|
80
68
|
if (typeof input === 'number') {
|
|
81
69
|
this.evaluateNumberAssertions(schema, input, instancePointer, failures);
|
|
@@ -84,107 +72,110 @@ class InstanceEvaluator {
|
|
|
84
72
|
this.evaluateStringAssertions(schema, input, instancePointer, failures);
|
|
85
73
|
}
|
|
86
74
|
if (Array.isArray(input)) {
|
|
87
|
-
this.evaluateArray(location, schema, input, instancePointer, failures,
|
|
75
|
+
yield* this.evaluateArray(location, schema, input, instancePointer, failures, items);
|
|
88
76
|
}
|
|
89
77
|
else if (isJsonObject(input)) {
|
|
90
|
-
this.evaluateObject(location, schema, input, instancePointer, failures, properties
|
|
78
|
+
yield* this.evaluateObject(location, schema, input, instancePointer, failures, properties);
|
|
91
79
|
}
|
|
92
|
-
|
|
80
|
+
const result = evaluation([...failures], properties, items);
|
|
81
|
+
byLocation.set(key, result);
|
|
82
|
+
return result;
|
|
93
83
|
}
|
|
94
|
-
evaluateCompositions(location, schema, input, instancePointer, failures, properties, items) {
|
|
95
|
-
const absorb = (result) => {
|
|
96
|
-
if (result.valid)
|
|
97
|
-
mergeAnnotations(properties, items, result);
|
|
98
|
-
else
|
|
99
|
-
failures.push(...result.failures);
|
|
100
|
-
};
|
|
84
|
+
*evaluateCompositions(location, schema, input, instancePointer, failures, properties, items) {
|
|
101
85
|
const allOf = schemaList(schema.allOf);
|
|
102
|
-
allOf
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
if (allOf !== undefined) {
|
|
87
|
+
for (let index = 0; index < allOf.length; index++) {
|
|
88
|
+
const branch = this.child(location, 'allOf', index);
|
|
89
|
+
absorb(yield this.evaluate(branch, input, instancePointer), failures, properties, items);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
105
92
|
const anyOf = schemaList(schema.anyOf);
|
|
106
93
|
if (anyOf !== undefined) {
|
|
107
94
|
let admitted = 0;
|
|
108
|
-
anyOf.
|
|
95
|
+
for (let index = 0; index < anyOf.length; index++) {
|
|
109
96
|
const branch = this.child(location, 'anyOf', index);
|
|
110
97
|
if (contradictsRequiredConst(branch.schema, input))
|
|
111
|
-
|
|
112
|
-
const result = this.evaluate(branch, input, instancePointer);
|
|
98
|
+
continue;
|
|
99
|
+
const result = yield this.evaluate(branch, input, instancePointer);
|
|
113
100
|
if (!result.valid)
|
|
114
|
-
|
|
101
|
+
continue;
|
|
115
102
|
admitted += 1;
|
|
116
103
|
mergeAnnotations(properties, items, result);
|
|
117
|
-
}
|
|
104
|
+
}
|
|
118
105
|
if (admitted === 0) {
|
|
119
|
-
failures.
|
|
106
|
+
failures.add(invalid(instancePointer, 'anyOf', 'Value satisfies no anyOf branch.'));
|
|
120
107
|
}
|
|
121
108
|
}
|
|
122
109
|
const oneOf = schemaList(schema.oneOf);
|
|
123
110
|
if (oneOf !== undefined) {
|
|
124
|
-
const admitted =
|
|
125
|
-
|
|
126
|
-
.
|
|
111
|
+
const admitted = [];
|
|
112
|
+
for (let index = 0; index < oneOf.length; index++) {
|
|
113
|
+
const branch = this.child(location, 'oneOf', index);
|
|
114
|
+
const result = yield this.evaluate(branch, input, instancePointer);
|
|
115
|
+
if (result.valid)
|
|
116
|
+
admitted.push(result);
|
|
117
|
+
}
|
|
127
118
|
if (admitted.length !== 1) {
|
|
128
|
-
failures.
|
|
119
|
+
failures.add(invalid(instancePointer, 'oneOf', 'Value must satisfy exactly one oneOf branch.'));
|
|
129
120
|
}
|
|
130
121
|
else {
|
|
131
122
|
mergeAnnotations(properties, items, admitted[0]);
|
|
132
123
|
}
|
|
133
124
|
}
|
|
134
125
|
if (isSchema(schema.not)) {
|
|
135
|
-
const result = this.evaluate(this.child(location, 'not'), input, instancePointer);
|
|
126
|
+
const result = yield this.evaluate(this.child(location, 'not'), input, instancePointer);
|
|
136
127
|
if (result.valid)
|
|
137
|
-
failures.
|
|
128
|
+
failures.add(invalid(instancePointer, 'not', 'Value satisfies not.'));
|
|
138
129
|
}
|
|
139
130
|
if (isSchema(schema.if)) {
|
|
140
|
-
const condition = this.evaluate(this.child(location, 'if'), input, instancePointer);
|
|
131
|
+
const condition = yield this.evaluate(this.child(location, 'if'), input, instancePointer);
|
|
141
132
|
if (condition.valid)
|
|
142
133
|
mergeAnnotations(properties, items, condition);
|
|
143
134
|
const branch = condition.valid ? 'then' : 'else';
|
|
144
135
|
if (isSchema(schema[branch])) {
|
|
145
|
-
|
|
136
|
+
const result = yield this.evaluate(this.child(location, branch), input, instancePointer);
|
|
137
|
+
absorb(result, failures, properties, items);
|
|
146
138
|
}
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
141
|
evaluateCommonAssertions(schema, input, instancePointer, failures) {
|
|
150
142
|
if (schema['x-astrale-value-kind'] === 'instant' && !isInstantValue(input)) {
|
|
151
|
-
failures.
|
|
143
|
+
failures.add(invalid(instancePointer, 'x-astrale-value-kind', 'Value is not an exact UTC millisecond Instant.'));
|
|
152
144
|
}
|
|
153
145
|
if (schema['x-astrale-value-kind'] === 'blob' && !isCanonicalBlobRef(input)) {
|
|
154
|
-
failures.
|
|
146
|
+
failures.add(invalid(instancePointer, 'x-astrale-value-kind', 'Value is not a canonical blob Ref.'));
|
|
155
147
|
}
|
|
156
148
|
if (typeof schema.type === 'string') {
|
|
157
149
|
if (!matchesType(schema.type, input)) {
|
|
158
|
-
failures.
|
|
150
|
+
failures.add(invalid(instancePointer, 'type', `Value is not of type ${schema.type}.`));
|
|
159
151
|
}
|
|
160
152
|
}
|
|
161
153
|
else if (Array.isArray(schema.type) &&
|
|
162
154
|
!schema.type.some((candidate) => typeof candidate === 'string' ? matchesType(candidate, input) : false)) {
|
|
163
|
-
failures.
|
|
155
|
+
failures.add(invalid(instancePointer, 'type', 'Value matches none of the admitted types.'));
|
|
164
156
|
}
|
|
165
|
-
if (Object.hasOwn(schema, 'const') && !
|
|
166
|
-
failures.
|
|
157
|
+
if (Object.hasOwn(schema, 'const') && !equal(input, schema.const)) {
|
|
158
|
+
failures.add(invalid(instancePointer, 'const', 'Value differs from const.'));
|
|
167
159
|
}
|
|
168
|
-
if (Array.isArray(schema.enum) &&
|
|
169
|
-
|
|
170
|
-
failures.push(invalid(instancePointer, 'enum', 'Value is absent from enum.'));
|
|
160
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((candidate) => equal(input, candidate))) {
|
|
161
|
+
failures.add(invalid(instancePointer, 'enum', 'Value is absent from enum.'));
|
|
171
162
|
}
|
|
172
163
|
}
|
|
173
164
|
evaluateNumberAssertions(schema, input, instancePointer, failures) {
|
|
174
165
|
if (typeof schema.multipleOf === 'number' && !isMultipleOf(input, schema.multipleOf)) {
|
|
175
|
-
failures.
|
|
166
|
+
failures.add(invalid(instancePointer, 'multipleOf', 'Number is not an exact multiple.'));
|
|
176
167
|
}
|
|
177
168
|
if (typeof schema.maximum === 'number' && input > schema.maximum) {
|
|
178
|
-
failures.
|
|
169
|
+
failures.add(invalid(instancePointer, 'maximum', 'Number exceeds maximum.'));
|
|
179
170
|
}
|
|
180
171
|
if (typeof schema.exclusiveMaximum === 'number' && input >= schema.exclusiveMaximum) {
|
|
181
|
-
failures.
|
|
172
|
+
failures.add(invalid(instancePointer, 'exclusiveMaximum', 'Number reaches exclusiveMaximum.'));
|
|
182
173
|
}
|
|
183
174
|
if (typeof schema.minimum === 'number' && input < schema.minimum) {
|
|
184
|
-
failures.
|
|
175
|
+
failures.add(invalid(instancePointer, 'minimum', 'Number is below minimum.'));
|
|
185
176
|
}
|
|
186
177
|
if (typeof schema.exclusiveMinimum === 'number' && input <= schema.exclusiveMinimum) {
|
|
187
|
-
failures.
|
|
178
|
+
failures.add(invalid(instancePointer, 'exclusiveMinimum', 'Number reaches exclusiveMinimum.'));
|
|
188
179
|
}
|
|
189
180
|
}
|
|
190
181
|
evaluateStringAssertions(schema, input, instancePointer, failures) {
|
|
@@ -194,38 +185,38 @@ class InstanceEvaluator {
|
|
|
194
185
|
(typeof schema.minLength === 'number' && Math.ceil(input.length / 2) < schema.minLength)) {
|
|
195
186
|
const length = codePointLength(input);
|
|
196
187
|
if (typeof schema.maxLength === 'number' && length > schema.maxLength) {
|
|
197
|
-
failures.
|
|
188
|
+
failures.add(invalid(instancePointer, 'maxLength', 'String exceeds maxLength.'));
|
|
198
189
|
}
|
|
199
190
|
if (typeof schema.minLength === 'number' && length < schema.minLength) {
|
|
200
|
-
failures.
|
|
191
|
+
failures.add(invalid(instancePointer, 'minLength', 'String is below minLength.'));
|
|
201
192
|
}
|
|
202
193
|
}
|
|
203
194
|
if (typeof schema.pattern === 'string' && !this.matchesPattern(schema.pattern, input, false)) {
|
|
204
|
-
failures.
|
|
195
|
+
failures.add(invalid(instancePointer, 'pattern', 'String does not match pattern.'));
|
|
205
196
|
}
|
|
206
197
|
if (typeof schema.fullMatch === 'string' &&
|
|
207
198
|
!this.matchesPattern(schema.fullMatch, input, true)) {
|
|
208
|
-
failures.
|
|
199
|
+
failures.add(invalid(instancePointer, 'fullMatch', 'String does not match fullMatch.'));
|
|
209
200
|
}
|
|
210
201
|
}
|
|
211
|
-
evaluateArray(location, schema, input, instancePointer, failures,
|
|
202
|
+
*evaluateArray(location, schema, input, instancePointer, failures, items) {
|
|
212
203
|
if (typeof schema.maxItems === 'number' && input.length > schema.maxItems) {
|
|
213
|
-
failures.
|
|
204
|
+
failures.add(invalid(instancePointer, 'maxItems', 'Array exceeds maxItems.'));
|
|
214
205
|
}
|
|
215
206
|
if (typeof schema.minItems === 'number' && input.length < schema.minItems) {
|
|
216
|
-
failures.
|
|
207
|
+
failures.add(invalid(instancePointer, 'minItems', 'Array is below minItems.'));
|
|
217
208
|
}
|
|
218
209
|
if (schema.uniqueItems === true && !unique(input)) {
|
|
219
|
-
failures.
|
|
210
|
+
failures.add(invalid(instancePointer, 'uniqueItems', 'Array items are not unique.'));
|
|
220
211
|
}
|
|
221
212
|
const prefixItems = schemaList(schema.prefixItems) ?? [];
|
|
222
213
|
const presentPrefix = Math.min(prefixItems.length, input.length);
|
|
223
214
|
let prefixValid = true;
|
|
224
215
|
for (let index = 0; index < presentPrefix; index++) {
|
|
225
|
-
const result = this.evaluate(this.child(location, 'prefixItems', index), input[index], appendPointer(instancePointer, index));
|
|
216
|
+
const result = yield this.evaluate(this.child(location, 'prefixItems', index), input[index], appendPointer(instancePointer, index));
|
|
226
217
|
if (!result.valid) {
|
|
227
218
|
prefixValid = false;
|
|
228
|
-
failures
|
|
219
|
+
addFailures(failures, result);
|
|
229
220
|
}
|
|
230
221
|
}
|
|
231
222
|
if (prefixValid) {
|
|
@@ -236,12 +227,12 @@ class InstanceEvaluator {
|
|
|
236
227
|
let itemValid = true;
|
|
237
228
|
const admitted = [];
|
|
238
229
|
for (let index = prefixItems.length; index < input.length; index++) {
|
|
239
|
-
const result = this.evaluate(this.child(location, 'items'), input[index], appendPointer(instancePointer, index));
|
|
230
|
+
const result = yield this.evaluate(this.child(location, 'items'), input[index], appendPointer(instancePointer, index));
|
|
240
231
|
if (result.valid)
|
|
241
232
|
admitted.push(index);
|
|
242
233
|
else {
|
|
243
234
|
itemValid = false;
|
|
244
|
-
failures
|
|
235
|
+
addFailures(failures, result);
|
|
245
236
|
}
|
|
246
237
|
}
|
|
247
238
|
if (itemValid)
|
|
@@ -250,14 +241,14 @@ class InstanceEvaluator {
|
|
|
250
241
|
if (isSchema(schema.contains)) {
|
|
251
242
|
const matches = [];
|
|
252
243
|
for (let index = 0; index < input.length; index++) {
|
|
253
|
-
const result = this.evaluate(this.child(location, 'contains'), input[index], appendPointer(instancePointer, index));
|
|
244
|
+
const result = yield this.evaluate(this.child(location, 'contains'), input[index], appendPointer(instancePointer, index));
|
|
254
245
|
if (result.valid)
|
|
255
246
|
matches.push(index);
|
|
256
247
|
}
|
|
257
248
|
const minimum = typeof schema.minContains === 'number' ? schema.minContains : 1;
|
|
258
249
|
const maximum = typeof schema.maxContains === 'number' ? schema.maxContains : Number.POSITIVE_INFINITY;
|
|
259
250
|
if (matches.length < minimum || matches.length > maximum) {
|
|
260
|
-
failures.
|
|
251
|
+
failures.add(invalid(instancePointer, 'contains', 'Array has an invalid number of contains matches.'));
|
|
261
252
|
}
|
|
262
253
|
else {
|
|
263
254
|
matches.forEach((index) => items.add(index));
|
|
@@ -269,30 +260,30 @@ class InstanceEvaluator {
|
|
|
269
260
|
for (let index = 0; index < input.length; index++) {
|
|
270
261
|
if (items.has(index))
|
|
271
262
|
continue;
|
|
272
|
-
const result = this.evaluate(this.child(location, 'unevaluatedItems'), input[index], appendPointer(instancePointer, index));
|
|
263
|
+
const result = yield this.evaluate(this.child(location, 'unevaluatedItems'), input[index], appendPointer(instancePointer, index));
|
|
273
264
|
if (result.valid)
|
|
274
265
|
admitted.push(index);
|
|
275
266
|
else {
|
|
276
267
|
valid = false;
|
|
277
|
-
failures
|
|
268
|
+
addFailures(failures, result);
|
|
278
269
|
}
|
|
279
270
|
}
|
|
280
271
|
if (valid)
|
|
281
272
|
admitted.forEach((index) => items.add(index));
|
|
282
273
|
}
|
|
283
274
|
}
|
|
284
|
-
evaluateObject(location, schema, input, instancePointer, failures, properties
|
|
275
|
+
*evaluateObject(location, schema, input, instancePointer, failures, properties) {
|
|
285
276
|
const names = Object.keys(input);
|
|
286
277
|
if (typeof schema.maxProperties === 'number' && names.length > schema.maxProperties) {
|
|
287
|
-
failures.
|
|
278
|
+
failures.add(invalid(instancePointer, 'maxProperties', 'Object exceeds maxProperties.'));
|
|
288
279
|
}
|
|
289
280
|
if (typeof schema.minProperties === 'number' && names.length < schema.minProperties) {
|
|
290
|
-
failures.
|
|
281
|
+
failures.add(invalid(instancePointer, 'minProperties', 'Object is below minProperties.'));
|
|
291
282
|
}
|
|
292
283
|
if (Array.isArray(schema.required)) {
|
|
293
284
|
for (const name of schema.required) {
|
|
294
285
|
if (typeof name === 'string' && !Object.hasOwn(input, name)) {
|
|
295
|
-
failures.
|
|
286
|
+
failures.add(invalid(instancePointer, 'required', `Object is missing required property ${name}.`));
|
|
296
287
|
}
|
|
297
288
|
}
|
|
298
289
|
}
|
|
@@ -302,7 +293,7 @@ class InstanceEvaluator {
|
|
|
302
293
|
continue;
|
|
303
294
|
for (const dependency of required) {
|
|
304
295
|
if (typeof dependency === 'string' && !Object.hasOwn(input, dependency)) {
|
|
305
|
-
failures.
|
|
296
|
+
failures.add(invalid(instancePointer, 'dependentRequired', `Property ${name} requires property ${dependency}.`));
|
|
306
297
|
}
|
|
307
298
|
}
|
|
308
299
|
}
|
|
@@ -311,10 +302,10 @@ class InstanceEvaluator {
|
|
|
311
302
|
const declaredPresent = Object.keys(declared).filter((name) => Object.hasOwn(input, name));
|
|
312
303
|
let declaredValid = true;
|
|
313
304
|
for (const name of declaredPresent) {
|
|
314
|
-
const result = this.evaluate(this.child(location, 'properties', name), input[name], appendPointer(instancePointer, name));
|
|
305
|
+
const result = yield this.evaluate(this.child(location, 'properties', name), input[name], appendPointer(instancePointer, name));
|
|
315
306
|
if (!result.valid) {
|
|
316
307
|
declaredValid = false;
|
|
317
|
-
failures
|
|
308
|
+
addFailures(failures, result);
|
|
318
309
|
}
|
|
319
310
|
}
|
|
320
311
|
if (declaredValid)
|
|
@@ -327,10 +318,10 @@ class InstanceEvaluator {
|
|
|
327
318
|
if (!this.matchesPattern(pattern, name, false))
|
|
328
319
|
continue;
|
|
329
320
|
patternMatched.add(name);
|
|
330
|
-
const result = this.evaluate(this.child(location, 'patternProperties', pattern), input[name], appendPointer(instancePointer, name));
|
|
321
|
+
const result = yield this.evaluate(this.child(location, 'patternProperties', pattern), input[name], appendPointer(instancePointer, name));
|
|
331
322
|
if (!result.valid) {
|
|
332
323
|
patternsValid = false;
|
|
333
|
-
failures
|
|
324
|
+
addFailures(failures, result);
|
|
334
325
|
}
|
|
335
326
|
}
|
|
336
327
|
}
|
|
@@ -340,10 +331,10 @@ class InstanceEvaluator {
|
|
|
340
331
|
const additional = names.filter((name) => !Object.hasOwn(declared, name) && !patternMatched.has(name));
|
|
341
332
|
let additionalValid = true;
|
|
342
333
|
for (const name of additional) {
|
|
343
|
-
const result = this.evaluate(this.child(location, 'additionalProperties'), input[name], appendPointer(instancePointer, name));
|
|
334
|
+
const result = yield this.evaluate(this.child(location, 'additionalProperties'), input[name], appendPointer(instancePointer, name));
|
|
344
335
|
if (!result.valid) {
|
|
345
336
|
additionalValid = false;
|
|
346
|
-
failures
|
|
337
|
+
addFailures(failures, result);
|
|
347
338
|
}
|
|
348
339
|
}
|
|
349
340
|
if (additionalValid)
|
|
@@ -351,20 +342,20 @@ class InstanceEvaluator {
|
|
|
351
342
|
}
|
|
352
343
|
if (isSchema(schema.propertyNames)) {
|
|
353
344
|
for (const name of names) {
|
|
354
|
-
const result = this.evaluate(this.child(location, 'propertyNames'), name, appendPointer(instancePointer, name));
|
|
345
|
+
const result = yield this.evaluate(this.child(location, 'propertyNames'), name, appendPointer(instancePointer, name));
|
|
355
346
|
if (!result.valid)
|
|
356
|
-
failures
|
|
347
|
+
addFailures(failures, result);
|
|
357
348
|
}
|
|
358
349
|
}
|
|
359
350
|
if (isJsonObject(schema.dependentSchemas)) {
|
|
360
351
|
for (const name of Object.keys(schema.dependentSchemas)) {
|
|
361
352
|
if (!Object.hasOwn(input, name))
|
|
362
353
|
continue;
|
|
363
|
-
const result = this.evaluate(this.child(location, 'dependentSchemas', name), input, instancePointer);
|
|
354
|
+
const result = yield this.evaluate(this.child(location, 'dependentSchemas', name), input, instancePointer);
|
|
364
355
|
if (result.valid)
|
|
365
356
|
mergeAnnotations(properties, new Set(), result);
|
|
366
357
|
else
|
|
367
|
-
failures
|
|
358
|
+
addFailures(failures, result);
|
|
368
359
|
}
|
|
369
360
|
}
|
|
370
361
|
if (isSchema(schema.unevaluatedProperties)) {
|
|
@@ -372,12 +363,12 @@ class InstanceEvaluator {
|
|
|
372
363
|
let valid = true;
|
|
373
364
|
const admitted = [];
|
|
374
365
|
for (const name of unevaluated) {
|
|
375
|
-
const result = this.evaluate(this.child(location, 'unevaluatedProperties'), input[name], appendPointer(instancePointer, name));
|
|
366
|
+
const result = yield this.evaluate(this.child(location, 'unevaluatedProperties'), input[name], appendPointer(instancePointer, name));
|
|
376
367
|
if (result.valid)
|
|
377
368
|
admitted.push(name);
|
|
378
369
|
else {
|
|
379
370
|
valid = false;
|
|
380
|
-
failures
|
|
371
|
+
addFailures(failures, result);
|
|
381
372
|
}
|
|
382
373
|
}
|
|
383
374
|
if (valid)
|
|
@@ -409,6 +400,17 @@ class InstanceEvaluator {
|
|
|
409
400
|
return result;
|
|
410
401
|
}
|
|
411
402
|
}
|
|
403
|
+
/** What a location answering for the same value adds to the location that applies it. */
|
|
404
|
+
function absorb(result, failures, properties, items) {
|
|
405
|
+
if (result.valid)
|
|
406
|
+
mergeAnnotations(properties, items, result);
|
|
407
|
+
else
|
|
408
|
+
addFailures(failures, result);
|
|
409
|
+
}
|
|
410
|
+
function addFailures(failures, result) {
|
|
411
|
+
for (const failure of result.failures)
|
|
412
|
+
failures.add(failure);
|
|
413
|
+
}
|
|
412
414
|
/** A required property with a different primitive const makes the entire branch impossible. */
|
|
413
415
|
function contradictsRequiredConst(schema, input) {
|
|
414
416
|
if (!isJsonObject(schema) || !isJsonObject(input) || !Array.isArray(schema.required)) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Diagnostic } from '../../validation/diagnostic.js';
|
|
2
|
+
import type { ValueProgram } from '../compile/model.js';
|
|
1
3
|
import type { JsonSchema } from '../model/schema.js';
|
|
2
4
|
import type { ValueSchemaRegistry } from '../reference/registry.js';
|
|
3
5
|
import type { IRegexpMatcher } from '../regexp/matcher.js';
|
|
@@ -18,5 +20,19 @@ interface PreparedPattern {
|
|
|
18
20
|
export type PatternPool = Map<string, PreparedPattern>;
|
|
19
21
|
/** Prepare reference and linear-regexp state without generating executable source. */
|
|
20
22
|
export declare function prepareValueSchema(schema: JsonSchema, registry: ValueSchemaRegistry, pointer: string, pool?: PatternPool): InstanceSchemaCompilation;
|
|
23
|
+
/** The one graph a program's root schema has: compiling emits it, admission reads it. */
|
|
24
|
+
export type ValueGraph = Pick<ValueProgram, 'root' | 'nodes'>;
|
|
25
|
+
/**
|
|
26
|
+
* Derive the graph of a schema no admission has seen and the pattern sources it uses, or the refusal
|
|
27
|
+
* of one with no graph to read: a reference with no target, a cycle consuming nothing, or a subschema
|
|
28
|
+
* slot holding anything else. Closed under the two reference forms, it needs no registry and compiles
|
|
29
|
+
* no pattern.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deriveValueGraph(schema: JsonSchema, pointer: string): {
|
|
32
|
+
readonly graph: ValueGraph;
|
|
33
|
+
readonly sources: readonly string[];
|
|
34
|
+
} | {
|
|
35
|
+
readonly refusal: Diagnostic;
|
|
36
|
+
};
|
|
21
37
|
export declare function childKey(pointer: string): string;
|
|
22
38
|
export {};
|