@vite-hub/schedule 0.0.4 → 0.3.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 (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -0,0 +1,468 @@
1
+ import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
2
+ import { t as scheduleErrorDiagnostics } from "./error-diagnostics-Mpeks7J0.js";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ //#region src/runtime/store.ts
5
+ const maxLegacyHistoryRecords = 1e3;
6
+ function trimPrefix(prefix) {
7
+ return prefix.replace(/^\/+|\/+$/g, "");
8
+ }
9
+ /**
10
+ * Decoded trailing segments of a listed key. Some KV stores, such as unstorage, list keys with `:` instead of `/`.
11
+ * Encoded parts contain neither, so both separators are safe to split on.
12
+ */
13
+ function keySegments(key, count) {
14
+ return key.split(/[/:]/).slice(-count).map(decodeURIComponent);
15
+ }
16
+ function joinKey(prefix, ...parts) {
17
+ const base = trimPrefix(prefix);
18
+ const suffix = parts.map(encodeURIComponent).join("/");
19
+ return base ? `${base}/${suffix}` : suffix;
20
+ }
21
+ function scheduleRunKey(prefix, id) {
22
+ return joinKey(prefix, "schedule-runs", id);
23
+ }
24
+ function scheduleRunAttemptKey(prefix, id) {
25
+ return joinKey(prefix, "schedule-run-attempts", id);
26
+ }
27
+ function scheduleRunBase(prefix) {
28
+ return `${joinKey(prefix, "schedule-runs")}/`;
29
+ }
30
+ function scheduleRunAttemptBase(prefix) {
31
+ return `${joinKey(prefix, "schedule-run-attempts")}/`;
32
+ }
33
+ const keyLocks = /* @__PURE__ */ new Map();
34
+ async function withKVKeyLock(key, operation) {
35
+ const previous = keyLocks.get(key) ?? Promise.resolve();
36
+ let release;
37
+ const current = new Promise((resolve) => {
38
+ release = resolve;
39
+ });
40
+ const queued = previous.then(() => current, () => current);
41
+ keyLocks.set(key, queued);
42
+ await previous;
43
+ try {
44
+ return await operation();
45
+ } finally {
46
+ release();
47
+ if (keyLocks.get(key) === queued) keyLocks.delete(key);
48
+ }
49
+ }
50
+ function cloneScheduleRun(record) {
51
+ return {
52
+ ...record,
53
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
54
+ createdAt: new Date(record.createdAt),
55
+ error: record.error ? { ...record.error } : void 0,
56
+ response: record.response ? structuredClone(record.response) : void 0,
57
+ scheduledAt: new Date(record.scheduledAt),
58
+ startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
59
+ updatedAt: new Date(record.updatedAt)
60
+ };
61
+ }
62
+ function cloneScheduleRunAttempt(record) {
63
+ return {
64
+ ...record,
65
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
66
+ createdAt: new Date(record.createdAt),
67
+ error: record.error ? { ...record.error } : void 0,
68
+ startedAt: new Date(record.startedAt),
69
+ updatedAt: new Date(record.updatedAt)
70
+ };
71
+ }
72
+ function serializeScheduleRun(record) {
73
+ return {
74
+ ...record,
75
+ completedAt: record.completedAt?.toISOString(),
76
+ createdAt: record.createdAt.toISOString(),
77
+ error: record.error ? { ...record.error } : void 0,
78
+ response: record.response ? structuredClone(record.response) : void 0,
79
+ scheduledAt: record.scheduledAt.toISOString(),
80
+ startedAt: record.startedAt?.toISOString(),
81
+ updatedAt: record.updatedAt.toISOString()
82
+ };
83
+ }
84
+ function serializeScheduleRunAttempt(record) {
85
+ return {
86
+ ...record,
87
+ completedAt: record.completedAt?.toISOString(),
88
+ createdAt: record.createdAt.toISOString(),
89
+ error: record.error ? { ...record.error } : void 0,
90
+ startedAt: record.startedAt.toISOString(),
91
+ updatedAt: record.updatedAt.toISOString()
92
+ };
93
+ }
94
+ function createMemoryScheduleRunStore() {
95
+ const runs = /* @__PURE__ */ new Map();
96
+ const attempts = /* @__PURE__ */ new Map();
97
+ return {
98
+ createAttempt(attempt) {
99
+ if (attempts.has(attempt.id)) throw scheduleErrorDiagnostics.SCHEDULE_R0030({ message: `Schedule Run Attempt already exists: ${attempt.id}` });
100
+ attempts.set(attempt.id, cloneScheduleRunAttempt(attempt));
101
+ return cloneScheduleRunAttempt(attempt);
102
+ },
103
+ createRun(run) {
104
+ if (runs.has(run.id)) throw scheduleErrorDiagnostics.SCHEDULE_R0031({ message: `Schedule Run already exists: ${run.id}` });
105
+ runs.set(run.id, cloneScheduleRun(run));
106
+ return cloneScheduleRun(run);
107
+ },
108
+ getAttempt(id) {
109
+ const attempt = attempts.get(id);
110
+ return attempt ? cloneScheduleRunAttempt(attempt) : void 0;
111
+ },
112
+ getRun(id) {
113
+ const run = runs.get(id);
114
+ return run ? cloneScheduleRun(run) : void 0;
115
+ },
116
+ listAttempts(runId) {
117
+ return [...attempts.values()].filter((attempt) => attempt.runId === runId).map(cloneScheduleRunAttempt);
118
+ },
119
+ listRuns(options) {
120
+ return selectRuns([...runs.values()], options).map(cloneScheduleRun);
121
+ },
122
+ updateAttempt(id, patch) {
123
+ const existing = attempts.get(id);
124
+ if (!existing) return;
125
+ const next = cloneScheduleRunAttempt({
126
+ ...existing,
127
+ ...patch,
128
+ updatedAt: patch.updatedAt
129
+ });
130
+ attempts.set(id, next);
131
+ return cloneScheduleRunAttempt(next);
132
+ },
133
+ updateRun(id, patch) {
134
+ const existing = runs.get(id);
135
+ if (!existing) return;
136
+ const next = cloneScheduleRun({
137
+ ...existing,
138
+ ...patch,
139
+ updatedAt: patch.updatedAt
140
+ });
141
+ runs.set(id, next);
142
+ return cloneScheduleRun(next);
143
+ }
144
+ };
145
+ }
146
+ function selectRuns(runs, options = {}) {
147
+ const selected = runs.filter((run) => (options.scheduleId === void 0 || run.scheduleId === options.scheduleId) && (options.idPrefix === void 0 || run.id.startsWith(options.idPrefix)));
148
+ selected.sort((left, right) => right.scheduledAt.getTime() - left.scheduledAt.getTime());
149
+ return options.limit === void 0 ? selected : selected.slice(0, options.limit);
150
+ }
151
+ /** Index keys carry metadata from the stored record, independent of caller-selected run IDs. */
152
+ function runIndexMetadata(key) {
153
+ try {
154
+ const parts = keySegments(key, 3);
155
+ const scheduledAt = Date.parse(parts[2]);
156
+ if (!Number.isFinite(scheduledAt)) return;
157
+ return {
158
+ id: parts[0],
159
+ scheduleId: parts[1],
160
+ scheduledAt
161
+ };
162
+ } catch {
163
+ return;
164
+ }
165
+ }
166
+ function createKVScheduleRunStore(options) {
167
+ const prefix = options.prefix ?? "vitehub:schedule";
168
+ const store = options.kvStore;
169
+ async function indexRun(run) {
170
+ try {
171
+ await store.set(joinKey(prefix, "schedule-run-index", run.id, run.scheduleId, run.scheduledAt.toISOString()), true);
172
+ } catch {}
173
+ }
174
+ async function indexAttempt(attempt) {
175
+ try {
176
+ await store.set(joinKey(prefix, "schedule-run-attempt-index", attempt.runId, attempt.id), true);
177
+ } catch {}
178
+ }
179
+ async function readSnapshot() {
180
+ const keys = await store.keys(scheduleRunBase(prefix));
181
+ const indexKeys = await store.keys(`${joinKey(prefix, "schedule-run-index")}/`);
182
+ const metadataById = new Map(indexKeys.flatMap((key) => {
183
+ const metadata = runIndexMetadata(key);
184
+ return metadata ? [[metadata.id, metadata]] : [];
185
+ }));
186
+ const known = [];
187
+ const bySchedule = /* @__PURE__ */ new Map();
188
+ const unknown = [];
189
+ const recordsByKey = /* @__PURE__ */ new Map();
190
+ function groupRun(key, metadata) {
191
+ const entry = {
192
+ id: metadata.id,
193
+ key,
194
+ scheduledAt: metadata.scheduledAt
195
+ };
196
+ known.push(entry);
197
+ const group = bySchedule.get(metadata.scheduleId) ?? [];
198
+ bySchedule.set(metadata.scheduleId, group);
199
+ group.push(entry);
200
+ }
201
+ for (const key of keys) {
202
+ let id;
203
+ try {
204
+ id = keySegments(key, 1)[0];
205
+ } catch {
206
+ unknown.push(key);
207
+ continue;
208
+ }
209
+ const metadata = metadataById.get(id);
210
+ if (!metadata) {
211
+ unknown.push(key);
212
+ continue;
213
+ }
214
+ groupRun(key, metadata);
215
+ }
216
+ if (unknown.length > maxLegacyHistoryRecords) return {
217
+ keys,
218
+ known,
219
+ bySchedule,
220
+ recordsByKey,
221
+ unknown
222
+ };
223
+ const legacyKeys = unknown;
224
+ for (let offset = 0; offset < legacyKeys.length; offset += 16) {
225
+ const batch = await Promise.all(legacyKeys.slice(offset, offset + 16).map(async (key) => {
226
+ const stored = await store.get(key);
227
+ const run = stored ? cloneScheduleRun(stored) : void 0;
228
+ recordsByKey.set(key, run);
229
+ if (run) await indexRun(run);
230
+ return {
231
+ key,
232
+ run
233
+ };
234
+ }));
235
+ for (const { key, run } of batch) if (run) groupRun(key, {
236
+ id: run.id,
237
+ scheduleId: run.scheduleId,
238
+ scheduledAt: run.scheduledAt.getTime()
239
+ });
240
+ }
241
+ for (const entries of [known, ...bySchedule.values()]) entries.sort((left, right) => right.scheduledAt - left.scheduledAt);
242
+ return {
243
+ keys,
244
+ known,
245
+ bySchedule,
246
+ recordsByKey,
247
+ unknown
248
+ };
249
+ }
250
+ async function listRuns(options, snapshot) {
251
+ if (snapshot.unknown.length > maxLegacyHistoryRecords) throw scheduleErrorDiagnostics.SCHEDULE_HISTORY_INCOMPLETE({
252
+ maxRecords: maxLegacyHistoryRecords,
253
+ recordCount: snapshot.unknown.length
254
+ });
255
+ const { keys, recordsByKey } = snapshot;
256
+ const known = options.scheduleId === void 0 ? snapshot.known : snapshot.bySchedule.get(options.scheduleId) ?? [];
257
+ const matching = options.idPrefix === void 0 ? known : known.filter((entry) => entry.id.startsWith(options.idPrefix));
258
+ const records = [];
259
+ const selectedKeys = options.scheduleId === void 0 && options.idPrefix === void 0 && options.limit === void 0 ? keys : matching.slice(0, options.limit ?? matching.length).map((entry) => entry.key);
260
+ for (let index = 0; index < selectedKeys.length; index += 16) {
261
+ const batch = await Promise.all(selectedKeys.slice(index, index + 16).map(async (key) => {
262
+ if (recordsByKey.has(key)) return recordsByKey.get(key);
263
+ const stored = await store.get(key);
264
+ const run = stored ? cloneScheduleRun(stored) : void 0;
265
+ recordsByKey.set(key, run);
266
+ return run;
267
+ }));
268
+ records.push(...batch.flatMap((run) => run ? [run] : []));
269
+ }
270
+ return selectRuns(records, options).map(cloneScheduleRun);
271
+ }
272
+ return {
273
+ async createAttempt(attempt) {
274
+ const key = scheduleRunAttemptKey(prefix, attempt.id);
275
+ return await withKVKeyLock(key, async () => {
276
+ if (await store.has(key)) throw scheduleErrorDiagnostics.SCHEDULE_R0032({ message: `Schedule Run Attempt already exists: ${attempt.id}` });
277
+ await store.set(key, serializeScheduleRunAttempt(attempt));
278
+ await indexAttempt(attempt);
279
+ return cloneScheduleRunAttempt(attempt);
280
+ });
281
+ },
282
+ async createRun(run) {
283
+ const key = scheduleRunKey(prefix, run.id);
284
+ return await withKVKeyLock(key, async () => {
285
+ if (await store.has(key)) throw scheduleErrorDiagnostics.SCHEDULE_R0033({ message: `Schedule Run already exists: ${run.id}` });
286
+ await store.set(key, serializeScheduleRun(run));
287
+ await indexRun(run);
288
+ return cloneScheduleRun(run);
289
+ });
290
+ },
291
+ async getAttempt(id) {
292
+ const attempt = await store.get(scheduleRunAttemptKey(prefix, id));
293
+ return attempt ? cloneScheduleRunAttempt(attempt) : void 0;
294
+ },
295
+ async getRun(id) {
296
+ const run = await store.get(scheduleRunKey(prefix, id));
297
+ return run ? cloneScheduleRun(run) : void 0;
298
+ },
299
+ async listAttempts(runId) {
300
+ const [keys, indexKeys] = await Promise.all([store.keys(scheduleRunAttemptBase(prefix)), store.keys(`${joinKey(prefix, "schedule-run-attempt-index")}/`)]);
301
+ const runByAttemptId = /* @__PURE__ */ new Map();
302
+ for (const key of indexKeys) try {
303
+ const parts = keySegments(key, 2);
304
+ runByAttemptId.set(parts[1], parts[0]);
305
+ } catch {}
306
+ const selectedKeys = keys.filter((key) => {
307
+ try {
308
+ const id = keySegments(key, 1)[0];
309
+ const indexedRunId = runByAttemptId.get(id);
310
+ return indexedRunId === void 0 || indexedRunId === runId;
311
+ } catch {
312
+ return true;
313
+ }
314
+ });
315
+ const attempts = [];
316
+ for (let offset = 0; offset < selectedKeys.length; offset += 16) {
317
+ const batch = await Promise.all(selectedKeys.slice(offset, offset + 16).map(async (key) => {
318
+ const stored = await store.get(key);
319
+ if (!stored) return;
320
+ const attempt = cloneScheduleRunAttempt(stored);
321
+ if (!runByAttemptId.has(attempt.id)) await indexAttempt(attempt);
322
+ return attempt.runId === runId ? attempt : void 0;
323
+ }));
324
+ attempts.push(...batch.flatMap((attempt) => attempt ? [attempt] : []));
325
+ }
326
+ return attempts;
327
+ },
328
+ async listRuns(options = {}) {
329
+ return listRuns(options, await readSnapshot());
330
+ },
331
+ async listRunsBatch(options) {
332
+ if (!options.length) return [];
333
+ const snapshot = await readSnapshot();
334
+ const results = [];
335
+ for (const query of options) results.push(await listRuns(query, snapshot));
336
+ return results;
337
+ },
338
+ async updateAttempt(id, patch) {
339
+ const key = scheduleRunAttemptKey(prefix, id);
340
+ return await withKVKeyLock(key, async () => {
341
+ const existing = await store.get(key);
342
+ if (!existing) return;
343
+ const next = cloneScheduleRunAttempt({
344
+ ...cloneScheduleRunAttempt(existing),
345
+ ...patch,
346
+ updatedAt: patch.updatedAt
347
+ });
348
+ await store.set(key, serializeScheduleRunAttempt(next));
349
+ return cloneScheduleRunAttempt(next);
350
+ });
351
+ },
352
+ async updateRun(id, patch) {
353
+ const key = scheduleRunKey(prefix, id);
354
+ return await withKVKeyLock(key, async () => {
355
+ const existing = await store.get(key);
356
+ if (!existing) return;
357
+ const next = cloneScheduleRun({
358
+ ...cloneScheduleRun(existing),
359
+ ...patch,
360
+ updatedAt: patch.updatedAt
361
+ });
362
+ await store.set(key, serializeScheduleRun(next));
363
+ return cloneScheduleRun(next);
364
+ });
365
+ }
366
+ };
367
+ }
368
+ //#endregion
369
+ //#region src/runtime/state.ts
370
+ let runtimeRegistry;
371
+ const processDefinitions = /* @__PURE__ */ new Set();
372
+ let runtimeRegistryVersion = 0;
373
+ let runStore;
374
+ let startedRuntime;
375
+ let occurrenceClaims;
376
+ const loadedRegistryEntries = /* @__PURE__ */ new Map();
377
+ const loadingRegistryEntries = /* @__PURE__ */ new Map();
378
+ const loadingRegistryStorage = new AsyncLocalStorage();
379
+ function isScheduleDefinition(value) {
380
+ return isRecordOrFunction(value) && Object.hasOwn(value, "handler") && typeof Reflect.get(value, "handler") === "function";
381
+ }
382
+ function setScheduleRuntimeRegistry(registry) {
383
+ runtimeRegistry = registry;
384
+ runtimeRegistryVersion++;
385
+ loadedRegistryEntries.clear();
386
+ loadingRegistryEntries.clear();
387
+ }
388
+ function getScheduleRuntimeRegistry() {
389
+ return runtimeRegistry;
390
+ }
391
+ /** Publish only ready runtimes, retaining earlier snapshots until their controllers close. */
392
+ function registerProcessScheduleDefinitions(definitions) {
393
+ processDefinitions.add(definitions);
394
+ return () => {
395
+ processDefinitions.delete(definitions);
396
+ };
397
+ }
398
+ function getProcessScheduleDefinitions() {
399
+ return [...processDefinitions].at(-1);
400
+ }
401
+ function setScheduleRunStore(store) {
402
+ runStore = store;
403
+ }
404
+ function getScheduleRunStore() {
405
+ return runStore ??= createMemoryScheduleRunStore();
406
+ }
407
+ /** Installs the claims that make each occurrence run in one process only. The Process Runtime installs them. */
408
+ function setScheduleOccurrenceClaims(claims) {
409
+ occurrenceClaims = claims;
410
+ }
411
+ function getScheduleOccurrenceClaims() {
412
+ return occurrenceClaims;
413
+ }
414
+ function setStartedScheduleRuntime(runtime) {
415
+ startedRuntime = runtime;
416
+ }
417
+ function getStartedScheduleRuntime() {
418
+ return startedRuntime;
419
+ }
420
+ async function loadScheduleDefinition(name) {
421
+ const entry = runtimeRegistry && Object.hasOwn(runtimeRegistry, name) ? runtimeRegistry[name] : void 0;
422
+ if (typeof entry !== "function") return;
423
+ if (loadedRegistryEntries.has(name)) return loadedRegistryEntries.get(name);
424
+ const activeLoads = loadingRegistryStorage.getStore();
425
+ const inFlightEntry = loadingRegistryEntries.get(name);
426
+ if (inFlightEntry) {
427
+ if (activeLoads?.has(name)) return void 0;
428
+ const loaded = await inFlightEntry.promise;
429
+ return inFlightEntry.version === runtimeRegistryVersion ? loaded : void 0;
430
+ }
431
+ const loadingVersion = runtimeRegistryVersion;
432
+ const nextActiveLoads = new Set(activeLoads);
433
+ nextActiveLoads.add(name);
434
+ const loadingEntry = Promise.resolve().then(() => loadingRegistryStorage.run(nextActiveLoads, async () => {
435
+ const loaded = await entry();
436
+ if (isScheduleDefinition(loaded)) return loaded;
437
+ if (isRecordOrFunction(loaded) && Object.hasOwn(loaded, "default")) {
438
+ const definition = Reflect.get(loaded, "default");
439
+ if (isScheduleDefinition(definition)) return definition;
440
+ }
441
+ }));
442
+ loadingRegistryEntries.set(name, {
443
+ promise: loadingEntry,
444
+ version: loadingVersion
445
+ });
446
+ try {
447
+ const loaded = await loadingEntry;
448
+ if (loadingVersion === runtimeRegistryVersion) {
449
+ loadedRegistryEntries.set(name, loaded);
450
+ return loaded;
451
+ }
452
+ return;
453
+ } finally {
454
+ if (loadingRegistryEntries.get(name)?.promise === loadingEntry) loadingRegistryEntries.delete(name);
455
+ }
456
+ }
457
+ function resetScheduleRuntime() {
458
+ runtimeRegistry = void 0;
459
+ processDefinitions.clear();
460
+ runtimeRegistryVersion++;
461
+ runStore = void 0;
462
+ startedRuntime = void 0;
463
+ occurrenceClaims = void 0;
464
+ loadedRegistryEntries.clear();
465
+ loadingRegistryEntries.clear();
466
+ }
467
+ //#endregion
468
+ export { getStartedScheduleRuntime as a, resetScheduleRuntime as c, setScheduleRuntimeRegistry as d, setStartedScheduleRuntime as f, keySegments as g, joinKey as h, getScheduleRuntimeRegistry as i, setScheduleOccurrenceClaims as l, createMemoryScheduleRunStore as m, getScheduleOccurrenceClaims as n, loadScheduleDefinition as o, createKVScheduleRunStore as p, getScheduleRunStore as r, registerProcessScheduleDefinitions as s, getProcessScheduleDefinitions as t, setScheduleRunStore as u };
@@ -0,0 +1,49 @@
1
+ import { a as ScheduleDefinitionRegistry, b as StartedScheduleStore, g as ScheduleRunStore, n as ScheduleDefinition, s as ScheduleRegistryDefinition } from "./types-Cw5LjPuc.js";
2
+ import { LeaseStore } from "@vite-hub/runtime";
3
+ //#region src/runtime/claims.d.ts
4
+ /** `held` when another process holds the occurrence now, `done` when a process finished it, `ran` when this call ran it. */
5
+ type OccurrenceClaimResult = "done" | "held" | "ran";
6
+ /** Runs each Schedule occurrence in one process of all the processes that share `leases`. */
7
+ interface OccurrenceClaims {
8
+ /**
9
+ * Runs `run` when this process gets the claim on `runId` and no process finished it. While `run` works, the claim is
10
+ * renewed. Call `markFinal` before invoking the handler or when an existing run is final. Then a done marker stays
11
+ * for `doneTtlMs`, also when the handler throws. Errors before `markFinal` leave the occurrence retryable.
12
+ */
13
+ run(runId: string, run: (markFinal: () => void) => Promise<unknown>): Promise<OccurrenceClaimResult>;
14
+ }
15
+ //#endregion
16
+ //#region src/runtime/state.d.ts
17
+ /** The cron and time zone of a Schedule that the Process Runtime runs. */
18
+ type ProcessScheduleTimingRecord = Pick<ScheduleDefinition, "cron" | "timeZone">;
19
+ /** What `startSchedule()` and the started-Schedule tick use. The generated Nitro plugin installs it. */
20
+ interface StartedScheduleRuntime {
21
+ /** How far back the first tick after a start runs cron minutes that no tick checked. */
22
+ catchUpMs: number;
23
+ /** Last minute, in epoch milliseconds, that a tick of this process checked. */
24
+ checkedThrough?: number;
25
+ /** Occurrences that another process held at a tick, by run id. The next tick tries them again. */
26
+ held?: Map<string, {
27
+ scheduledAt: Date;
28
+ scheduleId: string;
29
+ }>;
30
+ /** Schedule Definitions without `cron`, by name. */
31
+ registry: ScheduleDefinitionRegistry;
32
+ store: StartedScheduleStore;
33
+ }
34
+ declare function setScheduleRuntimeRegistry(registry: ScheduleDefinitionRegistry | undefined): void;
35
+ declare function getScheduleRuntimeRegistry(): ScheduleDefinitionRegistry | undefined;
36
+ /** Publish only ready runtimes, retaining earlier snapshots until their controllers close. */
37
+ declare function registerProcessScheduleDefinitions(definitions: ReadonlyMap<string, ProcessScheduleTimingRecord>): () => void;
38
+ declare function getProcessScheduleDefinitions(): ReadonlyMap<string, ProcessScheduleTimingRecord> | undefined;
39
+ declare function setScheduleRunStore(store: ScheduleRunStore | undefined): void;
40
+ declare function getScheduleRunStore(): ScheduleRunStore;
41
+ /** Installs the claims that make each occurrence run in one process only. The Process Runtime installs them. */
42
+ declare function setScheduleOccurrenceClaims(claims: OccurrenceClaims | undefined): void;
43
+ declare function getScheduleOccurrenceClaims(): OccurrenceClaims | undefined;
44
+ declare function setStartedScheduleRuntime(runtime: StartedScheduleRuntime | undefined): void;
45
+ declare function getStartedScheduleRuntime(): StartedScheduleRuntime | undefined;
46
+ declare function loadScheduleDefinition(name: string): Promise<ScheduleRegistryDefinition | undefined>;
47
+ declare function resetScheduleRuntime(): void;
48
+ //#endregion
49
+ export { getScheduleRuntimeRegistry as a, registerProcessScheduleDefinitions as c, setScheduleRunStore as d, setScheduleRuntimeRegistry as f, getScheduleRunStore as i, resetScheduleRuntime as l, getProcessScheduleDefinitions as n, getStartedScheduleRuntime as o, setStartedScheduleRuntime as p, getScheduleOccurrenceClaims as r, loadScheduleDefinition as s, StartedScheduleRuntime as t, setScheduleOccurrenceClaims as u };