ata-validator 0.1.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/binding.gyp ADDED
@@ -0,0 +1,33 @@
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
+ ],
15
+ "dependencies": [
16
+ "<!(node -p \"require('node-addon-api').gyp\")"
17
+ ],
18
+ "cflags!": ["-fno-exceptions"],
19
+ "cflags_cc!": ["-fno-exceptions"],
20
+ "cflags_cc": ["-std=c++20"],
21
+ "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
22
+ "conditions": [
23
+ ["OS=='mac'", {
24
+ "xcode_settings": {
25
+ "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
26
+ "CLANG_CXX_LANGUAGE_STANDARD": "c++20",
27
+ "MACOSX_DEPLOYMENT_TARGET": "12.0"
28
+ }
29
+ }]
30
+ ]
31
+ }
32
+ ]
33
+ }
package/compat.js ADDED
@@ -0,0 +1,51 @@
1
+ const { Validator } = require("./index");
2
+
3
+ class Ata {
4
+ constructor(opts = {}) {
5
+ this._opts = opts;
6
+ this._schemas = new Map();
7
+ }
8
+
9
+ compile(schema) {
10
+ const v = new Validator(schema);
11
+ const validate = (data) => {
12
+ const result = v.validate(data);
13
+ validate.errors = result.valid
14
+ ? null
15
+ : result.errors.map((e) => ({
16
+ instancePath: e.path ? "/" + e.path.replace(/\//g, "/") : "",
17
+ schemaPath: "",
18
+ keyword: "",
19
+ params: {},
20
+ message: e.message,
21
+ }));
22
+ return result.valid;
23
+ };
24
+ validate.errors = null;
25
+ validate.schema = schema;
26
+ return validate;
27
+ }
28
+
29
+ validate(schema, data) {
30
+ const validate = this.compile(schema);
31
+ return validate(data);
32
+ }
33
+
34
+ addSchema(schema, key) {
35
+ if (key) {
36
+ this._schemas.set(key, schema);
37
+ } else if (schema.$id) {
38
+ this._schemas.set(schema.$id, schema);
39
+ }
40
+ return this;
41
+ }
42
+
43
+ getSchema(key) {
44
+ const schema = this._schemas.get(key);
45
+ if (schema) return this.compile(schema);
46
+ return undefined;
47
+ }
48
+ }
49
+
50
+ module.exports = Ata;
51
+ module.exports.default = Ata;