itty-router
Advanced tools
Comparing version 5.0.0-next.2 to 5.0.0-next.3
{ | ||
"name": "itty-router", | ||
"version": "5.0.0-next.2", | ||
"version": "5.0.0-next.3", | ||
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -16,6 +16,6 @@ <p align="center"> | ||
<a href="https://github.com/kwhitley/itty-router/actions/workflows/verify.yml" target="_blank"> | ||
<img src="https://img.shields.io/github/actions/workflow/status/kwhitley/itty-router/verify.yml?branch=v4.x&style=flat-square" alt="build status" /> | ||
<img src="https://img.shields.io/github/actions/workflow/status/kwhitley/itty-router/verify.yml?branch=v5.x&style=flat-square" alt="build status" /> | ||
</a> | ||
<a href="https://coveralls.io/github/kwhitley/itty-router?branch=v4.x" target="_blank"> | ||
<img src="https://img.shields.io/coveralls/github/kwhitley/itty-router/v4.x?style=flat-square" alt="code coverage" /> | ||
<a href="https://coveralls.io/github/kwhitley/itty-router?branch=v5.x" target="_blank"> | ||
<img src="https://img.shields.io/coveralls/github/kwhitley/itty-router/v5.x?style=flat-square" alt="code coverage" /> | ||
</a> | ||
@@ -51,15 +51,12 @@ <a href="https://npmjs.com/package/itty-router" target="_blank"> | ||
## Features | ||
- 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). | ||
- [TypeScript](https://itty.dev/itty-router/typescript). Powerfully (and flexibly) typed for any environment. | ||
- [Route-parsing](https://itty.dev/itty-router/route-patterns) & [query parsing](https://itty.dev/itty-router/route-patterns#query). | ||
- [Middleware](https://itty.dev/itty-router/middleware). Use ours or write your own. | ||
- [100% Test Coverage](https://coveralls.io/github/kwhitley/itty-router?branch=v5.x). Bulletproof for production peace-of-mind. | ||
- Web Standards. Use it [anywhere, in any environment](https://itty.dev/itty-router/runtimes). | ||
- No assumptions. Return anything; pass in anything. | ||
- Dead-simple user-code. We want _your_ code to be tiny too. | ||
- Future-proof. HTTP methods not-yet-invented already work with it. | ||
- [Route-parsing](https://itty.dev/itty-router/route-patterns) & [query parsing](https://itty.dev/itty-router/route-patterns#query). | ||
- [Middleware](https://itty.dev/itty-router/middleware) - use ours or write your own. | ||
- [Supports Nesting](https://itty.dev/itty-router/nesting). | ||
@@ -66,0 +63,0 @@ ## Example |
@@ -0,2 +1,3 @@ | ||
import { StatusError } from '../StatusError'; | ||
import { IRequest } from './IRequest'; | ||
export type ErrorHandler<ErrorType = Error, RequestType = IRequest, Args extends any[] = any[]> = (response: ErrorType, request: RequestType, ...args: Args) => any; | ||
export type ErrorHandler<ErrorType extends Error = StatusError, RequestType = IRequest, Args extends any[] = any[]> = (error: ErrorType, request: RequestType, ...args: Args) => any; |
export type IRequestStrict = { | ||
method: string; | ||
url: string; | ||
route: string; | ||
@@ -5,0 +3,0 @@ params: { |
@@ -0,1 +1,2 @@ | ||
import { GenericTraps } from './GenericTraps'; | ||
import { RouteEntry } from './RouteEntry'; | ||
@@ -5,2 +6,2 @@ export type IttyRouterOptions = { | ||
routes?: RouteEntry[]; | ||
} & Record<string, any>; | ||
} & GenericTraps; |
@@ -1,2 +0,2 @@ | ||
import { CustomRoutes } from './CustomRoutes'; | ||
import { GenericTraps } from './GenericTraps'; | ||
import { IRequest } from './IRequest'; | ||
@@ -6,6 +6,7 @@ import { RequestLike } from './RequestLike'; | ||
import { RouteEntry } from './RouteEntry'; | ||
export type IttyRouterType<R = IRequest, A extends any[] = any[], Output = any> = { | ||
import { CustomRoutes } from './CustomRoutes'; | ||
export type IttyRouterType<R = IRequest, A extends any[] = any[], ResponseType = any> = { | ||
__proto__: IttyRouterType<R>; | ||
routes: RouteEntry[]; | ||
fetch: <Args extends any[] = A>(request: RequestLike, ...extra: Args) => Promise<Output>; | ||
fetch: <Args extends any[] = A>(request: RequestLike, ...extra: Args) => Promise<ResponseType>; | ||
all: Route<R, A>; | ||
@@ -19,2 +20,2 @@ delete: Route<R, A>; | ||
put: Route<R, A>; | ||
} & CustomRoutes<Route<R, A>>; | ||
} & CustomRoutes<Route<R, A>> & GenericTraps; |
@@ -1,3 +0,1 @@ | ||
export interface ResponseFormatter { | ||
(body?: any, options?: ResponseInit): Response; | ||
} | ||
export type ResponseFormatter = (body?: any, options?: ResponseInit) => Response; |
@@ -6,6 +6,6 @@ import { ErrorHandler } from './ErrorHandler'; | ||
import { ResponseHandler } from './ResponseHandler'; | ||
export type RouterType<R = IRequest, Args extends any[] = any[]> = { | ||
export type RouterType<R = IRequest, Args extends any[] = any[], ResponseType = any> = { | ||
before?: RequestHandler<any>[]; | ||
catch?: ErrorHandler; | ||
finally?: ResponseHandler[]; | ||
} & IttyRouterType<R, Args>; | ||
} & IttyRouterType<R, Args, ResponseType>; |
82821
334
91