@liveblocks/client 0.15.0-alpha.3 → 0.15.1

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 (59) hide show
  1. package/README.md +5 -10
  2. package/lib/esm/index.js +2991 -5
  3. package/lib/esm/index.mjs +2991 -0
  4. package/lib/esm/internal.js +149 -0
  5. package/lib/esm/internal.mjs +149 -0
  6. package/lib/{esm/types.d.ts → index.d.ts} +253 -61
  7. package/lib/index.js +4237 -0
  8. package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
  9. package/lib/internal.js +193 -0
  10. package/package.json +32 -10
  11. package/lib/cjs/AbstractCrdt.d.ts +0 -68
  12. package/lib/cjs/AbstractCrdt.js +0 -95
  13. package/lib/cjs/LiveList.d.ts +0 -144
  14. package/lib/cjs/LiveList.js +0 -530
  15. package/lib/cjs/LiveMap.d.ts +0 -91
  16. package/lib/cjs/LiveMap.js +0 -325
  17. package/lib/cjs/LiveObject.d.ts +0 -80
  18. package/lib/cjs/LiveObject.js +0 -485
  19. package/lib/cjs/LiveRegister.d.ts +0 -29
  20. package/lib/cjs/LiveRegister.js +0 -88
  21. package/lib/cjs/client.d.ts +0 -27
  22. package/lib/cjs/client.js +0 -123
  23. package/lib/cjs/immutable.d.ts +0 -9
  24. package/lib/cjs/immutable.js +0 -299
  25. package/lib/cjs/index.d.ts +0 -6
  26. package/lib/cjs/index.js +0 -18
  27. package/lib/cjs/live.d.ts +0 -181
  28. package/lib/cjs/live.js +0 -49
  29. package/lib/cjs/position.d.ts +0 -6
  30. package/lib/cjs/position.js +0 -113
  31. package/lib/cjs/room.d.ts +0 -159
  32. package/lib/cjs/room.js +0 -1129
  33. package/lib/cjs/types.d.ts +0 -502
  34. package/lib/cjs/types.js +0 -2
  35. package/lib/cjs/utils.d.ts +0 -15
  36. package/lib/cjs/utils.js +0 -225
  37. package/lib/esm/AbstractCrdt.d.ts +0 -68
  38. package/lib/esm/AbstractCrdt.js +0 -91
  39. package/lib/esm/LiveList.d.ts +0 -144
  40. package/lib/esm/LiveList.js +0 -526
  41. package/lib/esm/LiveMap.d.ts +0 -91
  42. package/lib/esm/LiveMap.js +0 -321
  43. package/lib/esm/LiveObject.d.ts +0 -80
  44. package/lib/esm/LiveObject.js +0 -481
  45. package/lib/esm/LiveRegister.d.ts +0 -29
  46. package/lib/esm/LiveRegister.js +0 -84
  47. package/lib/esm/client.d.ts +0 -27
  48. package/lib/esm/client.js +0 -119
  49. package/lib/esm/immutable.d.ts +0 -9
  50. package/lib/esm/immutable.js +0 -290
  51. package/lib/esm/index.d.ts +0 -6
  52. package/lib/esm/live.js +0 -46
  53. package/lib/esm/position.d.ts +0 -6
  54. package/lib/esm/position.js +0 -106
  55. package/lib/esm/room.d.ts +0 -159
  56. package/lib/esm/room.js +0 -1123
  57. package/lib/esm/types.js +0 -1
  58. package/lib/esm/utils.d.ts +0 -15
  59. package/lib/esm/utils.js +0 -213
@@ -1,481 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- 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");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- 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");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _LiveObject_instances, _LiveObject_map, _LiveObject_propToLastUpdate, _LiveObject_applyUpdate, _LiveObject_applyDeleteObjectKey;
13
- import { AbstractCrdt } from "./AbstractCrdt";
14
- import { deserialize, isCrdt } from "./utils";
15
- import { CrdtType, OpType, } from "./live";
16
- /**
17
- * The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
18
- * Keys should be a string, and values should be serializable to JSON.
19
- * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
20
- */
21
- export class LiveObject extends AbstractCrdt {
22
- constructor(object = {}) {
23
- super();
24
- _LiveObject_instances.add(this);
25
- _LiveObject_map.set(this, void 0);
26
- _LiveObject_propToLastUpdate.set(this, new Map());
27
- for (const key in object) {
28
- const value = object[key];
29
- if (value instanceof AbstractCrdt) {
30
- value._setParentLink(this, key);
31
- }
32
- }
33
- __classPrivateFieldSet(this, _LiveObject_map, new Map(Object.entries(object)), "f");
34
- }
35
- /**
36
- * INTERNAL
37
- */
38
- _serialize(parentId, parentKey, doc) {
39
- if (this._id == null) {
40
- throw new Error("Cannot serialize item is not attached");
41
- }
42
- const ops = [];
43
- const op = {
44
- id: this._id,
45
- opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
46
- type: OpType.CreateObject,
47
- parentId,
48
- parentKey,
49
- data: {},
50
- };
51
- ops.push(op);
52
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
53
- if (value instanceof AbstractCrdt) {
54
- ops.push(...value._serialize(this._id, key, doc));
55
- }
56
- else {
57
- op.data[key] = value;
58
- }
59
- }
60
- return ops;
61
- }
62
- /**
63
- * INTERNAL
64
- */
65
- static _deserialize([id, item], parentToChildren, doc) {
66
- if (item.type !== CrdtType.Object) {
67
- throw new Error(`Tried to deserialize a record but item type is "${item.type}"`);
68
- }
69
- const object = new LiveObject(item.data);
70
- object._attach(id, doc);
71
- return this._deserializeChildren(object, parentToChildren, doc);
72
- }
73
- /**
74
- * INTERNAL
75
- */
76
- static _deserializeChildren(object, parentToChildren, doc) {
77
- const children = parentToChildren.get(object._id);
78
- if (children == null) {
79
- return object;
80
- }
81
- for (const entry of children) {
82
- const crdt = entry[1];
83
- if (crdt.parentKey == null) {
84
- throw new Error("Tried to deserialize a crdt but it does not have a parentKey and is not the root");
85
- }
86
- const child = deserialize(entry, parentToChildren, doc);
87
- child._setParentLink(object, crdt.parentKey);
88
- __classPrivateFieldGet(object, _LiveObject_map, "f").set(crdt.parentKey, child);
89
- }
90
- return object;
91
- }
92
- /**
93
- * INTERNAL
94
- */
95
- _attach(id, doc) {
96
- super._attach(id, doc);
97
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
98
- if (value instanceof AbstractCrdt) {
99
- value._attach(doc.generateId(), doc);
100
- }
101
- }
102
- }
103
- /**
104
- * INTERNAL
105
- */
106
- _attachChild(id, key, child, opId, isLocal) {
107
- if (this._doc == null) {
108
- throw new Error("Can't attach child if doc is not present");
109
- }
110
- if (this._doc.getItem(id) !== undefined) {
111
- if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) === opId) {
112
- // Acknowlegment from local operation
113
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").delete(key);
114
- }
115
- return { modified: false };
116
- }
117
- if (isLocal) {
118
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
119
- }
120
- else if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) === undefined) {
121
- // Remote operation with no local change => apply operation
122
- }
123
- else if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) === opId) {
124
- // Acknowlegment from local operation
125
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").delete(key);
126
- return { modified: false };
127
- }
128
- else {
129
- // Conflict, ignore remote operation
130
- return { modified: false };
131
- }
132
- const previousValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
133
- let reverse;
134
- if (isCrdt(previousValue)) {
135
- reverse = previousValue._serialize(this._id, key);
136
- previousValue._detach();
137
- }
138
- else if (previousValue === undefined) {
139
- reverse = [
140
- { type: OpType.DeleteObjectKey, id: this._id, key: key },
141
- ];
142
- }
143
- else {
144
- reverse = [
145
- {
146
- type: OpType.UpdateObject,
147
- id: this._id,
148
- data: { [key]: previousValue },
149
- },
150
- ];
151
- }
152
- __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, child);
153
- child._setParentLink(this, key);
154
- child._attach(id, this._doc);
155
- return {
156
- reverse,
157
- modified: {
158
- node: this,
159
- type: "LiveObject",
160
- updates: { [key]: { type: "update" } },
161
- },
162
- };
163
- }
164
- /**
165
- * INTERNAL
166
- */
167
- _detachChild(child) {
168
- if (child) {
169
- const reverse = child._serialize(this._id, child._parentKey, this._doc);
170
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
171
- if (value === child) {
172
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
173
- }
174
- }
175
- child._detach();
176
- const storageUpdate = {
177
- node: this,
178
- type: "LiveObject",
179
- updates: {
180
- [child._parentKey]: { type: "delete" },
181
- },
182
- };
183
- return { modified: storageUpdate, reverse };
184
- }
185
- return { modified: false };
186
- }
187
- /**
188
- * INTERNAL
189
- */
190
- _detachChildren() {
191
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
192
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
193
- value._detach();
194
- }
195
- }
196
- /**
197
- * INTERNAL
198
- */
199
- _detach() {
200
- super._detach();
201
- for (const value of __classPrivateFieldGet(this, _LiveObject_map, "f").values()) {
202
- if (isCrdt(value)) {
203
- value._detach();
204
- }
205
- }
206
- }
207
- /**
208
- * INTERNAL
209
- */
210
- _apply(op, isLocal) {
211
- if (op.type === OpType.UpdateObject) {
212
- return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op, isLocal);
213
- }
214
- else if (op.type === OpType.DeleteObjectKey) {
215
- return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyDeleteObjectKey).call(this, op);
216
- }
217
- return super._apply(op, isLocal);
218
- }
219
- /**
220
- * INTERNAL
221
- */
222
- _toSerializedCrdt() {
223
- var _a;
224
- return {
225
- type: CrdtType.Object,
226
- parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
227
- parentKey: this._parentKey,
228
- data: this.toObject(),
229
- };
230
- }
231
- /**
232
- * INTERNAL
233
- */
234
- _getType() {
235
- return "LiveObject";
236
- }
237
- /**
238
- * Transform the LiveObject into a javascript object
239
- */
240
- toObject() {
241
- return Object.fromEntries(__classPrivateFieldGet(this, _LiveObject_map, "f"));
242
- }
243
- /**
244
- * Adds or updates a property with a specified key and a value.
245
- * @param key The key of the property to add
246
- * @param value The value of the property to add
247
- */
248
- set(key, value) {
249
- // TODO: Find out why typescript complains
250
- this.update({ [key]: value });
251
- }
252
- /**
253
- * Returns a specified property from the LiveObject.
254
- * @param key The key of the property to get
255
- */
256
- get(key) {
257
- return __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
258
- }
259
- /**
260
- * Deletes a key from the LiveObject
261
- * @param key The key of the property to delete
262
- */
263
- delete(key) {
264
- const keyAsString = key;
265
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(keyAsString);
266
- if (oldValue === undefined) {
267
- return;
268
- }
269
- if (this._doc == null || this._id == null) {
270
- if (oldValue instanceof AbstractCrdt) {
271
- oldValue._detach();
272
- }
273
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
274
- return;
275
- }
276
- let reverse;
277
- if (oldValue instanceof AbstractCrdt) {
278
- oldValue._detach();
279
- reverse = oldValue._serialize(this._id, keyAsString);
280
- }
281
- else {
282
- reverse = [
283
- {
284
- type: OpType.UpdateObject,
285
- data: { [keyAsString]: oldValue },
286
- id: this._id,
287
- },
288
- ];
289
- }
290
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
291
- const storageUpdates = new Map();
292
- storageUpdates.set(this._id, {
293
- node: this,
294
- type: "LiveObject",
295
- updates: { [key]: { type: "delete" } },
296
- });
297
- this._doc.dispatch([
298
- {
299
- type: OpType.DeleteObjectKey,
300
- key: keyAsString,
301
- id: this._id,
302
- opId: this._doc.generateOpId(),
303
- },
304
- ], reverse, storageUpdates);
305
- }
306
- /**
307
- * Adds or updates multiple properties at once with an object.
308
- * @param overrides The object used to overrides properties
309
- */
310
- update(overrides) {
311
- if (this._doc == null || this._id == null) {
312
- for (const key in overrides) {
313
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
314
- if (oldValue instanceof AbstractCrdt) {
315
- oldValue._detach();
316
- }
317
- const newValue = overrides[key];
318
- if (newValue instanceof AbstractCrdt) {
319
- newValue._setParentLink(this, key);
320
- }
321
- __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
322
- }
323
- return;
324
- }
325
- const ops = [];
326
- const reverseOps = [];
327
- const opId = this._doc.generateOpId();
328
- const updatedProps = {};
329
- const reverseUpdateOp = {
330
- id: this._id,
331
- type: OpType.UpdateObject,
332
- data: {},
333
- };
334
- const updateDelta = {};
335
- for (const key in overrides) {
336
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
337
- if (oldValue instanceof AbstractCrdt) {
338
- reverseOps.push(...oldValue._serialize(this._id, key));
339
- oldValue._detach();
340
- }
341
- else if (oldValue === undefined) {
342
- reverseOps.push({ type: OpType.DeleteObjectKey, id: this._id, key });
343
- }
344
- else {
345
- reverseUpdateOp.data[key] = oldValue;
346
- }
347
- const newValue = overrides[key];
348
- if (newValue instanceof AbstractCrdt) {
349
- newValue._setParentLink(this, key);
350
- newValue._attach(this._doc.generateId(), this._doc);
351
- const newAttachChildOps = newValue._serialize(this._id, key, this._doc);
352
- const createCrdtOp = newAttachChildOps.find((op) => op.parentId === this._id);
353
- if (createCrdtOp) {
354
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, createCrdtOp.opId);
355
- }
356
- ops.push(...newAttachChildOps);
357
- }
358
- else {
359
- updatedProps[key] = newValue;
360
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
361
- }
362
- __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
363
- updateDelta[key] = { type: "update" };
364
- }
365
- if (Object.keys(reverseUpdateOp.data).length !== 0) {
366
- reverseOps.unshift(reverseUpdateOp);
367
- }
368
- if (Object.keys(updatedProps).length !== 0) {
369
- ops.unshift({
370
- opId,
371
- id: this._id,
372
- type: OpType.UpdateObject,
373
- data: updatedProps,
374
- });
375
- }
376
- const storageUpdates = new Map();
377
- storageUpdates.set(this._id, {
378
- node: this,
379
- type: "LiveObject",
380
- updates: updateDelta,
381
- });
382
- this._doc.dispatch(ops, reverseOps, storageUpdates);
383
- }
384
- }
385
- _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op, isLocal) {
386
- let isModified = false;
387
- const reverse = [];
388
- const reverseUpdate = {
389
- type: OpType.UpdateObject,
390
- id: this._id,
391
- data: {},
392
- };
393
- reverse.push(reverseUpdate);
394
- for (const key in op.data) {
395
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
396
- if (oldValue instanceof AbstractCrdt) {
397
- reverse.push(...oldValue._serialize(this._id, key));
398
- oldValue._detach();
399
- }
400
- else if (oldValue !== undefined) {
401
- reverseUpdate.data[key] = oldValue;
402
- }
403
- else if (oldValue === undefined) {
404
- reverse.push({ type: OpType.DeleteObjectKey, id: this._id, key });
405
- }
406
- }
407
- let updateDelta = {};
408
- for (const key in op.data) {
409
- if (isLocal) {
410
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
411
- }
412
- else if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) == null) {
413
- // Not modified localy so we apply update
414
- isModified = true;
415
- }
416
- else if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) === op.opId) {
417
- // Acknowlegment from local operation
418
- __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").delete(key);
419
- continue;
420
- }
421
- else {
422
- // Conflict, ignore remote operation
423
- continue;
424
- }
425
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
426
- if (isCrdt(oldValue)) {
427
- oldValue._detach();
428
- }
429
- isModified = true;
430
- updateDelta[key] = { type: "update" };
431
- __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, op.data[key]);
432
- }
433
- if (Object.keys(reverseUpdate.data).length !== 0) {
434
- reverse.unshift(reverseUpdate);
435
- }
436
- return isModified
437
- ? {
438
- modified: {
439
- node: this,
440
- type: "LiveObject",
441
- updates: updateDelta,
442
- },
443
- reverse,
444
- }
445
- : { modified: false };
446
- }, _LiveObject_applyDeleteObjectKey = function _LiveObject_applyDeleteObjectKey(op) {
447
- const key = op.key;
448
- // If property does not exist, exit without notifying
449
- if (__classPrivateFieldGet(this, _LiveObject_map, "f").has(key) === false) {
450
- return { modified: false };
451
- }
452
- // If a local operation exists on the same key
453
- // prevent flickering by not applying delete op.
454
- if (__classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").get(key) !== undefined) {
455
- return { modified: false };
456
- }
457
- const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
458
- let reverse = [];
459
- if (isCrdt(oldValue)) {
460
- reverse = oldValue._serialize(this._id, op.key);
461
- oldValue._detach();
462
- }
463
- else if (oldValue !== undefined) {
464
- reverse = [
465
- {
466
- type: OpType.UpdateObject,
467
- id: this._id,
468
- data: { [key]: oldValue },
469
- },
470
- ];
471
- }
472
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
473
- return {
474
- modified: {
475
- node: this,
476
- type: "LiveObject",
477
- updates: { [op.key]: { type: "delete" } },
478
- },
479
- reverse,
480
- };
481
- };
@@ -1,29 +0,0 @@
1
- import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { SerializedCrdtWithId, Op, SerializedCrdt } from "./live";
3
- /**
4
- * INTERNAL
5
- */
6
- export declare class LiveRegister<TValue = any> extends AbstractCrdt {
7
- #private;
8
- constructor(data: TValue);
9
- get data(): TValue;
10
- /**
11
- * INTERNAL
12
- */
13
- static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveRegister<any>;
14
- /**
15
- * INTERNAL
16
- */
17
- _serialize(parentId: string, parentKey: string, doc?: Doc): Op[];
18
- /**
19
- * INTERNAL
20
- */
21
- _toSerializedCrdt(): SerializedCrdt;
22
- _attachChild(id: string, key: string, crdt: AbstractCrdt, opId: string, isLocal: boolean): ApplyResult;
23
- _detachChild(crdt: AbstractCrdt): ApplyResult;
24
- _apply(op: Op, isLocal: boolean): ApplyResult;
25
- /**
26
- * INTERNAL
27
- */
28
- _getType(): string;
29
- }
@@ -1,84 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- 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");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- 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");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _LiveRegister_data;
13
- import { AbstractCrdt } from "./AbstractCrdt";
14
- import { CrdtType, OpType, } from "./live";
15
- /**
16
- * INTERNAL
17
- */
18
- export class LiveRegister extends AbstractCrdt {
19
- constructor(data) {
20
- super();
21
- _LiveRegister_data.set(this, void 0);
22
- __classPrivateFieldSet(this, _LiveRegister_data, data, "f");
23
- }
24
- get data() {
25
- return __classPrivateFieldGet(this, _LiveRegister_data, "f");
26
- }
27
- /**
28
- * INTERNAL
29
- */
30
- static _deserialize([id, item], parentToChildren, doc) {
31
- if (item.type !== CrdtType.Register) {
32
- throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
33
- }
34
- const register = new LiveRegister(item.data);
35
- register._attach(id, doc);
36
- return register;
37
- }
38
- /**
39
- * INTERNAL
40
- */
41
- _serialize(parentId, parentKey, doc) {
42
- if (this._id == null || parentId == null || parentKey == null) {
43
- throw new Error("Cannot serialize register if parentId or parentKey is undefined");
44
- }
45
- return [
46
- {
47
- type: OpType.CreateRegister,
48
- opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
49
- id: this._id,
50
- parentId,
51
- parentKey,
52
- data: this.data,
53
- },
54
- ];
55
- }
56
- /**
57
- * INTERNAL
58
- */
59
- _toSerializedCrdt() {
60
- var _a;
61
- return {
62
- type: CrdtType.Register,
63
- parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
64
- parentKey: this._parentKey,
65
- data: this.data,
66
- };
67
- }
68
- _attachChild(id, key, crdt, opId, isLocal) {
69
- throw new Error("Method not implemented.");
70
- }
71
- _detachChild(crdt) {
72
- throw new Error("Method not implemented.");
73
- }
74
- _apply(op, isLocal) {
75
- return super._apply(op, isLocal);
76
- }
77
- /**
78
- * INTERNAL
79
- */
80
- _getType() {
81
- return "LiveRegister";
82
- }
83
- }
84
- _LiveRegister_data = new WeakMap();
@@ -1,27 +0,0 @@
1
- import { ClientOptions, Client } from "./types";
2
- /**
3
- * Create a client that will be responsible to communicate with liveblocks servers.
4
- *
5
- * @example
6
- * const client = createClient({
7
- * authEndpoint: "/api/auth"
8
- * });
9
- *
10
- * // It's also possible to use a function to call your authentication endpoint.
11
- * // Useful to add additional headers or use an API wrapper (like Firebase functions)
12
- * const client = createClient({
13
- * authEndpoint: async (room) => {
14
- * const response = await fetch("/api/auth", {
15
- * method: "POST",
16
- * headers: {
17
- * Authentication: "token",
18
- * "Content-Type": "application/json"
19
- * },
20
- * body: JSON.stringify({ room })
21
- * });
22
- *
23
- * return await response.json();
24
- * }
25
- * });
26
- */
27
- export declare function createClient(options: ClientOptions): Client;