@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9
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/Application-DtWDHXr1.d.ts +2110 -0
- package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
- package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
- package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
- package/dist/EventManager-CmIoLt7r.d.ts +207 -0
- package/dist/Gate-CNkBYf8m.d.ts +268 -0
- package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
- package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
- package/dist/LogManager-7mxnkaPM.d.ts +256 -0
- package/dist/MailManager-DpMvYiP9.d.ts +292 -0
- package/dist/Scheduler-BstvSca7.d.ts +469 -0
- package/dist/StorageManager-oZTHqaza.d.ts +337 -0
- package/dist/api-token-JOif2CtG.d.ts +1792 -0
- package/dist/app-key-CsBfRC_Q.d.ts +214 -0
- package/dist/auth/index.d.ts +418 -0
- package/dist/auth/index.js +6742 -0
- package/dist/authorization/index.d.ts +129 -0
- package/dist/authorization/index.js +621 -0
- package/dist/broadcasting/index.d.ts +233 -0
- package/dist/broadcasting/index.js +907 -0
- package/dist/cache/index.d.ts +233 -0
- package/dist/cache/index.js +817 -0
- package/dist/encryption/index.d.ts +222 -0
- package/dist/encryption/index.js +602 -0
- package/dist/events/index.d.ts +155 -0
- package/dist/events/index.js +330 -0
- package/dist/health/index.d.ts +185 -0
- package/dist/health/index.js +379 -0
- package/dist/i18n/index.d.ts +101 -0
- package/dist/i18n/index.js +597 -0
- package/dist/index-9_Jzj5jo.d.ts +7 -0
- package/dist/index.d.ts +2628 -619
- package/dist/index.js +22229 -3116
- package/dist/lambda/index.d.ts +156 -0
- package/dist/lambda/index.js +91 -0
- package/dist/logging/index.d.ts +50 -0
- package/dist/logging/index.js +557 -0
- package/dist/mail/index.d.ts +288 -0
- package/dist/mail/index.js +695 -0
- package/dist/mcp/index.d.ts +139 -0
- package/dist/mcp/index.js +382 -0
- package/dist/notifications/index.d.ts +271 -0
- package/dist/notifications/index.js +741 -0
- package/dist/queue/index.d.ts +423 -0
- package/dist/queue/index.js +958 -0
- package/dist/runtime/index.d.ts +93 -0
- package/dist/runtime/index.js +834 -0
- package/dist/scheduling/index.d.ts +41 -0
- package/dist/scheduling/index.js +836 -0
- package/dist/storage/index.d.ts +196 -0
- package/dist/storage/index.js +832 -0
- package/dist/vite/index.js +203 -3
- package/package.json +93 -6
- package/dist/chunk-FK2XQSBF.js +0 -160
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { M as Middleware } from './index-9_Jzj5jo.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Broadcast event payload.
|
|
5
|
+
*/
|
|
6
|
+
interface BroadcastEvent {
|
|
7
|
+
channel: string;
|
|
8
|
+
event: string;
|
|
9
|
+
data: unknown;
|
|
10
|
+
timestamp: Date;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Broadcast driver interface.
|
|
14
|
+
*/
|
|
15
|
+
interface BroadcastDriver {
|
|
16
|
+
/**
|
|
17
|
+
* Publish an event to a channel.
|
|
18
|
+
*/
|
|
19
|
+
publish(channel: string, event: string, data: unknown): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Subscribe to a channel.
|
|
22
|
+
* Returns an unsubscribe function.
|
|
23
|
+
*/
|
|
24
|
+
subscribe(channel: string, callback: (event: BroadcastEvent) => void): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Unsubscribe from a channel.
|
|
27
|
+
*/
|
|
28
|
+
unsubscribe(channel: string, callback: (event: BroadcastEvent) => void): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Broadcast driver with presence support.
|
|
32
|
+
*/
|
|
33
|
+
interface PresenceBroadcastDriver extends BroadcastDriver {
|
|
34
|
+
/**
|
|
35
|
+
* Get members of a presence channel.
|
|
36
|
+
*/
|
|
37
|
+
getMembers(channel: string): PresenceMember[];
|
|
38
|
+
/**
|
|
39
|
+
* Add a member to a presence channel.
|
|
40
|
+
*/
|
|
41
|
+
addMember(channel: string, member: PresenceMember): void;
|
|
42
|
+
/**
|
|
43
|
+
* Remove a member from a presence channel.
|
|
44
|
+
*/
|
|
45
|
+
removeMember(channel: string, memberId: string | number): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Channel authorizer function.
|
|
49
|
+
*/
|
|
50
|
+
interface ChannelAuthorizer {
|
|
51
|
+
(channelName: string, user: unknown): boolean | Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Presence channel authorizer function.
|
|
55
|
+
* Returns member info if authorized, null otherwise.
|
|
56
|
+
*/
|
|
57
|
+
interface PresenceChannelAuthorizer {
|
|
58
|
+
(channelName: string, user: unknown): PresenceMember | null | Promise<PresenceMember | null>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Presence channel member.
|
|
62
|
+
*/
|
|
63
|
+
interface PresenceMember {
|
|
64
|
+
id: string | number;
|
|
65
|
+
info?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* SSE client connection.
|
|
69
|
+
*/
|
|
70
|
+
interface SSEClient {
|
|
71
|
+
id: string;
|
|
72
|
+
userId?: string | number;
|
|
73
|
+
channels: Set<string>;
|
|
74
|
+
send(event: string, data: unknown): void;
|
|
75
|
+
close(): void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* WebSocket client connection.
|
|
79
|
+
*/
|
|
80
|
+
interface WebSocketClient {
|
|
81
|
+
id: string;
|
|
82
|
+
userId?: string | number;
|
|
83
|
+
channels: Set<string>;
|
|
84
|
+
send(event: string, data: unknown): void | Promise<void>;
|
|
85
|
+
close(): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Broadcast manager options.
|
|
89
|
+
*/
|
|
90
|
+
interface BroadcastManagerOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Default driver name.
|
|
93
|
+
*/
|
|
94
|
+
default?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Driver factories.
|
|
97
|
+
*/
|
|
98
|
+
drivers?: Record<string, BroadcastDriverFactory>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Broadcast driver factory.
|
|
102
|
+
*/
|
|
103
|
+
interface BroadcastDriverFactory {
|
|
104
|
+
(): BroadcastDriver;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Channel registration.
|
|
108
|
+
*/
|
|
109
|
+
interface ChannelRegistration {
|
|
110
|
+
pattern: string;
|
|
111
|
+
type: 'public' | 'private' | 'presence';
|
|
112
|
+
authorizer: ChannelAuthorizer | PresenceChannelAuthorizer;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* SSE middleware options.
|
|
116
|
+
*/
|
|
117
|
+
interface SSEMiddlewareOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Ping interval in milliseconds.
|
|
120
|
+
*/
|
|
121
|
+
pingInterval?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Retry delay for SSE reconnection.
|
|
124
|
+
*/
|
|
125
|
+
retry?: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Auth middleware options.
|
|
129
|
+
*/
|
|
130
|
+
interface AuthMiddlewareOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Function to get user from context.
|
|
133
|
+
*/
|
|
134
|
+
getUser?: (ctx: unknown) => unknown | Promise<unknown>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Broadcasted event interface (for Event class integration).
|
|
138
|
+
*/
|
|
139
|
+
interface BroadcastableEvent {
|
|
140
|
+
/**
|
|
141
|
+
* Get channels to broadcast to.
|
|
142
|
+
*/
|
|
143
|
+
broadcastOn(): string[];
|
|
144
|
+
/**
|
|
145
|
+
* Get the event name for broadcasting.
|
|
146
|
+
*/
|
|
147
|
+
broadcastAs?(): string;
|
|
148
|
+
/**
|
|
149
|
+
* Get the data to broadcast.
|
|
150
|
+
*/
|
|
151
|
+
broadcastWith?(): Record<string, unknown>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Base broadcast channel.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const channel = new Channel('notifications', driver)
|
|
160
|
+
* await channel.broadcast('NewMessage', { content: 'Hello!' })
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare class Channel {
|
|
164
|
+
readonly name: string;
|
|
165
|
+
protected driver: BroadcastDriver;
|
|
166
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
167
|
+
/**
|
|
168
|
+
* Broadcast an event to this channel.
|
|
169
|
+
*/
|
|
170
|
+
broadcast(event: string, data: unknown): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Subscribe to events on this channel.
|
|
173
|
+
* Returns an unsubscribe function.
|
|
174
|
+
*/
|
|
175
|
+
subscribe(callback: (event: string, data: unknown) => void): () => void;
|
|
176
|
+
/**
|
|
177
|
+
* Get the full channel name for broadcasting.
|
|
178
|
+
*/
|
|
179
|
+
getChannelName(): string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Private broadcast channel.
|
|
184
|
+
*
|
|
185
|
+
* Requires authentication to subscribe.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const channel = new PrivateChannel('orders.123', driver)
|
|
190
|
+
* await channel.broadcast('OrderUpdated', { status: 'shipped' })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
declare class PrivateChannel extends Channel {
|
|
194
|
+
/**
|
|
195
|
+
* Channel name prefix.
|
|
196
|
+
*/
|
|
197
|
+
static readonly PREFIX = "private-";
|
|
198
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
199
|
+
/**
|
|
200
|
+
* Get the channel name without the private prefix.
|
|
201
|
+
*/
|
|
202
|
+
getBaseName(): string;
|
|
203
|
+
/**
|
|
204
|
+
* Check if a channel name is a private channel.
|
|
205
|
+
*/
|
|
206
|
+
static isPrivateChannel(name: string): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Normalize a channel name to include the private prefix.
|
|
209
|
+
*/
|
|
210
|
+
static normalize(name: string): string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Presence broadcast channel.
|
|
215
|
+
*
|
|
216
|
+
* Tracks members who have joined the channel.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const channel = new PresenceChannel('chat.1', driver)
|
|
221
|
+
*
|
|
222
|
+
* // Join channel
|
|
223
|
+
* await channel.join({ id: 1, info: { name: 'John' } })
|
|
224
|
+
*
|
|
225
|
+
* // Get members
|
|
226
|
+
* const members = channel.members()
|
|
227
|
+
*
|
|
228
|
+
* // Leave channel
|
|
229
|
+
* await channel.leave(1)
|
|
230
|
+
*
|
|
231
|
+
* // Broadcast
|
|
232
|
+
* await channel.broadcast('UserTyping', { userId: 1 })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare class PresenceChannel extends Channel {
|
|
236
|
+
/**
|
|
237
|
+
* Channel name prefix.
|
|
238
|
+
*/
|
|
239
|
+
static readonly PREFIX = "presence-";
|
|
240
|
+
protected presenceDriver: PresenceBroadcastDriver;
|
|
241
|
+
constructor(name: string, driver: BroadcastDriver);
|
|
242
|
+
/**
|
|
243
|
+
* Check if a driver supports presence.
|
|
244
|
+
*/
|
|
245
|
+
protected isPresenceDriver(driver: BroadcastDriver): driver is PresenceBroadcastDriver;
|
|
246
|
+
/**
|
|
247
|
+
* Get members in this channel.
|
|
248
|
+
*/
|
|
249
|
+
members(): PresenceMember[];
|
|
250
|
+
/**
|
|
251
|
+
* Join the channel.
|
|
252
|
+
*/
|
|
253
|
+
join(member: PresenceMember): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Leave the channel.
|
|
256
|
+
*/
|
|
257
|
+
leave(memberId: string | number): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Check if a member is in the channel.
|
|
260
|
+
*/
|
|
261
|
+
hasMember(memberId: string | number): boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Get member by ID.
|
|
264
|
+
*/
|
|
265
|
+
getMember(memberId: string | number): PresenceMember | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Get member count.
|
|
268
|
+
*/
|
|
269
|
+
count(): number;
|
|
270
|
+
/**
|
|
271
|
+
* Get the channel name without the presence prefix.
|
|
272
|
+
*/
|
|
273
|
+
getBaseName(): string;
|
|
274
|
+
/**
|
|
275
|
+
* Check if a channel name is a presence channel.
|
|
276
|
+
*/
|
|
277
|
+
static isPresenceChannel(name: string): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Normalize a channel name to include the presence prefix.
|
|
280
|
+
*/
|
|
281
|
+
static normalize(name: string): string;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Broadcast manager for real-time event broadcasting.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const broadcast = new BroadcastManager({
|
|
290
|
+
* default: 'memory',
|
|
291
|
+
* drivers: {
|
|
292
|
+
* memory: () => new MemoryDriver(),
|
|
293
|
+
* redis: () => new RedisDriver(redis),
|
|
294
|
+
* },
|
|
295
|
+
* })
|
|
296
|
+
*
|
|
297
|
+
* // Register channel authorizers
|
|
298
|
+
* broadcast
|
|
299
|
+
* .channel('public.*', () => true)
|
|
300
|
+
* .privateChannel('orders.{orderId}', async (channel, user) => {
|
|
301
|
+
* const orderId = channel.split('.')[1]
|
|
302
|
+
* return order.userId === user.id
|
|
303
|
+
* })
|
|
304
|
+
* .presenceChannel('chat.{roomId}', async (channel, user) => {
|
|
305
|
+
* return { id: user.id, info: { name: user.name } }
|
|
306
|
+
* })
|
|
307
|
+
*
|
|
308
|
+
* // Broadcast events
|
|
309
|
+
* await broadcast.broadcast('notifications', 'NewMessage', { content: 'Hello!' })
|
|
310
|
+
*
|
|
311
|
+
* // Or use channel helpers
|
|
312
|
+
* await broadcast.toChannel('notifications').broadcast('NewMessage', data)
|
|
313
|
+
* await broadcast.toPrivate('orders.123').broadcast('OrderUpdated', data)
|
|
314
|
+
* await broadcast.toPresence('chat.1').broadcast('UserTyping', data)
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
declare class BroadcastManager {
|
|
318
|
+
/**
|
|
319
|
+
* Default driver name.
|
|
320
|
+
*/
|
|
321
|
+
protected defaultDriver: string;
|
|
322
|
+
/**
|
|
323
|
+
* Driver factories.
|
|
324
|
+
*/
|
|
325
|
+
protected driverFactories: Map<string, BroadcastDriverFactory>;
|
|
326
|
+
/**
|
|
327
|
+
* Resolved drivers.
|
|
328
|
+
*/
|
|
329
|
+
protected resolvedDrivers: Map<string, BroadcastDriver>;
|
|
330
|
+
/**
|
|
331
|
+
* Channel registrations.
|
|
332
|
+
*/
|
|
333
|
+
protected channelRegistrations: ChannelRegistration[];
|
|
334
|
+
/**
|
|
335
|
+
* SSE clients.
|
|
336
|
+
*/
|
|
337
|
+
protected sseClients: Map<string, SSEClient>;
|
|
338
|
+
/**
|
|
339
|
+
* WebSocket clients.
|
|
340
|
+
*/
|
|
341
|
+
protected wsClients: Map<string, WebSocketClient>;
|
|
342
|
+
constructor(options?: BroadcastManagerOptions);
|
|
343
|
+
/**
|
|
344
|
+
* Register a driver factory.
|
|
345
|
+
*/
|
|
346
|
+
registerDriver(name: string, factory: BroadcastDriverFactory): this;
|
|
347
|
+
/**
|
|
348
|
+
* Get a driver by name.
|
|
349
|
+
*/
|
|
350
|
+
driver(name?: string): BroadcastDriver;
|
|
351
|
+
/**
|
|
352
|
+
* Register a public channel authorizer.
|
|
353
|
+
*/
|
|
354
|
+
channel(pattern: string, authorizer: ChannelAuthorizer): this;
|
|
355
|
+
/**
|
|
356
|
+
* Register a private channel authorizer.
|
|
357
|
+
*/
|
|
358
|
+
privateChannel(pattern: string, authorizer: ChannelAuthorizer): this;
|
|
359
|
+
/**
|
|
360
|
+
* Register a presence channel authorizer.
|
|
361
|
+
*/
|
|
362
|
+
presenceChannel(pattern: string, authorizer: PresenceChannelAuthorizer): this;
|
|
363
|
+
/**
|
|
364
|
+
* Broadcast an event to a channel.
|
|
365
|
+
*/
|
|
366
|
+
broadcast(channelName: string, event: string, data: unknown): Promise<void>;
|
|
367
|
+
/**
|
|
368
|
+
* Get a public channel.
|
|
369
|
+
*/
|
|
370
|
+
toChannel(name: string): Channel;
|
|
371
|
+
/**
|
|
372
|
+
* Get a private channel.
|
|
373
|
+
*/
|
|
374
|
+
toPrivate(name: string): PrivateChannel;
|
|
375
|
+
/**
|
|
376
|
+
* Get a presence channel.
|
|
377
|
+
*/
|
|
378
|
+
toPresence(name: string): PresenceChannel;
|
|
379
|
+
/**
|
|
380
|
+
* Authorize a channel for a user.
|
|
381
|
+
*/
|
|
382
|
+
authorize(channelName: string, user: unknown): Promise<boolean | {
|
|
383
|
+
id: string | number;
|
|
384
|
+
info?: Record<string, unknown>;
|
|
385
|
+
} | null>;
|
|
386
|
+
/**
|
|
387
|
+
* Find channel registration for a channel name.
|
|
388
|
+
*/
|
|
389
|
+
protected findChannelRegistration(channelName: string): ChannelRegistration | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* Match a channel name against a pattern.
|
|
392
|
+
*/
|
|
393
|
+
protected matchPattern(pattern: string, channelName: string): boolean;
|
|
394
|
+
/**
|
|
395
|
+
* Create SSE middleware.
|
|
396
|
+
*/
|
|
397
|
+
sseMiddleware(options?: SSEMiddlewareOptions): Middleware;
|
|
398
|
+
/**
|
|
399
|
+
* Create auth middleware for channel authorization.
|
|
400
|
+
*/
|
|
401
|
+
authMiddleware(options?: AuthMiddlewareOptions): Middleware;
|
|
402
|
+
/**
|
|
403
|
+
* Subscribe a client to a channel.
|
|
404
|
+
*/
|
|
405
|
+
subscribeClient(clientId: string, channel: string): boolean;
|
|
406
|
+
/**
|
|
407
|
+
* Register a WebSocket client and return its generated client ID.
|
|
408
|
+
*/
|
|
409
|
+
registerWebSocketClient(client: Omit<WebSocketClient, 'id' | 'channels'> & {
|
|
410
|
+
userId?: string | number;
|
|
411
|
+
}): string;
|
|
412
|
+
/**
|
|
413
|
+
* Remove a WebSocket client and close the underlying connection.
|
|
414
|
+
*/
|
|
415
|
+
removeWebSocketClient(clientId: string): boolean;
|
|
416
|
+
/**
|
|
417
|
+
* Subscribe a WebSocket client to a channel.
|
|
418
|
+
*/
|
|
419
|
+
subscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
420
|
+
/**
|
|
421
|
+
* Unsubscribe a WebSocket client from a channel.
|
|
422
|
+
*/
|
|
423
|
+
unsubscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
424
|
+
/**
|
|
425
|
+
* Get a WebSocket client by ID.
|
|
426
|
+
*/
|
|
427
|
+
getWebSocketClient(clientId: string): WebSocketClient | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* Get all WebSocket clients.
|
|
430
|
+
*/
|
|
431
|
+
getWebSocketClients(): WebSocketClient[];
|
|
432
|
+
/**
|
|
433
|
+
* Unsubscribe a client from a channel.
|
|
434
|
+
*/
|
|
435
|
+
unsubscribeClient(clientId: string, channel: string): boolean;
|
|
436
|
+
/**
|
|
437
|
+
* Get SSE client by ID.
|
|
438
|
+
*/
|
|
439
|
+
getClient(clientId: string): SSEClient | undefined;
|
|
440
|
+
/**
|
|
441
|
+
* Get all SSE clients.
|
|
442
|
+
*/
|
|
443
|
+
getClients(): SSEClient[];
|
|
444
|
+
/**
|
|
445
|
+
* Get clients subscribed to a channel.
|
|
446
|
+
*/
|
|
447
|
+
getChannelClients(channel: string): SSEClient[];
|
|
448
|
+
/**
|
|
449
|
+
* Generate a unique client ID.
|
|
450
|
+
*/
|
|
451
|
+
protected generateClientId(prefix?: 'sse' | 'ws'): string;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Set the global broadcast manager.
|
|
455
|
+
*/
|
|
456
|
+
declare function setBroadcastManager(manager: BroadcastManager): void;
|
|
457
|
+
/**
|
|
458
|
+
* Get the global broadcast manager.
|
|
459
|
+
*/
|
|
460
|
+
declare function getBroadcastManager(): BroadcastManager;
|
|
461
|
+
/**
|
|
462
|
+
* Create a broadcast manager.
|
|
463
|
+
*/
|
|
464
|
+
declare function createBroadcastManager(options?: BroadcastManagerOptions): BroadcastManager;
|
|
465
|
+
|
|
466
|
+
export { type AuthMiddlewareOptions as A, BroadcastManager as B, Channel as C, type PresenceBroadcastDriver as P, type SSEClient as S, type WebSocketClient as W, type BroadcastDriver as a, type BroadcastDriverFactory as b, type BroadcastEvent as c, type BroadcastManagerOptions as d, type BroadcastableEvent as e, type ChannelAuthorizer as f, type ChannelRegistration as g, PresenceChannel as h, type PresenceChannelAuthorizer as i, type PresenceMember as j, PrivateChannel as k, type SSEMiddlewareOptions as l, createBroadcastManager as m, getBroadcastManager as n, setBroadcastManager as s };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache store interface.
|
|
3
|
+
*/
|
|
4
|
+
interface CacheStore {
|
|
5
|
+
/**
|
|
6
|
+
* Get a value from the cache.
|
|
7
|
+
*/
|
|
8
|
+
get<T>(key: string): Promise<T | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Set a value in the cache.
|
|
11
|
+
* @param key Cache key
|
|
12
|
+
* @param value Value to cache
|
|
13
|
+
* @param ttl Time-to-live in seconds (optional)
|
|
14
|
+
*/
|
|
15
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a key exists in the cache.
|
|
18
|
+
*/
|
|
19
|
+
has(key: string): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Delete a key from the cache.
|
|
22
|
+
*/
|
|
23
|
+
delete(key: string): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Clear all items from the cache.
|
|
26
|
+
*/
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Increment a numeric value.
|
|
30
|
+
* @param key Cache key
|
|
31
|
+
* @param value Amount to increment (default: 1)
|
|
32
|
+
* @returns The new value
|
|
33
|
+
*/
|
|
34
|
+
increment(key: string, value?: number): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Decrement a numeric value.
|
|
37
|
+
* @param key Cache key
|
|
38
|
+
* @param value Amount to decrement (default: 1)
|
|
39
|
+
* @returns The new value
|
|
40
|
+
*/
|
|
41
|
+
decrement(key: string, value?: number): Promise<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Get a value from the cache, or store and return the result of the callback.
|
|
44
|
+
* @param key Cache key
|
|
45
|
+
* @param ttl Time-to-live in seconds
|
|
46
|
+
* @param callback Function to compute the value if not cached
|
|
47
|
+
*/
|
|
48
|
+
remember<T>(key: string, ttl: number, callback: () => Promise<T>): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Get a value from the cache, or store and return the result of the callback forever.
|
|
51
|
+
* @param key Cache key
|
|
52
|
+
* @param callback Function to compute the value if not cached
|
|
53
|
+
*/
|
|
54
|
+
rememberForever<T>(key: string, callback: () => Promise<T>): Promise<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Get multiple values from the cache.
|
|
57
|
+
*/
|
|
58
|
+
getMany<T>(keys: string[]): Promise<Map<string, T | null>>;
|
|
59
|
+
/**
|
|
60
|
+
* Set multiple values in the cache.
|
|
61
|
+
*/
|
|
62
|
+
setMany<T>(items: Map<string, T>, ttl?: number): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete multiple keys from the cache.
|
|
65
|
+
*/
|
|
66
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
67
|
+
/**
|
|
68
|
+
* Get the remaining TTL for a key in seconds.
|
|
69
|
+
* Returns -1 if the key has no expiration, -2 if the key does not exist.
|
|
70
|
+
*/
|
|
71
|
+
ttl(key: string): Promise<number>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Cache store that supports tagging.
|
|
75
|
+
*/
|
|
76
|
+
interface TaggableCacheStore extends CacheStore {
|
|
77
|
+
/**
|
|
78
|
+
* Get a tagged cache instance.
|
|
79
|
+
*/
|
|
80
|
+
tags(tags: string[]): TaggedCacheStore;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Tagged cache store interface.
|
|
84
|
+
*/
|
|
85
|
+
interface TaggedCacheStore extends CacheStore {
|
|
86
|
+
/**
|
|
87
|
+
* Flush all items with the current tags.
|
|
88
|
+
*/
|
|
89
|
+
flush(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get the current tags.
|
|
92
|
+
*/
|
|
93
|
+
getTags(): string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Cache store factory function.
|
|
97
|
+
*/
|
|
98
|
+
type CacheStoreFactory = () => CacheStore;
|
|
99
|
+
/**
|
|
100
|
+
* Memory store options.
|
|
101
|
+
*/
|
|
102
|
+
interface MemoryStoreOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Maximum number of items to store.
|
|
105
|
+
* @default Infinity
|
|
106
|
+
*/
|
|
107
|
+
maxSize?: number;
|
|
108
|
+
/**
|
|
109
|
+
* Check interval for expired items in milliseconds.
|
|
110
|
+
* @default 60000 (1 minute)
|
|
111
|
+
*/
|
|
112
|
+
checkPeriod?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Redis store options.
|
|
116
|
+
*/
|
|
117
|
+
interface RedisStoreOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Redis client instance (ioredis).
|
|
120
|
+
*/
|
|
121
|
+
client: unknown;
|
|
122
|
+
/**
|
|
123
|
+
* Key prefix.
|
|
124
|
+
* @default 'cache:'
|
|
125
|
+
*/
|
|
126
|
+
prefix?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* File store options.
|
|
130
|
+
*/
|
|
131
|
+
interface FileStoreOptions {
|
|
132
|
+
/**
|
|
133
|
+
* Directory path for cache files.
|
|
134
|
+
*/
|
|
135
|
+
path: string;
|
|
136
|
+
/**
|
|
137
|
+
* File extension.
|
|
138
|
+
* @default '.cache'
|
|
139
|
+
*/
|
|
140
|
+
extension?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Store configuration union type.
|
|
144
|
+
*/
|
|
145
|
+
type StoreConfig = {
|
|
146
|
+
driver: 'memory';
|
|
147
|
+
} & MemoryStoreOptions | {
|
|
148
|
+
driver: 'redis';
|
|
149
|
+
} & RedisStoreOptions | {
|
|
150
|
+
driver: 'file';
|
|
151
|
+
} & FileStoreOptions;
|
|
152
|
+
/**
|
|
153
|
+
* Cache manager configuration.
|
|
154
|
+
*/
|
|
155
|
+
interface CacheConfig {
|
|
156
|
+
/**
|
|
157
|
+
* Default store name.
|
|
158
|
+
* @default 'memory'
|
|
159
|
+
*/
|
|
160
|
+
default?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Store configurations.
|
|
163
|
+
*/
|
|
164
|
+
stores?: Record<string, StoreConfig>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Cached item with metadata.
|
|
168
|
+
*/
|
|
169
|
+
interface CachedItem<T = unknown> {
|
|
170
|
+
value: T;
|
|
171
|
+
expiresAt: number | null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Cache manager for handling multiple cache stores.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const cache = new CacheManager({
|
|
180
|
+
* default: 'redis',
|
|
181
|
+
* stores: {
|
|
182
|
+
* memory: { driver: 'memory' },
|
|
183
|
+
* redis: { driver: 'redis', client: redisClient },
|
|
184
|
+
* file: { driver: 'file', path: './storage/cache' },
|
|
185
|
+
* }
|
|
186
|
+
* })
|
|
187
|
+
*
|
|
188
|
+
* // Use the default store
|
|
189
|
+
* await cache.store().set('key', 'value', 3600)
|
|
190
|
+
*
|
|
191
|
+
* // Use a specific store
|
|
192
|
+
* await cache.store('memory').set('key', 'value')
|
|
193
|
+
*
|
|
194
|
+
* // Use tagged cache
|
|
195
|
+
* await cache.store().tags(['posts', 'user:1']).set('user:1:posts', posts)
|
|
196
|
+
* await cache.store().tags(['user:1']).flush()
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare class CacheManager {
|
|
200
|
+
private readonly defaultStoreName;
|
|
201
|
+
private readonly storeFactories;
|
|
202
|
+
private readonly resolvedStores;
|
|
203
|
+
constructor(config?: CacheConfig);
|
|
204
|
+
private driverFactories;
|
|
205
|
+
/**
|
|
206
|
+
* Register built-in store drivers.
|
|
207
|
+
*/
|
|
208
|
+
private registerBuiltinDrivers;
|
|
209
|
+
/**
|
|
210
|
+
* Register a store from configuration.
|
|
211
|
+
*/
|
|
212
|
+
private registerStoreFromConfig;
|
|
213
|
+
/**
|
|
214
|
+
* Get a cache store by name.
|
|
215
|
+
* Returns the default store if no name is specified.
|
|
216
|
+
*/
|
|
217
|
+
store(name?: string): TaggableCacheStore;
|
|
218
|
+
/**
|
|
219
|
+
* Register a custom store factory.
|
|
220
|
+
*/
|
|
221
|
+
registerStore(name: string, factory: CacheStoreFactory): void;
|
|
222
|
+
/**
|
|
223
|
+
* Register a custom driver.
|
|
224
|
+
*/
|
|
225
|
+
registerDriver(name: string, factory: (options: unknown) => CacheStore): void;
|
|
226
|
+
/**
|
|
227
|
+
* Check if a store is registered.
|
|
228
|
+
*/
|
|
229
|
+
hasStore(name: string): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Get the default store name.
|
|
232
|
+
*/
|
|
233
|
+
getDefaultStoreName(): string;
|
|
234
|
+
/**
|
|
235
|
+
* Get all registered store names.
|
|
236
|
+
*/
|
|
237
|
+
getStoreNames(): string[];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Create a cache manager with configuration.
|
|
241
|
+
*/
|
|
242
|
+
declare function createCacheManager(config?: CacheConfig): CacheManager;
|
|
243
|
+
|
|
244
|
+
export { CacheManager as C, type FileStoreOptions as F, type MemoryStoreOptions as M, type RedisStoreOptions as R, type StoreConfig as S, type TaggedCacheStore as T, type CacheConfig as a, type CacheStore as b, type CacheStoreFactory as c, createCacheManager as d, type CachedItem as e, type TaggableCacheStore as f };
|