@liveblocks/client 0.16.8 → 0.16.11
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.d.ts +13 -1
- package/index.js +27 -27
- package/index.mjs +28 -31
- package/internal.d.ts +116 -66
- package/internal.js +11 -9
- package/internal.mjs +2 -2
- package/package.json +1 -1
- package/shared.d.ts +6 -1
- package/shared.js +118 -100
- package/shared.mjs +108 -86
package/internal.js
CHANGED
|
@@ -140,34 +140,36 @@ function patchImmutableNode(state, path, update) {
|
|
|
140
140
|
_extends2));
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
Object.defineProperty(exports, "
|
|
143
|
+
Object.defineProperty(exports, "ClientMsgCode", {
|
|
144
144
|
enumerable: !0,
|
|
145
145
|
get: function() {
|
|
146
|
-
return LiveObject.
|
|
146
|
+
return LiveObject.ClientMsgCode;
|
|
147
147
|
}
|
|
148
148
|
}), Object.defineProperty(exports, "CrdtType", {
|
|
149
149
|
enumerable: !0,
|
|
150
150
|
get: function() {
|
|
151
151
|
return LiveObject.CrdtType;
|
|
152
152
|
}
|
|
153
|
-
}), Object.defineProperty(exports, "
|
|
153
|
+
}), Object.defineProperty(exports, "OpCode", {
|
|
154
154
|
enumerable: !0,
|
|
155
155
|
get: function() {
|
|
156
|
-
return LiveObject.
|
|
156
|
+
return LiveObject.OpCode;
|
|
157
157
|
}
|
|
158
|
-
}), Object.defineProperty(exports, "
|
|
158
|
+
}), Object.defineProperty(exports, "ServerMsgCode", {
|
|
159
159
|
enumerable: !0,
|
|
160
160
|
get: function() {
|
|
161
|
-
return LiveObject.
|
|
161
|
+
return LiveObject.ServerMsgCode;
|
|
162
162
|
}
|
|
163
163
|
}), Object.defineProperty(exports, "WebsocketCloseCodes", {
|
|
164
164
|
enumerable: !0,
|
|
165
165
|
get: function() {
|
|
166
166
|
return LiveObject.WebsocketCloseCodes;
|
|
167
167
|
}
|
|
168
|
-
}), exports.
|
|
169
|
-
exports.
|
|
170
|
-
exports.
|
|
168
|
+
}), exports.assertNever = LiveObject.assertNever, exports.comparePosition = LiveObject.comparePosition,
|
|
169
|
+
exports.deprecate = LiveObject.deprecate, exports.deprecateIf = LiveObject.deprecateIf,
|
|
170
|
+
exports.errorIf = LiveObject.errorIf, exports.isChildCrdt = LiveObject.isChildCrdt,
|
|
171
|
+
exports.isRootCrdt = LiveObject.isRootCrdt, exports.makePosition = LiveObject.makePosition,
|
|
172
|
+
exports.parseJson = LiveObject.parseJson, exports.throwUsageError = LiveObject.throwUsageError,
|
|
171
173
|
exports.lsonToJson = lsonToJson, exports.patchImmutableObject = function(state, updates) {
|
|
172
174
|
return updates.reduce((function(state, update) {
|
|
173
175
|
return function(state, update) {
|
package/internal.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { L as LiveObject, b as LiveList,
|
|
1
|
+
import { L as LiveObject, b as LiveList, j as LiveMap, k as LiveRegister, A as AbstractCrdt, l as findNonSerializableValue } from "./shared.mjs";
|
|
2
2
|
|
|
3
|
-
export { C as
|
|
3
|
+
export { C as ClientMsgCode, q as CrdtType, O as OpCode, S as ServerMsgCode, W as WebsocketCloseCodes, w as assertNever, s as comparePosition, n as deprecate, h as deprecateIf, o as errorIf, v as isChildCrdt, f as isRootCrdt, u as makePosition, p as parseJson, t as throwUsageError } from "./shared.mjs";
|
|
4
4
|
|
|
5
5
|
function lsonObjectToJson(obj) {
|
|
6
6
|
const result = {};
|
package/package.json
CHANGED
package/shared.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ declare type JsonArray = Json[];
|
|
|
14
14
|
declare type JsonObject = {
|
|
15
15
|
[key: string]: Json | undefined;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Alternative to JSON.parse() that will not throw in production. If the passed
|
|
19
|
+
* string cannot be parsed, this will return `undefined`.
|
|
20
|
+
*/
|
|
21
|
+
declare function parseJson(rawMessage: string): Json | undefined;
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
@@ -780,4 +785,4 @@ declare class LiveObject<O extends LsonObject = LsonObject> extends AbstractCrdt
|
|
|
780
785
|
update(overrides: Partial<O>): void;
|
|
781
786
|
}
|
|
782
787
|
|
|
783
|
-
export { AbstractCrdt as A, BroadcastOptions as B, ClientOptions as C, History as H, Json as J, LiveObject as L, Others as O, Presence as P, Room as R, StorageUpdate as S, User as U, Client as a, LiveMap as b, LiveList as c, JsonObject as d, Lson as e, LsonObject as f, Resolve as g, RoomInitializers as h };
|
|
788
|
+
export { AbstractCrdt as A, BroadcastOptions as B, ClientOptions as C, History as H, Json as J, LiveObject as L, Others as O, Presence as P, Room as R, StorageUpdate as S, User as U, Client as a, LiveMap as b, LiveList as c, JsonObject as d, Lson as e, LsonObject as f, Resolve as g, RoomInitializers as h, parseJson as p };
|
package/shared.js
CHANGED
|
@@ -122,23 +122,27 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
122
122
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
var
|
|
125
|
+
var ServerMsgCode, ClientMsgCode, CrdtType, OpCode, WebsocketCloseCodes;
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
function isChildCrdt(crdt) {
|
|
128
|
+
return void 0 !== crdt.parentId && void 0 !== crdt.parentKey;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exports.ServerMsgCode = void 0, (ServerMsgCode = exports.ServerMsgCode || (exports.ServerMsgCode = {}))[ServerMsgCode.UPDATE_PRESENCE = 100] = "UPDATE_PRESENCE",
|
|
132
|
+
ServerMsgCode[ServerMsgCode.USER_JOINED = 101] = "USER_JOINED", ServerMsgCode[ServerMsgCode.USER_LEFT = 102] = "USER_LEFT",
|
|
133
|
+
ServerMsgCode[ServerMsgCode.BROADCASTED_EVENT = 103] = "BROADCASTED_EVENT", ServerMsgCode[ServerMsgCode.ROOM_STATE = 104] = "ROOM_STATE",
|
|
134
|
+
ServerMsgCode[ServerMsgCode.INITIAL_STORAGE_STATE = 200] = "INITIAL_STORAGE_STATE",
|
|
135
|
+
ServerMsgCode[ServerMsgCode.UPDATE_STORAGE = 201] = "UPDATE_STORAGE", exports.ClientMsgCode = void 0,
|
|
136
|
+
(ClientMsgCode = exports.ClientMsgCode || (exports.ClientMsgCode = {}))[ClientMsgCode.UPDATE_PRESENCE = 100] = "UPDATE_PRESENCE",
|
|
137
|
+
ClientMsgCode[ClientMsgCode.BROADCAST_EVENT = 103] = "BROADCAST_EVENT", ClientMsgCode[ClientMsgCode.FETCH_STORAGE = 200] = "FETCH_STORAGE",
|
|
138
|
+
ClientMsgCode[ClientMsgCode.UPDATE_STORAGE = 201] = "UPDATE_STORAGE", exports.CrdtType = void 0,
|
|
139
|
+
(CrdtType = exports.CrdtType || (exports.CrdtType = {}))[CrdtType.OBJECT = 0] = "OBJECT",
|
|
140
|
+
CrdtType[CrdtType.LIST = 1] = "LIST", CrdtType[CrdtType.MAP = 2] = "MAP", CrdtType[CrdtType.REGISTER = 3] = "REGISTER",
|
|
141
|
+
exports.OpCode = void 0, (OpCode = exports.OpCode || (exports.OpCode = {}))[OpCode.INIT = 0] = "INIT",
|
|
142
|
+
OpCode[OpCode.SET_PARENT_KEY = 1] = "SET_PARENT_KEY", OpCode[OpCode.CREATE_LIST = 2] = "CREATE_LIST",
|
|
143
|
+
OpCode[OpCode.UPDATE_OBJECT = 3] = "UPDATE_OBJECT", OpCode[OpCode.CREATE_OBJECT = 4] = "CREATE_OBJECT",
|
|
144
|
+
OpCode[OpCode.DELETE_CRDT = 5] = "DELETE_CRDT", OpCode[OpCode.DELETE_OBJECT_KEY = 6] = "DELETE_OBJECT_KEY",
|
|
145
|
+
OpCode[OpCode.CREATE_MAP = 7] = "CREATE_MAP", OpCode[OpCode.CREATE_REGISTER = 8] = "CREATE_REGISTER",
|
|
142
146
|
exports.WebsocketCloseCodes = void 0, (WebsocketCloseCodes = exports.WebsocketCloseCodes || (exports.WebsocketCloseCodes = {}))[WebsocketCloseCodes.CLOSE_ABNORMAL = 1006] = "CLOSE_ABNORMAL",
|
|
143
147
|
WebsocketCloseCodes[WebsocketCloseCodes.INVALID_MESSAGE_FORMAT = 4e3] = "INVALID_MESSAGE_FORMAT",
|
|
144
148
|
WebsocketCloseCodes[WebsocketCloseCodes.NOT_ALLOWED = 4001] = "NOT_ALLOWED", WebsocketCloseCodes[WebsocketCloseCodes.MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS",
|
|
@@ -153,7 +157,7 @@ var AbstractCrdt = function() {
|
|
|
153
157
|
}
|
|
154
158
|
var _proto = AbstractCrdt.prototype;
|
|
155
159
|
return _proto._apply = function(op, _isLocal) {
|
|
156
|
-
return op.type === exports.
|
|
160
|
+
return op.type === exports.OpCode.DELETE_CRDT && null != this._parent && null != this._parentKey ? this._parent._detachChild(this) : {
|
|
157
161
|
modified: !1
|
|
158
162
|
};
|
|
159
163
|
}, _proto._setParentLink = function(parent, key) {
|
|
@@ -216,16 +220,14 @@ var _Symbol$iterator$1, _Symbol$iterator2, LiveRegister = function(_AbstractCrdt
|
|
|
216
220
|
_this;
|
|
217
221
|
}
|
|
218
222
|
_inheritsLoose(LiveRegister, _AbstractCrdt), LiveRegister._deserialize = function(_ref, _parentToChildren, doc) {
|
|
219
|
-
var id = _ref[0],
|
|
220
|
-
if (item.type !== exports.CrdtType.Register) throw new Error('Tried to deserialize a map but item type is "' + item.type + '"');
|
|
221
|
-
var register = new LiveRegister(item.data);
|
|
223
|
+
var id = _ref[0], register = new LiveRegister(_ref[1].data);
|
|
222
224
|
return register._attach(id, doc), register;
|
|
223
225
|
};
|
|
224
226
|
var _proto = LiveRegister.prototype;
|
|
225
227
|
return _proto._serialize = function(parentId, parentKey, doc, intent) {
|
|
226
228
|
if (null == this._id || null == parentId || null == parentKey) throw new Error("Cannot serialize register if parentId or parentKey is undefined");
|
|
227
229
|
return [ {
|
|
228
|
-
type: exports.
|
|
230
|
+
type: exports.OpCode.CREATE_REGISTER,
|
|
229
231
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
230
232
|
id: this._id,
|
|
231
233
|
intent: intent,
|
|
@@ -236,7 +238,7 @@ var _Symbol$iterator$1, _Symbol$iterator2, LiveRegister = function(_AbstractCrdt
|
|
|
236
238
|
}, _proto._toSerializedCrdt = function() {
|
|
237
239
|
var _this$_parent;
|
|
238
240
|
return {
|
|
239
|
-
type: exports.CrdtType.
|
|
241
|
+
type: exports.CrdtType.REGISTER,
|
|
240
242
|
parentId: null == (_this$_parent = this._parent) ? void 0 : _this$_parent._id,
|
|
241
243
|
parentKey: this._parentKey,
|
|
242
244
|
data: this.data
|
|
@@ -328,8 +330,8 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
328
330
|
void 0 === items && (items = []), (_this = _AbstractCrdt.call(this) || this)._items = void 0,
|
|
329
331
|
_this._items = [];
|
|
330
332
|
for (var position = void 0, i = 0; i < items.length; i++) {
|
|
331
|
-
var newPosition = makePosition(position),
|
|
332
|
-
_this._items.push([
|
|
333
|
+
var newPosition = makePosition(position), item = selfOrRegister(items[i]);
|
|
334
|
+
_this._items.push([ item, newPosition ]), position = newPosition;
|
|
333
335
|
}
|
|
334
336
|
return _this;
|
|
335
337
|
}
|
|
@@ -355,7 +357,7 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
355
357
|
id: this._id,
|
|
356
358
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
357
359
|
intent: intent,
|
|
358
|
-
type: exports.
|
|
360
|
+
type: exports.OpCode.CREATE_LIST,
|
|
359
361
|
parentId: parentId,
|
|
360
362
|
parentKey: parentKey
|
|
361
363
|
};
|
|
@@ -423,7 +425,7 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
423
425
|
}));
|
|
424
426
|
return {
|
|
425
427
|
reverse: [ {
|
|
426
|
-
type: exports.
|
|
428
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
427
429
|
id: id
|
|
428
430
|
} ],
|
|
429
431
|
modified: {
|
|
@@ -485,7 +487,7 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
485
487
|
} ]
|
|
486
488
|
},
|
|
487
489
|
reverse: [ {
|
|
488
|
-
type: exports.
|
|
490
|
+
type: exports.OpCode.SET_PARENT_KEY,
|
|
489
491
|
id: null == item ? void 0 : item[0]._id,
|
|
490
492
|
parentKey: previousKey
|
|
491
493
|
} ]
|
|
@@ -495,7 +497,7 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
495
497
|
}, _proto._toSerializedCrdt = function() {
|
|
496
498
|
var _this$_parent;
|
|
497
499
|
return {
|
|
498
|
-
type: exports.CrdtType.
|
|
500
|
+
type: exports.CrdtType.LIST,
|
|
499
501
|
parentId: null == (_this$_parent = this._parent) ? void 0 : _this$_parent._id,
|
|
500
502
|
parentKey: this._parentKey
|
|
501
503
|
};
|
|
@@ -511,8 +513,8 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
511
513
|
return entry[1] === position;
|
|
512
514
|
}));
|
|
513
515
|
if (this._doc && this._id) {
|
|
514
|
-
var
|
|
515
|
-
value._attach(
|
|
516
|
+
var id = this._doc.generateId();
|
|
517
|
+
value._attach(id, this._doc);
|
|
516
518
|
var storageUpdates = new Map;
|
|
517
519
|
storageUpdates.set(this._id, {
|
|
518
520
|
node: this,
|
|
@@ -523,8 +525,8 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
523
525
|
type: "insert"
|
|
524
526
|
} ]
|
|
525
527
|
}), this._doc.dispatch(value._serialize(this._id, position, this._doc), [ {
|
|
526
|
-
type: exports.
|
|
527
|
-
id:
|
|
528
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
529
|
+
id: id
|
|
528
530
|
} ], storageUpdates);
|
|
529
531
|
}
|
|
530
532
|
}, _proto.move = function(index, targetIndex) {
|
|
@@ -555,12 +557,12 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
555
557
|
type: "move"
|
|
556
558
|
} ]
|
|
557
559
|
}), this._doc.dispatch([ {
|
|
558
|
-
type: exports.
|
|
560
|
+
type: exports.OpCode.SET_PARENT_KEY,
|
|
559
561
|
id: item[0]._id,
|
|
560
562
|
opId: this._doc.generateOpId(),
|
|
561
563
|
parentKey: position
|
|
562
564
|
} ], [ {
|
|
563
|
-
type: exports.
|
|
565
|
+
type: exports.OpCode.SET_PARENT_KEY,
|
|
564
566
|
id: item[0]._id,
|
|
565
567
|
parentKey: previousPosition
|
|
566
568
|
} ], storageUpdates);
|
|
@@ -582,21 +584,20 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
582
584
|
}), this._doc.dispatch([ {
|
|
583
585
|
id: childRecordId,
|
|
584
586
|
opId: this._doc.generateOpId(),
|
|
585
|
-
type: exports.
|
|
587
|
+
type: exports.OpCode.DELETE_CRDT
|
|
586
588
|
} ], item[0]._serialize(this._id, item[1]), storageUpdates);
|
|
587
589
|
}
|
|
588
590
|
}
|
|
589
591
|
}, _proto.clear = function() {
|
|
590
592
|
if (this._doc) {
|
|
591
593
|
for (var _step5, ops = [], reverseOps = [], updateDelta = [], i = 0, _iterator5 = _createForOfIteratorHelperLoose(this._items); !(_step5 = _iterator5()).done; ) {
|
|
592
|
-
var
|
|
593
|
-
|
|
594
|
-
var childId =
|
|
594
|
+
var item = _step5.value;
|
|
595
|
+
item[0]._detach();
|
|
596
|
+
var childId = item[0]._id;
|
|
595
597
|
childId && (ops.push({
|
|
596
598
|
id: childId,
|
|
597
|
-
type: exports.
|
|
598
|
-
}), reverseOps.push.apply(reverseOps,
|
|
599
|
-
updateDelta.push({
|
|
599
|
+
type: exports.OpCode.DELETE_CRDT
|
|
600
|
+
}), reverseOps.push.apply(reverseOps, item[0]._serialize(this._id, item[1])), updateDelta.push({
|
|
600
601
|
index: i,
|
|
601
602
|
type: "delete"
|
|
602
603
|
})), i++;
|
|
@@ -620,8 +621,8 @@ var LiveList = function(_AbstractCrdt) {
|
|
|
620
621
|
existingItem._detach();
|
|
621
622
|
var value = selfOrRegister(item);
|
|
622
623
|
if (value._setParentLink(this, position), this._items[index][0] = value, this._doc && this._id) {
|
|
623
|
-
var
|
|
624
|
-
value._attach(
|
|
624
|
+
var id = this._doc.generateId();
|
|
625
|
+
value._attach(id, this._doc);
|
|
625
626
|
var storageUpdates = new Map;
|
|
626
627
|
storageUpdates.set(this._id, {
|
|
627
628
|
node: this,
|
|
@@ -728,7 +729,7 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
728
729
|
var ops = [], op = {
|
|
729
730
|
id: this._id,
|
|
730
731
|
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
731
|
-
type: exports.
|
|
732
|
+
type: exports.OpCode.CREATE_MAP,
|
|
732
733
|
intent: intent,
|
|
733
734
|
parentId: parentId,
|
|
734
735
|
parentKey: parentKey
|
|
@@ -740,8 +741,8 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
740
741
|
}
|
|
741
742
|
return ops;
|
|
742
743
|
}, LiveMap._deserialize = function(_ref, parentToChildren, doc) {
|
|
743
|
-
var id = _ref[0]
|
|
744
|
-
|
|
744
|
+
var id = _ref[0];
|
|
745
|
+
_ref[1];
|
|
745
746
|
var map = new LiveMap;
|
|
746
747
|
map._attach(id, doc);
|
|
747
748
|
var children = parentToChildren.get(id);
|
|
@@ -770,7 +771,7 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
770
771
|
};
|
|
771
772
|
var reverse, previousValue = this._map.get(key);
|
|
772
773
|
return previousValue ? (reverse = previousValue._serialize(this._id, key), previousValue._detach()) : reverse = [ {
|
|
773
|
-
type: exports.
|
|
774
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
774
775
|
id: id
|
|
775
776
|
} ], child._setParentLink(this, key), child._attach(id, this._doc), this._map.set(key, child),
|
|
776
777
|
{
|
|
@@ -806,7 +807,7 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
806
807
|
}, _proto._toSerializedCrdt = function() {
|
|
807
808
|
var _this$_parent;
|
|
808
809
|
return {
|
|
809
|
-
type: exports.CrdtType.
|
|
810
|
+
type: exports.CrdtType.MAP,
|
|
810
811
|
parentId: null == (_this$_parent = this._parent) ? void 0 : _this$_parent._id,
|
|
811
812
|
parentKey: this._parentKey
|
|
812
813
|
};
|
|
@@ -828,7 +829,7 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
828
829
|
type: "update"
|
|
829
830
|
}, _updates3)
|
|
830
831
|
}), this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue ? oldValue._serialize(this._id, key) : [ {
|
|
831
|
-
type: exports.
|
|
832
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
832
833
|
id: id
|
|
833
834
|
} ], storageUpdates);
|
|
834
835
|
}
|
|
@@ -846,7 +847,7 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
846
847
|
type: "delete"
|
|
847
848
|
}, _updates4)
|
|
848
849
|
}), this._doc.dispatch([ {
|
|
849
|
-
type: exports.
|
|
850
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
850
851
|
id: item._id,
|
|
851
852
|
opId: this._doc.generateOpId()
|
|
852
853
|
} ], item._serialize(this._id, key), storageUpdates);
|
|
@@ -897,33 +898,34 @@ var LiveMap = function(_AbstractCrdt) {
|
|
|
897
898
|
|
|
898
899
|
function creationOpToLiveStructure(op) {
|
|
899
900
|
switch (op.type) {
|
|
900
|
-
case exports.
|
|
901
|
+
case exports.OpCode.CREATE_REGISTER:
|
|
901
902
|
return new LiveRegister(op.data);
|
|
902
903
|
|
|
903
|
-
case exports.
|
|
904
|
+
case exports.OpCode.CREATE_OBJECT:
|
|
904
905
|
return new LiveObject(op.data);
|
|
905
906
|
|
|
906
|
-
case exports.
|
|
907
|
+
case exports.OpCode.CREATE_MAP:
|
|
907
908
|
return new LiveMap;
|
|
908
909
|
|
|
909
|
-
case exports.
|
|
910
|
+
case exports.OpCode.CREATE_LIST:
|
|
910
911
|
return new LiveList;
|
|
911
912
|
}
|
|
912
913
|
}
|
|
913
914
|
|
|
914
|
-
function deserialize(
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
915
|
+
function deserialize(_ref, parentToChildren, doc) {
|
|
916
|
+
var id = _ref[0], crdt = _ref[1];
|
|
917
|
+
switch (crdt.type) {
|
|
918
|
+
case exports.CrdtType.OBJECT:
|
|
919
|
+
return LiveObject._deserialize([ id, crdt ], parentToChildren, doc);
|
|
918
920
|
|
|
919
|
-
case exports.CrdtType.
|
|
920
|
-
return LiveList._deserialize(
|
|
921
|
+
case exports.CrdtType.LIST:
|
|
922
|
+
return LiveList._deserialize([ id, crdt ], parentToChildren, doc);
|
|
921
923
|
|
|
922
|
-
case exports.CrdtType.
|
|
923
|
-
return LiveMap._deserialize(
|
|
924
|
+
case exports.CrdtType.MAP:
|
|
925
|
+
return LiveMap._deserialize([ id, crdt ], parentToChildren, doc);
|
|
924
926
|
|
|
925
|
-
case exports.CrdtType.
|
|
926
|
-
return LiveRegister._deserialize(
|
|
927
|
+
case exports.CrdtType.REGISTER:
|
|
928
|
+
return LiveRegister._deserialize([ id, crdt ], parentToChildren, doc);
|
|
927
929
|
|
|
928
930
|
default:
|
|
929
931
|
throw new Error("Unexpected CRDT type");
|
|
@@ -974,14 +976,20 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
974
976
|
var _proto = LiveObject.prototype;
|
|
975
977
|
return _proto._serialize = function(parentId, parentKey, doc, intent) {
|
|
976
978
|
if (null == this._id) throw new Error("Cannot serialize item is not attached");
|
|
977
|
-
var ops = [], op = {
|
|
979
|
+
var opId = null == doc ? void 0 : doc.generateOpId(), ops = [], op = void 0 !== parentId && void 0 !== parentKey ? {
|
|
980
|
+
type: exports.OpCode.CREATE_OBJECT,
|
|
978
981
|
id: this._id,
|
|
979
|
-
opId:
|
|
982
|
+
opId: opId,
|
|
980
983
|
intent: intent,
|
|
981
|
-
type: exports.OpType.CreateObject,
|
|
982
984
|
parentId: parentId,
|
|
983
985
|
parentKey: parentKey,
|
|
984
986
|
data: {}
|
|
987
|
+
} : {
|
|
988
|
+
type: exports.OpCode.CREATE_OBJECT,
|
|
989
|
+
id: this._id,
|
|
990
|
+
opId: opId,
|
|
991
|
+
intent: intent,
|
|
992
|
+
data: {}
|
|
985
993
|
};
|
|
986
994
|
ops.push(op);
|
|
987
995
|
for (var _step, _iterator = _createForOfIteratorHelperLoose(this._map); !(_step = _iterator()).done; ) {
|
|
@@ -990,9 +998,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
990
998
|
}
|
|
991
999
|
return ops;
|
|
992
1000
|
}, LiveObject._deserialize = function(_ref, parentToChildren, doc) {
|
|
993
|
-
var id = _ref[0],
|
|
994
|
-
if (item.type !== exports.CrdtType.Object) throw new Error('Tried to deserialize a record but item type is "' + item.type + '"');
|
|
995
|
-
var liveObj = new LiveObject(item.data);
|
|
1001
|
+
var id = _ref[0], liveObj = new LiveObject(_ref[1].data);
|
|
996
1002
|
return liveObj._attach(id, doc), this._deserializeChildren(liveObj, parentToChildren, doc);
|
|
997
1003
|
}, LiveObject._deserializeChildren = function(liveObj, parentToChildren, doc) {
|
|
998
1004
|
var children = parentToChildren.get(liveObj._id);
|
|
@@ -1028,13 +1034,13 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1028
1034
|
};
|
|
1029
1035
|
var reverse, previousValue = this._map.get(key);
|
|
1030
1036
|
if (isCrdt(previousValue)) reverse = previousValue._serialize(this._id, key), previousValue._detach(); else if (void 0 === previousValue) reverse = [ {
|
|
1031
|
-
type: exports.
|
|
1037
|
+
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
1032
1038
|
id: this._id,
|
|
1033
1039
|
key: key
|
|
1034
1040
|
} ]; else {
|
|
1035
1041
|
var _data;
|
|
1036
1042
|
reverse = [ {
|
|
1037
|
-
type: exports.
|
|
1043
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1038
1044
|
id: this._id,
|
|
1039
1045
|
data: (_data = {}, _data[key] = previousValue, _data)
|
|
1040
1046
|
} ];
|
|
@@ -1082,21 +1088,24 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1082
1088
|
isCrdt(value) && value._detach();
|
|
1083
1089
|
}
|
|
1084
1090
|
}, _proto._apply = function(op, isLocal) {
|
|
1085
|
-
return op.type === exports.
|
|
1091
|
+
return op.type === exports.OpCode.UPDATE_OBJECT ? this._applyUpdate(op, isLocal) : op.type === exports.OpCode.DELETE_OBJECT_KEY ? this._applyDeleteObjectKey(op) : _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
1086
1092
|
}, _proto._toSerializedCrdt = function() {
|
|
1087
1093
|
for (var _this$_parent, _step7, data = {}, _iterator7 = _createForOfIteratorHelperLoose(this._map); !(_step7 = _iterator7()).done; ) {
|
|
1088
1094
|
var _step7$value = _step7.value, key = _step7$value[0], value = _step7$value[1];
|
|
1089
1095
|
value instanceof AbstractCrdt == !1 && (data[key] = value);
|
|
1090
1096
|
}
|
|
1091
|
-
return {
|
|
1092
|
-
type: exports.CrdtType.
|
|
1093
|
-
parentId:
|
|
1097
|
+
return void 0 !== (null == (_this$_parent = this._parent) ? void 0 : _this$_parent._id) && void 0 !== this._parentKey ? {
|
|
1098
|
+
type: exports.CrdtType.OBJECT,
|
|
1099
|
+
parentId: this._parent._id,
|
|
1094
1100
|
parentKey: this._parentKey,
|
|
1095
1101
|
data: data
|
|
1102
|
+
} : {
|
|
1103
|
+
type: exports.CrdtType.OBJECT,
|
|
1104
|
+
data: data
|
|
1096
1105
|
};
|
|
1097
1106
|
}, _proto._applyUpdate = function(op, isLocal) {
|
|
1098
1107
|
var isModified = !1, reverse = [], reverseUpdate = {
|
|
1099
|
-
type: exports.
|
|
1108
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1100
1109
|
id: this._id,
|
|
1101
1110
|
data: {}
|
|
1102
1111
|
};
|
|
@@ -1104,7 +1113,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1104
1113
|
var oldValue = this._map.get(key);
|
|
1105
1114
|
oldValue instanceof AbstractCrdt ? (reverse.push.apply(reverse, oldValue._serialize(this._id, key)),
|
|
1106
1115
|
oldValue._detach()) : void 0 !== oldValue ? reverseUpdate.data[key] = oldValue : void 0 === oldValue && reverse.push({
|
|
1107
|
-
type: exports.
|
|
1116
|
+
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
1108
1117
|
id: this._id,
|
|
1109
1118
|
key: key
|
|
1110
1119
|
});
|
|
@@ -1149,7 +1158,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1149
1158
|
if (isCrdt(oldValue)) reverse = oldValue._serialize(this._id, op.key), oldValue._detach(); else if (void 0 !== oldValue) {
|
|
1150
1159
|
var _data2;
|
|
1151
1160
|
reverse = [ {
|
|
1152
|
-
type: exports.
|
|
1161
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1153
1162
|
id: this._id,
|
|
1154
1163
|
data: (_data2 = {}, _data2[key] = oldValue, _data2)
|
|
1155
1164
|
} ];
|
|
@@ -1184,7 +1193,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1184
1193
|
void this._map.delete(keyAsString);
|
|
1185
1194
|
var reverse, _data3;
|
|
1186
1195
|
if (oldValue instanceof AbstractCrdt) oldValue._detach(), reverse = oldValue._serialize(this._id, keyAsString); else reverse = [ {
|
|
1187
|
-
type: exports.
|
|
1196
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1188
1197
|
data: (_data3 = {}, _data3[keyAsString] = oldValue, _data3),
|
|
1189
1198
|
id: this._id
|
|
1190
1199
|
} ];
|
|
@@ -1197,7 +1206,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1197
1206
|
type: "delete"
|
|
1198
1207
|
}, _updates4)
|
|
1199
1208
|
}), this._doc.dispatch([ {
|
|
1200
|
-
type: exports.
|
|
1209
|
+
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
1201
1210
|
key: keyAsString,
|
|
1202
1211
|
id: this._id,
|
|
1203
1212
|
opId: this._doc.generateOpId()
|
|
@@ -1208,14 +1217,14 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1208
1217
|
if (null != this._doc && null != this._id) {
|
|
1209
1218
|
var ops = [], reverseOps = [], opId = this._doc.generateOpId(), updatedProps = {}, reverseUpdateOp = {
|
|
1210
1219
|
id: this._id,
|
|
1211
|
-
type: exports.
|
|
1220
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1212
1221
|
data: {}
|
|
1213
1222
|
}, updateDelta = {};
|
|
1214
1223
|
for (var _key3 in overrides) {
|
|
1215
1224
|
var _oldValue2 = this._map.get(_key3);
|
|
1216
1225
|
_oldValue2 instanceof AbstractCrdt ? (reverseOps.push.apply(reverseOps, _oldValue2._serialize(this._id, _key3)),
|
|
1217
1226
|
_oldValue2._detach()) : void 0 === _oldValue2 ? reverseOps.push({
|
|
1218
|
-
type: exports.
|
|
1227
|
+
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
1219
1228
|
id: this._id,
|
|
1220
1229
|
key: _key3
|
|
1221
1230
|
}) : reverseUpdateOp.data[_key3] = _oldValue2;
|
|
@@ -1235,7 +1244,7 @@ var LiveObject = function(_AbstractCrdt) {
|
|
|
1235
1244
|
0 !== Object.keys(updatedProps).length && ops.unshift({
|
|
1236
1245
|
opId: opId,
|
|
1237
1246
|
id: this._id,
|
|
1238
|
-
type: exports.
|
|
1247
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1239
1248
|
data: updatedProps
|
|
1240
1249
|
});
|
|
1241
1250
|
var storageUpdates = new Map;
|
|
@@ -1260,7 +1269,9 @@ exports._extends = _extends, exports._inheritsLoose = _inheritsLoose, exports._o
|
|
|
1260
1269
|
var key, i, target = {}, sourceKeys = Object.keys(source);
|
|
1261
1270
|
for (i = 0; i < sourceKeys.length; i++) key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
|
1262
1271
|
return target;
|
|
1263
|
-
}, exports._wrapNativeSuper = _wrapNativeSuper, exports.
|
|
1272
|
+
}, exports._wrapNativeSuper = _wrapNativeSuper, exports.assertNever = function(_value, errmsg) {
|
|
1273
|
+
throw new Error(errmsg);
|
|
1274
|
+
}, exports.compact = function(items) {
|
|
1264
1275
|
return items.filter((function(item) {
|
|
1265
1276
|
return null != item;
|
|
1266
1277
|
}));
|
|
@@ -1289,23 +1300,23 @@ exports.errorIf = function(condition, message) {
|
|
|
1289
1300
|
var ops = [];
|
|
1290
1301
|
return currentItems.forEach((function(_, id) {
|
|
1291
1302
|
newItems.get(id) || ops.push({
|
|
1292
|
-
type: exports.
|
|
1303
|
+
type: exports.OpCode.DELETE_CRDT,
|
|
1293
1304
|
id: id
|
|
1294
1305
|
});
|
|
1295
1306
|
})), newItems.forEach((function(crdt, id) {
|
|
1296
1307
|
var currentCrdt = currentItems.get(id);
|
|
1297
|
-
if (currentCrdt) crdt.type === exports.CrdtType.
|
|
1298
|
-
type: exports.
|
|
1308
|
+
if (currentCrdt) crdt.type === exports.CrdtType.OBJECT && (currentCrdt.type === exports.CrdtType.OBJECT && JSON.stringify(crdt.data) === JSON.stringify(currentCrdt.data) || ops.push({
|
|
1309
|
+
type: exports.OpCode.UPDATE_OBJECT,
|
|
1299
1310
|
id: id,
|
|
1300
1311
|
data: crdt.data
|
|
1301
|
-
}), crdt.parentKey !== currentCrdt.parentKey && ops.push({
|
|
1302
|
-
type: exports.
|
|
1312
|
+
})), crdt.parentKey !== currentCrdt.parentKey && ops.push({
|
|
1313
|
+
type: exports.OpCode.SET_PARENT_KEY,
|
|
1303
1314
|
id: id,
|
|
1304
1315
|
parentKey: crdt.parentKey
|
|
1305
1316
|
}); else switch (crdt.type) {
|
|
1306
|
-
case exports.CrdtType.
|
|
1317
|
+
case exports.CrdtType.REGISTER:
|
|
1307
1318
|
ops.push({
|
|
1308
|
-
type: exports.
|
|
1319
|
+
type: exports.OpCode.CREATE_REGISTER,
|
|
1309
1320
|
id: id,
|
|
1310
1321
|
parentId: crdt.parentId,
|
|
1311
1322
|
parentKey: crdt.parentKey,
|
|
@@ -1313,35 +1324,42 @@ exports.errorIf = function(condition, message) {
|
|
|
1313
1324
|
});
|
|
1314
1325
|
break;
|
|
1315
1326
|
|
|
1316
|
-
case exports.CrdtType.
|
|
1327
|
+
case exports.CrdtType.LIST:
|
|
1317
1328
|
ops.push({
|
|
1318
|
-
type: exports.
|
|
1329
|
+
type: exports.OpCode.CREATE_LIST,
|
|
1319
1330
|
id: id,
|
|
1320
1331
|
parentId: crdt.parentId,
|
|
1321
1332
|
parentKey: crdt.parentKey
|
|
1322
1333
|
});
|
|
1323
1334
|
break;
|
|
1324
1335
|
|
|
1325
|
-
case exports.CrdtType.
|
|
1326
|
-
ops.push({
|
|
1327
|
-
type: exports.
|
|
1336
|
+
case exports.CrdtType.OBJECT:
|
|
1337
|
+
ops.push(crdt.parentId ? {
|
|
1338
|
+
type: exports.OpCode.CREATE_OBJECT,
|
|
1328
1339
|
id: id,
|
|
1329
1340
|
parentId: crdt.parentId,
|
|
1330
1341
|
parentKey: crdt.parentKey,
|
|
1331
1342
|
data: crdt.data
|
|
1343
|
+
} : {
|
|
1344
|
+
type: exports.OpCode.CREATE_OBJECT,
|
|
1345
|
+
id: id,
|
|
1346
|
+
data: crdt.data
|
|
1332
1347
|
});
|
|
1333
1348
|
break;
|
|
1334
1349
|
|
|
1335
|
-
case exports.CrdtType.
|
|
1350
|
+
case exports.CrdtType.MAP:
|
|
1336
1351
|
ops.push({
|
|
1337
|
-
type: exports.
|
|
1352
|
+
type: exports.OpCode.CREATE_MAP,
|
|
1338
1353
|
id: id,
|
|
1339
1354
|
parentId: crdt.parentId,
|
|
1340
1355
|
parentKey: crdt.parentKey
|
|
1341
1356
|
});
|
|
1342
1357
|
}
|
|
1343
1358
|
})), ops;
|
|
1344
|
-
}, exports.
|
|
1359
|
+
}, exports.isChildCrdt = isChildCrdt, exports.isJsonArray = isJsonArray, exports.isJsonObject = isJsonObject,
|
|
1360
|
+
exports.isRootCrdt = function(crdt) {
|
|
1361
|
+
return crdt.type === exports.CrdtType.OBJECT && !isChildCrdt(crdt);
|
|
1362
|
+
}, exports.isSameNodeOrChildOf = function isSameNodeOrChildOf(node, parent) {
|
|
1345
1363
|
return node === parent || !!node._parent && isSameNodeOrChildOf(node._parent, parent);
|
|
1346
1364
|
}, exports.isTokenValid = function(token) {
|
|
1347
1365
|
var tokenParts = token.split(".");
|