@liveblocks/client 0.14.4 → 0.15.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import { Op, SerializedCrdt } from "./live";
2
+ import { StorageUpdate } from "./types";
2
3
  export declare type ApplyResult = {
3
4
  reverse: Op[];
4
- modified: AbstractCrdt;
5
+ modified: StorageUpdate;
5
6
  } | {
6
7
  modified: false;
7
8
  };
@@ -11,7 +12,7 @@ export interface Doc {
11
12
  getItem: (id: string) => AbstractCrdt | undefined;
12
13
  addItem: (id: string, item: AbstractCrdt) => void;
13
14
  deleteItem: (id: string) => void;
14
- dispatch: (ops: Op[], reverseOps: Op[], modified: AbstractCrdt[]) => void;
15
+ dispatch: (ops: Op[], reverseOps: Op[], storageUpdates: Map<string, StorageUpdate>) => void;
15
16
  }
16
17
  export declare abstract class AbstractCrdt {
17
18
  #private;
@@ -54,7 +55,7 @@ export declare abstract class AbstractCrdt {
54
55
  /**
55
56
  * INTERNAL
56
57
  */
57
- abstract _detachChild(crdt: AbstractCrdt): void;
58
+ abstract _detachChild(crdt: AbstractCrdt): ApplyResult;
58
59
  /**
59
60
  * INTERNAL
60
61
  */
@@ -63,4 +64,5 @@ export declare abstract class AbstractCrdt {
63
64
  * INTERNAL
64
65
  */
65
66
  abstract _toSerializedCrdt(): SerializedCrdt;
67
+ abstract _getType(): string;
66
68
  }
@@ -52,10 +52,7 @@ class AbstractCrdt {
52
52
  switch (op.type) {
53
53
  case live_1.OpType.DeleteCrdt: {
54
54
  if (this._parent != null && this._parentKey != null) {
55
- const parent = this._parent;
56
- const reverse = this._serialize(this._parent._id, this._parentKey, __classPrivateFieldGet(this, _AbstractCrdt_doc, "f"));
57
- this._parent._detachChild(this);
58
- return { modified: parent, reverse };
55
+ return this._parent._detachChild(this);
59
56
  }
60
57
  return { modified: false };
61
58
  }
@@ -14,6 +14,7 @@ export declare class LiveList<T> extends AbstractCrdt {
14
14
  * INTERNAL
15
15
  */
16
16
  _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
17
+ _indexOfPosition(position: string): number;
17
18
  /**
18
19
  * INTERNAL
19
20
  */
@@ -29,15 +30,19 @@ export declare class LiveList<T> extends AbstractCrdt {
29
30
  /**
30
31
  * INTERNAL
31
32
  */
32
- _detachChild(child: AbstractCrdt): void;
33
+ _detachChild(child: AbstractCrdt): ApplyResult;
33
34
  /**
34
35
  * INTERNAL
35
36
  */
36
- _setChildKey(key: string, child: AbstractCrdt): void;
37
+ _setChildKey(key: string, child: AbstractCrdt, previousKey: string): ApplyResult;
37
38
  /**
38
39
  * INTERNAL
39
40
  */
40
41
  _apply(op: Op, isLocal: boolean): ApplyResult;
42
+ /**
43
+ * INTERNAL
44
+ */
45
+ _getType(): string;
41
46
  /**
42
47
  * INTERNAL
43
48
  */
@@ -73,6 +78,7 @@ export declare class LiveList<T> extends AbstractCrdt {
73
78
  * Returns an Array of all the elements in the LiveList.
74
79
  */
75
80
  toArray(): T[];
81
+ toCrdtArray(): AbstractCrdt[];
76
82
  /**
77
83
  * Tests whether all elements pass the test implemented by the provided function.
78
84
  * @param predicate Function to test for each element, taking two arguments (the element and its index).
@@ -17,6 +17,7 @@ const AbstractCrdt_1 = require("./AbstractCrdt");
17
17
  const utils_1 = require("./utils");
18
18
  const live_1 = require("./live");
19
19
  const position_1 = require("./position");
20
+ const LiveRegister_1 = require("./LiveRegister");
20
21
  /**
21
22
  * The LiveList class represents an ordered collection of items that is synchorinized across clients.
22
23
  */
@@ -75,6 +76,9 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
75
76
  }
76
77
  return ops;
77
78
  }
79
+ _indexOfPosition(position) {
80
+ return __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[1] === position);
81
+ }
78
82
  /**
79
83
  * INTERNAL
80
84
  */
@@ -126,24 +130,47 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
126
130
  }
127
131
  __classPrivateFieldGet(this, _LiveList_items, "f").push([child, newKey]);
128
132
  __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
129
- return { reverse: [{ type: live_1.OpType.DeleteCrdt, id }], modified: this };
133
+ const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === newKey);
134
+ return {
135
+ reverse: [{ type: live_1.OpType.DeleteCrdt, id }],
136
+ modified: {
137
+ node: this,
138
+ type: "LiveList",
139
+ updates: [
140
+ {
141
+ index: newIndex,
142
+ type: "insert",
143
+ item: child instanceof LiveRegister_1.LiveRegister ? child.data : child,
144
+ },
145
+ ],
146
+ },
147
+ };
130
148
  }
131
149
  /**
132
150
  * INTERNAL
133
151
  */
134
152
  _detachChild(child) {
135
- const indexToDelete = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[0] === child);
136
- __classPrivateFieldGet(this, _LiveList_items, "f").splice(indexToDelete, 1);
137
153
  if (child) {
154
+ const reverse = child._serialize(this._id, child._parentKey, this._doc);
155
+ const indexToDelete = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[0] === child);
156
+ __classPrivateFieldGet(this, _LiveList_items, "f").splice(indexToDelete, 1);
138
157
  child._detach();
158
+ const storageUpdate = {
159
+ node: this,
160
+ type: "LiveList",
161
+ updates: [{ index: indexToDelete, type: "delete" }],
162
+ };
163
+ return { modified: storageUpdate, reverse };
139
164
  }
165
+ return { modified: false };
140
166
  }
141
167
  /**
142
168
  * INTERNAL
143
169
  */
144
- _setChildKey(key, child) {
170
+ _setChildKey(key, child, previousKey) {
145
171
  var _a;
146
172
  child._setParentLink(this, key);
173
+ const previousIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[0]._id === child._id);
147
174
  const index = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === key);
148
175
  // Assign a temporary position until we get the fix from the backend
149
176
  if (index !== -1) {
@@ -154,6 +181,31 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
154
181
  item[1] = key;
155
182
  }
156
183
  __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
184
+ const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[0]._id === child._id);
185
+ const updatesDelta = newIndex === previousIndex
186
+ ? []
187
+ : [
188
+ {
189
+ index: newIndex,
190
+ item: child instanceof LiveRegister_1.LiveRegister ? child.data : child,
191
+ previousIndex: previousIndex,
192
+ type: "move",
193
+ },
194
+ ];
195
+ return {
196
+ modified: {
197
+ node: this,
198
+ type: "LiveList",
199
+ updates: updatesDelta,
200
+ },
201
+ reverse: [
202
+ {
203
+ type: live_1.OpType.SetParentKey,
204
+ id: item === null || item === void 0 ? void 0 : item[0]._id,
205
+ parentKey: previousKey,
206
+ },
207
+ ],
208
+ };
157
209
  }
158
210
  /**
159
211
  * INTERNAL
@@ -161,6 +213,12 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
161
213
  _apply(op, isLocal) {
162
214
  return super._apply(op, isLocal);
163
215
  }
216
+ /**
217
+ * INTERNAL
218
+ */
219
+ _getType() {
220
+ return "LiveList";
221
+ }
164
222
  /**
165
223
  * INTERNAL
166
224
  */
@@ -192,7 +250,7 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
192
250
  */
193
251
  insert(element, index) {
194
252
  if (index < 0 || index > __classPrivateFieldGet(this, _LiveList_items, "f").length) {
195
- throw new Error(`Cannot delete list item at index "${index}". index should be between 0 and ${__classPrivateFieldGet(this, _LiveList_items, "f").length}`);
253
+ throw new Error(`Cannot insert list item at index "${index}". index should be between 0 and ${__classPrivateFieldGet(this, _LiveList_items, "f").length}`);
196
254
  }
197
255
  let before = __classPrivateFieldGet(this, _LiveList_items, "f")[index - 1] ? __classPrivateFieldGet(this, _LiveList_items, "f")[index - 1][1] : undefined;
198
256
  let after = __classPrivateFieldGet(this, _LiveList_items, "f")[index] ? __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] : undefined;
@@ -201,10 +259,23 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
201
259
  value._setParentLink(this, position);
202
260
  __classPrivateFieldGet(this, _LiveList_items, "f").push([value, position]);
203
261
  __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
262
+ const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === position);
204
263
  if (this._doc && this._id) {
205
264
  const id = this._doc.generateId();
206
265
  value._attach(id, this._doc);
207
- this._doc.dispatch(value._serialize(this._id, position, this._doc), [{ type: live_1.OpType.DeleteCrdt, id }], [this]);
266
+ const storageUpdates = new Map();
267
+ storageUpdates.set(this._id, {
268
+ node: this,
269
+ type: "LiveList",
270
+ updates: [
271
+ {
272
+ index: newIndex,
273
+ item: value instanceof LiveRegister_1.LiveRegister ? value.data : value,
274
+ type: "insert",
275
+ },
276
+ ],
277
+ });
278
+ this._doc.dispatch(value._serialize(this._id, position, this._doc), [{ type: live_1.OpType.DeleteCrdt, id }], storageUpdates);
208
279
  }
209
280
  }
210
281
  /**
@@ -245,7 +316,21 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
245
316
  item[1] = position;
246
317
  item[0]._setParentLink(this, position);
247
318
  __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => (0, position_1.compare)(itemA[1], itemB[1]));
319
+ const newIndex = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === position);
248
320
  if (this._doc && this._id) {
321
+ const storageUpdates = new Map();
322
+ storageUpdates.set(this._id, {
323
+ node: this,
324
+ type: "LiveList",
325
+ updates: [
326
+ {
327
+ index: newIndex,
328
+ previousIndex: index,
329
+ item: item[0],
330
+ type: "move",
331
+ },
332
+ ],
333
+ });
249
334
  this._doc.dispatch([
250
335
  {
251
336
  type: live_1.OpType.SetParentKey,
@@ -259,7 +344,7 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
259
344
  id: item[0]._id,
260
345
  parentKey: previousPosition,
261
346
  },
262
- ], [this]);
347
+ ], storageUpdates);
263
348
  }
264
349
  }
265
350
  /**
@@ -276,13 +361,19 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
276
361
  if (this._doc) {
277
362
  const childRecordId = item[0]._id;
278
363
  if (childRecordId) {
364
+ const storageUpdates = new Map();
365
+ storageUpdates.set(this._id, {
366
+ node: this,
367
+ type: "LiveList",
368
+ updates: [{ index: index, type: "delete" }],
369
+ });
279
370
  this._doc.dispatch([
280
371
  {
281
372
  id: childRecordId,
282
373
  opId: this._doc.generateOpId(),
283
374
  type: live_1.OpType.DeleteCrdt,
284
375
  },
285
- ], item[0]._serialize(this._id, item[1]), [this]);
376
+ ], item[0]._serialize(this._id, item[1]), storageUpdates);
286
377
  }
287
378
  }
288
379
  }
@@ -290,16 +381,26 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
290
381
  if (this._doc) {
291
382
  let ops = [];
292
383
  let reverseOps = [];
384
+ let updateDelta = [];
385
+ let i = 0;
293
386
  for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
294
387
  item[0]._detach();
295
388
  const childId = item[0]._id;
296
389
  if (childId) {
297
390
  ops.push({ id: childId, type: live_1.OpType.DeleteCrdt });
298
391
  reverseOps.push(...item[0]._serialize(this._id, item[1]));
392
+ updateDelta.push({ index: i, type: "delete" });
299
393
  }
394
+ i++;
300
395
  }
301
396
  __classPrivateFieldSet(this, _LiveList_items, [], "f");
302
- this._doc.dispatch(ops, reverseOps, [this]);
397
+ const storageUpdates = new Map();
398
+ storageUpdates.set(this._id, {
399
+ node: this,
400
+ type: "LiveList",
401
+ updates: updateDelta,
402
+ });
403
+ this._doc.dispatch(ops, reverseOps, storageUpdates);
303
404
  }
304
405
  else {
305
406
  for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
@@ -314,6 +415,9 @@ class LiveList extends AbstractCrdt_1.AbstractCrdt {
314
415
  toArray() {
315
416
  return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry) => (0, utils_1.selfOrRegisterValue)(entry[0]));
316
417
  }
418
+ toCrdtArray() {
419
+ return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry) => entry[0]);
420
+ }
317
421
  /**
318
422
  * Tests whether all elements pass the test implemented by the provided function.
319
423
  * @param predicate Function to test for each element, taking two arguments (the element and its index).
@@ -31,7 +31,11 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
31
31
  /**
32
32
  * INTERNAL
33
33
  */
34
- _detachChild(child: AbstractCrdt): void;
34
+ _detachChild(child: AbstractCrdt): ApplyResult;
35
+ /**
36
+ * INTERNAL
37
+ */
38
+ _getType(): string;
35
39
  /**
36
40
  * INTERNAL
37
41
  */
@@ -119,7 +119,14 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
119
119
  child._setParentLink(this, key);
120
120
  child._attach(id, this._doc);
121
121
  __classPrivateFieldGet(this, _LiveMap_map, "f").set(key, child);
122
- return { modified: this, reverse };
122
+ return {
123
+ modified: {
124
+ node: this,
125
+ type: "LiveMap",
126
+ updates: { [key]: { type: "update" } },
127
+ },
128
+ reverse,
129
+ };
123
130
  }
124
131
  /**
125
132
  * INTERNAL
@@ -134,12 +141,25 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
134
141
  * INTERNAL
135
142
  */
136
143
  _detachChild(child) {
144
+ const reverse = child._serialize(this._id, child._parentKey, this._doc);
137
145
  for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
138
146
  if (value === child) {
139
147
  __classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
140
148
  }
141
149
  }
142
150
  child._detach();
151
+ const storageUpdate = {
152
+ node: this,
153
+ type: "LiveMap",
154
+ updates: { [child._parentKey]: { type: "delete" } },
155
+ };
156
+ return { modified: storageUpdate, reverse };
157
+ }
158
+ /**
159
+ * INTERNAL
160
+ */
161
+ _getType() {
162
+ return "LiveMap";
143
163
  }
144
164
  /**
145
165
  * INTERNAL
@@ -180,9 +200,15 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
180
200
  if (this._doc && this._id) {
181
201
  const id = this._doc.generateId();
182
202
  item._attach(id, this._doc);
203
+ const storageUpdates = new Map();
204
+ storageUpdates.set(this._id, {
205
+ node: this,
206
+ type: "LiveMap",
207
+ updates: { [key]: { type: "update" } },
208
+ });
183
209
  this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue
184
210
  ? oldValue._serialize(this._id, key)
185
- : [{ type: live_1.OpType.DeleteCrdt, id }], [this]);
211
+ : [{ type: live_1.OpType.DeleteCrdt, id }], storageUpdates);
186
212
  }
187
213
  }
188
214
  /**
@@ -210,13 +236,19 @@ class LiveMap extends AbstractCrdt_1.AbstractCrdt {
210
236
  }
211
237
  item._detach();
212
238
  if (this._doc && item._id) {
239
+ const storageUpdates = new Map();
240
+ storageUpdates.set(this._id, {
241
+ node: this,
242
+ type: "LiveMap",
243
+ updates: { [key]: { type: "delete" } },
244
+ });
213
245
  this._doc.dispatch([
214
246
  {
215
247
  type: live_1.OpType.DeleteCrdt,
216
248
  id: item._id,
217
249
  opId: this._doc.generateOpId(),
218
250
  },
219
- ], item._serialize(this._id, key), [this]);
251
+ ], item._serialize(this._id, key), storageUpdates);
220
252
  }
221
253
  __classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
222
254
  return true;
@@ -31,7 +31,7 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
31
31
  /**
32
32
  * INTERNAL
33
33
  */
34
- _detachChild(child: AbstractCrdt): void;
34
+ _detachChild(child: AbstractCrdt): ApplyResult;
35
35
  /**
36
36
  * INTERNAL
37
37
  */
@@ -48,6 +48,10 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
48
48
  * INTERNAL
49
49
  */
50
50
  _toSerializedCrdt(): SerializedCrdt;
51
+ /**
52
+ * INTERNAL
53
+ */
54
+ _getType(): string;
51
55
  /**
52
56
  * Transform the LiveObject into a javascript object
53
57
  */
@@ -155,20 +155,37 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
155
155
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, child);
156
156
  child._setParentLink(this, key);
157
157
  child._attach(id, this._doc);
158
- return { reverse, modified: this };
158
+ return {
159
+ reverse,
160
+ modified: {
161
+ node: this,
162
+ type: "LiveObject",
163
+ updates: { [key]: { type: "update" } },
164
+ },
165
+ };
159
166
  }
160
167
  /**
161
168
  * INTERNAL
162
169
  */
163
170
  _detachChild(child) {
164
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
165
- if (value === child) {
166
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
167
- }
168
- }
169
171
  if (child) {
172
+ const reverse = child._serialize(this._id, child._parentKey, this._doc);
173
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
174
+ if (value === child) {
175
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
176
+ }
177
+ }
170
178
  child._detach();
179
+ const storageUpdate = {
180
+ node: this,
181
+ type: "LiveObject",
182
+ updates: {
183
+ [child._parentKey]: { type: "delete" },
184
+ },
185
+ };
186
+ return { modified: storageUpdate, reverse };
171
187
  }
188
+ return { modified: false };
172
189
  }
173
190
  /**
174
191
  * INTERNAL
@@ -214,6 +231,12 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
214
231
  data: this.toObject(),
215
232
  };
216
233
  }
234
+ /**
235
+ * INTERNAL
236
+ */
237
+ _getType() {
238
+ return "LiveObject";
239
+ }
217
240
  /**
218
241
  * Transform the LiveObject into a javascript object
219
242
  */
@@ -268,6 +291,12 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
268
291
  ];
269
292
  }
270
293
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
294
+ const storageUpdates = new Map();
295
+ storageUpdates.set(this._id, {
296
+ node: this,
297
+ type: "LiveObject",
298
+ updates: { [key]: { type: "delete" } },
299
+ });
271
300
  this._doc.dispatch([
272
301
  {
273
302
  type: live_1.OpType.DeleteObjectKey,
@@ -275,7 +304,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
275
304
  id: this._id,
276
305
  opId: this._doc.generateOpId(),
277
306
  },
278
- ], reverse, [this]);
307
+ ], reverse, storageUpdates);
279
308
  }
280
309
  /**
281
310
  * Adds or updates multiple properties at once with an object.
@@ -305,6 +334,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
305
334
  type: live_1.OpType.UpdateObject,
306
335
  data: {},
307
336
  };
337
+ const updateDelta = {};
308
338
  for (const key in overrides) {
309
339
  const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
310
340
  if (oldValue instanceof AbstractCrdt_1.AbstractCrdt) {
@@ -333,6 +363,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
333
363
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
334
364
  }
335
365
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
366
+ updateDelta[key] = { type: "update" };
336
367
  }
337
368
  if (Object.keys(reverseUpdateOp.data).length !== 0) {
338
369
  reverseOps.unshift(reverseUpdateOp);
@@ -345,7 +376,13 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
345
376
  data: updatedProps,
346
377
  });
347
378
  }
348
- this._doc.dispatch(ops, reverseOps, [this]);
379
+ const storageUpdates = new Map();
380
+ storageUpdates.set(this._id, {
381
+ node: this,
382
+ type: "LiveObject",
383
+ updates: updateDelta,
384
+ });
385
+ this._doc.dispatch(ops, reverseOps, storageUpdates);
349
386
  }
350
387
  }
351
388
  exports.LiveObject = LiveObject;
@@ -371,6 +408,7 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
371
408
  reverse.push({ type: live_1.OpType.DeleteObjectKey, id: this._id, key });
372
409
  }
373
410
  }
411
+ let updateDelta = {};
374
412
  for (const key in op.data) {
375
413
  if (isLocal) {
376
414
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
@@ -393,12 +431,22 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
393
431
  oldValue._detach();
394
432
  }
395
433
  isModified = true;
434
+ updateDelta[key] = { type: "update" };
396
435
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, op.data[key]);
397
436
  }
398
437
  if (Object.keys(reverseUpdate.data).length !== 0) {
399
438
  reverse.unshift(reverseUpdate);
400
439
  }
401
- return isModified ? { modified: this, reverse } : { modified: false };
440
+ return isModified
441
+ ? {
442
+ modified: {
443
+ node: this,
444
+ type: "LiveObject",
445
+ updates: updateDelta,
446
+ },
447
+ reverse,
448
+ }
449
+ : { modified: false };
402
450
  }, _LiveObject_applyDeleteObjectKey = function _LiveObject_applyDeleteObjectKey(op) {
403
451
  const key = op.key;
404
452
  // If property does not exist, exit without notifying
@@ -426,5 +474,12 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
426
474
  ];
427
475
  }
428
476
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
429
- return { modified: this, reverse };
477
+ return {
478
+ modified: {
479
+ node: this,
480
+ type: "LiveObject",
481
+ updates: { [op.key]: { type: "delete" } },
482
+ },
483
+ reverse,
484
+ };
430
485
  };
@@ -20,6 +20,10 @@ export declare class LiveRegister<TValue = any> extends AbstractCrdt {
20
20
  */
21
21
  _toSerializedCrdt(): SerializedCrdt;
22
22
  _attachChild(id: string, key: string, crdt: AbstractCrdt, opId: string, isLocal: boolean): ApplyResult;
23
- _detachChild(crdt: AbstractCrdt): void;
23
+ _detachChild(crdt: AbstractCrdt): ApplyResult;
24
24
  _apply(op: Op, isLocal: boolean): ApplyResult;
25
+ /**
26
+ * INTERNAL
27
+ */
28
+ _getType(): string;
25
29
  }
@@ -77,6 +77,12 @@ class LiveRegister extends AbstractCrdt_1.AbstractCrdt {
77
77
  _apply(op, isLocal) {
78
78
  return super._apply(op, isLocal);
79
79
  }
80
+ /**
81
+ * INTERNAL
82
+ */
83
+ _getType() {
84
+ return "LiveRegister";
85
+ }
80
86
  }
81
87
  exports.LiveRegister = LiveRegister;
82
88
  _LiveRegister_data = new WeakMap();
@@ -0,0 +1,9 @@
1
+ import { LiveList } from "./LiveList";
2
+ import { LiveObject } from "./LiveObject";
3
+ import { StorageUpdate } from "./types";
4
+ export declare function liveObjectToJson(liveObject: LiveObject<any>): any;
5
+ export declare function liveNodeToJson(value: any): any;
6
+ export declare function patchLiveList<T>(liveList: LiveList<T>, prev: Array<T>, next: Array<T>): void;
7
+ export declare function patchLiveObjectKey<T>(liveObject: LiveObject<T>, key: keyof T, prev: any, next: any): void;
8
+ export declare function patchLiveObject<T extends Record<string, any>>(root: LiveObject<T>, prev: T, next: T): void;
9
+ export declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;