routup 1.0.2 → 2.0.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.
Files changed (100) hide show
  1. package/README.md +92 -8
  2. package/dist/dispatcher/adapters/index.d.ts +3 -0
  3. package/dist/dispatcher/adapters/node/index.d.ts +1 -0
  4. package/dist/dispatcher/adapters/node/module.d.ts +6 -0
  5. package/dist/dispatcher/adapters/raw/module.d.ts +4 -0
  6. package/dist/dispatcher/adapters/raw/type.d.ts +18 -0
  7. package/dist/dispatcher/adapters/web/index.d.ts +2 -0
  8. package/dist/dispatcher/adapters/web/module.d.ts +5 -0
  9. package/dist/dispatcher/adapters/web/type.d.ts +3 -0
  10. package/dist/dispatcher/index.d.ts +3 -0
  11. package/dist/dispatcher/type.d.ts +30 -0
  12. package/dist/dispatcher/utils.d.ts +4 -0
  13. package/dist/error.d.ts +1 -0
  14. package/dist/index.cjs +1075 -538
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.mjs +1054 -509
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/layer/module.d.ts +5 -4
  20. package/dist/layer/type.d.ts +1 -2
  21. package/dist/layer/utils.d.ts +1 -1
  22. package/dist/path/index.d.ts +1 -0
  23. package/dist/path/matcher.d.ts +1 -2
  24. package/dist/path/type.d.ts +1 -0
  25. package/dist/path/utils.d.ts +2 -0
  26. package/dist/{helpers/request → request/helpers}/body.d.ts +1 -1
  27. package/dist/{helpers/request → request/helpers}/cache.d.ts +1 -1
  28. package/dist/{helpers/request → request/helpers}/cookie.d.ts +1 -1
  29. package/dist/{helpers/request → request/helpers}/env.d.ts +1 -1
  30. package/dist/{helpers/request → request/helpers}/header-accept-charset.d.ts +1 -1
  31. package/dist/{helpers/request → request/helpers}/header-accept-language.d.ts +1 -1
  32. package/dist/{helpers/request → request/helpers}/header-accept.d.ts +1 -1
  33. package/dist/{helpers/request → request/helpers}/header-content-type.d.ts +1 -1
  34. package/dist/{helpers/request → request/helpers}/header.d.ts +1 -1
  35. package/dist/{helpers/request → request/helpers}/hostname.d.ts +1 -1
  36. package/dist/{helpers/request → request/helpers}/index.d.ts +1 -0
  37. package/dist/{helpers/request → request/helpers}/ip.d.ts +1 -1
  38. package/dist/{helpers/request → request/helpers}/mount-path.d.ts +1 -1
  39. package/dist/{helpers/request → request/helpers}/negotiator.d.ts +1 -1
  40. package/dist/{helpers/request → request/helpers}/params.d.ts +1 -1
  41. package/dist/{helpers/request → request/helpers}/path.d.ts +1 -1
  42. package/dist/{helpers/request → request/helpers}/protocol.d.ts +1 -1
  43. package/dist/{helpers/request → request/helpers}/query.d.ts +1 -1
  44. package/dist/request/helpers/router.d.ts +3 -0
  45. package/dist/request/index.d.ts +3 -0
  46. package/dist/request/module.d.ts +4 -0
  47. package/dist/request/types.d.ts +9 -0
  48. package/dist/{helpers/response → response/helpers}/cache.d.ts +1 -1
  49. package/dist/response/helpers/gone.d.ts +2 -0
  50. package/dist/{helpers/response → response/helpers}/header-attachment.d.ts +1 -1
  51. package/dist/{helpers/response → response/helpers}/header-content-type.d.ts +1 -1
  52. package/dist/{helpers/response → response/helpers}/header.d.ts +1 -1
  53. package/dist/{helpers/response → response/helpers}/index.d.ts +3 -0
  54. package/dist/{helpers/response → response/helpers}/send-accepted.d.ts +2 -2
  55. package/dist/{helpers/response → response/helpers}/send-created.d.ts +2 -2
  56. package/dist/response/helpers/send-file.d.ts +17 -0
  57. package/dist/{helpers/response → response/helpers}/send-format.d.ts +1 -1
  58. package/dist/response/helpers/send-redirect.d.ts +2 -0
  59. package/dist/response/helpers/send-stream.d.ts +2 -0
  60. package/dist/response/helpers/send-web-blob.d.ts +2 -0
  61. package/dist/response/helpers/send-web-response.d.ts +2 -0
  62. package/dist/response/helpers/send.d.ts +2 -0
  63. package/dist/response/helpers/utils.d.ts +2 -0
  64. package/dist/response/index.d.ts +2 -0
  65. package/dist/response/module.d.ts +2 -0
  66. package/dist/route/module.d.ts +6 -5
  67. package/dist/route/type.d.ts +1 -1
  68. package/dist/route/utils.d.ts +1 -1
  69. package/dist/router/index.d.ts +0 -1
  70. package/dist/router/module.d.ts +13 -32
  71. package/dist/router/utils.d.ts +1 -0
  72. package/dist/router-options/index.d.ts +2 -0
  73. package/dist/router-options/module.d.ts +4 -0
  74. package/dist/router-options/transform.d.ts +2 -0
  75. package/dist/router-options/type.d.ts +50 -0
  76. package/dist/types.d.ts +19 -0
  77. package/dist/utils/cookie.d.ts +1 -0
  78. package/dist/utils/etag/module.d.ts +4 -3
  79. package/dist/utils/etag/type.d.ts +1 -1
  80. package/dist/utils/header.d.ts +3 -0
  81. package/dist/utils/index.d.ts +4 -1
  82. package/dist/utils/path.d.ts +5 -2
  83. package/dist/utils/stream.d.ts +8 -0
  84. package/dist/utils/web.d.ts +3 -0
  85. package/package.json +17 -16
  86. package/dist/config/module.d.ts +0 -8
  87. package/dist/config/type.d.ts +0 -34
  88. package/dist/handler/index.d.ts +0 -1
  89. package/dist/handler/utils.d.ts +0 -2
  90. package/dist/helpers/index.d.ts +0 -2
  91. package/dist/helpers/response/send-file.d.ts +0 -9
  92. package/dist/helpers/response/send-redirect.d.ts +0 -2
  93. package/dist/helpers/response/send-stream.d.ts +0 -4
  94. package/dist/helpers/response/send.d.ts +0 -2
  95. package/dist/helpers/response/utils.d.ts +0 -3
  96. package/dist/router/type.d.ts +0 -24
  97. package/dist/type.d.ts +0 -24
  98. package/dist/utils/request.d.ts +0 -2
  99. /package/dist/{config → dispatcher/adapters/raw}/index.d.ts +0 -0
  100. /package/dist/{helpers/request → request/helpers}/header-accept-encoding.d.ts +0 -0
@@ -1,14 +1,15 @@
1
- import type { DispatcherMeta, Request, Response } from '../type';
1
+ import type { Dispatcher, DispatcherEvent, DispatcherMeta } from '../dispatcher';
2
2
  import { PathMatcher } from '../path';
3
+ import type { Response } from '../types';
3
4
  import type { LayerOptions } from './type';
4
- export declare class Layer {
5
+ export declare class Layer implements Dispatcher {
5
6
  readonly '@instanceof': symbol;
6
7
  protected fn: CallableFunction;
7
8
  protected pathMatcher: PathMatcher;
8
9
  constructor(options: LayerOptions, fn: CallableFunction);
9
10
  isError(): boolean;
10
- dispatch(req: Request, res: Response, meta: DispatcherMeta, next: CallableFunction): void;
11
- dispatch(req: Request, res: Response, meta: DispatcherMeta, next: CallableFunction, err: Error): void;
11
+ dispatch(event: DispatcherEvent, meta: DispatcherMeta): Promise<boolean>;
12
+ protected sendOutput(res: Response, input: unknown): Promise<any>;
12
13
  matchPath(path: string): boolean;
13
14
  exec(path: string): import("../path").PathMatcherExecResult | undefined;
14
15
  }
@@ -1,5 +1,4 @@
1
- import type { PathMatcherOptions } from '../path';
2
- import type { Path } from '../type';
1
+ import type { Path, PathMatcherOptions } from '../path';
3
2
  export type LayerOptions = {
4
3
  path: Path;
5
4
  pathMatcher: PathMatcherOptions;
@@ -1,2 +1,2 @@
1
- import type { Layer } from './module';
1
+ import { Layer } from './module';
2
2
  export declare function isLayerInstance(input: unknown): input is Layer;
@@ -1,2 +1,3 @@
1
1
  export * from './matcher';
2
2
  export * from './type';
3
+ export * from './utils';
@@ -1,6 +1,5 @@
1
1
  import type { Key } from 'path-to-regexp';
2
- import type { Path } from '../type';
3
- import type { PathMatcherExecResult, PathMatcherOptions } from './type';
2
+ import type { Path, PathMatcherExecResult, PathMatcherOptions } from './type';
4
3
  export declare class PathMatcher {
5
4
  path: Path;
6
5
  regexp: RegExp;
@@ -4,3 +4,4 @@ export type PathMatcherExecResult = {
4
4
  path: string;
5
5
  params: Record<string, any>;
6
6
  };
7
+ export type Path = string | RegExp;
@@ -0,0 +1,2 @@
1
+ import type { Path } from './type';
2
+ export declare function isPath(input: unknown): input is Path;
@@ -1,4 +1,4 @@
1
- import type { Request } from '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
1
+ import type { Request } from '../../types';
2
2
  import type { TrustProxyInput } from '../../utils';
3
3
  type RequestHostNameOptions = {
4
4
  trustProxy?: TrustProxyInput;
@@ -16,3 +16,4 @@ export * from './params';
16
16
  export * from './path';
17
17
  export * from './protocol';
18
18
  export * from './query';
19
+ export * from './router';
@@ -1,4 +1,4 @@
1
- import type { Request } from '../../type';
1
+ import type { Request } from '../../types';
2
2
  import type { TrustProxyInput } from '../../utils';
3
3
  type RequestIpOptions = {
4
4
  trustProxy?: TrustProxyInput;
@@ -1,3 +1,3 @@
1
- import type { Request } from '../../type';
1
+ import type { Request } from '../../types';
2
2
  export declare function useRequestMountPath(req: Request): string;
3
3
  export declare function setRequestMountPath(req: Request, basePath: string): void;
@@ -1,3 +1,3 @@
1
1
  import Negotiator from 'negotiator';
2
- import type { Request } from '../../type';
2
+ import type { Request } from '../../types';
3
3
  export declare function useRequestNegotiator(req: Request): Negotiator;
@@ -1,4 +1,4 @@
1
- import type { Request } from '../../type';
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 '../../type';
1
+ import type { Request } from '../../types';
2
2
  export declare function useRequestPath(req: Request): string;
@@ -1,4 +1,4 @@
1
- import type { Request } from '../../type';
1
+ import type { Request } from '../../types';
2
2
  import type { TrustProxyInput } from '../../utils';
3
3
  type RequestProtocolOptions = {
4
4
  trustProxy?: TrustProxyInput;
@@ -1,4 +1,4 @@
1
- import type { Request } from '../../type';
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,3 @@
1
+ import type { Request } from '../../types';
2
+ export declare function setRequestRouterIds(req: Request, ids: number[]): void;
3
+ export declare function useRequestRouterIds(req: Request): number[] | undefined;
@@ -0,0 +1,3 @@
1
+ export * from './helpers';
2
+ export * from './module';
3
+ export * from './types';
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage } from 'node:http';
3
+ import type { RequestCreateContext } from './types';
4
+ export declare function createRequest(context: RequestCreateContext): IncomingMessage;
@@ -0,0 +1,9 @@
1
+ import type { NodeReadableStream, WebReadableStream } from '../types';
2
+ export type RequestBody = null | Iterable<any> | AsyncIterable<any> | NodeReadableStream | WebReadableStream;
3
+ export type RequestHeaders = Record<string, string | string[]>;
4
+ export type RequestCreateContext = {
5
+ body?: RequestBody;
6
+ headers?: RequestHeaders;
7
+ method?: string;
8
+ url?: string;
9
+ };
@@ -1,4 +1,4 @@
1
- import type { Response } from '../../type';
1
+ import type { Response } from '../../types';
2
2
  export type ResponseCacheHeadersOptions = {
3
3
  maxAge?: number;
4
4
  modifiedTime?: string | Date;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../types';
2
+ export declare function isResponseGone(res: Response): any;
@@ -1,2 +1,2 @@
1
- import type { Response } from '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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 '../../type';
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>;
@@ -1,4 +1,4 @@
1
- import type { Response } from '../../type';
1
+ import type { Response } from '../../types';
2
2
  type ResponseFormats = {
3
3
  default: () => void;
4
4
  [key: string]: () => void;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../types';
2
+ export declare function sendRedirect(res: Response, location: string, statusCode?: number): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { NodeReadableStream, Response, WebReadableStream } from '../../types';
2
+ export declare function sendStream(res: Response, stream: NodeReadableStream | WebReadableStream, next?: (err?: Error) => Promise<unknown> | unknown): Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ import type { Response, WebBlob } from '../../types';
2
+ export declare function sendWebBlob(res: Response, blob: WebBlob): Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ import type { Response, WebResponse } from '../../types';
2
+ export declare function sendWebResponse(res: Response, webResponse: WebResponse): Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../types';
2
+ export declare function send(res: Response, chunk?: any): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { Response } from '../../types';
2
+ export declare function setResponseContentTypeByFileName(res: Response, fileName: string): void;
@@ -0,0 +1,2 @@
1
+ export * from './helpers';
2
+ export * from './module';
@@ -0,0 +1,2 @@
1
+ import type { Request, Response } from '../types';
2
+ export declare function createResponse(request: Request): Response;
@@ -1,12 +1,13 @@
1
1
  import { MethodName } from '../constants';
2
- import type { DispatcherMeta, Handler, Next, Path, Request, Response } from '../type';
2
+ import type { Dispatcher, DispatcherEvent, DispatcherMeta } from '../dispatcher';
3
3
  import { Layer } from '../layer';
4
- import type { PathMatcherOptions } from '../path';
4
+ import type { Path, PathMatcherOptions } from '../path';
5
5
  import { PathMatcher } from '../path';
6
+ import type { Handler } from '../types';
6
7
  import type { RouteOptions } from './type';
7
- export declare class Route {
8
+ export declare class Route implements Dispatcher {
8
9
  readonly '@instanceof': symbol;
9
- path: Path;
10
+ readonly path: Path;
10
11
  protected pathMatcher: PathMatcher;
11
12
  protected pathMatcherOptions: PathMatcherOptions;
12
13
  protected layers: Record<string, Layer[]>;
@@ -14,7 +15,7 @@ export declare class Route {
14
15
  matchPath(path: string): boolean;
15
16
  matchMethod(method: string): boolean;
16
17
  getMethods(): string[];
17
- dispatch(req: Request, res: Response, meta: DispatcherMeta, done: Next): void;
18
+ dispatch(event: DispatcherEvent, meta: DispatcherMeta): Promise<boolean>;
18
19
  register(method: `${MethodName}`, ...handlers: Handler[]): void;
19
20
  get(...handlers: Handler[]): void;
20
21
  post(...handlers: Handler[]): void;
@@ -1,5 +1,5 @@
1
1
  import type { ParseOptions, TokensToRegexpOptions } from 'path-to-regexp';
2
- import type { Path } from '../type';
2
+ import type { Path } from '../path';
3
3
  export type RouteOptions = {
4
4
  path: Path;
5
5
  pathMatcher: TokensToRegexpOptions & ParseOptions;
@@ -1,2 +1,2 @@
1
- import type { Route } from './module';
1
+ import { Route } from './module';
2
2
  export declare function isRouteInstance(input: unknown): input is Route;
@@ -1,2 +1 @@
1
1
  export * from './module';
2
- export * from './type';
@@ -1,26 +1,23 @@
1
- /// <reference types="node" />
2
- import type { RequestListener } from 'node:http';
3
- import type { DispatcherMeta, ErrorHandler, Handler, Next, Path, Request, Response } from '../type';
4
- import type { PathMatcherOptions } from '../path';
1
+ import type { Dispatcher, DispatcherEvent, DispatcherMeta } from '../dispatcher';
2
+ import type { ErrorHandler, Handler } from '../types';
3
+ import type { Path, PathMatcherOptions } from '../path';
5
4
  import { PathMatcher } from '../path';
6
5
  import { Layer } from '../layer';
7
6
  import { Route } from '../route';
8
- import type { RouterOptions } from './type';
7
+ import type { RouterOptionsInput } from '../router-options';
9
8
  export declare function isRouterInstance(input: unknown): input is Router;
10
- export declare class Router {
9
+ export declare class Router implements Dispatcher {
11
10
  readonly '@instanceof': symbol;
12
11
  /**
13
- * Array of mounted layers, routes & routers.
14
- *
15
- * @protected
12
+ * An identifier for the router instance.
16
13
  */
17
- protected stack: (Router | Route | Layer)[];
14
+ readonly id: number;
18
15
  /**
19
- * Mount path of instance
16
+ * Array of mounted layers, routes & routers.
20
17
  *
21
18
  * @protected
22
19
  */
23
- protected path: Path | undefined;
20
+ protected stack: (Router | Route | Layer)[];
24
21
  /**
25
22
  * Path matcher for the current mount path.
26
23
  *
@@ -32,27 +29,11 @@ export declare class Router {
32
29
  *
33
30
  * @protected
34
31
  */
35
- protected pathMatcherOptions: PathMatcherOptions;
36
- /**
37
- * Is this the root instance?
38
- *
39
- * @protected
40
- */
41
- protected isRoot: boolean | undefined;
42
- /**
43
- * Timeout before the router decides to abort the request.
44
- *
45
- * @protected
46
- */
47
- protected timeout: number | undefined;
48
- constructor(ctx?: RouterOptions);
49
- setPathMatcherOptions(input: PathMatcherOptions): void;
50
- setPath(value: Path): void;
51
- createListener(): RequestListener;
52
- listen(port: number): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
32
+ protected pathMatcherOptions: PathMatcherOptions | undefined;
33
+ constructor(options?: RouterOptionsInput);
34
+ setPath(value?: Path): void;
53
35
  matchPath(path: string): boolean;
54
- dispatch(req: Request, res: Response, meta?: DispatcherMeta, done?: Next): void;
55
- dispatchAsync(req: Request, res: Response): Promise<void>;
36
+ dispatch(event: DispatcherEvent, meta?: DispatcherMeta): Promise<boolean>;
56
37
  route(path: Path): Route;
57
38
  delete(path: Path, ...handlers: Handler[]): this;
58
39
  get(path: Path, ...handlers: Handler[]): this;
@@ -0,0 +1 @@
1
+ export declare function generateRouterID(): number;
@@ -0,0 +1,2 @@
1
+ export * from './module';
2
+ export * from './type';
@@ -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, id?: number | number[]): RouterOptions[K];
@@ -0,0 +1,2 @@
1
+ import type { RouterOptions, RouterOptionsInput } from './type';
2
+ export declare function transformRouterOptions(input: RouterOptionsInput): Partial<RouterOptions>;
@@ -0,0 +1,50 @@
1
+ import type { Path, PathMatcherOptions } 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
+ * Path matcher options.
13
+ *
14
+ * @default: {end: false}
15
+ */
16
+ pathMatcher?: PathMatcherOptions;
17
+ /**
18
+ * Milliseconds (ms) until a request handler execution should be canceled.
19
+ *
20
+ * @type number
21
+ * @default undefined
22
+ */
23
+ timeout?: number;
24
+ /**
25
+ * default: 2
26
+ */
27
+ subdomainOffset: number;
28
+ /**
29
+ * default: 0
30
+ */
31
+ proxyIpMax: number;
32
+ /**
33
+ * default: () => true
34
+ */
35
+ etag: EtagFn;
36
+ /**
37
+ * default: () => false
38
+ */
39
+ trustProxy: TrustProxyFn;
40
+ };
41
+ export type RouterOptionsInput = Omit<Partial<RouterOptions>, 'etag' | 'trustProxy'> & {
42
+ /**
43
+ * default: true
44
+ */
45
+ etag?: EtagInput;
46
+ /**
47
+ * default: false
48
+ */
49
+ trustProxy?: TrustProxyInput;
50
+ };
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { IncomingMessage, ServerResponse } from 'node:http';
5
+ import type { Readable as NodeReadable } from 'node:stream';
6
+ import type { Readable } from 'readable-stream';
7
+ import type { ReadableStream } from 'stream/web';
8
+ export type NodeReadableStream = NodeReadable | Readable;
9
+ export type WebReadableStream = globalThis.ReadableStream | ReadableStream;
10
+ export type WebResponse = globalThis.Response;
11
+ export type WebRequest = globalThis.Request;
12
+ export type WebBlob = globalThis.Blob;
13
+ export interface Response extends ServerResponse {
14
+ }
15
+ export interface Request extends IncomingMessage {
16
+ }
17
+ export type Next = (err?: Error) => void;
18
+ export type Handler = (req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
19
+ export type ErrorHandler = (err: Error, req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
@@ -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 { Stats } from 'node:fs';
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>;
@@ -12,5 +12,5 @@ export type EtagOptions = {
12
12
  */
13
13
  threshold?: number;
14
14
  };
15
- export type EtagFn = (body: any, encoding?: BufferEncoding, size?: number) => string | undefined;
15
+ export type EtagFn = (body: any, encoding?: BufferEncoding, size?: number) => Promise<string | undefined>;
16
16
  export type EtagInput = boolean | EtagOptions | EtagFn;
@@ -0,0 +1,3 @@
1
+ import type { RawResponseHeader } from '../dispatcher';
2
+ export declare function transformHeaderToTuples(key: string, value: RawResponseHeader): [string, string][];
3
+ export declare function transformHeadersToTuples(input: Record<string, RawResponseHeader>): [string, string][];
@@ -1,3 +1,5 @@
1
+ export * from './cookie';
2
+ export * from './header';
1
3
  export * from './etag';
2
4
  export * from './trust-proxy';
3
5
  export * from './is-instance';
@@ -5,5 +7,6 @@ export * from './mime';
5
7
  export * from './object';
6
8
  export * from './path';
7
9
  export * from './promise';
8
- export * from './request';
10
+ export * from './stream';
9
11
  export * from './url';
12
+ export * from './web';
@@ -1,2 +1,5 @@
1
- import type { Path } from '../type';
2
- export declare function isPath(input: unknown): input is Path;
1
+ /**
2
+ * Based on https://github.com/unjs/pathe v1.1.1 (055f50a6f1131f4e5c56cf259dd8816168fba329)
3
+ */
4
+ export declare function extname(input: string): string;
5
+ export declare function basename(input: string, extension?: string): string;
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { ReadableStream as WebReadableStream } from 'stream/web';
4
+ import type { Readable as NodeReadable } from 'node:stream';
5
+ import type { Readable } from 'readable-stream';
6
+ export declare function isNodeStream(input: unknown): input is NodeReadable | Readable;
7
+ export declare function isWebStream(input: unknown): input is ReadableStream | WebReadableStream;
8
+ export declare function isStream(data: any): data is NodeReadable | Readable | ReadableStream | WebReadableStream;
@@ -0,0 +1,3 @@
1
+ import type { WebBlob, WebResponse } from '../types';
2
+ export declare function isWebBlob(input: unknown): input is WebBlob;
3
+ export declare function isWebResponse(input: unknown): input is WebResponse;