alepha 0.20.6 → 0.20.8

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