@vite-hub/queue 0.0.3 → 0.1.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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +110 -50
  3. package/dist/client-CIc3jsj2.js +114 -0
  4. package/dist/cloudflare-client-COzQ8fHk.js +147 -0
  5. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-CCuLDvSP.js} +3 -2
  6. package/dist/{cloudflare-vite-bA1eLf46.js → cloudflare-vite-BCuJOXcT.js} +31 -12
  7. package/dist/{cloudflare-vite-nFPor46-.d.ts → cloudflare-vite-CjdP5yBN.d.ts} +9 -4
  8. package/dist/config-BINujLv4.js +74 -0
  9. package/dist/enqueue-CnQ0QR3O.js +22 -0
  10. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  11. package/dist/error-diagnostics-qzRF6IVB.js +109 -0
  12. package/dist/errors-DIFaM9tW.js +42 -0
  13. package/dist/handler-response-CBwIkmTS.js +56 -0
  14. package/dist/index.d.ts +32 -70
  15. package/dist/index.js +9 -8
  16. package/dist/inspect-PeuckaC3.js +30 -0
  17. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  18. package/dist/internal/runtime/cloudflare-client.js +1 -1
  19. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  20. package/dist/internal/runtime/cloudflare-vite.js +1 -1
  21. package/dist/internal/runtime/state.d.ts +16 -15
  22. package/dist/internal/runtime/state.js +2 -2
  23. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  24. package/dist/internal/runtime/vercel-client.js +93 -62
  25. package/dist/nuxt.d.ts +27 -7
  26. package/dist/nuxt.js +7 -2
  27. package/dist/object-B1NW521B.js +7 -0
  28. package/dist/operations-Cnjbz8kk.js +63 -0
  29. package/dist/operations-tNUdj3G4.d.ts +212 -0
  30. package/dist/operations.d.ts +32 -0
  31. package/dist/operations.js +1195 -0
  32. package/dist/runtime/hosted.d.ts +4 -7
  33. package/dist/runtime/hosted.js +30 -8
  34. package/dist/state-G9s378-e.js +184 -0
  35. package/dist/{types-CwvoMATy.d.ts → types-1GRMYES1.d.ts} +35 -24
  36. package/dist/vercel-region-cjskrOKl.js +122 -0
  37. package/dist/vite-ChWLzOVu.js +1512 -0
  38. package/dist/vite.d.ts +346 -33
  39. package/dist/vite.js +2 -2
  40. package/package.json +69 -23
  41. package/dist/_app-D29AwUdD.d.ts +0 -11
  42. package/dist/app-BZpq2cwC.js +0 -10
  43. package/dist/client-CPQ-iyXS.js +0 -93
  44. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  45. package/dist/config-B7xkD1v0.js +0 -47
  46. package/dist/delivery-error-glgYWC9g.js +0 -45
  47. package/dist/errors-CjuG_qr-.js +0 -108
  48. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  49. package/dist/internal/runtime/vercel-vite.js +0 -49
  50. package/dist/state-Bo8CLZ_k.js +0 -105
  51. package/dist/vercel-runtime-package-copy-CKimoFJ5.js +0 -66
  52. package/dist/vite-BcMpQk_n.js +0 -1842
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,91 +1,151 @@
1
1
  # @vite-hub/queue
2
2
 
3
- <p>
4
- <a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/badge/ViteHub-vitehub.dev-646cff?style=flat-square"></a>
5
- <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square">
6
- <img alt="Vite" src="https://img.shields.io/badge/Vite-discovery-646cff?style=flat-square">
7
- <img alt="Queue" src="https://img.shields.io/badge/Queue-background%20jobs-9333ea?style=flat-square">
8
- </p>
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)
9
7
 
10
- `@vite-hub/queue` defines background job handlers by file path and keeps producers on one `runQueue()` API.
8
+ `@vite-hub/queue` discovers background job handlers during a Vite build and connects `runQueue()` to Cloudflare Queues or Vercel Queues. A successful enqueue means the provider accepted the job. It does not mean the handler finished.
11
9
 
12
- ## Install
10
+ Applications that already use the `vite-hub` framework distribution should enable Queue in `vitehub()` and import from `vite-hub/queue`. Install this owner package directly when you are building a custom composition, another framework integration, or package-level tooling. The [Queue guide](https://vitehub.dev/docs/queue) covers the framework-distribution setup.
11
+
12
+ ## Install the owner package
13
13
 
14
14
  ```sh
15
15
  pnpm add @vite-hub/queue
16
+ pnpm add -D @vite-hub/cli vite
16
17
  ```
17
18
 
18
- Add `@vercel/queue` when you use the Vercel provider.
19
+ The package requires Node 24 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
20
 
20
- Vercel Queue projects that typecheck the generated path need Node and ws ambient types:
21
+ For Vercel Queues, also install the provider package and the ambient types used by generated functions:
21
22
 
22
23
  ```sh
24
+ pnpm add @vercel/queue
23
25
  pnpm add -D @types/node @types/ws
24
26
  ```
25
27
 
26
- ## Minimal API
28
+ ## Build the first Queue Definition
29
+
30
+ Queue has no in-memory provider for local delivery. The first credential-free result is a build that discovers a Queue Definition and emits provider configuration. This example selects Cloudflare explicitly.
31
+
32
+ Define the handler in a discoverable file:
27
33
 
28
34
  ```ts
29
- // server/queues/welcome-email.ts
30
- import { defineQueue } from "@vite-hub/queue"
35
+ // src/welcome-email.queue.ts
36
+ import { defineQueue } from "@vite-hub/queue";
31
37
 
32
- export default defineQueue<{ email: string }>(async (job) => {
33
- console.log(`Send welcome email to ${job.payload.email}`)
34
- })
38
+ export default defineQueue<{ email: string }>(async ({ payload }) => {
39
+ console.log(`Send welcome email to ${payload.email}`);
40
+ });
35
41
  ```
36
42
 
37
- ```ts
38
- // server/api/signup.post.ts
39
- import { runQueue } from "@vite-hub/queue"
40
- import { defineEventHandler, readBody } from "h3"
43
+ Enqueue it by its discovered name:
41
44
 
42
- export default defineEventHandler(async (event) => {
43
- return runQueue("welcome-email", await readBody<{ email: string }>(event))
44
- })
45
+ ```ts
46
+ // src/server.ts
47
+ import { runQueue } from "@vite-hub/queue";
48
+
49
+ export async function enqueueWelcomeEmail(email: string) {
50
+ const [error, result] = await runQueue("welcome-email", { email });
51
+ if (error) throw error;
52
+ return result;
53
+ }
54
+
55
+ export default function handleRequest() {
56
+ return new Response("Queue producer ready");
57
+ }
45
58
  ```
46
59
 
60
+ Register the Vite integration with the Nitro Vite plugin. Nitro is the only host output:
61
+
47
62
  ```ts
48
63
  // vite.config.ts
49
- import { hubQueue } from "@vite-hub/queue/vite"
50
- import { defineConfig } from "vite"
64
+ import { hubQueue } from "@vite-hub/queue/vite";
65
+ import { nitro } from "nitro/vite";
66
+ import { defineConfig } from "vite";
51
67
 
52
68
  export default defineConfig({
53
- plugins: [hubQueue()],
54
- queue: { provider: "cloudflare" },
55
- })
69
+ nitro: { preset: "cloudflare-module", serverEntry: "./src/server.ts" },
70
+ plugins: [hubQueue({ provider: "cloudflare" }), nitro()],
71
+ });
72
+ ```
73
+
74
+ Run a production-shaped build:
75
+
76
+ ```sh
77
+ pnpm vite build
56
78
  ```
57
79
 
58
- Throw `ViteHubError` when a Queue Definition needs a stable application error code. Queue retry policy belongs to Queue Delivery and provider callbacks, not the error object.
80
+ A successful build writes `.vitehub/queue/registry.mjs` with the `welcome-email` definition. Nitro writes the Worker and `.output/server/wrangler.json`. The Wrangler configuration contains one generated producer binding and one consumer for the Queue Definition.
81
+
82
+ That build proves discovery and generated output only. `runQueue()` needs the generated runtime, a deployed Cloudflare binding, and an existing queue before it can return `[undefined, { status: "queued" }]`. Use the [Cloudflare host guide](https://vitehub.dev/docs/frameworks-hosts/cloudflare) for provisioning and deployment checks. Do not import `.vitehub` or `dist` files from application code.
83
+
84
+ ## Choose Cloudflare or Vercel
85
+
86
+ | Provider | Choose it when | Generated output | Enqueue options |
87
+ | ---------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------- |
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
+
91
+ The ViteHub framework preset selects Cloudflare for `preset: "cloudflare"` and Vercel for `preset: "vercel"`. With the owner package, set `provider` explicitly when host inference would be ambiguous. Netlify cannot infer one. ViteHub provides no Queue Provider for local delivery, Deno, or self-hosted Node. Check the [runtime and host support matrix](https://vitehub.dev/docs/frameworks-hosts/support-matrix) before choosing a deployment target.
92
+
93
+ 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`.
94
+
95
+ 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.
96
+
97
+ ## Treat acceptance and delivery separately
98
+
99
+ `runQueue()` waits for provider enqueue and returns `[error, result]`. `result` is this portable value:
59
100
 
60
101
  ```ts
61
- import { ViteHubError } from "@vite-hub/runtime"
62
- import { defineQueue } from "@vite-hub/queue"
63
-
64
- export default defineQueue<{ email?: string }>(async ({ payload }) => {
65
- if (!payload.email) {
66
- throw new ViteHubError("WELCOME_EMAIL_INVALID_PAYLOAD", "Welcome email payload requires an email address.", {
67
- details: { field: "email" },
68
- })
69
- }
70
-
71
- await sendWelcomeEmail(payload.email)
72
- })
102
+ type QueueSendResult = {
103
+ messageId?: string;
104
+ status: "queued";
105
+ };
73
106
  ```
74
107
 
75
- ViteHub's built-in codes remain available as `QueueErrorCode`. ViteHub reports each failed delivery with safe Queue and message identifiers, attempt count, code, details, and the Queue-owned retry decision before choosing the provider action. Cloudflare `onError` and Vercel `callbackOptions.retry` directives override the default action when they return an explicit directive.
108
+ The optional message ID is provider-specific. Vercel returns the ID from its enqueue response. Cloudflare returns the input's `id`, generating one locally when omitted; it does not send that ID to Cloudflare, and the later delivery has a different Cloudflare message ID. In both cases, `status: "queued"` is the portable acceptance signal. Queue handlers run later and return no value to the producer. Use a [Workflow](https://vitehub.dev/docs/workflows) when the caller needs a tracked run, durable steps, waits, or progress.
109
+
110
+ `deferQueue()` does not wait for provider acceptance. It schedules enqueue work through the current request's `waitUntil`, logs dispatch failures, and calls the Queue Definition's `onDispatchError` hook when present.
111
+
112
+ Providers can retry failed delivery, so handlers must tolerate another invocation after a partial side effect. ViteHub does not expose an exactly-once delivery guarantee. Vercel sends an idempotency key, using the generated message ID by default; pass a stable application key when repeated enqueue attempts should share one key. Cloudflare does not accept `idempotencyKey`, so protect non-repeatable side effects inside the handler.
113
+
114
+ On Cloudflare, successful handlers acknowledge the message. Failed handlers retry by default unless the error is a Queue error that a retry cannot fix or `onError` returns an explicit acknowledge or retry action. On Vercel, `callbackOptions.retry` can return an explicit directive; returning nothing preserves provider behavior. Application error codes do not choose retry policy.
76
115
 
77
- ## Vite Integration
116
+ `runQueue()`, `dynamicQueue.run()`, `send()`, and `sendBatch()` return `[error, data]`. `error.code` is `QUEUE_PROVIDER_FAILED`, `QUEUE_PROVIDER_INVALID_RESPONSE`, or `QUEUE_UNSUPPORTED_OPTION`, and each error has `why`, `fix`, `docs`, and `cause`. Configuration errors, for example an unknown Queue name or a missing Cloudflare binding, throw. `JSON.stringify(error)` and Queue delivery reports omit `cause`, so keep credentials and provider responses there. Throw `ViteHubError` from a handler for an application code. See the [Queue error reference](https://vitehub.dev/docs/queue/limits-and-errors) for each code and the retry policy.
78
117
 
79
- Use `hubQueue()` in Vite to discover `server/queues/<name>.ts` and `src/<name>.queue.ts`. The handler name comes from the file path, while provider output maps it to [Cloudflare Queues](https://developers.cloudflare.com/queues/) or [Vercel Queues](https://vercel.com/docs/queues).
118
+ ## Public imports
80
119
 
81
- In Nuxt, install the Queue module instead. It installs the same Vite integration and merges the generated runtime files and provider bindings into Nitro configuration:
120
+ | Import | Purpose |
121
+ | -------------------------------- | ----------------------------------------------------------------------------------- |
122
+ | `@vite-hub/queue` | Queue Definitions, enqueue helpers, direct clients, host adapters, and public types |
123
+ | `@vite-hub/queue/vite` | Vite discovery and Cloudflare or Vercel Nitro configuration |
124
+ | `@vite-hub/queue/nuxt` | Nuxt module that composes Queue into Nitro |
125
+ | `@vite-hub/queue/runtime/hosted` | Advanced hosted Vercel callback adapter |
126
+
127
+ `@vite-hub/queue/internal/*` exists for generated framework integration. Application code should not import it.
128
+
129
+ ## Go deeper
130
+
131
+ - [Queue guide](https://vitehub.dev/docs/queue)
132
+ - [Runtime and host support](https://vitehub.dev/docs/frameworks-hosts/support-matrix)
133
+ - [Definitions and discovery](https://vitehub.dev/docs/development/definition-discovery)
134
+ - [Public import paths](https://vitehub.dev/docs/reference/import-paths)
135
+
136
+
137
+ ## Definition-owned dispatch types
138
+
139
+ The Vite Integration writes `.vitehub/queue.d.ts`. Include that file in your TypeScript project. The Nuxt Integration adds it to the generated type context. Names and payloads then come from the discovered Queue Definitions:
82
140
 
83
141
  ```ts
84
- export default defineNuxtConfig({
85
- modules: [["@vite-hub/queue/nuxt", { provider: "cloudflare" }]],
86
- })
142
+ const [error] = await runQueue("welcome-email", { email: "ada@example.com" }, { delaySeconds: 60 })
143
+ const queue = await getQueue("welcome-email")
144
+ const [sendError] = await queue.send({ email: "ada@example.com" })
87
145
  ```
88
146
 
89
- Run `vite build` to emit Queue Provider Output. Cloudflare output is written under `dist/**/wrangler.json`; Vercel output is written under `.vercel/output/functions/api/vitehub/queues/vercel/**`.
147
+ `QueueRegistry` is the generated definition map. `QueuePayload<"welcome-email">` extracts a payload type. A missing name or wrong payload is a type error. Run Vite configuration or the Nuxt prepare step after you add a definition. For a standalone TypeScript host, you can extend `QueueRegistry` with `typeof import("./welcome.queue").default`.
148
+
149
+ Use `dynamicQueue.run(name, payload, options?)`, `dynamicQueue.defer()`, or `dynamicQueue.get()` for names read from external input. These methods check that the definition exists at runtime. They do not validate payload shape. Validate external data in your application. Direct provider clients from `createQueueClient()` also accept unknown payloads because they have no Queue Definition.
90
150
 
91
- Learn more at [vitehub.dev](https://vitehub.dev).
151
+ This is a breaking change: replace `runQueue(name, { payload, ...options })` with `runQueue(name, payload, options)`, and `client.send({ payload, ...options })` with `client.send(payload, options)`. There is no envelope detection. Existing envelope objects are delivered whole as payloads.
@@ -0,0 +1,114 @@
1
+ import { t as normalizeQueueOptions } from "./config-BINujLv4.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
3
+ import { i as normalizePublicQueueIdentifier, r as isQueueError } from "./errors-DIFaM9tW.js";
4
+ import { t as getCloudflareQueueBindingName } from "./cloudflare-GosJefIK.js";
5
+ import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
6
+ import { a as getQueueRuntimeEvent, h as resolveWaitUntil, i as getQueueRuntimeConfig, l as runWithQueueRuntimeEvent, m as getCloudflareEnv, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, s as loadQueueDefinition } from "./state-G9s378-e.js";
7
+ import { t as resolveVercelQueueRegion } from "./vercel-region-cjskrOKl.js";
8
+ //#region src/runtime/client.ts
9
+ async function loadNamedQueueDefinition(name) {
10
+ try {
11
+ return await loadQueueDefinition(name);
12
+ } catch (cause) {
13
+ throw queueErrorDiagnostics.QUEUE_DEFINITION_LOAD_FAILED({
14
+ cause,
15
+ queue: normalizePublicQueueIdentifier(name)
16
+ });
17
+ }
18
+ }
19
+ function resolveCloudflareBinding(binding, name) {
20
+ if (binding && typeof binding !== "string") return binding;
21
+ const bindingName = binding || getCloudflareQueueBindingName(name);
22
+ return getCloudflareEnv(getQueueRuntimeEvent())?.[bindingName] || bindingName;
23
+ }
24
+ function toProviderOptions(name, config) {
25
+ if (config.provider === "cloudflare") return {
26
+ ...config,
27
+ binding: resolveCloudflareBinding(config.binding, name)
28
+ };
29
+ return {
30
+ ...config,
31
+ topic: getVercelQueueTopicName(name)
32
+ };
33
+ }
34
+ function getActiveQueueConfig() {
35
+ const config = getQueueRuntimeConfig();
36
+ if (config === false) return false;
37
+ return config || normalizeQueueOptions(void 0, { hosting: "vercel" });
38
+ }
39
+ async function createNamedQueueClient(name) {
40
+ const config = getActiveQueueConfig();
41
+ if (config === false) throw queueErrorDiagnostics.QUEUE_DISABLED();
42
+ const provider = toProviderOptions(name, config);
43
+ const createClient = getQueueRuntimeClientFactory();
44
+ if (!createClient) throw queueErrorDiagnostics.QUEUE_RUNTIME_NOT_INSTALLED();
45
+ try {
46
+ return await createClient(provider);
47
+ } catch (cause) {
48
+ if (isQueueError(cause)) throw cause;
49
+ throw queueErrorDiagnostics.QUEUE_PROVIDER_FAILED({
50
+ cause,
51
+ operation: "create-client",
52
+ provider: provider.provider
53
+ });
54
+ }
55
+ }
56
+ async function getDynamicQueue(name) {
57
+ const definition = await loadNamedQueueDefinition(name);
58
+ if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: normalizePublicQueueIdentifier(name) });
59
+ const config = getActiveQueueConfig();
60
+ if (definition.options?.cache === false || config === false || config.cache === false || config.provider === "cloudflare" || config.provider === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
61
+ return await getOrCreateQueueClient(name, () => createNamedQueueClient(name));
62
+ }
63
+ async function runDynamicQueue(name, payload, options) {
64
+ let queue;
65
+ try {
66
+ queue = await getDynamicQueue(name);
67
+ } catch (error) {
68
+ if (isQueueError(error, ["QUEUE_PROVIDER_FAILED"])) return [error, void 0];
69
+ throw error;
70
+ }
71
+ return await queue.send(payload, options);
72
+ }
73
+ function deferDynamicQueue(name, payload, options) {
74
+ const request = getQueueRuntimeEvent();
75
+ const task = async () => {
76
+ const [error] = await runWithQueueRuntimeEvent(request, () => runDynamicQueue(name, payload, options));
77
+ if (error) throw error;
78
+ };
79
+ const handleError = async (error) => {
80
+ console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
81
+ try {
82
+ await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
83
+ } catch (hookError) {
84
+ console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
85
+ }
86
+ };
87
+ const promise = task().catch(handleError);
88
+ const waitUntil = resolveWaitUntil(request);
89
+ if (typeof waitUntil === "function") waitUntil(promise);
90
+ }
91
+ /** Dispatch externally supplied names and payloads after application validation. */
92
+ const dynamicQueue = {
93
+ defer: deferDynamicQueue,
94
+ get: getDynamicQueue,
95
+ run: runDynamicQueue
96
+ };
97
+ /**
98
+ * Returns the QueueClient of a discovered Queue Definition. Config errors, for example an unknown name, throw.
99
+ */
100
+ async function getQueue(name) {
101
+ return await getDynamicQueue(name);
102
+ }
103
+ /**
104
+ * Enqueues one job and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
105
+ * Config errors, for example an unknown Queue name, throw.
106
+ */
107
+ function runQueue(name, payload, options) {
108
+ return runDynamicQueue(name, payload, options);
109
+ }
110
+ function deferQueue(name, payload, options) {
111
+ deferDynamicQueue(name, payload, options);
112
+ }
113
+ //#endregion
114
+ export { runQueue as i, dynamicQueue as n, getQueue as r, deferQueue as t };