@guren/server 2.1.0 → 2.2.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.
- package/dist/{McpServiceProvider-7BB5FPF3.js → McpServiceProvider-GRDYNEQG.js} +1 -1
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +3 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-HONCNQXZ.js → chunk-BUQXOZCT.js} +97 -10
- package/dist/{chunk-DSDX3ASM.js → chunk-CDZUNKI6.js} +65 -83
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-EARA7JM4.js → chunk-PZKUDFMW.js} +11 -8
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +19 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +187 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +51 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +22 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +38 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +332 -152
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +144 -0
- package/dist/mcp/endpoint.d.ts +29 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +5 -2
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +1 -1
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +3 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-D60YF2ZO.d.ts +0 -329
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ServiceProvider } from '../container/ServiceProvider.js';
|
|
2
|
+
import { type TranslationMessages } from '../i18n/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the `_i18n` Inertia shared prop injected when `createApp({ i18n })`
|
|
5
|
+
* is configured (unless `i18n.share` is `false`). The client-side
|
|
6
|
+
* `useTranslation()` hook consumes this.
|
|
7
|
+
*/
|
|
8
|
+
export interface InertiaI18nProps {
|
|
9
|
+
locale: string;
|
|
10
|
+
fallbackLocale: string;
|
|
11
|
+
messages: Record<string, TranslationMessages>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Binds the I18nManager as a singleton in the container.
|
|
15
|
+
*
|
|
16
|
+
* When the app is created with `createApp({ i18n })`, this provider also
|
|
17
|
+
* mounts locale detection middleware (unless `i18n.detect` is `false`),
|
|
18
|
+
* preloads every supported locale during boot, and shares the request locale
|
|
19
|
+
* and its messages with Inertia pages as the `_i18n` prop (unless
|
|
20
|
+
* `i18n.share` is `false`).
|
|
21
|
+
*/
|
|
22
|
+
export declare class I18nServiceProvider extends ServiceProvider {
|
|
23
|
+
register(): void;
|
|
24
|
+
boot(): Promise<void>;
|
|
25
|
+
/** The provider works standalone on a bare container (no `app` binding). */
|
|
26
|
+
private application;
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ServiceProvider } from '../container/ServiceProvider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Registers the Inertia view engine and wires up validation error handling
|
|
4
|
+
* for Inertia requests (Laravel-style automatic redirect with flashed errors).
|
|
5
|
+
*/
|
|
6
|
+
export declare class InertiaServiceProvider extends ServiceProvider {
|
|
7
|
+
register(): void;
|
|
8
|
+
boot(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Register a custom renderer for ValidationException on Inertia requests.
|
|
11
|
+
* Non-Inertia requests fall through to the default JSON 422 response.
|
|
12
|
+
*/
|
|
13
|
+
private registerValidationRenderer;
|
|
14
|
+
/**
|
|
15
|
+
* Auto-inject flashed `errors` into shared props. Scoped to this app's
|
|
16
|
+
* container so a second Application booted in the same process keeps its
|
|
17
|
+
* own registrations.
|
|
18
|
+
*/
|
|
19
|
+
private registerSharedErrors;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { InertiaServiceProvider } from './InertiaServiceProvider.js';
|
|
2
|
+
export { AuthServiceProvider } from './AuthServiceProvider.js';
|
|
3
|
+
export { OAuthServiceProvider } from './OAuthServiceProvider.js';
|
|
4
|
+
export { EventServiceProvider } from './EventServiceProvider.js';
|
|
5
|
+
export { CacheServiceProvider } from './CacheServiceProvider.js';
|
|
6
|
+
export { QueueServiceProvider } from './QueueServiceProvider.js';
|
|
7
|
+
export { MailServiceProvider } from './MailServiceProvider.js';
|
|
8
|
+
export { LogServiceProvider } from './LogServiceProvider.js';
|
|
9
|
+
export { I18nServiceProvider } from './I18nServiceProvider.js';
|
|
10
|
+
export { NotificationServiceProvider } from './NotificationServiceProvider.js';
|
|
11
|
+
export { BroadcastServiceProvider } from './BroadcastServiceProvider.js';
|
|
12
|
+
export { EncryptionServiceProvider } from './EncryptionServiceProvider.js';
|
|
13
|
+
export { StorageServiceProvider } from './StorageServiceProvider.js';
|
|
14
|
+
export { HealthServiceProvider } from './HealthServiceProvider.js';
|
|
15
|
+
export { SchedulingServiceProvider } from './SchedulingServiceProvider.js';
|
|
16
|
+
export { AuthorizationServiceProvider } from './AuthorizationServiceProvider.js';
|
|
17
|
+
export { ErrorServiceProvider } from './ErrorServiceProvider.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Information about a failed queue job.
|
|
3
|
+
*/
|
|
4
|
+
export interface FailedJobInfo {
|
|
5
|
+
jobName: string;
|
|
6
|
+
queue: string;
|
|
7
|
+
attempt: number;
|
|
8
|
+
maxAttempts: number;
|
|
9
|
+
willRetry: boolean;
|
|
10
|
+
error: Error;
|
|
11
|
+
failedAt: Date;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Handler function invoked when a job fails.
|
|
15
|
+
*/
|
|
16
|
+
export type FailedJobHandler = (info: FailedJobInfo) => void | Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Configurable reporter for failed queue jobs.
|
|
19
|
+
*
|
|
20
|
+
* Registered by default in QueueServiceProvider to log failures.
|
|
21
|
+
* Can be extended with custom handlers (e.g., Sentry, Slack notifications).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const reporter = new FailedJobReporter()
|
|
26
|
+
*
|
|
27
|
+
* // Add a custom handler alongside the default logger
|
|
28
|
+
* reporter.onFailure(async (info) => {
|
|
29
|
+
* await sendToSentry(info.error)
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class FailedJobReporter {
|
|
34
|
+
private handlers;
|
|
35
|
+
constructor();
|
|
36
|
+
/** Add a custom handler for failed jobs. */
|
|
37
|
+
onFailure(handler: FailedJobHandler): this;
|
|
38
|
+
/** Report a job failure to all registered handlers. */
|
|
39
|
+
report(info: FailedJobInfo): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { QueueDriver, JobOptions } from './types.js';
|
|
2
|
+
import type { ServiceBindings } from '../container/bindings.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set the global queue driver.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setQueueDriver(driver: QueueDriver): void;
|
|
7
|
+
/**
|
|
8
|
+
* Get the global queue driver.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getQueueDriver(): QueueDriver | null;
|
|
11
|
+
/**
|
|
12
|
+
* Base class for defining jobs.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* class SendWelcomeEmailJob extends Job<{ userId: string }> {
|
|
17
|
+
* static queue = 'emails'
|
|
18
|
+
* static maxAttempts = 5
|
|
19
|
+
*
|
|
20
|
+
* async handle({ userId }: { userId: string }): Promise<void> {
|
|
21
|
+
* const user = await User.find(userId)
|
|
22
|
+
* await mail.to(user.email).template(WelcomeEmail, user).send()
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* async failed({ userId }: { userId: string }, error: Error): Promise<void> {
|
|
26
|
+
* console.error(`Failed to send welcome email to user ${userId}:`, error)
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // Dispatch the job
|
|
31
|
+
* await SendWelcomeEmailJob.dispatch({ userId: '123' })
|
|
32
|
+
*
|
|
33
|
+
* // Dispatch with delay
|
|
34
|
+
* await SendWelcomeEmailJob.dispatchAfter(60000, { userId: '123' })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class Job<T = unknown> {
|
|
38
|
+
/**
|
|
39
|
+
* Stable wire name for this job.
|
|
40
|
+
*
|
|
41
|
+
* Queued messages record this name, and the worker resolves the class back
|
|
42
|
+
* from it. When omitted the class name is used, which breaks if a bundler
|
|
43
|
+
* mangles identifiers or if the class is later renamed while messages are
|
|
44
|
+
* still in flight. Set it to pin the name across both.
|
|
45
|
+
*
|
|
46
|
+
* @default the class name
|
|
47
|
+
*/
|
|
48
|
+
static jobName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The queue this job should be dispatched to.
|
|
51
|
+
* @default 'default'
|
|
52
|
+
*/
|
|
53
|
+
static queue: string;
|
|
54
|
+
/**
|
|
55
|
+
* Maximum number of times the job should be attempted.
|
|
56
|
+
* @default 3
|
|
57
|
+
*/
|
|
58
|
+
static maxAttempts: number;
|
|
59
|
+
/**
|
|
60
|
+
* Backoff strategy for retries.
|
|
61
|
+
* - 'exponential': 2^attempt * 1000ms (1s, 2s, 4s, 8s, ...)
|
|
62
|
+
* - 'linear': attempt * 1000ms (1s, 2s, 3s, 4s, ...)
|
|
63
|
+
* - number: fixed delay in milliseconds
|
|
64
|
+
* @default 'exponential'
|
|
65
|
+
*/
|
|
66
|
+
static backoff: 'exponential' | 'linear' | number;
|
|
67
|
+
protected make<K extends keyof ServiceBindings>(key: K): ServiceBindings[K];
|
|
68
|
+
protected make<TService>(key: string): TService;
|
|
69
|
+
/**
|
|
70
|
+
* Handle the job.
|
|
71
|
+
* Override this method to define job logic.
|
|
72
|
+
*/
|
|
73
|
+
abstract handle(payload: T): void | Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Called when the job fails permanently (after all retries exhausted).
|
|
76
|
+
* Override this method to handle failures.
|
|
77
|
+
*/
|
|
78
|
+
failed?(payload: T, error: Error): void | Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Dispatch the job to the queue.
|
|
81
|
+
*
|
|
82
|
+
* @param payload - Job payload data
|
|
83
|
+
* @param options - Optional dispatch options
|
|
84
|
+
*/
|
|
85
|
+
static dispatch<T>(this: JobClass<T>, payload: T, options?: JobOptions): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Dispatch the job after a delay.
|
|
88
|
+
*
|
|
89
|
+
* @param delayMs - Delay in milliseconds
|
|
90
|
+
* @param payload - Job payload data
|
|
91
|
+
* @param options - Optional dispatch options (delay is overridden)
|
|
92
|
+
*/
|
|
93
|
+
static dispatchAfter<T>(this: JobClass<T>, delayMs: number, payload: T, options?: Omit<JobOptions, 'delay'>): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Calculate the retry delay based on backoff strategy.
|
|
96
|
+
*/
|
|
97
|
+
static calculateRetryDelay(attempts: number): number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Job class constructor type.
|
|
101
|
+
*/
|
|
102
|
+
export interface JobClass<T = unknown> {
|
|
103
|
+
new (): Job<T>;
|
|
104
|
+
name: string;
|
|
105
|
+
jobName?: string;
|
|
106
|
+
queue: string;
|
|
107
|
+
maxAttempts: number;
|
|
108
|
+
backoff: 'exponential' | 'linear' | number;
|
|
109
|
+
dispatch(payload: T, options?: JobOptions): Promise<string>;
|
|
110
|
+
dispatchAfter(delayMs: number, payload: T, options?: Omit<JobOptions, 'delay'>): Promise<string>;
|
|
111
|
+
calculateRetryDelay(attempts: number): number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Resolve the wire name a job is queued and looked up under.
|
|
115
|
+
*
|
|
116
|
+
* Prefers an explicit `jobName` over the class name so that renaming the class
|
|
117
|
+
* or bundling with identifier mangling does not orphan queued messages.
|
|
118
|
+
*
|
|
119
|
+
* Only an *own* `jobName` counts. Static members are inherited, so reading it
|
|
120
|
+
* off the prototype chain would make every subclass of a pinned job claim its
|
|
121
|
+
* parent's identity and overwrite it in the registry. A subclass that wants a
|
|
122
|
+
* pinned name declares its own.
|
|
123
|
+
*/
|
|
124
|
+
export declare function resolveJobName(jobClass: Pick<JobClass, 'name' | 'jobName'>): string;
|
|
125
|
+
/**
|
|
126
|
+
* Register a job class for the worker to use.
|
|
127
|
+
*/
|
|
128
|
+
export declare function registerJob<T>(jobClass: JobClass<T>): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get a registered job class by name.
|
|
131
|
+
*/
|
|
132
|
+
export declare function getJob(name: string): JobClass | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Get all registered job classes.
|
|
135
|
+
*/
|
|
136
|
+
export declare function getRegisteredJobs(): Map<string, JobClass>;
|
|
137
|
+
/**
|
|
138
|
+
* Clear all registered jobs (for testing).
|
|
139
|
+
*/
|
|
140
|
+
export declare function clearJobRegistry(): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { QueueDriver } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Queue driver factory function.
|
|
4
|
+
*/
|
|
5
|
+
export type QueueDriverFactory = () => QueueDriver;
|
|
6
|
+
/**
|
|
7
|
+
* Queue configuration.
|
|
8
|
+
*/
|
|
9
|
+
export interface QueueConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Default driver name.
|
|
12
|
+
* @default 'memory'
|
|
13
|
+
*/
|
|
14
|
+
default?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Driver configurations.
|
|
17
|
+
*/
|
|
18
|
+
drivers?: Record<string, QueueDriverFactory>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Queue manager for handling multiple queue drivers.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { QueueManager, MemoryDriver, RedisDriver } from '@guren/server/queue'
|
|
26
|
+
* import { createRedisClient } from '@guren/server/redis'
|
|
27
|
+
*
|
|
28
|
+
* const redis = createRedisClient({ url: process.env.REDIS_URL })
|
|
29
|
+
*
|
|
30
|
+
* const queueManager = new QueueManager({
|
|
31
|
+
* default: 'redis',
|
|
32
|
+
* drivers: {
|
|
33
|
+
* memory: () => new MemoryDriver(),
|
|
34
|
+
* redis: () => new RedisDriver(redis),
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* // Use the default driver
|
|
39
|
+
* const driver = queueManager.driver()
|
|
40
|
+
*
|
|
41
|
+
* // Use a specific driver
|
|
42
|
+
* const memoryDriver = queueManager.driver('memory')
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class QueueManager {
|
|
46
|
+
private readonly defaultDriver;
|
|
47
|
+
private readonly driverFactories;
|
|
48
|
+
private readonly resolvedDrivers;
|
|
49
|
+
constructor(config?: QueueConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Get a queue driver by name.
|
|
52
|
+
* Returns the default driver if no name is specified.
|
|
53
|
+
*/
|
|
54
|
+
driver(name?: string): QueueDriver;
|
|
55
|
+
/**
|
|
56
|
+
* Register a custom driver factory.
|
|
57
|
+
*/
|
|
58
|
+
registerDriver(name: string, factory: QueueDriverFactory): void;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a driver is registered.
|
|
61
|
+
*/
|
|
62
|
+
hasDriver(name: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Get the default driver name.
|
|
65
|
+
*/
|
|
66
|
+
getDefaultDriverName(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Get all registered driver names.
|
|
69
|
+
*/
|
|
70
|
+
getDriverNames(): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Set the default driver and update global driver.
|
|
73
|
+
*/
|
|
74
|
+
setDefaultDriver(name: string): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a queue manager with default configuration.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createQueueManager(config?: QueueConfig): QueueManager;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { QueueDriver, QueuedJob, WorkerOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Worker events.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkerEvents {
|
|
6
|
+
/**
|
|
7
|
+
* Emitted when a job is processed successfully.
|
|
8
|
+
*/
|
|
9
|
+
jobProcessed?: (job: QueuedJob) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Emitted when a job fails (but may retry).
|
|
12
|
+
*/
|
|
13
|
+
jobFailed?: (job: QueuedJob, error: Error, willRetry: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Emitted when the worker starts.
|
|
16
|
+
*/
|
|
17
|
+
workerStarted?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Emitted when the worker stops.
|
|
20
|
+
*/
|
|
21
|
+
workerStopped?: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Queue worker that processes jobs.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Worker, MemoryDriver, setQueueDriver } from '@guren/server/queue'
|
|
29
|
+
*
|
|
30
|
+
* const driver = new MemoryDriver()
|
|
31
|
+
* setQueueDriver(driver)
|
|
32
|
+
*
|
|
33
|
+
* const worker = new Worker(driver, {
|
|
34
|
+
* queues: ['default', 'emails'],
|
|
35
|
+
* sleep: 1000,
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* // Start processing
|
|
39
|
+
* await worker.start()
|
|
40
|
+
*
|
|
41
|
+
* // Stop gracefully
|
|
42
|
+
* await worker.stop()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class Worker {
|
|
46
|
+
private readonly driver;
|
|
47
|
+
private readonly options;
|
|
48
|
+
private readonly events;
|
|
49
|
+
private running;
|
|
50
|
+
private shouldStop;
|
|
51
|
+
private processedJobs;
|
|
52
|
+
private readonly queues;
|
|
53
|
+
private readonly sleep;
|
|
54
|
+
private readonly maxJobs;
|
|
55
|
+
private readonly timeout;
|
|
56
|
+
private readonly stopWhenEmpty;
|
|
57
|
+
private currentJob;
|
|
58
|
+
constructor(driver: QueueDriver, options?: WorkerOptions, events?: WorkerEvents);
|
|
59
|
+
/**
|
|
60
|
+
* Start the worker.
|
|
61
|
+
*/
|
|
62
|
+
start(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Stop the worker gracefully.
|
|
65
|
+
*/
|
|
66
|
+
stop(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if the worker is running.
|
|
69
|
+
*/
|
|
70
|
+
isRunning(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Get the number of processed jobs.
|
|
73
|
+
*/
|
|
74
|
+
getProcessedJobsCount(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Get the next available job from the queues.
|
|
77
|
+
*/
|
|
78
|
+
private getNextJob;
|
|
79
|
+
/**
|
|
80
|
+
* Process a single job.
|
|
81
|
+
*/
|
|
82
|
+
private processJob;
|
|
83
|
+
/**
|
|
84
|
+
* Handle a failed job.
|
|
85
|
+
*/
|
|
86
|
+
private handleFailedJob;
|
|
87
|
+
/**
|
|
88
|
+
* Execute a function with a timeout.
|
|
89
|
+
*/
|
|
90
|
+
private executeWithTimeout;
|
|
91
|
+
/**
|
|
92
|
+
* Sleep for a given number of milliseconds.
|
|
93
|
+
*/
|
|
94
|
+
private sleepMs;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Process a single job (for testing or one-off execution).
|
|
98
|
+
*/
|
|
99
|
+
export declare function processJob(driver: QueueDriver, queue?: string): Promise<boolean>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { QueueDriver, QueuedJob, FailedJob } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory queue driver for development and testing.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { MemoryDriver, setQueueDriver } from '@guren/server/queue'
|
|
8
|
+
*
|
|
9
|
+
* const driver = new MemoryDriver()
|
|
10
|
+
* setQueueDriver(driver)
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class MemoryDriver implements QueueDriver {
|
|
14
|
+
private jobs;
|
|
15
|
+
private failedJobs;
|
|
16
|
+
/**
|
|
17
|
+
* Push a job onto the queue.
|
|
18
|
+
*/
|
|
19
|
+
push(job: QueuedJob): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Pop the next available job from the queue.
|
|
22
|
+
*/
|
|
23
|
+
pop(queue: string): Promise<QueuedJob | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Release a job back onto the queue.
|
|
26
|
+
*/
|
|
27
|
+
release(job: QueuedJob, delayMs?: number): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Delete a job from the queue.
|
|
30
|
+
*/
|
|
31
|
+
delete(jobId: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Mark a job as failed.
|
|
34
|
+
*/
|
|
35
|
+
fail(job: QueuedJob, error: Error): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the number of jobs in a queue.
|
|
38
|
+
*/
|
|
39
|
+
size(queue: string): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Get failed jobs.
|
|
42
|
+
*/
|
|
43
|
+
getFailedJobs(queue?: string): Promise<FailedJob[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Retry a failed job.
|
|
46
|
+
*/
|
|
47
|
+
retryFailedJob(jobId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete a failed job.
|
|
50
|
+
*/
|
|
51
|
+
deleteFailedJob(jobId: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Clear all jobs (for testing).
|
|
54
|
+
*/
|
|
55
|
+
clear(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Get all pending jobs (for testing/debugging).
|
|
58
|
+
*/
|
|
59
|
+
getPendingJobs(queue?: string): QueuedJob[];
|
|
60
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { QueueDriver, QueuedJob, FailedJob } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for RedisDriver.
|
|
5
|
+
*/
|
|
6
|
+
export interface RedisDriverOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Key prefix for queue keys.
|
|
9
|
+
* @default 'queue:'
|
|
10
|
+
*/
|
|
11
|
+
prefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Visibility timeout in milliseconds.
|
|
14
|
+
* Jobs reserved longer than this will be released.
|
|
15
|
+
* @default 60000
|
|
16
|
+
*/
|
|
17
|
+
visibilityTimeout?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Redis-backed queue driver for production.
|
|
21
|
+
*
|
|
22
|
+
* Uses the following Redis structures:
|
|
23
|
+
* - `{prefix}{queue}:pending` - Sorted Set (score = availableAt timestamp)
|
|
24
|
+
* - `{prefix}{queue}:reserved` - Sorted Set (score = timeout timestamp)
|
|
25
|
+
* - `{prefix}{queue}:failed` - List of failed job IDs
|
|
26
|
+
* - `{prefix}job:{id}` - Hash containing job data
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createRedisClient } from '@guren/server/redis'
|
|
31
|
+
* import { RedisDriver, setQueueDriver } from '@guren/server/queue'
|
|
32
|
+
*
|
|
33
|
+
* const redis = createRedisClient({ url: process.env.REDIS_URL })
|
|
34
|
+
* const driver = new RedisDriver(redis)
|
|
35
|
+
* setQueueDriver(driver)
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class RedisDriver implements QueueDriver {
|
|
39
|
+
private readonly redis;
|
|
40
|
+
private readonly prefix;
|
|
41
|
+
private readonly visibilityTimeout;
|
|
42
|
+
constructor(redis: Redis, options?: RedisDriverOptions);
|
|
43
|
+
private pendingKey;
|
|
44
|
+
private reservedKey;
|
|
45
|
+
private failedKey;
|
|
46
|
+
private jobKey;
|
|
47
|
+
/**
|
|
48
|
+
* Push a job onto the queue.
|
|
49
|
+
*/
|
|
50
|
+
push(job: QueuedJob): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Pop the next available job from the queue.
|
|
53
|
+
*/
|
|
54
|
+
pop(queue: string): Promise<QueuedJob | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Release jobs that have exceeded visibility timeout.
|
|
57
|
+
*/
|
|
58
|
+
private releaseTimedOutJobs;
|
|
59
|
+
/**
|
|
60
|
+
* Release a job back onto the queue.
|
|
61
|
+
*/
|
|
62
|
+
release(job: QueuedJob, delayMs?: number): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete a job from the queue.
|
|
65
|
+
*/
|
|
66
|
+
delete(jobId: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Mark a job as failed.
|
|
69
|
+
*/
|
|
70
|
+
fail(job: QueuedJob, error: Error): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the number of jobs in a queue.
|
|
73
|
+
*/
|
|
74
|
+
size(queue: string): Promise<number>;
|
|
75
|
+
/**
|
|
76
|
+
* Get failed jobs.
|
|
77
|
+
*/
|
|
78
|
+
getFailedJobs(queue?: string): Promise<FailedJob[]>;
|
|
79
|
+
private getFailedJobsForQueue;
|
|
80
|
+
/**
|
|
81
|
+
* Retry a failed job.
|
|
82
|
+
*/
|
|
83
|
+
retryFailedJob(jobId: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Delete a failed job.
|
|
86
|
+
*/
|
|
87
|
+
deleteFailedJob(jobId: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Clear all jobs (for testing).
|
|
90
|
+
*/
|
|
91
|
+
clear(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Parse job data from Redis hash.
|
|
94
|
+
*/
|
|
95
|
+
private parseJobData;
|
|
96
|
+
}
|