loro-repo 0.5.3 → 0.7.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 +42 -1
- package/dist/index.cjs +511 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -6
- package/dist/index.d.ts +56 -6
- package/dist/index.js +511 -97
- package/dist/index.js.map +1 -1
- package/dist/storage/filesystem.cjs +17 -0
- package/dist/storage/filesystem.cjs.map +1 -1
- package/dist/storage/filesystem.d.cts +2 -1
- package/dist/storage/filesystem.d.ts +2 -1
- package/dist/storage/filesystem.js +17 -0
- package/dist/storage/filesystem.js.map +1 -1
- package/dist/storage/indexeddb.cjs +4 -0
- package/dist/storage/indexeddb.cjs.map +1 -1
- package/dist/storage/indexeddb.d.cts +2 -1
- package/dist/storage/indexeddb.d.ts +2 -1
- package/dist/storage/indexeddb.js +4 -0
- package/dist/storage/indexeddb.js.map +1 -1
- package/dist/transport/broadcast-channel.cjs +131 -1
- package/dist/transport/broadcast-channel.cjs.map +1 -1
- package/dist/transport/broadcast-channel.d.cts +20 -3
- package/dist/transport/broadcast-channel.d.ts +20 -3
- package/dist/transport/broadcast-channel.js +130 -1
- package/dist/transport/broadcast-channel.js.map +1 -1
- package/dist/transport/websocket.cjs +348 -24
- package/dist/transport/websocket.cjs.map +1 -1
- package/dist/transport/websocket.d.cts +47 -5
- package/dist/transport/websocket.d.ts +47 -5
- package/dist/transport/websocket.js +349 -24
- package/dist/transport/websocket.js.map +1 -1
- package/dist/types.d.cts +116 -4
- package/dist/types.d.ts +116 -4
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as TransportConnectionStatus, C as RepoEventType, D as StorageSavePayload, E as StorageAdapter, F as TransportSyncResult, I as UploadAssetOptions, M as TransportRoomStatus, N as TransportSubscription, O as SyncScope, P as TransportSyncRequest, S as RepoEventListener, T as RepoWatchHandle, _ as RepoDocSnapshot, a as AssetUploadMetadata, b as RepoEventFilter, c as GcDeletedDocOptions, d as LinkAssetOptions, f as ListDocQuery, g as RepoDocMeta, h as RepoDocHandle, i as AssetTransportAdapter, j as TransportJoinParams, k as TransportAdapter, l as JsonObject, m as RepoAssetMetadata, n as AssetDownload, o as DeleteDocOptions, p as LoroRepoOptions, r as AssetId, s as GarbageCollectionOptions, t as AssetContent, u as JsonValue, v as RepoEvent, w as RepoSyncOptions, x as RepoEventKind, y as RepoEventBy } from "./types.cjs";
|
|
2
2
|
import { Flock } from "@loro-dev/flock";
|
|
3
|
-
import { LoroDoc } from "loro-crdt";
|
|
3
|
+
import { EphemeralStore, LoroDoc } from "loro-crdt";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
7
|
-
readonly options: LoroRepoOptions;
|
|
8
7
|
private _destroyed;
|
|
9
|
-
private
|
|
8
|
+
private transport?;
|
|
10
9
|
private readonly storage?;
|
|
11
10
|
private metaFlock;
|
|
12
11
|
private readonly eventBus;
|
|
@@ -18,6 +17,8 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
18
17
|
private readonly state;
|
|
19
18
|
private readonly syncRunner;
|
|
20
19
|
private readonly metaPersister;
|
|
20
|
+
private readonly deletedDocKeepMs;
|
|
21
|
+
private readonly purgeWatchHandle;
|
|
21
22
|
private constructor();
|
|
22
23
|
static create<Meta extends JsonObject = JsonObject>(options: LoroRepoOptions): Promise<LoroRepo<Meta>>;
|
|
23
24
|
/**
|
|
@@ -27,14 +28,28 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
27
28
|
* Though we do that implicitly already
|
|
28
29
|
*/
|
|
29
30
|
private ready;
|
|
31
|
+
private computeDocPurgeAfter;
|
|
32
|
+
private purgeDocKeyspace;
|
|
30
33
|
/**
|
|
31
34
|
* Sync selected data via the transport adaptor
|
|
32
35
|
* @param options
|
|
33
36
|
*/
|
|
34
37
|
sync(options?: RepoSyncOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets (or replaces) the transport adapter used for syncing and realtime rooms.
|
|
40
|
+
*
|
|
41
|
+
* Swapping transports will leave any joined meta/doc rooms managed by the repo.
|
|
42
|
+
*/
|
|
43
|
+
setTransportAdapter(transport?: TransportAdapter): Promise<void>;
|
|
44
|
+
hasTransport(): boolean;
|
|
45
|
+
hasStorage(): boolean;
|
|
35
46
|
/**
|
|
36
47
|
* Start syncing the metadata (Flock) room. It will establish a realtime connection to the transport adaptor.
|
|
37
48
|
* All changes on the room will be synced to the Flock, and all changes on the Flock will be synced to the room.
|
|
49
|
+
*
|
|
50
|
+
* - Idempotent: repeated calls reuse the same underlying room session; no extra join request is sent for the same repo.
|
|
51
|
+
* - Reference-counted leave: every call to `joinMetaRoom` returns a subscription that increments an internal counter. The room is
|
|
52
|
+
* actually left only after all returned subscriptions have called `unsubscribe`.
|
|
38
53
|
* @param params
|
|
39
54
|
* @returns
|
|
40
55
|
*/
|
|
@@ -44,11 +59,22 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
44
59
|
* All changes on the doc will be synced to the transport, and all changes on the transport will be synced to the doc.
|
|
45
60
|
*
|
|
46
61
|
* All the changes on the room will be reflected on the same doc you get from `repo.openCollaborativeDoc(docId)`
|
|
62
|
+
*
|
|
63
|
+
* - Idempotent: multiple joins for the same `docId` reuse the existing session; no duplicate transport joins are issued.
|
|
64
|
+
* - Reference-counted leave: each returned subscription bumps an internal counter and only the final `unsubscribe()` will
|
|
65
|
+
* actually leave the room. Earlier unsubscribes simply decrement the counter.
|
|
47
66
|
* @param docId
|
|
48
67
|
* @param params
|
|
49
68
|
* @returns
|
|
50
69
|
*/
|
|
51
70
|
joinDocRoom(docId: string, params?: TransportJoinParams): Promise<TransportSubscription>;
|
|
71
|
+
/**
|
|
72
|
+
* Joins an ephemeral CRDT room. This is useful for presence-like state that should not be persisted.
|
|
73
|
+
* The returned store can be used immediately; the first sync promise resolves once the initial handshake completes.
|
|
74
|
+
*/
|
|
75
|
+
joinEphemeralRoom(roomId: string): Promise<TransportSubscription & {
|
|
76
|
+
store: EphemeralStore;
|
|
77
|
+
}>;
|
|
52
78
|
/**
|
|
53
79
|
* Opens a document that is automatically persisted to the configured storage adapter.
|
|
54
80
|
*
|
|
@@ -58,8 +84,31 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
58
84
|
*/
|
|
59
85
|
openPersistedDoc(docId: string): Promise<RepoDocHandle>;
|
|
60
86
|
upsertDocMeta(docId: string, patch: Partial<Meta>): Promise<void>;
|
|
61
|
-
getDocMeta(docId: string): Promise<Meta | undefined>;
|
|
87
|
+
getDocMeta(docId: string): Promise<RepoDocSnapshot<Meta> | undefined>;
|
|
62
88
|
listDoc(query?: ListDocQuery): Promise<RepoDocMeta<Meta>[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Mark a document deleted by writing a `ts/*` tombstone entry (timestamp).
|
|
91
|
+
* The body and metadata remain until purged; callers use the tombstone to
|
|
92
|
+
* render deleted state or trigger retention workflows. For immediate removal,
|
|
93
|
+
* call `purgeDoc` instead.
|
|
94
|
+
*/
|
|
95
|
+
deleteDoc(docId: string, options?: DeleteDocOptions): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Undo a soft delete by removing the tombstone entry. Metadata and document
|
|
98
|
+
* state remain untouched.
|
|
99
|
+
*/
|
|
100
|
+
restoreDoc(docId: string): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Hard-delete a document immediately. Removes doc snapshots/updates via the
|
|
103
|
+
* storage adapter (if supported), clears metadata/frontiers/link keys from
|
|
104
|
+
* Flock, and unlinks assets (they become orphaned for asset GC).
|
|
105
|
+
*/
|
|
106
|
+
purgeDoc(docId: string): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Sweep tombstoned documents whose retention window expired. Uses
|
|
109
|
+
* `deletedDocKeepMs` by default; pass `minKeepMs`/`now` for overrides.
|
|
110
|
+
*/
|
|
111
|
+
gcDeletedDocs(options?: GcDeletedDocOptions): Promise<number>;
|
|
63
112
|
getMeta(): Flock;
|
|
64
113
|
watch(listener: RepoEventListener<Meta>, filter?: RepoEventFilter<Meta>): RepoWatchHandle;
|
|
65
114
|
/**
|
|
@@ -88,7 +137,8 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
88
137
|
gcAssets(options?: GarbageCollectionOptions): Promise<number>;
|
|
89
138
|
get destroyed(): boolean;
|
|
90
139
|
destroy(): Promise<void>;
|
|
140
|
+
private handlePurgeSignals;
|
|
91
141
|
}
|
|
92
142
|
//#endregion
|
|
93
|
-
export { AssetContent, AssetDownload, AssetId, AssetTransportAdapter, AssetUploadMetadata, GarbageCollectionOptions, JsonObject, JsonValue, LinkAssetOptions, ListDocQuery, LoroRepo, LoroRepoOptions, RepoAssetMetadata, RepoDocHandle, RepoDocMeta, RepoEvent, RepoEventBy, RepoEventFilter, RepoEventKind, RepoEventListener, RepoEventType, RepoSyncOptions, RepoWatchHandle, StorageAdapter, StorageSavePayload, SyncScope, TransportAdapter, TransportJoinParams, TransportSubscription, TransportSyncRequest, TransportSyncResult, UploadAssetOptions };
|
|
143
|
+
export { AssetContent, AssetDownload, AssetId, AssetTransportAdapter, AssetUploadMetadata, DeleteDocOptions, GarbageCollectionOptions, GcDeletedDocOptions, JsonObject, JsonValue, LinkAssetOptions, ListDocQuery, LoroRepo, LoroRepoOptions, RepoAssetMetadata, RepoDocHandle, RepoDocMeta, RepoDocSnapshot, RepoEvent, RepoEventBy, RepoEventFilter, RepoEventKind, RepoEventListener, RepoEventType, RepoSyncOptions, RepoWatchHandle, StorageAdapter, StorageSavePayload, SyncScope, TransportAdapter, TransportConnectionStatus, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncRequest, TransportSyncResult, UploadAssetOptions };
|
|
94
144
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as TransportConnectionStatus, C as RepoEventType, D as StorageSavePayload, E as StorageAdapter, F as TransportSyncResult, I as UploadAssetOptions, M as TransportRoomStatus, N as TransportSubscription, O as SyncScope, P as TransportSyncRequest, S as RepoEventListener, T as RepoWatchHandle, _ as RepoDocSnapshot, a as AssetUploadMetadata, b as RepoEventFilter, c as GcDeletedDocOptions, d as LinkAssetOptions, f as ListDocQuery, g as RepoDocMeta, h as RepoDocHandle, i as AssetTransportAdapter, j as TransportJoinParams, k as TransportAdapter, l as JsonObject, m as RepoAssetMetadata, n as AssetDownload, o as DeleteDocOptions, p as LoroRepoOptions, r as AssetId, s as GarbageCollectionOptions, t as AssetContent, u as JsonValue, v as RepoEvent, w as RepoSyncOptions, x as RepoEventKind, y as RepoEventBy } from "./types.js";
|
|
2
2
|
import { Flock } from "@loro-dev/flock";
|
|
3
|
-
import { LoroDoc } from "loro-crdt";
|
|
3
|
+
import { EphemeralStore, LoroDoc } from "loro-crdt";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
7
|
-
readonly options: LoroRepoOptions;
|
|
8
7
|
private _destroyed;
|
|
9
|
-
private
|
|
8
|
+
private transport?;
|
|
10
9
|
private readonly storage?;
|
|
11
10
|
private metaFlock;
|
|
12
11
|
private readonly eventBus;
|
|
@@ -18,6 +17,8 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
18
17
|
private readonly state;
|
|
19
18
|
private readonly syncRunner;
|
|
20
19
|
private readonly metaPersister;
|
|
20
|
+
private readonly deletedDocKeepMs;
|
|
21
|
+
private readonly purgeWatchHandle;
|
|
21
22
|
private constructor();
|
|
22
23
|
static create<Meta extends JsonObject = JsonObject>(options: LoroRepoOptions): Promise<LoroRepo<Meta>>;
|
|
23
24
|
/**
|
|
@@ -27,14 +28,28 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
27
28
|
* Though we do that implicitly already
|
|
28
29
|
*/
|
|
29
30
|
private ready;
|
|
31
|
+
private computeDocPurgeAfter;
|
|
32
|
+
private purgeDocKeyspace;
|
|
30
33
|
/**
|
|
31
34
|
* Sync selected data via the transport adaptor
|
|
32
35
|
* @param options
|
|
33
36
|
*/
|
|
34
37
|
sync(options?: RepoSyncOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets (or replaces) the transport adapter used for syncing and realtime rooms.
|
|
40
|
+
*
|
|
41
|
+
* Swapping transports will leave any joined meta/doc rooms managed by the repo.
|
|
42
|
+
*/
|
|
43
|
+
setTransportAdapter(transport?: TransportAdapter): Promise<void>;
|
|
44
|
+
hasTransport(): boolean;
|
|
45
|
+
hasStorage(): boolean;
|
|
35
46
|
/**
|
|
36
47
|
* Start syncing the metadata (Flock) room. It will establish a realtime connection to the transport adaptor.
|
|
37
48
|
* All changes on the room will be synced to the Flock, and all changes on the Flock will be synced to the room.
|
|
49
|
+
*
|
|
50
|
+
* - Idempotent: repeated calls reuse the same underlying room session; no extra join request is sent for the same repo.
|
|
51
|
+
* - Reference-counted leave: every call to `joinMetaRoom` returns a subscription that increments an internal counter. The room is
|
|
52
|
+
* actually left only after all returned subscriptions have called `unsubscribe`.
|
|
38
53
|
* @param params
|
|
39
54
|
* @returns
|
|
40
55
|
*/
|
|
@@ -44,11 +59,22 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
44
59
|
* All changes on the doc will be synced to the transport, and all changes on the transport will be synced to the doc.
|
|
45
60
|
*
|
|
46
61
|
* All the changes on the room will be reflected on the same doc you get from `repo.openCollaborativeDoc(docId)`
|
|
62
|
+
*
|
|
63
|
+
* - Idempotent: multiple joins for the same `docId` reuse the existing session; no duplicate transport joins are issued.
|
|
64
|
+
* - Reference-counted leave: each returned subscription bumps an internal counter and only the final `unsubscribe()` will
|
|
65
|
+
* actually leave the room. Earlier unsubscribes simply decrement the counter.
|
|
47
66
|
* @param docId
|
|
48
67
|
* @param params
|
|
49
68
|
* @returns
|
|
50
69
|
*/
|
|
51
70
|
joinDocRoom(docId: string, params?: TransportJoinParams): Promise<TransportSubscription>;
|
|
71
|
+
/**
|
|
72
|
+
* Joins an ephemeral CRDT room. This is useful for presence-like state that should not be persisted.
|
|
73
|
+
* The returned store can be used immediately; the first sync promise resolves once the initial handshake completes.
|
|
74
|
+
*/
|
|
75
|
+
joinEphemeralRoom(roomId: string): Promise<TransportSubscription & {
|
|
76
|
+
store: EphemeralStore;
|
|
77
|
+
}>;
|
|
52
78
|
/**
|
|
53
79
|
* Opens a document that is automatically persisted to the configured storage adapter.
|
|
54
80
|
*
|
|
@@ -58,8 +84,31 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
58
84
|
*/
|
|
59
85
|
openPersistedDoc(docId: string): Promise<RepoDocHandle>;
|
|
60
86
|
upsertDocMeta(docId: string, patch: Partial<Meta>): Promise<void>;
|
|
61
|
-
getDocMeta(docId: string): Promise<Meta | undefined>;
|
|
87
|
+
getDocMeta(docId: string): Promise<RepoDocSnapshot<Meta> | undefined>;
|
|
62
88
|
listDoc(query?: ListDocQuery): Promise<RepoDocMeta<Meta>[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Mark a document deleted by writing a `ts/*` tombstone entry (timestamp).
|
|
91
|
+
* The body and metadata remain until purged; callers use the tombstone to
|
|
92
|
+
* render deleted state or trigger retention workflows. For immediate removal,
|
|
93
|
+
* call `purgeDoc` instead.
|
|
94
|
+
*/
|
|
95
|
+
deleteDoc(docId: string, options?: DeleteDocOptions): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Undo a soft delete by removing the tombstone entry. Metadata and document
|
|
98
|
+
* state remain untouched.
|
|
99
|
+
*/
|
|
100
|
+
restoreDoc(docId: string): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Hard-delete a document immediately. Removes doc snapshots/updates via the
|
|
103
|
+
* storage adapter (if supported), clears metadata/frontiers/link keys from
|
|
104
|
+
* Flock, and unlinks assets (they become orphaned for asset GC).
|
|
105
|
+
*/
|
|
106
|
+
purgeDoc(docId: string): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Sweep tombstoned documents whose retention window expired. Uses
|
|
109
|
+
* `deletedDocKeepMs` by default; pass `minKeepMs`/`now` for overrides.
|
|
110
|
+
*/
|
|
111
|
+
gcDeletedDocs(options?: GcDeletedDocOptions): Promise<number>;
|
|
63
112
|
getMeta(): Flock;
|
|
64
113
|
watch(listener: RepoEventListener<Meta>, filter?: RepoEventFilter<Meta>): RepoWatchHandle;
|
|
65
114
|
/**
|
|
@@ -88,7 +137,8 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
|
|
|
88
137
|
gcAssets(options?: GarbageCollectionOptions): Promise<number>;
|
|
89
138
|
get destroyed(): boolean;
|
|
90
139
|
destroy(): Promise<void>;
|
|
140
|
+
private handlePurgeSignals;
|
|
91
141
|
}
|
|
92
142
|
//#endregion
|
|
93
|
-
export { AssetContent, AssetDownload, AssetId, AssetTransportAdapter, AssetUploadMetadata, GarbageCollectionOptions, JsonObject, JsonValue, LinkAssetOptions, ListDocQuery, LoroRepo, LoroRepoOptions, RepoAssetMetadata, RepoDocHandle, RepoDocMeta, RepoEvent, RepoEventBy, RepoEventFilter, RepoEventKind, RepoEventListener, RepoEventType, RepoSyncOptions, RepoWatchHandle, StorageAdapter, StorageSavePayload, SyncScope, TransportAdapter, TransportJoinParams, TransportSubscription, TransportSyncRequest, TransportSyncResult, UploadAssetOptions };
|
|
143
|
+
export { AssetContent, AssetDownload, AssetId, AssetTransportAdapter, AssetUploadMetadata, DeleteDocOptions, GarbageCollectionOptions, GcDeletedDocOptions, JsonObject, JsonValue, LinkAssetOptions, ListDocQuery, LoroRepo, LoroRepoOptions, RepoAssetMetadata, RepoDocHandle, RepoDocMeta, RepoDocSnapshot, RepoEvent, RepoEventBy, RepoEventFilter, RepoEventKind, RepoEventListener, RepoEventType, RepoSyncOptions, RepoWatchHandle, StorageAdapter, StorageSavePayload, SyncScope, TransportAdapter, TransportConnectionStatus, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncRequest, TransportSyncResult, UploadAssetOptions };
|
|
94
144
|
//# sourceMappingURL=index.d.ts.map
|