@colyseus/schema 3.0.19 → 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.
@@ -3313,7 +3313,7 @@ class CollectionSchema {
3313
3313
  static [(_a$1 = $encoder, _b$1 = $decoder, $filter)](ref, index, view) {
3314
3314
  return (!view ||
3315
3315
  typeof (ref[$childType]) === "string" ||
3316
- view.items.has(ref[$getByIndex](index)[$changes]));
3316
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3317
3317
  }
3318
3318
  static is(type) {
3319
3319
  return type['collection'] !== undefined;
@@ -3321,6 +3321,7 @@ class CollectionSchema {
3321
3321
  constructor(initialValues) {
3322
3322
  this.$items = new Map();
3323
3323
  this.$indexes = new Map();
3324
+ this.deletedItems = {};
3324
3325
  this.$refId = 0;
3325
3326
  this[$changes] = new ChangeTree(this);
3326
3327
  this[$changes].indexes = {};
@@ -3370,7 +3371,7 @@ class CollectionSchema {
3370
3371
  if (index === undefined) {
3371
3372
  return false;
3372
3373
  }
3373
- this[$changes].delete(index);
3374
+ this.deletedItems[index] = this[$changes].delete(index);
3374
3375
  this.$indexes.delete(index);
3375
3376
  return this.$items.delete(index);
3376
3377
  }
@@ -3415,6 +3416,9 @@ class CollectionSchema {
3415
3416
  this.$items.delete(key);
3416
3417
  this.$indexes.delete(index);
3417
3418
  }
3419
+ [$onEncodeEnd]() {
3420
+ this.deletedItems = {};
3421
+ }
3418
3422
  toArray() {
3419
3423
  return Array.from(this.$items.values());
3420
3424
  }
@@ -3469,7 +3473,7 @@ class SetSchema {
3469
3473
  static [(_a = $encoder, _b = $decoder, $filter)](ref, index, view) {
3470
3474
  return (!view ||
3471
3475
  typeof (ref[$childType]) === "string" ||
3472
- view.items.has(ref[$getByIndex](index)[$changes]));
3476
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3473
3477
  }
3474
3478
  static is(type) {
3475
3479
  return type['set'] !== undefined;
@@ -3477,6 +3481,7 @@ class SetSchema {
3477
3481
  constructor(initialValues) {
3478
3482
  this.$items = new Map();
3479
3483
  this.$indexes = new Map();
3484
+ this.deletedItems = {};
3480
3485
  this.$refId = 0;
3481
3486
  this[$changes] = new ChangeTree(this);
3482
3487
  this[$changes].indexes = {};
@@ -3526,7 +3531,7 @@ class SetSchema {
3526
3531
  if (index === undefined) {
3527
3532
  return false;
3528
3533
  }
3529
- this[$changes].delete(index);
3534
+ this.deletedItems[index] = this[$changes].delete(index);
3530
3535
  this.$indexes.delete(index);
3531
3536
  return this.$items.delete(index);
3532
3537
  }
@@ -3583,6 +3588,9 @@ class SetSchema {
3583
3588
  this.$items.delete(key);
3584
3589
  this.$indexes.delete(index);
3585
3590
  }
3591
+ [$onEncodeEnd]() {
3592
+ this.deletedItems = {};
3593
+ }
3586
3594
  toArray() {
3587
3595
  return Array.from(this.$items.values());
3588
3596
  }
@@ -3787,7 +3795,7 @@ class Encoder {
3787
3795
  view.invisible.add(changeTree);
3788
3796
  continue; // skip this change tree
3789
3797
  }
3790
- else if (view.invisible.has(changeTree)) {
3798
+ else {
3791
3799
  view.invisible.delete(changeTree); // remove from invisible list
3792
3800
  }
3793
3801
  }
@@ -4743,10 +4751,11 @@ class StateView {
4743
4751
  } // skip "undefined" indexes
4744
4752
  const op = changeTree.indexedOperations[index] ?? exports.OPERATION.ADD;
4745
4753
  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
- ) &&
4754
+ if (!changeTree.isNew && // new structures will be added as part of .encode() call, no need to force it to .encodeView()
4755
+ (isInvisible || // if "invisible", include all
4756
+ tagAtIndex === undefined || // "all change" with no tag
4757
+ tagAtIndex === tag // tagged property
4758
+ ) &&
4750
4759
  op !== exports.OPERATION.DELETE) {
4751
4760
  changes[index] = op;
4752
4761
  }
@@ -4775,10 +4784,8 @@ class StateView {
4775
4784
  if (parentChangeTree && (parentChangeTree.filteredChanges !== undefined)) {
4776
4785
  this.addParentOf(changeTree, tag);
4777
4786
  }
4778
- // parent is already available, no need to add it!
4779
- if (!this.invisible.has(changeTree)) {
4780
- return;
4781
- }
4787
+ // // parent is already available, no need to add it!
4788
+ // if (!this.invisible.has(changeTree)) { return; }
4782
4789
  }
4783
4790
  // add parent's tag properties
4784
4791
  if (changeTree.getChange(parentIndex) !== exports.OPERATION.DELETE) {