@vite-hub/queue 0.1.0 → 0.4.1

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 (60) hide show
  1. package/README.md +152 -29
  2. package/dist/client-B53_G4ky.js +182 -0
  3. package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-CoISDpIx.js} +28 -21
  4. package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
  5. package/dist/config-B2eaXaT5.js +105 -0
  6. package/dist/durability.d.ts +13 -0
  7. package/dist/durability.js +47 -0
  8. package/dist/duration-tujyhAKt.js +111 -0
  9. package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
  10. package/dist/error-diagnostics-mJXBjmQx.js +181 -0
  11. package/dist/{handler-response-CBwIkmTS.js → handler-response-B6lz9nCn.js} +9 -4
  12. package/dist/index.d.ts +20 -32
  13. package/dist/index.js +39 -17
  14. package/dist/internal/runtime/cloudflare-client.d.ts +2 -2
  15. package/dist/internal/runtime/cloudflare-client.js +1 -1
  16. package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
  17. package/dist/internal/runtime/cloudflare-vite.js +111 -1
  18. package/dist/internal/runtime/local-client.d.ts +17 -0
  19. package/dist/internal/runtime/local-client.js +71 -0
  20. package/dist/internal/runtime/postgres-client.d.ts +46 -0
  21. package/dist/internal/runtime/postgres-client.js +570 -0
  22. package/dist/internal/runtime/state.d.ts +11 -4
  23. package/dist/internal/runtime/state.js +2 -2
  24. package/dist/internal/runtime/vercel-client.d.ts +2 -2
  25. package/dist/internal/runtime/vercel-client.js +66 -28
  26. package/dist/internal/runtime/worker-client.d.ts +6 -0
  27. package/dist/internal/runtime/worker-client.js +11 -0
  28. package/dist/invariant-D8_xBqmZ.js +22 -0
  29. package/dist/local-CUaWoRUx.d.ts +23 -0
  30. package/dist/local-Di0FrVUw.js +553 -0
  31. package/dist/object-D8pRdprI.js +15 -0
  32. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  33. package/dist/operations-BVV-9Q0N.js +129 -0
  34. package/dist/operations.d.ts +47 -9
  35. package/dist/operations.js +186 -69
  36. package/dist/runtime/hosted.d.ts +3 -5
  37. package/dist/runtime/hosted.js +21 -45
  38. package/dist/{state-G9s378-e.js → state-DLqTqF6V.js} +59 -47
  39. package/dist/types-CiuSIPR0.d.ts +440 -0
  40. package/dist/types-Dsbb_Pvp.d.ts +10 -0
  41. package/dist/vercel-region-B95MAMXN.js +26 -0
  42. package/dist/virtual.d.ts +4 -0
  43. package/dist/vite.d.ts +366 -49
  44. package/dist/vite.js +2071 -2
  45. package/package.json +39 -46
  46. package/dist/client-CIc3jsj2.js +0 -114
  47. package/dist/cloudflare-vite-BCuJOXcT.js +0 -111
  48. package/dist/cloudflare-vite-CjdP5yBN.d.ts +0 -29
  49. package/dist/config-BINujLv4.js +0 -74
  50. package/dist/enqueue-CnQ0QR3O.js +0 -22
  51. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  52. package/dist/error-diagnostics-qzRF6IVB.js +0 -109
  53. package/dist/errors-DIFaM9tW.js +0 -42
  54. package/dist/nuxt.d.ts +0 -39
  55. package/dist/nuxt.js +0 -34
  56. package/dist/object-B1NW521B.js +0 -7
  57. package/dist/operations-Cnjbz8kk.js +0 -63
  58. package/dist/types-1GRMYES1.d.ts +0 -180
  59. package/dist/vercel-region-cjskrOKl.js +0 -122
  60. package/dist/vite-ChWLzOVu.js +0 -1512
@@ -0,0 +1,105 @@
1
+ import { n as isRecord } from "./object-D8pRdprI.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
3
+ import { defu } from "defu";
4
+ /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
5
+ function hostFromNitroPreset(value) {
6
+ const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
7
+ if (!normalized) return;
8
+ if (normalized.startsWith("cloudflare")) return "cloudflare";
9
+ if (normalized.startsWith("deno")) return "deno";
10
+ if (normalized.startsWith("netlify")) return "netlify";
11
+ if (normalized === "node" || normalized.startsWith("node-")) return "node";
12
+ if (normalized.startsWith("vercel")) return "vercel";
13
+ }
14
+ //#endregion
15
+ //#region ../internal/src/hosting.ts
16
+ /**
17
+ * Returns the Nitro preset name that this build targets, as the developer wrote it.
18
+ * The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOST`.
19
+ * Empty values are skipped.
20
+ */
21
+ function resolveHostPreset(input = {}) {
22
+ const env = input.env ?? (typeof process === "undefined" ? {} : process.env);
23
+ const nitroPreset = input.nitro && typeof input.nitro === "object" ? Reflect.get(input.nitro, "preset") : void 0;
24
+ for (const value of [
25
+ nitroPreset,
26
+ input.hosting,
27
+ env.NITRO_PRESET,
28
+ env.SERVER_PRESET,
29
+ env.VITEHUB_HOST
30
+ ]) if (typeof value === "string" && value.trim()) return value.trim();
31
+ }
32
+ /** Returns the host that this build targets: `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. */
33
+ function resolveHost(input = {}) {
34
+ return hostFromNitroPreset(resolveHostPreset(input));
35
+ }
36
+ function normalizeHosting(hosting) {
37
+ const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
38
+ if (normalized === "cloudflare") return "cloudflare-module";
39
+ return normalized;
40
+ }
41
+ /** Narrows a ViteHub host or Nitro preset name to the hosts that have a native provider: Cloudflare, Netlify, or Vercel. */
42
+ function getHostingProvider(hosting) {
43
+ const host = hostFromNitroPreset(hosting);
44
+ if (host === "cloudflare" || host === "netlify" || host === "vercel") return host;
45
+ }
46
+ //#endregion
47
+ //#region src/config.ts
48
+ const knownDrivers = /* @__PURE__ */ new Set([
49
+ "cloudflare",
50
+ "local",
51
+ "postgres",
52
+ "vercel"
53
+ ]);
54
+ /** The variable that overrides the connection of the postgres driver at runtime. */
55
+ const postgresQueueUrlVariable = "QUEUE_POSTGRES_URL";
56
+ /** Default directory of the local driver, next to the KV `fs-lite` store in `.vitehub/data/kv`. */
57
+ const defaultLocalQueueBase = ".vitehub/data/queue";
58
+ /** A self-hosted Node server has no hosted Queue, so it runs Queue Definitions in its own process. */
59
+ function isLocalHosting(hosting) {
60
+ return hosting === "local" || hostFromNitroPreset(hosting) === "node";
61
+ }
62
+ function readOwnOption(options, key) {
63
+ return Object.hasOwn(options, key) ? options[key] : void 0;
64
+ }
65
+ /** The driver without `queue.driver`: the host's Queue, or on Node `postgres` with a Postgres Database, else `local`. */
66
+ function inferDriver(hosting, postgresDatabase) {
67
+ if (hosting.includes("cloudflare")) return "cloudflare";
68
+ if (hosting === "postgres") return "postgres";
69
+ if (isLocalHosting(hosting)) return postgresDatabase ? "postgres" : "local";
70
+ return "vercel";
71
+ }
72
+ function resolveDriver(options, hosting, postgresDatabase) {
73
+ const cache = readOwnOption(options, "cache");
74
+ const shared = typeof cache === "boolean" ? { cache } : {};
75
+ const driver = readOwnOption(options, "driver");
76
+ if (driver === void 0 && Object.hasOwn(options, "provider")) throw queueErrorDiagnostics.QUEUE_RENAMED_PROVIDER_KEY({ value: JSON.stringify(options.provider) ?? String(options.provider) });
77
+ if (typeof driver === "string" && !knownDrivers.has(driver)) throw queueErrorDiagnostics.QUEUE_INVALID_DRIVER({ driver });
78
+ if (typeof driver === "undefined" && hosting && !hosting.includes("cloudflare") && !hosting.includes("vercel") && hosting !== "postgres" && !isLocalHosting(hosting)) throw queueErrorDiagnostics.QUEUE_MISSING_DRIVER({ hosting });
79
+ const resolved = driver || inferDriver(hosting, postgresDatabase);
80
+ if (resolved === "postgres") return defu(postgresDatabase ? { database: "default" } : {}, shared, { driver: "postgres" });
81
+ if (resolved === "local") {
82
+ const base = readOwnOption(options, "base");
83
+ return defu(typeof base === "string" && base.trim() ? { base: base.trim() } : {}, shared, {
84
+ base: defaultLocalQueueBase,
85
+ driver: "local"
86
+ });
87
+ }
88
+ if (resolved === "cloudflare") {
89
+ const binding = readOwnOption(options, "binding");
90
+ const namePrefix = readOwnOption(options, "namePrefix");
91
+ return defu({
92
+ ...typeof binding === "string" ? { binding } : {},
93
+ ...typeof namePrefix === "string" ? { namePrefix } : {}
94
+ }, shared, { driver: "cloudflare" });
95
+ }
96
+ const region = readOwnOption(options, "region");
97
+ return defu(typeof region === "string" ? { region } : {}, shared, { driver: "vercel" });
98
+ }
99
+ function normalizeQueueOptions(options, input = {}) {
100
+ if (options === false) return void 0;
101
+ if (typeof options !== "undefined" && !isRecord(options)) throw queueErrorDiagnostics.QUEUE_INVALID_CONFIG();
102
+ return resolveDriver(options || {}, normalizeHosting(input.hosting), input.postgresDatabase === true);
103
+ }
104
+ //#endregion
105
+ export { resolveHost as a, getHostingProvider as i, normalizeQueueOptions as n, resolveHostPreset as o, postgresQueueUrlVariable as r, defaultLocalQueueBase as t };
@@ -0,0 +1,13 @@
1
+ import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
2
+ //#region src/durability.d.ts
3
+ /** What the build passes to `queueDurability()`. */
4
+ export interface QueueDurabilityInput {
5
+ /** The folder of the `local` driver. */
6
+ base?: string;
7
+ /** The Database of the `postgres` driver. */
8
+ database?: string;
9
+ driver: string;
10
+ }
11
+ /** The durability of Queue jobs, from the driver. */
12
+ export declare function queueDurability(input: QueueDurabilityInput, context: DurabilityContext): Durability[];
13
+ //#endregion
@@ -0,0 +1,47 @@
1
+ //#region src/durability.ts
2
+ const hostedDrivers = {
3
+ cloudflare: "Cloudflare Queues deliver each job once.",
4
+ vercel: "Vercel Queues deliver each job once."
5
+ };
6
+ /** The durability of Queue jobs, from the driver. */
7
+ function queueDurability(input, context) {
8
+ const hosted = hostedDrivers[input.driver];
9
+ if (hosted) return [{
10
+ primitive: "queue",
11
+ store: input.driver,
12
+ scope: "shared",
13
+ reason: hosted
14
+ }];
15
+ if (input.driver === "postgres") {
16
+ if (context.env.QUEUE_POSTGRES_URL?.trim()) return [{
17
+ primitive: "queue",
18
+ store: "postgres",
19
+ scope: "shared",
20
+ reason: "Jobs in Postgres at QUEUE_POSTGRES_URL."
21
+ }];
22
+ const name = input.database ?? "default";
23
+ const database = context.find("database", name);
24
+ return [database ? {
25
+ primitive: "queue",
26
+ store: "postgres",
27
+ scope: database.scope,
28
+ reason: `Jobs in the ${name} Database. ${database.reason}`,
29
+ ...database.fix ? { fix: database.fix } : {}
30
+ } : {
31
+ primitive: "queue",
32
+ store: "postgres",
33
+ scope: "process",
34
+ reason: `The ${name} Database is off, so the Queue has no connection.`,
35
+ fix: "Set QUEUE_POSTGRES_URL, or turn on a Postgres Default Database."
36
+ }];
37
+ }
38
+ return [{
39
+ primitive: "queue",
40
+ store: input.driver,
41
+ scope: "host",
42
+ reason: `Job files in ${input.base ?? ".vitehub/data/queue"}. One server process must own this folder.`,
43
+ fix: "Use the `postgres` driver with a Postgres Default Database."
44
+ }];
45
+ }
46
+ //#endregion
47
+ export { queueDurability };
@@ -0,0 +1,111 @@
1
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
2
+ import { parseDuration, runtimeErrorDiagnostics, toResultError } from "@vite-hub/runtime";
3
+ //#region src/enqueue.ts
4
+ let fallbackCounter = 0;
5
+ function createQueueMessageId(prefix = "queue") {
6
+ const uuid = globalThis.crypto?.randomUUID?.();
7
+ if (uuid) return `${prefix}_${uuid}`;
8
+ fallbackCounter = fallbackCounter + 1 >>> 0;
9
+ return `${prefix}_${Date.now().toString(36)}_${fallbackCounter.toString(36)}`;
10
+ }
11
+ /** Payload properties never select enqueue options. The message ID is always generated. */
12
+ function normalizeQueueEnqueueInput(payload, options = {}) {
13
+ return {
14
+ id: createQueueMessageId(),
15
+ options: { ...options },
16
+ payload
17
+ };
18
+ }
19
+ //#endregion
20
+ //#region src/errors.ts
21
+ const cloudflareUnsupportedEnqueueOptions = [
22
+ "idempotencyKey",
23
+ "region",
24
+ "retention"
25
+ ];
26
+ const localUnsupportedEnqueueOptions = [
27
+ "contentType",
28
+ "region",
29
+ "retention"
30
+ ];
31
+ const postgresUnsupportedEnqueueOptions = localUnsupportedEnqueueOptions;
32
+ const unsupportedEnqueueOptions = {
33
+ cloudflare: cloudflareUnsupportedEnqueueOptions,
34
+ local: localUnsupportedEnqueueOptions,
35
+ postgres: postgresUnsupportedEnqueueOptions,
36
+ vercel: ["contentType"]
37
+ };
38
+ const removedEnqueueOptions = [
39
+ "delaySeconds",
40
+ "id",
41
+ "retentionSeconds"
42
+ ];
43
+ function queueRemovedOptionsError(provider, options, items = []) {
44
+ const removed = removedEnqueueOptions.filter((name) => options && Object.hasOwn(options, name) || items.some((item) => Object.hasOwn(item, name)));
45
+ if (removed.length) return queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
46
+ options: formatQueueOptionNames(removed),
47
+ provider
48
+ });
49
+ }
50
+ /** Shared pre-dispatch option validation for provider clients and the test backend. */
51
+ function queueUnsupportedOptionsError(options, provider, names = unsupportedEnqueueOptions[provider]) {
52
+ const unsupported = [...removedEnqueueOptions.filter((option) => Object.hasOwn(options, option)), ...names.filter((option) => options[option] !== void 0)];
53
+ return unsupported.length ? queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
54
+ options: formatQueueOptionNames(unsupported),
55
+ provider
56
+ }) : void 0;
57
+ }
58
+ /** Returns `true` for an error from the Queue catalog. Pass `codes` to accept only some codes. */
59
+ function isQueueError(error, codes) {
60
+ return queueErrorDiagnostics.is(error) && (!codes || codes.some((code) => code === error.code));
61
+ }
62
+ /** Formats option names for an error `why`, for example `"region" and "retention"`. */
63
+ function formatQueueOptionNames(names) {
64
+ const quoted = names.map((name) => `\`${name}\``);
65
+ return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}` : quoted.join("");
66
+ }
67
+ function normalizePublicQueueIdentifier(value) {
68
+ if (typeof value !== "string" || !value || value.length > 128 || value.trim() !== value) return;
69
+ if (!/^[a-z\d][a-z\d._/-]*$/i.test(value)) return;
70
+ if (/^[a-z][a-z\d+.-]*:\/\//i.test(value) || /^[a-z]:\//i.test(value)) return;
71
+ if (value.split("/").some((part) => part === "." || part === "..")) return;
72
+ return value;
73
+ }
74
+ /**
75
+ * Runs one provider call and returns `[error, data]`.
76
+ * Any failure becomes `QUEUE_PROVIDER_FAILED` with the failure in `cause`.
77
+ */
78
+ async function queueProviderResult(provider, operation, run) {
79
+ try {
80
+ return [void 0, await run()];
81
+ } catch (cause) {
82
+ return [queueErrorDiagnostics.QUEUE_PROVIDER_FAILED({
83
+ cause,
84
+ operation,
85
+ provider
86
+ }), void 0];
87
+ }
88
+ }
89
+ //#endregion
90
+ //#region src/duration.ts
91
+ /**
92
+ * Reads `delay` and `retention` of a send. `delay` is a duration such as `"1m"`. `retention` is a duration or a number
93
+ * of seconds. A value that is not a duration returns `RUNTIME_DURATION_INVALID`. Pass `"ceil"` for a provider that
94
+ * takes whole seconds, so a job never runs earlier than the caller asked.
95
+ */
96
+ function readQueueTimes(options, round) {
97
+ const seconds = (milliseconds) => round === "ceil" ? Math.ceil(milliseconds / 1e3) : milliseconds / 1e3;
98
+ try {
99
+ const delaySeconds = options.delay === void 0 ? void 0 : seconds(parseDuration(options.delay, "delay", void 0, "s"));
100
+ const retentionSeconds = typeof options.retention === "number" ? round === "ceil" ? Math.ceil(options.retention) : options.retention : options.retention === void 0 ? void 0 : seconds(parseDuration(options.retention, "retention"));
101
+ return [void 0, {
102
+ ...delaySeconds === void 0 ? {} : { delaySeconds },
103
+ ...retentionSeconds === void 0 ? {} : { retentionSeconds }
104
+ }];
105
+ } catch (error) {
106
+ if (runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID.is(error)) return [toResultError(error), void 0];
107
+ throw error;
108
+ }
109
+ }
110
+ //#endregion
111
+ export { normalizePublicQueueIdentifier as a, queueRemovedOptionsError as c, normalizeQueueEnqueueInput as d, localUnsupportedEnqueueOptions as i, queueUnsupportedOptionsError as l, cloudflareUnsupportedEnqueueOptions as n, postgresUnsupportedEnqueueOptions as o, isQueueError as r, queueProviderResult as s, readQueueTimes as t, createQueueMessageId as u };
@@ -0,0 +1,270 @@
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/development/diagnostics",
6
+ codes: {
7
+ INTERNAL_R0012: {
8
+ ...dynamicError,
9
+ fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
10
+ },
11
+ INTERNAL_R0013: {
12
+ ...dynamicError,
13
+ fix: "Check that the provider token can manage the resource in the path that the message names. `error.kind` and `error.codes` hold the provider failure."
14
+ },
15
+ INTERNAL_R0014: {
16
+ why: ({ path }) => `Cannot read Provision State from "${path}".`,
17
+ fix: "Check file access and restore valid JSON while preserving existing resource IDs."
18
+ },
19
+ INTERNAL_R0020: {
20
+ fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
21
+ why: ({ message }) => message === void 0 ? "" : String(message)
22
+ },
23
+ INTERNAL_R0021: {
24
+ fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
25
+ why: ({ message }) => message === void 0 ? "" : String(message)
26
+ },
27
+ INTERNAL_R0022: {
28
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
29
+ why: ({ message }) => message === void 0 ? "" : String(message)
30
+ },
31
+ INTERNAL_R0024: {
32
+ fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
33
+ why: ({ message }) => message === void 0 ? "" : String(message)
34
+ },
35
+ INTERNAL_R0023: {
36
+ fix: "Ask for access to the section of this operation.",
37
+ why: ({ message }) => message === void 0 ? "" : String(message)
38
+ },
39
+ INTERNAL_B0001: {
40
+ ...dynamicError,
41
+ fix: "Give the resource that the message names another name or binding in the `vitehub()` options of its feature, so that two different Cloudflare resources do not share one name."
42
+ },
43
+ INTERNAL_B0015: {
44
+ ...dynamicError,
45
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
46
+ },
47
+ INTERNAL_B0016: {
48
+ ...dynamicError,
49
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
50
+ },
51
+ INTERNAL_B0017: {
52
+ ...dynamicError,
53
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
54
+ },
55
+ INTERNAL_B0018: {
56
+ ...dynamicError,
57
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
58
+ },
59
+ INTERNAL_B0019: {
60
+ ...dynamicError,
61
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
62
+ },
63
+ INTERNAL_B0020: {
64
+ ...dynamicError,
65
+ fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
66
+ },
67
+ INTERNAL_B0021: {
68
+ ...dynamicError,
69
+ fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
70
+ },
71
+ INTERNAL_B0022: {
72
+ ...dynamicError,
73
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
74
+ },
75
+ INTERNAL_B0025: {
76
+ ...dynamicError,
77
+ fix: "Replace the `new URL(\"./...\", import.meta.url)` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` of that file."
78
+ },
79
+ INTERNAL_B0026: {
80
+ ...dynamicError,
81
+ fix: "Replace the computed `import()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` or with `import(\"<literal path>\")`."
82
+ },
83
+ INTERNAL_B0027: {
84
+ ...dynamicError,
85
+ fix: "Replace the computed `require()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import`."
86
+ },
87
+ INTERNAL_B0028: {
88
+ ...dynamicError,
89
+ fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
90
+ },
91
+ INTERNAL_B0029: {
92
+ ...dynamicError,
93
+ fix: "Stop the other builds that write the same Deno output folder, delete the `.vitehub-lock` folder next to that output folder, such as `.output.vitehub-lock`, then build again."
94
+ },
95
+ INTERNAL_B0031: {
96
+ ...dynamicError,
97
+ fix: "Import `./schedule/deno-cron.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./schedule/deno-cron.mjs\", import.meta.url).href)` outside any condition."
98
+ },
99
+ INTERNAL_B0032: {
100
+ ...dynamicError,
101
+ fix: "Import `./server/index.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./server/index.mjs\", import.meta.url).href)` outside any condition."
102
+ },
103
+ INTERNAL_B0035: {
104
+ ...dynamicError,
105
+ fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
106
+ },
107
+ INTERNAL_B0039: {
108
+ ...dynamicError,
109
+ fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
110
+ },
111
+ INTERNAL_B0040: {
112
+ ...dynamicError,
113
+ fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
114
+ },
115
+ INTERNAL_B0043: {
116
+ ...dynamicError,
117
+ fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
118
+ },
119
+ INTERNAL_B0046: {
120
+ ...dynamicError,
121
+ fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
122
+ },
123
+ INTERNAL_B0047: {
124
+ ...dynamicError,
125
+ fix: "Correct the `package.json` file that the message names so that it holds one JSON object, or run `pnpm install` again to restore an installed package."
126
+ },
127
+ INTERNAL_B0048: {
128
+ fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
129
+ why: ({ message }) => message === void 0 ? "" : String(message)
130
+ },
131
+ INTERNAL_B0049: {
132
+ fix: "Set `cli: { namespace, command }` on one of the two operations.",
133
+ why: ({ message }) => message === void 0 ? "" : String(message)
134
+ },
135
+ INTERNAL_B0050: {
136
+ fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
137
+ why: ({ message }) => message === void 0 ? "" : String(message)
138
+ },
139
+ INTERNAL_B0051: {
140
+ why: ({ field, generated, name, path, project, scope }) => `The Cloudflare ${path} entry "${name}"${scope} is written by ViteHub and by the project's Wrangler config with a different ${field}: ${generated} and ${project}.`,
141
+ fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
142
+ },
143
+ INTERNAL_B0052: {
144
+ why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
145
+ fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
146
+ },
147
+ INTERNAL_R0025: {
148
+ fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
149
+ why: ({ message }) => message === void 0 ? "" : String(message)
150
+ },
151
+ INTERNAL_R0026: {
152
+ why: "The server parsed a destructive operation that the CLI did not confirm.",
153
+ fix: "Review the operation, then run it again with --yes to confirm the change."
154
+ },
155
+ INTERNAL_C0001: {
156
+ ...dynamicError,
157
+ fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
158
+ },
159
+ INTERNAL_C0002: {
160
+ ...dynamicError,
161
+ fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
162
+ },
163
+ INTERNAL_R0001: {
164
+ ...dynamicError,
165
+ fix: "Set `host` in `vitehub()`, or in the `vitehub` options of `nuxt.config.ts`, to `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. Or remove `host` so that ViteHub finds the host from the environment."
166
+ },
167
+ INTERNAL_R0002: {
168
+ ...dynamicError,
169
+ fix: "Stop using the feature that the message names, or set `host` in `vitehub()` to a host that provides it. For Blob, you can also set `blob: { driver: \"s3\" }` with a remote store."
170
+ },
171
+ INTERNAL_R0004: {
172
+ ...dynamicError,
173
+ fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
174
+ },
175
+ INTERNAL_R0005: {
176
+ ...dynamicError,
177
+ fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
178
+ },
179
+ INTERNAL_R0006: {
180
+ ...dynamicError,
181
+ fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
182
+ },
183
+ INTERNAL_R0007: {
184
+ ...dynamicError,
185
+ fix: "Set `maxResponseBytes` of the HTTP request to a positive integer no greater than the limit that the message names, or remove it to use the default."
186
+ },
187
+ INTERNAL_R0008: {
188
+ ...dynamicError,
189
+ fix: "Make the value that the message names match its schema: the input, query, or body that you send, or the response schema that you declare for the request."
190
+ },
191
+ INTERNAL_R0009: {
192
+ ...dynamicError,
193
+ fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
194
+ },
195
+ INTERNAL_R0010: {
196
+ ...dynamicError,
197
+ fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
198
+ },
199
+ INTERNAL_R0011: {
200
+ ...dynamicError,
201
+ fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
202
+ },
203
+ INTERNAL_CONSOLE_KEY_NAME_INVALID: {
204
+ why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
205
+ fix: "Name the Console key with 1 to 64 characters from A-Z, 0-9, and _, such as `CI`. The app reads its public key from `VITEHUB_CONSOLE_KEY_<NAME>`."
206
+ },
207
+ INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
208
+ why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
209
+ fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
210
+ },
211
+ INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
212
+ why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
213
+ fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
214
+ },
215
+ INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
216
+ why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
217
+ fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
218
+ },
219
+ INTERNAL_DEV_SERVER_NOT_FOUND: {
220
+ why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
221
+ fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
222
+ },
223
+ INTERNAL_FORGE_NOT_INSTALLED: {
224
+ why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
225
+ fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
226
+ },
227
+ INTERNAL_MCP_ARGUMENTS_INVALID: {
228
+ why: ({ detail }) => detail,
229
+ fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
230
+ },
231
+ INTERNAL_MCP_METHOD_FAILED: {
232
+ why: ({ name }) => `${name} failed on the server.`,
233
+ fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
234
+ },
235
+ INTERNAL_MCP_RESOURCE_NOT_FOUND: {
236
+ why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
237
+ fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
238
+ },
239
+ INTERNAL_PRESET_OPTION_UNKNOWN: {
240
+ why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
241
+ fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
242
+ },
243
+ INTERNAL_PRESET_TUPLE_INVALID: {
244
+ why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
245
+ fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
246
+ },
247
+ INTERNAL_SECRET_PURPOSE_MISSING: {
248
+ why: "[vitehub] A derived secret requires a purpose.",
249
+ fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
250
+ },
251
+ INTERNAL_SECRET_TOO_SHORT: {
252
+ why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
253
+ fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
254
+ },
255
+ INTERNAL_SQLITE_ARGUMENT_INVALID: {
256
+ why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
257
+ fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
258
+ },
259
+ INTERNAL_SQLITE_INTEGER_UNSAFE: {
260
+ why: "Received integer which cannot be safely represented as a JavaScript number",
261
+ fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
262
+ },
263
+ INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
264
+ why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
265
+ fix: "Ask for the `draft-07`, `draft-2020-12`, or `openapi-3.0` JSON Schema target, or pass one of them as `withValibotJsonSchema(schema, { target })`."
266
+ }
267
+ }
268
+ });
269
+ //#endregion
270
+ export { internalErrorDiagnostics as t };