@colyseus/schema 3.0.18 → 3.0.20

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.
@@ -1356,9 +1356,8 @@ class ChangeTree {
1356
1356
  }
1357
1357
  key += `-${parentIndex}`;
1358
1358
  this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
1359
- || this.root.types.parentFiltered[key];
1360
- // const parentMetadata = parentConstructor?.[Symbol.metadata];
1361
- // this.isFiltered = parentMetadata?.[$viewFieldIndexes]?.includes(parentIndex) || this.root.types.parentFiltered[key];
1359
+ || this.root.types.parentFiltered[key]
1360
+ || parentConstructor?.[Symbol.metadata]?.[$viewFieldIndexes]?.includes(parentIndex);
1362
1361
  //
1363
1362
  // TODO: refactor this!
1364
1363
  //
@@ -1573,7 +1572,6 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
1573
1572
  while ((iter = entries.next()) && !iter.done) {
1574
1573
  const [key, value] = iter.value;
1575
1574
  // if value is a schema, remove its reference
1576
- // FIXME: not sure if this is necessary, add more tests to confirm
1577
1575
  if (typeof (value) === "object") {
1578
1576
  previousRefId = $root.refIds.get(value);
1579
1577
  $root.removeRef(previousRefId);
@@ -3313,7 +3311,7 @@ class CollectionSchema {
3313
3311
  static [(_a$1 = $encoder, _b$1 = $decoder, $filter)](ref, index, view) {
3314
3312
  return (!view ||
3315
3313
  typeof (ref[$childType]) === "string" ||
3316
- view.items.has(ref[$getByIndex](index)[$changes]));
3314
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3317
3315
  }
3318
3316
  static is(type) {
3319
3317
  return type['collection'] !== undefined;
@@ -3321,6 +3319,7 @@ class CollectionSchema {
3321
3319
  constructor(initialValues) {
3322
3320
  this.$items = new Map();
3323
3321
  this.$indexes = new Map();
3322
+ this.deletedItems = {};
3324
3323
  this.$refId = 0;
3325
3324
  this[$changes] = new ChangeTree(this);
3326
3325
  this[$changes].indexes = {};
@@ -3370,7 +3369,7 @@ class CollectionSchema {
3370
3369
  if (index === undefined) {
3371
3370
  return false;
3372
3371
  }
3373
- this[$changes].delete(index);
3372
+ this.deletedItems[index] = this[$changes].delete(index);
3374
3373
  this.$indexes.delete(index);
3375
3374
  return this.$items.delete(index);
3376
3375
  }
@@ -3415,6 +3414,9 @@ class CollectionSchema {
3415
3414
  this.$items.delete(key);
3416
3415
  this.$indexes.delete(index);
3417
3416
  }
3417
+ [$onEncodeEnd]() {
3418
+ this.deletedItems = {};
3419
+ }
3418
3420
  toArray() {
3419
3421
  return Array.from(this.$items.values());
3420
3422
  }
@@ -3469,7 +3471,7 @@ class SetSchema {
3469
3471
  static [(_a = $encoder, _b = $decoder, $filter)](ref, index, view) {
3470
3472
  return (!view ||
3471
3473
  typeof (ref[$childType]) === "string" ||
3472
- view.items.has(ref[$getByIndex](index)[$changes]));
3474
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3473
3475
  }
3474
3476
  static is(type) {
3475
3477
  return type['set'] !== undefined;
@@ -3477,6 +3479,7 @@ class SetSchema {
3477
3479
  constructor(initialValues) {
3478
3480
  this.$items = new Map();
3479
3481
  this.$indexes = new Map();
3482
+ this.deletedItems = {};
3480
3483
  this.$refId = 0;
3481
3484
  this[$changes] = new ChangeTree(this);
3482
3485
  this[$changes].indexes = {};
@@ -3526,7 +3529,7 @@ class SetSchema {
3526
3529
  if (index === undefined) {
3527
3530
  return false;
3528
3531
  }
3529
- this[$changes].delete(index);
3532
+ this.deletedItems[index] = this[$changes].delete(index);
3530
3533
  this.$indexes.delete(index);
3531
3534
  return this.$items.delete(index);
3532
3535
  }
@@ -3583,6 +3586,9 @@ class SetSchema {
3583
3586
  this.$items.delete(key);
3584
3587
  this.$indexes.delete(index);
3585
3588
  }
3589
+ [$onEncodeEnd]() {
3590
+ this.deletedItems = {};
3591
+ }
3586
3592
  toArray() {
3587
3593
  return Array.from(this.$items.values());
3588
3594
  }
@@ -3787,7 +3793,7 @@ class Encoder {
3787
3793
  view.invisible.add(changeTree);
3788
3794
  continue; // skip this change tree
3789
3795
  }
3790
- else if (view.invisible.has(changeTree)) {
3796
+ else {
3791
3797
  view.invisible.delete(changeTree); // remove from invisible list
3792
3798
  }
3793
3799
  }
@@ -4743,10 +4749,11 @@ class StateView {
4743
4749
  } // skip "undefined" indexes
4744
4750
  const op = changeTree.indexedOperations[index] ?? OPERATION.ADD;
4745
4751
  const tagAtIndex = metadata?.[index].tag;
4746
- if ((isInvisible || // if "invisible", include all
4747
- tagAtIndex === undefined || // "all change" with no tag
4748
- tagAtIndex === tag // tagged property
4749
- ) &&
4752
+ if (!changeTree.isNew && // new structures will be added as part of .encode() call, no need to force it to .encodeView()
4753
+ (isInvisible || // if "invisible", include all
4754
+ tagAtIndex === undefined || // "all change" with no tag
4755
+ tagAtIndex === tag // tagged property
4756
+ ) &&
4750
4757
  op !== OPERATION.DELETE) {
4751
4758
  changes[index] = op;
4752
4759
  }
@@ -4775,10 +4782,8 @@ class StateView {
4775
4782
  if (parentChangeTree && (parentChangeTree.filteredChanges !== undefined)) {
4776
4783
  this.addParentOf(changeTree, tag);
4777
4784
  }
4778
- // parent is already available, no need to add it!
4779
- if (!this.invisible.has(changeTree)) {
4780
- return;
4781
- }
4785
+ // // parent is already available, no need to add it!
4786
+ // if (!this.invisible.has(changeTree)) { return; }
4782
4787
  }
4783
4788
  // add parent's tag properties
4784
4789
  if (changeTree.getChange(parentIndex) !== OPERATION.DELETE) {