@colyseus/schema 3.0.49 → 3.0.50

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.
@@ -1102,7 +1102,7 @@ class ChangeTree {
1102
1102
  if (typeof (this.ref[$childType]) !== "string") {
1103
1103
  // MapSchema / ArraySchema, etc.
1104
1104
  for (const [key, value] of this.ref.entries()) {
1105
- callback(value[$changes], key);
1105
+ callback(value[$changes], this.indexes?.[key] ?? key);
1106
1106
  }
1107
1107
  }
1108
1108
  }
@@ -1541,10 +1541,6 @@ const encodeSchemaOperation = function (encoder, bytes, changeTree, index, opera
1541
1541
  const encodeKeyValueOperation = function (encoder, bytes, changeTree, index, operation, it) {
1542
1542
  // encode operation
1543
1543
  bytes[it.offset++] = operation & 255;
1544
- // custom operations
1545
- if (operation === OPERATION.CLEAR) {
1546
- return;
1547
- }
1548
1544
  // encode index
1549
1545
  encode.number(bytes, index, it);
1550
1546
  // Do not encode value for DELETE operations
@@ -1603,11 +1599,6 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
1603
1599
  }
1604
1600
  // encode operation
1605
1601
  bytes[it.offset++] = operation & 255;
1606
- // custom operations
1607
- if (operation === OPERATION.CLEAR ||
1608
- operation === OPERATION.REVERSE) {
1609
- return;
1610
- }
1611
1602
  // encode index
1612
1603
  encode.number(bytes, refOrIndex, it);
1613
1604
  // Do not encode value for DELETE operations
@@ -3411,7 +3402,12 @@ class Schema {
3411
3402
  ? ` [×${root.refCount[refId]}]`
3412
3403
  : '';
3413
3404
  let output = `${getIndent(level)}${keyPrefix}${ref.constructor.name} (refId: ${refId})${refCount}${contents}\n`;
3414
- changeTree.forEachChild((childChangeTree, key) => {
3405
+ changeTree.forEachChild((childChangeTree, indexOrKey) => {
3406
+ let key = indexOrKey;
3407
+ if (typeof indexOrKey === 'number' && ref['$indexes']) {
3408
+ // MapSchema
3409
+ key = ref['$indexes'].get(indexOrKey) ?? indexOrKey;
3410
+ }
3415
3411
  const keyPrefix = (ref['forEach'] !== undefined && key !== undefined) ? `["${key}"]: ` : "";
3416
3412
  output += this.debugRefIds(childChangeTree.ref, showContents, level + 1, decoder, keyPrefix);
3417
3413
  });
@@ -4106,11 +4102,15 @@ class Encoder {
4106
4102
  }
4107
4103
  for (let j = 0; j < numChanges; j++) {
4108
4104
  const fieldIndex = changeSet.operations[j];
4109
- const operation = (fieldIndex < 0)
4110
- ? Math.abs(fieldIndex) // "pure" operation without fieldIndex (e.g. CLEAR, REVERSE, etc.)
4111
- : (isEncodeAll)
4112
- ? OPERATION.ADD
4113
- : changeTree.indexedOperations[fieldIndex];
4105
+ if (fieldIndex < 0) {
4106
+ // "pure" operation without fieldIndex (e.g. CLEAR, REVERSE, etc.)
4107
+ // encode and continue early - no need to reach $filter check
4108
+ buffer[it.offset++] = Math.abs(fieldIndex) & 255;
4109
+ continue;
4110
+ }
4111
+ const operation = (isEncodeAll)
4112
+ ? OPERATION.ADD
4113
+ : changeTree.indexedOperations[fieldIndex];
4114
4114
  //
4115
4115
  // first pass (encodeAll), identify "filtered" operations without encoding them
4116
4116
  // they will be encoded per client, based on their view.