@guren/server 2.15.0 → 2.16.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.
Files changed (296) hide show
  1. package/dist/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
  2. package/dist/{Hash-C8aejmi8.js → Hash-D2DFd8xX.js} +7 -57
  3. package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
  4. package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
  5. package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
  6. package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
  7. package/dist/agent/AgentApprovalRequested.d.ts +11 -39
  8. package/dist/agent/approval.d.ts +76 -187
  9. package/dist/agent/audit-emitter.d.ts +16 -44
  10. package/dist/agent/audit.d.ts +20 -56
  11. package/dist/agent/derive.d.ts +32 -66
  12. package/dist/agent/dispatch.d.ts +38 -90
  13. package/dist/agent/events.d.ts +11 -19
  14. package/dist/agent/meta-tools.d.ts +18 -46
  15. package/dist/agent/public.d.ts +6 -25
  16. package/dist/agent/public.js +1 -1
  17. package/dist/agent/redact.d.ts +16 -38
  18. package/dist/agent/scopes.d.ts +23 -69
  19. package/dist/auth/AuthManager.d.ts +19 -40
  20. package/dist/auth/AuthenticatableModel.d.ts +2 -2
  21. package/dist/auth/SessionGuard.d.ts +0 -1
  22. package/dist/auth/TokenGuard.d.ts +6 -26
  23. package/dist/auth/api-token.d.ts +16 -148
  24. package/dist/auth/context.d.ts +5 -10
  25. package/dist/auth/email-verification.d.ts +29 -127
  26. package/dist/auth/index.js +1 -1
  27. package/dist/auth/oauth/index.d.ts +35 -57
  28. package/dist/auth/password/DefaultHasher.d.ts +5 -14
  29. package/dist/auth/password/PasswordHasher.d.ts +5 -13
  30. package/dist/auth/password/hash-format.d.ts +5 -13
  31. package/dist/auth/password-reset.d.ts +16 -42
  32. package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
  33. package/dist/auth/providers/UserProvider.d.ts +4 -4
  34. package/dist/auth/signed-token.d.ts +18 -0
  35. package/dist/auth/types.d.ts +9 -32
  36. package/dist/auth/utils.d.ts +6 -27
  37. package/dist/{auth-DkYoAPVn.js → auth-CbdPH4Cd.js} +169 -502
  38. package/dist/authorization/Gate.d.ts +9 -145
  39. package/dist/authorization/Policy.d.ts +6 -53
  40. package/dist/authorization/index.js +1 -1
  41. package/dist/authorization/middleware.d.ts +16 -62
  42. package/dist/authorization/types.d.ts +8 -64
  43. package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
  44. package/dist/broadcasting/BroadcastManager.d.ts +29 -149
  45. package/dist/broadcasting/channels/Channel.d.ts +1 -19
  46. package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
  47. package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
  48. package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
  49. package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
  50. package/dist/broadcasting/drivers/index.d.ts +1 -1
  51. package/dist/broadcasting/index.d.ts +1 -1
  52. package/dist/broadcasting/index.js +1 -1
  53. package/dist/broadcasting/types.d.ts +7 -88
  54. package/dist/{broadcasting-BwodCA4q.js → broadcasting-B5RzB0A2.js} +87 -414
  55. package/dist/cache/CacheManager.d.ts +8 -62
  56. package/dist/cache/TaggedCache.d.ts +2 -35
  57. package/dist/cache/index.js +1 -1
  58. package/dist/cache/stores/FileStore.d.ts +2 -36
  59. package/dist/cache/stores/MemoryStore.d.ts +2 -26
  60. package/dist/cache/stores/RedisStore.d.ts +1 -29
  61. package/dist/cache/types.d.ts +21 -128
  62. package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
  63. package/dist/client-C4TEr_Dd.js +9 -0
  64. package/dist/console/Command.d.ts +17 -126
  65. package/dist/console/ConsoleKernel.d.ts +2 -74
  66. package/dist/console/Input.d.ts +5 -113
  67. package/dist/console/Output.d.ts +3 -99
  68. package/dist/console/types.d.ts +3 -33
  69. package/dist/container/Container.d.ts +12 -103
  70. package/dist/container/ServiceProvider.d.ts +17 -61
  71. package/dist/container/bindings.d.ts +5 -26
  72. package/dist/container/defineModule.d.ts +16 -54
  73. package/dist/container/definePlugin.d.ts +12 -45
  74. package/dist/container/types.d.ts +2 -34
  75. package/dist/context-CXk_umpT.js +21 -0
  76. package/dist/database/Factory.d.ts +4 -57
  77. package/dist/database/Seeder.d.ts +8 -46
  78. package/dist/database/SeederRunner.d.ts +3 -33
  79. package/dist/database/types.d.ts +3 -24
  80. package/dist/discovery/AutoDiscovery.d.ts +10 -82
  81. package/dist/{dispatch-erOS9epZ.js → dispatch-BAwzftws.js} +32 -79
  82. package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
  83. package/dist/docs-viewer/endpoint.d.ts +5 -11
  84. package/dist/encryption/Encrypter.d.ts +5 -71
  85. package/dist/encryption/Hash.d.ts +7 -57
  86. package/dist/encryption/Random.d.ts +6 -99
  87. package/dist/encryption/index.js +3 -3
  88. package/dist/encryption/types.d.ts +10 -72
  89. package/dist/{encryption-D99Vmls3.js → encryption-uwP3Di4D.js} +9 -78
  90. package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
  91. package/dist/endpoint-Dsw3Acvq.js +26 -0
  92. package/dist/errors/ExceptionHandler.d.ts +3 -90
  93. package/dist/errors/HttpException.d.ts +2 -79
  94. package/dist/errors/debug-page.d.ts +3 -17
  95. package/dist/errors/error-page.d.ts +1 -0
  96. package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
  97. package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
  98. package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
  99. package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
  100. package/dist/errors/exceptions/ValidationException.d.ts +2 -43
  101. package/dist/errors/types.d.ts +1 -25
  102. package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
  103. package/dist/events/Event.d.ts +1 -28
  104. package/dist/events/EventManager.d.ts +5 -107
  105. package/dist/events/Listener.d.ts +7 -55
  106. package/dist/events/builtin.d.ts +0 -24
  107. package/dist/events/index.js +1 -1
  108. package/dist/events/types.d.ts +4 -22
  109. package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
  110. package/dist/facades/index.d.ts +2 -14
  111. package/dist/health/HealthCheck.d.ts +0 -24
  112. package/dist/health/HealthManager.d.ts +0 -36
  113. package/dist/health/checks/CacheCheck.d.ts +2 -17
  114. package/dist/health/checks/CustomCheck.d.ts +0 -9
  115. package/dist/health/checks/DatabaseCheck.d.ts +2 -17
  116. package/dist/health/checks/MemoryCheck.d.ts +3 -12
  117. package/dist/health/checks/RedisCheck.d.ts +1 -13
  118. package/dist/health/checks/StorageCheck.d.ts +2 -17
  119. package/dist/health/index.js +1 -1
  120. package/dist/health/types.d.ts +4 -24
  121. package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
  122. package/dist/hot-disposables-B5BXqaIH.js +167 -0
  123. package/dist/hot-reload/hot-disposables.d.ts +22 -74
  124. package/dist/hot-reload/testing.d.ts +4 -9
  125. package/dist/http/Application.d.ts +62 -208
  126. package/dist/http/FormRequest.d.ts +4 -55
  127. package/dist/http/dev-assets.d.ts +13 -31
  128. package/dist/http/dev-banner.d.ts +2 -5
  129. package/dist/http/inertia-assets.d.ts +3 -6
  130. package/dist/http/middleware/capabilities.d.ts +27 -50
  131. package/dist/http/middleware/cors.d.ts +4 -29
  132. package/dist/http/middleware/csp.d.ts +2 -25
  133. package/dist/http/middleware/csrf.d.ts +20 -95
  134. package/dist/http/middleware/detect-locale.d.ts +7 -27
  135. package/dist/http/middleware/force-https.d.ts +6 -24
  136. package/dist/http/middleware/host-authorization.d.ts +2 -12
  137. package/dist/http/middleware/loopback-guard.d.ts +15 -33
  138. package/dist/http/middleware/rate-limit.d.ts +29 -126
  139. package/dist/http/middleware/redirect-safety.d.ts +2 -20
  140. package/dist/http/middleware/request-id.d.ts +1 -14
  141. package/dist/http/middleware/request-logging.d.ts +2 -13
  142. package/dist/http/middleware/response-headers.d.ts +5 -13
  143. package/dist/http/middleware/security-headers.d.ts +2 -16
  144. package/dist/http/middleware/session.d.ts +15 -34
  145. package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
  146. package/dist/http/middleware/validation.d.ts +8 -63
  147. package/dist/http/public-assets.d.ts +11 -7
  148. package/dist/http/request.d.ts +32 -118
  149. package/dist/http/resources/CursorPaginator.d.ts +5 -64
  150. package/dist/http/resources/Paginator.d.ts +7 -84
  151. package/dist/http/resources/Resource.d.ts +9 -65
  152. package/dist/http/resources/ResourceCollection.d.ts +5 -39
  153. package/dist/http/resources/types.d.ts +10 -30
  154. package/dist/http/static-documents.d.ts +10 -20
  155. package/dist/http/validation/Validator.d.ts +25 -85
  156. package/dist/http/validation/rules.d.ts +48 -147
  157. package/dist/http/validation/types.d.ts +16 -61
  158. package/dist/http/vite-assets.d.ts +5 -28
  159. package/dist/http/vite-dev-server.d.ts +6 -9
  160. package/dist/http/vite-manifest.d.ts +19 -33
  161. package/dist/i18n/I18nManager.d.ts +12 -78
  162. package/dist/i18n/Translator.d.ts +3 -54
  163. package/dist/i18n/index.js +1 -1
  164. package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
  165. package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
  166. package/dist/i18n/pluralization.d.ts +4 -13
  167. package/dist/i18n/types.d.ts +17 -69
  168. package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
  169. package/dist/index.d.ts +2 -1
  170. package/dist/index.js +714 -3011
  171. package/dist/internal/agent-preflight.d.ts +9 -21
  172. package/dist/internal/request.d.ts +6 -19
  173. package/dist/internal/request.js +1 -1
  174. package/dist/internal/route-path.d.ts +9 -21
  175. package/dist/internal/route-path.js +9 -21
  176. package/dist/internal/zod-compat.d.ts +55 -122
  177. package/dist/internal/zod-compat.js +39 -70
  178. package/dist/internal/zod-json-schema.d.ts +18 -54
  179. package/dist/internal/zod-json-schema.js +46 -123
  180. package/dist/jsx-runtime.d.ts +3 -8
  181. package/dist/lambda/index.d.ts +17 -79
  182. package/dist/lambda/index.js +11 -59
  183. package/dist/logging/LogManager.d.ts +1 -51
  184. package/dist/logging/Logger.d.ts +8 -47
  185. package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
  186. package/dist/logging/channels/DailyFileChannel.d.ts +1 -3
  187. package/dist/logging/channels/FileChannel.d.ts +1 -3
  188. package/dist/logging/daily-file-path.d.ts +7 -16
  189. package/dist/logging/index.js +1 -1
  190. package/dist/logging/types.d.ts +13 -45
  191. package/dist/{logging-B-kngi3q.js → logging-zOY1XCtq.js} +52 -141
  192. package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
  193. package/dist/mail/Mail.d.ts +10 -106
  194. package/dist/mail/MailManager.d.ts +2 -60
  195. package/dist/mail/index.js +1 -1
  196. package/dist/mail/transports/LogTransport.d.ts +1 -4
  197. package/dist/mail/transports/MemoryTransport.d.ts +1 -63
  198. package/dist/mail/transports/ResendTransport.d.ts +1 -23
  199. package/dist/mail/transports/SmtpTransport.d.ts +1 -31
  200. package/dist/mail/types.d.ts +28 -150
  201. package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
  202. package/dist/mcp/McpServiceProvider.d.ts +4 -10
  203. package/dist/mcp/create-mcp-server.d.ts +25 -57
  204. package/dist/mcp/endpoint.d.ts +12 -36
  205. package/dist/mcp/index.js +1 -1
  206. package/dist/mvc/Controller.d.ts +46 -227
  207. package/dist/mvc/Router.d.ts +50 -129
  208. package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
  209. package/dist/mvc/inertia/shared.d.ts +6 -19
  210. package/dist/mvc/mount-route.d.ts +2 -6
  211. package/dist/mvc/view.d.ts +1 -2
  212. package/dist/notifications/Notification.d.ts +8 -75
  213. package/dist/notifications/NotificationManager.d.ts +15 -88
  214. package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
  215. package/dist/notifications/channels/MailChannel.d.ts +2 -31
  216. package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
  217. package/dist/notifications/channels/SlackChannel.d.ts +3 -48
  218. package/dist/notifications/index.js +1 -1
  219. package/dist/notifications/notifiable-type.d.ts +3 -6
  220. package/dist/notifications/registry.d.ts +8 -27
  221. package/dist/notifications/types.d.ts +16 -53
  222. package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
  223. package/dist/providers/AuthServiceProvider.d.ts +1 -3
  224. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
  225. package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
  226. package/dist/providers/CacheServiceProvider.d.ts +1 -3
  227. package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
  228. package/dist/providers/ErrorServiceProvider.d.ts +1 -4
  229. package/dist/providers/EventServiceProvider.d.ts +1 -3
  230. package/dist/providers/HealthServiceProvider.d.ts +1 -3
  231. package/dist/providers/I18nServiceProvider.d.ts +6 -10
  232. package/dist/providers/InertiaServiceProvider.d.ts +1 -4
  233. package/dist/providers/LogServiceProvider.d.ts +1 -3
  234. package/dist/providers/MailServiceProvider.d.ts +1 -3
  235. package/dist/providers/NotificationServiceProvider.d.ts +1 -3
  236. package/dist/providers/OAuthServiceProvider.d.ts +1 -3
  237. package/dist/providers/QueueServiceProvider.d.ts +1 -3
  238. package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
  239. package/dist/providers/StorageServiceProvider.d.ts +1 -3
  240. package/dist/queue/FailedJobReporter.d.ts +1 -24
  241. package/dist/queue/Job.d.ts +12 -99
  242. package/dist/queue/QueueManager.d.ts +6 -57
  243. package/dist/queue/Worker.d.ts +4 -65
  244. package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
  245. package/dist/queue/drivers/RedisDriver.d.ts +7 -65
  246. package/dist/queue/drivers/SqsDriver.d.ts +6 -57
  247. package/dist/queue/drivers/SyncDriver.d.ts +10 -13
  248. package/dist/queue/index.js +2 -2
  249. package/dist/queue/types.d.ts +10 -92
  250. package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
  251. package/dist/redis/RedisApiTokenStore.d.ts +4 -56
  252. package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
  253. package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
  254. package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
  255. package/dist/redis/RedisRateLimitStore.d.ts +16 -49
  256. package/dist/redis/RedisSessionStore.d.ts +3 -44
  257. package/dist/redis/client.d.ts +2 -32
  258. package/dist/redis/index.js +47 -232
  259. package/dist/redis/redis-values.d.ts +6 -12
  260. package/dist/redis/scan-keys.d.ts +1 -4
  261. package/dist/request-CLOYytGP.js +68 -0
  262. package/dist/runtime/index.d.ts +2 -0
  263. package/dist/runtime/index.js +50 -92
  264. package/dist/scheduling/CronParser.d.ts +0 -29
  265. package/dist/scheduling/Schedule.d.ts +1 -153
  266. package/dist/scheduling/ScheduledTask.d.ts +0 -31
  267. package/dist/scheduling/Scheduler.d.ts +0 -70
  268. package/dist/scheduling/index.js +1 -1
  269. package/dist/scheduling/types.d.ts +4 -65
  270. package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
  271. package/dist/storage/StorageManager.d.ts +0 -48
  272. package/dist/storage/drivers/LocalDriver.d.ts +1 -25
  273. package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
  274. package/dist/storage/drivers/S3Driver.d.ts +6 -36
  275. package/dist/storage/drivers/s3-acl.d.ts +5 -10
  276. package/dist/storage/index.js +1 -1
  277. package/dist/storage/types.d.ts +27 -265
  278. package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
  279. package/dist/support/contained-path.d.ts +10 -20
  280. package/dist/support/error-polyfill.d.ts +4 -6
  281. package/dist/support/expiry.d.ts +17 -33
  282. package/dist/support/expiry.js +17 -33
  283. package/dist/support/import-map.d.ts +3 -7
  284. package/dist/support/inertia-defaults.d.ts +5 -10
  285. package/dist/support/redirect-target.d.ts +4 -6
  286. package/dist/support/stack-frames.d.ts +11 -50
  287. package/dist/support/trim-slashes.d.ts +4 -7
  288. package/dist/support/warn-once.d.ts +2 -6
  289. package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
  290. package/dist/{vite-manifest-w_RSOvQW.js → vite-manifest-CTQp-SOo.js} +34 -58
  291. package/package.json +2 -2
  292. package/dist/client-Dd7vLcqp.js +0 -27
  293. package/dist/context-DoD0c7J_.js +0 -26
  294. package/dist/endpoint-D-20PiHY.js +0 -46
  295. package/dist/hot-disposables-WsTX2ySN.js +0 -281
  296. package/dist/request-CVQwpu2J.js +0 -129
@@ -1,205 +1,85 @@
1
- import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient } from './types.js';
1
+ import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient, BroadcastEvent } from './types.js';
2
2
  import { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
3
3
  import type { Middleware } from '../http/middleware/index.js';
4
- /**
5
- * Broadcast manager for real-time event broadcasting.
6
- *
7
- * @example
8
- * ```typescript
9
- * const broadcast = new BroadcastManager({
10
- * default: 'memory',
11
- * drivers: {
12
- * memory: () => new MemoryDriver(),
13
- * redis: () => new RedisDriver(redis),
14
- * },
15
- * })
16
- *
17
- * // Register channel authorizers
18
- * broadcast
19
- * .channel('public.*', () => true)
20
- * .privateChannel('orders.{orderId}', async (channel, user) => {
21
- * const orderId = channel.split('.')[1]
22
- * return order.userId === user.id
23
- * })
24
- * .presenceChannel('chat.{roomId}', async (channel, user) => {
25
- * return { id: user.id, info: { name: user.name } }
26
- * })
27
- *
28
- * // Broadcast events
29
- * await broadcast.broadcast('notifications', 'NewMessage', { content: 'Hello!' })
30
- *
31
- * // Or use channel helpers
32
- * await broadcast.toChannel('notifications').broadcast('NewMessage', data)
33
- * await broadcast.toPrivate('orders.123').broadcast('OrderUpdated', data)
34
- * await broadcast.toPresence('chat.1').broadcast('UserTyping', data)
35
- * ```
36
- */
4
+ /** Broadcast manager for real-time event broadcasting. */
37
5
  export declare class BroadcastManager {
38
- /**
39
- * Default driver name.
40
- */
41
6
  protected defaultDriver: string;
42
- /**
43
- * Driver factories.
44
- */
45
7
  protected driverFactories: Map<string, BroadcastDriverFactory>;
46
- /**
47
- * Resolved drivers.
48
- */
49
8
  protected resolvedDrivers: Map<string, BroadcastDriver>;
50
- /**
51
- * Channel registrations.
52
- */
53
9
  protected channelRegistrations: ChannelRegistration[];
54
- /**
55
- * SSE clients.
56
- */
57
10
  protected sseClients: Map<string, SSEClient>;
58
- /**
59
- * WebSocket clients.
60
- */
61
11
  protected wsClients: Map<string, WebSocketClient>;
62
- constructor(options?: BroadcastManagerOptions);
63
12
  /**
64
- * Register a driver factory.
13
+ * Driver-level unsubscribe functions, per client id and channel: the only
14
+ * handle on the subscription `driver().subscribe()` opened. Dropping it
15
+ * leaves the driver fanning out to a client that has already gone — and on
16
+ * Redis, keeps that channel's SUBSCRIBE open for as long as the process lives.
65
17
  */
18
+ protected driverSubscriptions: Map<string, Map<string, () => void>>;
19
+ constructor(options?: BroadcastManagerOptions);
66
20
  registerDriver(name: string, factory: BroadcastDriverFactory): this;
67
- /**
68
- * Get a driver by name.
69
- */
70
21
  driver(name?: string): BroadcastDriver;
71
- /**
72
- * Register a public channel authorizer.
73
- */
74
22
  channel(pattern: string, authorizer: ChannelAuthorizer): this;
75
- /**
76
- * Register a private channel authorizer.
77
- */
78
23
  privateChannel(pattern: string, authorizer: ChannelAuthorizer): this;
79
- /**
80
- * Register a presence channel authorizer.
81
- */
82
24
  presenceChannel(pattern: string, authorizer: PresenceChannelAuthorizer): this;
83
- /**
84
- * Broadcast an event to a channel.
85
- */
86
25
  broadcast(channelName: string, event: string, data: unknown): Promise<void>;
87
- /**
88
- * Get a public channel.
89
- */
90
26
  toChannel(name: string): Channel;
91
- /**
92
- * Get a private channel.
93
- */
94
27
  toPrivate(name: string): PrivateChannel;
95
- /**
96
- * Get a presence channel.
97
- */
98
28
  toPresence(name: string): PresenceChannel;
99
- /**
100
- * Authorize a channel for a user.
101
- */
102
29
  authorize(channelName: string, user: unknown): Promise<boolean | {
103
30
  id: string | number;
104
31
  info?: Record<string, unknown>;
105
32
  } | null>;
106
- /**
107
- * Find channel registration for a channel name.
108
- */
109
33
  protected findChannelRegistration(channelName: string): ChannelRegistration | undefined;
110
- /**
111
- * Match a channel name against a pattern.
112
- */
113
34
  protected matchPattern(pattern: string, channelName: string): boolean;
114
- /**
115
- * Create SSE middleware.
116
- */
117
35
  sseMiddleware(options?: SSEMiddlewareOptions): Middleware;
36
+ authMiddleware(options?: AuthMiddlewareOptions): Middleware;
37
+ subscribeClient(clientId: string, channel: string): boolean;
118
38
  /**
119
- * Create auth middleware for channel authorization.
39
+ * Open one driver subscription for a client/channel pair, keeping its
40
+ * unsubscribe handle so the pair can be torn down later.
41
+ *
42
+ * A pair that is already subscribed is left alone: a second `subscribe`
43
+ * would register a second callback and deliver every event twice.
120
44
  */
121
- authMiddleware(options?: AuthMiddlewareOptions): Middleware;
45
+ protected openDriverSubscription(clientId: string, channel: string, callback: (event: BroadcastEvent) => void): void;
122
46
  /**
123
- * Subscribe a client to a channel.
47
+ * Close the driver subscription for one client/channel pair.
124
48
  */
125
- subscribeClient(clientId: string, channel: string): boolean;
49
+ protected closeDriverSubscription(clientId: string, channel: string): void;
126
50
  /**
127
- * Register a WebSocket client and return its generated client ID.
51
+ * Close every driver subscription a client holds.
128
52
  */
53
+ protected releaseDriverSubscriptions(clientId: string): void;
54
+ /** Returns the generated client ID. */
129
55
  registerWebSocketClient(client: Omit<WebSocketClient, 'id' | 'channels'> & {
130
56
  userId?: string | number;
131
57
  }): string;
132
- /**
133
- * Remove a WebSocket client and close the underlying connection.
134
- */
135
58
  removeWebSocketClient(clientId: string): boolean;
136
- /**
137
- * Subscribe a WebSocket client to a channel.
138
- */
139
59
  subscribeWebSocketClient(clientId: string, channel: string): boolean;
140
- /**
141
- * Unsubscribe a WebSocket client from a channel.
142
- */
143
60
  unsubscribeWebSocketClient(clientId: string, channel: string): boolean;
144
- /**
145
- * Get a WebSocket client by ID.
146
- */
147
61
  getWebSocketClient(clientId: string): WebSocketClient | undefined;
148
- /**
149
- * Get all WebSocket clients.
150
- */
151
62
  getWebSocketClients(): WebSocketClient[];
152
- /**
153
- * Unsubscribe a client from a channel.
154
- */
155
63
  unsubscribeClient(clientId: string, channel: string): boolean;
156
- /**
157
- * Get SSE client by ID.
158
- */
159
64
  getClient(clientId: string): SSEClient | undefined;
160
- /**
161
- * Get all SSE clients.
162
- */
163
65
  getClients(): SSEClient[];
164
- /**
165
- * Get clients subscribed to a channel.
166
- */
167
66
  getChannelClients(channel: string): SSEClient[];
168
67
  /**
169
- * Close every SSE connection this manager is holding.
170
- *
171
- * Each connection owns a ping timer that is only cleared when the stream is
172
- * cancelled or the request aborts. `Bun.serve().stop()` without forcing waits
173
- * for in-flight requests instead of cutting them, and an SSE response never
174
- * finishes — so on a hot reload those connections outlive the manager, and
175
- * their timers go on pinging a stream nobody reads.
176
- *
177
- * `getClients()` returns a snapshot. A `Map` iterator does tolerate an entry
178
- * deleting itself, which is all `cleanup()` does today — but not a `close()`
179
- * that reaches another client, which would drop that one from the iteration
180
- * unvisited and leave its timer running.
68
+ * Close every SSE connection this manager holds. Each owns a ping timer that
69
+ * is only cleared on stream cancel or request abort, and `Bun.serve().stop()`
70
+ * waits for in-flight requests while an SSE response never finishes — so on a
71
+ * hot reload the timers would go on pinging. `getClients()` is a snapshot: a
72
+ * `close()` reaching another client would drop it from a live iteration.
181
73
  */
182
74
  disconnectAll(): void;
183
- /**
184
- * Generate a unique client ID.
185
- */
186
75
  protected generateClientId(prefix?: 'sse' | 'ws'): string;
187
76
  }
188
- /**
189
- * Set the global broadcast manager.
190
- */
191
77
  export declare function setBroadcastManager(manager: BroadcastManager): void;
192
- /**
193
- * Get the global broadcast manager.
194
- */
195
78
  export declare function getBroadcastManager(): BroadcastManager;
196
79
  /**
197
- * Create a broadcast manager.
198
- *
199
80
  * Under `bun --hot`, the manager this one replaces has its SSE connections
200
- * closed first, so their ping timers stop with it. Registered from the factory
201
- * rather than the constructor because the factory is what application code
202
- * calls: frame 2 of the stack is the provider that built the manager, not this
203
- * file. A bare `new BroadcastManager()` is left alone.
81
+ * closed first, so their ping timers stop with it. Claimed from the factory
82
+ * rather than the constructor because frame 2 of the stack must be the caller's
83
+ * provider; a bare `new BroadcastManager()` is left alone.
204
84
  */
205
85
  export declare function createBroadcastManager(options?: BroadcastManagerOptions): BroadcastManager;
@@ -1,28 +1,10 @@
1
1
  import type { BroadcastDriver } from '../types.js';
2
- /**
3
- * Base broadcast channel.
4
- *
5
- * @example
6
- * ```typescript
7
- * const channel = new Channel('notifications', driver)
8
- * await channel.broadcast('NewMessage', { content: 'Hello!' })
9
- * ```
10
- */
11
2
  export declare class Channel {
12
3
  readonly name: string;
13
4
  protected driver: BroadcastDriver;
14
5
  constructor(name: string, driver: BroadcastDriver);
15
- /**
16
- * Broadcast an event to this channel.
17
- */
18
6
  broadcast(event: string, data: unknown): Promise<void>;
19
- /**
20
- * Subscribe to events on this channel.
21
- * Returns an unsubscribe function.
22
- */
7
+ /** Returns an unsubscribe function. */
23
8
  subscribe(callback: (event: string, data: unknown) => void): () => void;
24
- /**
25
- * Get the full channel name for broadcasting.
26
- */
27
9
  getChannelName(): string;
28
10
  }
@@ -1,72 +1,18 @@
1
1
  import { Channel } from './Channel.js';
2
2
  import type { BroadcastDriver, PresenceBroadcastDriver, PresenceMember } from '../types.js';
3
- /**
4
- * Presence broadcast channel.
5
- *
6
- * Tracks members who have joined the channel.
7
- *
8
- * @example
9
- * ```typescript
10
- * const channel = new PresenceChannel('chat.1', driver)
11
- *
12
- * // Join channel
13
- * await channel.join({ id: 1, info: { name: 'John' } })
14
- *
15
- * // Get members
16
- * const members = channel.members()
17
- *
18
- * // Leave channel
19
- * await channel.leave(1)
20
- *
21
- * // Broadcast
22
- * await channel.broadcast('UserTyping', { userId: 1 })
23
- * ```
24
- */
3
+ /** Broadcast channel that tracks the members who have joined it. */
25
4
  export declare class PresenceChannel extends Channel {
26
- /**
27
- * Channel name prefix.
28
- */
29
5
  static readonly PREFIX = "presence-";
30
6
  protected presenceDriver: PresenceBroadcastDriver;
31
7
  constructor(name: string, driver: BroadcastDriver);
32
- /**
33
- * Check if a driver supports presence.
34
- */
35
8
  protected isPresenceDriver(driver: BroadcastDriver): driver is PresenceBroadcastDriver;
36
- /**
37
- * Get members in this channel.
38
- */
39
9
  members(): PresenceMember[];
40
- /**
41
- * Join the channel.
42
- */
43
10
  join(member: PresenceMember): Promise<void>;
44
- /**
45
- * Leave the channel.
46
- */
47
11
  leave(memberId: string | number): Promise<void>;
48
- /**
49
- * Check if a member is in the channel.
50
- */
51
12
  hasMember(memberId: string | number): boolean;
52
- /**
53
- * Get member by ID.
54
- */
55
13
  getMember(memberId: string | number): PresenceMember | undefined;
56
- /**
57
- * Get member count.
58
- */
59
14
  count(): number;
60
- /**
61
- * Get the channel name without the presence prefix.
62
- */
63
15
  getBaseName(): string;
64
- /**
65
- * Check if a channel name is a presence channel.
66
- */
67
16
  static isPresenceChannel(name: string): boolean;
68
- /**
69
- * Normalize a channel name to include the presence prefix.
70
- */
71
17
  static normalize(name: string): string;
72
18
  }
@@ -1,32 +1,10 @@
1
1
  import { Channel } from './Channel.js';
2
2
  import type { BroadcastDriver } from '../types.js';
3
- /**
4
- * Private broadcast channel.
5
- *
6
- * Requires authentication to subscribe.
7
- *
8
- * @example
9
- * ```typescript
10
- * const channel = new PrivateChannel('orders.123', driver)
11
- * await channel.broadcast('OrderUpdated', { status: 'shipped' })
12
- * ```
13
- */
3
+ /** Broadcast channel that requires authentication to subscribe. */
14
4
  export declare class PrivateChannel extends Channel {
15
- /**
16
- * Channel name prefix.
17
- */
18
5
  static readonly PREFIX = "private-";
19
6
  constructor(name: string, driver: BroadcastDriver);
20
- /**
21
- * Get the channel name without the private prefix.
22
- */
23
7
  getBaseName(): string;
24
- /**
25
- * Check if a channel name is a private channel.
26
- */
27
8
  static isPrivateChannel(name: string): boolean;
28
- /**
29
- * Normalize a channel name to include the private prefix.
30
- */
31
9
  static normalize(name: string): string;
32
10
  }
@@ -1,93 +1,41 @@
1
1
  import type { BroadcastEvent, PresenceBroadcastDriver, PresenceMember } from '../types.js';
2
2
  /**
3
- * Memory broadcast driver.
4
- *
5
- * Stores all subscriptions and presence data in memory.
6
- * Useful for testing and single-server deployments.
7
- *
8
- * @example
9
- * ```typescript
10
- * const driver = new MemoryDriver()
11
- *
12
- * // Subscribe to a channel
13
- * const unsubscribe = driver.subscribe('notifications', (event) => {
14
- * console.log('Received:', event)
15
- * })
16
- *
17
- * // Publish an event
18
- * await driver.publish('notifications', 'NewMessage', { content: 'Hello!' })
19
- *
20
- * // Unsubscribe
21
- * unsubscribe()
22
- * ```
3
+ * Memory broadcast driver options.
23
4
  */
24
- export declare class MemoryDriver implements PresenceBroadcastDriver {
5
+ export interface MemoryDriverOptions {
25
6
  /**
26
- * Channel subscribers.
7
+ * How many published events `getPublishedEvents()` keeps, oldest dropped
8
+ * first; `0` turns recording off. The record is for tests, but the driver
9
+ * also serves single-server deployments, where an unbounded one is a leak.
10
+ * @default 1000
27
11
  */
12
+ maxPublishedEvents?: number;
13
+ }
14
+ /**
15
+ * Keeps subscriptions and presence data in memory — for testing and
16
+ * single-server deployments.
17
+ */
18
+ export declare class MemoryDriver implements PresenceBroadcastDriver {
28
19
  protected subscribers: Map<string, Set<(event: BroadcastEvent) => void>>;
29
- /**
30
- * Presence channel members.
31
- */
32
20
  protected presenceMembers: Map<string, Map<string | number, PresenceMember>>;
33
- /**
34
- * Published events (for testing).
35
- */
21
+ /** Kept for testing only, capped at `maxPublishedEvents`. */
36
22
  protected publishedEvents: BroadcastEvent[];
37
- /**
38
- * Publish an event to a channel.
39
- */
23
+ protected maxPublishedEvents: number;
24
+ constructor(options?: MemoryDriverOptions);
40
25
  publish(channel: string, event: string, data: unknown): Promise<void>;
41
- /**
42
- * Subscribe to a channel.
43
- */
26
+ protected recordPublishedEvent(event: BroadcastEvent): void;
44
27
  subscribe(channel: string, callback: (event: BroadcastEvent) => void): () => void;
45
- /**
46
- * Unsubscribe from a channel.
47
- */
48
28
  unsubscribe(channel: string, callback: (event: BroadcastEvent) => void): void;
49
- /**
50
- * Get members of a presence channel.
51
- */
52
29
  getMembers(channel: string): PresenceMember[];
53
- /**
54
- * Add a member to a presence channel.
55
- */
56
30
  addMember(channel: string, member: PresenceMember): void;
57
- /**
58
- * Remove a member from a presence channel.
59
- */
60
31
  removeMember(channel: string, memberId: string | number): void;
61
- /**
62
- * Check if a channel has subscribers.
63
- */
64
32
  hasSubscribers(channel: string): boolean;
65
- /**
66
- * Get subscriber count for a channel.
67
- */
68
33
  getSubscriberCount(channel: string): number;
69
- /**
70
- * Get all channels with subscribers.
71
- */
72
34
  getChannels(): string[];
73
- /**
74
- * Get all presence channels.
75
- */
76
35
  getPresenceChannels(): string[];
77
- /**
78
- * Get all published events (for testing).
79
- */
36
+ /** The newest `maxPublishedEvents` at most. */
80
37
  getPublishedEvents(): BroadcastEvent[];
81
- /**
82
- * Get published events for a specific channel.
83
- */
84
38
  getPublishedEventsFor(channel: string): BroadcastEvent[];
85
- /**
86
- * Clear all data (for testing).
87
- */
88
39
  clear(): void;
89
- /**
90
- * Clear published events only.
91
- */
92
40
  clearPublishedEvents(): void;
93
41
  }
@@ -1,8 +1,5 @@
1
1
  import type { BroadcastEvent, PresenceBroadcastDriver, PresenceMember } from '../types.js';
2
- /**
3
- * Redis client interface.
4
- * Compatible with ioredis and similar clients.
5
- */
2
+ /** Compatible with ioredis and similar clients. */
6
3
  export interface RedisClient {
7
4
  publish(channel: string, message: string): Promise<number>;
8
5
  subscribe(channel: string): Promise<void>;
@@ -13,100 +10,26 @@ export interface RedisClient {
13
10
  hgetall(key: string): Promise<Record<string, string>>;
14
11
  duplicate(): RedisClient;
15
12
  }
16
- /**
17
- * Redis broadcast driver.
18
- *
19
- * Uses Redis pub/sub for multi-server deployments.
20
- *
21
- * @example
22
- * ```typescript
23
- * import Redis from 'ioredis'
24
- *
25
- * const redis = new Redis()
26
- * const driver = new RedisDriver(redis)
27
- *
28
- * // Subscribe to a channel
29
- * driver.subscribe('notifications', (event) => {
30
- * console.log('Received:', event)
31
- * })
32
- *
33
- * // Publish an event
34
- * await driver.publish('notifications', 'NewMessage', { content: 'Hello!' })
35
- * ```
36
- */
13
+ /** Uses Redis pub/sub, for multi-server deployments. */
37
14
  export declare class RedisDriver implements PresenceBroadcastDriver {
38
- /**
39
- * Publisher Redis client.
40
- */
41
15
  protected publisher: RedisClient;
42
- /**
43
- * Subscriber Redis client.
44
- */
45
16
  protected subscriber: RedisClient;
46
- /**
47
- * Local subscribers.
48
- */
49
17
  protected subscribers: Map<string, Set<(event: BroadcastEvent) => void>>;
50
- /**
51
- * Local presence members cache.
52
- */
53
18
  protected localPresence: Map<string, Map<string | number, PresenceMember>>;
54
- /**
55
- * Presence key prefix.
56
- */
57
19
  protected presencePrefix: string;
58
- /**
59
- * Whether the driver is initialized.
60
- */
61
- protected initialized: boolean;
62
20
  constructor(redis: RedisClient, options?: RedisDriverOptions);
63
- /**
64
- * Setup the subscriber client.
65
- */
66
21
  protected setupSubscriber(): void;
67
- /**
68
- * Publish an event to a channel.
69
- */
70
22
  publish(channel: string, event: string, data: unknown): Promise<void>;
71
- /**
72
- * Subscribe to a channel.
73
- */
74
23
  subscribe(channel: string, callback: (event: BroadcastEvent) => void): () => void;
75
- /**
76
- * Unsubscribe from a channel.
77
- */
78
24
  unsubscribe(channel: string, callback: (event: BroadcastEvent) => void): void;
79
- /**
80
- * Get members of a presence channel.
81
- */
82
25
  getMembers(channel: string): PresenceMember[];
83
- /**
84
- * Get members asynchronously from Redis.
85
- */
86
26
  getMembersAsync(channel: string): Promise<PresenceMember[]>;
87
- /**
88
- * Add a member to a presence channel.
89
- */
90
27
  addMember(channel: string, member: PresenceMember): void;
91
- /**
92
- * Remove a member from a presence channel.
93
- */
94
28
  removeMember(channel: string, memberId: string | number): void;
95
- /**
96
- * Check if a channel has subscribers.
97
- */
98
29
  hasSubscribers(channel: string): boolean;
99
- /**
100
- * Get subscriber count for a channel.
101
- */
102
30
  getSubscriberCount(channel: string): number;
103
31
  }
104
- /**
105
- * Redis driver options.
106
- */
107
32
  export interface RedisDriverOptions {
108
- /**
109
- * Prefix for presence keys.
110
- */
33
+ /** Prefix for presence keys. */
111
34
  presencePrefix?: string;
112
35
  }
@@ -1,2 +1,2 @@
1
- export { MemoryDriver } from './MemoryDriver.js';
1
+ export { MemoryDriver, type MemoryDriverOptions } from './MemoryDriver.js';
2
2
  export { RedisDriver, type RedisClient, type RedisDriverOptions, } from './RedisDriver.js';
@@ -3,4 +3,4 @@ export { BroadcastManager, setBroadcastManager, getBroadcastManager, createBroad
3
3
  export { createTypedBroadcaster, } from './typed.js';
4
4
  export type { TypedBroadcaster, TypedChannelHandle, TypedPrivateChannelHandle, TypedPresenceChannelHandle, } from './typed.js';
5
5
  export { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
6
- export { MemoryDriver, RedisDriver, type RedisClient, type RedisDriverOptions, } from './drivers/index.js';
6
+ export { MemoryDriver, RedisDriver, type MemoryDriverOptions, type RedisClient, type RedisDriverOptions, } from './drivers/index.js';
@@ -1,2 +1,2 @@
1
- import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-BwodCA4q.js";
1
+ import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-B5RzB0A2.js";
2
2
  export { BroadcastManager, Channel, MemoryDriver, PresenceChannel, PrivateChannel, RedisDriver, createBroadcastManager, createTypedBroadcaster, getBroadcastManager, setBroadcastManager };