@oomol-lab/open-flow 0.1.0-beta.53 → 0.1.0-beta.55

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 (38) hide show
  1. package/dist/browser/{createResourceDialog-BsaBMf7_.js → createResourceDialog-4H5_lZ6s.js} +3 -3
  2. package/dist/browser/{main-BPABKzwN.js → dist-BFmpkX4P.js} +9 -1
  3. package/dist/browser/flow-authoring-node.d.ts +5 -0
  4. package/dist/browser/flow-authoring.d.ts +1 -1
  5. package/dist/browser/flow-authoring.js +9434 -9187
  6. package/dist/browser/flow-change.d.ts +6 -1
  7. package/dist/browser/flow-change.js +3108 -141
  8. package/dist/browser/{flowChanges-CcscgZsW.js → flowChanges-ZzG-f9cg.js} +1978 -5437
  9. package/dist/browser/{flowWorkspace-CoT_ewLX.js → flowWorkspace-ChpRaTMX.js} +3197 -310
  10. package/dist/browser/{icons-0s-Q_3lp.js → icons-CdAB9wyS.js} +4294 -54
  11. package/dist/browser/{markdownContent-D3FFc-u_.js → markdownContent-frwDfQQU.js} +1 -2
  12. package/dist/browser/preview.css +375 -322
  13. package/dist/browser/preview.js +5458 -1888
  14. package/dist/browser/theme.css +1 -0
  15. package/dist/browser/ui.css +30 -0
  16. package/dist/browser/ui.js +4 -3
  17. package/dist/browser/workbench.css +375 -322
  18. package/dist/browser/workbench.js +28 -16
  19. package/dist/browser/{workbenchSelect-BqUPacsr.js → workbenchSelect-BRZN4ish.js} +1 -1
  20. package/dist/common/authoringExamples.d.ts +3 -2
  21. package/dist/common/control-api-conformance.js +3410 -3285
  22. package/dist/common/control-api.js +3680 -3531
  23. package/dist/common/control-requests.js +2132 -1860
  24. package/dist/common/decision.d.ts +47 -0
  25. package/dist/common/decision.js +10153 -0
  26. package/dist/common/flow-encoding.js +3105 -124
  27. package/dist/common/flow-semantics.js +276 -2
  28. package/dist/common/integration-trigger.js +202 -1
  29. package/dist/common/mcp.js +3748 -3623
  30. package/dist/common/openapi.js +202 -1
  31. package/dist/common/poll-trigger.js +226 -1
  32. package/dist/common/run-events.js +1 -0
  33. package/dist/common/runtime-contract.d.ts +8 -0
  34. package/dist/common/scheduler.d.ts +1 -1
  35. package/dist/common/scheduler.js +2137 -1936
  36. package/dist/common/webhook-trigger.js +202 -1
  37. package/package.json +5 -1
  38. package/dist/browser/dist-BDBTOgS5.js +0 -9
@@ -7,6 +7,30 @@ function assertOpenApiAuthBindings(document) {
7
7
  }
8
8
  }
9
9
  //#endregion
10
+ //#region ../../node_modules/.bun/dequal@2.0.3/node_modules/dequal/lite/index.mjs
11
+ var has = Object.prototype.hasOwnProperty;
12
+ function dequal(foo, bar) {
13
+ var ctor, len;
14
+ if (foo === bar) return true;
15
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
16
+ if (ctor === Date) return foo.getTime() === bar.getTime();
17
+ if (ctor === RegExp) return foo.toString() === bar.toString();
18
+ if (ctor === Array) {
19
+ if ((len = foo.length) === bar.length) while (len-- && dequal(foo[len], bar[len]));
20
+ return len === -1;
21
+ }
22
+ if (!ctor || typeof foo === "object") {
23
+ len = 0;
24
+ for (ctor in foo) {
25
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
26
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
27
+ }
28
+ return Object.keys(bar).length === len;
29
+ }
30
+ }
31
+ return foo !== foo && bar !== bar;
32
+ }
33
+ //#endregion
10
34
  //#region ../../node_modules/.bun/zod@4.6.5/node_modules/zod/v4/core/util.js
11
35
  function getEnumValues(entries) {
12
36
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
@@ -144,7 +168,7 @@ function slugify(input) {
144
168
  return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
145
169
  }
146
170
  var captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
147
- function isObject(data) {
171
+ function isObject$1(data) {
148
172
  return typeof data === "object" && data !== null && !Array.isArray(data);
149
173
  }
150
174
  var allowsEval = /* @__PURE__*/ cached(() => {
@@ -157,18 +181,18 @@ var allowsEval = /* @__PURE__*/ cached(() => {
157
181
  return false;
158
182
  }
159
183
  });
160
- function isPlainObject(o) {
161
- if (isObject(o) === false) return false;
184
+ function isPlainObject$1(o) {
185
+ if (isObject$1(o) === false) return false;
162
186
  const ctor = o.constructor;
163
187
  if (ctor === void 0) return true;
164
188
  if (typeof ctor !== "function") return true;
165
189
  const prot = ctor.prototype;
166
- if (isObject(prot) === false) return false;
190
+ if (isObject$1(prot) === false) return false;
167
191
  if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
168
192
  return true;
169
193
  }
170
194
  function shallowClone(o) {
171
- if (isPlainObject(o)) return { ...o };
195
+ if (isPlainObject$1(o)) return { ...o };
172
196
  if (Array.isArray(o)) return [...o];
173
197
  if (o instanceof Map) return new Map(o);
174
198
  if (o instanceof Set) return new Set(o);
@@ -223,7 +247,7 @@ var BIGINT_FORMAT_RANGES = {
223
247
  int64: [/* @__PURE__*/ BigInt("-9223372036854775808"), /* @__PURE__*/ BigInt("9223372036854775807")],
224
248
  uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")]
225
249
  };
226
- function pick(schema, mask) {
250
+ function pick$1(schema, mask) {
227
251
  const currDef = schema._zod.def;
228
252
  const checks = currDef.checks;
229
253
  if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
@@ -256,7 +280,7 @@ function omit(schema, mask) {
256
280
  }));
257
281
  }
258
282
  function extend(schema, shape) {
259
- if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
283
+ if (!isPlainObject$1(shape)) throw new Error("Invalid input to extend: expected a plain object");
260
284
  const checks = schema._zod.def.checks;
261
285
  if (checks && checks.length > 0) {
262
286
  const existingShape = sourceShape(schema);
@@ -271,7 +295,7 @@ function extended(schema, shape) {
271
295
  return newShape;
272
296
  }
273
297
  function safeExtend(schema, shape) {
274
- if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
298
+ if (!isPlainObject$1(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
275
299
  return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
276
300
  }
277
301
  function merge(a, b) {
@@ -2041,7 +2065,7 @@ var $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
2041
2065
  }
2042
2066
  return propValues;
2043
2067
  });
2044
- const isObject$2 = isObject;
2068
+ const isObject = isObject$1;
2045
2069
  const catchall = def.catchall;
2046
2070
  let value;
2047
2071
  const memo = globalConfig.memoizer;
@@ -2049,7 +2073,7 @@ var $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
2049
2073
  inst._zod.parse = (payload, ctx) => {
2050
2074
  value ?? (value = _normalized.value);
2051
2075
  const input = payload.value;
2052
- if (!isObject$2(input)) {
2076
+ if (!isObject(input)) {
2053
2077
  payload.issues.push({
2054
2078
  expected: "object",
2055
2079
  code: "invalid_type",
@@ -2179,7 +2203,7 @@ var $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
2179
2203
  return doc.compile();
2180
2204
  };
2181
2205
  let fastpass;
2182
- const isObject$1 = isObject;
2206
+ const isObject = isObject$1;
2183
2207
  const jit = !globalConfig.jitless;
2184
2208
  const fastEnabled = jit && allowsEval.value;
2185
2209
  const catchall = def.catchall;
@@ -2187,7 +2211,7 @@ var $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
2187
2211
  inst._zod.parse = (payload, ctx) => {
2188
2212
  value ?? (value = _normalized.value);
2189
2213
  const input = payload.value;
2190
- if (!isObject$1(input)) {
2214
+ if (!isObject(input)) {
2191
2215
  payload.issues.push({
2192
2216
  expected: "object",
2193
2217
  code: "invalid_type",
@@ -2260,6 +2284,70 @@ var $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
2260
2284
  });
2261
2285
  };
2262
2286
  });
2287
+ function discriminatorMap(def) {
2288
+ const map = /* @__PURE__ */ new Map();
2289
+ for (const option of def.options) {
2290
+ const values = option._zod.propValues?.[def.discriminator];
2291
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
2292
+ for (const value of values) if (map.has(value)) {
2293
+ if (value !== void 0) throw new Error(`Duplicate discriminator value "${String(value)}"`);
2294
+ map.set(value, null);
2295
+ } else map.set(value, option);
2296
+ }
2297
+ return map;
2298
+ }
2299
+ var $ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
2300
+ def.inclusive = false;
2301
+ $ZodUnion.init(inst, def);
2302
+ const _super = inst._zod.parse;
2303
+ defineLazyInternal(inst, "propValues", (zod) => {
2304
+ const propValues = {};
2305
+ let undefinedCount = 0;
2306
+ for (const option of zod.def.options) {
2307
+ const pv = option._zod.propValues;
2308
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
2309
+ if (pv[zod.def.discriminator]?.has(void 0)) undefinedCount++;
2310
+ for (const [k, v] of Object.entries(pv)) {
2311
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) assignProp(propValues, k, /* @__PURE__ */ new Set());
2312
+ for (const val of v) propValues[k].add(val);
2313
+ }
2314
+ }
2315
+ if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(void 0);
2316
+ return propValues;
2317
+ });
2318
+ def.options.forEach((option, i) => {
2319
+ const propShape = rawShape(option._zod.def);
2320
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) throw new Error(`Invalid discriminated union option at index "${i}"`);
2321
+ });
2322
+ const disc = cached(() => discriminatorMap(def));
2323
+ inst._zod.parse = (payload, ctx) => {
2324
+ const input = payload.value;
2325
+ if (!isObject$1(input)) {
2326
+ payload.issues.push({
2327
+ code: "invalid_type",
2328
+ expected: "object",
2329
+ input,
2330
+ inst
2331
+ });
2332
+ return payload;
2333
+ }
2334
+ const value = input?.[def.discriminator];
2335
+ const opt = disc.value.get(value);
2336
+ if (opt && (value !== void 0 || ctx.direction !== "backward")) return opt._zod.run(payload, ctx);
2337
+ if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
2338
+ payload.issues.push({
2339
+ code: "invalid_union",
2340
+ errors: [],
2341
+ note: "No matching discriminator",
2342
+ discriminator: def.discriminator,
2343
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
2344
+ input,
2345
+ path: [def.discriminator],
2346
+ inst
2347
+ });
2348
+ return payload;
2349
+ };
2350
+ });
2263
2351
  var $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
2264
2352
  $ZodType.init(inst, def);
2265
2353
  inst._zod.parse = (payload, ctx) => {
@@ -2287,7 +2375,7 @@ function mergeValues(a, b) {
2287
2375
  valid: true,
2288
2376
  data: a
2289
2377
  };
2290
- if (isPlainObject(a) && isPlainObject(b)) {
2378
+ if (isPlainObject$1(a) && isPlainObject$1(b)) {
2291
2379
  const bKeys = Object.keys(b);
2292
2380
  const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
2293
2381
  const newObj = {
@@ -2380,7 +2468,7 @@ var $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
2380
2468
  memo?.attach(inst);
2381
2469
  inst._zod.parse = (payload, ctx) => {
2382
2470
  const input = payload.value;
2383
- if (!isPlainObject(input)) {
2471
+ if (!isPlainObject$1(input)) {
2384
2472
  payload.issues.push({
2385
2473
  expected: "record",
2386
2474
  code: "invalid_type",
@@ -5265,7 +5353,7 @@ var ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
5265
5353
  return merge(this, other);
5266
5354
  },
5267
5355
  pick(mask) {
5268
- return pick(this, mask);
5356
+ return pick$1(this, mask);
5269
5357
  },
5270
5358
  omit(mask) {
5271
5359
  return omit(this, mask);
@@ -5308,6 +5396,18 @@ function union(options, params) {
5308
5396
  ...normalizeParams(params)
5309
5397
  });
5310
5398
  }
5399
+ var ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
5400
+ ZodUnion.init(inst, def);
5401
+ $ZodDiscriminatedUnion.init(inst, def);
5402
+ });
5403
+ function discriminatedUnion(discriminator, options, params) {
5404
+ return new ZodDiscriminatedUnion({
5405
+ type: "union",
5406
+ options,
5407
+ discriminator,
5408
+ ...normalizeParams(params)
5409
+ });
5410
+ }
5311
5411
  var ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
5312
5412
  $ZodIntersection.init(inst, def);
5313
5413
  ZodType.init(inst, def);
@@ -5586,120 +5686,2966 @@ function json$1(params) {
5586
5686
  return jsonSchema;
5587
5687
  }
5588
5688
  //#endregion
5589
- //#region src/flow/common/json.ts
5590
- var maxJsonDepth = 64;
5591
- function checkJsonDepth(value, depth = 0) {
5592
- if (depth > 64) throw new TypeError("Value exceeds the maximum JSON depth.");
5593
- if (value != null && typeof value == "object") for (const child of Object.values(value)) checkJsonDepth(child, depth + 1);
5689
+ //#region src/json-schema-subset/utils.ts
5690
+ var nextId = 0;
5691
+ function createId() {
5692
+ const id = nextId;
5693
+ nextId += 1;
5694
+ return id;
5695
+ }
5696
+ function deepFreeze(target) {
5697
+ if (typeof target === "object" && target !== null && !Object.isFrozen(target)) {
5698
+ for (const key of Object.getOwnPropertyNames(target)) deepFreeze(Reflect.get(target, key));
5699
+ Object.freeze(target);
5700
+ }
5701
+ return target;
5702
+ }
5703
+ function pick(target, keys) {
5704
+ const newTarget = {};
5705
+ for (const key of keys) if (key in target) newTarget[key] = target[key];
5706
+ return newTarget;
5707
+ }
5708
+ function deepCopy(value) {
5709
+ if (typeof value !== "object" || value === null) return value;
5710
+ else if (Array.isArray(value)) {
5711
+ const array = [];
5712
+ for (const [i, element] of value.entries()) array[i] = deepCopy(element);
5713
+ return array;
5714
+ } else {
5715
+ const newObject = {};
5716
+ for (const key in value) newObject[key] = deepCopy(value[key]);
5717
+ return newObject;
5718
+ }
5719
+ }
5720
+ function isDeepEquals(value1, value2) {
5721
+ if (value1 === value2) return true;
5722
+ if (value1 === null) return false;
5723
+ if (typeof value1 !== "object") return false;
5724
+ if (typeof value1 !== typeof value2) return false;
5725
+ if (Array.isArray(value1)) {
5726
+ if (!Array.isArray(value2)) return false;
5727
+ if (value1.length !== value2.length) return false;
5728
+ for (const [i, value1Element] of value1.entries()) if (!isDeepEquals(value1Element, value2[i])) return false;
5729
+ } else {
5730
+ if (Array.isArray(value2)) return false;
5731
+ for (const key in value1) {
5732
+ if (!(key in value2)) return false;
5733
+ if (!isDeepEquals(value1[key], value2[key])) return false;
5734
+ }
5735
+ for (const key in value2) if (!(key in value1)) return false;
5736
+ }
5737
+ return true;
5594
5738
  }
5595
5739
  //#endregion
5596
- //#region src/flow/common/triggerScheduleSchema.ts
5597
- var triggerScheduleSchema = array(union([object({
5598
- type: literal("cron"),
5599
- expression: string(),
5600
- timezone: string()
5601
- }), object({
5602
- type: literal("every"),
5603
- unit: _enum([
5604
- "day",
5605
- "hour",
5606
- "minute",
5607
- "month",
5608
- "week"
5609
- ]),
5610
- value: number()
5611
- })]));
5740
+ //#region src/json-schema-subset/expression/result.ts
5741
+ var ExpressionSingleResult = Object.freeze({
5742
+ Equals: 0,
5743
+ Containing: 1,
5744
+ ContainedBy: 2,
5745
+ Rejection: 3,
5746
+ Intersection: 4
5747
+ });
5748
+ var ExpressionEquals = toExpression(ExpressionSingleResult.Equals);
5749
+ var ExpressionContaining = toExpression(ExpressionSingleResult.Containing);
5750
+ var ExpressionContainedBy = toExpression(ExpressionSingleResult.ContainedBy);
5751
+ var ExpressionRejection = toExpression(ExpressionSingleResult.Rejection);
5752
+ var ExpressionIntersection = toExpression(ExpressionSingleResult.Intersection);
5753
+ var ExpressionMaskList = deepFreeze([
5754
+ [ExpressionSingleResult.Equals, ExpressionEquals],
5755
+ [ExpressionSingleResult.Containing, ExpressionContaining],
5756
+ [ExpressionSingleResult.ContainedBy, ExpressionContainedBy],
5757
+ [ExpressionSingleResult.Rejection, ExpressionRejection],
5758
+ [ExpressionSingleResult.Intersection, ExpressionIntersection]
5759
+ ]);
5760
+ var ExpressionAny = (() => {
5761
+ let expression = 0;
5762
+ for (const [_, mask] of ExpressionMaskList) expression |= mask;
5763
+ return expression;
5764
+ })();
5765
+ function hasEquals(expression) {
5766
+ return !!(expression & ExpressionEquals);
5767
+ }
5768
+ function hasContaining(expression) {
5769
+ return !!(expression & ExpressionContaining);
5770
+ }
5771
+ function hasContainedBy(expression) {
5772
+ return !!(expression & ExpressionContainedBy);
5773
+ }
5774
+ function hasRejection(expression) {
5775
+ return !!(expression & ExpressionRejection);
5776
+ }
5777
+ function hasIntersection(expression) {
5778
+ return !!(expression & ExpressionIntersection);
5779
+ }
5780
+ function toExpression(expression) {
5781
+ return 1 << expression;
5782
+ }
5612
5783
  //#endregion
5613
- //#region src/flow/common/webhookMethod.ts
5614
- var webhookMethods = [
5615
- "GET",
5616
- "POST",
5617
- "PUT",
5618
- "PATCH",
5619
- "DELETE"
5620
- ];
5621
- var text = string();
5622
- var json = json$1();
5623
- var strings = array(text);
5624
- var port = object({
5625
- description: text.optional(),
5626
- jsonSchema: json,
5627
- nullable: boolean(),
5628
- handle: text
5629
- });
5630
- var input = port.extend({ value: json.optional() });
5631
- var group = object({
5632
- collapsed: boolean().optional(),
5633
- group: text
5634
- });
5635
- var nodeSource = object({
5636
- kind: literal("node"),
5637
- nodeId: text,
5638
- output: text,
5639
- field: text.optional()
5640
- });
5641
- var flowSource = object({
5642
- kind: literal("flow"),
5643
- input: text
5784
+ //#region src/json-schema-subset/expression/combination.ts
5785
+ function makeCombination(calculator) {
5786
+ let expression = 0;
5787
+ let count = 0;
5788
+ const quantum = { push: (newExpression) => {
5789
+ if (count === 0) expression = newExpression;
5790
+ else expression = forEach(expression, newExpression, calculator);
5791
+ count += 1;
5792
+ return expression;
5793
+ } };
5794
+ Object.defineProperties(quantum, {
5795
+ result: { get: () => expression },
5796
+ count: { get: () => count }
5797
+ });
5798
+ return quantum;
5799
+ }
5800
+ function forEach(e1, e2, calculator) {
5801
+ let expression = 0;
5802
+ for (const [singleResult1, mask1] of ExpressionMaskList) if (mask1 & e1) {
5803
+ for (const [singleResult2, mask2] of ExpressionMaskList) if (mask2 & e2) {
5804
+ expression |= calculator(singleResult1, singleResult2);
5805
+ if (expression === ExpressionAny) return expression;
5806
+ }
5807
+ }
5808
+ return expression;
5809
+ }
5810
+ //#endregion
5811
+ //#region src/json-schema-subset/expression/calculator.ts
5812
+ var CalculatorOperator = Object.freeze({
5813
+ Save: 0,
5814
+ OneOf: 1,
5815
+ AllOf: 2,
5816
+ AnyOf: 3,
5817
+ Not: 4,
5818
+ Swap: 5
5819
+ });
5820
+ function calculate(operator, expressions) {
5821
+ switch (operator) {
5822
+ case CalculatorOperator.Save: return expressions[0];
5823
+ case CalculatorOperator.OneOf: return calculateOneOf(expressions);
5824
+ case CalculatorOperator.AllOf:
5825
+ case CalculatorOperator.AnyOf: return calculateCombination(operator, expressions);
5826
+ case CalculatorOperator.Not:
5827
+ case CalculatorOperator.Swap: return calculateUnary(operator, expressions[0]);
5828
+ }
5829
+ }
5830
+ function swap(expression) {
5831
+ return calculateUnary(CalculatorOperator.Swap, expression);
5832
+ }
5833
+ /**
5834
+ * The oneOf operator is indivisible, so `a + b + c` must be evaluated as one expression.
5835
+ * ![](../../doc/images/all_of_expression.png)
5836
+ */
5837
+ function calculateOneOf(expressions) {
5838
+ if (expressions.length === 1) return expressions[0];
5839
+ const unionSet = calculateCombination(CalculatorOperator.AnyOf, expressions);
5840
+ const intersectionList = [];
5841
+ for (let i = 0; i < expressions.length; ++i) for (let j = i + 1; j < expressions.length; ++j) {
5842
+ const left = expressions[i];
5843
+ const right = expressions[j];
5844
+ const intersection = calculateCombination(CalculatorOperator.AllOf, [left, right]);
5845
+ intersectionList.push(intersection);
5846
+ }
5847
+ const banZone = calculateCombination(CalculatorOperator.AnyOf, intersectionList);
5848
+ const enableZone = calculateUnary(CalculatorOperator.Not, banZone);
5849
+ return calculateCombination(CalculatorOperator.AllOf, [unionSet, enableZone]);
5850
+ }
5851
+ function calculateCombination(operator, expressions) {
5852
+ if (expressions.length < 0) throw new Error("invalid expressions: empty array");
5853
+ let combination;
5854
+ switch (operator) {
5855
+ case CalculatorOperator.AllOf:
5856
+ combination = makeCombination(calculateAllOf);
5857
+ break;
5858
+ case CalculatorOperator.AnyOf:
5859
+ combination = makeCombination(calculateAnyOf);
5860
+ break;
5861
+ default: throw new Error(`invalid operator ${operator}`);
5862
+ }
5863
+ for (const expression of expressions) combination.push(expression);
5864
+ return combination.result;
5865
+ }
5866
+ function calculateUnary(operator, expression) {
5867
+ let calculator;
5868
+ let result = 0;
5869
+ switch (operator) {
5870
+ case CalculatorOperator.Not:
5871
+ calculator = calculateNot;
5872
+ break;
5873
+ case CalculatorOperator.Swap:
5874
+ calculator = calculateSwap;
5875
+ break;
5876
+ default: throw new Error(`invalid operator ${operator}`);
5877
+ }
5878
+ for (const [singleExpression, maskExpression] of ExpressionMaskList) if (maskExpression & expression) result |= calculator(singleExpression);
5879
+ return result;
5880
+ }
5881
+ function calculateAllOf(e1, e2) {
5882
+ let result = 0;
5883
+ switch (e1) {
5884
+ case ExpressionSingleResult.Equals:
5885
+ switch (e2) {
5886
+ case ExpressionSingleResult.Equals:
5887
+ result = ExpressionEquals;
5888
+ break;
5889
+ case ExpressionSingleResult.Containing:
5890
+ result = ExpressionEquals;
5891
+ break;
5892
+ case ExpressionSingleResult.ContainedBy:
5893
+ result = ExpressionContainedBy;
5894
+ break;
5895
+ case ExpressionSingleResult.Rejection:
5896
+ result = 0;
5897
+ break;
5898
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy;
5899
+ }
5900
+ break;
5901
+ case ExpressionSingleResult.Containing:
5902
+ switch (e2) {
5903
+ case ExpressionSingleResult.Equals:
5904
+ result = ExpressionEquals;
5905
+ break;
5906
+ case ExpressionSingleResult.Containing:
5907
+ result = ExpressionEquals | ExpressionContaining;
5908
+ break;
5909
+ case ExpressionSingleResult.ContainedBy:
5910
+ result = ExpressionContainedBy;
5911
+ break;
5912
+ case ExpressionSingleResult.Rejection:
5913
+ result = ExpressionRejection;
5914
+ break;
5915
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection | ExpressionContainedBy;
5916
+ }
5917
+ break;
5918
+ case ExpressionSingleResult.ContainedBy:
5919
+ switch (e2) {
5920
+ case ExpressionSingleResult.Equals:
5921
+ result = ExpressionContainedBy;
5922
+ break;
5923
+ case ExpressionSingleResult.Containing:
5924
+ result = ExpressionContainedBy;
5925
+ break;
5926
+ case ExpressionSingleResult.ContainedBy:
5927
+ result = ExpressionContainedBy;
5928
+ break;
5929
+ case ExpressionSingleResult.Rejection:
5930
+ result = 0;
5931
+ break;
5932
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy;
5933
+ }
5934
+ break;
5935
+ case ExpressionSingleResult.Rejection:
5936
+ switch (e2) {
5937
+ case ExpressionSingleResult.Equals:
5938
+ result = 0;
5939
+ break;
5940
+ case ExpressionSingleResult.Containing:
5941
+ result = ExpressionRejection;
5942
+ break;
5943
+ case ExpressionSingleResult.ContainedBy:
5944
+ result = 0;
5945
+ break;
5946
+ case ExpressionSingleResult.Rejection:
5947
+ result = ExpressionRejection;
5948
+ break;
5949
+ case ExpressionSingleResult.Intersection: result = ExpressionRejection;
5950
+ }
5951
+ break;
5952
+ case ExpressionSingleResult.Intersection: switch (e2) {
5953
+ case ExpressionSingleResult.Equals:
5954
+ result = ExpressionContainedBy;
5955
+ break;
5956
+ case ExpressionSingleResult.Containing:
5957
+ result = ExpressionIntersection | ExpressionContainedBy;
5958
+ break;
5959
+ case ExpressionSingleResult.ContainedBy:
5960
+ result = ExpressionContainedBy;
5961
+ break;
5962
+ case ExpressionSingleResult.Rejection:
5963
+ result = ExpressionRejection;
5964
+ break;
5965
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy | ExpressionRejection | ExpressionIntersection;
5966
+ }
5967
+ }
5968
+ return result;
5969
+ }
5970
+ function calculateAnyOf(e1, e2) {
5971
+ let result = 0;
5972
+ switch (e1) {
5973
+ case ExpressionSingleResult.Equals:
5974
+ switch (e2) {
5975
+ case ExpressionSingleResult.Equals:
5976
+ result = ExpressionEquals;
5977
+ break;
5978
+ case ExpressionSingleResult.Containing:
5979
+ result = ExpressionContaining;
5980
+ break;
5981
+ case ExpressionSingleResult.ContainedBy:
5982
+ result = ExpressionEquals;
5983
+ break;
5984
+ case ExpressionSingleResult.Rejection:
5985
+ result = ExpressionContaining;
5986
+ break;
5987
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining;
5988
+ }
5989
+ break;
5990
+ case ExpressionSingleResult.Containing:
5991
+ switch (e2) {
5992
+ case ExpressionSingleResult.Equals:
5993
+ result = ExpressionContaining;
5994
+ break;
5995
+ case ExpressionSingleResult.Containing:
5996
+ result = ExpressionContaining;
5997
+ break;
5998
+ case ExpressionSingleResult.ContainedBy:
5999
+ result = ExpressionContaining;
6000
+ break;
6001
+ case ExpressionSingleResult.Rejection:
6002
+ result = ExpressionContaining;
6003
+ break;
6004
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining;
6005
+ }
6006
+ break;
6007
+ case ExpressionSingleResult.ContainedBy:
6008
+ switch (e2) {
6009
+ case ExpressionSingleResult.Equals:
6010
+ result = ExpressionEquals;
6011
+ break;
6012
+ case ExpressionSingleResult.Containing:
6013
+ result = ExpressionContaining;
6014
+ break;
6015
+ case ExpressionSingleResult.ContainedBy:
6016
+ result = ExpressionEquals | ExpressionContainedBy;
6017
+ break;
6018
+ case ExpressionSingleResult.Rejection:
6019
+ result = ExpressionIntersection;
6020
+ break;
6021
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining | ExpressionIntersection;
6022
+ }
6023
+ break;
6024
+ case ExpressionSingleResult.Rejection:
6025
+ switch (e2) {
6026
+ case ExpressionSingleResult.Equals:
6027
+ result = ExpressionContaining;
6028
+ break;
6029
+ case ExpressionSingleResult.Containing:
6030
+ result = ExpressionContaining;
6031
+ break;
6032
+ case ExpressionSingleResult.ContainedBy:
6033
+ result = ExpressionIntersection;
6034
+ break;
6035
+ case ExpressionSingleResult.Rejection:
6036
+ result = ExpressionRejection;
6037
+ break;
6038
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection;
6039
+ }
6040
+ break;
6041
+ case ExpressionSingleResult.Intersection: switch (e2) {
6042
+ case ExpressionSingleResult.Equals:
6043
+ result = ExpressionContaining;
6044
+ break;
6045
+ case ExpressionSingleResult.Containing:
6046
+ result = ExpressionContaining;
6047
+ break;
6048
+ case ExpressionSingleResult.ContainedBy:
6049
+ result = ExpressionContaining | ExpressionIntersection;
6050
+ break;
6051
+ case ExpressionSingleResult.Rejection:
6052
+ result = ExpressionIntersection;
6053
+ break;
6054
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining | ExpressionIntersection;
6055
+ }
6056
+ }
6057
+ return result;
6058
+ }
6059
+ function calculateNot(expression) {
6060
+ let result = 0;
6061
+ switch (expression) {
6062
+ case ExpressionSingleResult.Equals:
6063
+ result = ExpressionRejection;
6064
+ break;
6065
+ case ExpressionSingleResult.Containing:
6066
+ result = ExpressionRejection;
6067
+ break;
6068
+ case ExpressionSingleResult.ContainedBy:
6069
+ result = ExpressionIntersection;
6070
+ break;
6071
+ case ExpressionSingleResult.Rejection:
6072
+ result = ExpressionEquals | ExpressionContaining;
6073
+ break;
6074
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy | ExpressionIntersection;
6075
+ }
6076
+ return result;
6077
+ }
6078
+ function calculateSwap(expression) {
6079
+ let result = 0;
6080
+ switch (expression) {
6081
+ case ExpressionSingleResult.Equals:
6082
+ result = ExpressionEquals;
6083
+ break;
6084
+ case ExpressionSingleResult.Containing:
6085
+ result = ExpressionContainedBy;
6086
+ break;
6087
+ case ExpressionSingleResult.ContainedBy:
6088
+ result = ExpressionContaining;
6089
+ break;
6090
+ case ExpressionSingleResult.Rejection:
6091
+ result = ExpressionRejection;
6092
+ break;
6093
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection;
6094
+ }
6095
+ return result;
6096
+ }
6097
+ //#endregion
6098
+ //#region src/json-schema-subset/expression/types.ts
6099
+ var ExpressionKind = Object.freeze({
6100
+ Leaf: 0,
6101
+ Not: 1,
6102
+ AllOf: 2,
6103
+ AnyOf: 3,
6104
+ OneOf: 4
5644
6105
  });
5645
- var source = union([
5646
- nodeSource,
5647
- flowSource,
5648
- object({
5649
- kind: literal("binding"),
5650
- bindingId: text
5651
- })
5652
- ]);
5653
- var fixedInput = union([object({ kind: literal("unset") }), object({
5654
- kind: literal("value"),
5655
- value: json
5656
- })]);
5657
- var mapping = union([fixedInput, object({
5658
- kind: literal("sources"),
5659
- sources: array(source)
5660
- })]);
5661
- var inputs = record$1(text, mapping);
5662
- var ports = {
5663
- inputs: array(union([input, group])),
5664
- outputs: array(union([port, group]))
6106
+ //#endregion
6107
+ //#region src/json-schema-subset/expression/expression.ts
6108
+ var expression = (delegate) => (e1, e2) => {
6109
+ const rootNode = {
6110
+ parent: null,
6111
+ swapped: false,
6112
+ expressions: null,
6113
+ calculation: {
6114
+ operator: CalculatorOperator.Save,
6115
+ results: [0],
6116
+ willSwap: false,
6117
+ count: 0
6118
+ }
6119
+ };
6120
+ const extendQueue = [{
6121
+ parent: {
6122
+ node: rootNode,
6123
+ index: 0
6124
+ },
6125
+ swapped: false,
6126
+ expressions: [e1, e2],
6127
+ calculation: null
6128
+ }];
6129
+ const calculateQueue = [];
6130
+ while (extendQueue.length > 0 || calculateQueue.length > 0) {
6131
+ while (extendQueue.length > 0) extendNode(extendQueue.pop());
6132
+ while (calculateQueue.length > 0) calculateNode(calculateQueue.pop());
6133
+ }
6134
+ function extendNode(node) {
6135
+ let result = ExpressionEquals;
6136
+ const [leftExpression, rightExpression] = node.expressions;
6137
+ if (!delegate.equals(leftExpression, rightExpression)) {
6138
+ const expression1 = delegate.describe(leftExpression);
6139
+ if (expression1.kind !== ExpressionKind.Leaf) {
6140
+ const [calculation, expressions] = expendExpression(expression1, false);
6141
+ node.expressions = null;
6142
+ node.calculation = calculation;
6143
+ for (const [index, childExpression] of expressions.entries()) extendQueue.push({
6144
+ parent: {
6145
+ node,
6146
+ index
6147
+ },
6148
+ swapped: node.swapped,
6149
+ expressions: [childExpression, rightExpression],
6150
+ calculation: null
6151
+ });
6152
+ return;
6153
+ }
6154
+ const expression2 = delegate.describe(rightExpression);
6155
+ if (expression2.kind !== ExpressionKind.Leaf) {
6156
+ const [calculation, expressions] = expendExpression(expression2, true);
6157
+ node.expressions = null;
6158
+ node.calculation = calculation;
6159
+ for (const [index, childExpression] of expressions.entries()) extendQueue.push({
6160
+ parent: {
6161
+ node,
6162
+ index
6163
+ },
6164
+ swapped: !node.swapped,
6165
+ expressions: [childExpression, leftExpression],
6166
+ calculation: null
6167
+ });
6168
+ return;
6169
+ }
6170
+ result = delegate.calculate(leftExpression, rightExpression);
6171
+ delegate.observeCalculation?.(leftExpression, rightExpression, result, node.swapped);
6172
+ if (result === 0) throw new Error("cannot response expression as none");
6173
+ }
6174
+ node.expressions = null;
6175
+ node.calculation = {
6176
+ operator: CalculatorOperator.Save,
6177
+ results: [result],
6178
+ willSwap: false,
6179
+ count: 0
6180
+ };
6181
+ calculateQueue.push(node);
6182
+ }
6183
+ function expendExpression(description, willSwap) {
6184
+ let operator = CalculatorOperator.Save;
6185
+ let expressions;
6186
+ switch (description.kind) {
6187
+ case ExpressionKind.Not:
6188
+ operator = CalculatorOperator.Not;
6189
+ expressions = [description.expression];
6190
+ break;
6191
+ case ExpressionKind.AllOf:
6192
+ operator = CalculatorOperator.AllOf;
6193
+ expressions = [...description.expressions];
6194
+ break;
6195
+ case ExpressionKind.AnyOf:
6196
+ operator = CalculatorOperator.AnyOf;
6197
+ expressions = [...description.expressions];
6198
+ break;
6199
+ case ExpressionKind.OneOf:
6200
+ operator = CalculatorOperator.OneOf;
6201
+ expressions = [...description.expressions];
6202
+ break;
6203
+ default: throw new Error(`invalid kind ${description.kind}`);
6204
+ }
6205
+ return [{
6206
+ operator,
6207
+ willSwap,
6208
+ count: 0,
6209
+ results: Array(expressions.length).fill(-1)
6210
+ }, expressions];
6211
+ }
6212
+ function calculateNode(node) {
6213
+ const calculation = node.calculation;
6214
+ const parent = node.parent;
6215
+ let result = calculate(calculation.operator, calculation.results);
6216
+ if (result === 0) result = ExpressionContainedBy;
6217
+ if (calculation.willSwap) result = swap(result);
6218
+ if (parent) {
6219
+ const parentCalculation = parent.node.calculation;
6220
+ const parentResults = parentCalculation.results;
6221
+ parentResults[parent.index] = result;
6222
+ parentCalculation.count += 1;
6223
+ if (parentCalculation.count >= parentResults.length) calculateQueue.push(parent.node);
6224
+ }
6225
+ }
6226
+ const result = rootNode.calculation.results[0];
6227
+ if (result === 0) throw new Error("cannot find result of root");
6228
+ return result;
5665
6229
  };
5666
- var capability = union([
5667
- strictObject({
5668
- kind: literal("connector"),
5669
- action: text,
5670
- connectionId: text.optional(),
5671
- connections: array(strictObject({
5672
- connectionId: text,
5673
- alias: text.optional()
5674
- }))
5675
- }),
5676
- strictObject({
5677
- kind: literal("connector"),
5678
- mode: literal("shared")
5679
- }),
5680
- strictObject({
5681
- kind: literal("connector"),
5682
- mode: literal("independent"),
5683
- actions: array(strictObject({
5684
- action: text,
5685
- connectionId: text.optional()
5686
- }))
5687
- }),
5688
- strictObject({
5689
- kind: literal("connector"),
5690
- actionHints: array(text).optional(),
5691
- connectionHints: array(strictObject({
5692
- action: text,
5693
- connectionId: text,
5694
- alias: text.optional()
5695
- })).optional()
5696
- })
6230
+ //#endregion
6231
+ //#region src/json-schema-subset/error.ts
6232
+ var SchemaError = class extends Error {
6233
+ constructor(items = []) {
6234
+ super(createSchemaErrorMessage(items));
6235
+ this.name = "SchemaError";
6236
+ this.items = items;
6237
+ }
6238
+ };
6239
+ var SchemaErrorItemKind = Object.freeze({
6240
+ Compiled: 0,
6241
+ External: 1
6242
+ });
6243
+ function stringifySchemaError(errorItem) {
6244
+ switch (errorItem.kind) {
6245
+ case SchemaErrorItemKind.Compiled: {
6246
+ const { message, path } = errorItem;
6247
+ return `${message} (at ${path.length > 0 ? path.join(".") : "$root"})`;
6248
+ }
6249
+ case SchemaErrorItemKind.External: return String(errorItem.error);
6250
+ }
6251
+ }
6252
+ function createSchemaErrorMessage(items) {
6253
+ switch (items.length) {
6254
+ case 0: return "without any items";
6255
+ case 1: return stringifySchemaError(items[0]);
6256
+ default: return `${stringifySchemaError(items[0])} ... omit the rest ${items.length - 1} items`;
6257
+ }
6258
+ }
6259
+ //#endregion
6260
+ //#region src/json-schema-subset/compiler/common.ts
6261
+ var jsonSchemaKeys = /* @__PURE__ */ new Set([
6262
+ "type",
6263
+ "enum",
6264
+ "const",
6265
+ "multipleOf",
6266
+ "maximum",
6267
+ "exclusiveMaximum",
6268
+ "minimum",
6269
+ "exclusiveMinimum",
6270
+ "maxLength",
6271
+ "minLength",
6272
+ "pattern",
6273
+ "items",
6274
+ "additionalItems",
6275
+ "maxItems",
6276
+ "minItems",
6277
+ "uniqueItems",
6278
+ "contains",
6279
+ "maxProperties",
6280
+ "minProperties",
6281
+ "required",
6282
+ "properties",
6283
+ "patternProperties",
6284
+ "additionalProperties",
6285
+ "dependencies",
6286
+ "propertyNames",
6287
+ "if",
6288
+ "then",
6289
+ "else",
6290
+ "allOf",
6291
+ "anyOf",
6292
+ "oneOf",
6293
+ "not",
6294
+ "format",
6295
+ "contentMediaType",
6296
+ "contentEncoding",
6297
+ "definitions"
5697
6298
  ]);
5698
- var inline = object({
5699
- ...ports,
5700
- name: text,
5701
- moduleId: text,
5702
- capabilities: array(capability).optional()
6299
+ function isJSONSchemaKey(key) {
6300
+ return jsonSchemaKeys.has(key);
6301
+ }
6302
+ function isLogicEmptyObject(object) {
6303
+ for (const key in object) if (isJSONSchemaKey(key)) return false;
6304
+ return true;
6305
+ }
6306
+ function joinPath(context, ...extraPath) {
6307
+ return {
6308
+ ...context,
6309
+ path: [...context.path, ...extraPath]
6310
+ };
6311
+ }
6312
+ function unwrapJSONSchema7Definition(schema) {
6313
+ if (typeof schema === "boolean") throw new Error("JSONSchema7Definition cannot be boolean");
6314
+ return schema;
6315
+ }
6316
+ function recordError({ path, errors }, message, ...extraPath) {
6317
+ errors.push(createSchemaError(path, extraPath, message));
6318
+ }
6319
+ function recordWarn({ path, warns }, message, ...extraPath) {
6320
+ warns.push(createSchemaError(path, extraPath, message));
6321
+ }
6322
+ function createSchemaError(path, extraPath, message) {
6323
+ return {
6324
+ kind: SchemaErrorItemKind.Compiled,
6325
+ message,
6326
+ path: [...path, ...extraPath]
6327
+ };
6328
+ }
6329
+ //#endregion
6330
+ //#region src/json-schema-subset/compiler/utils.ts
6331
+ function cleanEmptyValues(origin) {
6332
+ for (const key in origin) {
6333
+ const value = origin[key];
6334
+ if (value === void 0) delete origin[key];
6335
+ else if (value && typeof value === "object") {
6336
+ if (Array.isArray(value)) {
6337
+ if (value.length === 0) delete origin[key];
6338
+ } else if (isEmptyObject(value)) delete origin[key];
6339
+ }
6340
+ }
6341
+ return origin;
6342
+ }
6343
+ function isEmptyObject(object) {
6344
+ for (const _ in object) return false;
6345
+ return true;
6346
+ }
6347
+ //#endregion
6348
+ //#region src/json-schema-subset/compiler/wrapper.ts
6349
+ var symbolID = Symbol("compiledId");
6350
+ var symbolKind = Symbol("compiledKind");
6351
+ var symbolPath = Symbol("compiledPath");
6352
+ var symbolValidatorLoader = Symbol("validatorLoader");
6353
+ var CompiledKind = Object.freeze({
6354
+ Extends: 0,
6355
+ Never: 1,
6356
+ Any: 2,
6357
+ Null: 3,
6358
+ String: 4,
6359
+ Numeric: 5,
6360
+ Boolean: 6,
6361
+ Object: 7,
6362
+ Array: 8,
6363
+ Not: 9,
6364
+ Combination: 10,
6365
+ EnumOrConst: 11
6366
+ });
6367
+ var ANY = deepFreeze(toCompiledSchema(CompiledKind.Any, createId(), {}, () => () => true));
6368
+ var NEVER = deepFreeze(toCompiledSchema(CompiledKind.Never, createId(), {
6369
+ type: "string",
6370
+ maxLength: 0,
6371
+ minLength: 1
6372
+ }, () => () => false));
6373
+ function isCompiledObject(value) {
6374
+ if (value === null || typeof value !== "object") return false;
6375
+ return symbolID in value;
6376
+ }
6377
+ function isCompiledSchema(object) {
6378
+ if (object === null || typeof object !== "object") return false;
6379
+ return symbolID in object && symbolKind in object;
6380
+ }
6381
+ function getKind(schema) {
6382
+ if (isCompiledSchema(schema)) return schema[symbolKind];
6383
+ else return CompiledKind.Extends;
6384
+ }
6385
+ function getId(schema) {
6386
+ if (isCompiledSchema(schema) || isCompiledObject(schema)) return schema[symbolID];
6387
+ else return schema.id;
6388
+ }
6389
+ function getPath(schema) {
6390
+ return isCompiledSchema(schema) ? schema[symbolPath] : void 0;
6391
+ }
6392
+ function wrapCompiledValue(value) {
6393
+ if (value === null || typeof value !== "object") return value;
6394
+ Object.defineProperty(value, symbolID, {
6395
+ value: createId(),
6396
+ configurable: false,
6397
+ writable: false,
6398
+ enumerable: false
6399
+ });
6400
+ return value;
6401
+ }
6402
+ function wrapCompiledSchema(kind, schema, delegate, path = []) {
6403
+ return toCompiledSchema(kind, createId(), schema, delegate && (() => {
6404
+ return delegate.compile(schema);
6405
+ }), path);
6406
+ }
6407
+ function toNever(schema) {
6408
+ return toCompiledSchema(CompiledKind.Never, createId(), { ...schema }, schema[symbolValidatorLoader], schema[symbolPath]);
6409
+ }
6410
+ function toCompiledSchema(kind, id, schema, validatorLoader, path = []) {
6411
+ let validator = null;
6412
+ Object.defineProperties(schema, {
6413
+ [symbolKind]: {
6414
+ value: kind,
6415
+ configurable: false,
6416
+ writable: false,
6417
+ enumerable: false
6418
+ },
6419
+ [symbolID]: {
6420
+ value: id,
6421
+ configurable: false,
6422
+ writable: false,
6423
+ enumerable: false
6424
+ },
6425
+ [symbolPath]: {
6426
+ value: path,
6427
+ configurable: false,
6428
+ writable: false,
6429
+ enumerable: false
6430
+ },
6431
+ [symbolValidatorLoader]: {
6432
+ value: validatorLoader,
6433
+ configurable: false,
6434
+ writable: false,
6435
+ enumerable: false
6436
+ },
6437
+ isValid: {
6438
+ configurable: false,
6439
+ enumerable: false,
6440
+ get: () => {
6441
+ if (validatorLoader) {
6442
+ if (!validator) validator = validatorLoader();
6443
+ return validator;
6444
+ } else return;
6445
+ }
6446
+ }
6447
+ });
6448
+ return schema;
6449
+ }
6450
+ //#endregion
6451
+ //#region src/json-schema-subset/compiler/array.ts
6452
+ function compileArraySchema(context, schema) {
6453
+ let items = compileItems(context, schema);
6454
+ let maxItems = getItemsLimit(context, "maxItems", schema);
6455
+ const minItems = getItemsLimit(context, "minItems", schema);
6456
+ const contains = compileContains(context, schema);
6457
+ const uniqueItems = schema.uniqueItems;
6458
+ let additionalItems;
6459
+ if (Array.isArray(items)) additionalItems = compileAdditionalItems(context, schema);
6460
+ else if (schema.additionalItems) recordWarn(context, "it is needless when items is not array", "additionalItems");
6461
+ if (!items || !contains || additionalItems === null) return null;
6462
+ let isNever = false;
6463
+ let updateMaxItems = false;
6464
+ if (Array.isArray(items)) {
6465
+ if (maxItems !== void 0 && maxItems <= items.length) {
6466
+ items = items.splice(maxItems);
6467
+ additionalItems = variableToNever(additionalItems, context.delegate);
6468
+ }
6469
+ const firstNeverItemIndex = items.findIndex((item) => getKind(item) === CompiledKind.Never);
6470
+ if (firstNeverItemIndex !== -1) {
6471
+ items = items.splice(firstNeverItemIndex);
6472
+ additionalItems = variableToNever(additionalItems, context.delegate);
6473
+ if (maxItems === void 0) {
6474
+ maxItems = items.length;
6475
+ updateMaxItems = true;
6476
+ }
6477
+ }
6478
+ if (minItems !== void 0 && items.length < minItems) {
6479
+ recordWarn(context, `length(${items.length}) of items if less than minItems(${minItems})`);
6480
+ isNever = true;
6481
+ }
6482
+ if (items.length === 0 && additionalItems && getKind(additionalItems) === CompiledKind.Never) isNever = true;
6483
+ } else if (getKind(items) === CompiledKind.Never) isNever = true;
6484
+ if (maxItems !== void 0 && minItems !== void 0 && maxItems < minItems) {
6485
+ if (!updateMaxItems) recordWarn(context, `maxItems(${maxItems}) is less than minItems(${minItems})`);
6486
+ isNever = true;
6487
+ }
6488
+ return wrapCompiledSchema(isNever ? CompiledKind.Never : CompiledKind.Array, cleanEmptyValues({
6489
+ type: "array",
6490
+ items,
6491
+ contains,
6492
+ uniqueItems,
6493
+ maxItems,
6494
+ minItems,
6495
+ additionalItems
6496
+ }), context.delegate, context.path);
6497
+ }
6498
+ function compileItems(context, { items }) {
6499
+ if (!items) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6500
+ if (Array.isArray(items)) {
6501
+ const schemas = [];
6502
+ let hasAnyError = false;
6503
+ for (const [i, item] of items.entries()) {
6504
+ const schema = compileSchema(joinPath(context, "items", i), unwrapJSONSchema7Definition(item));
6505
+ if (!schema) {
6506
+ hasAnyError = true;
6507
+ continue;
6508
+ }
6509
+ schemas.push(schema);
6510
+ }
6511
+ if (hasAnyError) return null;
6512
+ return schemas;
6513
+ } else return compileSchema(joinPath(context, "items"), unwrapJSONSchema7Definition(items));
6514
+ }
6515
+ function getItemsLimit(context, name, schema) {
6516
+ const propertiesLimit = schema[name];
6517
+ if (propertiesLimit === void 0) return;
6518
+ if (Number.isNaN(propertiesLimit)) {
6519
+ recordWarn(context, "find NaN", name);
6520
+ return;
6521
+ }
6522
+ if (propertiesLimit < 0) {
6523
+ recordWarn(context, `find invalid number ${propertiesLimit}`, name);
6524
+ return;
6525
+ }
6526
+ return propertiesLimit;
6527
+ }
6528
+ function compileContains(context, { contains }) {
6529
+ if (!contains) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6530
+ return compileSchema(joinPath(context, "contains"), unwrapJSONSchema7Definition(contains));
6531
+ }
6532
+ function compileAdditionalItems(context, { additionalItems }) {
6533
+ switch (typeof additionalItems) {
6534
+ case "boolean": if (additionalItems) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6535
+ else return false;
6536
+ case "object": return compileSchema(joinPath(context, "additionalItems"), additionalItems);
6537
+ default: return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6538
+ }
6539
+ }
6540
+ function variableToNever(schema, delegate) {
6541
+ if (schema === void 0) return wrapCompiledSchema(CompiledKind.Never, {
6542
+ type: "string",
6543
+ maxLength: 0,
6544
+ minLength: 1
6545
+ }, delegate);
6546
+ else if (isCompiledSchema(schema)) return getKind(schema) === CompiledKind.Never ? schema : toNever(schema);
6547
+ else return schema;
6548
+ }
6549
+ //#endregion
6550
+ //#region src/json-schema-subset/compiler/combination.ts
6551
+ var COMBINATION_KEYS = Object.freeze([
6552
+ "allOf",
6553
+ "anyOf",
6554
+ "oneOf"
6555
+ ]);
6556
+ function compileCombinationSchema(context, key, combinationList, delegate) {
6557
+ if (combinationList.length === 0) {
6558
+ recordError(context, "disable empty list", key);
6559
+ return null;
6560
+ }
6561
+ const compiledCombinationList = [];
6562
+ for (const [i, element] of combinationList.entries()) {
6563
+ const compiledSchema = compileSchema(joinPath(context, key, i), unwrapJSONSchema7Definition(element));
6564
+ if (compiledSchema) compiledCombinationList.push(compiledSchema);
6565
+ }
6566
+ if (compiledCombinationList.length < combinationList.length) return null;
6567
+ let anyCount = 0;
6568
+ let neverCount = 0;
6569
+ for (const compiledSchema of compiledCombinationList) switch (getKind(compiledSchema)) {
6570
+ case CompiledKind.Any:
6571
+ anyCount += 1;
6572
+ break;
6573
+ case CompiledKind.Never: neverCount += 1;
6574
+ }
6575
+ let kind = CompiledKind.Combination;
6576
+ switch (key) {
6577
+ case "allOf":
6578
+ if (neverCount > 0) kind = CompiledKind.Never;
6579
+ else if (anyCount === compiledCombinationList.length) kind = CompiledKind.Any;
6580
+ else if (!areAllTypesTheSame(compiledCombinationList)) kind = CompiledKind.Never;
6581
+ break;
6582
+ case "anyOf":
6583
+ if (anyCount > 0) kind = CompiledKind.Any;
6584
+ else if (neverCount === compiledCombinationList.length) kind = CompiledKind.Never;
6585
+ break;
6586
+ case "oneOf": if (anyCount > 1) kind = CompiledKind.Never;
6587
+ else if (neverCount === compiledCombinationList.length) kind = CompiledKind.Never;
6588
+ else if (anyCount === 1 && neverCount === compiledCombinationList.length - 1) kind = CompiledKind.Any;
6589
+ }
6590
+ return wrapCompiledSchema(kind, { [key]: compiledCombinationList }, delegate, context.path);
6591
+ }
6592
+ function areAllTypesTheSame(combinationList) {
6593
+ let lastKind = null;
6594
+ for (const schema of combinationList) {
6595
+ const kind = getKind(schema);
6596
+ switch (kind) {
6597
+ case CompiledKind.Any:
6598
+ case CompiledKind.Never: break;
6599
+ default: if (lastKind === null) lastKind = kind;
6600
+ else if (lastKind !== kind) return false;
6601
+ }
6602
+ }
6603
+ return true;
6604
+ }
6605
+ //#endregion
6606
+ //#region src/json-schema-subset/checker/validator.ts
6607
+ var ValidResult = Object.freeze({
6608
+ Valid: 0,
6609
+ Invalid: 1,
6610
+ Unknown: 2
6611
+ });
6612
+ function valid(compiledSchema, value) {
6613
+ const isValid = compiledSchema.isValid;
6614
+ if (isValid) {
6615
+ if (isValid(value) === true) return ValidResult.Valid;
6616
+ else return ValidResult.Invalid;
6617
+ } else return ValidResult.Unknown;
6618
+ }
6619
+ //#endregion
6620
+ //#region src/json-schema-subset/compiler/enumAndConst.ts
6621
+ function compileEnumAndConst(context, enumList, constValue, schema) {
6622
+ let compiledEnum;
6623
+ let isNever = false;
6624
+ if (enumList) {
6625
+ if (enumList.length === 0) {
6626
+ recordError(context, "disable empty list", "enum");
6627
+ return null;
6628
+ }
6629
+ compiledEnum = [];
6630
+ for (const [i, enumValue] of enumList.entries()) switch (valid(schema, enumValue)) {
6631
+ case ValidResult.Valid:
6632
+ compiledEnum.push(wrapCompiledValue(enumValue));
6633
+ break;
6634
+ case ValidResult.Invalid: recordWarn(context, "cannot pass JSON schema of currently schema object", "enum", i);
6635
+ }
6636
+ if (compiledEnum.length === 0) recordWarn(context, "all of elements from list is rejected by currently schema object", "enum");
6637
+ }
6638
+ if (constValue && valid(schema, constValue) === ValidResult.Invalid) isNever = true;
6639
+ if (compiledEnum) {
6640
+ if (compiledEnum.length === 0) isNever = true;
6641
+ else if (constValue) {
6642
+ let foundEquals = false;
6643
+ for (const enumValue of compiledEnum) if (isDeepEquals(enumValue, constValue)) {
6644
+ foundEquals = true;
6645
+ break;
6646
+ }
6647
+ if (!foundEquals) isNever = true;
6648
+ }
6649
+ }
6650
+ const kind = isNever ? CompiledKind.Never : CompiledKind.EnumOrConst;
6651
+ const compiledSchema = {};
6652
+ if (schema.type) compiledSchema.type = schema.type;
6653
+ if (compiledEnum) compiledSchema.enum = compiledEnum;
6654
+ if (constValue) compiledSchema.const = wrapCompiledValue(deepCopy(constValue));
6655
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
6656
+ }
6657
+ //#endregion
6658
+ //#region src/json-schema-subset/compiler/object.ts
6659
+ var OBJECT_KEYS = /* @__PURE__ */ new Set([
6660
+ "type",
6661
+ "maxProperties",
6662
+ "minProperties",
6663
+ "required",
6664
+ "properties",
6665
+ "patternProperties",
6666
+ "additionalProperties",
6667
+ "dependencies",
6668
+ "propertyNames"
6669
+ ]);
6670
+ function compileObjectSchema(context, schema) {
6671
+ const rejectKeys = Object.keys(schema).filter((k) => !OBJECT_KEYS.has(k) && isJSONSchemaKey(k));
6672
+ if (rejectKeys.length > 0) recordWarn(context, `type="object" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
6673
+ const maxProperties = getPropertiesLimit(context, "maxProperties", schema);
6674
+ const minProperties = getPropertiesLimit(context, "minProperties", schema);
6675
+ const additionalPropertiesSchema = compileAdditionalProperties(context, schema);
6676
+ const patternProperties = compilePatternProperties(context, schema);
6677
+ const propertyNames = compilePropertyNames(context, schema);
6678
+ const dependentTuple = compileDependencies(context, schema);
6679
+ if (!additionalPropertiesSchema || !patternProperties || !propertyNames || !dependentTuple) return null;
6680
+ const properties = compileProperties(context, patternProperties, propertyNames, schema);
6681
+ if (!properties) return null;
6682
+ const required = compileRequired(context, createBanKeyChecker(additionalPropertiesSchema, patternProperties, propertyNames, properties), dependentTuple, schema);
6683
+ return wrapCompiledSchema(checkSchemaIsNever(context, additionalPropertiesSchema, properties, required, maxProperties, minProperties) ? CompiledKind.Never : CompiledKind.Object, cleanEmptyValues({
6684
+ type: "object",
6685
+ required,
6686
+ properties,
6687
+ minProperties,
6688
+ maxProperties,
6689
+ additionalProperties: additionalPropertiesSchema,
6690
+ patternProperties: unwrapPatternProperties(patternProperties),
6691
+ dependencies: mergeDependentTuple(dependentTuple, schema),
6692
+ propertyNames
6693
+ }), context.delegate, context.path);
6694
+ }
6695
+ function getPropertiesLimit(context, name, schema) {
6696
+ const propertiesLimit = schema[name];
6697
+ if (propertiesLimit === void 0) return;
6698
+ if (Number.isNaN(propertiesLimit)) {
6699
+ recordWarn(context, "find NaN", name);
6700
+ return;
6701
+ }
6702
+ if (propertiesLimit < 0) {
6703
+ recordWarn(context, `find invalid number ${propertiesLimit}`, name);
6704
+ return;
6705
+ }
6706
+ return propertiesLimit;
6707
+ }
6708
+ function compileAdditionalProperties(context, { additionalProperties }) {
6709
+ if (additionalProperties === false) return wrapCompiledSchema(CompiledKind.Never, {
6710
+ type: "string",
6711
+ maxLength: 0,
6712
+ minLength: 1
6713
+ }, context.delegate, context.path);
6714
+ if (typeof additionalProperties !== "object") return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6715
+ return compileSchema(joinPath(context, "additionalProperties"), unwrapJSONSchema7Definition(additionalProperties));
6716
+ }
6717
+ function compilePatternProperties(context, { patternProperties }) {
6718
+ let foundSubError = false;
6719
+ const target = {};
6720
+ for (const key in patternProperties) {
6721
+ const regExp = wrapRegExp(key);
6722
+ if (regExp instanceof Error) {
6723
+ recordWarn(context, `property name invalid. ${key}`, "patternProperties", key);
6724
+ continue;
6725
+ }
6726
+ const schema = unwrapJSONSchema7Definition(patternProperties[key]);
6727
+ const compiledSchema = compileSchema(joinPath(context, "patternProperties", key), schema);
6728
+ if (!compiledSchema) {
6729
+ foundSubError = true;
6730
+ continue;
6731
+ }
6732
+ target[key] = [compiledSchema, regExp];
6733
+ }
6734
+ if (foundSubError) return null;
6735
+ return target;
6736
+ }
6737
+ function compilePropertyNames(context, { propertyNames }) {
6738
+ if (!propertyNames) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6739
+ propertyNames = unwrapJSONSchema7Definition(propertyNames);
6740
+ const schema = compileSchema(joinPath(context, "propertyNames"), propertyNames);
6741
+ if (!schema) return null;
6742
+ const kind = getKind(schema);
6743
+ if (kind !== CompiledKind.String && kind !== CompiledKind.Any) return toNever(schema);
6744
+ return schema;
6745
+ }
6746
+ function compileProperties(context, patternProperties, propertyNamesSchema, { properties }) {
6747
+ let foundSubError = false;
6748
+ if (!properties) return {};
6749
+ const target = {};
6750
+ for (const key in properties) {
6751
+ if (valid(propertyNamesSchema, key) === ValidResult.Invalid) {
6752
+ recordWarn(context, `key ${JSON.stringify(key)} cannot pass JSON schema from propertyNames`, "properties");
6753
+ continue;
6754
+ }
6755
+ const patternSchema = findPatternSchema(patternProperties, key);
6756
+ if (patternSchema && getKind(patternSchema) === CompiledKind.Never) {
6757
+ recordWarn(context, `key ${JSON.stringify(key)} matches a pattern that has a impossible(never) schema`, "properties");
6758
+ continue;
6759
+ }
6760
+ const schema = unwrapJSONSchema7Definition(properties[key]);
6761
+ const compiledSchema = compileSchema(joinPath(context, "properties", key), schema);
6762
+ if (!compiledSchema) {
6763
+ foundSubError = true;
6764
+ continue;
6765
+ }
6766
+ target[key] = compiledSchema;
6767
+ }
6768
+ if (foundSubError) return null;
6769
+ return target;
6770
+ }
6771
+ function compileDependencies(context, { dependencies }) {
6772
+ if (!dependencies) return [{}, {}];
6773
+ const dependentRequired = {};
6774
+ const dependentSchemas = {};
6775
+ for (const key in dependencies) {
6776
+ const dependency = unwrapJSONSchema7Definition(dependencies[key]);
6777
+ if (Array.isArray(dependency)) {
6778
+ const { keys, duplicated } = checkUniqueKeys(dependency);
6779
+ if (duplicated) recordWarn(context, `found duplicated property names: ${duplicated.join(", ")}`, "dependencies", key);
6780
+ dependentRequired[key] = keys;
6781
+ } else {
6782
+ const compiledSchema = compileSchema(joinPath(context, "dependencies", key), dependency);
6783
+ if (compiledSchema) {
6784
+ const kind = getKind(compiledSchema);
6785
+ if (kind === CompiledKind.Object || kind === CompiledKind.Any) dependentSchemas[key] = compiledSchema;
6786
+ else if (kind === CompiledKind.Extends) dependentSchemas[key] = NEVER;
6787
+ else dependentSchemas[key] = toNever(compiledSchema);
6788
+ }
6789
+ }
6790
+ }
6791
+ return [dependentRequired, dependentSchemas];
6792
+ }
6793
+ function createBanKeyChecker(additionalPropertiesSchema, patternProperties, propertyNamesSchema, properties) {
6794
+ return (key) => {
6795
+ if (valid(propertyNamesSchema, key) === ValidResult.Invalid) return true;
6796
+ const patternSchema = findPatternSchema(patternProperties, key);
6797
+ if (patternSchema && getKind(patternSchema) === CompiledKind.Never) return true;
6798
+ if (getKind(properties[key] ?? additionalPropertiesSchema) === CompiledKind.Never) return true;
6799
+ return false;
6800
+ };
6801
+ }
6802
+ function compileRequired(context, isBan, dependentTuple, { required }) {
6803
+ if (!required) return [];
6804
+ const uniqueCheckedResult = checkUniqueKeys(required);
6805
+ if (uniqueCheckedResult.duplicated) recordWarn(context, `found duplicated required keys: ${uniqueCheckedResult.duplicated.join(", ")}`, "required");
6806
+ const requiredKeys = [];
6807
+ const banKeys = [];
6808
+ for (const requiredKey of uniqueCheckedResult.keys) if (collectDependencies(dependentTuple, requiredKey).some((key) => isBan(key))) banKeys.push(requiredKey);
6809
+ else requiredKeys.push(requiredKey);
6810
+ if (banKeys.length > 0) recordWarn(context, `key ${banKeys.map((k) => JSON.stringify(k)).join(", ")} will ban by another condition`, "required");
6811
+ return requiredKeys;
6812
+ }
6813
+ function checkSchemaIsNever(context, additionalPropertiesSchema, properties, required, maxProperties, minProperties) {
6814
+ if (maxProperties !== void 0 && minProperties !== void 0 && maxProperties < minProperties) {
6815
+ recordWarn(context, `maxProperties(${maxProperties}) is less than minProperties(${minProperties})`);
6816
+ return true;
6817
+ }
6818
+ if (maxProperties !== void 0 && required.length > maxProperties) {
6819
+ recordWarn(context, `length(${required.length}) of required is greater than maxProperties(${maxProperties})`);
6820
+ return true;
6821
+ }
6822
+ if (minProperties !== void 0 && required.length < minProperties) {
6823
+ recordWarn(context, `length(${required.length}) of required is less than minProperties(${minProperties})`);
6824
+ return true;
6825
+ }
6826
+ if (getKind(additionalPropertiesSchema) !== CompiledKind.Never) return false;
6827
+ for (const key in properties) {
6828
+ const compiledSchema = properties[key];
6829
+ if (getKind(compiledSchema) !== CompiledKind.Never) return false;
6830
+ }
6831
+ return true;
6832
+ }
6833
+ function collectDependencies([dependentRequired, dependentSchemas], seedKey) {
6834
+ const queue = [seedKey];
6835
+ const collection = new Set(queue);
6836
+ while (queue.length > 0) {
6837
+ const key = queue.pop();
6838
+ const schema = dependentSchemas[key];
6839
+ const requiredKeys = dependentRequired[key];
6840
+ if (schema) {
6841
+ if (getKind(schema) === CompiledKind.Object) collectKeys(schema.required);
6842
+ }
6843
+ if (requiredKeys) collectKeys(requiredKeys);
6844
+ }
6845
+ function collectKeys(keys) {
6846
+ if (keys) {
6847
+ for (const key of keys) if (!collection.has(key)) {
6848
+ collection.add(key);
6849
+ queue.push(key);
6850
+ }
6851
+ }
6852
+ }
6853
+ return [...collection];
6854
+ }
6855
+ function checkUniqueKeys(keys) {
6856
+ const checking = /* @__PURE__ */ new Set();
6857
+ const duplicated = /* @__PURE__ */ new Set();
6858
+ for (const e of keys) if (checking.has(e)) duplicated.add(e);
6859
+ else checking.add(e);
6860
+ if (duplicated.size === 0) return {
6861
+ keys: [...keys],
6862
+ duplicated: null
6863
+ };
6864
+ else return {
6865
+ keys: [...checking],
6866
+ duplicated: [...duplicated]
6867
+ };
6868
+ }
6869
+ function findPatternSchema(patternProperties, checkedKey) {
6870
+ for (const key in patternProperties) {
6871
+ const [schema, regExp] = patternProperties[key];
6872
+ if (regExp.test(checkedKey)) return schema;
6873
+ }
6874
+ return null;
6875
+ }
6876
+ function wrapRegExp(pattern) {
6877
+ try {
6878
+ return new RegExp(pattern, "i");
6879
+ } catch (error) {
6880
+ if (error instanceof SyntaxError) return error;
6881
+ else throw error;
6882
+ }
6883
+ }
6884
+ function unwrapPatternProperties(patternProperties) {
6885
+ const target = {};
6886
+ for (const key in patternProperties) target[key] = patternProperties[key][0];
6887
+ return target;
6888
+ }
6889
+ function mergeDependentTuple([dependentRequired, dependentSchemas], { dependencies }) {
6890
+ const target = {};
6891
+ for (const key in dependencies) {
6892
+ const required = dependentRequired[key];
6893
+ const schema = dependentSchemas[key];
6894
+ target[key] = required || schema;
6895
+ }
6896
+ return target;
6897
+ }
6898
+ //#endregion
6899
+ //#region src/json-schema-subset/compiler/primitive.ts
6900
+ var NUMERIC_KEYS = /* @__PURE__ */ new Set([
6901
+ "type",
6902
+ "multipleOf",
6903
+ "maximum",
6904
+ "exclusiveMaximum",
6905
+ "minimum",
6906
+ "exclusiveMinimum"
6907
+ ]);
6908
+ var STRING_KEYS = /* @__PURE__ */ new Set([
6909
+ "type",
6910
+ "format",
6911
+ "maxLength",
6912
+ "minLength",
6913
+ "pattern"
6914
+ ]);
6915
+ function compilePrimitiveSchema(context, schema) {
6916
+ const { type } = schema;
6917
+ switch (type) {
6918
+ case "number":
6919
+ case "integer": return compileNumericSchema(context, schema);
6920
+ case "string": return compileStringSchema(context, schema);
6921
+ case "boolean":
6922
+ case "null": {
6923
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== "type");
6924
+ if (rejectKeys.length > 0) recordWarn(context, `key "type" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
6925
+ return wrapCompiledSchema(type === "null" ? CompiledKind.Null : CompiledKind.Boolean, { type }, context.delegate, context.path);
6926
+ }
6927
+ default:
6928
+ recordError(context, `invalid type ${JSON.stringify(type)}`);
6929
+ return null;
6930
+ }
6931
+ }
6932
+ function compileNumericSchema(context, schema) {
6933
+ const rejectKeys = Object.keys(schema).filter((k) => !NUMERIC_KEYS.has(k) && isJSONSchemaKey(k));
6934
+ if (rejectKeys.length > 0) recordWarn(context, `type=${JSON.stringify(schema.type)} will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
6935
+ const compiledSchema = pick(schema, NUMERIC_KEYS);
6936
+ for (const key of NUMERIC_KEYS) {
6937
+ const value = compiledSchema[key];
6938
+ if (key !== "type" && value !== void 0 && Number.isNaN(value)) {
6939
+ recordWarn(context, "found NaN", key);
6940
+ delete compiledSchema[key];
6941
+ }
6942
+ }
6943
+ const { maximum, exclusiveMaximum, minimum, exclusiveMinimum } = compiledSchema;
6944
+ if (maximum !== void 0 && exclusiveMaximum !== void 0) {
6945
+ if (maximum === exclusiveMaximum) delete compiledSchema.maximum;
6946
+ else if (maximum < exclusiveMaximum) delete compiledSchema.exclusiveMaximum;
6947
+ else if (maximum > exclusiveMaximum) delete compiledSchema.maximum;
6948
+ }
6949
+ if (minimum !== void 0 && exclusiveMinimum !== void 0) {
6950
+ if (minimum === exclusiveMinimum) delete compiledSchema.minimum;
6951
+ else if (minimum < exclusiveMinimum) delete compiledSchema.exclusiveMinimum;
6952
+ else if (minimum > exclusiveMinimum) delete compiledSchema.minimum;
6953
+ }
6954
+ const { multipleOf } = compiledSchema;
6955
+ if (multipleOf === 0) {
6956
+ delete compiledSchema.multipleOf;
6957
+ compiledSchema.type = "number";
6958
+ recordWarn(context, "cannot be 0", "multipleOf");
6959
+ }
6960
+ let kind = CompiledKind.Numeric;
6961
+ if (!isNumericPossibleInvalid(compiledSchema)) kind = CompiledKind.Never;
6962
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
6963
+ }
6964
+ function isNumericPossibleInvalid(compiledSchema) {
6965
+ const { maximum, exclusiveMaximum, minimum, exclusiveMinimum } = compiledSchema;
6966
+ if (maximum !== void 0 && minimum !== void 0) return maximum >= minimum;
6967
+ else if (exclusiveMaximum !== void 0 && minimum !== void 0) return exclusiveMaximum > minimum;
6968
+ else if (maximum !== void 0 && exclusiveMinimum !== void 0) return maximum > exclusiveMinimum;
6969
+ else if (exclusiveMaximum !== void 0 && exclusiveMinimum !== void 0) return exclusiveMaximum > exclusiveMinimum;
6970
+ else return true;
6971
+ }
6972
+ function compileStringSchema(context, schema) {
6973
+ const rejectKeys = Object.keys(schema).filter((k) => !STRING_KEYS.has(k) && isJSONSchemaKey(k));
6974
+ if (rejectKeys.length > 0) recordWarn(context, `type="string" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
6975
+ const compiledSchema = pick(schema, STRING_KEYS);
6976
+ cleanInvalidLength(context, compiledSchema, "maxLength");
6977
+ cleanInvalidLength(context, compiledSchema, "minLength");
6978
+ const max = compiledSchema.maxLength;
6979
+ const min = compiledSchema.minLength;
6980
+ let kind = CompiledKind.String;
6981
+ if (max !== void 0) {
6982
+ if (max < 0) kind = CompiledKind.Never;
6983
+ else if (max !== void 0 && min !== void 0 && max < min) kind = CompiledKind.Never;
6984
+ }
6985
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
6986
+ }
6987
+ function cleanInvalidLength(context, compiledSchema, key) {
6988
+ const length = compiledSchema[key];
6989
+ if (length !== void 0) {
6990
+ if (Number.isNaN(length)) {
6991
+ recordWarn(context, "found NaN", key);
6992
+ delete compiledSchema[key];
6993
+ }
6994
+ }
6995
+ }
6996
+ //#endregion
6997
+ //#region src/json-schema-subset/compiler/compiler.ts
6998
+ var emptyList = Object.freeze([]);
6999
+ function compile(schema, extendsContext, payload, delegate) {
7000
+ if (isCompiledSchema(schema)) return {
7001
+ schema,
7002
+ warns: emptyList
7003
+ };
7004
+ if (extendsContext.isExtendsSchema(schema)) return {
7005
+ schema,
7006
+ warns: emptyList
7007
+ };
7008
+ if (delegate) {
7009
+ const isSchemaResult = delegate.isSchema(schema);
7010
+ if (typeof isSchemaResult === "object") {
7011
+ const items = [];
7012
+ for (const error of isSchemaResult) items.push({
7013
+ kind: SchemaErrorItemKind.External,
7014
+ error
7015
+ });
7016
+ if (items.length > 0) return items;
7017
+ } else if (isSchemaResult === false) throw new Error("it is not a JSON Schema 7");
7018
+ }
7019
+ const context = {
7020
+ delegate,
7021
+ payload,
7022
+ extends: extendsContext,
7023
+ path: [],
7024
+ errors: [],
7025
+ warns: []
7026
+ };
7027
+ const compiledSchema = compileSchema(context, schema);
7028
+ if (compiledSchema) assertCondition(context.errors.length === 0, "found errors (it should be empty)");
7029
+ else {
7030
+ assertCondition(context.errors.length > 0, "cannot found any errors");
7031
+ return context.errors;
7032
+ }
7033
+ return {
7034
+ schema: compiledSchema,
7035
+ warns: context.warns
7036
+ };
7037
+ }
7038
+ function assertCondition(condition, message) {
7039
+ if (!condition) throw new Error(message);
7040
+ }
7041
+ function compileSchema(context, schema) {
7042
+ if (context.extends.isExtendsSchema(schema)) return schema;
7043
+ if (isCompiledSchema(schema)) return schema;
7044
+ const extendsSchema = context.extends.tryCompiledExtendsSchema(schema, context.payload);
7045
+ if (extendsSchema) return extendsSchema;
7046
+ let targetSchema = schema;
7047
+ let shouldHandleEnumAndConst = false;
7048
+ const { enum: enumList, const: constValue } = schema;
7049
+ if (enumList || constValue) {
7050
+ const { enum: _0, const: _1, ...rest } = schema;
7051
+ targetSchema = rest;
7052
+ shouldHandleEnumAndConst = true;
7053
+ }
7054
+ let compiledSchema = checkAndCompileSchema(context, targetSchema);
7055
+ if (compiledSchema && shouldHandleEnumAndConst) compiledSchema = compileEnumAndConst(context, enumList, constValue, compiledSchema);
7056
+ if (!compiledSchema) return null;
7057
+ return compiledSchema;
7058
+ }
7059
+ function checkAndCompileSchema(context, schema) {
7060
+ for (const key of COMBINATION_KEYS) {
7061
+ const combinationList = schema[key];
7062
+ if (combinationList) {
7063
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== key);
7064
+ if (rejectKeys.length > 0) recordWarn(context, `composition key ${JSON.stringify(key)} will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7065
+ const compiledSchema = compileCombinationSchema(context, key, combinationList);
7066
+ if (!compiledSchema) return null;
7067
+ return compiledSchema;
7068
+ }
7069
+ }
7070
+ {
7071
+ const notSchema = unwrapJSONSchema7Definition(schema.not);
7072
+ if (notSchema) {
7073
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== "not");
7074
+ if (rejectKeys.length > 0) recordWarn(context, `key "not" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7075
+ const subSchema = compileSchema(joinPath(context, "not"), notSchema);
7076
+ if (!subSchema) return null;
7077
+ let kind = CompiledKind.Not;
7078
+ switch (getKind(subSchema)) {
7079
+ case CompiledKind.Never:
7080
+ kind = CompiledKind.Any;
7081
+ break;
7082
+ case CompiledKind.Any: kind = CompiledKind.Never;
7083
+ }
7084
+ return wrapCompiledSchema(kind, { not: subSchema }, context.delegate, context.path);
7085
+ }
7086
+ }
7087
+ if (schema.type) {
7088
+ const { type } = schema;
7089
+ if (Array.isArray(type)) {
7090
+ const { type: _type, ...rest } = schema;
7091
+ return compileCombinationSchema(context, "anyOf", type.map((item) => ({
7092
+ ...rest,
7093
+ type: item
7094
+ })));
7095
+ }
7096
+ switch (type) {
7097
+ case "object": return compileObjectSchema(context, schema);
7098
+ case "array": return compileArraySchema(context, schema);
7099
+ default: return compilePrimitiveSchema(context, schema);
7100
+ }
7101
+ }
7102
+ if (isLogicEmptyObject(schema)) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
7103
+ recordError(context, "unrecognized");
7104
+ return null;
7105
+ }
7106
+ //#endregion
7107
+ //#region src/json-schema-subset/checker/tools/mark.ts
7108
+ var VariableBundleDescription = class {
7109
+ constructor(_keys) {
7110
+ const keys = Object.freeze(_keys.toSorted());
7111
+ if (keys.length > 32) throw new Error(`cannot define ${keys.length} keys which is greater than 32`);
7112
+ this.keys = keys;
7113
+ this.clazz = class extends VariableBundleImpls {
7114
+ constructor(int32) {
7115
+ super(keys, int32);
7116
+ }
7117
+ };
7118
+ for (const [i, key] of this.keys.entries()) {
7119
+ const mask = 1 << i;
7120
+ Object.defineProperty(this.clazz.prototype, key, {
7121
+ enumerable: true,
7122
+ get: function get() {
7123
+ return !!(this.int32 & mask);
7124
+ },
7125
+ set: function set(value) {
7126
+ if (value) this.int32 |= mask;
7127
+ else this.int32 &= ~mask;
7128
+ }
7129
+ });
7130
+ }
7131
+ }
7132
+ toBundle(variable) {
7133
+ let int32 = 0;
7134
+ if (typeof variable === "number") int32 = variable;
7135
+ else if (variable) {
7136
+ for (const [i, key] of this.keys.entries()) if (variable[key]) int32 |= 1 << i;
7137
+ }
7138
+ return new this.clazz(int32);
7139
+ }
7140
+ };
7141
+ var VariableBundleImpls = class {
7142
+ constructor(keys, int32) {
7143
+ this.keys = keys;
7144
+ this.int32 = int32;
7145
+ }
7146
+ toInt32() {
7147
+ return this.int32;
7148
+ }
7149
+ toString() {
7150
+ const object = {};
7151
+ for (const key of this.keys) object[key] = this[key];
7152
+ return JSON.stringify(object);
7153
+ }
7154
+ };
7155
+ //#endregion
7156
+ //#region src/json-schema-subset/checker/tools/quantum.ts
7157
+ function makeQuantum(keys) {
7158
+ return new QuantumImpls(keys);
7159
+ }
7160
+ var QuantumImpls = class {
7161
+ constructor(keys) {
7162
+ this.description = new VariableBundleDescription(keys);
7163
+ }
7164
+ get keys() {
7165
+ return this.description.keys;
7166
+ }
7167
+ variable(variable) {
7168
+ let int32;
7169
+ if (variable) int32 = this.description.toBundle(variable).toInt32();
7170
+ return new QuantumVariableImpls(this.description, int32);
7171
+ }
7172
+ };
7173
+ var QuantumVariableImpls = class {
7174
+ constructor(description, int32) {
7175
+ this.values = /* @__PURE__ */ new Set();
7176
+ this.description = description;
7177
+ if (int32 !== void 0) this.values.add(int32);
7178
+ }
7179
+ [Symbol.iterator]() {
7180
+ const iterator = this.values[Symbol.iterator]();
7181
+ return { next: () => {
7182
+ const result = iterator.next();
7183
+ if (result.done) return result;
7184
+ else return {
7185
+ done: false,
7186
+ value: this.description.toBundle(result.value)
7187
+ };
7188
+ } };
7189
+ }
7190
+ assign(other) {
7191
+ const { values } = other;
7192
+ for (const int32 of values) this.values.add(int32);
7193
+ return this;
7194
+ }
7195
+ push(expression, calculate) {
7196
+ const nextValues = /* @__PURE__ */ new Set();
7197
+ for (const int32 of this.values) for (const [singleExpression, mask] of ExpressionMaskList) if (expression & mask) {
7198
+ const variable = this.description.toBundle(int32);
7199
+ calculate(singleExpression, variable);
7200
+ nextValues.add(variable.toInt32());
7201
+ }
7202
+ this.values = nextValues;
7203
+ }
7204
+ update(invoker) {
7205
+ const nextValues = /* @__PURE__ */ new Set();
7206
+ for (const int32 of this.values) {
7207
+ const variable = this.description.toBundle(int32);
7208
+ invoker(variable);
7209
+ nextValues.add(variable.toInt32());
7210
+ }
7211
+ this.values = nextValues;
7212
+ }
7213
+ };
7214
+ //#endregion
7215
+ //#region src/json-schema-subset/checker/tools/range.ts
7216
+ function splitRange$3(range1, range2) {
7217
+ const [min1] = range1;
7218
+ const [min2] = range2;
7219
+ if (min1.num < min2.num) return splitRangeLessBranch(range1, range2);
7220
+ else if (min1.num > min2.num) return splitRangeGreaterBranch(range1, range2);
7221
+ else return splitRangeEqualsBranch(range1, range2);
7222
+ }
7223
+ function splitRangeLessBranch(range1, range2) {
7224
+ const [min1, max1] = range1;
7225
+ const [min2, max2] = range2;
7226
+ if (max1.num <= min2.num) {
7227
+ const exclusive1 = max1.exclusive;
7228
+ const exclusive2 = min2.exclusive;
7229
+ if (max1.num < min2.num || exclusive1 || exclusive2) return {
7230
+ left: {
7231
+ fromLeft: true,
7232
+ range: range1
7233
+ },
7234
+ right: {
7235
+ fromLeft: false,
7236
+ range: range2
7237
+ }
7238
+ };
7239
+ }
7240
+ if (max1.num <= max2.num) {
7241
+ let hasRight = true;
7242
+ let isLeftRangeOverride = false;
7243
+ if (max1.num === max2.num) {
7244
+ const exclusive1 = max1.exclusive;
7245
+ const exclusive2 = max2.exclusive;
7246
+ hasRight = exclusive1 !== exclusive2;
7247
+ isLeftRangeOverride = !exclusive1 && exclusive2;
7248
+ }
7249
+ if (!isLeftRangeOverride) {
7250
+ let right;
7251
+ if (hasRight) right = {
7252
+ fromLeft: false,
7253
+ range: [reversalExclusive(max1), max2]
7254
+ };
7255
+ return {
7256
+ left: {
7257
+ fromLeft: true,
7258
+ range: [min1, reversalExclusive(min2)]
7259
+ },
7260
+ center: [min2, max1],
7261
+ right
7262
+ };
7263
+ }
7264
+ }
7265
+ return {
7266
+ left: {
7267
+ fromLeft: true,
7268
+ range: [min1, reversalExclusive(min2)]
7269
+ },
7270
+ center: [min2, max2],
7271
+ right: {
7272
+ fromLeft: true,
7273
+ range: [reversalExclusive(max2), max1]
7274
+ }
7275
+ };
7276
+ }
7277
+ function splitRangeGreaterBranch(range1, range2) {
7278
+ const [min1, max1] = range1;
7279
+ const [min2, max2] = range2;
7280
+ if (min1.num >= max2.num) {
7281
+ const exclusive1 = max2.exclusive;
7282
+ const exclusive2 = min1.exclusive;
7283
+ if (min1.num > max2.num || exclusive1 || exclusive2) return {
7284
+ left: {
7285
+ fromLeft: false,
7286
+ range: range2
7287
+ },
7288
+ right: {
7289
+ fromLeft: true,
7290
+ range: range1
7291
+ }
7292
+ };
7293
+ }
7294
+ if (max2.num <= max1.num) {
7295
+ let hasRight = true;
7296
+ let isRightRangeOverride = false;
7297
+ if (max1.num === max2.num) {
7298
+ const exclusive1 = max2.exclusive;
7299
+ const exclusive2 = max1.exclusive;
7300
+ hasRight = exclusive1 !== exclusive2;
7301
+ isRightRangeOverride = !exclusive1 && exclusive2;
7302
+ }
7303
+ if (!isRightRangeOverride) {
7304
+ let right;
7305
+ if (hasRight) right = {
7306
+ fromLeft: true,
7307
+ range: [reversalExclusive(max2), max1]
7308
+ };
7309
+ return {
7310
+ left: {
7311
+ fromLeft: false,
7312
+ range: [min2, reversalExclusive(min1)]
7313
+ },
7314
+ center: [min1, max2],
7315
+ right
7316
+ };
7317
+ }
7318
+ }
7319
+ return {
7320
+ left: {
7321
+ fromLeft: false,
7322
+ range: [min2, reversalExclusive(min1)]
7323
+ },
7324
+ center: [min1, max1],
7325
+ right: {
7326
+ fromLeft: false,
7327
+ range: [reversalExclusive(max1), max2]
7328
+ }
7329
+ };
7330
+ }
7331
+ function splitRangeEqualsBranch(range1, range2) {
7332
+ const [min1, max1] = range1;
7333
+ const [min2, max2] = range2;
7334
+ const exclusive1 = min1.exclusive;
7335
+ const exclusive2 = min2.exclusive;
7336
+ let left;
7337
+ let centerBegin = min1;
7338
+ if (!exclusive1 && exclusive2) {
7339
+ centerBegin = min2;
7340
+ left = {
7341
+ fromLeft: true,
7342
+ range: [min1, reversalExclusive(min2)]
7343
+ };
7344
+ } else if (exclusive1 && !exclusive2) left = {
7345
+ fromLeft: false,
7346
+ range: [min2, reversalExclusive(min1)]
7347
+ };
7348
+ if (max1.num <= max2.num) {
7349
+ let hasRight = true;
7350
+ let isLeftRangeOverride = false;
7351
+ if (max1.num === max2.num) {
7352
+ const maxExclusive1 = max1.exclusive;
7353
+ const maxExclusive2 = max2.exclusive;
7354
+ hasRight = maxExclusive1 !== maxExclusive2;
7355
+ isLeftRangeOverride = !maxExclusive1 && maxExclusive2;
7356
+ }
7357
+ if (!isLeftRangeOverride) {
7358
+ let right;
7359
+ if (hasRight) right = {
7360
+ fromLeft: false,
7361
+ range: [reversalExclusive(max1), max2]
7362
+ };
7363
+ return {
7364
+ left,
7365
+ center: [centerBegin, max1],
7366
+ right
7367
+ };
7368
+ }
7369
+ }
7370
+ return {
7371
+ left,
7372
+ center: [centerBegin, max2],
7373
+ right: {
7374
+ fromLeft: true,
7375
+ range: [reversalExclusive(max2), max1]
7376
+ }
7377
+ };
7378
+ }
7379
+ function reversalExclusive(point) {
7380
+ return {
7381
+ num: point.num,
7382
+ exclusive: !point.exclusive
7383
+ };
7384
+ }
7385
+ //#endregion
7386
+ //#region src/json-schema-subset/checker/range.ts
7387
+ var createRangeSplitter = (undefinedMin) => (min1 = undefinedMin, max1 = Number.POSITIVE_INFINITY, min2 = undefinedMin, max2 = Number.POSITIVE_INFINITY) => {
7388
+ const { left, center, right } = splitRange$3([{
7389
+ num: min1,
7390
+ exclusive: false
7391
+ }, {
7392
+ num: max1,
7393
+ exclusive: false
7394
+ }], [{
7395
+ num: min2,
7396
+ exclusive: false
7397
+ }, {
7398
+ num: max2,
7399
+ exclusive: false
7400
+ }]);
7401
+ let leftItem;
7402
+ let rightItem;
7403
+ let intersectionItem;
7404
+ if (left) leftItem = {
7405
+ min: left.range[0].num,
7406
+ max: left.range[1].num,
7407
+ isFrom1: left.fromLeft
7408
+ };
7409
+ if (right) rightItem = {
7410
+ min: right.range[0].num,
7411
+ max: right.range[1].num,
7412
+ isFrom1: right.fromLeft
7413
+ };
7414
+ if (center) intersectionItem = {
7415
+ min: center[0].num,
7416
+ max: center[1].num
7417
+ };
7418
+ return {
7419
+ left: leftItem,
7420
+ right: rightItem,
7421
+ intersection: intersectionItem
7422
+ };
7423
+ };
7424
+ function toExpressionSingleResult({ left, right, intersection }) {
7425
+ if (!intersection) return ExpressionSingleResult.Rejection;
7426
+ let extra1 = false;
7427
+ let extra2 = false;
7428
+ if (left) {
7429
+ if (left.isFrom1) extra1 = true;
7430
+ else extra2 = true;
7431
+ }
7432
+ if (right) {
7433
+ if (right.isFrom1) extra1 = true;
7434
+ else extra2 = true;
7435
+ }
7436
+ if (extra1 && extra2) return ExpressionSingleResult.Intersection;
7437
+ if (extra1) return ExpressionSingleResult.Containing;
7438
+ if (extra2) return ExpressionSingleResult.ContainedBy;
7439
+ return ExpressionSingleResult.Equals;
7440
+ }
7441
+ //#endregion
7442
+ //#region src/json-schema-subset/checker/array.ts
7443
+ var splitRange$2 = createRangeSplitter(0);
7444
+ var quantum$1 = makeQuantum([
7445
+ "hasCommon",
7446
+ "hasExtra1",
7447
+ "hasExtra2",
7448
+ "hasRejection",
7449
+ "hasCommonBroken"
7450
+ ]);
7451
+ function calculateArray({ calculate }, schema1, schema2) {
7452
+ const splitResult = splitRange$2(schema1.minItems, schema1.maxItems, schema2.minItems, schema2.maxItems);
7453
+ const splitExpression = toExpressionSingleResult(splitResult);
7454
+ if (splitExpression === ExpressionSingleResult.Rejection) return ExpressionRejection;
7455
+ const [items1, additionalItems1] = normalizeArray(schema1);
7456
+ const [items2, additionalItems2] = normalizeArray(schema2);
7457
+ const itemsLength = Math.max(items1.length, items2.length) + 1;
7458
+ const length = Math.min(itemsLength, splitResult.intersection.max);
7459
+ const quantumVariable = quantum$1.variable({});
7460
+ const minItems = Math.min(schema1.minItems ?? 0, schema2.minItems ?? 0);
7461
+ for (let i = 0; i < length; i++) {
7462
+ const expression = calculate(items1[i] ?? additionalItems1, items2[i] ?? additionalItems2);
7463
+ quantumVariable.push(expression, (singleExpression, variable) => {
7464
+ switch (singleExpression) {
7465
+ case ExpressionSingleResult.Equals:
7466
+ if (!variable.hasRejection) variable.hasCommon = true;
7467
+ break;
7468
+ case ExpressionSingleResult.Containing:
7469
+ if (!variable.hasRejection) variable.hasCommon = true;
7470
+ variable.hasExtra1 = true;
7471
+ break;
7472
+ case ExpressionSingleResult.ContainedBy:
7473
+ if (!variable.hasRejection) variable.hasCommon = true;
7474
+ variable.hasExtra2 = true;
7475
+ break;
7476
+ case ExpressionSingleResult.Intersection:
7477
+ if (!variable.hasRejection) variable.hasCommon = true;
7478
+ variable.hasExtra1 = true;
7479
+ variable.hasExtra2 = true;
7480
+ break;
7481
+ case ExpressionSingleResult.Rejection:
7482
+ if (i < minItems) variable.hasCommonBroken = true;
7483
+ variable.hasRejection = true;
7484
+ variable.hasExtra1 = true;
7485
+ variable.hasExtra2 = true;
7486
+ }
7487
+ });
7488
+ }
7489
+ quantumVariable.update((variable) => {
7490
+ switch (splitExpression) {
7491
+ case ExpressionSingleResult.Containing:
7492
+ variable.hasExtra1 = true;
7493
+ break;
7494
+ case ExpressionSingleResult.ContainedBy:
7495
+ variable.hasExtra2 = true;
7496
+ break;
7497
+ case ExpressionSingleResult.Intersection:
7498
+ variable.hasExtra1 = true;
7499
+ variable.hasExtra2 = true;
7500
+ }
7501
+ if (schema1.uniqueItems && !schema2.uniqueItems && (schema2.maxItems ?? Number.POSITIVE_INFINITY) > 1) variable.hasExtra2 = true;
7502
+ else if (!schema1.uniqueItems && schema2.uniqueItems && (schema1.maxItems ?? Number.POSITIVE_INFINITY) > 1) variable.hasExtra1 = true;
7503
+ if (schema1.maxItems === 0 || schema2.maxItems === 0) {
7504
+ variable.hasCommon = true;
7505
+ if (schema1.maxItems !== 0) variable.hasExtra1 = true;
7506
+ if (schema2.maxItems !== 0) variable.hasExtra2 = true;
7507
+ }
7508
+ });
7509
+ let expression = 0;
7510
+ for (const { hasExtra1, hasExtra2, hasCommon, hasCommonBroken } of quantumVariable) {
7511
+ let finalHasCommon = hasCommon;
7512
+ if (hasCommonBroken) finalHasCommon = false;
7513
+ if (!finalHasCommon) expression |= ExpressionRejection;
7514
+ else if (hasExtra1 && hasExtra2) expression |= ExpressionIntersection;
7515
+ else if (hasExtra1) expression |= ExpressionContaining;
7516
+ else if (hasExtra2) expression |= ExpressionContainedBy;
7517
+ else expression |= ExpressionEquals;
7518
+ }
7519
+ return expression;
7520
+ }
7521
+ function normalizeArray({ items, additionalItems }) {
7522
+ if (Array.isArray(items)) return [items, additionalItems ?? ANY];
7523
+ else return [[], items ?? ANY];
7524
+ }
7525
+ //#endregion
7526
+ //#region src/json-schema-subset/checker/cache.ts
7527
+ function wrapEqualsCheckerWithCache(check) {
7528
+ const map = /* @__PURE__ */ new Map();
7529
+ return (value1, value2) => {
7530
+ const isObject1 = isCompiledObject(value1);
7531
+ if (isObject1 !== isCompiledObject(value2)) return false;
7532
+ if (!isObject1) return value1 === value2;
7533
+ return getWithCache(map, value1, value2, check);
7534
+ };
7535
+ }
7536
+ function wrapSchemaCalculatorWithCache(check) {
7537
+ const map = /* @__PURE__ */ new Map();
7538
+ return (schema1, schema2) => getWithCache(map, schema1, schema2, check);
7539
+ }
7540
+ function getWithCache(map, node1, node2, check) {
7541
+ const key = `${getId(node1)}/${getId(node2)}`;
7542
+ let result = map.get(key);
7543
+ if (result === void 0) map.set(key, result = check(node1, node2));
7544
+ return result;
7545
+ }
7546
+ //#endregion
7547
+ //#region src/json-schema-subset/checker/enumAndConst.ts
7548
+ function calculateEnumAndEnum(context, schema1, schema2) {
7549
+ const enumList1 = normalizeEnumList(schema1);
7550
+ const enumList2 = normalizeEnumList(schema2);
7551
+ let foundExtra1 = false;
7552
+ let foundExtra2 = false;
7553
+ let foundIntersection = false;
7554
+ for (const enum1 of enumList1) {
7555
+ if (hasEqualsEnum(context, enumList2, enum1)) foundIntersection = true;
7556
+ else foundExtra1 = true;
7557
+ if (foundExtra1 && foundIntersection) break;
7558
+ }
7559
+ for (const enum2 of enumList2) {
7560
+ if (hasEqualsEnum(context, enumList1, enum2)) foundIntersection = true;
7561
+ else foundExtra2 = true;
7562
+ if (foundExtra2 && foundIntersection) break;
7563
+ }
7564
+ if (!foundIntersection) return ExpressionRejection;
7565
+ if (foundExtra1 && foundExtra2) return ExpressionIntersection;
7566
+ if (foundExtra1) return ExpressionContaining;
7567
+ if (foundExtra2) return ExpressionContainedBy;
7568
+ return ExpressionEquals;
7569
+ }
7570
+ function calculateEnumAndSchema(enumSchema, schema) {
7571
+ let hasValid = false;
7572
+ let hasInvalid = false;
7573
+ for (const enumValue of normalizeEnumList(enumSchema)) {
7574
+ switch (valid(schema, enumValue)) {
7575
+ case ValidResult.Valid:
7576
+ hasValid = true;
7577
+ break;
7578
+ case ValidResult.Invalid:
7579
+ hasInvalid = true;
7580
+ break;
7581
+ case ValidResult.Unknown: return ExpressionAny;
7582
+ }
7583
+ if (hasValid && hasInvalid) break;
7584
+ }
7585
+ if (hasValid && hasInvalid) return ExpressionIntersection;
7586
+ if (hasValid) return ExpressionEquals | ExpressionContainedBy;
7587
+ if (hasInvalid) return ExpressionRejection;
7588
+ if (getKind(schema) === CompiledKind.Never) return ExpressionEquals;
7589
+ return ExpressionContainedBy;
7590
+ }
7591
+ function normalizeEnumList({ const: constValue, enum: enumList }) {
7592
+ if (constValue !== void 0) return [constValue];
7593
+ if (enumList) return enumList;
7594
+ throw new Error("invalid branch");
7595
+ }
7596
+ function hasEqualsEnum({ isEquals }, enumList, checkedEnum) {
7597
+ for (const searchedEnum of enumList) if (isEquals(searchedEnum, checkedEnum)) return true;
7598
+ return false;
7599
+ }
7600
+ //#endregion
7601
+ //#region src/json-schema-subset/checker/equals.ts
7602
+ function schemaEqualsChecker(extendsContext) {
7603
+ function isSchemaEquals(schema1, schema2) {
7604
+ const isExtends1 = extendsContext.isExtendsSchema(schema1);
7605
+ const isExtends2 = extendsContext.isExtendsSchema(schema2);
7606
+ if (isExtends1 || isExtends2) return extendsContext.equals(schema1, schema2);
7607
+ else return isCompiledSchemaEquals(schema1, schema2);
7608
+ }
7609
+ const equalsMap = /* @__PURE__ */ new Map();
7610
+ function isCompiledSchemaEquals(schema1, schema2) {
7611
+ const id1 = getId(schema1);
7612
+ const id2 = getId(schema2);
7613
+ if (id1 === id2) return true;
7614
+ const key = `${id1}/${id2}`;
7615
+ let isEquals = equalsMap.get(key);
7616
+ if (isEquals === void 0) {
7617
+ isEquals = isObjectLikeEquals(schema1, schema2);
7618
+ equalsMap.set(key, isEquals);
7619
+ }
7620
+ return isEquals;
7621
+ }
7622
+ function isObjectLikeEquals(object1, object2) {
7623
+ if (Array.isArray(object1)) {
7624
+ if (!Array.isArray(object2)) return false;
7625
+ if (object1.length !== object2.length) return false;
7626
+ for (const [i, value1Element] of object1.entries()) if (!isValueEquals(value1Element, object2[i])) return false;
7627
+ } else {
7628
+ if (Array.isArray(object2)) return false;
7629
+ for (const key in object1) {
7630
+ if (!(key in object2)) return false;
7631
+ if (!isValueEquals(Reflect.get(object1, key), Reflect.get(object2, key))) return false;
7632
+ }
7633
+ for (const key in object2) if (!(key in object1)) return false;
7634
+ }
7635
+ return true;
7636
+ }
7637
+ function isValueEquals(value1, value2) {
7638
+ if (value1 === value2) return true;
7639
+ if (value1 === null) return false;
7640
+ if (typeof value1 !== "object") return false;
7641
+ if (typeof value1 !== typeof value2) return false;
7642
+ if (isCompiledSchema(value1) && isCompiledSchema(value2)) return isCompiledSchemaEquals(value1, value2);
7643
+ return isObjectLikeEquals(value1, value2);
7644
+ }
7645
+ return isSchemaEquals;
7646
+ }
7647
+ //#endregion
7648
+ //#region src/json-schema-subset/checker/numeric/integerNormalizer.ts
7649
+ function normalizeInteger(schema) {
7650
+ const floatRange = pickRange(schema);
7651
+ const multipleOf = schema.multipleOf ?? 1;
7652
+ const range = cutRange(floatRange, multipleOf);
7653
+ if (!range) return null;
7654
+ return {
7655
+ multipleOf,
7656
+ range
7657
+ };
7658
+ }
7659
+ function isPointRange([point1, point2]) {
7660
+ if (point1.num !== point2.num) return false;
7661
+ if (point1.exclusive) return false;
7662
+ if (point2.exclusive) return false;
7663
+ return true;
7664
+ }
7665
+ function cutRange(range, multipleOf) {
7666
+ if (!range) return;
7667
+ const [originMin, originMax] = range;
7668
+ let min = nextInteger(originMin.num, multipleOf);
7669
+ let max = previousInteger(originMax.num, multipleOf);
7670
+ if (min === originMin.num && originMin.exclusive) min += multipleOf;
7671
+ if (max === originMax.num && originMax.exclusive) max -= multipleOf;
7672
+ if (min > max) return;
7673
+ if (min === max) {
7674
+ if (min === Number.POSITIVE_INFINITY) return;
7675
+ if (min === Number.NEGATIVE_INFINITY) return;
7676
+ }
7677
+ return [{
7678
+ num: min,
7679
+ exclusive: false
7680
+ }, {
7681
+ num: max,
7682
+ exclusive: false
7683
+ }];
7684
+ }
7685
+ function nextInteger(float, multipleOf) {
7686
+ return Math.ceil(float / multipleOf) * multipleOf;
7687
+ }
7688
+ function previousInteger(float, multipleOf) {
7689
+ return Math.floor(float / multipleOf) * multipleOf;
7690
+ }
7691
+ //#endregion
7692
+ //#region src/json-schema-subset/checker/numeric/float.ts
7693
+ function calculateFloat(schema1, schema2) {
7694
+ const { left, right, center } = splitRange$3(pickRange(schema1), pickRange(schema2));
7695
+ if (!center) return ExpressionRejection;
7696
+ let extraLeft = false;
7697
+ let extraRight = false;
7698
+ if (left) {
7699
+ if (left.fromLeft) extraLeft = true;
7700
+ else extraRight = true;
7701
+ }
7702
+ if (right) {
7703
+ if (right.fromLeft) extraLeft = true;
7704
+ else extraRight = true;
7705
+ }
7706
+ if (extraLeft && extraRight) return ExpressionIntersection;
7707
+ if (extraLeft) return ExpressionContaining;
7708
+ if (extraRight) return ExpressionContainedBy;
7709
+ return ExpressionEquals;
7710
+ }
7711
+ function calculateFloatAndInteger(schema1, schema2) {
7712
+ const floatRange = pickRange(schema1);
7713
+ const integer = normalizeInteger(schema2);
7714
+ if (!integer) return ExpressionContaining;
7715
+ const result = splitRange$3(floatRange, integer.range);
7716
+ const intCenter = cutRange(result.center, integer.multipleOf);
7717
+ const leftIntRange = unwrapAndCutRange(result.left, integer.multipleOf);
7718
+ const rightIntRange = unwrapAndCutRange(result.right, integer.multipleOf);
7719
+ if (!result.center) return ExpressionRejection;
7720
+ let extraFloat = false;
7721
+ let extraInteger = false;
7722
+ if (result.left?.fromLeft) extraFloat = true;
7723
+ if (result.right?.fromLeft) extraFloat = true;
7724
+ if (!intCenter || !isPointRange(result.center)) extraFloat = true;
7725
+ if (leftIntRange) extraInteger = true;
7726
+ if (rightIntRange) extraInteger = true;
7727
+ if (extraFloat && extraInteger) return ExpressionIntersection;
7728
+ if (extraFloat) return ExpressionContaining;
7729
+ if (extraInteger) return ExpressionContainedBy;
7730
+ return ExpressionEquals;
7731
+ }
7732
+ function pickRange(schema) {
7733
+ let point1;
7734
+ let point2;
7735
+ if (schema.exclusiveMinimum !== void 0) point1 = {
7736
+ num: schema.exclusiveMinimum,
7737
+ exclusive: true
7738
+ };
7739
+ else if (schema.minimum !== void 0) point1 = {
7740
+ num: schema.minimum,
7741
+ exclusive: false
7742
+ };
7743
+ else point1 = {
7744
+ num: Number.NEGATIVE_INFINITY,
7745
+ exclusive: true
7746
+ };
7747
+ if (schema.exclusiveMaximum !== void 0) point2 = {
7748
+ num: schema.exclusiveMaximum,
7749
+ exclusive: true
7750
+ };
7751
+ else if (schema.maximum !== void 0) point2 = {
7752
+ num: schema.maximum,
7753
+ exclusive: false
7754
+ };
7755
+ else point2 = {
7756
+ num: Number.POSITIVE_INFINITY,
7757
+ exclusive: true
7758
+ };
7759
+ return [point1, point2];
7760
+ }
7761
+ function unwrapAndCutRange(side, multipleOf) {
7762
+ if (!side) return;
7763
+ if (side.fromLeft) return;
7764
+ return cutRange(side.range, multipleOf);
7765
+ }
7766
+ //#endregion
7767
+ //#region src/json-schema-subset/checker/numeric/integer.ts
7768
+ function calculateInteger(schema1, schema2) {
7769
+ const integer1 = normalizeInteger(schema1);
7770
+ const integer2 = normalizeInteger(schema2);
7771
+ if (!integer1 && !integer2) return ExpressionEquals;
7772
+ if (!integer1) return ExpressionContainedBy;
7773
+ if (!integer2) return ExpressionContaining;
7774
+ const { range: range1, multipleOf: multipleOf1 } = integer1;
7775
+ const { range: range2, multipleOf: multipleOf2 } = integer2;
7776
+ const result = splitRange$3(range1, range2);
7777
+ let centerRange;
7778
+ let lcm = 0;
7779
+ if (result.center) {
7780
+ lcm = getLCM(multipleOf1, multipleOf2);
7781
+ centerRange = cutRange(result.center, lcm);
7782
+ }
7783
+ if (!centerRange) return ExpressionRejection;
7784
+ let extraLeft = false;
7785
+ let extraRight = false;
7786
+ const { left, right } = result;
7787
+ if (left && cutRange(left.range, left.fromLeft ? multipleOf1 : multipleOf2)) {
7788
+ if (left.fromLeft) extraLeft = true;
7789
+ else extraRight = true;
7790
+ }
7791
+ if (right && cutRange(right.range, right.fromLeft ? multipleOf1 : multipleOf2)) {
7792
+ if (right.fromLeft) extraLeft = true;
7793
+ else extraRight = true;
7794
+ }
7795
+ extraLeft = extraLeft || hasExtraIntegersOnCenter(integer1, centerRange, lcm);
7796
+ extraRight = extraRight || hasExtraIntegersOnCenter(integer2, centerRange, lcm);
7797
+ if (extraLeft && extraRight) return ExpressionIntersection;
7798
+ if (extraLeft) return ExpressionContaining;
7799
+ if (extraRight) return ExpressionContainedBy;
7800
+ return ExpressionEquals;
7801
+ }
7802
+ function hasExtraIntegersOnCenter({ range, multipleOf }, lcmCenterRange, lcm) {
7803
+ const result = splitRange$3(range, lcmCenterRange);
7804
+ if (cutRange(result.left?.range, multipleOf)) return true;
7805
+ if (cutRange(result.right?.range, multipleOf)) return true;
7806
+ const center = cutRange(result.center, multipleOf);
7807
+ if (!center) return false;
7808
+ const lcmCenterLength = rangeLength(lcmCenterRange);
7809
+ if (rangeLength(center) > lcmCenterLength) return true;
7810
+ if (lcmCenterLength === 1) return false;
7811
+ if (multipleOf < lcm) return true;
7812
+ return false;
7813
+ }
7814
+ /** Returns the least common multiple. */
7815
+ function getLCM(a, b) {
7816
+ return a * b / getGCD(a, b);
7817
+ }
7818
+ /** @returns The greatest common divisor. */
7819
+ function getGCD(a, b) {
7820
+ if (a === 0) return b;
7821
+ return getGCD(b % a, a);
7822
+ }
7823
+ function rangeLength(range) {
7824
+ if (!range) return 0;
7825
+ const [point1, point2] = range;
7826
+ return point2.num - point1.num + 1;
7827
+ }
7828
+ //#endregion
7829
+ //#region src/json-schema-subset/checker/numeric/checker.ts
7830
+ function calculateNumeric(schema1, schema2) {
7831
+ if (isUndefinedNumber(schema1) || isUndefinedNumber(schema2)) return ExpressionAny;
7832
+ const isFloat1 = isFloat(schema1);
7833
+ const isFloat2 = isFloat(schema2);
7834
+ if (isFloat1 && isFloat2) return calculateFloat(schema1, schema2);
7835
+ else if (isFloat1) return calculateFloatAndInteger(schema1, schema2);
7836
+ else if (isFloat2) return swap(calculateFloatAndInteger(schema2, schema1));
7837
+ else return calculateInteger(schema1, schema2);
7838
+ }
7839
+ function isUndefinedNumber(schema) {
7840
+ const { multipleOf } = schema;
7841
+ if (multipleOf === void 0) return false;
7842
+ if (!Number.isInteger(multipleOf)) return true;
7843
+ if (multipleOf < 0) return true;
7844
+ return false;
7845
+ }
7846
+ function isFloat(schema) {
7847
+ const { multipleOf } = schema;
7848
+ if (multipleOf !== void 0 && Number.isInteger(multipleOf)) return false;
7849
+ if (schema.type === "integer") return false;
7850
+ return true;
7851
+ }
7852
+ //#endregion
7853
+ //#region src/json-schema-subset/checker/object.ts
7854
+ var splitRange$1 = createRangeSplitter(0);
7855
+ var quantum = makeQuantum([
7856
+ "hasCommonInRequired",
7857
+ "hasCommonOutRequired",
7858
+ "hasExtra1",
7859
+ "hasExtra2",
7860
+ "hasRejection"
7861
+ ]);
7862
+ function calculateObject(context, schema1, schema2) {
7863
+ if (isPropertiesCountCannotMatch(schema1, schema2)) return ExpressionRejection;
7864
+ const splitRequiredResult = splitRequired(schema1, schema2);
7865
+ if (!splitRequiredResult) return ExpressionRejection;
7866
+ const getProperty1 = createPropertySchemaGetter(schema1);
7867
+ const getProperty2 = createPropertySchemaGetter(schema2);
7868
+ const calculateKey = (key) => {
7869
+ const propertySchema1 = getProperty1(key);
7870
+ const propertySchema2 = getProperty2(key);
7871
+ if (areNotBothNever(propertySchema1, propertySchema2)) return context.calculate(propertySchema1, propertySchema2);
7872
+ else return 0;
7873
+ };
7874
+ const { commonRequired, extraRequired1, extraRequired2 } = splitRequiredResult;
7875
+ const quantumVariable = quantum.variable({});
7876
+ for (const requiredKey of [...commonRequired].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateCommonRequiredExpression);
7877
+ for (const requiredKey of [...extraRequired1].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateExtraRequiredExpression1);
7878
+ for (const requiredKey of [...extraRequired2].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateExtraRequiredExpression2);
7879
+ const { hasOptional1, hasOptional2 } = splitRequiredResult;
7880
+ if (hasOptional1 || hasOptional2) {
7881
+ const calculator = calculateOptionalExpression(hasOptional1, hasOptional2);
7882
+ for (const optionalKey of [...getOptionalKeys(schema1, schema2)].toSorted()) {
7883
+ const expression = calculateKey(optionalKey);
7884
+ if (expression !== 0) quantumVariable.push(expression, calculator);
7885
+ }
7886
+ const additionalProperties1 = schema1.additionalProperties ?? ANY;
7887
+ const additionalProperties2 = schema2.additionalProperties ?? ANY;
7888
+ if (areNotBothNever(additionalProperties1, additionalProperties2)) {
7889
+ const expression = context.calculate(additionalProperties1, additionalProperties2);
7890
+ quantumVariable.push(expression, calculator);
7891
+ }
7892
+ }
7893
+ quantumVariable.update((variable) => {
7894
+ if (!variable.hasRejection) {
7895
+ if (extraRequired1.size > 0) variable.hasExtra2 = true;
7896
+ if (extraRequired2.size > 0) variable.hasExtra1 = true;
7897
+ }
7898
+ });
7899
+ const { requiredKeysCount } = splitRequiredResult;
7900
+ let expression = 0;
7901
+ for (const { hasExtra1, hasExtra2, hasCommonInRequired, hasCommonOutRequired, hasRejection } of quantumVariable) if (!hasCommonInRequired && requiredKeysCount > 0) expression |= ExpressionRejection;
7902
+ else if (!hasCommonOutRequired && requiredKeysCount === 0) expression |= ExpressionRejection;
7903
+ else if (hasRejection) expression |= ExpressionRejection;
7904
+ else if (hasExtra1 && hasExtra2) expression |= ExpressionIntersection;
7905
+ else if (hasExtra1) expression |= ExpressionContaining;
7906
+ else if (hasExtra2) expression |= ExpressionContainedBy;
7907
+ else expression |= ExpressionEquals;
7908
+ return expression;
7909
+ }
7910
+ function isPropertiesCountCannotMatch(schema1, schema2) {
7911
+ return toExpressionSingleResult(splitRange$1(schema1.minProperties, schema1.maxProperties, schema2.minProperties, schema2.maxProperties)) === ExpressionSingleResult.Rejection;
7912
+ }
7913
+ function splitRequired(schema1, schema2) {
7914
+ const extraRequired1 = new Set(schema1.required);
7915
+ const extraRequired2 = new Set(schema2.required);
7916
+ const commonRequired = /* @__PURE__ */ new Set();
7917
+ const wholeRequired = /* @__PURE__ */ new Set();
7918
+ const requiredCount1 = extraRequired1.size;
7919
+ const requiredCount2 = extraRequired2.size;
7920
+ for (const key of extraRequired1) {
7921
+ if (extraRequired2.has(key)) commonRequired.add(key);
7922
+ wholeRequired.add(key);
7923
+ }
7924
+ for (const key of extraRequired2) {
7925
+ if (extraRequired1.has(key)) commonRequired.add(key);
7926
+ wholeRequired.add(key);
7927
+ }
7928
+ const requiredKeysCount = wholeRequired.size;
7929
+ for (const key of commonRequired) {
7930
+ extraRequired1.delete(key);
7931
+ extraRequired2.delete(key);
7932
+ }
7933
+ const maxProperties1 = schema1.maxProperties ?? Number.MAX_SAFE_INTEGER;
7934
+ const maxProperties2 = schema2.maxProperties ?? Number.MAX_SAFE_INTEGER;
7935
+ if (requiredKeysCount > maxProperties1 || requiredKeysCount > maxProperties2) return null;
7936
+ return {
7937
+ requiredKeysCount,
7938
+ extraRequired1,
7939
+ extraRequired2,
7940
+ commonRequired,
7941
+ hasOptional1: maxProperties1 > requiredCount1,
7942
+ hasOptional2: maxProperties2 > requiredCount2
7943
+ };
7944
+ }
7945
+ function getOptionalKeys(schema1, schema2) {
7946
+ const optionalKeys = new Set(schema1.required);
7947
+ const properties1 = schema1.properties;
7948
+ const properties2 = schema2.properties;
7949
+ const required1 = schema1.required;
7950
+ const required2 = schema2.required;
7951
+ if (properties1) for (const key in properties1) optionalKeys.add(key);
7952
+ if (properties2) for (const key in properties2) optionalKeys.add(key);
7953
+ if (required1) for (const key of required1) optionalKeys.delete(key);
7954
+ if (required2) for (const key of required2) optionalKeys.delete(key);
7955
+ return optionalKeys;
7956
+ }
7957
+ var calculateCommonRequiredExpression = (singleExpression, variable) => {
7958
+ switch (singleExpression) {
7959
+ case ExpressionSingleResult.Equals:
7960
+ variable.hasCommonInRequired = true;
7961
+ break;
7962
+ case ExpressionSingleResult.Containing:
7963
+ variable.hasExtra1 = true;
7964
+ variable.hasCommonInRequired = true;
7965
+ break;
7966
+ case ExpressionSingleResult.ContainedBy:
7967
+ variable.hasExtra2 = true;
7968
+ variable.hasCommonInRequired = true;
7969
+ break;
7970
+ case ExpressionSingleResult.Intersection:
7971
+ variable.hasExtra1 = true;
7972
+ variable.hasExtra2 = true;
7973
+ variable.hasCommonInRequired = true;
7974
+ break;
7975
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
7976
+ }
7977
+ };
7978
+ var calculateExtraRequiredExpression1 = (singleExpression, variable) => {
7979
+ switch (singleExpression) {
7980
+ case ExpressionSingleResult.Equals:
7981
+ case ExpressionSingleResult.ContainedBy:
7982
+ variable.hasCommonInRequired = true;
7983
+ break;
7984
+ case ExpressionSingleResult.Intersection:
7985
+ case ExpressionSingleResult.Containing:
7986
+ variable.hasExtra1 = true;
7987
+ variable.hasCommonInRequired = true;
7988
+ break;
7989
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
7990
+ }
7991
+ };
7992
+ var calculateExtraRequiredExpression2 = (singleExpression, variable) => {
7993
+ switch (singleExpression) {
7994
+ case ExpressionSingleResult.Equals:
7995
+ case ExpressionSingleResult.Containing:
7996
+ variable.hasCommonInRequired = true;
7997
+ break;
7998
+ case ExpressionSingleResult.Intersection:
7999
+ case ExpressionSingleResult.ContainedBy:
8000
+ variable.hasExtra2 = true;
8001
+ variable.hasCommonInRequired = true;
8002
+ break;
8003
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
8004
+ }
8005
+ };
8006
+ var calculateOptionalExpression = (hasOptional1, hasOptional2) => (singleExpression, variable) => {
8007
+ if (variable.hasRejection) return;
8008
+ let foundExtraPossibility1 = false;
8009
+ let foundExtraPossibility2 = false;
8010
+ let foundCommonPossibility = false;
8011
+ switch (singleExpression) {
8012
+ case ExpressionSingleResult.Equals:
8013
+ foundCommonPossibility = true;
8014
+ break;
8015
+ case ExpressionSingleResult.Containing:
8016
+ foundExtraPossibility1 = true;
8017
+ foundCommonPossibility = true;
8018
+ break;
8019
+ case ExpressionSingleResult.ContainedBy:
8020
+ foundExtraPossibility2 = true;
8021
+ foundCommonPossibility = true;
8022
+ break;
8023
+ case ExpressionSingleResult.Intersection:
8024
+ foundExtraPossibility1 = true;
8025
+ foundExtraPossibility2 = true;
8026
+ foundCommonPossibility = true;
8027
+ break;
8028
+ case ExpressionSingleResult.Rejection:
8029
+ foundExtraPossibility1 = true;
8030
+ foundExtraPossibility2 = true;
8031
+ }
8032
+ if (hasOptional1 && foundExtraPossibility1) variable.hasExtra1 = true;
8033
+ if (hasOptional2 && foundExtraPossibility2) variable.hasExtra2 = true;
8034
+ if (hasOptional1 && hasOptional2 && foundCommonPossibility) variable.hasCommonOutRequired = true;
8035
+ };
8036
+ function createPropertySchemaGetter(schema) {
8037
+ const properties = schema.properties;
8038
+ const propertyNames = schema.propertyNames;
8039
+ const additionalProperties = schema.additionalProperties;
8040
+ const patternProperties = [];
8041
+ if (schema.patternProperties) for (const pattern in schema.patternProperties) {
8042
+ const valueSchema = schema.patternProperties[pattern];
8043
+ const regExp = new RegExp(pattern, "i");
8044
+ patternProperties.push({
8045
+ pattern: regExp,
8046
+ schema: valueSchema
8047
+ });
8048
+ }
8049
+ return (key) => {
8050
+ if (propertyNames && valid(propertyNames, key) === ValidResult.Invalid) return NEVER;
8051
+ for (const { pattern, schema: patternSchema } of patternProperties) if (pattern.test(key)) return patternSchema;
8052
+ const propertySchema = (properties && properties[key]) ?? additionalProperties;
8053
+ if (!propertySchema) return ANY;
8054
+ return propertySchema;
8055
+ };
8056
+ }
8057
+ function areNotBothNever(schema1, schema2) {
8058
+ const kind1 = getKind(schema1);
8059
+ const kind2 = getKind(schema2);
8060
+ return kind1 !== CompiledKind.Never || kind2 !== CompiledKind.Never;
8061
+ }
8062
+ //#endregion
8063
+ //#region src/json-schema-subset/checker/string.ts
8064
+ var splitRange = createRangeSplitter(0);
8065
+ function calculateString(schema1, schema2) {
8066
+ if (schema2.format && !schema1.format) return ExpressionContaining;
8067
+ if (schema1.format && schema2.format && schema1.format !== schema2.format) return ExpressionAny;
8068
+ const expression = toExpressionSingleResult(splitRange(schema1.minLength, schema1.maxLength, schema2.minLength, schema2.maxLength));
8069
+ const hasPattern1 = !!schema1.pattern;
8070
+ const hasPattern2 = !!schema2.pattern;
8071
+ switch (expression) {
8072
+ case ExpressionSingleResult.Rejection: return ExpressionRejection;
8073
+ case ExpressionSingleResult.Containing: return hasPattern1 ? ExpressionAny : ExpressionContaining;
8074
+ case ExpressionSingleResult.ContainedBy: return hasPattern2 ? ExpressionAny : ExpressionContainedBy;
8075
+ case ExpressionSingleResult.Equals:
8076
+ if (hasPattern1 && hasPattern2) return schema1.pattern === schema2.pattern ? ExpressionEquals : ExpressionAny;
8077
+ if (hasPattern1) return ExpressionEquals | ExpressionContainedBy;
8078
+ if (hasPattern2) return ExpressionEquals | ExpressionContaining;
8079
+ return ExpressionEquals;
8080
+ case ExpressionSingleResult.Intersection:
8081
+ if (hasPattern1 && hasPattern2) return ExpressionAny;
8082
+ if (hasPattern1) return ExpressionIntersection | ExpressionRejection | ExpressionContainedBy;
8083
+ if (hasPattern2) return ExpressionIntersection | ExpressionRejection | ExpressionContaining;
8084
+ return ExpressionIntersection;
8085
+ }
8086
+ }
8087
+ //#endregion
8088
+ //#region src/json-schema-subset/checker/checker.ts
8089
+ function checkWithResult(extendsContext, schema1, schema2) {
8090
+ const context = {};
8091
+ const errorPaths = [];
8092
+ const calculate = wrapSchemaCalculatorWithCache(calculator(extendsContext, context));
8093
+ const describe = describer();
8094
+ const equals = schemaEqualsChecker(extendsContext);
8095
+ context.isEquals = wrapEqualsCheckerWithCache(isDeepEquals);
8096
+ context.calculate = expression({
8097
+ describe,
8098
+ equals,
8099
+ calculate,
8100
+ observeCalculation: (left, right, result, swapped) => {
8101
+ if (!isDecisiveMismatch(swapped ? swap(result) : result)) return;
8102
+ const errorPath = swapped ? findMismatchPath(right, left) : findMismatchPath(left, right);
8103
+ if (errorPath) errorPaths.push(errorPath);
8104
+ }
8105
+ });
8106
+ Object.freeze(context);
8107
+ const comparisonExpression = context.calculate(schema1, schema2);
8108
+ return {
8109
+ errorPath: errorPaths[0],
8110
+ expression: comparisonExpression
8111
+ };
8112
+ }
8113
+ var describer = () => (schema) => {
8114
+ let description;
8115
+ switch (getKind(schema)) {
8116
+ case CompiledKind.Not:
8117
+ description = {
8118
+ kind: ExpressionKind.Not,
8119
+ expression: schema.not
8120
+ };
8121
+ break;
8122
+ case CompiledKind.Combination:
8123
+ if ("allOf" in schema) description = {
8124
+ kind: ExpressionKind.AllOf,
8125
+ expressions: rejectInSchemaList(schema.allOf, CompiledKind.Any)
8126
+ };
8127
+ else if ("anyOf" in schema) description = {
8128
+ kind: ExpressionKind.AnyOf,
8129
+ expressions: rejectInSchemaList(schema.anyOf, CompiledKind.Never)
8130
+ };
8131
+ else if ("oneOf" in schema) description = {
8132
+ kind: ExpressionKind.OneOf,
8133
+ expressions: rejectInSchemaList(schema.oneOf, CompiledKind.Never)
8134
+ };
8135
+ else throw new Error(`invalid combination JSON Schema: ${JSON.stringify(schema)}`);
8136
+ break;
8137
+ default: description = { kind: ExpressionKind.Leaf };
8138
+ }
8139
+ return description;
8140
+ };
8141
+ var calculator = (extendsContext, context) => (schema1, schema2) => {
8142
+ const kind1 = getKind(schema1);
8143
+ const kind2 = getKind(schema2);
8144
+ if (kind1 === CompiledKind.Extends || kind2 === CompiledKind.Extends) return extendsContext.calculate(schema1, schema2);
8145
+ switch (kind1) {
8146
+ case CompiledKind.Any: return kind2 === CompiledKind.Any ? ExpressionEquals : ExpressionContaining;
8147
+ case CompiledKind.Never: return kind2 === CompiledKind.Never ? ExpressionEquals : ExpressionContainedBy;
8148
+ }
8149
+ switch (kind2) {
8150
+ case CompiledKind.Any: return ExpressionContainedBy;
8151
+ case CompiledKind.Never: return ExpressionContaining;
8152
+ }
8153
+ if (kind1 === CompiledKind.EnumOrConst && kind2 === CompiledKind.EnumOrConst) return calculateEnumAndEnum(context, schema1, schema2);
8154
+ if (kind1 === CompiledKind.EnumOrConst) return calculateEnumAndSchema(schema1, schema2);
8155
+ if (kind2 === CompiledKind.EnumOrConst) return swap(calculateEnumAndSchema(schema2, schema1));
8156
+ if (kind1 !== kind2) return ExpressionRejection;
8157
+ switch (kind1) {
8158
+ case CompiledKind.Null: return ExpressionEquals;
8159
+ case CompiledKind.Numeric: return calculateNumeric(schema1, schema2);
8160
+ case CompiledKind.String: return calculateString(schema1, schema2);
8161
+ case CompiledKind.Boolean: return ExpressionEquals;
8162
+ case CompiledKind.Object: return calculateObject(context, schema1, schema2);
8163
+ case CompiledKind.Array: return calculateArray(context, schema1, schema2);
8164
+ default: throw new Error(`invalid kind ${kind1}`);
8165
+ }
8166
+ };
8167
+ function rejectInSchemaList(schemaList, kind) {
8168
+ return schemaList.filter((e) => getKind(e) !== kind);
8169
+ }
8170
+ function isDecisiveMismatch(result) {
8171
+ return !hasEquals(result) && !hasContainedBy(result) && (hasContaining(result) || hasIntersection(result) || hasRejection(result));
8172
+ }
8173
+ function findMismatchPath(source, target) {
8174
+ const targetPath = getPath(target);
8175
+ if (!targetPath) return void 0;
8176
+ const sourceKind = getKind(source);
8177
+ const targetKind = getKind(target);
8178
+ if (sourceKind !== targetKind) return [...targetPath, "type"];
8179
+ const sourceSchema = source;
8180
+ const targetSchema = target;
8181
+ switch (targetKind) {
8182
+ case CompiledKind.String:
8183
+ if ((sourceSchema.minLength ?? 0) < (targetSchema.minLength ?? 0)) return [...targetPath, "minLength"];
8184
+ if ((sourceSchema.maxLength ?? Number.POSITIVE_INFINITY) > (targetSchema.maxLength ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxLength"];
8185
+ if (sourceSchema.pattern !== targetSchema.pattern && targetSchema.pattern) return [...targetPath, "pattern"];
8186
+ if (sourceSchema.format !== targetSchema.format && targetSchema.format) return [...targetPath, "format"];
8187
+ break;
8188
+ case CompiledKind.Numeric:
8189
+ if ((sourceSchema.minimum ?? sourceSchema.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) < (targetSchema.minimum ?? targetSchema.exclusiveMinimum ?? Number.NEGATIVE_INFINITY)) return [...targetPath, targetSchema.exclusiveMinimum == null ? "minimum" : "exclusiveMinimum"];
8190
+ if ((sourceSchema.maximum ?? sourceSchema.exclusiveMaximum ?? Number.POSITIVE_INFINITY) > (targetSchema.maximum ?? targetSchema.exclusiveMaximum ?? Number.POSITIVE_INFINITY)) return [...targetPath, targetSchema.exclusiveMaximum == null ? "maximum" : "exclusiveMaximum"];
8191
+ if (sourceSchema.multipleOf !== targetSchema.multipleOf && targetSchema.multipleOf != null) return [...targetPath, "multipleOf"];
8192
+ break;
8193
+ case CompiledKind.Array:
8194
+ if ((sourceSchema.minItems ?? 0) < (targetSchema.minItems ?? 0)) return [...targetPath, "minItems"];
8195
+ if ((sourceSchema.maxItems ?? Number.POSITIVE_INFINITY) > (targetSchema.maxItems ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxItems"];
8196
+ if (!sourceSchema.uniqueItems && targetSchema.uniqueItems) return [...targetPath, "uniqueItems"];
8197
+ break;
8198
+ case CompiledKind.Object: {
8199
+ const sourceRequired = new Set(sourceSchema.required ?? []);
8200
+ if ((targetSchema.required ?? []).some((key) => !sourceRequired.has(key))) return [...targetPath, "required"];
8201
+ if ((sourceSchema.minProperties ?? 0) < (targetSchema.minProperties ?? 0)) return [...targetPath, "minProperties"];
8202
+ if ((sourceSchema.maxProperties ?? Number.POSITIVE_INFINITY) > (targetSchema.maxProperties ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxProperties"];
8203
+ break;
8204
+ }
8205
+ case CompiledKind.EnumOrConst: return [...targetPath, targetSchema.const == null ? "enum" : "const"];
8206
+ }
8207
+ return targetPath;
8208
+ }
8209
+ //#endregion
8210
+ //#region src/json-schema-subset/extends/extendsContext.ts
8211
+ var ExtendsContext = class ExtendsContext {
8212
+ constructor(extendsSchemaClasses = []) {
8213
+ this.extendsSchemaClasses = Object.freeze([...extendsSchemaClasses]);
8214
+ }
8215
+ tryCompiledExtendsSchema(target, payload) {
8216
+ for (const extendsSchemaClass of this.extendsSchemaClasses) if (extendsSchemaClass.isMatch(target)) return new extendsSchemaClass(createId(), target, payload);
8217
+ return null;
8218
+ }
8219
+ isExtendsSchema(target) {
8220
+ for (const extendsSchemaClass of this.extendsSchemaClasses) if (target instanceof extendsSchemaClass) return true;
8221
+ return false;
8222
+ }
8223
+ calculate(schema1, schema2) {
8224
+ const shouldSwap = !(schema1 instanceof this.findMatchedClass(schema1, schema2));
8225
+ let expressionResult = 0;
8226
+ let result;
8227
+ if (shouldSwap) result = schema2.compare(schema1);
8228
+ else result = schema1.compare(schema2);
8229
+ for (let expression of result) {
8230
+ if (shouldSwap) expression = ExtendsContext.swap(expression);
8231
+ expressionResult |= toExpression(expression);
8232
+ }
8233
+ return expressionResult;
8234
+ }
8235
+ equals(schema1, schema2) {
8236
+ if (!(schema1 instanceof this.findMatchedClass(schema1, schema2))) return schema2.equals(schema1);
8237
+ else return schema1.equals(schema2);
8238
+ }
8239
+ findMatchedClass(schema1, schema2) {
8240
+ for (const schemaClass of this.extendsSchemaClasses) {
8241
+ if (schema1 instanceof schemaClass) return schemaClass;
8242
+ if (schema2 instanceof schemaClass) return schemaClass;
8243
+ }
8244
+ throw new Error("Invalid schema");
8245
+ }
8246
+ static swap(expression) {
8247
+ switch (expression) {
8248
+ case ExpressionSingleResult.Containing: return ExpressionSingleResult.ContainedBy;
8249
+ case ExpressionSingleResult.ContainedBy: return ExpressionSingleResult.Containing;
8250
+ default: return expression;
8251
+ }
8252
+ }
8253
+ };
8254
+ //#endregion
8255
+ //#region src/json-schema-subset/preprocessing.ts
8256
+ function preprocessSchema(schema, compile, printWarnLog = false) {
8257
+ const schemaResult = compile(schema);
8258
+ if (Array.isArray(schemaResult)) {
8259
+ const errorItems = [];
8260
+ collectWithPathPrefix(errorItems, schemaResult, "$");
8261
+ throw new SchemaError(errorItems);
8262
+ }
8263
+ const { schema: compiledSchema, warns } = schemaResult;
8264
+ if (printWarnLog && warns.length > 0) {
8265
+ console.warn(`found ${warns.length} warns after compile schema`);
8266
+ for (const warn of warns) console.warn(stringifySchemaError(warn));
8267
+ }
8268
+ return compiledSchema;
8269
+ }
8270
+ function preprocessSchemasPair(schema1, schema2, compile, printWarnLog = false) {
8271
+ const schemaResult1 = compile(schema1);
8272
+ const schemaResult2 = compile(schema2);
8273
+ if (Array.isArray(schemaResult1) || Array.isArray(schemaResult2)) {
8274
+ const errorItems = [];
8275
+ if (Array.isArray(schemaResult1)) collectWithPathPrefix(errorItems, schemaResult1, "$1");
8276
+ if (Array.isArray(schemaResult2)) collectWithPathPrefix(errorItems, schemaResult2, "$2");
8277
+ throw new SchemaError(errorItems);
8278
+ }
8279
+ const { schema: compiledSchema1, warns: superWarns } = schemaResult1;
8280
+ const { schema: compiledSchema2, warns: subWarns } = schemaResult2;
8281
+ if (printWarnLog) {
8282
+ if (superWarns.length > 0) console.warn(`found ${superWarns.length} warns after compile superSchema`);
8283
+ for (const warn of superWarns) console.warn(stringifySchemaError(warn));
8284
+ if (subWarns.length > 0) console.warn(`found ${subWarns.length} warns after compile subSchema`);
8285
+ for (const warn of subWarns) console.warn(stringifySchemaError(warn));
8286
+ }
8287
+ return [compiledSchema1, compiledSchema2];
8288
+ }
8289
+ function collectWithPathPrefix(errorItems, compiledItems, prefix) {
8290
+ for (const compiledItem of compiledItems) {
8291
+ const replacedItem = {
8292
+ ...compiledItem,
8293
+ path: [prefix, ...compiledItem.path]
8294
+ };
8295
+ errorItems.push(replacedItem);
8296
+ }
8297
+ }
8298
+ //#endregion
8299
+ //#region src/json-schema-subset/global.ts
8300
+ var SubsetCompareResult = Object.freeze({
8301
+ True: 0,
8302
+ False: 1,
8303
+ Unknown: 2
8304
+ });
8305
+ function makeSubsetCompare({ extendsSchemaClasses, delegate } = {}) {
8306
+ const extendsContext = new ExtendsContext(extendsSchemaClasses);
8307
+ return Object.freeze({
8308
+ compile: (schema, payload, printWarnLog) => {
8309
+ const compiler = (candidate) => compile(candidate, extendsContext, payload, delegate);
8310
+ return preprocessSchema(schema, compiler, printWarnLog);
8311
+ },
8312
+ isSubset: (superSchema, subSchema, printWarnLog = false) => {
8313
+ const compiler = (candidate) => compile(candidate, extendsContext, void 0, delegate);
8314
+ const [schema1, schema2] = preprocessSchemasPair(superSchema, subSchema, compiler, printWarnLog);
8315
+ const { errorPath, expression } = checkWithResult(extendsContext, schema1, schema2);
8316
+ const foundTrueExpression = hasEquals(expression) || hasContainedBy(expression);
8317
+ const foundFalseExpression = hasContaining(expression) || hasIntersection(expression) || hasRejection(expression);
8318
+ if (foundTrueExpression && !foundFalseExpression) return { result: SubsetCompareResult.True };
8319
+ if (!foundTrueExpression && foundFalseExpression) return {
8320
+ errorPath,
8321
+ result: SubsetCompareResult.False
8322
+ };
8323
+ return { result: SubsetCompareResult.Unknown };
8324
+ }
8325
+ });
8326
+ }
8327
+ //#endregion
8328
+ //#region ../../node_modules/.bun/@wopjs+cast@0.1.16/node_modules/@wopjs/cast/dist/index.mjs
8329
+ var isString = (x) => typeof x === "string";
8330
+ var isArray = Array.isArray;
8331
+ var isObject = (x) => x !== null && typeof x === "object";
8332
+ var isPlainObject = (x) => isObject(x) && !isArray(x);
8333
+ var toPlainObject = (x) => isPlainObject(x) ? x : void 0;
8334
+ //#endregion
8335
+ //#region src/manifest/common/schemaComparer.ts
8336
+ function isStringLikeSchema(value) {
8337
+ return toPlainObject(value)?.type === "string";
8338
+ }
8339
+ function assertSchemaCompareContext(value) {
8340
+ const context = toPlainObject(value);
8341
+ const error = toPlainObject(context?.error);
8342
+ if (context == null || error == null || context.packageId != null && !isString(context.packageId) || error.message != null && !isString(error.message)) throw new TypeError("Invalid schema comparison context.");
8343
+ }
8344
+ function parseSchemaCompareContext(value) {
8345
+ if (value == null) return { error: {} };
8346
+ assertSchemaCompareContext(value);
8347
+ return value;
8348
+ }
8349
+ var SpecialSchema = class SpecialSchema {
8350
+ static setError(fromSchema, toSchema, message) {
8351
+ if (fromSchema instanceof SpecialSchema) fromSchema.context.error.message = message;
8352
+ else if (toSchema instanceof SpecialSchema) toSchema.context.error.message = message;
8353
+ }
8354
+ constructor(id, value, context) {
8355
+ this.id = id;
8356
+ this.value = value;
8357
+ this.context = parseSchemaCompareContext(context);
8358
+ }
8359
+ compare(other) {
8360
+ if (isCompiledSchema(other) && getKind(other) === CompiledKind.Any) return [ExpressionSingleResult.ContainedBy];
8361
+ return this.compareImpl(other);
8362
+ }
8363
+ };
8364
+ var SingleSelectSchema = class SingleSelectSchema extends SpecialSchema {
8365
+ static isMatch(value) {
8366
+ const enumValues = toPlainObject(value)?.enum;
8367
+ return Array.isArray(enumValues) && enumValues.every((v) => isString(v));
8368
+ }
8369
+ constructor(id, value, context) {
8370
+ if (!SingleSelectSchema.isMatch(value)) throw new TypeError("Invalid single-select schema.");
8371
+ super(id, value, context);
8372
+ }
8373
+ compareImpl(other) {
8374
+ if (isStringLikeSchema(other)) return [ExpressionSingleResult.ContainedBy];
8375
+ if (other instanceof SingleSelectSchema) {
8376
+ const f = new Set(this.value.enum);
8377
+ let result = ExpressionSingleResult.Equals;
8378
+ for (const v of other.value.enum) {
8379
+ if (!f.has(v)) result = ExpressionSingleResult.ContainedBy;
8380
+ f.delete(v);
8381
+ }
8382
+ if (f.size === 0) return [result];
8383
+ if (f.size === this.value.enum.length) return [ExpressionSingleResult.Rejection];
8384
+ return [ExpressionSingleResult.Intersection];
8385
+ }
8386
+ return [ExpressionSingleResult.Rejection];
8387
+ }
8388
+ equals(other) {
8389
+ if (other instanceof SingleSelectSchema) {
8390
+ const f = new Set(this.value.enum);
8391
+ for (const v of other.value.enum) {
8392
+ if (!f.has(v)) return false;
8393
+ f.delete(v);
8394
+ }
8395
+ return f.size === 0;
8396
+ }
8397
+ return false;
8398
+ }
8399
+ };
8400
+ var BinarySchema = class BinarySchema extends SpecialSchema {
8401
+ static isMatch(value) {
8402
+ return toPlainObject(value)?.contentMediaType === "oomol/bin";
8403
+ }
8404
+ constructor(id, value, context) {
8405
+ if (!BinarySchema.isMatch(value)) throw new TypeError("Invalid binary schema.");
8406
+ super(id, value, context);
8407
+ }
8408
+ compareImpl(other) {
8409
+ if (other instanceof BinarySchema) return [ExpressionSingleResult.Equals];
8410
+ else {
8411
+ SpecialSchema.setError(this, other, "edgeError.binDiffType");
8412
+ return [ExpressionSingleResult.Rejection];
8413
+ }
8414
+ }
8415
+ equals(other) {
8416
+ return other instanceof BinarySchema;
8417
+ }
8418
+ };
8419
+ var ArtifactSchema = class ArtifactSchema extends SpecialSchema {
8420
+ static isMatch(value) {
8421
+ return toPlainObject(value)?.contentMediaType === "oomol/artifact";
8422
+ }
8423
+ constructor(id, value, context) {
8424
+ if (!ArtifactSchema.isMatch(value)) throw new TypeError("Invalid Artifact schema.");
8425
+ super(id, value, context);
8426
+ }
8427
+ compareImpl(other) {
8428
+ if (other instanceof ArtifactSchema) return [ExpressionSingleResult.Equals];
8429
+ SpecialSchema.setError(this, other, "edgeError.artifactDiffType");
8430
+ return [ExpressionSingleResult.Rejection];
8431
+ }
8432
+ equals(other) {
8433
+ return other instanceof ArtifactSchema;
8434
+ }
8435
+ };
8436
+ function createSchemaComparer() {
8437
+ return makeSubsetCompare({ extendsSchemaClasses: [
8438
+ SingleSelectSchema,
8439
+ BinarySchema,
8440
+ ArtifactSchema
8441
+ ] });
8442
+ }
8443
+ createSchemaComparer();
8444
+ //#endregion
8445
+ //#region src/decision/common/decision.ts
8446
+ var decisionLimits = {
8447
+ choice: 255,
8448
+ score: 10
8449
+ };
8450
+ /** Ordered prefixes are shared by authoring, schemas, validation, and execution. */
8451
+ function limitDecisionQuestion(question) {
8452
+ if (question.type === "noul" || question.criteria.length <= decisionLimits[question.type]) return question;
8453
+ if (question.type === "choice") return {
8454
+ ...question,
8455
+ criteria: question.criteria.slice(0, decisionLimits.choice)
8456
+ };
8457
+ return {
8458
+ ...question,
8459
+ criteria: question.criteria.slice(0, decisionLimits.score)
8460
+ };
8461
+ }
8462
+ function limitDecisionQuestions(questions) {
8463
+ const limited = questions.map(limitDecisionQuestion);
8464
+ return limited.every((question, i) => question === questions[i]) ? questions : limited;
8465
+ }
8466
+ /** Loading an oversized task also updates its previously generated output schemas. */
8467
+ function limitDecisionTask(task) {
8468
+ if (task.executor.kind !== "decision") return task;
8469
+ const original = task.executor.questions;
8470
+ const questions = limitDecisionQuestions(original);
8471
+ if (questions === original) return task;
8472
+ const outputs = task.outputs.map((port) => {
8473
+ if (!("handle" in port)) return port;
8474
+ const index = original.findIndex((question) => question.name === port.handle);
8475
+ if (index < 0 || original[index] === questions[index] || !dequal(port.jsonSchema, answerSchema(original[index]))) return port;
8476
+ return {
8477
+ ...port,
8478
+ jsonSchema: decisionAnswerSchema(questions[index])
8479
+ };
8480
+ });
8481
+ return {
8482
+ ...task,
8483
+ executor: {
8484
+ ...task.executor,
8485
+ questions
8486
+ },
8487
+ outputs
8488
+ };
8489
+ }
8490
+ var probability = {
8491
+ type: "number",
8492
+ minimum: 0,
8493
+ maximum: 1
8494
+ };
8495
+ function decisionAnswerSchema(question) {
8496
+ return answerSchema(limitDecisionQuestion(question));
8497
+ }
8498
+ function answerSchema(question) {
8499
+ const properties = { type: { const: question.type } };
8500
+ if (question.type === "noul") properties.noul = probability;
8501
+ else {
8502
+ const keys = question.type === "choice" ? question.criteria.map((item) => item.name) : question.criteria.map((_, index) => String(index));
8503
+ properties.confidence = probability;
8504
+ properties.probabilities = {
8505
+ type: "object",
8506
+ properties: Object.fromEntries(keys.map((key) => [key, probability])),
8507
+ required: keys,
8508
+ additionalProperties: false
8509
+ };
8510
+ if (question.type === "choice") properties.choice = {
8511
+ type: "string",
8512
+ ...keys.length ? { enum: keys } : {}
8513
+ };
8514
+ else {
8515
+ properties.score = {
8516
+ type: "number",
8517
+ minimum: 0,
8518
+ maximum: Math.max(0, keys.length - 1)
8519
+ };
8520
+ properties.legend = {
8521
+ type: "object",
8522
+ properties: Object.fromEntries(keys.map((key) => [key, { type: "string" }])),
8523
+ required: keys,
8524
+ additionalProperties: false
8525
+ };
8526
+ }
8527
+ }
8528
+ return {
8529
+ type: "object",
8530
+ properties,
8531
+ required: Object.keys(properties)
8532
+ };
8533
+ }
8534
+ //#endregion
8535
+ //#region src/flow/common/json.ts
8536
+ var maxJsonDepth = 64;
8537
+ function checkJsonDepth(value, depth = 0) {
8538
+ if (depth > 64) throw new TypeError("Value exceeds the maximum JSON depth.");
8539
+ if (value != null && typeof value == "object") for (const child of Object.values(value)) checkJsonDepth(child, depth + 1);
8540
+ }
8541
+ //#endregion
8542
+ //#region src/flow/common/triggerScheduleSchema.ts
8543
+ var triggerScheduleSchema = array(union([object({
8544
+ type: literal("cron"),
8545
+ expression: string(),
8546
+ timezone: string()
8547
+ }), object({
8548
+ type: literal("every"),
8549
+ unit: _enum([
8550
+ "day",
8551
+ "hour",
8552
+ "minute",
8553
+ "month",
8554
+ "week"
8555
+ ]),
8556
+ value: number()
8557
+ })]));
8558
+ //#endregion
8559
+ //#region src/flow/common/webhookMethod.ts
8560
+ var webhookMethods = [
8561
+ "GET",
8562
+ "POST",
8563
+ "PUT",
8564
+ "PATCH",
8565
+ "DELETE"
8566
+ ];
8567
+ var text = string();
8568
+ var json = json$1();
8569
+ var strings = array(text);
8570
+ var port = object({
8571
+ description: text.optional(),
8572
+ jsonSchema: json,
8573
+ nullable: boolean(),
8574
+ handle: text
8575
+ });
8576
+ var input = port.extend({ value: json.optional() });
8577
+ var group = object({
8578
+ collapsed: boolean().optional(),
8579
+ group: text
8580
+ });
8581
+ var nodeSource = object({
8582
+ kind: literal("node"),
8583
+ nodeId: text,
8584
+ output: text,
8585
+ field: text.optional()
8586
+ });
8587
+ var flowSource = object({
8588
+ kind: literal("flow"),
8589
+ input: text
8590
+ });
8591
+ var source = union([
8592
+ nodeSource,
8593
+ flowSource,
8594
+ object({
8595
+ kind: literal("binding"),
8596
+ bindingId: text
8597
+ })
8598
+ ]);
8599
+ var fixedInput = union([object({ kind: literal("unset") }), object({
8600
+ kind: literal("value"),
8601
+ value: json
8602
+ })]);
8603
+ var mapping = union([fixedInput, object({
8604
+ kind: literal("sources"),
8605
+ sources: array(source)
8606
+ })]);
8607
+ var inputs = record$1(text, mapping);
8608
+ var ports = {
8609
+ inputs: array(union([input, group])),
8610
+ outputs: array(union([port, group]))
8611
+ };
8612
+ var capability = union([
8613
+ strictObject({
8614
+ kind: literal("connector"),
8615
+ action: text,
8616
+ connectionId: text.optional(),
8617
+ connections: array(strictObject({
8618
+ connectionId: text,
8619
+ alias: text.optional()
8620
+ }))
8621
+ }),
8622
+ strictObject({
8623
+ kind: literal("connector"),
8624
+ mode: literal("shared")
8625
+ }),
8626
+ strictObject({
8627
+ kind: literal("connector"),
8628
+ mode: literal("independent"),
8629
+ actions: array(strictObject({
8630
+ action: text,
8631
+ connectionId: text.optional()
8632
+ }))
8633
+ }),
8634
+ strictObject({
8635
+ kind: literal("connector"),
8636
+ actionHints: array(text).optional(),
8637
+ connectionHints: array(strictObject({
8638
+ action: text,
8639
+ connectionId: text,
8640
+ alias: text.optional()
8641
+ })).optional()
8642
+ })
8643
+ ]);
8644
+ var inline = object({
8645
+ ...ports,
8646
+ name: text,
8647
+ moduleId: text,
8648
+ capabilities: array(capability).optional()
5703
8649
  });
5704
8650
  var agentValue = union([object({
5705
8651
  kind: literal("value"),
@@ -5709,6 +8655,32 @@ var agentValue = union([object({
5709
8655
  input: text
5710
8656
  })]);
5711
8657
  var agentInput = union([agentValue, object({ kind: literal("model") })]);
8658
+ var decisionQuestion = discriminatedUnion("type", [
8659
+ strictObject({
8660
+ name: text,
8661
+ instructions: text,
8662
+ type: literal("noul"),
8663
+ criteria: strictObject({
8664
+ true: text.optional(),
8665
+ false: text.optional()
8666
+ }).optional()
8667
+ }),
8668
+ strictObject({
8669
+ name: text,
8670
+ instructions: text,
8671
+ type: literal("choice"),
8672
+ criteria: array(strictObject({
8673
+ name: text,
8674
+ description: text
8675
+ }))
8676
+ }),
8677
+ strictObject({
8678
+ name: text,
8679
+ instructions: text,
8680
+ type: literal("score"),
8681
+ criteria: strings
8682
+ })
8683
+ ]);
5712
8684
  var managed = object({
5713
8685
  ...ports,
5714
8686
  name: text,
@@ -5736,6 +8708,10 @@ var managed = object({
5736
8708
  in: _enum(["header", "query"]).optional()
5737
8709
  }))
5738
8710
  }),
8711
+ strictObject({
8712
+ kind: literal("decision"),
8713
+ questions: array(decisionQuestion)
8714
+ }),
5739
8715
  object({
5740
8716
  kind: literal("llm"),
5741
8717
  mode: _enum(["chat", "json"])
@@ -5762,7 +8738,7 @@ var managed = object({
5762
8738
  }).optional()
5763
8739
  })
5764
8740
  ])
5765
- });
8741
+ }).transform(limitDecisionTask);
5766
8742
  var operand = union([object({
5767
8743
  kind: literal("value"),
5768
8744
  value: json.optional(),
@@ -6359,6 +9335,11 @@ var shapes = {
6359
9335
  before: text.optional(),
6360
9336
  value: text.optional()
6361
9337
  },
9338
+ "task.decision.set": {
9339
+ taskId: text,
9340
+ before: managed,
9341
+ value: managed
9342
+ },
6362
9343
  "task.openapi.set": {
6363
9344
  taskId: text,
6364
9345
  before: managed,