1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.CustomValidation = void 0;
|
4 | class CustomValidation {
|
5 | constructor(validator, negated) {
|
6 | this.validator = validator;
|
7 | this.negated = negated;
|
8 | }
|
9 | async run(context, value, meta) {
|
10 | try {
|
11 | const result = this.validator(value, meta);
|
12 | const actualResult = await result;
|
13 | const isPromise = result && result.then;
|
14 | const failed = this.negated ? actualResult : !actualResult;
|
15 |
|
16 |
|
17 | if ((!isPromise && failed) || (isPromise && this.negated)) {
|
18 | context.addError(this.message, value, meta);
|
19 | }
|
20 | }
|
21 | catch (err) {
|
22 | if (this.negated) {
|
23 | return;
|
24 | }
|
25 | context.addError((err instanceof Error ? err.message : err) || this.message, value, meta);
|
26 | }
|
27 | }
|
28 | }
|
29 | exports.CustomValidation = CustomValidation;
|