@oomol-lab/open-flow 0.1.0-beta.54 → 0.1.0-beta.56

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/{createResourceDialog-BsaBMf7_.js → createResourceDialog-Btjes3wD.js} +3 -3
  3. package/dist/browser/{main-BPABKzwN.js → dist-BFmpkX4P.js} +9 -1
  4. package/dist/browser/flow-authoring-edge.d.ts +3 -3
  5. package/dist/browser/flow-authoring-node.d.ts +29 -44
  6. package/dist/browser/flow-authoring.d.ts +1 -1
  7. package/dist/browser/flow-authoring.js +418 -12018
  8. package/dist/browser/flow-change-schema.d.ts +1 -1
  9. package/dist/browser/flow-change.d.ts +15 -100
  10. package/dist/browser/flow-change.js +3175 -383
  11. package/dist/browser/{flowChanges-CcscgZsW.js → flowChanges-BxutPLYO.js} +23382 -27177
  12. package/dist/browser/{flowWorkspace-CoT_ewLX.js → flowWorkspace-Dg4mqfa6.js} +3307 -595
  13. package/dist/browser/{icons-0s-Q_3lp.js → icons-p2A9zs8t.js} +4403 -354
  14. package/dist/browser/lib-DrKav3HG.js +11403 -0
  15. package/dist/browser/{markdownContent-D3FFc-u_.js → markdownContent-frwDfQQU.js} +1 -2
  16. package/dist/browser/preview.css +375 -322
  17. package/dist/browser/preview.js +16796 -13483
  18. package/dist/browser/theme.css +1 -0
  19. package/dist/browser/ui-idTooltip.d.ts +11 -0
  20. package/dist/browser/ui.css +30 -0
  21. package/dist/browser/ui.d.ts +5 -0
  22. package/dist/browser/ui.js +87 -4
  23. package/dist/browser/workbench.css +375 -322
  24. package/dist/browser/workbench.js +213 -414
  25. package/dist/browser/{workbenchSelect-BqUPacsr.js → workbenchSelect-LRp_Xjeq.js} +1 -1
  26. package/dist/common/authoringExamples.d.ts +3 -2
  27. package/dist/common/control-api-conformance.js +3686 -3594
  28. package/dist/common/control-api.d.ts +6 -6
  29. package/dist/common/control-api.js +3760 -3645
  30. package/dist/common/control-requests.js +2382 -3118
  31. package/dist/common/decision.d.ts +47 -0
  32. package/dist/common/decision.js +10109 -0
  33. package/dist/common/flow-agent.d.ts +1 -1
  34. package/dist/common/flow-connectionUsage.d.ts +1 -2
  35. package/dist/common/flow-encoding.d.ts +2 -4
  36. package/dist/common/flow-encoding.js +3206 -286
  37. package/dist/common/flow-graph.d.ts +10 -10
  38. package/dist/common/flow-semantics.d.ts +4 -9
  39. package/dist/common/flow-semantics.js +9200 -9132
  40. package/dist/common/flowInspection.d.ts +3 -21
  41. package/dist/common/integration-trigger.js +6251 -6094
  42. package/dist/common/mcp.d.ts +0 -1
  43. package/dist/common/mcp.js +3729 -3627
  44. package/dist/common/openapi.js +6402 -6245
  45. package/dist/common/poll-trigger.js +6433 -6252
  46. package/dist/common/run-events.js +1 -1
  47. package/dist/common/runtime-contract.d.ts +8 -0
  48. package/dist/common/scheduler.d.ts +3 -9
  49. package/dist/common/scheduler.js +3263 -3153
  50. package/dist/common/webhook-trigger.js +6402 -6245
  51. package/package.json +5 -1
  52. package/dist/browser/dist-BDBTOgS5.js +0 -9
@@ -1,9 +1,9 @@
1
1
  //#region src/openapi/common/authBindings.ts
2
2
  /** Never allow credentials to enter a Revision as literal node inputs. */
3
3
  function assertOpenApiAuthBindings(document) {
4
- for (const graph of [document.graph, ...Object.values(document.subflows).map((subflow) => subflow.graph)]) for (const node of Object.values(graph.nodes)) {
5
- if (node.kind != "task" || node.taskId == null || document.tasks[node.taskId]?.executor.kind != "openapi") continue;
6
- for (const [handle, mapping] of Object.entries(node.inputs)) if (handle.startsWith("auth.") && (mapping.kind == "value" || mapping.kind == "sources" && mapping.sources.some((source) => source.kind == "flow"))) throw new TypeError("OpenAPI authentication accepts deployment variables and upstream outputs only.");
4
+ for (const node of Object.values(document.graph.nodes)) {
5
+ if (node.kind != "task" || !("executor" in node.task) || node.task.executor.kind != "openapi") continue;
6
+ for (const [handle, mapping] of Object.entries(node.inputs)) if (handle.startsWith("auth.") && mapping.kind == "value") throw new TypeError("OpenAPI authentication accepts deployment variables and upstream outputs only.");
7
7
  }
8
8
  }
9
9
  //#endregion
@@ -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",
@@ -2769,6 +2833,9 @@ function handlePipeResult(left, next, ctx) {
2769
2833
  issues: left.issues
2770
2834
  }, ctx);
2771
2835
  }
2836
+ var $ZodPreprocess = /*@__PURE__*/ $constructor("$ZodPreprocess", (inst, def) => {
2837
+ $ZodPipe.init(inst, def);
2838
+ });
2772
2839
  var $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2773
2840
  $ZodType.init(inst, def);
2774
2841
  defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
@@ -5495,7 +5562,7 @@ var ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
5495
5562
  return merge(this, other);
5496
5563
  },
5497
5564
  pick(mask) {
5498
- return pick(this, mask);
5565
+ return pick$1(this, mask);
5499
5566
  },
5500
5567
  omit(mask) {
5501
5568
  return omit(this, mask);
@@ -5538,6 +5605,18 @@ function union(options, params) {
5538
5605
  ...normalizeParams(params)
5539
5606
  });
5540
5607
  }
5608
+ var ZodDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodDiscriminatedUnion", (inst, def) => {
5609
+ ZodUnion.init(inst, def);
5610
+ $ZodDiscriminatedUnion.init(inst, def);
5611
+ });
5612
+ function discriminatedUnion(discriminator, options, params) {
5613
+ return new ZodDiscriminatedUnion({
5614
+ type: "union",
5615
+ options,
5616
+ discriminator,
5617
+ ...normalizeParams(params)
5618
+ });
5619
+ }
5541
5620
  var ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
5542
5621
  $ZodIntersection.init(inst, def);
5543
5622
  ZodType.init(inst, def);
@@ -5558,7 +5637,7 @@ var ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
5558
5637
  inst.keyType = def.keyType;
5559
5638
  inst.valueType = def.valueType;
5560
5639
  });
5561
- function record(keyType, valueType, params) {
5640
+ function record$1(keyType, valueType, params) {
5562
5641
  if (!valueType || !valueType._zod) return new ZodRecord({
5563
5642
  type: "record",
5564
5643
  keyType: string(),
@@ -5767,6 +5846,10 @@ function pipe(in_, out) {
5767
5846
  out
5768
5847
  });
5769
5848
  }
5849
+ var ZodPreprocess = /*@__PURE__*/ $constructor("ZodPreprocess", (inst, def) => {
5850
+ ZodPipe.init(inst, def);
5851
+ $ZodPreprocess.init(inst, def);
5852
+ });
5770
5853
  var ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
5771
5854
  $ZodReadonly.init(inst, def);
5772
5855
  ZodType.init(inst, def);
@@ -5810,120 +5893,2964 @@ function json$1(params) {
5810
5893
  boolean(),
5811
5894
  _null(),
5812
5895
  array(jsonSchema),
5813
- record(string(), jsonSchema)
5896
+ record$1(string(), jsonSchema)
5814
5897
  ]);
5815
5898
  });
5816
5899
  return jsonSchema;
5817
5900
  }
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);
5901
+ function preprocess(fn, schema) {
5902
+ return new ZodPreprocess({
5903
+ type: "pipe",
5904
+ in: transform(fn),
5905
+ out: schema
5906
+ });
5821
5907
  }
5822
5908
  //#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
- })]));
5909
+ //#region src/json-schema-subset/utils.ts
5910
+ var nextId = 0;
5911
+ function createId() {
5912
+ const id = nextId;
5913
+ nextId += 1;
5914
+ return id;
5915
+ }
5916
+ function deepFreeze(target) {
5917
+ if (typeof target === "object" && target !== null && !Object.isFrozen(target)) {
5918
+ for (const key of Object.getOwnPropertyNames(target)) deepFreeze(Reflect.get(target, key));
5919
+ Object.freeze(target);
5920
+ }
5921
+ return target;
5922
+ }
5923
+ function pick(target, keys) {
5924
+ const newTarget = {};
5925
+ for (const key of keys) if (key in target) newTarget[key] = target[key];
5926
+ return newTarget;
5927
+ }
5928
+ function deepCopy(value) {
5929
+ if (typeof value !== "object" || value === null) return value;
5930
+ else if (Array.isArray(value)) {
5931
+ const array = [];
5932
+ for (const [i, element] of value.entries()) array[i] = deepCopy(element);
5933
+ return array;
5934
+ } else {
5935
+ const newObject = {};
5936
+ for (const key in value) newObject[key] = deepCopy(value[key]);
5937
+ return newObject;
5938
+ }
5939
+ }
5940
+ function isDeepEquals(value1, value2) {
5941
+ if (value1 === value2) return true;
5942
+ if (value1 === null) return false;
5943
+ if (typeof value1 !== "object") return false;
5944
+ if (typeof value1 !== typeof value2) return false;
5945
+ if (Array.isArray(value1)) {
5946
+ if (!Array.isArray(value2)) return false;
5947
+ if (value1.length !== value2.length) return false;
5948
+ for (const [i, value1Element] of value1.entries()) if (!isDeepEquals(value1Element, value2[i])) return false;
5949
+ } else {
5950
+ if (Array.isArray(value2)) return false;
5951
+ for (const key in value1) {
5952
+ if (!(key in value2)) return false;
5953
+ if (!isDeepEquals(value1[key], value2[key])) return false;
5954
+ }
5955
+ for (const key in value2) if (!(key in value1)) return false;
5956
+ }
5957
+ return true;
5958
+ }
5839
5959
  //#endregion
5840
- //#region src/flow/common/webhookMethod.ts
5841
- var webhookMethods = [
5842
- "GET",
5843
- "POST",
5844
- "PUT",
5845
- "PATCH",
5846
- "DELETE"
5847
- ];
5960
+ //#region src/json-schema-subset/expression/result.ts
5961
+ var ExpressionSingleResult = Object.freeze({
5962
+ Equals: 0,
5963
+ Containing: 1,
5964
+ ContainedBy: 2,
5965
+ Rejection: 3,
5966
+ Intersection: 4
5967
+ });
5968
+ var ExpressionEquals = toExpression(ExpressionSingleResult.Equals);
5969
+ var ExpressionContaining = toExpression(ExpressionSingleResult.Containing);
5970
+ var ExpressionContainedBy = toExpression(ExpressionSingleResult.ContainedBy);
5971
+ var ExpressionRejection = toExpression(ExpressionSingleResult.Rejection);
5972
+ var ExpressionIntersection = toExpression(ExpressionSingleResult.Intersection);
5973
+ var ExpressionMaskList = deepFreeze([
5974
+ [ExpressionSingleResult.Equals, ExpressionEquals],
5975
+ [ExpressionSingleResult.Containing, ExpressionContaining],
5976
+ [ExpressionSingleResult.ContainedBy, ExpressionContainedBy],
5977
+ [ExpressionSingleResult.Rejection, ExpressionRejection],
5978
+ [ExpressionSingleResult.Intersection, ExpressionIntersection]
5979
+ ]);
5980
+ var ExpressionAny = (() => {
5981
+ let expression = 0;
5982
+ for (const [_, mask] of ExpressionMaskList) expression |= mask;
5983
+ return expression;
5984
+ })();
5985
+ function hasEquals(expression) {
5986
+ return !!(expression & ExpressionEquals);
5987
+ }
5988
+ function hasContaining(expression) {
5989
+ return !!(expression & ExpressionContaining);
5990
+ }
5991
+ function hasContainedBy(expression) {
5992
+ return !!(expression & ExpressionContainedBy);
5993
+ }
5994
+ function hasRejection(expression) {
5995
+ return !!(expression & ExpressionRejection);
5996
+ }
5997
+ function hasIntersection(expression) {
5998
+ return !!(expression & ExpressionIntersection);
5999
+ }
6000
+ function toExpression(expression) {
6001
+ return 1 << expression;
6002
+ }
5848
6003
  //#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
6004
+ //#region src/json-schema-subset/expression/combination.ts
6005
+ function makeCombination(calculator) {
6006
+ let expression = 0;
6007
+ let count = 0;
6008
+ const quantum = { push: (newExpression) => {
6009
+ if (count === 0) expression = newExpression;
6010
+ else expression = forEach(expression, newExpression, calculator);
6011
+ count += 1;
6012
+ return expression;
6013
+ } };
6014
+ Object.defineProperties(quantum, {
6015
+ result: { get: () => expression },
6016
+ count: { get: () => count }
6017
+ });
6018
+ return quantum;
6019
+ }
6020
+ function forEach(e1, e2, calculator) {
6021
+ let expression = 0;
6022
+ for (const [singleResult1, mask1] of ExpressionMaskList) if (mask1 & e1) {
6023
+ for (const [singleResult2, mask2] of ExpressionMaskList) if (mask2 & e2) {
6024
+ expression |= calculator(singleResult1, singleResult2);
6025
+ if (expression === ExpressionAny) return expression;
6026
+ }
6027
+ }
6028
+ return expression;
6029
+ }
6030
+ //#endregion
6031
+ //#region src/json-schema-subset/expression/calculator.ts
6032
+ var CalculatorOperator = Object.freeze({
6033
+ Save: 0,
6034
+ OneOf: 1,
6035
+ AllOf: 2,
6036
+ AnyOf: 3,
6037
+ Not: 4,
6038
+ Swap: 5
6039
+ });
6040
+ function calculate(operator, expressions) {
6041
+ switch (operator) {
6042
+ case CalculatorOperator.Save: return expressions[0];
6043
+ case CalculatorOperator.OneOf: return calculateOneOf(expressions);
6044
+ case CalculatorOperator.AllOf:
6045
+ case CalculatorOperator.AnyOf: return calculateCombination(operator, expressions);
6046
+ case CalculatorOperator.Not:
6047
+ case CalculatorOperator.Swap: return calculateUnary(operator, expressions[0]);
6048
+ }
6049
+ }
6050
+ function swap(expression) {
6051
+ return calculateUnary(CalculatorOperator.Swap, expression);
6052
+ }
6053
+ /**
6054
+ * The oneOf operator is indivisible, so `a + b + c` must be evaluated as one expression.
6055
+ * ![](../../doc/images/all_of_expression.png)
6056
+ */
6057
+ function calculateOneOf(expressions) {
6058
+ if (expressions.length === 1) return expressions[0];
6059
+ const unionSet = calculateCombination(CalculatorOperator.AnyOf, expressions);
6060
+ const intersectionList = [];
6061
+ for (let i = 0; i < expressions.length; ++i) for (let j = i + 1; j < expressions.length; ++j) {
6062
+ const left = expressions[i];
6063
+ const right = expressions[j];
6064
+ const intersection = calculateCombination(CalculatorOperator.AllOf, [left, right]);
6065
+ intersectionList.push(intersection);
6066
+ }
6067
+ const banZone = calculateCombination(CalculatorOperator.AnyOf, intersectionList);
6068
+ const enableZone = calculateUnary(CalculatorOperator.Not, banZone);
6069
+ return calculateCombination(CalculatorOperator.AllOf, [unionSet, enableZone]);
6070
+ }
6071
+ function calculateCombination(operator, expressions) {
6072
+ if (expressions.length < 0) throw new Error("invalid expressions: empty array");
6073
+ let combination;
6074
+ switch (operator) {
6075
+ case CalculatorOperator.AllOf:
6076
+ combination = makeCombination(calculateAllOf);
6077
+ break;
6078
+ case CalculatorOperator.AnyOf:
6079
+ combination = makeCombination(calculateAnyOf);
6080
+ break;
6081
+ default: throw new Error(`invalid operator ${operator}`);
6082
+ }
6083
+ for (const expression of expressions) combination.push(expression);
6084
+ return combination.result;
6085
+ }
6086
+ function calculateUnary(operator, expression) {
6087
+ let calculator;
6088
+ let result = 0;
6089
+ switch (operator) {
6090
+ case CalculatorOperator.Not:
6091
+ calculator = calculateNot;
6092
+ break;
6093
+ case CalculatorOperator.Swap:
6094
+ calculator = calculateSwap;
6095
+ break;
6096
+ default: throw new Error(`invalid operator ${operator}`);
6097
+ }
6098
+ for (const [singleExpression, maskExpression] of ExpressionMaskList) if (maskExpression & expression) result |= calculator(singleExpression);
6099
+ return result;
6100
+ }
6101
+ function calculateAllOf(e1, e2) {
6102
+ let result = 0;
6103
+ switch (e1) {
6104
+ case ExpressionSingleResult.Equals:
6105
+ switch (e2) {
6106
+ case ExpressionSingleResult.Equals:
6107
+ result = ExpressionEquals;
6108
+ break;
6109
+ case ExpressionSingleResult.Containing:
6110
+ result = ExpressionEquals;
6111
+ break;
6112
+ case ExpressionSingleResult.ContainedBy:
6113
+ result = ExpressionContainedBy;
6114
+ break;
6115
+ case ExpressionSingleResult.Rejection:
6116
+ result = 0;
6117
+ break;
6118
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy;
6119
+ }
6120
+ break;
6121
+ case ExpressionSingleResult.Containing:
6122
+ switch (e2) {
6123
+ case ExpressionSingleResult.Equals:
6124
+ result = ExpressionEquals;
6125
+ break;
6126
+ case ExpressionSingleResult.Containing:
6127
+ result = ExpressionEquals | ExpressionContaining;
6128
+ break;
6129
+ case ExpressionSingleResult.ContainedBy:
6130
+ result = ExpressionContainedBy;
6131
+ break;
6132
+ case ExpressionSingleResult.Rejection:
6133
+ result = ExpressionRejection;
6134
+ break;
6135
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection | ExpressionContainedBy;
6136
+ }
6137
+ break;
6138
+ case ExpressionSingleResult.ContainedBy:
6139
+ switch (e2) {
6140
+ case ExpressionSingleResult.Equals:
6141
+ result = ExpressionContainedBy;
6142
+ break;
6143
+ case ExpressionSingleResult.Containing:
6144
+ result = ExpressionContainedBy;
6145
+ break;
6146
+ case ExpressionSingleResult.ContainedBy:
6147
+ result = ExpressionContainedBy;
6148
+ break;
6149
+ case ExpressionSingleResult.Rejection:
6150
+ result = 0;
6151
+ break;
6152
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy;
6153
+ }
6154
+ break;
6155
+ case ExpressionSingleResult.Rejection:
6156
+ switch (e2) {
6157
+ case ExpressionSingleResult.Equals:
6158
+ result = 0;
6159
+ break;
6160
+ case ExpressionSingleResult.Containing:
6161
+ result = ExpressionRejection;
6162
+ break;
6163
+ case ExpressionSingleResult.ContainedBy:
6164
+ result = 0;
6165
+ break;
6166
+ case ExpressionSingleResult.Rejection:
6167
+ result = ExpressionRejection;
6168
+ break;
6169
+ case ExpressionSingleResult.Intersection: result = ExpressionRejection;
6170
+ }
6171
+ break;
6172
+ case ExpressionSingleResult.Intersection: switch (e2) {
6173
+ case ExpressionSingleResult.Equals:
6174
+ result = ExpressionContainedBy;
6175
+ break;
6176
+ case ExpressionSingleResult.Containing:
6177
+ result = ExpressionIntersection | ExpressionContainedBy;
6178
+ break;
6179
+ case ExpressionSingleResult.ContainedBy:
6180
+ result = ExpressionContainedBy;
6181
+ break;
6182
+ case ExpressionSingleResult.Rejection:
6183
+ result = ExpressionRejection;
6184
+ break;
6185
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy | ExpressionRejection | ExpressionIntersection;
6186
+ }
6187
+ }
6188
+ return result;
6189
+ }
6190
+ function calculateAnyOf(e1, e2) {
6191
+ let result = 0;
6192
+ switch (e1) {
6193
+ case ExpressionSingleResult.Equals:
6194
+ switch (e2) {
6195
+ case ExpressionSingleResult.Equals:
6196
+ result = ExpressionEquals;
6197
+ break;
6198
+ case ExpressionSingleResult.Containing:
6199
+ result = ExpressionContaining;
6200
+ break;
6201
+ case ExpressionSingleResult.ContainedBy:
6202
+ result = ExpressionEquals;
6203
+ break;
6204
+ case ExpressionSingleResult.Rejection:
6205
+ result = ExpressionContaining;
6206
+ break;
6207
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining;
6208
+ }
6209
+ break;
6210
+ case ExpressionSingleResult.Containing:
6211
+ switch (e2) {
6212
+ case ExpressionSingleResult.Equals:
6213
+ result = ExpressionContaining;
6214
+ break;
6215
+ case ExpressionSingleResult.Containing:
6216
+ result = ExpressionContaining;
6217
+ break;
6218
+ case ExpressionSingleResult.ContainedBy:
6219
+ result = ExpressionContaining;
6220
+ break;
6221
+ case ExpressionSingleResult.Rejection:
6222
+ result = ExpressionContaining;
6223
+ break;
6224
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining;
6225
+ }
6226
+ break;
6227
+ case ExpressionSingleResult.ContainedBy:
6228
+ switch (e2) {
6229
+ case ExpressionSingleResult.Equals:
6230
+ result = ExpressionEquals;
6231
+ break;
6232
+ case ExpressionSingleResult.Containing:
6233
+ result = ExpressionContaining;
6234
+ break;
6235
+ case ExpressionSingleResult.ContainedBy:
6236
+ result = ExpressionEquals | ExpressionContainedBy;
6237
+ break;
6238
+ case ExpressionSingleResult.Rejection:
6239
+ result = ExpressionIntersection;
6240
+ break;
6241
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining | ExpressionIntersection;
6242
+ }
6243
+ break;
6244
+ case ExpressionSingleResult.Rejection:
6245
+ switch (e2) {
6246
+ case ExpressionSingleResult.Equals:
6247
+ result = ExpressionContaining;
6248
+ break;
6249
+ case ExpressionSingleResult.Containing:
6250
+ result = ExpressionContaining;
6251
+ break;
6252
+ case ExpressionSingleResult.ContainedBy:
6253
+ result = ExpressionIntersection;
6254
+ break;
6255
+ case ExpressionSingleResult.Rejection:
6256
+ result = ExpressionRejection;
6257
+ break;
6258
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection;
6259
+ }
6260
+ break;
6261
+ case ExpressionSingleResult.Intersection: switch (e2) {
6262
+ case ExpressionSingleResult.Equals:
6263
+ result = ExpressionContaining;
6264
+ break;
6265
+ case ExpressionSingleResult.Containing:
6266
+ result = ExpressionContaining;
6267
+ break;
6268
+ case ExpressionSingleResult.ContainedBy:
6269
+ result = ExpressionContaining | ExpressionIntersection;
6270
+ break;
6271
+ case ExpressionSingleResult.Rejection:
6272
+ result = ExpressionIntersection;
6273
+ break;
6274
+ case ExpressionSingleResult.Intersection: result = ExpressionContaining | ExpressionIntersection;
6275
+ }
6276
+ }
6277
+ return result;
6278
+ }
6279
+ function calculateNot(expression) {
6280
+ let result = 0;
6281
+ switch (expression) {
6282
+ case ExpressionSingleResult.Equals:
6283
+ result = ExpressionRejection;
6284
+ break;
6285
+ case ExpressionSingleResult.Containing:
6286
+ result = ExpressionRejection;
6287
+ break;
6288
+ case ExpressionSingleResult.ContainedBy:
6289
+ result = ExpressionIntersection;
6290
+ break;
6291
+ case ExpressionSingleResult.Rejection:
6292
+ result = ExpressionEquals | ExpressionContaining;
6293
+ break;
6294
+ case ExpressionSingleResult.Intersection: result = ExpressionContainedBy | ExpressionIntersection;
6295
+ }
6296
+ return result;
6297
+ }
6298
+ function calculateSwap(expression) {
6299
+ let result = 0;
6300
+ switch (expression) {
6301
+ case ExpressionSingleResult.Equals:
6302
+ result = ExpressionEquals;
6303
+ break;
6304
+ case ExpressionSingleResult.Containing:
6305
+ result = ExpressionContainedBy;
6306
+ break;
6307
+ case ExpressionSingleResult.ContainedBy:
6308
+ result = ExpressionContaining;
6309
+ break;
6310
+ case ExpressionSingleResult.Rejection:
6311
+ result = ExpressionRejection;
6312
+ break;
6313
+ case ExpressionSingleResult.Intersection: result = ExpressionIntersection;
6314
+ }
6315
+ return result;
6316
+ }
6317
+ //#endregion
6318
+ //#region src/json-schema-subset/expression/types.ts
6319
+ var ExpressionKind = Object.freeze({
6320
+ Leaf: 0,
6321
+ Not: 1,
6322
+ AllOf: 2,
6323
+ AnyOf: 3,
6324
+ OneOf: 4
5874
6325
  });
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]))
6326
+ //#endregion
6327
+ //#region src/json-schema-subset/expression/expression.ts
6328
+ var expression = (delegate) => (e1, e2) => {
6329
+ const rootNode = {
6330
+ parent: null,
6331
+ swapped: false,
6332
+ expressions: null,
6333
+ calculation: {
6334
+ operator: CalculatorOperator.Save,
6335
+ results: [0],
6336
+ willSwap: false,
6337
+ count: 0
6338
+ }
6339
+ };
6340
+ const extendQueue = [{
6341
+ parent: {
6342
+ node: rootNode,
6343
+ index: 0
6344
+ },
6345
+ swapped: false,
6346
+ expressions: [e1, e2],
6347
+ calculation: null
6348
+ }];
6349
+ const calculateQueue = [];
6350
+ while (extendQueue.length > 0 || calculateQueue.length > 0) {
6351
+ while (extendQueue.length > 0) extendNode(extendQueue.pop());
6352
+ while (calculateQueue.length > 0) calculateNode(calculateQueue.pop());
6353
+ }
6354
+ function extendNode(node) {
6355
+ let result = ExpressionEquals;
6356
+ const [leftExpression, rightExpression] = node.expressions;
6357
+ if (!delegate.equals(leftExpression, rightExpression)) {
6358
+ const expression1 = delegate.describe(leftExpression);
6359
+ if (expression1.kind !== ExpressionKind.Leaf) {
6360
+ const [calculation, expressions] = expendExpression(expression1, false);
6361
+ node.expressions = null;
6362
+ node.calculation = calculation;
6363
+ for (const [index, childExpression] of expressions.entries()) extendQueue.push({
6364
+ parent: {
6365
+ node,
6366
+ index
6367
+ },
6368
+ swapped: node.swapped,
6369
+ expressions: [childExpression, rightExpression],
6370
+ calculation: null
6371
+ });
6372
+ return;
6373
+ }
6374
+ const expression2 = delegate.describe(rightExpression);
6375
+ if (expression2.kind !== ExpressionKind.Leaf) {
6376
+ const [calculation, expressions] = expendExpression(expression2, true);
6377
+ node.expressions = null;
6378
+ node.calculation = calculation;
6379
+ for (const [index, childExpression] of expressions.entries()) extendQueue.push({
6380
+ parent: {
6381
+ node,
6382
+ index
6383
+ },
6384
+ swapped: !node.swapped,
6385
+ expressions: [childExpression, leftExpression],
6386
+ calculation: null
6387
+ });
6388
+ return;
6389
+ }
6390
+ result = delegate.calculate(leftExpression, rightExpression);
6391
+ delegate.observeCalculation?.(leftExpression, rightExpression, result, node.swapped);
6392
+ if (result === 0) throw new Error("cannot response expression as none");
6393
+ }
6394
+ node.expressions = null;
6395
+ node.calculation = {
6396
+ operator: CalculatorOperator.Save,
6397
+ results: [result],
6398
+ willSwap: false,
6399
+ count: 0
6400
+ };
6401
+ calculateQueue.push(node);
6402
+ }
6403
+ function expendExpression(description, willSwap) {
6404
+ let operator = CalculatorOperator.Save;
6405
+ let expressions;
6406
+ switch (description.kind) {
6407
+ case ExpressionKind.Not:
6408
+ operator = CalculatorOperator.Not;
6409
+ expressions = [description.expression];
6410
+ break;
6411
+ case ExpressionKind.AllOf:
6412
+ operator = CalculatorOperator.AllOf;
6413
+ expressions = [...description.expressions];
6414
+ break;
6415
+ case ExpressionKind.AnyOf:
6416
+ operator = CalculatorOperator.AnyOf;
6417
+ expressions = [...description.expressions];
6418
+ break;
6419
+ case ExpressionKind.OneOf:
6420
+ operator = CalculatorOperator.OneOf;
6421
+ expressions = [...description.expressions];
6422
+ break;
6423
+ default: throw new Error(`invalid kind ${description.kind}`);
6424
+ }
6425
+ return [{
6426
+ operator,
6427
+ willSwap,
6428
+ count: 0,
6429
+ results: Array(expressions.length).fill(-1)
6430
+ }, expressions];
6431
+ }
6432
+ function calculateNode(node) {
6433
+ const calculation = node.calculation;
6434
+ const parent = node.parent;
6435
+ let result = calculate(calculation.operator, calculation.results);
6436
+ if (result === 0) result = ExpressionContainedBy;
6437
+ if (calculation.willSwap) result = swap(result);
6438
+ if (parent) {
6439
+ const parentCalculation = parent.node.calculation;
6440
+ const parentResults = parentCalculation.results;
6441
+ parentResults[parent.index] = result;
6442
+ parentCalculation.count += 1;
6443
+ if (parentCalculation.count >= parentResults.length) calculateQueue.push(parent.node);
6444
+ }
6445
+ }
6446
+ const result = rootNode.calculation.results[0];
6447
+ if (result === 0) throw new Error("cannot find result of root");
6448
+ return result;
5895
6449
  };
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
- })
6450
+ //#endregion
6451
+ //#region src/json-schema-subset/error.ts
6452
+ var SchemaError = class extends Error {
6453
+ constructor(items = []) {
6454
+ super(createSchemaErrorMessage(items));
6455
+ this.name = "SchemaError";
6456
+ this.items = items;
6457
+ }
6458
+ };
6459
+ var SchemaErrorItemKind = Object.freeze({
6460
+ Compiled: 0,
6461
+ External: 1
6462
+ });
6463
+ function stringifySchemaError(errorItem) {
6464
+ switch (errorItem.kind) {
6465
+ case SchemaErrorItemKind.Compiled: {
6466
+ const { message, path } = errorItem;
6467
+ return `${message} (at ${path.length > 0 ? path.join(".") : "$root"})`;
6468
+ }
6469
+ case SchemaErrorItemKind.External: return String(errorItem.error);
6470
+ }
6471
+ }
6472
+ function createSchemaErrorMessage(items) {
6473
+ switch (items.length) {
6474
+ case 0: return "without any items";
6475
+ case 1: return stringifySchemaError(items[0]);
6476
+ default: return `${stringifySchemaError(items[0])} ... omit the rest ${items.length - 1} items`;
6477
+ }
6478
+ }
6479
+ //#endregion
6480
+ //#region src/json-schema-subset/compiler/common.ts
6481
+ var jsonSchemaKeys = /* @__PURE__ */ new Set([
6482
+ "type",
6483
+ "enum",
6484
+ "const",
6485
+ "multipleOf",
6486
+ "maximum",
6487
+ "exclusiveMaximum",
6488
+ "minimum",
6489
+ "exclusiveMinimum",
6490
+ "maxLength",
6491
+ "minLength",
6492
+ "pattern",
6493
+ "items",
6494
+ "additionalItems",
6495
+ "maxItems",
6496
+ "minItems",
6497
+ "uniqueItems",
6498
+ "contains",
6499
+ "maxProperties",
6500
+ "minProperties",
6501
+ "required",
6502
+ "properties",
6503
+ "patternProperties",
6504
+ "additionalProperties",
6505
+ "dependencies",
6506
+ "propertyNames",
6507
+ "if",
6508
+ "then",
6509
+ "else",
6510
+ "allOf",
6511
+ "anyOf",
6512
+ "oneOf",
6513
+ "not",
6514
+ "format",
6515
+ "contentMediaType",
6516
+ "contentEncoding",
6517
+ "definitions"
6518
+ ]);
6519
+ function isJSONSchemaKey(key) {
6520
+ return jsonSchemaKeys.has(key);
6521
+ }
6522
+ function isLogicEmptyObject(object) {
6523
+ for (const key in object) if (isJSONSchemaKey(key)) return false;
6524
+ return true;
6525
+ }
6526
+ function joinPath(context, ...extraPath) {
6527
+ return {
6528
+ ...context,
6529
+ path: [...context.path, ...extraPath]
6530
+ };
6531
+ }
6532
+ function unwrapJSONSchema7Definition(schema) {
6533
+ if (typeof schema === "boolean") throw new Error("JSONSchema7Definition cannot be boolean");
6534
+ return schema;
6535
+ }
6536
+ function recordError({ path, errors }, message, ...extraPath) {
6537
+ errors.push(createSchemaError(path, extraPath, message));
6538
+ }
6539
+ function recordWarn({ path, warns }, message, ...extraPath) {
6540
+ warns.push(createSchemaError(path, extraPath, message));
6541
+ }
6542
+ function createSchemaError(path, extraPath, message) {
6543
+ return {
6544
+ kind: SchemaErrorItemKind.Compiled,
6545
+ message,
6546
+ path: [...path, ...extraPath]
6547
+ };
6548
+ }
6549
+ //#endregion
6550
+ //#region src/json-schema-subset/compiler/utils.ts
6551
+ function cleanEmptyValues(origin) {
6552
+ for (const key in origin) {
6553
+ const value = origin[key];
6554
+ if (value === void 0) delete origin[key];
6555
+ else if (value && typeof value === "object") {
6556
+ if (Array.isArray(value)) {
6557
+ if (value.length === 0) delete origin[key];
6558
+ } else if (isEmptyObject(value)) delete origin[key];
6559
+ }
6560
+ }
6561
+ return origin;
6562
+ }
6563
+ function isEmptyObject(object) {
6564
+ for (const _ in object) return false;
6565
+ return true;
6566
+ }
6567
+ //#endregion
6568
+ //#region src/json-schema-subset/compiler/wrapper.ts
6569
+ var symbolID = Symbol("compiledId");
6570
+ var symbolKind = Symbol("compiledKind");
6571
+ var symbolPath = Symbol("compiledPath");
6572
+ var symbolValidatorLoader = Symbol("validatorLoader");
6573
+ var CompiledKind = Object.freeze({
6574
+ Extends: 0,
6575
+ Never: 1,
6576
+ Any: 2,
6577
+ Null: 3,
6578
+ String: 4,
6579
+ Numeric: 5,
6580
+ Boolean: 6,
6581
+ Object: 7,
6582
+ Array: 8,
6583
+ Not: 9,
6584
+ Combination: 10,
6585
+ EnumOrConst: 11
6586
+ });
6587
+ var ANY = deepFreeze(toCompiledSchema(CompiledKind.Any, createId(), {}, () => () => true));
6588
+ var NEVER = deepFreeze(toCompiledSchema(CompiledKind.Never, createId(), {
6589
+ type: "string",
6590
+ maxLength: 0,
6591
+ minLength: 1
6592
+ }, () => () => false));
6593
+ function isCompiledObject(value) {
6594
+ if (value === null || typeof value !== "object") return false;
6595
+ return symbolID in value;
6596
+ }
6597
+ function isCompiledSchema(object) {
6598
+ if (object === null || typeof object !== "object") return false;
6599
+ return symbolID in object && symbolKind in object;
6600
+ }
6601
+ function getKind(schema) {
6602
+ if (isCompiledSchema(schema)) return schema[symbolKind];
6603
+ else return CompiledKind.Extends;
6604
+ }
6605
+ function getId(schema) {
6606
+ if (isCompiledSchema(schema) || isCompiledObject(schema)) return schema[symbolID];
6607
+ else return schema.id;
6608
+ }
6609
+ function getPath(schema) {
6610
+ return isCompiledSchema(schema) ? schema[symbolPath] : void 0;
6611
+ }
6612
+ function wrapCompiledValue(value) {
6613
+ if (value === null || typeof value !== "object") return value;
6614
+ Object.defineProperty(value, symbolID, {
6615
+ value: createId(),
6616
+ configurable: false,
6617
+ writable: false,
6618
+ enumerable: false
6619
+ });
6620
+ return value;
6621
+ }
6622
+ function wrapCompiledSchema(kind, schema, delegate, path = []) {
6623
+ return toCompiledSchema(kind, createId(), schema, delegate && (() => {
6624
+ return delegate.compile(schema);
6625
+ }), path);
6626
+ }
6627
+ function toNever(schema) {
6628
+ return toCompiledSchema(CompiledKind.Never, createId(), { ...schema }, schema[symbolValidatorLoader], schema[symbolPath]);
6629
+ }
6630
+ function toCompiledSchema(kind, id, schema, validatorLoader, path = []) {
6631
+ let validator = null;
6632
+ Object.defineProperties(schema, {
6633
+ [symbolKind]: {
6634
+ value: kind,
6635
+ configurable: false,
6636
+ writable: false,
6637
+ enumerable: false
6638
+ },
6639
+ [symbolID]: {
6640
+ value: id,
6641
+ configurable: false,
6642
+ writable: false,
6643
+ enumerable: false
6644
+ },
6645
+ [symbolPath]: {
6646
+ value: path,
6647
+ configurable: false,
6648
+ writable: false,
6649
+ enumerable: false
6650
+ },
6651
+ [symbolValidatorLoader]: {
6652
+ value: validatorLoader,
6653
+ configurable: false,
6654
+ writable: false,
6655
+ enumerable: false
6656
+ },
6657
+ isValid: {
6658
+ configurable: false,
6659
+ enumerable: false,
6660
+ get: () => {
6661
+ if (validatorLoader) {
6662
+ if (!validator) validator = validatorLoader();
6663
+ return validator;
6664
+ } else return;
6665
+ }
6666
+ }
6667
+ });
6668
+ return schema;
6669
+ }
6670
+ //#endregion
6671
+ //#region src/json-schema-subset/compiler/array.ts
6672
+ function compileArraySchema(context, schema) {
6673
+ let items = compileItems(context, schema);
6674
+ let maxItems = getItemsLimit(context, "maxItems", schema);
6675
+ const minItems = getItemsLimit(context, "minItems", schema);
6676
+ const contains = compileContains(context, schema);
6677
+ const uniqueItems = schema.uniqueItems;
6678
+ let additionalItems;
6679
+ if (Array.isArray(items)) additionalItems = compileAdditionalItems(context, schema);
6680
+ else if (schema.additionalItems) recordWarn(context, "it is needless when items is not array", "additionalItems");
6681
+ if (!items || !contains || additionalItems === null) return null;
6682
+ let isNever = false;
6683
+ let updateMaxItems = false;
6684
+ if (Array.isArray(items)) {
6685
+ if (maxItems !== void 0 && maxItems <= items.length) {
6686
+ items = items.splice(maxItems);
6687
+ additionalItems = variableToNever(additionalItems, context.delegate);
6688
+ }
6689
+ const firstNeverItemIndex = items.findIndex((item) => getKind(item) === CompiledKind.Never);
6690
+ if (firstNeverItemIndex !== -1) {
6691
+ items = items.splice(firstNeverItemIndex);
6692
+ additionalItems = variableToNever(additionalItems, context.delegate);
6693
+ if (maxItems === void 0) {
6694
+ maxItems = items.length;
6695
+ updateMaxItems = true;
6696
+ }
6697
+ }
6698
+ if (minItems !== void 0 && items.length < minItems) {
6699
+ recordWarn(context, `length(${items.length}) of items if less than minItems(${minItems})`);
6700
+ isNever = true;
6701
+ }
6702
+ if (items.length === 0 && additionalItems && getKind(additionalItems) === CompiledKind.Never) isNever = true;
6703
+ } else if (getKind(items) === CompiledKind.Never) isNever = true;
6704
+ if (maxItems !== void 0 && minItems !== void 0 && maxItems < minItems) {
6705
+ if (!updateMaxItems) recordWarn(context, `maxItems(${maxItems}) is less than minItems(${minItems})`);
6706
+ isNever = true;
6707
+ }
6708
+ return wrapCompiledSchema(isNever ? CompiledKind.Never : CompiledKind.Array, cleanEmptyValues({
6709
+ type: "array",
6710
+ items,
6711
+ contains,
6712
+ uniqueItems,
6713
+ maxItems,
6714
+ minItems,
6715
+ additionalItems
6716
+ }), context.delegate, context.path);
6717
+ }
6718
+ function compileItems(context, { items }) {
6719
+ if (!items) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6720
+ if (Array.isArray(items)) {
6721
+ const schemas = [];
6722
+ let hasAnyError = false;
6723
+ for (const [i, item] of items.entries()) {
6724
+ const schema = compileSchema(joinPath(context, "items", i), unwrapJSONSchema7Definition(item));
6725
+ if (!schema) {
6726
+ hasAnyError = true;
6727
+ continue;
6728
+ }
6729
+ schemas.push(schema);
6730
+ }
6731
+ if (hasAnyError) return null;
6732
+ return schemas;
6733
+ } else return compileSchema(joinPath(context, "items"), unwrapJSONSchema7Definition(items));
6734
+ }
6735
+ function getItemsLimit(context, name, schema) {
6736
+ const propertiesLimit = schema[name];
6737
+ if (propertiesLimit === void 0) return;
6738
+ if (Number.isNaN(propertiesLimit)) {
6739
+ recordWarn(context, "find NaN", name);
6740
+ return;
6741
+ }
6742
+ if (propertiesLimit < 0) {
6743
+ recordWarn(context, `find invalid number ${propertiesLimit}`, name);
6744
+ return;
6745
+ }
6746
+ return propertiesLimit;
6747
+ }
6748
+ function compileContains(context, { contains }) {
6749
+ if (!contains) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6750
+ return compileSchema(joinPath(context, "contains"), unwrapJSONSchema7Definition(contains));
6751
+ }
6752
+ function compileAdditionalItems(context, { additionalItems }) {
6753
+ switch (typeof additionalItems) {
6754
+ case "boolean": if (additionalItems) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6755
+ else return false;
6756
+ case "object": return compileSchema(joinPath(context, "additionalItems"), additionalItems);
6757
+ default: return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6758
+ }
6759
+ }
6760
+ function variableToNever(schema, delegate) {
6761
+ if (schema === void 0) return wrapCompiledSchema(CompiledKind.Never, {
6762
+ type: "string",
6763
+ maxLength: 0,
6764
+ minLength: 1
6765
+ }, delegate);
6766
+ else if (isCompiledSchema(schema)) return getKind(schema) === CompiledKind.Never ? schema : toNever(schema);
6767
+ else return schema;
6768
+ }
6769
+ //#endregion
6770
+ //#region src/json-schema-subset/compiler/combination.ts
6771
+ var COMBINATION_KEYS = Object.freeze([
6772
+ "allOf",
6773
+ "anyOf",
6774
+ "oneOf"
6775
+ ]);
6776
+ function compileCombinationSchema(context, key, combinationList, delegate) {
6777
+ if (combinationList.length === 0) {
6778
+ recordError(context, "disable empty list", key);
6779
+ return null;
6780
+ }
6781
+ const compiledCombinationList = [];
6782
+ for (const [i, element] of combinationList.entries()) {
6783
+ const compiledSchema = compileSchema(joinPath(context, key, i), unwrapJSONSchema7Definition(element));
6784
+ if (compiledSchema) compiledCombinationList.push(compiledSchema);
6785
+ }
6786
+ if (compiledCombinationList.length < combinationList.length) return null;
6787
+ let anyCount = 0;
6788
+ let neverCount = 0;
6789
+ for (const compiledSchema of compiledCombinationList) switch (getKind(compiledSchema)) {
6790
+ case CompiledKind.Any:
6791
+ anyCount += 1;
6792
+ break;
6793
+ case CompiledKind.Never: neverCount += 1;
6794
+ }
6795
+ let kind = CompiledKind.Combination;
6796
+ switch (key) {
6797
+ case "allOf":
6798
+ if (neverCount > 0) kind = CompiledKind.Never;
6799
+ else if (anyCount === compiledCombinationList.length) kind = CompiledKind.Any;
6800
+ else if (!areAllTypesTheSame(compiledCombinationList)) kind = CompiledKind.Never;
6801
+ break;
6802
+ case "anyOf":
6803
+ if (anyCount > 0) kind = CompiledKind.Any;
6804
+ else if (neverCount === compiledCombinationList.length) kind = CompiledKind.Never;
6805
+ break;
6806
+ case "oneOf": if (anyCount > 1) kind = CompiledKind.Never;
6807
+ else if (neverCount === compiledCombinationList.length) kind = CompiledKind.Never;
6808
+ else if (anyCount === 1 && neverCount === compiledCombinationList.length - 1) kind = CompiledKind.Any;
6809
+ }
6810
+ return wrapCompiledSchema(kind, { [key]: compiledCombinationList }, delegate, context.path);
6811
+ }
6812
+ function areAllTypesTheSame(combinationList) {
6813
+ let lastKind = null;
6814
+ for (const schema of combinationList) {
6815
+ const kind = getKind(schema);
6816
+ switch (kind) {
6817
+ case CompiledKind.Any:
6818
+ case CompiledKind.Never: break;
6819
+ default: if (lastKind === null) lastKind = kind;
6820
+ else if (lastKind !== kind) return false;
6821
+ }
6822
+ }
6823
+ return true;
6824
+ }
6825
+ //#endregion
6826
+ //#region src/json-schema-subset/checker/validator.ts
6827
+ var ValidResult = Object.freeze({
6828
+ Valid: 0,
6829
+ Invalid: 1,
6830
+ Unknown: 2
6831
+ });
6832
+ function valid(compiledSchema, value) {
6833
+ const isValid = compiledSchema.isValid;
6834
+ if (isValid) {
6835
+ if (isValid(value) === true) return ValidResult.Valid;
6836
+ else return ValidResult.Invalid;
6837
+ } else return ValidResult.Unknown;
6838
+ }
6839
+ //#endregion
6840
+ //#region src/json-schema-subset/compiler/enumAndConst.ts
6841
+ function compileEnumAndConst(context, enumList, constValue, schema) {
6842
+ let compiledEnum;
6843
+ let isNever = false;
6844
+ if (enumList) {
6845
+ if (enumList.length === 0) {
6846
+ recordError(context, "disable empty list", "enum");
6847
+ return null;
6848
+ }
6849
+ compiledEnum = [];
6850
+ for (const [i, enumValue] of enumList.entries()) switch (valid(schema, enumValue)) {
6851
+ case ValidResult.Valid:
6852
+ compiledEnum.push(wrapCompiledValue(enumValue));
6853
+ break;
6854
+ case ValidResult.Invalid: recordWarn(context, "cannot pass JSON schema of currently schema object", "enum", i);
6855
+ }
6856
+ if (compiledEnum.length === 0) recordWarn(context, "all of elements from list is rejected by currently schema object", "enum");
6857
+ }
6858
+ if (constValue && valid(schema, constValue) === ValidResult.Invalid) isNever = true;
6859
+ if (compiledEnum) {
6860
+ if (compiledEnum.length === 0) isNever = true;
6861
+ else if (constValue) {
6862
+ let foundEquals = false;
6863
+ for (const enumValue of compiledEnum) if (isDeepEquals(enumValue, constValue)) {
6864
+ foundEquals = true;
6865
+ break;
6866
+ }
6867
+ if (!foundEquals) isNever = true;
6868
+ }
6869
+ }
6870
+ const kind = isNever ? CompiledKind.Never : CompiledKind.EnumOrConst;
6871
+ const compiledSchema = {};
6872
+ if (schema.type) compiledSchema.type = schema.type;
6873
+ if (compiledEnum) compiledSchema.enum = compiledEnum;
6874
+ if (constValue) compiledSchema.const = wrapCompiledValue(deepCopy(constValue));
6875
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
6876
+ }
6877
+ //#endregion
6878
+ //#region src/json-schema-subset/compiler/object.ts
6879
+ var OBJECT_KEYS = /* @__PURE__ */ new Set([
6880
+ "type",
6881
+ "maxProperties",
6882
+ "minProperties",
6883
+ "required",
6884
+ "properties",
6885
+ "patternProperties",
6886
+ "additionalProperties",
6887
+ "dependencies",
6888
+ "propertyNames"
6889
+ ]);
6890
+ function compileObjectSchema(context, schema) {
6891
+ const rejectKeys = Object.keys(schema).filter((k) => !OBJECT_KEYS.has(k) && isJSONSchemaKey(k));
6892
+ if (rejectKeys.length > 0) recordWarn(context, `type="object" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
6893
+ const maxProperties = getPropertiesLimit(context, "maxProperties", schema);
6894
+ const minProperties = getPropertiesLimit(context, "minProperties", schema);
6895
+ const additionalPropertiesSchema = compileAdditionalProperties(context, schema);
6896
+ const patternProperties = compilePatternProperties(context, schema);
6897
+ const propertyNames = compilePropertyNames(context, schema);
6898
+ const dependentTuple = compileDependencies(context, schema);
6899
+ if (!additionalPropertiesSchema || !patternProperties || !propertyNames || !dependentTuple) return null;
6900
+ const properties = compileProperties(context, patternProperties, propertyNames, schema);
6901
+ if (!properties) return null;
6902
+ const required = compileRequired(context, createBanKeyChecker(additionalPropertiesSchema, patternProperties, propertyNames, properties), dependentTuple, schema);
6903
+ return wrapCompiledSchema(checkSchemaIsNever(context, additionalPropertiesSchema, properties, required, maxProperties, minProperties) ? CompiledKind.Never : CompiledKind.Object, cleanEmptyValues({
6904
+ type: "object",
6905
+ required,
6906
+ properties,
6907
+ minProperties,
6908
+ maxProperties,
6909
+ additionalProperties: additionalPropertiesSchema,
6910
+ patternProperties: unwrapPatternProperties(patternProperties),
6911
+ dependencies: mergeDependentTuple(dependentTuple, schema),
6912
+ propertyNames
6913
+ }), context.delegate, context.path);
6914
+ }
6915
+ function getPropertiesLimit(context, name, schema) {
6916
+ const propertiesLimit = schema[name];
6917
+ if (propertiesLimit === void 0) return;
6918
+ if (Number.isNaN(propertiesLimit)) {
6919
+ recordWarn(context, "find NaN", name);
6920
+ return;
6921
+ }
6922
+ if (propertiesLimit < 0) {
6923
+ recordWarn(context, `find invalid number ${propertiesLimit}`, name);
6924
+ return;
6925
+ }
6926
+ return propertiesLimit;
6927
+ }
6928
+ function compileAdditionalProperties(context, { additionalProperties }) {
6929
+ if (additionalProperties === false) return wrapCompiledSchema(CompiledKind.Never, {
6930
+ type: "string",
6931
+ maxLength: 0,
6932
+ minLength: 1
6933
+ }, context.delegate, context.path);
6934
+ if (typeof additionalProperties !== "object") return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6935
+ return compileSchema(joinPath(context, "additionalProperties"), unwrapJSONSchema7Definition(additionalProperties));
6936
+ }
6937
+ function compilePatternProperties(context, { patternProperties }) {
6938
+ let foundSubError = false;
6939
+ const target = {};
6940
+ for (const key in patternProperties) {
6941
+ const regExp = wrapRegExp(key);
6942
+ if (regExp instanceof Error) {
6943
+ recordWarn(context, `property name invalid. ${key}`, "patternProperties", key);
6944
+ continue;
6945
+ }
6946
+ const schema = unwrapJSONSchema7Definition(patternProperties[key]);
6947
+ const compiledSchema = compileSchema(joinPath(context, "patternProperties", key), schema);
6948
+ if (!compiledSchema) {
6949
+ foundSubError = true;
6950
+ continue;
6951
+ }
6952
+ target[key] = [compiledSchema, regExp];
6953
+ }
6954
+ if (foundSubError) return null;
6955
+ return target;
6956
+ }
6957
+ function compilePropertyNames(context, { propertyNames }) {
6958
+ if (!propertyNames) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
6959
+ propertyNames = unwrapJSONSchema7Definition(propertyNames);
6960
+ const schema = compileSchema(joinPath(context, "propertyNames"), propertyNames);
6961
+ if (!schema) return null;
6962
+ const kind = getKind(schema);
6963
+ if (kind !== CompiledKind.String && kind !== CompiledKind.Any) return toNever(schema);
6964
+ return schema;
6965
+ }
6966
+ function compileProperties(context, patternProperties, propertyNamesSchema, { properties }) {
6967
+ let foundSubError = false;
6968
+ if (!properties) return {};
6969
+ const target = {};
6970
+ for (const key in properties) {
6971
+ if (valid(propertyNamesSchema, key) === ValidResult.Invalid) {
6972
+ recordWarn(context, `key ${JSON.stringify(key)} cannot pass JSON schema from propertyNames`, "properties");
6973
+ continue;
6974
+ }
6975
+ const patternSchema = findPatternSchema(patternProperties, key);
6976
+ if (patternSchema && getKind(patternSchema) === CompiledKind.Never) {
6977
+ recordWarn(context, `key ${JSON.stringify(key)} matches a pattern that has a impossible(never) schema`, "properties");
6978
+ continue;
6979
+ }
6980
+ const schema = unwrapJSONSchema7Definition(properties[key]);
6981
+ const compiledSchema = compileSchema(joinPath(context, "properties", key), schema);
6982
+ if (!compiledSchema) {
6983
+ foundSubError = true;
6984
+ continue;
6985
+ }
6986
+ target[key] = compiledSchema;
6987
+ }
6988
+ if (foundSubError) return null;
6989
+ return target;
6990
+ }
6991
+ function compileDependencies(context, { dependencies }) {
6992
+ if (!dependencies) return [{}, {}];
6993
+ const dependentRequired = {};
6994
+ const dependentSchemas = {};
6995
+ for (const key in dependencies) {
6996
+ const dependency = unwrapJSONSchema7Definition(dependencies[key]);
6997
+ if (Array.isArray(dependency)) {
6998
+ const { keys, duplicated } = checkUniqueKeys(dependency);
6999
+ if (duplicated) recordWarn(context, `found duplicated property names: ${duplicated.join(", ")}`, "dependencies", key);
7000
+ dependentRequired[key] = keys;
7001
+ } else {
7002
+ const compiledSchema = compileSchema(joinPath(context, "dependencies", key), dependency);
7003
+ if (compiledSchema) {
7004
+ const kind = getKind(compiledSchema);
7005
+ if (kind === CompiledKind.Object || kind === CompiledKind.Any) dependentSchemas[key] = compiledSchema;
7006
+ else if (kind === CompiledKind.Extends) dependentSchemas[key] = NEVER;
7007
+ else dependentSchemas[key] = toNever(compiledSchema);
7008
+ }
7009
+ }
7010
+ }
7011
+ return [dependentRequired, dependentSchemas];
7012
+ }
7013
+ function createBanKeyChecker(additionalPropertiesSchema, patternProperties, propertyNamesSchema, properties) {
7014
+ return (key) => {
7015
+ if (valid(propertyNamesSchema, key) === ValidResult.Invalid) return true;
7016
+ const patternSchema = findPatternSchema(patternProperties, key);
7017
+ if (patternSchema && getKind(patternSchema) === CompiledKind.Never) return true;
7018
+ if (getKind(properties[key] ?? additionalPropertiesSchema) === CompiledKind.Never) return true;
7019
+ return false;
7020
+ };
7021
+ }
7022
+ function compileRequired(context, isBan, dependentTuple, { required }) {
7023
+ if (!required) return [];
7024
+ const uniqueCheckedResult = checkUniqueKeys(required);
7025
+ if (uniqueCheckedResult.duplicated) recordWarn(context, `found duplicated required keys: ${uniqueCheckedResult.duplicated.join(", ")}`, "required");
7026
+ const requiredKeys = [];
7027
+ const banKeys = [];
7028
+ for (const requiredKey of uniqueCheckedResult.keys) if (collectDependencies(dependentTuple, requiredKey).some((key) => isBan(key))) banKeys.push(requiredKey);
7029
+ else requiredKeys.push(requiredKey);
7030
+ if (banKeys.length > 0) recordWarn(context, `key ${banKeys.map((k) => JSON.stringify(k)).join(", ")} will ban by another condition`, "required");
7031
+ return requiredKeys;
7032
+ }
7033
+ function checkSchemaIsNever(context, additionalPropertiesSchema, properties, required, maxProperties, minProperties) {
7034
+ if (maxProperties !== void 0 && minProperties !== void 0 && maxProperties < minProperties) {
7035
+ recordWarn(context, `maxProperties(${maxProperties}) is less than minProperties(${minProperties})`);
7036
+ return true;
7037
+ }
7038
+ if (maxProperties !== void 0 && required.length > maxProperties) {
7039
+ recordWarn(context, `length(${required.length}) of required is greater than maxProperties(${maxProperties})`);
7040
+ return true;
7041
+ }
7042
+ if (minProperties !== void 0 && required.length < minProperties) {
7043
+ recordWarn(context, `length(${required.length}) of required is less than minProperties(${minProperties})`);
7044
+ return true;
7045
+ }
7046
+ if (getKind(additionalPropertiesSchema) !== CompiledKind.Never) return false;
7047
+ for (const key in properties) {
7048
+ const compiledSchema = properties[key];
7049
+ if (getKind(compiledSchema) !== CompiledKind.Never) return false;
7050
+ }
7051
+ return true;
7052
+ }
7053
+ function collectDependencies([dependentRequired, dependentSchemas], seedKey) {
7054
+ const queue = [seedKey];
7055
+ const collection = new Set(queue);
7056
+ while (queue.length > 0) {
7057
+ const key = queue.pop();
7058
+ const schema = dependentSchemas[key];
7059
+ const requiredKeys = dependentRequired[key];
7060
+ if (schema) {
7061
+ if (getKind(schema) === CompiledKind.Object) collectKeys(schema.required);
7062
+ }
7063
+ if (requiredKeys) collectKeys(requiredKeys);
7064
+ }
7065
+ function collectKeys(keys) {
7066
+ if (keys) {
7067
+ for (const key of keys) if (!collection.has(key)) {
7068
+ collection.add(key);
7069
+ queue.push(key);
7070
+ }
7071
+ }
7072
+ }
7073
+ return [...collection];
7074
+ }
7075
+ function checkUniqueKeys(keys) {
7076
+ const checking = /* @__PURE__ */ new Set();
7077
+ const duplicated = /* @__PURE__ */ new Set();
7078
+ for (const e of keys) if (checking.has(e)) duplicated.add(e);
7079
+ else checking.add(e);
7080
+ if (duplicated.size === 0) return {
7081
+ keys: [...keys],
7082
+ duplicated: null
7083
+ };
7084
+ else return {
7085
+ keys: [...checking],
7086
+ duplicated: [...duplicated]
7087
+ };
7088
+ }
7089
+ function findPatternSchema(patternProperties, checkedKey) {
7090
+ for (const key in patternProperties) {
7091
+ const [schema, regExp] = patternProperties[key];
7092
+ if (regExp.test(checkedKey)) return schema;
7093
+ }
7094
+ return null;
7095
+ }
7096
+ function wrapRegExp(pattern) {
7097
+ try {
7098
+ return new RegExp(pattern, "i");
7099
+ } catch (error) {
7100
+ if (error instanceof SyntaxError) return error;
7101
+ else throw error;
7102
+ }
7103
+ }
7104
+ function unwrapPatternProperties(patternProperties) {
7105
+ const target = {};
7106
+ for (const key in patternProperties) target[key] = patternProperties[key][0];
7107
+ return target;
7108
+ }
7109
+ function mergeDependentTuple([dependentRequired, dependentSchemas], { dependencies }) {
7110
+ const target = {};
7111
+ for (const key in dependencies) {
7112
+ const required = dependentRequired[key];
7113
+ const schema = dependentSchemas[key];
7114
+ target[key] = required || schema;
7115
+ }
7116
+ return target;
7117
+ }
7118
+ //#endregion
7119
+ //#region src/json-schema-subset/compiler/primitive.ts
7120
+ var NUMERIC_KEYS = /* @__PURE__ */ new Set([
7121
+ "type",
7122
+ "multipleOf",
7123
+ "maximum",
7124
+ "exclusiveMaximum",
7125
+ "minimum",
7126
+ "exclusiveMinimum"
7127
+ ]);
7128
+ var STRING_KEYS = /* @__PURE__ */ new Set([
7129
+ "type",
7130
+ "format",
7131
+ "maxLength",
7132
+ "minLength",
7133
+ "pattern"
7134
+ ]);
7135
+ function compilePrimitiveSchema(context, schema) {
7136
+ const { type } = schema;
7137
+ switch (type) {
7138
+ case "number":
7139
+ case "integer": return compileNumericSchema(context, schema);
7140
+ case "string": return compileStringSchema(context, schema);
7141
+ case "boolean":
7142
+ case "null": {
7143
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== "type");
7144
+ if (rejectKeys.length > 0) recordWarn(context, `key "type" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7145
+ return wrapCompiledSchema(type === "null" ? CompiledKind.Null : CompiledKind.Boolean, { type }, context.delegate, context.path);
7146
+ }
7147
+ default:
7148
+ recordError(context, `invalid type ${JSON.stringify(type)}`);
7149
+ return null;
7150
+ }
7151
+ }
7152
+ function compileNumericSchema(context, schema) {
7153
+ const rejectKeys = Object.keys(schema).filter((k) => !NUMERIC_KEYS.has(k) && isJSONSchemaKey(k));
7154
+ if (rejectKeys.length > 0) recordWarn(context, `type=${JSON.stringify(schema.type)} will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7155
+ const compiledSchema = pick(schema, NUMERIC_KEYS);
7156
+ for (const key of NUMERIC_KEYS) {
7157
+ const value = compiledSchema[key];
7158
+ if (key !== "type" && value !== void 0 && Number.isNaN(value)) {
7159
+ recordWarn(context, "found NaN", key);
7160
+ delete compiledSchema[key];
7161
+ }
7162
+ }
7163
+ const { maximum, exclusiveMaximum, minimum, exclusiveMinimum } = compiledSchema;
7164
+ if (maximum !== void 0 && exclusiveMaximum !== void 0) {
7165
+ if (maximum === exclusiveMaximum) delete compiledSchema.maximum;
7166
+ else if (maximum < exclusiveMaximum) delete compiledSchema.exclusiveMaximum;
7167
+ else if (maximum > exclusiveMaximum) delete compiledSchema.maximum;
7168
+ }
7169
+ if (minimum !== void 0 && exclusiveMinimum !== void 0) {
7170
+ if (minimum === exclusiveMinimum) delete compiledSchema.minimum;
7171
+ else if (minimum < exclusiveMinimum) delete compiledSchema.exclusiveMinimum;
7172
+ else if (minimum > exclusiveMinimum) delete compiledSchema.minimum;
7173
+ }
7174
+ const { multipleOf } = compiledSchema;
7175
+ if (multipleOf === 0) {
7176
+ delete compiledSchema.multipleOf;
7177
+ compiledSchema.type = "number";
7178
+ recordWarn(context, "cannot be 0", "multipleOf");
7179
+ }
7180
+ let kind = CompiledKind.Numeric;
7181
+ if (!isNumericPossibleInvalid(compiledSchema)) kind = CompiledKind.Never;
7182
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
7183
+ }
7184
+ function isNumericPossibleInvalid(compiledSchema) {
7185
+ const { maximum, exclusiveMaximum, minimum, exclusiveMinimum } = compiledSchema;
7186
+ if (maximum !== void 0 && minimum !== void 0) return maximum >= minimum;
7187
+ else if (exclusiveMaximum !== void 0 && minimum !== void 0) return exclusiveMaximum > minimum;
7188
+ else if (maximum !== void 0 && exclusiveMinimum !== void 0) return maximum > exclusiveMinimum;
7189
+ else if (exclusiveMaximum !== void 0 && exclusiveMinimum !== void 0) return exclusiveMaximum > exclusiveMinimum;
7190
+ else return true;
7191
+ }
7192
+ function compileStringSchema(context, schema) {
7193
+ const rejectKeys = Object.keys(schema).filter((k) => !STRING_KEYS.has(k) && isJSONSchemaKey(k));
7194
+ if (rejectKeys.length > 0) recordWarn(context, `type="string" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7195
+ const compiledSchema = pick(schema, STRING_KEYS);
7196
+ cleanInvalidLength(context, compiledSchema, "maxLength");
7197
+ cleanInvalidLength(context, compiledSchema, "minLength");
7198
+ const max = compiledSchema.maxLength;
7199
+ const min = compiledSchema.minLength;
7200
+ let kind = CompiledKind.String;
7201
+ if (max !== void 0) {
7202
+ if (max < 0) kind = CompiledKind.Never;
7203
+ else if (max !== void 0 && min !== void 0 && max < min) kind = CompiledKind.Never;
7204
+ }
7205
+ return wrapCompiledSchema(kind, compiledSchema, context.delegate, context.path);
7206
+ }
7207
+ function cleanInvalidLength(context, compiledSchema, key) {
7208
+ const length = compiledSchema[key];
7209
+ if (length !== void 0) {
7210
+ if (Number.isNaN(length)) {
7211
+ recordWarn(context, "found NaN", key);
7212
+ delete compiledSchema[key];
7213
+ }
7214
+ }
7215
+ }
7216
+ //#endregion
7217
+ //#region src/json-schema-subset/compiler/compiler.ts
7218
+ var emptyList = Object.freeze([]);
7219
+ function compile(schema, extendsContext, payload, delegate) {
7220
+ if (isCompiledSchema(schema)) return {
7221
+ schema,
7222
+ warns: emptyList
7223
+ };
7224
+ if (extendsContext.isExtendsSchema(schema)) return {
7225
+ schema,
7226
+ warns: emptyList
7227
+ };
7228
+ if (delegate) {
7229
+ const isSchemaResult = delegate.isSchema(schema);
7230
+ if (typeof isSchemaResult === "object") {
7231
+ const items = [];
7232
+ for (const error of isSchemaResult) items.push({
7233
+ kind: SchemaErrorItemKind.External,
7234
+ error
7235
+ });
7236
+ if (items.length > 0) return items;
7237
+ } else if (isSchemaResult === false) throw new Error("it is not a JSON Schema 7");
7238
+ }
7239
+ const context = {
7240
+ delegate,
7241
+ payload,
7242
+ extends: extendsContext,
7243
+ path: [],
7244
+ errors: [],
7245
+ warns: []
7246
+ };
7247
+ const compiledSchema = compileSchema(context, schema);
7248
+ if (compiledSchema) assertCondition(context.errors.length === 0, "found errors (it should be empty)");
7249
+ else {
7250
+ assertCondition(context.errors.length > 0, "cannot found any errors");
7251
+ return context.errors;
7252
+ }
7253
+ return {
7254
+ schema: compiledSchema,
7255
+ warns: context.warns
7256
+ };
7257
+ }
7258
+ function assertCondition(condition, message) {
7259
+ if (!condition) throw new Error(message);
7260
+ }
7261
+ function compileSchema(context, schema) {
7262
+ if (context.extends.isExtendsSchema(schema)) return schema;
7263
+ if (isCompiledSchema(schema)) return schema;
7264
+ const extendsSchema = context.extends.tryCompiledExtendsSchema(schema, context.payload);
7265
+ if (extendsSchema) return extendsSchema;
7266
+ let targetSchema = schema;
7267
+ let shouldHandleEnumAndConst = false;
7268
+ const { enum: enumList, const: constValue } = schema;
7269
+ if (enumList || constValue) {
7270
+ const { enum: _0, const: _1, ...rest } = schema;
7271
+ targetSchema = rest;
7272
+ shouldHandleEnumAndConst = true;
7273
+ }
7274
+ let compiledSchema = checkAndCompileSchema(context, targetSchema);
7275
+ if (compiledSchema && shouldHandleEnumAndConst) compiledSchema = compileEnumAndConst(context, enumList, constValue, compiledSchema);
7276
+ if (!compiledSchema) return null;
7277
+ return compiledSchema;
7278
+ }
7279
+ function checkAndCompileSchema(context, schema) {
7280
+ for (const key of COMBINATION_KEYS) {
7281
+ const combinationList = schema[key];
7282
+ if (combinationList) {
7283
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== key);
7284
+ if (rejectKeys.length > 0) recordWarn(context, `composition key ${JSON.stringify(key)} will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7285
+ const compiledSchema = compileCombinationSchema(context, key, combinationList);
7286
+ if (!compiledSchema) return null;
7287
+ return compiledSchema;
7288
+ }
7289
+ }
7290
+ {
7291
+ const notSchema = unwrapJSONSchema7Definition(schema.not);
7292
+ if (notSchema) {
7293
+ const rejectKeys = Object.keys(schema).filter((k) => isJSONSchemaKey(k) && k !== "not");
7294
+ if (rejectKeys.length > 0) recordWarn(context, `key "not" will exclude other keys: ${rejectKeys.toSorted().join(", ")}`);
7295
+ const subSchema = compileSchema(joinPath(context, "not"), notSchema);
7296
+ if (!subSchema) return null;
7297
+ let kind = CompiledKind.Not;
7298
+ switch (getKind(subSchema)) {
7299
+ case CompiledKind.Never:
7300
+ kind = CompiledKind.Any;
7301
+ break;
7302
+ case CompiledKind.Any: kind = CompiledKind.Never;
7303
+ }
7304
+ return wrapCompiledSchema(kind, { not: subSchema }, context.delegate, context.path);
7305
+ }
7306
+ }
7307
+ if (schema.type) {
7308
+ const { type } = schema;
7309
+ if (Array.isArray(type)) {
7310
+ const { type: _type, ...rest } = schema;
7311
+ return compileCombinationSchema(context, "anyOf", type.map((item) => ({
7312
+ ...rest,
7313
+ type: item
7314
+ })));
7315
+ }
7316
+ switch (type) {
7317
+ case "object": return compileObjectSchema(context, schema);
7318
+ case "array": return compileArraySchema(context, schema);
7319
+ default: return compilePrimitiveSchema(context, schema);
7320
+ }
7321
+ }
7322
+ if (isLogicEmptyObject(schema)) return wrapCompiledSchema(CompiledKind.Any, {}, context.delegate, context.path);
7323
+ recordError(context, "unrecognized");
7324
+ return null;
7325
+ }
7326
+ //#endregion
7327
+ //#region src/json-schema-subset/checker/tools/mark.ts
7328
+ var VariableBundleDescription = class {
7329
+ constructor(_keys) {
7330
+ const keys = Object.freeze(_keys.toSorted());
7331
+ if (keys.length > 32) throw new Error(`cannot define ${keys.length} keys which is greater than 32`);
7332
+ this.keys = keys;
7333
+ this.clazz = class extends VariableBundleImpls {
7334
+ constructor(int32) {
7335
+ super(keys, int32);
7336
+ }
7337
+ };
7338
+ for (const [i, key] of this.keys.entries()) {
7339
+ const mask = 1 << i;
7340
+ Object.defineProperty(this.clazz.prototype, key, {
7341
+ enumerable: true,
7342
+ get: function get() {
7343
+ return !!(this.int32 & mask);
7344
+ },
7345
+ set: function set(value) {
7346
+ if (value) this.int32 |= mask;
7347
+ else this.int32 &= ~mask;
7348
+ }
7349
+ });
7350
+ }
7351
+ }
7352
+ toBundle(variable) {
7353
+ let int32 = 0;
7354
+ if (typeof variable === "number") int32 = variable;
7355
+ else if (variable) {
7356
+ for (const [i, key] of this.keys.entries()) if (variable[key]) int32 |= 1 << i;
7357
+ }
7358
+ return new this.clazz(int32);
7359
+ }
7360
+ };
7361
+ var VariableBundleImpls = class {
7362
+ constructor(keys, int32) {
7363
+ this.keys = keys;
7364
+ this.int32 = int32;
7365
+ }
7366
+ toInt32() {
7367
+ return this.int32;
7368
+ }
7369
+ toString() {
7370
+ const object = {};
7371
+ for (const key of this.keys) object[key] = this[key];
7372
+ return JSON.stringify(object);
7373
+ }
7374
+ };
7375
+ //#endregion
7376
+ //#region src/json-schema-subset/checker/tools/quantum.ts
7377
+ function makeQuantum(keys) {
7378
+ return new QuantumImpls(keys);
7379
+ }
7380
+ var QuantumImpls = class {
7381
+ constructor(keys) {
7382
+ this.description = new VariableBundleDescription(keys);
7383
+ }
7384
+ get keys() {
7385
+ return this.description.keys;
7386
+ }
7387
+ variable(variable) {
7388
+ let int32;
7389
+ if (variable) int32 = this.description.toBundle(variable).toInt32();
7390
+ return new QuantumVariableImpls(this.description, int32);
7391
+ }
7392
+ };
7393
+ var QuantumVariableImpls = class {
7394
+ constructor(description, int32) {
7395
+ this.values = /* @__PURE__ */ new Set();
7396
+ this.description = description;
7397
+ if (int32 !== void 0) this.values.add(int32);
7398
+ }
7399
+ [Symbol.iterator]() {
7400
+ const iterator = this.values[Symbol.iterator]();
7401
+ return { next: () => {
7402
+ const result = iterator.next();
7403
+ if (result.done) return result;
7404
+ else return {
7405
+ done: false,
7406
+ value: this.description.toBundle(result.value)
7407
+ };
7408
+ } };
7409
+ }
7410
+ assign(other) {
7411
+ const { values } = other;
7412
+ for (const int32 of values) this.values.add(int32);
7413
+ return this;
7414
+ }
7415
+ push(expression, calculate) {
7416
+ const nextValues = /* @__PURE__ */ new Set();
7417
+ for (const int32 of this.values) for (const [singleExpression, mask] of ExpressionMaskList) if (expression & mask) {
7418
+ const variable = this.description.toBundle(int32);
7419
+ calculate(singleExpression, variable);
7420
+ nextValues.add(variable.toInt32());
7421
+ }
7422
+ this.values = nextValues;
7423
+ }
7424
+ update(invoker) {
7425
+ const nextValues = /* @__PURE__ */ new Set();
7426
+ for (const int32 of this.values) {
7427
+ const variable = this.description.toBundle(int32);
7428
+ invoker(variable);
7429
+ nextValues.add(variable.toInt32());
7430
+ }
7431
+ this.values = nextValues;
7432
+ }
7433
+ };
7434
+ //#endregion
7435
+ //#region src/json-schema-subset/checker/tools/range.ts
7436
+ function splitRange$3(range1, range2) {
7437
+ const [min1] = range1;
7438
+ const [min2] = range2;
7439
+ if (min1.num < min2.num) return splitRangeLessBranch(range1, range2);
7440
+ else if (min1.num > min2.num) return splitRangeGreaterBranch(range1, range2);
7441
+ else return splitRangeEqualsBranch(range1, range2);
7442
+ }
7443
+ function splitRangeLessBranch(range1, range2) {
7444
+ const [min1, max1] = range1;
7445
+ const [min2, max2] = range2;
7446
+ if (max1.num <= min2.num) {
7447
+ const exclusive1 = max1.exclusive;
7448
+ const exclusive2 = min2.exclusive;
7449
+ if (max1.num < min2.num || exclusive1 || exclusive2) return {
7450
+ left: {
7451
+ fromLeft: true,
7452
+ range: range1
7453
+ },
7454
+ right: {
7455
+ fromLeft: false,
7456
+ range: range2
7457
+ }
7458
+ };
7459
+ }
7460
+ if (max1.num <= max2.num) {
7461
+ let hasRight = true;
7462
+ let isLeftRangeOverride = false;
7463
+ if (max1.num === max2.num) {
7464
+ const exclusive1 = max1.exclusive;
7465
+ const exclusive2 = max2.exclusive;
7466
+ hasRight = exclusive1 !== exclusive2;
7467
+ isLeftRangeOverride = !exclusive1 && exclusive2;
7468
+ }
7469
+ if (!isLeftRangeOverride) {
7470
+ let right;
7471
+ if (hasRight) right = {
7472
+ fromLeft: false,
7473
+ range: [reversalExclusive(max1), max2]
7474
+ };
7475
+ return {
7476
+ left: {
7477
+ fromLeft: true,
7478
+ range: [min1, reversalExclusive(min2)]
7479
+ },
7480
+ center: [min2, max1],
7481
+ right
7482
+ };
7483
+ }
7484
+ }
7485
+ return {
7486
+ left: {
7487
+ fromLeft: true,
7488
+ range: [min1, reversalExclusive(min2)]
7489
+ },
7490
+ center: [min2, max2],
7491
+ right: {
7492
+ fromLeft: true,
7493
+ range: [reversalExclusive(max2), max1]
7494
+ }
7495
+ };
7496
+ }
7497
+ function splitRangeGreaterBranch(range1, range2) {
7498
+ const [min1, max1] = range1;
7499
+ const [min2, max2] = range2;
7500
+ if (min1.num >= max2.num) {
7501
+ const exclusive1 = max2.exclusive;
7502
+ const exclusive2 = min1.exclusive;
7503
+ if (min1.num > max2.num || exclusive1 || exclusive2) return {
7504
+ left: {
7505
+ fromLeft: false,
7506
+ range: range2
7507
+ },
7508
+ right: {
7509
+ fromLeft: true,
7510
+ range: range1
7511
+ }
7512
+ };
7513
+ }
7514
+ if (max2.num <= max1.num) {
7515
+ let hasRight = true;
7516
+ let isRightRangeOverride = false;
7517
+ if (max1.num === max2.num) {
7518
+ const exclusive1 = max2.exclusive;
7519
+ const exclusive2 = max1.exclusive;
7520
+ hasRight = exclusive1 !== exclusive2;
7521
+ isRightRangeOverride = !exclusive1 && exclusive2;
7522
+ }
7523
+ if (!isRightRangeOverride) {
7524
+ let right;
7525
+ if (hasRight) right = {
7526
+ fromLeft: true,
7527
+ range: [reversalExclusive(max2), max1]
7528
+ };
7529
+ return {
7530
+ left: {
7531
+ fromLeft: false,
7532
+ range: [min2, reversalExclusive(min1)]
7533
+ },
7534
+ center: [min1, max2],
7535
+ right
7536
+ };
7537
+ }
7538
+ }
7539
+ return {
7540
+ left: {
7541
+ fromLeft: false,
7542
+ range: [min2, reversalExclusive(min1)]
7543
+ },
7544
+ center: [min1, max1],
7545
+ right: {
7546
+ fromLeft: false,
7547
+ range: [reversalExclusive(max1), max2]
7548
+ }
7549
+ };
7550
+ }
7551
+ function splitRangeEqualsBranch(range1, range2) {
7552
+ const [min1, max1] = range1;
7553
+ const [min2, max2] = range2;
7554
+ const exclusive1 = min1.exclusive;
7555
+ const exclusive2 = min2.exclusive;
7556
+ let left;
7557
+ let centerBegin = min1;
7558
+ if (!exclusive1 && exclusive2) {
7559
+ centerBegin = min2;
7560
+ left = {
7561
+ fromLeft: true,
7562
+ range: [min1, reversalExclusive(min2)]
7563
+ };
7564
+ } else if (exclusive1 && !exclusive2) left = {
7565
+ fromLeft: false,
7566
+ range: [min2, reversalExclusive(min1)]
7567
+ };
7568
+ if (max1.num <= max2.num) {
7569
+ let hasRight = true;
7570
+ let isLeftRangeOverride = false;
7571
+ if (max1.num === max2.num) {
7572
+ const maxExclusive1 = max1.exclusive;
7573
+ const maxExclusive2 = max2.exclusive;
7574
+ hasRight = maxExclusive1 !== maxExclusive2;
7575
+ isLeftRangeOverride = !maxExclusive1 && maxExclusive2;
7576
+ }
7577
+ if (!isLeftRangeOverride) {
7578
+ let right;
7579
+ if (hasRight) right = {
7580
+ fromLeft: false,
7581
+ range: [reversalExclusive(max1), max2]
7582
+ };
7583
+ return {
7584
+ left,
7585
+ center: [centerBegin, max1],
7586
+ right
7587
+ };
7588
+ }
7589
+ }
7590
+ return {
7591
+ left,
7592
+ center: [centerBegin, max2],
7593
+ right: {
7594
+ fromLeft: true,
7595
+ range: [reversalExclusive(max2), max1]
7596
+ }
7597
+ };
7598
+ }
7599
+ function reversalExclusive(point) {
7600
+ return {
7601
+ num: point.num,
7602
+ exclusive: !point.exclusive
7603
+ };
7604
+ }
7605
+ //#endregion
7606
+ //#region src/json-schema-subset/checker/range.ts
7607
+ var createRangeSplitter = (undefinedMin) => (min1 = undefinedMin, max1 = Number.POSITIVE_INFINITY, min2 = undefinedMin, max2 = Number.POSITIVE_INFINITY) => {
7608
+ const { left, center, right } = splitRange$3([{
7609
+ num: min1,
7610
+ exclusive: false
7611
+ }, {
7612
+ num: max1,
7613
+ exclusive: false
7614
+ }], [{
7615
+ num: min2,
7616
+ exclusive: false
7617
+ }, {
7618
+ num: max2,
7619
+ exclusive: false
7620
+ }]);
7621
+ let leftItem;
7622
+ let rightItem;
7623
+ let intersectionItem;
7624
+ if (left) leftItem = {
7625
+ min: left.range[0].num,
7626
+ max: left.range[1].num,
7627
+ isFrom1: left.fromLeft
7628
+ };
7629
+ if (right) rightItem = {
7630
+ min: right.range[0].num,
7631
+ max: right.range[1].num,
7632
+ isFrom1: right.fromLeft
7633
+ };
7634
+ if (center) intersectionItem = {
7635
+ min: center[0].num,
7636
+ max: center[1].num
7637
+ };
7638
+ return {
7639
+ left: leftItem,
7640
+ right: rightItem,
7641
+ intersection: intersectionItem
7642
+ };
7643
+ };
7644
+ function toExpressionSingleResult({ left, right, intersection }) {
7645
+ if (!intersection) return ExpressionSingleResult.Rejection;
7646
+ let extra1 = false;
7647
+ let extra2 = false;
7648
+ if (left) {
7649
+ if (left.isFrom1) extra1 = true;
7650
+ else extra2 = true;
7651
+ }
7652
+ if (right) {
7653
+ if (right.isFrom1) extra1 = true;
7654
+ else extra2 = true;
7655
+ }
7656
+ if (extra1 && extra2) return ExpressionSingleResult.Intersection;
7657
+ if (extra1) return ExpressionSingleResult.Containing;
7658
+ if (extra2) return ExpressionSingleResult.ContainedBy;
7659
+ return ExpressionSingleResult.Equals;
7660
+ }
7661
+ //#endregion
7662
+ //#region src/json-schema-subset/checker/array.ts
7663
+ var splitRange$2 = createRangeSplitter(0);
7664
+ var quantum$1 = makeQuantum([
7665
+ "hasCommon",
7666
+ "hasExtra1",
7667
+ "hasExtra2",
7668
+ "hasRejection",
7669
+ "hasCommonBroken"
7670
+ ]);
7671
+ function calculateArray({ calculate }, schema1, schema2) {
7672
+ const splitResult = splitRange$2(schema1.minItems, schema1.maxItems, schema2.minItems, schema2.maxItems);
7673
+ const splitExpression = toExpressionSingleResult(splitResult);
7674
+ if (splitExpression === ExpressionSingleResult.Rejection) return ExpressionRejection;
7675
+ const [items1, additionalItems1] = normalizeArray(schema1);
7676
+ const [items2, additionalItems2] = normalizeArray(schema2);
7677
+ const itemsLength = Math.max(items1.length, items2.length) + 1;
7678
+ const length = Math.min(itemsLength, splitResult.intersection.max);
7679
+ const quantumVariable = quantum$1.variable({});
7680
+ const minItems = Math.min(schema1.minItems ?? 0, schema2.minItems ?? 0);
7681
+ for (let i = 0; i < length; i++) {
7682
+ const expression = calculate(items1[i] ?? additionalItems1, items2[i] ?? additionalItems2);
7683
+ quantumVariable.push(expression, (singleExpression, variable) => {
7684
+ switch (singleExpression) {
7685
+ case ExpressionSingleResult.Equals:
7686
+ if (!variable.hasRejection) variable.hasCommon = true;
7687
+ break;
7688
+ case ExpressionSingleResult.Containing:
7689
+ if (!variable.hasRejection) variable.hasCommon = true;
7690
+ variable.hasExtra1 = true;
7691
+ break;
7692
+ case ExpressionSingleResult.ContainedBy:
7693
+ if (!variable.hasRejection) variable.hasCommon = true;
7694
+ variable.hasExtra2 = true;
7695
+ break;
7696
+ case ExpressionSingleResult.Intersection:
7697
+ if (!variable.hasRejection) variable.hasCommon = true;
7698
+ variable.hasExtra1 = true;
7699
+ variable.hasExtra2 = true;
7700
+ break;
7701
+ case ExpressionSingleResult.Rejection:
7702
+ if (i < minItems) variable.hasCommonBroken = true;
7703
+ variable.hasRejection = true;
7704
+ variable.hasExtra1 = true;
7705
+ variable.hasExtra2 = true;
7706
+ }
7707
+ });
7708
+ }
7709
+ quantumVariable.update((variable) => {
7710
+ switch (splitExpression) {
7711
+ case ExpressionSingleResult.Containing:
7712
+ variable.hasExtra1 = true;
7713
+ break;
7714
+ case ExpressionSingleResult.ContainedBy:
7715
+ variable.hasExtra2 = true;
7716
+ break;
7717
+ case ExpressionSingleResult.Intersection:
7718
+ variable.hasExtra1 = true;
7719
+ variable.hasExtra2 = true;
7720
+ }
7721
+ if (schema1.uniqueItems && !schema2.uniqueItems && (schema2.maxItems ?? Number.POSITIVE_INFINITY) > 1) variable.hasExtra2 = true;
7722
+ else if (!schema1.uniqueItems && schema2.uniqueItems && (schema1.maxItems ?? Number.POSITIVE_INFINITY) > 1) variable.hasExtra1 = true;
7723
+ if (schema1.maxItems === 0 || schema2.maxItems === 0) {
7724
+ variable.hasCommon = true;
7725
+ if (schema1.maxItems !== 0) variable.hasExtra1 = true;
7726
+ if (schema2.maxItems !== 0) variable.hasExtra2 = true;
7727
+ }
7728
+ });
7729
+ let expression = 0;
7730
+ for (const { hasExtra1, hasExtra2, hasCommon, hasCommonBroken } of quantumVariable) {
7731
+ let finalHasCommon = hasCommon;
7732
+ if (hasCommonBroken) finalHasCommon = false;
7733
+ if (!finalHasCommon) expression |= ExpressionRejection;
7734
+ else if (hasExtra1 && hasExtra2) expression |= ExpressionIntersection;
7735
+ else if (hasExtra1) expression |= ExpressionContaining;
7736
+ else if (hasExtra2) expression |= ExpressionContainedBy;
7737
+ else expression |= ExpressionEquals;
7738
+ }
7739
+ return expression;
7740
+ }
7741
+ function normalizeArray({ items, additionalItems }) {
7742
+ if (Array.isArray(items)) return [items, additionalItems ?? ANY];
7743
+ else return [[], items ?? ANY];
7744
+ }
7745
+ //#endregion
7746
+ //#region src/json-schema-subset/checker/cache.ts
7747
+ function wrapEqualsCheckerWithCache(check) {
7748
+ const map = /* @__PURE__ */ new Map();
7749
+ return (value1, value2) => {
7750
+ const isObject1 = isCompiledObject(value1);
7751
+ if (isObject1 !== isCompiledObject(value2)) return false;
7752
+ if (!isObject1) return value1 === value2;
7753
+ return getWithCache(map, value1, value2, check);
7754
+ };
7755
+ }
7756
+ function wrapSchemaCalculatorWithCache(check) {
7757
+ const map = /* @__PURE__ */ new Map();
7758
+ return (schema1, schema2) => getWithCache(map, schema1, schema2, check);
7759
+ }
7760
+ function getWithCache(map, node1, node2, check) {
7761
+ const key = `${getId(node1)}/${getId(node2)}`;
7762
+ let result = map.get(key);
7763
+ if (result === void 0) map.set(key, result = check(node1, node2));
7764
+ return result;
7765
+ }
7766
+ //#endregion
7767
+ //#region src/json-schema-subset/checker/enumAndConst.ts
7768
+ function calculateEnumAndEnum(context, schema1, schema2) {
7769
+ const enumList1 = normalizeEnumList(schema1);
7770
+ const enumList2 = normalizeEnumList(schema2);
7771
+ let foundExtra1 = false;
7772
+ let foundExtra2 = false;
7773
+ let foundIntersection = false;
7774
+ for (const enum1 of enumList1) {
7775
+ if (hasEqualsEnum(context, enumList2, enum1)) foundIntersection = true;
7776
+ else foundExtra1 = true;
7777
+ if (foundExtra1 && foundIntersection) break;
7778
+ }
7779
+ for (const enum2 of enumList2) {
7780
+ if (hasEqualsEnum(context, enumList1, enum2)) foundIntersection = true;
7781
+ else foundExtra2 = true;
7782
+ if (foundExtra2 && foundIntersection) break;
7783
+ }
7784
+ if (!foundIntersection) return ExpressionRejection;
7785
+ if (foundExtra1 && foundExtra2) return ExpressionIntersection;
7786
+ if (foundExtra1) return ExpressionContaining;
7787
+ if (foundExtra2) return ExpressionContainedBy;
7788
+ return ExpressionEquals;
7789
+ }
7790
+ function calculateEnumAndSchema(enumSchema, schema) {
7791
+ let hasValid = false;
7792
+ let hasInvalid = false;
7793
+ for (const enumValue of normalizeEnumList(enumSchema)) {
7794
+ switch (valid(schema, enumValue)) {
7795
+ case ValidResult.Valid:
7796
+ hasValid = true;
7797
+ break;
7798
+ case ValidResult.Invalid:
7799
+ hasInvalid = true;
7800
+ break;
7801
+ case ValidResult.Unknown: return ExpressionAny;
7802
+ }
7803
+ if (hasValid && hasInvalid) break;
7804
+ }
7805
+ if (hasValid && hasInvalid) return ExpressionIntersection;
7806
+ if (hasValid) return ExpressionEquals | ExpressionContainedBy;
7807
+ if (hasInvalid) return ExpressionRejection;
7808
+ if (getKind(schema) === CompiledKind.Never) return ExpressionEquals;
7809
+ return ExpressionContainedBy;
7810
+ }
7811
+ function normalizeEnumList({ const: constValue, enum: enumList }) {
7812
+ if (constValue !== void 0) return [constValue];
7813
+ if (enumList) return enumList;
7814
+ throw new Error("invalid branch");
7815
+ }
7816
+ function hasEqualsEnum({ isEquals }, enumList, checkedEnum) {
7817
+ for (const searchedEnum of enumList) if (isEquals(searchedEnum, checkedEnum)) return true;
7818
+ return false;
7819
+ }
7820
+ //#endregion
7821
+ //#region src/json-schema-subset/checker/equals.ts
7822
+ function schemaEqualsChecker(extendsContext) {
7823
+ function isSchemaEquals(schema1, schema2) {
7824
+ const isExtends1 = extendsContext.isExtendsSchema(schema1);
7825
+ const isExtends2 = extendsContext.isExtendsSchema(schema2);
7826
+ if (isExtends1 || isExtends2) return extendsContext.equals(schema1, schema2);
7827
+ else return isCompiledSchemaEquals(schema1, schema2);
7828
+ }
7829
+ const equalsMap = /* @__PURE__ */ new Map();
7830
+ function isCompiledSchemaEquals(schema1, schema2) {
7831
+ const id1 = getId(schema1);
7832
+ const id2 = getId(schema2);
7833
+ if (id1 === id2) return true;
7834
+ const key = `${id1}/${id2}`;
7835
+ let isEquals = equalsMap.get(key);
7836
+ if (isEquals === void 0) {
7837
+ isEquals = isObjectLikeEquals(schema1, schema2);
7838
+ equalsMap.set(key, isEquals);
7839
+ }
7840
+ return isEquals;
7841
+ }
7842
+ function isObjectLikeEquals(object1, object2) {
7843
+ if (Array.isArray(object1)) {
7844
+ if (!Array.isArray(object2)) return false;
7845
+ if (object1.length !== object2.length) return false;
7846
+ for (const [i, value1Element] of object1.entries()) if (!isValueEquals(value1Element, object2[i])) return false;
7847
+ } else {
7848
+ if (Array.isArray(object2)) return false;
7849
+ for (const key in object1) {
7850
+ if (!(key in object2)) return false;
7851
+ if (!isValueEquals(Reflect.get(object1, key), Reflect.get(object2, key))) return false;
7852
+ }
7853
+ for (const key in object2) if (!(key in object1)) return false;
7854
+ }
7855
+ return true;
7856
+ }
7857
+ function isValueEquals(value1, value2) {
7858
+ if (value1 === value2) return true;
7859
+ if (value1 === null) return false;
7860
+ if (typeof value1 !== "object") return false;
7861
+ if (typeof value1 !== typeof value2) return false;
7862
+ if (isCompiledSchema(value1) && isCompiledSchema(value2)) return isCompiledSchemaEquals(value1, value2);
7863
+ return isObjectLikeEquals(value1, value2);
7864
+ }
7865
+ return isSchemaEquals;
7866
+ }
7867
+ //#endregion
7868
+ //#region src/json-schema-subset/checker/numeric/integerNormalizer.ts
7869
+ function normalizeInteger(schema) {
7870
+ const floatRange = pickRange(schema);
7871
+ const multipleOf = schema.multipleOf ?? 1;
7872
+ const range = cutRange(floatRange, multipleOf);
7873
+ if (!range) return null;
7874
+ return {
7875
+ multipleOf,
7876
+ range
7877
+ };
7878
+ }
7879
+ function isPointRange([point1, point2]) {
7880
+ if (point1.num !== point2.num) return false;
7881
+ if (point1.exclusive) return false;
7882
+ if (point2.exclusive) return false;
7883
+ return true;
7884
+ }
7885
+ function cutRange(range, multipleOf) {
7886
+ if (!range) return;
7887
+ const [originMin, originMax] = range;
7888
+ let min = nextInteger(originMin.num, multipleOf);
7889
+ let max = previousInteger(originMax.num, multipleOf);
7890
+ if (min === originMin.num && originMin.exclusive) min += multipleOf;
7891
+ if (max === originMax.num && originMax.exclusive) max -= multipleOf;
7892
+ if (min > max) return;
7893
+ if (min === max) {
7894
+ if (min === Number.POSITIVE_INFINITY) return;
7895
+ if (min === Number.NEGATIVE_INFINITY) return;
7896
+ }
7897
+ return [{
7898
+ num: min,
7899
+ exclusive: false
7900
+ }, {
7901
+ num: max,
7902
+ exclusive: false
7903
+ }];
7904
+ }
7905
+ function nextInteger(float, multipleOf) {
7906
+ return Math.ceil(float / multipleOf) * multipleOf;
7907
+ }
7908
+ function previousInteger(float, multipleOf) {
7909
+ return Math.floor(float / multipleOf) * multipleOf;
7910
+ }
7911
+ //#endregion
7912
+ //#region src/json-schema-subset/checker/numeric/float.ts
7913
+ function calculateFloat(schema1, schema2) {
7914
+ const { left, right, center } = splitRange$3(pickRange(schema1), pickRange(schema2));
7915
+ if (!center) return ExpressionRejection;
7916
+ let extraLeft = false;
7917
+ let extraRight = false;
7918
+ if (left) {
7919
+ if (left.fromLeft) extraLeft = true;
7920
+ else extraRight = true;
7921
+ }
7922
+ if (right) {
7923
+ if (right.fromLeft) extraLeft = true;
7924
+ else extraRight = true;
7925
+ }
7926
+ if (extraLeft && extraRight) return ExpressionIntersection;
7927
+ if (extraLeft) return ExpressionContaining;
7928
+ if (extraRight) return ExpressionContainedBy;
7929
+ return ExpressionEquals;
7930
+ }
7931
+ function calculateFloatAndInteger(schema1, schema2) {
7932
+ const floatRange = pickRange(schema1);
7933
+ const integer = normalizeInteger(schema2);
7934
+ if (!integer) return ExpressionContaining;
7935
+ const result = splitRange$3(floatRange, integer.range);
7936
+ const intCenter = cutRange(result.center, integer.multipleOf);
7937
+ const leftIntRange = unwrapAndCutRange(result.left, integer.multipleOf);
7938
+ const rightIntRange = unwrapAndCutRange(result.right, integer.multipleOf);
7939
+ if (!result.center) return ExpressionRejection;
7940
+ let extraFloat = false;
7941
+ let extraInteger = false;
7942
+ if (result.left?.fromLeft) extraFloat = true;
7943
+ if (result.right?.fromLeft) extraFloat = true;
7944
+ if (!intCenter || !isPointRange(result.center)) extraFloat = true;
7945
+ if (leftIntRange) extraInteger = true;
7946
+ if (rightIntRange) extraInteger = true;
7947
+ if (extraFloat && extraInteger) return ExpressionIntersection;
7948
+ if (extraFloat) return ExpressionContaining;
7949
+ if (extraInteger) return ExpressionContainedBy;
7950
+ return ExpressionEquals;
7951
+ }
7952
+ function pickRange(schema) {
7953
+ let point1;
7954
+ let point2;
7955
+ if (schema.exclusiveMinimum !== void 0) point1 = {
7956
+ num: schema.exclusiveMinimum,
7957
+ exclusive: true
7958
+ };
7959
+ else if (schema.minimum !== void 0) point1 = {
7960
+ num: schema.minimum,
7961
+ exclusive: false
7962
+ };
7963
+ else point1 = {
7964
+ num: Number.NEGATIVE_INFINITY,
7965
+ exclusive: true
7966
+ };
7967
+ if (schema.exclusiveMaximum !== void 0) point2 = {
7968
+ num: schema.exclusiveMaximum,
7969
+ exclusive: true
7970
+ };
7971
+ else if (schema.maximum !== void 0) point2 = {
7972
+ num: schema.maximum,
7973
+ exclusive: false
7974
+ };
7975
+ else point2 = {
7976
+ num: Number.POSITIVE_INFINITY,
7977
+ exclusive: true
7978
+ };
7979
+ return [point1, point2];
7980
+ }
7981
+ function unwrapAndCutRange(side, multipleOf) {
7982
+ if (!side) return;
7983
+ if (side.fromLeft) return;
7984
+ return cutRange(side.range, multipleOf);
7985
+ }
7986
+ //#endregion
7987
+ //#region src/json-schema-subset/checker/numeric/integer.ts
7988
+ function calculateInteger(schema1, schema2) {
7989
+ const integer1 = normalizeInteger(schema1);
7990
+ const integer2 = normalizeInteger(schema2);
7991
+ if (!integer1 && !integer2) return ExpressionEquals;
7992
+ if (!integer1) return ExpressionContainedBy;
7993
+ if (!integer2) return ExpressionContaining;
7994
+ const { range: range1, multipleOf: multipleOf1 } = integer1;
7995
+ const { range: range2, multipleOf: multipleOf2 } = integer2;
7996
+ const result = splitRange$3(range1, range2);
7997
+ let centerRange;
7998
+ let lcm = 0;
7999
+ if (result.center) {
8000
+ lcm = getLCM(multipleOf1, multipleOf2);
8001
+ centerRange = cutRange(result.center, lcm);
8002
+ }
8003
+ if (!centerRange) return ExpressionRejection;
8004
+ let extraLeft = false;
8005
+ let extraRight = false;
8006
+ const { left, right } = result;
8007
+ if (left && cutRange(left.range, left.fromLeft ? multipleOf1 : multipleOf2)) {
8008
+ if (left.fromLeft) extraLeft = true;
8009
+ else extraRight = true;
8010
+ }
8011
+ if (right && cutRange(right.range, right.fromLeft ? multipleOf1 : multipleOf2)) {
8012
+ if (right.fromLeft) extraLeft = true;
8013
+ else extraRight = true;
8014
+ }
8015
+ extraLeft = extraLeft || hasExtraIntegersOnCenter(integer1, centerRange, lcm);
8016
+ extraRight = extraRight || hasExtraIntegersOnCenter(integer2, centerRange, lcm);
8017
+ if (extraLeft && extraRight) return ExpressionIntersection;
8018
+ if (extraLeft) return ExpressionContaining;
8019
+ if (extraRight) return ExpressionContainedBy;
8020
+ return ExpressionEquals;
8021
+ }
8022
+ function hasExtraIntegersOnCenter({ range, multipleOf }, lcmCenterRange, lcm) {
8023
+ const result = splitRange$3(range, lcmCenterRange);
8024
+ if (cutRange(result.left?.range, multipleOf)) return true;
8025
+ if (cutRange(result.right?.range, multipleOf)) return true;
8026
+ const center = cutRange(result.center, multipleOf);
8027
+ if (!center) return false;
8028
+ const lcmCenterLength = rangeLength(lcmCenterRange);
8029
+ if (rangeLength(center) > lcmCenterLength) return true;
8030
+ if (lcmCenterLength === 1) return false;
8031
+ if (multipleOf < lcm) return true;
8032
+ return false;
8033
+ }
8034
+ /** Returns the least common multiple. */
8035
+ function getLCM(a, b) {
8036
+ return a * b / getGCD(a, b);
8037
+ }
8038
+ /** @returns The greatest common divisor. */
8039
+ function getGCD(a, b) {
8040
+ if (a === 0) return b;
8041
+ return getGCD(b % a, a);
8042
+ }
8043
+ function rangeLength(range) {
8044
+ if (!range) return 0;
8045
+ const [point1, point2] = range;
8046
+ return point2.num - point1.num + 1;
8047
+ }
8048
+ //#endregion
8049
+ //#region src/json-schema-subset/checker/numeric/checker.ts
8050
+ function calculateNumeric(schema1, schema2) {
8051
+ if (isUndefinedNumber(schema1) || isUndefinedNumber(schema2)) return ExpressionAny;
8052
+ const isFloat1 = isFloat(schema1);
8053
+ const isFloat2 = isFloat(schema2);
8054
+ if (isFloat1 && isFloat2) return calculateFloat(schema1, schema2);
8055
+ else if (isFloat1) return calculateFloatAndInteger(schema1, schema2);
8056
+ else if (isFloat2) return swap(calculateFloatAndInteger(schema2, schema1));
8057
+ else return calculateInteger(schema1, schema2);
8058
+ }
8059
+ function isUndefinedNumber(schema) {
8060
+ const { multipleOf } = schema;
8061
+ if (multipleOf === void 0) return false;
8062
+ if (!Number.isInteger(multipleOf)) return true;
8063
+ if (multipleOf < 0) return true;
8064
+ return false;
8065
+ }
8066
+ function isFloat(schema) {
8067
+ const { multipleOf } = schema;
8068
+ if (multipleOf !== void 0 && Number.isInteger(multipleOf)) return false;
8069
+ if (schema.type === "integer") return false;
8070
+ return true;
8071
+ }
8072
+ //#endregion
8073
+ //#region src/json-schema-subset/checker/object.ts
8074
+ var splitRange$1 = createRangeSplitter(0);
8075
+ var quantum = makeQuantum([
8076
+ "hasCommonInRequired",
8077
+ "hasCommonOutRequired",
8078
+ "hasExtra1",
8079
+ "hasExtra2",
8080
+ "hasRejection"
8081
+ ]);
8082
+ function calculateObject(context, schema1, schema2) {
8083
+ if (isPropertiesCountCannotMatch(schema1, schema2)) return ExpressionRejection;
8084
+ const splitRequiredResult = splitRequired(schema1, schema2);
8085
+ if (!splitRequiredResult) return ExpressionRejection;
8086
+ const getProperty1 = createPropertySchemaGetter(schema1);
8087
+ const getProperty2 = createPropertySchemaGetter(schema2);
8088
+ const calculateKey = (key) => {
8089
+ const propertySchema1 = getProperty1(key);
8090
+ const propertySchema2 = getProperty2(key);
8091
+ if (areNotBothNever(propertySchema1, propertySchema2)) return context.calculate(propertySchema1, propertySchema2);
8092
+ else return 0;
8093
+ };
8094
+ const { commonRequired, extraRequired1, extraRequired2 } = splitRequiredResult;
8095
+ const quantumVariable = quantum.variable({});
8096
+ for (const requiredKey of [...commonRequired].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateCommonRequiredExpression);
8097
+ for (const requiredKey of [...extraRequired1].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateExtraRequiredExpression1);
8098
+ for (const requiredKey of [...extraRequired2].toSorted()) quantumVariable.push(calculateKey(requiredKey), calculateExtraRequiredExpression2);
8099
+ const { hasOptional1, hasOptional2 } = splitRequiredResult;
8100
+ if (hasOptional1 || hasOptional2) {
8101
+ const calculator = calculateOptionalExpression(hasOptional1, hasOptional2);
8102
+ for (const optionalKey of [...getOptionalKeys(schema1, schema2)].toSorted()) {
8103
+ const expression = calculateKey(optionalKey);
8104
+ if (expression !== 0) quantumVariable.push(expression, calculator);
8105
+ }
8106
+ const additionalProperties1 = schema1.additionalProperties ?? ANY;
8107
+ const additionalProperties2 = schema2.additionalProperties ?? ANY;
8108
+ if (areNotBothNever(additionalProperties1, additionalProperties2)) {
8109
+ const expression = context.calculate(additionalProperties1, additionalProperties2);
8110
+ quantumVariable.push(expression, calculator);
8111
+ }
8112
+ }
8113
+ quantumVariable.update((variable) => {
8114
+ if (!variable.hasRejection) {
8115
+ if (extraRequired1.size > 0) variable.hasExtra2 = true;
8116
+ if (extraRequired2.size > 0) variable.hasExtra1 = true;
8117
+ }
8118
+ });
8119
+ const { requiredKeysCount } = splitRequiredResult;
8120
+ let expression = 0;
8121
+ for (const { hasExtra1, hasExtra2, hasCommonInRequired, hasCommonOutRequired, hasRejection } of quantumVariable) if (!hasCommonInRequired && requiredKeysCount > 0) expression |= ExpressionRejection;
8122
+ else if (!hasCommonOutRequired && requiredKeysCount === 0) expression |= ExpressionRejection;
8123
+ else if (hasRejection) expression |= ExpressionRejection;
8124
+ else if (hasExtra1 && hasExtra2) expression |= ExpressionIntersection;
8125
+ else if (hasExtra1) expression |= ExpressionContaining;
8126
+ else if (hasExtra2) expression |= ExpressionContainedBy;
8127
+ else expression |= ExpressionEquals;
8128
+ return expression;
8129
+ }
8130
+ function isPropertiesCountCannotMatch(schema1, schema2) {
8131
+ return toExpressionSingleResult(splitRange$1(schema1.minProperties, schema1.maxProperties, schema2.minProperties, schema2.maxProperties)) === ExpressionSingleResult.Rejection;
8132
+ }
8133
+ function splitRequired(schema1, schema2) {
8134
+ const extraRequired1 = new Set(schema1.required);
8135
+ const extraRequired2 = new Set(schema2.required);
8136
+ const commonRequired = /* @__PURE__ */ new Set();
8137
+ const wholeRequired = /* @__PURE__ */ new Set();
8138
+ const requiredCount1 = extraRequired1.size;
8139
+ const requiredCount2 = extraRequired2.size;
8140
+ for (const key of extraRequired1) {
8141
+ if (extraRequired2.has(key)) commonRequired.add(key);
8142
+ wholeRequired.add(key);
8143
+ }
8144
+ for (const key of extraRequired2) {
8145
+ if (extraRequired1.has(key)) commonRequired.add(key);
8146
+ wholeRequired.add(key);
8147
+ }
8148
+ const requiredKeysCount = wholeRequired.size;
8149
+ for (const key of commonRequired) {
8150
+ extraRequired1.delete(key);
8151
+ extraRequired2.delete(key);
8152
+ }
8153
+ const maxProperties1 = schema1.maxProperties ?? Number.MAX_SAFE_INTEGER;
8154
+ const maxProperties2 = schema2.maxProperties ?? Number.MAX_SAFE_INTEGER;
8155
+ if (requiredKeysCount > maxProperties1 || requiredKeysCount > maxProperties2) return null;
8156
+ return {
8157
+ requiredKeysCount,
8158
+ extraRequired1,
8159
+ extraRequired2,
8160
+ commonRequired,
8161
+ hasOptional1: maxProperties1 > requiredCount1,
8162
+ hasOptional2: maxProperties2 > requiredCount2
8163
+ };
8164
+ }
8165
+ function getOptionalKeys(schema1, schema2) {
8166
+ const optionalKeys = new Set(schema1.required);
8167
+ const properties1 = schema1.properties;
8168
+ const properties2 = schema2.properties;
8169
+ const required1 = schema1.required;
8170
+ const required2 = schema2.required;
8171
+ if (properties1) for (const key in properties1) optionalKeys.add(key);
8172
+ if (properties2) for (const key in properties2) optionalKeys.add(key);
8173
+ if (required1) for (const key of required1) optionalKeys.delete(key);
8174
+ if (required2) for (const key of required2) optionalKeys.delete(key);
8175
+ return optionalKeys;
8176
+ }
8177
+ var calculateCommonRequiredExpression = (singleExpression, variable) => {
8178
+ switch (singleExpression) {
8179
+ case ExpressionSingleResult.Equals:
8180
+ variable.hasCommonInRequired = true;
8181
+ break;
8182
+ case ExpressionSingleResult.Containing:
8183
+ variable.hasExtra1 = true;
8184
+ variable.hasCommonInRequired = true;
8185
+ break;
8186
+ case ExpressionSingleResult.ContainedBy:
8187
+ variable.hasExtra2 = true;
8188
+ variable.hasCommonInRequired = true;
8189
+ break;
8190
+ case ExpressionSingleResult.Intersection:
8191
+ variable.hasExtra1 = true;
8192
+ variable.hasExtra2 = true;
8193
+ variable.hasCommonInRequired = true;
8194
+ break;
8195
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
8196
+ }
8197
+ };
8198
+ var calculateExtraRequiredExpression1 = (singleExpression, variable) => {
8199
+ switch (singleExpression) {
8200
+ case ExpressionSingleResult.Equals:
8201
+ case ExpressionSingleResult.ContainedBy:
8202
+ variable.hasCommonInRequired = true;
8203
+ break;
8204
+ case ExpressionSingleResult.Intersection:
8205
+ case ExpressionSingleResult.Containing:
8206
+ variable.hasExtra1 = true;
8207
+ variable.hasCommonInRequired = true;
8208
+ break;
8209
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
8210
+ }
8211
+ };
8212
+ var calculateExtraRequiredExpression2 = (singleExpression, variable) => {
8213
+ switch (singleExpression) {
8214
+ case ExpressionSingleResult.Equals:
8215
+ case ExpressionSingleResult.Containing:
8216
+ variable.hasCommonInRequired = true;
8217
+ break;
8218
+ case ExpressionSingleResult.Intersection:
8219
+ case ExpressionSingleResult.ContainedBy:
8220
+ variable.hasExtra2 = true;
8221
+ variable.hasCommonInRequired = true;
8222
+ break;
8223
+ case ExpressionSingleResult.Rejection: variable.hasRejection = true;
8224
+ }
8225
+ };
8226
+ var calculateOptionalExpression = (hasOptional1, hasOptional2) => (singleExpression, variable) => {
8227
+ if (variable.hasRejection) return;
8228
+ let foundExtraPossibility1 = false;
8229
+ let foundExtraPossibility2 = false;
8230
+ let foundCommonPossibility = false;
8231
+ switch (singleExpression) {
8232
+ case ExpressionSingleResult.Equals:
8233
+ foundCommonPossibility = true;
8234
+ break;
8235
+ case ExpressionSingleResult.Containing:
8236
+ foundExtraPossibility1 = true;
8237
+ foundCommonPossibility = true;
8238
+ break;
8239
+ case ExpressionSingleResult.ContainedBy:
8240
+ foundExtraPossibility2 = true;
8241
+ foundCommonPossibility = true;
8242
+ break;
8243
+ case ExpressionSingleResult.Intersection:
8244
+ foundExtraPossibility1 = true;
8245
+ foundExtraPossibility2 = true;
8246
+ foundCommonPossibility = true;
8247
+ break;
8248
+ case ExpressionSingleResult.Rejection:
8249
+ foundExtraPossibility1 = true;
8250
+ foundExtraPossibility2 = true;
8251
+ }
8252
+ if (hasOptional1 && foundExtraPossibility1) variable.hasExtra1 = true;
8253
+ if (hasOptional2 && foundExtraPossibility2) variable.hasExtra2 = true;
8254
+ if (hasOptional1 && hasOptional2 && foundCommonPossibility) variable.hasCommonOutRequired = true;
8255
+ };
8256
+ function createPropertySchemaGetter(schema) {
8257
+ const properties = schema.properties;
8258
+ const propertyNames = schema.propertyNames;
8259
+ const additionalProperties = schema.additionalProperties;
8260
+ const patternProperties = [];
8261
+ if (schema.patternProperties) for (const pattern in schema.patternProperties) {
8262
+ const valueSchema = schema.patternProperties[pattern];
8263
+ const regExp = new RegExp(pattern, "i");
8264
+ patternProperties.push({
8265
+ pattern: regExp,
8266
+ schema: valueSchema
8267
+ });
8268
+ }
8269
+ return (key) => {
8270
+ if (propertyNames && valid(propertyNames, key) === ValidResult.Invalid) return NEVER;
8271
+ for (const { pattern, schema: patternSchema } of patternProperties) if (pattern.test(key)) return patternSchema;
8272
+ const propertySchema = (properties && properties[key]) ?? additionalProperties;
8273
+ if (!propertySchema) return ANY;
8274
+ return propertySchema;
8275
+ };
8276
+ }
8277
+ function areNotBothNever(schema1, schema2) {
8278
+ const kind1 = getKind(schema1);
8279
+ const kind2 = getKind(schema2);
8280
+ return kind1 !== CompiledKind.Never || kind2 !== CompiledKind.Never;
8281
+ }
8282
+ //#endregion
8283
+ //#region src/json-schema-subset/checker/string.ts
8284
+ var splitRange = createRangeSplitter(0);
8285
+ function calculateString(schema1, schema2) {
8286
+ if (schema2.format && !schema1.format) return ExpressionContaining;
8287
+ if (schema1.format && schema2.format && schema1.format !== schema2.format) return ExpressionAny;
8288
+ const expression = toExpressionSingleResult(splitRange(schema1.minLength, schema1.maxLength, schema2.minLength, schema2.maxLength));
8289
+ const hasPattern1 = !!schema1.pattern;
8290
+ const hasPattern2 = !!schema2.pattern;
8291
+ switch (expression) {
8292
+ case ExpressionSingleResult.Rejection: return ExpressionRejection;
8293
+ case ExpressionSingleResult.Containing: return hasPattern1 ? ExpressionAny : ExpressionContaining;
8294
+ case ExpressionSingleResult.ContainedBy: return hasPattern2 ? ExpressionAny : ExpressionContainedBy;
8295
+ case ExpressionSingleResult.Equals:
8296
+ if (hasPattern1 && hasPattern2) return schema1.pattern === schema2.pattern ? ExpressionEquals : ExpressionAny;
8297
+ if (hasPattern1) return ExpressionEquals | ExpressionContainedBy;
8298
+ if (hasPattern2) return ExpressionEquals | ExpressionContaining;
8299
+ return ExpressionEquals;
8300
+ case ExpressionSingleResult.Intersection:
8301
+ if (hasPattern1 && hasPattern2) return ExpressionAny;
8302
+ if (hasPattern1) return ExpressionIntersection | ExpressionRejection | ExpressionContainedBy;
8303
+ if (hasPattern2) return ExpressionIntersection | ExpressionRejection | ExpressionContaining;
8304
+ return ExpressionIntersection;
8305
+ }
8306
+ }
8307
+ //#endregion
8308
+ //#region src/json-schema-subset/checker/checker.ts
8309
+ function checkWithResult(extendsContext, schema1, schema2) {
8310
+ const context = {};
8311
+ const errorPaths = [];
8312
+ const calculate = wrapSchemaCalculatorWithCache(calculator(extendsContext, context));
8313
+ const describe = describer();
8314
+ const equals = schemaEqualsChecker(extendsContext);
8315
+ context.isEquals = wrapEqualsCheckerWithCache(isDeepEquals);
8316
+ context.calculate = expression({
8317
+ describe,
8318
+ equals,
8319
+ calculate,
8320
+ observeCalculation: (left, right, result, swapped) => {
8321
+ if (!isDecisiveMismatch(swapped ? swap(result) : result)) return;
8322
+ const errorPath = swapped ? findMismatchPath(right, left) : findMismatchPath(left, right);
8323
+ if (errorPath) errorPaths.push(errorPath);
8324
+ }
8325
+ });
8326
+ Object.freeze(context);
8327
+ const comparisonExpression = context.calculate(schema1, schema2);
8328
+ return {
8329
+ errorPath: errorPaths[0],
8330
+ expression: comparisonExpression
8331
+ };
8332
+ }
8333
+ var describer = () => (schema) => {
8334
+ let description;
8335
+ switch (getKind(schema)) {
8336
+ case CompiledKind.Not:
8337
+ description = {
8338
+ kind: ExpressionKind.Not,
8339
+ expression: schema.not
8340
+ };
8341
+ break;
8342
+ case CompiledKind.Combination:
8343
+ if ("allOf" in schema) description = {
8344
+ kind: ExpressionKind.AllOf,
8345
+ expressions: rejectInSchemaList(schema.allOf, CompiledKind.Any)
8346
+ };
8347
+ else if ("anyOf" in schema) description = {
8348
+ kind: ExpressionKind.AnyOf,
8349
+ expressions: rejectInSchemaList(schema.anyOf, CompiledKind.Never)
8350
+ };
8351
+ else if ("oneOf" in schema) description = {
8352
+ kind: ExpressionKind.OneOf,
8353
+ expressions: rejectInSchemaList(schema.oneOf, CompiledKind.Never)
8354
+ };
8355
+ else throw new Error(`invalid combination JSON Schema: ${JSON.stringify(schema)}`);
8356
+ break;
8357
+ default: description = { kind: ExpressionKind.Leaf };
8358
+ }
8359
+ return description;
8360
+ };
8361
+ var calculator = (extendsContext, context) => (schema1, schema2) => {
8362
+ const kind1 = getKind(schema1);
8363
+ const kind2 = getKind(schema2);
8364
+ if (kind1 === CompiledKind.Extends || kind2 === CompiledKind.Extends) return extendsContext.calculate(schema1, schema2);
8365
+ switch (kind1) {
8366
+ case CompiledKind.Any: return kind2 === CompiledKind.Any ? ExpressionEquals : ExpressionContaining;
8367
+ case CompiledKind.Never: return kind2 === CompiledKind.Never ? ExpressionEquals : ExpressionContainedBy;
8368
+ }
8369
+ switch (kind2) {
8370
+ case CompiledKind.Any: return ExpressionContainedBy;
8371
+ case CompiledKind.Never: return ExpressionContaining;
8372
+ }
8373
+ if (kind1 === CompiledKind.EnumOrConst && kind2 === CompiledKind.EnumOrConst) return calculateEnumAndEnum(context, schema1, schema2);
8374
+ if (kind1 === CompiledKind.EnumOrConst) return calculateEnumAndSchema(schema1, schema2);
8375
+ if (kind2 === CompiledKind.EnumOrConst) return swap(calculateEnumAndSchema(schema2, schema1));
8376
+ if (kind1 !== kind2) return ExpressionRejection;
8377
+ switch (kind1) {
8378
+ case CompiledKind.Null: return ExpressionEquals;
8379
+ case CompiledKind.Numeric: return calculateNumeric(schema1, schema2);
8380
+ case CompiledKind.String: return calculateString(schema1, schema2);
8381
+ case CompiledKind.Boolean: return ExpressionEquals;
8382
+ case CompiledKind.Object: return calculateObject(context, schema1, schema2);
8383
+ case CompiledKind.Array: return calculateArray(context, schema1, schema2);
8384
+ default: throw new Error(`invalid kind ${kind1}`);
8385
+ }
8386
+ };
8387
+ function rejectInSchemaList(schemaList, kind) {
8388
+ return schemaList.filter((e) => getKind(e) !== kind);
8389
+ }
8390
+ function isDecisiveMismatch(result) {
8391
+ return !hasEquals(result) && !hasContainedBy(result) && (hasContaining(result) || hasIntersection(result) || hasRejection(result));
8392
+ }
8393
+ function findMismatchPath(source, target) {
8394
+ const targetPath = getPath(target);
8395
+ if (!targetPath) return void 0;
8396
+ const sourceKind = getKind(source);
8397
+ const targetKind = getKind(target);
8398
+ if (sourceKind !== targetKind) return [...targetPath, "type"];
8399
+ const sourceSchema = source;
8400
+ const targetSchema = target;
8401
+ switch (targetKind) {
8402
+ case CompiledKind.String:
8403
+ if ((sourceSchema.minLength ?? 0) < (targetSchema.minLength ?? 0)) return [...targetPath, "minLength"];
8404
+ if ((sourceSchema.maxLength ?? Number.POSITIVE_INFINITY) > (targetSchema.maxLength ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxLength"];
8405
+ if (sourceSchema.pattern !== targetSchema.pattern && targetSchema.pattern) return [...targetPath, "pattern"];
8406
+ if (sourceSchema.format !== targetSchema.format && targetSchema.format) return [...targetPath, "format"];
8407
+ break;
8408
+ case CompiledKind.Numeric:
8409
+ if ((sourceSchema.minimum ?? sourceSchema.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) < (targetSchema.minimum ?? targetSchema.exclusiveMinimum ?? Number.NEGATIVE_INFINITY)) return [...targetPath, targetSchema.exclusiveMinimum == null ? "minimum" : "exclusiveMinimum"];
8410
+ if ((sourceSchema.maximum ?? sourceSchema.exclusiveMaximum ?? Number.POSITIVE_INFINITY) > (targetSchema.maximum ?? targetSchema.exclusiveMaximum ?? Number.POSITIVE_INFINITY)) return [...targetPath, targetSchema.exclusiveMaximum == null ? "maximum" : "exclusiveMaximum"];
8411
+ if (sourceSchema.multipleOf !== targetSchema.multipleOf && targetSchema.multipleOf != null) return [...targetPath, "multipleOf"];
8412
+ break;
8413
+ case CompiledKind.Array:
8414
+ if ((sourceSchema.minItems ?? 0) < (targetSchema.minItems ?? 0)) return [...targetPath, "minItems"];
8415
+ if ((sourceSchema.maxItems ?? Number.POSITIVE_INFINITY) > (targetSchema.maxItems ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxItems"];
8416
+ if (!sourceSchema.uniqueItems && targetSchema.uniqueItems) return [...targetPath, "uniqueItems"];
8417
+ break;
8418
+ case CompiledKind.Object: {
8419
+ const sourceRequired = new Set(sourceSchema.required ?? []);
8420
+ if ((targetSchema.required ?? []).some((key) => !sourceRequired.has(key))) return [...targetPath, "required"];
8421
+ if ((sourceSchema.minProperties ?? 0) < (targetSchema.minProperties ?? 0)) return [...targetPath, "minProperties"];
8422
+ if ((sourceSchema.maxProperties ?? Number.POSITIVE_INFINITY) > (targetSchema.maxProperties ?? Number.POSITIVE_INFINITY)) return [...targetPath, "maxProperties"];
8423
+ break;
8424
+ }
8425
+ case CompiledKind.EnumOrConst: return [...targetPath, targetSchema.const == null ? "enum" : "const"];
8426
+ }
8427
+ return targetPath;
8428
+ }
8429
+ //#endregion
8430
+ //#region src/json-schema-subset/extends/extendsContext.ts
8431
+ var ExtendsContext = class ExtendsContext {
8432
+ constructor(extendsSchemaClasses = []) {
8433
+ this.extendsSchemaClasses = Object.freeze([...extendsSchemaClasses]);
8434
+ }
8435
+ tryCompiledExtendsSchema(target, payload) {
8436
+ for (const extendsSchemaClass of this.extendsSchemaClasses) if (extendsSchemaClass.isMatch(target)) return new extendsSchemaClass(createId(), target, payload);
8437
+ return null;
8438
+ }
8439
+ isExtendsSchema(target) {
8440
+ for (const extendsSchemaClass of this.extendsSchemaClasses) if (target instanceof extendsSchemaClass) return true;
8441
+ return false;
8442
+ }
8443
+ calculate(schema1, schema2) {
8444
+ const shouldSwap = !(schema1 instanceof this.findMatchedClass(schema1, schema2));
8445
+ let expressionResult = 0;
8446
+ let result;
8447
+ if (shouldSwap) result = schema2.compare(schema1);
8448
+ else result = schema1.compare(schema2);
8449
+ for (let expression of result) {
8450
+ if (shouldSwap) expression = ExtendsContext.swap(expression);
8451
+ expressionResult |= toExpression(expression);
8452
+ }
8453
+ return expressionResult;
8454
+ }
8455
+ equals(schema1, schema2) {
8456
+ if (!(schema1 instanceof this.findMatchedClass(schema1, schema2))) return schema2.equals(schema1);
8457
+ else return schema1.equals(schema2);
8458
+ }
8459
+ findMatchedClass(schema1, schema2) {
8460
+ for (const schemaClass of this.extendsSchemaClasses) {
8461
+ if (schema1 instanceof schemaClass) return schemaClass;
8462
+ if (schema2 instanceof schemaClass) return schemaClass;
8463
+ }
8464
+ throw new Error("Invalid schema");
8465
+ }
8466
+ static swap(expression) {
8467
+ switch (expression) {
8468
+ case ExpressionSingleResult.Containing: return ExpressionSingleResult.ContainedBy;
8469
+ case ExpressionSingleResult.ContainedBy: return ExpressionSingleResult.Containing;
8470
+ default: return expression;
8471
+ }
8472
+ }
8473
+ };
8474
+ //#endregion
8475
+ //#region src/json-schema-subset/preprocessing.ts
8476
+ function preprocessSchema(schema, compile, printWarnLog = false) {
8477
+ const schemaResult = compile(schema);
8478
+ if (Array.isArray(schemaResult)) {
8479
+ const errorItems = [];
8480
+ collectWithPathPrefix(errorItems, schemaResult, "$");
8481
+ throw new SchemaError(errorItems);
8482
+ }
8483
+ const { schema: compiledSchema, warns } = schemaResult;
8484
+ if (printWarnLog && warns.length > 0) {
8485
+ console.warn(`found ${warns.length} warns after compile schema`);
8486
+ for (const warn of warns) console.warn(stringifySchemaError(warn));
8487
+ }
8488
+ return compiledSchema;
8489
+ }
8490
+ function preprocessSchemasPair(schema1, schema2, compile, printWarnLog = false) {
8491
+ const schemaResult1 = compile(schema1);
8492
+ const schemaResult2 = compile(schema2);
8493
+ if (Array.isArray(schemaResult1) || Array.isArray(schemaResult2)) {
8494
+ const errorItems = [];
8495
+ if (Array.isArray(schemaResult1)) collectWithPathPrefix(errorItems, schemaResult1, "$1");
8496
+ if (Array.isArray(schemaResult2)) collectWithPathPrefix(errorItems, schemaResult2, "$2");
8497
+ throw new SchemaError(errorItems);
8498
+ }
8499
+ const { schema: compiledSchema1, warns: superWarns } = schemaResult1;
8500
+ const { schema: compiledSchema2, warns: subWarns } = schemaResult2;
8501
+ if (printWarnLog) {
8502
+ if (superWarns.length > 0) console.warn(`found ${superWarns.length} warns after compile superSchema`);
8503
+ for (const warn of superWarns) console.warn(stringifySchemaError(warn));
8504
+ if (subWarns.length > 0) console.warn(`found ${subWarns.length} warns after compile subSchema`);
8505
+ for (const warn of subWarns) console.warn(stringifySchemaError(warn));
8506
+ }
8507
+ return [compiledSchema1, compiledSchema2];
8508
+ }
8509
+ function collectWithPathPrefix(errorItems, compiledItems, prefix) {
8510
+ for (const compiledItem of compiledItems) {
8511
+ const replacedItem = {
8512
+ ...compiledItem,
8513
+ path: [prefix, ...compiledItem.path]
8514
+ };
8515
+ errorItems.push(replacedItem);
8516
+ }
8517
+ }
8518
+ //#endregion
8519
+ //#region src/json-schema-subset/global.ts
8520
+ var SubsetCompareResult = Object.freeze({
8521
+ True: 0,
8522
+ False: 1,
8523
+ Unknown: 2
8524
+ });
8525
+ function makeSubsetCompare({ extendsSchemaClasses, delegate } = {}) {
8526
+ const extendsContext = new ExtendsContext(extendsSchemaClasses);
8527
+ return Object.freeze({
8528
+ compile: (schema, payload, printWarnLog) => {
8529
+ const compiler = (candidate) => compile(candidate, extendsContext, payload, delegate);
8530
+ return preprocessSchema(schema, compiler, printWarnLog);
8531
+ },
8532
+ isSubset: (superSchema, subSchema, printWarnLog = false) => {
8533
+ const compiler = (candidate) => compile(candidate, extendsContext, void 0, delegate);
8534
+ const [schema1, schema2] = preprocessSchemasPair(superSchema, subSchema, compiler, printWarnLog);
8535
+ const { errorPath, expression } = checkWithResult(extendsContext, schema1, schema2);
8536
+ const foundTrueExpression = hasEquals(expression) || hasContainedBy(expression);
8537
+ const foundFalseExpression = hasContaining(expression) || hasIntersection(expression) || hasRejection(expression);
8538
+ if (foundTrueExpression && !foundFalseExpression) return { result: SubsetCompareResult.True };
8539
+ if (!foundTrueExpression && foundFalseExpression) return {
8540
+ errorPath,
8541
+ result: SubsetCompareResult.False
8542
+ };
8543
+ return { result: SubsetCompareResult.Unknown };
8544
+ }
8545
+ });
8546
+ }
8547
+ //#endregion
8548
+ //#region ../../node_modules/.bun/@wopjs+cast@0.1.16/node_modules/@wopjs/cast/dist/index.mjs
8549
+ var isString = (x) => typeof x === "string";
8550
+ var isArray = Array.isArray;
8551
+ var isObject = (x) => x !== null && typeof x === "object";
8552
+ var isPlainObject = (x) => isObject(x) && !isArray(x);
8553
+ var toPlainObject = (x) => isPlainObject(x) ? x : void 0;
8554
+ //#endregion
8555
+ //#region src/flow/common/schemaComparer.ts
8556
+ function isStringLikeSchema(value) {
8557
+ return toPlainObject(value)?.type === "string";
8558
+ }
8559
+ function assertSchemaCompareContext(value) {
8560
+ const context = toPlainObject(value);
8561
+ const error = toPlainObject(context?.error);
8562
+ if (context == null || error == null || context.packageId != null && !isString(context.packageId) || error.message != null && !isString(error.message)) throw new TypeError("Invalid schema comparison context.");
8563
+ }
8564
+ function parseSchemaCompareContext(value) {
8565
+ if (value == null) return { error: {} };
8566
+ assertSchemaCompareContext(value);
8567
+ return value;
8568
+ }
8569
+ var SpecialSchema = class SpecialSchema {
8570
+ static setError(fromSchema, toSchema, message) {
8571
+ if (fromSchema instanceof SpecialSchema) fromSchema.context.error.message = message;
8572
+ else if (toSchema instanceof SpecialSchema) toSchema.context.error.message = message;
8573
+ }
8574
+ constructor(id, value, context) {
8575
+ this.id = id;
8576
+ this.value = value;
8577
+ this.context = parseSchemaCompareContext(context);
8578
+ }
8579
+ compare(other) {
8580
+ if (isCompiledSchema(other) && getKind(other) === CompiledKind.Any) return [ExpressionSingleResult.ContainedBy];
8581
+ return this.compareImpl(other);
8582
+ }
8583
+ };
8584
+ var SingleSelectSchema = class SingleSelectSchema extends SpecialSchema {
8585
+ static isMatch(value) {
8586
+ const enumValues = toPlainObject(value)?.enum;
8587
+ return Array.isArray(enumValues) && enumValues.every((v) => isString(v));
8588
+ }
8589
+ constructor(id, value, context) {
8590
+ if (!SingleSelectSchema.isMatch(value)) throw new TypeError("Invalid single-select schema.");
8591
+ super(id, value, context);
8592
+ }
8593
+ compareImpl(other) {
8594
+ if (isStringLikeSchema(other)) return [ExpressionSingleResult.ContainedBy];
8595
+ if (other instanceof SingleSelectSchema) {
8596
+ const f = new Set(this.value.enum);
8597
+ let result = ExpressionSingleResult.Equals;
8598
+ for (const v of other.value.enum) {
8599
+ if (!f.has(v)) result = ExpressionSingleResult.ContainedBy;
8600
+ f.delete(v);
8601
+ }
8602
+ if (f.size === 0) return [result];
8603
+ if (f.size === this.value.enum.length) return [ExpressionSingleResult.Rejection];
8604
+ return [ExpressionSingleResult.Intersection];
8605
+ }
8606
+ return [ExpressionSingleResult.Rejection];
8607
+ }
8608
+ equals(other) {
8609
+ if (other instanceof SingleSelectSchema) {
8610
+ const f = new Set(this.value.enum);
8611
+ for (const v of other.value.enum) {
8612
+ if (!f.has(v)) return false;
8613
+ f.delete(v);
8614
+ }
8615
+ return f.size === 0;
8616
+ }
8617
+ return false;
8618
+ }
8619
+ };
8620
+ var BinarySchema = class BinarySchema extends SpecialSchema {
8621
+ static isMatch(value) {
8622
+ return toPlainObject(value)?.contentMediaType === "oomol/bin";
8623
+ }
8624
+ constructor(id, value, context) {
8625
+ if (!BinarySchema.isMatch(value)) throw new TypeError("Invalid binary schema.");
8626
+ super(id, value, context);
8627
+ }
8628
+ compareImpl(other) {
8629
+ if (other instanceof BinarySchema) return [ExpressionSingleResult.Equals];
8630
+ else {
8631
+ SpecialSchema.setError(this, other, "edgeError.binDiffType");
8632
+ return [ExpressionSingleResult.Rejection];
8633
+ }
8634
+ }
8635
+ equals(other) {
8636
+ return other instanceof BinarySchema;
8637
+ }
8638
+ };
8639
+ var ArtifactSchema = class ArtifactSchema extends SpecialSchema {
8640
+ static isMatch(value) {
8641
+ return toPlainObject(value)?.contentMediaType === "oomol/artifact";
8642
+ }
8643
+ constructor(id, value, context) {
8644
+ if (!ArtifactSchema.isMatch(value)) throw new TypeError("Invalid Artifact schema.");
8645
+ super(id, value, context);
8646
+ }
8647
+ compareImpl(other) {
8648
+ if (other instanceof ArtifactSchema) return [ExpressionSingleResult.Equals];
8649
+ SpecialSchema.setError(this, other, "edgeError.artifactDiffType");
8650
+ return [ExpressionSingleResult.Rejection];
8651
+ }
8652
+ equals(other) {
8653
+ return other instanceof ArtifactSchema;
8654
+ }
8655
+ };
8656
+ function createSchemaComparer() {
8657
+ return makeSubsetCompare({ extendsSchemaClasses: [
8658
+ SingleSelectSchema,
8659
+ BinarySchema,
8660
+ ArtifactSchema
8661
+ ] });
8662
+ }
8663
+ createSchemaComparer();
8664
+ //#endregion
8665
+ //#region src/decision/common/decision.ts
8666
+ var decisionLimits = {
8667
+ choice: 255,
8668
+ score: 10
8669
+ };
8670
+ /** Ordered prefixes are shared by authoring, schemas, validation, and execution. */
8671
+ function limitDecisionQuestion(question) {
8672
+ if (question.type === "noul" || question.criteria.length <= decisionLimits[question.type]) return question;
8673
+ if (question.type === "choice") return {
8674
+ ...question,
8675
+ criteria: question.criteria.slice(0, decisionLimits.choice)
8676
+ };
8677
+ return {
8678
+ ...question,
8679
+ criteria: question.criteria.slice(0, decisionLimits.score)
8680
+ };
8681
+ }
8682
+ function limitDecisionQuestions(questions) {
8683
+ const limited = questions.map(limitDecisionQuestion);
8684
+ return limited.every((question, i) => question === questions[i]) ? questions : limited;
8685
+ }
8686
+ /** Loading an oversized task also updates its previously generated output schemas. */
8687
+ function limitDecisionTask(task) {
8688
+ if (task.executor.kind !== "decision") return task;
8689
+ const original = task.executor.questions;
8690
+ const questions = limitDecisionQuestions(original);
8691
+ if (questions === original) return task;
8692
+ const outputs = task.outputs.map((port) => {
8693
+ if (!("handle" in port)) return port;
8694
+ const index = original.findIndex((question) => question.name === port.handle);
8695
+ if (index < 0 || original[index] === questions[index] || !dequal(port.jsonSchema, answerSchema(original[index]))) return port;
8696
+ return {
8697
+ ...port,
8698
+ jsonSchema: decisionAnswerSchema(questions[index])
8699
+ };
8700
+ });
8701
+ return {
8702
+ ...task,
8703
+ executor: {
8704
+ ...task.executor,
8705
+ questions
8706
+ },
8707
+ outputs
8708
+ };
8709
+ }
8710
+ var probability = {
8711
+ type: "number",
8712
+ minimum: 0,
8713
+ maximum: 1
8714
+ };
8715
+ function decisionAnswerSchema(question) {
8716
+ return answerSchema(limitDecisionQuestion(question));
8717
+ }
8718
+ function answerSchema(question) {
8719
+ const properties = { type: { const: question.type } };
8720
+ if (question.type === "noul") properties.noul = probability;
8721
+ else {
8722
+ const keys = question.type === "choice" ? question.criteria.map((item) => item.name) : question.criteria.map((_, index) => String(index));
8723
+ properties.confidence = probability;
8724
+ properties.probabilities = {
8725
+ type: "object",
8726
+ properties: Object.fromEntries(keys.map((key) => [key, probability])),
8727
+ required: keys,
8728
+ additionalProperties: false
8729
+ };
8730
+ if (question.type === "choice") properties.choice = {
8731
+ type: "string",
8732
+ ...keys.length ? { enum: keys } : {}
8733
+ };
8734
+ else {
8735
+ properties.score = {
8736
+ type: "number",
8737
+ minimum: 0,
8738
+ maximum: Math.max(0, keys.length - 1)
8739
+ };
8740
+ properties.legend = {
8741
+ type: "object",
8742
+ properties: Object.fromEntries(keys.map((key) => [key, { type: "string" }])),
8743
+ required: keys,
8744
+ additionalProperties: false
8745
+ };
8746
+ }
8747
+ }
8748
+ return {
8749
+ type: "object",
8750
+ properties,
8751
+ required: Object.keys(properties)
8752
+ };
8753
+ }
8754
+ function checkJsonDepth(value, depth = 0) {
8755
+ if (depth > 64) throw new TypeError("Value exceeds the maximum JSON depth.");
8756
+ if (value != null && typeof value == "object") for (const child of Object.values(value)) checkJsonDepth(child, depth + 1);
8757
+ }
8758
+ //#endregion
8759
+ //#region src/flow/common/triggerScheduleSchema.ts
8760
+ var triggerScheduleSchema = array(union([object({
8761
+ type: literal("cron"),
8762
+ expression: string(),
8763
+ timezone: string()
8764
+ }), object({
8765
+ type: literal("every"),
8766
+ unit: _enum([
8767
+ "day",
8768
+ "hour",
8769
+ "minute",
8770
+ "month",
8771
+ "week"
8772
+ ]),
8773
+ value: number()
8774
+ })]));
8775
+ //#endregion
8776
+ //#region src/flow/common/webhookMethod.ts
8777
+ var webhookMethods = [
8778
+ "GET",
8779
+ "POST",
8780
+ "PUT",
8781
+ "PATCH",
8782
+ "DELETE"
8783
+ ];
8784
+ //#endregion
8785
+ //#region src/flow/common/changeSchema.ts
8786
+ var currentFlowModelVersion = 6;
8787
+ var text = string();
8788
+ var json = json$1();
8789
+ var strings = array(text);
8790
+ var port = object({
8791
+ description: text.optional(),
8792
+ jsonSchema: json,
8793
+ nullable: boolean(),
8794
+ handle: text
8795
+ });
8796
+ var input = port.extend({ value: json.optional() });
8797
+ var group = object({
8798
+ collapsed: boolean().optional(),
8799
+ group: text
8800
+ });
8801
+ var source = union([object({
8802
+ kind: literal("node"),
8803
+ nodeId: text,
8804
+ output: text,
8805
+ field: text.optional()
8806
+ }), object({
8807
+ kind: literal("binding"),
8808
+ bindingId: text
8809
+ })]);
8810
+ var fixedInput = union([object({ kind: literal("unset") }), object({
8811
+ kind: literal("value"),
8812
+ value: json
8813
+ })]);
8814
+ var mapping = union([fixedInput, object({
8815
+ kind: literal("sources"),
8816
+ sources: array(source)
8817
+ })]);
8818
+ var inputs = record$1(text, mapping);
8819
+ var ports = {
8820
+ inputs: array(union([input, group])),
8821
+ outputs: array(union([port, group]))
8822
+ };
8823
+ var capability = union([
8824
+ strictObject({
8825
+ kind: literal("connector"),
8826
+ action: text,
8827
+ connectionId: text.optional(),
8828
+ connections: array(strictObject({
8829
+ connectionId: text,
8830
+ alias: text.optional()
8831
+ }))
8832
+ }),
8833
+ strictObject({
8834
+ kind: literal("connector"),
8835
+ mode: literal("shared")
8836
+ }),
8837
+ strictObject({
8838
+ kind: literal("connector"),
8839
+ mode: literal("independent"),
8840
+ actions: array(strictObject({
8841
+ action: text,
8842
+ connectionId: text.optional()
8843
+ }))
8844
+ }),
8845
+ strictObject({
8846
+ kind: literal("connector"),
8847
+ actionHints: array(text).optional(),
8848
+ connectionHints: array(strictObject({
8849
+ action: text,
8850
+ connectionId: text,
8851
+ alias: text.optional()
8852
+ })).optional()
8853
+ })
5927
8854
  ]);
5928
8855
  var inline = object({
5929
8856
  ...ports,
@@ -5939,6 +8866,32 @@ var agentValue = union([object({
5939
8866
  input: text
5940
8867
  })]);
5941
8868
  var agentInput = union([agentValue, object({ kind: literal("model") })]);
8869
+ var decisionQuestion = discriminatedUnion("type", [
8870
+ strictObject({
8871
+ name: text,
8872
+ instructions: text,
8873
+ type: literal("noul"),
8874
+ criteria: strictObject({
8875
+ true: text.optional(),
8876
+ false: text.optional()
8877
+ }).optional()
8878
+ }),
8879
+ strictObject({
8880
+ name: text,
8881
+ instructions: text,
8882
+ type: literal("choice"),
8883
+ criteria: array(strictObject({
8884
+ name: text,
8885
+ description: text
8886
+ }))
8887
+ }),
8888
+ strictObject({
8889
+ name: text,
8890
+ instructions: text,
8891
+ type: literal("score"),
8892
+ criteria: strings
8893
+ })
8894
+ ]);
5942
8895
  var managed = object({
5943
8896
  ...ports,
5944
8897
  name: text,
@@ -5966,6 +8919,10 @@ var managed = object({
5966
8919
  in: _enum(["header", "query"]).optional()
5967
8920
  }))
5968
8921
  }),
8922
+ strictObject({
8923
+ kind: literal("decision"),
8924
+ questions: array(decisionQuestion)
8925
+ }),
5969
8926
  object({
5970
8927
  kind: literal("llm"),
5971
8928
  mode: _enum(["chat", "json"])
@@ -5986,13 +8943,15 @@ var managed = object({
5986
8943
  inputs: array(input.extend({ source: agentInput }))
5987
8944
  })),
5988
8945
  notification: object({
5989
- taskId: text,
8946
+ action: text,
8947
+ connectionId: text.optional(),
8948
+ inputDefinitions: array(input),
5990
8949
  messageHandle: text,
5991
- inputs: record(text, agentValue)
8950
+ inputs: record$1(text, agentValue)
5992
8951
  }).optional()
5993
8952
  })
5994
8953
  ])
5995
- });
8954
+ }).transform(limitDecisionTask);
5996
8955
  var operand = union([object({
5997
8956
  kind: literal("value"),
5998
8957
  value: json.optional(),
@@ -6043,7 +9002,7 @@ var webhookOptions = object({
6043
9002
  allowedOrigins: strings.optional(),
6044
9003
  noResponseBody: never().optional(),
6045
9004
  responseData: text.optional(),
6046
- responseHeaders: record(text, text).optional(),
9005
+ responseHeaders: record$1(text, text).optional(),
6047
9006
  responseStatusCode: number().int().min(200).max(599).optional()
6048
9007
  });
6049
9008
  var webhook = {
@@ -6099,7 +9058,7 @@ var base = {
6099
9058
  var node = union([
6100
9059
  object({
6101
9060
  ...base,
6102
- inputs: record(text, never()),
9061
+ inputs: record$1(text, never()),
6103
9062
  kind: literal("condition"),
6104
9063
  ...condition
6105
9064
  }),
@@ -6109,21 +9068,10 @@ var node = union([
6109
9068
  kind: literal("value"),
6110
9069
  values: array(input)
6111
9070
  }),
6112
- object({
6113
- ...base,
6114
- kind: literal("subflow"),
6115
- subflowId: text
6116
- }),
6117
- object({
6118
- ...base,
6119
- kind: literal("task"),
6120
- task: inline,
6121
- additionalInputs: array(input).optional()
6122
- }),
6123
9071
  object({
6124
9072
  ...base,
6125
9073
  kind: literal("task"),
6126
- taskId: text,
9074
+ task: union([inline, managed]),
6127
9075
  additionalInputs: array(input).optional()
6128
9076
  }),
6129
9077
  strictObject({
@@ -6159,7 +9107,7 @@ var node = union([
6159
9107
  ...trigger,
6160
9108
  kind: literal("poll"),
6161
9109
  connectionId: text.min(1).optional(),
6162
- config: record(text, fixedInput),
9110
+ config: record$1(text, fixedInput),
6163
9111
  definition: object({
6164
9112
  ...definition,
6165
9113
  type: literal("poll")
@@ -6170,7 +9118,7 @@ var node = union([
6170
9118
  ...trigger,
6171
9119
  kind: literal("integration"),
6172
9120
  connectionId: text.min(1).optional(),
6173
- config: record(text, fixedInput),
9121
+ config: record$1(text, fixedInput),
6174
9122
  definition: object({
6175
9123
  ...definition,
6176
9124
  type: literal("integration"),
@@ -6178,10 +9126,6 @@ var node = union([
6178
9126
  })
6179
9127
  })
6180
9128
  ]);
6181
- var target = union([object({ kind: literal("flow") }), object({
6182
- kind: literal("subflow"),
6183
- id: text
6184
- })]);
6185
9129
  var edge = object({
6186
9130
  source: text,
6187
9131
  target: text,
@@ -6189,15 +9133,10 @@ var edge = object({
6189
9133
  });
6190
9134
  var at = {
6191
9135
  nodeId: text,
6192
- target
9136
+ target: never().optional()
6193
9137
  };
6194
- var subflow = object({
6195
- name: text,
6196
- inputs: array(input),
6197
- outputs: array(port.extend({ sources: array(union([nodeSource, flowSource])) }))
6198
- });
6199
9138
  var graph = object({
6200
- nodes: record(text, node),
9139
+ nodes: record$1(text, node),
6201
9140
  edges: array(edge).default([])
6202
9141
  });
6203
9142
  var binding = object({
@@ -6209,24 +9148,35 @@ var module = object({
6209
9148
  imports: strings,
6210
9149
  source: text
6211
9150
  });
6212
- var document = object({
6213
- bindings: record(text, binding),
6214
- graph,
6215
- subflows: record(text, subflow.extend({ graph })),
6216
- tasks: record(text, managed)
6217
- });
9151
+ var document = preprocess(rejectRetiredDefinitions, object({
9152
+ bindings: record$1(text, binding),
9153
+ graph
9154
+ }));
6218
9155
  object({
6219
9156
  modelVersion: union([
6220
9157
  literal(2),
6221
9158
  literal(4),
6222
- literal(5)
9159
+ literal(5),
9160
+ literal(6)
6223
9161
  ]),
6224
9162
  document,
6225
- modules: record(text, module)
9163
+ modules: record$1(text, module)
6226
9164
  }).extend({
6227
9165
  kind: literal("open-flow-flow-revision"),
6228
9166
  version: literal(1)
6229
9167
  });
9168
+ function rejectRetiredDefinitions(value) {
9169
+ const candidate = record(value);
9170
+ if (candidate.tasks !== void 0 && (candidate.tasks === null || typeof candidate.tasks !== "object" || Array.isArray(candidate.tasks) || Object.keys(candidate.tasks).length > 0)) throw new TypeError("Independent Task definitions are no longer supported.");
9171
+ if (Object.values(record(record(candidate.graph).nodes)).some((candidateNode) => Object.hasOwn(record(candidateNode), "taskId"))) throw new TypeError("Task references are no longer supported.");
9172
+ const subflows = candidate.subflows;
9173
+ if (subflows !== void 0 && (subflows === null || typeof subflows !== "object" || Array.isArray(subflows) || Object.keys(subflows).length > 0)) throw new TypeError("Subflows are no longer supported.");
9174
+ if (Object.values(record(record(candidate.graph).nodes)).some((candidateNode) => record(candidateNode).kind === "subflow")) throw new TypeError("Subflow nodes are no longer supported.");
9175
+ return value;
9176
+ }
9177
+ function record(value) {
9178
+ return value != null && typeof value == "object" && !Array.isArray(value) ? value : {};
9179
+ }
6230
9180
  var shapes = {
6231
9181
  "graph.trigger.sources.set": {
6232
9182
  nodeId: text,
@@ -6244,12 +9194,12 @@ var shapes = {
6244
9194
  value: text
6245
9195
  },
6246
9196
  "graph.edge.connect": {
6247
- target,
6248
- edge
9197
+ edge,
9198
+ target: never().optional()
6249
9199
  },
6250
9200
  "graph.edge.disconnect": {
6251
- target,
6252
- edge
9201
+ edge,
9202
+ target: never().optional()
6253
9203
  },
6254
9204
  "graph.node.create": {
6255
9205
  ...at,
@@ -6313,13 +9263,11 @@ var shapes = {
6313
9263
  },
6314
9264
  "graph.node.resolution.set": {
6315
9265
  ...at,
6316
- target: object({ kind: literal("flow") }),
6317
9266
  before: object(wait),
6318
9267
  value: object(wait)
6319
9268
  },
6320
9269
  "graph.node.webhook.set": {
6321
9270
  ...at,
6322
- target: object({ kind: literal("flow") }),
6323
9271
  before: object(webhook),
6324
9272
  value: object(webhook)
6325
9273
  },
@@ -6366,45 +9314,10 @@ var shapes = {
6366
9314
  imports: strings,
6367
9315
  source: text
6368
9316
  },
6369
- "subflow.create": {
6370
- subflowId: text,
6371
- subflow: subflow.extend({ graph })
6372
- },
6373
- "subflow.definition.set": {
6374
- subflowId: text,
6375
- before: subflow,
6376
- definition: subflow
6377
- },
6378
- "subflow.delete": { subflowId: text },
6379
- "task.create": {
6380
- taskId: text,
6381
- task: managed
6382
- },
6383
- "task.delete": { taskId: text },
6384
- "task.connector.connection.set": {
6385
- taskId: text,
6386
- before: text.optional(),
6387
- value: text.optional()
6388
- },
6389
- "task.openapi.set": {
6390
- taskId: text,
6391
- before: managed,
6392
- value: managed
6393
- },
6394
- "task.agent.set": {
6395
- taskId: text,
6396
- before: managed,
6397
- value: managed
6398
- },
6399
- "task.llm.mode.set": {
6400
- taskId: text,
6401
- before: _enum(["chat", "json"]),
6402
- value: _enum(["chat", "json"])
6403
- },
6404
- "task.name.set": {
6405
- taskId: text,
6406
- before: text,
6407
- value: text
9317
+ "graph.node.task.set": {
9318
+ ...at,
9319
+ before: union([inline, managed]),
9320
+ value: union([inline, managed])
6408
9321
  }
6409
9322
  };
6410
9323
  var variants = new Map(Object.entries(shapes).map(([kind, shape]) => [kind, shape instanceof ZodType ? shape : object({
@@ -6672,30 +9585,6 @@ var FlowChangeError = class extends Error {
6672
9585
  function invalid(message) {
6673
9586
  throw new FlowChangeError(message);
6674
9587
  }
6675
- function selectedGraph(document, target) {
6676
- if (target.kind == "flow") return document.graph;
6677
- const subflow = document.subflows[target.id];
6678
- if (subflow == null) invalid("The target Subflow does not exist.");
6679
- return subflow.graph;
6680
- }
6681
- function replaceGraph(document, target, value) {
6682
- if (target.kind == "flow") return {
6683
- ...document,
6684
- graph: value
6685
- };
6686
- const subflow = document.subflows[target.id];
6687
- if (subflow == null) invalid("The target Subflow does not exist.");
6688
- return {
6689
- ...document,
6690
- subflows: {
6691
- ...document.subflows,
6692
- [target.id]: {
6693
- ...subflow,
6694
- graph: value
6695
- }
6696
- }
6697
- };
6698
- }
6699
9588
  function applyFlowChanges(content, operations) {
6700
9589
  const document = { ...content.document };
6701
9590
  const modules = { ...content.modules };
@@ -6747,29 +9636,29 @@ function applyFlowChanges(content, operations) {
6747
9636
  break;
6748
9637
  }
6749
9638
  case "graph.edge.connect": {
6750
- const graph = selectedGraph(document, operation.target);
9639
+ const graph = document.graph;
6751
9640
  if (graph.nodes[operation.edge.source] == null) invalid("The source Node does not exist.");
6752
9641
  const node = graph.nodes[operation.edge.target];
6753
9642
  if (node == null || !("inputs" in node)) invalid("The target Node does not accept execution dependencies.");
6754
9643
  if (graph.edges.some((edge) => dequal(edge, operation.edge))) invalid("The Nodes are already connected.");
6755
- Object.assign(document, replaceGraph(document, operation.target, {
9644
+ Object.assign(document, { graph: {
6756
9645
  ...graph,
6757
9646
  edges: [...graph.edges, operation.edge]
6758
- }));
9647
+ } });
6759
9648
  break;
6760
9649
  }
6761
9650
  case "graph.edge.disconnect": {
6762
- const graph = selectedGraph(document, operation.target);
9651
+ const graph = document.graph;
6763
9652
  const edges = graph.edges.filter((edge) => !dequal(edge, operation.edge));
6764
9653
  if (edges.length == graph.edges.length) invalid("The Nodes are not connected.");
6765
- Object.assign(document, replaceGraph(document, operation.target, {
9654
+ Object.assign(document, { graph: {
6766
9655
  ...graph,
6767
9656
  edges
6768
- }));
9657
+ } });
6769
9658
  break;
6770
9659
  }
6771
9660
  case "graph.node.additional-inputs.set": {
6772
- const graph = selectedGraph(document, operation.target);
9661
+ const graph = document.graph;
6773
9662
  const node = graph.nodes[operation.nodeId];
6774
9663
  if (node?.kind != "task") invalid("The Task Node does not exist.");
6775
9664
  if (!dequal(node.additionalInputs, operation.before)) invalid("The Task Node inputs changed before this operation was applied.");
@@ -6778,17 +9667,17 @@ function applyFlowChanges(content, operations) {
6778
9667
  ...rest,
6779
9668
  additionalInputs: operation.value
6780
9669
  };
6781
- Object.assign(document, replaceGraph(document, operation.target, {
9670
+ Object.assign(document, { graph: {
6782
9671
  ...graph,
6783
9672
  nodes: {
6784
9673
  ...graph.nodes,
6785
9674
  [operation.nodeId]: updated
6786
9675
  }
6787
- }));
9676
+ } });
6788
9677
  break;
6789
9678
  }
6790
9679
  case "graph.node.condition.set": {
6791
- const graph = selectedGraph(document, operation.target);
9680
+ const graph = document.graph;
6792
9681
  const node = graph.nodes[operation.nodeId];
6793
9682
  if (node?.kind != "condition") invalid("The Condition Node does not exist.");
6794
9683
  if (!dequal(node.cases, operation.before.cases) || node.matchMode != operation.before.matchMode) invalid("The Condition Node changed before this operation was applied.");
@@ -6796,22 +9685,21 @@ function applyFlowChanges(content, operations) {
6796
9685
  ...node,
6797
9686
  ...operation.value
6798
9687
  };
6799
- Object.assign(document, replaceGraph(document, operation.target, {
9688
+ Object.assign(document, { graph: {
6800
9689
  ...graph,
6801
9690
  nodes: {
6802
9691
  ...graph.nodes,
6803
9692
  [operation.nodeId]: updated
6804
9693
  }
6805
- }));
9694
+ } });
6806
9695
  break;
6807
9696
  }
6808
9697
  case "graph.node.create": {
6809
- const graph = selectedGraph(document, operation.target);
9698
+ const graph = document.graph;
6810
9699
  if (graph.nodes[operation.nodeId] != null) invalid("A Node with this ID already exists in the target graph.");
6811
- if (operation.target.kind == "subflow" && !("inputs" in operation.node)) invalid("Trigger Nodes cannot be created inside a Subflow.");
6812
9700
  if (operation.node.kind == "error" && Object.values(graph.nodes).some((node) => node.kind == "error")) invalid("A graph can contain only one Flow Error node.");
6813
9701
  if (operation.node.kind == "manual" && Object.values(graph.nodes).some((node) => node.kind == "manual")) invalid("A graph can contain only one manual Trigger.");
6814
- if (operation.node.kind == "task" && operation.node.task?.capabilities !== void 0) decodeConnectorCapabilities(operation.node.task.capabilities);
9702
+ if (operation.node.kind == "task" && "moduleId" in operation.node.task && operation.node.task.capabilities !== void 0) decodeConnectorCapabilities(operation.node.task.capabilities);
6815
9703
  if (operation.node.name == null) invalid("A Node name cannot be empty.");
6816
9704
  const name = normalizeNodeName(operation.node.name);
6817
9705
  const issue = nodeNameIssue(graph, operation.nodeId, name);
@@ -6821,29 +9709,29 @@ function applyFlowChanges(content, operations) {
6821
9709
  ...operation.node,
6822
9710
  name
6823
9711
  };
6824
- Object.assign(document, replaceGraph(document, operation.target, {
9712
+ Object.assign(document, { graph: {
6825
9713
  ...graph,
6826
9714
  nodes: {
6827
9715
  ...graph.nodes,
6828
9716
  [operation.nodeId]: node
6829
9717
  }
6830
- }));
9718
+ } });
6831
9719
  break;
6832
9720
  }
6833
9721
  case "graph.node.delete": {
6834
- const graph = selectedGraph(document, operation.target);
9722
+ const graph = document.graph;
6835
9723
  if (graph.nodes[operation.nodeId] == null) invalid("The Node does not exist in the target graph.");
6836
9724
  const removed = /* @__PURE__ */ new Set([operation.nodeId]);
6837
9725
  const nodes = Object.fromEntries(Object.entries(graph.nodes).filter(([nodeId]) => !removed.has(nodeId)));
6838
- Object.assign(document, replaceGraph(document, operation.target, {
9726
+ Object.assign(document, { graph: {
6839
9727
  ...graph,
6840
9728
  edges: graph.edges.filter((edge) => !removed.has(edge.source) && !removed.has(edge.target)),
6841
9729
  nodes
6842
- }));
9730
+ } });
6843
9731
  break;
6844
9732
  }
6845
9733
  case "graph.node.field.set": {
6846
- const graph = selectedGraph(document, operation.target);
9734
+ const graph = document.graph;
6847
9735
  const node = graph.nodes[operation.nodeId];
6848
9736
  if (node == null) invalid("The Node does not exist in the target graph.");
6849
9737
  if (operation.field == "connectionId" && node.kind != "poll" && node.kind != "integration") invalid("Only provider Triggers select a node Connection.");
@@ -6858,24 +9746,24 @@ function applyFlowChanges(content, operations) {
6858
9746
  Object.assign(updated, { name });
6859
9747
  } else if (operation.value == null) Reflect.deleteProperty(updated, operation.field);
6860
9748
  else Object.assign(updated, { [operation.field]: operation.value });
6861
- Object.assign(document, replaceGraph(document, operation.target, {
9749
+ Object.assign(document, { graph: {
6862
9750
  ...graph,
6863
9751
  nodes: {
6864
9752
  ...graph.nodes,
6865
9753
  [operation.nodeId]: updated
6866
9754
  }
6867
- }));
9755
+ } });
6868
9756
  break;
6869
9757
  }
6870
9758
  case "graph.node.input.set": {
6871
- const graph = selectedGraph(document, operation.target);
9759
+ const graph = document.graph;
6872
9760
  const node = graph.nodes[operation.nodeId];
6873
9761
  if (node == null || !("inputs" in node)) invalid("The Node does not accept inputs.");
6874
9762
  if (!dequal(nodeInputMappings(node)[operation.handle], operation.before)) invalid("The Node input changed before this operation was applied.");
6875
9763
  const inputs = { ...node.inputs };
6876
9764
  if (operation.value == null) delete inputs[operation.handle];
6877
9765
  else inputs[operation.handle] = operation.value;
6878
- Object.assign(document, replaceGraph(document, operation.target, {
9766
+ Object.assign(document, { graph: {
6879
9767
  ...graph,
6880
9768
  nodes: {
6881
9769
  ...graph.nodes,
@@ -6884,18 +9772,18 @@ function applyFlowChanges(content, operations) {
6884
9772
  inputs
6885
9773
  }
6886
9774
  }
6887
- }));
9775
+ } });
6888
9776
  break;
6889
9777
  }
6890
9778
  case "graph.node.task.capabilities.set": {
6891
- const graph = selectedGraph(document, operation.target);
9779
+ const graph = document.graph;
6892
9780
  const node = graph.nodes[operation.nodeId];
6893
- if (node?.kind != "task" || node.task == null) invalid("The inline Task Node does not exist.");
9781
+ if (node?.kind != "task" || !("moduleId" in node.task)) invalid("The inline Task Node does not exist.");
6894
9782
  if (!dequal(node.task.capabilities, operation.before)) invalid("The inline Task capabilities changed before this operation was applied.");
6895
9783
  const task = { ...node.task };
6896
9784
  if (operation.value === void 0) delete task.capabilities;
6897
9785
  else task.capabilities = decodeConnectorCapabilities(operation.value);
6898
- Object.assign(document, replaceGraph(document, operation.target, {
9786
+ Object.assign(document, { graph: {
6899
9787
  ...graph,
6900
9788
  nodes: {
6901
9789
  ...graph.nodes,
@@ -6904,13 +9792,13 @@ function applyFlowChanges(content, operations) {
6904
9792
  task
6905
9793
  }
6906
9794
  }
6907
- }));
9795
+ } });
6908
9796
  break;
6909
9797
  }
6910
9798
  case "graph.node.task.name.set": {
6911
- const graph = selectedGraph(document, operation.target);
9799
+ const graph = document.graph;
6912
9800
  const node = graph.nodes[operation.nodeId];
6913
- if (node?.kind != "task" || node.task == null) invalid("The inline Task Node does not exist.");
9801
+ if (node?.kind != "task" || !("moduleId" in node.task)) invalid("The inline Task Node does not exist.");
6914
9802
  if (node.task.name != operation.before) invalid("The inline Task name changed before this operation was applied.");
6915
9803
  const updated = {
6916
9804
  ...node,
@@ -6919,19 +9807,19 @@ function applyFlowChanges(content, operations) {
6919
9807
  name: operation.value
6920
9808
  }
6921
9809
  };
6922
- Object.assign(document, replaceGraph(document, operation.target, {
9810
+ Object.assign(document, { graph: {
6923
9811
  ...graph,
6924
9812
  nodes: {
6925
9813
  ...graph.nodes,
6926
9814
  [operation.nodeId]: updated
6927
9815
  }
6928
- }));
9816
+ } });
6929
9817
  break;
6930
9818
  }
6931
9819
  case "graph.node.task.ports.set": {
6932
- const graph = selectedGraph(document, operation.target);
9820
+ const graph = document.graph;
6933
9821
  const node = graph.nodes[operation.nodeId];
6934
- if (node?.kind != "task" || node.task == null) invalid("The inline Task Node does not exist.");
9822
+ if (node?.kind != "task" || !("moduleId" in node.task)) invalid("The inline Task Node does not exist.");
6935
9823
  if (!dequal({
6936
9824
  inputs: node.task.inputs,
6937
9825
  outputs: node.task.outputs
@@ -6944,21 +9832,21 @@ function applyFlowChanges(content, operations) {
6944
9832
  outputs: operation.value.outputs
6945
9833
  }
6946
9834
  };
6947
- Object.assign(document, replaceGraph(document, operation.target, {
9835
+ Object.assign(document, { graph: {
6948
9836
  ...graph,
6949
9837
  nodes: {
6950
9838
  ...graph.nodes,
6951
9839
  [operation.nodeId]: updated
6952
9840
  }
6953
- }));
9841
+ } });
6954
9842
  break;
6955
9843
  }
6956
9844
  case "graph.node.values.set": {
6957
- const graph = selectedGraph(document, operation.target);
9845
+ const graph = document.graph;
6958
9846
  const node = graph.nodes[operation.nodeId];
6959
9847
  if (node?.kind != "value") invalid("The Value Node does not exist.");
6960
9848
  if (!dequal(node.values, operation.before)) invalid("The Value Node changed before this operation was applied.");
6961
- Object.assign(document, replaceGraph(document, operation.target, {
9849
+ Object.assign(document, { graph: {
6962
9850
  ...graph,
6963
9851
  nodes: {
6964
9852
  ...graph.nodes,
@@ -6967,7 +9855,7 @@ function applyFlowChanges(content, operations) {
6967
9855
  values: operation.value
6968
9856
  }
6969
9857
  }
6970
- }));
9858
+ } });
6971
9859
  break;
6972
9860
  }
6973
9861
  case "graph.node.resolution.set": {
@@ -6991,7 +9879,7 @@ function applyFlowChanges(content, operations) {
6991
9879
  break;
6992
9880
  }
6993
9881
  case "graph.node.webhook.set": {
6994
- const graph = selectedGraph(document, operation.target);
9882
+ const graph = document.graph;
6995
9883
  const node = graph.nodes[operation.nodeId];
6996
9884
  if (node?.kind != "webhook") invalid("The Webhook Node does not exist.");
6997
9885
  if (node.method != operation.before.method || !dequal(node.bodyFields, operation.before.bodyFields) || !dequal(node.options, operation.before.options)) invalid("The Webhook Node changed before this operation was applied.");
@@ -7004,13 +9892,13 @@ function applyFlowChanges(content, operations) {
7004
9892
  ...node,
7005
9893
  ...operation.value
7006
9894
  };
7007
- Object.assign(document, replaceGraph(document, operation.target, {
9895
+ Object.assign(document, { graph: {
7008
9896
  ...graph,
7009
9897
  nodes: {
7010
9898
  ...graph.nodes,
7011
9899
  [operation.nodeId]: updated
7012
9900
  }
7013
- }));
9901
+ } });
7014
9902
  break;
7015
9903
  }
7016
9904
  case "graph.trigger.config.set": {
@@ -7083,124 +9971,28 @@ function applyFlowChanges(content, operations) {
7083
9971
  };
7084
9972
  break;
7085
9973
  }
7086
- case "subflow.create":
7087
- if (document.subflows[operation.subflowId] != null) invalid("A Subflow with this ID already exists.");
7088
- for (const node of Object.values(operation.subflow.graph.nodes)) if (node.kind == "task" && node.task?.capabilities !== void 0) decodeConnectorCapabilities(node.task.capabilities);
7089
- document.subflows = {
7090
- ...document.subflows,
7091
- [operation.subflowId]: operation.subflow
7092
- };
7093
- break;
7094
- case "subflow.definition.set": {
7095
- const subflow = document.subflows[operation.subflowId];
7096
- if (subflow == null) invalid("The Subflow does not exist.");
7097
- if (!dequal({
7098
- inputs: subflow.inputs,
7099
- name: subflow.name,
7100
- outputs: subflow.outputs
7101
- }, operation.before)) invalid("The Subflow definition changed before this operation was applied.");
7102
- document.subflows = {
7103
- ...document.subflows,
7104
- [operation.subflowId]: {
7105
- ...operation.definition,
7106
- graph: subflow.graph
7107
- }
7108
- };
7109
- break;
7110
- }
7111
- case "subflow.delete": {
7112
- if (document.subflows[operation.subflowId] == null) invalid("The Subflow does not exist.");
7113
- const subflows = { ...document.subflows };
7114
- delete subflows[operation.subflowId];
7115
- document.subflows = subflows;
7116
- break;
7117
- }
7118
- case "task.create":
7119
- if (document.tasks[operation.taskId] != null) invalid("A Task with this ID already exists.");
7120
- document.tasks = {
7121
- ...document.tasks,
7122
- [operation.taskId]: operation.task
7123
- };
7124
- break;
7125
- case "task.connector.connection.set": {
7126
- const task = document.tasks[operation.taskId];
7127
- if (task == null || !("executor" in task) || task.executor.kind != "connector") invalid("The Connector Task does not exist.");
7128
- if (task.executor.connectionId != operation.before) invalid("The Connector Task connection changed before this operation was applied.");
7129
- const { connectionId: _, ...executor } = task.executor;
7130
- const next = operation.value == null ? executor : {
7131
- ...executor,
7132
- connectionId: operation.value
7133
- };
7134
- document.tasks = {
7135
- ...document.tasks,
7136
- [operation.taskId]: {
7137
- ...task,
7138
- executor: next
7139
- }
7140
- };
7141
- break;
7142
- }
7143
- case "task.delete": {
7144
- if (document.tasks[operation.taskId] == null) invalid("The Task does not exist.");
7145
- const tasks = { ...document.tasks };
7146
- delete tasks[operation.taskId];
7147
- document.tasks = tasks;
7148
- break;
7149
- }
7150
- case "task.openapi.set": {
7151
- const task = document.tasks[operation.taskId];
7152
- if (task?.executor.kind != "openapi" || operation.value.executor.kind != "openapi") invalid("The OpenAPI Task does not exist.");
7153
- if (!dequal(task, operation.before)) invalid("The OpenAPI Task changed before this operation was applied.");
7154
- document.tasks = {
7155
- ...document.tasks,
7156
- [operation.taskId]: operation.value
7157
- };
7158
- break;
7159
- }
7160
- case "task.agent.set": {
7161
- const task = document.tasks[operation.taskId];
7162
- if (task?.executor.kind != "agent" || operation.value.executor.kind != "agent") invalid("The Agent Task does not exist.");
7163
- if (!dequal(task, operation.before)) invalid("The Agent Task changed before this operation was applied.");
7164
- document.tasks = {
7165
- ...document.tasks,
7166
- [operation.taskId]: operation.value
7167
- };
7168
- break;
7169
- }
7170
- case "task.llm.mode.set": {
7171
- const task = document.tasks[operation.taskId];
7172
- if (task == null || !("executor" in task) || task.executor.kind != "llm") invalid("The LLM Task does not exist.");
7173
- if (task.executor.mode != operation.before) invalid("The LLM Task mode changed before this operation was applied.");
7174
- document.tasks = {
7175
- ...document.tasks,
7176
- [operation.taskId]: {
7177
- ...task,
7178
- executor: {
7179
- ...task.executor,
7180
- mode: operation.value
9974
+ case "graph.node.task.set": {
9975
+ const graph = document.graph;
9976
+ const node = graph.nodes[operation.nodeId];
9977
+ if (node?.kind != "task") invalid("The Task Node does not exist.");
9978
+ if (!dequal(node.task, operation.before)) invalid("The Task configuration changed before this operation was applied.");
9979
+ document.graph = {
9980
+ ...graph,
9981
+ nodes: {
9982
+ ...graph.nodes,
9983
+ [operation.nodeId]: {
9984
+ ...node,
9985
+ task: operation.value
7181
9986
  }
7182
9987
  }
7183
9988
  };
7184
9989
  break;
7185
9990
  }
7186
- case "task.name.set": {
7187
- const task = document.tasks[operation.taskId];
7188
- if (task == null) invalid("The Task does not exist.");
7189
- if (task.name != operation.before) invalid("The Task name changed before this operation was applied.");
7190
- document.tasks = {
7191
- ...document.tasks,
7192
- [operation.taskId]: {
7193
- ...task,
7194
- name: operation.value
7195
- }
7196
- };
7197
- break;
7198
- }
7199
9991
  }
7200
9992
  assertOpenApiAuthBindings(document);
7201
9993
  return {
7202
9994
  document,
7203
- modelVersion: 5,
9995
+ modelVersion: 6,
7204
9996
  modules
7205
9997
  };
7206
9998
  }