@guren/server 2.14.0 → 2.16.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/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
- package/dist/{Hash-CzrwKeDp.js → Hash-D2DFd8xX.js} +12 -57
- package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
- package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
- package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
- package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
- package/dist/agent/AgentApprovalRequested.d.ts +31 -0
- package/dist/agent/approval.d.ts +184 -0
- package/dist/agent/audit-emitter.d.ts +36 -0
- package/dist/agent/audit.d.ts +67 -0
- package/dist/agent/derive.d.ts +32 -66
- package/dist/agent/dispatch.d.ts +53 -63
- package/dist/agent/events.d.ts +11 -19
- package/dist/agent/meta-tools.d.ts +34 -0
- package/dist/agent/public.d.ts +14 -0
- package/dist/agent/public.js +2 -0
- package/dist/agent/redact.d.ts +16 -38
- package/dist/agent/scopes.d.ts +23 -69
- package/dist/auth/AuthManager.d.ts +19 -40
- package/dist/auth/AuthenticatableModel.d.ts +2 -2
- package/dist/auth/SessionGuard.d.ts +0 -1
- package/dist/auth/TokenGuard.d.ts +6 -26
- package/dist/auth/api-token.d.ts +16 -148
- package/dist/auth/context.d.ts +5 -10
- package/dist/auth/email-verification.d.ts +29 -127
- package/dist/auth/index.js +1 -1
- package/dist/auth/oauth/index.d.ts +35 -57
- package/dist/auth/password/DefaultHasher.d.ts +9 -5
- package/dist/auth/password/PasswordHasher.d.ts +7 -0
- package/dist/auth/password/hash-format.d.ts +11 -0
- package/dist/auth/password-reset.d.ts +16 -42
- package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
- package/dist/auth/providers/UserProvider.d.ts +4 -4
- package/dist/auth/signed-token.d.ts +18 -0
- package/dist/auth/types.d.ts +9 -32
- package/dist/auth/utils.d.ts +6 -27
- package/dist/{auth-BSUc14CD.js → auth-CbdPH4Cd.js} +252 -496
- package/dist/authorization/Gate.d.ts +9 -145
- package/dist/authorization/Policy.d.ts +6 -53
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +16 -62
- package/dist/authorization/types.d.ts +8 -64
- package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
- package/dist/broadcasting/BroadcastManager.d.ts +29 -149
- package/dist/broadcasting/channels/Channel.d.ts +1 -19
- package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
- package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
- package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
- package/dist/broadcasting/drivers/index.d.ts +1 -1
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +7 -88
- package/dist/{broadcasting-BxU-LIfF.js → broadcasting-B5RzB0A2.js} +87 -414
- package/dist/cache/CacheManager.d.ts +8 -62
- package/dist/cache/TaggedCache.d.ts +2 -35
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +2 -36
- package/dist/cache/stores/MemoryStore.d.ts +2 -26
- package/dist/cache/stores/RedisStore.d.ts +1 -29
- package/dist/cache/types.d.ts +21 -128
- package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
- package/dist/client-C4TEr_Dd.js +9 -0
- package/dist/console/Command.d.ts +17 -126
- package/dist/console/ConsoleKernel.d.ts +2 -74
- package/dist/console/Input.d.ts +5 -113
- package/dist/console/Output.d.ts +3 -99
- package/dist/console/types.d.ts +3 -33
- package/dist/container/Container.d.ts +12 -103
- package/dist/container/ServiceProvider.d.ts +17 -61
- package/dist/container/bindings.d.ts +10 -12
- package/dist/container/defineModule.d.ts +16 -54
- package/dist/container/definePlugin.d.ts +12 -45
- package/dist/container/types.d.ts +2 -34
- package/dist/context-CXk_umpT.js +21 -0
- package/dist/database/Factory.d.ts +4 -57
- package/dist/database/Seeder.d.ts +8 -46
- package/dist/database/SeederRunner.d.ts +3 -33
- package/dist/database/types.d.ts +3 -24
- package/dist/discovery/AutoDiscovery.d.ts +10 -82
- package/dist/dispatch-BAwzftws.js +238 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
- package/dist/docs-viewer/endpoint.d.ts +5 -11
- package/dist/encryption/Encrypter.d.ts +5 -71
- package/dist/encryption/Hash.d.ts +7 -57
- package/dist/encryption/Random.d.ts +6 -99
- package/dist/encryption/index.js +3 -3
- package/dist/encryption/types.d.ts +10 -72
- package/dist/{encryption-DJtkkhiw.js → encryption-uwP3Di4D.js} +13 -79
- package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
- package/dist/endpoint-Dsw3Acvq.js +26 -0
- package/dist/errors/ExceptionHandler.d.ts +3 -90
- package/dist/errors/HttpException.d.ts +2 -79
- package/dist/errors/debug-page.d.ts +3 -17
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
- package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
- package/dist/errors/exceptions/ValidationException.d.ts +2 -43
- package/dist/errors/types.d.ts +1 -25
- package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
- package/dist/events/Event.d.ts +1 -28
- package/dist/events/EventManager.d.ts +5 -107
- package/dist/events/Listener.d.ts +7 -55
- package/dist/events/builtin.d.ts +0 -24
- package/dist/events/index.js +1 -1
- package/dist/events/types.d.ts +4 -22
- package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
- package/dist/facades/index.d.ts +2 -14
- package/dist/health/HealthCheck.d.ts +0 -24
- package/dist/health/HealthManager.d.ts +0 -36
- package/dist/health/checks/CacheCheck.d.ts +2 -17
- package/dist/health/checks/CustomCheck.d.ts +0 -9
- package/dist/health/checks/DatabaseCheck.d.ts +2 -17
- package/dist/health/checks/MemoryCheck.d.ts +3 -12
- package/dist/health/checks/RedisCheck.d.ts +1 -13
- package/dist/health/checks/StorageCheck.d.ts +2 -17
- package/dist/health/index.js +1 -1
- package/dist/health/types.d.ts +4 -24
- package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
- package/dist/hot-disposables-B5BXqaIH.js +167 -0
- package/dist/hot-reload/hot-disposables.d.ts +22 -74
- package/dist/hot-reload/testing.d.ts +4 -9
- package/dist/http/Application.d.ts +62 -208
- package/dist/http/FormRequest.d.ts +4 -55
- package/dist/http/dev-assets.d.ts +16 -18
- package/dist/http/dev-banner.d.ts +2 -5
- package/dist/http/inertia-assets.d.ts +3 -6
- package/dist/http/middleware/capabilities.d.ts +27 -50
- package/dist/http/middleware/cors.d.ts +4 -29
- package/dist/http/middleware/csp.d.ts +2 -25
- package/dist/http/middleware/csrf.d.ts +20 -95
- package/dist/http/middleware/detect-locale.d.ts +7 -27
- package/dist/http/middleware/force-https.d.ts +6 -24
- package/dist/http/middleware/host-authorization.d.ts +2 -12
- package/dist/http/middleware/loopback-guard.d.ts +15 -33
- package/dist/http/middleware/rate-limit.d.ts +29 -126
- package/dist/http/middleware/redirect-safety.d.ts +2 -20
- package/dist/http/middleware/request-id.d.ts +1 -14
- package/dist/http/middleware/request-logging.d.ts +2 -13
- package/dist/http/middleware/response-headers.d.ts +5 -13
- package/dist/http/middleware/security-headers.d.ts +2 -16
- package/dist/http/middleware/session.d.ts +15 -34
- package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
- package/dist/http/middleware/validation.d.ts +8 -63
- package/dist/http/public-assets.d.ts +14 -0
- package/dist/http/request.d.ts +49 -48
- package/dist/http/resources/CursorPaginator.d.ts +5 -64
- package/dist/http/resources/Paginator.d.ts +7 -84
- package/dist/http/resources/Resource.d.ts +9 -65
- package/dist/http/resources/ResourceCollection.d.ts +5 -39
- package/dist/http/resources/types.d.ts +10 -30
- package/dist/http/static-documents.d.ts +21 -0
- package/dist/http/validation/Validator.d.ts +25 -85
- package/dist/http/validation/rules.d.ts +48 -147
- package/dist/http/validation/types.d.ts +16 -61
- package/dist/http/vite-assets.d.ts +5 -28
- package/dist/http/vite-dev-server.d.ts +6 -9
- package/dist/http/vite-manifest.d.ts +19 -33
- package/dist/i18n/I18nManager.d.ts +12 -78
- package/dist/i18n/Translator.d.ts +3 -54
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
- package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
- package/dist/i18n/pluralization.d.ts +4 -13
- package/dist/i18n/types.d.ts +17 -69
- package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
- package/dist/index.d.ts +13 -4
- package/dist/index.js +1036 -3080
- package/dist/internal/agent-preflight.d.ts +9 -21
- package/dist/internal/request.d.ts +10 -17
- package/dist/internal/request.js +2 -2
- package/dist/internal/route-path.d.ts +9 -21
- package/dist/internal/route-path.js +9 -21
- package/dist/internal/zod-compat.d.ts +55 -122
- package/dist/internal/zod-compat.js +39 -70
- package/dist/internal/zod-json-schema.d.ts +18 -54
- package/dist/internal/zod-json-schema.js +46 -123
- package/dist/jsx-runtime.d.ts +3 -8
- package/dist/lambda/index.d.ts +17 -79
- package/dist/lambda/index.js +11 -59
- package/dist/logging/LogManager.d.ts +1 -51
- package/dist/logging/Logger.d.ts +8 -47
- package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
- package/dist/logging/channels/DailyFileChannel.d.ts +1 -5
- package/dist/logging/channels/FileChannel.d.ts +1 -3
- package/dist/logging/daily-file-path.d.ts +15 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/logging/types.d.ts +13 -45
- package/dist/{logging-CPaRMuPP.js → logging-zOY1XCtq.js} +83 -129
- package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
- package/dist/mail/Mail.d.ts +10 -106
- package/dist/mail/MailManager.d.ts +2 -60
- package/dist/mail/index.js +1 -1
- package/dist/mail/transports/LogTransport.d.ts +1 -4
- package/dist/mail/transports/MemoryTransport.d.ts +1 -63
- package/dist/mail/transports/ResendTransport.d.ts +1 -23
- package/dist/mail/transports/SmtpTransport.d.ts +1 -31
- package/dist/mail/types.d.ts +28 -150
- package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
- package/dist/mcp/McpServiceProvider.d.ts +4 -10
- package/dist/mcp/create-mcp-server.d.ts +25 -57
- package/dist/mcp/endpoint.d.ts +12 -36
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +46 -253
- package/dist/mvc/Router.d.ts +50 -129
- package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
- package/dist/mvc/inertia/shared.d.ts +6 -19
- package/dist/mvc/mount-route.d.ts +2 -6
- package/dist/mvc/view.d.ts +1 -2
- package/dist/notifications/Notification.d.ts +8 -75
- package/dist/notifications/NotificationManager.d.ts +15 -88
- package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
- package/dist/notifications/channels/MailChannel.d.ts +2 -31
- package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
- package/dist/notifications/channels/SlackChannel.d.ts +3 -48
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/notifiable-type.d.ts +3 -6
- package/dist/notifications/registry.d.ts +8 -27
- package/dist/notifications/types.d.ts +16 -53
- package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
- package/dist/providers/AuthServiceProvider.d.ts +1 -3
- package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
- package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
- package/dist/providers/CacheServiceProvider.d.ts +1 -3
- package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
- package/dist/providers/ErrorServiceProvider.d.ts +1 -4
- package/dist/providers/EventServiceProvider.d.ts +1 -3
- package/dist/providers/HealthServiceProvider.d.ts +1 -3
- package/dist/providers/I18nServiceProvider.d.ts +6 -10
- package/dist/providers/InertiaServiceProvider.d.ts +1 -4
- package/dist/providers/LogServiceProvider.d.ts +1 -3
- package/dist/providers/MailServiceProvider.d.ts +1 -3
- package/dist/providers/NotificationServiceProvider.d.ts +1 -3
- package/dist/providers/OAuthServiceProvider.d.ts +1 -3
- package/dist/providers/QueueServiceProvider.d.ts +1 -3
- package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
- package/dist/providers/StorageServiceProvider.d.ts +1 -3
- package/dist/queue/FailedJobReporter.d.ts +1 -24
- package/dist/queue/Job.d.ts +12 -99
- package/dist/queue/QueueManager.d.ts +6 -57
- package/dist/queue/Worker.d.ts +4 -65
- package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
- package/dist/queue/drivers/RedisDriver.d.ts +7 -65
- package/dist/queue/drivers/SqsDriver.d.ts +6 -57
- package/dist/queue/drivers/SyncDriver.d.ts +10 -13
- package/dist/queue/index.js +2 -2
- package/dist/queue/types.d.ts +10 -92
- package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
- package/dist/redis/RedisApiTokenStore.d.ts +4 -56
- package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
- package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
- package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
- package/dist/redis/RedisRateLimitStore.d.ts +16 -49
- package/dist/redis/RedisSessionStore.d.ts +3 -44
- package/dist/redis/client.d.ts +2 -32
- package/dist/redis/index.js +47 -232
- package/dist/redis/redis-values.d.ts +6 -12
- package/dist/redis/scan-keys.d.ts +1 -4
- package/dist/request-CLOYytGP.js +68 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +108 -74
- package/dist/scheduling/CronParser.d.ts +0 -29
- package/dist/scheduling/Schedule.d.ts +1 -153
- package/dist/scheduling/ScheduledTask.d.ts +0 -31
- package/dist/scheduling/Scheduler.d.ts +0 -70
- package/dist/scheduling/index.js +1 -1
- package/dist/scheduling/types.d.ts +4 -65
- package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
- package/dist/storage/StorageManager.d.ts +0 -48
- package/dist/storage/drivers/LocalDriver.d.ts +1 -25
- package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
- package/dist/storage/drivers/S3Driver.d.ts +6 -36
- package/dist/storage/drivers/s3-acl.d.ts +5 -10
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +27 -265
- package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
- package/dist/support/contained-path.d.ts +10 -20
- package/dist/support/error-polyfill.d.ts +4 -6
- package/dist/support/expiry.d.ts +17 -33
- package/dist/support/expiry.js +17 -33
- package/dist/support/import-map.d.ts +3 -7
- package/dist/support/inertia-defaults.d.ts +5 -10
- package/dist/support/redirect-target.d.ts +4 -6
- package/dist/support/stack-frames.d.ts +11 -50
- package/dist/support/trim-slashes.d.ts +4 -7
- package/dist/support/warn-once.d.ts +2 -6
- package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
- package/dist/{vite-manifest-BGfWbPYp.js → vite-manifest-CTQp-SOo.js} +34 -58
- package/package.json +6 -2
- package/dist/client-Dd7vLcqp.js +0 -27
- package/dist/context-DoD0c7J_.js +0 -26
- package/dist/endpoint-D-20PiHY.js +0 -46
- package/dist/hot-disposables-WsTX2ySN.js +0 -281
- package/dist/request-CRVuIiQr.js +0 -78
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
import { c as setQueueDriver, r as getJob } from "./Job-
|
|
1
|
+
import { c as setQueueDriver, r as getJob } from "./Job-DxQK8h3P.js";
|
|
2
2
|
//#region src/queue/drivers/MemoryDriver.ts
|
|
3
|
-
/**
|
|
4
|
-
* In-memory queue driver for development and testing.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { MemoryDriver, setQueueDriver } from '@guren/server/queue'
|
|
9
|
-
*
|
|
10
|
-
* const driver = new MemoryDriver()
|
|
11
|
-
* setQueueDriver(driver)
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
3
|
+
/** In-memory queue driver for development and testing. */
|
|
14
4
|
var MemoryDriver = class {
|
|
15
5
|
jobs = /* @__PURE__ */ new Map();
|
|
16
6
|
failedJobs = /* @__PURE__ */ new Map();
|
|
17
|
-
/**
|
|
18
|
-
* Push a job onto the queue.
|
|
19
|
-
*/
|
|
20
7
|
async push(job) {
|
|
21
8
|
this.jobs.set(job.id, { ...job });
|
|
22
9
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Pop the next available job from the queue.
|
|
25
|
-
*/
|
|
26
10
|
async pop(queue) {
|
|
27
11
|
const now = /* @__PURE__ */ new Date();
|
|
28
|
-
for (const [
|
|
12
|
+
for (const [_id, job] of this.jobs) if (job.queue === queue && job.availableAt <= now && job.reservedAt === null) {
|
|
29
13
|
job.reservedAt = now;
|
|
30
14
|
return { ...job };
|
|
31
15
|
}
|
|
32
16
|
return null;
|
|
33
17
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Release a job back onto the queue.
|
|
36
|
-
*/
|
|
37
18
|
async release(job, delayMs = 0) {
|
|
38
19
|
const existing = this.jobs.get(job.id);
|
|
39
20
|
if (existing) {
|
|
@@ -43,15 +24,9 @@ var MemoryDriver = class {
|
|
|
43
24
|
if (job.lastError) existing.lastError = job.lastError;
|
|
44
25
|
}
|
|
45
26
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Delete a job from the queue.
|
|
48
|
-
*/
|
|
49
27
|
async delete(jobId) {
|
|
50
28
|
this.jobs.delete(jobId);
|
|
51
29
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Mark a job as failed.
|
|
54
|
-
*/
|
|
55
30
|
async fail(job, error) {
|
|
56
31
|
const failedJob = {
|
|
57
32
|
...job,
|
|
@@ -62,25 +37,16 @@ var MemoryDriver = class {
|
|
|
62
37
|
this.failedJobs.set(job.id, failedJob);
|
|
63
38
|
this.jobs.delete(job.id);
|
|
64
39
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Get the number of jobs in a queue.
|
|
67
|
-
*/
|
|
68
40
|
async size(queue) {
|
|
69
41
|
let count = 0;
|
|
70
42
|
for (const job of this.jobs.values()) if (job.queue === queue && job.reservedAt === null) count++;
|
|
71
43
|
return count;
|
|
72
44
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Get failed jobs.
|
|
75
|
-
*/
|
|
76
45
|
async getFailedJobs(queue) {
|
|
77
46
|
const jobs = [];
|
|
78
47
|
for (const job of this.failedJobs.values()) if (!queue || job.queue === queue) jobs.push({ ...job });
|
|
79
48
|
return jobs.sort((a, b) => b.failedAt.getTime() - a.failedAt.getTime());
|
|
80
49
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Retry a failed job.
|
|
83
|
-
*/
|
|
84
50
|
async retryFailedJob(jobId) {
|
|
85
51
|
const failedJob = this.failedJobs.get(jobId);
|
|
86
52
|
if (!failedJob) throw new Error(`Failed job not found: ${jobId}`);
|
|
@@ -98,22 +64,15 @@ var MemoryDriver = class {
|
|
|
98
64
|
this.jobs.set(job.id, job);
|
|
99
65
|
this.failedJobs.delete(jobId);
|
|
100
66
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Delete a failed job.
|
|
103
|
-
*/
|
|
104
67
|
async deleteFailedJob(jobId) {
|
|
105
68
|
this.failedJobs.delete(jobId);
|
|
106
69
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Clear all jobs (for testing).
|
|
109
|
-
*/
|
|
70
|
+
/** Testing only. */
|
|
110
71
|
async clear() {
|
|
111
72
|
this.jobs.clear();
|
|
112
73
|
this.failedJobs.clear();
|
|
113
74
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Get all pending jobs (for testing/debugging).
|
|
116
|
-
*/
|
|
75
|
+
/** Testing/debugging only. */
|
|
117
76
|
getPendingJobs(queue) {
|
|
118
77
|
const jobs = [];
|
|
119
78
|
for (const job of this.jobs.values()) if (!queue || job.queue === queue) jobs.push({ ...job });
|
|
@@ -123,18 +82,10 @@ var MemoryDriver = class {
|
|
|
123
82
|
//#endregion
|
|
124
83
|
//#region src/queue/drivers/SyncDriver.ts
|
|
125
84
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* const queue = createQueueManager({
|
|
134
|
-
* default: 'sync',
|
|
135
|
-
* drivers: { sync: () => new SyncDriver() },
|
|
136
|
-
* })
|
|
137
|
-
* ```
|
|
85
|
+
* Runs jobs inline in the dispatching process, no worker required: the
|
|
86
|
+
* development default. Dispatch semantics match a real queue but failures
|
|
87
|
+
* surface immediately, and retry backoff is not honored because nothing waits
|
|
88
|
+
* in a sync queue (`release()` re-runs the job at once whatever `delayMs`).
|
|
138
89
|
*/
|
|
139
90
|
var SyncDriver = class {
|
|
140
91
|
failedJobs = /* @__PURE__ */ new Map();
|
|
@@ -152,7 +103,12 @@ var SyncDriver = class {
|
|
|
152
103
|
async pop() {
|
|
153
104
|
return null;
|
|
154
105
|
}
|
|
155
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Re-run the job now, ignoring `delayMs`: honoring a backoff would block the
|
|
108
|
+
* releasing caller for the full delay, and a detached timer would move the
|
|
109
|
+
* failure off the call that surfaces it. A failure rethrows, as `push()` does.
|
|
110
|
+
*/
|
|
111
|
+
async release(job, _delayMs) {
|
|
156
112
|
await this.push(job);
|
|
157
113
|
}
|
|
158
114
|
async delete() {}
|
|
@@ -191,23 +147,10 @@ var SyncDriver = class {
|
|
|
191
147
|
//#endregion
|
|
192
148
|
//#region src/queue/drivers/RedisDriver.ts
|
|
193
149
|
/**
|
|
194
|
-
* Redis-backed queue driver for production.
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* - `{prefix}{queue}:reserved` - Sorted Set (score = timeout timestamp)
|
|
199
|
-
* - `{prefix}{queue}:failed` - List of failed job IDs
|
|
200
|
-
* - `{prefix}job:{id}` - Hash containing job data
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```ts
|
|
204
|
-
* import { createRedisClient } from '@guren/server/redis'
|
|
205
|
-
* import { RedisDriver, setQueueDriver } from '@guren/server/queue'
|
|
206
|
-
*
|
|
207
|
-
* const redis = createRedisClient({ url: process.env.REDIS_URL })
|
|
208
|
-
* const driver = new RedisDriver(redis)
|
|
209
|
-
* setQueueDriver(driver)
|
|
210
|
-
* ```
|
|
150
|
+
* Redis-backed queue driver for production. Key layout:
|
|
151
|
+
* `{prefix}{queue}:pending` Sorted Set (score = availableAt),
|
|
152
|
+
* `{prefix}{queue}:reserved` Sorted Set (score = timeout),
|
|
153
|
+
* `{prefix}{queue}:failed` List of job IDs, `{prefix}job:{id}` Hash of job data.
|
|
211
154
|
*/
|
|
212
155
|
var RedisDriver = class {
|
|
213
156
|
redis;
|
|
@@ -230,9 +173,6 @@ var RedisDriver = class {
|
|
|
230
173
|
jobKey(id) {
|
|
231
174
|
return `${this.prefix}job:${id}`;
|
|
232
175
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Push a job onto the queue.
|
|
235
|
-
*/
|
|
236
176
|
async push(job) {
|
|
237
177
|
const jobData = {
|
|
238
178
|
id: job.id,
|
|
@@ -249,9 +189,6 @@ var RedisDriver = class {
|
|
|
249
189
|
pipeline.zadd(this.pendingKey(job.queue), job.availableAt.getTime(), job.id);
|
|
250
190
|
await pipeline.exec();
|
|
251
191
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Pop the next available job from the queue.
|
|
254
|
-
*/
|
|
255
192
|
async pop(queue) {
|
|
256
193
|
const now = Date.now();
|
|
257
194
|
await this.releaseTimedOutJobs(queue);
|
|
@@ -269,9 +206,6 @@ var RedisDriver = class {
|
|
|
269
206
|
}
|
|
270
207
|
return this.parseJobData(jobData);
|
|
271
208
|
}
|
|
272
|
-
/**
|
|
273
|
-
* Release jobs that have exceeded visibility timeout.
|
|
274
|
-
*/
|
|
275
209
|
async releaseTimedOutJobs(queue) {
|
|
276
210
|
const now = Date.now();
|
|
277
211
|
const timedOutIds = await this.redis.zrangebyscore(this.reservedKey(queue), "-inf", now);
|
|
@@ -280,9 +214,6 @@ var RedisDriver = class {
|
|
|
280
214
|
await this.redis.hdel(this.jobKey(jobId), "reservedAt");
|
|
281
215
|
}
|
|
282
216
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Release a job back onto the queue.
|
|
285
|
-
*/
|
|
286
217
|
async release(job, delayMs = 0) {
|
|
287
218
|
const availableAt = Date.now() + delayMs;
|
|
288
219
|
await this.redis.zrem(this.reservedKey(job.queue), job.id);
|
|
@@ -295,9 +226,6 @@ var RedisDriver = class {
|
|
|
295
226
|
await this.redis.hdel(this.jobKey(job.id), "reservedAt");
|
|
296
227
|
await this.redis.zadd(this.pendingKey(job.queue), availableAt, job.id);
|
|
297
228
|
}
|
|
298
|
-
/**
|
|
299
|
-
* Delete a job from the queue.
|
|
300
|
-
*/
|
|
301
229
|
async delete(jobId) {
|
|
302
230
|
const jobData = await this.redis.hgetall(this.jobKey(jobId));
|
|
303
231
|
if (jobData && jobData.queue) {
|
|
@@ -308,9 +236,6 @@ var RedisDriver = class {
|
|
|
308
236
|
await pipeline.exec();
|
|
309
237
|
} else await this.redis.del(this.jobKey(jobId));
|
|
310
238
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Mark a job as failed.
|
|
313
|
-
*/
|
|
314
239
|
async fail(job, error) {
|
|
315
240
|
const failedData = {
|
|
316
241
|
failedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -323,15 +248,9 @@ var RedisDriver = class {
|
|
|
323
248
|
pipeline.lpush(this.failedKey(job.queue), job.id);
|
|
324
249
|
await pipeline.exec();
|
|
325
250
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Get the number of jobs in a queue.
|
|
328
|
-
*/
|
|
329
251
|
async size(queue) {
|
|
330
252
|
return this.redis.zcard(this.pendingKey(queue));
|
|
331
253
|
}
|
|
332
|
-
/**
|
|
333
|
-
* Get failed jobs.
|
|
334
|
-
*/
|
|
335
254
|
async getFailedJobs(queue) {
|
|
336
255
|
const jobs = [];
|
|
337
256
|
if (queue) jobs.push(...await this.getFailedJobsForQueue(queue));
|
|
@@ -368,9 +287,6 @@ var RedisDriver = class {
|
|
|
368
287
|
}
|
|
369
288
|
return jobs;
|
|
370
289
|
}
|
|
371
|
-
/**
|
|
372
|
-
* Retry a failed job.
|
|
373
|
-
*/
|
|
374
290
|
async retryFailedJob(jobId) {
|
|
375
291
|
const jobData = await this.redis.hgetall(this.jobKey(jobId));
|
|
376
292
|
if (!jobData || !jobData.queue) throw new Error(`Failed job not found: ${jobId}`);
|
|
@@ -385,17 +301,12 @@ var RedisDriver = class {
|
|
|
385
301
|
await this.redis.hdel(this.jobKey(jobId), "reservedAt", "failedAt", "error", "stack", "lastError");
|
|
386
302
|
await this.redis.zadd(this.pendingKey(queue), now.getTime(), jobId);
|
|
387
303
|
}
|
|
388
|
-
/**
|
|
389
|
-
* Delete a failed job.
|
|
390
|
-
*/
|
|
391
304
|
async deleteFailedJob(jobId) {
|
|
392
305
|
const jobData = await this.redis.hgetall(this.jobKey(jobId));
|
|
393
306
|
if (jobData && jobData.queue) await this.redis.lrem(this.failedKey(jobData.queue), 1, jobId);
|
|
394
307
|
await this.redis.del(this.jobKey(jobId));
|
|
395
308
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Clear all jobs (for testing).
|
|
398
|
-
*/
|
|
309
|
+
/** Testing only. */
|
|
399
310
|
async clear() {
|
|
400
311
|
const pattern = this.prefix + "*";
|
|
401
312
|
let cursor = "0";
|
|
@@ -407,9 +318,6 @@ var RedisDriver = class {
|
|
|
407
318
|
} while (cursor !== "0");
|
|
408
319
|
if (keys.length > 0) await this.redis.del(...keys);
|
|
409
320
|
}
|
|
410
|
-
/**
|
|
411
|
-
* Parse job data from Redis hash.
|
|
412
|
-
*/
|
|
413
321
|
parseJobData(data) {
|
|
414
322
|
return {
|
|
415
323
|
id: data.id,
|
|
@@ -427,19 +335,7 @@ var RedisDriver = class {
|
|
|
427
335
|
};
|
|
428
336
|
//#endregion
|
|
429
337
|
//#region src/queue/drivers/SqsDriver.ts
|
|
430
|
-
/**
|
|
431
|
-
* Create an SqsAdapter from an @aws-sdk/client-sqs SQSClient.
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```ts
|
|
435
|
-
* import { SQSClient } from '@aws-sdk/client-sqs'
|
|
436
|
-
* import { createSqsAdapter, SqsDriver } from '@guren/server/queue'
|
|
437
|
-
*
|
|
438
|
-
* const client = new SQSClient({ region: 'ap-northeast-1' })
|
|
439
|
-
* const adapter = createSqsAdapter(client)
|
|
440
|
-
* const driver = new SqsDriver(adapter, { queueUrl: '...' })
|
|
441
|
-
* ```
|
|
442
|
-
*/
|
|
338
|
+
/** Builds an SqsAdapter over an @aws-sdk/client-sqs SQSClient. */
|
|
443
339
|
function createSqsAdapter(client) {
|
|
444
340
|
return {
|
|
445
341
|
async sendMessage(params) {
|
|
@@ -494,22 +390,7 @@ async function importSqs() {
|
|
|
494
390
|
throw new Error(`Missing optional dependency "${SQS_MODULE}". Install @aws-sdk/client-sqs to use the SQS driver or createSqsAdapter.`);
|
|
495
391
|
}
|
|
496
392
|
}
|
|
497
|
-
/**
|
|
498
|
-
* AWS SQS queue driver for serverless deployments.
|
|
499
|
-
*
|
|
500
|
-
* @example
|
|
501
|
-
* ```ts
|
|
502
|
-
* import { SQSClient } from '@aws-sdk/client-sqs'
|
|
503
|
-
* import { createSqsAdapter, SqsDriver, setQueueDriver } from '@guren/server/queue'
|
|
504
|
-
*
|
|
505
|
-
* const adapter = createSqsAdapter(new SQSClient({ region: 'ap-northeast-1' }))
|
|
506
|
-
* const driver = new SqsDriver(adapter, { queueUrl: process.env.SQS_QUEUE_URL! })
|
|
507
|
-
* setQueueDriver(driver)
|
|
508
|
-
*
|
|
509
|
-
* // Dispatch jobs as usual
|
|
510
|
-
* await SendEmailJob.dispatch({ to: 'user@example.com' })
|
|
511
|
-
* ```
|
|
512
|
-
*/
|
|
393
|
+
/** AWS SQS queue driver for serverless deployments. */
|
|
513
394
|
var SqsDriver = class {
|
|
514
395
|
adapter;
|
|
515
396
|
options;
|
|
@@ -601,9 +482,6 @@ var SqsDriver = class {
|
|
|
601
482
|
return this.options.queueUrls?.[queue] ?? this.options.queueUrl;
|
|
602
483
|
}
|
|
603
484
|
};
|
|
604
|
-
/**
|
|
605
|
-
* Deserialize a JSON string into a QueuedJob, restoring Date objects.
|
|
606
|
-
*/
|
|
607
485
|
function deserializeJob(body) {
|
|
608
486
|
const raw = JSON.parse(body);
|
|
609
487
|
return {
|
|
@@ -616,26 +494,8 @@ function deserializeJob(body) {
|
|
|
616
494
|
//#endregion
|
|
617
495
|
//#region src/queue/Worker.ts
|
|
618
496
|
/**
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
* @example
|
|
622
|
-
* ```ts
|
|
623
|
-
* import { Worker, MemoryDriver, setQueueDriver } from '@guren/server/queue'
|
|
624
|
-
*
|
|
625
|
-
* const driver = new MemoryDriver()
|
|
626
|
-
* setQueueDriver(driver)
|
|
627
|
-
*
|
|
628
|
-
* const worker = new Worker(driver, {
|
|
629
|
-
* queues: ['default', 'emails'],
|
|
630
|
-
* sleep: 1000,
|
|
631
|
-
* })
|
|
632
|
-
*
|
|
633
|
-
* // Start processing
|
|
634
|
-
* await worker.start()
|
|
635
|
-
*
|
|
636
|
-
* // Stop gracefully
|
|
637
|
-
* await worker.stop()
|
|
638
|
-
* ```
|
|
497
|
+
* Pulls jobs off a driver's queues in priority order and runs each under a
|
|
498
|
+
* timeout, retrying through `driver.release()`.
|
|
639
499
|
*/
|
|
640
500
|
var Worker = class {
|
|
641
501
|
driver;
|
|
@@ -660,9 +520,6 @@ var Worker = class {
|
|
|
660
520
|
this.timeout = options.timeout ?? 6e4;
|
|
661
521
|
this.stopWhenEmpty = options.stopWhenEmpty ?? false;
|
|
662
522
|
}
|
|
663
|
-
/**
|
|
664
|
-
* Start the worker.
|
|
665
|
-
*/
|
|
666
523
|
async start() {
|
|
667
524
|
if (this.running) return;
|
|
668
525
|
this.running = true;
|
|
@@ -683,29 +540,17 @@ var Worker = class {
|
|
|
683
540
|
this.running = false;
|
|
684
541
|
this.events.workerStopped?.();
|
|
685
542
|
}
|
|
686
|
-
/**
|
|
687
|
-
* Stop the worker gracefully.
|
|
688
|
-
*/
|
|
689
543
|
async stop() {
|
|
690
544
|
this.shouldStop = true;
|
|
691
545
|
const startWait = Date.now();
|
|
692
546
|
while (this.running && this.currentJob && Date.now() - startWait < this.timeout) await this.sleepMs(100);
|
|
693
547
|
}
|
|
694
|
-
/**
|
|
695
|
-
* Check if the worker is running.
|
|
696
|
-
*/
|
|
697
548
|
isRunning() {
|
|
698
549
|
return this.running;
|
|
699
550
|
}
|
|
700
|
-
/**
|
|
701
|
-
* Get the number of processed jobs.
|
|
702
|
-
*/
|
|
703
551
|
getProcessedJobsCount() {
|
|
704
552
|
return this.processedJobs;
|
|
705
553
|
}
|
|
706
|
-
/**
|
|
707
|
-
* Get the next available job from the queues.
|
|
708
|
-
*/
|
|
709
554
|
async getNextJob() {
|
|
710
555
|
for (const queue of this.queues) {
|
|
711
556
|
const job = await this.driver.pop(queue);
|
|
@@ -713,9 +558,6 @@ var Worker = class {
|
|
|
713
558
|
}
|
|
714
559
|
return null;
|
|
715
560
|
}
|
|
716
|
-
/**
|
|
717
|
-
* Process a single job.
|
|
718
|
-
*/
|
|
719
561
|
async processJob(job) {
|
|
720
562
|
this.currentJob = job;
|
|
721
563
|
job.attempts++;
|
|
@@ -737,9 +579,6 @@ var Worker = class {
|
|
|
737
579
|
this.currentJob = null;
|
|
738
580
|
}
|
|
739
581
|
}
|
|
740
|
-
/**
|
|
741
|
-
* Handle a failed job.
|
|
742
|
-
*/
|
|
743
582
|
async handleFailedJob(job, error, JobClass) {
|
|
744
583
|
const willRetry = job.attempts < job.maxAttempts;
|
|
745
584
|
if (willRetry) {
|
|
@@ -767,9 +606,6 @@ var Worker = class {
|
|
|
767
606
|
}));
|
|
768
607
|
this.events.jobFailed?.(job, error, willRetry);
|
|
769
608
|
}
|
|
770
|
-
/**
|
|
771
|
-
* Execute a function with a timeout.
|
|
772
|
-
*/
|
|
773
609
|
async executeWithTimeout(fn, timeoutMs) {
|
|
774
610
|
return new Promise((resolve, reject) => {
|
|
775
611
|
const timer = setTimeout(() => {
|
|
@@ -784,16 +620,11 @@ var Worker = class {
|
|
|
784
620
|
});
|
|
785
621
|
});
|
|
786
622
|
}
|
|
787
|
-
/**
|
|
788
|
-
* Sleep for a given number of milliseconds.
|
|
789
|
-
*/
|
|
790
623
|
sleepMs(ms) {
|
|
791
624
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
792
625
|
}
|
|
793
626
|
};
|
|
794
|
-
/**
|
|
795
|
-
* Process a single job (for testing or one-off execution).
|
|
796
|
-
*/
|
|
627
|
+
/** Process one job without a running worker, for tests and one-off execution. */
|
|
797
628
|
async function processJob(driver, queue = "default") {
|
|
798
629
|
const worker = new Worker(driver, {
|
|
799
630
|
queues: [queue],
|
|
@@ -805,9 +636,6 @@ async function processJob(driver, queue = "default") {
|
|
|
805
636
|
}
|
|
806
637
|
//#endregion
|
|
807
638
|
//#region src/queue/FailedJobReporter.ts
|
|
808
|
-
/**
|
|
809
|
-
* Default handler that writes structured JSON to stderr.
|
|
810
|
-
*/
|
|
811
639
|
function defaultLogHandler(info) {
|
|
812
640
|
console.error(JSON.stringify({
|
|
813
641
|
level: "error",
|
|
@@ -821,33 +649,16 @@ function defaultLogHandler(info) {
|
|
|
821
649
|
failedAt: info.failedAt.toISOString()
|
|
822
650
|
}));
|
|
823
651
|
}
|
|
824
|
-
/**
|
|
825
|
-
* Configurable reporter for failed queue jobs.
|
|
826
|
-
*
|
|
827
|
-
* Registered by default in QueueServiceProvider to log failures.
|
|
828
|
-
* Can be extended with custom handlers (e.g., Sentry, Slack notifications).
|
|
829
|
-
*
|
|
830
|
-
* @example
|
|
831
|
-
* ```ts
|
|
832
|
-
* const reporter = new FailedJobReporter()
|
|
833
|
-
*
|
|
834
|
-
* // Add a custom handler alongside the default logger
|
|
835
|
-
* reporter.onFailure(async (info) => {
|
|
836
|
-
* await sendToSentry(info.error)
|
|
837
|
-
* })
|
|
838
|
-
* ```
|
|
839
|
-
*/
|
|
652
|
+
/** Registered by default in QueueServiceProvider; extend with custom handlers. */
|
|
840
653
|
var FailedJobReporter = class {
|
|
841
654
|
handlers = [];
|
|
842
655
|
constructor() {
|
|
843
656
|
this.handlers.push(defaultLogHandler);
|
|
844
657
|
}
|
|
845
|
-
/** Add a custom handler for failed jobs. */
|
|
846
658
|
onFailure(handler) {
|
|
847
659
|
this.handlers.push(handler);
|
|
848
660
|
return this;
|
|
849
661
|
}
|
|
850
|
-
/** Report a job failure to all registered handlers. */
|
|
851
662
|
async report(info) {
|
|
852
663
|
for (const handler of this.handlers) try {
|
|
853
664
|
await handler(info);
|
|
@@ -857,29 +668,8 @@ var FailedJobReporter = class {
|
|
|
857
668
|
//#endregion
|
|
858
669
|
//#region src/queue/QueueManager.ts
|
|
859
670
|
/**
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* ```ts
|
|
864
|
-
* import { QueueManager, MemoryDriver, RedisDriver } from '@guren/server/queue'
|
|
865
|
-
* import { createRedisClient } from '@guren/server/redis'
|
|
866
|
-
*
|
|
867
|
-
* const redis = createRedisClient({ url: process.env.REDIS_URL })
|
|
868
|
-
*
|
|
869
|
-
* const queueManager = new QueueManager({
|
|
870
|
-
* default: 'redis',
|
|
871
|
-
* drivers: {
|
|
872
|
-
* memory: () => new MemoryDriver(),
|
|
873
|
-
* redis: () => new RedisDriver(redis),
|
|
874
|
-
* }
|
|
875
|
-
* })
|
|
876
|
-
*
|
|
877
|
-
* // Use the default driver
|
|
878
|
-
* const driver = queueManager.driver()
|
|
879
|
-
*
|
|
880
|
-
* // Use a specific driver
|
|
881
|
-
* const memoryDriver = queueManager.driver('memory')
|
|
882
|
-
* ```
|
|
671
|
+
* Resolves queue drivers by name from the configured factories; `driver()` with
|
|
672
|
+
* no name returns the default and publishes it as the global driver.
|
|
883
673
|
*/
|
|
884
674
|
var QueueManager = class {
|
|
885
675
|
defaultDriver;
|
|
@@ -889,10 +679,6 @@ var QueueManager = class {
|
|
|
889
679
|
this.defaultDriver = config.default ?? "memory";
|
|
890
680
|
if (config.drivers) for (const [name, factory] of Object.entries(config.drivers)) this.driverFactories.set(name, factory);
|
|
891
681
|
}
|
|
892
|
-
/**
|
|
893
|
-
* Get a queue driver by name.
|
|
894
|
-
* Returns the default driver if no name is specified.
|
|
895
|
-
*/
|
|
896
682
|
driver(name) {
|
|
897
683
|
const driverName = name ?? this.defaultDriver;
|
|
898
684
|
const cached = this.resolvedDrivers.get(driverName);
|
|
@@ -904,43 +690,29 @@ var QueueManager = class {
|
|
|
904
690
|
if (driverName === this.defaultDriver) setQueueDriver(driver);
|
|
905
691
|
return driver;
|
|
906
692
|
}
|
|
907
|
-
/**
|
|
908
|
-
* Register a custom driver factory.
|
|
909
|
-
*/
|
|
910
693
|
registerDriver(name, factory) {
|
|
911
694
|
this.driverFactories.set(name, factory);
|
|
912
695
|
this.resolvedDrivers.delete(name);
|
|
913
696
|
}
|
|
914
|
-
/**
|
|
915
|
-
* Check if a driver is registered.
|
|
916
|
-
*/
|
|
917
697
|
hasDriver(name) {
|
|
918
698
|
return this.driverFactories.has(name);
|
|
919
699
|
}
|
|
920
|
-
/**
|
|
921
|
-
* Get the default driver name.
|
|
922
|
-
*/
|
|
923
700
|
getDefaultDriverName() {
|
|
924
701
|
return this.defaultDriver;
|
|
925
702
|
}
|
|
926
|
-
/**
|
|
927
|
-
* Get all registered driver names.
|
|
928
|
-
*/
|
|
929
703
|
getDriverNames() {
|
|
930
704
|
return Array.from(this.driverFactories.keys());
|
|
931
705
|
}
|
|
932
706
|
/**
|
|
933
|
-
*
|
|
707
|
+
* After this, `driver()` with no name, `getDefaultDriverName()`, and
|
|
708
|
+
* `Job.dispatch()` all use the new driver.
|
|
934
709
|
*/
|
|
935
710
|
setDefaultDriver(name) {
|
|
936
711
|
if (!this.driverFactories.has(name)) throw new Error(`Queue driver not found: ${name}`);
|
|
937
|
-
|
|
938
|
-
setQueueDriver(driver);
|
|
712
|
+
this.defaultDriver = name;
|
|
713
|
+
setQueueDriver(this.driver(name));
|
|
939
714
|
}
|
|
940
715
|
};
|
|
941
|
-
/**
|
|
942
|
-
* Create a queue manager with default configuration.
|
|
943
|
-
*/
|
|
944
716
|
function createQueueManager(config) {
|
|
945
717
|
return new QueueManager(config);
|
|
946
718
|
}
|
|
@@ -1,78 +1,26 @@
|
|
|
1
1
|
import type { Redis } from 'ioredis';
|
|
2
2
|
import type { ApiToken, ApiTokenStore } from '../auth/api-token.js';
|
|
3
|
-
/**
|
|
4
|
-
* Options for RedisApiTokenStore.
|
|
5
|
-
*/
|
|
6
3
|
export interface RedisApiTokenStoreOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Key prefix for token keys.
|
|
9
|
-
* @default 'apitoken:'
|
|
10
|
-
*/
|
|
4
|
+
/** @default 'apitoken:' */
|
|
11
5
|
prefix?: string;
|
|
12
6
|
}
|
|
13
7
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Uses the following key structure:
|
|
17
|
-
* - `apitoken:{id}` - Token data (hash)
|
|
18
|
-
* - `apitoken:hash:{hashedToken}` - Maps hash to token ID
|
|
19
|
-
* - `apitoken:user:{userId}` - Set of token IDs for a user
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { createRedisClient } from '@guren/server/redis'
|
|
24
|
-
*
|
|
25
|
-
* const redis = createRedisClient({ url: process.env.REDIS_URL })
|
|
26
|
-
* const store = new RedisApiTokenStore(redis)
|
|
27
|
-
*
|
|
28
|
-
* const { plainTextToken } = await createApiToken(store, {
|
|
29
|
-
* name: 'API Token',
|
|
30
|
-
* userId: user.id,
|
|
31
|
-
* })
|
|
32
|
-
* ```
|
|
8
|
+
* Key layout: `apitoken:{id}` Hash of token data, `apitoken:hash:{hashedToken}`
|
|
9
|
+
* hash → token ID, `apitoken:user:{userId}` Set of a user's token IDs.
|
|
33
10
|
*/
|
|
34
11
|
export declare class RedisApiTokenStore implements ApiTokenStore {
|
|
35
12
|
private readonly redis;
|
|
36
13
|
private readonly prefix;
|
|
37
14
|
constructor(redis: Redis, options?: RedisApiTokenStoreOptions);
|
|
38
|
-
/**
|
|
39
|
-
* Store a new API token.
|
|
40
|
-
*/
|
|
41
15
|
store(token: ApiToken): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Find a token by its hashed value.
|
|
44
|
-
*/
|
|
45
16
|
findByHashedToken(hashedToken: string): Promise<ApiToken | null>;
|
|
46
|
-
/**
|
|
47
|
-
* Find all tokens for a user.
|
|
48
|
-
*/
|
|
49
17
|
findByUserId(userId: string | number): Promise<ApiToken[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Delete a token by its ID.
|
|
52
|
-
*/
|
|
53
18
|
delete(id: string): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Delete all tokens for a user.
|
|
56
|
-
*/
|
|
57
19
|
deleteForUser(userId: string | number): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Update the last used timestamp.
|
|
60
|
-
*/
|
|
61
20
|
updateLastUsed(id: string, timestamp: Date): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Find a token by its ID.
|
|
64
|
-
*/
|
|
65
21
|
private findById;
|
|
66
|
-
/**
|
|
67
|
-
* Serialize a token for Redis storage.
|
|
68
|
-
*/
|
|
69
22
|
private serializeToken;
|
|
70
|
-
/**
|
|
71
|
-
* Deserialize a token from Redis storage.
|
|
72
|
-
*/
|
|
73
23
|
private deserializeToken;
|
|
74
|
-
/**
|
|
75
|
-
* Clear all tokens (for testing).
|
|
76
|
-
*/
|
|
24
|
+
/** Testing only. */
|
|
77
25
|
clear(): Promise<void>;
|
|
78
26
|
}
|