validation-result.d.ts 675 B

12345678910111213141516171819202122232425262728
  1. import * as express from 'express';
  2. import { Location } from './location';
  3. export type ErrorFormatter<T = any> = (error: {
  4. location: Location,
  5. param: string,
  6. msg: any,
  7. value: any
  8. }) => T;
  9. export interface Result<T = any> {
  10. array(options?: { onlyFirstError?: boolean }): T[];
  11. formatWith(formatter: ErrorFormatter<T>): this;
  12. isEmpty(): boolean;
  13. mapped(): Record<string, T>;
  14. throw(): void;
  15. }
  16. export const validationResult: ResultFactory;
  17. export interface ResultFactory {
  18. <T>(req: express.Request): Result<T>;
  19. withDefaults(options?: Partial<ResultFactoryBuilderOptions>) : this;
  20. }
  21. interface ResultFactoryBuilderOptions {
  22. formatter: ErrorFormatter;
  23. }