@asenajs/asena 0.1.16 → 0.1.18
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 +278 -5
- package/dist/lib/adapter/AsenaAdapter.d.ts +6 -0
- package/dist/lib/adapter/AsenaAdapter.js +10 -0
- package/dist/lib/adapter/AsenaAdapter.js.map +1 -1
- package/dist/lib/adapter/AsenaContext.d.ts +5 -7
- package/dist/lib/adapter/AsenaWebsocketAdapter.d.ts +39 -5
- package/dist/lib/adapter/AsenaWebsocketAdapter.js +54 -2
- package/dist/lib/adapter/AsenaWebsocketAdapter.js.map +1 -1
- package/dist/lib/adapter/defaultAdapter/DefaultAdapter.d.ts +4 -2
- package/dist/lib/adapter/defaultAdapter/DefaultAdapter.js +25 -32
- package/dist/lib/adapter/defaultAdapter/DefaultAdapter.js.map +1 -1
- package/dist/lib/adapter/defaultAdapter/DefaultWebsocketAdapter.d.ts +4 -5
- package/dist/lib/adapter/defaultAdapter/DefaultWebsocketAdapter.js +23 -22
- package/dist/lib/adapter/defaultAdapter/DefaultWebsocketAdapter.js.map +1 -1
- package/dist/lib/adapter/types/WebSocketRegistry.d.ts +7 -0
- package/dist/lib/adapter/types/WebSocketRegistry.js +2 -0
- package/dist/lib/adapter/types/WebSocketRegistry.js.map +1 -0
- package/dist/lib/adapter/types/WebsocketAdapterParams.d.ts +11 -0
- package/dist/lib/adapter/types/WebsocketAdapterParams.js +2 -0
- package/dist/lib/adapter/types/WebsocketAdapterParams.js.map +1 -0
- package/dist/lib/adapter/types/index.d.ts +2 -0
- package/dist/lib/adapter/types/index.js +2 -0
- package/dist/lib/adapter/types/index.js.map +1 -1
- package/dist/lib/ioc/Container.js +2 -16
- package/dist/lib/ioc/Container.js.map +1 -1
- package/dist/lib/ioc/IocEngine.js +16 -4
- package/dist/lib/ioc/IocEngine.js.map +1 -1
- package/dist/lib/server/AsenaServer.d.ts +1 -1
- package/dist/lib/server/AsenaServer.js +14 -9
- package/dist/lib/server/AsenaServer.js.map +1 -1
- package/dist/lib/server/web/types/ApiHandler.d.ts +1 -2
- package/dist/lib/server/web/websocket/AsenaSocket.d.ts +1 -0
- package/dist/lib/server/web/websocket/AsenaSocket.js +6 -3
- package/dist/lib/server/web/websocket/AsenaSocket.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaWebSocketService.js +1 -0
- package/dist/lib/server/web/websocket/AsenaWebSocketService.js.map +1 -1
- package/dist/lib/services/logger/DefaultLogger.d.ts +1 -0
- package/dist/lib/services/logger/DefaultLogger.js +3 -0
- package/dist/lib/services/logger/DefaultLogger.js.map +1 -1
- package/dist/lib/services/types/Logger.d.ts +5 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,13 +1,286 @@
|
|
|
1
1
|
# Asena
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Asena is a NestJS-like IoC web framework built on top of Hono and Bun. It combines the power of dependency injection
|
|
4
|
+
with the performance of Bun runtime and the flexibility of Hono web framework.
|
|
4
5
|
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
For detailed documentation, please visit [not ready yet](https://asena.sh). Documentation is still in progress, but updates are being made regularly.
|
|
9
|
+
|
|
10
|
+
## Key Features
|
|
11
|
+
|
|
12
|
+
- **Dependency Injection**: Built-in IoC container for managing dependencies
|
|
13
|
+
- **Decorator-based Development**: Similar to NestJS, using TypeScript decorators for routing and DI
|
|
14
|
+
- **High Performance**: Leverages Bun runtime for optimal performance
|
|
15
|
+
- **WebSocket Support**: Built-in WebSocket handling capabilities
|
|
16
|
+
- **Middleware System**: Flexible middleware architecture
|
|
17
|
+
- **HTTP Adapters**: Extensible adapter system with Hono as default
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
First, create a new project using Bun:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun init
|
|
25
|
+
````
|
|
26
|
+
|
|
27
|
+
For decorators working properly, you need to add some settings to your tsconfig. Here is an recommended file:
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"compilerOptions": {
|
|
31
|
+
// Enable latest features
|
|
32
|
+
"lib": ["ESNext", "DOM"],
|
|
33
|
+
"target": "ESNext",
|
|
34
|
+
"module": "ESNext",
|
|
35
|
+
"moduleDetection": "force",
|
|
36
|
+
"jsx": "react-jsx",
|
|
37
|
+
"allowJs": true,
|
|
38
|
+
"experimentalDecorators": true,
|
|
39
|
+
"emitDecoratorMetadata": true,
|
|
40
|
+
|
|
41
|
+
// Bundler mode
|
|
42
|
+
"moduleResolution": "bundler",
|
|
43
|
+
"allowImportingTsExtensions": true,
|
|
44
|
+
"verbatimModuleSyntax": true,
|
|
45
|
+
"noEmit": true,
|
|
46
|
+
|
|
47
|
+
// Best practices
|
|
48
|
+
"strict": false,
|
|
49
|
+
"skipLibCheck": true,
|
|
50
|
+
"noFallthroughCasesInSwitch": true,
|
|
51
|
+
|
|
52
|
+
// Some stricter flags
|
|
53
|
+
"noUnusedLocals": true,
|
|
54
|
+
"noUnusedParameters": true,
|
|
55
|
+
"noPropertyAccessFromIndexSignature": true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Then, install the required packages:
|
|
62
|
+
```bash
|
|
63
|
+
|
|
64
|
+
bun add @asenajs/asena hono winston
|
|
65
|
+
```
|
|
66
|
+
Add @asenajs/asena-cli to your package. This package provides a CLI for creating and managing Asena projects.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bun add -D @asenajs/asena-cli
|
|
70
|
+
````
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
Then, create a new .asenarc.json file using the CLI:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
|
|
77
|
+
## Creates a .asenarc.json file with default values (requires manual updates). Source folder is 'src'.
|
|
78
|
+
asena init
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`Note`: Built options directly copy of bun options, you can check bun documentation for more
|
|
82
|
+
options. [Bun Documentation](https://bun.sh/docs/bundler#reference)
|
|
83
|
+
|
|
84
|
+
Create index.ts file under your src folder:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// src/index.ts
|
|
88
|
+
import {AsenaServer, DefaultLogger} from "@asenajs/asena";
|
|
89
|
+
|
|
90
|
+
await new AsenaServer().logger(new DefaultLogger()).port(3000).start();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To run asena you need at least one controller. Create a new controller:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// src/controllers/TestController.ts
|
|
97
|
+
import {type Context, Controller, Get} from "@asenajs/asena";
|
|
98
|
+
|
|
99
|
+
@Controller("/hello")
|
|
100
|
+
export class TestController {
|
|
101
|
+
|
|
102
|
+
@Get("/world")
|
|
103
|
+
public async getHello(context: Context) {
|
|
104
|
+
return context.send("Hello World");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Finally, run the project:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
|
|
113
|
+
## only for fast developing purposes
|
|
114
|
+
asena dev start
|
|
115
|
+
````
|
|
116
|
+
```bash
|
|
117
|
+
## or you can simply build then run your bundled project
|
|
118
|
+
asena build
|
|
119
|
+
## then go to dist folder and run the project this way it will consume less memory
|
|
120
|
+
bun index.asena.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Example
|
|
124
|
+
|
|
125
|
+
Here is a simple example of a controller with service and middleware:
|
|
126
|
+
|
|
127
|
+
### Middleware
|
|
128
|
+
This middleware sets a value to the context object.
|
|
129
|
+
```typescript
|
|
130
|
+
// src/middleware/TestMiddleware.ts
|
|
131
|
+
import {type Context, Middleware, MiddlewareService} from "@asenajs/asena";
|
|
132
|
+
|
|
133
|
+
@Middleware()
|
|
134
|
+
export class TestMiddleware extends MiddlewareService {
|
|
135
|
+
|
|
136
|
+
public handle(context: Context, next: Function) {
|
|
137
|
+
context.setValue("testValue", "test");
|
|
138
|
+
|
|
139
|
+
next();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Service
|
|
145
|
+
Basic service with a getter and setter.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import {Service} from "@asenajs/asena";
|
|
149
|
+
|
|
150
|
+
@Service()
|
|
151
|
+
export class HelloService {
|
|
152
|
+
|
|
153
|
+
private _foo: string = "bar";
|
|
154
|
+
|
|
155
|
+
public get foo(): string {
|
|
156
|
+
return this._foo;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public set foo(value: string) {
|
|
160
|
+
this._foo = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Controller
|
|
167
|
+
Controller with a GET route that uses the middleware and service.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// src/controller/TestController.ts
|
|
171
|
+
import {type Context, Controller, Get, Inject} from "@asenajs/asena";
|
|
172
|
+
import {HelloService} from "../service/HelloService.ts";
|
|
173
|
+
import {TestMiddleware} from "../middleware/TestMiddleware.ts";
|
|
174
|
+
|
|
175
|
+
@Controller("/v1")
|
|
176
|
+
export class TestController {
|
|
177
|
+
|
|
178
|
+
@Inject(HelloService)
|
|
179
|
+
private helloService: HelloService
|
|
180
|
+
|
|
181
|
+
@Get("foo")
|
|
182
|
+
public async getFoo(context: Context) {
|
|
183
|
+
return context.send(this.helloService.foo);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@Get({path: "world", middlewares: [TestMiddleware]})
|
|
187
|
+
public async getHello(context: Context) {
|
|
188
|
+
const testValue: string = context.getValue("testValue");
|
|
189
|
+
|
|
190
|
+
return context.send(testValue);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Index
|
|
196
|
+
The main file that starts the server.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
// src/index.ts
|
|
200
|
+
import {AsenaServer, DefaultLogger} from "@asenajs/asena";
|
|
201
|
+
|
|
202
|
+
await new AsenaServer().logger(new DefaultLogger()).port(3000).start();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
then run
|
|
5
206
|
```bash
|
|
207
|
+
asena dev start
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
You should see the following output:
|
|
211
|
+
```text
|
|
6
212
|
|
|
7
|
-
|
|
213
|
+
Build completed successfully.
|
|
214
|
+
2024-11-19 17:58:35 [info]:
|
|
215
|
+
___ _____ ______ _ __ ___
|
|
216
|
+
/ | / ___/ / ____// | / // |
|
|
217
|
+
/ /| | \__ \ / __/ / |/ // /| |
|
|
218
|
+
/ ___ | ___/ // /___ / /| // ___ |
|
|
219
|
+
/_/ |_|/____//_____//_/ |_//_/ |_|
|
|
220
|
+
|
|
221
|
+
2024-11-19 17:58:35 [info]: IoC initialized
|
|
222
|
+
2024-11-19 17:58:35 [info]: No server services found
|
|
223
|
+
2024-11-19 17:58:35 [info]: Controller: V1 found
|
|
224
|
+
2024-11-19 17:58:35 [info]: Successfully registered GET route for PATH: /v1/foo
|
|
225
|
+
2024-11-19 17:58:35 [info]: Successfully registered GET route for PATH: /v1/world
|
|
226
|
+
2024-11-19 17:58:35 [info]: No websockets found
|
|
227
|
+
2024-11-19 17:58:35 [info]: Server started on port 3000
|
|
8
228
|
```
|
|
9
229
|
|
|
10
|
-
|
|
230
|
+
and you see the result on your browser [http://localhost:3000/v1/foo](http://localhost:3000/v1/foo) with "bar" message.
|
|
231
|
+
|
|
232
|
+
`Note`: For more example, you can check this project [Example](https://github.com/LibirSoft/AsenaExample).
|
|
233
|
+
|
|
234
|
+
## Core Concepts
|
|
235
|
+
|
|
236
|
+
- **Controllers**: Handle incoming requests using decorators
|
|
237
|
+
- **Services**: Business logic containers that can be injected
|
|
238
|
+
- **ServerSrvices**: Server-wide services that can be injected (e.g. Database)
|
|
239
|
+
- **Middleware**: Request/Response interceptors
|
|
240
|
+
- **Adapters**: Framework adapters (default: Hono)
|
|
241
|
+
- **WebSocket**: Real-time communication support
|
|
242
|
+
- **Validators**: Request validation system
|
|
243
|
+
|
|
244
|
+
## Architecture
|
|
245
|
+
|
|
246
|
+
Asena follows a modular architecture with:
|
|
247
|
+
|
|
248
|
+
- IoC Container for dependency management
|
|
249
|
+
- Adapter pattern for framework integration
|
|
250
|
+
- Decorator-based routing system
|
|
251
|
+
- Middleware pipeline
|
|
252
|
+
- WebSocket integration
|
|
253
|
+
- Context management
|
|
254
|
+
|
|
255
|
+
## Performance
|
|
256
|
+
|
|
257
|
+
Built on Bun runtime and Hono, Asena provides:
|
|
258
|
+
|
|
259
|
+
- Fast startup time
|
|
260
|
+
- Low memory footprint
|
|
261
|
+
- Quick request processing
|
|
262
|
+
- Efficient WebSocket handling
|
|
263
|
+
|
|
264
|
+
and here is the benchmark result of Asena with Hono adapter(Basic hello world example) in every test we used bun to run
|
|
265
|
+
the project:
|
|
266
|
+
|
|
267
|
+
### Performance Comparison (Fastest to Slowest)
|
|
268
|
+
|
|
269
|
+
| Framework | Requests/sec | Latency (avg) | Transfer/sec |
|
|
270
|
+
|--------------------------------------|--------------|---------------|--------------|
|
|
271
|
+
| Hono | 147,031.08 | 2.69ms | 18.09MB |
|
|
272
|
+
| Asena | 137,148.80 | 2.89ms | 16.74MB |
|
|
273
|
+
| NestJS (Bun + Fastify) | 81,652.05 | 6.01ms | 13.78MB |
|
|
274
|
+
| NestJS (Bun) | 64,435.83 | 6.14ms | 11.80MB |
|
|
275
|
+
| NestJS (Bun + kiyasov/platform-hono) | 45,082.27 | 8.79ms | 5.55MB |
|
|
276
|
+
| NestJS (Node) | 17,649.89 | 24.43ms | 4.02MB |
|
|
277
|
+
|
|
278
|
+
> Benchmark conditions:
|
|
279
|
+
>
|
|
280
|
+
> - 12 threads
|
|
281
|
+
> - 400 connections
|
|
282
|
+
> - 120 seconds duration
|
|
283
|
+
> - Simple "Hello World" endpoint
|
|
284
|
+
> - Running on same hardware
|
|
11
285
|
|
|
12
|
-
|
|
13
|
-
Asena still under development. Documents will be added soon...
|
|
286
|
+
_Note: Lower latency and higher requests/sec indicate better performance_
|
|
@@ -3,6 +3,7 @@ import type { BaseMiddleware } from '../server/web/types';
|
|
|
3
3
|
import type { ValidatorClass } from '../server/types';
|
|
4
4
|
import type { Server } from 'bun';
|
|
5
5
|
import type { AsenaWebsocketAdapter } from './AsenaWebsocketAdapter';
|
|
6
|
+
import type { ServerLogger } from '../services';
|
|
6
7
|
/**
|
|
7
8
|
* Abstract class representing an adapter for the Asena framework.
|
|
8
9
|
*
|
|
@@ -27,6 +28,11 @@ export declare abstract class AsenaAdapter<A = unknown, H = unknown, AM = unknow
|
|
|
27
28
|
* The port number.
|
|
28
29
|
*/
|
|
29
30
|
protected port: number;
|
|
31
|
+
/**
|
|
32
|
+
* The logger instance.
|
|
33
|
+
*/
|
|
34
|
+
protected logger: ServerLogger;
|
|
35
|
+
protected constructor(websocketAdapter: WSA, logger?: ServerLogger);
|
|
30
36
|
/**
|
|
31
37
|
* Sets the port number.
|
|
32
38
|
*
|
|
@@ -22,5 +22,15 @@ export class AsenaAdapter {
|
|
|
22
22
|
* The port number.
|
|
23
23
|
*/
|
|
24
24
|
port;
|
|
25
|
+
/**
|
|
26
|
+
* The logger instance.
|
|
27
|
+
*/
|
|
28
|
+
logger = console;
|
|
29
|
+
constructor(websocketAdapter, logger) {
|
|
30
|
+
this.websocketAdapter = websocketAdapter;
|
|
31
|
+
if (logger) {
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
//# sourceMappingURL=AsenaAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsenaAdapter.js","sourceRoot":"","sources":["../../../lib/adapter/AsenaAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AsenaAdapter.js","sourceRoot":"","sources":["../../../lib/adapter/AsenaAdapter.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,YAAY;IAUhC;;OAEG;IACI,GAAG,CAAI;IAEd;;OAEG;IACI,gBAAgB,CAAM;IAE7B;;OAEG;IACO,IAAI,CAAS;IAEvB;;OAEG;IACO,MAAM,GAAiB,OAAO,CAAC;IAEzC,YAAsB,gBAAqB,EAAE,MAAqB;QAChE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC;IACH,CAAC;CA8DF"}
|
|
@@ -1,6 +1,4 @@
|
|
|
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
|
* Interface representing the context for Asena.
|
|
6
4
|
*
|
|
@@ -123,17 +121,17 @@ export interface AsenaContext<R, S> {
|
|
|
123
121
|
* Sends an HTML response.
|
|
124
122
|
*
|
|
125
123
|
* @param {string} data - The HTML data to send.
|
|
126
|
-
* @returns {Response | Promise<Response>
|
|
124
|
+
* @returns {Response | Promise<Response> } The response object.
|
|
127
125
|
*/
|
|
128
|
-
html: (data: string) => Response | Promise<Response
|
|
126
|
+
html: (data: string) => Response | Promise<Response>;
|
|
129
127
|
/**
|
|
130
128
|
* Sends a response.
|
|
131
129
|
*
|
|
132
130
|
* @param {string | any} data - The data to send.
|
|
133
131
|
* @param {SendOptions | number} [status] - Optional status code or send options.
|
|
134
|
-
* @returns {Response | Promise<Response>
|
|
132
|
+
* @returns {Response | Promise<Response>} The response object.
|
|
135
133
|
*/
|
|
136
|
-
send: (data: string | any, status?: SendOptions | number) => Response | Promise<Response
|
|
134
|
+
send: (data: string | any, status?: SendOptions | number) => Response | Promise<Response>;
|
|
137
135
|
/**
|
|
138
136
|
* Redirects the request to a new URL.
|
|
139
137
|
*
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { AsenaWebSocketService, WSOptions } from '../server/web/websocket';
|
|
2
|
+
import type { WebSocketHandler } from 'bun';
|
|
3
|
+
import type { ServerLogger } from '../services';
|
|
4
|
+
import type { WebsocketAdapterParams } from './types';
|
|
5
|
+
import type { WebSocketRegistry } from './types';
|
|
2
6
|
/**
|
|
3
7
|
* Abstract class representing a WebSocket adapter.
|
|
4
8
|
*
|
|
@@ -6,11 +10,33 @@ import type { AsenaWebSocketService, WSOptions } from '../server/web/websocket';
|
|
|
6
10
|
* @template AM - The type of the message.
|
|
7
11
|
*/
|
|
8
12
|
export declare abstract class AsenaWebsocketAdapter<A, MH> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The WebSocket services.
|
|
15
|
+
* @ string - The namespace of the WebSocket.
|
|
16
|
+
* @ AsenaWebSocketService<any> - The WebSocket service.
|
|
17
|
+
* @ MH[] - The middlewares to use.
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
protected _websockets: WebSocketRegistry;
|
|
21
|
+
/**
|
|
22
|
+
* The application instance.
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private _app;
|
|
26
|
+
/**
|
|
27
|
+
* The WebSocket handler.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
private _websocket;
|
|
31
|
+
/**
|
|
32
|
+
* The logger instance.
|
|
33
|
+
*/
|
|
34
|
+
private _logger;
|
|
35
|
+
/**
|
|
36
|
+
* Constructor for the AsenaWebSocketAdapter class.
|
|
37
|
+
* @param params - The parameters for the constructor.
|
|
38
|
+
*/
|
|
39
|
+
protected constructor(params?: WebsocketAdapterParams<A>);
|
|
14
40
|
/**
|
|
15
41
|
* Registers a WebSocket handler.
|
|
16
42
|
*
|
|
@@ -34,4 +60,12 @@ export declare abstract class AsenaWebsocketAdapter<A, MH> {
|
|
|
34
60
|
* @param {Server} server - The server to start.
|
|
35
61
|
*/
|
|
36
62
|
abstract startWebsocket(server: any): void;
|
|
63
|
+
get app(): A;
|
|
64
|
+
set app(value: A);
|
|
65
|
+
protected get websockets(): WebSocketRegistry;
|
|
66
|
+
protected set websockets(value: WebSocketRegistry);
|
|
67
|
+
get websocket(): WebSocketHandler;
|
|
68
|
+
set websocket(value: WebSocketHandler);
|
|
69
|
+
get logger(): ServerLogger;
|
|
70
|
+
set logger(value: ServerLogger);
|
|
37
71
|
}
|
|
@@ -5,7 +5,59 @@
|
|
|
5
5
|
* @template AM - The type of the message.
|
|
6
6
|
*/
|
|
7
7
|
export class AsenaWebsocketAdapter {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The WebSocket services.
|
|
10
|
+
* @ string - The namespace of the WebSocket.
|
|
11
|
+
* @ AsenaWebSocketService<any> - The WebSocket service.
|
|
12
|
+
* @ MH[] - The middlewares to use.
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
_websockets;
|
|
16
|
+
/**
|
|
17
|
+
* The application instance.
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
_app;
|
|
21
|
+
/**
|
|
22
|
+
* The WebSocket handler.
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
_websocket;
|
|
26
|
+
/**
|
|
27
|
+
* The logger instance.
|
|
28
|
+
*/
|
|
29
|
+
_logger = console;
|
|
30
|
+
/**
|
|
31
|
+
* Constructor for the AsenaWebSocketAdapter class.
|
|
32
|
+
* @param params - The parameters for the constructor.
|
|
33
|
+
*/
|
|
34
|
+
constructor(params) {
|
|
35
|
+
this._app = params?.app;
|
|
36
|
+
this._logger = params?.logger;
|
|
37
|
+
}
|
|
38
|
+
get app() {
|
|
39
|
+
return this._app;
|
|
40
|
+
}
|
|
41
|
+
set app(value) {
|
|
42
|
+
this._app = value;
|
|
43
|
+
}
|
|
44
|
+
get websockets() {
|
|
45
|
+
return this._websockets;
|
|
46
|
+
}
|
|
47
|
+
set websockets(value) {
|
|
48
|
+
this._websockets = value;
|
|
49
|
+
}
|
|
50
|
+
get websocket() {
|
|
51
|
+
return this._websocket;
|
|
52
|
+
}
|
|
53
|
+
set websocket(value) {
|
|
54
|
+
this._websocket = value;
|
|
55
|
+
}
|
|
56
|
+
get logger() {
|
|
57
|
+
return this._logger;
|
|
58
|
+
}
|
|
59
|
+
set logger(value) {
|
|
60
|
+
this._logger = value;
|
|
61
|
+
}
|
|
10
62
|
}
|
|
11
63
|
//# sourceMappingURL=AsenaWebsocketAdapter.js.map
|
|
@@ -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":"AAMA;;;;;GAKG;AACH,MAAM,OAAgB,qBAAqB;IAEzC;;;;;;OAMG;IACO,WAAW,CAAoB;IAEzC;;;OAGG;IACK,IAAI,CAAI;IAEhB;;;OAGG;IACK,UAAU,CAAmB;IAErC;;OAEG;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;IA6BD,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAW,GAAG,CAAC,KAAQ;QACrB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,IAAc,UAAU;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAc,UAAU,CAAC,KAAwB;QAC/C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAW,SAAS,CAAC,KAAuB;QAC1C,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAW,MAAM,CAAC,KAAmB;QACnC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;CAEF"}
|
|
@@ -6,12 +6,14 @@ import type { H } from 'hono/types';
|
|
|
6
6
|
import type { BaseMiddleware } from '../../server/web/types';
|
|
7
7
|
import type { ErrorHandler, Handler } from './types';
|
|
8
8
|
import type { ValidatorClass } from '../../server/types';
|
|
9
|
-
import {
|
|
9
|
+
import { type ServerLogger } from '../../services';
|
|
10
|
+
import type { AsenaWebsocketAdapter } from '../AsenaWebsocketAdapter';
|
|
10
11
|
export declare class DefaultAdapter extends AsenaAdapter<Hono, Handler, MiddlewareHandler, H> {
|
|
11
12
|
private static readonly VALIDATOR_METHODS;
|
|
12
13
|
app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
13
|
-
websocketAdapter: DefaultWebsocketAdapter;
|
|
14
14
|
private server;
|
|
15
|
+
private readonly methodMap;
|
|
16
|
+
constructor(websocketAdapter: AsenaWebsocketAdapter<any, any>, logger?: ServerLogger);
|
|
15
17
|
use(middleware: BaseMiddleware<HonoRequest, Response>, path?: string): void;
|
|
16
18
|
registerRoute({ method, path, middleware, handler, staticServe, validator, }: RouteParams<MiddlewareHandler, H>): void;
|
|
17
19
|
start(): Promise<Server>;
|
|
@@ -4,12 +4,30 @@ import * as bun from 'bun';
|
|
|
4
4
|
import { createFactory } from 'hono/factory';
|
|
5
5
|
import { DefaultContextWrapper } from './DefaultContextWrapper';
|
|
6
6
|
import { HttpMethod } from '../../server/web/http';
|
|
7
|
-
import {
|
|
7
|
+
import { green, yellow } from '../../services';
|
|
8
8
|
export class DefaultAdapter extends AsenaAdapter {
|
|
9
9
|
static VALIDATOR_METHODS = ['json', 'query', 'form', 'param', 'header'];
|
|
10
10
|
app = new Hono();
|
|
11
|
-
websocketAdapter = new DefaultWebsocketAdapter(this.app);
|
|
12
11
|
server;
|
|
12
|
+
methodMap = {
|
|
13
|
+
[HttpMethod.GET]: (path, ...handlers) => this.app.get(path, ...handlers),
|
|
14
|
+
[HttpMethod.POST]: (path, ...handlers) => this.app.post(path, ...handlers),
|
|
15
|
+
[HttpMethod.PUT]: (path, ...handlers) => this.app.put(path, ...handlers),
|
|
16
|
+
[HttpMethod.DELETE]: (path, ...handlers) => this.app.delete(path, ...handlers),
|
|
17
|
+
[HttpMethod.PATCH]: (path, ...handlers) => this.app.patch(path, ...handlers),
|
|
18
|
+
[HttpMethod.OPTIONS]: (path, ...handlers) => this.app.options(path, ...handlers),
|
|
19
|
+
[HttpMethod.CONNECT]: (path, ...handlers) => this.app.on(HttpMethod.CONNECT.toUpperCase(), path, ...handlers),
|
|
20
|
+
[HttpMethod.HEAD]: (path, ...handlers) => this.app.on(HttpMethod.HEAD.toUpperCase(), path, ...handlers),
|
|
21
|
+
[HttpMethod.TRACE]: (path, ...handlers) => this.app.on(HttpMethod.TRACE.toUpperCase(), path, ...handlers),
|
|
22
|
+
};
|
|
23
|
+
constructor(websocketAdapter, logger) {
|
|
24
|
+
super(websocketAdapter, logger);
|
|
25
|
+
this.websocketAdapter.app = this.app;
|
|
26
|
+
// to ensure that the logger is set
|
|
27
|
+
if (!this.websocketAdapter.logger && logger) {
|
|
28
|
+
this.websocketAdapter.logger = this.logger;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
13
31
|
use(middleware, path) {
|
|
14
32
|
const normalizedPath = path ? this.normalizePath(path) : undefined;
|
|
15
33
|
const preparedMiddlewares = this.prepareMiddlewares(middleware);
|
|
@@ -22,37 +40,12 @@ export class DefaultAdapter extends AsenaAdapter {
|
|
|
22
40
|
registerRoute({ method, path, middleware, handler, staticServe, validator, }) {
|
|
23
41
|
const middlewares = validator ? [...validator, ...middleware] : middleware;
|
|
24
42
|
const routeHandler = staticServe ? middleware : [...middlewares, handler];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
break;
|
|
29
|
-
case HttpMethod.POST:
|
|
30
|
-
this.app.post(path, ...routeHandler);
|
|
31
|
-
break;
|
|
32
|
-
case HttpMethod.PUT:
|
|
33
|
-
this.app.put(path, ...routeHandler);
|
|
34
|
-
break;
|
|
35
|
-
case HttpMethod.DELETE:
|
|
36
|
-
this.app.delete(path, ...routeHandler);
|
|
37
|
-
break;
|
|
38
|
-
case HttpMethod.PATCH:
|
|
39
|
-
this.app.patch(path, ...routeHandler);
|
|
40
|
-
break;
|
|
41
|
-
case HttpMethod.OPTIONS:
|
|
42
|
-
this.app.options(path, ...routeHandler);
|
|
43
|
-
break;
|
|
44
|
-
case HttpMethod.CONNECT:
|
|
45
|
-
this.app.on(HttpMethod.CONNECT.toUpperCase(), path, ...routeHandler);
|
|
46
|
-
break;
|
|
47
|
-
case HttpMethod.HEAD:
|
|
48
|
-
this.app.on(HttpMethod.HEAD.toUpperCase(), path, ...routeHandler);
|
|
49
|
-
break;
|
|
50
|
-
case HttpMethod.TRACE:
|
|
51
|
-
this.app.on(HttpMethod.TRACE.toUpperCase(), path, ...routeHandler);
|
|
52
|
-
break;
|
|
53
|
-
default:
|
|
54
|
-
throw new Error('Invalid method');
|
|
43
|
+
const methodHandler = this.methodMap[method];
|
|
44
|
+
if (!methodHandler) {
|
|
45
|
+
throw new Error('Invalid method');
|
|
55
46
|
}
|
|
47
|
+
methodHandler(path, ...routeHandler);
|
|
48
|
+
this.logger.info(`${green('Successfully')} registered ${yellow(method.toUpperCase())} route for PATH: ${green(`/${path}`)}`);
|
|
56
49
|
}
|
|
57
50
|
async start() {
|
|
58
51
|
this.websocketAdapter.buildWebsocket();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultAdapter.js","sourceRoot":"","sources":["../../../../lib/adapter/defaultAdapter/DefaultAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAgB,IAAI,EAAuD,MAAM,MAAM,CAAC;AAE/F,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"DefaultAdapter.js","sourceRoot":"","sources":["../../../../lib/adapter/defaultAdapter/DefaultAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAgB,IAAI,EAAuD,MAAM,MAAM,CAAC;AAE/F,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD,OAAO,EAAE,KAAK,EAAqB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGlE,MAAM,OAAO,cAAe,SAAQ,YAAiD;IAE3E,MAAM,CAAU,iBAAiB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;IAE3F,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEhB,MAAM,CAAS;IAEN,SAAS,GAAG;QAC3B,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,IAAY,EAAE,GAAG,QAAe,EAAE,EAAE,CAAC,IAAI,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;QAChC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;IACtD,CAAC"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { type AsenaWebSocketService, type WSOptions } from '../../server/web/websocket';
|
|
2
2
|
import { AsenaWebsocketAdapter } from '../AsenaWebsocketAdapter';
|
|
3
3
|
import type { Hono, MiddlewareHandler } from 'hono';
|
|
4
|
-
import type { Server
|
|
4
|
+
import type { Server } from 'bun';
|
|
5
|
+
import type { WebsocketAdapterParams } from '../types';
|
|
5
6
|
export declare class DefaultWebsocketAdapter extends AsenaWebsocketAdapter<Hono, MiddlewareHandler> {
|
|
6
|
-
private _websocket;
|
|
7
7
|
private _server;
|
|
8
|
-
constructor(
|
|
9
|
-
registerWebSocket(
|
|
8
|
+
constructor(params?: WebsocketAdapterParams<Hono>);
|
|
9
|
+
registerWebSocket(webSocketService: AsenaWebSocketService<any>, middlewares: MiddlewareHandler[]): void;
|
|
10
10
|
prepareWebSocket(options?: WSOptions): void;
|
|
11
11
|
buildWebsocket(): void;
|
|
12
12
|
startWebsocket(server: Server): void;
|
|
13
13
|
private upgradeWebSocket;
|
|
14
14
|
private createHandler;
|
|
15
|
-
get websocket(): WebSocketHandler;
|
|
16
15
|
}
|