@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.
Files changed (54) hide show
  1. package/dist/Application-DtWDHXr1.d.ts +2110 -0
  2. package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
  3. package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
  4. package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
  5. package/dist/EventManager-CmIoLt7r.d.ts +207 -0
  6. package/dist/Gate-CNkBYf8m.d.ts +268 -0
  7. package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
  8. package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
  9. package/dist/LogManager-7mxnkaPM.d.ts +256 -0
  10. package/dist/MailManager-DpMvYiP9.d.ts +292 -0
  11. package/dist/Scheduler-BstvSca7.d.ts +469 -0
  12. package/dist/StorageManager-oZTHqaza.d.ts +337 -0
  13. package/dist/api-token-JOif2CtG.d.ts +1792 -0
  14. package/dist/app-key-CsBfRC_Q.d.ts +214 -0
  15. package/dist/auth/index.d.ts +418 -0
  16. package/dist/auth/index.js +6742 -0
  17. package/dist/authorization/index.d.ts +129 -0
  18. package/dist/authorization/index.js +621 -0
  19. package/dist/broadcasting/index.d.ts +233 -0
  20. package/dist/broadcasting/index.js +907 -0
  21. package/dist/cache/index.d.ts +233 -0
  22. package/dist/cache/index.js +817 -0
  23. package/dist/encryption/index.d.ts +222 -0
  24. package/dist/encryption/index.js +602 -0
  25. package/dist/events/index.d.ts +155 -0
  26. package/dist/events/index.js +330 -0
  27. package/dist/health/index.d.ts +185 -0
  28. package/dist/health/index.js +379 -0
  29. package/dist/i18n/index.d.ts +101 -0
  30. package/dist/i18n/index.js +597 -0
  31. package/dist/index-9_Jzj5jo.d.ts +7 -0
  32. package/dist/index.d.ts +2628 -619
  33. package/dist/index.js +22229 -3116
  34. package/dist/lambda/index.d.ts +156 -0
  35. package/dist/lambda/index.js +91 -0
  36. package/dist/logging/index.d.ts +50 -0
  37. package/dist/logging/index.js +557 -0
  38. package/dist/mail/index.d.ts +288 -0
  39. package/dist/mail/index.js +695 -0
  40. package/dist/mcp/index.d.ts +139 -0
  41. package/dist/mcp/index.js +382 -0
  42. package/dist/notifications/index.d.ts +271 -0
  43. package/dist/notifications/index.js +741 -0
  44. package/dist/queue/index.d.ts +423 -0
  45. package/dist/queue/index.js +958 -0
  46. package/dist/runtime/index.d.ts +93 -0
  47. package/dist/runtime/index.js +834 -0
  48. package/dist/scheduling/index.d.ts +41 -0
  49. package/dist/scheduling/index.js +836 -0
  50. package/dist/storage/index.d.ts +196 -0
  51. package/dist/storage/index.js +832 -0
  52. package/dist/vite/index.js +203 -3
  53. package/package.json +93 -6
  54. package/dist/chunk-FK2XQSBF.js +0 -160
@@ -0,0 +1,423 @@
1
+ import { a5 as QueueDriver, a7 as QueuedJob, F as FailedJob, aw as WorkerOptions } from '../Application-DtWDHXr1.js';
2
+ export { R as Job, T as JobClass, U as JobFailureHandler, V as JobHandler, W as JobOptions, a4 as QueueConfig, a6 as QueueDriverFactory, Q as QueueManager, aA as clearJobRegistry, aH as createQueueManager, aO as getJob, aQ as getQueueDriver, aR as getRegisteredJobs, aV as registerJob, a$ as setQueueDriver } from '../Application-DtWDHXr1.js';
3
+ import { Redis } from 'ioredis';
4
+ import 'hono';
5
+ import '../api-token-JOif2CtG.js';
6
+ import 'vite';
7
+ import '../EventManager-CmIoLt7r.js';
8
+ import '../CacheManager-BkvHEOZX.js';
9
+ import '../MailManager-DpMvYiP9.js';
10
+ import '../LogManager-7mxnkaPM.js';
11
+ import '../I18nManager-Dtgzsf5n.js';
12
+ import '../BroadcastManager-AkIWUGJo.js';
13
+ import '../index-9_Jzj5jo.js';
14
+ import '../app-key-CsBfRC_Q.js';
15
+ import '../StorageManager-oZTHqaza.js';
16
+ import '../HealthManager-DUyMIzsZ.js';
17
+ import '../Scheduler-BstvSca7.js';
18
+ import '../Gate-CNkBYf8m.js';
19
+
20
+ /**
21
+ * In-memory queue driver for development and testing.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { MemoryDriver, setQueueDriver } from '@guren/server/queue'
26
+ *
27
+ * const driver = new MemoryDriver()
28
+ * setQueueDriver(driver)
29
+ * ```
30
+ */
31
+ declare class MemoryDriver implements QueueDriver {
32
+ private jobs;
33
+ private failedJobs;
34
+ /**
35
+ * Push a job onto the queue.
36
+ */
37
+ push(job: QueuedJob): Promise<void>;
38
+ /**
39
+ * Pop the next available job from the queue.
40
+ */
41
+ pop(queue: string): Promise<QueuedJob | null>;
42
+ /**
43
+ * Release a job back onto the queue.
44
+ */
45
+ release(job: QueuedJob, delayMs?: number): Promise<void>;
46
+ /**
47
+ * Delete a job from the queue.
48
+ */
49
+ delete(jobId: string): Promise<void>;
50
+ /**
51
+ * Mark a job as failed.
52
+ */
53
+ fail(job: QueuedJob, error: Error): Promise<void>;
54
+ /**
55
+ * Get the number of jobs in a queue.
56
+ */
57
+ size(queue: string): Promise<number>;
58
+ /**
59
+ * Get failed jobs.
60
+ */
61
+ getFailedJobs(queue?: string): Promise<FailedJob[]>;
62
+ /**
63
+ * Retry a failed job.
64
+ */
65
+ retryFailedJob(jobId: string): Promise<void>;
66
+ /**
67
+ * Delete a failed job.
68
+ */
69
+ deleteFailedJob(jobId: string): Promise<void>;
70
+ /**
71
+ * Clear all jobs (for testing).
72
+ */
73
+ clear(): Promise<void>;
74
+ /**
75
+ * Get all pending jobs (for testing/debugging).
76
+ */
77
+ getPendingJobs(queue?: string): QueuedJob[];
78
+ }
79
+
80
+ /**
81
+ * Options for RedisDriver.
82
+ */
83
+ interface RedisDriverOptions {
84
+ /**
85
+ * Key prefix for queue keys.
86
+ * @default 'queue:'
87
+ */
88
+ prefix?: string;
89
+ /**
90
+ * Visibility timeout in milliseconds.
91
+ * Jobs reserved longer than this will be released.
92
+ * @default 60000
93
+ */
94
+ visibilityTimeout?: number;
95
+ }
96
+ /**
97
+ * Redis-backed queue driver for production.
98
+ *
99
+ * Uses the following Redis structures:
100
+ * - `{prefix}{queue}:pending` - Sorted Set (score = availableAt timestamp)
101
+ * - `{prefix}{queue}:reserved` - Sorted Set (score = timeout timestamp)
102
+ * - `{prefix}{queue}:failed` - List of failed job IDs
103
+ * - `{prefix}job:{id}` - Hash containing job data
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { createRedisClient } from '@guren/server/redis'
108
+ * import { RedisDriver, setQueueDriver } from '@guren/server/queue'
109
+ *
110
+ * const redis = createRedisClient({ url: process.env.REDIS_URL })
111
+ * const driver = new RedisDriver(redis)
112
+ * setQueueDriver(driver)
113
+ * ```
114
+ */
115
+ declare class RedisDriver implements QueueDriver {
116
+ private readonly redis;
117
+ private readonly prefix;
118
+ private readonly visibilityTimeout;
119
+ constructor(redis: Redis, options?: RedisDriverOptions);
120
+ private pendingKey;
121
+ private reservedKey;
122
+ private failedKey;
123
+ private jobKey;
124
+ /**
125
+ * Push a job onto the queue.
126
+ */
127
+ push(job: QueuedJob): Promise<void>;
128
+ /**
129
+ * Pop the next available job from the queue.
130
+ */
131
+ pop(queue: string): Promise<QueuedJob | null>;
132
+ /**
133
+ * Release jobs that have exceeded visibility timeout.
134
+ */
135
+ private releaseTimedOutJobs;
136
+ /**
137
+ * Release a job back onto the queue.
138
+ */
139
+ release(job: QueuedJob, delayMs?: number): Promise<void>;
140
+ /**
141
+ * Delete a job from the queue.
142
+ */
143
+ delete(jobId: string): Promise<void>;
144
+ /**
145
+ * Mark a job as failed.
146
+ */
147
+ fail(job: QueuedJob, error: Error): Promise<void>;
148
+ /**
149
+ * Get the number of jobs in a queue.
150
+ */
151
+ size(queue: string): Promise<number>;
152
+ /**
153
+ * Get failed jobs.
154
+ */
155
+ getFailedJobs(queue?: string): Promise<FailedJob[]>;
156
+ private getFailedJobsForQueue;
157
+ /**
158
+ * Retry a failed job.
159
+ */
160
+ retryFailedJob(jobId: string): Promise<void>;
161
+ /**
162
+ * Delete a failed job.
163
+ */
164
+ deleteFailedJob(jobId: string): Promise<void>;
165
+ /**
166
+ * Clear all jobs (for testing).
167
+ */
168
+ clear(): Promise<void>;
169
+ /**
170
+ * Parse job data from Redis hash.
171
+ */
172
+ private parseJobData;
173
+ }
174
+
175
+ /**
176
+ * Abstracted SQS operations.
177
+ * Users implement this interface by wrapping their SQS client (e.g. @aws-sdk/client-sqs).
178
+ * This avoids a hard dependency on @aws-sdk/client-sqs in the framework.
179
+ */
180
+ interface SqsAdapter {
181
+ /**
182
+ * Send a message to an SQS queue.
183
+ */
184
+ sendMessage(params: {
185
+ queueUrl: string;
186
+ messageBody: string;
187
+ delaySeconds: number;
188
+ messageGroupId?: string;
189
+ messageDeduplicationId?: string;
190
+ }): Promise<void>;
191
+ /**
192
+ * Receive a single message from an SQS queue.
193
+ */
194
+ receiveMessage(params: {
195
+ queueUrl: string;
196
+ waitTimeSeconds?: number;
197
+ }): Promise<{
198
+ body: string;
199
+ receiptHandle: string;
200
+ } | null>;
201
+ /**
202
+ * Change the visibility timeout of a message.
203
+ */
204
+ changeMessageVisibility(params: {
205
+ queueUrl: string;
206
+ receiptHandle: string;
207
+ visibilityTimeout: number;
208
+ }): Promise<void>;
209
+ /**
210
+ * Get the approximate number of messages in a queue.
211
+ */
212
+ getApproximateMessageCount(queueUrl: string): Promise<number>;
213
+ }
214
+ /**
215
+ * Options for SqsDriver.
216
+ */
217
+ interface SqsDriverOptions {
218
+ /**
219
+ * SQS queue URL for the primary queue.
220
+ */
221
+ queueUrl: string;
222
+ /**
223
+ * Optional mapping of logical queue names to SQS queue URLs.
224
+ * If not specified, all queues use the primary `queueUrl`.
225
+ */
226
+ queueUrls?: Record<string, string>;
227
+ /**
228
+ * Message group ID for FIFO queues. If set, enables FIFO mode.
229
+ */
230
+ messageGroupId?: string;
231
+ }
232
+ /**
233
+ * Create an SqsAdapter from an @aws-sdk/client-sqs SQSClient.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * import { SQSClient } from '@aws-sdk/client-sqs'
238
+ * import { createSqsAdapter, SqsDriver } from '@guren/server/queue'
239
+ *
240
+ * const client = new SQSClient({ region: 'ap-northeast-1' })
241
+ * const adapter = createSqsAdapter(client)
242
+ * const driver = new SqsDriver(adapter, { queueUrl: '...' })
243
+ * ```
244
+ */
245
+ declare function createSqsAdapter(client: {
246
+ send(command: unknown): Promise<unknown>;
247
+ }): SqsAdapter;
248
+ /**
249
+ * AWS SQS queue driver for serverless deployments.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { SQSClient } from '@aws-sdk/client-sqs'
254
+ * import { createSqsAdapter, SqsDriver, setQueueDriver } from '@guren/server/queue'
255
+ *
256
+ * const adapter = createSqsAdapter(new SQSClient({ region: 'ap-northeast-1' }))
257
+ * const driver = new SqsDriver(adapter, { queueUrl: process.env.SQS_QUEUE_URL! })
258
+ * setQueueDriver(driver)
259
+ *
260
+ * // Dispatch jobs as usual
261
+ * await SendEmailJob.dispatch({ to: 'user@example.com' })
262
+ * ```
263
+ */
264
+ declare class SqsDriver implements QueueDriver {
265
+ private readonly adapter;
266
+ private readonly options;
267
+ private readonly failedJobs;
268
+ private readonly receiptHandles;
269
+ constructor(adapter: SqsAdapter, options: SqsDriverOptions);
270
+ push(job: QueuedJob): Promise<void>;
271
+ pop(queue: string): Promise<QueuedJob | null>;
272
+ release(job: QueuedJob, delayMs?: number): Promise<void>;
273
+ delete(jobId: string): Promise<void>;
274
+ fail(job: QueuedJob, error: Error): Promise<void>;
275
+ size(queue: string): Promise<number>;
276
+ getFailedJobs(queue?: string): Promise<FailedJob[]>;
277
+ retryFailedJob(jobId: string): Promise<void>;
278
+ deleteFailedJob(jobId: string): Promise<void>;
279
+ clear(): Promise<void>;
280
+ private resolveQueueUrl;
281
+ }
282
+
283
+ /**
284
+ * Worker events.
285
+ */
286
+ interface WorkerEvents {
287
+ /**
288
+ * Emitted when a job is processed successfully.
289
+ */
290
+ jobProcessed?: (job: QueuedJob) => void;
291
+ /**
292
+ * Emitted when a job fails (but may retry).
293
+ */
294
+ jobFailed?: (job: QueuedJob, error: Error, willRetry: boolean) => void;
295
+ /**
296
+ * Emitted when the worker starts.
297
+ */
298
+ workerStarted?: () => void;
299
+ /**
300
+ * Emitted when the worker stops.
301
+ */
302
+ workerStopped?: () => void;
303
+ }
304
+ /**
305
+ * Queue worker that processes jobs.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * import { Worker, MemoryDriver, setQueueDriver } from '@guren/server/queue'
310
+ *
311
+ * const driver = new MemoryDriver()
312
+ * setQueueDriver(driver)
313
+ *
314
+ * const worker = new Worker(driver, {
315
+ * queues: ['default', 'emails'],
316
+ * sleep: 1000,
317
+ * })
318
+ *
319
+ * // Start processing
320
+ * await worker.start()
321
+ *
322
+ * // Stop gracefully
323
+ * await worker.stop()
324
+ * ```
325
+ */
326
+ declare class Worker {
327
+ private readonly driver;
328
+ private readonly options;
329
+ private readonly events;
330
+ private running;
331
+ private shouldStop;
332
+ private processedJobs;
333
+ private readonly queues;
334
+ private readonly sleep;
335
+ private readonly maxJobs;
336
+ private readonly timeout;
337
+ private readonly stopWhenEmpty;
338
+ private currentJob;
339
+ constructor(driver: QueueDriver, options?: WorkerOptions, events?: WorkerEvents);
340
+ /**
341
+ * Start the worker.
342
+ */
343
+ start(): Promise<void>;
344
+ /**
345
+ * Stop the worker gracefully.
346
+ */
347
+ stop(): Promise<void>;
348
+ /**
349
+ * Check if the worker is running.
350
+ */
351
+ isRunning(): boolean;
352
+ /**
353
+ * Get the number of processed jobs.
354
+ */
355
+ getProcessedJobsCount(): number;
356
+ /**
357
+ * Get the next available job from the queues.
358
+ */
359
+ private getNextJob;
360
+ /**
361
+ * Process a single job.
362
+ */
363
+ private processJob;
364
+ /**
365
+ * Handle a failed job.
366
+ */
367
+ private handleFailedJob;
368
+ /**
369
+ * Execute a function with a timeout.
370
+ */
371
+ private executeWithTimeout;
372
+ /**
373
+ * Sleep for a given number of milliseconds.
374
+ */
375
+ private sleepMs;
376
+ }
377
+ /**
378
+ * Process a single job (for testing or one-off execution).
379
+ */
380
+ declare function processJob(driver: QueueDriver, queue?: string): Promise<boolean>;
381
+
382
+ /**
383
+ * Information about a failed queue job.
384
+ */
385
+ interface FailedJobInfo {
386
+ jobName: string;
387
+ queue: string;
388
+ attempt: number;
389
+ maxAttempts: number;
390
+ willRetry: boolean;
391
+ error: Error;
392
+ failedAt: Date;
393
+ }
394
+ /**
395
+ * Handler function invoked when a job fails.
396
+ */
397
+ type FailedJobHandler = (info: FailedJobInfo) => void | Promise<void>;
398
+ /**
399
+ * Configurable reporter for failed queue jobs.
400
+ *
401
+ * Registered by default in QueueServiceProvider to log failures.
402
+ * Can be extended with custom handlers (e.g., Sentry, Slack notifications).
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * const reporter = new FailedJobReporter()
407
+ *
408
+ * // Add a custom handler alongside the default logger
409
+ * reporter.onFailure(async (info) => {
410
+ * await sendToSentry(info.error)
411
+ * })
412
+ * ```
413
+ */
414
+ declare class FailedJobReporter {
415
+ private handlers;
416
+ constructor();
417
+ /** Add a custom handler for failed jobs. */
418
+ onFailure(handler: FailedJobHandler): this;
419
+ /** Report a job failure to all registered handlers. */
420
+ report(info: FailedJobInfo): Promise<void>;
421
+ }
422
+
423
+ export { FailedJob, type FailedJobHandler, type FailedJobInfo, FailedJobReporter, MemoryDriver, QueueDriver, QueuedJob, RedisDriver, type RedisDriverOptions, type SqsAdapter, SqsDriver, type SqsDriverOptions, Worker, type WorkerEvents, WorkerOptions, createSqsAdapter, processJob };