@liveblocks/client 0.17.11 → 0.18.0-beta2

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.
@@ -1,107 +1,21 @@
1
- declare abstract class AbstractCrdt {
2
- get roomId(): string | null;
3
- }
1
+ declare type Callback<T> = (event: T) => void;
2
+ declare type UnsubscribeCallback = () => void;
3
+ declare type Observable<T> = {
4
+ subscribe(callback: Callback<T>): UnsubscribeCallback;
5
+ subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
6
+ };
4
7
 
5
- /**
6
- * The LiveList class represents an ordered collection of items that is synchronized across clients.
7
- */
8
- declare class LiveList<TItem extends Lson> extends AbstractCrdt {
9
- constructor(items?: TItem[]);
10
- /**
11
- * Returns the number of elements.
12
- */
13
- get length(): number;
14
- /**
15
- * Adds one element to the end of the LiveList.
16
- * @param element The element to add to the end of the LiveList.
17
- */
18
- push(element: TItem): void;
19
- /**
20
- * Inserts one element at a specified index.
21
- * @param element The element to insert.
22
- * @param index The index at which you want to insert the element.
23
- */
24
- insert(element: TItem, index: number): void;
25
- /**
26
- * Move one element from one index to another.
27
- * @param index The index of the element to move
28
- * @param targetIndex The index where the element should be after moving.
29
- */
30
- move(index: number, targetIndex: number): void;
31
- /**
32
- * Deletes an element at the specified index
33
- * @param index The index of the element to delete
34
- */
35
- delete(index: number): void;
36
- clear(): void;
37
- set(index: number, item: TItem): void;
8
+ declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
38
9
  /**
39
- * Returns an Array of all the elements in the LiveList.
40
- */
41
- toArray(): TItem[];
42
- /**
43
- * Tests whether all elements pass the test implemented by the provided function.
44
- * @param predicate Function to test for each element, taking two arguments (the element and its index).
45
- * @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
46
- */
47
- every(predicate: (value: TItem, index: number) => unknown): boolean;
48
- /**
49
- * Creates an array with all elements that pass the test implemented by the provided function.
50
- * @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
51
- * @returns An array with the elements that pass the test.
52
- */
53
- filter(predicate: (value: TItem, index: number) => unknown): TItem[];
54
- /**
55
- * Returns the first element that satisfies the provided testing function.
56
- * @param predicate Function to execute on each value.
57
- * @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
58
- */
59
- find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
60
- /**
61
- * Returns the index of the first element in the LiveList that satisfies the provided testing function.
62
- * @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
63
- * @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
64
- */
65
- findIndex(predicate: (value: TItem, index: number) => unknown): number;
66
- /**
67
- * Executes a provided function once for each element.
68
- * @param callbackfn Function to execute on each element.
69
- */
70
- forEach(callbackfn: (value: TItem, index: number) => void): void;
71
- /**
72
- * Get the element at the specified index.
73
- * @param index The index on the element to get.
74
- * @returns The element at the specified index or undefined.
10
+ * @deprecated Prefer the normal .length property on arrays.
75
11
  */
76
- get(index: number): TItem | undefined;
77
- /**
78
- * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
79
- * @param searchElement Element to locate.
80
- * @param fromIndex The index to start the search at.
81
- * @returns The first index of the element in the LiveList; -1 if not found.
82
- */
83
- indexOf(searchElement: TItem, fromIndex?: number): number;
84
- /**
85
- * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.
86
- * @param searchElement Element to locate.
87
- * @param fromIndex The index at which to start searching backwards.
88
- * @returns
89
- */
90
- lastIndexOf(searchElement: TItem, fromIndex?: number): number;
91
- /**
92
- * Creates an array populated with the results of calling a provided function on every element.
93
- * @param callback Function that is called for every element.
94
- * @returns An array with each element being the result of the callback function.
95
- */
96
- map<U>(callback: (value: TItem, index: number) => U): U[];
12
+ readonly count: number;
97
13
  /**
98
- * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
99
- * @param predicate Function to test for each element.
100
- * @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
14
+ * @deprecated Calling .toArray() is no longer needed
101
15
  */
102
- some(predicate: (value: TItem, index: number) => unknown): boolean;
103
- [Symbol.iterator](): IterableIterator<TItem>;
104
- }
16
+ readonly toArray: () => readonly T[];
17
+ };
18
+ declare function asArrayWithLegacyMethods<T>(arr: readonly T[]): ReadonlyArrayWithLegacyMethods<T>;
105
19
 
106
20
  /**
107
21
  * The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
@@ -110,10 +24,6 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
110
24
  */
111
25
  declare class LiveMap<TKey extends string, TValue extends Lson> extends AbstractCrdt {
112
26
  constructor(entries?: readonly (readonly [TKey, TValue])[] | undefined);
113
- /**
114
- * @deprecated Please call as `new LiveMap()` or `new LiveMap([])` instead.
115
- */
116
- constructor(entries: null);
117
27
  /**
118
28
  * Returns a specified element from the LiveMap.
119
29
  * @param key The key of the element to return.
@@ -162,6 +72,7 @@ declare class LiveMap<TKey extends string, TValue extends Lson> extends Abstract
162
72
  * @param callback Function to execute for each entry in the map.
163
73
  */
164
74
  forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
75
+ toImmutable(): ReadonlyMap<TKey, ToImmutable<TValue>>;
165
76
  }
166
77
 
167
78
  /**
@@ -193,9 +104,10 @@ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
193
104
  delete(key: keyof O): void;
194
105
  /**
195
106
  * Adds or updates multiple properties at once with an object.
196
- * @param overrides The object used to overrides properties
107
+ * @param patch The object used to overrides properties
197
108
  */
198
- update(overrides: Partial<O>): void;
109
+ update(patch: Partial<O>): void;
110
+ toImmutable(): ToImmutable<O>;
199
111
  }
200
112
 
201
113
  /**
@@ -218,18 +130,6 @@ declare function isJsonScalar(data: Json): data is JsonScalar;
218
130
  declare function isJsonArray(data: Json): data is JsonArray;
219
131
  declare function isJsonObject(data: Json): data is JsonObject;
220
132
 
221
- declare type BaseUserMeta = {
222
- /**
223
- * The id of the user that has been set in the authentication endpoint.
224
- * Useful to get additional information about the connected user.
225
- */
226
- id?: string;
227
- /**
228
- * Additional user information that has been set in the authentication endpoint.
229
- */
230
- info?: Json;
231
- };
232
-
233
133
  /**
234
134
  * INTERNAL
235
135
  */
@@ -257,6 +157,182 @@ declare type LiveNode = LiveStructure | LiveRegister<Json>;
257
157
  declare type LsonObject = {
258
158
  [key: string]: Lson | undefined;
259
159
  };
160
+ /**
161
+ * Helper type to convert any valid Lson type to the equivalent Json type.
162
+ *
163
+ * Examples:
164
+ *
165
+ * ToJson<42> // 42
166
+ * ToJson<'hi'> // 'hi'
167
+ * ToJson<number> // number
168
+ * ToJson<string> // string
169
+ * ToJson<string | LiveList<number>> // string | number[]
170
+ * ToJson<LiveMap<string, LiveList<number>>>
171
+ * // { [key: string]: number[] }
172
+ * ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
173
+ * // { a: null, b: string[], c?: number }
174
+ *
175
+ */
176
+ declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
177
+ [K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
178
+ } : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
179
+ [K in KS]: ToJson<V>;
180
+ } : never;
181
+
182
+ /**
183
+ * Represents an indefinitely deep arbitrary immutable data
184
+ * structure, as returned by the .toImmutable().
185
+ */
186
+
187
+ declare type Immutable = Scalar | ImmutableList | ImmutableObject | ImmutableMap;
188
+ declare type Scalar = string | number | boolean | null;
189
+ declare type ImmutableList = readonly Immutable[];
190
+ declare type ImmutableObject = {
191
+ readonly [key: string]: Immutable | undefined;
192
+ };
193
+ declare type ImmutableMap = ReadonlyMap<string, Immutable>;
194
+ declare type ImmutableRef = Exclude<Immutable, Scalar>;
195
+ /**
196
+ * Helper type to convert any valid Lson type to the equivalent Json type.
197
+ *
198
+ * Examples:
199
+ *
200
+ * ToImmutable<42> // 42
201
+ * ToImmutable<'hi'> // 'hi'
202
+ * ToImmutable<number> // number
203
+ * ToImmutable<string> // string
204
+ * ToImmutable<string | LiveList<number>> // string | readonly number[]
205
+ * ToImmutable<LiveMap<string, LiveList<number>>>
206
+ * // { readonly [key: string]: readonly number[] }
207
+ * ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
208
+ * // { readonly a: null, readonly b: readonly string[], readonly c?: number }
209
+ *
210
+ */
211
+ declare type ToImmutable<L extends Lson | LsonObject> = L extends LiveList<infer I> ? readonly ToImmutable<I>[] : L extends LiveObject<infer O> ? ToImmutable<O> : L extends LiveMap<infer K, infer V> ? ReadonlyMap<K, ToImmutable<V>> : L extends LsonObject ? {
212
+ readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
213
+ } : L extends Json ? L : never;
214
+
215
+ declare abstract class AbstractCrdt {
216
+ get roomId(): string | null;
217
+ /**
218
+ * Return an immutable snapshot of this Live node and its children.
219
+ */
220
+ toImmutable(): Immutable;
221
+ }
222
+
223
+ /**
224
+ * The LiveList class represents an ordered collection of items that is synchronized across clients.
225
+ */
226
+ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
227
+ constructor(items?: TItem[]);
228
+ /**
229
+ * Returns the number of elements.
230
+ */
231
+ get length(): number;
232
+ /**
233
+ * Adds one element to the end of the LiveList.
234
+ * @param element The element to add to the end of the LiveList.
235
+ */
236
+ push(element: TItem): void;
237
+ /**
238
+ * Inserts one element at a specified index.
239
+ * @param element The element to insert.
240
+ * @param index The index at which you want to insert the element.
241
+ */
242
+ insert(element: TItem, index: number): void;
243
+ /**
244
+ * Move one element from one index to another.
245
+ * @param index The index of the element to move
246
+ * @param targetIndex The index where the element should be after moving.
247
+ */
248
+ move(index: number, targetIndex: number): void;
249
+ /**
250
+ * Deletes an element at the specified index
251
+ * @param index The index of the element to delete
252
+ */
253
+ delete(index: number): void;
254
+ clear(): void;
255
+ set(index: number, item: TItem): void;
256
+ /**
257
+ * Returns an Array of all the elements in the LiveList.
258
+ */
259
+ toArray(): TItem[];
260
+ /**
261
+ * Tests whether all elements pass the test implemented by the provided function.
262
+ * @param predicate Function to test for each element, taking two arguments (the element and its index).
263
+ * @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
264
+ */
265
+ every(predicate: (value: TItem, index: number) => unknown): boolean;
266
+ /**
267
+ * Creates an array with all elements that pass the test implemented by the provided function.
268
+ * @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
269
+ * @returns An array with the elements that pass the test.
270
+ */
271
+ filter(predicate: (value: TItem, index: number) => unknown): TItem[];
272
+ /**
273
+ * Returns the first element that satisfies the provided testing function.
274
+ * @param predicate Function to execute on each value.
275
+ * @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
276
+ */
277
+ find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
278
+ /**
279
+ * Returns the index of the first element in the LiveList that satisfies the provided testing function.
280
+ * @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
281
+ * @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
282
+ */
283
+ findIndex(predicate: (value: TItem, index: number) => unknown): number;
284
+ /**
285
+ * Executes a provided function once for each element.
286
+ * @param callbackfn Function to execute on each element.
287
+ */
288
+ forEach(callbackfn: (value: TItem, index: number) => void): void;
289
+ /**
290
+ * Get the element at the specified index.
291
+ * @param index The index on the element to get.
292
+ * @returns The element at the specified index or undefined.
293
+ */
294
+ get(index: number): TItem | undefined;
295
+ /**
296
+ * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
297
+ * @param searchElement Element to locate.
298
+ * @param fromIndex The index to start the search at.
299
+ * @returns The first index of the element in the LiveList; -1 if not found.
300
+ */
301
+ indexOf(searchElement: TItem, fromIndex?: number): number;
302
+ /**
303
+ * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.
304
+ * @param searchElement Element to locate.
305
+ * @param fromIndex The index at which to start searching backwards.
306
+ * @returns
307
+ */
308
+ lastIndexOf(searchElement: TItem, fromIndex?: number): number;
309
+ /**
310
+ * Creates an array populated with the results of calling a provided function on every element.
311
+ * @param callback Function that is called for every element.
312
+ * @returns An array with each element being the result of the callback function.
313
+ */
314
+ map<U>(callback: (value: TItem, index: number) => U): U[];
315
+ /**
316
+ * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
317
+ * @param predicate Function to test for each element.
318
+ * @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
319
+ */
320
+ some(predicate: (value: TItem, index: number) => unknown): boolean;
321
+ [Symbol.iterator](): IterableIterator<TItem>;
322
+ toImmutable(): ImmutableList;
323
+ }
324
+
325
+ declare type BaseUserMeta = {
326
+ /**
327
+ * The id of the user that has been set in the authentication endpoint.
328
+ * Useful to get additional information about the connected user.
329
+ */
330
+ id?: string;
331
+ /**
332
+ * Additional user information that has been set in the authentication endpoint.
333
+ */
334
+ info?: Json;
335
+ };
260
336
 
261
337
  /**
262
338
  * This helper type is effectively a no-op, but will force TypeScript to
@@ -283,15 +359,10 @@ declare type LsonObject = {
283
359
  declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
284
360
  [K in keyof T]: T[K];
285
361
  };
286
- declare type MyPresenceCallback<TPresence extends JsonObject> = (me: TPresence) => void;
287
- declare type OthersEventCallback<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = (others: Others<TPresence, TUserMeta>, event: OthersEvent<TPresence, TUserMeta>) => void;
288
- declare type EventCallback<TRoomEvent extends Json> = ({ connectionId, event, }: {
362
+ declare type CustomEvent<TRoomEvent extends Json> = {
289
363
  connectionId: number;
290
364
  event: TRoomEvent;
291
- }) => void;
292
- declare type ErrorCallback = (error: Error) => void;
293
- declare type ConnectionCallback = (state: ConnectionState) => void;
294
- declare type HistoryCallback = (event: HistoryEvent) => void;
365
+ };
295
366
  declare type UpdateDelta = {
296
367
  type: "update";
297
368
  } | {
@@ -368,21 +439,11 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
368
439
  * The initial Presence to use and announce when you enter the Room. The
369
440
  * Presence is available on all users in the Room (me & others).
370
441
  */
371
- initialPresence?: TPresence | ((roomId: string) => TPresence);
442
+ initialPresence: TPresence | ((roomId: string) => TPresence);
372
443
  /**
373
444
  * The initial Storage to use when entering a new Room.
374
445
  */
375
446
  initialStorage?: TStorage | ((roomId: string) => TStorage);
376
- /**
377
- * @deprecated Please use `initialPresence` instead. This property is
378
- * scheduled for removal in 0.18.
379
- */
380
- defaultPresence?: () => TPresence;
381
- /**
382
- * @deprecated Please use `initialStorage` instead. This property is
383
- * scheduled for removal in 0.18.
384
- */
385
- defaultStorageRoot?: TStorage;
386
447
  }>;
387
448
  declare type Client = {
388
449
  /**
@@ -396,7 +457,7 @@ declare type Client = {
396
457
  * @param roomId The id of the room
397
458
  * @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
398
459
  */
399
- enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options?: RoomInitializers<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
460
+ enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: RoomInitializers<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
400
461
  /**
401
462
  * Leaves a room.
402
463
  * @param roomId The id of the room
@@ -406,24 +467,7 @@ declare type Client = {
406
467
  /**
407
468
  * Represents all the other users connected in the room. Treated as immutable.
408
469
  */
409
- interface Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> {
410
- /**
411
- * Number of other users in the room.
412
- */
413
- readonly count: number;
414
- /**
415
- * Returns a new Iterator object that contains the users.
416
- */
417
- [Symbol.iterator](): IterableIterator<User<TPresence, TUserMeta>>;
418
- /**
419
- * Returns the array of connected users in room.
420
- */
421
- toArray(): User<TPresence, TUserMeta>[];
422
- /**
423
- * This function let you map over the connected users in the room.
424
- */
425
- map<U>(callback: (user: User<TPresence, TUserMeta>) => U): U[];
426
- }
470
+ declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = ReadonlyArrayWithLegacyMethods<User<TPresence, TUserMeta>>;
427
471
  /**
428
472
  * Represents a user connected in a room. Treated as immutable.
429
473
  */
@@ -444,24 +488,8 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
444
488
  /**
445
489
  * The user presence.
446
490
  */
447
- readonly presence?: TPresence;
491
+ readonly presence: TPresence;
448
492
  };
449
- /**
450
- * @deprecated Whatever you want to store as presence is app-specific. Please
451
- * define your own Presence type instead of importing it from
452
- * `@liveblocks/client`, for example:
453
- *
454
- * type Presence = {
455
- * name: string,
456
- * cursor: {
457
- * x: number,
458
- * y: number,
459
- * } | null,
460
- * }
461
- *
462
- * As long as it only contains JSON-serializable values, you're good!
463
- */
464
- declare type Presence = JsonObject;
465
493
  declare type AuthEndpointCallback = (room: string) => Promise<{
466
494
  token: string;
467
495
  }>;
@@ -494,12 +522,23 @@ declare type ClientOptions = {
494
522
  authEndpoint: AuthEndpoint;
495
523
  });
496
524
  declare type Connection = {
497
- state: "closed" | "authenticating" | "unavailable" | "failed";
525
+ state: "closed";
526
+ } | {
527
+ state: "authenticating";
528
+ } | {
529
+ state: "connecting";
530
+ id: number;
531
+ userId?: string;
532
+ userInfo?: Json;
498
533
  } | {
499
- state: "open" | "connecting";
534
+ state: "open";
500
535
  id: number;
501
536
  userId?: string;
502
537
  userInfo?: Json;
538
+ } | {
539
+ state: "unavailable";
540
+ } | {
541
+ state: "failed";
503
542
  };
504
543
  declare type ConnectionState = Connection["state"];
505
544
  declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
@@ -597,6 +636,11 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
597
636
  * The id of the room.
598
637
  */
599
638
  readonly id: string;
639
+ /**
640
+ * A client is considered "self aware" if it knows its own
641
+ * metadata and connection ID (from the auth server).
642
+ */
643
+ isSelfAware(): boolean;
600
644
  getConnectionState(): ConnectionState;
601
645
  subscribe: {
602
646
  /**
@@ -611,7 +655,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
611
655
  * // Do something
612
656
  * });
613
657
  */
614
- (type: "my-presence", listener: MyPresenceCallback<TPresence>): () => void;
658
+ (type: "my-presence", listener: Callback<TPresence>): () => void;
615
659
  /**
616
660
  * Subscribe to the other users updates.
617
661
  *
@@ -623,8 +667,9 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
623
667
  * room.subscribe("others", (others) => {
624
668
  * // Do something
625
669
  * });
670
+ *
626
671
  */
627
- (type: "others", listener: OthersEventCallback<TPresence, TUserMeta>): () => void;
672
+ (type: "others", listener: (others: Others<TPresence, TUserMeta>, event: OthersEvent<TPresence, TUserMeta>) => void): () => void;
628
673
  /**
629
674
  * Subscribe to events broadcasted by {@link Room.broadcastEvent}
630
675
  *
@@ -636,20 +681,23 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
636
681
  * room.subscribe("event", ({ event, connectionId }) => {
637
682
  * // Do something
638
683
  * });
684
+ *
639
685
  */
640
- (type: "event", listener: EventCallback<TRoomEvent>): () => void;
686
+ (type: "event", listener: Callback<CustomEvent<TRoomEvent>>): () => void;
641
687
  /**
642
688
  * Subscribe to errors thrown in the room.
643
689
  *
644
690
  * @returns Unsubscribe function.
691
+ *
645
692
  */
646
693
  (type: "error", listener: ErrorCallback): () => void;
647
694
  /**
648
695
  * Subscribe to connection state updates.
649
696
  *
650
697
  * @returns Unsubscribe function.
698
+ *
651
699
  */
652
- (type: "connection", listener: ConnectionCallback): () => void;
700
+ (type: "connection", listener: Callback<ConnectionState>): () => void;
653
701
  /**
654
702
  * Subscribes to changes made on a Live structure. Returns an unsubscribe function.
655
703
  * In a future version, we will also expose what exactly changed in the Live structure.
@@ -691,8 +739,9 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
691
739
  * room.subscribe("history", ({ canUndo, canRedo }) => {
692
740
  * // Do something
693
741
  * });
742
+ *
694
743
  */
695
- (type: "history", listener: HistoryCallback): () => void;
744
+ (type: "history", listener: Callback<HistoryEvent>): () => void;
696
745
  };
697
746
  /**
698
747
  * Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage.
@@ -722,8 +771,8 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
722
771
  getOthers: () => Others<TPresence, TUserMeta>;
723
772
  /**
724
773
  * Updates the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
725
- * @param overrides A partial object that contains the properties you want to update.
726
- * @param overrides Optional object to configure the behavior of updatePresence.
774
+ * @param patch A partial object that contains the properties you want to update.
775
+ * @param options Optional object to configure the behavior of updatePresence.
727
776
  *
728
777
  * @example
729
778
  * room.updatePresence({ x: 0 });
@@ -732,7 +781,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
732
781
  * const presence = room.getPresence();
733
782
  * // presence is equivalent to { x: 0, y: 0 }
734
783
  */
735
- updatePresence: (overrides: Partial<TPresence>, options?: {
784
+ updatePresence: (patch: Partial<TPresence>, options?: {
736
785
  /**
737
786
  * Whether or not the presence should have an impact on the undo/redo history.
738
787
  */
@@ -764,6 +813,34 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
764
813
  getStorage: () => Promise<{
765
814
  root: LiveObject<TStorage>;
766
815
  }>;
816
+ /**
817
+ * Get the room's storage synchronously.
818
+ * The storage's root is a {@link LiveObject}.
819
+ *
820
+ * @example
821
+ * const root = room.getStorageSnapshot();
822
+ */
823
+ getStorageSnapshot(): LiveObject<TStorage> | null;
824
+ events: {
825
+ customEvent: Observable<{
826
+ connectionId: number;
827
+ event: TRoomEvent;
828
+ }>;
829
+ me: Observable<TPresence>;
830
+ others: Observable<{
831
+ others: Others<TPresence, TUserMeta>;
832
+ event: OthersEvent<TPresence, TUserMeta>;
833
+ }>;
834
+ error: Observable<Error>;
835
+ connection: Observable<ConnectionState>;
836
+ storage: Observable<StorageUpdate[]>;
837
+ history: Observable<HistoryEvent>;
838
+ /**
839
+ * Subscribe to the storage loaded event. Will fire at most once during the
840
+ * lifetime of a Room.
841
+ */
842
+ storageDidLoad: Observable<void>;
843
+ };
767
844
  /**
768
845
  * Batches modifications made during the given function.
769
846
  * All the modifications are sent to other clients in a single message.
@@ -777,7 +854,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
777
854
  * room.updatePresence({ cursor: { x: 100, y: 100 }});
778
855
  * });
779
856
  */
780
- batch: (fn: () => void) => void;
857
+ batch<T>(fn: () => T): T;
781
858
  };
782
859
  declare enum WebsocketCloseCodes {
783
860
  CLOSE_ABNORMAL = 1006,
@@ -790,4 +867,4 @@ declare enum WebsocketCloseCodes {
790
867
  CLOSE_WITHOUT_RETRY = 4999
791
868
  }
792
869
 
793
- export { BaseUserMeta as B, ClientOptions as C, History as H, Json as J, LiveList as L, Others as O, Presence as P, Room as R, StorageUpdate as S, User as U, WebsocketCloseCodes as W, Client as a, LiveMap as b, LiveObject as c, BroadcastOptions as d, JsonObject as e, LiveStructure as f, Lson as g, LsonObject as h, LiveNode as i, Resolve as j, RoomInitializers as k, isJsonArray as l, isJsonObject as m, isJsonScalar as n };
870
+ export { BaseUserMeta as B, ClientOptions as C, History as H, Immutable as I, Json as J, LiveList as L, Others as O, Room as R, StorageUpdate as S, ToJson as T, User as U, WebsocketCloseCodes as W, Client as a, LiveMap as b, LiveObject as c, BroadcastOptions as d, ImmutableList as e, ImmutableMap as f, ImmutableObject as g, ImmutableRef as h, JsonObject as i, LiveStructure as j, Lson as k, LsonObject as l, asArrayWithLegacyMethods as m, LiveNode as n, Resolve as o, RoomInitializers as p, ToImmutable as q, isJsonArray as r, isJsonObject as s, isJsonScalar as t };
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientOptions, a as Client } from './index-0007883d.js';
2
- export { B as BaseUserMeta, d as BroadcastOptions, a as Client, H as History, J as Json, e as JsonObject, L as LiveList, b as LiveMap, c as LiveObject, f as LiveStructure, g as Lson, h as LsonObject, O as Others, P as Presence, R as Room, S as StorageUpdate, U as User } from './index-0007883d.js';
1
+ import { C as ClientOptions, a as Client } from './index-60aa9677.js';
2
+ export { B as BaseUserMeta, d as BroadcastOptions, a as Client, H as History, I as Immutable, e as ImmutableList, f as ImmutableMap, g as ImmutableObject, h as ImmutableRef, J as Json, i as JsonObject, L as LiveList, b as LiveMap, c as LiveObject, j as LiveStructure, k as Lson, l as LsonObject, O as Others, R as Room, S as StorageUpdate, U as User } from './index-60aa9677.js';
3
3
 
4
4
  /**
5
5
  * Create a client that will be responsible to communicate with liveblocks servers.
@@ -28,6 +28,17 @@ export { B as BaseUserMeta, d as BroadcastOptions, a as Client, H as History, J
28
28
  */
29
29
  declare function createClient(options: ClientOptions): Client;
30
30
 
31
+ /**
32
+ * Shallowly compares two given values.
33
+ *
34
+ * - Two simple values are considered equal if they're strictly equal
35
+ * - Two arrays are considered equal if their members are strictly equal
36
+ * - Two objects are considered equal if their values are strictly equal
37
+ *
38
+ * Testing goes one level deep.
39
+ */
40
+ declare function shallow(a: unknown, b: unknown): boolean;
41
+
31
42
  /**
32
43
  * Helper type to help users adopt to Lson types from interface definitions.
33
44
  * You should only use this to wrap interfaces you don't control. For more
@@ -40,4 +51,4 @@ declare type EnsureJson<T> = [
40
51
  [K in keyof T]: EnsureJson<T[K]>;
41
52
  };
42
53
 
43
- export { EnsureJson, createClient };
54
+ export { EnsureJson, createClient, shallow };