@astrale-os/kernel-dsl 1.0.0-beta.21 → 1.0.0-beta.22

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.
@@ -35,6 +35,7 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
35
35
  path,
36
36
  zodSchema: source,
37
37
  });
38
+ keepLoweredShape(source, jsonSchema);
38
39
  }
39
40
  },
40
41
  });
@@ -62,6 +63,28 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
62
63
  diagnostics: [],
63
64
  };
64
65
  }
66
+ /**
67
+ * The lowering keeps one spelling per contract, whatever Zod version renders it, so that a Domain
68
+ * built from unchanged source keeps its schema digest. Every node lowers as its own Zod schema: a
69
+ * union by `anyOf`, an intersection by `allOf`, a tuple by its `prefixItems` and rest alone. Zod
70
+ * 4.6 compacts bare-type unions into a `type` array, folds object intersections, and closes tuples;
71
+ * the marker leaves no node bare, so the first two do not apply, and the tuple bounds are removed.
72
+ * `copyZodJson` drops the marker.
73
+ */
74
+ function keepLoweredShape(schema, jsonSchema) {
75
+ const def = getSchemaDefinition(schema);
76
+ if (def?.type === 'tuple' && Array.isArray(def.items)) {
77
+ if (jsonSchema.items === false)
78
+ delete jsonSchema.items;
79
+ if (jsonSchema.maxItems === def.items.length)
80
+ delete jsonSchema.maxItems;
81
+ if (typeof jsonSchema.minItems === 'number' && jsonSchema.minItems <= def.items.length) {
82
+ delete jsonSchema.minItems;
83
+ }
84
+ }
85
+ jsonSchema[LOWERED_NODE] = true;
86
+ }
87
+ const LOWERED_NODE = '~astrale-lowered-node';
65
88
  function copyZodJson(value) {
66
89
  if (value === null || ['boolean', 'number', 'string'].includes(typeof value))
67
90
  return value;
@@ -74,6 +97,8 @@ function copyZodJson(value) {
74
97
  for (const key of Reflect.ownKeys(value)) {
75
98
  if (typeof key === 'symbol')
76
99
  throw new TypeError('Zod emitted symbol-keyed schema metadata.');
100
+ if (key === LOWERED_NODE)
101
+ continue;
77
102
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
78
103
  if (descriptor === undefined)
79
104
  continue;
@@ -117,6 +142,11 @@ function inspectZodSchema(root, pointer, position) {
117
142
  if (def.coerce === true) {
118
143
  diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', schemaPointer, 'Zod coercion changes the accepted input domain and is not serializable as JSON Schema.'));
119
144
  }
145
+ if (type === 'record' && isZodType(def.keyType)) {
146
+ if (getSchemaDefinition(def.keyType)?.type === 'number') {
147
+ diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', `${schemaPointer}/propertyNames`, 'Zod number record keys accept the member names that spell a number, which V1 states by no portable pattern.'));
148
+ }
149
+ }
120
150
  inspectCheck(def, schemaPointer, diagnostics);
121
151
  if (Array.isArray(def.checks)) {
122
152
  def.checks.forEach((check, index) => {
@@ -2,7 +2,7 @@
2
2
  * Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
3
3
  * ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
4
4
  *
5
- * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26.7.0 in
5
+ * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
6
6
  * `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
7
7
  * its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
8
8
  * Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
@@ -2,7 +2,7 @@
2
2
  * Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
3
3
  * ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
4
4
  *
5
- * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26.7.0 in
5
+ * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
6
6
  * `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
7
7
  * its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
8
8
  * Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
@@ -572,9 +572,9 @@
572
572
  },
573
573
  "core-slug": {
574
574
  "type": "string",
575
+ "pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$",
575
576
  "minLength": 1,
576
- "maxLength": 100,
577
- "pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$"
577
+ "maxLength": 100
578
578
  },
579
579
  "create-policy": {
580
580
  "anyOf": [
@@ -1522,9 +1522,9 @@
1522
1522
  },
1523
1523
  "origin": {
1524
1524
  "type": "string",
1525
+ "pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$",
1525
1526
  "minLength": 3,
1526
- "maxLength": 253,
1527
- "pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"
1527
+ "maxLength": 253
1528
1528
  },
1529
1529
  "path-annotation": {
1530
1530
  "type": "object",
@@ -2183,6 +2183,7 @@
2183
2183
  "$ref": "#/$defs/incident-endpoint"
2184
2184
  }
2185
2185
  ],
2186
+ "items": false,
2186
2187
  "minItems": 2,
2187
2188
  "maxItems": 2
2188
2189
  },
@@ -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, } from './domain.structure.js';
5
+ import { domainSchemaStructure, documentJsonSchema, structureRules, VARIANTS, } 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. */
@@ -37,6 +37,8 @@ export function domainSchemaJsonSchema() {
37
37
  rendered.maxItems = def.items.length;
38
38
  },
39
39
  });
40
+ stateVariantsByAnyOf(root);
41
+ stateVariantsByAnyOf($defs);
40
42
  const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
41
43
  if (unnamed.length > 0) {
42
44
  throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
@@ -153,9 +155,32 @@ function isStated(schema, check) {
153
155
  }
154
156
  /** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
155
157
  function statementOf(schema) {
156
- const { id: _id, description: _description, ...statement } = documentJsonSchema._map.get(schema) ?? {};
158
+ const { id: _id, description: _description, [VARIANTS]: _variants, ...statement } = documentJsonSchema._map.get(schema) ?? {};
157
159
  return Object.keys(statement).length > 0 ? statement : undefined;
158
160
  }
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
+ }
159
184
  /**
160
185
  * Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
161
186
  * removed; every `maxLength` counts UTF-16 code units, the length the structure measures.
@@ -12,8 +12,11 @@ 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;
15
16
  };
16
17
  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";
17
20
  /**
18
21
  * The checks of the structure JSON Schema cannot state. The published document names each with the
19
22
  * positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
@@ -101,7 +104,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
101
104
  name: import("zod").ZodString;
102
105
  }, zodCore.$strict>>;
103
106
  properties: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
104
- schema: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
107
+ schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
105
108
  required: import("zod").ZodBoolean;
106
109
  auto: import("zod").ZodOptional<import("zod").ZodObject<{
107
110
  on: ZodType<["create" | "update", ...("create" | "update")[]], ["create" | "update", ...("create" | "update")[]], zodCore.$ZodTypeInternals<["create" | "update", ...("create" | "update")[]], ["create" | "update", ...("create" | "update")[]]>>;
@@ -119,13 +122,13 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
119
122
  }, zodCore.$strict>>;
120
123
  methods: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
121
124
  description: import("zod").ZodOptional<import("zod").ZodString>;
122
- input: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
125
+ input: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
123
126
  output: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
124
127
  mode: import("zod").ZodLiteral<"value">;
125
- schema: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
128
+ schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
126
129
  }, zodCore.$strict>, import("zod").ZodObject<{
127
130
  mode: import("zod").ZodLiteral<"stream">;
128
- item: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
131
+ item: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
129
132
  }, zodCore.$strict>, import("zod").ZodObject<{
130
133
  mode: import("zod").ZodLiteral<"binary">;
131
134
  }, zodCore.$strict>], "mode">;
@@ -140,11 +143,8 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
140
143
  authenticated: "authenticated";
141
144
  authorized: "authorized";
142
145
  }>;
143
- policy: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
146
+ policy: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
144
147
  kind: "self";
145
- } | {
146
- kind: "input";
147
- field: string;
148
148
  } | {
149
149
  kind: "ref";
150
150
  ref: {
@@ -176,11 +176,11 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
176
176
  kind: "view";
177
177
  name: string;
178
178
  };
179
- }>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
180
- kind: "self";
181
179
  } | {
182
180
  kind: "input";
183
181
  field: string;
182
+ }>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
183
+ kind: "self";
184
184
  } | {
185
185
  kind: "ref";
186
186
  ref: {
@@ -212,6 +212,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
212
212
  kind: "view";
213
213
  name: string;
214
214
  };
215
+ } | {
216
+ kind: "input";
217
+ field: string;
215
218
  }>, unknown>>]>>;
216
219
  static: import("zod").ZodBoolean;
217
220
  abstract: import("zod").ZodBoolean;
@@ -236,9 +239,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
236
239
  auth: "anonymous" | "authenticated" | "authorized";
237
240
  policy?: true | PolicyCheckExpression<PolicyRef, {
238
241
  kind: "self";
239
- } | {
240
- kind: "input";
241
- field: string;
242
242
  } | {
243
243
  kind: "ref";
244
244
  ref: {
@@ -270,6 +270,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
270
270
  kind: "view";
271
271
  name: string;
272
272
  };
273
+ } | {
274
+ kind: "input";
275
+ field: string;
273
276
  }> | undefined;
274
277
  static: boolean;
275
278
  abstract: boolean;
@@ -316,9 +319,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
316
319
  auth: "anonymous" | "authenticated" | "authorized";
317
320
  policy?: true | PolicyCheckExpression<PolicyRef, {
318
321
  kind: "self";
319
- } | {
320
- kind: "input";
321
- field: string;
322
322
  } | {
323
323
  kind: "ref";
324
324
  ref: {
@@ -350,6 +350,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
350
350
  kind: "view";
351
351
  name: string;
352
352
  };
353
+ } | {
354
+ kind: "input";
355
+ field: string;
353
356
  }> | undefined;
354
357
  static: boolean;
355
358
  abstract: boolean;
@@ -381,7 +384,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
381
384
  }, zodCore.$strict>>;
382
385
  icon: import("zod").ZodOptional<import("zod").ZodString>;
383
386
  policies: import("zod").ZodObject<{
384
- read: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
387
+ read: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
385
388
  origin: import("zod").ZodString;
386
389
  kind: import("zod").ZodLiteral<"policy">;
387
390
  name: import("zod").ZodString;
@@ -452,7 +455,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
452
455
  name: string;
453
456
  };
454
457
  }>, unknown>>]>>;
455
- traverse: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
458
+ traverse: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
456
459
  origin: import("zod").ZodString;
457
460
  kind: import("zod").ZodLiteral<"policy">;
458
461
  name: import("zod").ZodString;
@@ -523,7 +526,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
523
526
  name: string;
524
527
  };
525
528
  }>, unknown>>]>>;
526
- create: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
529
+ create: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
527
530
  kind: "ref";
528
531
  ref: {
529
532
  origin: string;
@@ -586,7 +589,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
586
589
  name: string;
587
590
  };
588
591
  }>, unknown>>]>>;
589
- update: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
592
+ update: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
590
593
  origin: import("zod").ZodString;
591
594
  kind: import("zod").ZodLiteral<"policy">;
592
595
  name: import("zod").ZodString;
@@ -657,7 +660,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
657
660
  name: string;
658
661
  };
659
662
  }>, unknown>>]>>;
660
- delete: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
663
+ delete: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
661
664
  origin: import("zod").ZodString;
662
665
  kind: import("zod").ZodLiteral<"policy">;
663
666
  name: import("zod").ZodString;
@@ -759,7 +762,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
759
762
  once: "once";
760
763
  }>>;
761
764
  description: import("zod").ZodOptional<import("zod").ZodString>;
762
- schema: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
765
+ schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
763
766
  }, zodCore.$strict>>;
764
767
  constraints: import("zod").ZodObject<{
765
768
  noSelf: import("zod").ZodOptional<import("zod").ZodLiteral<true>>;
@@ -802,7 +805,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
802
805
  directed: "directed";
803
806
  undirected: "undirected";
804
807
  }>;
805
- endpoints: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
808
+ endpoints: import("zod").ZodXor<readonly [import("zod").ZodObject<{
806
809
  source: import("zod").ZodObject<{
807
810
  role: import("zod").ZodString;
808
811
  accepts: ZodType<[{
@@ -987,7 +990,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
987
990
  }>;
988
991
  }, zodCore.$strict>], null>]>;
989
992
  policies: import("zod").ZodObject<{
990
- read: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
993
+ read: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
991
994
  origin: import("zod").ZodString;
992
995
  kind: import("zod").ZodLiteral<"policy">;
993
996
  name: import("zod").ZodString;
@@ -1058,7 +1061,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
1058
1061
  name: string;
1059
1062
  };
1060
1063
  }>, unknown>>]>>;
1061
- traverse: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
1064
+ traverse: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<false>, import("zod").ZodObject<{
1062
1065
  origin: import("zod").ZodString;
1063
1066
  kind: import("zod").ZodLiteral<"policy">;
1064
1067
  name: import("zod").ZodString;
@@ -1129,7 +1132,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
1129
1132
  name: string;
1130
1133
  };
1131
1134
  }>, unknown>>]>>;
1132
- create: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1135
+ create: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1133
1136
  origin: import("zod").ZodString;
1134
1137
  kind: import("zod").ZodLiteral<"policy">;
1135
1138
  name: import("zod").ZodString;
@@ -1200,7 +1203,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
1200
1203
  name: string;
1201
1204
  };
1202
1205
  }>, unknown>>]>>;
1203
- update: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1206
+ update: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1204
1207
  origin: import("zod").ZodString;
1205
1208
  kind: import("zod").ZodLiteral<"policy">;
1206
1209
  name: import("zod").ZodString;
@@ -1271,7 +1274,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
1271
1274
  name: string;
1272
1275
  };
1273
1276
  }>, unknown>>]>>;
1274
- delete: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1277
+ delete: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, import("zod").ZodObject<{
1275
1278
  origin: import("zod").ZodString;
1276
1279
  kind: import("zod").ZodLiteral<"policy">;
1277
1280
  name: import("zod").ZodString;
@@ -7310,10 +7313,10 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7310
7313
  description: import("zod").ZodOptional<import("zod").ZodString>;
7311
7314
  output: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
7312
7315
  mode: import("zod").ZodLiteral<"value">;
7313
- schema: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7316
+ schema: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7314
7317
  }, zodCore.$strict>, import("zod").ZodObject<{
7315
7318
  mode: import("zod").ZodLiteral<"stream">;
7316
- item: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7319
+ item: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7317
7320
  }, zodCore.$strict>, import("zod").ZodObject<{
7318
7321
  mode: import("zod").ZodLiteral<"binary">;
7319
7322
  }, zodCore.$strict>], "mode">;
@@ -7328,11 +7331,8 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7328
7331
  authenticated: "authenticated";
7329
7332
  authorized: "authorized";
7330
7333
  }>;
7331
- policy: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
7334
+ policy: import("zod").ZodOptional<import("zod").ZodXor<readonly [import("zod").ZodLiteral<true>, ZodType<PolicyCheckExpression<PolicyRef, {
7332
7335
  kind: "self";
7333
- } | {
7334
- kind: "input";
7335
- field: string;
7336
7336
  } | {
7337
7337
  kind: "ref";
7338
7338
  ref: {
@@ -7364,11 +7364,11 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7364
7364
  kind: "view";
7365
7365
  name: string;
7366
7366
  };
7367
- }>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
7368
- kind: "self";
7369
7367
  } | {
7370
7368
  kind: "input";
7371
7369
  field: string;
7370
+ }>, unknown, zodCore.$ZodTypeInternals<PolicyCheckExpression<PolicyRef, {
7371
+ kind: "self";
7372
7372
  } | {
7373
7373
  kind: "ref";
7374
7374
  ref: {
@@ -7400,12 +7400,15 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7400
7400
  kind: "view";
7401
7401
  name: string;
7402
7402
  };
7403
+ } | {
7404
+ kind: "input";
7405
+ field: string;
7403
7406
  }>, unknown>>]>>;
7404
- input: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
7407
+ input: import("zod").ZodXor<readonly [import("zod").ZodObject<{
7405
7408
  mode: import("zod").ZodLiteral<"binary">;
7406
- metadata: import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7409
+ metadata: import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>;
7407
7410
  maximumBytes: import("zod").ZodNumber;
7408
- }, zodCore.$strict>, import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>]>;
7411
+ }, zodCore.$strict>, import("zod").ZodXor<readonly [import("zod").ZodBoolean, import("zod").ZodRecord<import("zod").ZodString, ZodType<JsonValue, unknown, zodCore.$ZodTypeInternals<JsonValue, unknown>>>]>]>;
7409
7412
  ref: import("zod").ZodObject<{
7410
7413
  origin: import("zod").ZodString;
7411
7414
  kind: import("zod").ZodLiteral<"function">;
@@ -7431,9 +7434,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7431
7434
  auth: "anonymous" | "authenticated" | "authorized";
7432
7435
  policy?: true | PolicyCheckExpression<PolicyRef, {
7433
7436
  kind: "self";
7434
- } | {
7435
- kind: "input";
7436
- field: string;
7437
7437
  } | {
7438
7438
  kind: "ref";
7439
7439
  ref: {
@@ -7465,6 +7465,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7465
7465
  kind: "view";
7466
7466
  name: string;
7467
7467
  };
7468
+ } | {
7469
+ kind: "input";
7470
+ field: string;
7468
7471
  }> | undefined;
7469
7472
  input: boolean | Record<string, JsonValue> | {
7470
7473
  mode: "binary";
@@ -7525,9 +7528,6 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7525
7528
  auth: "anonymous" | "authenticated" | "authorized";
7526
7529
  policy?: true | PolicyCheckExpression<PolicyRef, {
7527
7530
  kind: "self";
7528
- } | {
7529
- kind: "input";
7530
- field: string;
7531
7531
  } | {
7532
7532
  kind: "ref";
7533
7533
  ref: {
@@ -7559,6 +7559,9 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7559
7559
  kind: "view";
7560
7560
  name: string;
7561
7561
  };
7562
+ } | {
7563
+ kind: "input";
7564
+ field: string;
7562
7565
  }> | undefined;
7563
7566
  input: boolean | Record<string, JsonValue> | {
7564
7567
  mode: "binary";
@@ -7606,7 +7609,7 @@ export declare const domainSchemaStructure: import("zod").ZodObject<{
7606
7609
  kind: import("zod").ZodLiteral<"policy">;
7607
7610
  name: import("zod").ZodString;
7608
7611
  }, zodCore.$strict>;
7609
- expression: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
7612
+ expression: import("zod").ZodXor<readonly [import("zod").ZodObject<{
7610
7613
  match: ZodType<PolicyPatternExpression, unknown, zodCore.$ZodTypeInternals<PolicyPatternExpression, unknown>>;
7611
7614
  }, zodCore.$strict>, import("zod").ZodObject<{
7612
7615
  allOf: ZodType<[{
@@ -1,4 +1,4 @@
1
- import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple, union, } from 'zod';
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 = string()
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 = string()
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 = string()
61
- .min(metadata.description.minLength)
62
- .max(metadata.description.maxLength)
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
- // Zod skips a `__proto__` member, which the structure therefore refuses (`lostProtoKeys`). The JSON
81
- // Schema refuses it by the fields of a closed object and the pattern of a record's names; a record
82
- // of any string states it here, by its property names.
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(() => union([
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 = union([boolean(), jsonObjectSchema]).register(documentJsonSchema, {
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 = string().min(1);
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 = union([
215
+ const edgeUniqueFieldSchema = variants([
214
216
  literal('source'),
215
217
  literal('target'),
216
218
  literal('slug'),
217
219
  strictObject({ property: propertyKeySchema }),
218
- ]).register(documentJsonSchema, { id: 'edge-unique-field' });
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 = union([
245
+ const policyVariableSchema = variants([
244
246
  strictObject({ variable: policyPatternVariableSchema, class: classRefSchema }),
245
247
  strictObject({ variable: policyPatternVariableSchema, selector: policyVariableSelectorSchema }),
246
- ]).register(documentJsonSchema, { id: 'policy-variable' });
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(() => union([
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(() => union([
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: union([literal(true), policyCheckExpressionSchema])
340
- .register(documentJsonSchema, { id: 'callable-policy' })
341
- .optional(),
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 = union([
360
- literal(false),
361
- policyRefSchema,
362
- classRuleChecksSchema,
363
- ]).register(documentJsonSchema, { id: 'observation-policy' });
364
- const writePolicySchema = union([literal(true), policyRefSchema, classRuleChecksSchema]).register(documentJsonSchema, { id: 'write-policy' });
365
- const createPolicySchema = union([literal(true), createRuleChecksSchema]).register(documentJsonSchema, { id: 'create-policy' });
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: union([directedEdgeEndpointsSchema, undirectedEdgeEndpointsSchema]),
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: union([binaryInputSchema, valueFunctionInputSchema]),
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 = union([
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 an
520
- * object or a record, so the structure would accept the document without it; it refuses the
521
- * document instead. A State's transitions are read in place and keep the member.
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) => diagnostic('STRUCTURE_UNKNOWN_FIELD', pointer([...issue.path, key]), `Unknown field ${JSON.stringify(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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-dsl",
3
- "version": "1.0.0-beta.21",
3
+ "version": "1.0.0-beta.22",
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.4.3"
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.6",
111
+ "re2js": "2.8.7",
112
112
  "typescript": "~6.0.3",
113
113
  "vitest": "^5.0.1",
114
114
  "yaml": "2.9.0"