mirror of
https://github.com/Expand-sys/ccashfrontend
synced 2025-12-19 16:12:14 +11:00
28 lines
675 B
TypeScript
28 lines
675 B
TypeScript
import * as express from 'express';
|
|
import { Location } from './location';
|
|
|
|
export type ErrorFormatter<T = any> = (error: {
|
|
location: Location,
|
|
param: string,
|
|
msg: any,
|
|
value: any
|
|
}) => T;
|
|
|
|
export interface Result<T = any> {
|
|
array(options?: { onlyFirstError?: boolean }): T[];
|
|
formatWith(formatter: ErrorFormatter<T>): this;
|
|
isEmpty(): boolean;
|
|
mapped(): Record<string, T>;
|
|
throw(): void;
|
|
}
|
|
|
|
export const validationResult: ResultFactory;
|
|
|
|
export interface ResultFactory {
|
|
<T>(req: express.Request): Result<T>;
|
|
withDefaults(options?: Partial<ResultFactoryBuilderOptions>) : this;
|
|
}
|
|
|
|
interface ResultFactoryBuilderOptions {
|
|
formatter: ErrorFormatter;
|
|
}
|