loro-repo 0.0.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 +132 -0
- package/dist/index.cjs +2173 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +670 -0
- package/dist/index.d.ts +670 -0
- package/dist/index.js +2170 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
import { Flock } from "@loro-dev/flock";
|
|
2
|
+
import { Frontiers, LoroDoc } from "loro-crdt";
|
|
3
|
+
import { JoinError, JoinResponseOk, RoomId, UpdateError } from "loro-protocol";
|
|
4
|
+
import { LoroWebsocketClientOptions } from "loro-websocket";
|
|
5
|
+
import { FlockAdaptorConfig } from "loro-adaptors";
|
|
6
|
+
|
|
7
|
+
//#region src/types.d.ts
|
|
8
|
+
type GlobalBlob = typeof globalThis extends {
|
|
9
|
+
Blob: infer B;
|
|
10
|
+
} ? B : {
|
|
11
|
+
readonly size: number;
|
|
12
|
+
readonly type: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Binary content accepted by asset ingestion helpers.
|
|
16
|
+
*/
|
|
17
|
+
type AssetContent = GlobalBlob | ArrayBufferView | ReadableStream<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* JSON-compatible leaf value used for document metadata.
|
|
20
|
+
*/
|
|
21
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
22
|
+
[key: string]: JsonValue;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* JSON-compatible object map used throughout metadata APIs.
|
|
26
|
+
*/
|
|
27
|
+
type JsonObject = {
|
|
28
|
+
[key: string]: JsonValue;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Synchronisation lanes available to repo consumers.
|
|
32
|
+
*/
|
|
33
|
+
type SyncScope = "meta" | "doc" | "full";
|
|
34
|
+
/**
|
|
35
|
+
* Construction options for creating a `LoroRepo` instance.
|
|
36
|
+
*/
|
|
37
|
+
interface LoroRepoOptions<_Meta extends JsonObject = JsonObject> {
|
|
38
|
+
/**
|
|
39
|
+
* Transport adapter responsible for fetching and pushing CRDT bundles.
|
|
40
|
+
* Omit when operating fully offline or within pure tests.
|
|
41
|
+
*/
|
|
42
|
+
readonly transportAdapter?: TransportAdapter;
|
|
43
|
+
/**
|
|
44
|
+
* Storage adapter that hydrates snapshots and persists incremental updates.
|
|
45
|
+
*/
|
|
46
|
+
readonly storageAdapter?: StorageAdapter;
|
|
47
|
+
/**
|
|
48
|
+
* Optional adapter that moves asset payloads while keeping metadata in sync.
|
|
49
|
+
*/
|
|
50
|
+
readonly assetTransportAdapter?: AssetTransportAdapter;
|
|
51
|
+
/**
|
|
52
|
+
* Factory invoked when a document handle needs to be materialised.
|
|
53
|
+
*/
|
|
54
|
+
readonly docFactory?: (docId: string) => Promise<LoroDoc>;
|
|
55
|
+
/**
|
|
56
|
+
* Debounce duration in milliseconds before persisting document frontier metadata
|
|
57
|
+
* after local edits. Defaults to 1000 ms when omitted.
|
|
58
|
+
*/
|
|
59
|
+
readonly docFrontierDebounceMs?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parameters accepted by `LoroRepo.sync`.
|
|
63
|
+
*/
|
|
64
|
+
interface RepoSyncOptions {
|
|
65
|
+
/**
|
|
66
|
+
* Defines the lanes to sync: metadata only, document bodies, or both.
|
|
67
|
+
*/
|
|
68
|
+
readonly scope?: SyncScope;
|
|
69
|
+
/**
|
|
70
|
+
* Explicit allow-list of document ids for partial synchronisation.
|
|
71
|
+
*/
|
|
72
|
+
readonly docIds?: ReadonlyArray<string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parameters passed to transport adapters when issuing a sync request.
|
|
76
|
+
*/
|
|
77
|
+
interface TransportSyncRequest {
|
|
78
|
+
/**
|
|
79
|
+
* Synchronisation scope (metadata-only, document bodies, or both).
|
|
80
|
+
*/
|
|
81
|
+
readonly scope: SyncScope;
|
|
82
|
+
/**
|
|
83
|
+
* Optional document allow-list when syncing specific bodies.
|
|
84
|
+
*/
|
|
85
|
+
readonly docIds?: ReadonlyArray<string>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Result returned by transport adapters after fetching updates.
|
|
89
|
+
*/
|
|
90
|
+
interface TransportSyncResult {
|
|
91
|
+
readonly ok: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parameters used when joining live collaboration rooms.
|
|
95
|
+
*/
|
|
96
|
+
interface TransportJoinParams {
|
|
97
|
+
readonly roomId?: RoomId;
|
|
98
|
+
readonly auth?: Uint8Array;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Subscription handle returned by transport adapters after joining a room.
|
|
102
|
+
*/
|
|
103
|
+
interface TransportSubscription {
|
|
104
|
+
readonly unsubscribe: () => void;
|
|
105
|
+
readonly firstSyncedWithRemote: Promise<void>;
|
|
106
|
+
readonly connected: boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Abstracts the transport channel that exchanges metadata and document bundles.
|
|
110
|
+
*/
|
|
111
|
+
interface TransportAdapter {
|
|
112
|
+
/**
|
|
113
|
+
* Establishes connectivity; If failed, the adapter should throw an error.
|
|
114
|
+
*/
|
|
115
|
+
connect(options?: {
|
|
116
|
+
timeout?: number;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Tears down network resources and stops background polling.
|
|
120
|
+
*/
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Indicates whether the adapter currently has an active transport connection.
|
|
124
|
+
*/
|
|
125
|
+
isConnected(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Pulls metadata updates and merges them into the supplied Flock replica. If the sync fails, the adapter should throw an error.
|
|
128
|
+
*/
|
|
129
|
+
syncMeta(flock: Flock, options?: {
|
|
130
|
+
timeout?: number;
|
|
131
|
+
}): Promise<TransportSyncResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Joins the metadata room and returns an unsubscribe function for realtime updates.
|
|
134
|
+
*/
|
|
135
|
+
joinMetaRoom(flock: Flock, params?: TransportJoinParams): TransportSubscription;
|
|
136
|
+
/**
|
|
137
|
+
* Pulls document body updates and merges them into the provided LoroDoc.
|
|
138
|
+
*/
|
|
139
|
+
syncDoc(docId: string, loroDoc: LoroDoc, options?: {
|
|
140
|
+
timeout?: number;
|
|
141
|
+
}): Promise<TransportSyncResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Subscribes to live document updates, returning a cleanup handle.
|
|
144
|
+
*/
|
|
145
|
+
joinDocRoom(docId: string, loroDoc: LoroDoc, params?: TransportJoinParams): TransportSubscription;
|
|
146
|
+
/**
|
|
147
|
+
* Optional callback invoked upon successful join responses.
|
|
148
|
+
*/
|
|
149
|
+
handleJoinResponse?(response: JoinResponseOk): void;
|
|
150
|
+
/**
|
|
151
|
+
* Optional callback surfaced when joining a room fails.
|
|
152
|
+
*/
|
|
153
|
+
handleJoinError?(error: JoinError): void;
|
|
154
|
+
/**
|
|
155
|
+
* Optional callback for update-level failures (e.g., decoding errors).
|
|
156
|
+
*/
|
|
157
|
+
handleUpdateError?(error: UpdateError): void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Persists metadata, documents, and asset payloads on behalf of the repo.
|
|
161
|
+
*/
|
|
162
|
+
interface StorageAdapter {
|
|
163
|
+
/**
|
|
164
|
+
* Writes document snapshots, queued updates, assets, or meta bundles to durable storage.
|
|
165
|
+
*/
|
|
166
|
+
save(payload: StorageSavePayload): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Optionally deletes an asset payload during garbage collection.
|
|
169
|
+
*/
|
|
170
|
+
deleteAsset?(assetId: AssetId): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Loads a stored document by hydrating the persisted snapshot and replaying any queued updates.
|
|
173
|
+
*/
|
|
174
|
+
loadDoc(docId: string): Promise<LoroDoc | undefined>;
|
|
175
|
+
/**
|
|
176
|
+
* Loads the repository-level metadata replica, if present.
|
|
177
|
+
*/
|
|
178
|
+
loadMeta(): Promise<Flock | undefined>;
|
|
179
|
+
/**
|
|
180
|
+
* Loads a cached asset payload, if present.
|
|
181
|
+
*/
|
|
182
|
+
loadAsset(assetId: AssetId): Promise<Uint8Array | undefined>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Union describing the kinds of payloads persisted via the storage adapter.
|
|
186
|
+
*/
|
|
187
|
+
type StorageSavePayload = {
|
|
188
|
+
readonly type: "doc-snapshot";
|
|
189
|
+
readonly docId: string;
|
|
190
|
+
readonly snapshot: Uint8Array;
|
|
191
|
+
} | {
|
|
192
|
+
readonly type: "doc-update";
|
|
193
|
+
readonly docId: string;
|
|
194
|
+
readonly update: Uint8Array;
|
|
195
|
+
} | {
|
|
196
|
+
readonly type: "asset";
|
|
197
|
+
readonly assetId: AssetId;
|
|
198
|
+
readonly data: Uint8Array;
|
|
199
|
+
} | {
|
|
200
|
+
readonly type: "meta";
|
|
201
|
+
readonly update: Uint8Array;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Envelope supplied to asset uploads via the transport adapter.
|
|
205
|
+
*/
|
|
206
|
+
interface AssetUploadMetadata {
|
|
207
|
+
readonly mime?: string;
|
|
208
|
+
readonly policy?: string;
|
|
209
|
+
readonly tag?: string;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Moves binary assets between peers or infrastructure-specific storage.
|
|
213
|
+
*/
|
|
214
|
+
interface AssetTransportAdapter {
|
|
215
|
+
/**
|
|
216
|
+
* Uploads a raw asset payload using transport-managed metadata.
|
|
217
|
+
*/
|
|
218
|
+
upload(assetId: AssetId, data: Uint8Array, metadata: AssetUploadMetadata): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Fetches a remote asset payload, returning metadata and a lazy content stream.
|
|
221
|
+
*/
|
|
222
|
+
fetch(assetId: AssetId): Promise<AssetDownload | undefined>;
|
|
223
|
+
/**
|
|
224
|
+
* Optional optimisation that ensures the remote asset exists or is reachable.
|
|
225
|
+
*/
|
|
226
|
+
ensure?(assetId: AssetId): Promise<boolean>;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Unique identifier for an asset managed by the repo. Set to the SHA-256 digest of the payload.
|
|
230
|
+
*/
|
|
231
|
+
type AssetId = string;
|
|
232
|
+
/**
|
|
233
|
+
* Asset reference augmented with a lazy content accessor.
|
|
234
|
+
*/
|
|
235
|
+
interface AssetDownload {
|
|
236
|
+
readonly assetId: AssetId;
|
|
237
|
+
readonly mime?: string;
|
|
238
|
+
readonly policy?: string;
|
|
239
|
+
readonly tag?: string;
|
|
240
|
+
readonly size: number;
|
|
241
|
+
readonly createdAt: number;
|
|
242
|
+
/**
|
|
243
|
+
* Lazily resolves to a readable stream, used to hydrate local caches.
|
|
244
|
+
*/
|
|
245
|
+
readonly content: () => Promise<ReadableStream<Uint8Array>>;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Options supplied when linking an asset to a document.
|
|
249
|
+
*/
|
|
250
|
+
interface LinkAssetOptions extends AssetUploadMetadata {
|
|
251
|
+
/**
|
|
252
|
+
* Optional pre-existing asset id. Must match the SHA-256 digest of the content when provided.
|
|
253
|
+
*/
|
|
254
|
+
readonly assetId?: AssetId;
|
|
255
|
+
/**
|
|
256
|
+
* Optional creation timestamp carried into metadata.
|
|
257
|
+
*/
|
|
258
|
+
readonly createdAt?: number;
|
|
259
|
+
/**
|
|
260
|
+
* Raw payload provided by the caller.
|
|
261
|
+
*/
|
|
262
|
+
readonly content: AssetContent;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Options accepted by `uploadAsset`.
|
|
266
|
+
*/
|
|
267
|
+
interface UploadAssetOptions extends AssetUploadMetadata {
|
|
268
|
+
/**
|
|
269
|
+
* Optional pre-assigned asset identifier. Must match the SHA-256 digest of the content when provided.
|
|
270
|
+
*/
|
|
271
|
+
readonly assetId?: AssetId;
|
|
272
|
+
/**
|
|
273
|
+
* Optional timestamp preserved in the stored metadata.
|
|
274
|
+
*/
|
|
275
|
+
readonly createdAt?: number;
|
|
276
|
+
/**
|
|
277
|
+
* Raw payload that will be persisted locally and optionally uploaded.
|
|
278
|
+
*/
|
|
279
|
+
readonly content: AssetContent;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Options accepted by `gcAssets`.
|
|
283
|
+
*/
|
|
284
|
+
interface GarbageCollectionOptions {
|
|
285
|
+
/**
|
|
286
|
+
* Minimum duration in milliseconds to keep unreferenced assets before purging.
|
|
287
|
+
*/
|
|
288
|
+
readonly minKeepMs?: number;
|
|
289
|
+
/**
|
|
290
|
+
* Optional batch size for deleting cached assets.
|
|
291
|
+
*/
|
|
292
|
+
readonly batchSize?: number;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Metadata entry returned by `listDoc`.
|
|
296
|
+
*/
|
|
297
|
+
interface RepoDocMeta<Meta extends JsonObject = JsonObject> {
|
|
298
|
+
/**
|
|
299
|
+
* Globally unique identifier for the document (e.g. `note:<uuid>`).
|
|
300
|
+
*/
|
|
301
|
+
readonly docId: string;
|
|
302
|
+
/**
|
|
303
|
+
* Merged metadata snapshot respecting the `Meta` contract.
|
|
304
|
+
*/
|
|
305
|
+
readonly meta: Meta;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Range-scan parameters for `listDoc`.
|
|
309
|
+
*/
|
|
310
|
+
interface ListDocQuery {
|
|
311
|
+
/**
|
|
312
|
+
* Optional partition-style prefix to scan within the metadata keyspace.
|
|
313
|
+
*/
|
|
314
|
+
readonly prefix?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Inclusive range start for ordered metadata iteration.
|
|
317
|
+
*/
|
|
318
|
+
readonly start?: string;
|
|
319
|
+
/**
|
|
320
|
+
* Exclusive range end for ordered metadata iteration.
|
|
321
|
+
*/
|
|
322
|
+
readonly end?: string;
|
|
323
|
+
/**
|
|
324
|
+
* Maximum number of documents to materialise per call.
|
|
325
|
+
*/
|
|
326
|
+
readonly limit?: number;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Handle returned by `openCollaborativeDoc` (shared/persistent) or `openDetachedDoc` (isolated snapshot).
|
|
330
|
+
*/
|
|
331
|
+
interface RepoDocHandle {
|
|
332
|
+
/**
|
|
333
|
+
* Shared collaborative document handle sourced from `loro-crdt`.
|
|
334
|
+
*/
|
|
335
|
+
readonly doc: LoroDoc;
|
|
336
|
+
/**
|
|
337
|
+
* Resolves once storage hydration and any queued remote updates complete.
|
|
338
|
+
*/
|
|
339
|
+
readonly whenSyncedWithRemote: Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Unsubscribes listeners and releases resources associated with the document.
|
|
342
|
+
*/
|
|
343
|
+
close(): Promise<void>;
|
|
344
|
+
}
|
|
345
|
+
interface UpsertDocMetaOptions {}
|
|
346
|
+
/**
|
|
347
|
+
* Provenance discriminant attached to every repo event.
|
|
348
|
+
*/
|
|
349
|
+
type RepoEventBy = "local" | "sync" | "live";
|
|
350
|
+
/**
|
|
351
|
+
* Unified event envelope emitted by `watch`.
|
|
352
|
+
*/
|
|
353
|
+
type RepoEvent<Meta extends JsonObject = JsonObject> = {
|
|
354
|
+
readonly kind: "doc-metadata";
|
|
355
|
+
readonly docId: string;
|
|
356
|
+
readonly patch: Partial<Meta>;
|
|
357
|
+
readonly by: RepoEventBy;
|
|
358
|
+
} | {
|
|
359
|
+
readonly kind: "doc-frontiers";
|
|
360
|
+
readonly docId: string;
|
|
361
|
+
readonly frontiers: Frontiers;
|
|
362
|
+
readonly by: RepoEventBy;
|
|
363
|
+
} | {
|
|
364
|
+
readonly kind: "asset-metadata";
|
|
365
|
+
readonly asset: AssetDownload;
|
|
366
|
+
readonly by: RepoEventBy;
|
|
367
|
+
} | {
|
|
368
|
+
readonly kind: "asset-link";
|
|
369
|
+
readonly docId: string;
|
|
370
|
+
readonly assetId: AssetId;
|
|
371
|
+
readonly by: RepoEventBy;
|
|
372
|
+
} | {
|
|
373
|
+
readonly kind: "asset-unlink";
|
|
374
|
+
readonly docId: string;
|
|
375
|
+
readonly assetId: AssetId;
|
|
376
|
+
readonly by: RepoEventBy;
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Listener signature for `watch`.
|
|
380
|
+
*/
|
|
381
|
+
type RepoEventListener<Meta extends JsonObject = JsonObject> = (event: RepoEvent<Meta>) => void;
|
|
382
|
+
/**
|
|
383
|
+
* Handle returned by `watch`, allowing subscribers to unsubscribe.
|
|
384
|
+
*/
|
|
385
|
+
interface RepoWatchHandle {
|
|
386
|
+
/**
|
|
387
|
+
* Stops receiving further repo events.
|
|
388
|
+
*/
|
|
389
|
+
unsubscribe(): void;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Server-side filter applied before emitting repo events.
|
|
393
|
+
*/
|
|
394
|
+
interface RepoEventFilter<Meta extends JsonObject = JsonObject> {
|
|
395
|
+
/**
|
|
396
|
+
* Restrict events to the supplied set of document identifiers.
|
|
397
|
+
*/
|
|
398
|
+
readonly docIds?: ReadonlyArray<string>;
|
|
399
|
+
/**
|
|
400
|
+
* Restrict events by kind (doc metadata/frontiers, asset lifecycle).
|
|
401
|
+
*/
|
|
402
|
+
readonly kinds?: ReadonlyArray<RepoEvent<Meta>["kind"]>;
|
|
403
|
+
/**
|
|
404
|
+
* Emit metadata events only when the specified fields change.
|
|
405
|
+
*/
|
|
406
|
+
readonly metadataFields?: ReadonlyArray<string>;
|
|
407
|
+
/**
|
|
408
|
+
* Restrict events by their provenance (local edits, explicit sync, or live collaboration).
|
|
409
|
+
*/
|
|
410
|
+
readonly by?: ReadonlyArray<RepoEventBy>;
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/loro-adaptor.d.ts
|
|
414
|
+
type RepoFlockAdaptorConfig = FlockAdaptorConfig;
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/transport/websocket.d.ts
|
|
417
|
+
interface WebSocketTransportOptions {
|
|
418
|
+
/**
|
|
419
|
+
* WebSocket endpoint provided to the loro-websocket client.
|
|
420
|
+
*/
|
|
421
|
+
readonly url: string;
|
|
422
|
+
/**
|
|
423
|
+
* Optional loro-websocket client configuration.
|
|
424
|
+
*/
|
|
425
|
+
readonly client?: Omit<LoroWebsocketClientOptions, "url">;
|
|
426
|
+
/**
|
|
427
|
+
* Metadata room identifier. When omitted, metadata synchronisation is disabled.
|
|
428
|
+
*/
|
|
429
|
+
readonly metadataRoomId?: string;
|
|
430
|
+
/**
|
|
431
|
+
* Overrides the CRDT type advertised for the metadata room (defaults to `%FLO`).
|
|
432
|
+
* Only `%FLO` is supported.
|
|
433
|
+
*/
|
|
434
|
+
readonly metadataCrdtType?: string;
|
|
435
|
+
/**
|
|
436
|
+
* Optional adaptor configuration for metadata joins.
|
|
437
|
+
*/
|
|
438
|
+
readonly metadataAdaptorConfig?: RepoFlockAdaptorConfig;
|
|
439
|
+
/**
|
|
440
|
+
* Static auth payload for metadata joins.
|
|
441
|
+
*/
|
|
442
|
+
readonly metadataAuth?: Uint8Array;
|
|
443
|
+
/**
|
|
444
|
+
* Factory that maps document ids to room identifiers. Defaults to the doc id.
|
|
445
|
+
*/
|
|
446
|
+
readonly docRoomId?: (docId: string) => string;
|
|
447
|
+
/**
|
|
448
|
+
* Optional auth provider for document joins.
|
|
449
|
+
*/
|
|
450
|
+
readonly docAuth?: (docId: string) => Uint8Array | undefined;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* loro-websocket backed {@link TransportAdapter} implementation for LoroRepo.
|
|
454
|
+
*/
|
|
455
|
+
declare class WebSocketTransportAdapter implements TransportAdapter {
|
|
456
|
+
private readonly options;
|
|
457
|
+
private client?;
|
|
458
|
+
private metadataSession?;
|
|
459
|
+
private readonly docSessions;
|
|
460
|
+
constructor(options: WebSocketTransportOptions);
|
|
461
|
+
connect(_options?: {
|
|
462
|
+
timeout?: number;
|
|
463
|
+
}): Promise<void>;
|
|
464
|
+
close(): Promise<void>;
|
|
465
|
+
isConnected(): boolean;
|
|
466
|
+
syncMeta(flock: Flock, options?: {
|
|
467
|
+
timeout?: number;
|
|
468
|
+
}): Promise<TransportSyncResult>;
|
|
469
|
+
joinMetaRoom(flock: Flock, params?: TransportJoinParams): TransportSubscription;
|
|
470
|
+
syncDoc(docId: string, doc: LoroDoc, options?: {
|
|
471
|
+
timeout?: number;
|
|
472
|
+
}): Promise<TransportSyncResult>;
|
|
473
|
+
joinDocRoom(docId: string, doc: LoroDoc, params?: TransportJoinParams): TransportSubscription;
|
|
474
|
+
private ensureClient;
|
|
475
|
+
private ensureMetadataSession;
|
|
476
|
+
private teardownMetadataSession;
|
|
477
|
+
private ensureDocSession;
|
|
478
|
+
private leaveDocSession;
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/transport/broadcast-channel.d.ts
|
|
482
|
+
interface BroadcastChannelTransportOptions {
|
|
483
|
+
/**
|
|
484
|
+
* Namespace used to derive broadcast channel names. Defaults to `loro-repo`.
|
|
485
|
+
*/
|
|
486
|
+
readonly namespace?: string;
|
|
487
|
+
/**
|
|
488
|
+
* Explicit channel name for metadata broadcasts. When omitted, resolves to `${namespace}-meta`.
|
|
489
|
+
*/
|
|
490
|
+
readonly metaChannelName?: string;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* TransportAdapter that relies on the BroadcastChannel API to fan out metadata
|
|
494
|
+
* and document updates between browser tabs within the same origin.
|
|
495
|
+
*/
|
|
496
|
+
declare class BroadcastChannelTransportAdapter implements TransportAdapter {
|
|
497
|
+
private readonly instanceId;
|
|
498
|
+
private readonly namespace;
|
|
499
|
+
private readonly metaChannelName;
|
|
500
|
+
private connected;
|
|
501
|
+
private metaState?;
|
|
502
|
+
private readonly docStates;
|
|
503
|
+
constructor(options?: BroadcastChannelTransportOptions);
|
|
504
|
+
connect(): Promise<void>;
|
|
505
|
+
close(): Promise<void>;
|
|
506
|
+
isConnected(): boolean;
|
|
507
|
+
syncMeta(flock: Flock, _options?: {
|
|
508
|
+
timeout?: number;
|
|
509
|
+
}): Promise<TransportSyncResult>;
|
|
510
|
+
joinMetaRoom(flock: Flock, _params?: TransportJoinParams): TransportSubscription;
|
|
511
|
+
syncDoc(docId: string, doc: LoroDoc, _options?: {
|
|
512
|
+
timeout?: number;
|
|
513
|
+
}): Promise<TransportSyncResult>;
|
|
514
|
+
joinDocRoom(docId: string, doc: LoroDoc, _params?: TransportJoinParams): TransportSubscription;
|
|
515
|
+
private ensureMetaChannel;
|
|
516
|
+
private ensureDocChannel;
|
|
517
|
+
private teardownDocChannel;
|
|
518
|
+
}
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/storage/indexeddb.d.ts
|
|
521
|
+
interface IndexedDBStorageAdaptorOptions {
|
|
522
|
+
readonly dbName?: string;
|
|
523
|
+
readonly version?: number;
|
|
524
|
+
readonly docStoreName?: string;
|
|
525
|
+
readonly docUpdateStoreName?: string;
|
|
526
|
+
readonly metaStoreName?: string;
|
|
527
|
+
readonly assetStoreName?: string;
|
|
528
|
+
readonly metaKey?: string;
|
|
529
|
+
}
|
|
530
|
+
declare class IndexedDBStorageAdaptor implements StorageAdapter {
|
|
531
|
+
private readonly idb;
|
|
532
|
+
private readonly dbName;
|
|
533
|
+
private readonly version;
|
|
534
|
+
private readonly docStore;
|
|
535
|
+
private readonly docUpdateStore;
|
|
536
|
+
private readonly metaStore;
|
|
537
|
+
private readonly assetStore;
|
|
538
|
+
private readonly metaKey;
|
|
539
|
+
private dbPromise?;
|
|
540
|
+
private closed;
|
|
541
|
+
constructor(options?: IndexedDBStorageAdaptorOptions);
|
|
542
|
+
save(payload: StorageSavePayload): Promise<void>;
|
|
543
|
+
deleteAsset(assetId: AssetId): Promise<void>;
|
|
544
|
+
loadDoc(docId: string): Promise<LoroDoc | undefined>;
|
|
545
|
+
loadMeta(): Promise<Flock | undefined>;
|
|
546
|
+
loadAsset(assetId: AssetId): Promise<Uint8Array | undefined>;
|
|
547
|
+
close(): Promise<void>;
|
|
548
|
+
private ensureDb;
|
|
549
|
+
private ensureStore;
|
|
550
|
+
private storeExists;
|
|
551
|
+
private storeMergedSnapshot;
|
|
552
|
+
private mergeSnapshots;
|
|
553
|
+
private appendDocUpdate;
|
|
554
|
+
private getDocUpdates;
|
|
555
|
+
private clearDocUpdates;
|
|
556
|
+
private writeSnapshot;
|
|
557
|
+
private getBinaryFromDb;
|
|
558
|
+
private normalizeUpdateQueue;
|
|
559
|
+
private putBinary;
|
|
560
|
+
private deleteKey;
|
|
561
|
+
private getBinary;
|
|
562
|
+
private runInTransaction;
|
|
563
|
+
private wrapRequest;
|
|
564
|
+
private normalizeBinary;
|
|
565
|
+
private createError;
|
|
566
|
+
}
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region src/index.d.ts
|
|
569
|
+
interface RepoAssetMetadata {
|
|
570
|
+
readonly assetId: AssetId;
|
|
571
|
+
readonly size: number;
|
|
572
|
+
readonly createdAt: number;
|
|
573
|
+
readonly mime?: string;
|
|
574
|
+
readonly policy?: string;
|
|
575
|
+
readonly tag?: string;
|
|
576
|
+
}
|
|
577
|
+
declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
578
|
+
readonly options: LoroRepoOptions<Meta>;
|
|
579
|
+
private readonly transport?;
|
|
580
|
+
private readonly storage?;
|
|
581
|
+
private readonly assetTransport?;
|
|
582
|
+
private readonly docFactory;
|
|
583
|
+
private metaFlock;
|
|
584
|
+
private readonly metadata;
|
|
585
|
+
private readonly docs;
|
|
586
|
+
private readonly docRefs;
|
|
587
|
+
private readonly docSubscriptions;
|
|
588
|
+
private readonly docAssets;
|
|
589
|
+
private readonly assets;
|
|
590
|
+
private readonly orphanedAssets;
|
|
591
|
+
private readonly assetToDocRefs;
|
|
592
|
+
private readonly docFrontierKeys;
|
|
593
|
+
private readonly docFrontierUpdates;
|
|
594
|
+
private readonly docPersistedVersions;
|
|
595
|
+
private readonly docFrontierDebounceMs;
|
|
596
|
+
private readonly watchers;
|
|
597
|
+
private readonly eventByStack;
|
|
598
|
+
private metaRoomSubscription?;
|
|
599
|
+
private unsubscribeMetaFlock?;
|
|
600
|
+
private readyPromise?;
|
|
601
|
+
constructor(options: LoroRepoOptions<Meta>);
|
|
602
|
+
ready(): Promise<void>;
|
|
603
|
+
private initialize;
|
|
604
|
+
sync(options?: RepoSyncOptions): Promise<void>;
|
|
605
|
+
private refreshDocMetadataEntry;
|
|
606
|
+
private refreshDocAssetsEntry;
|
|
607
|
+
private refreshAssetMetadataEntry;
|
|
608
|
+
private refreshDocFrontierKeys;
|
|
609
|
+
private readDocMetadataFromFlock;
|
|
610
|
+
private readDocAssetsFromFlock;
|
|
611
|
+
private readAssetMetadataFromFlock;
|
|
612
|
+
private handleAssetRemoval;
|
|
613
|
+
private emit;
|
|
614
|
+
joinMetaRoom(params?: TransportJoinParams): Promise<TransportSubscription>;
|
|
615
|
+
joinDocRoom(docId: string, params?: TransportJoinParams): Promise<TransportSubscription>;
|
|
616
|
+
close(): Promise<void>;
|
|
617
|
+
upsertDocMeta(docId: string, patch: Partial<Meta>, _options?: UpsertDocMetaOptions): Promise<void>;
|
|
618
|
+
getDocMeta(docId: string): Promise<Meta | undefined>;
|
|
619
|
+
listDoc(query?: ListDocQuery): Promise<RepoDocMeta<Meta>[]>;
|
|
620
|
+
getMetaReplica(): Flock;
|
|
621
|
+
watch(listener: RepoEventListener<Meta>, filter?: RepoEventFilter<Meta>): RepoWatchHandle;
|
|
622
|
+
/**
|
|
623
|
+
* Opens the repo-managed collaborative document, registers it for persistence,
|
|
624
|
+
* and schedules a doc-level sync so `whenSyncedWithRemote` resolves after remote backfills.
|
|
625
|
+
*/
|
|
626
|
+
openCollaborativeDoc(docId: string): Promise<RepoDocHandle>;
|
|
627
|
+
/**
|
|
628
|
+
* Opens a detached `LoroDoc` snapshot that never registers with the repo, meaning
|
|
629
|
+
* it neither participates in remote subscriptions nor persists edits back to storage.
|
|
630
|
+
*/
|
|
631
|
+
openDetachedDoc(docId: string): Promise<RepoDocHandle>;
|
|
632
|
+
uploadAsset(params: UploadAssetOptions): Promise<AssetId>;
|
|
633
|
+
whenDocInSyncWithRemote(docId: string): Promise<void>;
|
|
634
|
+
linkAsset(docId: string, params: LinkAssetOptions): Promise<AssetId>;
|
|
635
|
+
fetchAsset(assetId: AssetId): Promise<AssetDownload>;
|
|
636
|
+
unlinkAsset(docId: string, assetId: AssetId): Promise<void>;
|
|
637
|
+
listAssets(docId: string): Promise<RepoAssetMetadata[]>;
|
|
638
|
+
ensureAsset(assetId: AssetId): Promise<AssetDownload>;
|
|
639
|
+
private createAssetDownload;
|
|
640
|
+
private materializeAsset;
|
|
641
|
+
private updateDocAssetMetadata;
|
|
642
|
+
gcAssets(options?: GarbageCollectionOptions): Promise<number>;
|
|
643
|
+
private onDocHandleClose;
|
|
644
|
+
private ensureDoc;
|
|
645
|
+
private materializeDetachedDoc;
|
|
646
|
+
private exportDocSnapshot;
|
|
647
|
+
private persistMeta;
|
|
648
|
+
private persistDoc;
|
|
649
|
+
private persistDocUpdate;
|
|
650
|
+
private pushEventBy;
|
|
651
|
+
private popEventBy;
|
|
652
|
+
private resolveEventBy;
|
|
653
|
+
private ensureMetaLiveMonitor;
|
|
654
|
+
private applyMetaFlockEvents;
|
|
655
|
+
private registerDoc;
|
|
656
|
+
private ensureDocSubscription;
|
|
657
|
+
private rememberAsset;
|
|
658
|
+
private scheduleDocFrontierUpdate;
|
|
659
|
+
private mergeRepoEventBy;
|
|
660
|
+
private runScheduledDocFrontierUpdate;
|
|
661
|
+
private flushScheduledDocFrontierUpdate;
|
|
662
|
+
private onDocEvent;
|
|
663
|
+
private getAssetMetadata;
|
|
664
|
+
private updateDocFrontiers;
|
|
665
|
+
private hydrateMetadataFromFlock;
|
|
666
|
+
private shouldNotify;
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
669
|
+
export { AssetContent, AssetDownload, AssetId, AssetTransportAdapter, AssetUploadMetadata, BroadcastChannelTransportAdapter, type BroadcastChannelTransportOptions, GarbageCollectionOptions, IndexedDBStorageAdaptor, type IndexedDBStorageAdaptorOptions, JsonObject, JsonValue, LinkAssetOptions, ListDocQuery, LoroRepo, LoroRepoOptions, RepoAssetMetadata, RepoDocHandle, RepoDocMeta, RepoEvent, RepoEventBy, RepoEventFilter, RepoEventListener, type RepoSyncOptions, RepoWatchHandle, StorageAdapter, StorageSavePayload, SyncScope, TransportAdapter, type TransportJoinParams, type TransportSubscription, TransportSyncRequest, type TransportSyncResult, UploadAssetOptions, UpsertDocMetaOptions, WebSocketTransportAdapter, WebSocketTransportOptions };
|
|
670
|
+
//# sourceMappingURL=index.d.cts.map
|