@jetio/validator 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  **The Fastest JSON Schema Validator in JavaScript**
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/@jetio/validator.svg)](https://www.npmjs.com/package/@jetio/validator) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://img.shields.io/github/workflow/status/greatvenerable/jet-validator/CI)](https://github.com/jetio/validator/actions) [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@jetio/validator)](https://bundlephobia.com/package/@jetio/validator)
5
+ [![npm version](https://img.shields.io/npm/v/@jetio/validator.svg)](https://www.npmjs.com/package/@jetio/validator) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@jetio/validator)](https://bundlephobia.com/package/@jetio/validator)
6
6
 
7
7
  ---
8
8
 
9
9
  ## 🚀 Why jet-validator?
10
10
 
11
- **5-44x faster compilation** | **<100KB** | **Zero dependencies** | **JSON Schema Draft 06-2020-12**
11
+ **5-44x faster compilation** | **26KB gzipped** | **Zero dependencies** | **JSON Schema Draft 06-2020-12**
12
12
 
13
13
  jet-validator compiles JSON Schemas into highly optimized validation functions in **sub-millisecond time**. Unlike traditional validators that interpret schemas at runtime, jet-validator generates specialized code tailored to your exact schema structure.
14
14
 
@@ -18,12 +18,14 @@ Just one import for all supported drafts, check full documentation for how to sp
18
18
 
19
19
  ### Key Features
20
20
 
21
- - ⚡ **Lightning Fast** - 10-27x faster compilation than AJV (sub-millisecond compilation)
21
+ - ⚡ **Lightning Fast** - 5-44x faster compilation than AJV (sub-millisecond compilation)
22
22
  - ✅ **Highly Compliant** - 99.5%+ compliance on JSON Schema Test Suite across all supported drafts
23
- - 📦 **Smaller Bundle** - <100KB with built-in format validators (no external packages needed)
23
+ - 📦 **Smaller Bundle** - <26KB with built-in format validators and custom error messages(no external packages needed)
24
+ - 📝 **Built-in Formats** - email, uri, date-time, uuid, and more included (no extra packages!)
25
+ - ⚠️ **Custom Error Messages** - Flexible error customization with `errorMessage` keyword
24
26
  - 🎯 **Zero Dependencies** - Pure TypeScript implementation
25
27
  - 💪 **TypeScript-First** - Full type safety out of the box
26
- - 🔧 **Enhanced Features** - `elseIf` conditionals, advanced `$data` references, custom keywords
28
+ - 🔧 **Enhanced Features** - `elseIf` conditionals, advanced `$data` references, custom keywords, custom formats
27
29
  - 🔄 **Partial AJV Compatibility** - Similar API, minimal code changes needed
28
30
  - 📊 **Multiple Error Modes** - Fail-fast or collect all errors
29
31
  - 🌐 **Async Schema Loading** - Load schemas from HTTP, databases, or file systems
@@ -31,7 +33,7 @@ Just one import for all supported drafts, check full documentation for how to sp
31
33
 
32
34
  ## 🛠️ Schema Builder
33
35
 
34
- Want a fluent, type-safe API for building schemas? Check out [@jetio/schema-builder](https://github.com/jetio/schema-builder):
36
+ Want a fluent, type-safe API for building schemas? Check out [@jetio/schema-builder](https://www.npmjs.com/package/@jetio/schema-builder):
35
37
  ```typescript
36
38
  import { SchemaBuilder, JetValidator } from "@jetio/schema-builder";
37
39
 
@@ -133,7 +135,7 @@ console.log(validate.errors);
133
135
  // }]
134
136
  ```
135
137
 
136
- **→ [See Getting Started Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#-installation)**
138
+ **→ [See Getting Started Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#-installation)**
137
139
 
138
140
  ---
139
141
 
@@ -143,7 +145,7 @@ jet-validator supports **JSON Schema Draft 06 through 2020-12** with exceptional
143
145
 
144
146
  ### Compliance Results
145
147
 
146
- All results are from the official [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). Optional tests were skipped. You can view the test code in the [test folder](https://github.com/jetio/validator/tree/main/tests) of our repository.
148
+ All results are from the official [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). Optional tests were skipped. You can view the test code in the [test folder](https://github.com/official-jetio/validator/tree/main/tests) of our repository.
147
149
 
148
150
  #### Draft 2020-12
149
151
 
@@ -329,7 +331,7 @@ THERE IS NO INFINITE RECURSION IN jet-validator.
329
331
 
330
332
  While AJV encounters stack overflow errors (`RangeError: Maximum call stack size exceeded`) on schemas with complex relative URI references, jet-validator handles these schemas without issue. Our three-phase resolution process (Collection → Assignment → Resolution) eliminates circular reference problems at compile time.
331
333
 
332
- **→ [Learn more about our Resolution Process](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-resolution-process)**
334
+ **→ [Learn more about our Resolution Process](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-resolution-process)**
333
335
 
334
336
  ---
335
337
 
@@ -380,7 +382,7 @@ For transparency, here are the keywords jet-validator intentionally does not sup
380
382
  - Deep allOf chains: 68% faster
381
383
  - Complex conditionals: 36% faster
382
384
 
383
- [📊 Full Benchmark Report](https://github.com/jetio/validator/blob/main/benchmark/results/COMPARISON.md) | [📈 Detailed Results](https://github.com/jetio/validator/tree/main/benchmark/results/)
385
+ [📊 Full Benchmark Report](https://github.com/official-jetio/validator/blob/main/benchmark/results/COMPARISON.md) | [📈 Detailed Results](https://github.com/official-jetio/validator/tree/main/benchmark/results/)
384
386
 
385
387
  _Tested against AJV v8.17.1 using official benchmarks with 65 schemas, 1000 warmups, 10000 iterations, 5 runs per test_
386
388
 
@@ -430,7 +432,7 @@ console.log(result); // false
430
432
  console.log(validate.errors); // Detailed error information
431
433
  ```
432
434
 
433
- **→ [See Basic Validation Examples](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#-basic-validation-examples)**
435
+ **→ [See Basic Validation Examples](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#-basic-validation-examples)**
434
436
 
435
437
  ---
436
438
 
@@ -450,7 +452,7 @@ jetValidator.addSchema(schema, "user-schema");
450
452
  const validate = jetValidator.getSchema("user-schema");
451
453
  ```
452
454
 
453
- **→ [See Schema Management & Compilation](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-management--compilation)**
455
+ **→ [See Schema Management & Compilation](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-management--compilation)**
454
456
 
455
457
  ---
456
458
 
@@ -482,7 +484,7 @@ const jetValidator = new JetValidator({
482
484
  });
483
485
  ```
484
486
 
485
- **→ [See All Configuration Options](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#️-configuration-options)**
487
+ **→ [See All Configuration Options](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#️-configuration-options)**
486
488
 
487
489
  ---
488
490
 
@@ -534,7 +536,7 @@ console.log(validate.errors); // Custom error messages included
534
536
  }
535
537
  ```
536
538
 
537
- **→ [See Error Handling Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#error-handling)**
539
+ **→ [See Error Handling Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#error-handling)**
538
540
 
539
541
  ---
540
542
 
@@ -584,7 +586,7 @@ const schema = {
584
586
  };
585
587
  ```
586
588
 
587
- **→ [See Complete Error Handling Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#error-handling)**
589
+ **→ [See Complete Error Handling Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#error-handling)**
588
590
 
589
591
  ---
590
592
 
@@ -622,7 +624,7 @@ const jetValidator = new JetValidator({
622
624
  const validate = await jetValidator.compileAsync(schema);
623
625
  ```
624
626
 
625
- **→ [See Schema References & Composition](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-references--composition)**
627
+ **→ [See Schema References & Composition](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-references--composition)**
626
628
 
627
629
  ---
628
630
 
@@ -644,7 +646,7 @@ const validate = jetValidator.compile(schema);
644
646
  const isValid = jetValidator.validateSchema(schema);
645
647
  ```
646
648
 
647
- **→ [See Meta-Schema System](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#meta-schema-system)**
649
+ **→ [See Meta-Schema System](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#meta-schema-system)**
648
650
 
649
651
  ---
650
652
 
@@ -685,7 +687,7 @@ jetValidator.addFormat("unique-email", {
685
687
  });
686
688
  ```
687
689
 
688
- **→ [See Format Validation Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#format-validation)**
690
+ **→ [See Format Validation Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#format-validation)**
689
691
 
690
692
  ---
691
693
 
@@ -718,7 +720,7 @@ const jetValidator = new JetValidator({ $data: true });
718
720
  const validate = jetValidator.compile(schema);
719
721
  ```
720
722
 
721
- **→ [See $data References Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#data)**
723
+ **→ [See $data References Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#data)**
722
724
 
723
725
  ---
724
726
 
@@ -756,7 +758,7 @@ Enhanced conditional validation without deep nesting:
756
758
  }
757
759
  ```
758
760
 
759
- **→ [See elseIf Keyword Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#elseif-keyword)**
761
+ **→ [See elseIf Keyword Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#elseif-keyword)**
760
762
 
761
763
  ---
762
764
 
@@ -787,7 +789,7 @@ console.log(validate(4)); // true
787
789
  console.log(validate(5)); // false
788
790
  ```
789
791
 
790
- **→ [See Custom Keywords Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#custom-keywords)**
792
+ **→ [See Custom Keywords Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#custom-keywords)**
791
793
 
792
794
  ---
793
795
 
@@ -886,7 +888,7 @@ len_of("café"); // 4
886
888
 
887
889
  **Use case:** Validating `minLength`/`maxLength` for strings with emoji or special Unicode characters.
888
890
 
889
- **→ [See Full Utilities API Reference](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#utilities-api)**
891
+ **→ [See Full Utilities API Reference](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#utilities-api)**
890
892
 
891
893
  ---
892
894
 
@@ -919,7 +921,7 @@ const validate = jetValidator.compile(schema);
919
921
  - Custom keywords use different API (more powerful)
920
922
  - Meta-schema setup is easier
921
923
 
922
- **→ [See Migration Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#migration-from-ajv)**
924
+ **→ [See Migration Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#migration-from-ajv)**
923
925
 
924
926
  ---
925
927
 
@@ -954,7 +956,7 @@ jet-validator eliminates infinite recursion through a unique resolution approach
954
956
 
955
957
  This architecture enables both lightning-fast compilation and bulletproof circular reference handling.
956
958
 
957
- **→ [Learn more about the resolution process](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-resolution-process)**
959
+ **→ [Learn more about the resolution process](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-resolution-process)**
958
960
 
959
961
  ---
960
962
 
@@ -1088,31 +1090,31 @@ const validateUser = createValidatorForUser("user");
1088
1090
 
1089
1091
  **Getting Started:**
1090
1092
 
1091
- - [Installation & Setup](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#-installation)
1092
- - [Quick Start Guide](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#-quick-start)
1093
- - [Choosing Schema Language](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#-choosing-schema-language)
1093
+ - [Installation & Setup](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#-installation)
1094
+ - [Quick Start Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#-quick-start)
1095
+ - [Choosing Schema Language](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#-choosing-schema-language)
1094
1096
 
1095
1097
  **Core Concepts:**
1096
1098
 
1097
- - [Configuration Options](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#️-configuration-options)
1098
- - [Schema Compilation](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#compiling-schemas)
1099
- - [Validation Methods](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#validation)
1100
- - [Schema Management](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-management)
1101
- - [Error Handling](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#error-handling)
1099
+ - [Configuration Options](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#️-configuration-options)
1100
+ - [Schema Compilation](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#compiling-schemas)
1101
+ - [Validation Methods](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#validation)
1102
+ - [Schema Management](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-management)
1103
+ - [Error Handling](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#error-handling)
1102
1104
 
1103
1105
  **Advanced Features:**
1104
1106
 
1105
- - [Schema References & Composition](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#schema-references--composition)
1106
- - [Meta-Schema System](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#meta-schema-system)
1107
- - [$data References](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#data)
1108
- - [elseIf Conditionals](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#elseif-keyword)
1109
- - [Format Validation](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#format-validation)
1110
- - [Custom Keywords](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#custom-keywords)
1111
- - [Utilities API](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md#utilities-api)
1107
+ - [Schema References & Composition](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#schema-references--composition)
1108
+ - [Meta-Schema System](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#meta-schema-system)
1109
+ - [$data References](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#data)
1110
+ - [elseIf Conditionals](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#elseif-keyword)
1111
+ - [Format Validation](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#format-validation)
1112
+ - [Custom Keywords](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#custom-keywords)
1113
+ - [Utilities API](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#utilities-api)
1112
1114
 
1113
1115
  **Complete Documentation:**
1114
1116
 
1115
- - [📖 Full Documentation (20k+ lines)](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md) - Everything in one searchable file
1117
+ - [📖 Full Documentation (20k+ lines)](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md) - Everything in one searchable file
1116
1118
 
1117
1119
  ---
1118
1120
 
@@ -1127,8 +1129,8 @@ We welcome contributions! jet-validator is a community project and we appreciate
1127
1129
 
1128
1130
  ### Ways to Contribute
1129
1131
 
1130
- - 🐛 **Report bugs** - Found an issue? [Open a bug report](https://github.com/jetio/validator/issues/new?labels=bug)
1131
- - 💡 **Suggest features** - Have an idea? [Open a feature request](https://github.com/jetio/validator/issues/new?labels=enhancement)
1132
+ - 🐛 **Report bugs** - Found an issue? [Open a bug report](https://github.com/official-jetio/validator/issues/new?labels=bug)
1133
+ - 💡 **Suggest features** - Have an idea? [Open a feature request](https://github.com/official-jetio/validator/issues/new?labels=enhancement)
1132
1134
  - 📖 **Improve docs** - Fix typos, add examples, clarify explanations
1133
1135
  - 🧪 **Add test cases** - Contribute to JSON Schema compliance
1134
1136
  - ⚡ **Performance improvements** - Make it even faster
@@ -1138,7 +1140,7 @@ We welcome contributions! jet-validator is a community project and we appreciate
1138
1140
 
1139
1141
  ```bash
1140
1142
  # Clone the repo
1141
- git clone https://github.com/jetio/validator
1143
+ git clone https://github.com/official-jetio/validator
1142
1144
  cd jet-validator
1143
1145
 
1144
1146
  # Install dependencies
@@ -1211,8 +1213,8 @@ If you're working on the resolver, please be extra careful - it's complex but ba
1211
1213
 
1212
1214
  ### Questions?
1213
1215
 
1214
- - 💬 **Discussions:** [GitHub Discussions](https://github.com/jetio/validator/discussions)
1215
- - 🐛 **Issues:** [Issue Tracker](https://github.com/jetio/validator/issues)
1216
+ - 💬 **Discussions:** [GitHub Discussions](https://github.com/official-jetio/validator/discussions)
1217
+ - 🐛 **Issues:** [Issue Tracker](https://github.com/official-jetio/validator/issues)
1216
1218
 
1217
1219
  ---
1218
1220
 
@@ -1227,7 +1229,7 @@ We track bugs and feature requests using GitHub Issues.
1227
1229
  ### Before Filing an Issue
1228
1230
 
1229
1231
  1. **Search existing issues** - Your issue might already be reported
1230
- 2. **Check the documentation** - The answer might be in the [20k+ line docs](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md)
1232
+ 2. **Check the documentation** - The answer might be in the [20k+ line docs](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md)
1231
1233
  3. **Try the latest version** - `npm install @jetio/validator@latest`
1232
1234
 
1233
1235
  ### Types of Issues
@@ -1235,20 +1237,20 @@ We track bugs and feature requests using GitHub Issues.
1235
1237
  - 🐛 **Bug Report:** Something isn't working correctly
1236
1238
 
1237
1239
  - Include: Schema, data, expected vs actual behavior, error messages
1238
- - [File a bug report →](https://github.com/jetio/validator/issues/new?labels=bug)
1240
+ - [File a bug report →](https://github.com/official-jetio/validator/issues/new?labels=bug)
1239
1241
 
1240
1242
  - 💡 **Feature Request:** Suggest a new feature or improvement
1241
1243
 
1242
1244
  - Include: Use case, examples, why it's needed
1243
- - [Request a feature →](https://github.com/jetio/validator/issues/new?labels=enhancement)
1245
+ - [Request a feature →](https://github.com/official-jetio/validator/issues/new?labels=enhancement)
1244
1246
 
1245
1247
  - ❓ **Question:** Need help or clarification
1246
1248
 
1247
- - Use [GitHub Discussions](https://github.com/jetio/validator/discussions) for questions
1249
+ - Use [GitHub Discussions](https://github.com/official-jetio/validator/discussions) for questions
1248
1250
  - Issues are for bugs and features only
1249
1251
 
1250
1252
  - 📖 **Documentation:** Docs are unclear or missing information
1251
- - [Improve docs →](https://github.com/jetio/validator/issues/new?labels=documentation)
1253
+ - [Improve docs →](https://github.com/official-jetio/validator/issues/new?labels=documentation)
1252
1254
 
1253
1255
  ### Good Bug Report Template
1254
1256
 
@@ -1285,9 +1287,9 @@ We track bugs and feature requests using GitHub Issues.
1285
1287
 
1286
1288
  **🔗 Quick Links:**
1287
1289
 
1288
- - [Report a Bug](https://github.com/jetio/validator/issues/new?labels=bug)
1289
- - [Request a Feature](https://github.com/jetio/validator/issues/new?labels=enhancement)
1290
- - [Ask a Question](https://github.com/jetio/validator/discussions)
1290
+ - [Report a Bug](https://github.com/official-jetio/validator/issues/new?labels=bug)
1291
+ - [Request a Feature](https://github.com/official-jetio/validator/issues/new?labels=enhancement)
1292
+ - [Ask a Question](https://github.com/official-jetio/validator/discussions)
1291
1293
 
1292
1294
  ---
1293
1295
 
@@ -1351,11 +1353,11 @@ MIT © [Great Venerable](https://github.com/greatvenerable)
1351
1353
  ## 🔗 Links
1352
1354
 
1353
1355
  - **[npm Package](https://www.npmjs.com/package/@jetio/validator)**
1354
- - **[GitHub Repository](https://github.com/greatvenerable/jet-validator)**
1355
- - **[Complete Documentation (20k+ lines)](https://github.com/jetio/validator/blob/main/DOCUMENTATION.md)**
1356
- - **[Benchmark Results](https://github.com/jetio/validator/blob/main/benchmark/results/COMPARISON.md)**
1357
- - **[Issue Tracker](https://github.com/jetio/validator/issues)**
1358
- - **[GitHub Discussions](https://github.com/jetio/validator/discussions)**
1356
+ - **[GitHub Repository](https://github.com/@jetio/validator)**
1357
+ - **[Complete Documentation (20k+ lines)](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md)**
1358
+ - **[Benchmark Results](https://github.com/official-jetio/validator/blob/main/benchmark/results/COMPARISON.md)**
1359
+ - **[Issue Tracker](https://github.com/official-jetio/validator/issues)**
1360
+ - **[GitHub Discussions](https://github.com/official-jetio/validator/discussions)**
1359
1361
 
1360
1362
  ---
1361
1363
 
@@ -1187,11 +1187,15 @@ class Compiler {
1187
1187
  else {
1188
1188
  comparisonTarget = schema.multipleOf;
1189
1189
  }
1190
- src.push(`const multipleOf = ${comparisonTarget};
1191
- const quotient = ${varName} / multipleOf;
1192
- const rounded = Math.round(quotient);
1193
- const tolerance = Math.abs(quotient) * Number.EPSILON;
1194
- if (${extra.before}multipleOf === 0 || !isFinite(quotient) || Math.abs(quotient - rounded) > tolerance) {${this.buildErrorReturn(pathContext, {
1190
+ const multipleOfVar = "multipleOf" + counter++;
1191
+ const quotientVar = "quotient" + counter++;
1192
+ const roundedVar = "rounded" + counter++;
1193
+ const toleranceVar = "tolerance" + counter++;
1194
+ src.push(`const ${multipleOfVar} = ${comparisonTarget};
1195
+ const ${quotientVar} = ${varName} / ${multipleOfVar};
1196
+ const ${roundedVar} = Math.round(${quotientVar});
1197
+ const ${toleranceVar} = Math.abs(${quotientVar}) * Number.EPSILON;
1198
+ if (${extra.before}${multipleOfVar} === 0 || !isFinite(${quotientVar}) || Math.abs(${quotientVar} - ${roundedVar}) > ${toleranceVar}) {${this.buildErrorReturn(pathContext, {
1195
1199
  keyword: "multipleOf",
1196
1200
  value: varName,
1197
1201
  message: `"Value must be a multiple of " + ${comparisonTarget}`,
@@ -1294,7 +1298,8 @@ class Compiler {
1294
1298
  else {
1295
1299
  src.push(`const formatValidator = formatValidators[${formatKeyVar}].validate ?? formatValidators[${formatKeyVar}];`);
1296
1300
  }
1297
- src.push(`if (${extra.before}formatValidator && typeof ${varName} === 'string') {`, ` const isValid = typeof formatValidator === 'function' ? ${this.options.async ? "async" : ""}formatValidator(${varName}) : formatValidator.test(${varName});`, ` if (!isValid) {${this.buildErrorReturn(pathContext, {
1301
+ const isValid = "isValid" + counter++;
1302
+ src.push(`if (${extra.before}formatValidator && typeof ${varName} === 'string') {`, ` const ${isValid} = typeof formatValidator === 'function' ? ${this.options.async ? "async" : ""}formatValidator(${varName}) : formatValidator.test(${varName});`, ` if (!${isValid}) {${this.buildErrorReturn(pathContext, {
1298
1303
  keyword: "format",
1299
1304
  value: varName,
1300
1305
  message: `"Failed to validate value against format "+${formatKeyVar}`,
@@ -1403,14 +1408,16 @@ class Compiler {
1403
1408
  const resolvedPath = resolveDataPointerAtCompileTime(pointer, pathContext.$data, this.refCall);
1404
1409
  const requiredArrayExpr = generateArrayDataRef(src, resolvedPath, extra);
1405
1410
  src.push(`if (${extra.before}${requiredArrayExpr}) {`);
1406
- src.push(`for (let i = 0; i < ${requiredArrayExpr}.length; i++) {`);
1407
- src.push(`const prop = ${requiredArrayExpr}[i];`);
1408
- addEvaluatedProperty(src, "prop", trackingState);
1409
- src.push(`if (${extra.before}${varName}[prop] === undefined) {${this.buildErrorReturn(pathContext, {
1411
+ const i = "i" + counter++;
1412
+ src.push(`for (let ${i} = 0; ${i} < ${requiredArrayExpr}.length; ${i}++) {`);
1413
+ const prop = "prop" + counter++;
1414
+ src.push(`const ${prop} = ${requiredArrayExpr}[${i}];`);
1415
+ addEvaluatedProperty(src, prop, trackingState);
1416
+ src.push(`if (${extra.before}${varName}[${prop}] === undefined) {${this.buildErrorReturn(pathContext, {
1410
1417
  keyword: "required",
1411
1418
  value: varName,
1412
- message: `"Missing required field: " + prop + " in data."`,
1413
- expected: "prop",
1419
+ message: `"Missing required field: " + ${prop} + " in data."`,
1420
+ expected: `${prop}`,
1414
1421
  schemaPath: `${pathContext.schema}`,
1415
1422
  })}${extra.after}}`);
1416
1423
  src.push(`}`);
@@ -1431,13 +1438,14 @@ class Compiler {
1431
1438
  if (extra.before != "")
1432
1439
  src.push(`if(${extra.before} true){`);
1433
1440
  src.push(`for (let ${iVar} = 0; ${iVar} < ${arrVar}.length; ${iVar}++) {`);
1434
- src.push(`const prop = ${arrVar}[${iVar}];`);
1435
- addEvaluatedProperty(src, "prop", trackingState);
1436
- src.push(`if (${extra.before}${varName}[prop] === undefined) {${this.buildErrorReturn(pathContext, {
1441
+ const prop = "prop" + counter++;
1442
+ src.push(`const ${prop} = ${arrVar}[${iVar}];`);
1443
+ addEvaluatedProperty(src, prop, trackingState);
1444
+ src.push(`if (${extra.before}${varName}[${prop}] === undefined) {${this.buildErrorReturn(pathContext, {
1437
1445
  keyword: "required",
1438
1446
  value: varName,
1439
- message: `"Missing required field: " + prop + " in data."`,
1440
- expected: "prop",
1447
+ message: `"Missing required field: " + ${prop} + " in data."`,
1448
+ expected: `${prop}`,
1441
1449
  schemaPath: `${pathContext.schema}`,
1442
1450
  })}${extra.after}}`);
1443
1451
  src.push(`}`);
@@ -1493,21 +1501,22 @@ class Compiler {
1493
1501
  handlePatternProperties(src, schema, varName, pathContext, trackingState, extra) {
1494
1502
  if (extra.before != "")
1495
1503
  src.push(`if(${extra.before} true){`);
1496
- src.push(`for (const key in ${varName}) {`);
1504
+ const key = "key" + counter++;
1505
+ src.push(`for (const ${key} in ${varName}) {`);
1497
1506
  Object.getOwnPropertyNames(schema.patternProperties).forEach((pattern) => {
1498
1507
  let pname = this.regexCache.get(pattern);
1499
1508
  if (!pname) {
1500
1509
  pname = "patternProp" + counter++;
1501
1510
  this.regexCache.set(pattern, pname);
1502
1511
  }
1503
- src.push(`if (${pname}.test(key)) {`);
1504
- addEvaluatedProperty(src, "key", trackingState);
1512
+ src.push(`if (${pname}.test(${key})) {`);
1513
+ addEvaluatedProperty(src, key, trackingState);
1505
1514
  const parent = trackingState.parentHasUnevaluatedProperties ||
1506
1515
  trackingState.hasOwnUnevaluatedProperties;
1507
1516
  const patternValidation = this.compileSchema(schema.patternProperties[pattern], {
1508
1517
  schema: `${pathContext.schema}/patternProperties/${JSON.stringify(pattern)}`,
1509
- data: `${pathContext.data}/\${key}`,
1510
- $data: `${pathContext.$data}/\${key}`,
1518
+ data: `${pathContext.data}/\${${key}}`,
1519
+ $data: `${pathContext.$data}/\${${key}}`,
1511
1520
  alt: pathContext.alt,
1512
1521
  alt2: pathContext.alt2,
1513
1522
  }, {
@@ -1516,7 +1525,7 @@ class Compiler {
1516
1525
  parentUnevaluatedPropVar: parent
1517
1526
  ? trackingState.unevaluatedPropVar
1518
1527
  : undefined,
1519
- }, `${varName}[key]`, extra);
1528
+ }, `${varName}[${key}]`, extra);
1520
1529
  src.push(patternValidation, "}");
1521
1530
  });
1522
1531
  src.push("}");
@@ -1528,12 +1537,13 @@ class Compiler {
1528
1537
  const explicitProps = Array.from(allowedProperties);
1529
1538
  if (extra.before != "")
1530
1539
  src.push(`if(${extra.before} true){`);
1531
- src.push(`for (const key in ${varName}) {`);
1532
- addEvaluatedProperty(src, "key", trackingState);
1540
+ const key = "key" + counter++;
1541
+ src.push(`for (const ${key} in ${varName}) {`);
1542
+ addEvaluatedProperty(src, key, trackingState);
1533
1543
  let checks = [];
1534
1544
  if (explicitProps.length > 0) {
1535
1545
  const allowedCheck = explicitProps
1536
- .map((key) => `key === ${JSON.stringify(key)}`)
1546
+ .map((keyItem) => `${key} === ${JSON.stringify(keyItem)}`)
1537
1547
  .join(" || ");
1538
1548
  checks.push(allowedCheck);
1539
1549
  }
@@ -1545,7 +1555,7 @@ class Compiler {
1545
1555
  pname = "patternProp" + counter++;
1546
1556
  this.regexCache.set(pattern, pname);
1547
1557
  }
1548
- return `${pname}.test(key)`;
1558
+ return `${pname}.test(${key})`;
1549
1559
  })
1550
1560
  .join(" || ");
1551
1561
  checks.push(patternCheck);
@@ -1556,17 +1566,18 @@ class Compiler {
1556
1566
  }
1557
1567
  const additionalPropValidation = this.compileSchema(schema.additionalProperties, {
1558
1568
  schema: `${pathContext.schema}/additionalProperties`,
1559
- data: `${pathContext.data}/\${key}`,
1560
- $data: `${pathContext.$data}/\${key}`,
1569
+ data: `${pathContext.data}/\${${key}}`,
1570
+ $data: `${pathContext.$data}/\${${key}}`,
1561
1571
  alt: pathContext.alt,
1562
1572
  alt2: pathContext.alt2,
1563
- }, {}, `${varName}[key]`, extra);
1573
+ }, {}, `${varName}[${key}]`, extra);
1564
1574
  src.push(additionalPropValidation, "}");
1565
1575
  if (extra.before != "")
1566
1576
  src.push(`}`);
1567
1577
  }
1568
1578
  handlePropertyConstraints(src, schema, varName, pathContext, extra) {
1569
- src.push(`const objKeys = Object.keys(${varName});`);
1579
+ const objKeys = "objKeys" + counter++;
1580
+ src.push(`const ${objKeys} = Object.keys(${varName});`);
1570
1581
  if (schema.minProperties !== undefined) {
1571
1582
  const isDataRef = this.options.$data && isDataReference(schema.minProperties);
1572
1583
  let comparisonTarget;
@@ -1578,9 +1589,9 @@ class Compiler {
1578
1589
  else {
1579
1590
  comparisonTarget = schema.minProperties;
1580
1591
  }
1581
- src.push(`if (${extra.before}objKeys.length < ${comparisonTarget}) {${this.buildErrorReturn(pathContext, {
1592
+ src.push(`if (${extra.before}${objKeys}.length < ${comparisonTarget}) {${this.buildErrorReturn(pathContext, {
1582
1593
  keyword: "minProperties",
1583
- value: "objKeys.length",
1594
+ value: `${objKeys}.length`,
1584
1595
  message: `"Object must have at least " + ${comparisonTarget} + " properties."`,
1585
1596
  expected: comparisonTarget,
1586
1597
  })}${extra.after}}`);
@@ -1599,9 +1610,9 @@ class Compiler {
1599
1610
  else {
1600
1611
  comparisonTarget = schema.maxProperties;
1601
1612
  }
1602
- src.push(`if (${extra.before}objKeys.length > ${comparisonTarget}) {${this.buildErrorReturn(pathContext, {
1613
+ src.push(`if (${extra.before}${objKeys}.length > ${comparisonTarget}) {${this.buildErrorReturn(pathContext, {
1603
1614
  keyword: "maxProperties",
1604
- value: "objKeys.length",
1615
+ value: `${objKeys}.length`,
1605
1616
  message: `"Object must have at most " + ${comparisonTarget} + " properties."`,
1606
1617
  expected: comparisonTarget,
1607
1618
  })}${extra.after}}`);
@@ -1613,14 +1624,15 @@ class Compiler {
1613
1624
  handlePropertyNames(src, schema, varName, pathContext, extra) {
1614
1625
  if (extra.before != "")
1615
1626
  src.push(`if(${extra.before} true){`);
1616
- src.push(`for (const key in ${varName}) {`);
1627
+ const key = "key" + counter++;
1628
+ src.push(`for (const ${key} in ${varName}) {`);
1617
1629
  const propertyNameValidation = this.compileSchema(schema.propertyNames, {
1618
1630
  schema: `${pathContext.schema}/propertyNames`,
1619
- data: `${pathContext.data}/\${key}`,
1620
- $data: `${pathContext.$data}/\${key}`,
1631
+ data: `${pathContext.data}/\${${key}}`,
1632
+ $data: `${pathContext.$data}/\${${key}}`,
1621
1633
  alt: pathContext.alt,
1622
1634
  alt2: pathContext.alt2,
1623
- }, {}, `key`, extra);
1635
+ }, {}, key, extra);
1624
1636
  src.push(propertyNameValidation, "}");
1625
1637
  if (extra.before != "")
1626
1638
  src.push(`}`);
@@ -1732,7 +1744,8 @@ class Compiler {
1732
1744
  const evalSet = trackingState.unevaluatedPropVar;
1733
1745
  if (extra.before != "")
1734
1746
  src.push(`if(${extra.before} true){`);
1735
- src.push(`const ${unName} = [];`, `for (const key in ${varName}) {`, `if (!${evalSet}.has(key)) {`, `${unName}.push(key);`, `}`, `}`);
1747
+ const key = "key" + counter++;
1748
+ src.push(`const ${unName} = [];`, `for (const ${key} in ${varName}) {`, `if (!${evalSet}.has(${key})) {`, `${unName}.push(${key});`, `}`, `}`);
1736
1749
  if (schema.unevaluatedProperties === false) {
1737
1750
  src.push(`if (${unName}.length > 0) {${this.buildErrorReturn(pathContext, {
1738
1751
  keyword: "unevaluatedProperties",
@@ -1745,7 +1758,8 @@ class Compiler {
1745
1758
  }
1746
1759
  else if (schema.unevaluatedProperties === true) {
1747
1760
  if (trackingState.parentHasUnevaluatedProperties) {
1748
- src.push(`for(const key in ${varName}){${trackingState.parentUnevaluatedPropVar}.add(key)}`);
1761
+ const key = "key" + counter++;
1762
+ src.push(`for(const ${key} in ${varName}){${trackingState.parentUnevaluatedPropVar}.add(${key})}`);
1749
1763
  }
1750
1764
  }
1751
1765
  else {
@@ -2063,7 +2077,8 @@ class Compiler {
2063
2077
  const evalSet = trackingState.unevaluatedItemVar;
2064
2078
  if (extra.before != "")
2065
2079
  src.push(`if(${extra.before} true){`);
2066
- src.push(`const ${unName} = [];`, `for (let i = 0; i < ${varName}.length; i++) {`, `if (!${evalSet}.has(i)) {`, `${unName}.push(i);`, `}`, `}`);
2080
+ const i = "i" + counter++;
2081
+ src.push(`const ${unName} = [];`, `for (let ${i} = 0; ${i} < ${varName}.length; ${i}++) {`, `if (!${evalSet}.has(${i})) {`, `${unName}.push(${i});`, `}`, `}`);
2067
2082
  if (schema.unevaluatedItems === false) {
2068
2083
  src.push(`if (${extra.before}${unName}.length > 0) {${this.buildErrorReturn(pathContext, {
2069
2084
  keyword: "unevaluatedItems",