@astrale-os/kernel-dsl 1.0.0-beta.32 → 1.0.0-beta.34
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/class-key.js +16 -4
- package/dist/v1/addressing/key.d.ts +2 -0
- package/dist/v1/addressing/key.js +2 -0
- package/dist/v1/addressing/property-key.js +14 -2
- package/dist/v1/builder/lowering/value/zod.js +0 -25
- package/dist/v1/compiled/admission/wire/entry.js +5 -2
- package/dist/v1/language/policy/normalization/normalize.js +1 -1
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +19 -31
- package/dist/v1/schema/enforcement/install.d.ts +2 -2
- package/dist/v1/schema/enforcement/install.js +8 -2
- package/dist/v1/schema/rule.js +3 -3
- package/dist/v1/schema/validation/domain.json-schema.js +3 -41
- package/dist/v1/schema/validation/domain.structure.d.ts +0 -7
- package/dist/v1/schema/validation/domain.structure.js +28 -57
- package/package.json +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { acceptDefinitionRef } from './definition-ref.js';
|
|
2
|
-
import { Key } from './key.js';
|
|
2
|
+
import { Key, KNOWN_KEYS } from './key.js';
|
|
3
|
+
/**
|
|
4
|
+
* Texts `ClassKey.is` found canonical, at most `KNOWN_KEYS` of them: the test depends on the text
|
|
5
|
+
* alone, and stored rows name the same Classes again and again.
|
|
6
|
+
*/
|
|
7
|
+
const knownClassKeys = new Set();
|
|
3
8
|
/** Admit exact canonical Class-key text. */
|
|
4
9
|
export function ClassKey(input) {
|
|
5
10
|
if (!ClassKey.is(input)) {
|
|
@@ -18,13 +23,20 @@ export function ClassKey(input) {
|
|
|
18
23
|
}
|
|
19
24
|
ClassKey.of = of;
|
|
20
25
|
function is(input) {
|
|
21
|
-
if (typeof input !== 'string'
|
|
26
|
+
if (typeof input !== 'string')
|
|
27
|
+
return false;
|
|
28
|
+
if (knownClassKeys.has(input))
|
|
29
|
+
return true;
|
|
30
|
+
if (!Key.is(input))
|
|
22
31
|
return false;
|
|
23
32
|
// Only the coordinate is tested: an origin label may itself be `property` or `method`.
|
|
24
33
|
const coordinate = input.slice(input.indexOf(':') + 1);
|
|
25
|
-
|
|
34
|
+
const canonical = coordinate.startsWith('class.') &&
|
|
26
35
|
!coordinate.includes('.property.') &&
|
|
27
|
-
!coordinate.includes('.method.')
|
|
36
|
+
!coordinate.includes('.method.');
|
|
37
|
+
if (canonical && knownClassKeys.size < KNOWN_KEYS)
|
|
38
|
+
knownClassKeys.add(input);
|
|
39
|
+
return canonical;
|
|
28
40
|
}
|
|
29
41
|
ClassKey.is = is;
|
|
30
42
|
function ref(input) {
|
|
@@ -5,6 +5,8 @@ export type DefinitionKey<Origin extends Key.Origin = Key.Origin, Kind extends D
|
|
|
5
5
|
export type CoreKey<Origin extends Key.Origin = Key.Origin, Name extends string = string> = DefinitionKey<Origin, 'core', Name>;
|
|
6
6
|
export type PropertyKey<Origin extends Key.Origin = Key.Origin, Owner extends string = string, Name extends string = string> = `${Origin}:class.${Owner}.property.${Name}`;
|
|
7
7
|
export type Key = DefinitionKey | PropertyKey | MethodKey;
|
|
8
|
+
/** How many canonical key texts a key family's `is` keeps, so that a test of one is read back. */
|
|
9
|
+
export declare const KNOWN_KEYS = 16384;
|
|
8
10
|
export declare function Key(input: string): Key;
|
|
9
11
|
/** Canonical origin-qualified address operations. */
|
|
10
12
|
export declare namespace Key {
|
|
@@ -4,6 +4,8 @@ const DEFINITION_KEY = /^(?:class|function|policy|view)\.([A-Za-z][A-Za-z0-9_]*)
|
|
|
4
4
|
// The slug is the whole rest of the coordinate, its own `.` included: no member follows a Core key.
|
|
5
5
|
const CORE_KEY = /^core\.((?=.{1,100}$)[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*)$/u;
|
|
6
6
|
const MEMBER_KEY = /^class\.([A-Za-z][A-Za-z0-9_]*)\.(property|method)\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
7
|
+
/** How many canonical key texts a key family's `is` keeps, so that a test of one is read back. */
|
|
8
|
+
export const KNOWN_KEYS = 16_384;
|
|
7
9
|
/** The keys of frozen Definition coordinates, derived once each. */
|
|
8
10
|
const derived = new WeakMap();
|
|
9
11
|
export function Key(input) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { acceptDefinitionRef } from './definition-ref.js';
|
|
2
|
-
import { Key } from './key.js';
|
|
2
|
+
import { Key, KNOWN_KEYS } from './key.js';
|
|
3
3
|
import { MEMBER_NAME_PATTERN, PROPERTY_KEY_PATTERN } from './patterns.js';
|
|
4
|
+
/**
|
|
5
|
+
* Texts `PropertyKey.is` found canonical, at most `KNOWN_KEYS` of them: the test depends on the
|
|
6
|
+
* text alone, and stored rows name the same keys again and again.
|
|
7
|
+
*/
|
|
8
|
+
const knownPropertyKeys = new Set();
|
|
4
9
|
export function PropertyKey(input) {
|
|
5
10
|
if (!PropertyKey.is(input)) {
|
|
6
11
|
throw new TypeError(`Invalid canonical PropertyKey: ${JSON.stringify(input)}.`);
|
|
@@ -18,7 +23,14 @@ export function PropertyKey(input) {
|
|
|
18
23
|
}
|
|
19
24
|
PropertyKey.of = of;
|
|
20
25
|
function is(input) {
|
|
21
|
-
|
|
26
|
+
if (typeof input !== 'string')
|
|
27
|
+
return false;
|
|
28
|
+
if (knownPropertyKeys.has(input))
|
|
29
|
+
return true;
|
|
30
|
+
const canonical = Key.is(input) && PROPERTY_KEY_PATTERN.test(input);
|
|
31
|
+
if (canonical && knownPropertyKeys.size < KNOWN_KEYS)
|
|
32
|
+
knownPropertyKeys.add(input);
|
|
33
|
+
return canonical;
|
|
22
34
|
}
|
|
23
35
|
PropertyKey.is = is;
|
|
24
36
|
function address(input) {
|
|
@@ -35,7 +35,6 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
|
|
|
35
35
|
path,
|
|
36
36
|
zodSchema: source,
|
|
37
37
|
});
|
|
38
|
-
keepLoweredShape(source, jsonSchema);
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
40
|
});
|
|
@@ -66,28 +65,6 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
|
|
|
66
65
|
diagnostics: [],
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
/**
|
|
70
|
-
* The lowering keeps one spelling per contract, whatever Zod version renders it, so that a Domain
|
|
71
|
-
* built from unchanged source keeps its schema digest. Every node lowers as its own Zod schema: a
|
|
72
|
-
* union by `anyOf`, an intersection by `allOf`, a tuple by its `prefixItems` and rest alone. Zod
|
|
73
|
-
* 4.6 compacts bare-type unions into a `type` array, folds object intersections, and closes tuples;
|
|
74
|
-
* the marker leaves no node bare, so the first two do not apply, and the tuple bounds are removed.
|
|
75
|
-
* `copyZodJson` drops the marker.
|
|
76
|
-
*/
|
|
77
|
-
function keepLoweredShape(schema, jsonSchema) {
|
|
78
|
-
const def = getSchemaDefinition(schema);
|
|
79
|
-
if (def?.type === 'tuple' && Array.isArray(def.items)) {
|
|
80
|
-
if (jsonSchema.items === false)
|
|
81
|
-
delete jsonSchema.items;
|
|
82
|
-
if (jsonSchema.maxItems === def.items.length)
|
|
83
|
-
delete jsonSchema.maxItems;
|
|
84
|
-
if (typeof jsonSchema.minItems === 'number' && jsonSchema.minItems <= def.items.length) {
|
|
85
|
-
delete jsonSchema.minItems;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
jsonSchema[LOWERED_NODE] = true;
|
|
89
|
-
}
|
|
90
|
-
const LOWERED_NODE = '~astrale-lowered-node';
|
|
91
68
|
function copyZodJson(value) {
|
|
92
69
|
if (value === null || ['boolean', 'number', 'string'].includes(typeof value))
|
|
93
70
|
return value;
|
|
@@ -100,8 +77,6 @@ function copyZodJson(value) {
|
|
|
100
77
|
for (const key of Reflect.ownKeys(value)) {
|
|
101
78
|
if (typeof key === 'symbol')
|
|
102
79
|
throw new TypeError('Zod emitted symbol-keyed schema metadata.');
|
|
103
|
-
if (key === LOWERED_NODE)
|
|
104
|
-
continue;
|
|
105
80
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
106
81
|
if (descriptor === undefined)
|
|
107
82
|
continue;
|
|
@@ -2,6 +2,7 @@ import {} from '@astrale-os/kernel-dsl/value';
|
|
|
2
2
|
import {} from '../../../addressing/index.js';
|
|
3
3
|
import * as metadata from '../../../language/definition/metadata.js';
|
|
4
4
|
import { indexValuePrograms } from '../../../language/value/compile/load.js';
|
|
5
|
+
import { codePointLength } from '../../../language/value/evaluate/assertions.js';
|
|
5
6
|
import {} from '../../model/schema.js';
|
|
6
7
|
import { invalid, pointer, withinEncodingLimits } from '../diagnostic.js';
|
|
7
8
|
import { revisionOfCompiledEntry } from '../revision.js';
|
|
@@ -20,8 +21,10 @@ export function entry(input, entryIndex, path, machines) {
|
|
|
20
21
|
exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path, ['icon', 'entrypoint', 'patterns']);
|
|
21
22
|
const origin = originValue(value.origin, 'entry origin', `${path}/origin`);
|
|
22
23
|
const name = string(value.name, 'entry name', `${path}/name`);
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
// The bounds count code points, as the metadata's JSON Schema `minLength` and `maxLength` do.
|
|
25
|
+
const nameLength = codePointLength(name);
|
|
26
|
+
if (nameLength < metadata.name.minLength ||
|
|
27
|
+
nameLength > metadata.name.maxLength ||
|
|
25
28
|
!metadata.isDomainNameText(name))
|
|
26
29
|
invalid('entry name', undefined, `${path}/name`);
|
|
27
30
|
const icon = value.icon === undefined ? undefined : domainIcon(value.icon, `${path}/icon`);
|
|
@@ -154,7 +154,7 @@ function canonicalVariableIds(value) {
|
|
|
154
154
|
if (byDepth !== 0)
|
|
155
155
|
return byDepth;
|
|
156
156
|
// A remaining tie keeps the authored order of the ids: such variables were interchangeable in
|
|
157
|
-
// every admissible Pattern checked (`__tests__/canonical
|
|
157
|
+
// every admissible Pattern checked (`__tests__/canonical-orders-*.test.ts`).
|
|
158
158
|
return left - right;
|
|
159
159
|
});
|
|
160
160
|
return new Map(ordered.map((id, index) => [id, index]));
|
|
@@ -4,18 +4,6 @@
|
|
|
4
4
|
"title": "V1 DomainSchema",
|
|
5
5
|
"$comment": "Generated from the structure the Kernel enforces; value schemas are in the dialect https://schemas.astrale.ai/dsl/v1/value-schema. Each check JSON Schema cannot state is named under x-astrale-rules, with its stage and the positions it constrains.",
|
|
6
6
|
"x-astrale-rules": {
|
|
7
|
-
"length-in-utf16-code-units": {
|
|
8
|
-
"code": "STRUCTURE_MAXIMUM",
|
|
9
|
-
"stage": "structure",
|
|
10
|
-
"statement": "A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.",
|
|
11
|
-
"positions": [
|
|
12
|
-
"#/$defs/core-slug",
|
|
13
|
-
"#/$defs/description",
|
|
14
|
-
"#/$defs/domain-name",
|
|
15
|
-
"#/$defs/icon",
|
|
16
|
-
"#/$defs/origin"
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
7
|
"portable-json": {
|
|
20
8
|
"code": "DV_JSON_VALUE",
|
|
21
9
|
"stage": "structure",
|
|
@@ -317,7 +305,7 @@
|
|
|
317
305
|
]
|
|
318
306
|
},
|
|
319
307
|
"callable-policy": {
|
|
320
|
-
"
|
|
308
|
+
"oneOf": [
|
|
321
309
|
{
|
|
322
310
|
"type": "boolean",
|
|
323
311
|
"const": true
|
|
@@ -359,7 +347,7 @@
|
|
|
359
347
|
"additionalProperties": false
|
|
360
348
|
},
|
|
361
349
|
"class-rule-check-expr": {
|
|
362
|
-
"
|
|
350
|
+
"oneOf": [
|
|
363
351
|
{
|
|
364
352
|
"type": "object",
|
|
365
353
|
"properties": {
|
|
@@ -608,12 +596,12 @@
|
|
|
608
596
|
},
|
|
609
597
|
"core-slug": {
|
|
610
598
|
"type": "string",
|
|
611
|
-
"pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$",
|
|
612
599
|
"minLength": 1,
|
|
613
|
-
"maxLength": 100
|
|
600
|
+
"maxLength": 100,
|
|
601
|
+
"pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$"
|
|
614
602
|
},
|
|
615
603
|
"create-policy": {
|
|
616
|
-
"
|
|
604
|
+
"oneOf": [
|
|
617
605
|
{
|
|
618
606
|
"type": "boolean",
|
|
619
607
|
"const": true
|
|
@@ -624,7 +612,7 @@
|
|
|
624
612
|
]
|
|
625
613
|
},
|
|
626
614
|
"create-rule-check-expr": {
|
|
627
|
-
"
|
|
615
|
+
"oneOf": [
|
|
628
616
|
{
|
|
629
617
|
"type": "object",
|
|
630
618
|
"properties": {
|
|
@@ -991,7 +979,7 @@
|
|
|
991
979
|
]
|
|
992
980
|
},
|
|
993
981
|
"endpoints": {
|
|
994
|
-
"
|
|
982
|
+
"oneOf": [
|
|
995
983
|
{
|
|
996
984
|
"$ref": "#/$defs/directed-endpoints"
|
|
997
985
|
},
|
|
@@ -1146,7 +1134,7 @@
|
|
|
1146
1134
|
}
|
|
1147
1135
|
},
|
|
1148
1136
|
"edge-unique-field": {
|
|
1149
|
-
"
|
|
1137
|
+
"oneOf": [
|
|
1150
1138
|
{
|
|
1151
1139
|
"type": "string",
|
|
1152
1140
|
"const": "source"
|
|
@@ -1201,7 +1189,7 @@
|
|
|
1201
1189
|
"$ref": "#/$defs/description"
|
|
1202
1190
|
},
|
|
1203
1191
|
"input": {
|
|
1204
|
-
"
|
|
1192
|
+
"oneOf": [
|
|
1205
1193
|
{
|
|
1206
1194
|
"$ref": "#/$defs/binary-input"
|
|
1207
1195
|
},
|
|
@@ -1323,7 +1311,7 @@
|
|
|
1323
1311
|
"additionalProperties": false
|
|
1324
1312
|
},
|
|
1325
1313
|
"json-value": {
|
|
1326
|
-
"
|
|
1314
|
+
"oneOf": [
|
|
1327
1315
|
{
|
|
1328
1316
|
"type": "null"
|
|
1329
1317
|
},
|
|
@@ -1614,7 +1602,7 @@
|
|
|
1614
1602
|
}
|
|
1615
1603
|
},
|
|
1616
1604
|
"observation-policy": {
|
|
1617
|
-
"
|
|
1605
|
+
"oneOf": [
|
|
1618
1606
|
{
|
|
1619
1607
|
"type": "boolean",
|
|
1620
1608
|
"const": false
|
|
@@ -1629,9 +1617,9 @@
|
|
|
1629
1617
|
},
|
|
1630
1618
|
"origin": {
|
|
1631
1619
|
"type": "string",
|
|
1632
|
-
"pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$",
|
|
1633
1620
|
"minLength": 3,
|
|
1634
|
-
"maxLength": 253
|
|
1621
|
+
"maxLength": 253,
|
|
1622
|
+
"pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"
|
|
1635
1623
|
},
|
|
1636
1624
|
"path-annotation": {
|
|
1637
1625
|
"type": "object",
|
|
@@ -1661,7 +1649,7 @@
|
|
|
1661
1649
|
"additionalProperties": false
|
|
1662
1650
|
},
|
|
1663
1651
|
"policy-check-expr": {
|
|
1664
|
-
"
|
|
1652
|
+
"oneOf": [
|
|
1665
1653
|
{
|
|
1666
1654
|
"type": "object",
|
|
1667
1655
|
"properties": {
|
|
@@ -1817,7 +1805,7 @@
|
|
|
1817
1805
|
"$ref": "#/$defs/policy-ref"
|
|
1818
1806
|
},
|
|
1819
1807
|
"expression": {
|
|
1820
|
-
"
|
|
1808
|
+
"oneOf": [
|
|
1821
1809
|
{
|
|
1822
1810
|
"type": "object",
|
|
1823
1811
|
"properties": {
|
|
@@ -1884,7 +1872,7 @@
|
|
|
1884
1872
|
"additionalProperties": false
|
|
1885
1873
|
},
|
|
1886
1874
|
"policy-pattern-expr": {
|
|
1887
|
-
"
|
|
1875
|
+
"oneOf": [
|
|
1888
1876
|
{
|
|
1889
1877
|
"type": "object",
|
|
1890
1878
|
"properties": {
|
|
@@ -2151,7 +2139,7 @@
|
|
|
2151
2139
|
"additionalProperties": false
|
|
2152
2140
|
},
|
|
2153
2141
|
"policy-variable": {
|
|
2154
|
-
"
|
|
2142
|
+
"oneOf": [
|
|
2155
2143
|
{
|
|
2156
2144
|
"type": "object",
|
|
2157
2145
|
"properties": {
|
|
@@ -2540,7 +2528,7 @@
|
|
|
2540
2528
|
]
|
|
2541
2529
|
},
|
|
2542
2530
|
"value-schema": {
|
|
2543
|
-
"
|
|
2531
|
+
"oneOf": [
|
|
2544
2532
|
{
|
|
2545
2533
|
"type": "boolean"
|
|
2546
2534
|
},
|
|
@@ -2669,7 +2657,7 @@
|
|
|
2669
2657
|
"description": "Every View targets its owning Domain."
|
|
2670
2658
|
},
|
|
2671
2659
|
"write-policy": {
|
|
2672
|
-
"
|
|
2660
|
+
"oneOf": [
|
|
2673
2661
|
{
|
|
2674
2662
|
"type": "boolean",
|
|
2675
2663
|
"const": true
|
|
@@ -188,8 +188,8 @@ export declare const INSTALL: Readonly<{
|
|
|
188
188
|
readonly refusal: {
|
|
189
189
|
readonly code: 'SCHEMA_ARTIFACT_INVALID';
|
|
190
190
|
};
|
|
191
|
-
readonly statement: 'What a source answers stays within the limits of the protocol.';
|
|
192
|
-
readonly laws: readonly ["SB-LIMITS", "SB-RELEASE-FIRST", "SB-PUBLICATION-VERSION"];
|
|
191
|
+
readonly statement: 'What a source answers stays within the limits of the protocol: an answer over its bound, or a Bundle declared over it, is refused at once, and retrying it does not help.';
|
|
192
|
+
readonly laws: readonly ["SB-LIMITS", "SB-OVER-BOUND-REFUSED", "SB-RELEASE-FIRST", "SB-PUBLICATION-VERSION", "INSTALLATION-OVER-BOUND-SOURCE"];
|
|
193
193
|
};
|
|
194
194
|
readonly SOURCE_RELEASE_DRIFT: {
|
|
195
195
|
readonly phase: 'install';
|
|
@@ -154,8 +154,14 @@ export const INSTALL = deepFreeze({
|
|
|
154
154
|
subjects: ['install.source'],
|
|
155
155
|
does: 'refuse',
|
|
156
156
|
refusal: ARTIFACT,
|
|
157
|
-
statement: 'What a source answers stays within the limits of the protocol.',
|
|
158
|
-
laws: [
|
|
157
|
+
statement: 'What a source answers stays within the limits of the protocol: an answer over its bound, or a Bundle declared over it, is refused at once, and retrying it does not help.',
|
|
158
|
+
laws: [
|
|
159
|
+
'SB-LIMITS',
|
|
160
|
+
'SB-OVER-BOUND-REFUSED',
|
|
161
|
+
'SB-RELEASE-FIRST',
|
|
162
|
+
'SB-PUBLICATION-VERSION',
|
|
163
|
+
'INSTALLATION-OVER-BOUND-SOURCE',
|
|
164
|
+
],
|
|
159
165
|
},
|
|
160
166
|
SOURCE_RELEASE_DRIFT: {
|
|
161
167
|
phase: 'install',
|
package/dist/v1/schema/rule.js
CHANGED
|
@@ -313,7 +313,7 @@ const DECLARED = {
|
|
|
313
313
|
stage: 'structure',
|
|
314
314
|
positions: ['/functions/{function}/input'],
|
|
315
315
|
statement: 'A Function input in binary mode is a binary input: it declares its metadata and maximumBytes.',
|
|
316
|
-
conditions: ['#/$defs/function-definition/properties/input/
|
|
316
|
+
conditions: ['#/$defs/function-definition/properties/input/oneOf/1/not'],
|
|
317
317
|
},
|
|
318
318
|
STRUCTURE_CALLABLE_POLICY_AUTH: {
|
|
319
319
|
stage: 'structure',
|
|
@@ -395,8 +395,8 @@ const DECLARED = {
|
|
|
395
395
|
positions: ANY,
|
|
396
396
|
statement: 'No object of the document has a member named __proto__, except the transitions of a State.',
|
|
397
397
|
conditions: [
|
|
398
|
-
'#/$defs/json-value/
|
|
399
|
-
'#/$defs/value-schema/
|
|
398
|
+
'#/$defs/json-value/oneOf/5/propertyNames/not',
|
|
399
|
+
'#/$defs/value-schema/oneOf/1/propertyNames/not',
|
|
400
400
|
],
|
|
401
401
|
},
|
|
402
402
|
STRUCTURE_REQUIRED: {
|
|
@@ -2,7 +2,7 @@ import { toJSONSchema } from 'zod';
|
|
|
2
2
|
import { VALUE_RULES } from '../../language/validation/rule.js';
|
|
3
3
|
import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
4
4
|
import { RULES } from '../rule.js';
|
|
5
|
-
import { domainSchemaStructure, documentJsonSchema, structureRules,
|
|
5
|
+
import { domainSchemaStructure, documentJsonSchema, structureRules, } from './domain.structure.js';
|
|
6
6
|
import { jsonValueJsonSchema, jsonValueRules, } from './json.json-schema.js';
|
|
7
7
|
import { valueSchemaJsonSchema, valueSchemaRules, } from './value.json-schema.js';
|
|
8
8
|
/** The checks the published document names, each with its stage and the positions it constrains. */
|
|
@@ -25,20 +25,7 @@ export function domainSchemaJsonSchema() {
|
|
|
25
25
|
io: 'input',
|
|
26
26
|
// Every opaque part is stated or named, as `assertChecksStated` proved.
|
|
27
27
|
unrepresentable: 'any',
|
|
28
|
-
override: ({ zodSchema, jsonSchema: rendered }) => {
|
|
29
|
-
// Zod states the items of a tuple but not its length.
|
|
30
|
-
const def = zodSchema._zod.def;
|
|
31
|
-
if (def.type !== 'tuple')
|
|
32
|
-
return;
|
|
33
|
-
if (def.rest !== null || def.items.some((item) => item._zod.optin === 'optional')) {
|
|
34
|
-
throw new Error('A tuple of the structure has a fixed length.');
|
|
35
|
-
}
|
|
36
|
-
rendered.minItems = def.items.length;
|
|
37
|
-
rendered.maxItems = def.items.length;
|
|
38
|
-
},
|
|
39
28
|
});
|
|
40
|
-
stateVariantsByAnyOf(root);
|
|
41
|
-
stateVariantsByAnyOf($defs);
|
|
42
29
|
const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
|
|
43
30
|
if (unnamed.length > 0) {
|
|
44
31
|
throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
|
|
@@ -155,35 +142,12 @@ function isStated(schema, check) {
|
|
|
155
142
|
}
|
|
156
143
|
/** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
|
|
157
144
|
function statementOf(schema) {
|
|
158
|
-
const { id: _id, description: _description,
|
|
145
|
+
const { id: _id, description: _description, ...statement } = documentJsonSchema._map.get(schema) ?? {};
|
|
159
146
|
return Object.keys(statement).length > 0 ? statement : undefined;
|
|
160
147
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Zod renders an exclusive union by `oneOf`. The structure's `variants` are exclusive only for their
|
|
163
|
-
* diagnostics: they never overlap, so the document states them by `anyOf`, in place, as any union.
|
|
164
|
-
*/
|
|
165
|
-
function stateVariantsByAnyOf(value) {
|
|
166
|
-
if (Array.isArray(value)) {
|
|
167
|
-
for (const item of value)
|
|
168
|
-
stateVariantsByAnyOf(item);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (value === null || typeof value !== 'object')
|
|
172
|
-
return;
|
|
173
|
-
const schema = value;
|
|
174
|
-
if (schema[VARIANTS] !== undefined) {
|
|
175
|
-
const entries = Object.entries(schema).filter(([key]) => key !== VARIANTS);
|
|
176
|
-
for (const key of Object.keys(schema))
|
|
177
|
-
delete schema[key];
|
|
178
|
-
for (const [key, entry] of entries)
|
|
179
|
-
schema[key === 'oneOf' ? 'anyOf' : key] = entry;
|
|
180
|
-
}
|
|
181
|
-
for (const entry of Object.values(schema))
|
|
182
|
-
stateVariantsByAnyOf(entry);
|
|
183
|
-
}
|
|
184
148
|
/**
|
|
185
149
|
* Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
|
|
186
|
-
* removed
|
|
150
|
+
* removed.
|
|
187
151
|
*/
|
|
188
152
|
function rulePositions(document) {
|
|
189
153
|
const positions = new Map();
|
|
@@ -205,8 +169,6 @@ function rulePositions(document) {
|
|
|
205
169
|
}
|
|
206
170
|
delete schema['x-astrale-rule'];
|
|
207
171
|
}
|
|
208
|
-
if (typeof schema.maxLength === 'number')
|
|
209
|
-
note('length-in-utf16-code-units', pointer);
|
|
210
172
|
for (const [key, entry] of Object.entries(schema)) {
|
|
211
173
|
visit(entry, `${pointer}/${escapePointerToken(key)}`);
|
|
212
174
|
}
|
|
@@ -12,11 +12,8 @@ import type { DomainSchemaIR } from '../model/schema.js';
|
|
|
12
12
|
export type JsonSchemaAnnotation = zodCore.JSONSchema.JSONSchema & {
|
|
13
13
|
readonly id?: string;
|
|
14
14
|
readonly 'x-astrale-rule'?: StructureRule;
|
|
15
|
-
readonly [VARIANTS]?: true;
|
|
16
15
|
};
|
|
17
16
|
export declare const documentJsonSchema: zodCore.$ZodRegistry<JsonSchemaAnnotation, zodCore.$ZodType<unknown, unknown, zodCore.$ZodTypeInternals<unknown, unknown>>>;
|
|
18
|
-
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
19
|
-
export declare const VARIANTS = "x-astrale-variants";
|
|
20
17
|
/**
|
|
21
18
|
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
22
19
|
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
@@ -26,10 +23,6 @@ export declare const structureRules: {
|
|
|
26
23
|
readonly code: 'STRUCTURE_DUPLICATE_ITEM';
|
|
27
24
|
readonly statement: 'A unique tuple is a set of fields: two tuples naming the same fields in another order are one tuple, repeated.';
|
|
28
25
|
};
|
|
29
|
-
readonly 'length-in-utf16-code-units': {
|
|
30
|
-
readonly code: 'STRUCTURE_MAXIMUM';
|
|
31
|
-
readonly statement: 'A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.';
|
|
32
|
-
};
|
|
33
26
|
};
|
|
34
27
|
export type StructureRule = keyof typeof structureRules;
|
|
35
28
|
/** Only an authorized callable declares a policy: an anonymous or authenticated one has none. */
|
|
@@ -8,16 +8,17 @@ import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
|
8
8
|
import { SchemaError, diagnostic, } from '../diagnostic.js';
|
|
9
9
|
import { DOMAIN_FORMAT, DOMAIN_VERSION } from '../model/format.js';
|
|
10
10
|
export const documentJsonSchema = registry();
|
|
11
|
-
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
12
|
-
export const VARIANTS = 'x-astrale-variants';
|
|
13
11
|
/**
|
|
14
|
-
* A union of disjoint variants
|
|
15
|
-
* variant, from which `matchedVariant` decides what a refused value
|
|
16
|
-
*
|
|
12
|
+
* A union of disjoint variants, which JSON Schema states by `oneOf`. It is exclusive (`xor`) so that
|
|
13
|
+
* zod reports the issues of every variant, from which `matchedVariant` decides what a refused value
|
|
14
|
+
* reports: zod's own union reports its one variant that did not abort, and since zod 4.6 an
|
|
15
|
+
* oversized list aborts, so a value of the right shape would report `STRUCTURE_UNION` instead of its
|
|
16
|
+
* bound.
|
|
17
17
|
*/
|
|
18
|
-
function variants(options, annotation
|
|
18
|
+
function variants(options, annotation) {
|
|
19
19
|
const union = xor(options);
|
|
20
|
-
|
|
20
|
+
if (annotation !== undefined)
|
|
21
|
+
documentJsonSchema.add(union, annotation);
|
|
21
22
|
return union;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
@@ -29,14 +30,12 @@ export const structureRules = {
|
|
|
29
30
|
code: 'STRUCTURE_DUPLICATE_ITEM',
|
|
30
31
|
statement: 'A unique tuple is a set of fields: two tuples naming the same fields in another order are one tuple, repeated.',
|
|
31
32
|
},
|
|
32
|
-
'length-in-utf16-code-units': {
|
|
33
|
-
code: 'STRUCTURE_MAXIMUM',
|
|
34
|
-
statement: 'A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.',
|
|
35
|
-
},
|
|
36
33
|
};
|
|
37
34
|
// The pattern refuses `__proto__`, which zod skips before any key check (`lostProtoKeys`).
|
|
38
35
|
const RESERVED_DEPENDENCY_ALIASES = ['prototype', 'constructor'];
|
|
39
|
-
const originSchema =
|
|
36
|
+
const originSchema = string()
|
|
37
|
+
.min(3)
|
|
38
|
+
.max(253)
|
|
40
39
|
.regex(DOMAIN_ORIGIN_PATTERN)
|
|
41
40
|
.register(documentJsonSchema, { id: 'origin' });
|
|
42
41
|
const memberNameSchema = string()
|
|
@@ -58,15 +57,25 @@ const propertyKeySchema = string()
|
|
|
58
57
|
params: { structureCode: 'STRUCTURE_PROPERTY_KEY' },
|
|
59
58
|
})
|
|
60
59
|
.register(documentJsonSchema, { id: 'property-key', pattern: PROPERTY_KEY_PATTERN.source });
|
|
61
|
-
const coreSlugSchema =
|
|
60
|
+
const coreSlugSchema = string()
|
|
61
|
+
.min(1)
|
|
62
|
+
.max(100)
|
|
62
63
|
.regex(CORE_SLUG_PATTERN)
|
|
63
64
|
.register(documentJsonSchema, { id: 'core-slug' });
|
|
64
65
|
const revisionSchema = string()
|
|
65
66
|
.regex(DOMAIN_REVISION_PATTERN)
|
|
66
67
|
.register(documentJsonSchema, { id: 'revision' });
|
|
67
|
-
const descriptionSchema =
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const descriptionSchema = string()
|
|
69
|
+
.min(metadata.description.minLength)
|
|
70
|
+
.max(metadata.description.maxLength)
|
|
71
|
+
.register(documentJsonSchema, { id: 'description' });
|
|
72
|
+
const iconSchema = string()
|
|
73
|
+
.min(metadata.icon.minLength)
|
|
74
|
+
.max(metadata.icon.maxLength)
|
|
75
|
+
.register(documentJsonSchema, { id: 'icon' });
|
|
76
|
+
const domainNameSchema = string()
|
|
77
|
+
.min(metadata.name.minLength)
|
|
78
|
+
.max(metadata.name.maxLength)
|
|
70
79
|
.refine(metadata.isDomainNameText, {
|
|
71
80
|
message: 'Expected one trimmed line of text.',
|
|
72
81
|
params: { structureCode: 'STRUCTURE_DOMAIN_NAME' },
|
|
@@ -79,8 +88,8 @@ const domainNameSchema = boundedString(metadata.name.minLength, metadata.name.ma
|
|
|
79
88
|
// The shape of a Domain icon. Its UTF-8 bounds, its SVG grammar and that it draws at least one size
|
|
80
89
|
// are the rule DV_DOMAIN_ICON, which reads each text whole.
|
|
81
90
|
const domainIconArtSchema = strictObject({
|
|
82
|
-
svg:
|
|
83
|
-
dark:
|
|
91
|
+
svg: string().min(1),
|
|
92
|
+
dark: string().min(1).optional(),
|
|
84
93
|
}).register(documentJsonSchema, { id: 'domain-icon-art' });
|
|
85
94
|
const domainIconSchema = strictObject({
|
|
86
95
|
small: domainIconArtSchema.optional(),
|
|
@@ -110,7 +119,7 @@ const jsonSchemaSchema = variants([boolean(), jsonObjectSchema], {
|
|
|
110
119
|
id: 'value-schema',
|
|
111
120
|
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.',
|
|
112
121
|
});
|
|
113
|
-
const stateNameSchema =
|
|
122
|
+
const stateNameSchema = string().min(1);
|
|
114
123
|
// A custom check reads the relation in place: a record would copy it and drop a `__proto__` state.
|
|
115
124
|
const stateTransitionsSchema = custom(isStateTransitions, {
|
|
116
125
|
message: 'Expected each non-empty state to map non-empty events to non-empty states.',
|
|
@@ -608,44 +617,6 @@ function isRecord(input) {
|
|
|
608
617
|
function isObject(input) {
|
|
609
618
|
return input !== null && typeof input === 'object';
|
|
610
619
|
}
|
|
611
|
-
/**
|
|
612
|
-
* A string of `minimum` to `maximum` UTF-16 code units, the length the language measures, stated in
|
|
613
|
-
* JSON Schema as `minLength` and `maxLength` under the rule `length-in-utf16-code-units`. Zod's own
|
|
614
|
-
* string bounds count code points, which would admit twice the code units of the bound.
|
|
615
|
-
*/
|
|
616
|
-
function boundedString(minimum, maximum, id) {
|
|
617
|
-
return string()
|
|
618
|
-
.check((payload) => {
|
|
619
|
-
const length = payload.value.length;
|
|
620
|
-
if (length < minimum) {
|
|
621
|
-
payload.issues.push({
|
|
622
|
-
code: 'too_small',
|
|
623
|
-
origin: 'string',
|
|
624
|
-
minimum,
|
|
625
|
-
inclusive: true,
|
|
626
|
-
input: payload.value,
|
|
627
|
-
continue: true,
|
|
628
|
-
message: `Expected at least ${minimum} UTF-16 code units.`,
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
else if (maximum !== undefined && length > maximum) {
|
|
632
|
-
payload.issues.push({
|
|
633
|
-
code: 'too_big',
|
|
634
|
-
origin: 'string',
|
|
635
|
-
maximum,
|
|
636
|
-
inclusive: true,
|
|
637
|
-
input: payload.value,
|
|
638
|
-
continue: true,
|
|
639
|
-
message: `Expected at most ${maximum} UTF-16 code units.`,
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
})
|
|
643
|
-
.register(documentJsonSchema, {
|
|
644
|
-
...(id === undefined ? {} : { id }),
|
|
645
|
-
minLength: minimum,
|
|
646
|
-
...(maximum === undefined ? {} : { maxLength: maximum }),
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
620
|
/** At least one item, which `min(1)` proves: the output is typed as the non-empty tuple it is. */
|
|
650
621
|
function nonEmpty(list) {
|
|
651
622
|
return list.min(1);
|