@vite-hub/schedule 0.1.0 → 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 +114 -96
- package/dist/console-wEhr0LWn.d.ts +330 -0
- package/dist/definition.d.ts +6 -2
- package/dist/definition.js +47 -1
- 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 +59 -5
- package/dist/index.js +27 -2
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/{kv-storage-Bv9ocZT-.d.ts → kv-storage-C0KZZB6v.d.ts} +2 -2
- package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/{operations-gk2qzhYV.js → operations-DwZWFIUX.js} +75 -22
- package/dist/operations.d.ts +27 -4
- package/dist/operations.js +127 -730
- package/dist/os.d.ts +167 -0
- package/dist/os.js +1659 -0
- package/dist/runtime/console.d.ts +12 -0
- package/dist/runtime/console.js +85 -0
- package/dist/runtime/kv.d.ts +1 -1
- package/dist/runtime/kv.js +1 -1
- package/dist/runtime/process.d.ts +32 -5
- package/dist/runtime/process.js +401 -413
- package/dist/runtime/state.d.ts +2 -9
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +28 -2
- package/dist/runtime/static.js +2 -2
- package/dist/runtime.d.ts +34 -32
- package/dist/runtime.js +6 -5
- package/dist/started-BuGmnus4.js +201 -0
- package/dist/started-Bx7MDbrl.js +146 -0
- package/dist/{execute-BJrgNgQ0.js → started-errors-p7cu_rI7.js} +69 -20
- package/dist/{state-DSxmHPn3.js → state-B-Fuyfb4.js} +42 -22
- package/dist/state-Do2wV4Tx.d.ts +49 -0
- package/dist/{static-6g82xguw.js → static-DQwzzvPg.js} +63 -42
- package/dist/store-Df0-fzCl.d.ts +53 -0
- package/dist/time-zone-SBldrUgt.js +59 -0
- package/dist/{types-CHdV9FQU.d.ts → types-Cw5LjPuc.d.ts} +62 -8
- package/dist/vite.d.ts +255 -2
- package/dist/vite.js +5876 -2
- package/dist/{wait-until-BmIqRo4x.js → wait-until-Dy4Bn3ZN.js} +26 -1
- package/package.json +19 -24
- package/dist/definition-CMiOg1lg.js +0 -111
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-in7mif5s.js +0 -45
- package/dist/nuxt.d.ts +0 -17
- package/dist/nuxt.js +0 -27
- package/dist/store-QAOd8bxm.d.ts +0 -11
- package/dist/vite-BAVyZ8hZ.d.ts +0 -474
- package/dist/vite-BJwZkMrn.js +0 -5193
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
//#region ../internal/src/inspect.d.ts
|
|
2
|
+
interface ViteHubDefinitionField {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
/** Serializable summary of one discovered Definition. Files are relative to the project root. */
|
|
7
|
+
interface ViteHubDefinitionSummary {
|
|
8
|
+
fields: readonly ViteHubDefinitionField[];
|
|
9
|
+
file: string;
|
|
10
|
+
name: string;
|
|
11
|
+
source: string;
|
|
12
|
+
}
|
|
13
|
+
/** Lists the Definitions that one owner package discovered for the resolved Vite config. */
|
|
14
|
+
interface ViteHubDefinitionInspector {
|
|
15
|
+
/** Stable singular kind, for example `queue` or `rate-limit`. */
|
|
16
|
+
kind: string;
|
|
17
|
+
label: string;
|
|
18
|
+
list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
|
|
19
|
+
}
|
|
20
|
+
/** One generated Provider Output file or directory that an owner package can write. */
|
|
21
|
+
interface ViteHubProviderOutputEntry {
|
|
22
|
+
description: string;
|
|
23
|
+
owner: string;
|
|
24
|
+
/** Absolute path. */
|
|
25
|
+
path: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
|
|
29
|
+
* The CLI sets `provider-output` when only a generated Wrangler config names the id.
|
|
30
|
+
*/
|
|
31
|
+
type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
|
|
32
|
+
/** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
|
|
33
|
+
interface ViteHubResourceSummary {
|
|
34
|
+
/** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
|
|
35
|
+
binding?: string;
|
|
36
|
+
/** Definition or store name. */
|
|
37
|
+
definition: string;
|
|
38
|
+
/** Env variable that supplied the id when `source` is `env`. */
|
|
39
|
+
env?: string;
|
|
40
|
+
host: "cloudflare" | "vercel";
|
|
41
|
+
id?: string;
|
|
42
|
+
/** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
|
|
43
|
+
kind: string;
|
|
44
|
+
/** Resource name on the host, when the config names it. */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Explains how the host finds the resource when no id or name is known locally. */
|
|
47
|
+
note?: string;
|
|
48
|
+
owner: string;
|
|
49
|
+
/** Absent when no id is known yet. */
|
|
50
|
+
source?: ViteHubResourceIdSource;
|
|
51
|
+
}
|
|
52
|
+
interface ViteHubInspectionContributor {
|
|
53
|
+
definitions?: readonly ViteHubDefinitionInspector[];
|
|
54
|
+
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
55
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
56
|
+
}
|
|
57
|
+
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
58
|
+
interface ViteHubInspectionPluginMetadata {
|
|
59
|
+
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region ../internal/src/console.d.ts
|
|
63
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
64
|
+
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
65
|
+
interface ViteHubConsoleDefinitionCatalogView {
|
|
66
|
+
kind: "definition-catalog";
|
|
67
|
+
/** States which runtime data this catalog does not include. */
|
|
68
|
+
notice: string;
|
|
69
|
+
}
|
|
70
|
+
/** Lists Workspace Definitions like a catalog, and browses the refs, revisions, and files of the selected one. */
|
|
71
|
+
interface ViteHubConsoleWorkspaceBrowserView {
|
|
72
|
+
kind: "workspace-browser";
|
|
73
|
+
/** States which runtime data the browser does not include. */
|
|
74
|
+
notice: string;
|
|
75
|
+
}
|
|
76
|
+
interface ViteHubConsoleRecordColumn {
|
|
77
|
+
/** Set it for a column with few values, such as a status. The Console then filters the table by its values. */
|
|
78
|
+
filter?: boolean;
|
|
79
|
+
/** Key in `ViteHubConsoleRecord.cells`. */
|
|
80
|
+
key: string;
|
|
81
|
+
label: string;
|
|
82
|
+
}
|
|
83
|
+
/** Shows records in a table and the selected record's fields in a detail panel. */
|
|
84
|
+
interface ViteHubConsoleRecordTableView {
|
|
85
|
+
columns: readonly ViteHubConsoleRecordColumn[];
|
|
86
|
+
kind: "record-table";
|
|
87
|
+
/** States the source and limits of the records. */
|
|
88
|
+
notice: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Lists the collections and documents of an owner runtime and edits them with owner actions: a form generated from each
|
|
92
|
+
* collection's JSON Schema, a Markdown body, save, publish, and revision history.
|
|
93
|
+
*/
|
|
94
|
+
interface ViteHubConsoleDocumentEditorView {
|
|
95
|
+
kind: "document-editor";
|
|
96
|
+
/** States where documents are stored and what the editor does not do. */
|
|
97
|
+
notice: string;
|
|
98
|
+
}
|
|
99
|
+
interface ViteHubConsoleOperationColumn {
|
|
100
|
+
/** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
|
|
101
|
+
key: string;
|
|
102
|
+
label: string;
|
|
103
|
+
/**
|
|
104
|
+
* `datetime` shows a time in milliseconds since the epoch as a relative date, such as `5m ago`. `excerpt` cuts a long
|
|
105
|
+
* text. `status` shows the value as a status with a colored dot, such as `Open`. `tones` picks the color of each value.
|
|
106
|
+
* `switch` shows a boolean as a switch that calls the `switch` operation.
|
|
107
|
+
*/
|
|
108
|
+
format?: "datetime" | "excerpt" | "status" | "switch";
|
|
109
|
+
/** The color of each value of a `status` column, such as `{ open: "info", resolved: "success" }`. Other values are neutral. */
|
|
110
|
+
tones?: Readonly<Record<string, "error" | "info" | "neutral" | "success" | "warning">>;
|
|
111
|
+
/**
|
|
112
|
+
* What a `switch` column calls when the user flips it: `operation` with an input that maps each key of `input` to a
|
|
113
|
+
* dot path of the item, and the column `key` to the new value. `{ operation: "skills.set", input: { name: "name" } }`
|
|
114
|
+
* on the column `enabled` calls `skills.set` with `{ name, enabled }`, then loads the list again. A user who may only
|
|
115
|
+
* read the section sees the switch disabled.
|
|
116
|
+
*/
|
|
117
|
+
switch?: {
|
|
118
|
+
operation: string;
|
|
119
|
+
input: Readonly<Record<string, string>>;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A button on each row that calls `operation` with the Console user, then loads the list again. `input` maps each input
|
|
124
|
+
* key to a dot path of the item, as a `switch` column does.
|
|
125
|
+
*/
|
|
126
|
+
interface ViteHubConsoleOperationAction {
|
|
127
|
+
label: string;
|
|
128
|
+
operation: string;
|
|
129
|
+
input: Readonly<Record<string, string>>;
|
|
130
|
+
/**
|
|
131
|
+
* The result is `{ url }`, such as a one-time link or a provider sign-in: the Console opens it in a new tab, and loads
|
|
132
|
+
* the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
|
|
133
|
+
*/
|
|
134
|
+
tab?: true;
|
|
135
|
+
/** Show the button only on rows where each dot path holds one of the listed values. */
|
|
136
|
+
when?: Readonly<Record<string, readonly string[]>>;
|
|
137
|
+
/** Ask this question before the call. `{path}` takes a value from the item. */
|
|
138
|
+
confirm?: string;
|
|
139
|
+
}
|
|
140
|
+
/** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
|
|
141
|
+
interface ViteHubConsoleOperationFilter {
|
|
142
|
+
id: string;
|
|
143
|
+
label: string;
|
|
144
|
+
input: Readonly<Record<string, unknown>>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Lists the items that an operation returns, called over the Console RPC with the signed-in Console user. The operation
|
|
148
|
+
* checks the access of that user for each item, so the view shows only what the user may read. `operation` must return an
|
|
149
|
+
* array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
|
|
150
|
+
*/
|
|
151
|
+
interface ViteHubConsoleOperationView {
|
|
152
|
+
/** Buttons on each row. A user who may only read the section does not see them. */
|
|
153
|
+
actions?: readonly ViteHubConsoleOperationAction[];
|
|
154
|
+
columns: readonly ViteHubConsoleOperationColumn[];
|
|
155
|
+
/**
|
|
156
|
+
* Opens the item of a row in a side panel. `comment-thread` shows an item of `comments.list` as a comment thread
|
|
157
|
+
* where the user reads, replies, resolves, reopens, and mentions people. The panel calls the `comments.*` operations
|
|
158
|
+
* with the Console user, and `?thread=<id>` in the URL opens it.
|
|
159
|
+
*/
|
|
160
|
+
detail?: {
|
|
161
|
+
kind: "comment-thread";
|
|
162
|
+
};
|
|
163
|
+
filters?: readonly ViteHubConsoleOperationFilter[];
|
|
164
|
+
kind: "operation-view";
|
|
165
|
+
/**
|
|
166
|
+
* Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
|
|
167
|
+
* app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
|
|
168
|
+
* `{path:href}` takes an app URL that is already encoded, with its query, as it is. Rows where `when.path` is not
|
|
169
|
+
* `when.equals` get none.
|
|
170
|
+
*/
|
|
171
|
+
link?: {
|
|
172
|
+
label?: string;
|
|
173
|
+
template: string;
|
|
174
|
+
when?: {
|
|
175
|
+
equals: string;
|
|
176
|
+
path: string;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
notice: string;
|
|
180
|
+
/** Operation name, such as `comments.list`. */
|
|
181
|
+
operation: string;
|
|
182
|
+
/** Fetch every page with `limit` and a `before` object whose keys read these dot paths from the last item. */
|
|
183
|
+
pagination?: {
|
|
184
|
+
limit: number;
|
|
185
|
+
cursor: Readonly<Record<string, string>>;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
interface ViteHubConsoleAuthView {
|
|
189
|
+
kind: "auth-management";
|
|
190
|
+
notice: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The webhooks of the app, their pending debounce timers, and their delivery log. The Console calls the `webhooks.*`
|
|
194
|
+
* operations of `@vite-hub/webhooks` with the Console user to list them, send a test, send a pending delivery now,
|
|
195
|
+
* cancel it, and redeliver. It has no build-time data.
|
|
196
|
+
*/
|
|
197
|
+
interface ViteHubConsoleWebhooksView {
|
|
198
|
+
kind: "webhooks";
|
|
199
|
+
notice: string;
|
|
200
|
+
}
|
|
201
|
+
type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleWebhooksView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView | ViteHubConsoleWorkspaceBrowserView;
|
|
202
|
+
/**
|
|
203
|
+
* The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
|
|
204
|
+
* activity, and a New button per collection. It reads the owner `overview` action.
|
|
205
|
+
*/
|
|
206
|
+
interface ViteHubConsoleDocumentDashboardView {
|
|
207
|
+
kind: "document-dashboard";
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The media library of a document editor section: folders, uploads, alt text, focal points, and crops of the Blob Store
|
|
211
|
+
* that `blob.serve` serves. The owner decides who may use it with `mediaAccess`, and finds the documents that use a file
|
|
212
|
+
* with `references`. The page needs the Blob section, so declare it with `requires: ["blob"]`.
|
|
213
|
+
*/
|
|
214
|
+
interface ViteHubConsoleMediaLibraryView {
|
|
215
|
+
kind: "media-library";
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The singletons of a document editor section, such as site settings: one row per singleton that opens it in the
|
|
219
|
+
* editor. Singletons appear here instead of among the collections, and the Console hides the page when the section has
|
|
220
|
+
* none.
|
|
221
|
+
*/
|
|
222
|
+
interface ViteHubConsoleDocumentSettingsView {
|
|
223
|
+
kind: "document-settings";
|
|
224
|
+
}
|
|
225
|
+
/** A view that the Console UI in `vite-hub` renders for a section page. */
|
|
226
|
+
type ViteHubConsoleSectionPageView = ViteHubConsoleDocumentDashboardView | ViteHubConsoleDocumentSettingsView | ViteHubConsoleMediaLibraryView;
|
|
227
|
+
/**
|
|
228
|
+
* A page of a section next to its main view, such as the Content dashboard or media library. The section sidebar lists
|
|
229
|
+
* the pages, and each page has its own URL:
|
|
230
|
+
*
|
|
231
|
+
* - `/_vitehub/<section>` serves the `index` page, or the main view when the section has none.
|
|
232
|
+
* - `/_vitehub/<section>/-/<page>` serves every other page. The `-` segment keeps page URLs apart from the main view's
|
|
233
|
+
* own segments, such as a collection name.
|
|
234
|
+
*
|
|
235
|
+
* Pages share the access of their section: `console.authorize` that allows the section allows every page of it.
|
|
236
|
+
*/
|
|
237
|
+
interface ViteHubConsoleSectionPage {
|
|
238
|
+
/** Lowercase route segment, for example `media`. */
|
|
239
|
+
id: string;
|
|
240
|
+
/** Display name, for example `Media`. */
|
|
241
|
+
label: string;
|
|
242
|
+
/** Iconify class name, for example `i-lucide-image`. */
|
|
243
|
+
icon: string;
|
|
244
|
+
view: ViteHubConsoleSectionPageView;
|
|
245
|
+
/**
|
|
246
|
+
* Serve this page at the section root. At most one page sets it, and `/_vitehub/<section>/-/<id>` then redirects to
|
|
247
|
+
* the root.
|
|
248
|
+
*/
|
|
249
|
+
index?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Sidebar heading, for example `Assets`. Pages without a group lead the sidebar, above the main view's navigation.
|
|
252
|
+
* Grouped pages follow it, in the order their group first appears.
|
|
253
|
+
*/
|
|
254
|
+
group?: string;
|
|
255
|
+
/** Section ids that the project must enable, such as `["blob"]`. The Console leaves the page out otherwise. */
|
|
256
|
+
requires?: readonly string[];
|
|
257
|
+
}
|
|
258
|
+
/** One entry of a record's activity, such as a comment in a thread. `at` is an ISO 8601 timestamp. */
|
|
259
|
+
interface ViteHubConsoleRecordActivity {
|
|
260
|
+
author: string;
|
|
261
|
+
at: string;
|
|
262
|
+
text: string;
|
|
263
|
+
}
|
|
264
|
+
/** One serializable record row. Values are display strings. Do not put credentials in records. */
|
|
265
|
+
interface ViteHubConsoleRecord {
|
|
266
|
+
cells: Readonly<Record<string, string>>;
|
|
267
|
+
fields: readonly ViteHubDefinitionField[];
|
|
268
|
+
id: string;
|
|
269
|
+
/** The Console can run this record when it represents a runnable Schedule Definition. */
|
|
270
|
+
runnable?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Where the record lives in the app, such as the page of a comment thread. `href` is an app path that starts with one
|
|
273
|
+
* `/`, or an `https:` URL. The Console opens it in a new tab.
|
|
274
|
+
*/
|
|
275
|
+
link?: {
|
|
276
|
+
href: string;
|
|
277
|
+
label: string;
|
|
278
|
+
};
|
|
279
|
+
/** Entries in time order, such as the comments of a thread. The Console shows them as a conversation. */
|
|
280
|
+
activity?: readonly ViteHubConsoleRecordActivity[];
|
|
281
|
+
}
|
|
282
|
+
/** Serializable description of a Console section. The Console UI in `vite-hub` renders the view. */
|
|
283
|
+
interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionView = ViteHubConsoleSectionView> {
|
|
284
|
+
description: string;
|
|
285
|
+
/**
|
|
286
|
+
* Iconify class name, for example `i-lucide-inbox`. The Console draws with Lucide; `ph` also resolves. The
|
|
287
|
+
* Console build bundles the icon of every section in the `vite-hub` Console registry and fails if it cannot resolve one.
|
|
288
|
+
*/
|
|
289
|
+
icon: string;
|
|
290
|
+
/** Lowercase route segment, for example `queues`. The Console serves the section at `/_vitehub/<id>`. */
|
|
291
|
+
id: string;
|
|
292
|
+
/** Plural display name, for example `Queues`. */
|
|
293
|
+
label: string;
|
|
294
|
+
view: TView;
|
|
295
|
+
/** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
|
|
296
|
+
pages?: readonly ViteHubConsoleSectionPage[];
|
|
297
|
+
}
|
|
298
|
+
/** A named export of an owner package server module that the host imports in its generated server code. */
|
|
299
|
+
interface ViteHubConsoleServerExport {
|
|
300
|
+
/** Named export of `module`. */
|
|
301
|
+
export: string;
|
|
302
|
+
/**
|
|
303
|
+
* Absolute path of the owner module, such as `ownModule(import.meta.url, "runtime/console")`, or an owner package
|
|
304
|
+
* specifier that the host maps to a module path that the application can import.
|
|
305
|
+
*/
|
|
306
|
+
module: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Server module export that returns records on each Console request. The export must be a
|
|
310
|
+
* {@link ViteHubConsoleRuntimeRecordReader}.
|
|
311
|
+
*/
|
|
312
|
+
interface ViteHubConsoleRuntimeReader extends ViteHubConsoleServerExport {}
|
|
313
|
+
/**
|
|
314
|
+
* A record table that also reads records at request time. The Console shows the build-time records of `read` first,
|
|
315
|
+
* then the records of the `runtime` reader. A runtime record updates the build-time record with the same id: its cells
|
|
316
|
+
* and fields replace the build-time ones with the same key or label.
|
|
317
|
+
*/
|
|
318
|
+
interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
|
|
319
|
+
/** Reads build-time records on the server. When omitted, the section has only runtime records. */
|
|
320
|
+
read?: (options: TOptions) => MaybePromise<readonly ViteHubConsoleRecord[]>;
|
|
321
|
+
runtime: ViteHubConsoleRuntimeReader;
|
|
322
|
+
/**
|
|
323
|
+
* Returns the absolute path of the application module that turns the section on, such as `server/comments.ts`, or
|
|
324
|
+
* `undefined` when the project has none. With it, the host shows the section only when the module exists; without
|
|
325
|
+
* it, a Vite option enables the section.
|
|
326
|
+
*/
|
|
327
|
+
entry?: (options: TOptions) => MaybePromise<string | undefined>;
|
|
328
|
+
}
|
|
329
|
+
//#endregion
|
|
330
|
+
export { ViteHubInspectionPluginMetadata as i, ViteHubConsoleRuntimeRecordTableSection as n, ViteHubDefinitionSummary as r, ViteHubConsoleRecord as t };
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ScheduleDefinition, r as ScheduleDefinitionInput } from "./types-Cw5LjPuc.js";
|
|
2
2
|
//#region src/definition.d.ts
|
|
3
|
-
export declare function defineSchedule<TResult = unknown>(
|
|
3
|
+
export declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult> & {
|
|
4
|
+
cron: string;
|
|
5
|
+
}): ScheduleDefinition<TResult> & {
|
|
6
|
+
cron: string;
|
|
7
|
+
};
|
|
4
8
|
export declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult>): ScheduleDefinition<TResult>;
|
|
5
9
|
//#endregion
|
package/dist/definition.js
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as isIanaTimeZone } from "./time-zone-SBldrUgt.js";
|
|
2
|
+
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
3
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-Mpeks7J0.js";
|
|
4
|
+
//#region src/definition.ts
|
|
5
|
+
const cronFieldPattern = /^[^\s]+$/;
|
|
6
|
+
const scheduleDefinitionKeys = /* @__PURE__ */ new Set([
|
|
7
|
+
"manual",
|
|
8
|
+
"cron",
|
|
9
|
+
"handler",
|
|
10
|
+
"timeZone"
|
|
11
|
+
]);
|
|
12
|
+
function isCronString(value) {
|
|
13
|
+
return value !== null && value !== void 0 && String(value) === value;
|
|
14
|
+
}
|
|
15
|
+
function assertOwnDefinitionFields(input, keys, message, diagnostic) {
|
|
16
|
+
const inheritedKey = [...keys].find((key) => key in input && !Object.hasOwn(input, key));
|
|
17
|
+
if (inheritedKey) throw diagnostic({ message: `${message} The "${inheritedKey}" option must be an own property.` });
|
|
18
|
+
}
|
|
19
|
+
function validateCron(cron) {
|
|
20
|
+
if (typeof cron !== "string" || cron.trim() !== cron || cron.length === 0) throw scheduleErrorDiagnostics.SCHEDULE_C0001({ message: "`defineSchedule()` requires a cron string." });
|
|
21
|
+
const fields = cron.split(/\s+/);
|
|
22
|
+
if (fields.length !== 5 || !fields.every((field) => cronFieldPattern.test(field))) throw scheduleErrorDiagnostics.SCHEDULE_C0002({ message: "`defineSchedule()` cron must be a five-field cron expression." });
|
|
23
|
+
}
|
|
24
|
+
/** The `defineSchedule(cron, handler, options)` form was removed. Name the object form in the error. */
|
|
25
|
+
const positionalFormMessage = "`defineSchedule(cron, handler)` was removed. Pass one object: `defineSchedule({ cron: \"0 9 * * *\", handler })`, with `manual` and `timeZone` in the same object.";
|
|
26
|
+
function defineSchedule(input, ...removed) {
|
|
27
|
+
if (isCronString(input) || removed.length) throw scheduleErrorDiagnostics.SCHEDULE_C0007({ message: positionalFormMessage });
|
|
28
|
+
if (!isRecord(input)) throw scheduleErrorDiagnostics.SCHEDULE_C0003({ message: "`defineSchedule()` expects an object with `cron` and `handler`." });
|
|
29
|
+
if (!Object.hasOwn(input, "handler")) throw scheduleErrorDiagnostics.SCHEDULE_C0003({ message: "`defineSchedule()` expects an object with `handler`, and `cron` unless code starts the Schedule with `startSchedule()`." });
|
|
30
|
+
assertOwnDefinitionFields(input, scheduleDefinitionKeys, "`defineSchedule()` does not accept inherited options.", scheduleErrorDiagnostics.SCHEDULE_C0004);
|
|
31
|
+
const unknownKey = Object.keys(input).find((key) => !scheduleDefinitionKeys.has(key));
|
|
32
|
+
if (unknownKey) throw scheduleErrorDiagnostics.SCHEDULE_C0004({ message: `\`defineSchedule()\` does not support the "${unknownKey}" option.` });
|
|
33
|
+
const hasCron = Object.hasOwn(input, "cron");
|
|
34
|
+
if (hasCron) validateCron(input.cron);
|
|
35
|
+
else if (input.timeZone !== void 0) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` timeZone needs a cron. A Schedule without cron takes its time zone from `startSchedule()`." });
|
|
36
|
+
if (typeof input.handler !== "function") throw scheduleErrorDiagnostics.SCHEDULE_C0005({ message: "`defineSchedule()` requires a schedule handler." });
|
|
37
|
+
if (input.manual !== void 0 && input.manual !== true && input.manual !== false) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` manual must be a boolean." });
|
|
38
|
+
if (input.timeZone !== void 0 && !isIanaTimeZone(input.timeZone)) throw scheduleErrorDiagnostics.SCHEDULE_C0006({ message: "`defineSchedule()` timeZone must be an IANA time zone, such as \"Europe/Madrid\"." });
|
|
39
|
+
const definition = hasCron ? {
|
|
40
|
+
cron: input.cron,
|
|
41
|
+
handler: input.handler
|
|
42
|
+
} : { handler: input.handler };
|
|
43
|
+
if (input.timeZone !== void 0) definition.timeZone = input.timeZone;
|
|
44
|
+
if (input.manual !== void 0) definition.options = { manual: input.manual };
|
|
45
|
+
return definition;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
2
48
|
export { defineSchedule };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-Mpeks7J0.js";
|
|
2
|
+
import { parseCronExpression } from "cron-schedule";
|
|
3
|
+
//#region src/runtime/due.ts
|
|
4
|
+
const weekdayIndexes = /* @__PURE__ */ new Map([
|
|
5
|
+
["Sun", 0],
|
|
6
|
+
["Mon", 1],
|
|
7
|
+
["Tue", 2],
|
|
8
|
+
["Wed", 3],
|
|
9
|
+
["Thu", 4],
|
|
10
|
+
["Fri", 5],
|
|
11
|
+
["Sat", 6]
|
|
12
|
+
]);
|
|
13
|
+
const minuteMs = 6e4;
|
|
14
|
+
const hourMinutes = 60;
|
|
15
|
+
const dayMinutes = 1440;
|
|
16
|
+
const timeZoneFormatters = /* @__PURE__ */ new Map();
|
|
17
|
+
const parsedScheduleCrons = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
function timeZoneFormatter(timeZone) {
|
|
19
|
+
let formatter = timeZoneFormatters.get(timeZone);
|
|
20
|
+
if (!formatter) {
|
|
21
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
22
|
+
day: "numeric",
|
|
23
|
+
hour: "numeric",
|
|
24
|
+
hourCycle: "h23",
|
|
25
|
+
minute: "numeric",
|
|
26
|
+
month: "numeric",
|
|
27
|
+
timeZone,
|
|
28
|
+
weekday: "short",
|
|
29
|
+
year: "numeric"
|
|
30
|
+
});
|
|
31
|
+
timeZoneFormatters.set(timeZone, formatter);
|
|
32
|
+
}
|
|
33
|
+
return formatter;
|
|
34
|
+
}
|
|
35
|
+
function scheduleDateFields(scheduledAt, timeZone) {
|
|
36
|
+
if (!timeZone || timeZone === "UTC") return {
|
|
37
|
+
day: scheduledAt.getUTCDate(),
|
|
38
|
+
hour: scheduledAt.getUTCHours(),
|
|
39
|
+
minute: scheduledAt.getUTCMinutes(),
|
|
40
|
+
month: scheduledAt.getUTCMonth(),
|
|
41
|
+
weekday: scheduledAt.getUTCDay(),
|
|
42
|
+
year: scheduledAt.getUTCFullYear()
|
|
43
|
+
};
|
|
44
|
+
const values = new Map(timeZoneFormatter(timeZone).formatToParts(scheduledAt).map((part) => [part.type, part.value]));
|
|
45
|
+
const weekday = weekdayIndexes.get(values.get("weekday") || "");
|
|
46
|
+
const day = Number(values.get("day"));
|
|
47
|
+
const hour = Number(values.get("hour"));
|
|
48
|
+
const minute = Number(values.get("minute"));
|
|
49
|
+
const month = Number(values.get("month")) - 1;
|
|
50
|
+
const year = Number(values.get("year"));
|
|
51
|
+
if (weekday === void 0 || [
|
|
52
|
+
day,
|
|
53
|
+
hour,
|
|
54
|
+
minute,
|
|
55
|
+
month,
|
|
56
|
+
year
|
|
57
|
+
].some((value) => !Number.isInteger(value))) throw scheduleErrorDiagnostics.SCHEDULE_R0022({ message: `Schedule time zone could not resolve calendar fields: ${timeZone}` });
|
|
58
|
+
return {
|
|
59
|
+
day,
|
|
60
|
+
hour,
|
|
61
|
+
minute,
|
|
62
|
+
month,
|
|
63
|
+
weekday,
|
|
64
|
+
year
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function parseScheduleCron(schedule) {
|
|
68
|
+
const expression = schedule.cron;
|
|
69
|
+
const cached = parsedScheduleCrons.get(schedule);
|
|
70
|
+
if (cached?.expression === expression) return cached.cron;
|
|
71
|
+
if (expression.trim().split(/\s+/).length !== 5) throw scheduleErrorDiagnostics.SCHEDULE_R0023({ message: `Schedule "${schedule.id}" must use a five-field cron expression.` });
|
|
72
|
+
const cron = parseCronExpression(expression);
|
|
73
|
+
parsedScheduleCrons.set(schedule, {
|
|
74
|
+
expression,
|
|
75
|
+
cron
|
|
76
|
+
});
|
|
77
|
+
return cron;
|
|
78
|
+
}
|
|
79
|
+
function matchesCronHour(cron, fields) {
|
|
80
|
+
if (!cron.hours.includes(fields.hour) || !cron.months.includes(fields.month)) return false;
|
|
81
|
+
if (cron.days.length !== 31 && cron.weekdays.length !== 7) return cron.days.includes(fields.day) || cron.weekdays.includes(fields.weekday);
|
|
82
|
+
return cron.days.includes(fields.day) && cron.weekdays.includes(fields.weekday);
|
|
83
|
+
}
|
|
84
|
+
function localEpochMs(fields) {
|
|
85
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
86
|
+
date.setUTCFullYear(fields.year, fields.month, fields.day);
|
|
87
|
+
date.setUTCHours(fields.hour, fields.minute, 0, 0);
|
|
88
|
+
return date.getTime();
|
|
89
|
+
}
|
|
90
|
+
function sameLocalMinute(left, right) {
|
|
91
|
+
return left.minute === right.minute && left.hour === right.hour && left.day === right.day && left.month === right.month && left.year === right.year;
|
|
92
|
+
}
|
|
93
|
+
/** Detect a repeated local minute using the actual offset before the transition (including historical 23-hour rollbacks). */
|
|
94
|
+
function isRepeatedFixedLocalTime(cron, fields, scheduledAt, timeZone) {
|
|
95
|
+
if (!timeZone || timeZone === "UTC" || cron.minutes.length === hourMinutes || cron.hours.length === 24) return false;
|
|
96
|
+
const previous = /* @__PURE__ */ new Date(scheduledAt.getTime() - dayMinutes * minuteMs);
|
|
97
|
+
const currentOffset = localEpochMs(fields) - scheduledAt.getTime();
|
|
98
|
+
const previousOffset = localEpochMs(scheduleDateFields(previous, timeZone)) - previous.getTime();
|
|
99
|
+
if (previousOffset <= currentOffset) return false;
|
|
100
|
+
return sameLocalMinute(scheduleDateFields(new Date(scheduledAt.getTime() - (previousOffset - currentOffset)), timeZone), fields);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Detect a local time that the clock skipped on a spring-forward day, read with the offset from before the gap, as
|
|
104
|
+
* RFC 5545 and `Temporal` do. `02:30` in a gap from `02:00` to `03:00` maps to `03:30`, so it runs once that day.
|
|
105
|
+
*/
|
|
106
|
+
function matchesSkippedLocalTime(cron, fields, scheduledAt, timeZone) {
|
|
107
|
+
if (!timeZone || timeZone === "UTC") return false;
|
|
108
|
+
const currentOffset = localEpochMs(fields) - scheduledAt.getTime();
|
|
109
|
+
const previous = /* @__PURE__ */ new Date(scheduledAt.getTime() - dayMinutes * minuteMs);
|
|
110
|
+
const previousOffset = localEpochMs(scheduleDateFields(previous, timeZone)) - previous.getTime();
|
|
111
|
+
if (previousOffset >= currentOffset) return false;
|
|
112
|
+
const beforeGap = new Date(scheduledAt.getTime() - (currentOffset - previousOffset));
|
|
113
|
+
if (localEpochMs(scheduleDateFields(beforeGap, timeZone)) - beforeGap.getTime() !== previousOffset) return false;
|
|
114
|
+
const skipped = scheduleDateFields(new Date(scheduledAt.getTime() + previousOffset), void 0);
|
|
115
|
+
return cron.minutes.includes(skipped.minute) && matchesCronHour(cron, skipped);
|
|
116
|
+
}
|
|
117
|
+
/** Returns `true` when `schedule` is due at the exact minute `scheduledAt`. */
|
|
118
|
+
function isScheduleDue(schedule, scheduledAt) {
|
|
119
|
+
if (scheduledAt.getUTCSeconds() !== 0 || scheduledAt.getUTCMilliseconds() !== 0) return false;
|
|
120
|
+
const cron = parseScheduleCron(schedule);
|
|
121
|
+
const fields = scheduleDateFields(scheduledAt, schedule.timeZone);
|
|
122
|
+
if (cron.minutes.includes(fields.minute) && matchesCronHour(cron, fields)) return !isRepeatedFixedLocalTime(cron, fields, scheduledAt, schedule.timeZone);
|
|
123
|
+
return matchesSkippedLocalTime(cron, fields, scheduledAt, schedule.timeZone);
|
|
124
|
+
}
|
|
125
|
+
/** Minutes east of UTC that `timeZone` uses at `at`, such as `120` for Madrid in summer. */
|
|
126
|
+
function timeZoneOffsetMinutes(at, timeZone) {
|
|
127
|
+
const minute = /* @__PURE__ */ new Date(Math.floor(at.getTime() / minuteMs) * minuteMs);
|
|
128
|
+
return Math.round((localEpochMs(scheduleDateFields(minute, timeZone)) - minute.getTime()) / minuteMs);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns the newest minute at or before `at` that the UTC `cron` matches, within one day, or the current minute.
|
|
132
|
+
* This is an estimate for hosts without a scheduled timestamp, not an identity for delayed or retried deliveries.
|
|
133
|
+
*/
|
|
134
|
+
function latestCronMinute(cron, at) {
|
|
135
|
+
const record = {
|
|
136
|
+
cron,
|
|
137
|
+
id: cron
|
|
138
|
+
};
|
|
139
|
+
const latest = Math.floor(at.getTime() / minuteMs) * minuteMs;
|
|
140
|
+
for (let time = latest; time > latest - dayMinutes * minuteMs; time -= minuteMs) if (isScheduleDue(record, new Date(time))) return new Date(time);
|
|
141
|
+
return new Date(latest);
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { latestCronMinute as n, timeZoneOffsetMinutes as r, isScheduleDue as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
|
|
2
|
+
//#region src/durability.d.ts
|
|
3
|
+
/** What the build passes to `scheduleDurability()`. */
|
|
4
|
+
export interface ScheduleDurabilityInput {
|
|
5
|
+
driver: "process";
|
|
6
|
+
/** The process runtime claims occurrences with SQL leases in the Default Database. */
|
|
7
|
+
leases?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The durability of schedule claims. With SQL leases in a Postgres Default Database, one instance runs each
|
|
11
|
+
* occurrence. Without them, each process claims each occurrence for itself.
|
|
12
|
+
*/
|
|
13
|
+
export declare function scheduleDurability(input: ScheduleDurabilityInput, context: DurabilityContext): Durability[];
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/durability.ts
|
|
2
|
+
/**
|
|
3
|
+
* The durability of schedule claims. With SQL leases in a Postgres Default Database, one instance runs each
|
|
4
|
+
* occurrence. Without them, each process claims each occurrence for itself.
|
|
5
|
+
*/
|
|
6
|
+
function scheduleDurability(input, context) {
|
|
7
|
+
const database = input.leases ? context.find("database") : void 0;
|
|
8
|
+
if (database?.store === "postgres") return [{
|
|
9
|
+
primitive: "schedule",
|
|
10
|
+
store: "postgres",
|
|
11
|
+
scope: "shared",
|
|
12
|
+
reason: "Leases in the Default Database. One instance runs each occurrence."
|
|
13
|
+
}];
|
|
14
|
+
return [{
|
|
15
|
+
primitive: "schedule",
|
|
16
|
+
store: input.driver,
|
|
17
|
+
scope: "process",
|
|
18
|
+
reason: database ? `Leases in the ${database.store} Default Database do not lock across processes. Every instance can run every occurrence.` : "This process claims each occurrence. Every instance runs every occurrence.",
|
|
19
|
+
fix: input.leases ? "Define the Default Database with `dialect: \"postgresql\"`." : "Run the schedules on one instance only. Schedule has no shared lease store for Node yet."
|
|
20
|
+
}];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { scheduleDurability };
|