@abraca/dabra 2.90.0 → 2.91.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/package.json +5 -11
- package/src/AbracadabraBaseProvider.ts +0 -963
- package/src/AbracadabraClient.ts +0 -1960
- package/src/AbracadabraProvider.ts +0 -915
- package/src/AbracadabraWS.ts +0 -695
- package/src/BackgroundSyncManager.ts +0 -856
- package/src/BackgroundSyncPersistence.ts +0 -140
- package/src/ChatClient.ts +0 -314
- package/src/CloseEvents.ts +0 -49
- package/src/ContentManager.ts +0 -246
- package/src/CoverReconcile.ts +0 -168
- package/src/CryptoIdentityKeystore.ts +0 -754
- package/src/DeviceRegistrationService.ts +0 -257
- package/src/DocConverters.ts +0 -1859
- package/src/DocKeyManager.ts +0 -163
- package/src/DocTypes.ts +0 -628
- package/src/DocUtils.ts +0 -251
- package/src/DocumentCache.ts +0 -210
- package/src/DocumentManager.ts +0 -410
- package/src/E2EAbracadabraProvider.ts +0 -426
- package/src/E2EOfflineStore.ts +0 -55
- package/src/EncryptedChatClient.ts +0 -173
- package/src/EncryptedY.ts +0 -145
- package/src/EventEmitter.ts +0 -59
- package/src/FileBlobStore.ts +0 -569
- package/src/IdentityDoc.ts +0 -711
- package/src/IncomingMessage.ts +0 -63
- package/src/MessageReceiver.ts +0 -151
- package/src/MessageSender.ts +0 -22
- package/src/MetaManager.ts +0 -194
- package/src/MnemonicKeyDerivation.ts +0 -171
- package/src/NodeConnect.ts +0 -63
- package/src/NodeIdentity.ts +0 -378
- package/src/NotificationsClient.ts +0 -207
- package/src/OfflineStore.ts +0 -294
- package/src/OutgoingMessage.ts +0 -25
- package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
- package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
- package/src/OutgoingMessages/CloseMessage.ts +0 -17
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
- package/src/OutgoingMessages/StatelessMessage.ts +0 -18
- package/src/OutgoingMessages/SubdocMessage.ts +0 -35
- package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
- package/src/OutgoingMessages/UpdateMessage.ts +0 -20
- package/src/QueryClient.ts +0 -209
- package/src/RpcClient.ts +0 -659
- package/src/SchemaTypes.ts +0 -179
- package/src/SearchIndex.ts +0 -250
- package/src/ServerRegistry.ts +0 -220
- package/src/ServerReset.ts +0 -222
- package/src/TokenManager.ts +0 -337
- package/src/TreeManager.ts +0 -894
- package/src/TreeTimestamps.ts +0 -101
- package/src/auth.ts +0 -62
- package/src/awarenessStatesToArray.ts +0 -10
- package/src/index.ts +0 -219
- package/src/messageRecord.ts +0 -121
- package/src/sync/BroadcastChannelSync.ts +0 -235
- package/src/types.ts +0 -790
- package/src/webrtc/AbracadabraWebRTC.ts +0 -683
- package/src/webrtc/DataChannelRouter.ts +0 -179
- package/src/webrtc/DevicePairingChannel.ts +0 -496
- package/src/webrtc/E2EEChannel.ts +0 -195
- package/src/webrtc/FileTransferChannel.ts +0 -367
- package/src/webrtc/ManualSignaling.ts +0 -204
- package/src/webrtc/PeerConnection.ts +0 -133
- package/src/webrtc/SignalingSocket.ts +0 -378
- package/src/webrtc/YjsDataChannel.ts +0 -203
- package/src/webrtc/index.ts +0 -26
- package/src/webrtc/types.ts +0 -177
package/src/OfflineStore.ts
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IndexedDB-backed offline store for a single Abracadabra document.
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* - Persist CRDT updates locally so they survive page refreshes / network loss.
|
|
6
|
-
* - Store the last-known state vector for fast reconnect diffs.
|
|
7
|
-
* - Store a permission snapshot so the UI can gate writes without a network round-trip.
|
|
8
|
-
* - Queue subdoc registration events created while offline.
|
|
9
|
-
* - Store a full document snapshot so the app can load content without a server connection.
|
|
10
|
-
*
|
|
11
|
-
* Falls back to a silent no-op when IndexedDB is unavailable (e.g. SSR / Node.js).
|
|
12
|
-
*
|
|
13
|
-
* Database key is scoped by server origin to prevent cross-server data contamination
|
|
14
|
-
* when the same docId is used on multiple servers.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export interface PendingSubdoc {
|
|
18
|
-
childId: string;
|
|
19
|
-
parentId: string;
|
|
20
|
-
createdAt: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const DB_VERSION = 2;
|
|
24
|
-
|
|
25
|
-
function idbAvailable(): boolean {
|
|
26
|
-
return typeof globalThis !== "undefined" && "indexedDB" in globalThis;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function openDb(storeKey: string): Promise<IDBDatabase> {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
const req = globalThis.indexedDB.open(`abracadabra:${storeKey}`, DB_VERSION);
|
|
32
|
-
|
|
33
|
-
req.onupgradeneeded = (event) => {
|
|
34
|
-
const db = (event.target as IDBOpenDBRequest).result;
|
|
35
|
-
|
|
36
|
-
if (!db.objectStoreNames.contains("updates")) {
|
|
37
|
-
db.createObjectStore("updates", { autoIncrement: true });
|
|
38
|
-
}
|
|
39
|
-
if (!db.objectStoreNames.contains("meta")) {
|
|
40
|
-
db.createObjectStore("meta");
|
|
41
|
-
}
|
|
42
|
-
if (!db.objectStoreNames.contains("subdoc_queue")) {
|
|
43
|
-
db.createObjectStore("subdoc_queue", { keyPath: "childId" });
|
|
44
|
-
}
|
|
45
|
-
// v2: full document snapshot store
|
|
46
|
-
if (!db.objectStoreNames.contains("doc_state")) {
|
|
47
|
-
db.createObjectStore("doc_state");
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
req.onsuccess = () => resolve(req.result);
|
|
52
|
-
req.onerror = () => reject(req.error);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function txPromise<T>(
|
|
57
|
-
store: IDBObjectStore,
|
|
58
|
-
request: IDBRequest<T>,
|
|
59
|
-
): Promise<T> {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
request.onsuccess = () => resolve(request.result);
|
|
62
|
-
request.onerror = () => reject(request.error);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class OfflineStore {
|
|
67
|
-
private storeKey: string;
|
|
68
|
-
private db: IDBDatabase | null = null;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @param docId The document UUID.
|
|
72
|
-
* @param serverOrigin Host of the server, including a non-default port
|
|
73
|
-
* (e.g. "abra.cou.sh", "localhost:3001"). When provided
|
|
74
|
-
* the IndexedDB database is namespaced per-server,
|
|
75
|
-
* preventing cross-server data contamination — the port
|
|
76
|
-
* matters because two same-host servers sharing the
|
|
77
|
-
* default root_doc_id would otherwise collide.
|
|
78
|
-
*/
|
|
79
|
-
constructor(docId: string, serverOrigin?: string) {
|
|
80
|
-
this.storeKey = serverOrigin ? `${serverOrigin}/${docId}` : docId;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private dbPromise: Promise<IDBDatabase | null> | null = null;
|
|
84
|
-
|
|
85
|
-
private _destroyed = false;
|
|
86
|
-
|
|
87
|
-
private getDb(): Promise<IDBDatabase | null> {
|
|
88
|
-
if (this._destroyed || !idbAvailable()) return Promise.resolve(null);
|
|
89
|
-
if (!this.dbPromise) {
|
|
90
|
-
// Cache the promise so concurrent callers share a single open operation.
|
|
91
|
-
this.dbPromise = openDb(this.storeKey).catch(() => null).then(db => {
|
|
92
|
-
this.db = db;
|
|
93
|
-
return db;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return this.dbPromise;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ── Pending (unsynced) updates ────────────────────────────────────────────
|
|
100
|
-
|
|
101
|
-
async persistUpdate(update: Uint8Array): Promise<void> {
|
|
102
|
-
const db = await this.getDb();
|
|
103
|
-
if (!db) return;
|
|
104
|
-
const tx = db.transaction("updates", "readwrite");
|
|
105
|
-
const store = tx.objectStore("updates");
|
|
106
|
-
await txPromise(store, store.add(update));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async getPendingUpdates(): Promise<Uint8Array[]> {
|
|
110
|
-
const db = await this.getDb();
|
|
111
|
-
if (!db) return [];
|
|
112
|
-
return new Promise((resolve, reject) => {
|
|
113
|
-
const tx = db.transaction("updates", "readonly");
|
|
114
|
-
const store = tx.objectStore("updates");
|
|
115
|
-
const req = store.getAll();
|
|
116
|
-
req.onsuccess = () => resolve(req.result as Uint8Array[]);
|
|
117
|
-
req.onerror = () => reject(req.error);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async clearPendingUpdates(): Promise<void> {
|
|
122
|
-
const db = await this.getDb();
|
|
123
|
-
if (!db) return;
|
|
124
|
-
const tx = db.transaction("updates", "readwrite");
|
|
125
|
-
await txPromise(tx.objectStore("updates"), tx.objectStore("updates").clear());
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ── Full document snapshot ────────────────────────────────────────────────
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Persist a full Y.js state snapshot (Y.encodeStateAsUpdate output).
|
|
132
|
-
* Replaces any previously stored snapshot.
|
|
133
|
-
*/
|
|
134
|
-
async saveDocSnapshot(snapshot: Uint8Array): Promise<void> {
|
|
135
|
-
const db = await this.getDb();
|
|
136
|
-
if (!db) return;
|
|
137
|
-
const tx = db.transaction("doc_state", "readwrite");
|
|
138
|
-
await txPromise(
|
|
139
|
-
tx.objectStore("doc_state"),
|
|
140
|
-
tx.objectStore("doc_state").put(snapshot, "snapshot"),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Retrieve the stored full document snapshot, or null if none exists.
|
|
146
|
-
*/
|
|
147
|
-
async getDocSnapshot(): Promise<Uint8Array | null> {
|
|
148
|
-
const db = await this.getDb();
|
|
149
|
-
if (!db) return null;
|
|
150
|
-
const tx = db.transaction("doc_state", "readonly");
|
|
151
|
-
const result = await txPromise<Uint8Array | undefined>(
|
|
152
|
-
tx.objectStore("doc_state"),
|
|
153
|
-
tx.objectStore("doc_state").get("snapshot"),
|
|
154
|
-
);
|
|
155
|
-
return result ?? null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ── State vector ─────────────────────────────────────────────────────────
|
|
159
|
-
|
|
160
|
-
async getStateVector(): Promise<Uint8Array | null> {
|
|
161
|
-
const db = await this.getDb();
|
|
162
|
-
if (!db) return null;
|
|
163
|
-
const tx = db.transaction("meta", "readonly");
|
|
164
|
-
const result = await txPromise<Uint8Array | undefined>(
|
|
165
|
-
tx.objectStore("meta"),
|
|
166
|
-
tx.objectStore("meta").get("sv"),
|
|
167
|
-
);
|
|
168
|
-
return result ?? null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async saveStateVector(sv: Uint8Array): Promise<void> {
|
|
172
|
-
const db = await this.getDb();
|
|
173
|
-
if (!db) return;
|
|
174
|
-
const tx = db.transaction("meta", "readwrite");
|
|
175
|
-
await txPromise(tx.objectStore("meta"), tx.objectStore("meta").put(sv, "sv"));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ── Permission snapshot ──────────────────────────────────────────────────
|
|
179
|
-
|
|
180
|
-
async getPermissionSnapshot(): Promise<string | null> {
|
|
181
|
-
const db = await this.getDb();
|
|
182
|
-
if (!db) return null;
|
|
183
|
-
const tx = db.transaction("meta", "readonly");
|
|
184
|
-
const result = await txPromise<string | undefined>(
|
|
185
|
-
tx.objectStore("meta"),
|
|
186
|
-
tx.objectStore("meta").get("role"),
|
|
187
|
-
);
|
|
188
|
-
return result ?? null;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async savePermissionSnapshot(role: string): Promise<void> {
|
|
192
|
-
const db = await this.getDb();
|
|
193
|
-
if (!db) return;
|
|
194
|
-
const tx = db.transaction("meta", "readwrite");
|
|
195
|
-
await txPromise(
|
|
196
|
-
tx.objectStore("meta"),
|
|
197
|
-
tx.objectStore("meta").put(role, "role"),
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ── Subdoc registration queue ─────────────────────────────────────────────
|
|
202
|
-
|
|
203
|
-
async queueSubdoc(entry: PendingSubdoc): Promise<void> {
|
|
204
|
-
const db = await this.getDb();
|
|
205
|
-
if (!db) return;
|
|
206
|
-
const tx = db.transaction("subdoc_queue", "readwrite");
|
|
207
|
-
await txPromise(
|
|
208
|
-
tx.objectStore("subdoc_queue"),
|
|
209
|
-
tx.objectStore("subdoc_queue").put(entry),
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async getPendingSubdocs(): Promise<PendingSubdoc[]> {
|
|
214
|
-
const db = await this.getDb();
|
|
215
|
-
if (!db) return [];
|
|
216
|
-
return new Promise((resolve, reject) => {
|
|
217
|
-
const tx = db.transaction("subdoc_queue", "readonly");
|
|
218
|
-
const req = tx.objectStore("subdoc_queue").getAll();
|
|
219
|
-
req.onsuccess = () => resolve(req.result as PendingSubdoc[]);
|
|
220
|
-
req.onerror = () => reject(req.error);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
async removeSubdocFromQueue(childId: string): Promise<void> {
|
|
225
|
-
const db = await this.getDb();
|
|
226
|
-
if (!db) return;
|
|
227
|
-
const tx = db.transaction("subdoc_queue", "readwrite");
|
|
228
|
-
await txPromise(
|
|
229
|
-
tx.objectStore("subdoc_queue"),
|
|
230
|
-
tx.objectStore("subdoc_queue").delete(childId),
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// ── Generic meta accessors ────────────────────────────────────────────────
|
|
235
|
-
|
|
236
|
-
async getMeta(key: string): Promise<string | null> {
|
|
237
|
-
const db = await this.getDb();
|
|
238
|
-
if (!db) return null;
|
|
239
|
-
const tx = db.transaction("meta", "readonly");
|
|
240
|
-
const result = await txPromise<string | undefined>(
|
|
241
|
-
tx.objectStore("meta"),
|
|
242
|
-
tx.objectStore("meta").get(`meta:${key}`),
|
|
243
|
-
);
|
|
244
|
-
return result ?? null;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
async setMeta(key: string, value: string): Promise<void> {
|
|
248
|
-
const db = await this.getDb();
|
|
249
|
-
if (!db) return;
|
|
250
|
-
const tx = db.transaction("meta", "readwrite");
|
|
251
|
-
await txPromise(
|
|
252
|
-
tx.objectStore("meta"),
|
|
253
|
-
tx.objectStore("meta").put(value, `meta:${key}`),
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Clear all stored data (updates, snapshots, state vectors, subdoc queue).
|
|
259
|
-
* The database itself is kept but emptied.
|
|
260
|
-
*/
|
|
261
|
-
async clearAll(): Promise<void> {
|
|
262
|
-
const db = await this.getDb();
|
|
263
|
-
if (!db) return;
|
|
264
|
-
const storeNames = Array.from(db.objectStoreNames);
|
|
265
|
-
if (storeNames.length === 0) return;
|
|
266
|
-
const tx = db.transaction(storeNames, "readwrite");
|
|
267
|
-
await Promise.all(
|
|
268
|
-
storeNames.map(
|
|
269
|
-
(name) =>
|
|
270
|
-
new Promise<void>((resolve, reject) => {
|
|
271
|
-
const req = tx.objectStore(name).clear();
|
|
272
|
-
req.onsuccess = () => resolve();
|
|
273
|
-
req.onerror = () => reject(req.error);
|
|
274
|
-
}),
|
|
275
|
-
),
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
280
|
-
|
|
281
|
-
destroy() {
|
|
282
|
-
// Set the destroyed flag first so getDb() returns null for any new operations.
|
|
283
|
-
this._destroyed = true;
|
|
284
|
-
const db = this.db;
|
|
285
|
-
this.db = null;
|
|
286
|
-
this.dbPromise = null;
|
|
287
|
-
// Close the IDB connection to free the file descriptor. Deferred to the
|
|
288
|
-
// next microtask so any in-flight transaction callbacks settle first.
|
|
289
|
-
// IDB spec: close() waits for running transactions to finish before closing.
|
|
290
|
-
if (db) {
|
|
291
|
-
Promise.resolve().then(() => db.close());
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
package/src/OutgoingMessage.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Encoder } from "lib0/encoding";
|
|
2
|
-
import { createEncoder, toUint8Array } from "lib0/encoding";
|
|
3
|
-
import type {
|
|
4
|
-
MessageType,
|
|
5
|
-
OutgoingMessageArguments,
|
|
6
|
-
OutgoingMessageInterface,
|
|
7
|
-
} from "./types.ts";
|
|
8
|
-
|
|
9
|
-
export class OutgoingMessage implements OutgoingMessageInterface {
|
|
10
|
-
encoder: Encoder;
|
|
11
|
-
|
|
12
|
-
type?: MessageType;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.encoder = createEncoder();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
19
|
-
return args.encoder;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
toUint8Array() {
|
|
23
|
-
return toUint8Array(this.encoder);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
-
import { writeAuthentication } from "../auth.ts";
|
|
3
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
-
import { MessageType } from "../types.ts";
|
|
5
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
|
-
|
|
7
|
-
export class AuthenticationMessage extends OutgoingMessage {
|
|
8
|
-
type = MessageType.Auth;
|
|
9
|
-
|
|
10
|
-
description = "Authentication";
|
|
11
|
-
|
|
12
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
-
if (typeof args.token === "undefined") {
|
|
14
|
-
throw new Error("The authentication message requires `token` as an argument.");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
writeVarString(this.encoder, args.documentName!);
|
|
18
|
-
writeVarUint(this.encoder, this.type);
|
|
19
|
-
writeAuthentication(this.encoder, args.token);
|
|
20
|
-
|
|
21
|
-
return this.encoder;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import { encodeAwarenessUpdate } from "y-protocols/awareness";
|
|
3
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
-
import { MessageType } from "../types.ts";
|
|
5
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
|
-
|
|
7
|
-
export class AwarenessMessage extends OutgoingMessage {
|
|
8
|
-
type = MessageType.Awareness;
|
|
9
|
-
|
|
10
|
-
description = "Awareness states update";
|
|
11
|
-
|
|
12
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
-
if (typeof args.awareness === "undefined") {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"The awareness message requires awareness as an argument",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (typeof args.clients === "undefined") {
|
|
20
|
-
throw new Error("The awareness message requires clients as an argument");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
encoding.writeVarString(this.encoder, args.documentName!);
|
|
24
|
-
encoding.writeVarUint(this.encoder, this.type);
|
|
25
|
-
|
|
26
|
-
let awarenessUpdate;
|
|
27
|
-
if (args.states === undefined) {
|
|
28
|
-
awarenessUpdate = encodeAwarenessUpdate(args.awareness, args.clients);
|
|
29
|
-
} else {
|
|
30
|
-
awarenessUpdate = encodeAwarenessUpdate(
|
|
31
|
-
args.awareness,
|
|
32
|
-
args.clients,
|
|
33
|
-
args.states,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
encoding.writeVarUint8Array(this.encoder, awarenessUpdate);
|
|
38
|
-
|
|
39
|
-
return this.encoder;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
|
|
6
|
-
export class CloseMessage extends OutgoingMessage {
|
|
7
|
-
type = MessageType.CLOSE;
|
|
8
|
-
|
|
9
|
-
description = "Ask the server to close the connection";
|
|
10
|
-
|
|
11
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
-
encoding.writeVarString(this.encoder, args.documentName!);
|
|
13
|
-
encoding.writeVarUint(this.encoder, this.type);
|
|
14
|
-
|
|
15
|
-
return this.encoder;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
|
|
6
|
-
export class QueryAwarenessMessage extends OutgoingMessage {
|
|
7
|
-
type = MessageType.QueryAwareness;
|
|
8
|
-
|
|
9
|
-
description = "Queries awareness states";
|
|
10
|
-
|
|
11
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
-
encoding.writeVarString(this.encoder, args.documentName!);
|
|
13
|
-
encoding.writeVarUint(this.encoder, this.type);
|
|
14
|
-
|
|
15
|
-
return this.encoder;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
|
|
6
|
-
export class StatelessMessage extends OutgoingMessage {
|
|
7
|
-
type = MessageType.Stateless;
|
|
8
|
-
|
|
9
|
-
description = "A stateless message";
|
|
10
|
-
|
|
11
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
-
writeVarString(this.encoder, args.documentName!);
|
|
13
|
-
writeVarUint(this.encoder, this.type);
|
|
14
|
-
writeVarString(this.encoder, args.payload ?? "");
|
|
15
|
-
|
|
16
|
-
return this.encoder;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
-
import type { AbracadabraOutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Registers a new subdocument with the Abracadabra server.
|
|
8
|
-
*
|
|
9
|
-
* Wire format (consumed by handle_subdoc in sync.rs):
|
|
10
|
-
* [ParentDocName: VarString] [MSG_SUBDOC(4): VarUint] [childDocumentName: VarString]
|
|
11
|
-
*
|
|
12
|
-
* The server responds with a MSG_STATELESS JSON frame:
|
|
13
|
-
* { type: "subdoc_registered", child_id, parent_id }
|
|
14
|
-
* which AbracadabraProvider intercepts in receiveStateless().
|
|
15
|
-
*/
|
|
16
|
-
export class SubdocMessage extends OutgoingMessage {
|
|
17
|
-
type = MessageType.Subdoc;
|
|
18
|
-
|
|
19
|
-
description = "SubdocRegistration";
|
|
20
|
-
|
|
21
|
-
get(args: Partial<AbracadabraOutgoingMessageArguments>) {
|
|
22
|
-
if (!args.documentName) {
|
|
23
|
-
throw new Error("SubdocMessage requires `documentName` (parent id).");
|
|
24
|
-
}
|
|
25
|
-
if (!args.childDocumentName) {
|
|
26
|
-
throw new Error("SubdocMessage requires `childDocumentName`.");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
writeVarString(this.encoder, args.documentName);
|
|
30
|
-
writeVarUint(this.encoder, this.type);
|
|
31
|
-
writeVarString(this.encoder, args.childDocumentName);
|
|
32
|
-
|
|
33
|
-
return this.encoder;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import * as syncProtocol from "y-protocols/sync";
|
|
3
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
-
import { MessageType } from "../types.ts";
|
|
5
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
|
-
|
|
7
|
-
export class SyncStepOneMessage extends OutgoingMessage {
|
|
8
|
-
type = MessageType.Sync;
|
|
9
|
-
|
|
10
|
-
description = "First sync step";
|
|
11
|
-
|
|
12
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
-
if (typeof args.document === "undefined") {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"The sync step one message requires document as an argument",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
encoding.writeVarString(this.encoder, args.documentName!);
|
|
20
|
-
encoding.writeVarUint(this.encoder, this.type);
|
|
21
|
-
syncProtocol.writeSyncStep1(this.encoder, args.document);
|
|
22
|
-
|
|
23
|
-
return this.encoder;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import * as syncProtocol from "y-protocols/sync";
|
|
3
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
-
import { MessageType } from "../types.ts";
|
|
5
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
|
-
|
|
7
|
-
export class SyncStepTwoMessage extends OutgoingMessage {
|
|
8
|
-
type = MessageType.Sync;
|
|
9
|
-
|
|
10
|
-
description = "Second sync step";
|
|
11
|
-
|
|
12
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
-
if (typeof args.document === "undefined") {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"The sync step two message requires document as an argument",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
encoding.writeVarString(this.encoder, args.documentName!);
|
|
20
|
-
encoding.writeVarUint(this.encoder, this.type);
|
|
21
|
-
syncProtocol.writeSyncStep2(this.encoder, args.document);
|
|
22
|
-
|
|
23
|
-
return this.encoder;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
-
import { writeUpdate } from "y-protocols/sync";
|
|
3
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
-
import { MessageType } from "../types.ts";
|
|
5
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
|
-
|
|
7
|
-
export class UpdateMessage extends OutgoingMessage {
|
|
8
|
-
type = MessageType.Sync;
|
|
9
|
-
|
|
10
|
-
description = "A document update";
|
|
11
|
-
|
|
12
|
-
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
-
writeVarString(this.encoder, args.documentName!);
|
|
14
|
-
writeVarUint(this.encoder, this.type);
|
|
15
|
-
|
|
16
|
-
writeUpdate(this.encoder, args.update);
|
|
17
|
-
|
|
18
|
-
return this.encoder;
|
|
19
|
-
}
|
|
20
|
-
}
|