@liveblocks/client 0.16.8 → 0.16.9
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/index.js +23 -23
- package/index.mjs +24 -24
- package/internal.d.ts +56 -56
- package/internal.js +6 -6
- package/internal.mjs +1 -1
- package/package.json +1 -1
- package/shared.js +69 -69
- package/shared.mjs +73 -73
package/shared.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ServerMsgCode, ClientMsgCode, CrdtType, OpCode, WebsocketCloseCodes;
|
|
2
2
|
|
|
3
|
-
!function(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}(
|
|
12
|
-
CrdtType[CrdtType.
|
|
13
|
-
CrdtType[CrdtType.
|
|
14
|
-
}(CrdtType || (CrdtType = {})), function(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}(
|
|
3
|
+
!function(ServerMsgCode) {
|
|
4
|
+
ServerMsgCode[ServerMsgCode.UPDATE_PRESENCE = 100] = "UPDATE_PRESENCE", ServerMsgCode[ServerMsgCode.USER_JOINED = 101] = "USER_JOINED",
|
|
5
|
+
ServerMsgCode[ServerMsgCode.USER_LEFT = 102] = "USER_LEFT", ServerMsgCode[ServerMsgCode.BROADCASTED_EVENT = 103] = "BROADCASTED_EVENT",
|
|
6
|
+
ServerMsgCode[ServerMsgCode.ROOM_STATE = 104] = "ROOM_STATE", ServerMsgCode[ServerMsgCode.INITIAL_STORAGE_STATE = 200] = "INITIAL_STORAGE_STATE",
|
|
7
|
+
ServerMsgCode[ServerMsgCode.UPDATE_STORAGE = 201] = "UPDATE_STORAGE";
|
|
8
|
+
}(ServerMsgCode || (ServerMsgCode = {})), function(ClientMsgCode) {
|
|
9
|
+
ClientMsgCode[ClientMsgCode.UPDATE_PRESENCE = 100] = "UPDATE_PRESENCE", ClientMsgCode[ClientMsgCode.BROADCAST_EVENT = 103] = "BROADCAST_EVENT",
|
|
10
|
+
ClientMsgCode[ClientMsgCode.FETCH_STORAGE = 200] = "FETCH_STORAGE", ClientMsgCode[ClientMsgCode.UPDATE_STORAGE = 201] = "UPDATE_STORAGE";
|
|
11
|
+
}(ClientMsgCode || (ClientMsgCode = {})), function(CrdtType) {
|
|
12
|
+
CrdtType[CrdtType.OBJECT = 0] = "OBJECT", CrdtType[CrdtType.LIST = 1] = "LIST",
|
|
13
|
+
CrdtType[CrdtType.MAP = 2] = "MAP", CrdtType[CrdtType.REGISTER = 3] = "REGISTER";
|
|
14
|
+
}(CrdtType || (CrdtType = {})), function(OpCode) {
|
|
15
|
+
OpCode[OpCode.INIT = 0] = "INIT", OpCode[OpCode.SET_PARENT_KEY = 1] = "SET_PARENT_KEY",
|
|
16
|
+
OpCode[OpCode.CREATE_LIST = 2] = "CREATE_LIST", OpCode[OpCode.UPDATE_OBJECT = 3] = "UPDATE_OBJECT",
|
|
17
|
+
OpCode[OpCode.CREATE_OBJECT = 4] = "CREATE_OBJECT", OpCode[OpCode.DELETE_CRDT = 5] = "DELETE_CRDT",
|
|
18
|
+
OpCode[OpCode.DELETE_OBJECT_KEY = 6] = "DELETE_OBJECT_KEY", OpCode[OpCode.CREATE_MAP = 7] = "CREATE_MAP",
|
|
19
|
+
OpCode[OpCode.CREATE_REGISTER = 8] = "CREATE_REGISTER";
|
|
20
|
+
}(OpCode || (OpCode = {})), function(WebsocketCloseCodes) {
|
|
21
21
|
WebsocketCloseCodes[WebsocketCloseCodes.CLOSE_ABNORMAL = 1006] = "CLOSE_ABNORMAL",
|
|
22
22
|
WebsocketCloseCodes[WebsocketCloseCodes.INVALID_MESSAGE_FORMAT = 4e3] = "INVALID_MESSAGE_FORMAT",
|
|
23
23
|
WebsocketCloseCodes[WebsocketCloseCodes.NOT_ALLOWED = 4001] = "NOT_ALLOWED", WebsocketCloseCodes[WebsocketCloseCodes.MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS",
|
|
@@ -44,7 +44,7 @@ class AbstractCrdt {
|
|
|
44
44
|
return this.__parentKey;
|
|
45
45
|
}
|
|
46
46
|
_apply(op, _isLocal) {
|
|
47
|
-
return op.type ===
|
|
47
|
+
return op.type === OpCode.DELETE_CRDT && null != this._parent && null != this._parentKey ? this._parent._detachChild(this) : {
|
|
48
48
|
modified: !1
|
|
49
49
|
};
|
|
50
50
|
}
|
|
@@ -86,14 +86,14 @@ class LiveRegister extends AbstractCrdt {
|
|
|
86
86
|
return this._data;
|
|
87
87
|
}
|
|
88
88
|
static _deserialize([id, item], _parentToChildren, doc) {
|
|
89
|
-
if (item.type !== CrdtType.
|
|
89
|
+
if (item.type !== CrdtType.REGISTER) throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
|
|
90
90
|
const register = new LiveRegister(item.data);
|
|
91
91
|
return register._attach(id, doc), register;
|
|
92
92
|
}
|
|
93
93
|
_serialize(parentId, parentKey, doc, intent) {
|
|
94
94
|
if (null == this._id || null == parentId || null == parentKey) throw new Error("Cannot serialize register if parentId or parentKey is undefined");
|
|
95
95
|
return [ {
|
|
96
|
-
type:
|
|
96
|
+
type: OpCode.CREATE_REGISTER,
|
|
97
97
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
98
98
|
id: this._id,
|
|
99
99
|
intent: intent,
|
|
@@ -105,7 +105,7 @@ class LiveRegister extends AbstractCrdt {
|
|
|
105
105
|
_toSerializedCrdt() {
|
|
106
106
|
var _a;
|
|
107
107
|
return {
|
|
108
|
-
type: CrdtType.
|
|
108
|
+
type: CrdtType.REGISTER,
|
|
109
109
|
parentId: null === (_a = this._parent) || void 0 === _a ? void 0 : _a._id,
|
|
110
110
|
parentKey: this._parentKey,
|
|
111
111
|
data: this.data
|
|
@@ -222,7 +222,7 @@ class LiveList extends AbstractCrdt {
|
|
|
222
222
|
id: this._id,
|
|
223
223
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
224
224
|
intent: intent,
|
|
225
|
-
type:
|
|
225
|
+
type: OpCode.CREATE_LIST,
|
|
226
226
|
parentId: parentId,
|
|
227
227
|
parentKey: parentKey
|
|
228
228
|
};
|
|
@@ -278,7 +278,7 @@ class LiveList extends AbstractCrdt {
|
|
|
278
278
|
const newIndex = this._items.findIndex((entry => entry[1] === newKey));
|
|
279
279
|
return {
|
|
280
280
|
reverse: [ {
|
|
281
|
-
type:
|
|
281
|
+
type: OpCode.DELETE_CRDT,
|
|
282
282
|
id: id
|
|
283
283
|
} ],
|
|
284
284
|
modified: {
|
|
@@ -332,7 +332,7 @@ class LiveList extends AbstractCrdt {
|
|
|
332
332
|
} ]
|
|
333
333
|
},
|
|
334
334
|
reverse: [ {
|
|
335
|
-
type:
|
|
335
|
+
type: OpCode.SET_PARENT_KEY,
|
|
336
336
|
id: null == item ? void 0 : item[0]._id,
|
|
337
337
|
parentKey: previousKey
|
|
338
338
|
} ]
|
|
@@ -344,7 +344,7 @@ class LiveList extends AbstractCrdt {
|
|
|
344
344
|
_toSerializedCrdt() {
|
|
345
345
|
var _a;
|
|
346
346
|
return {
|
|
347
|
-
type: CrdtType.
|
|
347
|
+
type: CrdtType.LIST,
|
|
348
348
|
parentId: null === (_a = this._parent) || void 0 === _a ? void 0 : _a._id,
|
|
349
349
|
parentKey: this._parentKey
|
|
350
350
|
};
|
|
@@ -373,7 +373,7 @@ class LiveList extends AbstractCrdt {
|
|
|
373
373
|
type: "insert"
|
|
374
374
|
} ]
|
|
375
375
|
}), this._doc.dispatch(value._serialize(this._id, position, this._doc), [ {
|
|
376
|
-
type:
|
|
376
|
+
type: OpCode.DELETE_CRDT,
|
|
377
377
|
id: id
|
|
378
378
|
} ], storageUpdates);
|
|
379
379
|
}
|
|
@@ -402,12 +402,12 @@ class LiveList extends AbstractCrdt {
|
|
|
402
402
|
type: "move"
|
|
403
403
|
} ]
|
|
404
404
|
}), this._doc.dispatch([ {
|
|
405
|
-
type:
|
|
405
|
+
type: OpCode.SET_PARENT_KEY,
|
|
406
406
|
id: item[0]._id,
|
|
407
407
|
opId: this._doc.generateOpId(),
|
|
408
408
|
parentKey: position
|
|
409
409
|
} ], [ {
|
|
410
|
-
type:
|
|
410
|
+
type: OpCode.SET_PARENT_KEY,
|
|
411
411
|
id: item[0]._id,
|
|
412
412
|
parentKey: previousPosition
|
|
413
413
|
} ], storageUpdates);
|
|
@@ -430,7 +430,7 @@ class LiveList extends AbstractCrdt {
|
|
|
430
430
|
}), this._doc.dispatch([ {
|
|
431
431
|
id: childRecordId,
|
|
432
432
|
opId: this._doc.generateOpId(),
|
|
433
|
-
type:
|
|
433
|
+
type: OpCode.DELETE_CRDT
|
|
434
434
|
} ], item[0]._serialize(this._id, item[1]), storageUpdates);
|
|
435
435
|
}
|
|
436
436
|
}
|
|
@@ -444,7 +444,7 @@ class LiveList extends AbstractCrdt {
|
|
|
444
444
|
const childId = item[0]._id;
|
|
445
445
|
childId && (ops.push({
|
|
446
446
|
id: childId,
|
|
447
|
-
type:
|
|
447
|
+
type: OpCode.DELETE_CRDT
|
|
448
448
|
}), reverseOps.push(...item[0]._serialize(this._id, item[1])), updateDelta.push({
|
|
449
449
|
index: i,
|
|
450
450
|
type: "delete"
|
|
@@ -578,7 +578,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
578
578
|
const ops = [], op = {
|
|
579
579
|
id: this._id,
|
|
580
580
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
581
|
-
type:
|
|
581
|
+
type: OpCode.CREATE_MAP,
|
|
582
582
|
intent: intent,
|
|
583
583
|
parentId: parentId,
|
|
584
584
|
parentKey: parentKey
|
|
@@ -588,7 +588,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
588
588
|
return ops;
|
|
589
589
|
}
|
|
590
590
|
static _deserialize([id, item], parentToChildren, doc) {
|
|
591
|
-
if (item.type !== CrdtType.
|
|
591
|
+
if (item.type !== CrdtType.MAP) throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
|
|
592
592
|
const map = new LiveMap;
|
|
593
593
|
map._attach(id, doc);
|
|
594
594
|
const children = parentToChildren.get(id);
|
|
@@ -614,7 +614,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
614
614
|
const previousValue = this._map.get(key);
|
|
615
615
|
let reverse;
|
|
616
616
|
return previousValue ? (reverse = previousValue._serialize(this._id, key), previousValue._detach()) : reverse = [ {
|
|
617
|
-
type:
|
|
617
|
+
type: OpCode.DELETE_CRDT,
|
|
618
618
|
id: id
|
|
619
619
|
} ], child._setParentLink(this, key), child._attach(id, this._doc), this._map.set(key, child),
|
|
620
620
|
{
|
|
@@ -654,7 +654,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
654
654
|
_toSerializedCrdt() {
|
|
655
655
|
var _a;
|
|
656
656
|
return {
|
|
657
|
-
type: CrdtType.
|
|
657
|
+
type: CrdtType.MAP,
|
|
658
658
|
parentId: null === (_a = this._parent) || void 0 === _a ? void 0 : _a._id,
|
|
659
659
|
parentKey: this._parentKey
|
|
660
660
|
};
|
|
@@ -680,7 +680,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
}), this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue ? oldValue._serialize(this._id, key) : [ {
|
|
683
|
-
type:
|
|
683
|
+
type: OpCode.DELETE_CRDT,
|
|
684
684
|
id: id
|
|
685
685
|
} ], storageUpdates);
|
|
686
686
|
}
|
|
@@ -705,7 +705,7 @@ class LiveMap extends AbstractCrdt {
|
|
|
705
705
|
}
|
|
706
706
|
}
|
|
707
707
|
}), this._doc.dispatch([ {
|
|
708
|
-
type:
|
|
708
|
+
type: OpCode.DELETE_CRDT,
|
|
709
709
|
id: item._id,
|
|
710
710
|
opId: this._doc.generateOpId()
|
|
711
711
|
} ], item._serialize(this._id, key), storageUpdates);
|
|
@@ -771,16 +771,16 @@ function compact(items) {
|
|
|
771
771
|
|
|
772
772
|
function creationOpToLiveStructure(op) {
|
|
773
773
|
switch (op.type) {
|
|
774
|
-
case
|
|
774
|
+
case OpCode.CREATE_REGISTER:
|
|
775
775
|
return new LiveRegister(op.data);
|
|
776
776
|
|
|
777
|
-
case
|
|
777
|
+
case OpCode.CREATE_OBJECT:
|
|
778
778
|
return new LiveObject(op.data);
|
|
779
779
|
|
|
780
|
-
case
|
|
780
|
+
case OpCode.CREATE_MAP:
|
|
781
781
|
return new LiveMap;
|
|
782
782
|
|
|
783
|
-
case
|
|
783
|
+
case OpCode.CREATE_LIST:
|
|
784
784
|
return new LiveList;
|
|
785
785
|
}
|
|
786
786
|
}
|
|
@@ -791,16 +791,16 @@ function isSameNodeOrChildOf(node, parent) {
|
|
|
791
791
|
|
|
792
792
|
function deserialize(entry, parentToChildren, doc) {
|
|
793
793
|
switch (entry[1].type) {
|
|
794
|
-
case CrdtType.
|
|
794
|
+
case CrdtType.OBJECT:
|
|
795
795
|
return LiveObject._deserialize(entry, parentToChildren, doc);
|
|
796
796
|
|
|
797
|
-
case CrdtType.
|
|
797
|
+
case CrdtType.LIST:
|
|
798
798
|
return LiveList._deserialize(entry, parentToChildren, doc);
|
|
799
799
|
|
|
800
|
-
case CrdtType.
|
|
800
|
+
case CrdtType.MAP:
|
|
801
801
|
return LiveMap._deserialize(entry, parentToChildren, doc);
|
|
802
802
|
|
|
803
|
-
case CrdtType.
|
|
803
|
+
case CrdtType.REGISTER:
|
|
804
804
|
return LiveRegister._deserialize(entry, parentToChildren, doc);
|
|
805
805
|
|
|
806
806
|
default:
|
|
@@ -826,23 +826,23 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
826
826
|
const ops = [];
|
|
827
827
|
return currentItems.forEach(((_, id) => {
|
|
828
828
|
newItems.get(id) || ops.push({
|
|
829
|
-
type:
|
|
829
|
+
type: OpCode.DELETE_CRDT,
|
|
830
830
|
id: id
|
|
831
831
|
});
|
|
832
832
|
})), newItems.forEach(((crdt, id) => {
|
|
833
833
|
const currentCrdt = currentItems.get(id);
|
|
834
|
-
if (currentCrdt) crdt.type === CrdtType.
|
|
835
|
-
type:
|
|
834
|
+
if (currentCrdt) crdt.type === CrdtType.OBJECT && JSON.stringify(crdt.data) !== JSON.stringify(currentCrdt.data) && ops.push({
|
|
835
|
+
type: OpCode.UPDATE_OBJECT,
|
|
836
836
|
id: id,
|
|
837
837
|
data: crdt.data
|
|
838
838
|
}), crdt.parentKey !== currentCrdt.parentKey && ops.push({
|
|
839
|
-
type:
|
|
839
|
+
type: OpCode.SET_PARENT_KEY,
|
|
840
840
|
id: id,
|
|
841
841
|
parentKey: crdt.parentKey
|
|
842
842
|
}); else switch (crdt.type) {
|
|
843
|
-
case CrdtType.
|
|
843
|
+
case CrdtType.REGISTER:
|
|
844
844
|
ops.push({
|
|
845
|
-
type:
|
|
845
|
+
type: OpCode.CREATE_REGISTER,
|
|
846
846
|
id: id,
|
|
847
847
|
parentId: crdt.parentId,
|
|
848
848
|
parentKey: crdt.parentKey,
|
|
@@ -850,18 +850,18 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
850
850
|
});
|
|
851
851
|
break;
|
|
852
852
|
|
|
853
|
-
case CrdtType.
|
|
853
|
+
case CrdtType.LIST:
|
|
854
854
|
ops.push({
|
|
855
|
-
type:
|
|
855
|
+
type: OpCode.CREATE_LIST,
|
|
856
856
|
id: id,
|
|
857
857
|
parentId: crdt.parentId,
|
|
858
858
|
parentKey: crdt.parentKey
|
|
859
859
|
});
|
|
860
860
|
break;
|
|
861
861
|
|
|
862
|
-
case CrdtType.
|
|
862
|
+
case CrdtType.OBJECT:
|
|
863
863
|
ops.push({
|
|
864
|
-
type:
|
|
864
|
+
type: OpCode.CREATE_OBJECT,
|
|
865
865
|
id: id,
|
|
866
866
|
parentId: crdt.parentId,
|
|
867
867
|
parentKey: crdt.parentKey,
|
|
@@ -869,9 +869,9 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
869
869
|
});
|
|
870
870
|
break;
|
|
871
871
|
|
|
872
|
-
case CrdtType.
|
|
872
|
+
case CrdtType.MAP:
|
|
873
873
|
ops.push({
|
|
874
|
-
type:
|
|
874
|
+
type: OpCode.CREATE_MAP,
|
|
875
875
|
id: id,
|
|
876
876
|
parentId: crdt.parentId,
|
|
877
877
|
parentKey: crdt.parentKey
|
|
@@ -960,7 +960,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
960
960
|
id: this._id,
|
|
961
961
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
962
962
|
intent: intent,
|
|
963
|
-
type:
|
|
963
|
+
type: OpCode.CREATE_OBJECT,
|
|
964
964
|
parentId: parentId,
|
|
965
965
|
parentKey: parentKey,
|
|
966
966
|
data: {}
|
|
@@ -970,7 +970,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
970
970
|
return ops;
|
|
971
971
|
}
|
|
972
972
|
static _deserialize([id, item], parentToChildren, doc) {
|
|
973
|
-
if (item.type !== CrdtType.
|
|
973
|
+
if (item.type !== CrdtType.OBJECT) throw new Error(`Tried to deserialize a record but item type is "${item.type}"`);
|
|
974
974
|
const liveObj = new LiveObject(item.data);
|
|
975
975
|
return liveObj._attach(id, doc), this._deserializeChildren(liveObj, parentToChildren, doc);
|
|
976
976
|
}
|
|
@@ -1006,11 +1006,11 @@ class LiveObject extends AbstractCrdt {
|
|
|
1006
1006
|
let reverse;
|
|
1007
1007
|
return isCrdt(previousValue) ? (reverse = previousValue._serialize(this._id, key),
|
|
1008
1008
|
previousValue._detach()) : reverse = void 0 === previousValue ? [ {
|
|
1009
|
-
type:
|
|
1009
|
+
type: OpCode.DELETE_OBJECT_KEY,
|
|
1010
1010
|
id: this._id,
|
|
1011
1011
|
key: key
|
|
1012
1012
|
} ] : [ {
|
|
1013
|
-
type:
|
|
1013
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1014
1014
|
id: this._id,
|
|
1015
1015
|
data: {
|
|
1016
1016
|
[key]: previousValue
|
|
@@ -1059,14 +1059,14 @@ class LiveObject extends AbstractCrdt {
|
|
|
1059
1059
|
for (const value of this._map.values()) isCrdt(value) && value._detach();
|
|
1060
1060
|
}
|
|
1061
1061
|
_apply(op, isLocal) {
|
|
1062
|
-
return op.type ===
|
|
1062
|
+
return op.type === OpCode.UPDATE_OBJECT ? this._applyUpdate(op, isLocal) : op.type === OpCode.DELETE_OBJECT_KEY ? this._applyDeleteObjectKey(op) : super._apply(op, isLocal);
|
|
1063
1063
|
}
|
|
1064
1064
|
_toSerializedCrdt() {
|
|
1065
1065
|
var _a;
|
|
1066
1066
|
const data = {};
|
|
1067
1067
|
for (const [key, value] of this._map) value instanceof AbstractCrdt == !1 && (data[key] = value);
|
|
1068
1068
|
return {
|
|
1069
|
-
type: CrdtType.
|
|
1069
|
+
type: CrdtType.OBJECT,
|
|
1070
1070
|
parentId: null === (_a = this._parent) || void 0 === _a ? void 0 : _a._id,
|
|
1071
1071
|
parentKey: this._parentKey,
|
|
1072
1072
|
data: data
|
|
@@ -1075,7 +1075,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1075
1075
|
_applyUpdate(op, isLocal) {
|
|
1076
1076
|
let isModified = !1;
|
|
1077
1077
|
const reverse = [], reverseUpdate = {
|
|
1078
|
-
type:
|
|
1078
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1079
1079
|
id: this._id,
|
|
1080
1080
|
data: {}
|
|
1081
1081
|
};
|
|
@@ -1084,7 +1084,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1084
1084
|
const oldValue = this._map.get(key);
|
|
1085
1085
|
oldValue instanceof AbstractCrdt ? (reverse.push(...oldValue._serialize(this._id, key)),
|
|
1086
1086
|
oldValue._detach()) : void 0 !== oldValue ? reverseUpdate.data[key] = oldValue : void 0 === oldValue && reverse.push({
|
|
1087
|
-
type:
|
|
1087
|
+
type: OpCode.DELETE_OBJECT_KEY,
|
|
1088
1088
|
id: this._id,
|
|
1089
1089
|
key: key
|
|
1090
1090
|
});
|
|
@@ -1129,7 +1129,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1129
1129
|
const oldValue = this._map.get(key);
|
|
1130
1130
|
let reverse = [];
|
|
1131
1131
|
return isCrdt(oldValue) ? (reverse = oldValue._serialize(this._id, op.key), oldValue._detach()) : void 0 !== oldValue && (reverse = [ {
|
|
1132
|
-
type:
|
|
1132
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1133
1133
|
id: this._id,
|
|
1134
1134
|
data: {
|
|
1135
1135
|
[key]: oldValue
|
|
@@ -1169,7 +1169,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1169
1169
|
void this._map.delete(keyAsString);
|
|
1170
1170
|
let reverse;
|
|
1171
1171
|
oldValue instanceof AbstractCrdt ? (oldValue._detach(), reverse = oldValue._serialize(this._id, keyAsString)) : reverse = [ {
|
|
1172
|
-
type:
|
|
1172
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1173
1173
|
data: {
|
|
1174
1174
|
[keyAsString]: oldValue
|
|
1175
1175
|
},
|
|
@@ -1185,7 +1185,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
1187
1187
|
}), this._doc.dispatch([ {
|
|
1188
|
-
type:
|
|
1188
|
+
type: OpCode.DELETE_OBJECT_KEY,
|
|
1189
1189
|
key: keyAsString,
|
|
1190
1190
|
id: this._id,
|
|
1191
1191
|
opId: this._doc.generateOpId()
|
|
@@ -1203,14 +1203,14 @@ class LiveObject extends AbstractCrdt {
|
|
|
1203
1203
|
}
|
|
1204
1204
|
const ops = [], reverseOps = [], opId = this._doc.generateOpId(), updatedProps = {}, reverseUpdateOp = {
|
|
1205
1205
|
id: this._id,
|
|
1206
|
-
type:
|
|
1206
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1207
1207
|
data: {}
|
|
1208
1208
|
}, updateDelta = {};
|
|
1209
1209
|
for (const key in overrides) {
|
|
1210
1210
|
const oldValue = this._map.get(key);
|
|
1211
1211
|
oldValue instanceof AbstractCrdt ? (reverseOps.push(...oldValue._serialize(this._id, key)),
|
|
1212
1212
|
oldValue._detach()) : void 0 === oldValue ? reverseOps.push({
|
|
1213
|
-
type:
|
|
1213
|
+
type: OpCode.DELETE_OBJECT_KEY,
|
|
1214
1214
|
id: this._id,
|
|
1215
1215
|
key: key
|
|
1216
1216
|
}) : reverseUpdateOp.data[key] = oldValue;
|
|
@@ -1228,7 +1228,7 @@ class LiveObject extends AbstractCrdt {
|
|
|
1228
1228
|
0 !== Object.keys(updatedProps).length && ops.unshift({
|
|
1229
1229
|
opId: opId,
|
|
1230
1230
|
id: this._id,
|
|
1231
|
-
type:
|
|
1231
|
+
type: OpCode.UPDATE_OBJECT,
|
|
1232
1232
|
data: updatedProps
|
|
1233
1233
|
});
|
|
1234
1234
|
const storageUpdates = new Map;
|
|
@@ -1240,4 +1240,4 @@ class LiveObject extends AbstractCrdt {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
}
|
|
1242
1242
|
|
|
1243
|
-
export { AbstractCrdt as A,
|
|
1243
|
+
export { AbstractCrdt as A, ClientMsgCode as C, LiveObject as L, OpCode as O, ServerMsgCode as S, WebsocketCloseCodes as W, isSameNodeOrChildOf as a, LiveList as b, isJsonArray as c, compact as d, isJsonObject as e, deprecateIf as f, getTreesDiffOperations as g, LiveMap as h, isTokenValid as i, LiveRegister as j, findNonSerializableValue as k, deprecate as l, mergeStorageUpdates as m, errorIf as n, CrdtType as o, parseJson as p, comparePosition as q, remove as r, makePosition as s, throwUsageError as t };
|