@liveblocks/core 1.4.8-test1 → 1.5.0-test2
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 +89 -15
- package/dist/index.d.ts +89 -15
- package/dist/index.js +276 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +219 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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>,
|
|
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 {
|
|
@@ -1312,7 +1322,7 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
1312
1322
|
* @deprecated Use `readonly User<TPresence, TUserMeta>[]` instead of `Others<TPresence, TUserMeta>`.
|
|
1313
1323
|
*/
|
|
1314
1324
|
declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = readonly User<TPresence, TUserMeta>[];
|
|
1315
|
-
declare type
|
|
1325
|
+
declare type InternalOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
1316
1326
|
type: "leave";
|
|
1317
1327
|
user: User<TPresence, TUserMeta>;
|
|
1318
1328
|
} | {
|
|
@@ -1325,7 +1335,24 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
|
|
|
1325
1335
|
} | {
|
|
1326
1336
|
type: "reset";
|
|
1327
1337
|
};
|
|
1338
|
+
declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = Resolve<InternalOthersEvent<TPresence, TUserMeta> & {
|
|
1339
|
+
others: readonly User<TPresence, TUserMeta>[];
|
|
1340
|
+
}>;
|
|
1328
1341
|
|
|
1342
|
+
declare type LegacyOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
1343
|
+
type: "leave";
|
|
1344
|
+
user: User<TPresence, TUserMeta>;
|
|
1345
|
+
} | {
|
|
1346
|
+
type: "enter";
|
|
1347
|
+
user: User<TPresence, TUserMeta>;
|
|
1348
|
+
} | {
|
|
1349
|
+
type: "update";
|
|
1350
|
+
user: User<TPresence, TUserMeta>;
|
|
1351
|
+
updates: Partial<TPresence>;
|
|
1352
|
+
} | {
|
|
1353
|
+
type: "reset";
|
|
1354
|
+
};
|
|
1355
|
+
declare type LegacyOthersEventCallback<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = (others: readonly User<TPresence, TUserMeta>[], event: LegacyOthersEvent<TPresence, TUserMeta>) => void;
|
|
1329
1356
|
declare type RoomEventMessage<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
|
|
1330
1357
|
/**
|
|
1331
1358
|
* The connection ID of the client that sent the event.
|
|
@@ -1458,7 +1485,7 @@ declare type SubscribeFn<TPresence extends JsonObject, _TStorage extends LsonObj
|
|
|
1458
1485
|
* });
|
|
1459
1486
|
*
|
|
1460
1487
|
*/
|
|
1461
|
-
(type: "others", listener:
|
|
1488
|
+
(type: "others", listener: LegacyOthersEventCallback<TPresence, TUserMeta>): () => void;
|
|
1462
1489
|
/**
|
|
1463
1490
|
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
|
|
1464
1491
|
*
|
|
@@ -1715,10 +1742,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1715
1742
|
readonly customEvent: Observable<RoomEventMessage<TPresence, TUserMeta, TRoomEvent>>;
|
|
1716
1743
|
readonly self: Observable<User<TPresence, TUserMeta>>;
|
|
1717
1744
|
readonly myPresence: Observable<TPresence>;
|
|
1718
|
-
readonly others: Observable<
|
|
1719
|
-
others: readonly User<TPresence, TUserMeta>[];
|
|
1720
|
-
event: OthersEvent<TPresence, TUserMeta>;
|
|
1721
|
-
}>;
|
|
1745
|
+
readonly others: Observable<OthersEvent<TPresence, TUserMeta>>;
|
|
1722
1746
|
readonly error: Observable<Error>;
|
|
1723
1747
|
readonly storage: Observable<StorageUpdate[]>;
|
|
1724
1748
|
readonly history: Observable<HistoryEvent>;
|
|
@@ -1755,6 +1779,24 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1755
1779
|
* - `synchronized`: Storage is in sync with Liveblocks servers.
|
|
1756
1780
|
*/
|
|
1757
1781
|
getStorageStatus(): StorageStatus;
|
|
1782
|
+
/**
|
|
1783
|
+
* Start an attempt to connect the room (aka "enter" it). Calling
|
|
1784
|
+
* `.connect()` only has an effect if the room is still in its idle initial
|
|
1785
|
+
* state, or the room was explicitly disconnected, or reconnection attempts
|
|
1786
|
+
* were stopped (for example, because the user isn't authorized to enter the
|
|
1787
|
+
* room). Will be a no-op otherwise.
|
|
1788
|
+
*/
|
|
1789
|
+
connect(): void;
|
|
1790
|
+
/**
|
|
1791
|
+
* Disconnect the room's connection to the Liveblocks server, if any. Puts
|
|
1792
|
+
* the room back into an idle state. It will not do anything until either
|
|
1793
|
+
* `.connect()` or `.reconnect()` is called.
|
|
1794
|
+
*
|
|
1795
|
+
* Only use this API if you wish to connect the room again at a later time.
|
|
1796
|
+
* If you want to disconnect the room because you no longer need it, call
|
|
1797
|
+
* `.destroy()` instead.
|
|
1798
|
+
*/
|
|
1799
|
+
disconnect(): void;
|
|
1758
1800
|
/**
|
|
1759
1801
|
* Reconnect the room to the Liveblocks server by re-establishing a fresh
|
|
1760
1802
|
* connection. If the room is not connected yet, initiate it.
|
|
@@ -1777,11 +1819,14 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
|
|
|
1777
1819
|
*/
|
|
1778
1820
|
initialStorage?: TStorage | ((roomId: string) => TStorage);
|
|
1779
1821
|
/**
|
|
1780
|
-
* Whether or not the room connects to Liveblock servers.
|
|
1822
|
+
* Whether or not the room automatically connects to Liveblock servers.
|
|
1823
|
+
* Default is true.
|
|
1781
1824
|
*
|
|
1782
1825
|
* Usually set to false when the client is used from the server to not call
|
|
1783
1826
|
* the authentication endpoint or connect via WebSocket.
|
|
1784
1827
|
*/
|
|
1828
|
+
autoConnect?: boolean;
|
|
1829
|
+
/** @deprecated Renamed to `autoConnect` */
|
|
1785
1830
|
shouldInitiallyConnect?: boolean;
|
|
1786
1831
|
}>;
|
|
1787
1832
|
|
|
@@ -1804,16 +1849,43 @@ declare type Client = {
|
|
|
1804
1849
|
*/
|
|
1805
1850
|
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
1851
|
/**
|
|
1852
|
+
* Enter a room.
|
|
1853
|
+
* @param roomId The id of the room
|
|
1854
|
+
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
1855
|
+
* @returns The room and a leave function. Call the returned leave() function when you no longer need the room.
|
|
1856
|
+
*/
|
|
1857
|
+
enterRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): {
|
|
1858
|
+
room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
1859
|
+
leave: () => void;
|
|
1860
|
+
};
|
|
1861
|
+
/**
|
|
1862
|
+
* @deprecated - Prefer using {@link Client.enterRoom} instead.
|
|
1863
|
+
*
|
|
1807
1864
|
* Enters a room and returns it.
|
|
1808
1865
|
* @param roomId The id of the room
|
|
1809
1866
|
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
1810
1867
|
*/
|
|
1811
1868
|
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
1869
|
/**
|
|
1813
|
-
*
|
|
1870
|
+
* @deprecated - Prefer using {@link Client.enterRoom} and calling the returned leave function instead, which is safer.
|
|
1871
|
+
*
|
|
1872
|
+
* Forcefully leaves a room.
|
|
1873
|
+
*
|
|
1874
|
+
* Only call this if you know for sure there are no other "instances" of this
|
|
1875
|
+
* room used elsewhere in your application. Force-leaving can trigger
|
|
1876
|
+
* unexpected conditions in other parts of your application that may not
|
|
1877
|
+
* expect this.
|
|
1878
|
+
*
|
|
1814
1879
|
* @param roomId The id of the room
|
|
1815
1880
|
*/
|
|
1816
1881
|
leave(roomId: string): void;
|
|
1882
|
+
/**
|
|
1883
|
+
* Purges all cached auth tokens and reconnects all rooms that are still
|
|
1884
|
+
* connected, if any.
|
|
1885
|
+
*
|
|
1886
|
+
* Call this whenever you log out a user in your application.
|
|
1887
|
+
*/
|
|
1888
|
+
logout(): void;
|
|
1817
1889
|
};
|
|
1818
1890
|
declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthenticationResult>);
|
|
1819
1891
|
/**
|
|
@@ -1823,6 +1895,7 @@ declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthentica
|
|
|
1823
1895
|
declare type ClientOptions = {
|
|
1824
1896
|
throttle?: number;
|
|
1825
1897
|
lostConnectionTimeout?: number;
|
|
1898
|
+
backgroundKeepAliveTimeout?: number;
|
|
1826
1899
|
polyfills?: Polyfills;
|
|
1827
1900
|
unstable_fallbackToHTTP?: boolean;
|
|
1828
1901
|
/**
|
|
@@ -1882,6 +1955,7 @@ declare type ParentToChildNodeMap = Map<string, // Parent's node ID
|
|
|
1882
1955
|
IdTuple<SerializedChild>[]>;
|
|
1883
1956
|
|
|
1884
1957
|
declare function isLiveNode(value: unknown): value is LiveNode;
|
|
1958
|
+
declare function cloneLson<L extends Lson | undefined>(value: L): L;
|
|
1885
1959
|
|
|
1886
1960
|
declare function lsonToJson(value: Lson): Json;
|
|
1887
1961
|
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 +2440,4 @@ declare type EnsureJson<T> = [
|
|
|
2366
2440
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
2367
2441
|
};
|
|
2368
2442
|
|
|
2369
|
-
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, 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 };
|
|
2443
|
+
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, 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
|
-
|
|
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>,
|
|
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 {
|
|
@@ -1312,7 +1322,7 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
1312
1322
|
* @deprecated Use `readonly User<TPresence, TUserMeta>[]` instead of `Others<TPresence, TUserMeta>`.
|
|
1313
1323
|
*/
|
|
1314
1324
|
declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = readonly User<TPresence, TUserMeta>[];
|
|
1315
|
-
declare type
|
|
1325
|
+
declare type InternalOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
1316
1326
|
type: "leave";
|
|
1317
1327
|
user: User<TPresence, TUserMeta>;
|
|
1318
1328
|
} | {
|
|
@@ -1325,7 +1335,24 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
|
|
|
1325
1335
|
} | {
|
|
1326
1336
|
type: "reset";
|
|
1327
1337
|
};
|
|
1338
|
+
declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = Resolve<InternalOthersEvent<TPresence, TUserMeta> & {
|
|
1339
|
+
others: readonly User<TPresence, TUserMeta>[];
|
|
1340
|
+
}>;
|
|
1328
1341
|
|
|
1342
|
+
declare type LegacyOthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
1343
|
+
type: "leave";
|
|
1344
|
+
user: User<TPresence, TUserMeta>;
|
|
1345
|
+
} | {
|
|
1346
|
+
type: "enter";
|
|
1347
|
+
user: User<TPresence, TUserMeta>;
|
|
1348
|
+
} | {
|
|
1349
|
+
type: "update";
|
|
1350
|
+
user: User<TPresence, TUserMeta>;
|
|
1351
|
+
updates: Partial<TPresence>;
|
|
1352
|
+
} | {
|
|
1353
|
+
type: "reset";
|
|
1354
|
+
};
|
|
1355
|
+
declare type LegacyOthersEventCallback<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = (others: readonly User<TPresence, TUserMeta>[], event: LegacyOthersEvent<TPresence, TUserMeta>) => void;
|
|
1329
1356
|
declare type RoomEventMessage<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
|
|
1330
1357
|
/**
|
|
1331
1358
|
* The connection ID of the client that sent the event.
|
|
@@ -1458,7 +1485,7 @@ declare type SubscribeFn<TPresence extends JsonObject, _TStorage extends LsonObj
|
|
|
1458
1485
|
* });
|
|
1459
1486
|
*
|
|
1460
1487
|
*/
|
|
1461
|
-
(type: "others", listener:
|
|
1488
|
+
(type: "others", listener: LegacyOthersEventCallback<TPresence, TUserMeta>): () => void;
|
|
1462
1489
|
/**
|
|
1463
1490
|
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
|
|
1464
1491
|
*
|
|
@@ -1715,10 +1742,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1715
1742
|
readonly customEvent: Observable<RoomEventMessage<TPresence, TUserMeta, TRoomEvent>>;
|
|
1716
1743
|
readonly self: Observable<User<TPresence, TUserMeta>>;
|
|
1717
1744
|
readonly myPresence: Observable<TPresence>;
|
|
1718
|
-
readonly others: Observable<
|
|
1719
|
-
others: readonly User<TPresence, TUserMeta>[];
|
|
1720
|
-
event: OthersEvent<TPresence, TUserMeta>;
|
|
1721
|
-
}>;
|
|
1745
|
+
readonly others: Observable<OthersEvent<TPresence, TUserMeta>>;
|
|
1722
1746
|
readonly error: Observable<Error>;
|
|
1723
1747
|
readonly storage: Observable<StorageUpdate[]>;
|
|
1724
1748
|
readonly history: Observable<HistoryEvent>;
|
|
@@ -1755,6 +1779,24 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1755
1779
|
* - `synchronized`: Storage is in sync with Liveblocks servers.
|
|
1756
1780
|
*/
|
|
1757
1781
|
getStorageStatus(): StorageStatus;
|
|
1782
|
+
/**
|
|
1783
|
+
* Start an attempt to connect the room (aka "enter" it). Calling
|
|
1784
|
+
* `.connect()` only has an effect if the room is still in its idle initial
|
|
1785
|
+
* state, or the room was explicitly disconnected, or reconnection attempts
|
|
1786
|
+
* were stopped (for example, because the user isn't authorized to enter the
|
|
1787
|
+
* room). Will be a no-op otherwise.
|
|
1788
|
+
*/
|
|
1789
|
+
connect(): void;
|
|
1790
|
+
/**
|
|
1791
|
+
* Disconnect the room's connection to the Liveblocks server, if any. Puts
|
|
1792
|
+
* the room back into an idle state. It will not do anything until either
|
|
1793
|
+
* `.connect()` or `.reconnect()` is called.
|
|
1794
|
+
*
|
|
1795
|
+
* Only use this API if you wish to connect the room again at a later time.
|
|
1796
|
+
* If you want to disconnect the room because you no longer need it, call
|
|
1797
|
+
* `.destroy()` instead.
|
|
1798
|
+
*/
|
|
1799
|
+
disconnect(): void;
|
|
1758
1800
|
/**
|
|
1759
1801
|
* Reconnect the room to the Liveblocks server by re-establishing a fresh
|
|
1760
1802
|
* connection. If the room is not connected yet, initiate it.
|
|
@@ -1777,11 +1819,14 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
|
|
|
1777
1819
|
*/
|
|
1778
1820
|
initialStorage?: TStorage | ((roomId: string) => TStorage);
|
|
1779
1821
|
/**
|
|
1780
|
-
* Whether or not the room connects to Liveblock servers.
|
|
1822
|
+
* Whether or not the room automatically connects to Liveblock servers.
|
|
1823
|
+
* Default is true.
|
|
1781
1824
|
*
|
|
1782
1825
|
* Usually set to false when the client is used from the server to not call
|
|
1783
1826
|
* the authentication endpoint or connect via WebSocket.
|
|
1784
1827
|
*/
|
|
1828
|
+
autoConnect?: boolean;
|
|
1829
|
+
/** @deprecated Renamed to `autoConnect` */
|
|
1785
1830
|
shouldInitiallyConnect?: boolean;
|
|
1786
1831
|
}>;
|
|
1787
1832
|
|
|
@@ -1804,16 +1849,43 @@ declare type Client = {
|
|
|
1804
1849
|
*/
|
|
1805
1850
|
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
1851
|
/**
|
|
1852
|
+
* Enter a room.
|
|
1853
|
+
* @param roomId The id of the room
|
|
1854
|
+
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
1855
|
+
* @returns The room and a leave function. Call the returned leave() function when you no longer need the room.
|
|
1856
|
+
*/
|
|
1857
|
+
enterRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: EnterOptions<TPresence, TStorage>): {
|
|
1858
|
+
room: Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
1859
|
+
leave: () => void;
|
|
1860
|
+
};
|
|
1861
|
+
/**
|
|
1862
|
+
* @deprecated - Prefer using {@link Client.enterRoom} instead.
|
|
1863
|
+
*
|
|
1807
1864
|
* Enters a room and returns it.
|
|
1808
1865
|
* @param roomId The id of the room
|
|
1809
1866
|
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
1810
1867
|
*/
|
|
1811
1868
|
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
1869
|
/**
|
|
1813
|
-
*
|
|
1870
|
+
* @deprecated - Prefer using {@link Client.enterRoom} and calling the returned leave function instead, which is safer.
|
|
1871
|
+
*
|
|
1872
|
+
* Forcefully leaves a room.
|
|
1873
|
+
*
|
|
1874
|
+
* Only call this if you know for sure there are no other "instances" of this
|
|
1875
|
+
* room used elsewhere in your application. Force-leaving can trigger
|
|
1876
|
+
* unexpected conditions in other parts of your application that may not
|
|
1877
|
+
* expect this.
|
|
1878
|
+
*
|
|
1814
1879
|
* @param roomId The id of the room
|
|
1815
1880
|
*/
|
|
1816
1881
|
leave(roomId: string): void;
|
|
1882
|
+
/**
|
|
1883
|
+
* Purges all cached auth tokens and reconnects all rooms that are still
|
|
1884
|
+
* connected, if any.
|
|
1885
|
+
*
|
|
1886
|
+
* Call this whenever you log out a user in your application.
|
|
1887
|
+
*/
|
|
1888
|
+
logout(): void;
|
|
1817
1889
|
};
|
|
1818
1890
|
declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthenticationResult>);
|
|
1819
1891
|
/**
|
|
@@ -1823,6 +1895,7 @@ declare type AuthEndpoint = string | ((room: string) => Promise<CustomAuthentica
|
|
|
1823
1895
|
declare type ClientOptions = {
|
|
1824
1896
|
throttle?: number;
|
|
1825
1897
|
lostConnectionTimeout?: number;
|
|
1898
|
+
backgroundKeepAliveTimeout?: number;
|
|
1826
1899
|
polyfills?: Polyfills;
|
|
1827
1900
|
unstable_fallbackToHTTP?: boolean;
|
|
1828
1901
|
/**
|
|
@@ -1882,6 +1955,7 @@ declare type ParentToChildNodeMap = Map<string, // Parent's node ID
|
|
|
1882
1955
|
IdTuple<SerializedChild>[]>;
|
|
1883
1956
|
|
|
1884
1957
|
declare function isLiveNode(value: unknown): value is LiveNode;
|
|
1958
|
+
declare function cloneLson<L extends Lson | undefined>(value: L): L;
|
|
1885
1959
|
|
|
1886
1960
|
declare function lsonToJson(value: Lson): Json;
|
|
1887
1961
|
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 +2440,4 @@ declare type EnsureJson<T> = [
|
|
|
2366
2440
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
2367
2441
|
};
|
|
2368
2442
|
|
|
2369
|
-
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, 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 };
|
|
2443
|
+
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, 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 };
|