UNPKG

798 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.CustomCondition = void 0;
4const base_1 = require("../base");
5class CustomCondition {
6 constructor(condition) {
7 this.condition = condition;
8 }
9 async run(_context, value, meta) {
10 try {
11 const result = this.condition(value, meta);
12 await result;
13 // if the promise resolved or the result is truthy somehow, then there's no validation halt.
14 if (!result) {
15 // the error thrown here is symbolic, it will be re-thrown in the catch clause anyway.
16 throw new Error();
17 }
18 }
19 catch (e) {
20 throw new base_1.ValidationHalt();
21 }
22 }
23}
24exports.CustomCondition = CustomCondition;