@kaito-http/core 2.2.4 → 2.2.7
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.
|
@@ -4,18 +4,24 @@ import { z, ZodTypeAny } from 'zod';
|
|
|
4
4
|
import { KaitoRequest } from './req';
|
|
5
5
|
import { KaitoResponse } from './res';
|
|
6
6
|
import { Method, NormalizePath } from './util';
|
|
7
|
+
declare type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
8
|
+
[k in Param | keyof ExtractRouteParams<Rest>]: string;
|
|
9
|
+
} : T extends `${string}:${infer Param}` ? {
|
|
10
|
+
[k in Param]: string;
|
|
11
|
+
} : {};
|
|
7
12
|
export declare type GetContext<T> = (req: KaitoRequest, res: KaitoResponse) => Promise<T>;
|
|
8
13
|
declare type Never = [never];
|
|
9
14
|
export declare function createGetContext<T>(getContext: GetContext<T>): GetContext<T>;
|
|
10
15
|
export declare type InferContext<T> = T extends GetContext<infer Value> ? Value : never;
|
|
11
|
-
export declare type ContextWithInput<Ctx, Input> = {
|
|
16
|
+
export declare type ContextWithInput<Ctx, Params extends Record<string, string>, Input> = {
|
|
12
17
|
ctx: Ctx;
|
|
18
|
+
params: Params;
|
|
13
19
|
input: Input;
|
|
14
20
|
};
|
|
15
21
|
declare type Values<T> = T[keyof T];
|
|
16
|
-
export declare type Proc<Ctx, Result, Input extends z.ZodTypeAny | Never = Never> = {
|
|
22
|
+
export declare type Proc<Ctx, Result, Params extends Record<string, string> = Record<never, string>, Input extends z.ZodTypeAny | Never = Never> = {
|
|
17
23
|
input?: Input;
|
|
18
|
-
run(arg: ContextWithInput<Ctx, Input extends ZodTypeAny ? z.infer<Input> : undefined>): Promise<Result>;
|
|
24
|
+
run(arg: ContextWithInput<Ctx, Params, Input extends ZodTypeAny ? z.infer<Input> : undefined>): Promise<Result>;
|
|
19
25
|
};
|
|
20
26
|
export interface RouterProc<Path extends string, M extends Method> {
|
|
21
27
|
method: M;
|
|
@@ -23,7 +29,7 @@ export interface RouterProc<Path extends string, M extends Method> {
|
|
|
23
29
|
pattern: RegExp;
|
|
24
30
|
}
|
|
25
31
|
export declare type AnyProcs<Ctx> = {
|
|
26
|
-
[Path in string]: Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<Path, Method>;
|
|
32
|
+
[Path in string]: Proc<Ctx, unknown, Record<string, string>, z.ZodTypeAny> & RouterProc<Path, Method>;
|
|
27
33
|
};
|
|
28
34
|
export declare type AnyRouter<Ctx> = Router<Ctx, AnyProcs<Ctx>>;
|
|
29
35
|
export declare class Router<Ctx, Procs extends AnyProcs<Ctx>> {
|
|
@@ -32,22 +38,22 @@ export declare class Router<Ctx, Procs extends AnyProcs<Ctx>> {
|
|
|
32
38
|
private static patternize;
|
|
33
39
|
constructor(procs: Procs);
|
|
34
40
|
getProcs(): Procs;
|
|
35
|
-
find(method: Method, url: string): (Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<string, Method>) | null;
|
|
41
|
+
find(method: Method, url: string): (Proc<Ctx, unknown, Record<string, string>, z.ZodTypeAny> & RouterProc<string, Method>) | null;
|
|
36
42
|
private readonly create;
|
|
37
|
-
readonly merge: <Prefix extends string, NewCtx, NewProcs extends AnyProcs<NewCtx>>(
|
|
43
|
+
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 Extract<keyof NewProcs, string> as `/${Prefix}${P}`]: Omit<NewProcs[P], "path"> & {
|
|
38
44
|
path: P;
|
|
39
45
|
}; }>;
|
|
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">>>;
|
|
46
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "GET">>>;
|
|
47
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "POST">>>;
|
|
48
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PUT">>>;
|
|
49
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PATCH">>>;
|
|
50
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "DELETE">>>;
|
|
51
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "HEAD">>>;
|
|
52
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "OPTIONS">>>;
|
|
53
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "CONNECT">>>;
|
|
54
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "TRACE">>>;
|
|
55
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "ACL">>>;
|
|
56
|
+
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, ExtractRouteParams<Path>, 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, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "BIND">>>;
|
|
51
57
|
}
|
|
52
58
|
export declare class KaitoError extends Error {
|
|
53
59
|
readonly status: number;
|
|
@@ -174,6 +174,8 @@ function _getInput() {
|
|
|
174
174
|
|
|
175
175
|
class KaitoRequest {
|
|
176
176
|
constructor(raw) {
|
|
177
|
+
_defineProperty(this, "_url", null);
|
|
178
|
+
|
|
177
179
|
this.raw = raw;
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -184,7 +186,12 @@ class KaitoRequest {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
get url() {
|
|
187
|
-
|
|
189
|
+
if (this._url) {
|
|
190
|
+
return this._url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._url = new URL(this.fullURL);
|
|
194
|
+
return this._url;
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
get method() {
|
|
@@ -264,11 +271,10 @@ class Router {
|
|
|
264
271
|
return new Router(merged);
|
|
265
272
|
});
|
|
266
273
|
|
|
267
|
-
_defineProperty(this, "merge", (
|
|
268
|
-
var prefix = normalizePath(_prefix);
|
|
274
|
+
_defineProperty(this, "merge", (prefix, router) => {
|
|
269
275
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
270
276
|
var [path, proc] = entry;
|
|
271
|
-
var newPath = "".concat(prefix).concat(
|
|
277
|
+
var newPath = "".concat(prefix).concat(path);
|
|
272
278
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
273
279
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
274
280
|
path: newPath,
|
|
@@ -356,7 +362,7 @@ function createServer(config) {
|
|
|
356
362
|
try {
|
|
357
363
|
var _handler$input, _yield$getInput;
|
|
358
364
|
|
|
359
|
-
var handler = config.router.find(req.method, req.url
|
|
365
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
360
366
|
|
|
361
367
|
if (!handler) {
|
|
362
368
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -366,7 +372,8 @@ function createServer(config) {
|
|
|
366
372
|
var context = yield config.getContext(req, res);
|
|
367
373
|
var data = yield handler.run({
|
|
368
374
|
ctx: context,
|
|
369
|
-
input
|
|
375
|
+
input,
|
|
376
|
+
params: {}
|
|
370
377
|
});
|
|
371
378
|
res.json({
|
|
372
379
|
success: true,
|
|
@@ -174,6 +174,8 @@ function _getInput() {
|
|
|
174
174
|
|
|
175
175
|
class KaitoRequest {
|
|
176
176
|
constructor(raw) {
|
|
177
|
+
_defineProperty(this, "_url", null);
|
|
178
|
+
|
|
177
179
|
this.raw = raw;
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -184,7 +186,12 @@ class KaitoRequest {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
get url() {
|
|
187
|
-
|
|
189
|
+
if (this._url) {
|
|
190
|
+
return this._url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._url = new URL(this.fullURL);
|
|
194
|
+
return this._url;
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
get method() {
|
|
@@ -264,11 +271,10 @@ class Router {
|
|
|
264
271
|
return new Router(merged);
|
|
265
272
|
});
|
|
266
273
|
|
|
267
|
-
_defineProperty(this, "merge", (
|
|
268
|
-
var prefix = normalizePath(_prefix);
|
|
274
|
+
_defineProperty(this, "merge", (prefix, router) => {
|
|
269
275
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
270
276
|
var [path, proc] = entry;
|
|
271
|
-
var newPath = "".concat(prefix).concat(
|
|
277
|
+
var newPath = "".concat(prefix).concat(path);
|
|
272
278
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
273
279
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
274
280
|
path: newPath,
|
|
@@ -356,7 +362,7 @@ function createServer(config) {
|
|
|
356
362
|
try {
|
|
357
363
|
var _handler$input, _yield$getInput;
|
|
358
364
|
|
|
359
|
-
var handler = config.router.find(req.method, req.url
|
|
365
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
360
366
|
|
|
361
367
|
if (!handler) {
|
|
362
368
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -366,7 +372,8 @@ function createServer(config) {
|
|
|
366
372
|
var context = yield config.getContext(req, res);
|
|
367
373
|
var data = yield handler.run({
|
|
368
374
|
ctx: context,
|
|
369
|
-
input
|
|
375
|
+
input,
|
|
376
|
+
params: {}
|
|
370
377
|
});
|
|
371
378
|
res.json({
|
|
372
379
|
success: true,
|
|
@@ -165,6 +165,8 @@ function _getInput() {
|
|
|
165
165
|
|
|
166
166
|
class KaitoRequest {
|
|
167
167
|
constructor(raw) {
|
|
168
|
+
_defineProperty(this, "_url", null);
|
|
169
|
+
|
|
168
170
|
this.raw = raw;
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -175,7 +177,12 @@ class KaitoRequest {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
get url() {
|
|
178
|
-
|
|
180
|
+
if (this._url) {
|
|
181
|
+
return this._url;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this._url = new URL(this.fullURL);
|
|
185
|
+
return this._url;
|
|
179
186
|
}
|
|
180
187
|
|
|
181
188
|
get method() {
|
|
@@ -255,11 +262,10 @@ class Router {
|
|
|
255
262
|
return new Router(merged);
|
|
256
263
|
});
|
|
257
264
|
|
|
258
|
-
_defineProperty(this, "merge", (
|
|
259
|
-
var prefix = normalizePath(_prefix);
|
|
265
|
+
_defineProperty(this, "merge", (prefix, router) => {
|
|
260
266
|
var newProcs = Object.entries(router.getProcs()).reduce((all, entry) => {
|
|
261
267
|
var [path, proc] = entry;
|
|
262
|
-
var newPath = "".concat(prefix).concat(
|
|
268
|
+
var newPath = "".concat(prefix).concat(path);
|
|
263
269
|
return _objectSpread2(_objectSpread2({}, all), {}, {
|
|
264
270
|
["".concat(prefix).concat(path)]: _objectSpread2(_objectSpread2({}, proc), {}, {
|
|
265
271
|
path: newPath,
|
|
@@ -347,7 +353,7 @@ function createServer(config) {
|
|
|
347
353
|
try {
|
|
348
354
|
var _handler$input, _yield$getInput;
|
|
349
355
|
|
|
350
|
-
var handler = config.router.find(req.method, req.url
|
|
356
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
351
357
|
|
|
352
358
|
if (!handler) {
|
|
353
359
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -357,7 +363,8 @@ function createServer(config) {
|
|
|
357
363
|
var context = yield config.getContext(req, res);
|
|
358
364
|
var data = yield handler.run({
|
|
359
365
|
ctx: context,
|
|
360
|
-
input
|
|
366
|
+
input,
|
|
367
|
+
params: {}
|
|
361
368
|
});
|
|
362
369
|
res.json({
|
|
363
370
|
success: true,
|