@spinajs/validation 1.0.0 → 1.1.2

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.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path_1 = require("path");
4
4
  function dir(path) {
5
- return path_1.resolve(path_1.normalize(path_1.join(__dirname, path)));
5
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
6
  }
7
7
  module.exports = {
8
8
  system: {
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/config/validation.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACrB,OAAO,cAAO,CAAC,gBAAS,CAAC,WAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACb,MAAM,EAAE;QACJ,IAAI,EAAE;YACF,OAAO,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;SACjC;KACJ;IACD,UAAU,EAAE;QAER,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"}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/config/validation.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACrB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACb,MAAM,EAAE;QACJ,IAAI,EAAE;YACF,OAAO,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;SACjC;KACJ;IACD,UAAU,EAAE;QAER,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"}
package/lib/index.d.ts CHANGED
@@ -1,44 +1,3 @@
1
- import { AsyncModule, IContainer } from "@spinajs/di";
2
- import Ajv from "ajv";
3
- import { Configuration } from "@spinajs/configuration";
4
- import { Log } from "@spinajs/log";
5
- import { ValidationError } from "./exceptions";
6
- export declare class DataValidator extends AsyncModule {
7
- protected Validator: Ajv.Ajv;
8
- protected Configuration: Configuration;
9
- protected Container: IContainer;
10
- protected Log: Log;
11
- resolveAsync(container: IContainer): Promise<void>;
12
- /**
13
- * Tries to validate given data
14
- *
15
- * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
16
- * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
17
- * set in config validation.allErrors is set to false, only firs error is returned
18
- */
19
- tryValidate(data: any): [boolean, ValidationError[]];
20
- /**
21
- * Tries to validate given data
22
- *
23
- * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
24
- * @param {Any} data to be validated
25
- * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
26
- * set in config validation.allErrors is set to false, only firs error is returned
27
- */
28
- tryValidate(schema: object | string | boolean, data: any): [boolean, ValidationError[]];
29
- /**
30
- * Validate given data. When failed, exception is thrown
31
- *
32
- * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
33
- * @throws {InvalidArgumen | ValidationFailed }
34
- */
35
- validate(data: any): void;
36
- /**
37
- * Validate given data
38
- *
39
- * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
40
- * @param {Any} data to be validated
41
- * @throws {InvalidArgumen | ValidationFailed }
42
- */
43
- validate(schema: object | string | boolean, data: any): void;
44
- }
1
+ export * from "./decorators";
2
+ export * from "./exceptions";
3
+ export * from "./validator";
package/lib/index.js CHANGED
@@ -6,130 +6,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6
6
  if (k2 === undefined) k2 = k;
7
7
  o[k2] = m[k];
8
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.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
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
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);
32
11
  };
33
12
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.DataValidator = void 0;
35
- const di_1 = require("@spinajs/di");
36
- const ajv_1 = __importDefault(require("ajv"));
37
- const configuration_1 = require("@spinajs/configuration");
38
- const fs = __importStar(require("fs"));
39
- const glob = __importStar(require("glob"));
40
- const path = __importStar(require("path"));
41
- const log_1 = require("@spinajs/log");
42
- const exceptions_1 = require("./exceptions");
43
- const exceptions_2 = require("@spinajs/exceptions");
44
- const decorators_1 = require("./decorators");
45
- class DataValidator extends di_1.AsyncModule {
46
- async resolveAsync(container) {
47
- this.Configuration = await container.resolve(configuration_1.Configuration);
48
- this.Container = container;
49
- const ajvConfig = Object.assign({ logger: {
50
- log: this.Log.info.bind(this.Log),
51
- warn: this.Log.warn.bind(this.Log),
52
- error: this.Log.error.bind(this.Log)
53
- } }, this.Configuration.get("validation"));
54
- this.Validator = new ajv_1.default(ajvConfig);
55
- // add $merge & $patch for json schema
56
- require("ajv-merge-patch")(this.Validator);
57
- // add common formats validation eg: date time
58
- require("ajv-formats")(this.Validator);
59
- // add keywords
60
- require("ajv-keywords")(this.Validator);
61
- this.Configuration.get("system.dirs.schemas", [])
62
- .filter(dir => fs.existsSync(dir))
63
- .flatMap((d) => glob.sync(path.join(d, "*.json")))
64
- .map(f => {
65
- return {
66
- schema: require(f),
67
- file: path.basename(f)
68
- };
69
- })
70
- .filter(s => {
71
- const isValid = this.Validator.validateSchema(s.schema);
72
- if (!isValid) {
73
- this.Log.warn(`Schema is not valid %s`, s.file);
74
- return false;
75
- }
76
- return true;
77
- })
78
- .forEach(s => {
79
- var _a;
80
- const schemaId = (_a = s.schema.$id) !== null && _a !== void 0 ? _a : path.basename(s.file);
81
- this.Log.trace(`Added schema ${schemaId}`);
82
- this.Validator.addSchema(s.schema, schemaId);
83
- });
84
- }
85
- tryValidate(schemaOrData, data) {
86
- if (arguments.length === 1) {
87
- const schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
88
- if (!schema) {
89
- return [false, [{
90
- keyword: "empty_schema",
91
- dataPath: "data",
92
- schemaPath: "",
93
- params: "data"
94
- }]];
95
- }
96
- const result = this.Validator.validate(schema, schemaOrData);
97
- if (!result) {
98
- return [false, this.Validator.errors];
99
- }
100
- }
101
- else {
102
- if (!data) {
103
- return [false, [{
104
- keyword: "invalid_argument",
105
- dataPath: "data",
106
- schemaPath: "",
107
- params: "data"
108
- }]];
109
- }
110
- const result = this.Validator.validate(schemaOrData, data);
111
- if (!result) {
112
- return [false, this.Validator.errors];
113
- }
114
- }
115
- }
116
- validate(schemaOrData, data) {
117
- const [isValid, errors] = this.tryValidate(schemaOrData, data);
118
- if (!isValid) {
119
- switch (errors[0].keyword) {
120
- case "invalid_argument":
121
- throw new exceptions_2.InvalidArgument("data is null or undefined");
122
- case "empty_schema":
123
- throw new exceptions_2.InvalidArgument("objects schema is not set");
124
- default:
125
- throw new exceptions_1.ValidationFailed("validation error", errors);
126
- }
127
- }
128
- }
129
- }
130
- __decorate([
131
- log_1.Logger(),
132
- __metadata("design:type", Object)
133
- ], DataValidator.prototype, "Log", void 0);
134
- exports.DataValidator = DataValidator;
13
+ __exportStar(require("./decorators"), exports);
14
+ __exportStar(require("./exceptions"), exports);
15
+ __exportStar(require("./validator"), exports);
135
16
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAsD;AACtD,8CAAsB;AACtB,0DAAuD;AACvD,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA6B;AAC7B,sCAA2C;AAC3C,6CAAiE;AACjE,oDAAsD;AACtD,6CAA6C;AAE7C,MAAa,aAAc,SAAQ,gBAAW;IAWnC,KAAK,CAAC,YAAY,CAAC,SAAqB;QAE3C,IAAI,CAAC,aAAa,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,6BAAa,CAAC,CAAC;QAC5D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,MAAM,SAAS,mBACX,MAAM,EAAE;gBACJ,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAA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EAAE,MAAM;yBACjB,CAAC,CAAC,CAAA;aACN;YAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,EAAE;gBACT,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;aACxC;SACJ;IAGL,CAAC;IAkBM,QAAQ,CAAC,YAAuC,EAAE,IAAU;QAC/D,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,EAAE;YACV,QAAQ,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;gBACvB,KAAK,kBAAkB;oBACnB,MAAM,IAAI,4BAAe,CAAC,2BAA2B,CAAC,CAAC;gBAC3D,KAAK,cAAc;oBACf,MAAM,IAAI,4BAAe,CAAC,2BAA2B,CAAC,CAAC;gBAC3D;oBACI,MAAM,IAAI,6BAAgB,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;aAE9D;SACJ;IACL,CAAC;CACJ;AA5IG;IADC,YAAM,EAAE;;0CACU;AATvB,sCAqJC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
+ }
7
+ module.exports = {
8
+ system: {
9
+ dirs: {
10
+ schemas: [dir('./../schemas')],
11
+ }
12
+ },
13
+ validation: {
14
+ // enable all errors on validation, not only first one that occurred
15
+ allErrors: true,
16
+ // remove properties that are not defined in schema
17
+ removeAdditional: true,
18
+ // set default values if possible
19
+ useDefaults: true,
20
+ // The option coerceTypes allows you to have your data types coerced to the types specified in your schema type keywords
21
+ coerceTypes: true
22
+ }
23
+ };
24
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/config/validation.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACrB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACb,MAAM,EAAE;QACJ,IAAI,EAAE;YACF,OAAO,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;SACjC;KACJ;IACD,UAAU,EAAE;QAER,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"}
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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: ValidationError[]);
9
+ }
10
+ export interface ValidationError extends ErrorObject {
11
+ }
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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,gBAAmC;QAC9D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC;IACpC,CAAC;CACF;AAPF,4CAOE"}
@@ -0,0 +1,3 @@
1
+ export * from "./decorators";
2
+ export * from "./exceptions";
3
+ export * from "./validator";
@@ -0,0 +1,16 @@
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
+ __exportStar(require("./decorators"), exports);
14
+ __exportStar(require("./exceptions"), exports);
15
+ __exportStar(require("./validator"), exports);
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,8CAA4B"}
@@ -0,0 +1,52 @@
1
+ import { SyncModule, IContainer } from "@spinajs/di";
2
+ import Ajv from "ajv";
3
+ import { Configuration } from "@spinajs/configuration";
4
+ import { ValidationError } from "./exceptions";
5
+ export declare class DataValidator extends SyncModule {
6
+ Options: any;
7
+ SchemaDirs: string[];
8
+ protected Validator: Ajv;
9
+ protected Configuration: Configuration;
10
+ protected Container: IContainer;
11
+ resolve(container: IContainer): 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, ValidationError[]];
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, ValidationError[]];
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
+ }
@@ -0,0 +1,177 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.DataValidator = void 0;
35
+ const di_1 = require("@spinajs/di");
36
+ const ajv_1 = __importDefault(require("ajv"));
37
+ const configuration_1 = require("@spinajs/configuration");
38
+ const fs = __importStar(require("fs"));
39
+ const glob = __importStar(require("glob"));
40
+ const path = __importStar(require("path"));
41
+ const exceptions_1 = require("./exceptions");
42
+ const exceptions_2 = require("@spinajs/exceptions");
43
+ const decorators_1 = require("./decorators");
44
+ const log_1 = require("@spinajs/log");
45
+ class DataValidator extends di_1.SyncModule {
46
+ resolve(container) {
47
+ this.Container = container;
48
+ const ajvConfig = Object.assign({ logger: {
49
+ log: (msg) => log_1.Log.info(msg, "validation"),
50
+ warn: (msg) => log_1.Log.warn(msg, "validation"),
51
+ error: (msg) => log_1.Log.error(msg, "validation")
52
+ } }, this.Options);
53
+ this.Validator = new ajv_1.default(ajvConfig);
54
+ // add $merge & $patch for json schema
55
+ require("ajv-merge-patch")(this.Validator);
56
+ // add common formats validation eg: date time
57
+ require("ajv-formats")(this.Validator);
58
+ // add keywords
59
+ require("ajv-keywords")(this.Validator);
60
+ this.SchemaDirs.filter(dir => fs.existsSync(dir))
61
+ .flatMap((d) => glob.sync(path.join(d, "/**/*.+(json|js)")))
62
+ .map(f => {
63
+ log_1.Log.trace(`Found schema at: ${f}`, "validation");
64
+ return {
65
+ schema: require(f),
66
+ file: path.basename(f)
67
+ };
68
+ })
69
+ .filter(s => {
70
+ // validate schema can throw sometimes
71
+ try {
72
+ const vResult = this.Validator.validateSchema(s.schema, true);
73
+ if (!vResult) {
74
+ log_1.Log.error(`Schema at ${s.file} invalid`, "validator");
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+ catch (err) {
80
+ log_1.Log.error(`Schema at ${s.file} invalid, reason: ${err.message}`, "validator");
81
+ return false;
82
+ }
83
+ })
84
+ .forEach(s => {
85
+ var _a, _b;
86
+ const schemaName = (_a = s.schema.$id) !== null && _a !== void 0 ? _a : path.basename(s.file);
87
+ this.Validator.addSchema(s.schema, (_b = s.schema.$id) !== null && _b !== void 0 ? _b : path.basename(s.file));
88
+ log_1.Log.info(`Schema ${schemaName} added !`, "validator");
89
+ });
90
+ super.resolve(container);
91
+ }
92
+ /**
93
+ *
94
+ * Checks if schema is loaded ( from file )
95
+ *
96
+ * @param schemaId schema id to check
97
+ * @returns { boolean } true if schema is loaded, false otherwise
98
+ */
99
+ hasSchema(schemaId) {
100
+ return !!this.Validator.getSchema(schemaId);
101
+ }
102
+ tryValidate(schemaOrData, data) {
103
+ var _a, _b;
104
+ if (arguments.length === 1) {
105
+ const schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
106
+ if (!schema) {
107
+ return [false, [{
108
+ keyword: "empty_schema",
109
+ instancePath: "./",
110
+ schemaPath: "",
111
+ params: { "data": "" }
112
+ }]];
113
+ }
114
+ const result = this.Validator.validate(schema, schemaOrData);
115
+ if (!result) {
116
+ return [false, (_a = this.Validator.errors) !== null && _a !== void 0 ? _a : null];
117
+ }
118
+ }
119
+ else {
120
+ if (!data) {
121
+ return [false, [{
122
+ keyword: "invalid_argument",
123
+ instancePath: "./",
124
+ schemaPath: "",
125
+ params: { "data": "" }
126
+ }]];
127
+ }
128
+ let schema = null;
129
+ if (typeof schemaOrData === "object") {
130
+ schema = schemaOrData;
131
+ }
132
+ else if (typeof schemaOrData === 'string') {
133
+ const s = this.Validator.getSchema(schemaOrData);
134
+ schema = s === null || s === void 0 ? void 0 : s.schema;
135
+ }
136
+ else {
137
+ schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
138
+ }
139
+ if (!schema) {
140
+ return [false, [{
141
+ keyword: "empty_schema",
142
+ instancePath: "./",
143
+ schemaPath: "",
144
+ params: { "data": "" }
145
+ }]];
146
+ }
147
+ const result = this.Validator.validate(schema, data);
148
+ if (!result) {
149
+ return [false, (_b = this.Validator.errors) !== null && _b !== void 0 ? _b : null];
150
+ }
151
+ }
152
+ return [true, null];
153
+ }
154
+ validate(schemaOrData, data) {
155
+ const [isValid, errors] = this.tryValidate(schemaOrData, data);
156
+ if (!isValid) {
157
+ switch (errors[0].keyword) {
158
+ case "invalid_argument":
159
+ throw new exceptions_2.InvalidArgument("data is null or undefined");
160
+ case "empty_schema":
161
+ throw new exceptions_2.InvalidArgument("objects schema is not set");
162
+ default:
163
+ throw new exceptions_1.ValidationFailed("validation error", errors);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ __decorate([
169
+ (0, configuration_1.Config)("validation"),
170
+ __metadata("design:type", Object)
171
+ ], DataValidator.prototype, "Options", void 0);
172
+ __decorate([
173
+ (0, configuration_1.Config)("system.dirs.schemas"),
174
+ __metadata("design:type", Array)
175
+ ], DataValidator.prototype, "SchemaDirs", void 0);
176
+ exports.DataValidator = DataValidator;
177
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAqD;AACrD,8CAAsB;AACtB,0DAA+D;AAC/D,uCAAyB;AACzB,2CAA6B;AAC7B,2CA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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 __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("mocha");
13
+ const di_1 = require("@spinajs/di");
14
+ const configuration_1 = require("@spinajs/configuration");
15
+ const sinon_1 = __importDefault(require("sinon"));
16
+ const chai_1 = require("chai");
17
+ const lodash_1 = __importDefault(require("lodash"));
18
+ const path_1 = require("path");
19
+ const validator_1 = require("../src/validator");
20
+ const src_1 = require("../src");
21
+ function dir(path) {
22
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
23
+ }
24
+ class TestConfiguration extends configuration_1.FrameworkConfiguration {
25
+ async resolveAsync(container) {
26
+ await super.resolveAsync(container);
27
+ lodash_1.default.merge(this.Config, {
28
+ system: {
29
+ dirs: {
30
+ schemas: [dir('./../test/schemas')],
31
+ }
32
+ },
33
+ validation: {
34
+ // enable all errors on validation, not only first one that occurred
35
+ allErrors: true,
36
+ // remove properties that are not defined in schema
37
+ removeAdditional: true,
38
+ // set default values if possible
39
+ useDefaults: true,
40
+ // The option coerceTypes allows you to have your data types coerced to the types specified in your schema type keywords
41
+ coerceTypes: true
42
+ }
43
+ });
44
+ }
45
+ }
46
+ function val() {
47
+ return di_1.DI.resolve(validator_1.DataValidator);
48
+ }
49
+ describe("validator tests", function () {
50
+ this.timeout(15000);
51
+ before(async () => {
52
+ di_1.DI.clearCache();
53
+ di_1.DI.register(TestConfiguration).as(configuration_1.Configuration);
54
+ await di_1.DI.resolve(configuration_1.Configuration);
55
+ });
56
+ afterEach(() => {
57
+ sinon_1.default.restore();
58
+ });
59
+ it("should resolve validator", async () => {
60
+ const v = val();
61
+ (0, chai_1.expect)(v).to.be.not.null;
62
+ });
63
+ it("should load schemas from json and js files", async () => {
64
+ const v = val();
65
+ (0, chai_1.expect)(v.hasSchema("http://spinajs/example_js.schema.js")).to.be.true;
66
+ (0, chai_1.expect)(v.hasSchema("http://spinajs/example_json.schema.json")).to.be.true;
67
+ });
68
+ it("should try to validate object with schema from file", async () => {
69
+ const v = val();
70
+ const [result, errors] = v.tryValidate("http://spinajs/example_json.schema.json", {
71
+ productId: 1
72
+ });
73
+ (0, chai_1.expect)(result).to.be.true;
74
+ (0, chai_1.expect)(errors).to.be.null;
75
+ });
76
+ it("should validate object with schema from file", async () => {
77
+ const v = val();
78
+ const func = () => v.validate("http://spinajs/example_json.schema.json", {
79
+ productId: 1
80
+ });
81
+ (0, chai_1.expect)(func).not.to.throw;
82
+ });
83
+ it("should validate object with schema from decorator", async () => {
84
+ let foo = class foo {
85
+ };
86
+ foo = __decorate([
87
+ (0, src_1.Schema)({
88
+ properties: {
89
+ foo: { type: "string" }
90
+ }
91
+ })
92
+ ], foo);
93
+ const data = new foo();
94
+ data.foo = "test";
95
+ const v = val();
96
+ const [result, errors] = v.tryValidate(data);
97
+ (0, chai_1.expect)(result).to.be.true;
98
+ (0, chai_1.expect)(errors).to.be.null;
99
+ });
100
+ it("Should valide object with schema name from decorator", async () => {
101
+ let foo = class foo {
102
+ };
103
+ foo = __decorate([
104
+ (0, src_1.Schema)("http://spinajs/example_json.schema.json")
105
+ ], foo);
106
+ const data = new foo();
107
+ data.productId = 1;
108
+ const v = val();
109
+ const [result, errors] = v.tryValidate(data);
110
+ (0, chai_1.expect)(result).to.be.true;
111
+ (0, chai_1.expect)(errors).to.be.null;
112
+ });
113
+ it("trying to validate shouhld fail with proper error", async () => {
114
+ const v = val();
115
+ const [result, errors] = v.tryValidate("http://spinajs/example_json.schema.json", {
116
+ productId: "dasdas"
117
+ });
118
+ (0, chai_1.expect)(result).to.be.false;
119
+ (0, chai_1.expect)(errors).to.be.not.null;
120
+ (0, chai_1.expect)(errors).to.be.an("array").to.have.deep.members([{
121
+ instancePath: '/productId',
122
+ keyword: 'type',
123
+ message: 'must be integer',
124
+ schemaPath: '#/properties/productId/type',
125
+ params: {
126
+ type: "integer"
127
+ }
128
+ }]);
129
+ });
130
+ it("validate should throw on invalid data", async () => {
131
+ const v = val();
132
+ const func = () => v.validate("http://spinajs/example_json.schema.json", {
133
+ productId: "sss"
134
+ });
135
+ (0, chai_1.expect)(func).to.throw("validation error");
136
+ });
137
+ });
138
+ //# sourceMappingURL=validator.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.test.js","sourceRoot":"","sources":["../../test/validator.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iBAAe;AACf,oCAA6C;AAC7C,0DAA+E;AAC/E,kDAA0B;AAC1B,+BAA8B;AAC9B,oDAAuB;AACvB,+BAAgD;AAChD,gDAAiD;AACjD,gCAAgC;AAEhC,SAAS,GAAG,CAAC,IAAY;IACrB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAGD,MAAM,iBAAkB,SAAQ,sCAAsB;IAE3C,KAAK,CAAC,YAAY,CAAC,SAAqB;QAC3C,MAAM,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAEpC,gBAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE;gBACJ,IAAI,EAAE;oBACF,OAAO,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;iBACtC;aACJ;YACD,UAAU,EAAE;gBAER,qEAAqE;gBACrE,SAAS,EAAE,IAAI;gBAEf,mDAAmD;gBACnD,gBAAgB,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C1B,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,iBAAiB;gBAC1B,UAAU,EAAC,6BAA6B;gBACxC,MAAM,EAAE;oBACJ,IAAI,EAAE,SAAS;iBAClB;aACJ,CAAC,CAAC,CAAC;IAER,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QAEnD,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC;QAEhB,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,yCAAyC,EAAE;YACrE,SAAS,EAAE,KAAK;SACnB,CAAC,CAAC;QAEH,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAE9C,CAAC,CAAC,CAAA;AAEN,CAAC,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { SyncModule, IContainer } from "@spinajs/di";
2
+ import Ajv from "ajv";
3
+ import { Configuration } from "@spinajs/configuration";
4
+ import { ValidationError } from "./exceptions";
5
+ export declare class DataValidator extends SyncModule {
6
+ Options: any;
7
+ SchemaDirs: string[];
8
+ protected Validator: Ajv;
9
+ protected Configuration: Configuration;
10
+ protected Container: IContainer;
11
+ resolve(container: IContainer): void;
12
+ /**
13
+ * Tries to validate given data
14
+ *
15
+ * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
16
+ * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
17
+ * set in config validation.allErrors is set to false, only firs error is returned
18
+ */
19
+ tryValidate(data: any): [boolean, ValidationError[]];
20
+ /**
21
+ * Tries to validate given data
22
+ *
23
+ * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
24
+ * @param {Any} data to be validated
25
+ * @return { array : [boolean, ValidationError[]]} [0] true if data is valid, false otherwise, [1] list of all errors. If
26
+ * set in config validation.allErrors is set to false, only firs error is returned
27
+ */
28
+ tryValidate(schema: object | string, data: any): [boolean, ValidationError[]];
29
+ /**
30
+ * Validate given data. When failed, exception is thrown
31
+ *
32
+ * @param data data to validate. Function will try to extract schema attached to object via @Schema decorator
33
+ * @throws {InvalidArgument | ValidationFailed }
34
+ */
35
+ validate(data: any): void;
36
+ /**
37
+ * Validate given data
38
+ *
39
+ * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
40
+ * @param {Any} data to be validated
41
+ * @throws {InvalidArgumen | ValidationFailed }
42
+ */
43
+ validate(schema: object | string, data: any): void;
44
+ }
@@ -0,0 +1,139 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.DataValidator = void 0;
35
+ const di_1 = require("@spinajs/di");
36
+ const ajv_1 = __importDefault(require("ajv"));
37
+ const configuration_1 = require("@spinajs/configuration");
38
+ const fs = __importStar(require("fs"));
39
+ const glob = __importStar(require("glob"));
40
+ const path = __importStar(require("path"));
41
+ const exceptions_1 = require("./exceptions");
42
+ const exceptions_2 = require("@spinajs/exceptions");
43
+ const decorators_1 = require("./decorators");
44
+ class DataValidator extends di_1.SyncModule {
45
+ resolve(container) {
46
+ this.Container = container;
47
+ this.Validator = new ajv_1.default(this.Options);
48
+ // add $merge & $patch for json schema
49
+ require("ajv-merge-patch")(this.Validator);
50
+ // add common formats validation eg: date time
51
+ require("ajv-formats")(this.Validator);
52
+ // add keywords
53
+ require("ajv-keywords")(this.Validator);
54
+ this.SchemaDirs.filter(dir => fs.existsSync(dir))
55
+ .flatMap((d) => glob.sync(path.join(d, "/**/*.+(json|js)")))
56
+ .map(f => {
57
+ return {
58
+ schema: require(f),
59
+ file: path.basename(f)
60
+ };
61
+ })
62
+ .filter(s => this.Validator.validateSchema(s.schema))
63
+ .forEach(s => { var _a; return this.Validator.addSchema(s.schema, (_a = s.schema.$id) !== null && _a !== void 0 ? _a : path.basename(s.file)); });
64
+ }
65
+ tryValidate(schemaOrData, data) {
66
+ if (arguments.length === 1) {
67
+ const schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
68
+ if (!schema) {
69
+ return [false, [{
70
+ keyword: "empty_schema",
71
+ instancePath: "./",
72
+ schemaPath: "",
73
+ params: { "data": "" }
74
+ }]];
75
+ }
76
+ const result = this.Validator.validate(schema, schemaOrData);
77
+ if (!result) {
78
+ return [false, this.Validator.errors];
79
+ }
80
+ }
81
+ else {
82
+ if (!data) {
83
+ return [false, [{
84
+ keyword: "invalid_argument",
85
+ instancePath: "./",
86
+ schemaPath: "",
87
+ params: { "data": "" }
88
+ }]];
89
+ }
90
+ let schema = null;
91
+ if (typeof schemaOrData === "object") {
92
+ schema = schemaOrData;
93
+ }
94
+ else if (typeof schemaOrData === 'string') {
95
+ const s = this.Validator.getSchema(schemaOrData);
96
+ schema = s === null || s === void 0 ? void 0 : s.schema;
97
+ }
98
+ else {
99
+ schema = Reflect.getMetadata(decorators_1.SCHEMA_SYMBOL, schemaOrData);
100
+ }
101
+ if (!schema) {
102
+ return [false, [{
103
+ keyword: "empty_schema",
104
+ instancePath: "./",
105
+ schemaPath: "",
106
+ params: { "data": "" }
107
+ }]];
108
+ }
109
+ const result = this.Validator.validate(schema, data);
110
+ if (!result) {
111
+ return [false, this.Validator.errors];
112
+ }
113
+ }
114
+ return [true, undefined];
115
+ }
116
+ validate(schemaOrData, data) {
117
+ const [isValid, errors] = this.tryValidate(schemaOrData, data);
118
+ if (!isValid) {
119
+ switch (errors[0].keyword) {
120
+ case "invalid_argument":
121
+ throw new exceptions_2.InvalidArgument("data is null or undefined");
122
+ case "empty_schema":
123
+ throw new exceptions_2.InvalidArgument("objects schema is not set");
124
+ default:
125
+ throw new exceptions_1.ValidationFailed("validation error", errors);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ __decorate([
131
+ (0, configuration_1.Config)("validation"),
132
+ __metadata("design:type", Object)
133
+ ], DataValidator.prototype, "Options", void 0);
134
+ __decorate([
135
+ (0, configuration_1.Config)("system.dirs.schemas"),
136
+ __metadata("design:type", Array)
137
+ ], DataValidator.prototype, "SchemaDirs", void 0);
138
+ exports.DataValidator = DataValidator;
139
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA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1.0.0",
3
+ "version": "1.1.2",
4
4
  "description": "validation library for spinajs framework",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -36,14 +36,14 @@
36
36
  },
37
37
  "homepage": "https://github.com/spinajs/validation#readme",
38
38
  "dependencies": {
39
- "@spinajs/configuration": "^1.0.16",
40
- "@spinajs/di": "^1.1.0",
41
- "@spinajs/exceptions": "^1.0.4",
42
- "@spinajs/log": "^1.0.10",
43
- "ajv": "^6.12.2",
39
+ "@spinajs/configuration": "^1.1.2",
40
+ "@spinajs/di": "^1.1.7",
41
+ "@spinajs/exceptions": "^1.0.5",
42
+ "@spinajs/log": "^1.1.0",
43
+ "ajv": "^8.8.2",
44
44
  "ajv-formats": "^2.1.1",
45
45
  "ajv-keywords": "^5.1.0",
46
- "ajv-merge-patch": "^4.1.0"
46
+ "ajv-merge-patch": "^5.0.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/bunyan": "^1.8.6",
@@ -55,6 +55,7 @@
55
55
  "@types/cors": "^2.8.6",
56
56
  "@types/express": "^4.17.6",
57
57
  "@types/formidable": "^1.0.31",
58
+ "@types/glob": "^7.2.0",
58
59
  "@types/helmet": "^0.0.47",
59
60
  "@types/lodash": "^4.14.136",
60
61
  "@types/luxon": "^2.0.8",
@@ -82,6 +83,6 @@
82
83
  "tslint-config-standard": "^8.0.1",
83
84
  "tslint-no-unused-expression-chai": "^0.1.4",
84
85
  "typedoc": "^0.14.2",
85
- "typescript": "^3.7.3"
86
+ "typescript": "^4.2.3"
86
87
  }
87
88
  }