one-of.d.ts 1.3 KB

12345678910111213141516171819202122232425262728
  1. import { AlternativeMessageFactory, ErrorMessage, GroupedAlternativeMessageFactory, Middleware } from '../base';
  2. import { ContextRunner, ValidationChain } from '../chain';
  3. export type OneOfErrorType = 'grouped' | 'least_errored' | 'flat';
  4. export type OneOfOptions = {
  5. /**
  6. * The error message to use in case none of the chains are valid.
  7. */
  8. message?: AlternativeMessageFactory | ErrorMessage;
  9. errorType?: Exclude<OneOfErrorType, 'grouped'>;
  10. } | {
  11. /**
  12. * The error message to use in case none of the chain groups are valid.
  13. */
  14. message?: GroupedAlternativeMessageFactory | ErrorMessage;
  15. errorType?: 'grouped';
  16. };
  17. /**
  18. * Creates a middleware that will ensure that at least one of the given validation chains
  19. * or validation chain groups are valid.
  20. *
  21. * If none are, a single `AlternativeValidationError` or `GroupedAlternativeValidationError`
  22. * is added to the request, with the errors of each chain made available under the `nestedErrors` property.
  23. *
  24. * @param chains an array of validation chains to check if are valid.
  25. * If any of the items of `chains` is an array of validation chains, then all of them
  26. * must be valid together for the request to be considered valid.
  27. */
  28. export declare function oneOf(chains: (ValidationChain | ValidationChain[])[], options?: OneOfOptions): Middleware & ContextRunner;