@vite-hub/schedule 0.0.2 → 0.0.3
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 +1 -1
- package/dist/{client-B3cyh-BG.js → client-BMFCy0dX.js} +2 -2
- package/dist/{discovery-MXY52MTU.js → discovery-BZlat3Kc.js} +12 -3
- package/dist/{execute-BnR8oEKq.js → execute-ClFYvmp9.js} +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +6 -5
- package/dist/kv-BJ1I9IlJ.js +6 -0
- package/dist/kv-storage-DWinmLLy.js +30 -0
- package/dist/nuxt.js +1 -1
- package/dist/runtime/driver.js +2 -2
- package/dist/runtime/state.js +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +2 -2
- package/dist/{state-BcEhBV8v.js → state-By7WU_ks.js} +10 -26
- package/dist/{store-D2zUgEDc.d.ts → store-t-74rsM_.d.ts} +12 -2
- package/dist/{vite-Dfeg9ZY3.js → vite-BX6_KiRw.js} +22 -25
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
pnpm add @vite-hub/schedule
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Add `@vite-hub/kv` when
|
|
18
|
+
Add `@vite-hub/kv` when using the default KV-backed stores or the generated Process Runtime. Static Schedules, memory stores, and custom `ScheduleKVStorage` implementations do not require it.
|
|
19
19
|
|
|
20
20
|
## Minimal API
|
|
21
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as executeRuntimeSchedule, o as randomId } from "./execute-
|
|
2
|
-
import { h as invalidScheduleValueDetails, i as loadScheduleDefinition, m as createScheduleError, n as getScheduleRunStore, p as assertRuntimeScheduleId, t as getRuntimeScheduleStore } from "./state-
|
|
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
3
|
//#region ../internal/src/runtime/time-zone.ts
|
|
4
4
|
const slashlessIanaTimeZones = new Set([
|
|
5
5
|
"CET",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import "node:fs/promises";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import "node:url";
|
|
5
5
|
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
6
6
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
@@ -291,6 +291,14 @@ function createRuntimeRegistryContents(registryFile, definitions) {
|
|
|
291
291
|
""
|
|
292
292
|
].join("\n");
|
|
293
293
|
}
|
|
294
|
+
async function writeRuntimeRegistryFile(registryFile, definitions) {
|
|
295
|
+
await writeFileIfChanged(registryFile, createRuntimeRegistryContents(registryFile, definitions));
|
|
296
|
+
}
|
|
297
|
+
async function writeFileIfChanged(file, contents) {
|
|
298
|
+
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
299
|
+
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
300
|
+
await writeFile(file, contents, "utf8");
|
|
301
|
+
}
|
|
294
302
|
//#endregion
|
|
295
303
|
//#region ../internal/src/source-scanner.ts
|
|
296
304
|
function isQuote(char) {
|
|
@@ -757,11 +765,12 @@ function discoverScheduleDefinitions(options) {
|
|
|
757
765
|
normalizeName: normalizeDirectoryScheduleName
|
|
758
766
|
})]);
|
|
759
767
|
const roots = resolveDefinitionScanRoots(options.rootDir, options.scanDirs);
|
|
760
|
-
const
|
|
768
|
+
const serverRoots = resolveDefinitionScanRoots(options.serverRootDir || options.rootDir, options.scanDirs);
|
|
769
|
+
const serverScanDirs = options.serverDirs ?? serverRoots.map((root) => resolve(root, "server"));
|
|
761
770
|
return mergeDefinitions("schedule", discoverDefinitions("schedule", [createSuffixDefinitionSource("vite-suffix", roots, scheduleSuffixPattern, normalizeSuffixScheduleName, { createDefinition: createDiscoveredScheduleDefinition("vite-suffix") })]), discoverDefinitions("schedule", [createDirectoryDefinitionSource("server-schedules", serverScanDirs, "schedules", {
|
|
762
771
|
createDefinition: createDiscoveredScheduleDefinition("server-schedules"),
|
|
763
772
|
normalizeName: normalizeDirectoryScheduleName
|
|
764
773
|
})]));
|
|
765
774
|
}
|
|
766
775
|
//#endregion
|
|
767
|
-
export {
|
|
776
|
+
export { writeRuntimeRegistryFile as a, createRuntimeRegistryContents as i, findDefaultExportCall as n, createImportPath as o, readObjectProperty as r, ensureGeneratedDir as s, discoverScheduleDefinitions as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as invalidScheduleValueDetails, i as loadScheduleDefinition, m as createScheduleError, n as getScheduleRunStore, p as assertRuntimeScheduleId, t as getRuntimeScheduleStore } from "./state-
|
|
1
|
+
import { h as invalidScheduleValueDetails, i as loadScheduleDefinition, m as createScheduleError, n as getScheduleRunStore, p as assertRuntimeScheduleId, t as getRuntimeScheduleStore } from "./state-By7WU_ks.js";
|
|
2
2
|
import { t as isRuntimeScheduleDue } from "./due-Bbh4yIxq.js";
|
|
3
3
|
import { t as createLocalWaitUntil } from "./wait-until-CR-JjIOb.js";
|
|
4
4
|
//#region ../internal/src/runtime/random.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./registry-module.d.ts" />
|
|
2
2
|
import { C as ScheduleTargetName, S as ScheduleTargetDefinitionInput, _ as ScheduleRunError, a as RuntimeScheduleStore, b as ScheduleRunStore, c as ScheduleDefinition, d as ScheduleDefinitionRegistry, f as ScheduleHandler, g as ScheduleRunContext, h as ScheduleRunAttemptStatus, i as RuntimeScheduleRecord, l as ScheduleDefinitionInput, m as ScheduleRunAttemptRecord, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, p as ScheduleRegistryDefinition, r as RuntimeScheduleMetadata, t as DiscoveredScheduleDefinition, v as ScheduleRunRecord, x as ScheduleTargetDefinition, y as ScheduleRunStatus } from "./types-Bcje4dLV.js";
|
|
3
3
|
import { defineSchedule, defineScheduleTarget } from "./definition.js";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as createMemoryScheduleRunStore, c as schedules, i as createMemoryRuntimeScheduleStore, l as validateRuntimeScheduleCron, n as createKVRuntimeScheduleStore, o as ScheduleKVStorage, r as createKVScheduleRunStore, s as createScheduleKVStorage, t as KVScheduleStoreOptions } from "./store-t-74rsM_.js";
|
|
5
5
|
import { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry } from "./runtime/state.js";
|
|
6
6
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@ declare function discoverScheduleDefinitions(options: {
|
|
|
10
10
|
mode?: "vite-suffix";
|
|
11
11
|
rootDir: string;
|
|
12
12
|
scanDirs?: string[];
|
|
13
|
+
serverDirs?: string[];
|
|
13
14
|
serverRootDir?: string;
|
|
14
15
|
} | {
|
|
15
16
|
mode: "server-schedules";
|
|
@@ -60,4 +61,4 @@ type ScheduleErrorDetails = {
|
|
|
60
61
|
valueType: ScheduleErrorValueType;
|
|
61
62
|
};
|
|
62
63
|
//#endregion
|
|
63
|
-
export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunRecord, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleTargetDefinition, type ScheduleTargetDefinitionInput, type ScheduleTargetName, type ScheduleValidationErrorCode, createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleRun, defineSchedule, defineScheduleTarget, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
|
64
|
+
export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunRecord, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleTargetDefinition, type ScheduleTargetDefinitionInput, type ScheduleTargetName, type ScheduleValidationErrorCode, createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, defineSchedule, defineScheduleTarget, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineSchedule, defineScheduleTarget } from "./definition.js";
|
|
2
|
-
import { t as discoverScheduleDefinitions } from "./discovery-
|
|
3
|
-
import { a as executeStaticSchedule, i as executeSchedule, n as executeRuntimeSchedule, t as createScheduleRun } from "./execute-
|
|
4
|
-
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, f as createMemoryScheduleRunStore, i as loadScheduleDefinition, l as createKVRuntimeScheduleStore, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore, u as createKVScheduleRunStore } from "./state-
|
|
5
|
-
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-
|
|
6
|
-
|
|
2
|
+
import { t as discoverScheduleDefinitions } from "./discovery-BZlat3Kc.js";
|
|
3
|
+
import { a as executeStaticSchedule, i as executeSchedule, n as executeRuntimeSchedule, t as createScheduleRun } from "./execute-ClFYvmp9.js";
|
|
4
|
+
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, f as createMemoryScheduleRunStore, i as loadScheduleDefinition, l as createKVRuntimeScheduleStore, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore, u as createKVScheduleRunStore } from "./state-By7WU_ks.js";
|
|
5
|
+
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-BMFCy0dX.js";
|
|
6
|
+
import { t as createScheduleKVStorage } from "./kv-storage-DWinmLLy.js";
|
|
7
|
+
export { createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, defineSchedule, defineScheduleTarget, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/runtime/kv-storage.ts
|
|
2
|
+
function createScheduleKVStorage(kvStore) {
|
|
3
|
+
return {
|
|
4
|
+
async del(key) {
|
|
5
|
+
const [error] = await kvStore.del(key);
|
|
6
|
+
if (error) throw error;
|
|
7
|
+
},
|
|
8
|
+
async get(key) {
|
|
9
|
+
const [error, value] = await kvStore.get(key);
|
|
10
|
+
if (error) throw error;
|
|
11
|
+
return value;
|
|
12
|
+
},
|
|
13
|
+
async has(key) {
|
|
14
|
+
const [error, value] = await kvStore.has(key);
|
|
15
|
+
if (error) throw error;
|
|
16
|
+
return value ?? false;
|
|
17
|
+
},
|
|
18
|
+
async keys(base) {
|
|
19
|
+
const [error, value] = await kvStore.keys(base);
|
|
20
|
+
if (error) throw error;
|
|
21
|
+
return value ?? [];
|
|
22
|
+
},
|
|
23
|
+
async set(key, value) {
|
|
24
|
+
const [error] = await kvStore.set(key, value);
|
|
25
|
+
if (error) throw error;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createScheduleKVStorage as t };
|
package/dist/nuxt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as hubSchedule, t as createScheduleNitroConfig } from "./vite-
|
|
1
|
+
import { n as hubSchedule, t as createScheduleNitroConfig } from "./vite-BX6_KiRw.js";
|
|
2
2
|
//#region src/nuxt.ts
|
|
3
3
|
function isScheduleVitePlugin(value) {
|
|
4
4
|
return Boolean(value && typeof value === "object" && value.name === "@vite-hub/schedule/vite");
|
package/dist/runtime/driver.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as executeStaticSchedule, r as executeRuntimeScheduleWake } from "../execute-
|
|
2
|
-
import { c as setScheduleRuntimeRegistry, m as createScheduleError, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore } from "../state-
|
|
1
|
+
import { a as executeStaticSchedule, r as executeRuntimeScheduleWake } from "../execute-ClFYvmp9.js";
|
|
2
|
+
import { c as setScheduleRuntimeRegistry, m as createScheduleError, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore } from "../state-By7WU_ks.js";
|
|
3
3
|
import { t as isRuntimeScheduleDue } from "../due-Bbh4yIxq.js";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
//#region src/runtime/driver.ts
|
package/dist/runtime/state.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, i as loadScheduleDefinition, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore } from "../state-
|
|
1
|
+
import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, i as loadScheduleDefinition, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore } from "../state-By7WU_ks.js";
|
|
2
2
|
export { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./registry-module.d.ts" />
|
|
2
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 {
|
|
3
|
+
import { c as schedules, i as createMemoryRuntimeScheduleStore, l as validateRuntimeScheduleCron } from "./store-t-74rsM_.js";
|
|
4
4
|
import { getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRuntimeRegistry } from "./runtime/state.js";
|
|
5
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, r as getScheduleRuntimeRegistry, t as getRuntimeScheduleStore } from "./state-
|
|
2
|
-
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-
|
|
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-By7WU_ks.js";
|
|
2
|
+
import { n as validateRuntimeScheduleCron, t as schedules } from "./client-BMFCy0dX.js";
|
|
3
3
|
export { createMemoryRuntimeScheduleStore, getRuntimeScheduleStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
|
|
@@ -63,33 +63,17 @@ function scheduleRunBase(prefix) {
|
|
|
63
63
|
function scheduleRunAttemptBase(prefix) {
|
|
64
64
|
return joinKey(prefix, "schedule-run-attempts");
|
|
65
65
|
}
|
|
66
|
+
function isMissingKVPackage(error) {
|
|
67
|
+
if (!(error instanceof Error)) return false;
|
|
68
|
+
return error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes("Cannot find package '@vite-hub/kv'");
|
|
69
|
+
}
|
|
66
70
|
async function resolveDefaultKVStore() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
};
|
|
71
|
+
try {
|
|
72
|
+
return (await import("./kv-BJ1I9IlJ.js")).scheduleKVStorage;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (isMissingKVPackage(error)) throw new Error("[vitehub:schedule] The default KV-backed stores require @vite-hub/kv. Install it with: pnpm add @vite-hub/kv", { cause: error });
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
93
77
|
}
|
|
94
78
|
function cloneRuntimeSchedule(record) {
|
|
95
79
|
return {
|
|
@@ -18,7 +18,7 @@ declare const schedules: {
|
|
|
18
18
|
update<TTarget extends ScheduleTargetName, TInput = unknown>(id: string, input: RuntimeScheduleUpdateInput<TTarget, TInput>): Promise<RuntimeScheduleRecord<TInput>>;
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region src/runtime/
|
|
21
|
+
//#region src/runtime/kv-storage.d.ts
|
|
22
22
|
interface ScheduleKVStorage {
|
|
23
23
|
del(key: string): boolean | Promise<boolean> | Promise<void> | void;
|
|
24
24
|
get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
|
|
@@ -26,6 +26,16 @@ interface ScheduleKVStorage {
|
|
|
26
26
|
keys(base?: string): Promise<string[]> | string[];
|
|
27
27
|
set<T = unknown>(key: string, value: T): Promise<void> | void;
|
|
28
28
|
}
|
|
29
|
+
interface ViteHubKVStorage {
|
|
30
|
+
del(key: string): Promise<readonly [unknown, unknown]>;
|
|
31
|
+
get<T = unknown>(key: string): Promise<readonly [unknown, T | null | undefined]>;
|
|
32
|
+
has(key: string): Promise<readonly [unknown, boolean | undefined]>;
|
|
33
|
+
keys(base?: string): Promise<readonly [unknown, string[] | undefined]>;
|
|
34
|
+
set<T = unknown>(key: string, value: T): Promise<readonly [unknown, unknown]>;
|
|
35
|
+
}
|
|
36
|
+
declare function createScheduleKVStorage(kvStore: ViteHubKVStorage): ScheduleKVStorage;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/runtime/store.d.ts
|
|
29
39
|
interface KVScheduleStoreOptions {
|
|
30
40
|
kvStore?: ScheduleKVStorage;
|
|
31
41
|
prefix?: string;
|
|
@@ -35,4 +45,4 @@ declare function createKVRuntimeScheduleStore(options?: KVScheduleStoreOptions):
|
|
|
35
45
|
declare function createMemoryScheduleRunStore(): ScheduleRunStore;
|
|
36
46
|
declare function createKVScheduleRunStore(options?: KVScheduleStoreOptions): ScheduleRunStore;
|
|
37
47
|
//#endregion
|
|
38
|
-
export {
|
|
48
|
+
export { createMemoryScheduleRunStore as a, schedules as c, createMemoryRuntimeScheduleStore as i, validateRuntimeScheduleCron as l, createKVRuntimeScheduleStore as n, ScheduleKVStorage as o, createKVScheduleRunStore as r, createScheduleKVStorage as s, KVScheduleStoreOptions as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as writeRuntimeRegistryFile, i as createRuntimeRegistryContents, n as findDefaultExportCall, o as createImportPath, r as readObjectProperty, s as ensureGeneratedDir, t as discoverScheduleDefinitions } from "./discovery-BZlat3Kc.js";
|
|
2
2
|
import { readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, isAbsolute, normalize, relative, resolve } from "node:path";
|
|
4
4
|
import { mkdir, readFile, readdir, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
@@ -16,6 +16,7 @@ function createDefaultCloudflareOutputRoot(rootDir) {
|
|
|
16
16
|
//#region ../internal/src/build/vite.ts
|
|
17
17
|
const projectRootDirectoryMarkers = [
|
|
18
18
|
["server", "agents"],
|
|
19
|
+
["server", "browsers"],
|
|
19
20
|
["server", "schedules"],
|
|
20
21
|
["server", "templates"],
|
|
21
22
|
["server", "workspaces"]
|
|
@@ -388,19 +389,11 @@ const productName = "schedule";
|
|
|
388
389
|
const cloudflareOutputStateFileName = "cloudflare-output.json";
|
|
389
390
|
const denoCronFileName = "deno-cron.mjs";
|
|
390
391
|
const generatedRegistryFileName = "registry.mjs";
|
|
391
|
-
function resolveScheduleRuntimeEntry(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return normalizedFile.includes("/dist/") ? resolve(dirname(file), "runtime/static.js") : resolve(dirname(file), "dist/runtime/static.js");
|
|
397
|
-
}
|
|
398
|
-
function resolveScheduleDefinitionEntry(metaUrl = import.meta.url) {
|
|
399
|
-
const file = fileURLToPath(metaUrl);
|
|
400
|
-
const normalizedFile = file.replace(/\\/g, "/");
|
|
401
|
-
if (normalizedFile.endsWith("/src/internal/provider-output.ts")) return resolve(dirname(file), "../definition.ts");
|
|
402
|
-
if (normalizedFile.endsWith("/dist/internal/provider-output.js")) return resolve(dirname(file), "../definition.js");
|
|
403
|
-
return normalizedFile.includes("/dist/") ? resolve(dirname(file), "definition.js") : resolve(dirname(file), "dist/definition.js");
|
|
392
|
+
function resolveScheduleRuntimeEntry(resolveImport = (specifier) => import.meta.resolve(specifier)) {
|
|
393
|
+
return fileURLToPath(resolveImport(scheduleStaticRuntimeImport));
|
|
394
|
+
}
|
|
395
|
+
function resolveScheduleDefinitionEntry(resolveImport = (specifier) => import.meta.resolve(specifier)) {
|
|
396
|
+
return resolve(dirname(fileURLToPath(resolveImport(`${schedulePackageName}/package.json`))), "dist/definition.js");
|
|
404
397
|
}
|
|
405
398
|
const scheduleRuntimeEntry = resolveScheduleRuntimeEntry();
|
|
406
399
|
const scheduleDefinitionEntry = resolveScheduleDefinitionEntry();
|
|
@@ -572,10 +565,9 @@ function createScheduleDefinitionAliasPlugin() {
|
|
|
572
565
|
}
|
|
573
566
|
async function writeProviderEntries(rootDir, source, providedDefinitions) {
|
|
574
567
|
const generatedDir = ensureGeneratedDir(rootDir, productName);
|
|
575
|
-
await mkdir(generatedDir, { recursive: true });
|
|
576
568
|
const registryFile = resolve(generatedDir, generatedRegistryFileName);
|
|
577
569
|
const definitions = (providedDefinitions ?? discoverScheduleDefinitions({ rootDir })).filter((definition) => !source || definition.source === source).filter((definition) => definition.runtimeOnly !== true);
|
|
578
|
-
await
|
|
570
|
+
await writeRuntimeRegistryFile(registryFile, definitions);
|
|
579
571
|
const cloudflareWorkerFile = resolve(generatedDir, "cloudflare-worker.mjs");
|
|
580
572
|
const denoCronFile = resolve(generatedDir, denoCronFileName);
|
|
581
573
|
const vercelServerFile = resolve(generatedDir, "vercel-server.mjs");
|
|
@@ -864,7 +856,7 @@ const registryImportAnchor = ".vitehub/schedule/registry.js";
|
|
|
864
856
|
const generatedNitroSchedulePlugin = ".vitehub/nitro/schedule/plugin.ts";
|
|
865
857
|
const generatedNitroRuntimeRegistry = ".vitehub/nitro/schedule/runtime-registry.js";
|
|
866
858
|
const generatedNitroStaticRegistry = ".vitehub/nitro/schedule/static-registry.js";
|
|
867
|
-
const generatedNitroCloudflareModule = "./.vitehub/nitro/schedule/module.
|
|
859
|
+
const generatedNitroCloudflareModule = "./.vitehub/nitro/schedule/module.mjs";
|
|
868
860
|
const mergeNoExternal = createNoExternalMerger(schedulePackageName);
|
|
869
861
|
function resolveSchedulePluginRoots(root, options = {}) {
|
|
870
862
|
const resolvedViteRoot = resolve(root);
|
|
@@ -1012,17 +1004,15 @@ function renderNitroSchedulePlugin(options) {
|
|
|
1012
1004
|
}
|
|
1013
1005
|
function renderNitroCloudflareModule(crons) {
|
|
1014
1006
|
return [
|
|
1015
|
-
"import type { Nitro } from 'nitro/types'",
|
|
1016
|
-
"",
|
|
1017
1007
|
`const crons = ${JSON.stringify(crons)}`,
|
|
1018
1008
|
"",
|
|
1019
|
-
"function dedupeCloudflareCrons(nitro
|
|
1009
|
+
"function dedupeCloudflareCrons(nitro) {",
|
|
1020
1010
|
" const wrangler = nitro.options.cloudflare?.wrangler",
|
|
1021
1011
|
" if (!wrangler?.triggers || !Array.isArray(wrangler.triggers.crons)) return",
|
|
1022
|
-
" wrangler.triggers.crons = [...new Set(wrangler.triggers.crons.filter((cron)
|
|
1012
|
+
" wrangler.triggers.crons = [...new Set(wrangler.triggers.crons.filter((cron) => typeof cron === 'string'))]",
|
|
1023
1013
|
"}",
|
|
1024
1014
|
"",
|
|
1025
|
-
"export default function vitehubScheduleModule(nitro
|
|
1015
|
+
"export default function vitehubScheduleModule(nitro) {",
|
|
1026
1016
|
" nitro.options.cloudflare ??= {}",
|
|
1027
1017
|
" nitro.options.cloudflare.wrangler ??= {}",
|
|
1028
1018
|
" nitro.options.cloudflare.wrangler.triggers ??= {}",
|
|
@@ -1103,6 +1093,7 @@ async function createScheduleNitroConfig(options = {}) {
|
|
|
1103
1093
|
const roots = resolveSchedulePluginRoots(options.root || process.cwd(), options);
|
|
1104
1094
|
const definitions = discoverScheduleDefinitions({
|
|
1105
1095
|
rootDir: roots.viteRoot,
|
|
1096
|
+
serverDirs: options.serverDirs,
|
|
1106
1097
|
serverRootDir: roots.projectRoot
|
|
1107
1098
|
});
|
|
1108
1099
|
if (!shouldInstallNitroSchedulePlugin(definitions, options)) return null;
|
|
@@ -1130,12 +1121,14 @@ function hubSchedule(options = {}) {
|
|
|
1130
1121
|
let emitStandaloneProviderOutput = true;
|
|
1131
1122
|
let projectRoot;
|
|
1132
1123
|
let standaloneProviderSource;
|
|
1124
|
+
let serverDirs;
|
|
1133
1125
|
let viteRoot;
|
|
1134
1126
|
function discoverViteSchedules() {
|
|
1135
1127
|
if (!projectRoot || !viteRoot) return [];
|
|
1136
1128
|
return discoverScheduleDefinitions({
|
|
1137
1129
|
mode: "vite-suffix",
|
|
1138
1130
|
rootDir: viteRoot,
|
|
1131
|
+
serverDirs,
|
|
1139
1132
|
serverRootDir: projectRoot
|
|
1140
1133
|
});
|
|
1141
1134
|
}
|
|
@@ -1143,6 +1136,7 @@ function hubSchedule(options = {}) {
|
|
|
1143
1136
|
if (!projectRoot || !viteRoot) return [];
|
|
1144
1137
|
return discoverScheduleDefinitions({
|
|
1145
1138
|
rootDir: viteRoot,
|
|
1139
|
+
serverDirs,
|
|
1146
1140
|
serverRootDir: projectRoot
|
|
1147
1141
|
});
|
|
1148
1142
|
}
|
|
@@ -1157,9 +1151,11 @@ function hubSchedule(options = {}) {
|
|
|
1157
1151
|
name: SCHEDULE_VITE_PLUGIN_NAME,
|
|
1158
1152
|
enforce: "pre",
|
|
1159
1153
|
async config(config, env) {
|
|
1154
|
+
serverDirs = config["__vitehubServerDirs"] ?? serverDirs;
|
|
1160
1155
|
const roots = resolveSchedulePluginRoots(config.root || process.cwd(), options);
|
|
1161
1156
|
const definitions = discoverScheduleDefinitions({
|
|
1162
1157
|
rootDir: roots.viteRoot,
|
|
1158
|
+
serverDirs,
|
|
1163
1159
|
serverRootDir: roots.projectRoot
|
|
1164
1160
|
});
|
|
1165
1161
|
emitStandaloneProviderOutput = (options.runtime === void 0 || options.providerOutput === "standalone") && shouldEmitStandaloneProviderOutput(definitions, options);
|
|
@@ -1169,11 +1165,11 @@ function hubSchedule(options = {}) {
|
|
|
1169
1165
|
...options,
|
|
1170
1166
|
command: env.command,
|
|
1171
1167
|
nitro: config.nitro,
|
|
1172
|
-
root: config.root || process.cwd()
|
|
1168
|
+
root: config.root || process.cwd(),
|
|
1169
|
+
serverDirs
|
|
1173
1170
|
});
|
|
1174
1171
|
if (!nitro) return null;
|
|
1175
1172
|
config.nitro = nitro;
|
|
1176
|
-
return { nitro };
|
|
1177
1173
|
},
|
|
1178
1174
|
configResolved(config) {
|
|
1179
1175
|
resolved = config;
|
|
@@ -1187,7 +1183,8 @@ function hubSchedule(options = {}) {
|
|
|
1187
1183
|
},
|
|
1188
1184
|
handleHotUpdate(context) {
|
|
1189
1185
|
const file = normalize(context.file).replace(/\\/g, "/");
|
|
1190
|
-
|
|
1186
|
+
const serverSchedule = (serverDirs ?? [resolve(projectRoot ?? resolved?.root ?? context.server.config.root, "server")]).map((directory) => `${resolve(directory, "schedules").replace(/\\/g, "/")}/`).some((directory) => file.startsWith(directory) && /\.(?:c|m)?[jt]s$/i.test(file.slice(directory.length)));
|
|
1187
|
+
if (!/\.schedule\.(?:c|m)?[jt]s$/i.test(file) && !serverSchedule) return;
|
|
1191
1188
|
const registryModule = context.server.moduleGraph.getModuleById(RESOLVED_SCHEDULE_REGISTRY_ID);
|
|
1192
1189
|
if (registryModule) context.server.moduleGraph.invalidateModule(registryModule);
|
|
1193
1190
|
const targetsModule = context.server.moduleGraph.getModuleById(RESOLVED_SCHEDULE_TARGETS_ID);
|
package/dist/vite.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ interface ScheduleNitroConfigOptions extends ScheduleVitePluginOptions {
|
|
|
14
14
|
command?: "build" | "serve";
|
|
15
15
|
nitro?: unknown;
|
|
16
16
|
root?: string;
|
|
17
|
+
/** @internal Framework-resolved server definition directories. */
|
|
18
|
+
serverDirs?: string[];
|
|
17
19
|
}
|
|
18
20
|
interface ScheduleVitePlugin {
|
|
19
21
|
name: string;
|
package/dist/vite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as hubSchedule, t as createScheduleNitroConfig } from "./vite-
|
|
1
|
+
import { n as hubSchedule, t as createScheduleNitroConfig } from "./vite-BX6_KiRw.js";
|
|
2
2
|
export { createScheduleNitroConfig, hubSchedule };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/schedule",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Schedule primitives and definition discovery for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cron",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"cron-schedule": "^6.0.0",
|
|
40
40
|
"effect": "4.0.0-beta.99",
|
|
41
41
|
"esbuild": "^0.28.1",
|
|
42
|
-
"@vite-hub/runtime": "0.0.
|
|
43
|
-
"@vite-hub/kv": "0.0.2"
|
|
42
|
+
"@vite-hub/runtime": "0.0.3"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@types/node": "^24.13.3",
|
|
@@ -49,12 +48,17 @@
|
|
|
49
48
|
"vite": "^8.0.8",
|
|
50
49
|
"vite-plus": "^0.1.24",
|
|
51
50
|
"vitest": "^4.1.4",
|
|
51
|
+
"@vite-hub/kv": "0.0.3",
|
|
52
52
|
"@vite-hub/internal": "0.0.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"vite": ">=8.0.0"
|
|
55
|
+
"vite": ">=8.0.0",
|
|
56
|
+
"@vite-hub/kv": "0.0.3"
|
|
56
57
|
},
|
|
57
58
|
"peerDependenciesMeta": {
|
|
59
|
+
"@vite-hub/kv": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
58
62
|
"vite": {
|
|
59
63
|
"optional": true
|
|
60
64
|
}
|