@liveblocks/client 0.15.0-alpha.2 → 0.15.0

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.
Files changed (62) hide show
  1. package/lib/esm/index.js +2991 -5
  2. package/lib/esm/index.mjs +2991 -0
  3. package/lib/esm/internal.js +149 -0
  4. package/lib/esm/internal.mjs +149 -0
  5. package/lib/{esm/types.d.ts → index.d.ts} +255 -50
  6. package/lib/index.js +4237 -0
  7. package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
  8. package/lib/internal.js +193 -0
  9. package/package.json +36 -9
  10. package/lib/cjs/AbstractCrdt.d.ts +0 -67
  11. package/lib/cjs/AbstractCrdt.js +0 -95
  12. package/lib/cjs/LiveList.d.ts +0 -144
  13. package/lib/cjs/LiveList.js +0 -527
  14. package/lib/cjs/LiveMap.d.ts +0 -91
  15. package/lib/cjs/LiveMap.js +0 -322
  16. package/lib/cjs/LiveObject.d.ts +0 -80
  17. package/lib/cjs/LiveObject.js +0 -453
  18. package/lib/cjs/LiveRegister.d.ts +0 -29
  19. package/lib/cjs/LiveRegister.js +0 -88
  20. package/lib/cjs/authentication.d.ts +0 -3
  21. package/lib/cjs/authentication.js +0 -71
  22. package/lib/cjs/client.d.ts +0 -27
  23. package/lib/cjs/client.js +0 -80
  24. package/lib/cjs/immutable.d.ts +0 -9
  25. package/lib/cjs/immutable.js +0 -291
  26. package/lib/cjs/index.d.ts +0 -6
  27. package/lib/cjs/index.js +0 -18
  28. package/lib/cjs/live.d.ts +0 -181
  29. package/lib/cjs/live.js +0 -49
  30. package/lib/cjs/position.d.ts +0 -6
  31. package/lib/cjs/position.js +0 -113
  32. package/lib/cjs/room.d.ts +0 -159
  33. package/lib/cjs/room.js +0 -1094
  34. package/lib/cjs/types.d.ts +0 -489
  35. package/lib/cjs/types.js +0 -2
  36. package/lib/cjs/utils.d.ts +0 -11
  37. package/lib/cjs/utils.js +0 -175
  38. package/lib/esm/AbstractCrdt.d.ts +0 -67
  39. package/lib/esm/AbstractCrdt.js +0 -91
  40. package/lib/esm/LiveList.d.ts +0 -144
  41. package/lib/esm/LiveList.js +0 -523
  42. package/lib/esm/LiveMap.d.ts +0 -91
  43. package/lib/esm/LiveMap.js +0 -318
  44. package/lib/esm/LiveObject.d.ts +0 -80
  45. package/lib/esm/LiveObject.js +0 -449
  46. package/lib/esm/LiveRegister.d.ts +0 -29
  47. package/lib/esm/LiveRegister.js +0 -84
  48. package/lib/esm/authentication.d.ts +0 -3
  49. package/lib/esm/authentication.js +0 -66
  50. package/lib/esm/client.d.ts +0 -27
  51. package/lib/esm/client.js +0 -76
  52. package/lib/esm/immutable.d.ts +0 -9
  53. package/lib/esm/immutable.js +0 -282
  54. package/lib/esm/index.d.ts +0 -6
  55. package/lib/esm/live.js +0 -46
  56. package/lib/esm/position.d.ts +0 -6
  57. package/lib/esm/position.js +0 -106
  58. package/lib/esm/room.d.ts +0 -159
  59. package/lib/esm/room.js +0 -1069
  60. package/lib/esm/types.js +0 -1
  61. package/lib/esm/utils.d.ts +0 -11
  62. package/lib/esm/utils.js +0 -164
@@ -1,91 +0,0 @@
1
- import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { Op, SerializedCrdtWithId, SerializedCrdt } from "./live";
3
- /**
4
- * The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
5
- * Keys should be a string, and values should be serializable to JSON.
6
- * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
7
- */
8
- export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
9
- #private;
10
- constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
11
- /**
12
- * INTERNAL
13
- */
14
- _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
15
- /**
16
- * INTERNAL
17
- */
18
- static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveMap<string, unknown>;
19
- /**
20
- * INTERNAL
21
- */
22
- _attach(id: string, doc: Doc): void;
23
- /**
24
- * INTERNAL
25
- */
26
- _attachChild(id: string, key: TKey, child: AbstractCrdt, isLocal: boolean): ApplyResult;
27
- /**
28
- * INTERNAL
29
- */
30
- _detach(): void;
31
- /**
32
- * INTERNAL
33
- */
34
- _detachChild(child: AbstractCrdt): ApplyResult;
35
- /**
36
- * INTERNAL
37
- */
38
- _getType(): string;
39
- /**
40
- * INTERNAL
41
- */
42
- _toSerializedCrdt(): SerializedCrdt;
43
- /**
44
- * Returns a specified element from the LiveMap.
45
- * @param key The key of the element to return.
46
- * @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
47
- */
48
- get(key: TKey): TValue | undefined;
49
- /**
50
- * Adds or updates an element with a specified key and a value.
51
- * @param key The key of the element to add. Should be a string.
52
- * @param value The value of the element to add. Should be serializable to JSON.
53
- */
54
- set(key: TKey, value: TValue): void;
55
- /**
56
- * Returns the number of elements in the LiveMap.
57
- */
58
- get size(): number;
59
- /**
60
- * Returns a boolean indicating whether an element with the specified key exists or not.
61
- * @param key The key of the element to test for presence.
62
- */
63
- has(key: TKey): boolean;
64
- /**
65
- * Removes the specified element by key.
66
- * @param key The key of the element to remove.
67
- * @returns true if an element existed and has been removed, or false if the element does not exist.
68
- */
69
- delete(key: TKey): boolean;
70
- /**
71
- * Returns a new Iterator object that contains the [key, value] pairs for each element.
72
- */
73
- entries(): IterableIterator<[string, TValue]>;
74
- /**
75
- * Same function object as the initial value of the entries method.
76
- */
77
- [Symbol.iterator](): IterableIterator<[string, TValue]>;
78
- /**
79
- * Returns a new Iterator object that contains the keys for each element.
80
- */
81
- keys(): IterableIterator<TKey>;
82
- /**
83
- * Returns a new Iterator object that contains the values for each element.
84
- */
85
- values(): IterableIterator<TValue>;
86
- /**
87
- * Executes a provided function once per each key/value pair in the Map object, in insertion order.
88
- * @param callback Function to execute for each entry in the map.
89
- */
90
- forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
91
- }
@@ -1,322 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _LiveMap_map;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.LiveMap = void 0;
16
- const AbstractCrdt_1 = require("./AbstractCrdt");
17
- const utils_1 = require("./utils");
18
- const live_1 = require("./live");
19
- /**
20
- * The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
21
- * Keys should be a string, and values should be serializable to JSON.
22
- * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
23
- */
24
- class LiveMap extends AbstractCrdt_1.AbstractCrdt {
25
- constructor(entries) {
26
- super();
27
- _LiveMap_map.set(this, void 0);
28
- if (entries) {
29
- const mappedEntries = [];
30
- for (const entry of entries) {
31
- const value = (0, utils_1.selfOrRegister)(entry[1]);
32
- value._setParentLink(this, entry[0]);
33
- mappedEntries.push([entry[0], value]);
34
- }
35
- __classPrivateFieldSet(this, _LiveMap_map, new Map(mappedEntries), "f");
36
- }
37
- else {
38
- __classPrivateFieldSet(this, _LiveMap_map, new Map(), "f");
39
- }
40
- }
41
- /**
42
- * INTERNAL
43
- */
44
- _serialize(parentId, parentKey, doc) {
45
- if (this._id == null) {
46
- throw new Error("Cannot serialize item is not attached");
47
- }
48
- if (parentId == null || parentKey == null) {
49
- throw new Error("Cannot serialize map if parentId or parentKey is undefined");
50
- }
51
- const ops = [];
52
- const op = {
53
- id: this._id,
54
- opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
55
- type: live_1.OpType.CreateMap,
56
- parentId,
57
- parentKey,
58
- };
59
- ops.push(op);
60
- for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
61
- ops.push(...value._serialize(this._id, key, doc));
62
- }
63
- return ops;
64
- }
65
- /**
66
- * INTERNAL
67
- */
68
- static _deserialize([id, item], parentToChildren, doc) {
69
- if (item.type !== live_1.CrdtType.Map) {
70
- throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
71
- }
72
- const map = new LiveMap();
73
- map._attach(id, doc);
74
- const children = parentToChildren.get(id);
75
- if (children == null) {
76
- return map;
77
- }
78
- for (const entry of children) {
79
- const crdt = entry[1];
80
- if (crdt.parentKey == null) {
81
- throw new Error("Tried to deserialize a crdt but it does not have a parentKey and is not the root");
82
- }
83
- const child = (0, utils_1.deserialize)(entry, parentToChildren, doc);
84
- child._setParentLink(map, crdt.parentKey);
85
- __classPrivateFieldGet(map, _LiveMap_map, "f").set(crdt.parentKey, child);
86
- }
87
- return map;
88
- }
89
- /**
90
- * INTERNAL
91
- */
92
- _attach(id, doc) {
93
- super._attach(id, doc);
94
- for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
95
- if ((0, utils_1.isCrdt)(value)) {
96
- value._attach(doc.generateId(), doc);
97
- }
98
- }
99
- }
100
- /**
101
- * INTERNAL
102
- */
103
- _attachChild(id, key, child, isLocal) {
104
- if (this._doc == null) {
105
- throw new Error("Can't attach child if doc is not present");
106
- }
107
- const previousValue = __classPrivateFieldGet(this, _LiveMap_map, "f").get(key);
108
- let reverse;
109
- if (previousValue) {
110
- reverse = previousValue._serialize(this._id, key);
111
- previousValue._detach();
112
- }
113
- else {
114
- reverse = [{ type: live_1.OpType.DeleteCrdt, id }];
115
- }
116
- child._setParentLink(this, key);
117
- child._attach(id, this._doc);
118
- __classPrivateFieldGet(this, _LiveMap_map, "f").set(key, child);
119
- return {
120
- modified: {
121
- node: this,
122
- type: "LiveMap",
123
- updates: { [key]: { type: "update" } },
124
- },
125
- reverse,
126
- };
127
- }
128
- /**
129
- * INTERNAL
130
- */
131
- _detach() {
132
- super._detach();
133
- for (const item of __classPrivateFieldGet(this, _LiveMap_map, "f").values()) {
134
- item._detach();
135
- }
136
- }
137
- /**
138
- * INTERNAL
139
- */
140
- _detachChild(child) {
141
- const reverse = child._serialize(this._id, child._parentKey, this._doc);
142
- for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
143
- if (value === child) {
144
- __classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
145
- }
146
- }
147
- child._detach();
148
- const storageUpdate = {
149
- node: this,
150
- type: "LiveMap",
151
- updates: { [child._parentKey]: { type: "delete" } },
152
- };
153
- return { modified: storageUpdate, reverse };
154
- }
155
- /**
156
- * INTERNAL
157
- */
158
- _getType() {
159
- return "LiveMap";
160
- }
161
- /**
162
- * INTERNAL
163
- */
164
- _toSerializedCrdt() {
165
- var _a;
166
- return {
167
- type: live_1.CrdtType.Map,
168
- parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
169
- parentKey: this._parentKey,
170
- };
171
- }
172
- /**
173
- * Returns a specified element from the LiveMap.
174
- * @param key The key of the element to return.
175
- * @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
176
- */
177
- get(key) {
178
- const value = __classPrivateFieldGet(this, _LiveMap_map, "f").get(key);
179
- if (value == undefined) {
180
- return undefined;
181
- }
182
- return (0, utils_1.selfOrRegisterValue)(value);
183
- }
184
- /**
185
- * Adds or updates an element with a specified key and a value.
186
- * @param key The key of the element to add. Should be a string.
187
- * @param value The value of the element to add. Should be serializable to JSON.
188
- */
189
- set(key, value) {
190
- const oldValue = __classPrivateFieldGet(this, _LiveMap_map, "f").get(key);
191
- if (oldValue) {
192
- oldValue._detach();
193
- }
194
- const item = (0, utils_1.selfOrRegister)(value);
195
- item._setParentLink(this, key);
196
- __classPrivateFieldGet(this, _LiveMap_map, "f").set(key, item);
197
- if (this._doc && this._id) {
198
- const id = this._doc.generateId();
199
- item._attach(id, this._doc);
200
- const storageUpdates = new Map();
201
- storageUpdates.set(this._id, {
202
- node: this,
203
- type: "LiveMap",
204
- updates: { [key]: { type: "update" } },
205
- });
206
- this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue
207
- ? oldValue._serialize(this._id, key)
208
- : [{ type: live_1.OpType.DeleteCrdt, id }], storageUpdates);
209
- }
210
- }
211
- /**
212
- * Returns the number of elements in the LiveMap.
213
- */
214
- get size() {
215
- return __classPrivateFieldGet(this, _LiveMap_map, "f").size;
216
- }
217
- /**
218
- * Returns a boolean indicating whether an element with the specified key exists or not.
219
- * @param key The key of the element to test for presence.
220
- */
221
- has(key) {
222
- return __classPrivateFieldGet(this, _LiveMap_map, "f").has(key);
223
- }
224
- /**
225
- * Removes the specified element by key.
226
- * @param key The key of the element to remove.
227
- * @returns true if an element existed and has been removed, or false if the element does not exist.
228
- */
229
- delete(key) {
230
- const item = __classPrivateFieldGet(this, _LiveMap_map, "f").get(key);
231
- if (item == null) {
232
- return false;
233
- }
234
- item._detach();
235
- if (this._doc && item._id) {
236
- const storageUpdates = new Map();
237
- storageUpdates.set(this._id, {
238
- node: this,
239
- type: "LiveMap",
240
- updates: { [key]: { type: "delete" } },
241
- });
242
- this._doc.dispatch([
243
- {
244
- type: live_1.OpType.DeleteCrdt,
245
- id: item._id,
246
- opId: this._doc.generateOpId(),
247
- },
248
- ], item._serialize(this._id, key), storageUpdates);
249
- }
250
- __classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
251
- return true;
252
- }
253
- /**
254
- * Returns a new Iterator object that contains the [key, value] pairs for each element.
255
- */
256
- entries() {
257
- const innerIterator = __classPrivateFieldGet(this, _LiveMap_map, "f").entries();
258
- return {
259
- [Symbol.iterator]: function () {
260
- return this;
261
- },
262
- next() {
263
- const iteratorValue = innerIterator.next();
264
- if (iteratorValue.done) {
265
- return {
266
- done: true,
267
- value: undefined,
268
- };
269
- }
270
- const entry = iteratorValue.value;
271
- return {
272
- value: [entry[0], (0, utils_1.selfOrRegisterValue)(iteratorValue.value[1])],
273
- };
274
- },
275
- };
276
- }
277
- /**
278
- * Same function object as the initial value of the entries method.
279
- */
280
- [(_LiveMap_map = new WeakMap(), Symbol.iterator)]() {
281
- return this.entries();
282
- }
283
- /**
284
- * Returns a new Iterator object that contains the keys for each element.
285
- */
286
- keys() {
287
- return __classPrivateFieldGet(this, _LiveMap_map, "f").keys();
288
- }
289
- /**
290
- * Returns a new Iterator object that contains the values for each element.
291
- */
292
- values() {
293
- const innerIterator = __classPrivateFieldGet(this, _LiveMap_map, "f").values();
294
- return {
295
- [Symbol.iterator]: function () {
296
- return this;
297
- },
298
- next() {
299
- const iteratorValue = innerIterator.next();
300
- if (iteratorValue.done) {
301
- return {
302
- done: true,
303
- value: undefined,
304
- };
305
- }
306
- return {
307
- value: (0, utils_1.selfOrRegisterValue)(iteratorValue.value),
308
- };
309
- },
310
- };
311
- }
312
- /**
313
- * Executes a provided function once per each key/value pair in the Map object, in insertion order.
314
- * @param callback Function to execute for each entry in the map.
315
- */
316
- forEach(callback) {
317
- for (const entry of this) {
318
- callback(entry[1], entry[0], this);
319
- }
320
- }
321
- }
322
- exports.LiveMap = LiveMap;
@@ -1,80 +0,0 @@
1
- import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { Op, SerializedCrdt, SerializedCrdtWithId } from "./live";
3
- /**
4
- * The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
5
- * Keys should be a string, and values should be serializable to JSON.
6
- * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
7
- */
8
- export declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
9
- #private;
10
- constructor(object?: T);
11
- /**
12
- * INTERNAL
13
- */
14
- _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
15
- /**
16
- * INTERNAL
17
- */
18
- static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<Record<string, any>>;
19
- /**
20
- * INTERNAL
21
- */
22
- static _deserializeChildren(object: LiveObject, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<Record<string, any>>;
23
- /**
24
- * INTERNAL
25
- */
26
- _attach(id: string, doc: Doc): void;
27
- /**
28
- * INTERNAL
29
- */
30
- _attachChild(id: string, key: keyof T, child: AbstractCrdt, isLocal: boolean): ApplyResult;
31
- /**
32
- * INTERNAL
33
- */
34
- _detachChild(child: AbstractCrdt): ApplyResult;
35
- /**
36
- * INTERNAL
37
- */
38
- _detachChildren(): void;
39
- /**
40
- * INTERNAL
41
- */
42
- _detach(): void;
43
- /**
44
- * INTERNAL
45
- */
46
- _apply(op: Op, isLocal: boolean): ApplyResult;
47
- /**
48
- * INTERNAL
49
- */
50
- _toSerializedCrdt(): SerializedCrdt;
51
- /**
52
- * INTERNAL
53
- */
54
- _getType(): string;
55
- /**
56
- * Transform the LiveObject into a javascript object
57
- */
58
- toObject(): T;
59
- /**
60
- * Adds or updates a property with a specified key and a value.
61
- * @param key The key of the property to add
62
- * @param value The value of the property to add
63
- */
64
- set<TKey extends keyof T>(key: TKey, value: T[TKey]): void;
65
- /**
66
- * Returns a specified property from the LiveObject.
67
- * @param key The key of the property to get
68
- */
69
- get<TKey extends keyof T>(key: TKey): T[TKey];
70
- /**
71
- * Deletes a key from the LiveObject
72
- * @param key The key of the property to delete
73
- */
74
- delete(key: keyof T): void;
75
- /**
76
- * Adds or updates multiple properties at once with an object.
77
- * @param overrides The object used to overrides properties
78
- */
79
- update(overrides: Partial<T>): void;
80
- }