ata-validator 0.10.1 → 0.10.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/include/ata.h +4 -4
- package/lib/js-compiler.js +14 -3
- package/lib/shape-classifier.js +1 -1
- package/lib/tier0.js +12 -7
- package/package.json +1 -1
- package/prebuilds/ata-darwin-arm64/node-napi-v10.node +0 -0
- package/prebuilds/ata-linux-arm64/node-napi-v10.node +0 -0
- package/prebuilds/ata-linux-arm64-musl/node-napi-v10.node +0 -0
- package/prebuilds/ata-linux-x64/node-napi-v10.node +0 -0
- package/prebuilds/ata-linux-x64-musl/node-napi-v10.node +0 -0
- package/prebuilds/ata-win32-x64/node-napi-v10.node +0 -0
package/include/ata.h
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
#include <variant>
|
|
9
9
|
#include <vector>
|
|
10
10
|
|
|
11
|
-
#define ATA_VERSION "0.
|
|
11
|
+
#define ATA_VERSION "0.10.3"
|
|
12
12
|
|
|
13
13
|
namespace ata {
|
|
14
14
|
|
|
15
15
|
inline constexpr uint32_t VERSION_MAJOR = 0;
|
|
16
|
-
inline constexpr uint32_t VERSION_MINOR =
|
|
17
|
-
inline constexpr uint32_t VERSION_REVISION =
|
|
16
|
+
inline constexpr uint32_t VERSION_MINOR = 10;
|
|
17
|
+
inline constexpr uint32_t VERSION_REVISION = 3;
|
|
18
18
|
|
|
19
19
|
inline constexpr std::string_view version() noexcept {
|
|
20
|
-
return "0.
|
|
20
|
+
return "0.10.3";
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
enum class error_code : uint8_t {
|
package/lib/js-compiler.js
CHANGED
|
@@ -6,7 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
// Count Unicode code points, not UTF-16 code units (surrogate pairs).
|
|
8
8
|
// JSON Schema: minLength/maxLength count characters per RFC 8259.
|
|
9
|
-
|
|
9
|
+
// Fast path: if no surrogate pairs exist, .length is correct (covers >99% of real data).
|
|
10
|
+
function _cpLen(s) {
|
|
11
|
+
const len = s.length;
|
|
12
|
+
for (let i = 0; i < len; i++) {
|
|
13
|
+
if (s.charCodeAt(i) >= 0xD800 && s.charCodeAt(i) <= 0xDBFF) {
|
|
14
|
+
// Found a high surrogate — count code points the slow way
|
|
15
|
+
let n = 0; for (const _ of s) n++; return n;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return len;
|
|
19
|
+
}
|
|
10
20
|
|
|
11
21
|
// AJV-compatible error message templates (compile-time, not runtime)
|
|
12
22
|
const AJV_MESSAGES = {
|
|
@@ -275,11 +285,12 @@ function compileToJS(schema, defs, schemaMap) {
|
|
|
275
285
|
// string
|
|
276
286
|
if (schema.minLength !== undefined) {
|
|
277
287
|
const min = schema.minLength
|
|
278
|
-
|
|
288
|
+
const min2 = min * 2
|
|
289
|
+
checks.push((d) => typeof d !== 'string' || d.length >= min2 || (d.length >= min && _cpLen(d) >= min))
|
|
279
290
|
}
|
|
280
291
|
if (schema.maxLength !== undefined) {
|
|
281
292
|
const max = schema.maxLength
|
|
282
|
-
checks.push((d) => typeof d !== 'string' || _cpLen(d) <= max)
|
|
293
|
+
checks.push((d) => typeof d !== 'string' || d.length <= max || _cpLen(d) <= max)
|
|
283
294
|
}
|
|
284
295
|
if (schema.pattern) {
|
|
285
296
|
try {
|
package/lib/shape-classifier.js
CHANGED
package/lib/tier0.js
CHANGED
|
@@ -19,10 +19,15 @@ const T_BOOLEAN = TYPE_MASK.boolean;
|
|
|
19
19
|
|
|
20
20
|
// Count Unicode code points, not UTF-16 code units.
|
|
21
21
|
// JSON Schema spec: minLength/maxLength count characters (RFC 8259 = code points).
|
|
22
|
+
// Fast path: scan for surrogates first, skip slow iteration for ASCII-only strings.
|
|
22
23
|
function codePointLength(s) {
|
|
23
|
-
|
|
24
|
-
for (
|
|
25
|
-
|
|
24
|
+
const len = s.length;
|
|
25
|
+
for (let i = 0; i < len; i++) {
|
|
26
|
+
if (s.charCodeAt(i) >= 0xD800 && s.charCodeAt(i) <= 0xDBFF) {
|
|
27
|
+
let n = 0; for (const _ of s) n++; return n;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return len;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
// Numeric constraint flags, packed into constraint.numFlags.
|
|
@@ -102,8 +107,8 @@ function checkPrimitive(c, v) {
|
|
|
102
107
|
if (typeof v !== 'string') return false;
|
|
103
108
|
const minLen = c.minLen;
|
|
104
109
|
const maxLen = c.maxLen;
|
|
105
|
-
if (minLen >= 0 && codePointLength(v) < minLen) return false;
|
|
106
|
-
if (maxLen >= 0 && codePointLength(v) > maxLen) return false;
|
|
110
|
+
if (minLen >= 0) { const l = v.length; if (l < minLen) return false; if (l < minLen * 2 && codePointLength(v) < minLen) return false; }
|
|
111
|
+
if (maxLen >= 0) { const l = v.length; if (l > maxLen && codePointLength(v) > maxLen) return false; }
|
|
107
112
|
} else if (m === T_INTEGER) {
|
|
108
113
|
if (typeof v !== 'number' || !Number.isInteger(v)) return false;
|
|
109
114
|
const f = c.numFlags;
|
|
@@ -156,8 +161,8 @@ function tier0ValidateObject(plan, data) {
|
|
|
156
161
|
if (typeof v !== 'string') return false;
|
|
157
162
|
const minLen = c.minLen;
|
|
158
163
|
const maxLen = c.maxLen;
|
|
159
|
-
if (minLen >= 0
|
|
160
|
-
if (maxLen >= 0
|
|
164
|
+
if (minLen >= 0) { const l = v.length; if (l < minLen) return false; if (l < minLen * 2 && codePointLength(v) < minLen) return false; }
|
|
165
|
+
if (maxLen >= 0) { const l = v.length; if (l > maxLen && codePointLength(v) > maxLen) return false; }
|
|
161
166
|
} else if (m === T_INTEGER) {
|
|
162
167
|
if (typeof v !== 'number' || !Number.isInteger(v)) return false;
|
|
163
168
|
const f = c.numFlags;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ata-validator",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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
6
|
"module": "index.mjs",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|