@astrale-os/kernel-dsl 1.0.0-beta.27 → 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.
- package/dist/v1/addressing/ordering.d.ts +2 -2
- package/dist/v1/addressing/ordering.js +2 -4
- package/dist/v1/builder/index.d.ts +2 -0
- package/dist/v1/builder/index.js +1 -0
- package/dist/v1/builder/schema/rule.d.ts +316 -0
- package/dist/v1/builder/schema/rule.js +192 -0
- package/dist/v1/bundle/index.d.ts +2 -0
- package/dist/v1/bundle/index.js +1 -0
- package/dist/v1/bundle/rule.d.ts +14 -0
- package/dist/v1/bundle/rule.js +41 -0
- package/dist/v1/compiled/admission/diagnostic.d.ts +14 -0
- package/dist/v1/compiled/admission/diagnostic.js +6 -0
- package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -3
- package/dist/v1/compiled/admission/semantics/policy/parity.js +8 -13
- package/dist/v1/compiled/admission/semantics/policy/pattern.js +3 -5
- package/dist/v1/compiled/admission/wire/policy.js +16 -11
- package/dist/v1/compiled/index.d.ts +2 -0
- package/dist/v1/compiled/index.js +1 -0
- package/dist/v1/compiled/rule.d.ts +49 -0
- package/dist/v1/compiled/rule.js +169 -0
- package/dist/v1/language/callable/admission.js +2 -1
- package/dist/v1/language/policy/analysis/branches.js +6 -7
- package/dist/v1/language/policy/analysis/budgets.js +8 -6
- package/dist/v1/language/policy/analysis/checks.js +5 -4
- package/dist/v1/language/policy/analysis/composition.js +2 -2
- package/dist/v1/language/policy/analysis/typing.js +3 -2
- package/dist/v1/language/policy/model/policy.d.ts +22 -0
- package/dist/v1/language/policy/model/policy.js +28 -4
- package/dist/v1/language/policy/normalization/normalize.js +33 -56
- package/dist/v1/language/value/evaluate/assertions.d.ts +2 -2
- package/dist/v1/language/value/evaluate/assertions.js +4 -34
- package/dist/v1/language/value/evaluate/evaluator.js +10 -15
- package/dist/v1/language/value/evaluate/validity.optimization.js +9 -14
- package/dist/v1/language/value/files.js +2 -1
- package/dist/v1/language/value/ordering.js +1 -3
- package/dist/v1/language/value/profile/canonicalize.js +1 -3
- package/dist/v1/language/value/syntax/walk.d.ts +2 -0
- package/dist/v1/language/value/syntax/walk.js +4 -0
- package/dist/v1/schema/compatibility/api.d.ts +2 -0
- package/dist/v1/schema/compatibility/api.js +1 -0
- package/dist/v1/schema/compatibility/rule.d.ts +13 -0
- package/dist/v1/schema/compatibility/rule.js +23 -0
- package/dist/v1/schema/enforcement/changes.d.ts +590 -0
- package/dist/v1/schema/enforcement/changes.js +566 -0
- package/dist/v1/schema/enforcement/derived.d.ts +236 -0
- package/dist/v1/schema/enforcement/derived.js +243 -0
- package/dist/v1/schema/enforcement/dispose.d.ts +308 -0
- package/dist/v1/schema/enforcement/dispose.js +275 -0
- package/dist/v1/schema/enforcement/facts.d.ts +89 -0
- package/dist/v1/schema/enforcement/facts.js +70 -0
- package/dist/v1/schema/enforcement/fields.d.ts +65 -0
- package/dist/v1/schema/enforcement/fields.js +36 -0
- package/dist/v1/schema/enforcement/index.d.ts +39 -0
- package/dist/v1/schema/enforcement/index.js +10 -0
- package/dist/v1/schema/enforcement/install.d.ts +1634 -0
- package/dist/v1/schema/enforcement/install.js +1223 -0
- package/dist/v1/schema/enforcement/lifecycle.d.ts +87 -0
- package/dist/v1/schema/enforcement/lifecycle.js +91 -0
- package/dist/v1/schema/enforcement/model.d.ts +253 -0
- package/dist/v1/schema/enforcement/model.js +1 -0
- package/dist/v1/schema/enforcement/obligations.d.ts +248 -0
- package/dist/v1/schema/enforcement/obligations.js +240 -0
- package/dist/v1/schema/enforcement/write.d.ts +1314 -0
- package/dist/v1/schema/enforcement/write.js +1017 -0
- package/dist/v1/schema/index.d.ts +1 -0
- package/dist/v1/schema/index.js +1 -0
- package/dist/v1/schema/resolution/origins.js +4 -7
- package/dist/v1/schema/rule.d.ts +4 -5
- package/dist/v1/schema/rule.js +19 -13
- package/dist/v1/schema/validation/policy/references.js +5 -11
- package/dist/v1/schema/validation/policy/uses.js +3 -8
- package/dist/value/canonical.d.ts +16 -1
- package/dist/value/canonical.js +90 -33
- package/dist/value/index.d.ts +2 -0
- package/dist/value/index.js +1 -0
- package/dist/value/rule.d.ts +12 -0
- package/dist/value/rule.js +50 -0
- package/package.json +5 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { json } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import { definitionRefIndex, compareDefinitionRefs } from '../../../addressing/ordering.js';
|
|
3
|
-
import { isClassRuleChecks, policyObjectKey, policyVariableSelector } from '../model/policy.js';
|
|
3
|
+
import { isClassRuleChecks, PolicyComposition, policyObjectKey, policyVariableSelector, } from '../model/policy.js';
|
|
4
4
|
export function normalizePolicyExpression(value) {
|
|
5
5
|
if ('match' in value) {
|
|
6
6
|
return { match: normalizePolicyPattern(value.match) };
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return { anyOf: operands(uniqueRefs(value.anyOf)) };
|
|
8
|
+
const { operator, operands: refs } = PolicyComposition.of(value);
|
|
9
|
+
return PolicyComposition.from(operator, operands(uniqueRefs(refs)));
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
12
|
* Passes after the first, while one still changes the Pattern. A pass numbers variables by the
|
|
@@ -55,36 +53,20 @@ export function normalizeClassRule(value) {
|
|
|
55
53
|
function unwrapSingleOperands(value) {
|
|
56
54
|
if ('check' in value || 'sameNode' in value)
|
|
57
55
|
return value;
|
|
58
|
-
const
|
|
59
|
-
const children = uniqueJson(
|
|
60
|
-
const unwrapped = unwrapSingleOperands(child);
|
|
61
|
-
if (all && 'allOf' in unwrapped)
|
|
62
|
-
return unwrapped.allOf;
|
|
63
|
-
if (!all && 'anyOf' in unwrapped)
|
|
64
|
-
return unwrapped.anyOf;
|
|
65
|
-
return [unwrapped];
|
|
66
|
-
}));
|
|
56
|
+
const { operator, operands: values } = PolicyComposition.of(value);
|
|
57
|
+
const children = uniqueJson(values.flatMap((child) => operandsUnder(operator, unwrapSingleOperands(child))));
|
|
67
58
|
if (children.length === 1)
|
|
68
59
|
return children[0];
|
|
69
|
-
return
|
|
60
|
+
return PolicyComposition.from(operator, operands(children));
|
|
70
61
|
}
|
|
71
62
|
export function normalizePolicyChecks(value) {
|
|
72
63
|
if ('check' in value)
|
|
73
64
|
return value;
|
|
74
65
|
if ('sameNode' in value)
|
|
75
66
|
return { sameNode: normalizeEquality(value.sameNode) };
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return 'allOf' in normalized ? normalized.allOf : [normalized];
|
|
80
|
-
});
|
|
81
|
-
return { allOf: operands(uniqueJson(children)) };
|
|
82
|
-
}
|
|
83
|
-
const children = value.anyOf.flatMap((child) => {
|
|
84
|
-
const normalized = normalizePolicyChecks(child);
|
|
85
|
-
return 'anyOf' in normalized ? normalized.anyOf : [normalized];
|
|
86
|
-
});
|
|
87
|
-
return { anyOf: operands(uniqueJson(children)) };
|
|
67
|
+
const { operator, operands: values } = PolicyComposition.of(value);
|
|
68
|
+
const children = values.flatMap((child) => operandsUnder(operator, normalizePolicyChecks(child)));
|
|
69
|
+
return PolicyComposition.from(operator, operands(uniqueJson(children)));
|
|
88
70
|
}
|
|
89
71
|
/**
|
|
90
72
|
* The operands of a non-empty list, mapped, flattened, deduplicated or sorted one by one: still at
|
|
@@ -93,6 +75,16 @@ export function normalizePolicyChecks(value) {
|
|
|
93
75
|
function operands(values) {
|
|
94
76
|
return values;
|
|
95
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* What `value` contributes to a composition under `operator`: its operands if it composes so. The
|
|
80
|
+
* grammar is recursive, so a composition's operands are of its own expression type.
|
|
81
|
+
*/
|
|
82
|
+
function operandsUnder(operator, value) {
|
|
83
|
+
if (!PolicyComposition.is(value))
|
|
84
|
+
return [value];
|
|
85
|
+
const composed = PolicyComposition.of(value);
|
|
86
|
+
return composed.operator === operator ? composed.operands : [value];
|
|
87
|
+
}
|
|
96
88
|
function normalizePatternNode(value) {
|
|
97
89
|
if ('sameNode' in value)
|
|
98
90
|
return { sameNode: normalizeEquality(value.sameNode) };
|
|
@@ -112,18 +104,9 @@ function normalizePatternNode(value) {
|
|
|
112
104
|
},
|
|
113
105
|
};
|
|
114
106
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return 'allOf' in normalized ? normalized.allOf : [normalized];
|
|
119
|
-
});
|
|
120
|
-
return { allOf: operands(uniqueJson(children)) };
|
|
121
|
-
}
|
|
122
|
-
const children = value.anyOf.flatMap((child) => {
|
|
123
|
-
const normalized = normalizePatternNode(child);
|
|
124
|
-
return 'anyOf' in normalized ? normalized.anyOf : [normalized];
|
|
125
|
-
});
|
|
126
|
-
return { anyOf: operands(uniqueJson(children)) };
|
|
107
|
+
const { operator, operands: values } = PolicyComposition.of(value);
|
|
108
|
+
const children = values.flatMap((child) => operandsUnder(operator, normalizePatternNode(child)));
|
|
109
|
+
return PolicyComposition.from(operator, operands(uniqueJson(children)));
|
|
127
110
|
}
|
|
128
111
|
function canonicalVariableIds(value) {
|
|
129
112
|
const declarations = new Map();
|
|
@@ -181,12 +164,10 @@ function collectDeclarations(value, result, depths, depth = 0) {
|
|
|
181
164
|
collectDeclarations(value.exists.where, result, depths, depth + 1);
|
|
182
165
|
return;
|
|
183
166
|
}
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (const child of value.anyOf)
|
|
189
|
-
collectDeclarations(child, result, depths, depth);
|
|
167
|
+
if (!PolicyComposition.is(value))
|
|
168
|
+
return;
|
|
169
|
+
for (const child of PolicyComposition.of(value).operands)
|
|
170
|
+
collectDeclarations(child, result, depths, depth);
|
|
190
171
|
}
|
|
191
172
|
function collectUses(value, result) {
|
|
192
173
|
if ('sameNode' in value) {
|
|
@@ -207,8 +188,7 @@ function collectUses(value, result) {
|
|
|
207
188
|
}
|
|
208
189
|
if ('exists' in value)
|
|
209
190
|
return collectUses(value.exists.where, result);
|
|
210
|
-
const
|
|
211
|
-
for (const child of children)
|
|
191
|
+
for (const child of PolicyComposition.of(value).operands)
|
|
212
192
|
collectUses(child, result);
|
|
213
193
|
}
|
|
214
194
|
function rank(names) {
|
|
@@ -254,12 +234,11 @@ function collectFirstUseKeys(value, colors, scoped, result, prefix = '$') {
|
|
|
254
234
|
collectFirstUseKeys(value.exists.where, colors, scoped, result, `${prefix}:exists`);
|
|
255
235
|
return;
|
|
256
236
|
}
|
|
257
|
-
const
|
|
258
|
-
const operands = 'allOf' in value ? value.allOf : value.anyOf;
|
|
237
|
+
const { operator, operands } = PolicyComposition.of(value);
|
|
259
238
|
const children = operands
|
|
260
239
|
.map((child) => [patternSignature(child, colors), patternSignature(child, scoped), child])
|
|
261
240
|
.sort(([left, leftScoped], [right, rightScoped]) => compareUtf8Bytes(left, right) || compareUtf8Bytes(leftScoped, rightScoped));
|
|
262
|
-
children.forEach(([, , child], index) => collectFirstUseKeys(child, colors, scoped, result, `${prefix}:${
|
|
241
|
+
children.forEach(([, , child], index) => collectFirstUseKeys(child, colors, scoped, result, `${prefix}:${operator}:${index}`));
|
|
263
242
|
}
|
|
264
243
|
function patternSignature(value, colors) {
|
|
265
244
|
if ('sameNode' in value)
|
|
@@ -273,9 +252,8 @@ function patternSignature(value, colors) {
|
|
|
273
252
|
.sort(compareUtf8Bytes)
|
|
274
253
|
.join(',')}:${patternSignature(value.exists.where, colors)}`;
|
|
275
254
|
}
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
return `${key}:${operands
|
|
255
|
+
const { operator, operands } = PolicyComposition.of(value);
|
|
256
|
+
return `${operator}:${operands
|
|
279
257
|
.map((child) => patternSignature(child, colors))
|
|
280
258
|
.sort(compareUtf8Bytes)
|
|
281
259
|
.join('|')}`;
|
|
@@ -311,9 +289,8 @@ function rewriteVariables(value, ids) {
|
|
|
311
289
|
},
|
|
312
290
|
};
|
|
313
291
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return { anyOf: operands(value.anyOf.map((child) => rewriteVariables(child, ids))) };
|
|
292
|
+
const { operator, operands: values } = PolicyComposition.of(value);
|
|
293
|
+
return PolicyComposition.from(operator, operands(values.map((child) => rewriteVariables(child, ids))));
|
|
317
294
|
}
|
|
318
295
|
function selectorSignature(node) {
|
|
319
296
|
const selector = policyVariableSelector(node);
|
|
@@ -4,8 +4,8 @@ export declare function matchesType(input: string, value: JsonValue): boolean;
|
|
|
4
4
|
export declare function codePointLength(input: string): number;
|
|
5
5
|
/**
|
|
6
6
|
* Whether no two items are the same JSON value, at any size their admission allowed, in time linear
|
|
7
|
-
* in their tokens: an item whose
|
|
8
|
-
* one of them, since no
|
|
7
|
+
* in their canonical tokens: an item whose tokens add no node to the trie of the items before it
|
|
8
|
+
* repeats one of them, since no item's tokens are a prefix of another's.
|
|
9
9
|
*/
|
|
10
10
|
export declare function unique(values: readonly JsonValue[]): boolean;
|
|
11
11
|
/** Compare finite JSON numbers as their exact ECMAScript decimal spellings. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canonicalTokens } from '../../../../value/canonical.js';
|
|
1
2
|
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
2
3
|
export function matchesType(input, value) {
|
|
3
4
|
switch (input) {
|
|
@@ -32,15 +33,15 @@ export function codePointLength(input) {
|
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Whether no two items are the same JSON value, at any size their admission allowed, in time linear
|
|
35
|
-
* in their tokens: an item whose
|
|
36
|
-
* one of them, since no
|
|
36
|
+
* in their canonical tokens: an item whose tokens add no node to the trie of the items before it
|
|
37
|
+
* repeats one of them, since no item's tokens are a prefix of another's.
|
|
37
38
|
*/
|
|
38
39
|
export function unique(values) {
|
|
39
40
|
const readings = new Map();
|
|
40
41
|
for (const value of values) {
|
|
41
42
|
let node = readings;
|
|
42
43
|
let repeated = true;
|
|
43
|
-
for (const token of
|
|
44
|
+
for (const token of canonicalTokens(value)) {
|
|
44
45
|
let next = node.get(token);
|
|
45
46
|
if (next === undefined) {
|
|
46
47
|
next = new Map();
|
|
@@ -54,37 +55,6 @@ export function unique(values) {
|
|
|
54
55
|
}
|
|
55
56
|
return true;
|
|
56
57
|
}
|
|
57
|
-
const ARRAY = Symbol('array');
|
|
58
|
-
const OBJECT = Symbol('object');
|
|
59
|
-
const END = Symbol('end');
|
|
60
|
-
/**
|
|
61
|
-
* An admitted value as tokens: each scalar and member name, and where each container starts and
|
|
62
|
-
* ends, with member names sorted. Two values have the same reading exactly when they have the same
|
|
63
|
-
* canonical JSON text, and no reading is a prefix of another. Admission bounded the value under the
|
|
64
|
-
* limits of its validation, so a reading checks none of its own, and it holds neither the text,
|
|
65
|
-
* which may outgrow any string, nor a stack frame per level.
|
|
66
|
-
*/
|
|
67
|
-
function* readingOf(value) {
|
|
68
|
-
const pending = [value];
|
|
69
|
-
while (pending.length > 0) {
|
|
70
|
-
const next = pending.pop();
|
|
71
|
-
if (next === null || typeof next !== 'object') {
|
|
72
|
-
yield next;
|
|
73
|
-
}
|
|
74
|
-
else if (isJsonObject(next)) {
|
|
75
|
-
yield OBJECT;
|
|
76
|
-
pending.push(END);
|
|
77
|
-
for (const name of Object.keys(next).sort())
|
|
78
|
-
pending.push(next[name], name);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
yield ARRAY;
|
|
82
|
-
pending.push(END);
|
|
83
|
-
for (const item of next)
|
|
84
|
-
pending.push(item);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
58
|
/** Compare finite JSON numbers as their exact ECMAScript decimal spellings. */
|
|
89
59
|
export function isMultipleOf(value, divisor) {
|
|
90
60
|
if (!(divisor > 0))
|
|
@@ -4,6 +4,7 @@ import { isCanonicalBlobRef } from '../model/blob.js';
|
|
|
4
4
|
import { isInstantValue } from '../model/instant.js';
|
|
5
5
|
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
6
6
|
import { appendPointer } from '../syntax/pointer.js';
|
|
7
|
+
import { isJsonSchema, schemaList } from '../syntax/walk.js';
|
|
7
8
|
import { codePointLength, isMultipleOf, matchesType, unique } from './assertions.js';
|
|
8
9
|
import { evaluation, mergeAnnotations } from './types.js';
|
|
9
10
|
/** Evaluate complete Draft 2020-12 acceptance without dynamic source generation. */
|
|
@@ -122,17 +123,17 @@ class InstanceEvaluator {
|
|
|
122
123
|
mergeAnnotations(properties, items, admitted[0]);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
if (
|
|
126
|
+
if (isJsonSchema(schema.not)) {
|
|
126
127
|
const result = yield this.evaluate(this.child(location, 'not'), input, instancePointer);
|
|
127
128
|
if (result.valid)
|
|
128
129
|
failures.add(invalid(instancePointer, 'not', 'Value satisfies not.'));
|
|
129
130
|
}
|
|
130
|
-
if (
|
|
131
|
+
if (isJsonSchema(schema.if)) {
|
|
131
132
|
const condition = yield this.evaluate(this.child(location, 'if'), input, instancePointer);
|
|
132
133
|
if (condition.valid)
|
|
133
134
|
mergeAnnotations(properties, items, condition);
|
|
134
135
|
const branch = condition.valid ? 'then' : 'else';
|
|
135
|
-
if (
|
|
136
|
+
if (isJsonSchema(schema[branch])) {
|
|
136
137
|
const result = yield this.evaluate(this.child(location, branch), input, instancePointer);
|
|
137
138
|
absorb(result, failures, properties, items);
|
|
138
139
|
}
|
|
@@ -223,7 +224,7 @@ class InstanceEvaluator {
|
|
|
223
224
|
for (let index = 0; index < presentPrefix; index++)
|
|
224
225
|
items.add(index);
|
|
225
226
|
}
|
|
226
|
-
if (
|
|
227
|
+
if (isJsonSchema(schema.items)) {
|
|
227
228
|
let itemValid = true;
|
|
228
229
|
const admitted = [];
|
|
229
230
|
for (let index = prefixItems.length; index < input.length; index++) {
|
|
@@ -238,7 +239,7 @@ class InstanceEvaluator {
|
|
|
238
239
|
if (itemValid)
|
|
239
240
|
admitted.forEach((index) => items.add(index));
|
|
240
241
|
}
|
|
241
|
-
if (
|
|
242
|
+
if (isJsonSchema(schema.contains)) {
|
|
242
243
|
const matches = [];
|
|
243
244
|
for (let index = 0; index < input.length; index++) {
|
|
244
245
|
const result = yield this.evaluate(this.child(location, 'contains'), input[index], appendPointer(instancePointer, index));
|
|
@@ -254,7 +255,7 @@ class InstanceEvaluator {
|
|
|
254
255
|
matches.forEach((index) => items.add(index));
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
|
-
if (
|
|
258
|
+
if (isJsonSchema(schema.unevaluatedItems)) {
|
|
258
259
|
let valid = true;
|
|
259
260
|
const admitted = [];
|
|
260
261
|
for (let index = 0; index < input.length; index++) {
|
|
@@ -327,7 +328,7 @@ class InstanceEvaluator {
|
|
|
327
328
|
}
|
|
328
329
|
if (patternsValid)
|
|
329
330
|
patternMatched.forEach((name) => properties.add(name));
|
|
330
|
-
if (
|
|
331
|
+
if (isJsonSchema(schema.additionalProperties)) {
|
|
331
332
|
const additional = names.filter((name) => !Object.hasOwn(declared, name) && !patternMatched.has(name));
|
|
332
333
|
let additionalValid = true;
|
|
333
334
|
for (const name of additional) {
|
|
@@ -340,7 +341,7 @@ class InstanceEvaluator {
|
|
|
340
341
|
if (additionalValid)
|
|
341
342
|
additional.forEach((name) => properties.add(name));
|
|
342
343
|
}
|
|
343
|
-
if (
|
|
344
|
+
if (isJsonSchema(schema.propertyNames)) {
|
|
344
345
|
for (const name of names) {
|
|
345
346
|
const result = yield this.evaluate(this.child(location, 'propertyNames'), name, appendPointer(instancePointer, name));
|
|
346
347
|
if (!result.valid)
|
|
@@ -358,7 +359,7 @@ class InstanceEvaluator {
|
|
|
358
359
|
addFailures(failures, result);
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
|
-
if (
|
|
362
|
+
if (isJsonSchema(schema.unevaluatedProperties)) {
|
|
362
363
|
const unevaluated = names.filter((name) => !properties.has(name));
|
|
363
364
|
let valid = true;
|
|
364
365
|
const admitted = [];
|
|
@@ -435,12 +436,6 @@ function contradictsRequiredConst(schema, input) {
|
|
|
435
436
|
}
|
|
436
437
|
return false;
|
|
437
438
|
}
|
|
438
|
-
function schemaList(input) {
|
|
439
|
-
return Array.isArray(input) ? input : undefined;
|
|
440
|
-
}
|
|
441
|
-
function isSchema(input) {
|
|
442
|
-
return typeof input === 'boolean' || isJsonObject(input);
|
|
443
|
-
}
|
|
444
439
|
function invalid(instancePointer, keyword, message) {
|
|
445
440
|
return { instancePointer, keyword, message };
|
|
446
441
|
}
|
|
@@ -2,6 +2,7 @@ import { equal } from '@astrale-os/kernel-dsl/value';
|
|
|
2
2
|
import { isCanonicalBlobRef } from '../model/blob.js';
|
|
3
3
|
import { isInstantValue } from '../model/instant.js';
|
|
4
4
|
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
5
|
+
import { isJsonSchema, schemaList } from '../syntax/walk.js';
|
|
5
6
|
import { codePointLength, isMultipleOf, matchesType, unique } from './assertions.js';
|
|
6
7
|
/**
|
|
7
8
|
* Whether a value satisfies its prepared schema, as the evaluator decides it, without building a
|
|
@@ -138,14 +139,14 @@ function compileCompositions(schema, child, parts) {
|
|
|
138
139
|
return admitted === 1;
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
|
-
if (
|
|
142
|
+
if (isJsonSchema(schema.not)) {
|
|
142
143
|
const not = child('not');
|
|
143
144
|
parts.push((value, depth) => !not(value, depth + 1));
|
|
144
145
|
}
|
|
145
|
-
if (
|
|
146
|
+
if (isJsonSchema(schema.if)) {
|
|
146
147
|
const condition = child('if');
|
|
147
|
-
const then =
|
|
148
|
-
const otherwise =
|
|
148
|
+
const then = isJsonSchema(schema.then) ? child('then') : undefined;
|
|
149
|
+
const otherwise = isJsonSchema(schema.else) ? child('else') : undefined;
|
|
149
150
|
parts.push((value, depth) => {
|
|
150
151
|
const branch = condition(value, depth + 1) ? then : otherwise;
|
|
151
152
|
return branch === undefined || branch(value, depth + 1);
|
|
@@ -226,7 +227,7 @@ function compileArray(schema, child, parts) {
|
|
|
226
227
|
(!distinct || unique(value))));
|
|
227
228
|
}
|
|
228
229
|
const prefix = schemaList(schema.prefixItems)?.map((_, index) => child('prefixItems', index));
|
|
229
|
-
const items =
|
|
230
|
+
const items = isJsonSchema(schema.items) ? child('items') : undefined;
|
|
230
231
|
if (prefix !== undefined || items !== undefined) {
|
|
231
232
|
const leading = prefix ?? [];
|
|
232
233
|
parts.push((value, depth) => {
|
|
@@ -240,7 +241,7 @@ function compileArray(schema, child, parts) {
|
|
|
240
241
|
return true;
|
|
241
242
|
});
|
|
242
243
|
}
|
|
243
|
-
if (
|
|
244
|
+
if (isJsonSchema(schema.contains)) {
|
|
244
245
|
const contains = child('contains');
|
|
245
246
|
const least = typeof schema.minContains === 'number' ? schema.minContains : 1;
|
|
246
247
|
const most = typeof schema.maxContains === 'number' ? schema.maxContains : Number.POSITIVE_INFINITY;
|
|
@@ -297,10 +298,10 @@ function compileObject(compiled, schema, child, parts) {
|
|
|
297
298
|
const patterns = isJsonObject(schema.patternProperties)
|
|
298
299
|
? Object.keys(schema.patternProperties).map((source) => [compiled.matcher(source), child('patternProperties', source)])
|
|
299
300
|
: [];
|
|
300
|
-
const additional =
|
|
301
|
+
const additional = isJsonSchema(schema.additionalProperties)
|
|
301
302
|
? child('additionalProperties')
|
|
302
303
|
: undefined;
|
|
303
|
-
const names =
|
|
304
|
+
const names = isJsonSchema(schema.propertyNames) ? child('propertyNames') : undefined;
|
|
304
305
|
if (properties.size > 0 || patterns.length > 0 || additional !== undefined || names) {
|
|
305
306
|
parts.push((value, depth) => {
|
|
306
307
|
if (!isJsonObject(value))
|
|
@@ -335,9 +336,3 @@ function compileObject(compiled, schema, child, parts) {
|
|
|
335
336
|
dependent.every(([name, check]) => !Object.hasOwn(value, name) || check(value, depth + 1)));
|
|
336
337
|
}
|
|
337
338
|
}
|
|
338
|
-
function schemaList(input) {
|
|
339
|
-
return Array.isArray(input) ? input : undefined;
|
|
340
|
-
}
|
|
341
|
-
function isSchema(input) {
|
|
342
|
-
return typeof input === 'boolean' || isJsonObject(input);
|
|
343
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fileOptionsOf, isFileValueSchema } from './model/file.js';
|
|
2
2
|
import { isValueObject as isJsonObject } from './model/object.js';
|
|
3
3
|
import { escapePointerToken, parseJsonPointerFragment, resolvePointer } from './syntax/pointer.js';
|
|
4
|
+
import { isJsonSchema } from './syntax/walk.js';
|
|
4
5
|
const SAME_VALUE = ['allOf', 'anyOf', 'oneOf'];
|
|
5
6
|
// `not` admits no value through its subschema, so no file field lies below it.
|
|
6
7
|
const SAME_VALUE_SINGLE = ['if', 'then', 'else'];
|
|
@@ -143,7 +144,7 @@ export function locateFiles(positions, input) {
|
|
|
143
144
|
function resolveLocal(root, reference) {
|
|
144
145
|
const tokens = parseJsonPointerFragment(reference);
|
|
145
146
|
const target = tokens === undefined ? undefined : resolvePointer(root, tokens);
|
|
146
|
-
return
|
|
147
|
+
return isJsonSchema(target) ? target : undefined;
|
|
147
148
|
}
|
|
148
149
|
function isPlainObject(value) {
|
|
149
150
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runSuspended } from '../suspended.js';
|
|
2
2
|
import { loadValueProgram } from './compile/load.js';
|
|
3
3
|
import { prepareValueSchema } from './evaluate/preparation.js';
|
|
4
|
+
import { schemaList } from './syntax/walk.js';
|
|
4
5
|
const ALL_JSON_KINDS = new Set([
|
|
5
6
|
'null',
|
|
6
7
|
'boolean',
|
|
@@ -234,6 +235,3 @@ function normalize(input) {
|
|
|
234
235
|
input.delete('set');
|
|
235
236
|
return input;
|
|
236
237
|
}
|
|
237
|
-
function schemaList(input) {
|
|
238
|
-
return Array.isArray(input) ? input : undefined;
|
|
239
|
-
}
|
|
@@ -2,6 +2,7 @@ import { json } from '@astrale-os/kernel-dsl/value';
|
|
|
2
2
|
import { compareDefinitionRefs, compareUnicode } from '../../../addressing/ordering.js';
|
|
3
3
|
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
4
4
|
import { SCHEMA_ARRAY_KEYWORDS, SCHEMA_MAP_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, } from '../syntax/keywords.js';
|
|
5
|
+
import { isJsonSchema } from '../syntax/walk.js';
|
|
5
6
|
const TYPE_ORDER = ['null', 'boolean', 'integer', 'number', 'string', 'array', 'object'];
|
|
6
7
|
const TYPE_RANK = new Map(TYPE_ORDER.map((name, index) => [name, index]));
|
|
7
8
|
const encoder = new TextEncoder();
|
|
@@ -107,6 +108,3 @@ function isComparableRef(value) {
|
|
|
107
108
|
typeof value.kind === 'string' &&
|
|
108
109
|
typeof value.name === 'string');
|
|
109
110
|
}
|
|
110
|
-
function isJsonSchema(value) {
|
|
111
|
-
return typeof value === 'boolean' || isJsonObject(value);
|
|
112
|
-
}
|
|
@@ -15,3 +15,5 @@ export declare function forEachSubschema(keyword: string, value: unknown, pointe
|
|
|
15
15
|
export declare function holdsOnlySubschemas(keyword: string, value: unknown): boolean;
|
|
16
16
|
export declare function collectSchemaPointers(schema: JsonSchema): ReadonlySet<string>;
|
|
17
17
|
export declare function isJsonSchema(value: unknown): value is JsonSchema;
|
|
18
|
+
/** The subschemas an Array keyword holds, read without checking each item. */
|
|
19
|
+
export declare function schemaList(input: unknown): readonly JsonSchema[] | undefined;
|
|
@@ -64,3 +64,7 @@ export function collectSchemaPointers(schema) {
|
|
|
64
64
|
export function isJsonSchema(value) {
|
|
65
65
|
return typeof value === 'boolean' || isJsonObject(value);
|
|
66
66
|
}
|
|
67
|
+
/** The subschemas an Array keyword holds, read without checking each item. */
|
|
68
|
+
export function schemaList(input) {
|
|
69
|
+
return Array.isArray(input) ? input : undefined;
|
|
70
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { compare, compareMeaning, compareStructure } from './compare.js';
|
|
2
2
|
export { closedParents } from './extension.js';
|
|
3
|
+
export { COMPARISON_RULES as RULES } from './rule.js';
|
|
4
|
+
export type { ComparisonRule as Rule } from './rule.js';
|
|
3
5
|
export { requiredBump } from './versioning/index.js';
|
|
4
6
|
export type { Analysis, Assessment, Bump, Comparison, ComparisonEntry, ComparisonEvidence, ComparisonRequest, ComparisonScope, DiagnosticCode, Facet, Fingerprint, MeaningComparison, Observation, RequiredBump, SchemaIdentity, StructureComparison, Subject, Usage, VersionChange, } from './model.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DiagnosticCode } from './model.js';
|
|
2
|
+
/** The rule one code of a refused comparison request reports. */
|
|
3
|
+
export interface ComparisonRule {
|
|
4
|
+
/** The positions its diagnostics point at, in the request, as the positions of `schema.Rule`. */
|
|
5
|
+
readonly positions: readonly [string, ...string[]];
|
|
6
|
+
/** The rule, in one plain sentence. */
|
|
7
|
+
readonly statement: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Every code a comparison request is refused with and the rule it reports, frozen. A code added
|
|
11
|
+
* here does not compile until it is described.
|
|
12
|
+
*/
|
|
13
|
+
export declare const COMPARISON_RULES: Readonly<Record<DiagnosticCode, ComparisonRule>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { deepFreeze } from '../../language/freeze.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every code a comparison request is refused with and the rule it reports, frozen. A code added
|
|
4
|
+
* here does not compile until it is described.
|
|
5
|
+
*/
|
|
6
|
+
export const COMPARISON_RULES = deepFreeze({
|
|
7
|
+
DM_MEMBER_ORIGIN_MISMATCH: {
|
|
8
|
+
positions: ['/target/origin', '/next/origin'],
|
|
9
|
+
statement: 'A member comparison and a required bump compare two versions of one origin.',
|
|
10
|
+
},
|
|
11
|
+
DM_MEMBER_ROOT_INVALID: {
|
|
12
|
+
positions: ['/roots', '/roots/{index}'],
|
|
13
|
+
statement: "The roots of a member comparison are a non-empty list without duplicates of canonical Keys of the source's origin, each of a shape V1 supports and naming a definition of the source under its exact owner.",
|
|
14
|
+
},
|
|
15
|
+
DM_CAPABILITY_INVALID: {
|
|
16
|
+
positions: ['/capabilities', '/capabilities/{index}'],
|
|
17
|
+
statement: 'The capabilities a dependency comparison declares are a list of canonical Keys, each of the target origin naming a Function, Method or Class of the retained source; a Key of another origin is ignored.',
|
|
18
|
+
},
|
|
19
|
+
DM_DEPENDENCY_NOT_RETAINED: {
|
|
20
|
+
positions: ['/target/origin', '/origin'],
|
|
21
|
+
statement: 'A dependency comparison has a target whose origin is in the closure the dependent was accepted with.',
|
|
22
|
+
},
|
|
23
|
+
});
|