@golemio/validator 0.2.2 → 0.2.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.
|
@@ -19,18 +19,13 @@ export declare class JSONSchemaValidator implements IValidator {
|
|
|
19
19
|
* @param jsonSchema JSON Schema object by which to validate the input data
|
|
20
20
|
* @param strict sets coerceTypes = false for Avj ( https://ajv.js.org/#coercing-data-types )
|
|
21
21
|
*/
|
|
22
|
-
constructor(modelName: string, jsonSchema: object,
|
|
23
|
-
/**
|
|
24
|
-
* Temporary wrapper to evaluate modules that are dependent on coerseType setting.
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
Validate(data: any): Promise<boolean>;
|
|
28
|
-
setLogger(logger: any): void;
|
|
22
|
+
constructor(modelName: string, jsonSchema: object, deprecated?: boolean);
|
|
29
23
|
/**
|
|
30
24
|
* Data validation - validates input data exactly by json schema
|
|
31
25
|
*
|
|
32
26
|
* @param {any} data Data to be validated by the validator's schema
|
|
33
27
|
* @returns {boolean} Returns true or throws error
|
|
34
28
|
*/
|
|
35
|
-
|
|
29
|
+
Validate(data: any): Promise<boolean>;
|
|
30
|
+
setLogger(logger: any): void;
|
|
36
31
|
}
|
|
@@ -22,45 +22,21 @@ class JSONSchemaValidator {
|
|
|
22
22
|
* @param jsonSchema JSON Schema object by which to validate the input data
|
|
23
23
|
* @param strict sets coerceTypes = false for Avj ( https://ajv.js.org/#coercing-data-types )
|
|
24
24
|
*/
|
|
25
|
-
constructor(modelName, jsonSchema,
|
|
25
|
+
constructor(modelName, jsonSchema, deprecated = false) {
|
|
26
26
|
this.modelName = modelName;
|
|
27
27
|
this.jsonSchema = jsonSchema;
|
|
28
28
|
const options = { schemaId: "auto" };
|
|
29
|
-
if (!strict) {
|
|
30
|
-
this.strictValidator = new JSONSchemaValidator(modelName, jsonSchema, true);
|
|
31
|
-
options.coerceTypes = true;
|
|
32
|
-
}
|
|
33
29
|
this.ajv = new Ajv(options);
|
|
34
30
|
this.ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"));
|
|
35
31
|
this.logger = Logger_1.log;
|
|
36
32
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Temporary wrapper to evaluate modules that are dependent on coerseType setting.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
Validate(data) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
if (this.strictValidator) {
|
|
44
|
-
try {
|
|
45
|
-
return yield this.strictValidator.Validate(data);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
this.logger.warn(`Unable to finish strict validation for ${this.modelName}. Err message: ${err.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return this.ValidateInternal(data);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
setLogger(logger) {
|
|
55
|
-
this.logger = logger;
|
|
56
|
-
}
|
|
57
33
|
/**
|
|
58
34
|
* Data validation - validates input data exactly by json schema
|
|
59
35
|
*
|
|
60
36
|
* @param {any} data Data to be validated by the validator's schema
|
|
61
37
|
* @returns {boolean} Returns true or throws error
|
|
62
38
|
*/
|
|
63
|
-
|
|
39
|
+
Validate(data) {
|
|
64
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
41
|
try {
|
|
66
42
|
const validate = this.ajv.compile(Object.assign({ $async: true }, this.jsonSchema));
|
|
@@ -78,6 +54,9 @@ class JSONSchemaValidator {
|
|
|
78
54
|
}
|
|
79
55
|
});
|
|
80
56
|
}
|
|
57
|
+
setLogger(logger) {
|
|
58
|
+
this.logger = logger;
|
|
59
|
+
}
|
|
81
60
|
}
|
|
82
61
|
exports.JSONSchemaValidator = JSONSchemaValidator;
|
|
83
62
|
//# sourceMappingURL=JSONSchemaValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONSchemaValidator.js","sourceRoot":"","sources":["../src/JSONSchemaValidator.ts"],"names":[],"mappings":"AAAA,YA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;oBACH,MAAM,KAAK,CAAC;iBACf;aACJ;QACL,CAAC;KAAA;IAEM,SAAS,CAAC,MAAW;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAvDD,kDAuDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemio/validator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Library of Validator classes of the Golemio Data Platform System",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test-debug": "mocha --inspect-brk=9230 -b --check-leaks --timeout 60000 -r ts-node/register -r dotenv/config --recursive test/*.test.ts --exit",
|
|
13
13
|
"code-coverage": "nyc mocha --check-leaks --timeout 60000 -r ts-node/register -r source-map-support/register -r dotenv/config --recursive test/*.test.ts --exit",
|
|
14
14
|
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
15
|
-
"generate-docs": "
|
|
15
|
+
"generate-docs": "typedoc --out docs/typedoc src"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
18
|
"author": "Operator ICT, a.s.",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"prettier": "^2.6.2",
|
|
41
41
|
"sinon": "^7.2.3",
|
|
42
42
|
"ts-node": "^9.1.1",
|
|
43
|
-
"typedoc": "^0.22.
|
|
43
|
+
"typedoc": "^0.22.15",
|
|
44
44
|
"typescript": "^4.4.4"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|