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