routup 4.0.2 → 5.0.0-beta.0
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 +87 -134
- package/dist/bun.cjs +66 -0
- package/dist/bun.cjs.map +1 -0
- package/dist/bun.d.cts +8 -0
- package/dist/bun.d.mts +8 -0
- package/dist/bun.mjs +13 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/cloudflare.cjs +66 -0
- package/dist/cloudflare.cjs.map +1 -0
- package/dist/cloudflare.d.cts +8 -0
- package/dist/cloudflare.d.mts +8 -0
- package/dist/cloudflare.mjs +13 -0
- package/dist/cloudflare.mjs.map +1 -0
- package/dist/deno.cjs +66 -0
- package/dist/deno.cjs.map +1 -0
- package/dist/deno.d.cts +8 -0
- package/dist/deno.d.mts +8 -0
- package/dist/deno.mjs +13 -0
- package/dist/deno.mjs.map +1 -0
- package/dist/generic.cjs +66 -0
- package/dist/generic.cjs.map +1 -0
- package/dist/generic.d.cts +8 -0
- package/dist/generic.d.mts +8 -0
- package/dist/generic.mjs +13 -0
- package/dist/generic.mjs.map +1 -0
- package/dist/index-9K5FcIb3.d.cts +786 -0
- package/dist/index-B6F5CzQy.d.mts +786 -0
- package/dist/node.cjs +70 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +11 -0
- package/dist/node.d.mts +11 -0
- package/dist/node.mjs +16 -0
- package/dist/node.mjs.map +1 -0
- package/dist/service-worker.cjs +66 -0
- package/dist/service-worker.cjs.map +1 -0
- package/dist/service-worker.d.cts +10 -0
- package/dist/service-worker.d.mts +10 -0
- package/dist/service-worker.mjs +13 -0
- package/dist/service-worker.mjs.map +1 -0
- package/dist/src-C789deGE.mjs +1599 -0
- package/dist/src-C789deGE.mjs.map +1 -0
- package/dist/src-Ca2_b8P0.cjs +1939 -0
- package/dist/src-Ca2_b8P0.cjs.map +1 -0
- package/package.json +76 -36
- package/dist/adapters/index.d.ts +0 -3
- package/dist/adapters/node/index.d.ts +0 -1
- package/dist/adapters/node/module.d.ts +0 -6
- package/dist/adapters/raw/header.d.ts +0 -3
- package/dist/adapters/raw/index.d.ts +0 -3
- package/dist/adapters/raw/module.d.ts +0 -4
- package/dist/adapters/raw/type.d.ts +0 -18
- package/dist/adapters/web/index.d.ts +0 -2
- package/dist/adapters/web/module.d.ts +0 -4
- package/dist/adapters/web/type.d.ts +0 -3
- package/dist/constants.d.ts +0 -42
- package/dist/dispatcher/event/dispatch.d.ts +0 -4
- package/dist/dispatcher/event/error.d.ts +0 -5
- package/dist/dispatcher/event/index.d.ts +0 -5
- package/dist/dispatcher/event/is.d.ts +0 -3
- package/dist/dispatcher/event/module.d.ts +0 -56
- package/dist/dispatcher/event/types.d.ts +0 -9
- package/dist/dispatcher/index.d.ts +0 -2
- package/dist/dispatcher/type.d.ts +0 -4
- package/dist/error/create.d.ts +0 -11
- package/dist/error/index.d.ts +0 -3
- package/dist/error/is.d.ts +0 -2
- package/dist/error/module.d.ts +0 -3
- package/dist/handler/constants.d.ts +0 -5
- package/dist/handler/core/define.d.ts +0 -4
- package/dist/handler/core/index.d.ts +0 -2
- package/dist/handler/core/types.d.ts +0 -10
- package/dist/handler/error/define.d.ts +0 -4
- package/dist/handler/error/index.d.ts +0 -2
- package/dist/handler/error/types.d.ts +0 -11
- package/dist/handler/index.d.ts +0 -7
- package/dist/handler/is.d.ts +0 -4
- package/dist/handler/module.d.ts +0 -23
- package/dist/handler/types-base.d.ts +0 -10
- package/dist/handler/types.d.ts +0 -4
- package/dist/hook/constants.d.ts +0 -8
- package/dist/hook/index.d.ts +0 -3
- package/dist/hook/module.d.ts +0 -19
- package/dist/hook/types.d.ts +0 -5
- package/dist/index.cjs +0 -2314
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.mjs +0 -2235
- package/dist/index.mjs.map +0 -1
- package/dist/path/index.d.ts +0 -3
- package/dist/path/matcher.d.ts +0 -11
- package/dist/path/type.d.ts +0 -7
- package/dist/path/utils.d.ts +0 -2
- package/dist/plugin/index.d.ts +0 -2
- package/dist/plugin/is.d.ts +0 -2
- package/dist/plugin/types.d.ts +0 -23
- package/dist/request/helpers/cache.d.ts +0 -2
- package/dist/request/helpers/env.d.ts +0 -6
- package/dist/request/helpers/header-accept-charset.d.ts +0 -3
- package/dist/request/helpers/header-accept-encoding.d.ts +0 -3
- package/dist/request/helpers/header-accept-language.d.ts +0 -3
- package/dist/request/helpers/header-accept.d.ts +0 -3
- package/dist/request/helpers/header-content-type.d.ts +0 -2
- package/dist/request/helpers/header.d.ts +0 -4
- package/dist/request/helpers/hostname.d.ts +0 -7
- package/dist/request/helpers/http2.d.ts +0 -2
- package/dist/request/helpers/index.d.ts +0 -17
- package/dist/request/helpers/ip.d.ts +0 -7
- package/dist/request/helpers/mount-path.d.ts +0 -3
- package/dist/request/helpers/negotiator.d.ts +0 -3
- package/dist/request/helpers/params.d.ts +0 -5
- package/dist/request/helpers/path.d.ts +0 -2
- package/dist/request/helpers/protocol.d.ts +0 -8
- package/dist/request/helpers/router.d.ts +0 -3
- package/dist/request/index.d.ts +0 -3
- package/dist/request/module.d.ts +0 -3
- package/dist/request/types.d.ts +0 -12
- package/dist/response/helpers/cache.d.ts +0 -7
- package/dist/response/helpers/event-stream/factory.d.ts +0 -3
- package/dist/response/helpers/event-stream/index.d.ts +0 -2
- package/dist/response/helpers/event-stream/module.d.ts +0 -17
- package/dist/response/helpers/event-stream/types.d.ts +0 -24
- package/dist/response/helpers/event-stream/utils.d.ts +0 -2
- package/dist/response/helpers/gone.d.ts +0 -3
- package/dist/response/helpers/header-attachment.d.ts +0 -2
- package/dist/response/helpers/header-content-type.d.ts +0 -2
- package/dist/response/helpers/header.d.ts +0 -4
- package/dist/response/helpers/index.d.ts +0 -16
- package/dist/response/helpers/send-accepted.d.ts +0 -2
- package/dist/response/helpers/send-created.d.ts +0 -2
- package/dist/response/helpers/send-file.d.ts +0 -17
- package/dist/response/helpers/send-format.d.ts +0 -7
- package/dist/response/helpers/send-redirect.d.ts +0 -2
- package/dist/response/helpers/send-stream.d.ts +0 -3
- package/dist/response/helpers/send-web-blob.d.ts +0 -3
- package/dist/response/helpers/send-web-response.d.ts +0 -3
- package/dist/response/helpers/send.d.ts +0 -2
- package/dist/response/helpers/utils.d.ts +0 -2
- package/dist/response/index.d.ts +0 -3
- package/dist/response/module.d.ts +0 -3
- package/dist/response/types.d.ts +0 -3
- package/dist/router/constants.d.ts +0 -9
- package/dist/router/index.d.ts +0 -1
- package/dist/router/module.d.ts +0 -89
- package/dist/router/types.d.ts +0 -7
- package/dist/router/utils.d.ts +0 -3
- package/dist/router-options/index.d.ts +0 -2
- package/dist/router-options/module.d.ts +0 -4
- package/dist/router-options/transform.d.ts +0 -2
- package/dist/router-options/type.d.ts +0 -41
- package/dist/types.d.ts +0 -9
- package/dist/utils/cookie.d.ts +0 -1
- package/dist/utils/etag/index.d.ts +0 -3
- package/dist/utils/etag/module.d.ts +0 -11
- package/dist/utils/etag/type.d.ts +0 -15
- package/dist/utils/etag/utils.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -13
- package/dist/utils/is-instance.d.ts +0 -1
- package/dist/utils/method.d.ts +0 -3
- package/dist/utils/mime.d.ts +0 -2
- package/dist/utils/next.d.ts +0 -2
- package/dist/utils/object.d.ts +0 -3
- package/dist/utils/path.d.ts +0 -5
- package/dist/utils/promise.d.ts +0 -1
- package/dist/utils/stream.d.ts +0 -6
- package/dist/utils/trust-proxy/index.d.ts +0 -2
- package/dist/utils/trust-proxy/module.d.ts +0 -2
- package/dist/utils/trust-proxy/type.d.ts +0 -2
- package/dist/utils/url.d.ts +0 -7
- package/dist/utils/web.d.ts +0 -3
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
import { FastURL, ServerRequest } from "srvx";
|
|
2
|
+
import { HTTPError, HTTPErrorInput, HTTPErrorInput as HTTPErrorInput$1 } from "@ebec/http";
|
|
3
|
+
import { Key, ParseOptions, PathToRegexpOptions } from "path-to-regexp";
|
|
4
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
5
|
+
import Negotiator from "negotiator";
|
|
6
|
+
|
|
7
|
+
//#region src/constants.d.ts
|
|
8
|
+
declare enum MethodName {
|
|
9
|
+
GET = "GET",
|
|
10
|
+
POST = "POST",
|
|
11
|
+
PUT = "PUT",
|
|
12
|
+
PATCH = "PATCH",
|
|
13
|
+
DELETE = "DELETE",
|
|
14
|
+
OPTIONS = "OPTIONS",
|
|
15
|
+
HEAD = "HEAD"
|
|
16
|
+
}
|
|
17
|
+
declare enum HeaderName {
|
|
18
|
+
ACCEPT = "accept",
|
|
19
|
+
ACCEPT_CHARSET = "accept-charset",
|
|
20
|
+
ACCEPT_ENCODING = "accept-encoding",
|
|
21
|
+
ACCEPT_LANGUAGE = "accept-language",
|
|
22
|
+
ACCEPT_RANGES = "accept-ranges",
|
|
23
|
+
ALLOW = "allow",
|
|
24
|
+
CACHE_CONTROL = "cache-control",
|
|
25
|
+
CONTENT_DISPOSITION = "content-disposition",
|
|
26
|
+
CONTENT_ENCODING = "content-encoding",
|
|
27
|
+
CONTENT_LENGTH = "content-length",
|
|
28
|
+
CONTENT_RANGE = "content-range",
|
|
29
|
+
CONTENT_TYPE = "content-type",
|
|
30
|
+
CONNECTION = "connection",
|
|
31
|
+
COOKIE = "cookie",
|
|
32
|
+
ETag = "etag",
|
|
33
|
+
HOST = "host",
|
|
34
|
+
IF_MODIFIED_SINCE = "if-modified-since",
|
|
35
|
+
IF_NONE_MATCH = "if-none-match",
|
|
36
|
+
LAST_MODIFIED = "last-modified",
|
|
37
|
+
LOCATION = "location",
|
|
38
|
+
RANGE = "range",
|
|
39
|
+
RATE_LIMIT_LIMIT = "ratelimit-limit",
|
|
40
|
+
RATE_LIMIT_REMAINING = "ratelimit-remaining",
|
|
41
|
+
RATE_LIMIT_RESET = "ratelimit-reset",
|
|
42
|
+
RETRY_AFTER = "retry-after",
|
|
43
|
+
SET_COOKIE = "set-cookie",
|
|
44
|
+
TRANSFER_ENCODING = "transfer-encoding",
|
|
45
|
+
X_ACCEL_BUFFERING = "x-accel-buffering",
|
|
46
|
+
X_FORWARDED_HOST = "x-forwarded-host",
|
|
47
|
+
X_FORWARDED_FOR = "x-forwarded-for",
|
|
48
|
+
X_FORWARDED_PROTO = "x-forwarded-proto"
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/error/module.d.ts
|
|
52
|
+
declare class RoutupError extends HTTPError {
|
|
53
|
+
constructor(input?: HTTPErrorInput$1);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/event/types.d.ts
|
|
57
|
+
type RoutupResponse = {
|
|
58
|
+
status: number;
|
|
59
|
+
headers: Headers;
|
|
60
|
+
statusText?: string;
|
|
61
|
+
};
|
|
62
|
+
type RoutupRequest = ServerRequest;
|
|
63
|
+
interface IRoutupEvent {
|
|
64
|
+
/**
|
|
65
|
+
* The srvx ServerRequest (extends Web Standard Request).
|
|
66
|
+
*/
|
|
67
|
+
readonly request: RoutupRequest;
|
|
68
|
+
/**
|
|
69
|
+
* Route parameters extracted from the URL path pattern.
|
|
70
|
+
*/
|
|
71
|
+
params: Record<string, any>;
|
|
72
|
+
/**
|
|
73
|
+
* Current request path, adjusted relative to the mount point during router nesting.
|
|
74
|
+
*/
|
|
75
|
+
path: string;
|
|
76
|
+
/**
|
|
77
|
+
* HTTP method (GET, POST, PUT, etc.).
|
|
78
|
+
*/
|
|
79
|
+
readonly method: string;
|
|
80
|
+
/**
|
|
81
|
+
* Accumulated mount path from nested routers.
|
|
82
|
+
*/
|
|
83
|
+
mountPath: string;
|
|
84
|
+
/**
|
|
85
|
+
* Error that occurred during dispatch, if any.
|
|
86
|
+
*/
|
|
87
|
+
error?: RoutupError;
|
|
88
|
+
/**
|
|
89
|
+
* Router ID stack for nesting tracking.
|
|
90
|
+
* Used internally by router options resolution.
|
|
91
|
+
*/
|
|
92
|
+
routerPath: number[];
|
|
93
|
+
/**
|
|
94
|
+
* Web Standard Headers from the request.
|
|
95
|
+
*/
|
|
96
|
+
readonly headers: Headers;
|
|
97
|
+
/**
|
|
98
|
+
* Lazily-parsed URL search parameters.
|
|
99
|
+
*
|
|
100
|
+
* For advanced query parsing (arrays, nesting), use `@routup/query`.
|
|
101
|
+
*/
|
|
102
|
+
readonly searchParams: URLSearchParams;
|
|
103
|
+
/**
|
|
104
|
+
* Response accumulator — set status/headers before returning a plain value.
|
|
105
|
+
*
|
|
106
|
+
* If the handler returns a `Response` object directly, these values are
|
|
107
|
+
* ignored. They only apply when returning plain values (string, object, etc.)
|
|
108
|
+
* that go through `toResponse()`.
|
|
109
|
+
*/
|
|
110
|
+
readonly response: RoutupResponse;
|
|
111
|
+
/**
|
|
112
|
+
* Whether a response has been produced.
|
|
113
|
+
*/
|
|
114
|
+
dispatched: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Per-request store for caching and plugin state.
|
|
117
|
+
*
|
|
118
|
+
* Use symbol keys (e.g., `Symbol.for('routup:body')`) to avoid collisions.
|
|
119
|
+
* Data is garbage collected with the event when the request completes.
|
|
120
|
+
*/
|
|
121
|
+
readonly store: Record<string | symbol, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Call the next handler in the pipeline (onion model).
|
|
124
|
+
*
|
|
125
|
+
* The result is cached — calling `next()` multiple times returns the same response.
|
|
126
|
+
* Returns the downstream `Response`, or `undefined` if no handler matched.
|
|
127
|
+
*/
|
|
128
|
+
next(): Promise<Response | undefined>;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/event/module.d.ts
|
|
132
|
+
declare class RoutupEvent implements IRoutupEvent {
|
|
133
|
+
readonly request: RoutupRequest;
|
|
134
|
+
params: Record<string, any>;
|
|
135
|
+
path: string;
|
|
136
|
+
readonly method: string;
|
|
137
|
+
mountPath: string;
|
|
138
|
+
error?: RoutupError;
|
|
139
|
+
routerPath: number[];
|
|
140
|
+
/**
|
|
141
|
+
* Collected allowed methods (for OPTIONS).
|
|
142
|
+
*/
|
|
143
|
+
methodsAllowed: string[];
|
|
144
|
+
readonly store: Record<string | symbol, unknown>;
|
|
145
|
+
protected _dispatched: boolean;
|
|
146
|
+
protected _response?: RoutupResponse;
|
|
147
|
+
/**
|
|
148
|
+
* Cached parsed URL (avoids double-parsing).
|
|
149
|
+
*/
|
|
150
|
+
protected _url: InstanceType<typeof FastURL>;
|
|
151
|
+
protected _searchParams?: URLSearchParams;
|
|
152
|
+
/**
|
|
153
|
+
* Continuation function for middleware onion model.
|
|
154
|
+
*/
|
|
155
|
+
_next?: () => Promise<Response | undefined>;
|
|
156
|
+
/**
|
|
157
|
+
* Whether _next has already been called (guard against double-invocation).
|
|
158
|
+
*/
|
|
159
|
+
_nextCalled: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* The cached result of the next handler.
|
|
162
|
+
*/
|
|
163
|
+
_nextResult?: Promise<Response | undefined>;
|
|
164
|
+
constructor(request: RoutupRequest);
|
|
165
|
+
get headers(): Headers;
|
|
166
|
+
get searchParams(): URLSearchParams;
|
|
167
|
+
get response(): RoutupResponse;
|
|
168
|
+
get dispatched(): boolean;
|
|
169
|
+
set dispatched(value: boolean);
|
|
170
|
+
next(): Promise<Response | undefined>;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/dispatcher/types.d.ts
|
|
174
|
+
interface IDispatcher {
|
|
175
|
+
dispatch(event: RoutupEvent): Promise<Response | undefined>;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/hook/constants.d.ts
|
|
179
|
+
declare enum HookName {
|
|
180
|
+
REQUEST = "request",
|
|
181
|
+
RESPONSE = "response",
|
|
182
|
+
ERROR = "error",
|
|
183
|
+
CHILD_MATCH = "childMatch",
|
|
184
|
+
CHILD_DISPATCH_BEFORE = "childDispatchBefore",
|
|
185
|
+
CHILD_DISPATCH_AFTER = "childDispatchAfter"
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/hook/types.d.ts
|
|
189
|
+
type HookErrorListener = (event: IRoutupEvent) => Promise<unknown> | unknown;
|
|
190
|
+
type HookDefaultListener = (event: IRoutupEvent) => Promise<unknown> | unknown;
|
|
191
|
+
type HookListener = HookErrorListener | HookDefaultListener;
|
|
192
|
+
type HookUnsubscribeFn = () => void;
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/hook/module.d.ts
|
|
195
|
+
declare class HookManager {
|
|
196
|
+
protected items: Record<string, HookListener[]>;
|
|
197
|
+
constructor();
|
|
198
|
+
addListener(name: `${HookName}`, fn: HookListener): HookUnsubscribeFn;
|
|
199
|
+
removeListener(name: `${HookName}`): void;
|
|
200
|
+
removeListener(name: `${HookName}`, fn: HookListener): void;
|
|
201
|
+
trigger(name: `${HookName}`, event: IRoutupEvent): Promise<void>;
|
|
202
|
+
private triggerListener;
|
|
203
|
+
private isErrorListenerHook;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/path/type.d.ts
|
|
207
|
+
type PathMatcherOptions = PathToRegexpOptions & ParseOptions;
|
|
208
|
+
type PathMatcherExecResult = {
|
|
209
|
+
path: string;
|
|
210
|
+
params: Record<string, any>;
|
|
211
|
+
};
|
|
212
|
+
type Path = string;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/path/matcher.d.ts
|
|
215
|
+
declare class PathMatcher {
|
|
216
|
+
protected path: Path;
|
|
217
|
+
protected regexp: RegExp;
|
|
218
|
+
protected regexpKeys: Key[];
|
|
219
|
+
protected regexpOptions: PathMatcherOptions;
|
|
220
|
+
constructor(path: Path, options?: PathMatcherOptions);
|
|
221
|
+
test(path: string): boolean;
|
|
222
|
+
exec(path: string): PathMatcherExecResult | undefined;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/path/utils.d.ts
|
|
226
|
+
declare function isPath(input: unknown): input is Path;
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/handler/constants.d.ts
|
|
229
|
+
declare enum HandlerType {
|
|
230
|
+
CORE = "core",
|
|
231
|
+
ERROR = "error"
|
|
232
|
+
}
|
|
233
|
+
declare const HandlerSymbol: unique symbol;
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/handler/types-base.d.ts
|
|
236
|
+
type HandlerBaseConfig = {
|
|
237
|
+
method?: Uppercase<MethodName> | Lowercase<MethodName>;
|
|
238
|
+
path?: Path;
|
|
239
|
+
onError?: HookErrorListener;
|
|
240
|
+
onBefore?: HookDefaultListener;
|
|
241
|
+
onAfter?: HookDefaultListener;
|
|
242
|
+
};
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/handler/error/types.d.ts
|
|
245
|
+
type ErrorHandlerFn = (error: RoutupError, event: IRoutupEvent) => unknown | Promise<unknown>;
|
|
246
|
+
type ErrorHandlerConfig = HandlerBaseConfig & {
|
|
247
|
+
type: `${HandlerType.ERROR}`;
|
|
248
|
+
fn: ErrorHandlerFn;
|
|
249
|
+
};
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/handler/error/define.d.ts
|
|
252
|
+
declare function errorHandler(input: Omit<ErrorHandlerConfig, 'type'>): Handler;
|
|
253
|
+
declare function errorHandler(input: ErrorHandlerFn): Handler;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/handler/types.d.ts
|
|
256
|
+
type HandlerConfig = CoreHandlerConfig | ErrorHandlerConfig;
|
|
257
|
+
type HandlerFn = CoreHandlerFn | ErrorHandlerFn;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/handler/module.d.ts
|
|
260
|
+
declare class Handler implements IDispatcher {
|
|
261
|
+
readonly '@instanceof': symbol;
|
|
262
|
+
protected config: HandlerConfig;
|
|
263
|
+
protected hookManager: HookManager;
|
|
264
|
+
protected pathMatcher: PathMatcher | undefined;
|
|
265
|
+
protected _method: MethodName | undefined;
|
|
266
|
+
constructor(handler: HandlerConfig);
|
|
267
|
+
get type(): "error" | "core";
|
|
268
|
+
get path(): string | undefined;
|
|
269
|
+
get method(): MethodName | undefined;
|
|
270
|
+
dispatch(event: RoutupEvent): Promise<Response | undefined>;
|
|
271
|
+
matchPath(path: string): boolean;
|
|
272
|
+
setPath(path?: Path): void;
|
|
273
|
+
matchMethod(method: `${MethodName}`): boolean;
|
|
274
|
+
setMethod(input?: `${MethodName}`): void;
|
|
275
|
+
protected mountHooks(): void;
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/handler/core/types.d.ts
|
|
279
|
+
type CoreHandlerFn = (event: IRoutupEvent) => unknown | Promise<unknown>;
|
|
280
|
+
type CoreHandlerConfig = HandlerBaseConfig & {
|
|
281
|
+
type: `${HandlerType.CORE}`;
|
|
282
|
+
fn: CoreHandlerFn;
|
|
283
|
+
};
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/handler/core/define.d.ts
|
|
286
|
+
declare function coreHandler(input: Omit<CoreHandlerConfig, 'type'>): Handler;
|
|
287
|
+
declare function coreHandler(input: CoreHandlerFn): Handler;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/handler/helpers/from-node-handler.d.ts
|
|
290
|
+
type NodeHandler = (req: IncomingMessage, res: ServerResponse) => unknown | Promise<unknown>;
|
|
291
|
+
type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => unknown | Promise<unknown>;
|
|
292
|
+
/**
|
|
293
|
+
* Wraps a Node.js `(req, res)` handler for use in the routup pipeline.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* import { fromNodeHandler } from 'routup/node';
|
|
298
|
+
*
|
|
299
|
+
* router.use(fromNodeHandler((req, res) => {
|
|
300
|
+
* res.end('Hello');
|
|
301
|
+
* }));
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
declare function fromNodeHandler(handler: NodeHandler): Handler;
|
|
305
|
+
/**
|
|
306
|
+
* Wraps a Node.js `(req, res, next)` middleware for use in the routup pipeline.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* import cors from 'cors';
|
|
311
|
+
* import { fromNodeMiddleware } from 'routup/node';
|
|
312
|
+
*
|
|
313
|
+
* router.use(fromNodeMiddleware(cors()));
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
declare function fromNodeMiddleware(handler: NodeMiddleware): Handler;
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/handler/is.d.ts
|
|
319
|
+
declare function isHandlerConfig(input: unknown): input is HandlerConfig;
|
|
320
|
+
declare function isHandler(input: unknown): input is Handler;
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/router/constants.d.ts
|
|
323
|
+
declare enum RouterPipelineStep {
|
|
324
|
+
START = 0,
|
|
325
|
+
LOOKUP = 1,
|
|
326
|
+
CHILD_BEFORE = 2,
|
|
327
|
+
CHILD_DISPATCH = 3,
|
|
328
|
+
CHILD_AFTER = 4,
|
|
329
|
+
FINISH = 5
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/router/types.d.ts
|
|
333
|
+
type RouterPipelineContext = {
|
|
334
|
+
step: RouterPipelineStep;
|
|
335
|
+
event: RoutupEvent;
|
|
336
|
+
stackIndex: number;
|
|
337
|
+
response?: Response;
|
|
338
|
+
};
|
|
339
|
+
interface IRouter extends IDispatcher {
|
|
340
|
+
/**
|
|
341
|
+
* Unique identifier for this router instance.
|
|
342
|
+
*/
|
|
343
|
+
readonly id: number;
|
|
344
|
+
/**
|
|
345
|
+
* Optional label for the router instance.
|
|
346
|
+
*/
|
|
347
|
+
readonly name?: string;
|
|
348
|
+
/**
|
|
349
|
+
* Public entry point — processes a request through the pipeline
|
|
350
|
+
* and returns a Response (with 404/500 fallbacks).
|
|
351
|
+
*/
|
|
352
|
+
fetch(request: RoutupRequest): Promise<Response>;
|
|
353
|
+
/**
|
|
354
|
+
* Test if a path matches this router's mount path.
|
|
355
|
+
*/
|
|
356
|
+
matchPath(path: string): boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Set or clear the router's mount path.
|
|
359
|
+
*/
|
|
360
|
+
setPath(value?: Path): void;
|
|
361
|
+
/**
|
|
362
|
+
* Register a handler, router, or plugin.
|
|
363
|
+
* When a path is provided, the item is mounted at that path.
|
|
364
|
+
*/
|
|
365
|
+
use(router: IRouter): this;
|
|
366
|
+
use(handler: Handler | HandlerConfig): this;
|
|
367
|
+
use(plugin: Plugin): this;
|
|
368
|
+
use(path: Path, router: IRouter): this;
|
|
369
|
+
use(path: Path, handler: Handler | HandlerConfig): this;
|
|
370
|
+
use(path: Path, plugin: Plugin): this;
|
|
371
|
+
/** Register GET handler(s). */
|
|
372
|
+
get(...handlers: (Handler | HandlerConfig)[]): this;
|
|
373
|
+
get(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
374
|
+
/** Register POST handler(s). */
|
|
375
|
+
post(...handlers: (Handler | HandlerConfig)[]): this;
|
|
376
|
+
post(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
377
|
+
/** Register PUT handler(s). */
|
|
378
|
+
put(...handlers: (Handler | HandlerConfig)[]): this;
|
|
379
|
+
put(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
380
|
+
/** Register PATCH handler(s). */
|
|
381
|
+
patch(...handlers: (Handler | HandlerConfig)[]): this;
|
|
382
|
+
patch(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
383
|
+
/** Register DELETE handler(s). */
|
|
384
|
+
delete(...handlers: (Handler | HandlerConfig)[]): this;
|
|
385
|
+
delete(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
386
|
+
/** Register HEAD handler(s). */
|
|
387
|
+
head(...handlers: (Handler | HandlerConfig)[]): this;
|
|
388
|
+
head(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
389
|
+
/** Register OPTIONS handler(s). */
|
|
390
|
+
options(...handlers: (Handler | HandlerConfig)[]): this;
|
|
391
|
+
options(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
392
|
+
/**
|
|
393
|
+
* Mount an external fetch handler at the given path.
|
|
394
|
+
* The handler receives requests with the mount prefix stripped from the URL.
|
|
395
|
+
*
|
|
396
|
+
* @experimental
|
|
397
|
+
*/
|
|
398
|
+
mount(path: Path, handler: {
|
|
399
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
400
|
+
}): this;
|
|
401
|
+
mount(path: Path, handler: (request: Request) => Response | Promise<Response>): this;
|
|
402
|
+
/**
|
|
403
|
+
* Add a hook listener.
|
|
404
|
+
*/
|
|
405
|
+
on(name: `${HookName.REQUEST}` | `${HookName.RESPONSE}` | `${HookName.CHILD_DISPATCH_BEFORE}` | `${HookName.CHILD_DISPATCH_AFTER}`, fn: HookDefaultListener): HookUnsubscribeFn;
|
|
406
|
+
on(name: `${HookName.CHILD_MATCH}`, fn: HookDefaultListener): HookUnsubscribeFn;
|
|
407
|
+
on(name: `${HookName.ERROR}`, fn: HookErrorListener): HookUnsubscribeFn;
|
|
408
|
+
/**
|
|
409
|
+
* Remove a specific or all hook listeners for the given hook name.
|
|
410
|
+
*/
|
|
411
|
+
off(name: `${HookName}`): this;
|
|
412
|
+
off(name: `${HookName}`, fn: HookListener): this;
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/plugin/types.d.ts
|
|
416
|
+
type PluginInstallFn = (router: IRouter) => any;
|
|
417
|
+
type Plugin = {
|
|
418
|
+
/**
|
|
419
|
+
* The name of the plugin.
|
|
420
|
+
*/
|
|
421
|
+
name: string;
|
|
422
|
+
/**
|
|
423
|
+
* The installation function called on registration.
|
|
424
|
+
*/
|
|
425
|
+
install: PluginInstallFn;
|
|
426
|
+
};
|
|
427
|
+
type PluginInstallContext = {
|
|
428
|
+
/**
|
|
429
|
+
* The name property overwrites the name defined by the plugin.
|
|
430
|
+
*/
|
|
431
|
+
name?: string;
|
|
432
|
+
/**
|
|
433
|
+
* By specifying a path, the plugin will be installed as a child router.
|
|
434
|
+
*/
|
|
435
|
+
path?: Path;
|
|
436
|
+
};
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/plugin/is.d.ts
|
|
439
|
+
declare function isPlugin(input: unknown): input is Plugin;
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/utils/etag/type.d.ts
|
|
442
|
+
type EtagOptions = {
|
|
443
|
+
/**
|
|
444
|
+
* Create a weak ETag?
|
|
445
|
+
* Output is prefixed with: /W
|
|
446
|
+
*/
|
|
447
|
+
weak?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Threshold of bytes from which an etag is generated.
|
|
450
|
+
*
|
|
451
|
+
* default: undefined
|
|
452
|
+
*/
|
|
453
|
+
threshold?: number;
|
|
454
|
+
};
|
|
455
|
+
type EtagFn = (body: any, encoding?: BufferEncoding, size?: number) => Promise<string | undefined>;
|
|
456
|
+
type EtagInput = boolean | EtagOptions | EtagFn;
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/utils/trust-proxy/type.d.ts
|
|
459
|
+
type TrustProxyFn = (address: string, hop: number) => boolean;
|
|
460
|
+
type TrustProxyInput = boolean | number | string | string[] | TrustProxyFn;
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/router-options/type.d.ts
|
|
463
|
+
type RouterOptions = {
|
|
464
|
+
/**
|
|
465
|
+
* The path the router is mounted on.
|
|
466
|
+
*
|
|
467
|
+
* @type string
|
|
468
|
+
* @default '/'
|
|
469
|
+
*/
|
|
470
|
+
path?: Path;
|
|
471
|
+
/**
|
|
472
|
+
* Name of the router.
|
|
473
|
+
*/
|
|
474
|
+
name?: string;
|
|
475
|
+
/**
|
|
476
|
+
* default: 2
|
|
477
|
+
*/
|
|
478
|
+
subdomainOffset: number;
|
|
479
|
+
/**
|
|
480
|
+
* default: 0
|
|
481
|
+
*/
|
|
482
|
+
proxyIpMax: number;
|
|
483
|
+
/**
|
|
484
|
+
* default: () => true
|
|
485
|
+
*/
|
|
486
|
+
etag: EtagFn;
|
|
487
|
+
/**
|
|
488
|
+
* default: () => false
|
|
489
|
+
*/
|
|
490
|
+
trustProxy: TrustProxyFn;
|
|
491
|
+
};
|
|
492
|
+
type RouterOptionsInput = Omit<Partial<RouterOptions>, 'etag' | 'trustProxy'> & {
|
|
493
|
+
/**
|
|
494
|
+
* default: true
|
|
495
|
+
*/
|
|
496
|
+
etag?: EtagInput;
|
|
497
|
+
/**
|
|
498
|
+
* default: false
|
|
499
|
+
*/
|
|
500
|
+
trustProxy?: TrustProxyInput;
|
|
501
|
+
};
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/router/module.d.ts
|
|
504
|
+
declare class Router implements IRouter {
|
|
505
|
+
readonly '@instanceof': symbol;
|
|
506
|
+
/**
|
|
507
|
+
* An identifier for the router instance.
|
|
508
|
+
*/
|
|
509
|
+
readonly id: number;
|
|
510
|
+
/**
|
|
511
|
+
* A label for the router instance.
|
|
512
|
+
*/
|
|
513
|
+
readonly name?: string;
|
|
514
|
+
/**
|
|
515
|
+
* Array of mounted layers, routes & routers.
|
|
516
|
+
*
|
|
517
|
+
* @protected
|
|
518
|
+
*/
|
|
519
|
+
protected stack: (Router | Handler)[];
|
|
520
|
+
/**
|
|
521
|
+
* Path matcher for the current mount path.
|
|
522
|
+
*
|
|
523
|
+
* @protected
|
|
524
|
+
*/
|
|
525
|
+
protected pathMatcher: PathMatcher | undefined;
|
|
526
|
+
/**
|
|
527
|
+
* A hook manager.
|
|
528
|
+
*
|
|
529
|
+
* @protected
|
|
530
|
+
*/
|
|
531
|
+
protected hookManager: HookManager;
|
|
532
|
+
constructor(options?: RouterOptionsInput);
|
|
533
|
+
matchPath(path: string): boolean;
|
|
534
|
+
setPath(value?: Path): void;
|
|
535
|
+
/**
|
|
536
|
+
* Public entry point — creates a RoutupEvent from the request,
|
|
537
|
+
* runs the pipeline, and returns a Response (with 404/500 fallbacks).
|
|
538
|
+
*/
|
|
539
|
+
fetch(request: RoutupRequest): Promise<Response>;
|
|
540
|
+
protected buildFallbackResponse(request: RoutupRequest, event: RoutupEvent, status: number, message: string): Response;
|
|
541
|
+
protected executePipelineStep(context: RouterPipelineContext): Promise<void>;
|
|
542
|
+
protected executePipelineStepStart(context: RouterPipelineContext): Promise<void>;
|
|
543
|
+
protected executePipelineStepLookup(context: RouterPipelineContext): Promise<void>;
|
|
544
|
+
protected executePipelineStepChildBefore(context: RouterPipelineContext): Promise<void>;
|
|
545
|
+
protected executePipelineStepChildAfter(context: RouterPipelineContext): Promise<void>;
|
|
546
|
+
protected executePipelineStepChildDispatch(context: RouterPipelineContext): Promise<void>;
|
|
547
|
+
protected executePipelineStepFinish(context: RouterPipelineContext): Promise<void>;
|
|
548
|
+
dispatch(event: RoutupEvent): Promise<Response | undefined>;
|
|
549
|
+
delete(...handlers: (Handler | HandlerConfig)[]): this;
|
|
550
|
+
delete(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
551
|
+
get(...handlers: (Handler | HandlerConfig)[]): this;
|
|
552
|
+
get(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
553
|
+
post(...handlers: (Handler | HandlerConfig)[]): this;
|
|
554
|
+
post(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
555
|
+
put(...handlers: (Handler | HandlerConfig)[]): this;
|
|
556
|
+
put(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
557
|
+
patch(...handlers: (Handler | HandlerConfig)[]): this;
|
|
558
|
+
patch(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
559
|
+
head(...handlers: (Handler | HandlerConfig)[]): this;
|
|
560
|
+
head(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
561
|
+
options(...handlers: (Handler | HandlerConfig)[]): this;
|
|
562
|
+
options(path: Path, ...handlers: (Handler | HandlerConfig)[]): this;
|
|
563
|
+
protected useForMethod(method: MethodName, ...input: (Path | Handler | HandlerConfig)[]): void;
|
|
564
|
+
/**
|
|
565
|
+
* Mount an external fetch handler at the given path.
|
|
566
|
+
* The handler receives requests with the mount prefix stripped from the URL.
|
|
567
|
+
*
|
|
568
|
+
* @experimental
|
|
569
|
+
*/
|
|
570
|
+
mount(path: Path, handler: {
|
|
571
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
572
|
+
}): this;
|
|
573
|
+
mount(path: Path, handler: (request: Request) => Response | Promise<Response>): this;
|
|
574
|
+
use(router: Router): this;
|
|
575
|
+
use(handler: Handler | HandlerConfig): this;
|
|
576
|
+
use(plugin: Plugin): this;
|
|
577
|
+
use(path: Path, router: Router): this;
|
|
578
|
+
use(path: Path, handler: Handler | HandlerConfig): this;
|
|
579
|
+
use(path: Path, plugin: Plugin): this;
|
|
580
|
+
protected install(plugin: Plugin, context?: PluginInstallContext): this;
|
|
581
|
+
/**
|
|
582
|
+
* Add a hook listener.
|
|
583
|
+
*
|
|
584
|
+
* @param name
|
|
585
|
+
* @param fn
|
|
586
|
+
*/
|
|
587
|
+
on(name: `${HookName.REQUEST}` | `${HookName.RESPONSE}` | `${HookName.CHILD_DISPATCH_BEFORE}` | `${HookName.CHILD_DISPATCH_AFTER}`, fn: HookDefaultListener): HookUnsubscribeFn;
|
|
588
|
+
on(name: `${HookName.CHILD_MATCH}`, fn: HookDefaultListener): HookUnsubscribeFn;
|
|
589
|
+
on(name: `${HookName.ERROR}`, fn: HookErrorListener): HookUnsubscribeFn;
|
|
590
|
+
/**
|
|
591
|
+
* Remove single or all hook listeners.
|
|
592
|
+
*
|
|
593
|
+
* @param name
|
|
594
|
+
*/
|
|
595
|
+
off(name: `${HookName}`): this;
|
|
596
|
+
off(name: `${HookName}`, fn: HookListener): this;
|
|
597
|
+
}
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/error/create.d.ts
|
|
600
|
+
/**
|
|
601
|
+
* Create an internal error object by
|
|
602
|
+
* - an existing RoutupError (returned as-is)
|
|
603
|
+
* - an HTTPError (wrapped into a RoutupError preserving status)
|
|
604
|
+
* - an Error (wrapped preserving message and cause)
|
|
605
|
+
* - an options object (statusCode, statusMessage, etc.)
|
|
606
|
+
* - a message string
|
|
607
|
+
*
|
|
608
|
+
* @param input
|
|
609
|
+
*/
|
|
610
|
+
declare function createError(input: HTTPErrorInput | unknown): RoutupError;
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region src/error/is.d.ts
|
|
613
|
+
declare function isError(input: unknown): input is RoutupError;
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/response/helpers/cache.d.ts
|
|
616
|
+
type ResponseCacheHeadersOptions = {
|
|
617
|
+
maxAge?: number;
|
|
618
|
+
modifiedTime?: string | Date;
|
|
619
|
+
cacheControls?: string[];
|
|
620
|
+
};
|
|
621
|
+
declare function setResponseCacheHeaders(event: IRoutupEvent, options?: ResponseCacheHeadersOptions): void;
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/response/helpers/event-stream/types.d.ts
|
|
624
|
+
/**
|
|
625
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
|
|
626
|
+
*/
|
|
627
|
+
type EventStreamMessage = {
|
|
628
|
+
/**
|
|
629
|
+
* The event ID to set the EventSource object's last event ID value.
|
|
630
|
+
*/
|
|
631
|
+
id?: string;
|
|
632
|
+
/**
|
|
633
|
+
* The reconnection time.
|
|
634
|
+
* If the connection to the server is lost, the browser will wait for the specified time before attempting to reconnect.
|
|
635
|
+
* This must be an integer, specifying the reconnection time in milliseconds.
|
|
636
|
+
*/
|
|
637
|
+
retry?: number;
|
|
638
|
+
/**
|
|
639
|
+
* The data field for the message.
|
|
640
|
+
*/
|
|
641
|
+
data: string;
|
|
642
|
+
/**
|
|
643
|
+
* A string identifying the type of event described.
|
|
644
|
+
*/
|
|
645
|
+
event?: string;
|
|
646
|
+
};
|
|
647
|
+
type EventStreamListener<T = any> = (err: Error | null, data: T) => void | Promise<void>;
|
|
648
|
+
//#endregion
|
|
649
|
+
//#region src/response/helpers/event-stream/module.d.ts
|
|
650
|
+
type EventStreamOptions = {
|
|
651
|
+
maxMessageSize?: number;
|
|
652
|
+
};
|
|
653
|
+
type EventStreamHandle = {
|
|
654
|
+
write(message: string | EventStreamMessage): void;
|
|
655
|
+
end(): void;
|
|
656
|
+
response: Response;
|
|
657
|
+
};
|
|
658
|
+
declare function createEventStream(event: IRoutupEvent, options?: EventStreamOptions): EventStreamHandle;
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/response/helpers/event-stream/utils.d.ts
|
|
661
|
+
declare function serializeEventStreamMessage(message: EventStreamMessage): string;
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/response/helpers/gone.d.ts
|
|
664
|
+
declare function isResponseGone(event: IRoutupEvent): boolean;
|
|
665
|
+
declare function setResponseGone(event: IRoutupEvent): void;
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region src/response/helpers/header.d.ts
|
|
668
|
+
declare function appendResponseHeader(event: IRoutupEvent, name: string, value: string | string[]): void;
|
|
669
|
+
declare function appendResponseHeaderDirective(event: IRoutupEvent, name: string, value: string | string[]): void;
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/response/helpers/header-attachment.d.ts
|
|
672
|
+
declare function setResponseHeaderAttachment(event: IRoutupEvent, filename?: string): void;
|
|
673
|
+
//#endregion
|
|
674
|
+
//#region src/response/helpers/header-content-type.d.ts
|
|
675
|
+
declare function setResponseHeaderContentType(event: IRoutupEvent, input: string, ifNotExists?: boolean): void;
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region src/response/helpers/send-accepted.d.ts
|
|
678
|
+
declare function sendAccepted(event: IRoutupEvent, data?: unknown): Promise<Response>;
|
|
679
|
+
//#endregion
|
|
680
|
+
//#region src/response/helpers/send-created.d.ts
|
|
681
|
+
declare function sendCreated(event: IRoutupEvent, data?: unknown): Promise<Response>;
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/response/helpers/send-file.d.ts
|
|
684
|
+
type SendFileContentOptions = {
|
|
685
|
+
end?: number;
|
|
686
|
+
start?: number;
|
|
687
|
+
};
|
|
688
|
+
type SendFileStats = {
|
|
689
|
+
size?: number;
|
|
690
|
+
mtime?: Date | number | string;
|
|
691
|
+
name?: string;
|
|
692
|
+
};
|
|
693
|
+
type SendFileOptions = {
|
|
694
|
+
stats: () => Promise<SendFileStats> | SendFileStats;
|
|
695
|
+
content: (options: SendFileContentOptions) => Promise<ReadableStream | ArrayBuffer | Uint8Array> | ReadableStream | ArrayBuffer | Uint8Array;
|
|
696
|
+
attachment?: boolean;
|
|
697
|
+
name?: string;
|
|
698
|
+
};
|
|
699
|
+
declare function sendFile(event: IRoutupEvent, options: SendFileOptions): Promise<Response>;
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/response/helpers/send-format.d.ts
|
|
702
|
+
type ResponseFormatHandler = () => Response | unknown;
|
|
703
|
+
type ResponseFormats = {
|
|
704
|
+
default: ResponseFormatHandler;
|
|
705
|
+
[key: string]: ResponseFormatHandler;
|
|
706
|
+
};
|
|
707
|
+
declare function sendFormat(event: IRoutupEvent, input: ResponseFormats): Response | unknown | undefined;
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/response/helpers/send-redirect.d.ts
|
|
710
|
+
declare function sendRedirect(event: IRoutupEvent, location: string, statusCode?: number): Response;
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/response/helpers/send-stream.d.ts
|
|
713
|
+
declare function sendStream(event: IRoutupEvent, stream: ReadableStream): Response;
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region src/response/helpers/utils.d.ts
|
|
716
|
+
declare function setResponseContentTypeByFileName(event: IRoutupEvent, fileName: string): void;
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/response/to-response.d.ts
|
|
719
|
+
declare function toResponse(value: unknown, event: IRoutupEvent): Promise<Response | undefined>;
|
|
720
|
+
//#endregion
|
|
721
|
+
//#region src/request/helpers/body.d.ts
|
|
722
|
+
/**
|
|
723
|
+
* Read and parse the request body.
|
|
724
|
+
*
|
|
725
|
+
* - `application/x-www-form-urlencoded` → plain object (duplicate keys become arrays)
|
|
726
|
+
* - `application/json` or other → attempts JSON parse, returns undefined on failure
|
|
727
|
+
*
|
|
728
|
+
* The result is cached on the event store — calling `readBody()` multiple
|
|
729
|
+
* times returns the same parsed result.
|
|
730
|
+
*
|
|
731
|
+
* For binary or streaming access, use `event.request.arrayBuffer()`,
|
|
732
|
+
* `event.request.blob()`, or `event.request.body` directly.
|
|
733
|
+
*
|
|
734
|
+
* @experimental
|
|
735
|
+
*/
|
|
736
|
+
declare function readBody<T = unknown>(event: IRoutupEvent): Promise<T | undefined>;
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/request/helpers/cache.d.ts
|
|
739
|
+
declare function isRequestCacheable(event: IRoutupEvent, modifiedTime: string | Date): boolean;
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/request/helpers/header.d.ts
|
|
742
|
+
declare function getRequestHeader(event: IRoutupEvent, name: string): string | null;
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/request/helpers/header-accept.d.ts
|
|
745
|
+
declare function getRequestAcceptableContentTypes(event: IRoutupEvent): string[];
|
|
746
|
+
declare function getRequestAcceptableContentType(event: IRoutupEvent, input?: string | string[]): string | undefined;
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/request/helpers/header-accept-charset.d.ts
|
|
749
|
+
declare function getRequestAcceptableCharsets(event: IRoutupEvent): string[];
|
|
750
|
+
declare function getRequestAcceptableCharset(event: IRoutupEvent, input: string | string[]): string | undefined;
|
|
751
|
+
//#endregion
|
|
752
|
+
//#region src/request/helpers/header-accept-encoding.d.ts
|
|
753
|
+
declare function getRequestAcceptableEncodings(event: IRoutupEvent): string[];
|
|
754
|
+
declare function getRequestAcceptableEncoding(event: IRoutupEvent, input: string | string[]): string | undefined;
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/request/helpers/header-accept-language.d.ts
|
|
757
|
+
declare function getRequestAcceptableLanguages(event: IRoutupEvent): string[];
|
|
758
|
+
declare function getRequestAcceptableLanguage(event: IRoutupEvent, input?: string | string[]): string | undefined;
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region src/request/helpers/header-content-type.d.ts
|
|
761
|
+
declare function matchRequestContentType(event: IRoutupEvent, contentType: string): boolean;
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/request/helpers/hostname.d.ts
|
|
764
|
+
type RequestHostNameOptions = {
|
|
765
|
+
trustProxy?: TrustProxyInput;
|
|
766
|
+
};
|
|
767
|
+
declare function getRequestHostName(event: IRoutupEvent, options?: RequestHostNameOptions): string | undefined;
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region src/request/helpers/ip.d.ts
|
|
770
|
+
type RequestIpOptions = {
|
|
771
|
+
trustProxy?: boolean;
|
|
772
|
+
};
|
|
773
|
+
declare function getRequestIP(event: IRoutupEvent, options?: RequestIpOptions): string | undefined;
|
|
774
|
+
//#endregion
|
|
775
|
+
//#region src/request/helpers/negotiator.d.ts
|
|
776
|
+
declare function useRequestNegotiator(event: IRoutupEvent): Negotiator;
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/request/helpers/protocol.d.ts
|
|
779
|
+
type RequestProtocolOptions = {
|
|
780
|
+
trustProxy?: TrustProxyInput;
|
|
781
|
+
default?: string;
|
|
782
|
+
};
|
|
783
|
+
declare function getRequestProtocol(event: IRoutupEvent, options?: RequestProtocolOptions): string;
|
|
784
|
+
//#endregion
|
|
785
|
+
export { RouterPipelineContext as $, sendAccepted as A, HeaderName as At, createEventStream as B, sendRedirect as C, IDispatcher as Ct, SendFileStats as D, RoutupResponse as Dt, SendFileOptions as E, RoutupRequest as Et, isResponseGone as F, isError as G, EventStreamMessage as H, setResponseGone as I, isPlugin as J, createError as K, serializeEventStreamMessage as L, setResponseHeaderAttachment as M, appendResponseHeader as N, sendFile as O, HTTPErrorInput$1 as Ot, appendResponseHeaderDirective as P, IRouter as Q, EventStreamHandle as R, sendStream as S, PathMatcherOptions as St, SendFileContentOptions as T, IRoutupEvent as Tt, ResponseCacheHeadersOptions as U, EventStreamListener as V, setResponseCacheHeaders as W, PluginInstallContext as X, Plugin as Y, PluginInstallFn as Z, getRequestHeader as _, HandlerType as _t, getRequestIP as a, fromNodeMiddleware as at, toResponse as b, Path as bt, matchRequestContentType as c, CoreHandlerFn as ct, getRequestAcceptableEncoding as d, HandlerFn as dt, isHandler as et, getRequestAcceptableEncodings as f, errorHandler as ft, getRequestAcceptableContentTypes as g, HandlerSymbol as gt, getRequestAcceptableContentType as h, HandlerBaseConfig as ht, RequestIpOptions as i, fromNodeHandler as it, setResponseHeaderContentType as j, MethodName as jt, sendCreated as k, RoutupError as kt, getRequestAcceptableLanguage as l, Handler as lt, getRequestAcceptableCharsets as m, ErrorHandlerFn as mt, getRequestProtocol as n, NodeHandler as nt, RequestHostNameOptions as o, coreHandler as ot, getRequestAcceptableCharset as p, ErrorHandlerConfig as pt, Router as q, useRequestNegotiator as r, NodeMiddleware as rt, getRequestHostName as s, CoreHandlerConfig as st, RequestProtocolOptions as t, isHandlerConfig as tt, getRequestAcceptableLanguages as u, HandlerConfig as ut, isRequestCacheable as v, isPath as vt, sendFormat as w, RoutupEvent as wt, setResponseContentTypeByFileName as x, PathMatcherExecResult as xt, readBody as y, PathMatcher as yt, EventStreamOptions as z };
|
|
786
|
+
//# sourceMappingURL=index-9K5FcIb3.d.cts.map
|