routup 1.0.3 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -26
- package/dist/dispatcher/adapters/index.d.ts +3 -0
- package/dist/dispatcher/adapters/node/index.d.ts +1 -0
- package/dist/dispatcher/adapters/node/module.d.ts +7 -0
- package/dist/dispatcher/adapters/raw/module.d.ts +4 -0
- package/dist/dispatcher/adapters/raw/type.d.ts +18 -0
- package/dist/{route → dispatcher/adapters/web}/index.d.ts +0 -1
- package/dist/dispatcher/adapters/web/module.d.ts +5 -0
- package/dist/dispatcher/adapters/web/type.d.ts +3 -0
- package/dist/dispatcher/index.d.ts +3 -0
- package/dist/dispatcher/type.d.ts +32 -0
- package/dist/dispatcher/utils.d.ts +5 -0
- package/dist/error/create.d.ts +11 -0
- package/dist/error/index.d.ts +3 -0
- package/dist/error/is.d.ts +2 -0
- package/dist/error/module.d.ts +3 -0
- package/dist/handler/constants.d.ts +4 -0
- package/dist/handler/core/define.d.ts +3 -0
- package/dist/handler/core/index.d.ts +2 -0
- package/dist/handler/core/types.d.ts +10 -0
- package/dist/handler/error/define.d.ts +3 -0
- package/dist/handler/error/index.d.ts +2 -0
- package/dist/handler/error/types.d.ts +11 -0
- package/dist/handler/index.d.ts +6 -1
- package/dist/handler/is.d.ts +2 -0
- package/dist/handler/types-base.d.ts +6 -0
- package/dist/handler/types.d.ts +5 -0
- package/dist/index.cjs +1202 -629
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +1172 -597
- package/dist/index.mjs.map +1 -1
- package/dist/layer/constants.d.ts +1 -0
- package/dist/layer/module.d.ts +13 -10
- package/dist/layer/type.d.ts +6 -4
- package/dist/path/index.d.ts +1 -0
- package/dist/path/matcher.d.ts +5 -6
- package/dist/path/type.d.ts +1 -0
- package/dist/path/utils.d.ts +2 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/is.d.ts +2 -0
- package/dist/plugin/types.d.ts +32 -0
- package/dist/{helpers/request → request/helpers}/body.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/cache.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/cookie.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/env.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept-charset.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept-language.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-accept.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header-content-type.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/header.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/hostname.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/index.d.ts +1 -0
- package/dist/{helpers/request → request/helpers}/ip.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/mount-path.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/negotiator.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/params.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/path.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/protocol.d.ts +1 -1
- package/dist/{helpers/request → request/helpers}/query.d.ts +1 -1
- package/dist/request/helpers/router.d.ts +3 -0
- package/dist/request/index.d.ts +3 -0
- package/dist/request/module.d.ts +4 -0
- package/dist/request/types.d.ts +13 -0
- package/dist/{helpers/response → response/helpers}/cache.d.ts +1 -1
- package/dist/response/helpers/gone.d.ts +2 -0
- package/dist/{helpers/response → response/helpers}/header-attachment.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/header-content-type.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/header.d.ts +1 -1
- package/dist/{helpers/response → response/helpers}/index.d.ts +3 -0
- package/dist/{helpers/response → response/helpers}/send-accepted.d.ts +2 -2
- package/dist/{helpers/response → response/helpers}/send-created.d.ts +2 -2
- package/dist/response/helpers/send-file.d.ts +17 -0
- package/dist/{helpers/response → response/helpers}/send-format.d.ts +1 -1
- package/dist/response/helpers/send-redirect.d.ts +2 -0
- package/dist/response/helpers/send-stream.d.ts +3 -0
- package/dist/response/helpers/send-web-blob.d.ts +3 -0
- package/dist/response/helpers/send-web-response.d.ts +3 -0
- package/dist/response/helpers/send.d.ts +2 -0
- package/dist/response/helpers/utils.d.ts +2 -0
- package/dist/response/index.d.ts +3 -0
- package/dist/response/module.d.ts +3 -0
- package/dist/response/types.d.ts +4 -0
- package/dist/router/constants.d.ts +1 -0
- package/dist/router/index.d.ts +1 -1
- package/dist/router/module.d.ts +34 -50
- package/dist/router/utils.d.ts +3 -0
- package/dist/router-options/index.d.ts +2 -0
- package/dist/router-options/module.d.ts +4 -0
- package/dist/router-options/transform.d.ts +2 -0
- package/dist/router-options/type.d.ts +41 -0
- package/dist/types.d.ts +10 -0
- package/dist/utils/cookie.d.ts +1 -0
- package/dist/utils/etag/module.d.ts +4 -3
- package/dist/utils/etag/type.d.ts +1 -1
- package/dist/utils/header.d.ts +3 -0
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/is-instance.d.ts +1 -1
- package/dist/utils/path.d.ts +5 -2
- package/dist/utils/stream.d.ts +8 -0
- package/dist/utils/web.d.ts +3 -0
- package/package.json +21 -19
- package/dist/config/module.d.ts +0 -8
- package/dist/config/type.d.ts +0 -34
- package/dist/handler/utils.d.ts +0 -2
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/response/send-file.d.ts +0 -9
- package/dist/helpers/response/send-redirect.d.ts +0 -2
- package/dist/helpers/response/send-stream.d.ts +0 -4
- package/dist/helpers/response/send.d.ts +0 -2
- package/dist/helpers/response/utils.d.ts +0 -3
- package/dist/route/module.d.ts +0 -27
- package/dist/route/type.d.ts +0 -6
- package/dist/route/utils.d.ts +0 -2
- package/dist/router/type.d.ts +0 -24
- package/dist/type.d.ts +0 -24
- package/dist/utils/request.d.ts +0 -2
- /package/dist/{config → dispatcher/adapters/raw}/index.d.ts +0 -0
- /package/dist/{helpers/request → request/helpers}/header-accept-encoding.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LayerSymbol: unique symbol;
|
package/dist/layer/module.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Dispatcher, DispatcherEvent, DispatcherMeta } from '../dispatcher';
|
|
2
|
+
import type { Handler } from '../handler';
|
|
2
3
|
import { PathMatcher } from '../path';
|
|
3
|
-
import type {
|
|
4
|
-
export declare class Layer {
|
|
4
|
+
import type { Response } from '../response';
|
|
5
|
+
export declare class Layer implements Dispatcher {
|
|
5
6
|
readonly '@instanceof': symbol;
|
|
6
|
-
protected
|
|
7
|
-
protected pathMatcher: PathMatcher;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
protected handler: Handler;
|
|
8
|
+
protected pathMatcher: PathMatcher | undefined;
|
|
9
|
+
constructor(handler: Handler);
|
|
10
|
+
get type(): "error" | "core";
|
|
11
|
+
get path(): import("../path").Path | undefined;
|
|
12
|
+
get method(): string | undefined;
|
|
13
|
+
dispatch(event: DispatcherEvent, meta: DispatcherMeta): Promise<boolean>;
|
|
14
|
+
protected sendOutput(res: Response, input: unknown): Promise<any>;
|
|
12
15
|
matchPath(path: string): boolean;
|
|
13
|
-
|
|
16
|
+
matchMethod(method: string): boolean;
|
|
14
17
|
}
|
package/dist/layer/type.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { MethodName } from '../constants';
|
|
2
|
+
import type { HandlerFn } from '../handler';
|
|
3
|
+
import type { Path } from '../path';
|
|
3
4
|
export type LayerOptions = {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
handler: HandlerFn;
|
|
6
|
+
method?: `${MethodName}`;
|
|
7
|
+
path?: Path;
|
|
6
8
|
};
|
package/dist/path/index.d.ts
CHANGED
package/dist/path/matcher.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Key } from 'path-to-regexp';
|
|
2
|
-
import type { Path } from '
|
|
3
|
-
import type { PathMatcherExecResult, PathMatcherOptions } from './type';
|
|
2
|
+
import type { Path, PathMatcherExecResult, PathMatcherOptions } from './type';
|
|
4
3
|
export declare class PathMatcher {
|
|
5
|
-
path: Path;
|
|
6
|
-
regexp: RegExp;
|
|
7
|
-
regexpKeys: Key[];
|
|
8
|
-
regexpOptions: PathMatcherOptions;
|
|
4
|
+
protected path: Path;
|
|
5
|
+
protected regexp: RegExp;
|
|
6
|
+
protected regexpKeys: Key[];
|
|
7
|
+
protected regexpOptions: PathMatcherOptions;
|
|
9
8
|
constructor(path: Path, options?: PathMatcherOptions);
|
|
10
9
|
test(path: string): boolean;
|
|
11
10
|
exec(path: string): PathMatcherExecResult | undefined;
|
package/dist/path/type.d.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Path } from '../path';
|
|
2
|
+
import type { Router } from '../router';
|
|
3
|
+
export type PluginOptions = Record<string | symbol, any>;
|
|
4
|
+
export type PluginInstallFn<Options extends PluginOptions = PluginOptions> = (router: Router, options: Options) => any;
|
|
5
|
+
export type Plugin<Options extends PluginOptions = PluginOptions> = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the plugin.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The supported routup (semver) version.
|
|
12
|
+
*/
|
|
13
|
+
version?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The installation function called on registration.
|
|
16
|
+
*/
|
|
17
|
+
install: PluginInstallFn<Options>;
|
|
18
|
+
};
|
|
19
|
+
export type PluginInstallContext<Options = any> = {
|
|
20
|
+
/**
|
|
21
|
+
* The name property overwrites the name defined by the plugin.
|
|
22
|
+
*/
|
|
23
|
+
name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* By specifying a path, the plugin will be installed as a child router.
|
|
26
|
+
*/
|
|
27
|
+
path?: Path;
|
|
28
|
+
/**
|
|
29
|
+
* Pass options to the plugin installation routine.
|
|
30
|
+
*/
|
|
31
|
+
options: Options;
|
|
32
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function useRequestBody(req: Request): Record<string, any>;
|
|
3
3
|
export declare function useRequestBody(req: Request, key: string): any | undefined;
|
|
4
4
|
export declare function hasRequestBody(req: Request): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function isRequestCacheable(req: Request, modifiedTime: string | Date): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function useRequestCookies(req: Request): Record<string, string>;
|
|
3
3
|
export declare function hasRequestCookies(req: Request): boolean;
|
|
4
4
|
export declare function useRequestCookie(req: Request, name: string): string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function setRequestEnv(req: Request, key: string, value: unknown): void;
|
|
3
3
|
export declare function setRequestEnv(req: Request, record: Record<string, any>, append?: boolean): void;
|
|
4
4
|
export declare function useRequestEnv(req: Request): Record<string, any>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function getRequestAcceptableCharsets(req: Request): string[];
|
|
3
3
|
export declare function getRequestAcceptableCharset(req: Request, input: string | string[]): string | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function getRequestAcceptableLanguages(req: Request): string[];
|
|
3
3
|
export declare function getRequestAcceptableLanguage(req: Request, input?: string | string[]): string | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function getRequestAcceptableContentTypes(req: Request): string[];
|
|
3
3
|
export declare function getRequestAcceptableContentType(req: Request, input?: string | string[]): string | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function matchRequestContentType(req: Request, contentType: string): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
|
-
import type { Request } from '
|
|
3
|
+
import type { Request } from '../types';
|
|
4
4
|
export declare function getRequestHeader<K extends keyof IncomingHttpHeaders>(req: Request, name: K): IncomingHttpHeaders[K];
|
|
5
5
|
export declare function setRequestHeader<K extends keyof IncomingHttpHeaders>(req: Request, name: K, value: IncomingHttpHeaders[K]): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function useRequestParams(req: Request): Record<string, any>;
|
|
3
3
|
export declare function useRequestParam(req: Request, key: string): any;
|
|
4
4
|
export declare function setRequestParams(req: Request, data: Record<string, any>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function useRequestPath(req: Request): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request } from '
|
|
1
|
+
import type { Request } from '../types';
|
|
2
2
|
export declare function useRequestQuery(req: Request): Record<string, any>;
|
|
3
3
|
export declare function useRequestQuery(req: Request, key: string): any;
|
|
4
4
|
export declare function hasRequestQuery(req: Request): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import type { NodeReadableStream, WebReadableStream } from '../types';
|
|
4
|
+
export type RequestBody = null | Iterable<any> | AsyncIterable<any> | NodeReadableStream | WebReadableStream;
|
|
5
|
+
export type RequestHeaders = Record<string, string | string[]>;
|
|
6
|
+
export type RequestCreateContext = {
|
|
7
|
+
body?: RequestBody;
|
|
8
|
+
headers?: RequestHeaders;
|
|
9
|
+
method?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface Request extends IncomingMessage {
|
|
13
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Response } from '
|
|
1
|
+
import type { Response } from '../types';
|
|
2
2
|
export declare function setResponseHeaderAttachment(res: Response, filename?: string): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Response } from '
|
|
1
|
+
import type { Response } from '../types';
|
|
2
2
|
export declare function setResponseHeaderContentType(res: Response, input: string, ifNotExists?: boolean): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { OutgoingHttpHeader } from 'node:http';
|
|
3
|
-
import type { Response } from '
|
|
3
|
+
import type { Response } from '../types';
|
|
4
4
|
export declare function appendResponseHeader(res: Response, name: string, value: OutgoingHttpHeader): void;
|
|
5
5
|
export declare function appendResponseHeaderDirective(res: Response, name: string, value: OutgoingHttpHeader): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './cache';
|
|
2
|
+
export * from './gone';
|
|
2
3
|
export * from './header';
|
|
3
4
|
export * from './header-attachment';
|
|
4
5
|
export * from './header-content-type';
|
|
@@ -9,4 +10,6 @@ export * from './send-file';
|
|
|
9
10
|
export * from './send-format';
|
|
10
11
|
export * from './send-redirect';
|
|
11
12
|
export * from './send-stream';
|
|
13
|
+
export * from './send-web-response';
|
|
14
|
+
export * from './send-web-blob';
|
|
12
15
|
export * from './utils';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Response } from '
|
|
2
|
-
export declare function sendAccepted(res: Response, chunk?: any): void
|
|
1
|
+
import type { Response } from '../types';
|
|
2
|
+
export declare function sendAccepted(res: Response, chunk?: any): Promise<void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Response } from '
|
|
2
|
-
export declare function sendCreated(res: Response, chunk?: any): void
|
|
1
|
+
import type { Response } from '../types';
|
|
2
|
+
export declare function sendCreated(res: Response, chunk?: any): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Response } from '../types';
|
|
2
|
+
export type SendFileContentOptions = {
|
|
3
|
+
end?: number;
|
|
4
|
+
start?: number;
|
|
5
|
+
};
|
|
6
|
+
export type SendFileStats = {
|
|
7
|
+
size?: number;
|
|
8
|
+
mtime?: Date | number | string;
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
11
|
+
export type SendFileOptions = {
|
|
12
|
+
stats: () => Promise<SendFileStats> | SendFileStats;
|
|
13
|
+
content: (options: SendFileContentOptions) => Promise<unknown> | unknown;
|
|
14
|
+
attachment?: boolean;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function sendFile(res: Response, options: SendFileOptions, next?: (err?: Error) => Promise<unknown> | unknown): Promise<unknown>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NodeReadableStream, WebReadableStream } from '../../types';
|
|
2
|
+
import type { Response } from '../types';
|
|
3
|
+
export declare function sendStream(res: Response, stream: NodeReadableStream | WebReadableStream, next?: (err?: Error) => Promise<unknown> | unknown): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RouterSymbol: unique symbol;
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './module';
|
|
2
|
-
export
|
|
2
|
+
export { isRouterInstance } from './utils';
|
package/dist/router/module.d.ts
CHANGED
|
@@ -1,70 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type { DispatcherMeta, ErrorHandler, Handler, Next, Path, Request, Response } from '../type';
|
|
4
|
-
import type { PathMatcherOptions } from '../path';
|
|
5
|
-
import { PathMatcher } from '../path';
|
|
1
|
+
import type { Dispatcher, DispatcherEvent, DispatcherMeta } from '../dispatcher';
|
|
2
|
+
import type { Handler } from '../handler';
|
|
6
3
|
import { Layer } from '../layer';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import type { Path } from '../path';
|
|
5
|
+
import { PathMatcher } from '../path';
|
|
6
|
+
import type { RouterOptionsInput } from '../router-options';
|
|
7
|
+
import type { Plugin, PluginInstallContext, PluginOptions } from '../plugin';
|
|
8
|
+
export declare class Router implements Dispatcher {
|
|
11
9
|
readonly '@instanceof': symbol;
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @protected
|
|
16
|
-
*/
|
|
17
|
-
protected stack: (Router | Route | Layer)[];
|
|
18
|
-
/**
|
|
19
|
-
* Mount path of instance
|
|
20
|
-
*
|
|
21
|
-
* @protected
|
|
22
|
-
*/
|
|
23
|
-
protected path: Path | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Path matcher for the current mount path.
|
|
26
|
-
*
|
|
27
|
-
* @protected
|
|
11
|
+
* An identifier for the router instance.
|
|
28
12
|
*/
|
|
29
|
-
|
|
13
|
+
readonly id: number;
|
|
30
14
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @protected
|
|
15
|
+
* A label for the router instance.
|
|
34
16
|
*/
|
|
35
|
-
|
|
17
|
+
readonly name?: string;
|
|
36
18
|
/**
|
|
37
|
-
*
|
|
19
|
+
* Array of mounted layers, routes & routers.
|
|
38
20
|
*
|
|
39
21
|
* @protected
|
|
40
22
|
*/
|
|
41
|
-
protected
|
|
23
|
+
protected stack: (Router | Layer)[];
|
|
42
24
|
/**
|
|
43
|
-
*
|
|
25
|
+
* Path matcher for the current mount path.
|
|
44
26
|
*
|
|
45
27
|
* @protected
|
|
46
28
|
*/
|
|
47
|
-
protected
|
|
48
|
-
constructor(
|
|
49
|
-
|
|
50
|
-
setPath(value: Path): void;
|
|
51
|
-
createListener(): RequestListener;
|
|
52
|
-
listen(port: number): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
29
|
+
protected pathMatcher: PathMatcher | undefined;
|
|
30
|
+
constructor(options?: RouterOptionsInput);
|
|
31
|
+
setPath(value?: Path): void;
|
|
53
32
|
matchPath(path: string): boolean;
|
|
54
|
-
dispatch(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
get(path: Path,
|
|
59
|
-
post(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
33
|
+
dispatch(event: DispatcherEvent, meta: DispatcherMeta): Promise<boolean>;
|
|
34
|
+
delete(handler: Handler): this;
|
|
35
|
+
delete(path: Path, handler: Handler): this;
|
|
36
|
+
get(handler: Handler): this;
|
|
37
|
+
get(path: Path, handler: Handler): this;
|
|
38
|
+
post(handler: Handler): this;
|
|
39
|
+
post(path: Path, handler: Handler): this;
|
|
40
|
+
put(handler: Handler): this;
|
|
41
|
+
put(path: Path, handler: Handler): this;
|
|
42
|
+
patch(handler: Handler): this;
|
|
43
|
+
patch(path: Path, handler: Handler): this;
|
|
44
|
+
head(handler: Handler): this;
|
|
45
|
+
head(path: Path, handler: Handler): this;
|
|
46
|
+
options(handler: Handler): this;
|
|
47
|
+
options(path: Path, handler: Handler): this;
|
|
64
48
|
use(router: Router): this;
|
|
65
49
|
use(handler: Handler): this;
|
|
66
|
-
use(handler: ErrorHandler): this;
|
|
67
50
|
use(path: Path, router: Router): this;
|
|
68
51
|
use(path: Path, handler: Handler): this;
|
|
69
|
-
|
|
52
|
+
install<Options extends PluginOptions = PluginOptions>(plugin: Plugin<Options>, context: PluginInstallContext<Options> | Options): this;
|
|
53
|
+
uninstall(name: string): void;
|
|
70
54
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RouterOptions } from './type';
|
|
2
|
+
export declare function setRouterOptions(id: number, input: Partial<RouterOptions>): void;
|
|
3
|
+
export declare function unsetRouterOptions(id: number): void;
|
|
4
|
+
export declare function findRouterOption<K extends keyof RouterOptions>(key: K, path?: number[]): RouterOptions[K];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Path } from '../path';
|
|
2
|
+
import type { EtagFn, EtagInput, TrustProxyFn, TrustProxyInput } from '../utils';
|
|
3
|
+
export type RouterOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The path the router is mounted on.
|
|
6
|
+
*
|
|
7
|
+
* @type string
|
|
8
|
+
* @default '/'
|
|
9
|
+
*/
|
|
10
|
+
path?: Path;
|
|
11
|
+
/**
|
|
12
|
+
* Name of the router.
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* default: 2
|
|
17
|
+
*/
|
|
18
|
+
subdomainOffset: number;
|
|
19
|
+
/**
|
|
20
|
+
* default: 0
|
|
21
|
+
*/
|
|
22
|
+
proxyIpMax: number;
|
|
23
|
+
/**
|
|
24
|
+
* default: () => true
|
|
25
|
+
*/
|
|
26
|
+
etag: EtagFn;
|
|
27
|
+
/**
|
|
28
|
+
* default: () => false
|
|
29
|
+
*/
|
|
30
|
+
trustProxy: TrustProxyFn;
|
|
31
|
+
};
|
|
32
|
+
export type RouterOptionsInput = Omit<Partial<RouterOptions>, 'etag' | 'trustProxy'> & {
|
|
33
|
+
/**
|
|
34
|
+
* default: true
|
|
35
|
+
*/
|
|
36
|
+
etag?: EtagInput;
|
|
37
|
+
/**
|
|
38
|
+
* default: false
|
|
39
|
+
*/
|
|
40
|
+
trustProxy?: TrustProxyInput;
|
|
41
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Readable as NodeReadable } from 'node:stream';
|
|
4
|
+
import type { Readable } from 'readable-stream';
|
|
5
|
+
import type { ReadableStream } from 'stream/web';
|
|
6
|
+
export type NodeReadableStream = NodeReadable | Readable;
|
|
7
|
+
export type WebReadableStream = globalThis.ReadableStream | ReadableStream;
|
|
8
|
+
export type WebResponse = globalThis.Response;
|
|
9
|
+
export type WebRequest = globalThis.Request;
|
|
10
|
+
export type WebBlob = globalThis.Blob;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function splitCookiesString(input?: string | string[]): string[];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { type Stats } from 'node:fs';
|
|
4
5
|
import type { EtagOptions } from './type';
|
|
5
6
|
/**
|
|
6
7
|
* Generate an ETag.
|
|
7
8
|
*/
|
|
8
|
-
export declare function generateETag(input: string | Buffer | Stats): string
|
|
9
|
+
export declare function generateETag(input: string | Buffer | Stats): Promise<string>;
|
|
9
10
|
/**
|
|
10
11
|
* Create a simple ETag.
|
|
11
12
|
*/
|
|
12
|
-
export declare function createEtag(input: string | Buffer | Stats, options?: EtagOptions): string
|
|
13
|
+
export declare function createEtag(input: string | Buffer | Stats, options?: EtagOptions): Promise<string>;
|