1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ContextHandlerImpl = void 0;
|
4 | const context_items_1 = require("../context-items");
|
5 | const bail_1 = require("../context-items/bail");
|
6 | class ContextHandlerImpl {
|
7 | constructor(builder, chain) {
|
8 | this.builder = builder;
|
9 | this.chain = chain;
|
10 | }
|
11 | bail() {
|
12 | this.builder.addItem(new bail_1.Bail());
|
13 | return this.chain;
|
14 | }
|
15 | if(condition) {
|
16 | if ('run' in condition) {
|
17 | this.builder.addItem(new context_items_1.ChainCondition(condition));
|
18 | }
|
19 | else if (typeof condition === 'function') {
|
20 | this.builder.addItem(new context_items_1.CustomCondition(condition));
|
21 | }
|
22 | else {
|
23 | throw new Error('express-validator: condition is not a validation chain nor a function');
|
24 | }
|
25 | return this.chain;
|
26 | }
|
27 | optional(options = true) {
|
28 | if (typeof options === 'boolean') {
|
29 | this.builder.setOptional(options ? { checkFalsy: false, nullable: false } : false);
|
30 | }
|
31 | else {
|
32 | this.builder.setOptional({
|
33 | checkFalsy: !!options.checkFalsy,
|
34 | nullable: !!options.nullable,
|
35 | });
|
36 | }
|
37 | return this.chain;
|
38 | }
|
39 | }
|
40 | exports.ContextHandlerImpl = ContextHandlerImpl;
|