loro-repo 0.6.0 → 0.8.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
@@ -4,9 +4,8 @@ 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 readonly transport?;
8
+ private transport?;
10
9
  private readonly storage?;
11
10
  private metaFlock;
12
11
  private readonly eventBus;
@@ -36,6 +35,14 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
36
35
  * @param options
37
36
  */
38
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;
39
46
  /**
40
47
  * Start syncing the metadata (Flock) room. It will establish a realtime connection to the transport adaptor.
41
48
  * All changes on the room will be synced to the Flock, and all changes on the Flock will be synced to the room.
package/dist/index.d.ts CHANGED
@@ -4,9 +4,8 @@ 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 readonly transport?;
8
+ private transport?;
10
9
  private readonly storage?;
11
10
  private metaFlock;
12
11
  private readonly eventBus;
@@ -36,6 +35,14 @@ declare class LoroRepo<Meta extends JsonObject = JsonObject> {
36
35
  * @param options
37
36
  */
38
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;
39
46
  /**
40
47
  * Start syncing the metadata (Flock) room. It will establish a realtime connection to the transport adaptor.
41
48
  * All changes on the room will be synced to the Flock, and all changes on the Flock will be synced to the room.
package/dist/index.js CHANGED
@@ -1582,6 +1582,11 @@ var SyncRunner = class {
1582
1582
  this.getMetaFlock = options.getMetaFlock;
1583
1583
  this.replaceMetaFlock = options.mergeFlock;
1584
1584
  }
1585
+ setTransport(transport) {
1586
+ if (this.transport === transport) return;
1587
+ this.leaveRooms();
1588
+ this.transport = transport;
1589
+ }
1585
1590
  async ready() {
1586
1591
  if (!this.readyPromise) this.readyPromise = this.initialize();
1587
1592
  await this.readyPromise;
@@ -1751,6 +1756,16 @@ var SyncRunner = class {
1751
1756
  get metaFlock() {
1752
1757
  return this.getMetaFlock();
1753
1758
  }
1759
+ leaveRooms() {
1760
+ if (this.metaRoomSubscription) {
1761
+ this.metaRoomSubscription.base.unsubscribe();
1762
+ this.metaRoomSubscription = void 0;
1763
+ }
1764
+ for (const record of this.docSubscriptions.values()) record.base.unsubscribe();
1765
+ this.docSubscriptions.clear();
1766
+ this.unsubscribeMetaFlock?.();
1767
+ this.unsubscribeMetaFlock = void 0;
1768
+ }
1754
1769
  };
1755
1770
 
1756
1771
  //#endregion
@@ -1913,7 +1928,6 @@ var MetaPersister = class {
1913
1928
  const DEFAULT_DOC_FRONTIER_DEBOUNCE_MS = 1e3;
1914
1929
  const DEFAULT_DELETED_DOC_KEEP_MS = 720 * 60 * 60 * 1e3;
1915
1930
  var LoroRepo = class LoroRepo {
1916
- options;
1917
1931
  _destroyed = false;
1918
1932
  transport;
1919
1933
  storage;
@@ -1930,7 +1944,6 @@ var LoroRepo = class LoroRepo {
1930
1944
  deletedDocKeepMs;
1931
1945
  purgeWatchHandle;
1932
1946
  constructor(options) {
1933
- this.options = options;
1934
1947
  this.transport = options.transportAdapter;
1935
1948
  this.storage = options.storageAdapter;
1936
1949
  this.assetTransport = options.assetTransportAdapter;
@@ -2023,6 +2036,25 @@ var LoroRepo = class LoroRepo {
2023
2036
  await this.syncRunner.sync(options);
2024
2037
  }
2025
2038
  /**
2039
+ * Sets (or replaces) the transport adapter used for syncing and realtime rooms.
2040
+ *
2041
+ * Swapping transports will leave any joined meta/doc rooms managed by the repo.
2042
+ */
2043
+ async setTransportAdapter(transport) {
2044
+ if (this._destroyed) throw new Error("Repo has been destroyed");
2045
+ if (this.transport === transport) return;
2046
+ const previous = this.transport;
2047
+ this.transport = transport;
2048
+ this.syncRunner.setTransport(transport);
2049
+ await previous?.close();
2050
+ }
2051
+ hasTransport() {
2052
+ return Boolean(this.transport);
2053
+ }
2054
+ hasStorage() {
2055
+ return Boolean(this.storage);
2056
+ }
2057
+ /**
2026
2058
  * Start syncing the metadata (Flock) room. It will establish a realtime connection to the transport adaptor.
2027
2059
  * All changes on the room will be synced to the Flock, and all changes on the Flock will be synced to the room.
2028
2060
  *