routup 1.0.3 → 3.0.0-alpha.1

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.
Files changed (119) hide show
  1. package/README.md +163 -26
  2. package/dist/dispatcher/adapters/index.d.ts +3 -0
  3. package/dist/dispatcher/adapters/node/index.d.ts +1 -0
  4. package/dist/dispatcher/adapters/node/module.d.ts +7 -0
  5. package/dist/dispatcher/adapters/raw/module.d.ts +4 -0
  6. package/dist/dispatcher/adapters/raw/type.d.ts +18 -0
  7. package/dist/{route → dispatcher/adapters/web}/index.d.ts +0 -1
  8. package/dist/dispatcher/adapters/web/module.d.ts +5 -0
  9. package/dist/dispatcher/adapters/web/type.d.ts +3 -0
  10. package/dist/dispatcher/index.d.ts +3 -0
  11. package/dist/dispatcher/type.d.ts +32 -0
  12. package/dist/dispatcher/utils.d.ts +5 -0
  13. package/dist/error/create.d.ts +11 -0
  14. package/dist/error/index.d.ts +3 -0
  15. package/dist/error/is.d.ts +2 -0
  16. package/dist/error/module.d.ts +3 -0
  17. package/dist/handler/constants.d.ts +4 -0
  18. package/dist/handler/core/define.d.ts +3 -0
  19. package/dist/handler/core/index.d.ts +2 -0
  20. package/dist/handler/core/types.d.ts +10 -0
  21. package/dist/handler/error/define.d.ts +3 -0
  22. package/dist/handler/error/index.d.ts +2 -0
  23. package/dist/handler/error/types.d.ts +11 -0
  24. package/dist/handler/index.d.ts +6 -1
  25. package/dist/handler/is.d.ts +2 -0
  26. package/dist/handler/types-base.d.ts +6 -0
  27. package/dist/handler/types.d.ts +5 -0
  28. package/dist/index.cjs +1202 -629
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.ts +6 -5
  31. package/dist/index.mjs +1172 -597
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/layer/constants.d.ts +1 -0
  34. package/dist/layer/module.d.ts +13 -10
  35. package/dist/layer/type.d.ts +6 -4
  36. package/dist/path/index.d.ts +1 -0
  37. package/dist/path/matcher.d.ts +5 -6
  38. package/dist/path/type.d.ts +1 -0
  39. package/dist/path/utils.d.ts +2 -0
  40. package/dist/plugin/index.d.ts +2 -0
  41. package/dist/plugin/is.d.ts +2 -0
  42. package/dist/plugin/types.d.ts +32 -0
  43. package/dist/{helpers/request → request/helpers}/body.d.ts +1 -1
  44. package/dist/{helpers/request → request/helpers}/cache.d.ts +1 -1
  45. package/dist/{helpers/request → request/helpers}/cookie.d.ts +1 -1
  46. package/dist/{helpers/request → request/helpers}/env.d.ts +1 -1
  47. package/dist/{helpers/request → request/helpers}/header-accept-charset.d.ts +1 -1
  48. package/dist/{helpers/request → request/helpers}/header-accept-language.d.ts +1 -1
  49. package/dist/{helpers/request → request/helpers}/header-accept.d.ts +1 -1
  50. package/dist/{helpers/request → request/helpers}/header-content-type.d.ts +1 -1
  51. package/dist/{helpers/request → request/helpers}/header.d.ts +1 -1
  52. package/dist/{helpers/request → request/helpers}/hostname.d.ts +1 -1
  53. package/dist/{helpers/request → request/helpers}/index.d.ts +1 -0
  54. package/dist/{helpers/request → request/helpers}/ip.d.ts +1 -1
  55. package/dist/{helpers/request → request/helpers}/mount-path.d.ts +1 -1
  56. package/dist/{helpers/request → request/helpers}/negotiator.d.ts +1 -1
  57. package/dist/{helpers/request → request/helpers}/params.d.ts +1 -1
  58. package/dist/{helpers/request → request/helpers}/path.d.ts +1 -1
  59. package/dist/{helpers/request → request/helpers}/protocol.d.ts +1 -1
  60. package/dist/{helpers/request → request/helpers}/query.d.ts +1 -1
  61. package/dist/request/helpers/router.d.ts +3 -0
  62. package/dist/request/index.d.ts +3 -0
  63. package/dist/request/module.d.ts +4 -0
  64. package/dist/request/types.d.ts +13 -0
  65. package/dist/{helpers/response → response/helpers}/cache.d.ts +1 -1
  66. package/dist/response/helpers/gone.d.ts +2 -0
  67. package/dist/{helpers/response → response/helpers}/header-attachment.d.ts +1 -1
  68. package/dist/{helpers/response → response/helpers}/header-content-type.d.ts +1 -1
  69. package/dist/{helpers/response → response/helpers}/header.d.ts +1 -1
  70. package/dist/{helpers/response → response/helpers}/index.d.ts +3 -0
  71. package/dist/{helpers/response → response/helpers}/send-accepted.d.ts +2 -2
  72. package/dist/{helpers/response → response/helpers}/send-created.d.ts +2 -2
  73. package/dist/response/helpers/send-file.d.ts +17 -0
  74. package/dist/{helpers/response → response/helpers}/send-format.d.ts +1 -1
  75. package/dist/response/helpers/send-redirect.d.ts +2 -0
  76. package/dist/response/helpers/send-stream.d.ts +3 -0
  77. package/dist/response/helpers/send-web-blob.d.ts +3 -0
  78. package/dist/response/helpers/send-web-response.d.ts +3 -0
  79. package/dist/response/helpers/send.d.ts +2 -0
  80. package/dist/response/helpers/utils.d.ts +2 -0
  81. package/dist/response/index.d.ts +3 -0
  82. package/dist/response/module.d.ts +3 -0
  83. package/dist/response/types.d.ts +4 -0
  84. package/dist/router/constants.d.ts +1 -0
  85. package/dist/router/index.d.ts +1 -1
  86. package/dist/router/module.d.ts +34 -50
  87. package/dist/router/utils.d.ts +3 -0
  88. package/dist/router-options/index.d.ts +2 -0
  89. package/dist/router-options/module.d.ts +4 -0
  90. package/dist/router-options/transform.d.ts +2 -0
  91. package/dist/router-options/type.d.ts +41 -0
  92. package/dist/types.d.ts +10 -0
  93. package/dist/utils/cookie.d.ts +1 -0
  94. package/dist/utils/etag/module.d.ts +4 -3
  95. package/dist/utils/etag/type.d.ts +1 -1
  96. package/dist/utils/header.d.ts +3 -0
  97. package/dist/utils/index.d.ts +4 -1
  98. package/dist/utils/is-instance.d.ts +1 -1
  99. package/dist/utils/path.d.ts +5 -2
  100. package/dist/utils/stream.d.ts +8 -0
  101. package/dist/utils/web.d.ts +3 -0
  102. package/package.json +21 -19
  103. package/dist/config/module.d.ts +0 -8
  104. package/dist/config/type.d.ts +0 -34
  105. package/dist/handler/utils.d.ts +0 -2
  106. package/dist/helpers/index.d.ts +0 -2
  107. package/dist/helpers/response/send-file.d.ts +0 -9
  108. package/dist/helpers/response/send-redirect.d.ts +0 -2
  109. package/dist/helpers/response/send-stream.d.ts +0 -4
  110. package/dist/helpers/response/send.d.ts +0 -2
  111. package/dist/helpers/response/utils.d.ts +0 -3
  112. package/dist/route/module.d.ts +0 -27
  113. package/dist/route/type.d.ts +0 -6
  114. package/dist/route/utils.d.ts +0 -2
  115. package/dist/router/type.d.ts +0 -24
  116. package/dist/type.d.ts +0 -24
  117. package/dist/utils/request.d.ts +0 -2
  118. /package/dist/{config → dispatcher/adapters/raw}/index.d.ts +0 -0
  119. /package/dist/{helpers/request → request/helpers}/header-accept-encoding.d.ts +0 -0
package/README.md CHANGED
@@ -12,10 +12,11 @@
12
12
  [![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/routup/badge.svg)](https://snyk.io/test/github/Tada5hi/routup)
13
13
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
14
14
 
15
- **Routup** is a lightweight, minimalistic and extendable http interface based routing framework.
16
- It uses node's vanilla request and response interfaces, which are injected into route handlers aka middlewares as function argument.
15
+ **Routup** is a fast, lightweight, runtime agnostic and asynchronous routing framework.
16
+ Helpers provide additional functionalities to interact with the request and manipulate the response.
17
17
 
18
- Helpers provide additional functionalities to transform and interact with the request and manipulate the response upstream.
18
+ It can be used independently of the selected runtime environment (Node.Js, Bun, ... ) 🎉.
19
+ Moreover, it is even **228%** faster than Express ([more](#benchmarks)).
19
20
 
20
21
  **Table of Contents**
21
22
 
@@ -24,6 +25,7 @@ Helpers provide additional functionalities to transform and interact with the re
24
25
  - [Documentation](#documentation)
25
26
  - [Usage](#usage)
26
27
  - [Plugins](#plugins)
28
+ - [Benchmarks](#benchmarks)
27
29
  - [Contributing](#contributing)
28
30
  - [License](#license)
29
31
 
@@ -35,15 +37,15 @@ npm install routup --save
35
37
 
36
38
  ## Features
37
39
 
38
- - 🚀 high performance routing
39
- - 🧰 response & request composables/helpers
40
- - 💼 extendable & compact
41
- - 🛫 named route parameters
40
+ - 🚀 runtime agnostic (Node.JS, Bun, Deno, ...)
41
+ - 📝 different handler types (base & error)
42
+ - promise (async) support for core- & error-handlers
43
+ - 🔌 powerful plugin system
44
+ - 🧰 tree shakeable response & request helpers
45
+ - 🤝️ different handler declaration styles (shorthand & verbose)
42
46
  - 📁 nestable routers
43
- - 🤝️ define one or many (error-) middlewares
44
- - promise support for route- & middleware-handlers
45
- - 👕 TypeScript fully supported
46
- - 🤏 Minimalistic to fit into any solution with minimum overhead
47
+ - 👕 TypeScript support
48
+ - 🤏 minimalistic to fit into any solution with minimum overhead
47
49
  - & much more
48
50
 
49
51
  ## Documentation
@@ -52,16 +54,131 @@ To read the docs, visit [https://routup.net](https://routup.net)
52
54
 
53
55
  ## Usage
54
56
 
57
+ The following examples are intended to give a small insight into the use of the framework.
58
+ However, it is highly recommended to read the [documentation](https://routup.net),
59
+ as all concepts and basics are taught there.
60
+
61
+ ### Handlers
62
+
63
+ Both core and error handlers, can be defined in two different ways.
64
+
65
+ **`Shorthand`**
66
+
67
+ With the shorthand variant,
68
+ only the handler function is passed as argument to the **coreHandler** & **errorHandler** function.
69
+
55
70
  ```typescript
56
- import { Router, send } from 'routup';
71
+ import { createServer } from 'node:http';
72
+ import {
73
+ coreHandler,
74
+ createNodeDispatcher,
75
+ errorHandler,
76
+ Router,
77
+ useRequestParam
78
+ } from 'routup';
57
79
 
58
80
  const router = new Router();
59
81
 
60
- router.get('/', (req, res) => {
61
- send(res, 'Hello World');
82
+ router.get('/', coreHandler(() => 'Hello, World!'));
83
+ router.get('/greet/:name', coreHandler((req) => `Hello, ${useRequestParam(req, 'name')}!`));
84
+ router.use(errorHandler((err) => `An error with statusCode ${err.statusCode} occured.`));
85
+
86
+ const server = createServer(createNodeDispatcher(router));
87
+ server.listen(3000)
88
+ ```
89
+
90
+ **`Verbose`**
91
+
92
+ The verbose variant is more complex, but offers the possibility to set additional information
93
+ like **path**, **method**, ... in the handler definition.
94
+
95
+ ```typescript
96
+ import { createServer } from 'node:http';
97
+ import {
98
+ coreHandler,
99
+ createNodeDispatcher,
100
+ errorHandler,
101
+ Router,
102
+ useRequestParam
103
+ } from 'routup';
104
+
105
+ const router = new Router();
106
+
107
+ router.get(coreHandler({
108
+ path: '/',
109
+ fn: () => 'Hello, World!',
110
+ }));
111
+
112
+ router.get(coreHandler({
113
+ path: '/greet/:name',
114
+ fn: (req) => `Hello, ${useRequestParam(req, 'name')}!`
115
+ }))
116
+
117
+ router.use(errorHandler({
118
+ fn: (err) => `An error with statusCode ${err.statusCode} occured.`
119
+ }))
120
+
121
+ const server = createServer(createNodeDispatcher(router));
122
+ server.listen(3000)
123
+ ```
124
+
125
+ ### Runtimes
126
+
127
+ It is possible to use any javascript runtime environment. Below are examples for Bun and Deno.
128
+ These use the web dispatcher to submit requests based on the web api. Besides the node- & web-dispatcher,
129
+ there is also a plain dispatcher that underlies the web dispatcher, which can be controlled via a simple API.
130
+
131
+ **`Bun`**
132
+
133
+ ```typescript
134
+ import {
135
+ coreHandler,
136
+ createWebDispatcher,
137
+ Router
138
+ } from 'routup';
139
+
140
+ const router = new Router();
141
+
142
+ router.get('/', coreHandler(() => 'Hello, World!'));
143
+
144
+ const dispatch = createWebDispatcher(router);
145
+
146
+ Bun.serve({
147
+ async fetch(request) {
148
+ return dispatch(request);
149
+ },
150
+ port: 3000,
62
151
  });
152
+ ```
153
+
154
+ **`Deno`**
63
155
 
64
- router.listen(3000);
156
+ ```typescript
157
+ import {
158
+ coreHandler,
159
+ createWebDispatcher,
160
+ Router
161
+ } from 'routup';
162
+
163
+ const router = new Router();
164
+
165
+ router.get('/', coreHandler(() => 'Hello, World!'));
166
+
167
+ const dispatch = createWebDispatcher(router);
168
+
169
+ const server = Deno.listen({
170
+ port: 3000
171
+ });
172
+ for await (const conn of server) {
173
+ const httpConn = Deno.serveHttp(conn);
174
+
175
+ for await (const requestEvent of httpConn) {
176
+ const response = await dispatch(
177
+ requestEvent.request
178
+ );
179
+ requestEvent.respondWith(response);
180
+ }
181
+ }
65
182
  ```
66
183
 
67
184
  ## Plugins
@@ -70,17 +187,37 @@ According to the fact that routup is a minimalistic framework,
70
187
  it depends on [plugins](https://github.com/routup/plugins) to cover some
71
188
  typically http framework functions, which are not integrated in the main package.
72
189
 
73
- | Name | Description |
74
- |----------------------------------------------------------------------------|------------------------------------------------------------------------|
75
- | [body](https://www.npmjs.com/package/@routup/body) | Read and parse the request body. |
76
- | [cookie](https://www.npmjs.com/package/@routup/cookie) | Read and parse request cookies and serialize cookies for the response. |
77
- | [decorators](https://www.npmjs.com/package/@routup/decorators) | Create request handlers with class-, method- & parameter-decorators. |
78
- | [prometheus](https://www.npmjs.com/package/@routup/prometheus) | Collect and serve metrics for prometheus. |
79
- | [query](https://www.npmjs.com/package/@routup/query) | Read and parse the query string of the request url. |
80
- | [rate-limit](https://www.npmjs.com/package/@routup/rate-limit) | Rate limit incoming requests. |
81
- | [rate-limit-redis](https://www.npmjs.com/package/@routup/rate-limit-redis) | Redis adapter for the rate-limit plugin. |
82
- | [static](https://www.npmjs.com/package/@routup/static) | Serve static files from a directory. |
83
- | [swagger](https://www.npmjs.com/package/@routup/swagger) | Serve generated docs from URL or based on a JSON file. |
190
+ | Name | Description |
191
+ |-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
192
+ | [body](https://github.com/routup/plugins/tree/master/packages/body) | Read and parse the request body. |
193
+ | [cookie](https://github.com/routup/plugins/tree/master/packages/cookie) | Read and parse request cookies and serialize cookies for the response. |
194
+ | [decorators](https://github.com/routup/plugins/tree/master/packages/decorators) | Create request handlers with class-, method- & parameter-decorators. |
195
+ | [prometheus](https://github.com/routup/plugins/tree/master/packages/prometheus) | Collect and serve metrics for prometheus. |
196
+ | [query](https://github.com/routup/plugins/tree/master/packages/query) | Read and parse the query string of the request url. |
197
+ | [rate-limit](https://github.com/routup/plugins/tree/master/packages/rate-limit) | Rate limit incoming requests. |
198
+ | [rate-limit-redis](https://github.com/routup/plugins/tree/master/packages/rate-limit-redis) | Redis adapter for the rate-limit plugin. |
199
+ | [static](https://github.com/routup/plugins/tree/master/packages/static) | Serve static files from a directory. |
200
+ | [swagger](https://github.com/routup/plugins/tree/master/packages/swagger) | Serve generated docs from URL or based on a JSON file. |
201
+
202
+ ## Benchmarks
203
+
204
+ * CPUs: `24`
205
+ * RAM: `63.9GB`
206
+ * Node: `v18.16.0`
207
+ * Date: `Wed Sep 13 2023 15:11:58 GMT+0200 (Mitteleuropäische Sommerzeit) `
208
+ * Method: `autocannon -c 100 -d 40 -p 10 localhost:3000` (two rounds; one to warm-up, one to measure)
209
+
210
+ | Package | Requests/s | Latency (ms) | Throughput/MB |
211
+ |:-----------|:-----------:|--------------:|----------------:|
212
+ | http | 61062 | 15.87 | 10.89 |
213
+ | fastify | 59679 | 16.26 | 10.70 |
214
+ | koa | 45763 | 21.35 | 8.16 |
215
+ | **routup** | 43881 | 22.29 | 8.87 |
216
+ | hapi | 41374 | 23.67 | 7.38 |
217
+ | express | 13376 | 74.18 | 2.39 |
218
+
219
+ Benchmarks were generated using autocannon.
220
+ To recreate the results, this can be done using the [benchmarks'](https://github.com/routup/benchmarks) repository.
84
221
  ## Contributing
85
222
 
86
223
  Before starting to work on a pull request, it is important to review the guidelines for
@@ -0,0 +1,3 @@
1
+ export * from './node';
2
+ export * from './raw';
3
+ export * from './web';
@@ -0,0 +1 @@
1
+ export * from './module';
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type { RequestListener } from 'node:http';
3
+ import type { Request } from '../../../request';
4
+ import type { Response } from '../../../response';
5
+ import type { Router } from '../../../router';
6
+ export declare function dispatchNodeRequest(router: Router, req: Request, res: Response): Promise<void>;
7
+ export declare function createNodeDispatcher(router: Router): RequestListener;
@@ -0,0 +1,4 @@
1
+ import type { Router } from '../../../router';
2
+ import type { DispatchRawRequestOptions, RawRequest, RawResponse } from './type';
3
+ export declare function dispatchRawRequest(router: Router, request: RawRequest, options?: DispatchRawRequestOptions): Promise<RawResponse>;
4
+ export declare function createRawDispatcher(router: Router): (request: RawRequest) => Promise<RawResponse>;
@@ -0,0 +1,18 @@
1
+ import type { RequestBody, RequestHeaders } from '../../../request';
2
+ export type RawRequest = {
3
+ method: string;
4
+ path: string;
5
+ headers?: RequestHeaders;
6
+ body?: RequestBody;
7
+ };
8
+ export type RawResponseHeader = string | string[];
9
+ export type RawResponseHeaders = Record<string, RawResponseHeader>;
10
+ export type RawResponse = {
11
+ status: number;
12
+ statusMessage?: string;
13
+ headers: RawResponseHeaders;
14
+ body?: ArrayBuffer;
15
+ };
16
+ export type DispatchRawRequestOptions = {
17
+ throwOnError?: boolean;
18
+ };
@@ -1,3 +1,2 @@
1
1
  export * from './module';
2
2
  export * from './type';
3
- export * from './utils';
@@ -0,0 +1,5 @@
1
+ import type { Router } from '../../../router';
2
+ import type { WebRequest } from '../../../types';
3
+ import type { DispatchWebRequestOptions } from './type';
4
+ export declare function dispatchWebRequest(router: Router, request: WebRequest, options?: DispatchWebRequestOptions): Promise<Response>;
5
+ export declare function createWebDispatcher(router: Router): (request: WebRequest) => Promise<Response>;
@@ -0,0 +1,3 @@
1
+ export type DispatchWebRequestOptions = {
2
+ throwOnError?: boolean;
3
+ };
@@ -0,0 +1,3 @@
1
+ export * from './adapters';
2
+ export * from './type';
3
+ export * from './utils';
@@ -0,0 +1,32 @@
1
+ import type { ErrorProxy } from '../error';
2
+ import type { Request } from '../request';
3
+ import type { Response } from '../response';
4
+ export interface Dispatcher {
5
+ dispatch(event: DispatcherEvent, meta: DispatcherMeta): Promise<boolean>;
6
+ }
7
+ export type DispatcherMeta = {
8
+ /**
9
+ * Params collected on path.
10
+ */
11
+ params: Record<string, any>;
12
+ /**
13
+ * Path to check for the current instance.
14
+ */
15
+ path: string;
16
+ /**
17
+ * The relative path on which the router is hung.
18
+ */
19
+ mountPath: string;
20
+ /**
21
+ * The error which occurred during a previous handler.
22
+ */
23
+ error?: ErrorProxy;
24
+ /**
25
+ * Ids of chained router instances.
26
+ */
27
+ routerPath: number[];
28
+ };
29
+ export type DispatcherEvent = {
30
+ req: Request;
31
+ res: Response;
32
+ };
@@ -0,0 +1,5 @@
1
+ import type { DispatcherMeta } from './type';
2
+ export declare function buildDispatcherMeta(input: Partial<DispatcherMeta>): DispatcherMeta;
3
+ export declare function cloneDispatcherMeta(input: DispatcherMeta): DispatcherMeta;
4
+ export declare function cloneDispatcherMetaParams(input?: Record<string, any>): Record<string, any>;
5
+ export declare function mergeDispatcherMetaParams(t1?: Record<string, any>, t2?: Record<string, any>): Record<string, any>;
@@ -0,0 +1,11 @@
1
+ import type { Input } from '@ebec/http';
2
+ import { ErrorProxy } from './module';
3
+ /**
4
+ * Create an error proxy by
5
+ * - an existing error (accessible via cause property)
6
+ * - options
7
+ * - message
8
+ *
9
+ * @param input
10
+ */
11
+ export declare function createError(input: Input): ErrorProxy;
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './is';
3
+ export * from './module';
@@ -0,0 +1,2 @@
1
+ import { ErrorProxy } from './module';
2
+ export declare function isError(input: unknown): input is ErrorProxy;
@@ -0,0 +1,3 @@
1
+ import { HTTPError } from '@ebec/http';
2
+ export declare class ErrorProxy extends HTTPError {
3
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum HandlerType {
2
+ CORE = "core",
3
+ ERROR = "error"
4
+ }
@@ -0,0 +1,3 @@
1
+ import type { CoreHandler, CoreHandlerFn } from './types';
2
+ export declare function coreHandler(input: Omit<CoreHandler, 'type'>): CoreHandler;
3
+ export declare function coreHandler(input: CoreHandlerFn): CoreHandler;
@@ -0,0 +1,2 @@
1
+ export * from './define';
2
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ import type { Request } from '../../request';
2
+ import type { Response } from '../../response';
3
+ import type { HandlerType } from '../constants';
4
+ import type { Next } from '../types';
5
+ import type { HandlerBase } from '../types-base';
6
+ export type CoreHandlerFn = (req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
7
+ export type CoreHandler = HandlerBase & {
8
+ type: `${HandlerType.CORE}`;
9
+ fn: CoreHandlerFn;
10
+ };
@@ -0,0 +1,3 @@
1
+ import type { ErrorHandler, ErrorHandlerFn } from './types';
2
+ export declare function errorHandler(input: Omit<ErrorHandler, 'type'>): ErrorHandler;
3
+ export declare function errorHandler(input: ErrorHandlerFn): ErrorHandler;
@@ -0,0 +1,2 @@
1
+ export * from './define';
2
+ export * from './types';
@@ -0,0 +1,11 @@
1
+ import type { ErrorProxy } from '../../error';
2
+ import type { Request } from '../../request';
3
+ import type { Response } from '../../response';
4
+ import type { HandlerType } from '../constants';
5
+ import type { Next } from '../types';
6
+ import type { HandlerBase } from '../types-base';
7
+ export type ErrorHandlerFn = (err: ErrorProxy, req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
8
+ export type ErrorHandler = HandlerBase & {
9
+ type: `${HandlerType.ERROR}`;
10
+ fn: ErrorHandlerFn;
11
+ };
@@ -1 +1,6 @@
1
- export * from './utils';
1
+ export * from './core';
2
+ export * from './error';
3
+ export * from './constants';
4
+ export * from './is';
5
+ export * from './types';
6
+ export * from './types-base';
@@ -0,0 +1,2 @@
1
+ import type { Handler } from './types';
2
+ export declare function isHandler(input: unknown): input is Handler;
@@ -0,0 +1,6 @@
1
+ import type { MethodName } from '../constants';
2
+ import type { Path } from '../path';
3
+ export type HandlerBase = {
4
+ method?: `${MethodName}` | `${Uppercase<MethodName>}`;
5
+ path?: Path;
6
+ };
@@ -0,0 +1,5 @@
1
+ import type { CoreHandler, CoreHandlerFn } from './core';
2
+ import type { ErrorHandler, ErrorHandlerFn } from './error';
3
+ export type Next = (err?: Error) => void;
4
+ export type Handler = CoreHandler | ErrorHandler;
5
+ export type HandlerFn = CoreHandlerFn | ErrorHandlerFn;