@types/koa-joi-router
TypeScript icon, indicating that this package has built-in type declarations

8.0.7 • Public • Published

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

/// <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

Credits

These definitions were written by Matthew Bull, Dave Welsh, Hiroshi Ioka, Tiger Oakes, and Jeremy Hull.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/koa-joi-router

Weekly Downloads

2,685

Version

8.0.7

License

MIT

Unpacked Size

8.61 kB

Total Files

5

Last publish

Collaborators

  • types