@liveblocks/core 1.4.8 → 1.5.0-subdoc

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.mts CHANGED
@@ -240,6 +240,7 @@ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
240
240
  */
241
241
  update(patch: Partial<O>): void;
242
242
  toImmutable(): ToImmutable<O>;
243
+ clone(): LiveObject<O>;
243
244
  }
244
245
 
245
246
  /**
@@ -333,6 +334,7 @@ declare class LiveMap<TKey extends string, TValue extends Lson> extends Abstract
333
334
  */
334
335
  forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
335
336
  toImmutable(): ReadonlyMap<TKey, ToImmutable<TValue>>;
337
+ clone(): LiveMap<TKey, TValue>;
336
338
  }
337
339
 
338
340
  declare type StorageCallback = (updates: StorageUpdate[]) => void;
@@ -352,24 +354,29 @@ declare abstract class AbstractCrdt {
352
354
  * Return an immutable snapshot of this Live node and its children.
353
355
  */
354
356
  toImmutable(): Immutable;
357
+ /**
358
+ * Returns a deep clone of the current LiveStructure, suitable for insertion
359
+ * in the tree elsewhere.
360
+ */
361
+ abstract clone(): Lson;
355
362
  }
356
363
 
357
364
  declare type LiveListUpdateDelta = {
365
+ type: "insert";
358
366
  index: number;
359
367
  item: Lson;
360
- type: "insert";
361
368
  } | {
362
- index: number;
363
369
  type: "delete";
370
+ index: number;
364
371
  } | {
372
+ type: "move";
365
373
  index: number;
366
374
  previousIndex: number;
367
375
  item: Lson;
368
- type: "move";
369
376
  } | {
377
+ type: "set";
370
378
  index: number;
371
379
  item: Lson;
372
- type: "set";
373
380
  };
374
381
  /**
375
382
  * A LiveList notification that is sent in-client to any subscribers whenever
@@ -480,6 +487,7 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
480
487
  some(predicate: (value: TItem, index: number) => unknown): boolean;
481
488
  [Symbol.iterator](): IterableIterator<TItem>;
482
489
  toImmutable(): readonly ToImmutable<TItem>[];
490
+ clone(): LiveList<TItem>;
483
491
  }
484
492
 
485
493
  /**
@@ -488,6 +496,7 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
488
496
  declare class LiveRegister<TValue extends Json> extends AbstractCrdt {
489
497
  constructor(data: TValue);
490
498
  get data(): TValue;
499
+ clone(): TValue;
491
500
  }
492
501
 
493
502
  declare type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson>;
@@ -723,7 +732,7 @@ declare type ThreadData<TThreadMetadata extends BaseMetadata = never> = {
723
732
  };
724
733
 
725
734
  declare type Options = {
726
- serverEndpoint: string;
735
+ baseUrl: string;
727
736
  };
728
737
  declare type PartialNullable<T> = {
729
738
  [P in keyof T]?: T[P] | null | undefined;
@@ -765,7 +774,7 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
765
774
  emoji: string;
766
775
  }): Promise<CommentData>;
767
776
  };
768
- declare function createCommentsApi<TThreadMetadata extends BaseMetadata>(roomId: string, getAuthValue: () => Promise<AuthValue>, { serverEndpoint }: Options): CommentsApi<TThreadMetadata>;
777
+ declare function createCommentsApi<TThreadMetadata extends BaseMetadata>(roomId: string, getAuthValue: () => Promise<AuthValue>, config: Options): CommentsApi<TThreadMetadata>;
769
778
 
770
779
  declare type Callback<T> = (event: T) => void;
771
780
  declare type UnsubscribeCallback = () => void;
@@ -944,6 +953,7 @@ declare type BaseAuthResult = NonNullable<Json>;
944
953
  declare type Delegates<T extends BaseAuthResult> = {
945
954
  authenticate: () => Promise<T>;
946
955
  createSocket: (authValue: T) => IWebSocketInstance;
956
+ canZombie: () => boolean;
947
957
  };
948
958
 
949
959
  declare enum ClientMsgCode {
@@ -998,10 +1008,12 @@ declare type FetchStorageClientMsg = {
998
1008
  declare type FetchYDocClientMsg = {
999
1009
  readonly type: ClientMsgCode.FETCH_YDOC;
1000
1010
  readonly vector: string;
1011
+ readonly guid?: string;
1001
1012
  };
1002
1013
  declare type UpdateYDocClientMsg = {
1003
1014
  readonly type: ClientMsgCode.UPDATE_YDOC;
1004
1015
  readonly update: string;
1016
+ readonly guid?: string;
1005
1017
  };
1006
1018
 
1007
1019
  declare type IdTuple<T> = [id: string, value: T];
@@ -1193,6 +1205,7 @@ declare type YDocUpdateServerMsg = {
1193
1205
  readonly update: string;
1194
1206
  readonly isSync: boolean;
1195
1207
  readonly stateVector: string | null;
1208
+ readonly guid?: string;
1196
1209
  };
1197
1210
  /**
1198
1211
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -1312,7 +1325,7 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
1312
1325
  * @deprecated Use `readonly User<TPresence, TUserMeta>[]` instead of `Others<TPresence, TUserMeta>`.
1313
1326
  */
1314
1327
  declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = readonly User<TPresence, TUserMeta>[];
1315
- declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1328
+ declare type InternalOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1316
1329
  type: "leave";
1317
1330
  user: User<TPresence, TUserMeta>;
1318
1331
  } | {
@@ -1325,7 +1338,24 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
1325
1338
  } | {
1326
1339
  type: "reset";
1327
1340
  };
1341
+ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = Resolve<InternalOthersEvent<TPresence, TUserMeta> & {
1342
+ others: readonly User<TPresence, TUserMeta>[];
1343
+ }>;
1328
1344
 
1345
+ declare type LegacyOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1346
+ type: "leave";
1347
+ user: User<TPresence, TUserMeta>;
1348
+ } | {
1349
+ type: "enter";
1350
+ user: User<TPresence, TUserMeta>;
1351
+ } | {
1352
+ type: "update";
1353
+ user: User<TPresence, TUserMeta>;
1354
+ updates: Partial<TPresence>;
1355
+ } | {
1356
+ type: "reset";
1357
+ };
1358
+ declare type LegacyOthersEventCallback<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = (others: readonly User<TPresence, TUserMeta>[], event: LegacyOthersEvent<TPresence, TUserMeta>) => void;
1329
1359
  declare type RoomEventMessage<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
1330
1360
  /**
1331
1361
  * The connection ID of the client that sent the event.
@@ -1458,7 +1488,7 @@ declare type SubscribeFn<TPresence extends JsonObject, _TStorage extends LsonObj
1458
1488
  * });
1459
1489
  *
1460
1490
  */
1461
- (type: "others", listener: (others: readonly User<TPresence, TUserMeta>[], event: OthersEvent<TPresence, TUserMeta>) => void): () => void;
1491
+ (type: "others", listener: LegacyOthersEventCallback<TPresence, TUserMeta>): () => void;
1462
1492
  /**
1463
1493
  * Subscribe to events broadcasted by {@link Room.broadcastEvent}
1464
1494
  *
@@ -1668,11 +1698,11 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1668
1698
  *
1669
1699
  * @param {string} data the doc update to send to the server, base64 encoded uint8array
1670
1700
  */
1671
- updateYDoc(data: string): void;
1701
+ updateYDoc(data: string, guid?: string): void;
1672
1702
  /**
1673
1703
  * Sends a request for the current document from liveblocks server
1674
1704
  */
1675
- fetchYDoc(stateVector: string): void;
1705
+ fetchYDoc(stateVector: string, guid?: string): void;
1676
1706
  /**
1677
1707
  * Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
1678
1708
  * @param {any} event the event to broadcast. Should be serializable to JSON
@@ -1708,17 +1738,12 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1708
1738
  */
1709
1739
  getStorageSnapshot(): LiveObject<TStorage> | null;
1710
1740
  readonly events: {
1711
- /** @deprecated Prefer `status` instead. */
1712
- readonly connection: Observable<LegacyConnectionStatus>;
1713
1741
  readonly status: Observable<Status>;
1714
1742
  readonly lostConnection: Observable<LostConnectionEvent>;
1715
1743
  readonly customEvent: Observable<RoomEventMessage<TPresence, TUserMeta, TRoomEvent>>;
1716
1744
  readonly self: Observable<User<TPresence, TUserMeta>>;
1717
1745
  readonly myPresence: Observable<TPresence>;
1718
- readonly others: Observable<{
1719
- others: readonly User<TPresence, TUserMeta>[];
1720
- event: OthersEvent<TPresence, TUserMeta>;
1721
- }>;
1746
+ readonly others: Observable<OthersEvent<TPresence, TUserMeta>>;
1722
1747
  readonly error: Observable<Error>;
1723
1748
  readonly storage: Observable<StorageUpdate[]>;
1724
1749
  readonly history: Observable<HistoryEvent>;
@@ -1755,6 +1780,24 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1755
1780
  * - `synchronized`: Storage is in sync with Liveblocks servers.
1756
1781
  */
1757
1782
  getStorageStatus(): StorageStatus;
1783
+ /**
1784
+ * Start an attempt to connect the room (aka "enter" it). Calling
1785
+ * `.connect()` only has an effect if the room is still in its idle initial
1786
+ * state, or the room was explicitly disconnected, or reconnection attempts
1787
+ * were stopped (for example, because the user isn't authorized to enter the
1788
+ * room). Will be a no-op otherwise.
1789
+ */
1790
+ connect(): void;
1791
+ /**
1792
+ * Disconnect the room's connection to the Liveblocks server, if any. Puts
1793
+ * the room back into an idle state. It will not do anything until either
1794
+ * `.connect()` or `.reconnect()` is called.
1795
+ *
1796
+ * Only use this API if you wish to connect the room again at a later time.
1797
+ * If you want to disconnect the room because you no longer need it, call
1798
+ * `.destroy()` instead.
1799
+ */
1800
+ disconnect(): void;
1758
1801
  /**
1759
1802
  * Reconnect the room to the Liveblocks server by re-establishing a fresh
1760
1803
  * connection. If the room is not connected yet, initiate it.
@@ -1777,11 +1820,14 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
1777
1820
  */
1778
1821
  initialStorage?: TStorage | ((roomId: string) => TStorage);
1779
1822
  /**
1780
- * Whether or not the room connects to Liveblock servers. Default is true.
1823
+ * Whether or not the room automatically connects to Liveblock servers.
1824
+ * Default is true.
1781
1825
  *
1782
1826
  * Usually set to false when the client is used from the server to not call
1783
1827
  * the authentication endpoint or connect via WebSocket.
1784
1828
  */
1829
+ autoConnect?: boolean;
1830
+ /** @deprecated Renamed to `autoConnect` */
1785
1831
  shouldInitiallyConnect?: boolean;
1786
1832
  }>;
1787
1833
 
@@ -1804,16 +1850,43 @@ declare type Client = {
1804
1850
  */
1805
1851
  getRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string): Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
1806
1852
  /**
1853
+ * Enter a room.
1854
+ * @param roomId The id of the room
1855
+ * @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
1856
+ * @returns The room and a leave function. Call the returned leave() function when you no longer need the room.
1857
+ */
1858
+ enterRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): {
1859
+ room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
1860
+ leave: () => void;
1861
+ };
1862
+ /**
1863
+ * @deprecated - Prefer using {@link Client.enterRoom} instead.
1864
+ *
1807
1865
  * Enters a room and returns it.
1808
1866
  * @param roomId The id of the room
1809
1867
  * @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
1810
1868
  */
1811
1869
  enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
1812
1870
  /**
1813
- * Leaves a room.
1871
+ * @deprecated - Prefer using {@link Client.enterRoom} and calling the returned leave function instead, which is safer.
1872
+ *
1873
+ * Forcefully leaves a room.
1874
+ *
1875
+ * Only call this if you know for sure there are no other "instances" of this
1876
+ * room used elsewhere in your application. Force-leaving can trigger
1877
+ * unexpected conditions in other parts of your application that may not
1878
+ * expect this.
1879
+ *
1814
1880
  * @param roomId The id of the room
1815
1881
  */
1816
1882
  leave(roomId: string): void;
1883
+ /**
1884
+ * Purges all cached auth tokens and reconnects all rooms that are still
1885
+ * connected, if any.
1886
+ *
1887
+ * Call this whenever you log out a user in your application.
1888
+ */
1889
+ logout(): void;
1817
1890
  };
1818
1891
  declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthenticationResult>);
1819
1892
  /**
@@ -1823,6 +1896,7 @@ declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthentica
1823
1896
  declare type ClientOptions = {
1824
1897
  throttle?: number;
1825
1898
  lostConnectionTimeout?: number;
1899
+ backgroundKeepAliveTimeout?: number;
1826
1900
  polyfills?: Polyfills;
1827
1901
  unstable_fallbackToHTTP?: boolean;
1828
1902
  /**
@@ -1882,6 +1956,7 @@ declare type ParentToChildNodeMap = Map<string, // Parent's node ID
1882
1956
  IdTuple<SerializedChild>[]>;
1883
1957
 
1884
1958
  declare function isLiveNode(value: unknown): value is LiveNode;
1959
+ declare function cloneLson<L extends Lson | undefined>(value: L): L;
1885
1960
 
1886
1961
  declare function lsonToJson(value: Lson): Json;
1887
1962
  declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Json>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
@@ -2366,4 +2441,4 @@ declare type EnsureJson<T> = [
2366
2441
  [K in keyof T]: EnsureJson<T[K]>;
2367
2442
  };
2368
2443
 
2369
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2444
+ export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
package/dist/index.d.ts CHANGED
@@ -240,6 +240,7 @@ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
240
240
  */
241
241
  update(patch: Partial<O>): void;
242
242
  toImmutable(): ToImmutable<O>;
243
+ clone(): LiveObject<O>;
243
244
  }
244
245
 
245
246
  /**
@@ -333,6 +334,7 @@ declare class LiveMap<TKey extends string, TValue extends Lson> extends Abstract
333
334
  */
334
335
  forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
335
336
  toImmutable(): ReadonlyMap<TKey, ToImmutable<TValue>>;
337
+ clone(): LiveMap<TKey, TValue>;
336
338
  }
337
339
 
338
340
  declare type StorageCallback = (updates: StorageUpdate[]) => void;
@@ -352,24 +354,29 @@ declare abstract class AbstractCrdt {
352
354
  * Return an immutable snapshot of this Live node and its children.
353
355
  */
354
356
  toImmutable(): Immutable;
357
+ /**
358
+ * Returns a deep clone of the current LiveStructure, suitable for insertion
359
+ * in the tree elsewhere.
360
+ */
361
+ abstract clone(): Lson;
355
362
  }
356
363
 
357
364
  declare type LiveListUpdateDelta = {
365
+ type: "insert";
358
366
  index: number;
359
367
  item: Lson;
360
- type: "insert";
361
368
  } | {
362
- index: number;
363
369
  type: "delete";
370
+ index: number;
364
371
  } | {
372
+ type: "move";
365
373
  index: number;
366
374
  previousIndex: number;
367
375
  item: Lson;
368
- type: "move";
369
376
  } | {
377
+ type: "set";
370
378
  index: number;
371
379
  item: Lson;
372
- type: "set";
373
380
  };
374
381
  /**
375
382
  * A LiveList notification that is sent in-client to any subscribers whenever
@@ -480,6 +487,7 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
480
487
  some(predicate: (value: TItem, index: number) => unknown): boolean;
481
488
  [Symbol.iterator](): IterableIterator<TItem>;
482
489
  toImmutable(): readonly ToImmutable<TItem>[];
490
+ clone(): LiveList<TItem>;
483
491
  }
484
492
 
485
493
  /**
@@ -488,6 +496,7 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
488
496
  declare class LiveRegister<TValue extends Json> extends AbstractCrdt {
489
497
  constructor(data: TValue);
490
498
  get data(): TValue;
499
+ clone(): TValue;
491
500
  }
492
501
 
493
502
  declare type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson>;
@@ -723,7 +732,7 @@ declare type ThreadData<TThreadMetadata extends BaseMetadata = never> = {
723
732
  };
724
733
 
725
734
  declare type Options = {
726
- serverEndpoint: string;
735
+ baseUrl: string;
727
736
  };
728
737
  declare type PartialNullable<T> = {
729
738
  [P in keyof T]?: T[P] | null | undefined;
@@ -765,7 +774,7 @@ declare type CommentsApi<TThreadMetadata extends BaseMetadata> = {
765
774
  emoji: string;
766
775
  }): Promise<CommentData>;
767
776
  };
768
- declare function createCommentsApi<TThreadMetadata extends BaseMetadata>(roomId: string, getAuthValue: () => Promise<AuthValue>, { serverEndpoint }: Options): CommentsApi<TThreadMetadata>;
777
+ declare function createCommentsApi<TThreadMetadata extends BaseMetadata>(roomId: string, getAuthValue: () => Promise<AuthValue>, config: Options): CommentsApi<TThreadMetadata>;
769
778
 
770
779
  declare type Callback<T> = (event: T) => void;
771
780
  declare type UnsubscribeCallback = () => void;
@@ -944,6 +953,7 @@ declare type BaseAuthResult = NonNullable<Json>;
944
953
  declare type Delegates<T extends BaseAuthResult> = {
945
954
  authenticate: () => Promise<T>;
946
955
  createSocket: (authValue: T) => IWebSocketInstance;
956
+ canZombie: () => boolean;
947
957
  };
948
958
 
949
959
  declare enum ClientMsgCode {
@@ -998,10 +1008,12 @@ declare type FetchStorageClientMsg = {
998
1008
  declare type FetchYDocClientMsg = {
999
1009
  readonly type: ClientMsgCode.FETCH_YDOC;
1000
1010
  readonly vector: string;
1011
+ readonly guid?: string;
1001
1012
  };
1002
1013
  declare type UpdateYDocClientMsg = {
1003
1014
  readonly type: ClientMsgCode.UPDATE_YDOC;
1004
1015
  readonly update: string;
1016
+ readonly guid?: string;
1005
1017
  };
1006
1018
 
1007
1019
  declare type IdTuple<T> = [id: string, value: T];
@@ -1193,6 +1205,7 @@ declare type YDocUpdateServerMsg = {
1193
1205
  readonly update: string;
1194
1206
  readonly isSync: boolean;
1195
1207
  readonly stateVector: string | null;
1208
+ readonly guid?: string;
1196
1209
  };
1197
1210
  /**
1198
1211
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -1312,7 +1325,7 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
1312
1325
  * @deprecated Use `readonly User<TPresence, TUserMeta>[]` instead of `Others<TPresence, TUserMeta>`.
1313
1326
  */
1314
1327
  declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = readonly User<TPresence, TUserMeta>[];
1315
- declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1328
+ declare type InternalOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1316
1329
  type: "leave";
1317
1330
  user: User<TPresence, TUserMeta>;
1318
1331
  } | {
@@ -1325,7 +1338,24 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
1325
1338
  } | {
1326
1339
  type: "reset";
1327
1340
  };
1341
+ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = Resolve<InternalOthersEvent<TPresence, TUserMeta> & {
1342
+ others: readonly User<TPresence, TUserMeta>[];
1343
+ }>;
1328
1344
 
1345
+ declare type LegacyOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
1346
+ type: "leave";
1347
+ user: User<TPresence, TUserMeta>;
1348
+ } | {
1349
+ type: "enter";
1350
+ user: User<TPresence, TUserMeta>;
1351
+ } | {
1352
+ type: "update";
1353
+ user: User<TPresence, TUserMeta>;
1354
+ updates: Partial<TPresence>;
1355
+ } | {
1356
+ type: "reset";
1357
+ };
1358
+ declare type LegacyOthersEventCallback<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = (others: readonly User<TPresence, TUserMeta>[], event: LegacyOthersEvent<TPresence, TUserMeta>) => void;
1329
1359
  declare type RoomEventMessage<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
1330
1360
  /**
1331
1361
  * The connection ID of the client that sent the event.
@@ -1458,7 +1488,7 @@ declare type SubscribeFn<TPresence extends JsonObject, _TStorage extends LsonObj
1458
1488
  * });
1459
1489
  *
1460
1490
  */
1461
- (type: "others", listener: (others: readonly User<TPresence, TUserMeta>[], event: OthersEvent<TPresence, TUserMeta>) => void): () => void;
1491
+ (type: "others", listener: LegacyOthersEventCallback<TPresence, TUserMeta>): () => void;
1462
1492
  /**
1463
1493
  * Subscribe to events broadcasted by {@link Room.broadcastEvent}
1464
1494
  *
@@ -1668,11 +1698,11 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1668
1698
  *
1669
1699
  * @param {string} data the doc update to send to the server, base64 encoded uint8array
1670
1700
  */
1671
- updateYDoc(data: string): void;
1701
+ updateYDoc(data: string, guid?: string): void;
1672
1702
  /**
1673
1703
  * Sends a request for the current document from liveblocks server
1674
1704
  */
1675
- fetchYDoc(stateVector: string): void;
1705
+ fetchYDoc(stateVector: string, guid?: string): void;
1676
1706
  /**
1677
1707
  * Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
1678
1708
  * @param {any} event the event to broadcast. Should be serializable to JSON
@@ -1708,17 +1738,12 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1708
1738
  */
1709
1739
  getStorageSnapshot(): LiveObject<TStorage> | null;
1710
1740
  readonly events: {
1711
- /** @deprecated Prefer `status` instead. */
1712
- readonly connection: Observable<LegacyConnectionStatus>;
1713
1741
  readonly status: Observable<Status>;
1714
1742
  readonly lostConnection: Observable<LostConnectionEvent>;
1715
1743
  readonly customEvent: Observable<RoomEventMessage<TPresence, TUserMeta, TRoomEvent>>;
1716
1744
  readonly self: Observable<User<TPresence, TUserMeta>>;
1717
1745
  readonly myPresence: Observable<TPresence>;
1718
- readonly others: Observable<{
1719
- others: readonly User<TPresence, TUserMeta>[];
1720
- event: OthersEvent<TPresence, TUserMeta>;
1721
- }>;
1746
+ readonly others: Observable<OthersEvent<TPresence, TUserMeta>>;
1722
1747
  readonly error: Observable<Error>;
1723
1748
  readonly storage: Observable<StorageUpdate[]>;
1724
1749
  readonly history: Observable<HistoryEvent>;
@@ -1755,6 +1780,24 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
1755
1780
  * - `synchronized`: Storage is in sync with Liveblocks servers.
1756
1781
  */
1757
1782
  getStorageStatus(): StorageStatus;
1783
+ /**
1784
+ * Start an attempt to connect the room (aka "enter" it). Calling
1785
+ * `.connect()` only has an effect if the room is still in its idle initial
1786
+ * state, or the room was explicitly disconnected, or reconnection attempts
1787
+ * were stopped (for example, because the user isn't authorized to enter the
1788
+ * room). Will be a no-op otherwise.
1789
+ */
1790
+ connect(): void;
1791
+ /**
1792
+ * Disconnect the room's connection to the Liveblocks server, if any. Puts
1793
+ * the room back into an idle state. It will not do anything until either
1794
+ * `.connect()` or `.reconnect()` is called.
1795
+ *
1796
+ * Only use this API if you wish to connect the room again at a later time.
1797
+ * If you want to disconnect the room because you no longer need it, call
1798
+ * `.destroy()` instead.
1799
+ */
1800
+ disconnect(): void;
1758
1801
  /**
1759
1802
  * Reconnect the room to the Liveblocks server by re-establishing a fresh
1760
1803
  * connection. If the room is not connected yet, initiate it.
@@ -1777,11 +1820,14 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
1777
1820
  */
1778
1821
  initialStorage?: TStorage | ((roomId: string) => TStorage);
1779
1822
  /**
1780
- * Whether or not the room connects to Liveblock servers. Default is true.
1823
+ * Whether or not the room automatically connects to Liveblock servers.
1824
+ * Default is true.
1781
1825
  *
1782
1826
  * Usually set to false when the client is used from the server to not call
1783
1827
  * the authentication endpoint or connect via WebSocket.
1784
1828
  */
1829
+ autoConnect?: boolean;
1830
+ /** @deprecated Renamed to `autoConnect` */
1785
1831
  shouldInitiallyConnect?: boolean;
1786
1832
  }>;
1787
1833
 
@@ -1804,16 +1850,43 @@ declare type Client = {
1804
1850
  */
1805
1851
  getRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string): Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
1806
1852
  /**
1853
+ * Enter a room.
1854
+ * @param roomId The id of the room
1855
+ * @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
1856
+ * @returns The room and a leave function. Call the returned leave() function when you no longer need the room.
1857
+ */
1858
+ enterRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): {
1859
+ room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
1860
+ leave: () => void;
1861
+ };
1862
+ /**
1863
+ * @deprecated - Prefer using {@link Client.enterRoom} instead.
1864
+ *
1807
1865
  * Enters a room and returns it.
1808
1866
  * @param roomId The id of the room
1809
1867
  * @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
1810
1868
  */
1811
1869
  enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
1812
1870
  /**
1813
- * Leaves a room.
1871
+ * @deprecated - Prefer using {@link Client.enterRoom} and calling the returned leave function instead, which is safer.
1872
+ *
1873
+ * Forcefully leaves a room.
1874
+ *
1875
+ * Only call this if you know for sure there are no other "instances" of this
1876
+ * room used elsewhere in your application. Force-leaving can trigger
1877
+ * unexpected conditions in other parts of your application that may not
1878
+ * expect this.
1879
+ *
1814
1880
  * @param roomId The id of the room
1815
1881
  */
1816
1882
  leave(roomId: string): void;
1883
+ /**
1884
+ * Purges all cached auth tokens and reconnects all rooms that are still
1885
+ * connected, if any.
1886
+ *
1887
+ * Call this whenever you log out a user in your application.
1888
+ */
1889
+ logout(): void;
1817
1890
  };
1818
1891
  declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthenticationResult>);
1819
1892
  /**
@@ -1823,6 +1896,7 @@ declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthentica
1823
1896
  declare type ClientOptions = {
1824
1897
  throttle?: number;
1825
1898
  lostConnectionTimeout?: number;
1899
+ backgroundKeepAliveTimeout?: number;
1826
1900
  polyfills?: Polyfills;
1827
1901
  unstable_fallbackToHTTP?: boolean;
1828
1902
  /**
@@ -1882,6 +1956,7 @@ declare type ParentToChildNodeMap = Map<string, // Parent's node ID
1882
1956
  IdTuple<SerializedChild>[]>;
1883
1957
 
1884
1958
  declare function isLiveNode(value: unknown): value is LiveNode;
1959
+ declare function cloneLson<L extends Lson | undefined>(value: L): L;
1885
1960
 
1886
1961
  declare function lsonToJson(value: Lson): Json;
1887
1962
  declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Json>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
@@ -2366,4 +2441,4 @@ declare type EnsureJson<T> = [
2366
2441
  [K in keyof T]: EnsureJson<T[K]>;
2367
2442
  };
2368
2443
 
2369
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2444
+ export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentBodyText, CommentData, CommentReaction, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EnterOptions, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, OthersEvent, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomEventMessage, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, YDocUpdateServerMsg, asPos, assert, assertNever, b64decode, cloneLson, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, stringify, throwUsageError, toPlainLson, tryParseJson, withTimeout };