1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Validator = void 0;
|
4 | const ValidationExecutor_1 = require("./ValidationExecutor");
|
5 |
|
6 |
|
7 |
|
8 | class Validator {
|
9 | |
10 |
|
11 |
|
12 | validate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
|
13 | return this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);
|
14 | }
|
15 | |
16 |
|
17 |
|
18 | async validateOrReject(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
|
19 | const errors = await this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);
|
20 | if (errors.length)
|
21 | return Promise.reject(errors);
|
22 | }
|
23 | |
24 |
|
25 |
|
26 | validateSync(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
|
27 | const object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
|
28 | const options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
|
29 | const schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
|
30 | const executor = new ValidationExecutor_1.ValidationExecutor(this, options);
|
31 | executor.ignoreAsyncValidations = true;
|
32 | const validationErrors = [];
|
33 | executor.execute(object, schema, validationErrors);
|
34 | return executor.stripEmptyErrors(validationErrors);
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 | coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
|
44 | const object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
|
45 | const options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
|
46 | const schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
|
47 | const executor = new ValidationExecutor_1.ValidationExecutor(this, options);
|
48 | const validationErrors = [];
|
49 | executor.execute(object, schema, validationErrors);
|
50 | return Promise.all(executor.awaitingPromises).then(() => {
|
51 | return executor.stripEmptyErrors(validationErrors);
|
52 | });
|
53 | }
|
54 | }
|
55 | exports.Validator = Validator;
|
56 |
|
\ | No newline at end of file |