@colyseus/schema 3.0.49 → 3.0.51
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/cjs/index.js +22 -17
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +22 -17
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +22 -17
- package/lib/Schema.js +6 -1
- package/lib/Schema.js.map +1 -1
- package/lib/encoder/ChangeTree.js +1 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.js +6 -10
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/lib/encoder/Encoder.js +9 -5
- package/lib/encoder/Encoder.js.map +1 -1
- package/package.json +1 -1
- package/src/Schema.ts +6 -1
- package/src/encoder/ChangeTree.ts +1 -1
- package/src/encoder/EncodeOperation.ts +6 -14
- package/src/encoder/Encoder.ts +10 -5
package/build/esm/index.mjs
CHANGED
|
@@ -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
|
|
@@ -1590,7 +1586,12 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
|
|
|
1590
1586
|
const useOperationByRefId = hasView && changeTree.isFiltered && (typeof (changeTree.getType(field)) !== "string");
|
|
1591
1587
|
let refOrIndex;
|
|
1592
1588
|
if (useOperationByRefId) {
|
|
1593
|
-
|
|
1589
|
+
const item = ref['tmpItems'][field];
|
|
1590
|
+
// Skip encoding if item is undefined (e.g. when clear() is called)
|
|
1591
|
+
if (!item) {
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
refOrIndex = item[$changes].refId;
|
|
1594
1595
|
if (operation === OPERATION.DELETE) {
|
|
1595
1596
|
operation = OPERATION.DELETE_BY_REFID;
|
|
1596
1597
|
}
|
|
@@ -1603,11 +1604,6 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
|
|
|
1603
1604
|
}
|
|
1604
1605
|
// encode operation
|
|
1605
1606
|
bytes[it.offset++] = operation & 255;
|
|
1606
|
-
// custom operations
|
|
1607
|
-
if (operation === OPERATION.CLEAR ||
|
|
1608
|
-
operation === OPERATION.REVERSE) {
|
|
1609
|
-
return;
|
|
1610
|
-
}
|
|
1611
1607
|
// encode index
|
|
1612
1608
|
encode.number(bytes, refOrIndex, it);
|
|
1613
1609
|
// Do not encode value for DELETE operations
|
|
@@ -3411,7 +3407,12 @@ class Schema {
|
|
|
3411
3407
|
? ` [×${root.refCount[refId]}]`
|
|
3412
3408
|
: '';
|
|
3413
3409
|
let output = `${getIndent(level)}${keyPrefix}${ref.constructor.name} (refId: ${refId})${refCount}${contents}\n`;
|
|
3414
|
-
changeTree.forEachChild((childChangeTree,
|
|
3410
|
+
changeTree.forEachChild((childChangeTree, indexOrKey) => {
|
|
3411
|
+
let key = indexOrKey;
|
|
3412
|
+
if (typeof indexOrKey === 'number' && ref['$indexes']) {
|
|
3413
|
+
// MapSchema
|
|
3414
|
+
key = ref['$indexes'].get(indexOrKey) ?? indexOrKey;
|
|
3415
|
+
}
|
|
3415
3416
|
const keyPrefix = (ref['forEach'] !== undefined && key !== undefined) ? `["${key}"]: ` : "";
|
|
3416
3417
|
output += this.debugRefIds(childChangeTree.ref, showContents, level + 1, decoder, keyPrefix);
|
|
3417
3418
|
});
|
|
@@ -4106,11 +4107,15 @@ class Encoder {
|
|
|
4106
4107
|
}
|
|
4107
4108
|
for (let j = 0; j < numChanges; j++) {
|
|
4108
4109
|
const fieldIndex = changeSet.operations[j];
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4110
|
+
if (fieldIndex < 0) {
|
|
4111
|
+
// "pure" operation without fieldIndex (e.g. CLEAR, REVERSE, etc.)
|
|
4112
|
+
// encode and continue early - no need to reach $filter check
|
|
4113
|
+
buffer[it.offset++] = Math.abs(fieldIndex) & 255;
|
|
4114
|
+
continue;
|
|
4115
|
+
}
|
|
4116
|
+
const operation = (isEncodeAll)
|
|
4117
|
+
? OPERATION.ADD
|
|
4118
|
+
: changeTree.indexedOperations[fieldIndex];
|
|
4114
4119
|
//
|
|
4115
4120
|
// first pass (encodeAll), identify "filtered" operations without encoding them
|
|
4116
4121
|
// they will be encoded per client, based on their view.
|