create-ones-app 0.0.11 → 0.0.12

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/dist/index.cjs CHANGED
@@ -2,15 +2,16 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const _includesInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/includes");
4
4
  const commander = require("commander");
5
+ const node_child_process = require("node:child_process");
5
6
  const node_path = require("node:path");
6
7
  const fse = require("fs-extra");
7
8
  const uuid = require("uuid");
8
9
  const node_url = require("node:url");
9
10
  const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
10
11
  const chalk = require("chalk");
12
+ const lodashEs = require("lodash-es");
11
13
  const node_fs = require("node:fs");
12
14
  const node_process = require("node:process");
13
- const lodashEs = require("lodash-es");
14
15
  const zod = require("zod");
15
16
  const addFormats = require("ajv-formats");
16
17
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
@@ -39,6 +40,47 @@ const throwError = (code2, message) => {
39
40
  console.error(chalk.red(text));
40
41
  process.exit(1);
41
42
  };
43
+ const en = {
44
+ "desc.create": "Create a new ONES App",
45
+ "desc.create.projectPath": "Specify the project path",
46
+ "desc.create.templateName": "Specify the template name",
47
+ "desc.create.manifestOnly": "Only create the manifest file",
48
+ "success.create.gitInitialized": "Git repository initialized.",
49
+ "success.create.gitInitializedAndIgnoreStaged": 'Git repository initialized, and ".gitignore" has been staged.',
50
+ "success.create.fetchReferences": "To help your AI work on this app, fetch the app development references:",
51
+ "warn.create.gitInitSkipped": 'Warning: failed to initialize a Git repository automatically. You can run "git init" later. Reason: {reason}',
52
+ "warn.create.gitIgnoreStageSkipped": 'Warning: Git repository initialized, but failed to stage ".gitignore". You can run "git add .gitignore" later. Reason: {reason}',
53
+ "error.command.missingProjectPathFriendly": "Project path is required. Example: ones create hello-ones",
54
+ "error.create.templateNotFound": 'Template "{templateName}" not found',
55
+ "error.create.missingProjectPath": "Project path is required"
56
+ };
57
+ const map = {
58
+ en
59
+ };
60
+ const getCurrentLanguageList = () => {
61
+ return ["en"];
62
+ };
63
+ const translate = (key, params) => {
64
+ const list = getCurrentLanguageList();
65
+ for (let index = 0; index < list.length; index++) {
66
+ const language = list[index];
67
+ let value = lodashEs.get(map[language], key);
68
+ if (value) {
69
+ if (params && typeof value === "string") {
70
+ value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
71
+ var _params$paramKey;
72
+ const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
73
+ return String(result);
74
+ });
75
+ }
76
+ return value;
77
+ }
78
+ }
79
+ return key;
80
+ };
81
+ const i18n = {
82
+ t: translate
83
+ };
42
84
  const getCommandOptions = (args, keys) => {
43
85
  const $args = args.slice(-2);
44
86
  const $list = args.slice(0, -2);
@@ -80,6 +122,10 @@ const addCommandUsage = (cmd, blackList2) => {
80
122
  const addCommandOutput = (cmd) => {
81
123
  cmd.configureOutput({
82
124
  outputError(str) {
125
+ const message = str.replace(/^error: /, "").trim();
126
+ if (message === "missing required argument 'project-path'") {
127
+ throwError(ErrorCode.COMMAND_ERROR, i18n.t("error.command.missingProjectPathFriendly"));
128
+ }
83
129
  throwError(ErrorCode.COMMAND_ERROR, str);
84
130
  }
85
131
  });
@@ -95,41 +141,6 @@ const getTemplateChoices = () => {
95
141
  const getTemplateDefault = () => {
96
142
  return "example";
97
143
  };
98
- const en = {
99
- "desc.create": "Create a new ONES App",
100
- "desc.create.projectPath": "Specify the project path",
101
- "desc.create.templateName": "Specify the template name",
102
- "desc.create.manifestOnly": "Only create the manifest file",
103
- "error.create.templateNotFound": 'Template "{templateName}" not found',
104
- "error.create.missingProjectPath": "Project path is required"
105
- };
106
- const map = {
107
- en
108
- };
109
- const getCurrentLanguageList = () => {
110
- return ["en"];
111
- };
112
- const translate = (key, params) => {
113
- const list = getCurrentLanguageList();
114
- for (let index = 0; index < list.length; index++) {
115
- const language = list[index];
116
- let value = lodashEs.get(map[language], key);
117
- if (value) {
118
- if (params && typeof value === "string") {
119
- value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
120
- var _params$paramKey;
121
- const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
122
- return String(result);
123
- });
124
- }
125
- return value;
126
- }
127
- }
128
- return key;
129
- };
130
- const i18n = {
131
- t: translate
132
- };
133
144
  const defaultTemplateName = getTemplateDefault();
134
145
  const normalize$1 = async (options) => {
135
146
  const projectPathInput = options.projectPath;
@@ -167,6 +178,44 @@ const {
167
178
  writeFile,
168
179
  ensureDir
169
180
  } = fse;
181
+ const getErrorMessage = (error2) => {
182
+ if (error2 instanceof Error && error2.message) {
183
+ return error2.message;
184
+ }
185
+ return "Unknown error";
186
+ };
187
+ const initializeGitRepository = (projectPath) => {
188
+ try {
189
+ node_child_process.execFileSync("git", ["init"], {
190
+ cwd: projectPath,
191
+ stdio: "ignore"
192
+ });
193
+ } catch (error2) {
194
+ return {
195
+ status: "git-init-skipped",
196
+ reason: getErrorMessage(error2)
197
+ };
198
+ }
199
+ if (existsSync(node_path.join(projectPath, ".gitignore"))) {
200
+ try {
201
+ node_child_process.execFileSync("git", ["add", ".gitignore"], {
202
+ cwd: projectPath,
203
+ stdio: "ignore"
204
+ });
205
+ return {
206
+ status: "ignore-staged"
207
+ };
208
+ } catch (error2) {
209
+ return {
210
+ status: "gitignore-stage-skipped",
211
+ reason: getErrorMessage(error2)
212
+ };
213
+ }
214
+ }
215
+ return {
216
+ status: "initialized"
217
+ };
218
+ };
170
219
  const create = async function() {
171
220
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
172
221
  args[_key] = arguments[_key];
@@ -230,7 +279,24 @@ const create = async function() {
230
279
  await writeJSON(node_path.join(projectPath, PUBLIC_FILENAME.RC), rcJSON, {
231
280
  spaces: 2
232
281
  });
282
+ const gitSetupResult = initializeGitRepository(projectPath);
233
283
  console.log(`App "${appName}" created successfully!`);
284
+ if (gitSetupResult.status === "ignore-staged") {
285
+ console.log(i18n.t("success.create.gitInitializedAndIgnoreStaged"));
286
+ } else if (gitSetupResult.status === "initialized") {
287
+ console.log(i18n.t("success.create.gitInitialized"));
288
+ } else if (gitSetupResult.status === "git-init-skipped") {
289
+ console.log(i18n.t("warn.create.gitInitSkipped", {
290
+ reason: gitSetupResult.reason
291
+ }));
292
+ } else if (gitSetupResult.status === "gitignore-stage-skipped") {
293
+ console.log(i18n.t("warn.create.gitIgnoreStageSkipped", {
294
+ reason: gitSetupResult.reason
295
+ }));
296
+ }
297
+ console.log("");
298
+ console.log(i18n.t("success.create.fetchReferences"));
299
+ console.log(`ones specs fetch --dir "${projectPath}"`);
234
300
  };
235
301
  const createCommandArguments = ["projectPath", "templateName"];
236
302
  const blackList = ["template-name"];
@@ -1281,8 +1347,8 @@ var scope = {};
1281
1347
  var util = {};
1282
1348
  Object.defineProperty(util, "__esModule", { value: true });
1283
1349
  util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
1284
- const codegen_1$s = codegen;
1285
- const code_1$9 = code$1;
1350
+ const codegen_1$z = codegen;
1351
+ const code_1$a = code$1;
1286
1352
  function toHash(arr) {
1287
1353
  const hash = {};
1288
1354
  for (const item of arr)
@@ -1335,9 +1401,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
1335
1401
  if (typeof schema == "number" || typeof schema == "boolean")
1336
1402
  return schema;
1337
1403
  if (typeof schema == "string")
1338
- return (0, codegen_1$s._)`${schema}`;
1404
+ return (0, codegen_1$z._)`${schema}`;
1339
1405
  }
1340
- return (0, codegen_1$s._)`${topSchemaRef}${schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`;
1406
+ return (0, codegen_1$z._)`${topSchemaRef}${schemaPath}${(0, codegen_1$z.getProperty)(keyword2)}`;
1341
1407
  }
1342
1408
  util.schemaRefOrVal = schemaRefOrVal;
1343
1409
  function unescapeFragment(str) {
@@ -1369,20 +1435,20 @@ function eachItem(xs, f) {
1369
1435
  util.eachItem = eachItem;
1370
1436
  function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
1371
1437
  return (gen, from, to, toName) => {
1372
- const res = to === void 0 ? from : to instanceof codegen_1$s.Name ? (from instanceof codegen_1$s.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$s.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
1373
- return toName === codegen_1$s.Name && !(res instanceof codegen_1$s.Name) ? resultToName(gen, res) : res;
1438
+ const res = to === void 0 ? from : to instanceof codegen_1$z.Name ? (from instanceof codegen_1$z.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$z.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
1439
+ return toName === codegen_1$z.Name && !(res instanceof codegen_1$z.Name) ? resultToName(gen, res) : res;
1374
1440
  };
1375
1441
  }
1376
1442
  util.mergeEvaluated = {
1377
1443
  props: makeMergeEvaluated({
1378
- mergeNames: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true && ${from} !== undefined`, () => {
1379
- gen.if((0, codegen_1$s._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$s._)`${to} || {}`).code((0, codegen_1$s._)`Object.assign(${to}, ${from})`));
1444
+ mergeNames: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true && ${from} !== undefined`, () => {
1445
+ gen.if((0, codegen_1$z._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$z._)`${to} || {}`).code((0, codegen_1$z._)`Object.assign(${to}, ${from})`));
1380
1446
  }),
1381
- mergeToName: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true`, () => {
1447
+ mergeToName: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true`, () => {
1382
1448
  if (from === true) {
1383
1449
  gen.assign(to, true);
1384
1450
  } else {
1385
- gen.assign(to, (0, codegen_1$s._)`${to} || {}`);
1451
+ gen.assign(to, (0, codegen_1$z._)`${to} || {}`);
1386
1452
  setEvaluated(gen, to, from);
1387
1453
  }
1388
1454
  }),
@@ -1390,8 +1456,8 @@ util.mergeEvaluated = {
1390
1456
  resultToName: evaluatedPropsToName
1391
1457
  }),
1392
1458
  items: makeMergeEvaluated({
1393
- mergeNames: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$s._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
1394
- mergeToName: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$s._)`${to} > ${from} ? ${to} : ${from}`)),
1459
+ mergeNames: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$z._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
1460
+ mergeToName: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$z._)`${to} > ${from} ? ${to} : ${from}`)),
1395
1461
  mergeValues: (from, to) => from === true ? true : Math.max(from, to),
1396
1462
  resultToName: (gen, items2) => gen.var("items", items2)
1397
1463
  })
@@ -1399,21 +1465,21 @@ util.mergeEvaluated = {
1399
1465
  function evaluatedPropsToName(gen, ps) {
1400
1466
  if (ps === true)
1401
1467
  return gen.var("props", true);
1402
- const props = gen.var("props", (0, codegen_1$s._)`{}`);
1468
+ const props = gen.var("props", (0, codegen_1$z._)`{}`);
1403
1469
  if (ps !== void 0)
1404
1470
  setEvaluated(gen, props, ps);
1405
1471
  return props;
1406
1472
  }
1407
1473
  util.evaluatedPropsToName = evaluatedPropsToName;
1408
1474
  function setEvaluated(gen, props, ps) {
1409
- Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$s._)`${props}${(0, codegen_1$s.getProperty)(p)}`, true));
1475
+ Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$z._)`${props}${(0, codegen_1$z.getProperty)(p)}`, true));
1410
1476
  }
1411
1477
  util.setEvaluated = setEvaluated;
1412
1478
  const snippets = {};
1413
1479
  function useFunc(gen, f) {
1414
1480
  return gen.scopeValue("func", {
1415
1481
  ref: f,
1416
- code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
1482
+ code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
1417
1483
  });
1418
1484
  }
1419
1485
  util.useFunc = useFunc;
@@ -1423,11 +1489,11 @@ var Type;
1423
1489
  Type2[Type2["Str"] = 1] = "Str";
1424
1490
  })(Type || (util.Type = Type = {}));
1425
1491
  function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
1426
- if (dataProp instanceof codegen_1$s.Name) {
1492
+ if (dataProp instanceof codegen_1$z.Name) {
1427
1493
  const isNumber = dataPropType === Type.Num;
1428
- return jsPropertySyntax ? isNumber ? (0, codegen_1$s._)`"[" + ${dataProp} + "]"` : (0, codegen_1$s._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$s._)`"/" + ${dataProp}` : (0, codegen_1$s._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
1494
+ return jsPropertySyntax ? isNumber ? (0, codegen_1$z._)`"[" + ${dataProp} + "]"` : (0, codegen_1$z._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$z._)`"/" + ${dataProp}` : (0, codegen_1$z._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
1429
1495
  }
1430
- return jsPropertySyntax ? (0, codegen_1$s.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
1496
+ return jsPropertySyntax ? (0, codegen_1$z.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
1431
1497
  }
1432
1498
  util.getErrorPath = getErrorPath;
1433
1499
  function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
@@ -1439,52 +1505,45 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
1439
1505
  it.self.logger.warn(msg);
1440
1506
  }
1441
1507
  util.checkStrictMode = checkStrictMode;
1442
- var names = {};
1443
- var hasRequiredNames;
1444
- function requireNames() {
1445
- if (hasRequiredNames)
1446
- return names;
1447
- hasRequiredNames = 1;
1448
- Object.defineProperty(names, "__esModule", { value: true });
1449
- const codegen_12 = codegen;
1450
- const names$1 = {
1451
- // validation function arguments
1452
- data: new codegen_12.Name("data"),
1453
- // data passed to validation function
1454
- // args passed from referencing schema
1455
- valCxt: new codegen_12.Name("valCxt"),
1456
- // validation/data context - should not be used directly, it is destructured to the names below
1457
- instancePath: new codegen_12.Name("instancePath"),
1458
- parentData: new codegen_12.Name("parentData"),
1459
- parentDataProperty: new codegen_12.Name("parentDataProperty"),
1460
- rootData: new codegen_12.Name("rootData"),
1461
- // root data - same as the data passed to the first/top validation function
1462
- dynamicAnchors: new codegen_12.Name("dynamicAnchors"),
1463
- // used to support recursiveRef and dynamicRef
1464
- // function scoped variables
1465
- vErrors: new codegen_12.Name("vErrors"),
1466
- // null or array of validation errors
1467
- errors: new codegen_12.Name("errors"),
1468
- // counter of validation errors
1469
- this: new codegen_12.Name("this"),
1470
- // "globals"
1471
- self: new codegen_12.Name("self"),
1472
- scope: new codegen_12.Name("scope"),
1473
- // JTD serialize/parse name for JSON string and position
1474
- json: new codegen_12.Name("json"),
1475
- jsonPos: new codegen_12.Name("jsonPos"),
1476
- jsonLen: new codegen_12.Name("jsonLen"),
1477
- jsonPart: new codegen_12.Name("jsonPart")
1478
- };
1479
- names.default = names$1;
1480
- return names;
1481
- }
1508
+ var names$1 = {};
1509
+ Object.defineProperty(names$1, "__esModule", { value: true });
1510
+ const codegen_1$y = codegen;
1511
+ const names = {
1512
+ // validation function arguments
1513
+ data: new codegen_1$y.Name("data"),
1514
+ // data passed to validation function
1515
+ // args passed from referencing schema
1516
+ valCxt: new codegen_1$y.Name("valCxt"),
1517
+ // validation/data context - should not be used directly, it is destructured to the names below
1518
+ instancePath: new codegen_1$y.Name("instancePath"),
1519
+ parentData: new codegen_1$y.Name("parentData"),
1520
+ parentDataProperty: new codegen_1$y.Name("parentDataProperty"),
1521
+ rootData: new codegen_1$y.Name("rootData"),
1522
+ // root data - same as the data passed to the first/top validation function
1523
+ dynamicAnchors: new codegen_1$y.Name("dynamicAnchors"),
1524
+ // used to support recursiveRef and dynamicRef
1525
+ // function scoped variables
1526
+ vErrors: new codegen_1$y.Name("vErrors"),
1527
+ // null or array of validation errors
1528
+ errors: new codegen_1$y.Name("errors"),
1529
+ // counter of validation errors
1530
+ this: new codegen_1$y.Name("this"),
1531
+ // "globals"
1532
+ self: new codegen_1$y.Name("self"),
1533
+ scope: new codegen_1$y.Name("scope"),
1534
+ // JTD serialize/parse name for JSON string and position
1535
+ json: new codegen_1$y.Name("json"),
1536
+ jsonPos: new codegen_1$y.Name("jsonPos"),
1537
+ jsonLen: new codegen_1$y.Name("jsonLen"),
1538
+ jsonPart: new codegen_1$y.Name("jsonPart")
1539
+ };
1540
+ names$1.default = names;
1482
1541
  (function(exports2) {
1483
1542
  Object.defineProperty(exports2, "__esModule", { value: true });
1484
1543
  exports2.extendErrors = exports2.resetErrorsCount = exports2.reportExtraError = exports2.reportError = exports2.keyword$DataError = exports2.keywordError = void 0;
1485
1544
  const codegen_12 = codegen;
1486
1545
  const util_12 = util;
1487
- const names_12 = requireNames();
1546
+ const names_12 = names$1;
1488
1547
  exports2.keywordError = {
1489
1548
  message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
1490
1549
  };
@@ -1596,56 +1655,49 @@ function requireNames() {
1596
1655
  keyValues.push([E.propertyName, propertyName]);
1597
1656
  }
1598
1657
  })(errors);
1599
- var hasRequiredBoolSchema;
1600
- function requireBoolSchema() {
1601
- if (hasRequiredBoolSchema)
1602
- return boolSchema;
1603
- hasRequiredBoolSchema = 1;
1604
- Object.defineProperty(boolSchema, "__esModule", { value: true });
1605
- boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1606
- const errors_12 = errors;
1607
- const codegen_12 = codegen;
1608
- const names_12 = requireNames();
1609
- const boolError = {
1610
- message: "boolean schema is false"
1611
- };
1612
- function topBoolOrEmptySchema(it) {
1613
- const { gen, schema, validateName } = it;
1614
- if (schema === false) {
1615
- falseSchemaError(it, false);
1616
- } else if (typeof schema == "object" && schema.$async === true) {
1617
- gen.return(names_12.default.data);
1618
- } else {
1619
- gen.assign((0, codegen_12._)`${validateName}.errors`, null);
1620
- gen.return(true);
1621
- }
1658
+ Object.defineProperty(boolSchema, "__esModule", { value: true });
1659
+ boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1660
+ const errors_1$3 = errors;
1661
+ const codegen_1$x = codegen;
1662
+ const names_1$9 = names$1;
1663
+ const boolError = {
1664
+ message: "boolean schema is false"
1665
+ };
1666
+ function topBoolOrEmptySchema(it) {
1667
+ const { gen, schema, validateName } = it;
1668
+ if (schema === false) {
1669
+ falseSchemaError(it, false);
1670
+ } else if (typeof schema == "object" && schema.$async === true) {
1671
+ gen.return(names_1$9.default.data);
1672
+ } else {
1673
+ gen.assign((0, codegen_1$x._)`${validateName}.errors`, null);
1674
+ gen.return(true);
1622
1675
  }
1623
- boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
1624
- function boolOrEmptySchema(it, valid) {
1625
- const { gen, schema } = it;
1626
- if (schema === false) {
1627
- gen.var(valid, false);
1628
- falseSchemaError(it);
1629
- } else {
1630
- gen.var(valid, true);
1631
- }
1632
- }
1633
- boolSchema.boolOrEmptySchema = boolOrEmptySchema;
1634
- function falseSchemaError(it, overrideAllErrors) {
1635
- const { gen, data } = it;
1636
- const cxt = {
1637
- gen,
1638
- keyword: "false schema",
1639
- data,
1640
- schema: false,
1641
- schemaCode: false,
1642
- schemaValue: false,
1643
- params: {},
1644
- it
1645
- };
1646
- (0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
1676
+ }
1677
+ boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
1678
+ function boolOrEmptySchema(it, valid) {
1679
+ const { gen, schema } = it;
1680
+ if (schema === false) {
1681
+ gen.var(valid, false);
1682
+ falseSchemaError(it);
1683
+ } else {
1684
+ gen.var(valid, true);
1647
1685
  }
1648
- return boolSchema;
1686
+ }
1687
+ boolSchema.boolOrEmptySchema = boolOrEmptySchema;
1688
+ function falseSchemaError(it, overrideAllErrors) {
1689
+ const { gen, data } = it;
1690
+ const cxt = {
1691
+ gen,
1692
+ keyword: "false schema",
1693
+ data,
1694
+ schema: false,
1695
+ schemaCode: false,
1696
+ schemaValue: false,
1697
+ params: {},
1698
+ it
1699
+ };
1700
+ (0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
1649
1701
  }
1650
1702
  var dataType = {};
1651
1703
  var rules = {};
@@ -1674,36 +1726,29 @@ function getRules() {
1674
1726
  }
1675
1727
  rules.getRules = getRules;
1676
1728
  var applicability = {};
1677
- var hasRequiredApplicability;
1678
- function requireApplicability() {
1679
- if (hasRequiredApplicability)
1680
- return applicability;
1681
- hasRequiredApplicability = 1;
1682
- Object.defineProperty(applicability, "__esModule", { value: true });
1683
- applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
1684
- function schemaHasRulesForType({ schema, self }, type2) {
1685
- const group = self.RULES.types[type2];
1686
- return group && group !== true && shouldUseGroup(schema, group);
1687
- }
1688
- applicability.schemaHasRulesForType = schemaHasRulesForType;
1689
- function shouldUseGroup(schema, group) {
1690
- return group.rules.some((rule) => shouldUseRule(schema, rule));
1691
- }
1692
- applicability.shouldUseGroup = shouldUseGroup;
1693
- function shouldUseRule(schema, rule) {
1694
- var _a;
1695
- return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
1696
- }
1697
- applicability.shouldUseRule = shouldUseRule;
1698
- return applicability;
1729
+ Object.defineProperty(applicability, "__esModule", { value: true });
1730
+ applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
1731
+ function schemaHasRulesForType({ schema, self }, type2) {
1732
+ const group = self.RULES.types[type2];
1733
+ return group && group !== true && shouldUseGroup(schema, group);
1699
1734
  }
1735
+ applicability.schemaHasRulesForType = schemaHasRulesForType;
1736
+ function shouldUseGroup(schema, group) {
1737
+ return group.rules.some((rule) => shouldUseRule(schema, rule));
1738
+ }
1739
+ applicability.shouldUseGroup = shouldUseGroup;
1740
+ function shouldUseRule(schema, rule) {
1741
+ var _a;
1742
+ return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
1743
+ }
1744
+ applicability.shouldUseRule = shouldUseRule;
1700
1745
  Object.defineProperty(dataType, "__esModule", { value: true });
1701
1746
  dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
1702
1747
  const rules_1 = rules;
1703
- const applicability_1 = requireApplicability();
1704
- const errors_1 = errors;
1705
- const codegen_1$r = codegen;
1706
- const util_1$q = util;
1748
+ const applicability_1$1 = applicability;
1749
+ const errors_1$2 = errors;
1750
+ const codegen_1$w = codegen;
1751
+ const util_1$u = util;
1707
1752
  var DataType;
1708
1753
  (function(DataType2) {
1709
1754
  DataType2[DataType2["Correct"] = 0] = "Correct";
@@ -1735,7 +1780,7 @@ dataType.getJSONTypes = getJSONTypes;
1735
1780
  function coerceAndCheckDataType(it, types2) {
1736
1781
  const { gen, data, opts } = it;
1737
1782
  const coerceTo = coerceToTypes(types2, opts.coerceTypes);
1738
- const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
1783
+ const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
1739
1784
  if (checkTypes) {
1740
1785
  const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
1741
1786
  gen.if(wrongType, () => {
@@ -1754,12 +1799,12 @@ function coerceToTypes(types2, coerceTypes) {
1754
1799
  }
1755
1800
  function coerceData(it, types2, coerceTo) {
1756
1801
  const { gen, data, opts } = it;
1757
- const dataType2 = gen.let("dataType", (0, codegen_1$r._)`typeof ${data}`);
1758
- const coerced = gen.let("coerced", (0, codegen_1$r._)`undefined`);
1802
+ const dataType2 = gen.let("dataType", (0, codegen_1$w._)`typeof ${data}`);
1803
+ const coerced = gen.let("coerced", (0, codegen_1$w._)`undefined`);
1759
1804
  if (opts.coerceTypes === "array") {
1760
- gen.if((0, codegen_1$r._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$r._)`${data}[0]`).assign(dataType2, (0, codegen_1$r._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
1805
+ gen.if((0, codegen_1$w._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$w._)`${data}[0]`).assign(dataType2, (0, codegen_1$w._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
1761
1806
  }
1762
- gen.if((0, codegen_1$r._)`${coerced} !== undefined`);
1807
+ gen.if((0, codegen_1$w._)`${coerced} !== undefined`);
1763
1808
  for (const t of coerceTo) {
1764
1809
  if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
1765
1810
  coerceSpecificType(t);
@@ -1768,63 +1813,63 @@ function coerceData(it, types2, coerceTo) {
1768
1813
  gen.else();
1769
1814
  reportTypeError(it);
1770
1815
  gen.endIf();
1771
- gen.if((0, codegen_1$r._)`${coerced} !== undefined`, () => {
1816
+ gen.if((0, codegen_1$w._)`${coerced} !== undefined`, () => {
1772
1817
  gen.assign(data, coerced);
1773
1818
  assignParentData(it, coerced);
1774
1819
  });
1775
1820
  function coerceSpecificType(t) {
1776
1821
  switch (t) {
1777
1822
  case "string":
1778
- gen.elseIf((0, codegen_1$r._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$r._)`"" + ${data}`).elseIf((0, codegen_1$r._)`${data} === null`).assign(coerced, (0, codegen_1$r._)`""`);
1823
+ gen.elseIf((0, codegen_1$w._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$w._)`"" + ${data}`).elseIf((0, codegen_1$w._)`${data} === null`).assign(coerced, (0, codegen_1$w._)`""`);
1779
1824
  return;
1780
1825
  case "number":
1781
- gen.elseIf((0, codegen_1$r._)`${dataType2} == "boolean" || ${data} === null
1782
- || (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$r._)`+${data}`);
1826
+ gen.elseIf((0, codegen_1$w._)`${dataType2} == "boolean" || ${data} === null
1827
+ || (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$w._)`+${data}`);
1783
1828
  return;
1784
1829
  case "integer":
1785
- gen.elseIf((0, codegen_1$r._)`${dataType2} === "boolean" || ${data} === null
1786
- || (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$r._)`+${data}`);
1830
+ gen.elseIf((0, codegen_1$w._)`${dataType2} === "boolean" || ${data} === null
1831
+ || (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$w._)`+${data}`);
1787
1832
  return;
1788
1833
  case "boolean":
1789
- gen.elseIf((0, codegen_1$r._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$r._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
1834
+ gen.elseIf((0, codegen_1$w._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$w._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
1790
1835
  return;
1791
1836
  case "null":
1792
- gen.elseIf((0, codegen_1$r._)`${data} === "" || ${data} === 0 || ${data} === false`);
1837
+ gen.elseIf((0, codegen_1$w._)`${data} === "" || ${data} === 0 || ${data} === false`);
1793
1838
  gen.assign(coerced, null);
1794
1839
  return;
1795
1840
  case "array":
1796
- gen.elseIf((0, codegen_1$r._)`${dataType2} === "string" || ${dataType2} === "number"
1797
- || ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$r._)`[${data}]`);
1841
+ gen.elseIf((0, codegen_1$w._)`${dataType2} === "string" || ${dataType2} === "number"
1842
+ || ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$w._)`[${data}]`);
1798
1843
  }
1799
1844
  }
1800
1845
  }
1801
1846
  function assignParentData({ gen, parentData, parentDataProperty }, expr) {
1802
- gen.if((0, codegen_1$r._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$r._)`${parentData}[${parentDataProperty}]`, expr));
1847
+ gen.if((0, codegen_1$w._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$w._)`${parentData}[${parentDataProperty}]`, expr));
1803
1848
  }
1804
1849
  function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
1805
- const EQ = correct === DataType.Correct ? codegen_1$r.operators.EQ : codegen_1$r.operators.NEQ;
1850
+ const EQ = correct === DataType.Correct ? codegen_1$w.operators.EQ : codegen_1$w.operators.NEQ;
1806
1851
  let cond;
1807
1852
  switch (dataType2) {
1808
1853
  case "null":
1809
- return (0, codegen_1$r._)`${data} ${EQ} null`;
1854
+ return (0, codegen_1$w._)`${data} ${EQ} null`;
1810
1855
  case "array":
1811
- cond = (0, codegen_1$r._)`Array.isArray(${data})`;
1856
+ cond = (0, codegen_1$w._)`Array.isArray(${data})`;
1812
1857
  break;
1813
1858
  case "object":
1814
- cond = (0, codegen_1$r._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
1859
+ cond = (0, codegen_1$w._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
1815
1860
  break;
1816
1861
  case "integer":
1817
- cond = numCond((0, codegen_1$r._)`!(${data} % 1) && !isNaN(${data})`);
1862
+ cond = numCond((0, codegen_1$w._)`!(${data} % 1) && !isNaN(${data})`);
1818
1863
  break;
1819
1864
  case "number":
1820
1865
  cond = numCond();
1821
1866
  break;
1822
1867
  default:
1823
- return (0, codegen_1$r._)`typeof ${data} ${EQ} ${dataType2}`;
1868
+ return (0, codegen_1$w._)`typeof ${data} ${EQ} ${dataType2}`;
1824
1869
  }
1825
- return correct === DataType.Correct ? cond : (0, codegen_1$r.not)(cond);
1826
- function numCond(_cond = codegen_1$r.nil) {
1827
- return (0, codegen_1$r.and)((0, codegen_1$r._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$r._)`isFinite(${data})` : codegen_1$r.nil);
1870
+ return correct === DataType.Correct ? cond : (0, codegen_1$w.not)(cond);
1871
+ function numCond(_cond = codegen_1$w.nil) {
1872
+ return (0, codegen_1$w.and)((0, codegen_1$w._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$w._)`isFinite(${data})` : codegen_1$w.nil);
1828
1873
  }
1829
1874
  }
1830
1875
  dataType.checkDataType = checkDataType;
@@ -1833,35 +1878,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
1833
1878
  return checkDataType(dataTypes[0], data, strictNums, correct);
1834
1879
  }
1835
1880
  let cond;
1836
- const types2 = (0, util_1$q.toHash)(dataTypes);
1881
+ const types2 = (0, util_1$u.toHash)(dataTypes);
1837
1882
  if (types2.array && types2.object) {
1838
- const notObj = (0, codegen_1$r._)`typeof ${data} != "object"`;
1839
- cond = types2.null ? notObj : (0, codegen_1$r._)`!${data} || ${notObj}`;
1883
+ const notObj = (0, codegen_1$w._)`typeof ${data} != "object"`;
1884
+ cond = types2.null ? notObj : (0, codegen_1$w._)`!${data} || ${notObj}`;
1840
1885
  delete types2.null;
1841
1886
  delete types2.array;
1842
1887
  delete types2.object;
1843
1888
  } else {
1844
- cond = codegen_1$r.nil;
1889
+ cond = codegen_1$w.nil;
1845
1890
  }
1846
1891
  if (types2.number)
1847
1892
  delete types2.integer;
1848
1893
  for (const t in types2)
1849
- cond = (0, codegen_1$r.and)(cond, checkDataType(t, data, strictNums, correct));
1894
+ cond = (0, codegen_1$w.and)(cond, checkDataType(t, data, strictNums, correct));
1850
1895
  return cond;
1851
1896
  }
1852
1897
  dataType.checkDataTypes = checkDataTypes;
1853
1898
  const typeError = {
1854
1899
  message: ({ schema }) => `must be ${schema}`,
1855
- params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$r._)`{type: ${schema}}` : (0, codegen_1$r._)`{type: ${schemaValue}}`
1900
+ params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$w._)`{type: ${schema}}` : (0, codegen_1$w._)`{type: ${schemaValue}}`
1856
1901
  };
1857
1902
  function reportTypeError(it) {
1858
1903
  const cxt = getTypeErrorContext(it);
1859
- (0, errors_1.reportError)(cxt, typeError);
1904
+ (0, errors_1$2.reportError)(cxt, typeError);
1860
1905
  }
1861
1906
  dataType.reportTypeError = reportTypeError;
1862
1907
  function getTypeErrorContext(it) {
1863
1908
  const { gen, data, schema } = it;
1864
- const schemaCode = (0, util_1$q.schemaRefOrVal)(it, schema, "type");
1909
+ const schemaCode = (0, util_1$u.schemaRefOrVal)(it, schema, "type");
1865
1910
  return {
1866
1911
  gen,
1867
1912
  keyword: "type",
@@ -1875,380 +1920,352 @@ function getTypeErrorContext(it) {
1875
1920
  };
1876
1921
  }
1877
1922
  var defaults = {};
1878
- var hasRequiredDefaults;
1879
- function requireDefaults() {
1880
- if (hasRequiredDefaults)
1881
- return defaults;
1882
- hasRequiredDefaults = 1;
1883
- Object.defineProperty(defaults, "__esModule", { value: true });
1884
- defaults.assignDefaults = void 0;
1885
- const codegen_12 = codegen;
1886
- const util_12 = util;
1887
- function assignDefaults(it, ty) {
1888
- const { properties: properties2, items: items2 } = it.schema;
1889
- if (ty === "object" && properties2) {
1890
- for (const key in properties2) {
1891
- assignDefault(it, key, properties2[key].default);
1892
- }
1893
- } else if (ty === "array" && Array.isArray(items2)) {
1894
- items2.forEach((sch, i) => assignDefault(it, i, sch.default));
1895
- }
1923
+ Object.defineProperty(defaults, "__esModule", { value: true });
1924
+ defaults.assignDefaults = void 0;
1925
+ const codegen_1$v = codegen;
1926
+ const util_1$t = util;
1927
+ function assignDefaults(it, ty) {
1928
+ const { properties: properties2, items: items2 } = it.schema;
1929
+ if (ty === "object" && properties2) {
1930
+ for (const key in properties2) {
1931
+ assignDefault(it, key, properties2[key].default);
1932
+ }
1933
+ } else if (ty === "array" && Array.isArray(items2)) {
1934
+ items2.forEach((sch, i) => assignDefault(it, i, sch.default));
1896
1935
  }
1897
- defaults.assignDefaults = assignDefaults;
1898
- function assignDefault(it, prop, defaultValue) {
1899
- const { gen, compositeRule, data, opts } = it;
1900
- if (defaultValue === void 0)
1901
- return;
1902
- const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
1903
- if (compositeRule) {
1904
- (0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
1905
- return;
1906
- }
1907
- let condition = (0, codegen_12._)`${childData} === undefined`;
1908
- if (opts.useDefaults === "empty") {
1909
- condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
1910
- }
1911
- gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
1936
+ }
1937
+ defaults.assignDefaults = assignDefaults;
1938
+ function assignDefault(it, prop, defaultValue) {
1939
+ const { gen, compositeRule, data, opts } = it;
1940
+ if (defaultValue === void 0)
1941
+ return;
1942
+ const childData = (0, codegen_1$v._)`${data}${(0, codegen_1$v.getProperty)(prop)}`;
1943
+ if (compositeRule) {
1944
+ (0, util_1$t.checkStrictMode)(it, `default is ignored for: ${childData}`);
1945
+ return;
1946
+ }
1947
+ let condition = (0, codegen_1$v._)`${childData} === undefined`;
1948
+ if (opts.useDefaults === "empty") {
1949
+ condition = (0, codegen_1$v._)`${condition} || ${childData} === null || ${childData} === ""`;
1912
1950
  }
1913
- return defaults;
1951
+ gen.if(condition, (0, codegen_1$v._)`${childData} = ${(0, codegen_1$v.stringify)(defaultValue)}`);
1914
1952
  }
1915
1953
  var keyword = {};
1916
1954
  var code = {};
1917
- var hasRequiredCode;
1918
- function requireCode() {
1919
- if (hasRequiredCode)
1920
- return code;
1921
- hasRequiredCode = 1;
1922
- Object.defineProperty(code, "__esModule", { value: true });
1923
- code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
1924
- const codegen_12 = codegen;
1925
- const util_12 = util;
1926
- const names_12 = requireNames();
1927
- const util_22 = util;
1928
- function checkReportMissingProp(cxt, prop) {
1929
- const { gen, data, it } = cxt;
1930
- gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
1931
- cxt.setParams({ missingProperty: (0, codegen_12._)`${prop}` }, true);
1932
- cxt.error();
1955
+ Object.defineProperty(code, "__esModule", { value: true });
1956
+ code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
1957
+ const codegen_1$u = codegen;
1958
+ const util_1$s = util;
1959
+ const names_1$8 = names$1;
1960
+ const util_2$1 = util;
1961
+ function checkReportMissingProp(cxt, prop) {
1962
+ const { gen, data, it } = cxt;
1963
+ gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
1964
+ cxt.setParams({ missingProperty: (0, codegen_1$u._)`${prop}` }, true);
1965
+ cxt.error();
1966
+ });
1967
+ }
1968
+ code.checkReportMissingProp = checkReportMissingProp;
1969
+ function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
1970
+ return (0, codegen_1$u.or)(...properties2.map((prop) => (0, codegen_1$u.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$u._)`${missing} = ${prop}`)));
1971
+ }
1972
+ code.checkMissingProp = checkMissingProp;
1973
+ function reportMissingProp(cxt, missing) {
1974
+ cxt.setParams({ missingProperty: missing }, true);
1975
+ cxt.error();
1976
+ }
1977
+ code.reportMissingProp = reportMissingProp;
1978
+ function hasPropFunc(gen) {
1979
+ return gen.scopeValue("func", {
1980
+ // eslint-disable-next-line @typescript-eslint/unbound-method
1981
+ ref: Object.prototype.hasOwnProperty,
1982
+ code: (0, codegen_1$u._)`Object.prototype.hasOwnProperty`
1983
+ });
1984
+ }
1985
+ code.hasPropFunc = hasPropFunc;
1986
+ function isOwnProperty(gen, data, property) {
1987
+ return (0, codegen_1$u._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
1988
+ }
1989
+ code.isOwnProperty = isOwnProperty;
1990
+ function propertyInData(gen, data, property, ownProperties) {
1991
+ const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} !== undefined`;
1992
+ return ownProperties ? (0, codegen_1$u._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
1993
+ }
1994
+ code.propertyInData = propertyInData;
1995
+ function noPropertyInData(gen, data, property, ownProperties) {
1996
+ const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} === undefined`;
1997
+ return ownProperties ? (0, codegen_1$u.or)(cond, (0, codegen_1$u.not)(isOwnProperty(gen, data, property))) : cond;
1998
+ }
1999
+ code.noPropertyInData = noPropertyInData;
2000
+ function allSchemaProperties(schemaMap) {
2001
+ return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
2002
+ }
2003
+ code.allSchemaProperties = allSchemaProperties;
2004
+ function schemaProperties(it, schemaMap) {
2005
+ return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$s.alwaysValidSchema)(it, schemaMap[p]));
2006
+ }
2007
+ code.schemaProperties = schemaProperties;
2008
+ function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
2009
+ const dataAndSchema = passSchema ? (0, codegen_1$u._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
2010
+ const valCxt = [
2011
+ [names_1$8.default.instancePath, (0, codegen_1$u.strConcat)(names_1$8.default.instancePath, errorPath)],
2012
+ [names_1$8.default.parentData, it.parentData],
2013
+ [names_1$8.default.parentDataProperty, it.parentDataProperty],
2014
+ [names_1$8.default.rootData, names_1$8.default.rootData]
2015
+ ];
2016
+ if (it.opts.dynamicRef)
2017
+ valCxt.push([names_1$8.default.dynamicAnchors, names_1$8.default.dynamicAnchors]);
2018
+ const args = (0, codegen_1$u._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
2019
+ return context2 !== codegen_1$u.nil ? (0, codegen_1$u._)`${func}.call(${context2}, ${args})` : (0, codegen_1$u._)`${func}(${args})`;
2020
+ }
2021
+ code.callValidateCode = callValidateCode;
2022
+ const newRegExp = (0, codegen_1$u._)`new RegExp`;
2023
+ function usePattern({ gen, it: { opts } }, pattern2) {
2024
+ const u = opts.unicodeRegExp ? "u" : "";
2025
+ const { regExp } = opts.code;
2026
+ const rx = regExp(pattern2, u);
2027
+ return gen.scopeValue("pattern", {
2028
+ key: rx.toString(),
2029
+ ref: rx,
2030
+ code: (0, codegen_1$u._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
2031
+ });
2032
+ }
2033
+ code.usePattern = usePattern;
2034
+ function validateArray(cxt) {
2035
+ const { gen, data, keyword: keyword2, it } = cxt;
2036
+ const valid = gen.name("valid");
2037
+ if (it.allErrors) {
2038
+ const validArr = gen.let("valid", true);
2039
+ validateItems(() => gen.assign(validArr, false));
2040
+ return validArr;
2041
+ }
2042
+ gen.var(valid, true);
2043
+ validateItems(() => gen.break());
2044
+ return valid;
2045
+ function validateItems(notValid) {
2046
+ const len = gen.const("len", (0, codegen_1$u._)`${data}.length`);
2047
+ gen.forRange("i", 0, len, (i) => {
2048
+ cxt.subschema({
2049
+ keyword: keyword2,
2050
+ dataProp: i,
2051
+ dataPropType: util_1$s.Type.Num
2052
+ }, valid);
2053
+ gen.if((0, codegen_1$u.not)(valid), notValid);
1933
2054
  });
1934
2055
  }
1935
- code.checkReportMissingProp = checkReportMissingProp;
1936
- function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
1937
- return (0, codegen_12.or)(...properties2.map((prop) => (0, codegen_12.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_12._)`${missing} = ${prop}`)));
2056
+ }
2057
+ code.validateArray = validateArray;
2058
+ function validateUnion(cxt) {
2059
+ const { gen, schema, keyword: keyword2, it } = cxt;
2060
+ if (!Array.isArray(schema))
2061
+ throw new Error("ajv implementation error");
2062
+ const alwaysValid = schema.some((sch) => (0, util_1$s.alwaysValidSchema)(it, sch));
2063
+ if (alwaysValid && !it.opts.unevaluated)
2064
+ return;
2065
+ const valid = gen.let("valid", false);
2066
+ const schValid = gen.name("_valid");
2067
+ gen.block(() => schema.forEach((_sch, i) => {
2068
+ const schCxt = cxt.subschema({
2069
+ keyword: keyword2,
2070
+ schemaProp: i,
2071
+ compositeRule: true
2072
+ }, schValid);
2073
+ gen.assign(valid, (0, codegen_1$u._)`${valid} || ${schValid}`);
2074
+ const merged = cxt.mergeValidEvaluated(schCxt, schValid);
2075
+ if (!merged)
2076
+ gen.if((0, codegen_1$u.not)(valid));
2077
+ }));
2078
+ cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
2079
+ }
2080
+ code.validateUnion = validateUnion;
2081
+ Object.defineProperty(keyword, "__esModule", { value: true });
2082
+ keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
2083
+ const codegen_1$t = codegen;
2084
+ const names_1$7 = names$1;
2085
+ const code_1$9 = code;
2086
+ const errors_1$1 = errors;
2087
+ function macroKeywordCode(cxt, def2) {
2088
+ const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
2089
+ const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
2090
+ const schemaRef = useKeyword(gen, keyword2, macroSchema);
2091
+ if (it.opts.validateSchema !== false)
2092
+ it.self.validateSchema(macroSchema, true);
2093
+ const valid = gen.name("valid");
2094
+ cxt.subschema({
2095
+ schema: macroSchema,
2096
+ schemaPath: codegen_1$t.nil,
2097
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
2098
+ topSchemaRef: schemaRef,
2099
+ compositeRule: true
2100
+ }, valid);
2101
+ cxt.pass(valid, () => cxt.error(true));
2102
+ }
2103
+ keyword.macroKeywordCode = macroKeywordCode;
2104
+ function funcKeywordCode(cxt, def2) {
2105
+ var _a;
2106
+ const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
2107
+ checkAsyncKeyword(it, def2);
2108
+ const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
2109
+ const validateRef = useKeyword(gen, keyword2, validate2);
2110
+ const valid = gen.let("valid");
2111
+ cxt.block$data(valid, validateKeyword);
2112
+ cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
2113
+ function validateKeyword() {
2114
+ if (def2.errors === false) {
2115
+ assignValid();
2116
+ if (def2.modifying)
2117
+ modifyData(cxt);
2118
+ reportErrs(() => cxt.error());
2119
+ } else {
2120
+ const ruleErrs = def2.async ? validateAsync() : validateSync();
2121
+ if (def2.modifying)
2122
+ modifyData(cxt);
2123
+ reportErrs(() => addErrs(cxt, ruleErrs));
2124
+ }
1938
2125
  }
1939
- code.checkMissingProp = checkMissingProp;
1940
- function reportMissingProp(cxt, missing) {
1941
- cxt.setParams({ missingProperty: missing }, true);
1942
- cxt.error();
2126
+ function validateAsync() {
2127
+ const ruleErrs = gen.let("ruleErrs", null);
2128
+ gen.try(() => assignValid((0, codegen_1$t._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$t._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$t._)`${e}.errors`), () => gen.throw(e)));
2129
+ return ruleErrs;
1943
2130
  }
1944
- code.reportMissingProp = reportMissingProp;
1945
- function hasPropFunc(gen) {
1946
- return gen.scopeValue("func", {
1947
- // eslint-disable-next-line @typescript-eslint/unbound-method
1948
- ref: Object.prototype.hasOwnProperty,
1949
- code: (0, codegen_12._)`Object.prototype.hasOwnProperty`
1950
- });
2131
+ function validateSync() {
2132
+ const validateErrs = (0, codegen_1$t._)`${validateRef}.errors`;
2133
+ gen.assign(validateErrs, null);
2134
+ assignValid(codegen_1$t.nil);
2135
+ return validateErrs;
1951
2136
  }
1952
- code.hasPropFunc = hasPropFunc;
1953
- function isOwnProperty(gen, data, property) {
1954
- return (0, codegen_12._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
1955
- }
1956
- code.isOwnProperty = isOwnProperty;
1957
- function propertyInData(gen, data, property, ownProperties) {
1958
- const cond = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(property)} !== undefined`;
1959
- return ownProperties ? (0, codegen_12._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
1960
- }
1961
- code.propertyInData = propertyInData;
1962
- function noPropertyInData(gen, data, property, ownProperties) {
1963
- const cond = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(property)} === undefined`;
1964
- return ownProperties ? (0, codegen_12.or)(cond, (0, codegen_12.not)(isOwnProperty(gen, data, property))) : cond;
1965
- }
1966
- code.noPropertyInData = noPropertyInData;
1967
- function allSchemaProperties(schemaMap) {
1968
- return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
1969
- }
1970
- code.allSchemaProperties = allSchemaProperties;
1971
- function schemaProperties(it, schemaMap) {
1972
- return allSchemaProperties(schemaMap).filter((p) => !(0, util_12.alwaysValidSchema)(it, schemaMap[p]));
1973
- }
1974
- code.schemaProperties = schemaProperties;
1975
- function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
1976
- const dataAndSchema = passSchema ? (0, codegen_12._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
1977
- const valCxt = [
1978
- [names_12.default.instancePath, (0, codegen_12.strConcat)(names_12.default.instancePath, errorPath)],
1979
- [names_12.default.parentData, it.parentData],
1980
- [names_12.default.parentDataProperty, it.parentDataProperty],
1981
- [names_12.default.rootData, names_12.default.rootData]
1982
- ];
1983
- if (it.opts.dynamicRef)
1984
- valCxt.push([names_12.default.dynamicAnchors, names_12.default.dynamicAnchors]);
1985
- const args = (0, codegen_12._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
1986
- return context2 !== codegen_12.nil ? (0, codegen_12._)`${func}.call(${context2}, ${args})` : (0, codegen_12._)`${func}(${args})`;
1987
- }
1988
- code.callValidateCode = callValidateCode;
1989
- const newRegExp = (0, codegen_12._)`new RegExp`;
1990
- function usePattern({ gen, it: { opts } }, pattern2) {
1991
- const u = opts.unicodeRegExp ? "u" : "";
1992
- const { regExp } = opts.code;
1993
- const rx = regExp(pattern2, u);
1994
- return gen.scopeValue("pattern", {
1995
- key: rx.toString(),
1996
- ref: rx,
1997
- code: (0, codegen_12._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_22.useFunc)(gen, regExp)}(${pattern2}, ${u})`
1998
- });
2137
+ function assignValid(_await = def2.async ? (0, codegen_1$t._)`await ` : codegen_1$t.nil) {
2138
+ const passCxt = it.opts.passContext ? names_1$7.default.this : names_1$7.default.self;
2139
+ const passSchema = !("compile" in def2 && !$data || def2.schema === false);
2140
+ gen.assign(valid, (0, codegen_1$t._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
1999
2141
  }
2000
- code.usePattern = usePattern;
2001
- function validateArray(cxt) {
2002
- const { gen, data, keyword: keyword2, it } = cxt;
2003
- const valid = gen.name("valid");
2004
- if (it.allErrors) {
2005
- const validArr = gen.let("valid", true);
2006
- validateItems(() => gen.assign(validArr, false));
2007
- return validArr;
2008
- }
2009
- gen.var(valid, true);
2010
- validateItems(() => gen.break());
2011
- return valid;
2012
- function validateItems(notValid) {
2013
- const len = gen.const("len", (0, codegen_12._)`${data}.length`);
2014
- gen.forRange("i", 0, len, (i) => {
2015
- cxt.subschema({
2016
- keyword: keyword2,
2017
- dataProp: i,
2018
- dataPropType: util_12.Type.Num
2019
- }, valid);
2020
- gen.if((0, codegen_12.not)(valid), notValid);
2021
- });
2022
- }
2142
+ function reportErrs(errors2) {
2143
+ var _a2;
2144
+ gen.if((0, codegen_1$t.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
2023
2145
  }
2024
- code.validateArray = validateArray;
2025
- function validateUnion(cxt) {
2026
- const { gen, schema, keyword: keyword2, it } = cxt;
2027
- if (!Array.isArray(schema))
2028
- throw new Error("ajv implementation error");
2029
- const alwaysValid = schema.some((sch) => (0, util_12.alwaysValidSchema)(it, sch));
2030
- if (alwaysValid && !it.opts.unevaluated)
2031
- return;
2032
- const valid = gen.let("valid", false);
2033
- const schValid = gen.name("_valid");
2034
- gen.block(() => schema.forEach((_sch, i) => {
2035
- const schCxt = cxt.subschema({
2036
- keyword: keyword2,
2037
- schemaProp: i,
2038
- compositeRule: true
2039
- }, schValid);
2040
- gen.assign(valid, (0, codegen_12._)`${valid} || ${schValid}`);
2041
- const merged = cxt.mergeValidEvaluated(schCxt, schValid);
2042
- if (!merged)
2043
- gen.if((0, codegen_12.not)(valid));
2044
- }));
2045
- cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
2146
+ }
2147
+ keyword.funcKeywordCode = funcKeywordCode;
2148
+ function modifyData(cxt) {
2149
+ const { gen, data, it } = cxt;
2150
+ gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$t._)`${it.parentData}[${it.parentDataProperty}]`));
2151
+ }
2152
+ function addErrs(cxt, errs) {
2153
+ const { gen } = cxt;
2154
+ gen.if((0, codegen_1$t._)`Array.isArray(${errs})`, () => {
2155
+ gen.assign(names_1$7.default.vErrors, (0, codegen_1$t._)`${names_1$7.default.vErrors} === null ? ${errs} : ${names_1$7.default.vErrors}.concat(${errs})`).assign(names_1$7.default.errors, (0, codegen_1$t._)`${names_1$7.default.vErrors}.length`);
2156
+ (0, errors_1$1.extendErrors)(cxt);
2157
+ }, () => cxt.error());
2158
+ }
2159
+ function checkAsyncKeyword({ schemaEnv }, def2) {
2160
+ if (def2.async && !schemaEnv.$async)
2161
+ throw new Error("async keyword in sync schema");
2162
+ }
2163
+ function useKeyword(gen, keyword2, result) {
2164
+ if (result === void 0)
2165
+ throw new Error(`keyword "${keyword2}" failed to compile`);
2166
+ return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$t.stringify)(result) });
2167
+ }
2168
+ function validSchemaType(schema, schemaType, allowUndefined = false) {
2169
+ return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
2170
+ }
2171
+ keyword.validSchemaType = validSchemaType;
2172
+ function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
2173
+ if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
2174
+ throw new Error("ajv implementation error");
2175
+ }
2176
+ const deps = def2.dependencies;
2177
+ if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
2178
+ throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
2179
+ }
2180
+ if (def2.validateSchema) {
2181
+ const valid = def2.validateSchema(schema[keyword2]);
2182
+ if (!valid) {
2183
+ const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
2184
+ if (opts.validateSchema === "log")
2185
+ self.logger.error(msg);
2186
+ else
2187
+ throw new Error(msg);
2188
+ }
2046
2189
  }
2047
- code.validateUnion = validateUnion;
2048
- return code;
2049
2190
  }
2050
- var hasRequiredKeyword;
2051
- function requireKeyword() {
2052
- if (hasRequiredKeyword)
2053
- return keyword;
2054
- hasRequiredKeyword = 1;
2055
- Object.defineProperty(keyword, "__esModule", { value: true });
2056
- keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
2057
- const codegen_12 = codegen;
2058
- const names_12 = requireNames();
2059
- const code_12 = requireCode();
2060
- const errors_12 = errors;
2061
- function macroKeywordCode(cxt, def2) {
2062
- const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
2063
- const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
2064
- const schemaRef = useKeyword(gen, keyword2, macroSchema);
2065
- if (it.opts.validateSchema !== false)
2066
- it.self.validateSchema(macroSchema, true);
2067
- const valid = gen.name("valid");
2068
- cxt.subschema({
2069
- schema: macroSchema,
2070
- schemaPath: codegen_12.nil,
2071
- errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
2072
- topSchemaRef: schemaRef,
2073
- compositeRule: true
2074
- }, valid);
2075
- cxt.pass(valid, () => cxt.error(true));
2191
+ keyword.validateKeywordUsage = validateKeywordUsage;
2192
+ var subschema = {};
2193
+ Object.defineProperty(subschema, "__esModule", { value: true });
2194
+ subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
2195
+ const codegen_1$s = codegen;
2196
+ const util_1$r = util;
2197
+ function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
2198
+ if (keyword2 !== void 0 && schema !== void 0) {
2199
+ throw new Error('both "keyword" and "schema" passed, only one allowed');
2200
+ }
2201
+ if (keyword2 !== void 0) {
2202
+ const sch = it.schema[keyword2];
2203
+ return schemaProp === void 0 ? {
2204
+ schema: sch,
2205
+ schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`,
2206
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}`
2207
+ } : {
2208
+ schema: sch[schemaProp],
2209
+ schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}${(0, codegen_1$s.getProperty)(schemaProp)}`,
2210
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$r.escapeFragment)(schemaProp)}`
2211
+ };
2076
2212
  }
2077
- keyword.macroKeywordCode = macroKeywordCode;
2078
- function funcKeywordCode(cxt, def2) {
2079
- var _a;
2080
- const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
2081
- checkAsyncKeyword(it, def2);
2082
- const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
2083
- const validateRef = useKeyword(gen, keyword2, validate2);
2084
- const valid = gen.let("valid");
2085
- cxt.block$data(valid, validateKeyword);
2086
- cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
2087
- function validateKeyword() {
2088
- if (def2.errors === false) {
2089
- assignValid();
2090
- if (def2.modifying)
2091
- modifyData(cxt);
2092
- reportErrs(() => cxt.error());
2093
- } else {
2094
- const ruleErrs = def2.async ? validateAsync() : validateSync();
2095
- if (def2.modifying)
2096
- modifyData(cxt);
2097
- reportErrs(() => addErrs(cxt, ruleErrs));
2098
- }
2099
- }
2100
- function validateAsync() {
2101
- const ruleErrs = gen.let("ruleErrs", null);
2102
- gen.try(() => assignValid((0, codegen_12._)`await `), (e) => gen.assign(valid, false).if((0, codegen_12._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_12._)`${e}.errors`), () => gen.throw(e)));
2103
- return ruleErrs;
2104
- }
2105
- function validateSync() {
2106
- const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
2107
- gen.assign(validateErrs, null);
2108
- assignValid(codegen_12.nil);
2109
- return validateErrs;
2110
- }
2111
- function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
2112
- const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
2113
- const passSchema = !("compile" in def2 && !$data || def2.schema === false);
2114
- gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
2115
- }
2116
- function reportErrs(errors2) {
2117
- var _a2;
2118
- gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
2213
+ if (schema !== void 0) {
2214
+ if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
2215
+ throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
2119
2216
  }
2217
+ return {
2218
+ schema,
2219
+ schemaPath,
2220
+ topSchemaRef,
2221
+ errSchemaPath
2222
+ };
2120
2223
  }
2121
- keyword.funcKeywordCode = funcKeywordCode;
2122
- function modifyData(cxt) {
2123
- const { gen, data, it } = cxt;
2124
- gen.if(it.parentData, () => gen.assign(data, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
2125
- }
2126
- function addErrs(cxt, errs) {
2127
- const { gen } = cxt;
2128
- gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
2129
- gen.assign(names_12.default.vErrors, (0, codegen_12._)`${names_12.default.vErrors} === null ? ${errs} : ${names_12.default.vErrors}.concat(${errs})`).assign(names_12.default.errors, (0, codegen_12._)`${names_12.default.vErrors}.length`);
2130
- (0, errors_12.extendErrors)(cxt);
2131
- }, () => cxt.error());
2132
- }
2133
- function checkAsyncKeyword({ schemaEnv }, def2) {
2134
- if (def2.async && !schemaEnv.$async)
2135
- throw new Error("async keyword in sync schema");
2136
- }
2137
- function useKeyword(gen, keyword2, result) {
2138
- if (result === void 0)
2139
- throw new Error(`keyword "${keyword2}" failed to compile`);
2140
- return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
2141
- }
2142
- function validSchemaType(schema, schemaType, allowUndefined = false) {
2143
- return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
2144
- }
2145
- keyword.validSchemaType = validSchemaType;
2146
- function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
2147
- if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
2148
- throw new Error("ajv implementation error");
2149
- }
2150
- const deps = def2.dependencies;
2151
- if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
2152
- throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
2153
- }
2154
- if (def2.validateSchema) {
2155
- const valid = def2.validateSchema(schema[keyword2]);
2156
- if (!valid) {
2157
- const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
2158
- if (opts.validateSchema === "log")
2159
- self.logger.error(msg);
2160
- else
2161
- throw new Error(msg);
2162
- }
2163
- }
2224
+ throw new Error('either "keyword" or "schema" must be passed');
2225
+ }
2226
+ subschema.getSubschema = getSubschema;
2227
+ function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
2228
+ if (data !== void 0 && dataProp !== void 0) {
2229
+ throw new Error('both "data" and "dataProp" passed, only one allowed');
2230
+ }
2231
+ const { gen } = it;
2232
+ if (dataProp !== void 0) {
2233
+ const { errorPath, dataPathArr, opts } = it;
2234
+ const nextData = gen.let("data", (0, codegen_1$s._)`${it.data}${(0, codegen_1$s.getProperty)(dataProp)}`, true);
2235
+ dataContextProps(nextData);
2236
+ subschema2.errorPath = (0, codegen_1$s.str)`${errorPath}${(0, util_1$r.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
2237
+ subschema2.parentDataProperty = (0, codegen_1$s._)`${dataProp}`;
2238
+ subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
2239
+ }
2240
+ if (data !== void 0) {
2241
+ const nextData = data instanceof codegen_1$s.Name ? data : gen.let("data", data, true);
2242
+ dataContextProps(nextData);
2243
+ if (propertyName !== void 0)
2244
+ subschema2.propertyName = propertyName;
2245
+ }
2246
+ if (dataTypes)
2247
+ subschema2.dataTypes = dataTypes;
2248
+ function dataContextProps(_nextData) {
2249
+ subschema2.data = _nextData;
2250
+ subschema2.dataLevel = it.dataLevel + 1;
2251
+ subschema2.dataTypes = [];
2252
+ it.definedProperties = /* @__PURE__ */ new Set();
2253
+ subschema2.parentData = it.data;
2254
+ subschema2.dataNames = [...it.dataNames, _nextData];
2164
2255
  }
2165
- keyword.validateKeywordUsage = validateKeywordUsage;
2166
- return keyword;
2167
2256
  }
2168
- var subschema = {};
2169
- var hasRequiredSubschema;
2170
- function requireSubschema() {
2171
- if (hasRequiredSubschema)
2172
- return subschema;
2173
- hasRequiredSubschema = 1;
2174
- Object.defineProperty(subschema, "__esModule", { value: true });
2175
- subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
2176
- const codegen_12 = codegen;
2177
- const util_12 = util;
2178
- function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
2179
- if (keyword2 !== void 0 && schema !== void 0) {
2180
- throw new Error('both "keyword" and "schema" passed, only one allowed');
2181
- }
2182
- if (keyword2 !== void 0) {
2183
- const sch = it.schema[keyword2];
2184
- return schemaProp === void 0 ? {
2185
- schema: sch,
2186
- schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
2187
- errSchemaPath: `${it.errSchemaPath}/${keyword2}`
2188
- } : {
2189
- schema: sch[schemaProp],
2190
- schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
2191
- errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
2192
- };
2193
- }
2194
- if (schema !== void 0) {
2195
- if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
2196
- throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
2197
- }
2198
- return {
2199
- schema,
2200
- schemaPath,
2201
- topSchemaRef,
2202
- errSchemaPath
2203
- };
2204
- }
2205
- throw new Error('either "keyword" or "schema" must be passed');
2206
- }
2207
- subschema.getSubschema = getSubschema;
2208
- function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
2209
- if (data !== void 0 && dataProp !== void 0) {
2210
- throw new Error('both "data" and "dataProp" passed, only one allowed');
2211
- }
2212
- const { gen } = it;
2213
- if (dataProp !== void 0) {
2214
- const { errorPath, dataPathArr, opts } = it;
2215
- const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
2216
- dataContextProps(nextData);
2217
- subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
2218
- subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
2219
- subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
2220
- }
2221
- if (data !== void 0) {
2222
- const nextData = data instanceof codegen_12.Name ? data : gen.let("data", data, true);
2223
- dataContextProps(nextData);
2224
- if (propertyName !== void 0)
2225
- subschema2.propertyName = propertyName;
2226
- }
2227
- if (dataTypes)
2228
- subschema2.dataTypes = dataTypes;
2229
- function dataContextProps(_nextData) {
2230
- subschema2.data = _nextData;
2231
- subschema2.dataLevel = it.dataLevel + 1;
2232
- subschema2.dataTypes = [];
2233
- it.definedProperties = /* @__PURE__ */ new Set();
2234
- subschema2.parentData = it.data;
2235
- subschema2.dataNames = [...it.dataNames, _nextData];
2236
- }
2237
- }
2238
- subschema.extendSubschemaData = extendSubschemaData;
2239
- function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
2240
- if (compositeRule !== void 0)
2241
- subschema2.compositeRule = compositeRule;
2242
- if (createErrors !== void 0)
2243
- subschema2.createErrors = createErrors;
2244
- if (allErrors !== void 0)
2245
- subschema2.allErrors = allErrors;
2246
- subschema2.jtdDiscriminator = jtdDiscriminator;
2247
- subschema2.jtdMetadata = jtdMetadata;
2248
- }
2249
- subschema.extendSubschemaMode = extendSubschemaMode;
2250
- return subschema;
2257
+ subschema.extendSubschemaData = extendSubschemaData;
2258
+ function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
2259
+ if (compositeRule !== void 0)
2260
+ subschema2.compositeRule = compositeRule;
2261
+ if (createErrors !== void 0)
2262
+ subschema2.createErrors = createErrors;
2263
+ if (allErrors !== void 0)
2264
+ subschema2.allErrors = allErrors;
2265
+ subschema2.jtdDiscriminator = jtdDiscriminator;
2266
+ subschema2.jtdMetadata = jtdMetadata;
2251
2267
  }
2268
+ subschema.extendSubschemaMode = extendSubschemaMode;
2252
2269
  var resolve$2 = {};
2253
2270
  var fastDeepEqual = function equal(a, b) {
2254
2271
  if (a === b)
@@ -2373,7 +2390,7 @@ function escapeJsonPtr(str) {
2373
2390
  var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
2374
2391
  Object.defineProperty(resolve$2, "__esModule", { value: true });
2375
2392
  resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
2376
- const util_1$p = util;
2393
+ const util_1$q = util;
2377
2394
  const equal$3 = fastDeepEqual;
2378
2395
  const traverse = jsonSchemaTraverseExports;
2379
2396
  const SIMPLE_INLINED = /* @__PURE__ */ new Set([
@@ -2432,7 +2449,7 @@ function countKeys(schema) {
2432
2449
  if (SIMPLE_INLINED.has(key))
2433
2450
  continue;
2434
2451
  if (typeof schema[key] == "object") {
2435
- (0, util_1$p.eachItem)(schema[key], (sch) => count += countKeys(sch));
2452
+ (0, util_1$q.eachItem)(schema[key], (sch) => count += countKeys(sch));
2436
2453
  }
2437
2454
  if (count === Infinity)
2438
2455
  return Infinity;
@@ -2520,513 +2537,506 @@ function getSchemaRefs(schema, baseId) {
2520
2537
  }
2521
2538
  }
2522
2539
  resolve$2.getSchemaRefs = getSchemaRefs;
2523
- var hasRequiredValidate;
2524
- function requireValidate() {
2525
- if (hasRequiredValidate)
2526
- return validate;
2527
- hasRequiredValidate = 1;
2528
- Object.defineProperty(validate, "__esModule", { value: true });
2529
- validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
2530
- const boolSchema_1 = requireBoolSchema();
2531
- const dataType_12 = dataType;
2532
- const applicability_12 = requireApplicability();
2533
- const dataType_2 = dataType;
2534
- const defaults_1 = requireDefaults();
2535
- const keyword_1 = requireKeyword();
2536
- const subschema_1 = requireSubschema();
2537
- const codegen_12 = codegen;
2538
- const names_12 = requireNames();
2539
- const resolve_12 = resolve$2;
2540
- const util_12 = util;
2541
- const errors_12 = errors;
2542
- function validateFunctionCode(it) {
2543
- if (isSchemaObj(it)) {
2544
- checkKeywords(it);
2545
- if (schemaCxtHasRules(it)) {
2546
- topSchemaObjCode(it);
2547
- return;
2548
- }
2540
+ Object.defineProperty(validate, "__esModule", { value: true });
2541
+ validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
2542
+ const boolSchema_1 = boolSchema;
2543
+ const dataType_1$1 = dataType;
2544
+ const applicability_1 = applicability;
2545
+ const dataType_2 = dataType;
2546
+ const defaults_1 = defaults;
2547
+ const keyword_1 = keyword;
2548
+ const subschema_1 = subschema;
2549
+ const codegen_1$r = codegen;
2550
+ const names_1$6 = names$1;
2551
+ const resolve_1$2 = resolve$2;
2552
+ const util_1$p = util;
2553
+ const errors_1 = errors;
2554
+ function validateFunctionCode(it) {
2555
+ if (isSchemaObj(it)) {
2556
+ checkKeywords(it);
2557
+ if (schemaCxtHasRules(it)) {
2558
+ topSchemaObjCode(it);
2559
+ return;
2549
2560
  }
2550
- validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
2551
- }
2552
- validate.validateFunctionCode = validateFunctionCode;
2553
- function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
2554
- if (opts.code.es5) {
2555
- gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
2556
- gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
2557
- destructureValCxtES5(gen, opts);
2558
- gen.code(body);
2559
- });
2560
- } else {
2561
- gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
2562
- }
2563
- }
2564
- function destructureValCxt(opts) {
2565
- return (0, codegen_12._)`{${names_12.default.instancePath}="", ${names_12.default.parentData}, ${names_12.default.parentDataProperty}, ${names_12.default.rootData}=${names_12.default.data}${opts.dynamicRef ? (0, codegen_12._)`, ${names_12.default.dynamicAnchors}={}` : codegen_12.nil}}={}`;
2566
- }
2567
- function destructureValCxtES5(gen, opts) {
2568
- gen.if(names_12.default.valCxt, () => {
2569
- gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
2570
- gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
2571
- gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
2572
- gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
2573
- if (opts.dynamicRef)
2574
- gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
2575
- }, () => {
2576
- gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
2577
- gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
2578
- gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
2579
- gen.var(names_12.default.rootData, names_12.default.data);
2580
- if (opts.dynamicRef)
2581
- gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
2582
- });
2583
2561
  }
2584
- function topSchemaObjCode(it) {
2585
- const { schema, opts, gen } = it;
2586
- validateFunction(it, () => {
2587
- if (opts.$comment && schema.$comment)
2588
- commentKeyword(it);
2589
- checkNoDefault(it);
2590
- gen.let(names_12.default.vErrors, null);
2591
- gen.let(names_12.default.errors, 0);
2592
- if (opts.unevaluated)
2593
- resetEvaluated(it);
2594
- typeAndKeywords(it);
2595
- returnResults(it);
2562
+ validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
2563
+ }
2564
+ validate.validateFunctionCode = validateFunctionCode;
2565
+ function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
2566
+ if (opts.code.es5) {
2567
+ gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${names_1$6.default.valCxt}`, schemaEnv.$async, () => {
2568
+ gen.code((0, codegen_1$r._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
2569
+ destructureValCxtES5(gen, opts);
2570
+ gen.code(body);
2596
2571
  });
2597
- return;
2598
- }
2599
- function resetEvaluated(it) {
2600
- const { gen, validateName } = it;
2601
- it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
2602
- gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
2603
- gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
2604
- }
2605
- function funcSourceUrl(schema, opts) {
2606
- const schId = typeof schema == "object" && schema[opts.schemaId];
2607
- return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
2608
- }
2609
- function subschemaCode(it, valid) {
2610
- if (isSchemaObj(it)) {
2611
- checkKeywords(it);
2612
- if (schemaCxtHasRules(it)) {
2613
- subSchemaObjCode(it, valid);
2614
- return;
2615
- }
2616
- }
2617
- (0, boolSchema_1.boolOrEmptySchema)(it, valid);
2618
- }
2619
- function schemaCxtHasRules({ schema, self }) {
2620
- if (typeof schema == "boolean")
2621
- return !schema;
2622
- for (const key in schema)
2623
- if (self.RULES.all[key])
2624
- return true;
2625
- return false;
2626
- }
2627
- function isSchemaObj(it) {
2628
- return typeof it.schema != "boolean";
2572
+ } else {
2573
+ gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
2629
2574
  }
2630
- function subSchemaObjCode(it, valid) {
2631
- const { schema, gen, opts } = it;
2575
+ }
2576
+ function destructureValCxt(opts) {
2577
+ return (0, codegen_1$r._)`{${names_1$6.default.instancePath}="", ${names_1$6.default.parentData}, ${names_1$6.default.parentDataProperty}, ${names_1$6.default.rootData}=${names_1$6.default.data}${opts.dynamicRef ? (0, codegen_1$r._)`, ${names_1$6.default.dynamicAnchors}={}` : codegen_1$r.nil}}={}`;
2578
+ }
2579
+ function destructureValCxtES5(gen, opts) {
2580
+ gen.if(names_1$6.default.valCxt, () => {
2581
+ gen.var(names_1$6.default.instancePath, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.instancePath}`);
2582
+ gen.var(names_1$6.default.parentData, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.parentData}`);
2583
+ gen.var(names_1$6.default.parentDataProperty, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.parentDataProperty}`);
2584
+ gen.var(names_1$6.default.rootData, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.rootData}`);
2585
+ if (opts.dynamicRef)
2586
+ gen.var(names_1$6.default.dynamicAnchors, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.dynamicAnchors}`);
2587
+ }, () => {
2588
+ gen.var(names_1$6.default.instancePath, (0, codegen_1$r._)`""`);
2589
+ gen.var(names_1$6.default.parentData, (0, codegen_1$r._)`undefined`);
2590
+ gen.var(names_1$6.default.parentDataProperty, (0, codegen_1$r._)`undefined`);
2591
+ gen.var(names_1$6.default.rootData, names_1$6.default.data);
2592
+ if (opts.dynamicRef)
2593
+ gen.var(names_1$6.default.dynamicAnchors, (0, codegen_1$r._)`{}`);
2594
+ });
2595
+ }
2596
+ function topSchemaObjCode(it) {
2597
+ const { schema, opts, gen } = it;
2598
+ validateFunction(it, () => {
2632
2599
  if (opts.$comment && schema.$comment)
2633
2600
  commentKeyword(it);
2634
- updateContext(it);
2635
- checkAsyncSchema(it);
2636
- const errsCount = gen.const("_errs", names_12.default.errors);
2637
- typeAndKeywords(it, errsCount);
2638
- gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
2639
- }
2640
- function checkKeywords(it) {
2641
- (0, util_12.checkUnknownRules)(it);
2642
- checkRefsAndKeywords(it);
2643
- }
2644
- function typeAndKeywords(it, errsCount) {
2645
- if (it.opts.jtd)
2646
- return schemaKeywords(it, [], false, errsCount);
2647
- const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
2648
- const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
2649
- schemaKeywords(it, types2, !checkedTypes, errsCount);
2650
- }
2651
- function checkRefsAndKeywords(it) {
2652
- const { schema, errSchemaPath, opts, self } = it;
2653
- if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self.RULES)) {
2654
- self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
2601
+ checkNoDefault(it);
2602
+ gen.let(names_1$6.default.vErrors, null);
2603
+ gen.let(names_1$6.default.errors, 0);
2604
+ if (opts.unevaluated)
2605
+ resetEvaluated(it);
2606
+ typeAndKeywords(it);
2607
+ returnResults(it);
2608
+ });
2609
+ return;
2610
+ }
2611
+ function resetEvaluated(it) {
2612
+ const { gen, validateName } = it;
2613
+ it.evaluated = gen.const("evaluated", (0, codegen_1$r._)`${validateName}.evaluated`);
2614
+ gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.props`, (0, codegen_1$r._)`undefined`));
2615
+ gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.items`, (0, codegen_1$r._)`undefined`));
2616
+ }
2617
+ function funcSourceUrl(schema, opts) {
2618
+ const schId = typeof schema == "object" && schema[opts.schemaId];
2619
+ return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$r._)`/*# sourceURL=${schId} */` : codegen_1$r.nil;
2620
+ }
2621
+ function subschemaCode(it, valid) {
2622
+ if (isSchemaObj(it)) {
2623
+ checkKeywords(it);
2624
+ if (schemaCxtHasRules(it)) {
2625
+ subSchemaObjCode(it, valid);
2626
+ return;
2655
2627
  }
2656
2628
  }
2657
- function checkNoDefault(it) {
2658
- const { schema, opts } = it;
2659
- if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
2660
- (0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
2661
- }
2629
+ (0, boolSchema_1.boolOrEmptySchema)(it, valid);
2630
+ }
2631
+ function schemaCxtHasRules({ schema, self }) {
2632
+ if (typeof schema == "boolean")
2633
+ return !schema;
2634
+ for (const key in schema)
2635
+ if (self.RULES.all[key])
2636
+ return true;
2637
+ return false;
2638
+ }
2639
+ function isSchemaObj(it) {
2640
+ return typeof it.schema != "boolean";
2641
+ }
2642
+ function subSchemaObjCode(it, valid) {
2643
+ const { schema, gen, opts } = it;
2644
+ if (opts.$comment && schema.$comment)
2645
+ commentKeyword(it);
2646
+ updateContext(it);
2647
+ checkAsyncSchema(it);
2648
+ const errsCount = gen.const("_errs", names_1$6.default.errors);
2649
+ typeAndKeywords(it, errsCount);
2650
+ gen.var(valid, (0, codegen_1$r._)`${errsCount} === ${names_1$6.default.errors}`);
2651
+ }
2652
+ function checkKeywords(it) {
2653
+ (0, util_1$p.checkUnknownRules)(it);
2654
+ checkRefsAndKeywords(it);
2655
+ }
2656
+ function typeAndKeywords(it, errsCount) {
2657
+ if (it.opts.jtd)
2658
+ return schemaKeywords(it, [], false, errsCount);
2659
+ const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
2660
+ const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
2661
+ schemaKeywords(it, types2, !checkedTypes, errsCount);
2662
+ }
2663
+ function checkRefsAndKeywords(it) {
2664
+ const { schema, errSchemaPath, opts, self } = it;
2665
+ if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$p.schemaHasRulesButRef)(schema, self.RULES)) {
2666
+ self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
2662
2667
  }
2663
- function updateContext(it) {
2664
- const schId = it.schema[it.opts.schemaId];
2665
- if (schId)
2666
- it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
2668
+ }
2669
+ function checkNoDefault(it) {
2670
+ const { schema, opts } = it;
2671
+ if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
2672
+ (0, util_1$p.checkStrictMode)(it, "default is ignored in the schema root");
2667
2673
  }
2668
- function checkAsyncSchema(it) {
2669
- if (it.schema.$async && !it.schemaEnv.$async)
2670
- throw new Error("async schema in sync schema");
2674
+ }
2675
+ function updateContext(it) {
2676
+ const schId = it.schema[it.opts.schemaId];
2677
+ if (schId)
2678
+ it.baseId = (0, resolve_1$2.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
2679
+ }
2680
+ function checkAsyncSchema(it) {
2681
+ if (it.schema.$async && !it.schemaEnv.$async)
2682
+ throw new Error("async schema in sync schema");
2683
+ }
2684
+ function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
2685
+ const msg = schema.$comment;
2686
+ if (opts.$comment === true) {
2687
+ gen.code((0, codegen_1$r._)`${names_1$6.default.self}.logger.log(${msg})`);
2688
+ } else if (typeof opts.$comment == "function") {
2689
+ const schemaPath = (0, codegen_1$r.str)`${errSchemaPath}/$comment`;
2690
+ const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
2691
+ gen.code((0, codegen_1$r._)`${names_1$6.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
2671
2692
  }
2672
- function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
2673
- const msg = schema.$comment;
2674
- if (opts.$comment === true) {
2675
- gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
2676
- } else if (typeof opts.$comment == "function") {
2677
- const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
2678
- const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
2679
- gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
2680
- }
2693
+ }
2694
+ function returnResults(it) {
2695
+ const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
2696
+ if (schemaEnv.$async) {
2697
+ gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === 0`, () => gen.return(names_1$6.default.data), () => gen.throw((0, codegen_1$r._)`new ${ValidationError2}(${names_1$6.default.vErrors})`));
2698
+ } else {
2699
+ gen.assign((0, codegen_1$r._)`${validateName}.errors`, names_1$6.default.vErrors);
2700
+ if (opts.unevaluated)
2701
+ assignEvaluated(it);
2702
+ gen.return((0, codegen_1$r._)`${names_1$6.default.errors} === 0`);
2681
2703
  }
2682
- function returnResults(it) {
2683
- const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
2684
- if (schemaEnv.$async) {
2685
- gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError2}(${names_12.default.vErrors})`));
2686
- } else {
2687
- gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
2688
- if (opts.unevaluated)
2689
- assignEvaluated(it);
2690
- gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
2691
- }
2692
- }
2693
- function assignEvaluated({ gen, evaluated, props, items: items2 }) {
2694
- if (props instanceof codegen_12.Name)
2695
- gen.assign((0, codegen_12._)`${evaluated}.props`, props);
2696
- if (items2 instanceof codegen_12.Name)
2697
- gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
2698
- }
2699
- function schemaKeywords(it, types2, typeErrors, errsCount) {
2700
- const { gen, schema, data, allErrors, opts, self } = it;
2701
- const { RULES } = self;
2702
- if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
2703
- gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
2704
+ }
2705
+ function assignEvaluated({ gen, evaluated, props, items: items2 }) {
2706
+ if (props instanceof codegen_1$r.Name)
2707
+ gen.assign((0, codegen_1$r._)`${evaluated}.props`, props);
2708
+ if (items2 instanceof codegen_1$r.Name)
2709
+ gen.assign((0, codegen_1$r._)`${evaluated}.items`, items2);
2710
+ }
2711
+ function schemaKeywords(it, types2, typeErrors, errsCount) {
2712
+ const { gen, schema, data, allErrors, opts, self } = it;
2713
+ const { RULES } = self;
2714
+ if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$p.schemaHasRulesButRef)(schema, RULES))) {
2715
+ gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
2716
+ return;
2717
+ }
2718
+ if (!opts.jtd)
2719
+ checkStrictTypes(it, types2);
2720
+ gen.block(() => {
2721
+ for (const group of RULES.rules)
2722
+ groupKeywords(group);
2723
+ groupKeywords(RULES.post);
2724
+ });
2725
+ function groupKeywords(group) {
2726
+ if (!(0, applicability_1.shouldUseGroup)(schema, group))
2704
2727
  return;
2705
- }
2706
- if (!opts.jtd)
2707
- checkStrictTypes(it, types2);
2708
- gen.block(() => {
2709
- for (const group of RULES.rules)
2710
- groupKeywords(group);
2711
- groupKeywords(RULES.post);
2712
- });
2713
- function groupKeywords(group) {
2714
- if (!(0, applicability_12.shouldUseGroup)(schema, group))
2715
- return;
2716
- if (group.type) {
2717
- gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
2718
- iterateKeywords(it, group);
2719
- if (types2.length === 1 && types2[0] === group.type && typeErrors) {
2720
- gen.else();
2721
- (0, dataType_2.reportTypeError)(it);
2722
- }
2723
- gen.endIf();
2724
- } else {
2725
- iterateKeywords(it, group);
2728
+ if (group.type) {
2729
+ gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
2730
+ iterateKeywords(it, group);
2731
+ if (types2.length === 1 && types2[0] === group.type && typeErrors) {
2732
+ gen.else();
2733
+ (0, dataType_2.reportTypeError)(it);
2726
2734
  }
2727
- if (!allErrors)
2728
- gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
2735
+ gen.endIf();
2736
+ } else {
2737
+ iterateKeywords(it, group);
2729
2738
  }
2739
+ if (!allErrors)
2740
+ gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === ${errsCount || 0}`);
2730
2741
  }
2731
- function iterateKeywords(it, group) {
2732
- const { gen, schema, opts: { useDefaults } } = it;
2733
- if (useDefaults)
2734
- (0, defaults_1.assignDefaults)(it, group.type);
2735
- gen.block(() => {
2736
- for (const rule of group.rules) {
2737
- if ((0, applicability_12.shouldUseRule)(schema, rule)) {
2738
- keywordCode(it, rule.keyword, rule.definition, group.type);
2739
- }
2742
+ }
2743
+ function iterateKeywords(it, group) {
2744
+ const { gen, schema, opts: { useDefaults } } = it;
2745
+ if (useDefaults)
2746
+ (0, defaults_1.assignDefaults)(it, group.type);
2747
+ gen.block(() => {
2748
+ for (const rule of group.rules) {
2749
+ if ((0, applicability_1.shouldUseRule)(schema, rule)) {
2750
+ keywordCode(it, rule.keyword, rule.definition, group.type);
2740
2751
  }
2741
- });
2742
- }
2743
- function checkStrictTypes(it, types2) {
2744
- if (it.schemaEnv.meta || !it.opts.strictTypes)
2745
- return;
2746
- checkContextTypes(it, types2);
2747
- if (!it.opts.allowUnionTypes)
2748
- checkMultipleTypes(it, types2);
2749
- checkKeywordTypes(it, it.dataTypes);
2750
- }
2751
- function checkContextTypes(it, types2) {
2752
- if (!types2.length)
2753
- return;
2754
- if (!it.dataTypes.length) {
2755
- it.dataTypes = types2;
2756
- return;
2757
2752
  }
2758
- types2.forEach((t) => {
2759
- if (!includesType(it.dataTypes, t)) {
2760
- strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
2761
- }
2762
- });
2763
- narrowSchemaTypes(it, types2);
2753
+ });
2754
+ }
2755
+ function checkStrictTypes(it, types2) {
2756
+ if (it.schemaEnv.meta || !it.opts.strictTypes)
2757
+ return;
2758
+ checkContextTypes(it, types2);
2759
+ if (!it.opts.allowUnionTypes)
2760
+ checkMultipleTypes(it, types2);
2761
+ checkKeywordTypes(it, it.dataTypes);
2762
+ }
2763
+ function checkContextTypes(it, types2) {
2764
+ if (!types2.length)
2765
+ return;
2766
+ if (!it.dataTypes.length) {
2767
+ it.dataTypes = types2;
2768
+ return;
2764
2769
  }
2765
- function checkMultipleTypes(it, ts) {
2766
- if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
2767
- strictTypesError(it, "use allowUnionTypes to allow union type keyword");
2770
+ types2.forEach((t) => {
2771
+ if (!includesType(it.dataTypes, t)) {
2772
+ strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
2768
2773
  }
2774
+ });
2775
+ narrowSchemaTypes(it, types2);
2776
+ }
2777
+ function checkMultipleTypes(it, ts) {
2778
+ if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
2779
+ strictTypesError(it, "use allowUnionTypes to allow union type keyword");
2769
2780
  }
2770
- function checkKeywordTypes(it, ts) {
2771
- const rules2 = it.self.RULES.all;
2772
- for (const keyword2 in rules2) {
2773
- const rule = rules2[keyword2];
2774
- if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
2775
- const { type: type2 } = rule.definition;
2776
- if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
2777
- strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
2778
- }
2781
+ }
2782
+ function checkKeywordTypes(it, ts) {
2783
+ const rules2 = it.self.RULES.all;
2784
+ for (const keyword2 in rules2) {
2785
+ const rule = rules2[keyword2];
2786
+ if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
2787
+ const { type: type2 } = rule.definition;
2788
+ if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
2789
+ strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
2779
2790
  }
2780
2791
  }
2781
2792
  }
2782
- function hasApplicableType(schTs, kwdT) {
2783
- return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
2784
- }
2785
- function includesType(ts, t) {
2786
- return ts.includes(t) || t === "integer" && ts.includes("number");
2787
- }
2788
- function narrowSchemaTypes(it, withTypes) {
2789
- const ts = [];
2790
- for (const t of it.dataTypes) {
2791
- if (includesType(withTypes, t))
2792
- ts.push(t);
2793
- else if (withTypes.includes("integer") && t === "number")
2794
- ts.push("integer");
2795
- }
2796
- it.dataTypes = ts;
2797
- }
2798
- function strictTypesError(it, msg) {
2799
- const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
2800
- msg += ` at "${schemaPath}" (strictTypes)`;
2801
- (0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
2802
- }
2803
- class KeywordCxt {
2804
- constructor(it, def2, keyword2) {
2805
- (0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
2806
- this.gen = it.gen;
2807
- this.allErrors = it.allErrors;
2808
- this.keyword = keyword2;
2809
- this.data = it.data;
2810
- this.schema = it.schema[keyword2];
2811
- this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
2812
- this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
2813
- this.schemaType = def2.schemaType;
2814
- this.parentSchema = it.schema;
2815
- this.params = {};
2816
- this.it = it;
2817
- this.def = def2;
2818
- if (this.$data) {
2819
- this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
2820
- } else {
2821
- this.schemaCode = this.schemaValue;
2822
- if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
2823
- throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
2824
- }
2825
- }
2826
- if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
2827
- this.errsCount = it.gen.const("_errs", names_12.default.errors);
2828
- }
2829
- }
2830
- result(condition, successAction, failAction) {
2831
- this.failResult((0, codegen_12.not)(condition), successAction, failAction);
2832
- }
2833
- failResult(condition, successAction, failAction) {
2834
- this.gen.if(condition);
2835
- if (failAction)
2836
- failAction();
2837
- else
2838
- this.error();
2839
- if (successAction) {
2840
- this.gen.else();
2841
- successAction();
2842
- if (this.allErrors)
2843
- this.gen.endIf();
2844
- } else {
2845
- if (this.allErrors)
2846
- this.gen.endIf();
2847
- else
2848
- this.gen.else();
2793
+ }
2794
+ function hasApplicableType(schTs, kwdT) {
2795
+ return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
2796
+ }
2797
+ function includesType(ts, t) {
2798
+ return ts.includes(t) || t === "integer" && ts.includes("number");
2799
+ }
2800
+ function narrowSchemaTypes(it, withTypes) {
2801
+ const ts = [];
2802
+ for (const t of it.dataTypes) {
2803
+ if (includesType(withTypes, t))
2804
+ ts.push(t);
2805
+ else if (withTypes.includes("integer") && t === "number")
2806
+ ts.push("integer");
2807
+ }
2808
+ it.dataTypes = ts;
2809
+ }
2810
+ function strictTypesError(it, msg) {
2811
+ const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
2812
+ msg += ` at "${schemaPath}" (strictTypes)`;
2813
+ (0, util_1$p.checkStrictMode)(it, msg, it.opts.strictTypes);
2814
+ }
2815
+ class KeywordCxt {
2816
+ constructor(it, def2, keyword2) {
2817
+ (0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
2818
+ this.gen = it.gen;
2819
+ this.allErrors = it.allErrors;
2820
+ this.keyword = keyword2;
2821
+ this.data = it.data;
2822
+ this.schema = it.schema[keyword2];
2823
+ this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
2824
+ this.schemaValue = (0, util_1$p.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
2825
+ this.schemaType = def2.schemaType;
2826
+ this.parentSchema = it.schema;
2827
+ this.params = {};
2828
+ this.it = it;
2829
+ this.def = def2;
2830
+ if (this.$data) {
2831
+ this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
2832
+ } else {
2833
+ this.schemaCode = this.schemaValue;
2834
+ if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
2835
+ throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
2849
2836
  }
2850
2837
  }
2851
- pass(condition, failAction) {
2852
- this.failResult((0, codegen_12.not)(condition), void 0, failAction);
2838
+ if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
2839
+ this.errsCount = it.gen.const("_errs", names_1$6.default.errors);
2853
2840
  }
2854
- fail(condition) {
2855
- if (condition === void 0) {
2856
- this.error();
2857
- if (!this.allErrors)
2858
- this.gen.if(false);
2859
- return;
2860
- }
2861
- this.gen.if(condition);
2841
+ }
2842
+ result(condition, successAction, failAction) {
2843
+ this.failResult((0, codegen_1$r.not)(condition), successAction, failAction);
2844
+ }
2845
+ failResult(condition, successAction, failAction) {
2846
+ this.gen.if(condition);
2847
+ if (failAction)
2848
+ failAction();
2849
+ else
2862
2850
  this.error();
2851
+ if (successAction) {
2852
+ this.gen.else();
2853
+ successAction();
2854
+ if (this.allErrors)
2855
+ this.gen.endIf();
2856
+ } else {
2863
2857
  if (this.allErrors)
2864
2858
  this.gen.endIf();
2865
2859
  else
2866
2860
  this.gen.else();
2867
2861
  }
2868
- fail$data(condition) {
2869
- if (!this.$data)
2870
- return this.fail(condition);
2871
- const { schemaCode } = this;
2872
- this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
2873
- }
2874
- error(append, errorParams, errorPaths) {
2875
- if (errorParams) {
2876
- this.setParams(errorParams);
2877
- this._error(append, errorPaths);
2878
- this.setParams({});
2879
- return;
2880
- }
2881
- this._error(append, errorPaths);
2882
- }
2883
- _error(append, errorPaths) {
2884
- (append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
2885
- }
2886
- $dataError() {
2887
- (0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
2888
- }
2889
- reset() {
2890
- if (this.errsCount === void 0)
2891
- throw new Error('add "trackErrors" to keyword definition');
2892
- (0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
2893
- }
2894
- ok(cond) {
2862
+ }
2863
+ pass(condition, failAction) {
2864
+ this.failResult((0, codegen_1$r.not)(condition), void 0, failAction);
2865
+ }
2866
+ fail(condition) {
2867
+ if (condition === void 0) {
2868
+ this.error();
2895
2869
  if (!this.allErrors)
2896
- this.gen.if(cond);
2870
+ this.gen.if(false);
2871
+ return;
2897
2872
  }
2898
- setParams(obj, assign) {
2899
- if (assign)
2900
- Object.assign(this.params, obj);
2901
- else
2902
- this.params = obj;
2873
+ this.gen.if(condition);
2874
+ this.error();
2875
+ if (this.allErrors)
2876
+ this.gen.endIf();
2877
+ else
2878
+ this.gen.else();
2879
+ }
2880
+ fail$data(condition) {
2881
+ if (!this.$data)
2882
+ return this.fail(condition);
2883
+ const { schemaCode } = this;
2884
+ this.fail((0, codegen_1$r._)`${schemaCode} !== undefined && (${(0, codegen_1$r.or)(this.invalid$data(), condition)})`);
2885
+ }
2886
+ error(append, errorParams, errorPaths) {
2887
+ if (errorParams) {
2888
+ this.setParams(errorParams);
2889
+ this._error(append, errorPaths);
2890
+ this.setParams({});
2891
+ return;
2903
2892
  }
2904
- block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
2905
- this.gen.block(() => {
2906
- this.check$data(valid, $dataValid);
2907
- codeBlock();
2908
- });
2893
+ this._error(append, errorPaths);
2894
+ }
2895
+ _error(append, errorPaths) {
2896
+ (append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
2897
+ }
2898
+ $dataError() {
2899
+ (0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
2900
+ }
2901
+ reset() {
2902
+ if (this.errsCount === void 0)
2903
+ throw new Error('add "trackErrors" to keyword definition');
2904
+ (0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
2905
+ }
2906
+ ok(cond) {
2907
+ if (!this.allErrors)
2908
+ this.gen.if(cond);
2909
+ }
2910
+ setParams(obj, assign) {
2911
+ if (assign)
2912
+ Object.assign(this.params, obj);
2913
+ else
2914
+ this.params = obj;
2915
+ }
2916
+ block$data(valid, codeBlock, $dataValid = codegen_1$r.nil) {
2917
+ this.gen.block(() => {
2918
+ this.check$data(valid, $dataValid);
2919
+ codeBlock();
2920
+ });
2921
+ }
2922
+ check$data(valid = codegen_1$r.nil, $dataValid = codegen_1$r.nil) {
2923
+ if (!this.$data)
2924
+ return;
2925
+ const { gen, schemaCode, schemaType, def: def2 } = this;
2926
+ gen.if((0, codegen_1$r.or)((0, codegen_1$r._)`${schemaCode} === undefined`, $dataValid));
2927
+ if (valid !== codegen_1$r.nil)
2928
+ gen.assign(valid, true);
2929
+ if (schemaType.length || def2.validateSchema) {
2930
+ gen.elseIf(this.invalid$data());
2931
+ this.$dataError();
2932
+ if (valid !== codegen_1$r.nil)
2933
+ gen.assign(valid, false);
2909
2934
  }
2910
- check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
2911
- if (!this.$data)
2912
- return;
2913
- const { gen, schemaCode, schemaType, def: def2 } = this;
2914
- gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
2915
- if (valid !== codegen_12.nil)
2916
- gen.assign(valid, true);
2917
- if (schemaType.length || def2.validateSchema) {
2918
- gen.elseIf(this.invalid$data());
2919
- this.$dataError();
2920
- if (valid !== codegen_12.nil)
2921
- gen.assign(valid, false);
2935
+ gen.else();
2936
+ }
2937
+ invalid$data() {
2938
+ const { gen, schemaCode, schemaType, def: def2, it } = this;
2939
+ return (0, codegen_1$r.or)(wrong$DataType(), invalid$DataSchema());
2940
+ function wrong$DataType() {
2941
+ if (schemaType.length) {
2942
+ if (!(schemaCode instanceof codegen_1$r.Name))
2943
+ throw new Error("ajv implementation error");
2944
+ const st = Array.isArray(schemaType) ? schemaType : [schemaType];
2945
+ return (0, codegen_1$r._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
2922
2946
  }
2923
- gen.else();
2947
+ return codegen_1$r.nil;
2924
2948
  }
2925
- invalid$data() {
2926
- const { gen, schemaCode, schemaType, def: def2, it } = this;
2927
- return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
2928
- function wrong$DataType() {
2929
- if (schemaType.length) {
2930
- if (!(schemaCode instanceof codegen_12.Name))
2931
- throw new Error("ajv implementation error");
2932
- const st = Array.isArray(schemaType) ? schemaType : [schemaType];
2933
- return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
2934
- }
2935
- return codegen_12.nil;
2936
- }
2937
- function invalid$DataSchema() {
2938
- if (def2.validateSchema) {
2939
- const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
2940
- return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
2941
- }
2942
- return codegen_12.nil;
2949
+ function invalid$DataSchema() {
2950
+ if (def2.validateSchema) {
2951
+ const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
2952
+ return (0, codegen_1$r._)`!${validateSchemaRef}(${schemaCode})`;
2943
2953
  }
2954
+ return codegen_1$r.nil;
2944
2955
  }
2945
- subschema(appl, valid) {
2946
- const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
2947
- (0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
2948
- (0, subschema_1.extendSubschemaMode)(subschema2, appl);
2949
- const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
2950
- subschemaCode(nextContext, valid);
2951
- return nextContext;
2952
- }
2953
- mergeEvaluated(schemaCxt, toName) {
2954
- const { it, gen } = this;
2955
- if (!it.opts.unevaluated)
2956
- return;
2957
- if (it.props !== true && schemaCxt.props !== void 0) {
2958
- it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
2959
- }
2960
- if (it.items !== true && schemaCxt.items !== void 0) {
2961
- it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
2962
- }
2956
+ }
2957
+ subschema(appl, valid) {
2958
+ const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
2959
+ (0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
2960
+ (0, subschema_1.extendSubschemaMode)(subschema2, appl);
2961
+ const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
2962
+ subschemaCode(nextContext, valid);
2963
+ return nextContext;
2964
+ }
2965
+ mergeEvaluated(schemaCxt, toName) {
2966
+ const { it, gen } = this;
2967
+ if (!it.opts.unevaluated)
2968
+ return;
2969
+ if (it.props !== true && schemaCxt.props !== void 0) {
2970
+ it.props = util_1$p.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
2963
2971
  }
2964
- mergeValidEvaluated(schemaCxt, valid) {
2965
- const { it, gen } = this;
2966
- if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
2967
- gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
2968
- return true;
2969
- }
2972
+ if (it.items !== true && schemaCxt.items !== void 0) {
2973
+ it.items = util_1$p.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
2970
2974
  }
2971
2975
  }
2972
- validate.KeywordCxt = KeywordCxt;
2973
- function keywordCode(it, keyword2, def2, ruleType) {
2974
- const cxt = new KeywordCxt(it, def2, keyword2);
2975
- if ("code" in def2) {
2976
- def2.code(cxt, ruleType);
2977
- } else if (cxt.$data && def2.validate) {
2978
- (0, keyword_1.funcKeywordCode)(cxt, def2);
2979
- } else if ("macro" in def2) {
2980
- (0, keyword_1.macroKeywordCode)(cxt, def2);
2981
- } else if (def2.compile || def2.validate) {
2982
- (0, keyword_1.funcKeywordCode)(cxt, def2);
2983
- }
2984
- }
2985
- const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
2986
- const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
2987
- function getData($data, { dataLevel, dataNames, dataPathArr }) {
2988
- let jsonPointer;
2989
- let data;
2990
- if ($data === "")
2991
- return names_12.default.rootData;
2992
- if ($data[0] === "/") {
2993
- if (!JSON_POINTER.test($data))
2994
- throw new Error(`Invalid JSON-pointer: ${$data}`);
2995
- jsonPointer = $data;
2996
- data = names_12.default.rootData;
2997
- } else {
2998
- const matches = RELATIVE_JSON_POINTER.exec($data);
2999
- if (!matches)
3000
- throw new Error(`Invalid JSON-pointer: ${$data}`);
3001
- const up = +matches[1];
3002
- jsonPointer = matches[2];
3003
- if (jsonPointer === "#") {
3004
- if (up >= dataLevel)
3005
- throw new Error(errorMsg("property/index", up));
3006
- return dataPathArr[dataLevel - up];
3007
- }
3008
- if (up > dataLevel)
3009
- throw new Error(errorMsg("data", up));
3010
- data = dataNames[dataLevel - up];
3011
- if (!jsonPointer)
3012
- return data;
3013
- }
3014
- let expr = data;
3015
- const segments = jsonPointer.split("/");
3016
- for (const segment of segments) {
3017
- if (segment) {
3018
- data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
3019
- expr = (0, codegen_12._)`${expr} && ${data}`;
3020
- }
3021
- }
3022
- return expr;
3023
- function errorMsg(pointerType, up) {
3024
- return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
2976
+ mergeValidEvaluated(schemaCxt, valid) {
2977
+ const { it, gen } = this;
2978
+ if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
2979
+ gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$r.Name));
2980
+ return true;
3025
2981
  }
3026
2982
  }
3027
- validate.getData = getData;
3028
- return validate;
3029
2983
  }
2984
+ validate.KeywordCxt = KeywordCxt;
2985
+ function keywordCode(it, keyword2, def2, ruleType) {
2986
+ const cxt = new KeywordCxt(it, def2, keyword2);
2987
+ if ("code" in def2) {
2988
+ def2.code(cxt, ruleType);
2989
+ } else if (cxt.$data && def2.validate) {
2990
+ (0, keyword_1.funcKeywordCode)(cxt, def2);
2991
+ } else if ("macro" in def2) {
2992
+ (0, keyword_1.macroKeywordCode)(cxt, def2);
2993
+ } else if (def2.compile || def2.validate) {
2994
+ (0, keyword_1.funcKeywordCode)(cxt, def2);
2995
+ }
2996
+ }
2997
+ const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
2998
+ const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
2999
+ function getData($data, { dataLevel, dataNames, dataPathArr }) {
3000
+ let jsonPointer;
3001
+ let data;
3002
+ if ($data === "")
3003
+ return names_1$6.default.rootData;
3004
+ if ($data[0] === "/") {
3005
+ if (!JSON_POINTER.test($data))
3006
+ throw new Error(`Invalid JSON-pointer: ${$data}`);
3007
+ jsonPointer = $data;
3008
+ data = names_1$6.default.rootData;
3009
+ } else {
3010
+ const matches = RELATIVE_JSON_POINTER.exec($data);
3011
+ if (!matches)
3012
+ throw new Error(`Invalid JSON-pointer: ${$data}`);
3013
+ const up = +matches[1];
3014
+ jsonPointer = matches[2];
3015
+ if (jsonPointer === "#") {
3016
+ if (up >= dataLevel)
3017
+ throw new Error(errorMsg("property/index", up));
3018
+ return dataPathArr[dataLevel - up];
3019
+ }
3020
+ if (up > dataLevel)
3021
+ throw new Error(errorMsg("data", up));
3022
+ data = dataNames[dataLevel - up];
3023
+ if (!jsonPointer)
3024
+ return data;
3025
+ }
3026
+ let expr = data;
3027
+ const segments = jsonPointer.split("/");
3028
+ for (const segment of segments) {
3029
+ if (segment) {
3030
+ data = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)((0, util_1$p.unescapeJsonPointer)(segment))}`;
3031
+ expr = (0, codegen_1$r._)`${expr} && ${data}`;
3032
+ }
3033
+ }
3034
+ return expr;
3035
+ function errorMsg(pointerType, up) {
3036
+ return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
3037
+ }
3038
+ }
3039
+ validate.getData = getData;
3030
3040
  var validation_error = {};
3031
3041
  Object.defineProperty(validation_error, "__esModule", { value: true });
3032
3042
  class ValidationError extends Error {
@@ -3053,10 +3063,10 @@ Object.defineProperty(compile, "__esModule", { value: true });
3053
3063
  compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
3054
3064
  const codegen_1$q = codegen;
3055
3065
  const validation_error_1 = validation_error;
3056
- const names_1$5 = requireNames();
3066
+ const names_1$5 = names$1;
3057
3067
  const resolve_1 = resolve$2;
3058
3068
  const util_1$o = util;
3059
- const validate_1$1 = requireValidate();
3069
+ const validate_1$1 = validate;
3060
3070
  class SchemaEnv {
3061
3071
  constructor(env) {
3062
3072
  var _a;
@@ -4007,7 +4017,7 @@ uri$1.default = uri;
4007
4017
  (function(exports2) {
4008
4018
  Object.defineProperty(exports2, "__esModule", { value: true });
4009
4019
  exports2.CodeGen = exports2.Name = exports2.nil = exports2.stringify = exports2.str = exports2._ = exports2.KeywordCxt = void 0;
4010
- var validate_12 = requireValidate();
4020
+ var validate_12 = validate;
4011
4021
  Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
4012
4022
  return validate_12.KeywordCxt;
4013
4023
  } });
@@ -4625,9 +4635,9 @@ var ref = {};
4625
4635
  Object.defineProperty(ref, "__esModule", { value: true });
4626
4636
  ref.callRef = ref.getValidate = void 0;
4627
4637
  const ref_error_1$1 = ref_error;
4628
- const code_1$8 = requireCode();
4638
+ const code_1$8 = code;
4629
4639
  const codegen_1$p = codegen;
4630
- const names_1$4 = requireNames();
4640
+ const names_1$4 = names$1;
4631
4641
  const compile_1$2 = compile;
4632
4642
  const util_1$n = util;
4633
4643
  const def$A = {
@@ -4848,7 +4858,7 @@ const def$x = {
4848
4858
  limitLength.default = def$x;
4849
4859
  var pattern = {};
4850
4860
  Object.defineProperty(pattern, "__esModule", { value: true });
4851
- const code_1$7 = requireCode();
4861
+ const code_1$7 = code;
4852
4862
  const codegen_1$l = codegen;
4853
4863
  const error$h = {
4854
4864
  message: ({ schemaCode }) => (0, codegen_1$l.str)`must match pattern "${schemaCode}"`,
@@ -4893,7 +4903,7 @@ const def$v = {
4893
4903
  limitProperties.default = def$v;
4894
4904
  var required = {};
4895
4905
  Object.defineProperty(required, "__esModule", { value: true });
4896
- const code_1$6 = requireCode();
4906
+ const code_1$6 = code;
4897
4907
  const codegen_1$j = codegen;
4898
4908
  const util_1$l = util;
4899
4909
  const error$f = {
@@ -5207,7 +5217,7 @@ Object.defineProperty(items, "__esModule", { value: true });
5207
5217
  items.validateTuple = void 0;
5208
5218
  const codegen_1$d = codegen;
5209
5219
  const util_1$g = util;
5210
- const code_1$5 = requireCode();
5220
+ const code_1$5 = code;
5211
5221
  const def$o = {
5212
5222
  keyword: "items",
5213
5223
  type: "array",
@@ -5267,7 +5277,7 @@ var items2020 = {};
5267
5277
  Object.defineProperty(items2020, "__esModule", { value: true });
5268
5278
  const codegen_1$c = codegen;
5269
5279
  const util_1$f = util;
5270
- const code_1$4 = requireCode();
5280
+ const code_1$4 = code;
5271
5281
  const additionalItems_1$1 = additionalItems;
5272
5282
  const error$9 = {
5273
5283
  message: ({ params: { len } }) => (0, codegen_1$c.str)`must NOT have more than ${len} items`,
@@ -5386,7 +5396,7 @@ var dependencies = {};
5386
5396
  exports2.validateSchemaDeps = exports2.validatePropertyDeps = exports2.error = void 0;
5387
5397
  const codegen_12 = codegen;
5388
5398
  const util_12 = util;
5389
- const code_12 = requireCode();
5399
+ const code_12 = code;
5390
5400
  exports2.error = {
5391
5401
  message: ({ params: { property, depsCount, deps } }) => {
5392
5402
  const property_ies = depsCount === 1 ? "property" : "properties";
@@ -5509,9 +5519,9 @@ const def$k = {
5509
5519
  propertyNames.default = def$k;
5510
5520
  var additionalProperties = {};
5511
5521
  Object.defineProperty(additionalProperties, "__esModule", { value: true });
5512
- const code_1$3 = requireCode();
5522
+ const code_1$3 = code;
5513
5523
  const codegen_1$9 = codegen;
5514
- const names_1$3 = requireNames();
5524
+ const names_1$3 = names$1;
5515
5525
  const util_1$c = util;
5516
5526
  const error$6 = {
5517
5527
  message: "must NOT have additional properties",
@@ -5609,8 +5619,8 @@ const def$j = {
5609
5619
  additionalProperties.default = def$j;
5610
5620
  var properties$8 = {};
5611
5621
  Object.defineProperty(properties$8, "__esModule", { value: true });
5612
- const validate_1 = requireValidate();
5613
- const code_1$2 = requireCode();
5622
+ const validate_1 = validate;
5623
+ const code_1$2 = code;
5614
5624
  const util_1$b = util;
5615
5625
  const additionalProperties_1$1 = additionalProperties;
5616
5626
  const def$i = {
@@ -5661,7 +5671,7 @@ const def$i = {
5661
5671
  properties$8.default = def$i;
5662
5672
  var patternProperties = {};
5663
5673
  Object.defineProperty(patternProperties, "__esModule", { value: true });
5664
- const code_1$1 = requireCode();
5674
+ const code_1$1 = code;
5665
5675
  const codegen_1$8 = codegen;
5666
5676
  const util_1$a = util;
5667
5677
  const util_2 = util;
@@ -5754,7 +5764,7 @@ const def$g = {
5754
5764
  not.default = def$g;
5755
5765
  var anyOf = {};
5756
5766
  Object.defineProperty(anyOf, "__esModule", { value: true });
5757
- const code_1 = requireCode();
5767
+ const code_1 = code;
5758
5768
  const def$f = {
5759
5769
  keyword: "anyOf",
5760
5770
  schemaType: "array",
@@ -5957,7 +5967,7 @@ var dynamicAnchor$1 = {};
5957
5967
  Object.defineProperty(dynamicAnchor$1, "__esModule", { value: true });
5958
5968
  dynamicAnchor$1.dynamicAnchor = void 0;
5959
5969
  const codegen_1$5 = codegen;
5960
- const names_1$2 = requireNames();
5970
+ const names_1$2 = names$1;
5961
5971
  const compile_1$1 = compile;
5962
5972
  const ref_1$1 = ref;
5963
5973
  const def$a = {
@@ -5986,7 +5996,7 @@ var dynamicRef$1 = {};
5986
5996
  Object.defineProperty(dynamicRef$1, "__esModule", { value: true });
5987
5997
  dynamicRef$1.dynamicRef = void 0;
5988
5998
  const codegen_1$4 = codegen;
5989
- const names_1$1 = requireNames();
5999
+ const names_1$1 = names$1;
5990
6000
  const ref_1 = ref;
5991
6001
  const def$9 = {
5992
6002
  keyword: "$dynamicRef",
@@ -6100,7 +6110,7 @@ var unevaluatedProperties = {};
6100
6110
  Object.defineProperty(unevaluatedProperties, "__esModule", { value: true });
6101
6111
  const codegen_1$3 = codegen;
6102
6112
  const util_1$2 = util;
6103
- const names_1 = requireNames();
6113
+ const names_1 = names$1;
6104
6114
  const error$3 = {
6105
6115
  message: "must NOT have unevaluated properties",
6106
6116
  params: ({ params }) => (0, codegen_1$3._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
@@ -7016,7 +7026,7 @@ jsonSchema202012.default = addMetaSchema2020;
7016
7026
  module2.exports.Ajv2020 = Ajv20202;
7017
7027
  Object.defineProperty(exports2, "__esModule", { value: true });
7018
7028
  exports2.default = Ajv20202;
7019
- var validate_12 = requireValidate();
7029
+ var validate_12 = validate;
7020
7030
  Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
7021
7031
  return validate_12.KeywordCxt;
7022
7032
  } });