@vite-hub/queue 0.0.1 → 0.0.3
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.
- package/README.md +42 -6
- package/dist/client-CPQ-iyXS.js +93 -0
- package/dist/{cloudflare-D5dVqiNw.js → cloudflare-GosJefIK.js} +5 -8
- package/dist/{cloudflare-CTdH2u_E.js → cloudflare-client-w5vphoNn.js} +34 -42
- package/dist/cloudflare-resource-name-R8zYQiZb.js +34 -0
- package/dist/cloudflare-vite-bA1eLf46.js +92 -0
- package/dist/{cloudflare-vite-CRx2CsH9.d.ts → cloudflare-vite-nFPor46-.d.ts} +4 -3
- package/dist/{config-CIDUZkmH.js → config-B7xkD1v0.js} +21 -3
- package/dist/delivery-error-glgYWC9g.js +45 -0
- package/dist/errors-CjuG_qr-.js +108 -0
- package/dist/index.d.ts +62 -24
- package/dist/index.js +19 -8
- package/dist/internal/runtime/cloudflare-client.d.ts +6 -0
- package/dist/internal/runtime/cloudflare-client.js +2 -0
- package/dist/{runtime → internal/runtime}/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +2 -0
- package/dist/internal/runtime/state.d.ts +16 -0
- package/dist/internal/runtime/state.js +2 -0
- package/dist/internal/runtime/vercel-client.d.ts +6 -0
- package/dist/{vercel-D31zfxiW.js → internal/runtime/vercel-client.js} +46 -30
- package/dist/internal/runtime/vercel-vite.d.ts +20 -0
- package/dist/{runtime → internal/runtime}/vercel-vite.js +6 -5
- package/dist/nuxt.d.ts +19 -0
- package/dist/nuxt.js +29 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +52 -1
- package/dist/state-Bo8CLZ_k.js +105 -0
- package/dist/{types-CBsyjWye.d.ts → types-CwvoMATy.d.ts} +3 -1
- package/dist/{vercel-BGm0G00p.js → vercel-C_4vqxcl.js} +1 -1
- package/dist/vercel-runtime-package-copy-CKimoFJ5.js +66 -0
- package/dist/vite-BcMpQk_n.js +1842 -0
- package/dist/vite.d.ts +90 -6
- package/dist/vite.js +2 -492
- package/package.json +45 -49
- package/dist/cloudflare-env-CJ6g1-Qb.js +0 -49
- package/dist/cloudflare-shared-Ce61GXcn.js +0 -14
- package/dist/cloudflare-vite-Bs67_E_Y.js +0 -66
- package/dist/errors-xRt0BFZK.js +0 -57
- package/dist/hosted-Dw9WiPNH.js +0 -136
- package/dist/module-Cr8pH2J_.js +0 -610
- package/dist/nitro.d.ts +0 -32
- package/dist/nitro.js +0 -2
- package/dist/runtime/cloudflare-vite.js +0 -2
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -40
- package/dist/runtime/state.d.ts +0 -13
- package/dist/runtime/state.js +0 -41
- package/dist/runtime/vercel-vite.d.ts +0 -13
- /package/dist/{_app-Bx4e5L33.d.ts → _app-D29AwUdD.d.ts} +0 -0
- /package/dist/{app-BFpA3j89.js → app-BZpq2cwC.js} +0 -0
|
@@ -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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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-nFPor46-.js";
|
|
3
|
+
import { ViteHubError, ViteHubErrorDetails } from "@vite-hub/runtime";
|
|
4
4
|
|
|
5
5
|
//#region src/config.d.ts
|
|
6
6
|
interface QueueResolutionInput {
|
|
@@ -15,39 +15,77 @@ declare function defineQueue<TPayload = unknown, TResult = unknown>(handler: Que
|
|
|
15
15
|
declare function createQueueMessageId(prefix?: string): string;
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/errors.d.ts
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
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];
|
|
35
69
|
//#endregion
|
|
36
70
|
//#region src/providers/cloudflare.d.ts
|
|
37
71
|
declare function createCloudflareQueueBatchHandler<TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>): (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
|
|
38
72
|
//#endregion
|
|
39
73
|
//#region src/integrations/cloudflare.d.ts
|
|
40
|
-
declare function getCloudflareQueueName(name: string): string;
|
|
41
74
|
declare function getCloudflareQueueBindingName(name: string): string;
|
|
42
|
-
declare function getCloudflareQueueDefinitionName(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;
|
|
43
79
|
//#endregion
|
|
44
80
|
//#region src/integrations/vercel.d.ts
|
|
45
81
|
declare function getVercelQueueTopicName(name: string): string;
|
|
46
82
|
//#endregion
|
|
47
83
|
//#region src/runtime/client.d.ts
|
|
48
|
-
declare function createQueueClient(options: QueueProviderOptions): Promise<QueueClient>;
|
|
49
84
|
declare function getQueue(name: string): Promise<QueueClient>;
|
|
50
85
|
declare function runQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): Promise<QueueSendResult>;
|
|
51
86
|
declare function deferQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): void;
|
|
52
87
|
//#endregion
|
|
53
|
-
|
|
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
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import { n as
|
|
5
|
-
import { t as
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
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-CPQ-iyXS.js";
|
|
8
|
+
import { t as createQueueCloudflareWorker } from "./cloudflare-vite-bA1eLf46.js";
|
|
8
9
|
//#region src/definition.ts
|
|
9
10
|
function defineQueue(handler, options) {
|
|
10
11
|
if (typeof handler !== "function") throw new TypeError("`defineQueue()` requires a queue handler.");
|
|
@@ -14,4 +15,14 @@ function defineQueue(handler, options) {
|
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
|
-
|
|
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 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as createQueueCloudflareWorker, n as QueueCloudflareWorker, r as QueueCloudflareWorkerOptions, t as CloudflareWorkerApp } from "
|
|
1
|
+
import { i as createQueueCloudflareWorker, n as QueueCloudflareWorker, r as QueueCloudflareWorkerOptions, t as CloudflareWorkerApp } from "../../cloudflare-vite-nFPor46-.js";
|
|
2
2
|
export { CloudflareWorkerApp, QueueCloudflareWorker, QueueCloudflareWorkerOptions, createQueueCloudflareWorker };
|
|
@@ -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/internal/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-Bo8CLZ_k.js";
|
|
2
|
+
export { enterQueueRuntimeEvent, getQueueClientCache, getQueueRuntimeClientFactory, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeRegistry };
|
|
@@ -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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getQueueRuntimeEvent } from "
|
|
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-Bo8CLZ_k.js";
|
|
3
3
|
//#region src/providers/vercel.ts
|
|
4
4
|
function readHeader(headers, name) {
|
|
5
5
|
if (!headers) return;
|
|
@@ -17,9 +17,30 @@ function resolveVercelRegion(explicitRegion) {
|
|
|
17
17
|
if (typeof process.env.QUEUE_REGION === "string" && process.env.QUEUE_REGION) return process.env.QUEUE_REGION;
|
|
18
18
|
if (typeof process.env.VERCEL_REGION === "string" && process.env.VERCEL_REGION) return process.env.VERCEL_REGION;
|
|
19
19
|
const event = getQueueRuntimeEvent();
|
|
20
|
-
const requestHeaders = event?.request instanceof Request ? event.request.headers : event?.req?.headers;
|
|
20
|
+
const requestHeaders = event?.request instanceof Request ? event.request.headers : event?.req?.headers ?? event?.node?.req?.headers;
|
|
21
21
|
return readHeader(requestHeaders, "ce-vqsregion") || parseRegionFromVercelId(readHeader(requestHeaders, "x-vercel-id"));
|
|
22
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
|
+
}
|
|
23
44
|
async function loadVercelQueueClient(region) {
|
|
24
45
|
let module;
|
|
25
46
|
try {
|
|
@@ -36,37 +57,29 @@ async function loadVercelQueueClient(region) {
|
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
} catch (error) {
|
|
39
|
-
|
|
60
|
+
if (isQueueBoundaryIdentity(error)) throw error;
|
|
61
|
+
throw createQueueError("VERCEL_QUEUE_SDK_LOAD_FAILED", {
|
|
40
62
|
cause: error,
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
details: {
|
|
64
|
+
operation: "load-sdk",
|
|
65
|
+
provider: "vercel"
|
|
66
|
+
}
|
|
43
67
|
});
|
|
44
68
|
}
|
|
45
69
|
const resolvedRegion = resolveVercelRegion(region);
|
|
46
70
|
if ("QueueClient" in module && typeof module.QueueClient === "function") {
|
|
47
|
-
if (!resolvedRegion) throw
|
|
48
|
-
code: "VERCEL_QUEUE_REGION_REQUIRED",
|
|
49
|
-
httpStatus: 500,
|
|
50
|
-
provider: "vercel"
|
|
51
|
-
});
|
|
71
|
+
if (!resolvedRegion) throw createQueueError("VERCEL_QUEUE_REGION_REQUIRED", { details: { provider: "vercel" } });
|
|
52
72
|
return new module.QueueClient({ region: resolvedRegion });
|
|
53
73
|
}
|
|
54
74
|
if (typeof module.send === "function" && typeof module.handleCallback === "function") return {
|
|
55
75
|
handleCallback: module.handleCallback,
|
|
56
76
|
send: module.send
|
|
57
77
|
};
|
|
58
|
-
throw
|
|
59
|
-
code: "VERCEL_QUEUE_SDK_INVALID",
|
|
60
|
-
provider: "vercel"
|
|
61
|
-
});
|
|
78
|
+
throw createQueueError("VERCEL_QUEUE_SDK_INVALID", { details: { provider: "vercel" } });
|
|
62
79
|
}
|
|
63
80
|
async function createVercelQueueClient(provider) {
|
|
64
81
|
const topic = provider.topic;
|
|
65
|
-
if (!topic) throw
|
|
66
|
-
code: "VERCEL_TOPIC_RESOLUTION_REQUIRED",
|
|
67
|
-
httpStatus: 400,
|
|
68
|
-
provider: "vercel"
|
|
69
|
-
});
|
|
82
|
+
if (!topic) throw createQueueError("VERCEL_TOPIC_RESOLUTION_REQUIRED", { details: { provider: "vercel" } });
|
|
70
83
|
const client = provider.client || await loadVercelQueueClient(provider.region);
|
|
71
84
|
return {
|
|
72
85
|
provider: "vercel",
|
|
@@ -74,25 +87,28 @@ async function createVercelQueueClient(provider) {
|
|
|
74
87
|
topic,
|
|
75
88
|
async send(input) {
|
|
76
89
|
const normalized = normalizeQueueEnqueueInput(input);
|
|
77
|
-
if (normalized.options.contentType !== void 0) throw
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
method: "send",
|
|
82
|
-
provider: "vercel"
|
|
83
|
-
});
|
|
90
|
+
if (normalized.options.contentType !== void 0) throw createQueueError("VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS", { details: {
|
|
91
|
+
provider: "vercel",
|
|
92
|
+
unsupported: ["contentType"]
|
|
93
|
+
} });
|
|
84
94
|
return {
|
|
85
95
|
status: "queued",
|
|
86
|
-
messageId: (await client.send(topic, normalized.payload, {
|
|
96
|
+
messageId: await runQueueProviderOperation("vercel", "send", async () => parseVercelMessageId(await client.send(topic, normalized.payload, {
|
|
87
97
|
delaySeconds: normalized.options.delaySeconds,
|
|
88
98
|
idempotencyKey: normalized.options.idempotencyKey || normalized.id,
|
|
89
99
|
region: normalized.options.region ?? provider.region,
|
|
90
100
|
retentionSeconds: normalized.options.retentionSeconds
|
|
91
|
-
}))
|
|
101
|
+
})))
|
|
92
102
|
};
|
|
93
103
|
},
|
|
94
104
|
callback: client.handleCallback.bind(client)
|
|
95
105
|
};
|
|
96
106
|
}
|
|
97
107
|
//#endregion
|
|
98
|
-
|
|
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 };
|
|
@@ -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/internal/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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as resolveAppFetch } from "
|
|
1
|
+
import { c as setQueueRuntimeConfig, s as runWithQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "../../state-Bo8CLZ_k.js";
|
|
2
|
+
import { t as resolveAppFetch } from "../../app-BZpq2cwC.js";
|
|
3
3
|
import { waitUntil } from "@vercel/functions";
|
|
4
4
|
import { H3 } from "h3";
|
|
5
5
|
//#region ../internal/src/runtime/vercel-hosted.ts
|
|
@@ -28,13 +28,14 @@ function createVercelHostedServer(adapter) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
//#endregion
|
|
31
|
-
//#region src/runtime/vercel-vite.ts
|
|
32
|
-
function createQueueVercelServer(options
|
|
31
|
+
//#region src/internal/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.");
|
|
33
34
|
return createVercelHostedServer({
|
|
34
35
|
app: options.app,
|
|
35
36
|
label: "queue",
|
|
36
37
|
onRequest({ handle, req, res }) {
|
|
37
|
-
setQueueRuntimeConfig(options.queue);
|
|
38
|
+
setQueueRuntimeConfig(options.queue, options.createClient);
|
|
38
39
|
setQueueRuntimeRegistry(options.registry);
|
|
39
40
|
return runWithQueueRuntimeEvent({
|
|
40
41
|
req,
|
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-BcMpQk_n.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 };
|
package/dist/runtime/hosted.d.ts
CHANGED
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,2 +1,53 @@
|
|
|
1
|
-
import { n as
|
|
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-CPQ-iyXS.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
|
|
2
53
|
export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
|