@colyseus/schema 3.0.44 → 3.0.46
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 +15 -10
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +15 -10
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +15 -10
- package/lib/decoder/Decoder.js +1 -1
- package/lib/decoder/Decoder.js.map +1 -1
- package/lib/encoder/ChangeTree.js +3 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/Root.d.ts +2 -2
- package/lib/encoder/Root.js +2 -3
- package/lib/encoder/Root.js.map +1 -1
- package/lib/types/custom/ArraySchema.js +2 -2
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/lib/types/custom/CollectionSchema.js +1 -1
- package/lib/types/custom/CollectionSchema.js.map +1 -1
- package/lib/types/custom/MapSchema.js +2 -2
- package/lib/types/custom/MapSchema.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/Decoder.ts +1 -2
- package/src/encoder/ChangeTree.ts +3 -1
- package/src/encoder/Root.ts +2 -3
- package/src/types/custom/ArraySchema.ts +3 -3
- package/src/types/custom/CollectionSchema.ts +2 -2
- package/src/types/custom/MapSchema.ts +3 -3
package/build/cjs/index.js
CHANGED
|
@@ -1426,7 +1426,9 @@ class ChangeTree {
|
|
|
1426
1426
|
*/
|
|
1427
1427
|
addParent(parent, index) {
|
|
1428
1428
|
// Check if this parent already exists in the chain
|
|
1429
|
-
if (this.hasParent((p,
|
|
1429
|
+
if (this.hasParent((p, _) => p[$changes] === parent[$changes])) {
|
|
1430
|
+
// if (this.hasParent((p, i) => p[$changes] === parent[$changes] && i === index)) {
|
|
1431
|
+
this.parentChain.index = index;
|
|
1430
1432
|
return;
|
|
1431
1433
|
}
|
|
1432
1434
|
this.parentChain = {
|
|
@@ -2010,7 +2012,7 @@ class ArraySchema {
|
|
|
2010
2012
|
}
|
|
2011
2013
|
if (previousValue !== undefined) {
|
|
2012
2014
|
// remove root reference from previous value
|
|
2013
|
-
previousValue[$changes].root?.remove(previousValue[$changes]
|
|
2015
|
+
previousValue[$changes].root?.remove(previousValue[$changes]);
|
|
2014
2016
|
}
|
|
2015
2017
|
}
|
|
2016
2018
|
else {
|
|
@@ -2167,7 +2169,7 @@ class ArraySchema {
|
|
|
2167
2169
|
const changeTree = this[$changes];
|
|
2168
2170
|
// remove children references
|
|
2169
2171
|
changeTree.forEachChild((childChangeTree, _) => {
|
|
2170
|
-
changeTree.root?.remove(childChangeTree
|
|
2172
|
+
changeTree.root?.remove(childChangeTree);
|
|
2171
2173
|
});
|
|
2172
2174
|
changeTree.discard(true);
|
|
2173
2175
|
changeTree.operation(exports.OPERATION.CLEAR);
|
|
@@ -2721,7 +2723,7 @@ class MapSchema {
|
|
|
2721
2723
|
operation = exports.OPERATION.DELETE_AND_ADD;
|
|
2722
2724
|
// remove reference from previous value
|
|
2723
2725
|
if (previousValue !== undefined) {
|
|
2724
|
-
previousValue[$changes].root?.remove(previousValue[$changes]
|
|
2726
|
+
previousValue[$changes].root?.remove(previousValue[$changes]);
|
|
2725
2727
|
}
|
|
2726
2728
|
}
|
|
2727
2729
|
}
|
|
@@ -2758,7 +2760,7 @@ class MapSchema {
|
|
|
2758
2760
|
changeTree.indexes = {};
|
|
2759
2761
|
// remove children references
|
|
2760
2762
|
changeTree.forEachChild((childChangeTree, _) => {
|
|
2761
|
-
changeTree.root?.remove(childChangeTree
|
|
2763
|
+
changeTree.root?.remove(childChangeTree);
|
|
2762
2764
|
});
|
|
2763
2765
|
// clear previous indexes
|
|
2764
2766
|
this.$indexes.clear();
|
|
@@ -3600,7 +3602,7 @@ class CollectionSchema {
|
|
|
3600
3602
|
changeTree.indexes = {};
|
|
3601
3603
|
// remove children references
|
|
3602
3604
|
changeTree.forEachChild((childChangeTree, _) => {
|
|
3603
|
-
changeTree.root?.remove(childChangeTree
|
|
3605
|
+
changeTree.root?.remove(childChangeTree);
|
|
3604
3606
|
});
|
|
3605
3607
|
// clear previous indexes
|
|
3606
3608
|
this.$indexes.clear();
|
|
@@ -3922,9 +3924,8 @@ class Root {
|
|
|
3922
3924
|
// console.log("ADD", { refId: changeTree.refId, refCount: this.refCount[changeTree.refId] });
|
|
3923
3925
|
return isNewChangeTree;
|
|
3924
3926
|
}
|
|
3925
|
-
remove(changeTree
|
|
3927
|
+
remove(changeTree) {
|
|
3926
3928
|
const refCount = (this.refCount[changeTree.refId]) - 1;
|
|
3927
|
-
// console.log("REMOVE", { refId: changeTree.refId, refCount });
|
|
3928
3929
|
if (refCount <= 0) {
|
|
3929
3930
|
//
|
|
3930
3931
|
// Only remove "root" reference if it's the last reference
|
|
@@ -3943,7 +3944,7 @@ class Root {
|
|
|
3943
3944
|
if ((child.parentChain === undefined || // no parent, remove it
|
|
3944
3945
|
(child.parentChain && this.refCount[child.refId] > 1) // parent is still in use, but has more than one reference, remove it
|
|
3945
3946
|
)) {
|
|
3946
|
-
this.remove(child
|
|
3947
|
+
this.remove(child);
|
|
3947
3948
|
}
|
|
3948
3949
|
else if (child.parentChain) {
|
|
3949
3950
|
// re-assigning a child of the same root, move it to the end
|
|
@@ -4424,7 +4425,11 @@ class Decoder {
|
|
|
4424
4425
|
// Trying to access a reference that haven't been decoded yet.
|
|
4425
4426
|
//
|
|
4426
4427
|
if (!nextRef) {
|
|
4427
|
-
throw new Error(`"refId" not found: ${nextRefId}`);
|
|
4428
|
+
// throw new Error(`"refId" not found: ${nextRefId}`);
|
|
4429
|
+
console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId });
|
|
4430
|
+
console.warn("Please report this to the developers. All refIds =>");
|
|
4431
|
+
console.warn(Schema.debugRefIdsFromDecoder(this));
|
|
4432
|
+
this.skipCurrentStructure(bytes, it, totalBytes);
|
|
4428
4433
|
}
|
|
4429
4434
|
else {
|
|
4430
4435
|
ref = nextRef;
|