@vite-hub/schedule 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 (56) hide show
  1. package/README.md +118 -100
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +6 -2
  4. package/dist/definition.js +47 -1
  5. package/dist/due-sOJvF_6Z.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-BBtYYl8j.js +170 -0
  9. package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
  10. package/dist/index.d.ts +73 -5
  11. package/dist/index.js +56 -2
  12. package/dist/invariant-DolT9EEx.js +22 -0
  13. package/dist/{kv-storage-DWinmLLy.js → kv-storage-2kZtP2CC.js} +4 -4
  14. package/dist/{kv-storage-Bv9ocZT-.d.ts → kv-storage-Bm9aYLfZ.d.ts} +7 -3
  15. package/dist/object-Da1zyPCR.js +11 -0
  16. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  17. package/dist/operations-DqwmJ8MN.js +207 -0
  18. package/dist/operations.d.ts +36 -4
  19. package/dist/operations.js +130 -730
  20. package/dist/os.d.ts +167 -0
  21. package/dist/os.js +1659 -0
  22. package/dist/runtime/console.d.ts +12 -0
  23. package/dist/runtime/console.js +85 -0
  24. package/dist/runtime/kv.d.ts +1 -1
  25. package/dist/runtime/kv.js +1 -1
  26. package/dist/runtime/process.d.ts +32 -5
  27. package/dist/runtime/process.js +401 -413
  28. package/dist/runtime/state.d.ts +2 -9
  29. package/dist/runtime/state.js +2 -2
  30. package/dist/runtime/static.d.ts +28 -2
  31. package/dist/runtime/static.js +2 -2
  32. package/dist/runtime.d.ts +34 -32
  33. package/dist/runtime.js +6 -5
  34. package/dist/started-B0pc3JY0.js +146 -0
  35. package/dist/started-Bk2Icknk.js +201 -0
  36. package/dist/{execute-BJrgNgQ0.js → started-errors-DEmYH-vp.js} +94 -38
  37. package/dist/{inspect-DTfAo5gS.js → started-name-ruCM1EtQ.js} +5 -1
  38. package/dist/state-CPd10SXq.d.ts +58 -0
  39. package/dist/{state-DSxmHPn3.js → state-D4SZH6zk.js} +50 -22
  40. package/dist/{static-6g82xguw.js → static-7JCga3Iu.js} +80 -44
  41. package/dist/store-DeMojnXM.d.ts +53 -0
  42. package/dist/time-zone-SBldrUgt.js +59 -0
  43. package/dist/{types-CHdV9FQU.d.ts → types-Cw5LjPuc.d.ts} +62 -8
  44. package/dist/vite.d.ts +255 -2
  45. package/dist/vite.js +6128 -2
  46. package/dist/{wait-until-BmIqRo4x.js → wait-until-Dy4Bn3ZN.js} +26 -1
  47. package/package.json +19 -24
  48. package/dist/definition-CMiOg1lg.js +0 -111
  49. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  50. package/dist/error-diagnostics-in7mif5s.js +0 -45
  51. package/dist/nuxt.d.ts +0 -17
  52. package/dist/nuxt.js +0 -27
  53. package/dist/operations-gk2qzhYV.js +0 -131
  54. package/dist/store-QAOd8bxm.d.ts +0 -11
  55. package/dist/vite-BAVyZ8hZ.d.ts +0 -474
  56. package/dist/vite-BJwZkMrn.js +0 -5193
@@ -0,0 +1,170 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const scheduleErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/schedule/diagnostics",
6
+ codes: {
7
+ SCHEDULE_DEFINITION_NOT_FOUND: {
8
+ why: "Schedule run is not available. Set manual: true on the Schedule Definition and enable Console invocation.",
9
+ fix: "Set `manual: true` in defineSchedule() and keep `console.invoke` on (it is on in development)."
10
+ },
11
+ SCHEDULE_HISTORY_INCOMPLETE: {
12
+ why: ({ maxRecords, recordCount }) => `Schedule run history is incomplete because ${recordCount} records have no usable metadata index (maximum fallback is ${maxRecords}). Rebuild the schedule run index before listing history.`,
13
+ fix: "Rebuild the Schedule run index of the store, as the message says, before you list the history."
14
+ },
15
+ SCHEDULE_OPERATION_FAILED: {
16
+ why: "Schedule operation failed.",
17
+ fix: "Read `error.cause` for the error of the Schedule store or handler. Check that the store is reachable, then retry."
18
+ },
19
+ SCHEDULE_RUN_NOT_FOUND: {
20
+ why: "Schedule Run was not found.",
21
+ fix: "List the runs of the Schedule with `vitehub schedule runs <name>` and pass one of their ids."
22
+ },
23
+ SCHEDULE_C0001: {
24
+ ...dynamicError,
25
+ fix: "Pass `cron` to `defineSchedule()` as a non-empty string without spaces around it, such as `defineSchedule({ cron: \"0 9 * * *\", handler })`. Remove `cron` for a Schedule that only `startSchedule()` starts."
26
+ },
27
+ SCHEDULE_C0002: {
28
+ ...dynamicError,
29
+ fix: "Write `cron` as five fields with one space between them (minute, hour, day of month, month, day of week), such as `\"0 9 * * 1-5\"`."
30
+ },
31
+ SCHEDULE_C0003: {
32
+ ...dynamicError,
33
+ fix: "Pass one object with a `handler` to `defineSchedule()`, such as `defineSchedule({ cron: \"0 9 * * *\", handler })`."
34
+ },
35
+ SCHEDULE_C0004: {
36
+ ...dynamicError,
37
+ fix: "Use only the `cron`, `handler`, `manual`, and `timeZone` options in `defineSchedule()`, written in the object itself. Remove the other options."
38
+ },
39
+ SCHEDULE_C0005: {
40
+ ...dynamicError,
41
+ fix: "Set `handler` in `defineSchedule()` to a function, such as `handler: async () => { ... }`."
42
+ },
43
+ SCHEDULE_C0006: {
44
+ ...dynamicError,
45
+ fix: "Set `manual` in `defineSchedule()` to `true` or `false`. Set `timeZone` only together with `cron`, and use an IANA time zone, such as `\"Europe/Madrid\"`."
46
+ },
47
+ SCHEDULE_C0007: {
48
+ ...dynamicError,
49
+ fix: "Write `defineSchedule({ cron, handler })`. Run `npx @vite-hub/codemods define-forms` to rewrite every Schedule."
50
+ },
51
+ SCHEDULE_R0003: {
52
+ ...dynamicError,
53
+ fix: "Write `cron` of `defineSchedule()` as a five-field cron string, such as `\"0 9 * * 1\"`, and `timeZone` as a string literal with an IANA name, such as `\"Europe/Madrid\"`."
54
+ },
55
+ SCHEDULE_R0004: {
56
+ ...dynamicError,
57
+ fix: "Write `cron` of `defineSchedule()` as a string literal, such as `cron: \"0 9 * * *\"`."
58
+ },
59
+ SCHEDULE_R0005: {
60
+ ...dynamicError,
61
+ fix: "Rename one of the two Schedule files that the message names, so that their Vercel function paths are different."
62
+ },
63
+ SCHEDULE_R0006: {
64
+ ...dynamicError,
65
+ fix: "Rename one of the two Schedule files that the message names, so that their Netlify function files are different."
66
+ },
67
+ SCHEDULE_R0022: {
68
+ ...dynamicError,
69
+ fix: "Set `timeZone` of the Schedule to an IANA time zone that the host supports, such as `\"Europe/Madrid\"`, or remove it to use UTC."
70
+ },
71
+ SCHEDULE_R0023: {
72
+ ...dynamicError,
73
+ fix: "Write `cron` of the Schedule as five fields: minute, hour, day of the month, month, and day of the week."
74
+ },
75
+ SCHEDULE_R0024: {
76
+ ...dynamicError,
77
+ fix: "Set Schedule `runtime.leaseTtlMs` and `runtime.intervalMs` to numbers greater than zero, with `intervalMs` at most 60000, and `runtime.catchUpMs` to 0 or more. Or omit them to use the defaults."
78
+ },
79
+ SCHEDULE_R0025: {
80
+ ...dynamicError,
81
+ fix: "Set Schedule `runtime.concurrency` to a whole number of 1 or more, or omit it to run one Schedule at a time."
82
+ },
83
+ SCHEDULE_R0026: {
84
+ ...dynamicError,
85
+ fix: "Do not call the Process Schedule Runtime after `close()`. Install a new runtime with `installProcessScheduleRuntime()` if the process must run Schedules again."
86
+ },
87
+ SCHEDULE_R0027: {
88
+ ...dynamicError,
89
+ fix: "Send the Cloudflare scheduled event with a cron string. With `wrangler dev --test-scheduled`, call `/__scheduled?cron=*+*+*+*+*`."
90
+ },
91
+ SCHEDULE_R0028: {
92
+ ...dynamicError,
93
+ fix: "Send the Cloudflare scheduled event with `scheduledTime` as a Unix time in milliseconds, or without `scheduledTime` to use the current time."
94
+ },
95
+ SCHEDULE_R0030: {
96
+ ...dynamicError,
97
+ fix: "Pass a new `id` to `createAttempt()` of the Schedule Run store."
98
+ },
99
+ SCHEDULE_R0031: {
100
+ ...dynamicError,
101
+ fix: "Pass a new `id` to `createRun()` of the Schedule Run store, or read the existing Run with `getRun(id)`."
102
+ },
103
+ SCHEDULE_R0032: {
104
+ ...dynamicError,
105
+ fix: "Pass a new `id` to `createAttempt()` of the Schedule Run store."
106
+ },
107
+ SCHEDULE_R0033: {
108
+ ...dynamicError,
109
+ fix: "Pass a new `id` to `createRun()` of the Schedule Run store, or read the existing Run with `getRun(id)`."
110
+ },
111
+ SCHEDULE_R0034: {
112
+ ...dynamicError,
113
+ fix: "Deploy the output of the current build, and keep the file under `server/schedules/` of each Schedule that the host still triggers."
114
+ },
115
+ SCHEDULE_R0035: {
116
+ ...dynamicError,
117
+ fix: "Read `error.cause` for the value that the Schedule handler threw, and fix the handler in `server/schedules/<name>.ts`. Throw an `Error` so that the run keeps its stack."
118
+ },
119
+ SCHEDULE_B0001: {
120
+ ...dynamicError,
121
+ fix: "Set `runtime: { driver: \"process\" }` in `hubSchedule()` or in `vitehub({ schedule })`, or remove `runtime` to let the host wake Schedules."
122
+ },
123
+ SCHEDULE_B0002: {
124
+ ...dynamicError,
125
+ fix: "Set `runtime.prefix` in `hubSchedule()` or in `vitehub({ schedule })` to a string, such as `\"my-app:schedule\"`, or remove it to use `vitehub:schedule`."
126
+ },
127
+ SCHEDULE_B0003: {
128
+ ...dynamicError,
129
+ fix: "Set `runtime.intervalMs` in `hubSchedule()` or in `vitehub({ schedule })` to a number greater than 0 and not more than `60000`, or remove it to use `60000`."
130
+ },
131
+ SCHEDULE_B0004: {
132
+ ...dynamicError,
133
+ fix: "Set `runtime.concurrency` in `hubSchedule()` or in `vitehub({ schedule })` to an integer of 1 or more, or remove it to use 1."
134
+ },
135
+ SCHEDULE_B0005: {
136
+ ...dynamicError,
137
+ fix: "Write the Schedule file that the message names as `export default defineSchedule({ cron: \"...\", handler })`, with literal option values and no spread or computed keys. If the file has a syntax error, correct it first."
138
+ },
139
+ SCHEDULE_B0006: {
140
+ ...dynamicError,
141
+ fix: "Rename or remove one of the two Schedule definitions that the message lists. Each Schedule name must have one file in `server/schedules/` or one plugin contribution."
142
+ },
143
+ SCHEDULE_B0007: {
144
+ ...dynamicError,
145
+ fix: "Correct the `vitehub.schedules` entry of the plugin that the message names. Give it a `name` and `definition: { module, export: \"default\" }`, where `module` is the absolute path or `file:` URL of a file that exists."
146
+ },
147
+ SCHEDULE_B0008: {
148
+ ...dynamicError,
149
+ fix: "Set `cron` in `hubSchedule()` or in `vitehub({ schedule })` to a map of Schedule names to cron strings, such as `{ cleanup: \"0 0 * * *\" }`, and use only the names of existing Schedules. With the Process Runtime, remove `cron`, or set `providerOutput` to `\"nitro\"` or `\"standalone\"`."
150
+ },
151
+ SCHEDULE_B0009: {
152
+ ...dynamicError,
153
+ fix: "Set Schedule `runtime.leaseTtlMs` to a finite number greater than zero, or omit it to use the 60000 ms default."
154
+ },
155
+ SCHEDULE_DEFINITION_EXPORT_INVALID: {
156
+ why: ({ name }) => `Schedule "${name}" has no default export of defineSchedule() with a cron and a handler.`,
157
+ fix: "Default-export `defineSchedule({ cron, handler })` from the Schedule file that the message names, in `server/schedules/`."
158
+ },
159
+ SCHEDULE_PROCESS_CLAIMS_IN_MEMORY: {
160
+ why: "The Process Runtime claims each Schedule occurrence in memory, because the app has no Database. With several server processes, each one runs every occurrence.",
161
+ fix: "Run one server only, or add a Postgres Database so that more than one server runs each occurrence once."
162
+ },
163
+ SCHEDULE_RUNTIME_CATCH_UP_INVALID: {
164
+ why: "Schedule Process Runtime catchUpMs must be a non-negative number.",
165
+ fix: "Set `runtime.catchUpMs` in `hubSchedule()` or in `vitehub({ schedule })` to a number of 0 or more, or remove it to use one hour (`3600000`)."
166
+ }
167
+ }
168
+ });
169
+ //#endregion
170
+ export { scheduleErrorDiagnostics as t };
@@ -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 };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,77 @@
1
1
  /// <reference path="./registry-module.d.ts" />
2
- import { a as ScheduleDefinitionRegistry, c as ScheduleRunAttemptRecord, d as ScheduleRunError, f as ScheduleRunListOptions, g as ScheduleRunStore, h as ScheduleRunStatus, l as ScheduleRunAttemptStatus, m as ScheduleRunResponse, n as ScheduleDefinition, o as ScheduleHandler, p as ScheduleRunRecord, r as ScheduleDefinitionInput, s as ScheduleRegistryDefinition, t as DiscoveredScheduleDefinition, u as ScheduleRunContext } from "./types-CHdV9FQU.js";
2
+ import { _ as StartScheduleOptions, a as ScheduleDefinitionRegistry, b as StartedScheduleStore, c as ScheduleRunAttemptRecord, d as ScheduleRunError, f as ScheduleRunListOptions, g as ScheduleRunStore, h as ScheduleRunStatus, l as ScheduleRunAttemptStatus, m as ScheduleRunResponse, n as ScheduleDefinition, o as ScheduleHandler, p as ScheduleRunRecord, r as ScheduleDefinitionInput, s as ScheduleRegistryDefinition, t as DiscoveredScheduleDefinition, u as ScheduleRunContext, v as StartScheduleTiming, y as StartedSchedule } from "./types-Cw5LjPuc.js";
3
3
  import { defineSchedule } from "./definition.js";
4
- import { t as ScheduleKVStorage } from "./kv-storage-Bv9ocZT-.js";
5
- import { t as KVScheduleStoreOptions } from "./store-QAOd8bxm.js";
6
- import { ViteHubError } from "@vite-hub/runtime";
4
+ import { i as RunScheduleOptions, t as KVScheduleStoreOptions } from "./store-DeMojnXM.js";
5
+ import { t as ScheduleKVStorage } from "./kv-storage-Bm9aYLfZ.js";
6
+ import { ErrorCatalog, Result, ViteHubError } from "@vite-hub/runtime";
7
+ //#region src/run-errors.d.ts
8
+ type RunScheduleErrorCodes = {
9
+ SCHEDULE_INVALID_SCHEDULED_AT: {
10
+ fix: string;
11
+ why: string;
12
+ };
13
+ SCHEDULE_RUN_STORE_FAILED: {
14
+ fix: string;
15
+ why: string;
16
+ };
17
+ };
18
+ type RunScheduleErrorCode = keyof RunScheduleErrorCodes;
19
+ //#endregion
20
+ //#region src/run.d.ts
21
+ /**
22
+ * Runs a Static Schedule Definition that sets `manual: true` now, as if its cron fired at `scheduledAt` (default: now).
23
+ * It returns `[error, run]`. A failed handler is a run with `status: "failed"`, not an error. An invalid `scheduledAt`
24
+ * or a failed run store is `error`. Definition loading errors, unknown names, and Definitions without `manual: true` throw.
25
+ */
26
+ export declare function runSchedule(name: string, options?: RunScheduleOptions): Promise<Result<ScheduleRunRecord, RunScheduleErrorCode>>;
27
+ //#endregion
28
+ //#region src/started-errors.d.ts
29
+ type StartedScheduleErrorCodes = {
30
+ SCHEDULE_INVALID_OPTIONS: {
31
+ fix: string;
32
+ why: (data: {
33
+ problem: string;
34
+ }) => string;
35
+ };
36
+ SCHEDULE_NOT_FOUND: {
37
+ fix: string;
38
+ why: (data: {
39
+ id: string;
40
+ }) => string;
41
+ };
42
+ SCHEDULE_NOT_STARTABLE: {
43
+ fix: string;
44
+ why: (data: {
45
+ name: string;
46
+ }) => string;
47
+ };
48
+ SCHEDULE_STORE_FAILED: {
49
+ fix: string;
50
+ why: string;
51
+ };
52
+ SCHEDULE_STORE_MISSING: {
53
+ fix: string;
54
+ why: string;
55
+ };
56
+ };
57
+ type StartedScheduleErrorCode = keyof StartedScheduleErrorCodes;
58
+ //#endregion
59
+ //#region src/started.d.ts
60
+ /**
61
+ * Starts the Schedule Definition `name`, which declares no `cron`, at a time that code picks: once at `at`, or on each
62
+ * occurrence of `cron` in `timeZone` until `cancelSchedule()`. The store keeps it across restarts and deploys. The handler
63
+ * receives `payload` as `context.payload`.
64
+ */
65
+ export declare function startSchedule(name: string, options: StartScheduleOptions): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
66
+ /** Reads one started Schedule. */
67
+ export declare function getSchedule(id: string): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
68
+ /** Lists the started Schedules, oldest first. `name` keeps the Schedules of one Definition. */
69
+ export declare function listSchedules(options?: {
70
+ name?: string;
71
+ }): Promise<Result<StartedSchedule[], StartedScheduleErrorCode>>;
72
+ /** Removes a started Schedule, so it does not run again. A run that already started finishes. */
73
+ export declare function cancelSchedule(id: string): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
74
+ //#endregion
7
75
  //#region src/errors.d.ts
8
76
  declare const scheduleErrorCodes: readonly ["SCHEDULE_DEFINITION_NOT_FOUND", "SCHEDULE_INVALID_CRON", "SCHEDULE_INVALID_SCHEDULED_AT", "SCHEDULE_MANUAL_RUN_DISABLED", "SCHEDULE_NOT_DUE", "SCHEDULE_RUN_NOT_FOUND"];
9
77
  declare const scheduleErrorFields: readonly ["cron", "scheduledAt"];
@@ -17,4 +85,4 @@ type ScheduleErrorDetails = {
17
85
  valueType: ScheduleErrorValueType;
18
86
  };
19
87
  //#endregion
20
- export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunResponse, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleValidationErrorCode, defineSchedule };
88
+ export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RunScheduleErrorCode, type RunScheduleOptions, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunResponse, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleValidationErrorCode, type StartScheduleOptions, type StartScheduleTiming, type StartedSchedule, type StartedScheduleErrorCode, type StartedScheduleStore, defineSchedule };
package/dist/index.js CHANGED
@@ -1,2 +1,56 @@
1
- import { t as defineSchedule } from "./definition-CMiOg1lg.js";
2
- export { defineSchedule };
1
+ import { defineSchedule } from "./definition.js";
2
+ import { o as createScheduleError, r as parseScheduledAt } from "./wait-until-Dy4Bn3ZN.js";
3
+ import { r as executeManualSchedule, s as resolveManualSchedule } from "./started-errors-DEmYH-vp.js";
4
+ import { i as startSchedule, n as getSchedule, r as listSchedules, t as cancelSchedule } from "./started-B0pc3JY0.js";
5
+ import { defineErrors } from "@vite-hub/runtime";
6
+ //#region src/run-errors.ts
7
+ const runScheduleErrors = /*#__PURE__*/ defineErrors({
8
+ docs: "https://vitehub.dev/docs/schedule/diagnostics",
9
+ codes: {
10
+ SCHEDULE_INVALID_SCHEDULED_AT: {
11
+ why: "`runSchedule()` got a `scheduledAt` that is not a valid date-time.",
12
+ fix: "Pass a valid `Date`, or an ISO 8601 date-time with `Z` or an offset, such as `2026-01-31T23:59:00Z`. Leave it out to run as of now."
13
+ },
14
+ SCHEDULE_RUN_STORE_FAILED: {
15
+ why: "The store of Schedule Runs failed, so the run did not start or its record is incomplete. `error.cause` has the store error.",
16
+ fix: "Check that the Schedule run store is reachable from this server. Before retrying, confirm that the handler did not already run or that it is safe to repeat."
17
+ }
18
+ }
19
+ });
20
+ //#endregion
21
+ //#region src/run.ts
22
+ const registryModule = "#vitehub/schedule/registry";
23
+ /** The registry that the Schedule Vite plugin generates. It loads on the first run, so importing the root stays cheap. */
24
+ async function loadRegistry() {
25
+ try {
26
+ return (await import(
27
+ /* @vite-ignore */
28
+ /* @vitehub-schedule-registry */
29
+ registryModule
30
+ )).default;
31
+ } catch (cause) {
32
+ throw createScheduleError("SCHEDULE_DEFINITION_NOT_FOUND", { cause });
33
+ }
34
+ }
35
+ /**
36
+ * Runs a Static Schedule Definition that sets `manual: true` now, as if its cron fired at `scheduledAt` (default: now).
37
+ * It returns `[error, run]`. A failed handler is a run with `status: "failed"`, not an error. An invalid `scheduledAt`
38
+ * or a failed run store is `error`. Definition loading errors, unknown names, and Definitions without `manual: true` throw.
39
+ */
40
+ async function runSchedule(name, options = {}) {
41
+ const registry = await loadRegistry();
42
+ const definition = await resolveManualSchedule(registry, name);
43
+ let scheduledAt;
44
+ try {
45
+ scheduledAt = parseScheduledAt(options.scheduledAt);
46
+ } catch (cause) {
47
+ return [runScheduleErrors.SCHEDULE_INVALID_SCHEDULED_AT({ cause }), void 0];
48
+ }
49
+ try {
50
+ return [void 0, await executeManualSchedule(definition, name, scheduledAt)];
51
+ } catch (cause) {
52
+ return [runScheduleErrors.SCHEDULE_RUN_STORE_FAILED({ cause }), void 0];
53
+ }
54
+ }
55
+ //#endregion
56
+ export { cancelSchedule, defineSchedule, getSchedule, listSchedules, runSchedule, startSchedule };
@@ -0,0 +1,22 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/invariant.ts
3
+ const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
+ codes: { INTERNAL_INVARIANT_FAILED: {
6
+ why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
7
+ fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
8
+ } }
9
+ });
10
+ /**
11
+ * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
12
+ * Use a code from the package catalog when a developer can cause the error or fix it.
13
+ */
14
+ function invariantError(what) {
15
+ return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
16
+ }
17
+ /** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
18
+ function invariant(condition, what) {
19
+ if (!condition) throw invariantError(what);
20
+ }
21
+ //#endregion
22
+ export { invariantError as n, invariant as t };
@@ -1,8 +1,8 @@
1
1
  //#region src/runtime/kv-storage.ts
2
2
  function createScheduleKVStorage(kvStore) {
3
3
  return {
4
- async del(key) {
5
- const [error] = await kvStore.del(key);
4
+ async delete(key) {
5
+ const [error] = await kvStore.delete(key);
6
6
  if (error) throw error;
7
7
  },
8
8
  async get(key) {
@@ -16,9 +16,9 @@ function createScheduleKVStorage(kvStore) {
16
16
  return value ?? false;
17
17
  },
18
18
  async keys(base) {
19
- const [error, value] = await kvStore.keys(base);
19
+ const [error, value] = await kvStore.list({ prefix: base && !/[:/\\]$/.test(base) ? `${base}:` : base });
20
20
  if (error) throw error;
21
- return value ?? [];
21
+ return value?.keys ?? [];
22
22
  },
23
23
  async set(key, value) {
24
24
  const [error] = await kvStore.set(key, value);
@@ -1,16 +1,20 @@
1
1
  //#region src/runtime/kv-storage.d.ts
2
2
  interface ScheduleKVStorage {
3
- del(key: string): boolean | Promise<boolean> | Promise<void> | void;
3
+ delete(key: string): boolean | Promise<boolean> | Promise<void> | void;
4
4
  get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
5
5
  has(key: string): boolean | Promise<boolean>;
6
6
  keys(base?: string): Promise<string[]> | string[];
7
7
  set<T = unknown>(key: string, value: T): Promise<void> | void;
8
8
  }
9
9
  interface ViteHubKVStorage {
10
- del(key: string): Promise<readonly [unknown, unknown]>;
10
+ delete(key: string): Promise<readonly [unknown, unknown]>;
11
11
  get<T = unknown>(key: string): Promise<readonly [unknown, T | null | undefined]>;
12
12
  has(key: string): Promise<readonly [unknown, boolean | undefined]>;
13
- keys(base?: string): Promise<readonly [unknown, string[] | undefined]>;
13
+ list(options: {
14
+ prefix?: string;
15
+ }): Promise<readonly [unknown, {
16
+ keys: string[];
17
+ } | undefined]>;
14
18
  set<T = unknown>(key: string, value: T): Promise<readonly [unknown, unknown]>;
15
19
  }
16
20
  declare function createScheduleKVStorage(kvStore: ViteHubKVStorage): ScheduleKVStorage;