@asenajs/asena 0.6.3 → 0.7.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.
- package/README.md +2 -2
- package/dist/lib/adapter/AsenaAdapter.d.ts +17 -0
- package/dist/lib/adapter/AsenaAdapter.js +6 -0
- package/dist/lib/adapter/AsenaAdapter.js.map +1 -1
- package/dist/lib/adapter/AsenaContext.d.ts +81 -8
- package/dist/lib/adapter/AsenaWebsocketAdapter.d.ts +41 -2
- package/dist/lib/adapter/AsenaWebsocketAdapter.js +74 -0
- package/dist/lib/adapter/AsenaWebsocketAdapter.js.map +1 -1
- package/dist/lib/adapter/types/ApiParams.d.ts +6 -0
- package/dist/lib/adapter/types/Streaming.d.ts +42 -0
- package/dist/lib/adapter/types/Streaming.js +2 -0
- package/dist/lib/adapter/types/Streaming.js.map +1 -0
- package/dist/lib/adapter/types/index.d.ts +1 -0
- package/dist/lib/adapter/types/index.js +1 -0
- package/dist/lib/adapter/types/index.js.map +1 -1
- package/dist/lib/ioc/Container.d.ts +8 -1
- package/dist/lib/ioc/Container.js +16 -2
- package/dist/lib/ioc/Container.js.map +1 -1
- package/dist/lib/ioc/CoreContainer.js +10 -3
- package/dist/lib/ioc/CoreContainer.js.map +1 -1
- package/dist/lib/ioc/IocEngine.d.ts +7 -0
- package/dist/lib/ioc/IocEngine.js +85 -3
- package/dist/lib/ioc/IocEngine.js.map +1 -1
- package/dist/lib/ioc/component/componentUtils.js +3 -1
- package/dist/lib/ioc/component/componentUtils.js.map +1 -1
- package/dist/lib/ioc/constants/ComponentConstants.d.ts +2 -0
- package/dist/lib/ioc/constants/ComponentConstants.js +3 -0
- package/dist/lib/ioc/constants/ComponentConstants.js.map +1 -1
- package/dist/lib/ioc/helper/cronParser.d.ts +3 -0
- package/dist/lib/ioc/helper/cronParser.js +3 -1
- package/dist/lib/ioc/helper/cronParser.js.map +1 -1
- package/dist/lib/ioc/types/ComponentPostProcessor.d.ts +30 -0
- package/dist/lib/ioc/types/ComponentPostProcessor.js +2 -0
- package/dist/lib/ioc/types/ComponentPostProcessor.js.map +1 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.d.ts +3 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js +4 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js.map +1 -1
- package/dist/lib/ioc/types/decorators/ComponentType.d.ts +3 -1
- package/dist/lib/ioc/types/decorators/ComponentType.js +2 -0
- package/dist/lib/ioc/types/decorators/ComponentType.js.map +1 -1
- package/dist/lib/ioc/types/decorators/ControllerParams.d.ts +1 -0
- package/dist/lib/ioc/types/index.d.ts +1 -0
- package/dist/lib/ioc/types/index.js +1 -0
- package/dist/lib/ioc/types/index.js.map +1 -1
- package/dist/lib/server/AsenaServer.d.ts +18 -0
- package/dist/lib/server/AsenaServer.js +85 -1
- package/dist/lib/server/AsenaServer.js.map +1 -1
- package/dist/lib/server/config/AsenaConfig.d.ts +16 -1
- package/dist/lib/server/decorators/components/Controller.js +3 -0
- package/dist/lib/server/decorators/components/Controller.js.map +1 -1
- package/dist/lib/server/decorators/components/FrontendController.d.ts +15 -0
- package/dist/lib/server/decorators/components/FrontendController.js +20 -0
- package/dist/lib/server/decorators/components/FrontendController.js.map +1 -0
- package/dist/lib/server/decorators/components/PostProcessor.d.ts +25 -0
- package/dist/lib/server/decorators/components/PostProcessor.js +29 -0
- package/dist/lib/server/decorators/components/PostProcessor.js.map +1 -0
- package/dist/lib/server/decorators/components/Schedule.d.ts +15 -3
- package/dist/lib/server/decorators/components/Schedule.js +24 -6
- package/dist/lib/server/decorators/components/Schedule.js.map +1 -1
- package/dist/lib/server/decorators/components/index.d.ts +2 -0
- package/dist/lib/server/decorators/components/index.js +2 -0
- package/dist/lib/server/decorators/components/index.js.map +1 -1
- package/dist/lib/server/decorators/index.d.ts +0 -3
- package/dist/lib/server/decorators/index.js +0 -3
- package/dist/lib/server/decorators/index.js.map +1 -1
- package/dist/lib/server/messaging/Ulak.js +8 -5
- package/dist/lib/server/messaging/Ulak.js.map +1 -1
- package/dist/lib/server/schedule/AsenaSchedule.d.ts +21 -0
- package/dist/lib/server/schedule/AsenaSchedule.js +2 -0
- package/dist/lib/server/schedule/AsenaSchedule.js.map +1 -0
- package/dist/lib/server/schedule/CronRunner.d.ts +54 -0
- package/dist/lib/server/schedule/CronRunner.js +130 -0
- package/dist/lib/server/schedule/CronRunner.js.map +1 -0
- package/dist/lib/server/schedule/index.d.ts +2 -0
- package/dist/lib/server/schedule/index.js +2 -0
- package/dist/lib/server/schedule/index.js.map +1 -0
- package/dist/lib/server/src/services/PrepareFrontendControllerService.d.ts +17 -0
- package/dist/lib/server/src/services/PrepareFrontendControllerService.js +63 -0
- package/dist/lib/server/src/services/PrepareFrontendControllerService.js.map +1 -0
- package/dist/lib/server/src/services/PrepareScheduleService.d.ts +21 -0
- package/dist/lib/server/src/services/PrepareScheduleService.js +69 -0
- package/dist/lib/server/src/services/PrepareScheduleService.js.map +1 -0
- package/dist/lib/server/web/decorators/Page.d.ts +13 -0
- package/dist/lib/server/web/decorators/Page.js +17 -0
- package/dist/lib/server/web/decorators/Page.js.map +1 -0
- package/dist/lib/server/web/decorators/http.base.d.ts +1 -1
- package/dist/lib/server/web/decorators/http.base.js +3 -2
- package/dist/lib/server/web/decorators/http.base.js.map +1 -1
- package/dist/lib/server/web/decorators/index.d.ts +1 -0
- package/dist/lib/server/web/decorators/index.js +1 -0
- package/dist/lib/server/web/decorators/index.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/All.d.ts +7 -0
- package/dist/lib/server/web/decorators/methods/All.js +12 -0
- package/dist/lib/server/web/decorators/methods/All.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Connect.js +2 -2
- package/dist/lib/server/web/decorators/methods/Connect.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Delete.js +2 -2
- package/dist/lib/server/web/decorators/methods/Delete.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Get.js +2 -2
- package/dist/lib/server/web/decorators/methods/Get.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Head.js +2 -2
- package/dist/lib/server/web/decorators/methods/Head.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Options.js +2 -2
- package/dist/lib/server/web/decorators/methods/Options.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Patch.js +2 -2
- package/dist/lib/server/web/decorators/methods/Patch.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Post.js +2 -2
- package/dist/lib/server/web/decorators/methods/Post.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Put.js +2 -2
- package/dist/lib/server/web/decorators/methods/Put.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/Route.d.ts +21 -0
- package/dist/lib/server/web/decorators/methods/Route.js +33 -0
- package/dist/lib/server/web/decorators/methods/Route.js.map +1 -0
- package/dist/lib/server/web/decorators/methods/Trace.js +2 -2
- package/dist/lib/server/web/decorators/methods/Trace.js.map +1 -1
- package/dist/lib/server/web/decorators/methods/index.d.ts +2 -0
- package/dist/lib/server/web/decorators/methods/index.js +2 -0
- package/dist/lib/server/web/decorators/methods/index.js.map +1 -1
- package/dist/lib/server/web/middleware/AsenaValidationService.d.ts +32 -0
- package/dist/lib/server/web/types/HttpMethod.d.ts +2 -1
- package/dist/lib/server/web/types/HttpMethod.js +1 -0
- package/dist/lib/server/web/types/HttpMethod.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaSocket.d.ts +16 -8
- package/dist/lib/server/web/websocket/AsenaSocket.js +30 -7
- package/dist/lib/server/web/websocket/AsenaSocket.js.map +1 -1
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.d.ts +6 -7
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js +10 -11
- package/dist/lib/server/web/websocket/AsenaWebSocketServer.js.map +1 -1
- package/dist/lib/server/web/websocket/BunLocalTransport.d.ts +16 -0
- package/dist/lib/server/web/websocket/BunLocalTransport.js +18 -0
- package/dist/lib/server/web/websocket/BunLocalTransport.js.map +1 -0
- package/dist/lib/server/web/websocket/WebSocketTransport.d.ts +76 -0
- package/dist/lib/server/web/websocket/WebSocketTransport.js +2 -0
- package/dist/lib/server/web/websocket/WebSocketTransport.js.map +1 -0
- package/dist/lib/server/web/websocket/index.d.ts +2 -0
- package/dist/lib/server/web/websocket/index.js +2 -0
- package/dist/lib/server/web/websocket/index.js.map +1 -1
- package/dist/lib/server/web/websocket/types.d.ts +24 -0
- package/dist/lib/utils/index.d.ts +2 -0
- package/dist/lib/utils/index.js +1 -0
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/metadataExtractor.d.ts +88 -0
- package/dist/lib/utils/metadataExtractor.js +105 -0
- package/dist/lib/utils/metadataExtractor.js.map +1 -0
- package/dist/lib/utils/patternMatcher.js +5 -2
- package/dist/lib/utils/patternMatcher.js.map +1 -1
- package/package.json +23 -15
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ServerWebSocket, ServerWebSocketSendStatus, WebSocketReadyState } from 'bun';
|
|
2
2
|
import type { WebSocketData } from './types';
|
|
3
|
+
import type { WebSocketTransport } from './WebSocketTransport';
|
|
3
4
|
/**
|
|
4
5
|
* Wrapper class for Bun's ServerWebSocket that provides Asena-specific WebSocket functionality.
|
|
5
6
|
* This class acts as a facade over the native Bun WebSocket implementation, adding features like
|
|
@@ -15,7 +16,7 @@ import type { WebSocketData } from './types';
|
|
|
15
16
|
* socket.unsubscribe('chat-room');
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
|
-
export declare class AsenaSocket<T>
|
|
19
|
+
export declare class AsenaSocket<T> {
|
|
19
20
|
readonly subscriptions: string[];
|
|
20
21
|
/**
|
|
21
22
|
* The underlying Bun ServerWebSocket instance.
|
|
@@ -52,13 +53,20 @@ export declare class AsenaSocket<T> implements ServerWebSocket<WebSocketData<T>>
|
|
|
52
53
|
* @private
|
|
53
54
|
*/
|
|
54
55
|
private _namespace;
|
|
56
|
+
/**
|
|
57
|
+
* Optional transport layer for cross-pod message publishing.
|
|
58
|
+
* When set, publish operations go through the transport instead of direct ws.publish().
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private _transport?;
|
|
55
62
|
/**
|
|
56
63
|
* Creates a new AsenaSocket instance wrapping a Bun ServerWebSocket.
|
|
57
64
|
*
|
|
58
65
|
* @param ws - The native Bun ServerWebSocket instance to wrap
|
|
59
66
|
* @param namespace - The namespace this socket belongs to
|
|
67
|
+
* @param transport - Optional WebSocket transport for cross-pod publishing
|
|
60
68
|
*/
|
|
61
|
-
constructor(ws: ServerWebSocket<WebSocketData<T>>, namespace: string);
|
|
69
|
+
constructor(ws: ServerWebSocket<WebSocketData<T>>, namespace: string, transport?: WebSocketTransport);
|
|
62
70
|
/**
|
|
63
71
|
* Sends data to the client. Automatically detects whether data is text or binary.
|
|
64
72
|
*
|
|
@@ -114,17 +122,19 @@ export declare class AsenaSocket<T> implements ServerWebSocket<WebSocketData<T>>
|
|
|
114
122
|
* Publishes data to all clients subscribed to the specified topic.
|
|
115
123
|
* The topic is automatically prefixed with the namespace.
|
|
116
124
|
*
|
|
125
|
+
* When a transport is configured, messages are routed through the transport
|
|
126
|
+
* layer for cross-pod delivery. Otherwise, uses Bun's native ws.publish().
|
|
127
|
+
*
|
|
117
128
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
118
129
|
* @param data - The data to publish (string, ArrayBuffer, TypedArray, or DataView)
|
|
119
130
|
* @param compress - Whether to compress the data (default: false)
|
|
120
|
-
* @returns The send status indicating success or failure
|
|
121
131
|
*
|
|
122
132
|
* @example
|
|
123
133
|
* ```typescript
|
|
124
134
|
* socket.publish('chat-room', 'Hello everyone!');
|
|
125
135
|
* ```
|
|
126
136
|
*/
|
|
127
|
-
publish(topic: string, data: string | ArrayBufferLike | DataView, compress?: boolean):
|
|
137
|
+
publish(topic: string, data: string | ArrayBufferLike | DataView, compress?: boolean): void;
|
|
128
138
|
/**
|
|
129
139
|
* Publishes text data to all clients subscribed to the specified topic.
|
|
130
140
|
* The topic is automatically prefixed with the namespace.
|
|
@@ -132,9 +142,8 @@ export declare class AsenaSocket<T> implements ServerWebSocket<WebSocketData<T>>
|
|
|
132
142
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
133
143
|
* @param data - The text string to publish
|
|
134
144
|
* @param compress - Whether to compress the data (default: false)
|
|
135
|
-
* @returns The send status indicating success or failure
|
|
136
145
|
*/
|
|
137
|
-
publishText(topic: string, data: string, compress?: boolean):
|
|
146
|
+
publishText(topic: string, data: string, compress?: boolean): void;
|
|
138
147
|
/**
|
|
139
148
|
* Publishes binary data to all clients subscribed to the specified topic.
|
|
140
149
|
* The topic is automatically prefixed with the namespace.
|
|
@@ -142,9 +151,8 @@ export declare class AsenaSocket<T> implements ServerWebSocket<WebSocketData<T>>
|
|
|
142
151
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
143
152
|
* @param data - The binary data to publish (ArrayBuffer, TypedArray, or DataView)
|
|
144
153
|
* @param compress - Whether to compress the data (default: false)
|
|
145
|
-
* @returns The send status indicating success or failure
|
|
146
154
|
*/
|
|
147
|
-
publishBinary(topic: string, data: ArrayBufferLike | DataView, compress?: boolean):
|
|
155
|
+
publishBinary(topic: string, data: ArrayBufferLike | DataView, compress?: boolean): void;
|
|
148
156
|
/**
|
|
149
157
|
* Subscribes this socket to a topic/room. Once subscribed, the socket will receive
|
|
150
158
|
* all messages published to this topic. The topic is automatically prefixed with the namespace.
|
|
@@ -50,13 +50,20 @@ export class AsenaSocket {
|
|
|
50
50
|
* @private
|
|
51
51
|
*/
|
|
52
52
|
_namespace;
|
|
53
|
+
/**
|
|
54
|
+
* Optional transport layer for cross-pod message publishing.
|
|
55
|
+
* When set, publish operations go through the transport instead of direct ws.publish().
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
_transport;
|
|
53
59
|
/**
|
|
54
60
|
* Creates a new AsenaSocket instance wrapping a Bun ServerWebSocket.
|
|
55
61
|
*
|
|
56
62
|
* @param ws - The native Bun ServerWebSocket instance to wrap
|
|
57
63
|
* @param namespace - The namespace this socket belongs to
|
|
64
|
+
* @param transport - Optional WebSocket transport for cross-pod publishing
|
|
58
65
|
*/
|
|
59
|
-
constructor(ws, namespace) {
|
|
66
|
+
constructor(ws, namespace, transport) {
|
|
60
67
|
this.ws = ws;
|
|
61
68
|
this._data = ws.data;
|
|
62
69
|
this._id = ws.data.id;
|
|
@@ -64,6 +71,7 @@ export class AsenaSocket {
|
|
|
64
71
|
this._binaryType = ws.binaryType;
|
|
65
72
|
this._readyState = ws.readyState;
|
|
66
73
|
this._namespace = namespace;
|
|
74
|
+
this._transport = transport;
|
|
67
75
|
this.subscriptions = ws.subscriptions;
|
|
68
76
|
}
|
|
69
77
|
/**
|
|
@@ -135,10 +143,12 @@ export class AsenaSocket {
|
|
|
135
143
|
* Publishes data to all clients subscribed to the specified topic.
|
|
136
144
|
* The topic is automatically prefixed with the namespace.
|
|
137
145
|
*
|
|
146
|
+
* When a transport is configured, messages are routed through the transport
|
|
147
|
+
* layer for cross-pod delivery. Otherwise, uses Bun's native ws.publish().
|
|
148
|
+
*
|
|
138
149
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
139
150
|
* @param data - The data to publish (string, ArrayBuffer, TypedArray, or DataView)
|
|
140
151
|
* @param compress - Whether to compress the data (default: false)
|
|
141
|
-
* @returns The send status indicating success or failure
|
|
142
152
|
*
|
|
143
153
|
* @example
|
|
144
154
|
* ```typescript
|
|
@@ -146,7 +156,12 @@ export class AsenaSocket {
|
|
|
146
156
|
* ```
|
|
147
157
|
*/
|
|
148
158
|
publish(topic, data, compress) {
|
|
149
|
-
|
|
159
|
+
if (this._transport) {
|
|
160
|
+
this._transport.publish(this.createTopic(topic), data);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.ws.publish(this.createTopic(topic), data, compress);
|
|
164
|
+
}
|
|
150
165
|
}
|
|
151
166
|
/**
|
|
152
167
|
* Publishes text data to all clients subscribed to the specified topic.
|
|
@@ -155,10 +170,14 @@ export class AsenaSocket {
|
|
|
155
170
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
156
171
|
* @param data - The text string to publish
|
|
157
172
|
* @param compress - Whether to compress the data (default: false)
|
|
158
|
-
* @returns The send status indicating success or failure
|
|
159
173
|
*/
|
|
160
174
|
publishText(topic, data, compress) {
|
|
161
|
-
|
|
175
|
+
if (this._transport) {
|
|
176
|
+
this._transport.publish(this.createTopic(topic), data);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.ws.publishText(this.createTopic(topic), data, compress);
|
|
180
|
+
}
|
|
162
181
|
}
|
|
163
182
|
/**
|
|
164
183
|
* Publishes binary data to all clients subscribed to the specified topic.
|
|
@@ -167,10 +186,14 @@ export class AsenaSocket {
|
|
|
167
186
|
* @param topic - The topic name to publish to (will be prefixed with namespace)
|
|
168
187
|
* @param data - The binary data to publish (ArrayBuffer, TypedArray, or DataView)
|
|
169
188
|
* @param compress - Whether to compress the data (default: false)
|
|
170
|
-
* @returns The send status indicating success or failure
|
|
171
189
|
*/
|
|
172
190
|
publishBinary(topic, data, compress) {
|
|
173
|
-
|
|
191
|
+
if (this._transport) {
|
|
192
|
+
this._transport.publish(this.createTopic(topic), data);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this.ws.publishBinary(this.createTopic(topic), data, compress);
|
|
196
|
+
}
|
|
174
197
|
}
|
|
175
198
|
/**
|
|
176
199
|
* Subscribes this socket to a topic/room. Once subscribed, the socket will receive
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsenaSocket.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/AsenaSocket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AsenaSocket.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/AsenaSocket.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,WAAW;IAEb,aAAa,CAAW;I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IAAW,UAAU,CAAC,KAAkD;QACtE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU,CAAC,KAA0B;QAC9C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI,CAAC,KAAuB;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,IAAW,EAAE,CAAC,KAAa;QACzB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CAAC,KAAa;QAC/B,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,EAAE,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WebSocketTransport } from './WebSocketTransport';
|
|
2
2
|
/**
|
|
3
3
|
* AsenaWebSocketServer class handles WebSocket server operations and message broadcasting
|
|
4
4
|
*
|
|
5
|
-
* This class provides a thin wrapper around
|
|
5
|
+
* This class provides a thin wrapper around the WebSocket transport layer.
|
|
6
6
|
* All WebSocket services share a single instance of this wrapper for efficiency.
|
|
7
7
|
*/
|
|
8
8
|
export declare class AsenaWebSocketServer {
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The transport layer used for publishing messages
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
|
-
private
|
|
13
|
+
private transport;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new instance of AsenaWebSocketServer
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
17
|
+
* @param transport - The WebSocket transport to use for publishing
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(transport: WebSocketTransport);
|
|
20
20
|
/**
|
|
21
21
|
* Publishes data to a specific namespace
|
|
22
22
|
*
|
|
23
23
|
* @param nameSpace - The target namespace to publish to
|
|
24
24
|
* @param data - The data to publish. Supports ArrayBuffer, objects, strings, and numbers
|
|
25
|
-
* @returns void
|
|
26
25
|
*/
|
|
27
26
|
to(nameSpace: string, data?: any): void;
|
|
28
27
|
/**
|
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AsenaWebSocketServer class handles WebSocket server operations and message broadcasting
|
|
3
3
|
*
|
|
4
|
-
* This class provides a thin wrapper around
|
|
4
|
+
* This class provides a thin wrapper around the WebSocket transport layer.
|
|
5
5
|
* All WebSocket services share a single instance of this wrapper for efficiency.
|
|
6
6
|
*/
|
|
7
7
|
export class AsenaWebSocketServer {
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
9
|
+
* The transport layer used for publishing messages
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
transport;
|
|
13
13
|
/**
|
|
14
14
|
* Creates a new instance of AsenaWebSocketServer
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param transport - The WebSocket transport to use for publishing
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
this.
|
|
18
|
+
constructor(transport) {
|
|
19
|
+
this.transport = transport;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Publishes data to a specific namespace
|
|
23
23
|
*
|
|
24
24
|
* @param nameSpace - The target namespace to publish to
|
|
25
25
|
* @param data - The data to publish. Supports ArrayBuffer, objects, strings, and numbers
|
|
26
|
-
* @returns void
|
|
27
26
|
*/
|
|
28
27
|
to(nameSpace, data) {
|
|
29
|
-
if (data instanceof ArrayBuffer || data instanceof DataView
|
|
30
|
-
this.
|
|
28
|
+
if (data instanceof ArrayBuffer || data instanceof DataView) {
|
|
29
|
+
this.transport.publish(nameSpace, data);
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
if ((typeof data === 'object' || typeof data === 'string') && data !== null) {
|
|
34
|
-
this.
|
|
33
|
+
this.transport.publish(nameSpace, JSON.stringify(data));
|
|
35
34
|
}
|
|
36
35
|
else if (typeof data === 'number' || data === null || data === undefined) {
|
|
37
|
-
this.
|
|
36
|
+
this.transport.publish(nameSpace, String(data));
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsenaWebSocketServer.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/AsenaWebSocketServer.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;OAGG;IACK,
|
|
1
|
+
{"version":3,"file":"AsenaWebSocketServer.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/AsenaWebSocketServer.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;OAGG;IACK,SAAS,CAAqB;IAEtC;;;;OAIG;IACH,YAAmB,SAA6B;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,EAAE,CAAC,SAAiB,EAAE,IAAU;QACrC,IAAI,IAAI,YAAY,WAAW,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;YAC5D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACxC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC5E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YAC3E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,EAAE,CAAC,SAAiB,EAAE,IAAU;QACrC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Server } from 'bun';
|
|
2
|
+
import type { WebSocketData } from './types';
|
|
3
|
+
import type { WebSocketTransport } from './WebSocketTransport';
|
|
4
|
+
/**
|
|
5
|
+
* Default WebSocket transport using Bun's native server.publish().
|
|
6
|
+
*
|
|
7
|
+
* Single-pod only - messages are delivered to local sockets via Bun's
|
|
8
|
+
* built-in pub/sub mechanism. Zero overhead, no external dependencies.
|
|
9
|
+
*
|
|
10
|
+
* This is the default transport when no custom transport is configured.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BunLocalTransport implements WebSocketTransport {
|
|
13
|
+
private server;
|
|
14
|
+
init(server: Server<WebSocketData>): Promise<void>;
|
|
15
|
+
publish(topic: string, data: string | ArrayBuffer | ArrayBufferView): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default WebSocket transport using Bun's native server.publish().
|
|
3
|
+
*
|
|
4
|
+
* Single-pod only - messages are delivered to local sockets via Bun's
|
|
5
|
+
* built-in pub/sub mechanism. Zero overhead, no external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* This is the default transport when no custom transport is configured.
|
|
8
|
+
*/
|
|
9
|
+
export class BunLocalTransport {
|
|
10
|
+
server;
|
|
11
|
+
async init(server) {
|
|
12
|
+
this.server = server;
|
|
13
|
+
}
|
|
14
|
+
publish(topic, data) {
|
|
15
|
+
this.server.publish(topic, data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=BunLocalTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BunLocalTransport.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/BunLocalTransport.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAwB;IAE/B,KAAK,CAAC,IAAI,CAAC,MAA6B;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,OAAO,CAAC,KAAa,EAAE,IAA4C;QACxE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAA4B,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Server } from 'bun';
|
|
2
|
+
import type { WebSocketData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for WebSocket message transport.
|
|
5
|
+
*
|
|
6
|
+
* Abstracts the publish mechanism so WebSocket messages can be delivered
|
|
7
|
+
* across multiple server instances (pods) via external message brokers
|
|
8
|
+
* like Redis or NATS.
|
|
9
|
+
*
|
|
10
|
+
* The default implementation (BunLocalTransport) uses Bun's native
|
|
11
|
+
* server.publish() for single-pod deployments with zero overhead.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Custom Redis transport
|
|
16
|
+
* class RedisTransport implements WebSocketTransport {
|
|
17
|
+
* private server: Server;
|
|
18
|
+
* private podId = crypto.randomUUID();
|
|
19
|
+
*
|
|
20
|
+
* async init(server: Server) {
|
|
21
|
+
* this.server = server;
|
|
22
|
+
* // Subscribe to Redis for inbound messages from other pods
|
|
23
|
+
* this.redis.psubscribe('ws:*', (channel, message) => {
|
|
24
|
+
* const { data, origin } = JSON.parse(message);
|
|
25
|
+
* if (origin !== this.podId) {
|
|
26
|
+
* server.publish(channel.replace('ws:', ''), data);
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* publish(topic: string, data: string | ArrayBuffer | ArrayBufferView) {
|
|
32
|
+
* // Local delivery
|
|
33
|
+
* this.server.publish(topic, data);
|
|
34
|
+
* // Remote delivery
|
|
35
|
+
* this.redis.publish(`ws:${topic}`, JSON.stringify({ data, origin: this.podId }));
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* async destroy() {
|
|
39
|
+
* this.redis.punsubscribe('ws:*');
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export interface WebSocketTransport {
|
|
45
|
+
/**
|
|
46
|
+
* Publish data to a topic.
|
|
47
|
+
*
|
|
48
|
+
* Responsible for BOTH local and remote delivery:
|
|
49
|
+
* - BunLocalTransport: server.publish() only (single-pod)
|
|
50
|
+
* - Remote transports: server.publish() (local) + broker publish (remote)
|
|
51
|
+
*
|
|
52
|
+
* @param topic - The topic/channel to publish to (namespace-prefixed)
|
|
53
|
+
* @param data - The data to publish
|
|
54
|
+
*/
|
|
55
|
+
publish(topic: string, data: string | ArrayBuffer | ArrayBufferView): void;
|
|
56
|
+
/**
|
|
57
|
+
* Initialize transport with Bun server reference.
|
|
58
|
+
*
|
|
59
|
+
* Called during server startup, before any WebSocket connections are accepted.
|
|
60
|
+
* Remote transports should:
|
|
61
|
+
* 1. Store the server reference for local message delivery
|
|
62
|
+
* 2. Subscribe to the message broker for inbound messages from other pods
|
|
63
|
+
* 3. Relay inbound messages to local sockets via server.publish()
|
|
64
|
+
*
|
|
65
|
+
* @param server - The Bun server instance
|
|
66
|
+
*/
|
|
67
|
+
init?(server: Server<WebSocketData>): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Cleanup transport resources.
|
|
70
|
+
*
|
|
71
|
+
* Called during server shutdown. Remote transports should:
|
|
72
|
+
* 1. Unsubscribe from message broker channels
|
|
73
|
+
* 2. Close broker connections
|
|
74
|
+
*/
|
|
75
|
+
destroy?(): Promise<void>;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketTransport.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/WebSocketTransport.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lib/server/web/websocket/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
@@ -14,6 +14,19 @@ export interface WSEvents<T extends ServerWebSocket<any> = ServerWebSocket<any>>
|
|
|
14
14
|
onOpenInternal: (ws: T) => void | Promise<void>;
|
|
15
15
|
onCloseInternal: (ws: T, code: number, reason: string) => void | Promise<void>;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* WebSocket ping strategy for keepalive.
|
|
19
|
+
*
|
|
20
|
+
* - `'adapter'` (default): Disables Bun's native sendPings and uses the adapter's
|
|
21
|
+
* own heartbeat mechanism via `ws.ping()`. Controlled by `heartbeatInterval` option.
|
|
22
|
+
* This avoids Bun's aggressive, non-configurable ping timeout (4-16s) that can
|
|
23
|
+
* kill connections under load. See: https://github.com/oven-sh/bun/issues/26554
|
|
24
|
+
*
|
|
25
|
+
* - `'native'`: Delegates ping/pong entirely to Bun's built-in `sendPings` mechanism.
|
|
26
|
+
* Bun automatically sends pings and closes connections that don't respond within
|
|
27
|
+
* its internal timeout. Simpler but less configurable.
|
|
28
|
+
*/
|
|
29
|
+
export type SendPingStrategy = 'adapter' | 'native';
|
|
17
30
|
/**
|
|
18
31
|
* Options for configuring the WebSocket server.
|
|
19
32
|
*/
|
|
@@ -24,6 +37,17 @@ export interface WSOptions {
|
|
|
24
37
|
idleTimeout?: number;
|
|
25
38
|
publishToSelf?: boolean;
|
|
26
39
|
sendPings?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* WebSocket ping strategy for keepalive.
|
|
42
|
+
* - 'adapter' (default): Uses adapter's heartbeat mechanism via ws.ping()
|
|
43
|
+
* - 'native': Uses Bun's built-in sendPings
|
|
44
|
+
*/
|
|
45
|
+
sendPingStrategy?: SendPingStrategy;
|
|
46
|
+
/**
|
|
47
|
+
* Heartbeat interval in milliseconds.
|
|
48
|
+
* Only used when sendPingStrategy is 'adapter'.
|
|
49
|
+
*/
|
|
50
|
+
heartbeatInterval?: number;
|
|
27
51
|
perMessageDeflate: boolean | {
|
|
28
52
|
compress?: WebSocketCompressor | boolean;
|
|
29
53
|
decompress?: WebSocketCompressor | boolean;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { matchesPattern, shouldApplyMiddleware } from './patternMatcher';
|
|
2
2
|
export { getTypedMetadata, getOwnTypedMetadata, defineTypedMetadata } from './typedMetadata';
|
|
3
|
+
export { extractControllerRouteInfo, extractComponentName, isValidator, isController, isService, isMiddleware, getComponentType, } from './metadataExtractor';
|
|
4
|
+
export type { ControllerRouteInfo } from './metadataExtractor';
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { matchesPattern, shouldApplyMiddleware } from './patternMatcher';
|
|
2
2
|
export { getTypedMetadata, getOwnTypedMetadata, defineTypedMetadata } from './typedMetadata';
|
|
3
|
+
export { extractControllerRouteInfo, extractComponentName, isValidator, isController, isService, isMiddleware, getComponentType, } from './metadataExtractor';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Route } from '../adapter';
|
|
2
|
+
/**
|
|
3
|
+
* Extracted route information from a controller instance.
|
|
4
|
+
* Provides a stable public API for reading controller metadata
|
|
5
|
+
* without exposing internal ComponentConstants symbols.
|
|
6
|
+
*/
|
|
7
|
+
export interface ControllerRouteInfo {
|
|
8
|
+
/** Base path from @Controller decorator (e.g., '/api/users') */
|
|
9
|
+
basePath: string;
|
|
10
|
+
/** Component name from @Controller decorator or class name */
|
|
11
|
+
controllerName: string;
|
|
12
|
+
/** Optional description for the controller (used as OpenAPI tag description) */
|
|
13
|
+
description: string;
|
|
14
|
+
/** Route map: { [methodName]: { path, method, description, validator, ... } } */
|
|
15
|
+
routes: Route;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts route metadata from a controller instance.
|
|
19
|
+
*
|
|
20
|
+
* @param controller - A resolved controller instance from the container
|
|
21
|
+
* @returns Controller route information including base path, name, and route definitions
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const controllers = await container.resolveAll(ComponentType.CONTROLLER);
|
|
26
|
+
* for (const controller of controllers) {
|
|
27
|
+
* const info = extractControllerRouteInfo(controller);
|
|
28
|
+
* console.log(info.basePath, info.controllerName, Object.keys(info.routes));
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractControllerRouteInfo(controller: any): ControllerRouteInfo;
|
|
33
|
+
/**
|
|
34
|
+
* Extracts the registered component name from a class or instance.
|
|
35
|
+
*
|
|
36
|
+
* @param target - A class constructor or instance
|
|
37
|
+
* @returns The component name, or empty string if not found
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const name = extractComponentName(MyValidator);
|
|
42
|
+
* const validator = await container.resolve(name);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractComponentName(target: any): string;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a class is decorated with `@Middleware({ validator: true })`.
|
|
48
|
+
*
|
|
49
|
+
* @param target - A class constructor
|
|
50
|
+
* @returns true if the class is a validator middleware
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // In a PostProcessor:
|
|
55
|
+
* postProcess<T>(instance: T, Class: any): T {
|
|
56
|
+
* if (isValidator(Class)) {
|
|
57
|
+
* // collect validator instance
|
|
58
|
+
* }
|
|
59
|
+
* return instance;
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function isValidator(target: any): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a class is decorated with `@Controller`.
|
|
66
|
+
*
|
|
67
|
+
* @param target - A class constructor
|
|
68
|
+
*/
|
|
69
|
+
export declare function isController(target: any): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a class is decorated with `@Service`.
|
|
72
|
+
*
|
|
73
|
+
* @param target - A class constructor
|
|
74
|
+
*/
|
|
75
|
+
export declare function isService(target: any): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if a class is decorated with `@Middleware`.
|
|
78
|
+
*
|
|
79
|
+
* @param target - A class constructor
|
|
80
|
+
*/
|
|
81
|
+
export declare function isMiddleware(target: any): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the component type string if the class is an Asena component.
|
|
84
|
+
*
|
|
85
|
+
* @param target - A class constructor
|
|
86
|
+
* @returns Component type ('SERVICE', 'CONTROLLER', 'MIDDLEWARE', etc.) or undefined
|
|
87
|
+
*/
|
|
88
|
+
export declare function getComponentType(target: any): string | undefined;
|