@vite-hub/schedule 0.0.3 → 0.1.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 (50) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +199 -65
  3. package/dist/definition-CMiOg1lg.js +111 -0
  4. package/dist/definition.d.ts +4 -6
  5. package/dist/definition.js +2 -42
  6. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  7. package/dist/error-diagnostics-in7mif5s.js +45 -0
  8. package/dist/execute-BJrgNgQ0.js +201 -0
  9. package/dist/index.d.ts +7 -51
  10. package/dist/index.js +2 -7
  11. package/dist/inspect-DTfAo5gS.js +118 -0
  12. package/dist/kv-storage-Bv9ocZT-.d.ts +18 -0
  13. package/dist/nuxt.d.ts +4 -6
  14. package/dist/nuxt.js +3 -1
  15. package/dist/operations-gk2qzhYV.js +131 -0
  16. package/dist/operations-tNUdj3G4.d.ts +212 -0
  17. package/dist/operations.d.ts +61 -0
  18. package/dist/operations.js +921 -0
  19. package/dist/registry-module.d.ts +0 -5
  20. package/dist/runtime/kv.d.ts +4 -0
  21. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  22. package/dist/runtime/process.d.ts +26 -5
  23. package/dist/runtime/process.js +337 -75
  24. package/dist/runtime/state.d.ts +8 -12
  25. package/dist/runtime/state.js +2 -2
  26. package/dist/runtime/static.d.ts +18 -12
  27. package/dist/runtime/static.js +2 -138
  28. package/dist/runtime.d.ts +36 -4
  29. package/dist/runtime.js +5 -3
  30. package/dist/state-DSxmHPn3.js +448 -0
  31. package/dist/static-6g82xguw.js +245 -0
  32. package/dist/store-QAOd8bxm.d.ts +11 -0
  33. package/dist/types-CHdV9FQU.d.ts +113 -0
  34. package/dist/vite-BAVyZ8hZ.d.ts +474 -0
  35. package/dist/vite-BJwZkMrn.js +5193 -0
  36. package/dist/vite.d.ts +2 -38
  37. package/dist/vite.js +2 -2
  38. package/dist/wait-until-BmIqRo4x.js +87 -0
  39. package/package.json +68 -22
  40. package/dist/client-BMFCy0dX.js +0 -233
  41. package/dist/discovery-BZlat3Kc.js +0 -776
  42. package/dist/due-Bbh4yIxq.js +0 -59
  43. package/dist/execute-ClFYvmp9.js +0 -211
  44. package/dist/runtime/driver.d.ts +0 -26
  45. package/dist/runtime/driver.js +0 -334
  46. package/dist/state-By7WU_ks.js +0 -472
  47. package/dist/store-t-74rsM_.d.ts +0 -48
  48. package/dist/types-Bcje4dLV.d.ts +0 -136
  49. package/dist/vite-BX6_KiRw.js +0 -1218
  50. package/dist/wait-until-CR-JjIOb.js +0 -23
@@ -1,472 +0,0 @@
1
- import { ViteHubError } from "@vite-hub/runtime";
2
- import { AsyncLocalStorage } from "node:async_hooks";
3
- //#region src/errors.ts
4
- const scheduleErrorMessages = {
5
- SCHEDULE_ALREADY_EXISTS: "Runtime Schedule already exists.",
6
- SCHEDULE_DISABLED: "Runtime Schedule is disabled.",
7
- SCHEDULE_INVALID_CRON: "Runtime Schedule cron is invalid.",
8
- SCHEDULE_INVALID_ENABLED: "Runtime Schedule enabled value is invalid.",
9
- SCHEDULE_INVALID_ID: "Runtime Schedule id is invalid.",
10
- SCHEDULE_INVALID_INPUT: "Runtime Schedule input is invalid.",
11
- SCHEDULE_INVALID_SCHEDULED_AT: "Runtime Schedule scheduledAt value is invalid.",
12
- SCHEDULE_INVALID_TARGET: "Runtime Schedule target is invalid.",
13
- SCHEDULE_INVALID_TIME_ZONE: "Runtime Schedule time zone is invalid.",
14
- SCHEDULE_NOT_DUE: "Schedule is not due.",
15
- SCHEDULE_NOT_FOUND: "Runtime Schedule was not found.",
16
- SCHEDULE_RUN_NOT_FOUND: "Schedule Run was not found.",
17
- SCHEDULE_TARGET_NOT_ELIGIBLE: "Runtime Schedule target is not eligible.",
18
- SCHEDULE_TARGET_NOT_FOUND: "Runtime Schedule target was not found."
19
- };
20
- function invalidScheduleValueDetails(field, value) {
21
- let valueType;
22
- try {
23
- valueType = value === null ? "null" : Array.isArray(value) ? "array" : value instanceof Date ? "date" : typeof value;
24
- } catch {
25
- valueType = "unknown";
26
- }
27
- return {
28
- field,
29
- valueType
30
- };
31
- }
32
- function createScheduleError(code, options = {}) {
33
- return new ViteHubError(code, scheduleErrorMessages[code], options);
34
- }
35
- function assertRuntimeScheduleId(id) {
36
- if (typeof id !== "string" || !id.trim()) throw createScheduleError("SCHEDULE_INVALID_ID", { details: invalidScheduleValueDetails("id", id) });
37
- }
38
- //#endregion
39
- //#region src/runtime/store.ts
40
- function trimPrefix(prefix) {
41
- return prefix.replace(/^\/+|\/+$/g, "");
42
- }
43
- function joinKey(prefix, ...parts) {
44
- const base = trimPrefix(prefix);
45
- const suffix = parts.map(encodeURIComponent).join("/");
46
- return base ? `${base}/${suffix}` : suffix;
47
- }
48
- function runtimeScheduleKey(prefix, id) {
49
- return joinKey(prefix, "runtime-schedules", id);
50
- }
51
- function scheduleRunKey(prefix, id) {
52
- return joinKey(prefix, "schedule-runs", id);
53
- }
54
- function scheduleRunAttemptKey(prefix, id) {
55
- return joinKey(prefix, "schedule-run-attempts", id);
56
- }
57
- function runtimeScheduleBase(prefix) {
58
- return joinKey(prefix, "runtime-schedules");
59
- }
60
- function scheduleRunBase(prefix) {
61
- return joinKey(prefix, "schedule-runs");
62
- }
63
- function scheduleRunAttemptBase(prefix) {
64
- return joinKey(prefix, "schedule-run-attempts");
65
- }
66
- function isMissingKVPackage(error) {
67
- if (!(error instanceof Error)) return false;
68
- return error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes("Cannot find package '@vite-hub/kv'");
69
- }
70
- async function resolveDefaultKVStore() {
71
- try {
72
- return (await import("./kv-BJ1I9IlJ.js")).scheduleKVStorage;
73
- } catch (error) {
74
- if (isMissingKVPackage(error)) throw new Error("[vitehub:schedule] The default KV-backed stores require @vite-hub/kv. Install it with: pnpm add @vite-hub/kv", { cause: error });
75
- throw error;
76
- }
77
- }
78
- function cloneRuntimeSchedule(record) {
79
- return {
80
- ...record,
81
- createdAt: new Date(record.createdAt),
82
- ...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
83
- updatedAt: new Date(record.updatedAt)
84
- };
85
- }
86
- function serializeRuntimeSchedule(record) {
87
- return {
88
- ...record,
89
- createdAt: record.createdAt.toISOString(),
90
- ...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
91
- updatedAt: record.updatedAt.toISOString()
92
- };
93
- }
94
- function deserializeRuntimeSchedule(record) {
95
- return {
96
- ...record,
97
- createdAt: new Date(record.createdAt),
98
- ...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
99
- updatedAt: new Date(record.updatedAt)
100
- };
101
- }
102
- function omitUndefinedPatch(patch) {
103
- return {
104
- ...patch.cron !== void 0 ? { cron: patch.cron } : {},
105
- ...patch.enabled !== void 0 ? { enabled: patch.enabled } : {},
106
- ...Object.hasOwn(patch, "input") ? { input: structuredClone(patch.input) } : {},
107
- ...patch.target !== void 0 ? { target: patch.target } : {},
108
- ...patch.timeZone !== void 0 ? { timeZone: patch.timeZone } : {}
109
- };
110
- }
111
- const keyLocks = /* @__PURE__ */ new Map();
112
- async function withKVKeyLock(key, operation) {
113
- const previous = keyLocks.get(key) ?? Promise.resolve();
114
- let release;
115
- const current = new Promise((resolve) => {
116
- release = resolve;
117
- });
118
- const queued = previous.then(() => current, () => current);
119
- keyLocks.set(key, queued);
120
- await previous;
121
- try {
122
- return await operation();
123
- } finally {
124
- release();
125
- if (keyLocks.get(key) === queued) keyLocks.delete(key);
126
- }
127
- }
128
- function createMemoryRuntimeScheduleStore() {
129
- const records = /* @__PURE__ */ new Map();
130
- return {
131
- create(record) {
132
- assertRuntimeScheduleId(record.id);
133
- if (records.has(record.id)) throw createScheduleError("SCHEDULE_ALREADY_EXISTS");
134
- records.set(record.id, cloneRuntimeSchedule(record));
135
- return cloneRuntimeSchedule(record);
136
- },
137
- delete(id) {
138
- return records.delete(id);
139
- },
140
- get(id) {
141
- const record = records.get(id);
142
- return record ? cloneRuntimeSchedule(record) : void 0;
143
- },
144
- list() {
145
- return [...records.values()].map(cloneRuntimeSchedule);
146
- },
147
- update(id, patch) {
148
- const existing = records.get(id);
149
- if (!existing) return;
150
- const next = cloneRuntimeSchedule({
151
- ...existing,
152
- ...omitUndefinedPatch(patch),
153
- updatedAt: patch.updatedAt
154
- });
155
- records.set(id, next);
156
- return cloneRuntimeSchedule(next);
157
- }
158
- };
159
- }
160
- function createKVRuntimeScheduleStore(options = {}) {
161
- const prefix = options.prefix ?? "vitehub:schedule";
162
- async function getKVStore() {
163
- return options.kvStore || await resolveDefaultKVStore();
164
- }
165
- return {
166
- async create(record) {
167
- assertRuntimeScheduleId(record.id);
168
- const store = await getKVStore();
169
- const key = runtimeScheduleKey(prefix, record.id);
170
- return await withKVKeyLock(key, async () => {
171
- if (await store.has(key)) throw createScheduleError("SCHEDULE_ALREADY_EXISTS");
172
- await store.set(key, serializeRuntimeSchedule(record));
173
- return cloneRuntimeSchedule(record);
174
- });
175
- },
176
- async delete(id) {
177
- const store = await getKVStore();
178
- const key = runtimeScheduleKey(prefix, id);
179
- return await withKVKeyLock(key, async () => {
180
- if (!await store.has(key)) return false;
181
- await store.del(key);
182
- return true;
183
- });
184
- },
185
- async get(id) {
186
- const record = await (await getKVStore()).get(runtimeScheduleKey(prefix, id));
187
- return record ? deserializeRuntimeSchedule(record) : void 0;
188
- },
189
- async list() {
190
- const store = await getKVStore();
191
- const keys = await store.keys(runtimeScheduleBase(prefix));
192
- return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((record) => record ? [deserializeRuntimeSchedule(record)] : []);
193
- },
194
- async update(id, patch) {
195
- const store = await getKVStore();
196
- const key = runtimeScheduleKey(prefix, id);
197
- return await withKVKeyLock(key, async () => {
198
- const existing = await store.get(key);
199
- if (!existing) return;
200
- const next = cloneRuntimeSchedule({
201
- ...deserializeRuntimeSchedule(existing),
202
- ...omitUndefinedPatch(patch),
203
- updatedAt: patch.updatedAt
204
- });
205
- await store.set(key, serializeRuntimeSchedule(next));
206
- return cloneRuntimeSchedule(next);
207
- });
208
- }
209
- };
210
- }
211
- function cloneScheduleRun(record) {
212
- return {
213
- ...record,
214
- completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
215
- createdAt: new Date(record.createdAt),
216
- scheduledAt: new Date(record.scheduledAt),
217
- error: record.error ? { ...record.error } : void 0,
218
- startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
219
- updatedAt: new Date(record.updatedAt)
220
- };
221
- }
222
- function cloneScheduleRunAttempt(record) {
223
- return {
224
- ...record,
225
- completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
226
- createdAt: new Date(record.createdAt),
227
- error: record.error ? { ...record.error } : void 0,
228
- startedAt: new Date(record.startedAt),
229
- updatedAt: new Date(record.updatedAt)
230
- };
231
- }
232
- function serializeScheduleRun(record) {
233
- return {
234
- ...record,
235
- completedAt: record.completedAt?.toISOString(),
236
- createdAt: record.createdAt.toISOString(),
237
- error: record.error ? { ...record.error } : void 0,
238
- scheduledAt: record.scheduledAt.toISOString(),
239
- startedAt: record.startedAt?.toISOString(),
240
- updatedAt: record.updatedAt.toISOString()
241
- };
242
- }
243
- function deserializeScheduleRun(record) {
244
- return {
245
- ...record,
246
- completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
247
- createdAt: new Date(record.createdAt),
248
- error: record.error ? { ...record.error } : void 0,
249
- scheduledAt: new Date(record.scheduledAt),
250
- startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
251
- updatedAt: new Date(record.updatedAt)
252
- };
253
- }
254
- function serializeScheduleRunAttempt(record) {
255
- return {
256
- ...record,
257
- completedAt: record.completedAt?.toISOString(),
258
- createdAt: record.createdAt.toISOString(),
259
- error: record.error ? { ...record.error } : void 0,
260
- startedAt: record.startedAt.toISOString(),
261
- updatedAt: record.updatedAt.toISOString()
262
- };
263
- }
264
- function deserializeScheduleRunAttempt(record) {
265
- return {
266
- ...record,
267
- completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
268
- createdAt: new Date(record.createdAt),
269
- error: record.error ? { ...record.error } : void 0,
270
- startedAt: new Date(record.startedAt),
271
- updatedAt: new Date(record.updatedAt)
272
- };
273
- }
274
- function createMemoryScheduleRunStore() {
275
- const runs = /* @__PURE__ */ new Map();
276
- const attempts = /* @__PURE__ */ new Map();
277
- return {
278
- createAttempt(attempt) {
279
- if (attempts.has(attempt.id)) throw new Error(`Schedule Run Attempt already exists: ${attempt.id}`);
280
- attempts.set(attempt.id, cloneScheduleRunAttempt(attempt));
281
- return cloneScheduleRunAttempt(attempt);
282
- },
283
- createRun(run) {
284
- if (runs.has(run.id)) throw new Error(`Schedule Run already exists: ${run.id}`);
285
- runs.set(run.id, cloneScheduleRun(run));
286
- return cloneScheduleRun(run);
287
- },
288
- getAttempt(id) {
289
- const attempt = attempts.get(id);
290
- return attempt ? cloneScheduleRunAttempt(attempt) : void 0;
291
- },
292
- getRun(id) {
293
- const run = runs.get(id);
294
- return run ? cloneScheduleRun(run) : void 0;
295
- },
296
- listAttempts(runId) {
297
- return [...attempts.values()].filter((attempt) => attempt.runId === runId).map(cloneScheduleRunAttempt);
298
- },
299
- listRuns() {
300
- return [...runs.values()].map(cloneScheduleRun);
301
- },
302
- updateAttempt(id, patch) {
303
- const existing = attempts.get(id);
304
- if (!existing) return;
305
- const next = cloneScheduleRunAttempt({
306
- ...existing,
307
- ...patch,
308
- updatedAt: patch.updatedAt
309
- });
310
- attempts.set(id, next);
311
- return cloneScheduleRunAttempt(next);
312
- },
313
- updateRun(id, patch) {
314
- const existing = runs.get(id);
315
- if (!existing) return;
316
- const next = cloneScheduleRun({
317
- ...existing,
318
- ...patch,
319
- updatedAt: patch.updatedAt
320
- });
321
- runs.set(id, next);
322
- return cloneScheduleRun(next);
323
- }
324
- };
325
- }
326
- function createKVScheduleRunStore(options = {}) {
327
- const prefix = options.prefix ?? "vitehub:schedule";
328
- async function getKVStore() {
329
- return options.kvStore || await resolveDefaultKVStore();
330
- }
331
- return {
332
- async createAttempt(attempt) {
333
- const store = await getKVStore();
334
- const key = scheduleRunAttemptKey(prefix, attempt.id);
335
- return await withKVKeyLock(key, async () => {
336
- if (await store.has(key)) throw new Error(`Schedule Run Attempt already exists: ${attempt.id}`);
337
- await store.set(key, serializeScheduleRunAttempt(attempt));
338
- return cloneScheduleRunAttempt(attempt);
339
- });
340
- },
341
- async createRun(run) {
342
- const store = await getKVStore();
343
- const key = scheduleRunKey(prefix, run.id);
344
- return await withKVKeyLock(key, async () => {
345
- if (await store.has(key)) throw new Error(`Schedule Run already exists: ${run.id}`);
346
- await store.set(key, serializeScheduleRun(run));
347
- return cloneScheduleRun(run);
348
- });
349
- },
350
- async getAttempt(id) {
351
- const attempt = await (await getKVStore()).get(scheduleRunAttemptKey(prefix, id));
352
- return attempt ? deserializeScheduleRunAttempt(attempt) : void 0;
353
- },
354
- async getRun(id) {
355
- const run = await (await getKVStore()).get(scheduleRunKey(prefix, id));
356
- return run ? deserializeScheduleRun(run) : void 0;
357
- },
358
- async listAttempts(runId) {
359
- const store = await getKVStore();
360
- const keys = await store.keys(scheduleRunAttemptBase(prefix));
361
- return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((attempt) => attempt && attempt.runId === runId ? [deserializeScheduleRunAttempt(attempt)] : []);
362
- },
363
- async listRuns() {
364
- const store = await getKVStore();
365
- const keys = await store.keys(scheduleRunBase(prefix));
366
- return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((run) => run ? [deserializeScheduleRun(run)] : []);
367
- },
368
- async updateAttempt(id, patch) {
369
- const store = await getKVStore();
370
- const key = scheduleRunAttemptKey(prefix, id);
371
- const existing = await store.get(key);
372
- if (!existing) return;
373
- const next = cloneScheduleRunAttempt({
374
- ...deserializeScheduleRunAttempt(existing),
375
- ...patch,
376
- updatedAt: patch.updatedAt
377
- });
378
- await store.set(key, serializeScheduleRunAttempt(next));
379
- return cloneScheduleRunAttempt(next);
380
- },
381
- async updateRun(id, patch) {
382
- const store = await getKVStore();
383
- const key = scheduleRunKey(prefix, id);
384
- const existing = await store.get(key);
385
- if (!existing) return;
386
- const next = cloneScheduleRun({
387
- ...deserializeScheduleRun(existing),
388
- ...patch,
389
- updatedAt: patch.updatedAt
390
- });
391
- await store.set(key, serializeScheduleRun(next));
392
- return cloneScheduleRun(next);
393
- }
394
- };
395
- }
396
- //#endregion
397
- //#region src/runtime/state.ts
398
- let runtimeRegistry;
399
- let runtimeStore;
400
- let runtimeRegistryVersion = 0;
401
- let runStore;
402
- const loadedRegistryEntries = /* @__PURE__ */ new Map();
403
- const loadingRegistryEntries = /* @__PURE__ */ new Map();
404
- const loadingRegistryStorage = new AsyncLocalStorage();
405
- function isScheduleDefinition(value) {
406
- return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
407
- }
408
- function setScheduleRuntimeRegistry(registry) {
409
- runtimeRegistry = registry;
410
- runtimeRegistryVersion++;
411
- loadedRegistryEntries.clear();
412
- loadingRegistryEntries.clear();
413
- }
414
- function getScheduleRuntimeRegistry() {
415
- return runtimeRegistry;
416
- }
417
- function setRuntimeScheduleStore(store) {
418
- runtimeStore = store;
419
- }
420
- function getRuntimeScheduleStore() {
421
- return runtimeStore ??= createMemoryRuntimeScheduleStore();
422
- }
423
- function setScheduleRunStore(store) {
424
- runStore = store;
425
- }
426
- function getScheduleRunStore() {
427
- return runStore ??= createMemoryScheduleRunStore();
428
- }
429
- async function loadScheduleDefinition(name) {
430
- const entry = runtimeRegistry && Object.hasOwn(runtimeRegistry, name) ? runtimeRegistry[name] : void 0;
431
- if (typeof entry !== "function") return;
432
- if (loadedRegistryEntries.has(name)) return loadedRegistryEntries.get(name);
433
- const activeLoads = loadingRegistryStorage.getStore();
434
- const inFlightEntry = loadingRegistryEntries.get(name);
435
- if (inFlightEntry) {
436
- if (activeLoads?.has(name)) return void 0;
437
- const loaded = await inFlightEntry.promise;
438
- return inFlightEntry.version === runtimeRegistryVersion ? loaded : void 0;
439
- }
440
- const loadingVersion = runtimeRegistryVersion;
441
- const nextActiveLoads = new Set(activeLoads);
442
- nextActiveLoads.add(name);
443
- const loadingEntry = Promise.resolve().then(() => loadingRegistryStorage.run(nextActiveLoads, async () => {
444
- const loaded = await entry();
445
- if (isScheduleDefinition(loaded)) return loaded;
446
- if (loaded && typeof loaded === "object" && "default" in loaded && isScheduleDefinition(loaded.default)) return loaded.default;
447
- }));
448
- loadingRegistryEntries.set(name, {
449
- promise: loadingEntry,
450
- version: loadingVersion
451
- });
452
- try {
453
- const loaded = await loadingEntry;
454
- if (loadingVersion === runtimeRegistryVersion) {
455
- loadedRegistryEntries.set(name, loaded);
456
- return loaded;
457
- }
458
- return;
459
- } finally {
460
- if (loadingRegistryEntries.get(name)?.promise === loadingEntry) loadingRegistryEntries.delete(name);
461
- }
462
- }
463
- function resetScheduleRuntime() {
464
- runtimeRegistry = void 0;
465
- runtimeRegistryVersion++;
466
- runtimeStore = void 0;
467
- runStore = void 0;
468
- loadedRegistryEntries.clear();
469
- loadingRegistryEntries.clear();
470
- }
471
- //#endregion
472
- export { resetScheduleRuntime as a, setScheduleRuntimeRegistry as c, createMemoryRuntimeScheduleStore as d, createMemoryScheduleRunStore as f, invalidScheduleValueDetails as h, loadScheduleDefinition as i, createKVRuntimeScheduleStore as l, createScheduleError as m, getScheduleRunStore as n, setRuntimeScheduleStore as o, assertRuntimeScheduleId as p, getScheduleRuntimeRegistry as r, setScheduleRunStore as s, getRuntimeScheduleStore as t, createKVScheduleRunStore as u };
@@ -1,48 +0,0 @@
1
- import { C as ScheduleTargetName, a as RuntimeScheduleStore, b as ScheduleRunStore, i as RuntimeScheduleRecord, m as ScheduleRunAttemptRecord, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, v as ScheduleRunRecord } from "./types-Bcje4dLV.js";
2
-
3
- //#region src/runtime/client.d.ts
4
- declare function validateRuntimeScheduleCron(cron: unknown): void;
5
- declare const schedules: {
6
- create<TTarget extends ScheduleTargetName, TInput = unknown>(input: RuntimeScheduleCreateInput<TTarget, TInput>): Promise<RuntimeScheduleRecord<TInput>>;
7
- delete(id: string): Promise<boolean>;
8
- disable(id: string): Promise<RuntimeScheduleRecord>;
9
- enable(id: string): Promise<RuntimeScheduleRecord>;
10
- get(id: string): Promise<RuntimeScheduleRecord | undefined>;
11
- getRun(id: string): Promise<ScheduleRunRecord | undefined>;
12
- list(): Promise<RuntimeScheduleRecord[]>;
13
- listAttempts(runId: string): Promise<ScheduleRunAttemptRecord[]>;
14
- listRuns(): Promise<ScheduleRunRecord[]>;
15
- run(id: string, options?: {
16
- scheduledAt?: Date;
17
- }): Promise<ScheduleRunRecord>;
18
- update<TTarget extends ScheduleTargetName, TInput = unknown>(id: string, input: RuntimeScheduleUpdateInput<TTarget, TInput>): Promise<RuntimeScheduleRecord<TInput>>;
19
- };
20
- //#endregion
21
- //#region src/runtime/kv-storage.d.ts
22
- interface ScheduleKVStorage {
23
- del(key: string): boolean | Promise<boolean> | Promise<void> | void;
24
- get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
25
- has(key: string): boolean | Promise<boolean>;
26
- keys(base?: string): Promise<string[]> | string[];
27
- set<T = unknown>(key: string, value: T): Promise<void> | void;
28
- }
29
- interface ViteHubKVStorage {
30
- del(key: string): Promise<readonly [unknown, unknown]>;
31
- get<T = unknown>(key: string): Promise<readonly [unknown, T | null | undefined]>;
32
- has(key: string): Promise<readonly [unknown, boolean | undefined]>;
33
- keys(base?: string): Promise<readonly [unknown, string[] | undefined]>;
34
- set<T = unknown>(key: string, value: T): Promise<readonly [unknown, unknown]>;
35
- }
36
- declare function createScheduleKVStorage(kvStore: ViteHubKVStorage): ScheduleKVStorage;
37
- //#endregion
38
- //#region src/runtime/store.d.ts
39
- interface KVScheduleStoreOptions {
40
- kvStore?: ScheduleKVStorage;
41
- prefix?: string;
42
- }
43
- declare function createMemoryRuntimeScheduleStore(): RuntimeScheduleStore;
44
- declare function createKVRuntimeScheduleStore(options?: KVScheduleStoreOptions): RuntimeScheduleStore;
45
- declare function createMemoryScheduleRunStore(): ScheduleRunStore;
46
- declare function createKVScheduleRunStore(options?: KVScheduleStoreOptions): ScheduleRunStore;
47
- //#endregion
48
- export { createMemoryScheduleRunStore as a, schedules as c, createMemoryRuntimeScheduleStore as i, validateRuntimeScheduleCron as l, createKVRuntimeScheduleStore as n, ScheduleKVStorage as o, createKVScheduleRunStore as r, createScheduleKVStorage as s, KVScheduleStoreOptions as t };
@@ -1,136 +0,0 @@
1
- //#region src/types.d.ts
2
- interface ScheduleRunContext<TInput = unknown> {
3
- id: string;
4
- attemptId?: string;
5
- input?: TInput;
6
- runId?: string;
7
- scheduleId?: string;
8
- scheduledAt: Date;
9
- target?: ScheduleTargetName;
10
- waitUntil(promise: PromiseLike<unknown>): void;
11
- }
12
- type ScheduleHandler<TResult = unknown, TInput = unknown> = {
13
- bivarianceHack(context: ScheduleRunContext<TInput>): TResult | Promise<TResult>;
14
- }["bivarianceHack"];
15
- interface ScheduleDefinitionInput<TResult = unknown> {
16
- allowRuntimeSchedules?: boolean;
17
- cron: string;
18
- handler: ScheduleHandler<TResult>;
19
- }
20
- interface ScheduleDefinitionOptions {
21
- allowRuntimeSchedules?: boolean;
22
- }
23
- interface ScheduleDefinition<TResult = unknown> {
24
- cron: string;
25
- handler: ScheduleHandler<TResult>;
26
- options?: ScheduleDefinitionOptions;
27
- }
28
- interface ScheduleTargetDefinitionInput<TInput = unknown, TResult = unknown> {
29
- handler: ScheduleHandler<TResult, TInput>;
30
- }
31
- interface ScheduleTargetDefinition<TInput = unknown, TResult = unknown> {
32
- handler: ScheduleHandler<TResult, TInput>;
33
- options: {
34
- allowRuntimeSchedules: true;
35
- };
36
- }
37
- type ScheduleRegistryDefinition = ScheduleDefinition | ScheduleTargetDefinition;
38
- interface ScheduleDefinitionRegistry {
39
- [name: string]: () => Promise<{
40
- default?: ScheduleRegistryDefinition;
41
- } | ScheduleRegistryDefinition>;
42
- }
43
- type ScheduleTargetName = string & {};
44
- interface RuntimeScheduleMetadata {
45
- createdAt: Date;
46
- updatedAt: Date;
47
- }
48
- interface RuntimeScheduleRecord<TInput = unknown> extends RuntimeScheduleMetadata {
49
- cron: string;
50
- enabled: boolean;
51
- id: string;
52
- input?: TInput;
53
- target: ScheduleTargetName;
54
- timeZone?: string;
55
- }
56
- interface RuntimeScheduleWake {
57
- scheduleId: string;
58
- scheduledAt: Date;
59
- }
60
- interface RuntimeScheduleCreateInput<TTarget extends ScheduleTargetName = ScheduleTargetName, TInput = unknown> {
61
- cron: string;
62
- enabled?: boolean;
63
- id?: string;
64
- input?: TInput;
65
- target: TTarget;
66
- timeZone?: string;
67
- }
68
- interface RuntimeScheduleUpdateInput<TTarget extends ScheduleTargetName = ScheduleTargetName, TInput = unknown> {
69
- cron?: string;
70
- enabled?: boolean;
71
- input?: TInput;
72
- target?: TTarget;
73
- timeZone?: string;
74
- }
75
- interface RuntimeScheduleStore {
76
- create: (record: RuntimeScheduleRecord) => Promise<RuntimeScheduleRecord> | RuntimeScheduleRecord;
77
- delete: (id: string) => Promise<boolean> | boolean;
78
- get: (id: string) => Promise<RuntimeScheduleRecord | undefined> | RuntimeScheduleRecord | undefined;
79
- list: () => Promise<RuntimeScheduleRecord[]> | RuntimeScheduleRecord[];
80
- update: (id: string, patch: RuntimeScheduleUpdateInput & {
81
- updatedAt: Date;
82
- }) => Promise<RuntimeScheduleRecord | undefined> | RuntimeScheduleRecord | undefined;
83
- }
84
- type ScheduleRunStatus = "pending" | "running" | "succeeded" | "failed";
85
- type ScheduleRunAttemptStatus = "running" | "succeeded" | "failed";
86
- interface ScheduleRunError {
87
- message: string;
88
- name?: string;
89
- stack?: string;
90
- }
91
- interface ScheduleRunRecord {
92
- attemptCount: number;
93
- completedAt?: Date;
94
- createdAt: Date;
95
- error?: ScheduleRunError;
96
- id: string;
97
- scheduleId: string;
98
- scheduledAt: Date;
99
- startedAt?: Date;
100
- status: ScheduleRunStatus;
101
- target: ScheduleTargetName;
102
- updatedAt: Date;
103
- }
104
- interface ScheduleRunAttemptRecord {
105
- completedAt?: Date;
106
- createdAt: Date;
107
- error?: ScheduleRunError;
108
- id: string;
109
- runId: string;
110
- startedAt: Date;
111
- status: ScheduleRunAttemptStatus;
112
- updatedAt: Date;
113
- }
114
- interface ScheduleRunStore {
115
- createAttempt: (attempt: ScheduleRunAttemptRecord) => Promise<ScheduleRunAttemptRecord> | ScheduleRunAttemptRecord;
116
- createRun: (run: ScheduleRunRecord) => Promise<ScheduleRunRecord> | ScheduleRunRecord;
117
- getAttempt: (id: string) => Promise<ScheduleRunAttemptRecord | undefined> | ScheduleRunAttemptRecord | undefined;
118
- getRun: (id: string) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
119
- listAttempts: (runId: string) => Promise<ScheduleRunAttemptRecord[]> | ScheduleRunAttemptRecord[];
120
- listRuns: () => Promise<ScheduleRunRecord[]> | ScheduleRunRecord[];
121
- updateAttempt: (id: string, patch: Partial<Pick<ScheduleRunAttemptRecord, "completedAt" | "error" | "status">> & {
122
- updatedAt: Date;
123
- }) => Promise<ScheduleRunAttemptRecord | undefined> | ScheduleRunAttemptRecord | undefined;
124
- updateRun: (id: string, patch: Partial<Pick<ScheduleRunRecord, "attemptCount" | "completedAt" | "error" | "startedAt" | "status">> & {
125
- updatedAt: Date;
126
- }) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
127
- }
128
- interface DiscoveredScheduleDefinition {
129
- allowRuntimeSchedules?: boolean;
130
- handler: string;
131
- name: string;
132
- runtimeOnly?: boolean;
133
- source?: "server-schedules" | "vite-suffix";
134
- }
135
- //#endregion
136
- export { ScheduleTargetName as C, ScheduleTargetDefinitionInput as S, ScheduleRunError as _, RuntimeScheduleStore as a, ScheduleRunStore as b, ScheduleDefinition as c, ScheduleDefinitionRegistry as d, ScheduleHandler as f, ScheduleRunContext as g, ScheduleRunAttemptStatus as h, RuntimeScheduleRecord as i, ScheduleDefinitionInput as l, ScheduleRunAttemptRecord as m, RuntimeScheduleCreateInput as n, RuntimeScheduleUpdateInput as o, ScheduleRegistryDefinition as p, RuntimeScheduleMetadata as r, RuntimeScheduleWake as s, DiscoveredScheduleDefinition as t, ScheduleDefinitionOptions as u, ScheduleRunRecord as v, ScheduleTargetDefinition as x, ScheduleRunStatus as y };