expediate 1.0.4 → 1.0.6
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/CHANGELOG.md +138 -0
- package/CONTRIBUTING.md +150 -0
- package/LICENSE +16 -16
- package/README.md +330 -444
- package/dist/apis.d.ts +504 -27
- package/dist/apis.d.ts.map +1 -1
- package/dist/apis.js +618 -107
- package/dist/apis.js.map +1 -1
- package/dist/cjs/index.js +4066 -0
- package/dist/cjs/package.json +1 -0
- package/dist/git.d.ts +72 -9
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +129 -74
- package/dist/git.js.map +1 -1
- package/dist/http-objects.d.ts +26 -0
- package/dist/http-objects.d.ts.map +1 -0
- package/dist/http-objects.js +588 -0
- package/dist/http-objects.js.map +1 -0
- package/dist/index.d.ts +18 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -24
- package/dist/index.js.map +1 -1
- package/dist/jwt-auth.d.ts +158 -57
- package/dist/jwt-auth.d.ts.map +1 -1
- package/dist/jwt-auth.js +447 -207
- package/dist/jwt-auth.js.map +1 -1
- package/dist/middleware.d.ts +476 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +647 -0
- package/dist/middleware.js.map +1 -0
- package/dist/mimetypes.json +882 -1
- package/dist/misc.d.ts +268 -25
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +449 -168
- package/dist/misc.js.map +1 -1
- package/dist/openapi.d.ts +433 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +624 -0
- package/dist/openapi.js.map +1 -0
- package/dist/router-types.d.ts +760 -0
- package/dist/router-types.d.ts.map +1 -0
- package/dist/router-types.js +23 -0
- package/dist/router-types.js.map +1 -0
- package/dist/router.d.ts +37 -201
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +502 -244
- package/dist/router.js.map +1 -1
- package/dist/static.d.ts +3 -3
- package/dist/static.d.ts.map +1 -1
- package/dist/static.js +164 -105
- package/dist/static.js.map +1 -1
- package/docs/THREAT_MODEL.md +52 -0
- package/docs/api-builder-v2-design.md +644 -0
- package/docs/api-builder-v3-design.md +397 -0
- package/docs/api-builder.md +454 -0
- package/docs/benchmark.md +27 -0
- package/docs/body-parsing.md +223 -0
- package/docs/errors.md +359 -0
- package/docs/expediate.png +0 -0
- package/docs/git.md +139 -0
- package/docs/jwt-auth.md +251 -0
- package/docs/logo.svg +12 -0
- package/docs/middleware.md +264 -0
- package/docs/openapi.md +180 -0
- package/docs/router.md +356 -0
- package/docs/static.md +128 -0
- package/docs/wiki.json +123 -0
- package/package.json +47 -8
- package/.npmignore +0 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-types.d.ts","sourceRoot":"","sources":["../src/router-types.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,KAAK,IAAI,MAAO,MAAM,CAAC;AACnC,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,kDAAkD;AAClD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,eAAe;IACzD,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,MAAM,EAAE,SAAS,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software and associated documentation files (the "Software"),
|
|
5
|
+
* to deal in the Software without restriction, including without limitation
|
|
6
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
7
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
8
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
*
|
|
10
|
+
* The above copyright notice and this permission notice shall be included
|
|
11
|
+
* in all copies or substantial portions of the Software.
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
14
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
19
|
+
* DEALINGS IN THE SOFTWARE.
|
|
20
|
+
*/
|
|
21
|
+
'use strict';
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=router-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-types.js","sourceRoot":"","sources":["../src/router-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,CAAC"}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,176 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BodyOptions } from './misc';
|
|
3
|
-
/** A key-value map of arbitrary string values. */
|
|
4
|
-
type StringMap = Record<string, string>;
|
|
5
|
-
/**
|
|
6
|
-
* Extended HTTP incoming message that carries parsed routing metadata.
|
|
7
|
-
* Augments the standard `http.IncomingMessage` with fields populated by
|
|
8
|
-
* the router before any middleware is invoked.
|
|
9
|
-
*/
|
|
10
|
-
interface RouterRequest extends http.IncomingMessage {
|
|
11
|
-
/** The original, unmodified URL string from the HTTP request. */
|
|
12
|
-
originalUrl: string;
|
|
13
|
-
/**
|
|
14
|
-
* The current path being matched. Prefix-style layers (`use`)
|
|
15
|
-
* rewrite this field after matching so that nested routers only see the
|
|
16
|
-
* remaining suffix. Exact-method layers (`all`, `get`, `post`, etc.) leave it
|
|
17
|
-
* untouched so that chained middlewares sharing the same path each match.
|
|
18
|
-
*/
|
|
19
|
-
path: string;
|
|
20
|
-
/**
|
|
21
|
-
* Aggregated parameters from all sources.
|
|
22
|
-
* URL query parameters are merged first; named route parameters (from both
|
|
23
|
-
* plain-string and RegExp patterns) override them when a route matches.
|
|
24
|
-
*/
|
|
25
|
-
params: StringMap;
|
|
26
|
-
/**
|
|
27
|
-
* Structured query buckets:
|
|
28
|
-
* - `url` — parameters parsed from the query string.
|
|
29
|
-
* - `route` — named parameters captured from the route pattern.
|
|
30
|
-
*/
|
|
31
|
-
queries: {
|
|
32
|
-
url?: StringMap;
|
|
33
|
-
route?: StringMap;
|
|
34
|
-
};
|
|
35
|
-
/** Parsed cookies sent with the request. */
|
|
36
|
-
cookies: StringMap;
|
|
37
|
-
json(opts?: BodyOptions): Promise<unknown | null>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Extended HTTP server response with convenience helpers.
|
|
41
|
-
* Augments the standard `http.ServerResponse`.
|
|
42
|
-
*/
|
|
43
|
-
interface RouterResponse extends http.ServerResponse {
|
|
44
|
-
/**
|
|
45
|
-
* Write `data` (if provided) and end the response.
|
|
46
|
-
* Equivalent to `res.write(data); res.end()`.
|
|
47
|
-
*/
|
|
48
|
-
send(data?: string): void;
|
|
49
|
-
json(data: unknown): void;
|
|
50
|
-
/**
|
|
51
|
-
* Set the HTTP status code and optional response headers, then return
|
|
52
|
-
* `this` so calls can be chained (e.g. `res.status(404).end(...)`).
|
|
53
|
-
*/
|
|
54
|
-
status(code: number, headers?: StringMap): this;
|
|
55
|
-
/** Redirect the client to `url` with a 302 Found response. */
|
|
56
|
-
redirect(url: string): void;
|
|
57
|
-
/**
|
|
58
|
-
* Append a `Set-Cookie` header for the given `name`/`value` pair.
|
|
59
|
-
* Returns `this` to allow chaining.
|
|
60
|
-
*/
|
|
61
|
-
cookie(name: string, value: string | object, options?: CookieOptions): this;
|
|
62
|
-
}
|
|
63
|
-
/** Options accepted by `res.cookie()`. */
|
|
64
|
-
interface CookieOptions {
|
|
65
|
-
/** Sign the cookie value (requires a secret on the request). */
|
|
66
|
-
signed?: boolean;
|
|
67
|
-
/** Expiry date for the cookie. */
|
|
68
|
-
expires?: Date;
|
|
69
|
-
/** Max age in milliseconds; converted to seconds in the `Set-Cookie` header. */
|
|
70
|
-
maxAge?: number;
|
|
71
|
-
/** Cookie path (defaults to `'/'`). */
|
|
72
|
-
path?: string;
|
|
73
|
-
}
|
|
74
|
-
/** Options for HTTPS servers passed to `router.listen()`. */
|
|
75
|
-
interface TlsOptions {
|
|
76
|
-
key: string | Buffer;
|
|
77
|
-
cert: string | Buffer;
|
|
78
|
-
[key: string]: unknown;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* A middleware function. Receives the current request and response objects
|
|
82
|
-
* and a `next` callback to hand control to the next registered middleware.
|
|
83
|
-
*/
|
|
84
|
-
type Middleware = (req: RouterRequest, res: RouterResponse, next: NextFunction) => void;
|
|
85
|
-
/** Callback used to pass control to the next matching middleware. */
|
|
86
|
-
type NextFunction = () => void;
|
|
87
|
-
/**
|
|
88
|
-
* A value that can be registered as a route handler: a single `Middleware`
|
|
89
|
-
* function, a `Router` instance (whose `listener` will be used), or an array
|
|
90
|
-
* of either. Arrays may not be nested.
|
|
91
|
-
*/
|
|
92
|
-
type MiddlewareArg = Middleware | Router | (Middleware | Router)[];
|
|
93
|
-
/**
|
|
94
|
-
* Internal representation of a single registered route.
|
|
95
|
-
* One layer is created per middleware function for every `router.get(...)` /
|
|
96
|
-
* `router.use(...)` etc. call, and stored in the route table.
|
|
97
|
-
*/
|
|
98
|
-
interface Layer {
|
|
99
|
-
/** HTTP method this layer is restricted to, or `null` for any method. */
|
|
100
|
-
method: string | null;
|
|
101
|
-
/** The original path pattern supplied by the caller. */
|
|
102
|
-
path: string | RegExp;
|
|
103
|
-
/**
|
|
104
|
-
* The compiled `RegExp` used for matching, regardless of whether the
|
|
105
|
-
* original `path` was a plain string, a glob, or already a `RegExp`.
|
|
106
|
-
*
|
|
107
|
-
* - Plain strings (e.g. `'/users/:id'`) are compiled with named capture
|
|
108
|
-
* groups so that `:id` becomes `(?<id>[^/]+)`.
|
|
109
|
-
* - Glob strings (e.g. `'/**\/*.php'`) are compiled following `.gitignore`
|
|
110
|
-
* wildcard rules.
|
|
111
|
-
* - `RegExp` values are stored as-is; named groups are surfaced directly
|
|
112
|
-
* as route parameters.
|
|
113
|
-
*/
|
|
114
|
-
regex: RegExp;
|
|
115
|
-
/**
|
|
116
|
-
* When `true`, the portion of `req.path` consumed by `layer.regex` is
|
|
117
|
-
* stripped before invoking the middleware, exposing only the remaining
|
|
118
|
-
* suffix to nested routers.
|
|
119
|
-
*
|
|
120
|
-
* Set to `true` for prefix-style registrations (`use`) and
|
|
121
|
-
* `false` for exact-method routes (`all`, `get`, `post`, etc.). Stripping on
|
|
122
|
-
* exact-match routes would break chained middlewares sharing the same path,
|
|
123
|
-
* because each subsequent layer would see a truncated path that no longer
|
|
124
|
-
* matches its own pattern.
|
|
125
|
-
*/
|
|
126
|
-
stripPath: boolean;
|
|
127
|
-
/** The middleware function to invoke when the layer matches. */
|
|
128
|
-
middleware: Middleware;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* The public interface of the object returned by `createRouter()`.
|
|
132
|
-
*
|
|
133
|
-
* All route-registration methods share the same uniform signature: a mandatory
|
|
134
|
-
* `path` argument followed by any number of `MiddlewareArg` values.
|
|
135
|
-
* A `MiddlewareArg` may be a `Middleware` function, a `Router` instance
|
|
136
|
-
* (whose `listener` is used automatically), or an array of either.
|
|
137
|
-
*/
|
|
138
|
-
interface Router {
|
|
139
|
-
/**
|
|
140
|
-
* Register middleware for all HTTP methods, scoped to `path`.
|
|
141
|
-
* The matched path prefix is stripped from `req.path` before the middleware
|
|
142
|
-
* is invoked, so nested routers only see the remaining suffix.
|
|
143
|
-
* Equivalent to Express's `app.use()`.
|
|
144
|
-
*/
|
|
145
|
-
use(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
146
|
-
/**
|
|
147
|
-
* Register middleware for all HTTP methods.
|
|
148
|
-
* Unlike `use`, it doesn't strips the matched prefix from `req.path`.
|
|
149
|
-
*/
|
|
150
|
-
all(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
151
|
-
/** Register middleware for `GET` requests. */
|
|
152
|
-
get(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
153
|
-
/** Register middleware for `PUT` requests. */
|
|
154
|
-
put(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
155
|
-
/** Register middleware for `POST` requests. */
|
|
156
|
-
post(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
157
|
-
/** Register middleware for `DELETE` requests. */
|
|
158
|
-
delete(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
159
|
-
/** Register middleware for `PATCH` requests. */
|
|
160
|
-
patch(path: string | RegExp, ...args: MiddlewareArg[]): void;
|
|
161
|
-
/**
|
|
162
|
-
* Start listening on the given port.
|
|
163
|
-
* When `opts` contains both `key` and `cert`, an HTTPS server is created;
|
|
164
|
-
* otherwise a plain HTTP server is used.
|
|
165
|
-
*/
|
|
166
|
-
listen(port: number, opts?: TlsOptions | (() => void), cb?: () => void): void;
|
|
167
|
-
/**
|
|
168
|
-
* The underlying `(req, res, next)` function, allowing this router to be
|
|
169
|
-
* mounted as middleware inside another router:
|
|
170
|
-
* `parent.use('/api', child)`.
|
|
171
|
-
*/
|
|
172
|
-
readonly listener: Middleware;
|
|
173
|
-
}
|
|
1
|
+
import type { RouterOptions, Router } from './router-types.js';
|
|
174
2
|
/**
|
|
175
3
|
* Create and return a new `Router` instance.
|
|
176
4
|
*
|
|
@@ -179,49 +7,57 @@ interface Router {
|
|
|
179
7
|
* mounted inside another router:
|
|
180
8
|
* ```ts
|
|
181
9
|
* parent.use('/api', child);
|
|
10
|
+
* // or, if child has a prefix:
|
|
11
|
+
* parent.use(child);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Prefix shorthand:**
|
|
15
|
+
* Pass a path string as the first argument to associate a prefix with this
|
|
16
|
+
* router. The prefix is used automatically when the router is mounted via
|
|
17
|
+
* `parent.use(child)`:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const v1 = createRouter('/api/v1');
|
|
20
|
+
* v1.get('/users', handler); // handler is reached at /api/v1/users
|
|
21
|
+
* app.use(v1); // same as app.use('/api/v1', v1)
|
|
182
22
|
* ```
|
|
183
23
|
*
|
|
184
24
|
* **Path patterns** accepted by all route-registration methods:
|
|
185
25
|
* - Plain strings with optional `:name` segments — e.g. `'/users/:id'`.
|
|
186
|
-
* Each `:name` is compiled to a named capture group and exposed in
|
|
187
|
-
* `req.params` on a match.
|
|
188
26
|
* - Glob strings following `.gitignore` rules — e.g. `'/**\/*.php'`.
|
|
189
|
-
* Supported wildcards: `?` (one non-slash char), `*` (any non-slash chars),
|
|
190
|
-
* `**` (any chars, including slashes).
|
|
191
27
|
* - `RegExp` objects — used directly; named groups become route parameters.
|
|
192
28
|
*
|
|
193
|
-
* **
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* - A `Router` instance (its `listener` is registered automatically).
|
|
197
|
-
* - An array of either of the above.
|
|
29
|
+
* **Error handling:**
|
|
30
|
+
* Register a global error handler with `router.onError()`. It is called
|
|
31
|
+
* when any middleware throws, rejects, or calls `next(err)`.
|
|
198
32
|
*
|
|
199
|
-
* **
|
|
200
|
-
*
|
|
201
|
-
* invoking middleware. Nested routers therefore only see the remaining suffix.
|
|
202
|
-
* - `all` / `get` / `post` / `put` / `delete` / `patch` — leave `req.path` intact
|
|
203
|
-
* so that multiple middlewares registered for the same exact path can each
|
|
204
|
-
* match and be invoked in sequence via `next()`.
|
|
33
|
+
* **Graceful shutdown:**
|
|
34
|
+
* Call `router.shutdown()` to stop the server created by `router.listen()`.
|
|
205
35
|
*
|
|
206
|
-
* @
|
|
207
|
-
*
|
|
36
|
+
* @param prefixOrOpts - Optional path prefix string (e.g. `'/api/v1'`) **or**
|
|
37
|
+
* an {@link RouterOptions} object.
|
|
38
|
+
* @param opts - Options when `prefixOrOpts` is a string.
|
|
39
|
+
* @returns A fully initialised `Router`.
|
|
208
40
|
*
|
|
209
41
|
* @example
|
|
210
42
|
* ```ts
|
|
211
|
-
* const
|
|
212
|
-
*
|
|
213
|
-
*
|
|
43
|
+
* const app = createRouter({ secret: process.env.COOKIE_SECRET, timeout: 30_000 });
|
|
44
|
+
*
|
|
45
|
+
* const v1 = createRouter('/api/v1');
|
|
46
|
+
* v1.get('/users', handler);
|
|
47
|
+
*
|
|
48
|
+
* app.use(v1);
|
|
49
|
+
* app.onError((err, _req, res) => res.status(500).json({ error: String(err) }));
|
|
214
50
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* app.
|
|
219
|
-
* res.status(403).send('Forbidden'));
|
|
51
|
+
* // Custom 404: register a catch-all as the LAST layer. Because layers match
|
|
52
|
+
* // in registration order, it only runs when nothing earlier claimed the
|
|
53
|
+
* // request. Use `all('/**', …)` (glob) to match any method and path.
|
|
54
|
+
* app.all('/**', (_req, res) => res.status(404).json({ error: 'Not Found' }));
|
|
220
55
|
*
|
|
221
|
-
* app.listen(3000, () => console.log('Listening
|
|
56
|
+
* app.listen(3000, () => console.log('Listening'));
|
|
57
|
+
* process.on('SIGTERM', () => app.shutdown(10_000));
|
|
222
58
|
* ```
|
|
223
59
|
*/
|
|
224
|
-
declare function createRouter(): Router;
|
|
60
|
+
declare function createRouter(prefixOrOpts?: string | RouterOptions, opts?: RouterOptions): Router;
|
|
225
61
|
export default createRouter;
|
|
226
|
-
export type { Router, RouterRequest, RouterResponse, Middleware, MiddlewareArg, NextFunction, Layer, CookieOptions, TlsOptions, StringMap, };
|
|
62
|
+
export type { Router, RouterOptions, RouterRequest, RouterResponse, Middleware, MiddlewareArg, NextFunction, ErrorHandler, ErrorMiddleware, Layer, RouteInfo, RouteBuilder, CookieOptions, TlsOptions, StringMap, } from './router-types.js';
|
|
227
63
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAEV,aAAa,EAYb,MAAM,EACP,MAAM,mBAAmB,CAAC;AAoZ3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,iBAAS,YAAY,CACnB,YAAY,CAAC,EAAE,MAAM,GAAG,aAAa,EACrC,IAAI,CAAC,EAAE,aAAa,GACnB,MAAM,CA2WR;AAED,eAAe,YAAY,CAAC;AAC5B,YAAY,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,cAAc,EACd,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,KAAK,EACL,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,mBAAmB,CAAC"}
|