@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
@@ -0,0 +1,56 @@
1
+ import { i as normalizePublicQueueIdentifier, r as isQueueError } from "./errors-DIFaM9tW.js";
2
+ import { getViteHubErrorShape, toResponse } from "@vite-hub/runtime";
3
+ //#region src/internal/delivery-error.ts
4
+ const retryableQueueCodes = /* @__PURE__ */ new Set(["QUEUE_PROVIDER_FAILED", "QUEUE_PROVIDER_INVALID_RESPONSE"]);
5
+ function isNonRetryableQueueError(error) {
6
+ return isQueueError(error) && !retryableQueueCodes.has(error.code);
7
+ }
8
+ function toReportError(error) {
9
+ if (isQueueError(error)) return {
10
+ code: error.code,
11
+ docs: error.docs,
12
+ fix: error.fix,
13
+ message: error.why,
14
+ name: error.name
15
+ };
16
+ const shape = getViteHubErrorShape(error);
17
+ if (shape) return {
18
+ code: shape.code,
19
+ details: shape.details,
20
+ message: shape.message,
21
+ name: "ViteHubError"
22
+ };
23
+ return {
24
+ message: "[vitehub] Queue Delivery failed.",
25
+ name: "Error"
26
+ };
27
+ }
28
+ function createQueueDeliveryErrorReport(error, context) {
29
+ const id = normalizePublicQueueIdentifier(context.id);
30
+ const queue = normalizePublicQueueIdentifier(context.queue);
31
+ return {
32
+ attempts: context.attempts,
33
+ provider: context.provider,
34
+ ...id ? { id } : {},
35
+ ...queue ? { queue } : {},
36
+ error: toReportError(error),
37
+ retryable: !isNonRetryableQueueError(error)
38
+ };
39
+ }
40
+ function reportQueueDeliveryError(error, context) {
41
+ console.error("[vitehub:queue] Queue Delivery failed.", createQueueDeliveryErrorReport(error, context));
42
+ }
43
+ //#endregion
44
+ //#region src/internal/handler-response.ts
45
+ /** Queue deliveries use the handler's status and discard its response body. */
46
+ function checkQueueHandlerResponse(value) {
47
+ const response = toResponse(value);
48
+ response.body?.cancel().catch(() => {});
49
+ if (!response.ok) {
50
+ const error = /* @__PURE__ */ new Error(`Queue handler returned HTTP ${response.status}`);
51
+ Object.assign(error, { status: response.status });
52
+ throw error;
53
+ }
54
+ }
55
+ //#endregion
56
+ export { isNonRetryableQueueError as n, reportQueueDeliveryError as r, checkQueueHandlerResponse as t };
package/dist/index.d.ts CHANGED
@@ -1,91 +1,53 @@
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
-
1
+ import { C as ResolvedQueueOptions, D as VercelQueueRetryDirective, E as VercelQueueErrorCode, O as VercelQueueRetryHandler, S as QueueSendResult, T as VercelQueueClient, _ as QueueName, a as CloudflareQueueMessageBatch, b as QueueProviderOptions, c as QueueDefinition, d as QueueEnqueueOptions, f as QueueErrorCode, g as QueueModuleProviderOptions, h as QueueModuleOptions, i as CloudflareQueueMessage, k as VercelQueueSendResult, l as QueueDefinitionOptions, m as QueueJob, n as CloudflareQueueClient, o as DiscoveredQueueDefinition, p as QueueHandler, r as CloudflareQueueErrorCode, s as QueueClient, t as CloudflareQueueBatchHandlerOptions, u as QueueDefinitionRegistry, v as QueuePayload, w as VercelQueueCallbackOptions, x as QueueRegistry, y as QueueProvider } from "./types-1GRMYES1.js";
2
+ import { i as createQueueCloudflareWorker } from "./cloudflare-vite-CjdP5yBN.js";
3
+ import { Result } from "@vite-hub/runtime";
5
4
  //#region src/config.d.ts
6
5
  interface QueueResolutionInput {
7
6
  hosting?: string;
8
7
  }
9
- declare function normalizeQueueOptions(options: QueueModuleOptions | undefined, input?: QueueResolutionInput): ResolvedQueueOptions | undefined;
8
+ export declare function normalizeQueueOptions(options: QueueModuleOptions | undefined, input?: QueueResolutionInput): ResolvedQueueOptions | undefined;
10
9
  //#endregion
11
10
  //#region src/definition.d.ts
12
- declare function defineQueue<TPayload = unknown, TResult = unknown>(handler: QueueHandler<TPayload, TResult>, options?: QueueDefinitionOptions): QueueDefinition<TPayload, TResult>;
11
+ export declare function defineQueue<TPayload = unknown, TResult = unknown>(handler: QueueHandler<TPayload, TResult>, options?: QueueDefinitionOptions): QueueDefinition<TPayload, TResult>;
13
12
  //#endregion
14
13
  //#region src/enqueue.d.ts
15
- declare function createQueueMessageId(prefix?: string): string;
16
- //#endregion
17
- //#region src/errors.d.ts
18
- type QueueProviderOperation = "create-client" | "load-sdk" | "send" | "send-batch";
19
- declare const cloudflareUnsupportedEnqueueOptions: readonly ["idempotencyKey", "region", "retentionSeconds"];
20
- type QueueErrorCode = "CLOUDFLARE_BINDING_INVALID" | "CLOUDFLARE_BINDING_RESOLUTION_REQUIRED" | "CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS" | "QUEUE_DEFINITION_LOAD_FAILED" | "QUEUE_DEFINITION_NOT_FOUND" | "QUEUE_DISABLED" | "QUEUE_PROVIDER_OPERATION_FAILED" | "QUEUE_PROVIDER_RESPONSE_INVALID" | "VERCEL_PROVIDER_EXPECTED" | "VERCEL_QUEUE_REGION_REQUIRED" | "VERCEL_QUEUE_SDK_INVALID" | "VERCEL_QUEUE_SDK_LOAD_FAILED" | "VERCEL_TOPIC_RESOLUTION_REQUIRED" | "VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS";
21
- type QueueErrorDetailMap = {
22
- CLOUDFLARE_BINDING_INVALID: {
23
- readonly provider: "cloudflare";
24
- };
25
- CLOUDFLARE_BINDING_RESOLUTION_REQUIRED: {
26
- readonly provider: "cloudflare";
27
- };
28
- CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS: {
29
- readonly provider: "cloudflare";
30
- readonly unsupported: readonly (typeof cloudflareUnsupportedEnqueueOptions)[number][];
31
- };
32
- QUEUE_DEFINITION_LOAD_FAILED: {
33
- readonly queue?: string;
34
- };
35
- QUEUE_DEFINITION_NOT_FOUND: {
36
- readonly queue?: string;
37
- };
38
- QUEUE_DISABLED: ViteHubErrorDetails;
39
- QUEUE_PROVIDER_OPERATION_FAILED: {
40
- readonly operation: Exclude<QueueProviderOperation, "load-sdk">;
41
- readonly provider: QueueProvider;
42
- };
43
- QUEUE_PROVIDER_RESPONSE_INVALID: {
44
- readonly operation: "send";
45
- readonly provider: "vercel";
46
- };
47
- VERCEL_PROVIDER_EXPECTED: {
48
- readonly provider: QueueProvider;
49
- };
50
- VERCEL_QUEUE_REGION_REQUIRED: {
51
- readonly provider: "vercel";
52
- };
53
- VERCEL_QUEUE_SDK_INVALID: {
54
- readonly provider: "vercel";
55
- };
56
- VERCEL_QUEUE_SDK_LOAD_FAILED: {
57
- readonly operation: "load-sdk";
58
- readonly provider: "vercel";
59
- };
60
- VERCEL_TOPIC_RESOLUTION_REQUIRED: {
61
- readonly provider: "vercel";
62
- };
63
- VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS: {
64
- readonly provider: "vercel";
65
- readonly unsupported: readonly "contentType"[];
66
- };
67
- };
68
- type QueueErrorDetails<TCode extends QueueErrorCode = QueueErrorCode> = QueueErrorDetailMap[TCode];
14
+ export declare function createQueueMessageId(prefix?: string): string;
69
15
  //#endregion
70
16
  //#region src/providers/cloudflare.d.ts
71
- declare function createCloudflareQueueBatchHandler<TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>): (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
17
+ export declare function createCloudflareQueueBatchHandler<TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>): (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
72
18
  //#endregion
73
19
  //#region src/integrations/cloudflare.d.ts
74
- declare function getCloudflareQueueBindingName(name: string): string;
75
- declare function getCloudflareQueueDefinitionName(name: string, namePrefix?: string): string;
20
+ export declare function getCloudflareQueueBindingName(name: string): string;
21
+ export declare function getCloudflareQueueDefinitionName(name: string, namePrefix?: string): string;
76
22
  //#endregion
77
23
  //#region src/internal/cloudflare-resource-name.d.ts
78
- declare function getCloudflareQueueName(name: string, namePrefix?: string): string;
24
+ export declare function getCloudflareQueueName(name: string, namePrefix?: string): string;
79
25
  //#endregion
80
26
  //#region src/integrations/vercel.d.ts
81
- declare function getVercelQueueTopicName(name: string): string;
27
+ export declare function getVercelQueueTopicName(name: string): string;
82
28
  //#endregion
83
29
  //#region src/runtime/client.d.ts
84
- declare function getQueue(name: string): Promise<QueueClient>;
85
- declare function runQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): Promise<QueueSendResult>;
86
- declare function deferQueue<TPayload = unknown>(name: string, input: QueueEnqueueInput<TPayload>): void;
30
+ declare function getDynamicQueue(name: string): Promise<QueueClient>;
31
+ declare function runDynamicQueue(name: string, payload: unknown, options?: QueueEnqueueOptions): Promise<Result<QueueSendResult, QueueErrorCode>>;
32
+ declare function deferDynamicQueue(name: string, payload: unknown, options?: QueueEnqueueOptions): void;
33
+ /** Dispatch externally supplied names and payloads after application validation. */
34
+ export declare const dynamicQueue: {
35
+ defer: typeof deferDynamicQueue;
36
+ get: typeof getDynamicQueue;
37
+ run: typeof runDynamicQueue;
38
+ };
39
+ /**
40
+ * Returns the QueueClient of a discovered Queue Definition. Config errors, for example an unknown name, throw.
41
+ */
42
+ export declare function getQueue<TName extends QueueName>(name: TName): Promise<QueueClient<"cloudflare" | "vercel", QueuePayload<TName>>>;
43
+ /**
44
+ * Enqueues one job and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
45
+ * Config errors, for example an unknown Queue name, throw.
46
+ */
47
+ export declare function runQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?: QueueEnqueueOptions): Promise<Result<QueueSendResult, QueueErrorCode>>;
48
+ export declare function deferQueue<TName extends QueueName>(name: TName, payload: NoInfer<QueuePayload<TName>>, options?: QueueEnqueueOptions): void;
87
49
  //#endregion
88
50
  //#region src/runtime/create-client.d.ts
89
- declare function createQueueClient(options: QueueProviderOptions): Promise<QueueClient>;
51
+ export declare function createQueueClient(options: QueueProviderOptions): Promise<QueueClient>;
90
52
  //#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 };
53
+ export { type CloudflareQueueBatchHandlerOptions, type CloudflareQueueClient, type CloudflareQueueErrorCode, type CloudflareQueueMessage, type CloudflareQueueMessageBatch, type DiscoveredQueueDefinition, type QueueClient, type QueueDefinition, type QueueDefinitionOptions, type QueueDefinitionRegistry, type QueueEnqueueOptions, type QueueErrorCode, type QueueHandler, type QueueJob, type QueueModuleOptions, type QueueModuleProviderOptions, type QueueName, type QueuePayload, type QueueProvider, type QueueProviderOptions, type QueueRegistry, type QueueSendResult, type ResolvedQueueOptions, type VercelQueueCallbackOptions, type VercelQueueClient, type VercelQueueErrorCode, type VercelQueueRetryDirective, type VercelQueueRetryHandler, type VercelQueueSendResult, createQueueCloudflareWorker };
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
- import { t as normalizeQueueOptions } from "./config-B7xkD1v0.js";
2
- import { c as createQueueMessageId } from "./errors-CjuG_qr-.js";
1
+ import { t as normalizeQueueOptions } from "./config-BINujLv4.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
3
+ import { t as createQueueMessageId } from "./enqueue-CnQ0QR3O.js";
3
4
  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";
5
+ import { n as createCloudflareQueueBatchHandler } from "./cloudflare-client-COzQ8fHk.js";
6
+ import { t as getCloudflareQueueName } from "./cloudflare-resource-name-CCuLDvSP.js";
6
7
  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
+ import { i as runQueue, n as dynamicQueue, r as getQueue, t as deferQueue } from "./client-CIc3jsj2.js";
9
+ import { t as createQueueCloudflareWorker } from "./cloudflare-vite-BCuJOXcT.js";
9
10
  //#region src/definition.ts
10
11
  function defineQueue(handler, options) {
11
- if (typeof handler !== "function") throw new TypeError("`defineQueue()` requires a queue handler.");
12
+ if (typeof handler !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_DEFINITION();
12
13
  return {
13
14
  handler,
14
15
  options
@@ -25,4 +26,4 @@ async function createQueueClient(options) {
25
26
  return await createVercelQueueRuntimeClient(options);
26
27
  }
27
28
  //#endregion
28
- export { createCloudflareQueueBatchHandler, createQueueClient, createQueueCloudflareWorker, createQueueMessageId, deferQueue, defineQueue, getCloudflareQueueBindingName, getCloudflareQueueDefinitionName, getCloudflareQueueName, getQueue, getVercelQueueTopicName, normalizeQueueOptions, runQueue };
29
+ export { createCloudflareQueueBatchHandler, createQueueClient, createQueueCloudflareWorker, createQueueMessageId, deferQueue, defineQueue, dynamicQueue, getCloudflareQueueBindingName, getCloudflareQueueDefinitionName, getCloudflareQueueName, getQueue, getVercelQueueTopicName, normalizeQueueOptions, runQueue };
@@ -0,0 +1,30 @@
1
+ import { relative } from "pathe";
2
+ //#region ../internal/src/inspect.ts
3
+ function relativeDefinitionFile(projectRoot, file) {
4
+ return relative(projectRoot, file).replaceAll("\\", "/");
5
+ }
6
+ /** Summarizes Definitions that have no owner-specific fields. */
7
+ function summarizeDefinitions(projectRoot, definitions, fallbackSource) {
8
+ return definitions.map((definition) => ({
9
+ fields: [],
10
+ file: relativeDefinitionFile(projectRoot, definition.handler),
11
+ name: definition.name,
12
+ source: definition.source || fallbackSource
13
+ }));
14
+ }
15
+ const redactedInspectionValue = "[redacted]";
16
+ const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
17
+ const embeddedUrlCredentialPattern = /\b([a-z][a-z0-9+.-]*:\/\/)[^/\s?#]*@/gi;
18
+ const embeddedCookiePattern = /\b([\w-]*cookie[\w-]*["']?\s*[:=]\s*)(?:"(?:\\[^\r\n]|[^"\\\r\n])*"(?:\s*;\s*[\w.-]+\s*=[^;\r\n]*)*|'(?:\\[^\r\n]|[^'\\\r\n])*'(?:\s*;\s*[\w.-]+\s*=[^;\r\n]*)*|[^\r\n]+?(?=\s*(?:;\s*[^;=\r\n/]+\s*(?:\r?\n|$)|&|\r?\n|$)))/gi;
19
+ const embeddedBearerPattern = /\bbearer\s+[^\s,;]+/gi;
20
+ const embeddedAuthorizationPattern = new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
21
+ const embeddedSecretAssignmentPattern = new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
22
+ /**
23
+ * Removes credentials inside free text, for example an error message. URL credentials, bearer tokens, and
24
+ * `name=value` pairs with a secret name are replaced with `[redacted]`.
25
+ */
26
+ function redactInspectionText(value) {
27
+ return value.replace(embeddedUrlCredentialPattern, `$1${redactedInspectionValue}@`).replace(embeddedAuthorizationPattern, `$1${redactedInspectionValue}`).replace(embeddedCookiePattern, `$1${redactedInspectionValue}`).replace(embeddedBearerPattern, `Bearer ${redactedInspectionValue}`).replace(embeddedSecretAssignmentPattern, `$1${redactedInspectionValue}`);
28
+ }
29
+ //#endregion
30
+ export { summarizeDefinitions as n, redactInspectionText as t };
@@ -1,6 +1,4 @@
1
- import { _ as QueueProviderOptions, o as QueueClient } from "../../types-CwvoMATy.js";
2
-
1
+ import { b as QueueProviderOptions, s as QueueClient } from "../../types-1GRMYES1.js";
3
2
  //#region src/internal/runtime/cloudflare-client.d.ts
4
- declare function createCloudflareQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
5
- //#endregion
6
- export { createCloudflareQueueRuntimeClient };
3
+ export declare function createCloudflareQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
4
+ //#endregion
@@ -1,2 +1,2 @@
1
- import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-w5vphoNn.js";
1
+ import { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-COzQ8fHk.js";
2
2
  export { createCloudflareQueueRuntimeClient };
@@ -1,2 +1,2 @@
1
- import { i as createQueueCloudflareWorker, n as QueueCloudflareWorker, r as QueueCloudflareWorkerOptions, t as CloudflareWorkerApp } from "../../cloudflare-vite-nFPor46-.js";
1
+ import { i as createQueueCloudflareWorker, n as QueueCloudflareWorker, r as QueueCloudflareWorkerOptions, t as CloudflareWorkerApp } from "../../cloudflare-vite-CjdP5yBN.js";
2
2
  export { CloudflareWorkerApp, QueueCloudflareWorker, QueueCloudflareWorkerOptions, createQueueCloudflareWorker };
@@ -1,2 +1,2 @@
1
- import { t as createQueueCloudflareWorker } from "../../cloudflare-vite-bA1eLf46.js";
1
+ import { t as createQueueCloudflareWorker } from "../../cloudflare-vite-BCuJOXcT.js";
2
2
  export { createQueueCloudflareWorker };
@@ -1,16 +1,17 @@
1
- import { _ as QueueProviderOptions, l as QueueDefinitionRegistry, o as QueueClient, s as QueueDefinition, y as ResolvedQueueOptions } from "../../types-CwvoMATy.js";
2
-
1
+ import { C as ResolvedQueueOptions, b as QueueProviderOptions, c as QueueDefinition, s as QueueClient, u as QueueDefinitionRegistry } from "../../types-1GRMYES1.js";
3
2
  //#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 };
3
+ export type QueueRuntimeClientFactory = (options: QueueProviderOptions) => QueueClient | Promise<QueueClient>;
4
+ export declare function missingQueueDefinitionError(queue: string): Error;
5
+ export declare function setQueueRuntimeConfig(config: false | ResolvedQueueOptions | undefined, createClient?: QueueRuntimeClientFactory): void;
6
+ export declare function getQueueRuntimeConfig(): false | ResolvedQueueOptions | undefined;
7
+ export declare function getQueueRuntimeClientFactory(): QueueRuntimeClientFactory | undefined;
8
+ export declare function runWithQueueRuntimeEvent<T>(event: unknown, callback: () => T): T;
9
+ export declare function enterQueueRuntimeEvent(event: unknown): void;
10
+ export declare function getQueueRuntimeEvent(): unknown;
11
+ export declare function setQueueRuntimeEventDefaults(event: unknown): void;
12
+ export declare function setQueueRuntimeRegistry(registry: QueueDefinitionRegistry | undefined): void;
13
+ /** The names of the Queue Definitions that this runtime loads, sorted. */
14
+ export declare function listQueueDefinitionNames(): string[];
15
+ export declare function getOrCreateQueueClient(name: string, createClient: () => Promise<QueueClient>): Promise<QueueClient>;
16
+ export declare function loadQueueDefinition(name: string): Promise<QueueDefinition | undefined>;
17
+ //#endregion
@@ -1,2 +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 };
1
+ import { a as getQueueRuntimeEvent, c as missingQueueDefinitionError, d as setQueueRuntimeEventDefaults, f as setQueueRuntimeRegistry, i as getQueueRuntimeConfig, l as runWithQueueRuntimeEvent, n as getOrCreateQueueClient, o as listQueueDefinitionNames, r as getQueueRuntimeClientFactory, s as loadQueueDefinition, t as enterQueueRuntimeEvent, u as setQueueRuntimeConfig } from "../../state-G9s378-e.js";
2
+ export { enterQueueRuntimeEvent, getOrCreateQueueClient, getQueueRuntimeClientFactory, getQueueRuntimeConfig, getQueueRuntimeEvent, listQueueDefinitionNames, loadQueueDefinition, missingQueueDefinitionError, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeRegistry };
@@ -1,6 +1,4 @@
1
- import { _ as QueueProviderOptions, o as QueueClient } from "../../types-CwvoMATy.js";
2
-
1
+ import { b as QueueProviderOptions, s as QueueClient } from "../../types-1GRMYES1.js";
3
2
  //#region src/internal/runtime/vercel-client.d.ts
4
- declare function createVercelQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
5
- //#endregion
6
- export { createVercelQueueRuntimeClient };
3
+ export declare function createVercelQueueRuntimeClient(options: QueueProviderOptions): Promise<QueueClient>;
4
+ //#endregion
@@ -1,45 +1,75 @@
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";
1
+ import { t as queueErrorDiagnostics } from "../../error-diagnostics-qzRF6IVB.js";
2
+ import { n as normalizeQueueEnqueueInput } from "../../enqueue-CnQ0QR3O.js";
3
+ import { a as queueProviderResult } from "../../errors-DIFaM9tW.js";
4
+ import { t as resolveVercelQueueRegion } from "../../vercel-region-cjskrOKl.js";
3
5
  //#region src/providers/vercel.ts
4
- function readHeader(headers, name) {
5
- if (!headers) return;
6
- if (headers instanceof Headers) return headers.get(name) || void 0;
7
- const value = headers[name] ?? headers[name.toLowerCase()];
8
- if (typeof value === "string") return value;
9
- if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
10
- }
11
- function parseRegionFromVercelId(value) {
12
- if (!value) return;
13
- return value.match(/^([a-z0-9]+)::/i)?.[1]?.toLowerCase();
6
+ function invalidVercelSendResponse(cause) {
7
+ return [queueErrorDiagnostics.QUEUE_PROVIDER_INVALID_RESPONSE({ cause }), void 0];
14
8
  }
15
- function resolveVercelRegion(explicitRegion) {
16
- if (explicitRegion) return explicitRegion;
17
- if (typeof process.env.QUEUE_REGION === "string" && process.env.QUEUE_REGION) return process.env.QUEUE_REGION;
18
- if (typeof process.env.VERCEL_REGION === "string" && process.env.VERCEL_REGION) return process.env.VERCEL_REGION;
19
- const event = getQueueRuntimeEvent();
20
- const requestHeaders = event?.request instanceof Request ? event.request.headers : event?.req?.headers ?? event?.node?.req?.headers;
21
- return readHeader(requestHeaders, "ce-vqsregion") || parseRegionFromVercelId(readHeader(requestHeaders, "x-vercel-id"));
9
+ function isRuntimeFunction(value) {
10
+ if (value === null || value === void 0 || Object(value) !== value) return false;
11
+ try {
12
+ Function.prototype.toString.call(value);
13
+ return true;
14
+ } catch {
15
+ return false;
16
+ }
22
17
  }
23
- function invalidVercelSendResponse(cause) {
24
- throw createQueueError("QUEUE_PROVIDER_RESPONSE_INVALID", {
25
- cause,
26
- details: {
27
- operation: "send",
28
- provider: "vercel"
18
+ function isVercelQueueSDK(value) {
19
+ if (value === null || typeof value !== "object") return false;
20
+ try {
21
+ if (Array.isArray(value)) return false;
22
+ } catch {
23
+ return false;
24
+ }
25
+ const hasCallableMethod = (name) => {
26
+ let owner = value;
27
+ while (owner && owner !== Object.prototype) {
28
+ let descriptor;
29
+ try {
30
+ descriptor = Object.getOwnPropertyDescriptor(owner, name);
31
+ } catch {
32
+ return false;
33
+ }
34
+ if (descriptor) {
35
+ if (owner !== value) {
36
+ let constructor;
37
+ try {
38
+ constructor = Object.getOwnPropertyDescriptor(owner, "constructor");
39
+ if (!constructor || !("value" in constructor) || !isRuntimeFunction(constructor.value) || constructor.value.prototype !== owner) return false;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+ if ("value" in descriptor) return isRuntimeFunction(descriptor.value);
45
+ try {
46
+ return isRuntimeFunction(Reflect.get(value, name));
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
51
+ try {
52
+ owner = Object.getPrototypeOf(owner);
53
+ } catch {
54
+ return false;
55
+ }
29
56
  }
30
- });
57
+ return false;
58
+ };
59
+ return hasCallableMethod("send") && hasCallableMethod("handleCallback");
31
60
  }
32
61
  function parseVercelMessageId(value) {
33
- if (!value || typeof value !== "object" || Array.isArray(value)) invalidVercelSendResponse(value);
62
+ if (!value || typeof value !== "object" || Array.isArray(value)) return invalidVercelSendResponse(value);
34
63
  let messageId;
35
64
  try {
65
+ if (!Object.prototype.hasOwnProperty.call(value, "messageId")) return invalidVercelSendResponse(value);
36
66
  messageId = Reflect.get(value, "messageId");
37
67
  } catch (cause) {
38
- invalidVercelSendResponse(cause);
68
+ return invalidVercelSendResponse(cause);
39
69
  }
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;
70
+ if (messageId === null) return [void 0, void 0];
71
+ if (typeof messageId !== "string" || !messageId || messageId.length > 128 || messageId.trim() !== messageId) return invalidVercelSendResponse(value);
72
+ return [void 0, messageId];
43
73
  }
44
74
  async function loadVercelQueueClient(region) {
45
75
  let module;
@@ -56,50 +86,48 @@ async function loadVercelQueueClient(region) {
56
86
  module = await import(specifier);
57
87
  }
58
88
  }
59
- } catch (error) {
60
- if (isQueueBoundaryIdentity(error)) throw error;
61
- throw createQueueError("VERCEL_QUEUE_SDK_LOAD_FAILED", {
62
- cause: error,
63
- details: {
64
- operation: "load-sdk",
65
- provider: "vercel"
66
- }
67
- });
89
+ } catch (cause) {
90
+ throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_UNAVAILABLE({ cause });
68
91
  }
69
- const resolvedRegion = resolveVercelRegion(region);
70
- if ("QueueClient" in module && typeof module.QueueClient === "function") {
71
- if (!resolvedRegion) throw createQueueError("VERCEL_QUEUE_REGION_REQUIRED", { details: { provider: "vercel" } });
92
+ const { region: resolvedRegion } = resolveVercelQueueRegion(region);
93
+ if (Object.hasOwn(module, "QueueClient") && isRuntimeFunction(module.QueueClient)) {
94
+ if (!resolvedRegion) throw queueErrorDiagnostics.QUEUE_MISSING_REGION();
72
95
  return new module.QueueClient({ region: resolvedRegion });
73
96
  }
74
- if (typeof module.send === "function" && typeof module.handleCallback === "function") return {
97
+ if (Object.hasOwn(module, "send") && Object.hasOwn(module, "handleCallback") && isRuntimeFunction(module.send) && isRuntimeFunction(module.handleCallback)) return {
75
98
  handleCallback: module.handleCallback,
76
99
  send: module.send
77
100
  };
78
- throw createQueueError("VERCEL_QUEUE_SDK_INVALID", { details: { provider: "vercel" } });
101
+ throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_INVALID();
79
102
  }
80
103
  async function createVercelQueueClient(provider) {
81
104
  const topic = provider.topic;
82
- if (!topic) throw createQueueError("VERCEL_TOPIC_RESOLUTION_REQUIRED", { details: { provider: "vercel" } });
83
- const client = provider.client || await loadVercelQueueClient(provider.region);
105
+ if (!topic) throw queueErrorDiagnostics.QUEUE_MISSING_TOPIC();
106
+ const client = provider.client === void 0 ? await loadVercelQueueClient(provider.region) : provider.client;
107
+ if (!isVercelQueueSDK(client)) throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_INVALID();
84
108
  return {
85
109
  provider: "vercel",
86
110
  native: client,
87
111
  topic,
88
- async send(input) {
89
- const normalized = normalizeQueueEnqueueInput(input);
90
- if (normalized.options.contentType !== void 0) throw createQueueError("VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS", { details: {
91
- provider: "vercel",
92
- unsupported: ["contentType"]
93
- } });
94
- return {
112
+ async send(payload, options) {
113
+ const normalized = normalizeQueueEnqueueInput(payload, options);
114
+ if (normalized.options.contentType !== void 0) return [queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
115
+ options: "`contentType`",
116
+ provider: "vercel"
117
+ }), void 0];
118
+ const [error, response] = await queueProviderResult("vercel", "send", () => client.send(topic, normalized.payload, {
119
+ delaySeconds: normalized.options.delaySeconds,
120
+ idempotencyKey: normalized.options.idempotencyKey || normalized.id,
121
+ region: normalized.options.region ?? provider.region,
122
+ retentionSeconds: normalized.options.retentionSeconds
123
+ }));
124
+ if (error) return [error, void 0];
125
+ const [responseError, messageId] = parseVercelMessageId(response);
126
+ if (responseError) return [responseError, void 0];
127
+ return [void 0, {
95
128
  status: "queued",
96
- messageId: await runQueueProviderOperation("vercel", "send", async () => parseVercelMessageId(await client.send(topic, normalized.payload, {
97
- delaySeconds: normalized.options.delaySeconds,
98
- idempotencyKey: normalized.options.idempotencyKey || normalized.id,
99
- region: normalized.options.region ?? provider.region,
100
- retentionSeconds: normalized.options.retentionSeconds
101
- })))
102
- };
129
+ messageId
130
+ }];
103
131
  },
104
132
  callback: client.handleCallback.bind(client)
105
133
  };
@@ -107,7 +135,10 @@ async function createVercelQueueClient(provider) {
107
135
  //#endregion
108
136
  //#region src/internal/runtime/vercel-client.ts
109
137
  async function createVercelQueueRuntimeClient(options) {
110
- if (options.provider !== "vercel") throw new TypeError("[vitehub] Vercel Queue runtime received a non-Vercel provider.");
138
+ if (options.provider !== "vercel") throw queueErrorDiagnostics.QUEUE_PROVIDER_MISMATCH({
139
+ expected: "vercel",
140
+ provider: options.provider
141
+ });
111
142
  return await createVercelQueueClient(options);
112
143
  }
113
144
  //#endregion
package/dist/nuxt.d.ts CHANGED
@@ -1,10 +1,31 @@
1
- import { m as QueueModuleOptions } from "./types-CwvoMATy.js";
2
-
1
+ import { h as QueueModuleOptions } from "./types-1GRMYES1.js";
2
+ //#region ../internal/src/build/vite.d.ts
3
+ interface NuxtLayerDirectoryConfig {
4
+ rootDir?: string;
5
+ serverDir?: string;
6
+ srcDir?: string;
7
+ }
8
+ /** The Nuxt options that locate the server directory of each layer. */
9
+ interface NuxtServerDirOptions extends NuxtLayerDirectoryConfig {
10
+ _layers?: ReadonlyArray<{
11
+ config?: NuxtLayerDirectoryConfig;
12
+ cwd?: string;
13
+ }>;
14
+ }
15
+ //#endregion
3
16
  //#region src/nuxt.d.ts
4
- type QueueNuxtModuleOptions = QueueModuleOptions;
17
+ export type QueueNuxtModuleOptions = QueueModuleOptions;
5
18
  type NuxtLike = {
6
- hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
19
+ hook?: {
20
+ (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>): void;
21
+ (name: "prepare:types", handler: (context: {
22
+ references: {
23
+ path: string;
24
+ }[];
25
+ }) => void): void;
26
+ };
7
27
  options: {
28
+ _layers?: NuxtServerDirOptions["_layers"];
8
29
  dev?: boolean;
9
30
  rootDir?: string;
10
31
  serverDir?: string;
@@ -14,6 +35,5 @@ type NuxtLike = {
14
35
  };
15
36
  };
16
37
  };
17
- declare function viteHubQueueNuxtModule(options?: QueueNuxtModuleOptions, nuxt?: NuxtLike): void;
18
- //#endregion
19
- export { QueueNuxtModuleOptions, viteHubQueueNuxtModule as default };
38
+ export default function viteHubQueueNuxtModule(options?: QueueNuxtModuleOptions, nuxt?: NuxtLike): void;
39
+ //#endregion
package/dist/nuxt.js CHANGED
@@ -1,4 +1,5 @@
1
- import { n as hubQueue, t as createQueueNitroConfig } from "./vite-BcMpQk_n.js";
1
+ import { n as hubQueue, o as resolveNuxtServerDirs, t as createQueueNitroConfig } from "./vite-ChWLzOVu.js";
2
+ import { resolve } from "node:path";
2
3
  //#region src/nuxt.ts
3
4
  function isQueueVitePlugin(value) {
4
5
  return Boolean(value && typeof value === "object" && value.name === "@vite-hub/queue/vite");
@@ -8,6 +9,9 @@ function findQueueVitePlugin(plugins) {
8
9
  }
9
10
  function viteHubQueueNuxtModule(options = {}, nuxt) {
10
11
  if (!nuxt) return;
12
+ nuxt.hook?.("prepare:types", (context) => {
13
+ context.references.push({ path: resolve(nuxt.options.rootDir || process.cwd(), ".vitehub/queue.d.ts") });
14
+ });
11
15
  nuxt.options.vite ??= {};
12
16
  const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
13
17
  const existingPlugin = findQueueVitePlugin(plugins);
@@ -17,10 +21,11 @@ function viteHubQueueNuxtModule(options = {}, nuxt) {
17
21
  nuxt.hook?.("nitro:config", async (nitroConfig) => {
18
22
  const projectRoot = nuxt.options.rootDir || process.cwd();
19
23
  const nitro = await createQueueNitroConfig(plugin, {
24
+ development: nuxt.options.dev,
20
25
  nitro: nitroConfig,
21
26
  projectRoot,
22
27
  root: nuxt.options.srcDir || projectRoot,
23
- serverDirs: nuxt.options.serverDir ? [nuxt.options.serverDir] : void 0
28
+ serverDirs: resolveNuxtServerDirs(nuxt.options)
24
29
  });
25
30
  Object.assign(nitroConfig, nitro);
26
31
  });
@@ -0,0 +1,7 @@
1
+ //#region ../internal/src/object.ts
2
+ function isPlainObject(value) {
3
+ if (value === null || Object(value) !== value || Array.isArray(value)) return false;
4
+ return typeof value === "object";
5
+ }
6
+ //#endregion
7
+ export { isPlainObject as t };