@guren/server 2.1.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DocsViewerServiceProvider-D7RGJPGM.js → DocsViewerServiceProvider-RUYDFBMW.js} +2 -2
- package/dist/McpServiceProvider-FRJ5O7LT.js +8 -0
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +4 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/chunk-3KV5X2FL.js +31 -0
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-DSDX3ASM.js → chunk-5WL2FTC4.js} +67 -85
- package/dist/{chunk-5SZTEZ22.js → chunk-6IGN233M.js} +15 -8
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-WIXGT4TN.js → chunk-A5JJ7XTH.js} +8 -2
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-BZMZEFRG.js → chunk-LHR6OHI7.js} +11 -0
- package/dist/{chunk-JBG4AR24.js → chunk-Q2P6YLRR.js} +8 -2
- package/dist/{chunk-J6ETA476.js → chunk-TVV5YNEC.js} +101 -9
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +29 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +199 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +62 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +31 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +51 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/response-headers.d.ts +18 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +405 -180
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +152 -0
- package/dist/mcp/endpoint.d.ts +47 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +3 -3
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +45 -9
- package/dist/redis/redis-values.d.ts +17 -0
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +101 -68
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/contained-path.d.ts +26 -0
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/expiry.d.ts +47 -0
- package/dist/support/expiry.js +12 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +7 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/McpServiceProvider-7BB5FPF3.js +0 -8
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-Dx426KLn.d.ts +0 -336
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Context } from '../http/Application.js';
|
|
2
|
+
/**
|
|
3
|
+
* User type for authorization.
|
|
4
|
+
*/
|
|
5
|
+
export interface AuthUser {
|
|
6
|
+
id: string | number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Gate callback function.
|
|
10
|
+
*/
|
|
11
|
+
export type GateCallback<Args extends unknown[] = unknown[]> = {
|
|
12
|
+
bivarianceHack(user: AuthUser | null, ...args: Args): PolicyResult | Promise<PolicyResult>;
|
|
13
|
+
}['bivarianceHack'];
|
|
14
|
+
/**
|
|
15
|
+
* Gate before callbacks can short-circuit authorization.
|
|
16
|
+
* Return true to allow, false to deny, or undefined to continue.
|
|
17
|
+
*/
|
|
18
|
+
export type GateBeforeCallback<Args extends unknown[] = unknown[]> = {
|
|
19
|
+
bivarianceHack(user: AuthUser | null, ability: string, ...args: Args): PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
20
|
+
}['bivarianceHack'];
|
|
21
|
+
/**
|
|
22
|
+
* Gate definition with optional callback.
|
|
23
|
+
*/
|
|
24
|
+
export interface GateDefinition {
|
|
25
|
+
callback: GateCallback;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What a policy ability or gate callback may answer.
|
|
29
|
+
*
|
|
30
|
+
* `Response.deny()` and friends return an object, so it must be part of the
|
|
31
|
+
* type — a signature of just `boolean` is what let a denial object be read
|
|
32
|
+
* as an approval.
|
|
33
|
+
*/
|
|
34
|
+
export type PolicyResult = boolean | AuthorizationResponse;
|
|
35
|
+
/**
|
|
36
|
+
* Policy method type.
|
|
37
|
+
*/
|
|
38
|
+
export type PolicyMethod<T = unknown> = (user: AuthUser | null, model?: T, ...args: unknown[]) => PolicyResult | Promise<PolicyResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Policy class interface.
|
|
41
|
+
*/
|
|
42
|
+
export interface Policy {
|
|
43
|
+
/**
|
|
44
|
+
* Run before all other authorization checks.
|
|
45
|
+
* Return true to allow, false to deny, undefined to continue to specific check.
|
|
46
|
+
*/
|
|
47
|
+
before?(user: AuthUser | null, ability: string): PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Policy class constructor.
|
|
51
|
+
*/
|
|
52
|
+
export interface PolicyClass {
|
|
53
|
+
new (): Policy;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Authorization response.
|
|
57
|
+
*/
|
|
58
|
+
export interface AuthorizationResponse {
|
|
59
|
+
allowed: boolean;
|
|
60
|
+
message?: string;
|
|
61
|
+
code?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gate options.
|
|
65
|
+
*/
|
|
66
|
+
export interface GateOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Default user resolver from context.
|
|
69
|
+
*/
|
|
70
|
+
userResolver?: (ctx: Context) => AuthUser | null | Promise<AuthUser | null>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Authorization check options.
|
|
74
|
+
*/
|
|
75
|
+
export interface AuthorizeOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Custom message for denial.
|
|
78
|
+
*/
|
|
79
|
+
message?: string;
|
|
80
|
+
/**
|
|
81
|
+
* HTTP status code for denial.
|
|
82
|
+
*/
|
|
83
|
+
status?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Policy registration.
|
|
87
|
+
*/
|
|
88
|
+
export interface PolicyRegistration {
|
|
89
|
+
modelClass: unknown;
|
|
90
|
+
policyClass: PolicyClass;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Resource actions for policies.
|
|
94
|
+
*/
|
|
95
|
+
export type ResourceAction = 'viewAny' | 'view' | 'create' | 'update' | 'delete' | 'restore' | 'forceDelete';
|
|
96
|
+
/**
|
|
97
|
+
* Response builder for authorization.
|
|
98
|
+
*/
|
|
99
|
+
export interface ResponseBuilder {
|
|
100
|
+
allow(message?: string): AuthorizationResponse;
|
|
101
|
+
deny(message?: string, code?: string): AuthorizationResponse;
|
|
102
|
+
denyWithStatus(status: number, message?: string): AuthorizationResponse & {
|
|
103
|
+
status: number;
|
|
104
|
+
};
|
|
105
|
+
denyAsNotFound(message?: string): AuthorizationResponse & {
|
|
106
|
+
status: 404;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient } from './types.js';
|
|
2
|
+
import { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
|
|
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
|
+
*/
|
|
37
|
+
export declare class BroadcastManager {
|
|
38
|
+
/**
|
|
39
|
+
* Default driver name.
|
|
40
|
+
*/
|
|
41
|
+
protected defaultDriver: string;
|
|
42
|
+
/**
|
|
43
|
+
* Driver factories.
|
|
44
|
+
*/
|
|
45
|
+
protected driverFactories: Map<string, BroadcastDriverFactory>;
|
|
46
|
+
/**
|
|
47
|
+
* Resolved drivers.
|
|
48
|
+
*/
|
|
49
|
+
protected resolvedDrivers: Map<string, BroadcastDriver>;
|
|
50
|
+
/**
|
|
51
|
+
* Channel registrations.
|
|
52
|
+
*/
|
|
53
|
+
protected channelRegistrations: ChannelRegistration[];
|
|
54
|
+
/**
|
|
55
|
+
* SSE clients.
|
|
56
|
+
*/
|
|
57
|
+
protected sseClients: Map<string, SSEClient>;
|
|
58
|
+
/**
|
|
59
|
+
* WebSocket clients.
|
|
60
|
+
*/
|
|
61
|
+
protected wsClients: Map<string, WebSocketClient>;
|
|
62
|
+
constructor(options?: BroadcastManagerOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Register a driver factory.
|
|
65
|
+
*/
|
|
66
|
+
registerDriver(name: string, factory: BroadcastDriverFactory): this;
|
|
67
|
+
/**
|
|
68
|
+
* Get a driver by name.
|
|
69
|
+
*/
|
|
70
|
+
driver(name?: string): BroadcastDriver;
|
|
71
|
+
/**
|
|
72
|
+
* Register a public channel authorizer.
|
|
73
|
+
*/
|
|
74
|
+
channel(pattern: string, authorizer: ChannelAuthorizer): this;
|
|
75
|
+
/**
|
|
76
|
+
* Register a private channel authorizer.
|
|
77
|
+
*/
|
|
78
|
+
privateChannel(pattern: string, authorizer: ChannelAuthorizer): this;
|
|
79
|
+
/**
|
|
80
|
+
* Register a presence channel authorizer.
|
|
81
|
+
*/
|
|
82
|
+
presenceChannel(pattern: string, authorizer: PresenceChannelAuthorizer): this;
|
|
83
|
+
/**
|
|
84
|
+
* Broadcast an event to a channel.
|
|
85
|
+
*/
|
|
86
|
+
broadcast(channelName: string, event: string, data: unknown): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Get a public channel.
|
|
89
|
+
*/
|
|
90
|
+
toChannel(name: string): Channel;
|
|
91
|
+
/**
|
|
92
|
+
* Get a private channel.
|
|
93
|
+
*/
|
|
94
|
+
toPrivate(name: string): PrivateChannel;
|
|
95
|
+
/**
|
|
96
|
+
* Get a presence channel.
|
|
97
|
+
*/
|
|
98
|
+
toPresence(name: string): PresenceChannel;
|
|
99
|
+
/**
|
|
100
|
+
* Authorize a channel for a user.
|
|
101
|
+
*/
|
|
102
|
+
authorize(channelName: string, user: unknown): Promise<boolean | {
|
|
103
|
+
id: string | number;
|
|
104
|
+
info?: Record<string, unknown>;
|
|
105
|
+
} | null>;
|
|
106
|
+
/**
|
|
107
|
+
* Find channel registration for a channel name.
|
|
108
|
+
*/
|
|
109
|
+
protected findChannelRegistration(channelName: string): ChannelRegistration | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Match a channel name against a pattern.
|
|
112
|
+
*/
|
|
113
|
+
protected matchPattern(pattern: string, channelName: string): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Create SSE middleware.
|
|
116
|
+
*/
|
|
117
|
+
sseMiddleware(options?: SSEMiddlewareOptions): Middleware;
|
|
118
|
+
/**
|
|
119
|
+
* Create auth middleware for channel authorization.
|
|
120
|
+
*/
|
|
121
|
+
authMiddleware(options?: AuthMiddlewareOptions): Middleware;
|
|
122
|
+
/**
|
|
123
|
+
* Subscribe a client to a channel.
|
|
124
|
+
*/
|
|
125
|
+
subscribeClient(clientId: string, channel: string): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Register a WebSocket client and return its generated client ID.
|
|
128
|
+
*/
|
|
129
|
+
registerWebSocketClient(client: Omit<WebSocketClient, 'id' | 'channels'> & {
|
|
130
|
+
userId?: string | number;
|
|
131
|
+
}): string;
|
|
132
|
+
/**
|
|
133
|
+
* Remove a WebSocket client and close the underlying connection.
|
|
134
|
+
*/
|
|
135
|
+
removeWebSocketClient(clientId: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe a WebSocket client to a channel.
|
|
138
|
+
*/
|
|
139
|
+
subscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Unsubscribe a WebSocket client from a channel.
|
|
142
|
+
*/
|
|
143
|
+
unsubscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Get a WebSocket client by ID.
|
|
146
|
+
*/
|
|
147
|
+
getWebSocketClient(clientId: string): WebSocketClient | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Get all WebSocket clients.
|
|
150
|
+
*/
|
|
151
|
+
getWebSocketClients(): WebSocketClient[];
|
|
152
|
+
/**
|
|
153
|
+
* Unsubscribe a client from a channel.
|
|
154
|
+
*/
|
|
155
|
+
unsubscribeClient(clientId: string, channel: string): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Get SSE client by ID.
|
|
158
|
+
*/
|
|
159
|
+
getClient(clientId: string): SSEClient | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Get all SSE clients.
|
|
162
|
+
*/
|
|
163
|
+
getClients(): SSEClient[];
|
|
164
|
+
/**
|
|
165
|
+
* Get clients subscribed to a channel.
|
|
166
|
+
*/
|
|
167
|
+
getChannelClients(channel: string): SSEClient[];
|
|
168
|
+
/**
|
|
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.
|
|
181
|
+
*/
|
|
182
|
+
disconnectAll(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Generate a unique client ID.
|
|
185
|
+
*/
|
|
186
|
+
protected generateClientId(prefix?: 'sse' | 'ws'): string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Set the global broadcast manager.
|
|
190
|
+
*/
|
|
191
|
+
export declare function setBroadcastManager(manager: BroadcastManager): void;
|
|
192
|
+
/**
|
|
193
|
+
* Get the global broadcast manager.
|
|
194
|
+
*/
|
|
195
|
+
export declare function getBroadcastManager(): BroadcastManager;
|
|
196
|
+
/**
|
|
197
|
+
* Create a broadcast manager.
|
|
198
|
+
*
|
|
199
|
+
* 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.
|
|
204
|
+
*/
|
|
205
|
+
export declare function createBroadcastManager(options?: BroadcastManagerOptions): BroadcastManager;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
export declare class Channel {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
protected driver: BroadcastDriver;
|
|
14
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
15
|
+
/**
|
|
16
|
+
* Broadcast an event to this channel.
|
|
17
|
+
*/
|
|
18
|
+
broadcast(event: string, data: unknown): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Subscribe to events on this channel.
|
|
21
|
+
* Returns an unsubscribe function.
|
|
22
|
+
*/
|
|
23
|
+
subscribe(callback: (event: string, data: unknown) => void): () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Get the full channel name for broadcasting.
|
|
26
|
+
*/
|
|
27
|
+
getChannelName(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Channel } from './Channel.js';
|
|
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
|
+
*/
|
|
25
|
+
export declare class PresenceChannel extends Channel {
|
|
26
|
+
/**
|
|
27
|
+
* Channel name prefix.
|
|
28
|
+
*/
|
|
29
|
+
static readonly PREFIX = "presence-";
|
|
30
|
+
protected presenceDriver: PresenceBroadcastDriver;
|
|
31
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
32
|
+
/**
|
|
33
|
+
* Check if a driver supports presence.
|
|
34
|
+
*/
|
|
35
|
+
protected isPresenceDriver(driver: BroadcastDriver): driver is PresenceBroadcastDriver;
|
|
36
|
+
/**
|
|
37
|
+
* Get members in this channel.
|
|
38
|
+
*/
|
|
39
|
+
members(): PresenceMember[];
|
|
40
|
+
/**
|
|
41
|
+
* Join the channel.
|
|
42
|
+
*/
|
|
43
|
+
join(member: PresenceMember): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Leave the channel.
|
|
46
|
+
*/
|
|
47
|
+
leave(memberId: string | number): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a member is in the channel.
|
|
50
|
+
*/
|
|
51
|
+
hasMember(memberId: string | number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get member by ID.
|
|
54
|
+
*/
|
|
55
|
+
getMember(memberId: string | number): PresenceMember | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get member count.
|
|
58
|
+
*/
|
|
59
|
+
count(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Get the channel name without the presence prefix.
|
|
62
|
+
*/
|
|
63
|
+
getBaseName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a channel name is a presence channel.
|
|
66
|
+
*/
|
|
67
|
+
static isPresenceChannel(name: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Normalize a channel name to include the presence prefix.
|
|
70
|
+
*/
|
|
71
|
+
static normalize(name: string): string;
|
|
72
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Channel } from './Channel.js';
|
|
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
|
+
*/
|
|
14
|
+
export declare class PrivateChannel extends Channel {
|
|
15
|
+
/**
|
|
16
|
+
* Channel name prefix.
|
|
17
|
+
*/
|
|
18
|
+
static readonly PREFIX = "private-";
|
|
19
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
20
|
+
/**
|
|
21
|
+
* Get the channel name without the private prefix.
|
|
22
|
+
*/
|
|
23
|
+
getBaseName(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a channel name is a private channel.
|
|
26
|
+
*/
|
|
27
|
+
static isPrivateChannel(name: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Normalize a channel name to include the private prefix.
|
|
30
|
+
*/
|
|
31
|
+
static normalize(name: string): string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { BroadcastEvent, PresenceBroadcastDriver, PresenceMember } from '../types.js';
|
|
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
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class MemoryDriver implements PresenceBroadcastDriver {
|
|
25
|
+
/**
|
|
26
|
+
* Channel subscribers.
|
|
27
|
+
*/
|
|
28
|
+
protected subscribers: Map<string, Set<(event: BroadcastEvent) => void>>;
|
|
29
|
+
/**
|
|
30
|
+
* Presence channel members.
|
|
31
|
+
*/
|
|
32
|
+
protected presenceMembers: Map<string, Map<string | number, PresenceMember>>;
|
|
33
|
+
/**
|
|
34
|
+
* Published events (for testing).
|
|
35
|
+
*/
|
|
36
|
+
protected publishedEvents: BroadcastEvent[];
|
|
37
|
+
/**
|
|
38
|
+
* Publish an event to a channel.
|
|
39
|
+
*/
|
|
40
|
+
publish(channel: string, event: string, data: unknown): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to a channel.
|
|
43
|
+
*/
|
|
44
|
+
subscribe(channel: string, callback: (event: BroadcastEvent) => void): () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Unsubscribe from a channel.
|
|
47
|
+
*/
|
|
48
|
+
unsubscribe(channel: string, callback: (event: BroadcastEvent) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get members of a presence channel.
|
|
51
|
+
*/
|
|
52
|
+
getMembers(channel: string): PresenceMember[];
|
|
53
|
+
/**
|
|
54
|
+
* Add a member to a presence channel.
|
|
55
|
+
*/
|
|
56
|
+
addMember(channel: string, member: PresenceMember): void;
|
|
57
|
+
/**
|
|
58
|
+
* Remove a member from a presence channel.
|
|
59
|
+
*/
|
|
60
|
+
removeMember(channel: string, memberId: string | number): void;
|
|
61
|
+
/**
|
|
62
|
+
* Check if a channel has subscribers.
|
|
63
|
+
*/
|
|
64
|
+
hasSubscribers(channel: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Get subscriber count for a channel.
|
|
67
|
+
*/
|
|
68
|
+
getSubscriberCount(channel: string): number;
|
|
69
|
+
/**
|
|
70
|
+
* Get all channels with subscribers.
|
|
71
|
+
*/
|
|
72
|
+
getChannels(): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Get all presence channels.
|
|
75
|
+
*/
|
|
76
|
+
getPresenceChannels(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Get all published events (for testing).
|
|
79
|
+
*/
|
|
80
|
+
getPublishedEvents(): BroadcastEvent[];
|
|
81
|
+
/**
|
|
82
|
+
* Get published events for a specific channel.
|
|
83
|
+
*/
|
|
84
|
+
getPublishedEventsFor(channel: string): BroadcastEvent[];
|
|
85
|
+
/**
|
|
86
|
+
* Clear all data (for testing).
|
|
87
|
+
*/
|
|
88
|
+
clear(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Clear published events only.
|
|
91
|
+
*/
|
|
92
|
+
clearPublishedEvents(): void;
|
|
93
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { BroadcastEvent, PresenceBroadcastDriver, PresenceMember } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Redis client interface.
|
|
4
|
+
* Compatible with ioredis and similar clients.
|
|
5
|
+
*/
|
|
6
|
+
export interface RedisClient {
|
|
7
|
+
publish(channel: string, message: string): Promise<number>;
|
|
8
|
+
subscribe(channel: string): Promise<void>;
|
|
9
|
+
unsubscribe(channel: string): Promise<void>;
|
|
10
|
+
on(event: 'message', callback: (channel: string, message: string) => void): void;
|
|
11
|
+
hset(key: string, field: string, value: string): Promise<number>;
|
|
12
|
+
hdel(key: string, field: string): Promise<number>;
|
|
13
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
14
|
+
duplicate(): RedisClient;
|
|
15
|
+
}
|
|
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
|
+
*/
|
|
37
|
+
export declare class RedisDriver implements PresenceBroadcastDriver {
|
|
38
|
+
/**
|
|
39
|
+
* Publisher Redis client.
|
|
40
|
+
*/
|
|
41
|
+
protected publisher: RedisClient;
|
|
42
|
+
/**
|
|
43
|
+
* Subscriber Redis client.
|
|
44
|
+
*/
|
|
45
|
+
protected subscriber: RedisClient;
|
|
46
|
+
/**
|
|
47
|
+
* Local subscribers.
|
|
48
|
+
*/
|
|
49
|
+
protected subscribers: Map<string, Set<(event: BroadcastEvent) => void>>;
|
|
50
|
+
/**
|
|
51
|
+
* Local presence members cache.
|
|
52
|
+
*/
|
|
53
|
+
protected localPresence: Map<string, Map<string | number, PresenceMember>>;
|
|
54
|
+
/**
|
|
55
|
+
* Presence key prefix.
|
|
56
|
+
*/
|
|
57
|
+
protected presencePrefix: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the driver is initialized.
|
|
60
|
+
*/
|
|
61
|
+
protected initialized: boolean;
|
|
62
|
+
constructor(redis: RedisClient, options?: RedisDriverOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Setup the subscriber client.
|
|
65
|
+
*/
|
|
66
|
+
protected setupSubscriber(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Publish an event to a channel.
|
|
69
|
+
*/
|
|
70
|
+
publish(channel: string, event: string, data: unknown): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Subscribe to a channel.
|
|
73
|
+
*/
|
|
74
|
+
subscribe(channel: string, callback: (event: BroadcastEvent) => void): () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Unsubscribe from a channel.
|
|
77
|
+
*/
|
|
78
|
+
unsubscribe(channel: string, callback: (event: BroadcastEvent) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Get members of a presence channel.
|
|
81
|
+
*/
|
|
82
|
+
getMembers(channel: string): PresenceMember[];
|
|
83
|
+
/**
|
|
84
|
+
* Get members asynchronously from Redis.
|
|
85
|
+
*/
|
|
86
|
+
getMembersAsync(channel: string): Promise<PresenceMember[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Add a member to a presence channel.
|
|
89
|
+
*/
|
|
90
|
+
addMember(channel: string, member: PresenceMember): void;
|
|
91
|
+
/**
|
|
92
|
+
* Remove a member from a presence channel.
|
|
93
|
+
*/
|
|
94
|
+
removeMember(channel: string, memberId: string | number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Check if a channel has subscribers.
|
|
97
|
+
*/
|
|
98
|
+
hasSubscribers(channel: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Get subscriber count for a channel.
|
|
101
|
+
*/
|
|
102
|
+
getSubscriberCount(channel: string): number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Redis driver options.
|
|
106
|
+
*/
|
|
107
|
+
export interface RedisDriverOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Prefix for presence keys.
|
|
110
|
+
*/
|
|
111
|
+
presencePrefix?: string;
|
|
112
|
+
}
|