@colyseus/schema 3.0.28 → 3.0.29
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 +13 -6
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +13 -6
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +13 -6
- package/lib/Metadata.d.ts +1 -0
- package/lib/Metadata.js +3 -0
- package/lib/Metadata.js.map +1 -1
- package/lib/decoder/DecodeOperation.js +8 -4
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/encoder/ChangeTree.js +1 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.js +1 -1
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +4 -0
- package/src/decoder/DecodeOperation.ts +9 -4
- package/src/encoder/ChangeTree.ts +1 -1
- package/src/encoder/EncodeOperation.ts +1 -1
package/build/esm/index.mjs
CHANGED
|
@@ -957,6 +957,9 @@ const Metadata = {
|
|
|
957
957
|
fields[metadata[i].name] = metadata[i].type;
|
|
958
958
|
}
|
|
959
959
|
return fields;
|
|
960
|
+
},
|
|
961
|
+
hasViewTagAtIndex(metadata, index) {
|
|
962
|
+
return metadata?.[$viewFieldIndexes]?.includes(index);
|
|
960
963
|
}
|
|
961
964
|
};
|
|
962
965
|
|
|
@@ -1377,7 +1380,7 @@ class ChangeTree {
|
|
|
1377
1380
|
key += `-${this.root.types.schemas.get(parentConstructor)}`;
|
|
1378
1381
|
}
|
|
1379
1382
|
key += `-${parentIndex}`;
|
|
1380
|
-
const fieldHasViewTag = parentConstructor?.[Symbol.metadata]
|
|
1383
|
+
const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
|
|
1381
1384
|
this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
|
|
1382
1385
|
|| this.root.types.parentFiltered[key]
|
|
1383
1386
|
|| fieldHasViewTag;
|
|
@@ -1520,7 +1523,7 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
|
|
|
1520
1523
|
// encode index
|
|
1521
1524
|
encode.number(bytes, refOrIndex, it);
|
|
1522
1525
|
// Do not encode value for DELETE operations
|
|
1523
|
-
if (operation === OPERATION.DELETE) {
|
|
1526
|
+
if (operation === OPERATION.DELETE || operation === OPERATION.DELETE_BY_REFID) {
|
|
1524
1527
|
return;
|
|
1525
1528
|
}
|
|
1526
1529
|
const type = changeTree.getType(field);
|
|
@@ -1741,10 +1744,14 @@ const decodeArray = function (decoder, bytes, it, ref, allChanges) {
|
|
|
1741
1744
|
else if (operation === OPERATION.ADD_BY_REFID) {
|
|
1742
1745
|
const refId = decode.number(bytes, it);
|
|
1743
1746
|
const itemByRefId = decoder.root.refs.get(refId);
|
|
1744
|
-
//
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1747
|
+
// if item already exists, use existing index
|
|
1748
|
+
if (itemByRefId) {
|
|
1749
|
+
index = ref.findIndex((value) => value === itemByRefId);
|
|
1750
|
+
}
|
|
1751
|
+
// fallback to use last index
|
|
1752
|
+
if (index === -1 || index === undefined) {
|
|
1753
|
+
index = ref.length;
|
|
1754
|
+
}
|
|
1748
1755
|
}
|
|
1749
1756
|
else {
|
|
1750
1757
|
index = decode.number(bytes, it);
|