-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjoi-router.d.ts
87 lines (74 loc) · 2.23 KB
/
joi-router.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
87
// Inspired from: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-joi-router
/// <reference types="node" />
import * as Koa from "koa";
import * as Joi from "joi";
import * as KoaRouter from "@koa/router";
import * as CoBody from "co-body";
import { BusboyConfig } from "@fastify/busboy";
declare module "Koa" {
interface Request {
body?: any;
params: { [key: string]: string };
}
}
interface KoaJoiRouter {
new (): KoaJoiRouter.Router;
Joi: typeof Joi;
}
declare namespace KoaJoiRouter {
type FullHandler = (ctx: Koa.Context, next: Koa.Next) => any;
interface NestedHandler extends ReadonlyArray<Handler> {}
type Handler = FullHandler | NestedHandler;
type Method = (
path: string | RegExp,
handlerOrConfig: Handler | Config,
...handlers: Handler[]
) => Router;
type OutputValidation =
| { body: Joi.SchemaLike }
| { headers: Joi.SchemaLike };
interface Config {
pre?: Handler | undefined;
validate?:
| {
header?: Joi.SchemaLike | undefined;
query?: Joi.SchemaLike | undefined;
params?: Joi.SchemaLike | undefined;
body?: Joi.SchemaLike | undefined;
maxBody?: number | string | undefined;
failure?: number | undefined;
type?: "form" | "json" | "multipart" | undefined;
formOptions?: CoBody.Options | undefined;
jsonOptions?: CoBody.Options | undefined;
multipartOptions?: BusboyConfig | undefined;
output?: { [status: string]: OutputValidation } | undefined;
continueOnError?: boolean | undefined;
validateOptions?: Joi.ValidationOptions | undefined;
}
| undefined;
meta?: any;
}
interface Spec extends Config {
method: string | string[];
path: string | RegExp;
handler: Handler;
}
interface Router {
routes: Spec[];
route(spec: Spec | Spec[]): Router;
router: KoaRouter;
middleware(): Koa.Middleware;
prefix: KoaRouter["prefix"];
use: KoaRouter["use"];
param: KoaRouter["param"];
head: Method;
options: Method;
get: Method;
post: Method;
put: Method;
patch: Method;
delete: Method;
}
}
declare var KoaJoiRouter: KoaJoiRouter;
export = KoaJoiRouter;