@vite-hub/schedule 0.0.4 → 0.3.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 (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -1,7 +1,9 @@
1
- import { S as ScheduleTargetDefinitionInput, c as ScheduleDefinition, l as ScheduleDefinitionInput, x as ScheduleTargetDefinition } from "./types-Bcje4dLV.js";
2
-
1
+ import { n as ScheduleDefinition, r as ScheduleDefinitionInput } from "./types-Cw5LjPuc.js";
3
2
  //#region src/definition.d.ts
4
- declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult>): ScheduleDefinition<TResult>;
5
- declare function defineScheduleTarget<TInput = unknown, TResult = unknown>(input: ScheduleTargetDefinitionInput<TInput, TResult>): ScheduleTargetDefinition<TInput, TResult>;
6
- //#endregion
7
- export { defineSchedule, defineScheduleTarget };
3
+ export declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult> & {
4
+ cron: string;
5
+ }): ScheduleDefinition<TResult> & {
6
+ cron: string;
7
+ };
8
+ export declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult>): ScheduleDefinition<TResult>;
9
+ //#endregion
@@ -1,42 +1,48 @@
1
+ import { t as isIanaTimeZone } from "./time-zone-SBldrUgt.js";
2
+ import { t as isRecord } from "./object-Da1zyPCR.js";
3
+ import { t as scheduleErrorDiagnostics } from "./error-diagnostics-Mpeks7J0.js";
1
4
  //#region src/definition.ts
2
5
  const cronFieldPattern = /^[^\s]+$/;
3
- const scheduleDefinitionKeys = new Set([
4
- "allowRuntimeSchedules",
6
+ const scheduleDefinitionKeys = /* @__PURE__ */ new Set([
7
+ "manual",
5
8
  "cron",
6
- "handler"
9
+ "handler",
10
+ "timeZone"
7
11
  ]);
8
- const scheduleTargetDefinitionKeys = new Set(["handler"]);
9
- function isPlainObject(value) {
10
- return !!value && typeof value === "object" && !Array.isArray(value);
12
+ function isCronString(value) {
13
+ return value !== null && value !== void 0 && String(value) === value;
14
+ }
15
+ function assertOwnDefinitionFields(input, keys, message, diagnostic) {
16
+ const inheritedKey = [...keys].find((key) => key in input && !Object.hasOwn(input, key));
17
+ if (inheritedKey) throw diagnostic({ message: `${message} The "${inheritedKey}" option must be an own property.` });
11
18
  }
12
19
  function validateCron(cron) {
13
- if (typeof cron !== "string" || cron.trim() !== cron || cron.length === 0) throw new TypeError("`defineSchedule()` requires a cron string.");
20
+ if (typeof cron !== "string" || cron.trim() !== cron || cron.length === 0) throw scheduleErrorDiagnostics.SCHEDULE_C0001({ message: "`defineSchedule()` requires a cron string." });
14
21
  const fields = cron.split(/\s+/);
15
- if (fields.length !== 5 || !fields.every((field) => cronFieldPattern.test(field))) throw new TypeError("`defineSchedule()` cron must be a five-field UTC cron expression.");
22
+ if (fields.length !== 5 || !fields.every((field) => cronFieldPattern.test(field))) throw scheduleErrorDiagnostics.SCHEDULE_C0002({ message: "`defineSchedule()` cron must be a five-field cron expression." });
16
23
  }
17
- function defineSchedule(input) {
18
- if (!isPlainObject(input)) throw new TypeError("`defineSchedule()` expects an object with `cron` and `handler`.");
24
+ /** The `defineSchedule(cron, handler, options)` form was removed. Name the object form in the error. */
25
+ const positionalFormMessage = "`defineSchedule(cron, handler)` was removed. Pass one object: `defineSchedule({ cron: \"0 9 * * *\", handler })`, with `manual` and `timeZone` in the same object.";
26
+ function defineSchedule(input, ...removed) {
27
+ if (isCronString(input) || removed.length) throw scheduleErrorDiagnostics.SCHEDULE_C0007({ message: positionalFormMessage });
28
+ if (!isRecord(input)) throw scheduleErrorDiagnostics.SCHEDULE_C0003({ message: "`defineSchedule()` expects an object with `cron` and `handler`." });
29
+ if (!Object.hasOwn(input, "handler")) throw scheduleErrorDiagnostics.SCHEDULE_C0003({ message: "`defineSchedule()` expects an object with `handler`, and `cron` unless code starts the Schedule with `startSchedule()`." });
30
+ assertOwnDefinitionFields(input, scheduleDefinitionKeys, "`defineSchedule()` does not accept inherited options.", scheduleErrorDiagnostics.SCHEDULE_C0004);
19
31
  const unknownKey = Object.keys(input).find((key) => !scheduleDefinitionKeys.has(key));
20
- if (unknownKey) throw new TypeError(`\`defineSchedule()\` does not support the "${unknownKey}" option.`);
21
- validateCron(input.cron);
22
- if (typeof input.handler !== "function") throw new TypeError("`defineSchedule()` requires a schedule handler.");
23
- if (typeof input.allowRuntimeSchedules !== "undefined" && typeof input.allowRuntimeSchedules !== "boolean") throw new TypeError("`defineSchedule()` allowRuntimeSchedules must be a boolean.");
24
- const definition = {
32
+ if (unknownKey) throw scheduleErrorDiagnostics.SCHEDULE_C0004({ message: `\`defineSchedule()\` does not support the "${unknownKey}" option.` });
33
+ const hasCron = Object.hasOwn(input, "cron");
34
+ if (hasCron) validateCron(input.cron);
35
+ else if (input.timeZone !== void 0) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` timeZone needs a cron. A Schedule without cron takes its time zone from `startSchedule()`." });
36
+ if (typeof input.handler !== "function") throw scheduleErrorDiagnostics.SCHEDULE_C0005({ message: "`defineSchedule()` requires a schedule handler." });
37
+ if (input.manual !== void 0 && input.manual !== true && input.manual !== false) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` manual must be a boolean." });
38
+ if (input.timeZone !== void 0 && !isIanaTimeZone(input.timeZone)) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` timeZone must be an IANA time zone, such as \"Europe/Madrid\"." });
39
+ const definition = hasCron ? {
25
40
  cron: input.cron,
26
41
  handler: input.handler
27
- };
28
- if (typeof input.allowRuntimeSchedules !== "undefined") definition.options = { allowRuntimeSchedules: input.allowRuntimeSchedules };
42
+ } : { handler: input.handler };
43
+ if (input.timeZone !== void 0) definition.timeZone = input.timeZone;
44
+ if (input.manual !== void 0) definition.options = { manual: input.manual };
29
45
  return definition;
30
46
  }
31
- function defineScheduleTarget(input) {
32
- if (!isPlainObject(input)) throw new TypeError("`defineScheduleTarget()` expects an object with `handler`.");
33
- const unknownKey = Object.keys(input).find((key) => !scheduleTargetDefinitionKeys.has(key));
34
- if (unknownKey) throw new TypeError(`\`defineScheduleTarget()\` does not support the "${unknownKey}" option.`);
35
- if (typeof input.handler !== "function") throw new TypeError("`defineScheduleTarget()` requires a schedule handler.");
36
- return {
37
- handler: input.handler,
38
- options: { allowRuntimeSchedules: true }
39
- };
40
- }
41
47
  //#endregion
42
- export { defineSchedule, defineScheduleTarget };
48
+ export { defineSchedule };
@@ -0,0 +1,144 @@
1
+ import { t as scheduleErrorDiagnostics } from "./error-diagnostics-Mpeks7J0.js";
2
+ import { parseCronExpression } from "cron-schedule";
3
+ //#region src/runtime/due.ts
4
+ const weekdayIndexes = /* @__PURE__ */ new Map([
5
+ ["Sun", 0],
6
+ ["Mon", 1],
7
+ ["Tue", 2],
8
+ ["Wed", 3],
9
+ ["Thu", 4],
10
+ ["Fri", 5],
11
+ ["Sat", 6]
12
+ ]);
13
+ const minuteMs = 6e4;
14
+ const hourMinutes = 60;
15
+ const dayMinutes = 1440;
16
+ const timeZoneFormatters = /* @__PURE__ */ new Map();
17
+ const parsedScheduleCrons = /* @__PURE__ */ new WeakMap();
18
+ function timeZoneFormatter(timeZone) {
19
+ let formatter = timeZoneFormatters.get(timeZone);
20
+ if (!formatter) {
21
+ formatter = new Intl.DateTimeFormat("en-US", {
22
+ day: "numeric",
23
+ hour: "numeric",
24
+ hourCycle: "h23",
25
+ minute: "numeric",
26
+ month: "numeric",
27
+ timeZone,
28
+ weekday: "short",
29
+ year: "numeric"
30
+ });
31
+ timeZoneFormatters.set(timeZone, formatter);
32
+ }
33
+ return formatter;
34
+ }
35
+ function scheduleDateFields(scheduledAt, timeZone) {
36
+ if (!timeZone || timeZone === "UTC") return {
37
+ day: scheduledAt.getUTCDate(),
38
+ hour: scheduledAt.getUTCHours(),
39
+ minute: scheduledAt.getUTCMinutes(),
40
+ month: scheduledAt.getUTCMonth(),
41
+ weekday: scheduledAt.getUTCDay(),
42
+ year: scheduledAt.getUTCFullYear()
43
+ };
44
+ const values = new Map(timeZoneFormatter(timeZone).formatToParts(scheduledAt).map((part) => [part.type, part.value]));
45
+ const weekday = weekdayIndexes.get(values.get("weekday") || "");
46
+ const day = Number(values.get("day"));
47
+ const hour = Number(values.get("hour"));
48
+ const minute = Number(values.get("minute"));
49
+ const month = Number(values.get("month")) - 1;
50
+ const year = Number(values.get("year"));
51
+ if (weekday === void 0 || [
52
+ day,
53
+ hour,
54
+ minute,
55
+ month,
56
+ year
57
+ ].some((value) => !Number.isInteger(value))) throw scheduleErrorDiagnostics.SCHEDULE_R0022({ message: `Schedule time zone could not resolve calendar fields: ${timeZone}` });
58
+ return {
59
+ day,
60
+ hour,
61
+ minute,
62
+ month,
63
+ weekday,
64
+ year
65
+ };
66
+ }
67
+ function parseScheduleCron(schedule) {
68
+ const expression = schedule.cron;
69
+ const cached = parsedScheduleCrons.get(schedule);
70
+ if (cached?.expression === expression) return cached.cron;
71
+ if (expression.trim().split(/\s+/).length !== 5) throw scheduleErrorDiagnostics.SCHEDULE_R0023({ message: `Schedule "${schedule.id}" must use a five-field cron expression.` });
72
+ const cron = parseCronExpression(expression);
73
+ parsedScheduleCrons.set(schedule, {
74
+ expression,
75
+ cron
76
+ });
77
+ return cron;
78
+ }
79
+ function matchesCronHour(cron, fields) {
80
+ if (!cron.hours.includes(fields.hour) || !cron.months.includes(fields.month)) return false;
81
+ if (cron.days.length !== 31 && cron.weekdays.length !== 7) return cron.days.includes(fields.day) || cron.weekdays.includes(fields.weekday);
82
+ return cron.days.includes(fields.day) && cron.weekdays.includes(fields.weekday);
83
+ }
84
+ function localEpochMs(fields) {
85
+ const date = /* @__PURE__ */ new Date(0);
86
+ date.setUTCFullYear(fields.year, fields.month, fields.day);
87
+ date.setUTCHours(fields.hour, fields.minute, 0, 0);
88
+ return date.getTime();
89
+ }
90
+ function sameLocalMinute(left, right) {
91
+ return left.minute === right.minute && left.hour === right.hour && left.day === right.day && left.month === right.month && left.year === right.year;
92
+ }
93
+ /** Detect a repeated local minute using the actual offset before the transition (including historical 23-hour rollbacks). */
94
+ function isRepeatedFixedLocalTime(cron, fields, scheduledAt, timeZone) {
95
+ if (!timeZone || timeZone === "UTC" || cron.minutes.length === hourMinutes || cron.hours.length === 24) return false;
96
+ const previous = /* @__PURE__ */ new Date(scheduledAt.getTime() - dayMinutes * minuteMs);
97
+ const currentOffset = localEpochMs(fields) - scheduledAt.getTime();
98
+ const previousOffset = localEpochMs(scheduleDateFields(previous, timeZone)) - previous.getTime();
99
+ if (previousOffset <= currentOffset) return false;
100
+ return sameLocalMinute(scheduleDateFields(new Date(scheduledAt.getTime() - (previousOffset - currentOffset)), timeZone), fields);
101
+ }
102
+ /**
103
+ * Detect a local time that the clock skipped on a spring-forward day, read with the offset from before the gap, as
104
+ * RFC 5545 and `Temporal` do. `02:30` in a gap from `02:00` to `03:00` maps to `03:30`, so it runs once that day.
105
+ */
106
+ function matchesSkippedLocalTime(cron, fields, scheduledAt, timeZone) {
107
+ if (!timeZone || timeZone === "UTC") return false;
108
+ const currentOffset = localEpochMs(fields) - scheduledAt.getTime();
109
+ const previous = /* @__PURE__ */ new Date(scheduledAt.getTime() - dayMinutes * minuteMs);
110
+ const previousOffset = localEpochMs(scheduleDateFields(previous, timeZone)) - previous.getTime();
111
+ if (previousOffset >= currentOffset) return false;
112
+ const beforeGap = new Date(scheduledAt.getTime() - (currentOffset - previousOffset));
113
+ if (localEpochMs(scheduleDateFields(beforeGap, timeZone)) - beforeGap.getTime() !== previousOffset) return false;
114
+ const skipped = scheduleDateFields(new Date(scheduledAt.getTime() + previousOffset), void 0);
115
+ return cron.minutes.includes(skipped.minute) && matchesCronHour(cron, skipped);
116
+ }
117
+ /** Returns `true` when `schedule` is due at the exact minute `scheduledAt`. */
118
+ function isScheduleDue(schedule, scheduledAt) {
119
+ if (scheduledAt.getUTCSeconds() !== 0 || scheduledAt.getUTCMilliseconds() !== 0) return false;
120
+ const cron = parseScheduleCron(schedule);
121
+ const fields = scheduleDateFields(scheduledAt, schedule.timeZone);
122
+ if (cron.minutes.includes(fields.minute) && matchesCronHour(cron, fields)) return !isRepeatedFixedLocalTime(cron, fields, scheduledAt, schedule.timeZone);
123
+ return matchesSkippedLocalTime(cron, fields, scheduledAt, schedule.timeZone);
124
+ }
125
+ /** Minutes east of UTC that `timeZone` uses at `at`, such as `120` for Madrid in summer. */
126
+ function timeZoneOffsetMinutes(at, timeZone) {
127
+ const minute = /* @__PURE__ */ new Date(Math.floor(at.getTime() / minuteMs) * minuteMs);
128
+ return Math.round((localEpochMs(scheduleDateFields(minute, timeZone)) - minute.getTime()) / minuteMs);
129
+ }
130
+ /**
131
+ * Returns the newest minute at or before `at` that the UTC `cron` matches, within one day, or the current minute.
132
+ * This is an estimate for hosts without a scheduled timestamp, not an identity for delayed or retried deliveries.
133
+ */
134
+ function latestCronMinute(cron, at) {
135
+ const record = {
136
+ cron,
137
+ id: cron
138
+ };
139
+ const latest = Math.floor(at.getTime() / minuteMs) * minuteMs;
140
+ for (let time = latest; time > latest - dayMinutes * minuteMs; time -= minuteMs) if (isScheduleDue(record, new Date(time))) return new Date(time);
141
+ return new Date(latest);
142
+ }
143
+ //#endregion
144
+ export { latestCronMinute as n, timeZoneOffsetMinutes as r, isScheduleDue as t };
@@ -0,0 +1,14 @@
1
+ import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
2
+ //#region src/durability.d.ts
3
+ /** What the build passes to `scheduleDurability()`. */
4
+ export interface ScheduleDurabilityInput {
5
+ driver: "process";
6
+ /** The process runtime claims occurrences with SQL leases in the Default Database. */
7
+ leases?: boolean;
8
+ }
9
+ /**
10
+ * The durability of schedule claims. With SQL leases in a Postgres Default Database, one instance runs each
11
+ * occurrence. Without them, each process claims each occurrence for itself.
12
+ */
13
+ export declare function scheduleDurability(input: ScheduleDurabilityInput, context: DurabilityContext): Durability[];
14
+ //#endregion
@@ -0,0 +1,23 @@
1
+ //#region src/durability.ts
2
+ /**
3
+ * The durability of schedule claims. With SQL leases in a Postgres Default Database, one instance runs each
4
+ * occurrence. Without them, each process claims each occurrence for itself.
5
+ */
6
+ function scheduleDurability(input, context) {
7
+ const database = input.leases ? context.find("database") : void 0;
8
+ if (database?.store === "postgres") return [{
9
+ primitive: "schedule",
10
+ store: "postgres",
11
+ scope: "shared",
12
+ reason: "Leases in the Default Database. One instance runs each occurrence."
13
+ }];
14
+ return [{
15
+ primitive: "schedule",
16
+ store: input.driver,
17
+ scope: "process",
18
+ reason: database ? `Leases in the ${database.store} Default Database do not lock across processes. Every instance can run every occurrence.` : "This process claims each occurrence. Every instance runs every occurrence.",
19
+ fix: input.leases ? "Define the Default Database with `dialect: \"postgresql\"`." : "Run the schedules on one instance only. Schedule has no shared lease store for Node yet."
20
+ }];
21
+ }
22
+ //#endregion
23
+ export { scheduleDurability };
@@ -0,0 +1,266 @@
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 `fetch()` 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_FORGE_NOT_INSTALLED: {
220
+ why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
221
+ fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
222
+ },
223
+ INTERNAL_MCP_ARGUMENTS_INVALID: {
224
+ why: ({ detail }) => detail,
225
+ fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
226
+ },
227
+ INTERNAL_MCP_METHOD_FAILED: {
228
+ why: ({ name }) => `${name} failed on the server.`,
229
+ fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
230
+ },
231
+ INTERNAL_MCP_RESOURCE_NOT_FOUND: {
232
+ why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
233
+ fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
234
+ },
235
+ INTERNAL_PRESET_OPTION_UNKNOWN: {
236
+ why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
237
+ fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
238
+ },
239
+ INTERNAL_PRESET_TUPLE_INVALID: {
240
+ why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
241
+ fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
242
+ },
243
+ INTERNAL_SECRET_PURPOSE_MISSING: {
244
+ why: "[vitehub] A derived secret requires a purpose.",
245
+ fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
246
+ },
247
+ INTERNAL_SECRET_TOO_SHORT: {
248
+ why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
249
+ fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
250
+ },
251
+ INTERNAL_SQLITE_ARGUMENT_INVALID: {
252
+ 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",
253
+ 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."
254
+ },
255
+ INTERNAL_SQLITE_INTEGER_UNSAFE: {
256
+ why: "Received integer which cannot be safely represented as a JavaScript number",
257
+ fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
258
+ },
259
+ INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
260
+ why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
261
+ 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 })`."
262
+ }
263
+ }
264
+ });
265
+ //#endregion
266
+ export { internalErrorDiagnostics as t };