mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Got tests running, made changes to get tests to compile
This commit is contained in:
12
types/koa-joi-router/index.d.ts
vendored
12
types/koa-joi-router/index.d.ts
vendored
@@ -5,13 +5,11 @@
|
||||
import * as Koa from 'koa';
|
||||
import * as Joi from 'joi';
|
||||
|
||||
type METHODS = 'POST' | 'GET' | 'DELETE' | 'PUT' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
||||
|
||||
interface Spec {
|
||||
method: METHODS;
|
||||
method: string;
|
||||
path: string|RegExp;
|
||||
handler: (ctx: Koa.Context) => void;
|
||||
validate: {
|
||||
validate?: {
|
||||
type: string;
|
||||
body?: Joi.AnySchema;
|
||||
params?: Joi.AnySchema;
|
||||
@@ -19,7 +17,7 @@ interface Spec {
|
||||
};
|
||||
}
|
||||
|
||||
declare class Router {
|
||||
interface Router {
|
||||
route(spec: Spec): Router;
|
||||
middleware(): Koa.Middleware;
|
||||
}
|
||||
@@ -29,6 +27,6 @@ interface createRouter {
|
||||
Joi: typeof Joi;
|
||||
}
|
||||
|
||||
declare namespace createRouter {}
|
||||
declare var create: createRouter;
|
||||
|
||||
export = createRouter;
|
||||
export = create;
|
||||
|
||||
@@ -1,20 +1,50 @@
|
||||
import * as router from 'koa-joi-router';
|
||||
import { Context } from 'koa';
|
||||
|
||||
const { Joi } = router;
|
||||
|
||||
const spec1 = {
|
||||
route: '/user',
|
||||
path: '/user',
|
||||
method: 'POST',
|
||||
handler: (ctx) => ctx.body = '';
|
||||
handler: (ctx: Context) => ctx.body = '',
|
||||
};
|
||||
|
||||
router().route(spec1);
|
||||
|
||||
const spec2: ISpec = {
|
||||
const spec2 = {
|
||||
method: 'PATCH',
|
||||
route: '/user',
|
||||
validate: {},
|
||||
handler: (ctx) => ctx.stat
|
||||
path: '/user',
|
||||
validate: {
|
||||
type: 'json',
|
||||
},
|
||||
handler: (ctx: Context) => ctx.status = 201,
|
||||
};
|
||||
|
||||
router().route(spec2);
|
||||
|
||||
const spec3 = {
|
||||
method: 'PATCH',
|
||||
path: '/user',
|
||||
validate: {
|
||||
type: 'json',
|
||||
body: Joi.any(),
|
||||
},
|
||||
handler: (ctx: Context) => ctx.status = 201,
|
||||
};
|
||||
|
||||
router().route(spec3);
|
||||
|
||||
const spec4 = {
|
||||
method: 'PATCH',
|
||||
path: '/user',
|
||||
validate: {
|
||||
type: 'json',
|
||||
201: Joi.object(),
|
||||
},
|
||||
handler: (ctx: Context) => {
|
||||
ctx.status = 201;
|
||||
ctx.body = {};
|
||||
},
|
||||
};
|
||||
|
||||
router().route(spec3);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"koa-tests.ts"
|
||||
"koa-joi-router-tests.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
@@ -10,7 +10,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
|
||||
Reference in New Issue
Block a user