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