Skip to content

Commit 1a608e0

Browse files
migstophelesmhegazy
authored andcommitted
Remove path-to-regexp and add koa-route definitions (DefinitelyTyped#16220)
* Add type definitions for koa-route * Not needed: path-to-regexp * Change path-to-regexp asOfVersion to ^1.7.0 * Revert "Change path-to-regexp asOfVersion to ^1.7.0" This reverts commit 0452ebe. * Change path-to-regexp dependency to ^1.7.0
1 parent 74c1a01 commit 1a608e0

8 files changed

+99
-38
lines changed

notNeededPackages.json

+6
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@
354354
"sourceRepoURL": "https://github.com/blakeembrey/path-case",
355355
"asOfVersion": "1.1.2"
356356
},
357+
{
358+
"libraryName": "path-to-regexp",
359+
"typingsPackageName": "path-to-regexp",
360+
"sourceRepoURL": "https://github.com/pillarjs/path-to-regexp",
361+
"asOfVersion": "1.7.0"
362+
},
357363
{
358364
"libraryName": "pg-promise",
359365
"typingsPackageName": "pg-promise",

types/koa-route/index.d.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Type definitions for koa-route 3.2
2+
// Project: https://github.com/koajs/route#readme
3+
// Definitions by: Mike Cook <https://github.com/migstopheles>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
// TypeScript Version: 2.2
6+
7+
import * as Koa from 'koa';
8+
import * as pathToRegexp from 'path-to-regexp';
9+
10+
type RoutePath = string | RegExp | Array<string | RegExp>;
11+
12+
type RouteHandler = (this: Koa.Context, ctx: Koa.Context, ...params: any[]) => any;
13+
14+
type CreateRoute = (routeFunc: RouteHandler) => Koa.Middleware;
15+
16+
interface RouteMethod {
17+
(path: RoutePath): CreateRoute;
18+
(path: RoutePath, fn: RouteHandler, opts?: pathToRegexp.ParseOptions & pathToRegexp.RegExpOptions): Koa.Middleware;
19+
}
20+
21+
type CreateRouteMethod = (method: string) => RouteMethod;
22+
23+
interface KoaRoutes {
24+
all: CreateRouteMethod;
25+
acl: RouteMethod;
26+
bind: RouteMethod;
27+
checkout: RouteMethod;
28+
connect: RouteMethod;
29+
copy: RouteMethod;
30+
delete: RouteMethod;
31+
del: RouteMethod;
32+
get: RouteMethod;
33+
head: RouteMethod;
34+
link: RouteMethod;
35+
lock: RouteMethod;
36+
msearch: RouteMethod;
37+
merge: RouteMethod;
38+
mkactivity: RouteMethod;
39+
mkcalendar: RouteMethod;
40+
mkcol: RouteMethod;
41+
move: RouteMethod;
42+
notify: RouteMethod;
43+
options: RouteMethod;
44+
patch: RouteMethod;
45+
post: RouteMethod;
46+
propfind: RouteMethod;
47+
proppatch: RouteMethod;
48+
purge: RouteMethod;
49+
put: RouteMethod;
50+
rebind: RouteMethod;
51+
report: RouteMethod;
52+
search: RouteMethod;
53+
subscribe: RouteMethod;
54+
trace: RouteMethod;
55+
unbind: RouteMethod;
56+
unlink: RouteMethod;
57+
unlock: RouteMethod;
58+
unsubscribe: RouteMethod;
59+
}
60+
61+
declare const routes: KoaRoutes;
62+
63+
export = routes;

types/koa-route/koa-route-tests.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Koa from 'koa';
2+
import * as route from 'koa-route';
3+
4+
const app = new Koa();
5+
6+
const getData = async (param: string) => Promise.resolve({ foo: param });
7+
8+
const getter = route.get('/');
9+
const getterMiddleware = getter((ctx, next) => {
10+
ctx.body = { status: 'OK' };
11+
next();
12+
});
13+
14+
const putter = route.put('/api/:param', async (ctx, param, next) => {
15+
const data = await getData(param);
16+
ctx.body = { status: 'OK', ...data };
17+
next();
18+
});
19+
20+
app.use(getterMiddleware);
21+
app.use(putter);

types/koa-route/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"path-to-regexp": "^1.7.0"
4+
}
5+
}

types/path-to-regexp/tsconfig.json types/koa-route/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
],
77
"noImplicitAny": true,
88
"noImplicitThis": true,
9-
"strictNullChecks": false,
9+
"strictNullChecks": true,
1010
"baseUrl": "../",
1111
"typeRoots": [
1212
"../"
@@ -17,6 +17,6 @@
1717
},
1818
"files": [
1919
"index.d.ts",
20-
"path-to-regexp-tests.ts"
20+
"koa-route-tests.ts"
2121
]
22-
}
22+
}

types/koa-route/tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

types/path-to-regexp/index.d.ts

-20
This file was deleted.

types/path-to-regexp/path-to-regexp-tests.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)