-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
40 lines (27 loc) · 1.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { FastifyPlugin } from 'fastify'
import { Spec, ValidatorSpec, CleanOptions, CleanedEnvAccessors } from 'envalid'
declare module 'fastify' {
export interface FastifyInstance {
validators: Validators
cleanEnv: CleanEnvFunction
makeValidator: <T>(
parser: (input: string) => T,
type?: string
) => (spec?: Spec<T>) => ValidatorSpec<T>
}
}
export interface Validators {
bool: <T extends boolean = boolean>(spec?: Spec<T>) => ValidatorSpec<T>
num: <T extends number = number>(spec?: Spec<T>) => ValidatorSpec<T>
str: <T extends string = string>(spec?: Spec<T>) => ValidatorSpec<T>
json: <T = any>(spec?: Spec<T>) => ValidatorSpec<T>
url: <T extends string = string>(spec?: Spec<T>) => ValidatorSpec<T>
email: <T extends string = string>(spec?: Spec<T>) => ValidatorSpec<T>
host: <T extends string = string>(spec?: Spec<T>) => ValidatorSpec<T>
port: <T extends number = number>(spec?: Spec<T>) => ValidatorSpec<T>
}
export declare type CleanEnvFunction = <T>(environment: unknown, specs: {
[K in keyof T]: ValidatorSpec<T[K]>;
}, options?: CleanOptions<T>) => Readonly<T & CleanedEnvAccessors>
declare const fastifyEnvalid: FastifyPlugin
export default fastifyEnvalid