itty-router 5.0.0-next.2 → 5.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
<img src="https://edge.bundlejs.com/?q=itty-router/Router&badge&badge-style=flat-square" alt="bundle size" />
|
|
14
14
|
</a>
|
|
15
15
|
<a href="https://github.com/kwhitley/itty-router/actions/workflows/verify.yml" target="_blank">
|
|
16
|
-
<img src="https://img.shields.io/github/actions/workflow/status/kwhitley/itty-router/verify.yml?branch=
|
|
16
|
+
<img src="https://img.shields.io/github/actions/workflow/status/kwhitley/itty-router/verify.yml?branch=v5.x&style=flat-square" alt="build status" />
|
|
17
17
|
</a>
|
|
18
|
-
<a href="https://coveralls.io/github/kwhitley/itty-router?branch=
|
|
19
|
-
<img src="https://img.shields.io/coveralls/github/kwhitley/itty-router/
|
|
18
|
+
<a href="https://coveralls.io/github/kwhitley/itty-router?branch=v5.x" target="_blank">
|
|
19
|
+
<img src="https://img.shields.io/coveralls/github/kwhitley/itty-router/v5.x?style=flat-square" alt="code coverage" />
|
|
20
20
|
</a>
|
|
21
21
|
<a href="https://npmjs.com/package/itty-router" target="_blank">
|
|
22
22
|
<img src="https://img.shields.io/npm/dw/itty-router?style=flat-square" alt="weekly downloads" />
|
|
@@ -47,19 +47,16 @@
|
|
|
47
47
|
|
|
48
48
|
An ultra-tiny API microrouter, for use when [size matters](https://github.com/TigersWay/cloudflare-playground) (e.g. [Cloudflare Workers](https://developers.cloudflare.com/workers/)).
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
50
|
## Features
|
|
54
51
|
|
|
55
52
|
- Tiny. Routers from [~450 bytes](https://itty.dev/itty-router/routers/ittyrouter) to a [~970 bytes](https://itty.dev/itty-router/routers/autorouter) batteries-included version (~240-500x smaller than Express.js).
|
|
53
|
+
- [TypeScript](https://itty.dev/itty-router/typescript). Powerfully (and flexibly) typed for any environment.
|
|
54
|
+
- [Route-parsing](https://itty.dev/itty-router/route-patterns) & [query parsing](https://itty.dev/itty-router/route-patterns#query).
|
|
55
|
+
- [Middleware](https://itty.dev/itty-router/middleware). Use ours or write your own.
|
|
56
|
+
- [100% Test Coverage](https://coveralls.io/github/kwhitley/itty-router?branch=v5.x). Bulletproof for production peace-of-mind.
|
|
56
57
|
- Web Standards. Use it [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
|
|
57
58
|
- No assumptions. Return anything; pass in anything.
|
|
58
|
-
- Dead-simple user-code. We want _your_ code to be tiny too.
|
|
59
59
|
- Future-proof. HTTP methods not-yet-invented already work with it.
|
|
60
|
-
- [Route-parsing](https://itty.dev/itty-router/route-patterns) & [query parsing](https://itty.dev/itty-router/route-patterns#query).
|
|
61
|
-
- [Middleware](https://itty.dev/itty-router/middleware) - use ours or write your own.
|
|
62
|
-
- [Supports Nesting](https://itty.dev/itty-router/nesting).
|
|
63
60
|
|
|
64
61
|
## Example
|
|
65
62
|
|
package/package.json
CHANGED
package/types/ErrorHandler.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { StatusError } from '../StatusError';
|
|
1
2
|
import { IRequest } from './IRequest';
|
|
2
|
-
export type ErrorHandler<ErrorType =
|
|
3
|
+
export type ErrorHandler<ErrorType extends Error = StatusError, RequestType = IRequest, Args extends any[] = any[]> = (error: ErrorType, request: RequestType, ...args: Args) => any;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericTraps } from './GenericTraps';
|
|
2
2
|
import { IRequest } from './IRequest';
|
|
3
3
|
import { RequestLike } from './RequestLike';
|
|
4
4
|
import { Route } from './Route';
|
|
5
5
|
import { RouteEntry } from './RouteEntry';
|
|
6
|
-
|
|
6
|
+
import { CustomRoutes } from './CustomRoutes';
|
|
7
|
+
export type IttyRouterType<R = IRequest, A extends any[] = any[], ResponseType = any> = {
|
|
7
8
|
__proto__: IttyRouterType<R>;
|
|
8
9
|
routes: RouteEntry[];
|
|
9
|
-
fetch: <Args extends any[] = A>(request: RequestLike, ...extra: Args) => Promise<
|
|
10
|
+
fetch: <Args extends any[] = A>(request: RequestLike, ...extra: Args) => Promise<ResponseType>;
|
|
10
11
|
all: Route<R, A>;
|
|
11
12
|
delete: Route<R, A>;
|
|
12
13
|
get: Route<R, A>;
|
|
@@ -15,4 +16,4 @@ export type IttyRouterType<R = IRequest, A extends any[] = any[], Output = any>
|
|
|
15
16
|
patch: Route<R, A>;
|
|
16
17
|
post: Route<R, A>;
|
|
17
18
|
put: Route<R, A>;
|
|
18
|
-
} & CustomRoutes<Route<R, A
|
|
19
|
+
} & CustomRoutes<Route<R, A>> & GenericTraps;
|
package/types/RouterType.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { IRequest } from './IRequest';
|
|
|
3
3
|
import { IttyRouterType } from './IttyRouterType';
|
|
4
4
|
import { RequestHandler } from './RequestHandler';
|
|
5
5
|
import { ResponseHandler } from './ResponseHandler';
|
|
6
|
-
export type RouterType<R = IRequest, Args extends any[] = any[]> = {
|
|
6
|
+
export type RouterType<R = IRequest, Args extends any[] = any[], ResponseType = any> = {
|
|
7
7
|
before?: RequestHandler<any>[];
|
|
8
8
|
catch?: ErrorHandler;
|
|
9
9
|
finally?: ResponseHandler[];
|
|
10
|
-
} & IttyRouterType<R, Args>;
|
|
10
|
+
} & IttyRouterType<R, Args, ResponseType>;
|