@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
package/dist/os.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ import { ErrorCatalog, Result } from "@vite-hub/runtime";
2
+ import { posix } from "node:path";
3
+ //#region src/os/errors.d.ts
4
+ /** Operating systems that `@vite-hub/schedule/os` installs timers on, as `process.platform` names them. */
5
+ type OsSchedulePlatform = "linux" | "darwin" | "win32";
6
+ /** `"user"` runs as the current user. `"system"` runs as root or SYSTEM and needs root or Administrator to install. */
7
+ type OsScheduleScope = "user" | "system";
8
+ type CommandFailed = {
9
+ command: string;
10
+ exitCode: number;
11
+ output: string;
12
+ };
13
+ type CronUnsupported = {
14
+ platform: OsSchedulePlatform;
15
+ cron: string;
16
+ reason: string;
17
+ };
18
+ type InvalidOptions = {
19
+ problem: string;
20
+ };
21
+ type NameTaken = {
22
+ platform: OsSchedulePlatform;
23
+ name: string;
24
+ scope: OsScheduleScope;
25
+ resource: string;
26
+ };
27
+ type OptionUnsupported = {
28
+ platform: OsSchedulePlatform;
29
+ option: string;
30
+ reason: string;
31
+ };
32
+ type PermissionRequired = {
33
+ scope: OsScheduleScope;
34
+ };
35
+ type PlatformUnsupported = {
36
+ platform: string;
37
+ };
38
+ type TimeZoneUnsupported = {
39
+ platform: OsSchedulePlatform;
40
+ timeZone: string;
41
+ machineTimeZone: string;
42
+ };
43
+ /** A code whose `error.data` holds the values of its message. */
44
+ type Code<TData> = {
45
+ fix: string;
46
+ why: (data: TData) => string;
47
+ data: (data: TData) => TData;
48
+ };
49
+ type OsScheduleErrorCodes = {
50
+ SCHEDULE_OS_COMMAND_FAILED: Code<CommandFailed>;
51
+ SCHEDULE_OS_CRON_UNSUPPORTED: Code<CronUnsupported>;
52
+ SCHEDULE_OS_INVALID_OPTIONS: Code<InvalidOptions>;
53
+ SCHEDULE_OS_NAME_TAKEN: Code<NameTaken>;
54
+ SCHEDULE_OS_OPTION_UNSUPPORTED: Code<OptionUnsupported>;
55
+ SCHEDULE_OS_PERMISSION_REQUIRED: Code<PermissionRequired>;
56
+ SCHEDULE_OS_PLATFORM_UNSUPPORTED: Code<PlatformUnsupported>;
57
+ SCHEDULE_OS_TIME_ZONE_UNSUPPORTED: Code<TimeZoneUnsupported>;
58
+ };
59
+ export declare const osScheduleErrors: ErrorCatalog<OsScheduleErrorCodes>;
60
+ type OsScheduleErrorCode = keyof OsScheduleErrorCodes;
61
+ //#endregion
62
+ //#region src/os/host.d.ts
63
+ interface OsScheduleStatus {
64
+ name: string;
65
+ platform: OsSchedulePlatform;
66
+ scope: OsScheduleScope;
67
+ /**
68
+ * The OS knows the timer, and ViteHub installed it in this scope. `false` for a timer, unit, plist, or task of the
69
+ * same name that ViteHub did not install: it is not this timer.
70
+ */
71
+ installed: boolean;
72
+ /** A run is in progress. */
73
+ running: boolean;
74
+ /** Start of the last run. macOS does not expose it. */
75
+ lastRunAt?: Date;
76
+ /** Exit code of the last finished run. */
77
+ lastExitCode?: number;
78
+ /** Next time the OS starts the timer. */
79
+ nextRunAt?: Date;
80
+ /** Linux user scope: whether systemd lingering is on. Without it, the timer runs only while the user has a session. */
81
+ linger?: boolean;
82
+ /** File that collects the output of each run. On Linux without `logDir`, the output goes to the journal. */
83
+ logFile?: string;
84
+ }
85
+ interface OsScheduleRemoval {
86
+ name: string;
87
+ platform: OsSchedulePlatform;
88
+ scope: OsScheduleScope;
89
+ /** Files that the uninstall deleted. */
90
+ removed: string[];
91
+ /**
92
+ * The timer or one of its files existed. `false` also when the name belongs to a timer that ViteHub did not install
93
+ * in this scope: the uninstall leaves it as it is.
94
+ */
95
+ existed: boolean;
96
+ }
97
+ //#endregion
98
+ //#region src/os/schedules.d.ts
99
+ /** Any object with `cron` and an optional `timeZone`. The result of `defineSchedule()` fits. */
100
+ interface OsScheduleTiming {
101
+ cron?: string;
102
+ /**
103
+ * IANA time zone of the cron. Without it, the cron runs in UTC, as every Schedule does. `"local"` runs it in the time
104
+ * zone of the machine.
105
+ */
106
+ timeZone?: string;
107
+ }
108
+ interface InstallOsScheduleOptions {
109
+ /** Program and arguments. The program is an absolute path on the target OS, such as `process.execPath`. */
110
+ command: readonly [string, ...string[]];
111
+ /**
112
+ * `"user"` (default): a systemd user timer, a LaunchAgent, or a task that runs as the current user while they are
113
+ * logged in. `"system"`: a system timer, a LaunchDaemon, or a task that runs as SYSTEM. It needs root or Administrator.
114
+ */
115
+ scope?: OsScheduleScope;
116
+ /** Run a missed time once after the machine wakes or boots. Defaults to `true`. macOS always does, so `false` fails there. */
117
+ catchUp?: boolean;
118
+ /** Environment variables of each run. Nothing is copied from the shell that installs the timer. */
119
+ env?: Record<string, string>;
120
+ /** Absolute working directory of each run. Defaults to the home directory, or the OS default for `"system"`. */
121
+ cwd?: string;
122
+ /**
123
+ * Absolute directory of `<name>.log`, which collects the output of each run. Defaults to the journal on Linux,
124
+ * `~/Library/Logs/<name>` on macOS, and `%LOCALAPPDATA%\<name>\Logs` on Windows (`/Library/Logs/<name>` and
125
+ * `%ProgramData%\<name>\Logs` for `"system"`).
126
+ */
127
+ logDir?: string;
128
+ /** Start each run up to this many seconds late, at random. systemd and Task Scheduler only. */
129
+ randomDelaySeconds?: number;
130
+ /** Defaults to `<name> (ViteHub schedule)`. */
131
+ description?: string;
132
+ }
133
+ interface OsScheduleTarget {
134
+ /** Defaults to `"user"`. */
135
+ scope?: OsScheduleScope;
136
+ }
137
+ interface OsScheduleUnit {
138
+ name: string;
139
+ platform: OsSchedulePlatform;
140
+ scope: OsScheduleScope;
141
+ /** Absolute paths of the files that the timer owns. `uninstallOsSchedule()` deletes them. */
142
+ files: string[];
143
+ /** `false` when everything was already up to date and the install changed nothing. */
144
+ changed: boolean;
145
+ /** Linux user scope: whether systemd lingering is on. When it is off, the timer runs only while the user has a session. */
146
+ linger?: boolean;
147
+ status(): Promise<Result<OsScheduleStatus, OsScheduleErrorCode>>;
148
+ uninstall(): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
149
+ }
150
+ //#endregion
151
+ //#region src/os.d.ts
152
+ /**
153
+ * Installs `schedule` as an OS timer named `name` that runs `options.command`: a systemd timer on Linux, a launchd job
154
+ * on macOS, or a Task Scheduler task on Windows. It runs on the Schedule's `cron` in its `timeZone`, or fails with a
155
+ * code when the OS cannot run that cron exactly. Installing the same timer again changes nothing. It fails with
156
+ * `SCHEDULE_OS_NAME_TAKEN` when the OS already has a timer of that name that ViteHub did not install in this scope.
157
+ */
158
+ export declare function installOsSchedule(name: string, schedule: OsScheduleTiming, options: InstallOsScheduleOptions): Promise<Result<OsScheduleUnit, OsScheduleErrorCode>>;
159
+ /** Reads the state of the OS timer `name`: whether it is installed and running, its last run and exit code, and its next run. */
160
+ export declare function osScheduleStatus(name: string, target?: OsScheduleTarget): Promise<Result<OsScheduleStatus, OsScheduleErrorCode>>;
161
+ /**
162
+ * Stops and removes the OS timer `name` and the files that it owns. Removing a timer that does not exist succeeds.
163
+ * A timer of the same name that ViteHub did not install in this scope stays as it is, and `existed` is `false`.
164
+ */
165
+ export declare function uninstallOsSchedule(name: string, target?: OsScheduleTarget): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
166
+ //#endregion
167
+ export type { InstallOsScheduleOptions, OsScheduleErrorCode, OsSchedulePlatform, OsScheduleRemoval, OsScheduleScope, OsScheduleStatus, OsScheduleTarget, OsScheduleTiming, OsScheduleUnit };