@liveblocks/client 0.15.11-test.1 → 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/esm/index.mjs CHANGED
@@ -46,46 +46,21 @@ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
46
46
  return WebsocketCloseCodes2;
47
47
  })(WebsocketCloseCodes || {});
48
48
 
49
- var __accessCheck$4 = (obj, member, msg) => {
50
- if (!member.has(obj))
51
- throw TypeError("Cannot " + msg);
52
- };
53
- var __privateGet$4 = (obj, member, getter) => {
54
- __accessCheck$4(obj, member, "read from private field");
55
- return getter ? getter.call(obj) : member.get(obj);
56
- };
57
- var __privateAdd$4 = (obj, member, value) => {
58
- if (member.has(obj))
59
- throw TypeError("Cannot add the same private member more than once");
60
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
61
- };
62
- var __privateSet$4 = (obj, member, value, setter) => {
63
- __accessCheck$4(obj, member, "write to private field");
64
- setter ? setter.call(obj, value) : member.set(obj, value);
65
- return value;
66
- };
67
- var _parent, _doc, _id, _parentKey;
68
49
  class AbstractCrdt {
69
- constructor() {
70
- __privateAdd$4(this, _parent, void 0);
71
- __privateAdd$4(this, _doc, void 0);
72
- __privateAdd$4(this, _id, void 0);
73
- __privateAdd$4(this, _parentKey, void 0);
74
- }
75
50
  get _doc() {
76
- return __privateGet$4(this, _doc);
51
+ return this.__doc;
77
52
  }
78
53
  get roomId() {
79
- return __privateGet$4(this, _doc) ? __privateGet$4(this, _doc).roomId : null;
54
+ return this.__doc ? this.__doc.roomId : null;
80
55
  }
81
56
  get _id() {
82
- return __privateGet$4(this, _id);
57
+ return this.__id;
83
58
  }
84
59
  get _parent() {
85
- return __privateGet$4(this, _parent);
60
+ return this.__parent;
86
61
  }
87
62
  get _parentKey() {
88
- return __privateGet$4(this, _parentKey);
63
+ return this.__parentKey;
89
64
  }
90
65
  _apply(op, _isLocal) {
91
66
  switch (op.type) {
@@ -99,32 +74,28 @@ class AbstractCrdt {
99
74
  return { modified: false };
100
75
  }
101
76
  _setParentLink(parent, key) {
102
- if (__privateGet$4(this, _parent) != null && __privateGet$4(this, _parent) !== parent) {
77
+ if (this.__parent != null && this.__parent !== parent) {
103
78
  throw new Error("Cannot attach parent if it already exist");
104
79
  }
105
- __privateSet$4(this, _parentKey, key);
106
- __privateSet$4(this, _parent, parent);
80
+ this.__parentKey = key;
81
+ this.__parent = parent;
107
82
  }
108
83
  _attach(id, doc) {
109
- if (__privateGet$4(this, _id) || __privateGet$4(this, _doc)) {
84
+ if (this.__id || this.__doc) {
110
85
  throw new Error("Cannot attach if CRDT is already attached");
111
86
  }
112
87
  doc.addItem(id, this);
113
- __privateSet$4(this, _id, id);
114
- __privateSet$4(this, _doc, doc);
88
+ this.__id = id;
89
+ this.__doc = doc;
115
90
  }
116
91
  _detach() {
117
- if (__privateGet$4(this, _doc) && __privateGet$4(this, _id)) {
118
- __privateGet$4(this, _doc).deleteItem(__privateGet$4(this, _id));
92
+ if (this.__doc && this.__id) {
93
+ this.__doc.deleteItem(this.__id);
119
94
  }
120
- __privateSet$4(this, _parent, void 0);
121
- __privateSet$4(this, _doc, void 0);
95
+ this.__parent = void 0;
96
+ this.__doc = void 0;
122
97
  }
123
98
  }
124
- _parent = new WeakMap();
125
- _doc = new WeakMap();
126
- _id = new WeakMap();
127
- _parentKey = new WeakMap();
128
99
 
129
100
  const min = 32;
130
101
  const max = 126;
@@ -227,39 +198,19 @@ function compare(posA, posB) {
227
198
  throw new Error(`Impossible to compare similar position "${posA}" and "${posB}"`);
228
199
  }
229
200
 
230
- var __accessCheck$3 = (obj, member, msg) => {
231
- if (!member.has(obj))
232
- throw TypeError("Cannot " + msg);
233
- };
234
- var __privateGet$3 = (obj, member, getter) => {
235
- __accessCheck$3(obj, member, "read from private field");
236
- return getter ? getter.call(obj) : member.get(obj);
237
- };
238
- var __privateAdd$3 = (obj, member, value) => {
239
- if (member.has(obj))
240
- throw TypeError("Cannot add the same private member more than once");
241
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
242
- };
243
- var __privateSet$3 = (obj, member, value, setter) => {
244
- __accessCheck$3(obj, member, "write to private field");
245
- setter ? setter.call(obj, value) : member.set(obj, value);
246
- return value;
247
- };
248
- var _data;
249
- const _LiveRegister = class extends AbstractCrdt {
201
+ class LiveRegister extends AbstractCrdt {
250
202
  constructor(data) {
251
203
  super();
252
- __privateAdd$3(this, _data, void 0);
253
- __privateSet$3(this, _data, data);
204
+ this._data = data;
254
205
  }
255
206
  get data() {
256
- return __privateGet$3(this, _data);
207
+ return this._data;
257
208
  }
258
209
  static _deserialize([id, item], parentToChildren, doc) {
259
210
  if (item.type !== CrdtType.Register) {
260
211
  throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
261
212
  }
262
- const register = new _LiveRegister(item.data);
213
+ const register = new LiveRegister(item.data);
263
214
  register._attach(id, doc);
264
215
  return register;
265
216
  }
@@ -296,43 +247,22 @@ const _LiveRegister = class extends AbstractCrdt {
296
247
  _apply(op, isLocal) {
297
248
  return super._apply(op, isLocal);
298
249
  }
299
- };
300
- let LiveRegister = _LiveRegister;
301
- _data = new WeakMap();
250
+ }
302
251
 
303
- var __accessCheck$2 = (obj, member, msg) => {
304
- if (!member.has(obj))
305
- throw TypeError("Cannot " + msg);
306
- };
307
- var __privateGet$2 = (obj, member, getter) => {
308
- __accessCheck$2(obj, member, "read from private field");
309
- return getter ? getter.call(obj) : member.get(obj);
310
- };
311
- var __privateAdd$2 = (obj, member, value) => {
312
- if (member.has(obj))
313
- throw TypeError("Cannot add the same private member more than once");
314
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
315
- };
316
- var __privateSet$2 = (obj, member, value, setter) => {
317
- __accessCheck$2(obj, member, "write to private field");
318
- setter ? setter.call(obj, value) : member.set(obj, value);
319
- return value;
320
- };
321
- var _items, _innerIterator;
322
- const _LiveList = class extends AbstractCrdt {
252
+ class LiveList extends AbstractCrdt {
323
253
  constructor(items = []) {
324
254
  super();
325
- __privateAdd$2(this, _items, []);
255
+ this._items = [];
326
256
  let position = void 0;
327
257
  for (let i = 0; i < items.length; i++) {
328
258
  const newPosition = makePosition(position);
329
259
  const item = selfOrRegister(items[i]);
330
- __privateGet$2(this, _items).push([item, newPosition]);
260
+ this._items.push([item, newPosition]);
331
261
  position = newPosition;
332
262
  }
333
263
  }
334
264
  static _deserialize([id], parentToChildren, doc) {
335
- const list = new _LiveList([]);
265
+ const list = new LiveList([]);
336
266
  list._attach(id, doc);
337
267
  const children = parentToChildren.get(id);
338
268
  if (children == null) {
@@ -341,8 +271,8 @@ const _LiveList = class extends AbstractCrdt {
341
271
  for (const entry of children) {
342
272
  const child = deserialize(entry, parentToChildren, doc);
343
273
  child._setParentLink(list, entry[1].parentKey);
344
- __privateGet$2(list, _items).push([child, entry[1].parentKey]);
345
- __privateGet$2(list, _items).sort((itemA, itemB) => compare(itemA[1], itemB[1]));
274
+ list._items.push([child, entry[1].parentKey]);
275
+ list._items.sort((itemA, itemB) => compare(itemA[1], itemB[1]));
346
276
  }
347
277
  return list;
348
278
  }
@@ -362,23 +292,23 @@ const _LiveList = class extends AbstractCrdt {
362
292
  parentKey
363
293
  };
364
294
  ops.push(op);
365
- for (const [value, key] of __privateGet$2(this, _items)) {
295
+ for (const [value, key] of this._items) {
366
296
  ops.push(...value._serialize(this._id, key, doc));
367
297
  }
368
298
  return ops;
369
299
  }
370
300
  _indexOfPosition(position) {
371
- return __privateGet$2(this, _items).findIndex((item) => item[1] === position);
301
+ return this._items.findIndex((item) => item[1] === position);
372
302
  }
373
303
  _attach(id, doc) {
374
304
  super._attach(id, doc);
375
- for (const [item] of __privateGet$2(this, _items)) {
305
+ for (const [item] of this._items) {
376
306
  item._attach(doc.generateId(), doc);
377
307
  }
378
308
  }
379
309
  _detach() {
380
310
  super._detach();
381
- for (const [value] of __privateGet$2(this, _items)) {
311
+ for (const [value] of this._items) {
382
312
  value._detach();
383
313
  }
384
314
  }
@@ -392,21 +322,21 @@ const _LiveList = class extends AbstractCrdt {
392
322
  }
393
323
  child._attach(id, this._doc);
394
324
  child._setParentLink(this, key);
395
- const index = __privateGet$2(this, _items).findIndex((entry) => entry[1] === key);
325
+ const index = this._items.findIndex((entry) => entry[1] === key);
396
326
  let newKey = key;
397
327
  if (index !== -1) {
398
328
  if (isLocal) {
399
- const before = __privateGet$2(this, _items)[index] ? __privateGet$2(this, _items)[index][1] : void 0;
400
- const after = __privateGet$2(this, _items)[index + 1] ? __privateGet$2(this, _items)[index + 1][1] : void 0;
329
+ let before = this._items[index] ? this._items[index][1] : void 0;
330
+ let after = this._items[index + 1] ? this._items[index + 1][1] : void 0;
401
331
  newKey = makePosition(before, after);
402
332
  child._setParentLink(this, newKey);
403
333
  } else {
404
- __privateGet$2(this, _items)[index][1] = makePosition(key, (_a = __privateGet$2(this, _items)[index + 1]) == null ? void 0 : _a[1]);
334
+ this._items[index][1] = makePosition(key, (_a = this._items[index + 1]) == null ? void 0 : _a[1]);
405
335
  }
406
336
  }
407
- __privateGet$2(this, _items).push([child, newKey]);
408
- __privateGet$2(this, _items).sort((itemA, itemB) => compare(itemA[1], itemB[1]));
409
- const newIndex = __privateGet$2(this, _items).findIndex((entry) => entry[1] === newKey);
337
+ this._items.push([child, newKey]);
338
+ this._items.sort((itemA, itemB) => compare(itemA[1], itemB[1]));
339
+ const newIndex = this._items.findIndex((entry) => entry[1] === newKey);
410
340
  return {
411
341
  reverse: [{ type: OpType.DeleteCrdt, id }],
412
342
  modified: {
@@ -425,8 +355,8 @@ const _LiveList = class extends AbstractCrdt {
425
355
  _detachChild(child) {
426
356
  if (child) {
427
357
  const reverse = child._serialize(this._id, child._parentKey, this._doc);
428
- const indexToDelete = __privateGet$2(this, _items).findIndex((item) => item[0] === child);
429
- __privateGet$2(this, _items).splice(indexToDelete, 1);
358
+ const indexToDelete = this._items.findIndex((item) => item[0] === child);
359
+ this._items.splice(indexToDelete, 1);
430
360
  child._detach();
431
361
  const storageUpdate = {
432
362
  node: this,
@@ -440,17 +370,17 @@ const _LiveList = class extends AbstractCrdt {
440
370
  _setChildKey(key, child, previousKey) {
441
371
  var _a;
442
372
  child._setParentLink(this, key);
443
- const previousIndex = __privateGet$2(this, _items).findIndex((entry) => entry[0]._id === child._id);
444
- const index = __privateGet$2(this, _items).findIndex((entry) => entry[1] === key);
373
+ const previousIndex = this._items.findIndex((entry) => entry[0]._id === child._id);
374
+ const index = this._items.findIndex((entry) => entry[1] === key);
445
375
  if (index !== -1) {
446
- __privateGet$2(this, _items)[index][1] = makePosition(key, (_a = __privateGet$2(this, _items)[index + 1]) == null ? void 0 : _a[1]);
376
+ this._items[index][1] = makePosition(key, (_a = this._items[index + 1]) == null ? void 0 : _a[1]);
447
377
  }
448
- const item = __privateGet$2(this, _items).find((item2) => item2[0] === child);
378
+ const item = this._items.find((item2) => item2[0] === child);
449
379
  if (item) {
450
380
  item[1] = key;
451
381
  }
452
- __privateGet$2(this, _items).sort((itemA, itemB) => compare(itemA[1], itemB[1]));
453
- const newIndex = __privateGet$2(this, _items).findIndex((entry) => entry[0]._id === child._id);
382
+ this._items.sort((itemA, itemB) => compare(itemA[1], itemB[1]));
383
+ const newIndex = this._items.findIndex((entry) => entry[0]._id === child._id);
454
384
  const updatesDelta = newIndex === previousIndex ? [] : [
455
385
  {
456
386
  index: newIndex,
@@ -486,23 +416,23 @@ const _LiveList = class extends AbstractCrdt {
486
416
  };
487
417
  }
488
418
  get length() {
489
- return __privateGet$2(this, _items).length;
419
+ return this._items.length;
490
420
  }
491
421
  push(element) {
492
422
  return this.insert(element, this.length);
493
423
  }
494
424
  insert(element, index) {
495
- if (index < 0 || index > __privateGet$2(this, _items).length) {
496
- throw new Error(`Cannot insert list item at index "${index}". index should be between 0 and ${__privateGet$2(this, _items).length}`);
425
+ if (index < 0 || index > this._items.length) {
426
+ throw new Error(`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`);
497
427
  }
498
- const before = __privateGet$2(this, _items)[index - 1] ? __privateGet$2(this, _items)[index - 1][1] : void 0;
499
- const after = __privateGet$2(this, _items)[index] ? __privateGet$2(this, _items)[index][1] : void 0;
428
+ const before = this._items[index - 1] ? this._items[index - 1][1] : void 0;
429
+ const after = this._items[index] ? this._items[index][1] : void 0;
500
430
  const position = makePosition(before, after);
501
431
  const value = selfOrRegister(element);
502
432
  value._setParentLink(this, position);
503
- __privateGet$2(this, _items).push([value, position]);
504
- __privateGet$2(this, _items).sort((itemA, itemB) => compare(itemA[1], itemB[1]));
505
- const newIndex = __privateGet$2(this, _items).findIndex((entry) => entry[1] === position);
433
+ this._items.push([value, position]);
434
+ this._items.sort((itemA, itemB) => compare(itemA[1], itemB[1]));
435
+ const newIndex = this._items.findIndex((entry) => entry[1] === position);
506
436
  if (this._doc && this._id) {
507
437
  const id = this._doc.generateId();
508
438
  value._attach(id, this._doc);
@@ -525,31 +455,31 @@ const _LiveList = class extends AbstractCrdt {
525
455
  if (targetIndex < 0) {
526
456
  throw new Error("targetIndex cannot be less than 0");
527
457
  }
528
- if (targetIndex >= __privateGet$2(this, _items).length) {
458
+ if (targetIndex >= this._items.length) {
529
459
  throw new Error("targetIndex cannot be greater or equal than the list length");
530
460
  }
531
461
  if (index < 0) {
532
462
  throw new Error("index cannot be less than 0");
533
463
  }
534
- if (index >= __privateGet$2(this, _items).length) {
464
+ if (index >= this._items.length) {
535
465
  throw new Error("index cannot be greater or equal than the list length");
536
466
  }
537
467
  let beforePosition = null;
538
468
  let afterPosition = null;
539
469
  if (index < targetIndex) {
540
- afterPosition = targetIndex === __privateGet$2(this, _items).length - 1 ? void 0 : __privateGet$2(this, _items)[targetIndex + 1][1];
541
- beforePosition = __privateGet$2(this, _items)[targetIndex][1];
470
+ afterPosition = targetIndex === this._items.length - 1 ? void 0 : this._items[targetIndex + 1][1];
471
+ beforePosition = this._items[targetIndex][1];
542
472
  } else {
543
- afterPosition = __privateGet$2(this, _items)[targetIndex][1];
544
- beforePosition = targetIndex === 0 ? void 0 : __privateGet$2(this, _items)[targetIndex - 1][1];
473
+ afterPosition = this._items[targetIndex][1];
474
+ beforePosition = targetIndex === 0 ? void 0 : this._items[targetIndex - 1][1];
545
475
  }
546
476
  const position = makePosition(beforePosition, afterPosition);
547
- const item = __privateGet$2(this, _items)[index];
477
+ const item = this._items[index];
548
478
  const previousPosition = item[1];
549
479
  item[1] = position;
550
480
  item[0]._setParentLink(this, position);
551
- __privateGet$2(this, _items).sort((itemA, itemB) => compare(itemA[1], itemB[1]));
552
- const newIndex = __privateGet$2(this, _items).findIndex((entry) => entry[1] === position);
481
+ this._items.sort((itemA, itemB) => compare(itemA[1], itemB[1]));
482
+ const newIndex = this._items.findIndex((entry) => entry[1] === position);
553
483
  if (this._doc && this._id) {
554
484
  const storageUpdates = /* @__PURE__ */ new Map();
555
485
  storageUpdates.set(this._id, {
@@ -581,12 +511,12 @@ const _LiveList = class extends AbstractCrdt {
581
511
  }
582
512
  }
583
513
  delete(index) {
584
- if (index < 0 || index >= __privateGet$2(this, _items).length) {
585
- throw new Error(`Cannot delete list item at index "${index}". index should be between 0 and ${__privateGet$2(this, _items).length - 1}`);
514
+ if (index < 0 || index >= this._items.length) {
515
+ throw new Error(`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`);
586
516
  }
587
- const item = __privateGet$2(this, _items)[index];
517
+ const item = this._items[index];
588
518
  item[0]._detach();
589
- __privateGet$2(this, _items).splice(index, 1);
519
+ this._items.splice(index, 1);
590
520
  if (this._doc) {
591
521
  const childRecordId = item[0]._id;
592
522
  if (childRecordId) {
@@ -612,7 +542,7 @@ const _LiveList = class extends AbstractCrdt {
612
542
  const reverseOps = [];
613
543
  const updateDelta = [];
614
544
  let i = 0;
615
- for (const item of __privateGet$2(this, _items)) {
545
+ for (const item of this._items) {
616
546
  item[0]._detach();
617
547
  const childId = item[0]._id;
618
548
  if (childId) {
@@ -622,7 +552,7 @@ const _LiveList = class extends AbstractCrdt {
622
552
  }
623
553
  i++;
624
554
  }
625
- __privateSet$2(this, _items, []);
555
+ this._items = [];
626
556
  const storageUpdates = /* @__PURE__ */ new Map();
627
557
  storageUpdates.set(this._id, {
628
558
  node: this,
@@ -631,14 +561,14 @@ const _LiveList = class extends AbstractCrdt {
631
561
  });
632
562
  this._doc.dispatch(ops, reverseOps, storageUpdates);
633
563
  } else {
634
- for (const item of __privateGet$2(this, _items)) {
564
+ for (const item of this._items) {
635
565
  item[0]._detach();
636
566
  }
637
- __privateSet$2(this, _items, []);
567
+ this._items = [];
638
568
  }
639
569
  }
640
570
  toArray() {
641
- return __privateGet$2(this, _items).map((entry) => selfOrRegisterValue(entry[0]));
571
+ return this._items.map((entry) => selfOrRegisterValue(entry[0]));
642
572
  }
643
573
  every(predicate) {
644
574
  return this.toArray().every(predicate);
@@ -656,10 +586,10 @@ const _LiveList = class extends AbstractCrdt {
656
586
  return this.toArray().forEach(callbackfn);
657
587
  }
658
588
  get(index) {
659
- if (index < 0 || index >= __privateGet$2(this, _items).length) {
589
+ if (index < 0 || index >= this._items.length) {
660
590
  return void 0;
661
591
  }
662
- return selfOrRegisterValue(__privateGet$2(this, _items)[index][0]);
592
+ return selfOrRegisterValue(this._items[index][0]);
663
593
  }
664
594
  indexOf(searchElement, fromIndex) {
665
595
  return this.toArray().indexOf(searchElement, fromIndex);
@@ -668,27 +598,24 @@ const _LiveList = class extends AbstractCrdt {
668
598
  return this.toArray().lastIndexOf(searchElement, fromIndex);
669
599
  }
670
600
  map(callback) {
671
- return __privateGet$2(this, _items).map((entry, i) => callback(selfOrRegisterValue(entry[0]), i));
601
+ return this._items.map((entry, i) => callback(selfOrRegisterValue(entry[0]), i));
672
602
  }
673
603
  some(predicate) {
674
604
  return this.toArray().some(predicate);
675
605
  }
676
606
  [Symbol.iterator]() {
677
- return new LiveListIterator(__privateGet$2(this, _items));
607
+ return new LiveListIterator(this._items);
678
608
  }
679
- };
680
- let LiveList = _LiveList;
681
- _items = new WeakMap();
609
+ }
682
610
  class LiveListIterator {
683
611
  constructor(items) {
684
- __privateAdd$2(this, _innerIterator, void 0);
685
- __privateSet$2(this, _innerIterator, items[Symbol.iterator]());
612
+ this._innerIterator = items[Symbol.iterator]();
686
613
  }
687
614
  [Symbol.iterator]() {
688
615
  return this;
689
616
  }
690
617
  next() {
691
- const result = __privateGet$2(this, _innerIterator).next();
618
+ const result = this._innerIterator.next();
692
619
  if (result.done) {
693
620
  return {
694
621
  done: true,
@@ -700,31 +627,10 @@ class LiveListIterator {
700
627
  };
701
628
  }
702
629
  }
703
- _innerIterator = new WeakMap();
704
630
 
705
- var __accessCheck$1 = (obj, member, msg) => {
706
- if (!member.has(obj))
707
- throw TypeError("Cannot " + msg);
708
- };
709
- var __privateGet$1 = (obj, member, getter) => {
710
- __accessCheck$1(obj, member, "read from private field");
711
- return getter ? getter.call(obj) : member.get(obj);
712
- };
713
- var __privateAdd$1 = (obj, member, value) => {
714
- if (member.has(obj))
715
- throw TypeError("Cannot add the same private member more than once");
716
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
717
- };
718
- var __privateSet$1 = (obj, member, value, setter) => {
719
- __accessCheck$1(obj, member, "write to private field");
720
- setter ? setter.call(obj, value) : member.set(obj, value);
721
- return value;
722
- };
723
- var _map$1;
724
- const _LiveMap = class extends AbstractCrdt {
631
+ class LiveMap extends AbstractCrdt {
725
632
  constructor(entries) {
726
633
  super();
727
- __privateAdd$1(this, _map$1, void 0);
728
634
  if (entries) {
729
635
  const mappedEntries = [];
730
636
  for (const entry of entries) {
@@ -732,9 +638,9 @@ const _LiveMap = class extends AbstractCrdt {
732
638
  value._setParentLink(this, entry[0]);
733
639
  mappedEntries.push([entry[0], value]);
734
640
  }
735
- __privateSet$1(this, _map$1, new Map(mappedEntries));
641
+ this._map = new Map(mappedEntries);
736
642
  } else {
737
- __privateSet$1(this, _map$1, /* @__PURE__ */ new Map());
643
+ this._map = /* @__PURE__ */ new Map();
738
644
  }
739
645
  }
740
646
  _serialize(parentId, parentKey, doc) {
@@ -753,7 +659,7 @@ const _LiveMap = class extends AbstractCrdt {
753
659
  parentKey
754
660
  };
755
661
  ops.push(op);
756
- for (const [key, value] of __privateGet$1(this, _map$1)) {
662
+ for (const [key, value] of this._map) {
757
663
  ops.push(...value._serialize(this._id, key, doc));
758
664
  }
759
665
  return ops;
@@ -762,7 +668,7 @@ const _LiveMap = class extends AbstractCrdt {
762
668
  if (item.type !== CrdtType.Map) {
763
669
  throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
764
670
  }
765
- const map = new _LiveMap();
671
+ const map = new LiveMap();
766
672
  map._attach(id, doc);
767
673
  const children = parentToChildren.get(id);
768
674
  if (children == null) {
@@ -775,13 +681,13 @@ const _LiveMap = class extends AbstractCrdt {
775
681
  }
776
682
  const child = deserialize(entry, parentToChildren, doc);
777
683
  child._setParentLink(map, crdt.parentKey);
778
- __privateGet$1(map, _map$1).set(crdt.parentKey, child);
684
+ map._map.set(crdt.parentKey, child);
779
685
  }
780
686
  return map;
781
687
  }
782
688
  _attach(id, doc) {
783
689
  super._attach(id, doc);
784
- for (const [_key, value] of __privateGet$1(this, _map$1)) {
690
+ for (const [_key, value] of this._map) {
785
691
  if (isCrdt(value)) {
786
692
  value._attach(doc.generateId(), doc);
787
693
  }
@@ -794,7 +700,7 @@ const _LiveMap = class extends AbstractCrdt {
794
700
  if (this._doc.getItem(id) !== void 0) {
795
701
  return { modified: false };
796
702
  }
797
- const previousValue = __privateGet$1(this, _map$1).get(key);
703
+ const previousValue = this._map.get(key);
798
704
  let reverse;
799
705
  if (previousValue) {
800
706
  reverse = previousValue._serialize(this._id, key);
@@ -804,7 +710,7 @@ const _LiveMap = class extends AbstractCrdt {
804
710
  }
805
711
  child._setParentLink(this, key);
806
712
  child._attach(id, this._doc);
807
- __privateGet$1(this, _map$1).set(key, child);
713
+ this._map.set(key, child);
808
714
  return {
809
715
  modified: {
810
716
  node: this,
@@ -816,15 +722,15 @@ const _LiveMap = class extends AbstractCrdt {
816
722
  }
817
723
  _detach() {
818
724
  super._detach();
819
- for (const item of __privateGet$1(this, _map$1).values()) {
725
+ for (const item of this._map.values()) {
820
726
  item._detach();
821
727
  }
822
728
  }
823
729
  _detachChild(child) {
824
730
  const reverse = child._serialize(this._id, child._parentKey, this._doc);
825
- for (const [key, value] of __privateGet$1(this, _map$1)) {
731
+ for (const [key, value] of this._map) {
826
732
  if (value === child) {
827
- __privateGet$1(this, _map$1).delete(key);
733
+ this._map.delete(key);
828
734
  }
829
735
  }
830
736
  child._detach();
@@ -844,20 +750,20 @@ const _LiveMap = class extends AbstractCrdt {
844
750
  };
845
751
  }
846
752
  get(key) {
847
- const value = __privateGet$1(this, _map$1).get(key);
753
+ const value = this._map.get(key);
848
754
  if (value == void 0) {
849
755
  return void 0;
850
756
  }
851
757
  return selfOrRegisterValue(value);
852
758
  }
853
759
  set(key, value) {
854
- const oldValue = __privateGet$1(this, _map$1).get(key);
760
+ const oldValue = this._map.get(key);
855
761
  if (oldValue) {
856
762
  oldValue._detach();
857
763
  }
858
764
  const item = selfOrRegister(value);
859
765
  item._setParentLink(this, key);
860
- __privateGet$1(this, _map$1).set(key, item);
766
+ this._map.set(key, item);
861
767
  if (this._doc && this._id) {
862
768
  const id = this._doc.generateId();
863
769
  item._attach(id, this._doc);
@@ -871,18 +777,18 @@ const _LiveMap = class extends AbstractCrdt {
871
777
  }
872
778
  }
873
779
  get size() {
874
- return __privateGet$1(this, _map$1).size;
780
+ return this._map.size;
875
781
  }
876
782
  has(key) {
877
- return __privateGet$1(this, _map$1).has(key);
783
+ return this._map.has(key);
878
784
  }
879
785
  delete(key) {
880
- const item = __privateGet$1(this, _map$1).get(key);
786
+ const item = this._map.get(key);
881
787
  if (item == null) {
882
788
  return false;
883
789
  }
884
790
  item._detach();
885
- __privateGet$1(this, _map$1).delete(key);
791
+ this._map.delete(key);
886
792
  if (this._doc && item._id) {
887
793
  const storageUpdates = /* @__PURE__ */ new Map();
888
794
  storageUpdates.set(this._id, {
@@ -901,7 +807,7 @@ const _LiveMap = class extends AbstractCrdt {
901
807
  return true;
902
808
  }
903
809
  entries() {
904
- const innerIterator = __privateGet$1(this, _map$1).entries();
810
+ const innerIterator = this._map.entries();
905
811
  return {
906
812
  [Symbol.iterator]: function() {
907
813
  return this;
@@ -925,10 +831,10 @@ const _LiveMap = class extends AbstractCrdt {
925
831
  return this.entries();
926
832
  }
927
833
  keys() {
928
- return __privateGet$1(this, _map$1).keys();
834
+ return this._map.keys();
929
835
  }
930
836
  values() {
931
- const innerIterator = __privateGet$1(this, _map$1).values();
837
+ const innerIterator = this._map.values();
932
838
  return {
933
839
  [Symbol.iterator]: function() {
934
840
  return this;
@@ -952,9 +858,7 @@ const _LiveMap = class extends AbstractCrdt {
952
858
  callback(entry[1], entry[0], this);
953
859
  }
954
860
  }
955
- };
956
- let LiveMap = _LiveMap;
957
- _map$1 = new WeakMap();
861
+ }
958
862
 
959
863
  var __defProp$2 = Object.defineProperty;
960
864
  var __defProps$2 = Object.defineProperties;
@@ -1170,44 +1074,36 @@ function findNonSerializableValue(value, path = "") {
1170
1074
  }
1171
1075
  return false;
1172
1076
  }
1077
+ function isTokenValid(token) {
1078
+ if (token === null) {
1079
+ return false;
1080
+ }
1081
+ const tokenParts = token.split(".");
1082
+ if (tokenParts.length !== 3) {
1083
+ return false;
1084
+ }
1085
+ const data = JSON.parse(atob(tokenParts[1]));
1086
+ if (typeof data.exp !== "number") {
1087
+ return false;
1088
+ }
1089
+ const now = Date.now();
1090
+ if (now / 1e3 > data.exp - 300) {
1091
+ return false;
1092
+ }
1093
+ return true;
1094
+ }
1173
1095
 
1174
- var __accessCheck = (obj, member, msg) => {
1175
- if (!member.has(obj))
1176
- throw TypeError("Cannot " + msg);
1177
- };
1178
- var __privateGet = (obj, member, getter) => {
1179
- __accessCheck(obj, member, "read from private field");
1180
- return getter ? getter.call(obj) : member.get(obj);
1181
- };
1182
- var __privateAdd = (obj, member, value) => {
1183
- if (member.has(obj))
1184
- throw TypeError("Cannot add the same private member more than once");
1185
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1186
- };
1187
- var __privateSet = (obj, member, value, setter) => {
1188
- __accessCheck(obj, member, "write to private field");
1189
- setter ? setter.call(obj, value) : member.set(obj, value);
1190
- return value;
1191
- };
1192
- var __privateMethod = (obj, member, method) => {
1193
- __accessCheck(obj, member, "access private method");
1194
- return method;
1195
- };
1196
- var _map, _propToLastUpdate, _applyUpdate, applyUpdate_fn, _applyDeleteObjectKey, applyDeleteObjectKey_fn;
1197
- const _LiveObject = class extends AbstractCrdt {
1096
+ class LiveObject extends AbstractCrdt {
1198
1097
  constructor(object = {}) {
1199
1098
  super();
1200
- __privateAdd(this, _applyUpdate);
1201
- __privateAdd(this, _applyDeleteObjectKey);
1202
- __privateAdd(this, _map, void 0);
1203
- __privateAdd(this, _propToLastUpdate, /* @__PURE__ */ new Map());
1099
+ this._propToLastUpdate = /* @__PURE__ */ new Map();
1204
1100
  for (const key in object) {
1205
1101
  const value = object[key];
1206
1102
  if (value instanceof AbstractCrdt) {
1207
1103
  value._setParentLink(this, key);
1208
1104
  }
1209
1105
  }
1210
- __privateSet(this, _map, new Map(Object.entries(object)));
1106
+ this._map = new Map(Object.entries(object));
1211
1107
  }
1212
1108
  _serialize(parentId, parentKey, doc) {
1213
1109
  if (this._id == null) {
@@ -1223,7 +1119,7 @@ const _LiveObject = class extends AbstractCrdt {
1223
1119
  data: {}
1224
1120
  };
1225
1121
  ops.push(op);
1226
- for (const [key, value] of __privateGet(this, _map)) {
1122
+ for (const [key, value] of this._map) {
1227
1123
  if (value instanceof AbstractCrdt) {
1228
1124
  ops.push(...value._serialize(this._id, key, doc));
1229
1125
  } else {
@@ -1236,7 +1132,7 @@ const _LiveObject = class extends AbstractCrdt {
1236
1132
  if (item.type !== CrdtType.Object) {
1237
1133
  throw new Error(`Tried to deserialize a record but item type is "${item.type}"`);
1238
1134
  }
1239
- const object = new _LiveObject(item.data);
1135
+ const object = new LiveObject(item.data);
1240
1136
  object._attach(id, doc);
1241
1137
  return this._deserializeChildren(object, parentToChildren, doc);
1242
1138
  }
@@ -1252,13 +1148,13 @@ const _LiveObject = class extends AbstractCrdt {
1252
1148
  }
1253
1149
  const child = deserialize(entry, parentToChildren, doc);
1254
1150
  child._setParentLink(object, crdt.parentKey);
1255
- __privateGet(object, _map).set(crdt.parentKey, child);
1151
+ object._map.set(crdt.parentKey, child);
1256
1152
  }
1257
1153
  return object;
1258
1154
  }
1259
1155
  _attach(id, doc) {
1260
1156
  super._attach(id, doc);
1261
- for (const [_key, value] of __privateGet(this, _map)) {
1157
+ for (const [_key, value] of this._map) {
1262
1158
  if (value instanceof AbstractCrdt) {
1263
1159
  value._attach(doc.generateId(), doc);
1264
1160
  }
@@ -1269,20 +1165,20 @@ const _LiveObject = class extends AbstractCrdt {
1269
1165
  throw new Error("Can't attach child if doc is not present");
1270
1166
  }
1271
1167
  if (this._doc.getItem(id) !== void 0) {
1272
- if (__privateGet(this, _propToLastUpdate).get(key) === opId) {
1273
- __privateGet(this, _propToLastUpdate).delete(key);
1168
+ if (this._propToLastUpdate.get(key) === opId) {
1169
+ this._propToLastUpdate.delete(key);
1274
1170
  }
1275
1171
  return { modified: false };
1276
1172
  }
1277
1173
  if (isLocal) {
1278
- __privateGet(this, _propToLastUpdate).set(key, opId);
1279
- } else if (__privateGet(this, _propToLastUpdate).get(key) === void 0) ; else if (__privateGet(this, _propToLastUpdate).get(key) === opId) {
1280
- __privateGet(this, _propToLastUpdate).delete(key);
1174
+ this._propToLastUpdate.set(key, opId);
1175
+ } else if (this._propToLastUpdate.get(key) === void 0) ; else if (this._propToLastUpdate.get(key) === opId) {
1176
+ this._propToLastUpdate.delete(key);
1281
1177
  return { modified: false };
1282
1178
  } else {
1283
1179
  return { modified: false };
1284
1180
  }
1285
- const previousValue = __privateGet(this, _map).get(key);
1181
+ const previousValue = this._map.get(key);
1286
1182
  let reverse;
1287
1183
  if (isCrdt(previousValue)) {
1288
1184
  reverse = previousValue._serialize(this._id, key);
@@ -1300,7 +1196,7 @@ const _LiveObject = class extends AbstractCrdt {
1300
1196
  }
1301
1197
  ];
1302
1198
  }
1303
- __privateGet(this, _map).set(key, child);
1199
+ this._map.set(key, child);
1304
1200
  child._setParentLink(this, key);
1305
1201
  child._attach(id, this._doc);
1306
1202
  return {
@@ -1315,9 +1211,9 @@ const _LiveObject = class extends AbstractCrdt {
1315
1211
  _detachChild(child) {
1316
1212
  if (child) {
1317
1213
  const reverse = child._serialize(this._id, child._parentKey, this._doc);
1318
- for (const [key, value] of __privateGet(this, _map)) {
1214
+ for (const [key, value] of this._map) {
1319
1215
  if (value === child) {
1320
- __privateGet(this, _map).delete(key);
1216
+ this._map.delete(key);
1321
1217
  }
1322
1218
  }
1323
1219
  child._detach();
@@ -1333,14 +1229,14 @@ const _LiveObject = class extends AbstractCrdt {
1333
1229
  return { modified: false };
1334
1230
  }
1335
1231
  _detachChildren() {
1336
- for (const [key, value] of __privateGet(this, _map)) {
1337
- __privateGet(this, _map).delete(key);
1232
+ for (const [key, value] of this._map) {
1233
+ this._map.delete(key);
1338
1234
  value._detach();
1339
1235
  }
1340
1236
  }
1341
1237
  _detach() {
1342
1238
  super._detach();
1343
- for (const value of __privateGet(this, _map).values()) {
1239
+ for (const value of this._map.values()) {
1344
1240
  if (isCrdt(value)) {
1345
1241
  value._detach();
1346
1242
  }
@@ -1348,33 +1244,123 @@ const _LiveObject = class extends AbstractCrdt {
1348
1244
  }
1349
1245
  _apply(op, isLocal) {
1350
1246
  if (op.type === OpType.UpdateObject) {
1351
- return __privateMethod(this, _applyUpdate, applyUpdate_fn).call(this, op, isLocal);
1247
+ return this._applyUpdate(op, isLocal);
1352
1248
  } else if (op.type === OpType.DeleteObjectKey) {
1353
- return __privateMethod(this, _applyDeleteObjectKey, applyDeleteObjectKey_fn).call(this, op);
1249
+ return this._applyDeleteObjectKey(op);
1354
1250
  }
1355
1251
  return super._apply(op, isLocal);
1356
1252
  }
1357
1253
  _toSerializedCrdt() {
1358
1254
  var _a;
1255
+ const data = {};
1256
+ for (const [key, value] of this._map) {
1257
+ if (value instanceof AbstractCrdt === false) {
1258
+ data[key] = value;
1259
+ }
1260
+ }
1359
1261
  return {
1360
1262
  type: CrdtType.Object,
1361
1263
  parentId: (_a = this._parent) == null ? void 0 : _a._id,
1362
1264
  parentKey: this._parentKey,
1363
- data: this.toObject()
1265
+ data
1266
+ };
1267
+ }
1268
+ _applyUpdate(op, isLocal) {
1269
+ let isModified = false;
1270
+ const reverse = [];
1271
+ const reverseUpdate = {
1272
+ type: OpType.UpdateObject,
1273
+ id: this._id,
1274
+ data: {}
1275
+ };
1276
+ reverse.push(reverseUpdate);
1277
+ for (const key in op.data) {
1278
+ const oldValue = this._map.get(key);
1279
+ if (oldValue instanceof AbstractCrdt) {
1280
+ reverse.push(...oldValue._serialize(this._id, key));
1281
+ oldValue._detach();
1282
+ } else if (oldValue !== void 0) {
1283
+ reverseUpdate.data[key] = oldValue;
1284
+ } else if (oldValue === void 0) {
1285
+ reverse.push({ type: OpType.DeleteObjectKey, id: this._id, key });
1286
+ }
1287
+ }
1288
+ const updateDelta = {};
1289
+ for (const key in op.data) {
1290
+ if (isLocal) {
1291
+ this._propToLastUpdate.set(key, op.opId);
1292
+ } else if (this._propToLastUpdate.get(key) == null) {
1293
+ isModified = true;
1294
+ } else if (this._propToLastUpdate.get(key) === op.opId) {
1295
+ this._propToLastUpdate.delete(key);
1296
+ continue;
1297
+ } else {
1298
+ continue;
1299
+ }
1300
+ const oldValue = this._map.get(key);
1301
+ if (isCrdt(oldValue)) {
1302
+ oldValue._detach();
1303
+ }
1304
+ isModified = true;
1305
+ updateDelta[key] = { type: "update" };
1306
+ this._map.set(key, op.data[key]);
1307
+ }
1308
+ if (Object.keys(reverseUpdate.data).length !== 0) {
1309
+ reverse.unshift(reverseUpdate);
1310
+ }
1311
+ return isModified ? {
1312
+ modified: {
1313
+ node: this,
1314
+ type: "LiveObject",
1315
+ updates: updateDelta
1316
+ },
1317
+ reverse
1318
+ } : { modified: false };
1319
+ }
1320
+ _applyDeleteObjectKey(op) {
1321
+ const key = op.key;
1322
+ if (this._map.has(key) === false) {
1323
+ return { modified: false };
1324
+ }
1325
+ if (this._propToLastUpdate.get(key) !== void 0) {
1326
+ return { modified: false };
1327
+ }
1328
+ const oldValue = this._map.get(key);
1329
+ let reverse = [];
1330
+ if (isCrdt(oldValue)) {
1331
+ reverse = oldValue._serialize(this._id, op.key);
1332
+ oldValue._detach();
1333
+ } else if (oldValue !== void 0) {
1334
+ reverse = [
1335
+ {
1336
+ type: OpType.UpdateObject,
1337
+ id: this._id,
1338
+ data: { [key]: oldValue }
1339
+ }
1340
+ ];
1341
+ }
1342
+ this._map.delete(key);
1343
+ return {
1344
+ modified: {
1345
+ node: this,
1346
+ type: "LiveObject",
1347
+ updates: { [op.key]: { type: "delete" } }
1348
+ },
1349
+ reverse
1364
1350
  };
1365
1351
  }
1366
1352
  toObject() {
1367
- return Object.fromEntries(__privateGet(this, _map));
1353
+ return Object.fromEntries(this._map);
1368
1354
  }
1369
1355
  set(key, value) {
1370
1356
  this.update({ [key]: value });
1371
1357
  }
1372
1358
  get(key) {
1373
- return __privateGet(this, _map).get(key);
1359
+ return this._map.get(key);
1374
1360
  }
1375
1361
  delete(key) {
1376
1362
  const keyAsString = key;
1377
- const oldValue = __privateGet(this, _map).get(keyAsString);
1363
+ const oldValue = this._map.get(keyAsString);
1378
1364
  if (oldValue === void 0) {
1379
1365
  return;
1380
1366
  }
@@ -1382,7 +1368,7 @@ const _LiveObject = class extends AbstractCrdt {
1382
1368
  if (oldValue instanceof AbstractCrdt) {
1383
1369
  oldValue._detach();
1384
1370
  }
1385
- __privateGet(this, _map).delete(keyAsString);
1371
+ this._map.delete(keyAsString);
1386
1372
  return;
1387
1373
  }
1388
1374
  let reverse;
@@ -1398,7 +1384,7 @@ const _LiveObject = class extends AbstractCrdt {
1398
1384
  }
1399
1385
  ];
1400
1386
  }
1401
- __privateGet(this, _map).delete(keyAsString);
1387
+ this._map.delete(keyAsString);
1402
1388
  const storageUpdates = /* @__PURE__ */ new Map();
1403
1389
  storageUpdates.set(this._id, {
1404
1390
  node: this,
@@ -1417,7 +1403,7 @@ const _LiveObject = class extends AbstractCrdt {
1417
1403
  update(overrides) {
1418
1404
  if (this._doc == null || this._id == null) {
1419
1405
  for (const key in overrides) {
1420
- const oldValue = __privateGet(this, _map).get(key);
1406
+ const oldValue = this._map.get(key);
1421
1407
  if (oldValue instanceof AbstractCrdt) {
1422
1408
  oldValue._detach();
1423
1409
  }
@@ -1425,7 +1411,7 @@ const _LiveObject = class extends AbstractCrdt {
1425
1411
  if (newValue instanceof AbstractCrdt) {
1426
1412
  newValue._setParentLink(this, key);
1427
1413
  }
1428
- __privateGet(this, _map).set(key, newValue);
1414
+ this._map.set(key, newValue);
1429
1415
  }
1430
1416
  return;
1431
1417
  }
@@ -1440,7 +1426,7 @@ const _LiveObject = class extends AbstractCrdt {
1440
1426
  };
1441
1427
  const updateDelta = {};
1442
1428
  for (const key in overrides) {
1443
- const oldValue = __privateGet(this, _map).get(key);
1429
+ const oldValue = this._map.get(key);
1444
1430
  if (oldValue instanceof AbstractCrdt) {
1445
1431
  reverseOps.push(...oldValue._serialize(this._id, key));
1446
1432
  oldValue._detach();
@@ -1456,14 +1442,14 @@ const _LiveObject = class extends AbstractCrdt {
1456
1442
  const newAttachChildOps = newValue._serialize(this._id, key, this._doc);
1457
1443
  const createCrdtOp = newAttachChildOps.find((op) => op.parentId === this._id);
1458
1444
  if (createCrdtOp) {
1459
- __privateGet(this, _propToLastUpdate).set(key, createCrdtOp.opId);
1445
+ this._propToLastUpdate.set(key, createCrdtOp.opId);
1460
1446
  }
1461
1447
  ops.push(...newAttachChildOps);
1462
1448
  } else {
1463
1449
  updatedProps[key] = newValue;
1464
- __privateGet(this, _propToLastUpdate).set(key, opId);
1450
+ this._propToLastUpdate.set(key, opId);
1465
1451
  }
1466
- __privateGet(this, _map).set(key, newValue);
1452
+ this._map.set(key, newValue);
1467
1453
  updateDelta[key] = { type: "update" };
1468
1454
  }
1469
1455
  if (Object.keys(reverseUpdateOp.data).length !== 0) {
@@ -1485,96 +1471,7 @@ const _LiveObject = class extends AbstractCrdt {
1485
1471
  });
1486
1472
  this._doc.dispatch(ops, reverseOps, storageUpdates);
1487
1473
  }
1488
- };
1489
- let LiveObject = _LiveObject;
1490
- _map = new WeakMap();
1491
- _propToLastUpdate = new WeakMap();
1492
- _applyUpdate = new WeakSet();
1493
- applyUpdate_fn = function(op, isLocal) {
1494
- let isModified = false;
1495
- const reverse = [];
1496
- const reverseUpdate = {
1497
- type: OpType.UpdateObject,
1498
- id: this._id,
1499
- data: {}
1500
- };
1501
- reverse.push(reverseUpdate);
1502
- for (const key in op.data) {
1503
- const oldValue = __privateGet(this, _map).get(key);
1504
- if (oldValue instanceof AbstractCrdt) {
1505
- reverse.push(...oldValue._serialize(this._id, key));
1506
- oldValue._detach();
1507
- } else if (oldValue !== void 0) {
1508
- reverseUpdate.data[key] = oldValue;
1509
- } else if (oldValue === void 0) {
1510
- reverse.push({ type: OpType.DeleteObjectKey, id: this._id, key });
1511
- }
1512
- }
1513
- const updateDelta = {};
1514
- for (const key in op.data) {
1515
- if (isLocal) {
1516
- __privateGet(this, _propToLastUpdate).set(key, op.opId);
1517
- } else if (__privateGet(this, _propToLastUpdate).get(key) == null) {
1518
- isModified = true;
1519
- } else if (__privateGet(this, _propToLastUpdate).get(key) === op.opId) {
1520
- __privateGet(this, _propToLastUpdate).delete(key);
1521
- continue;
1522
- } else {
1523
- continue;
1524
- }
1525
- const oldValue = __privateGet(this, _map).get(key);
1526
- if (isCrdt(oldValue)) {
1527
- oldValue._detach();
1528
- }
1529
- isModified = true;
1530
- updateDelta[key] = { type: "update" };
1531
- __privateGet(this, _map).set(key, op.data[key]);
1532
- }
1533
- if (Object.keys(reverseUpdate.data).length !== 0) {
1534
- reverse.unshift(reverseUpdate);
1535
- }
1536
- return isModified ? {
1537
- modified: {
1538
- node: this,
1539
- type: "LiveObject",
1540
- updates: updateDelta
1541
- },
1542
- reverse
1543
- } : { modified: false };
1544
- };
1545
- _applyDeleteObjectKey = new WeakSet();
1546
- applyDeleteObjectKey_fn = function(op) {
1547
- const key = op.key;
1548
- if (__privateGet(this, _map).has(key) === false) {
1549
- return { modified: false };
1550
- }
1551
- if (__privateGet(this, _propToLastUpdate).get(key) !== void 0) {
1552
- return { modified: false };
1553
- }
1554
- const oldValue = __privateGet(this, _map).get(key);
1555
- let reverse = [];
1556
- if (isCrdt(oldValue)) {
1557
- reverse = oldValue._serialize(this._id, op.key);
1558
- oldValue._detach();
1559
- } else if (oldValue !== void 0) {
1560
- reverse = [
1561
- {
1562
- type: OpType.UpdateObject,
1563
- id: this._id,
1564
- data: { [key]: oldValue }
1565
- }
1566
- ];
1567
- }
1568
- __privateGet(this, _map).delete(key);
1569
- return {
1570
- modified: {
1571
- node: this,
1572
- type: "LiveObject",
1573
- updates: { [op.key]: { type: "delete" } }
1574
- },
1575
- reverse
1576
- };
1577
- };
1474
+ }
1578
1475
 
1579
1476
  var __defProp$1 = Object.defineProperty;
1580
1477
  var __defProps$1 = Object.defineProperties;
@@ -1641,14 +1538,21 @@ function makeOthers(userMap) {
1641
1538
  function makeStateMachine(state, context, mockedEffects) {
1642
1539
  const effects = mockedEffects || {
1643
1540
  authenticate(auth, createWebSocket) {
1644
- return auth(context.room).then(({ token }) => {
1645
- if (state.connection.state !== "authenticating") {
1646
- return;
1647
- }
1648
- const parsedToken = parseToken(token);
1649
- const socket = createWebSocket(token);
1541
+ if (isTokenValid(state.token)) {
1542
+ const parsedToken = parseToken(state.token);
1543
+ const socket = createWebSocket(state.token);
1650
1544
  authenticationSuccess(parsedToken, socket);
1651
- }).catch((er) => authenticationFailure(er));
1545
+ } else {
1546
+ return auth(context.room).then(({ token }) => {
1547
+ if (state.connection.state !== "authenticating") {
1548
+ return;
1549
+ }
1550
+ const parsedToken = parseToken(token);
1551
+ const socket = createWebSocket(token);
1552
+ authenticationSuccess(parsedToken, socket);
1553
+ state.token = token;
1554
+ }).catch((er) => authenticationFailure(er));
1555
+ }
1652
1556
  },
1653
1557
  send(messageOrMessages) {
1654
1558
  if (state.socket == null) {
@@ -2006,6 +1910,7 @@ See v0.13 release notes for more information.
2006
1910
  if (process.env.NODE_ENV !== "production") {
2007
1911
  console.error("Call to authentication endpoint failed", error);
2008
1912
  }
1913
+ state.token = null;
2009
1914
  updateConnection({ state: "unavailable" });
2010
1915
  state.numberOfRetry++;
2011
1916
  state.timeoutHandles.reconnect = effects.scheduleReconnect(getRetryDelay());
@@ -2136,8 +2041,9 @@ See v0.13 release notes for more information.
2136
2041
  break;
2137
2042
  }
2138
2043
  case ServerMessageType.InitialStorageState: {
2044
+ const offlineOps = new Map(state.offlineOperations);
2139
2045
  createOrUpdateRootFromMessage(subMessage);
2140
- applyAndSendOfflineOps();
2046
+ applyAndSendOfflineOps(offlineOps);
2141
2047
  _getInitialStateResolver == null ? void 0 : _getInitialStateResolver();
2142
2048
  break;
2143
2049
  }
@@ -2249,12 +2155,12 @@ See v0.13 release notes for more information.
2249
2155
  clearInterval(state.intervalHandles.heartbeat);
2250
2156
  connect();
2251
2157
  }
2252
- function applyAndSendOfflineOps() {
2253
- if (state.offlineOperations.size === 0) {
2158
+ function applyAndSendOfflineOps(offlineOps) {
2159
+ if (offlineOps.size === 0) {
2254
2160
  return;
2255
2161
  }
2256
2162
  const messages = [];
2257
- const ops = Array.from(state.offlineOperations.values());
2163
+ const ops = Array.from(offlineOps.values());
2258
2164
  const result = apply(ops, true);
2259
2165
  messages.push({
2260
2166
  type: ClientMessageType.UpdateStorage,
@@ -2504,6 +2410,7 @@ See v0.13 release notes for more information.
2504
2410
  function defaultState(me, defaultStorageRoot) {
2505
2411
  return {
2506
2412
  connection: { state: "closed" },
2413
+ token: null,
2507
2414
  lastConnectionId: null,
2508
2415
  socket: null,
2509
2416
  listeners: {