@vite-hub/queue 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +110 -50
  3. package/dist/client-CIc3jsj2.js +114 -0
  4. package/dist/cloudflare-client-COzQ8fHk.js +147 -0
  5. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-CCuLDvSP.js} +3 -2
  6. package/dist/{cloudflare-vite-bA1eLf46.js → cloudflare-vite-BCuJOXcT.js} +31 -12
  7. package/dist/{cloudflare-vite-nFPor46-.d.ts → cloudflare-vite-CjdP5yBN.d.ts} +9 -4
  8. package/dist/config-BINujLv4.js +74 -0
  9. package/dist/enqueue-CnQ0QR3O.js +22 -0
  10. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  11. package/dist/error-diagnostics-qzRF6IVB.js +109 -0
  12. package/dist/errors-DIFaM9tW.js +42 -0
  13. package/dist/handler-response-CBwIkmTS.js +56 -0
  14. package/dist/index.d.ts +32 -70
  15. package/dist/index.js +9 -8
  16. package/dist/inspect-PeuckaC3.js +30 -0
  17. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  18. package/dist/internal/runtime/cloudflare-client.js +1 -1
  19. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  20. package/dist/internal/runtime/cloudflare-vite.js +1 -1
  21. package/dist/internal/runtime/state.d.ts +16 -15
  22. package/dist/internal/runtime/state.js +2 -2
  23. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  24. package/dist/internal/runtime/vercel-client.js +93 -62
  25. package/dist/nuxt.d.ts +27 -7
  26. package/dist/nuxt.js +7 -2
  27. package/dist/object-B1NW521B.js +7 -0
  28. package/dist/operations-Cnjbz8kk.js +63 -0
  29. package/dist/operations-tNUdj3G4.d.ts +212 -0
  30. package/dist/operations.d.ts +32 -0
  31. package/dist/operations.js +1195 -0
  32. package/dist/runtime/hosted.d.ts +4 -7
  33. package/dist/runtime/hosted.js +30 -8
  34. package/dist/state-G9s378-e.js +184 -0
  35. package/dist/{types-CwvoMATy.d.ts → types-1GRMYES1.d.ts} +35 -24
  36. package/dist/vercel-region-cjskrOKl.js +122 -0
  37. package/dist/vite-ChWLzOVu.js +1512 -0
  38. package/dist/vite.d.ts +346 -33
  39. package/dist/vite.js +2 -2
  40. package/package.json +69 -23
  41. package/dist/_app-D29AwUdD.d.ts +0 -11
  42. package/dist/app-BZpq2cwC.js +0 -10
  43. package/dist/client-CPQ-iyXS.js +0 -93
  44. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  45. package/dist/config-B7xkD1v0.js +0 -47
  46. package/dist/delivery-error-glgYWC9g.js +0 -45
  47. package/dist/errors-CjuG_qr-.js +0 -108
  48. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  49. package/dist/internal/runtime/vercel-vite.js +0 -49
  50. package/dist/state-Bo8CLZ_k.js +0 -105
  51. package/dist/vercel-runtime-package-copy-CKimoFJ5.js +0 -66
  52. package/dist/vite-BcMpQk_n.js +0 -1842
@@ -1,93 +0,0 @@
1
- import { t as normalizeQueueOptions } from "./config-B7xkD1v0.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-Bo8CLZ_k.js";
6
- //#region src/runtime/client.ts
7
- function createQueueDefinitionNotFoundError(name) {
8
- const queue = normalizePublicQueueIdentifier(name);
9
- return createQueueError("QUEUE_DEFINITION_NOT_FOUND", { details: queue ? { queue } : void 0 });
10
- }
11
- async function loadNamedQueueDefinition(name) {
12
- try {
13
- return await loadQueueDefinition(name);
14
- } catch (cause) {
15
- if (isQueueBoundaryIdentity(cause)) throw cause;
16
- const queue = normalizePublicQueueIdentifier(name);
17
- throw createQueueError("QUEUE_DEFINITION_LOAD_FAILED", {
18
- cause,
19
- details: queue ? { queue } : void 0
20
- });
21
- }
22
- }
23
- function resolveCloudflareBinding(binding, name) {
24
- if (binding && typeof binding !== "string") return binding;
25
- const bindingName = binding || getCloudflareQueueBindingName(name);
26
- return getCloudflareEnv(getQueueRuntimeEvent())?.[bindingName] || bindingName;
27
- }
28
- function toProviderOptions(name, config) {
29
- if (config.provider === "cloudflare") return {
30
- ...config,
31
- binding: resolveCloudflareBinding(config.binding, name)
32
- };
33
- return {
34
- ...config,
35
- topic: getVercelQueueTopicName(name)
36
- };
37
- }
38
- function getActiveQueueConfig() {
39
- const config = getQueueRuntimeConfig();
40
- if (config === false) return false;
41
- return config || normalizeQueueOptions(void 0, { hosting: "vercel" });
42
- }
43
- function hasRequestScopedVercelRegion(config) {
44
- return config.provider === "vercel" && !config.region && !process.env.QUEUE_REGION && !process.env.VERCEL_REGION && typeof getQueueRuntimeEvent() !== "undefined";
45
- }
46
- async function createNamedQueueClient(name) {
47
- const config = getActiveQueueConfig();
48
- if (config === false) throw createQueueError("QUEUE_DISABLED");
49
- const provider = toProviderOptions(name, config);
50
- const createClient = getQueueRuntimeClientFactory();
51
- if (!createClient) throw new Error("[vitehub] Queue Client is installed by generated Provider Output.");
52
- return await runQueueProviderOperation(provider.provider, "create-client", () => createClient(provider));
53
- }
54
- async function getQueue(name) {
55
- const definition = await loadNamedQueueDefinition(name);
56
- if (!definition) throw createQueueDefinitionNotFoundError(name);
57
- const config = getActiveQueueConfig();
58
- if (definition.options?.cache === false || config === false || config.cache === false || config.provider === "cloudflare" || hasRequestScopedVercelRegion(config)) return await createNamedQueueClient(name);
59
- const cache = getQueueClientCache();
60
- const existing = cache.get(name);
61
- if (existing) return await existing;
62
- const pending = createNamedQueueClient(name).catch((error) => {
63
- cache.delete(name);
64
- throw error;
65
- });
66
- cache.set(name, pending);
67
- return await pending;
68
- }
69
- async function runQueue(name, input) {
70
- const normalized = normalizeQueueEnqueueInput(input);
71
- return await (await getQueue(name)).send({
72
- ...normalized.options,
73
- id: normalized.id,
74
- payload: normalized.payload
75
- });
76
- }
77
- function deferQueue(name, input) {
78
- const request = getQueueRuntimeEvent();
79
- const task = () => runWithQueueRuntimeEvent(request, () => runQueue(name, input));
80
- const handleError = async (error) => {
81
- console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
82
- try {
83
- await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
84
- } catch (hookError) {
85
- console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
86
- }
87
- };
88
- const promise = task().catch(handleError);
89
- const waitUntil = resolveWaitUntil(request);
90
- if (typeof waitUntil === "function") waitUntil(promise);
91
- }
92
- //#endregion
93
- export { getQueue as n, runQueue as r, deferQueue as t };
@@ -1,99 +0,0 @@
1
- import { l as normalizeQueueEnqueueInput, n as createQueueError, s as runQueueProviderOperation, t as cloudflareUnsupportedEnqueueOptions } from "./errors-CjuG_qr-.js";
2
- import { n as getCloudflareQueueDefinitionName } from "./cloudflare-GosJefIK.js";
3
- import { n as reportQueueDeliveryError, t as isNonRetryableQueueError } from "./delivery-error-glgYWC9g.js";
4
- //#region src/providers/cloudflare.ts
5
- function isCloudflareQueueBinding(binding) {
6
- return Boolean(binding) && typeof binding === "object" && typeof binding.send === "function" && typeof binding.sendBatch === "function";
7
- }
8
- function toSendOptions(options = {}) {
9
- const unsupported = cloudflareUnsupportedEnqueueOptions.filter((option) => options[option] !== void 0);
10
- if (unsupported.length) throw createQueueError("CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS", { details: {
11
- provider: "cloudflare",
12
- unsupported
13
- } });
14
- return {
15
- contentType: options.contentType,
16
- delaySeconds: options.delaySeconds
17
- };
18
- }
19
- function resolveAction(action, message, fallback) {
20
- if (action === "ack") {
21
- message.ack();
22
- return;
23
- }
24
- if (action === "retry") {
25
- message.retry();
26
- return;
27
- }
28
- if (action && typeof action === "object" && "retry" in action) {
29
- message.retry(action.retry);
30
- return;
31
- }
32
- if (fallback === "ack") message.ack();
33
- else message.retry();
34
- }
35
- function createCloudflareQueueBatchHandler(options) {
36
- const requested = Number(options.concurrency ?? 1);
37
- const concurrency = Number.isFinite(requested) ? Math.max(1, Math.floor(requested)) : 1;
38
- return async (batch) => {
39
- const messages = Array.isArray(batch?.messages) ? batch.messages : [];
40
- if (!messages.length) return;
41
- let index = 0;
42
- const worker = async () => {
43
- while (index < messages.length) {
44
- const message = messages[index++];
45
- try {
46
- await options.onMessage(message, batch);
47
- message.ack();
48
- } catch (error) {
49
- reportQueueDeliveryError(error, {
50
- attempts: message.attempts,
51
- id: message.id,
52
- provider: "cloudflare",
53
- queue: getCloudflareQueueDefinitionName(batch.queue)
54
- });
55
- resolveAction(options.onError ? await options.onError(error, message, batch) : void 0, message, isNonRetryableQueueError(error) ? "ack" : "retry");
56
- }
57
- }
58
- };
59
- await Promise.all(Array.from({ length: Math.min(concurrency, messages.length) }, () => worker()));
60
- };
61
- }
62
- function createCloudflareQueueClient(provider) {
63
- if (typeof provider.binding === "undefined" || typeof provider.binding === "string") throw createQueueError("CLOUDFLARE_BINDING_RESOLUTION_REQUIRED", { details: { provider: "cloudflare" } });
64
- if (!isCloudflareQueueBinding(provider.binding)) throw createQueueError("CLOUDFLARE_BINDING_INVALID", { details: { provider: "cloudflare" } });
65
- const binding = provider.binding;
66
- return {
67
- provider: "cloudflare",
68
- native: binding,
69
- binding,
70
- async send(input) {
71
- const normalized = normalizeQueueEnqueueInput(input);
72
- await runQueueProviderOperation("cloudflare", "send", () => binding.send(normalized.payload, toSendOptions(normalized.options)));
73
- return {
74
- status: "queued",
75
- messageId: normalized.id
76
- };
77
- },
78
- async sendBatch(items, options) {
79
- await runQueueProviderOperation("cloudflare", "send-batch", () => binding.sendBatch(items.map((item) => ({
80
- ...item,
81
- ...toSendOptions({
82
- ...options,
83
- contentType: item.contentType || options?.contentType,
84
- delaySeconds: item.delaySeconds ?? options?.delaySeconds
85
- })
86
- }))));
87
- return items.map(() => ({ status: "queued" }));
88
- },
89
- createBatchHandler: createCloudflareQueueBatchHandler
90
- };
91
- }
92
- //#endregion
93
- //#region src/internal/runtime/cloudflare-client.ts
94
- async function createCloudflareQueueRuntimeClient(options) {
95
- if (options.provider !== "cloudflare") throw new TypeError("[vitehub] Cloudflare Queue runtime received a non-Cloudflare provider.");
96
- return createCloudflareQueueClient(options);
97
- }
98
- //#endregion
99
- export { createCloudflareQueueBatchHandler as n, createCloudflareQueueRuntimeClient as t };
@@ -1,47 +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
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
26
- }
27
- //#endregion
28
- //#region src/config.ts
29
- const knownProviders = new Set(["cloudflare", "vercel"]);
30
- function resolveProvider(options, hosting) {
31
- const shared = typeof options.cache === "boolean" ? { cache: options.cache } : {};
32
- const provider = options.provider;
33
- if (typeof provider === "string" && !knownProviders.has(provider)) throw new TypeError(`Unknown \`queue.provider\`: ${JSON.stringify(provider)}. Expected "cloudflare" or "vercel".`);
34
- 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.");
35
- if ((provider || (hosting.includes("cloudflare") ? "cloudflare" : "vercel")) === "cloudflare") return defu({
36
- ...typeof options.binding === "string" ? { binding: options.binding } : {},
37
- ...typeof options.namePrefix === "string" ? { namePrefix: options.namePrefix } : {}
38
- }, shared, { provider: "cloudflare" });
39
- return defu(typeof options.region === "string" ? { region: options.region } : {}, shared, { provider: "vercel" });
40
- }
41
- function normalizeQueueOptions(options, input = {}) {
42
- if (options === false) return void 0;
43
- if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`queue` must be a plain object.");
44
- return resolveProvider(options || {}, normalizeHosting(input.hosting));
45
- }
46
- //#endregion
47
- export { getHostingProvider as n, 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 };
@@ -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-Bo8CLZ_k.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 };
@@ -1,105 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- //#region ../internal/src/runtime/cloudflare-env.ts
3
- let activeEnv;
4
- const activeEnvStorage = new AsyncLocalStorage();
5
- function setActiveCloudflareEnv(env) {
6
- activeEnv = env;
7
- globalThis.__env__ = env;
8
- try {
9
- activeEnvStorage.enterWith({ env });
10
- } catch {}
11
- }
12
- function runWithActiveCloudflareEnv(env, callback) {
13
- return activeEnvStorage.run({ env }, callback);
14
- }
15
- function getActiveCloudflareEnv() {
16
- const scoped = activeEnvStorage.getStore();
17
- return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
18
- }
19
- function getCloudflareEnv(event) {
20
- const target = event;
21
- return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
22
- }
23
- function resolveWaitUntil(event) {
24
- const target = event;
25
- const owners = [
26
- target,
27
- target?.context,
28
- target?.context?.cloudflare,
29
- target?.context?.cloudflare?.context,
30
- target?.context?._platform?.cloudflare,
31
- target?.context?._platform?.cloudflare?.context,
32
- target?.req,
33
- target?.req?.runtime?.cloudflare,
34
- target?.req?.runtime?.cloudflare?.context
35
- ];
36
- for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
37
- }
38
- function createCloudflareRuntimeEvent(env, context) {
39
- const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
40
- return {
41
- context: {
42
- cloudflare: {
43
- env,
44
- context
45
- },
46
- waitUntil
47
- },
48
- env,
49
- waitUntil
50
- };
51
- }
52
- //#endregion
53
- //#region src/internal/runtime/state.ts
54
- let runtimeConfig;
55
- let runtimeClientFactory;
56
- let registryOverride;
57
- const queueEventStorage = new AsyncLocalStorage();
58
- let queueEventDefaults;
59
- const queueClientCache = /* @__PURE__ */ new Map();
60
- function setQueueRuntimeConfig(config, createClient) {
61
- runtimeConfig = config;
62
- runtimeClientFactory = createClient;
63
- if (typeof config === "undefined") queueEventDefaults = void 0;
64
- queueClientCache.clear();
65
- }
66
- function getQueueRuntimeConfig() {
67
- return runtimeConfig;
68
- }
69
- function getQueueRuntimeClientFactory() {
70
- return runtimeClientFactory;
71
- }
72
- function runWithQueueRuntimeEvent(event, callback) {
73
- return queueEventStorage.run(event, callback);
74
- }
75
- function enterQueueRuntimeEvent(event) {
76
- try {
77
- queueEventStorage.enterWith(event);
78
- } catch {}
79
- setActiveCloudflareEnv(getCloudflareEnv(event));
80
- }
81
- function getQueueRuntimeEvent() {
82
- return queueEventStorage.getStore() ?? queueEventDefaults;
83
- }
84
- function setQueueRuntimeEventDefaults(event) {
85
- queueEventDefaults = event;
86
- }
87
- function setQueueRuntimeRegistry(registry) {
88
- registryOverride = registry;
89
- queueClientCache.clear();
90
- }
91
- function getQueueClientCache() {
92
- return queueClientCache;
93
- }
94
- function isQueueDefinition(value) {
95
- return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
96
- }
97
- async function loadQueueDefinition(name) {
98
- const entry = registryOverride?.[name];
99
- if (!entry) return;
100
- const loaded = await entry();
101
- if (isQueueDefinition(loaded)) return loaded;
102
- if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
103
- }
104
- //#endregion
105
- 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 };
@@ -1,66 +0,0 @@
1
- import { i as createDefaultVercelOutputRoot } from "./vite-BcMpQk_n.js";
2
- import { access, cp, mkdir, readFile, realpath, rm } from "node:fs/promises";
3
- import { dirname, join, relative, resolve, sep } from "node:path";
4
- //#region ../internal/src/build/vercel-runtime-package-copy.ts
5
- async function copyVercelFunctionRuntimePackageDirectories(options) {
6
- if (!options.packages.length) return;
7
- const outputNodeModules = resolve(resolve(options.outputRoot ?? createDefaultVercelOutputRoot(options.rootDir), "functions", options.serverFunctionName ?? "__server.func"), "node_modules");
8
- const copied = /* @__PURE__ */ new Map();
9
- const selected = /* @__PURE__ */ new Map();
10
- for (const runtimePackage of options.packages) try {
11
- selected.set(runtimePackage.name, await realpath(await resolvePackageJson(runtimePackage.name, dirname(runtimePackage.resolveFrom ?? join(options.rootDir, "package.json")))));
12
- } catch (error) {
13
- if (!runtimePackage.optional || error.code !== "ENOENT") throw error;
14
- }
15
- for (const runtimePackage of options.packages) await copyPackageDirectory(runtimePackage.name, runtimePackage.resolveFrom ?? join(options.rootDir, "package.json"), outputNodeModules, copied, selected, runtimePackage.optional);
16
- }
17
- async function copyPackageDirectory(name, resolveFrom, outputNodeModules, copied, selected, optional = false, conflictNodeModules) {
18
- let resolvedPackageJsonPath;
19
- try {
20
- resolvedPackageJsonPath = await resolvePackageJson(name, dirname(resolveFrom));
21
- } catch (error) {
22
- if (optional && error.code === "ENOENT") return;
23
- throw error;
24
- }
25
- const packageJsonPath = await realpath(resolvedPackageJsonPath);
26
- const packageDir = dirname(packageJsonPath);
27
- let targetDir = join(outputNodeModules, ...name.split("/"));
28
- const selectedPackage = selected.get(name);
29
- const existingPackage = copied.get(targetDir);
30
- if (selectedPackage && selectedPackage !== packageJsonPath || existingPackage && existingPackage !== packageJsonPath) {
31
- if (!conflictNodeModules) return;
32
- targetDir = join(conflictNodeModules, ...name.split("/"));
33
- }
34
- if (copied.get(targetDir) === packageJsonPath) return;
35
- copied.set(targetDir, packageJsonPath);
36
- await rm(targetDir, {
37
- force: true,
38
- recursive: true
39
- });
40
- await mkdir(dirname(targetDir), { recursive: true });
41
- await cp(packageDir, targetDir, {
42
- dereference: true,
43
- filter: (source) => !relative(packageDir, source).split(sep).includes("node_modules"),
44
- recursive: true
45
- });
46
- const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
47
- for (const dependency of Object.keys(packageJson.dependencies ?? {})) await copyPackageDirectory(dependency, packageJsonPath, outputNodeModules, copied, selected, false, join(targetDir, "node_modules"));
48
- }
49
- async function resolvePackageJson(name, fromDir) {
50
- let current = await realpath(fromDir).catch(() => fromDir);
51
- while (current !== dirname(current)) {
52
- const candidate = join(current, "node_modules", ...name.split("/"), "package.json");
53
- try {
54
- await access(candidate);
55
- return candidate;
56
- } catch (error) {
57
- if (error.code !== "ENOENT") throw error;
58
- }
59
- current = dirname(current);
60
- }
61
- const error = /* @__PURE__ */ new Error(`Could not resolve package.json for ${name}.`);
62
- error.code = "ENOENT";
63
- throw error;
64
- }
65
- //#endregion
66
- export { copyVercelFunctionRuntimePackageDirectories };