@vite-hub/schedule 0.0.0 → 0.0.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.
@@ -0,0 +1,6 @@
1
+ import { NitroModule } from "nitro/types";
2
+
3
+ //#region src/nitro/module.d.ts
4
+ declare const scheduleNitroModule: NitroModule;
5
+ //#endregion
6
+ export { scheduleNitroModule as default };
package/dist/nitro.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as scheduleNitroModule } from "./module-C_j2ahfg.js";
2
+ export { scheduleNitroModule as default };
@@ -0,0 +1,9 @@
1
+ declare module "#vitehub/schedule/registry" {
2
+ const registry: import("@vite-hub/schedule").ScheduleDefinitionRegistry
3
+ export default registry
4
+ }
5
+
6
+ declare module "#vitehub/schedule/targets" {
7
+ export const scheduleTargetNames: import("@vite-hub/schedule").ScheduleTargetName[]
8
+ export type ScheduleTargetName = import("@vite-hub/schedule").ScheduleTargetName
9
+ }
@@ -0,0 +1,13 @@
1
+ import { a as RuntimeScheduleStore, s as ScheduleDefinition, u as ScheduleDefinitionRegistry, v as ScheduleRunStore } from "../types-DOjXDq0s.js";
2
+
3
+ //#region src/runtime/state.d.ts
4
+ declare function setScheduleRuntimeRegistry(registry: ScheduleDefinitionRegistry | undefined): void;
5
+ declare function getScheduleRuntimeRegistry(): ScheduleDefinitionRegistry | undefined;
6
+ declare function setRuntimeScheduleStore(store: RuntimeScheduleStore | undefined): void;
7
+ declare function getRuntimeScheduleStore(): RuntimeScheduleStore;
8
+ declare function setScheduleRunStore(store: ScheduleRunStore | undefined): void;
9
+ declare function getScheduleRunStore(): ScheduleRunStore;
10
+ declare function loadScheduleDefinition(name: string): Promise<ScheduleDefinition | undefined>;
11
+ declare function resetScheduleRuntime(): void;
12
+ //#endregion
13
+ export { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry };
@@ -0,0 +1,2 @@
1
+ import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, i as loadScheduleDefinition, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore } from "../state-DoONzfij.js";
2
+ export { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry };
@@ -0,0 +1,17 @@
1
+ import { m as ScheduleRunContext, s as ScheduleDefinition } from "../types-DOjXDq0s.js";
2
+
3
+ //#region src/runtime/static.d.ts
4
+ interface ExecuteStaticScheduleOptions {
5
+ cron: string;
6
+ definition: ScheduleDefinition;
7
+ name: string;
8
+ scheduledAt?: Date;
9
+ }
10
+ interface StaticScheduleRun extends ScheduleRunContext {
11
+ cron: string;
12
+ scheduleId: string;
13
+ }
14
+ declare function createStaticScheduleRun(options: Omit<ExecuteStaticScheduleOptions, "definition">): StaticScheduleRun;
15
+ declare function executeStaticSchedule(options: ExecuteStaticScheduleOptions): Promise<unknown>;
16
+ //#endregion
17
+ export { ExecuteStaticScheduleOptions, StaticScheduleRun, createStaticScheduleRun, executeStaticSchedule };
@@ -0,0 +1,15 @@
1
+ //#region src/runtime/static.ts
2
+ function createStaticScheduleRun(options) {
3
+ const scheduledAt = options.scheduledAt ?? /* @__PURE__ */ new Date();
4
+ return {
5
+ cron: options.cron,
6
+ id: `run_${options.name}_${scheduledAt.toISOString()}`,
7
+ scheduleId: options.name,
8
+ scheduledAt
9
+ };
10
+ }
11
+ async function executeStaticSchedule(options) {
12
+ return await options.definition.handler(createStaticScheduleRun(options));
13
+ }
14
+ //#endregion
15
+ export { createStaticScheduleRun, executeStaticSchedule };
@@ -0,0 +1,4 @@
1
+ import { a as RuntimeScheduleStore, d as ScheduleHandler, i as RuntimeScheduleRecord, l as ScheduleDefinitionOptions, m as ScheduleRunContext, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, r as RuntimeScheduleMetadata, s as ScheduleDefinition, u as ScheduleDefinitionRegistry, y as ScheduleTargetName } from "./types-DOjXDq0s.js";
2
+ import { a as createMemoryRuntimeScheduleStore, c as validateRuntimeScheduleCron, l as ScheduleError, s as schedules } from "./store-CeeSsInC.js";
3
+ import { getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRuntimeRegistry } from "./runtime/state.js";
4
+ export { type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionOptions, type ScheduleDefinitionRegistry, ScheduleError, type ScheduleHandler, type ScheduleRunContext, type ScheduleTargetName, createMemoryRuntimeScheduleStore, getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
@@ -0,0 +1,3 @@
1
+ import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, i as loadScheduleDefinition, o as setRuntimeScheduleStore, p as ScheduleError, r as getScheduleRuntimeRegistry, t as getRuntimeScheduleStore } from "./state-DoONzfij.js";
2
+ import { n as validateRuntimeScheduleCron, t as schedules } from "./client-BJ33CRLg.js";
3
+ export { ScheduleError, createMemoryRuntimeScheduleStore, getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
@@ -0,0 +1,441 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ //#region src/errors.ts
3
+ var ScheduleError = class extends Error {
4
+ code;
5
+ details;
6
+ httpStatus;
7
+ constructor(message, options = {}) {
8
+ super(message, { cause: options.cause });
9
+ this.name = "ScheduleError";
10
+ this.code = options.code;
11
+ this.details = options.details;
12
+ this.httpStatus = options.httpStatus;
13
+ }
14
+ };
15
+ //#endregion
16
+ //#region src/runtime/store.ts
17
+ function trimPrefix(prefix) {
18
+ return prefix.replace(/^\/+|\/+$/g, "");
19
+ }
20
+ function joinKey(prefix, ...parts) {
21
+ const base = trimPrefix(prefix);
22
+ const suffix = parts.map(encodeURIComponent).join("/");
23
+ return base ? `${base}/${suffix}` : suffix;
24
+ }
25
+ function runtimeScheduleKey(prefix, id) {
26
+ return joinKey(prefix, "runtime-schedules", id);
27
+ }
28
+ function scheduleRunKey(prefix, id) {
29
+ return joinKey(prefix, "schedule-runs", id);
30
+ }
31
+ function scheduleRunAttemptKey(prefix, id) {
32
+ return joinKey(prefix, "schedule-run-attempts", id);
33
+ }
34
+ function runtimeScheduleBase(prefix) {
35
+ return joinKey(prefix, "runtime-schedules");
36
+ }
37
+ function scheduleRunBase(prefix) {
38
+ return joinKey(prefix, "schedule-runs");
39
+ }
40
+ function scheduleRunAttemptBase(prefix) {
41
+ return joinKey(prefix, "schedule-run-attempts");
42
+ }
43
+ async function resolveDefaultKVStore() {
44
+ return (await import("@vite-hub/kv")).kv;
45
+ }
46
+ function cloneRuntimeSchedule(record) {
47
+ return {
48
+ ...record,
49
+ createdAt: new Date(record.createdAt),
50
+ updatedAt: new Date(record.updatedAt)
51
+ };
52
+ }
53
+ function serializeRuntimeSchedule(record) {
54
+ return {
55
+ ...record,
56
+ createdAt: record.createdAt.toISOString(),
57
+ updatedAt: record.updatedAt.toISOString()
58
+ };
59
+ }
60
+ function deserializeRuntimeSchedule(record) {
61
+ return {
62
+ ...record,
63
+ createdAt: new Date(record.createdAt),
64
+ updatedAt: new Date(record.updatedAt)
65
+ };
66
+ }
67
+ function omitUndefinedPatch(patch) {
68
+ return {
69
+ ...patch.cron !== void 0 ? { cron: patch.cron } : {},
70
+ ...patch.enabled !== void 0 ? { enabled: patch.enabled } : {},
71
+ ...patch.target !== void 0 ? { target: patch.target } : {}
72
+ };
73
+ }
74
+ const keyLocks = /* @__PURE__ */ new Map();
75
+ async function withKVKeyLock(key, operation) {
76
+ const previous = keyLocks.get(key) ?? Promise.resolve();
77
+ let release;
78
+ const current = new Promise((resolve) => {
79
+ release = resolve;
80
+ });
81
+ const queued = previous.then(() => current, () => current);
82
+ keyLocks.set(key, queued);
83
+ await previous;
84
+ try {
85
+ return await operation();
86
+ } finally {
87
+ release();
88
+ if (keyLocks.get(key) === queued) keyLocks.delete(key);
89
+ }
90
+ }
91
+ function createMemoryRuntimeScheduleStore() {
92
+ const records = /* @__PURE__ */ new Map();
93
+ return {
94
+ create(record) {
95
+ if (records.has(record.id)) throw new ScheduleError(`Runtime Schedule already exists: ${record.id}`, {
96
+ code: "SCHEDULE_ALREADY_EXISTS",
97
+ details: { id: record.id },
98
+ httpStatus: 409
99
+ });
100
+ records.set(record.id, cloneRuntimeSchedule(record));
101
+ return cloneRuntimeSchedule(record);
102
+ },
103
+ delete(id) {
104
+ return records.delete(id);
105
+ },
106
+ get(id) {
107
+ const record = records.get(id);
108
+ return record ? cloneRuntimeSchedule(record) : void 0;
109
+ },
110
+ list() {
111
+ return [...records.values()].map(cloneRuntimeSchedule);
112
+ },
113
+ update(id, patch) {
114
+ const existing = records.get(id);
115
+ if (!existing) return;
116
+ const next = cloneRuntimeSchedule({
117
+ ...existing,
118
+ ...omitUndefinedPatch(patch),
119
+ updatedAt: patch.updatedAt
120
+ });
121
+ records.set(id, next);
122
+ return cloneRuntimeSchedule(next);
123
+ }
124
+ };
125
+ }
126
+ function createKVRuntimeScheduleStore(options = {}) {
127
+ const prefix = options.prefix ?? "vitehub:schedule";
128
+ async function getKVStore() {
129
+ return options.kvStore || await resolveDefaultKVStore();
130
+ }
131
+ return {
132
+ async create(record) {
133
+ const store = await getKVStore();
134
+ const key = runtimeScheduleKey(prefix, record.id);
135
+ return await withKVKeyLock(key, async () => {
136
+ if (await store.has(key)) throw new ScheduleError(`Runtime Schedule already exists: ${record.id}`, {
137
+ code: "SCHEDULE_ALREADY_EXISTS",
138
+ details: { id: record.id },
139
+ httpStatus: 409
140
+ });
141
+ await store.set(key, serializeRuntimeSchedule(record));
142
+ return cloneRuntimeSchedule(record);
143
+ });
144
+ },
145
+ async delete(id) {
146
+ const store = await getKVStore();
147
+ const key = runtimeScheduleKey(prefix, id);
148
+ return await withKVKeyLock(key, async () => {
149
+ if (!await store.has(key)) return false;
150
+ await store.del(key);
151
+ return true;
152
+ });
153
+ },
154
+ async get(id) {
155
+ const record = await (await getKVStore()).get(runtimeScheduleKey(prefix, id));
156
+ return record ? deserializeRuntimeSchedule(record) : void 0;
157
+ },
158
+ async list() {
159
+ const store = await getKVStore();
160
+ const keys = await store.keys(runtimeScheduleBase(prefix));
161
+ return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((record) => record ? [deserializeRuntimeSchedule(record)] : []);
162
+ },
163
+ async update(id, patch) {
164
+ const store = await getKVStore();
165
+ const key = runtimeScheduleKey(prefix, id);
166
+ return await withKVKeyLock(key, async () => {
167
+ const existing = await store.get(key);
168
+ if (!existing) return;
169
+ const next = cloneRuntimeSchedule({
170
+ ...deserializeRuntimeSchedule(existing),
171
+ ...omitUndefinedPatch(patch),
172
+ updatedAt: patch.updatedAt
173
+ });
174
+ await store.set(key, serializeRuntimeSchedule(next));
175
+ return cloneRuntimeSchedule(next);
176
+ });
177
+ }
178
+ };
179
+ }
180
+ function cloneScheduleRun(record) {
181
+ return {
182
+ ...record,
183
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
184
+ createdAt: new Date(record.createdAt),
185
+ scheduledAt: new Date(record.scheduledAt),
186
+ error: record.error ? { ...record.error } : void 0,
187
+ startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
188
+ updatedAt: new Date(record.updatedAt)
189
+ };
190
+ }
191
+ function cloneScheduleRunAttempt(record) {
192
+ return {
193
+ ...record,
194
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
195
+ createdAt: new Date(record.createdAt),
196
+ error: record.error ? { ...record.error } : void 0,
197
+ startedAt: new Date(record.startedAt),
198
+ updatedAt: new Date(record.updatedAt)
199
+ };
200
+ }
201
+ function serializeScheduleRun(record) {
202
+ return {
203
+ ...record,
204
+ completedAt: record.completedAt?.toISOString(),
205
+ createdAt: record.createdAt.toISOString(),
206
+ error: record.error ? { ...record.error } : void 0,
207
+ scheduledAt: record.scheduledAt.toISOString(),
208
+ startedAt: record.startedAt?.toISOString(),
209
+ updatedAt: record.updatedAt.toISOString()
210
+ };
211
+ }
212
+ function deserializeScheduleRun(record) {
213
+ return {
214
+ ...record,
215
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
216
+ createdAt: new Date(record.createdAt),
217
+ error: record.error ? { ...record.error } : void 0,
218
+ scheduledAt: new Date(record.scheduledAt),
219
+ startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
220
+ updatedAt: new Date(record.updatedAt)
221
+ };
222
+ }
223
+ function serializeScheduleRunAttempt(record) {
224
+ return {
225
+ ...record,
226
+ completedAt: record.completedAt?.toISOString(),
227
+ createdAt: record.createdAt.toISOString(),
228
+ error: record.error ? { ...record.error } : void 0,
229
+ startedAt: record.startedAt.toISOString(),
230
+ updatedAt: record.updatedAt.toISOString()
231
+ };
232
+ }
233
+ function deserializeScheduleRunAttempt(record) {
234
+ return {
235
+ ...record,
236
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
237
+ createdAt: new Date(record.createdAt),
238
+ error: record.error ? { ...record.error } : void 0,
239
+ startedAt: new Date(record.startedAt),
240
+ updatedAt: new Date(record.updatedAt)
241
+ };
242
+ }
243
+ function createMemoryScheduleRunStore() {
244
+ const runs = /* @__PURE__ */ new Map();
245
+ const attempts = /* @__PURE__ */ new Map();
246
+ return {
247
+ createAttempt(attempt) {
248
+ if (attempts.has(attempt.id)) throw new Error(`Schedule Run Attempt already exists: ${attempt.id}`);
249
+ attempts.set(attempt.id, cloneScheduleRunAttempt(attempt));
250
+ return cloneScheduleRunAttempt(attempt);
251
+ },
252
+ createRun(run) {
253
+ if (runs.has(run.id)) throw new Error(`Schedule Run already exists: ${run.id}`);
254
+ runs.set(run.id, cloneScheduleRun(run));
255
+ return cloneScheduleRun(run);
256
+ },
257
+ getAttempt(id) {
258
+ const attempt = attempts.get(id);
259
+ return attempt ? cloneScheduleRunAttempt(attempt) : void 0;
260
+ },
261
+ getRun(id) {
262
+ const run = runs.get(id);
263
+ return run ? cloneScheduleRun(run) : void 0;
264
+ },
265
+ listAttempts(runId) {
266
+ return [...attempts.values()].filter((attempt) => attempt.runId === runId).map(cloneScheduleRunAttempt);
267
+ },
268
+ listRuns() {
269
+ return [...runs.values()].map(cloneScheduleRun);
270
+ },
271
+ updateAttempt(id, patch) {
272
+ const existing = attempts.get(id);
273
+ if (!existing) return;
274
+ const next = cloneScheduleRunAttempt({
275
+ ...existing,
276
+ ...patch,
277
+ updatedAt: patch.updatedAt
278
+ });
279
+ attempts.set(id, next);
280
+ return cloneScheduleRunAttempt(next);
281
+ },
282
+ updateRun(id, patch) {
283
+ const existing = runs.get(id);
284
+ if (!existing) return;
285
+ const next = cloneScheduleRun({
286
+ ...existing,
287
+ ...patch,
288
+ updatedAt: patch.updatedAt
289
+ });
290
+ runs.set(id, next);
291
+ return cloneScheduleRun(next);
292
+ }
293
+ };
294
+ }
295
+ function createKVScheduleRunStore(options = {}) {
296
+ const prefix = options.prefix ?? "vitehub:schedule";
297
+ async function getKVStore() {
298
+ return options.kvStore || await resolveDefaultKVStore();
299
+ }
300
+ return {
301
+ async createAttempt(attempt) {
302
+ const store = await getKVStore();
303
+ const key = scheduleRunAttemptKey(prefix, attempt.id);
304
+ return await withKVKeyLock(key, async () => {
305
+ if (await store.has(key)) throw new Error(`Schedule Run Attempt already exists: ${attempt.id}`);
306
+ await store.set(key, serializeScheduleRunAttempt(attempt));
307
+ return cloneScheduleRunAttempt(attempt);
308
+ });
309
+ },
310
+ async createRun(run) {
311
+ const store = await getKVStore();
312
+ const key = scheduleRunKey(prefix, run.id);
313
+ return await withKVKeyLock(key, async () => {
314
+ if (await store.has(key)) throw new Error(`Schedule Run already exists: ${run.id}`);
315
+ await store.set(key, serializeScheduleRun(run));
316
+ return cloneScheduleRun(run);
317
+ });
318
+ },
319
+ async getAttempt(id) {
320
+ const attempt = await (await getKVStore()).get(scheduleRunAttemptKey(prefix, id));
321
+ return attempt ? deserializeScheduleRunAttempt(attempt) : void 0;
322
+ },
323
+ async getRun(id) {
324
+ const run = await (await getKVStore()).get(scheduleRunKey(prefix, id));
325
+ return run ? deserializeScheduleRun(run) : void 0;
326
+ },
327
+ async listAttempts(runId) {
328
+ const store = await getKVStore();
329
+ const keys = await store.keys(scheduleRunAttemptBase(prefix));
330
+ return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((attempt) => attempt && attempt.runId === runId ? [deserializeScheduleRunAttempt(attempt)] : []);
331
+ },
332
+ async listRuns() {
333
+ const store = await getKVStore();
334
+ const keys = await store.keys(scheduleRunBase(prefix));
335
+ return (await Promise.all(keys.map((key) => store.get(key)))).flatMap((run) => run ? [deserializeScheduleRun(run)] : []);
336
+ },
337
+ async updateAttempt(id, patch) {
338
+ const store = await getKVStore();
339
+ const key = scheduleRunAttemptKey(prefix, id);
340
+ const existing = await store.get(key);
341
+ if (!existing) return;
342
+ const next = cloneScheduleRunAttempt({
343
+ ...deserializeScheduleRunAttempt(existing),
344
+ ...patch,
345
+ updatedAt: patch.updatedAt
346
+ });
347
+ await store.set(key, serializeScheduleRunAttempt(next));
348
+ return cloneScheduleRunAttempt(next);
349
+ },
350
+ async updateRun(id, patch) {
351
+ const store = await getKVStore();
352
+ const key = scheduleRunKey(prefix, id);
353
+ const existing = await store.get(key);
354
+ if (!existing) return;
355
+ const next = cloneScheduleRun({
356
+ ...deserializeScheduleRun(existing),
357
+ ...patch,
358
+ updatedAt: patch.updatedAt
359
+ });
360
+ await store.set(key, serializeScheduleRun(next));
361
+ return cloneScheduleRun(next);
362
+ }
363
+ };
364
+ }
365
+ //#endregion
366
+ //#region src/runtime/state.ts
367
+ let runtimeRegistry;
368
+ let runtimeStore;
369
+ let runtimeRegistryVersion = 0;
370
+ let runStore;
371
+ const loadedRegistryEntries = /* @__PURE__ */ new Map();
372
+ const loadingRegistryEntries = /* @__PURE__ */ new Map();
373
+ const loadingRegistryStorage = new AsyncLocalStorage();
374
+ function isScheduleDefinition(value) {
375
+ return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
376
+ }
377
+ function setScheduleRuntimeRegistry(registry) {
378
+ runtimeRegistry = registry;
379
+ runtimeRegistryVersion++;
380
+ loadedRegistryEntries.clear();
381
+ loadingRegistryEntries.clear();
382
+ }
383
+ function getScheduleRuntimeRegistry() {
384
+ return runtimeRegistry;
385
+ }
386
+ function setRuntimeScheduleStore(store) {
387
+ runtimeStore = store;
388
+ }
389
+ function getRuntimeScheduleStore() {
390
+ return runtimeStore ??= createMemoryRuntimeScheduleStore();
391
+ }
392
+ function setScheduleRunStore(store) {
393
+ runStore = store;
394
+ }
395
+ function getScheduleRunStore() {
396
+ return runStore ??= createMemoryScheduleRunStore();
397
+ }
398
+ async function loadScheduleDefinition(name) {
399
+ const entry = runtimeRegistry && Object.hasOwn(runtimeRegistry, name) ? runtimeRegistry[name] : void 0;
400
+ if (typeof entry !== "function") return;
401
+ if (loadedRegistryEntries.has(name)) return loadedRegistryEntries.get(name);
402
+ const activeLoads = loadingRegistryStorage.getStore();
403
+ const inFlightEntry = loadingRegistryEntries.get(name);
404
+ if (inFlightEntry) {
405
+ if (activeLoads?.has(name)) return void 0;
406
+ const loaded = await inFlightEntry.promise;
407
+ return inFlightEntry.version === runtimeRegistryVersion ? loaded : void 0;
408
+ }
409
+ const loadingVersion = runtimeRegistryVersion;
410
+ const nextActiveLoads = new Set(activeLoads);
411
+ nextActiveLoads.add(name);
412
+ const loadingEntry = Promise.resolve().then(() => loadingRegistryStorage.run(nextActiveLoads, async () => {
413
+ const loaded = await entry();
414
+ if (isScheduleDefinition(loaded)) return loaded;
415
+ if (loaded && typeof loaded === "object" && "default" in loaded && isScheduleDefinition(loaded.default)) return loaded.default;
416
+ }));
417
+ loadingRegistryEntries.set(name, {
418
+ promise: loadingEntry,
419
+ version: loadingVersion
420
+ });
421
+ try {
422
+ const loaded = await loadingEntry;
423
+ if (loadingVersion === runtimeRegistryVersion) {
424
+ loadedRegistryEntries.set(name, loaded);
425
+ return loaded;
426
+ }
427
+ return;
428
+ } finally {
429
+ if (loadingRegistryEntries.get(name)?.promise === loadingEntry) loadingRegistryEntries.delete(name);
430
+ }
431
+ }
432
+ function resetScheduleRuntime() {
433
+ runtimeRegistry = void 0;
434
+ runtimeRegistryVersion++;
435
+ runtimeStore = void 0;
436
+ runStore = void 0;
437
+ loadedRegistryEntries.clear();
438
+ loadingRegistryEntries.clear();
439
+ }
440
+ //#endregion
441
+ export { resetScheduleRuntime as a, setScheduleRuntimeRegistry as c, createMemoryRuntimeScheduleStore as d, createMemoryScheduleRunStore as f, loadScheduleDefinition as i, createKVRuntimeScheduleStore as l, getScheduleRunStore as n, setRuntimeScheduleStore as o, ScheduleError as p, getScheduleRuntimeRegistry as r, setScheduleRunStore as s, getRuntimeScheduleStore as t, createKVScheduleRunStore as u };
@@ -0,0 +1,63 @@
1
+ import { a as RuntimeScheduleStore, f as ScheduleRunAttemptRecord, g as ScheduleRunRecord, i as RuntimeScheduleRecord, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, v as ScheduleRunStore, y as ScheduleTargetName } from "./types-DOjXDq0s.js";
2
+ import * as _$_vite_hub_schedule0 from "@vite-hub/schedule";
3
+
4
+ //#region src/registry-module.d.ts
5
+ declare module "#vitehub/schedule/registry" {
6
+ const registry: _$_vite_hub_schedule0.ScheduleDefinitionRegistry;
7
+ export default registry;
8
+ }
9
+ declare module "#vitehub/schedule/targets" {
10
+ export const scheduleTargetNames: _$_vite_hub_schedule0.ScheduleTargetName[];
11
+ export type ScheduleTargetName = _$_vite_hub_schedule0.ScheduleTargetName;
12
+ }
13
+ //#endregion
14
+ //#region src/errors.d.ts
15
+ interface ScheduleErrorOptions {
16
+ cause?: unknown;
17
+ code?: string;
18
+ details?: unknown;
19
+ httpStatus?: number;
20
+ }
21
+ declare class ScheduleError extends Error {
22
+ code?: string;
23
+ details?: unknown;
24
+ httpStatus?: number;
25
+ constructor(message: string, options?: ScheduleErrorOptions);
26
+ }
27
+ //#endregion
28
+ //#region src/runtime/client.d.ts
29
+ declare function validateRuntimeScheduleCron(cron: unknown): void;
30
+ declare const schedules: {
31
+ create<TTarget extends ScheduleTargetName>(input: RuntimeScheduleCreateInput<TTarget>): Promise<RuntimeScheduleRecord>;
32
+ delete(id: string): Promise<boolean>;
33
+ disable(id: string): Promise<RuntimeScheduleRecord>;
34
+ enable(id: string): Promise<RuntimeScheduleRecord>;
35
+ get(id: string): Promise<RuntimeScheduleRecord | undefined>;
36
+ getRun(id: string): Promise<ScheduleRunRecord | undefined>;
37
+ list(): Promise<RuntimeScheduleRecord[]>;
38
+ listAttempts(runId: string): Promise<ScheduleRunAttemptRecord[]>;
39
+ listRuns(): Promise<ScheduleRunRecord[]>;
40
+ run(id: string, options?: {
41
+ scheduledAt?: Date;
42
+ }): Promise<ScheduleRunRecord>;
43
+ update<TTarget extends ScheduleTargetName>(id: string, input: RuntimeScheduleUpdateInput<TTarget>): Promise<RuntimeScheduleRecord>;
44
+ };
45
+ //#endregion
46
+ //#region src/runtime/store.d.ts
47
+ interface ScheduleKVStorage {
48
+ del(key: string): boolean | Promise<boolean> | Promise<void> | void;
49
+ get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
50
+ has(key: string): boolean | Promise<boolean>;
51
+ keys(base?: string): Promise<string[]> | string[];
52
+ set<T = unknown>(key: string, value: T): Promise<void> | void;
53
+ }
54
+ interface KVScheduleStoreOptions {
55
+ kvStore?: ScheduleKVStorage;
56
+ prefix?: string;
57
+ }
58
+ declare function createMemoryRuntimeScheduleStore(): RuntimeScheduleStore;
59
+ declare function createKVRuntimeScheduleStore(options?: KVScheduleStoreOptions): RuntimeScheduleStore;
60
+ declare function createMemoryScheduleRunStore(): ScheduleRunStore;
61
+ declare function createKVScheduleRunStore(options?: KVScheduleStoreOptions): ScheduleRunStore;
62
+ //#endregion
63
+ export { createMemoryRuntimeScheduleStore as a, validateRuntimeScheduleCron as c, createKVScheduleRunStore as i, ScheduleError as l, ScheduleKVStorage as n, createMemoryScheduleRunStore as o, createKVRuntimeScheduleStore as r, schedules as s, KVScheduleStoreOptions as t };