@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
package/dist/server.d.ts
CHANGED
|
@@ -1,16 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as RealtimeDocumentContext, f as RealtimeEditor, l as RealtimeDocumentDefinition, s as RealtimeDocumentAdapter, w as RealtimeRegistry, x as RealtimePerson } from "./types-1DVVG5ro.js";
|
|
2
|
+
import { i as RealtimeRoomRequestResult, n as RealtimeDurableObjectNamespace, o as requestRealtimeRoom, r as RealtimeRoomRequestOptions } from "./request-BUwa359H.js";
|
|
3
|
+
import { n as RealtimeBusMessage, r as RealtimeRoomRecord, t as RealtimeBus } from "./bus-protocol-wXkXW28q.js";
|
|
2
4
|
import { n as isRealtimeDocumentConflict, t as RealtimeDocumentConflict } from "./conflict-CmZizTYl.js";
|
|
3
|
-
import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-
|
|
4
|
-
import { i as readRealtimeYDoc, n as createRealtimeYDoc, r as diffRealtimeYDoc, t as containsRealtimeState } from "./document-
|
|
5
|
+
import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-fyQnhwCg.js";
|
|
6
|
+
import { i as readRealtimeYDoc, n as createRealtimeYDoc, r as diffRealtimeYDoc, t as containsRealtimeState } from "./document-DPaywuCO.js";
|
|
5
7
|
import * as awarenessProtocol from "y-protocols/awareness";
|
|
6
8
|
import * as Y from "yjs";
|
|
7
9
|
import { Diagnostic } from "nostics";
|
|
8
|
-
import {
|
|
10
|
+
import { ReadonlyWorkspaceFiles, WritableWorkspaceFiles } from "@vite-hub/workspace/files";
|
|
11
|
+
//#region src/availability.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Returns `true` when this build has a Realtime room driver: Durable Objects on Cloudflare, a Node server, or memory
|
|
14
|
+
* on the dev server. Without one, no room opens and `refreshRealtimeDocument()` resolves `false`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isRealtimeAvailable(): boolean;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/blob-document.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* The part of a ViteHub Blob store that `blobDocument()` uses, such as `blob` from `vite-hub/blob`. `put()` writes only
|
|
21
|
+
* when its `ifMatch` or `overwrite: false` condition holds, and otherwise returns a `BLOB_CONFLICT` error.
|
|
22
|
+
*/
|
|
23
|
+
interface RealtimeBlobStore {
|
|
24
|
+
get(pathname: string): Promise<[error: unknown, value: Blob | null | undefined]>;
|
|
25
|
+
head(pathname: string): Promise<[error: unknown, value: {
|
|
26
|
+
httpEtag: string | undefined;
|
|
27
|
+
} | null | undefined]>;
|
|
28
|
+
put(pathname: string, body: string, options: {
|
|
29
|
+
contentType: string;
|
|
30
|
+
ifMatch: string;
|
|
31
|
+
} | {
|
|
32
|
+
contentType: string;
|
|
33
|
+
overwrite: false;
|
|
34
|
+
}): Promise<[error: unknown, value: unknown]>;
|
|
35
|
+
}
|
|
36
|
+
interface RealtimeBlobDocumentOptions {
|
|
37
|
+
/** Defaults to `text/markdown; charset=utf-8`. */
|
|
38
|
+
contentType?: string;
|
|
39
|
+
/** Prepended to the document id to make the Blob pathname. Defaults to none. */
|
|
40
|
+
prefix?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Stores each Realtime document as one Blob file at `prefix + documentId`. Its digest is the SHA-256 of the
|
|
44
|
+
* body. `save()` reads the stored file and throws `RealtimeDocumentConflict` when its digest is not `ifDigest`. It
|
|
45
|
+
* writes only if the file still has the ETag that it read, so a writer outside the room that writes between that read
|
|
46
|
+
* and the save's write also makes the save throw `RealtimeDocumentConflict`, and keeps its file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function blobDocument(store: RealtimeBlobStore, options?: RealtimeBlobDocumentOptions): RealtimeDocumentAdapter;
|
|
49
|
+
//#endregion
|
|
9
50
|
//#region src/presence.d.ts
|
|
10
51
|
type RealtimeIdentity = Omit<RealtimePerson, "clientId">;
|
|
11
52
|
//#endregion
|
|
12
53
|
//#region src/awareness.d.ts
|
|
13
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Records that `peer` owns `clients`. A client that another peer owns is a conflict, unless `transferable` accepts its
|
|
56
|
+
* owner, such as another server instance that the client left.
|
|
57
|
+
*/
|
|
58
|
+
export declare function claimAwarenessClientIds<Peer extends object>(owners: Map<number, Peer>, peer: Peer, clients: number[], transferable?: (owner: Peer) => boolean): number[];
|
|
14
59
|
export declare function bindAwarenessIdentity(update: Uint8Array, identity: RealtimeIdentity): Uint8Array;
|
|
15
60
|
export declare function applyRealtimeAwarenessUpdate(awareness: awarenessProtocol.Awareness, update: Uint8Array, origin: unknown, maxStateBytes?: number): void;
|
|
16
61
|
export declare function compactRealtimeAwareness(awareness: awarenessProtocol.Awareness): awarenessProtocol.Awareness;
|
|
@@ -23,7 +68,7 @@ interface RealtimeWorkspaceDocumentAdapter extends RealtimeDocumentAdapter {
|
|
|
23
68
|
kind: "workspace";
|
|
24
69
|
workspace: string;
|
|
25
70
|
}
|
|
26
|
-
export declare function readRealtimeWorkspaceDocument(readable:
|
|
71
|
+
export declare function readRealtimeWorkspaceDocument(readable: ReadonlyWorkspaceFiles, writable: WritableWorkspaceFiles, documentId: string): Promise<{
|
|
27
72
|
baselineDigest: string | undefined;
|
|
28
73
|
markdown: string;
|
|
29
74
|
}>;
|
|
@@ -40,6 +85,14 @@ export interface RealtimeHandler {
|
|
|
40
85
|
(event: unknown): Promise<unknown>;
|
|
41
86
|
fetch(input: Request | URL | string): Promise<Response>;
|
|
42
87
|
}
|
|
88
|
+
export interface RealtimeHandlerOptions {
|
|
89
|
+
/**
|
|
90
|
+
* Shares the rooms of this server with other instances. ViteHub passes `useRealtimeBus()` from
|
|
91
|
+
* `@vite-hub/realtime/bus` in Node builds. It runs once, when the first room opens. `undefined` keeps the rooms in
|
|
92
|
+
* this process.
|
|
93
|
+
*/
|
|
94
|
+
bus?: () => Promise<RealtimeBus | undefined> | RealtimeBus | undefined;
|
|
95
|
+
}
|
|
43
96
|
export declare const realtimePersistenceDefaults: Readonly<{
|
|
44
97
|
debounce: 2000;
|
|
45
98
|
maxWait: 10000;
|
|
@@ -47,10 +100,6 @@ export declare const realtimePersistenceDefaults: Readonly<{
|
|
|
47
100
|
export declare function encodeSyncUpdate(update: Uint8Array): Uint8Array;
|
|
48
101
|
export declare function encodeSyncStep1(document: Y.Doc): Uint8Array;
|
|
49
102
|
export declare function encodeAwarenessState(awareness: awarenessProtocol.Awareness, clients: number[]): Uint8Array;
|
|
50
|
-
/** A peer tried to write what it may not: a read-only connection, or the server-written status map. */
|
|
51
|
-
export declare class RealtimeWriteRejected extends Error {
|
|
52
|
-
constructor(message: string);
|
|
53
|
-
}
|
|
54
103
|
export interface RealtimeSyncOptions {
|
|
55
104
|
maxStateBytes?: number;
|
|
56
105
|
/** Reject any update that changes the document. A string replaces the rejection message. */
|
|
@@ -60,11 +109,11 @@ export interface RealtimeSyncOptions {
|
|
|
60
109
|
}
|
|
61
110
|
export declare function applyRealtimeSyncMessage(data: Uint8Array, document: Y.Doc, origin: unknown, options?: RealtimeSyncOptions): Uint8Array | undefined;
|
|
62
111
|
export declare function assertRealtimeRoomStateQuota(document: Y.Doc, maxStateBytes?: number): void;
|
|
63
|
-
export declare function realtimeRoomKey(definitionName: string, documentId: string): string;
|
|
112
|
+
export declare function realtimeRoomKey(definitionName: string, documentId: string, scope?: string): string;
|
|
64
113
|
export declare function restoreRealtimeDocument(markdown: string, baselineDigest: string | undefined, stored: Record<string, unknown> | undefined): Promise<Y.Doc>;
|
|
65
114
|
interface ResolvedRealtimeDefinition {
|
|
66
115
|
adapter: RealtimeDocumentAdapter;
|
|
67
|
-
definition:
|
|
116
|
+
definition: RealtimeDocumentDefinition;
|
|
68
117
|
/** The codec of one document: the definition's editor, or the one its editor function picks. */
|
|
69
118
|
editor: (context: RealtimeDocumentContext) => RealtimeEditor;
|
|
70
119
|
persistence: {
|
|
@@ -73,14 +122,7 @@ interface ResolvedRealtimeDefinition {
|
|
|
73
122
|
} | false;
|
|
74
123
|
}
|
|
75
124
|
/** Resolves the document adapter, editor codec, and persistence timing of a definition. */
|
|
76
|
-
export declare function resolveRealtimeDefinition(definition:
|
|
77
|
-
/** The `$DurableObject` namespace binding that holds Realtime rooms on Cloudflare. */
|
|
78
|
-
export interface RealtimeDurableObjectNamespace {
|
|
79
|
-
get(id: unknown): {
|
|
80
|
-
fetch(request: Request): Promise<Response>;
|
|
81
|
-
};
|
|
82
|
-
idFromName(name: string): unknown;
|
|
83
|
-
}
|
|
125
|
+
export declare function resolveRealtimeDefinition(definition: RealtimeDocumentDefinition): ResolvedRealtimeDefinition;
|
|
84
126
|
export interface RealtimeRefreshOptions {
|
|
85
127
|
/**
|
|
86
128
|
* On Cloudflare, the `$DurableObject` binding that holds the rooms. Defaults to the binding of the running Worker.
|
|
@@ -95,12 +137,6 @@ export interface RealtimeRefreshOptions {
|
|
|
95
137
|
* whether a room re-seeded. It never throws: a failed refresh leaves the next save to find the change.
|
|
96
138
|
*/
|
|
97
139
|
export declare function refreshRealtimeDocument(definition: string, documentId: string, options?: RealtimeRefreshOptions): Promise<boolean>;
|
|
98
|
-
|
|
99
|
-
* Remembers the Durable Object of this isolate, for the sockets that Nitro 2 upgrades in it: its upgrade hook gets only
|
|
100
|
-
* the request, and the rooms keep their tables in the Durable Object's storage. Realtime's Nitro plugin calls it at
|
|
101
|
-
* `cloudflare:durable:init`.
|
|
102
|
-
*/
|
|
103
|
-
export declare function registerRealtimeDurableObject(state: unknown, env: unknown): void;
|
|
104
|
-
export declare function createRealtimeHandler(registry: RealtimeRegistry): RealtimeHandler;
|
|
140
|
+
export declare function createRealtimeHandler(registry: RealtimeRegistry, options?: RealtimeHandlerOptions): RealtimeHandler;
|
|
105
141
|
//#endregion
|
|
106
|
-
export { RealtimeDocumentConflict, type RealtimeWorkspaceDocumentAdapter, containsRealtimeState, createRealtimeYDoc, diffRealtimeYDoc, isRealtimeDocumentConflict, readRealtimeStatus, readRealtimeYDoc, realtimeDocumentLayout };
|
|
142
|
+
export { type RealtimeBlobDocumentOptions, type RealtimeBlobStore, type RealtimeBus, type RealtimeBusMessage, RealtimeDocumentConflict, type RealtimeDurableObjectNamespace, type RealtimeRoomRecord, type RealtimeRoomRequestOptions, type RealtimeRoomRequestResult, type RealtimeWorkspaceDocumentAdapter, containsRealtimeState, createRealtimeYDoc, diffRealtimeYDoc, isRealtimeDocumentConflict, readRealtimeStatus, readRealtimeYDoc, realtimeDocumentLayout, requestRealtimeRoom };
|