@warlock.js/queue 5.14.0 → 5.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.
@@ -1,42 +0,0 @@
1
- import { JobBackoff } from "../types.mjs";
2
- import { QueueDispatcher } from "@warlock.js/notifications";
3
-
4
- //#region ../queue/src/notifications/queue-notification-dispatcher.d.ts
5
- /** The job name notification deliveries run under. */
6
- declare const NOTIFICATION_JOB_NAME = "warlock.notifications.deliver";
7
- type NotificationJobPayload = Parameters<QueueDispatcher["dispatch"]>[0];
8
- type QueueNotificationDispatcherOptions = {
9
- /** Queue to deliver on. Default: the default queue. */queue?: string; /** Attempts per delivery. Default: `queue.defaultJobOptions.attempts`, else `1`. */
10
- attempts?: number; /** Backoff between attempts. */
11
- backoff?: JobBackoff;
12
- };
13
- /**
14
- * Create the dispatcher for `NotificationConfig.queue`.
15
- *
16
- * - `SendOptions.delay` is honoured: a number is SECONDS (notifications'
17
- * convention), a string is a duration such as `"10m"`.
18
- * - A failing `channel.send` throws, so the delivery is retried per
19
- * `attempts` / `backoff` and ends in `failedJobs()` when exhausted.
20
- * - A channel missing from the worker's notifications config fails at once,
21
- * without retries.
22
- *
23
- * @deprecated Import `bullmqQueue` from `@warlock.js/notifications` instead —
24
- * vendor integrations now live as lazy drivers inside the feature package:
25
- *
26
- * queue: bullmqQueue({ attempts: 3, backoff: { type: "exponential", delay: 5000 } })
27
- *
28
- * This subpath keeps working for one release and then goes away. See the
29
- * queue CHANGELOG.
30
- *
31
- * @example src/config/notifications.ts
32
- * import { queueNotificationDispatcher } from "@warlock.js/queue/notifications";
33
- *
34
- * const config: NotificationConfig = {
35
- * channels: { mail: mailChannel() },
36
- * queue: queueNotificationDispatcher({ attempts: 3, backoff: { type: "exponential", delay: 5000 } }),
37
- * };
38
- */
39
- declare function queueNotificationDispatcher(options?: QueueNotificationDispatcherOptions): QueueDispatcher;
40
- //#endregion
41
- export { NOTIFICATION_JOB_NAME, NotificationJobPayload, QueueNotificationDispatcherOptions, queueNotificationDispatcher };
42
- //# sourceMappingURL=queue-notification-dispatcher.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue-notification-dispatcher.d.mts","names":[],"sources":["../../../../../../../queue/src/notifications/queue-notification-dispatcher.ts"],"mappings":";;;;AAqB+D;AAAA,cAFlD,qBAAA;AAAA,KAED,sBAAA,GAAyB,UAAU,CAAC,eAAA;AAAA,KAEpC,kCAAA;EAMU,uDAJpB,KAAA,WAEA;EAAA,QAAA,WAEU;EAAV,OAAA,GAAU,UAAU;AAAA;AA6BtB;;;;;;;;AAEkB;;;;;;;;;;;;;;;;;;AAFlB,iBAAgB,2BAAA,CACd,OAAA,GAAS,kCAAA,GACR,eAAe"}
@@ -1,91 +0,0 @@
1
- import { toMilliseconds } from "../duration.mjs";
2
- import { defineJob } from "../define-job.mjs";
3
- import { log } from "@warlock.js/logger";
4
- import { UnrecoverableError } from "bullmq";
5
- import { getNotificationConfig } from "@warlock.js/notifications";
6
-
7
- //#region ../queue/src/notifications/queue-notification-dispatcher.ts
8
- /**
9
- * BullMQ-backed `QueueDispatcher` for `@warlock.js/notifications`.
10
- *
11
- * Notifications renders the payload and resolves the route BEFORE handing a
12
- * job to its dispatcher, so the job (`{ channel, route, payload, options }`)
13
- * is plain JSON. This adapter enqueues it as a queue job; the job's handler,
14
- * running in any worker process, looks the channel up by name in that
15
- * process's notifications config and calls `channel.send`.
16
- *
17
- * Notifications itself has no dependency on this package.
18
- */
19
- /** The job name notification deliveries run under. */
20
- const NOTIFICATION_JOB_NAME = "warlock.notifications.deliver";
21
- /**
22
- * Create the dispatcher for `NotificationConfig.queue`.
23
- *
24
- * - `SendOptions.delay` is honoured: a number is SECONDS (notifications'
25
- * convention), a string is a duration such as `"10m"`.
26
- * - A failing `channel.send` throws, so the delivery is retried per
27
- * `attempts` / `backoff` and ends in `failedJobs()` when exhausted.
28
- * - A channel missing from the worker's notifications config fails at once,
29
- * without retries.
30
- *
31
- * @deprecated Import `bullmqQueue` from `@warlock.js/notifications` instead —
32
- * vendor integrations now live as lazy drivers inside the feature package:
33
- *
34
- * queue: bullmqQueue({ attempts: 3, backoff: { type: "exponential", delay: 5000 } })
35
- *
36
- * This subpath keeps working for one release and then goes away. See the
37
- * queue CHANGELOG.
38
- *
39
- * @example src/config/notifications.ts
40
- * import { queueNotificationDispatcher } from "@warlock.js/queue/notifications";
41
- *
42
- * const config: NotificationConfig = {
43
- * channels: { mail: mailChannel() },
44
- * queue: queueNotificationDispatcher({ attempts: 3, backoff: { type: "exponential", delay: 5000 } }),
45
- * };
46
- */
47
- function queueNotificationDispatcher(options = {}) {
48
- warnDeprecatedOnce();
49
- const deliver = defineNotificationJob(options);
50
- return { async dispatch(job) {
51
- await deliver.dispatch(job, { delay: job.options.delay === void 0 ? void 0 : notificationDelay(job.options.delay) });
52
- } };
53
- }
54
- function defineNotificationJob(options) {
55
- return defineJob({
56
- name: NOTIFICATION_JOB_NAME,
57
- queue: options.queue,
58
- attempts: options.attempts,
59
- backoff: options.backoff,
60
- async handle(job) {
61
- const channel = getNotificationConfig().channels[job.channel];
62
- if (!channel) throw new UnrecoverableError(`Notification channel "${job.channel}" is not configured in this worker's notifications config.`);
63
- await channel.send({
64
- payload: job.payload,
65
- route: job.route,
66
- options: job.options
67
- });
68
- }
69
- });
70
- }
71
- function notificationDelay(delay) {
72
- return typeof delay === "number" ? delay * 1e3 : toMilliseconds(delay);
73
- }
74
- let warnedDeprecated = false;
75
- /**
76
- * Warn once per process that `@warlock.js/queue/notifications` is deprecated
77
- * in favour of `bullmqQueue` from `@warlock.js/notifications`. Kept thin —
78
- * this file still owns the actual dispatch logic (delegating to notifications
79
- * would create a runtime import cycle: notifications' `bullmqQueue` lazily
80
- * imports `@warlock.js/queue`, which this file already statically imports
81
- * `@warlock.js/notifications` from).
82
- */
83
- function warnDeprecatedOnce() {
84
- if (warnedDeprecated) return;
85
- warnedDeprecated = true;
86
- log.warn("queue", "notifications.deprecated", "\"queueNotificationDispatcher\" from \"@warlock.js/queue/notifications\" is deprecated and will be removed in the next release. Use the notifications-owned driver instead: import { bullmqQueue } from \"@warlock.js/notifications\"; queue: bullmqQueue({ attempts, backoff })");
87
- }
88
-
89
- //#endregion
90
- export { NOTIFICATION_JOB_NAME, queueNotificationDispatcher };
91
- //# sourceMappingURL=queue-notification-dispatcher.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue-notification-dispatcher.mjs","names":[],"sources":["../../../../../../../queue/src/notifications/queue-notification-dispatcher.ts"],"sourcesContent":["/**\n * BullMQ-backed `QueueDispatcher` for `@warlock.js/notifications`.\n *\n * Notifications renders the payload and resolves the route BEFORE handing a\n * job to its dispatcher, so the job (`{ channel, route, payload, options }`)\n * is plain JSON. This adapter enqueues it as a queue job; the job's handler,\n * running in any worker process, looks the channel up by name in that\n * process's notifications config and calls `channel.send`.\n *\n * Notifications itself has no dependency on this package.\n */\nimport { getNotificationConfig, type QueueDispatcher } from \"@warlock.js/notifications\";\nimport { log } from \"@warlock.js/logger\";\nimport { UnrecoverableError } from \"bullmq\";\nimport { defineJob } from \"../define-job\";\nimport { toMilliseconds } from \"../duration\";\nimport type { Duration, JobBackoff, QueueJob } from \"../types\";\n\n/** The job name notification deliveries run under. */\nexport const NOTIFICATION_JOB_NAME = \"warlock.notifications.deliver\";\n\nexport type NotificationJobPayload = Parameters<QueueDispatcher[\"dispatch\"]>[0];\n\nexport type QueueNotificationDispatcherOptions = {\n /** Queue to deliver on. Default: the default queue. */\n queue?: string;\n /** Attempts per delivery. Default: `queue.defaultJobOptions.attempts`, else `1`. */\n attempts?: number;\n /** Backoff between attempts. */\n backoff?: JobBackoff;\n};\n\n/**\n * Create the dispatcher for `NotificationConfig.queue`.\n *\n * - `SendOptions.delay` is honoured: a number is SECONDS (notifications'\n * convention), a string is a duration such as `\"10m\"`.\n * - A failing `channel.send` throws, so the delivery is retried per\n * `attempts` / `backoff` and ends in `failedJobs()` when exhausted.\n * - A channel missing from the worker's notifications config fails at once,\n * without retries.\n *\n * @deprecated Import `bullmqQueue` from `@warlock.js/notifications` instead —\n * vendor integrations now live as lazy drivers inside the feature package:\n *\n * queue: bullmqQueue({ attempts: 3, backoff: { type: \"exponential\", delay: 5000 } })\n *\n * This subpath keeps working for one release and then goes away. See the\n * queue CHANGELOG.\n *\n * @example src/config/notifications.ts\n * import { queueNotificationDispatcher } from \"@warlock.js/queue/notifications\";\n *\n * const config: NotificationConfig = {\n * channels: { mail: mailChannel() },\n * queue: queueNotificationDispatcher({ attempts: 3, backoff: { type: \"exponential\", delay: 5000 } }),\n * };\n */\nexport function queueNotificationDispatcher(\n options: QueueNotificationDispatcherOptions = {},\n): QueueDispatcher {\n warnDeprecatedOnce();\n const deliver = defineNotificationJob(options);\n\n return {\n async dispatch(job) {\n await deliver.dispatch(job, {\n delay: job.options.delay === undefined ? undefined : notificationDelay(job.options.delay),\n });\n },\n };\n}\n\nfunction defineNotificationJob(\n options: QueueNotificationDispatcherOptions,\n): QueueJob<NotificationJobPayload, void> {\n return defineJob<NotificationJobPayload, void>({\n name: NOTIFICATION_JOB_NAME,\n queue: options.queue,\n attempts: options.attempts,\n backoff: options.backoff,\n async handle(job) {\n const channels = getNotificationConfig().channels as Record<\n string,\n { send(context: never): Promise<void> } | undefined\n >;\n const channel = channels[job.channel];\n\n if (!channel) {\n throw new UnrecoverableError(\n `Notification channel \"${job.channel}\" is not configured in this worker's notifications config.`,\n );\n }\n\n await channel.send({ payload: job.payload, route: job.route, options: job.options } as never);\n },\n });\n}\n\nfunction notificationDelay(delay: number | string): Duration {\n return typeof delay === \"number\" ? delay * 1_000 : toMilliseconds(delay);\n}\n\nlet warnedDeprecated = false;\n\n/**\n * Warn once per process that `@warlock.js/queue/notifications` is deprecated\n * in favour of `bullmqQueue` from `@warlock.js/notifications`. Kept thin —\n * this file still owns the actual dispatch logic (delegating to notifications\n * would create a runtime import cycle: notifications' `bullmqQueue` lazily\n * imports `@warlock.js/queue`, which this file already statically imports\n * `@warlock.js/notifications` from).\n */\nfunction warnDeprecatedOnce(): void {\n if (warnedDeprecated) {\n return;\n }\n\n warnedDeprecated = true;\n log.warn(\n \"queue\",\n \"notifications.deprecated\",\n '\"queueNotificationDispatcher\" from \"@warlock.js/queue/notifications\" is deprecated and will be ' +\n \"removed in the next release. Use the notifications-owned driver instead: \" +\n 'import { bullmqQueue } from \"@warlock.js/notifications\"; ' +\n 'queue: bullmqQueue({ attempts, backoff })',\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAa,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCrC,SAAgB,4BACd,UAA8C,CAAC,GAC9B;CACjB,mBAAmB;CACnB,MAAM,UAAU,sBAAsB,OAAO;CAE7C,OAAO,EACL,MAAM,SAAS,KAAK;EAClB,MAAM,QAAQ,SAAS,KAAK,EAC1B,OAAO,IAAI,QAAQ,UAAU,SAAY,SAAY,kBAAkB,IAAI,QAAQ,KAAK,EAC1F,CAAC;CACH,EACF;AACF;AAEA,SAAS,sBACP,SACwC;CACxC,OAAO,UAAwC;EAC7C,MAAM;EACN,OAAO,QAAQ;EACf,UAAU,QAAQ;EAClB,SAAS,QAAQ;EACjB,MAAM,OAAO,KAAK;GAKhB,MAAM,UAJW,sBAAsB,CAAC,CAAC,SAIhB,IAAI;GAE7B,IAAI,CAAC,SACH,MAAM,IAAI,mBACR,yBAAyB,IAAI,QAAQ,2DACvC;GAGF,MAAM,QAAQ,KAAK;IAAE,SAAS,IAAI;IAAS,OAAO,IAAI;IAAO,SAAS,IAAI;GAAQ,CAAU;EAC9F;CACF,CAAC;AACH;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,OAAO,OAAO,UAAU,WAAW,QAAQ,MAAQ,eAAe,KAAK;AACzE;AAEA,IAAI,mBAAmB;;;;;;;;;AAUvB,SAAS,qBAA2B;CAClC,IAAI,kBACF;CAGF,mBAAmB;CACnB,IAAI,KACF,SACA,4BACA,kRAIF;AACF"}