@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,155 @@
|
|
|
1
|
+
import { a as Event, b as EventClass } from '../EventManager-CmIoLt7r.js';
|
|
2
|
+
export { c as EventListener, E as EventManager, d as EventSubscription, L as ListenerOptions, R as RegisteredListener, e as createEventManager } from '../EventManager-CmIoLt7r.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class for event listeners.
|
|
6
|
+
* Extend this class to create reusable, class-based event listeners.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* class SendWelcomeEmail extends Listener<UserRegistered> {
|
|
11
|
+
* static event = UserRegistered
|
|
12
|
+
* static shouldQueue = true
|
|
13
|
+
* static queue = 'emails'
|
|
14
|
+
*
|
|
15
|
+
* async handle(event: UserRegistered): Promise<void> {
|
|
16
|
+
* await mail.to(event.email).subject('Welcome!').send()
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* shouldHandle(event: UserRegistered): boolean {
|
|
20
|
+
* // Only send to non-admin users
|
|
21
|
+
* return !event.isAdmin
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare abstract class Listener<T extends Event = Event> {
|
|
27
|
+
/**
|
|
28
|
+
* The event class this listener handles.
|
|
29
|
+
* Must be set by subclasses.
|
|
30
|
+
*/
|
|
31
|
+
static event: EventClass;
|
|
32
|
+
/**
|
|
33
|
+
* Whether this listener should be queued instead of executed immediately.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
static shouldQueue: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The queue name to dispatch to when shouldQueue is true.
|
|
39
|
+
* @default 'default'
|
|
40
|
+
*/
|
|
41
|
+
static queue: string;
|
|
42
|
+
/**
|
|
43
|
+
* Priority of this listener. Higher values are executed first.
|
|
44
|
+
* @default 0
|
|
45
|
+
*/
|
|
46
|
+
static priority: number;
|
|
47
|
+
/**
|
|
48
|
+
* Handle the event.
|
|
49
|
+
* This method must be implemented by subclasses.
|
|
50
|
+
*
|
|
51
|
+
* @param event - The event instance
|
|
52
|
+
*/
|
|
53
|
+
abstract handle(event: T): void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Determine if this listener should handle the event.
|
|
56
|
+
* Override this method to conditionally handle events.
|
|
57
|
+
*
|
|
58
|
+
* @param event - The event instance
|
|
59
|
+
* @returns true if the listener should handle the event
|
|
60
|
+
*/
|
|
61
|
+
shouldHandle?(event: T): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Called when the listener fails to handle the event.
|
|
64
|
+
* Override this method to handle errors.
|
|
65
|
+
*
|
|
66
|
+
* @param event - The event instance
|
|
67
|
+
* @param error - The error that occurred
|
|
68
|
+
*/
|
|
69
|
+
failed?(event: T, error: Error): void | Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Listener class constructor type.
|
|
73
|
+
*/
|
|
74
|
+
interface ListenerClass<T extends Event = Event> {
|
|
75
|
+
new (): Listener<T>;
|
|
76
|
+
event: EventClass<T>;
|
|
77
|
+
shouldQueue: boolean;
|
|
78
|
+
queue: string;
|
|
79
|
+
priority: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Emitted when an HTTP request is received.
|
|
84
|
+
*/
|
|
85
|
+
declare class RequestReceived extends Event {
|
|
86
|
+
readonly method: string;
|
|
87
|
+
readonly path: string;
|
|
88
|
+
readonly requestId?: string | undefined;
|
|
89
|
+
constructor(method: string, path: string, requestId?: string | undefined);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Emitted when an HTTP request has finished processing.
|
|
93
|
+
*/
|
|
94
|
+
declare class RequestFinished extends Event {
|
|
95
|
+
readonly method: string;
|
|
96
|
+
readonly path: string;
|
|
97
|
+
readonly status: number;
|
|
98
|
+
readonly durationMs: number;
|
|
99
|
+
readonly requestId?: string | undefined;
|
|
100
|
+
constructor(method: string, path: string, status: number, durationMs: number, requestId?: string | undefined);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Emitted when a user successfully authenticates.
|
|
104
|
+
*/
|
|
105
|
+
declare class UserAuthenticated extends Event {
|
|
106
|
+
readonly userId: string | number;
|
|
107
|
+
readonly guard: string;
|
|
108
|
+
constructor(userId: string | number, guard?: string);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Emitted when a user logs out.
|
|
112
|
+
*/
|
|
113
|
+
declare class UserLoggedOut extends Event {
|
|
114
|
+
readonly userId: string | number;
|
|
115
|
+
readonly guard: string;
|
|
116
|
+
constructor(userId: string | number, guard?: string);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Emitted when a queued job is successfully processed.
|
|
120
|
+
*/
|
|
121
|
+
declare class JobProcessed extends Event {
|
|
122
|
+
readonly jobId: string;
|
|
123
|
+
readonly jobName: string;
|
|
124
|
+
readonly queue: string;
|
|
125
|
+
readonly durationMs: number;
|
|
126
|
+
constructor(jobId: string, jobName: string, queue: string, durationMs: number);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Emitted when a queued job fails.
|
|
130
|
+
*/
|
|
131
|
+
declare class JobFailed extends Event {
|
|
132
|
+
readonly jobId: string;
|
|
133
|
+
readonly jobName: string;
|
|
134
|
+
readonly queue: string;
|
|
135
|
+
readonly error: Error;
|
|
136
|
+
readonly attempts: number;
|
|
137
|
+
constructor(jobId: string, jobName: string, queue: string, error: Error, attempts: number);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Emitted when the application starts.
|
|
141
|
+
*/
|
|
142
|
+
declare class ApplicationStarted extends Event {
|
|
143
|
+
readonly port: number;
|
|
144
|
+
readonly host: string;
|
|
145
|
+
constructor(port: number, host: string);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Emitted when the application is shutting down.
|
|
149
|
+
*/
|
|
150
|
+
declare class ApplicationShutdown extends Event {
|
|
151
|
+
readonly reason?: string | undefined;
|
|
152
|
+
constructor(reason?: string | undefined);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { ApplicationShutdown, ApplicationStarted, Event, EventClass, JobFailed, JobProcessed, Listener, type ListenerClass, RequestFinished, RequestReceived, UserAuthenticated, UserLoggedOut };
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// src/events/Event.ts
|
|
2
|
+
var Event = class {
|
|
3
|
+
/**
|
|
4
|
+
* Timestamp when the event was created.
|
|
5
|
+
*/
|
|
6
|
+
timestamp = /* @__PURE__ */ new Date();
|
|
7
|
+
/**
|
|
8
|
+
* Get the event name (class name by default).
|
|
9
|
+
* Override this to customize the event name.
|
|
10
|
+
*/
|
|
11
|
+
static get eventName() {
|
|
12
|
+
return this.name;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the event name from an instance.
|
|
16
|
+
*/
|
|
17
|
+
get eventName() {
|
|
18
|
+
return this.constructor.eventName;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/events/EventManager.ts
|
|
23
|
+
var EventManager = class {
|
|
24
|
+
listeners = /* @__PURE__ */ new Map();
|
|
25
|
+
/**
|
|
26
|
+
* Queue dispatcher function (set when Queue system is integrated).
|
|
27
|
+
*/
|
|
28
|
+
queueDispatcher;
|
|
29
|
+
/**
|
|
30
|
+
* Register a listener for an event.
|
|
31
|
+
*
|
|
32
|
+
* @param event - Event class to listen for
|
|
33
|
+
* @param listener - Listener function
|
|
34
|
+
* @param options - Listener options
|
|
35
|
+
* @returns Subscription handle for unsubscribing
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* // Basic usage
|
|
40
|
+
* events.on(UserRegistered, (e) => console.log(e.email))
|
|
41
|
+
*
|
|
42
|
+
* // With options
|
|
43
|
+
* events.on(UserRegistered, (e) => sendEmail(e), { priority: 10 })
|
|
44
|
+
*
|
|
45
|
+
* // Unsubscribe later
|
|
46
|
+
* const sub = events.on(UserRegistered, handler)
|
|
47
|
+
* sub.unsubscribe()
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
on(event, listener, options = {}) {
|
|
51
|
+
const eventName = typeof event === "string" ? event : event.eventName;
|
|
52
|
+
const registeredListeners = this.listeners.get(eventName) ?? [];
|
|
53
|
+
const registered = {
|
|
54
|
+
listener,
|
|
55
|
+
options: { once: false, priority: 0, ...options }
|
|
56
|
+
};
|
|
57
|
+
registeredListeners.push(registered);
|
|
58
|
+
registeredListeners.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0));
|
|
59
|
+
this.listeners.set(eventName, registeredListeners);
|
|
60
|
+
return {
|
|
61
|
+
unsubscribe: () => this.off(event, listener)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Register a one-time listener for an event.
|
|
66
|
+
* The listener will be automatically removed after the first invocation.
|
|
67
|
+
*
|
|
68
|
+
* @param event - Event class to listen for
|
|
69
|
+
* @param listener - Listener function
|
|
70
|
+
* @param options - Additional listener options (once is always true)
|
|
71
|
+
* @returns Subscription handle for unsubscribing
|
|
72
|
+
*/
|
|
73
|
+
once(event, listener, options = {}) {
|
|
74
|
+
return this.on(event, listener, { ...options, once: true });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Remove a listener for an event.
|
|
78
|
+
*
|
|
79
|
+
* @param event - Event class
|
|
80
|
+
* @param listener - Listener to remove (if omitted, all listeners for the event are removed)
|
|
81
|
+
*/
|
|
82
|
+
off(event, listener) {
|
|
83
|
+
const eventName = typeof event === "string" ? event : event.eventName;
|
|
84
|
+
const registeredListeners = this.listeners.get(eventName);
|
|
85
|
+
if (!registeredListeners) return;
|
|
86
|
+
if (!listener) {
|
|
87
|
+
this.listeners.delete(eventName);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const index = registeredListeners.findIndex((r) => r.listener === listener);
|
|
91
|
+
if (index !== -1) {
|
|
92
|
+
registeredListeners.splice(index, 1);
|
|
93
|
+
if (registeredListeners.length === 0) {
|
|
94
|
+
this.listeners.delete(eventName);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Emit an event to all registered listeners.
|
|
100
|
+
* Listeners are executed in order of priority (highest first).
|
|
101
|
+
* Async listeners are awaited sequentially.
|
|
102
|
+
*
|
|
103
|
+
* @param event - Event instance to emit
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* await events.emit(new UserRegistered('123', 'user@example.com'))
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
async emit(event) {
|
|
111
|
+
const eventName = event.eventName;
|
|
112
|
+
const registeredListeners = this.listeners.get(eventName);
|
|
113
|
+
if (!registeredListeners || registeredListeners.length === 0) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const listenersToCall = [...registeredListeners];
|
|
117
|
+
const toRemove = [];
|
|
118
|
+
for (const registered of listenersToCall) {
|
|
119
|
+
if (registered.options.queue && this.queueDispatcher) {
|
|
120
|
+
await this.queueDispatcher(registered.options.queue, eventName, event);
|
|
121
|
+
} else {
|
|
122
|
+
await registered.listener(event);
|
|
123
|
+
}
|
|
124
|
+
if (registered.options.once) {
|
|
125
|
+
toRemove.push(registered);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const registered of toRemove) {
|
|
129
|
+
const index = registeredListeners.indexOf(registered);
|
|
130
|
+
if (index !== -1) {
|
|
131
|
+
registeredListeners.splice(index, 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (registeredListeners.length === 0) {
|
|
135
|
+
this.listeners.delete(eventName);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Emit an event to all registered listeners in parallel.
|
|
140
|
+
* Use this when listener execution order doesn't matter and you want faster execution.
|
|
141
|
+
*
|
|
142
|
+
* @param event - Event instance to emit
|
|
143
|
+
*/
|
|
144
|
+
async emitParallel(event) {
|
|
145
|
+
const eventName = event.eventName;
|
|
146
|
+
const registeredListeners = this.listeners.get(eventName);
|
|
147
|
+
if (!registeredListeners || registeredListeners.length === 0) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const listenersToCall = [...registeredListeners];
|
|
151
|
+
const toRemove = [];
|
|
152
|
+
await Promise.all(
|
|
153
|
+
listenersToCall.map(async (registered) => {
|
|
154
|
+
if (registered.options.queue && this.queueDispatcher) {
|
|
155
|
+
await this.queueDispatcher(registered.options.queue, eventName, event);
|
|
156
|
+
} else {
|
|
157
|
+
await registered.listener(event);
|
|
158
|
+
}
|
|
159
|
+
if (registered.options.once) {
|
|
160
|
+
toRemove.push(registered);
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
for (const registered of toRemove) {
|
|
165
|
+
const index = registeredListeners.indexOf(registered);
|
|
166
|
+
if (index !== -1) {
|
|
167
|
+
registeredListeners.splice(index, 1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (registeredListeners.length === 0) {
|
|
171
|
+
this.listeners.delete(eventName);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check if an event has any listeners registered.
|
|
176
|
+
*
|
|
177
|
+
* @param event - Event class or event name
|
|
178
|
+
*/
|
|
179
|
+
hasListeners(event) {
|
|
180
|
+
const eventName = typeof event === "string" ? event : event.eventName;
|
|
181
|
+
const listeners = this.listeners.get(eventName);
|
|
182
|
+
return listeners !== void 0 && listeners.length > 0;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get all listeners for an event.
|
|
186
|
+
*
|
|
187
|
+
* @param event - Event class or event name
|
|
188
|
+
*/
|
|
189
|
+
getListeners(event) {
|
|
190
|
+
const eventName = typeof event === "string" ? event : event.eventName;
|
|
191
|
+
const registeredListeners = this.listeners.get(eventName);
|
|
192
|
+
if (!registeredListeners) return [];
|
|
193
|
+
return registeredListeners.map((r) => r.listener);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get the count of listeners for an event.
|
|
197
|
+
*
|
|
198
|
+
* @param event - Event class or event name
|
|
199
|
+
*/
|
|
200
|
+
listenerCount(event) {
|
|
201
|
+
const eventName = typeof event === "string" ? event : event.eventName;
|
|
202
|
+
return this.listeners.get(eventName)?.length ?? 0;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get all registered event names.
|
|
206
|
+
*/
|
|
207
|
+
eventNames() {
|
|
208
|
+
return Array.from(this.listeners.keys());
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Remove all listeners for all events.
|
|
212
|
+
*/
|
|
213
|
+
removeAllListeners() {
|
|
214
|
+
this.listeners.clear();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Set the queue dispatcher function.
|
|
218
|
+
* This is called by the Queue system when it's integrated.
|
|
219
|
+
*/
|
|
220
|
+
setQueueDispatcher(dispatcher) {
|
|
221
|
+
this.queueDispatcher = dispatcher;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
function createEventManager() {
|
|
225
|
+
return new EventManager();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/events/Listener.ts
|
|
229
|
+
var Listener = class {
|
|
230
|
+
/**
|
|
231
|
+
* The event class this listener handles.
|
|
232
|
+
* Must be set by subclasses.
|
|
233
|
+
*/
|
|
234
|
+
static event;
|
|
235
|
+
/**
|
|
236
|
+
* Whether this listener should be queued instead of executed immediately.
|
|
237
|
+
* @default false
|
|
238
|
+
*/
|
|
239
|
+
static shouldQueue = false;
|
|
240
|
+
/**
|
|
241
|
+
* The queue name to dispatch to when shouldQueue is true.
|
|
242
|
+
* @default 'default'
|
|
243
|
+
*/
|
|
244
|
+
static queue = "default";
|
|
245
|
+
/**
|
|
246
|
+
* Priority of this listener. Higher values are executed first.
|
|
247
|
+
* @default 0
|
|
248
|
+
*/
|
|
249
|
+
static priority = 0;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/events/builtin.ts
|
|
253
|
+
var RequestReceived = class extends Event {
|
|
254
|
+
constructor(method, path, requestId) {
|
|
255
|
+
super();
|
|
256
|
+
this.method = method;
|
|
257
|
+
this.path = path;
|
|
258
|
+
this.requestId = requestId;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
var RequestFinished = class extends Event {
|
|
262
|
+
constructor(method, path, status, durationMs, requestId) {
|
|
263
|
+
super();
|
|
264
|
+
this.method = method;
|
|
265
|
+
this.path = path;
|
|
266
|
+
this.status = status;
|
|
267
|
+
this.durationMs = durationMs;
|
|
268
|
+
this.requestId = requestId;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
var UserAuthenticated = class extends Event {
|
|
272
|
+
constructor(userId, guard = "default") {
|
|
273
|
+
super();
|
|
274
|
+
this.userId = userId;
|
|
275
|
+
this.guard = guard;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var UserLoggedOut = class extends Event {
|
|
279
|
+
constructor(userId, guard = "default") {
|
|
280
|
+
super();
|
|
281
|
+
this.userId = userId;
|
|
282
|
+
this.guard = guard;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var JobProcessed = class extends Event {
|
|
286
|
+
constructor(jobId, jobName, queue, durationMs) {
|
|
287
|
+
super();
|
|
288
|
+
this.jobId = jobId;
|
|
289
|
+
this.jobName = jobName;
|
|
290
|
+
this.queue = queue;
|
|
291
|
+
this.durationMs = durationMs;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var JobFailed = class extends Event {
|
|
295
|
+
constructor(jobId, jobName, queue, error, attempts) {
|
|
296
|
+
super();
|
|
297
|
+
this.jobId = jobId;
|
|
298
|
+
this.jobName = jobName;
|
|
299
|
+
this.queue = queue;
|
|
300
|
+
this.error = error;
|
|
301
|
+
this.attempts = attempts;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var ApplicationStarted = class extends Event {
|
|
305
|
+
constructor(port, host) {
|
|
306
|
+
super();
|
|
307
|
+
this.port = port;
|
|
308
|
+
this.host = host;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var ApplicationShutdown = class extends Event {
|
|
312
|
+
constructor(reason) {
|
|
313
|
+
super();
|
|
314
|
+
this.reason = reason;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
export {
|
|
318
|
+
ApplicationShutdown,
|
|
319
|
+
ApplicationStarted,
|
|
320
|
+
Event,
|
|
321
|
+
EventManager,
|
|
322
|
+
JobFailed,
|
|
323
|
+
JobProcessed,
|
|
324
|
+
Listener,
|
|
325
|
+
RequestFinished,
|
|
326
|
+
RequestReceived,
|
|
327
|
+
UserAuthenticated,
|
|
328
|
+
UserLoggedOut,
|
|
329
|
+
createEventManager
|
|
330
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { a as HealthCheck, C as CheckResult, e as HealthStatus } from '../HealthManager-DUyMIzsZ.js';
|
|
2
|
+
export { b as HealthCheckOptions, H as HealthManager, c as HealthMiddlewareOptions, d as HealthReport, f as createHealthManager } from '../HealthManager-DUyMIzsZ.js';
|
|
3
|
+
import '../index-9_Jzj5jo.js';
|
|
4
|
+
import 'hono';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Database connection interface (minimal).
|
|
8
|
+
*/
|
|
9
|
+
interface DatabaseConnection {
|
|
10
|
+
query(sql: string): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Options for database health check.
|
|
14
|
+
*/
|
|
15
|
+
interface DatabaseCheckOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Custom name for this check.
|
|
18
|
+
* @default 'database'
|
|
19
|
+
*/
|
|
20
|
+
name?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Custom query to execute.
|
|
23
|
+
* @default 'SELECT 1'
|
|
24
|
+
*/
|
|
25
|
+
query?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Health check for database connectivity.
|
|
29
|
+
*/
|
|
30
|
+
declare class DatabaseCheck extends HealthCheck {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
private db;
|
|
33
|
+
private query;
|
|
34
|
+
constructor(db: DatabaseConnection, options?: DatabaseCheckOptions);
|
|
35
|
+
check(): Promise<CheckResult>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Redis client interface (minimal).
|
|
40
|
+
*/
|
|
41
|
+
interface RedisClient {
|
|
42
|
+
ping(): Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for Redis health check.
|
|
46
|
+
*/
|
|
47
|
+
interface RedisCheckOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Custom name for this check.
|
|
50
|
+
* @default 'redis'
|
|
51
|
+
*/
|
|
52
|
+
name?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Health check for Redis connectivity.
|
|
56
|
+
*/
|
|
57
|
+
declare class RedisCheck extends HealthCheck {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
private redis;
|
|
60
|
+
constructor(redis: RedisClient, options?: RedisCheckOptions);
|
|
61
|
+
check(): Promise<CheckResult>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Cache store interface (minimal).
|
|
66
|
+
*/
|
|
67
|
+
interface CacheStoreInterface {
|
|
68
|
+
get<T>(key: string): Promise<T | null>;
|
|
69
|
+
put<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
70
|
+
forget(key: string): Promise<boolean>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Options for cache health check.
|
|
74
|
+
*/
|
|
75
|
+
interface CacheCheckOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Custom name for this check.
|
|
78
|
+
* @default 'cache'
|
|
79
|
+
*/
|
|
80
|
+
name?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Key to use for health check test.
|
|
83
|
+
* @default '__health_check__'
|
|
84
|
+
*/
|
|
85
|
+
testKey?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Health check for cache functionality.
|
|
89
|
+
*/
|
|
90
|
+
declare class CacheCheck extends HealthCheck {
|
|
91
|
+
readonly name: string;
|
|
92
|
+
private cache;
|
|
93
|
+
private testKey;
|
|
94
|
+
constructor(cache: CacheStoreInterface, options?: CacheCheckOptions);
|
|
95
|
+
check(): Promise<CheckResult>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Storage driver interface (minimal).
|
|
100
|
+
*/
|
|
101
|
+
interface StorageDriverInterface {
|
|
102
|
+
put(path: string, contents: string | Buffer): Promise<void>;
|
|
103
|
+
get(path: string): Promise<Buffer | null>;
|
|
104
|
+
delete(path: string): Promise<boolean>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Options for storage health check.
|
|
108
|
+
*/
|
|
109
|
+
interface StorageCheckOptions {
|
|
110
|
+
/**
|
|
111
|
+
* Custom name for this check.
|
|
112
|
+
* @default 'storage'
|
|
113
|
+
*/
|
|
114
|
+
name?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Test file path.
|
|
117
|
+
* @default '__health_check__.txt'
|
|
118
|
+
*/
|
|
119
|
+
testPath?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Health check for storage functionality.
|
|
123
|
+
*/
|
|
124
|
+
declare class StorageCheck extends HealthCheck {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
private storage;
|
|
127
|
+
private testPath;
|
|
128
|
+
constructor(storage: StorageDriverInterface, options?: StorageCheckOptions);
|
|
129
|
+
check(): Promise<CheckResult>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Options for memory health check.
|
|
134
|
+
*/
|
|
135
|
+
interface MemoryCheckOptions {
|
|
136
|
+
/**
|
|
137
|
+
* Custom name for this check.
|
|
138
|
+
* @default 'memory'
|
|
139
|
+
*/
|
|
140
|
+
name?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Memory threshold in MB. Above this is degraded.
|
|
143
|
+
* @default 512
|
|
144
|
+
*/
|
|
145
|
+
thresholdMb?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Critical memory threshold in MB. Above this is unhealthy.
|
|
148
|
+
* @default 1024
|
|
149
|
+
*/
|
|
150
|
+
criticalThresholdMb?: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Health check for memory usage.
|
|
154
|
+
*/
|
|
155
|
+
declare class MemoryCheck extends HealthCheck {
|
|
156
|
+
readonly name: string;
|
|
157
|
+
private thresholdMb;
|
|
158
|
+
private criticalThresholdMb;
|
|
159
|
+
constructor(options?: MemoryCheckOptions);
|
|
160
|
+
check(): Promise<CheckResult>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Callback for custom health check.
|
|
165
|
+
*/
|
|
166
|
+
type CustomCheckCallback = () => Promise<{
|
|
167
|
+
status: HealthStatus;
|
|
168
|
+
message?: string;
|
|
169
|
+
meta?: Record<string, unknown>;
|
|
170
|
+
}>;
|
|
171
|
+
/**
|
|
172
|
+
* Custom health check with callback.
|
|
173
|
+
*/
|
|
174
|
+
declare class CustomCheck extends HealthCheck {
|
|
175
|
+
readonly name: string;
|
|
176
|
+
private callback;
|
|
177
|
+
constructor(name: string, callback: CustomCheckCallback);
|
|
178
|
+
check(): Promise<CheckResult>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a custom health check.
|
|
182
|
+
*/
|
|
183
|
+
declare function customCheck(name: string, callback: CustomCheckCallback): CustomCheck;
|
|
184
|
+
|
|
185
|
+
export { CacheCheck, type CacheCheckOptions, type CacheStoreInterface, CheckResult, CustomCheck, type CustomCheckCallback, DatabaseCheck, type DatabaseCheckOptions, type DatabaseConnection, HealthCheck, HealthStatus, MemoryCheck, type MemoryCheckOptions, RedisCheck, type RedisCheckOptions, type RedisClient, StorageCheck, type StorageCheckOptions, type StorageDriverInterface, customCheck };
|