@asenajs/asena 0.1.17 → 0.1.19
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 +171 -41
- package/dist/index.d.ts +1 -10
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/adapter/AsenaAdapter.d.ts +46 -53
- package/dist/lib/adapter/AsenaAdapter.js +22 -11
- package/dist/lib/adapter/AsenaAdapter.js.map +1 -1
- package/dist/lib/adapter/AsenaContext.d.ts +70 -62
- package/dist/lib/adapter/AsenaWebsocketAdapter.d.ts +58 -34
- package/dist/lib/adapter/AsenaWebsocketAdapter.js +43 -12
- package/dist/lib/adapter/AsenaWebsocketAdapter.js.map +1 -1
- package/dist/lib/adapter/hono/HonoAdapter.d.ts +28 -0
- package/dist/lib/adapter/{defaultAdapter/DefaultAdapter.js → hono/HonoAdapter.js} +57 -35
- package/dist/lib/adapter/hono/HonoAdapter.js.map +1 -0
- package/dist/lib/adapter/{defaultAdapter/DefaultContextWrapper.d.ts → hono/HonoContextWrapper.d.ts} +4 -4
- package/dist/lib/adapter/{defaultAdapter/DefaultContextWrapper.js → hono/HonoContextWrapper.js} +6 -6
- package/dist/lib/adapter/hono/HonoContextWrapper.js.map +1 -0
- package/dist/lib/adapter/{defaultAdapter/DefaultWebsocketAdapter.d.ts → hono/HonoWebsocketAdapter.d.ts} +9 -5
- package/dist/lib/adapter/{defaultAdapter/DefaultWebsocketAdapter.js → hono/HonoWebsocketAdapter.js} +34 -24
- package/dist/lib/adapter/hono/HonoWebsocketAdapter.js.map +1 -0
- package/dist/lib/adapter/hono/defaults/ConfigService.d.ts +4 -0
- package/dist/lib/adapter/hono/defaults/ConfigService.js +3 -0
- package/dist/lib/adapter/hono/defaults/ConfigService.js.map +1 -0
- package/dist/lib/adapter/hono/defaults/Context.js +2 -0
- package/dist/lib/adapter/hono/defaults/Context.js.map +1 -0
- package/dist/lib/adapter/hono/defaults/MiddlewareService.d.ts +5 -0
- package/dist/lib/adapter/hono/defaults/MiddlewareService.js +4 -0
- package/dist/lib/adapter/hono/defaults/MiddlewareService.js.map +1 -0
- package/dist/lib/adapter/hono/defaults/ValidationService.d.ts +10 -0
- package/dist/lib/adapter/hono/defaults/ValidationService.js +3 -0
- package/dist/lib/adapter/hono/defaults/ValidationService.js.map +1 -0
- package/dist/lib/adapter/hono/defaults/index.d.ts +4 -0
- package/dist/lib/adapter/hono/defaults/index.js +5 -0
- package/dist/lib/adapter/hono/defaults/index.js.map +1 -0
- package/dist/lib/adapter/hono/index.d.ts +6 -0
- package/dist/lib/adapter/hono/index.js +7 -0
- package/dist/lib/adapter/hono/index.js.map +1 -0
- package/dist/lib/adapter/hono/types/HonoHandler.d.ts +5 -0
- package/dist/lib/adapter/hono/types/HonoHandler.js +2 -0
- package/dist/lib/adapter/hono/types/HonoHandler.js.map +1 -0
- package/dist/lib/adapter/hono/types/index.d.ts +2 -0
- package/dist/lib/adapter/hono/types/index.js +3 -0
- package/dist/lib/adapter/hono/types/index.js.map +1 -0
- package/dist/lib/adapter/hono/utils/createHonoAdapter.d.ts +3 -0
- package/dist/lib/adapter/hono/utils/createHonoAdapter.js +6 -0
- package/dist/lib/adapter/hono/utils/createHonoAdapter.js.map +1 -0
- package/dist/lib/adapter/hono/utils/middlewareParser.d.ts +4 -0
- package/dist/lib/adapter/hono/utils/middlewareParser.js +15 -0
- package/dist/lib/adapter/hono/utils/middlewareParser.js.map +1 -0
- package/dist/lib/adapter/index.d.ts +1 -0
- package/dist/lib/adapter/index.js +1 -0
- package/dist/lib/adapter/index.js.map +1 -1
- package/dist/lib/adapter/types/AsenaHandler.d.ts +2 -0
- package/dist/lib/adapter/types/AsenaHandler.js +2 -0
- package/dist/lib/adapter/types/AsenaHandler.js.map +1 -0
- package/dist/lib/adapter/types/AsenaMiddlewareHandler.d.ts +2 -0
- package/dist/lib/adapter/types/AsenaMiddlewareHandler.js +2 -0
- package/dist/lib/adapter/types/AsenaMiddlewareHandler.js.map +1 -0
- package/dist/lib/adapter/types/ErrorHandler.d.ts +2 -0
- package/dist/lib/adapter/types/ErrorHandler.js +2 -0
- package/dist/lib/adapter/types/ErrorHandler.js.map +1 -0
- package/dist/lib/adapter/types/RouteParams.d.ts +7 -4
- package/dist/lib/adapter/types/ServeOptions.d.ts +7 -0
- package/dist/lib/adapter/types/ServeOptions.js +2 -0
- package/dist/lib/adapter/types/ServeOptions.js.map +1 -0
- package/dist/lib/adapter/types/WebSocketRegistry.d.ts +5 -4
- package/dist/lib/adapter/types/WebsocketAdapterParams.d.ts +1 -1
- package/dist/lib/adapter/types/index.d.ts +3 -0
- package/dist/lib/adapter/types/index.js +3 -0
- package/dist/lib/adapter/types/index.js.map +1 -1
- package/dist/lib/ioc/Container.d.ts +7 -3
- package/dist/lib/ioc/Container.js +69 -87
- package/dist/lib/ioc/Container.js.map +1 -1
- package/dist/lib/ioc/IocEngine.d.ts +2 -2
- package/dist/lib/ioc/IocEngine.js +27 -15
- package/dist/lib/ioc/IocEngine.js.map +1 -1
- package/dist/lib/ioc/component/componentUtils.d.ts +1 -1
- package/dist/lib/ioc/component/componentUtils.js +16 -12
- package/dist/lib/ioc/component/componentUtils.js.map +1 -1
- package/dist/lib/{server/decorators/components → ioc/component/decorators}/Component.d.ts +1 -1
- package/dist/lib/{server/decorators/components → ioc/component/decorators}/Component.js +2 -2
- package/dist/lib/ioc/component/decorators/Component.js.map +1 -0
- package/dist/lib/ioc/component/decorators/Implements.js +2 -2
- package/dist/lib/ioc/component/decorators/Implements.js.map +1 -1
- package/dist/lib/ioc/component/decorators/Inject.d.ts +1 -1
- package/dist/lib/ioc/component/decorators/Inject.js +6 -7
- package/dist/lib/ioc/component/decorators/Inject.js.map +1 -1
- package/dist/lib/ioc/component/decorators/PostConstruct.d.ts +6 -0
- package/dist/lib/ioc/component/decorators/PostConstruct.js +17 -0
- package/dist/lib/ioc/component/decorators/PostConstruct.js.map +1 -0
- package/dist/lib/ioc/component/decorators/Strategy.js +6 -6
- package/dist/lib/ioc/component/decorators/Strategy.js.map +1 -1
- package/dist/lib/ioc/component/decorators/index.d.ts +1 -0
- package/dist/lib/ioc/component/decorators/index.js +1 -0
- package/dist/lib/ioc/component/decorators/index.js.map +1 -1
- package/dist/lib/ioc/component/index.d.ts +1 -0
- package/dist/lib/ioc/component/index.js +2 -0
- package/dist/lib/ioc/component/index.js.map +1 -0
- package/dist/lib/ioc/constants/ComponentConstants.d.ts +4 -2
- package/dist/lib/ioc/constants/ComponentConstants.js +3 -1
- package/dist/lib/ioc/constants/ComponentConstants.js.map +1 -1
- package/dist/lib/ioc/helper/fileHelper.d.ts +1 -1
- package/dist/lib/ioc/helper/fileHelper.js +9 -3
- package/dist/lib/ioc/helper/fileHelper.js.map +1 -1
- package/dist/lib/ioc/helper/iocHelper.d.ts +2 -3
- package/dist/lib/ioc/helper/iocHelper.js +4 -2
- package/dist/lib/ioc/helper/iocHelper.js.map +1 -1
- package/dist/lib/ioc/types/{Component.d.ts → InjectableComponent.d.ts} +4 -4
- package/dist/lib/ioc/types/InjectableComponent.js +2 -0
- package/dist/lib/ioc/types/InjectableComponent.js.map +1 -0
- package/dist/lib/ioc/types/IocConfig.d.ts +1 -0
- package/dist/lib/ioc/types/decorators/ComponentParams.d.ts +1 -1
- package/dist/lib/ioc/types/decorators/ComponentType.d.ts +2 -2
- package/dist/lib/ioc/types/decorators/ComponentType.js +1 -1
- package/dist/lib/ioc/types/decorators/ComponentType.js.map +1 -1
- package/dist/lib/ioc/types/decorators/ControllerParams.d.ts +4 -3
- package/dist/lib/ioc/types/decorators/MiddlewareParams.d.ts +1 -1
- package/dist/lib/ioc/types/index.d.ts +1 -1
- package/dist/lib/ioc/types/index.js +1 -1
- package/dist/lib/ioc/types/index.js.map +1 -1
- package/dist/lib/{services/logger → logger}/DefaultLogger.d.ts +1 -1
- package/dist/lib/logger/DefaultLogger.js.map +1 -0
- package/dist/lib/{services/types → logger}/Logger.js.map +1 -1
- package/dist/lib/logger/index.d.ts +2 -0
- package/dist/lib/logger/index.js +3 -0
- package/dist/lib/logger/index.js.map +1 -0
- package/dist/lib/server/AsenaServer.d.ts +15 -14
- package/dist/lib/server/AsenaServer.js +125 -113
- package/dist/lib/server/AsenaServer.js.map +1 -1
- package/dist/lib/server/config/AsenaConfig.d.ts +43 -0
- package/dist/lib/server/config/AsenaConfig.js +2 -0
- package/dist/lib/server/config/AsenaConfig.js.map +1 -0
- package/dist/lib/server/decorators/Override.d.ts +4 -4
- package/dist/lib/server/decorators/Override.js +11 -7
- package/dist/lib/server/decorators/Override.js.map +1 -1
- package/dist/lib/server/decorators/components/Config.d.ts +10 -0
- package/dist/lib/server/decorators/components/Config.js +14 -0
- package/dist/lib/server/decorators/components/Config.js.map +1 -0
- package/dist/lib/server/decorators/components/Controller.js +4 -4
- package/dist/lib/server/decorators/components/Controller.js.map +1 -1
- package/dist/lib/server/decorators/components/Middleware.d.ts +1 -1
- package/dist/lib/server/decorators/components/Middleware.js +19 -9
- package/dist/lib/server/decorators/components/Middleware.js.map +1 -1
- package/dist/lib/server/decorators/components/Schedule.d.ts +2 -2
- package/dist/lib/server/decorators/components/Schedule.js +7 -7
- package/dist/lib/server/decorators/components/Schedule.js.map +1 -1
- package/dist/lib/server/decorators/components/Service.d.ts +1 -1
- package/dist/lib/server/decorators/components/Service.js +2 -2
- package/dist/lib/server/decorators/components/Service.js.map +1 -1
- package/dist/lib/server/decorators/components/WebSocket.js +4 -4
- package/dist/lib/server/decorators/components/WebSocket.js.map +1 -1
- package/dist/lib/server/decorators/components/index.d.ts +1 -2
- package/dist/lib/server/decorators/components/index.js +1 -2
- package/dist/lib/server/decorators/components/index.js.map +1 -1
- package/dist/lib/server/decorators/index.d.ts +2 -1
- package/dist/lib/server/decorators/index.js +2 -1
- package/dist/lib/server/decorators/index.js.map +1 -1
- package/dist/lib/server/index.d.ts +1 -0
- package/dist/lib/server/index.js +1 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/server/types/Class.d.ts +0 -3
- package/dist/lib/server/web/decorators/http.base.d.ts +4 -0
- package/dist/lib/server/web/decorators/http.base.js +35 -0
- package/dist/lib/server/web/decorators/http.base.js.map +1 -0
- package/dist/lib/server/web/decorators/index.d.ts +4 -0
- package/dist/lib/server/web/decorators/index.js +5 -0
- package/dist/lib/server/web/decorators/index.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Connect.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Connect.js +12 -0
- package/dist/lib/server/web/decorators/methods/Connect.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Delete.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Delete.js +12 -0
- package/dist/lib/server/web/decorators/methods/Delete.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Get.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Get.js +12 -0
- package/dist/lib/server/web/decorators/methods/Get.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Head.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Head.js +12 -0
- package/dist/lib/server/web/decorators/methods/Head.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Options.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Options.js +12 -0
- package/dist/lib/server/web/decorators/methods/Options.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Patch.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Patch.js +12 -0
- package/dist/lib/server/web/decorators/methods/Patch.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Post.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Post.js +12 -0
- package/dist/lib/server/web/decorators/methods/Post.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Put.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Put.js +12 -0
- package/dist/lib/server/web/decorators/methods/Put.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Trace.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/Trace.js +12 -0
- package/dist/lib/server/web/decorators/methods/Trace.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/index.d.ts +9 -0
- package/dist/lib/server/web/decorators/methods/index.js +10 -0
- package/dist/lib/server/web/decorators/methods/index.js.map +1 -0
- package/dist/lib/server/web/helper/middlewareHelper.d.ts +7 -1
- package/dist/lib/server/web/helper/middlewareHelper.js +11 -5
- package/dist/lib/server/web/helper/middlewareHelper.js.map +1 -1
- package/dist/lib/server/web/http/HttpStatus.d.ts +69 -67
- package/dist/lib/server/web/http/HttpStatus.js +69 -68
- package/dist/lib/server/web/http/HttpStatus.js.map +1 -1
- package/dist/lib/server/web/middleware/AsenaMiddlewareService.d.ts +8 -10
- package/dist/lib/server/web/middleware/AsenaMiddlewareService.js +1 -4
- package/dist/lib/server/web/middleware/AsenaMiddlewareService.js.map +1 -1
- package/dist/lib/server/web/middleware/AsenaValidationService.d.ts +15 -16
- package/dist/lib/server/web/middleware/AsenaValidationService.js +1 -8
- package/dist/lib/server/web/middleware/AsenaValidationService.js.map +1 -1
- package/dist/lib/server/web/types/ApiParams.d.ts +73 -0
- package/dist/lib/server/web/types/ApiParams.js +2 -0
- package/dist/lib/server/web/types/ApiParams.js.map +1 -0
- package/dist/lib/server/web/types/BaseMiddleware.d.ts +50 -5
- package/dist/lib/server/web/types/BaseMiddleware.js +1 -1
- package/dist/lib/server/web/types/BaseMiddleware.js.map +1 -1
- package/dist/lib/server/web/types/index.d.ts +1 -1
- package/dist/lib/server/web/types/index.js +1 -1
- package/dist/lib/server/web/types/index.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaSocket.js +1 -0
- package/dist/lib/server/web/websocket/AsenaSocket.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.d.ts +39 -0
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js +40 -0
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaWebSocketService.js +4 -4
- package/dist/lib/server/web/websocket/AsenaWebSocketService.js.map +1 -1
- package/dist/lib/utils/typedMetadata.d.ts +2 -0
- package/dist/lib/utils/typedMetadata.js +13 -0
- package/dist/lib/utils/typedMetadata.js.map +1 -0
- package/package.json +53 -5
- package/dist/lib/adapter/defaultAdapter/DefaultAdapter.d.ts +0 -26
- package/dist/lib/adapter/defaultAdapter/DefaultAdapter.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/DefaultContextWrapper.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/DefaultWebsocketAdapter.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/index.d.ts +0 -3
- package/dist/lib/adapter/defaultAdapter/index.js +0 -4
- package/dist/lib/adapter/defaultAdapter/index.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/types/Defaultcontext.js +0 -2
- package/dist/lib/adapter/defaultAdapter/types/Defaultcontext.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/types/Handler.d.ts +0 -4
- package/dist/lib/adapter/defaultAdapter/types/Handler.js +0 -2
- package/dist/lib/adapter/defaultAdapter/types/Handler.js.map +0 -1
- package/dist/lib/adapter/defaultAdapter/types/index.d.ts +0 -2
- package/dist/lib/adapter/defaultAdapter/types/index.js +0 -3
- package/dist/lib/adapter/defaultAdapter/types/index.js.map +0 -1
- package/dist/lib/ioc/types/Component.js +0 -2
- package/dist/lib/ioc/types/Component.js.map +0 -1
- package/dist/lib/server/decorators/components/Component.js.map +0 -1
- package/dist/lib/server/decorators/components/ServerService.d.ts +0 -9
- package/dist/lib/server/decorators/components/ServerService.js +0 -13
- package/dist/lib/server/decorators/components/ServerService.js.map +0 -1
- package/dist/lib/server/web/api/apiHandler.d.ts +0 -55
- package/dist/lib/server/web/api/apiHandler.js +0 -107
- package/dist/lib/server/web/api/apiHandler.js.map +0 -1
- package/dist/lib/server/web/api/index.d.ts +0 -1
- package/dist/lib/server/web/api/index.js +0 -2
- package/dist/lib/server/web/api/index.js.map +0 -1
- package/dist/lib/server/web/types/ApiHandler.d.ts +0 -23
- package/dist/lib/server/web/types/ApiHandler.js +0 -2
- package/dist/lib/server/web/types/ApiHandler.js.map +0 -1
- package/dist/lib/services/index.d.ts +0 -3
- package/dist/lib/services/index.js +0 -4
- package/dist/lib/services/index.js.map +0 -1
- package/dist/lib/services/logger/DefaultLogger.js.map +0 -1
- package/dist/lib/services/serverService/AsenaService.d.ts +0 -7
- package/dist/lib/services/serverService/AsenaService.js +0 -7
- package/dist/lib/services/serverService/AsenaService.js.map +0 -1
- package/dist/lib/services/types/index.d.ts +0 -2
- package/dist/lib/services/types/index.js +0 -3
- package/dist/lib/services/types/index.js.map +0 -1
- /package/dist/lib/adapter/{defaultAdapter/types/Defaultcontext.d.ts → hono/defaults/Context.d.ts} +0 -0
- /package/dist/lib/{services/logger → logger}/DefaultLogger.js +0 -0
- /package/dist/lib/{services/types → logger}/Logger.d.ts +0 -0
- /package/dist/lib/{services/types → logger}/Logger.js +0 -0
|
@@ -1,143 +1,151 @@
|
|
|
1
|
-
import type { CookieExtra } from './types';
|
|
2
|
-
import type { SendOptions } from './types';
|
|
3
|
-
import type { TypedResponse } from 'hono';
|
|
1
|
+
import type { CookieExtra, SendOptions } from './types';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
3
|
+
* AsenaContext represents the core context interface for handling HTTP requests and responses in Asena framework.
|
|
4
|
+
* It provides essential methods and properties for request/response handling, data manipulation, and state management.
|
|
6
5
|
*
|
|
7
|
-
* @template R -
|
|
8
|
-
* @template S -
|
|
6
|
+
* @template R - Type parameter for the underlying request object
|
|
7
|
+
* @template S - Type parameter for the underlying response object
|
|
9
8
|
*/
|
|
10
9
|
export interface AsenaContext<R, S> {
|
|
10
|
+
/** The original request object */
|
|
11
11
|
req: R;
|
|
12
|
+
/** The original response object */
|
|
12
13
|
res: S;
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* Request headers stored as key-value pairs
|
|
15
16
|
*/
|
|
16
17
|
headers: Record<string, string>;
|
|
17
18
|
/**
|
|
18
|
-
* Retrieves the request body as an ArrayBuffer.
|
|
19
|
+
* Retrieves the raw request body as an ArrayBuffer.
|
|
20
|
+
* Useful for handling binary data.
|
|
19
21
|
*
|
|
20
|
-
* @returns {Promise<ArrayBuffer>}
|
|
22
|
+
* @returns {Promise<ArrayBuffer>} The request body as an ArrayBuffer
|
|
21
23
|
*/
|
|
22
24
|
getArrayBuffer: () => Promise<ArrayBuffer>;
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
26
|
+
* Automatically parses the request body based on content type.
|
|
27
|
+
* Supports JSON, form data, and other common formats.
|
|
25
28
|
*
|
|
26
|
-
* @returns {Promise<any>}
|
|
29
|
+
* @returns {Promise<any>} The parsed request body
|
|
27
30
|
*/
|
|
28
31
|
getParseBody: () => Promise<any>;
|
|
29
32
|
/**
|
|
30
|
-
* Retrieves the request body as a Blob.
|
|
33
|
+
* Retrieves the request body as a Blob object.
|
|
34
|
+
* Useful for handling file uploads and binary data.
|
|
31
35
|
*
|
|
32
|
-
* @returns {Promise<Blob>}
|
|
36
|
+
* @returns {Promise<Blob>} The request body as a Blob
|
|
33
37
|
*/
|
|
34
38
|
getBlob: () => Promise<Blob>;
|
|
35
39
|
/**
|
|
36
40
|
* Retrieves the request body as FormData.
|
|
41
|
+
* Useful for processing multipart/form-data submissions.
|
|
37
42
|
*
|
|
38
|
-
* @returns {Promise<FormData>}
|
|
43
|
+
* @returns {Promise<FormData>} The request body as FormData
|
|
39
44
|
*/
|
|
40
45
|
getFormData: () => Promise<FormData>;
|
|
41
46
|
/**
|
|
42
|
-
* Retrieves a parameter
|
|
47
|
+
* Retrieves a route parameter by name.
|
|
48
|
+
* Example: For route "/users/:id", getParam("id") returns the actual ID value.
|
|
43
49
|
*
|
|
44
|
-
* @param {string} s - The name
|
|
45
|
-
* @returns {string} The value
|
|
50
|
+
* @param {string} s - The parameter name to retrieve
|
|
51
|
+
* @returns {string} The parameter value
|
|
46
52
|
*/
|
|
47
53
|
getParam: (s: string) => string;
|
|
48
54
|
/**
|
|
49
|
-
* Retrieves the request body
|
|
55
|
+
* Retrieves and automatically type-casts the request body.
|
|
50
56
|
*
|
|
51
|
-
* @template U - The type
|
|
52
|
-
* @returns {Promise<U>}
|
|
57
|
+
* @template U - The expected type of the body
|
|
58
|
+
* @returns {Promise<U>} The typed request body
|
|
53
59
|
*/
|
|
54
60
|
getBody: <U>() => Promise<U>;
|
|
55
61
|
/**
|
|
56
|
-
* Retrieves a query parameter
|
|
62
|
+
* Retrieves a single query parameter value.
|
|
63
|
+
* For URL "?name=john", getQuery("name") returns "john".
|
|
57
64
|
*
|
|
58
|
-
* @param {string} query - The
|
|
59
|
-
* @returns {Promise<string>}
|
|
65
|
+
* @param {string} query - The query parameter name
|
|
66
|
+
* @returns {Promise<string>} The query parameter value
|
|
60
67
|
*/
|
|
61
68
|
getQuery: (query: string) => Promise<string>;
|
|
62
69
|
/**
|
|
63
|
-
* Retrieves all values
|
|
70
|
+
* Retrieves all values for a query parameter that appears multiple times.
|
|
71
|
+
* For URL "?color=red&color=blue", getQueryAll("color") returns ["red", "blue"].
|
|
64
72
|
*
|
|
65
|
-
* @param {string} query - The
|
|
66
|
-
* @returns {Promise<string[]>}
|
|
73
|
+
* @param {string} query - The query parameter name
|
|
74
|
+
* @returns {Promise<string[]>} Array of all values for the query parameter
|
|
67
75
|
*/
|
|
68
76
|
getQueryAll: (query: string) => Promise<string[]>;
|
|
69
77
|
/**
|
|
70
|
-
* Retrieves a cookie
|
|
78
|
+
* Retrieves a cookie value by name, with optional signature verification.
|
|
71
79
|
*
|
|
72
|
-
* @param {string} name - The name
|
|
73
|
-
* @param {string | BufferSource} [secret] - Optional secret for signed cookies
|
|
74
|
-
* @returns {Promise<string | false>}
|
|
80
|
+
* @param {string} name - The cookie name
|
|
81
|
+
* @param {string | BufferSource} [secret] - Optional secret for verifying signed cookies
|
|
82
|
+
* @returns {Promise<string | false>} The cookie value if found, false otherwise
|
|
75
83
|
*/
|
|
76
84
|
getCookie: (name: string, secret?: string | BufferSource) => Promise<string | false>;
|
|
77
85
|
/**
|
|
78
|
-
* Sets a cookie
|
|
86
|
+
* Sets a cookie with the specified name, value, and options.
|
|
79
87
|
*
|
|
80
|
-
* @param {string} name - The name
|
|
81
|
-
* @param {string} value - The value
|
|
82
|
-
* @param {CookieExtra<any>} [options] -
|
|
83
|
-
* @returns {Promise<void>}
|
|
88
|
+
* @param {string} name - The cookie name
|
|
89
|
+
* @param {string} value - The cookie value
|
|
90
|
+
* @param {CookieExtra<any>} [options] - Cookie options (expires, domain, path, etc.)
|
|
91
|
+
* @returns {Promise<void>}
|
|
84
92
|
*/
|
|
85
93
|
setCookie: (name: string, value: string, options?: CookieExtra<any>) => Promise<void>;
|
|
86
94
|
/**
|
|
87
|
-
* Deletes a cookie
|
|
95
|
+
* Deletes a cookie by setting its expiration to the past.
|
|
88
96
|
*
|
|
89
|
-
* @param {string} name - The name
|
|
90
|
-
* @param {CookieExtra<any>} [options] -
|
|
91
|
-
* @returns {Promise<void>}
|
|
97
|
+
* @param {string} name - The cookie name to delete
|
|
98
|
+
* @param {CookieExtra<any>} [options] - Cookie options (domain, path, etc.)
|
|
99
|
+
* @returns {Promise<void>}
|
|
92
100
|
*/
|
|
93
101
|
deleteCookie: (name: string, options?: CookieExtra<any>) => Promise<void>;
|
|
94
102
|
/**
|
|
95
|
-
* Retrieves a value from the context.
|
|
103
|
+
* Retrieves a value from the context's state storage.
|
|
96
104
|
*
|
|
97
|
-
* @template T - The type of the value
|
|
98
|
-
* @param {string} key - The key
|
|
99
|
-
* @returns {T} The value
|
|
105
|
+
* @template T - The expected type of the value
|
|
106
|
+
* @param {string} key - The key to retrieve
|
|
107
|
+
* @returns {T} The stored value
|
|
100
108
|
*/
|
|
101
109
|
getValue: <T>(key: string) => T;
|
|
102
110
|
/**
|
|
103
|
-
*
|
|
111
|
+
* Stores a value in the context's state storage.
|
|
104
112
|
*
|
|
105
|
-
* @param {string} key - The key
|
|
106
|
-
* @param {any} value - The value to
|
|
113
|
+
* @param {string} key - The key to store under
|
|
114
|
+
* @param {any} value - The value to store
|
|
107
115
|
*/
|
|
108
116
|
setValue: (key: string, value: any) => void;
|
|
109
117
|
/**
|
|
110
|
-
*
|
|
118
|
+
* Stores a value specifically for WebSocket communication.
|
|
111
119
|
*
|
|
112
|
-
* @param {any} value - The value to
|
|
120
|
+
* @param {any} value - The value to store for WebSocket context
|
|
113
121
|
*/
|
|
114
122
|
setWebSocketValue: (value: any) => void;
|
|
115
123
|
/**
|
|
116
|
-
* Retrieves
|
|
124
|
+
* Retrieves the stored WebSocket-specific value.
|
|
117
125
|
*
|
|
118
|
-
* @template T - The type of the value
|
|
119
|
-
* @returns {T} The
|
|
126
|
+
* @template T - The expected type of the WebSocket value
|
|
127
|
+
* @returns {T} The stored WebSocket value
|
|
120
128
|
*/
|
|
121
129
|
getWebSocketValue: <T>() => T;
|
|
122
130
|
/**
|
|
123
|
-
* Sends an HTML response.
|
|
131
|
+
* Sends an HTML response with appropriate content-type headers.
|
|
124
132
|
*
|
|
125
|
-
* @param {string} data - The HTML
|
|
126
|
-
* @returns {Response | Promise<Response>
|
|
133
|
+
* @param {string} data - The HTML content to send
|
|
134
|
+
* @returns {Response | Promise<Response>} The response object
|
|
127
135
|
*/
|
|
128
|
-
html: (data: string) => Response | Promise<Response
|
|
136
|
+
html: (data: string) => Response | Promise<Response>;
|
|
129
137
|
/**
|
|
130
|
-
* Sends a response.
|
|
138
|
+
* Sends a response with automatic content-type detection.
|
|
131
139
|
*
|
|
132
|
-
* @param {string | any} data - The
|
|
133
|
-
* @param {SendOptions | number} [status] -
|
|
134
|
-
* @returns {Response | Promise<Response>
|
|
140
|
+
* @param {string | any} data - The content to send
|
|
141
|
+
* @param {SendOptions | number} [status] - HTTP status code or send options
|
|
142
|
+
* @returns {Response | Promise<Response>} The response object
|
|
135
143
|
*/
|
|
136
|
-
send: (data: string | any, status?: SendOptions | number) => Response | Promise<Response
|
|
144
|
+
send: (data: string | any, status?: SendOptions | number) => Response | Promise<Response>;
|
|
137
145
|
/**
|
|
138
|
-
*
|
|
146
|
+
* Performs an HTTP redirect to the specified URL.
|
|
139
147
|
*
|
|
140
|
-
* @param {string} url - The URL
|
|
148
|
+
* @param {string} url - The destination URL
|
|
141
149
|
*/
|
|
142
150
|
redirect: (url: string) => void;
|
|
143
151
|
}
|
|
@@ -1,71 +1,95 @@
|
|
|
1
1
|
import type { AsenaWebSocketService, WSOptions } from '../server/web/websocket';
|
|
2
2
|
import type { WebSocketHandler } from 'bun';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
3
|
+
import type { WebsocketAdapterParams, WebSocketRegistry } from './types';
|
|
4
|
+
import type { ServerLogger } from '../logger';
|
|
5
|
+
import type { BaseMiddleware } from '../server/web/types';
|
|
6
|
+
import type { AsenaContext } from './AsenaContext';
|
|
6
7
|
/**
|
|
7
|
-
* Abstract class
|
|
8
|
+
* Abstract class that provides a base implementation for WebSocket adapters.
|
|
9
|
+
* Handles WebSocket connections, registration, and management.
|
|
8
10
|
*
|
|
9
|
-
* @template A -
|
|
10
|
-
* @template
|
|
11
|
+
* @template A - Type of the application instance
|
|
12
|
+
* @template R - Type of the request object
|
|
13
|
+
* @template S - Type of the response object
|
|
11
14
|
*/
|
|
12
|
-
export declare abstract class AsenaWebsocketAdapter<A,
|
|
15
|
+
export declare abstract class AsenaWebsocketAdapter<A, C extends AsenaContext<any, any>> {
|
|
16
|
+
readonly name: string;
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Registry containing WebSocket services and their configurations
|
|
19
|
+
* Structure:
|
|
20
|
+
* - Key: WebSocket namespace
|
|
21
|
+
* - Value: Object containing:
|
|
22
|
+
* - service: WebSocket service instance
|
|
23
|
+
* - middlewares: Array of middleware functions
|
|
18
24
|
* @protected
|
|
19
25
|
*/
|
|
20
|
-
protected _websockets: WebSocketRegistry
|
|
26
|
+
protected _websockets: WebSocketRegistry<C>;
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
28
|
+
* Reference to the main application instance
|
|
23
29
|
* @private
|
|
24
30
|
*/
|
|
25
31
|
private _app;
|
|
26
32
|
/**
|
|
27
|
-
*
|
|
33
|
+
* WebSocket handler instance for managing connections
|
|
28
34
|
* @private
|
|
29
35
|
*/
|
|
30
36
|
private _websocket;
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
38
|
+
* Logger instance for WebSocket-related logging
|
|
39
|
+
* @private
|
|
33
40
|
*/
|
|
34
41
|
private _logger;
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param params -
|
|
43
|
+
* Initializes a new WebSocket adapter instance
|
|
44
|
+
* @param params - Configuration parameters including app instance and logger
|
|
38
45
|
*/
|
|
39
46
|
protected constructor(params?: WebsocketAdapterParams<A>);
|
|
40
47
|
/**
|
|
41
|
-
* Registers a WebSocket
|
|
42
|
-
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param middlewares to used in upgrade function
|
|
48
|
+
* Registers a new WebSocket service with associated middlewares
|
|
49
|
+
* @param websocket - WebSocket service instance to register
|
|
50
|
+
* @param middlewares - Array of middleware functions to be executed during connection upgrade
|
|
45
51
|
*/
|
|
46
|
-
abstract registerWebSocket(websocket: AsenaWebSocketService<any>, middlewares:
|
|
52
|
+
abstract registerWebSocket(websocket: AsenaWebSocketService<any>, middlewares: BaseMiddleware<C>[]): Promise<void> | void;
|
|
47
53
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param {WSOptions} [wsOptions] - Optional WebSocket options.
|
|
54
|
+
* Configures and initializes the WebSocket server with provided options
|
|
55
|
+
* @param wsOptions - Configuration options for the WebSocket server
|
|
51
56
|
*/
|
|
52
|
-
abstract
|
|
57
|
+
abstract buildWebsocket(wsOptions?: WSOptions): Promise<void> | void;
|
|
53
58
|
/**
|
|
54
|
-
*
|
|
59
|
+
* Starts the WebSocket server on the provided HTTP/S server instance
|
|
60
|
+
* @param server - HTTP/S server instance to attach the WebSocket server to
|
|
55
61
|
*/
|
|
56
|
-
abstract
|
|
62
|
+
abstract startWebsocket(server: any): Promise<void> | void;
|
|
57
63
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param {Server} server - The server to start.
|
|
64
|
+
* Gets the application instance
|
|
61
65
|
*/
|
|
62
|
-
abstract startWebsocket(server: any): void;
|
|
63
66
|
get app(): A;
|
|
67
|
+
/**
|
|
68
|
+
* Sets the application instance
|
|
69
|
+
*/
|
|
64
70
|
set app(value: A);
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Gets the WebSocket registry
|
|
73
|
+
*/
|
|
74
|
+
protected get websockets(): WebSocketRegistry<C>;
|
|
75
|
+
/**
|
|
76
|
+
* Sets the WebSocket registry
|
|
77
|
+
*/
|
|
78
|
+
protected set websockets(value: WebSocketRegistry<C>);
|
|
79
|
+
/**
|
|
80
|
+
* Gets the WebSocket handler
|
|
81
|
+
*/
|
|
67
82
|
get websocket(): WebSocketHandler;
|
|
83
|
+
/**
|
|
84
|
+
* Sets the WebSocket handler
|
|
85
|
+
*/
|
|
68
86
|
set websocket(value: WebSocketHandler);
|
|
87
|
+
/**
|
|
88
|
+
* Gets the logger instance
|
|
89
|
+
*/
|
|
69
90
|
get logger(): ServerLogger;
|
|
91
|
+
/**
|
|
92
|
+
* Sets the logger instance
|
|
93
|
+
*/
|
|
70
94
|
set logger(value: ServerLogger);
|
|
71
95
|
}
|
|
@@ -1,61 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Abstract class
|
|
2
|
+
* Abstract class that provides a base implementation for WebSocket adapters.
|
|
3
|
+
* Handles WebSocket connections, registration, and management.
|
|
3
4
|
*
|
|
4
|
-
* @template A -
|
|
5
|
-
* @template
|
|
5
|
+
* @template A - Type of the application instance
|
|
6
|
+
* @template R - Type of the request object
|
|
7
|
+
* @template S - Type of the response object
|
|
6
8
|
*/
|
|
7
9
|
export class AsenaWebsocketAdapter {
|
|
10
|
+
name;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* Registry containing WebSocket services and their configurations
|
|
13
|
+
* Structure:
|
|
14
|
+
* - Key: WebSocket namespace
|
|
15
|
+
* - Value: Object containing:
|
|
16
|
+
* - service: WebSocket service instance
|
|
17
|
+
* - middlewares: Array of middleware functions
|
|
13
18
|
* @protected
|
|
14
19
|
*/
|
|
15
20
|
_websockets;
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
22
|
+
* Reference to the main application instance
|
|
18
23
|
* @private
|
|
19
24
|
*/
|
|
20
25
|
_app;
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
27
|
+
* WebSocket handler instance for managing connections
|
|
23
28
|
* @private
|
|
24
29
|
*/
|
|
25
30
|
_websocket;
|
|
26
31
|
/**
|
|
27
|
-
*
|
|
32
|
+
* Logger instance for WebSocket-related logging
|
|
33
|
+
* @private
|
|
28
34
|
*/
|
|
29
35
|
_logger = console;
|
|
30
36
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param params -
|
|
37
|
+
* Initializes a new WebSocket adapter instance
|
|
38
|
+
* @param params - Configuration parameters including app instance and logger
|
|
33
39
|
*/
|
|
34
40
|
constructor(params) {
|
|
35
41
|
this._app = params?.app;
|
|
36
42
|
this._logger = params?.logger;
|
|
37
43
|
}
|
|
44
|
+
// Getters and Setters with improved documentation
|
|
45
|
+
/**
|
|
46
|
+
* Gets the application instance
|
|
47
|
+
*/
|
|
38
48
|
get app() {
|
|
39
49
|
return this._app;
|
|
40
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Sets the application instance
|
|
53
|
+
*/
|
|
41
54
|
set app(value) {
|
|
42
55
|
this._app = value;
|
|
43
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the WebSocket registry
|
|
59
|
+
*/
|
|
44
60
|
get websockets() {
|
|
45
61
|
return this._websockets;
|
|
46
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Sets the WebSocket registry
|
|
65
|
+
*/
|
|
47
66
|
set websockets(value) {
|
|
48
67
|
this._websockets = value;
|
|
49
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the WebSocket handler
|
|
71
|
+
*/
|
|
50
72
|
get websocket() {
|
|
51
73
|
return this._websocket;
|
|
52
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets the WebSocket handler
|
|
77
|
+
*/
|
|
53
78
|
set websocket(value) {
|
|
54
79
|
this._websocket = value;
|
|
55
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the logger instance
|
|
83
|
+
*/
|
|
56
84
|
get logger() {
|
|
57
85
|
return this._logger;
|
|
58
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Sets the logger instance
|
|
89
|
+
*/
|
|
59
90
|
set logger(value) {
|
|
60
91
|
this._logger = value;
|
|
61
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsenaWebsocketAdapter.js","sourceRoot":"","sources":["../../../lib/adapter/AsenaWebsocketAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AsenaWebsocketAdapter.js","sourceRoot":"","sources":["../../../lib/adapter/AsenaWebsocketAdapter.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,MAAM,OAAgB,qBAAqB;IAEzB,IAAI,CAAS;IAE7B;;;;;;;;OAQG;IACO,WAAW,CAAuB;IAE5C;;;OAGG;IACK,IAAI,CAAI;IAEhB;;;OAGG;IACK,UAAU,CAAmB;IAErC;;;OAGG;IACK,OAAO,GAAiB,OAAO,CAAC;IAExC;;;OAGG;IACH,YAAsB,MAAkC;QACtD,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,MAAM,CAAC;IAChC,CAAC;IAwBD,kDAAkD;IAElD;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAW,GAAG,CAAC,KAAQ;QACrB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,IAAc,UAAU;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAc,UAAU,CAAC,KAA2B;QAClD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,SAAS,CAAC,KAAuB;QAC1C,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,MAAM,CAAC,KAAmB;QACnC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;CAEF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsenaAdapter } from '../AsenaAdapter';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import type { Server } from 'bun';
|
|
4
|
+
import type { AsenaServeOptions, RouteParams } from '../types';
|
|
5
|
+
import { type BaseMiddleware } from '../../server/web/types';
|
|
6
|
+
import type { HonoErrorHandler } from './types';
|
|
7
|
+
import { type ServerLogger } from '../../logger';
|
|
8
|
+
import type { AsenaWebsocketAdapter } from '../AsenaWebsocketAdapter';
|
|
9
|
+
import type { ValidationSchema } from './defaults';
|
|
10
|
+
import type { Context as HonoAdapterContext } from './defaults/Context';
|
|
11
|
+
export declare class HonoAdapter extends AsenaAdapter<Hono, HonoAdapterContext, ValidationSchema, AsenaWebsocketAdapter<Hono, HonoAdapterContext>> {
|
|
12
|
+
name: string;
|
|
13
|
+
app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
14
|
+
private server;
|
|
15
|
+
private options;
|
|
16
|
+
private readonly methodMap;
|
|
17
|
+
constructor(websocketAdapter: AsenaWebsocketAdapter<Hono, HonoAdapterContext>, logger?: ServerLogger);
|
|
18
|
+
use(middleware: BaseMiddleware<HonoAdapterContext>, path?: string): void;
|
|
19
|
+
registerRoute({ method, path, middleware, handler, staticServe, validator, }: RouteParams<HonoAdapterContext, ValidationSchema>): Promise<void>;
|
|
20
|
+
start(): Promise<Server>;
|
|
21
|
+
onError(errorHandler: HonoErrorHandler): void;
|
|
22
|
+
serveOptions(options: () => Promise<AsenaServeOptions> | AsenaServeOptions): Promise<void>;
|
|
23
|
+
setPort(port: number): void;
|
|
24
|
+
private prepareMiddlewares;
|
|
25
|
+
private prepareHandler;
|
|
26
|
+
private prepareValidator;
|
|
27
|
+
private normalizePath;
|
|
28
|
+
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { AsenaAdapter } from '../AsenaAdapter';
|
|
2
2
|
import { Hono } from 'hono';
|
|
3
3
|
import * as bun from 'bun';
|
|
4
|
-
import {
|
|
5
|
-
import { DefaultContextWrapper } from './DefaultContextWrapper';
|
|
4
|
+
import { HonoContextWrapper } from './HonoContextWrapper';
|
|
6
5
|
import { HttpMethod } from '../../server/web/http';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { VALIDATOR_METHODS, } from '../../server/web/types';
|
|
7
|
+
import { green, yellow } from '../../logger';
|
|
8
|
+
import { zValidator } from '@hono/zod-validator';
|
|
9
|
+
import { middlewareParser } from './utils/middlewareParser';
|
|
10
|
+
export class HonoAdapter extends AsenaAdapter {
|
|
11
|
+
name = 'HonoAdapter';
|
|
10
12
|
app = new Hono();
|
|
11
13
|
server;
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
options = {};
|
|
12
16
|
methodMap = {
|
|
13
17
|
[HttpMethod.GET]: (path, ...handlers) => this.app.get(path, ...handlers),
|
|
14
18
|
[HttpMethod.POST]: (path, ...handlers) => this.app.post(path, ...handlers),
|
|
@@ -30,63 +34,81 @@ export class DefaultAdapter extends AsenaAdapter {
|
|
|
30
34
|
}
|
|
31
35
|
use(middleware, path) {
|
|
32
36
|
const normalizedPath = path ? this.normalizePath(path) : undefined;
|
|
33
|
-
const preparedMiddlewares = this.prepareMiddlewares(middleware);
|
|
37
|
+
const preparedMiddlewares = this.prepareMiddlewares([middleware]);
|
|
34
38
|
if (normalizedPath) {
|
|
35
39
|
this.app.use(normalizedPath, ...preparedMiddlewares);
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
42
|
this.app.use(...preparedMiddlewares);
|
|
39
43
|
}
|
|
40
|
-
registerRoute({ method, path, middleware, handler, staticServe, validator, }) {
|
|
41
|
-
const middlewares =
|
|
42
|
-
const
|
|
44
|
+
async registerRoute({ method, path, middleware, handler, staticServe, validator, }) {
|
|
45
|
+
const middlewares = this.prepareMiddlewares(middleware);
|
|
46
|
+
const allMiddlewares = validator
|
|
47
|
+
? [...(await this.prepareValidator(validator)), ...middlewares]
|
|
48
|
+
: middlewares;
|
|
49
|
+
const routeHandler = staticServe ? allMiddlewares : [...allMiddlewares, this.prepareHandler(handler)];
|
|
43
50
|
const methodHandler = this.methodMap[method];
|
|
44
51
|
if (!methodHandler) {
|
|
45
52
|
throw new Error('Invalid method');
|
|
46
53
|
}
|
|
47
54
|
methodHandler(path, ...routeHandler);
|
|
48
|
-
this.logger.info(`${green('Successfully')} registered ${yellow(method.toUpperCase())} route for PATH: ${green(
|
|
55
|
+
this.logger.info(`${green('Successfully')} registered ${yellow(method.toUpperCase())} route for PATH: ${green(`${path}`)}`);
|
|
49
56
|
}
|
|
50
57
|
async start() {
|
|
51
|
-
this.websocketAdapter.buildWebsocket();
|
|
52
|
-
this.server = bun.serve({
|
|
58
|
+
this.websocketAdapter.buildWebsocket(this.options?.wsOptions);
|
|
59
|
+
this.server = bun.serve({
|
|
60
|
+
...this.options.serveOptions,
|
|
61
|
+
port: this.port,
|
|
62
|
+
fetch: this.app.fetch,
|
|
63
|
+
websocket: this.websocketAdapter.websocket,
|
|
64
|
+
});
|
|
53
65
|
this.websocketAdapter.startWebsocket(this.server);
|
|
54
66
|
return this.server;
|
|
55
67
|
}
|
|
56
|
-
prepareMiddlewares(middlewares) {
|
|
57
|
-
const _middlewares = Array.isArray(middlewares) ? middlewares : [middlewares];
|
|
58
|
-
const factory = createFactory();
|
|
59
|
-
return _middlewares.map((middleware) => {
|
|
60
|
-
if (middleware.override) {
|
|
61
|
-
return (c, next) => middleware.middlewareService.handle(c, next);
|
|
62
|
-
}
|
|
63
|
-
return factory.createMiddleware(async (context, next) => {
|
|
64
|
-
await middleware.middlewareService.handle(new DefaultContextWrapper(context), next);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
prepareHandler(handler) {
|
|
69
|
-
return (c) => handler()(new DefaultContextWrapper(c));
|
|
70
|
-
}
|
|
71
68
|
onError(errorHandler) {
|
|
72
69
|
this.app.onError((error, context) => {
|
|
73
|
-
return errorHandler(error, new
|
|
70
|
+
return errorHandler(error, new HonoContextWrapper(context));
|
|
74
71
|
});
|
|
75
72
|
}
|
|
73
|
+
async serveOptions(options) {
|
|
74
|
+
this.options = await options();
|
|
75
|
+
}
|
|
76
76
|
setPort(port) {
|
|
77
77
|
this.port = port;
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
prepareMiddlewares(middlewares) {
|
|
80
|
+
return middlewareParser(middlewares);
|
|
81
|
+
}
|
|
82
|
+
prepareHandler(handler) {
|
|
83
|
+
return (c) => handler(new HonoContextWrapper(c));
|
|
84
|
+
}
|
|
85
|
+
async prepareValidator(baseValidator) {
|
|
86
|
+
if (!baseValidator) {
|
|
81
87
|
return [];
|
|
82
88
|
}
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const validators = [];
|
|
90
|
+
for (const key of VALIDATOR_METHODS) {
|
|
91
|
+
// if the key is not a validator method, skip
|
|
92
|
+
if (typeof baseValidator[key]?.handle !== 'function') {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const validator = baseValidator[key];
|
|
96
|
+
const validationSchema = await validator.handle();
|
|
97
|
+
let schema;
|
|
98
|
+
let hook;
|
|
99
|
+
if ('schema' in validationSchema) {
|
|
100
|
+
schema = validationSchema['schema'];
|
|
101
|
+
hook = validationSchema['hook'];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
schema = validationSchema;
|
|
105
|
+
}
|
|
106
|
+
validators.push(zValidator(key, schema, hook));
|
|
107
|
+
}
|
|
108
|
+
return validators;
|
|
87
109
|
}
|
|
88
110
|
normalizePath(path) {
|
|
89
111
|
return `${path.endsWith('/') ? path : `${path}/`}*`;
|
|
90
112
|
}
|
|
91
113
|
}
|
|
92
|
-
//# sourceMappingURL=
|
|
114
|
+
//# sourceMappingURL=HonoAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HonoAdapter.js","sourceRoot":"","sources":["../../../../lib/adapter/hono/HonoAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAA8B,IAAI,EAAkD,MAAM,MAAM,CAAC;AAExG,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAGL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAqB,MAAM,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAa,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,MAAM,OAAO,WAAY,SAAQ,YAKhC;IAEQ,IAAI,GAAG,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