@astrale-os/kernel-dsl 1.0.0-beta.21 → 1.0.0-beta.23
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/index.d.ts +2 -0
- package/dist/v1/builder/index.js +1 -0
- package/dist/v1/builder/lowering/value/compile.js +5 -1
- package/dist/v1/builder/lowering/value/file.d.ts +7 -0
- package/dist/v1/builder/lowering/value/file.js +14 -0
- package/dist/v1/builder/lowering/value/zod.js +30 -0
- package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
- package/dist/v1/builder/value/file.d.ts +34 -0
- package/dist/v1/builder/value/file.js +77 -0
- package/dist/v1/index.d.ts +2 -2
- package/dist/v1/index.js +1 -1
- package/dist/v1/language/.spec/schemas/value-schema.schema.json +2 -1
- package/dist/v1/language/validation/rule.js +2 -2
- package/dist/v1/language/value/files.d.ts +44 -0
- package/dist/v1/language/value/files.js +150 -0
- package/dist/v1/language/value/inclusion/evidence.js +2 -0
- package/dist/v1/language/value/inclusion/types.js +23 -0
- package/dist/v1/language/value/model/file.d.ts +41 -0
- package/dist/v1/language/value/model/file.js +122 -0
- package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
- package/dist/v1/language/value/profile/meta-schema.compiled.js +18 -5
- package/dist/v1/language/value/profile/rules.js +10 -1
- package/dist/v1/language/value/profile/vocabulary.d.ts +7 -6
- package/dist/v1/language/value/profile/vocabulary.js +7 -1
- package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
- package/dist/v1/language/value/regexp/unicode.js +1 -1
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +48 -7
- package/dist/v1/schema/validation/domain.json-schema.js +27 -2
- package/dist/v1/schema/validation/domain.structure.d.ts +49 -46
- package/dist/v1/schema/validation/domain.structure.js +140 -50
- package/dist/v1/schema/validation/value-api.d.ts +4 -0
- package/dist/v1/schema/validation/value-api.js +2 -0
- package/dist/v1/schema/validation/value.json-schema.d.ts +5 -0
- package/dist/v1/schema/validation/value.json-schema.js +30 -4
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple,
|
|
1
|
+
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple, xor, } from 'zod';
|
|
2
2
|
import { PropertyKey as SemanticPropertyKey } from '../../addressing/index.js';
|
|
3
3
|
import { CORE_SLUG_PATTERN, DEPENDENCY_ALIAS_PATTERN, DOMAIN_ORIGIN_PATTERN, DOMAIN_REVISION_PATTERN, MEMBER_NAME_PATTERN, PROPERTY_KEY_PATTERN, } from '../../addressing/patterns.js';
|
|
4
4
|
import { MEDIA_TYPE_PATTERN } from '../../language/class/model/data.js';
|
|
@@ -9,6 +9,18 @@ import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
|
9
9
|
import { SchemaError, diagnostic, } from '../diagnostic.js';
|
|
10
10
|
import { DOMAIN_FORMAT, DOMAIN_VERSION } from '../model/format.js';
|
|
11
11
|
export const documentJsonSchema = registry();
|
|
12
|
+
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
13
|
+
export const VARIANTS = 'x-astrale-variants';
|
|
14
|
+
/**
|
|
15
|
+
* A union of disjoint variants. It is exclusive (`xor`) so that zod reports the issues of every
|
|
16
|
+
* variant, from which `matchedVariant` decides what a refused value reports. Its variants never
|
|
17
|
+
* overlap, so JSON Schema states it as any union, by `anyOf`.
|
|
18
|
+
*/
|
|
19
|
+
function variants(options, annotation = {}) {
|
|
20
|
+
const union = xor(options);
|
|
21
|
+
documentJsonSchema.add(union, { ...annotation, [VARIANTS]: true });
|
|
22
|
+
return union;
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
14
26
|
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
@@ -25,9 +37,7 @@ export const structureRules = {
|
|
|
25
37
|
};
|
|
26
38
|
// The pattern refuses `__proto__`, which zod skips before any key check (`lostProtoKeys`).
|
|
27
39
|
const RESERVED_DEPENDENCY_ALIASES = ['prototype', 'constructor'];
|
|
28
|
-
const originSchema =
|
|
29
|
-
.min(3)
|
|
30
|
-
.max(253)
|
|
40
|
+
const originSchema = boundedString(3, 253)
|
|
31
41
|
.regex(DOMAIN_ORIGIN_PATTERN)
|
|
32
42
|
.register(documentJsonSchema, { id: 'origin' });
|
|
33
43
|
const memberNameSchema = string()
|
|
@@ -49,25 +59,15 @@ const propertyKeySchema = string()
|
|
|
49
59
|
params: { structureCode: 'STRUCTURE_PROPERTY_KEY' },
|
|
50
60
|
})
|
|
51
61
|
.register(documentJsonSchema, { id: 'property-key', pattern: PROPERTY_KEY_PATTERN.source });
|
|
52
|
-
const coreSlugSchema =
|
|
53
|
-
.min(1)
|
|
54
|
-
.max(100)
|
|
62
|
+
const coreSlugSchema = boundedString(1, 100)
|
|
55
63
|
.regex(CORE_SLUG_PATTERN)
|
|
56
64
|
.register(documentJsonSchema, { id: 'core-slug' });
|
|
57
65
|
const revisionSchema = string()
|
|
58
66
|
.regex(DOMAIN_REVISION_PATTERN)
|
|
59
67
|
.register(documentJsonSchema, { id: 'revision' });
|
|
60
|
-
const descriptionSchema =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.register(documentJsonSchema, { id: 'description' });
|
|
64
|
-
const iconSchema = string()
|
|
65
|
-
.min(metadata.icon.minLength)
|
|
66
|
-
.max(metadata.icon.maxLength)
|
|
67
|
-
.register(documentJsonSchema, { id: 'icon' });
|
|
68
|
-
const domainNameSchema = string()
|
|
69
|
-
.min(metadata.name.minLength)
|
|
70
|
-
.max(metadata.name.maxLength)
|
|
68
|
+
const descriptionSchema = boundedString(metadata.description.minLength, metadata.description.maxLength, 'description');
|
|
69
|
+
const iconSchema = boundedString(metadata.icon.minLength, metadata.icon.maxLength, 'icon');
|
|
70
|
+
const domainNameSchema = boundedString(metadata.name.minLength, metadata.name.maxLength)
|
|
71
71
|
.refine(metadata.isDomainNameText, {
|
|
72
72
|
message: 'Expected one trimmed line of text.',
|
|
73
73
|
params: { structureCode: 'STRUCTURE_DOMAIN_NAME' },
|
|
@@ -77,12 +77,14 @@ const domainNameSchema = string()
|
|
|
77
77
|
description: 'The display name of the Domain: one trimmed line of text.',
|
|
78
78
|
pattern: metadata.DOMAIN_NAME_TEXT_PATTERN.source,
|
|
79
79
|
});
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// of
|
|
80
|
+
// The parsed document cannot keep a `__proto__` member, which the structure therefore refuses: a
|
|
81
|
+
// closed object reports it as an unknown key, and a record, which skips it, by `lostProtoKeys`. The
|
|
82
|
+
// JSON Schema refuses it by the fields of a closed object and the pattern of a record's names; a
|
|
83
|
+
// record of any string states it here, by its property names.
|
|
83
84
|
const PROTO_KEY = '__proto__';
|
|
85
|
+
const PROTO_KEY_MESSAGE = 'A member named __proto__ is refused: the parsed document cannot keep it.';
|
|
84
86
|
const anyKeyRecord = { propertyNames: { not: { const: PROTO_KEY } } };
|
|
85
|
-
const jsonValueSchema = lazy(() =>
|
|
87
|
+
const jsonValueSchema = lazy(() => variants([
|
|
86
88
|
nullSchema(),
|
|
87
89
|
boolean(),
|
|
88
90
|
number(),
|
|
@@ -91,14 +93,14 @@ const jsonValueSchema = lazy(() => union([
|
|
|
91
93
|
record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord),
|
|
92
94
|
])).register(documentJsonSchema, { id: 'json-value' });
|
|
93
95
|
const jsonObjectSchema = record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord);
|
|
94
|
-
const jsonSchemaSchema =
|
|
96
|
+
const jsonSchemaSchema = variants([boolean(), jsonObjectSchema], {
|
|
95
97
|
id: 'value-schema',
|
|
96
98
|
description: 'A value schema of the dialect https://schemas.astrale.ai/dsl/v1/value-schema. The structure admits any boolean or object; the language admits its keywords.',
|
|
97
99
|
});
|
|
98
100
|
const dataDeclarationSchema = strictObject({
|
|
99
101
|
mediaType: string().regex(MEDIA_TYPE_PATTERN).register(documentJsonSchema, { id: 'media-type' }),
|
|
100
102
|
});
|
|
101
|
-
const stateNameSchema =
|
|
103
|
+
const stateNameSchema = boundedString(1);
|
|
102
104
|
// A custom check reads the relation in place: a record would copy it and drop a `__proto__` state.
|
|
103
105
|
const stateTransitionsSchema = custom(isStateTransitions, {
|
|
104
106
|
message: 'Expected each non-empty state to map non-empty events to non-empty states.',
|
|
@@ -210,12 +212,12 @@ const edgeConstraintsSchema = strictObject({
|
|
|
210
212
|
// A tuple names distinct fields: endpoints, the slug and Properties by key. Normalization puts
|
|
211
213
|
// them, and the tuples, in canonical order (`compareEdgeUniqueFields`). No tuple is spelled by the
|
|
212
214
|
// absence of the field, never by an empty list: one spelling per meaning, one revision.
|
|
213
|
-
const edgeUniqueFieldSchema =
|
|
215
|
+
const edgeUniqueFieldSchema = variants([
|
|
214
216
|
literal('source'),
|
|
215
217
|
literal('target'),
|
|
216
218
|
literal('slug'),
|
|
217
219
|
strictObject({ property: propertyKeySchema }),
|
|
218
|
-
]
|
|
220
|
+
], { id: 'edge-unique-field' });
|
|
219
221
|
const edgeUniqueSchema = nonEmpty(uniqueTupleSet(nonEmpty(uniqueArray(edgeUniqueFieldSchema))));
|
|
220
222
|
// A Node tuple names distinct Properties by key, which normalization puts in code-point order, as
|
|
221
223
|
// it does the tuples (`compareNodeUniqueTuples`). Two orders of one set of keys are one tuple.
|
|
@@ -240,15 +242,15 @@ const policyVariableSelectorSchema = discriminatedUnion('kind', [
|
|
|
240
242
|
strictObject({ kind: literal('any') }),
|
|
241
243
|
strictObject({ kind: literal('satisfies'), class: classRefSchema }),
|
|
242
244
|
]).register(documentJsonSchema, { id: 'policy-variable-selector' });
|
|
243
|
-
const policyVariableSchema =
|
|
245
|
+
const policyVariableSchema = variants([
|
|
244
246
|
strictObject({ variable: policyPatternVariableSchema, class: classRefSchema }),
|
|
245
247
|
strictObject({ variable: policyPatternVariableSchema, selector: policyVariableSelectorSchema }),
|
|
246
|
-
]
|
|
248
|
+
], { id: 'policy-variable' });
|
|
247
249
|
const policyRepeatSchema = strictObject({
|
|
248
250
|
min: number().int().min(0).max(limits.policy.repetition),
|
|
249
251
|
max: number().int().min(0).max(limits.policy.repetition),
|
|
250
252
|
}).register(documentJsonSchema, { id: 'policy-repeat' });
|
|
251
|
-
const policyPatternExpressionSchema = lazy(() =>
|
|
253
|
+
const policyPatternExpressionSchema = lazy(() => variants([
|
|
252
254
|
strictObject({
|
|
253
255
|
sameNode: strictObject({ left: policyPatternNodeSchema, right: policyPatternNodeSchema }),
|
|
254
256
|
}),
|
|
@@ -284,7 +286,7 @@ const classRuleObjectSchema = discriminatedUnion('kind', [
|
|
|
284
286
|
]).register(documentJsonSchema, { id: 'class-rule-object' });
|
|
285
287
|
/** The recursive Policy check grammar, over the objects one use site admits. */
|
|
286
288
|
function policyChecksSchema(objectSchema, id) {
|
|
287
|
-
const checks = lazy(() =>
|
|
289
|
+
const checks = lazy(() => variants([
|
|
288
290
|
strictObject({ sameNode: strictObject({ left: objectSchema, right: objectSchema }) }),
|
|
289
291
|
strictObject({ check: policyRefSchema, object: objectSchema }),
|
|
290
292
|
strictObject({ allOf: nonEmpty(array(checks)) }),
|
|
@@ -336,9 +338,9 @@ const callableShape = {
|
|
|
336
338
|
execution: callableExecutionSchema.optional(),
|
|
337
339
|
admission: callableAdmissionSchema.optional(),
|
|
338
340
|
auth: enumeration(['anonymous', 'authenticated', 'authorized']),
|
|
339
|
-
policy:
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
policy: variants([literal(true), policyCheckExpressionSchema], {
|
|
342
|
+
id: 'callable-policy',
|
|
343
|
+
}).optional(),
|
|
342
344
|
};
|
|
343
345
|
const authorizedPolicy = {
|
|
344
346
|
if: { properties: { auth: { enum: ['anonymous', 'authenticated'] } }, required: ['auth'] },
|
|
@@ -356,13 +358,15 @@ const methodRecordSchema = record(memberNameSchema, methodDeclarationSchema).reg
|
|
|
356
358
|
id: 'method-record',
|
|
357
359
|
});
|
|
358
360
|
// Each slot spells one constant: the other one is what its absence already means.
|
|
359
|
-
const observationPolicySchema =
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const createPolicySchema =
|
|
361
|
+
const observationPolicySchema = variants([literal(false), policyRefSchema, classRuleChecksSchema], {
|
|
362
|
+
id: 'observation-policy',
|
|
363
|
+
});
|
|
364
|
+
const writePolicySchema = variants([literal(true), policyRefSchema, classRuleChecksSchema], {
|
|
365
|
+
id: 'write-policy',
|
|
366
|
+
});
|
|
367
|
+
const createPolicySchema = variants([literal(true), createRuleChecksSchema], {
|
|
368
|
+
id: 'create-policy',
|
|
369
|
+
});
|
|
366
370
|
const nodeClassPoliciesSchema = strictObject({
|
|
367
371
|
read: observationPolicySchema.optional(),
|
|
368
372
|
traverse: observationPolicySchema.optional(),
|
|
@@ -405,7 +409,7 @@ const edgeClassSchema = strictObject({
|
|
|
405
409
|
constraints: edgeConstraintsSchema,
|
|
406
410
|
unique: edgeUniqueSchema.optional(),
|
|
407
411
|
orientation: enumeration(['directed', 'undirected']),
|
|
408
|
-
endpoints:
|
|
412
|
+
endpoints: variants([directedEdgeEndpointsSchema, undirectedEdgeEndpointsSchema]),
|
|
409
413
|
policies: edgeClassPoliciesSchema,
|
|
410
414
|
})
|
|
411
415
|
.refine((edge) => (edge.orientation === 'undirected') === Array.isArray(edge.endpoints), {
|
|
@@ -442,7 +446,7 @@ const classDeclarationSchema = discriminatedUnion('kind', [
|
|
|
442
446
|
]).register(documentJsonSchema, { id: 'class-definition' });
|
|
443
447
|
const functionContractShape = {
|
|
444
448
|
...callableShape,
|
|
445
|
-
input:
|
|
449
|
+
input: variants([binaryInputSchema, valueFunctionInputSchema]),
|
|
446
450
|
};
|
|
447
451
|
const functionDefinitionSchema = strictObject({
|
|
448
452
|
ref: functionRefSchema,
|
|
@@ -452,7 +456,7 @@ const functionDefinitionSchema = strictObject({
|
|
|
452
456
|
.register(documentJsonSchema, { id: 'function-definition', ...authorizedPolicy });
|
|
453
457
|
// A callable contract has the structure of a Function declaration without its ref, wherever it is.
|
|
454
458
|
const callableContractSchema = strictObject(functionContractShape).refine((callable) => callable.auth === 'authorized' || callable.policy === undefined, callablePolicyIssue('function'));
|
|
455
|
-
const policyExpressionSchema =
|
|
459
|
+
const policyExpressionSchema = variants([
|
|
456
460
|
strictObject({
|
|
457
461
|
match: policyPatternExpressionSchema,
|
|
458
462
|
}),
|
|
@@ -516,17 +520,16 @@ export function parseDomainSchemaStructure(input) {
|
|
|
516
520
|
return modelOf(result.data);
|
|
517
521
|
}
|
|
518
522
|
/**
|
|
519
|
-
* Each `__proto__` member of the input that the parsed document lost. Zod skips that member in
|
|
520
|
-
*
|
|
521
|
-
*
|
|
523
|
+
* Each `__proto__` member of the input that the parsed document lost. Zod skips that member in a
|
|
524
|
+
* record, so the structure would accept the document without it; it refuses the document instead.
|
|
525
|
+
* A closed object reports the member itself, as an unknown key. A State's transitions are read in
|
|
526
|
+
* place and keep the member.
|
|
522
527
|
*/
|
|
523
528
|
function lostProtoKeys(input, parsed, path) {
|
|
524
529
|
if (!isObject(input) || !isObject(parsed))
|
|
525
530
|
return [];
|
|
526
531
|
const lost = Object.hasOwn(input, PROTO_KEY) && !Object.hasOwn(parsed, PROTO_KEY)
|
|
527
|
-
? [
|
|
528
|
-
diagnostic('STRUCTURE_PROTO_KEY', pointer([...path, PROTO_KEY]), 'A member named __proto__ is refused: the parsed document cannot keep it.'),
|
|
529
|
-
]
|
|
532
|
+
? [diagnostic('STRUCTURE_PROTO_KEY', pointer([...path, PROTO_KEY]), PROTO_KEY_MESSAGE)]
|
|
530
533
|
: [];
|
|
531
534
|
return [
|
|
532
535
|
...lost,
|
|
@@ -592,6 +595,44 @@ function isRecord(input) {
|
|
|
592
595
|
function isObject(input) {
|
|
593
596
|
return input !== null && typeof input === 'object';
|
|
594
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* A string of `minimum` to `maximum` UTF-16 code units, the length the language measures, stated in
|
|
600
|
+
* JSON Schema as `minLength` and `maxLength` under the rule `length-in-utf16-code-units`. Zod's own
|
|
601
|
+
* string bounds count code points, which would admit twice the code units of the bound.
|
|
602
|
+
*/
|
|
603
|
+
function boundedString(minimum, maximum, id) {
|
|
604
|
+
return string()
|
|
605
|
+
.check((payload) => {
|
|
606
|
+
const length = payload.value.length;
|
|
607
|
+
if (length < minimum) {
|
|
608
|
+
payload.issues.push({
|
|
609
|
+
code: 'too_small',
|
|
610
|
+
origin: 'string',
|
|
611
|
+
minimum,
|
|
612
|
+
inclusive: true,
|
|
613
|
+
input: payload.value,
|
|
614
|
+
continue: true,
|
|
615
|
+
message: `Expected at least ${minimum} UTF-16 code units.`,
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
else if (maximum !== undefined && length > maximum) {
|
|
619
|
+
payload.issues.push({
|
|
620
|
+
code: 'too_big',
|
|
621
|
+
origin: 'string',
|
|
622
|
+
maximum,
|
|
623
|
+
inclusive: true,
|
|
624
|
+
input: payload.value,
|
|
625
|
+
continue: true,
|
|
626
|
+
message: `Expected at most ${maximum} UTF-16 code units.`,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
.register(documentJsonSchema, {
|
|
631
|
+
...(id === undefined ? {} : { id }),
|
|
632
|
+
minLength: minimum,
|
|
633
|
+
...(maximum === undefined ? {} : { maxLength: maximum }),
|
|
634
|
+
});
|
|
635
|
+
}
|
|
595
636
|
/** At least one item, which `min(1)` proves: the output is typed as the non-empty tuple it is. */
|
|
596
637
|
function nonEmpty(list) {
|
|
597
638
|
return list.min(1);
|
|
@@ -638,7 +679,14 @@ function canonicalJson(value) {
|
|
|
638
679
|
}
|
|
639
680
|
function diagnosticsForIssue(issue, input) {
|
|
640
681
|
if (issue.code === 'unrecognized_keys') {
|
|
641
|
-
return issue.keys.map((key) =>
|
|
682
|
+
return issue.keys.map((key) => key === PROTO_KEY
|
|
683
|
+
? diagnostic('STRUCTURE_PROTO_KEY', pointer([...issue.path, key]), PROTO_KEY_MESSAGE)
|
|
684
|
+
: diagnostic('STRUCTURE_UNKNOWN_FIELD', pointer([...issue.path, key]), `Unknown field ${JSON.stringify(key)}.`));
|
|
685
|
+
}
|
|
686
|
+
if (issue.code === 'invalid_union') {
|
|
687
|
+
const matched = matchedVariant(issue);
|
|
688
|
+
if (matched !== undefined)
|
|
689
|
+
return matched.flatMap((inner) => diagnosticsForIssue(inner, input));
|
|
642
690
|
}
|
|
643
691
|
// A record key refused by a refinement reports that refinement, at the key.
|
|
644
692
|
const refinement = issue.code === 'invalid_key' ? issue.issues.find(isRefinement) : undefined;
|
|
@@ -649,6 +697,48 @@ function diagnosticsForIssue(issue, input) {
|
|
|
649
697
|
diagnostic(structureCode(issue, input), pointer(issue.path), structureMessage(issue, input)),
|
|
650
698
|
];
|
|
651
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* The issues of the one variant a refused union value has the shape of, or none: a union reports
|
|
702
|
+
* `STRUCTURE_UNION` unless exactly one variant refuses the value only by checks (bounds, formats,
|
|
703
|
+
* refinements, or a `__proto__` member). A refused union in a variant counts as checks when it
|
|
704
|
+
* resolves to one variant itself. The structure's unions are exclusive (`xor`), so zod reports each
|
|
705
|
+
* variant's issues and this rule, not zod's choice among them, decides what is reported.
|
|
706
|
+
*/
|
|
707
|
+
function matchedVariant(issue) {
|
|
708
|
+
const candidates = issue.errors.flatMap((variant) => {
|
|
709
|
+
const checks = checksOnly(variant);
|
|
710
|
+
return checks === undefined ? [] : [checks];
|
|
711
|
+
});
|
|
712
|
+
const [only] = candidates;
|
|
713
|
+
if (candidates.length !== 1 || only === undefined)
|
|
714
|
+
return undefined;
|
|
715
|
+
return only.map((inner) => ({ ...inner, path: [...issue.path, ...inner.path] }));
|
|
716
|
+
}
|
|
717
|
+
function checksOnly(issues) {
|
|
718
|
+
const checks = [];
|
|
719
|
+
for (const issue of issues) {
|
|
720
|
+
if (issue.code === 'invalid_union') {
|
|
721
|
+
const matched = matchedVariant(issue);
|
|
722
|
+
if (matched === undefined)
|
|
723
|
+
return undefined;
|
|
724
|
+
checks.push(...matched);
|
|
725
|
+
}
|
|
726
|
+
else if (CHECK_CODES.has(issue.code) ||
|
|
727
|
+
(issue.code === 'unrecognized_keys' && issue.keys.every((key) => key === PROTO_KEY))) {
|
|
728
|
+
checks.push(issue);
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return checks;
|
|
735
|
+
}
|
|
736
|
+
const CHECK_CODES = new Set([
|
|
737
|
+
'custom',
|
|
738
|
+
'invalid_format',
|
|
739
|
+
'too_big',
|
|
740
|
+
'too_small',
|
|
741
|
+
]);
|
|
652
742
|
function isRefinement(issue) {
|
|
653
743
|
return issue.code === 'custom';
|
|
654
744
|
}
|
|
@@ -7,6 +7,10 @@ import type { DomainSchema } from '../model/schema.js';
|
|
|
7
7
|
export { VALUE_SCHEMA_DIALECT as DIALECT, VALUE_SCHEMA_VOCABULARY as VOCABULARY, } from '../../language/value/model/schema.js';
|
|
8
8
|
export { blob, isBlobValueSchema as isBlob } from '../../language/value/model/blob.js';
|
|
9
9
|
export type { BlobOptions, BlobReceipt, BlobRef, BlobSchema, } from '../../language/value/model/blob.js';
|
|
10
|
+
export { file, isFileValueSchema as isFile } from '../../language/value/model/file.js';
|
|
11
|
+
export type { FileOptions, FileSchema } from '../../language/value/model/file.js';
|
|
12
|
+
export { filePositions, locateFiles } from '../../language/value/files.js';
|
|
13
|
+
export type { FilePosition, FileSegment, LocatedFile } from '../../language/value/files.js';
|
|
10
14
|
export type { JsonSchema as Schema, JsonSchemaObject as SchemaObject, PathAnnotation, PropertyObjectSchema as PropertySchema, ValueSchemaContext as Context, } from '../../language/value/model/schema.js';
|
|
11
15
|
export { instant } from '../../language/value/model/instant.js';
|
|
12
16
|
export type { OrderingKind } from '../../language/value/ordering.js';
|
|
@@ -7,6 +7,8 @@ import { createDomainValueSchemaRegistry } from '../resolution/value.registry.js
|
|
|
7
7
|
const registries = new WeakMap();
|
|
8
8
|
export { VALUE_SCHEMA_DIALECT as DIALECT, VALUE_SCHEMA_VOCABULARY as VOCABULARY, } from '../../language/value/model/schema.js';
|
|
9
9
|
export { blob, isBlobValueSchema as isBlob } from '../../language/value/model/blob.js';
|
|
10
|
+
export { file, isFileValueSchema as isFile } from '../../language/value/model/file.js';
|
|
11
|
+
export { filePositions, locateFiles } from '../../language/value/files.js';
|
|
10
12
|
export { instant } from '../../language/value/model/instant.js';
|
|
11
13
|
export { VALUE_KINDS } from '../../language/value/ordering.js';
|
|
12
14
|
export { GRAPH_NODE_PATH_SCHEMA_ID as NODE_PATH } from '../../language/value/syntax/node-path/schema.js';
|
|
@@ -9,6 +9,11 @@ export declare const valueSchemaRules: {
|
|
|
9
9
|
readonly valueCode: 'VS_VALUE_KIND';
|
|
10
10
|
readonly statement: 'A blob is declared only by the whole schema of a Property, exactly as values.blob writes it.';
|
|
11
11
|
};
|
|
12
|
+
readonly 'value-file': {
|
|
13
|
+
readonly code: 'DV_VALUE_SCHEMA';
|
|
14
|
+
readonly valueCode: 'VS_VALUE_KIND';
|
|
15
|
+
readonly statement: 'A file is declared only inside a callable input, exactly as values.file writes it, and x-astrale-file only beside it.';
|
|
16
|
+
};
|
|
12
17
|
readonly 'value-path': {
|
|
13
18
|
readonly code: 'DV_VALUE_SCHEMA';
|
|
14
19
|
readonly valueCode: 'VS_PATH_EXTENSION';
|
|
@@ -12,6 +12,11 @@ export const valueSchemaRules = {
|
|
|
12
12
|
valueCode: 'VS_VALUE_KIND',
|
|
13
13
|
statement: 'A blob is declared only by the whole schema of a Property, exactly as values.blob writes it.',
|
|
14
14
|
},
|
|
15
|
+
'value-file': {
|
|
16
|
+
code: 'DV_VALUE_SCHEMA',
|
|
17
|
+
valueCode: 'VS_VALUE_KIND',
|
|
18
|
+
statement: 'A file is declared only inside a callable input, exactly as values.file writes it, and x-astrale-file only beside it.',
|
|
19
|
+
},
|
|
15
20
|
// Its members are stated (`path-annotation`); where it stands is named.
|
|
16
21
|
'value-path': {
|
|
17
22
|
code: 'DV_VALUE_SCHEMA',
|
|
@@ -43,6 +48,7 @@ const KIND = 'x-astrale-value-kind';
|
|
|
43
48
|
const LOCATION = '#/$defs/value-location';
|
|
44
49
|
const SUBSCHEMA = '#/$defs/value-subschema';
|
|
45
50
|
const PATH = '#/$defs/path-annotation';
|
|
51
|
+
const FILE = '#/$defs/file-annotation';
|
|
46
52
|
/**
|
|
47
53
|
* The value language in JSON Schema, for the document that embeds value schemas: `root` constrains
|
|
48
54
|
* the `value-schema` definition with the published dialect and what the profile adds to it,
|
|
@@ -57,7 +63,7 @@ export function valueSchemaJsonSchema() {
|
|
|
57
63
|
objectOrBoolean({
|
|
58
64
|
properties: {
|
|
59
65
|
$schema: { const: VALUE_SCHEMA_DIALECT },
|
|
60
|
-
[KIND]: named({ enum: ['instant', 'blob'] }, 'value-blob'),
|
|
66
|
+
[KIND]: named({ enum: ['instant', 'blob', 'file'] }, 'value-blob', 'value-file'),
|
|
61
67
|
},
|
|
62
68
|
}),
|
|
63
69
|
],
|
|
@@ -73,6 +79,7 @@ export function valueSchemaJsonSchema() {
|
|
|
73
79
|
enum: { type: 'array', uniqueItems: true },
|
|
74
80
|
fullMatch: named({ type: 'string' }, 'value-regexp'),
|
|
75
81
|
pattern: named({ type: 'string' }, 'value-regexp'),
|
|
82
|
+
'x-astrale-file': named({ $ref: FILE }, 'value-file'),
|
|
76
83
|
'x-astrale-path': named({ $ref: PATH }, 'value-path'),
|
|
77
84
|
...Object.fromEntries(SUBSCHEMA_KEYWORDS.single.map((keyword) => [keyword, { $ref: SUBSCHEMA }])),
|
|
78
85
|
...Object.fromEntries(SUBSCHEMA_KEYWORDS.array.map((keyword) => [
|
|
@@ -89,8 +96,8 @@ export function valueSchemaJsonSchema() {
|
|
|
89
96
|
return [keyword, named(members, 'value-regexp')];
|
|
90
97
|
})),
|
|
91
98
|
},
|
|
92
|
-
// An instant
|
|
93
|
-
if: { required: [KIND], properties: { [KIND]: {
|
|
99
|
+
// An instant and a file are strings.
|
|
100
|
+
if: { required: [KIND], properties: { [KIND]: { enum: ['instant', 'file'] } } },
|
|
94
101
|
// oxlint-disable-next-line unicorn/no-thenable -- the JSON Schema keyword
|
|
95
102
|
then: { required: ['type'], properties: { type: { const: 'string' } } },
|
|
96
103
|
}),
|
|
@@ -110,11 +117,30 @@ export function valueSchemaJsonSchema() {
|
|
|
110
117
|
required: ['target', 'cardinality', 'accepts'],
|
|
111
118
|
additionalProperties: false,
|
|
112
119
|
},
|
|
120
|
+
// The constraints of a file field, which a client checks before it uploads.
|
|
121
|
+
'file-annotation': {
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
|
+
maxBytes: { type: 'integer', minimum: 1 },
|
|
125
|
+
mediaTypes: {
|
|
126
|
+
type: 'array',
|
|
127
|
+
minItems: 1,
|
|
128
|
+
uniqueItems: true,
|
|
129
|
+
items: { type: 'string' },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
},
|
|
113
134
|
// A location below the root: no $schema, and no blob.
|
|
114
135
|
'value-subschema': {
|
|
115
136
|
allOf: [
|
|
116
137
|
{ $ref: LOCATION },
|
|
117
|
-
objectOrBoolean({
|
|
138
|
+
objectOrBoolean({
|
|
139
|
+
properties: {
|
|
140
|
+
$schema: false,
|
|
141
|
+
[KIND]: named({ enum: ['instant', 'file'] }, 'value-file'),
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
118
144
|
],
|
|
119
145
|
},
|
|
120
146
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/kernel-dsl",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.23",
|
|
4
4
|
"description": "Astrale Kernel DSL - Schema authoring, inference, and IR serialization",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -102,13 +102,13 @@
|
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"@noble/hashes": "2.3.0",
|
|
104
104
|
"jsonc-parser": "3.3.1",
|
|
105
|
-
"zod": "4.
|
|
105
|
+
"zod": "4.6.7"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
109
109
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
110
110
|
"ajv": "^8.20.0",
|
|
111
|
-
"re2js": "2.8.
|
|
111
|
+
"re2js": "2.8.7",
|
|
112
112
|
"typescript": "~6.0.3",
|
|
113
113
|
"vitest": "^5.0.1",
|
|
114
114
|
"yaml": "2.9.0"
|