@jetio/validator 1.0.1 β 1.0.3
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 +25 -59
- package/dist/compileSchema.d.ts +0 -1
- package/dist/compileSchema.js +177 -100
- package/dist/compileSchema.js.map +1 -1
- package/dist/index.cjs.js +213 -117
- package/dist/index.esm.js +213 -117
- package/dist/jet-validator.js +36 -16
- package/dist/jet-validator.js.map +1 -1
- package/dist/resolver.js +1 -1
- package/dist/resolver.js.map +1 -1
- package/dist/src/compileSchema.d.ts +0 -1
- package/dist/validator.umd.js +213 -121
- package/package.json +16 -4
package/README.md
CHANGED
|
@@ -363,28 +363,14 @@ For transparency, here are the keywords jet-validator intentionally does not sup
|
|
|
363
363
|
|
|
364
364
|
### Summary
|
|
365
365
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
- **Overall winner:** 71.8% of all benchmarks
|
|
366
|
+
π **Compilation:** 19x faster (1.47ms vs 28.29ms)
|
|
367
|
+
β
**Valid Data:** 58% win rate (36/62)
|
|
368
|
+
π‘οΈ **Invalid Data:** 73% win rate (45/62)
|
|
369
|
+
π **Overall:** 72% win rate (89/124)
|
|
371
370
|
|
|
372
|
-
|
|
371
|
+
[π Full Benchmark Report](https://github.com/official-jetio/validator/blob/main/benchmarks/results/COMPARISON.md) | [π Detailed Results](https://github.com/official-jetio/validator/tree/main/benchmarks/results/)
|
|
373
372
|
|
|
374
|
-
|
|
375
|
-
- Pattern matching: Up to 88% faster
|
|
376
|
-
- Integer validation: 48-120% faster
|
|
377
|
-
- Object validation at scale: 28-51% faster
|
|
378
|
-
|
|
379
|
-
**Where AJV leads:**
|
|
380
|
-
|
|
381
|
-
- Deeply chained $refs: 88% faster
|
|
382
|
-
- Deep allOf chains: 68% faster
|
|
383
|
-
- Complex conditionals: 36% faster
|
|
384
|
-
|
|
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/)
|
|
386
|
-
|
|
387
|
-
_Tested against AJV v8.17.1 using official benchmarks with 65 schemas, 1000 warmups, 10000 iterations, 5 runs per test_
|
|
373
|
+
_Tested against AJV v8.17.1 using official benchmarks with 65 schemas, 1000 warmups, 10000 iterations, 30 runs per test_
|
|
388
374
|
|
|
389
375
|
---
|
|
390
376
|
|
|
@@ -888,7 +874,6 @@ len_of("cafΓ©"); // 4
|
|
|
888
874
|
|
|
889
875
|
**Use case:** Validating `minLength`/`maxLength` for strings with emoji or special Unicode characters.
|
|
890
876
|
|
|
891
|
-
**β [See Full Utilities API Reference](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#utilities-api)**
|
|
892
877
|
|
|
893
878
|
---
|
|
894
879
|
|
|
@@ -910,18 +895,16 @@ const validate = jetValidator.compile(schema);
|
|
|
910
895
|
|
|
911
896
|
**Benefits of switching:**
|
|
912
897
|
|
|
913
|
-
- β‘
|
|
898
|
+
- β‘ 19x faster compilation
|
|
914
899
|
- π¦ Smaller bundle size
|
|
915
|
-
- π― Built-in formats (no separate packages)
|
|
900
|
+
- π― Built-in formats and error messages (no separate packages)
|
|
916
901
|
- β¨ Enhanced features (`elseIf`, better `$data`)
|
|
917
902
|
|
|
918
903
|
**What's different:**
|
|
919
904
|
|
|
920
|
-
- Error object structure
|
|
921
|
-
- Custom keywords use different API
|
|
922
|
-
- Meta-schema setup
|
|
923
|
-
|
|
924
|
-
**β [See Migration Guide](https://github.com/official-jetio/validator/blob/main/DOCUMENTATION.md#migration-from-ajv)**
|
|
905
|
+
- Error object structure
|
|
906
|
+
- Custom keywords use different API
|
|
907
|
+
- Meta-schema setup with cli
|
|
925
908
|
|
|
926
909
|
---
|
|
927
910
|
|
|
@@ -939,7 +922,7 @@ const validate = jetValidator.compile(schema);
|
|
|
939
922
|
### Consider Alternatives If:
|
|
940
923
|
|
|
941
924
|
β οΈ You need 100% JSON Schema spec compliance (we're at 99.5%)
|
|
942
|
-
β οΈ You're already heavily invested in AJV ecosystem with custom plugins (we offer the same custom keywords but contexts are simpler and different, although much more easy to use
|
|
925
|
+
β οΈ You're already heavily invested in AJV ecosystem with custom plugins (we offer the same custom keywords but contexts are simpler and different, although much more easy to use)
|
|
943
926
|
β οΈ You need streaming validation for extremely large documents
|
|
944
927
|
|
|
945
928
|
---
|
|
@@ -951,7 +934,7 @@ const validate = jetValidator.compile(schema);
|
|
|
951
934
|
jet-validator eliminates infinite recursion through a unique resolution approach. Unlike other validators that resolve references during traversal (causing stack overflow), jet-validator:
|
|
952
935
|
|
|
953
936
|
1. **Collects** all references and identifiers
|
|
954
|
-
2. **Assigns** unique function names to each location
|
|
937
|
+
2. **Assigns** unique function names to each location when inlining is impossible
|
|
955
938
|
3. **Resolves** references by replacing them with function calls
|
|
956
939
|
|
|
957
940
|
This architecture enables both lightning-fast compilation and bulletproof circular reference handling.
|
|
@@ -965,14 +948,14 @@ This architecture enables both lightning-fast compilation and bulletproof circul
|
|
|
965
948
|
Traditional validators:
|
|
966
949
|
|
|
967
950
|
```typescript
|
|
968
|
-
// Slow: 20ms per compilation
|
|
951
|
+
// Slow: 10-20ms per compilation
|
|
969
952
|
const validate = ajv.compile(schema); // Must cache!
|
|
970
953
|
```
|
|
971
954
|
|
|
972
955
|
jet-validator:
|
|
973
956
|
|
|
974
957
|
```typescript
|
|
975
|
-
// Fast:
|
|
958
|
+
// Fast: 0.7ms per compilation
|
|
976
959
|
const validate = jetValidator.compile(schema); // Can recompile!
|
|
977
960
|
```
|
|
978
961
|
|
|
@@ -1141,7 +1124,7 @@ We welcome contributions! jet-validator is a community project and we appreciate
|
|
|
1141
1124
|
```bash
|
|
1142
1125
|
# Clone the repo
|
|
1143
1126
|
git clone https://github.com/official-jetio/validator
|
|
1144
|
-
cd
|
|
1127
|
+
cd validator
|
|
1145
1128
|
|
|
1146
1129
|
# Install dependencies
|
|
1147
1130
|
npm install
|
|
@@ -1159,8 +1142,7 @@ npm run test:draft6
|
|
|
1159
1142
|
npm run test
|
|
1160
1143
|
|
|
1161
1144
|
# Run benchmarks
|
|
1162
|
-
|
|
1163
|
-
npm run benchmark:compare
|
|
1145
|
+
node --expose-gc --max-old-space-size=4096 --max-semi-space-size=64 benchmarks/jet-validator-benchmark.js
|
|
1164
1146
|
```
|
|
1165
1147
|
|
|
1166
1148
|
### Testing Philosophy
|
|
@@ -1174,7 +1156,7 @@ jet-validator uses the official [JSON Schema Test Suite](https://github.com/json
|
|
|
1174
1156
|
3. Run the official test suite: `npm run test:draft2020-12` (or appropriate draft)
|
|
1175
1157
|
4. Check compliance rate - aim to maintain or improve current 99.5%+ compliance
|
|
1176
1158
|
|
|
1177
|
-
**The test runner** (`tests/test
|
|
1159
|
+
**The test runner** (`tests/test.ts`) validates against:
|
|
1178
1160
|
|
|
1179
1161
|
- 1,261+ tests for Draft 2020-12
|
|
1180
1162
|
- 1,227+ tests for Draft 2019-09
|
|
@@ -1294,23 +1276,10 @@ We track bugs and feature requests using GitHub Issues.
|
|
|
1294
1276
|
---
|
|
1295
1277
|
|
|
1296
1278
|
## β οΈ Benchmark Methodology & Hardware Notes
|
|
1297
|
-
|
|
1298
|
-
The benchmarks took hours to run due to laptop hardware and the billions of operations performed. The `array100KItems` benchmark aloneβvalidating 100K array items with 1,000 warmups, 10,000 iterations, and 5 runsβwas particularly intensive.
|
|
1299
|
-
|
|
1300
1279
|
**Performance on Better Hardware:**
|
|
1301
1280
|
|
|
1302
1281
|
Results will vary significantly on better hardware. While absolute numbers will improve across the board, jet-validator is expected to maintain its performance advantages, especially in compilation speed.
|
|
1303
1282
|
|
|
1304
|
-
**Implementation Differences:**
|
|
1305
|
-
|
|
1306
|
-
Unlike AJV, jet-validator doesn't inline `$ref`s by default. This design choice:
|
|
1307
|
-
|
|
1308
|
-
- Reduces code bloat
|
|
1309
|
-
- Enables proper tracing for `unevaluatedItems`/`unevaluatedProperties`
|
|
1310
|
-
- Maintains cleaner stack traces for debugging
|
|
1311
|
-
|
|
1312
|
-
Optional inlining is a feature we plan to add in the future for users who prefer maximum runtime performance over bundle size.
|
|
1313
|
-
|
|
1314
1283
|
---
|
|
1315
1284
|
|
|
1316
1285
|
## π Conclusion
|
|
@@ -1318,11 +1287,10 @@ Optional inlining is a feature we plan to add in the future for users who prefer
|
|
|
1318
1287
|
jet-validator has proven itself as a strong contender for JSON Schema validation in the Node.js ecosystem, offering:
|
|
1319
1288
|
|
|
1320
1289
|
β
**99.5% JSON Schema compliance** - More spec-compliant than AJV in many areas
|
|
1321
|
-
|
|
1322
|
-
β
**
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
β
**66% invalid win rate** - Dominant error detection
|
|
1290
|
+
π **Compilation:** 19x faster (1.47ms vs 28.29ms) on average - Game-changer for serverless
|
|
1291
|
+
β
**Valid Data:** 58% win rate (36/62)
|
|
1292
|
+
π‘οΈ **Invalid Data:** 73% win rate (45/62)
|
|
1293
|
+
π **Overall:** 72% win rate (89/124)
|
|
1326
1294
|
|
|
1327
1295
|
**jet-validator is the clear choice for:**
|
|
1328
1296
|
|
|
@@ -1331,12 +1299,10 @@ jet-validator has proven itself as a strong contender for JSON Schema validation
|
|
|
1331
1299
|
- Real-world schema validation
|
|
1332
1300
|
- Applications requiring fast compilation
|
|
1333
1301
|
- Security-focused applications (invalid data detection)
|
|
1334
|
-
|
|
1335
|
-
**Consider AJV for:**
|
|
1336
|
-
|
|
1337
|
-
- Extremely deep composition chains (>10 levels)
|
|
1338
1302
|
- Heavy reliance on complex $ref graphs
|
|
1339
1303
|
- Schemas with complex conditional logic
|
|
1304
|
+
- Extremely deep composition chains (>10 levels)
|
|
1305
|
+
|
|
1340
1306
|
|
|
1341
1307
|
---
|
|
1342
1308
|
|
|
@@ -1355,7 +1321,7 @@ MIT Β© [Great Venerable](https://github.com/greatvenerable)
|
|
|
1355
1321
|
- **[npm Package](https://www.npmjs.com/package/@jetio/validator)**
|
|
1356
1322
|
- **[GitHub Repository](https://github.com/@jetio/validator)**
|
|
1357
1323
|
- **[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/
|
|
1324
|
+
- **[Benchmark Results](https://github.com/official-jetio/validator/blob/main/benchmarks/results/COMPARISON.md)**
|
|
1359
1325
|
- **[Issue Tracker](https://github.com/official-jetio/validator/issues)**
|
|
1360
1326
|
- **[GitHub Discussions](https://github.com/official-jetio/validator/discussions)**
|
|
1361
1327
|
|