@guren/server 1.3.0 → 1.5.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 (51) hide show
  1. package/dist/{Application-DImeY-VW.d.ts → Application-Bi-olFMF.d.ts} +387 -18
  2. package/dist/{AuthManager-BU8ZvenF.d.ts → AuthManager-C84xF5ks.d.ts} +1 -1
  3. package/dist/{BroadcastManager-CGWl9rUO.d.ts → BroadcastManager-D8KoJxiV.d.ts} +21 -0
  4. package/dist/{CacheManager-BkvHEOZX.d.ts → CacheManager-BmDzUKrF.d.ts} +17 -0
  5. package/dist/ConsoleKernel-D0dkFt6u.d.ts +101 -0
  6. package/dist/{McpServiceProvider-RNTDHZAZ.js → McpServiceProvider-TZWQWXCT.js} +2 -2
  7. package/dist/{Scheduler-BstvSca7.d.ts → Scheduler-pZiT8i57.d.ts} +2 -0
  8. package/dist/{api-token-CB12xnVg.d.ts → api-token-COQHXyM_.d.ts} +68 -1
  9. package/dist/auth/index.d.ts +5 -5
  10. package/dist/auth/index.js +1 -1
  11. package/dist/authorization/index.js +2 -2
  12. package/dist/broadcasting/index.d.ts +2 -2
  13. package/dist/broadcasting/index.js +2 -1
  14. package/dist/cache/index.d.ts +2 -2
  15. package/dist/cache/index.js +2 -1
  16. package/dist/{chunk-EGU5KB7V.js → chunk-4SBGSJNT.js} +31 -1
  17. package/dist/{chunk-CSDKWLFD.js → chunk-5AD7LYWO.js} +111 -35
  18. package/dist/{chunk-THSX7OOR.js → chunk-63SKW5PS.js} +3 -0
  19. package/dist/{chunk-R2TCP7D7.js → chunk-6J6B5KOB.js} +18 -2
  20. package/dist/{chunk-VY2JPS6V.js → chunk-AUXQISW5.js} +83 -11
  21. package/dist/chunk-DCYKSYAT.js +63 -0
  22. package/dist/{chunk-ZRBLZY3M.js → chunk-FZD2AKJI.js} +1 -1
  23. package/dist/{chunk-HKQSAFSN.js → chunk-MC752CQT.js} +15 -0
  24. package/dist/{chunk-J753UWAY.js → chunk-NQCZQAJL.js} +93 -28
  25. package/dist/{chunk-STZUODC3.js → chunk-NYQGAWDN.js} +44 -1
  26. package/dist/{chunk-EDRGAM6G.js → chunk-RNXTRWKL.js} +2 -1
  27. package/dist/{chunk-CSP7W3WY.js → chunk-SHYRVOMJ.js} +2 -2
  28. package/dist/{chunk-44F7JQ7I.js → chunk-XMQZENBP.js} +35 -1
  29. package/dist/{chunk-WJJ5CTNI.js → chunk-Z3HXKWI6.js} +2 -2
  30. package/dist/{client-CKXJLsTe.d.ts → client-BQwF2b9Y.d.ts} +7 -0
  31. package/dist/{email-verification-D9u7krkn.d.ts → email-verification-H_WlpsVH.d.ts} +1 -1
  32. package/dist/{errors-JOOPDDQ6.js → errors-PUNHAFL2.js} +1 -1
  33. package/dist/index.d.ts +35 -17
  34. package/dist/index.js +329 -132
  35. package/dist/lambda/index.d.ts +7 -7
  36. package/dist/lambda/index.js +1 -1
  37. package/dist/mail/index.js +3 -3
  38. package/dist/mcp/index.d.ts +53 -19
  39. package/dist/mcp/index.js +2 -2
  40. package/dist/notifications/index.d.ts +57 -8
  41. package/dist/notifications/index.js +11 -3
  42. package/dist/queue/index.d.ts +7 -7
  43. package/dist/queue/index.js +4 -2
  44. package/dist/redis/index.d.ts +11 -21
  45. package/dist/redis/index.js +42 -6
  46. package/dist/runtime/index.d.ts +7 -7
  47. package/dist/runtime/index.js +1 -1
  48. package/dist/scheduling/index.d.ts +2 -2
  49. package/dist/scheduling/index.js +2 -1
  50. package/package.json +2 -2
  51. package/dist/ConsoleKernel-COKndy_V.d.ts +0 -207
@@ -0,0 +1,101 @@
1
+ import { C as CommandClass, a as Container, O as OutputInterface, b as ConsoleKernelOptions } from './Application-Bi-olFMF.js';
2
+
3
+ /**
4
+ * Console kernel for managing and executing commands.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const kernel = new ConsoleKernel()
9
+ *
10
+ * kernel.register(CreateUserCommand)
11
+ * kernel.register(SendNotificationsCommand)
12
+ *
13
+ * // Execute command
14
+ * const exitCode = await kernel.handle(['users:create', 'john@example.com', '--admin'])
15
+ * ```
16
+ */
17
+ declare class ConsoleKernel {
18
+ /**
19
+ * Registered commands.
20
+ */
21
+ protected commands: Map<string, CommandClass>;
22
+ /**
23
+ * Service container.
24
+ */
25
+ protected container?: Container;
26
+ /**
27
+ * Output instance.
28
+ */
29
+ protected output: OutputInterface;
30
+ constructor(options?: ConsoleKernelOptions);
31
+ /**
32
+ * Register a command.
33
+ */
34
+ register(command: CommandClass): this;
35
+ /**
36
+ * Register multiple commands.
37
+ */
38
+ registerMany(commands: CommandClass[]): this;
39
+ /**
40
+ * Get all registered commands.
41
+ */
42
+ getCommands(): Map<string, CommandClass>;
43
+ /**
44
+ * Get a command by name.
45
+ */
46
+ getCommand(name: string): CommandClass | undefined;
47
+ /**
48
+ * Check if a command is registered.
49
+ */
50
+ hasCommand(name: string): boolean;
51
+ /**
52
+ * Set the output instance.
53
+ */
54
+ setOutput(output: OutputInterface): this;
55
+ /**
56
+ * Get the output instance.
57
+ */
58
+ getOutput(): OutputInterface;
59
+ /**
60
+ * Handle command execution.
61
+ */
62
+ handle(argv?: string[]): Promise<number>;
63
+ /**
64
+ * Run a command.
65
+ */
66
+ protected runCommand(CommandClass: CommandClass, args: string[]): Promise<number>;
67
+ /**
68
+ * Show help.
69
+ */
70
+ protected showHelp(): void;
71
+ /**
72
+ * Show help for a specific command.
73
+ */
74
+ protected showCommandHelp(commandName: string): void;
75
+ /**
76
+ * List all commands.
77
+ */
78
+ protected listCommands(): void;
79
+ /**
80
+ * Group commands by namespace.
81
+ */
82
+ protected groupCommands(): Map<string, Map<string, CommandClass>>;
83
+ /**
84
+ * Suggest similar commands.
85
+ */
86
+ protected suggestCommands(input: string): void;
87
+ /**
88
+ * Calculate string similarity (simple Dice coefficient).
89
+ */
90
+ protected similarity(a: string, b: string): number;
91
+ /**
92
+ * Call a command programmatically.
93
+ */
94
+ call(commandName: string, args?: string[], silent?: boolean): Promise<number>;
95
+ }
96
+ /**
97
+ * Create a console kernel.
98
+ */
99
+ declare function createConsoleKernel(options?: ConsoleKernelOptions): ConsoleKernel;
100
+
101
+ export { ConsoleKernel as C, createConsoleKernel as c };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  McpServiceProvider
3
- } from "./chunk-J753UWAY.js";
4
- import "./chunk-STZUODC3.js";
3
+ } from "./chunk-NQCZQAJL.js";
4
+ import "./chunk-NYQGAWDN.js";
5
5
  export {
6
6
  McpServiceProvider
7
7
  };
@@ -399,6 +399,8 @@ declare class Scheduler {
399
399
  private interval;
400
400
  private isRunning;
401
401
  private lastCheck;
402
+ /** This scheduler's claim on its hot-reload slot while it is running. */
403
+ private hotReloadClaim;
402
404
  constructor(options?: SchedulerOptions);
403
405
  /**
404
406
  * Define schedules using a callback.
@@ -15,6 +15,14 @@ interface SessionStore {
15
15
  * Destroy a session. Implementations must treat repeated calls as safe.
16
16
  */
17
17
  destroy(id: string): Promise<void>;
18
+ /**
19
+ * Optional: refresh an existing session's TTL without rewriting its data.
20
+ * The middleware uses this for unchanged sessions (rolling expiry); stores
21
+ * that omit it fall back to a full `write`. Refreshing a session that no
22
+ * longer exists — including one that has expired but not yet been swept
23
+ * from storage — must be a no-op, not a resurrection.
24
+ */
25
+ touch?(id: string, ttlSeconds: number): Promise<void>;
18
26
  }
19
27
  declare class MemorySessionStore implements SessionStore {
20
28
  private readonly now;
@@ -23,6 +31,7 @@ declare class MemorySessionStore implements SessionStore {
23
31
  read(id: string): Promise<SessionData | undefined>;
24
32
  write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
25
33
  destroy(id: string): Promise<void>;
34
+ touch(id: string, ttlSeconds: number): Promise<void>;
26
35
  }
27
36
  interface SessionOptions {
28
37
  cookieName?: string;
@@ -44,6 +53,14 @@ interface Session {
44
53
  forget(key: string): void;
45
54
  flush(): void;
46
55
  all(): SessionData;
56
+ /**
57
+ * Rotate the session id (call after login to mitigate session fixation).
58
+ * The new id is persisted and the old one destroyed at request end. Known
59
+ * limitation shared by every multi-process store: a concurrent request
60
+ * still carrying the old cookie can re-persist the old id afterwards; the
61
+ * resurrected row holds only pre-rotation data (no auth state), so
62
+ * fixation does not escalate, but the row can linger until it expires.
63
+ */
47
64
  regenerate(): void;
48
65
  invalidate(): void;
49
66
  flash(key: string, value: unknown): void;
@@ -170,6 +187,35 @@ interface OAuthProviderConfig {
170
187
  tokenAuthMethod?: 'client_secret_post' | 'client_secret_basic';
171
188
  userInfoMethod?: 'GET' | 'POST';
172
189
  mapProfile?: (raw: Record<string, unknown>, token: OAuthTokenResult) => OAuthUserProfile;
190
+ /**
191
+ * Key in the userinfo response carrying the provider's own verification
192
+ * signal for the email address — Discord returns `verified`, for example.
193
+ * Defaults to OIDC's standard `email_verified` claim. Only boolean values
194
+ * are read; anything else leaves `profile.emailVerified` undefined. Ignored
195
+ * when `mapProfile` is set, since that owns the whole mapping.
196
+ */
197
+ emailVerifiedKey?: string;
198
+ /**
199
+ * Fallback used when the userinfo response carries no email — e.g. GitHub
200
+ * returns `email: null` for accounts with a private email even when the
201
+ * `user:email` scope was granted. Returns the email to use, or undefined
202
+ * to leave the profile without one.
203
+ *
204
+ * The signal read via `emailVerifiedKey` does not carry over to a fallback
205
+ * address — it was read against a response that had no email. A bare string
206
+ * therefore makes no verification claim and leaves `profile.emailVerified`
207
+ * undefined; return `{ email, emailVerified: true }` to assert one.
208
+ */
209
+ fetchFallbackEmail?: (token: OAuthTokenResult) => Promise<string | OAuthFallbackEmail | undefined>;
210
+ }
211
+ interface OAuthFallbackEmail {
212
+ email: string;
213
+ /**
214
+ * Whether the provider verified this specific address. Omit it when the
215
+ * lookup cannot tell — the profile then reports `emailVerified: undefined`
216
+ * rather than an unfounded claim.
217
+ */
218
+ emailVerified?: boolean;
173
219
  }
174
220
  interface OAuthTokenResult {
175
221
  accessToken: string;
@@ -184,6 +230,15 @@ interface OAuthUserProfile {
184
230
  email?: string;
185
231
  name?: string;
186
232
  avatar?: string;
233
+ /**
234
+ * Whether the provider itself verified `email`. Tri-state on purpose:
235
+ * `true` — the provider asserts the address is verified; `false` — it
236
+ * asserts it is not; `undefined` — the provider sends no such signal
237
+ * (GitHub's `/user`, for instance), so the consumer decides its own policy.
238
+ * Returning an email is not by itself a claim that it was checked, so
239
+ * treating `undefined` as verified is a decision, not a default.
240
+ */
241
+ emailVerified?: boolean;
187
242
  token: OAuthTokenResult;
188
243
  raw: Record<string, unknown>;
189
244
  }
@@ -196,6 +251,17 @@ interface OAuthStateStore {
196
251
  store(stateHash: string, payload: OAuthStatePayload): Promise<void>;
197
252
  find(stateHash: string): Promise<OAuthStatePayload | null>;
198
253
  delete(stateHash: string): Promise<void>;
254
+ /**
255
+ * Atomically fetch and delete a state in one step. Exactly one caller may
256
+ * receive the payload; every other concurrent caller (and any later call)
257
+ * must get null. Expired states must also return null, mirroring `find`.
258
+ *
259
+ * Optional for backward compatibility: `verifyOAuthState` prefers this
260
+ * when present. Stores that only implement find/delete keep working, but
261
+ * leave a window where two concurrent callbacks with the same state can
262
+ * both pass verification.
263
+ */
264
+ consume?(stateHash: string): Promise<OAuthStatePayload | null>;
199
265
  }
200
266
  interface OAuthStateConfig {
201
267
  expiresIn?: number;
@@ -232,6 +298,7 @@ declare class MemoryOAuthStateStore implements OAuthStateStore {
232
298
  private sweepExpired;
233
299
  find(stateHash: string): Promise<OAuthStatePayload | null>;
234
300
  delete(stateHash: string): Promise<void>;
301
+ consume(stateHash: string): Promise<OAuthStatePayload | null>;
235
302
  clear(): void;
236
303
  }
237
304
  declare class OAuthManager {
@@ -593,4 +660,4 @@ declare function getApiTokenOrFail(ctx: Context): {
593
660
  abilities: string[];
594
661
  };
595
662
 
596
- export { parseApiToken as $, type Authenticatable as A, type BearerTokenMiddlewareOptions as B, type CreateSessionMiddlewareOptions as C, type DefaultSanitizedKeys as D, type Session as E, buildOAuthAuthorizeUrl as F, type GuardFactory as G, buildOAuthRedirectUrl as H, createApiToken as I, createBearerTokenMiddleware as J, createDiscordOAuthProviderConfig as K, createGitHubOAuthProviderConfig as L, MemoryApiTokenStore as M, createGoogleOAuthProviderConfig as N, type OAuthStateStore as O, type ProviderFactory as P, createOAuthManager as Q, createOAuthState as R, type SessionStore as S, createSessionMiddleware as T, type UserProvider as U, exchangeOAuthCode as V, fetchOAuthUserProfile as W, getApiToken as X, getApiTokenOrFail as Y, getSessionFromContext as Z, getUserApiTokens as _, type AuthCredentials as a, parseOAuthRedirectUrl as a0, revokeAllApiTokens as a1, revokeApiToken as a2, sanitizeOAuthRedirect as a3, tokenCan as a4, tokenCanAll as a5, tokenCanAny as a6, verifyApiToken as a7, verifyOAuthState as a8, type AuthManagerContract as b, type AuthManagerOptions as c, type GuardContext as d, type Guard as e, type AttachContextOptions as f, type AuthContext as g, type SessionData as h, type ApiTokenStore as i, type ApiToken as j, type OAuthStatePayload as k, OAuthManager as l, API_TOKEN_KEY as m, type CreateApiTokenOptions as n, type CreateApiTokenResult as o, MemoryOAuthStateStore as p, MemorySessionStore as q, type OAuthAuthorizeOptions as r, type OAuthCallbackPayload as s, type OAuthManagerOptions as t, type OAuthProviderConfig as u, type OAuthProviderFactoryInput as v, type OAuthStateConfig as w, type OAuthTokenResult as x, type OAuthUserProfile as y, type Sanitized as z };
663
+ export { getUserApiTokens as $, type Authenticatable as A, type BearerTokenMiddlewareOptions as B, type CreateSessionMiddlewareOptions as C, type DefaultSanitizedKeys as D, type Sanitized as E, type Session as F, type GuardFactory as G, buildOAuthAuthorizeUrl as H, buildOAuthRedirectUrl as I, createApiToken as J, createBearerTokenMiddleware as K, createDiscordOAuthProviderConfig as L, MemoryApiTokenStore as M, createGitHubOAuthProviderConfig as N, type OAuthStateStore as O, type ProviderFactory as P, createGoogleOAuthProviderConfig as Q, createOAuthManager as R, type SessionStore as S, createOAuthState as T, type UserProvider as U, createSessionMiddleware as V, exchangeOAuthCode as W, fetchOAuthUserProfile as X, getApiToken as Y, getApiTokenOrFail as Z, getSessionFromContext as _, type AuthCredentials as a, parseApiToken as a0, parseOAuthRedirectUrl as a1, revokeAllApiTokens as a2, revokeApiToken as a3, sanitizeOAuthRedirect as a4, tokenCan as a5, tokenCanAll as a6, tokenCanAny as a7, verifyApiToken as a8, verifyOAuthState as a9, type AuthManagerContract as b, type AuthManagerOptions as c, type GuardContext as d, type Guard as e, type AttachContextOptions as f, type AuthContext as g, type SessionData as h, type ApiTokenStore as i, type ApiToken as j, type OAuthStatePayload as k, OAuthManager as l, API_TOKEN_KEY as m, type CreateApiTokenOptions as n, type CreateApiTokenResult as o, MemoryOAuthStateStore as p, MemorySessionStore as q, type OAuthAuthorizeOptions as r, type OAuthCallbackPayload as s, type OAuthFallbackEmail as t, type OAuthManagerOptions as u, type OAuthProviderConfig as v, type OAuthProviderFactoryInput as w, type OAuthStateConfig as x, type OAuthTokenResult as y, type OAuthUserProfile as z };
@@ -1,9 +1,9 @@
1
- import { P as PasswordHasher } from '../AuthManager-BU8ZvenF.js';
2
- export { A as AuthManager, B as BaseUserProvider, M as ModelUserProvider } from '../AuthManager-BU8ZvenF.js';
3
- import { A as Authenticatable, e as Guard, U as UserProvider, E as Session, a as AuthCredentials } from '../api-token-CB12xnVg.js';
4
- export { m as API_TOKEN_KEY, j as ApiToken, i as ApiTokenStore, f as AttachContextOptions, g as AuthContext, b as AuthManagerContract, c as AuthManagerOptions, B as BearerTokenMiddlewareOptions, n as CreateApiTokenOptions, o as CreateApiTokenResult, D as DefaultSanitizedKeys, d as GuardContext, G as GuardFactory, M as MemoryApiTokenStore, p as MemoryOAuthStateStore, r as OAuthAuthorizeOptions, s as OAuthCallbackPayload, l as OAuthManager, t as OAuthManagerOptions, u as OAuthProviderConfig, v as OAuthProviderFactoryInput, w as OAuthStateConfig, k as OAuthStatePayload, O as OAuthStateStore, x as OAuthTokenResult, y as OAuthUserProfile, P as ProviderFactory, z as Sanitized, F as buildOAuthAuthorizeUrl, H as buildOAuthRedirectUrl, I as createApiToken, J as createBearerTokenMiddleware, K as createDiscordOAuthProviderConfig, L as createGitHubOAuthProviderConfig, N as createGoogleOAuthProviderConfig, Q as createOAuthManager, R as createOAuthState, V as exchangeOAuthCode, W as fetchOAuthUserProfile, X as getApiToken, Y as getApiTokenOrFail, _ as getUserApiTokens, $ as parseApiToken, a0 as parseOAuthRedirectUrl, a1 as revokeAllApiTokens, a2 as revokeApiToken, a3 as sanitizeOAuthRedirect, a4 as tokenCan, a5 as tokenCanAll, a6 as tokenCanAny, a7 as verifyApiToken, a8 as verifyOAuthState } from '../api-token-CB12xnVg.js';
1
+ import { P as PasswordHasher } from '../AuthManager-C84xF5ks.js';
2
+ export { A as AuthManager, B as BaseUserProvider, M as ModelUserProvider } from '../AuthManager-C84xF5ks.js';
3
+ import { A as Authenticatable, e as Guard, U as UserProvider, F as Session, a as AuthCredentials } from '../api-token-COQHXyM_.js';
4
+ export { m as API_TOKEN_KEY, j as ApiToken, i as ApiTokenStore, f as AttachContextOptions, g as AuthContext, b as AuthManagerContract, c as AuthManagerOptions, B as BearerTokenMiddlewareOptions, n as CreateApiTokenOptions, o as CreateApiTokenResult, D as DefaultSanitizedKeys, d as GuardContext, G as GuardFactory, M as MemoryApiTokenStore, p as MemoryOAuthStateStore, r as OAuthAuthorizeOptions, s as OAuthCallbackPayload, t as OAuthFallbackEmail, l as OAuthManager, u as OAuthManagerOptions, v as OAuthProviderConfig, w as OAuthProviderFactoryInput, x as OAuthStateConfig, k as OAuthStatePayload, O as OAuthStateStore, y as OAuthTokenResult, z as OAuthUserProfile, P as ProviderFactory, E as Sanitized, H as buildOAuthAuthorizeUrl, I as buildOAuthRedirectUrl, J as createApiToken, K as createBearerTokenMiddleware, L as createDiscordOAuthProviderConfig, N as createGitHubOAuthProviderConfig, Q as createGoogleOAuthProviderConfig, R as createOAuthManager, T as createOAuthState, W as exchangeOAuthCode, X as fetchOAuthUserProfile, Y as getApiToken, Z as getApiTokenOrFail, $ as getUserApiTokens, a0 as parseApiToken, a1 as parseOAuthRedirectUrl, a2 as revokeAllApiTokens, a3 as revokeApiToken, a4 as sanitizeOAuthRedirect, a5 as tokenCan, a6 as tokenCanAll, a7 as tokenCanAny, a8 as verifyApiToken, a9 as verifyOAuthState } from '../api-token-COQHXyM_.js';
5
5
  import { PlainObject, Model } from '@guren/orm';
6
- export { b as EmailVerificationConfig, a as EmailVerificationToken, c as EmailVerificationTokenResult, E as EmailVerificationTokenStore, M as MemoryEmailVerificationStore, d as MemoryPasswordResetStore, e as PasswordResetConfig, f as PasswordResetTokenResult, P as PasswordResetTokenStore, g as buildPasswordResetUrl, q as buildTokenUrl, h as buildVerificationUrl, i as completeEmailVerification, j as completePasswordReset, k as createEmailVerificationToken, l as createPasswordResetToken, s as generateId, t as generateToken, u as hashToken, m as isEmailVerified, p as parsePasswordResetUrl, w as parseTokenUrl, n as parseVerificationUrl, r as requireVerifiedEmail, x as secureCompare, y as secureStringCompare, v as verifyEmailToken, o as verifyPasswordResetToken } from '../email-verification-D9u7krkn.js';
6
+ export { b as EmailVerificationConfig, a as EmailVerificationToken, c as EmailVerificationTokenResult, E as EmailVerificationTokenStore, M as MemoryEmailVerificationStore, d as MemoryPasswordResetStore, e as PasswordResetConfig, f as PasswordResetTokenResult, P as PasswordResetTokenStore, g as buildPasswordResetUrl, q as buildTokenUrl, h as buildVerificationUrl, i as completeEmailVerification, j as completePasswordReset, k as createEmailVerificationToken, l as createPasswordResetToken, s as generateId, t as generateToken, u as hashToken, m as isEmailVerified, p as parsePasswordResetUrl, w as parseTokenUrl, n as parseVerificationUrl, r as requireVerifiedEmail, x as secureCompare, y as secureStringCompare, v as verifyEmailToken, o as verifyPasswordResetToken } from '../email-verification-H_WlpsVH.js';
7
7
  import 'hono';
8
8
 
9
9
  interface SessionGuardOptions {
@@ -55,7 +55,7 @@ import {
55
55
  verifyEmailToken,
56
56
  verifyOAuthState,
57
57
  verifyPasswordResetToken
58
- } from "../chunk-VY2JPS6V.js";
58
+ } from "../chunk-AUXQISW5.js";
59
59
  import "../chunk-DAQKYKLH.js";
60
60
  import "../chunk-ONSDE37A.js";
61
61
  import "../chunk-QQKTH5KX.js";
@@ -14,8 +14,8 @@ import {
14
14
  getGate,
15
15
  setGate,
16
16
  withAuthorization
17
- } from "../chunk-ZRBLZY3M.js";
18
- import "../chunk-THSX7OOR.js";
17
+ } from "../chunk-FZD2AKJI.js";
18
+ import "../chunk-63SKW5PS.js";
19
19
  import "../chunk-DAQKYKLH.js";
20
20
  export {
21
21
  Gate,
@@ -1,5 +1,5 @@
1
- import { B as BroadcastManager, P as PresenceBroadcastDriver, c as BroadcastEvent, j as PresenceMember } from '../BroadcastManager-CGWl9rUO.js';
2
- export { A as AuthMiddlewareOptions, a as BroadcastDriver, b as BroadcastDriverFactory, d as BroadcastManagerOptions, e as BroadcastableEvent, C as Channel, f as ChannelAuthorizer, g as ChannelRegistration, h as PresenceChannel, i as PresenceChannelAuthorizer, k as PrivateChannel, S as SSEClient, l as SSEMiddlewareOptions, W as WebSocketClient, m as createBroadcastManager, n as getBroadcastManager, s as setBroadcastManager } from '../BroadcastManager-CGWl9rUO.js';
1
+ import { B as BroadcastManager, P as PresenceBroadcastDriver, c as BroadcastEvent, j as PresenceMember } from '../BroadcastManager-D8KoJxiV.js';
2
+ export { A as AuthMiddlewareOptions, a as BroadcastDriver, b as BroadcastDriverFactory, d as BroadcastManagerOptions, e as BroadcastableEvent, C as Channel, f as ChannelAuthorizer, g as ChannelRegistration, h as PresenceChannel, i as PresenceChannelAuthorizer, k as PrivateChannel, S as SSEClient, l as SSEMiddlewareOptions, W as WebSocketClient, m as createBroadcastManager, n as getBroadcastManager, s as setBroadcastManager } from '../BroadcastManager-D8KoJxiV.js';
3
3
  import '../index-9_Jzj5jo.js';
4
4
  import 'hono';
5
5
 
@@ -9,7 +9,8 @@ import {
9
9
  createTypedBroadcaster,
10
10
  getBroadcastManager,
11
11
  setBroadcastManager
12
- } from "../chunk-44F7JQ7I.js";
12
+ } from "../chunk-XMQZENBP.js";
13
+ import "../chunk-DCYKSYAT.js";
13
14
  export {
14
15
  BroadcastManager,
15
16
  Channel,
@@ -1,5 +1,5 @@
1
- import { b as CacheStore, M as MemoryStoreOptions, R as RedisStoreOptions, F as FileStoreOptions, T as TaggedCacheStore } from '../CacheManager-BkvHEOZX.js';
2
- export { a as CacheConfig, C as CacheManager, c as CacheStoreFactory, e as CachedItem, S as StoreConfig, f as TaggableCacheStore, d as createCacheManager } from '../CacheManager-BkvHEOZX.js';
1
+ import { b as CacheStore, M as MemoryStoreOptions, R as RedisStoreOptions, F as FileStoreOptions, T as TaggedCacheStore } from '../CacheManager-BmDzUKrF.js';
2
+ export { a as CacheConfig, C as CacheManager, c as CacheStoreFactory, e as CachedItem, S as StoreConfig, f as TaggableCacheStore, d as createCacheManager } from '../CacheManager-BmDzUKrF.js';
3
3
 
4
4
  /**
5
5
  * In-memory cache store.
@@ -5,7 +5,8 @@ import {
5
5
  RedisStore,
6
6
  TaggedCache,
7
7
  createCacheManager
8
- } from "../chunk-EGU5KB7V.js";
8
+ } from "../chunk-4SBGSJNT.js";
9
+ import "../chunk-DCYKSYAT.js";
9
10
  export {
10
11
  CacheManager,
11
12
  FileStore,
@@ -1,3 +1,8 @@
1
+ import {
2
+ claimHotDisposable,
3
+ isHotReloadRuntime
4
+ } from "./chunk-DCYKSYAT.js";
5
+
1
6
  // src/cache/stores/MemoryStore.ts
2
7
  var MemoryStore = class {
3
8
  cache = /* @__PURE__ */ new Map();
@@ -716,7 +721,17 @@ var CacheManager = class {
716
721
  defaultStoreName;
717
722
  storeFactories = /* @__PURE__ */ new Map();
718
723
  resolvedStores = /* @__PURE__ */ new Map();
724
+ /**
725
+ * Where this manager was built, for identifying its stores across hot reloads.
726
+ *
727
+ * Captured here rather than in `store()` because stores resolve lazily, from
728
+ * whichever request first asks for one — a call site that says nothing about
729
+ * which manager owns the result. Skipped outside `--hot`, where it would be a
730
+ * formatted stack string held for the manager's lifetime and never read.
731
+ */
732
+ builtAt;
719
733
  constructor(config = {}) {
734
+ this.builtAt = isHotReloadRuntime() ? new Error().stack : void 0;
720
735
  this.defaultStoreName = config.default ?? "memory";
721
736
  this.registerBuiltinDrivers();
722
737
  if (config.stores) {
@@ -768,10 +783,25 @@ var CacheManager = class {
768
783
  if (!factory) {
769
784
  throw new Error(`Cache store not found: ${storeName}`);
770
785
  }
771
- const store = new TaggableCacheStoreWrapper(factory());
786
+ const raw = factory();
787
+ this.stopPreviousStore(storeName, raw);
788
+ const store = new TaggableCacheStoreWrapper(raw);
772
789
  this.resolvedStores.set(storeName, store);
773
790
  return store;
774
791
  }
792
+ /**
793
+ * Under `bun --hot`, stops the sweep timer held by the store this one replaces.
794
+ *
795
+ * Registered from here rather than from `MemoryStore` itself because this is
796
+ * where the store's name is known, and the name is what keeps two memory
797
+ * stores in one config from sharing a slot and cancelling each other's sweep.
798
+ */
799
+ stopPreviousStore(storeName, store) {
800
+ const disposable = store;
801
+ if (typeof disposable.destroy === "function") {
802
+ claimHotDisposable("cache-store", this.builtAt, storeName, () => disposable.destroy?.());
803
+ }
804
+ }
775
805
  /**
776
806
  * Register a custom store factory.
777
807
  */
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Job,
3
3
  registerJob
4
- } from "./chunk-R2TCP7D7.js";
4
+ } from "./chunk-6J6B5KOB.js";
5
5
 
6
6
  // src/notifications/Notification.ts
7
7
  var Notification = class {
@@ -62,6 +62,36 @@ var Notification = class {
62
62
  }
63
63
  };
64
64
 
65
+ // src/notifications/registry.ts
66
+ var notificationRegistry = /* @__PURE__ */ new Map();
67
+ function resolveRegistryKey(notificationClass) {
68
+ try {
69
+ const { type } = Object.create(notificationClass.prototype);
70
+ if (typeof type === "string" && type.length > 0) {
71
+ return type;
72
+ }
73
+ } catch {
74
+ }
75
+ return notificationClass.name;
76
+ }
77
+ function registerNotification(notificationClass, type) {
78
+ notificationRegistry.set(
79
+ type ?? resolveRegistryKey(notificationClass),
80
+ notificationClass
81
+ );
82
+ }
83
+ function getNotification(type) {
84
+ return notificationRegistry.get(type);
85
+ }
86
+ function clearNotificationRegistry() {
87
+ notificationRegistry.clear();
88
+ }
89
+
90
+ // src/notifications/notifiable-type.ts
91
+ function resolveNotifiableType(notifiable) {
92
+ return notifiable.notifiableType ?? notifiable.constructor?.name ?? "Unknown";
93
+ }
94
+
65
95
  // src/notifications/NotificationManager.ts
66
96
  var NotificationManager = class {
67
97
  channels = /* @__PURE__ */ new Map();
@@ -173,10 +203,16 @@ var NotificationManager = class {
173
203
  * Queue a notification for later delivery.
174
204
  */
175
205
  async queue(notifiable, notification, queueConfig) {
176
- const job = this.createNotificationJob();
177
- registerJob(job);
206
+ const job = this.registerQueueJob();
207
+ registerNotification(
208
+ notification.constructor,
209
+ notification.type
210
+ );
178
211
  const payload = {
179
- notifiableData: this.serializeNotifiable(notifiable),
212
+ notifiableData: this.serializeNotifiable(
213
+ notifiable,
214
+ notification.via(notifiable)
215
+ ),
180
216
  notificationData: this.serializeNotification(notification),
181
217
  notificationType: notification.type
182
218
  };
@@ -206,32 +242,47 @@ var NotificationManager = class {
206
242
  }
207
243
  /**
208
244
  * Serialize notifiable for queue storage.
209
- */
210
- serializeNotifiable(notifiable) {
245
+ *
246
+ * Routing is resolved here rather than in the worker: `routeNotificationFor`
247
+ * is arbitrary user code — often a closure on an object literal — and cannot
248
+ * be reconstructed from a payload.
249
+ *
250
+ * @param channels - Channels to resolve routes for
251
+ */
252
+ serializeNotifiable(notifiable, channels = []) {
253
+ const routes = {};
254
+ for (const channel of channels) {
255
+ routes[channel] = notifiable.routeNotificationFor(channel);
256
+ }
211
257
  return {
212
- type: notifiable.constructor?.name ?? "Unknown",
258
+ type: resolveNotifiableType(notifiable),
259
+ routes,
213
260
  data: { ...notifiable }
214
261
  };
215
262
  }
216
263
  /**
217
264
  * Serialize notification for queue storage.
265
+ *
266
+ * Only own enumerable properties are captured. Behaviour is restored by
267
+ * rebuilding the registered class in the job handler, not by serializing it.
218
268
  */
219
269
  serializeNotification(notification) {
220
270
  return {
221
- type: notification.type,
222
271
  id: notification.id,
272
+ createdAt: notification.createdAt.toISOString(),
223
273
  data: { ...notification }
224
274
  };
225
275
  }
226
276
  /**
227
- * Create the notification job class.
277
+ * Bind this manager to the queued-notification job and register it.
278
+ *
279
+ * Call this during boot in a process that runs a worker but may never send
280
+ * a notification itself: without it, the worker cannot resolve the job.
228
281
  */
229
- createNotificationJob() {
230
- const manager = this;
231
- class BoundSendNotificationJob extends SendNotificationJob {
232
- static notificationManager = manager;
233
- }
234
- return BoundSendNotificationJob;
282
+ registerQueueJob() {
283
+ SendNotificationJob.notificationManager = this;
284
+ registerJob(SendNotificationJob);
285
+ return SendNotificationJob;
235
286
  }
236
287
  };
237
288
  var SendNotificationJob = class extends Job {
@@ -245,33 +296,54 @@ var SendNotificationJob = class extends Job {
245
296
  if (!manager) {
246
297
  throw new Error("NotificationManager not set on SendNotificationJob");
247
298
  }
248
- const notifiable = {
249
- ...payload.notifiableData.data,
299
+ const notifiable = this.rebuildNotifiable(payload.notifiableData);
300
+ const notification = this.rebuildNotification(
301
+ payload.notificationType,
302
+ payload.notificationData
303
+ );
304
+ await manager.sendNow(notifiable, notification);
305
+ }
306
+ /**
307
+ * Rebuild the notifiable from its serialized data.
308
+ */
309
+ rebuildNotifiable(serialized) {
310
+ const { data, routes } = serialized;
311
+ return {
312
+ ...data,
313
+ notifiableType: serialized.type,
250
314
  routeNotificationFor(channel) {
251
- const key = `${channel}Route`;
252
- const value = payload.notifiableData.data[key];
315
+ if (routes && channel in routes) {
316
+ return routes[channel] ?? null;
317
+ }
318
+ const value = data[`${channel}Route`];
253
319
  if (typeof value === "string") return value;
254
320
  if (channel === "mail") {
255
- const email = payload.notifiableData.data["email"];
321
+ const email = data["email"];
256
322
  return typeof email === "string" ? email : null;
257
323
  }
258
324
  return null;
259
325
  }
260
326
  };
261
- const notification = {
262
- ...payload.notificationData.data,
263
- id: payload.notificationData.id,
264
- type: payload.notificationType,
265
- via: () => {
266
- const viaChannels = payload.notificationData.data._viaChannels;
267
- return viaChannels ?? [];
268
- },
269
- shouldSend: () => true,
270
- toMail: payload.notificationData.data.toMail,
271
- toDatabase: payload.notificationData.data.toDatabase,
272
- toSlack: payload.notificationData.data.toSlack
273
- };
274
- await manager.sendNow(notifiable, notification);
327
+ }
328
+ /**
329
+ * Rebuild a real notification instance from its serialized data.
330
+ *
331
+ * The class is looked up in the notification registry and instantiated via
332
+ * its prototype, so prototype methods (`via`, `toMail`, `toDatabase`,
333
+ * `toSlack`, `shouldSend`) are restored without running the constructor.
334
+ */
335
+ rebuildNotification(type, serialized) {
336
+ const NotificationClass = getNotification(type);
337
+ if (!NotificationClass) {
338
+ throw new Error(
339
+ `Notification type "${type}" is not registered. Call registerNotification(${type}) before running the queue worker.`
340
+ );
341
+ }
342
+ return Object.assign(
343
+ Object.create(NotificationClass.prototype),
344
+ serialized.data,
345
+ { id: serialized.id, createdAt: new Date(serialized.createdAt) }
346
+ );
275
347
  }
276
348
  };
277
349
  var globalNotificationManager = null;
@@ -399,7 +471,7 @@ var DatabaseChannel = class {
399
471
  * Get the notifiable type.
400
472
  */
401
473
  getNotifiableType(notifiable) {
402
- return notifiable.constructor?.name ?? "Unknown";
474
+ return resolveNotifiableType(notifiable);
403
475
  }
404
476
  /**
405
477
  * Get all stored notifications (for testing).
@@ -641,6 +713,10 @@ var MemoryChannel = class {
641
713
 
642
714
  export {
643
715
  Notification,
716
+ registerNotification,
717
+ getNotification,
718
+ clearNotificationRegistry,
719
+ resolveNotifiableType,
644
720
  NotificationManager,
645
721
  setNotificationManager,
646
722
  getNotificationManager,
@@ -152,6 +152,9 @@ var ExceptionHandler = class {
152
152
  if (this.shouldNotReport(error)) {
153
153
  return;
154
154
  }
155
+ if (this.reporters.length === 0) {
156
+ console.error("Unhandled exception:", error);
157
+ }
155
158
  for (const reporter of this.reporters) {
156
159
  try {
157
160
  await reporter(error);
@@ -307,6 +307,17 @@ function generateJobId() {
307
307
  return randomBytes(16).toString("hex");
308
308
  }
309
309
  var Job = class {
310
+ /**
311
+ * Stable wire name for this job.
312
+ *
313
+ * Queued messages record this name, and the worker resolves the class back
314
+ * from it. When omitted the class name is used, which breaks if a bundler
315
+ * mangles identifiers or if the class is later renamed while messages are
316
+ * still in flight. Set it to pin the name across both.
317
+ *
318
+ * @default the class name
319
+ */
320
+ static jobName;
310
321
  /**
311
322
  * The queue this job should be dispatched to.
312
323
  * @default 'default'
@@ -344,7 +355,7 @@ var Job = class {
344
355
  const delay = options.delay ?? 0;
345
356
  const job = {
346
357
  id: jobId,
347
- name: this.name,
358
+ name: resolveJobName(this),
348
359
  payload,
349
360
  queue: options.queue ?? this.queue,
350
361
  attempts: 0,
@@ -379,9 +390,13 @@ var Job = class {
379
390
  return Math.pow(2, attempts) * 1e3;
380
391
  }
381
392
  };
393
+ function resolveJobName(jobClass) {
394
+ const own = Object.prototype.hasOwnProperty.call(jobClass, "jobName") ? jobClass.jobName : void 0;
395
+ return own ?? jobClass.name;
396
+ }
382
397
  var jobRegistry = /* @__PURE__ */ new Map();
383
398
  function registerJob(jobClass) {
384
- jobRegistry.set(jobClass.name, jobClass);
399
+ jobRegistry.set(resolveJobName(jobClass), jobClass);
385
400
  }
386
401
  function getJob(name) {
387
402
  return jobRegistry.get(name);
@@ -402,6 +417,7 @@ export {
402
417
  setQueueDriver,
403
418
  getQueueDriver,
404
419
  Job,
420
+ resolveJobName,
405
421
  registerJob,
406
422
  getJob,
407
423
  getRegisteredJobs,