@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.
- package/README.md +139 -58
- package/dist/console-wEhr0LWn.d.ts +330 -0
- package/dist/definition.d.ts +8 -6
- package/dist/definition.js +34 -28
- package/dist/due-BVMRQ93v.js +144 -0
- package/dist/durability.d.ts +14 -0
- package/dist/durability.js +23 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/error-diagnostics-Mpeks7J0.js +166 -0
- package/dist/index.d.ts +61 -40
- package/dist/index.js +27 -7
- package/dist/inspect-DTfAo5gS.js +118 -0
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
- package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-DwZWFIUX.js +184 -0
- package/dist/operations.d.ts +84 -0
- package/dist/operations.js +318 -0
- package/dist/os.d.ts +167 -0
- package/dist/os.js +1659 -0
- package/dist/registry-module.d.ts +0 -5
- package/dist/runtime/console.d.ts +12 -0
- package/dist/runtime/console.js +85 -0
- package/dist/runtime/kv.d.ts +4 -0
- package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
- package/dist/runtime/process.d.ts +53 -5
- package/dist/runtime/process.js +501 -251
- package/dist/runtime/state.d.ts +2 -13
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +44 -12
- package/dist/runtime/static.js +2 -150
- package/dist/runtime.d.ts +38 -4
- package/dist/runtime.js +6 -3
- package/dist/started-BuGmnus4.js +201 -0
- package/dist/started-Bx7MDbrl.js +146 -0
- package/dist/started-errors-p7cu_rI7.js +250 -0
- package/dist/state-B-Fuyfb4.js +468 -0
- package/dist/state-Do2wV4Tx.d.ts +49 -0
- package/dist/static-DQwzzvPg.js +266 -0
- package/dist/store-Df0-fzCl.d.ts +53 -0
- package/dist/time-zone-SBldrUgt.js +59 -0
- package/dist/types-Cw5LjPuc.d.ts +167 -0
- package/dist/vite.d.ts +214 -11
- package/dist/vite.js +5876 -3
- package/dist/wait-until-Dy4Bn3ZN.js +112 -0
- package/package.json +65 -24
- package/dist/client-DpCD4YFE.js +0 -233
- package/dist/discovery-DkFAN7Wd.d.ts +0 -15
- package/dist/discovery-DvU3B6iD.js +0 -753
- package/dist/due-Bbh4yIxq.js +0 -59
- package/dist/execute-B-pii4wf.js +0 -211
- package/dist/nuxt.d.ts +0 -19
- package/dist/nuxt.js +0 -26
- package/dist/runtime/driver.d.ts +0 -26
- package/dist/runtime/driver.js +0 -337
- package/dist/state-By7WU_ks.js +0 -472
- package/dist/store-t-74rsM_.d.ts +0 -48
- package/dist/types-Bcje4dLV.d.ts +0 -136
- package/dist/vite-BHs17nWX.js +0 -4166
- package/dist/wait-until-BzIwzXw4.js +0 -23
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/errors.ts
|
|
3
|
+
const scheduleErrorMessages = {
|
|
4
|
+
SCHEDULE_DEFINITION_NOT_FOUND: "Static Schedule Definition was not found.",
|
|
5
|
+
SCHEDULE_INVALID_CRON: "Schedule cron is invalid.",
|
|
6
|
+
SCHEDULE_INVALID_SCHEDULED_AT: "Schedule scheduledAt value is invalid.",
|
|
7
|
+
SCHEDULE_MANUAL_RUN_DISABLED: "Schedule Definition does not allow manual runs. Set manual: true to allow them.",
|
|
8
|
+
SCHEDULE_NOT_DUE: "Schedule is not due.",
|
|
9
|
+
SCHEDULE_RUN_NOT_FOUND: "Schedule Run was not found."
|
|
10
|
+
};
|
|
11
|
+
function isDateValue(value) {
|
|
12
|
+
if (value instanceof Date) return true;
|
|
13
|
+
try {
|
|
14
|
+
Date.prototype.getTime.call(value);
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function invalidScheduleValueDetails(field, value) {
|
|
21
|
+
let valueType;
|
|
22
|
+
try {
|
|
23
|
+
valueType = value === null ? "null" : Array.isArray(value) ? "array" : isDateValue(value) ? "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
|
+
//#endregion
|
|
36
|
+
//#region src/runtime/date.ts
|
|
37
|
+
/** The idempotency key of one Schedule occurrence. Two runs of the same Schedule for the same time share it. */
|
|
38
|
+
function scheduleIdempotencyKey(name, scheduledAt) {
|
|
39
|
+
return `schedule:${name}:${scheduledAt.toISOString()}`;
|
|
40
|
+
}
|
|
41
|
+
function isScheduleDate(value) {
|
|
42
|
+
try {
|
|
43
|
+
return !Number.isNaN(Date.prototype.getTime.call(value));
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const scheduledAtText = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
49
|
+
function parseScheduledAtText(value) {
|
|
50
|
+
const match = scheduledAtText.exec(value);
|
|
51
|
+
if (!match) return;
|
|
52
|
+
const [, year, month, day, hour] = match.map(Number);
|
|
53
|
+
const calendarDay = /* @__PURE__ */ new Date(0);
|
|
54
|
+
calendarDay.setUTCFullYear(year, month - 1, day);
|
|
55
|
+
if (hour > 23 || calendarDay.getUTCMonth() !== month - 1 || calendarDay.getUTCDate() !== day) return;
|
|
56
|
+
const date = new Date(value);
|
|
57
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
58
|
+
}
|
|
59
|
+
function validateScheduledAt(scheduledAt) {
|
|
60
|
+
const value = scheduledAt ?? /* @__PURE__ */ new Date();
|
|
61
|
+
if (!isScheduleDate(value)) throw createScheduleError("SCHEDULE_INVALID_SCHEDULED_AT", { details: invalidScheduleValueDetails("scheduledAt", value) });
|
|
62
|
+
return new Date(Date.prototype.getTime.call(value));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the time a manual run treats as its fire time. A string must be an ISO 8601 date-time with a time zone, such
|
|
66
|
+
* as `2026-01-31T23:59:00Z`. Anything else fails with `SCHEDULE_INVALID_SCHEDULED_AT`. Absent means now.
|
|
67
|
+
*/
|
|
68
|
+
function parseScheduledAt(scheduledAt) {
|
|
69
|
+
if (typeof scheduledAt !== "string") return validateScheduledAt(scheduledAt);
|
|
70
|
+
const parsed = parseScheduledAtText(scheduledAt);
|
|
71
|
+
if (parsed) return parsed;
|
|
72
|
+
throw createScheduleError("SCHEDULE_INVALID_SCHEDULED_AT", { details: invalidScheduleValueDetails("scheduledAt", scheduledAt) });
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/runtime/wait-until.ts
|
|
76
|
+
function createLocalWaitUntil() {
|
|
77
|
+
const pending = /* @__PURE__ */ new Set();
|
|
78
|
+
let error;
|
|
79
|
+
let failed = false;
|
|
80
|
+
return {
|
|
81
|
+
async flush() {
|
|
82
|
+
while (pending.size > 0) await Promise.allSettled(pending);
|
|
83
|
+
if (failed) throw error;
|
|
84
|
+
},
|
|
85
|
+
waitUntil(value) {
|
|
86
|
+
const promise = Promise.resolve(value);
|
|
87
|
+
pending.add(promise);
|
|
88
|
+
promise.then(() => pending.delete(promise), (reason) => {
|
|
89
|
+
pending.delete(promise);
|
|
90
|
+
if (!failed) error = reason;
|
|
91
|
+
failed = true;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Complete local deferred work while preserving a handler's failure over a deferred failure. */
|
|
97
|
+
async function runWithScheduleWaitUntil(run, hostWaitUntil) {
|
|
98
|
+
if (hostWaitUntil) return await run(hostWaitUntil);
|
|
99
|
+
const local = createLocalWaitUntil();
|
|
100
|
+
try {
|
|
101
|
+
const result = await run(local.waitUntil);
|
|
102
|
+
await local.flush();
|
|
103
|
+
return result;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
try {
|
|
106
|
+
await local.flush();
|
|
107
|
+
} catch {}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { validateScheduledAt as a, scheduleIdempotencyKey as i, isScheduleDate as n, createScheduleError as o, parseScheduledAt as r, invalidScheduleValueDetails as s, runWithScheduleWaitUntil as t };
|
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/schedule",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Schedule primitives and definition discovery for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
6
7
|
"cron",
|
|
8
|
+
"cron-jobs",
|
|
9
|
+
"netlify",
|
|
10
|
+
"nuxt",
|
|
7
11
|
"schedule",
|
|
12
|
+
"typescript",
|
|
13
|
+
"vercel",
|
|
8
14
|
"vite",
|
|
9
15
|
"vitehub"
|
|
10
16
|
],
|
|
11
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://vitehub.dev",
|
|
12
18
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
13
19
|
"license": "Apache-2.0",
|
|
14
20
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -25,34 +31,69 @@
|
|
|
25
31
|
"sideEffects": false,
|
|
26
32
|
"types": "./dist/index.d.ts",
|
|
27
33
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"./
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./durability": {
|
|
40
|
+
"types": "./dist/durability.d.ts",
|
|
41
|
+
"import": "./dist/durability.js",
|
|
42
|
+
"default": "./dist/durability.js"
|
|
43
|
+
},
|
|
44
|
+
"./os": {
|
|
45
|
+
"types": "./dist/os.d.ts",
|
|
46
|
+
"import": "./dist/os.js",
|
|
47
|
+
"default": "./dist/os.js"
|
|
48
|
+
},
|
|
49
|
+
"./runtime": {
|
|
50
|
+
"types": "./dist/runtime.d.ts",
|
|
51
|
+
"import": "./dist/runtime.js",
|
|
52
|
+
"default": "./dist/runtime.js"
|
|
53
|
+
},
|
|
54
|
+
"./runtime/kv": {
|
|
55
|
+
"types": "./dist/runtime/kv.d.ts",
|
|
56
|
+
"import": "./dist/runtime/kv.js",
|
|
57
|
+
"default": "./dist/runtime/kv.js"
|
|
58
|
+
},
|
|
59
|
+
"./runtime/process": {
|
|
60
|
+
"types": "./dist/runtime/process.d.ts",
|
|
61
|
+
"import": "./dist/runtime/process.js",
|
|
62
|
+
"default": "./dist/runtime/process.js"
|
|
63
|
+
},
|
|
64
|
+
"./runtime/static": {
|
|
65
|
+
"types": "./dist/runtime/static.d.ts",
|
|
66
|
+
"import": "./dist/runtime/static.js",
|
|
67
|
+
"default": "./dist/runtime/static.js"
|
|
68
|
+
},
|
|
69
|
+
"./vite": {
|
|
70
|
+
"types": "./dist/vite.d.ts",
|
|
71
|
+
"import": "./dist/vite.js",
|
|
72
|
+
"default": "./dist/vite.js"
|
|
73
|
+
},
|
|
36
74
|
"./package.json": "./package.json"
|
|
37
75
|
},
|
|
38
76
|
"dependencies": {
|
|
39
|
-
"@
|
|
77
|
+
"@valibot/to-json-schema": "^1.8.0",
|
|
78
|
+
"@vite-hub/runtime": "0.3.1",
|
|
40
79
|
"cron-schedule": "^6.0.0",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
80
|
+
"esbuild": "^0.28.2",
|
|
81
|
+
"nostics": "1.4.0",
|
|
82
|
+
"valibot": "^1.5.0"
|
|
43
83
|
},
|
|
44
84
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^24.
|
|
46
|
-
"@vite-hub/
|
|
47
|
-
"
|
|
85
|
+
"@types/node": "^24.19.1",
|
|
86
|
+
"@vite-hub/internal": "0.0.1",
|
|
87
|
+
"@vite-hub/kv": "0.3.1",
|
|
88
|
+
"postgres": "^3.4.9",
|
|
89
|
+
"publint": "^0.3.25",
|
|
48
90
|
"typescript": "^6.0.3",
|
|
49
|
-
"vite": "^8.
|
|
50
|
-
"vite-plus": "^0.
|
|
51
|
-
"vitest": "^4.1.
|
|
52
|
-
"@vite-hub/internal": "0.0.1"
|
|
91
|
+
"vite": "^8.2.2",
|
|
92
|
+
"vite-plus": "^0.3.3",
|
|
93
|
+
"vitest": "^4.1.11"
|
|
53
94
|
},
|
|
54
95
|
"peerDependencies": {
|
|
55
|
-
"@vite-hub/kv": "0.
|
|
96
|
+
"@vite-hub/kv": "0.3.1",
|
|
56
97
|
"vite": ">=8.0.0"
|
|
57
98
|
},
|
|
58
99
|
"peerDependenciesMeta": {
|
|
@@ -64,12 +105,12 @@
|
|
|
64
105
|
}
|
|
65
106
|
},
|
|
66
107
|
"engines": {
|
|
67
|
-
"node": ">=
|
|
108
|
+
"node": ">=22.18.0"
|
|
68
109
|
},
|
|
69
110
|
"scripts": {
|
|
70
111
|
"build": "vp pack",
|
|
71
112
|
"dev": "vp pack --watch",
|
|
72
|
-
"typecheck": "
|
|
73
|
-
"test": "vp run -t @vite-hub/schedule#build && vp test"
|
|
113
|
+
"typecheck": "vp run --cache -t @vite-hub/schedule#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
114
|
+
"test": "vp run --cache -t @vite-hub/schedule#build && vp test"
|
|
74
115
|
}
|
|
75
116
|
}
|
package/dist/client-DpCD4YFE.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { n as executeRuntimeSchedule, o as randomId } from "./execute-B-pii4wf.js";
|
|
2
|
-
import { h as invalidScheduleValueDetails, i as loadScheduleDefinition, m as createScheduleError, n as getScheduleRunStore, p as assertRuntimeScheduleId, t as getRuntimeScheduleStore } from "./state-By7WU_ks.js";
|
|
3
|
-
//#region ../internal/src/runtime/time-zone.ts
|
|
4
|
-
const slashlessIanaTimeZones = new Set([
|
|
5
|
-
"CET",
|
|
6
|
-
"CST6CDT",
|
|
7
|
-
"Cuba",
|
|
8
|
-
"EET",
|
|
9
|
-
"EST",
|
|
10
|
-
"EST5EDT",
|
|
11
|
-
"Egypt",
|
|
12
|
-
"Eire",
|
|
13
|
-
"Factory",
|
|
14
|
-
"GB",
|
|
15
|
-
"GB-Eire",
|
|
16
|
-
"GMT",
|
|
17
|
-
"GMT+0",
|
|
18
|
-
"GMT-0",
|
|
19
|
-
"GMT0",
|
|
20
|
-
"Greenwich",
|
|
21
|
-
"HST",
|
|
22
|
-
"Hongkong",
|
|
23
|
-
"Iceland",
|
|
24
|
-
"Iran",
|
|
25
|
-
"Israel",
|
|
26
|
-
"Jamaica",
|
|
27
|
-
"Japan",
|
|
28
|
-
"Kwajalein",
|
|
29
|
-
"Libya",
|
|
30
|
-
"MET",
|
|
31
|
-
"MST",
|
|
32
|
-
"MST7MDT",
|
|
33
|
-
"NZ",
|
|
34
|
-
"NZ-CHAT",
|
|
35
|
-
"Navajo",
|
|
36
|
-
"PRC",
|
|
37
|
-
"PST8PDT",
|
|
38
|
-
"Poland",
|
|
39
|
-
"Portugal",
|
|
40
|
-
"ROC",
|
|
41
|
-
"ROK",
|
|
42
|
-
"Singapore",
|
|
43
|
-
"Turkey",
|
|
44
|
-
"UCT",
|
|
45
|
-
"UTC",
|
|
46
|
-
"Universal",
|
|
47
|
-
"W-SU",
|
|
48
|
-
"WET",
|
|
49
|
-
"Zulu"
|
|
50
|
-
]);
|
|
51
|
-
function isIanaTimeZone(timeZone) {
|
|
52
|
-
if (typeof timeZone !== "string" || !timeZone.includes("/") && !slashlessIanaTimeZones.has(timeZone)) return false;
|
|
53
|
-
try {
|
|
54
|
-
new Intl.DateTimeFormat("en-US", { timeZone });
|
|
55
|
-
return true;
|
|
56
|
-
} catch {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/runtime/client.ts
|
|
62
|
-
const cronRange = {
|
|
63
|
-
dayOfMonth: {
|
|
64
|
-
max: 31,
|
|
65
|
-
min: 1
|
|
66
|
-
},
|
|
67
|
-
dayOfWeek: {
|
|
68
|
-
max: 7,
|
|
69
|
-
min: 0
|
|
70
|
-
},
|
|
71
|
-
hour: {
|
|
72
|
-
max: 23,
|
|
73
|
-
min: 0
|
|
74
|
-
},
|
|
75
|
-
minute: {
|
|
76
|
-
max: 59,
|
|
77
|
-
min: 0
|
|
78
|
-
},
|
|
79
|
-
month: {
|
|
80
|
-
max: 12,
|
|
81
|
-
min: 1
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const cronFieldRanges = [
|
|
85
|
-
cronRange.minute,
|
|
86
|
-
cronRange.hour,
|
|
87
|
-
cronRange.dayOfMonth,
|
|
88
|
-
cronRange.month,
|
|
89
|
-
cronRange.dayOfWeek
|
|
90
|
-
];
|
|
91
|
-
const runtimeScheduleCreateInputKeys = new Set([
|
|
92
|
-
"cron",
|
|
93
|
-
"enabled",
|
|
94
|
-
"id",
|
|
95
|
-
"input",
|
|
96
|
-
"target",
|
|
97
|
-
"timeZone"
|
|
98
|
-
]);
|
|
99
|
-
const runtimeScheduleUpdateInputKeys = new Set([
|
|
100
|
-
"cron",
|
|
101
|
-
"enabled",
|
|
102
|
-
"input",
|
|
103
|
-
"target",
|
|
104
|
-
"timeZone"
|
|
105
|
-
]);
|
|
106
|
-
function parseCronNumber(value, range) {
|
|
107
|
-
if (!/^\d+$/.test(value)) throw new Error("not a number");
|
|
108
|
-
const parsed = Number(value);
|
|
109
|
-
if (!Number.isInteger(parsed) || parsed < range.min || parsed > range.max) throw new Error("out of range");
|
|
110
|
-
return parsed;
|
|
111
|
-
}
|
|
112
|
-
function validateCronPart(part, range) {
|
|
113
|
-
const [value, step, extra] = part.split("/");
|
|
114
|
-
if (extra !== void 0 || value === void 0 || value.length === 0) throw new Error("invalid step");
|
|
115
|
-
if (step !== void 0) {
|
|
116
|
-
if (parseCronNumber(step, {
|
|
117
|
-
max: range.max,
|
|
118
|
-
min: 1
|
|
119
|
-
}) < 1) throw new Error("invalid step");
|
|
120
|
-
}
|
|
121
|
-
if (value === "*") return;
|
|
122
|
-
const [start, end, extraRange] = value.split("-");
|
|
123
|
-
if (extraRange !== void 0 || start === void 0 || start.length === 0) throw new Error("invalid range");
|
|
124
|
-
const parsedStart = parseCronNumber(start, range);
|
|
125
|
-
if (end === void 0) return;
|
|
126
|
-
if (parseCronNumber(end, range) < parsedStart) throw new Error("invalid range");
|
|
127
|
-
}
|
|
128
|
-
function validateRuntimeScheduleCron(cron) {
|
|
129
|
-
if (typeof cron !== "string" || cron.trim() !== cron || cron.length === 0) throw createScheduleError("SCHEDULE_INVALID_CRON", { details: invalidScheduleValueDetails("cron", cron) });
|
|
130
|
-
const fields = cron.split(/\s+/);
|
|
131
|
-
if (fields.length !== 5) throw createScheduleError("SCHEDULE_INVALID_CRON", { details: invalidScheduleValueDetails("cron", cron) });
|
|
132
|
-
try {
|
|
133
|
-
fields.forEach((field, index) => {
|
|
134
|
-
if (field.length === 0) throw new Error("empty field");
|
|
135
|
-
for (const part of field.split(",")) validateCronPart(part, cronFieldRanges[index]);
|
|
136
|
-
});
|
|
137
|
-
} catch {
|
|
138
|
-
throw createScheduleError("SCHEDULE_INVALID_CRON", { details: invalidScheduleValueDetails("cron", cron) });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function validateRuntimeScheduleTimeZone(timeZone) {
|
|
142
|
-
if (!isIanaTimeZone(timeZone)) throw createScheduleError("SCHEDULE_INVALID_TIME_ZONE", { details: invalidScheduleValueDetails("timeZone", timeZone) });
|
|
143
|
-
}
|
|
144
|
-
async function assertRuntimeTarget(target) {
|
|
145
|
-
if (typeof target !== "string" || !target.trim()) throw createScheduleError("SCHEDULE_INVALID_TARGET", { details: invalidScheduleValueDetails("target", target) });
|
|
146
|
-
const definition = await loadScheduleDefinition(target);
|
|
147
|
-
if (!definition) throw createScheduleError("SCHEDULE_TARGET_NOT_FOUND");
|
|
148
|
-
if (definition.options?.allowRuntimeSchedules !== true) throw createScheduleError("SCHEDULE_TARGET_NOT_ELIGIBLE");
|
|
149
|
-
}
|
|
150
|
-
function assertRuntimeScheduleInputObject(input) {
|
|
151
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) throw createScheduleError("SCHEDULE_INVALID_INPUT", { details: invalidScheduleValueDetails("input", input) });
|
|
152
|
-
}
|
|
153
|
-
function assertRuntimeScheduleInputKeys(input, allowed) {
|
|
154
|
-
if (Object.keys(input).find((key) => !allowed.has(key))) throw createScheduleError("SCHEDULE_INVALID_INPUT", { details: invalidScheduleValueDetails("input", input) });
|
|
155
|
-
}
|
|
156
|
-
async function validateCreateInput(input) {
|
|
157
|
-
assertRuntimeScheduleInputObject(input);
|
|
158
|
-
assertRuntimeScheduleInputKeys(input, runtimeScheduleCreateInputKeys);
|
|
159
|
-
await assertRuntimeTarget(input.target);
|
|
160
|
-
validateRuntimeScheduleCron(input.cron);
|
|
161
|
-
if (input.id !== void 0) assertRuntimeScheduleId(input.id);
|
|
162
|
-
if (input.enabled !== void 0 && typeof input.enabled !== "boolean") throw createScheduleError("SCHEDULE_INVALID_ENABLED", { details: invalidScheduleValueDetails("enabled", input.enabled) });
|
|
163
|
-
if (input.timeZone !== void 0) validateRuntimeScheduleTimeZone(input.timeZone);
|
|
164
|
-
}
|
|
165
|
-
async function validateUpdateInput(input) {
|
|
166
|
-
assertRuntimeScheduleInputObject(input);
|
|
167
|
-
assertRuntimeScheduleInputKeys(input, runtimeScheduleUpdateInputKeys);
|
|
168
|
-
if (input.target !== void 0) await assertRuntimeTarget(input.target);
|
|
169
|
-
if (input.cron !== void 0) validateRuntimeScheduleCron(input.cron);
|
|
170
|
-
if (input.enabled !== void 0 && typeof input.enabled !== "boolean") throw createScheduleError("SCHEDULE_INVALID_ENABLED", { details: invalidScheduleValueDetails("enabled", input.enabled) });
|
|
171
|
-
if (input.timeZone !== void 0) validateRuntimeScheduleTimeZone(input.timeZone);
|
|
172
|
-
}
|
|
173
|
-
async function updateRuntimeSchedule(id, input) {
|
|
174
|
-
assertRuntimeScheduleId(id);
|
|
175
|
-
await validateUpdateInput(input);
|
|
176
|
-
const updated = await getRuntimeScheduleStore().update(id, {
|
|
177
|
-
...input,
|
|
178
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
179
|
-
});
|
|
180
|
-
if (!updated) throw createScheduleError("SCHEDULE_NOT_FOUND");
|
|
181
|
-
return updated;
|
|
182
|
-
}
|
|
183
|
-
const schedules = {
|
|
184
|
-
async create(input) {
|
|
185
|
-
await validateCreateInput(input);
|
|
186
|
-
const now = /* @__PURE__ */ new Date();
|
|
187
|
-
return await getRuntimeScheduleStore().create({
|
|
188
|
-
createdAt: now,
|
|
189
|
-
cron: input.cron,
|
|
190
|
-
enabled: input.enabled ?? true,
|
|
191
|
-
id: input.id ?? randomId("sched"),
|
|
192
|
-
...input.input !== void 0 ? { input: input.input } : {},
|
|
193
|
-
target: input.target,
|
|
194
|
-
...input.timeZone ? { timeZone: input.timeZone } : {},
|
|
195
|
-
updatedAt: now
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
async delete(id) {
|
|
199
|
-
return await getRuntimeScheduleStore().delete(id);
|
|
200
|
-
},
|
|
201
|
-
async disable(id) {
|
|
202
|
-
return await updateRuntimeSchedule(id, { enabled: false });
|
|
203
|
-
},
|
|
204
|
-
async enable(id) {
|
|
205
|
-
return await updateRuntimeSchedule(id, { enabled: true });
|
|
206
|
-
},
|
|
207
|
-
async get(id) {
|
|
208
|
-
return await getRuntimeScheduleStore().get(id);
|
|
209
|
-
},
|
|
210
|
-
async getRun(id) {
|
|
211
|
-
return await getScheduleRunStore().getRun(id);
|
|
212
|
-
},
|
|
213
|
-
async list() {
|
|
214
|
-
return await getRuntimeScheduleStore().list();
|
|
215
|
-
},
|
|
216
|
-
async listAttempts(runId) {
|
|
217
|
-
return await getScheduleRunStore().listAttempts(runId);
|
|
218
|
-
},
|
|
219
|
-
async listRuns() {
|
|
220
|
-
return await getScheduleRunStore().listRuns();
|
|
221
|
-
},
|
|
222
|
-
async run(id, options = {}) {
|
|
223
|
-
return await executeRuntimeSchedule({
|
|
224
|
-
id,
|
|
225
|
-
scheduledAt: options.scheduledAt
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
async update(id, input) {
|
|
229
|
-
return await updateRuntimeSchedule(id, input);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
//#endregion
|
|
233
|
-
export { validateRuntimeScheduleCron as n, schedules as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { t as DiscoveredScheduleDefinition } from "./types-Bcje4dLV.js";
|
|
2
|
-
|
|
3
|
-
//#region src/discovery.d.ts
|
|
4
|
-
declare function discoverScheduleDefinitions(options: {
|
|
5
|
-
mode?: "vite-suffix";
|
|
6
|
-
rootDir: string;
|
|
7
|
-
scanDirs?: string[];
|
|
8
|
-
serverDirs?: string[];
|
|
9
|
-
serverRootDir?: string;
|
|
10
|
-
} | {
|
|
11
|
-
mode: "server-schedules";
|
|
12
|
-
scanDirs: string[];
|
|
13
|
-
}): DiscoveredScheduleDefinition[];
|
|
14
|
-
//#endregion
|
|
15
|
-
export { discoverScheduleDefinitions as t };
|