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