@vite-hub/queue 0.3.1 → 0.4.1

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 (40) hide show
  1. package/README.md +20 -18
  2. package/dist/{client-Cj50hQYp.js → client-B53_G4ky.js} +11 -9
  3. package/dist/{cloudflare-client-DYsAjM8B.js → cloudflare-client-CoISDpIx.js} +22 -8
  4. package/dist/{cloudflare-resource-name-BJHYRCMQ.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
  5. package/dist/{config-BcTDeQIP.js → config-B2eaXaT5.js} +1 -1
  6. package/dist/{errors-DL3pcNO4.js → duration-tujyhAKt.js} +40 -6
  7. package/dist/{error-diagnostics-DSkCJC_L.js → error-diagnostics-CQ4BUqRe.js} +5 -1
  8. package/dist/{error-diagnostics-BRartC1z.js → error-diagnostics-mJXBjmQx.js} +7 -7
  9. package/dist/{handler-response-By0Fpspv.js → handler-response-B6lz9nCn.js} +1 -1
  10. package/dist/index.d.ts +7 -3
  11. package/dist/index.js +19 -9
  12. package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
  13. package/dist/internal/runtime/cloudflare-client.js +1 -1
  14. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  15. package/dist/internal/runtime/cloudflare-vite.js +8 -8
  16. package/dist/internal/runtime/local-client.d.ts +3 -3
  17. package/dist/internal/runtime/local-client.js +4 -4
  18. package/dist/internal/runtime/postgres-client.d.ts +3 -3
  19. package/dist/internal/runtime/postgres-client.js +24 -14
  20. package/dist/internal/runtime/state.d.ts +2 -2
  21. package/dist/internal/runtime/state.js +1 -1
  22. package/dist/internal/runtime/vercel-client.d.ts +1 -1
  23. package/dist/internal/runtime/vercel-client.js +23 -11
  24. package/dist/internal/runtime/worker-client.d.ts +2 -2
  25. package/dist/internal/runtime/worker-client.js +1 -1
  26. package/dist/{local-CVVRVWeR.d.ts → local-CUaWoRUx.d.ts} +2 -1
  27. package/dist/{local-CGckW5nr.js → local-Di0FrVUw.js} +27 -14
  28. package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-nmRu_O3V.d.ts} +5 -0
  29. package/dist/{operations-Crwjca91.js → operations-BVV-9Q0N.js} +10 -5
  30. package/dist/operations.d.ts +5 -4
  31. package/dist/operations.js +15 -47
  32. package/dist/runtime/hosted.d.ts +1 -1
  33. package/dist/runtime/hosted.js +4 -4
  34. package/dist/{state-mVA2X_wa.js → state-DLqTqF6V.js} +1 -1
  35. package/dist/{types-BD-8U9zS.d.ts → types-CiuSIPR0.d.ts} +42 -22
  36. package/dist/{types-DS_rqu9l.d.ts → types-Dsbb_Pvp.d.ts} +1 -1
  37. package/dist/{vercel-region-D1CivgdA.js → vercel-region-B95MAMXN.js} +1 -1
  38. package/dist/vite.d.ts +4 -2
  39. package/dist/vite.js +4 -4
  40. package/package.json +4 -4
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @vite-hub/queue
2
2
 
3
- [![npm version](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=%40vite-hub%2Fqueue&icon=npm)](https://npmx.dev/package/@vite-hub/queue)
4
- [![npm downloads](https://comark-ui.onmax.me/badge.svg?source=npm-downloads&package=%40vite-hub%2Fqueue&period=month&icon=npm)](https://npmx.dev/package/@vite-hub/queue)
5
- [![license](https://comark-ui.onmax.me/badge.svg?label=license&value=Apache-2.0)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
6
- [![docs](https://comark-ui.onmax.me/badge.svg?label=docs&value=vitehub.dev)](https://vitehub.dev/docs)
3
+ [![npm version](https://img.shields.io/npm/v/@vite-hub/queue)](https://npmx.dev/package/@vite-hub/queue)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@vite-hub/queue)](https://npmx.dev/package/@vite-hub/queue)
5
+ [![license](https://img.shields.io/static/v1?label=license&message=Apache-2.0&color=blue)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
6
+ [![docs](https://img.shields.io/static/v1?label=docs&message=vitehub.dev&color=blue)](https://vitehub.dev/docs)
7
7
 
8
8
  `@vite-hub/queue` discovers background job handlers during a Vite build and connects `sendQueue()` to Cloudflare Queues, Vercel Queues, or a Node server that runs the jobs from Postgres or from local files. In `vite dev`, every app runs its jobs in the dev server, so you can test a handler without an account. A successful enqueue means the provider accepted the job. It does not mean the handler finished.
9
9
 
@@ -16,7 +16,7 @@ pnpm add @vite-hub/queue
16
16
  pnpm add -D @vite-hub/cli vite
17
17
  ```
18
18
 
19
- The package requires Node.js 22.19 or newer. Vite is an optional peer dependency and is required for definition discovery and provider output. The ViteHub CLI provides the `vitehub provision` command used by the host guides.
19
+ The package requires Node.js 24.15 or newer. Vite is an optional peer dependency and is required for definition discovery and provider output. The ViteHub CLI provides the `vitehub provision` command used by the host guides.
20
20
 
21
21
  For Vercel Queues, also install the provider package and the ambient types used by generated functions:
22
22
 
@@ -35,8 +35,10 @@ Define the handler in a discoverable file:
35
35
  // src/welcome-email.queue.ts
36
36
  import { defineQueue } from "@vite-hub/queue";
37
37
 
38
- export default defineQueue<{ email: string }>(async ({ payload }) => {
39
- console.log(`Send welcome email to ${payload.email}`);
38
+ export default defineQueue<{ email: string }>({
39
+ handler: async ({ payload }) => {
40
+ console.log(`Send welcome email to ${payload.email}`);
41
+ },
40
42
  });
41
43
  ```
42
44
 
@@ -85,14 +87,14 @@ That build proves discovery and generated output only. In the built Worker, `sen
85
87
 
86
88
  | Provider | Choose it when | Generated output | Enqueue options |
87
89
  | ---------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------- |
88
- | Cloudflare | The deployed runtime supplies request-scoped Cloudflare Queue bindings | Worker bundle and `wrangler.json` producer and consumer entries | `contentType`, `delaySeconds` |
89
- | Vercel | The deployment runs Vercel Queue callbacks and has a Queue region when the installed SDK requires one | One Nitro route per Queue Definition, with a Vercel queue trigger | `delaySeconds`, `idempotencyKey`, `region`, `retentionSeconds` |
90
- | Local | One Node server runs the jobs: `node .output/server/index.mjs`, Docker, or a WebContainer | A Nitro plugin that runs stored jobs in the server process | `delaySeconds`, `idempotencyKey` |
91
- | Postgres | One or more Node servers share a Postgres database | A Nitro plugin that starts workers in each server process | `delaySeconds`, `idempotencyKey` |
90
+ | Cloudflare | The deployed runtime supplies request-scoped Cloudflare Queue bindings | Worker bundle and `wrangler.json` producer and consumer entries | `contentType`, `delay` |
91
+ | Vercel | The deployment runs Vercel Queue callbacks and has a Queue region when the installed SDK requires one | One Nitro route per Queue Definition, with a Vercel queue trigger | `delay`, `idempotencyKey`, `region`, `retention` |
92
+ | Local | One Node server runs the jobs: `node .output/server/index.mjs`, Docker, or a WebContainer | A Nitro plugin that runs stored jobs in the server process | `delay`, `idempotencyKey` |
93
+ | Postgres | One or more Node servers share a Postgres database | A Nitro plugin that starts workers in each server process | `delay`, `idempotencyKey` |
92
94
 
93
95
  The ViteHub framework host selects Cloudflare for `host: "cloudflare"` and Vercel for `host: "vercel"`. For `host: "node"` and a Nitro `node-server` preset, it selects the postgres driver when the app has a Postgres Default Database, else the local driver. `vitehub({ queue: { driver: "postgres" } })` or `{ driver: "local" }` picks one on Node. Set `driver` explicitly when host inference would be ambiguous. Netlify cannot infer one. ViteHub provides no Queue driver for Deno. Check the [runtime and host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix) before choosing a deployment target.
94
96
 
95
- Cloudflare needs a concrete request-scoped binding at runtime. Its generated queue resources can be created through the ViteHub Cloudflare provision step when the required account credentials are present. Cloudflare rejects Vercel-only options such as `idempotencyKey`, `region`, and `retentionSeconds`.
97
+ Cloudflare needs a concrete request-scoped binding at runtime. Its generated queue resources can be created through the ViteHub Cloudflare provision step when the required account credentials are present. Cloudflare rejects Vercel-only options such as `idempotencyKey`, `region`, and `retention`.
96
98
 
97
99
  Vercel needs a generated topic and the `@vercel/queue` runtime. It rejects Cloudflare's `contentType` option. The [Vercel host guide](https://vitehub.dev/docs/frameworks-hosts/vercel) explains the generated Build Output boundary.
98
100
 
@@ -121,7 +123,7 @@ When a production server reopens a dev store, it redacts stored errors without a
121
123
  - A failed job runs again after 1, 2, and 4 seconds. After 4 attempts, or after a Queue error that a retry cannot fix, it becomes a dead job. A dead job stays in its file with the last error. The provider keeps the 100 newest dead jobs of each Queue Definition.
122
124
  - The server writes the attempt count before the handler runs. A job whose handler was running when the process stopped runs again after the restart. If that was the fourth attempt, the job becomes a dead job instead.
123
125
  - Delivery is at least once. A successful handler can run again after a restart if the process stops before completion is saved, or if both deleting the job and saving its completed state fail. Make handler side effects idempotent.
124
- - `delaySeconds` survives a restart. `idempotencyKey` returns the message ID of a pending or running job with the same key. A dead job does not hold its key. `sendBatch()` stores all jobs or none.
126
+ - `delay` survives a restart. `idempotencyKey` returns the message ID of a pending or running job with the same key. A dead job does not hold its key. `sendBatch()` stores all jobs or none.
125
127
  - The jobs survive a restart on the same disk. Another host, a new container, or an ephemeral filesystem does not have them. Run one server process per directory: there is no lock between processes, so two processes can run the same job.
126
128
  - `onError` and `callbackOptions` are Cloudflare and Vercel options. The local provider does not call them.
127
129
 
@@ -146,7 +148,7 @@ export default defineConfig({
146
148
  - The first server creates the table and its indexes under `pg_advisory_xact_lock`, so servers that start at the same time do not race.
147
149
  - Workers claim jobs with `UPDATE ... WHERE id IN (SELECT ... FOR UPDATE SKIP LOCKED)`. A send wakes the workers with `NOTIFY`. Without it, each worker checks every second.
148
150
  - A claim holds a job for 30 seconds, and a running handler renews it. When a process stops during a handler, another instance runs the job again with the next attempt number after the claim ends.
149
- - Retries, dead jobs, `delaySeconds`, `idempotencyKey`, `sendBatch()`, and `concurrency` follow the local rules above. `concurrency` applies per process.
151
+ - Retries, dead jobs, `delay`, `idempotencyKey`, `sendBatch()`, and `concurrency` follow the local rules above. `concurrency` applies per process.
150
152
  - When Nitro closes, the workers stop taking jobs and wait up to 10 seconds for the running jobs.
151
153
  - `vitehub queue list` shows the table and its database without the password, and `durability: "shared"`. `vitehub queue jobs` and the Console read the table, so any instance shows the jobs of all instances.
152
154
  - `vite dev` runs the jobs of a postgres app with the local provider and the same rules, so development needs no Postgres.
@@ -161,11 +163,11 @@ The dev server follows the documented defaults of the provider of the build, so
161
163
  | --- | --- | --- | --- |
162
164
  | Attempts | 4 (`max_retries` 3) | No limit until the job expires | 4 |
163
165
  | Retry delay | None | 60 seconds (`retryAfterSeconds`) | 1, 2, then 4 seconds |
164
- | Largest `delaySeconds` | 86400 (24 hours) | 604800 (7 days) | No limit |
165
- | Retention | None | `retentionSeconds` from 60 to 604800, default 86400 | None |
166
+ | Largest `delay` | `"24h"` (86400 seconds) | `"7d"` (604800 seconds) | No limit |
167
+ | Retention | None | `retention` from `"1m"` to `"7d"`, default `"1d"` | None |
166
168
  | Largest payload | 128 KB of JSON | 100 MB of JSON | No limit |
167
169
  | Largest `sendBatch()` | 100 jobs, 256 KB | 100 jobs | No limit |
168
- | Rejected options | `idempotencyKey`, `region`, `retentionSeconds` | `contentType` | `contentType`, `region`, `retentionSeconds` |
170
+ | Rejected options | `idempotencyKey`, `region`, `retention` | `contentType` | `contentType`, `region`, `retention` |
169
171
 
170
172
  The sources are the [Cloudflare Queues limits](https://developers.cloudflare.com/queues/platform/limits/), [Cloudflare batching and retries](https://developers.cloudflare.com/queues/configuration/batching-retries/), the [Vercel Queues concepts](https://vercel.com/docs/queues/concepts), and the [Vercel Queues limits](https://vercel.com/docs/queues/pricing#limits). A broken limit fails `sendQueue()` with `QUEUE_PROVIDER_FAILED`, and `error.cause` names the limit. A rejected option fails with `QUEUE_UNSUPPORTED_OPTION` and names the provider of the build.
171
173
 
@@ -260,7 +262,7 @@ The Vite Integration writes `.vitehub/queue.d.ts`. Include that file in your Typ
260
262
  ```ts
261
263
  import { sendQueue, useQueue } from "@vite-hub/queue"
262
264
 
263
- const [error] = await sendQueue("welcome-email", { email: "ada@example.com" }, { delaySeconds: 60 })
265
+ const [error] = await sendQueue("welcome-email", { email: "ada@example.com" }, { delay: "1m" })
264
266
  const queue = await useQueue("welcome-email")
265
267
  const [sendError] = await queue.send({ email: "ada@example.com" })
266
268
  ```
@@ -1,8 +1,8 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
2
- import { i as normalizePublicQueueIdentifier, l as normalizeQueueEnqueueInput, n as isQueueError, s as queueUnsupportedOptionsError } from "./errors-DL3pcNO4.js";
3
- import { a as getQueueRuntimeEvent, c as loadQueueDefinition, g as resolveWaitUntil, i as getQueueRuntimeConfig, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, u as runWithQueueRuntimeEvent, v as getCloudflareEnv } from "./state-mVA2X_wa.js";
4
- import { n as normalizeQueueOptions } from "./config-BcTDeQIP.js";
5
- import { t as resolveVercelQueueRegion } from "./vercel-region-D1CivgdA.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
2
+ import { a as normalizePublicQueueIdentifier, c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, r as isQueueError, t as readQueueTimes } from "./duration-tujyhAKt.js";
3
+ import { a as getQueueRuntimeEvent, c as loadQueueDefinition, g as resolveWaitUntil, i as getQueueRuntimeConfig, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, u as runWithQueueRuntimeEvent, v as getCloudflareEnv } from "./state-DLqTqF6V.js";
4
+ import { n as normalizeQueueOptions } from "./config-B2eaXaT5.js";
5
+ import { t as resolveVercelQueueRegion } from "./vercel-region-B95MAMXN.js";
6
6
  import { t as getCloudflareQueueBindingName } from "./cloudflare-GosJefIK.js";
7
7
  import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
8
8
  import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
@@ -38,17 +38,19 @@ function createTestQueueClient(test, queue, provider) {
38
38
  queue,
39
39
  async send(payload, options) {
40
40
  const input = normalizeQueueEnqueueInput(payload, options);
41
- const error = queueUnsupportedOptionsError(input.options, provider);
41
+ const error = queueUnsupportedOptionsError(input.options, provider) ?? readQueueTimes(input.options)[0];
42
42
  if (error) return [error, void 0];
43
43
  return [void 0, recordQueueTestMessage(test, queue, input)];
44
44
  },
45
45
  async sendBatch(items, options = {}) {
46
+ const removed = queueRemovedOptionsError(provider, options, items);
47
+ if (removed) return [removed, void 0];
46
48
  const inputs = items.map(({ body, ...itemOptions }) => normalizeQueueEnqueueInput(body, {
47
49
  ...options,
48
50
  ...Object.fromEntries(Object.entries(itemOptions).filter(([, value]) => value !== void 0))
49
51
  }));
50
52
  for (const input of inputs) {
51
- const error = queueUnsupportedOptionsError(input.options, provider);
53
+ const error = queueUnsupportedOptionsError(input.options, provider) ?? readQueueTimes(input.options)[0];
52
54
  if (error) return [error, void 0];
53
55
  }
54
56
  return [void 0, inputs.map((input) => recordQueueTestMessage(test, queue, input))];
@@ -119,7 +121,7 @@ async function useDynamicQueue(name) {
119
121
  if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: normalizePublicQueueIdentifier(name) });
120
122
  const test = getViteHubTestMode();
121
123
  if (test) return createTestQueueClient(test, name, config.driver === "local" ? config.rules ?? "local" : config.driver);
122
- if (definition.options?.cache === false || config.cache === false || config.driver === "cloudflare" || config.driver === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
124
+ if (definition.cache === false || config.cache === false || config.driver === "cloudflare" || config.driver === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
123
125
  return await getOrCreateQueueClient(name, () => createNamedQueueClient(name));
124
126
  }
125
127
  async function sendDynamicQueue(name, payload, options) {
@@ -141,7 +143,7 @@ function deferDynamicQueue(name, payload, options) {
141
143
  const handleError = async (error) => {
142
144
  console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
143
145
  try {
144
- await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
146
+ await (await loadNamedQueueDefinition(name))?.onDispatchError?.(error, { name });
145
147
  } catch (hookError) {
146
148
  console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
147
149
  }
@@ -1,7 +1,8 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
2
- import { l as normalizeQueueEnqueueInput, o as queueProviderResult, s as queueUnsupportedOptionsError } from "./errors-DL3pcNO4.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
2
+ import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes } from "./duration-tujyhAKt.js";
3
3
  import { n as getCloudflareQueueDefinitionName } from "./cloudflare-GosJefIK.js";
4
- import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-By0Fpspv.js";
4
+ import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-B6lz9nCn.js";
5
+ import { parseDuration } from "@vite-hub/runtime";
5
6
  //#region src/providers/cloudflare.ts
6
7
  const cloudflareBindingName = /^[A-Z_]\w{0,127}$/i;
7
8
  function isCloudflareQueueBinding(binding) {
@@ -40,14 +41,20 @@ function isCloudflareQueueBinding(binding) {
40
41
  function toSendOptions(options = {}) {
41
42
  const error = queueUnsupportedOptionsError(options, "cloudflare");
42
43
  if (error) return [error, void 0];
44
+ const [timeError, times] = readQueueTimes(options, "ceil");
45
+ if (timeError) return [timeError, void 0];
43
46
  return [void 0, {
44
47
  contentType: options.contentType,
45
- delaySeconds: options.delaySeconds
48
+ delaySeconds: times.delaySeconds
46
49
  }];
47
50
  }
51
+ /** Runs the action that `onError` returned. A `delay` that is not a duration throws, and the caller retries at once. */
48
52
  function resolveAction(action, message, fallback) {
49
53
  if (action && typeof action === "object" && !Array.isArray(action) && Object.hasOwn(action, "retry")) {
50
- message.retry(action.retry);
54
+ const removed = queueRemovedOptionsError("cloudflare", action.retry);
55
+ if (removed) throw removed;
56
+ const delay = action.retry?.delay;
57
+ message.retry(delay === void 0 ? void 0 : { delaySeconds: Math.ceil(parseDuration(delay, "delay", void 0, "s") / 1e3) });
51
58
  return;
52
59
  }
53
60
  if ((action === "ack" || action === "retry" ? action : fallback) === "ack") message.ack();
@@ -80,7 +87,12 @@ function createCloudflareQueueBatchHandler(options) {
80
87
  } catch (hookError) {
81
88
  reportQueueDeliveryError(hookError, reportContext);
82
89
  }
83
- resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry");
90
+ try {
91
+ resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry");
92
+ } catch (actionError) {
93
+ reportQueueDeliveryError(actionError, reportContext);
94
+ message.retry();
95
+ }
84
96
  }
85
97
  }
86
98
  };
@@ -107,16 +119,18 @@ function createCloudflareQueueClient(provider) {
107
119
  return [void 0, { status: "queued" }];
108
120
  },
109
121
  async sendBatch(items, options) {
122
+ const removed = queueRemovedOptionsError("cloudflare", options, items);
123
+ if (removed) return [removed, void 0];
110
124
  const messages = [];
111
125
  for (const item of items) {
112
126
  const [optionsError, sendOptions] = toSendOptions({
113
127
  ...options,
114
128
  contentType: item.contentType || options?.contentType,
115
- delaySeconds: item.delaySeconds ?? options?.delaySeconds
129
+ delay: item.delay ?? options?.delay
116
130
  });
117
131
  if (optionsError) return [optionsError, void 0];
118
132
  messages.push({
119
- ...item,
133
+ body: item.body,
120
134
  ...sendOptions
121
135
  });
122
136
  }
@@ -1,4 +1,4 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
2
2
  import { r as encodeNameHex } from "./cloudflare-GosJefIK.js";
3
3
  //#region src/internal/cloudflare-resource-name.ts
4
4
  const cloudflareQueueNamePrefix = "queue--";
@@ -1,5 +1,5 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
2
1
  import { n as isRecord } from "./object-D8pRdprI.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
3
3
  import { defu } from "defu";
4
4
  /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
5
5
  function hostFromNitroPreset(value) {
@@ -1,4 +1,5 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
2
+ import { parseDuration, runtimeErrorDiagnostics, toResultError } from "@vite-hub/runtime";
2
3
  //#region src/enqueue.ts
3
4
  let fallbackCounter = 0;
4
5
  function createQueueMessageId(prefix = "queue") {
@@ -20,12 +21,12 @@ function normalizeQueueEnqueueInput(payload, options = {}) {
20
21
  const cloudflareUnsupportedEnqueueOptions = [
21
22
  "idempotencyKey",
22
23
  "region",
23
- "retentionSeconds"
24
+ "retention"
24
25
  ];
25
26
  const localUnsupportedEnqueueOptions = [
26
27
  "contentType",
27
28
  "region",
28
- "retentionSeconds"
29
+ "retention"
29
30
  ];
30
31
  const postgresUnsupportedEnqueueOptions = localUnsupportedEnqueueOptions;
31
32
  const unsupportedEnqueueOptions = {
@@ -34,9 +35,21 @@ const unsupportedEnqueueOptions = {
34
35
  postgres: postgresUnsupportedEnqueueOptions,
35
36
  vercel: ["contentType"]
36
37
  };
38
+ const removedEnqueueOptions = [
39
+ "delaySeconds",
40
+ "id",
41
+ "retentionSeconds"
42
+ ];
43
+ function queueRemovedOptionsError(provider, options, items = []) {
44
+ const removed = removedEnqueueOptions.filter((name) => options && Object.hasOwn(options, name) || items.some((item) => Object.hasOwn(item, name)));
45
+ if (removed.length) return queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
46
+ options: formatQueueOptionNames(removed),
47
+ provider
48
+ });
49
+ }
37
50
  /** Shared pre-dispatch option validation for provider clients and the test backend. */
38
51
  function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqueueOptions[provider]) {
39
- const unsupported = [...Object.hasOwn(options, "id") ? ["id"] : [], ...names.filter((option) => options[option] !== void 0)];
52
+ const unsupported = [...removedEnqueueOptions.filter((option) => Object.hasOwn(options, option)), ...names.filter((option) => options[option] !== void 0)];
40
53
  return unsupported.length ? queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
41
54
  options: formatQueueOptionNames(unsupported),
42
55
  provider
@@ -46,7 +59,7 @@ function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqu
46
59
  function isQueueError(error, codes) {
47
60
  return queueErrorDiagnostics.is(error) && (!codes || codes.some((code) => code === error.code));
48
61
  }
49
- /** Formats option names for an error `why`, for example `"region" and "retentionSeconds"`. */
62
+ /** Formats option names for an error `why`, for example `"region" and "retention"`. */
50
63
  function formatQueueOptionNames(names) {
51
64
  const quoted = names.map((name) => `\`${name}\``);
52
65
  return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}` : quoted.join("");
@@ -74,4 +87,25 @@ async function queueProviderResult(provider, operation, run) {
74
87
  }
75
88
  }
76
89
  //#endregion
77
- export { postgresUnsupportedEnqueueOptions as a, createQueueMessageId as c, normalizePublicQueueIdentifier as i, normalizeQueueEnqueueInput as l, isQueueError as n, queueProviderResult as o, localUnsupportedEnqueueOptions as r, queueUnsupportedOptionsError as s, cloudflareUnsupportedEnqueueOptions as t };
90
+ //#region src/duration.ts
91
+ /**
92
+ * Reads `delay` and `retention` of a send. `delay` is a duration such as `"1m"`. `retention` is a duration or a number
93
+ * of seconds. A value that is not a duration returns `RUNTIME_DURATION_INVALID`. Pass `"ceil"` for a provider that
94
+ * takes whole seconds, so a job never runs earlier than the caller asked.
95
+ */
96
+ function readQueueTimes(options, round) {
97
+ const seconds = (milliseconds) => round === "ceil" ? Math.ceil(milliseconds / 1e3) : milliseconds / 1e3;
98
+ try {
99
+ const delaySeconds = options.delay === void 0 ? void 0 : seconds(parseDuration(options.delay, "delay", void 0, "s"));
100
+ const retentionSeconds = typeof options.retention === "number" ? round === "ceil" ? Math.ceil(options.retention) : options.retention : options.retention === void 0 ? void 0 : seconds(parseDuration(options.retention, "retention"));
101
+ return [void 0, {
102
+ ...delaySeconds === void 0 ? {} : { delaySeconds },
103
+ ...retentionSeconds === void 0 ? {} : { retentionSeconds }
104
+ }];
105
+ } catch (error) {
106
+ if (runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID.is(error)) return [toResultError(error), void 0];
107
+ throw error;
108
+ }
109
+ }
110
+ //#endregion
111
+ export { normalizePublicQueueIdentifier as a, queueRemovedOptionsError as c, normalizeQueueEnqueueInput as d, localUnsupportedEnqueueOptions as i, queueUnsupportedOptionsError as l, cloudflareUnsupportedEnqueueOptions as n, postgresUnsupportedEnqueueOptions as o, isQueueError as r, queueProviderResult as s, readQueueTimes as t, createQueueMessageId as u };
@@ -170,7 +170,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
170
170
  },
171
171
  INTERNAL_R0004: {
172
172
  ...dynamicError,
173
- fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
173
+ fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
174
174
  },
175
175
  INTERNAL_R0005: {
176
176
  ...dynamicError,
@@ -216,6 +216,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
216
216
  why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
217
217
  fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
218
218
  },
219
+ INTERNAL_DEV_SERVER_NOT_FOUND: {
220
+ why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
221
+ fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
222
+ },
219
223
  INTERNAL_FORGE_NOT_INSTALLED: {
220
224
  why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
221
225
  fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
@@ -13,19 +13,19 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
13
13
  },
14
14
  QUEUE_UNSUPPORTED_OPTION: {
15
15
  why: ({ options, provider }) => `The ${provider} queue provider does not support the enqueue option ${options}.`,
16
- fix: ({ options }) => options.includes("`id`") ? "Remove `id`. ViteHub generates the message ID. To deduplicate sends, pass `idempotencyKey` on a provider that supports it." : "Remove the option for this provider. The enqueue options table on the Queue Server API page shows which provider supports each option."
16
+ fix: ({ options }) => options.includes("Seconds`") ? "Rename `delaySeconds` to `delay` and `retentionSeconds` to `retention`, and write the time as a duration: `{ delay: \"60s\" }` in place of `{ delaySeconds: 60 }`. `vitehub migrate` renames them." : options.includes("`id`") ? "Remove `id`. ViteHub generates the message ID. To deduplicate sends, pass `idempotencyKey` on a provider that supports it." : "Remove the option for this provider. The enqueue options table on the Queue Server API page shows which provider supports each option."
17
17
  },
18
18
  QUEUE_LOCAL_LIMIT_EXCEEDED: {
19
19
  why: ({ limit, max, min, provider, value }) => ({
20
20
  "batch-bytes": `${provider} accepts up to ${max} bytes in one \`sendBatch()\`, got ${value} bytes of JSON.`,
21
21
  "batch-empty": "Vercel requires at least one job in a `sendBatch()`.",
22
22
  "batch-jobs": `${provider} accepts up to ${max} jobs in one \`sendBatch()\`, got ${value}.`,
23
- "delay": `\`delaySeconds\` must be a number of seconds from 0, got ${value}.`,
24
- "delay-max": `${provider} accepts \`delaySeconds\` up to ${max}, got ${value}.`,
23
+ "delay": `\`delay\` must be a time from 0, got ${value} seconds.`,
24
+ "delay-max": `${provider} accepts a \`delay\` of up to ${max} seconds, got ${value} seconds.`,
25
25
  "payload": `${provider} accepts a payload of up to ${max} bytes, got ${value} bytes of JSON.`,
26
- "retention": `${provider} accepts \`retentionSeconds\` from ${min} to ${max}, got ${value}.`
26
+ "retention": `${provider} accepts a \`retention\` from ${min} to ${max} seconds, got ${value} seconds.`
27
27
  })[limit],
28
- fix: "Change the job as the message says: `delaySeconds`, `retentionSeconds`, the payload size, or the number or size of the jobs in one `sendBatch()`. The local provider applies the limits of the production provider, so the same job fails there too."
28
+ fix: "Change the job as the message says: `delay`, `retention`, the payload size, or the number or size of the jobs in one `sendBatch()`. The local provider applies the limits of the production provider, so the same job fails there too."
29
29
  },
30
30
  QUEUE_VERCEL_BATCH_REJECTED: {
31
31
  why: ({ failed, total }) => `@vercel/queue did not accept ${failed} of ${total} batch messages.`,
@@ -144,8 +144,8 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
144
144
  fix: "Pass an object, for example `queue: { driver: 'cloudflare' }`."
145
145
  },
146
146
  QUEUE_INVALID_DEFINITION: {
147
- why: "`defineQueue()` needs a handler function.",
148
- fix: "Pass the handler as the first argument, for example `defineQueue(async (job) => { ... })`."
147
+ why: ({ reason }) => reason,
148
+ fix: "Pass one object with a `handler` function and the options next to it, for example `defineQueue({ handler: async ({ payload }) => { ... }, concurrency: 2 })`. Run `npx vitehub migrate` to move the former `defineQueue(handler, options)` form."
149
149
  },
150
150
  QUEUE_INVALID_DRIVER: {
151
151
  why: ({ driver }) => `\`queue.driver\` "${driver}" is not a Queue driver.`,
@@ -1,4 +1,4 @@
1
- import { i as normalizePublicQueueIdentifier, n as isQueueError } from "./errors-DL3pcNO4.js";
1
+ import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-tujyhAKt.js";
2
2
  import { getViteHubErrorShape, toResponse } from "@vite-hub/runtime";
3
3
  //#region src/internal/delivery-error.ts
4
4
  const retryableQueueCodes = /* @__PURE__ */ new Set(["QUEUE_PROVIDER_FAILED", "QUEUE_PROVIDER_INVALID_RESPONSE"]);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
- import { A as QueueModuleDriverOptions, B as VercelQueueClient, C as QueueDriver, D as QueueHandler, E as QueueErrorCode, F as QueueSendResult, G as VercelQueueSendBatchOptions, H as VercelQueueRetryDirective, I as ResolvedLocalQueueOptions, K as VercelQueueSendResult, L as ResolvedQueueOptions, M as QueueOptions, N as QueuePayload, O as QueueJob, P as QueueRegistry, R as VercelQueueBatchSendResult, S as QueueDefinitionRegistry, T as QueueEnqueueOptions, U as VercelQueueRetryHandler, V as VercelQueueErrorCode, W as VercelQueueSendBatchMessage, _ as PostgresQueueDriverOptions, a as CloudflareQueueMessageBatch, b as QueueDefinition, c as LocalQueueDriverOptions, f as LocalQueueRules, g as PostgresQueueClient, h as NodeQueueDriver, i as CloudflareQueueMessage, j as QueueName, k as QueueJobStore, l as LocalQueueErrorCode, n as CloudflareQueueClient, o as DiscoveredQueueDefinition, p as LocalQueueSendBatchMessage, r as CloudflareQueueErrorCode, s as LocalQueueClient, t as CloudflareQueueBatchHandlerOptions, v as PostgresQueueErrorCode, w as QueueDriverOptions, x as QueueDefinitionOptions, y as QueueClient, z as VercelQueueCallbackOptions } from "./types-BD-8U9zS.js";
1
+ import { A as QueueJobStore, B as VercelQueueCallbackOptions, C as QueueDefinitionRegistry, D as QueueErrorCode, E as QueueEnqueueOptions, F as QueueRegistry, G as VercelQueueSendBatchMessage, H as VercelQueueErrorCode, I as QueueSendResult, K as VercelQueueSendBatchOptions, L as ResolvedLocalQueueOptions, M as QueueName, N as QueueOptions, O as QueueHandler, P as QueuePayload, R as ResolvedQueueOptions, S as QueueDefinitionOptions, T as QueueDriverOptions, U as VercelQueueRetryDirective, V as VercelQueueClient, W as VercelQueueRetryHandler, _ as PostgresQueueClient, a as CloudflareQueueMessageBatch, b as QueueClient, c as LocalQueueClient, g as NodeQueueDriver, i as CloudflareQueueMessage, j as QueueModuleDriverOptions, k as QueueJob, l as LocalQueueDriverOptions, m as LocalQueueSendBatchMessage, n as CloudflareQueueClient, o as CloudflareQueueSendBatchItem, p as LocalQueueRules, q as VercelQueueSendResult, r as CloudflareQueueErrorCode, s as DiscoveredQueueDefinition, t as CloudflareQueueBatchHandlerOptions, u as LocalQueueErrorCode, v as PostgresQueueDriverOptions, w as QueueDriver, x as QueueDefinition, y as PostgresQueueErrorCode, z as VercelQueueBatchSendResult } from "./types-CiuSIPR0.js";
2
2
  import { Result } from "@vite-hub/runtime";
3
3
  //#region src/definition.d.ts
4
- export declare function defineQueue<TPayload = unknown, TResult = unknown>(handler: QueueHandler<TPayload, TResult>, options?: QueueDefinitionOptions): QueueDefinition<TPayload, TResult>;
4
+ /**
5
+ * Defines a Queue from one object: `defineQueue({ handler, concurrency })`. The handler receives one object,
6
+ * `{ payload, id, attempts, metadata }`. The payload type of `handler` types `sendQueue()` for this Queue.
7
+ */
8
+ export declare function defineQueue<TPayload = unknown, TResult = unknown>(definition: QueueDefinition<TPayload, TResult>): QueueDefinition<TPayload, TResult>;
5
9
  //#endregion
6
10
  //#region src/enqueue.d.ts
7
11
  export declare function createQueueMessageId(prefix?: string): string;
@@ -34,4 +38,4 @@ export declare function deferQueue<TName extends QueueName>(name: TName, payload
34
38
  //#region src/runtime/create-client.d.ts
35
39
  export declare function createQueueClient(options: QueueDriverOptions): Promise<QueueClient>;
36
40
  //#endregion
37
- export type { CloudflareQueueBatchHandlerOptions, CloudflareQueueClient, CloudflareQueueErrorCode, CloudflareQueueMessage, CloudflareQueueMessageBatch, DiscoveredQueueDefinition, LocalQueueClient, LocalQueueDriverOptions, LocalQueueErrorCode, LocalQueueRules, LocalQueueSendBatchMessage, NodeQueueDriver, PostgresQueueClient, PostgresQueueDriverOptions, PostgresQueueErrorCode, QueueClient, QueueDefinition, QueueDefinitionOptions, QueueDefinitionRegistry, QueueDriver, QueueDriverOptions, QueueEnqueueOptions, QueueErrorCode, QueueHandler, QueueJob, QueueJobStore, QueueModuleDriverOptions, QueueName, QueueOptions, QueuePayload, QueueRegistry, QueueSendResult, ResolvedLocalQueueOptions, ResolvedQueueOptions, VercelQueueBatchSendResult, VercelQueueCallbackOptions, VercelQueueClient, VercelQueueErrorCode, VercelQueueRetryDirective, VercelQueueRetryHandler, VercelQueueSendBatchMessage, VercelQueueSendBatchOptions, VercelQueueSendResult };
41
+ export type { CloudflareQueueBatchHandlerOptions, CloudflareQueueClient, CloudflareQueueErrorCode, CloudflareQueueMessage, CloudflareQueueMessageBatch, CloudflareQueueSendBatchItem, DiscoveredQueueDefinition, LocalQueueClient, LocalQueueDriverOptions, LocalQueueErrorCode, LocalQueueRules, LocalQueueSendBatchMessage, NodeQueueDriver, PostgresQueueClient, PostgresQueueDriverOptions, PostgresQueueErrorCode, QueueClient, QueueDefinition, QueueDefinitionOptions, QueueDefinitionRegistry, QueueDriver, QueueDriverOptions, QueueEnqueueOptions, QueueErrorCode, QueueHandler, QueueJob, QueueJobStore, QueueModuleDriverOptions, QueueName, QueueOptions, QueuePayload, QueueRegistry, QueueSendResult, ResolvedLocalQueueOptions, ResolvedQueueOptions, VercelQueueBatchSendResult, VercelQueueCallbackOptions, VercelQueueClient, VercelQueueErrorCode, VercelQueueRetryDirective, VercelQueueRetryHandler, VercelQueueSendBatchMessage, VercelQueueSendBatchOptions, VercelQueueSendResult };
package/dist/index.js CHANGED
@@ -1,13 +1,23 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
2
- import { c as createQueueMessageId } from "./errors-DL3pcNO4.js";
3
- import { i as useQueue, n as dynamicQueue, r as sendQueue, t as deferQueue } from "./client-Cj50hQYp.js";
1
+ import { n as isRecord } from "./object-D8pRdprI.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
3
+ import { u as createQueueMessageId } from "./duration-tujyhAKt.js";
4
+ import { i as useQueue, n as dynamicQueue, r as sendQueue, t as deferQueue } from "./client-B53_G4ky.js";
4
5
  //#region src/definition.ts
5
- function defineQueue(handler, options) {
6
- if (typeof handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION();
7
- return {
8
- handler,
9
- options
10
- };
6
+ const queueDefinitionKeys = /* @__PURE__ */ new Set([
7
+ "cache",
8
+ "callbackOptions",
9
+ "concurrency",
10
+ "handler",
11
+ "onDispatchError",
12
+ "onError"
13
+ ]);
14
+ function defineQueue(definition, ...removed) {
15
+ if (typeof definition === "function" || removed.length) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue(handler, options)` was removed." });
16
+ if (!isRecord(definition)) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` expects one object with `handler`." });
17
+ const unknownKey = Object.keys(definition).find((key) => !queueDefinitionKeys.has(key));
18
+ if (unknownKey) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: `\`defineQueue()\` does not support the "${unknownKey}" option.` });
19
+ if (!Object.hasOwn(definition, "handler") || typeof definition.handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` needs a `handler` function." });
20
+ return definition;
11
21
  }
12
22
  //#endregion
13
23
  //#region src/runtime/create-client.ts
@@ -1,4 +1,4 @@
1
- import { w as QueueDriverOptions, y as QueueClient } from "../../types-BD-8U9zS.js";
1
+ import { T as QueueDriverOptions, b as QueueClient } from "../../types-CiuSIPR0.js";
2
2
  //#region src/internal/runtime/cloudflare-client.d.ts
3
3
  export declare function createCloudflareQueueRuntimeClient(options: QueueDriverOptions): Promise<QueueClient>;
4
4
  //#endregion
@@ -1,2 +1,2 @@
1
- import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-DYsAjM8B.js";
1
+ import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-CoISDpIx.js";
2
2
  export { createCloudflareQueueRuntimeClient };
@@ -1,4 +1,4 @@
1
- import { L as ResolvedQueueOptions, S as QueueDefinitionRegistry, a as CloudflareQueueMessageBatch } from "../../types-BD-8U9zS.js";
1
+ import { C as QueueDefinitionRegistry, R as ResolvedQueueOptions, a as CloudflareQueueMessageBatch } from "../../types-CiuSIPR0.js";
2
2
  //#region ../internal/src/runtime/cloudflare-env-lookup.d.ts
3
3
  type CloudflareWorkerEnv = Record<string, unknown>;
4
4
  //#endregion
@@ -1,10 +1,10 @@
1
- import { t as queueErrorDiagnostics } from "../../error-diagnostics-BRartC1z.js";
2
- import { _ as runWithActiveCloudflareEnv, c as loadQueueDefinition, d as setQueueRuntimeConfig, h as createCloudflareRuntimeEvent, m as setQueueRuntimeRegistry, u as runWithQueueRuntimeEvent } from "../../state-mVA2X_wa.js";
3
- import { t as internalErrorDiagnostics } from "../../error-diagnostics-DSkCJC_L.js";
4
- import { n as normalizeQueueOptions } from "../../config-BcTDeQIP.js";
1
+ import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
2
+ import { _ as runWithActiveCloudflareEnv, c as loadQueueDefinition, d as setQueueRuntimeConfig, h as createCloudflareRuntimeEvent, m as setQueueRuntimeRegistry, u as runWithQueueRuntimeEvent } from "../../state-DLqTqF6V.js";
3
+ import { t as internalErrorDiagnostics } from "../../error-diagnostics-CQ4BUqRe.js";
4
+ import { n as normalizeQueueOptions } from "../../config-B2eaXaT5.js";
5
5
  import { n as getCloudflareQueueDefinitionName } from "../../cloudflare-GosJefIK.js";
6
- import { t as getCloudflareQueueName } from "../../cloudflare-resource-name-BJHYRCMQ.js";
7
- import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-DYsAjM8B.js";
6
+ import { t as getCloudflareQueueName } from "../../cloudflare-resource-name-BIfBglC2.js";
7
+ import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-CoISDpIx.js";
8
8
  import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
9
9
  //#region ../internal/src/runtime/app.ts
10
10
  function resolveAppFetch(label, app) {
@@ -96,8 +96,8 @@ function createQueueCloudflareWorker(options = {}) {
96
96
  const definition = await loadQueueDefinition(definitionName);
97
97
  if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: definitionName });
98
98
  await createCloudflareQueueBatchHandler({
99
- concurrency: definition.options?.concurrency,
100
- onError: definition.options?.onError,
99
+ concurrency: definition.concurrency,
100
+ onError: definition.onError,
101
101
  onMessage: async (message, currentBatch) => {
102
102
  await runWithQueueRuntimeEvent(runtimeEvent, async () => {
103
103
  await runInRunScopes(() => definition.handler(createQueueJob(message, currentBatch)));
@@ -1,6 +1,6 @@
1
- import { m as LocalQueueStatus, y as QueueClient } from "../../types-BD-8U9zS.js";
2
- import { t as LocalQueueEngine } from "../../local-CVVRVWeR.js";
3
- import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-DS_rqu9l.js";
1
+ import { b as QueueClient, h as LocalQueueStatus } from "../../types-CiuSIPR0.js";
2
+ import { t as LocalQueueEngine } from "../../local-CUaWoRUx.js";
3
+ import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-Dsbb_Pvp.js";
4
4
  //#region src/internal/runtime/local-client.d.ts
5
5
  export declare function createLocalQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
6
6
  /**
@@ -1,7 +1,7 @@
1
- import { t as queueErrorDiagnostics } from "../../error-diagnostics-BRartC1z.js";
2
- import { c as loadQueueDefinition, l as missingQueueDefinitionError } from "../../state-mVA2X_wa.js";
3
- import { t as defaultLocalQueueBase } from "../../config-BcTDeQIP.js";
4
- import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-CGckW5nr.js";
1
+ import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
2
+ import { c as loadQueueDefinition, l as missingQueueDefinitionError } from "../../state-DLqTqF6V.js";
3
+ import { t as defaultLocalQueueBase } from "../../config-B2eaXaT5.js";
4
+ import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-Di0FrVUw.js";
5
5
  import { resolve } from "pathe";
6
6
  //#region src/internal/runtime/local-client.ts
7
7
  const engines = /* @__PURE__ */ new Map();
@@ -1,6 +1,6 @@
1
- import { y as QueueClient } from "../../types-BD-8U9zS.js";
2
- import "../../local-CVVRVWeR.js";
3
- import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-DS_rqu9l.js";
1
+ import { b as QueueClient } from "../../types-CiuSIPR0.js";
2
+ import "../../local-CUaWoRUx.js";
3
+ import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-Dsbb_Pvp.js";
4
4
  import postgres from "postgres";
5
5
  //#region src/providers/postgres.d.ts
6
6
  /** A postgres.js client. */
@@ -1,10 +1,10 @@
1
- import { t as queueErrorDiagnostics } from "../../error-diagnostics-BRartC1z.js";
2
- import { c as createQueueMessageId, l as normalizeQueueEnqueueInput, o as queueProviderResult, s as queueUnsupportedOptionsError } from "../../errors-DL3pcNO4.js";
3
- import { c as loadQueueDefinition, l as missingQueueDefinitionError, p as setQueueRuntimeJobStore, s as listQueueDefinitionNames } from "../../state-mVA2X_wa.js";
4
- import { r as postgresQueueUrlVariable } from "../../config-BcTDeQIP.js";
1
+ import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
2
+ import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "../../duration-tujyhAKt.js";
3
+ import { c as loadQueueDefinition, l as missingQueueDefinitionError, p as setQueueRuntimeJobStore, s as listQueueDefinitionNames } from "../../state-DLqTqF6V.js";
4
+ import { r as postgresQueueUrlVariable } from "../../config-B2eaXaT5.js";
5
5
  import { t as invariant } from "../../invariant-D8_xBqmZ.js";
6
- import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../../handler-response-By0Fpspv.js";
7
- import { i as localQueueDeliveryRules, r as delayMs } from "../../local-CGckW5nr.js";
6
+ import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../../handler-response-B6lz9nCn.js";
7
+ import { i as localQueueDeliveryRules, r as delayMs } from "../../local-Di0FrVUw.js";
8
8
  import { hostname } from "node:os";
9
9
  import { randomUUID } from "node:crypto";
10
10
  import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
@@ -120,7 +120,7 @@ function createPostgresQueueEngine(options) {
120
120
  if (known !== void 0) return known;
121
121
  const definition = await options.load(queue);
122
122
  if (!definition) return void 0;
123
- const limit = Number(definition.options?.concurrency ?? 1);
123
+ const limit = Number(definition.concurrency ?? 1);
124
124
  const value = Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : 1;
125
125
  concurrency.set(queue, value);
126
126
  return value;
@@ -402,8 +402,10 @@ function createPostgresQueueClient(engine, queue, resolveEngine) {
402
402
  const normalized = normalizeQueueEnqueueInput(payload, options);
403
403
  const optionsError = queueUnsupportedOptionsError(normalized.options, "postgres", engine.rules.unsupportedOptions);
404
404
  if (optionsError) return [optionsError, void 0];
405
+ const [timeError, times] = readQueueTimes(normalized.options);
406
+ if (timeError) return [timeError, void 0];
405
407
  const [error, ids] = await queueProviderResult("postgres", "send", () => enqueue([{
406
- delaySeconds: normalized.options.delaySeconds,
408
+ delaySeconds: times.delaySeconds,
407
409
  id: normalized.id,
408
410
  idempotencyKey: normalized.options.idempotencyKey,
409
411
  payload: normalized.payload
@@ -415,12 +417,20 @@ function createPostgresQueueClient(engine, queue, resolveEngine) {
415
417
  }];
416
418
  },
417
419
  async sendBatch(items, options) {
418
- const [error, ids] = await queueProviderResult("postgres", "send-batch", () => enqueue(items.map((item) => ({
419
- delaySeconds: item.delaySeconds ?? options?.delaySeconds,
420
- id: createQueueMessageId(),
421
- idempotencyKey: item.idempotencyKey,
422
- payload: item.body
423
- }))));
420
+ const removed = queueRemovedOptionsError("postgres", options, items);
421
+ if (removed) return [removed, void 0];
422
+ const entries = [];
423
+ for (const item of items) {
424
+ const [timeError, times] = readQueueTimes({ delay: item.delay ?? options?.delay });
425
+ if (timeError) return [timeError, void 0];
426
+ entries.push({
427
+ delaySeconds: times.delaySeconds,
428
+ id: createQueueMessageId(),
429
+ idempotencyKey: item.idempotencyKey,
430
+ payload: item.body
431
+ });
432
+ }
433
+ const [error, ids] = await queueProviderResult("postgres", "send-batch", () => enqueue(entries));
424
434
  if (error) return [error, void 0];
425
435
  return [void 0, ids.map((messageId) => ({
426
436
  messageId,