@vite-hub/schedule 0.0.1 → 0.0.2
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 +72 -7
- package/dist/client-B3cyh-BG.js +233 -0
- package/dist/definition.d.ts +7 -0
- package/dist/definition.js +42 -0
- package/dist/discovery-MXY52MTU.js +767 -0
- package/dist/due-Bbh4yIxq.js +59 -0
- package/dist/execute-BnR8oEKq.js +211 -0
- package/dist/index.d.ts +27 -23
- package/dist/index.js +6 -152
- package/dist/nuxt.d.ts +19 -0
- package/dist/nuxt.js +25 -0
- package/dist/runtime/driver.d.ts +26 -0
- package/dist/runtime/driver.js +334 -0
- package/dist/runtime/process.d.ts +11 -0
- package/dist/runtime/process.js +285 -0
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +1 -1
- package/dist/runtime/static.d.ts +27 -3
- package/dist/runtime/static.js +126 -3
- package/dist/runtime.d.ts +4 -3
- package/dist/runtime.js +3 -3
- package/dist/{state-DoONzfij.js → state-BcEhBV8v.js} +71 -24
- package/dist/{store-CeeSsInC.d.ts → store-D2zUgEDc.d.ts} +4 -29
- package/dist/{types-DOjXDq0s.d.ts → types-Bcje4dLV.d.ts} +34 -9
- package/dist/vite-Dfeg9ZY3.js +1221 -0
- package/dist/vite.d.ts +33 -6
- package/dist/vite.js +2 -110
- package/dist/wait-until-CR-JjIOb.js +23 -0
- package/package.json +39 -42
- package/dist/client-BJ33CRLg.js +0 -401
- package/dist/discovery-Di9MD-SN.js +0 -574
- package/dist/module-C_j2ahfg.js +0 -1767
- package/dist/nitro.d.ts +0 -6
- package/dist/nitro.js +0 -2
package/dist/runtime/static.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as ScheduleDefinition, d as ScheduleDefinitionRegistry, g as ScheduleRunContext } from "../types-Bcje4dLV.js";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/static.d.ts
|
|
4
4
|
interface ExecuteStaticScheduleOptions {
|
|
@@ -6,12 +6,36 @@ interface ExecuteStaticScheduleOptions {
|
|
|
6
6
|
definition: ScheduleDefinition;
|
|
7
7
|
name: string;
|
|
8
8
|
scheduledAt?: Date;
|
|
9
|
+
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
10
|
+
}
|
|
11
|
+
interface ExecuteMatchingStaticSchedulesOptions {
|
|
12
|
+
cron: string;
|
|
13
|
+
registry: ScheduleDefinitionRegistry;
|
|
14
|
+
scheduledAt?: Date;
|
|
15
|
+
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
16
|
+
}
|
|
17
|
+
interface ExecuteCloudflareStaticSchedulesOptions {
|
|
18
|
+
registry: ScheduleDefinitionRegistry;
|
|
19
|
+
waitUntil?: (promise: PromiseLike<unknown>) => void;
|
|
20
|
+
}
|
|
21
|
+
interface CloudflareScheduledEventLike {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
controller?: {
|
|
24
|
+
cron?: string;
|
|
25
|
+
scheduledTime?: number | string | Date;
|
|
26
|
+
};
|
|
27
|
+
cron?: string;
|
|
28
|
+
scheduledTime?: number | string | Date;
|
|
9
29
|
}
|
|
10
30
|
interface StaticScheduleRun extends ScheduleRunContext {
|
|
11
31
|
cron: string;
|
|
12
32
|
scheduleId: string;
|
|
13
33
|
}
|
|
14
|
-
declare function createStaticScheduleRun(options: Omit<ExecuteStaticScheduleOptions, "definition">
|
|
34
|
+
declare function createStaticScheduleRun(options: Omit<ExecuteStaticScheduleOptions, "definition" | "waitUntil"> & {
|
|
35
|
+
waitUntil: NonNullable<ExecuteStaticScheduleOptions["waitUntil"]>;
|
|
36
|
+
}): StaticScheduleRun;
|
|
15
37
|
declare function executeStaticSchedule(options: ExecuteStaticScheduleOptions): Promise<unknown>;
|
|
38
|
+
declare function executeMatchingStaticSchedules(options: ExecuteMatchingStaticSchedulesOptions): Promise<unknown[]>;
|
|
39
|
+
declare function executeCloudflareStaticSchedules(event: CloudflareScheduledEventLike, options: ExecuteCloudflareStaticSchedulesOptions): Promise<unknown[]>;
|
|
16
40
|
//#endregion
|
|
17
|
-
export { ExecuteStaticScheduleOptions, StaticScheduleRun, createStaticScheduleRun, executeStaticSchedule };
|
|
41
|
+
export { ExecuteCloudflareStaticSchedulesOptions, ExecuteMatchingStaticSchedulesOptions, ExecuteStaticScheduleOptions, StaticScheduleRun, createStaticScheduleRun, executeCloudflareStaticSchedules, executeMatchingStaticSchedules, executeStaticSchedule };
|
package/dist/runtime/static.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as createLocalWaitUntil } from "../wait-until-CR-JjIOb.js";
|
|
1
2
|
//#region src/runtime/static.ts
|
|
2
3
|
function createStaticScheduleRun(options) {
|
|
3
4
|
const scheduledAt = options.scheduledAt ?? /* @__PURE__ */ new Date();
|
|
@@ -5,11 +6,133 @@ function createStaticScheduleRun(options) {
|
|
|
5
6
|
cron: options.cron,
|
|
6
7
|
id: `run_${options.name}_${scheduledAt.toISOString()}`,
|
|
7
8
|
scheduleId: options.name,
|
|
8
|
-
scheduledAt
|
|
9
|
+
scheduledAt,
|
|
10
|
+
waitUntil: options.waitUntil
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
13
|
async function executeStaticSchedule(options) {
|
|
12
|
-
|
|
14
|
+
const localWaitUntil = createLocalWaitUntil();
|
|
15
|
+
try {
|
|
16
|
+
const result = await options.definition.handler(createStaticScheduleRun({
|
|
17
|
+
...options,
|
|
18
|
+
waitUntil: options.waitUntil ?? localWaitUntil.waitUntil
|
|
19
|
+
}));
|
|
20
|
+
if (!options.waitUntil) await localWaitUntil.flush();
|
|
21
|
+
return result;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (!options.waitUntil) try {
|
|
24
|
+
await localWaitUntil.flush();
|
|
25
|
+
} catch {}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function executeMatchingStaticSchedules(options) {
|
|
30
|
+
const scheduledAt = options.scheduledAt ?? /* @__PURE__ */ new Date();
|
|
31
|
+
const runs = [];
|
|
32
|
+
for (const [name, load] of Object.entries(options.registry)) {
|
|
33
|
+
const definition = unwrapScheduleDefinition(await load());
|
|
34
|
+
if (!definition || definition.cron !== options.cron) continue;
|
|
35
|
+
runs.push(executeStaticSchedule({
|
|
36
|
+
cron: options.cron,
|
|
37
|
+
definition,
|
|
38
|
+
name,
|
|
39
|
+
scheduledAt,
|
|
40
|
+
waitUntil: options.waitUntil
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
return await Promise.all(runs);
|
|
44
|
+
}
|
|
45
|
+
async function executeCloudflareStaticSchedules(event, options) {
|
|
46
|
+
const scheduled = readCloudflareScheduledEvent(event);
|
|
47
|
+
return await runWithCloudflareServerEnv(event, async (waitUntil) => {
|
|
48
|
+
return await executeMatchingStaticSchedules({
|
|
49
|
+
cron: scheduled.cron,
|
|
50
|
+
registry: options.registry,
|
|
51
|
+
scheduledAt: scheduled.scheduledAt,
|
|
52
|
+
waitUntil
|
|
53
|
+
});
|
|
54
|
+
}, options.waitUntil ?? readCloudflareWaitUntil(event));
|
|
55
|
+
}
|
|
56
|
+
function readCloudflareScheduledEvent(event) {
|
|
57
|
+
const cron = event.controller?.cron ?? event.cron;
|
|
58
|
+
if (!cron) throw new TypeError("[vitehub:schedule] Cloudflare scheduled event is missing a cron string.");
|
|
59
|
+
const scheduledTime = event.controller?.scheduledTime ?? event.scheduledTime;
|
|
60
|
+
const scheduledAt = scheduledTime instanceof Date ? scheduledTime : typeof scheduledTime === "number" || typeof scheduledTime === "string" ? new Date(scheduledTime) : /* @__PURE__ */ new Date();
|
|
61
|
+
if (Number.isNaN(scheduledAt.getTime())) throw new TypeError("[vitehub:schedule] Cloudflare scheduled event has an invalid scheduledTime.");
|
|
62
|
+
return {
|
|
63
|
+
cron,
|
|
64
|
+
scheduledAt
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function runWithCloudflareServerEnv(event, callback, hostWaitUntil) {
|
|
68
|
+
const globals = globalThis;
|
|
69
|
+
const hadGlobalEnv = Object.prototype.hasOwnProperty.call(globals, "__env__");
|
|
70
|
+
const previousGlobalEnv = globals.__env__;
|
|
71
|
+
const env = readCloudflareEventEnv(event);
|
|
72
|
+
if (env) globals.__env__ = env;
|
|
73
|
+
const pending = /* @__PURE__ */ new Set();
|
|
74
|
+
const waitUntil = hostWaitUntil ? (value) => {
|
|
75
|
+
const promise = Promise.resolve(value);
|
|
76
|
+
pending.add(promise);
|
|
77
|
+
promise.then(() => pending.delete(promise), () => pending.delete(promise));
|
|
78
|
+
hostWaitUntil(promise);
|
|
79
|
+
} : void 0;
|
|
80
|
+
try {
|
|
81
|
+
return await callback(waitUntil);
|
|
82
|
+
} finally {
|
|
83
|
+
if (pending.size === 0) restoreGlobalEnv(globals, hadGlobalEnv, previousGlobalEnv);
|
|
84
|
+
else hostWaitUntil(flushPendingWork(pending).finally(() => {
|
|
85
|
+
restoreGlobalEnv(globals, hadGlobalEnv, previousGlobalEnv);
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function flushPendingWork(pending) {
|
|
90
|
+
while (pending.size > 0) await Promise.allSettled([...pending]);
|
|
91
|
+
}
|
|
92
|
+
function restoreGlobalEnv(globals, hadGlobalEnv, previousGlobalEnv) {
|
|
93
|
+
if (hadGlobalEnv) globals.__env__ = previousGlobalEnv;
|
|
94
|
+
else delete globals.__env__;
|
|
95
|
+
}
|
|
96
|
+
function isRecord(value) {
|
|
97
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
98
|
+
}
|
|
99
|
+
function readCloudflareWaitUntil(event) {
|
|
100
|
+
const context = isRecord(event.context) ? event.context : void 0;
|
|
101
|
+
const cloudflareContext = isRecord(context?.cloudflare) ? context.cloudflare : void 0;
|
|
102
|
+
const platformContext = isRecord(context?._platform) ? context._platform : void 0;
|
|
103
|
+
const platformCloudflareContext = isRecord(platformContext?.cloudflare) ? platformContext.cloudflare : void 0;
|
|
104
|
+
const request = isRecord(event.req) ? event.req : void 0;
|
|
105
|
+
const runtime = isRecord(request?.runtime) ? request.runtime : void 0;
|
|
106
|
+
const runtimeCloudflare = isRecord(runtime?.cloudflare) ? runtime.cloudflare : void 0;
|
|
107
|
+
const owners = [
|
|
108
|
+
event,
|
|
109
|
+
context,
|
|
110
|
+
cloudflareContext,
|
|
111
|
+
isRecord(cloudflareContext?.context) ? cloudflareContext.context : void 0,
|
|
112
|
+
platformCloudflareContext,
|
|
113
|
+
isRecord(platformCloudflareContext?.context) ? platformCloudflareContext.context : void 0,
|
|
114
|
+
request,
|
|
115
|
+
runtimeCloudflare,
|
|
116
|
+
isRecord(runtimeCloudflare?.context) ? runtimeCloudflare.context : void 0
|
|
117
|
+
];
|
|
118
|
+
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
119
|
+
}
|
|
120
|
+
function readCloudflareEventEnv(event) {
|
|
121
|
+
if (isRecord(event.env)) return event.env;
|
|
122
|
+
const context = isRecord(event.context) ? event.context : void 0;
|
|
123
|
+
const cloudflareContext = isRecord(context?.cloudflare) ? context.cloudflare : void 0;
|
|
124
|
+
if (isRecord(cloudflareContext?.env)) return cloudflareContext.env;
|
|
125
|
+
const platformContext = isRecord(context?._platform) ? context._platform : void 0;
|
|
126
|
+
const platformCloudflareContext = isRecord(platformContext?.cloudflare) ? platformContext.cloudflare : void 0;
|
|
127
|
+
if (isRecord(platformCloudflareContext?.env)) return platformCloudflareContext.env;
|
|
128
|
+
const request = isRecord(event.req) ? event.req : void 0;
|
|
129
|
+
const runtime = isRecord(request?.runtime) ? request.runtime : void 0;
|
|
130
|
+
const runtimeCloudflare = isRecord(runtime?.cloudflare) ? runtime.cloudflare : void 0;
|
|
131
|
+
return isRecord(runtimeCloudflare?.env) ? runtimeCloudflare.env : void 0;
|
|
132
|
+
}
|
|
133
|
+
function unwrapScheduleDefinition(loaded) {
|
|
134
|
+
const definition = typeof loaded === "object" && loaded !== null && "default" in loaded ? loaded.default : loaded;
|
|
135
|
+
return definition && "cron" in definition ? definition : void 0;
|
|
13
136
|
}
|
|
14
137
|
//#endregion
|
|
15
|
-
export { createStaticScheduleRun, executeStaticSchedule };
|
|
138
|
+
export { createStaticScheduleRun, executeCloudflareStaticSchedules, executeMatchingStaticSchedules, executeStaticSchedule };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { a as
|
|
1
|
+
/// <reference path="./registry-module.d.ts" />
|
|
2
|
+
import { C as ScheduleTargetName, S as ScheduleTargetDefinitionInput, a as RuntimeScheduleStore, c as ScheduleDefinition, d as ScheduleDefinitionRegistry, f as ScheduleHandler, g as ScheduleRunContext, i as RuntimeScheduleRecord, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, p as ScheduleRegistryDefinition, r as RuntimeScheduleMetadata, u as ScheduleDefinitionOptions, x as ScheduleTargetDefinition } from "./types-Bcje4dLV.js";
|
|
3
|
+
import { a as createMemoryRuntimeScheduleStore, c as validateRuntimeScheduleCron, s as schedules } from "./store-D2zUgEDc.js";
|
|
3
4
|
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,
|
|
5
|
+
export { type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionOptions, type ScheduleDefinitionRegistry, type ScheduleHandler, type ScheduleRegistryDefinition, type ScheduleRunContext, type ScheduleTargetDefinition, type ScheduleTargetDefinitionInput, type ScheduleTargetName, createMemoryRuntimeScheduleStore, getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, i as loadScheduleDefinition, o as setRuntimeScheduleStore,
|
|
2
|
-
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-
|
|
3
|
-
export {
|
|
1
|
+
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, i as loadScheduleDefinition, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, t as getRuntimeScheduleStore } from "./state-BcEhBV8v.js";
|
|
2
|
+
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-B3cyh-BG.js";
|
|
3
|
+
export { createMemoryRuntimeScheduleStore, getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
1
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
//#region src/errors.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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."
|
|
14
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
|
+
}
|
|
15
38
|
//#endregion
|
|
16
39
|
//#region src/runtime/store.ts
|
|
17
40
|
function trimPrefix(prefix) {
|
|
@@ -41,12 +64,38 @@ function scheduleRunAttemptBase(prefix) {
|
|
|
41
64
|
return joinKey(prefix, "schedule-run-attempts");
|
|
42
65
|
}
|
|
43
66
|
async function resolveDefaultKVStore() {
|
|
44
|
-
|
|
67
|
+
const module = await import("@vite-hub/kv");
|
|
68
|
+
return {
|
|
69
|
+
async del(key) {
|
|
70
|
+
const [error] = await module.kv.del(key);
|
|
71
|
+
if (error) throw error;
|
|
72
|
+
},
|
|
73
|
+
async get(key) {
|
|
74
|
+
const [error, value] = await module.kv.get(key);
|
|
75
|
+
if (error) throw error;
|
|
76
|
+
return value;
|
|
77
|
+
},
|
|
78
|
+
async has(key) {
|
|
79
|
+
const [error, value] = await module.kv.has(key);
|
|
80
|
+
if (error) throw error;
|
|
81
|
+
return value;
|
|
82
|
+
},
|
|
83
|
+
async keys(base) {
|
|
84
|
+
const [error, value] = await module.kv.keys(base);
|
|
85
|
+
if (error) throw error;
|
|
86
|
+
return value;
|
|
87
|
+
},
|
|
88
|
+
async set(key, value) {
|
|
89
|
+
const [error] = await module.kv.set(key, value);
|
|
90
|
+
if (error) throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
45
93
|
}
|
|
46
94
|
function cloneRuntimeSchedule(record) {
|
|
47
95
|
return {
|
|
48
96
|
...record,
|
|
49
97
|
createdAt: new Date(record.createdAt),
|
|
98
|
+
...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
|
|
50
99
|
updatedAt: new Date(record.updatedAt)
|
|
51
100
|
};
|
|
52
101
|
}
|
|
@@ -54,6 +103,7 @@ function serializeRuntimeSchedule(record) {
|
|
|
54
103
|
return {
|
|
55
104
|
...record,
|
|
56
105
|
createdAt: record.createdAt.toISOString(),
|
|
106
|
+
...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
|
|
57
107
|
updatedAt: record.updatedAt.toISOString()
|
|
58
108
|
};
|
|
59
109
|
}
|
|
@@ -61,6 +111,7 @@ function deserializeRuntimeSchedule(record) {
|
|
|
61
111
|
return {
|
|
62
112
|
...record,
|
|
63
113
|
createdAt: new Date(record.createdAt),
|
|
114
|
+
...record.input !== void 0 ? { input: structuredClone(record.input) } : {},
|
|
64
115
|
updatedAt: new Date(record.updatedAt)
|
|
65
116
|
};
|
|
66
117
|
}
|
|
@@ -68,7 +119,9 @@ function omitUndefinedPatch(patch) {
|
|
|
68
119
|
return {
|
|
69
120
|
...patch.cron !== void 0 ? { cron: patch.cron } : {},
|
|
70
121
|
...patch.enabled !== void 0 ? { enabled: patch.enabled } : {},
|
|
71
|
-
...patch
|
|
122
|
+
...Object.hasOwn(patch, "input") ? { input: structuredClone(patch.input) } : {},
|
|
123
|
+
...patch.target !== void 0 ? { target: patch.target } : {},
|
|
124
|
+
...patch.timeZone !== void 0 ? { timeZone: patch.timeZone } : {}
|
|
72
125
|
};
|
|
73
126
|
}
|
|
74
127
|
const keyLocks = /* @__PURE__ */ new Map();
|
|
@@ -92,11 +145,8 @@ function createMemoryRuntimeScheduleStore() {
|
|
|
92
145
|
const records = /* @__PURE__ */ new Map();
|
|
93
146
|
return {
|
|
94
147
|
create(record) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
details: { id: record.id },
|
|
98
|
-
httpStatus: 409
|
|
99
|
-
});
|
|
148
|
+
assertRuntimeScheduleId(record.id);
|
|
149
|
+
if (records.has(record.id)) throw createScheduleError("SCHEDULE_ALREADY_EXISTS");
|
|
100
150
|
records.set(record.id, cloneRuntimeSchedule(record));
|
|
101
151
|
return cloneRuntimeSchedule(record);
|
|
102
152
|
},
|
|
@@ -130,14 +180,11 @@ function createKVRuntimeScheduleStore(options = {}) {
|
|
|
130
180
|
}
|
|
131
181
|
return {
|
|
132
182
|
async create(record) {
|
|
183
|
+
assertRuntimeScheduleId(record.id);
|
|
133
184
|
const store = await getKVStore();
|
|
134
185
|
const key = runtimeScheduleKey(prefix, record.id);
|
|
135
186
|
return await withKVKeyLock(key, async () => {
|
|
136
|
-
if (await store.has(key)) throw
|
|
137
|
-
code: "SCHEDULE_ALREADY_EXISTS",
|
|
138
|
-
details: { id: record.id },
|
|
139
|
-
httpStatus: 409
|
|
140
|
-
});
|
|
187
|
+
if (await store.has(key)) throw createScheduleError("SCHEDULE_ALREADY_EXISTS");
|
|
141
188
|
await store.set(key, serializeRuntimeSchedule(record));
|
|
142
189
|
return cloneRuntimeSchedule(record);
|
|
143
190
|
});
|
|
@@ -438,4 +485,4 @@ function resetScheduleRuntime() {
|
|
|
438
485
|
loadingRegistryEntries.clear();
|
|
439
486
|
}
|
|
440
487
|
//#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,
|
|
488
|
+
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,34 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as _$_vite_hub_schedule0 from "@vite-hub/schedule";
|
|
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";
|
|
3
2
|
|
|
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
3
|
//#region src/runtime/client.d.ts
|
|
29
4
|
declare function validateRuntimeScheduleCron(cron: unknown): void;
|
|
30
5
|
declare const schedules: {
|
|
31
|
-
create<TTarget extends ScheduleTargetName>(input: RuntimeScheduleCreateInput<TTarget>): Promise<RuntimeScheduleRecord
|
|
6
|
+
create<TTarget extends ScheduleTargetName, TInput = unknown>(input: RuntimeScheduleCreateInput<TTarget, TInput>): Promise<RuntimeScheduleRecord<TInput>>;
|
|
32
7
|
delete(id: string): Promise<boolean>;
|
|
33
8
|
disable(id: string): Promise<RuntimeScheduleRecord>;
|
|
34
9
|
enable(id: string): Promise<RuntimeScheduleRecord>;
|
|
@@ -40,7 +15,7 @@ declare const schedules: {
|
|
|
40
15
|
run(id: string, options?: {
|
|
41
16
|
scheduledAt?: Date;
|
|
42
17
|
}): Promise<ScheduleRunRecord>;
|
|
43
|
-
update<TTarget extends ScheduleTargetName>(id: string, input: RuntimeScheduleUpdateInput<TTarget>): Promise<RuntimeScheduleRecord
|
|
18
|
+
update<TTarget extends ScheduleTargetName, TInput = unknown>(id: string, input: RuntimeScheduleUpdateInput<TTarget, TInput>): Promise<RuntimeScheduleRecord<TInput>>;
|
|
44
19
|
};
|
|
45
20
|
//#endregion
|
|
46
21
|
//#region src/runtime/store.d.ts
|
|
@@ -60,4 +35,4 @@ declare function createKVRuntimeScheduleStore(options?: KVScheduleStoreOptions):
|
|
|
60
35
|
declare function createMemoryScheduleRunStore(): ScheduleRunStore;
|
|
61
36
|
declare function createKVScheduleRunStore(options?: KVScheduleStoreOptions): ScheduleRunStore;
|
|
62
37
|
//#endregion
|
|
63
|
-
export { createMemoryRuntimeScheduleStore as a, validateRuntimeScheduleCron as c, createKVScheduleRunStore as i,
|
|
38
|
+
export { createMemoryRuntimeScheduleStore as a, validateRuntimeScheduleCron as c, createKVScheduleRunStore as i, ScheduleKVStorage as n, createMemoryScheduleRunStore as o, createKVRuntimeScheduleStore as r, schedules as s, KVScheduleStoreOptions as t };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
-
interface ScheduleRunContext {
|
|
2
|
+
interface ScheduleRunContext<TInput = unknown> {
|
|
3
3
|
id: string;
|
|
4
4
|
attemptId?: string;
|
|
5
|
+
input?: TInput;
|
|
5
6
|
runId?: string;
|
|
6
7
|
scheduleId?: string;
|
|
7
8
|
scheduledAt: Date;
|
|
8
9
|
target?: ScheduleTargetName;
|
|
10
|
+
waitUntil(promise: PromiseLike<unknown>): void;
|
|
9
11
|
}
|
|
10
|
-
type ScheduleHandler<TResult = unknown
|
|
12
|
+
type ScheduleHandler<TResult = unknown, TInput = unknown> = {
|
|
13
|
+
bivarianceHack(context: ScheduleRunContext<TInput>): TResult | Promise<TResult>;
|
|
14
|
+
}["bivarianceHack"];
|
|
11
15
|
interface ScheduleDefinitionInput<TResult = unknown> {
|
|
12
16
|
allowRuntimeSchedules?: boolean;
|
|
13
17
|
cron: string;
|
|
@@ -21,32 +25,52 @@ interface ScheduleDefinition<TResult = unknown> {
|
|
|
21
25
|
handler: ScheduleHandler<TResult>;
|
|
22
26
|
options?: ScheduleDefinitionOptions;
|
|
23
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;
|
|
24
38
|
interface ScheduleDefinitionRegistry {
|
|
25
39
|
[name: string]: () => Promise<{
|
|
26
|
-
default?:
|
|
27
|
-
} |
|
|
40
|
+
default?: ScheduleRegistryDefinition;
|
|
41
|
+
} | ScheduleRegistryDefinition>;
|
|
28
42
|
}
|
|
29
43
|
type ScheduleTargetName = string & {};
|
|
30
44
|
interface RuntimeScheduleMetadata {
|
|
31
45
|
createdAt: Date;
|
|
32
46
|
updatedAt: Date;
|
|
33
47
|
}
|
|
34
|
-
interface RuntimeScheduleRecord extends RuntimeScheduleMetadata {
|
|
48
|
+
interface RuntimeScheduleRecord<TInput = unknown> extends RuntimeScheduleMetadata {
|
|
35
49
|
cron: string;
|
|
36
50
|
enabled: boolean;
|
|
37
51
|
id: string;
|
|
52
|
+
input?: TInput;
|
|
38
53
|
target: ScheduleTargetName;
|
|
54
|
+
timeZone?: string;
|
|
55
|
+
}
|
|
56
|
+
interface RuntimeScheduleWake {
|
|
57
|
+
scheduleId: string;
|
|
58
|
+
scheduledAt: Date;
|
|
39
59
|
}
|
|
40
|
-
interface RuntimeScheduleCreateInput<TTarget extends ScheduleTargetName = ScheduleTargetName> {
|
|
60
|
+
interface RuntimeScheduleCreateInput<TTarget extends ScheduleTargetName = ScheduleTargetName, TInput = unknown> {
|
|
41
61
|
cron: string;
|
|
42
62
|
enabled?: boolean;
|
|
43
63
|
id?: string;
|
|
64
|
+
input?: TInput;
|
|
44
65
|
target: TTarget;
|
|
66
|
+
timeZone?: string;
|
|
45
67
|
}
|
|
46
|
-
interface RuntimeScheduleUpdateInput<TTarget extends ScheduleTargetName = ScheduleTargetName> {
|
|
68
|
+
interface RuntimeScheduleUpdateInput<TTarget extends ScheduleTargetName = ScheduleTargetName, TInput = unknown> {
|
|
47
69
|
cron?: string;
|
|
48
70
|
enabled?: boolean;
|
|
71
|
+
input?: TInput;
|
|
49
72
|
target?: TTarget;
|
|
73
|
+
timeZone?: string;
|
|
50
74
|
}
|
|
51
75
|
interface RuntimeScheduleStore {
|
|
52
76
|
create: (record: RuntimeScheduleRecord) => Promise<RuntimeScheduleRecord> | RuntimeScheduleRecord;
|
|
@@ -105,7 +129,8 @@ interface DiscoveredScheduleDefinition {
|
|
|
105
129
|
allowRuntimeSchedules?: boolean;
|
|
106
130
|
handler: string;
|
|
107
131
|
name: string;
|
|
108
|
-
|
|
132
|
+
runtimeOnly?: boolean;
|
|
133
|
+
source?: "server-schedules" | "vite-suffix";
|
|
109
134
|
}
|
|
110
135
|
//#endregion
|
|
111
|
-
export {
|
|
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 };
|