@kaito-http/core 2.3.9 → 2.5.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/index.d.ts +5 -5
- package/dist/declarations/src/req.d.ts +20 -1
- package/dist/declarations/src/res.d.ts +26 -1
- package/dist/declarations/src/route.d.ts +9 -8
- package/dist/declarations/src/router.d.ts +17 -55
- package/dist/declarations/src/server.d.ts +33 -13
- package/dist/declarations/src/util.d.ts +2 -0
- package/dist/kaito-http-core.cjs.dev.js +298 -275
- package/dist/kaito-http-core.cjs.prod.js +294 -275
- package/dist/kaito-http-core.esm.js +281 -257
- package/package.json +7 -5
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type { HTTPMethod } from 'find-my-way';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './router';
|
|
4
|
-
export * from './route';
|
|
5
|
-
export * from './util';
|
|
2
|
+
export * from './error';
|
|
6
3
|
export * from './req';
|
|
7
4
|
export * from './res';
|
|
8
|
-
export * from './
|
|
5
|
+
export * from './route';
|
|
6
|
+
export * from './router';
|
|
7
|
+
export * from './server';
|
|
8
|
+
export * from './util';
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { HTTPMethod } from 'find-my-way';
|
|
3
|
-
import { IncomingMessage } from 'http';
|
|
3
|
+
import { IncomingMessage } from 'node:http';
|
|
4
4
|
export declare class KaitoRequest {
|
|
5
5
|
readonly raw: IncomingMessage;
|
|
6
6
|
private _url;
|
|
7
7
|
constructor(raw: IncomingMessage);
|
|
8
|
+
/**
|
|
9
|
+
* The full URL of the request, including the protocol, hostname, and path.
|
|
10
|
+
* Note: does not include the query string or hash
|
|
11
|
+
*/
|
|
8
12
|
get fullURL(): string;
|
|
13
|
+
/**
|
|
14
|
+
* A new URL instance for the full URL of the request.
|
|
15
|
+
*/
|
|
9
16
|
get url(): URL;
|
|
17
|
+
/**
|
|
18
|
+
* The HTTP method of the request.
|
|
19
|
+
*/
|
|
10
20
|
get method(): HTTPMethod;
|
|
21
|
+
/**
|
|
22
|
+
* The protocol of the request, either `http` or `https`.
|
|
23
|
+
*/
|
|
11
24
|
get protocol(): 'http' | 'https';
|
|
25
|
+
/**
|
|
26
|
+
* The request headers
|
|
27
|
+
*/
|
|
12
28
|
get headers(): import("http").IncomingHttpHeaders;
|
|
29
|
+
/**
|
|
30
|
+
* The hostname of the request.
|
|
31
|
+
*/
|
|
13
32
|
get hostname(): string;
|
|
14
33
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ServerResponse } from 'http';
|
|
2
|
+
import { ServerResponse } from 'node:http';
|
|
3
|
+
import { CookieSerializeOptions } from 'cookie';
|
|
3
4
|
export declare type ErroredAPIResponse = {
|
|
4
5
|
success: false;
|
|
5
6
|
data: null;
|
|
@@ -15,7 +16,31 @@ export declare type AnyResponse = APIResponse<unknown>;
|
|
|
15
16
|
export declare class KaitoResponse<T = unknown> {
|
|
16
17
|
readonly raw: ServerResponse;
|
|
17
18
|
constructor(raw: ServerResponse);
|
|
19
|
+
/**
|
|
20
|
+
* Send a response
|
|
21
|
+
* @param key The key of the header
|
|
22
|
+
* @param value The value of the header
|
|
23
|
+
* @returns The response object
|
|
24
|
+
*/
|
|
18
25
|
header(key: string, value: string | readonly string[]): this;
|
|
26
|
+
/**
|
|
27
|
+
* Set the status code of the response
|
|
28
|
+
* @param code The status code
|
|
29
|
+
* @returns The response object
|
|
30
|
+
*/
|
|
19
31
|
status(code: number): this;
|
|
32
|
+
/**
|
|
33
|
+
* Set a cookie
|
|
34
|
+
* @param name The name of the cookie
|
|
35
|
+
* @param value The value of the cookie
|
|
36
|
+
* @param options The options for the cookie
|
|
37
|
+
* @returns The response object
|
|
38
|
+
*/
|
|
39
|
+
cookie(name: string, value: string, options: CookieSerializeOptions): this;
|
|
40
|
+
/**
|
|
41
|
+
* Send a JSON APIResponse body
|
|
42
|
+
* @param data The data to send
|
|
43
|
+
* @returns The response object
|
|
44
|
+
*/
|
|
20
45
|
json(data: APIResponse<T>): this;
|
|
21
46
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { HTTPMethod } from 'find-my-way';
|
|
2
1
|
import { z } from 'zod';
|
|
3
|
-
import { ExtractRouteParams } from './util';
|
|
4
|
-
export declare type RouteArgument<Path extends string, Context,
|
|
2
|
+
import { ExtractRouteParams, KaitoMethod } from './util';
|
|
3
|
+
export declare type RouteArgument<Path extends string, Context, InputOutput> = {
|
|
5
4
|
ctx: Context;
|
|
6
|
-
input:
|
|
5
|
+
input: InputOutput;
|
|
7
6
|
params: ExtractRouteParams<Path>;
|
|
8
7
|
};
|
|
9
|
-
export
|
|
10
|
-
input?:
|
|
8
|
+
export declare type Route<Context, Result, Path extends string, Method extends KaitoMethod, InputOutput = never, InputDef extends z.ZodTypeDef = z.ZodTypeDef, InputInput = InputOutput> = {
|
|
9
|
+
input?: z.ZodType<InputOutput, InputDef, InputInput>;
|
|
10
|
+
path: Path;
|
|
11
11
|
method: Method;
|
|
12
|
-
run(
|
|
13
|
-
}
|
|
12
|
+
run(args: RouteArgument<Path, Context, InputOutput>): Promise<Result>;
|
|
13
|
+
};
|
|
14
|
+
export declare type AnyRoute<Context = any> = Route<Context, any, any, any, any, z.ZodTypeDef, any>;
|
|
@@ -1,59 +1,21 @@
|
|
|
1
|
-
import fmw
|
|
1
|
+
import fmw from 'find-my-way';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Route } from './route';
|
|
3
|
+
import { AnyRoute, Route } from './route';
|
|
4
4
|
import { ServerConfig } from './server';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { KaitoMethod } from './util';
|
|
6
|
+
declare type Routes = readonly AnyRoute[];
|
|
7
|
+
declare type RemapRoutePrefix<R extends AnyRoute, Prefix extends `/${string}`> = R extends Route<infer Context, infer Result, infer Path, infer Method, infer InputOutput, infer InputDef, infer InputInput> ? Route<Context, Result, `${Prefix}${Path}`, Method, InputOutput, InputDef, InputInput> : never;
|
|
8
|
+
declare type PrefixRoutesPath<Prefix extends `/${string}`, R extends Routes> = R extends [infer First, ...infer Rest] ? [
|
|
9
|
+
RemapRoutePrefix<Extract<First, AnyRoute<any>>, Prefix>,
|
|
10
|
+
...PrefixRoutesPath<Prefix, Extract<Rest, readonly AnyRoute<any>[]>>
|
|
11
|
+
] : [];
|
|
12
|
+
export declare class Router<Context, R extends Routes> {
|
|
13
|
+
readonly routes: R;
|
|
14
|
+
constructor(routes: R);
|
|
11
15
|
private static handle;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
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
|
-
toFindMyWay(server: ServerConfig<Context>): Instance<fmw.HTTPVersion.V1>;
|
|
53
|
-
_copy<NewRoutes extends RoutesInit<Context>>(routes: NewRoutes): Router<Context, NewRoutes>;
|
|
54
|
-
private make;
|
|
16
|
+
static create: <Context_1>() => Router<Context_1, []>;
|
|
17
|
+
add: <Result, Path extends string, Method extends KaitoMethod, InputOutput = never, InputDef extends z.ZodTypeDef = z.ZodTypeDef, InputInput = InputOutput>(route: Route<Context, Result, Path, Method, InputOutput, InputDef, InputInput>) => Router<Context, [...R, Route<Context, Result, Path, Method, InputOutput, InputDef, InputInput>]>;
|
|
18
|
+
merge: <PathPrefix extends `/${string}`, OtherRoutes extends Routes>(pathPrefix: PathPrefix, other: Router<Context, OtherRoutes>) => Router<Context, [...R, ...PrefixRoutesPath<PathPrefix, OtherRoutes>]>;
|
|
19
|
+
toFindMyWay: (server: ServerConfig<Context, any>) => fmw.Instance<fmw.HTTPVersion.V1>;
|
|
55
20
|
}
|
|
56
|
-
|
|
57
|
-
* @deprecated Please use Router#create instead
|
|
58
|
-
*/
|
|
59
|
-
export declare const createRouter: typeof Router.create;
|
|
21
|
+
export {};
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as http from 'node:http';
|
|
3
|
+
import { KaitoError } from './error';
|
|
4
4
|
import { KaitoRequest } from './req';
|
|
5
5
|
import { KaitoResponse } from './res';
|
|
6
|
-
import {
|
|
7
|
-
import { GetContext } from './util';
|
|
8
|
-
export declare type Before = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<
|
|
9
|
-
export
|
|
10
|
-
|
|
6
|
+
import { Router } from './router';
|
|
7
|
+
import { GetContext, KaitoMethod } from './util';
|
|
8
|
+
export declare type Before<BeforeAfterContext> = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<BeforeAfterContext>;
|
|
9
|
+
export declare type HandlerResult = {
|
|
10
|
+
success: true;
|
|
11
|
+
data: unknown;
|
|
12
|
+
} | {
|
|
13
|
+
success: false;
|
|
14
|
+
data: {
|
|
15
|
+
status: number;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare type After<BeforeAfterContext> = (ctx: BeforeAfterContext, result: HandlerResult) => Promise<void>;
|
|
20
|
+
export declare type ServerConfigWithBefore<BeforeAfterContext> = {
|
|
21
|
+
before: Before<BeforeAfterContext>;
|
|
22
|
+
after?: After<BeforeAfterContext>;
|
|
23
|
+
} | {
|
|
24
|
+
before?: undefined;
|
|
25
|
+
};
|
|
26
|
+
export declare type ServerConfig<Context, BeforeAfterContext> = ServerConfigWithBefore<BeforeAfterContext> & {
|
|
27
|
+
router: Router<Context, any>;
|
|
11
28
|
getContext: GetContext<Context>;
|
|
12
|
-
|
|
29
|
+
rawRoutes?: Partial<Record<KaitoMethod, {
|
|
30
|
+
path: string;
|
|
31
|
+
handler: (request: http.IncomingMessage, response: http.ServerResponse) => unknown;
|
|
32
|
+
}[]>>;
|
|
13
33
|
onError(arg: {
|
|
14
34
|
error: Error;
|
|
15
35
|
req: KaitoRequest;
|
|
@@ -18,9 +38,9 @@ export interface ServerConfig<Context> {
|
|
|
18
38
|
status: number;
|
|
19
39
|
message: string;
|
|
20
40
|
}>;
|
|
21
|
-
}
|
|
22
|
-
export declare function createFMWServer<Context>(config: ServerConfig<Context>): {
|
|
23
|
-
server: http.Server;
|
|
24
|
-
fmw: import("find-my-way").Instance<import("find-my-way").HTTPVersion.V1>;
|
|
25
41
|
};
|
|
26
|
-
export declare function
|
|
42
|
+
export declare function createFMWServer<Context, BeforeAfterContext = null>(config: ServerConfig<Context, BeforeAfterContext>): {
|
|
43
|
+
readonly server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
44
|
+
readonly fmw: import("find-my-way").Instance<import("find-my-way").HTTPVersion.V1>;
|
|
45
|
+
};
|
|
46
|
+
export declare function createServer<Context, BeforeAfterContext = null>(config: ServerConfig<Context, BeforeAfterContext>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
@@ -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;
|