-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
86 lines (72 loc) · 2.37 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/// <reference types="node" />
import {
FastifyInstance,
FastifyPluginCallback,
FastifyRequest,
} from "fastify";
type OriginCallback = (err: Error | null, allow: boolean) => void;
type OriginType = string | boolean | RegExp;
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
type FastifyEnforceSchemaPlugin = FastifyPluginCallback<
| NonNullable<fastifyEnforceSchema.FastifyEnforceSchemaOptions>
| fastifyEnforceSchema.FastifyEnforceSchemaOptionsDelegate
>;
enum SchemaTypes {
Body = "body",
Response = "response",
Params = "params",
}
declare namespace fastifyEnforceSchema {
export type OriginFunction = (
origin: string,
callback: OriginCallback
) => void;
export interface FastifyEnforceSchemaOptions {
required: string[SchemaTypes];
/**
* A list of endpoints to exclude by the route path
*/
exclude: string[];
/**
* If true, the plugin will not throw an error if the schema or schema types is equal to false
* @default false
* @example
* fastify.register(fastifyEnforceSchema, { excludeOnFalseSchema: true })
*
* fastify.get('/', { schema: false }, (req, reply) => {
* reply.send({ hello: 'world' })
* })
* // or
* fastify.get('/test', { schema: { body: false } }, (req, reply) => {
* reply.send({ hello: 'world' })
* })
* // no error will be thrown
*/
excludeOnFalseSchema: boolean;
}
export interface FastifyEnforceSchemaOptionsDelegateCallback {
(
req: FastifyRequest,
cb: (
error: Error | null,
enforceSchemaOptions?: FastifyEnforceSchemaOptions
) => void
): void;
}
export interface FastifyEnforceSchemaOptionsDelegatePromise {
(req: FastifyRequest): Promise<FastifyEnforceSchemaOptions>;
}
export type FastifyEnforceSchemaOptionsDelegate =
| FastifyEnforceSchemaOptionsDelegateCallback
| FastifyEnforceSchemaOptionsDelegatePromise;
export type FastifyPluginOptionsDelegate<
T = FastifyEnforceSchemaOptionsDelegate
> = (instance: FastifyInstance) => T;
export const fastifyEnforceSchema: FastifyEnforceSchemaPlugin;
export { fastifyEnforceSchema as default };
}
declare function fastifyEnforceSchema(
...params: Parameters<FastifyEnforceSchemaPlugin>
): ReturnType<FastifyEnforceSchemaPlugin>;
export = fastifyEnforceSchema;