@spinajs/validation 1.1.8 → 1.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spinajs/validation",
3
- "version": "1.1.8",
3
+ "version": "1.2.9",
4
4
  "description": "validation library for spinajs framework",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -10,8 +10,8 @@
10
10
  "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
11
11
  "build": "tsc",
12
12
  "prepare": "npm run build",
13
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
14
- "lint": "tslint -p tsconfig.json",
13
+ "format": "prettier --write \"src/**/*.ts\"",
14
+ "lint": "eslint -c .eslintrc.js --ext .ts src",
15
15
  "prepublishOnly": "npm test && npm run lint",
16
16
  "preversion": "npm run lint",
17
17
  "version": "npm run format && git add -A src",
@@ -36,53 +36,15 @@
36
36
  },
37
37
  "homepage": "https://github.com/spinajs/validation#readme",
38
38
  "dependencies": {
39
- "@spinajs/configuration": "^1.1.8",
40
- "@spinajs/di": "^1.1.7",
41
- "@spinajs/exceptions": "^1.0.5",
42
- "@spinajs/log": "^1.1.7",
39
+ "@spinajs/configuration": "^1.2.7",
40
+ "@spinajs/di": "^1.2.7",
41
+ "@spinajs/exceptions": "^1.2.7",
42
+ "@spinajs/log": "^1.2.9",
43
43
  "ajv": "^8.8.2",
44
44
  "ajv-formats": "^2.1.1",
45
45
  "ajv-keywords": "^5.1.0",
46
- "ajv-merge-patch": "^5.0.1"
46
+ "ajv-merge-patch": "^5.0.1",
47
+ "lodash": "^4.17.21"
47
48
  },
48
- "devDependencies": {
49
- "@types/bunyan": "^1.8.6",
50
- "@types/chai": "^4.1.7",
51
- "@types/chai-as-promised": "^7.1.0",
52
- "@types/compression": "^1.7.0",
53
- "@types/cookie-parser": "^1.4.2",
54
- "@types/cookie-signature": "^1.0.3",
55
- "@types/cors": "^2.8.6",
56
- "@types/express": "^4.17.6",
57
- "@types/formidable": "^1.0.31",
58
- "@types/glob": "^7.2.0",
59
- "@types/helmet": "^0.0.47",
60
- "@types/lodash": "^4.14.136",
61
- "@types/luxon": "^2.0.8",
62
- "@types/mime": "^2.0.3",
63
- "@types/mocha": "^5.2.7",
64
- "@types/node": "^16.11.11",
65
- "@types/pug": "^2.0.4",
66
- "@types/randomstring": "^1.1.6",
67
- "@types/sinon": "^7.0.13",
68
- "@types/uuid": "^8.3.3",
69
- "chai": "^4.2.0",
70
- "chai-as-promised": "^7.1.1",
71
- "chai-dom": "^1.8.2",
72
- "chai-http": "^4.3.0",
73
- "cpx": "^1.5.0",
74
- "mocha": "^6.1.4",
75
- "nyc": "^14.1.1",
76
- "prettier": "^1.18.2",
77
- "sinon": "^7.3.2",
78
- "ts-mocha": "^6.0.0",
79
- "ts-node": "^8.3.0",
80
- "tslint": "^5.20.1",
81
- "tslint-circular-dependencies": "^0.1.0",
82
- "tslint-config-prettier": "^1.18.0",
83
- "tslint-config-standard": "^8.0.1",
84
- "tslint-no-unused-expression-chai": "^0.1.4",
85
- "typedoc": "^0.14.2",
86
- "typescript": "^4.2.3"
87
- }
49
+ "gitHead": "ece3619ffa482e1aaba0064e200626abc0f447bf"
88
50
  }
@@ -1,9 +0,0 @@
1
- declare const config: {
2
- validation: {
3
- allErrors: boolean;
4
- removeAdditional: boolean;
5
- useDefaults: boolean;
6
- coerceTypes: boolean;
7
- };
8
- };
9
- export default config;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
4
- validation: {
5
- // enable all errors on validation, not only first one that occurred
6
- allErrors: true,
7
- // remove properties that are not defined in schema
8
- removeAdditional: true,
9
- // set default values if possible
10
- useDefaults: true,
11
- // The option coerceTypes allows you to have your data types coerced to the types specified in your schema type keywords
12
- coerceTypes: true
13
- }
14
- };
15
- exports.default = config;
16
- //# sourceMappingURL=validation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/config/validation.ts"],"names":[],"mappings":";;AAAA,MAAM,MAAM,GAAG;IACX,UAAU,EAAE;QACR,qEAAqE;QACrE,SAAS,EAAE,IAAI;QAEf,mDAAmD;QACnD,gBAAgB,EAAE,IAAI;QAEtB,iCAAiC;QACjC,WAAW,EAAE,IAAI;QAEjB,wHAAwH;QACxH,WAAW,EAAE,IAAI;KACpB;CACJ,CAAA;AAED,kBAAe,MAAM,CAAC"}
@@ -1,8 +0,0 @@
1
- export declare const SCHEMA_SYMBOL: unique symbol;
2
- /**
3
- *
4
- * Add schema for object eg. model or dto.
5
- *
6
- * @param schema schema for object or schema name
7
- */
8
- export declare function Schema(schema: object | string): (target: any) => void;
package/lib/decorators.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Schema = exports.SCHEMA_SYMBOL = void 0;
4
- exports.SCHEMA_SYMBOL = Symbol('SCHEMA_SYMBOL');
5
- /**
6
- *
7
- * Add schema for object eg. model or dto.
8
- *
9
- * @param schema schema for object or schema name
10
- */
11
- function Schema(schema) {
12
- return (target) => {
13
- Reflect.defineMetadata(exports.SCHEMA_SYMBOL, schema, target.prototype || target);
14
- };
15
- }
16
- exports.Schema = Schema;
17
- //# sourceMappingURL=decorators.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAErD;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,MAAuB;IAC1C,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,OAAO,CAAC,cAAc,CAAC,qBAAa,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;IAC9E,CAAC,CAAC;AACN,CAAC;AAJD,wBAIC"}
@@ -1,11 +0,0 @@
1
- import { Exception } from "@spinajs/exceptions";
2
- import { ErrorObject } from "ajv";
3
- /**
4
- * The exception that is thrown when JSON entity is checked against schema and is invalid
5
- */
6
- export declare class ValidationFailed extends Exception {
7
- parameter: any;
8
- constructor(message: string, validationErrors: IValidationError[]);
9
- }
10
- export interface IValidationError extends ErrorObject {
11
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationFailed = void 0;
4
- const exceptions_1 = require("@spinajs/exceptions");
5
- /**
6
- * The exception that is thrown when JSON entity is checked against schema and is invalid
7
- */
8
- class ValidationFailed extends exceptions_1.Exception {
9
- constructor(message, validationErrors) {
10
- super(message);
11
- this.parameter = validationErrors;
12
- }
13
- }
14
- exports.ValidationFailed = ValidationFailed;
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD;;GAEG;AACF,MAAa,gBAAiB,SAAQ,sBAAS;IAG5C,YAAY,OAAe,EAAE,gBAAoC;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC;IACpC,CAAC;CACF;AAPF,4CAOE"}
package/lib/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * We export default configuration for webpack modules
3
- * Normally we load configuration from disk via filesystem
4
- * But webpack is bundlig all files into one.
5
- *
6
- * When we export, we can see configuration variable
7
- * in webpack module cache and webpack config loader can see it
8
- */
9
- export * from "./config/validation";
10
- export * from "./decorators";
11
- export * from "./exceptions";
12
- export * from "./validator";
package/lib/index.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /**
14
- * We export default configuration for webpack modules
15
- * Normally we load configuration from disk via filesystem
16
- * But webpack is bundlig all files into one.
17
- *
18
- * When we export, we can see configuration variable
19
- * in webpack module cache and webpack config loader can see it
20
- */
21
- __exportStar(require("./config/validation"), exports);
22
- __exportStar(require("./decorators"), exports);
23
- __exportStar(require("./exceptions"), exports);
24
- __exportStar(require("./validator"), exports);
25
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;GAOG;AACF,sDAAoC;AACrC,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B"}
package/lib/sources.d.ts DELETED
@@ -1,12 +0,0 @@
1
- interface ISchema {
2
- schema: any;
3
- file?: string;
4
- }
5
- export declare abstract class SchemaSource {
6
- abstract Load(): ISchema[];
7
- }
8
- export declare class FileSystemSource extends SchemaSource {
9
- SchemaDirs: string[];
10
- Load(): ISchema[];
11
- }
12
- export {};
package/lib/sources.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- };
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- var __metadata = (this && this.__metadata) || function (k, v) {
28
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.FileSystemSource = exports.SchemaSource = void 0;
32
- const lib_1 = require("@spinajs/configuration/lib");
33
- const di_1 = require("@spinajs/di");
34
- const log_1 = require("@spinajs/log/lib/log");
35
- const fs = __importStar(require("fs"));
36
- const glob = __importStar(require("glob"));
37
- const path = __importStar(require("path"));
38
- class SchemaSource {
39
- }
40
- exports.SchemaSource = SchemaSource;
41
- let FileSystemSource = class FileSystemSource extends SchemaSource {
42
- Load() {
43
- return this.SchemaDirs.filter(dir => fs.existsSync(dir))
44
- .flatMap((d) => glob.sync(path.join(d, "/**/*.+(json|js)")))
45
- .map(f => {
46
- log_1.Log.trace(`Found schema at: ${f}`, "validation");
47
- return {
48
- schema: require(f),
49
- file: path.basename(f)
50
- };
51
- });
52
- }
53
- };
54
- __decorate([
55
- (0, lib_1.Config)("system.dirs.schemas"),
56
- __metadata("design:type", Array)
57
- ], FileSystemSource.prototype, "SchemaDirs", void 0);
58
- FileSystemSource = __decorate([
59
- (0, di_1.Injectable)(SchemaSource)
60
- ], FileSystemSource);
61
- exports.FileSystemSource = FileSystemSource;
62
- //# sourceMappingURL=sources.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,oCAAyC;AACzC,8CAA2C;AAC3C,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA6B;AAO7B,MAAsB,YAAY;CAEjC;AAFD,oCAEC;AAGD,IAAa,gBAAgB,GAA7B,MAAa,gBAAiB,SAAQ,YAAY;IAKvC,IAAI;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;aACnD,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;aACnE,GAAG,CAAC,CAAC,CAAC,EAAE;YAEL,SAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;YAEjD,OAAO;gBACH,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;gBAClB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;aACzB,CAAC;QACN,CAAC,CAAC,CAAA;IACV,CAAC;CAEJ,CAAA;AAhBG;IADC,IAAA,YAAM,EAAC,qBAAqB,CAAC;;oDACF;AAHnB,gBAAgB;IAD5B,IAAA,eAAU,EAAC,YAAY,CAAC;GACZ,gBAAgB,CAmB5B;AAnBY,4CAAgB"}
@@ -1,52 +0,0 @@
1
- import { SyncModule, IContainer } from "@spinajs/di";
2
- import Ajv from "ajv";
3
- import { IValidationError } from "./exceptions";
4
- import { SchemaSource } from "./sources";
5
- export declare class DataValidator extends SyncModule {
6
- Options: any;
7
- protected Sources: SchemaSource[];
8
- protected Validator: Ajv;
9
- protected Container: IContainer;
10
- resolve(container: IContainer): void;
11
- addSchema(schemaObject: any, identifier: string): void;
12
- /**
13
- *
14
- * Checks if schema is loaded ( from file )
15
- *
16
- * @param schemaId schema id to check
17
- * @returns { boolean } true if schema is loaded, false otherwise
18
- */
19
- hasSchema(schemaId: string): boolean;
20
- /**
21
- * Tries to validate given data
22
- *
23
- * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
24
- * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
25
- * set in config validation.allErrors is set to false, only firs error is returned
26
- */
27
- tryValidate(data: any): [boolean, IValidationError[]];
28
- /**
29
- * Tries to validate given data
30
- *
31
- * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
32
- * @param {Any} data to be validated
33
- * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
34
- * set in config validation.allErrors is set to false, only firs error is returned
35
- */
36
- tryValidate(schema: object | string, data: any): [boolean, IValidationError[]];
37
- /**
38
- * Validate given data. When failed, exception is thrown
39
- *
40
- * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
41
- * @throws {InvalidArgument | ValidationFailed }
42
- */
43
- validate(data: any): void;
44
- /**
45
- * Validate given data
46
- *
47
- * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
48
- * @param {Any} data to be validated
49
- * @throws {InvalidArgumen | ValidationFailed }
50
- */
51
- validate(schema: object | string, data: any): void;
52
- }
package/lib/validator.js DELETED
@@ -1,150 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DataValidator = void 0;
16
- const di_1 = require("@spinajs/di");
17
- const ajv_1 = __importDefault(require("ajv"));
18
- const configuration_1 = require("@spinajs/configuration");
19
- const exceptions_1 = require("./exceptions");
20
- const exceptions_2 = require("@spinajs/exceptions");
21
- const decorators_1 = require("./decorators");
22
- const log_1 = require("@spinajs/log/lib/log");
23
- const sources_1 = require("./sources");
24
- class DataValidator extends di_1.SyncModule {
25
- resolve(container) {
26
- this.Sources = container.resolve(Array.ofType(sources_1.SchemaSource));
27
- if (!this.Sources || this.Sources.length === 0) {
28
- throw new exceptions_2.InvalidOperation("No schema sources avaible. Register any in DI container");
29
- }
30
- const ajvConfig = Object.assign({ logger: {
31
- log: (msg) => log_1.Log.info(msg, "validation"),
32
- warn: (msg) => log_1.Log.warn(msg, "validation"),
33
- error: (msg) => log_1.Log.error(msg, "validation")
34
- } }, this.Options);
35
- this.Validator = new ajv_1.default(ajvConfig);
36
- // add $merge & $patch for json schema
37
- require("ajv-merge-patch")(this.Validator);
38
- // add common formats validation eg: date time
39
- require("ajv-formats")(this.Validator);
40
- // add keywords
41
- require("ajv-keywords")(this.Validator);
42
- this.Sources.map(x => x.Load()).reduce((prev, curr) => {
43
- return prev.concat(curr);
44
- }, []).filter(s => {
45
- // validate schema can throw sometimes
46
- try {
47
- const vResult = this.Validator.validateSchema(s.schema, true);
48
- if (!vResult) {
49
- log_1.Log.error(`Schema at ${s.file} invalid`, "validator");
50
- return false;
51
- }
52
- return true;
53
- }
54
- catch (err) {
55
- log_1.Log.error(`Schema at ${s.file} invalid, reason: ${err.message}`, "validator");
56
- return false;
57
- }
58
- }).forEach(s => {
59
- this.addSchema(s.schema, s.schema.$id);
60
- });
61
- super.resolve(container);
62
- }
63
- addSchema(schemaObject, identifier) {
64
- if (!this.hasSchema(identifier)) {
65
- this.Validator.addSchema(schemaObject, identifier);
66
- log_1.Log.trace(`Schema ${identifier} added !`, "validator");
67
- }
68
- }
69
- /**
70
- *
71
- * Checks if schema is loaded ( from file )
72
- *
73
- * @param schemaId schema id to check
74
- * @returns { boolean } true if schema is loaded, false otherwise
75
- */
76
- hasSchema(schemaId) {
77
- return !!this.Validator.getSchema(schemaId);
78
- }
79
- tryValidate(schemaOrData, data) {
80
- var _a, _b;
81
- if (arguments.length === 1) {
82
- const schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
83
- if (!schema) {
84
- return [false, [{
85
- keyword: "empty_schema",
86
- instancePath: "./",
87
- schemaPath: "",
88
- params: { "data": "" }
89
- }]];
90
- }
91
- const result = this.Validator.validate(schema, schemaOrData);
92
- if (!result) {
93
- return [false, (_a = this.Validator.errors) !== null && _a !== void 0 ? _a : null];
94
- }
95
- }
96
- else {
97
- if (!data) {
98
- return [false, [{
99
- keyword: "invalid_argument",
100
- instancePath: "./",
101
- schemaPath: "",
102
- params: { "data": "" }
103
- }]];
104
- }
105
- let schema = null;
106
- if (typeof schemaOrData === "object") {
107
- schema = schemaOrData;
108
- }
109
- else if (typeof schemaOrData === 'string') {
110
- const s = this.Validator.getSchema(schemaOrData);
111
- schema = s === null || s === void 0 ? void 0 : s.schema;
112
- }
113
- else {
114
- schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
115
- }
116
- if (!schema) {
117
- return [false, [{
118
- keyword: "empty_schema",
119
- instancePath: "./",
120
- schemaPath: "",
121
- params: { "data": "" }
122
- }]];
123
- }
124
- const result = this.Validator.validate(schema, data);
125
- if (!result) {
126
- return [false, (_b = this.Validator.errors) !== null && _b !== void 0 ? _b : null];
127
- }
128
- }
129
- return [true, null];
130
- }
131
- validate(schemaOrData, data) {
132
- const [isValid, errors] = this.tryValidate(schemaOrData, data);
133
- if (!isValid) {
134
- switch (errors[0].keyword) {
135
- case "invalid_argument":
136
- throw new exceptions_2.InvalidArgument("data is null or undefined");
137
- case "empty_schema":
138
- throw new exceptions_2.InvalidArgument("objects schema is not set");
139
- default:
140
- throw new exceptions_1.ValidationFailed("validation error", errors);
141
- }
142
- }
143
- }
144
- }
145
- __decorate([
146
- (0, configuration_1.Config)("validation"),
147
- __metadata("design:type", Object)
148
- ], DataValidator.prototype, "Options", void 0);
149
- exports.DataValidator = DataValidator;
150
- //# sourceMappingURL=validator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oCAAqD;AACrD,8CAAsB;AACtB,0DAAgD;AAChD,6CAAkE;AAClE,oDAAwE;AACxE,6CAA6C;AAC7C,8CAA2C;AAC3C,uCAAyC;AAEzC,MAAa,aAAc,SAAQ,eAAU;IAWlC,OAAO,CAAC,SAAqB;QAEhC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,sBAAY,CAAC,CAAC,CAAC;QAE7D,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5C,MAAM,IAAI,6BAAgB,CAAC,yDAAyD,CAAC,CAAC;SACzF;QAED,MAAM,SAAS,mBACX,MAAM,EAAE;gBACJ,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAG,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC;gBACjD,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAG,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC;gBAClD,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAG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