@liveblocks/client 0.15.10 → 0.16.0
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 +438 -453
- package/lib/esm/index.mjs +438 -453
- package/lib/index.d.ts +204 -160
- package/lib/index.js +563 -557
- package/lib/internal.d.ts +29 -15
- package/package.json +8 -4
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,40 +249,12 @@ 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
|
|
|
327
|
-
_proto._apply = function _apply(op,
|
|
257
|
+
_proto._apply = function _apply(op, _isLocal) {
|
|
328
258
|
switch (op.type) {
|
|
329
259
|
case OpType.DeleteCrdt:
|
|
330
260
|
{
|
|
@@ -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,11 +513,11 @@ 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
|
|
|
602
|
-
_proto._detachChild = function _detachChild(
|
|
520
|
+
_proto._detachChild = function _detachChild(_crdt) {
|
|
603
521
|
throw new Error("Method not implemented.");
|
|
604
522
|
};
|
|
605
523
|
|
|
@@ -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
|
}
|
|
@@ -656,7 +564,6 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
656
564
|
|
|
657
565
|
LiveList._deserialize = function _deserialize(_ref, parentToChildren, doc) {
|
|
658
566
|
var id = _ref[0];
|
|
659
|
-
_ref[1];
|
|
660
567
|
var list = new LiveList([]);
|
|
661
568
|
|
|
662
569
|
list._attach(id, doc);
|
|
@@ -673,9 +580,9 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
673
580
|
|
|
674
581
|
child._setParentLink(list, entry[1].parentKey);
|
|
675
582
|
|
|
676
|
-
|
|
583
|
+
list._items.push([child, entry[1].parentKey]);
|
|
677
584
|
|
|
678
|
-
|
|
585
|
+
list._items.sort(function (itemA, itemB) {
|
|
679
586
|
return compare(itemA[1], itemB[1]);
|
|
680
587
|
});
|
|
681
588
|
}
|
|
@@ -685,7 +592,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
685
592
|
|
|
686
593
|
var _proto = LiveList.prototype;
|
|
687
594
|
|
|
688
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
595
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
689
596
|
if (this._id == null) {
|
|
690
597
|
throw new Error("Cannot serialize item is not attached");
|
|
691
598
|
}
|
|
@@ -698,13 +605,14 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
698
605
|
var op = {
|
|
699
606
|
id: this._id,
|
|
700
607
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
608
|
+
intent: intent,
|
|
701
609
|
type: OpType.CreateList,
|
|
702
610
|
parentId: parentId,
|
|
703
611
|
parentKey: parentKey
|
|
704
612
|
};
|
|
705
613
|
ops.push(op);
|
|
706
614
|
|
|
707
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
615
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this._items), _step2; !(_step2 = _iterator2()).done;) {
|
|
708
616
|
var _step2$value = _step2.value,
|
|
709
617
|
_value = _step2$value[0],
|
|
710
618
|
key = _step2$value[1];
|
|
@@ -715,7 +623,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
715
623
|
};
|
|
716
624
|
|
|
717
625
|
_proto._indexOfPosition = function _indexOfPosition(position) {
|
|
718
|
-
return
|
|
626
|
+
return this._items.findIndex(function (item) {
|
|
719
627
|
return item[1] === position;
|
|
720
628
|
});
|
|
721
629
|
};
|
|
@@ -723,10 +631,9 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
723
631
|
_proto._attach = function _attach(id, doc) {
|
|
724
632
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
725
633
|
|
|
726
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
634
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(this._items), _step3; !(_step3 = _iterator3()).done;) {
|
|
727
635
|
var _step3$value = _step3.value,
|
|
728
636
|
_item2 = _step3$value[0];
|
|
729
|
-
_step3$value[1];
|
|
730
637
|
|
|
731
638
|
_item2._attach(doc.generateId(), doc);
|
|
732
639
|
}
|
|
@@ -735,7 +642,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
735
642
|
_proto._detach = function _detach() {
|
|
736
643
|
_AbstractCrdt.prototype._detach.call(this);
|
|
737
644
|
|
|
738
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
645
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._items), _step4; !(_step4 = _iterator4()).done;) {
|
|
739
646
|
var _step4$value = _step4.value,
|
|
740
647
|
_value2 = _step4$value[0];
|
|
741
648
|
|
|
@@ -743,11 +650,17 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
743
650
|
}
|
|
744
651
|
};
|
|
745
652
|
|
|
746
|
-
_proto._attachChild = function _attachChild(
|
|
653
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
747
654
|
if (this._doc == null) {
|
|
748
655
|
throw new Error("Can't attach child if doc is not present");
|
|
749
656
|
}
|
|
750
657
|
|
|
658
|
+
var id = op.id,
|
|
659
|
+
parentKey = op.parentKey,
|
|
660
|
+
intent = op.intent;
|
|
661
|
+
var key = parentKey;
|
|
662
|
+
var child = creationOpToLiveStructure(op);
|
|
663
|
+
|
|
751
664
|
if (this._doc.getItem(id) !== undefined) {
|
|
752
665
|
return {
|
|
753
666
|
modified: false
|
|
@@ -758,33 +671,52 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
758
671
|
|
|
759
672
|
child._setParentLink(this, key);
|
|
760
673
|
|
|
761
|
-
var index =
|
|
674
|
+
var index = this._items.findIndex(function (entry) {
|
|
762
675
|
return entry[1] === key;
|
|
763
676
|
});
|
|
764
677
|
|
|
765
678
|
var newKey = key;
|
|
766
679
|
|
|
767
680
|
if (index !== -1) {
|
|
768
|
-
if (
|
|
769
|
-
var
|
|
770
|
-
|
|
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;
|
|
771
703
|
newKey = makePosition(before, after);
|
|
772
704
|
|
|
773
705
|
child._setParentLink(this, newKey);
|
|
774
706
|
} else {
|
|
775
|
-
var
|
|
707
|
+
var _this$_items;
|
|
776
708
|
|
|
777
|
-
|
|
709
|
+
this._items[index][1] = makePosition(key, (_this$_items = this._items[index + 1]) == null ? void 0 : _this$_items[1]);
|
|
778
710
|
}
|
|
779
711
|
}
|
|
780
712
|
|
|
781
|
-
|
|
713
|
+
this._items.push([child, newKey]);
|
|
782
714
|
|
|
783
|
-
|
|
715
|
+
this._items.sort(function (itemA, itemB) {
|
|
784
716
|
return compare(itemA[1], itemB[1]);
|
|
785
717
|
});
|
|
786
718
|
|
|
787
|
-
var newIndex =
|
|
719
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
788
720
|
return entry[1] === newKey;
|
|
789
721
|
});
|
|
790
722
|
|
|
@@ -809,11 +741,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
809
741
|
if (child) {
|
|
810
742
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
811
743
|
|
|
812
|
-
var indexToDelete =
|
|
744
|
+
var indexToDelete = this._items.findIndex(function (item) {
|
|
813
745
|
return item[0] === child;
|
|
814
746
|
});
|
|
815
747
|
|
|
816
|
-
|
|
748
|
+
this._items.splice(indexToDelete, 1);
|
|
817
749
|
|
|
818
750
|
child._detach();
|
|
819
751
|
|
|
@@ -839,21 +771,21 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
839
771
|
_proto._setChildKey = function _setChildKey(key, child, previousKey) {
|
|
840
772
|
child._setParentLink(this, key);
|
|
841
773
|
|
|
842
|
-
var previousIndex =
|
|
774
|
+
var previousIndex = this._items.findIndex(function (entry) {
|
|
843
775
|
return entry[0]._id === child._id;
|
|
844
776
|
});
|
|
845
777
|
|
|
846
|
-
var index =
|
|
778
|
+
var index = this._items.findIndex(function (entry) {
|
|
847
779
|
return entry[1] === key;
|
|
848
780
|
});
|
|
849
781
|
|
|
850
782
|
if (index !== -1) {
|
|
851
|
-
var
|
|
783
|
+
var _this$_items2;
|
|
852
784
|
|
|
853
|
-
|
|
785
|
+
this._items[index][1] = makePosition(key, (_this$_items2 = this._items[index + 1]) == null ? void 0 : _this$_items2[1]);
|
|
854
786
|
}
|
|
855
787
|
|
|
856
|
-
var item =
|
|
788
|
+
var item = this._items.find(function (item) {
|
|
857
789
|
return item[0] === child;
|
|
858
790
|
});
|
|
859
791
|
|
|
@@ -861,11 +793,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
861
793
|
item[1] = key;
|
|
862
794
|
}
|
|
863
795
|
|
|
864
|
-
|
|
796
|
+
this._items.sort(function (itemA, itemB) {
|
|
865
797
|
return compare(itemA[1], itemB[1]);
|
|
866
798
|
});
|
|
867
799
|
|
|
868
|
-
var newIndex =
|
|
800
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
869
801
|
return entry[0]._id === child._id;
|
|
870
802
|
});
|
|
871
803
|
|
|
@@ -908,24 +840,24 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
908
840
|
};
|
|
909
841
|
|
|
910
842
|
_proto.insert = function insert(element, index) {
|
|
911
|
-
if (index < 0 || index >
|
|
912
|
-
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);
|
|
913
845
|
}
|
|
914
846
|
|
|
915
|
-
var before =
|
|
916
|
-
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;
|
|
917
849
|
var position = makePosition(before, after);
|
|
918
850
|
var value = selfOrRegister(element);
|
|
919
851
|
|
|
920
852
|
value._setParentLink(this, position);
|
|
921
853
|
|
|
922
|
-
|
|
854
|
+
this._items.push([value, position]);
|
|
923
855
|
|
|
924
|
-
|
|
856
|
+
this._items.sort(function (itemA, itemB) {
|
|
925
857
|
return compare(itemA[1], itemB[1]);
|
|
926
858
|
});
|
|
927
859
|
|
|
928
|
-
var newIndex =
|
|
860
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
929
861
|
return entry[1] === position;
|
|
930
862
|
});
|
|
931
863
|
|
|
@@ -957,7 +889,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
957
889
|
throw new Error("targetIndex cannot be less than 0");
|
|
958
890
|
}
|
|
959
891
|
|
|
960
|
-
if (targetIndex >=
|
|
892
|
+
if (targetIndex >= this._items.length) {
|
|
961
893
|
throw new Error("targetIndex cannot be greater or equal than the list length");
|
|
962
894
|
}
|
|
963
895
|
|
|
@@ -965,7 +897,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
965
897
|
throw new Error("index cannot be less than 0");
|
|
966
898
|
}
|
|
967
899
|
|
|
968
|
-
if (index >=
|
|
900
|
+
if (index >= this._items.length) {
|
|
969
901
|
throw new Error("index cannot be greater or equal than the list length");
|
|
970
902
|
}
|
|
971
903
|
|
|
@@ -973,27 +905,25 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
973
905
|
var afterPosition = null;
|
|
974
906
|
|
|
975
907
|
if (index < targetIndex) {
|
|
976
|
-
afterPosition = targetIndex ===
|
|
977
|
-
beforePosition =
|
|
908
|
+
afterPosition = targetIndex === this._items.length - 1 ? undefined : this._items[targetIndex + 1][1];
|
|
909
|
+
beforePosition = this._items[targetIndex][1];
|
|
978
910
|
} else {
|
|
979
|
-
afterPosition =
|
|
980
|
-
beforePosition = targetIndex === 0 ? undefined :
|
|
911
|
+
afterPosition = this._items[targetIndex][1];
|
|
912
|
+
beforePosition = targetIndex === 0 ? undefined : this._items[targetIndex - 1][1];
|
|
981
913
|
}
|
|
982
914
|
|
|
983
915
|
var position = makePosition(beforePosition, afterPosition);
|
|
984
|
-
|
|
985
|
-
var item = _classPrivateFieldGet(this, _items)[index];
|
|
986
|
-
|
|
916
|
+
var item = this._items[index];
|
|
987
917
|
var previousPosition = item[1];
|
|
988
918
|
item[1] = position;
|
|
989
919
|
|
|
990
920
|
item[0]._setParentLink(this, position);
|
|
991
921
|
|
|
992
|
-
|
|
922
|
+
this._items.sort(function (itemA, itemB) {
|
|
993
923
|
return compare(itemA[1], itemB[1]);
|
|
994
924
|
});
|
|
995
925
|
|
|
996
|
-
var newIndex =
|
|
926
|
+
var newIndex = this._items.findIndex(function (entry) {
|
|
997
927
|
return entry[1] === position;
|
|
998
928
|
});
|
|
999
929
|
|
|
@@ -1024,15 +954,15 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1024
954
|
};
|
|
1025
955
|
|
|
1026
956
|
_proto.delete = function _delete(index) {
|
|
1027
|
-
if (index < 0 || index >=
|
|
1028
|
-
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));
|
|
1029
959
|
}
|
|
1030
960
|
|
|
1031
|
-
var item =
|
|
961
|
+
var item = this._items[index];
|
|
1032
962
|
|
|
1033
963
|
item[0]._detach();
|
|
1034
964
|
|
|
1035
|
-
|
|
965
|
+
this._items.splice(index, 1);
|
|
1036
966
|
|
|
1037
967
|
if (this._doc) {
|
|
1038
968
|
var childRecordId = item[0]._id;
|
|
@@ -1064,7 +994,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1064
994
|
var updateDelta = [];
|
|
1065
995
|
var i = 0;
|
|
1066
996
|
|
|
1067
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
997
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._items), _step5; !(_step5 = _iterator5()).done;) {
|
|
1068
998
|
var _item3 = _step5.value;
|
|
1069
999
|
|
|
1070
1000
|
_item3[0]._detach();
|
|
@@ -1086,8 +1016,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1086
1016
|
i++;
|
|
1087
1017
|
}
|
|
1088
1018
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1019
|
+
this._items = [];
|
|
1091
1020
|
var storageUpdates = new Map();
|
|
1092
1021
|
storageUpdates.set(this._id, {
|
|
1093
1022
|
node: this,
|
|
@@ -1097,18 +1026,55 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1097
1026
|
|
|
1098
1027
|
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
1099
1028
|
} else {
|
|
1100
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
1029
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._items), _step6; !(_step6 = _iterator6()).done;) {
|
|
1101
1030
|
var _item4 = _step6.value;
|
|
1102
1031
|
|
|
1103
1032
|
_item4[0]._detach();
|
|
1104
1033
|
}
|
|
1105
1034
|
|
|
1106
|
-
|
|
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);
|
|
1107
1073
|
}
|
|
1108
1074
|
};
|
|
1109
1075
|
|
|
1110
1076
|
_proto.toArray = function toArray() {
|
|
1111
|
-
return
|
|
1077
|
+
return this._items.map(function (entry) {
|
|
1112
1078
|
return selfOrRegisterValue(entry[0]);
|
|
1113
1079
|
});
|
|
1114
1080
|
};
|
|
@@ -1134,11 +1100,11 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1134
1100
|
};
|
|
1135
1101
|
|
|
1136
1102
|
_proto.get = function get(index) {
|
|
1137
|
-
if (index < 0 || index >=
|
|
1103
|
+
if (index < 0 || index >= this._items.length) {
|
|
1138
1104
|
return undefined;
|
|
1139
1105
|
}
|
|
1140
1106
|
|
|
1141
|
-
return selfOrRegisterValue(
|
|
1107
|
+
return selfOrRegisterValue(this._items[index][0]);
|
|
1142
1108
|
};
|
|
1143
1109
|
|
|
1144
1110
|
_proto.indexOf = function indexOf(searchElement, fromIndex) {
|
|
@@ -1150,7 +1116,7 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1150
1116
|
};
|
|
1151
1117
|
|
|
1152
1118
|
_proto.map = function map(callback) {
|
|
1153
|
-
return
|
|
1119
|
+
return this._items.map(function (entry, i) {
|
|
1154
1120
|
return callback(selfOrRegisterValue(entry[0]), i);
|
|
1155
1121
|
});
|
|
1156
1122
|
};
|
|
@@ -1159,42 +1125,33 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
1159
1125
|
return this.toArray().some(predicate);
|
|
1160
1126
|
};
|
|
1161
1127
|
|
|
1162
|
-
_proto[
|
|
1163
|
-
return new LiveListIterator(
|
|
1128
|
+
_proto[Symbol.iterator] = function () {
|
|
1129
|
+
return new LiveListIterator(this._items);
|
|
1164
1130
|
};
|
|
1165
1131
|
|
|
1166
1132
|
_createClass(LiveList, [{
|
|
1167
1133
|
key: "length",
|
|
1168
1134
|
get: function get() {
|
|
1169
|
-
return
|
|
1135
|
+
return this._items.length;
|
|
1170
1136
|
}
|
|
1171
1137
|
}]);
|
|
1172
1138
|
|
|
1173
1139
|
return LiveList;
|
|
1174
1140
|
}(AbstractCrdt);
|
|
1175
1141
|
|
|
1176
|
-
var _innerIterator = new WeakMap();
|
|
1177
|
-
|
|
1178
|
-
_Symbol$iterator2 = Symbol.iterator;
|
|
1179
|
-
|
|
1180
1142
|
var LiveListIterator = function () {
|
|
1181
1143
|
function LiveListIterator(items) {
|
|
1182
|
-
_innerIterator.
|
|
1183
|
-
writable: true,
|
|
1184
|
-
value: void 0
|
|
1185
|
-
});
|
|
1186
|
-
|
|
1187
|
-
_classPrivateFieldSet(this, _innerIterator, items[Symbol.iterator]());
|
|
1144
|
+
this._innerIterator = items[Symbol.iterator]();
|
|
1188
1145
|
}
|
|
1189
1146
|
|
|
1190
1147
|
var _proto2 = LiveListIterator.prototype;
|
|
1191
1148
|
|
|
1192
|
-
_proto2[
|
|
1149
|
+
_proto2[Symbol.iterator] = function () {
|
|
1193
1150
|
return this;
|
|
1194
1151
|
};
|
|
1195
1152
|
|
|
1196
1153
|
_proto2.next = function next() {
|
|
1197
|
-
var result =
|
|
1154
|
+
var result = this._innerIterator.next();
|
|
1198
1155
|
|
|
1199
1156
|
if (result.done) {
|
|
1200
1157
|
return {
|
|
@@ -1211,11 +1168,6 @@ var LiveListIterator = function () {
|
|
|
1211
1168
|
return LiveListIterator;
|
|
1212
1169
|
}();
|
|
1213
1170
|
|
|
1214
|
-
var _Symbol$iterator;
|
|
1215
|
-
|
|
1216
|
-
var _map$1 = new WeakMap();
|
|
1217
|
-
|
|
1218
|
-
_Symbol$iterator = Symbol.iterator;
|
|
1219
1171
|
var LiveMap = function (_AbstractCrdt) {
|
|
1220
1172
|
_inheritsLoose(LiveMap, _AbstractCrdt);
|
|
1221
1173
|
|
|
@@ -1224,11 +1176,6 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1224
1176
|
|
|
1225
1177
|
_this = _AbstractCrdt.call(this) || this;
|
|
1226
1178
|
|
|
1227
|
-
_map$1.set(_assertThisInitialized(_this), {
|
|
1228
|
-
writable: true,
|
|
1229
|
-
value: void 0
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
1179
|
if (entries) {
|
|
1233
1180
|
var mappedEntries = [];
|
|
1234
1181
|
|
|
@@ -1242,9 +1189,9 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1242
1189
|
mappedEntries.push([entry[0], _value]);
|
|
1243
1190
|
}
|
|
1244
1191
|
|
|
1245
|
-
|
|
1192
|
+
_this._map = new Map(mappedEntries);
|
|
1246
1193
|
} else {
|
|
1247
|
-
|
|
1194
|
+
_this._map = new Map();
|
|
1248
1195
|
}
|
|
1249
1196
|
|
|
1250
1197
|
return _this;
|
|
@@ -1252,7 +1199,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1252
1199
|
|
|
1253
1200
|
var _proto = LiveMap.prototype;
|
|
1254
1201
|
|
|
1255
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1202
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1256
1203
|
if (this._id == null) {
|
|
1257
1204
|
throw new Error("Cannot serialize item is not attached");
|
|
1258
1205
|
}
|
|
@@ -1266,16 +1213,17 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1266
1213
|
id: this._id,
|
|
1267
1214
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1268
1215
|
type: OpType.CreateMap,
|
|
1216
|
+
intent: intent,
|
|
1269
1217
|
parentId: parentId,
|
|
1270
1218
|
parentKey: parentKey
|
|
1271
1219
|
};
|
|
1272
1220
|
ops.push(op);
|
|
1273
1221
|
|
|
1274
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
1222
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(this._map), _step2; !(_step2 = _iterator2()).done;) {
|
|
1275
1223
|
var _step2$value = _step2.value,
|
|
1276
|
-
|
|
1224
|
+
_key2 = _step2$value[0],
|
|
1277
1225
|
_value2 = _step2$value[1];
|
|
1278
|
-
ops.push.apply(ops, _value2._serialize(this._id,
|
|
1226
|
+
ops.push.apply(ops, _value2._serialize(this._id, _key2, doc));
|
|
1279
1227
|
}
|
|
1280
1228
|
|
|
1281
1229
|
return ops;
|
|
@@ -1311,7 +1259,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1311
1259
|
|
|
1312
1260
|
child._setParentLink(map, crdt.parentKey);
|
|
1313
1261
|
|
|
1314
|
-
|
|
1262
|
+
map._map.set(crdt.parentKey, child);
|
|
1315
1263
|
}
|
|
1316
1264
|
|
|
1317
1265
|
return map;
|
|
@@ -1320,7 +1268,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1320
1268
|
_proto._attach = function _attach(id, doc) {
|
|
1321
1269
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1322
1270
|
|
|
1323
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
1271
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
1324
1272
|
var _step4$value = _step4.value;
|
|
1325
1273
|
_step4$value[0];
|
|
1326
1274
|
var _value3 = _step4$value[1];
|
|
@@ -1331,20 +1279,25 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1331
1279
|
}
|
|
1332
1280
|
};
|
|
1333
1281
|
|
|
1334
|
-
_proto._attachChild = function _attachChild(
|
|
1282
|
+
_proto._attachChild = function _attachChild(op, _isLocal) {
|
|
1335
1283
|
var _updates;
|
|
1336
1284
|
|
|
1337
1285
|
if (this._doc == null) {
|
|
1338
1286
|
throw new Error("Can't attach child if doc is not present");
|
|
1339
1287
|
}
|
|
1340
1288
|
|
|
1289
|
+
var id = op.id,
|
|
1290
|
+
parentKey = op.parentKey;
|
|
1291
|
+
var key = parentKey;
|
|
1292
|
+
var child = creationOpToLiveStructure(op);
|
|
1293
|
+
|
|
1341
1294
|
if (this._doc.getItem(id) !== undefined) {
|
|
1342
1295
|
return {
|
|
1343
1296
|
modified: false
|
|
1344
1297
|
};
|
|
1345
1298
|
}
|
|
1346
1299
|
|
|
1347
|
-
var previousValue =
|
|
1300
|
+
var previousValue = this._map.get(key);
|
|
1348
1301
|
|
|
1349
1302
|
var reverse;
|
|
1350
1303
|
|
|
@@ -1363,7 +1316,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1363
1316
|
|
|
1364
1317
|
child._attach(id, this._doc);
|
|
1365
1318
|
|
|
1366
|
-
|
|
1319
|
+
this._map.set(key, child);
|
|
1367
1320
|
|
|
1368
1321
|
return {
|
|
1369
1322
|
modified: {
|
|
@@ -1380,7 +1333,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1380
1333
|
_proto._detach = function _detach() {
|
|
1381
1334
|
_AbstractCrdt.prototype._detach.call(this);
|
|
1382
1335
|
|
|
1383
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
1336
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map.values()), _step5; !(_step5 = _iterator5()).done;) {
|
|
1384
1337
|
var item = _step5.value;
|
|
1385
1338
|
|
|
1386
1339
|
item._detach();
|
|
@@ -1392,13 +1345,13 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1392
1345
|
|
|
1393
1346
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
1394
1347
|
|
|
1395
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
1348
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map), _step6; !(_step6 = _iterator6()).done;) {
|
|
1396
1349
|
var _step6$value = _step6.value,
|
|
1397
1350
|
_key3 = _step6$value[0],
|
|
1398
1351
|
_value4 = _step6$value[1];
|
|
1399
1352
|
|
|
1400
1353
|
if (_value4 === child) {
|
|
1401
|
-
|
|
1354
|
+
this._map.delete(_key3);
|
|
1402
1355
|
}
|
|
1403
1356
|
}
|
|
1404
1357
|
|
|
@@ -1428,7 +1381,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1428
1381
|
};
|
|
1429
1382
|
|
|
1430
1383
|
_proto.get = function get(key) {
|
|
1431
|
-
var value =
|
|
1384
|
+
var value = this._map.get(key);
|
|
1432
1385
|
|
|
1433
1386
|
if (value == undefined) {
|
|
1434
1387
|
return undefined;
|
|
@@ -1438,7 +1391,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1438
1391
|
};
|
|
1439
1392
|
|
|
1440
1393
|
_proto.set = function set(key, value) {
|
|
1441
|
-
var oldValue =
|
|
1394
|
+
var oldValue = this._map.get(key);
|
|
1442
1395
|
|
|
1443
1396
|
if (oldValue) {
|
|
1444
1397
|
oldValue._detach();
|
|
@@ -1448,7 +1401,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1448
1401
|
|
|
1449
1402
|
item._setParentLink(this, key);
|
|
1450
1403
|
|
|
1451
|
-
|
|
1404
|
+
this._map.set(key, item);
|
|
1452
1405
|
|
|
1453
1406
|
if (this._doc && this._id) {
|
|
1454
1407
|
var _updates3;
|
|
@@ -1474,11 +1427,11 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1474
1427
|
};
|
|
1475
1428
|
|
|
1476
1429
|
_proto.has = function has(key) {
|
|
1477
|
-
return
|
|
1430
|
+
return this._map.has(key);
|
|
1478
1431
|
};
|
|
1479
1432
|
|
|
1480
1433
|
_proto.delete = function _delete(key) {
|
|
1481
|
-
var item =
|
|
1434
|
+
var item = this._map.get(key);
|
|
1482
1435
|
|
|
1483
1436
|
if (item == null) {
|
|
1484
1437
|
return false;
|
|
@@ -1486,7 +1439,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1486
1439
|
|
|
1487
1440
|
item._detach();
|
|
1488
1441
|
|
|
1489
|
-
|
|
1442
|
+
this._map.delete(key);
|
|
1490
1443
|
|
|
1491
1444
|
if (this._doc && item._id) {
|
|
1492
1445
|
var _updates4;
|
|
@@ -1513,7 +1466,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1513
1466
|
_proto.entries = function entries() {
|
|
1514
1467
|
var _ref2;
|
|
1515
1468
|
|
|
1516
|
-
var innerIterator =
|
|
1469
|
+
var innerIterator = this._map.entries();
|
|
1517
1470
|
|
|
1518
1471
|
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
|
|
1519
1472
|
return this;
|
|
@@ -1534,18 +1487,18 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1534
1487
|
}, _ref2;
|
|
1535
1488
|
};
|
|
1536
1489
|
|
|
1537
|
-
_proto[
|
|
1490
|
+
_proto[Symbol.iterator] = function () {
|
|
1538
1491
|
return this.entries();
|
|
1539
1492
|
};
|
|
1540
1493
|
|
|
1541
1494
|
_proto.keys = function keys() {
|
|
1542
|
-
return
|
|
1495
|
+
return this._map.keys();
|
|
1543
1496
|
};
|
|
1544
1497
|
|
|
1545
1498
|
_proto.values = function values() {
|
|
1546
1499
|
var _ref3;
|
|
1547
1500
|
|
|
1548
|
-
var innerIterator =
|
|
1501
|
+
var innerIterator = this._map.values();
|
|
1549
1502
|
|
|
1550
1503
|
return _ref3 = {}, _ref3[Symbol.iterator] = function () {
|
|
1551
1504
|
return this;
|
|
@@ -1575,7 +1528,7 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1575
1528
|
_createClass(LiveMap, [{
|
|
1576
1529
|
key: "size",
|
|
1577
1530
|
get: function get() {
|
|
1578
|
-
return
|
|
1531
|
+
return this._map.size;
|
|
1579
1532
|
}
|
|
1580
1533
|
}]);
|
|
1581
1534
|
|
|
@@ -1590,6 +1543,21 @@ function remove(array, item) {
|
|
|
1590
1543
|
}
|
|
1591
1544
|
}
|
|
1592
1545
|
}
|
|
1546
|
+
function creationOpToLiveStructure(op) {
|
|
1547
|
+
switch (op.type) {
|
|
1548
|
+
case OpType.CreateRegister:
|
|
1549
|
+
return new LiveRegister(op.data);
|
|
1550
|
+
|
|
1551
|
+
case OpType.CreateObject:
|
|
1552
|
+
return new LiveObject(op.data);
|
|
1553
|
+
|
|
1554
|
+
case OpType.CreateMap:
|
|
1555
|
+
return new LiveMap();
|
|
1556
|
+
|
|
1557
|
+
case OpType.CreateList:
|
|
1558
|
+
return new LiveList();
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1593
1561
|
function isSameNodeOrChildOf(node, parent) {
|
|
1594
1562
|
if (node === parent) {
|
|
1595
1563
|
return true;
|
|
@@ -1723,44 +1691,57 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
1723
1691
|
});
|
|
1724
1692
|
return ops;
|
|
1725
1693
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1694
|
+
|
|
1695
|
+
function mergeObjectStorageUpdates(first, second) {
|
|
1696
|
+
var updates = first.updates;
|
|
1697
|
+
|
|
1698
|
+
for (var _iterator = _createForOfIteratorHelperLoose(entries(second.updates)), _step; !(_step = _iterator()).done;) {
|
|
1699
|
+
var _step$value = _step.value,
|
|
1700
|
+
_key = _step$value[0],
|
|
1701
|
+
value = _step$value[1];
|
|
1702
|
+
updates[_key] = value;
|
|
1729
1703
|
}
|
|
1730
1704
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1705
|
+
return _extends({}, second, {
|
|
1706
|
+
updates: updates
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1733
1709
|
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
key = _Object$entries$_i[0],
|
|
1737
|
-
value = _Object$entries$_i[1];
|
|
1738
|
-
updates[key] = value;
|
|
1739
|
-
}
|
|
1710
|
+
function mergeMapStorageUpdates(first, second) {
|
|
1711
|
+
var updates = first.updates;
|
|
1740
1712
|
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1713
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(entries(second.updates)), _step2; !(_step2 = _iterator2()).done;) {
|
|
1714
|
+
var _step2$value = _step2.value,
|
|
1715
|
+
_key2 = _step2$value[0],
|
|
1716
|
+
value = _step2$value[1];
|
|
1717
|
+
updates[_key2] = value;
|
|
1718
|
+
}
|
|
1746
1719
|
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
_updates[_key] = _value;
|
|
1752
|
-
}
|
|
1720
|
+
return _extends({}, second, {
|
|
1721
|
+
updates: updates
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1753
1724
|
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1725
|
+
function mergeListStorageUpdates(first, second) {
|
|
1726
|
+
var updates = first.updates;
|
|
1727
|
+
return _extends({}, second, {
|
|
1728
|
+
updates: updates.concat(second.updates)
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
function mergeStorageUpdates(first, second) {
|
|
1733
|
+
if (!first) {
|
|
1734
|
+
return second;
|
|
1762
1735
|
}
|
|
1763
1736
|
|
|
1737
|
+
if (first.type === "LiveObject" && second.type === "LiveObject") {
|
|
1738
|
+
return mergeObjectStorageUpdates(first, second);
|
|
1739
|
+
} else if (first.type === "LiveMap" && second.type === "LiveMap") {
|
|
1740
|
+
return mergeMapStorageUpdates(first, second);
|
|
1741
|
+
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
1742
|
+
return mergeListStorageUpdates(first, second);
|
|
1743
|
+
} else ;
|
|
1744
|
+
|
|
1764
1745
|
return second;
|
|
1765
1746
|
}
|
|
1766
1747
|
|
|
@@ -1798,11 +1779,11 @@ function findNonSerializableValue(value, path) {
|
|
|
1798
1779
|
return false;
|
|
1799
1780
|
}
|
|
1800
1781
|
|
|
1801
|
-
for (var
|
|
1802
|
-
var _Object$
|
|
1803
|
-
|
|
1804
|
-
nestedValue = _Object$
|
|
1805
|
-
var nestedPath = path ? path + "." +
|
|
1782
|
+
for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
|
|
1783
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
1784
|
+
_key3 = _Object$entries$_i[0],
|
|
1785
|
+
nestedValue = _Object$entries$_i[1];
|
|
1786
|
+
var nestedPath = path ? path + "." + _key3 : _key3;
|
|
1806
1787
|
|
|
1807
1788
|
if (!isPlain(nestedValue)) {
|
|
1808
1789
|
return {
|
|
@@ -1822,14 +1803,34 @@ function findNonSerializableValue(value, path) {
|
|
|
1822
1803
|
|
|
1823
1804
|
return false;
|
|
1824
1805
|
}
|
|
1806
|
+
function isTokenValid(token) {
|
|
1807
|
+
if (token === null) {
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1825
1810
|
|
|
1826
|
-
var
|
|
1811
|
+
var tokenParts = token.split(".");
|
|
1812
|
+
|
|
1813
|
+
if (tokenParts.length !== 3) {
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1827
1816
|
|
|
1828
|
-
var
|
|
1817
|
+
var data = JSON.parse(atob(tokenParts[1]));
|
|
1829
1818
|
|
|
1830
|
-
|
|
1819
|
+
if (typeof data.exp !== "number") {
|
|
1820
|
+
return false;
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
var now = Date.now();
|
|
1824
|
+
|
|
1825
|
+
if (now / 1000 > data.exp - 300) {
|
|
1826
|
+
return false;
|
|
1827
|
+
}
|
|
1831
1828
|
|
|
1832
|
-
|
|
1829
|
+
return true;
|
|
1830
|
+
}
|
|
1831
|
+
function entries(obj) {
|
|
1832
|
+
return Object.entries(obj);
|
|
1833
|
+
}
|
|
1833
1834
|
|
|
1834
1835
|
var LiveObject = function (_AbstractCrdt) {
|
|
1835
1836
|
_inheritsLoose(LiveObject, _AbstractCrdt);
|
|
@@ -1842,20 +1843,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1842
1843
|
}
|
|
1843
1844
|
|
|
1844
1845
|
_this = _AbstractCrdt.call(this) || this;
|
|
1845
|
-
|
|
1846
|
-
_applyDeleteObjectKey.add(_assertThisInitialized(_this));
|
|
1847
|
-
|
|
1848
|
-
_applyUpdate.add(_assertThisInitialized(_this));
|
|
1849
|
-
|
|
1850
|
-
_map.set(_assertThisInitialized(_this), {
|
|
1851
|
-
writable: true,
|
|
1852
|
-
value: void 0
|
|
1853
|
-
});
|
|
1854
|
-
|
|
1855
|
-
_propToLastUpdate.set(_assertThisInitialized(_this), {
|
|
1856
|
-
writable: true,
|
|
1857
|
-
value: new Map()
|
|
1858
|
-
});
|
|
1846
|
+
_this._propToLastUpdate = new Map();
|
|
1859
1847
|
|
|
1860
1848
|
for (var key in object) {
|
|
1861
1849
|
var value = object[key];
|
|
@@ -1865,14 +1853,13 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1865
1853
|
}
|
|
1866
1854
|
}
|
|
1867
1855
|
|
|
1868
|
-
|
|
1869
|
-
|
|
1856
|
+
_this._map = new Map(Object.entries(object));
|
|
1870
1857
|
return _this;
|
|
1871
1858
|
}
|
|
1872
1859
|
|
|
1873
1860
|
var _proto = LiveObject.prototype;
|
|
1874
1861
|
|
|
1875
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc) {
|
|
1862
|
+
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1876
1863
|
if (this._id == null) {
|
|
1877
1864
|
throw new Error("Cannot serialize item is not attached");
|
|
1878
1865
|
}
|
|
@@ -1881,6 +1868,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1881
1868
|
var op = {
|
|
1882
1869
|
id: this._id,
|
|
1883
1870
|
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1871
|
+
intent: intent,
|
|
1884
1872
|
type: OpType.CreateObject,
|
|
1885
1873
|
parentId: parentId,
|
|
1886
1874
|
parentKey: parentKey,
|
|
@@ -1888,7 +1876,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1888
1876
|
};
|
|
1889
1877
|
ops.push(op);
|
|
1890
1878
|
|
|
1891
|
-
for (var _iterator = _createForOfIteratorHelperLoose(
|
|
1879
|
+
for (var _iterator = _createForOfIteratorHelperLoose(this._map), _step; !(_step = _iterator()).done;) {
|
|
1892
1880
|
var _step$value = _step.value,
|
|
1893
1881
|
key = _step$value[0],
|
|
1894
1882
|
value = _step$value[1];
|
|
@@ -1937,7 +1925,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1937
1925
|
|
|
1938
1926
|
child._setParentLink(object, crdt.parentKey);
|
|
1939
1927
|
|
|
1940
|
-
|
|
1928
|
+
object._map.set(crdt.parentKey, child);
|
|
1941
1929
|
}
|
|
1942
1930
|
|
|
1943
1931
|
return object;
|
|
@@ -1946,7 +1934,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1946
1934
|
_proto._attach = function _attach(id, doc) {
|
|
1947
1935
|
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1948
1936
|
|
|
1949
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
1937
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(this._map), _step3; !(_step3 = _iterator3()).done;) {
|
|
1950
1938
|
var _step3$value = _step3.value;
|
|
1951
1939
|
_step3$value[0];
|
|
1952
1940
|
var value = _step3$value[1];
|
|
@@ -1957,16 +1945,22 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1957
1945
|
}
|
|
1958
1946
|
};
|
|
1959
1947
|
|
|
1960
|
-
_proto._attachChild = function _attachChild(
|
|
1948
|
+
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
1961
1949
|
var _updates;
|
|
1962
1950
|
|
|
1963
1951
|
if (this._doc == null) {
|
|
1964
1952
|
throw new Error("Can't attach child if doc is not present");
|
|
1965
1953
|
}
|
|
1966
1954
|
|
|
1955
|
+
var id = op.id,
|
|
1956
|
+
parentKey = op.parentKey,
|
|
1957
|
+
opId = op.opId;
|
|
1958
|
+
var key = parentKey;
|
|
1959
|
+
var child = creationOpToLiveStructure(op);
|
|
1960
|
+
|
|
1967
1961
|
if (this._doc.getItem(id) !== undefined) {
|
|
1968
|
-
if (
|
|
1969
|
-
|
|
1962
|
+
if (this._propToLastUpdate.get(key) === opId) {
|
|
1963
|
+
this._propToLastUpdate.delete(key);
|
|
1970
1964
|
}
|
|
1971
1965
|
|
|
1972
1966
|
return {
|
|
@@ -1975,9 +1969,9 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1975
1969
|
}
|
|
1976
1970
|
|
|
1977
1971
|
if (isLocal) {
|
|
1978
|
-
|
|
1979
|
-
} else if (
|
|
1980
|
-
|
|
1972
|
+
this._propToLastUpdate.set(key, opId);
|
|
1973
|
+
} else if (this._propToLastUpdate.get(key) === undefined) ; else if (this._propToLastUpdate.get(key) === opId) {
|
|
1974
|
+
this._propToLastUpdate.delete(key);
|
|
1981
1975
|
|
|
1982
1976
|
return {
|
|
1983
1977
|
modified: false
|
|
@@ -1988,7 +1982,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
1988
1982
|
};
|
|
1989
1983
|
}
|
|
1990
1984
|
|
|
1991
|
-
var previousValue =
|
|
1985
|
+
var previousValue = this._map.get(key);
|
|
1992
1986
|
|
|
1993
1987
|
var reverse;
|
|
1994
1988
|
|
|
@@ -2012,7 +2006,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2012
2006
|
}];
|
|
2013
2007
|
}
|
|
2014
2008
|
|
|
2015
|
-
|
|
2009
|
+
this._map.set(key, child);
|
|
2016
2010
|
|
|
2017
2011
|
child._setParentLink(this, key);
|
|
2018
2012
|
|
|
@@ -2036,13 +2030,13 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2036
2030
|
|
|
2037
2031
|
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
2038
2032
|
|
|
2039
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(
|
|
2033
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
2040
2034
|
var _step4$value = _step4.value,
|
|
2041
2035
|
key = _step4$value[0],
|
|
2042
2036
|
value = _step4$value[1];
|
|
2043
2037
|
|
|
2044
2038
|
if (value === child) {
|
|
2045
|
-
|
|
2039
|
+
this._map.delete(key);
|
|
2046
2040
|
}
|
|
2047
2041
|
}
|
|
2048
2042
|
|
|
@@ -2067,12 +2061,12 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2067
2061
|
};
|
|
2068
2062
|
|
|
2069
2063
|
_proto._detachChildren = function _detachChildren() {
|
|
2070
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(
|
|
2064
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map), _step5; !(_step5 = _iterator5()).done;) {
|
|
2071
2065
|
var _step5$value = _step5.value,
|
|
2072
2066
|
key = _step5$value[0],
|
|
2073
2067
|
value = _step5$value[1];
|
|
2074
2068
|
|
|
2075
|
-
|
|
2069
|
+
this._map.delete(key);
|
|
2076
2070
|
|
|
2077
2071
|
value._detach();
|
|
2078
2072
|
}
|
|
@@ -2081,7 +2075,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2081
2075
|
_proto._detach = function _detach() {
|
|
2082
2076
|
_AbstractCrdt.prototype._detach.call(this);
|
|
2083
2077
|
|
|
2084
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(
|
|
2078
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map.values()), _step6; !(_step6 = _iterator6()).done;) {
|
|
2085
2079
|
var value = _step6.value;
|
|
2086
2080
|
|
|
2087
2081
|
if (isCrdt(value)) {
|
|
@@ -2092,9 +2086,9 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2092
2086
|
|
|
2093
2087
|
_proto._apply = function _apply(op, isLocal) {
|
|
2094
2088
|
if (op.type === OpType.UpdateObject) {
|
|
2095
|
-
return
|
|
2089
|
+
return this._applyUpdate(op, isLocal);
|
|
2096
2090
|
} else if (op.type === OpType.DeleteObjectKey) {
|
|
2097
|
-
return
|
|
2091
|
+
return this._applyDeleteObjectKey(op);
|
|
2098
2092
|
}
|
|
2099
2093
|
|
|
2100
2094
|
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
@@ -2103,16 +2097,150 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2103
2097
|
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
2104
2098
|
var _this$_parent;
|
|
2105
2099
|
|
|
2100
|
+
var data = {};
|
|
2101
|
+
|
|
2102
|
+
for (var _iterator7 = _createForOfIteratorHelperLoose(this._map), _step7; !(_step7 = _iterator7()).done;) {
|
|
2103
|
+
var _step7$value = _step7.value,
|
|
2104
|
+
key = _step7$value[0],
|
|
2105
|
+
value = _step7$value[1];
|
|
2106
|
+
|
|
2107
|
+
if (value instanceof AbstractCrdt === false) {
|
|
2108
|
+
data[key] = value;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2106
2112
|
return {
|
|
2107
2113
|
type: CrdtType.Object,
|
|
2108
2114
|
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
2109
2115
|
parentKey: this._parentKey,
|
|
2110
|
-
data:
|
|
2116
|
+
data: data
|
|
2117
|
+
};
|
|
2118
|
+
};
|
|
2119
|
+
|
|
2120
|
+
_proto._applyUpdate = function _applyUpdate(op, isLocal) {
|
|
2121
|
+
var isModified = false;
|
|
2122
|
+
var reverse = [];
|
|
2123
|
+
var reverseUpdate = {
|
|
2124
|
+
type: OpType.UpdateObject,
|
|
2125
|
+
id: this._id,
|
|
2126
|
+
data: {}
|
|
2127
|
+
};
|
|
2128
|
+
reverse.push(reverseUpdate);
|
|
2129
|
+
|
|
2130
|
+
for (var key in op.data) {
|
|
2131
|
+
var oldValue = this._map.get(key);
|
|
2132
|
+
|
|
2133
|
+
if (oldValue instanceof AbstractCrdt) {
|
|
2134
|
+
reverse.push.apply(reverse, oldValue._serialize(this._id, key));
|
|
2135
|
+
|
|
2136
|
+
oldValue._detach();
|
|
2137
|
+
} else if (oldValue !== undefined) {
|
|
2138
|
+
reverseUpdate.data[key] = oldValue;
|
|
2139
|
+
} else if (oldValue === undefined) {
|
|
2140
|
+
reverse.push({
|
|
2141
|
+
type: OpType.DeleteObjectKey,
|
|
2142
|
+
id: this._id,
|
|
2143
|
+
key: key
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
var updateDelta = {};
|
|
2149
|
+
|
|
2150
|
+
for (var _key2 in op.data) {
|
|
2151
|
+
if (isLocal) {
|
|
2152
|
+
this._propToLastUpdate.set(_key2, op.opId);
|
|
2153
|
+
} else if (this._propToLastUpdate.get(_key2) == null) {
|
|
2154
|
+
isModified = true;
|
|
2155
|
+
} else if (this._propToLastUpdate.get(_key2) === op.opId) {
|
|
2156
|
+
this._propToLastUpdate.delete(_key2);
|
|
2157
|
+
|
|
2158
|
+
continue;
|
|
2159
|
+
} else {
|
|
2160
|
+
continue;
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
var _oldValue = this._map.get(_key2);
|
|
2164
|
+
|
|
2165
|
+
if (isCrdt(_oldValue)) {
|
|
2166
|
+
_oldValue._detach();
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
isModified = true;
|
|
2170
|
+
updateDelta[_key2] = {
|
|
2171
|
+
type: "update"
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
this._map.set(_key2, op.data[_key2]);
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
2178
|
+
reverse.unshift(reverseUpdate);
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
return isModified ? {
|
|
2182
|
+
modified: {
|
|
2183
|
+
node: this,
|
|
2184
|
+
type: "LiveObject",
|
|
2185
|
+
updates: updateDelta
|
|
2186
|
+
},
|
|
2187
|
+
reverse: reverse
|
|
2188
|
+
} : {
|
|
2189
|
+
modified: false
|
|
2190
|
+
};
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2193
|
+
_proto._applyDeleteObjectKey = function _applyDeleteObjectKey(op) {
|
|
2194
|
+
var _updates3;
|
|
2195
|
+
|
|
2196
|
+
var key = op.key;
|
|
2197
|
+
|
|
2198
|
+
if (this._map.has(key) === false) {
|
|
2199
|
+
return {
|
|
2200
|
+
modified: false
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
if (this._propToLastUpdate.get(key) !== undefined) {
|
|
2205
|
+
return {
|
|
2206
|
+
modified: false
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
var oldValue = this._map.get(key);
|
|
2211
|
+
|
|
2212
|
+
var reverse = [];
|
|
2213
|
+
|
|
2214
|
+
if (isCrdt(oldValue)) {
|
|
2215
|
+
reverse = oldValue._serialize(this._id, op.key);
|
|
2216
|
+
|
|
2217
|
+
oldValue._detach();
|
|
2218
|
+
} else if (oldValue !== undefined) {
|
|
2219
|
+
var _data2;
|
|
2220
|
+
|
|
2221
|
+
reverse = [{
|
|
2222
|
+
type: OpType.UpdateObject,
|
|
2223
|
+
id: this._id,
|
|
2224
|
+
data: (_data2 = {}, _data2[key] = oldValue, _data2)
|
|
2225
|
+
}];
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
this._map.delete(key);
|
|
2229
|
+
|
|
2230
|
+
return {
|
|
2231
|
+
modified: {
|
|
2232
|
+
node: this,
|
|
2233
|
+
type: "LiveObject",
|
|
2234
|
+
updates: (_updates3 = {}, _updates3[op.key] = {
|
|
2235
|
+
type: "delete"
|
|
2236
|
+
}, _updates3)
|
|
2237
|
+
},
|
|
2238
|
+
reverse: reverse
|
|
2111
2239
|
};
|
|
2112
2240
|
};
|
|
2113
2241
|
|
|
2114
2242
|
_proto.toObject = function toObject() {
|
|
2115
|
-
return Object.fromEntries(
|
|
2243
|
+
return Object.fromEntries(this._map);
|
|
2116
2244
|
};
|
|
2117
2245
|
|
|
2118
2246
|
_proto.set = function set(key, value) {
|
|
@@ -2122,15 +2250,15 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2122
2250
|
};
|
|
2123
2251
|
|
|
2124
2252
|
_proto.get = function get(key) {
|
|
2125
|
-
return
|
|
2253
|
+
return this._map.get(key);
|
|
2126
2254
|
};
|
|
2127
2255
|
|
|
2128
2256
|
_proto.delete = function _delete(key) {
|
|
2129
|
-
var
|
|
2257
|
+
var _updates4;
|
|
2130
2258
|
|
|
2131
2259
|
var keyAsString = key;
|
|
2132
2260
|
|
|
2133
|
-
var oldValue =
|
|
2261
|
+
var oldValue = this._map.get(keyAsString);
|
|
2134
2262
|
|
|
2135
2263
|
if (oldValue === undefined) {
|
|
2136
2264
|
return;
|
|
@@ -2141,7 +2269,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2141
2269
|
oldValue._detach();
|
|
2142
2270
|
}
|
|
2143
2271
|
|
|
2144
|
-
|
|
2272
|
+
this._map.delete(keyAsString);
|
|
2145
2273
|
|
|
2146
2274
|
return;
|
|
2147
2275
|
}
|
|
@@ -2153,24 +2281,24 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2153
2281
|
|
|
2154
2282
|
reverse = oldValue._serialize(this._id, keyAsString);
|
|
2155
2283
|
} else {
|
|
2156
|
-
var
|
|
2284
|
+
var _data3;
|
|
2157
2285
|
|
|
2158
2286
|
reverse = [{
|
|
2159
2287
|
type: OpType.UpdateObject,
|
|
2160
|
-
data: (
|
|
2288
|
+
data: (_data3 = {}, _data3[keyAsString] = oldValue, _data3),
|
|
2161
2289
|
id: this._id
|
|
2162
2290
|
}];
|
|
2163
2291
|
}
|
|
2164
2292
|
|
|
2165
|
-
|
|
2293
|
+
this._map.delete(keyAsString);
|
|
2166
2294
|
|
|
2167
2295
|
var storageUpdates = new Map();
|
|
2168
2296
|
storageUpdates.set(this._id, {
|
|
2169
2297
|
node: this,
|
|
2170
2298
|
type: "LiveObject",
|
|
2171
|
-
updates: (
|
|
2299
|
+
updates: (_updates4 = {}, _updates4[key] = {
|
|
2172
2300
|
type: "delete"
|
|
2173
|
-
},
|
|
2301
|
+
}, _updates4)
|
|
2174
2302
|
});
|
|
2175
2303
|
|
|
2176
2304
|
this._doc.dispatch([{
|
|
@@ -2186,7 +2314,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2186
2314
|
|
|
2187
2315
|
if (this._doc == null || this._id == null) {
|
|
2188
2316
|
for (var key in overrides) {
|
|
2189
|
-
var oldValue =
|
|
2317
|
+
var oldValue = this._map.get(key);
|
|
2190
2318
|
|
|
2191
2319
|
if (oldValue instanceof AbstractCrdt) {
|
|
2192
2320
|
oldValue._detach();
|
|
@@ -2198,7 +2326,7 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2198
2326
|
newValue._setParentLink(this, key);
|
|
2199
2327
|
}
|
|
2200
2328
|
|
|
2201
|
-
|
|
2329
|
+
this._map.set(key, newValue);
|
|
2202
2330
|
}
|
|
2203
2331
|
|
|
2204
2332
|
return;
|
|
@@ -2217,50 +2345,50 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2217
2345
|
};
|
|
2218
2346
|
var updateDelta = {};
|
|
2219
2347
|
|
|
2220
|
-
for (var
|
|
2221
|
-
var
|
|
2348
|
+
for (var _key3 in overrides) {
|
|
2349
|
+
var _oldValue2 = this._map.get(_key3);
|
|
2222
2350
|
|
|
2223
|
-
if (
|
|
2224
|
-
reverseOps.push.apply(reverseOps,
|
|
2351
|
+
if (_oldValue2 instanceof AbstractCrdt) {
|
|
2352
|
+
reverseOps.push.apply(reverseOps, _oldValue2._serialize(this._id, _key3));
|
|
2225
2353
|
|
|
2226
|
-
|
|
2227
|
-
} else if (
|
|
2354
|
+
_oldValue2._detach();
|
|
2355
|
+
} else if (_oldValue2 === undefined) {
|
|
2228
2356
|
reverseOps.push({
|
|
2229
2357
|
type: OpType.DeleteObjectKey,
|
|
2230
2358
|
id: this._id,
|
|
2231
|
-
key:
|
|
2359
|
+
key: _key3
|
|
2232
2360
|
});
|
|
2233
2361
|
} else {
|
|
2234
|
-
reverseUpdateOp.data[
|
|
2362
|
+
reverseUpdateOp.data[_key3] = _oldValue2;
|
|
2235
2363
|
}
|
|
2236
2364
|
|
|
2237
|
-
var _newValue = overrides[
|
|
2365
|
+
var _newValue = overrides[_key3];
|
|
2238
2366
|
|
|
2239
2367
|
if (_newValue instanceof AbstractCrdt) {
|
|
2240
|
-
_newValue._setParentLink(this,
|
|
2368
|
+
_newValue._setParentLink(this, _key3);
|
|
2241
2369
|
|
|
2242
2370
|
_newValue._attach(this._doc.generateId(), this._doc);
|
|
2243
2371
|
|
|
2244
|
-
var newAttachChildOps = _newValue._serialize(this._id,
|
|
2372
|
+
var newAttachChildOps = _newValue._serialize(this._id, _key3, this._doc);
|
|
2245
2373
|
|
|
2246
2374
|
var createCrdtOp = newAttachChildOps.find(function (op) {
|
|
2247
2375
|
return op.parentId === _this2._id;
|
|
2248
2376
|
});
|
|
2249
2377
|
|
|
2250
2378
|
if (createCrdtOp) {
|
|
2251
|
-
|
|
2379
|
+
this._propToLastUpdate.set(_key3, createCrdtOp.opId);
|
|
2252
2380
|
}
|
|
2253
2381
|
|
|
2254
2382
|
ops.push.apply(ops, newAttachChildOps);
|
|
2255
2383
|
} else {
|
|
2256
|
-
updatedProps[
|
|
2384
|
+
updatedProps[_key3] = _newValue;
|
|
2257
2385
|
|
|
2258
|
-
|
|
2386
|
+
this._propToLastUpdate.set(_key3, opId);
|
|
2259
2387
|
}
|
|
2260
2388
|
|
|
2261
|
-
|
|
2389
|
+
this._map.set(_key3, _newValue);
|
|
2262
2390
|
|
|
2263
|
-
updateDelta[
|
|
2391
|
+
updateDelta[_key3] = {
|
|
2264
2392
|
type: "update"
|
|
2265
2393
|
};
|
|
2266
2394
|
}
|
|
@@ -2291,128 +2419,6 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2291
2419
|
return LiveObject;
|
|
2292
2420
|
}(AbstractCrdt);
|
|
2293
2421
|
|
|
2294
|
-
function _applyUpdate2(op, isLocal) {
|
|
2295
|
-
var isModified = false;
|
|
2296
|
-
var reverse = [];
|
|
2297
|
-
var reverseUpdate = {
|
|
2298
|
-
type: OpType.UpdateObject,
|
|
2299
|
-
id: this._id,
|
|
2300
|
-
data: {}
|
|
2301
|
-
};
|
|
2302
|
-
reverse.push(reverseUpdate);
|
|
2303
|
-
|
|
2304
|
-
for (var key in op.data) {
|
|
2305
|
-
var oldValue = _classPrivateFieldGet(this, _map).get(key);
|
|
2306
|
-
|
|
2307
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2308
|
-
reverse.push.apply(reverse, oldValue._serialize(this._id, key));
|
|
2309
|
-
|
|
2310
|
-
oldValue._detach();
|
|
2311
|
-
} else if (oldValue !== undefined) {
|
|
2312
|
-
reverseUpdate.data[key] = oldValue;
|
|
2313
|
-
} else if (oldValue === undefined) {
|
|
2314
|
-
reverse.push({
|
|
2315
|
-
type: OpType.DeleteObjectKey,
|
|
2316
|
-
id: this._id,
|
|
2317
|
-
key: key
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
var updateDelta = {};
|
|
2323
|
-
|
|
2324
|
-
for (var _key2 in op.data) {
|
|
2325
|
-
if (isLocal) {
|
|
2326
|
-
_classPrivateFieldGet(this, _propToLastUpdate).set(_key2, op.opId);
|
|
2327
|
-
} else if (_classPrivateFieldGet(this, _propToLastUpdate).get(_key2) == null) {
|
|
2328
|
-
isModified = true;
|
|
2329
|
-
} else if (_classPrivateFieldGet(this, _propToLastUpdate).get(_key2) === op.opId) {
|
|
2330
|
-
_classPrivateFieldGet(this, _propToLastUpdate).delete(_key2);
|
|
2331
|
-
|
|
2332
|
-
continue;
|
|
2333
|
-
} else {
|
|
2334
|
-
continue;
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
var _oldValue2 = _classPrivateFieldGet(this, _map).get(_key2);
|
|
2338
|
-
|
|
2339
|
-
if (isCrdt(_oldValue2)) {
|
|
2340
|
-
_oldValue2._detach();
|
|
2341
|
-
}
|
|
2342
|
-
|
|
2343
|
-
isModified = true;
|
|
2344
|
-
updateDelta[_key2] = {
|
|
2345
|
-
type: "update"
|
|
2346
|
-
};
|
|
2347
|
-
|
|
2348
|
-
_classPrivateFieldGet(this, _map).set(_key2, op.data[_key2]);
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
2352
|
-
reverse.unshift(reverseUpdate);
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
return isModified ? {
|
|
2356
|
-
modified: {
|
|
2357
|
-
node: this,
|
|
2358
|
-
type: "LiveObject",
|
|
2359
|
-
updates: updateDelta
|
|
2360
|
-
},
|
|
2361
|
-
reverse: reverse
|
|
2362
|
-
} : {
|
|
2363
|
-
modified: false
|
|
2364
|
-
};
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
function _applyDeleteObjectKey2(op) {
|
|
2368
|
-
var _updates4;
|
|
2369
|
-
|
|
2370
|
-
var key = op.key;
|
|
2371
|
-
|
|
2372
|
-
if (_classPrivateFieldGet(this, _map).has(key) === false) {
|
|
2373
|
-
return {
|
|
2374
|
-
modified: false
|
|
2375
|
-
};
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
if (_classPrivateFieldGet(this, _propToLastUpdate).get(key) !== undefined) {
|
|
2379
|
-
return {
|
|
2380
|
-
modified: false
|
|
2381
|
-
};
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
var oldValue = _classPrivateFieldGet(this, _map).get(key);
|
|
2385
|
-
|
|
2386
|
-
var reverse = [];
|
|
2387
|
-
|
|
2388
|
-
if (isCrdt(oldValue)) {
|
|
2389
|
-
reverse = oldValue._serialize(this._id, op.key);
|
|
2390
|
-
|
|
2391
|
-
oldValue._detach();
|
|
2392
|
-
} else if (oldValue !== undefined) {
|
|
2393
|
-
var _data3;
|
|
2394
|
-
|
|
2395
|
-
reverse = [{
|
|
2396
|
-
type: OpType.UpdateObject,
|
|
2397
|
-
id: this._id,
|
|
2398
|
-
data: (_data3 = {}, _data3[key] = oldValue, _data3)
|
|
2399
|
-
}];
|
|
2400
|
-
}
|
|
2401
|
-
|
|
2402
|
-
_classPrivateFieldGet(this, _map).delete(key);
|
|
2403
|
-
|
|
2404
|
-
return {
|
|
2405
|
-
modified: {
|
|
2406
|
-
node: this,
|
|
2407
|
-
type: "LiveObject",
|
|
2408
|
-
updates: (_updates4 = {}, _updates4[op.key] = {
|
|
2409
|
-
type: "delete"
|
|
2410
|
-
}, _updates4)
|
|
2411
|
-
},
|
|
2412
|
-
reverse: reverse
|
|
2413
|
-
};
|
|
2414
|
-
}
|
|
2415
|
-
|
|
2416
2422
|
var BACKOFF_RETRY_DELAYS = [250, 500, 1000, 2000, 4000, 8000, 10000];
|
|
2417
2423
|
var BACKOFF_RETRY_DELAYS_SLOW = [2000, 30000, 60000, 300000];
|
|
2418
2424
|
var HEARTBEAT_INTERVAL = 30000;
|
|
@@ -2429,45 +2435,52 @@ function makeIdFactory(connectionId) {
|
|
|
2429
2435
|
};
|
|
2430
2436
|
}
|
|
2431
2437
|
|
|
2432
|
-
function makeOthers(
|
|
2438
|
+
function makeOthers(userMap) {
|
|
2433
2439
|
var _ref;
|
|
2434
2440
|
|
|
2435
|
-
var
|
|
2436
|
-
|
|
2437
|
-
var publicKeys = _objectWithoutPropertiesLoose(
|
|
2441
|
+
var users = Object.values(userMap).map(function (user) {
|
|
2442
|
+
user._hasReceivedInitialPresence;
|
|
2443
|
+
var publicKeys = _objectWithoutPropertiesLoose(user, ["_hasReceivedInitialPresence"]);
|
|
2438
2444
|
|
|
2439
2445
|
return publicKeys;
|
|
2440
2446
|
});
|
|
2441
2447
|
return _ref = {
|
|
2442
2448
|
get count() {
|
|
2443
|
-
return
|
|
2449
|
+
return users.length;
|
|
2444
2450
|
}
|
|
2445
2451
|
|
|
2446
2452
|
}, _ref[Symbol.iterator] = function () {
|
|
2447
|
-
return
|
|
2453
|
+
return users[Symbol.iterator]();
|
|
2448
2454
|
}, _ref.map = function map(callback) {
|
|
2449
|
-
return
|
|
2455
|
+
return users.map(callback);
|
|
2450
2456
|
}, _ref.toArray = function toArray() {
|
|
2451
|
-
return
|
|
2457
|
+
return users;
|
|
2452
2458
|
}, _ref;
|
|
2453
2459
|
}
|
|
2454
2460
|
|
|
2455
2461
|
function makeStateMachine(state, context, mockedEffects) {
|
|
2456
2462
|
var effects = mockedEffects || {
|
|
2457
2463
|
authenticate: function authenticate(auth, createWebSocket) {
|
|
2458
|
-
|
|
2459
|
-
var
|
|
2464
|
+
if (isTokenValid(state.token)) {
|
|
2465
|
+
var parsedToken = parseToken(state.token);
|
|
2466
|
+
var socket = createWebSocket(state.token);
|
|
2467
|
+
authenticationSuccess(parsedToken, socket);
|
|
2468
|
+
} else {
|
|
2469
|
+
return auth(context.room).then(function (_ref2) {
|
|
2470
|
+
var token = _ref2.token;
|
|
2460
2471
|
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2472
|
+
if (state.connection.state !== "authenticating") {
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2464
2475
|
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2476
|
+
var parsedToken = parseToken(token);
|
|
2477
|
+
var socket = createWebSocket(token);
|
|
2478
|
+
authenticationSuccess(parsedToken, socket);
|
|
2479
|
+
state.token = token;
|
|
2480
|
+
}).catch(function (er) {
|
|
2481
|
+
return authenticationFailure(er);
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2471
2484
|
},
|
|
2472
2485
|
send: function send(messageOrMessages) {
|
|
2473
2486
|
if (state.socket == null) {
|
|
@@ -2530,9 +2543,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2530
2543
|
state.root = load(message.items);
|
|
2531
2544
|
}
|
|
2532
2545
|
|
|
2533
|
-
for (var
|
|
2534
|
-
if (state.root.get(
|
|
2535
|
-
state.root.set(
|
|
2546
|
+
for (var _key in state.defaultStorageRoot) {
|
|
2547
|
+
if (state.root.get(_key) == null) {
|
|
2548
|
+
state.root.set(_key, state.defaultStorageRoot[_key]);
|
|
2536
2549
|
}
|
|
2537
2550
|
}
|
|
2538
2551
|
}
|
|
@@ -2648,15 +2661,15 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2648
2661
|
_ref3$presence = _ref3.presence,
|
|
2649
2662
|
presence = _ref3$presence === void 0 ? false : _ref3$presence,
|
|
2650
2663
|
_ref3$others = _ref3.others,
|
|
2651
|
-
|
|
2664
|
+
otherEvents = _ref3$others === void 0 ? [] : _ref3$others;
|
|
2652
2665
|
|
|
2653
|
-
if (
|
|
2666
|
+
if (otherEvents.length > 0) {
|
|
2654
2667
|
state.others = makeOthers(state.users);
|
|
2655
2668
|
|
|
2656
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
2669
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(otherEvents), _step3; !(_step3 = _iterator3()).done;) {
|
|
2657
2670
|
var event = _step3.value;
|
|
2658
2671
|
|
|
2659
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(state.listeners
|
|
2672
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(state.listeners.others), _step4; !(_step4 = _iterator4()).done;) {
|
|
2660
2673
|
var _listener = _step4.value;
|
|
2661
2674
|
|
|
2662
2675
|
_listener(state.others, event);
|
|
@@ -2716,8 +2729,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2716
2729
|
data: {}
|
|
2717
2730
|
};
|
|
2718
2731
|
|
|
2719
|
-
for (var
|
|
2720
|
-
reverse.data[
|
|
2732
|
+
for (var _key2 in op.data) {
|
|
2733
|
+
reverse.data[_key2] = state.me[_key2];
|
|
2721
2734
|
}
|
|
2722
2735
|
|
|
2723
2736
|
state.me = _extends({}, state.me, op.data);
|
|
@@ -2725,8 +2738,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2725
2738
|
if (state.buffer.presence == null) {
|
|
2726
2739
|
state.buffer.presence = op.data;
|
|
2727
2740
|
} else {
|
|
2728
|
-
for (var
|
|
2729
|
-
state.buffer.presence[
|
|
2741
|
+
for (var _key3 in op.data) {
|
|
2742
|
+
state.buffer.presence[_key3] = op.data;
|
|
2730
2743
|
}
|
|
2731
2744
|
}
|
|
2732
2745
|
|
|
@@ -2801,55 +2814,19 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2801
2814
|
}
|
|
2802
2815
|
|
|
2803
2816
|
case OpType.CreateObject:
|
|
2804
|
-
{
|
|
2805
|
-
var parent = state.items.get(op.parentId);
|
|
2806
|
-
|
|
2807
|
-
if (parent == null) {
|
|
2808
|
-
return {
|
|
2809
|
-
modified: false
|
|
2810
|
-
};
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
return parent._attachChild(op.id, op.parentKey, new LiveObject(op.data), op.opId, isLocal);
|
|
2814
|
-
}
|
|
2815
|
-
|
|
2816
2817
|
case OpType.CreateList:
|
|
2817
|
-
{
|
|
2818
|
-
var _parent = state.items.get(op.parentId);
|
|
2819
|
-
|
|
2820
|
-
if (_parent == null) {
|
|
2821
|
-
return {
|
|
2822
|
-
modified: false
|
|
2823
|
-
};
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
|
-
return _parent._attachChild(op.id, op.parentKey, new LiveList(), op.opId, isLocal);
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
|
-
case OpType.CreateRegister:
|
|
2830
|
-
{
|
|
2831
|
-
var _parent2 = state.items.get(op.parentId);
|
|
2832
|
-
|
|
2833
|
-
if (_parent2 == null) {
|
|
2834
|
-
return {
|
|
2835
|
-
modified: false
|
|
2836
|
-
};
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
return _parent2._attachChild(op.id, op.parentKey, new LiveRegister(op.data), op.opId, isLocal);
|
|
2840
|
-
}
|
|
2841
|
-
|
|
2842
2818
|
case OpType.CreateMap:
|
|
2819
|
+
case OpType.CreateRegister:
|
|
2843
2820
|
{
|
|
2844
|
-
var
|
|
2821
|
+
var parent = state.items.get(op.parentId);
|
|
2845
2822
|
|
|
2846
|
-
if (
|
|
2823
|
+
if (parent == null) {
|
|
2847
2824
|
return {
|
|
2848
2825
|
modified: false
|
|
2849
2826
|
};
|
|
2850
2827
|
}
|
|
2851
2828
|
|
|
2852
|
-
return
|
|
2829
|
+
return parent._attachChild(op, isLocal);
|
|
2853
2830
|
}
|
|
2854
2831
|
}
|
|
2855
2832
|
|
|
@@ -2918,9 +2895,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2918
2895
|
state.buffer.presence = {};
|
|
2919
2896
|
}
|
|
2920
2897
|
|
|
2921
|
-
for (var
|
|
2922
|
-
state.buffer.presence[
|
|
2923
|
-
oldValues[
|
|
2898
|
+
for (var _key4 in overrides) {
|
|
2899
|
+
state.buffer.presence[_key4] = overrides[_key4];
|
|
2900
|
+
oldValues[_key4] = state.me[_key4];
|
|
2924
2901
|
}
|
|
2925
2902
|
|
|
2926
2903
|
state.me = _extends({}, state.me, overrides);
|
|
@@ -2970,6 +2947,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2970
2947
|
console.error("Call to authentication endpoint failed", error);
|
|
2971
2948
|
}
|
|
2972
2949
|
|
|
2950
|
+
state.token = null;
|
|
2973
2951
|
updateConnection({
|
|
2974
2952
|
state: "unavailable"
|
|
2975
2953
|
});
|
|
@@ -3031,10 +3009,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3031
3009
|
function onRoomStateMessage(message) {
|
|
3032
3010
|
var newUsers = {};
|
|
3033
3011
|
|
|
3034
|
-
for (var
|
|
3035
|
-
var _connectionId = Number.parseInt(
|
|
3012
|
+
for (var _key5 in message.users) {
|
|
3013
|
+
var _connectionId = Number.parseInt(_key5);
|
|
3036
3014
|
|
|
3037
|
-
var user = message.users[
|
|
3015
|
+
var user = message.users[_key5];
|
|
3038
3016
|
newUsers[_connectionId] = {
|
|
3039
3017
|
connectionId: _connectionId,
|
|
3040
3018
|
info: user.info,
|
|
@@ -3154,8 +3132,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3154
3132
|
|
|
3155
3133
|
case ServerMessageType.InitialStorageState:
|
|
3156
3134
|
{
|
|
3135
|
+
var offlineOps = new Map(state.offlineOperations);
|
|
3157
3136
|
createOrUpdateRootFromMessage(subMessage);
|
|
3158
|
-
applyAndSendOfflineOps();
|
|
3137
|
+
applyAndSendOfflineOps(offlineOps);
|
|
3159
3138
|
_getInitialStateResolver == null ? void 0 : _getInitialStateResolver();
|
|
3160
3139
|
break;
|
|
3161
3140
|
}
|
|
@@ -3327,13 +3306,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3327
3306
|
connect();
|
|
3328
3307
|
}
|
|
3329
3308
|
|
|
3330
|
-
function applyAndSendOfflineOps() {
|
|
3331
|
-
if (
|
|
3309
|
+
function applyAndSendOfflineOps(offlineOps) {
|
|
3310
|
+
if (offlineOps.size === 0) {
|
|
3332
3311
|
return;
|
|
3333
3312
|
}
|
|
3334
3313
|
|
|
3335
3314
|
var messages = [];
|
|
3336
|
-
var ops = Array.from(
|
|
3315
|
+
var ops = Array.from(offlineOps.values());
|
|
3337
3316
|
var result = apply(ops, true);
|
|
3338
3317
|
messages.push({
|
|
3339
3318
|
type: ClientMessageType.UpdateStorage,
|
|
@@ -3439,8 +3418,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3439
3418
|
}
|
|
3440
3419
|
|
|
3441
3420
|
function clearListeners() {
|
|
3442
|
-
for (var
|
|
3443
|
-
state.listeners[
|
|
3421
|
+
for (var _key6 in state.listeners) {
|
|
3422
|
+
state.listeners[_key6] = [];
|
|
3444
3423
|
}
|
|
3445
3424
|
}
|
|
3446
3425
|
|
|
@@ -3666,6 +3645,7 @@ function defaultState(me, defaultStorageRoot) {
|
|
|
3666
3645
|
connection: {
|
|
3667
3646
|
state: "closed"
|
|
3668
3647
|
},
|
|
3648
|
+
token: null,
|
|
3669
3649
|
lastConnectionId: null,
|
|
3670
3650
|
socket: null,
|
|
3671
3651
|
listeners: {
|
|
@@ -3971,33 +3951,42 @@ function prepareAuthentication(clientOptions) {
|
|
|
3971
3951
|
throw new Error("Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");
|
|
3972
3952
|
}
|
|
3973
3953
|
|
|
3974
|
-
function
|
|
3954
|
+
function lsonObjectToJson(obj) {
|
|
3975
3955
|
var result = {};
|
|
3976
|
-
var obj = liveObject.toObject();
|
|
3977
3956
|
|
|
3978
3957
|
for (var _key in obj) {
|
|
3979
|
-
result[_key] =
|
|
3958
|
+
result[_key] = lsonToJson(obj[_key]);
|
|
3980
3959
|
}
|
|
3981
3960
|
|
|
3982
3961
|
return result;
|
|
3983
3962
|
}
|
|
3984
3963
|
|
|
3964
|
+
function liveObjectToJson(liveObject) {
|
|
3965
|
+
return lsonObjectToJson(liveObject.toObject());
|
|
3966
|
+
}
|
|
3967
|
+
|
|
3985
3968
|
function liveMapToJson(map) {
|
|
3986
3969
|
var result = {};
|
|
3987
|
-
var obj = Object.fromEntries(map);
|
|
3988
3970
|
|
|
3989
|
-
for (var
|
|
3990
|
-
|
|
3971
|
+
for (var _iterator = _createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
3972
|
+
var _step$value = _step.value,
|
|
3973
|
+
_key2 = _step$value[0],
|
|
3974
|
+
value = _step$value[1];
|
|
3975
|
+
result[_key2] = lsonToJson(value);
|
|
3991
3976
|
}
|
|
3992
3977
|
|
|
3993
3978
|
return result;
|
|
3994
3979
|
}
|
|
3995
3980
|
|
|
3981
|
+
function lsonListToJson(value) {
|
|
3982
|
+
return value.map(lsonToJson);
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3996
3985
|
function liveListToJson(value) {
|
|
3997
|
-
return value.toArray()
|
|
3986
|
+
return lsonListToJson(value.toArray());
|
|
3998
3987
|
}
|
|
3999
3988
|
|
|
4000
|
-
function
|
|
3989
|
+
function lsonToJson(value) {
|
|
4001
3990
|
if (value instanceof LiveObject) {
|
|
4002
3991
|
return liveObjectToJson(value);
|
|
4003
3992
|
} else if (value instanceof LiveList) {
|
|
@@ -4006,13 +3995,21 @@ function liveNodeToJson(value) {
|
|
|
4006
3995
|
return liveMapToJson(value);
|
|
4007
3996
|
} else if (value instanceof LiveRegister) {
|
|
4008
3997
|
return value.data;
|
|
3998
|
+
} else if (value instanceof AbstractCrdt) {
|
|
3999
|
+
throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
if (Array.isArray(value)) {
|
|
4003
|
+
return lsonListToJson(value);
|
|
4004
|
+
} else if (isPlainObject(value)) {
|
|
4005
|
+
return lsonObjectToJson(value);
|
|
4009
4006
|
}
|
|
4010
4007
|
|
|
4011
4008
|
return value;
|
|
4012
4009
|
}
|
|
4013
4010
|
|
|
4014
4011
|
function isPlainObject(obj) {
|
|
4015
|
-
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
4012
|
+
return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
|
|
4016
4013
|
}
|
|
4017
4014
|
|
|
4018
4015
|
function anyToCrdt(obj) {
|
|
@@ -4095,8 +4092,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4095
4092
|
if (liveListNode instanceof LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
4096
4093
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
4097
4094
|
} else {
|
|
4098
|
-
liveList.
|
|
4099
|
-
liveList.insert(anyToCrdt(nextNode), i);
|
|
4095
|
+
liveList.set(i, anyToCrdt(nextNode));
|
|
4100
4096
|
}
|
|
4101
4097
|
|
|
4102
4098
|
i++;
|
|
@@ -4107,9 +4103,11 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4107
4103
|
i++;
|
|
4108
4104
|
}
|
|
4109
4105
|
|
|
4110
|
-
|
|
4106
|
+
var _localI = i;
|
|
4107
|
+
|
|
4108
|
+
while (_localI <= prevEnd) {
|
|
4111
4109
|
liveList.delete(i);
|
|
4112
|
-
|
|
4110
|
+
_localI++;
|
|
4113
4111
|
}
|
|
4114
4112
|
}
|
|
4115
4113
|
}
|
|
@@ -4201,7 +4199,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4201
4199
|
var _update$updates$_key, _update$updates$_key2;
|
|
4202
4200
|
|
|
4203
4201
|
if (((_update$updates$_key = update.updates[_key6]) == null ? void 0 : _update$updates$_key.type) === "update") {
|
|
4204
|
-
newState[_key6] =
|
|
4202
|
+
newState[_key6] = lsonToJson(update.node.get(_key6));
|
|
4205
4203
|
} else if (((_update$updates$_key2 = update.updates[_key6]) == null ? void 0 : _update$updates$_key2.type) === "delete") {
|
|
4206
4204
|
delete newState[_key6];
|
|
4207
4205
|
}
|
|
@@ -4220,24 +4218,32 @@ function patchImmutableNode(state, path, update) {
|
|
|
4220
4218
|
return x;
|
|
4221
4219
|
});
|
|
4222
4220
|
|
|
4223
|
-
|
|
4224
|
-
var listUpdate =
|
|
4221
|
+
var _loop = function _loop() {
|
|
4222
|
+
var listUpdate = _step2.value;
|
|
4225
4223
|
|
|
4226
|
-
if (listUpdate.type === "
|
|
4224
|
+
if (listUpdate.type === "set") {
|
|
4225
|
+
_newState = _newState.map(function (item, index) {
|
|
4226
|
+
return index === listUpdate.index ? listUpdate.item : item;
|
|
4227
|
+
});
|
|
4228
|
+
} else if (listUpdate.type === "insert") {
|
|
4227
4229
|
if (listUpdate.index === _newState.length) {
|
|
4228
|
-
_newState.push(
|
|
4230
|
+
_newState.push(lsonToJson(listUpdate.item));
|
|
4229
4231
|
} else {
|
|
4230
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4232
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index));
|
|
4231
4233
|
}
|
|
4232
4234
|
} else if (listUpdate.type === "delete") {
|
|
4233
4235
|
_newState.splice(listUpdate.index, 1);
|
|
4234
4236
|
} else if (listUpdate.type === "move") {
|
|
4235
4237
|
if (listUpdate.previousIndex > listUpdate.index) {
|
|
4236
|
-
_newState = [].concat(_newState.slice(0, listUpdate.index), [
|
|
4238
|
+
_newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1));
|
|
4237
4239
|
} else {
|
|
4238
|
-
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [
|
|
4240
|
+
_newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index + 1));
|
|
4239
4241
|
}
|
|
4240
4242
|
}
|
|
4243
|
+
};
|
|
4244
|
+
|
|
4245
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
4246
|
+
_loop();
|
|
4241
4247
|
}
|
|
4242
4248
|
|
|
4243
4249
|
return _newState;
|
|
@@ -4255,7 +4261,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4255
4261
|
var _update$updates$_key3, _update$updates$_key4;
|
|
4256
4262
|
|
|
4257
4263
|
if (((_update$updates$_key3 = update.updates[_key7]) == null ? void 0 : _update$updates$_key3.type) === "update") {
|
|
4258
|
-
_newState2[_key7] =
|
|
4264
|
+
_newState2[_key7] = lsonToJson(update.node.get(_key7));
|
|
4259
4265
|
} else if (((_update$updates$_key4 = update.updates[_key7]) == null ? void 0 : _update$updates$_key4.type) === "delete") {
|
|
4260
4266
|
delete _newState2[_key7];
|
|
4261
4267
|
}
|
|
@@ -4279,7 +4285,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4279
4285
|
|
|
4280
4286
|
var internals = {
|
|
4281
4287
|
liveObjectToJson: liveObjectToJson,
|
|
4282
|
-
|
|
4288
|
+
lsonToJson: lsonToJson,
|
|
4283
4289
|
patchLiveList: patchLiveList,
|
|
4284
4290
|
patchImmutableObject: patchImmutableObject,
|
|
4285
4291
|
patchLiveObject: patchLiveObject,
|