@vite-hub/queue 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.
Files changed (63) hide show
  1. package/README.md +170 -31
  2. package/dist/client-Cj50hQYp.js +180 -0
  3. package/dist/cloudflare-client-DYsAjM8B.js +140 -0
  4. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-BJHYRCMQ.js} +3 -2
  5. package/dist/config-BcTDeQIP.js +105 -0
  6. package/dist/durability.d.ts +13 -0
  7. package/dist/durability.js +47 -0
  8. package/dist/error-diagnostics-BRartC1z.js +181 -0
  9. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  10. package/dist/errors-DL3pcNO4.js +77 -0
  11. package/dist/handler-response-By0Fpspv.js +61 -0
  12. package/dist/index.d.ts +29 -83
  13. package/dist/index.js +24 -11
  14. package/dist/inspect-PeuckaC3.js +30 -0
  15. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  16. package/dist/internal/runtime/cloudflare-client.js +1 -1
  17. package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
  18. package/dist/internal/runtime/cloudflare-vite.js +111 -1
  19. package/dist/internal/runtime/local-client.d.ts +17 -0
  20. package/dist/internal/runtime/local-client.js +71 -0
  21. package/dist/internal/runtime/postgres-client.d.ts +46 -0
  22. package/dist/internal/runtime/postgres-client.js +560 -0
  23. package/dist/internal/runtime/state.d.ts +23 -15
  24. package/dist/internal/runtime/state.js +2 -2
  25. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  26. package/dist/internal/runtime/vercel-client.js +120 -63
  27. package/dist/internal/runtime/worker-client.d.ts +6 -0
  28. package/dist/internal/runtime/worker-client.js +11 -0
  29. package/dist/invariant-D8_xBqmZ.js +22 -0
  30. package/dist/local-CGckW5nr.js +540 -0
  31. package/dist/local-CVVRVWeR.d.ts +22 -0
  32. package/dist/object-D8pRdprI.js +15 -0
  33. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  34. package/dist/operations-Crwjca91.js +124 -0
  35. package/dist/operations.d.ts +69 -0
  36. package/dist/operations.js +1344 -0
  37. package/dist/runtime/hosted.d.ts +5 -9
  38. package/dist/runtime/hosted.js +21 -23
  39. package/dist/state-mVA2X_wa.js +196 -0
  40. package/dist/types-BD-8U9zS.d.ts +420 -0
  41. package/dist/types-DS_rqu9l.d.ts +10 -0
  42. package/dist/vercel-region-D1CivgdA.js +26 -0
  43. package/dist/virtual.d.ts +4 -0
  44. package/dist/vite.d.ts +655 -40
  45. package/dist/vite.js +2071 -2
  46. package/package.json +66 -30
  47. package/dist/_app-D29AwUdD.d.ts +0 -11
  48. package/dist/app-BZpq2cwC.js +0 -10
  49. package/dist/client-DG9fweET.js +0 -93
  50. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  51. package/dist/cloudflare-vite-BlQfDVZD.js +0 -97
  52. package/dist/cloudflare-vite-nFPor46-.d.ts +0 -24
  53. package/dist/config-CNgAeIND.js +0 -53
  54. package/dist/delivery-error-glgYWC9g.js +0 -45
  55. package/dist/errors-CjuG_qr-.js +0 -108
  56. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  57. package/dist/internal/runtime/vercel-vite.js +0 -49
  58. package/dist/nuxt.d.ts +0 -19
  59. package/dist/nuxt.js +0 -30
  60. package/dist/state-Cno9O7YS.js +0 -110
  61. package/dist/types-CwvoMATy.d.ts +0 -169
  62. package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
  63. package/dist/vite-DOuoen0w.js +0 -4414
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,135 @@
1
- import { a as DiscoveredQueueDefinition, m as QueueModuleOptions } from "./types-CwvoMATy.js";
2
- import { Plugin } from "vite";
3
-
1
+ import { M as QueueOptions, o as DiscoveredQueueDefinition } from "./types-BD-8U9zS.js";
2
+ import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
3
+ import "nostics";
4
+ import { Plugin, UserConfig } from "vite";
5
+ //#region ../internal/src/deployment.d.ts
6
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
7
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
8
+ //#endregion
9
+ //#region ../internal/src/inspect.d.ts
10
+ interface ViteHubDefinitionField {
11
+ label: string;
12
+ value: string;
13
+ }
14
+ /** Serializable summary of one discovered Definition. Files are relative to the project root. */
15
+ interface ViteHubDefinitionSummary {
16
+ fields: readonly ViteHubDefinitionField[];
17
+ file: string;
18
+ name: string;
19
+ source: string;
20
+ }
21
+ /** Lists the Definitions that one owner package discovered for the resolved Vite config. */
22
+ interface ViteHubDefinitionInspector {
23
+ /** Stable singular kind, for example `queue` or `rate-limit`. */
24
+ kind: string;
25
+ label: string;
26
+ list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
27
+ }
28
+ /** One generated Provider Output file or directory that an owner package can write. */
29
+ interface ViteHubProviderOutputEntry {
30
+ description: string;
31
+ owner: string;
32
+ /** Absolute path. */
33
+ path: string;
34
+ }
35
+ /**
36
+ * Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
37
+ * The CLI sets `provider-output` when only a generated Wrangler config names the id.
38
+ */
39
+ type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
40
+ /** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
41
+ interface ViteHubResourceSummary {
42
+ /** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
43
+ binding?: string;
44
+ /** Definition or store name. */
45
+ definition: string;
46
+ /** Env variable that supplied the id when `source` is `env`. */
47
+ env?: string;
48
+ host: "cloudflare" | "vercel";
49
+ id?: string;
50
+ /** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
51
+ kind: string;
52
+ /** Resource name on the host, when the config names it. */
53
+ name?: string;
54
+ /** Explains how the host finds the resource when no id or name is known locally. */
55
+ note?: string;
56
+ owner: string;
57
+ /** Absent when no id is known yet. */
58
+ source?: ViteHubResourceIdSource;
59
+ }
60
+ interface ViteHubInspectionContributor {
61
+ definitions?: readonly ViteHubDefinitionInspector[];
62
+ providerOutput?: readonly ViteHubProviderOutputEntry[];
63
+ resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
64
+ }
65
+ //#endregion
66
+ //#region ../internal/src/build/deployment-plan-output.d.ts
67
+ /**
68
+ * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
69
+ * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
70
+ * It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
71
+ */
72
+ interface DeploymentEnvEntry {
73
+ /** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
74
+ path?: string;
75
+ /** The host variable names, in read order. The first name that is set supplies the value. */
76
+ names: readonly string[];
77
+ /** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
78
+ prefix?: string;
79
+ required: boolean;
80
+ secret: boolean;
81
+ /** A default supplies the value when no name is set. */
82
+ hasDefault: boolean;
83
+ /** The primitives that read these names, such as `blob`. Server Env declarations have none. */
84
+ owners?: readonly string[];
85
+ }
86
+ /** What a primitive needs to know to name the variables it reads in the deployed app. */
87
+ interface DeploymentEnvContext {
88
+ host: ViteHubHost;
89
+ }
90
+ /**
91
+ * The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
92
+ * config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
93
+ * Return names only, never values.
94
+ */
95
+ type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
96
+ //#endregion
97
+ //#region ../internal/src/durability.d.ts
98
+ /**
99
+ * One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
100
+ * imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
101
+ * `Durability` lines of `@vite-hub/runtime/durability`.
102
+ */
103
+ interface DurabilityContribution {
104
+ /** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
105
+ primitive: string;
106
+ /** The absolute file of the reporter module. */
107
+ module: string;
108
+ export: string;
109
+ /**
110
+ * The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
111
+ * `JSON.stringify`, so do not put credentials here.
112
+ */
113
+ input: unknown;
114
+ }
115
+ /** The `vitehub.durability` field of a primitive's Vite plugin. */
116
+ interface DurabilityPluginMetadata {
117
+ /** Called after Vite resolves the config. Return an empty list when the primitive is off. */
118
+ durability?: () => readonly DurabilityContribution[];
119
+ }
120
+ //#endregion
121
+ //#region ../internal/src/host-credentials.d.ts
122
+ interface HostCliRunResult {
123
+ exitCode: number | null;
124
+ stdout: string;
125
+ }
126
+ /** Runs a host CLI with an argument array and no shell, and returns its stdout. */
127
+ type HostCliRun = (command: string, args: readonly string[], options: {
128
+ cwd?: string;
129
+ env: NodeJS.ProcessEnv;
130
+ signal?: AbortSignal;
131
+ }) => Promise<HostCliRunResult>;
132
+ //#endregion
4
133
  //#region ../internal/src/provision.d.ts
5
134
  type ProvisionProvider = "cloudflare" | "vercel";
6
135
  interface ProvisionLogger {
@@ -11,6 +140,7 @@ interface ProvisionContext {
11
140
  env: Record<string, string | undefined>;
12
141
  fetch: typeof globalThis.fetch;
13
142
  logger: ProvisionLogger;
143
+ markPlanUnchecked?: () => void;
14
144
  }
15
145
  interface ProvisionState {
16
146
  cloudflare?: Record<string, Record<string, string>>;
@@ -23,18 +153,40 @@ interface ProvisionAction {
23
153
  kind: string;
24
154
  name: string;
25
155
  exists: boolean;
156
+ pending?: boolean;
157
+ /** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
158
+ update?: string;
26
159
  apply: () => Promise<ProvisionResult>;
27
160
  }
161
+ /** One Provision State category that a step records, with the keys that current Definitions use. */
162
+ interface ProvisionStateCategory {
163
+ category: string;
164
+ declared: readonly string[];
165
+ /** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
166
+ resourceIdentity?: (entry: {
167
+ id: string;
168
+ key: string;
169
+ }) => string | undefined;
170
+ /** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
171
+ declaredResourceIdentity?: (key: string) => string | undefined;
172
+ /** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
173
+ deleteHint: (entry: {
174
+ id: string;
175
+ key: string;
176
+ }) => string;
177
+ }
28
178
  interface ProvisionStep {
29
179
  id: string;
30
180
  provider: ProvisionProvider;
31
181
  plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
182
+ /** Describes the Provision State this step records. Runs without network access, also without credentials. */
183
+ recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
32
184
  }
33
185
  //#endregion
34
186
  //#region ../internal/src/cli.d.ts
35
187
  interface ViteHubCliStreams {
36
188
  stderr: {
37
- write: (chunk: string | Uint8Array) => unknown;
189
+ write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
38
190
  };
39
191
  stdout: {
40
192
  write: (chunk: string | Uint8Array) => unknown;
@@ -43,20 +195,41 @@ interface ViteHubCliStreams {
43
195
  interface ViteHubCliSpawnResult {
44
196
  exitCode: number | null;
45
197
  signal?: NodeJS.Signals | null;
198
+ /** The output of the child when `stdout` is `pipe`. */
199
+ stdout?: string;
46
200
  }
47
201
  interface ViteHubCliSpawnOptions {
48
202
  cwd?: string;
49
203
  env?: NodeJS.ProcessEnv;
50
204
  stderr?: "inherit" | "pipe";
51
- stdout?: "inherit" | "pipe";
205
+ /** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
206
+ stdin?: "ignore" | "inherit";
207
+ /** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
208
+ stdout?: "inherit" | "pipe" | "stderr";
52
209
  }
53
210
  type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
54
211
  interface ViteHubCliContext extends ViteHubCliStreams {
55
212
  cwd: string;
56
213
  env: NodeJS.ProcessEnv;
214
+ /** Replaces `fetch` for commands that call a running app, so tests need no server. */
215
+ fetch?: typeof fetch;
216
+ /**
217
+ * Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
218
+ * that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
219
+ * steps, so they still run on a config that throws.
220
+ */
221
+ loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
222
+ /** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
223
+ publicUrl?: string;
57
224
  rootDir: string;
225
+ /** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
226
+ runHostCli?: HostCliRun;
58
227
  spawn: ViteHubCliSpawn;
59
228
  }
229
+ interface ViteHubCliProvision {
230
+ rootDir: string;
231
+ steps: readonly ProvisionStep[];
232
+ }
60
233
  interface ViteHubCliFeature {
61
234
  description?: string;
62
235
  name: string;
@@ -64,79 +237,521 @@ interface ViteHubCliFeature {
64
237
  usage?: string;
65
238
  }
66
239
  interface ViteHubCliCommandNamespace {
240
+ /** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
241
+ defaultFeature?: string;
67
242
  description?: string;
68
243
  features: ViteHubCliFeature[];
69
244
  name: string;
70
245
  }
246
+ /** The flags of `vitehub seed` that every seed gets. */
247
+ interface ViteHubCliSeedOptions {
248
+ /** `--database <name>`: seed only this Database. Only the Database seed runs. */
249
+ database?: string;
250
+ /** The process environment with the env files of `--stage`. */
251
+ env: NodeJS.ProcessEnv;
252
+ /** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
253
+ remote: boolean;
254
+ /** `--timeout <ms>` of each call to the app. */
255
+ timeout?: number;
256
+ /** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
257
+ url?: string;
258
+ }
259
+ /** The seed files of one primitive, which `vitehub seed` writes. */
260
+ interface ViteHubCliSeed {
261
+ /** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
262
+ files: string;
263
+ /** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
264
+ name: string;
265
+ /** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
266
+ run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
267
+ }
71
268
  interface ViteHubCliContributor {
72
269
  namespaces: ViteHubCliCommandNamespace[];
73
270
  provision?: ProvisionStep[];
271
+ /** The seed files that `vitehub seed` writes. */
272
+ seeds?: ViteHubCliSeed[];
273
+ /** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
274
+ publicUrl?: string;
275
+ }
276
+ type StdoutWriteCallback = (error?: Error | null) => void;
277
+ //#endregion
278
+ //#region ../internal/src/contributions.d.ts
279
+ /** Module and export that hold a contributed Definition. */
280
+ interface ContributionDefinition {
281
+ /**
282
+ * Absolute file path, `file:` URL, or package specifier that the application can import. Relative paths are
283
+ * rejected because they have no stable base.
284
+ */
285
+ module: string;
286
+ /** Named export that holds the Definition. Defaults to `default`. */
287
+ export?: string;
288
+ }
289
+ /**
290
+ * One Definition that a Vite plugin adds to a Server Primitive, for example a Workspace, a Schedule, or Database tables.
291
+ * Every owner package reads this shape from `plugin.vitehub.<key>`. Owners can add fields, such as `database`.
292
+ */
293
+ interface Contribution {
294
+ /** Unique name in the owner, for example the Workspace or Schedule name. */
295
+ name: string;
296
+ definition: ContributionDefinition;
297
+ /** Why the plugin adds the Definition. `vitehub inspect` and the Console show it. */
298
+ reason?: string;
299
+ }
300
+ /** Roots that ViteHub passes to every contribution factory. */
301
+ interface ContributionContext {
302
+ /** Vite root. */
303
+ root: string;
304
+ /** ViteHub project root. It can differ from the Vite root, for example in a Nuxt app with a `srcDir`. */
305
+ projectRoot: string;
306
+ /** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
307
+ serverDirs?: readonly string[];
308
+ }
309
+ /**
310
+ * Returns the contributions of a plugin. It runs once per discovery pass, so it must be idempotent and must not depend
311
+ * on the order of Vite config hooks.
312
+ */
313
+ type ContributionFactory<TEntry extends Contribution = Contribution> = (context: ContributionContext) => readonly TEntry[] | undefined | Promise<readonly TEntry[] | undefined>;
314
+ type ContributionSource<TEntry extends Contribution = Contribution> = readonly TEntry[] | ContributionFactory<TEntry>;
315
+ /** A Vite plugin that contributes Definitions under `vitehub[TKey]`. */
316
+ type ContributingPlugin<TKey extends string, TEntry extends Contribution = Contribution> = {
317
+ name?: string;
318
+ vitehub?: { [K in TKey]?: ContributionSource<TEntry>; };
319
+ };
320
+ /** A validated contribution with its export resolved and the name of the plugin that added it. */
321
+ interface CollectedContribution {
322
+ name: string;
323
+ definition: {
324
+ module: string;
325
+ export: string;
326
+ };
327
+ reason?: string;
328
+ /** Name of the contributing Vite plugin. */
329
+ plugin: string;
74
330
  }
75
331
  //#endregion
332
+ //#region src/contributions.d.ts
333
+ /**
334
+ * A Queue Definition that another package adds from its Vite plugin. The Queue plugin merges it with the discovered
335
+ * files, so the registry, the generated types, Cloudflare bindings, Vercel consumers, inspection, and provisioning
336
+ * treat it like `server/queues/<name>.ts`.
337
+ *
338
+ * The generated registry imports the module by path, so `definition.module` must be an absolute file path or a `file:`
339
+ * URL, and the module must `export default defineQueue(...)`.
340
+ */
341
+ type QueueContribution = Contribution;
342
+ /** Roots that ViteHub passes to contribution factories. `root` is the Vite root. */
343
+ type QueueContributionContext = ContributionContext;
344
+ type QueueContributionFactory = ContributionFactory<QueueContribution>;
345
+ /** A Vite plugin that contributes Queue Definitions through `vitehub.queues`. */
346
+ type QueueContributingPlugin = ContributingPlugin<"queues", QueueContribution>;
347
+ /** A validated contribution with the name of the plugin that contributed it. */
348
+ type CollectedQueueContribution = CollectedContribution;
349
+ /**
350
+ * Collects `vitehub.queues` contributions from Vite plugins. Two contributions with one name fail with
351
+ * `QUEUE_DEFINITION_DUPLICATE`. Invalid entries fail with `QUEUE_CONTRIBUTION_INVALID`.
352
+ */
353
+ export declare function collectQueueContributions(plugins: readonly unknown[] | undefined, context: QueueContributionContext): Promise<CollectedQueueContribution[]>;
354
+ //#endregion
76
355
  //#region src/discovery.d.ts
77
- declare function discoverQueueDefinitions(options: {
356
+ /** Discovery source of Queue Definitions that Vite plugins contribute through `vitehub.queues`. */
357
+ export declare const contributedQueueSource = "vite-plugin-contribution";
358
+ interface QueueContributionOptions {
359
+ /** Queue Definitions that Vite plugins contribute. See `collectQueueContributions()`. */
360
+ contributions?: readonly CollectedQueueContribution[];
361
+ }
362
+ export declare function discoverQueueDefinitions(options: QueueContributionOptions & {
78
363
  mode?: "vite-suffix";
79
364
  rootDir: string;
80
365
  scanDirs?: string[];
81
366
  serverDirs?: string[];
82
367
  serverRootDirs?: string[];
83
- } | {
368
+ } | QueueContributionOptions & {
84
369
  mode: "server-queues";
85
370
  scanDirs: string[];
86
371
  }): DiscoveredQueueDefinition[];
87
372
  //#endregion
88
- //#region src/internal/vite-build.d.ts
89
- interface CloudflareQueueConfigOptions {
90
- compatibilityDate?: string;
91
- rootDir?: string;
92
- }
93
- interface CloudflareQueueConfig {
94
- assets?: {
95
- directory?: string;
96
- run_worker_first: string[];
373
+ //#region ../internal/src/console.d.ts
374
+ type MaybePromise<T> = T | Promise<T>;
375
+ /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
376
+ interface ViteHubConsoleDefinitionCatalogView {
377
+ kind: "definition-catalog";
378
+ /** States which runtime data this catalog does not include. */
379
+ notice: string;
380
+ }
381
+ /** Lists Workspace Definitions like a catalog, and browses the refs, revisions, and files of the selected one. */
382
+ interface ViteHubConsoleWorkspaceBrowserView {
383
+ kind: "workspace-browser";
384
+ /** States which runtime data the browser does not include. */
385
+ notice: string;
386
+ }
387
+ interface ViteHubConsoleRecordColumn {
388
+ /** Set it for a column with few values, such as a status. The Console then filters the table by its values. */
389
+ filter?: boolean;
390
+ /** Key in `ViteHubConsoleRecord.cells`. */
391
+ key: string;
392
+ label: string;
393
+ }
394
+ /** Shows records in a table and the selected record's fields in a detail panel. */
395
+ interface ViteHubConsoleRecordTableView {
396
+ columns: readonly ViteHubConsoleRecordColumn[];
397
+ kind: "record-table";
398
+ /** States the source and limits of the records. */
399
+ notice: string;
400
+ }
401
+ /**
402
+ * Lists the collections and documents of an owner runtime and edits them with owner actions: a form generated from each
403
+ * collection's JSON Schema, a Markdown body, save, publish, and revision history.
404
+ */
405
+ interface ViteHubConsoleDocumentEditorView {
406
+ kind: "document-editor";
407
+ /** States where documents are stored and what the editor does not do. */
408
+ notice: string;
409
+ }
410
+ interface ViteHubConsoleOperationColumn {
411
+ /** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
412
+ key: string;
413
+ label: string;
414
+ /**
415
+ * `datetime` shows a time in milliseconds since the epoch as a relative date, such as `5m ago`. `excerpt` cuts a long
416
+ * text. `status` shows the value as a status with a colored dot, such as `Open`. `tones` picks the color of each value.
417
+ * `switch` shows a boolean as a switch that calls the `switch` operation.
418
+ */
419
+ format?: "datetime" | "excerpt" | "status" | "switch";
420
+ /** The color of each value of a `status` column, such as `{ open: "info", resolved: "success" }`. Other values are neutral. */
421
+ tones?: Readonly<Record<string, "error" | "info" | "neutral" | "success" | "warning">>;
422
+ /**
423
+ * What a `switch` column calls when the user flips it: `operation` with an input that maps each key of `input` to a
424
+ * dot path of the item, and the column `key` to the new value. `{ operation: "skills.set", input: { name: "name" } }`
425
+ * on the column `enabled` calls `skills.set` with `{ name, enabled }`, then loads the list again. A user who may only
426
+ * read the section sees the switch disabled.
427
+ */
428
+ switch?: {
429
+ operation: string;
430
+ input: Readonly<Record<string, string>>;
97
431
  };
98
- compatibility_date: string;
99
- compatibility_flags: string[];
100
- main: string;
101
- name?: string;
102
- observability: {
103
- enabled: true;
432
+ }
433
+ /**
434
+ * A button on each row that calls `operation` with the Console user, then loads the list again. `input` maps each input
435
+ * key to a dot path of the item, as a `switch` column does.
436
+ */
437
+ interface ViteHubConsoleOperationAction {
438
+ label: string;
439
+ operation: string;
440
+ input: Readonly<Record<string, string>>;
441
+ /**
442
+ * 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
443
+ * the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
444
+ */
445
+ tab?: true;
446
+ /** Show the button only on rows where each dot path holds one of the listed values. */
447
+ when?: Readonly<Record<string, readonly string[]>>;
448
+ /** Ask this question before the call. `{path}` takes a value from the item. */
449
+ confirm?: string;
450
+ }
451
+ /** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
452
+ interface ViteHubConsoleOperationFilter {
453
+ id: string;
454
+ label: string;
455
+ input: Readonly<Record<string, unknown>>;
456
+ }
457
+ /**
458
+ * Lists the items that an operation returns, called over the Console RPC with the signed-in Console user. The operation
459
+ * checks the access of that user for each item, so the view shows only what the user may read. `operation` must return an
460
+ * array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
461
+ */
462
+ interface ViteHubConsoleOperationView {
463
+ /** Buttons on each row. A user who may only read the section does not see them. */
464
+ actions?: readonly ViteHubConsoleOperationAction[];
465
+ columns: readonly ViteHubConsoleOperationColumn[];
466
+ /**
467
+ * Opens the item of a row in a side panel. `comment-thread` shows an item of `comments.list` as a comment thread
468
+ * where the user reads, replies, resolves, reopens, and mentions people. The panel calls the `comments.*` operations
469
+ * with the Console user, and `?thread=<id>` in the URL opens it.
470
+ */
471
+ detail?: {
472
+ kind: "comment-thread";
473
+ };
474
+ filters?: readonly ViteHubConsoleOperationFilter[];
475
+ kind: "operation-view";
476
+ /**
477
+ * Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
478
+ * app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
479
+ * `{path:href}` takes an app URL that is already encoded, with its query, as it is. Rows where `when.path` is not
480
+ * `when.equals` get none.
481
+ */
482
+ link?: {
483
+ label?: string;
484
+ template: string;
485
+ when?: {
486
+ equals: string;
487
+ path: string;
488
+ };
104
489
  };
105
- queues?: {
106
- consumers: Array<{
107
- queue: string;
108
- }>;
109
- producers: Array<{
110
- binding: string;
111
- queue: string;
112
- }>;
490
+ notice: string;
491
+ /** Operation name, such as `comments.list`. */
492
+ operation: string;
493
+ /** Fetch every page with `limit` and a `before` object whose keys read these dot paths from the last item. */
494
+ pagination?: {
495
+ limit: number;
496
+ cursor: Readonly<Record<string, string>>;
113
497
  };
114
498
  }
115
- declare function createCloudflareQueueConfig(options?: CloudflareQueueConfigOptions): Promise<CloudflareQueueConfig>;
499
+ interface ViteHubConsoleAuthView {
500
+ kind: "auth-management";
501
+ notice: string;
502
+ }
503
+ interface ViteHubConsoleAuthSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleAuthView> {}
504
+ /**
505
+ * The webhooks of the app, their pending debounce timers, and their delivery log. The Console calls the `webhooks.*`
506
+ * operations of `@vite-hub/webhooks` with the Console user to list them, send a test, send a pending delivery now,
507
+ * cancel it, and redeliver. It has no build-time data.
508
+ */
509
+ interface ViteHubConsoleWebhooksView {
510
+ kind: "webhooks";
511
+ notice: string;
512
+ }
513
+ interface ViteHubConsoleWebhooksSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleWebhooksView> {}
514
+ type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleWebhooksView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView | ViteHubConsoleWorkspaceBrowserView;
515
+ /**
516
+ * The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
517
+ * activity, and a New button per collection. It reads the owner `overview` action.
518
+ */
519
+ interface ViteHubConsoleDocumentDashboardView {
520
+ kind: "document-dashboard";
521
+ }
522
+ /**
523
+ * The media library of a document editor section: folders, uploads, alt text, focal points, and crops of the Blob Store
524
+ * that `blob.serve` serves. The owner decides who may use it with `mediaAccess`, and finds the documents that use a file
525
+ * with `references`. The page needs the Blob section, so declare it with `requires: ["blob"]`.
526
+ */
527
+ interface ViteHubConsoleMediaLibraryView {
528
+ kind: "media-library";
529
+ }
530
+ /**
531
+ * The singletons of a document editor section, such as site settings: one row per singleton that opens it in the
532
+ * editor. Singletons appear here instead of among the collections, and the Console hides the page when the section has
533
+ * none.
534
+ */
535
+ interface ViteHubConsoleDocumentSettingsView {
536
+ kind: "document-settings";
537
+ }
538
+ /** A view that the Console UI in `vite-hub` renders for a section page. */
539
+ type ViteHubConsoleSectionPageView = ViteHubConsoleDocumentDashboardView | ViteHubConsoleDocumentSettingsView | ViteHubConsoleMediaLibraryView;
540
+ /**
541
+ * A page of a section next to its main view, such as the Content dashboard or media library. The section sidebar lists
542
+ * the pages, and each page has its own URL:
543
+ *
544
+ * - `/_vitehub/<section>` serves the `index` page, or the main view when the section has none.
545
+ * - `/_vitehub/<section>/-/<page>` serves every other page. The `-` segment keeps page URLs apart from the main view's
546
+ * own segments, such as a collection name.
547
+ *
548
+ * Pages share the access of their section: `console.authorize` that allows the section allows every page of it.
549
+ */
550
+ interface ViteHubConsoleSectionPage {
551
+ /** Lowercase route segment, for example `media`. */
552
+ id: string;
553
+ /** Display name, for example `Media`. */
554
+ label: string;
555
+ /** Iconify class name, for example `i-lucide-image`. */
556
+ icon: string;
557
+ view: ViteHubConsoleSectionPageView;
558
+ /**
559
+ * Serve this page at the section root. At most one page sets it, and `/_vitehub/<section>/-/<id>` then redirects to
560
+ * the root.
561
+ */
562
+ index?: boolean;
563
+ /**
564
+ * Sidebar heading, for example `Assets`. Pages without a group lead the sidebar, above the main view's navigation.
565
+ * Grouped pages follow it, in the order their group first appears.
566
+ */
567
+ group?: string;
568
+ /** Section ids that the project must enable, such as `["blob"]`. The Console leaves the page out otherwise. */
569
+ requires?: readonly string[];
570
+ }
571
+ /** One entry of a record's activity, such as a comment in a thread. `at` is an ISO 8601 timestamp. */
572
+ interface ViteHubConsoleRecordActivity {
573
+ author: string;
574
+ at: string;
575
+ text: string;
576
+ }
577
+ /** One serializable record row. Values are display strings. Do not put credentials in records. */
578
+ interface ViteHubConsoleRecord {
579
+ cells: Readonly<Record<string, string>>;
580
+ fields: readonly ViteHubDefinitionField[];
581
+ id: string;
582
+ /** The Console can run this record when it represents a runnable Schedule Definition. */
583
+ runnable?: boolean;
584
+ /**
585
+ * Where the record lives in the app, such as the page of a comment thread. `href` is an app path that starts with one
586
+ * `/`, or an `https:` URL. The Console opens it in a new tab.
587
+ */
588
+ link?: {
589
+ href: string;
590
+ label: string;
591
+ };
592
+ /** Entries in time order, such as the comments of a thread. The Console shows them as a conversation. */
593
+ activity?: readonly ViteHubConsoleRecordActivity[];
594
+ }
595
+ /** Serializable description of a Console section. The Console UI in `vite-hub` renders the view. */
596
+ interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionView = ViteHubConsoleSectionView> {
597
+ description: string;
598
+ /**
599
+ * Iconify class name, for example `i-lucide-inbox`. The Console draws with Lucide; `ph` also resolves. The
600
+ * Console build bundles the icon of every section in the `vite-hub` Console registry and fails if it cannot resolve one.
601
+ */
602
+ icon: string;
603
+ /** Lowercase route segment, for example `queues`. The Console serves the section at `/_vitehub/<id>`. */
604
+ id: string;
605
+ /** Plural display name, for example `Queues`. */
606
+ label: string;
607
+ view: TView;
608
+ /** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
609
+ pages?: readonly ViteHubConsoleSectionPage[];
610
+ }
611
+ interface ViteHubConsoleDefinitionCatalogSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleDefinitionCatalogView> {
612
+ /** Reads the section data on the server. The Console never runs it in the browser. */
613
+ read: (options: TOptions) => MaybePromise<readonly ViteHubDefinitionSummary[]>;
614
+ }
615
+ interface ViteHubConsoleRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
616
+ /** Reads the section data on the server. The Console never runs it in the browser. */
617
+ read: (options: TOptions) => MaybePromise<readonly ViteHubConsoleRecord[]>;
618
+ }
619
+ /** A named export of an owner package server module that the host imports in its generated server code. */
620
+ interface ViteHubConsoleServerExport {
621
+ /** Named export of `module`. */
622
+ export: string;
623
+ /**
624
+ * Absolute path of the owner module, such as `ownModule(import.meta.url, "runtime/console")`, or an owner package
625
+ * specifier that the host maps to a module path that the application can import.
626
+ */
627
+ module: string;
628
+ }
629
+ /**
630
+ * Server module export that returns records on each Console request. The export must be a
631
+ * {@link ViteHubConsoleRuntimeRecordReader}.
632
+ */
633
+ interface ViteHubConsoleRuntimeReader extends ViteHubConsoleServerExport {}
634
+ /**
635
+ * A record table that also reads records at request time. The Console shows the build-time records of `read` first,
636
+ * then the records of the `runtime` reader. A runtime record updates the build-time record with the same id: its cells
637
+ * and fields replace the build-time ones with the same key or label.
638
+ */
639
+ interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
640
+ /** Reads build-time records on the server. When omitted, the section has only runtime records. */
641
+ read?: (options: TOptions) => MaybePromise<readonly ViteHubConsoleRecord[]>;
642
+ runtime: ViteHubConsoleRuntimeReader;
643
+ /**
644
+ * Returns the absolute path of the application module that turns the section on, such as `server/comments.ts`, or
645
+ * `undefined` when the project has none. With it, the host shows the section only when the module exists; without
646
+ * it, a Vite option enables the section.
647
+ */
648
+ entry?: (options: TOptions) => MaybePromise<string | undefined>;
649
+ }
650
+ /** A section whose list comes from an operation, called with the Console user on each visit. It has no build-time data. */
651
+ interface ViteHubConsoleOperationSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleOperationView> {}
652
+ /**
653
+ * A document editor section. The owner finds the application module that holds its runtime, such as `server/content.ts`,
654
+ * and names the server export that turns that module into {@link ViteHubConsoleDocumentActions}. The host shows the
655
+ * section only when `entry` finds a module, imports the module on the first Console request, and checks the Console
656
+ * section before it calls an action. The owner actions check their own access policy for the signed-in user.
657
+ */
658
+ interface ViteHubConsoleDocumentEditorSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleDocumentEditorView> {
659
+ /** Returns the absolute path of the application module, or `undefined` when the project has none. */
660
+ entry: (options: TOptions) => MaybePromise<string | undefined>;
661
+ /**
662
+ * Reads, at build time and without running the application, what the project lacks for some editor features, such as
663
+ * a runner for scheduled publishes. The Console merges it with the owner `setup` action on each request.
664
+ */
665
+ inspect?: (options: TOptions, entry: string) => MaybePromise<ViteHubConsoleDocumentSetup>;
666
+ /** Owner export that must be a {@link ViteHubConsoleDocumentActionsFactory}. */
667
+ actions: ViteHubConsoleServerExport;
668
+ }
669
+ /**
670
+ * A Console section that an owner package contributes. The owner defines the label, icon, view, and data reader.
671
+ * `TOptions` is the discovery context that the host passes to `read`.
672
+ */
673
+ type ViteHubConsoleSectionContribution<TOptions = void> = ViteHubConsoleAuthSection | ViteHubConsoleWebhooksSection | ViteHubConsoleDefinitionCatalogSection<TOptions> | ViteHubConsoleRecordTableSection<TOptions> | ViteHubConsoleRuntimeRecordTableSection<TOptions> | ViteHubConsoleDocumentEditorSection<TOptions> | ViteHubConsoleOperationSection;
674
+ /** A fix that the owner names for a feature the project lacks, such as `Add authorize to defineContent().` */
675
+ interface ViteHubConsoleDocumentHint {
676
+ /** One sentence that names the fix. Text in backticks shows as code. */
677
+ message: string;
678
+ /** Absolute URL of the documentation for the fix. */
679
+ docs?: string;
680
+ }
681
+ /**
682
+ * What the project lacks for some editor features. The editor names each fix where the feature would be, instead of
683
+ * failing without a reason.
684
+ */
685
+ interface ViteHubConsoleDocumentSetup {
686
+ /** Present when no user can read anything because the owner has no access policy. */
687
+ access?: ViteHubConsoleDocumentHint;
688
+ /**
689
+ * Live co-editing. `definition` names the Realtime Definition whose rooms are `<collection>/<id>`; the editor joins
690
+ * the room of a Markdown document instead of taking the edit lease. `unavailable` names why the owner wanted live
691
+ * editing and the host cannot run it, such as a host without a Realtime authority. Absent when live editing is off.
692
+ */
693
+ live?: {
694
+ definition: string;
695
+ } | {
696
+ unavailable: string;
697
+ };
698
+ /**
699
+ * Present when nothing runs scheduled publishes. The editor disables Schedule, and overdue schedules name the fix.
700
+ */
701
+ schedule?: ViteHubConsoleDocumentHint;
702
+ }
703
+ //#endregion
704
+ //#region src/inspect.d.ts
705
+ interface QueueInspectionOptions {
706
+ /** Queue Definitions that Vite plugins contribute through `vitehub.queues`. */
707
+ contributions?: readonly CollectedQueueContribution[];
708
+ projectRoot: string;
709
+ rootDir: string;
710
+ serverDirs?: string[];
711
+ }
712
+ /** Summarizes discovered Queue Definitions for the CLI and Console. */
713
+ export declare function inspectQueueDefinitions(options: QueueInspectionOptions): ViteHubDefinitionSummary[];
714
+ /** Console section that lists discovered Queue Definitions. `vitehub inspect definitions` reads the same data. */
715
+ export declare const queueConsoleSection: ViteHubConsoleSectionContribution<QueueInspectionOptions>;
116
716
  //#endregion
117
717
  //#region src/vite.d.ts
118
718
  interface QueueProvisionContributingPlugin {
119
719
  vitehub?: {
120
720
  cli?: () => Promise<ViteHubCliContributor>;
721
+ durability?: DurabilityPluginMetadata["durability"];
722
+ inspect?: () => ViteHubInspectionContributor | undefined;
723
+ operations?: readonly OperationContributionEntry[];
121
724
  queue?: {
122
725
  createNitroConfig: (options: QueueNitroConfigOptions) => Promise<Record<string, unknown>>;
123
726
  };
124
727
  };
125
728
  }
126
- type QueueVitePlugin = Plugin & QueueProvisionContributingPlugin;
127
- interface QueueNitroConfigOptions {
729
+ export type QueueVitePlugin = Plugin & QueueProvisionContributingPlugin & {
730
+ /** The variables that Queue reads on the deployed host. See `queueDeploymentEnv()`. */
731
+ api: {
732
+ deploymentEnv: DeploymentEnvContribution;
733
+ };
734
+ };
735
+ export interface QueueNitroConfigOptions {
128
736
  development?: boolean;
129
737
  nitro: Record<string, unknown>;
130
738
  projectRoot: string;
131
739
  root: string;
132
740
  serverDirs?: string[];
741
+ /**
742
+ * The Vite config that a framework replays to make its Nitro config.
743
+ * Queue reads `queue` from it and adds its Cloudflare entries to the provider output of this config, so the final Nitro config keeps them.
744
+ */
745
+ viteConfig?: UserConfig;
133
746
  }
134
- declare function createQueueNitroConfig(plugin: QueueVitePlugin, options: QueueNitroConfigOptions): Promise<Record<string, unknown>>;
135
- declare function hubQueue(options?: QueueModuleOptions): QueueVitePlugin;
136
- declare module "vite" {
137
- interface UserConfig {
138
- queue?: QueueModuleOptions;
139
- }
747
+ /** Options that a framework distribution passes to `hubQueue()`. */
748
+ export interface QueueVitePluginInternalOptions {
749
+ /** Module that exports the app's `databases`, for the postgres driver. Defaults to `@vite-hub/database/drizzle`. */
750
+ databaseImport?: string;
751
+ /** Module that the generated Queue types augment, for example `vite-hub/queue`. Defaults to `@vite-hub/queue`. */
752
+ importBase?: string;
140
753
  }
754
+ export declare function createQueueNitroConfig(plugin: QueueVitePlugin, options: QueueNitroConfigOptions): Promise<Record<string, unknown>>;
755
+ export declare function hubQueue(options?: QueueOptions, internalOptions?: QueueVitePluginInternalOptions): QueueVitePlugin;
141
756
  //#endregion
142
- export { type CloudflareQueueConfig, type CloudflareQueueConfigOptions, QueueNitroConfigOptions, QueueVitePlugin, createCloudflareQueueConfig, createQueueNitroConfig, discoverQueueDefinitions, hubQueue };
757
+ export type { CollectedQueueContribution, QueueContributingPlugin, QueueContribution, QueueContributionContext, QueueContributionFactory, QueueInspectionOptions };