@liveblocks/client 0.17.11 → 0.18.0-beta0
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/.built-by-link-script +1 -1
- package/{chunk-QLMVHHAZ.js → chunk-ZR7CHFN6.js} +306 -170
- package/{index-0007883d.d.ts → index-4e7d8cac.d.ts} +260 -185
- package/index.d.ts +14 -3
- package/index.js +701 -496
- package/index.mjs +1 -0
- package/internal.d.ts +35 -8
- package/internal.js +48 -47
- package/internal.mjs +2 -1
- package/package.json +1 -1
|
@@ -1,107 +1,9 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
38
|
-
/**
|
|
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.
|
|
75
|
-
*/
|
|
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[];
|
|
97
|
-
/**
|
|
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.
|
|
101
|
-
*/
|
|
102
|
-
some(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
103
|
-
[Symbol.iterator](): IterableIterator<TItem>;
|
|
104
|
-
}
|
|
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
|
+
};
|
|
105
7
|
|
|
106
8
|
/**
|
|
107
9
|
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
@@ -110,10 +12,6 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
|
|
|
110
12
|
*/
|
|
111
13
|
declare class LiveMap<TKey extends string, TValue extends Lson> extends AbstractCrdt {
|
|
112
14
|
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
15
|
/**
|
|
118
16
|
* Returns a specified element from the LiveMap.
|
|
119
17
|
* @param key The key of the element to return.
|
|
@@ -162,6 +60,7 @@ declare class LiveMap<TKey extends string, TValue extends Lson> extends Abstract
|
|
|
162
60
|
* @param callback Function to execute for each entry in the map.
|
|
163
61
|
*/
|
|
164
62
|
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
|
|
63
|
+
toImmutable(): ReadonlyMap<TKey, ToImmutable<TValue>>;
|
|
165
64
|
}
|
|
166
65
|
|
|
167
66
|
/**
|
|
@@ -193,9 +92,10 @@ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
|
|
|
193
92
|
delete(key: keyof O): void;
|
|
194
93
|
/**
|
|
195
94
|
* Adds or updates multiple properties at once with an object.
|
|
196
|
-
* @param
|
|
95
|
+
* @param patch The object used to overrides properties
|
|
197
96
|
*/
|
|
198
|
-
update(
|
|
97
|
+
update(patch: Partial<O>): void;
|
|
98
|
+
toImmutable(): ToImmutable<O>;
|
|
199
99
|
}
|
|
200
100
|
|
|
201
101
|
/**
|
|
@@ -218,18 +118,6 @@ declare function isJsonScalar(data: Json): data is JsonScalar;
|
|
|
218
118
|
declare function isJsonArray(data: Json): data is JsonArray;
|
|
219
119
|
declare function isJsonObject(data: Json): data is JsonObject;
|
|
220
120
|
|
|
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
121
|
/**
|
|
234
122
|
* INTERNAL
|
|
235
123
|
*/
|
|
@@ -257,6 +145,182 @@ declare type LiveNode = LiveStructure | LiveRegister<Json>;
|
|
|
257
145
|
declare type LsonObject = {
|
|
258
146
|
[key: string]: Lson | undefined;
|
|
259
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
150
|
+
*
|
|
151
|
+
* Examples:
|
|
152
|
+
*
|
|
153
|
+
* ToJson<42> // 42
|
|
154
|
+
* ToJson<'hi'> // 'hi'
|
|
155
|
+
* ToJson<number> // number
|
|
156
|
+
* ToJson<string> // string
|
|
157
|
+
* ToJson<string | LiveList<number>> // string | number[]
|
|
158
|
+
* ToJson<LiveMap<string, LiveList<number>>>
|
|
159
|
+
* // { [key: string]: number[] }
|
|
160
|
+
* ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
161
|
+
* // { a: null, b: string[], c?: number }
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
|
|
165
|
+
[K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
|
|
166
|
+
} : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
|
|
167
|
+
[K in KS]: ToJson<V>;
|
|
168
|
+
} : never;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Represents an indefinitely deep arbitrary immutable data
|
|
172
|
+
* structure, as returned by the .toImmutable().
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
declare type Immutable = Scalar | ImmutableList | ImmutableObject | ImmutableMap;
|
|
176
|
+
declare type Scalar = string | number | boolean | null;
|
|
177
|
+
declare type ImmutableList = readonly Immutable[];
|
|
178
|
+
declare type ImmutableObject = {
|
|
179
|
+
readonly [key: string]: Immutable | undefined;
|
|
180
|
+
};
|
|
181
|
+
declare type ImmutableMap = ReadonlyMap<string, Immutable>;
|
|
182
|
+
declare type ImmutableRef = Exclude<Immutable, Scalar>;
|
|
183
|
+
/**
|
|
184
|
+
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
185
|
+
*
|
|
186
|
+
* Examples:
|
|
187
|
+
*
|
|
188
|
+
* ToImmutable<42> // 42
|
|
189
|
+
* ToImmutable<'hi'> // 'hi'
|
|
190
|
+
* ToImmutable<number> // number
|
|
191
|
+
* ToImmutable<string> // string
|
|
192
|
+
* ToImmutable<string | LiveList<number>> // string | readonly number[]
|
|
193
|
+
* ToImmutable<LiveMap<string, LiveList<number>>>
|
|
194
|
+
* // { readonly [key: string]: readonly number[] }
|
|
195
|
+
* ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
196
|
+
* // { readonly a: null, readonly b: readonly string[], readonly c?: number }
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
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 ? {
|
|
200
|
+
readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
|
|
201
|
+
} : L extends Json ? L : never;
|
|
202
|
+
|
|
203
|
+
declare abstract class AbstractCrdt {
|
|
204
|
+
get roomId(): string | null;
|
|
205
|
+
/**
|
|
206
|
+
* Return an immutable snapshot of this Live node and its children.
|
|
207
|
+
*/
|
|
208
|
+
toImmutable(): Immutable;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The LiveList class represents an ordered collection of items that is synchronized across clients.
|
|
213
|
+
*/
|
|
214
|
+
declare class LiveList<TItem extends Lson> extends AbstractCrdt {
|
|
215
|
+
constructor(items?: TItem[]);
|
|
216
|
+
/**
|
|
217
|
+
* Returns the number of elements.
|
|
218
|
+
*/
|
|
219
|
+
get length(): number;
|
|
220
|
+
/**
|
|
221
|
+
* Adds one element to the end of the LiveList.
|
|
222
|
+
* @param element The element to add to the end of the LiveList.
|
|
223
|
+
*/
|
|
224
|
+
push(element: TItem): void;
|
|
225
|
+
/**
|
|
226
|
+
* Inserts one element at a specified index.
|
|
227
|
+
* @param element The element to insert.
|
|
228
|
+
* @param index The index at which you want to insert the element.
|
|
229
|
+
*/
|
|
230
|
+
insert(element: TItem, index: number): void;
|
|
231
|
+
/**
|
|
232
|
+
* Move one element from one index to another.
|
|
233
|
+
* @param index The index of the element to move
|
|
234
|
+
* @param targetIndex The index where the element should be after moving.
|
|
235
|
+
*/
|
|
236
|
+
move(index: number, targetIndex: number): void;
|
|
237
|
+
/**
|
|
238
|
+
* Deletes an element at the specified index
|
|
239
|
+
* @param index The index of the element to delete
|
|
240
|
+
*/
|
|
241
|
+
delete(index: number): void;
|
|
242
|
+
clear(): void;
|
|
243
|
+
set(index: number, item: TItem): void;
|
|
244
|
+
/**
|
|
245
|
+
* Returns an Array of all the elements in the LiveList.
|
|
246
|
+
*/
|
|
247
|
+
toArray(): TItem[];
|
|
248
|
+
/**
|
|
249
|
+
* Tests whether all elements pass the test implemented by the provided function.
|
|
250
|
+
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
|
251
|
+
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
|
|
252
|
+
*/
|
|
253
|
+
every(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Creates an array with all elements that pass the test implemented by the provided function.
|
|
256
|
+
* @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.
|
|
257
|
+
* @returns An array with the elements that pass the test.
|
|
258
|
+
*/
|
|
259
|
+
filter(predicate: (value: TItem, index: number) => unknown): TItem[];
|
|
260
|
+
/**
|
|
261
|
+
* Returns the first element that satisfies the provided testing function.
|
|
262
|
+
* @param predicate Function to execute on each value.
|
|
263
|
+
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
264
|
+
*/
|
|
265
|
+
find(predicate: (value: TItem, index: number) => unknown): TItem | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
|
|
268
|
+
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
|
|
269
|
+
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
|
|
270
|
+
*/
|
|
271
|
+
findIndex(predicate: (value: TItem, index: number) => unknown): number;
|
|
272
|
+
/**
|
|
273
|
+
* Executes a provided function once for each element.
|
|
274
|
+
* @param callbackfn Function to execute on each element.
|
|
275
|
+
*/
|
|
276
|
+
forEach(callbackfn: (value: TItem, index: number) => void): void;
|
|
277
|
+
/**
|
|
278
|
+
* Get the element at the specified index.
|
|
279
|
+
* @param index The index on the element to get.
|
|
280
|
+
* @returns The element at the specified index or undefined.
|
|
281
|
+
*/
|
|
282
|
+
get(index: number): TItem | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
285
|
+
* @param searchElement Element to locate.
|
|
286
|
+
* @param fromIndex The index to start the search at.
|
|
287
|
+
* @returns The first index of the element in the LiveList; -1 if not found.
|
|
288
|
+
*/
|
|
289
|
+
indexOf(searchElement: TItem, fromIndex?: number): number;
|
|
290
|
+
/**
|
|
291
|
+
* 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.
|
|
292
|
+
* @param searchElement Element to locate.
|
|
293
|
+
* @param fromIndex The index at which to start searching backwards.
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
lastIndexOf(searchElement: TItem, fromIndex?: number): number;
|
|
297
|
+
/**
|
|
298
|
+
* Creates an array populated with the results of calling a provided function on every element.
|
|
299
|
+
* @param callback Function that is called for every element.
|
|
300
|
+
* @returns An array with each element being the result of the callback function.
|
|
301
|
+
*/
|
|
302
|
+
map<U>(callback: (value: TItem, index: number) => U): U[];
|
|
303
|
+
/**
|
|
304
|
+
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
305
|
+
* @param predicate Function to test for each element.
|
|
306
|
+
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
|
|
307
|
+
*/
|
|
308
|
+
some(predicate: (value: TItem, index: number) => unknown): boolean;
|
|
309
|
+
[Symbol.iterator](): IterableIterator<TItem>;
|
|
310
|
+
toImmutable(): ImmutableList;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
declare type BaseUserMeta = {
|
|
314
|
+
/**
|
|
315
|
+
* The id of the user that has been set in the authentication endpoint.
|
|
316
|
+
* Useful to get additional information about the connected user.
|
|
317
|
+
*/
|
|
318
|
+
id?: string;
|
|
319
|
+
/**
|
|
320
|
+
* Additional user information that has been set in the authentication endpoint.
|
|
321
|
+
*/
|
|
322
|
+
info?: Json;
|
|
323
|
+
};
|
|
260
324
|
|
|
261
325
|
/**
|
|
262
326
|
* This helper type is effectively a no-op, but will force TypeScript to
|
|
@@ -283,15 +347,10 @@ declare type LsonObject = {
|
|
|
283
347
|
declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
|
|
284
348
|
[K in keyof T]: T[K];
|
|
285
349
|
};
|
|
286
|
-
declare type
|
|
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, }: {
|
|
350
|
+
declare type CustomEvent<TRoomEvent extends Json> = {
|
|
289
351
|
connectionId: number;
|
|
290
352
|
event: TRoomEvent;
|
|
291
|
-
}
|
|
292
|
-
declare type ErrorCallback = (error: Error) => void;
|
|
293
|
-
declare type ConnectionCallback = (state: ConnectionState) => void;
|
|
294
|
-
declare type HistoryCallback = (event: HistoryEvent) => void;
|
|
353
|
+
};
|
|
295
354
|
declare type UpdateDelta = {
|
|
296
355
|
type: "update";
|
|
297
356
|
} | {
|
|
@@ -368,21 +427,11 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
|
|
|
368
427
|
* The initial Presence to use and announce when you enter the Room. The
|
|
369
428
|
* Presence is available on all users in the Room (me & others).
|
|
370
429
|
*/
|
|
371
|
-
initialPresence
|
|
430
|
+
initialPresence: TPresence | ((roomId: string) => TPresence);
|
|
372
431
|
/**
|
|
373
432
|
* The initial Storage to use when entering a new Room.
|
|
374
433
|
*/
|
|
375
434
|
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
435
|
}>;
|
|
387
436
|
declare type Client = {
|
|
388
437
|
/**
|
|
@@ -396,34 +445,27 @@ declare type Client = {
|
|
|
396
445
|
* @param roomId The id of the room
|
|
397
446
|
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
398
447
|
*/
|
|
399
|
-
enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options
|
|
448
|
+
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
449
|
/**
|
|
401
450
|
* Leaves a room.
|
|
402
451
|
* @param roomId The id of the room
|
|
403
452
|
*/
|
|
404
453
|
leave(roomId: string): void;
|
|
405
454
|
};
|
|
406
|
-
|
|
407
|
-
* Represents all the other users connected in the room. Treated as immutable.
|
|
408
|
-
*/
|
|
409
|
-
interface Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> {
|
|
455
|
+
declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
|
|
410
456
|
/**
|
|
411
|
-
*
|
|
457
|
+
* @deprecated Prefer the normal .length property on arrays.
|
|
412
458
|
*/
|
|
413
459
|
readonly count: number;
|
|
414
460
|
/**
|
|
415
|
-
*
|
|
461
|
+
* @deprecated Calling .toArray() is no longer needed
|
|
416
462
|
*/
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
}
|
|
463
|
+
readonly toArray: () => readonly T[];
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Represents all the other users connected in the room. Treated as immutable.
|
|
467
|
+
*/
|
|
468
|
+
declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = ReadonlyArrayWithLegacyMethods<User<TPresence, TUserMeta>>;
|
|
427
469
|
/**
|
|
428
470
|
* Represents a user connected in a room. Treated as immutable.
|
|
429
471
|
*/
|
|
@@ -444,24 +486,8 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
444
486
|
/**
|
|
445
487
|
* The user presence.
|
|
446
488
|
*/
|
|
447
|
-
readonly presence
|
|
489
|
+
readonly presence: TPresence;
|
|
448
490
|
};
|
|
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
491
|
declare type AuthEndpointCallback = (room: string) => Promise<{
|
|
466
492
|
token: string;
|
|
467
493
|
}>;
|
|
@@ -494,12 +520,23 @@ declare type ClientOptions = {
|
|
|
494
520
|
authEndpoint: AuthEndpoint;
|
|
495
521
|
});
|
|
496
522
|
declare type Connection = {
|
|
497
|
-
state: "closed"
|
|
523
|
+
state: "closed";
|
|
524
|
+
} | {
|
|
525
|
+
state: "authenticating";
|
|
526
|
+
} | {
|
|
527
|
+
state: "connecting";
|
|
528
|
+
id: number;
|
|
529
|
+
userId?: string;
|
|
530
|
+
userInfo?: Json;
|
|
498
531
|
} | {
|
|
499
|
-
state: "open"
|
|
532
|
+
state: "open";
|
|
500
533
|
id: number;
|
|
501
534
|
userId?: string;
|
|
502
535
|
userInfo?: Json;
|
|
536
|
+
} | {
|
|
537
|
+
state: "unavailable";
|
|
538
|
+
} | {
|
|
539
|
+
state: "failed";
|
|
503
540
|
};
|
|
504
541
|
declare type ConnectionState = Connection["state"];
|
|
505
542
|
declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
@@ -597,6 +634,11 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
597
634
|
* The id of the room.
|
|
598
635
|
*/
|
|
599
636
|
readonly id: string;
|
|
637
|
+
/**
|
|
638
|
+
* A client is considered "self aware" if it knows its own
|
|
639
|
+
* metadata and connection ID (from the auth server).
|
|
640
|
+
*/
|
|
641
|
+
isSelfAware(): boolean;
|
|
600
642
|
getConnectionState(): ConnectionState;
|
|
601
643
|
subscribe: {
|
|
602
644
|
/**
|
|
@@ -611,7 +653,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
611
653
|
* // Do something
|
|
612
654
|
* });
|
|
613
655
|
*/
|
|
614
|
-
(type: "my-presence", listener:
|
|
656
|
+
(type: "my-presence", listener: Callback<TPresence>): () => void;
|
|
615
657
|
/**
|
|
616
658
|
* Subscribe to the other users updates.
|
|
617
659
|
*
|
|
@@ -623,8 +665,9 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
623
665
|
* room.subscribe("others", (others) => {
|
|
624
666
|
* // Do something
|
|
625
667
|
* });
|
|
668
|
+
*
|
|
626
669
|
*/
|
|
627
|
-
(type: "others", listener:
|
|
670
|
+
(type: "others", listener: (others: Others<TPresence, TUserMeta>, event: OthersEvent<TPresence, TUserMeta>) => void): () => void;
|
|
628
671
|
/**
|
|
629
672
|
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
|
|
630
673
|
*
|
|
@@ -636,20 +679,23 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
636
679
|
* room.subscribe("event", ({ event, connectionId }) => {
|
|
637
680
|
* // Do something
|
|
638
681
|
* });
|
|
682
|
+
*
|
|
639
683
|
*/
|
|
640
|
-
(type: "event", listener:
|
|
684
|
+
(type: "event", listener: Callback<CustomEvent<TRoomEvent>>): () => void;
|
|
641
685
|
/**
|
|
642
686
|
* Subscribe to errors thrown in the room.
|
|
643
687
|
*
|
|
644
688
|
* @returns Unsubscribe function.
|
|
689
|
+
*
|
|
645
690
|
*/
|
|
646
691
|
(type: "error", listener: ErrorCallback): () => void;
|
|
647
692
|
/**
|
|
648
693
|
* Subscribe to connection state updates.
|
|
649
694
|
*
|
|
650
695
|
* @returns Unsubscribe function.
|
|
696
|
+
*
|
|
651
697
|
*/
|
|
652
|
-
(type: "connection", listener:
|
|
698
|
+
(type: "connection", listener: Callback<ConnectionState>): () => void;
|
|
653
699
|
/**
|
|
654
700
|
* Subscribes to changes made on a Live structure. Returns an unsubscribe function.
|
|
655
701
|
* In a future version, we will also expose what exactly changed in the Live structure.
|
|
@@ -691,8 +737,9 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
691
737
|
* room.subscribe("history", ({ canUndo, canRedo }) => {
|
|
692
738
|
* // Do something
|
|
693
739
|
* });
|
|
740
|
+
*
|
|
694
741
|
*/
|
|
695
|
-
(type: "history", listener:
|
|
742
|
+
(type: "history", listener: Callback<HistoryEvent>): () => void;
|
|
696
743
|
};
|
|
697
744
|
/**
|
|
698
745
|
* 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 +769,8 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
722
769
|
getOthers: () => Others<TPresence, TUserMeta>;
|
|
723
770
|
/**
|
|
724
771
|
* Updates the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
|
|
725
|
-
* @param
|
|
726
|
-
* @param
|
|
772
|
+
* @param patch A partial object that contains the properties you want to update.
|
|
773
|
+
* @param options Optional object to configure the behavior of updatePresence.
|
|
727
774
|
*
|
|
728
775
|
* @example
|
|
729
776
|
* room.updatePresence({ x: 0 });
|
|
@@ -732,7 +779,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
732
779
|
* const presence = room.getPresence();
|
|
733
780
|
* // presence is equivalent to { x: 0, y: 0 }
|
|
734
781
|
*/
|
|
735
|
-
updatePresence: (
|
|
782
|
+
updatePresence: (patch: Partial<TPresence>, options?: {
|
|
736
783
|
/**
|
|
737
784
|
* Whether or not the presence should have an impact on the undo/redo history.
|
|
738
785
|
*/
|
|
@@ -764,6 +811,34 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
764
811
|
getStorage: () => Promise<{
|
|
765
812
|
root: LiveObject<TStorage>;
|
|
766
813
|
}>;
|
|
814
|
+
/**
|
|
815
|
+
* Get the room's storage synchronously.
|
|
816
|
+
* The storage's root is a {@link LiveObject}.
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* const root = room.getStorageSnapshot();
|
|
820
|
+
*/
|
|
821
|
+
getStorageSnapshot(): LiveObject<TStorage> | null;
|
|
822
|
+
events: {
|
|
823
|
+
customEvent: Observable<{
|
|
824
|
+
connectionId: number;
|
|
825
|
+
event: TRoomEvent;
|
|
826
|
+
}>;
|
|
827
|
+
me: Observable<TPresence>;
|
|
828
|
+
others: Observable<{
|
|
829
|
+
others: Others<TPresence, TUserMeta>;
|
|
830
|
+
event: OthersEvent<TPresence, TUserMeta>;
|
|
831
|
+
}>;
|
|
832
|
+
error: Observable<Error>;
|
|
833
|
+
connection: Observable<ConnectionState>;
|
|
834
|
+
storage: Observable<StorageUpdate[]>;
|
|
835
|
+
history: Observable<HistoryEvent>;
|
|
836
|
+
/**
|
|
837
|
+
* Subscribe to the storage loaded event. Will fire at most once during the
|
|
838
|
+
* lifetime of a Room.
|
|
839
|
+
*/
|
|
840
|
+
storageDidLoad: Observable<void>;
|
|
841
|
+
};
|
|
767
842
|
/**
|
|
768
843
|
* Batches modifications made during the given function.
|
|
769
844
|
* All the modifications are sent to other clients in a single message.
|
|
@@ -790,4 +865,4 @@ declare enum WebsocketCloseCodes {
|
|
|
790
865
|
CLOSE_WITHOUT_RETRY = 4999
|
|
791
866
|
}
|
|
792
867
|
|
|
793
|
-
export { BaseUserMeta as B, ClientOptions as C, History as H, Json as J, LiveList as L, Others as O,
|
|
868
|
+
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, LiveNode as m, Resolve as n, RoomInitializers as o, ToImmutable as p, isJsonArray as q, isJsonObject as r, isJsonScalar as s };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClientOptions, a as Client } from './index-
|
|
2
|
-
export { B as BaseUserMeta, d as BroadcastOptions, a as Client, H as History, J as Json,
|
|
1
|
+
import { C as ClientOptions, a as Client } from './index-4e7d8cac.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-4e7d8cac.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 };
|