@vite-hub/realtime 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 +71 -12
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +2 -0
- package/dist/bus-Bi-Ec414.js +476 -0
- package/dist/bus-protocol-wXkXW28q.d.ts +66 -0
- package/dist/bus.d.ts +85 -0
- package/dist/bus.js +2 -0
- package/dist/client/browser.js +53 -0
- package/dist/client.d.ts +25 -4
- package/dist/client.js +66 -8
- package/dist/conflict-Bg8vCisd.js +63 -0
- package/dist/{document-CtY6umWY.d.ts → document-DPaywuCO.d.ts} +2 -2
- package/dist/{document-BFaqcCAL.js → document-DjBrcgpY.js} +22 -10
- package/dist/durability.d.ts +10 -0
- package/dist/durability.js +46 -0
- package/dist/{layout-Br1aOL7o.js → editor-BM5-vHqf.js} +30 -36
- package/dist/error-diagnostics-B_66irmt.js +141 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +3 -7
- package/dist/internal/runtime/unavailable.d.ts +5 -0
- package/dist/internal/runtime/unavailable.js +8 -0
- package/dist/keepalive-BCs-uXp4.js +33 -0
- package/dist/layout-DNaxppTZ.js +34 -0
- package/dist/{layout-WNWejwOY.d.ts → layout-fyQnhwCg.d.ts} +1 -1
- package/dist/{protocol-9ZDLEcSS.js → object-CzKyK0hX.js} +57 -58
- package/dist/presence-Tuy1y_l9.js +53 -0
- package/dist/request-BUwa359H.d.ts +48 -0
- package/dist/request-CWaHqW3R.js +192 -0
- package/dist/server.d.ts +64 -28
- package/dist/server.js +1002 -379
- package/dist/{types-Bw6-42Se.d.ts → types-1DVVG5ro.d.ts} +118 -14
- package/dist/vite.d.ts +109 -12
- package/dist/vite.js +469 -138
- package/dist/vue.d.ts +8 -5
- package/dist/vue.js +25 -11
- package/package.json +71 -19
- package/dist/application-path-CJblgbWK.js +0 -6
- package/dist/conflict-rguoaHlE.js +0 -34
- package/dist/durable-key-tnSw58ZK.js +0 -8
- package/dist/error-diagnostics-Cvm6vRXQ.js +0 -73
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ViteHubContext } from "@vite-hub/runtime";
|
|
1
2
|
import { AnyExtension, JSONContent } from "@tiptap/core";
|
|
2
3
|
import { WorkspaceSnapshot } from "@vite-hub/workspace";
|
|
3
4
|
import { H3Event } from "h3";
|
|
@@ -31,8 +32,11 @@ interface RealtimeUser {
|
|
|
31
32
|
name?: string;
|
|
32
33
|
}
|
|
33
34
|
interface RealtimeDocumentContext {
|
|
34
|
-
/**
|
|
35
|
-
|
|
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";
|
|
36
40
|
definition: string;
|
|
37
41
|
documentId: string;
|
|
38
42
|
}
|
|
@@ -99,6 +103,12 @@ interface RealtimeWorkspaceDocumentOptions {
|
|
|
99
103
|
*/
|
|
100
104
|
interface RealtimeEditor {
|
|
101
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;
|
|
102
112
|
fromMarkdown(markdown: string): Promise<JSONContent> | JSONContent;
|
|
103
113
|
toMarkdown(document: JSONContent): Promise<string> | string;
|
|
104
114
|
/**
|
|
@@ -121,14 +131,27 @@ interface RealtimeVerifyResult {
|
|
|
121
131
|
/** `false` opens the room read-only: no saves, and clients cannot change the body or fields. */
|
|
122
132
|
writable: boolean;
|
|
123
133
|
}
|
|
124
|
-
/**
|
|
125
|
-
|
|
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;
|
|
126
145
|
interface RealtimeRequestContext {
|
|
127
146
|
definition: string;
|
|
128
|
-
/** The
|
|
129
|
-
event:
|
|
147
|
+
/** The request event of the WebSocket upgrade or HTTP request. */
|
|
148
|
+
event: RealtimeRequestEvent;
|
|
130
149
|
request: Request;
|
|
131
150
|
}
|
|
151
|
+
interface RealtimeOriginContext extends RealtimeRequestContext {
|
|
152
|
+
/** The `Origin` header of a request from another origin than the app's. */
|
|
153
|
+
origin: string;
|
|
154
|
+
}
|
|
132
155
|
interface RealtimeAuthorizeContext extends RealtimeRequestContext {
|
|
133
156
|
/** Requested document, or `null` for the definition's Workspace event channel. */
|
|
134
157
|
documentId: string | null;
|
|
@@ -141,13 +164,41 @@ interface RealtimePersistenceOptions {
|
|
|
141
164
|
/** Longest time edits wait while editing continues. Default 10000 ms. */
|
|
142
165
|
maxWait?: number;
|
|
143
166
|
}
|
|
144
|
-
interface
|
|
145
|
-
/** Require an identified user. Without `identify`, the identity is the ViteHub Auth session. */
|
|
146
|
-
auth?: boolean;
|
|
167
|
+
interface RealtimeDefinitionIdentity {
|
|
147
168
|
/** Resolve the user for a request, replacing the ViteHub Auth session. Return `null` for anonymous. */
|
|
148
169
|
identify?: (context: RealtimeRequestContext) => RealtimeUser | null | undefined | Promise<RealtimeUser | null | undefined>;
|
|
149
|
-
/**
|
|
150
|
-
|
|
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 {
|
|
151
202
|
document: RealtimeWorkspaceDocumentOptions | RealtimeDocumentAdapter;
|
|
152
203
|
/**
|
|
153
204
|
* Editor schema and Markdown codec. Defaults to the built-in Markdown kit. A function picks the codec of each
|
|
@@ -162,6 +213,33 @@ interface RealtimeDefinition {
|
|
|
162
213
|
/** Idle saves. `false` saves only when a client calls `save()` or `history.checkpoint()`. */
|
|
163
214
|
persistence?: RealtimePersistenceOptions | false;
|
|
164
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;
|
|
165
243
|
/** Server-written save state, mirrored in the read-only `status` Y.Map. */
|
|
166
244
|
interface RealtimeDocumentStatus {
|
|
167
245
|
digest: string | null;
|
|
@@ -184,8 +262,20 @@ interface DiscoveredRealtimeDefinition {
|
|
|
184
262
|
/** `server-realtime` for a file in `server/realtime/`; `contributed` for one another package adds, such as Content. */
|
|
185
263
|
source: "contributed" | "server-realtime";
|
|
186
264
|
}
|
|
187
|
-
interface
|
|
188
|
-
|
|
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;
|
|
189
279
|
projectRoot?: string;
|
|
190
280
|
}
|
|
191
281
|
interface RealtimePerson {
|
|
@@ -210,6 +300,20 @@ type RealtimeRegistry = Record<string, () => Promise<{
|
|
|
210
300
|
/**
|
|
211
301
|
* Codes that `save()`, `history.checkpoint()`, and `refresh()` of `useRealtimeTiptap()` return in the `[error, data]` tuple.
|
|
212
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";
|
|
213
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
|
+
};
|
|
214
318
|
//#endregion
|
|
215
|
-
export { RealtimeSaveOptions as C,
|
|
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,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as DiscoveredRealtimeDefinition, v as RealtimeOptions } from "./types-1DVVG5ro.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
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
|
|
3
10
|
//#region ../internal/src/inspect.d.ts
|
|
4
11
|
interface ViteHubDefinitionField {
|
|
5
12
|
label: string;
|
|
@@ -26,23 +33,107 @@ interface ViteHubProviderOutputEntry {
|
|
|
26
33
|
/** Absolute path. */
|
|
27
34
|
path: string;
|
|
28
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
|
+
}
|
|
29
61
|
interface ViteHubInspectionContributor {
|
|
30
62
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
31
63
|
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
64
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
32
65
|
}
|
|
33
66
|
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
34
67
|
interface ViteHubInspectionPluginMetadata {
|
|
35
68
|
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
36
69
|
}
|
|
37
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
|
|
38
126
|
//#region src/inspect.d.ts
|
|
39
|
-
type
|
|
127
|
+
type RealtimeInspectionDriver = "auto" | "cloudflare" | "memory" | "node" | "postgres" | "redis" | "unsupported";
|
|
40
128
|
//#endregion
|
|
41
129
|
//#region src/vite.d.ts
|
|
42
130
|
/** Where a contributed definition runs. */
|
|
43
131
|
export interface RealtimeContributionContext {
|
|
44
|
-
/**
|
|
45
|
-
|
|
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";
|
|
46
137
|
/** `.vitehub/nitro/realtime`, for generated definition files. */
|
|
47
138
|
directory: string;
|
|
48
139
|
projectRoot: string;
|
|
@@ -55,21 +146,27 @@ export interface RealtimeContribution {
|
|
|
55
146
|
/** Nitro plugin files to install with the Realtime route. */
|
|
56
147
|
plugins?: string[];
|
|
57
148
|
}
|
|
58
|
-
export interface RealtimeVitePluginOptions extends
|
|
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;
|
|
59
152
|
importBase?: string;
|
|
60
153
|
/**
|
|
61
|
-
* Adds definitions owned by another package. It runs only when the build has a room
|
|
62
|
-
* Objects, or memory in development
|
|
63
|
-
*
|
|
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.
|
|
64
157
|
*/
|
|
65
158
|
contribute?: (context: RealtimeContributionContext) => Promise<RealtimeContribution | undefined> | RealtimeContribution | undefined;
|
|
66
159
|
}
|
|
67
160
|
export type RealtimeVitePlugin = Plugin & {
|
|
68
|
-
|
|
161
|
+
/** The variables that Realtime reads on the deployed host. See `realtimeDeploymentEnv()`. */
|
|
162
|
+
api: {
|
|
163
|
+
deploymentEnv: DeploymentEnvContribution;
|
|
164
|
+
};
|
|
165
|
+
vitehub: ViteHubInspectionPluginMetadata & DurabilityPluginMetadata;
|
|
69
166
|
};
|
|
70
167
|
export interface RealtimeInspectionOptions {
|
|
71
|
-
/** Resolved
|
|
72
|
-
|
|
168
|
+
/** Resolved driver. Defaults to `auto`. */
|
|
169
|
+
driver?: RealtimeInspectionDriver;
|
|
73
170
|
projectRoot: string;
|
|
74
171
|
serverDirs?: string[];
|
|
75
172
|
/** Definitions other packages contributed to this build, such as Content live editing. */
|
|
@@ -77,7 +174,7 @@ export interface RealtimeInspectionOptions {
|
|
|
77
174
|
}
|
|
78
175
|
/**
|
|
79
176
|
* Lists Realtime Definitions with their document adapter, editor codec, identity, authorization,
|
|
80
|
-
* persistence, and
|
|
177
|
+
* persistence, and driver, read statically from each definition file.
|
|
81
178
|
*/
|
|
82
179
|
export declare function inspectRealtimeDefinitions(options: RealtimeInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
|
|
83
180
|
export declare function hubRealtime(options?: RealtimeVitePluginOptions): RealtimeVitePlugin;
|