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.
- package/README.md +163 -26
- package/dist/dispatcher/adapters/index.d.ts +3 -0
- package/dist/dispatcher/adapters/node/index.d.ts +1 -0
- package/dist/dispatcher/adapters/node/module.d.ts +7 -0
- package/dist/dispatcher/adapters/raw/module.d.ts +4 -0
- package/dist/dispatcher/adapters/raw/type.d.ts +18 -0
- package/dist/{route → dispatcher/adapters/web}/index.d.ts +0 -1
- package/dist/dispatcher/adapters/web/module.d.ts +5 -0
- package/dist/dispatcher/adapters/web/type.d.ts +3 -0
- package/dist/dispatcher/index.d.ts +3 -0
- package/dist/dispatcher/type.d.ts +32 -0
- package/dist/dispatcher/utils.d.ts +5 -0
- package/dist/error/create.d.ts +11 -0
- package/dist/error/index.d.ts +3 -0
- package/dist/error/is.d.ts +2 -0
- package/dist/error/module.d.ts +3 -0
- package/dist/handler/constants.d.ts +4 -0
- package/dist/handler/core/define.d.ts +3 -0
- package/dist/handler/core/index.d.ts +2 -0
- package/dist/handler/core/types.d.ts +10 -0
- package/dist/handler/error/define.d.ts +3 -0
- package/dist/handler/error/index.d.ts +2 -0
- package/dist/handler/error/types.d.ts +11 -0
- package/dist/handler/index.d.ts +6 -1
- package/dist/handler/is.d.ts +2 -0
- package/dist/handler/types-base.d.ts +6 -0
- package/dist/handler/types.d.ts +5 -0
- package/dist/index.cjs +1202 -629
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +1172 -597
- package/dist/index.mjs.map +1 -1
- package/dist/layer/constants.d.ts +1 -0
- package/dist/layer/module.d.ts +13 -10
- package/dist/layer/type.d.ts +6 -4
- package/dist/path/index.d.ts +1 -0
- package/dist/path/matcher.d.ts +5 -6
- package/dist/path/type.d.ts +1 -0
- package/dist/path/utils.d.ts +2 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/is.d.ts +2 -0
- package/dist/plugin/types.d.ts +32 -0
- package/dist/{helpers/request → request/helpers}/body.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/cache.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/cookie.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/env.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept-charset.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept-language.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-content-type.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/hostname.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/index.d.ts +1 -0
- package/dist/{helpers/request → request/helpers}/ip.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/mount-path.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/negotiator.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/params.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/path.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/protocol.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/query.d.ts +1 -1
- package/dist/request/helpers/router.d.ts +3 -0
- package/dist/request/index.d.ts +3 -0
- package/dist/request/module.d.ts +4 -0
- package/dist/request/types.d.ts +13 -0
- package/dist/{helpers/response → response/helpers}/cache.d.ts +1 -1
- package/dist/response/helpers/gone.d.ts +2 -0
- package/dist/{helpers/response → response/helpers}/header-attachment.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/header-content-type.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/header.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/index.d.ts +3 -0
- package/dist/{helpers/response → response/helpers}/send-accepted.d.ts +2 -2
- package/dist/{helpers/response → response/helpers}/send-created.d.ts +2 -2
- package/dist/response/helpers/send-file.d.ts +17 -0
- package/dist/{helpers/response → response/helpers}/send-format.d.ts +1 -1
- package/dist/response/helpers/send-redirect.d.ts +2 -0
- package/dist/response/helpers/send-stream.d.ts +3 -0
- package/dist/response/helpers/send-web-blob.d.ts +3 -0
- package/dist/response/helpers/send-web-response.d.ts +3 -0
- package/dist/response/helpers/send.d.ts +2 -0
- package/dist/response/helpers/utils.d.ts +2 -0
- package/dist/response/index.d.ts +3 -0
- package/dist/response/module.d.ts +3 -0
- package/dist/response/types.d.ts +4 -0
- package/dist/router/constants.d.ts +1 -0
- package/dist/router/index.d.ts +1 -1
- package/dist/router/module.d.ts +34 -50
- package/dist/router/utils.d.ts +3 -0
- package/dist/router-options/index.d.ts +2 -0
- package/dist/router-options/module.d.ts +4 -0
- package/dist/router-options/transform.d.ts +2 -0
- package/dist/router-options/type.d.ts +41 -0
- package/dist/types.d.ts +10 -0
- package/dist/utils/cookie.d.ts +1 -0
- package/dist/utils/etag/module.d.ts +4 -3
- package/dist/utils/etag/type.d.ts +1 -1
- package/dist/utils/header.d.ts +3 -0
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/is-instance.d.ts +1 -1
- package/dist/utils/path.d.ts +5 -2
- package/dist/utils/stream.d.ts +8 -0
- package/dist/utils/web.d.ts +3 -0
- package/package.json +21 -19
- package/dist/config/module.d.ts +0 -8
- package/dist/config/type.d.ts +0 -34
- package/dist/handler/utils.d.ts +0 -2
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/response/send-file.d.ts +0 -9
- package/dist/helpers/response/send-redirect.d.ts +0 -2
- package/dist/helpers/response/send-stream.d.ts +0 -4
- package/dist/helpers/response/send.d.ts +0 -2
- package/dist/helpers/response/utils.d.ts +0 -3
- package/dist/route/module.d.ts +0 -27
- package/dist/route/type.d.ts +0 -6
- package/dist/route/utils.d.ts +0 -2
- package/dist/router/type.d.ts +0 -24
- package/dist/type.d.ts +0 -24
- package/dist/utils/request.d.ts +0 -2
- /package/dist/{config → dispatcher/adapters/raw}/index.d.ts +0 -0
- /package/dist/{helpers/request → request/helpers}/header-accept-encoding.d.ts +0 -0
package/README.md
CHANGED
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
[](https://snyk.io/test/github/Tada5hi/routup)
|
|
13
13
|
[](https://conventionalcommits.org)
|
|
14
14
|
|
|
15
|
-
**Routup** is a lightweight,
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
- 🚀
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
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
|
-
-
|
|
44
|
-
-
|
|
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 {
|
|
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('/', (
|
|
61
|
-
|
|
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
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
| [body](https://
|
|
76
|
-
| [cookie](https://
|
|
77
|
-
| [decorators](https://
|
|
78
|
-
| [prometheus](https://
|
|
79
|
-
| [query](https://
|
|
80
|
-
| [rate-limit](https://
|
|
81
|
-
| [rate-limit-redis](https://
|
|
82
|
-
| [static](https://
|
|
83
|
-
| [swagger](https://
|
|
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 @@
|
|
|
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
|
+
};
|
|
@@ -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,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,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,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
|
+
};
|
package/dist/handler/index.d.ts
CHANGED
|
@@ -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;
|