@vite-hub/schedule 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +27 -6
  2. package/dist/cron-D0mqg3ql.js +22 -0
  3. package/dist/definition.d.ts +1 -1
  4. package/dist/definition.js +3 -4
  5. package/dist/{due-D-0trD1g.js → due-DXgXKgzg.js} +1 -1
  6. package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
  7. package/dist/{error-diagnostics-B1AaIGWP.js → error-diagnostics-KvK9MX6w.js} +14 -2
  8. package/dist/{started-errors-IG9DlT2A.js → execute-DoQC2i_V.js} +7 -34
  9. package/dist/index.d.ts +12 -8
  10. package/dist/index.js +1 -51
  11. package/dist/{kv-storage-hI2IOjb5.d.ts → kv-storage-CKSSQ6Fk.d.ts} +7 -3
  12. package/dist/{kv-storage-Dsr3TL9c.js → kv-storage-CszEkof6.js} +2 -2
  13. package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-Blwi3jQF.d.ts} +1 -0
  14. package/dist/{operations-BTUQeba1.js → operations-CEZCefAG.js} +25 -13
  15. package/dist/operations.d.ts +2 -2
  16. package/dist/operations.js +7 -5
  17. package/dist/os.js +2 -2
  18. package/dist/runtime/console.js +24 -11
  19. package/dist/runtime/kv.d.ts +1 -1
  20. package/dist/runtime/kv.js +1 -1
  21. package/dist/runtime/process.d.ts +1 -1
  22. package/dist/runtime/process.js +14 -16
  23. package/dist/runtime/state.d.ts +1 -1
  24. package/dist/runtime/state.js +1 -1
  25. package/dist/runtime/static.d.ts +1 -1
  26. package/dist/runtime/static.js +2 -2
  27. package/dist/runtime.d.ts +6 -6
  28. package/dist/runtime.js +5 -5
  29. package/dist/{started-B1Se_Iwo.js → started-ClJ5XOWH.js} +48 -9
  30. package/dist/started-errors-DVw5cYHR.js +28 -0
  31. package/dist/{started-Bzvr4t5f.js → started-yb49f37g.js} +6 -4
  32. package/dist/state-CcVY3UzB.js +570 -0
  33. package/dist/{state-BDEDVlyr.d.ts → state-LuEgYpwR.d.ts} +1 -1
  34. package/dist/{static-Bg7Jj92L.js → static--wi-oIIb.js} +7 -5
  35. package/dist/{static-DeRvJqcQ.d.ts → static-BFV4x94g.d.ts} +1 -1
  36. package/dist/{store-CEv3cScg.d.ts → store-TOayO0NL.d.ts} +6 -3
  37. package/dist/{types-DTVPVY5O.d.ts → types-Wllh0U8N.d.ts} +35 -4
  38. package/dist/vite.d.ts +4 -2
  39. package/dist/vite.js +377 -118
  40. package/package.json +10 -4
  41. package/dist/started-name-w6n9uDdt.js +0 -4
  42. package/dist/state-BZLy46UJ.js +0 -427
  43. package/dist/{cron-BT3ef48f.js → cron-imqlBgO-.js} +1 -1
@@ -21,7 +21,10 @@ type ScheduleHandler<TResult = unknown> = {
21
21
  bivarianceHack(context: ScheduleRunContext): TResult | Promise<TResult>;
22
22
  }["bivarianceHack"];
23
23
  interface ScheduleDefinitionInput<TResult = unknown> {
24
- /** Allows `runSchedule()`, the Console, and `vitehub schedule run` to start a Definition with `cron` outside its cron. */
24
+ /**
25
+ * Set `false` to stop `runSchedule()`, the Console, and `vitehub schedule run` from starting a Definition with `cron`
26
+ * outside its cron. Defaults to `true`.
27
+ */
25
28
  manual?: boolean;
26
29
  /**
27
30
  * Five-field cron expression, evaluated in `timeZone`. Leave it out for a Schedule that runs only when code starts it
@@ -37,7 +40,10 @@ interface ScheduleDefinitionInput<TResult = unknown> {
37
40
  timeZone?: string;
38
41
  }
39
42
  interface ScheduleDefinitionOptions {
40
- /** Allows `runSchedule()`, the Console, and `vitehub schedule run` to start a Definition with `cron` outside its cron. */
43
+ /**
44
+ * Set `false` to stop `runSchedule()`, the Console, and `vitehub schedule run` from starting a Definition with `cron`
45
+ * outside its cron. Defaults to `true`.
46
+ */
41
47
  manual?: boolean;
42
48
  /** IANA time zone of the cron, such as `"Europe/Madrid"`. Defaults to `"UTC"`. */
43
49
  timeZone?: string;
@@ -99,7 +105,9 @@ interface ScheduleRunListOptions {
99
105
  }
100
106
  interface ScheduleRunStore {
101
107
  createAttempt: (attempt: ScheduleRunAttemptRecord) => Promise<ScheduleRunAttemptRecord> | ScheduleRunAttemptRecord;
102
- createRun: (run: ScheduleRunRecord) => Promise<ScheduleRunRecord> | ScheduleRunRecord;
108
+ createRun: (run: ScheduleRunRecord, options?: {
109
+ oneShot?: boolean;
110
+ }) => Promise<ScheduleRunRecord> | ScheduleRunRecord;
103
111
  getAttempt: (id: string) => Promise<ScheduleRunAttemptRecord | undefined> | ScheduleRunAttemptRecord | undefined;
104
112
  getRun: (id: string) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
105
113
  listAttempts: (runId: string) => Promise<ScheduleRunAttemptRecord[]> | ScheduleRunAttemptRecord[];
@@ -114,6 +122,7 @@ interface ScheduleRunStore {
114
122
  }) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
115
123
  }
116
124
  interface DiscoveredScheduleDefinition {
125
+ /** False when the Definition sets `manual: false` or has no `cron`. Only these Definitions cannot run by name. */
117
126
  manual?: boolean;
118
127
  /** True when the Definition declares no `cron`, so it runs only when code starts it with `startSchedule()`. */
119
128
  startable?: boolean;
@@ -125,6 +134,28 @@ interface DiscoveredScheduleDefinition {
125
134
  reason?: string;
126
135
  source?: "server-schedules" | "vite-plugin-contribution" | "vite-suffix";
127
136
  }
137
+ /**
138
+ * The Static Schedule Definitions of the app, by name. ViteHub writes it to `.vitehub/schedule.d.ts` from the files
139
+ * with `cron` in `server/schedules/` and the Schedules that plugins contribute, so `runSchedule()` checks the name.
140
+ */
141
+ interface ScheduleRegistry {}
142
+ /**
143
+ * The Schedule Definitions without `cron`, by name. ViteHub writes it to `.vitehub/schedule.d.ts`, so
144
+ * `startSchedule()` checks the name.
145
+ */
146
+ interface StartableScheduleRegistry {}
147
+ /** @internal Augmented when Schedule discovery writes a registry, even if it finds no Definitions. */
148
+ interface ScheduleRegistryState {}
149
+ type RegistryName<TRegistry> = [keyof (TRegistry & ScheduleRegistryState)] extends [never] ? string : Extract<keyof TRegistry, string>;
150
+ /** A Static Schedule name from `ScheduleRegistry`. Any string before ViteHub writes the registry. */
151
+ type ScheduleName = RegistryName<ScheduleRegistry>;
152
+ /** A name of a Schedule Definition without `cron`, from `StartableScheduleRegistry`. Any string before ViteHub writes the registry. */
153
+ type StartableScheduleName = RegistryName<StartableScheduleRegistry>;
154
+ /**
155
+ * A name that the code reads at runtime, such as from a request. It accepts a `string` value but not a string
156
+ * literal, so a typo in a literal name still fails the type check.
157
+ */
158
+ type DynamicScheduleName<TName extends string> = TName & (string extends TName ? unknown : never);
128
159
  /** When a started Schedule runs: once at `at`, or on each occurrence of `cron` until you cancel it. */
129
160
  type StartScheduleTiming = {
130
161
  /** One run at this time: a `Date`, or an ISO 8601 date-time with a time zone, such as `"2026-11-08T09:00:00Z"`. */
@@ -162,4 +193,4 @@ interface StartedScheduleStore {
162
193
  list: () => Promise<StartedSchedule[]>;
163
194
  put: (schedule: StartedSchedule) => Promise<void>;
164
195
  }
165
- export { StartScheduleOptions as _, ScheduleDefinitionRegistry as a, StartedScheduleStore as b, ScheduleRunAttemptRecord as c, ScheduleRunError as d, ScheduleRunListOptions as f, ScheduleRunStore as g, ScheduleRunStatus as h, ScheduleDefinitionOptions as i, ScheduleRunAttemptStatus as l, ScheduleRunResponse as m, ScheduleDefinition as n, ScheduleHandler as o, ScheduleRunRecord as p, ScheduleDefinitionInput as r, ScheduleRegistryDefinition as s, DiscoveredScheduleDefinition as t, ScheduleRunContext as u, StartScheduleTiming as v, StartedSchedule as y };
196
+ export { StartableScheduleName as C, StartedScheduleStore as E, StartScheduleTiming as S, StartedSchedule as T, ScheduleRunRecord as _, ScheduleDefinitionOptions as a, ScheduleRunStore as b, ScheduleName as c, ScheduleRegistryState as d, ScheduleRunAttemptRecord as f, ScheduleRunListOptions as g, ScheduleRunError as h, ScheduleDefinitionInput as i, ScheduleRegistry as l, ScheduleRunContext as m, DynamicScheduleName as n, ScheduleDefinitionRegistry as o, ScheduleRunAttemptStatus as p, ScheduleDefinition as r, ScheduleHandler as s, DiscoveredScheduleDefinition as t, ScheduleRegistryDefinition as u, ScheduleRunResponse as v, StartableScheduleRegistry as w, StartScheduleOptions as x, ScheduleRunStatus as y };
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { i as ViteHubInspectionPluginMetadata, n as ViteHubConsoleRuntimeRecordTableSection, r as ViteHubDefinitionSummary } from "./console-BdlDJUfS.js";
2
- import { n as OperationContributionEntry } from "./operation-definition-CqZkx1Rm.js";
3
- import { t as DiscoveredScheduleDefinition } from "./types-DTVPVY5O.js";
2
+ import { n as OperationContributionEntry } from "./operations-Blwi3jQF.js";
3
+ import { t as DiscoveredScheduleDefinition } from "./types-Wllh0U8N.js";
4
+ import { Duration } from "@vite-hub/runtime";
4
5
  /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
5
6
  type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
6
7
  /**
@@ -193,6 +194,7 @@ export interface ScheduleOptions {
193
194
  cron?: Readonly<Record<string, string>>;
194
195
  providerOutput?: "auto" | "standalone" | "nitro" | false;
195
196
  projectRoot?: string;
197
+ retention?: Duration;
196
198
  runtime?: ScheduleProcessRuntimeOptions;
197
199
  }
198
200
  export interface ScheduleNitroConfigOptions extends ScheduleOptions {