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