routup 4.0.2 → 5.0.0-beta.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 (169) hide show
  1. package/README.md +87 -134
  2. package/dist/bun.cjs +66 -0
  3. package/dist/bun.cjs.map +1 -0
  4. package/dist/bun.d.cts +8 -0
  5. package/dist/bun.d.mts +8 -0
  6. package/dist/bun.mjs +13 -0
  7. package/dist/bun.mjs.map +1 -0
  8. package/dist/cloudflare.cjs +66 -0
  9. package/dist/cloudflare.cjs.map +1 -0
  10. package/dist/cloudflare.d.cts +8 -0
  11. package/dist/cloudflare.d.mts +8 -0
  12. package/dist/cloudflare.mjs +13 -0
  13. package/dist/cloudflare.mjs.map +1 -0
  14. package/dist/deno.cjs +66 -0
  15. package/dist/deno.cjs.map +1 -0
  16. package/dist/deno.d.cts +8 -0
  17. package/dist/deno.d.mts +8 -0
  18. package/dist/deno.mjs +13 -0
  19. package/dist/deno.mjs.map +1 -0
  20. package/dist/generic.cjs +66 -0
  21. package/dist/generic.cjs.map +1 -0
  22. package/dist/generic.d.cts +8 -0
  23. package/dist/generic.d.mts +8 -0
  24. package/dist/generic.mjs +13 -0
  25. package/dist/generic.mjs.map +1 -0
  26. package/dist/index-9K5FcIb3.d.cts +786 -0
  27. package/dist/index-B6F5CzQy.d.mts +786 -0
  28. package/dist/node.cjs +70 -0
  29. package/dist/node.cjs.map +1 -0
  30. package/dist/node.d.cts +11 -0
  31. package/dist/node.d.mts +11 -0
  32. package/dist/node.mjs +16 -0
  33. package/dist/node.mjs.map +1 -0
  34. package/dist/service-worker.cjs +66 -0
  35. package/dist/service-worker.cjs.map +1 -0
  36. package/dist/service-worker.d.cts +10 -0
  37. package/dist/service-worker.d.mts +10 -0
  38. package/dist/service-worker.mjs +13 -0
  39. package/dist/service-worker.mjs.map +1 -0
  40. package/dist/src-C789deGE.mjs +1599 -0
  41. package/dist/src-C789deGE.mjs.map +1 -0
  42. package/dist/src-Ca2_b8P0.cjs +1939 -0
  43. package/dist/src-Ca2_b8P0.cjs.map +1 -0
  44. package/package.json +76 -36
  45. package/dist/adapters/index.d.ts +0 -3
  46. package/dist/adapters/node/index.d.ts +0 -1
  47. package/dist/adapters/node/module.d.ts +0 -6
  48. package/dist/adapters/raw/header.d.ts +0 -3
  49. package/dist/adapters/raw/index.d.ts +0 -3
  50. package/dist/adapters/raw/module.d.ts +0 -4
  51. package/dist/adapters/raw/type.d.ts +0 -18
  52. package/dist/adapters/web/index.d.ts +0 -2
  53. package/dist/adapters/web/module.d.ts +0 -4
  54. package/dist/adapters/web/type.d.ts +0 -3
  55. package/dist/constants.d.ts +0 -42
  56. package/dist/dispatcher/event/dispatch.d.ts +0 -4
  57. package/dist/dispatcher/event/error.d.ts +0 -5
  58. package/dist/dispatcher/event/index.d.ts +0 -5
  59. package/dist/dispatcher/event/is.d.ts +0 -3
  60. package/dist/dispatcher/event/module.d.ts +0 -56
  61. package/dist/dispatcher/event/types.d.ts +0 -9
  62. package/dist/dispatcher/index.d.ts +0 -2
  63. package/dist/dispatcher/type.d.ts +0 -4
  64. package/dist/error/create.d.ts +0 -11
  65. package/dist/error/index.d.ts +0 -3
  66. package/dist/error/is.d.ts +0 -2
  67. package/dist/error/module.d.ts +0 -3
  68. package/dist/handler/constants.d.ts +0 -5
  69. package/dist/handler/core/define.d.ts +0 -4
  70. package/dist/handler/core/index.d.ts +0 -2
  71. package/dist/handler/core/types.d.ts +0 -10
  72. package/dist/handler/error/define.d.ts +0 -4
  73. package/dist/handler/error/index.d.ts +0 -2
  74. package/dist/handler/error/types.d.ts +0 -11
  75. package/dist/handler/index.d.ts +0 -7
  76. package/dist/handler/is.d.ts +0 -4
  77. package/dist/handler/module.d.ts +0 -23
  78. package/dist/handler/types-base.d.ts +0 -10
  79. package/dist/handler/types.d.ts +0 -4
  80. package/dist/hook/constants.d.ts +0 -8
  81. package/dist/hook/index.d.ts +0 -3
  82. package/dist/hook/module.d.ts +0 -19
  83. package/dist/hook/types.d.ts +0 -5
  84. package/dist/index.cjs +0 -2314
  85. package/dist/index.cjs.map +0 -1
  86. package/dist/index.d.ts +0 -11
  87. package/dist/index.mjs +0 -2235
  88. package/dist/index.mjs.map +0 -1
  89. package/dist/path/index.d.ts +0 -3
  90. package/dist/path/matcher.d.ts +0 -11
  91. package/dist/path/type.d.ts +0 -7
  92. package/dist/path/utils.d.ts +0 -2
  93. package/dist/plugin/index.d.ts +0 -2
  94. package/dist/plugin/is.d.ts +0 -2
  95. package/dist/plugin/types.d.ts +0 -23
  96. package/dist/request/helpers/cache.d.ts +0 -2
  97. package/dist/request/helpers/env.d.ts +0 -6
  98. package/dist/request/helpers/header-accept-charset.d.ts +0 -3
  99. package/dist/request/helpers/header-accept-encoding.d.ts +0 -3
  100. package/dist/request/helpers/header-accept-language.d.ts +0 -3
  101. package/dist/request/helpers/header-accept.d.ts +0 -3
  102. package/dist/request/helpers/header-content-type.d.ts +0 -2
  103. package/dist/request/helpers/header.d.ts +0 -4
  104. package/dist/request/helpers/hostname.d.ts +0 -7
  105. package/dist/request/helpers/http2.d.ts +0 -2
  106. package/dist/request/helpers/index.d.ts +0 -17
  107. package/dist/request/helpers/ip.d.ts +0 -7
  108. package/dist/request/helpers/mount-path.d.ts +0 -3
  109. package/dist/request/helpers/negotiator.d.ts +0 -3
  110. package/dist/request/helpers/params.d.ts +0 -5
  111. package/dist/request/helpers/path.d.ts +0 -2
  112. package/dist/request/helpers/protocol.d.ts +0 -8
  113. package/dist/request/helpers/router.d.ts +0 -3
  114. package/dist/request/index.d.ts +0 -3
  115. package/dist/request/module.d.ts +0 -3
  116. package/dist/request/types.d.ts +0 -12
  117. package/dist/response/helpers/cache.d.ts +0 -7
  118. package/dist/response/helpers/event-stream/factory.d.ts +0 -3
  119. package/dist/response/helpers/event-stream/index.d.ts +0 -2
  120. package/dist/response/helpers/event-stream/module.d.ts +0 -17
  121. package/dist/response/helpers/event-stream/types.d.ts +0 -24
  122. package/dist/response/helpers/event-stream/utils.d.ts +0 -2
  123. package/dist/response/helpers/gone.d.ts +0 -3
  124. package/dist/response/helpers/header-attachment.d.ts +0 -2
  125. package/dist/response/helpers/header-content-type.d.ts +0 -2
  126. package/dist/response/helpers/header.d.ts +0 -4
  127. package/dist/response/helpers/index.d.ts +0 -16
  128. package/dist/response/helpers/send-accepted.d.ts +0 -2
  129. package/dist/response/helpers/send-created.d.ts +0 -2
  130. package/dist/response/helpers/send-file.d.ts +0 -17
  131. package/dist/response/helpers/send-format.d.ts +0 -7
  132. package/dist/response/helpers/send-redirect.d.ts +0 -2
  133. package/dist/response/helpers/send-stream.d.ts +0 -3
  134. package/dist/response/helpers/send-web-blob.d.ts +0 -3
  135. package/dist/response/helpers/send-web-response.d.ts +0 -3
  136. package/dist/response/helpers/send.d.ts +0 -2
  137. package/dist/response/helpers/utils.d.ts +0 -2
  138. package/dist/response/index.d.ts +0 -3
  139. package/dist/response/module.d.ts +0 -3
  140. package/dist/response/types.d.ts +0 -3
  141. package/dist/router/constants.d.ts +0 -9
  142. package/dist/router/index.d.ts +0 -1
  143. package/dist/router/module.d.ts +0 -89
  144. package/dist/router/types.d.ts +0 -7
  145. package/dist/router/utils.d.ts +0 -3
  146. package/dist/router-options/index.d.ts +0 -2
  147. package/dist/router-options/module.d.ts +0 -4
  148. package/dist/router-options/transform.d.ts +0 -2
  149. package/dist/router-options/type.d.ts +0 -41
  150. package/dist/types.d.ts +0 -9
  151. package/dist/utils/cookie.d.ts +0 -1
  152. package/dist/utils/etag/index.d.ts +0 -3
  153. package/dist/utils/etag/module.d.ts +0 -11
  154. package/dist/utils/etag/type.d.ts +0 -15
  155. package/dist/utils/etag/utils.d.ts +0 -2
  156. package/dist/utils/index.d.ts +0 -13
  157. package/dist/utils/is-instance.d.ts +0 -1
  158. package/dist/utils/method.d.ts +0 -3
  159. package/dist/utils/mime.d.ts +0 -2
  160. package/dist/utils/next.d.ts +0 -2
  161. package/dist/utils/object.d.ts +0 -3
  162. package/dist/utils/path.d.ts +0 -5
  163. package/dist/utils/promise.d.ts +0 -1
  164. package/dist/utils/stream.d.ts +0 -6
  165. package/dist/utils/trust-proxy/index.d.ts +0 -2
  166. package/dist/utils/trust-proxy/module.d.ts +0 -2
  167. package/dist/utils/trust-proxy/type.d.ts +0 -2
  168. package/dist/utils/url.d.ts +0 -7
  169. package/dist/utils/web.d.ts +0 -3
@@ -1,56 +0,0 @@
1
- import { MethodName } from '../../constants';
2
- import type { RoutupError } from '../../error';
3
- import type { Request } from '../../request';
4
- import type { Response } from '../../response';
5
- import type { Next } from '../../types';
6
- import type { DispatchEventCreateContext } from './types';
7
- export declare class DispatchEvent {
8
- /**
9
- * Request Object.
10
- */
11
- request: Request;
12
- /**
13
- * Response Object.
14
- */
15
- response: Response;
16
- /**
17
- * Params collected during execution.
18
- */
19
- params: Record<string, any>;
20
- /**
21
- * Request path.
22
- */
23
- path: string;
24
- /**
25
- * HTTP Method used for the request.
26
- */
27
- method: `${MethodName}`;
28
- /**
29
- * The relative path on which the router is hung.
30
- */
31
- mountPath: string;
32
- /**
33
- * The error which occurred during the dispatch process.
34
- */
35
- error?: RoutupError;
36
- /**
37
- * Signal that the request hasn't been handled.
38
- * Therefore, the request must be passed to the next handler or router in the chain.
39
- */
40
- next: Next;
41
- /**
42
- * Indicate if the request has already been dispatched/send.
43
- */
44
- protected _dispatched: boolean;
45
- /**
46
- * Ids of chained router instances.
47
- */
48
- routerPath: number[];
49
- /**
50
- * Collected methods during dispatch process.
51
- */
52
- methodsAllowed: string[];
53
- constructor(context: DispatchEventCreateContext);
54
- get dispatched(): boolean;
55
- set dispatched(value: boolean);
56
- }
@@ -1,9 +0,0 @@
1
- import type { MethodName } from '../../constants';
2
- import type { Request } from '../../request';
3
- import type { Response } from '../../response';
4
- export type DispatchEventCreateContext = {
5
- request: Request;
6
- response: Response;
7
- method?: `${MethodName}`;
8
- path?: string;
9
- };
@@ -1,2 +0,0 @@
1
- export * from './event';
2
- export * from './type';
@@ -1,4 +0,0 @@
1
- import type { DispatchEvent } from './event';
2
- export interface Dispatcher {
3
- dispatch(event: DispatchEvent): Promise<void>;
4
- }
@@ -1,11 +0,0 @@
1
- import type { Input } from '@ebec/http';
2
- import { RoutupError } from './module';
3
- /**
4
- * Create an internal error object by
5
- * - an existing error (accessible via cause property)
6
- * - options
7
- * - message
8
- *
9
- * @param input
10
- */
11
- export declare function createError(input: Input | unknown): RoutupError;
@@ -1,3 +0,0 @@
1
- export * from './create';
2
- export * from './is';
3
- export * from './module';
@@ -1,2 +0,0 @@
1
- import { RoutupError } from './module';
2
- export declare function isError(input: unknown): input is RoutupError;
@@ -1,3 +0,0 @@
1
- import { HTTPError } from '@ebec/http';
2
- export declare class RoutupError extends HTTPError {
3
- }
@@ -1,5 +0,0 @@
1
- export declare enum HandlerType {
2
- CORE = "core",
3
- ERROR = "error"
4
- }
5
- export declare const HandlerSymbol: unique symbol;
@@ -1,4 +0,0 @@
1
- import { Handler } from '../module';
2
- import type { CoreHandlerConfig, CoreHandlerFn } from './types';
3
- export declare function coreHandler(input: Omit<CoreHandlerConfig, 'type'>): Handler;
4
- export declare function coreHandler(input: CoreHandlerFn): Handler;
@@ -1,2 +0,0 @@
1
- export * from './define';
2
- export * from './types';
@@ -1,10 +0,0 @@
1
- import type { Request } from '../../request';
2
- import type { Response } from '../../response';
3
- import type { Next } from '../../types';
4
- import type { HandlerType } from '../constants';
5
- import type { HandlerBaseConfig } from '../types-base';
6
- export type CoreHandlerFn = (req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
7
- export type CoreHandlerConfig = HandlerBaseConfig & {
8
- type: `${HandlerType.CORE}`;
9
- fn: CoreHandlerFn;
10
- };
@@ -1,4 +0,0 @@
1
- import { Handler } from '../module';
2
- import type { ErrorHandlerConfig, ErrorHandlerFn } from './types';
3
- export declare function errorHandler(input: Omit<ErrorHandlerConfig, 'type'>): Handler;
4
- export declare function errorHandler(input: ErrorHandlerFn): Handler;
@@ -1,2 +0,0 @@
1
- export * from './define';
2
- export * from './types';
@@ -1,11 +0,0 @@
1
- import type { RoutupError } from '../../error';
2
- import type { Request } from '../../request';
3
- import type { Response } from '../../response';
4
- import type { Next } from '../../types';
5
- import type { HandlerType } from '../constants';
6
- import type { HandlerBaseConfig } from '../types-base';
7
- export type ErrorHandlerFn = (err: RoutupError, req: Request, res: Response, next: Next) => unknown | Promise<unknown>;
8
- export type ErrorHandlerConfig = HandlerBaseConfig & {
9
- type: `${HandlerType.ERROR}`;
10
- fn: ErrorHandlerFn;
11
- };
@@ -1,7 +0,0 @@
1
- export * from './core';
2
- export * from './error';
3
- export * from './constants';
4
- export * from './is';
5
- export * from './module';
6
- export * from './types';
7
- export * from './types-base';
@@ -1,4 +0,0 @@
1
- import type { Handler } from './module';
2
- import type { HandlerConfig } from './types';
3
- export declare function isHandlerConfig(input: unknown): input is HandlerConfig;
4
- export declare function isHandler(input: unknown): input is Handler;
@@ -1,23 +0,0 @@
1
- import { MethodName } from '../constants';
2
- import type { DispatchEvent, Dispatcher } from '../dispatcher';
3
- import { HookManager } from '../hook';
4
- import type { Path } from '../path';
5
- import { PathMatcher } from '../path';
6
- import type { HandlerConfig } from './types';
7
- export declare class Handler implements Dispatcher {
8
- readonly '@instanceof': symbol;
9
- protected config: HandlerConfig;
10
- protected hookManager: HookManager;
11
- protected pathMatcher: PathMatcher | undefined;
12
- protected _method: MethodName | undefined;
13
- constructor(handler: HandlerConfig);
14
- get type(): "error" | "core";
15
- get path(): string | undefined;
16
- get method(): MethodName | undefined;
17
- dispatch(event: DispatchEvent): Promise<void>;
18
- matchPath(path: string): boolean;
19
- setPath(path?: Path): void;
20
- matchMethod(method: `${MethodName}`): boolean;
21
- setMethod(input?: `${MethodName}`): void;
22
- protected mountHooks(): void;
23
- }
@@ -1,10 +0,0 @@
1
- import type { MethodName } from '../constants';
2
- import type { HookDefaultListener, HookErrorListener } from '../hook';
3
- import type { Path } from '../path';
4
- export type HandlerBaseConfig = {
5
- method?: Uppercase<MethodName> | Lowercase<MethodName>;
6
- path?: Path;
7
- onError?: HookErrorListener;
8
- onBefore?: HookDefaultListener;
9
- onAfter?: HookDefaultListener;
10
- };
@@ -1,4 +0,0 @@
1
- import type { CoreHandlerConfig, CoreHandlerFn } from './core';
2
- import type { ErrorHandlerConfig, ErrorHandlerFn } from './error';
3
- export type HandlerConfig = CoreHandlerConfig | ErrorHandlerConfig;
4
- export type HandlerFn = CoreHandlerFn | ErrorHandlerFn;
@@ -1,8 +0,0 @@
1
- export declare enum HookName {
2
- ERROR = "error",
3
- DISPATCH_START = "dispatchStart",
4
- DISPATCH_END = "dispatchEnd",
5
- CHILD_MATCH = "childMatch",
6
- CHILD_DISPATCH_BEFORE = "childDispatchBefore",
7
- CHILD_DISPATCH_AFTER = "childDispatchAfter"
8
- }
@@ -1,3 +0,0 @@
1
- export * from './constants';
2
- export * from './module';
3
- export * from './types';
@@ -1,19 +0,0 @@
1
- import type { DispatchEvent } from '../dispatcher';
2
- import { HookName } from './constants';
3
- import type { HookListener, HookUnsubscribeFn } from './types';
4
- export declare class HookManager {
5
- protected items: Record<string, HookListener[]>;
6
- constructor();
7
- addListener(name: `${HookName}`, fn: HookListener): HookUnsubscribeFn;
8
- removeListener(name: `${HookName}`): void;
9
- removeListener(name: `${HookName}`, fn: HookListener): void;
10
- /**
11
- * @throws RoutupError
12
- *
13
- * @param name
14
- * @param event
15
- */
16
- trigger(name: `${HookName}`, event: DispatchEvent): Promise<void>;
17
- private triggerListener;
18
- private isErrorListenerHook;
19
- }
@@ -1,5 +0,0 @@
1
- import type { DispatchErrorEvent, DispatchEvent } from '../dispatcher';
2
- export type HookErrorListener = (event: DispatchErrorEvent) => Promise<unknown> | unknown;
3
- export type HookDefaultListener = (event: DispatchEvent) => Promise<unknown> | unknown;
4
- export type HookListener = HookErrorListener | HookDefaultListener;
5
- export type HookUnsubscribeFn = () => void;