@vite-hub/schedule 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +199 -65
- package/dist/definition-CMiOg1lg.js +111 -0
- package/dist/definition.d.ts +4 -6
- package/dist/definition.js +2 -42
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-in7mif5s.js +45 -0
- package/dist/execute-BJrgNgQ0.js +201 -0
- package/dist/index.d.ts +7 -51
- package/dist/index.js +2 -7
- package/dist/inspect-DTfAo5gS.js +118 -0
- package/dist/kv-storage-Bv9ocZT-.d.ts +18 -0
- package/dist/nuxt.d.ts +4 -6
- package/dist/nuxt.js +3 -1
- package/dist/operations-gk2qzhYV.js +131 -0
- package/dist/operations-tNUdj3G4.d.ts +212 -0
- package/dist/operations.d.ts +61 -0
- package/dist/operations.js +921 -0
- package/dist/registry-module.d.ts +0 -5
- package/dist/runtime/kv.d.ts +4 -0
- package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
- package/dist/runtime/process.d.ts +26 -5
- package/dist/runtime/process.js +337 -75
- package/dist/runtime/state.d.ts +8 -12
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +18 -12
- package/dist/runtime/static.js +2 -138
- package/dist/runtime.d.ts +36 -4
- package/dist/runtime.js +5 -3
- package/dist/state-DSxmHPn3.js +448 -0
- package/dist/static-6g82xguw.js +245 -0
- package/dist/store-QAOd8bxm.d.ts +11 -0
- package/dist/types-CHdV9FQU.d.ts +113 -0
- package/dist/vite-BAVyZ8hZ.d.ts +474 -0
- package/dist/vite-BJwZkMrn.js +5193 -0
- package/dist/vite.d.ts +2 -38
- package/dist/vite.js +2 -2
- package/dist/wait-until-BmIqRo4x.js +87 -0
- package/package.json +68 -22
- package/dist/client-BMFCy0dX.js +0 -233
- package/dist/discovery-BZlat3Kc.js +0 -776
- package/dist/due-Bbh4yIxq.js +0 -59
- package/dist/execute-ClFYvmp9.js +0 -211
- package/dist/runtime/driver.d.ts +0 -26
- package/dist/runtime/driver.js +0 -334
- 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-BX6_KiRw.js +0 -1218
- package/dist/wait-until-CR-JjIOb.js +0 -23
package/dist/vite.d.ts
CHANGED
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
concurrency?: number;
|
|
4
|
-
driver: "process";
|
|
5
|
-
intervalMs?: number;
|
|
6
|
-
prefix?: string;
|
|
7
|
-
}
|
|
8
|
-
interface ScheduleVitePluginOptions {
|
|
9
|
-
providerOutput?: "auto" | "standalone" | "nitro" | false;
|
|
10
|
-
projectRoot?: string;
|
|
11
|
-
runtime?: ScheduleProcessRuntimeOptions;
|
|
12
|
-
}
|
|
13
|
-
interface ScheduleNitroConfigOptions extends ScheduleVitePluginOptions {
|
|
14
|
-
command?: "build" | "serve";
|
|
15
|
-
nitro?: unknown;
|
|
16
|
-
root?: string;
|
|
17
|
-
/** @internal Framework-resolved server definition directories. */
|
|
18
|
-
serverDirs?: string[];
|
|
19
|
-
}
|
|
20
|
-
interface ScheduleVitePlugin {
|
|
21
|
-
name: string;
|
|
22
|
-
[hook: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
type NitroConfig = Record<string, unknown> & {
|
|
25
|
-
cloudflare?: {
|
|
26
|
-
wrangler?: {
|
|
27
|
-
triggers?: {
|
|
28
|
-
crons?: string[];
|
|
29
|
-
} & Record<string, unknown>;
|
|
30
|
-
} & Record<string, unknown>;
|
|
31
|
-
} & Record<string, unknown>;
|
|
32
|
-
modules?: unknown[];
|
|
33
|
-
plugins?: unknown[];
|
|
34
|
-
};
|
|
35
|
-
declare function createScheduleNitroConfig(options?: ScheduleNitroConfigOptions): Promise<NitroConfig | null>;
|
|
36
|
-
declare function hubSchedule(options?: ScheduleVitePluginOptions): ScheduleVitePlugin;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { ScheduleNitroConfigOptions, ScheduleProcessRuntimeOptions, ScheduleVitePlugin, ScheduleVitePluginOptions, createScheduleNitroConfig, hubSchedule };
|
|
1
|
+
import { _ as ScheduleContributionContext, a as createScheduleNitroConfig, c as ScheduleInspectionOptions, d as ScheduleDiscoveryOptions, f as contributedScheduleSource, g as ScheduleContribution, h as ScheduleContributingPlugin, i as ScheduleVitePluginOptions, l as inspectScheduleDefinitions, m as CollectedScheduleContribution, n as ScheduleProcessRuntimeOptions, o as hubSchedule, p as discoverScheduleDefinitions, r as ScheduleVitePlugin, s as readScheduleDefinitionCrons, t as ScheduleNitroConfigOptions, u as scheduleConsoleSection, v as ScheduleContributionFactory, y as collectScheduleContributions } from "./vite-BAVyZ8hZ.js";
|
|
2
|
+
export { type CollectedScheduleContribution, type ScheduleContributingPlugin, type ScheduleContribution, type ScheduleContributionContext, type ScheduleContributionFactory, type ScheduleDiscoveryOptions, type ScheduleInspectionOptions, ScheduleNitroConfigOptions, ScheduleProcessRuntimeOptions, ScheduleVitePlugin, ScheduleVitePluginOptions, collectScheduleContributions, contributedScheduleSource, createScheduleNitroConfig, discoverScheduleDefinitions, hubSchedule, inspectScheduleDefinitions, readScheduleDefinitionCrons, scheduleConsoleSection };
|
package/dist/vite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as hubSchedule, t as createScheduleNitroConfig } from "./vite-
|
|
2
|
-
export { createScheduleNitroConfig, hubSchedule };
|
|
1
|
+
import { a as scheduleConsoleSection, c as collectScheduleContributions, i as inspectScheduleDefinitions, n as hubSchedule, o as contributedScheduleSource, r as readScheduleDefinitionCrons, s as discoverScheduleDefinitions, t as createScheduleNitroConfig } from "./vite-BJwZkMrn.js";
|
|
2
|
+
export { collectScheduleContributions, contributedScheduleSource, createScheduleNitroConfig, discoverScheduleDefinitions, hubSchedule, inspectScheduleDefinitions, readScheduleDefinitionCrons, scheduleConsoleSection };
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
function isScheduleDate(value) {
|
|
38
|
+
try {
|
|
39
|
+
return !Number.isNaN(Date.prototype.getTime.call(value));
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function validateScheduledAt(scheduledAt) {
|
|
45
|
+
const value = scheduledAt ?? /* @__PURE__ */ new Date();
|
|
46
|
+
if (!isScheduleDate(value)) throw createScheduleError("SCHEDULE_INVALID_SCHEDULED_AT", { details: invalidScheduleValueDetails("scheduledAt", value) });
|
|
47
|
+
return new Date(Date.prototype.getTime.call(value));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/runtime/wait-until.ts
|
|
51
|
+
function createLocalWaitUntil() {
|
|
52
|
+
const pending = /* @__PURE__ */ new Set();
|
|
53
|
+
let error;
|
|
54
|
+
let failed = false;
|
|
55
|
+
return {
|
|
56
|
+
async flush() {
|
|
57
|
+
while (pending.size > 0) await Promise.allSettled(pending);
|
|
58
|
+
if (failed) throw error;
|
|
59
|
+
},
|
|
60
|
+
waitUntil(value) {
|
|
61
|
+
const promise = Promise.resolve(value);
|
|
62
|
+
pending.add(promise);
|
|
63
|
+
promise.then(() => pending.delete(promise), (reason) => {
|
|
64
|
+
pending.delete(promise);
|
|
65
|
+
if (!failed) error = reason;
|
|
66
|
+
failed = true;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Complete local deferred work while preserving a handler's failure over a deferred failure. */
|
|
72
|
+
async function runWithScheduleWaitUntil(run, hostWaitUntil) {
|
|
73
|
+
if (hostWaitUntil) return await run(hostWaitUntil);
|
|
74
|
+
const local = createLocalWaitUntil();
|
|
75
|
+
try {
|
|
76
|
+
const result = await run(local.waitUntil);
|
|
77
|
+
await local.flush();
|
|
78
|
+
return result;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
try {
|
|
81
|
+
await local.flush();
|
|
82
|
+
} catch {}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { invalidScheduleValueDetails as a, createScheduleError as i, isScheduleDate as n, validateScheduledAt as r, runWithScheduleWaitUntil as t };
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/schedule",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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",
|
|
11
|
+
"nuxt-module",
|
|
7
12
|
"schedule",
|
|
13
|
+
"typescript",
|
|
14
|
+
"vercel",
|
|
8
15
|
"vite",
|
|
9
16
|
"vitehub"
|
|
10
17
|
],
|
|
11
|
-
"homepage": "https://
|
|
18
|
+
"homepage": "https://vitehub.dev",
|
|
12
19
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
13
20
|
"license": "Apache-2.0",
|
|
14
21
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -25,35 +32,74 @@
|
|
|
25
32
|
"sideEffects": false,
|
|
26
33
|
"types": "./dist/index.d.ts",
|
|
27
34
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"./
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./nuxt": {
|
|
41
|
+
"types": "./dist/nuxt.d.ts",
|
|
42
|
+
"import": "./dist/nuxt.js",
|
|
43
|
+
"default": "./dist/nuxt.js"
|
|
44
|
+
},
|
|
45
|
+
"./operations": {
|
|
46
|
+
"types": "./dist/operations.d.ts",
|
|
47
|
+
"import": "./dist/operations.js",
|
|
48
|
+
"default": "./dist/operations.js"
|
|
49
|
+
},
|
|
50
|
+
"./runtime": {
|
|
51
|
+
"types": "./dist/runtime.d.ts",
|
|
52
|
+
"import": "./dist/runtime.js",
|
|
53
|
+
"default": "./dist/runtime.js"
|
|
54
|
+
},
|
|
55
|
+
"./runtime/kv": {
|
|
56
|
+
"types": "./dist/runtime/kv.d.ts",
|
|
57
|
+
"import": "./dist/runtime/kv.js",
|
|
58
|
+
"default": "./dist/runtime/kv.js"
|
|
59
|
+
},
|
|
60
|
+
"./runtime/process": {
|
|
61
|
+
"types": "./dist/runtime/process.d.ts",
|
|
62
|
+
"import": "./dist/runtime/process.js",
|
|
63
|
+
"default": "./dist/runtime/process.js"
|
|
64
|
+
},
|
|
65
|
+
"./runtime/state": {
|
|
66
|
+
"types": "./dist/runtime/state.d.ts",
|
|
67
|
+
"import": "./dist/runtime/state.js",
|
|
68
|
+
"default": "./dist/runtime/state.js"
|
|
69
|
+
},
|
|
70
|
+
"./runtime/static": {
|
|
71
|
+
"types": "./dist/runtime/static.d.ts",
|
|
72
|
+
"import": "./dist/runtime/static.js",
|
|
73
|
+
"default": "./dist/runtime/static.js"
|
|
74
|
+
},
|
|
75
|
+
"./vite": {
|
|
76
|
+
"types": "./dist/vite.d.ts",
|
|
77
|
+
"import": "./dist/vite.js",
|
|
78
|
+
"default": "./dist/vite.js"
|
|
79
|
+
},
|
|
36
80
|
"./package.json": "./package.json"
|
|
37
81
|
},
|
|
38
82
|
"dependencies": {
|
|
83
|
+
"@vite-hub/runtime": "0.1.0",
|
|
39
84
|
"cron-schedule": "^6.0.0",
|
|
40
|
-
"effect": "4.0.0-
|
|
41
|
-
"esbuild": "^0.28.
|
|
42
|
-
"
|
|
85
|
+
"effect": "4.0.0-rc.112",
|
|
86
|
+
"esbuild": "^0.28.2",
|
|
87
|
+
"nostics": "1.3.0",
|
|
88
|
+
"valibot": "^1.5.0"
|
|
43
89
|
},
|
|
44
90
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^24.
|
|
46
|
-
"
|
|
91
|
+
"@types/node": "^24.19.1",
|
|
92
|
+
"@vite-hub/kv": "0.1.0",
|
|
93
|
+
"publint": "^0.3.25",
|
|
47
94
|
"typescript": "^6.0.3",
|
|
48
|
-
"vite": "^8.
|
|
49
|
-
"vite-plus": "^0.
|
|
50
|
-
"vitest": "^4.1.
|
|
51
|
-
"@vite-hub/kv": "0.0.3",
|
|
95
|
+
"vite": "^8.2.2",
|
|
96
|
+
"vite-plus": "^0.3.3",
|
|
97
|
+
"vitest": "^4.1.11",
|
|
52
98
|
"@vite-hub/internal": "0.0.1"
|
|
53
99
|
},
|
|
54
100
|
"peerDependencies": {
|
|
55
|
-
"vite": "
|
|
56
|
-
"
|
|
101
|
+
"@vite-hub/kv": "0.1.0",
|
|
102
|
+
"vite": ">=8.0.0"
|
|
57
103
|
},
|
|
58
104
|
"peerDependenciesMeta": {
|
|
59
105
|
"@vite-hub/kv": {
|
|
@@ -69,7 +115,7 @@
|
|
|
69
115
|
"scripts": {
|
|
70
116
|
"build": "vp pack",
|
|
71
117
|
"dev": "vp pack --watch",
|
|
72
|
-
"typecheck": "
|
|
118
|
+
"typecheck": "vp run --cache -t @vite-hub/schedule#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
73
119
|
"test": "vp run -t @vite-hub/schedule#build && vp test"
|
|
74
120
|
}
|
|
75
121
|
}
|
package/dist/client-BMFCy0dX.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { n as executeRuntimeSchedule, o as randomId } from "./execute-ClFYvmp9.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 };
|