ata-validator 0.6.0 → 0.7.0
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/compat.mjs +3 -0
- package/index.browser.mjs +4 -0
- package/index.js +6 -4
- package/index.mjs +3 -0
- package/lib/js-compiler.js +1 -1
- package/package.json +26 -1
- package/src/ata.cpp +8 -0
package/compat.mjs
ADDED
package/index.js
CHANGED
|
@@ -282,6 +282,7 @@ function parsePointerPath(path) {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
function createPaddedBuffer(jsonStr) {
|
|
285
|
+
if (typeof Buffer === 'undefined') throw new Error('createPaddedBuffer requires Node.js Buffer');
|
|
285
286
|
const jsonBuf = Buffer.from(jsonStr);
|
|
286
287
|
const padded = Buffer.allocUnsafe(jsonBuf.length + SIMDJSON_PADDING);
|
|
287
288
|
jsonBuf.copy(padded);
|
|
@@ -405,11 +406,12 @@ class Validator {
|
|
|
405
406
|
: this._schemaStr;
|
|
406
407
|
const cached = _compileCache.get(mapKey);
|
|
407
408
|
let jsFn, jsCombinedFn, jsErrFn;
|
|
408
|
-
|
|
409
|
+
var _forceNapi = typeof process !== 'undefined' && process.env && process.env.ATA_FORCE_NAPI;
|
|
410
|
+
if (cached && !_forceNapi) {
|
|
409
411
|
jsFn = cached.jsFn;
|
|
410
412
|
jsCombinedFn = cached.combined;
|
|
411
413
|
jsErrFn = cached.errFn;
|
|
412
|
-
} else if (!
|
|
414
|
+
} else if (!_forceNapi) {
|
|
413
415
|
jsFn = compileToJSCodegen(schemaObj, sm) || compileToJS(schemaObj, null, sm);
|
|
414
416
|
jsCombinedFn = compileToJSCombined(schemaObj, VALID_RESULT, sm);
|
|
415
417
|
jsErrFn = compileToJSCodegenWithErrors(schemaObj, sm);
|
|
@@ -686,7 +688,7 @@ class Validator {
|
|
|
686
688
|
|
|
687
689
|
_ensureCodegen() {
|
|
688
690
|
if (this._jsFn) return;
|
|
689
|
-
if (process.env.ATA_FORCE_NAPI) return;
|
|
691
|
+
if (typeof process !== 'undefined' && process.env && process.env.ATA_FORCE_NAPI) return;
|
|
690
692
|
const sm = this._schemaMap.size > 0 ? this._schemaMap : null;
|
|
691
693
|
const mapKey = this._schemaMap.size > 0
|
|
692
694
|
? this._schemaStr + '\0' + [...this._schemaMap.keys()].sort().join('\0')
|
|
@@ -902,7 +904,7 @@ function validate(schema, data) {
|
|
|
902
904
|
|
|
903
905
|
function version() {
|
|
904
906
|
if (native) return native.version();
|
|
905
|
-
return require("./package.json").version;
|
|
907
|
+
try { return require("./package.json").version; } catch { return "unknown"; }
|
|
906
908
|
}
|
|
907
909
|
|
|
908
910
|
// Bundle multiple validators into a single JS file for fast startup.
|
package/index.mjs
ADDED
package/lib/js-compiler.js
CHANGED
|
@@ -786,7 +786,7 @@ function genCode(schema, v, lines, ctx, knownType) {
|
|
|
786
786
|
if (reqChecks.length > 0) {
|
|
787
787
|
lines.push(`if(${reqChecks.join('||')})return false`)
|
|
788
788
|
}
|
|
789
|
-
} else if (schema.required) {
|
|
789
|
+
} else if (schema.required && schema.required.length > 0) {
|
|
790
790
|
if (isObj) {
|
|
791
791
|
const checks = schema.required.map(key => `${v}[${JSON.stringify(key)}]===undefined`)
|
|
792
792
|
lines.push(`if(${checks.join('||')})return false`)
|
package/package.json
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ata-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Ultra-fast JSON Schema validator. 4.7x faster validation, 1,800x faster compilation. Works without native addon. Cross-schema $ref, Draft 2020-12 + Draft 7, V8-optimized JS codegen, simdjson, RE2, multi-core. Standard Schema V1 compatible.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"module": "index.mjs",
|
|
6
7
|
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"browser": {
|
|
12
|
+
"import": "./index.browser.mjs",
|
|
13
|
+
"require": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"import": "./index.mjs",
|
|
16
|
+
"require": "./index.js"
|
|
17
|
+
},
|
|
18
|
+
"./compat": {
|
|
19
|
+
"types": "./compat.d.ts",
|
|
20
|
+
"import": "./compat.mjs",
|
|
21
|
+
"require": "./compat.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"browser": {
|
|
26
|
+
"node-gyp-build": false
|
|
27
|
+
},
|
|
7
28
|
"scripts": {
|
|
8
29
|
"install": "node-gyp-build",
|
|
9
30
|
"build": "node-gyp rebuild",
|
|
@@ -13,6 +34,7 @@
|
|
|
13
34
|
"test:suite": "node tests/run_suite.js",
|
|
14
35
|
"test:compat": "node tests/test_compat.js",
|
|
15
36
|
"test:standard-schema": "node tests/test_standard_schema.js",
|
|
37
|
+
"test:browser": "node tests/test_browser.js",
|
|
16
38
|
"bench": "node benchmark/bench_large.js",
|
|
17
39
|
"fuzz": "node tests/fuzz_differential.js",
|
|
18
40
|
"fuzz:long": "FUZZ_ITERATIONS=100000 node tests/fuzz_differential.js"
|
|
@@ -47,9 +69,12 @@
|
|
|
47
69
|
},
|
|
48
70
|
"files": [
|
|
49
71
|
"index.js",
|
|
72
|
+
"index.mjs",
|
|
73
|
+
"index.browser.mjs",
|
|
50
74
|
"index.d.ts",
|
|
51
75
|
"lib/",
|
|
52
76
|
"compat.js",
|
|
77
|
+
"compat.mjs",
|
|
53
78
|
"compat.d.ts",
|
|
54
79
|
"binding.gyp",
|
|
55
80
|
"binding/",
|
package/src/ata.cpp
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
#include <unistd.h>
|
|
20
20
|
#endif
|
|
21
21
|
|
|
22
|
+
// MSVC implementation by Pavel P (https://gist.github.com/pps83/3210a2f980fd02bb2ba2e5a1fc4a2ef0)
|
|
23
|
+
#if defined(_MSC_VER) && !defined(__clang__)
|
|
24
|
+
#include <intrin.h>
|
|
25
|
+
#ifndef __builtin_popcount
|
|
26
|
+
#define __builtin_popcount __popcnt
|
|
27
|
+
#endif
|
|
28
|
+
#endif // defined(_MSC_VER) && !defined(__clang__)
|
|
29
|
+
|
|
22
30
|
#include "simdjson.h"
|
|
23
31
|
|
|
24
32
|
// --- Fast format validators (no std::regex) ---
|