@vite-hub/queue 0.0.0 → 0.0.2

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 (37) hide show
  1. package/README.md +89 -1
  2. package/dist/_app-D29AwUdD.d.ts +11 -0
  3. package/dist/app-BZpq2cwC.js +10 -0
  4. package/dist/client-CBDT9GL9.js +93 -0
  5. package/dist/cloudflare-GosJefIK.js +26 -0
  6. package/dist/cloudflare-client-w5vphoNn.js +99 -0
  7. package/dist/cloudflare-resource-name-R8zYQiZb.js +34 -0
  8. package/dist/cloudflare-vite-BNBVtEwG.js +92 -0
  9. package/dist/cloudflare-vite-krY8T3zM.d.ts +24 -0
  10. package/dist/config-B7xkD1v0.js +47 -0
  11. package/dist/delivery-error-glgYWC9g.js +45 -0
  12. package/dist/errors-CjuG_qr-.js +108 -0
  13. package/dist/index.d.ts +91 -0
  14. package/dist/index.js +28 -0
  15. package/dist/internal/runtime/cloudflare-client.d.ts +6 -0
  16. package/dist/internal/runtime/cloudflare-client.js +2 -0
  17. package/dist/internal/runtime/vercel-client.d.ts +6 -0
  18. package/dist/internal/runtime/vercel-client.js +114 -0
  19. package/dist/nuxt.d.ts +19 -0
  20. package/dist/nuxt.js +29 -0
  21. package/dist/runtime/cloudflare-vite.d.ts +2 -0
  22. package/dist/runtime/cloudflare-vite.js +2 -0
  23. package/dist/runtime/hosted.d.ts +11 -0
  24. package/dist/runtime/hosted.js +53 -0
  25. package/dist/runtime/state.d.ts +16 -0
  26. package/dist/runtime/state.js +2 -0
  27. package/dist/runtime/vercel-vite.d.ts +20 -0
  28. package/dist/runtime/vercel-vite.js +49 -0
  29. package/dist/state-BfUFGeC2.js +105 -0
  30. package/dist/types-CwvoMATy.d.ts +169 -0
  31. package/dist/vercel-C_4vqxcl.js +8 -0
  32. package/dist/vercel-runtime-package-copy-B8AEFWXT.js +66 -0
  33. package/dist/virtual.d.ts +4 -0
  34. package/dist/vite-C6yK76Sw.js +1823 -0
  35. package/dist/vite.d.ts +129 -0
  36. package/dist/vite.js +2 -0
  37. package/package.json +73 -5
@@ -0,0 +1,108 @@
1
+ import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
2
+ //#region src/enqueue.ts
3
+ const envelopeKeys = new Set([
4
+ "contentType",
5
+ "delaySeconds",
6
+ "id",
7
+ "idempotencyKey",
8
+ "region",
9
+ "retentionSeconds"
10
+ ]);
11
+ let fallbackCounter = 0;
12
+ function createQueueMessageId(prefix = "queue") {
13
+ const uuid = globalThis.crypto?.randomUUID?.();
14
+ if (uuid) return `${prefix}_${uuid}`;
15
+ fallbackCounter = fallbackCounter + 1 >>> 0;
16
+ return `${prefix}_${Date.now().toString(36)}_${fallbackCounter.toString(36)}`;
17
+ }
18
+ function isQueueEnvelope(input) {
19
+ if (typeof input !== "object" || input === null || Array.isArray(input) || !("payload" in input)) return false;
20
+ return Object.keys(input).every((key) => key === "payload" || envelopeKeys.has(key));
21
+ }
22
+ function normalizeQueueEnqueueInput(input) {
23
+ if (!isQueueEnvelope(input)) return {
24
+ id: createQueueMessageId(),
25
+ options: {},
26
+ payload: input
27
+ };
28
+ const { contentType, delaySeconds, id, idempotencyKey, payload, region, retentionSeconds } = input;
29
+ const options = {
30
+ ...contentType !== void 0 ? { contentType } : {},
31
+ ...delaySeconds !== void 0 ? { delaySeconds } : {},
32
+ ...idempotencyKey !== void 0 ? { idempotencyKey } : {},
33
+ ...region !== void 0 ? { region } : {},
34
+ ...retentionSeconds !== void 0 ? { retentionSeconds } : {}
35
+ };
36
+ return {
37
+ id: typeof id === "string" && id.length > 0 ? id : createQueueMessageId(),
38
+ options,
39
+ payload
40
+ };
41
+ }
42
+ //#endregion
43
+ //#region src/errors.ts
44
+ const cloudflareUnsupportedEnqueueOptions = [
45
+ "idempotencyKey",
46
+ "region",
47
+ "retentionSeconds"
48
+ ];
49
+ const queueErrorMessages = {
50
+ CLOUDFLARE_BINDING_INVALID: "[vitehub] Cloudflare queue binding is invalid.",
51
+ CLOUDFLARE_BINDING_RESOLUTION_REQUIRED: "[vitehub] Cloudflare queue requires a concrete request-scoped binding.",
52
+ CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS: "[vitehub] Cloudflare queue does not support one or more enqueue options.",
53
+ QUEUE_DEFINITION_LOAD_FAILED: "[vitehub] Queue Definition could not be loaded.",
54
+ QUEUE_DEFINITION_NOT_FOUND: "[vitehub] Queue Definition is not registered. Queue Runtime Registry is installed by generated Provider Output.",
55
+ QUEUE_DISABLED: "[vitehub] Queue runtime is disabled.",
56
+ QUEUE_PROVIDER_OPERATION_FAILED: "[vitehub] Queue provider operation failed.",
57
+ QUEUE_PROVIDER_RESPONSE_INVALID: "[vitehub] Vercel queue provider returned an invalid send response.",
58
+ VERCEL_PROVIDER_EXPECTED: "[vitehub] Hosted Vercel Queue Delivery requires the Vercel provider.",
59
+ VERCEL_QUEUE_REGION_REQUIRED: "[vitehub] Vercel queue region could not be resolved.",
60
+ VERCEL_QUEUE_SDK_INVALID: "[vitehub] Vercel queue SDK does not expose the expected client API.",
61
+ VERCEL_QUEUE_SDK_LOAD_FAILED: "[vitehub] Vercel queue SDK could not be loaded.",
62
+ VERCEL_TOPIC_RESOLUTION_REQUIRED: "[vitehub] Vercel queue requires a concrete topic.",
63
+ VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS: "[vitehub] Vercel queue does not support one or more enqueue options."
64
+ };
65
+ const queueOwnedErrors = /* @__PURE__ */ new WeakSet();
66
+ function createQueueError(code, options = {}) {
67
+ const details = options.details;
68
+ const error = new ViteHubError(code, code === "QUEUE_PROVIDER_OPERATION_FAILED" && details && "provider" in details && "operation" in details ? `[vitehub] ${details.provider} queue provider failed during ${details.operation}.` : queueErrorMessages[code], options);
69
+ queueOwnedErrors.add(error);
70
+ return error;
71
+ }
72
+ function isQueueOwnedError(error) {
73
+ return typeof error === "object" && error !== null && queueOwnedErrors.has(error);
74
+ }
75
+ function getQueueErrorPublicShape(error) {
76
+ return getViteHubErrorShape(error);
77
+ }
78
+ function normalizePublicQueueIdentifier(value) {
79
+ if (typeof value !== "string" || !value || value.length > 128 || value.trim() !== value) return;
80
+ if (!/^[a-z\d][a-z\d._/-]*$/i.test(value)) return;
81
+ if (/^[a-z][a-z\d+.-]*:\/\//i.test(value) || /^[a-z]:\//i.test(value)) return;
82
+ if (value.split("/").some((part) => part === "." || part === "..")) return;
83
+ return value;
84
+ }
85
+ function isQueueBoundaryIdentity(error) {
86
+ if (getViteHubErrorShape(error)) return true;
87
+ try {
88
+ return error instanceof Error && error.name === "AbortError";
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+ async function runQueueProviderOperation(provider, operation, run) {
94
+ try {
95
+ return await run();
96
+ } catch (cause) {
97
+ if (isQueueBoundaryIdentity(cause)) throw cause;
98
+ throw createQueueError("QUEUE_PROVIDER_OPERATION_FAILED", {
99
+ cause,
100
+ details: {
101
+ operation,
102
+ provider
103
+ }
104
+ });
105
+ }
106
+ }
107
+ //#endregion
108
+ export { isQueueOwnedError as a, createQueueMessageId as c, isQueueBoundaryIdentity as i, normalizeQueueEnqueueInput as l, createQueueError as n, normalizePublicQueueIdentifier as o, getQueueErrorPublicShape as r, runQueueProviderOperation as s, cloudflareUnsupportedEnqueueOptions as t };
@@ -0,0 +1,91 @@
1
+ import { C as VercelQueueRetryHandler, S as VercelQueueRetryDirective, _ as QueueProviderOptions, a as DiscoveredQueueDefinition, b as VercelQueueCallbackOptions, c as QueueDefinitionOptions, d as QueueEnqueueOptions, f as QueueHandler, g as QueueProvider, h as QueueModuleProviderOptions, i as CloudflareQueueMessageBatch, l as QueueDefinitionRegistry, m as QueueModuleOptions, n as CloudflareQueueClient, o as QueueClient, p as QueueJob, r as CloudflareQueueMessage, s as QueueDefinition, t as CloudflareQueueBatchHandlerOptions, u as QueueEnqueueInput, v as QueueSendResult, w as VercelQueueSendResult, x as VercelQueueClient, y as ResolvedQueueOptions } from "./types-CwvoMATy.js";
2
+ import { i as createQueueCloudflareWorker } from "./cloudflare-vite-krY8T3zM.js";
3
+ import { ViteHubError, ViteHubErrorDetails } from "@vite-hub/runtime";
4
+
5
+ //#region src/config.d.ts
6
+ interface QueueResolutionInput {
7
+ hosting?: string;
8
+ }
9
+ declare function normalizeQueueOptions(options: QueueModuleOptions | undefined, input?: QueueResolutionInput): ResolvedQueueOptions | undefined;
10
+ //#endregion
11
+ //#region src/definition.d.ts
12
+ declare function defineQueue<TPayload = unknown, TResult = unknown>(handler: QueueHandler<TPayload, TResult>, options?: QueueDefinitionOptions): QueueDefinition<TPayload, TResult>;
13
+ //#endregion
14
+ //#region src/enqueue.d.ts
15
+ declare function createQueueMessageId(prefix?: string): string;
16
+ //#endregion
17
+ //#region src/errors.d.ts
18
+ type QueueProviderOperation = "create-client" | "load-sdk" | "send" | "send-batch";
19
+ declare const cloudflareUnsupportedEnqueueOptions: readonly ["idempotencyKey", "region", "retentionSeconds"];
20
+ type QueueErrorCode = "CLOUDFLARE_BINDING_INVALID" | "CLOUDFLARE_BINDING_RESOLUTION_REQUIRED" | "CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS" | "QUEUE_DEFINITION_LOAD_FAILED" | "QUEUE_DEFINITION_NOT_FOUND" | "QUEUE_DISABLED" | "QUEUE_PROVIDER_OPERATION_FAILED" | "QUEUE_PROVIDER_RESPONSE_INVALID" | "VERCEL_PROVIDER_EXPECTED" | "VERCEL_QUEUE_REGION_REQUIRED" | "VERCEL_QUEUE_SDK_INVALID" | "VERCEL_QUEUE_SDK_LOAD_FAILED" | "VERCEL_TOPIC_RESOLUTION_REQUIRED" | "VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS";
21
+ type QueueErrorDetailMap = {
22
+ CLOUDFLARE_BINDING_INVALID: {
23
+ readonly provider: "cloudflare";
24
+ };
25
+ CLOUDFLARE_BINDING_RESOLUTION_REQUIRED: {
26
+ readonly provider: "cloudflare";
27
+ };
28
+ CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS: {
29
+ readonly provider: "cloudflare";
30
+ readonly unsupported: readonly (typeof cloudflareUnsupportedEnqueueOptions)[number][];
31
+ };
32
+ QUEUE_DEFINITION_LOAD_FAILED: {
33
+ readonly queue?: string;
34
+ };
35
+ QUEUE_DEFINITION_NOT_FOUND: {
36
+ readonly queue?: string;
37
+ };
38
+ QUEUE_DISABLED: ViteHubErrorDetails;
39
+ QUEUE_PROVIDER_OPERATION_FAILED: {
40
+ readonly operation: Exclude<QueueProviderOperation, "load-sdk">;
41
+ readonly provider: QueueProvider;
42
+ };
43
+ QUEUE_PROVIDER_RESPONSE_INVALID: {
44
+ readonly operation: "send";
45
+ readonly provider: "vercel";
46
+ };
47
+ VERCEL_PROVIDER_EXPECTED: {
48
+ readonly provider: QueueProvider;
49
+ };
50
+ VERCEL_QUEUE_REGION_REQUIRED: {
51
+ readonly provider: "vercel";
52
+ };
53
+ VERCEL_QUEUE_SDK_INVALID: {
54
+ readonly provider: "vercel";
55
+ };
56
+ VERCEL_QUEUE_SDK_LOAD_FAILED: {
57
+ readonly operation: "load-sdk";
58
+ readonly provider: "vercel";
59
+ };
60
+ VERCEL_TOPIC_RESOLUTION_REQUIRED: {
61
+ readonly provider: "vercel";
62
+ };
63
+ VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS: {
64
+ readonly provider: "vercel";
65
+ readonly unsupported: readonly "contentType"[];
66
+ };
67
+ };
68
+ type QueueErrorDetails<TCode extends QueueErrorCode = QueueErrorCode> = QueueErrorDetailMap[TCode];
69
+ //#endregion
70
+ //#region src/providers/cloudflare.d.ts
71
+ declare function createCloudflareQueueBatchHandler<TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>): (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
72
+ //#endregion
73
+ //#region src/integrations/cloudflare.d.ts
74
+ declare function getCloudflareQueueBindingName(name: string): string;
75
+ declare function getCloudflareQueueDefinitionName(name: string, namePrefix?: string): string;
76
+ //#endregion
77
+ //#region src/internal/cloudflare-resource-name.d.ts
78
+ declare function getCloudflareQueueName(name: string, namePrefix?: string): string;
79
+ //#endregion
80
+ //#region src/integrations/vercel.d.ts
81
+ declare function getVercelQueueTopicName(name: string): string;
82
+ //#endregion
83
+ //#region src/runtime/client.d.ts
84
+ declare function getQueue(name: string): Promise<QueueClient>;
85
+ declare function runQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): Promise<QueueSendResult>;
86
+ declare function deferQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): void;
87
+ //#endregion
88
+ //#region src/runtime/create-client.d.ts
89
+ declare function createQueueClient(options: QueueProviderOptions): Promise<QueueClient>;
90
+ //#endregion
91
+ export { type CloudflareQueueBatchHandlerOptions, type CloudflareQueueClient, type CloudflareQueueMessage, type CloudflareQueueMessageBatch, type DiscoveredQueueDefinition, type QueueClient, type QueueDefinition, type QueueDefinitionOptions, type QueueDefinitionRegistry, type QueueEnqueueInput, type QueueEnqueueOptions, type QueueErrorCode, type QueueErrorDetails, type QueueHandler, type QueueJob, type QueueModuleOptions, type QueueModuleProviderOptions, type QueueProvider, type QueueProviderOperation, type QueueProviderOptions, type QueueSendResult, type ResolvedQueueOptions, type VercelQueueCallbackOptions, type VercelQueueClient, type VercelQueueRetryDirective, type VercelQueueRetryHandler, type VercelQueueSendResult, createCloudflareQueueBatchHandler, createQueueClient, createQueueCloudflareWorker, createQueueMessageId, deferQueue, defineQueue, getCloudflareQueueBindingName, getCloudflareQueueDefinitionName, getCloudflareQueueName, getQueue, getVercelQueueTopicName, normalizeQueueOptions, runQueue };
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import { t as normalizeQueueOptions } from "./config-B7xkD1v0.js";
2
+ import { c as createQueueMessageId } from "./errors-CjuG_qr-.js";
3
+ import { n as getCloudflareQueueDefinitionName, t as getCloudflareQueueBindingName } from "./cloudflare-GosJefIK.js";
4
+ import { n as createCloudflareQueueBatchHandler } from "./cloudflare-client-w5vphoNn.js";
5
+ import { t as getCloudflareQueueName } from "./cloudflare-resource-name-R8zYQiZb.js";
6
+ import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
7
+ import { n as getQueue, r as runQueue, t as deferQueue } from "./client-CBDT9GL9.js";
8
+ import { t as createQueueCloudflareWorker } from "./cloudflare-vite-BNBVtEwG.js";
9
+ //#region src/definition.ts
10
+ function defineQueue(handler, options) {
11
+ if (typeof handler !== "function") throw new TypeError("`defineQueue()` requires a queue handler.");
12
+ return {
13
+ handler,
14
+ options
15
+ };
16
+ }
17
+ //#endregion
18
+ //#region src/runtime/create-client.ts
19
+ async function createQueueClient(options) {
20
+ if (options.provider === "cloudflare") {
21
+ const { createCloudflareQueueRuntimeClient } = await import("./internal/runtime/cloudflare-client.js");
22
+ return await createCloudflareQueueRuntimeClient(options);
23
+ }
24
+ const { createVercelQueueRuntimeClient } = await import("./internal/runtime/vercel-client.js");
25
+ return await createVercelQueueRuntimeClient(options);
26
+ }
27
+ //#endregion
28
+ export { createCloudflareQueueBatchHandler, createQueueClient, createQueueCloudflareWorker, createQueueMessageId, deferQueue, defineQueue, getCloudflareQueueBindingName, getCloudflareQueueDefinitionName, getCloudflareQueueName, getQueue, getVercelQueueTopicName, normalizeQueueOptions, runQueue };
@@ -0,0 +1,6 @@
1
+ import { _ as QueueProviderOptions, o as QueueClient } from "../../types-CwvoMATy.js";
2
+
3
+ //#region src/internal/runtime/cloudflare-client.d.ts
4
+ declare function createCloudflareQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
5
+ //#endregion
6
+ export { createCloudflareQueueRuntimeClient };
@@ -0,0 +1,2 @@
1
+ import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-w5vphoNn.js";
2
+ export { createCloudflareQueueRuntimeClient };
@@ -0,0 +1,6 @@
1
+ import { _ as QueueProviderOptions, o as QueueClient } from "../../types-CwvoMATy.js";
2
+
3
+ //#region src/internal/runtime/vercel-client.d.ts
4
+ declare function createVercelQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
5
+ //#endregion
6
+ export { createVercelQueueRuntimeClient };
@@ -0,0 +1,114 @@
1
+ import { i as isQueueBoundaryIdentity, l as normalizeQueueEnqueueInput, n as createQueueError, s as runQueueProviderOperation } from "../../errors-CjuG_qr-.js";
2
+ import { a as getQueueRuntimeEvent } from "../../state-BfUFGeC2.js";
3
+ //#region src/providers/vercel.ts
4
+ function readHeader(headers, name) {
5
+ if (!headers) return;
6
+ if (headers instanceof Headers) return headers.get(name) || void 0;
7
+ const value = headers[name] ?? headers[name.toLowerCase()];
8
+ if (typeof value === "string") return value;
9
+ if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
10
+ }
11
+ function parseRegionFromVercelId(value) {
12
+ if (!value) return;
13
+ return value.match(/^([a-z0-9]+)::/i)?.[1]?.toLowerCase();
14
+ }
15
+ function resolveVercelRegion(explicitRegion) {
16
+ if (explicitRegion) return explicitRegion;
17
+ if (typeof process.env.QUEUE_REGION === "string" && process.env.QUEUE_REGION) return process.env.QUEUE_REGION;
18
+ if (typeof process.env.VERCEL_REGION === "string" && process.env.VERCEL_REGION) return process.env.VERCEL_REGION;
19
+ const event = getQueueRuntimeEvent();
20
+ const requestHeaders = event?.request instanceof Request ? event.request.headers : event?.req?.headers ?? event?.node?.req?.headers;
21
+ return readHeader(requestHeaders, "ce-vqsregion") || parseRegionFromVercelId(readHeader(requestHeaders, "x-vercel-id"));
22
+ }
23
+ function invalidVercelSendResponse(cause) {
24
+ throw createQueueError("QUEUE_PROVIDER_RESPONSE_INVALID", {
25
+ cause,
26
+ details: {
27
+ operation: "send",
28
+ provider: "vercel"
29
+ }
30
+ });
31
+ }
32
+ function parseVercelMessageId(value) {
33
+ if (!value || typeof value !== "object" || Array.isArray(value)) invalidVercelSendResponse(value);
34
+ let messageId;
35
+ try {
36
+ messageId = Reflect.get(value, "messageId");
37
+ } catch (cause) {
38
+ invalidVercelSendResponse(cause);
39
+ }
40
+ if (messageId === void 0 || messageId === null) return;
41
+ if (typeof messageId !== "string" || !messageId || messageId.length > 128 || messageId.trim() !== messageId) invalidVercelSendResponse(value);
42
+ return messageId;
43
+ }
44
+ async function loadVercelQueueClient(region) {
45
+ let module;
46
+ try {
47
+ const loaded = globalThis.__vitehubVercelQueue;
48
+ if (loaded && typeof loaded === "object") module = loaded;
49
+ else {
50
+ const importVercelQueue = new Function("specifier", "return import(specifier)");
51
+ const specifier = "@vercel/queue";
52
+ try {
53
+ module = await importVercelQueue(specifier);
54
+ } catch (error) {
55
+ if (!(error instanceof TypeError) || !/dynamic import callback/i.test(error.message)) throw error;
56
+ module = await import(specifier);
57
+ }
58
+ }
59
+ } catch (error) {
60
+ if (isQueueBoundaryIdentity(error)) throw error;
61
+ throw createQueueError("VERCEL_QUEUE_SDK_LOAD_FAILED", {
62
+ cause: error,
63
+ details: {
64
+ operation: "load-sdk",
65
+ provider: "vercel"
66
+ }
67
+ });
68
+ }
69
+ const resolvedRegion = resolveVercelRegion(region);
70
+ if ("QueueClient" in module && typeof module.QueueClient === "function") {
71
+ if (!resolvedRegion) throw createQueueError("VERCEL_QUEUE_REGION_REQUIRED", { details: { provider: "vercel" } });
72
+ return new module.QueueClient({ region: resolvedRegion });
73
+ }
74
+ if (typeof module.send === "function" && typeof module.handleCallback === "function") return {
75
+ handleCallback: module.handleCallback,
76
+ send: module.send
77
+ };
78
+ throw createQueueError("VERCEL_QUEUE_SDK_INVALID", { details: { provider: "vercel" } });
79
+ }
80
+ async function createVercelQueueClient(provider) {
81
+ const topic = provider.topic;
82
+ if (!topic) throw createQueueError("VERCEL_TOPIC_RESOLUTION_REQUIRED", { details: { provider: "vercel" } });
83
+ const client = provider.client || await loadVercelQueueClient(provider.region);
84
+ return {
85
+ provider: "vercel",
86
+ native: client,
87
+ topic,
88
+ async send(input) {
89
+ const normalized = normalizeQueueEnqueueInput(input);
90
+ if (normalized.options.contentType !== void 0) throw createQueueError("VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS", { details: {
91
+ provider: "vercel",
92
+ unsupported: ["contentType"]
93
+ } });
94
+ return {
95
+ status: "queued",
96
+ messageId: await runQueueProviderOperation("vercel", "send", async () => parseVercelMessageId(await client.send(topic, normalized.payload, {
97
+ delaySeconds: normalized.options.delaySeconds,
98
+ idempotencyKey: normalized.options.idempotencyKey || normalized.id,
99
+ region: normalized.options.region ?? provider.region,
100
+ retentionSeconds: normalized.options.retentionSeconds
101
+ })))
102
+ };
103
+ },
104
+ callback: client.handleCallback.bind(client)
105
+ };
106
+ }
107
+ //#endregion
108
+ //#region src/internal/runtime/vercel-client.ts
109
+ async function createVercelQueueRuntimeClient(options) {
110
+ if (options.provider !== "vercel") throw new TypeError("[vitehub] Vercel Queue runtime received a non-Vercel provider.");
111
+ return await createVercelQueueClient(options);
112
+ }
113
+ //#endregion
114
+ export { createVercelQueueRuntimeClient };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { m as QueueModuleOptions } from "./types-CwvoMATy.js";
2
+
3
+ //#region src/nuxt.d.ts
4
+ type QueueNuxtModuleOptions = QueueModuleOptions;
5
+ type NuxtLike = {
6
+ hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
7
+ options: {
8
+ dev?: boolean;
9
+ rootDir?: string;
10
+ serverDir?: string;
11
+ srcDir?: string;
12
+ vite?: {
13
+ plugins?: unknown[];
14
+ };
15
+ };
16
+ };
17
+ declare function viteHubQueueNuxtModule(options?: QueueNuxtModuleOptions, nuxt?: NuxtLike): void;
18
+ //#endregion
19
+ export { QueueNuxtModuleOptions, viteHubQueueNuxtModule as default };
package/dist/nuxt.js ADDED
@@ -0,0 +1,29 @@
1
+ import { n as hubQueue, t as createQueueNitroConfig } from "./vite-C6yK76Sw.js";
2
+ //#region src/nuxt.ts
3
+ function isQueueVitePlugin(value) {
4
+ return Boolean(value && typeof value === "object" && value.name === "@vite-hub/queue/vite");
5
+ }
6
+ function findQueueVitePlugin(plugins) {
7
+ return plugins.flat(Infinity).find(isQueueVitePlugin);
8
+ }
9
+ function viteHubQueueNuxtModule(options = {}, nuxt) {
10
+ if (!nuxt) return;
11
+ nuxt.options.vite ??= {};
12
+ const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
13
+ const existingPlugin = findQueueVitePlugin(plugins);
14
+ const plugin = existingPlugin || hubQueue(options);
15
+ if (!existingPlugin) plugins.push(plugin);
16
+ nuxt.options.vite.plugins = plugins;
17
+ nuxt.hook?.("nitro:config", async (nitroConfig) => {
18
+ const projectRoot = nuxt.options.rootDir || process.cwd();
19
+ const nitro = await createQueueNitroConfig(plugin, {
20
+ nitro: nitroConfig,
21
+ projectRoot,
22
+ root: nuxt.options.srcDir || projectRoot,
23
+ serverDirs: nuxt.options.serverDir ? [nuxt.options.serverDir] : void 0
24
+ });
25
+ Object.assign(nitroConfig, nitro);
26
+ });
27
+ }
28
+ //#endregion
29
+ export { viteHubQueueNuxtModule as default };
@@ -0,0 +1,2 @@
1
+ import { i as createQueueCloudflareWorker, n as QueueCloudflareWorker, r as QueueCloudflareWorkerOptions, t as CloudflareWorkerApp } from "../cloudflare-vite-krY8T3zM.js";
2
+ export { CloudflareWorkerApp, QueueCloudflareWorker, QueueCloudflareWorkerOptions, createQueueCloudflareWorker };
@@ -0,0 +1,2 @@
1
+ import { t as createQueueCloudflareWorker } from "../cloudflare-vite-BNBVtEwG.js";
2
+ export { createQueueCloudflareWorker };
@@ -0,0 +1,11 @@
1
+ import { s as QueueDefinition } from "../types-CwvoMATy.js";
2
+ import { waitUntil } from "@vercel/functions";
3
+
4
+ //#region src/runtime/hosted.d.ts
5
+ declare const hostedVercelWaitUntil: typeof waitUntil;
6
+ declare function handleHostedVercelQueueCallback(event: {
7
+ method?: string;
8
+ request?: Request;
9
+ }, name: string, definition: QueueDefinition): Promise<unknown>;
10
+ //#endregion
11
+ export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
@@ -0,0 +1,53 @@
1
+ import { n as createQueueError } from "../errors-CjuG_qr-.js";
2
+ import { n as reportQueueDeliveryError, t as isNonRetryableQueueError } from "../delivery-error-glgYWC9g.js";
3
+ import { n as getQueue } from "../client-CBDT9GL9.js";
4
+ import { waitUntil } from "@vercel/functions";
5
+ import { getRequestHeaders, getRequestURL, readRawBody } from "h3";
6
+ //#region src/runtime/hosted.ts
7
+ const hostedVercelWaitUntil = waitUntil;
8
+ async function toRequest(event) {
9
+ if (event.request instanceof Request) return event.request;
10
+ const h3Event = event;
11
+ const body = await readRawBody(h3Event);
12
+ return new Request(getRequestURL(h3Event), {
13
+ body: body || void 0,
14
+ headers: getRequestHeaders(h3Event),
15
+ method: event.method || "POST"
16
+ });
17
+ }
18
+ function createVercelJobHandler(definition) {
19
+ return async (payload, metadata) => {
20
+ const meta = metadata;
21
+ await definition.handler({
22
+ attempts: typeof meta?.deliveryCount === "number" ? meta.deliveryCount : 1,
23
+ id: typeof meta?.messageId === "string" ? meta.messageId : "vercel-message",
24
+ metadata,
25
+ payload
26
+ });
27
+ };
28
+ }
29
+ function createVercelCallbackOptions(name, options) {
30
+ const retry = options?.retry;
31
+ return {
32
+ ...options,
33
+ retry(error, metadata) {
34
+ const meta = metadata;
35
+ reportQueueDeliveryError(error, {
36
+ attempts: typeof meta?.deliveryCount === "number" ? meta.deliveryCount : 1,
37
+ id: typeof meta?.messageId === "string" ? meta.messageId : "vercel-message",
38
+ provider: "vercel",
39
+ queue: name
40
+ });
41
+ const directive = retry?.(error, metadata);
42
+ if (directive !== void 0) return directive;
43
+ if (isNonRetryableQueueError(error)) return { acknowledge: true };
44
+ }
45
+ };
46
+ }
47
+ async function handleHostedVercelQueueCallback(event, name, definition) {
48
+ const queue = await getQueue(name);
49
+ if (queue.provider !== "vercel") throw createQueueError("VERCEL_PROVIDER_EXPECTED", { details: { provider: queue.provider } });
50
+ return await queue.callback(createVercelJobHandler(definition), createVercelCallbackOptions(name, definition.options?.callbackOptions))(await toRequest(event));
51
+ }
52
+ //#endregion
53
+ export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
@@ -0,0 +1,16 @@
1
+ import { _ as QueueProviderOptions, l as QueueDefinitionRegistry, o as QueueClient, s as QueueDefinition, y as ResolvedQueueOptions } from "../types-CwvoMATy.js";
2
+
3
+ //#region src/runtime/state.d.ts
4
+ type QueueRuntimeClientFactory = (options: QueueProviderOptions) => QueueClient | Promise<QueueClient>;
5
+ declare function setQueueRuntimeConfig(config: false | ResolvedQueueOptions | undefined, createClient?: QueueRuntimeClientFactory): void;
6
+ declare function getQueueRuntimeConfig(): false | ResolvedQueueOptions | undefined;
7
+ declare function getQueueRuntimeClientFactory(): QueueRuntimeClientFactory | undefined;
8
+ declare function runWithQueueRuntimeEvent<T>(event: unknown, callback: () => T): T;
9
+ declare function enterQueueRuntimeEvent(event: unknown): void;
10
+ declare function getQueueRuntimeEvent(): unknown;
11
+ declare function setQueueRuntimeEventDefaults(event: unknown): void;
12
+ declare function setQueueRuntimeRegistry(registry: QueueDefinitionRegistry | undefined): void;
13
+ declare function getQueueClientCache(): Map<string, Promise<unknown>>;
14
+ declare function loadQueueDefinition(name: string): Promise<QueueDefinition | undefined>;
15
+ //#endregion
16
+ export { QueueRuntimeClientFactory, enterQueueRuntimeEvent, getQueueClientCache, getQueueRuntimeClientFactory, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeRegistry };
@@ -0,0 +1,2 @@
1
+ import { a as getQueueRuntimeEvent, c as setQueueRuntimeConfig, i as getQueueRuntimeConfig, l as setQueueRuntimeEventDefaults, n as getQueueClientCache, o as loadQueueDefinition, r as getQueueRuntimeClientFactory, s as runWithQueueRuntimeEvent, t as enterQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "../state-BfUFGeC2.js";
2
+ export { enterQueueRuntimeEvent, getQueueClientCache, getQueueRuntimeClientFactory, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeRegistry };
@@ -0,0 +1,20 @@
1
+ import { l as QueueDefinitionRegistry, y as ResolvedQueueOptions } from "../types-CwvoMATy.js";
2
+ import { t as QueueApp } from "../_app-D29AwUdD.js";
3
+ import { QueueRuntimeClientFactory } from "./state.js";
4
+
5
+ //#region src/runtime/vercel-vite.d.ts
6
+ interface QueueVercelServerBaseOptions {
7
+ app?: QueueApp;
8
+ registry?: QueueDefinitionRegistry;
9
+ }
10
+ type QueueVercelServerOptions = QueueVercelServerBaseOptions & ({
11
+ createClient: QueueRuntimeClientFactory;
12
+ queue?: ResolvedQueueOptions;
13
+ } | {
14
+ createClient?: never;
15
+ queue: false;
16
+ });
17
+ type QueueVercelServer = (req: unknown, res: unknown) => unknown;
18
+ declare function createQueueVercelServer(options: QueueVercelServerOptions): QueueVercelServer;
19
+ //#endregion
20
+ export { QueueVercelServer, createQueueVercelServer };
@@ -0,0 +1,49 @@
1
+ import { c as setQueueRuntimeConfig, s as runWithQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "../state-BfUFGeC2.js";
2
+ import { t as resolveAppFetch } from "../app-BZpq2cwC.js";
3
+ import { waitUntil } from "@vercel/functions";
4
+ import { H3 } from "h3";
5
+ //#region ../internal/src/runtime/vercel-hosted.ts
6
+ function createVercelHostedServer(adapter) {
7
+ const app = new H3();
8
+ const appHandler = resolveAppFetch(adapter.label, adapter.app);
9
+ let nodeHandlerPromise;
10
+ return function hostedVercelServer(req, res) {
11
+ const handle = async () => {
12
+ nodeHandlerPromise ||= (async () => {
13
+ if (appHandler) {
14
+ const { fromWebHandler } = await import("h3");
15
+ app.use(fromWebHandler(async (request, context) => await appHandler(request, context)));
16
+ }
17
+ const { toNodeHandler } = await import("h3/node");
18
+ return toNodeHandler(app);
19
+ })();
20
+ return (await nodeHandlerPromise)(req, res);
21
+ };
22
+ if (adapter.onRequest) return adapter.onRequest({
23
+ handle,
24
+ req,
25
+ res
26
+ });
27
+ return handle();
28
+ };
29
+ }
30
+ //#endregion
31
+ //#region src/runtime/vercel-vite.ts
32
+ function createQueueVercelServer(options) {
33
+ if (options.queue !== false && !options.createClient) throw new TypeError("[vitehub] Enabled Vercel Queue output requires its generated client factory.");
34
+ return createVercelHostedServer({
35
+ app: options.app,
36
+ label: "queue",
37
+ onRequest({ handle, req, res }) {
38
+ setQueueRuntimeConfig(options.queue, options.createClient);
39
+ setQueueRuntimeRegistry(options.registry);
40
+ return runWithQueueRuntimeEvent({
41
+ req,
42
+ res,
43
+ waitUntil
44
+ }, handle);
45
+ }
46
+ });
47
+ }
48
+ //#endregion
49
+ export { createQueueVercelServer };