@vite-hub/queue 0.3.1 → 0.5.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.
Files changed (42) hide show
  1. package/README.md +22 -20
  2. package/dist/{client-Cj50hQYp.js → client-DYE_ZV8c.js} +11 -10
  3. package/dist/{cloudflare-client-DYsAjM8B.js → cloudflare-client-BasaJ68s.js} +22 -9
  4. package/dist/{cloudflare-resource-name-BJHYRCMQ.js → cloudflare-resource-name-BUNNqgkg.js} +1 -1
  5. package/dist/{config-BcTDeQIP.js → config-YEuaeQVq.js} +1 -3
  6. package/dist/definition-BL_3WHNu.js +27 -0
  7. package/dist/{errors-DL3pcNO4.js → duration-CshzgSSx.js} +48 -6
  8. package/dist/{error-diagnostics-DSkCJC_L.js → error-diagnostics-C0KyI408.js} +10 -2
  9. package/dist/{error-diagnostics-BRartC1z.js → error-diagnostics-DukggGP6.js} +14 -10
  10. package/dist/{handler-response-By0Fpspv.js → handler-response-ChtAjPNo.js} +8 -3
  11. package/dist/index.d.ts +7 -3
  12. package/dist/index.js +4 -12
  13. package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
  14. package/dist/internal/runtime/cloudflare-client.js +1 -1
  15. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  16. package/dist/internal/runtime/cloudflare-vite.js +10 -9
  17. package/dist/internal/runtime/local-client.d.ts +3 -3
  18. package/dist/internal/runtime/local-client.js +4 -4
  19. package/dist/internal/runtime/postgres-client.d.ts +5 -4
  20. package/dist/internal/runtime/postgres-client.js +34 -17
  21. package/dist/internal/runtime/state.d.ts +2 -2
  22. package/dist/internal/runtime/state.js +1 -1
  23. package/dist/internal/runtime/vercel-client.d.ts +1 -1
  24. package/dist/internal/runtime/vercel-client.js +23 -12
  25. package/dist/internal/runtime/worker-client.d.ts +2 -2
  26. package/dist/internal/runtime/worker-client.js +1 -1
  27. package/dist/{local-CGckW5nr.js → local-CnBd5jdm.js} +50 -31
  28. package/dist/{local-CVVRVWeR.d.ts → local-DAL5ZgDg.d.ts} +2 -1
  29. package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
  30. package/dist/{operations-Crwjca91.js → operations-BL0b9pte.js} +10 -11
  31. package/dist/operations.d.ts +5 -4
  32. package/dist/operations.js +16 -48
  33. package/dist/runtime/hosted.d.ts +1 -1
  34. package/dist/runtime/hosted.js +4 -4
  35. package/dist/scan-module-BbqyaLl6.js +311 -0
  36. package/dist/{state-mVA2X_wa.js → state-ER1YdCBF.js} +1 -1
  37. package/dist/{types-DS_rqu9l.d.ts → types-D6hDNcMY.d.ts} +1 -2
  38. package/dist/{types-BD-8U9zS.d.ts → types-klaR79hV.d.ts} +50 -24
  39. package/dist/{vercel-region-D1CivgdA.js → vercel-region-DOciq2kx.js} +1 -1
  40. package/dist/vite.d.ts +10 -4
  41. package/dist/vite.js +123 -94
  42. 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
 
@@ -129,7 +131,7 @@ The server logs the directory and this durability once when it starts. `vitehub
129
131
 
130
132
  ## Run jobs on several Node servers
131
133
 
132
- The postgres driver keeps the jobs in the `vitehub_queue_jobs` table, and every server process of the app takes due jobs from it. Install `postgres` (postgres.js). The jobs use the postgres.js client of the Default Database, so they connect as the Database does, whatever variable or URL its Definition reads. `QUEUE_POSTGRES_URL` on the server overrides it. An explicit `driver: "postgres"` without a Postgres Default Database needs `QUEUE_POSTGRES_URL`.
134
+ The postgres driver keeps the jobs in the `vitehub_queue_jobs` table, and every server process of the app takes due jobs from it. Install `postgres` (postgres.js). The jobs use the postgres.js client of the Default Database, so they connect as the Database does, whatever variable or URL its Definition reads. When the Database sets `driver: "node-postgres"`, the jobs open their own postgres.js client on the connection URL of the Database. A node-postgres Database that reads only the PG* variables needs `QUEUE_POSTGRES_URL`. `QUEUE_POSTGRES_URL` on the server overrides it. An explicit `driver: "postgres"` without a Postgres Default Database needs `QUEUE_POSTGRES_URL`.
133
135
 
134
136
  ```ts
135
137
  // vite.config.ts
@@ -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
 
@@ -181,7 +183,7 @@ List, inspect, run again, and remove the stored jobs with the CLI. The commands
181
183
 
182
184
  ```sh
183
185
  pnpm vitehub queue jobs list --state dead
184
- pnpm vitehub queue jobs show <message-id>
186
+ pnpm vitehub queue jobs get <message-id>
185
187
  pnpm vitehub queue jobs retry <message-id>
186
188
  pnpm vitehub queue jobs clear --state dead --yes
187
189
  ```
@@ -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-DukggGP6.js";
2
+ import { a as normalizePublicQueueIdentifier, c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, r as isQueueError, t as readQueueTimes } from "./duration-CshzgSSx.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-ER1YdCBF.js";
4
+ import { n as normalizeQueueOptions } from "./config-YEuaeQVq.js";
5
+ import { t as resolveVercelQueueRegion } from "./vercel-region-DOciq2kx.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";
@@ -11,7 +11,6 @@ import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
11
11
  function queueTestMessages(test) {
12
12
  return test.backend("queue", () => []);
13
13
  }
14
- /** Records the job and does not run it, so a test asserts what the app sent. */
15
14
  function recordQueueTestMessage(test, queue, input) {
16
15
  const messages = queueTestMessages(test);
17
16
  const duplicate = input.options.idempotencyKey === void 0 ? void 0 : messages.find((message) => message.queue === queue && message.options.idempotencyKey === input.options.idempotencyKey);
@@ -38,17 +37,19 @@ function createTestQueueClient(test, queue, provider) {
38
37
  queue,
39
38
  async send(payload, options) {
40
39
  const input = normalizeQueueEnqueueInput(payload, options);
41
- const error = queueUnsupportedOptionsError(input.options, provider);
40
+ const error = queueUnsupportedOptionsError(input.options, provider) ?? readQueueTimes(input.options)[0];
42
41
  if (error) return [error, void 0];
43
42
  return [void 0, recordQueueTestMessage(test, queue, input)];
44
43
  },
45
44
  async sendBatch(items, options = {}) {
45
+ const removed = queueRemovedOptionsError(provider, options, items);
46
+ if (removed) return [removed, void 0];
46
47
  const inputs = items.map(({ body, ...itemOptions }) => normalizeQueueEnqueueInput(body, {
47
48
  ...options,
48
49
  ...Object.fromEntries(Object.entries(itemOptions).filter(([, value]) => value !== void 0))
49
50
  }));
50
51
  for (const input of inputs) {
51
- const error = queueUnsupportedOptionsError(input.options, provider);
52
+ const error = queueUnsupportedOptionsError(input.options, provider) ?? readQueueTimes(input.options)[0];
52
53
  if (error) return [error, void 0];
53
54
  }
54
55
  return [void 0, inputs.map((input) => recordQueueTestMessage(test, queue, input))];
@@ -119,7 +120,7 @@ async function useDynamicQueue(name) {
119
120
  if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: normalizePublicQueueIdentifier(name) });
120
121
  const test = getViteHubTestMode();
121
122
  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);
123
+ if (definition.cache === false || config.cache === false || config.driver === "cloudflare" || config.driver === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
123
124
  return await getOrCreateQueueClient(name, () => createNamedQueueClient(name));
124
125
  }
125
126
  async function sendDynamicQueue(name, payload, options) {
@@ -141,7 +142,7 @@ function deferDynamicQueue(name, payload, options) {
141
142
  const handleError = async (error) => {
142
143
  console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
143
144
  try {
144
- await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
145
+ await (await loadNamedQueueDefinition(name))?.onDispatchError?.(error, { name });
145
146
  } catch (hookError) {
146
147
  console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
147
148
  }
@@ -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-DukggGP6.js";
2
+ import { a as normalizePublicQueueIdentifier, c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes } from "./duration-CshzgSSx.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-ChtAjPNo.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,19 @@ 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
  }
48
51
  function resolveAction(action, message, fallback) {
49
52
  if (action && typeof action === "object" && !Array.isArray(action) && Object.hasOwn(action, "retry")) {
50
- message.retry(action.retry);
53
+ const removed = queueRemovedOptionsError("cloudflare", action.retry);
54
+ if (removed) throw removed;
55
+ const delay = action.retry?.delay;
56
+ message.retry(delay === void 0 ? void 0 : { delaySeconds: Math.ceil(parseDuration(delay, "delay", void 0, "s") / 1e3) });
51
57
  return;
52
58
  }
53
59
  if ((action === "ack" || action === "retry" ? action : fallback) === "ack") message.ack();
@@ -71,7 +77,7 @@ function createCloudflareQueueBatchHandler(options) {
71
77
  attempts: message.attempts,
72
78
  id: message.id,
73
79
  provider: "cloudflare",
74
- queue: getCloudflareQueueDefinitionName(batch.queue)
80
+ queue: normalizePublicQueueIdentifier(options.queue) ?? normalizePublicQueueIdentifier(getCloudflareQueueDefinitionName(batch.queue)) ?? batch.queue
75
81
  };
76
82
  reportQueueDeliveryError(error, reportContext);
77
83
  let action = void 0;
@@ -80,7 +86,12 @@ function createCloudflareQueueBatchHandler(options) {
80
86
  } catch (hookError) {
81
87
  reportQueueDeliveryError(hookError, reportContext);
82
88
  }
83
- resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry");
89
+ try {
90
+ resolveAction(action, message, isNonRetryableQueueError(error) ? "ack" : "retry");
91
+ } catch (actionError) {
92
+ reportQueueDeliveryError(actionError, reportContext);
93
+ message.retry();
94
+ }
84
95
  }
85
96
  }
86
97
  };
@@ -107,16 +118,18 @@ function createCloudflareQueueClient(provider) {
107
118
  return [void 0, { status: "queued" }];
108
119
  },
109
120
  async sendBatch(items, options) {
121
+ const removed = queueRemovedOptionsError("cloudflare", options, items);
122
+ if (removed) return [removed, void 0];
110
123
  const messages = [];
111
124
  for (const item of items) {
112
125
  const [optionsError, sendOptions] = toSendOptions({
113
126
  ...options,
114
127
  contentType: item.contentType || options?.contentType,
115
- delaySeconds: item.delaySeconds ?? options?.delaySeconds
128
+ delay: item.delay ?? options?.delay
116
129
  });
117
130
  if (optionsError) return [optionsError, void 0];
118
131
  messages.push({
119
- ...item,
132
+ body: item.body,
120
133
  ...sendOptions
121
134
  });
122
135
  }
@@ -1,4 +1,4 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.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-DukggGP6.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) {
@@ -55,14 +55,12 @@ const knownDrivers = /* @__PURE__ */ new Set([
55
55
  const postgresQueueUrlVariable = "QUEUE_POSTGRES_URL";
56
56
  /** Default directory of the local driver, next to the KV `fs-lite` store in `.vitehub/data/kv`. */
57
57
  const defaultLocalQueueBase = ".vitehub/data/queue";
58
- /** A self-hosted Node server has no hosted Queue, so it runs Queue Definitions in its own process. */
59
58
  function isLocalHosting(hosting) {
60
59
  return hosting === "local" || hostFromNitroPreset(hosting) === "node";
61
60
  }
62
61
  function readOwnOption(options, key) {
63
62
  return Object.hasOwn(options, key) ? options[key] : void 0;
64
63
  }
65
- /** The driver without `queue.driver`: the host's Queue, or on Node `postgres` with a Postgres Database, else `local`. */
66
64
  function inferDriver(hosting, postgresDatabase) {
67
65
  if (hosting.includes("cloudflare")) return "cloudflare";
68
66
  if (hosting === "postgres") return "postgres";
@@ -0,0 +1,27 @@
1
+ import { n as isRecord } from "./object-D8pRdprI.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
3
+ //#region src/definition.ts
4
+ /** Cloudflare accepts a `max_batch_size` from 1 to 100. */
5
+ function isQueueMaxBatchSize(value) {
6
+ return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 100;
7
+ }
8
+ const queueDefinitionKeys = /* @__PURE__ */ new Set([
9
+ "cache",
10
+ "callbackOptions",
11
+ "concurrency",
12
+ "handler",
13
+ "maxBatchSize",
14
+ "onDispatchError",
15
+ "onError"
16
+ ]);
17
+ function defineQueue(definition, ...removed) {
18
+ if (typeof definition === "function" || removed.length) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue(handler, options)` was removed." });
19
+ if (!isRecord(definition)) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` expects one object with `handler`." });
20
+ const unknownKey = Object.keys(definition).find((key) => !queueDefinitionKeys.has(key));
21
+ if (unknownKey) throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: `\`defineQueue()\` does not support the "${unknownKey}" option.` });
22
+ if (!Object.hasOwn(definition, "handler") || typeof definition.handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION({ reason: "`defineQueue()` needs a `handler` function." });
23
+ if (definition.maxBatchSize !== void 0 && !isQueueMaxBatchSize(definition.maxBatchSize)) throw queueErrorDiagnostics.QUEUE_MAX_BATCH_SIZE_INVALID({ where: "defineQueue()" });
24
+ return definition;
25
+ }
26
+ //#endregion
27
+ export { isQueueMaxBatchSize as n, defineQueue as t };
@@ -1,4 +1,6 @@
1
- import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
2
+ import { parseDuration, toResultError } from "@vite-hub/runtime";
3
+ import { runtimeErrorDiagnostics } from "@vite-hub/runtime/internal/error-diagnostics";
2
4
  //#region src/enqueue.ts
3
5
  let fallbackCounter = 0;
4
6
  function createQueueMessageId(prefix = "queue") {
@@ -20,12 +22,12 @@ function normalizeQueueEnqueueInput(payload, options = {}) {
20
22
  const cloudflareUnsupportedEnqueueOptions = [
21
23
  "idempotencyKey",
22
24
  "region",
23
- "retentionSeconds"
25
+ "retention"
24
26
  ];
25
27
  const localUnsupportedEnqueueOptions = [
26
28
  "contentType",
27
29
  "region",
28
- "retentionSeconds"
30
+ "retention"
29
31
  ];
30
32
  const postgresUnsupportedEnqueueOptions = localUnsupportedEnqueueOptions;
31
33
  const unsupportedEnqueueOptions = {
@@ -34,9 +36,21 @@ const unsupportedEnqueueOptions = {
34
36
  postgres: postgresUnsupportedEnqueueOptions,
35
37
  vercel: ["contentType"]
36
38
  };
39
+ const removedEnqueueOptions = [
40
+ "delaySeconds",
41
+ "id",
42
+ "retentionSeconds"
43
+ ];
44
+ function queueRemovedOptionsError(provider, options, items = []) {
45
+ const removed = removedEnqueueOptions.filter((name) => options && Object.hasOwn(options, name) || items.some((item) => Object.hasOwn(item, name)));
46
+ if (removed.length) return queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
47
+ options: formatQueueOptionNames(removed),
48
+ provider
49
+ });
50
+ }
37
51
  /** Shared pre-dispatch option validation for provider clients and the test backend. */
38
52
  function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqueueOptions[provider]) {
39
- const unsupported = [...Object.hasOwn(options, "id") ? ["id"] : [], ...names.filter((option) => options[option] !== void 0)];
53
+ const unsupported = [...removedEnqueueOptions.filter((option) => Object.hasOwn(options, option)), ...names.filter((option) => options[option] !== void 0)];
40
54
  return unsupported.length ? queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
41
55
  options: formatQueueOptionNames(unsupported),
42
56
  provider
@@ -46,7 +60,7 @@ function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqu
46
60
  function isQueueError(error, codes) {
47
61
  return queueErrorDiagnostics.is(error) && (!codes || codes.some((code) => code === error.code));
48
62
  }
49
- /** Formats option names for an error `why`, for example `"region" and "retentionSeconds"`. */
63
+ /** Formats option names for an error `why`, for example `"region" and "retention"`. */
50
64
  function formatQueueOptionNames(names) {
51
65
  const quoted = names.map((name) => `\`${name}\``);
52
66
  return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}` : quoted.join("");
@@ -74,4 +88,32 @@ async function queueProviderResult(provider, operation, run) {
74
88
  }
75
89
  }
76
90
  //#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 };
91
+ //#region src/duration.ts
92
+ function readRetentionSeconds(seconds, round) {
93
+ if (!Number.isFinite(seconds) || seconds < 0) throw runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID({
94
+ option: "retention",
95
+ value: String(seconds)
96
+ });
97
+ return round === "ceil" ? Math.ceil(seconds) : seconds;
98
+ }
99
+ /**
100
+ * Reads `delay` and `retention` of a send. `delay` is a duration such as `"1m"`. `retention` is a duration or a number
101
+ * of seconds. A value that is not a duration returns `RUNTIME_DURATION_INVALID`. Pass `"ceil"` for a provider that
102
+ * takes whole seconds, so a job never runs earlier than the caller asked.
103
+ */
104
+ function readQueueTimes(options, round) {
105
+ const seconds = (milliseconds) => round === "ceil" ? Math.ceil(milliseconds / 1e3) : milliseconds / 1e3;
106
+ try {
107
+ const delaySeconds = options.delay === void 0 ? void 0 : seconds(parseDuration(options.delay, "delay", void 0, "s"));
108
+ const retentionSeconds = typeof options.retention === "number" ? readRetentionSeconds(options.retention, round) : options.retention === void 0 ? void 0 : seconds(parseDuration(options.retention, "retention"));
109
+ return [void 0, {
110
+ ...delaySeconds === void 0 ? {} : { delaySeconds },
111
+ ...retentionSeconds === void 0 ? {} : { retentionSeconds }
112
+ }];
113
+ } catch (error) {
114
+ if (runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID.is(error)) return [toResultError(error), void 0];
115
+ throw error;
116
+ }
117
+ }
118
+ //#endregion
119
+ 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 };
@@ -25,7 +25,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
25
25
  why: ({ message }) => message === void 0 ? "" : String(message)
26
26
  },
27
27
  INTERNAL_R0022: {
28
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
28
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
29
29
  why: ({ message }) => message === void 0 ? "" : String(message)
30
30
  },
31
31
  INTERNAL_R0024: {
@@ -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."
@@ -240,6 +244,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
240
244
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
241
245
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
242
246
  },
247
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
248
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
249
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
250
+ },
243
251
  INTERNAL_SECRET_PURPOSE_MISSING: {
244
252
  why: "[vitehub] A derived secret requires a purpose.",
245
253
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -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.`,
@@ -53,7 +53,7 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
53
53
  },
54
54
  QUEUE_JOB_RUNNING: {
55
55
  why: "The job is running now.",
56
- fix: "Wait for the attempt to end, then run `vitehub queue jobs show` for its state."
56
+ fix: "Wait for the attempt to end, then run `vitehub queue jobs get` for its state."
57
57
  },
58
58
  QUEUE_BINDING_NOT_FOUND: {
59
59
  why: ({ binding }) => binding ? `The Cloudflare queue binding "${binding}" is not in the Worker env.` : "The Cloudflare queue client has no binding.",
@@ -104,8 +104,8 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
104
104
  fix: "Set `QUEUE_POSTGRES_URL` to the Postgres URL of the jobs, or remove it to use the connection of the Default Database."
105
105
  },
106
106
  QUEUE_POSTGRES_MISSING_CONNECTION: {
107
- why: ({ database }) => database ? `The postgres queue provider uses the connection of the Database "${database}", and that Database has no Postgres client in this runtime.` : "The postgres queue provider has no connection: the build found no Postgres Default Database, and `QUEUE_POSTGRES_URL` is not set.",
108
- fix: "Add a Default Database with `dialect: 'postgresql'` and build again, or set `QUEUE_POSTGRES_URL` on the server to the Postgres URL of the jobs."
107
+ why: ({ database }) => database ? `The postgres queue provider uses the connection of the Database "${database}", and that Database has no postgres.js client and no connection URL in this runtime.` : "The postgres queue provider has no connection: the build found no Postgres Default Database, and `QUEUE_POSTGRES_URL` is not set.",
108
+ fix: ({ database }) => database ? `Set \`connection.url\` on the Database "${database}", or set \`QUEUE_POSTGRES_URL\` on the server to the Postgres URL of the jobs.` : "Add a Default Database with `dialect: 'postgresql'` and build again, or set `QUEUE_POSTGRES_URL` on the server to the Postgres URL of the jobs."
109
109
  },
110
110
  QUEUE_RUNTIME_NOT_INSTALLED: {
111
111
  why: "The Queue runtime has no client factory. The generated server output installs it.",
@@ -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 @vite-hub/codemods define-forms` 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.`,
@@ -155,6 +155,10 @@ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
155
155
  why: ({ name }) => `The Cloudflare queue name "${name}" can contain only letters, numbers, and dashes, and must start and end with a letter or number.`,
156
156
  fix: "Change `queue.namePrefix` so that it contains only letters, numbers, and dashes."
157
157
  },
158
+ QUEUE_MAX_BATCH_SIZE_INVALID: {
159
+ why: ({ where }) => `${where}: \`maxBatchSize\` must be a whole number from 1 to 100, written as a number in \`export default defineQueue({ ... })\`. The build reads the options from the file to configure the Cloudflare consumer, so they cannot use a spread or a computed key.`,
160
+ fix: "Write each option, such as `maxBatchSize: 5` (a whole number from 1 to 100), directly in the object of `export default defineQueue({ ... })`, without a variable, a spread, or a computed key."
161
+ },
158
162
  QUEUE_MISSING_DRIVER: {
159
163
  why: ({ hosting }) => `ViteHub cannot select a Queue driver for ${hosting} hosting.`,
160
164
  fix: "Set `queue.driver`, select the Cloudflare, Vercel, or Node deployment preset, or set `queue: false`."
@@ -1,5 +1,6 @@
1
- import { i as normalizePublicQueueIdentifier, n as isQueueError } from "./errors-DL3pcNO4.js";
2
- import { getViteHubErrorShape, toResponse } from "@vite-hub/runtime";
1
+ import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-CshzgSSx.js";
2
+ import { getViteHubErrorShape } from "@vite-hub/runtime";
3
+ import { toResponse } from "@vite-hub/runtime/internal/response";
3
4
  //#region src/internal/delivery-error.ts
4
5
  const retryableQueueCodes = /* @__PURE__ */ new Set(["QUEUE_PROVIDER_FAILED", "QUEUE_PROVIDER_INVALID_RESPONSE"]);
5
6
  function isNonRetryableQueueError(error) {
@@ -50,12 +51,16 @@ function reportQueueDeliveryError(error, context) {
50
51
  /** Queue deliveries use the handler's status and discard its response body. */
51
52
  function checkQueueHandlerResponse(value) {
52
53
  const response = toResponse(value);
53
- response.body?.cancel().catch(() => {});
54
+ discardUnreadBody(response.body);
54
55
  if (!response.ok) {
55
56
  const error = /* @__PURE__ */ new Error(`Queue handler returned HTTP ${response.status}`);
56
57
  Object.assign(error, { status: response.status });
57
58
  throw error;
58
59
  }
59
60
  }
61
+ function discardUnreadBody(body) {
62
+ if (!body || body.locked) return;
63
+ body.cancel().catch(() => console.debug("[vitehub:queue] The Queue handler response body could not be cancelled."));
64
+ }
60
65
  //#endregion
61
66
  export { reportQueueDeliveryError as i, createQueueDeliveryErrorReport as n, isNonRetryableQueueError as r, checkQueueHandlerResponse as t };
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-klaR79hV.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,15 +1,7 @@
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";
4
- //#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
- };
11
- }
12
- //#endregion
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
2
+ import { t as defineQueue } from "./definition-BL_3WHNu.js";
3
+ import { u as createQueueMessageId } from "./duration-CshzgSSx.js";
4
+ import { i as useQueue, n as dynamicQueue, r as sendQueue, t as deferQueue } from "./client-DYE_ZV8c.js";
13
5
  //#region src/runtime/create-client.ts
14
6
  async function createQueueClient(options) {
15
7
  if (options.driver === void 0 && Object.hasOwn(options, "provider")) {
@@ -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-klaR79hV.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-BasaJ68s.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-klaR79hV.js";
2
2
  //#region ../internal/src/runtime/cloudflare-env-lookup.d.ts
3
3
  type CloudflareWorkerEnv = Record<string, unknown>;
4
4
  //#endregion