alepha 0.12.1 → 0.13.1
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/dist/api-notifications/index.d.ts +111 -111
- package/dist/api-users/index.d.ts +1240 -1240
- package/dist/api-verifications/index.d.ts +94 -94
- package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
- package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
- package/dist/cli/index.d.ts +3 -11
- package/dist/cli/index.js +106 -74
- package/dist/cli/index.js.map +1 -1
- package/dist/email/index.js +71 -73
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/index.d.ts +4 -4
- package/dist/redis/index.d.ts +10 -10
- package/dist/retry/index.d.ts +1 -1
- package/dist/retry/index.js +2 -2
- package/dist/retry/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +6 -6
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server-auth/index.d.ts +193 -193
- package/dist/server-health/index.d.ts +17 -17
- package/dist/server-links/index.d.ts +34 -34
- package/dist/server-metrics/index.js +170 -174
- package/dist/server-metrics/index.js.map +1 -1
- package/dist/server-security/index.d.ts +9 -9
- package/dist/vite/index.js +4 -5
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/package.json +52 -103
- package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
- package/src/cli/assets/appRouterTs.ts +9 -0
- package/src/cli/assets/indexHtml.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +10 -0
- package/src/cli/commands/CoreCommands.ts +6 -5
- package/src/cli/commands/DrizzleCommands.ts +65 -57
- package/src/cli/commands/VerifyCommands.ts +1 -1
- package/src/cli/services/ProjectUtils.ts +44 -38
- package/src/orm/providers/DrizzleKitProvider.ts +1 -1
- package/src/retry/descriptors/$retry.ts +5 -3
- package/src/server/providers/NodeHttpServerProvider.ts +1 -1
- package/src/vite/helpers/boot.ts +3 -3
- package/dist/api-files/index.cjs +0 -1293
- package/dist/api-files/index.cjs.map +0 -1
- package/dist/api-files/index.d.cts +0 -829
- package/dist/api-jobs/index.cjs +0 -274
- package/dist/api-jobs/index.cjs.map +0 -1
- package/dist/api-jobs/index.d.cts +0 -654
- package/dist/api-notifications/index.cjs +0 -380
- package/dist/api-notifications/index.cjs.map +0 -1
- package/dist/api-notifications/index.d.cts +0 -289
- package/dist/api-parameters/index.cjs +0 -66
- package/dist/api-parameters/index.cjs.map +0 -1
- package/dist/api-parameters/index.d.cts +0 -84
- package/dist/api-users/index.cjs +0 -6009
- package/dist/api-users/index.cjs.map +0 -1
- package/dist/api-users/index.d.cts +0 -4740
- package/dist/api-verifications/index.cjs +0 -407
- package/dist/api-verifications/index.cjs.map +0 -1
- package/dist/api-verifications/index.d.cts +0 -207
- package/dist/batch/index.cjs +0 -408
- package/dist/batch/index.cjs.map +0 -1
- package/dist/batch/index.d.cts +0 -330
- package/dist/bin/index.cjs +0 -17
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/bucket/index.cjs +0 -303
- package/dist/bucket/index.cjs.map +0 -1
- package/dist/bucket/index.d.cts +0 -355
- package/dist/cache/index.cjs +0 -241
- package/dist/cache/index.cjs.map +0 -1
- package/dist/cache/index.d.cts +0 -202
- package/dist/cache-redis/index.cjs +0 -84
- package/dist/cache-redis/index.cjs.map +0 -1
- package/dist/cache-redis/index.d.cts +0 -40
- package/dist/cli/chunk-DSlc6foC.cjs +0 -43
- package/dist/cli/dist-BBPjuQ56.js +0 -2778
- package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
- package/dist/cli/index.cjs +0 -1241
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -422
- package/dist/command/index.cjs +0 -693
- package/dist/command/index.cjs.map +0 -1
- package/dist/command/index.d.cts +0 -340
- package/dist/core/index.cjs +0 -2264
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1927
- package/dist/datetime/index.cjs +0 -318
- package/dist/datetime/index.cjs.map +0 -1
- package/dist/datetime/index.d.cts +0 -145
- package/dist/email/index.cjs +0 -10874
- package/dist/email/index.cjs.map +0 -1
- package/dist/email/index.d.cts +0 -186
- package/dist/fake/index.cjs +0 -34641
- package/dist/fake/index.cjs.map +0 -1
- package/dist/fake/index.d.cts +0 -74
- package/dist/file/index.cjs +0 -1212
- package/dist/file/index.cjs.map +0 -1
- package/dist/file/index.d.cts +0 -698
- package/dist/lock/index.cjs +0 -226
- package/dist/lock/index.cjs.map +0 -1
- package/dist/lock/index.d.cts +0 -361
- package/dist/lock-redis/index.cjs +0 -113
- package/dist/lock-redis/index.cjs.map +0 -1
- package/dist/lock-redis/index.d.cts +0 -24
- package/dist/logger/index.cjs +0 -521
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -281
- package/dist/orm/index.cjs +0 -2986
- package/dist/orm/index.cjs.map +0 -1
- package/dist/orm/index.d.cts +0 -2213
- package/dist/queue/index.cjs +0 -1044
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts +0 -1265
- package/dist/queue-redis/index.cjs +0 -873
- package/dist/queue-redis/index.cjs.map +0 -1
- package/dist/queue-redis/index.d.cts +0 -82
- package/dist/redis/index.cjs +0 -153
- package/dist/redis/index.cjs.map +0 -1
- package/dist/redis/index.d.cts +0 -82
- package/dist/retry/index.cjs +0 -146
- package/dist/retry/index.cjs.map +0 -1
- package/dist/retry/index.d.cts +0 -172
- package/dist/router/index.cjs +0 -111
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -46
- package/dist/scheduler/index.cjs +0 -576
- package/dist/scheduler/index.cjs.map +0 -1
- package/dist/scheduler/index.d.cts +0 -145
- package/dist/security/index.cjs +0 -2402
- package/dist/security/index.cjs.map +0 -1
- package/dist/security/index.d.cts +0 -598
- package/dist/server/index.cjs +0 -1680
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -810
- package/dist/server-auth/index.cjs +0 -3146
- package/dist/server-auth/index.cjs.map +0 -1
- package/dist/server-auth/index.d.cts +0 -1164
- package/dist/server-cache/index.cjs +0 -252
- package/dist/server-cache/index.cjs.map +0 -1
- package/dist/server-cache/index.d.cts +0 -164
- package/dist/server-compress/index.cjs +0 -141
- package/dist/server-compress/index.cjs.map +0 -1
- package/dist/server-compress/index.d.cts +0 -38
- package/dist/server-cookies/index.cjs +0 -234
- package/dist/server-cookies/index.cjs.map +0 -1
- package/dist/server-cookies/index.d.cts +0 -144
- package/dist/server-cors/index.cjs +0 -201
- package/dist/server-cors/index.cjs.map +0 -1
- package/dist/server-cors/index.d.cts +0 -140
- package/dist/server-health/index.cjs +0 -62
- package/dist/server-health/index.cjs.map +0 -1
- package/dist/server-health/index.d.cts +0 -58
- package/dist/server-helmet/index.cjs +0 -131
- package/dist/server-helmet/index.cjs.map +0 -1
- package/dist/server-helmet/index.d.cts +0 -97
- package/dist/server-links/index.cjs +0 -992
- package/dist/server-links/index.cjs.map +0 -1
- package/dist/server-links/index.d.cts +0 -513
- package/dist/server-metrics/index.cjs +0 -4535
- package/dist/server-metrics/index.cjs.map +0 -1
- package/dist/server-metrics/index.d.cts +0 -35
- package/dist/server-multipart/index.cjs +0 -237
- package/dist/server-multipart/index.cjs.map +0 -1
- package/dist/server-multipart/index.d.cts +0 -50
- package/dist/server-proxy/index.cjs +0 -186
- package/dist/server-proxy/index.cjs.map +0 -1
- package/dist/server-proxy/index.d.cts +0 -234
- package/dist/server-rate-limit/index.cjs +0 -241
- package/dist/server-rate-limit/index.cjs.map +0 -1
- package/dist/server-rate-limit/index.d.cts +0 -183
- package/dist/server-security/index.cjs +0 -316
- package/dist/server-security/index.cjs.map +0 -1
- package/dist/server-security/index.d.cts +0 -173
- package/dist/server-static/index.cjs +0 -170
- package/dist/server-static/index.cjs.map +0 -1
- package/dist/server-static/index.d.cts +0 -121
- package/dist/server-swagger/index.cjs +0 -1021
- package/dist/server-swagger/index.cjs.map +0 -1
- package/dist/server-swagger/index.d.cts +0 -382
- package/dist/sms/index.cjs +0 -221
- package/dist/sms/index.cjs.map +0 -1
- package/dist/sms/index.d.cts +0 -130
- package/dist/thread/index.cjs +0 -350
- package/dist/thread/index.cjs.map +0 -1
- package/dist/thread/index.d.cts +0 -260
- package/dist/topic/index.cjs +0 -282
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts +0 -523
- package/dist/topic-redis/index.cjs +0 -71
- package/dist/topic-redis/index.cjs.map +0 -1
- package/dist/topic-redis/index.d.cts +0 -42
- package/dist/vite/index.cjs +0 -1077
- package/dist/vite/index.cjs.map +0 -1
- package/dist/vite/index.d.cts +0 -542
- package/dist/websocket/index.cjs +0 -1117
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -861
|
@@ -1,861 +0,0 @@
|
|
|
1
|
-
import * as alepha42 from "alepha";
|
|
2
|
-
import { Alepha, Descriptor, KIND, Static, TObject, TString, TUnion } from "alepha";
|
|
3
|
-
import * as alepha_logger2 from "alepha/logger";
|
|
4
|
-
import * as alepha_topic0 from "alepha/topic";
|
|
5
|
-
import { IncomingMessage } from "node:http";
|
|
6
|
-
import { WebSocket as WebSocket$1, WebSocketServer } from "ws";
|
|
7
|
-
|
|
8
|
-
//#region src/websocket/descriptors/$channel.d.ts
|
|
9
|
-
type TWSObject = TObject | TUnion;
|
|
10
|
-
/**
|
|
11
|
-
* Channel descriptor options
|
|
12
|
-
*/
|
|
13
|
-
interface ChannelDescriptorOptions<TClient extends TWSObject, TServer extends TWSObject> {
|
|
14
|
-
/**
|
|
15
|
-
* WebSocket endpoint path (e.g., "/ws/chat")
|
|
16
|
-
*/
|
|
17
|
-
path: string;
|
|
18
|
-
/**
|
|
19
|
-
* Optional description for documentation
|
|
20
|
-
*/
|
|
21
|
-
description?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Message schemas for bidirectional communication
|
|
24
|
-
*/
|
|
25
|
-
schema: {
|
|
26
|
-
/**
|
|
27
|
-
* Optional room ID schema validation
|
|
28
|
-
* Default: t.text() (any string)
|
|
29
|
-
* Can be enforced at application level: t.uuid(), t.regex(/^[a-f0-9\-]{36}$/)
|
|
30
|
-
*/
|
|
31
|
-
roomId?: TString;
|
|
32
|
-
/**
|
|
33
|
-
* Messages from server to client
|
|
34
|
-
* This is what clients will receive
|
|
35
|
-
*/
|
|
36
|
-
in: TClient;
|
|
37
|
-
/**
|
|
38
|
-
* Messages from client to server
|
|
39
|
-
* This is what the server will receive
|
|
40
|
-
*/
|
|
41
|
-
out: TServer;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Defines a WebSocket channel with specified client and server message schemas.
|
|
46
|
-
*
|
|
47
|
-
* Channels must be defined as class properties to be registered in the Alepha context.
|
|
48
|
-
* They define the "vocabulary" for communication - the schema for messages flowing
|
|
49
|
-
* in both directions (server→client and client→server).
|
|
50
|
-
*
|
|
51
|
-
* @example Server-side with $websocket
|
|
52
|
-
* ```typescript
|
|
53
|
-
* class ChatController {
|
|
54
|
-
* // Channel must be defined inside a class
|
|
55
|
-
* chatChannel = $channel({
|
|
56
|
-
* path: "/ws/chat",
|
|
57
|
-
* description: "Real-time chat channel",
|
|
58
|
-
* schema: {
|
|
59
|
-
* // Server → Client messages
|
|
60
|
-
* in: t.union([
|
|
61
|
-
* t.object({
|
|
62
|
-
* type: t.const("append"),
|
|
63
|
-
* content: t.text(),
|
|
64
|
-
* username: t.text()
|
|
65
|
-
* }),
|
|
66
|
-
* t.object({
|
|
67
|
-
* type: t.const("system"),
|
|
68
|
-
* message: t.text()
|
|
69
|
-
* })
|
|
70
|
-
* ]),
|
|
71
|
-
* // Client → Server messages
|
|
72
|
-
* out: t.object({
|
|
73
|
-
* content: t.text()
|
|
74
|
-
* })
|
|
75
|
-
* }
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* chat = $websocket({
|
|
79
|
-
* channel: this.chatChannel,
|
|
80
|
-
* handler: async ({ message, reply }) => {
|
|
81
|
-
* await reply({
|
|
82
|
-
* message: { type: "append", content: message.content, username: "user" }
|
|
83
|
-
* });
|
|
84
|
-
* }
|
|
85
|
-
* });
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* @example Browser-side with useRoom
|
|
90
|
-
* ```typescript
|
|
91
|
-
* // Define channel in a class for browser context
|
|
92
|
-
* class ChatClient {
|
|
93
|
-
* chatChannel = $channel({
|
|
94
|
-
* path: "/ws/chat",
|
|
95
|
-
* schema: { in: inSchema, out: outSchema }
|
|
96
|
-
* });
|
|
97
|
-
* }
|
|
98
|
-
*
|
|
99
|
-
* // Use in React component
|
|
100
|
-
* function Chat() {
|
|
101
|
-
* const client = useInject(ChatClient);
|
|
102
|
-
* const chat = useRoom({ roomId: "lobby", channel: client.chatChannel, handler: ... }, []);
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
declare const $channel: {
|
|
107
|
-
<TClient extends TWSObject, TServer extends TWSObject>(options: ChannelDescriptorOptions<TClient, TServer>): ChannelDescriptor<TClient, TServer>;
|
|
108
|
-
[KIND]: typeof ChannelDescriptor;
|
|
109
|
-
};
|
|
110
|
-
declare class ChannelDescriptor<TClient extends TWSObject, TServer extends TWSObject> extends Descriptor<ChannelDescriptorOptions<TClient, TServer>> {}
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/websocket/interfaces/WebSocketInterfaces.d.ts
|
|
113
|
-
/**
|
|
114
|
-
* WebSocket connection interface
|
|
115
|
-
*/
|
|
116
|
-
interface WebSocketConnection {
|
|
117
|
-
/**
|
|
118
|
-
* Unique connection ID
|
|
119
|
-
*/
|
|
120
|
-
id: string;
|
|
121
|
-
/**
|
|
122
|
-
* User ID (if authenticated and security module is used)
|
|
123
|
-
*/
|
|
124
|
-
userId?: string;
|
|
125
|
-
/**
|
|
126
|
-
* Room IDs that this connection is currently in
|
|
127
|
-
*/
|
|
128
|
-
roomIds: string[];
|
|
129
|
-
/**
|
|
130
|
-
* Send a message to this connection
|
|
131
|
-
*/
|
|
132
|
-
send(message: any): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Close this connection
|
|
135
|
-
*/
|
|
136
|
-
close(code?: number, reason?: string): Promise<void>;
|
|
137
|
-
/**
|
|
138
|
-
* Connection metadata (custom data)
|
|
139
|
-
*/
|
|
140
|
-
metadata?: Record<string, any>;
|
|
141
|
-
/**
|
|
142
|
-
* Connection state
|
|
143
|
-
*/
|
|
144
|
-
readyState: WebSocketState;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* WebSocket state enum
|
|
148
|
-
*/
|
|
149
|
-
declare enum WebSocketState {
|
|
150
|
-
CONNECTING = 0,
|
|
151
|
-
OPEN = 1,
|
|
152
|
-
CLOSING = 2,
|
|
153
|
-
CLOSED = 3,
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* WebSocket endpoint configuration (server-side)
|
|
157
|
-
*/
|
|
158
|
-
interface WebSocketDescriptorOptions<TClient extends TWSObject, TServer extends TWSObject> {
|
|
159
|
-
/**
|
|
160
|
-
* Channel definition with schema and path
|
|
161
|
-
*/
|
|
162
|
-
channel: ChannelDescriptor<TClient, TServer>;
|
|
163
|
-
/**
|
|
164
|
-
* Handler for incoming messages from clients
|
|
165
|
-
*/
|
|
166
|
-
handler: WebSocketHandler<TClient, TServer>;
|
|
167
|
-
/**
|
|
168
|
-
* Optional connection handler (called when a client connects)
|
|
169
|
-
*/
|
|
170
|
-
onConnect?: (params: {
|
|
171
|
-
/**
|
|
172
|
-
* Unique connection ID of the client
|
|
173
|
-
*/
|
|
174
|
-
connectionId: string;
|
|
175
|
-
/**
|
|
176
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
177
|
-
*/
|
|
178
|
-
userId?: string;
|
|
179
|
-
/**
|
|
180
|
-
* Room IDs that the client is connecting to
|
|
181
|
-
*/
|
|
182
|
-
roomIds: string[];
|
|
183
|
-
}) => Promise<void> | void;
|
|
184
|
-
/**
|
|
185
|
-
* Optional disconnection handler (called when a client disconnects)
|
|
186
|
-
*/
|
|
187
|
-
onDisconnect?: (params: {
|
|
188
|
-
/**
|
|
189
|
-
* Unique connection ID of the client
|
|
190
|
-
*/
|
|
191
|
-
connectionId: string;
|
|
192
|
-
/**
|
|
193
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
194
|
-
*/
|
|
195
|
-
userId?: string;
|
|
196
|
-
/**
|
|
197
|
-
* Room IDs that the client was connected to
|
|
198
|
-
*/
|
|
199
|
-
roomIds: string[];
|
|
200
|
-
}) => Promise<void> | void;
|
|
201
|
-
/**
|
|
202
|
-
* Change WebSocket server provider (for custom implementations)
|
|
203
|
-
*/
|
|
204
|
-
provider?: any;
|
|
205
|
-
/**
|
|
206
|
-
* Whether to enforce security (authentication, authorization) on this WebSocket endpoint
|
|
207
|
-
* Requires alepha/security integration
|
|
208
|
-
*/
|
|
209
|
-
secure?: boolean;
|
|
210
|
-
/**
|
|
211
|
-
* Limit number of connections per user (if authenticated)
|
|
212
|
-
*/
|
|
213
|
-
maxConnectionsPerUser?: number;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* WebSocket message handler
|
|
217
|
-
*/
|
|
218
|
-
type WebSocketHandler<TClient extends TWSObject, TServer extends TWSObject> = (context: WebSocketHandlerContext<TClient, TServer>) => Promise<void> | void;
|
|
219
|
-
/**
|
|
220
|
-
* WebSocket handler context
|
|
221
|
-
*/
|
|
222
|
-
interface WebSocketHandlerContext<TClient extends TWSObject, TServer extends TWSObject> {
|
|
223
|
-
/**
|
|
224
|
-
* Unique connection ID of the client
|
|
225
|
-
*/
|
|
226
|
-
connectionId: string;
|
|
227
|
-
/**
|
|
228
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
229
|
-
*/
|
|
230
|
-
userId?: string;
|
|
231
|
-
/**
|
|
232
|
-
* Room ID that the client sent the message from
|
|
233
|
-
*/
|
|
234
|
-
roomId: string;
|
|
235
|
-
/**
|
|
236
|
-
* The parsed and validated message from the client
|
|
237
|
-
*/
|
|
238
|
-
message: Static<TServer>;
|
|
239
|
-
/**
|
|
240
|
-
* Reply function tailored to current context (connectionId, roomId)
|
|
241
|
-
*/
|
|
242
|
-
reply: (options: {
|
|
243
|
-
/**
|
|
244
|
-
* Message to send
|
|
245
|
-
*/
|
|
246
|
-
message: Static<TClient>;
|
|
247
|
-
/**
|
|
248
|
-
* Optional: specify room ID to send to (defaults to sender's room ID)
|
|
249
|
-
*/
|
|
250
|
-
roomId?: string;
|
|
251
|
-
/**
|
|
252
|
-
* Optional: exclude the sender connection from receiving the message
|
|
253
|
-
* Will populate exceptConnectionIds with sender connection ID behind the scenes
|
|
254
|
-
*/
|
|
255
|
-
exceptSelf?: boolean;
|
|
256
|
-
/**
|
|
257
|
-
* Optional: exclude specific connection IDs from receiving the message
|
|
258
|
-
*/
|
|
259
|
-
exceptConnectionIds?: string[];
|
|
260
|
-
/**
|
|
261
|
-
* Optional: exclude specific user IDs from receiving the message
|
|
262
|
-
* Requires alepha/security integration
|
|
263
|
-
*/
|
|
264
|
-
exceptUserIds?: string[];
|
|
265
|
-
}) => Promise<void>;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Emit options for sending messages from the server
|
|
269
|
-
*/
|
|
270
|
-
interface EmitOptions<TClient extends TWSObject> {
|
|
271
|
-
/**
|
|
272
|
-
* Message to send to clients
|
|
273
|
-
*/
|
|
274
|
-
message: Static<TClient>;
|
|
275
|
-
/**
|
|
276
|
-
* Room ID to send the message to
|
|
277
|
-
*/
|
|
278
|
-
roomId?: string;
|
|
279
|
-
/**
|
|
280
|
-
* Room IDs to send the message to
|
|
281
|
-
*/
|
|
282
|
-
roomIds?: string[];
|
|
283
|
-
/**
|
|
284
|
-
* User ID to send the message to (if authenticated)
|
|
285
|
-
*/
|
|
286
|
-
userId?: string;
|
|
287
|
-
/**
|
|
288
|
-
* User IDs to send the message to (if authenticated)
|
|
289
|
-
*/
|
|
290
|
-
userIds?: string[];
|
|
291
|
-
/**
|
|
292
|
-
* Connection ID to send the message to
|
|
293
|
-
*/
|
|
294
|
-
connectionId?: string;
|
|
295
|
-
/**
|
|
296
|
-
* Connection IDs to send the message to
|
|
297
|
-
*/
|
|
298
|
-
connectionIds?: string[];
|
|
299
|
-
/**
|
|
300
|
-
* Optional: exclude specific connection IDs from receiving the message
|
|
301
|
-
*/
|
|
302
|
-
exceptConnectionIds?: string[];
|
|
303
|
-
/**
|
|
304
|
-
* Optional: exclude specific user IDs from receiving the message
|
|
305
|
-
* Requires alepha/security integration
|
|
306
|
-
*/
|
|
307
|
-
exceptUserIds?: string[];
|
|
308
|
-
}
|
|
309
|
-
//#endregion
|
|
310
|
-
//#region src/websocket/providers/WebSocketServerProvider.d.ts
|
|
311
|
-
/**
|
|
312
|
-
* Abstract WebSocket server provider
|
|
313
|
-
*
|
|
314
|
-
* This class provides the base interface that must be implemented by
|
|
315
|
-
* platform-specific providers (Node.js, Browser, etc.)
|
|
316
|
-
*/
|
|
317
|
-
declare abstract class WebSocketServerProvider {
|
|
318
|
-
/**
|
|
319
|
-
* Register a WebSocket endpoint with its channel configuration
|
|
320
|
-
*/
|
|
321
|
-
abstract registerEndpoint<TClient extends TWSObject, TServer extends TWSObject>(config: WebSocketDescriptorOptions<TClient, TServer>): void;
|
|
322
|
-
/**
|
|
323
|
-
* Emit a message to clients based on targeting criteria
|
|
324
|
-
*
|
|
325
|
-
* This method distributes messages across all server instances via pub/sub.
|
|
326
|
-
*/
|
|
327
|
-
abstract emit<TClient extends TWSObject>(channelPath: string, options: EmitOptions<TClient>): Promise<void>;
|
|
328
|
-
/**
|
|
329
|
-
* Get all active connections (local to this server instance)
|
|
330
|
-
*/
|
|
331
|
-
abstract getConnections(): WebSocketConnection[];
|
|
332
|
-
/**
|
|
333
|
-
* Get connections in a specific room (local to this server instance)
|
|
334
|
-
*/
|
|
335
|
-
abstract getRoomConnections(roomId: string): WebSocketConnection[];
|
|
336
|
-
/**
|
|
337
|
-
* Get connections for a specific user (local to this server instance)
|
|
338
|
-
*/
|
|
339
|
-
abstract getUserConnections(userId: string): WebSocketConnection[];
|
|
340
|
-
/**
|
|
341
|
-
* Close a specific connection
|
|
342
|
-
*/
|
|
343
|
-
abstract closeConnection(connectionId: string, code?: number, reason?: string): Promise<void>;
|
|
344
|
-
}
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region src/websocket/descriptors/$websocket.d.ts
|
|
347
|
-
/**
|
|
348
|
-
* Defines a WebSocket server endpoint for a specific channel.
|
|
349
|
-
*
|
|
350
|
-
* Server-side only. Creates a WebSocket endpoint that:
|
|
351
|
-
* - Accepts connections from clients
|
|
352
|
-
* - Validates incoming messages against the channel schema
|
|
353
|
-
* - Provides room-based messaging
|
|
354
|
-
* - Integrates with alepha/security for authentication (optional)
|
|
355
|
-
* - Supports horizontal scaling via alepha/topic
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```typescript
|
|
359
|
-
* class ChatController {
|
|
360
|
-
* chat = $websocket({
|
|
361
|
-
* channel: chatChannel,
|
|
362
|
-
* handler: async ({ connectionId, userId, roomId, message, reply }) => {
|
|
363
|
-
* // Broadcast to all in room except sender
|
|
364
|
-
* await reply({
|
|
365
|
-
* message: {
|
|
366
|
-
* type: "append",
|
|
367
|
-
* username: userId,
|
|
368
|
-
* content: message.content
|
|
369
|
-
* },
|
|
370
|
-
* exceptSelf: true
|
|
371
|
-
* });
|
|
372
|
-
* }
|
|
373
|
-
* });
|
|
374
|
-
*
|
|
375
|
-
* async broadcastAnnouncement(roomId: string, text: string) {
|
|
376
|
-
* await this.chat.emit({
|
|
377
|
-
* roomId,
|
|
378
|
-
* message: {
|
|
379
|
-
* type: "append",
|
|
380
|
-
* username: "System",
|
|
381
|
-
* content: text
|
|
382
|
-
* }
|
|
383
|
-
* });
|
|
384
|
-
* }
|
|
385
|
-
* }
|
|
386
|
-
* ```
|
|
387
|
-
*/
|
|
388
|
-
declare const $websocket: {
|
|
389
|
-
<TClient extends TWSObject, TServer extends TWSObject>(options: WebSocketDescriptorOptions<TClient, TServer>): WebSocketDescriptor<TClient, TServer>;
|
|
390
|
-
[KIND]: typeof WebSocketDescriptor;
|
|
391
|
-
};
|
|
392
|
-
declare class WebSocketDescriptor<TClient extends TWSObject, TServer extends TWSObject> extends Descriptor<WebSocketDescriptorOptions<TClient, TServer>> {
|
|
393
|
-
protected readonly webSocketServerProvider: WebSocketServerProvider;
|
|
394
|
-
protected onInit(): void;
|
|
395
|
-
/**
|
|
396
|
-
* Emit message to clients
|
|
397
|
-
*
|
|
398
|
-
* Send messages from the server to connected clients based on targeting criteria.
|
|
399
|
-
* Messages are distributed across all server instances via pub/sub.
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```typescript
|
|
403
|
-
* // Send to specific room
|
|
404
|
-
* await websocket.emit({
|
|
405
|
-
* roomId: "room-123",
|
|
406
|
-
* message: { type: "update", data: {...} }
|
|
407
|
-
* });
|
|
408
|
-
*
|
|
409
|
-
* // Send to specific user (all their connections)
|
|
410
|
-
* await websocket.emit({
|
|
411
|
-
* userId: "user-456",
|
|
412
|
-
* message: { type: "notification", text: "Hello!" }
|
|
413
|
-
* });
|
|
414
|
-
*
|
|
415
|
-
* // Send to multiple rooms, except certain users
|
|
416
|
-
* await websocket.emit({
|
|
417
|
-
* roomIds: ["room-1", "room-2"],
|
|
418
|
-
* exceptUserIds: ["user-123"],
|
|
419
|
-
* message: { type: "broadcast", content: "System announcement" }
|
|
420
|
-
* });
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
emit(options: EmitOptions<TClient>): Promise<void>;
|
|
424
|
-
}
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/websocket/errors/WebSocketError.d.ts
|
|
427
|
-
/**
|
|
428
|
-
* Base WebSocket error class
|
|
429
|
-
*/
|
|
430
|
-
declare class WebSocketError extends Error {
|
|
431
|
-
readonly code?: number | undefined;
|
|
432
|
-
constructor(message: string, code?: number | undefined);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Error thrown when WebSocket connection fails
|
|
436
|
-
*/
|
|
437
|
-
declare class WebSocketConnectionError extends WebSocketError {
|
|
438
|
-
constructor(message: string, code?: number);
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Error thrown when WebSocket message validation fails
|
|
442
|
-
*/
|
|
443
|
-
declare class WebSocketValidationError extends WebSocketError {
|
|
444
|
-
constructor(message: string);
|
|
445
|
-
}
|
|
446
|
-
//#endregion
|
|
447
|
-
//#region src/websocket/services/RoomManager.d.ts
|
|
448
|
-
/**
|
|
449
|
-
* Manages WebSocket room memberships
|
|
450
|
-
*
|
|
451
|
-
* Rooms are logical groupings of connections. A connection can be in multiple rooms,
|
|
452
|
-
* and messages can be targeted to specific rooms.
|
|
453
|
-
*/
|
|
454
|
-
declare class RoomManager {
|
|
455
|
-
protected readonly log: alepha_logger2.Logger;
|
|
456
|
-
/**
|
|
457
|
-
* Maps roomId → Set<connectionId>
|
|
458
|
-
*/
|
|
459
|
-
protected readonly rooms: Map<string, Set<string>>;
|
|
460
|
-
/**
|
|
461
|
-
* Maps connectionId → Set<roomId>
|
|
462
|
-
* Inverse index for fast lookup of connection's rooms
|
|
463
|
-
*/
|
|
464
|
-
protected readonly connectionRooms: Map<string, Set<string>>;
|
|
465
|
-
/**
|
|
466
|
-
* Join a connection to one or more rooms
|
|
467
|
-
*/
|
|
468
|
-
joinRooms(connectionId: string, roomIds: string[]): void;
|
|
469
|
-
/**
|
|
470
|
-
* Join a connection to a room
|
|
471
|
-
*/
|
|
472
|
-
joinRoom(connectionId: string, roomId: string): void;
|
|
473
|
-
/**
|
|
474
|
-
* Leave a connection from a room
|
|
475
|
-
*/
|
|
476
|
-
leaveRoom(connectionId: string, roomId: string): void;
|
|
477
|
-
/**
|
|
478
|
-
* Remove a connection from all rooms
|
|
479
|
-
*/
|
|
480
|
-
leaveAllRooms(connectionId: string): void;
|
|
481
|
-
/**
|
|
482
|
-
* Get all connection IDs in a room
|
|
483
|
-
*/
|
|
484
|
-
getRoomConnections(roomId: string): string[];
|
|
485
|
-
/**
|
|
486
|
-
* Get all room IDs for a connection
|
|
487
|
-
*/
|
|
488
|
-
getConnectionRooms(connectionId: string): string[];
|
|
489
|
-
/**
|
|
490
|
-
* Check if a connection is in a room
|
|
491
|
-
*/
|
|
492
|
-
isInRoom(connectionId: string, roomId: string): boolean;
|
|
493
|
-
/**
|
|
494
|
-
* Get all active rooms
|
|
495
|
-
*/
|
|
496
|
-
getAllRooms(): string[];
|
|
497
|
-
/**
|
|
498
|
-
* Get total number of connections across all rooms
|
|
499
|
-
*/
|
|
500
|
-
getTotalConnections(): number;
|
|
501
|
-
/**
|
|
502
|
-
* Get room statistics
|
|
503
|
-
*/
|
|
504
|
-
getStats(): {
|
|
505
|
-
totalRooms: number;
|
|
506
|
-
totalConnections: number;
|
|
507
|
-
roomSizes: Map<string, number>;
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
//#endregion
|
|
511
|
-
//#region src/websocket/services/WebSocketClient.d.ts
|
|
512
|
-
declare const envSchema$1: alepha42.TObject<{
|
|
513
|
-
WEBSOCKET_URL: alepha42.TString;
|
|
514
|
-
WEBSOCKET_RECONNECT_INTERVAL: alepha42.TInteger;
|
|
515
|
-
WEBSOCKET_MAX_RECONNECT_ATTEMPTS: alepha42.TInteger;
|
|
516
|
-
}>;
|
|
517
|
-
declare module "alepha" {
|
|
518
|
-
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* WebSocket channel connection
|
|
522
|
-
*
|
|
523
|
-
* Manages a single WebSocket connection to a channel with multiple room subscriptions.
|
|
524
|
-
* One connection can handle multiple rooms on the same channel.
|
|
525
|
-
*/
|
|
526
|
-
declare class WebSocketChannelConnection<TClient extends TWSObject, TServer extends TWSObject> {
|
|
527
|
-
protected readonly channel: ChannelDescriptor<TClient, TServer>;
|
|
528
|
-
protected readonly options: {
|
|
529
|
-
url?: string;
|
|
530
|
-
autoReconnect?: boolean;
|
|
531
|
-
reconnectInterval?: number;
|
|
532
|
-
maxReconnectAttempts?: number;
|
|
533
|
-
};
|
|
534
|
-
protected readonly env: Static<typeof envSchema$1>;
|
|
535
|
-
protected readonly alepha: Alepha;
|
|
536
|
-
protected readonly log: alepha_logger2.Logger;
|
|
537
|
-
protected ws?: WebSocket;
|
|
538
|
-
protected reconnectAttempts: number;
|
|
539
|
-
protected reconnectTimer?: number;
|
|
540
|
-
protected messageQueue: Array<{
|
|
541
|
-
roomId: string;
|
|
542
|
-
message: Static<TServer>;
|
|
543
|
-
}>;
|
|
544
|
-
protected subscriptions: Map<string, (message: Static<TClient>) => void>;
|
|
545
|
-
isConnected: boolean;
|
|
546
|
-
isConnecting: boolean;
|
|
547
|
-
isError: boolean;
|
|
548
|
-
error?: Error;
|
|
549
|
-
protected onConnectCallbacks: Set<() => void>;
|
|
550
|
-
protected onDisconnectCallbacks: Set<() => void>;
|
|
551
|
-
protected onErrorCallbacks: Set<(error: Error) => void>;
|
|
552
|
-
constructor(channel: ChannelDescriptor<TClient, TServer>, options: {
|
|
553
|
-
url?: string;
|
|
554
|
-
autoReconnect?: boolean;
|
|
555
|
-
reconnectInterval?: number;
|
|
556
|
-
maxReconnectAttempts?: number;
|
|
557
|
-
}, env: Static<typeof envSchema$1>);
|
|
558
|
-
/**
|
|
559
|
-
* Build WebSocket URL
|
|
560
|
-
*/
|
|
561
|
-
protected buildUrl(): string;
|
|
562
|
-
/**
|
|
563
|
-
* Subscribe to a room on this channel
|
|
564
|
-
*/
|
|
565
|
-
subscribe(roomId: string, handler: (message: Static<TClient>) => void, callbacks?: {
|
|
566
|
-
onConnect?: () => void;
|
|
567
|
-
onDisconnect?: () => void;
|
|
568
|
-
onError?: (error: Error) => void;
|
|
569
|
-
}): () => void;
|
|
570
|
-
/**
|
|
571
|
-
* Connect to WebSocket server
|
|
572
|
-
*/
|
|
573
|
-
protected connect(): Promise<void>;
|
|
574
|
-
/**
|
|
575
|
-
* Handle incoming message
|
|
576
|
-
*/
|
|
577
|
-
protected handleMessage(data: string): void;
|
|
578
|
-
/**
|
|
579
|
-
* Send message to a specific room
|
|
580
|
-
*/
|
|
581
|
-
send(roomId: string, message: Static<TServer>): Promise<void>;
|
|
582
|
-
/**
|
|
583
|
-
* Schedule reconnection
|
|
584
|
-
*/
|
|
585
|
-
protected scheduleReconnect(): void;
|
|
586
|
-
/**
|
|
587
|
-
* Disconnect from server
|
|
588
|
-
*/
|
|
589
|
-
disconnect(): void;
|
|
590
|
-
/**
|
|
591
|
-
* Reconnect manually
|
|
592
|
-
*/
|
|
593
|
-
reconnect(): void;
|
|
594
|
-
/**
|
|
595
|
-
* Check if subscribed to a room
|
|
596
|
-
*/
|
|
597
|
-
hasRoom(roomId: string): boolean;
|
|
598
|
-
/**
|
|
599
|
-
* Get all subscribed rooms
|
|
600
|
-
*/
|
|
601
|
-
getRooms(): string[];
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* WebSocket Client Service
|
|
605
|
-
*
|
|
606
|
-
* Manages WebSocket connections from the client side (browser).
|
|
607
|
-
* One connection per channel, multiple rooms per connection.
|
|
608
|
-
*/
|
|
609
|
-
declare class WebSocketClient {
|
|
610
|
-
protected readonly log: alepha_logger2.Logger;
|
|
611
|
-
protected readonly alepha: Alepha;
|
|
612
|
-
protected readonly env: {
|
|
613
|
-
WEBSOCKET_URL: string;
|
|
614
|
-
WEBSOCKET_RECONNECT_INTERVAL: number;
|
|
615
|
-
WEBSOCKET_MAX_RECONNECT_ATTEMPTS: number;
|
|
616
|
-
};
|
|
617
|
-
protected connections: Map<string, WebSocketChannelConnection<any, any>>;
|
|
618
|
-
/**
|
|
619
|
-
* Subscribe to a room on a channel
|
|
620
|
-
*/
|
|
621
|
-
subscribe<TClient extends TWSObject, TServer extends TWSObject>(roomId: string, channel: ChannelDescriptor<TClient, TServer>, handler: (message: Static<TClient>) => void, options?: {
|
|
622
|
-
url?: string;
|
|
623
|
-
autoReconnect?: boolean;
|
|
624
|
-
reconnectInterval?: number;
|
|
625
|
-
maxReconnectAttempts?: number;
|
|
626
|
-
onConnect?: () => void;
|
|
627
|
-
onDisconnect?: () => void;
|
|
628
|
-
onError?: (error: Error) => void;
|
|
629
|
-
}): () => void;
|
|
630
|
-
/**
|
|
631
|
-
* Send message to a room on a channel
|
|
632
|
-
*/
|
|
633
|
-
send<TClient extends TWSObject, TServer extends TWSObject>(roomId: string, channel: ChannelDescriptor<TClient, TServer>, message: Static<TServer>): Promise<void>;
|
|
634
|
-
/**
|
|
635
|
-
* Get connection for a channel
|
|
636
|
-
*/
|
|
637
|
-
getConnection<TClient extends TWSObject, TServer extends TWSObject>(channel: ChannelDescriptor<TClient, TServer>): WebSocketChannelConnection<TClient, TServer> | undefined;
|
|
638
|
-
/**
|
|
639
|
-
* Disconnect all connections
|
|
640
|
-
*/
|
|
641
|
-
disconnectAll(): void;
|
|
642
|
-
}
|
|
643
|
-
//#endregion
|
|
644
|
-
//#region src/websocket/services/WebSocketTopicService.d.ts
|
|
645
|
-
/**
|
|
646
|
-
* WebSocket message distribution event
|
|
647
|
-
*/
|
|
648
|
-
declare const webSocketMessageSchema: {
|
|
649
|
-
payload: alepha42.TObject<{
|
|
650
|
-
/**
|
|
651
|
-
* Channel path (e.g., "/ws/chat")
|
|
652
|
-
*/
|
|
653
|
-
channelPath: alepha42.TString;
|
|
654
|
-
/**
|
|
655
|
-
* Target room ID(s)
|
|
656
|
-
*/
|
|
657
|
-
roomIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
658
|
-
/**
|
|
659
|
-
* Target user ID(s)
|
|
660
|
-
*/
|
|
661
|
-
userIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
662
|
-
/**
|
|
663
|
-
* Target connection ID(s)
|
|
664
|
-
*/
|
|
665
|
-
connectionIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
666
|
-
/**
|
|
667
|
-
* Exclude connection ID(s) from receiving the message
|
|
668
|
-
*/
|
|
669
|
-
exceptConnectionIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
670
|
-
/**
|
|
671
|
-
* Exclude user ID(s) from receiving the message
|
|
672
|
-
*/
|
|
673
|
-
exceptUserIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
674
|
-
/**
|
|
675
|
-
* The message payload to send
|
|
676
|
-
*/
|
|
677
|
-
message: alepha42.TAny;
|
|
678
|
-
}>;
|
|
679
|
-
};
|
|
680
|
-
/**
|
|
681
|
-
* WebSocket Topic Service
|
|
682
|
-
*
|
|
683
|
-
* Manages pub/sub messaging for WebSocket connections across multiple server instances.
|
|
684
|
-
* Uses alepha/topic for cross-instance message distribution, enabling horizontal scaling.
|
|
685
|
-
*
|
|
686
|
-
* When a WebSocket message needs to be sent:
|
|
687
|
-
* 1. Server instance A publishes to the topic
|
|
688
|
-
* 2. All server instances (A, B, C, etc.) receive the message
|
|
689
|
-
* 3. Each instance sends to its local connections that match the criteria
|
|
690
|
-
*
|
|
691
|
-
* This enables:
|
|
692
|
-
* - Multiple server instances handling WebSocket connections
|
|
693
|
-
* - Redis-backed message distribution (with alepha/topic/redis)
|
|
694
|
-
* - Horizontal scaling without losing messages
|
|
695
|
-
*/
|
|
696
|
-
declare class WebSocketTopicService {
|
|
697
|
-
protected readonly log: alepha_logger2.Logger;
|
|
698
|
-
/**
|
|
699
|
-
* Handler function to be called when a message is received from the topic
|
|
700
|
-
* This is set by the WebSocket provider during initialization
|
|
701
|
-
*/
|
|
702
|
-
messageHandler?: (event: Static<(typeof webSocketMessageSchema)["payload"]>) => Promise<void>;
|
|
703
|
-
/**
|
|
704
|
-
* Topic for distributing WebSocket messages across server instances
|
|
705
|
-
*/
|
|
706
|
-
readonly topic: alepha_topic0.TopicDescriptor<{
|
|
707
|
-
payload: alepha42.TObject<{
|
|
708
|
-
/**
|
|
709
|
-
* Channel path (e.g., "/ws/chat")
|
|
710
|
-
*/
|
|
711
|
-
channelPath: alepha42.TString;
|
|
712
|
-
/**
|
|
713
|
-
* Target room ID(s)
|
|
714
|
-
*/
|
|
715
|
-
roomIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
716
|
-
/**
|
|
717
|
-
* Target user ID(s)
|
|
718
|
-
*/
|
|
719
|
-
userIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
720
|
-
/**
|
|
721
|
-
* Target connection ID(s)
|
|
722
|
-
*/
|
|
723
|
-
connectionIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
724
|
-
/**
|
|
725
|
-
* Exclude connection ID(s) from receiving the message
|
|
726
|
-
*/
|
|
727
|
-
exceptConnectionIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
728
|
-
/**
|
|
729
|
-
* Exclude user ID(s) from receiving the message
|
|
730
|
-
*/
|
|
731
|
-
exceptUserIds: alepha42.TOptional<alepha42.TArray<alepha42.TString>>;
|
|
732
|
-
/**
|
|
733
|
-
* The message payload to send
|
|
734
|
-
*/
|
|
735
|
-
message: alepha42.TAny;
|
|
736
|
-
}>;
|
|
737
|
-
}>;
|
|
738
|
-
/**
|
|
739
|
-
* Publish a message to be distributed across all server instances
|
|
740
|
-
*/
|
|
741
|
-
publish(event: Static<(typeof webSocketMessageSchema)["payload"]>): Promise<void>;
|
|
742
|
-
/**
|
|
743
|
-
* Set the handler for incoming messages
|
|
744
|
-
*/
|
|
745
|
-
setMessageHandler(handler: (event: Static<(typeof webSocketMessageSchema)["payload"]>) => Promise<void>): void;
|
|
746
|
-
}
|
|
747
|
-
//#endregion
|
|
748
|
-
//#region src/websocket/providers/NodeWebSocketServerProvider.d.ts
|
|
749
|
-
declare const envSchema: alepha42.TObject<{
|
|
750
|
-
WEBSOCKET_PATH: alepha42.TString;
|
|
751
|
-
}>;
|
|
752
|
-
declare module "alepha" {
|
|
753
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
754
|
-
}
|
|
755
|
-
declare class NodeWebSocketServerProvider extends WebSocketServerProvider {
|
|
756
|
-
protected readonly alepha: Alepha;
|
|
757
|
-
protected readonly roomManager: RoomManager;
|
|
758
|
-
protected readonly topicService: WebSocketTopicService;
|
|
759
|
-
protected readonly log: alepha_logger2.Logger;
|
|
760
|
-
protected readonly env: {
|
|
761
|
-
WEBSOCKET_PATH: string;
|
|
762
|
-
};
|
|
763
|
-
protected wss?: WebSocketServer;
|
|
764
|
-
protected endpoints: Map<string, WebSocketDescriptorOptions<any, any>>;
|
|
765
|
-
protected connections: Map<string, WebSocketConnection>;
|
|
766
|
-
protected userConnections: Map<string, Set<string>>;
|
|
767
|
-
protected nextConnectionId: number;
|
|
768
|
-
registerEndpoint<TClient extends TWSObject, TServer extends TWSObject>(config: WebSocketDescriptorOptions<TClient, TServer>): void;
|
|
769
|
-
emit<TClient extends TWSObject>(channelPath: string, options: EmitOptions<TClient>): Promise<void>;
|
|
770
|
-
getConnections(): WebSocketConnection[];
|
|
771
|
-
getRoomConnections(roomId: string): WebSocketConnection[];
|
|
772
|
-
getUserConnections(userId: string): WebSocketConnection[];
|
|
773
|
-
closeConnection(connectionId: string, code?: number, reason?: string): Promise<void>;
|
|
774
|
-
protected handleUpgrade(request: IncomingMessage, socket: any, head: Buffer): boolean;
|
|
775
|
-
protected handleConnection<TClient extends TWSObject, TServer extends TWSObject>(ws: WebSocket$1, endpoint: WebSocketDescriptorOptions<TClient, TServer>, request: IncomingMessage): void;
|
|
776
|
-
protected extractRoomIds(url: URL): string[];
|
|
777
|
-
/**
|
|
778
|
-
* Send message to local connections based on targeting criteria
|
|
779
|
-
* This is called by the topic service when a message is received
|
|
780
|
-
*/
|
|
781
|
-
protected sendToLocalConnections(channelPath: string, message: any, criteria: {
|
|
782
|
-
roomIds?: string[];
|
|
783
|
-
userIds?: string[];
|
|
784
|
-
connectionIds?: string[];
|
|
785
|
-
exceptConnectionIds?: string[];
|
|
786
|
-
exceptUserIds?: string[];
|
|
787
|
-
}): Promise<void>;
|
|
788
|
-
protected readonly start: alepha42.HookDescriptor<"start">;
|
|
789
|
-
protected readonly ready: alepha42.HookDescriptor<"ready">;
|
|
790
|
-
protected readonly stop: alepha42.HookDescriptor<"stop">;
|
|
791
|
-
}
|
|
792
|
-
declare class NodeWebSocketConnection implements WebSocketConnection {
|
|
793
|
-
readonly id: string;
|
|
794
|
-
readonly userId: string | undefined;
|
|
795
|
-
readonly roomIds: string[];
|
|
796
|
-
protected readonly ws: WebSocket$1;
|
|
797
|
-
protected readonly provider: NodeWebSocketServerProvider;
|
|
798
|
-
protected readonly endpoint: WebSocketDescriptorOptions<any, any>;
|
|
799
|
-
protected readonly log: alepha_logger2.Logger;
|
|
800
|
-
metadata?: Record<string, any>;
|
|
801
|
-
constructor(id: string, userId: string | undefined, roomIds: string[], ws: WebSocket$1, provider: NodeWebSocketServerProvider, endpoint: WebSocketDescriptorOptions<any, any>);
|
|
802
|
-
get readyState(): WebSocketState;
|
|
803
|
-
send(message: any): Promise<void>;
|
|
804
|
-
close(code?: number, reason?: string): Promise<void>;
|
|
805
|
-
handleMessage(data: any): Promise<void>;
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
//#region src/websocket/index.d.ts
|
|
809
|
-
declare module "alepha" {
|
|
810
|
-
interface Hooks {
|
|
811
|
-
/**
|
|
812
|
-
* Fires when a WebSocket connection is established
|
|
813
|
-
*/
|
|
814
|
-
"websocket:connect": {
|
|
815
|
-
connectionId: string;
|
|
816
|
-
path: string;
|
|
817
|
-
};
|
|
818
|
-
/**
|
|
819
|
-
* Fires when a WebSocket connection is closed
|
|
820
|
-
*/
|
|
821
|
-
"websocket:disconnect": {
|
|
822
|
-
connectionId: string;
|
|
823
|
-
path: string;
|
|
824
|
-
code?: number;
|
|
825
|
-
reason?: string;
|
|
826
|
-
};
|
|
827
|
-
/**
|
|
828
|
-
* Fires when a WebSocket message is received
|
|
829
|
-
*/
|
|
830
|
-
"websocket:message": {
|
|
831
|
-
connectionId: string;
|
|
832
|
-
path: string;
|
|
833
|
-
message: any;
|
|
834
|
-
};
|
|
835
|
-
/**
|
|
836
|
-
* Fires when a WebSocket error occurs
|
|
837
|
-
*/
|
|
838
|
-
"websocket:error": {
|
|
839
|
-
connectionId: string;
|
|
840
|
-
path: string;
|
|
841
|
-
error: Error;
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Provides real-time bidirectional communication using WebSockets.
|
|
847
|
-
*
|
|
848
|
-
* The WebSockets module enables building real-time applications using the `$websocket` descriptor
|
|
849
|
-
* on class properties. It provides automatic connection management, message routing, type-safe
|
|
850
|
-
* message handling, and seamless integration with other Alepha modules.
|
|
851
|
-
*
|
|
852
|
-
* On the server side (Node.js), it uses the 'ws' library to create a WebSocket server.
|
|
853
|
-
* On the client side (browser), it uses the native WebSocket API.
|
|
854
|
-
*
|
|
855
|
-
* @see {@link $websocket}
|
|
856
|
-
* @module alepha.websockets
|
|
857
|
-
*/
|
|
858
|
-
declare const AlephaWebSocket: alepha42.Service<alepha42.Module>;
|
|
859
|
-
//#endregion
|
|
860
|
-
export { $channel, $websocket, AlephaWebSocket, ChannelDescriptor, ChannelDescriptorOptions, EmitOptions, NodeWebSocketConnection, NodeWebSocketServerProvider, RoomManager, TWSObject, WebSocketChannelConnection, WebSocketClient, WebSocketConnection, WebSocketConnectionError, WebSocketDescriptor, WebSocketDescriptorOptions, WebSocketError, WebSocketHandler, WebSocketHandlerContext, WebSocketServerProvider, WebSocketState, WebSocketTopicService, WebSocketValidationError };
|
|
861
|
-
//# sourceMappingURL=index.d.cts.map
|