@vite-hub/realtime 0.0.3 → 0.1.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.
- package/README.md +24 -10
- package/dist/application-path-CJblgbWK.js +6 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +142 -0
- package/dist/conflict-CmZizTYl.d.ts +17 -0
- package/dist/conflict-rguoaHlE.js +34 -0
- package/dist/document-BFaqcCAL.js +2029 -0
- package/dist/document-CtY6umWY.d.ts +16 -0
- package/dist/durable-key-tnSw58ZK.js +8 -0
- package/dist/error-diagnostics-Cvm6vRXQ.js +73 -0
- package/dist/index.d.ts +17 -4
- package/dist/index.js +3 -1
- package/dist/layout-Br1aOL7o.js +153 -0
- package/dist/layout-WNWejwOY.d.ts +18 -0
- package/dist/protocol-9ZDLEcSS.js +146 -0
- package/dist/server.d.ts +95 -26
- package/dist/server.js +1596 -497
- package/dist/types-Bw6-42Se.d.ts +215 -0
- package/dist/vite.d.ts +80 -6
- package/dist/vite.js +582 -38
- package/dist/vue.d.ts +67 -3808
- package/dist/vue.js +338 -64
- package/package.json +61 -32
- package/dist/editor-extensions-CZEzrJ-t.js +0 -4860
- package/dist/types-BSDtKw5d.d.ts +0 -42
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { AnyExtension, JSONContent } from "@tiptap/core";
|
|
2
|
+
import { WorkspaceSnapshot } from "@vite-hub/workspace";
|
|
3
|
+
import { H3Event } from "h3";
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
/** JSON value stored in one field of a structured Realtime document. */
|
|
6
|
+
type RealtimeFieldValue = null | boolean | number | string | RealtimeFieldValue[] | {
|
|
7
|
+
[key: string]: RealtimeFieldValue;
|
|
8
|
+
};
|
|
9
|
+
/** Plain document state that crosses the document adapter boundary. */
|
|
10
|
+
interface RealtimeDocumentSnapshot {
|
|
11
|
+
/** Structured fields. Each key is one last-write-wins entry in the `fields` Y.Map. */
|
|
12
|
+
fields?: Record<string, RealtimeFieldValue>;
|
|
13
|
+
/** Markdown body, encoded and decoded by the definition's editor codec. */
|
|
14
|
+
body: string;
|
|
15
|
+
}
|
|
16
|
+
interface RealtimeLoadedDocument extends RealtimeDocumentSnapshot {
|
|
17
|
+
/** Version of the stored document, or `null` when it does not exist yet. */
|
|
18
|
+
digest: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** A validation problem reported by a document adapter. Saving still succeeded. */
|
|
21
|
+
interface RealtimeIssue {
|
|
22
|
+
field?: string;
|
|
23
|
+
message: string;
|
|
24
|
+
path?: Array<string | number>;
|
|
25
|
+
}
|
|
26
|
+
/** Identity resolved on the server. Presence shows `name` and `image`; `id` keys awareness colours. */
|
|
27
|
+
interface RealtimeUser {
|
|
28
|
+
email?: string;
|
|
29
|
+
id: string;
|
|
30
|
+
image?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
}
|
|
33
|
+
interface RealtimeDocumentContext {
|
|
34
|
+
/** Room authority holding the live document: one process (`memory`) or a Durable Object (`cloudflare`). */
|
|
35
|
+
authority: "cloudflare" | "memory";
|
|
36
|
+
definition: string;
|
|
37
|
+
documentId: string;
|
|
38
|
+
}
|
|
39
|
+
interface RealtimeSaveOptions {
|
|
40
|
+
/** Users who changed the room since the previous save, in order of their latest edit. */
|
|
41
|
+
editors: RealtimeUser[];
|
|
42
|
+
/** Compare-and-set guard: the digest the room was seeded from or last saved as. `null` means create. */
|
|
43
|
+
ifDigest: string | null;
|
|
44
|
+
/** Why Realtime saves: debounced edits, the last client leaving, or an explicit client request. */
|
|
45
|
+
reason: "idle" | "leave" | "request";
|
|
46
|
+
/** The most recent editor, when identified. */
|
|
47
|
+
user?: RealtimeUser;
|
|
48
|
+
}
|
|
49
|
+
interface RealtimeSaveResult {
|
|
50
|
+
digest: string;
|
|
51
|
+
issues?: RealtimeIssue[];
|
|
52
|
+
/**
|
|
53
|
+
* The stored form when the adapter normalized what it received. Realtime merges the
|
|
54
|
+
* difference into the live room without resetting clients.
|
|
55
|
+
*/
|
|
56
|
+
stored?: RealtimeDocumentSnapshot;
|
|
57
|
+
}
|
|
58
|
+
interface RealtimeHistoryOptions {
|
|
59
|
+
/** Digest of the save that the history entry must contain. */
|
|
60
|
+
digest: string;
|
|
61
|
+
message?: string;
|
|
62
|
+
user?: RealtimeUser;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Loads and stores one kind of Realtime document. The live room keeps the Yjs state as
|
|
66
|
+
* its source of truth; the adapter receives plain snapshots and owns the stored copy.
|
|
67
|
+
*/
|
|
68
|
+
interface RealtimeDocumentAdapter {
|
|
69
|
+
/** Short label shown by `vitehub inspect`, for example `workspace` or `content`. */
|
|
70
|
+
kind?: string;
|
|
71
|
+
load(context: RealtimeDocumentContext): Promise<RealtimeLoadedDocument>;
|
|
72
|
+
/**
|
|
73
|
+
* Store a snapshot only when the stored digest still equals `ifDigest`. Throw
|
|
74
|
+
* `RealtimeDocumentConflict` when it does not; Realtime then reloads and re-seeds the room.
|
|
75
|
+
*/
|
|
76
|
+
save(context: RealtimeDocumentContext, document: RealtimeDocumentSnapshot, options: RealtimeSaveOptions): Promise<RealtimeSaveResult>;
|
|
77
|
+
/** Optional durable history entry, used by `history.checkpoint()`. */
|
|
78
|
+
checkpoint?(context: RealtimeDocumentContext, options: RealtimeHistoryOptions): Promise<WorkspaceSnapshot>;
|
|
79
|
+
/**
|
|
80
|
+
* Optional. Called while a writable room has clients: when a client joins or leaves, and every 60 seconds. `users`
|
|
81
|
+
* are the identified users connected now. Use it to keep a lease, such as the live edit lease of a Content document.
|
|
82
|
+
* A thrown error shows in the room `status` until the next successful call.
|
|
83
|
+
*/
|
|
84
|
+
hold?(context: RealtimeDocumentContext, options: RealtimeHoldOptions): Promise<void> | void;
|
|
85
|
+
/** Optional. Called once after the last client left a room that `hold()` kept, after the room saved its edits. */
|
|
86
|
+
release?(context: RealtimeDocumentContext): Promise<void> | void;
|
|
87
|
+
}
|
|
88
|
+
interface RealtimeHoldOptions {
|
|
89
|
+
/** Identified users connected to the room now, in the order they joined. */
|
|
90
|
+
users: RealtimeUser[];
|
|
91
|
+
}
|
|
92
|
+
interface RealtimeWorkspaceDocumentOptions {
|
|
93
|
+
/** Workspace whose working tree stores the Markdown file at the document path. */
|
|
94
|
+
workspace: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Editor schema and Markdown codec shared by the server and the browser. The server never
|
|
98
|
+
* creates an editor view: it builds the schema from `extensions()` and calls the codec.
|
|
99
|
+
*/
|
|
100
|
+
interface RealtimeEditor {
|
|
101
|
+
extensions(): AnyExtension[];
|
|
102
|
+
fromMarkdown(markdown: string): Promise<JSONContent> | JSONContent;
|
|
103
|
+
toMarkdown(document: JSONContent): Promise<string> | string;
|
|
104
|
+
/**
|
|
105
|
+
* Checks a stored document when a room opens. Return `writable: false` when the codec
|
|
106
|
+
* cannot edit it without loss: the room then opens read-only and never saves.
|
|
107
|
+
*/
|
|
108
|
+
verify?(markdown: string, options: {
|
|
109
|
+
fields?: Record<string, RealtimeFieldValue>;
|
|
110
|
+
}): Promise<RealtimeVerifyResult> | RealtimeVerifyResult;
|
|
111
|
+
}
|
|
112
|
+
/** Result of `RealtimeEditor.verify()` for one stored document. */
|
|
113
|
+
interface RealtimeVerifyResult {
|
|
114
|
+
/**
|
|
115
|
+
* The body this codec writes for the unchanged document, when it differs from the stored
|
|
116
|
+
* body only in form. A save whose body equals it, with unchanged fields, writes nothing.
|
|
117
|
+
*/
|
|
118
|
+
canonical?: string;
|
|
119
|
+
/** Problems shown in the room `status` until the first save. */
|
|
120
|
+
issues?: RealtimeIssue[];
|
|
121
|
+
/** `false` opens the room read-only: no saves, and clients cannot change the body or fields. */
|
|
122
|
+
writable: boolean;
|
|
123
|
+
}
|
|
124
|
+
/** Why a connection is read-only: `access` (authorization denied write) or `document` (the codec cannot edit it losslessly). */
|
|
125
|
+
type RealtimeReadOnlyReason = "access" | "document";
|
|
126
|
+
interface RealtimeRequestContext {
|
|
127
|
+
definition: string;
|
|
128
|
+
/** The H3 event of the WebSocket upgrade or HTTP request, for reading cookies, context, and platform bindings. */
|
|
129
|
+
event: H3Event;
|
|
130
|
+
request: Request;
|
|
131
|
+
}
|
|
132
|
+
interface RealtimeAuthorizeContext extends RealtimeRequestContext {
|
|
133
|
+
/** Requested document, or `null` for the definition's Workspace event channel. */
|
|
134
|
+
documentId: string | null;
|
|
135
|
+
mode: "read" | "write";
|
|
136
|
+
user: RealtimeUser | null;
|
|
137
|
+
}
|
|
138
|
+
interface RealtimePersistenceOptions {
|
|
139
|
+
/** Quiet period after the last edit before saving. Default 2000 ms. */
|
|
140
|
+
debounce?: number;
|
|
141
|
+
/** Longest time edits wait while editing continues. Default 10000 ms. */
|
|
142
|
+
maxWait?: number;
|
|
143
|
+
}
|
|
144
|
+
interface RealtimeDefinition {
|
|
145
|
+
/** Require an identified user. Without `identify`, the identity is the ViteHub Auth session. */
|
|
146
|
+
auth?: boolean;
|
|
147
|
+
/** Resolve the user for a request, replacing the ViteHub Auth session. Return `null` for anonymous. */
|
|
148
|
+
identify?: (context: RealtimeRequestContext) => RealtimeUser | null | undefined | Promise<RealtimeUser | null | undefined>;
|
|
149
|
+
/** Allow or deny one access mode. Return `false` to deny. Write denial makes a connection read-only. */
|
|
150
|
+
authorize?: (context: RealtimeAuthorizeContext) => boolean | void | Promise<boolean | void>;
|
|
151
|
+
document: RealtimeWorkspaceDocumentOptions | RealtimeDocumentAdapter;
|
|
152
|
+
/**
|
|
153
|
+
* Editor schema and Markdown codec. Defaults to the built-in Markdown kit. A function picks the codec of each
|
|
154
|
+
* document, such as one per Content collection; browsers that open the document must use the same schema.
|
|
155
|
+
*/
|
|
156
|
+
editor?: RealtimeEditor | ((context: RealtimeDocumentContext) => RealtimeEditor);
|
|
157
|
+
history?: {
|
|
158
|
+
checkpoint: true | {
|
|
159
|
+
message?: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/** Idle saves. `false` saves only when a client calls `save()` or `history.checkpoint()`. */
|
|
163
|
+
persistence?: RealtimePersistenceOptions | false;
|
|
164
|
+
}
|
|
165
|
+
/** Server-written save state, mirrored in the read-only `status` Y.Map. */
|
|
166
|
+
interface RealtimeDocumentStatus {
|
|
167
|
+
digest: string | null;
|
|
168
|
+
/** Message of the latest failed save, cleared by the next successful save. */
|
|
169
|
+
error: string | null;
|
|
170
|
+
issues: RealtimeIssue[];
|
|
171
|
+
savedAt: string | null;
|
|
172
|
+
savedBy: RealtimeUser | null;
|
|
173
|
+
}
|
|
174
|
+
interface RealtimeSaved extends RealtimeDocumentStatus {
|
|
175
|
+
document: RealtimeDocumentSnapshot;
|
|
176
|
+
}
|
|
177
|
+
interface RealtimeCheckpoint extends RealtimeSaved {
|
|
178
|
+
digest: string;
|
|
179
|
+
snapshot: WorkspaceSnapshot;
|
|
180
|
+
}
|
|
181
|
+
interface DiscoveredRealtimeDefinition {
|
|
182
|
+
handler: string;
|
|
183
|
+
name: string;
|
|
184
|
+
/** `server-realtime` for a file in `server/realtime/`; `contributed` for one another package adds, such as Content. */
|
|
185
|
+
source: "contributed" | "server-realtime";
|
|
186
|
+
}
|
|
187
|
+
interface RealtimeModuleOptions {
|
|
188
|
+
authority?: "auto" | "cloudflare" | "memory";
|
|
189
|
+
projectRoot?: string;
|
|
190
|
+
}
|
|
191
|
+
interface RealtimePerson {
|
|
192
|
+
clientId: number;
|
|
193
|
+
color: string;
|
|
194
|
+
id: string;
|
|
195
|
+
image?: string;
|
|
196
|
+
name: string;
|
|
197
|
+
}
|
|
198
|
+
type RealtimeWorkspaceChange = {
|
|
199
|
+
operation: "create" | "delete" | "update";
|
|
200
|
+
path: string;
|
|
201
|
+
} | {
|
|
202
|
+
operation: "move";
|
|
203
|
+
from: string;
|
|
204
|
+
to: string;
|
|
205
|
+
};
|
|
206
|
+
type RealtimeResetReason = "source-changed" | "stale";
|
|
207
|
+
type RealtimeRegistry = Record<string, () => Promise<{
|
|
208
|
+
default: RealtimeDefinition;
|
|
209
|
+
}>>;
|
|
210
|
+
/**
|
|
211
|
+
* Codes that `save()`, `history.checkpoint()`, and `refresh()` of `useRealtimeTiptap()` return in the `[error, data]` tuple.
|
|
212
|
+
*/
|
|
213
|
+
type RealtimeRequestErrorCode = "REALTIME_DISABLED" | "REALTIME_DISCONNECTED" | "REALTIME_INVALID_RESPONSE" | "REALTIME_MISSING_DOCUMENT" | "REALTIME_REQUEST_FAILED";
|
|
214
|
+
//#endregion
|
|
215
|
+
export { RealtimeSaveOptions as C, RealtimeVerifyResult as D, RealtimeUser as E, RealtimeWorkspaceChange as O, RealtimeResetReason as S, RealtimeSaved as T, RealtimePerson as _, RealtimeDocumentAdapter as a, RealtimeRequestContext as b, RealtimeDocumentStatus as c, RealtimeHistoryOptions as d, RealtimeHoldOptions as f, RealtimePersistenceOptions as g, RealtimeModuleOptions as h, RealtimeDefinition as i, RealtimeWorkspaceDocumentOptions as k, RealtimeEditor as l, RealtimeLoadedDocument as m, RealtimeAuthorizeContext as n, RealtimeDocumentContext as o, RealtimeIssue as p, RealtimeCheckpoint as r, RealtimeDocumentSnapshot as s, DiscoveredRealtimeDefinition as t, RealtimeFieldValue as u, RealtimeReadOnlyReason as v, RealtimeSaveResult as w, RealtimeRequestErrorCode as x, RealtimeRegistry as y };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,10 +1,84 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as RealtimeModuleOptions, t as DiscoveredRealtimeDefinition } from "./types-Bw6-42Se.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
-
|
|
3
|
+
//#region ../internal/src/inspect.d.ts
|
|
4
|
+
interface ViteHubDefinitionField {
|
|
5
|
+
label: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
/** Serializable summary of one discovered Definition. Files are relative to the project root. */
|
|
9
|
+
interface ViteHubDefinitionSummary {
|
|
10
|
+
fields: readonly ViteHubDefinitionField[];
|
|
11
|
+
file: string;
|
|
12
|
+
name: string;
|
|
13
|
+
source: string;
|
|
14
|
+
}
|
|
15
|
+
/** Lists the Definitions that one owner package discovered for the resolved Vite config. */
|
|
16
|
+
interface ViteHubDefinitionInspector {
|
|
17
|
+
/** Stable singular kind, for example `queue` or `rate-limit`. */
|
|
18
|
+
kind: string;
|
|
19
|
+
label: string;
|
|
20
|
+
list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
|
|
21
|
+
}
|
|
22
|
+
/** One generated Provider Output file or directory that an owner package can write. */
|
|
23
|
+
interface ViteHubProviderOutputEntry {
|
|
24
|
+
description: string;
|
|
25
|
+
owner: string;
|
|
26
|
+
/** Absolute path. */
|
|
27
|
+
path: string;
|
|
28
|
+
}
|
|
29
|
+
interface ViteHubInspectionContributor {
|
|
30
|
+
definitions?: readonly ViteHubDefinitionInspector[];
|
|
31
|
+
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
32
|
+
}
|
|
33
|
+
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
34
|
+
interface ViteHubInspectionPluginMetadata {
|
|
35
|
+
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/inspect.d.ts
|
|
39
|
+
type RealtimeInspectionAuthority = "auto" | "cloudflare" | "memory" | "unsupported";
|
|
40
|
+
//#endregion
|
|
4
41
|
//#region src/vite.d.ts
|
|
5
|
-
|
|
42
|
+
/** Where a contributed definition runs. */
|
|
43
|
+
export interface RealtimeContributionContext {
|
|
44
|
+
/** The room authority of this build. Contributions only run when there is one. */
|
|
45
|
+
authority: "cloudflare" | "memory";
|
|
46
|
+
/** `.vitehub/nitro/realtime`, for generated definition files. */
|
|
47
|
+
directory: string;
|
|
48
|
+
projectRoot: string;
|
|
49
|
+
serverDirs?: string[];
|
|
50
|
+
}
|
|
51
|
+
/** Definitions and Nitro plugins that another package adds, such as Content live editing. */
|
|
52
|
+
export interface RealtimeContribution {
|
|
53
|
+
/** Generated definition files. A file in `server/realtime/` with the same name wins. */
|
|
54
|
+
definitions?: Array<Pick<DiscoveredRealtimeDefinition, "handler" | "name">>;
|
|
55
|
+
/** Nitro plugin files to install with the Realtime route. */
|
|
56
|
+
plugins?: string[];
|
|
57
|
+
}
|
|
58
|
+
export interface RealtimeVitePluginOptions extends RealtimeModuleOptions {
|
|
6
59
|
importBase?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Adds definitions owned by another package. It runs only when the build has a room authority (Cloudflare Durable
|
|
62
|
+
* Objects, or memory in development or with `authority: 'memory'`). Without one, Realtime leaves the contribution
|
|
63
|
+
* out without an error, so the contributing feature can fall back.
|
|
64
|
+
*/
|
|
65
|
+
contribute?: (context: RealtimeContributionContext) => Promise<RealtimeContribution | undefined> | RealtimeContribution | undefined;
|
|
7
66
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
67
|
+
export type RealtimeVitePlugin = Plugin & {
|
|
68
|
+
vitehub: ViteHubInspectionPluginMetadata;
|
|
69
|
+
};
|
|
70
|
+
export interface RealtimeInspectionOptions {
|
|
71
|
+
/** Resolved room authority. Defaults to `auto`. */
|
|
72
|
+
authority?: RealtimeInspectionAuthority;
|
|
73
|
+
projectRoot: string;
|
|
74
|
+
serverDirs?: string[];
|
|
75
|
+
/** Definitions other packages contributed to this build, such as Content live editing. */
|
|
76
|
+
contributed?: readonly DiscoveredRealtimeDefinition[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Lists Realtime Definitions with their document adapter, editor codec, identity, authorization,
|
|
80
|
+
* persistence, and room authority, read statically from each definition file.
|
|
81
|
+
*/
|
|
82
|
+
export declare function inspectRealtimeDefinitions(options: RealtimeInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
|
|
83
|
+
export declare function hubRealtime(options?: RealtimeVitePluginOptions): RealtimeVitePlugin;
|
|
84
|
+
//#endregion
|