@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.
@@ -3311,7 +3311,7 @@ class CollectionSchema {
3311
3311
  static [(_a$1 = $encoder, _b$1 = $decoder, $filter)](ref, index, view) {
3312
3312
  return (!view ||
3313
3313
  typeof (ref[$childType]) === "string" ||
3314
- view.items.has(ref[$getByIndex](index)[$changes]));
3314
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3315
3315
  }
3316
3316
  static is(type) {
3317
3317
  return type['collection'] !== undefined;
@@ -3319,6 +3319,7 @@ class CollectionSchema {
3319
3319
  constructor(initialValues) {
3320
3320
  this.$items = new Map();
3321
3321
  this.$indexes = new Map();
3322
+ this.deletedItems = {};
3322
3323
  this.$refId = 0;
3323
3324
  this[$changes] = new ChangeTree(this);
3324
3325
  this[$changes].indexes = {};
@@ -3368,7 +3369,7 @@ class CollectionSchema {
3368
3369
  if (index === undefined) {
3369
3370
  return false;
3370
3371
  }
3371
- this[$changes].delete(index);
3372
+ this.deletedItems[index] = this[$changes].delete(index);
3372
3373
  this.$indexes.delete(index);
3373
3374
  return this.$items.delete(index);
3374
3375
  }
@@ -3413,6 +3414,9 @@ class CollectionSchema {
3413
3414
  this.$items.delete(key);
3414
3415
  this.$indexes.delete(index);
3415
3416
  }
3417
+ [$onEncodeEnd]() {
3418
+ this.deletedItems = {};
3419
+ }
3416
3420
  toArray() {
3417
3421
  return Array.from(this.$items.values());
3418
3422
  }
@@ -3467,7 +3471,7 @@ class SetSchema {
3467
3471
  static [(_a = $encoder, _b = $decoder, $filter)](ref, index, view) {
3468
3472
  return (!view ||
3469
3473
  typeof (ref[$childType]) === "string" ||
3470
- view.items.has(ref[$getByIndex](index)[$changes]));
3474
+ view.items.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes]));
3471
3475
  }
3472
3476
  static is(type) {
3473
3477
  return type['set'] !== undefined;
@@ -3475,6 +3479,7 @@ class SetSchema {
3475
3479
  constructor(initialValues) {
3476
3480
  this.$items = new Map();
3477
3481
  this.$indexes = new Map();
3482
+ this.deletedItems = {};
3478
3483
  this.$refId = 0;
3479
3484
  this[$changes] = new ChangeTree(this);
3480
3485
  this[$changes].indexes = {};
@@ -3524,7 +3529,7 @@ class SetSchema {
3524
3529
  if (index === undefined) {
3525
3530
  return false;
3526
3531
  }
3527
- this[$changes].delete(index);
3532
+ this.deletedItems[index] = this[$changes].delete(index);
3528
3533
  this.$indexes.delete(index);
3529
3534
  return this.$items.delete(index);
3530
3535
  }
@@ -3581,6 +3586,9 @@ class SetSchema {
3581
3586
  this.$items.delete(key);
3582
3587
  this.$indexes.delete(index);
3583
3588
  }
3589
+ [$onEncodeEnd]() {
3590
+ this.deletedItems = {};
3591
+ }
3584
3592
  toArray() {
3585
3593
  return Array.from(this.$items.values());
3586
3594
  }
@@ -3785,7 +3793,7 @@ class Encoder {
3785
3793
  view.invisible.add(changeTree);
3786
3794
  continue; // skip this change tree
3787
3795
  }
3788
- else if (view.invisible.has(changeTree)) {
3796
+ else {
3789
3797
  view.invisible.delete(changeTree); // remove from invisible list
3790
3798
  }
3791
3799
  }
@@ -4741,10 +4749,11 @@ class StateView {
4741
4749
  } // skip "undefined" indexes
4742
4750
  const op = changeTree.indexedOperations[index] ?? OPERATION.ADD;
4743
4751
  const tagAtIndex = metadata?.[index].tag;
4744
- if ((isInvisible || // if "invisible", include all
4745
- tagAtIndex === undefined || // "all change" with no tag
4746
- tagAtIndex === tag // tagged property
4747
- ) &&
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
+ ) &&
4748
4757
  op !== OPERATION.DELETE) {
4749
4758
  changes[index] = op;
4750
4759
  }
@@ -4773,10 +4782,8 @@ class StateView {
4773
4782
  if (parentChangeTree && (parentChangeTree.filteredChanges !== undefined)) {
4774
4783
  this.addParentOf(changeTree, tag);
4775
4784
  }
4776
- // parent is already available, no need to add it!
4777
- if (!this.invisible.has(changeTree)) {
4778
- return;
4779
- }
4785
+ // // parent is already available, no need to add it!
4786
+ // if (!this.invisible.has(changeTree)) { return; }
4780
4787
  }
4781
4788
  // add parent's tag properties
4782
4789
  if (changeTree.getChange(parentIndex) !== OPERATION.DELETE) {