@vite-hub/queue 0.0.4 → 0.3.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 (63) hide show
  1. package/README.md +170 -31
  2. package/dist/client-Cj50hQYp.js +180 -0
  3. package/dist/cloudflare-client-DYsAjM8B.js +140 -0
  4. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-BJHYRCMQ.js} +3 -2
  5. package/dist/config-BcTDeQIP.js +105 -0
  6. package/dist/durability.d.ts +13 -0
  7. package/dist/durability.js +47 -0
  8. package/dist/error-diagnostics-BRartC1z.js +181 -0
  9. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  10. package/dist/errors-DL3pcNO4.js +77 -0
  11. package/dist/handler-response-By0Fpspv.js +61 -0
  12. package/dist/index.d.ts +29 -83
  13. package/dist/index.js +24 -11
  14. package/dist/inspect-PeuckaC3.js +30 -0
  15. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  16. package/dist/internal/runtime/cloudflare-client.js +1 -1
  17. package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
  18. package/dist/internal/runtime/cloudflare-vite.js +111 -1
  19. package/dist/internal/runtime/local-client.d.ts +17 -0
  20. package/dist/internal/runtime/local-client.js +71 -0
  21. package/dist/internal/runtime/postgres-client.d.ts +46 -0
  22. package/dist/internal/runtime/postgres-client.js +560 -0
  23. package/dist/internal/runtime/state.d.ts +23 -15
  24. package/dist/internal/runtime/state.js +2 -2
  25. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  26. package/dist/internal/runtime/vercel-client.js +120 -63
  27. package/dist/internal/runtime/worker-client.d.ts +6 -0
  28. package/dist/internal/runtime/worker-client.js +11 -0
  29. package/dist/invariant-D8_xBqmZ.js +22 -0
  30. package/dist/local-CGckW5nr.js +540 -0
  31. package/dist/local-CVVRVWeR.d.ts +22 -0
  32. package/dist/object-D8pRdprI.js +15 -0
  33. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  34. package/dist/operations-Crwjca91.js +124 -0
  35. package/dist/operations.d.ts +69 -0
  36. package/dist/operations.js +1344 -0
  37. package/dist/runtime/hosted.d.ts +5 -9
  38. package/dist/runtime/hosted.js +21 -23
  39. package/dist/state-mVA2X_wa.js +196 -0
  40. package/dist/types-BD-8U9zS.d.ts +420 -0
  41. package/dist/types-DS_rqu9l.d.ts +10 -0
  42. package/dist/vercel-region-D1CivgdA.js +26 -0
  43. package/dist/virtual.d.ts +4 -0
  44. package/dist/vite.d.ts +655 -40
  45. package/dist/vite.js +2071 -2
  46. package/package.json +66 -30
  47. package/dist/_app-D29AwUdD.d.ts +0 -11
  48. package/dist/app-BZpq2cwC.js +0 -10
  49. package/dist/client-DG9fweET.js +0 -93
  50. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  51. package/dist/cloudflare-vite-BlQfDVZD.js +0 -97
  52. package/dist/cloudflare-vite-nFPor46-.d.ts +0 -24
  53. package/dist/config-CNgAeIND.js +0 -53
  54. package/dist/delivery-error-glgYWC9g.js +0 -45
  55. package/dist/errors-CjuG_qr-.js +0 -108
  56. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  57. package/dist/internal/runtime/vercel-vite.js +0 -49
  58. package/dist/nuxt.d.ts +0 -19
  59. package/dist/nuxt.js +0 -30
  60. package/dist/state-Cno9O7YS.js +0 -110
  61. package/dist/types-CwvoMATy.d.ts +0 -169
  62. package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
  63. package/dist/vite-DOuoen0w.js +0 -4414
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@vite-hub/queue",
3
- "version": "0.0.4",
3
+ "version": "0.3.1",
4
4
  "description": "Queue primitives and Vite deployment integration for ViteHub.",
5
5
  "keywords": [
6
+ "background-jobs",
6
7
  "cloudflare",
7
8
  "h3",
9
+ "job-queue",
10
+ "nuxt",
11
+ "postgres",
8
12
  "queue",
13
+ "typescript",
9
14
  "vercel",
10
15
  "vite",
11
16
  "vitehub"
12
17
  ],
13
- "homepage": "https://github.com/vite-hub/vitehub#readme",
18
+ "homepage": "https://vitehub.dev",
14
19
  "bugs": "https://github.com/vite-hub/vitehub/issues",
15
20
  "license": "Apache-2.0",
16
21
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -26,55 +31,86 @@
26
31
  "type": "module",
27
32
  "sideEffects": false,
28
33
  "types": "./dist/index.d.ts",
34
+ "imports": {
35
+ "#vitehub/queue/node-client": {
36
+ "types": "./dist/internal/runtime/postgres-client.d.ts",
37
+ "workerd": "./dist/internal/runtime/worker-client.js",
38
+ "worker": "./dist/internal/runtime/worker-client.js",
39
+ "browser": "./dist/internal/runtime/worker-client.js",
40
+ "default": "./dist/internal/runtime/postgres-client.js"
41
+ }
42
+ },
29
43
  "exports": {
30
- ".": "./dist/index.js",
31
- "./internal/runtime/cloudflare-client": "./dist/internal/runtime/cloudflare-client.js",
32
- "./internal/runtime/cloudflare-vite": "./dist/internal/runtime/cloudflare-vite.js",
33
- "./internal/runtime/state": "./dist/internal/runtime/state.js",
34
- "./internal/runtime/vercel-client": "./dist/internal/runtime/vercel-client.js",
35
- "./internal/runtime/vercel-vite": "./dist/internal/runtime/vercel-vite.js",
36
- "./nuxt": "./dist/nuxt.js",
37
- "./runtime/hosted": "./dist/runtime/hosted.js",
38
- "./vite": "./dist/vite.js",
44
+ ".": {
45
+ "types": "./dist/index.d.ts",
46
+ "import": "./dist/index.js",
47
+ "default": "./dist/index.js"
48
+ },
49
+ "./durability": {
50
+ "types": "./dist/durability.d.ts",
51
+ "import": "./dist/durability.js",
52
+ "default": "./dist/durability.js"
53
+ },
54
+ "./runtime/hosted": {
55
+ "types": "./dist/runtime/hosted.d.ts",
56
+ "import": "./dist/runtime/hosted.js",
57
+ "default": "./dist/runtime/hosted.js"
58
+ },
59
+ "./vite": {
60
+ "types": "./dist/vite.d.ts",
61
+ "import": "./dist/vite.js",
62
+ "default": "./dist/vite.js"
63
+ },
39
64
  "./package.json": "./package.json"
40
65
  },
41
66
  "dependencies": {
42
- "@types/ws": "^8.18.1",
43
- "@vercel/functions": "^3.7.5",
44
- "@vercel/queue": "^0.0.0-alpha.40",
45
- "@vite-hub/runtime": "0.0.4",
67
+ "@vite-hub/runtime": "0.3.1",
46
68
  "defu": "^6.1.7",
47
- "esbuild": "^0.27.7",
48
- "h3": "2.0.1-rc.25",
49
- "pathe": "^2.0.3",
50
- "ws": "^8.21.0"
69
+ "nostics": "1.4.0",
70
+ "pathe": "^2.0.3"
51
71
  },
52
72
  "devDependencies": {
53
- "@types/node": "^24.13.3",
54
- "nuxt": "^4.5.2",
55
- "publint": "^0.3.21",
73
+ "@types/node": "^24.19.1",
74
+ "@vercel/functions": "^3.9.11",
75
+ "@vercel/queue": "^0.11.0",
76
+ "@vite-hub/database": "0.3.1",
77
+ "@vite-hub/internal": "0.0.1",
78
+ "postgres": "^3.4.9",
79
+ "publint": "^0.3.25",
56
80
  "typescript": "^6.0.3",
57
- "valibot": "^1.4.2",
58
- "vite": "^8.0.8",
59
- "vite-plus": "^0.1.24",
60
- "vitest": "^4.1.4",
61
- "@vite-hub/internal": "0.0.1"
81
+ "undici": "8.12.2",
82
+ "valibot": "^1.5.0",
83
+ "vite": "^8.2.2",
84
+ "vite-plus": "^0.3.3",
85
+ "vitest": "^4.1.11"
62
86
  },
63
87
  "peerDependencies": {
88
+ "@vercel/functions": "^3.9.11",
89
+ "@vercel/queue": "^0.11.0",
90
+ "postgres": "^3.4.9",
64
91
  "vite": ">=8.0.0"
65
92
  },
66
93
  "peerDependenciesMeta": {
94
+ "@vercel/functions": {
95
+ "optional": true
96
+ },
97
+ "@vercel/queue": {
98
+ "optional": true
99
+ },
100
+ "postgres": {
101
+ "optional": true
102
+ },
67
103
  "vite": {
68
104
  "optional": true
69
105
  }
70
106
  },
71
107
  "engines": {
72
- "node": ">=24.0.0"
108
+ "node": ">=22.19.0"
73
109
  },
74
110
  "scripts": {
75
111
  "build": "vp pack",
76
112
  "dev": "vp pack --watch",
77
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
78
- "test": "vp run -t @vite-hub/queue#build && vp test"
113
+ "typecheck": "vp run --cache -t @vite-hub/queue#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
114
+ "test": "vp run --cache -t @vite-hub/queue#build && vp test"
79
115
  }
80
116
  }
@@ -1,11 +0,0 @@
1
- //#region ../internal/src/runtime/app.d.ts
2
- type AppHandler = (request: Request, context?: Record<string, unknown>) => Response | Promise<Response>;
3
- type VitehubApp = AppHandler | {
4
- fetch?: AppHandler;
5
- request?: (request: Request, options?: RequestInit, context?: Record<string, unknown>) => Response | Promise<Response>;
6
- };
7
- //#endregion
8
- //#region src/runtime/_app.d.ts
9
- type QueueApp = VitehubApp;
10
- //#endregion
11
- export { QueueApp as t };
@@ -1,10 +0,0 @@
1
- //#region ../internal/src/runtime/app.ts
2
- function resolveAppFetch(label, app) {
3
- if (!app) return;
4
- if (typeof app === "function") return app;
5
- if (typeof app.request === "function") return (request, context) => app.request(request, void 0, context);
6
- if (typeof app.fetch === "function") return app.fetch.bind(app);
7
- throw new TypeError(`Invalid ${label} app. Expected an h3 app or a fetch-compatible handler.`);
8
- }
9
- //#endregion
10
- export { resolveAppFetch as t };
@@ -1,93 +0,0 @@
1
- import { t as normalizeQueueOptions } from "./config-CNgAeIND.js";
2
- import { i as isQueueBoundaryIdentity, l as normalizeQueueEnqueueInput, n as createQueueError, o as normalizePublicQueueIdentifier, s as runQueueProviderOperation } from "./errors-CjuG_qr-.js";
3
- import { t as getCloudflareQueueBindingName } from "./cloudflare-GosJefIK.js";
4
- import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
5
- import { a as getQueueRuntimeEvent, f as getCloudflareEnv, i as getQueueRuntimeConfig, n as getQueueClientCache, o as loadQueueDefinition, p as resolveWaitUntil, r as getQueueRuntimeClientFactory, s as runWithQueueRuntimeEvent } from "./state-Cno9O7YS.js";
6
- //#region src/runtime/client.ts
7
- function createQueueDefinitionNotFoundError(name) {
8
- const queue = normalizePublicQueueIdentifier(name);
9
- return createQueueError("QUEUE_DEFINITION_NOT_FOUND", { details: queue ? { queue } : void 0 });
10
- }
11
- async function loadNamedQueueDefinition(name) {
12
- try {
13
- return await loadQueueDefinition(name);
14
- } catch (cause) {
15
- if (isQueueBoundaryIdentity(cause)) throw cause;
16
- const queue = normalizePublicQueueIdentifier(name);
17
- throw createQueueError("QUEUE_DEFINITION_LOAD_FAILED", {
18
- cause,
19
- details: queue ? { queue } : void 0
20
- });
21
- }
22
- }
23
- function resolveCloudflareBinding(binding, name) {
24
- if (binding && typeof binding !== "string") return binding;
25
- const bindingName = binding || getCloudflareQueueBindingName(name);
26
- return getCloudflareEnv(getQueueRuntimeEvent())?.[bindingName] || bindingName;
27
- }
28
- function toProviderOptions(name, config) {
29
- if (config.provider === "cloudflare") return {
30
- ...config,
31
- binding: resolveCloudflareBinding(config.binding, name)
32
- };
33
- return {
34
- ...config,
35
- topic: getVercelQueueTopicName(name)
36
- };
37
- }
38
- function getActiveQueueConfig() {
39
- const config = getQueueRuntimeConfig();
40
- if (config === false) return false;
41
- return config || normalizeQueueOptions(void 0, { hosting: "vercel" });
42
- }
43
- function hasRequestScopedVercelRegion(config) {
44
- return config.provider === "vercel" && !config.region && !process.env.QUEUE_REGION && !process.env.VERCEL_REGION && typeof getQueueRuntimeEvent() !== "undefined";
45
- }
46
- async function createNamedQueueClient(name) {
47
- const config = getActiveQueueConfig();
48
- if (config === false) throw createQueueError("QUEUE_DISABLED");
49
- const provider = toProviderOptions(name, config);
50
- const createClient = getQueueRuntimeClientFactory();
51
- if (!createClient) throw new Error("[vitehub] Queue Client is installed by generated Provider Output.");
52
- return await runQueueProviderOperation(provider.provider, "create-client", () => createClient(provider));
53
- }
54
- async function getQueue(name) {
55
- const definition = await loadNamedQueueDefinition(name);
56
- if (!definition) throw createQueueDefinitionNotFoundError(name);
57
- const config = getActiveQueueConfig();
58
- if (definition.options?.cache === false || config === false || config.cache === false || config.provider === "cloudflare" || hasRequestScopedVercelRegion(config)) return await createNamedQueueClient(name);
59
- const cache = getQueueClientCache();
60
- const existing = cache.get(name);
61
- if (existing) return await existing;
62
- const pending = createNamedQueueClient(name).catch((error) => {
63
- cache.delete(name);
64
- throw error;
65
- });
66
- cache.set(name, pending);
67
- return await pending;
68
- }
69
- async function runQueue(name, input) {
70
- const normalized = normalizeQueueEnqueueInput(input);
71
- return await (await getQueue(name)).send({
72
- ...normalized.options,
73
- id: normalized.id,
74
- payload: normalized.payload
75
- });
76
- }
77
- function deferQueue(name, input) {
78
- const request = getQueueRuntimeEvent();
79
- const task = () => runWithQueueRuntimeEvent(request, () => runQueue(name, input));
80
- const handleError = async (error) => {
81
- console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
82
- try {
83
- await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
84
- } catch (hookError) {
85
- console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
86
- }
87
- };
88
- const promise = task().catch(handleError);
89
- const waitUntil = resolveWaitUntil(request);
90
- if (typeof waitUntil === "function") waitUntil(promise);
91
- }
92
- //#endregion
93
- export { getQueue as n, runQueue as r, deferQueue as t };
@@ -1,99 +0,0 @@
1
- import { l as normalizeQueueEnqueueInput, n as createQueueError, s as runQueueProviderOperation, t as cloudflareUnsupportedEnqueueOptions } from "./errors-CjuG_qr-.js";
2
- import { n as getCloudflareQueueDefinitionName } from "./cloudflare-GosJefIK.js";
3
- import { n as reportQueueDeliveryError, t as isNonRetryableQueueError } from "./delivery-error-glgYWC9g.js";
4
- //#region src/providers/cloudflare.ts
5
- function isCloudflareQueueBinding(binding) {
6
- return Boolean(binding) && typeof binding === "object" && typeof binding.send === "function" && typeof binding.sendBatch === "function";
7
- }
8
- function toSendOptions(options = {}) {
9
- const unsupported = cloudflareUnsupportedEnqueueOptions.filter((option) => options[option] !== void 0);
10
- if (unsupported.length) throw createQueueError("CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS", { details: {
11
- provider: "cloudflare",
12
- unsupported
13
- } });
14
- return {
15
- contentType: options.contentType,
16
- delaySeconds: options.delaySeconds
17
- };
18
- }
19
- function resolveAction(action, message, fallback) {
20
- if (action === "ack") {
21
- message.ack();
22
- return;
23
- }
24
- if (action === "retry") {
25
- message.retry();
26
- return;
27
- }
28
- if (action && typeof action === "object" && "retry" in action) {
29
- message.retry(action.retry);
30
- return;
31
- }
32
- if (fallback === "ack") message.ack();
33
- else message.retry();
34
- }
35
- function createCloudflareQueueBatchHandler(options) {
36
- const requested = Number(options.concurrency ?? 1);
37
- const concurrency = Number.isFinite(requested) ? Math.max(1, Math.floor(requested)) : 1;
38
- return async (batch) => {
39
- const messages = Array.isArray(batch?.messages) ? batch.messages : [];
40
- if (!messages.length) return;
41
- let index = 0;
42
- const worker = async () => {
43
- while (index < messages.length) {
44
- const message = messages[index++];
45
- try {
46
- await options.onMessage(message, batch);
47
- message.ack();
48
- } catch (error) {
49
- reportQueueDeliveryError(error, {
50
- attempts: message.attempts,
51
- id: message.id,
52
- provider: "cloudflare",
53
- queue: getCloudflareQueueDefinitionName(batch.queue)
54
- });
55
- resolveAction(options.onError ? await options.onError(error, message, batch) : void 0, message, isNonRetryableQueueError(error) ? "ack" : "retry");
56
- }
57
- }
58
- };
59
- await Promise.all(Array.from({ length: Math.min(concurrency, messages.length) }, () => worker()));
60
- };
61
- }
62
- function createCloudflareQueueClient(provider) {
63
- if (typeof provider.binding === "undefined" || typeof provider.binding === "string") throw createQueueError("CLOUDFLARE_BINDING_RESOLUTION_REQUIRED", { details: { provider: "cloudflare" } });
64
- if (!isCloudflareQueueBinding(provider.binding)) throw createQueueError("CLOUDFLARE_BINDING_INVALID", { details: { provider: "cloudflare" } });
65
- const binding = provider.binding;
66
- return {
67
- provider: "cloudflare",
68
- native: binding,
69
- binding,
70
- async send(input) {
71
- const normalized = normalizeQueueEnqueueInput(input);
72
- await runQueueProviderOperation("cloudflare", "send", () => binding.send(normalized.payload, toSendOptions(normalized.options)));
73
- return {
74
- status: "queued",
75
- messageId: normalized.id
76
- };
77
- },
78
- async sendBatch(items, options) {
79
- await runQueueProviderOperation("cloudflare", "send-batch", () => binding.sendBatch(items.map((item) => ({
80
- ...item,
81
- ...toSendOptions({
82
- ...options,
83
- contentType: item.contentType || options?.contentType,
84
- delaySeconds: item.delaySeconds ?? options?.delaySeconds
85
- })
86
- }))));
87
- return items.map(() => ({ status: "queued" }));
88
- },
89
- createBatchHandler: createCloudflareQueueBatchHandler
90
- };
91
- }
92
- //#endregion
93
- //#region src/internal/runtime/cloudflare-client.ts
94
- async function createCloudflareQueueRuntimeClient(options) {
95
- if (options.provider !== "cloudflare") throw new TypeError("[vitehub] Cloudflare Queue runtime received a non-Cloudflare provider.");
96
- return createCloudflareQueueClient(options);
97
- }
98
- //#endregion
99
- export { createCloudflareQueueBatchHandler as n, createCloudflareQueueRuntimeClient as t };
@@ -1,97 +0,0 @@
1
- import { t as normalizeQueueOptions } from "./config-CNgAeIND.js";
2
- import { n as getCloudflareQueueDefinitionName } from "./cloudflare-GosJefIK.js";
3
- import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "./cloudflare-client-w5vphoNn.js";
4
- import { t as getCloudflareQueueName } from "./cloudflare-resource-name-R8zYQiZb.js";
5
- import { c as setQueueRuntimeConfig, d as createCloudflareRuntimeEvent, m as runWithActiveCloudflareEnv, o as loadQueueDefinition, s as runWithQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "./state-Cno9O7YS.js";
6
- import { t as resolveAppFetch } from "./app-BZpq2cwC.js";
7
- //#region ../internal/src/runtime/cloudflare-hosted.ts
8
- function createWebRequestHandler(appHandler) {
9
- return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : new Response(JSON.stringify({
10
- status: 404,
11
- message: `Cannot find any route matching [${request.method}] ${request.url}`
12
- }), {
13
- headers: { "content-type": "application/json;charset=UTF-8" },
14
- status: 404,
15
- statusText: "Not Found"
16
- }));
17
- }
18
- function createCloudflareHostedWorker(adapter) {
19
- const requestHandler = createWebRequestHandler(resolveAppFetch(adapter.label, adapter.app));
20
- return { async fetch(request, env, context) {
21
- const handle = async (handlerContext) => await Promise.resolve(requestHandler(request, handlerContext));
22
- if (adapter.onRequest) return await adapter.onRequest({
23
- env,
24
- executionContext: context,
25
- handle
26
- });
27
- return await handle();
28
- } };
29
- }
30
- //#endregion
31
- //#region src/runtime/cloudflare-shared.ts
32
- function createQueueJob(message, batch) {
33
- return {
34
- attempts: typeof message.attempts === "number" ? message.attempts : 1,
35
- id: message.id,
36
- metadata: {
37
- batch,
38
- message
39
- },
40
- payload: message.body
41
- };
42
- }
43
- //#endregion
44
- //#region src/internal/runtime/cloudflare-vite.ts
45
- function createRegistryDefinitionNames(registry, namePrefix) {
46
- if (!registry) return void 0;
47
- const definitions = {};
48
- for (const name of Object.keys(registry)) {
49
- const physicalName = getCloudflareQueueName(name, namePrefix);
50
- if (definitions[physicalName]) throw new Error(`Queue names ${JSON.stringify(definitions[physicalName])} and ${JSON.stringify(name)} collide after Cloudflare resource name derivation.`);
51
- definitions[physicalName] = name;
52
- }
53
- return definitions;
54
- }
55
- function createQueueCloudflareWorker(options = {}) {
56
- const queueConfig = options.queue === false ? false : normalizeQueueOptions(options.queue, { hosting: "cloudflare" });
57
- const registry = options.registry;
58
- const definitions = options.definitions;
59
- const registryDefinitions = !definitions && queueConfig !== false && queueConfig.provider === "cloudflare" ? createRegistryDefinitionNames(registry, queueConfig.namePrefix ?? "") : void 0;
60
- const applyRuntimeState = () => {
61
- setQueueRuntimeConfig(queueConfig, createCloudflareQueueRuntimeClient);
62
- setQueueRuntimeRegistry(registry);
63
- };
64
- return {
65
- ...createCloudflareHostedWorker({
66
- app: options.app,
67
- label: "queue",
68
- async onRequest({ env, executionContext, handle }) {
69
- applyRuntimeState();
70
- const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
71
- return await runWithActiveCloudflareEnv(env, () => runWithQueueRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context)));
72
- }
73
- }),
74
- async queue(batch, env, context) {
75
- applyRuntimeState();
76
- if (queueConfig === false || queueConfig?.provider !== "cloudflare") return;
77
- const runtimeEvent = createCloudflareRuntimeEvent(env, context);
78
- await runWithActiveCloudflareEnv(env, async () => {
79
- const definitionName = definitions ? definitions[batch.queue] : registryDefinitions?.[batch.queue] ?? (/-[0-9a-f]{32}$/.test(batch.queue) && !/(?:^|-)queue--(?:[0-9a-f]{2})+$/i.test(batch.queue) || queueConfig.namePrefix && !batch.queue.startsWith(queueConfig.namePrefix) ? void 0 : getCloudflareQueueDefinitionName(batch.queue, queueConfig.namePrefix));
80
- if (!definitionName) throw new Error(`[vitehub] Cloudflare queue ${JSON.stringify(batch.queue)} is not mapped to a Queue Definition.`);
81
- const definition = await loadQueueDefinition(definitionName);
82
- if (!definition) throw new Error(`[vitehub] Cloudflare queue ${JSON.stringify(batch.queue)} maps to unknown Queue Definition ${JSON.stringify(definitionName)}.`);
83
- await createCloudflareQueueBatchHandler({
84
- concurrency: definition.options?.concurrency,
85
- onError: definition.options?.onError,
86
- onMessage: async (message, currentBatch) => {
87
- await runWithQueueRuntimeEvent(runtimeEvent, async () => {
88
- await definition.handler(createQueueJob(message, currentBatch));
89
- });
90
- }
91
- })(batch);
92
- });
93
- }
94
- };
95
- }
96
- //#endregion
97
- export { createQueueCloudflareWorker as t };
@@ -1,24 +0,0 @@
1
- import { i as CloudflareQueueMessageBatch, l as QueueDefinitionRegistry, y as ResolvedQueueOptions } from "./types-CwvoMATy.js";
2
- import { t as QueueApp } from "./_app-D29AwUdD.js";
3
-
4
- //#region ../internal/src/runtime/cloudflare-env.d.ts
5
- type CloudflareWorkerEnv = Record<string, unknown>;
6
- interface CloudflareWorkerExecutionContext {
7
- waitUntil?: (promise: Promise<unknown>) => void;
8
- }
9
- //#endregion
10
- //#region src/internal/runtime/cloudflare-vite.d.ts
11
- type CloudflareWorkerApp = QueueApp;
12
- interface QueueCloudflareWorkerOptions {
13
- app?: CloudflareWorkerApp;
14
- definitions?: Record<string, string>;
15
- queue?: false | ResolvedQueueOptions;
16
- registry?: QueueDefinitionRegistry;
17
- }
18
- interface QueueCloudflareWorker {
19
- fetch: (request: Request, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<Response>;
20
- queue: (batch: CloudflareQueueMessageBatch, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<void>;
21
- }
22
- declare function createQueueCloudflareWorker(options?: QueueCloudflareWorkerOptions): QueueCloudflareWorker;
23
- //#endregion
24
- export { createQueueCloudflareWorker as i, QueueCloudflareWorker as n, QueueCloudflareWorkerOptions as r, CloudflareWorkerApp as t };
@@ -1,53 +0,0 @@
1
- import { defu } from "defu";
2
- function deploymentPresetFromNitro(value) {
3
- const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
4
- if (!normalized) return;
5
- if (normalized.startsWith("cloudflare")) return "cloudflare";
6
- if (normalized.startsWith("deno")) return "deno";
7
- if (normalized.startsWith("netlify")) return "netlify";
8
- if (normalized === "node" || normalized.startsWith("node-")) return "node";
9
- if (normalized.startsWith("vercel")) return "vercel";
10
- }
11
- //#endregion
12
- //#region ../internal/src/hosting.ts
13
- function normalizeHosting(hosting) {
14
- const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
15
- if (normalized === "cloudflare") return "cloudflare-module";
16
- return normalized;
17
- }
18
- function getHostingProvider(hosting) {
19
- const preset = deploymentPresetFromNitro(hosting);
20
- if (preset === "cloudflare" || preset === "netlify" || preset === "vercel") return preset;
21
- }
22
- //#endregion
23
- //#region ../internal/src/object.ts
24
- function isPlainObject(value) {
25
- if (value === null || Object(value) !== value || Array.isArray(value)) return false;
26
- try {
27
- Function.prototype.toString.call(value);
28
- return false;
29
- } catch {
30
- return true;
31
- }
32
- }
33
- //#endregion
34
- //#region src/config.ts
35
- const knownProviders = new Set(["cloudflare", "vercel"]);
36
- function resolveProvider(options, hosting) {
37
- const shared = typeof options.cache === "boolean" ? { cache: options.cache } : {};
38
- const provider = options.provider;
39
- if (typeof provider === "string" && !knownProviders.has(provider)) throw new TypeError(`Unknown \`queue.provider\`: ${JSON.stringify(provider)}. Expected "cloudflare" or "vercel".`);
40
- if (typeof provider === "undefined" && hosting && !hosting.includes("cloudflare") && !hosting.includes("vercel")) throw new TypeError("`queue.provider` cannot be inferred for " + hosting + " hosting. Disable `queue` or select the Cloudflare or Vercel deployment preset.");
41
- if ((provider || (hosting.includes("cloudflare") ? "cloudflare" : "vercel")) === "cloudflare") return defu({
42
- ...typeof options.binding === "string" ? { binding: options.binding } : {},
43
- ...typeof options.namePrefix === "string" ? { namePrefix: options.namePrefix } : {}
44
- }, shared, { provider: "cloudflare" });
45
- return defu(typeof options.region === "string" ? { region: options.region } : {}, shared, { provider: "vercel" });
46
- }
47
- function normalizeQueueOptions(options, input = {}) {
48
- if (options === false) return void 0;
49
- if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`queue` must be a plain object.");
50
- return resolveProvider(options || {}, normalizeHosting(input.hosting));
51
- }
52
- //#endregion
53
- export { isPlainObject as n, getHostingProvider as r, normalizeQueueOptions as t };
@@ -1,45 +0,0 @@
1
- import { a as isQueueOwnedError, o as normalizePublicQueueIdentifier, r as getQueueErrorPublicShape } from "./errors-CjuG_qr-.js";
2
- //#region src/internal/delivery-error.ts
3
- const nonRetryableBuiltInCodes = new Set([
4
- "CLOUDFLARE_BINDING_INVALID",
5
- "CLOUDFLARE_BINDING_RESOLUTION_REQUIRED",
6
- "CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS",
7
- "QUEUE_DEFINITION_LOAD_FAILED",
8
- "QUEUE_DEFINITION_NOT_FOUND",
9
- "QUEUE_DISABLED",
10
- "VERCEL_PROVIDER_EXPECTED",
11
- "VERCEL_QUEUE_REGION_REQUIRED",
12
- "VERCEL_QUEUE_SDK_INVALID",
13
- "VERCEL_QUEUE_SDK_LOAD_FAILED",
14
- "VERCEL_TOPIC_RESOLUTION_REQUIRED",
15
- "VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS"
16
- ]);
17
- function isNonRetryableQueueError(error) {
18
- const shape = getQueueErrorPublicShape(error);
19
- return isQueueOwnedError(error) && shape !== void 0 && nonRetryableBuiltInCodes.has(shape.code);
20
- }
21
- function createQueueDeliveryErrorReport(error, context) {
22
- const queueError = getQueueErrorPublicShape(error);
23
- const id = normalizePublicQueueIdentifier(context.id);
24
- const queue = normalizePublicQueueIdentifier(context.queue);
25
- return {
26
- attempts: context.attempts,
27
- provider: context.provider,
28
- ...id ? { id } : {},
29
- ...queue ? { queue } : {},
30
- error: {
31
- ...queueError ? {
32
- code: queueError.code,
33
- details: queueError.details
34
- } : {},
35
- message: queueError?.message ?? "[vitehub] Queue Delivery failed.",
36
- name: queueError ? "ViteHubError" : "Error"
37
- },
38
- retryable: !isNonRetryableQueueError(error)
39
- };
40
- }
41
- function reportQueueDeliveryError(error, context) {
42
- console.error("[vitehub:queue] Queue Delivery failed.", createQueueDeliveryErrorReport(error, context));
43
- }
44
- //#endregion
45
- export { reportQueueDeliveryError as n, isNonRetryableQueueError as t };