@liveblocks/client 0.12.0-beta.8 → 0.12.2
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/README.md +2 -12
- package/lib/cjs/authentication.d.ts +1 -1
- package/lib/cjs/authentication.js +4 -3
- package/lib/cjs/doc.d.ts +182 -11
- package/lib/cjs/doc.js +513 -198
- package/lib/cjs/live.d.ts +1 -0
- package/lib/cjs/position.d.ts +1 -5
- package/lib/cjs/position.js +4 -4
- package/lib/cjs/room.d.ts +3 -0
- package/lib/cjs/room.js +22 -3
- package/lib/cjs/storage.d.ts +2 -0
- package/lib/cjs/storage.js +14 -8
- package/lib/cjs/types.d.ts +13 -6
- package/lib/esm/authentication.d.ts +1 -1
- package/lib/esm/authentication.js +4 -3
- package/lib/esm/doc.d.ts +182 -11
- package/lib/esm/doc.js +513 -198
- package/lib/esm/live.d.ts +1 -0
- package/lib/esm/position.d.ts +1 -5
- package/lib/esm/position.js +4 -4
- package/lib/esm/room.d.ts +3 -0
- package/lib/esm/room.js +22 -3
- package/lib/esm/storage.d.ts +2 -0
- package/lib/esm/storage.js +14 -8
- package/lib/esm/types.d.ts +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,16 +12,6 @@ Liveblocks helps you create performant and reliable collaborative experiences.
|
|
|
12
12
|
|
|
13
13
|
## Examples
|
|
14
14
|
|
|
15
|
-
Try it live on [liveblocks.io](https://liveblocks.io/examples)
|
|
15
|
+
Try it live on [liveblocks.io](https://liveblocks.io/examples).
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Clone this [github repository](https://github.com/liveblocks/next-js-examples) or try it directly on [CodeSandbox](https://codesandbox.io/s/github/liveblocks/next-js-examples?file=/pages/presence.tsx)
|
|
20
|
-
|
|
21
|
-
### Nuxt.js
|
|
22
|
-
|
|
23
|
-
Clone this [github repository](https://github.com/liveblocks/nuxt-js-examples) or try it directly on [CodeSandbox](https://codesandbox.io/s/github/liveblocks/nuxt-js-examples?file=/pages/presence.vue)
|
|
24
|
-
|
|
25
|
-
### Vanilla JavaScript + Express.js
|
|
26
|
-
|
|
27
|
-
Clone this [github repository](https://github.com/liveblocks/javascript-examples)
|
|
17
|
+
Clone one of our [examples](https://github.com/liveblocks/liveblocks/tree/main/examples).
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AuthEndpoint, AuthenticationToken } from "./types";
|
|
2
|
-
export default function auth(endpoint: AuthEndpoint, room: string): Promise<string>;
|
|
2
|
+
export default function auth(endpoint: AuthEndpoint, room: string, publicApiKey?: string): Promise<string>;
|
|
3
3
|
export declare function parseToken(token: string): AuthenticationToken;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.parseToken = void 0;
|
|
13
|
-
function fetchAuthorize(endpoint, room) {
|
|
13
|
+
function fetchAuthorize(endpoint, room, publicApiKey) {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const res = yield fetch(endpoint, {
|
|
16
16
|
method: "POST",
|
|
@@ -19,6 +19,7 @@ function fetchAuthorize(endpoint, room) {
|
|
|
19
19
|
},
|
|
20
20
|
body: JSON.stringify({
|
|
21
21
|
room,
|
|
22
|
+
publicApiKey,
|
|
22
23
|
}),
|
|
23
24
|
});
|
|
24
25
|
if (!res.ok) {
|
|
@@ -37,10 +38,10 @@ function fetchAuthorize(endpoint, room) {
|
|
|
37
38
|
return authResponse.token;
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
function auth(endpoint, room) {
|
|
41
|
+
function auth(endpoint, room, publicApiKey) {
|
|
41
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
43
|
if (typeof endpoint === "string") {
|
|
43
|
-
return fetchAuthorize(endpoint, room);
|
|
44
|
+
return fetchAuthorize(endpoint, room, publicApiKey);
|
|
44
45
|
}
|
|
45
46
|
if (typeof endpoint === "function") {
|
|
46
47
|
const { token } = yield endpoint(room);
|
package/lib/cjs/doc.d.ts
CHANGED
|
@@ -9,10 +9,14 @@ export declare class Doc<T extends Record<string, any> = Record<string, any>> {
|
|
|
9
9
|
addItem(id: string, item: AbstractCrdt): void;
|
|
10
10
|
deleteItem(id: string): void;
|
|
11
11
|
getItem(id: string): AbstractCrdt | undefined;
|
|
12
|
-
apply(
|
|
12
|
+
apply(ops: Op[]): Op[];
|
|
13
13
|
get root(): LiveObject<T>;
|
|
14
|
+
addToUndoStack(ops: Op[]): void;
|
|
15
|
+
undo(): void;
|
|
16
|
+
redo(): void;
|
|
14
17
|
count(): number;
|
|
15
18
|
generateId(): string;
|
|
19
|
+
generateOpId(): string;
|
|
16
20
|
}
|
|
17
21
|
declare abstract class AbstractCrdt {
|
|
18
22
|
#private;
|
|
@@ -31,24 +35,49 @@ declare abstract class AbstractCrdt {
|
|
|
31
35
|
/**
|
|
32
36
|
* INTERNAL
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
get _parentKey(): string | undefined;
|
|
39
|
+
_apply(op: Op): Op[];
|
|
40
|
+
/**
|
|
41
|
+
* INTERNAL
|
|
42
|
+
*/
|
|
43
|
+
_setParentLink(parent: AbstractCrdt, key: string): void;
|
|
35
44
|
/**
|
|
36
45
|
* INTERNAL
|
|
37
46
|
*/
|
|
38
47
|
_attach(id: string, doc: Doc): void;
|
|
39
|
-
abstract _attachChild(id: string, key: string, crdt: AbstractCrdt):
|
|
48
|
+
abstract _attachChild(id: string, key: string, crdt: AbstractCrdt): Op[];
|
|
40
49
|
/**
|
|
41
50
|
* INTERNAL
|
|
42
51
|
*/
|
|
43
52
|
_detach(): void;
|
|
44
53
|
abstract _detachChild(crdt: AbstractCrdt): void;
|
|
54
|
+
/**
|
|
55
|
+
* Subscribes to updates.
|
|
56
|
+
*/
|
|
45
57
|
subscribe(listener: () => void): void;
|
|
58
|
+
/**
|
|
59
|
+
* Subscribes to updates and children updates.
|
|
60
|
+
*/
|
|
46
61
|
subscribeDeep(listener: () => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Unsubscribes to updates.
|
|
64
|
+
*/
|
|
47
65
|
unsubscribe(listener: () => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* Unsubscribes to updates and children updates.
|
|
68
|
+
*/
|
|
48
69
|
unsubscribeDeep(listener: () => void): void;
|
|
49
|
-
|
|
70
|
+
/**
|
|
71
|
+
* INTERNAL
|
|
72
|
+
*/
|
|
73
|
+
_notify(onlyDeep?: boolean): void;
|
|
50
74
|
abstract _serialize(parentId: string, parentKey: string): Op[];
|
|
51
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
|
|
78
|
+
* Keys should be a string, and values should be serializable to JSON.
|
|
79
|
+
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
80
|
+
*/
|
|
52
81
|
export declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
|
|
53
82
|
#private;
|
|
54
83
|
constructor(object?: T);
|
|
@@ -69,7 +98,7 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
69
98
|
/**
|
|
70
99
|
* INTERNAL
|
|
71
100
|
*/
|
|
72
|
-
_attachChild(id: string, key: keyof T, child: AbstractCrdt):
|
|
101
|
+
_attachChild(id: string, key: keyof T, child: AbstractCrdt): Op[];
|
|
73
102
|
/**
|
|
74
103
|
* INTERNAL
|
|
75
104
|
*/
|
|
@@ -81,12 +110,33 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
81
110
|
/**
|
|
82
111
|
* INTERNAL
|
|
83
112
|
*/
|
|
84
|
-
_apply(op: Op):
|
|
113
|
+
_apply(op: Op): Op[];
|
|
114
|
+
/**
|
|
115
|
+
* Transform the LiveObject into a javascript object
|
|
116
|
+
*/
|
|
85
117
|
toObject(): T;
|
|
118
|
+
/**
|
|
119
|
+
* Adds or updates a property with a specified key and a value.
|
|
120
|
+
* @param key The key of the property to add
|
|
121
|
+
* @param value The value of the property to add
|
|
122
|
+
*/
|
|
86
123
|
set<TKey extends keyof T>(key: TKey, value: T[TKey]): void;
|
|
124
|
+
/**
|
|
125
|
+
* Returns a specified property from the LiveObject.
|
|
126
|
+
* @param key The key of the property to get
|
|
127
|
+
*/
|
|
87
128
|
get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
129
|
+
/**
|
|
130
|
+
* Adds or updates multiple properties at once with an object.
|
|
131
|
+
* @param overrides The object used to overrides properties
|
|
132
|
+
*/
|
|
88
133
|
update(overrides: Partial<T>): void;
|
|
89
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
137
|
+
* Keys should be a string, and values should be serializable to JSON.
|
|
138
|
+
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
139
|
+
*/
|
|
90
140
|
export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
91
141
|
#private;
|
|
92
142
|
constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
|
|
@@ -105,7 +155,7 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
|
105
155
|
/**
|
|
106
156
|
* INTERNAL
|
|
107
157
|
*/
|
|
108
|
-
_attachChild(id: string, key: TKey, child: AbstractCrdt):
|
|
158
|
+
_attachChild(id: string, key: TKey, child: AbstractCrdt): Op[];
|
|
109
159
|
/**
|
|
110
160
|
* INTERNAL
|
|
111
161
|
*/
|
|
@@ -114,17 +164,58 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
|
114
164
|
* INTERNAL
|
|
115
165
|
*/
|
|
116
166
|
_detachChild(child: AbstractCrdt): void;
|
|
167
|
+
/**
|
|
168
|
+
* Returns a specified element from the LiveMap.
|
|
169
|
+
* @param key The key of the element to return.
|
|
170
|
+
* @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
|
|
171
|
+
*/
|
|
117
172
|
get(key: TKey): TValue | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Adds or updates an element with a specified key and a value.
|
|
175
|
+
* @param key The key of the element to add. Should be a string.
|
|
176
|
+
* @param value The value of the element to add. Should be serializable to JSON.
|
|
177
|
+
*/
|
|
118
178
|
set(key: TKey, value: TValue): void;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the number of elements in the LiveMap.
|
|
181
|
+
*/
|
|
119
182
|
get size(): number;
|
|
183
|
+
/**
|
|
184
|
+
* Returns a boolean indicating whether an element with the specified key exists or not.
|
|
185
|
+
* @param key The key of the element to test for presence.
|
|
186
|
+
*/
|
|
120
187
|
has(key: TKey): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Removes the specified element by key.
|
|
190
|
+
* @param key The key of the element to remove.
|
|
191
|
+
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
192
|
+
*/
|
|
121
193
|
delete(key: TKey): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Returns a new Iterator object that contains the [key, value] pairs for each element.
|
|
196
|
+
*/
|
|
122
197
|
entries(): IterableIterator<[string, TValue]>;
|
|
198
|
+
/**
|
|
199
|
+
* Same function object as the initial value of the entries method.
|
|
200
|
+
*/
|
|
123
201
|
[Symbol.iterator](): IterableIterator<[string, TValue]>;
|
|
202
|
+
/**
|
|
203
|
+
* Returns a new Iterator object that contains the keys for each element.
|
|
204
|
+
*/
|
|
124
205
|
keys(): IterableIterator<TKey>;
|
|
206
|
+
/**
|
|
207
|
+
* Returns a new Iterator object that contains the values for each element.
|
|
208
|
+
*/
|
|
125
209
|
values(): IterableIterator<TValue>;
|
|
210
|
+
/**
|
|
211
|
+
* Executes a provided function once per each key/value pair in the Map object, in insertion order.
|
|
212
|
+
* @param callback Function to execute for each entry in the map.
|
|
213
|
+
*/
|
|
126
214
|
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
|
|
127
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* The LiveList class represents an ordered collection of items that is synchorinized across clients.
|
|
218
|
+
*/
|
|
128
219
|
export declare class LiveList<T> extends AbstractCrdt {
|
|
129
220
|
#private;
|
|
130
221
|
constructor(items?: T[]);
|
|
@@ -147,7 +238,7 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
147
238
|
/**
|
|
148
239
|
* INTERNAL
|
|
149
240
|
*/
|
|
150
|
-
_attachChild(id: string, key: string, child: AbstractCrdt):
|
|
241
|
+
_attachChild(id: string, key: string, child: AbstractCrdt): Op[];
|
|
151
242
|
/**
|
|
152
243
|
* INTERNAL
|
|
153
244
|
*/
|
|
@@ -156,20 +247,100 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
156
247
|
* INTERNAL
|
|
157
248
|
*/
|
|
158
249
|
_setChildKey(key: string, child: AbstractCrdt): void;
|
|
159
|
-
|
|
160
|
-
|
|
250
|
+
/**
|
|
251
|
+
* INTERNAL
|
|
252
|
+
*/
|
|
253
|
+
_apply(op: Op): Op[];
|
|
254
|
+
/**
|
|
255
|
+
* Returns the number of elements.
|
|
256
|
+
*/
|
|
257
|
+
get length(): number;
|
|
258
|
+
/**
|
|
259
|
+
* Adds one element to the end of the LiveList.
|
|
260
|
+
* @param element The element to add to the end of the LiveList.
|
|
261
|
+
*/
|
|
262
|
+
push(element: T): void;
|
|
263
|
+
/**
|
|
264
|
+
* Inserts one element at a specified index.
|
|
265
|
+
* @param element The element to insert.
|
|
266
|
+
* @param index The index at which you want to insert the element.
|
|
267
|
+
*/
|
|
268
|
+
insert(element: T, index: number): void;
|
|
269
|
+
/**
|
|
270
|
+
* Move one element from one index to another.
|
|
271
|
+
* @param index The index of the element to move
|
|
272
|
+
* @param targetIndex The index where the element should be after moving.
|
|
273
|
+
*/
|
|
161
274
|
move(index: number, targetIndex: number): void;
|
|
275
|
+
/**
|
|
276
|
+
* Deletes an element at the specified index
|
|
277
|
+
* @param index The index of the element to delete
|
|
278
|
+
*/
|
|
162
279
|
delete(index: number): void;
|
|
280
|
+
/**
|
|
281
|
+
* Returns an Array of all the elements in the LiveList.
|
|
282
|
+
*/
|
|
163
283
|
toArray(): T[];
|
|
284
|
+
/**
|
|
285
|
+
* Tests whether all elements pass the test implemented by the provided function.
|
|
286
|
+
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
|
287
|
+
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
|
|
288
|
+
*/
|
|
164
289
|
every(predicate: (value: T, index: number) => unknown): boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Creates an array with all elements that pass the test implemented by the provided function.
|
|
292
|
+
* @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.
|
|
293
|
+
* @returns An array with the elements that pass the test.
|
|
294
|
+
*/
|
|
165
295
|
filter(predicate: (value: T, index: number) => unknown): T[];
|
|
296
|
+
/**
|
|
297
|
+
* Returns the first element that satisfies the provided testing function.
|
|
298
|
+
* @param predicate Function to execute on each value.
|
|
299
|
+
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
300
|
+
*/
|
|
166
301
|
find(predicate: (value: T, index: number) => unknown): T | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
|
|
304
|
+
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
|
|
305
|
+
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
|
|
306
|
+
*/
|
|
167
307
|
findIndex(predicate: (value: T, index: number) => unknown): number;
|
|
308
|
+
/**
|
|
309
|
+
* Executes a provided function once for each element.
|
|
310
|
+
* @param callbackfn Function to execute on each element.
|
|
311
|
+
*/
|
|
168
312
|
forEach(callbackfn: (value: T, index: number) => void): void;
|
|
169
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Get the element at the specified index.
|
|
315
|
+
* @param index The index on the element to get.
|
|
316
|
+
* @returns The element at the specified index or undefined.
|
|
317
|
+
*/
|
|
318
|
+
get(index: number): T | undefined;
|
|
319
|
+
/**
|
|
320
|
+
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
321
|
+
* @param searchElement Element to locate.
|
|
322
|
+
* @param fromIndex The index to start the search at.
|
|
323
|
+
* @returns The first index of the element in the LiveList; -1 if not found.
|
|
324
|
+
*/
|
|
170
325
|
indexOf(searchElement: T, fromIndex?: number): number;
|
|
326
|
+
/**
|
|
327
|
+
* 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.
|
|
328
|
+
* @param searchElement Element to locate.
|
|
329
|
+
* @param fromIndex The index at which to start searching backwards.
|
|
330
|
+
* @returns
|
|
331
|
+
*/
|
|
171
332
|
lastIndexOf(searchElement: T, fromIndex?: number): number;
|
|
333
|
+
/**
|
|
334
|
+
* Creates an array populated with the results of calling a provided function on every element.
|
|
335
|
+
* @param callback Function that is called for every element.
|
|
336
|
+
* @returns An array with each element being the result of the callback function.
|
|
337
|
+
*/
|
|
172
338
|
map<U>(callback: (value: T, index: number) => U): U[];
|
|
339
|
+
/**
|
|
340
|
+
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
341
|
+
* @param predicate Function to test for each element.
|
|
342
|
+
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
|
|
343
|
+
*/
|
|
173
344
|
some(predicate: (value: T, index: number) => unknown): boolean;
|
|
174
345
|
[Symbol.iterator](): IterableIterator<T>;
|
|
175
346
|
}
|