@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
package/dist/vite.d.ts
CHANGED
|
@@ -1,31 +1,234 @@
|
|
|
1
|
-
import { t as DiscoveredScheduleDefinition } from "./types-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as DiscoveredScheduleDefinition } from "./types-Cw5LjPuc.js";
|
|
2
|
+
import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
|
|
3
|
+
import { i as ViteHubInspectionPluginMetadata, n as ViteHubConsoleRuntimeRecordTableSection, r as ViteHubDefinitionSummary } from "./console-wEhr0LWn.js";
|
|
4
|
+
//#region ../internal/src/deployment.d.ts
|
|
5
|
+
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
6
|
+
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region ../internal/src/build/deployment-plan-output.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
|
|
11
|
+
* a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
|
|
12
|
+
* It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
|
|
13
|
+
*/
|
|
14
|
+
interface DeploymentEnvEntry {
|
|
15
|
+
/** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
|
|
16
|
+
path?: string;
|
|
17
|
+
/** The host variable names, in read order. The first name that is set supplies the value. */
|
|
18
|
+
names: readonly string[];
|
|
19
|
+
/** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
|
|
20
|
+
prefix?: string;
|
|
21
|
+
required: boolean;
|
|
22
|
+
secret: boolean;
|
|
23
|
+
/** A default supplies the value when no name is set. */
|
|
24
|
+
hasDefault: boolean;
|
|
25
|
+
/** The primitives that read these names, such as `blob`. Server Env declarations have none. */
|
|
26
|
+
owners?: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/** What a primitive needs to know to name the variables it reads in the deployed app. */
|
|
29
|
+
interface DeploymentEnvContext {
|
|
30
|
+
host: ViteHubHost;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
|
|
34
|
+
* config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
|
|
35
|
+
* Return names only, never values.
|
|
36
|
+
*/
|
|
37
|
+
type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region ../internal/src/durability.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
42
|
+
* imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
|
|
43
|
+
* `Durability` lines of `@vite-hub/runtime/durability`.
|
|
44
|
+
*/
|
|
45
|
+
interface DurabilityContribution {
|
|
46
|
+
/** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
|
|
47
|
+
primitive: string;
|
|
48
|
+
/** The absolute file of the reporter module. */
|
|
49
|
+
module: string;
|
|
50
|
+
export: string;
|
|
51
|
+
/**
|
|
52
|
+
* The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
|
|
53
|
+
* `JSON.stringify`, so do not put credentials here.
|
|
54
|
+
*/
|
|
55
|
+
input: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** The `vitehub.durability` field of a primitive's Vite plugin. */
|
|
58
|
+
interface DurabilityPluginMetadata {
|
|
59
|
+
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
60
|
+
durability?: () => readonly DurabilityContribution[];
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region ../internal/src/contributions.d.ts
|
|
64
|
+
/** Module and export that hold a contributed Definition. */
|
|
65
|
+
interface ContributionDefinition {
|
|
66
|
+
/**
|
|
67
|
+
* Absolute file path, `file:` URL, or package specifier that the application can import. Relative paths are
|
|
68
|
+
* rejected because they have no stable base.
|
|
69
|
+
*/
|
|
70
|
+
module: string;
|
|
71
|
+
/** Named export that holds the Definition. Defaults to `default`. */
|
|
72
|
+
export?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One Definition that a Vite plugin adds to a Server Primitive, for example a Workspace, a Schedule, or Database tables.
|
|
76
|
+
* Every owner package reads this shape from `plugin.vitehub.<key>`. Owners can add fields, such as `database`.
|
|
77
|
+
*/
|
|
78
|
+
interface Contribution {
|
|
79
|
+
/** Unique name in the owner, for example the Workspace or Schedule name. */
|
|
80
|
+
name: string;
|
|
81
|
+
definition: ContributionDefinition;
|
|
82
|
+
/** Why the plugin adds the Definition. `vitehub inspect` and the Console show it. */
|
|
83
|
+
reason?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Roots that ViteHub passes to every contribution factory. */
|
|
86
|
+
interface ContributionContext {
|
|
87
|
+
/** Vite root. */
|
|
88
|
+
root: string;
|
|
89
|
+
/** ViteHub project root. It can differ from the Vite root, for example in a Nuxt app with a `srcDir`. */
|
|
90
|
+
projectRoot: string;
|
|
91
|
+
/** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
|
|
92
|
+
serverDirs?: readonly string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the contributions of a plugin. It runs once per discovery pass, so it must be idempotent and must not depend
|
|
96
|
+
* on the order of Vite config hooks.
|
|
97
|
+
*/
|
|
98
|
+
type ContributionFactory<TEntry extends Contribution = Contribution> = (context: ContributionContext) => readonly TEntry[] | undefined | Promise<readonly TEntry[] | undefined>;
|
|
99
|
+
type ContributionSource<TEntry extends Contribution = Contribution> = readonly TEntry[] | ContributionFactory<TEntry>;
|
|
100
|
+
/** A Vite plugin that contributes Definitions under `vitehub[TKey]`. */
|
|
101
|
+
type ContributingPlugin<TKey extends string, TEntry extends Contribution = Contribution> = {
|
|
102
|
+
name?: string;
|
|
103
|
+
vitehub?: { [K in TKey]?: ContributionSource<TEntry>; };
|
|
104
|
+
};
|
|
105
|
+
/** A validated contribution with its export resolved and the name of the plugin that added it. */
|
|
106
|
+
interface CollectedContribution {
|
|
107
|
+
name: string;
|
|
108
|
+
definition: {
|
|
109
|
+
module: string;
|
|
110
|
+
export: string;
|
|
111
|
+
};
|
|
112
|
+
reason?: string;
|
|
113
|
+
/** Name of the contributing Vite plugin. */
|
|
114
|
+
plugin: string;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/contributions.d.ts
|
|
118
|
+
/**
|
|
119
|
+
* A Schedule Definition that another package adds from its Vite plugin. The Schedule plugin merges it with the
|
|
120
|
+
* discovered files, so provider wake output, the Process Runtime, `vitehub schedule run`, inspection,
|
|
121
|
+
* and the Console treat it like `server/schedules/<name>.ts`.
|
|
122
|
+
*
|
|
123
|
+
* The build reads the cron and the `manual` option from the source of the Definition module without running it, as it
|
|
124
|
+
* does for discovered files. `definition.module` must therefore be an absolute file path or `file:` URL, and
|
|
125
|
+
* `definition.export` must be `default`: `export default defineSchedule({ cron: "...", handler })` with literal options.
|
|
126
|
+
*/
|
|
127
|
+
type ScheduleContribution = Contribution;
|
|
128
|
+
/** Roots that ViteHub passes to contribution factories. `root` is the Vite root. */
|
|
129
|
+
type ScheduleContributionContext = ContributionContext;
|
|
130
|
+
type ScheduleContributionFactory = ContributionFactory<ScheduleContribution>;
|
|
131
|
+
/** A Vite plugin that contributes Schedule Definitions through `vitehub.schedules`. */
|
|
132
|
+
type ScheduleContributingPlugin = ContributingPlugin<"schedules", ScheduleContribution>;
|
|
133
|
+
/** A validated contribution with the name of the plugin that contributed it. */
|
|
134
|
+
type CollectedScheduleContribution = CollectedContribution;
|
|
135
|
+
/**
|
|
136
|
+
* Collects `vitehub.schedules` contributions from Vite plugins. Two contributions with one name fail with
|
|
137
|
+
* `SCHEDULE_B0006`. Invalid entries fail with `SCHEDULE_B0007`.
|
|
138
|
+
*/
|
|
139
|
+
export declare function collectScheduleContributions(plugins: readonly unknown[] | undefined, context: ScheduleContributionContext): Promise<CollectedScheduleContribution[]>;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/discovery.d.ts
|
|
142
|
+
/** Discovery source of Schedule Definitions that Vite plugins contribute through `vitehub.schedules`. */
|
|
143
|
+
export declare const contributedScheduleSource = "vite-plugin-contribution";
|
|
144
|
+
interface ScheduleDiscoveryOptions {
|
|
145
|
+
/** Schedule Definitions that Vite plugins contribute. See `collectScheduleContributions()`. */
|
|
146
|
+
contributions?: readonly CollectedScheduleContribution[];
|
|
147
|
+
mode?: "vite-suffix";
|
|
148
|
+
rootDir: string;
|
|
149
|
+
scanDirs?: string[];
|
|
150
|
+
serverDirs?: string[];
|
|
151
|
+
serverRootDir?: string;
|
|
152
|
+
}
|
|
153
|
+
type DiscoverScheduleDefinitionsOptions = ScheduleDiscoveryOptions | {
|
|
154
|
+
mode: "server-schedules";
|
|
155
|
+
scanDirs: string[];
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Discovers the Schedule Definitions that run on a cron. When a Definition has no `cron`, it adds the
|
|
159
|
+
* `vitehub/started-schedules` Schedule, which runs the Schedules that code starts with `startSchedule()`.
|
|
160
|
+
* `discoverStartableScheduleDefinitions()` lists the Definitions without `cron`.
|
|
161
|
+
*/
|
|
162
|
+
export declare function discoverScheduleDefinitions(options: DiscoverScheduleDefinitionsOptions): DiscoveredScheduleDefinition[];
|
|
163
|
+
/** Discovers the Schedule Definitions without `cron`. Only `startSchedule()` runs them. */
|
|
164
|
+
export declare function discoverStartableScheduleDefinitions(options: DiscoverScheduleDefinitionsOptions): DiscoveredScheduleDefinition[];
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/inspect.d.ts
|
|
167
|
+
interface ScheduleInspectionOptions {
|
|
168
|
+
/** Cron per Schedule name that this build's host runs in place of the declared cron. */
|
|
169
|
+
cron?: Readonly<Record<string, string>>;
|
|
170
|
+
/** Vite plugins that can contribute Schedule Definitions through `vitehub.schedules`. */
|
|
171
|
+
plugins?: readonly unknown[];
|
|
172
|
+
projectRoot: string;
|
|
173
|
+
rootDir: string;
|
|
174
|
+
serverDirs?: string[];
|
|
175
|
+
serverRootDir: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Lists Schedule Definitions with their static cron when the Definition declares one, or the build's `cron` for it.
|
|
179
|
+
* Contributed Definitions name the plugin that added them and its reason.
|
|
180
|
+
*/
|
|
181
|
+
export declare function inspectScheduleDefinitions(options: ScheduleInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Console section for Schedules. Records list discovered Schedule Definitions. When the server runs the Process Runtime,
|
|
184
|
+
* the cron and time zone come from the loaded Definitions, so any expression shows its real value.
|
|
185
|
+
* `vitehub inspect definitions` reads the same Definitions from source, and `vitehub schedule runs <name>` lists the runs
|
|
186
|
+
* that a runtime recorded.
|
|
187
|
+
*/
|
|
188
|
+
export declare const scheduleConsoleSection: ViteHubConsoleRuntimeRecordTableSection<ScheduleInspectionOptions>;
|
|
189
|
+
//#endregion
|
|
4
190
|
//#region src/vite.d.ts
|
|
5
|
-
declare function readScheduleDefinitionCrons(definitions: DiscoveredScheduleDefinition[]): Promise<Map<string, string>>;
|
|
6
|
-
interface ScheduleProcessRuntimeOptions {
|
|
191
|
+
export declare function readScheduleDefinitionCrons(definitions: DiscoveredScheduleDefinition[]): Promise<Map<string, string>>;
|
|
192
|
+
export interface ScheduleProcessRuntimeOptions {
|
|
193
|
+
catchUpMs?: number;
|
|
7
194
|
concurrency?: number;
|
|
8
195
|
driver: "process";
|
|
9
196
|
intervalMs?: number;
|
|
197
|
+
/** Milliseconds that a server holds an occurrence after it stops, before another server may run it. Defaults to `60000`. */
|
|
198
|
+
leaseTtlMs?: number;
|
|
10
199
|
prefix?: string;
|
|
11
200
|
}
|
|
12
|
-
interface
|
|
201
|
+
export interface ScheduleOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Cron per Schedule name for this build's host, in place of the cron that the Schedule declares. Set it in the
|
|
204
|
+
* host's build config, such as `{ cleanup: "0 0 * * *" }` for Vercel Hobby, which runs cron jobs at most once a day.
|
|
205
|
+
*/
|
|
206
|
+
cron?: Readonly<Record<string, string>>;
|
|
13
207
|
providerOutput?: "auto" | "standalone" | "nitro" | false;
|
|
14
208
|
projectRoot?: string;
|
|
15
209
|
runtime?: ScheduleProcessRuntimeOptions;
|
|
16
210
|
}
|
|
17
|
-
interface ScheduleNitroConfigOptions extends
|
|
211
|
+
export interface ScheduleNitroConfigOptions extends ScheduleOptions {
|
|
18
212
|
command?: "build" | "serve";
|
|
19
213
|
/** @internal Resolve generated Nitro registrations from the ViteHub project root. */
|
|
20
214
|
nitroOwnsPaths?: boolean;
|
|
21
215
|
nitro?: unknown;
|
|
216
|
+
/** Vite plugins that can contribute Schedule Definitions through `vitehub.schedules`. */
|
|
217
|
+
plugins?: readonly unknown[];
|
|
22
218
|
root?: string;
|
|
23
219
|
/** @internal Framework-resolved server definition directories. */
|
|
24
220
|
serverDirs?: string[];
|
|
25
221
|
}
|
|
26
|
-
interface ScheduleVitePlugin {
|
|
222
|
+
export interface ScheduleVitePlugin {
|
|
27
223
|
name: string;
|
|
224
|
+
/** The variables that Schedules read on the deployed host. See `scheduleDeploymentEnv()`. */
|
|
225
|
+
api?: {
|
|
226
|
+
deploymentEnv: DeploymentEnvContribution;
|
|
227
|
+
};
|
|
28
228
|
[hook: string]: unknown;
|
|
229
|
+
vitehub?: ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
230
|
+
operations?: readonly OperationContributionEntry[];
|
|
231
|
+
};
|
|
29
232
|
}
|
|
30
233
|
type NitroConfig = Record<string, unknown> & {
|
|
31
234
|
cloudflare?: {
|
|
@@ -46,7 +249,7 @@ type NitroConfig = Record<string, unknown> & {
|
|
|
46
249
|
} & Record<string, unknown>;
|
|
47
250
|
} & Record<string, unknown>;
|
|
48
251
|
};
|
|
49
|
-
declare function createScheduleNitroConfig(options?: ScheduleNitroConfigOptions): Promise<NitroConfig | null>;
|
|
50
|
-
declare function hubSchedule(options?:
|
|
252
|
+
export declare function createScheduleNitroConfig(options?: ScheduleNitroConfigOptions): Promise<NitroConfig | null>;
|
|
253
|
+
export declare function hubSchedule(options?: ScheduleOptions): ScheduleVitePlugin;
|
|
51
254
|
//#endregion
|
|
52
|
-
export {
|
|
255
|
+
export type { CollectedScheduleContribution, ScheduleContributingPlugin, ScheduleContribution, ScheduleContributionContext, ScheduleContributionFactory, ScheduleDiscoveryOptions, ScheduleInspectionOptions };
|