schemair 0.1.0 → 0.2.0

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.
Files changed (69) hide show
  1. package/README.md +420 -11
  2. package/dist/authoring/index.cjs +13 -350
  3. package/dist/authoring/index.d.cts +2 -90
  4. package/dist/authoring/index.d.ts +2 -90
  5. package/dist/authoring/index.js +2 -304
  6. package/dist/authoring-D3V0iyTe.js +362 -0
  7. package/dist/authoring-Dnrg5TXm.cjs +389 -0
  8. package/dist/chunk-BgLxgFZR.js +18 -0
  9. package/dist/definition/index.cjs +10 -2
  10. package/dist/definition/index.d.cts +3 -21
  11. package/dist/definition/index.d.ts +3 -21
  12. package/dist/definition/index.js +2 -2
  13. package/dist/definition-BLLBpLKv.cjs +1187 -0
  14. package/dist/definition-DmYnDmQO.js +1115 -0
  15. package/dist/index-4aMF0cTE.d.ts +368 -0
  16. package/dist/index-BqfGAU1K.d.ts +56 -0
  17. package/dist/{index-eK2Xgrwp.d.ts → index-CBbd4hXJ.d.ts} +13 -2
  18. package/dist/index-CIim1dG7.d.cts +92 -0
  19. package/dist/{index-TACcK_mi.d.cts → index-CNjYUKvu.d.cts} +13 -2
  20. package/dist/index-CQynt7ft.d.cts +420 -0
  21. package/dist/index-D3mfwaSO.d.cts +56 -0
  22. package/dist/index-DDMwVy2I.d.cts +368 -0
  23. package/dist/index-DM5DSLLL.d.ts +99 -0
  24. package/dist/index-DXWoNYFB.d.ts +92 -0
  25. package/dist/index-DhmHCGpT.d.cts +99 -0
  26. package/dist/index-bQy-C-1l.d.ts +418 -0
  27. package/dist/index.cjs +64 -52
  28. package/dist/index.d.cts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.js +7 -5
  31. package/dist/integrations/json-schema/index.cjs +328 -0
  32. package/dist/integrations/json-schema/index.d.cts +53 -0
  33. package/dist/integrations/json-schema/index.d.ts +53 -0
  34. package/dist/integrations/json-schema/index.js +324 -0
  35. package/dist/integrations/standard-schema/index.cjs +32 -0
  36. package/dist/integrations/standard-schema/index.d.cts +22 -0
  37. package/dist/integrations/standard-schema/index.d.ts +22 -0
  38. package/dist/integrations/standard-schema/index.js +32 -0
  39. package/dist/payload/index.cjs +1 -1
  40. package/dist/payload/index.d.cts +1 -55
  41. package/dist/payload/index.d.ts +1 -55
  42. package/dist/payload/index.js +1 -1
  43. package/dist/relations/index.cjs +3 -1
  44. package/dist/relations/index.d.cts +2 -2
  45. package/dist/relations/index.d.ts +2 -2
  46. package/dist/relations/index.js +2 -2
  47. package/dist/{relations-CMz_0nf4.cjs → relations-Cymx4iTc.cjs} +158 -5
  48. package/dist/{relations-By0bK3UK.js → relations-ysXDmi-Z.js} +147 -6
  49. package/dist/spec/index.cjs +9 -0
  50. package/dist/spec/index.d.cts +2 -2
  51. package/dist/spec/index.d.ts +2 -2
  52. package/dist/spec/index.js +3 -1
  53. package/dist/standard/index.cjs +810 -0
  54. package/dist/standard/index.d.cts +3 -0
  55. package/dist/standard/index.d.ts +3 -0
  56. package/dist/standard/index.js +777 -0
  57. package/dist/standard-DhKsxu9U.js +471 -0
  58. package/dist/standard-etPFZDJI.cjs +513 -0
  59. package/dist/type-interpreter/index.cjs +3 -3
  60. package/dist/type-interpreter/index.d.cts +2 -99
  61. package/dist/type-interpreter/index.d.ts +2 -99
  62. package/dist/type-interpreter/index.js +2 -2
  63. package/dist/{type-interpreter-Ck0VDhzn.js → type-interpreter-DnrId8aM.js} +5 -284
  64. package/dist/{type-interpreter-DAIBUqKf.cjs → type-interpreter-OLt2W2yd.cjs} +15 -294
  65. package/package.json +38 -3
  66. package/dist/definition-BXj3T94L.js +0 -467
  67. package/dist/definition-DSZZTz4e.cjs +0 -473
  68. package/dist/index-CEzHfht2.d.ts +0 -269
  69. package/dist/index-rzkFjgrt.d.cts +0 -269
@@ -0,0 +1,1187 @@
1
+
2
+ //#region src/definition/validator.ts
3
+ const NODE_KINDS = new Set([
4
+ "primitive",
5
+ "literal",
6
+ "record",
7
+ "array",
8
+ "tuple",
9
+ "literalUnion",
10
+ "nullable",
11
+ "taggedUnion",
12
+ "ref",
13
+ "selfRef"
14
+ ]);
15
+ const PRIMITIVE_NAMES = new Set([
16
+ "string",
17
+ "number",
18
+ "boolean",
19
+ "null"
20
+ ]);
21
+ function isRecord$1(value) {
22
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
23
+ const prototype = Object.getPrototypeOf(value);
24
+ return prototype === Object.prototype || prototype === null;
25
+ }
26
+ function hasOwn(value, key) {
27
+ return Object.prototype.hasOwnProperty.call(value, key);
28
+ }
29
+ function ownKeys(value) {
30
+ return Reflect.ownKeys(value);
31
+ }
32
+ function hasAccessor(value) {
33
+ return ownKeys(value).some((key) => {
34
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
35
+ return descriptor !== void 0 && ("get" in descriptor || "set" in descriptor);
36
+ });
37
+ }
38
+ function isDenseArray(value) {
39
+ if (!Array.isArray(value)) return false;
40
+ for (const key of Reflect.ownKeys(value)) {
41
+ if (typeof key === "symbol") return false;
42
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
43
+ if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) return false;
44
+ if (key !== "length" && !/^(0|[1-9]\d*)$/.test(key)) return false;
45
+ }
46
+ for (let index = 0; index < value.length; index += 1) if (!hasOwn(value, String(index))) return false;
47
+ return true;
48
+ }
49
+ function isFiniteNumber(value) {
50
+ return typeof value === "number" && Number.isFinite(value);
51
+ }
52
+ function isLiteral(value) {
53
+ return typeof value === "string" || typeof value === "boolean" || isFiniteNumber(value);
54
+ }
55
+ function scalarDomain(value) {
56
+ if (typeof value === "string") return "string";
57
+ if (typeof value === "boolean") return "boolean";
58
+ return "number";
59
+ }
60
+ function equalLiteral(left, right) {
61
+ return typeof left === typeof right && Object.is(left, right) || left === right;
62
+ }
63
+ function describe(value) {
64
+ if (value === null) return "null";
65
+ if (Array.isArray(value)) return "array";
66
+ return typeof value;
67
+ }
68
+ var DefinitionValidator = class {
69
+ issues = [];
70
+ active = /* @__PURE__ */ new WeakSet();
71
+ validateRoot(value) {
72
+ if (this.validateNode(value, [], true)) return {
73
+ ok: true,
74
+ node: value,
75
+ issues: []
76
+ };
77
+ return {
78
+ ok: false,
79
+ issues: this.issues
80
+ };
81
+ }
82
+ issue(code, path, message) {
83
+ this.issues.push({
84
+ code,
85
+ path,
86
+ message
87
+ });
88
+ }
89
+ checkObject(value, path, label) {
90
+ if (!isRecord$1(value)) {
91
+ this.issue("schema.object.invalid", path, `${label} must be a plain object`);
92
+ return false;
93
+ }
94
+ if (hasAccessor(value)) {
95
+ this.issue("schema.object.accessor", path, `${label} must not contain accessor properties`);
96
+ return false;
97
+ }
98
+ if (ownKeys(value).some((key) => typeof key === "symbol")) {
99
+ this.issue("schema.object.symbol-key", path, `${label} must not contain symbol keys`);
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ checkFields(value, allowed, required, path) {
105
+ let valid = true;
106
+ for (const key of Object.getOwnPropertyNames(value)) if (!allowed.includes(key)) {
107
+ this.issue("schema.field.unknown", [...path, key], `unknown field '${key}'`);
108
+ valid = false;
109
+ }
110
+ for (const key of required) if (!hasOwn(value, key)) {
111
+ this.issue("schema.field.missing", [...path, key], `missing required field '${key}'`);
112
+ valid = false;
113
+ }
114
+ return valid;
115
+ }
116
+ enter(value, path) {
117
+ if (this.active.has(value)) {
118
+ this.issue("schema.cycle", path, "actual object cycles are not valid schema data");
119
+ return false;
120
+ }
121
+ this.active.add(value);
122
+ return true;
123
+ }
124
+ leave(value) {
125
+ this.active.delete(value);
126
+ }
127
+ validateNode(value, path, root) {
128
+ if (!this.checkObject(value, path, "schema node")) return false;
129
+ if (!this.enter(value, path)) return false;
130
+ let valid = true;
131
+ const kind = value.kind;
132
+ if (typeof kind !== "string" || !NODE_KINDS.has(kind)) {
133
+ this.issue("schema.kind.invalid", [...path, "kind"], `unsupported schema kind '${String(kind)}'`);
134
+ valid = false;
135
+ } else switch (kind) {
136
+ case "primitive":
137
+ valid = this.validatePrimitive(value, path);
138
+ break;
139
+ case "literal":
140
+ valid = this.validateLiteral(value, path);
141
+ break;
142
+ case "record":
143
+ valid = this.validateRecord(value, path);
144
+ break;
145
+ case "array":
146
+ valid = this.validateArray(value, path);
147
+ break;
148
+ case "tuple":
149
+ valid = this.validateTuple(value, path);
150
+ break;
151
+ case "literalUnion":
152
+ valid = this.validateLiteralUnion(value, path);
153
+ break;
154
+ case "nullable":
155
+ valid = this.validateNullable(value, path);
156
+ break;
157
+ case "taggedUnion":
158
+ valid = this.validateTaggedUnion(value, path);
159
+ break;
160
+ case "ref":
161
+ valid = this.validateRef(value, path);
162
+ break;
163
+ case "selfRef":
164
+ valid = this.checkFields(value, ["kind"], [], path);
165
+ if (root) {
166
+ this.issue("schema.selfRef.root", path, "a root schema cannot consist only of selfRef");
167
+ valid = false;
168
+ }
169
+ break;
170
+ default: valid = false;
171
+ }
172
+ this.leave(value);
173
+ return valid;
174
+ }
175
+ validatePrimitive(value, path) {
176
+ let valid = this.checkFields(value, [
177
+ "kind",
178
+ "name",
179
+ "semanticPath",
180
+ "constraints"
181
+ ], ["name"], path);
182
+ const name = value.name;
183
+ if (typeof name !== "string" || !PRIMITIVE_NAMES.has(name)) {
184
+ this.issue("schema.primitive.name", [...path, "name"], `primitive name must be one of string, number, boolean, or null`);
185
+ return false;
186
+ }
187
+ if (!(name === "string" || name === "number") && (hasOwn(value, "semanticPath") || hasOwn(value, "constraints"))) {
188
+ this.issue("schema.primitive.metadata", path, "semanticPath and constraints are only supported on string and number primitives");
189
+ valid = false;
190
+ }
191
+ if (hasOwn(value, "semanticPath")) valid = this.validatePath(value.semanticPath, [...path, "semanticPath"], "semanticPath") && valid;
192
+ if (hasOwn(value, "constraints")) valid = this.validateConstraints(value.constraints, [...path, "constraints"], "constraints") && valid;
193
+ return valid;
194
+ }
195
+ validateLiteral(value, path) {
196
+ let valid = this.checkFields(value, ["kind", "literal"], ["literal"], path);
197
+ if (!isLiteral(value.literal)) {
198
+ this.issue("schema.literal.value", [...path, "literal"], "literal must be a finite string, number, or boolean");
199
+ valid = false;
200
+ }
201
+ return valid;
202
+ }
203
+ validateRecord(value, path) {
204
+ let valid = this.checkFields(value, [
205
+ "kind",
206
+ "fields",
207
+ "additionalFields",
208
+ "constraints"
209
+ ], ["fields"], path);
210
+ if (!isDenseArray(value.fields)) {
211
+ this.issue("schema.record.fields", [...path, "fields"], "fields must be a dense array");
212
+ return false;
213
+ }
214
+ const keys$1 = /* @__PURE__ */ new Set();
215
+ value.fields.forEach((field, index) => {
216
+ const fieldPath = [
217
+ ...path,
218
+ "fields",
219
+ index
220
+ ];
221
+ if (!this.checkObject(field, fieldPath, "record field")) {
222
+ valid = false;
223
+ return;
224
+ }
225
+ valid = this.checkFields(field, [
226
+ "key",
227
+ "schema",
228
+ "required",
229
+ "description"
230
+ ], ["key", "schema"], fieldPath) && valid;
231
+ if (typeof field.key !== "string") {
232
+ this.issue("schema.record.field-key", [...fieldPath, "key"], "record field key must be a string");
233
+ valid = false;
234
+ } else if (keys$1.has(field.key)) {
235
+ this.issue("schema.record.field-key.duplicate", [...fieldPath, "key"], `duplicate record field key '${field.key}'`);
236
+ valid = false;
237
+ } else keys$1.add(field.key);
238
+ if (hasOwn(field, "required") && typeof field.required !== "boolean") {
239
+ this.issue("schema.record.required", [...fieldPath, "required"], "required must be a boolean");
240
+ valid = false;
241
+ }
242
+ if (hasOwn(field, "description") && typeof field.description !== "string") {
243
+ this.issue("schema.record.description", [...fieldPath, "description"], "description must be a string");
244
+ valid = false;
245
+ }
246
+ valid = this.validateNode(field.schema, [...fieldPath, "schema"], false) && valid;
247
+ });
248
+ if (hasOwn(value, "additionalFields")) {
249
+ if (value.additionalFields !== true) valid = this.validateNode(value.additionalFields, [...path, "additionalFields"], false) && valid;
250
+ }
251
+ if (hasOwn(value, "constraints")) valid = this.validateConstraints(value.constraints, [...path, "constraints"], "constraints") && valid;
252
+ return valid;
253
+ }
254
+ validateArray(value, path) {
255
+ let valid = this.checkFields(value, [
256
+ "kind",
257
+ "elementSchema",
258
+ "constraints"
259
+ ], ["elementSchema"], path);
260
+ valid = this.validateNode(value.elementSchema, [...path, "elementSchema"], false) && valid;
261
+ if (hasOwn(value, "constraints")) valid = this.validateConstraints(value.constraints, [...path, "constraints"], "constraints") && valid;
262
+ return valid;
263
+ }
264
+ validateTuple(value, path) {
265
+ let valid = this.checkFields(value, ["kind", "elementSchemas"], ["elementSchemas"], path);
266
+ if (!isDenseArray(value.elementSchemas)) {
267
+ this.issue("schema.tuple.elements", [...path, "elementSchemas"], "elementSchemas must be a dense array");
268
+ return false;
269
+ }
270
+ value.elementSchemas.forEach((child, index) => {
271
+ valid = this.validateNode(child, [
272
+ ...path,
273
+ "elementSchemas",
274
+ index
275
+ ], false) && valid;
276
+ });
277
+ return valid;
278
+ }
279
+ validateLiteralUnion(value, path) {
280
+ let valid = this.checkFields(value, ["kind", "values"], ["values"], path);
281
+ if (!isDenseArray(value.values)) {
282
+ this.issue("schema.literalUnion.values", [...path, "values"], "values must be a dense array");
283
+ return false;
284
+ }
285
+ if (value.values.length < 2) {
286
+ this.issue("schema.literalUnion.cardinality", [...path, "values"], "literalUnion requires at least two values");
287
+ valid = false;
288
+ }
289
+ let domain;
290
+ const literals = [];
291
+ value.values.forEach((candidate, index) => {
292
+ const candidatePath = [
293
+ ...path,
294
+ "values",
295
+ index
296
+ ];
297
+ if (!isLiteral(candidate)) {
298
+ this.issue("schema.literalUnion.value", candidatePath, "literalUnion values must be finite strings, numbers, or booleans");
299
+ valid = false;
300
+ return;
301
+ }
302
+ const candidateDomain = scalarDomain(candidate);
303
+ if (domain === void 0) domain = candidateDomain;
304
+ else if (domain !== candidateDomain) {
305
+ this.issue("schema.literalUnion.domain", candidatePath, "literalUnion values must share one scalar domain");
306
+ valid = false;
307
+ }
308
+ if (literals.some((existing) => equalLiteral(existing, candidate))) {
309
+ this.issue("schema.literalUnion.duplicate", candidatePath, "literalUnion values must be unique");
310
+ valid = false;
311
+ }
312
+ literals.push(candidate);
313
+ });
314
+ return valid;
315
+ }
316
+ validateNullable(value, path) {
317
+ let valid = this.checkFields(value, ["kind", "value"], ["value"], path);
318
+ valid = this.validateNode(value.value, [...path, "value"], false) && valid;
319
+ if (isRecord$1(value.value) && (value.value.kind === "nullable" || value.value.kind === "primitive" && value.value.name === "null")) {
320
+ this.issue("schema.nullable.redundant", [...path, "value"], "nullable cannot wrap null or another nullable node");
321
+ valid = false;
322
+ }
323
+ return valid;
324
+ }
325
+ validateTaggedUnion(value, path) {
326
+ let valid = this.checkFields(value, [
327
+ "kind",
328
+ "discriminator",
329
+ "variants"
330
+ ], ["discriminator", "variants"], path);
331
+ if (typeof value.discriminator !== "string") {
332
+ this.issue("schema.taggedUnion.discriminator", [...path, "discriminator"], "discriminator must be a string");
333
+ valid = false;
334
+ }
335
+ if (!isDenseArray(value.variants)) {
336
+ this.issue("schema.taggedUnion.variants", [...path, "variants"], "variants must be a dense array");
337
+ return false;
338
+ }
339
+ if (value.variants.length < 2) {
340
+ this.issue("schema.taggedUnion.cardinality", [...path, "variants"], "taggedUnion requires at least two variants");
341
+ valid = false;
342
+ }
343
+ const variantKeys = /* @__PURE__ */ new Set();
344
+ const tags = /* @__PURE__ */ new Set();
345
+ value.variants.forEach((variant, index) => {
346
+ const variantPath = [
347
+ ...path,
348
+ "variants",
349
+ index
350
+ ];
351
+ if (!this.checkObject(variant, variantPath, "tagged-union variant")) {
352
+ valid = false;
353
+ return;
354
+ }
355
+ valid = this.checkFields(variant, [
356
+ "key",
357
+ "schema",
358
+ "description"
359
+ ], ["key", "schema"], variantPath) && valid;
360
+ if (typeof variant.key !== "string" || variant.key.trim() === "") {
361
+ this.issue("schema.taggedUnion.variant-key", [...variantPath, "key"], "variant key must be a non-blank string");
362
+ valid = false;
363
+ } else if (variantKeys.has(variant.key)) {
364
+ this.issue("schema.taggedUnion.variant-key.duplicate", [...variantPath, "key"], `duplicate variant key '${variant.key}'`);
365
+ valid = false;
366
+ } else variantKeys.add(variant.key);
367
+ if (hasOwn(variant, "description") && typeof variant.description !== "string") {
368
+ this.issue("schema.taggedUnion.description", [...variantPath, "description"], "description must be a string");
369
+ valid = false;
370
+ }
371
+ valid = this.validateNode(variant.schema, [...variantPath, "schema"], false) && valid;
372
+ if (!isRecord$1(variant.schema) || variant.schema.kind !== "record") {
373
+ this.issue("schema.taggedUnion.variant-schema", [...variantPath, "schema"], "tagged-union variants must be direct record schemas");
374
+ valid = false;
375
+ return;
376
+ }
377
+ const field = (isDenseArray(variant.schema.fields) ? variant.schema.fields : []).find((candidate) => isRecord$1(candidate) && candidate.key === value.discriminator);
378
+ if (!field || field.required !== true || !isRecord$1(field.schema) || field.schema.kind !== "literal" || typeof field.schema.literal !== "string") {
379
+ this.issue("schema.taggedUnion.discriminator-field", [
380
+ ...variantPath,
381
+ "schema",
382
+ "fields"
383
+ ], "each variant must have a required string-literal discriminator field");
384
+ valid = false;
385
+ } else if (tags.has(field.schema.literal)) {
386
+ this.issue("schema.taggedUnion.discriminator-duplicate", [
387
+ ...variantPath,
388
+ "schema",
389
+ "fields"
390
+ ], "discriminator literal tags must be unique");
391
+ valid = false;
392
+ } else tags.add(field.schema.literal);
393
+ });
394
+ return valid;
395
+ }
396
+ validateRef(value, path) {
397
+ let valid = this.checkFields(value, ["kind", "refPath"], ["refPath"], path);
398
+ valid = this.validatePath(value.refPath, [...path, "refPath"], "refPath") && valid;
399
+ return valid;
400
+ }
401
+ validatePath(value, path, label) {
402
+ if (!isDenseArray(value) || value.length === 0 || value.some((segment) => typeof segment !== "string" || segment.trim() === "")) {
403
+ this.issue("schema.path.invalid", path, `${label} must be a non-empty dense array of non-blank strings`);
404
+ return false;
405
+ }
406
+ return true;
407
+ }
408
+ validateConstraints(value, path, label) {
409
+ if (!isDenseArray(value)) {
410
+ this.issue("schema.constraints.invalid", path, `${label} must be a dense array`);
411
+ return false;
412
+ }
413
+ let valid = true;
414
+ value.forEach((constraint, index) => {
415
+ const constraintPath = [...path, index];
416
+ if (!this.checkObject(constraint, constraintPath, "constraint")) {
417
+ valid = false;
418
+ return;
419
+ }
420
+ valid = this.checkFields(constraint, ["constraintPath", "args"], ["constraintPath"], constraintPath) && valid;
421
+ valid = this.validatePath(constraint.constraintPath, [...constraintPath, "constraintPath"], "constraintPath") && valid;
422
+ if (hasOwn(constraint, "args")) valid = this.validateJsonValue(constraint.args, [...constraintPath, "args"], /* @__PURE__ */ new WeakSet()) && valid;
423
+ });
424
+ return valid;
425
+ }
426
+ validateJsonValue(value, path, active) {
427
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
428
+ if (typeof value === "number") {
429
+ if (Number.isFinite(value)) return true;
430
+ this.issue("schema.json-value.number", path, "JSON numbers must be finite");
431
+ return false;
432
+ }
433
+ if (typeof value !== "object") {
434
+ this.issue("schema.json-value.type", path, `value of type ${describe(value)} is not JSON-compatible`);
435
+ return false;
436
+ }
437
+ if (active.has(value)) {
438
+ this.issue("schema.json-value.cycle", path, "actual object cycles are not JSON-compatible");
439
+ return false;
440
+ }
441
+ if (Array.isArray(value)) {
442
+ if (!isDenseArray(value)) {
443
+ this.issue("schema.json-value.array", path, "JSON arrays must be dense and have no symbol keys");
444
+ return false;
445
+ }
446
+ active.add(value);
447
+ let valid$1 = true;
448
+ value.forEach((child, index) => {
449
+ valid$1 = this.validateJsonValue(child, [...path, index], active) && valid$1;
450
+ });
451
+ active.delete(value);
452
+ return valid$1;
453
+ }
454
+ if (!this.checkObject(value, path, "JSON object")) return false;
455
+ active.add(value);
456
+ let valid = true;
457
+ for (const key of Object.keys(value)) valid = this.validateJsonValue(value[key], [...path, key], active) && valid;
458
+ active.delete(value);
459
+ return valid;
460
+ }
461
+ };
462
+ /** Validate only the serializable structural definition of one SchemaNode. */
463
+ function validateSchemaNodeDefinition(value) {
464
+ return new DefinitionValidator().validateRoot(value);
465
+ }
466
+
467
+ //#endregion
468
+ //#region src/definition/operation-validator.ts
469
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
470
+ const own$1 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
471
+ const keys = (value) => Object.getOwnPropertyNames(value);
472
+ const MAX_OPERATION_DEFINITION_STEPS = 1e4;
473
+ const MAX_OPERATION_DEFINITION_DEPTH = 64;
474
+ var Validator$1 = class {
475
+ issues = [];
476
+ active = /* @__PURE__ */ new WeakSet();
477
+ steps = 0;
478
+ budgetExceeded = false;
479
+ issue(code, path, message) {
480
+ this.issues.push({
481
+ code,
482
+ path,
483
+ message
484
+ });
485
+ }
486
+ object(value, path, label) {
487
+ if (++this.steps > MAX_OPERATION_DEFINITION_STEPS) {
488
+ if (!this.budgetExceeded) {
489
+ this.issue("operation.budget", path, "operation definition validation budget exceeded");
490
+ this.budgetExceeded = true;
491
+ }
492
+ return false;
493
+ }
494
+ if (!isRecord(value)) {
495
+ this.issue("operation.object.invalid", path, `${label} must be a plain object`);
496
+ return false;
497
+ }
498
+ const prototype = Object.getPrototypeOf(value);
499
+ if (prototype !== null && prototype !== Object.prototype || Reflect.ownKeys(value).some((key) => typeof key === "symbol" || !("value" in Object.getOwnPropertyDescriptor(value, key)) || !Object.getOwnPropertyDescriptor(value, key).enumerable)) {
500
+ this.issue("operation.object.invalid", path, `${label} must contain only enumerable own data properties on a plain object`);
501
+ return false;
502
+ }
503
+ return true;
504
+ }
505
+ fields(value, allowed, path) {
506
+ let valid = true;
507
+ for (const key of keys(value)) if (!allowed.includes(key)) {
508
+ this.issue("operation.field.unknown", [...path, key], `unknown field '${key}'`);
509
+ valid = false;
510
+ }
511
+ return valid;
512
+ }
513
+ enter(value, path) {
514
+ if (this.active.has(value)) {
515
+ this.issue("operation.cycle", path, "operation declarations must be acyclic");
516
+ return false;
517
+ }
518
+ this.active.add(value);
519
+ return true;
520
+ }
521
+ leave(value) {
522
+ this.active.delete(value);
523
+ }
524
+ description(value, path) {
525
+ if (!own$1(value, "description")) return true;
526
+ if (typeof value.description !== "string" || value.description.length === 0) {
527
+ this.issue("operation.description.invalid", [...path, "description"], "description must be a non-empty string");
528
+ return false;
529
+ }
530
+ return true;
531
+ }
532
+ nameMap(value, path, label, child) {
533
+ if (!this.object(value, path, label)) return false;
534
+ let valid = true;
535
+ for (const [name, item] of keys(value).map((name$1) => [name$1, value[name$1]])) {
536
+ if (name.length === 0) {
537
+ this.issue("operation.name.invalid", [...path, name], `${label} names must be non-empty`);
538
+ valid = false;
539
+ }
540
+ valid = child(item, [...path, name]) && valid;
541
+ }
542
+ return valid;
543
+ }
544
+ schema(value, path) {
545
+ const result = validateSchemaNodeDefinition(value);
546
+ if (result.ok) return true;
547
+ for (const issue of result.issues) this.issues.push({
548
+ ...issue,
549
+ path: [...path, ...issue.path]
550
+ });
551
+ return false;
552
+ }
553
+ payload(value, path, structured) {
554
+ if (!this.object(value, path, "payload")) return false;
555
+ let valid = this.fields(value, value.kind === "structured" ? ["kind", "schema"] : ["kind", "meta"], path);
556
+ if (value.kind === "structured") {
557
+ if (!own$1(value, "schema")) {
558
+ this.issue("operation.payload.schema.missing", [...path, "schema"], "structured payload requires schema");
559
+ return false;
560
+ }
561
+ valid = this.schema(value.schema, [...path, "schema"]) && valid;
562
+ } else if (value.kind === "binary" && !structured) {
563
+ if (own$1(value, "meta")) if (!this.object(value.meta, [...path, "meta"], "binary metadata")) valid = false;
564
+ else {
565
+ valid = this.fields(value.meta, ["kind", "value"], [...path, "meta"]) && valid;
566
+ if (value.meta.kind !== "mime" || typeof value.meta.value !== "string" || value.meta.value.length === 0) {
567
+ this.issue("operation.payload.meta.invalid", [...path, "meta"], "binary metadata must be a non-empty mime descriptor");
568
+ valid = false;
569
+ }
570
+ }
571
+ } else {
572
+ this.issue("operation.payload.kind.invalid", [...path, "kind"], structured ? "structured payload kind must be structured" : "payload kind must be structured or binary");
573
+ valid = false;
574
+ }
575
+ return valid;
576
+ }
577
+ error(value, path) {
578
+ if (!this.object(value, path, "error")) return false;
579
+ let valid = this.fields(value, ["description", "data"], path) && this.description(value, path);
580
+ if (own$1(value, "data")) valid = this.schema(value.data, [...path, "data"]) && valid;
581
+ return valid;
582
+ }
583
+ errors(value, path) {
584
+ return this.nameMap(value, path, "error", (item, childPath) => this.error(item, childPath));
585
+ }
586
+ channel(value, path, structured) {
587
+ if (!this.object(value, path, "channel")) return false;
588
+ let valid = this.fields(value, [
589
+ "description",
590
+ "data",
591
+ "errors"
592
+ ], path) && this.description(value, path);
593
+ if (own$1(value, "data")) valid = this.payload(value.data, [...path, "data"], structured) && valid;
594
+ if (own$1(value, "errors")) valid = this.errors(value.errors, [...path, "errors"]) && valid;
595
+ return valid;
596
+ }
597
+ operation(value, path, structured = false) {
598
+ if (!this.object(value, path, "operation") || !this.enter(value, path)) return false;
599
+ let valid = this.fields(value, [
600
+ "description",
601
+ "input",
602
+ "output",
603
+ "errors",
604
+ "emits"
605
+ ], path) && this.description(value, path);
606
+ if (own$1(value, "input")) valid = this.payload(value.input, [...path, "input"], structured) && valid;
607
+ if (own$1(value, "output")) valid = this.payload(value.output, [...path, "output"], structured) && valid;
608
+ if (own$1(value, "errors")) valid = this.errors(value.errors, [...path, "errors"]) && valid;
609
+ if (own$1(value, "emits")) valid = this.nameMap(value.emits, [...path, "emits"], "channel", (item, childPath) => this.channel(item, childPath, structured)) && valid;
610
+ this.leave(value);
611
+ return valid;
612
+ }
613
+ container(value, path, structured = false) {
614
+ if (path.length > MAX_OPERATION_DEFINITION_DEPTH) {
615
+ this.issue("operation.depth", path, "operation declaration nesting depth exceeded");
616
+ return false;
617
+ }
618
+ if (!this.object(value, path, "container") || !this.enter(value, path)) return false;
619
+ let valid = this.fields(value, [
620
+ "description",
621
+ "operations",
622
+ "containers"
623
+ ], path) && this.description(value, path);
624
+ const operationNames = isRecord(value.operations) ? new Set(Object.getOwnPropertyNames(value.operations)) : /* @__PURE__ */ new Set();
625
+ const containerNames = isRecord(value.containers) ? new Set(Object.getOwnPropertyNames(value.containers)) : /* @__PURE__ */ new Set();
626
+ for (const name of operationNames) if (containerNames.has(name)) {
627
+ this.issue("operation.container.name-collision", [...path, name], "operation and container names must be disjoint");
628
+ valid = false;
629
+ }
630
+ if (own$1(value, "operations")) valid = this.nameMap(value.operations, [...path, "operations"], "operation", (item, childPath) => this.operation(item, childPath, structured)) && valid;
631
+ if (own$1(value, "containers")) valid = this.nameMap(value.containers, [...path, "containers"], "container", (item, childPath) => this.container(item, childPath, structured)) && valid;
632
+ this.leave(value);
633
+ return valid;
634
+ }
635
+ };
636
+ function validateOperationDefinition(value) {
637
+ const validator = new Validator$1();
638
+ return validator.operation(value, []) ? {
639
+ ok: true,
640
+ operation: value,
641
+ issues: []
642
+ } : {
643
+ ok: false,
644
+ issues: validator.issues
645
+ };
646
+ }
647
+ function validateOperationContainerDefinition(value) {
648
+ const validator = new Validator$1();
649
+ return validator.container(value, []) ? {
650
+ ok: true,
651
+ container: value,
652
+ issues: []
653
+ } : {
654
+ ok: false,
655
+ issues: validator.issues
656
+ };
657
+ }
658
+ function validateStructuredOperationDefinition(value) {
659
+ const validator = new Validator$1();
660
+ return validator.operation(value, [], true) ? {
661
+ ok: true,
662
+ operation: value,
663
+ issues: []
664
+ } : {
665
+ ok: false,
666
+ issues: validator.issues
667
+ };
668
+ }
669
+ function validateStructuredOperationContainerDefinition(value) {
670
+ const validator = new Validator$1();
671
+ return validator.container(value, [], true) ? {
672
+ ok: true,
673
+ container: value,
674
+ issues: []
675
+ } : {
676
+ ok: false,
677
+ issues: validator.issues
678
+ };
679
+ }
680
+ function isStructuredOperationDefinition(value) {
681
+ return validateStructuredOperationDefinition(value).ok;
682
+ }
683
+ function isStructuredOperationContainerDefinition(value) {
684
+ return validateStructuredOperationContainerDefinition(value).ok;
685
+ }
686
+
687
+ //#endregion
688
+ //#region src/definition/expression-shape.ts
689
+ const expressionKinds = new Set([
690
+ "typeVar",
691
+ "opaqueHostType",
692
+ "absent",
693
+ "never",
694
+ "unknown",
695
+ "maybeAbsent",
696
+ "arrayOf",
697
+ "tupleOf",
698
+ "recordOf",
699
+ "elementOf",
700
+ "valueOf",
701
+ "elementAt",
702
+ "fieldOf",
703
+ "keyOf",
704
+ "fieldsOf",
705
+ "pickFields",
706
+ "omitFields",
707
+ "partialFields",
708
+ "requiredFields",
709
+ "mergeRecords",
710
+ "nullableOf",
711
+ "taggedUnionOf",
712
+ "intersect",
713
+ "refine",
714
+ "excludeVariants",
715
+ "extractVariants"
716
+ ]);
717
+ const expressionFields = {
718
+ typeVar: {
719
+ required: ["name"],
720
+ allowed: [
721
+ "kind",
722
+ "name",
723
+ "extends"
724
+ ]
725
+ },
726
+ opaqueHostType: {
727
+ required: ["hostPath"],
728
+ allowed: ["kind", "hostPath"]
729
+ },
730
+ absent: {
731
+ required: [],
732
+ allowed: ["kind"]
733
+ },
734
+ never: {
735
+ required: [],
736
+ allowed: ["kind"]
737
+ },
738
+ unknown: {
739
+ required: [],
740
+ allowed: ["kind"]
741
+ },
742
+ maybeAbsent: {
743
+ required: ["value"],
744
+ allowed: ["kind", "value"]
745
+ },
746
+ arrayOf: {
747
+ required: ["element"],
748
+ allowed: [
749
+ "kind",
750
+ "element",
751
+ "constraints"
752
+ ]
753
+ },
754
+ tupleOf: {
755
+ required: ["elements"],
756
+ allowed: ["kind", "elements"]
757
+ },
758
+ recordOf: {
759
+ required: ["fields"],
760
+ allowed: [
761
+ "kind",
762
+ "fields",
763
+ "additionalFields",
764
+ "constraints"
765
+ ]
766
+ },
767
+ nullableOf: {
768
+ required: ["value"],
769
+ allowed: ["kind", "value"]
770
+ },
771
+ taggedUnionOf: {
772
+ required: ["discriminator", "variants"],
773
+ allowed: [
774
+ "kind",
775
+ "discriminator",
776
+ "variants"
777
+ ]
778
+ },
779
+ elementOf: {
780
+ required: ["source"],
781
+ allowed: ["kind", "source"]
782
+ },
783
+ valueOf: {
784
+ required: ["source"],
785
+ allowed: ["kind", "source"]
786
+ },
787
+ elementAt: {
788
+ required: ["source", "index"],
789
+ allowed: [
790
+ "kind",
791
+ "source",
792
+ "index"
793
+ ]
794
+ },
795
+ fieldOf: {
796
+ required: ["source", "key"],
797
+ allowed: [
798
+ "kind",
799
+ "source",
800
+ "key"
801
+ ]
802
+ },
803
+ keyOf: {
804
+ required: ["source"],
805
+ allowed: ["kind", "source"]
806
+ },
807
+ fieldsOf: {
808
+ required: ["source", "fields"],
809
+ allowed: [
810
+ "kind",
811
+ "source",
812
+ "fields"
813
+ ]
814
+ },
815
+ pickFields: {
816
+ required: ["source", "fields"],
817
+ allowed: [
818
+ "kind",
819
+ "source",
820
+ "fields"
821
+ ]
822
+ },
823
+ omitFields: {
824
+ required: ["source", "fields"],
825
+ allowed: [
826
+ "kind",
827
+ "source",
828
+ "fields"
829
+ ]
830
+ },
831
+ partialFields: {
832
+ required: ["source", "fields"],
833
+ allowed: [
834
+ "kind",
835
+ "source",
836
+ "fields"
837
+ ]
838
+ },
839
+ requiredFields: {
840
+ required: ["source", "fields"],
841
+ allowed: [
842
+ "kind",
843
+ "source",
844
+ "fields"
845
+ ]
846
+ },
847
+ mergeRecords: {
848
+ required: ["sources", "conflict"],
849
+ allowed: [
850
+ "kind",
851
+ "sources",
852
+ "conflict"
853
+ ]
854
+ },
855
+ intersect: {
856
+ required: ["sources"],
857
+ allowed: ["kind", "sources"]
858
+ },
859
+ refine: {
860
+ required: ["source", "fields"],
861
+ allowed: [
862
+ "kind",
863
+ "source",
864
+ "fields"
865
+ ]
866
+ },
867
+ excludeVariants: {
868
+ required: ["source", "variants"],
869
+ allowed: [
870
+ "kind",
871
+ "source",
872
+ "variants"
873
+ ]
874
+ },
875
+ extractVariants: {
876
+ required: ["source", "variants"],
877
+ allowed: [
878
+ "kind",
879
+ "source",
880
+ "variants"
881
+ ]
882
+ }
883
+ };
884
+ function isObject(value) {
885
+ return typeof value === "object" && value !== null && !Array.isArray(value);
886
+ }
887
+ function hasOnlyKeys(value, keys$1) {
888
+ return Object.keys(value).every((key) => keys$1.includes(key));
889
+ }
890
+ function isSelector(value) {
891
+ if (!isObject(value)) return false;
892
+ if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
893
+ return value.kind === "keys" && hasOnlyKeys(value, [
894
+ "kind",
895
+ "keys",
896
+ "onMissing"
897
+ ]) && Array.isArray(value.keys) && value.keys.every((key) => typeof key === "string") && new Set(value.keys).size === value.keys.length && (value.onMissing === "error" || value.onMissing === "ignore");
898
+ }
899
+ function expressionShapeIssue(expression) {
900
+ const kind = expression.kind;
901
+ if (kind === "typeVar" && (typeof expression.name !== "string" || !expression.name.trim())) return "typeVar name must be non-blank";
902
+ if (kind === "opaqueHostType" && (!Array.isArray(expression.hostPath) || expression.hostPath.length === 0 || expression.hostPath.some((part) => typeof part !== "string" || !part.trim()))) return "hostPath must be a non-empty path";
903
+ if (kind === "tupleOf" && (!Array.isArray(expression.elements) || !isDense(expression.elements))) return "elements must be a dense array";
904
+ if (kind === "recordOf") {
905
+ if (!Array.isArray(expression.fields) || !isDense(expression.fields)) return "fields must be a dense array";
906
+ const keys$1 = /* @__PURE__ */ new Set();
907
+ for (const field of expression.fields) {
908
+ if (!isObject(field) || !hasOnlyKeys(field, [
909
+ "key",
910
+ "value",
911
+ "required",
912
+ "description"
913
+ ]) || typeof field.key !== "string" || keys$1.has(field.key)) return "record fields must have unique keys and a valid shape";
914
+ if (field.required !== void 0 && typeof field.required !== "boolean") return "record field required must be a boolean";
915
+ if (field.description !== void 0 && typeof field.description !== "string") return "record field description must be a string";
916
+ keys$1.add(field.key);
917
+ }
918
+ if (expression.additionalFields !== void 0 && expression.additionalFields !== true && !isObject(expression.additionalFields)) return "additionalFields must be a type term or true";
919
+ if (expression.constraints !== void 0 && (!Array.isArray(expression.constraints) || !isDense(expression.constraints))) return "constraints must be a dense array";
920
+ }
921
+ if (kind === "arrayOf" && expression.constraints !== void 0 && (!Array.isArray(expression.constraints) || !isDense(expression.constraints))) return "constraints must be a dense array";
922
+ if (kind === "taggedUnionOf") {
923
+ if (typeof expression.discriminator !== "string" || !expression.discriminator.trim() || !Array.isArray(expression.variants) || !isDense(expression.variants) || expression.variants.length < 2) return "taggedUnionOf requires a discriminator and at least two dense variants";
924
+ const keys$1 = /* @__PURE__ */ new Set();
925
+ for (const variant of expression.variants) {
926
+ if (!isObject(variant) || !hasOnlyKeys(variant, [
927
+ "key",
928
+ "value",
929
+ "description"
930
+ ]) || typeof variant.key !== "string" || !variant.key.trim() || keys$1.has(variant.key)) return "taggedUnionOf variants must have unique non-blank keys and a valid shape";
931
+ if (variant.description !== void 0 && typeof variant.description !== "string") return "variant description must be a string";
932
+ keys$1.add(variant.key);
933
+ }
934
+ }
935
+ if ([
936
+ "fieldsOf",
937
+ "pickFields",
938
+ "omitFields",
939
+ "partialFields",
940
+ "requiredFields"
941
+ ].includes(String(kind)) && !isSelector(expression.fields)) return "fields must be a valid field selector";
942
+ if ((kind === "excludeVariants" || kind === "extractVariants") && !isSelector(expression.variants)) return "variants must be a valid variant selector";
943
+ if (kind === "elementAt" && (!Number.isSafeInteger(expression.index) || expression.index < 0)) return "index must be a non-negative safe integer";
944
+ if (kind === "fieldOf" && typeof expression.key !== "string") return "key must be a string";
945
+ if (kind === "mergeRecords" && (!Array.isArray(expression.sources) || !isDense(expression.sources) || expression.sources.length < 2 || ![
946
+ "leftWins",
947
+ "rightWins",
948
+ "error"
949
+ ].includes(String(expression.conflict)))) return "mergeRecords requires at least two dense sources and a valid conflict policy";
950
+ if (kind === "intersect" && (!Array.isArray(expression.sources) || !isDense(expression.sources) || expression.sources.length < 2)) return "intersect requires at least two dense sources";
951
+ if (kind === "refine") {
952
+ if (!Array.isArray(expression.fields) || !isDense(expression.fields) || expression.fields.length === 0) return "refine requires non-empty dense field actions";
953
+ const keys$1 = /* @__PURE__ */ new Set();
954
+ for (const action of expression.fields) {
955
+ if (!isObject(action) || !hasOnlyKeys(action, [
956
+ "key",
957
+ "require",
958
+ "intersectWith",
959
+ "addConstraints"
960
+ ]) || typeof action.key !== "string" || keys$1.has(action.key)) return "refine actions must have unique keys and a valid shape";
961
+ if (action.require !== void 0 && action.require !== true) return "refine require must be true when specified";
962
+ if (action.addConstraints !== void 0 && (!Array.isArray(action.addConstraints) || !isDense(action.addConstraints))) return "addConstraints must be a dense array";
963
+ keys$1.add(action.key);
964
+ }
965
+ }
966
+ }
967
+ function isDense(value) {
968
+ for (let index = 0; index < value.length; index += 1) if (!Object.prototype.hasOwnProperty.call(value, index)) return false;
969
+ return true;
970
+ }
971
+
972
+ //#endregion
973
+ //#region src/definition/expression-validator.ts
974
+ const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
975
+ var Validator = class {
976
+ issues = [];
977
+ steps = 0;
978
+ active = /* @__PURE__ */ new WeakSet();
979
+ issue(code, path, message) {
980
+ this.issues.push({
981
+ code: `expression.${code}`,
982
+ path,
983
+ message
984
+ });
985
+ return false;
986
+ }
987
+ portable(value, path = [], depth = 0) {
988
+ if (++this.steps > 1e4 || depth > 64) return this.issue("budget", path, "definition validation budget exceeded");
989
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
990
+ if (typeof value === "number" && Number.isFinite(value)) return true;
991
+ if (typeof value !== "object" || value === null) return this.issue("json.invalid", path, "value must be JSON-compatible");
992
+ if (this.active.has(value)) return this.issue("cycle", path, "declarations must be acyclic");
993
+ const array = Array.isArray(value);
994
+ const prototype = Object.getPrototypeOf(value);
995
+ if (!array && prototype !== null && prototype !== Object.prototype) return this.issue("object.invalid", path, "declarations require plain objects");
996
+ this.active.add(value);
997
+ let valid = true;
998
+ for (const key of Reflect.ownKeys(value)) {
999
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1000
+ if (typeof key === "symbol" || !("value" in descriptor) || !descriptor.enumerable && !(array && key === "length")) {
1001
+ valid = this.issue("property.invalid", path, "only enumerable own data properties are supported") && valid;
1002
+ continue;
1003
+ }
1004
+ if (array && key === "length") continue;
1005
+ if (array && (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= value.length)) {
1006
+ valid = this.issue("array.invalid", path, "arrays must have only indexed elements") && valid;
1007
+ continue;
1008
+ }
1009
+ valid = this.portable(descriptor.value, [...path, array ? Number(key) : key], depth + 1) && valid;
1010
+ }
1011
+ if (array) {
1012
+ for (let i = 0; i < value.length; i++) if (!own(value, String(i))) {
1013
+ valid = this.issue("array.sparse", [...path, i], "arrays must be dense") && valid;
1014
+ break;
1015
+ }
1016
+ }
1017
+ this.active.delete(value);
1018
+ return valid;
1019
+ }
1020
+ term(value, path = [], expressionOnly = false) {
1021
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return this.issue("term.invalid", path, "type term must be an object");
1022
+ const record = value;
1023
+ const kind = record.kind;
1024
+ if (typeof kind !== "string" || !expressionKinds.has(kind)) {
1025
+ if (expressionOnly) return this.issue("kind.invalid", [...path, "kind"], "expected a SchemaTypeExpr kind");
1026
+ const schema = validateSchemaNodeDefinition(value);
1027
+ if (schema.ok) return true;
1028
+ this.issues.push(...schema.issues.map((issue$1) => ({
1029
+ ...issue$1,
1030
+ path: [...path, ...issue$1.path]
1031
+ })));
1032
+ return false;
1033
+ }
1034
+ const shape = expressionFields[kind];
1035
+ for (const key of Object.keys(record)) if (!shape.allowed.includes(key)) return this.issue("shape.invalid", [...path, key], `unknown field '${key}'`);
1036
+ for (const key of shape.required) if (!own(record, key)) return this.issue("shape.invalid", [...path, key], `missing field '${key}'`);
1037
+ const issue = expressionShapeIssue(record);
1038
+ if (issue) return this.issue("shape.invalid", path, issue);
1039
+ let valid = true;
1040
+ const child = (value$1, childPath) => {
1041
+ valid = this.term(value$1, childPath) && valid;
1042
+ };
1043
+ for (const key of [
1044
+ "value",
1045
+ "element",
1046
+ "source",
1047
+ "extends"
1048
+ ]) if (own(record, key)) child(record[key], [...path, key]);
1049
+ if (own(record, "additionalFields") && record.additionalFields !== true) child(record.additionalFields, [...path, "additionalFields"]);
1050
+ for (const key of ["elements", "sources"]) if (Array.isArray(record[key])) record[key].forEach((item, index) => child(item, [
1051
+ ...path,
1052
+ key,
1053
+ index
1054
+ ]));
1055
+ for (const key of ["fields", "variants"]) if (Array.isArray(record[key])) record[key].forEach((item, index) => {
1056
+ if (kind === "recordOf" && key === "fields" || kind === "taggedUnionOf" && key === "variants") child(item.value, [
1057
+ ...path,
1058
+ key,
1059
+ index,
1060
+ "value"
1061
+ ]);
1062
+ if (kind === "refine" && own(item, "intersectWith")) child(item.intersectWith, [
1063
+ ...path,
1064
+ key,
1065
+ index,
1066
+ "intersectWith"
1067
+ ]);
1068
+ if (kind === "refine" && own(item, "addConstraints")) valid = this.constraints(item.addConstraints, [
1069
+ ...path,
1070
+ key,
1071
+ index,
1072
+ "addConstraints"
1073
+ ]) && valid;
1074
+ });
1075
+ if (own(record, "constraints")) valid = this.constraints(record.constraints, [...path, "constraints"]) && valid;
1076
+ return valid;
1077
+ }
1078
+ constraints(value, path) {
1079
+ const result = validateSchemaNodeDefinition({
1080
+ kind: "record",
1081
+ fields: [],
1082
+ constraints: value
1083
+ });
1084
+ if (result.ok) return true;
1085
+ this.issues.push(...result.issues.map((issue) => ({
1086
+ ...issue,
1087
+ path: [...path, ...issue.path.slice(1)]
1088
+ })));
1089
+ return false;
1090
+ }
1091
+ };
1092
+ function validateSchemaTypeExprDefinition(value) {
1093
+ const validator = new Validator();
1094
+ return validator.portable(value) && validator.term(value, [], true) ? {
1095
+ ok: true,
1096
+ expression: value,
1097
+ issues: []
1098
+ } : {
1099
+ ok: false,
1100
+ issues: validator.issues
1101
+ };
1102
+ }
1103
+ function validateSchemaTypeTermDefinition(value) {
1104
+ const validator = new Validator();
1105
+ return validator.portable(value) && validator.term(value) ? {
1106
+ ok: true,
1107
+ term: value,
1108
+ issues: []
1109
+ } : {
1110
+ ok: false,
1111
+ issues: validator.issues
1112
+ };
1113
+ }
1114
+
1115
+ //#endregion
1116
+ Object.defineProperty(exports, 'expressionFields', {
1117
+ enumerable: true,
1118
+ get: function () {
1119
+ return expressionFields;
1120
+ }
1121
+ });
1122
+ Object.defineProperty(exports, 'expressionKinds', {
1123
+ enumerable: true,
1124
+ get: function () {
1125
+ return expressionKinds;
1126
+ }
1127
+ });
1128
+ Object.defineProperty(exports, 'expressionShapeIssue', {
1129
+ enumerable: true,
1130
+ get: function () {
1131
+ return expressionShapeIssue;
1132
+ }
1133
+ });
1134
+ Object.defineProperty(exports, 'isStructuredOperationContainerDefinition', {
1135
+ enumerable: true,
1136
+ get: function () {
1137
+ return isStructuredOperationContainerDefinition;
1138
+ }
1139
+ });
1140
+ Object.defineProperty(exports, 'isStructuredOperationDefinition', {
1141
+ enumerable: true,
1142
+ get: function () {
1143
+ return isStructuredOperationDefinition;
1144
+ }
1145
+ });
1146
+ Object.defineProperty(exports, 'validateOperationContainerDefinition', {
1147
+ enumerable: true,
1148
+ get: function () {
1149
+ return validateOperationContainerDefinition;
1150
+ }
1151
+ });
1152
+ Object.defineProperty(exports, 'validateOperationDefinition', {
1153
+ enumerable: true,
1154
+ get: function () {
1155
+ return validateOperationDefinition;
1156
+ }
1157
+ });
1158
+ Object.defineProperty(exports, 'validateSchemaNodeDefinition', {
1159
+ enumerable: true,
1160
+ get: function () {
1161
+ return validateSchemaNodeDefinition;
1162
+ }
1163
+ });
1164
+ Object.defineProperty(exports, 'validateSchemaTypeExprDefinition', {
1165
+ enumerable: true,
1166
+ get: function () {
1167
+ return validateSchemaTypeExprDefinition;
1168
+ }
1169
+ });
1170
+ Object.defineProperty(exports, 'validateSchemaTypeTermDefinition', {
1171
+ enumerable: true,
1172
+ get: function () {
1173
+ return validateSchemaTypeTermDefinition;
1174
+ }
1175
+ });
1176
+ Object.defineProperty(exports, 'validateStructuredOperationContainerDefinition', {
1177
+ enumerable: true,
1178
+ get: function () {
1179
+ return validateStructuredOperationContainerDefinition;
1180
+ }
1181
+ });
1182
+ Object.defineProperty(exports, 'validateStructuredOperationDefinition', {
1183
+ enumerable: true,
1184
+ get: function () {
1185
+ return validateStructuredOperationDefinition;
1186
+ }
1187
+ });