@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.
- package/README.md +118 -100
- package/dist/console-wEhr0LWn.d.ts +330 -0
- package/dist/definition.d.ts +6 -2
- package/dist/definition.js +47 -1
- package/dist/due-sOJvF_6Z.js +144 -0
- package/dist/durability.d.ts +14 -0
- package/dist/durability.js +23 -0
- package/dist/error-diagnostics-BBtYYl8j.js +170 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/index.d.ts +73 -5
- package/dist/index.js +56 -2
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/{kv-storage-DWinmLLy.js → kv-storage-2kZtP2CC.js} +4 -4
- package/dist/{kv-storage-Bv9ocZT-.d.ts → kv-storage-Bm9aYLfZ.d.ts} +7 -3
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-DqwmJ8MN.js +207 -0
- package/dist/operations.d.ts +36 -4
- package/dist/operations.js +130 -730
- package/dist/os.d.ts +167 -0
- package/dist/os.js +1659 -0
- package/dist/runtime/console.d.ts +12 -0
- package/dist/runtime/console.js +85 -0
- package/dist/runtime/kv.d.ts +1 -1
- package/dist/runtime/kv.js +1 -1
- package/dist/runtime/process.d.ts +32 -5
- package/dist/runtime/process.js +401 -413
- package/dist/runtime/state.d.ts +2 -9
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +28 -2
- package/dist/runtime/static.js +2 -2
- package/dist/runtime.d.ts +34 -32
- package/dist/runtime.js +6 -5
- package/dist/started-B0pc3JY0.js +146 -0
- package/dist/started-Bk2Icknk.js +201 -0
- package/dist/{execute-BJrgNgQ0.js → started-errors-DEmYH-vp.js} +94 -38
- package/dist/{inspect-DTfAo5gS.js → started-name-ruCM1EtQ.js} +5 -1
- package/dist/state-CPd10SXq.d.ts +58 -0
- package/dist/{state-DSxmHPn3.js → state-D4SZH6zk.js} +50 -22
- package/dist/{static-6g82xguw.js → static-7JCga3Iu.js} +80 -44
- package/dist/store-DeMojnXM.d.ts +53 -0
- package/dist/time-zone-SBldrUgt.js +59 -0
- package/dist/{types-CHdV9FQU.d.ts → types-Cw5LjPuc.d.ts} +62 -8
- package/dist/vite.d.ts +255 -2
- package/dist/vite.js +6128 -2
- package/dist/{wait-until-BmIqRo4x.js → wait-until-Dy4Bn3ZN.js} +26 -1
- package/package.json +19 -24
- package/dist/definition-CMiOg1lg.js +0 -111
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-in7mif5s.js +0 -45
- package/dist/nuxt.d.ts +0 -17
- package/dist/nuxt.js +0 -27
- package/dist/operations-gk2qzhYV.js +0 -131
- package/dist/store-QAOd8bxm.d.ts +0 -11
- package/dist/vite-BAVyZ8hZ.d.ts +0 -474
- package/dist/vite-BJwZkMrn.js +0 -5193
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../internal/src/object.ts
|
|
2
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/** A non-null object or a function that is not an array. */
|
|
7
|
+
function isRecordOrFunction(value) {
|
|
8
|
+
return Object(value) === value && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { isRecordOrFunction as n, isRecord as t };
|
|
@@ -75,7 +75,7 @@ declare namespace StandardSchemaV1 {
|
|
|
75
75
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
|
-
//#region ../internal/src/
|
|
78
|
+
//#region ../internal/src/operation-definition.d.ts
|
|
79
79
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
80
80
|
type OperationKind = "read" | "write" | "destructive";
|
|
81
81
|
/** The signed-in user of a call. */
|
|
@@ -98,7 +98,9 @@ interface OperationAccess {
|
|
|
98
98
|
readonly mode: string;
|
|
99
99
|
/**
|
|
100
100
|
* The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
|
|
101
|
-
* operation of the section)
|
|
101
|
+
* operation of the section), `"<section>:read"` (only the operations that read), or `"<section>:<scope>"` (only the
|
|
102
|
+
* calls of a scoped operation for that scope, such as `"blob:media"` for one Blob store). `"<section>:<scope>:read"`
|
|
103
|
+
* allows only the reads of that scope.
|
|
102
104
|
*/
|
|
103
105
|
readonly sections: "all" | readonly string[];
|
|
104
106
|
readonly user?: OperationUser;
|
|
@@ -113,9 +115,20 @@ interface OperationContext {
|
|
|
113
115
|
surface: "console" | "cli" | "mcp" | "agent";
|
|
114
116
|
/** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
|
|
115
117
|
development?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* The project root of a development server, for operations that read build files, such as `bundle.report`. Hosts set
|
|
120
|
+
* it only with `development`, so a deployed server never reads project files through it.
|
|
121
|
+
*/
|
|
122
|
+
projectRoot?: string;
|
|
116
123
|
env?: Record<string, unknown>;
|
|
117
124
|
waitUntil?: (task: Promise<unknown>) => void;
|
|
118
125
|
request?: Request;
|
|
126
|
+
/**
|
|
127
|
+
* The request event of the HTTP request that carries the call, when there is one: the Request of the Console route,
|
|
128
|
+
* with its Standard Context. Operations hand it to app hooks that read the request's own session, such as `identify`
|
|
129
|
+
* of Comments.
|
|
130
|
+
*/
|
|
131
|
+
event?: unknown;
|
|
119
132
|
/** Operations set a success status here, such as 202 for an accepted call. */
|
|
120
133
|
response?: {
|
|
121
134
|
status?: number;
|
|
@@ -138,9 +151,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
138
151
|
description: string;
|
|
139
152
|
/**
|
|
140
153
|
* Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
|
|
141
|
-
* from the input, for operations that serve several sections.
|
|
154
|
+
* from the input, for operations that serve several sections. Section ids cannot contain `:`; it is reserved for
|
|
155
|
+
* scope and read-only grants. A function that returns an invalid id denies the call.
|
|
142
156
|
*/
|
|
143
157
|
section: string | false | ((input: Input) => string | undefined);
|
|
158
|
+
/**
|
|
159
|
+
* The part of a string `section` that one call uses, such as the Blob store that the input names. The call then needs
|
|
160
|
+
* the section (every scope) or `"<section>:<scope>"` (only this scope). A scope that is empty, is `read`, or has a
|
|
161
|
+
* `:` needs the whole section.
|
|
162
|
+
*/
|
|
163
|
+
scope?: (input: Input) => string | undefined;
|
|
144
164
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
|
|
145
165
|
kind: OperationKind;
|
|
146
166
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
@@ -149,19 +169,14 @@ interface OperationDefinition<Input, Output> {
|
|
|
149
169
|
cli?: {
|
|
150
170
|
/** Defaults: namespace = section, command = verb. */
|
|
151
171
|
namespace?: string;
|
|
172
|
+
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
152
173
|
command?: string;
|
|
153
174
|
/** Input keys read from positional arguments, in order. */
|
|
154
175
|
positional?: string[];
|
|
155
176
|
/** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
|
|
156
177
|
format?: (output: Output) => string;
|
|
157
|
-
/** `vitehub <namespace>` runs this command when no command is named
|
|
178
|
+
/** `vitehub <namespace>` runs this command when no command is named. */
|
|
158
179
|
default?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
|
|
161
|
-
* and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
|
|
162
|
-
* a CI job needs no Console credentials. Without a key it calls the RPC.
|
|
163
|
-
*/
|
|
164
|
-
dispatch?: string;
|
|
165
180
|
};
|
|
166
181
|
/** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
|
|
167
182
|
maxRequestBytes?: number;
|
|
@@ -170,8 +185,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
170
185
|
* confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
|
|
171
186
|
*/
|
|
172
187
|
readOnlyWhen?: (input: Input) => boolean;
|
|
173
|
-
/**
|
|
174
|
-
|
|
188
|
+
/**
|
|
189
|
+
* How MCP offers the operation as a tool. `false`: MCP does not offer it, such as an editor transport that only the
|
|
190
|
+
* Console uses. `title`: the short title that clients show, instead of the name in words. `format`: the text of a
|
|
191
|
+
* result for the Agent, such as a list of lines. The result stays the structured content. Without `format`, the text
|
|
192
|
+
* is the result as JSON.
|
|
193
|
+
*/
|
|
194
|
+
mcp?: false | {
|
|
195
|
+
title?: string;
|
|
196
|
+
format?: (output: NoInfer<Output>) => string;
|
|
197
|
+
};
|
|
175
198
|
/** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
|
|
176
199
|
user?: false;
|
|
177
200
|
/**
|
|
@@ -182,24 +205,28 @@ interface OperationDefinition<Input, Output> {
|
|
|
182
205
|
run: (input: Input, context: OperationContext) => Output | Promise<Output>;
|
|
183
206
|
}
|
|
184
207
|
/** An operation of any input and output, as a registry holds it. */
|
|
185
|
-
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
|
|
208
|
+
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
186
209
|
readOnlyWhen?: (input: never) => boolean;
|
|
187
210
|
cli?: {
|
|
188
211
|
namespace?: string;
|
|
189
212
|
command?: string;
|
|
190
213
|
default?: boolean;
|
|
191
|
-
dispatch?: string;
|
|
192
214
|
positional?: string[];
|
|
193
215
|
format?: (output: never) => string;
|
|
194
216
|
};
|
|
217
|
+
mcp?: false | {
|
|
218
|
+
title?: string;
|
|
219
|
+
format?: (output: never) => string;
|
|
220
|
+
};
|
|
195
221
|
input: StandardSchemaV1;
|
|
196
222
|
output?: StandardSchemaV1;
|
|
197
223
|
run: (input: never, context: OperationContext) => unknown;
|
|
224
|
+
scope?: (input: never) => string | undefined;
|
|
198
225
|
section: string | false | ((input: never) => string | undefined);
|
|
199
226
|
}
|
|
200
227
|
/** The contribution of one plugin: operations, or a module that exports them. */
|
|
201
228
|
interface OperationContributionEntry {
|
|
202
|
-
/**
|
|
229
|
+
/** The absolute path of the module that generated code imports, such as `ownModule(import.meta.url, "operations")`. */
|
|
203
230
|
module: string;
|
|
204
231
|
/** Named export that holds an operation or an array of operations. Defaults to `default`. */
|
|
205
232
|
export?: string;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-BBtYYl8j.js";
|
|
2
|
+
import { c as runScheduleFrom, o as loadStaticScheduleDefinition } from "./started-errors-DEmYH-vp.js";
|
|
3
|
+
import { i as getScheduleRunStore, n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime, t as getHostScheduleInventory } from "./state-D4SZH6zk.js";
|
|
4
|
+
import { i as startSchedule, r as listSchedules, t as cancelSchedule } from "./started-B0pc3JY0.js";
|
|
5
|
+
import { n as redactInspectionText } from "./started-name-ruCM1EtQ.js";
|
|
6
|
+
//#region src/runtime/operations.ts
|
|
7
|
+
function isoDate(value) {
|
|
8
|
+
if (value === void 0) return;
|
|
9
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
10
|
+
return Number.isNaN(date.getTime()) ? String(value) : date.toISOString();
|
|
11
|
+
}
|
|
12
|
+
function summarizeError(error) {
|
|
13
|
+
if (!error) return;
|
|
14
|
+
const summary = { message: redactInspectionText(error.message) };
|
|
15
|
+
if (error.name) summary.name = redactInspectionText(error.name);
|
|
16
|
+
return summary;
|
|
17
|
+
}
|
|
18
|
+
function summarizeScheduleRun(run) {
|
|
19
|
+
const error = summarizeError(run.error);
|
|
20
|
+
const completedAt = isoDate(run.completedAt);
|
|
21
|
+
const startedAt = isoDate(run.startedAt);
|
|
22
|
+
const summary = {
|
|
23
|
+
attemptCount: run.attemptCount,
|
|
24
|
+
id: run.id,
|
|
25
|
+
scheduleId: run.scheduleId,
|
|
26
|
+
scheduledAt: isoDate(run.scheduledAt) ?? "",
|
|
27
|
+
status: run.status,
|
|
28
|
+
target: run.target
|
|
29
|
+
};
|
|
30
|
+
if (completedAt) summary.completedAt = completedAt;
|
|
31
|
+
if (error) summary.error = error;
|
|
32
|
+
if (run.response) summary.response = {
|
|
33
|
+
status: run.response.status,
|
|
34
|
+
statusText: redactInspectionText(run.response.statusText)
|
|
35
|
+
};
|
|
36
|
+
if (startedAt) summary.startedAt = startedAt;
|
|
37
|
+
return summary;
|
|
38
|
+
}
|
|
39
|
+
function summarizeManualScheduleRun(run) {
|
|
40
|
+
const error = summarizeError(run.error);
|
|
41
|
+
const completedAt = isoDate(run.completedAt);
|
|
42
|
+
const startedAt = isoDate(run.startedAt);
|
|
43
|
+
return {
|
|
44
|
+
...completedAt ? { completedAt } : {},
|
|
45
|
+
...error ? { error } : {},
|
|
46
|
+
id: run.id,
|
|
47
|
+
scheduleId: run.scheduleId,
|
|
48
|
+
scheduledAt: isoDate(run.scheduledAt) ?? "",
|
|
49
|
+
...startedAt ? { startedAt } : {},
|
|
50
|
+
status: run.status
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function summarizeScheduleRunAttempt(attempt) {
|
|
54
|
+
const error = summarizeError(attempt.error);
|
|
55
|
+
const completedAt = isoDate(attempt.completedAt);
|
|
56
|
+
return {
|
|
57
|
+
...completedAt ? { completedAt } : {},
|
|
58
|
+
...error ? { error } : {},
|
|
59
|
+
id: attempt.id,
|
|
60
|
+
runId: attempt.runId,
|
|
61
|
+
startedAt: isoDate(attempt.startedAt) ?? "",
|
|
62
|
+
status: attempt.status
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function newestFirst(left, right) {
|
|
66
|
+
return new Date(right.scheduledAt).getTime() - new Date(left.scheduledAt).getTime();
|
|
67
|
+
}
|
|
68
|
+
/** Lists the recorded runs of one Schedule Definition, newest first. */
|
|
69
|
+
async function listScheduleRuns(scheduleId, options = {}) {
|
|
70
|
+
const runs = (await getScheduleRunStore().listRuns({
|
|
71
|
+
scheduleId,
|
|
72
|
+
limit: options.limit
|
|
73
|
+
})).filter((run) => run.scheduleId === scheduleId).sort(newestFirst);
|
|
74
|
+
return (options.limit === void 0 ? runs : runs.slice(0, options.limit)).map(summarizeScheduleRun);
|
|
75
|
+
}
|
|
76
|
+
/** Lists the attempts of one Schedule Run, oldest first. */
|
|
77
|
+
async function listScheduleRunAttempts(runId) {
|
|
78
|
+
return [...await getScheduleRunStore().listAttempts(runId)].sort((left, right) => new Date(left.startedAt).getTime() - new Date(right.startedAt).getTime()).map(summarizeScheduleRunAttempt);
|
|
79
|
+
}
|
|
80
|
+
/** Gives an operation error its HTTP status and the redacted message that the CLI and the Console report. */
|
|
81
|
+
function withStatus(error, status, fix) {
|
|
82
|
+
return Object.defineProperties(error, {
|
|
83
|
+
...fix && !Reflect.get(error, "fix") ? { fix: {
|
|
84
|
+
configurable: true,
|
|
85
|
+
enumerable: false,
|
|
86
|
+
value: fix,
|
|
87
|
+
writable: true
|
|
88
|
+
} } : {},
|
|
89
|
+
status: {
|
|
90
|
+
configurable: true,
|
|
91
|
+
enumerable: false,
|
|
92
|
+
value: status,
|
|
93
|
+
writable: true
|
|
94
|
+
},
|
|
95
|
+
statusMessage: {
|
|
96
|
+
configurable: true,
|
|
97
|
+
enumerable: false,
|
|
98
|
+
value: redactInspectionText(error.message),
|
|
99
|
+
writable: true
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const errorFix = { SCHEDULE_INVALID_SCHEDULED_AT: "Pass `at` as an ISO 8601 date-time with a time zone, such as 2026-01-31T23:59:00Z or 2026-01-31T23:59:00+01:00." };
|
|
104
|
+
const errorStatus = {
|
|
105
|
+
SCHEDULE_DEFINITION_NOT_FOUND: 404,
|
|
106
|
+
SCHEDULE_HISTORY_INCOMPLETE: 503,
|
|
107
|
+
SCHEDULE_INVALID_SCHEDULED_AT: 400,
|
|
108
|
+
SCHEDULE_MANUAL_RUN_DISABLED: 403,
|
|
109
|
+
SCHEDULE_OPERATION_FAILED: 500,
|
|
110
|
+
SCHEDULE_RUN_NOT_FOUND: 404
|
|
111
|
+
};
|
|
112
|
+
/** Gives a Schedule error the status and the redacted message that every surface reports. */
|
|
113
|
+
async function attempt(work) {
|
|
114
|
+
try {
|
|
115
|
+
return await work();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const code = Reflect.get(Object(error), "code");
|
|
118
|
+
const status = String(code) === code ? errorStatus[code] : void 0;
|
|
119
|
+
if (status && error instanceof Error) throw withStatus(error, status, errorFix[String(code)]);
|
|
120
|
+
throw withStatus(scheduleErrorDiagnostics.SCHEDULE_OPERATION_FAILED({ cause: error }), 500);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function runScheduleRuns(input) {
|
|
124
|
+
return await attempt(async () => ({ runs: await listScheduleRuns(input.id, { limit: input.limit ?? 100 }) }));
|
|
125
|
+
}
|
|
126
|
+
async function runScheduleAttempts(input) {
|
|
127
|
+
return await attempt(async () => {
|
|
128
|
+
const run = await getScheduleRunStore().getRun(input.id);
|
|
129
|
+
if (!run) throw scheduleErrorDiagnostics.SCHEDULE_RUN_NOT_FOUND();
|
|
130
|
+
return {
|
|
131
|
+
attempts: await listScheduleRunAttempts(input.id),
|
|
132
|
+
run: summarizeScheduleRun(run)
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** The manual Static Schedule Definitions that the Console installed. Only `console.invoke` installs them. */
|
|
137
|
+
const consoleSchedulesKey = Symbol.for("vitehub.console.schedules");
|
|
138
|
+
/**
|
|
139
|
+
* Runs a Static Schedule Definition that sets `manual: true`, as if its cron fired at `at` (default: now). The registry holds only those definitions, and it is empty
|
|
140
|
+
* unless Console invocation is enabled, so anything else is "not available".
|
|
141
|
+
*/
|
|
142
|
+
async function runScheduleNow(input, registry = Reflect.get(globalThis, consoleSchedulesKey) ?? {}) {
|
|
143
|
+
if (!Object.hasOwn(registry, input.name)) throw withStatus(scheduleErrorDiagnostics.SCHEDULE_DEFINITION_NOT_FOUND(), 404);
|
|
144
|
+
return await attempt(async () => ({ run: summarizeManualScheduleRun(await runScheduleFrom(registry, input.name, { scheduledAt: input.at })) }));
|
|
145
|
+
}
|
|
146
|
+
function summarizeStartedSchedule(schedule) {
|
|
147
|
+
return {
|
|
148
|
+
...schedule.at ? { at: schedule.at.toISOString() } : {},
|
|
149
|
+
createdAt: schedule.createdAt.toISOString(),
|
|
150
|
+
...schedule.cron === void 0 ? {} : { cron: schedule.cron },
|
|
151
|
+
id: schedule.id,
|
|
152
|
+
...schedule.payload === void 0 ? {} : { payload: schedule.payload },
|
|
153
|
+
name: schedule.name,
|
|
154
|
+
...schedule.timeZone === void 0 ? {} : { timeZone: schedule.timeZone }
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const startedErrorStatus = {
|
|
158
|
+
SCHEDULE_INVALID_OPTIONS: 400,
|
|
159
|
+
SCHEDULE_NOT_FOUND: 404,
|
|
160
|
+
SCHEDULE_NOT_STARTABLE: 404,
|
|
161
|
+
SCHEDULE_STORE_FAILED: 503,
|
|
162
|
+
SCHEDULE_STORE_MISSING: 503
|
|
163
|
+
};
|
|
164
|
+
function operationError(error) {
|
|
165
|
+
return withStatus(error, startedErrorStatus[error.code] ?? 500);
|
|
166
|
+
}
|
|
167
|
+
async function listStaticSchedules(filter) {
|
|
168
|
+
const inventory = getHostScheduleInventory();
|
|
169
|
+
const registry = inventory?.registry ?? {};
|
|
170
|
+
const timings = new Map([...Object.entries(inventory?.timings ?? {}), ...getProcessScheduleDefinitions() ?? []]);
|
|
171
|
+
const names = [.../* @__PURE__ */ new Set([...timings.keys(), ...Object.keys(registry)])].filter((name) => name !== "vitehub/started-schedules" && (filter === void 0 || name === filter)).sort((left, right) => left.localeCompare(right));
|
|
172
|
+
return (await Promise.all(names.map(async (name) => [name, timings.get(name) ?? await loadStaticScheduleDefinition(name, registry)]))).flatMap(([name, definition]) => definition?.cron === void 0 ? [] : [{
|
|
173
|
+
cron: definition.cron,
|
|
174
|
+
name,
|
|
175
|
+
...definition.timeZone === void 0 ? {} : { timeZone: definition.timeZone }
|
|
176
|
+
}]);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Lists the Static Schedule Definitions and the Schedules that code started. An app with only cron Schedules has no store
|
|
180
|
+
* for started Schedules, so it lists only its Definitions.
|
|
181
|
+
*/
|
|
182
|
+
async function runScheduleList(input) {
|
|
183
|
+
const definitions = await listStaticSchedules(input.name);
|
|
184
|
+
if (!getStartedScheduleRuntime()) return {
|
|
185
|
+
definitions,
|
|
186
|
+
schedules: []
|
|
187
|
+
};
|
|
188
|
+
const [error, schedules] = await listSchedules(input.name === void 0 ? {} : { name: input.name });
|
|
189
|
+
if (error) throw operationError(error);
|
|
190
|
+
return {
|
|
191
|
+
definitions,
|
|
192
|
+
schedules: schedules.map(summarizeStartedSchedule)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
async function runScheduleStart(input) {
|
|
196
|
+
const { name, ...options } = input;
|
|
197
|
+
const [error, schedule] = await startSchedule(name, options);
|
|
198
|
+
if (error) throw operationError(error);
|
|
199
|
+
return { schedule: summarizeStartedSchedule(schedule) };
|
|
200
|
+
}
|
|
201
|
+
async function runScheduleCancel(input) {
|
|
202
|
+
const [error, schedule] = await cancelSchedule(input.id);
|
|
203
|
+
if (error) throw operationError(error);
|
|
204
|
+
return { schedule: summarizeStartedSchedule(schedule) };
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
export { listScheduleRunAttempts, listScheduleRuns, runScheduleAttempts, runScheduleCancel, runScheduleList, runScheduleNow, runScheduleRuns, runScheduleStart, summarizeScheduleRun, summarizeScheduleRunAttempt };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as ScheduleRunStatus, l as ScheduleRunAttemptStatus } from "./types-
|
|
2
|
-
import { t as AnyOperation } from "./
|
|
1
|
+
import { h as ScheduleRunStatus, l as ScheduleRunAttemptStatus } from "./types-Cw5LjPuc.js";
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-nmRu_O3V.js";
|
|
3
3
|
//#region src/runtime/operations.d.ts
|
|
4
4
|
/** Error of a run or attempt. The stack is not included. */
|
|
5
5
|
interface ScheduleRunErrorSummary {
|
|
@@ -37,6 +37,8 @@ interface ManualScheduleRunSummary {
|
|
|
37
37
|
error?: ScheduleRunErrorSummary;
|
|
38
38
|
id: string;
|
|
39
39
|
scheduleId: string;
|
|
40
|
+
/** The fire time that the handler received. */
|
|
41
|
+
scheduledAt: string;
|
|
40
42
|
startedAt?: string;
|
|
41
43
|
status: ScheduleRunStatus;
|
|
42
44
|
}
|
|
@@ -53,9 +55,39 @@ interface ScheduleAttemptsResult {
|
|
|
53
55
|
interface ScheduleRunResult {
|
|
54
56
|
run: ManualScheduleRunSummary;
|
|
55
57
|
}
|
|
58
|
+
/** Serializable view of one started Schedule, as `vitehub schedule list` prints it. */
|
|
59
|
+
interface StartedScheduleSummary {
|
|
60
|
+
at?: string;
|
|
61
|
+
createdAt: string;
|
|
62
|
+
cron?: string;
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
payload?: unknown;
|
|
66
|
+
timeZone?: string;
|
|
67
|
+
}
|
|
68
|
+
/** Serializable view of one Static Schedule Definition, which runs on its own `cron`. */
|
|
69
|
+
interface ScheduleDefinitionSummary {
|
|
70
|
+
cron: string;
|
|
71
|
+
name: string;
|
|
72
|
+
timeZone?: string;
|
|
73
|
+
}
|
|
74
|
+
/** Result of `schedule.list`. */
|
|
75
|
+
interface ScheduleListResult {
|
|
76
|
+
/** The Static Schedule Definitions of this server, by name. */
|
|
77
|
+
definitions: ScheduleDefinitionSummary[];
|
|
78
|
+
/** The Schedules that code started with `startSchedule()`, oldest first. Empty when no Definition can be started. */
|
|
79
|
+
schedules: StartedScheduleSummary[];
|
|
80
|
+
}
|
|
81
|
+
/** Result of `schedule.start` and `schedule.cancel`. */
|
|
82
|
+
interface StartedScheduleResult {
|
|
83
|
+
schedule: StartedScheduleSummary;
|
|
84
|
+
}
|
|
56
85
|
//#endregion
|
|
57
86
|
//#region src/operations.d.ts
|
|
58
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* The `schedule.*` operations: runs, attempts, run, list, start, and cancel. The Console, `vitehub schedule`, and agents
|
|
89
|
+
* run them.
|
|
90
|
+
*/
|
|
59
91
|
export declare const scheduleOperations: readonly AnyOperation[];
|
|
60
92
|
//#endregion
|
|
61
|
-
export type { ScheduleAttemptsResult, ScheduleRunResult, ScheduleRunsResult };
|
|
93
|
+
export type { ScheduleAttemptsResult, ScheduleListResult, ScheduleRunResult, ScheduleRunsResult, StartedScheduleResult };
|