@vite-hub/realtime 0.0.4 → 0.3.0

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.
@@ -0,0 +1,319 @@
1
+ import { ViteHubContext } from "@vite-hub/runtime";
2
+ import { AnyExtension, JSONContent } from "@tiptap/core";
3
+ import { WorkspaceSnapshot } from "@vite-hub/workspace";
4
+ import { H3Event } from "h3";
5
+ //#region src/types.d.ts
6
+ /** JSON value stored in one field of a structured Realtime document. */
7
+ type RealtimeFieldValue = null | boolean | number | string | RealtimeFieldValue[] | {
8
+ [key: string]: RealtimeFieldValue;
9
+ };
10
+ /** Plain document state that crosses the document adapter boundary. */
11
+ interface RealtimeDocumentSnapshot {
12
+ /** Structured fields. Each key is one last-write-wins entry in the `fields` Y.Map. */
13
+ fields?: Record<string, RealtimeFieldValue>;
14
+ /** Markdown body, encoded and decoded by the definition's editor codec. */
15
+ body: string;
16
+ }
17
+ interface RealtimeLoadedDocument extends RealtimeDocumentSnapshot {
18
+ /** Version of the stored document, or `null` when it does not exist yet. */
19
+ digest: string | null;
20
+ }
21
+ /** A validation problem reported by a document adapter. Saving still succeeded. */
22
+ interface RealtimeIssue {
23
+ field?: string;
24
+ message: string;
25
+ path?: Array<string | number>;
26
+ }
27
+ /** Identity resolved on the server. Presence shows `name` and `image`; `id` keys awareness colours. */
28
+ interface RealtimeUser {
29
+ email?: string;
30
+ id: string;
31
+ image?: string;
32
+ name?: string;
33
+ }
34
+ interface RealtimeDocumentContext {
35
+ /**
36
+ * Room authority holding the live document: one process (`memory`), a Durable Object (`cloudflare`), or rooms that
37
+ * several Node instances share through Postgres (`postgres`) or Redis (`redis`).
38
+ */
39
+ authority: "cloudflare" | "memory" | "postgres" | "redis";
40
+ definition: string;
41
+ documentId: string;
42
+ }
43
+ interface RealtimeSaveOptions {
44
+ /** Users who changed the room since the previous save, in order of their latest edit. */
45
+ editors: RealtimeUser[];
46
+ /** Compare-and-set guard: the digest the room was seeded from or last saved as. `null` means create. */
47
+ ifDigest: string | null;
48
+ /** Why Realtime saves: debounced edits, the last client leaving, or an explicit client request. */
49
+ reason: "idle" | "leave" | "request";
50
+ /** The most recent editor, when identified. */
51
+ user?: RealtimeUser;
52
+ }
53
+ interface RealtimeSaveResult {
54
+ digest: string;
55
+ issues?: RealtimeIssue[];
56
+ /**
57
+ * The stored form when the adapter normalized what it received. Realtime merges the
58
+ * difference into the live room without resetting clients.
59
+ */
60
+ stored?: RealtimeDocumentSnapshot;
61
+ }
62
+ interface RealtimeHistoryOptions {
63
+ /** Digest of the save that the history entry must contain. */
64
+ digest: string;
65
+ message?: string;
66
+ user?: RealtimeUser;
67
+ }
68
+ /**
69
+ * Loads and stores one kind of Realtime document. The live room keeps the Yjs state as
70
+ * its source of truth; the adapter receives plain snapshots and owns the stored copy.
71
+ */
72
+ interface RealtimeDocumentAdapter {
73
+ /** Short label shown by `vitehub inspect`, for example `workspace` or `content`. */
74
+ kind?: string;
75
+ load(context: RealtimeDocumentContext): Promise<RealtimeLoadedDocument>;
76
+ /**
77
+ * Store a snapshot only when the stored digest still equals `ifDigest`. Throw
78
+ * `RealtimeDocumentConflict` when it does not; Realtime then reloads and re-seeds the room.
79
+ */
80
+ save(context: RealtimeDocumentContext, document: RealtimeDocumentSnapshot, options: RealtimeSaveOptions): Promise<RealtimeSaveResult>;
81
+ /** Optional durable history entry, used by `history.checkpoint()`. */
82
+ checkpoint?(context: RealtimeDocumentContext, options: RealtimeHistoryOptions): Promise<WorkspaceSnapshot>;
83
+ /**
84
+ * Optional. Called while a writable room has clients: when a client joins or leaves, and every 60 seconds. `users`
85
+ * are the identified users connected now. Use it to keep a lease, such as the live edit lease of a Content document.
86
+ * A thrown error shows in the room `status` until the next successful call.
87
+ */
88
+ hold?(context: RealtimeDocumentContext, options: RealtimeHoldOptions): Promise<void> | void;
89
+ /** Optional. Called once after the last client left a room that `hold()` kept, after the room saved its edits. */
90
+ release?(context: RealtimeDocumentContext): Promise<void> | void;
91
+ }
92
+ interface RealtimeHoldOptions {
93
+ /** Identified users connected to the room now, in the order they joined. */
94
+ users: RealtimeUser[];
95
+ }
96
+ interface RealtimeWorkspaceDocumentOptions {
97
+ /** Workspace whose working tree stores the Markdown file at the document path. */
98
+ workspace: string;
99
+ }
100
+ /**
101
+ * Editor schema and Markdown codec shared by the server and the browser. The server never
102
+ * creates an editor view: it builds the schema from `extensions()` and calls the codec.
103
+ */
104
+ interface RealtimeEditor {
105
+ extensions(): AnyExtension[];
106
+ /**
107
+ * Version of the schema and codec. Change it when a new `extensions()` or codec cannot read the Yjs state of the
108
+ * previous one, such as a node type that was removed or renamed. A room persisted under another version opens fresh
109
+ * from the stored Markdown, and a browser that connects with another version is read-only until it reloads.
110
+ */
111
+ version?: string;
112
+ fromMarkdown(markdown: string): Promise<JSONContent> | JSONContent;
113
+ toMarkdown(document: JSONContent): Promise<string> | string;
114
+ /**
115
+ * Checks a stored document when a room opens. Return `writable: false` when the codec
116
+ * cannot edit it without loss: the room then opens read-only and never saves.
117
+ */
118
+ verify?(markdown: string, options: {
119
+ fields?: Record<string, RealtimeFieldValue>;
120
+ }): Promise<RealtimeVerifyResult> | RealtimeVerifyResult;
121
+ }
122
+ /** Result of `RealtimeEditor.verify()` for one stored document. */
123
+ interface RealtimeVerifyResult {
124
+ /**
125
+ * The body this codec writes for the unchanged document, when it differs from the stored
126
+ * body only in form. A save whose body equals it, with unchanged fields, writes nothing.
127
+ */
128
+ canonical?: string;
129
+ /** Problems shown in the room `status` until the first save. */
130
+ issues?: RealtimeIssue[];
131
+ /** `false` opens the room read-only: no saves, and clients cannot change the body or fields. */
132
+ writable: boolean;
133
+ }
134
+ /**
135
+ * Why a connection is read-only: `access` (authorization denied write), `document` (the codec cannot edit it
136
+ * losslessly), or `version` (the browser runs another editor version than the server, so it must reload to edit).
137
+ */
138
+ type RealtimeReadOnlyReason = "access" | "document" | "version";
139
+ /**
140
+ * The H3 event of a WebSocket upgrade or HTTP request, so helpers that take an `H3Event` accept it. Read the request,
141
+ * its cookies, and the platform bindings from `event["~standard"]`. `context` holds what a middleware set, such as the
142
+ * session.
143
+ */
144
+ type RealtimeRequestEvent = H3Event & ViteHubContext;
145
+ interface RealtimeRequestContext {
146
+ definition: string;
147
+ /** The request event of the WebSocket upgrade or HTTP request. */
148
+ event: RealtimeRequestEvent;
149
+ request: Request;
150
+ }
151
+ interface RealtimeOriginContext extends RealtimeRequestContext {
152
+ /** The `Origin` header of a request from another origin than the app's. */
153
+ origin: string;
154
+ }
155
+ interface RealtimeAuthorizeContext extends RealtimeRequestContext {
156
+ /** Requested document, or `null` for the definition's Workspace event channel. */
157
+ documentId: string | null;
158
+ mode: "read" | "write";
159
+ user: RealtimeUser | null;
160
+ }
161
+ interface RealtimePersistenceOptions {
162
+ /** Quiet period after the last edit before saving. Default 2000 ms. */
163
+ debounce?: number;
164
+ /** Longest time edits wait while editing continues. Default 10000 ms. */
165
+ maxWait?: number;
166
+ }
167
+ interface RealtimeDefinitionIdentity {
168
+ /** Resolve the user for a request, replacing the ViteHub Auth session. Return `null` for anonymous. */
169
+ identify?: (context: RealtimeRequestContext) => RealtimeUser | null | undefined | Promise<RealtimeUser | null | undefined>;
170
+ /**
171
+ * Let a page on another origin connect, such as a script that sites load from the app. Return `true` to accept
172
+ * `origin`. Without it, only the app's own origin connects. The browser sends cookies with a cross-site handshake
173
+ * too, so `identify` and `authorize` must then trust only what the page sends on purpose, such as a ticket in
174
+ * `params`, never the session cookie. `auth: true` without `identify` rejects it: the Auth session is a cookie.
175
+ */
176
+ origins?: (context: RealtimeOriginContext) => boolean | Promise<boolean>;
177
+ }
178
+ type RealtimeAuthorize = (context: RealtimeAuthorizeContext) => boolean | Promise<boolean>;
179
+ /**
180
+ * Who can use the rooms. Set one: `auth: true` requires an identified user, `authorize()` decides each request, and
181
+ * `access: "public"` lets anyone read and write.
182
+ */
183
+ type RealtimeDefinitionAccess = RealtimeDefinitionIdentity & ({
184
+ access?: never;
185
+ /** Require an identified user. Without `identify`, the identity is the ViteHub Auth session. */
186
+ auth: true;
187
+ /** Allow or deny one access mode. Only `true` allows. Write denial makes a connection read-only. */
188
+ authorize?: RealtimeAuthorize;
189
+ } | {
190
+ access?: never;
191
+ /** Require an identified user. Without `identify`, the identity is the ViteHub Auth session. */
192
+ auth?: boolean;
193
+ /** Allow or deny one access mode. Only `true` allows. Write denial makes a connection read-only. */
194
+ authorize: RealtimeAuthorize;
195
+ } | {
196
+ /** Let anyone who can reach the app read and write every room of this definition. */
197
+ access: "public";
198
+ auth?: never;
199
+ authorize?: never;
200
+ });
201
+ interface RealtimeDocumentFields {
202
+ document: RealtimeWorkspaceDocumentOptions | RealtimeDocumentAdapter;
203
+ /**
204
+ * Editor schema and Markdown codec. Defaults to the built-in Markdown kit. A function picks the codec of each
205
+ * document, such as one per Content collection; browsers that open the document must use the same schema.
206
+ */
207
+ editor?: RealtimeEditor | ((context: RealtimeDocumentContext) => RealtimeEditor);
208
+ history?: {
209
+ checkpoint: true | {
210
+ message?: string;
211
+ };
212
+ };
213
+ /** Idle saves. `false` saves only when a client calls `save()` or `history.checkpoint()`. */
214
+ persistence?: RealtimePersistenceOptions | false;
215
+ }
216
+ /** A definition whose rooms edit one stored document each. */
217
+ type RealtimeDocumentDefinition = RealtimeDocumentFields & RealtimeDefinitionAccess;
218
+ interface RealtimePresenceFields {
219
+ document: false;
220
+ editor?: never;
221
+ history?: never;
222
+ persistence?: never;
223
+ /**
224
+ * Lets server code ask the one browser in a room with `requestRealtimeRoom()` from `@vite-hub/realtime/server`. The
225
+ * browser answers with `room.onRequest()`. Default `false`: rooms without it refuse request frames.
226
+ */
227
+ requests?: boolean;
228
+ /**
229
+ * `"user"`: each person gets their own rooms. A room is keyed by the identity of whoever joins it, so the same room id
230
+ * for two people is two rooms, and `requestRealtimeRoom()` must name the person with `{ user }`. The identity is the
231
+ * ViteHub Auth session when the app has Auth, read without requiring one; everyone without a session shares one
232
+ * `anonymous` scope. With `identify` or `auth: true`, those decide the identity.
233
+ */
234
+ scope?: "user";
235
+ }
236
+ /**
237
+ * A definition whose rooms hold no document, only presence: who is in the room and the awareness fields each client
238
+ * sets, such as a cursor. Nothing loads or saves, and `authorize()` is asked only for `read`. Join its rooms with
239
+ * `connectRealtimeRoom()` from `@vite-hub/realtime/client`.
240
+ */
241
+ type RealtimePresenceDefinition = RealtimePresenceFields & RealtimeDefinitionAccess;
242
+ type RealtimeDefinition = RealtimeDocumentDefinition | RealtimePresenceDefinition;
243
+ /** Server-written save state, mirrored in the read-only `status` Y.Map. */
244
+ interface RealtimeDocumentStatus {
245
+ digest: string | null;
246
+ /** Message of the latest failed save, cleared by the next successful save. */
247
+ error: string | null;
248
+ issues: RealtimeIssue[];
249
+ savedAt: string | null;
250
+ savedBy: RealtimeUser | null;
251
+ }
252
+ interface RealtimeSaved extends RealtimeDocumentStatus {
253
+ document: RealtimeDocumentSnapshot;
254
+ }
255
+ interface RealtimeCheckpoint extends RealtimeSaved {
256
+ digest: string;
257
+ snapshot: WorkspaceSnapshot;
258
+ }
259
+ interface DiscoveredRealtimeDefinition {
260
+ handler: string;
261
+ name: string;
262
+ /** `server-realtime` for a file in `server/realtime/`; `contributed` for one another package adds, such as Content. */
263
+ source: "contributed" | "server-realtime";
264
+ }
265
+ interface RealtimeOptions {
266
+ /**
267
+ * The driver that runs the rooms. `auto` (default) picks Durable Objects on Cloudflare and memory on the dev server. A
268
+ * Node build picks when the server starts: Redis with `REDIS_URL`, else Postgres on the connection of the Default
269
+ * Database when it is on Postgres (`REALTIME_POSTGRES_URL` overrides it), else memory. `postgres` and `redis` require
270
+ * their connection. `memory` keeps rooms in one process.
271
+ */
272
+ driver?: "auto" | "cloudflare" | "memory" | "postgres" | "redis";
273
+ /**
274
+ * Keeps the rooms of this app apart from other apps on the same Redis or Postgres. Defaults to the `name` of
275
+ * `vitehub()`, else the `name` in the root `package.json`, else the root folder name. `REALTIME_NAMESPACE` replaces
276
+ * it when the server starts.
277
+ */
278
+ namespace?: string;
279
+ projectRoot?: string;
280
+ }
281
+ interface RealtimePerson {
282
+ clientId: number;
283
+ color: string;
284
+ id: string;
285
+ image?: string;
286
+ name: string;
287
+ }
288
+ type RealtimeWorkspaceChange = {
289
+ operation: "create" | "delete" | "update";
290
+ path: string;
291
+ } | {
292
+ operation: "move";
293
+ from: string;
294
+ to: string;
295
+ };
296
+ type RealtimeResetReason = "source-changed" | "stale";
297
+ type RealtimeRegistry = Record<string, () => Promise<{
298
+ default: RealtimeDefinition;
299
+ }>>;
300
+ /**
301
+ * Codes that `save()`, `history.checkpoint()`, and `refresh()` of `useRealtimeTiptap()` return in the `[error, data]` tuple.
302
+ */
303
+ /** The codes that `requestRealtimeRoom()` returns in `[error, undefined]`. */
304
+ type RealtimeRoomRequestErrorCode = "REALTIME_ROOM_ABORTED" | "REALTIME_ROOM_CROWDED" | "REALTIME_ROOM_ELSEWHERE" | "REALTIME_ROOM_EMPTY" | "REALTIME_ROOM_REFUSED" | "REALTIME_ROOM_REQUESTS_OFF" | "REALTIME_ROOM_TIMEOUT";
305
+ type RealtimeRequestErrorCode = "REALTIME_DISABLED" | "REALTIME_DISCONNECTED" | "REALTIME_INVALID_RESPONSE" | "REALTIME_MISSING_DOCUMENT" | "REALTIME_REQUEST_FAILED";
306
+ /**
307
+ * Whether this build has a Realtime room driver. ViteHub generates it for each build; an unavailable build says why
308
+ * and how to enable Realtime.
309
+ */
310
+ type RealtimeAvailability = {
311
+ available: true;
312
+ } | {
313
+ available: false;
314
+ host?: string;
315
+ reason: string;
316
+ fix: string;
317
+ };
318
+ //#endregion
319
+ export { RealtimeSaveOptions as A, RealtimeReadOnlyReason as C, RealtimeRequestEvent as D, RealtimeRequestErrorCode as E, RealtimeWorkspaceChange as F, RealtimeWorkspaceDocumentOptions as I, RealtimeSaved as M, RealtimeUser as N, RealtimeResetReason as O, RealtimeVerifyResult as P, RealtimePresenceDefinition as S, RealtimeRequestContext as T, RealtimeLoadedDocument as _, RealtimeDefinition as a, RealtimePersistenceOptions as b, RealtimeDocumentContext as c, RealtimeDocumentStatus as d, RealtimeEditor as f, RealtimeIssue as g, RealtimeHoldOptions as h, RealtimeCheckpoint as i, RealtimeSaveResult as j, RealtimeRoomRequestErrorCode as k, RealtimeDocumentDefinition as l, RealtimeHistoryOptions as m, RealtimeAuthorizeContext as n, RealtimeDefinitionAccess as o, RealtimeFieldValue as p, RealtimeAvailability as r, RealtimeDocumentAdapter as s, DiscoveredRealtimeDefinition as t, RealtimeDocumentSnapshot as u, RealtimeOptions as v, RealtimeRegistry as w, RealtimePerson as x, RealtimeOriginContext as y };
package/dist/vite.d.ts CHANGED
@@ -1,10 +1,181 @@
1
- import { r as RealtimeModuleOptions } from "./types-BSDtKw5d.js";
1
+ import { t as DiscoveredRealtimeDefinition, v as RealtimeOptions } from "./types-1DVVG5ro.js";
2
2
  import { Plugin } from "vite";
3
-
3
+ //#region src/discovery.d.ts
4
+ export declare function discoverRealtimeDefinitions(rootDir: string, serverDirs?: string[]): DiscoveredRealtimeDefinition[];
5
+ //#endregion
6
+ //#region ../internal/src/deployment.d.ts
7
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
8
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
9
+ //#endregion
10
+ //#region ../internal/src/inspect.d.ts
11
+ interface ViteHubDefinitionField {
12
+ label: string;
13
+ value: string;
14
+ }
15
+ /** Serializable summary of one discovered Definition. Files are relative to the project root. */
16
+ interface ViteHubDefinitionSummary {
17
+ fields: readonly ViteHubDefinitionField[];
18
+ file: string;
19
+ name: string;
20
+ source: string;
21
+ }
22
+ /** Lists the Definitions that one owner package discovered for the resolved Vite config. */
23
+ interface ViteHubDefinitionInspector {
24
+ /** Stable singular kind, for example `queue` or `rate-limit`. */
25
+ kind: string;
26
+ label: string;
27
+ list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
28
+ }
29
+ /** One generated Provider Output file or directory that an owner package can write. */
30
+ interface ViteHubProviderOutputEntry {
31
+ description: string;
32
+ owner: string;
33
+ /** Absolute path. */
34
+ path: string;
35
+ }
36
+ /**
37
+ * Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
38
+ * The CLI sets `provider-output` when only a generated Wrangler config names the id.
39
+ */
40
+ type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
41
+ /** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
42
+ interface ViteHubResourceSummary {
43
+ /** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
44
+ binding?: string;
45
+ /** Definition or store name. */
46
+ definition: string;
47
+ /** Env variable that supplied the id when `source` is `env`. */
48
+ env?: string;
49
+ host: "cloudflare" | "vercel";
50
+ id?: string;
51
+ /** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
52
+ kind: string;
53
+ /** Resource name on the host, when the config names it. */
54
+ name?: string;
55
+ /** Explains how the host finds the resource when no id or name is known locally. */
56
+ note?: string;
57
+ owner: string;
58
+ /** Absent when no id is known yet. */
59
+ source?: ViteHubResourceIdSource;
60
+ }
61
+ interface ViteHubInspectionContributor {
62
+ definitions?: readonly ViteHubDefinitionInspector[];
63
+ providerOutput?: readonly ViteHubProviderOutputEntry[];
64
+ resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
65
+ }
66
+ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
67
+ interface ViteHubInspectionPluginMetadata {
68
+ inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
69
+ }
70
+ //#endregion
71
+ //#region ../internal/src/build/deployment-plan-output.d.ts
72
+ /**
73
+ * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
74
+ * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
75
+ * It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
76
+ */
77
+ interface DeploymentEnvEntry {
78
+ /** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
79
+ path?: string;
80
+ /** The host variable names, in read order. The first name that is set supplies the value. */
81
+ names: readonly string[];
82
+ /** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
83
+ prefix?: string;
84
+ required: boolean;
85
+ secret: boolean;
86
+ /** A default supplies the value when no name is set. */
87
+ hasDefault: boolean;
88
+ /** The primitives that read these names, such as `blob`. Server Env declarations have none. */
89
+ owners?: readonly string[];
90
+ }
91
+ /** What a primitive needs to know to name the variables it reads in the deployed app. */
92
+ interface DeploymentEnvContext {
93
+ host: ViteHubHost;
94
+ }
95
+ /**
96
+ * The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
97
+ * config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
98
+ * Return names only, never values.
99
+ */
100
+ type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
101
+ //#endregion
102
+ //#region ../internal/src/durability.d.ts
103
+ /**
104
+ * One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
105
+ * imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
106
+ * `Durability` lines of `@vite-hub/runtime/durability`.
107
+ */
108
+ interface DurabilityContribution {
109
+ /** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
110
+ primitive: string;
111
+ /** The absolute file of the reporter module. */
112
+ module: string;
113
+ export: string;
114
+ /**
115
+ * The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
116
+ * `JSON.stringify`, so do not put credentials here.
117
+ */
118
+ input: unknown;
119
+ }
120
+ /** The `vitehub.durability` field of a primitive's Vite plugin. */
121
+ interface DurabilityPluginMetadata {
122
+ /** Called after Vite resolves the config. Return an empty list when the primitive is off. */
123
+ durability?: () => readonly DurabilityContribution[];
124
+ }
125
+ //#endregion
126
+ //#region src/inspect.d.ts
127
+ type RealtimeInspectionDriver = "auto" | "cloudflare" | "memory" | "node" | "postgres" | "redis" | "unsupported";
128
+ //#endregion
4
129
  //#region src/vite.d.ts
5
- interface RealtimeVitePluginOptions extends RealtimeModuleOptions {
130
+ /** Where a contributed definition runs. */
131
+ export interface RealtimeContributionContext {
132
+ /**
133
+ * Where the rooms of this build live: Durable Objects (`cloudflare`), or the memory of each Node process (`memory`),
134
+ * also when Node instances share rooms through Postgres or Redis. Contributions only run when there is one.
135
+ */
136
+ driver: "cloudflare" | "memory";
137
+ /** `.vitehub/nitro/realtime`, for generated definition files. */
138
+ directory: string;
139
+ projectRoot: string;
140
+ serverDirs?: string[];
141
+ }
142
+ /** Definitions and Nitro plugins that another package adds, such as Content live editing. */
143
+ export interface RealtimeContribution {
144
+ /** Generated definition files. A file in `server/realtime/` with the same name wins. */
145
+ definitions?: Array<Pick<DiscoveredRealtimeDefinition, "handler" | "name">>;
146
+ /** Nitro plugin files to install with the Realtime route. */
147
+ plugins?: string[];
148
+ }
149
+ export interface RealtimeVitePluginOptions extends RealtimeOptions {
150
+ /** Module that exports the app's `databases`, for the Postgres bus. Defaults to `@vite-hub/database/drizzle`. */
151
+ databaseImport?: string;
6
152
  importBase?: string;
153
+ /**
154
+ * Adds definitions owned by another package. It runs only when the build has a room driver (Cloudflare Durable
155
+ * Objects, a Node server, or memory in development). Without one, Realtime leaves the contribution out without an
156
+ * error, so the contributing feature can fall back.
157
+ */
158
+ contribute?: (context: RealtimeContributionContext) => Promise<RealtimeContribution | undefined> | RealtimeContribution | undefined;
7
159
  }
8
- declare function hubRealtime(options?: RealtimeVitePluginOptions): Plugin;
9
- //#endregion
10
- export { RealtimeVitePluginOptions, hubRealtime };
160
+ export type RealtimeVitePlugin = Plugin & {
161
+ /** The variables that Realtime reads on the deployed host. See `realtimeDeploymentEnv()`. */
162
+ api: {
163
+ deploymentEnv: DeploymentEnvContribution;
164
+ };
165
+ vitehub: ViteHubInspectionPluginMetadata & DurabilityPluginMetadata;
166
+ };
167
+ export interface RealtimeInspectionOptions {
168
+ /** Resolved driver. Defaults to `auto`. */
169
+ driver?: RealtimeInspectionDriver;
170
+ projectRoot: string;
171
+ serverDirs?: string[];
172
+ /** Definitions other packages contributed to this build, such as Content live editing. */
173
+ contributed?: readonly DiscoveredRealtimeDefinition[];
174
+ }
175
+ /**
176
+ * Lists Realtime Definitions with their document adapter, editor codec, identity, authorization,
177
+ * persistence, and driver, read statically from each definition file.
178
+ */
179
+ export declare function inspectRealtimeDefinitions(options: RealtimeInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
180
+ export declare function hubRealtime(options?: RealtimeVitePluginOptions): RealtimeVitePlugin;
181
+ //#endregion