UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ContextHandlerImpl = void 0;
4const context_items_1 = require("../context-items");
5const bail_1 = require("../context-items/bail");
6class 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}
40exports.ContextHandlerImpl = ContextHandlerImpl;