import {ArgumentFilter, ArgumentWorker, ArgumentProcessorContext} from "./types"; import {InputHelper} from "./input-helper"; import {ValueValidatorObject, ValueSanitizerObject} from "../../value-checker/base"; import {Request} from "express-serve-static-core"; export interface OptionalDefaultFunction { (this: ArgumentProcessorContext, req: Request): any; } export class ParamInputHelper extends InputHelper { filter(fn: ArgumentFilter | ValueValidatorObject) { if (typeof fn === 'function') { this.state.filter = fn; } else { this.state.filter = fn.getFunction(); } return this; } optional(defaultValue: any | OptionalDefaultFunction = null) { this.state.optionalDefault = defaultValue; return this; } optionalCallback(defaultValue: OptionalDefaultFunction = null) { this.state.optionalDefault = defaultValue; return this; } sanitize(fn: ArgumentWorker | ValueSanitizerObject) { if (typeof fn === 'function') { this.state.handler = fn; } else { this.state.handler = fn.getFunction(); } return this; } } export class SafeParamInputHelper extends InputHelper { }