@guren/server 2.22.0 → 2.23.1

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 (108) hide show
  1. package/dist/Job-BVvaY-7p.js +165 -0
  2. package/dist/auth/AuthManager.d.ts +29 -0
  3. package/dist/auth/AuthenticatableModel.d.ts +15 -0
  4. package/dist/auth/RequestAuthContext.d.ts +10 -1
  5. package/dist/auth/SessionGuard.d.ts +2 -0
  6. package/dist/auth/api-token.d.ts +6 -0
  7. package/dist/auth/context.d.ts +32 -0
  8. package/dist/auth/index.d.ts +7 -0
  9. package/dist/auth/index.js +2 -2
  10. package/dist/auth/model-capability.d.ts +8 -0
  11. package/dist/auth/oauth/index.d.ts +5 -0
  12. package/dist/auth/password/DefaultHasher.d.ts +17 -6
  13. package/dist/auth/password/configured-hasher.d.ts +23 -0
  14. package/dist/auth/providers/ModelUserProvider.d.ts +3 -0
  15. package/dist/auth/providers/unconfigured-user-provider.d.ts +12 -0
  16. package/dist/auth/types.d.ts +9 -0
  17. package/dist/{auth-CjE2oO50.js → auth-D_W1cJp3.js} +279 -84
  18. package/dist/authorization/Gate.d.ts +12 -0
  19. package/dist/authorization/index.js +1 -1
  20. package/dist/{authorization-CdEWZZw3.js → authorization-0mCGUFoI.js} +58 -12
  21. package/dist/broadcasting/BroadcastManager.d.ts +10 -0
  22. package/dist/broadcasting/index.js +1 -1
  23. package/dist/{broadcasting-B5RzB0A2.js → broadcasting-BdJnaq1O.js} +17 -3
  24. package/dist/console/Command.d.ts +3 -3
  25. package/dist/console/ConsoleKernel.d.ts +2 -2
  26. package/dist/console/index.d.ts +1 -1
  27. package/dist/console/types.d.ts +9 -1
  28. package/dist/container/Container.d.ts +18 -1
  29. package/dist/container/bindings.d.ts +5 -0
  30. package/dist/container/index.d.ts +4 -2
  31. package/dist/container/resolve-optional.d.ts +10 -0
  32. package/dist/context-af2n5abO.js +91 -0
  33. package/dist/{Job-CvDwk2Gj.js → default-application-Chbrul_m.js} +126 -82
  34. package/dist/encryption/Encrypter.d.ts +10 -0
  35. package/dist/encryption/index.js +1 -1
  36. package/dist/{encryption-uwP3Di4D.js → encryption-BRjZnshr.js} +23 -5
  37. package/dist/errors/ExceptionHandler.d.ts +10 -0
  38. package/dist/events/Event.d.ts +18 -0
  39. package/dist/events/EventManager.d.ts +56 -4
  40. package/dist/events/index.d.ts +2 -1
  41. package/dist/events/index.js +2 -2
  42. package/dist/events/queued.d.ts +8 -0
  43. package/dist/events/serialize.d.ts +8 -0
  44. package/dist/events/types.d.ts +19 -2
  45. package/dist/events-CaJKZ2qk.js +428 -0
  46. package/dist/health/checks/CacheCheck.d.ts +3 -5
  47. package/dist/health/checks/StorageCheck.d.ts +3 -5
  48. package/dist/health/index.js +1 -1
  49. package/dist/{health-DQSvUplL.js → health-CB0oS_UE.js} +2 -2
  50. package/dist/http/Application.d.ts +28 -0
  51. package/dist/http/default-application.d.ts +33 -0
  52. package/dist/http/middleware/detect-locale.d.ts +2 -1
  53. package/dist/http/request-container.d.ts +25 -0
  54. package/dist/i18n/I18nManager.d.ts +16 -3
  55. package/dist/i18n/index.d.ts +1 -1
  56. package/dist/i18n/index.js +2 -2
  57. package/dist/{i18n-BZ2VrSud.js → i18n-DRo1g0AN.js} +34 -10
  58. package/dist/index.d.ts +14 -9
  59. package/dist/index.js +196 -87
  60. package/dist/lambda/index.js +1 -1
  61. package/dist/logging/LogManager.d.ts +9 -0
  62. package/dist/logging/index.js +1 -1
  63. package/dist/{logging-Dmzdb6mL.js → logging-CXotojgW.js} +16 -3
  64. package/dist/mail/Mail.d.ts +14 -1
  65. package/dist/mail/MailManager.d.ts +10 -2
  66. package/dist/mail/index.js +1 -1
  67. package/dist/{mail-9CrvJyBZ.js → mail-zMjQimaJ.js} +42 -11
  68. package/dist/mvc/Controller.d.ts +2 -2
  69. package/dist/mvc/Router.d.ts +16 -5
  70. package/dist/mvc/inertia/InertiaEngine.d.ts +18 -3
  71. package/dist/mvc/inertia/shared.d.ts +7 -0
  72. package/dist/notifications/NotificationManager.d.ts +15 -0
  73. package/dist/notifications/index.js +1 -1
  74. package/dist/{notifications-D0VXkFLF.js → notifications-BLid0Y6M.js} +24 -5
  75. package/dist/providers/AuthServiceProvider.d.ts +5 -4
  76. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -2
  77. package/dist/providers/BroadcastServiceProvider.d.ts +4 -1
  78. package/dist/providers/EncryptionServiceProvider.d.ts +7 -1
  79. package/dist/providers/EventServiceProvider.d.ts +1 -0
  80. package/dist/providers/LogServiceProvider.d.ts +6 -1
  81. package/dist/providers/MailServiceProvider.d.ts +7 -1
  82. package/dist/providers/NotificationServiceProvider.d.ts +4 -1
  83. package/dist/queue/Job.d.ts +39 -0
  84. package/dist/queue/QueueManager.d.ts +14 -5
  85. package/dist/queue/Worker.d.ts +2 -1
  86. package/dist/queue/index.d.ts +1 -1
  87. package/dist/queue/index.js +3 -3
  88. package/dist/queue/types.d.ts +7 -0
  89. package/dist/{queue-zPPYZdif.js → queue-IdJjqbyJ.js} +24 -10
  90. package/dist/redis/RedisSchedulerLock.d.ts +17 -0
  91. package/dist/redis/index.d.ts +2 -0
  92. package/dist/redis/index.js +21 -1
  93. package/dist/runtime/index.js +1 -1
  94. package/dist/scheduling/MemorySchedulerLock.d.ts +16 -0
  95. package/dist/scheduling/ScheduledTask.d.ts +19 -2
  96. package/dist/scheduling/Scheduler.d.ts +25 -0
  97. package/dist/scheduling/index.d.ts +2 -1
  98. package/dist/scheduling/index.js +2 -2
  99. package/dist/scheduling/types.d.ts +26 -2
  100. package/dist/{scheduling-C6tcOtUl.js → scheduling-DudNXGnh.js} +178 -20
  101. package/dist/storage/index.js +1 -1
  102. package/dist/{storage-D_yNe54O.js → storage-6HLaUf9j.js} +2 -13
  103. package/dist/support/deprecate.d.ts +16 -0
  104. package/dist/{vite-manifest-D295_7-_.js → vite-manifest-QooqG8FE.js} +1 -1
  105. package/dist/warn-once-p-IlMjra.js +13 -0
  106. package/package.json +2 -2
  107. package/dist/context-CXk_umpT.js +0 -21
  108. package/dist/events-DOmAHDeP.js +0 -230
@@ -0,0 +1,428 @@
1
+ import { d as resolveQueueDriver, l as registerJob, t as Job } from "./Job-BVvaY-7p.js";
2
+ import { t as warnOnce } from "./warn-once-p-IlMjra.js";
3
+ //#region src/events/Event.ts
4
+ /** Base class for all application events. */
5
+ var Event = class {
6
+ timestamp = /* @__PURE__ */ new Date();
7
+ /**
8
+ * Stable wire name: queued emits record it and the worker resolves the class
9
+ * back from it. Declare it as a static field to pin the name against a
10
+ * rename or identifier mangling.
11
+ * @default the class name
12
+ */
13
+ static get eventName() {
14
+ return this.name;
15
+ }
16
+ get eventName() {
17
+ return resolveEventName(this.constructor);
18
+ }
19
+ };
20
+ /**
21
+ * Only an *own* `eventName` counts: statics are inherited, so reading the
22
+ * prototype chain would make every subclass of a pinned event claim its
23
+ * parent's name and take over its listeners. The base class's own entry is the
24
+ * accessor, which answers with the class name.
25
+ */
26
+ function resolveEventName(eventClass) {
27
+ return (Object.prototype.hasOwnProperty.call(eventClass, "eventName") ? eventClass.eventName : void 0) ?? eventClass.name;
28
+ }
29
+ //#endregion
30
+ //#region src/events/serialize.ts
31
+ /**
32
+ * Marks a `Date` inside a queued event's fields. A driver that JSON-encodes the
33
+ * message turns every Date into a string indistinguishable from a string field,
34
+ * so the tag is what tells the worker which ones to revive.
35
+ */
36
+ const DATE_TAG = "__guren_date";
37
+ /**
38
+ * An event's own enumerable fields, one level deep: a Date nested inside an
39
+ * object or array field survives as whatever the driver's encoding makes of it.
40
+ */
41
+ function encodeEventData(event) {
42
+ const encoded = {};
43
+ for (const [key, value] of Object.entries(event)) encoded[key] = value instanceof Date ? { [DATE_TAG]: value.toISOString() } : value;
44
+ return encoded;
45
+ }
46
+ /** The inverse of {@link encodeEventData}; a value that carries no tag is passed through. */
47
+ function decodeEventData(data) {
48
+ const decoded = {};
49
+ for (const [key, value] of Object.entries(data)) {
50
+ const iso = readDateTag(value);
51
+ decoded[key] = iso === void 0 ? value : new Date(iso);
52
+ }
53
+ return decoded;
54
+ }
55
+ function readDateTag(value) {
56
+ if (typeof value !== "object" || value === null) return void 0;
57
+ const tagged = value[DATE_TAG];
58
+ return typeof tagged === "string" ? tagged : void 0;
59
+ }
60
+ //#endregion
61
+ //#region src/events/EventManager.ts
62
+ /** Registers listeners and emits events. */
63
+ var EventManager = class {
64
+ listeners = /* @__PURE__ */ new Map();
65
+ /** Classes seen by `on()` or `registerEvent()`, so a queued event can be rebuilt as an instance on the worker. */
66
+ eventClasses = /* @__PURE__ */ new Map();
67
+ /** Next `listenerSeq` per "<event>\u0000<queue>", never reset; see {@link RegisteredListener.listenerSeq}. */
68
+ listenerSeqCounters = /* @__PURE__ */ new Map();
69
+ queueDispatcher;
70
+ on(event, listener, options = {}) {
71
+ return this.register(event, listener, options);
72
+ }
73
+ register(event, listener, options, failed) {
74
+ const eventName = this.nameOf(event);
75
+ if (typeof event !== "string") this.eventClasses.set(eventName, event);
76
+ const registeredListeners = this.listeners.get(eventName) ?? [];
77
+ const registered = {
78
+ listener,
79
+ options: {
80
+ once: false,
81
+ priority: 0,
82
+ ...options
83
+ },
84
+ listenerSeq: options.queue === void 0 ? void 0 : this.nextListenerSeq(eventName, options.queue),
85
+ failed
86
+ };
87
+ registeredListeners.push(registered);
88
+ registeredListeners.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0));
89
+ this.listeners.set(eventName, registeredListeners);
90
+ return { unsubscribe: () => this.off(event, listener) };
91
+ }
92
+ once(event, listener, options = {}) {
93
+ return this.on(event, listener, {
94
+ ...options,
95
+ once: true
96
+ });
97
+ }
98
+ /**
99
+ * Makes the class resolvable by name when a queued emit reaches a worker.
100
+ * `on()` registers it too; a worker that only drains the queue registers the
101
+ * listeners anyway, so this is for a process that emits and never listens.
102
+ */
103
+ registerEvent(eventClass) {
104
+ this.eventClasses.set(resolveEventName(eventClass), eventClass);
105
+ }
106
+ /**
107
+ * Registers a `Listener` subclass under its own statics: `event`, `priority`,
108
+ * and `queue` when `shouldQueue`. The instance is built per invocation, so
109
+ * two events cannot share one listener's state. `failed()` is terminal either
110
+ * way: inline on the throw that then propagates, queued once the carrier
111
+ * job's retries are exhausted, where `Job.failed` runs.
112
+ */
113
+ listen(listenerClass) {
114
+ const queue = listenerClass.shouldQueue ? listenerClass.queue : void 0;
115
+ const listener = async (event) => {
116
+ const instance = new listenerClass();
117
+ if (instance.shouldHandle && !instance.shouldHandle(event)) return;
118
+ if (queue !== void 0) {
119
+ await instance.handle(event);
120
+ return;
121
+ }
122
+ try {
123
+ await instance.handle(event);
124
+ } catch (error) {
125
+ const failure = error instanceof Error ? error : new Error(String(error));
126
+ if (instance.failed) await instance.failed(event, failure);
127
+ throw failure;
128
+ }
129
+ };
130
+ const failed = queue === void 0 ? void 0 : async (event, error) => {
131
+ await new listenerClass().failed?.(event, error);
132
+ };
133
+ return this.register(listenerClass.event, listener, {
134
+ priority: listenerClass.priority,
135
+ queue
136
+ }, failed);
137
+ }
138
+ /** Omitting `listener` removes every listener for the event. */
139
+ off(event, listener) {
140
+ const eventName = this.nameOf(event);
141
+ const registeredListeners = this.listeners.get(eventName);
142
+ if (!registeredListeners) return;
143
+ if (!listener) {
144
+ this.listeners.delete(eventName);
145
+ return;
146
+ }
147
+ const index = registeredListeners.findIndex((r) => r.listener === listener);
148
+ if (index !== -1) {
149
+ registeredListeners.splice(index, 1);
150
+ if (registeredListeners.length === 0) this.listeners.delete(eventName);
151
+ }
152
+ }
153
+ /** Highest priority first, awaited one at a time. */
154
+ async emit(event) {
155
+ await this.dispatch(event, false);
156
+ }
157
+ /** {@link emit} without the ordering guarantee. */
158
+ async emitParallel(event) {
159
+ await this.dispatch(event, true);
160
+ }
161
+ async dispatch(event, parallel) {
162
+ const eventName = event.eventName;
163
+ const registeredListeners = this.listeners.get(eventName);
164
+ if (!registeredListeners || registeredListeners.length === 0) return;
165
+ const listenersToCall = [...registeredListeners];
166
+ const toRemove = [];
167
+ const call = async (registered) => {
168
+ const queued = await this.invoke(registered, event, eventName);
169
+ if (registered.options.once && !queued) toRemove.push(registered);
170
+ };
171
+ if (parallel) await Promise.all(listenersToCall.map(call));
172
+ else for (const registered of listenersToCall) await call(registered);
173
+ this.forget(eventName, registeredListeners, toRemove);
174
+ }
175
+ /** Resolves whether the listener was sent to a queue rather than run here. */
176
+ async invoke(registered, event, eventName) {
177
+ const queue = registered.options.queue;
178
+ if (!queue) {
179
+ await registered.listener(event);
180
+ return false;
181
+ }
182
+ const dispatcher = this.queueDispatcher;
183
+ if (!dispatcher || await dispatcher(queue, eventName, event, registered.listenerSeq) === false) {
184
+ warnOnce(`event-queue-unwired:${eventName}:${queue}`, `[guren] A listener for "${eventName}" is registered with queue "${queue}", but no queue is reachable from this EventManager, so it ran inline. Bind a QueueManager as "queue" (QueueServiceProvider) and register a driver, or call setQueueDispatcher(createQueueEventDispatcher()) on a manager you build yourself. A future major will throw here instead of running the listener inline.`);
185
+ await registered.listener(event);
186
+ return false;
187
+ }
188
+ return true;
189
+ }
190
+ /**
191
+ * Counted per event and queue, so an inline listener registered beside them
192
+ * does not move the numbers. The worker counts its own the same way, which is
193
+ * why both processes must register the queued listeners in the same order.
194
+ */
195
+ nextListenerSeq(eventName, queue) {
196
+ const key = `${eventName}\u0000${queue}`;
197
+ const next = this.listenerSeqCounters.get(key) ?? 0;
198
+ this.listenerSeqCounters.set(key, next + 1);
199
+ return next;
200
+ }
201
+ onQueue(eventName, queue) {
202
+ return (this.listeners.get(eventName) ?? []).filter((r) => r.options.queue === queue);
203
+ }
204
+ forget(eventName, registeredListeners, toRemove) {
205
+ for (const registered of toRemove) {
206
+ const index = registeredListeners.indexOf(registered);
207
+ if (index !== -1) registeredListeners.splice(index, 1);
208
+ }
209
+ if (registeredListeners.length === 0) this.listeners.delete(eventName);
210
+ }
211
+ /**
212
+ * The worker side of a queued emit: runs the listener the message names,
213
+ * with the event rebuilt as an instance of the registered class. An absent
214
+ * `listenerSeq` — a dispatcher of your own that does not send one — runs
215
+ * every listener for that event on that queue.
216
+ */
217
+ async handleQueued(queueName, eventName, data, listenerSeq) {
218
+ const onQueue = this.onQueue(eventName, queueName);
219
+ const named = listenerSeq === void 0 ? void 0 : onQueue.find((r) => r.listenerSeq === listenerSeq);
220
+ if (listenerSeq !== void 0 && named === void 0) throw new Error(`Queued event "${eventName}" names listener ${listenerSeq} on queue "${queueName}", but this process has no listener registered under that number (${onQueue.length} on that queue). The worker must register the same queued listeners, in the same order, as the process that emitted.`);
221
+ const event = this.rehydrate(eventName, data);
222
+ const toRun = named === void 0 ? onQueue : [named];
223
+ for (const registered of toRun) {
224
+ await registered.listener(event);
225
+ if (registered.options.once) this.off(eventName, registered.listener);
226
+ }
227
+ }
228
+ /**
229
+ * The worker side of a queued listener's failure, once the carrier job has
230
+ * run out of retries. Total by contract: an unknown listener, a class with no
231
+ * `failed()`, and an event it cannot rebuild are no-ops, since a throw here
232
+ * only buries the error that caused it.
233
+ */
234
+ async failedQueued(queueName, eventName, data, listenerSeq, error) {
235
+ if (listenerSeq === void 0 || !this.eventClasses.has(eventName)) return;
236
+ const registered = this.onQueue(eventName, queueName).find((r) => r.listenerSeq === listenerSeq);
237
+ if (!registered?.failed) return;
238
+ await registered.failed(this.rehydrate(eventName, data), error);
239
+ }
240
+ rehydrate(eventName, data) {
241
+ const eventClass = this.eventClasses.get(eventName);
242
+ if (!eventClass) throw new Error(`No event class is registered for "${eventName}", so the queued message cannot be rebuilt. Register it with events.registerEvent(EventClass) in the worker process, or listen for the class itself rather than the name. Pin the name with \`static eventName\` if the class may be renamed.`);
243
+ const event = Object.create(eventClass.prototype);
244
+ Object.assign(event, decodeEventData(data));
245
+ if (typeof event.timestamp === "string") event.timestamp = new Date(event.timestamp);
246
+ return event;
247
+ }
248
+ hasListeners(event) {
249
+ const listeners = this.listeners.get(this.nameOf(event));
250
+ return listeners !== void 0 && listeners.length > 0;
251
+ }
252
+ getListeners(event) {
253
+ const registeredListeners = this.listeners.get(this.nameOf(event));
254
+ if (!registeredListeners) return [];
255
+ return registeredListeners.map((r) => r.listener);
256
+ }
257
+ listenerCount(event) {
258
+ return this.listeners.get(this.nameOf(event))?.length ?? 0;
259
+ }
260
+ eventNames() {
261
+ return Array.from(this.listeners.keys());
262
+ }
263
+ removeAllListeners() {
264
+ this.listeners.clear();
265
+ this.eventClasses.clear();
266
+ }
267
+ /**
268
+ * `EventServiceProvider` installs `createQueueEventDispatcher()` at boot,
269
+ * before the app's queue driver necessarily exists. A dispatcher that finds
270
+ * no queue at emit time resolves false, and the listener runs inline rather
271
+ * than failing the emit.
272
+ */
273
+ setQueueDispatcher(dispatcher) {
274
+ this.queueDispatcher = dispatcher;
275
+ }
276
+ nameOf(event) {
277
+ return typeof event === "string" ? event : resolveEventName(event);
278
+ }
279
+ };
280
+ function createEventManager() {
281
+ return new EventManager();
282
+ }
283
+ //#endregion
284
+ //#region src/events/Listener.ts
285
+ /** Base class for reusable, class-based event listeners. */
286
+ var Listener = class {
287
+ /** Must be set by subclasses. */
288
+ static event;
289
+ /** @default false */
290
+ static shouldQueue = false;
291
+ /**
292
+ * Used when `shouldQueue`.
293
+ * @default 'default'
294
+ */
295
+ static queue = "default";
296
+ /**
297
+ * Higher runs first.
298
+ * @default 0
299
+ */
300
+ static priority = 0;
301
+ };
302
+ //#endregion
303
+ //#region src/events/queued.ts
304
+ /**
305
+ * Carries a queued emit to the worker, which runs the listener through the
306
+ * app's `events` binding. One message per queued listener, so a listener that
307
+ * throws is retried on its own rather than re-running the ones beside it.
308
+ */
309
+ var QueuedEventJob = class extends Job {
310
+ static jobName = "QueuedEventJob";
311
+ async handle(payload) {
312
+ await this.make("events").handleQueued(payload.queue, payload.eventName, payload.event, payload.listenerSeq);
313
+ }
314
+ async failed(payload, error) {
315
+ await this.make("events").failedQueued(payload.queue, payload.eventName, payload.event, payload.listenerSeq, error);
316
+ }
317
+ };
318
+ /**
319
+ * The dispatcher `EventServiceProvider` installs at boot. Registers the carrier
320
+ * job too, which is what lets a worker booting the same app resolve the message.
321
+ * Resolves false rather than letting `Job.dispatch()` throw: it is installed
322
+ * before the app's queue is bound, and an emit it cannot queue runs inline.
323
+ */
324
+ function createQueueEventDispatcher() {
325
+ registerJob(QueuedEventJob);
326
+ return async (queue, eventName, event, listenerSeq) => {
327
+ if (resolveQueueDriver() === null) return false;
328
+ await QueuedEventJob.dispatch({
329
+ queue,
330
+ eventName,
331
+ event: encodeEventData(event),
332
+ listenerSeq
333
+ }, { queue });
334
+ return true;
335
+ };
336
+ }
337
+ //#endregion
338
+ //#region src/events/builtin.ts
339
+ var RequestReceived = class extends Event {
340
+ method;
341
+ path;
342
+ requestId;
343
+ constructor(method, path, requestId) {
344
+ super();
345
+ this.method = method;
346
+ this.path = path;
347
+ this.requestId = requestId;
348
+ }
349
+ };
350
+ var RequestFinished = class extends Event {
351
+ method;
352
+ path;
353
+ status;
354
+ durationMs;
355
+ requestId;
356
+ constructor(method, path, status, durationMs, requestId) {
357
+ super();
358
+ this.method = method;
359
+ this.path = path;
360
+ this.status = status;
361
+ this.durationMs = durationMs;
362
+ this.requestId = requestId;
363
+ }
364
+ };
365
+ var UserAuthenticated = class extends Event {
366
+ userId;
367
+ guard;
368
+ constructor(userId, guard = "default") {
369
+ super();
370
+ this.userId = userId;
371
+ this.guard = guard;
372
+ }
373
+ };
374
+ var UserLoggedOut = class extends Event {
375
+ userId;
376
+ guard;
377
+ constructor(userId, guard = "default") {
378
+ super();
379
+ this.userId = userId;
380
+ this.guard = guard;
381
+ }
382
+ };
383
+ var JobProcessed = class extends Event {
384
+ jobId;
385
+ jobName;
386
+ queue;
387
+ durationMs;
388
+ constructor(jobId, jobName, queue, durationMs) {
389
+ super();
390
+ this.jobId = jobId;
391
+ this.jobName = jobName;
392
+ this.queue = queue;
393
+ this.durationMs = durationMs;
394
+ }
395
+ };
396
+ var JobFailed = class extends Event {
397
+ jobId;
398
+ jobName;
399
+ queue;
400
+ error;
401
+ attempts;
402
+ constructor(jobId, jobName, queue, error, attempts) {
403
+ super();
404
+ this.jobId = jobId;
405
+ this.jobName = jobName;
406
+ this.queue = queue;
407
+ this.error = error;
408
+ this.attempts = attempts;
409
+ }
410
+ };
411
+ var ApplicationStarted = class extends Event {
412
+ port;
413
+ host;
414
+ constructor(port, host) {
415
+ super();
416
+ this.port = port;
417
+ this.host = host;
418
+ }
419
+ };
420
+ var ApplicationShutdown = class extends Event {
421
+ reason;
422
+ constructor(reason) {
423
+ super();
424
+ this.reason = reason;
425
+ }
426
+ };
427
+ //#endregion
428
+ export { RequestFinished as a, UserLoggedOut as c, EventManager as d, createEventManager as f, JobProcessed as i, createQueueEventDispatcher as l, ApplicationStarted as n, RequestReceived as o, Event as p, JobFailed as r, UserAuthenticated as s, ApplicationShutdown as t, Listener as u };
@@ -1,10 +1,8 @@
1
1
  import type { CheckResult } from '../types.js';
2
+ import type { CacheStore } from '../../cache/types.js';
2
3
  import { HealthCheck } from '../HealthCheck.js';
3
- export interface CacheStoreInterface {
4
- get<T>(key: string): Promise<T | null>;
5
- put<T>(key: string, value: T, ttl?: number): Promise<void>;
6
- forget(key: string): Promise<boolean>;
7
- }
4
+ /** The slice of `CacheStore` the check exercises; `cache.store()` satisfies it. */
5
+ export type CacheStoreInterface = Pick<CacheStore, 'get' | 'set' | 'delete'>;
8
6
  export interface CacheCheckOptions {
9
7
  /** @default 'cache' */
10
8
  name?: string;
@@ -1,10 +1,8 @@
1
1
  import type { CheckResult } from '../types.js';
2
+ import type { StorageDriver } from '../../storage/types.js';
2
3
  import { HealthCheck } from '../HealthCheck.js';
3
- export interface StorageDriverInterface {
4
- put(path: string, contents: string | Buffer): Promise<void>;
5
- get(path: string): Promise<Buffer | null>;
6
- delete(path: string): Promise<boolean>;
7
- }
4
+ /** The slice of `StorageDriver` the check exercises; `storage.disk()` satisfies it. */
5
+ export type StorageDriverInterface = Pick<StorageDriver, 'put' | 'get' | 'delete'>;
8
6
  export interface StorageCheckOptions {
9
7
  /** @default 'storage' */
10
8
  name?: string;
@@ -1,2 +1,2 @@
1
- import { a as CacheCheck, c as HealthManager, i as StorageCheck, l as createHealthManager, n as customCheck, o as RedisCheck, r as MemoryCheck, s as DatabaseCheck, t as CustomCheck, u as HealthCheck } from "../health-DQSvUplL.js";
1
+ import { a as CacheCheck, c as HealthManager, i as StorageCheck, l as createHealthManager, n as customCheck, o as RedisCheck, r as MemoryCheck, s as DatabaseCheck, t as CustomCheck, u as HealthCheck } from "../health-CB0oS_UE.js";
2
2
  export { CacheCheck, CustomCheck, DatabaseCheck, HealthCheck, HealthManager, MemoryCheck, RedisCheck, StorageCheck, createHealthManager, customCheck };
@@ -177,9 +177,9 @@ var CacheCheck = class extends HealthCheck {
177
177
  async check() {
178
178
  const testValue = `health_check_${Date.now()}`;
179
179
  try {
180
- await this.cache.put(this.testKey, testValue, 60);
180
+ await this.cache.set(this.testKey, testValue, 60);
181
181
  const retrieved = await this.cache.get(this.testKey);
182
- await this.cache.forget(this.testKey);
182
+ await this.cache.delete(this.testKey);
183
183
  if (retrieved === testValue) return this.healthy("Cache is functioning correctly");
184
184
  return this.degraded(`Cache read/write mismatch: expected "${testValue}", got "${retrieved}"`);
185
185
  } catch (error) {
@@ -5,6 +5,7 @@ import { type PrototypeFixtureLoader } from '../mvc/prototype.js';
5
5
  import { Container, type GurenModule } from '../container/index.js';
6
6
  import { type ServiceProviderConstructor } from '../container/ServiceProvider.js';
7
7
  import { AuthManager } from '../auth/AuthManager.js';
8
+ import type { PasswordHasherOption } from '../auth/password/configured-hasher.js';
8
9
  import type { CreateSessionMiddlewareOptions } from './middleware/session.js';
9
10
  import type { DetectLocaleOptions } from './middleware/detect-locale.js';
10
11
  import type { TranslationLoader } from '../i18n/index.js';
@@ -12,6 +13,7 @@ import { type SecurityHeadersOptions } from './middleware/security-headers.js';
12
13
  import { type HostAuthorizationOptions } from './middleware/host-authorization.js';
13
14
  import { type DevBannerOptions } from './dev-banner.js';
14
15
  import { startViteDevServer, type StartViteDevServerOptions } from './vite-dev-server.js';
16
+ import type { InertiaDocumentOptions, InertiaSsrRenderer } from '../mvc/inertia/InertiaEngine.js';
15
17
  type BunServer = {
16
18
  stop?: (closeConnections?: boolean) => void | Promise<void>;
17
19
  requestIP?: (request: Request) => {
@@ -74,6 +76,18 @@ export interface ApplicationOptions {
74
76
  * Loaded at boot only when such a route exists.
75
77
  */
76
78
  readonly prototype?: PrototypeFixtureLoader;
79
+ /**
80
+ * App-wide Inertia rendering defaults, bound as `inertia.document` and
81
+ * `inertia.ssrRenderer` on this app's container (RFC 0023 §1) and read by
82
+ * `Controller.inertia()` ahead of the process-wide setters.
83
+ */
84
+ readonly inertia?: InertiaApplicationOptions;
85
+ }
86
+ export interface InertiaApplicationOptions {
87
+ /** Document defaults for server-rendered responses; each per-response {@link InertiaOptions} field overrides its own. */
88
+ readonly document?: InertiaDocumentOptions;
89
+ /** Default SSR renderer, for a bundle that cannot resolve a runtime path; per-call `ssr.render` still wins. */
90
+ readonly ssrRenderer?: InertiaSsrRenderer;
77
91
  }
78
92
  export interface I18nPluginOptions {
79
93
  /** Detection only resolves to one of these; all are preloaded during `boot()`. */
@@ -94,6 +108,13 @@ export interface I18nPluginOptions {
94
108
  readonly share?: boolean;
95
109
  }
96
110
  export interface AuthPluginOptions {
111
+ /**
112
+ * The format new password hashes are written in. `'scrypt'` (the default)
113
+ * verifies on every runtime; `'argon2'` uses `Bun.password` and is for
114
+ * Bun-only deployments. Rows in the other format still verify and are
115
+ * rehashed on their next login. A `PasswordHasher` replaces both.
116
+ */
117
+ hasher?: PasswordHasherOption;
97
118
  autoSession?: boolean;
98
119
  sessionOptions?: CreateSessionMiddlewareOptions;
99
120
  /** Defaults to `true` when session is enabled. */
@@ -196,6 +217,13 @@ export declare class Application {
196
217
  */
197
218
  booted(): Promise<void>;
198
219
  private bootOnce;
220
+ /**
221
+ * After every provider has booted: `auth` was asked for, yet the default
222
+ * guard still runs against the placeholder provider, so a session login
223
+ * attempt would throw. Silent for an app that authenticates through tokens,
224
+ * or that mounts its own sessions, since neither reaches that guard.
225
+ */
226
+ private warnOnUnconfiguredAuth;
199
227
  /** Called once, from the constructor — see the note there for why. */
200
228
  private mountSecurityDefaults;
201
229
  private mountHostAuthorization;
@@ -0,0 +1,33 @@
1
+ import type { Application } from './Application.js';
2
+ import type { ServiceBindings } from '../container/bindings.js';
3
+ import { type Container } from '../container/Container.js';
4
+ /** @internal Application constructor only. Displacing a still-ambient app is what makes the choice ambiguous. */
5
+ export declare function adoptDefaultApplication(app: Application): void;
6
+ /** Opt-in override for a process that constructs several and wants the ambient one chosen, not last. */
7
+ export declare function useAsDefaultApplication(app: Application): void;
8
+ /** @internal Test seam: empties the ambient slot and the ambiguity flag. */
9
+ export declare function resetDefaultApplication(): void;
10
+ /**
11
+ * The most recently constructed Application; `null` before any exists, and
12
+ * `null` again once `setContainer()` handed the ambient slot a container that
13
+ * belongs to no Application.
14
+ */
15
+ export declare function defaultApplication(): Application | null;
16
+ /** The default application's container; throws the same "not initialized" error the getters throw. */
17
+ export declare function defaultContainer(): Container;
18
+ /** `defaultContainer()` for a caller with a fallback of its own: null instead of the throw. */
19
+ export declare function ambientContainer(): Container | null;
20
+ /**
21
+ * The binding the default application holds under `key`, or undefined when
22
+ * there is no default application or it binds nothing there. Every functional
23
+ * helper reads through this before its module slot (RFC 0023 §3).
24
+ */
25
+ export declare function ambientBinding<K extends keyof ServiceBindings>(key: K): ServiceBindings[K] | undefined;
26
+ /**
27
+ * @internal A deprecated setter's write (RFC 0023 §5): the ambient container
28
+ * when one exists, else nothing. Answers whether it landed, so the caller can
29
+ * drop its module slot rather than leave a copy that outlives the app.
30
+ */
31
+ export declare function bindAmbient<K extends keyof ServiceBindings>(key: K, value: ServiceBindings[K]): boolean;
32
+ /** Resolve `key` from the default application's container. */
33
+ export declare function resolve<T = unknown>(key: string): T;
@@ -31,7 +31,8 @@ export interface DetectLocaleOptions {
31
31
  cookieName?: string;
32
32
  /**
33
33
  * Manager backing the request-scoped `t`/`tc` helpers. Defaults to the
34
- * global one registered via `setI18n()`; `false` skips the binding.
34
+ * serving app's `i18n` binding, then the one `setI18n()` registered;
35
+ * `false` skips the binding.
35
36
  */
36
37
  i18n?: I18nManager | false;
37
38
  }
@@ -0,0 +1,25 @@
1
+ import type { Container } from '../container/Container.js';
2
+ /**
3
+ * Context variable the serving Application's container is stamped under
4
+ * (RFC 0023 §2). The stamp is the first middleware `Application` mounts, so
5
+ * nothing an app registers runs ahead of it. The one place a middleware
6
+ * reaches its app's container without holding the app.
7
+ */
8
+ export declare const CONTAINER_CONTEXT_KEY = "guren.container";
9
+ declare module 'hono' {
10
+ interface ContextVariableMap {
11
+ [CONTAINER_CONTEXT_KEY]: Container;
12
+ }
13
+ }
14
+ /** The narrowest surface every Hono `Context` and `ContextVariableMap`-typed context satisfies. */
15
+ export interface RequestContextLike {
16
+ get: (key: string) => unknown;
17
+ }
18
+ /**
19
+ * The container of the Application serving `ctx`, or undefined off an
20
+ * Application (bare Hono). Judged by shape rather than `instanceof`: a test
21
+ * double answering every key must not pass as a container.
22
+ */
23
+ export declare function tryGetRequestContainer(ctx: RequestContextLike): Container | undefined;
24
+ /** The container of the Application serving `ctx`; throws off an Application (bare Hono). */
25
+ export declare function getRequestContainer(ctx: RequestContextLike): Container;
@@ -36,12 +36,25 @@ export declare class I18nManager {
36
36
  }
37
37
  /** Create a new I18n manager. */
38
38
  export declare function createI18n(config: I18nConfig): I18nManager;
39
- /** Set the global I18n manager. */
39
+ /**
40
+ * @deprecated since 2.23.0, removed in 3.0.0 (RFC 0023). Pass
41
+ * `createApp({ i18n })`, or bind it from a provider as
42
+ * `this.container.instance('i18n', manager)`.
43
+ */
40
44
  export declare function setI18n(i18n: I18nManager): void;
41
- /** Get the global I18n manager. */
45
+ /**
46
+ * @deprecated since 2.23.0, removed in 3.0.0 (RFC 0023). Use `this.t(key)` in a
47
+ * controller, `getRequestTranslator(ctx)` in middleware, or
48
+ * `defaultContainer().make('i18n')`. `t()` / `tc()` are unaffected.
49
+ */
42
50
  export declare function getI18n(): I18nManager;
43
- /** Get the global I18n manager, or `undefined` when none was registered. */
51
+ /**
52
+ * @deprecated since 2.23.0, removed in 3.0.0 (RFC 0023). Use
53
+ * `container.makeOptional('i18n')` on the container that owns the call.
54
+ */
44
55
  export declare function tryGetI18n(): I18nManager | undefined;
56
+ /** @internal The default application's `i18n`, else the one `setI18n()` installed. */
57
+ export declare function resolveI18n(): I18nManager | undefined;
45
58
  /** Translate a key using the global I18n manager. */
46
59
  export declare function t(key: string, replacements?: ReplacementValues): string;
47
60
  /** Translate a key with count using the global I18n manager. */
@@ -1,6 +1,6 @@
1
1
  export type { TranslationMessages, ReplacementValues, GurenTranslationKeys, RegisteredTranslationKey, PluralizationRule, TranslationLoader, TranslatorOptions, I18nConfig, TranslationLoaderFactory, } from './types.js';
2
2
  export { pluralizationRules, getPluralizationRule, selectPluralForm, } from './pluralization.js';
3
3
  export { Translator } from './Translator.js';
4
- export { I18nManager, createI18n, setI18n, getI18n, tryGetI18n, t, tc, } from './I18nManager.js';
4
+ export { I18nManager, createI18n, setI18n, getI18n, tryGetI18n, resolveI18n, t, tc, } from './I18nManager.js';
5
5
  export { JsonLoader } from './loaders/JsonLoader.js';
6
6
  export { MemoryLoader } from './loaders/MemoryLoader.js';
@@ -1,2 +1,2 @@
1
- import { a as setI18n, c as tryGetI18n, d as getPluralizationRule, f as pluralizationRules, i as getI18n, l as JsonLoader, n as I18nManager, o as t, p as selectPluralForm, r as createI18n, s as tc, t as MemoryLoader, u as Translator } from "../i18n-BZ2VrSud.js";
2
- export { I18nManager, JsonLoader, MemoryLoader, Translator, createI18n, getI18n, getPluralizationRule, pluralizationRules, selectPluralForm, setI18n, t, tc, tryGetI18n };
1
+ import { a as resolveI18n, c as tc, d as Translator, f as getPluralizationRule, i as getI18n, l as tryGetI18n, m as selectPluralForm, n as I18nManager, o as setI18n, p as pluralizationRules, r as createI18n, s as t, t as MemoryLoader, u as JsonLoader } from "../i18n-DRo1g0AN.js";
2
+ export { I18nManager, JsonLoader, MemoryLoader, Translator, createI18n, getI18n, getPluralizationRule, pluralizationRules, resolveI18n, selectPluralForm, setI18n, t, tc, tryGetI18n };