@spinajs/validation 2.0.179 → 2.0.181
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/lib/cjs/bootstrap.d.ts +4 -4
- package/lib/cjs/bootstrap.js +23 -23
- package/lib/cjs/bootstrap.js.map +1 -1
- package/lib/cjs/config/validation.d.ts +9 -9
- package/lib/cjs/config/validation.js +15 -15
- package/lib/cjs/decorators.d.ts +8 -8
- package/lib/cjs/decorators.js +16 -16
- package/lib/cjs/exceptions/index.d.ts +11 -11
- package/lib/cjs/exceptions/index.js +14 -14
- package/lib/cjs/index.d.ts +13 -13
- package/lib/cjs/index.js +34 -34
- package/lib/cjs/schemas/validation.d.ts +21 -21
- package/lib/cjs/schemas/validation.js +15 -15
- package/lib/cjs/sources.d.ts +13 -13
- package/lib/cjs/sources.js +92 -93
- package/lib/cjs/sources.js.map +1 -1
- package/lib/cjs/types.d.ts +17 -17
- package/lib/cjs/types.js +6 -6
- package/lib/cjs/validator.d.ts +61 -61
- package/lib/cjs/validator.js +164 -164
- package/lib/cjs/validator.js.map +1 -1
- package/lib/mjs/bootstrap.d.ts +4 -4
- package/lib/mjs/bootstrap.js +17 -17
- package/lib/mjs/bootstrap.js.map +1 -1
- package/lib/mjs/config/validation.d.ts +9 -9
- package/lib/mjs/config/validation.js +13 -13
- package/lib/mjs/decorators.d.ts +8 -8
- package/lib/mjs/decorators.js +12 -12
- package/lib/mjs/exceptions/index.d.ts +11 -11
- package/lib/mjs/exceptions/index.js +10 -10
- package/lib/mjs/index.d.ts +13 -13
- package/lib/mjs/index.js +13 -13
- package/lib/mjs/schemas/validation.d.ts +21 -21
- package/lib/mjs/schemas/validation.js +13 -13
- package/lib/mjs/sources.d.ts +13 -13
- package/lib/mjs/sources.js +63 -63
- package/lib/mjs/sources.js.map +1 -1
- package/lib/mjs/types.d.ts +17 -17
- package/lib/mjs/types.js +2 -2
- package/lib/mjs/validator.d.ts +61 -61
- package/lib/mjs/validator.js +158 -158
- package/lib/mjs/validator.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export interface ISchema {
|
|
2
|
-
schema: ISchemaObject;
|
|
3
|
-
file?: string;
|
|
4
|
-
}
|
|
5
|
-
export interface ISchemaObject {
|
|
6
|
-
$id: string;
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class SchemaSource {
|
|
10
|
-
abstract Load(): Promise<ISchema[]>;
|
|
11
|
-
}
|
|
12
|
-
export interface IValidationOptions {
|
|
13
|
-
allErrors: boolean;
|
|
14
|
-
removeAdditional: boolean;
|
|
15
|
-
useDefaults: boolean;
|
|
16
|
-
coerceTypes: boolean;
|
|
17
|
-
}
|
|
1
|
+
export interface ISchema {
|
|
2
|
+
schema: ISchemaObject;
|
|
3
|
+
file?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ISchemaObject {
|
|
6
|
+
$id: string;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class SchemaSource {
|
|
10
|
+
abstract Load(): Promise<ISchema[]>;
|
|
11
|
+
}
|
|
12
|
+
export interface IValidationOptions {
|
|
13
|
+
allErrors: boolean;
|
|
14
|
+
removeAdditional: boolean;
|
|
15
|
+
useDefaults: boolean;
|
|
16
|
+
coerceTypes: boolean;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/cjs/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaSource = void 0;
|
|
4
|
-
class SchemaSource {
|
|
5
|
-
}
|
|
6
|
-
exports.SchemaSource = SchemaSource;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaSource = void 0;
|
|
4
|
+
class SchemaSource {
|
|
5
|
+
}
|
|
6
|
+
exports.SchemaSource = SchemaSource;
|
|
7
7
|
//# sourceMappingURL=types.js.map
|
package/lib/cjs/validator.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { Container, AsyncService } from '@spinajs/di';
|
|
2
|
-
import { IValidationError } from './exceptions/index.js';
|
|
3
|
-
import { IValidationOptions, SchemaSource, ISchemaObject } from './types.js';
|
|
4
|
-
import { Log } from '@spinajs/log-common';
|
|
5
|
-
import './sources.js';
|
|
6
|
-
/**
|
|
7
|
-
* HACK:
|
|
8
|
-
* Becouse of ajv not supporting esm default exports we need to
|
|
9
|
-
* check for default export module property and if not provided use module itself
|
|
10
|
-
*/
|
|
11
|
-
export declare class DataValidator extends AsyncService {
|
|
12
|
-
Options: IValidationOptions;
|
|
13
|
-
protected Sources: SchemaSource[];
|
|
14
|
-
protected Log: Log;
|
|
15
|
-
/**
|
|
16
|
-
* We ignore this error because ajv have problems with
|
|
17
|
-
* commonjs / esm default exports
|
|
18
|
-
*/
|
|
19
|
-
protected Validator: any;
|
|
20
|
-
protected Container: Container;
|
|
21
|
-
resolve(): Promise<void>;
|
|
22
|
-
addSchema(schemaObject: object, identifier: string): void;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* Checks if schema is loaded ( from file )
|
|
26
|
-
*
|
|
27
|
-
* @param schemaId - schema id to check
|
|
28
|
-
* @returns true if schema is loaded, false otherwise
|
|
29
|
-
*/
|
|
30
|
-
hasSchema(schemaId: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Tries to validate given data
|
|
33
|
-
*
|
|
34
|
-
* @param data - data to validate. Function will try to extract schema attached to object via `@Schema` decorator
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
tryValidate(data: object): [boolean, IValidationError[]];
|
|
38
|
-
/**
|
|
39
|
-
* Tries to validate given data
|
|
40
|
-
*
|
|
41
|
-
* @param schemaKeyRef - key, ref or schema object
|
|
42
|
-
* @param data - to be validated
|
|
43
|
-
*/
|
|
44
|
-
tryValidate(schema: object | string, data: object): [boolean, IValidationError[]];
|
|
45
|
-
extractSchema(object: unknown): ISchemaObject;
|
|
46
|
-
/**
|
|
47
|
-
* Validate given data. When failed, exception is thrown
|
|
48
|
-
*s
|
|
49
|
-
* @param data - data to validate. Function will try to extract schema attached to object via `@Schema` decorator
|
|
50
|
-
* @throws {@link InvalidArgument | ValidationFailed }
|
|
51
|
-
*/
|
|
52
|
-
validate(data: object): void;
|
|
53
|
-
/**
|
|
54
|
-
* Validate given data
|
|
55
|
-
*
|
|
56
|
-
* @param schemaKeyRef - key, ref or schema object
|
|
57
|
-
* @param data - to be validated
|
|
58
|
-
* @throws {@link InvalidArgumen | ValidationFailed }
|
|
59
|
-
*/
|
|
60
|
-
validate(schema: object | string, data: object): void;
|
|
61
|
-
}
|
|
1
|
+
import { Container, AsyncService } from '@spinajs/di';
|
|
2
|
+
import { IValidationError } from './exceptions/index.js';
|
|
3
|
+
import { IValidationOptions, SchemaSource, ISchemaObject } from './types.js';
|
|
4
|
+
import { Log } from '@spinajs/log-common';
|
|
5
|
+
import './sources.js';
|
|
6
|
+
/**
|
|
7
|
+
* HACK:
|
|
8
|
+
* Becouse of ajv not supporting esm default exports we need to
|
|
9
|
+
* check for default export module property and if not provided use module itself
|
|
10
|
+
*/
|
|
11
|
+
export declare class DataValidator extends AsyncService {
|
|
12
|
+
Options: IValidationOptions;
|
|
13
|
+
protected Sources: SchemaSource[];
|
|
14
|
+
protected Log: Log;
|
|
15
|
+
/**
|
|
16
|
+
* We ignore this error because ajv have problems with
|
|
17
|
+
* commonjs / esm default exports
|
|
18
|
+
*/
|
|
19
|
+
protected Validator: any;
|
|
20
|
+
protected Container: Container;
|
|
21
|
+
resolve(): Promise<void>;
|
|
22
|
+
addSchema(schemaObject: object, identifier: string): void;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* Checks if schema is loaded ( from file )
|
|
26
|
+
*
|
|
27
|
+
* @param schemaId - schema id to check
|
|
28
|
+
* @returns true if schema is loaded, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
hasSchema(schemaId: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Tries to validate given data
|
|
33
|
+
*
|
|
34
|
+
* @param data - data to validate. Function will try to extract schema attached to object via `@Schema` decorator
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
tryValidate(data: object): [boolean, IValidationError[]];
|
|
38
|
+
/**
|
|
39
|
+
* Tries to validate given data
|
|
40
|
+
*
|
|
41
|
+
* @param schemaKeyRef - key, ref or schema object
|
|
42
|
+
* @param data - to be validated
|
|
43
|
+
*/
|
|
44
|
+
tryValidate(schema: object | string, data: object): [boolean, IValidationError[]];
|
|
45
|
+
extractSchema(object: unknown): ISchemaObject;
|
|
46
|
+
/**
|
|
47
|
+
* Validate given data. When failed, exception is thrown
|
|
48
|
+
*s
|
|
49
|
+
* @param data - data to validate. Function will try to extract schema attached to object via `@Schema` decorator
|
|
50
|
+
* @throws {@link InvalidArgument | ValidationFailed }
|
|
51
|
+
*/
|
|
52
|
+
validate(data: object): void;
|
|
53
|
+
/**
|
|
54
|
+
* Validate given data
|
|
55
|
+
*
|
|
56
|
+
* @param schemaKeyRef - key, ref or schema object
|
|
57
|
+
* @param data - to be validated
|
|
58
|
+
* @throws {@link InvalidArgumen | ValidationFailed }
|
|
59
|
+
*/
|
|
60
|
+
validate(schema: object | string, data: object): void;
|
|
61
|
+
}
|
|
62
62
|
//# sourceMappingURL=validator.d.ts.map
|
package/lib/cjs/validator.js
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
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 index_js_1 = require("./exceptions/index.js");
|
|
20
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
21
|
-
const decorators_js_1 = require("./decorators.js");
|
|
22
|
-
const types_js_1 = require("./types.js");
|
|
23
|
-
const log_common_1 = require("@spinajs/log-common");
|
|
24
|
-
// import default souces
|
|
25
|
-
require("./sources.js");
|
|
26
|
-
const ajv_merge_patch_1 = __importDefault(require("ajv-merge-patch"));
|
|
27
|
-
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
28
|
-
const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
|
|
29
|
-
/**
|
|
30
|
-
* HACK:
|
|
31
|
-
* Becouse of ajv not supporting esm default exports we need to
|
|
32
|
-
* check for default export module property and if not provided use module itself
|
|
33
|
-
*/
|
|
34
|
-
let DataValidator = class DataValidator extends di_1.AsyncService {
|
|
35
|
-
async resolve() {
|
|
36
|
-
if (!this.Sources || this.Sources.length === 0) {
|
|
37
|
-
throw new exceptions_1.InvalidOperation('No schema sources avaible. Register any in DI container');
|
|
38
|
-
}
|
|
39
|
-
const ajvConfig = {
|
|
40
|
-
logger: {
|
|
41
|
-
log: (msg) => this.Log.info(msg),
|
|
42
|
-
warn: (msg) => this.Log.warn(msg),
|
|
43
|
-
error: (msg) => this.Log.error(msg),
|
|
44
|
-
},
|
|
45
|
-
...this.Options,
|
|
46
|
-
$data: true,
|
|
47
|
-
};
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
if (ajv_1.default.default) {
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
52
|
-
this.Validator = new ajv_1.default.default(ajvConfig);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
this.Validator = new ajv_1.default(ajvConfig);
|
|
57
|
-
}
|
|
58
|
-
// add $merge & $patch for json schema
|
|
59
|
-
(0, ajv_merge_patch_1.default)(this.Validator);
|
|
60
|
-
// add common formats validation eg: date time
|
|
61
|
-
ajv_formats_1.default.default(this.Validator);
|
|
62
|
-
// add keywords
|
|
63
|
-
ajv_keywords_1.default.default(this.Validator);
|
|
64
|
-
const pSources = this.Sources.map((x) => x.Load());
|
|
65
|
-
const result = await Promise.all(pSources);
|
|
66
|
-
result
|
|
67
|
-
.reduce((prev, curr) => {
|
|
68
|
-
return prev.concat(curr);
|
|
69
|
-
}, [])
|
|
70
|
-
.filter((s) => {
|
|
71
|
-
// validate schema can throw sometimes
|
|
72
|
-
try {
|
|
73
|
-
const vResult = this.Validator.validateSchema(s.schema, true);
|
|
74
|
-
if (!vResult) {
|
|
75
|
-
this.Log.error(`Schema at ${s.file} invalid`, 'validator');
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
this.Log.error(`Schema at ${s.file} invalid, reason: ${err.message}`, 'validator');
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.forEach((s) => {
|
|
86
|
-
this.addSchema(s.schema, s.schema.$id);
|
|
87
|
-
});
|
|
88
|
-
await super.resolve();
|
|
89
|
-
}
|
|
90
|
-
addSchema(schemaObject, identifier) {
|
|
91
|
-
if (!this.hasSchema(identifier)) {
|
|
92
|
-
this.Validator.addSchema(schemaObject, identifier);
|
|
93
|
-
this.Log.trace(`Schema ${identifier} added !`, 'validator');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* Checks if schema is loaded ( from file )
|
|
99
|
-
*
|
|
100
|
-
* @param schemaId - schema id to check
|
|
101
|
-
* @returns true if schema is loaded, false otherwise
|
|
102
|
-
*/
|
|
103
|
-
hasSchema(schemaId) {
|
|
104
|
-
return !!this.Validator.getSchema(schemaId);
|
|
105
|
-
}
|
|
106
|
-
tryValidate(schemaOrData, data) {
|
|
107
|
-
let schema = null;
|
|
108
|
-
if (data === null || data === undefined) {
|
|
109
|
-
schema = Reflect.getMetadata(decorators_js_1.SCHEMA_SYMBOL, schemaOrData);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
if (typeof schemaOrData === 'string') {
|
|
113
|
-
/* eslint-disable */
|
|
114
|
-
schema = this.Validator.getSchema(schemaOrData)?.schema ?? null;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
schema = schemaOrData;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (schema) {
|
|
121
|
-
const result = this.Validator.validate(schema, data !== null && data !== undefined ? data : schemaOrData);
|
|
122
|
-
if (!result) {
|
|
123
|
-
return [false, this.Validator.errors ?? null];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return [true, null];
|
|
127
|
-
}
|
|
128
|
-
extractSchema(object) {
|
|
129
|
-
return Reflect.getMetadata(decorators_js_1.SCHEMA_SYMBOL, object);
|
|
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_1.InvalidArgument('data is null or undefined');
|
|
137
|
-
case 'empty_schema':
|
|
138
|
-
throw new exceptions_1.InvalidArgument('objects schema is not set');
|
|
139
|
-
default:
|
|
140
|
-
throw new index_js_1.ValidationFailed('validation error', errors);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
DataValidator
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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 index_js_1 = require("./exceptions/index.js");
|
|
20
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
21
|
+
const decorators_js_1 = require("./decorators.js");
|
|
22
|
+
const types_js_1 = require("./types.js");
|
|
23
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
24
|
+
// import default souces
|
|
25
|
+
require("./sources.js");
|
|
26
|
+
const ajv_merge_patch_1 = __importDefault(require("ajv-merge-patch"));
|
|
27
|
+
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
28
|
+
const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
|
|
29
|
+
/**
|
|
30
|
+
* HACK:
|
|
31
|
+
* Becouse of ajv not supporting esm default exports we need to
|
|
32
|
+
* check for default export module property and if not provided use module itself
|
|
33
|
+
*/
|
|
34
|
+
let DataValidator = class DataValidator extends di_1.AsyncService {
|
|
35
|
+
async resolve() {
|
|
36
|
+
if (!this.Sources || this.Sources.length === 0) {
|
|
37
|
+
throw new exceptions_1.InvalidOperation('No schema sources avaible. Register any in DI container');
|
|
38
|
+
}
|
|
39
|
+
const ajvConfig = {
|
|
40
|
+
logger: {
|
|
41
|
+
log: (msg) => this.Log.info(msg),
|
|
42
|
+
warn: (msg) => this.Log.warn(msg),
|
|
43
|
+
error: (msg) => this.Log.error(msg),
|
|
44
|
+
},
|
|
45
|
+
...this.Options,
|
|
46
|
+
$data: true,
|
|
47
|
+
};
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
if (ajv_1.default.default) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
52
|
+
this.Validator = new ajv_1.default.default(ajvConfig);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
this.Validator = new ajv_1.default(ajvConfig);
|
|
57
|
+
}
|
|
58
|
+
// add $merge & $patch for json schema
|
|
59
|
+
(0, ajv_merge_patch_1.default)(this.Validator);
|
|
60
|
+
// add common formats validation eg: date time
|
|
61
|
+
ajv_formats_1.default.default(this.Validator);
|
|
62
|
+
// add keywords
|
|
63
|
+
ajv_keywords_1.default.default(this.Validator);
|
|
64
|
+
const pSources = this.Sources.map((x) => x.Load());
|
|
65
|
+
const result = await Promise.all(pSources);
|
|
66
|
+
result
|
|
67
|
+
.reduce((prev, curr) => {
|
|
68
|
+
return prev.concat(curr);
|
|
69
|
+
}, [])
|
|
70
|
+
.filter((s) => {
|
|
71
|
+
// validate schema can throw sometimes
|
|
72
|
+
try {
|
|
73
|
+
const vResult = this.Validator.validateSchema(s.schema, true);
|
|
74
|
+
if (!vResult) {
|
|
75
|
+
this.Log.error(`Schema at ${s.file} invalid`, 'validator');
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
this.Log.error(`Schema at ${s.file} invalid, reason: ${err.message}`, 'validator');
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
.forEach((s) => {
|
|
86
|
+
this.addSchema(s.schema, s.schema.$id);
|
|
87
|
+
});
|
|
88
|
+
await super.resolve();
|
|
89
|
+
}
|
|
90
|
+
addSchema(schemaObject, identifier) {
|
|
91
|
+
if (!this.hasSchema(identifier)) {
|
|
92
|
+
this.Validator.addSchema(schemaObject, identifier);
|
|
93
|
+
this.Log.trace(`Schema ${identifier} added !`, 'validator');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* Checks if schema is loaded ( from file )
|
|
99
|
+
*
|
|
100
|
+
* @param schemaId - schema id to check
|
|
101
|
+
* @returns true if schema is loaded, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
hasSchema(schemaId) {
|
|
104
|
+
return !!this.Validator.getSchema(schemaId);
|
|
105
|
+
}
|
|
106
|
+
tryValidate(schemaOrData, data) {
|
|
107
|
+
let schema = null;
|
|
108
|
+
if (data === null || data === undefined) {
|
|
109
|
+
schema = Reflect.getMetadata(decorators_js_1.SCHEMA_SYMBOL, schemaOrData);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (typeof schemaOrData === 'string') {
|
|
113
|
+
/* eslint-disable */
|
|
114
|
+
schema = this.Validator.getSchema(schemaOrData)?.schema ?? null;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
schema = schemaOrData;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (schema) {
|
|
121
|
+
const result = this.Validator.validate(schema, data !== null && data !== undefined ? data : schemaOrData);
|
|
122
|
+
if (!result) {
|
|
123
|
+
return [false, this.Validator.errors ?? null];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return [true, null];
|
|
127
|
+
}
|
|
128
|
+
extractSchema(object) {
|
|
129
|
+
return Reflect.getMetadata(decorators_js_1.SCHEMA_SYMBOL, object);
|
|
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_1.InvalidArgument('data is null or undefined');
|
|
137
|
+
case 'empty_schema':
|
|
138
|
+
throw new exceptions_1.InvalidArgument('objects schema is not set');
|
|
139
|
+
default:
|
|
140
|
+
throw new index_js_1.ValidationFailed('validation error', errors);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
exports.DataValidator = DataValidator;
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, configuration_1.Config)('validation'),
|
|
148
|
+
__metadata("design:type", Object)
|
|
149
|
+
], DataValidator.prototype, "Options", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, di_1.Autoinject)(types_js_1.SchemaSource),
|
|
152
|
+
__metadata("design:type", Array)
|
|
153
|
+
], DataValidator.prototype, "Sources", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
(0, log_common_1.Logger)('validation'),
|
|
156
|
+
__metadata("design:type", log_common_1.Log)
|
|
157
|
+
], DataValidator.prototype, "Log", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, di_1.Autoinject)(),
|
|
160
|
+
__metadata("design:type", di_1.Container)
|
|
161
|
+
], DataValidator.prototype, "Container", void 0);
|
|
162
|
+
exports.DataValidator = DataValidator = __decorate([
|
|
163
|
+
(0, di_1.Singleton)()
|
|
164
|
+
], DataValidator);
|
|
165
165
|
//# sourceMappingURL=validator.js.map
|
package/lib/cjs/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oCAA6E;AAC7E,8CAAsB;AACtB,0DAAgD;AAChD,oDAA2E;AAC3E,oDAAwE;AACxE,mDAAgD;AAChD,yCAA6E;AAC7E,oDAAkD;AAElD,wBAAwB;AACxB,wBAAsB;AAGtB,sEAA0D;AAC1D,8DAAoD;AACpD,gEAAsD;AAGtD;;;;GAIG;AAII,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,iBAAY;IAoBtC,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,MAAM,IAAI,6BAAgB,CAAC,yDAAyD,CAAC,CAAC;SACvF;QAED,MAAM,SAAS,GAAG;YAChB,MAAM,EAAE;gBACN,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,I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;QAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,aAAa,CAAC,MAAe;QAClC,OAAO,OAAO,CAAC,WAAW,CAAC,6BAAa,EAAE,MAAM,CAAkB,CAAA;IACpE,CAAC;IAkBM,QAAQ,CAAC,YAA6B,EAAE,IAAa;QAC1D,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,EAAE;YACZ,QAAQ,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;gBACzB,KAAK,kBAAkB;oBACrB,MAAM,IAAI,4BAAe,CAAC,2BAA2B,CAAC,CAAC;gBACzD,KAAK,cAAc;oBACjB,MAAM,IAAI,4BAAe,CAAC,2BAA2B,CAAC,CAAC;gBACzD;oBACE,MAAM,IAAI,2BAAgB,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;aAC1D;SACF;IACH,CAAC;CACF,CAAA;AA/KY,sCAAa;AAEjB;IADN,IAAA,sBAAM,EAAC,YAAY,CAAC;;8CACc;AAGzB;IADT,IAAA,eAAU,EAAC,uBAAY,CAAC;;8CACS;AAGxB;IADT,IAAA,mBAAM,EAAC,YAAY,CAAC;8BACN,gBAAG;0CAAC;AAUT;IADT,IAAA,eAAU,GAAE;8BACQ,cAAS;gDAAC;wBAlBpB,aAAa;IADzB,IAAA,cAAS,GAAE;GACC,aAAa,CA+KzB"}
|
package/lib/mjs/bootstrap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Bootstrapper } from '@spinajs/di';
|
|
2
|
-
export declare class ValidatorBootstraper extends Bootstrapper {
|
|
3
|
-
bootstrap(): void;
|
|
4
|
-
}
|
|
1
|
+
import { Bootstrapper } from '@spinajs/di';
|
|
2
|
+
export declare class ValidatorBootstraper extends Bootstrapper {
|
|
3
|
+
bootstrap(): void;
|
|
4
|
+
}
|
|
5
5
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/lib/mjs/bootstrap.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Bootstrapper, DI, Injectable } from '@spinajs/di';
|
|
8
|
-
import CONFIGURATION_SCHEMA from './schemas/validation.js';
|
|
9
|
-
let ValidatorBootstraper = class ValidatorBootstraper extends Bootstrapper {
|
|
10
|
-
bootstrap() {
|
|
11
|
-
DI.register(CONFIGURATION_SCHEMA).asValue('__configurationSchema__');
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
ValidatorBootstraper = __decorate([
|
|
15
|
-
Injectable(Bootstrapper)
|
|
16
|
-
], ValidatorBootstraper);
|
|
17
|
-
export { ValidatorBootstraper };
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Bootstrapper, DI, Injectable } from '@spinajs/di';
|
|
8
|
+
import CONFIGURATION_SCHEMA from './schemas/validation.js';
|
|
9
|
+
let ValidatorBootstraper = class ValidatorBootstraper extends Bootstrapper {
|
|
10
|
+
bootstrap() {
|
|
11
|
+
DI.register(CONFIGURATION_SCHEMA).asValue('__configurationSchema__');
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
ValidatorBootstraper = __decorate([
|
|
15
|
+
Injectable(Bootstrapper)
|
|
16
|
+
], ValidatorBootstraper);
|
|
17
|
+
export { ValidatorBootstraper };
|
|
18
18
|
//# sourceMappingURL=bootstrap.js.map
|
package/lib/mjs/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAGpD,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,YAAY;IAC7C,SAAS;QACd,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAJY,oBAAoB;IADhC,UAAU,CAAC,YAAY,CAAC;GACZ,oBAAoB,CAIhC
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAGpD,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,YAAY;IAC7C,SAAS;QACd,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAJY,oBAAoB;IADhC,UAAU,CAAC,YAAY,CAAC;GACZ,oBAAoB,CAIhC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
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
|
+
declare const config: {
|
|
2
|
+
validation: {
|
|
3
|
+
allErrors: boolean;
|
|
4
|
+
removeAdditional: boolean;
|
|
5
|
+
useDefaults: boolean;
|
|
6
|
+
coerceTypes: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default config;
|
|
10
10
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
validation: {
|
|
3
|
-
// enable all errors on validation, not only first one that occurred
|
|
4
|
-
allErrors: true,
|
|
5
|
-
// remove properties that are not defined in schema
|
|
6
|
-
removeAdditional: true,
|
|
7
|
-
// set default values if possible
|
|
8
|
-
useDefaults: true,
|
|
9
|
-
// The option coerceTypes allows you to have your data types coerced to the types specified in your schema type keywords
|
|
10
|
-
coerceTypes: true,
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
export default config;
|
|
1
|
+
const config = {
|
|
2
|
+
validation: {
|
|
3
|
+
// enable all errors on validation, not only first one that occurred
|
|
4
|
+
allErrors: true,
|
|
5
|
+
// remove properties that are not defined in schema
|
|
6
|
+
removeAdditional: true,
|
|
7
|
+
// set default values if possible
|
|
8
|
+
useDefaults: true,
|
|
9
|
+
// The option coerceTypes allows you to have your data types coerced to the types specified in your schema type keywords
|
|
10
|
+
coerceTypes: true,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export default config;
|
|
14
14
|
//# sourceMappingURL=validation.js.map
|
package/lib/mjs/decorators.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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;
|
|
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;
|
|
9
9
|
//# sourceMappingURL=decorators.d.ts.map
|