@vite-hub/realtime 0.4.1 → 0.5.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 (43) hide show
  1. package/README.md +8 -4
  2. package/dist/agent.d.ts +1 -1
  3. package/dist/agent.js +1 -2
  4. package/dist/{bus-CKv8gQZf.js → bus-DJ3dOQAZ.js} +11 -22
  5. package/dist/{bus-protocol-wXkXW28q.d.ts → bus-protocol-juNrVJDF.d.ts} +0 -2
  6. package/dist/bus.d.ts +1 -3
  7. package/dist/bus.js +1 -2
  8. package/dist/client/browser.js +3 -3
  9. package/dist/client.d.ts +2 -4
  10. package/dist/client.js +15 -9
  11. package/dist/{conflict-DYC_qXzM.js → conflict-BqdKFrkE.js} +3 -5
  12. package/dist/{conflict-CmZizTYl.d.ts → conflict-C5KRv-J1.d.ts} +0 -2
  13. package/dist/{document-BfMW1zYU.d.ts → document-CbqgNO_0.d.ts} +2 -4
  14. package/dist/document-CfrQbB03.js +1736 -0
  15. package/dist/durability.d.ts +1 -3
  16. package/dist/durability.js +1 -6
  17. package/dist/{editor-BM5-vHqf.js → editor-DzhKM4Gt.js} +2 -5
  18. package/dist/{error-diagnostics-Cd-XWNf7.js → error-diagnostics-we8V1O-X.js} +1 -2
  19. package/dist/index.d.ts +3 -7
  20. package/dist/index.js +3 -3
  21. package/dist/internal/runtime/unavailable.d.ts +1 -3
  22. package/dist/internal/runtime/unavailable.js +1 -2
  23. package/dist/internal/server.d.ts +7 -0
  24. package/dist/internal/server.js +6 -0
  25. package/dist/{keepalive-B4ONG6AD.js → keepalive-BYkk6Ax8.js} +3 -5
  26. package/dist/{layout-DNaxppTZ.js → layout-BQwRLTH0.js} +1 -2
  27. package/dist/{layout-B7i6-FnH.d.ts → layout-BZtKNqiC.d.ts} +1 -3
  28. package/dist/log-NlQi6kow.js +157 -0
  29. package/dist/{object-BgPPDLDE.js → object-DfrneieE.js} +2 -4
  30. package/dist/{presence-B6rvkHqd.js → presence-DZ21pPKm.js} +3 -4
  31. package/dist/{request-C_bQc4NE.js → request-DM6xHTaU.js} +5 -10
  32. package/dist/{request-BwaohsJS.d.ts → request-PrMHOYFK.d.ts} +1 -3
  33. package/dist/server-CLdYV7Md.d.ts +126 -0
  34. package/dist/server-yQp02XNp.js +2599 -0
  35. package/dist/server.d.ts +4 -142
  36. package/dist/server.js +3 -2588
  37. package/dist/{types-Cvm0G3VJ.d.ts → types-oUyN-CJR.d.ts} +1 -27
  38. package/dist/vite.d.ts +4 -15
  39. package/dist/vite.js +64 -63
  40. package/dist/vue.d.ts +2 -7
  41. package/dist/vue.js +47 -40
  42. package/package.json +44 -39
  43. package/dist/document-U5rzg2vG.js +0 -2041
package/dist/server.d.ts CHANGED
@@ -1,142 +1,4 @@
1
- import { R as RealtimeWorkspaceDocumentOptions, c as RealtimeDocumentContext, f as RealtimeEditor, l as RealtimeDocumentDefinition, s as RealtimeDocumentAdapter, w as RealtimeRegistry, x as RealtimePerson } from "./types-Cvm0G3VJ.js";
2
- import { i as RealtimeRoomRequestResult, n as RealtimeDurableObjectNamespace, o as requestRealtimeRoom, r as RealtimeRoomRequestOptions } from "./request-BwaohsJS.js";
3
- import { n as RealtimeBusMessage, r as RealtimeRoomRecord, t as RealtimeBus } from "./bus-protocol-wXkXW28q.js";
4
- import { n as isRealtimeDocumentConflict, t as RealtimeDocumentConflict } from "./conflict-CmZizTYl.js";
5
- import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-B7i6-FnH.js";
6
- import { i as readRealtimeYDoc, n as createRealtimeYDoc, r as diffRealtimeYDoc, t as containsRealtimeState } from "./document-BfMW1zYU.js";
7
- import * as awarenessProtocol from "y-protocols/awareness";
8
- import * as Y from "yjs";
9
- import { Diagnostic } from "nostics";
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
50
- //#region src/presence.d.ts
51
- type RealtimeIdentity = Omit<RealtimePerson, "clientId">;
52
- //#endregion
53
- //#region src/awareness.d.ts
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[];
59
- export declare function bindAwarenessIdentity(update: Uint8Array, identity: RealtimeIdentity): Uint8Array;
60
- export declare function applyRealtimeAwarenessUpdate(awareness: awarenessProtocol.Awareness, update: Uint8Array, origin: unknown, maxStateBytes?: number): void;
61
- export declare function compactRealtimeAwareness(awareness: awarenessProtocol.Awareness): awarenessProtocol.Awareness;
62
- //#endregion
63
- //#region src/transport.d.ts
64
- export declare function readRealtimeRequestState(request: Request, maxBytes?: number): Promise<Uint8Array>;
65
- //#endregion
66
- //#region src/workspace-document.d.ts
67
- interface RealtimeWorkspaceDocumentAdapter extends RealtimeDocumentAdapter {
68
- kind: "workspace";
69
- workspace: string;
70
- }
71
- export declare function readRealtimeWorkspaceDocument(readable: ReadonlyWorkspaceFiles, writable: WritableWorkspaceFiles, documentId: string): Promise<{
72
- baselineDigest: string | undefined;
73
- markdown: string;
74
- }>;
75
- /**
76
- * Stores each Realtime document as the Markdown file at its path in a Workspace working tree.
77
- * `history.checkpoint()` commits the working tree to Workspace history with the Store's author by default.
78
- * `document: { workspace }` in a Realtime Definition uses this adapter.
79
- */
80
- export declare function workspaceDocument(workspaceName: string, checkpointAuthor?: RealtimeWorkspaceDocumentOptions["checkpointAuthor"]): RealtimeWorkspaceDocumentAdapter;
81
- export declare function isRealtimeWorkspaceDocument(adapter: RealtimeDocumentAdapter): adapter is RealtimeWorkspaceDocumentAdapter;
82
- //#endregion
83
- //#region src/server.d.ts
84
- export interface RealtimeHandler {
85
- (event: unknown): Promise<unknown>;
86
- fetch(input: Request | URL | string): Promise<Response>;
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
- }
96
- export declare const realtimePersistenceDefaults: Readonly<{
97
- debounce: 2000;
98
- maxWait: 10000;
99
- }>;
100
- export declare function encodeSyncUpdate(update: Uint8Array): Uint8Array;
101
- export declare function encodeSyncStep1(document: Y.Doc): Uint8Array;
102
- export declare function encodeAwarenessState(awareness: awarenessProtocol.Awareness, clients: number[]): Uint8Array;
103
- export interface RealtimeSyncOptions {
104
- maxStateBytes?: number;
105
- /** Reject any update that changes the document. A string replaces the rejection message. */
106
- readOnly?: boolean | string;
107
- /** Reject updates that change the server-written `status` map. Default `true`. */
108
- protectStatus?: boolean;
109
- }
110
- export declare function applyRealtimeSyncMessage(data: Uint8Array, document: Y.Doc, origin: unknown, options?: RealtimeSyncOptions): Uint8Array | undefined;
111
- export declare function assertRealtimeRoomStateQuota(document: Y.Doc, maxStateBytes?: number): void;
112
- export declare function realtimeRoomKey(definitionName: string, documentId: string, scope?: string): string;
113
- export declare function restoreRealtimeDocument(markdown: string, baselineDigest: string | undefined, stored: Record<string, unknown> | undefined): Promise<Y.Doc>;
114
- interface ResolvedRealtimeDefinition {
115
- adapter: RealtimeDocumentAdapter;
116
- definition: RealtimeDocumentDefinition;
117
- /** The codec of one document: the definition's editor, or the one its editor function picks. */
118
- editor: (context: RealtimeDocumentContext) => RealtimeEditor;
119
- persistence: {
120
- debounce: number;
121
- maxWait: number;
122
- } | false;
123
- }
124
- /** Resolves the document adapter, editor codec, and persistence timing of a definition. */
125
- export declare function resolveRealtimeDefinition(definition: RealtimeDocumentDefinition): ResolvedRealtimeDefinition;
126
- export interface RealtimeRefreshOptions {
127
- /**
128
- * On Cloudflare, the `$DurableObject` binding that holds the rooms. Defaults to the binding of the running Worker.
129
- * Without one, the rooms of this process refresh.
130
- */
131
- durableObjects?: RealtimeDurableObjectNamespace;
132
- }
133
- /**
134
- * Tells the open room of a document that its stored copy changed outside the room, such as a save by an Agent or the
135
- * CLI. A room without unsaved edits re-seeds at once and resets its clients. A room with unsaved edits finds the change
136
- * at its next save, which also re-seeds it. A room that is not open loads the stored copy when it opens. Resolves
137
- * whether a room re-seeded. It never throws: a failed refresh leaves the next save to find the change.
138
- */
139
- export declare function refreshRealtimeDocument(definition: string, documentId: string, options?: RealtimeRefreshOptions): Promise<boolean>;
140
- export declare function createRealtimeHandler(registry: RealtimeRegistry, options?: RealtimeHandlerOptions): RealtimeHandler;
141
- //#endregion
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 };
1
+ import { D as blobDocument, E as RealtimeBlobStore, O as isRealtimeAvailable, T as RealtimeBlobDocumentOptions, g as RealtimeWorkspaceDocumentAdapter, n as RealtimeHandlerOptions, p as refreshRealtimeDocument, r as RealtimeRefreshOptions, s as createRealtimeHandler, t as RealtimeHandler, y as workspaceDocument } from "./server-CLdYV7Md.js";
2
+ import { i as RealtimeRoomRequestResult, n as RealtimeDurableObjectNamespace, o as requestRealtimeRoom, r as RealtimeRoomRequestOptions } from "./request-PrMHOYFK.js";
3
+ import { n as RealtimeBusMessage, r as RealtimeRoomRecord, t as RealtimeBus } from "./bus-protocol-juNrVJDF.js";
4
+ export { type RealtimeBlobDocumentOptions, type RealtimeBlobStore, type RealtimeBus, type RealtimeBusMessage, type RealtimeDurableObjectNamespace, type RealtimeHandler, type RealtimeHandlerOptions, type RealtimeRefreshOptions, type RealtimeRoomRecord, type RealtimeRoomRequestOptions, type RealtimeRoomRequestResult, type RealtimeWorkspaceDocumentAdapter, blobDocument, createRealtimeHandler, isRealtimeAvailable, refreshRealtimeDocument, requestRealtimeRoom, workspaceDocument };