@types/koa-joi-router
Version: 
TypeScript definitions for koa-joi-router
101 lines (82 loc) • 3.5 kB
Markdown
# Installation
> `npm install --save @types/koa-joi-router`
# Summary
This package contains type definitions for koa-joi-router (https://github.com/koajs/joi-router).
# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-joi-router.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-joi-router/index.d.ts)
````ts
/// <reference types="node" />
import { BusboyConfig } from "busboy";
import * as CoBody from "co-body";
import * as http from "http";
import * as Joi from "joi";
import * as Koa from "koa";
import * as KoaRouter from "koa-router";
declare module "koa" {
    interface Request {
        body?: any;
        params: { [key: string]: string };
    }
}
interface createRouter {
    (): createRouter.Router;
    Joi: typeof Joi;
}
declare namespace createRouter {
    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 createRouter: createRouter;
export = createRouter;
````
### Additional Details
 * Last updated: Tue, 07 Nov 2023 09:09:38 GMT
 * Dependencies: [@types/busboy](https://npmjs.com/package/@types/busboy), [@types/co-body](https://npmjs.com/package/@types/co-body), [@types/koa](https://npmjs.com/package/@types/koa), [@types/koa-router](https://npmjs.com/package/@types/koa-router), [@types/node](https://npmjs.com/package/@types/node), [joi](https://npmjs.com/package/joi)
# Credits
These definitions were written by [Matthew Bull](https://github.com/wingsbob), [Dave Welsh](https://github.com/move-zig), [Hiroshi Ioka](https://github.com/hirochachacha), [Tiger Oakes](https://github.com/NotWoods), and [Jeremy Hull](https://github.com/sourrust).