ata-validator 0.7.0 → 0.7.1
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/CMakeLists.txt +132 -0
- package/index.js +1 -1
- package/lib/js-compiler.js +10 -7
- package/package.json +17 -11
- 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-x64/node-napi-v10.node +0 -0
- package/binding.gyp +0 -44
- package/prebuilds/darwin-arm64/ata-validator.node +0 -0
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.28)
|
|
2
|
+
cmake_policy(SET CMP0091 NEW)
|
|
3
|
+
cmake_policy(SET CMP0042 NEW)
|
|
4
|
+
|
|
5
|
+
project(ata VERSION 0.1.0 LANGUAGES CXX)
|
|
6
|
+
|
|
7
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
|
|
8
|
+
|
|
9
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
10
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
11
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
12
|
+
|
|
13
|
+
if(MSVC)
|
|
14
|
+
set(ABSL_MSVC_STATIC_RUNTIME ON)
|
|
15
|
+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)
|
|
16
|
+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
17
|
+
endif()
|
|
18
|
+
|
|
19
|
+
option(ATA_TESTING "Build test suite" ON)
|
|
20
|
+
option(ATA_BENCHMARKS "Build benchmarks" OFF)
|
|
21
|
+
option(ATA_SANITIZE "Enable address sanitizer" OFF)
|
|
22
|
+
|
|
23
|
+
# Fetch simdjson
|
|
24
|
+
include(FetchContent)
|
|
25
|
+
FetchContent_Declare(
|
|
26
|
+
simdjson
|
|
27
|
+
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
|
|
28
|
+
GIT_TAG v3.12.2
|
|
29
|
+
GIT_SHALLOW TRUE
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# RE2 — fast regex engine (replaces std::regex)
|
|
33
|
+
set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
34
|
+
FetchContent_Declare(
|
|
35
|
+
re2
|
|
36
|
+
GIT_REPOSITORY https://github.com/google/re2.git
|
|
37
|
+
GIT_TAG 2024-07-02
|
|
38
|
+
GIT_SHALLOW TRUE
|
|
39
|
+
EXCLUDE_FROM_ALL
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Abseil — required by RE2
|
|
43
|
+
set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
|
|
44
|
+
set(ABSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
45
|
+
set(ABSL_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
|
46
|
+
FetchContent_Declare(
|
|
47
|
+
abseil-cpp
|
|
48
|
+
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
|
|
49
|
+
GIT_TAG 20240722.0
|
|
50
|
+
GIT_SHALLOW TRUE
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
FetchContent_MakeAvailable(abseil-cpp simdjson re2)
|
|
54
|
+
|
|
55
|
+
if (CMAKE_JS_VERSION)
|
|
56
|
+
# add_definitions(-DNAPI_VERSION=10)
|
|
57
|
+
include_directories(${CMAKE_JS_INC})
|
|
58
|
+
file(GLOB SOURCE_FILES "binding/*.cpp" "src/*.cpp" "deps/simdjson/*.cpp")
|
|
59
|
+
else()
|
|
60
|
+
file(GLOB SOURCE_FILES "src/*.cpp")
|
|
61
|
+
endif()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if (CMAKE_JS_VERSION)
|
|
65
|
+
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
|
|
66
|
+
|
|
67
|
+
# Include Node-API wrappers
|
|
68
|
+
execute_process(
|
|
69
|
+
COMMAND node -p "require('node-addon-api').include"
|
|
70
|
+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
71
|
+
OUTPUT_VARIABLE NODE_ADDON_API_DIR
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
string(REGEX REPLACE "[\r\n\"]" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
|
|
75
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
|
|
76
|
+
|
|
77
|
+
# Include Node-API C headers
|
|
78
|
+
execute_process(
|
|
79
|
+
COMMAND node -p "require('node-api-headers').include_dir"
|
|
80
|
+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
81
|
+
OUTPUT_VARIABLE NODE_API_HEADERS_DIR
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
string(REGEX REPLACE "[\r\n\"]" "" NODE_API_HEADERS_DIR ${NODE_API_HEADERS_DIR})
|
|
85
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_API_HEADERS_DIR})
|
|
86
|
+
else()
|
|
87
|
+
add_library(${PROJECT_NAME} ${SOURCE_FILES})
|
|
88
|
+
endif()
|
|
89
|
+
|
|
90
|
+
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
|
91
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE simdjson re2)
|
|
92
|
+
|
|
93
|
+
if (CMAKE_JS_VERSION)
|
|
94
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
|
|
95
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
|
|
96
|
+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
|
|
97
|
+
endif()
|
|
98
|
+
|
|
99
|
+
add_library(ata::ata ALIAS ata)
|
|
100
|
+
|
|
101
|
+
if(CMAKE_JS_VERSION AND UNIX AND NOT APPLE)
|
|
102
|
+
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
|
|
103
|
+
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--exclude-libs,ALL)
|
|
104
|
+
endif()
|
|
105
|
+
|
|
106
|
+
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
|
|
107
|
+
# Generate node.lib
|
|
108
|
+
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
|
|
109
|
+
endif()
|
|
110
|
+
|
|
111
|
+
if(ATA_SANITIZE)
|
|
112
|
+
target_compile_options(ata PRIVATE -fsanitize=address -fno-omit-frame-pointer)
|
|
113
|
+
target_link_options(ata PRIVATE -fsanitize=address)
|
|
114
|
+
endif()
|
|
115
|
+
|
|
116
|
+
# Tests
|
|
117
|
+
if(ATA_TESTING)
|
|
118
|
+
enable_testing()
|
|
119
|
+
add_executable(ata_tests tests/test.cpp)
|
|
120
|
+
target_link_libraries(ata_tests PRIVATE ata simdjson)
|
|
121
|
+
if(ATA_SANITIZE)
|
|
122
|
+
target_compile_options(ata_tests PRIVATE -fsanitize=address -fno-omit-frame-pointer)
|
|
123
|
+
target_link_options(ata_tests PRIVATE -fsanitize=address)
|
|
124
|
+
endif()
|
|
125
|
+
add_test(NAME ata_tests COMMAND ata_tests)
|
|
126
|
+
endif()
|
|
127
|
+
|
|
128
|
+
# Benchmarks
|
|
129
|
+
if(ATA_BENCHMARKS)
|
|
130
|
+
add_executable(ata_bench benchmark/bench.cpp)
|
|
131
|
+
target_link_libraries(ata_bench PRIVATE ata simdjson)
|
|
132
|
+
endif()
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Native addon: optional. Core validate() uses JS codegen and works without it.
|
|
2
2
|
// Buffer APIs (isValid, countValid, isValidParallel) require native.
|
|
3
3
|
let native;
|
|
4
|
-
try { native = require("
|
|
4
|
+
try { native = require("pkg-prebuilds")(__dirname, require("./binding-options")); } catch {}
|
|
5
5
|
const {
|
|
6
6
|
compileToJS,
|
|
7
7
|
compileToJSCodegen,
|
package/lib/js-compiler.js
CHANGED
|
@@ -2331,13 +2331,16 @@ function genCodeC(schema, v, pathExpr, lines, ctx, schemaPrefix) {
|
|
|
2331
2331
|
if (destructKeys.length > 0) lines.push(`const{${destructKeys.join(',')}}=${v}`)
|
|
2332
2332
|
for (const key of schema.required) {
|
|
2333
2333
|
const check = hoisted[key] ? `${hoisted[key]}===undefined` : `${v}[${JSON.stringify(key)}]===undefined`
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2334
|
+
if (isStaticPath) {
|
|
2335
|
+
const ei = ctx.varCounter++
|
|
2336
|
+
const errVar = `_E${ei}`
|
|
2337
|
+
const pathVal = pathExpr ? pathExpr.slice(1, -1) : ''
|
|
2338
|
+
ctx.closureVars.push(errVar)
|
|
2339
|
+
ctx.closureVals.push(Object.freeze({keyword: 'required', instancePath: pathVal, schemaPath: `${schemaPrefix}/required`, params: Object.freeze({missingProperty: key}), message: `must have required property '${key}'`}))
|
|
2340
|
+
lines.push(`if(${check}){(_e||(_e=[])).push(${errVar})}`)
|
|
2341
|
+
} else {
|
|
2342
|
+
lines.push(`if(${check}){(_e||(_e=[])).push({keyword:'required',instancePath:${pathExpr||'""'},schemaPath:'${schemaPrefix}/required',params:{missingProperty:'${esc(key)}'},message:"must have required property '${esc(key)}'"})}`)
|
|
2343
|
+
}
|
|
2341
2344
|
}
|
|
2342
2345
|
} else if (schema.required) {
|
|
2343
2346
|
for (const key of schema.required) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ata-validator",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"browser": {
|
|
26
|
-
"
|
|
26
|
+
"pkg-prebuilds": false
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"install": "
|
|
30
|
-
"build": "
|
|
31
|
-
"
|
|
32
|
-
"prebuild
|
|
29
|
+
"install": "pkg-prebuilds-verify ./binding-options.js || cmake-js compile --target ata",
|
|
30
|
+
"build": "cmake-js build --target ata",
|
|
31
|
+
"rebuild": "cmake-js rebuild --target ata",
|
|
32
|
+
"prebuild": "pkg-prebuilds-copy --baseDir build/Release --source ata.node --name=ata --strip --napi_version=10",
|
|
33
|
+
"prebuild-all": "npm run prebuild -- --arch x64 && npm run prebuild -- --arch arm64",
|
|
33
34
|
"test": "node test.js",
|
|
34
35
|
"test:suite": "node tests/run_suite.js",
|
|
35
36
|
"test:compat": "node tests/test_compat.js",
|
|
@@ -82,21 +83,26 @@
|
|
|
82
83
|
"src/",
|
|
83
84
|
"deps/",
|
|
84
85
|
"prebuilds/",
|
|
86
|
+
"/CMakeLists.txt",
|
|
85
87
|
"README.md",
|
|
86
88
|
"LICENSE"
|
|
87
89
|
],
|
|
88
90
|
"dependencies": {
|
|
89
|
-
"node-addon-api": "^8.
|
|
90
|
-
"node-
|
|
91
|
+
"node-addon-api": "^8.7.0",
|
|
92
|
+
"node-api-headers": "^1.8.0",
|
|
93
|
+
"pkg-prebuilds": "^1.0.0"
|
|
91
94
|
},
|
|
92
95
|
"devDependencies": {
|
|
93
96
|
"@sinclair/typebox": "^0.34.49",
|
|
97
|
+
"cmake-js": "^8.0.0",
|
|
94
98
|
"mitata": "^1.0.34",
|
|
95
|
-
"node-gyp": "^11.0.0",
|
|
96
|
-
"prebuildify": "^6.0.1",
|
|
97
99
|
"typebox": "^1.1.7",
|
|
98
100
|
"valibot": "^1.3.1",
|
|
99
101
|
"zod": "^4.3.6"
|
|
100
102
|
},
|
|
101
|
-
"
|
|
103
|
+
"binary": {
|
|
104
|
+
"napi_versions": [
|
|
105
|
+
10
|
|
106
|
+
]
|
|
107
|
+
}
|
|
102
108
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/binding.gyp
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "ata",
|
|
5
|
-
"sources": [
|
|
6
|
-
"binding/ata_napi.cpp",
|
|
7
|
-
"src/ata.cpp",
|
|
8
|
-
"deps/simdjson/simdjson.cpp"
|
|
9
|
-
],
|
|
10
|
-
"include_dirs": [
|
|
11
|
-
"<!@(node -p \"require('node-addon-api').include\")",
|
|
12
|
-
"include",
|
|
13
|
-
"deps/simdjson",
|
|
14
|
-
"<!@(node -e \"var p=process.platform,a=process.arch;if(p==='darwin'){console.log(a==='arm64'?'/opt/homebrew/opt/re2/include':'/usr/local/opt/re2/include');console.log(a==='arm64'?'/opt/homebrew/opt/abseil/include':'/usr/local/opt/abseil/include');console.log(a==='arm64'?'/opt/homebrew/opt/mimalloc/include':'/usr/local/opt/mimalloc/include')}else{console.log('/usr/include')}\")"
|
|
15
|
-
],
|
|
16
|
-
"libraries": [
|
|
17
|
-
"<!@(node -e \"var p=process.platform,a=process.arch;if(p==='darwin'){var pre=a==='arm64'?'/opt/homebrew/opt/re2':'/usr/local/opt/re2';var mi=a==='arm64'?'/opt/homebrew/opt/mimalloc':'/usr/local/opt/mimalloc';console.log('-L'+pre+'/lib -lre2 -L'+mi+'/lib -lmimalloc')}else{console.log('-lre2')}\")"
|
|
18
|
-
],
|
|
19
|
-
"dependencies": [
|
|
20
|
-
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
21
|
-
],
|
|
22
|
-
"cflags!": ["-fno-exceptions"],
|
|
23
|
-
"cflags_cc!": ["-fno-exceptions"],
|
|
24
|
-
"cflags_cc": ["-std=c++20"],
|
|
25
|
-
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS", "NDEBUG"],
|
|
26
|
-
"conditions": [
|
|
27
|
-
["OS=='mac'", {
|
|
28
|
-
"xcode_settings": {
|
|
29
|
-
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
30
|
-
"CLANG_CXX_LANGUAGE_STANDARD": "c++20",
|
|
31
|
-
"MACOSX_DEPLOYMENT_TARGET": "12.0"
|
|
32
|
-
}
|
|
33
|
-
}],
|
|
34
|
-
["OS=='win'", {
|
|
35
|
-
"msvs_settings": {
|
|
36
|
-
"VCCLCompilerTool": {
|
|
37
|
-
"AdditionalOptions": ["/std:c++20", "/EHsc"]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}]
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
Binary file
|