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