@kaito-http/core 2.3.9 → 2.4.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/dist/declarations/src/route.d.ts +5 -5
- package/dist/declarations/src/router.d.ts +13 -45
- package/dist/declarations/src/server.d.ts +2 -2
- package/dist/declarations/src/util.d.ts +2 -0
- package/dist/kaito-http-core.cjs.dev.js +45 -107
- package/dist/kaito-http-core.cjs.prod.js +45 -107
- package/dist/kaito-http-core.esm.js +45 -107
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { HTTPMethod } from 'find-my-way';
|
|
2
1
|
import { z } from 'zod';
|
|
3
|
-
import { ExtractRouteParams } from './util';
|
|
2
|
+
import { ExtractRouteParams, KaitoMethod } from './util';
|
|
4
3
|
export declare type RouteArgument<Path extends string, Context, Input extends z.ZodSchema> = {
|
|
5
4
|
ctx: Context;
|
|
6
5
|
input: z.infer<Input>;
|
|
7
6
|
params: ExtractRouteParams<Path>;
|
|
8
7
|
};
|
|
9
|
-
export
|
|
8
|
+
export declare type Route<Context, Result, Path extends string, Method extends KaitoMethod, Input extends z.ZodSchema> = {
|
|
10
9
|
input?: Input;
|
|
10
|
+
path: Path;
|
|
11
11
|
method: Method;
|
|
12
|
-
run(
|
|
13
|
-
}
|
|
12
|
+
run(args: RouteArgument<Path, Context, Input>): Promise<Result>;
|
|
13
|
+
};
|
|
@@ -2,56 +2,24 @@ import fmw, { HTTPMethod, Instance } from 'find-my-way';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { Route } from './route';
|
|
4
4
|
import { ServerConfig } from './server';
|
|
5
|
-
import {
|
|
6
|
-
export declare type RoutesInit<Context> =
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { KaitoMethod } from './util';
|
|
6
|
+
export declare type RoutesInit<Context> = Array<Route<Context, unknown, string, KaitoMethod, z.ZodSchema>>;
|
|
7
|
+
export declare type MergePaths<Routes extends RoutesInit<unknown>, Prefix extends string> = Routes extends [
|
|
8
|
+
infer R,
|
|
9
|
+
...infer Rest
|
|
10
|
+
] ? R extends Route<infer Context, infer Result, infer Path, infer Method, infer Input> ? [Route<Context, Result, `${Prefix}${Path}`, Method, Input>, ...MergePaths<Extract<Rest, RoutesInit<any>>, Prefix>] : MergePaths<Extract<Rest, RoutesInit<any>>, Prefix> : [];
|
|
9
11
|
export declare class Router<Context, Routes extends RoutesInit<Context>> {
|
|
10
|
-
static create<Context = null>(): Router<Context,
|
|
12
|
+
static create<Context = null>(): Router<Context, []>;
|
|
11
13
|
private static handle;
|
|
12
14
|
readonly 'routes': Routes;
|
|
13
|
-
readonly 'acl': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "ACL", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "ACL", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "ACL", Context, Input>; }>;
|
|
14
|
-
readonly 'bind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "BIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "BIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "BIND", Context, Input>; }>;
|
|
15
|
-
readonly 'checkout': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "CHECKOUT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "CHECKOUT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "CHECKOUT", Context, Input>; }>;
|
|
16
|
-
readonly 'connect': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "CONNECT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "CONNECT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "CONNECT", Context, Input>; }>;
|
|
17
|
-
readonly 'copy': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "COPY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "COPY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "COPY", Context, Input>; }>;
|
|
18
|
-
readonly 'delete': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "DELETE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "DELETE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "DELETE", Context, Input>; }>;
|
|
19
|
-
readonly 'get': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "GET", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "GET", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "GET", Context, Input>; }>;
|
|
20
|
-
readonly 'head': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "HEAD", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "HEAD", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "HEAD", Context, Input>; }>;
|
|
21
|
-
readonly 'link': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "LINK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "LINK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "LINK", Context, Input>; }>;
|
|
22
|
-
readonly 'lock': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "LOCK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "LOCK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "LOCK", Context, Input>; }>;
|
|
23
|
-
readonly 'm_search': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "M-SEARCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "M-SEARCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "M-SEARCH", Context, Input>; }>;
|
|
24
|
-
readonly 'mkactivity': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKACTIVITY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKACTIVITY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKACTIVITY", Context, Input>; }>;
|
|
25
|
-
readonly 'mkcalendar': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKCALENDAR", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKCALENDAR", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKCALENDAR", Context, Input>; }>;
|
|
26
|
-
readonly 'mkcol': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MKCOL", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MKCOL", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MKCOL", Context, Input>; }>;
|
|
27
|
-
readonly 'move': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "MOVE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "MOVE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "MOVE", Context, Input>; }>;
|
|
28
|
-
readonly 'notify': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "NOTIFY", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "NOTIFY", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "NOTIFY", Context, Input>; }>;
|
|
29
|
-
readonly 'patch': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PATCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PATCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PATCH", Context, Input>; }>;
|
|
30
|
-
readonly 'post': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "POST", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "POST", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "POST", Context, Input>; }>;
|
|
31
|
-
readonly 'propfind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PROPFIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PROPFIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PROPFIND", Context, Input>; }>;
|
|
32
|
-
readonly 'proppatch': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PROPPATCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PROPPATCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PROPPATCH", Context, Input>; }>;
|
|
33
|
-
readonly 'purge': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PURGE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PURGE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PURGE", Context, Input>; }>;
|
|
34
|
-
readonly 'put': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "PUT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "PUT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "PUT", Context, Input>; }>;
|
|
35
|
-
readonly 'rebind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "REBIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "REBIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "REBIND", Context, Input>; }>;
|
|
36
|
-
readonly 'report': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "REPORT", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "REPORT", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "REPORT", Context, Input>; }>;
|
|
37
|
-
readonly 'search': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SEARCH", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SEARCH", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SEARCH", Context, Input>; }>;
|
|
38
|
-
readonly 'source': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SOURCE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SOURCE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SOURCE", Context, Input>; }>;
|
|
39
|
-
readonly 'subscribe': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "SUBSCRIBE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "SUBSCRIBE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "SUBSCRIBE", Context, Input>; }>;
|
|
40
|
-
readonly 'trace': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "TRACE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "TRACE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "TRACE", Context, Input>; }>;
|
|
41
|
-
readonly 'unbind': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNBIND", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNBIND", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNBIND", Context, Input>; }>;
|
|
42
|
-
readonly 'unlink': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNLINK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNLINK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNLINK", Context, Input>; }>;
|
|
43
|
-
readonly 'unlock': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNLOCK", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNLOCK", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNLOCK", Context, Input>; }>;
|
|
44
|
-
readonly 'unsubscribe': <Result, Path extends `/${string}`, Input extends z.ZodType<any, z.ZodTypeDef, any> = never>(path: Path, route: Omit<Route<Result, Path, "UNSUBSCRIBE", Context, Input>, "method">) => Router<Context, Path extends keyof Routes ? NoEmpty<Pick<Routes, Path>> | { [key in Path]: Route<Result, Path, "UNSUBSCRIBE", Context, Input>; } : Routes & { [key_1 in Path]: Route<Result, Path, "UNSUBSCRIBE", Context, Input>; }>;
|
|
45
15
|
private constructor();
|
|
46
|
-
merge<Prefix extends string, NewRoutes extends RoutesInit<Context>>(prefix: NormalizePath<Prefix>, router: Router<Context, NewRoutes>): Router<Context, Routes & { [Path in Extract<keyof NewRoutes, string> as `/${Prefix}${Path}`]: Values<{ [M in NewRoutes[Path]["method"]]: Omit<Extract<NewRoutes[Path], {
|
|
47
|
-
method: M;
|
|
48
|
-
}>, "method" | "path"> & {
|
|
49
|
-
path: `/${Prefix}${Path}`;
|
|
50
|
-
method: M;
|
|
51
|
-
}; }>; }>;
|
|
52
16
|
toFindMyWay(server: ServerConfig<Context>): Instance<fmw.HTTPVersion.V1>;
|
|
53
|
-
|
|
54
|
-
|
|
17
|
+
add<Method extends HTTPMethod, Path extends string, Result, Input extends z.ZodSchema>(route: Route<Context, Result, Path, Method, Input>): Router<Context, [...Routes, Route<Context, Result, Path, Method, Input>]>;
|
|
18
|
+
map(): { [Method in Routes[number]["method"]]: { [R in Extract<Routes[number], {
|
|
19
|
+
method: Method;
|
|
20
|
+
}> as R["path"]]: R; }; };
|
|
21
|
+
merge<Prefix extends string, NewRoutes extends RoutesInit<Context>>(prefix: Prefix, router: Router<Context, NewRoutes>): Router<Context, [...Routes, ...MergePaths<NewRoutes, Prefix>]>;
|
|
22
|
+
private copyContext;
|
|
55
23
|
}
|
|
56
24
|
/**
|
|
57
25
|
* @deprecated Please use Router#create instead
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Router
|
|
2
|
+
import { Router } from './router';
|
|
3
3
|
import * as http from 'http';
|
|
4
4
|
import { KaitoRequest } from './req';
|
|
5
5
|
import { KaitoResponse } from './res';
|
|
@@ -7,7 +7,7 @@ import { KaitoError } from './error';
|
|
|
7
7
|
import { GetContext } from './util';
|
|
8
8
|
export declare type Before = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
9
9
|
export interface ServerConfig<Context> {
|
|
10
|
-
router: Router<Context,
|
|
10
|
+
router: Router<Context, any>;
|
|
11
11
|
getContext: GetContext<Context>;
|
|
12
12
|
before?: Before[];
|
|
13
13
|
onError(arg: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HTTPMethod } from 'find-my-way';
|
|
1
2
|
import { KaitoRequest } from './req';
|
|
2
3
|
import { KaitoResponse } from './res';
|
|
3
4
|
export declare type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
@@ -5,6 +6,7 @@ export declare type ExtractRouteParams<T extends string> = string extends T ? Re
|
|
|
5
6
|
} : T extends `${string}:${infer Param}` ? {
|
|
6
7
|
[k in Param]: string;
|
|
7
8
|
} : {};
|
|
9
|
+
export declare type KaitoMethod = HTTPMethod | '*';
|
|
8
10
|
export declare type GetContext<Result> = (req: KaitoRequest, res: KaitoResponse) => Promise<Result>;
|
|
9
11
|
export declare function createGetContext<Context>(callback: GetContext<Context>): GetContext<Context>;
|
|
10
12
|
export declare type InferContext<T> = T extends (req: KaitoRequest, res: KaitoResponse) => Promise<infer U> ? U : never;
|
|
@@ -306,18 +306,18 @@ class KaitoResponse {
|
|
|
306
306
|
|
|
307
307
|
class Router {
|
|
308
308
|
static create() {
|
|
309
|
-
return new Router(
|
|
309
|
+
return new Router([]);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
static handle(server, options) {
|
|
312
|
+
static handle(server, route, options) {
|
|
313
313
|
return _asyncToGenerator(function* () {
|
|
314
314
|
try {
|
|
315
|
-
var
|
|
315
|
+
var _route$input$parse, _route$input;
|
|
316
316
|
|
|
317
317
|
var context = yield server.getContext(options.req, options.res);
|
|
318
318
|
var body = yield getInput(options.req);
|
|
319
|
-
var input = (
|
|
320
|
-
var result = yield
|
|
319
|
+
var input = (_route$input$parse = (_route$input = route.input) === null || _route$input === void 0 ? void 0 : _route$input.parse(body)) !== null && _route$input$parse !== void 0 ? _route$input$parse : undefined;
|
|
320
|
+
var result = yield route.run({
|
|
321
321
|
ctx: context,
|
|
322
322
|
input,
|
|
323
323
|
params: options.params
|
|
@@ -360,87 +360,10 @@ class Router {
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
constructor(routes) {
|
|
363
|
-
_defineProperty(this, 'acl', this.make('ACL'));
|
|
364
|
-
|
|
365
|
-
_defineProperty(this, 'bind', this.make('BIND'));
|
|
366
|
-
|
|
367
|
-
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
368
|
-
|
|
369
|
-
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
370
|
-
|
|
371
|
-
_defineProperty(this, 'copy', this.make('COPY'));
|
|
372
|
-
|
|
373
|
-
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
374
|
-
|
|
375
|
-
_defineProperty(this, 'get', this.make('GET'));
|
|
376
|
-
|
|
377
|
-
_defineProperty(this, 'head', this.make('HEAD'));
|
|
378
|
-
|
|
379
|
-
_defineProperty(this, 'link', this.make('LINK'));
|
|
380
|
-
|
|
381
|
-
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
382
|
-
|
|
383
|
-
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
384
|
-
|
|
385
|
-
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
386
|
-
|
|
387
|
-
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
388
|
-
|
|
389
|
-
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
390
|
-
|
|
391
|
-
_defineProperty(this, 'move', this.make('MOVE'));
|
|
392
|
-
|
|
393
|
-
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
394
|
-
|
|
395
|
-
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
396
|
-
|
|
397
|
-
_defineProperty(this, 'post', this.make('POST'));
|
|
398
|
-
|
|
399
|
-
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
400
|
-
|
|
401
|
-
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
402
|
-
|
|
403
|
-
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
404
|
-
|
|
405
|
-
_defineProperty(this, 'put', this.make('PUT'));
|
|
406
|
-
|
|
407
|
-
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
408
|
-
|
|
409
|
-
_defineProperty(this, 'report', this.make('REPORT'));
|
|
410
|
-
|
|
411
|
-
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
412
|
-
|
|
413
|
-
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
414
|
-
|
|
415
|
-
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
416
|
-
|
|
417
|
-
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
418
|
-
|
|
419
|
-
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
420
|
-
|
|
421
|
-
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
422
|
-
|
|
423
|
-
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
424
|
-
|
|
425
|
-
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
426
|
-
|
|
427
363
|
this.routes = routes;
|
|
428
364
|
}
|
|
429
365
|
|
|
430
|
-
merge(prefix, router) {
|
|
431
|
-
var newRoutes = Object.fromEntries(Object.entries(router.routes).map(_ref => {
|
|
432
|
-
var [k, v] = _ref;
|
|
433
|
-
return ["".concat(prefix).concat(k), v];
|
|
434
|
-
}));
|
|
435
|
-
|
|
436
|
-
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
437
|
-
|
|
438
|
-
return this._copy(merged);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
366
|
toFindMyWay(server) {
|
|
442
|
-
var _this = this;
|
|
443
|
-
|
|
444
367
|
var instance = fmw__default["default"]({
|
|
445
368
|
ignoreTrailingSlash: true,
|
|
446
369
|
|
|
@@ -456,54 +379,69 @@ class Router {
|
|
|
456
379
|
}
|
|
457
380
|
|
|
458
381
|
});
|
|
459
|
-
var paths = Object.keys(this.routes);
|
|
460
382
|
|
|
461
|
-
var _loop = function _loop(
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
var _ref2 = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
383
|
+
var _loop = function _loop(route) {
|
|
384
|
+
var handler = /*#__PURE__*/function () {
|
|
385
|
+
var _ref = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
465
386
|
var req = new KaitoRequest(incomingMessage);
|
|
466
387
|
var res = new KaitoResponse(serverResponse);
|
|
467
|
-
yield Router.handle(server, {
|
|
468
|
-
route,
|
|
388
|
+
yield Router.handle(server, route, {
|
|
469
389
|
params,
|
|
470
390
|
req,
|
|
471
391
|
res
|
|
472
392
|
});
|
|
473
393
|
});
|
|
474
394
|
|
|
475
|
-
return function (_x, _x2, _x3) {
|
|
476
|
-
return
|
|
395
|
+
return function handler(_x, _x2, _x3) {
|
|
396
|
+
return _ref.apply(this, arguments);
|
|
477
397
|
};
|
|
478
|
-
}()
|
|
398
|
+
}();
|
|
399
|
+
|
|
400
|
+
if (route.method === '*') {
|
|
401
|
+
instance.all(route.path, handler);
|
|
402
|
+
return "continue";
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
instance.on(route.method, route.path, handler);
|
|
479
406
|
};
|
|
480
407
|
|
|
481
|
-
for (var
|
|
482
|
-
_loop(
|
|
408
|
+
for (var route of this.routes) {
|
|
409
|
+
var _ret = _loop(route);
|
|
410
|
+
|
|
411
|
+
if (_ret === "continue") continue;
|
|
483
412
|
}
|
|
484
413
|
|
|
485
414
|
return instance;
|
|
486
415
|
}
|
|
487
416
|
|
|
488
|
-
|
|
489
|
-
return new Router(routes);
|
|
417
|
+
add(route) {
|
|
418
|
+
return new Router([...this.routes, route]);
|
|
490
419
|
}
|
|
491
420
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
method
|
|
496
|
-
}); // `as unknown` is required because otherwise
|
|
497
|
-
// this type just gets massive and too slow,
|
|
498
|
-
// so we have to write it out specifically
|
|
421
|
+
map() {
|
|
422
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
423
|
+
var result = {};
|
|
499
424
|
|
|
425
|
+
for (var route of this.routes) {
|
|
426
|
+
var _result$method;
|
|
500
427
|
|
|
501
|
-
var
|
|
502
|
-
|
|
428
|
+
var method = route.method;
|
|
429
|
+
result[method] = _objectSpread2(_objectSpread2({}, (_result$method = result[method]) !== null && _result$method !== void 0 ? _result$method : {}), {}, {
|
|
430
|
+
[route.path]: route
|
|
503
431
|
});
|
|
432
|
+
}
|
|
504
433
|
|
|
505
|
-
|
|
506
|
-
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
merge(prefix, router) {
|
|
438
|
+
return this.copyContext([...this.routes, ...router.routes.map(route => _objectSpread2(_objectSpread2({}, route), {}, {
|
|
439
|
+
path: prefix + route.path
|
|
440
|
+
}))]);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
copyContext(routes) {
|
|
444
|
+
return new Router(routes);
|
|
507
445
|
}
|
|
508
446
|
|
|
509
447
|
}
|
|
@@ -306,18 +306,18 @@ class KaitoResponse {
|
|
|
306
306
|
|
|
307
307
|
class Router {
|
|
308
308
|
static create() {
|
|
309
|
-
return new Router(
|
|
309
|
+
return new Router([]);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
static handle(server, options) {
|
|
312
|
+
static handle(server, route, options) {
|
|
313
313
|
return _asyncToGenerator(function* () {
|
|
314
314
|
try {
|
|
315
|
-
var
|
|
315
|
+
var _route$input$parse, _route$input;
|
|
316
316
|
|
|
317
317
|
var context = yield server.getContext(options.req, options.res);
|
|
318
318
|
var body = yield getInput(options.req);
|
|
319
|
-
var input = (
|
|
320
|
-
var result = yield
|
|
319
|
+
var input = (_route$input$parse = (_route$input = route.input) === null || _route$input === void 0 ? void 0 : _route$input.parse(body)) !== null && _route$input$parse !== void 0 ? _route$input$parse : undefined;
|
|
320
|
+
var result = yield route.run({
|
|
321
321
|
ctx: context,
|
|
322
322
|
input,
|
|
323
323
|
params: options.params
|
|
@@ -360,87 +360,10 @@ class Router {
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
constructor(routes) {
|
|
363
|
-
_defineProperty(this, 'acl', this.make('ACL'));
|
|
364
|
-
|
|
365
|
-
_defineProperty(this, 'bind', this.make('BIND'));
|
|
366
|
-
|
|
367
|
-
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
368
|
-
|
|
369
|
-
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
370
|
-
|
|
371
|
-
_defineProperty(this, 'copy', this.make('COPY'));
|
|
372
|
-
|
|
373
|
-
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
374
|
-
|
|
375
|
-
_defineProperty(this, 'get', this.make('GET'));
|
|
376
|
-
|
|
377
|
-
_defineProperty(this, 'head', this.make('HEAD'));
|
|
378
|
-
|
|
379
|
-
_defineProperty(this, 'link', this.make('LINK'));
|
|
380
|
-
|
|
381
|
-
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
382
|
-
|
|
383
|
-
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
384
|
-
|
|
385
|
-
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
386
|
-
|
|
387
|
-
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
388
|
-
|
|
389
|
-
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
390
|
-
|
|
391
|
-
_defineProperty(this, 'move', this.make('MOVE'));
|
|
392
|
-
|
|
393
|
-
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
394
|
-
|
|
395
|
-
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
396
|
-
|
|
397
|
-
_defineProperty(this, 'post', this.make('POST'));
|
|
398
|
-
|
|
399
|
-
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
400
|
-
|
|
401
|
-
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
402
|
-
|
|
403
|
-
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
404
|
-
|
|
405
|
-
_defineProperty(this, 'put', this.make('PUT'));
|
|
406
|
-
|
|
407
|
-
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
408
|
-
|
|
409
|
-
_defineProperty(this, 'report', this.make('REPORT'));
|
|
410
|
-
|
|
411
|
-
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
412
|
-
|
|
413
|
-
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
414
|
-
|
|
415
|
-
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
416
|
-
|
|
417
|
-
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
418
|
-
|
|
419
|
-
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
420
|
-
|
|
421
|
-
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
422
|
-
|
|
423
|
-
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
424
|
-
|
|
425
|
-
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
426
|
-
|
|
427
363
|
this.routes = routes;
|
|
428
364
|
}
|
|
429
365
|
|
|
430
|
-
merge(prefix, router) {
|
|
431
|
-
var newRoutes = Object.fromEntries(Object.entries(router.routes).map(_ref => {
|
|
432
|
-
var [k, v] = _ref;
|
|
433
|
-
return ["".concat(prefix).concat(k), v];
|
|
434
|
-
}));
|
|
435
|
-
|
|
436
|
-
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
437
|
-
|
|
438
|
-
return this._copy(merged);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
366
|
toFindMyWay(server) {
|
|
442
|
-
var _this = this;
|
|
443
|
-
|
|
444
367
|
var instance = fmw__default["default"]({
|
|
445
368
|
ignoreTrailingSlash: true,
|
|
446
369
|
|
|
@@ -456,54 +379,69 @@ class Router {
|
|
|
456
379
|
}
|
|
457
380
|
|
|
458
381
|
});
|
|
459
|
-
var paths = Object.keys(this.routes);
|
|
460
382
|
|
|
461
|
-
var _loop = function _loop(
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
var _ref2 = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
383
|
+
var _loop = function _loop(route) {
|
|
384
|
+
var handler = /*#__PURE__*/function () {
|
|
385
|
+
var _ref = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
465
386
|
var req = new KaitoRequest(incomingMessage);
|
|
466
387
|
var res = new KaitoResponse(serverResponse);
|
|
467
|
-
yield Router.handle(server, {
|
|
468
|
-
route,
|
|
388
|
+
yield Router.handle(server, route, {
|
|
469
389
|
params,
|
|
470
390
|
req,
|
|
471
391
|
res
|
|
472
392
|
});
|
|
473
393
|
});
|
|
474
394
|
|
|
475
|
-
return function (_x, _x2, _x3) {
|
|
476
|
-
return
|
|
395
|
+
return function handler(_x, _x2, _x3) {
|
|
396
|
+
return _ref.apply(this, arguments);
|
|
477
397
|
};
|
|
478
|
-
}()
|
|
398
|
+
}();
|
|
399
|
+
|
|
400
|
+
if (route.method === '*') {
|
|
401
|
+
instance.all(route.path, handler);
|
|
402
|
+
return "continue";
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
instance.on(route.method, route.path, handler);
|
|
479
406
|
};
|
|
480
407
|
|
|
481
|
-
for (var
|
|
482
|
-
_loop(
|
|
408
|
+
for (var route of this.routes) {
|
|
409
|
+
var _ret = _loop(route);
|
|
410
|
+
|
|
411
|
+
if (_ret === "continue") continue;
|
|
483
412
|
}
|
|
484
413
|
|
|
485
414
|
return instance;
|
|
486
415
|
}
|
|
487
416
|
|
|
488
|
-
|
|
489
|
-
return new Router(routes);
|
|
417
|
+
add(route) {
|
|
418
|
+
return new Router([...this.routes, route]);
|
|
490
419
|
}
|
|
491
420
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
method
|
|
496
|
-
}); // `as unknown` is required because otherwise
|
|
497
|
-
// this type just gets massive and too slow,
|
|
498
|
-
// so we have to write it out specifically
|
|
421
|
+
map() {
|
|
422
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
423
|
+
var result = {};
|
|
499
424
|
|
|
425
|
+
for (var route of this.routes) {
|
|
426
|
+
var _result$method;
|
|
500
427
|
|
|
501
|
-
var
|
|
502
|
-
|
|
428
|
+
var method = route.method;
|
|
429
|
+
result[method] = _objectSpread2(_objectSpread2({}, (_result$method = result[method]) !== null && _result$method !== void 0 ? _result$method : {}), {}, {
|
|
430
|
+
[route.path]: route
|
|
503
431
|
});
|
|
432
|
+
}
|
|
504
433
|
|
|
505
|
-
|
|
506
|
-
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
merge(prefix, router) {
|
|
438
|
+
return this.copyContext([...this.routes, ...router.routes.map(route => _objectSpread2(_objectSpread2({}, route), {}, {
|
|
439
|
+
path: prefix + route.path
|
|
440
|
+
}))]);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
copyContext(routes) {
|
|
444
|
+
return new Router(routes);
|
|
507
445
|
}
|
|
508
446
|
|
|
509
447
|
}
|
|
@@ -278,18 +278,18 @@ class KaitoResponse {
|
|
|
278
278
|
|
|
279
279
|
class Router {
|
|
280
280
|
static create() {
|
|
281
|
-
return new Router(
|
|
281
|
+
return new Router([]);
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
static handle(server, options) {
|
|
284
|
+
static handle(server, route, options) {
|
|
285
285
|
return _asyncToGenerator(function* () {
|
|
286
286
|
try {
|
|
287
|
-
var
|
|
287
|
+
var _route$input$parse, _route$input;
|
|
288
288
|
|
|
289
289
|
var context = yield server.getContext(options.req, options.res);
|
|
290
290
|
var body = yield getInput(options.req);
|
|
291
|
-
var input = (
|
|
292
|
-
var result = yield
|
|
291
|
+
var input = (_route$input$parse = (_route$input = route.input) === null || _route$input === void 0 ? void 0 : _route$input.parse(body)) !== null && _route$input$parse !== void 0 ? _route$input$parse : undefined;
|
|
292
|
+
var result = yield route.run({
|
|
293
293
|
ctx: context,
|
|
294
294
|
input,
|
|
295
295
|
params: options.params
|
|
@@ -332,87 +332,10 @@ class Router {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
constructor(routes) {
|
|
335
|
-
_defineProperty(this, 'acl', this.make('ACL'));
|
|
336
|
-
|
|
337
|
-
_defineProperty(this, 'bind', this.make('BIND'));
|
|
338
|
-
|
|
339
|
-
_defineProperty(this, 'checkout', this.make('CHECKOUT'));
|
|
340
|
-
|
|
341
|
-
_defineProperty(this, 'connect', this.make('CONNECT'));
|
|
342
|
-
|
|
343
|
-
_defineProperty(this, 'copy', this.make('COPY'));
|
|
344
|
-
|
|
345
|
-
_defineProperty(this, 'delete', this.make('DELETE'));
|
|
346
|
-
|
|
347
|
-
_defineProperty(this, 'get', this.make('GET'));
|
|
348
|
-
|
|
349
|
-
_defineProperty(this, 'head', this.make('HEAD'));
|
|
350
|
-
|
|
351
|
-
_defineProperty(this, 'link', this.make('LINK'));
|
|
352
|
-
|
|
353
|
-
_defineProperty(this, 'lock', this.make('LOCK'));
|
|
354
|
-
|
|
355
|
-
_defineProperty(this, 'm_search', this.make('M-SEARCH'));
|
|
356
|
-
|
|
357
|
-
_defineProperty(this, 'mkactivity', this.make('MKACTIVITY'));
|
|
358
|
-
|
|
359
|
-
_defineProperty(this, 'mkcalendar', this.make('MKCALENDAR'));
|
|
360
|
-
|
|
361
|
-
_defineProperty(this, 'mkcol', this.make('MKCOL'));
|
|
362
|
-
|
|
363
|
-
_defineProperty(this, 'move', this.make('MOVE'));
|
|
364
|
-
|
|
365
|
-
_defineProperty(this, 'notify', this.make('NOTIFY'));
|
|
366
|
-
|
|
367
|
-
_defineProperty(this, 'patch', this.make('PATCH'));
|
|
368
|
-
|
|
369
|
-
_defineProperty(this, 'post', this.make('POST'));
|
|
370
|
-
|
|
371
|
-
_defineProperty(this, 'propfind', this.make('PROPFIND'));
|
|
372
|
-
|
|
373
|
-
_defineProperty(this, 'proppatch', this.make('PROPPATCH'));
|
|
374
|
-
|
|
375
|
-
_defineProperty(this, 'purge', this.make('PURGE'));
|
|
376
|
-
|
|
377
|
-
_defineProperty(this, 'put', this.make('PUT'));
|
|
378
|
-
|
|
379
|
-
_defineProperty(this, 'rebind', this.make('REBIND'));
|
|
380
|
-
|
|
381
|
-
_defineProperty(this, 'report', this.make('REPORT'));
|
|
382
|
-
|
|
383
|
-
_defineProperty(this, 'search', this.make('SEARCH'));
|
|
384
|
-
|
|
385
|
-
_defineProperty(this, 'source', this.make('SOURCE'));
|
|
386
|
-
|
|
387
|
-
_defineProperty(this, 'subscribe', this.make('SUBSCRIBE'));
|
|
388
|
-
|
|
389
|
-
_defineProperty(this, 'trace', this.make('TRACE'));
|
|
390
|
-
|
|
391
|
-
_defineProperty(this, 'unbind', this.make('UNBIND'));
|
|
392
|
-
|
|
393
|
-
_defineProperty(this, 'unlink', this.make('UNLINK'));
|
|
394
|
-
|
|
395
|
-
_defineProperty(this, 'unlock', this.make('UNLOCK'));
|
|
396
|
-
|
|
397
|
-
_defineProperty(this, 'unsubscribe', this.make('UNSUBSCRIBE'));
|
|
398
|
-
|
|
399
335
|
this.routes = routes;
|
|
400
336
|
}
|
|
401
337
|
|
|
402
|
-
merge(prefix, router) {
|
|
403
|
-
var newRoutes = Object.fromEntries(Object.entries(router.routes).map(_ref => {
|
|
404
|
-
var [k, v] = _ref;
|
|
405
|
-
return ["".concat(prefix).concat(k), v];
|
|
406
|
-
}));
|
|
407
|
-
|
|
408
|
-
var merged = _objectSpread2(_objectSpread2({}, this.routes), newRoutes);
|
|
409
|
-
|
|
410
|
-
return this._copy(merged);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
338
|
toFindMyWay(server) {
|
|
414
|
-
var _this = this;
|
|
415
|
-
|
|
416
339
|
var instance = fmw({
|
|
417
340
|
ignoreTrailingSlash: true,
|
|
418
341
|
|
|
@@ -428,54 +351,69 @@ class Router {
|
|
|
428
351
|
}
|
|
429
352
|
|
|
430
353
|
});
|
|
431
|
-
var paths = Object.keys(this.routes);
|
|
432
354
|
|
|
433
|
-
var _loop = function _loop(
|
|
434
|
-
var
|
|
435
|
-
|
|
436
|
-
var _ref2 = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
355
|
+
var _loop = function _loop(route) {
|
|
356
|
+
var handler = /*#__PURE__*/function () {
|
|
357
|
+
var _ref = _asyncToGenerator(function* (incomingMessage, serverResponse, params) {
|
|
437
358
|
var req = new KaitoRequest(incomingMessage);
|
|
438
359
|
var res = new KaitoResponse(serverResponse);
|
|
439
|
-
yield Router.handle(server, {
|
|
440
|
-
route,
|
|
360
|
+
yield Router.handle(server, route, {
|
|
441
361
|
params,
|
|
442
362
|
req,
|
|
443
363
|
res
|
|
444
364
|
});
|
|
445
365
|
});
|
|
446
366
|
|
|
447
|
-
return function (_x, _x2, _x3) {
|
|
448
|
-
return
|
|
367
|
+
return function handler(_x, _x2, _x3) {
|
|
368
|
+
return _ref.apply(this, arguments);
|
|
449
369
|
};
|
|
450
|
-
}()
|
|
370
|
+
}();
|
|
371
|
+
|
|
372
|
+
if (route.method === '*') {
|
|
373
|
+
instance.all(route.path, handler);
|
|
374
|
+
return "continue";
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
instance.on(route.method, route.path, handler);
|
|
451
378
|
};
|
|
452
379
|
|
|
453
|
-
for (var
|
|
454
|
-
_loop(
|
|
380
|
+
for (var route of this.routes) {
|
|
381
|
+
var _ret = _loop(route);
|
|
382
|
+
|
|
383
|
+
if (_ret === "continue") continue;
|
|
455
384
|
}
|
|
456
385
|
|
|
457
386
|
return instance;
|
|
458
387
|
}
|
|
459
388
|
|
|
460
|
-
|
|
461
|
-
return new Router(routes);
|
|
389
|
+
add(route) {
|
|
390
|
+
return new Router([...this.routes, route]);
|
|
462
391
|
}
|
|
463
392
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
method
|
|
468
|
-
}); // `as unknown` is required because otherwise
|
|
469
|
-
// this type just gets massive and too slow,
|
|
470
|
-
// so we have to write it out specifically
|
|
393
|
+
map() {
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
395
|
+
var result = {};
|
|
471
396
|
|
|
397
|
+
for (var route of this.routes) {
|
|
398
|
+
var _result$method;
|
|
472
399
|
|
|
473
|
-
var
|
|
474
|
-
|
|
400
|
+
var method = route.method;
|
|
401
|
+
result[method] = _objectSpread2(_objectSpread2({}, (_result$method = result[method]) !== null && _result$method !== void 0 ? _result$method : {}), {}, {
|
|
402
|
+
[route.path]: route
|
|
475
403
|
});
|
|
404
|
+
}
|
|
476
405
|
|
|
477
|
-
|
|
478
|
-
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
merge(prefix, router) {
|
|
410
|
+
return this.copyContext([...this.routes, ...router.routes.map(route => _objectSpread2(_objectSpread2({}, route), {}, {
|
|
411
|
+
path: prefix + route.path
|
|
412
|
+
}))]);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
copyContext(routes) {
|
|
416
|
+
return new Router(routes);
|
|
479
417
|
}
|
|
480
418
|
|
|
481
419
|
}
|