@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.
Files changed (51) hide show
  1. package/README.md +41 -23
  2. package/dist/client-CIc3jsj2.js +114 -0
  3. package/dist/cloudflare-client-COzQ8fHk.js +147 -0
  4. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-CCuLDvSP.js} +3 -2
  5. package/dist/{cloudflare-vite-BlQfDVZD.js → cloudflare-vite-BCuJOXcT.js} +23 -9
  6. package/dist/{cloudflare-vite-nFPor46-.d.ts → cloudflare-vite-CjdP5yBN.d.ts} +9 -4
  7. package/dist/config-BINujLv4.js +74 -0
  8. package/dist/enqueue-CnQ0QR3O.js +22 -0
  9. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  10. package/dist/error-diagnostics-qzRF6IVB.js +109 -0
  11. package/dist/errors-DIFaM9tW.js +42 -0
  12. package/dist/handler-response-CBwIkmTS.js +56 -0
  13. package/dist/index.d.ts +32 -70
  14. package/dist/index.js +9 -8
  15. package/dist/inspect-PeuckaC3.js +30 -0
  16. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  17. package/dist/internal/runtime/cloudflare-client.js +1 -1
  18. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  19. package/dist/internal/runtime/cloudflare-vite.js +1 -1
  20. package/dist/internal/runtime/state.d.ts +16 -15
  21. package/dist/internal/runtime/state.js +2 -2
  22. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  23. package/dist/internal/runtime/vercel-client.js +93 -62
  24. package/dist/nuxt.d.ts +27 -7
  25. package/dist/nuxt.js +6 -2
  26. package/dist/object-B1NW521B.js +7 -0
  27. package/dist/operations-Cnjbz8kk.js +63 -0
  28. package/dist/operations-tNUdj3G4.d.ts +212 -0
  29. package/dist/operations.d.ts +32 -0
  30. package/dist/operations.js +1195 -0
  31. package/dist/runtime/hosted.d.ts +4 -6
  32. package/dist/runtime/hosted.js +30 -8
  33. package/dist/state-G9s378-e.js +184 -0
  34. package/dist/{types-CwvoMATy.d.ts → types-1GRMYES1.d.ts} +35 -24
  35. package/dist/vercel-region-cjskrOKl.js +122 -0
  36. package/dist/vite-ChWLzOVu.js +1512 -0
  37. package/dist/vite.d.ts +334 -34
  38. package/dist/vite.js +2 -2
  39. package/package.json +68 -25
  40. package/dist/_app-D29AwUdD.d.ts +0 -11
  41. package/dist/app-BZpq2cwC.js +0 -10
  42. package/dist/client-DG9fweET.js +0 -93
  43. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  44. package/dist/config-CNgAeIND.js +0 -53
  45. package/dist/delivery-error-glgYWC9g.js +0 -45
  46. package/dist/errors-CjuG_qr-.js +0 -108
  47. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  48. package/dist/internal/runtime/vercel-vite.js +0 -49
  49. package/dist/state-Cno9O7YS.js +0 -110
  50. package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
  51. package/dist/vite-DOuoen0w.js +0 -4414
@@ -0,0 +1,116 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
6
+ codes: {
7
+ INTERNAL_R0012: dynamicError,
8
+ INTERNAL_R0013: dynamicError,
9
+ INTERNAL_R0014: {
10
+ why: ({ path }) => `Cannot read Provision State from "${path}".`,
11
+ fix: "Check file access and restore valid JSON while preserving existing resource IDs."
12
+ },
13
+ INTERNAL_R0020: {
14
+ fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
15
+ why: ({ message }) => message === void 0 ? "" : String(message)
16
+ },
17
+ INTERNAL_R0021: {
18
+ fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
19
+ why: ({ message }) => message === void 0 ? "" : String(message)
20
+ },
21
+ INTERNAL_R0022: {
22
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
23
+ why: ({ message }) => message === void 0 ? "" : String(message)
24
+ },
25
+ INTERNAL_R0024: {
26
+ fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app with credentials in VITEHUB_CONSOLE_AUTHORIZATION, VITEHUB_CONSOLE_COOKIE, or CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET.",
27
+ why: ({ message }) => message === void 0 ? "" : String(message)
28
+ },
29
+ INTERNAL_R0023: {
30
+ fix: "Ask for access to the section of this operation.",
31
+ why: ({ message }) => message === void 0 ? "" : String(message)
32
+ },
33
+ INTERNAL_B0001: dynamicError,
34
+ INTERNAL_B0002: dynamicError,
35
+ INTERNAL_B0003: dynamicError,
36
+ INTERNAL_B0004: dynamicError,
37
+ INTERNAL_B0005: dynamicError,
38
+ INTERNAL_B0006: dynamicError,
39
+ INTERNAL_B0007: dynamicError,
40
+ INTERNAL_B0008: dynamicError,
41
+ INTERNAL_B0009: dynamicError,
42
+ INTERNAL_B0010: dynamicError,
43
+ INTERNAL_B0011: dynamicError,
44
+ INTERNAL_B0012: dynamicError,
45
+ INTERNAL_B0013: dynamicError,
46
+ INTERNAL_B0014: dynamicError,
47
+ INTERNAL_B0015: dynamicError,
48
+ INTERNAL_B0016: dynamicError,
49
+ INTERNAL_B0017: dynamicError,
50
+ INTERNAL_B0018: dynamicError,
51
+ INTERNAL_B0019: dynamicError,
52
+ INTERNAL_B0020: dynamicError,
53
+ INTERNAL_B0021: dynamicError,
54
+ INTERNAL_B0022: dynamicError,
55
+ INTERNAL_B0023: dynamicError,
56
+ INTERNAL_B0024: dynamicError,
57
+ INTERNAL_B0025: dynamicError,
58
+ INTERNAL_B0026: dynamicError,
59
+ INTERNAL_B0027: dynamicError,
60
+ INTERNAL_B0028: dynamicError,
61
+ INTERNAL_B0029: dynamicError,
62
+ INTERNAL_B0030: dynamicError,
63
+ INTERNAL_B0031: dynamicError,
64
+ INTERNAL_B0032: dynamicError,
65
+ INTERNAL_B0033: dynamicError,
66
+ INTERNAL_B0034: dynamicError,
67
+ INTERNAL_B0035: dynamicError,
68
+ INTERNAL_B0036: dynamicError,
69
+ INTERNAL_B0037: dynamicError,
70
+ INTERNAL_B0038: dynamicError,
71
+ INTERNAL_B0039: dynamicError,
72
+ INTERNAL_B0040: dynamicError,
73
+ INTERNAL_B0041: dynamicError,
74
+ INTERNAL_B0042: dynamicError,
75
+ INTERNAL_B0043: dynamicError,
76
+ INTERNAL_B0044: dynamicError,
77
+ INTERNAL_B0045: dynamicError,
78
+ INTERNAL_B0046: dynamicError,
79
+ INTERNAL_B0047: dynamicError,
80
+ INTERNAL_B0048: {
81
+ fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
82
+ why: ({ message }) => message === void 0 ? "" : String(message)
83
+ },
84
+ INTERNAL_B0049: {
85
+ fix: "Set `cli: { namespace, command }` on one of the two operations.",
86
+ why: ({ message }) => message === void 0 ? "" : String(message)
87
+ },
88
+ INTERNAL_B0050: {
89
+ fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
90
+ why: ({ message }) => message === void 0 ? "" : String(message)
91
+ },
92
+ INTERNAL_R0025: {
93
+ fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
94
+ why: ({ message }) => message === void 0 ? "" : String(message)
95
+ },
96
+ INTERNAL_R0026: {
97
+ why: "The server parsed a destructive operation that the CLI did not confirm.",
98
+ fix: "Review the operation, then run it again with --yes to confirm the change."
99
+ },
100
+ INTERNAL_C0001: dynamicError,
101
+ INTERNAL_C0002: dynamicError,
102
+ INTERNAL_R0001: dynamicError,
103
+ INTERNAL_R0002: dynamicError,
104
+ INTERNAL_R0003: dynamicError,
105
+ INTERNAL_R0004: dynamicError,
106
+ INTERNAL_R0005: dynamicError,
107
+ INTERNAL_R0006: dynamicError,
108
+ INTERNAL_R0007: dynamicError,
109
+ INTERNAL_R0008: dynamicError,
110
+ INTERNAL_R0009: dynamicError,
111
+ INTERNAL_R0010: dynamicError,
112
+ INTERNAL_R0011: dynamicError
113
+ }
114
+ });
115
+ //#endregion
116
+ export { internalErrorDiagnostics as t };
@@ -0,0 +1,109 @@
1
+ import { defineErrors } from "@vite-hub/runtime";
2
+ //#region src/error-diagnostics.ts
3
+ const queueErrorDiagnostics = /*#__PURE__*/ defineErrors({
4
+ docs: "https://vitehub.dev/docs/queue/limits-and-errors",
5
+ codes: {
6
+ QUEUE_PROVIDER_FAILED: {
7
+ why: ({ operation, provider }) => `The ${provider} queue provider failed during ${operation}.`,
8
+ fix: "Read `error.cause` for the provider error. Retry when the provider is available again. Pass `idempotencyKey` on Vercel so that a retry does not enqueue the job two times."
9
+ },
10
+ QUEUE_PROVIDER_INVALID_RESPONSE: {
11
+ why: "The Vercel queue provider accepted the job, but returned an invalid `messageId`.",
12
+ fix: "Do not send the job again without an `idempotencyKey`, because the provider can have it. Check the installed `@vercel/queue` version."
13
+ },
14
+ QUEUE_UNSUPPORTED_OPTION: {
15
+ why: ({ options, provider }) => `The ${provider} queue provider does not support the enqueue option ${options}.`,
16
+ fix: "Remove the option for this provider. The enqueue options table on the Queue Server API page shows which provider supports each option."
17
+ },
18
+ QUEUE_BINDING_NOT_FOUND: {
19
+ why: ({ binding }) => binding ? `The Cloudflare queue binding "${binding}" is not in the Worker env.` : "The Cloudflare queue client has no binding.",
20
+ fix: "The dev server has no local Queue delivery. Run the built Worker with `wrangler dev`, or deploy it. In a deployed Worker, add the binding to the Worker configuration."
21
+ },
22
+ QUEUE_DEFINITION_LOAD_FAILED: {
23
+ why: ({ queue }) => queue ? `The Queue Definition "${queue}" failed to load.` : "A Queue Definition failed to load.",
24
+ fix: "Read `error.cause` for the import error, and fix the Queue Definition module."
25
+ },
26
+ QUEUE_DEFINITION_NOT_FOUND: {
27
+ why: ({ queue }) => queue ? `No Queue Definition has the name "${queue}".` : "No Queue Definition has the requested name.",
28
+ fix: "Add `server/queues/<name>.ts` with a default `defineQueue()` export, and build again. The generated server output loads the Queue Definitions, so a script that runs outside of it finds none."
29
+ },
30
+ QUEUE_DISABLED: {
31
+ why: "Queue is disabled in this runtime.",
32
+ fix: "Add `hubQueue()` to the Vite config and do not set `queue: false`."
33
+ },
34
+ QUEUE_INVALID_BINDING: {
35
+ why: "The Cloudflare queue binding does not have `send()` and `sendBatch()`.",
36
+ fix: "Pass a Cloudflare Queue producer binding, for example `env.WELCOME_QUEUE`."
37
+ },
38
+ QUEUE_MISSING_REGION: {
39
+ why: "The installed `@vercel/queue` needs a region, and ViteHub cannot find one.",
40
+ fix: "Set `queue.region` in the Vite config, or set the `QUEUE_REGION` environment variable."
41
+ },
42
+ QUEUE_MISSING_TOPIC: {
43
+ why: "A direct Vercel queue client needs a `topic`.",
44
+ fix: "Pass `topic` to `createQueueClient()`, or use `getQueue()` for a discovered Queue Definition."
45
+ },
46
+ QUEUE_PROVIDER_MISMATCH: {
47
+ why: ({ expected, provider }) => `The ${expected} Queue runtime received the ${provider} provider.`,
48
+ fix: "Set `queue.provider` to the provider of the deployment preset, and build again."
49
+ },
50
+ QUEUE_RUNTIME_NOT_INSTALLED: {
51
+ why: "The Queue runtime has no client factory. The generated server output installs it.",
52
+ fix: "Add `hubQueue()` to the Vite config, build the app, and run the built server."
53
+ },
54
+ QUEUE_VERCEL_SDK_INVALID: {
55
+ why: "`@vercel/queue` does not have the client API that ViteHub uses.",
56
+ fix: "Install a supported `@vercel/queue` version, or pass a `client` that has `send()` and `handleCallback()`."
57
+ },
58
+ QUEUE_VERCEL_SDK_UNAVAILABLE: {
59
+ why: "`@vercel/queue` cannot be loaded.",
60
+ fix: "Add `@vercel/queue` to the app dependencies. Read `error.cause` for the import error."
61
+ },
62
+ QUEUE_BINDING_CONFLICT: {
63
+ why: "A custom `queue.binding` works with one Queue Definition only, and this app has more.",
64
+ fix: "Remove `queue.binding`, so that each Queue Definition gets its own generated binding."
65
+ },
66
+ QUEUE_CRYPTO_UNAVAILABLE: {
67
+ why: "Cloudflare queue names for long Queue Definition names need the `node:crypto` module, and this runtime does not have it.",
68
+ fix: "Enable the `nodejs_compat` compatibility flag, or use a shorter Queue Definition name."
69
+ },
70
+ QUEUE_DEFINITIONS_CHANGED: {
71
+ why: ({ context }) => `The ${context} Queue Definitions changed after Vite resolved the config.`,
72
+ fix: "Generate Queue Definition files before the Vite config resolves, then build again."
73
+ },
74
+ QUEUE_INVALID_CONFIG: {
75
+ why: "`queue` must be a plain object or `false`.",
76
+ fix: "Pass an object, for example `queue: { provider: 'cloudflare' }`."
77
+ },
78
+ QUEUE_INVALID_DEFINITION: {
79
+ why: "`defineQueue()` needs a handler function.",
80
+ fix: "Pass the handler as the first argument, for example `defineQueue(async (job) => { ... })`."
81
+ },
82
+ QUEUE_INVALID_NAME: {
83
+ why: ({ name }) => `The Cloudflare queue name "${name}" can contain only letters, numbers, and dashes, and must start and end with a letter or number.`,
84
+ fix: "Change `queue.namePrefix` so that it contains only letters, numbers, and dashes."
85
+ },
86
+ QUEUE_INVALID_PROVIDER: {
87
+ why: ({ provider }) => `\`queue.provider\` "${provider}" is not a Queue provider.`,
88
+ fix: "Set `queue.provider` to \"cloudflare\" or \"vercel\"."
89
+ },
90
+ QUEUE_MISSING_PROVIDER: {
91
+ why: ({ hosting }) => `ViteHub cannot select a Queue provider for ${hosting} hosting.`,
92
+ fix: "Set `queue.provider`, select the Cloudflare or Vercel deployment preset, or set `queue: false`."
93
+ },
94
+ QUEUE_NAME_COLLISION: {
95
+ why: ({ first, resolved, second }) => `The Queue Definitions "${first}" and "${second}" have the same provider name "${resolved}".`,
96
+ fix: "Rename one of the two Queue Definition files."
97
+ },
98
+ QUEUE_PLUGIN_INCOMPATIBLE: {
99
+ why: "The `hubQueue()` plugin in the Vite config does not expose the Queue Nitro config.",
100
+ fix: "Install one version of `@vite-hub/queue`, and use `hubQueue()` from it."
101
+ },
102
+ QUEUE_PROVISION_FAILED: {
103
+ why: "Cloudflare returned an invalid queue list during provisioning.",
104
+ fix: "Run `vitehub provision run --provider cloudflare --dry-run` again, and check the Cloudflare token permissions."
105
+ }
106
+ }
107
+ });
108
+ //#endregion
109
+ export { queueErrorDiagnostics as t };
@@ -0,0 +1,42 @@
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
2
+ import { isRuntimeDiagnostic } from "@vite-hub/runtime";
3
+ //#region src/errors.ts
4
+ const cloudflareUnsupportedEnqueueOptions = [
5
+ "idempotencyKey",
6
+ "region",
7
+ "retentionSeconds"
8
+ ];
9
+ /** Returns `true` for an error from the Queue catalog. Pass `codes` to accept only some codes. */
10
+ function isQueueError(error, codes) {
11
+ if (!isRuntimeDiagnostic(error) || !Object.hasOwn(queueErrorDiagnostics, error.code)) return false;
12
+ return !codes || codes.some((code) => code === error.code);
13
+ }
14
+ /** Formats option names for an error `why`, for example `"region" and "retentionSeconds"`. */
15
+ function formatQueueOptionNames(names) {
16
+ const quoted = names.map((name) => `\`${name}\``);
17
+ return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}` : quoted.join("");
18
+ }
19
+ function normalizePublicQueueIdentifier(value) {
20
+ if (typeof value !== "string" || !value || value.length > 128 || value.trim() !== value) return;
21
+ if (!/^[a-z\d][a-z\d._/-]*$/i.test(value)) return;
22
+ if (/^[a-z][a-z\d+.-]*:\/\//i.test(value) || /^[a-z]:\//i.test(value)) return;
23
+ if (value.split("/").some((part) => part === "." || part === "..")) return;
24
+ return value;
25
+ }
26
+ /**
27
+ * Runs one provider call and returns `[error, data]`.
28
+ * Any failure becomes `QUEUE_PROVIDER_FAILED` with the failure in `cause`.
29
+ */
30
+ async function queueProviderResult(provider, operation, run) {
31
+ try {
32
+ return [void 0, await run()];
33
+ } catch (cause) {
34
+ return [queueErrorDiagnostics.QUEUE_PROVIDER_FAILED({
35
+ cause,
36
+ operation,
37
+ provider
38
+ }), void 0];
39
+ }
40
+ }
41
+ //#endregion
42
+ export { queueProviderResult as a, normalizePublicQueueIdentifier as i, formatQueueOptionNames as n, isQueueError as r, cloudflareUnsupportedEnqueueOptions as t };
@@ -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-CNgAeIND.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-DG9fweET.js";
8
- import { t as createQueueCloudflareWorker } from "./cloudflare-vite-BlQfDVZD.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-BlQfDVZD.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-Cno9O7YS.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