@colyseus/schema 4.0.22 → 4.0.24

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/build/index.js CHANGED
@@ -1235,12 +1235,26 @@
1235
1235
  }
1236
1236
  return;
1237
1237
  }
1238
- const changeSet = (this.filteredChanges !== undefined)
1238
+ // Mirror `change()`: a field's add/delete must target the same
1239
+ // changeset family (filtered vs non-filtered). Otherwise
1240
+ // `deleteOperationAtIndex` falls through to its "find last
1241
+ // operation" branch and evicts an unrelated sibling field —
1242
+ // surfaced as encodeAll() dropping a non-@view field after a
1243
+ // sibling @view field is set to undefined on a Schema with
1244
+ // mixed @view / non-@view fields (filteredChanges defined,
1245
+ // isFiltered false).
1246
+ const isFiltered = this.isFiltered || (this.metadata?.[index]?.tag !== undefined);
1247
+ const changeSet = (isFiltered)
1239
1248
  ? this.filteredChanges
1240
1249
  : this.changes;
1241
1250
  this.indexedOperations[index] = operation ?? exports.OPERATION.DELETE;
1242
1251
  setOperationAtIndex(changeSet, index);
1243
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
1252
+ if (isFiltered) {
1253
+ deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1254
+ }
1255
+ else {
1256
+ deleteOperationAtIndex(this.allChanges, allChangesIndex);
1257
+ }
1244
1258
  const previousValue = this.getValue(index);
1245
1259
  // remove `root` reference
1246
1260
  if (previousValue && previousValue[$changes]) {
@@ -1256,11 +1270,7 @@
1256
1270
  //
1257
1271
  this.root?.remove(previousValue[$changes]);
1258
1272
  }
1259
- //
1260
- // FIXME: this is looking a ugly and repeated
1261
- //
1262
- if (this.filteredChanges !== undefined) {
1263
- deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1273
+ if (isFiltered) {
1264
1274
  this.root?.enqueueChangeTree(this, 'filteredChanges');
1265
1275
  }
1266
1276
  else {
@@ -5538,6 +5548,7 @@
5538
5548
  else if ('decoder' in roomOrDecoder.serializer) {
5539
5549
  return getDecoderStateCallbacks(roomOrDecoder.serializer.decoder);
5540
5550
  }
5551
+ throw new Error('Invalid room or decoder');
5541
5552
  },
5542
5553
  getRawChanges(decoder, callback) {
5543
5554
  return getRawChangesCallback(decoder, callback);
package/build/index.mjs CHANGED
@@ -1229,12 +1229,26 @@ class ChangeTree {
1229
1229
  }
1230
1230
  return;
1231
1231
  }
1232
- const changeSet = (this.filteredChanges !== undefined)
1232
+ // Mirror `change()`: a field's add/delete must target the same
1233
+ // changeset family (filtered vs non-filtered). Otherwise
1234
+ // `deleteOperationAtIndex` falls through to its "find last
1235
+ // operation" branch and evicts an unrelated sibling field —
1236
+ // surfaced as encodeAll() dropping a non-@view field after a
1237
+ // sibling @view field is set to undefined on a Schema with
1238
+ // mixed @view / non-@view fields (filteredChanges defined,
1239
+ // isFiltered false).
1240
+ const isFiltered = this.isFiltered || (this.metadata?.[index]?.tag !== undefined);
1241
+ const changeSet = (isFiltered)
1233
1242
  ? this.filteredChanges
1234
1243
  : this.changes;
1235
1244
  this.indexedOperations[index] = operation ?? OPERATION.DELETE;
1236
1245
  setOperationAtIndex(changeSet, index);
1237
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
1246
+ if (isFiltered) {
1247
+ deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1248
+ }
1249
+ else {
1250
+ deleteOperationAtIndex(this.allChanges, allChangesIndex);
1251
+ }
1238
1252
  const previousValue = this.getValue(index);
1239
1253
  // remove `root` reference
1240
1254
  if (previousValue && previousValue[$changes]) {
@@ -1250,11 +1264,7 @@ class ChangeTree {
1250
1264
  //
1251
1265
  this.root?.remove(previousValue[$changes]);
1252
1266
  }
1253
- //
1254
- // FIXME: this is looking a ugly and repeated
1255
- //
1256
- if (this.filteredChanges !== undefined) {
1257
- deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1267
+ if (isFiltered) {
1258
1268
  this.root?.enqueueChangeTree(this, 'filteredChanges');
1259
1269
  }
1260
1270
  else {
@@ -5532,6 +5542,7 @@ const Callbacks = {
5532
5542
  else if ('decoder' in roomOrDecoder.serializer) {
5533
5543
  return getDecoderStateCallbacks(roomOrDecoder.serializer.decoder);
5534
5544
  }
5545
+ throw new Error('Invalid room or decoder');
5535
5546
  },
5536
5547
  getRawChanges(decoder, callback) {
5537
5548
  return getRawChangesCallback(decoder, callback);