@liveblocks/client 0.15.11-test.1 → 0.16.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.
- package/README.md +15 -3
- package/lib/esm/index.js +468 -451
- package/lib/esm/index.mjs +468 -451
- package/lib/index.d.ts +220 -157
- package/lib/index.js +607 -559
- package/lib/internal.d.ts +110 -16
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -192,48 +192,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
192
192
|
return it.next.bind(it);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
196
|
-
var descriptor = privateMap.get(receiver);
|
|
197
|
-
|
|
198
|
-
if (!descriptor) {
|
|
199
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (descriptor.get) {
|
|
203
|
-
return descriptor.get.call(receiver);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return descriptor.value;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
210
|
-
var descriptor = privateMap.get(receiver);
|
|
211
|
-
|
|
212
|
-
if (!descriptor) {
|
|
213
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (descriptor.set) {
|
|
217
|
-
descriptor.set.call(receiver, value);
|
|
218
|
-
} else {
|
|
219
|
-
if (!descriptor.writable) {
|
|
220
|
-
throw new TypeError("attempted to set read only private field");
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
descriptor.value = value;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return value;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
230
|
-
if (!privateSet.has(receiver)) {
|
|
231
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return fn;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
195
|
var ServerMessageType;
|
|
238
196
|
|
|
239
197
|
(function (ServerMessageType) {
|
|
@@ -291,36 +249,8 @@ var WebsocketCloseCodes;
|
|
|
291
249
|
WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
|
|
292
250
|
})(WebsocketCloseCodes || (WebsocketCloseCodes = {}));
|
|
293
251
|
|
|
294
|
-
var _parent = new WeakMap();
|
|
295
|
-
|
|
296
|
-
var _doc = new WeakMap();
|
|
297
|
-
|
|
298
|
-
var _id = new WeakMap();
|
|
299
|
-
|
|
300
|
-
var _parentKey = new WeakMap();
|
|
301
|
-
|
|
302
252
|
var AbstractCrdt = function () {
|
|
303
|
-
function AbstractCrdt() {
|
|
304
|
-
_parent.set(this, {
|
|
305
|
-
writable: true,
|
|
306
|
-
value: void 0
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
_doc.set(this, {
|
|
310
|
-
writable: true,
|
|
311
|
-
value: void 0
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
_id.set(this, {
|
|
315
|
-
writable: true,
|
|
316
|
-
value: void 0
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
_parentKey.set(this, {
|
|
320
|
-
writable: true,
|
|
321
|
-
value: void 0
|
|
322
|
-
});
|
|
323
|
-
}
|
|
253
|
+
function AbstractCrdt() {}
|
|
324
254
|
|
|
325
255
|
var _proto = AbstractCrdt.prototype;
|
|
326
256
|
|
|
@@ -344,61 +274,57 @@ var AbstractCrdt = function () {
|
|
|
344
274
|
};
|
|
345
275
|
|
|
346
276
|
_proto._setParentLink = function _setParentLink(parent, key) {
|
|
347
|
-
if (
|
|
277
|
+
if (this.__parent != null && this.__parent !== parent) {
|
|
348
278
|
throw new Error("Cannot attach parent if it already exist");
|
|
349
279
|
}
|
|
350
280
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
_classPrivateFieldSet(this, _parent, parent);
|
|
281
|
+
this.__parentKey = key;
|
|
282
|
+
this.__parent = parent;
|
|
354
283
|
};
|
|
355
284
|
|
|
356
285
|
_proto._attach = function _attach(id, doc) {
|
|
357
|
-
if (
|
|
286
|
+
if (this.__id || this.__doc) {
|
|
358
287
|
throw new Error("Cannot attach if CRDT is already attached");
|
|
359
288
|
}
|
|
360
289
|
|
|
361
290
|
doc.addItem(id, this);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
_classPrivateFieldSet(this, _doc, doc);
|
|
291
|
+
this.__id = id;
|
|
292
|
+
this.__doc = doc;
|
|
366
293
|
};
|
|
367
294
|
|
|
368
295
|
_proto._detach = function _detach() {
|
|
369
|
-
if (
|
|
370
|
-
|
|
296
|
+
if (this.__doc && this.__id) {
|
|
297
|
+
this.__doc.deleteItem(this.__id);
|
|
371
298
|
}
|
|
372
299
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
_classPrivateFieldSet(this, _doc, undefined);
|
|
300
|
+
this.__parent = undefined;
|
|
301
|
+
this.__doc = undefined;
|
|
376
302
|
};
|
|
377
303
|
|
|
378
304
|
_createClass(AbstractCrdt, [{
|
|
379
305
|
key: "_doc",
|
|
380
306
|
get: function get() {
|
|
381
|
-
return
|
|
307
|
+
return this.__doc;
|
|
382
308
|
}
|
|
383
309
|
}, {
|
|
384
310
|
key: "roomId",
|
|
385
311
|
get: function get() {
|
|
386
|
-
return
|
|
312
|
+
return this.__doc ? this.__doc.roomId : null;
|
|
387
313
|
}
|
|
388
314
|
}, {
|
|
389
315
|
key: "_id",
|
|
390
316
|
get: function get() {
|
|
391
|
-
return
|
|
317
|
+
return this.__id;
|
|
392
318
|
}
|
|
393
319
|
}, {
|
|
394
320
|
key: "_parent",
|
|
395
321
|
get: function get() {
|
|
396
|
-
return
|
|
322
|
+
return this.__parent;
|
|
397
323
|
}
|
|
398
324
|
}, {
|
|
399
325
|
key: "_parentKey",
|
|
400
326
|
get: function get() {
|
|
401
|
-
return
|
|
327
|
+
return this.__parentKey;
|
|
402
328
|
}
|
|
403
329
|
}]);
|
|
404
330
|
|
|
@@ -532,8 +458,6 @@ function compare(posA, posB) {
|
|
|
532
458
|
throw new Error("Impossible to compare similar position \"" + posA + "\" and \"" + posB + "\"");
|
|
533
459
|
}
|
|
534
460
|
|
|
535
|
-
var _data = new WeakMap();
|
|
536
|
-
|
|
537
461
|
var LiveRegister = function (_AbstractCrdt) {
|
|
538
462
|
_inheritsLoose(LiveRegister, _AbstractCrdt);
|
|
539
463
|
|
|
@@ -541,18 +465,11 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
541
465
|
var _this;
|
|
542
466
|
|
|
543
467
|
_this = _AbstractCrdt.call(this) || this;
|
|
544
|
-
|
|
545
|
-
_data.set(_assertThisInitialized(_this), {
|
|
546
|
-
writable: true,
|
|
547
|
-
value: void 0
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
_classPrivateFieldSet(_assertThisInitialized(_this), _data, data);
|
|
551
|
-
|
|
468
|
+
_this._data = data;
|
|
552
469
|
return _this;
|
|
553
470
|
}
|
|
554
471
|
|
|
555
|
-
LiveRegister._deserialize = function _deserialize(_ref,
|
|
472
|
+
LiveRegister._deserialize = function _deserialize(_ref, _parentToChildren, doc) {
|
|
556
473
|
var id = _ref[0],
|
|
557
474
|
item = _ref[1];
|
|
558
475
|
|
|
@@ -569,7 +486,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
569
486
|
|
|
570
487
|
var _proto = LiveRegister.prototype;
|
|
571
488
|
|
|
572
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
489
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
573
490
|
if (this._id == null || parentId == null || parentKey == null) {
|
|
574
491
|
throw new Error("Cannot serialize register if parentId or parentKey is undefined");
|
|
575
492
|
}
|
|
@@ -578,6 +495,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
578
495
|
type: OpType.CreateRegister,
|
|
579
496
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
580
497
|
id: this._id,
|
|
498
|
+
intent: intent,
|
|
581
499
|
parentId: parentId,
|
|
582
500
|
parentKey: parentKey,
|
|
583
501
|
data: this.data
|
|
@@ -595,7 +513,7 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
595
513
|
};
|
|
596
514
|
};
|
|
597
515
|
|
|
598
|
-
_proto._attachChild = function _attachChild(
|
|
516
|
+
_proto._attachChild = function _attachChild(_op, _isLocal) {
|
|
599
517
|
throw new Error("Method not implemented.");
|
|
600
518
|
};
|
|
601
519
|
|
|
@@ -610,18 +528,13 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
610
528
|
_createClass(LiveRegister, [{
|
|
611
529
|
key: "data",
|
|
612
530
|
get: function get() {
|
|
613
|
-
return
|
|
531
|
+
return this._data;
|
|
614
532
|
}
|
|
615
533
|
}]);
|
|
616
534
|
|
|
617
535
|
return LiveRegister;
|
|
618
536
|
}(AbstractCrdt);
|
|
619
537
|
|
|
620
|
-
var _Symbol$iterator$1, _Symbol$iterator2;
|
|
621
|
-
|
|
622
|
-
var _items = new WeakMap();
|
|
623
|
-
|
|
624
|
-
_Symbol$iterator$1 = Symbol.iterator;
|
|
625
538
|
var LiveList = function (_AbstractCrdt) {
|
|
626
539
|
_inheritsLoose(LiveList, _AbstractCrdt);
|
|
627
540
|
|
|
@@ -633,12 +546,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
633
546
|
}
|
|
634
547
|
|
|
635
548
|
_this = _AbstractCrdt.call(this) || this;
|
|
636
|
-
|
|
637
|
-
_items.set(_assertThisInitialized(_this), {
|
|
638
|
-
writable: true,
|
|
639
|
-
value: []
|
|
640
|
-
});
|
|
641
|
-
|
|
549
|
+
_this._items = [];
|
|
642
550
|
var position = undefined;
|
|
643
551
|
|
|
644
552
|
for (var i = 0; i < items.length; i++) {
|
|
@@ -646,7 +554,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
646
554
|
|
|
647
555
|
var _item = selfOrRegister(items[i]);
|
|
648
556
|
|
|
649
|
-
|
|
557
|
+
_this._items.push([_item, newPosition]);
|
|
650
558
|
|
|
651
559
|
position = newPosition;
|
|
652
560
|
}
|
|
@@ -672,9 +580,9 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
672
580
|
|
|
673
581
|
child._setParentLink(list, entry[1].parentKey);
|
|
674
582
|
|
|
675
|
-
|
|
583
|
+
list._items.push([child, entry[1].parentKey]);
|
|
676
584
|
|
|
677
|
-
|
|
585
|
+
list._items.sort(function (itemA, itemB) {
|
|
678
586
|
return compare(itemA[1], itemB[1]);
|
|
679
587
|
});
|
|
680
588
|
}
|
|
@@ -684,7 +592,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
684
592
|
|
|
685
593
|
var _proto = LiveList.prototype;
|
|
686
594
|
|
|
687
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
595
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
688
596
|
if (this._id == null) {
|
|
689
597
|
throw new Error("Cannot serialize item is not attached");
|
|
690
598
|
}
|
|
@@ -697,13 +605,14 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
697
605
|
var op = {
|
|
698
606
|
id: this._id,
|
|
699
607
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
608
|
+
intent: intent,
|
|
700
609
|
type: OpType.CreateList,
|
|
701
610
|
parentId: parentId,
|
|
702
611
|
parentKey: parentKey
|
|
703
612
|
};
|
|
704
613
|
ops.push(op);
|
|
705
614
|
|
|
706
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
615
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this._items), _step2; !(_step2 = _iterator2()).done;) {
|
|
707
616
|
var _step2$value = _step2.value,
|
|
708
617
|
_value = _step2$value[0],
|
|
709
618
|
key = _step2$value[1];
|
|
@@ -714,7 +623,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
714
623
|
};
|
|
715
624
|
|
|
716
625
|
_proto._indexOfPosition = function _indexOfPosition(position) {
|
|
717
|
-
return
|
|
626
|
+
return this._items.findIndex(function (item) {
|
|
718
627
|
return item[1] === position;
|
|
719
628
|
});
|
|
720
629
|
};
|
|
@@ -722,7 +631,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
722
631
|
_proto._attach = function _attach(id, doc) {
|
|
723
632
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
724
633
|
|
|
725
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
634
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(this._items), _step3; !(_step3 = _iterator3()).done;) {
|
|
726
635
|
var _step3$value = _step3.value,
|
|
727
636
|
_item2 = _step3$value[0];
|
|
728
637
|
|
|
@@ -733,7 +642,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
733
642
|
_proto._detach = function _detach() {
|
|
734
643
|
_AbstractCrdt.prototype._detach.call(this);
|
|
735
644
|
|
|
736
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
645
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._items), _step4; !(_step4 = _iterator4()).done;) {
|
|
737
646
|
var _step4$value = _step4.value,
|
|
738
647
|
_value2 = _step4$value[0];
|
|
739
648
|
|
|
@@ -741,11 +650,17 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
741
650
|
}
|
|
742
651
|
};
|
|
743
652
|
|
|
744
|
-
_proto._attachChild = function _attachChild(
|
|
653
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
745
654
|
if (this._doc == null) {
|
|
746
655
|
throw new Error("Can't attach child if doc is not present");
|
|
747
656
|
}
|
|
748
657
|
|
|
658
|
+
var id = op.id,
|
|
659
|
+
parentKey = op.parentKey,
|
|
660
|
+
intent = op.intent;
|
|
661
|
+
var key = parentKey;
|
|
662
|
+
var child = creationOpToLiveStructure(op);
|
|
663
|
+
|
|
749
664
|
if (this._doc.getItem(id) !== undefined) {
|
|
750
665
|
return {
|
|
751
666
|
modified: false
|
|
@@ -756,33 +671,52 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
756
671
|
|
|
757
672
|
child._setParentLink(this, key);
|
|
758
673
|
|
|
759
|
-
var index =
|
|
674
|
+
var index = this._items.findIndex(function (entry) {
|
|
760
675
|
return entry[1] === key;
|
|
761
676
|
});
|
|
762
677
|
|
|
763
678
|
var newKey = key;
|
|
764
679
|
|
|
765
680
|
if (index !== -1) {
|
|
766
|
-
if (
|
|
767
|
-
var
|
|
768
|
-
|
|
681
|
+
if (intent === "set") {
|
|
682
|
+
var existingItem = this._items[index][0];
|
|
683
|
+
|
|
684
|
+
existingItem._detach();
|
|
685
|
+
|
|
686
|
+
var storageUpdate = {
|
|
687
|
+
node: this,
|
|
688
|
+
type: "LiveList",
|
|
689
|
+
updates: [{
|
|
690
|
+
index: index,
|
|
691
|
+
type: "set",
|
|
692
|
+
item: child instanceof LiveRegister ? child.data : child
|
|
693
|
+
}]
|
|
694
|
+
};
|
|
695
|
+
this._items[index][0] = child;
|
|
696
|
+
return {
|
|
697
|
+
modified: storageUpdate,
|
|
698
|
+
reverse: existingItem._serialize(this._id, key, this._doc, "set")
|
|
699
|
+
};
|
|
700
|
+
} else if (isLocal) {
|
|
701
|
+
var before = this._items[index] ? this._items[index][1] : undefined;
|
|
702
|
+
var after = this._items[index + 1] ? this._items[index + 1][1] : undefined;
|
|
769
703
|
newKey = makePosition(before, after);
|
|
770
704
|
|
|
771
705
|
child._setParentLink(this, newKey);
|
|
772
706
|
} else {
|
|
773
|
-
var
|
|
707
|
+
var _this$_items;
|
|
774
708
|
|
|
775
|
-
|
|
709
|
+
this._items[index][1] = makePosition(key, (_this$_items = this._items[index + 1]) == null ? void 0 : _this$_items[1]);
|
|
776
710
|
}
|
|
777
711
|
}
|
|
778
712
|
|
|
779
|
-
|
|
713
|
+
this._items.push([child, newKey]);
|
|
780
714
|
|
|
781
|
-
|
|
715
|
+
this._items.sort(function (itemA, itemB) {
|
|
782
716
|
return compare(itemA[1], itemB[1]);
|
|
783
717
|
});
|
|
784
718
|
|
|
785
|
-
var newIndex =
|
|
719
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
786
720
|
return entry[1] === newKey;
|
|
787
721
|
});
|
|
788
722
|
|
|
@@ -807,11 +741,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
807
741
|
if (child) {
|
|
808
742
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
809
743
|
|
|
810
|
-
var indexToDelete =
|
|
744
|
+
var indexToDelete = this._items.findIndex(function (item) {
|
|
811
745
|
return item[0] === child;
|
|
812
746
|
});
|
|
813
747
|
|
|
814
|
-
|
|
748
|
+
this._items.splice(indexToDelete, 1);
|
|
815
749
|
|
|
816
750
|
child._detach();
|
|
817
751
|
|
|
@@ -837,21 +771,21 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
837
771
|
_proto._setChildKey = function _setChildKey(key, child, previousKey) {
|
|
838
772
|
child._setParentLink(this, key);
|
|
839
773
|
|
|
840
|
-
var previousIndex =
|
|
774
|
+
var previousIndex = this._items.findIndex(function (entry) {
|
|
841
775
|
return entry[0]._id === child._id;
|
|
842
776
|
});
|
|
843
777
|
|
|
844
|
-
var index =
|
|
778
|
+
var index = this._items.findIndex(function (entry) {
|
|
845
779
|
return entry[1] === key;
|
|
846
780
|
});
|
|
847
781
|
|
|
848
782
|
if (index !== -1) {
|
|
849
|
-
var
|
|
783
|
+
var _this$_items2;
|
|
850
784
|
|
|
851
|
-
|
|
785
|
+
this._items[index][1] = makePosition(key, (_this$_items2 = this._items[index + 1]) == null ? void 0 : _this$_items2[1]);
|
|
852
786
|
}
|
|
853
787
|
|
|
854
|
-
var item =
|
|
788
|
+
var item = this._items.find(function (item) {
|
|
855
789
|
return item[0] === child;
|
|
856
790
|
});
|
|
857
791
|
|
|
@@ -859,11 +793,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
859
793
|
item[1] = key;
|
|
860
794
|
}
|
|
861
795
|
|
|
862
|
-
|
|
796
|
+
this._items.sort(function (itemA, itemB) {
|
|
863
797
|
return compare(itemA[1], itemB[1]);
|
|
864
798
|
});
|
|
865
799
|
|
|
866
|
-
var newIndex =
|
|
800
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
867
801
|
return entry[0]._id === child._id;
|
|
868
802
|
});
|
|
869
803
|
|
|
@@ -906,24 +840,24 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
906
840
|
};
|
|
907
841
|
|
|
908
842
|
_proto.insert = function insert(element, index) {
|
|
909
|
-
if (index < 0 || index >
|
|
910
|
-
throw new Error("Cannot insert list item at index \"\x1D" + index + "\". index should be between 0 and " +
|
|
843
|
+
if (index < 0 || index > this._items.length) {
|
|
844
|
+
throw new Error("Cannot insert list item at index \"\x1D" + index + "\". index should be between 0 and " + this._items.length);
|
|
911
845
|
}
|
|
912
846
|
|
|
913
|
-
var before =
|
|
914
|
-
var after =
|
|
847
|
+
var before = this._items[index - 1] ? this._items[index - 1][1] : undefined;
|
|
848
|
+
var after = this._items[index] ? this._items[index][1] : undefined;
|
|
915
849
|
var position = makePosition(before, after);
|
|
916
850
|
var value = selfOrRegister(element);
|
|
917
851
|
|
|
918
852
|
value._setParentLink(this, position);
|
|
919
853
|
|
|
920
|
-
|
|
854
|
+
this._items.push([value, position]);
|
|
921
855
|
|
|
922
|
-
|
|
856
|
+
this._items.sort(function (itemA, itemB) {
|
|
923
857
|
return compare(itemA[1], itemB[1]);
|
|
924
858
|
});
|
|
925
859
|
|
|
926
|
-
var newIndex =
|
|
860
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
927
861
|
return entry[1] === position;
|
|
928
862
|
});
|
|
929
863
|
|
|
@@ -955,7 +889,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
955
889
|
throw new Error("targetIndex cannot be less than 0");
|
|
956
890
|
}
|
|
957
891
|
|
|
958
|
-
if (targetIndex >=
|
|
892
|
+
if (targetIndex >= this._items.length) {
|
|
959
893
|
throw new Error("targetIndex cannot be greater or equal than the list length");
|
|
960
894
|
}
|
|
961
895
|
|
|
@@ -963,7 +897,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
963
897
|
throw new Error("index cannot be less than 0");
|
|
964
898
|
}
|
|
965
899
|
|
|
966
|
-
if (index >=
|
|
900
|
+
if (index >= this._items.length) {
|
|
967
901
|
throw new Error("index cannot be greater or equal than the list length");
|
|
968
902
|
}
|
|
969
903
|
|
|
@@ -971,27 +905,25 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
971
905
|
var afterPosition = null;
|
|
972
906
|
|
|
973
907
|
if (index < targetIndex) {
|
|
974
|
-
afterPosition = targetIndex ===
|
|
975
|
-
beforePosition =
|
|
908
|
+
afterPosition = targetIndex === this._items.length - 1 ? undefined : this._items[targetIndex + 1][1];
|
|
909
|
+
beforePosition = this._items[targetIndex][1];
|
|
976
910
|
} else {
|
|
977
|
-
afterPosition =
|
|
978
|
-
beforePosition = targetIndex === 0 ? undefined :
|
|
911
|
+
afterPosition = this._items[targetIndex][1];
|
|
912
|
+
beforePosition = targetIndex === 0 ? undefined : this._items[targetIndex - 1][1];
|
|
979
913
|
}
|
|
980
914
|
|
|
981
915
|
var position = makePosition(beforePosition, afterPosition);
|
|
982
|
-
|
|
983
|
-
var item = _classPrivateFieldGet(this, _items)[index];
|
|
984
|
-
|
|
916
|
+
var item = this._items[index];
|
|
985
917
|
var previousPosition = item[1];
|
|
986
918
|
item[1] = position;
|
|
987
919
|
|
|
988
920
|
item[0]._setParentLink(this, position);
|
|
989
921
|
|
|
990
|
-
|
|
922
|
+
this._items.sort(function (itemA, itemB) {
|
|
991
923
|
return compare(itemA[1], itemB[1]);
|
|
992
924
|
});
|
|
993
925
|
|
|
994
|
-
var newIndex =
|
|
926
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
995
927
|
return entry[1] === position;
|
|
996
928
|
});
|
|
997
929
|
|
|
@@ -1022,15 +954,15 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1022
954
|
};
|
|
1023
955
|
|
|
1024
956
|
_proto.delete = function _delete(index) {
|
|
1025
|
-
if (index < 0 || index >=
|
|
1026
|
-
throw new Error("Cannot delete list item at index \"\x1D" + index + "\". index should be between 0 and " + (
|
|
957
|
+
if (index < 0 || index >= this._items.length) {
|
|
958
|
+
throw new Error("Cannot delete list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
|
|
1027
959
|
}
|
|
1028
960
|
|
|
1029
|
-
var item =
|
|
961
|
+
var item = this._items[index];
|
|
1030
962
|
|
|
1031
963
|
item[0]._detach();
|
|
1032
964
|
|
|
1033
|
-
|
|
965
|
+
this._items.splice(index, 1);
|
|
1034
966
|
|
|
1035
967
|
if (this._doc) {
|
|
1036
968
|
var childRecordId = item[0]._id;
|
|
@@ -1062,7 +994,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1062
994
|
var updateDelta = [];
|
|
1063
995
|
var i = 0;
|
|
1064
996
|
|
|
1065
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
997
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._items), _step5; !(_step5 = _iterator5()).done;) {
|
|
1066
998
|
var _item3 = _step5.value;
|
|
1067
999
|
|
|
1068
1000
|
_item3[0]._detach();
|
|
@@ -1084,8 +1016,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1084
1016
|
i++;
|
|
1085
1017
|
}
|
|
1086
1018
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1019
|
+
this._items = [];
|
|
1089
1020
|
var storageUpdates = new Map();
|
|
1090
1021
|
storageUpdates.set(this._id, {
|
|
1091
1022
|
node: this,
|
|
@@ -1095,18 +1026,55 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1095
1026
|
|
|
1096
1027
|
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
1097
1028
|
} else {
|
|
1098
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
1029
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._items), _step6; !(_step6 = _iterator6()).done;) {
|
|
1099
1030
|
var _item4 = _step6.value;
|
|
1100
1031
|
|
|
1101
1032
|
_item4[0]._detach();
|
|
1102
1033
|
}
|
|
1103
1034
|
|
|
1104
|
-
|
|
1035
|
+
this._items = [];
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
_proto.set = function set(index, item) {
|
|
1040
|
+
if (index < 0 || index >= this._items.length) {
|
|
1041
|
+
throw new Error("Cannot set list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
var _this$_items$index = this._items[index],
|
|
1045
|
+
existingItem = _this$_items$index[0],
|
|
1046
|
+
position = _this$_items$index[1];
|
|
1047
|
+
|
|
1048
|
+
existingItem._detach();
|
|
1049
|
+
|
|
1050
|
+
var value = selfOrRegister(item);
|
|
1051
|
+
|
|
1052
|
+
value._setParentLink(this, position);
|
|
1053
|
+
|
|
1054
|
+
this._items[index][0] = value;
|
|
1055
|
+
|
|
1056
|
+
if (this._doc && this._id) {
|
|
1057
|
+
var _id2 = this._doc.generateId();
|
|
1058
|
+
|
|
1059
|
+
value._attach(_id2, this._doc);
|
|
1060
|
+
|
|
1061
|
+
var storageUpdates = new Map();
|
|
1062
|
+
storageUpdates.set(this._id, {
|
|
1063
|
+
node: this,
|
|
1064
|
+
type: "LiveList",
|
|
1065
|
+
updates: [{
|
|
1066
|
+
index: index,
|
|
1067
|
+
item: value instanceof LiveRegister ? value.data : value,
|
|
1068
|
+
type: "set"
|
|
1069
|
+
}]
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
this._doc.dispatch(value._serialize(this._id, position, this._doc, "set"), existingItem._serialize(this._id, position, undefined, "set"), storageUpdates);
|
|
1105
1073
|
}
|
|
1106
1074
|
};
|
|
1107
1075
|
|
|
1108
1076
|
_proto.toArray = function toArray() {
|
|
1109
|
-
return
|
|
1077
|
+
return this._items.map(function (entry) {
|
|
1110
1078
|
return selfOrRegisterValue(entry[0]);
|
|
1111
1079
|
});
|
|
1112
1080
|
};
|
|
@@ -1132,11 +1100,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1132
1100
|
};
|
|
1133
1101
|
|
|
1134
1102
|
_proto.get = function get(index) {
|
|
1135
|
-
if (index < 0 || index >=
|
|
1103
|
+
if (index < 0 || index >= this._items.length) {
|
|
1136
1104
|
return undefined;
|
|
1137
1105
|
}
|
|
1138
1106
|
|
|
1139
|
-
return selfOrRegisterValue(
|
|
1107
|
+
return selfOrRegisterValue(this._items[index][0]);
|
|
1140
1108
|
};
|
|
1141
1109
|
|
|
1142
1110
|
_proto.indexOf = function indexOf(searchElement, fromIndex) {
|
|
@@ -1148,7 +1116,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1148
1116
|
};
|
|
1149
1117
|
|
|
1150
1118
|
_proto.map = function map(callback) {
|
|
1151
|
-
return
|
|
1119
|
+
return this._items.map(function (entry, i) {
|
|
1152
1120
|
return callback(selfOrRegisterValue(entry[0]), i);
|
|
1153
1121
|
});
|
|
1154
1122
|
};
|
|
@@ -1157,42 +1125,33 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1157
1125
|
return this.toArray().some(predicate);
|
|
1158
1126
|
};
|
|
1159
1127
|
|
|
1160
|
-
_proto[
|
|
1161
|
-
return new LiveListIterator(
|
|
1128
|
+
_proto[Symbol.iterator] = function () {
|
|
1129
|
+
return new LiveListIterator(this._items);
|
|
1162
1130
|
};
|
|
1163
1131
|
|
|
1164
1132
|
_createClass(LiveList, [{
|
|
1165
1133
|
key: "length",
|
|
1166
1134
|
get: function get() {
|
|
1167
|
-
return
|
|
1135
|
+
return this._items.length;
|
|
1168
1136
|
}
|
|
1169
1137
|
}]);
|
|
1170
1138
|
|
|
1171
1139
|
return LiveList;
|
|
1172
1140
|
}(AbstractCrdt);
|
|
1173
1141
|
|
|
1174
|
-
var _innerIterator = new WeakMap();
|
|
1175
|
-
|
|
1176
|
-
_Symbol$iterator2 = Symbol.iterator;
|
|
1177
|
-
|
|
1178
1142
|
var LiveListIterator = function () {
|
|
1179
1143
|
function LiveListIterator(items) {
|
|
1180
|
-
_innerIterator.
|
|
1181
|
-
writable: true,
|
|
1182
|
-
value: void 0
|
|
1183
|
-
});
|
|
1184
|
-
|
|
1185
|
-
_classPrivateFieldSet(this, _innerIterator, items[Symbol.iterator]());
|
|
1144
|
+
this._innerIterator = items[Symbol.iterator]();
|
|
1186
1145
|
}
|
|
1187
1146
|
|
|
1188
1147
|
var _proto2 = LiveListIterator.prototype;
|
|
1189
1148
|
|
|
1190
|
-
_proto2[
|
|
1149
|
+
_proto2[Symbol.iterator] = function () {
|
|
1191
1150
|
return this;
|
|
1192
1151
|
};
|
|
1193
1152
|
|
|
1194
1153
|
_proto2.next = function next() {
|
|
1195
|
-
var result =
|
|
1154
|
+
var result = this._innerIterator.next();
|
|
1196
1155
|
|
|
1197
1156
|
if (result.done) {
|
|
1198
1157
|
return {
|
|
@@ -1209,11 +1168,6 @@ var LiveListIterator = function () {
|
|
|
1209
1168
|
return LiveListIterator;
|
|
1210
1169
|
}();
|
|
1211
1170
|
|
|
1212
|
-
var _Symbol$iterator;
|
|
1213
|
-
|
|
1214
|
-
var _map$1 = new WeakMap();
|
|
1215
|
-
|
|
1216
|
-
_Symbol$iterator = Symbol.iterator;
|
|
1217
1171
|
var LiveMap = function (_AbstractCrdt) {
|
|
1218
1172
|
_inheritsLoose(LiveMap, _AbstractCrdt);
|
|
1219
1173
|
|
|
@@ -1222,11 +1176,6 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1222
1176
|
|
|
1223
1177
|
_this = _AbstractCrdt.call(this) || this;
|
|
1224
1178
|
|
|
1225
|
-
_map$1.set(_assertThisInitialized(_this), {
|
|
1226
|
-
writable: true,
|
|
1227
|
-
value: void 0
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
1179
|
if (entries) {
|
|
1231
1180
|
var mappedEntries = [];
|
|
1232
1181
|
|
|
@@ -1240,9 +1189,9 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1240
1189
|
mappedEntries.push([entry[0], _value]);
|
|
1241
1190
|
}
|
|
1242
1191
|
|
|
1243
|
-
|
|
1192
|
+
_this._map = new Map(mappedEntries);
|
|
1244
1193
|
} else {
|
|
1245
|
-
|
|
1194
|
+
_this._map = new Map();
|
|
1246
1195
|
}
|
|
1247
1196
|
|
|
1248
1197
|
return _this;
|
|
@@ -1250,7 +1199,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1250
1199
|
|
|
1251
1200
|
var _proto = LiveMap.prototype;
|
|
1252
1201
|
|
|
1253
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1202
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1254
1203
|
if (this._id == null) {
|
|
1255
1204
|
throw new Error("Cannot serialize item is not attached");
|
|
1256
1205
|
}
|
|
@@ -1264,12 +1213,13 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1264
1213
|
id: this._id,
|
|
1265
1214
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1266
1215
|
type: OpType.CreateMap,
|
|
1216
|
+
intent: intent,
|
|
1267
1217
|
parentId: parentId,
|
|
1268
1218
|
parentKey: parentKey
|
|
1269
1219
|
};
|
|
1270
1220
|
ops.push(op);
|
|
1271
1221
|
|
|
1272
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
1222
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this._map), _step2; !(_step2 = _iterator2()).done;) {
|
|
1273
1223
|
var _step2$value = _step2.value,
|
|
1274
1224
|
_key2 = _step2$value[0],
|
|
1275
1225
|
_value2 = _step2$value[1];
|
|
@@ -1309,7 +1259,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1309
1259
|
|
|
1310
1260
|
child._setParentLink(map, crdt.parentKey);
|
|
1311
1261
|
|
|
1312
|
-
|
|
1262
|
+
map._map.set(crdt.parentKey, child);
|
|
1313
1263
|
}
|
|
1314
1264
|
|
|
1315
1265
|
return map;
|
|
@@ -1318,7 +1268,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1318
1268
|
_proto._attach = function _attach(id, doc) {
|
|
1319
1269
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1320
1270
|
|
|
1321
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
1271
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
1322
1272
|
var _step4$value = _step4.value;
|
|
1323
1273
|
_step4$value[0];
|
|
1324
1274
|
var _value3 = _step4$value[1];
|
|
@@ -1329,20 +1279,25 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1329
1279
|
}
|
|
1330
1280
|
};
|
|
1331
1281
|
|
|
1332
|
-
_proto._attachChild = function _attachChild(
|
|
1282
|
+
_proto._attachChild = function _attachChild(op, _isLocal) {
|
|
1333
1283
|
var _updates;
|
|
1334
1284
|
|
|
1335
1285
|
if (this._doc == null) {
|
|
1336
1286
|
throw new Error("Can't attach child if doc is not present");
|
|
1337
1287
|
}
|
|
1338
1288
|
|
|
1289
|
+
var id = op.id,
|
|
1290
|
+
parentKey = op.parentKey;
|
|
1291
|
+
var key = parentKey;
|
|
1292
|
+
var child = creationOpToLiveStructure(op);
|
|
1293
|
+
|
|
1339
1294
|
if (this._doc.getItem(id) !== undefined) {
|
|
1340
1295
|
return {
|
|
1341
1296
|
modified: false
|
|
1342
1297
|
};
|
|
1343
1298
|
}
|
|
1344
1299
|
|
|
1345
|
-
var previousValue =
|
|
1300
|
+
var previousValue = this._map.get(key);
|
|
1346
1301
|
|
|
1347
1302
|
var reverse;
|
|
1348
1303
|
|
|
@@ -1361,7 +1316,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1361
1316
|
|
|
1362
1317
|
child._attach(id, this._doc);
|
|
1363
1318
|
|
|
1364
|
-
|
|
1319
|
+
this._map.set(key, child);
|
|
1365
1320
|
|
|
1366
1321
|
return {
|
|
1367
1322
|
modified: {
|
|
@@ -1378,7 +1333,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1378
1333
|
_proto._detach = function _detach() {
|
|
1379
1334
|
_AbstractCrdt.prototype._detach.call(this);
|
|
1380
1335
|
|
|
1381
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
1336
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map.values()), _step5; !(_step5 = _iterator5()).done;) {
|
|
1382
1337
|
var item = _step5.value;
|
|
1383
1338
|
|
|
1384
1339
|
item._detach();
|
|
@@ -1390,13 +1345,13 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1390
1345
|
|
|
1391
1346
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
1392
1347
|
|
|
1393
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
1348
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map), _step6; !(_step6 = _iterator6()).done;) {
|
|
1394
1349
|
var _step6$value = _step6.value,
|
|
1395
1350
|
_key3 = _step6$value[0],
|
|
1396
1351
|
_value4 = _step6$value[1];
|
|
1397
1352
|
|
|
1398
1353
|
if (_value4 === child) {
|
|
1399
|
-
|
|
1354
|
+
this._map.delete(_key3);
|
|
1400
1355
|
}
|
|
1401
1356
|
}
|
|
1402
1357
|
|
|
@@ -1426,7 +1381,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1426
1381
|
};
|
|
1427
1382
|
|
|
1428
1383
|
_proto.get = function get(key) {
|
|
1429
|
-
var value =
|
|
1384
|
+
var value = this._map.get(key);
|
|
1430
1385
|
|
|
1431
1386
|
if (value == undefined) {
|
|
1432
1387
|
return undefined;
|
|
@@ -1436,7 +1391,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1436
1391
|
};
|
|
1437
1392
|
|
|
1438
1393
|
_proto.set = function set(key, value) {
|
|
1439
|
-
var oldValue =
|
|
1394
|
+
var oldValue = this._map.get(key);
|
|
1440
1395
|
|
|
1441
1396
|
if (oldValue) {
|
|
1442
1397
|
oldValue._detach();
|
|
@@ -1446,7 +1401,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1446
1401
|
|
|
1447
1402
|
item._setParentLink(this, key);
|
|
1448
1403
|
|
|
1449
|
-
|
|
1404
|
+
this._map.set(key, item);
|
|
1450
1405
|
|
|
1451
1406
|
if (this._doc && this._id) {
|
|
1452
1407
|
var _updates3;
|
|
@@ -1472,11 +1427,11 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1472
1427
|
};
|
|
1473
1428
|
|
|
1474
1429
|
_proto.has = function has(key) {
|
|
1475
|
-
return
|
|
1430
|
+
return this._map.has(key);
|
|
1476
1431
|
};
|
|
1477
1432
|
|
|
1478
1433
|
_proto.delete = function _delete(key) {
|
|
1479
|
-
var item =
|
|
1434
|
+
var item = this._map.get(key);
|
|
1480
1435
|
|
|
1481
1436
|
if (item == null) {
|
|
1482
1437
|
return false;
|
|
@@ -1484,7 +1439,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1484
1439
|
|
|
1485
1440
|
item._detach();
|
|
1486
1441
|
|
|
1487
|
-
|
|
1442
|
+
this._map.delete(key);
|
|
1488
1443
|
|
|
1489
1444
|
if (this._doc && item._id) {
|
|
1490
1445
|
var _updates4;
|
|
@@ -1511,7 +1466,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1511
1466
|
_proto.entries = function entries() {
|
|
1512
1467
|
var _ref2;
|
|
1513
1468
|
|
|
1514
|
-
var innerIterator =
|
|
1469
|
+
var innerIterator = this._map.entries();
|
|
1515
1470
|
|
|
1516
1471
|
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
|
|
1517
1472
|
return this;
|
|
@@ -1532,18 +1487,18 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1532
1487
|
}, _ref2;
|
|
1533
1488
|
};
|
|
1534
1489
|
|
|
1535
|
-
_proto[
|
|
1490
|
+
_proto[Symbol.iterator] = function () {
|
|
1536
1491
|
return this.entries();
|
|
1537
1492
|
};
|
|
1538
1493
|
|
|
1539
1494
|
_proto.keys = function keys() {
|
|
1540
|
-
return
|
|
1495
|
+
return this._map.keys();
|
|
1541
1496
|
};
|
|
1542
1497
|
|
|
1543
1498
|
_proto.values = function values() {
|
|
1544
1499
|
var _ref3;
|
|
1545
1500
|
|
|
1546
|
-
var innerIterator =
|
|
1501
|
+
var innerIterator = this._map.values();
|
|
1547
1502
|
|
|
1548
1503
|
return _ref3 = {}, _ref3[Symbol.iterator] = function () {
|
|
1549
1504
|
return this;
|
|
@@ -1573,13 +1528,27 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1573
1528
|
_createClass(LiveMap, [{
|
|
1574
1529
|
key: "size",
|
|
1575
1530
|
get: function get() {
|
|
1576
|
-
return
|
|
1531
|
+
return this._map.size;
|
|
1577
1532
|
}
|
|
1578
1533
|
}]);
|
|
1579
1534
|
|
|
1580
1535
|
return LiveMap;
|
|
1581
1536
|
}(AbstractCrdt);
|
|
1582
1537
|
|
|
1538
|
+
function parseJson(rawMessage) {
|
|
1539
|
+
try {
|
|
1540
|
+
return JSON.parse(rawMessage);
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
return undefined;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
function isJsonArray(data) {
|
|
1546
|
+
return Array.isArray(data);
|
|
1547
|
+
}
|
|
1548
|
+
function isJsonObject(data) {
|
|
1549
|
+
return data !== null && typeof data === "object" && !isJsonArray(data);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1583
1552
|
function remove(array, item) {
|
|
1584
1553
|
for (var i = 0; i < array.length; i++) {
|
|
1585
1554
|
if (array[i] === item) {
|
|
@@ -1588,6 +1557,26 @@ function remove(array, item) {
|
|
|
1588
1557
|
}
|
|
1589
1558
|
}
|
|
1590
1559
|
}
|
|
1560
|
+
function compact(items) {
|
|
1561
|
+
return items.filter(function (item) {
|
|
1562
|
+
return item != null;
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
function creationOpToLiveStructure(op) {
|
|
1566
|
+
switch (op.type) {
|
|
1567
|
+
case OpType.CreateRegister:
|
|
1568
|
+
return new LiveRegister(op.data);
|
|
1569
|
+
|
|
1570
|
+
case OpType.CreateObject:
|
|
1571
|
+
return new LiveObject(op.data);
|
|
1572
|
+
|
|
1573
|
+
case OpType.CreateMap:
|
|
1574
|
+
return new LiveMap();
|
|
1575
|
+
|
|
1576
|
+
case OpType.CreateList:
|
|
1577
|
+
return new LiveList();
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1591
1580
|
function isSameNodeOrChildOf(node, parent) {
|
|
1592
1581
|
if (node === parent) {
|
|
1593
1582
|
return true;
|
|
@@ -1721,44 +1710,57 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
1721
1710
|
});
|
|
1722
1711
|
return ops;
|
|
1723
1712
|
}
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1713
|
+
|
|
1714
|
+
function mergeObjectStorageUpdates(first, second) {
|
|
1715
|
+
var updates = first.updates;
|
|
1716
|
+
|
|
1717
|
+
for (var _iterator = _createForOfIteratorHelperLoose(entries(second.updates)), _step; !(_step = _iterator()).done;) {
|
|
1718
|
+
var _step$value = _step.value,
|
|
1719
|
+
_key = _step$value[0],
|
|
1720
|
+
value = _step$value[1];
|
|
1721
|
+
updates[_key] = value;
|
|
1727
1722
|
}
|
|
1728
1723
|
|
|
1729
|
-
|
|
1730
|
-
|
|
1724
|
+
return _extends({}, second, {
|
|
1725
|
+
updates: updates
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1731
1728
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
key = _Object$entries$_i[0],
|
|
1735
|
-
value = _Object$entries$_i[1];
|
|
1736
|
-
updates[key] = value;
|
|
1737
|
-
}
|
|
1729
|
+
function mergeMapStorageUpdates(first, second) {
|
|
1730
|
+
var updates = first.updates;
|
|
1738
1731
|
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1732
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(entries(second.updates)), _step2; !(_step2 = _iterator2()).done;) {
|
|
1733
|
+
var _step2$value = _step2.value,
|
|
1734
|
+
_key2 = _step2$value[0],
|
|
1735
|
+
value = _step2$value[1];
|
|
1736
|
+
updates[_key2] = value;
|
|
1737
|
+
}
|
|
1744
1738
|
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
_updates[_key] = _value;
|
|
1750
|
-
}
|
|
1739
|
+
return _extends({}, second, {
|
|
1740
|
+
updates: updates
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1751
1743
|
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1744
|
+
function mergeListStorageUpdates(first, second) {
|
|
1745
|
+
var updates = first.updates;
|
|
1746
|
+
return _extends({}, second, {
|
|
1747
|
+
updates: updates.concat(second.updates)
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
function mergeStorageUpdates(first, second) {
|
|
1752
|
+
if (!first) {
|
|
1753
|
+
return second;
|
|
1760
1754
|
}
|
|
1761
1755
|
|
|
1756
|
+
if (first.type === "LiveObject" && second.type === "LiveObject") {
|
|
1757
|
+
return mergeObjectStorageUpdates(first, second);
|
|
1758
|
+
} else if (first.type === "LiveMap" && second.type === "LiveMap") {
|
|
1759
|
+
return mergeMapStorageUpdates(first, second);
|
|
1760
|
+
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
1761
|
+
return mergeListStorageUpdates(first, second);
|
|
1762
|
+
} else ;
|
|
1763
|
+
|
|
1762
1764
|
return second;
|
|
1763
1765
|
}
|
|
1764
1766
|
|
|
@@ -1796,11 +1798,11 @@ function findNonSerializableValue(value, path) {
|
|
|
1796
1798
|
return false;
|
|
1797
1799
|
}
|
|
1798
1800
|
|
|
1799
|
-
for (var
|
|
1800
|
-
var _Object$
|
|
1801
|
-
|
|
1802
|
-
nestedValue = _Object$
|
|
1803
|
-
var nestedPath = path ? path + "." +
|
|
1801
|
+
for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
|
|
1802
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
1803
|
+
_key3 = _Object$entries$_i[0],
|
|
1804
|
+
nestedValue = _Object$entries$_i[1];
|
|
1805
|
+
var nestedPath = path ? path + "." + _key3 : _key3;
|
|
1804
1806
|
|
|
1805
1807
|
if (!isPlain(nestedValue)) {
|
|
1806
1808
|
return {
|
|
@@ -1820,14 +1822,30 @@ function findNonSerializableValue(value, path) {
|
|
|
1820
1822
|
|
|
1821
1823
|
return false;
|
|
1822
1824
|
}
|
|
1825
|
+
function isTokenValid(token) {
|
|
1826
|
+
var tokenParts = token.split(".");
|
|
1827
|
+
|
|
1828
|
+
if (tokenParts.length !== 3) {
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1823
1831
|
|
|
1824
|
-
var
|
|
1832
|
+
var data = parseJson(atob(tokenParts[1]));
|
|
1833
|
+
|
|
1834
|
+
if (data === undefined || !isJsonObject(data) || typeof data.exp !== "number") {
|
|
1835
|
+
return false;
|
|
1836
|
+
}
|
|
1825
1837
|
|
|
1826
|
-
var
|
|
1838
|
+
var now = Date.now();
|
|
1827
1839
|
|
|
1828
|
-
|
|
1840
|
+
if (now / 1000 > data.exp - 300) {
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1829
1843
|
|
|
1830
|
-
|
|
1844
|
+
return true;
|
|
1845
|
+
}
|
|
1846
|
+
function entries(obj) {
|
|
1847
|
+
return Object.entries(obj);
|
|
1848
|
+
}
|
|
1831
1849
|
|
|
1832
1850
|
var LiveObject = function (_AbstractCrdt) {
|
|
1833
1851
|
_inheritsLoose(LiveObject, _AbstractCrdt);
|
|
@@ -1840,20 +1858,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1840
1858
|
}
|
|
1841
1859
|
|
|
1842
1860
|
_this = _AbstractCrdt.call(this) || this;
|
|
1843
|
-
|
|
1844
|
-
_applyDeleteObjectKey.add(_assertThisInitialized(_this));
|
|
1845
|
-
|
|
1846
|
-
_applyUpdate.add(_assertThisInitialized(_this));
|
|
1847
|
-
|
|
1848
|
-
_map.set(_assertThisInitialized(_this), {
|
|
1849
|
-
writable: true,
|
|
1850
|
-
value: void 0
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
|
-
_propToLastUpdate.set(_assertThisInitialized(_this), {
|
|
1854
|
-
writable: true,
|
|
1855
|
-
value: new Map()
|
|
1856
|
-
});
|
|
1861
|
+
_this._propToLastUpdate = new Map();
|
|
1857
1862
|
|
|
1858
1863
|
for (var key in object) {
|
|
1859
1864
|
var value = object[key];
|
|
@@ -1863,14 +1868,13 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1863
1868
|
}
|
|
1864
1869
|
}
|
|
1865
1870
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1871
|
+
_this._map = new Map(Object.entries(object));
|
|
1868
1872
|
return _this;
|
|
1869
1873
|
}
|
|
1870
1874
|
|
|
1871
1875
|
var _proto = LiveObject.prototype;
|
|
1872
1876
|
|
|
1873
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1877
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1874
1878
|
if (this._id == null) {
|
|
1875
1879
|
throw new Error("Cannot serialize item is not attached");
|
|
1876
1880
|
}
|
|
@@ -1879,6 +1883,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1879
1883
|
var op = {
|
|
1880
1884
|
id: this._id,
|
|
1881
1885
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1886
|
+
intent: intent,
|
|
1882
1887
|
type: OpType.CreateObject,
|
|
1883
1888
|
parentId: parentId,
|
|
1884
1889
|
parentKey: parentKey,
|
|
@@ -1886,7 +1891,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1886
1891
|
};
|
|
1887
1892
|
ops.push(op);
|
|
1888
1893
|
|
|
1889
|
-
for (var _iterator = _createForOfIteratorHelperLoose(
|
|
1894
|
+
for (var _iterator = _createForOfIteratorHelperLoose(this._map), _step; !(_step = _iterator()).done;) {
|
|
1890
1895
|
var _step$value = _step.value,
|
|
1891
1896
|
key = _step$value[0],
|
|
1892
1897
|
value = _step$value[1];
|
|
@@ -1935,7 +1940,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1935
1940
|
|
|
1936
1941
|
child._setParentLink(object, crdt.parentKey);
|
|
1937
1942
|
|
|
1938
|
-
|
|
1943
|
+
object._map.set(crdt.parentKey, child);
|
|
1939
1944
|
}
|
|
1940
1945
|
|
|
1941
1946
|
return object;
|
|
@@ -1944,7 +1949,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1944
1949
|
_proto._attach = function _attach(id, doc) {
|
|
1945
1950
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1946
1951
|
|
|
1947
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
1952
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(this._map), _step3; !(_step3 = _iterator3()).done;) {
|
|
1948
1953
|
var _step3$value = _step3.value;
|
|
1949
1954
|
_step3$value[0];
|
|
1950
1955
|
var value = _step3$value[1];
|
|
@@ -1955,16 +1960,22 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1955
1960
|
}
|
|
1956
1961
|
};
|
|
1957
1962
|
|
|
1958
|
-
_proto._attachChild = function _attachChild(
|
|
1963
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
1959
1964
|
var _updates;
|
|
1960
1965
|
|
|
1961
1966
|
if (this._doc == null) {
|
|
1962
1967
|
throw new Error("Can't attach child if doc is not present");
|
|
1963
1968
|
}
|
|
1964
1969
|
|
|
1970
|
+
var id = op.id,
|
|
1971
|
+
parentKey = op.parentKey,
|
|
1972
|
+
opId = op.opId;
|
|
1973
|
+
var key = parentKey;
|
|
1974
|
+
var child = creationOpToLiveStructure(op);
|
|
1975
|
+
|
|
1965
1976
|
if (this._doc.getItem(id) !== undefined) {
|
|
1966
|
-
if (
|
|
1967
|
-
|
|
1977
|
+
if (this._propToLastUpdate.get(key) === opId) {
|
|
1978
|
+
this._propToLastUpdate.delete(key);
|
|
1968
1979
|
}
|
|
1969
1980
|
|
|
1970
1981
|
return {
|
|
@@ -1973,9 +1984,9 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1973
1984
|
}
|
|
1974
1985
|
|
|
1975
1986
|
if (isLocal) {
|
|
1976
|
-
|
|
1977
|
-
} else if (
|
|
1978
|
-
|
|
1987
|
+
this._propToLastUpdate.set(key, opId);
|
|
1988
|
+
} else if (this._propToLastUpdate.get(key) === undefined) ; else if (this._propToLastUpdate.get(key) === opId) {
|
|
1989
|
+
this._propToLastUpdate.delete(key);
|
|
1979
1990
|
|
|
1980
1991
|
return {
|
|
1981
1992
|
modified: false
|
|
@@ -1986,7 +1997,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1986
1997
|
};
|
|
1987
1998
|
}
|
|
1988
1999
|
|
|
1989
|
-
var previousValue =
|
|
2000
|
+
var previousValue = this._map.get(key);
|
|
1990
2001
|
|
|
1991
2002
|
var reverse;
|
|
1992
2003
|
|
|
@@ -2010,7 +2021,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2010
2021
|
}];
|
|
2011
2022
|
}
|
|
2012
2023
|
|
|
2013
|
-
|
|
2024
|
+
this._map.set(key, child);
|
|
2014
2025
|
|
|
2015
2026
|
child._setParentLink(this, key);
|
|
2016
2027
|
|
|
@@ -2034,13 +2045,13 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2034
2045
|
|
|
2035
2046
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
2036
2047
|
|
|
2037
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
2048
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
2038
2049
|
var _step4$value = _step4.value,
|
|
2039
2050
|
key = _step4$value[0],
|
|
2040
2051
|
value = _step4$value[1];
|
|
2041
2052
|
|
|
2042
2053
|
if (value === child) {
|
|
2043
|
-
|
|
2054
|
+
this._map.delete(key);
|
|
2044
2055
|
}
|
|
2045
2056
|
}
|
|
2046
2057
|
|
|
@@ -2065,12 +2076,12 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2065
2076
|
};
|
|
2066
2077
|
|
|
2067
2078
|
_proto._detachChildren = function _detachChildren() {
|
|
2068
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
2079
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map), _step5; !(_step5 = _iterator5()).done;) {
|
|
2069
2080
|
var _step5$value = _step5.value,
|
|
2070
2081
|
key = _step5$value[0],
|
|
2071
2082
|
value = _step5$value[1];
|
|
2072
2083
|
|
|
2073
|
-
|
|
2084
|
+
this._map.delete(key);
|
|
2074
2085
|
|
|
2075
2086
|
value._detach();
|
|
2076
2087
|
}
|
|
@@ -2079,7 +2090,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2079
2090
|
_proto._detach = function _detach() {
|
|
2080
2091
|
_AbstractCrdt.prototype._detach.call(this);
|
|
2081
2092
|
|
|
2082
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
2093
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map.values()), _step6; !(_step6 = _iterator6()).done;) {
|
|
2083
2094
|
var value = _step6.value;
|
|
2084
2095
|
|
|
2085
2096
|
if (isCrdt(value)) {
|
|
@@ -2090,9 +2101,9 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2090
2101
|
|
|
2091
2102
|
_proto._apply = function _apply(op, isLocal) {
|
|
2092
2103
|
if (op.type === OpType.UpdateObject) {
|
|
2093
|
-
return
|
|
2104
|
+
return this._applyUpdate(op, isLocal);
|
|
2094
2105
|
} else if (op.type === OpType.DeleteObjectKey) {
|
|
2095
|
-
return
|
|
2106
|
+
return this._applyDeleteObjectKey(op);
|
|
2096
2107
|
}
|
|
2097
2108
|
|
|
2098
2109
|
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
@@ -2101,16 +2112,150 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2101
2112
|
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
2102
2113
|
var _this$_parent;
|
|
2103
2114
|
|
|
2115
|
+
var data = {};
|
|
2116
|
+
|
|
2117
|
+
for (var _iterator7 = _createForOfIteratorHelperLoose(this._map), _step7; !(_step7 = _iterator7()).done;) {
|
|
2118
|
+
var _step7$value = _step7.value,
|
|
2119
|
+
key = _step7$value[0],
|
|
2120
|
+
value = _step7$value[1];
|
|
2121
|
+
|
|
2122
|
+
if (value instanceof AbstractCrdt === false) {
|
|
2123
|
+
data[key] = value;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2104
2127
|
return {
|
|
2105
2128
|
type: CrdtType.Object,
|
|
2106
2129
|
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
2107
2130
|
parentKey: this._parentKey,
|
|
2108
|
-
data:
|
|
2131
|
+
data: data
|
|
2132
|
+
};
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
_proto._applyUpdate = function _applyUpdate(op, isLocal) {
|
|
2136
|
+
var isModified = false;
|
|
2137
|
+
var reverse = [];
|
|
2138
|
+
var reverseUpdate = {
|
|
2139
|
+
type: OpType.UpdateObject,
|
|
2140
|
+
id: this._id,
|
|
2141
|
+
data: {}
|
|
2142
|
+
};
|
|
2143
|
+
reverse.push(reverseUpdate);
|
|
2144
|
+
|
|
2145
|
+
for (var key in op.data) {
|
|
2146
|
+
var oldValue = this._map.get(key);
|
|
2147
|
+
|
|
2148
|
+
if (oldValue instanceof AbstractCrdt) {
|
|
2149
|
+
reverse.push.apply(reverse, oldValue._serialize(this._id, key));
|
|
2150
|
+
|
|
2151
|
+
oldValue._detach();
|
|
2152
|
+
} else if (oldValue !== undefined) {
|
|
2153
|
+
reverseUpdate.data[key] = oldValue;
|
|
2154
|
+
} else if (oldValue === undefined) {
|
|
2155
|
+
reverse.push({
|
|
2156
|
+
type: OpType.DeleteObjectKey,
|
|
2157
|
+
id: this._id,
|
|
2158
|
+
key: key
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
var updateDelta = {};
|
|
2164
|
+
|
|
2165
|
+
for (var _key2 in op.data) {
|
|
2166
|
+
if (isLocal) {
|
|
2167
|
+
this._propToLastUpdate.set(_key2, op.opId);
|
|
2168
|
+
} else if (this._propToLastUpdate.get(_key2) == null) {
|
|
2169
|
+
isModified = true;
|
|
2170
|
+
} else if (this._propToLastUpdate.get(_key2) === op.opId) {
|
|
2171
|
+
this._propToLastUpdate.delete(_key2);
|
|
2172
|
+
|
|
2173
|
+
continue;
|
|
2174
|
+
} else {
|
|
2175
|
+
continue;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
var _oldValue = this._map.get(_key2);
|
|
2179
|
+
|
|
2180
|
+
if (isCrdt(_oldValue)) {
|
|
2181
|
+
_oldValue._detach();
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
isModified = true;
|
|
2185
|
+
updateDelta[_key2] = {
|
|
2186
|
+
type: "update"
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
this._map.set(_key2, op.data[_key2]);
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
2193
|
+
reverse.unshift(reverseUpdate);
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
return isModified ? {
|
|
2197
|
+
modified: {
|
|
2198
|
+
node: this,
|
|
2199
|
+
type: "LiveObject",
|
|
2200
|
+
updates: updateDelta
|
|
2201
|
+
},
|
|
2202
|
+
reverse: reverse
|
|
2203
|
+
} : {
|
|
2204
|
+
modified: false
|
|
2205
|
+
};
|
|
2206
|
+
};
|
|
2207
|
+
|
|
2208
|
+
_proto._applyDeleteObjectKey = function _applyDeleteObjectKey(op) {
|
|
2209
|
+
var _updates3;
|
|
2210
|
+
|
|
2211
|
+
var key = op.key;
|
|
2212
|
+
|
|
2213
|
+
if (this._map.has(key) === false) {
|
|
2214
|
+
return {
|
|
2215
|
+
modified: false
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
if (this._propToLastUpdate.get(key) !== undefined) {
|
|
2220
|
+
return {
|
|
2221
|
+
modified: false
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
var oldValue = this._map.get(key);
|
|
2226
|
+
|
|
2227
|
+
var reverse = [];
|
|
2228
|
+
|
|
2229
|
+
if (isCrdt(oldValue)) {
|
|
2230
|
+
reverse = oldValue._serialize(this._id, op.key);
|
|
2231
|
+
|
|
2232
|
+
oldValue._detach();
|
|
2233
|
+
} else if (oldValue !== undefined) {
|
|
2234
|
+
var _data2;
|
|
2235
|
+
|
|
2236
|
+
reverse = [{
|
|
2237
|
+
type: OpType.UpdateObject,
|
|
2238
|
+
id: this._id,
|
|
2239
|
+
data: (_data2 = {}, _data2[key] = oldValue, _data2)
|
|
2240
|
+
}];
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
this._map.delete(key);
|
|
2244
|
+
|
|
2245
|
+
return {
|
|
2246
|
+
modified: {
|
|
2247
|
+
node: this,
|
|
2248
|
+
type: "LiveObject",
|
|
2249
|
+
updates: (_updates3 = {}, _updates3[op.key] = {
|
|
2250
|
+
type: "delete"
|
|
2251
|
+
}, _updates3)
|
|
2252
|
+
},
|
|
2253
|
+
reverse: reverse
|
|
2109
2254
|
};
|
|
2110
2255
|
};
|
|
2111
2256
|
|
|
2112
2257
|
_proto.toObject = function toObject() {
|
|
2113
|
-
return Object.fromEntries(
|
|
2258
|
+
return Object.fromEntries(this._map);
|
|
2114
2259
|
};
|
|
2115
2260
|
|
|
2116
2261
|
_proto.set = function set(key, value) {
|
|
@@ -2120,15 +2265,15 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2120
2265
|
};
|
|
2121
2266
|
|
|
2122
2267
|
_proto.get = function get(key) {
|
|
2123
|
-
return
|
|
2268
|
+
return this._map.get(key);
|
|
2124
2269
|
};
|
|
2125
2270
|
|
|
2126
2271
|
_proto.delete = function _delete(key) {
|
|
2127
|
-
var
|
|
2272
|
+
var _updates4;
|
|
2128
2273
|
|
|
2129
2274
|
var keyAsString = key;
|
|
2130
2275
|
|
|
2131
|
-
var oldValue =
|
|
2276
|
+
var oldValue = this._map.get(keyAsString);
|
|
2132
2277
|
|
|
2133
2278
|
if (oldValue === undefined) {
|
|
2134
2279
|
return;
|
|
@@ -2139,7 +2284,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2139
2284
|
oldValue._detach();
|
|
2140
2285
|
}
|
|
2141
2286
|
|
|
2142
|
-
|
|
2287
|
+
this._map.delete(keyAsString);
|
|
2143
2288
|
|
|
2144
2289
|
return;
|
|
2145
2290
|
}
|
|
@@ -2151,24 +2296,24 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2151
2296
|
|
|
2152
2297
|
reverse = oldValue._serialize(this._id, keyAsString);
|
|
2153
2298
|
} else {
|
|
2154
|
-
var
|
|
2299
|
+
var _data3;
|
|
2155
2300
|
|
|
2156
2301
|
reverse = [{
|
|
2157
2302
|
type: OpType.UpdateObject,
|
|
2158
|
-
data: (
|
|
2303
|
+
data: (_data3 = {}, _data3[keyAsString] = oldValue, _data3),
|
|
2159
2304
|
id: this._id
|
|
2160
2305
|
}];
|
|
2161
2306
|
}
|
|
2162
2307
|
|
|
2163
|
-
|
|
2308
|
+
this._map.delete(keyAsString);
|
|
2164
2309
|
|
|
2165
2310
|
var storageUpdates = new Map();
|
|
2166
2311
|
storageUpdates.set(this._id, {
|
|
2167
2312
|
node: this,
|
|
2168
2313
|
type: "LiveObject",
|
|
2169
|
-
updates: (
|
|
2314
|
+
updates: (_updates4 = {}, _updates4[key] = {
|
|
2170
2315
|
type: "delete"
|
|
2171
|
-
},
|
|
2316
|
+
}, _updates4)
|
|
2172
2317
|
});
|
|
2173
2318
|
|
|
2174
2319
|
this._doc.dispatch([{
|
|
@@ -2184,7 +2329,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2184
2329
|
|
|
2185
2330
|
if (this._doc == null || this._id == null) {
|
|
2186
2331
|
for (var key in overrides) {
|
|
2187
|
-
var oldValue =
|
|
2332
|
+
var oldValue = this._map.get(key);
|
|
2188
2333
|
|
|
2189
2334
|
if (oldValue instanceof AbstractCrdt) {
|
|
2190
2335
|
oldValue._detach();
|
|
@@ -2196,7 +2341,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2196
2341
|
newValue._setParentLink(this, key);
|
|
2197
2342
|
}
|
|
2198
2343
|
|
|
2199
|
-
|
|
2344
|
+
this._map.set(key, newValue);
|
|
2200
2345
|
}
|
|
2201
2346
|
|
|
2202
2347
|
return;
|
|
@@ -2215,50 +2360,50 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2215
2360
|
};
|
|
2216
2361
|
var updateDelta = {};
|
|
2217
2362
|
|
|
2218
|
-
for (var
|
|
2219
|
-
var
|
|
2363
|
+
for (var _key3 in overrides) {
|
|
2364
|
+
var _oldValue2 = this._map.get(_key3);
|
|
2220
2365
|
|
|
2221
|
-
if (
|
|
2222
|
-
reverseOps.push.apply(reverseOps,
|
|
2366
|
+
if (_oldValue2 instanceof AbstractCrdt) {
|
|
2367
|
+
reverseOps.push.apply(reverseOps, _oldValue2._serialize(this._id, _key3));
|
|
2223
2368
|
|
|
2224
|
-
|
|
2225
|
-
} else if (
|
|
2369
|
+
_oldValue2._detach();
|
|
2370
|
+
} else if (_oldValue2 === undefined) {
|
|
2226
2371
|
reverseOps.push({
|
|
2227
2372
|
type: OpType.DeleteObjectKey,
|
|
2228
2373
|
id: this._id,
|
|
2229
|
-
key:
|
|
2374
|
+
key: _key3
|
|
2230
2375
|
});
|
|
2231
2376
|
} else {
|
|
2232
|
-
reverseUpdateOp.data[
|
|
2377
|
+
reverseUpdateOp.data[_key3] = _oldValue2;
|
|
2233
2378
|
}
|
|
2234
2379
|
|
|
2235
|
-
var _newValue = overrides[
|
|
2380
|
+
var _newValue = overrides[_key3];
|
|
2236
2381
|
|
|
2237
2382
|
if (_newValue instanceof AbstractCrdt) {
|
|
2238
|
-
_newValue._setParentLink(this,
|
|
2383
|
+
_newValue._setParentLink(this, _key3);
|
|
2239
2384
|
|
|
2240
2385
|
_newValue._attach(this._doc.generateId(), this._doc);
|
|
2241
2386
|
|
|
2242
|
-
var newAttachChildOps = _newValue._serialize(this._id,
|
|
2387
|
+
var newAttachChildOps = _newValue._serialize(this._id, _key3, this._doc);
|
|
2243
2388
|
|
|
2244
2389
|
var createCrdtOp = newAttachChildOps.find(function (op) {
|
|
2245
2390
|
return op.parentId === _this2._id;
|
|
2246
2391
|
});
|
|
2247
2392
|
|
|
2248
2393
|
if (createCrdtOp) {
|
|
2249
|
-
|
|
2394
|
+
this._propToLastUpdate.set(_key3, createCrdtOp.opId);
|
|
2250
2395
|
}
|
|
2251
2396
|
|
|
2252
2397
|
ops.push.apply(ops, newAttachChildOps);
|
|
2253
2398
|
} else {
|
|
2254
|
-
updatedProps[
|
|
2399
|
+
updatedProps[_key3] = _newValue;
|
|
2255
2400
|
|
|
2256
|
-
|
|
2401
|
+
this._propToLastUpdate.set(_key3, opId);
|
|
2257
2402
|
}
|
|
2258
2403
|
|
|
2259
|
-
|
|
2404
|
+
this._map.set(_key3, _newValue);
|
|
2260
2405
|
|
|
2261
|
-
updateDelta[
|
|
2406
|
+
updateDelta[_key3] = {
|
|
2262
2407
|
type: "update"
|
|
2263
2408
|
};
|
|
2264
2409
|
}
|
|
@@ -2289,128 +2434,6 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2289
2434
|
return LiveObject;
|
|
2290
2435
|
}(AbstractCrdt);
|
|
2291
2436
|
|
|
2292
|
-
function _applyUpdate2(op, isLocal) {
|
|
2293
|
-
var isModified = false;
|
|
2294
|
-
var reverse = [];
|
|
2295
|
-
var reverseUpdate = {
|
|
2296
|
-
type: OpType.UpdateObject,
|
|
2297
|
-
id: this._id,
|
|
2298
|
-
data: {}
|
|
2299
|
-
};
|
|
2300
|
-
reverse.push(reverseUpdate);
|
|
2301
|
-
|
|
2302
|
-
for (var key in op.data) {
|
|
2303
|
-
var oldValue = _classPrivateFieldGet(this, _map).get(key);
|
|
2304
|
-
|
|
2305
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2306
|
-
reverse.push.apply(reverse, oldValue._serialize(this._id, key));
|
|
2307
|
-
|
|
2308
|
-
oldValue._detach();
|
|
2309
|
-
} else if (oldValue !== undefined) {
|
|
2310
|
-
reverseUpdate.data[key] = oldValue;
|
|
2311
|
-
} else if (oldValue === undefined) {
|
|
2312
|
-
reverse.push({
|
|
2313
|
-
type: OpType.DeleteObjectKey,
|
|
2314
|
-
id: this._id,
|
|
2315
|
-
key: key
|
|
2316
|
-
});
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
var updateDelta = {};
|
|
2321
|
-
|
|
2322
|
-
for (var _key3 in op.data) {
|
|
2323
|
-
if (isLocal) {
|
|
2324
|
-
_classPrivateFieldGet(this, _propToLastUpdate).set(_key3, op.opId);
|
|
2325
|
-
} else if (_classPrivateFieldGet(this, _propToLastUpdate).get(_key3) == null) {
|
|
2326
|
-
isModified = true;
|
|
2327
|
-
} else if (_classPrivateFieldGet(this, _propToLastUpdate).get(_key3) === op.opId) {
|
|
2328
|
-
_classPrivateFieldGet(this, _propToLastUpdate).delete(_key3);
|
|
2329
|
-
|
|
2330
|
-
continue;
|
|
2331
|
-
} else {
|
|
2332
|
-
continue;
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
var _oldValue2 = _classPrivateFieldGet(this, _map).get(_key3);
|
|
2336
|
-
|
|
2337
|
-
if (isCrdt(_oldValue2)) {
|
|
2338
|
-
_oldValue2._detach();
|
|
2339
|
-
}
|
|
2340
|
-
|
|
2341
|
-
isModified = true;
|
|
2342
|
-
updateDelta[_key3] = {
|
|
2343
|
-
type: "update"
|
|
2344
|
-
};
|
|
2345
|
-
|
|
2346
|
-
_classPrivateFieldGet(this, _map).set(_key3, op.data[_key3]);
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
2350
|
-
reverse.unshift(reverseUpdate);
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
return isModified ? {
|
|
2354
|
-
modified: {
|
|
2355
|
-
node: this,
|
|
2356
|
-
type: "LiveObject",
|
|
2357
|
-
updates: updateDelta
|
|
2358
|
-
},
|
|
2359
|
-
reverse: reverse
|
|
2360
|
-
} : {
|
|
2361
|
-
modified: false
|
|
2362
|
-
};
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
function _applyDeleteObjectKey2(op) {
|
|
2366
|
-
var _updates4;
|
|
2367
|
-
|
|
2368
|
-
var key = op.key;
|
|
2369
|
-
|
|
2370
|
-
if (_classPrivateFieldGet(this, _map).has(key) === false) {
|
|
2371
|
-
return {
|
|
2372
|
-
modified: false
|
|
2373
|
-
};
|
|
2374
|
-
}
|
|
2375
|
-
|
|
2376
|
-
if (_classPrivateFieldGet(this, _propToLastUpdate).get(key) !== undefined) {
|
|
2377
|
-
return {
|
|
2378
|
-
modified: false
|
|
2379
|
-
};
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
var oldValue = _classPrivateFieldGet(this, _map).get(key);
|
|
2383
|
-
|
|
2384
|
-
var reverse = [];
|
|
2385
|
-
|
|
2386
|
-
if (isCrdt(oldValue)) {
|
|
2387
|
-
reverse = oldValue._serialize(this._id, op.key);
|
|
2388
|
-
|
|
2389
|
-
oldValue._detach();
|
|
2390
|
-
} else if (oldValue !== undefined) {
|
|
2391
|
-
var _data3;
|
|
2392
|
-
|
|
2393
|
-
reverse = [{
|
|
2394
|
-
type: OpType.UpdateObject,
|
|
2395
|
-
id: this._id,
|
|
2396
|
-
data: (_data3 = {}, _data3[key] = oldValue, _data3)
|
|
2397
|
-
}];
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
_classPrivateFieldGet(this, _map).delete(key);
|
|
2401
|
-
|
|
2402
|
-
return {
|
|
2403
|
-
modified: {
|
|
2404
|
-
node: this,
|
|
2405
|
-
type: "LiveObject",
|
|
2406
|
-
updates: (_updates4 = {}, _updates4[op.key] = {
|
|
2407
|
-
type: "delete"
|
|
2408
|
-
}, _updates4)
|
|
2409
|
-
},
|
|
2410
|
-
reverse: reverse
|
|
2411
|
-
};
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
2437
|
var BACKOFF_RETRY_DELAYS = [250, 500, 1000, 2000, 4000, 8000, 10000];
|
|
2415
2438
|
var BACKOFF_RETRY_DELAYS_SLOW = [2000, 30000, 60000, 300000];
|
|
2416
2439
|
var HEARTBEAT_INTERVAL = 30000;
|
|
@@ -2453,19 +2476,28 @@ function makeOthers(userMap) {
|
|
|
2453
2476
|
function makeStateMachine(state, context, mockedEffects) {
|
|
2454
2477
|
var effects = mockedEffects || {
|
|
2455
2478
|
authenticate: function authenticate(auth, createWebSocket) {
|
|
2456
|
-
|
|
2457
|
-
var token = _ref2.token;
|
|
2458
|
-
|
|
2459
|
-
if (state.connection.state !== "authenticating") {
|
|
2460
|
-
return;
|
|
2461
|
-
}
|
|
2479
|
+
var token = state.token;
|
|
2462
2480
|
|
|
2481
|
+
if (token && isTokenValid(token)) {
|
|
2463
2482
|
var parsedToken = parseToken(token);
|
|
2464
2483
|
var socket = createWebSocket(token);
|
|
2465
2484
|
authenticationSuccess(parsedToken, socket);
|
|
2466
|
-
}
|
|
2467
|
-
return
|
|
2468
|
-
|
|
2485
|
+
} else {
|
|
2486
|
+
return auth(context.roomId).then(function (_ref2) {
|
|
2487
|
+
var token = _ref2.token;
|
|
2488
|
+
|
|
2489
|
+
if (state.connection.state !== "authenticating") {
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
var parsedToken = parseToken(token);
|
|
2494
|
+
var socket = createWebSocket(token);
|
|
2495
|
+
authenticationSuccess(parsedToken, socket);
|
|
2496
|
+
state.token = token;
|
|
2497
|
+
}).catch(function (er) {
|
|
2498
|
+
return authenticationFailure(er);
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2469
2501
|
},
|
|
2470
2502
|
send: function send(messageOrMessages) {
|
|
2471
2503
|
if (state.socket == null) {
|
|
@@ -2528,9 +2560,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2528
2560
|
state.root = load(message.items);
|
|
2529
2561
|
}
|
|
2530
2562
|
|
|
2531
|
-
for (var
|
|
2532
|
-
if (state.root.get(
|
|
2533
|
-
state.root.set(
|
|
2563
|
+
for (var _key in state.defaultStorageRoot) {
|
|
2564
|
+
if (state.root.get(_key) == null) {
|
|
2565
|
+
state.root.set(_key, state.defaultStorageRoot[_key]);
|
|
2534
2566
|
}
|
|
2535
2567
|
}
|
|
2536
2568
|
}
|
|
@@ -2589,7 +2621,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2589
2621
|
generateId: generateId,
|
|
2590
2622
|
generateOpId: generateOpId,
|
|
2591
2623
|
dispatch: storageDispatch,
|
|
2592
|
-
roomId: context.
|
|
2624
|
+
roomId: context.roomId
|
|
2593
2625
|
});
|
|
2594
2626
|
}
|
|
2595
2627
|
|
|
@@ -2714,8 +2746,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2714
2746
|
data: {}
|
|
2715
2747
|
};
|
|
2716
2748
|
|
|
2717
|
-
for (var
|
|
2718
|
-
reverse.data[
|
|
2749
|
+
for (var _key2 in op.data) {
|
|
2750
|
+
reverse.data[_key2] = state.me[_key2];
|
|
2719
2751
|
}
|
|
2720
2752
|
|
|
2721
2753
|
state.me = _extends({}, state.me, op.data);
|
|
@@ -2723,8 +2755,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2723
2755
|
if (state.buffer.presence == null) {
|
|
2724
2756
|
state.buffer.presence = op.data;
|
|
2725
2757
|
} else {
|
|
2726
|
-
for (var
|
|
2727
|
-
state.buffer.presence[
|
|
2758
|
+
for (var _key3 in op.data) {
|
|
2759
|
+
state.buffer.presence[_key3] = op.data;
|
|
2728
2760
|
}
|
|
2729
2761
|
}
|
|
2730
2762
|
|
|
@@ -2799,55 +2831,19 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2799
2831
|
}
|
|
2800
2832
|
|
|
2801
2833
|
case OpType.CreateObject:
|
|
2802
|
-
{
|
|
2803
|
-
var parent = state.items.get(op.parentId);
|
|
2804
|
-
|
|
2805
|
-
if (parent == null) {
|
|
2806
|
-
return {
|
|
2807
|
-
modified: false
|
|
2808
|
-
};
|
|
2809
|
-
}
|
|
2810
|
-
|
|
2811
|
-
return parent._attachChild(op.id, op.parentKey, new LiveObject(op.data), op.opId, isLocal);
|
|
2812
|
-
}
|
|
2813
|
-
|
|
2814
2834
|
case OpType.CreateList:
|
|
2815
|
-
{
|
|
2816
|
-
var _parent = state.items.get(op.parentId);
|
|
2817
|
-
|
|
2818
|
-
if (_parent == null) {
|
|
2819
|
-
return {
|
|
2820
|
-
modified: false
|
|
2821
|
-
};
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
return _parent._attachChild(op.id, op.parentKey, new LiveList(), op.opId, isLocal);
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
case OpType.CreateRegister:
|
|
2828
|
-
{
|
|
2829
|
-
var _parent2 = state.items.get(op.parentId);
|
|
2830
|
-
|
|
2831
|
-
if (_parent2 == null) {
|
|
2832
|
-
return {
|
|
2833
|
-
modified: false
|
|
2834
|
-
};
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
return _parent2._attachChild(op.id, op.parentKey, new LiveRegister(op.data), op.opId, isLocal);
|
|
2838
|
-
}
|
|
2839
|
-
|
|
2840
2835
|
case OpType.CreateMap:
|
|
2836
|
+
case OpType.CreateRegister:
|
|
2841
2837
|
{
|
|
2842
|
-
var
|
|
2838
|
+
var parent = state.items.get(op.parentId);
|
|
2843
2839
|
|
|
2844
|
-
if (
|
|
2840
|
+
if (parent == null) {
|
|
2845
2841
|
return {
|
|
2846
2842
|
modified: false
|
|
2847
2843
|
};
|
|
2848
2844
|
}
|
|
2849
2845
|
|
|
2850
|
-
return
|
|
2846
|
+
return parent._attachChild(op, isLocal);
|
|
2851
2847
|
}
|
|
2852
2848
|
}
|
|
2853
2849
|
|
|
@@ -2916,9 +2912,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2916
2912
|
state.buffer.presence = {};
|
|
2917
2913
|
}
|
|
2918
2914
|
|
|
2919
|
-
for (var
|
|
2920
|
-
state.buffer.presence[
|
|
2921
|
-
oldValues[
|
|
2915
|
+
for (var _key4 in overrides) {
|
|
2916
|
+
state.buffer.presence[_key4] = overrides[_key4];
|
|
2917
|
+
oldValues[_key4] = state.me[_key4];
|
|
2922
2918
|
}
|
|
2923
2919
|
|
|
2924
2920
|
state.me = _extends({}, state.me, overrides);
|
|
@@ -2968,6 +2964,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2968
2964
|
console.error("Call to authentication endpoint failed", error);
|
|
2969
2965
|
}
|
|
2970
2966
|
|
|
2967
|
+
state.token = null;
|
|
2971
2968
|
updateConnection({
|
|
2972
2969
|
state: "unavailable"
|
|
2973
2970
|
});
|
|
@@ -3029,10 +3026,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3029
3026
|
function onRoomStateMessage(message) {
|
|
3030
3027
|
var newUsers = {};
|
|
3031
3028
|
|
|
3032
|
-
for (var
|
|
3033
|
-
var _connectionId = Number.parseInt(
|
|
3029
|
+
for (var _key5 in message.users) {
|
|
3030
|
+
var _connectionId = Number.parseInt(_key5);
|
|
3034
3031
|
|
|
3035
|
-
var user = message.users[
|
|
3032
|
+
var user = message.users[_key5];
|
|
3036
3033
|
newUsers[_connectionId] = {
|
|
3037
3034
|
connectionId: _connectionId,
|
|
3038
3035
|
info: user.info,
|
|
@@ -3086,19 +3083,38 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3086
3083
|
};
|
|
3087
3084
|
}
|
|
3088
3085
|
|
|
3086
|
+
function parseServerMessage(data) {
|
|
3087
|
+
if (!isJsonObject(data)) {
|
|
3088
|
+
return null;
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
return data;
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
function parseServerMessages(text) {
|
|
3095
|
+
var data = parseJson(text);
|
|
3096
|
+
|
|
3097
|
+
if (data === undefined) {
|
|
3098
|
+
return null;
|
|
3099
|
+
} else if (isJsonArray(data)) {
|
|
3100
|
+
return compact(data.map(function (item) {
|
|
3101
|
+
return parseServerMessage(item);
|
|
3102
|
+
}));
|
|
3103
|
+
} else {
|
|
3104
|
+
return compact([parseServerMessage(data)]);
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3089
3108
|
function onMessage(event) {
|
|
3090
3109
|
if (event.data === "pong") {
|
|
3091
3110
|
clearTimeout(state.timeoutHandles.pongTimeout);
|
|
3092
3111
|
return;
|
|
3093
3112
|
}
|
|
3094
3113
|
|
|
3095
|
-
var
|
|
3096
|
-
var subMessages = [];
|
|
3114
|
+
var messages = parseServerMessages(event.data);
|
|
3097
3115
|
|
|
3098
|
-
if (
|
|
3099
|
-
|
|
3100
|
-
} else {
|
|
3101
|
-
subMessages.push(message);
|
|
3116
|
+
if (messages === null || messages.length === 0) {
|
|
3117
|
+
return;
|
|
3102
3118
|
}
|
|
3103
3119
|
|
|
3104
3120
|
var updates = {
|
|
@@ -3106,10 +3122,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3106
3122
|
others: []
|
|
3107
3123
|
};
|
|
3108
3124
|
|
|
3109
|
-
for (var _iterator9 = _createForOfIteratorHelperLoose(
|
|
3110
|
-
var
|
|
3125
|
+
for (var _iterator9 = _createForOfIteratorHelperLoose(messages), _step9; !(_step9 = _iterator9()).done;) {
|
|
3126
|
+
var message = _step9.value;
|
|
3111
3127
|
|
|
3112
|
-
switch (
|
|
3128
|
+
switch (message.type) {
|
|
3113
3129
|
case ServerMessageType.UserJoined:
|
|
3114
3130
|
{
|
|
3115
3131
|
updates.others.push(onUserJoinedMessage(message));
|
|
@@ -3118,7 +3134,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3118
3134
|
|
|
3119
3135
|
case ServerMessageType.UpdatePresence:
|
|
3120
3136
|
{
|
|
3121
|
-
var othersPresenceUpdate = onUpdatePresenceMessage(
|
|
3137
|
+
var othersPresenceUpdate = onUpdatePresenceMessage(message);
|
|
3122
3138
|
|
|
3123
3139
|
if (othersPresenceUpdate) {
|
|
3124
3140
|
updates.others.push(othersPresenceUpdate);
|
|
@@ -3129,13 +3145,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3129
3145
|
|
|
3130
3146
|
case ServerMessageType.Event:
|
|
3131
3147
|
{
|
|
3132
|
-
onEvent(
|
|
3148
|
+
onEvent(message);
|
|
3133
3149
|
break;
|
|
3134
3150
|
}
|
|
3135
3151
|
|
|
3136
3152
|
case ServerMessageType.UserLeft:
|
|
3137
3153
|
{
|
|
3138
|
-
var _event = onUserLeftMessage(
|
|
3154
|
+
var _event = onUserLeftMessage(message);
|
|
3139
3155
|
|
|
3140
3156
|
if (_event) {
|
|
3141
3157
|
updates.others.push(_event);
|
|
@@ -3146,21 +3162,22 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3146
3162
|
|
|
3147
3163
|
case ServerMessageType.RoomState:
|
|
3148
3164
|
{
|
|
3149
|
-
updates.others.push(onRoomStateMessage(
|
|
3165
|
+
updates.others.push(onRoomStateMessage(message));
|
|
3150
3166
|
break;
|
|
3151
3167
|
}
|
|
3152
3168
|
|
|
3153
3169
|
case ServerMessageType.InitialStorageState:
|
|
3154
3170
|
{
|
|
3155
|
-
|
|
3156
|
-
|
|
3171
|
+
var offlineOps = new Map(state.offlineOperations);
|
|
3172
|
+
createOrUpdateRootFromMessage(message);
|
|
3173
|
+
applyAndSendOfflineOps(offlineOps);
|
|
3157
3174
|
_getInitialStateResolver == null ? void 0 : _getInitialStateResolver();
|
|
3158
3175
|
break;
|
|
3159
3176
|
}
|
|
3160
3177
|
|
|
3161
3178
|
case ServerMessageType.UpdateStorage:
|
|
3162
3179
|
{
|
|
3163
|
-
var applyResult = apply(
|
|
3180
|
+
var applyResult = apply(message.ops, false);
|
|
3164
3181
|
applyResult.updates.storageUpdates.forEach(function (value, key) {
|
|
3165
3182
|
updates.storageUpdates.set(key, mergeStorageUpdates(updates.storageUpdates.get(key), value));
|
|
3166
3183
|
});
|
|
@@ -3325,13 +3342,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3325
3342
|
connect();
|
|
3326
3343
|
}
|
|
3327
3344
|
|
|
3328
|
-
function applyAndSendOfflineOps() {
|
|
3329
|
-
if (
|
|
3345
|
+
function applyAndSendOfflineOps(offlineOps) {
|
|
3346
|
+
if (offlineOps.size === 0) {
|
|
3330
3347
|
return;
|
|
3331
3348
|
}
|
|
3332
3349
|
|
|
3333
3350
|
var messages = [];
|
|
3334
|
-
var ops = Array.from(
|
|
3351
|
+
var ops = Array.from(offlineOps.values());
|
|
3335
3352
|
var result = apply(ops, true);
|
|
3336
3353
|
messages.push({
|
|
3337
3354
|
type: ClientMessageType.UpdateStorage,
|
|
@@ -3437,8 +3454,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3437
3454
|
}
|
|
3438
3455
|
|
|
3439
3456
|
function clearListeners() {
|
|
3440
|
-
for (var
|
|
3441
|
-
state.listeners[
|
|
3457
|
+
for (var _key6 in state.listeners) {
|
|
3458
|
+
state.listeners[_key6] = [];
|
|
3442
3459
|
}
|
|
3443
3460
|
}
|
|
3444
3461
|
|
|
@@ -3664,6 +3681,7 @@ function defaultState(me, defaultStorageRoot) {
|
|
|
3664
3681
|
connection: {
|
|
3665
3682
|
state: "closed"
|
|
3666
3683
|
},
|
|
3684
|
+
token: null,
|
|
3667
3685
|
lastConnectionId: null,
|
|
3668
3686
|
socket: null,
|
|
3669
3687
|
listeners: {
|
|
@@ -3719,7 +3737,7 @@ function createRoom(options, context) {
|
|
|
3719
3737
|
var state = defaultState(options.defaultPresence, options.defaultStorageRoot);
|
|
3720
3738
|
var machine = makeStateMachine(state, context);
|
|
3721
3739
|
var room = {
|
|
3722
|
-
id: context.
|
|
3740
|
+
id: context.roomId,
|
|
3723
3741
|
getConnectionState: machine.selectors.getConnectionState,
|
|
3724
3742
|
getSelf: machine.selectors.getSelf,
|
|
3725
3743
|
subscribe: machine.subscribe,
|
|
@@ -3771,13 +3789,17 @@ function parseToken(token) {
|
|
|
3771
3789
|
throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");
|
|
3772
3790
|
}
|
|
3773
3791
|
|
|
3774
|
-
var data =
|
|
3792
|
+
var data = parseJson(atob(tokenParts[1]));
|
|
3775
3793
|
|
|
3776
|
-
if (typeof data.actor
|
|
3777
|
-
|
|
3794
|
+
if (data !== undefined && isJsonObject(data) && typeof data.actor === "number" && (data.id === undefined || typeof data.id === "string")) {
|
|
3795
|
+
return {
|
|
3796
|
+
actor: data.actor,
|
|
3797
|
+
id: data.id,
|
|
3798
|
+
info: data.info
|
|
3799
|
+
};
|
|
3778
3800
|
}
|
|
3779
3801
|
|
|
3780
|
-
|
|
3802
|
+
throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");
|
|
3781
3803
|
}
|
|
3782
3804
|
|
|
3783
3805
|
function prepareCreateWebSocket(liveblocksServer, WebSocketPolyfill) {
|
|
@@ -3883,7 +3905,7 @@ function createClient(options) {
|
|
|
3883
3905
|
defaultPresence: options.defaultPresence,
|
|
3884
3906
|
defaultStorageRoot: options.defaultStorageRoot
|
|
3885
3907
|
}, {
|
|
3886
|
-
|
|
3908
|
+
roomId: roomId,
|
|
3887
3909
|
throttleDelay: throttleDelay,
|
|
3888
3910
|
WebSocketPolyfill: clientOptions.WebSocketPolyfill,
|
|
3889
3911
|
fetchPolyfill: clientOptions.fetchPolyfill,
|
|
@@ -3969,33 +3991,42 @@ function prepareAuthentication(clientOptions) {
|
|
|
3969
3991
|
throw new Error("Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");
|
|
3970
3992
|
}
|
|
3971
3993
|
|
|
3972
|
-
function
|
|
3994
|
+
function lsonObjectToJson(obj) {
|
|
3973
3995
|
var result = {};
|
|
3974
|
-
var obj = liveObject.toObject();
|
|
3975
3996
|
|
|
3976
3997
|
for (var _key in obj) {
|
|
3977
|
-
result[_key] =
|
|
3998
|
+
result[_key] = lsonToJson(obj[_key]);
|
|
3978
3999
|
}
|
|
3979
4000
|
|
|
3980
4001
|
return result;
|
|
3981
4002
|
}
|
|
3982
4003
|
|
|
4004
|
+
function liveObjectToJson(liveObject) {
|
|
4005
|
+
return lsonObjectToJson(liveObject.toObject());
|
|
4006
|
+
}
|
|
4007
|
+
|
|
3983
4008
|
function liveMapToJson(map) {
|
|
3984
4009
|
var result = {};
|
|
3985
|
-
var obj = Object.fromEntries(map);
|
|
3986
4010
|
|
|
3987
|
-
for (var
|
|
3988
|
-
|
|
4011
|
+
for (var _iterator = _createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
4012
|
+
var _step$value = _step.value,
|
|
4013
|
+
_key2 = _step$value[0],
|
|
4014
|
+
value = _step$value[1];
|
|
4015
|
+
result[_key2] = lsonToJson(value);
|
|
3989
4016
|
}
|
|
3990
4017
|
|
|
3991
4018
|
return result;
|
|
3992
4019
|
}
|
|
3993
4020
|
|
|
4021
|
+
function lsonListToJson(value) {
|
|
4022
|
+
return value.map(lsonToJson);
|
|
4023
|
+
}
|
|
4024
|
+
|
|
3994
4025
|
function liveListToJson(value) {
|
|
3995
|
-
return value.toArray()
|
|
4026
|
+
return lsonListToJson(value.toArray());
|
|
3996
4027
|
}
|
|
3997
4028
|
|
|
3998
|
-
function
|
|
4029
|
+
function lsonToJson(value) {
|
|
3999
4030
|
if (value instanceof LiveObject) {
|
|
4000
4031
|
return liveObjectToJson(value);
|
|
4001
4032
|
} else if (value instanceof LiveList) {
|
|
@@ -4004,13 +4035,21 @@ function liveNodeToJson(value) {
|
|
|
4004
4035
|
return liveMapToJson(value);
|
|
4005
4036
|
} else if (value instanceof LiveRegister) {
|
|
4006
4037
|
return value.data;
|
|
4038
|
+
} else if (value instanceof AbstractCrdt) {
|
|
4039
|
+
throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
if (Array.isArray(value)) {
|
|
4043
|
+
return lsonListToJson(value);
|
|
4044
|
+
} else if (isPlainObject(value)) {
|
|
4045
|
+
return lsonObjectToJson(value);
|
|
4007
4046
|
}
|
|
4008
4047
|
|
|
4009
4048
|
return value;
|
|
4010
4049
|
}
|
|
4011
4050
|
|
|
4012
4051
|
function isPlainObject(obj) {
|
|
4013
|
-
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
4052
|
+
return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
|
|
4014
4053
|
}
|
|
4015
4054
|
|
|
4016
4055
|
function anyToCrdt(obj) {
|
|
@@ -4093,8 +4132,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4093
4132
|
if (liveListNode instanceof LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
4094
4133
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
4095
4134
|
} else {
|
|
4096
|
-
liveList.
|
|
4097
|
-
liveList.insert(anyToCrdt(nextNode), i);
|
|
4135
|
+
liveList.set(i, anyToCrdt(nextNode));
|
|
4098
4136
|
}
|
|
4099
4137
|
|
|
4100
4138
|
i++;
|
|
@@ -4105,9 +4143,11 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4105
4143
|
i++;
|
|
4106
4144
|
}
|
|
4107
4145
|
|
|
4108
|
-
|
|
4146
|
+
var _localI = i;
|
|
4147
|
+
|
|
4148
|
+
while (_localI <= prevEnd) {
|
|
4109
4149
|
liveList.delete(i);
|
|
4110
|
-
|
|
4150
|
+
_localI++;
|
|
4111
4151
|
}
|
|
4112
4152
|
}
|
|
4113
4153
|
}
|
|
@@ -4199,7 +4239,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4199
4239
|
var _update$updates$_key, _update$updates$_key2;
|
|
4200
4240
|
|
|
4201
4241
|
if (((_update$updates$_key = update.updates[_key6]) == null ? void 0 : _update$updates$_key.type) === "update") {
|
|
4202
|
-
newState[_key6] =
|
|
4242
|
+
newState[_key6] = lsonToJson(update.node.get(_key6));
|
|
4203
4243
|
} else if (((_update$updates$_key2 = update.updates[_key6]) == null ? void 0 : _update$updates$_key2.type) === "delete") {
|
|
4204
4244
|
delete newState[_key6];
|
|
4205
4245
|
}
|
|
@@ -4218,24 +4258,32 @@ function patchImmutableNode(state, path, update) {
|
|
|
4218
4258
|
return x;
|
|
4219
4259
|
});
|
|
4220
4260
|
|
|
4221
|
-
|
|
4222
|
-
var listUpdate =
|
|
4261
|
+
var _loop = function _loop() {
|
|
4262
|
+
var listUpdate = _step2.value;
|
|
4223
4263
|
|
|
4224
|
-
if (listUpdate.type === "
|
|
4264
|
+
if (listUpdate.type === "set") {
|
|
4265
|
+
_newState = _newState.map(function (item, index) {
|
|
4266
|
+
return index === listUpdate.index ? listUpdate.item : item;
|
|
4267
|
+
});
|
|
4268
|
+
} else if (listUpdate.type === "insert") {
|
|
4225
4269
|
if (listUpdate.index === _newState.length) {
|
|
4226
|
-
_newState.push(
|
|
4270
|
+
_newState.push(lsonToJson(listUpdate.item));
|
|
4227
4271
|
} else {
|
|
4228
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4272
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index));
|
|
4229
4273
|
}
|
|
4230
4274
|
} else if (listUpdate.type === "delete") {
|
|
4231
4275
|
_newState.splice(listUpdate.index, 1);
|
|
4232
4276
|
} else if (listUpdate.type === "move") {
|
|
4233
4277
|
if (listUpdate.previousIndex > listUpdate.index) {
|
|
4234
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4278
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1));
|
|
4235
4279
|
} else {
|
|
4236
|
-
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [
|
|
4280
|
+
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index + 1));
|
|
4237
4281
|
}
|
|
4238
4282
|
}
|
|
4283
|
+
};
|
|
4284
|
+
|
|
4285
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
4286
|
+
_loop();
|
|
4239
4287
|
}
|
|
4240
4288
|
|
|
4241
4289
|
return _newState;
|
|
@@ -4253,7 +4301,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4253
4301
|
var _update$updates$_key3, _update$updates$_key4;
|
|
4254
4302
|
|
|
4255
4303
|
if (((_update$updates$_key3 = update.updates[_key7]) == null ? void 0 : _update$updates$_key3.type) === "update") {
|
|
4256
|
-
_newState2[_key7] =
|
|
4304
|
+
_newState2[_key7] = lsonToJson(update.node.get(_key7));
|
|
4257
4305
|
} else if (((_update$updates$_key4 = update.updates[_key7]) == null ? void 0 : _update$updates$_key4.type) === "delete") {
|
|
4258
4306
|
delete _newState2[_key7];
|
|
4259
4307
|
}
|
|
@@ -4277,7 +4325,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4277
4325
|
|
|
4278
4326
|
var internals = {
|
|
4279
4327
|
liveObjectToJson: liveObjectToJson,
|
|
4280
|
-
|
|
4328
|
+
lsonToJson: lsonToJson,
|
|
4281
4329
|
patchLiveList: patchLiveList,
|
|
4282
4330
|
patchImmutableObject: patchImmutableObject,
|
|
4283
4331
|
patchLiveObject: patchLiveObject,
|