@liveblocks/client 0.15.9 → 0.15.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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, isLocal) {
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 (_classPrivateFieldGet(this, _parent) != null && _classPrivateFieldGet(this, _parent) !== parent) {
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
- _classPrivateFieldSet(this, _parentKey, key);
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 (_classPrivateFieldGet(this, _id) || _classPrivateFieldGet(this, _doc)) {
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
- _classPrivateFieldSet(this, _id, id);
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 (_classPrivateFieldGet(this, _doc) && _classPrivateFieldGet(this, _id)) {
370
- _classPrivateFieldGet(this, _doc).deleteItem(_classPrivateFieldGet(this, _id));
296
+ if (this.__doc && this.__id) {
297
+ this.__doc.deleteItem(this.__id);
371
298
  }
372
299
 
373
- _classPrivateFieldSet(this, _parent, undefined);
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 _classPrivateFieldGet(this, _doc);
307
+ return this.__doc;
382
308
  }
383
309
  }, {
384
310
  key: "roomId",
385
311
  get: function get() {
386
- return _classPrivateFieldGet(this, _doc) ? _classPrivateFieldGet(this, _doc).roomId : null;
312
+ return this.__doc ? this.__doc.roomId : null;
387
313
  }
388
314
  }, {
389
315
  key: "_id",
390
316
  get: function get() {
391
- return _classPrivateFieldGet(this, _id);
317
+ return this.__id;
392
318
  }
393
319
  }, {
394
320
  key: "_parent",
395
321
  get: function get() {
396
- return _classPrivateFieldGet(this, _parent);
322
+ return this.__parent;
397
323
  }
398
324
  }, {
399
325
  key: "_parentKey",
400
326
  get: function get() {
401
- return _classPrivateFieldGet(this, _parentKey);
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,14 +465,7 @@ 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
 
@@ -595,11 +512,11 @@ var LiveRegister = function (_AbstractCrdt) {
595
512
  };
596
513
  };
597
514
 
598
- _proto._attachChild = function _attachChild(id, key, crdt, opId, isLocal) {
515
+ _proto._attachChild = function _attachChild(_id, _key, _crdt, _opId, _isLocal) {
599
516
  throw new Error("Method not implemented.");
600
517
  };
601
518
 
602
- _proto._detachChild = function _detachChild(crdt) {
519
+ _proto._detachChild = function _detachChild(_crdt) {
603
520
  throw new Error("Method not implemented.");
604
521
  };
605
522
 
@@ -610,18 +527,13 @@ var LiveRegister = function (_AbstractCrdt) {
610
527
  _createClass(LiveRegister, [{
611
528
  key: "data",
612
529
  get: function get() {
613
- return _classPrivateFieldGet(this, _data);
530
+ return this._data;
614
531
  }
615
532
  }]);
616
533
 
617
534
  return LiveRegister;
618
535
  }(AbstractCrdt);
619
536
 
620
- var _Symbol$iterator$1, _Symbol$iterator2;
621
-
622
- var _items = new WeakMap();
623
-
624
- _Symbol$iterator$1 = Symbol.iterator;
625
537
  var LiveList = function (_AbstractCrdt) {
626
538
  _inheritsLoose(LiveList, _AbstractCrdt);
627
539
 
@@ -633,12 +545,7 @@ var LiveList = function (_AbstractCrdt) {
633
545
  }
634
546
 
635
547
  _this = _AbstractCrdt.call(this) || this;
636
-
637
- _items.set(_assertThisInitialized(_this), {
638
- writable: true,
639
- value: []
640
- });
641
-
548
+ _this._items = [];
642
549
  var position = undefined;
643
550
 
644
551
  for (var i = 0; i < items.length; i++) {
@@ -646,7 +553,7 @@ var LiveList = function (_AbstractCrdt) {
646
553
 
647
554
  var _item = selfOrRegister(items[i]);
648
555
 
649
- _classPrivateFieldGet(_assertThisInitialized(_this), _items).push([_item, newPosition]);
556
+ _this._items.push([_item, newPosition]);
650
557
 
651
558
  position = newPosition;
652
559
  }
@@ -656,7 +563,6 @@ var LiveList = function (_AbstractCrdt) {
656
563
 
657
564
  LiveList._deserialize = function _deserialize(_ref, parentToChildren, doc) {
658
565
  var id = _ref[0];
659
- _ref[1];
660
566
  var list = new LiveList([]);
661
567
 
662
568
  list._attach(id, doc);
@@ -673,9 +579,9 @@ var LiveList = function (_AbstractCrdt) {
673
579
 
674
580
  child._setParentLink(list, entry[1].parentKey);
675
581
 
676
- _classPrivateFieldGet(list, _items).push([child, entry[1].parentKey]);
582
+ list._items.push([child, entry[1].parentKey]);
677
583
 
678
- _classPrivateFieldGet(list, _items).sort(function (itemA, itemB) {
584
+ list._items.sort(function (itemA, itemB) {
679
585
  return compare(itemA[1], itemB[1]);
680
586
  });
681
587
  }
@@ -704,7 +610,7 @@ var LiveList = function (_AbstractCrdt) {
704
610
  };
705
611
  ops.push(op);
706
612
 
707
- for (var _iterator2 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _items)), _step2; !(_step2 = _iterator2()).done;) {
613
+ for (var _iterator2 = _createForOfIteratorHelperLoose(this._items), _step2; !(_step2 = _iterator2()).done;) {
708
614
  var _step2$value = _step2.value,
709
615
  _value = _step2$value[0],
710
616
  key = _step2$value[1];
@@ -715,7 +621,7 @@ var LiveList = function (_AbstractCrdt) {
715
621
  };
716
622
 
717
623
  _proto._indexOfPosition = function _indexOfPosition(position) {
718
- return _classPrivateFieldGet(this, _items).findIndex(function (item) {
624
+ return this._items.findIndex(function (item) {
719
625
  return item[1] === position;
720
626
  });
721
627
  };
@@ -723,10 +629,9 @@ var LiveList = function (_AbstractCrdt) {
723
629
  _proto._attach = function _attach(id, doc) {
724
630
  _AbstractCrdt.prototype._attach.call(this, id, doc);
725
631
 
726
- for (var _iterator3 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _items)), _step3; !(_step3 = _iterator3()).done;) {
632
+ for (var _iterator3 = _createForOfIteratorHelperLoose(this._items), _step3; !(_step3 = _iterator3()).done;) {
727
633
  var _step3$value = _step3.value,
728
634
  _item2 = _step3$value[0];
729
- _step3$value[1];
730
635
 
731
636
  _item2._attach(doc.generateId(), doc);
732
637
  }
@@ -735,7 +640,7 @@ var LiveList = function (_AbstractCrdt) {
735
640
  _proto._detach = function _detach() {
736
641
  _AbstractCrdt.prototype._detach.call(this);
737
642
 
738
- for (var _iterator4 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _items)), _step4; !(_step4 = _iterator4()).done;) {
643
+ for (var _iterator4 = _createForOfIteratorHelperLoose(this._items), _step4; !(_step4 = _iterator4()).done;) {
739
644
  var _step4$value = _step4.value,
740
645
  _value2 = _step4$value[0];
741
646
 
@@ -743,7 +648,7 @@ var LiveList = function (_AbstractCrdt) {
743
648
  }
744
649
  };
745
650
 
746
- _proto._attachChild = function _attachChild(id, key, child, opId, isLocal) {
651
+ _proto._attachChild = function _attachChild(id, key, child, _opId, isLocal) {
747
652
  if (this._doc == null) {
748
653
  throw new Error("Can't attach child if doc is not present");
749
654
  }
@@ -758,7 +663,7 @@ var LiveList = function (_AbstractCrdt) {
758
663
 
759
664
  child._setParentLink(this, key);
760
665
 
761
- var index = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
666
+ var index = this._items.findIndex(function (entry) {
762
667
  return entry[1] === key;
763
668
  });
764
669
 
@@ -766,25 +671,25 @@ var LiveList = function (_AbstractCrdt) {
766
671
 
767
672
  if (index !== -1) {
768
673
  if (isLocal) {
769
- var before = _classPrivateFieldGet(this, _items)[index] ? _classPrivateFieldGet(this, _items)[index][1] : undefined;
770
- var after = _classPrivateFieldGet(this, _items)[index + 1] ? _classPrivateFieldGet(this, _items)[index + 1][1] : undefined;
674
+ var before = this._items[index] ? this._items[index][1] : undefined;
675
+ var after = this._items[index + 1] ? this._items[index + 1][1] : undefined;
771
676
  newKey = makePosition(before, after);
772
677
 
773
678
  child._setParentLink(this, newKey);
774
679
  } else {
775
- var _classPrivateFieldGet2;
680
+ var _this$_items;
776
681
 
777
- _classPrivateFieldGet(this, _items)[index][1] = makePosition(key, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _items)[index + 1]) == null ? void 0 : _classPrivateFieldGet2[1]);
682
+ this._items[index][1] = makePosition(key, (_this$_items = this._items[index + 1]) == null ? void 0 : _this$_items[1]);
778
683
  }
779
684
  }
780
685
 
781
- _classPrivateFieldGet(this, _items).push([child, newKey]);
686
+ this._items.push([child, newKey]);
782
687
 
783
- _classPrivateFieldGet(this, _items).sort(function (itemA, itemB) {
688
+ this._items.sort(function (itemA, itemB) {
784
689
  return compare(itemA[1], itemB[1]);
785
690
  });
786
691
 
787
- var newIndex = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
692
+ var newIndex = this._items.findIndex(function (entry) {
788
693
  return entry[1] === newKey;
789
694
  });
790
695
 
@@ -809,11 +714,11 @@ var LiveList = function (_AbstractCrdt) {
809
714
  if (child) {
810
715
  var reverse = child._serialize(this._id, child._parentKey, this._doc);
811
716
 
812
- var indexToDelete = _classPrivateFieldGet(this, _items).findIndex(function (item) {
717
+ var indexToDelete = this._items.findIndex(function (item) {
813
718
  return item[0] === child;
814
719
  });
815
720
 
816
- _classPrivateFieldGet(this, _items).splice(indexToDelete, 1);
721
+ this._items.splice(indexToDelete, 1);
817
722
 
818
723
  child._detach();
819
724
 
@@ -839,21 +744,21 @@ var LiveList = function (_AbstractCrdt) {
839
744
  _proto._setChildKey = function _setChildKey(key, child, previousKey) {
840
745
  child._setParentLink(this, key);
841
746
 
842
- var previousIndex = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
747
+ var previousIndex = this._items.findIndex(function (entry) {
843
748
  return entry[0]._id === child._id;
844
749
  });
845
750
 
846
- var index = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
751
+ var index = this._items.findIndex(function (entry) {
847
752
  return entry[1] === key;
848
753
  });
849
754
 
850
755
  if (index !== -1) {
851
- var _classPrivateFieldGet3;
756
+ var _this$_items2;
852
757
 
853
- _classPrivateFieldGet(this, _items)[index][1] = makePosition(key, (_classPrivateFieldGet3 = _classPrivateFieldGet(this, _items)[index + 1]) == null ? void 0 : _classPrivateFieldGet3[1]);
758
+ this._items[index][1] = makePosition(key, (_this$_items2 = this._items[index + 1]) == null ? void 0 : _this$_items2[1]);
854
759
  }
855
760
 
856
- var item = _classPrivateFieldGet(this, _items).find(function (item) {
761
+ var item = this._items.find(function (item) {
857
762
  return item[0] === child;
858
763
  });
859
764
 
@@ -861,11 +766,11 @@ var LiveList = function (_AbstractCrdt) {
861
766
  item[1] = key;
862
767
  }
863
768
 
864
- _classPrivateFieldGet(this, _items).sort(function (itemA, itemB) {
769
+ this._items.sort(function (itemA, itemB) {
865
770
  return compare(itemA[1], itemB[1]);
866
771
  });
867
772
 
868
- var newIndex = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
773
+ var newIndex = this._items.findIndex(function (entry) {
869
774
  return entry[0]._id === child._id;
870
775
  });
871
776
 
@@ -908,24 +813,24 @@ var LiveList = function (_AbstractCrdt) {
908
813
  };
909
814
 
910
815
  _proto.insert = function insert(element, index) {
911
- if (index < 0 || index > _classPrivateFieldGet(this, _items).length) {
912
- throw new Error("Cannot insert list item at index \"\x1D" + index + "\". index should be between 0 and " + _classPrivateFieldGet(this, _items).length);
816
+ if (index < 0 || index > this._items.length) {
817
+ throw new Error("Cannot insert list item at index \"\x1D" + index + "\". index should be between 0 and " + this._items.length);
913
818
  }
914
819
 
915
- var before = _classPrivateFieldGet(this, _items)[index - 1] ? _classPrivateFieldGet(this, _items)[index - 1][1] : undefined;
916
- var after = _classPrivateFieldGet(this, _items)[index] ? _classPrivateFieldGet(this, _items)[index][1] : undefined;
820
+ var before = this._items[index - 1] ? this._items[index - 1][1] : undefined;
821
+ var after = this._items[index] ? this._items[index][1] : undefined;
917
822
  var position = makePosition(before, after);
918
823
  var value = selfOrRegister(element);
919
824
 
920
825
  value._setParentLink(this, position);
921
826
 
922
- _classPrivateFieldGet(this, _items).push([value, position]);
827
+ this._items.push([value, position]);
923
828
 
924
- _classPrivateFieldGet(this, _items).sort(function (itemA, itemB) {
829
+ this._items.sort(function (itemA, itemB) {
925
830
  return compare(itemA[1], itemB[1]);
926
831
  });
927
832
 
928
- var newIndex = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
833
+ var newIndex = this._items.findIndex(function (entry) {
929
834
  return entry[1] === position;
930
835
  });
931
836
 
@@ -957,7 +862,7 @@ var LiveList = function (_AbstractCrdt) {
957
862
  throw new Error("targetIndex cannot be less than 0");
958
863
  }
959
864
 
960
- if (targetIndex >= _classPrivateFieldGet(this, _items).length) {
865
+ if (targetIndex >= this._items.length) {
961
866
  throw new Error("targetIndex cannot be greater or equal than the list length");
962
867
  }
963
868
 
@@ -965,7 +870,7 @@ var LiveList = function (_AbstractCrdt) {
965
870
  throw new Error("index cannot be less than 0");
966
871
  }
967
872
 
968
- if (index >= _classPrivateFieldGet(this, _items).length) {
873
+ if (index >= this._items.length) {
969
874
  throw new Error("index cannot be greater or equal than the list length");
970
875
  }
971
876
 
@@ -973,27 +878,25 @@ var LiveList = function (_AbstractCrdt) {
973
878
  var afterPosition = null;
974
879
 
975
880
  if (index < targetIndex) {
976
- afterPosition = targetIndex === _classPrivateFieldGet(this, _items).length - 1 ? undefined : _classPrivateFieldGet(this, _items)[targetIndex + 1][1];
977
- beforePosition = _classPrivateFieldGet(this, _items)[targetIndex][1];
881
+ afterPosition = targetIndex === this._items.length - 1 ? undefined : this._items[targetIndex + 1][1];
882
+ beforePosition = this._items[targetIndex][1];
978
883
  } else {
979
- afterPosition = _classPrivateFieldGet(this, _items)[targetIndex][1];
980
- beforePosition = targetIndex === 0 ? undefined : _classPrivateFieldGet(this, _items)[targetIndex - 1][1];
884
+ afterPosition = this._items[targetIndex][1];
885
+ beforePosition = targetIndex === 0 ? undefined : this._items[targetIndex - 1][1];
981
886
  }
982
887
 
983
888
  var position = makePosition(beforePosition, afterPosition);
984
-
985
- var item = _classPrivateFieldGet(this, _items)[index];
986
-
889
+ var item = this._items[index];
987
890
  var previousPosition = item[1];
988
891
  item[1] = position;
989
892
 
990
893
  item[0]._setParentLink(this, position);
991
894
 
992
- _classPrivateFieldGet(this, _items).sort(function (itemA, itemB) {
895
+ this._items.sort(function (itemA, itemB) {
993
896
  return compare(itemA[1], itemB[1]);
994
897
  });
995
898
 
996
- var newIndex = _classPrivateFieldGet(this, _items).findIndex(function (entry) {
899
+ var newIndex = this._items.findIndex(function (entry) {
997
900
  return entry[1] === position;
998
901
  });
999
902
 
@@ -1024,15 +927,15 @@ var LiveList = function (_AbstractCrdt) {
1024
927
  };
1025
928
 
1026
929
  _proto.delete = function _delete(index) {
1027
- if (index < 0 || index >= _classPrivateFieldGet(this, _items).length) {
1028
- throw new Error("Cannot delete list item at index \"\x1D" + index + "\". index should be between 0 and " + (_classPrivateFieldGet(this, _items).length - 1));
930
+ if (index < 0 || index >= this._items.length) {
931
+ throw new Error("Cannot delete list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
1029
932
  }
1030
933
 
1031
- var item = _classPrivateFieldGet(this, _items)[index];
934
+ var item = this._items[index];
1032
935
 
1033
936
  item[0]._detach();
1034
937
 
1035
- _classPrivateFieldGet(this, _items).splice(index, 1);
938
+ this._items.splice(index, 1);
1036
939
 
1037
940
  if (this._doc) {
1038
941
  var childRecordId = item[0]._id;
@@ -1064,7 +967,7 @@ var LiveList = function (_AbstractCrdt) {
1064
967
  var updateDelta = [];
1065
968
  var i = 0;
1066
969
 
1067
- for (var _iterator5 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _items)), _step5; !(_step5 = _iterator5()).done;) {
970
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this._items), _step5; !(_step5 = _iterator5()).done;) {
1068
971
  var _item3 = _step5.value;
1069
972
 
1070
973
  _item3[0]._detach();
@@ -1086,8 +989,7 @@ var LiveList = function (_AbstractCrdt) {
1086
989
  i++;
1087
990
  }
1088
991
 
1089
- _classPrivateFieldSet(this, _items, []);
1090
-
992
+ this._items = [];
1091
993
  var storageUpdates = new Map();
1092
994
  storageUpdates.set(this._id, {
1093
995
  node: this,
@@ -1097,18 +999,18 @@ var LiveList = function (_AbstractCrdt) {
1097
999
 
1098
1000
  this._doc.dispatch(ops, reverseOps, storageUpdates);
1099
1001
  } else {
1100
- for (var _iterator6 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _items)), _step6; !(_step6 = _iterator6()).done;) {
1002
+ for (var _iterator6 = _createForOfIteratorHelperLoose(this._items), _step6; !(_step6 = _iterator6()).done;) {
1101
1003
  var _item4 = _step6.value;
1102
1004
 
1103
1005
  _item4[0]._detach();
1104
1006
  }
1105
1007
 
1106
- _classPrivateFieldSet(this, _items, []);
1008
+ this._items = [];
1107
1009
  }
1108
1010
  };
1109
1011
 
1110
1012
  _proto.toArray = function toArray() {
1111
- return _classPrivateFieldGet(this, _items).map(function (entry) {
1013
+ return this._items.map(function (entry) {
1112
1014
  return selfOrRegisterValue(entry[0]);
1113
1015
  });
1114
1016
  };
@@ -1134,11 +1036,11 @@ var LiveList = function (_AbstractCrdt) {
1134
1036
  };
1135
1037
 
1136
1038
  _proto.get = function get(index) {
1137
- if (index < 0 || index >= _classPrivateFieldGet(this, _items).length) {
1039
+ if (index < 0 || index >= this._items.length) {
1138
1040
  return undefined;
1139
1041
  }
1140
1042
 
1141
- return selfOrRegisterValue(_classPrivateFieldGet(this, _items)[index][0]);
1043
+ return selfOrRegisterValue(this._items[index][0]);
1142
1044
  };
1143
1045
 
1144
1046
  _proto.indexOf = function indexOf(searchElement, fromIndex) {
@@ -1150,7 +1052,7 @@ var LiveList = function (_AbstractCrdt) {
1150
1052
  };
1151
1053
 
1152
1054
  _proto.map = function map(callback) {
1153
- return _classPrivateFieldGet(this, _items).map(function (entry, i) {
1055
+ return this._items.map(function (entry, i) {
1154
1056
  return callback(selfOrRegisterValue(entry[0]), i);
1155
1057
  });
1156
1058
  };
@@ -1159,42 +1061,33 @@ var LiveList = function (_AbstractCrdt) {
1159
1061
  return this.toArray().some(predicate);
1160
1062
  };
1161
1063
 
1162
- _proto[_Symbol$iterator$1] = function () {
1163
- return new LiveListIterator(_classPrivateFieldGet(this, _items));
1064
+ _proto[Symbol.iterator] = function () {
1065
+ return new LiveListIterator(this._items);
1164
1066
  };
1165
1067
 
1166
1068
  _createClass(LiveList, [{
1167
1069
  key: "length",
1168
1070
  get: function get() {
1169
- return _classPrivateFieldGet(this, _items).length;
1071
+ return this._items.length;
1170
1072
  }
1171
1073
  }]);
1172
1074
 
1173
1075
  return LiveList;
1174
1076
  }(AbstractCrdt);
1175
1077
 
1176
- var _innerIterator = new WeakMap();
1177
-
1178
- _Symbol$iterator2 = Symbol.iterator;
1179
-
1180
1078
  var LiveListIterator = function () {
1181
1079
  function LiveListIterator(items) {
1182
- _innerIterator.set(this, {
1183
- writable: true,
1184
- value: void 0
1185
- });
1186
-
1187
- _classPrivateFieldSet(this, _innerIterator, items[Symbol.iterator]());
1080
+ this._innerIterator = items[Symbol.iterator]();
1188
1081
  }
1189
1082
 
1190
1083
  var _proto2 = LiveListIterator.prototype;
1191
1084
 
1192
- _proto2[_Symbol$iterator2] = function () {
1085
+ _proto2[Symbol.iterator] = function () {
1193
1086
  return this;
1194
1087
  };
1195
1088
 
1196
1089
  _proto2.next = function next() {
1197
- var result = _classPrivateFieldGet(this, _innerIterator).next();
1090
+ var result = this._innerIterator.next();
1198
1091
 
1199
1092
  if (result.done) {
1200
1093
  return {
@@ -1211,11 +1104,6 @@ var LiveListIterator = function () {
1211
1104
  return LiveListIterator;
1212
1105
  }();
1213
1106
 
1214
- var _Symbol$iterator;
1215
-
1216
- var _map$1 = new WeakMap();
1217
-
1218
- _Symbol$iterator = Symbol.iterator;
1219
1107
  var LiveMap = function (_AbstractCrdt) {
1220
1108
  _inheritsLoose(LiveMap, _AbstractCrdt);
1221
1109
 
@@ -1224,11 +1112,6 @@ var LiveMap = function (_AbstractCrdt) {
1224
1112
 
1225
1113
  _this = _AbstractCrdt.call(this) || this;
1226
1114
 
1227
- _map$1.set(_assertThisInitialized(_this), {
1228
- writable: true,
1229
- value: void 0
1230
- });
1231
-
1232
1115
  if (entries) {
1233
1116
  var mappedEntries = [];
1234
1117
 
@@ -1242,9 +1125,9 @@ var LiveMap = function (_AbstractCrdt) {
1242
1125
  mappedEntries.push([entry[0], _value]);
1243
1126
  }
1244
1127
 
1245
- _classPrivateFieldSet(_assertThisInitialized(_this), _map$1, new Map(mappedEntries));
1128
+ _this._map = new Map(mappedEntries);
1246
1129
  } else {
1247
- _classPrivateFieldSet(_assertThisInitialized(_this), _map$1, new Map());
1130
+ _this._map = new Map();
1248
1131
  }
1249
1132
 
1250
1133
  return _this;
@@ -1271,11 +1154,11 @@ var LiveMap = function (_AbstractCrdt) {
1271
1154
  };
1272
1155
  ops.push(op);
1273
1156
 
1274
- for (var _iterator2 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map$1)), _step2; !(_step2 = _iterator2()).done;) {
1157
+ for (var _iterator2 = _createForOfIteratorHelperLoose(this._map), _step2; !(_step2 = _iterator2()).done;) {
1275
1158
  var _step2$value = _step2.value,
1276
- _key = _step2$value[0],
1159
+ _key2 = _step2$value[0],
1277
1160
  _value2 = _step2$value[1];
1278
- ops.push.apply(ops, _value2._serialize(this._id, _key, doc));
1161
+ ops.push.apply(ops, _value2._serialize(this._id, _key2, doc));
1279
1162
  }
1280
1163
 
1281
1164
  return ops;
@@ -1311,7 +1194,7 @@ var LiveMap = function (_AbstractCrdt) {
1311
1194
 
1312
1195
  child._setParentLink(map, crdt.parentKey);
1313
1196
 
1314
- _classPrivateFieldGet(map, _map$1).set(crdt.parentKey, child);
1197
+ map._map.set(crdt.parentKey, child);
1315
1198
  }
1316
1199
 
1317
1200
  return map;
@@ -1320,7 +1203,7 @@ var LiveMap = function (_AbstractCrdt) {
1320
1203
  _proto._attach = function _attach(id, doc) {
1321
1204
  _AbstractCrdt.prototype._attach.call(this, id, doc);
1322
1205
 
1323
- for (var _iterator4 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map$1)), _step4; !(_step4 = _iterator4()).done;) {
1206
+ for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
1324
1207
  var _step4$value = _step4.value;
1325
1208
  _step4$value[0];
1326
1209
  var _value3 = _step4$value[1];
@@ -1331,7 +1214,7 @@ var LiveMap = function (_AbstractCrdt) {
1331
1214
  }
1332
1215
  };
1333
1216
 
1334
- _proto._attachChild = function _attachChild(id, key, child, opId, isLocal) {
1217
+ _proto._attachChild = function _attachChild(id, key, child, _opId, _isLocal) {
1335
1218
  var _updates;
1336
1219
 
1337
1220
  if (this._doc == null) {
@@ -1344,7 +1227,7 @@ var LiveMap = function (_AbstractCrdt) {
1344
1227
  };
1345
1228
  }
1346
1229
 
1347
- var previousValue = _classPrivateFieldGet(this, _map$1).get(key);
1230
+ var previousValue = this._map.get(key);
1348
1231
 
1349
1232
  var reverse;
1350
1233
 
@@ -1363,7 +1246,7 @@ var LiveMap = function (_AbstractCrdt) {
1363
1246
 
1364
1247
  child._attach(id, this._doc);
1365
1248
 
1366
- _classPrivateFieldGet(this, _map$1).set(key, child);
1249
+ this._map.set(key, child);
1367
1250
 
1368
1251
  return {
1369
1252
  modified: {
@@ -1380,7 +1263,7 @@ var LiveMap = function (_AbstractCrdt) {
1380
1263
  _proto._detach = function _detach() {
1381
1264
  _AbstractCrdt.prototype._detach.call(this);
1382
1265
 
1383
- for (var _iterator5 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map$1).values()), _step5; !(_step5 = _iterator5()).done;) {
1266
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this._map.values()), _step5; !(_step5 = _iterator5()).done;) {
1384
1267
  var item = _step5.value;
1385
1268
 
1386
1269
  item._detach();
@@ -1392,13 +1275,13 @@ var LiveMap = function (_AbstractCrdt) {
1392
1275
 
1393
1276
  var reverse = child._serialize(this._id, child._parentKey, this._doc);
1394
1277
 
1395
- for (var _iterator6 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map$1)), _step6; !(_step6 = _iterator6()).done;) {
1278
+ for (var _iterator6 = _createForOfIteratorHelperLoose(this._map), _step6; !(_step6 = _iterator6()).done;) {
1396
1279
  var _step6$value = _step6.value,
1397
1280
  _key3 = _step6$value[0],
1398
1281
  _value4 = _step6$value[1];
1399
1282
 
1400
1283
  if (_value4 === child) {
1401
- _classPrivateFieldGet(this, _map$1).delete(_key3);
1284
+ this._map.delete(_key3);
1402
1285
  }
1403
1286
  }
1404
1287
 
@@ -1428,7 +1311,7 @@ var LiveMap = function (_AbstractCrdt) {
1428
1311
  };
1429
1312
 
1430
1313
  _proto.get = function get(key) {
1431
- var value = _classPrivateFieldGet(this, _map$1).get(key);
1314
+ var value = this._map.get(key);
1432
1315
 
1433
1316
  if (value == undefined) {
1434
1317
  return undefined;
@@ -1438,7 +1321,7 @@ var LiveMap = function (_AbstractCrdt) {
1438
1321
  };
1439
1322
 
1440
1323
  _proto.set = function set(key, value) {
1441
- var oldValue = _classPrivateFieldGet(this, _map$1).get(key);
1324
+ var oldValue = this._map.get(key);
1442
1325
 
1443
1326
  if (oldValue) {
1444
1327
  oldValue._detach();
@@ -1448,7 +1331,7 @@ var LiveMap = function (_AbstractCrdt) {
1448
1331
 
1449
1332
  item._setParentLink(this, key);
1450
1333
 
1451
- _classPrivateFieldGet(this, _map$1).set(key, item);
1334
+ this._map.set(key, item);
1452
1335
 
1453
1336
  if (this._doc && this._id) {
1454
1337
  var _updates3;
@@ -1474,11 +1357,11 @@ var LiveMap = function (_AbstractCrdt) {
1474
1357
  };
1475
1358
 
1476
1359
  _proto.has = function has(key) {
1477
- return _classPrivateFieldGet(this, _map$1).has(key);
1360
+ return this._map.has(key);
1478
1361
  };
1479
1362
 
1480
1363
  _proto.delete = function _delete(key) {
1481
- var item = _classPrivateFieldGet(this, _map$1).get(key);
1364
+ var item = this._map.get(key);
1482
1365
 
1483
1366
  if (item == null) {
1484
1367
  return false;
@@ -1486,7 +1369,7 @@ var LiveMap = function (_AbstractCrdt) {
1486
1369
 
1487
1370
  item._detach();
1488
1371
 
1489
- _classPrivateFieldGet(this, _map$1).delete(key);
1372
+ this._map.delete(key);
1490
1373
 
1491
1374
  if (this._doc && item._id) {
1492
1375
  var _updates4;
@@ -1513,7 +1396,7 @@ var LiveMap = function (_AbstractCrdt) {
1513
1396
  _proto.entries = function entries() {
1514
1397
  var _ref2;
1515
1398
 
1516
- var innerIterator = _classPrivateFieldGet(this, _map$1).entries();
1399
+ var innerIterator = this._map.entries();
1517
1400
 
1518
1401
  return _ref2 = {}, _ref2[Symbol.iterator] = function () {
1519
1402
  return this;
@@ -1534,18 +1417,18 @@ var LiveMap = function (_AbstractCrdt) {
1534
1417
  }, _ref2;
1535
1418
  };
1536
1419
 
1537
- _proto[_Symbol$iterator] = function () {
1420
+ _proto[Symbol.iterator] = function () {
1538
1421
  return this.entries();
1539
1422
  };
1540
1423
 
1541
1424
  _proto.keys = function keys() {
1542
- return _classPrivateFieldGet(this, _map$1).keys();
1425
+ return this._map.keys();
1543
1426
  };
1544
1427
 
1545
1428
  _proto.values = function values() {
1546
1429
  var _ref3;
1547
1430
 
1548
- var innerIterator = _classPrivateFieldGet(this, _map$1).values();
1431
+ var innerIterator = this._map.values();
1549
1432
 
1550
1433
  return _ref3 = {}, _ref3[Symbol.iterator] = function () {
1551
1434
  return this;
@@ -1575,7 +1458,7 @@ var LiveMap = function (_AbstractCrdt) {
1575
1458
  _createClass(LiveMap, [{
1576
1459
  key: "size",
1577
1460
  get: function get() {
1578
- return _classPrivateFieldGet(this, _map$1).size;
1461
+ return this._map.size;
1579
1462
  }
1580
1463
  }]);
1581
1464
 
@@ -1822,14 +1705,31 @@ function findNonSerializableValue(value, path) {
1822
1705
 
1823
1706
  return false;
1824
1707
  }
1708
+ function isTokenValid(token) {
1709
+ if (token === null) {
1710
+ return false;
1711
+ }
1825
1712
 
1826
- var _map = new WeakMap();
1713
+ var tokenParts = token.split(".");
1714
+
1715
+ if (tokenParts.length !== 3) {
1716
+ return false;
1717
+ }
1718
+
1719
+ var data = JSON.parse(atob(tokenParts[1]));
1720
+
1721
+ if (typeof data.exp !== "number") {
1722
+ return false;
1723
+ }
1827
1724
 
1828
- var _propToLastUpdate = new WeakMap();
1725
+ var now = Date.now();
1829
1726
 
1830
- var _applyUpdate = new WeakSet();
1727
+ if (now / 1000 > data.exp - 300) {
1728
+ return false;
1729
+ }
1831
1730
 
1832
- var _applyDeleteObjectKey = new WeakSet();
1731
+ return true;
1732
+ }
1833
1733
 
1834
1734
  var LiveObject = function (_AbstractCrdt) {
1835
1735
  _inheritsLoose(LiveObject, _AbstractCrdt);
@@ -1842,20 +1742,7 @@ var LiveObject = function (_AbstractCrdt) {
1842
1742
  }
1843
1743
 
1844
1744
  _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
- });
1745
+ _this._propToLastUpdate = new Map();
1859
1746
 
1860
1747
  for (var key in object) {
1861
1748
  var value = object[key];
@@ -1865,8 +1752,7 @@ var LiveObject = function (_AbstractCrdt) {
1865
1752
  }
1866
1753
  }
1867
1754
 
1868
- _classPrivateFieldSet(_assertThisInitialized(_this), _map, new Map(Object.entries(object)));
1869
-
1755
+ _this._map = new Map(Object.entries(object));
1870
1756
  return _this;
1871
1757
  }
1872
1758
 
@@ -1888,7 +1774,7 @@ var LiveObject = function (_AbstractCrdt) {
1888
1774
  };
1889
1775
  ops.push(op);
1890
1776
 
1891
- for (var _iterator = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map)), _step; !(_step = _iterator()).done;) {
1777
+ for (var _iterator = _createForOfIteratorHelperLoose(this._map), _step; !(_step = _iterator()).done;) {
1892
1778
  var _step$value = _step.value,
1893
1779
  key = _step$value[0],
1894
1780
  value = _step$value[1];
@@ -1937,7 +1823,7 @@ var LiveObject = function (_AbstractCrdt) {
1937
1823
 
1938
1824
  child._setParentLink(object, crdt.parentKey);
1939
1825
 
1940
- _classPrivateFieldGet(object, _map).set(crdt.parentKey, child);
1826
+ object._map.set(crdt.parentKey, child);
1941
1827
  }
1942
1828
 
1943
1829
  return object;
@@ -1946,7 +1832,7 @@ var LiveObject = function (_AbstractCrdt) {
1946
1832
  _proto._attach = function _attach(id, doc) {
1947
1833
  _AbstractCrdt.prototype._attach.call(this, id, doc);
1948
1834
 
1949
- for (var _iterator3 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map)), _step3; !(_step3 = _iterator3()).done;) {
1835
+ for (var _iterator3 = _createForOfIteratorHelperLoose(this._map), _step3; !(_step3 = _iterator3()).done;) {
1950
1836
  var _step3$value = _step3.value;
1951
1837
  _step3$value[0];
1952
1838
  var value = _step3$value[1];
@@ -1965,8 +1851,8 @@ var LiveObject = function (_AbstractCrdt) {
1965
1851
  }
1966
1852
 
1967
1853
  if (this._doc.getItem(id) !== undefined) {
1968
- if (_classPrivateFieldGet(this, _propToLastUpdate).get(key) === opId) {
1969
- _classPrivateFieldGet(this, _propToLastUpdate).delete(key);
1854
+ if (this._propToLastUpdate.get(key) === opId) {
1855
+ this._propToLastUpdate.delete(key);
1970
1856
  }
1971
1857
 
1972
1858
  return {
@@ -1975,9 +1861,9 @@ var LiveObject = function (_AbstractCrdt) {
1975
1861
  }
1976
1862
 
1977
1863
  if (isLocal) {
1978
- _classPrivateFieldGet(this, _propToLastUpdate).set(key, opId);
1979
- } else if (_classPrivateFieldGet(this, _propToLastUpdate).get(key) === undefined) ; else if (_classPrivateFieldGet(this, _propToLastUpdate).get(key) === opId) {
1980
- _classPrivateFieldGet(this, _propToLastUpdate).delete(key);
1864
+ this._propToLastUpdate.set(key, opId);
1865
+ } else if (this._propToLastUpdate.get(key) === undefined) ; else if (this._propToLastUpdate.get(key) === opId) {
1866
+ this._propToLastUpdate.delete(key);
1981
1867
 
1982
1868
  return {
1983
1869
  modified: false
@@ -1988,7 +1874,7 @@ var LiveObject = function (_AbstractCrdt) {
1988
1874
  };
1989
1875
  }
1990
1876
 
1991
- var previousValue = _classPrivateFieldGet(this, _map).get(key);
1877
+ var previousValue = this._map.get(key);
1992
1878
 
1993
1879
  var reverse;
1994
1880
 
@@ -2012,7 +1898,7 @@ var LiveObject = function (_AbstractCrdt) {
2012
1898
  }];
2013
1899
  }
2014
1900
 
2015
- _classPrivateFieldGet(this, _map).set(key, child);
1901
+ this._map.set(key, child);
2016
1902
 
2017
1903
  child._setParentLink(this, key);
2018
1904
 
@@ -2036,13 +1922,13 @@ var LiveObject = function (_AbstractCrdt) {
2036
1922
 
2037
1923
  var reverse = child._serialize(this._id, child._parentKey, this._doc);
2038
1924
 
2039
- for (var _iterator4 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map)), _step4; !(_step4 = _iterator4()).done;) {
1925
+ for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
2040
1926
  var _step4$value = _step4.value,
2041
1927
  key = _step4$value[0],
2042
1928
  value = _step4$value[1];
2043
1929
 
2044
1930
  if (value === child) {
2045
- _classPrivateFieldGet(this, _map).delete(key);
1931
+ this._map.delete(key);
2046
1932
  }
2047
1933
  }
2048
1934
 
@@ -2067,12 +1953,12 @@ var LiveObject = function (_AbstractCrdt) {
2067
1953
  };
2068
1954
 
2069
1955
  _proto._detachChildren = function _detachChildren() {
2070
- for (var _iterator5 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map)), _step5; !(_step5 = _iterator5()).done;) {
1956
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this._map), _step5; !(_step5 = _iterator5()).done;) {
2071
1957
  var _step5$value = _step5.value,
2072
1958
  key = _step5$value[0],
2073
1959
  value = _step5$value[1];
2074
1960
 
2075
- _classPrivateFieldGet(this, _map).delete(key);
1961
+ this._map.delete(key);
2076
1962
 
2077
1963
  value._detach();
2078
1964
  }
@@ -2081,7 +1967,7 @@ var LiveObject = function (_AbstractCrdt) {
2081
1967
  _proto._detach = function _detach() {
2082
1968
  _AbstractCrdt.prototype._detach.call(this);
2083
1969
 
2084
- for (var _iterator6 = _createForOfIteratorHelperLoose(_classPrivateFieldGet(this, _map).values()), _step6; !(_step6 = _iterator6()).done;) {
1970
+ for (var _iterator6 = _createForOfIteratorHelperLoose(this._map.values()), _step6; !(_step6 = _iterator6()).done;) {
2085
1971
  var value = _step6.value;
2086
1972
 
2087
1973
  if (isCrdt(value)) {
@@ -2092,9 +1978,9 @@ var LiveObject = function (_AbstractCrdt) {
2092
1978
 
2093
1979
  _proto._apply = function _apply(op, isLocal) {
2094
1980
  if (op.type === OpType.UpdateObject) {
2095
- return _classPrivateMethodGet(this, _applyUpdate, _applyUpdate2).call(this, op, isLocal);
1981
+ return this._applyUpdate(op, isLocal);
2096
1982
  } else if (op.type === OpType.DeleteObjectKey) {
2097
- return _classPrivateMethodGet(this, _applyDeleteObjectKey, _applyDeleteObjectKey2).call(this, op);
1983
+ return this._applyDeleteObjectKey(op);
2098
1984
  }
2099
1985
 
2100
1986
  return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
@@ -2103,16 +1989,150 @@ var LiveObject = function (_AbstractCrdt) {
2103
1989
  _proto._toSerializedCrdt = function _toSerializedCrdt() {
2104
1990
  var _this$_parent;
2105
1991
 
1992
+ var data = {};
1993
+
1994
+ for (var _iterator7 = _createForOfIteratorHelperLoose(this._map), _step7; !(_step7 = _iterator7()).done;) {
1995
+ var _step7$value = _step7.value,
1996
+ key = _step7$value[0],
1997
+ value = _step7$value[1];
1998
+
1999
+ if (value instanceof AbstractCrdt === false) {
2000
+ data[key] = value;
2001
+ }
2002
+ }
2003
+
2106
2004
  return {
2107
2005
  type: CrdtType.Object,
2108
2006
  parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
2109
2007
  parentKey: this._parentKey,
2110
- data: this.toObject()
2008
+ data: data
2009
+ };
2010
+ };
2011
+
2012
+ _proto._applyUpdate = function _applyUpdate(op, isLocal) {
2013
+ var isModified = false;
2014
+ var reverse = [];
2015
+ var reverseUpdate = {
2016
+ type: OpType.UpdateObject,
2017
+ id: this._id,
2018
+ data: {}
2019
+ };
2020
+ reverse.push(reverseUpdate);
2021
+
2022
+ for (var key in op.data) {
2023
+ var oldValue = this._map.get(key);
2024
+
2025
+ if (oldValue instanceof AbstractCrdt) {
2026
+ reverse.push.apply(reverse, oldValue._serialize(this._id, key));
2027
+
2028
+ oldValue._detach();
2029
+ } else if (oldValue !== undefined) {
2030
+ reverseUpdate.data[key] = oldValue;
2031
+ } else if (oldValue === undefined) {
2032
+ reverse.push({
2033
+ type: OpType.DeleteObjectKey,
2034
+ id: this._id,
2035
+ key: key
2036
+ });
2037
+ }
2038
+ }
2039
+
2040
+ var updateDelta = {};
2041
+
2042
+ for (var _key2 in op.data) {
2043
+ if (isLocal) {
2044
+ this._propToLastUpdate.set(_key2, op.opId);
2045
+ } else if (this._propToLastUpdate.get(_key2) == null) {
2046
+ isModified = true;
2047
+ } else if (this._propToLastUpdate.get(_key2) === op.opId) {
2048
+ this._propToLastUpdate.delete(_key2);
2049
+
2050
+ continue;
2051
+ } else {
2052
+ continue;
2053
+ }
2054
+
2055
+ var _oldValue = this._map.get(_key2);
2056
+
2057
+ if (isCrdt(_oldValue)) {
2058
+ _oldValue._detach();
2059
+ }
2060
+
2061
+ isModified = true;
2062
+ updateDelta[_key2] = {
2063
+ type: "update"
2064
+ };
2065
+
2066
+ this._map.set(_key2, op.data[_key2]);
2067
+ }
2068
+
2069
+ if (Object.keys(reverseUpdate.data).length !== 0) {
2070
+ reverse.unshift(reverseUpdate);
2071
+ }
2072
+
2073
+ return isModified ? {
2074
+ modified: {
2075
+ node: this,
2076
+ type: "LiveObject",
2077
+ updates: updateDelta
2078
+ },
2079
+ reverse: reverse
2080
+ } : {
2081
+ modified: false
2082
+ };
2083
+ };
2084
+
2085
+ _proto._applyDeleteObjectKey = function _applyDeleteObjectKey(op) {
2086
+ var _updates3;
2087
+
2088
+ var key = op.key;
2089
+
2090
+ if (this._map.has(key) === false) {
2091
+ return {
2092
+ modified: false
2093
+ };
2094
+ }
2095
+
2096
+ if (this._propToLastUpdate.get(key) !== undefined) {
2097
+ return {
2098
+ modified: false
2099
+ };
2100
+ }
2101
+
2102
+ var oldValue = this._map.get(key);
2103
+
2104
+ var reverse = [];
2105
+
2106
+ if (isCrdt(oldValue)) {
2107
+ reverse = oldValue._serialize(this._id, op.key);
2108
+
2109
+ oldValue._detach();
2110
+ } else if (oldValue !== undefined) {
2111
+ var _data2;
2112
+
2113
+ reverse = [{
2114
+ type: OpType.UpdateObject,
2115
+ id: this._id,
2116
+ data: (_data2 = {}, _data2[key] = oldValue, _data2)
2117
+ }];
2118
+ }
2119
+
2120
+ this._map.delete(key);
2121
+
2122
+ return {
2123
+ modified: {
2124
+ node: this,
2125
+ type: "LiveObject",
2126
+ updates: (_updates3 = {}, _updates3[op.key] = {
2127
+ type: "delete"
2128
+ }, _updates3)
2129
+ },
2130
+ reverse: reverse
2111
2131
  };
2112
2132
  };
2113
2133
 
2114
2134
  _proto.toObject = function toObject() {
2115
- return Object.fromEntries(_classPrivateFieldGet(this, _map));
2135
+ return Object.fromEntries(this._map);
2116
2136
  };
2117
2137
 
2118
2138
  _proto.set = function set(key, value) {
@@ -2122,15 +2142,15 @@ var LiveObject = function (_AbstractCrdt) {
2122
2142
  };
2123
2143
 
2124
2144
  _proto.get = function get(key) {
2125
- return _classPrivateFieldGet(this, _map).get(key);
2145
+ return this._map.get(key);
2126
2146
  };
2127
2147
 
2128
2148
  _proto.delete = function _delete(key) {
2129
- var _updates3;
2149
+ var _updates4;
2130
2150
 
2131
2151
  var keyAsString = key;
2132
2152
 
2133
- var oldValue = _classPrivateFieldGet(this, _map).get(keyAsString);
2153
+ var oldValue = this._map.get(keyAsString);
2134
2154
 
2135
2155
  if (oldValue === undefined) {
2136
2156
  return;
@@ -2141,7 +2161,7 @@ var LiveObject = function (_AbstractCrdt) {
2141
2161
  oldValue._detach();
2142
2162
  }
2143
2163
 
2144
- _classPrivateFieldGet(this, _map).delete(keyAsString);
2164
+ this._map.delete(keyAsString);
2145
2165
 
2146
2166
  return;
2147
2167
  }
@@ -2153,24 +2173,24 @@ var LiveObject = function (_AbstractCrdt) {
2153
2173
 
2154
2174
  reverse = oldValue._serialize(this._id, keyAsString);
2155
2175
  } else {
2156
- var _data2;
2176
+ var _data3;
2157
2177
 
2158
2178
  reverse = [{
2159
2179
  type: OpType.UpdateObject,
2160
- data: (_data2 = {}, _data2[keyAsString] = oldValue, _data2),
2180
+ data: (_data3 = {}, _data3[keyAsString] = oldValue, _data3),
2161
2181
  id: this._id
2162
2182
  }];
2163
2183
  }
2164
2184
 
2165
- _classPrivateFieldGet(this, _map).delete(keyAsString);
2185
+ this._map.delete(keyAsString);
2166
2186
 
2167
2187
  var storageUpdates = new Map();
2168
2188
  storageUpdates.set(this._id, {
2169
2189
  node: this,
2170
2190
  type: "LiveObject",
2171
- updates: (_updates3 = {}, _updates3[key] = {
2191
+ updates: (_updates4 = {}, _updates4[key] = {
2172
2192
  type: "delete"
2173
- }, _updates3)
2193
+ }, _updates4)
2174
2194
  });
2175
2195
 
2176
2196
  this._doc.dispatch([{
@@ -2186,7 +2206,7 @@ var LiveObject = function (_AbstractCrdt) {
2186
2206
 
2187
2207
  if (this._doc == null || this._id == null) {
2188
2208
  for (var key in overrides) {
2189
- var oldValue = _classPrivateFieldGet(this, _map).get(key);
2209
+ var oldValue = this._map.get(key);
2190
2210
 
2191
2211
  if (oldValue instanceof AbstractCrdt) {
2192
2212
  oldValue._detach();
@@ -2198,7 +2218,7 @@ var LiveObject = function (_AbstractCrdt) {
2198
2218
  newValue._setParentLink(this, key);
2199
2219
  }
2200
2220
 
2201
- _classPrivateFieldGet(this, _map).set(key, newValue);
2221
+ this._map.set(key, newValue);
2202
2222
  }
2203
2223
 
2204
2224
  return;
@@ -2217,50 +2237,50 @@ var LiveObject = function (_AbstractCrdt) {
2217
2237
  };
2218
2238
  var updateDelta = {};
2219
2239
 
2220
- for (var _key in overrides) {
2221
- var _oldValue = _classPrivateFieldGet(this, _map).get(_key);
2240
+ for (var _key3 in overrides) {
2241
+ var _oldValue2 = this._map.get(_key3);
2222
2242
 
2223
- if (_oldValue instanceof AbstractCrdt) {
2224
- reverseOps.push.apply(reverseOps, _oldValue._serialize(this._id, _key));
2243
+ if (_oldValue2 instanceof AbstractCrdt) {
2244
+ reverseOps.push.apply(reverseOps, _oldValue2._serialize(this._id, _key3));
2225
2245
 
2226
- _oldValue._detach();
2227
- } else if (_oldValue === undefined) {
2246
+ _oldValue2._detach();
2247
+ } else if (_oldValue2 === undefined) {
2228
2248
  reverseOps.push({
2229
2249
  type: OpType.DeleteObjectKey,
2230
2250
  id: this._id,
2231
- key: _key
2251
+ key: _key3
2232
2252
  });
2233
2253
  } else {
2234
- reverseUpdateOp.data[_key] = _oldValue;
2254
+ reverseUpdateOp.data[_key3] = _oldValue2;
2235
2255
  }
2236
2256
 
2237
- var _newValue = overrides[_key];
2257
+ var _newValue = overrides[_key3];
2238
2258
 
2239
2259
  if (_newValue instanceof AbstractCrdt) {
2240
- _newValue._setParentLink(this, _key);
2260
+ _newValue._setParentLink(this, _key3);
2241
2261
 
2242
2262
  _newValue._attach(this._doc.generateId(), this._doc);
2243
2263
 
2244
- var newAttachChildOps = _newValue._serialize(this._id, _key, this._doc);
2264
+ var newAttachChildOps = _newValue._serialize(this._id, _key3, this._doc);
2245
2265
 
2246
2266
  var createCrdtOp = newAttachChildOps.find(function (op) {
2247
2267
  return op.parentId === _this2._id;
2248
2268
  });
2249
2269
 
2250
2270
  if (createCrdtOp) {
2251
- _classPrivateFieldGet(this, _propToLastUpdate).set(_key, createCrdtOp.opId);
2271
+ this._propToLastUpdate.set(_key3, createCrdtOp.opId);
2252
2272
  }
2253
2273
 
2254
2274
  ops.push.apply(ops, newAttachChildOps);
2255
2275
  } else {
2256
- updatedProps[_key] = _newValue;
2276
+ updatedProps[_key3] = _newValue;
2257
2277
 
2258
- _classPrivateFieldGet(this, _propToLastUpdate).set(_key, opId);
2278
+ this._propToLastUpdate.set(_key3, opId);
2259
2279
  }
2260
2280
 
2261
- _classPrivateFieldGet(this, _map).set(_key, _newValue);
2281
+ this._map.set(_key3, _newValue);
2262
2282
 
2263
- updateDelta[_key] = {
2283
+ updateDelta[_key3] = {
2264
2284
  type: "update"
2265
2285
  };
2266
2286
  }
@@ -2291,128 +2311,6 @@ var LiveObject = function (_AbstractCrdt) {
2291
2311
  return LiveObject;
2292
2312
  }(AbstractCrdt);
2293
2313
 
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
2314
  var BACKOFF_RETRY_DELAYS = [250, 500, 1000, 2000, 4000, 8000, 10000];
2417
2315
  var BACKOFF_RETRY_DELAYS_SLOW = [2000, 30000, 60000, 300000];
2418
2316
  var HEARTBEAT_INTERVAL = 30000;
@@ -2429,38 +2327,52 @@ function makeIdFactory(connectionId) {
2429
2327
  };
2430
2328
  }
2431
2329
 
2432
- function makeOthers(presenceMap) {
2433
- var array = Object.values(presenceMap).map(function (presence) {
2434
- presence._hasReceivedInitialPresence;
2435
- var publicKeys = _objectWithoutPropertiesLoose(presence, ["_hasReceivedInitialPresence"]);
2330
+ function makeOthers(userMap) {
2331
+ var _ref;
2332
+
2333
+ var users = Object.values(userMap).map(function (user) {
2334
+ user._hasReceivedInitialPresence;
2335
+ var publicKeys = _objectWithoutPropertiesLoose(user, ["_hasReceivedInitialPresence"]);
2436
2336
 
2437
2337
  return publicKeys;
2438
2338
  });
2439
- var arrayish = Object.assign(array, {
2440
- count: array.length,
2441
- toArray: function toArray() {
2442
- return array;
2443
- }
2444
- });
2445
- return Object.freeze(arrayish);
2339
+ return _ref = {
2340
+ get count() {
2341
+ return users.length;
2342
+ }
2343
+
2344
+ }, _ref[Symbol.iterator] = function () {
2345
+ return users[Symbol.iterator]();
2346
+ }, _ref.map = function map(callback) {
2347
+ return users.map(callback);
2348
+ }, _ref.toArray = function toArray() {
2349
+ return users;
2350
+ }, _ref;
2446
2351
  }
2447
2352
 
2448
2353
  function makeStateMachine(state, context, mockedEffects) {
2449
2354
  var effects = mockedEffects || {
2450
2355
  authenticate: function authenticate(auth, createWebSocket) {
2451
- return auth(context.room).then(function (_ref) {
2452
- var token = _ref.token;
2356
+ if (isTokenValid(state.token)) {
2357
+ var parsedToken = parseToken(state.token);
2358
+ var socket = createWebSocket(state.token);
2359
+ authenticationSuccess(parsedToken, socket);
2360
+ } else {
2361
+ return auth(context.room).then(function (_ref2) {
2362
+ var token = _ref2.token;
2453
2363
 
2454
- if (state.connection.state !== "authenticating") {
2455
- return;
2456
- }
2364
+ if (state.connection.state !== "authenticating") {
2365
+ return;
2366
+ }
2457
2367
 
2458
- var parsedToken = parseToken(token);
2459
- var socket = createWebSocket(token);
2460
- authenticationSuccess(parsedToken, socket);
2461
- }).catch(function (er) {
2462
- return authenticationFailure(er);
2463
- });
2368
+ var parsedToken = parseToken(token);
2369
+ var socket = createWebSocket(token);
2370
+ authenticationSuccess(parsedToken, socket);
2371
+ state.token = token;
2372
+ }).catch(function (er) {
2373
+ return authenticationFailure(er);
2374
+ });
2375
+ }
2464
2376
  },
2465
2377
  send: function send(messageOrMessages) {
2466
2378
  if (state.socket == null) {
@@ -2635,21 +2547,21 @@ function makeStateMachine(state, context, mockedEffects) {
2635
2547
  }
2636
2548
  }
2637
2549
 
2638
- function notify(_ref2) {
2639
- var _ref2$storageUpdates = _ref2.storageUpdates,
2640
- storageUpdates = _ref2$storageUpdates === void 0 ? new Map() : _ref2$storageUpdates,
2641
- _ref2$presence = _ref2.presence,
2642
- presence = _ref2$presence === void 0 ? false : _ref2$presence,
2643
- _ref2$others = _ref2.others,
2644
- others = _ref2$others === void 0 ? [] : _ref2$others;
2550
+ function notify(_ref3) {
2551
+ var _ref3$storageUpdates = _ref3.storageUpdates,
2552
+ storageUpdates = _ref3$storageUpdates === void 0 ? new Map() : _ref3$storageUpdates,
2553
+ _ref3$presence = _ref3.presence,
2554
+ presence = _ref3$presence === void 0 ? false : _ref3$presence,
2555
+ _ref3$others = _ref3.others,
2556
+ otherEvents = _ref3$others === void 0 ? [] : _ref3$others;
2645
2557
 
2646
- if (others.length > 0) {
2558
+ if (otherEvents.length > 0) {
2647
2559
  state.others = makeOthers(state.users);
2648
2560
 
2649
- for (var _iterator3 = _createForOfIteratorHelperLoose(others), _step3; !(_step3 = _iterator3()).done;) {
2561
+ for (var _iterator3 = _createForOfIteratorHelperLoose(otherEvents), _step3; !(_step3 = _iterator3()).done;) {
2650
2562
  var event = _step3.value;
2651
2563
 
2652
- for (var _iterator4 = _createForOfIteratorHelperLoose(state.listeners["others"]), _step4; !(_step4 = _iterator4()).done;) {
2564
+ for (var _iterator4 = _createForOfIteratorHelperLoose(state.listeners.others), _step4; !(_step4 = _iterator4()).done;) {
2653
2565
  var _listener = _step4.value;
2654
2566
 
2655
2567
  _listener(state.others, event);
@@ -2963,6 +2875,7 @@ function makeStateMachine(state, context, mockedEffects) {
2963
2875
  console.error("Call to authentication endpoint failed", error);
2964
2876
  }
2965
2877
 
2878
+ state.token = null;
2966
2879
  updateConnection({
2967
2880
  state: "unavailable"
2968
2881
  });
@@ -3147,8 +3060,9 @@ function makeStateMachine(state, context, mockedEffects) {
3147
3060
 
3148
3061
  case ServerMessageType.InitialStorageState:
3149
3062
  {
3063
+ var offlineOps = new Map(state.offlineOperations);
3150
3064
  createOrUpdateRootFromMessage(subMessage);
3151
- applyAndSendOfflineOps();
3065
+ applyAndSendOfflineOps(offlineOps);
3152
3066
  _getInitialStateResolver == null ? void 0 : _getInitialStateResolver();
3153
3067
  break;
3154
3068
  }
@@ -3320,13 +3234,13 @@ function makeStateMachine(state, context, mockedEffects) {
3320
3234
  connect();
3321
3235
  }
3322
3236
 
3323
- function applyAndSendOfflineOps() {
3324
- if (state.offlineOperations.size === 0) {
3237
+ function applyAndSendOfflineOps(offlineOps) {
3238
+ if (offlineOps.size === 0) {
3325
3239
  return;
3326
3240
  }
3327
3241
 
3328
3242
  var messages = [];
3329
- var ops = Array.from(state.offlineOperations.values());
3243
+ var ops = Array.from(offlineOps.values());
3330
3244
  var result = apply(ops, true);
3331
3245
  messages.push({
3332
3246
  type: ClientMessageType.UpdateStorage,
@@ -3659,6 +3573,7 @@ function defaultState(me, defaultStorageRoot) {
3659
3573
  connection: {
3660
3574
  state: "closed"
3661
3575
  },
3576
+ token: null,
3662
3577
  lastConnectionId: null,
3663
3578
  socket: null,
3664
3579
  listeners: {