@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/cjs/index.js
CHANGED
|
@@ -959,6 +959,9 @@ const Metadata = {
|
|
|
959
959
|
fields[metadata[i].name] = metadata[i].type;
|
|
960
960
|
}
|
|
961
961
|
return fields;
|
|
962
|
+
},
|
|
963
|
+
hasViewTagAtIndex(metadata, index) {
|
|
964
|
+
return metadata?.[$viewFieldIndexes]?.includes(index);
|
|
962
965
|
}
|
|
963
966
|
};
|
|
964
967
|
|
|
@@ -1379,7 +1382,7 @@ class ChangeTree {
|
|
|
1379
1382
|
key += `-${this.root.types.schemas.get(parentConstructor)}`;
|
|
1380
1383
|
}
|
|
1381
1384
|
key += `-${parentIndex}`;
|
|
1382
|
-
const fieldHasViewTag = parentConstructor?.[Symbol.metadata]
|
|
1385
|
+
const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
|
|
1383
1386
|
this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
|
|
1384
1387
|
|| this.root.types.parentFiltered[key]
|
|
1385
1388
|
|| fieldHasViewTag;
|
|
@@ -1522,7 +1525,7 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
|
|
|
1522
1525
|
// encode index
|
|
1523
1526
|
encode.number(bytes, refOrIndex, it);
|
|
1524
1527
|
// Do not encode value for DELETE operations
|
|
1525
|
-
if (operation === exports.OPERATION.DELETE) {
|
|
1528
|
+
if (operation === exports.OPERATION.DELETE || operation === exports.OPERATION.DELETE_BY_REFID) {
|
|
1526
1529
|
return;
|
|
1527
1530
|
}
|
|
1528
1531
|
const type = changeTree.getType(field);
|
|
@@ -1743,10 +1746,14 @@ const decodeArray = function (decoder, bytes, it, ref, allChanges) {
|
|
|
1743
1746
|
else if (operation === exports.OPERATION.ADD_BY_REFID) {
|
|
1744
1747
|
const refId = decode.number(bytes, it);
|
|
1745
1748
|
const itemByRefId = decoder.root.refs.get(refId);
|
|
1746
|
-
//
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1749
|
+
// if item already exists, use existing index
|
|
1750
|
+
if (itemByRefId) {
|
|
1751
|
+
index = ref.findIndex((value) => value === itemByRefId);
|
|
1752
|
+
}
|
|
1753
|
+
// fallback to use last index
|
|
1754
|
+
if (index === -1 || index === undefined) {
|
|
1755
|
+
index = ref.length;
|
|
1756
|
+
}
|
|
1750
1757
|
}
|
|
1751
1758
|
else {
|
|
1752
1759
|
index = decode.number(bytes, it);
|