@colyseus/schema 3.0.44 → 3.0.46

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.
@@ -1424,7 +1424,9 @@ class ChangeTree {
1424
1424
  */
1425
1425
  addParent(parent, index) {
1426
1426
  // Check if this parent already exists in the chain
1427
- if (this.hasParent((p, i) => p[$changes] === parent[$changes] && i === index)) {
1427
+ if (this.hasParent((p, _) => p[$changes] === parent[$changes])) {
1428
+ // if (this.hasParent((p, i) => p[$changes] === parent[$changes] && i === index)) {
1429
+ this.parentChain.index = index;
1428
1430
  return;
1429
1431
  }
1430
1432
  this.parentChain = {
@@ -2008,7 +2010,7 @@ class ArraySchema {
2008
2010
  }
2009
2011
  if (previousValue !== undefined) {
2010
2012
  // remove root reference from previous value
2011
- previousValue[$changes].root?.remove(previousValue[$changes], obj);
2013
+ previousValue[$changes].root?.remove(previousValue[$changes]);
2012
2014
  }
2013
2015
  }
2014
2016
  else {
@@ -2165,7 +2167,7 @@ class ArraySchema {
2165
2167
  const changeTree = this[$changes];
2166
2168
  // remove children references
2167
2169
  changeTree.forEachChild((childChangeTree, _) => {
2168
- changeTree.root?.remove(childChangeTree, this);
2170
+ changeTree.root?.remove(childChangeTree);
2169
2171
  });
2170
2172
  changeTree.discard(true);
2171
2173
  changeTree.operation(OPERATION.CLEAR);
@@ -2719,7 +2721,7 @@ class MapSchema {
2719
2721
  operation = OPERATION.DELETE_AND_ADD;
2720
2722
  // remove reference from previous value
2721
2723
  if (previousValue !== undefined) {
2722
- previousValue[$changes].root?.remove(previousValue[$changes], this);
2724
+ previousValue[$changes].root?.remove(previousValue[$changes]);
2723
2725
  }
2724
2726
  }
2725
2727
  }
@@ -2756,7 +2758,7 @@ class MapSchema {
2756
2758
  changeTree.indexes = {};
2757
2759
  // remove children references
2758
2760
  changeTree.forEachChild((childChangeTree, _) => {
2759
- changeTree.root?.remove(childChangeTree, this);
2761
+ changeTree.root?.remove(childChangeTree);
2760
2762
  });
2761
2763
  // clear previous indexes
2762
2764
  this.$indexes.clear();
@@ -3598,7 +3600,7 @@ class CollectionSchema {
3598
3600
  changeTree.indexes = {};
3599
3601
  // remove children references
3600
3602
  changeTree.forEachChild((childChangeTree, _) => {
3601
- changeTree.root?.remove(childChangeTree, this);
3603
+ changeTree.root?.remove(childChangeTree);
3602
3604
  });
3603
3605
  // clear previous indexes
3604
3606
  this.$indexes.clear();
@@ -3920,9 +3922,8 @@ class Root {
3920
3922
  // console.log("ADD", { refId: changeTree.refId, refCount: this.refCount[changeTree.refId] });
3921
3923
  return isNewChangeTree;
3922
3924
  }
3923
- remove(changeTree, parent) {
3925
+ remove(changeTree) {
3924
3926
  const refCount = (this.refCount[changeTree.refId]) - 1;
3925
- // console.log("REMOVE", { refId: changeTree.refId, refCount });
3926
3927
  if (refCount <= 0) {
3927
3928
  //
3928
3929
  // Only remove "root" reference if it's the last reference
@@ -3941,7 +3942,7 @@ class Root {
3941
3942
  if ((child.parentChain === undefined || // no parent, remove it
3942
3943
  (child.parentChain && this.refCount[child.refId] > 1) // parent is still in use, but has more than one reference, remove it
3943
3944
  )) {
3944
- this.remove(child, changeTree.ref);
3945
+ this.remove(child);
3945
3946
  }
3946
3947
  else if (child.parentChain) {
3947
3948
  // re-assigning a child of the same root, move it to the end
@@ -4422,7 +4423,11 @@ class Decoder {
4422
4423
  // Trying to access a reference that haven't been decoded yet.
4423
4424
  //
4424
4425
  if (!nextRef) {
4425
- throw new Error(`"refId" not found: ${nextRefId}`);
4426
+ // throw new Error(`"refId" not found: ${nextRefId}`);
4427
+ console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });
4428
+ console.warn("Please report this to the developers. All refIds =>");
4429
+ console.warn(Schema.debugRefIdsFromDecoder(this));
4430
+ this.skipCurrentStructure(bytes, it, totalBytes);
4426
4431
  }
4427
4432
  else {
4428
4433
  ref = nextRef;