@vite-hub/schedule 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -1
- package/dist/client-BJ33CRLg.js +401 -0
- package/dist/discovery-Di9MD-SN.js +574 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +152 -0
- package/dist/module-C_j2ahfg.js +1767 -0
- package/dist/nitro.d.ts +6 -0
- package/dist/nitro.js +2 -0
- package/dist/registry-module.d.ts +9 -0
- package/dist/runtime/state.d.ts +13 -0
- package/dist/runtime/state.js +2 -0
- package/dist/runtime/static.d.ts +17 -0
- package/dist/runtime/static.js +15 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +3 -0
- package/dist/state-DoONzfij.js +441 -0
- package/dist/store-CeeSsInC.d.ts +63 -0
- package/dist/types-DOjXDq0s.d.ts +111 -0
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +110 -0
- package/package.json +70 -5
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface ScheduleRunContext {
|
|
3
|
+
id: string;
|
|
4
|
+
attemptId?: string;
|
|
5
|
+
runId?: string;
|
|
6
|
+
scheduleId?: string;
|
|
7
|
+
scheduledAt: Date;
|
|
8
|
+
target?: ScheduleTargetName;
|
|
9
|
+
}
|
|
10
|
+
type ScheduleHandler<TResult = unknown> = (context: ScheduleRunContext) => TResult | Promise<TResult>;
|
|
11
|
+
interface ScheduleDefinitionInput<TResult = unknown> {
|
|
12
|
+
allowRuntimeSchedules?: boolean;
|
|
13
|
+
cron: string;
|
|
14
|
+
handler: ScheduleHandler<TResult>;
|
|
15
|
+
}
|
|
16
|
+
interface ScheduleDefinitionOptions {
|
|
17
|
+
allowRuntimeSchedules?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface ScheduleDefinition<TResult = unknown> {
|
|
20
|
+
cron: string;
|
|
21
|
+
handler: ScheduleHandler<TResult>;
|
|
22
|
+
options?: ScheduleDefinitionOptions;
|
|
23
|
+
}
|
|
24
|
+
interface ScheduleDefinitionRegistry {
|
|
25
|
+
[name: string]: () => Promise<{
|
|
26
|
+
default?: ScheduleDefinition;
|
|
27
|
+
} | ScheduleDefinition>;
|
|
28
|
+
}
|
|
29
|
+
type ScheduleTargetName = string & {};
|
|
30
|
+
interface RuntimeScheduleMetadata {
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
}
|
|
34
|
+
interface RuntimeScheduleRecord extends RuntimeScheduleMetadata {
|
|
35
|
+
cron: string;
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
id: string;
|
|
38
|
+
target: ScheduleTargetName;
|
|
39
|
+
}
|
|
40
|
+
interface RuntimeScheduleCreateInput<TTarget extends ScheduleTargetName = ScheduleTargetName> {
|
|
41
|
+
cron: string;
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
id?: string;
|
|
44
|
+
target: TTarget;
|
|
45
|
+
}
|
|
46
|
+
interface RuntimeScheduleUpdateInput<TTarget extends ScheduleTargetName = ScheduleTargetName> {
|
|
47
|
+
cron?: string;
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
target?: TTarget;
|
|
50
|
+
}
|
|
51
|
+
interface RuntimeScheduleStore {
|
|
52
|
+
create: (record: RuntimeScheduleRecord) => Promise<RuntimeScheduleRecord> | RuntimeScheduleRecord;
|
|
53
|
+
delete: (id: string) => Promise<boolean> | boolean;
|
|
54
|
+
get: (id: string) => Promise<RuntimeScheduleRecord | undefined> | RuntimeScheduleRecord | undefined;
|
|
55
|
+
list: () => Promise<RuntimeScheduleRecord[]> | RuntimeScheduleRecord[];
|
|
56
|
+
update: (id: string, patch: RuntimeScheduleUpdateInput & {
|
|
57
|
+
updatedAt: Date;
|
|
58
|
+
}) => Promise<RuntimeScheduleRecord | undefined> | RuntimeScheduleRecord | undefined;
|
|
59
|
+
}
|
|
60
|
+
type ScheduleRunStatus = "pending" | "running" | "succeeded" | "failed";
|
|
61
|
+
type ScheduleRunAttemptStatus = "running" | "succeeded" | "failed";
|
|
62
|
+
interface ScheduleRunError {
|
|
63
|
+
message: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
stack?: string;
|
|
66
|
+
}
|
|
67
|
+
interface ScheduleRunRecord {
|
|
68
|
+
attemptCount: number;
|
|
69
|
+
completedAt?: Date;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
error?: ScheduleRunError;
|
|
72
|
+
id: string;
|
|
73
|
+
scheduleId: string;
|
|
74
|
+
scheduledAt: Date;
|
|
75
|
+
startedAt?: Date;
|
|
76
|
+
status: ScheduleRunStatus;
|
|
77
|
+
target: ScheduleTargetName;
|
|
78
|
+
updatedAt: Date;
|
|
79
|
+
}
|
|
80
|
+
interface ScheduleRunAttemptRecord {
|
|
81
|
+
completedAt?: Date;
|
|
82
|
+
createdAt: Date;
|
|
83
|
+
error?: ScheduleRunError;
|
|
84
|
+
id: string;
|
|
85
|
+
runId: string;
|
|
86
|
+
startedAt: Date;
|
|
87
|
+
status: ScheduleRunAttemptStatus;
|
|
88
|
+
updatedAt: Date;
|
|
89
|
+
}
|
|
90
|
+
interface ScheduleRunStore {
|
|
91
|
+
createAttempt: (attempt: ScheduleRunAttemptRecord) => Promise<ScheduleRunAttemptRecord> | ScheduleRunAttemptRecord;
|
|
92
|
+
createRun: (run: ScheduleRunRecord) => Promise<ScheduleRunRecord> | ScheduleRunRecord;
|
|
93
|
+
getAttempt: (id: string) => Promise<ScheduleRunAttemptRecord | undefined> | ScheduleRunAttemptRecord | undefined;
|
|
94
|
+
getRun: (id: string) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
|
|
95
|
+
listAttempts: (runId: string) => Promise<ScheduleRunAttemptRecord[]> | ScheduleRunAttemptRecord[];
|
|
96
|
+
listRuns: () => Promise<ScheduleRunRecord[]> | ScheduleRunRecord[];
|
|
97
|
+
updateAttempt: (id: string, patch: Partial<Pick<ScheduleRunAttemptRecord, "completedAt" | "error" | "status">> & {
|
|
98
|
+
updatedAt: Date;
|
|
99
|
+
}) => Promise<ScheduleRunAttemptRecord | undefined> | ScheduleRunAttemptRecord | undefined;
|
|
100
|
+
updateRun: (id: string, patch: Partial<Pick<ScheduleRunRecord, "attemptCount" | "completedAt" | "error" | "startedAt" | "status">> & {
|
|
101
|
+
updatedAt: Date;
|
|
102
|
+
}) => Promise<ScheduleRunRecord | undefined> | ScheduleRunRecord | undefined;
|
|
103
|
+
}
|
|
104
|
+
interface DiscoveredScheduleDefinition {
|
|
105
|
+
allowRuntimeSchedules?: boolean;
|
|
106
|
+
handler: string;
|
|
107
|
+
name: string;
|
|
108
|
+
source?: "nitro-server-schedules" | "vite-suffix";
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { ScheduleRunStatus as _, RuntimeScheduleStore as a, ScheduleDefinitionInput as c, ScheduleHandler as d, ScheduleRunAttemptRecord as f, ScheduleRunRecord as g, ScheduleRunError as h, RuntimeScheduleRecord as i, ScheduleDefinitionOptions as l, ScheduleRunContext as m, RuntimeScheduleCreateInput as n, RuntimeScheduleUpdateInput as o, ScheduleRunAttemptStatus as p, RuntimeScheduleMetadata as r, ScheduleDefinition as s, DiscoveredScheduleDefinition as t, ScheduleDefinitionRegistry as u, ScheduleRunStore as v, ScheduleTargetName as y };
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { i as createRuntimeRegistryContents, t as discoverScheduleDefinitions } from "./discovery-Di9MD-SN.js";
|
|
2
|
+
import { a as schedulePackageName, i as generateProviderOutputs, n as SCHEDULE_TARGETS_ID, o as shouldSkipViteProviderBuild, r as createScheduleTargetsContents, t as scheduleNitroModule } from "./module-C_j2ahfg.js";
|
|
3
|
+
import { normalize, resolve } from "node:path";
|
|
4
|
+
const VITEHUB_MODES = {
|
|
5
|
+
e2e: "e2e",
|
|
6
|
+
blob: "blob",
|
|
7
|
+
chat: "chat",
|
|
8
|
+
db: "db",
|
|
9
|
+
env: "env",
|
|
10
|
+
kv: "kv",
|
|
11
|
+
queue: "queue",
|
|
12
|
+
schedule: "schedule",
|
|
13
|
+
sandbox: "sandbox",
|
|
14
|
+
workspace: "workspace",
|
|
15
|
+
workflow: "workflow"
|
|
16
|
+
};
|
|
17
|
+
function isViteCli(argv) {
|
|
18
|
+
return argv.some((arg) => /(?:^|[/\\])vite(?:\.[cm]?js)?$/.test(arg) || arg === "vite");
|
|
19
|
+
}
|
|
20
|
+
function getViteCliMode(argv = process.argv) {
|
|
21
|
+
if (!isViteCli(argv)) return;
|
|
22
|
+
const modes = new Set(Object.values(VITEHUB_MODES));
|
|
23
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
24
|
+
const arg = argv[index];
|
|
25
|
+
const mode = arg === "--mode" || arg === "-m" ? argv[index + 1] : arg.startsWith("--mode=") ? arg.slice(7) : void 0;
|
|
26
|
+
if (mode && modes.has(mode)) return mode;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getViteMode(env = process.env) {
|
|
30
|
+
return env["VITEHUB_VITE_MODE"] ?? getViteCliMode();
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region ../internal/src/build/vite.ts
|
|
34
|
+
function createNoExternalMerger(packageName) {
|
|
35
|
+
return (current) => {
|
|
36
|
+
if (current === true) return true;
|
|
37
|
+
if (!current) return [packageName];
|
|
38
|
+
const values = Array.isArray(current) ? current : [current];
|
|
39
|
+
return values.includes(packageName) ? values : [...values, packageName];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isServerEnvironment(name, config) {
|
|
43
|
+
return name === "ssr" || config.consumer === "server";
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/vite.ts
|
|
47
|
+
const SCHEDULE_VITE_PLUGIN_NAME = "@vite-hub/schedule/vite";
|
|
48
|
+
const SCHEDULE_REGISTRY_ID = "#vitehub/schedule/registry";
|
|
49
|
+
const RESOLVED_SCHEDULE_REGISTRY_ID = "\0#vitehub/schedule/registry";
|
|
50
|
+
const RESOLVED_SCHEDULE_TARGETS_ID = `\0${SCHEDULE_TARGETS_ID}`;
|
|
51
|
+
const registryImportAnchor = ".vitehub/schedule/registry.js";
|
|
52
|
+
const mergeNoExternal = createNoExternalMerger(schedulePackageName);
|
|
53
|
+
function resolveStringAliases(config) {
|
|
54
|
+
const aliases = {};
|
|
55
|
+
for (const alias of config.resolve.alias) if (typeof alias.find === "string" && typeof alias.replacement === "string") aliases[alias.find] = alias.replacement;
|
|
56
|
+
return aliases;
|
|
57
|
+
}
|
|
58
|
+
function hubSchedule() {
|
|
59
|
+
let resolved;
|
|
60
|
+
function discoverViteSchedules() {
|
|
61
|
+
if (!resolved) return [];
|
|
62
|
+
return discoverScheduleDefinitions({
|
|
63
|
+
mode: "vite-suffix",
|
|
64
|
+
rootDir: resolved.root
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function createRegistryContents() {
|
|
68
|
+
const definitions = discoverViteSchedules();
|
|
69
|
+
return createRuntimeRegistryContents(resolved ? resolve(resolved.root, registryImportAnchor) : registryImportAnchor, definitions);
|
|
70
|
+
}
|
|
71
|
+
function createTargetsContents() {
|
|
72
|
+
return createScheduleTargetsContents(discoverViteSchedules(), { types: false });
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
name: SCHEDULE_VITE_PLUGIN_NAME,
|
|
76
|
+
nitro: scheduleNitroModule,
|
|
77
|
+
configResolved(config) {
|
|
78
|
+
resolved = config;
|
|
79
|
+
},
|
|
80
|
+
configEnvironment(name, config) {
|
|
81
|
+
if (!isServerEnvironment(name, config)) return;
|
|
82
|
+
return { resolve: { noExternal: mergeNoExternal(config.resolve?.noExternal) } };
|
|
83
|
+
},
|
|
84
|
+
handleHotUpdate(context) {
|
|
85
|
+
if (!/\.schedule\.(?:c|m)?[jt]s$/i.test(normalize(context.file))) return;
|
|
86
|
+
const registryModule = context.server.moduleGraph.getModuleById(RESOLVED_SCHEDULE_REGISTRY_ID);
|
|
87
|
+
if (registryModule) context.server.moduleGraph.invalidateModule(registryModule);
|
|
88
|
+
const targetsModule = context.server.moduleGraph.getModuleById(RESOLVED_SCHEDULE_TARGETS_ID);
|
|
89
|
+
if (targetsModule) context.server.moduleGraph.invalidateModule(targetsModule);
|
|
90
|
+
},
|
|
91
|
+
resolveId(id) {
|
|
92
|
+
if (id === SCHEDULE_REGISTRY_ID) return RESOLVED_SCHEDULE_REGISTRY_ID;
|
|
93
|
+
if (id === "#vitehub/schedule/targets") return RESOLVED_SCHEDULE_TARGETS_ID;
|
|
94
|
+
},
|
|
95
|
+
load(id) {
|
|
96
|
+
if (id === RESOLVED_SCHEDULE_REGISTRY_ID) return createRegistryContents();
|
|
97
|
+
if (id === RESOLVED_SCHEDULE_TARGETS_ID) return createTargetsContents();
|
|
98
|
+
},
|
|
99
|
+
async closeBundle() {
|
|
100
|
+
if (!resolved || shouldSkipViteProviderBuild(resolved.command, getViteMode())) return;
|
|
101
|
+
await generateProviderOutputs({
|
|
102
|
+
bundleAlias: resolveStringAliases(resolved),
|
|
103
|
+
clientOutDir: resolved.build.outDir,
|
|
104
|
+
rootDir: resolved.root
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { hubSchedule };
|
package/package.json
CHANGED
|
@@ -1,9 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/schedule",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Schedule primitives and definition discovery for ViteHub.",
|
|
5
|
+
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
7
|
+
"homepage": "https://github.com/vite-hub/vitehub#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/vite-hub/vitehub.git",
|
|
11
|
+
"directory": "packages/schedule"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"vitehub",
|
|
16
|
+
"vite",
|
|
17
|
+
"nitro",
|
|
18
|
+
"schedule",
|
|
19
|
+
"cron"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"cron-schedule": "^6.0.0",
|
|
23
|
+
"esbuild": "^0.28.0"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js",
|
|
30
|
+
"./nitro": "./dist/nitro.js",
|
|
31
|
+
"./runtime": "./dist/runtime.js",
|
|
32
|
+
"./runtime/state": "./dist/runtime/state.js",
|
|
33
|
+
"./runtime/static": "./dist/runtime/static.js",
|
|
34
|
+
"./vite": "./dist/vite.js",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"package.json"
|
|
40
|
+
],
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"nitro": "^3.0.0-0",
|
|
43
|
+
"vite": "^8.0.0",
|
|
44
|
+
"@vite-hub/kv": "0.0.1"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"@vite-hub/kv": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"nitro": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"vite": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^25.6.0",
|
|
59
|
+
"nitro": "3.0.260311-beta",
|
|
60
|
+
"publint": "^0.3.15",
|
|
61
|
+
"tsdown": "^0.21.8",
|
|
62
|
+
"typescript": "^6.0.2",
|
|
63
|
+
"vite": "^8.0.8",
|
|
64
|
+
"vitest": "^4.1.4",
|
|
65
|
+
"@vite-hub/internal": "0.0.1",
|
|
66
|
+
"@vite-hub/kv": "0.0.1"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsdown --tsconfig tsconfig.build.json",
|
|
70
|
+
"dev": "tsdown --watch",
|
|
71
|
+
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
72
|
+
"test": "pnpm --dir . build && vitest run"
|
|
8
73
|
}
|
|
9
|
-
}
|
|
74
|
+
}
|