@kaito-http/core 2.2.0 → 2.2.3
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.
|
@@ -3,7 +3,7 @@ import http from 'http';
|
|
|
3
3
|
import { z, ZodTypeAny } from 'zod';
|
|
4
4
|
import { KaitoRequest } from './req';
|
|
5
5
|
import { KaitoResponse } from './res';
|
|
6
|
-
import { Method } from './util';
|
|
6
|
+
import { Method, NormalizePath } from './util';
|
|
7
7
|
export declare type GetContext<T> = (req: KaitoRequest, res: KaitoResponse) => Promise<T>;
|
|
8
8
|
declare type Never = [never];
|
|
9
9
|
export declare function createGetContext<T>(getContext: GetContext<T>): GetContext<T>;
|
|
@@ -13,115 +13,41 @@ export declare type ContextWithInput<Ctx, Input> = {
|
|
|
13
13
|
input: Input;
|
|
14
14
|
};
|
|
15
15
|
declare type Values<T> = T[keyof T];
|
|
16
|
-
export declare type Proc<Ctx, Result, Input extends z.ZodTypeAny | Never = Never> =
|
|
16
|
+
export declare type Proc<Ctx, Result, Input extends z.ZodTypeAny | Never = Never> = {
|
|
17
17
|
input?: Input;
|
|
18
18
|
run(arg: ContextWithInput<Ctx, Input extends ZodTypeAny ? z.infer<Input> : undefined>): Promise<Result>;
|
|
19
|
-
}
|
|
20
|
-
export interface RouterProc<Path extends string
|
|
19
|
+
};
|
|
20
|
+
export interface RouterProc<Path extends string, M extends Method> {
|
|
21
21
|
method: M;
|
|
22
22
|
path: Path;
|
|
23
23
|
pattern: RegExp;
|
|
24
24
|
}
|
|
25
25
|
export declare type AnyProcs<Ctx> = {
|
|
26
|
-
[Path in string]: Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<Path>;
|
|
26
|
+
[Path in string]: Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<Path, Method>;
|
|
27
27
|
};
|
|
28
28
|
export declare type AnyRouter<Ctx> = Router<Ctx, AnyProcs<Ctx>>;
|
|
29
29
|
export declare class Router<Ctx, Procs extends AnyProcs<Ctx>> {
|
|
30
30
|
private readonly procs;
|
|
31
31
|
private readonly _procsArray;
|
|
32
|
-
|
|
33
|
-
* Ensures that the path does not start or end with a slash.
|
|
34
|
-
* @param path
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
private static stripSlashes;
|
|
32
|
+
private static patternize;
|
|
38
33
|
constructor(procs: Procs);
|
|
39
34
|
getProcs(): Procs;
|
|
40
|
-
find(method: Method, url: string): (
|
|
41
|
-
input?: z.ZodTypeAny | undefined;
|
|
42
|
-
run(arg: ContextWithInput<Ctx, any>): Promise<unknown>;
|
|
43
|
-
}> & RouterProc<string, Method>) | null;
|
|
35
|
+
find(method: Method, url: string): (Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<string, Method>) | null;
|
|
44
36
|
private readonly create;
|
|
45
|
-
readonly merge: <Prefix extends string, NewCtx, NewProcs extends AnyProcs<NewCtx>>(
|
|
37
|
+
readonly merge: <Prefix extends string, NewCtx, NewProcs extends AnyProcs<NewCtx>>(_prefix: (Prefix extends `${infer U}/` ? U : Prefix) extends `/${infer U_1}` ? `/${U_1}` : `/${Prefix extends `${infer U}/` ? U : Prefix}`, router: Router<NewCtx, NewProcs>) => Router<NewCtx & Ctx, Procs & { [P in keyof NewProcs as `/${Prefix}${Extract<keyof NewProcs, string>}`]: Omit<NewProcs[P], "path"> & {
|
|
46
38
|
path: P;
|
|
47
39
|
}; }>;
|
|
48
|
-
readonly get: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}>) => Router<Ctx, Procs & Record<Path,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}> &
|
|
55
|
-
readonly
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}>) => Router<Ctx, Procs & Record<Path,
|
|
59
|
-
input?: Input | undefined;
|
|
60
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
61
|
-
}> & RouterProc<Path, "POST">>>;
|
|
62
|
-
readonly put: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
63
|
-
input?: Input | undefined;
|
|
64
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
65
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
66
|
-
input?: Input | undefined;
|
|
67
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
68
|
-
}> & RouterProc<Path, "PUT">>>;
|
|
69
|
-
readonly patch: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
70
|
-
input?: Input | undefined;
|
|
71
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
72
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
73
|
-
input?: Input | undefined;
|
|
74
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
75
|
-
}> & RouterProc<Path, "PATCH">>>;
|
|
76
|
-
readonly delete: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
77
|
-
input?: Input | undefined;
|
|
78
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
79
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
80
|
-
input?: Input | undefined;
|
|
81
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
82
|
-
}> & RouterProc<Path, "DELETE">>>;
|
|
83
|
-
readonly head: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
84
|
-
input?: Input | undefined;
|
|
85
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
86
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
87
|
-
input?: Input | undefined;
|
|
88
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
89
|
-
}> & RouterProc<Path, "HEAD">>>;
|
|
90
|
-
readonly options: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
91
|
-
input?: Input | undefined;
|
|
92
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
93
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
94
|
-
input?: Input | undefined;
|
|
95
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
96
|
-
}> & RouterProc<Path, "OPTIONS">>>;
|
|
97
|
-
readonly connect: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
98
|
-
input?: Input | undefined;
|
|
99
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
100
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
101
|
-
input?: Input | undefined;
|
|
102
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
103
|
-
}> & RouterProc<Path, "CONNECT">>>;
|
|
104
|
-
readonly trace: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
105
|
-
input?: Input | undefined;
|
|
106
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
107
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
108
|
-
input?: Input | undefined;
|
|
109
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
110
|
-
}> & RouterProc<Path, "TRACE">>>;
|
|
111
|
-
readonly acl: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
112
|
-
input?: Input | undefined;
|
|
113
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
114
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
115
|
-
input?: Input | undefined;
|
|
116
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
117
|
-
}> & RouterProc<Path, "ACL">>>;
|
|
118
|
-
readonly bind: <Path extends string, Result, Input extends z.ZodTypeAny>(path: Path, proc: Readonly<{
|
|
119
|
-
input?: Input | undefined;
|
|
120
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
121
|
-
}>) => Router<Ctx, Procs & Record<Path, Readonly<{
|
|
122
|
-
input?: Input | undefined;
|
|
123
|
-
run(arg: ContextWithInput<Ctx, Input extends z.ZodTypeAny ? z.TypeOf<Input> : undefined>): Promise<Result>;
|
|
124
|
-
}> & RouterProc<Path, "BIND">>>;
|
|
40
|
+
readonly get: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "GET">>>;
|
|
41
|
+
readonly post: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "POST">>>;
|
|
42
|
+
readonly put: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PUT">>>;
|
|
43
|
+
readonly patch: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PATCH">>>;
|
|
44
|
+
readonly delete: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "DELETE">>>;
|
|
45
|
+
readonly head: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "HEAD">>>;
|
|
46
|
+
readonly options: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "OPTIONS">>>;
|
|
47
|
+
readonly connect: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "CONNECT">>>;
|
|
48
|
+
readonly trace: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "TRACE">>>;
|
|
49
|
+
readonly acl: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "ACL">>>;
|
|
50
|
+
readonly bind: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "BIND">>>;
|
|
125
51
|
}
|
|
126
52
|
export declare class KaitoError extends Error {
|
|
127
53
|
readonly status: number;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { KaitoRequest } from './req';
|
|
2
2
|
export declare function getLastEntryInMultiHeaderValue(headerValue: string | string[]): string;
|
|
3
|
+
declare type RemoveEndSlashes<T extends string> = T extends `${infer U}/` ? U : T;
|
|
4
|
+
declare type AddStartSlashes<T extends string> = T extends `/${infer U}` ? `/${U}` : `/${T}`;
|
|
5
|
+
export declare type NormalizePath<T extends string> = AddStartSlashes<RemoveEndSlashes<T>>;
|
|
6
|
+
export declare function normalizePath<T extends string>(path: T): NormalizePath<T>;
|
|
3
7
|
export declare type Method = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PRI' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE';
|
|
4
8
|
export declare function getInput(req: KaitoRequest): Promise<unknown>;
|
|
9
|
+
export {};
|
|
@@ -124,6 +124,19 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
124
124
|
var normalized = Array.isArray(headerValue) ? headerValue.join(',') : headerValue;
|
|
125
125
|
var lastIndex = normalized.lastIndexOf(',');
|
|
126
126
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
127
|
+
}
|
|
128
|
+
function normalizePath(path) {
|
|
129
|
+
var result = path;
|
|
130
|
+
|
|
131
|
+
if (!result.startsWith('/')) {
|
|
132
|
+
result = "/".concat(result);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (result.endsWith('/')) {
|
|
136
|
+
result = result.slice(-1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result;
|
|
127
140
|
} // Type for import('http').METHODS
|
|
128
141
|
|
|
129
142
|
function getInput(_x) {
|
|
@@ -231,27 +244,14 @@ function createGetContext(getContext) {
|
|
|
231
244
|
return getContext;
|
|
232
245
|
}
|
|
233
246
|
class Router {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
* @private
|
|
238
|
-
*/
|
|
239
|
-
static stripSlashes(path) {
|
|
240
|
-
if (path.startsWith('/')) {
|
|
241
|
-
path = path.slice(1);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (path.endsWith('/')) {
|
|
245
|
-
path = path.slice(-1);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return path;
|
|
247
|
+
static patternize(path) {
|
|
248
|
+
var normalized = normalizePath(path);
|
|
249
|
+
return new RegExp("^".concat(normalized, "/?$"), 'i');
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
constructor(procs) {
|
|
252
253
|
_defineProperty(this, "create", method => (path, proc) => {
|
|
253
|
-
var
|
|
254
|
-
var pattern = new RegExp("^/".concat(stripped, "/?$"), 'i');
|
|
254
|
+
var pattern = Router.patternize(path);
|
|
255
255
|
|
|
256
256
|
var merged = _objectSpread2(_objectSpread2({}, this.procs), {}, {
|
|
257
257
|
[path]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
@@ -264,12 +264,15 @@ class Router {
|
|
|
264
264
|
return new Router(merged);
|
|
265
265
|
});
|
|
266
266
|
|
|
267
|
-
_defineProperty(this, "merge", (
|
|
267
|
+
_defineProperty(this, "merge", (_prefix, router) => {
|
|
268
|
+
var prefix = normalizePath(_prefix);
|
|
268
269
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
269
270
|
var [path, proc] = entry;
|
|
271
|
+
var newPath = "".concat(prefix).concat(normalizePath(path));
|
|
270
272
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
271
273
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
272
|
-
path:
|
|
274
|
+
path: newPath,
|
|
275
|
+
pattern: Router.patternize(newPath)
|
|
273
276
|
})
|
|
274
277
|
});
|
|
275
278
|
}, {});
|
|
@@ -124,6 +124,19 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
124
124
|
var normalized = Array.isArray(headerValue) ? headerValue.join(',') : headerValue;
|
|
125
125
|
var lastIndex = normalized.lastIndexOf(',');
|
|
126
126
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
127
|
+
}
|
|
128
|
+
function normalizePath(path) {
|
|
129
|
+
var result = path;
|
|
130
|
+
|
|
131
|
+
if (!result.startsWith('/')) {
|
|
132
|
+
result = "/".concat(result);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (result.endsWith('/')) {
|
|
136
|
+
result = result.slice(-1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result;
|
|
127
140
|
} // Type for import('http').METHODS
|
|
128
141
|
|
|
129
142
|
function getInput(_x) {
|
|
@@ -231,27 +244,14 @@ function createGetContext(getContext) {
|
|
|
231
244
|
return getContext;
|
|
232
245
|
}
|
|
233
246
|
class Router {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
* @private
|
|
238
|
-
*/
|
|
239
|
-
static stripSlashes(path) {
|
|
240
|
-
if (path.startsWith('/')) {
|
|
241
|
-
path = path.slice(1);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (path.endsWith('/')) {
|
|
245
|
-
path = path.slice(-1);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return path;
|
|
247
|
+
static patternize(path) {
|
|
248
|
+
var normalized = normalizePath(path);
|
|
249
|
+
return new RegExp("^".concat(normalized, "/?$"), 'i');
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
constructor(procs) {
|
|
252
253
|
_defineProperty(this, "create", method => (path, proc) => {
|
|
253
|
-
var
|
|
254
|
-
var pattern = new RegExp("^/".concat(stripped, "/?$"), 'i');
|
|
254
|
+
var pattern = Router.patternize(path);
|
|
255
255
|
|
|
256
256
|
var merged = _objectSpread2(_objectSpread2({}, this.procs), {}, {
|
|
257
257
|
[path]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
@@ -264,12 +264,15 @@ class Router {
|
|
|
264
264
|
return new Router(merged);
|
|
265
265
|
});
|
|
266
266
|
|
|
267
|
-
_defineProperty(this, "merge", (
|
|
267
|
+
_defineProperty(this, "merge", (_prefix, router) => {
|
|
268
|
+
var prefix = normalizePath(_prefix);
|
|
268
269
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
269
270
|
var [path, proc] = entry;
|
|
271
|
+
var newPath = "".concat(prefix).concat(normalizePath(path));
|
|
270
272
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
271
273
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
272
|
-
path:
|
|
274
|
+
path: newPath,
|
|
275
|
+
pattern: Router.patternize(newPath)
|
|
273
276
|
})
|
|
274
277
|
});
|
|
275
278
|
}, {});
|
|
@@ -115,6 +115,19 @@ function getLastEntryInMultiHeaderValue(headerValue) {
|
|
|
115
115
|
var normalized = Array.isArray(headerValue) ? headerValue.join(',') : headerValue;
|
|
116
116
|
var lastIndex = normalized.lastIndexOf(',');
|
|
117
117
|
return lastIndex === -1 ? normalized.trim() : normalized.slice(lastIndex + 1).trim();
|
|
118
|
+
}
|
|
119
|
+
function normalizePath(path) {
|
|
120
|
+
var result = path;
|
|
121
|
+
|
|
122
|
+
if (!result.startsWith('/')) {
|
|
123
|
+
result = "/".concat(result);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (result.endsWith('/')) {
|
|
127
|
+
result = result.slice(-1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
118
131
|
} // Type for import('http').METHODS
|
|
119
132
|
|
|
120
133
|
function getInput(_x) {
|
|
@@ -222,27 +235,14 @@ function createGetContext(getContext) {
|
|
|
222
235
|
return getContext;
|
|
223
236
|
}
|
|
224
237
|
class Router {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
* @private
|
|
229
|
-
*/
|
|
230
|
-
static stripSlashes(path) {
|
|
231
|
-
if (path.startsWith('/')) {
|
|
232
|
-
path = path.slice(1);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (path.endsWith('/')) {
|
|
236
|
-
path = path.slice(-1);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return path;
|
|
238
|
+
static patternize(path) {
|
|
239
|
+
var normalized = normalizePath(path);
|
|
240
|
+
return new RegExp("^".concat(normalized, "/?$"), 'i');
|
|
240
241
|
}
|
|
241
242
|
|
|
242
243
|
constructor(procs) {
|
|
243
244
|
_defineProperty(this, "create", method => (path, proc) => {
|
|
244
|
-
var
|
|
245
|
-
var pattern = new RegExp("^/".concat(stripped, "/?$"), 'i');
|
|
245
|
+
var pattern = Router.patternize(path);
|
|
246
246
|
|
|
247
247
|
var merged = _objectSpread2(_objectSpread2({}, this.procs), {}, {
|
|
248
248
|
[path]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
@@ -255,12 +255,15 @@ class Router {
|
|
|
255
255
|
return new Router(merged);
|
|
256
256
|
});
|
|
257
257
|
|
|
258
|
-
_defineProperty(this, "merge", (
|
|
258
|
+
_defineProperty(this, "merge", (_prefix, router) => {
|
|
259
|
+
var prefix = normalizePath(_prefix);
|
|
259
260
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
260
261
|
var [path, proc] = entry;
|
|
262
|
+
var newPath = "".concat(prefix).concat(normalizePath(path));
|
|
261
263
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
262
264
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
263
|
-
path:
|
|
265
|
+
path: newPath,
|
|
266
|
+
pattern: Router.patternize(newPath)
|
|
264
267
|
})
|
|
265
268
|
});
|
|
266
269
|
}, {});
|