@vite-hub/queue 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -23
- package/dist/client-CIc3jsj2.js +114 -0
- package/dist/cloudflare-client-COzQ8fHk.js +147 -0
- package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-CCuLDvSP.js} +3 -2
- package/dist/{cloudflare-vite-BlQfDVZD.js → cloudflare-vite-BCuJOXcT.js} +23 -9
- package/dist/{cloudflare-vite-nFPor46-.d.ts → cloudflare-vite-CjdP5yBN.d.ts} +9 -4
- package/dist/config-BINujLv4.js +74 -0
- package/dist/enqueue-CnQ0QR3O.js +22 -0
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-qzRF6IVB.js +109 -0
- package/dist/errors-DIFaM9tW.js +42 -0
- package/dist/handler-response-CBwIkmTS.js +56 -0
- package/dist/index.d.ts +32 -70
- package/dist/index.js +9 -8
- package/dist/inspect-PeuckaC3.js +30 -0
- package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +1 -1
- package/dist/internal/runtime/state.d.ts +16 -15
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +3 -5
- package/dist/internal/runtime/vercel-client.js +93 -62
- package/dist/nuxt.d.ts +27 -7
- package/dist/nuxt.js +6 -2
- package/dist/object-B1NW521B.js +7 -0
- package/dist/operations-Cnjbz8kk.js +63 -0
- package/dist/operations-tNUdj3G4.d.ts +212 -0
- package/dist/operations.d.ts +32 -0
- package/dist/operations.js +1195 -0
- package/dist/runtime/hosted.d.ts +4 -6
- package/dist/runtime/hosted.js +30 -8
- package/dist/state-G9s378-e.js +184 -0
- package/dist/{types-CwvoMATy.d.ts → types-1GRMYES1.d.ts} +35 -24
- package/dist/vercel-region-cjskrOKl.js +122 -0
- package/dist/vite-ChWLzOVu.js +1512 -0
- package/dist/vite.d.ts +334 -34
- package/dist/vite.js +2 -2
- package/package.json +68 -25
- package/dist/_app-D29AwUdD.d.ts +0 -11
- package/dist/app-BZpq2cwC.js +0 -10
- package/dist/client-DG9fweET.js +0 -93
- package/dist/cloudflare-client-w5vphoNn.js +0 -99
- package/dist/config-CNgAeIND.js +0 -53
- package/dist/delivery-error-glgYWC9g.js +0 -45
- package/dist/errors-CjuG_qr-.js +0 -108
- package/dist/internal/runtime/vercel-vite.d.ts +0 -20
- package/dist/internal/runtime/vercel-vite.js +0 -49
- package/dist/state-Cno9O7YS.js +0 -110
- package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
- package/dist/vite-DOuoen0w.js +0 -4414
package/dist/client-DG9fweET.js
DELETED
|
@@ -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 };
|
package/dist/config-CNgAeIND.js
DELETED
|
@@ -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 };
|
package/dist/errors-CjuG_qr-.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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 };
|
|
@@ -1,20 +0,0 @@
|
|
|
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,49 +0,0 @@
|
|
|
1
|
-
import { c as setQueueRuntimeConfig, s as runWithQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "../../state-Cno9O7YS.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/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.");
|
|
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 };
|
package/dist/state-Cno9O7YS.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
-
let activeEnv;
|
|
4
|
-
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
5
|
-
const runtimeGlobal = globalThis;
|
|
6
|
-
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
7
|
-
function setActiveCloudflareEnv(env) {
|
|
8
|
-
activeEnv = env;
|
|
9
|
-
globalThis.__env__ = env;
|
|
10
|
-
try {
|
|
11
|
-
activeEnvStorage.enterWith({ env });
|
|
12
|
-
} catch {}
|
|
13
|
-
}
|
|
14
|
-
function runWithActiveCloudflareEnv(env, callback) {
|
|
15
|
-
return activeEnvStorage.run({ env }, callback);
|
|
16
|
-
}
|
|
17
|
-
function getActiveCloudflareEnv() {
|
|
18
|
-
const scoped = activeEnvStorage.getStore();
|
|
19
|
-
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
20
|
-
}
|
|
21
|
-
function getCloudflareEnv(event) {
|
|
22
|
-
const target = event;
|
|
23
|
-
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || target?.node?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
24
|
-
}
|
|
25
|
-
function resolveWaitUntil(event) {
|
|
26
|
-
const target = event;
|
|
27
|
-
const owners = [
|
|
28
|
-
target,
|
|
29
|
-
target?.context,
|
|
30
|
-
target?.context?.cloudflare,
|
|
31
|
-
target?.context?.cloudflare?.context,
|
|
32
|
-
target?.context?._platform?.cloudflare,
|
|
33
|
-
target?.context?._platform?.cloudflare?.context,
|
|
34
|
-
target?.req,
|
|
35
|
-
target?.req?.runtime?.cloudflare,
|
|
36
|
-
target?.req?.runtime?.cloudflare?.context,
|
|
37
|
-
target?.node?.req,
|
|
38
|
-
target?.node?.req?.runtime?.cloudflare,
|
|
39
|
-
target?.node?.req?.runtime?.cloudflare?.context
|
|
40
|
-
];
|
|
41
|
-
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
42
|
-
}
|
|
43
|
-
function createCloudflareRuntimeEvent(env, context) {
|
|
44
|
-
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
45
|
-
return {
|
|
46
|
-
context: {
|
|
47
|
-
cloudflare: {
|
|
48
|
-
env,
|
|
49
|
-
context
|
|
50
|
-
},
|
|
51
|
-
waitUntil
|
|
52
|
-
},
|
|
53
|
-
env,
|
|
54
|
-
waitUntil
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/internal/runtime/state.ts
|
|
59
|
-
let runtimeConfig;
|
|
60
|
-
let runtimeClientFactory;
|
|
61
|
-
let registryOverride;
|
|
62
|
-
const queueEventStorage = new AsyncLocalStorage();
|
|
63
|
-
let queueEventDefaults;
|
|
64
|
-
const queueClientCache = /* @__PURE__ */ new Map();
|
|
65
|
-
function setQueueRuntimeConfig(config, createClient) {
|
|
66
|
-
runtimeConfig = config;
|
|
67
|
-
runtimeClientFactory = createClient;
|
|
68
|
-
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
69
|
-
queueClientCache.clear();
|
|
70
|
-
}
|
|
71
|
-
function getQueueRuntimeConfig() {
|
|
72
|
-
return runtimeConfig;
|
|
73
|
-
}
|
|
74
|
-
function getQueueRuntimeClientFactory() {
|
|
75
|
-
return runtimeClientFactory;
|
|
76
|
-
}
|
|
77
|
-
function runWithQueueRuntimeEvent(event, callback) {
|
|
78
|
-
return queueEventStorage.run(event, callback);
|
|
79
|
-
}
|
|
80
|
-
function enterQueueRuntimeEvent(event) {
|
|
81
|
-
try {
|
|
82
|
-
queueEventStorage.enterWith(event);
|
|
83
|
-
} catch {}
|
|
84
|
-
setActiveCloudflareEnv(event && typeof event === "object" && Object.hasOwn(event, "env") ? event.env : getCloudflareEnv(event));
|
|
85
|
-
}
|
|
86
|
-
function getQueueRuntimeEvent() {
|
|
87
|
-
return queueEventStorage.getStore() ?? queueEventDefaults;
|
|
88
|
-
}
|
|
89
|
-
function setQueueRuntimeEventDefaults(event) {
|
|
90
|
-
queueEventDefaults = event;
|
|
91
|
-
}
|
|
92
|
-
function setQueueRuntimeRegistry(registry) {
|
|
93
|
-
registryOverride = registry;
|
|
94
|
-
queueClientCache.clear();
|
|
95
|
-
}
|
|
96
|
-
function getQueueClientCache() {
|
|
97
|
-
return queueClientCache;
|
|
98
|
-
}
|
|
99
|
-
function isQueueDefinition(value) {
|
|
100
|
-
return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
|
|
101
|
-
}
|
|
102
|
-
async function loadQueueDefinition(name) {
|
|
103
|
-
const entry = registryOverride?.[name];
|
|
104
|
-
if (!entry) return;
|
|
105
|
-
const loaded = await entry();
|
|
106
|
-
if (isQueueDefinition(loaded)) return loaded;
|
|
107
|
-
if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { getQueueRuntimeEvent as a, setQueueRuntimeConfig as c, createCloudflareRuntimeEvent as d, getCloudflareEnv as f, getQueueRuntimeConfig as i, setQueueRuntimeEventDefaults as l, runWithActiveCloudflareEnv as m, getQueueClientCache as n, loadQueueDefinition as o, resolveWaitUntil as p, getQueueRuntimeClientFactory as r, runWithQueueRuntimeEvent as s, enterQueueRuntimeEvent as t, setQueueRuntimeRegistry as u };
|