@colyseus/schema 3.0.9 → 3.0.11
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 +28 -12
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +28 -12
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +28 -12
- package/lib/Schema.d.ts +2 -2
- package/lib/Schema.js +5 -6
- package/lib/Schema.js.map +1 -1
- package/lib/decoder/ReferenceTracker.js +1 -1
- package/lib/decoder/ReferenceTracker.js.map +1 -1
- package/lib/encoder/ChangeTree.d.ts +1 -0
- package/lib/encoder/ChangeTree.js +2 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/Root.js +19 -3
- package/lib/encoder/Root.js.map +1 -1
- package/lib/types/custom/ArraySchema.js +2 -1
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/package.json +1 -1
- package/src/Schema.ts +6 -8
- package/src/decoder/ReferenceTracker.ts +1 -1
- package/src/encoder/ChangeTree.ts +3 -2
- package/src/encoder/Root.ts +20 -4
- package/src/types/custom/ArraySchema.ts +2 -1
package/build/umd/index.js
CHANGED
|
@@ -1242,6 +1242,7 @@
|
|
|
1242
1242
|
//
|
|
1243
1243
|
this.root?.remove(previousValue[$changes]);
|
|
1244
1244
|
}
|
|
1245
|
+
deleteOperationAtIndex(this.allChanges, allChangesIndex);
|
|
1245
1246
|
//
|
|
1246
1247
|
// FIXME: this is looking a ugly and repeated
|
|
1247
1248
|
//
|
|
@@ -1250,7 +1251,6 @@
|
|
|
1250
1251
|
enqueueChangeTree(this.root, this, 'filteredChanges');
|
|
1251
1252
|
}
|
|
1252
1253
|
else {
|
|
1253
|
-
deleteOperationAtIndex(this.allChanges, allChangesIndex);
|
|
1254
1254
|
enqueueChangeTree(this.root, this, 'changes');
|
|
1255
1255
|
}
|
|
1256
1256
|
}
|
|
@@ -1852,7 +1852,6 @@
|
|
|
1852
1852
|
* - Then, the encoder iterates over all "owned" properties per instance and encodes them.
|
|
1853
1853
|
*/
|
|
1854
1854
|
static [(_a$4 = $encoder, _b$4 = $decoder, $filter)](ref, index, view) {
|
|
1855
|
-
// console.log("ArraSchema[$filter] VIEW??", !view)
|
|
1856
1855
|
return (!view ||
|
|
1857
1856
|
typeof (ref[$childType]) === "string" ||
|
|
1858
1857
|
// view.items.has(ref[$getByIndex](index)[$changes])
|
|
@@ -2452,6 +2451,7 @@
|
|
|
2452
2451
|
}
|
|
2453
2452
|
[$deleteByIndex](index) {
|
|
2454
2453
|
this.items[index] = undefined;
|
|
2454
|
+
this.tmpItems[index] = undefined; // TODO: do not try to get "tmpItems" at decoding time.
|
|
2455
2455
|
}
|
|
2456
2456
|
[$onEncodeEnd]() {
|
|
2457
2457
|
this.tmpItems = this.items.slice();
|
|
@@ -2459,6 +2459,7 @@
|
|
|
2459
2459
|
}
|
|
2460
2460
|
[$onDecodeEnd]() {
|
|
2461
2461
|
this.items = this.items.filter((item) => item !== undefined);
|
|
2462
|
+
this.tmpItems = this.items.slice(); // TODO: do no use "tmpItems" at decoding time.
|
|
2462
2463
|
}
|
|
2463
2464
|
toArray() {
|
|
2464
2465
|
return this.items.slice(0);
|
|
@@ -3085,7 +3086,6 @@
|
|
|
3085
3086
|
class Schema {
|
|
3086
3087
|
static { this[_a$2] = encodeSchemaOperation; }
|
|
3087
3088
|
static { this[_b$2] = decodeSchemaOperation; }
|
|
3088
|
-
// public [$changes]: ChangeTree;
|
|
3089
3089
|
/**
|
|
3090
3090
|
* Assign the property descriptors required to track changes on this instance.
|
|
3091
3091
|
* @param instance
|
|
@@ -3217,16 +3217,16 @@
|
|
|
3217
3217
|
/**
|
|
3218
3218
|
* Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
|
|
3219
3219
|
*
|
|
3220
|
-
* @param
|
|
3220
|
+
* @param ref Schema instance
|
|
3221
3221
|
* @param showContents display JSON contents of the instance
|
|
3222
3222
|
* @returns
|
|
3223
3223
|
*/
|
|
3224
|
-
static debugRefIds(
|
|
3225
|
-
const ref = instance;
|
|
3226
|
-
const changeTree = ref[$changes];
|
|
3224
|
+
static debugRefIds(ref, showContents = false, level = 0) {
|
|
3227
3225
|
const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : "";
|
|
3226
|
+
const changeTree = ref[$changes];
|
|
3227
|
+
const refId = changeTree.refId;
|
|
3228
3228
|
let output = "";
|
|
3229
|
-
output += `${getIndent(level)}${ref.constructor.name} (refId: ${
|
|
3229
|
+
output += `${getIndent(level)}${ref.constructor.name} (refId: ${refId})${contents}\n`;
|
|
3230
3230
|
changeTree.forEachChild((childChangeTree) => output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));
|
|
3231
3231
|
return output;
|
|
3232
3232
|
}
|
|
@@ -3751,15 +3751,31 @@
|
|
|
3751
3751
|
}
|
|
3752
3752
|
else {
|
|
3753
3753
|
this.refCount[changeTree.refId] = refCount;
|
|
3754
|
+
//
|
|
3755
|
+
// When losing a reference to an instance, it is best to move the
|
|
3756
|
+
// ChangeTree to the end of the encoding queue.
|
|
3757
|
+
//
|
|
3758
|
+
// This way, at decoding time, the instance that contains the
|
|
3759
|
+
// ChangeTree will be available before the ChangeTree itself. If the
|
|
3760
|
+
// containing instance is not available, the Decoder will throw
|
|
3761
|
+
// "refId not found" error.
|
|
3762
|
+
//
|
|
3763
|
+
if (changeTree.filteredChanges !== undefined) {
|
|
3764
|
+
this.removeChangeFromChangeSet("filteredChanges", changeTree);
|
|
3765
|
+
enqueueChangeTree(this, changeTree, "filteredChanges");
|
|
3766
|
+
}
|
|
3767
|
+
else {
|
|
3768
|
+
this.removeChangeFromChangeSet("changes", changeTree);
|
|
3769
|
+
enqueueChangeTree(this, changeTree, "changes");
|
|
3770
|
+
}
|
|
3754
3771
|
}
|
|
3755
3772
|
changeTree.forEachChild((child, _) => this.remove(child));
|
|
3756
3773
|
return refCount;
|
|
3757
3774
|
}
|
|
3758
3775
|
removeChangeFromChangeSet(changeSetName, changeTree) {
|
|
3759
3776
|
const changeSet = this[changeSetName];
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
spliceOne(changeSet, index);
|
|
3777
|
+
if (spliceOne(changeSet, changeSet.indexOf(changeTree))) {
|
|
3778
|
+
changeTree[changeSetName].queueRootIndex = -1;
|
|
3763
3779
|
// changeSet[index] = undefined;
|
|
3764
3780
|
}
|
|
3765
3781
|
}
|
|
@@ -4041,7 +4057,7 @@
|
|
|
4041
4057
|
const refCount = this.refCounts[refId];
|
|
4042
4058
|
if (refCount === undefined) {
|
|
4043
4059
|
try {
|
|
4044
|
-
throw new DecodingWarning("trying to remove refId that doesn't exist");
|
|
4060
|
+
throw new DecodingWarning("trying to remove refId that doesn't exist: " + refId);
|
|
4045
4061
|
}
|
|
4046
4062
|
catch (e) {
|
|
4047
4063
|
console.warn(e);
|
package/lib/Schema.d.ts
CHANGED
|
@@ -49,11 +49,11 @@ export declare class Schema {
|
|
|
49
49
|
/**
|
|
50
50
|
* Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
|
|
51
51
|
*
|
|
52
|
-
* @param
|
|
52
|
+
* @param ref Schema instance
|
|
53
53
|
* @param showContents display JSON contents of the instance
|
|
54
54
|
* @returns
|
|
55
55
|
*/
|
|
56
|
-
static debugRefIds(
|
|
56
|
+
static debugRefIds(ref: Ref, showContents?: boolean, level?: number): string;
|
|
57
57
|
/**
|
|
58
58
|
* Return a string representation of the changes on a Schema instance.
|
|
59
59
|
* The list of changes is cleared after each encode.
|
package/lib/Schema.js
CHANGED
|
@@ -15,7 +15,6 @@ const utils_1 = require("./utils");
|
|
|
15
15
|
class Schema {
|
|
16
16
|
static { this[_a] = EncodeOperation_1.encodeSchemaOperation; }
|
|
17
17
|
static { this[_b] = DecodeOperation_1.decodeSchemaOperation; }
|
|
18
|
-
// public [$changes]: ChangeTree;
|
|
19
18
|
/**
|
|
20
19
|
* Assign the property descriptors required to track changes on this instance.
|
|
21
20
|
* @param instance
|
|
@@ -147,16 +146,16 @@ class Schema {
|
|
|
147
146
|
/**
|
|
148
147
|
* Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
|
|
149
148
|
*
|
|
150
|
-
* @param
|
|
149
|
+
* @param ref Schema instance
|
|
151
150
|
* @param showContents display JSON contents of the instance
|
|
152
151
|
* @returns
|
|
153
152
|
*/
|
|
154
|
-
static debugRefIds(
|
|
155
|
-
const ref = instance;
|
|
156
|
-
const changeTree = ref[symbols_1.$changes];
|
|
153
|
+
static debugRefIds(ref, showContents = false, level = 0) {
|
|
157
154
|
const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : "";
|
|
155
|
+
const changeTree = ref[symbols_1.$changes];
|
|
156
|
+
const refId = changeTree.refId;
|
|
158
157
|
let output = "";
|
|
159
|
-
output += `${(0, utils_1.getIndent)(level)}${ref.constructor.name} (refId: ${
|
|
158
|
+
output += `${(0, utils_1.getIndent)(level)}${ref.constructor.name} (refId: ${refId})${contents}\n`;
|
|
160
159
|
changeTree.forEachChild((childChangeTree) => output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));
|
|
161
160
|
return output;
|
|
162
161
|
}
|
package/lib/Schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":";;;;AAAA,0CAA4C;AAC5C,+CAAsE;AAItE,qDAAkE;AAClE,6CAA2H;AAG3H,+DAAkE;AAClE,+DAAkE;AAElE,mCAAoC;AAEpC;;GAEG;AACH,MAAa,MAAM;aACR,QAAU,GAAG,uCAAqB,CAAC;aACnC,QAAU,GAAG,uCAAqB,CAAC;IAE1C,iCAAiC;IAEjC;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,QAAa;QAC3B,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,kBAAQ,EAAE;YACtC,KAAK,EAAE,IAAI,uBAAU,CAAC,QAAQ,CAAC;YAC/B,UAAU,EAAE,KAA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C,IAAI,YAAY,gBAAgB,CAAC,KAAK,KAAK,CAAC;oBAC7G,cAAc,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;gBACzC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC;YAC7C,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC;YACvC,MAAM,MAAM,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC;YAEhC,MAAM,WAAW,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,YAAY,UAAU,CAAC,KAAK,gBAAgB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC;YAE/I,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC1B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjC,MAAM,IAAI,GAAG,IAAA,iBAAS,EAAC,KAAK,GAAG,CAAC,CAAC,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,OAAO,GAAG,MAAM,EAAE,CAAC;IACvB,CAAC;;AA5SL,wBA+SC","sourcesContent":["import { OPERATION } from './encoding/spec';\nimport { DEFAULT_VIEW_TAG, type DefinitionType } from \"./annotations\";\n\nimport { NonFunctionPropNames, ToJSON } from './types/HelperTypes';\n\nimport { ChangeSet, ChangeTree, Ref } from './encoder/ChangeTree';\nimport { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $track } from './types/symbols';\nimport { StateView } from './encoder/StateView';\n\nimport { encodeSchemaOperation } from './encoder/EncodeOperation';\nimport { decodeSchemaOperation } from './decoder/DecodeOperation';\nimport type { Metadata } from './Metadata';\nimport { getIndent } from './utils';\n\n/**\n * Schema encoder / decoder\n */\nexport class Schema {\n static [$encoder] = encodeSchemaOperation;\n static [$decoder] = decodeSchemaOperation;\n\n // public [$changes]: ChangeTree;\n\n /**\n * Assign the property descriptors required to track changes on this instance.\n * @param instance\n */\n static initialize(instance: any) {\n Object.defineProperty(instance, $changes, {\n value: new ChangeTree(instance),\n enumerable: false,\n writable: true\n });\n\n Object.defineProperties(instance, instance.constructor[Symbol.metadata]?.[$descriptors] || {});\n }\n\n static is(type: DefinitionType) {\n return typeof(type[Symbol.metadata]) === \"object\";\n // const metadata = type[Symbol.metadata];\n // return metadata && Object.prototype.hasOwnProperty.call(metadata, -1);\n }\n\n /**\n * Track property changes\n */\n static [$track] (changeTree: ChangeTree, index: number, operation: OPERATION = OPERATION.ADD) {\n changeTree.change(index, operation);\n }\n\n /**\n * Determine if a property must be filtered.\n * - If returns false, the property is NOT going to be encoded.\n * - If returns true, the property is going to be encoded.\n *\n * Encoding with \"filters\" happens in two steps:\n * - First, the encoder iterates over all \"not owned\" properties and encodes them.\n * - Then, the encoder iterates over all \"owned\" properties per instance and encodes them.\n */\n static [$filter] (ref: Schema, index: number, view: StateView) {\n const metadata: Metadata = ref.constructor[Symbol.metadata];\n const tag = metadata[index]?.tag;\n\n if (view === undefined) {\n // shared pass/encode: encode if doesn't have a tag\n return tag === undefined;\n\n } else if (tag === undefined) {\n // view pass: no tag\n return true;\n\n } else if (tag === DEFAULT_VIEW_TAG) {\n // view pass: default tag\n return view.items.has(ref[$changes]);\n\n } else {\n // view pass: custom tag\n const tags = view.tags?.get(ref[$changes]);\n return tags && tags.has(tag);\n }\n }\n\n // allow inherited classes to have a constructor\n constructor(...args: any[]) {\n //\n // inline\n // Schema.initialize(this);\n //\n Schema.initialize(this);\n\n //\n // Assign initial values\n //\n if (args[0]) {\n Object.assign(this, args[0]);\n }\n }\n\n public assign(\n props: { [prop in NonFunctionPropNames<this>]?: this[prop] } | ToJSON<this>,\n ) {\n Object.assign(this, props);\n return this;\n }\n\n /**\n * (Server-side): Flag a property to be encoded for the next patch.\n * @param instance Schema instance\n * @param property string representing the property name, or number representing the index of the property.\n * @param operation OPERATION to perform (detected automatically)\n */\n public setDirty<K extends NonFunctionPropNames<this>>(property: K | number, operation?: OPERATION) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n this[$changes].change(\n metadata[metadata[property as string]].index,\n operation\n );\n }\n\n clone (): this {\n const cloned = new ((this as any).constructor);\n const metadata: Metadata = this.constructor[Symbol.metadata];\n\n //\n // TODO: clone all properties, not only annotated ones\n //\n // for (const field in this) {\n for (const fieldIndex in metadata) {\n // const field = metadata[metadata[fieldIndex]].name;\n const field = metadata[fieldIndex as any as number].name;\n\n if (\n typeof (this[field]) === \"object\" &&\n typeof (this[field]?.clone) === \"function\"\n ) {\n // deep clone\n cloned[field] = this[field].clone();\n\n } else {\n // primitive values\n cloned[field] = this[field];\n }\n }\n\n return cloned;\n }\n\n toJSON () {\n const obj: unknown = {};\n const metadata = this.constructor[Symbol.metadata];\n for (const index in metadata) {\n const field = metadata[index];\n const fieldName = field.name;\n if (!field.deprecated && this[fieldName] !== null && typeof (this[fieldName]) !== \"undefined\") {\n obj[fieldName] = (typeof (this[fieldName]['toJSON']) === \"function\")\n ? this[fieldName]['toJSON']()\n : this[fieldName];\n }\n }\n return obj as ToJSON<typeof this>;\n }\n\n discardAllChanges() {\n this[$changes].discardAll();\n }\n\n protected [$getByIndex](index: number) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n return this[metadata[index].name];\n }\n\n protected [$deleteByIndex](index: number) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n this[metadata[index].name] = undefined;\n }\n\n /**\n * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.\n *\n * @param instance Schema instance\n * @param showContents display JSON contents of the instance\n * @returns\n */\n static debugRefIds(instance: Ref, showContents: boolean = false, level: number = 0) {\n const ref = instance;\n const changeTree = ref[$changes];\n\n const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : \"\";\n\n let output = \"\";\n output += `${getIndent(level)}${ref.constructor.name} (refId: ${ref[$changes].refId})${contents}\\n`;\n\n changeTree.forEachChild((childChangeTree) =>\n output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));\n\n return output;\n }\n\n /**\n * Return a string representation of the changes on a Schema instance.\n * The list of changes is cleared after each encode.\n *\n * @param instance Schema instance\n * @param isEncodeAll Return \"full encode\" instead of current change set.\n * @returns\n */\n static debugChanges(instance: Ref, isEncodeAll: boolean = false) {\n const changeTree: ChangeTree = instance[$changes];\n\n const changeSet = (isEncodeAll) ? changeTree.allChanges : changeTree.changes;\n const changeSetName = (isEncodeAll) ? \"allChanges\" : \"changes\";\n\n let output = `${instance.constructor.name} (${changeTree.refId}) -> .${changeSetName}:\\n`;\n\n function dumpChangeSet(changeSet: ChangeSet) {\n changeSet.operations\n .filter(op => op)\n .forEach((index) => {\n const operation = changeTree.indexedOperations[index];\n console.log({ index, operation })\n output += `- [${index}]: ${OPERATION[operation]} (${JSON.stringify(changeTree.getValue(Number(index), isEncodeAll))})\\n`\n });\n }\n\n dumpChangeSet(changeSet);\n\n // display filtered changes\n if (\n !isEncodeAll &&\n changeTree.filteredChanges &&\n (changeTree.filteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${changeTree.refId}) -> .filteredChanges:\\n`;\n dumpChangeSet(changeTree.filteredChanges);\n }\n\n // display filtered changes\n if (\n isEncodeAll &&\n changeTree.allFilteredChanges &&\n (changeTree.allFilteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${changeTree.refId}) -> .allFilteredChanges:\\n`;\n dumpChangeSet(changeTree.allFilteredChanges);\n }\n\n return output;\n }\n\n static debugChangesDeep(ref: Ref, changeSetName: \"changes\" | \"allChanges\" | \"allFilteredChanges\" | \"filteredChanges\" = \"changes\") {\n let output = \"\";\n\n const rootChangeTree = ref[$changes];\n const root = rootChangeTree.root;\n const changeTrees: Map<ChangeTree, ChangeTree[]> = new Map();\n\n const instanceRefIds = [];\n let totalOperations = 0;\n\n for (const [refId, changes] of Object.entries(root[changeSetName])) {\n const changeTree = root.changeTrees[refId];\n\n let includeChangeTree = false;\n let parentChangeTrees: ChangeTree[] = [];\n let parentChangeTree = changeTree.parent?.[$changes];\n\n if (changeTree === rootChangeTree) {\n includeChangeTree = true;\n\n } else {\n while (parentChangeTree !== undefined) {\n parentChangeTrees.push(parentChangeTree);\n if (parentChangeTree.ref === ref) {\n includeChangeTree = true;\n break;\n }\n parentChangeTree = parentChangeTree.parent?.[$changes];\n }\n }\n\n if (includeChangeTree) {\n instanceRefIds.push(changeTree.refId);\n totalOperations += Object.keys(changes).length;\n changeTrees.set(changeTree, parentChangeTrees.reverse());\n }\n }\n\n output += \"---\\n\"\n output += `root refId: ${rootChangeTree.refId}\\n`;\n output += `Total instances: ${instanceRefIds.length} (refIds: ${instanceRefIds.join(\", \")})\\n`;\n output += `Total changes: ${totalOperations}\\n`;\n output += \"---\\n\"\n\n // based on root.changes, display a tree of changes that has the \"ref\" instance as parent\n const visitedParents = new WeakSet<ChangeTree>();\n for (const [changeTree, parentChangeTrees] of changeTrees.entries()) {\n parentChangeTrees.forEach((parentChangeTree, level) => {\n if (!visitedParents.has(parentChangeTree)) {\n output += `${getIndent(level)}${parentChangeTree.ref.constructor.name} (refId: ${parentChangeTree.refId})\\n`;\n visitedParents.add(parentChangeTree);\n }\n });\n\n const changes = changeTree.indexedOperations;\n const level = parentChangeTrees.length;\n const indent = getIndent(level);\n\n const parentIndex = (level > 0) ? `(${changeTree.parentIndex}) ` : \"\";\n output += `${indent}${parentIndex}${changeTree.ref.constructor.name} (refId: ${changeTree.refId}) - changes: ${Object.keys(changes).length}\\n`;\n\n for (const index in changes) {\n const operation = changes[index];\n output += `${getIndent(level + 1)}${OPERATION[operation]}: ${index}\\n`;\n }\n }\n\n return `${output}`;\n }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G,CAAC,CAAC,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,OAAO,GAAG,MAAM,EAAE,CAAC;IACvB,CAAC;;AA1SL,wBA6SC","sourcesContent":["import { OPERATION } from './encoding/spec';\nimport { DEFAULT_VIEW_TAG, type DefinitionType } from \"./annotations\";\n\nimport { NonFunctionPropNames, ToJSON } from './types/HelperTypes';\n\nimport { ChangeSet, ChangeTree, Ref } from './encoder/ChangeTree';\nimport { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $track } from './types/symbols';\nimport { StateView } from './encoder/StateView';\n\nimport { encodeSchemaOperation } from './encoder/EncodeOperation';\nimport { decodeSchemaOperation } from './decoder/DecodeOperation';\nimport type { Metadata } from './Metadata';\nimport { getIndent } from './utils';\n\n/**\n * Schema encoder / decoder\n */\nexport class Schema {\n static [$encoder] = encodeSchemaOperation;\n static [$decoder] = decodeSchemaOperation;\n\n /**\n * Assign the property descriptors required to track changes on this instance.\n * @param instance\n */\n static initialize(instance: any) {\n Object.defineProperty(instance, $changes, {\n value: new ChangeTree(instance),\n enumerable: false,\n writable: true\n });\n\n Object.defineProperties(instance, instance.constructor[Symbol.metadata]?.[$descriptors] || {});\n }\n\n static is(type: DefinitionType) {\n return typeof(type[Symbol.metadata]) === \"object\";\n // const metadata = type[Symbol.metadata];\n // return metadata && Object.prototype.hasOwnProperty.call(metadata, -1);\n }\n\n /**\n * Track property changes\n */\n static [$track] (changeTree: ChangeTree, index: number, operation: OPERATION = OPERATION.ADD) {\n changeTree.change(index, operation);\n }\n\n /**\n * Determine if a property must be filtered.\n * - If returns false, the property is NOT going to be encoded.\n * - If returns true, the property is going to be encoded.\n *\n * Encoding with \"filters\" happens in two steps:\n * - First, the encoder iterates over all \"not owned\" properties and encodes them.\n * - Then, the encoder iterates over all \"owned\" properties per instance and encodes them.\n */\n static [$filter] (ref: Schema, index: number, view: StateView) {\n const metadata: Metadata = ref.constructor[Symbol.metadata];\n const tag = metadata[index]?.tag;\n\n if (view === undefined) {\n // shared pass/encode: encode if doesn't have a tag\n return tag === undefined;\n\n } else if (tag === undefined) {\n // view pass: no tag\n return true;\n\n } else if (tag === DEFAULT_VIEW_TAG) {\n // view pass: default tag\n return view.items.has(ref[$changes]);\n\n } else {\n // view pass: custom tag\n const tags = view.tags?.get(ref[$changes]);\n return tags && tags.has(tag);\n }\n }\n\n // allow inherited classes to have a constructor\n constructor(...args: any[]) {\n //\n // inline\n // Schema.initialize(this);\n //\n Schema.initialize(this);\n\n //\n // Assign initial values\n //\n if (args[0]) {\n Object.assign(this, args[0]);\n }\n }\n\n public assign(\n props: { [prop in NonFunctionPropNames<this>]?: this[prop] } | ToJSON<this>,\n ) {\n Object.assign(this, props);\n return this;\n }\n\n /**\n * (Server-side): Flag a property to be encoded for the next patch.\n * @param instance Schema instance\n * @param property string representing the property name, or number representing the index of the property.\n * @param operation OPERATION to perform (detected automatically)\n */\n public setDirty<K extends NonFunctionPropNames<this>>(property: K | number, operation?: OPERATION) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n this[$changes].change(\n metadata[metadata[property as string]].index,\n operation\n );\n }\n\n clone (): this {\n const cloned = new ((this as any).constructor);\n const metadata: Metadata = this.constructor[Symbol.metadata];\n\n //\n // TODO: clone all properties, not only annotated ones\n //\n // for (const field in this) {\n for (const fieldIndex in metadata) {\n // const field = metadata[metadata[fieldIndex]].name;\n const field = metadata[fieldIndex as any as number].name;\n\n if (\n typeof (this[field]) === \"object\" &&\n typeof (this[field]?.clone) === \"function\"\n ) {\n // deep clone\n cloned[field] = this[field].clone();\n\n } else {\n // primitive values\n cloned[field] = this[field];\n }\n }\n\n return cloned;\n }\n\n toJSON () {\n const obj: unknown = {};\n const metadata = this.constructor[Symbol.metadata];\n for (const index in metadata) {\n const field = metadata[index];\n const fieldName = field.name;\n if (!field.deprecated && this[fieldName] !== null && typeof (this[fieldName]) !== \"undefined\") {\n obj[fieldName] = (typeof (this[fieldName]['toJSON']) === \"function\")\n ? this[fieldName]['toJSON']()\n : this[fieldName];\n }\n }\n return obj as ToJSON<typeof this>;\n }\n\n discardAllChanges() {\n this[$changes].discardAll();\n }\n\n protected [$getByIndex](index: number) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n return this[metadata[index].name];\n }\n\n protected [$deleteByIndex](index: number) {\n const metadata: Metadata = this.constructor[Symbol.metadata];\n this[metadata[index].name] = undefined;\n }\n\n /**\n * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.\n *\n * @param ref Schema instance\n * @param showContents display JSON contents of the instance\n * @returns\n */\n static debugRefIds(ref: Ref, showContents: boolean = false, level: number = 0) {\n const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : \"\";\n\n const changeTree: ChangeTree = ref[$changes];\n const refId = changeTree.refId;\n\n let output = \"\";\n output += `${getIndent(level)}${ref.constructor.name} (refId: ${refId})${contents}\\n`;\n\n changeTree.forEachChild((childChangeTree) =>\n output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));\n\n return output;\n }\n\n /**\n * Return a string representation of the changes on a Schema instance.\n * The list of changes is cleared after each encode.\n *\n * @param instance Schema instance\n * @param isEncodeAll Return \"full encode\" instead of current change set.\n * @returns\n */\n static debugChanges(instance: Ref, isEncodeAll: boolean = false) {\n const changeTree: ChangeTree = instance[$changes];\n\n const changeSet = (isEncodeAll) ? changeTree.allChanges : changeTree.changes;\n const changeSetName = (isEncodeAll) ? \"allChanges\" : \"changes\";\n\n let output = `${instance.constructor.name} (${changeTree.refId}) -> .${changeSetName}:\\n`;\n\n function dumpChangeSet(changeSet: ChangeSet) {\n changeSet.operations\n .filter(op => op)\n .forEach((index) => {\n const operation = changeTree.indexedOperations[index];\n console.log({ index, operation })\n output += `- [${index}]: ${OPERATION[operation]} (${JSON.stringify(changeTree.getValue(Number(index), isEncodeAll))})\\n`\n });\n }\n\n dumpChangeSet(changeSet);\n\n // display filtered changes\n if (\n !isEncodeAll &&\n changeTree.filteredChanges &&\n (changeTree.filteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${changeTree.refId}) -> .filteredChanges:\\n`;\n dumpChangeSet(changeTree.filteredChanges);\n }\n\n // display filtered changes\n if (\n isEncodeAll &&\n changeTree.allFilteredChanges &&\n (changeTree.allFilteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${changeTree.refId}) -> .allFilteredChanges:\\n`;\n dumpChangeSet(changeTree.allFilteredChanges);\n }\n\n return output;\n }\n\n static debugChangesDeep(ref: Ref, changeSetName: \"changes\" | \"allChanges\" | \"allFilteredChanges\" | \"filteredChanges\" = \"changes\") {\n let output = \"\";\n\n const rootChangeTree = ref[$changes];\n const root = rootChangeTree.root;\n const changeTrees: Map<ChangeTree, ChangeTree[]> = new Map();\n\n const instanceRefIds = [];\n let totalOperations = 0;\n\n for (const [refId, changes] of Object.entries(root[changeSetName])) {\n const changeTree = root.changeTrees[refId];\n\n let includeChangeTree = false;\n let parentChangeTrees: ChangeTree[] = [];\n let parentChangeTree = changeTree.parent?.[$changes];\n\n if (changeTree === rootChangeTree) {\n includeChangeTree = true;\n\n } else {\n while (parentChangeTree !== undefined) {\n parentChangeTrees.push(parentChangeTree);\n if (parentChangeTree.ref === ref) {\n includeChangeTree = true;\n break;\n }\n parentChangeTree = parentChangeTree.parent?.[$changes];\n }\n }\n\n if (includeChangeTree) {\n instanceRefIds.push(changeTree.refId);\n totalOperations += Object.keys(changes).length;\n changeTrees.set(changeTree, parentChangeTrees.reverse());\n }\n }\n\n output += \"---\\n\"\n output += `root refId: ${rootChangeTree.refId}\\n`;\n output += `Total instances: ${instanceRefIds.length} (refIds: ${instanceRefIds.join(\", \")})\\n`;\n output += `Total changes: ${totalOperations}\\n`;\n output += \"---\\n\"\n\n // based on root.changes, display a tree of changes that has the \"ref\" instance as parent\n const visitedParents = new WeakSet<ChangeTree>();\n for (const [changeTree, parentChangeTrees] of changeTrees.entries()) {\n parentChangeTrees.forEach((parentChangeTree, level) => {\n if (!visitedParents.has(parentChangeTree)) {\n output += `${getIndent(level)}${parentChangeTree.ref.constructor.name} (refId: ${parentChangeTree.refId})\\n`;\n visitedParents.add(parentChangeTree);\n }\n });\n\n const changes = changeTree.indexedOperations;\n const level = parentChangeTrees.length;\n const indent = getIndent(level);\n\n const parentIndex = (level > 0) ? `(${changeTree.parentIndex}) ` : \"\";\n output += `${indent}${parentIndex}${changeTree.ref.constructor.name} (refId: ${changeTree.refId}) - changes: ${Object.keys(changes).length}\\n`;\n\n for (const index in changes) {\n const operation = changes[index];\n output += `${getIndent(level + 1)}${OPERATION[operation]}: ${index}\\n`;\n }\n }\n\n return `${output}`;\n }\n\n\n}\n\n"]}
|
|
@@ -43,7 +43,7 @@ class ReferenceTracker {
|
|
|
43
43
|
const refCount = this.refCounts[refId];
|
|
44
44
|
if (refCount === undefined) {
|
|
45
45
|
try {
|
|
46
|
-
throw new DecodingWarning("trying to remove refId that doesn't exist");
|
|
46
|
+
throw new DecodingWarning("trying to remove refId that doesn't exist: " + refId);
|
|
47
47
|
}
|
|
48
48
|
catch (e) {
|
|
49
49
|
console.warn(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferenceTracker.js","sourceRoot":"","sources":["../../src/decoder/ReferenceTracker.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,8CAA8C;AAE9C,0CAA2C;AAE3C,2CAA6C;AAE7C,MAAM,eAAgB,SAAQ,KAAK;IAC/B,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAQD,MAAa,gBAAgB;IAA7B;QACI,EAAE;QACF,wCAAwC;QACxC,wDAAwD;QACxD,EAAE;QACK,SAAI,GAAG,IAAI,GAAG,EAAe,CAAC;QAC9B,WAAM,GAAG,IAAI,OAAO,EAAe,CAAC;QAEpC,cAAS,GAAiC,E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\";\nimport { Ref } from \"../encoder/ChangeTree\";\nimport { spliceOne } from \"../types/utils\";\nimport type { MapSchema } from \"../types/custom/MapSchema\";\nimport { OPERATION } from \"../encoding/spec\";\n\nclass DecodingWarning extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"DecodingWarning\";\n }\n}\n\n/**\n * Used for decoding only.\n */\n\nexport type SchemaCallbacks = { [field: string | number]: Function[] };\n\nexport class ReferenceTracker {\n //\n // Relation of refId => Schema structure\n // For direct access of structures during decoding time.\n //\n public refs = new Map<number, Ref>();\n public refIds = new WeakMap<Ref, number>();\n\n public refCounts: { [refId: number]: number; } = {};\n public deletedRefs = new Set<number>();\n\n public callbacks: { [refId: number]: SchemaCallbacks } = {};\n protected nextUniqueId: number = 0;\n\n getNextUniqueId() {\n return this.nextUniqueId++;\n }\n\n // for decoding\n addRef(refId: number, ref: Ref, incrementCount: boolean = true) {\n this.refs.set(refId, ref);\n this.refIds.set(ref, refId);\n\n if (incrementCount) {\n this.refCounts[refId] = (this.refCounts[refId] || 0) + 1;\n }\n\n if (this.deletedRefs.has(refId)) {\n this.deletedRefs.delete(refId);\n }\n }\n\n // for decoding\n removeRef(refId: number) {\n const refCount = this.refCounts[refId];\n\n if (refCount === undefined) {\n try {\n throw new DecodingWarning(\"trying to remove refId that doesn't exist: \" + refId);\n } catch (e) {\n console.warn(e);\n }\n return;\n }\n\n if (refCount === 0) {\n try {\n const ref = this.refs.get(refId);\n throw new DecodingWarning(`trying to remove refId '${refId}' with 0 refCount (${ref.constructor.name}: ${JSON.stringify(ref)})`);\n } catch (e) {\n console.warn(e);\n }\n return;\n }\n\n if ((this.refCounts[refId] = refCount - 1) <= 0) {\n this.deletedRefs.add(refId);\n }\n }\n\n clearRefs() {\n this.refs.clear();\n this.deletedRefs.clear();\n this.callbacks = {};\n this.refCounts = {};\n }\n\n // for decoding\n garbageCollectDeletedRefs() {\n this.deletedRefs.forEach((refId) => {\n //\n // Skip active references.\n //\n if (this.refCounts[refId] > 0) { return; }\n\n const ref = this.refs.get(refId);\n\n //\n // Ensure child schema instances have their references removed as well.\n //\n if (Metadata.isValidInstance(ref)) {\n const metadata: Metadata = ref.constructor[Symbol.metadata];\n for (const index in metadata) {\n const field = metadata[index as any as number].name;\n const childRefId = typeof(ref[field]) === \"object\" && this.refIds.get(ref[field]);\n if (childRefId) {\n this.removeRef(childRefId);\n }\n }\n\n } else {\n if (typeof (Object.values(ref[$childType])[0]) === \"function\") {\n Array.from((ref as MapSchema).values())\n .forEach((child) => this.removeRef(this.refIds.get(child)));\n }\n }\n\n this.refs.delete(refId); // remove ref\n delete this.refCounts[refId]; // remove ref count\n delete this.callbacks[refId]; // remove callbacks\n });\n\n // clear deleted refs.\n this.deletedRefs.clear();\n }\n\n addCallback(refId: number, fieldOrOperation: string | number, callback: Function) {\n if (refId === undefined) {\n const name = (typeof(fieldOrOperation) === \"number\")\n ? OPERATION[fieldOrOperation]\n : fieldOrOperation\n throw new Error(\n `Can't addCallback on '${name}' (refId is undefined)`\n );\n }\n if (!this.callbacks[refId]) {\n this.callbacks[refId] = {};\n }\n if (!this.callbacks[refId][fieldOrOperation]) {\n this.callbacks[refId][fieldOrOperation] = [];\n }\n this.callbacks[refId][fieldOrOperation].push(callback);\n return () => this.removeCallback(refId, fieldOrOperation, callback);\n }\n\n removeCallback(refId: number, field: string | number, callback: Function) {\n const index = this.callbacks?.[refId]?.[field]?.indexOf(callback);\n if (index !== -1) {\n spliceOne(this.callbacks[refId][field], index);\n }\n }\n\n}\n"]}
|
|
@@ -29,6 +29,7 @@ export interface ChangeSet {
|
|
|
29
29
|
}
|
|
30
30
|
export declare function setOperationAtIndex(changeSet: ChangeSet, index: number): void;
|
|
31
31
|
export declare function deleteOperationAtIndex(changeSet: ChangeSet, index: number): void;
|
|
32
|
+
export declare function enqueueChangeTree(root: Root, changeTree: ChangeTree, changeSet: 'changes' | 'filteredChanges' | 'allFilteredChanges', queueRootIndex?: number): void;
|
|
32
33
|
export declare class ChangeTree<T extends Ref = any> {
|
|
33
34
|
ref: T;
|
|
34
35
|
refId: number;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ChangeTree = void 0;
|
|
4
4
|
exports.setOperationAtIndex = setOperationAtIndex;
|
|
5
5
|
exports.deleteOperationAtIndex = deleteOperationAtIndex;
|
|
6
|
+
exports.enqueueChangeTree = enqueueChangeTree;
|
|
6
7
|
const spec_1 = require("../encoding/spec");
|
|
7
8
|
const symbols_1 = require("../types/symbols");
|
|
8
9
|
const Metadata_1 = require("../Metadata");
|
|
@@ -287,6 +288,7 @@ class ChangeTree {
|
|
|
287
288
|
//
|
|
288
289
|
this.root?.remove(previousValue[symbols_1.$changes]);
|
|
289
290
|
}
|
|
291
|
+
deleteOperationAtIndex(this.allChanges, allChangesIndex);
|
|
290
292
|
//
|
|
291
293
|
// FIXME: this is looking a ugly and repeated
|
|
292
294
|
//
|
|
@@ -295,7 +297,6 @@ class ChangeTree {
|
|
|
295
297
|
enqueueChangeTree(this.root, this, 'filteredChanges');
|
|
296
298
|
}
|
|
297
299
|
else {
|
|
298
|
-
deleteOperationAtIndex(this.allChanges, allChangesIndex);
|
|
299
300
|
enqueueChangeTree(this.root, this, 'changes');
|
|
300
301
|
}
|
|
301
302
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChangeTree.js","sourceRoot":"","sources":["../../src/encoder/ChangeTree.ts"],"names":[],"mappings":";;;AA+CA,kDAOC;AAED,wDAMC;AA9DD,2CAA6C;AAE7C,8CAAgJ;AAQhJ,0CAAuC;AAqCvC,SAAgB,mBAAmB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,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AC,EAAE,CAAC;gBACrC,yBAAyB;gBACzB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;gBAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC;gBACpC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;gBAE/B,+BAA+B;gBAC/B,MAAM,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;gBACnD,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,UAAU,CAAC;gBAC1C,IAAI,CAAC,UAAU,GAAG,kBAAkB,CAAC;YACzC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAveD,gCAueC","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { Schema } from \"../Schema\";\nimport { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refTypeFieldIndexes, $viewFieldIndexes } from \"../types/symbols\";\n\nimport type { MapSchema } from \"../types/custom/MapSchema\";\nimport type { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { CollectionSchema } from \"../types/custom/CollectionSchema\";\nimport type { SetSchema } from \"../types/custom/SetSchema\";\n\nimport { Root } from \"./Root\";\nimport { Metadata } from \"../Metadata\";\nimport type { EncodeOperation } from \"./EncodeOperation\";\nimport type { DecodeOperation } from \"../decoder/DecodeOperation\";\nimport { TypeContext } from \"../types/TypeContext\";\nimport { ReferenceTracker } from \"../decoder/ReferenceTracker\";\n\ndeclare global {\n interface Object {\n // FIXME: not a good practice to extend globals here\n [$changes]?: ChangeTree;\n [$encoder]?: EncodeOperation,\n [$decoder]?: DecodeOperation,\n }\n}\n\nexport type Ref = Schema\n | ArraySchema\n | MapSchema\n | CollectionSchema\n | SetSchema;\n\nexport type ChangeSetName = \"changes\"\n | \"allChanges\"\n | \"filteredChanges\"\n | \"allFilteredChanges\";\n\nexport interface IndexedOperations {\n [index: number]: OPERATION;\n}\n\nexport interface ChangeSet {\n // field index -> operation index\n indexes: { [index: number]: number };\n operations: OPERATION[]\n queueRootIndex?: number; // index of ChangeTree structure in `root.changes` or `root.filteredChanges`\n}\n\nexport function setOperationAtIndex(changeSet: ChangeSet, index: number) {\n const operationsIndex = changeSet.indexes[index];\n if (operationsIndex === undefined) {\n changeSet.indexes[index] = changeSet.operations.push(index) - 1;\n } else {\n changeSet.operations[operationsIndex] = index;\n }\n}\n\nexport function deleteOperationAtIndex(changeSet: ChangeSet, index: number) {\n const operationsIndex = changeSet.indexes[index];\n if (operationsIndex !== undefined) {\n changeSet.operations[operationsIndex] = undefined;\n }\n delete changeSet.indexes[index];\n}\n\nfunction enqueueChangeTree(\n root: Root,\n changeTree: ChangeTree,\n changeSet: 'changes' | 'filteredChanges' | 'allFilteredChanges',\n queueRootIndex = changeTree[changeSet].queueRootIndex\n) {\n if (root && root[changeSet][queueRootIndex] !== changeTree) {\n changeTree[changeSet].queueRootIndex = root[changeSet].push(changeTree) - 1;\n }\n}\n\nexport class ChangeTree<T extends Ref=any> {\n ref: T;\n refId: number;\n\n root?: Root;\n parent?: Ref;\n parentIndex?: number;\n\n /**\n * Whether this structure is parent of a filtered structure.\n */\n isFiltered: boolean = false;\n\n indexedOperations: IndexedOperations = {};\n\n //\n // TODO:\n // try storing the index + operation per item.\n // example: 1024 & 1025 => ADD, 1026 => DELETE\n //\n // => https://chatgpt.com/share/67107d0c-bc20-8004-8583-83b17dd7c196\n //\n changes: ChangeSet = { indexes: {}, operations: [] };\n allChanges: ChangeSet = { indexes: {}, operations: [] };\n filteredChanges: ChangeSet;\n allFilteredChanges: ChangeSet;\n\n indexes: {[index: string]: any}; // TODO: remove this, only used by MapSchema/SetSchema/CollectionSchema (`encodeKeyValueOperation`)\n\n /**\n * Is this a new instance? Used on ArraySchema to determine OPERATION.MOVE_AND_ADD operation.\n */\n isNew = true;\n\n constructor(ref: T) {\n this.ref = ref;\n\n //\n // Does this structure have \"filters\" declared?\n //\n const metadata = ref.constructor[Symbol.metadata];\n if (metadata?.[$viewFieldIndexes]) {\n this.allFilteredChanges = { indexes: {}, operations: [] };\n this.filteredChanges = { indexes: {}, operations: [] };\n }\n }\n\n setRoot(root: Root) {\n this.root = root;\n this.checkIsFiltered(this.parent, this.parentIndex);\n\n // Recursively set root on child structures\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n value?.[$changes].setRoot(root);\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n value[$changes].setRoot(root);\n });\n }\n\n }\n\n setParent(\n parent: Ref,\n root?: Root,\n parentIndex?: number,\n ) {\n this.parent = parent;\n this.parentIndex = parentIndex;\n\n // avoid setting parents with empty `root`\n if (!root) { return; }\n\n // skip if parent is already set\n if (root !== this.root) {\n this.root = root;\n this.checkIsFiltered(parent, parentIndex);\n\n } else {\n root.add(this);\n }\n\n // assign same parent on child structures\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n value?.[$changes].setParent(this.ref, root, index);\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n value[$changes].setParent(this.ref, root, this.indexes[key] ?? key);\n });\n }\n\n }\n\n forEachChild(callback: (change: ChangeTree, atIndex: number) => void) {\n //\n // assign same parent on child structures\n //\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n if (value) {\n callback(value[$changes], index);\n }\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n callback(value[$changes], this.indexes[key] ?? key);\n });\n }\n }\n\n operation(op: OPERATION) {\n // operations without index use negative values to represent them\n // this is checked during .encode() time.\n this.changes.operations.push(-op);\n\n enqueueChangeTree(this.root, this, 'changes');\n }\n\n change(index: number, operation: OPERATION = OPERATION.ADD) {\n const metadata = this.ref.constructor[Symbol.metadata] as Metadata;\n\n const isFiltered = this.isFiltered || (metadata?.[index]?.tag !== undefined);\n const changeSet = (isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const previousOperation = this.indexedOperations[index];\n if (!previousOperation || previousOperation === OPERATION.DELETE) {\n const op = (!previousOperation)\n ? operation\n : (previousOperation === OPERATION.DELETE)\n ? OPERATION.DELETE_AND_ADD\n : operation\n //\n // TODO: are DELETE operations being encoded as ADD here ??\n //\n this.indexedOperations[index] = op;\n }\n\n setOperationAtIndex(changeSet, index);\n\n if (isFiltered) {\n setOperationAtIndex(this.allFilteredChanges, index);\n\n if (this.root) {\n enqueueChangeTree(this.root, this, 'filteredChanges');\n enqueueChangeTree(this.root, this, 'allFilteredChanges');\n }\n\n } else {\n setOperationAtIndex(this.allChanges, index);\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n shiftChangeIndexes(shiftIndex: number) {\n //\n // Used only during:\n //\n // - ArraySchema#unshift()\n //\n const changeSet = (this.isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const newIndexedOperations = {};\n const newIndexes = {};\n for (const index in this.indexedOperations) {\n newIndexedOperations[Number(index) + shiftIndex] = this.indexedOperations[index];\n newIndexes[Number(index) + shiftIndex] = changeSet[index];\n }\n this.indexedOperations = newIndexedOperations;\n changeSet.indexes = newIndexes;\n\n changeSet.operations = changeSet.operations.map((index) => index + shiftIndex);\n }\n\n shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0) {\n //\n // Used only during:\n //\n // - ArraySchema#splice()\n //\n if (this.filteredChanges !== undefined) {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allFilteredChanges);\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n\n } else {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n }\n }\n\n private _shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0, changeSet: ChangeSet) {\n const newIndexes = {};\n\n for (const key in changeSet.indexes) {\n const index = changeSet.indexes[key];\n if (index > startIndex) {\n newIndexes[Number(key) + shiftIndex] = index;\n } else {\n newIndexes[key] = index;\n }\n }\n changeSet.indexes = newIndexes;\n\n for (let i = 0; i < changeSet.operations.length; i++) {\n const index = changeSet.operations[i];\n if (index > startIndex) {\n changeSet.operations[i] = index + shiftIndex;\n }\n }\n }\n\n indexedOperation(index: number, operation: OPERATION, allChangesIndex: number = index) {\n this.indexedOperations[index] = operation;\n\n if (this.filteredChanges !== undefined) {\n setOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n setOperationAtIndex(this.filteredChanges, index);\n enqueueChangeTree(this.root, this, 'filteredChanges');\n\n } else {\n setOperationAtIndex(this.allChanges, allChangesIndex);\n setOperationAtIndex(this.changes, index);\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n getType(index?: number) {\n if (Metadata.isValidInstance(this.ref)) {\n const metadata = this.ref.constructor[Symbol.metadata] as Metadata;\n return metadata[index].type;\n\n } else {\n //\n // Get the child type from parent structure.\n // - [\"string\"] => \"string\"\n // - { map: \"string\" } => \"string\"\n // - { set: \"string\" } => \"string\"\n //\n return this.ref[$childType];\n }\n }\n\n getChange(index: number) {\n return this.indexedOperations[index];\n }\n\n //\n // used during `.encode()`\n //\n getValue(index: number, isEncodeAll: boolean = false) {\n //\n // `isEncodeAll` param is only used by ArraySchema\n //\n return this.ref[$getByIndex](index, isEncodeAll);\n }\n\n delete(index: number, operation?: OPERATION, allChangesIndex = index) {\n if (index === undefined) {\n try {\n throw new Error(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index '${index}'`);\n } catch (e) {\n console.warn(e);\n }\n return;\n }\n\n const changeSet = (this.filteredChanges !== undefined)\n ? this.filteredChanges\n : this.changes;\n\n this.indexedOperations[index] = operation ?? OPERATION.DELETE;\n setOperationAtIndex(changeSet, index);\n\n const previousValue = this.getValue(index);\n\n // remove `root` reference\n if (previousValue && previousValue[$changes]) {\n //\n // FIXME: this.root is \"undefined\"\n //\n // This method is being called at decoding time when a DELETE operation is found.\n //\n // - This is due to using the concrete Schema class at decoding time.\n // - \"Reflected\" structures do not have this problem.\n //\n // (The property descriptors should NOT be used at decoding time. only at encoding time.)\n //\n this.root?.remove(previousValue[$changes]);\n }\n\n //\n // FIXME: this is looking a ugly and repeated\n //\n if (this.filteredChanges !== undefined) {\n deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n enqueueChangeTree(this.root, this, 'filteredChanges');\n\n } else {\n deleteOperationAtIndex(this.allChanges, allChangesIndex);\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n endEncode() {\n this.indexedOperations = {};\n\n // // clear changes\n // this.changes.indexes = {};\n // this.changes.operations.length = 0;\n\n // ArraySchema and MapSchema have a custom \"encode end\" method\n this.ref[$onEncodeEnd]?.();\n\n // Not a new instance anymore\n this.isNew = false;\n }\n\n discard(discardAll: boolean = false) {\n //\n // > MapSchema:\n // Remove cached key to ensure ADD operations is unsed instead of\n // REPLACE in case same key is used on next patches.\n //\n this.ref[$onEncodeEnd]?.();\n\n this.indexedOperations = {};\n\n this.changes.indexes = {};\n this.changes.operations.length = 0;\n this.changes.queueRootIndex = undefined;\n\n if (this.filteredChanges !== undefined) {\n this.filteredChanges.indexes = {};\n this.filteredChanges.operations.length = 0;\n this.filteredChanges.queueRootIndex = undefined;\n }\n\n if (discardAll) {\n this.allChanges.indexes = {};\n this.allChanges.operations.length = 0;\n\n if (this.allFilteredChanges !== undefined) {\n this.allFilteredChanges.indexes = {};\n this.allFilteredChanges.operations.length = 0;\n }\n\n // remove children references\n this.forEachChild((changeTree, _) =>\n this.root?.remove(changeTree));\n }\n }\n\n /**\n * Recursively discard all changes from this, and child structures.\n */\n discardAll() {\n const keys = Object.keys(this.indexedOperations);\n for (let i = 0, len = keys.length; i < len; i++) {\n const value = this.getValue(Number(keys[i]));\n\n if (value && value[$changes]) {\n value[$changes].discardAll();\n }\n }\n\n this.discard();\n }\n\n ensureRefId() {\n // skip if refId is already set.\n if (this.refId !== undefined) {\n return;\n }\n\n this.refId = this.root.getNextUniqueId();\n }\n\n get changed() {\n return (Object.entries(this.indexedOperations).length > 0);\n }\n\n protected checkIsFiltered(parent: Ref, parentIndex: number) {\n const isNewChangeTree = this.root.add(this);\n\n if (this.root.types.hasFilters) {\n //\n // At Schema initialization, the \"root\" structure might not be available\n // yet, as it only does once the \"Encoder\" has been set up.\n //\n // So the \"parent\" may be already set without a \"root\".\n //\n this._checkFilteredByParent(parent, parentIndex);\n\n if (this.filteredChanges !== undefined) {\n enqueueChangeTree(this.root, this, 'filteredChanges');\n if (isNewChangeTree) {\n this.root.allFilteredChanges.push(this);\n }\n }\n }\n\n if (!this.isFiltered) {\n enqueueChangeTree(this.root, this, 'changes');\n if (isNewChangeTree) {\n this.root.allChanges.push(this);\n }\n }\n }\n\n protected _checkFilteredByParent(parent: Ref, parentIndex: number) {\n // skip if parent is not set\n if (!parent) { return; }\n\n //\n // ArraySchema | MapSchema - get the child type\n // (if refType is typeof string, the parentFiltered[key] below will always be invalid)\n //\n const refType = Metadata.isValidInstance(this.ref)\n ? this.ref.constructor\n : this.ref[$childType];\n\n if (!Metadata.isValidInstance(parent)) {\n const parentChangeTree = parent[$changes];\n parent = parentChangeTree.parent;\n parentIndex = parentChangeTree.parentIndex;\n }\n\n const parentConstructor = parent.constructor as typeof Schema;\n\n let key = `${this.root.types.getTypeId(refType as typeof Schema)}`;\n if (parentConstructor) {\n key += `-${this.root.types.schemas.get(parentConstructor)}`;\n }\n key += `-${parentIndex}`;\n\n this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered\n || this.root.types.parentFiltered[key];\n\n // const parentMetadata = parentConstructor?.[Symbol.metadata];\n // this.isFiltered = parentMetadata?.[$viewFieldIndexes]?.includes(parentIndex) || this.root.types.parentFiltered[key];\n\n //\n // TODO: refactor this!\n //\n // swapping `changes` and `filteredChanges` is required here\n // because \"isFiltered\" may not be imedialely available on `change()`\n // (this happens when instance is detached from root or parent)\n //\n if (this.isFiltered) {\n this.filteredChanges = { indexes: {}, operations: [] };\n this.allFilteredChanges = { indexes: {}, operations: [] };\n\n if (this.changes.operations.length > 0) {\n // swap changes reference\n const changes = this.changes;\n this.changes = this.filteredChanges;\n this.filteredChanges = changes;\n\n // swap \"all changes\" reference\n const allFilteredChanges = this.allFilteredChanges;\n this.allFilteredChanges = this.allChanges;\n this.allChanges = allFilteredChanges;\n }\n }\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ChangeTree.js","sourceRoot":"","sources":["../../src/encoder/ChangeTree.ts"],"names":[],"mappings":";;;AA+CA,kDAOC;AAED,wDAMC;AAED,8CASC;AAzED,2CAA6C;AAE7C,8CAAgJ;AAQhJ,0CAAuC;AAqCvC,SAAgB,mBAAmB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;SAAM,CAAC;QACJ,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC;IAClD,CAAC;AACL,CAAC;AAED,SAAgB,sBAAsB,CAAC,SAAoB,EAAE,KAAa;IACtE,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;IACtD,CAAC;I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C;YACzC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAxeD,gCAweC","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { Schema } from \"../Schema\";\nimport { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refTypeFieldIndexes, $viewFieldIndexes } from \"../types/symbols\";\n\nimport type { MapSchema } from \"../types/custom/MapSchema\";\nimport type { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { CollectionSchema } from \"../types/custom/CollectionSchema\";\nimport type { SetSchema } from \"../types/custom/SetSchema\";\n\nimport { Root } from \"./Root\";\nimport { Metadata } from \"../Metadata\";\nimport type { EncodeOperation } from \"./EncodeOperation\";\nimport type { DecodeOperation } from \"../decoder/DecodeOperation\";\nimport { TypeContext } from \"../types/TypeContext\";\nimport { ReferenceTracker } from \"../decoder/ReferenceTracker\";\n\ndeclare global {\n interface Object {\n // FIXME: not a good practice to extend globals here\n [$changes]?: ChangeTree;\n [$encoder]?: EncodeOperation,\n [$decoder]?: DecodeOperation,\n }\n}\n\nexport type Ref = Schema\n | ArraySchema\n | MapSchema\n | CollectionSchema\n | SetSchema;\n\nexport type ChangeSetName = \"changes\"\n | \"allChanges\"\n | \"filteredChanges\"\n | \"allFilteredChanges\";\n\nexport interface IndexedOperations {\n [index: number]: OPERATION;\n}\n\nexport interface ChangeSet {\n // field index -> operation index\n indexes: { [index: number]: number };\n operations: OPERATION[]\n queueRootIndex?: number; // index of ChangeTree structure in `root.changes` or `root.filteredChanges`\n}\n\nexport function setOperationAtIndex(changeSet: ChangeSet, index: number) {\n const operationsIndex = changeSet.indexes[index];\n if (operationsIndex === undefined) {\n changeSet.indexes[index] = changeSet.operations.push(index) - 1;\n } else {\n changeSet.operations[operationsIndex] = index;\n }\n}\n\nexport function deleteOperationAtIndex(changeSet: ChangeSet, index: number) {\n const operationsIndex = changeSet.indexes[index];\n if (operationsIndex !== undefined) {\n changeSet.operations[operationsIndex] = undefined;\n }\n delete changeSet.indexes[index];\n}\n\nexport function enqueueChangeTree(\n root: Root,\n changeTree: ChangeTree,\n changeSet: 'changes' | 'filteredChanges' | 'allFilteredChanges',\n queueRootIndex = changeTree[changeSet].queueRootIndex\n) {\n if (root && root[changeSet][queueRootIndex] !== changeTree) {\n changeTree[changeSet].queueRootIndex = root[changeSet].push(changeTree) - 1;\n }\n}\n\nexport class ChangeTree<T extends Ref=any> {\n ref: T;\n refId: number;\n\n root?: Root;\n parent?: Ref;\n parentIndex?: number;\n\n /**\n * Whether this structure is parent of a filtered structure.\n */\n isFiltered: boolean = false;\n\n indexedOperations: IndexedOperations = {};\n\n //\n // TODO:\n // try storing the index + operation per item.\n // example: 1024 & 1025 => ADD, 1026 => DELETE\n //\n // => https://chatgpt.com/share/67107d0c-bc20-8004-8583-83b17dd7c196\n //\n changes: ChangeSet = { indexes: {}, operations: [] };\n allChanges: ChangeSet = { indexes: {}, operations: [] };\n filteredChanges: ChangeSet;\n allFilteredChanges: ChangeSet;\n\n indexes: {[index: string]: any}; // TODO: remove this, only used by MapSchema/SetSchema/CollectionSchema (`encodeKeyValueOperation`)\n\n /**\n * Is this a new instance? Used on ArraySchema to determine OPERATION.MOVE_AND_ADD operation.\n */\n isNew = true;\n\n constructor(ref: T) {\n this.ref = ref;\n\n //\n // Does this structure have \"filters\" declared?\n //\n const metadata = ref.constructor[Symbol.metadata];\n if (metadata?.[$viewFieldIndexes]) {\n this.allFilteredChanges = { indexes: {}, operations: [] };\n this.filteredChanges = { indexes: {}, operations: [] };\n }\n }\n\n setRoot(root: Root) {\n this.root = root;\n this.checkIsFiltered(this.parent, this.parentIndex);\n\n // Recursively set root on child structures\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n value?.[$changes].setRoot(root);\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n value[$changes].setRoot(root);\n });\n }\n\n }\n\n setParent(\n parent: Ref,\n root?: Root,\n parentIndex?: number,\n ) {\n this.parent = parent;\n this.parentIndex = parentIndex;\n\n // avoid setting parents with empty `root`\n if (!root) { return; }\n\n // skip if parent is already set\n if (root !== this.root) {\n this.root = root;\n this.checkIsFiltered(parent, parentIndex);\n\n } else {\n root.add(this);\n }\n\n // assign same parent on child structures\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n value?.[$changes].setParent(this.ref, root, index);\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n value[$changes].setParent(this.ref, root, this.indexes[key] ?? key);\n });\n }\n\n }\n\n forEachChild(callback: (change: ChangeTree, atIndex: number) => void) {\n //\n // assign same parent on child structures\n //\n const metadata: Metadata = this.ref.constructor[Symbol.metadata];\n if (metadata) {\n metadata[$refTypeFieldIndexes]?.forEach((index) => {\n const field = metadata[index as any as number];\n const value = this.ref[field.name];\n if (value) {\n callback(value[$changes], index);\n }\n });\n\n } else if (this.ref[$childType] && typeof(this.ref[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n (this.ref as MapSchema).forEach((value, key) => {\n callback(value[$changes], this.indexes[key] ?? key);\n });\n }\n }\n\n operation(op: OPERATION) {\n // operations without index use negative values to represent them\n // this is checked during .encode() time.\n this.changes.operations.push(-op);\n\n enqueueChangeTree(this.root, this, 'changes');\n }\n\n change(index: number, operation: OPERATION = OPERATION.ADD) {\n const metadata = this.ref.constructor[Symbol.metadata] as Metadata;\n\n const isFiltered = this.isFiltered || (metadata?.[index]?.tag !== undefined);\n const changeSet = (isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const previousOperation = this.indexedOperations[index];\n if (!previousOperation || previousOperation === OPERATION.DELETE) {\n const op = (!previousOperation)\n ? operation\n : (previousOperation === OPERATION.DELETE)\n ? OPERATION.DELETE_AND_ADD\n : operation\n //\n // TODO: are DELETE operations being encoded as ADD here ??\n //\n this.indexedOperations[index] = op;\n }\n\n setOperationAtIndex(changeSet, index);\n\n if (isFiltered) {\n setOperationAtIndex(this.allFilteredChanges, index);\n\n if (this.root) {\n enqueueChangeTree(this.root, this, 'filteredChanges');\n enqueueChangeTree(this.root, this, 'allFilteredChanges');\n }\n\n } else {\n setOperationAtIndex(this.allChanges, index);\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n shiftChangeIndexes(shiftIndex: number) {\n //\n // Used only during:\n //\n // - ArraySchema#unshift()\n //\n const changeSet = (this.isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const newIndexedOperations = {};\n const newIndexes = {};\n for (const index in this.indexedOperations) {\n newIndexedOperations[Number(index) + shiftIndex] = this.indexedOperations[index];\n newIndexes[Number(index) + shiftIndex] = changeSet[index];\n }\n this.indexedOperations = newIndexedOperations;\n changeSet.indexes = newIndexes;\n\n changeSet.operations = changeSet.operations.map((index) => index + shiftIndex);\n }\n\n shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0) {\n //\n // Used only during:\n //\n // - ArraySchema#splice()\n //\n if (this.filteredChanges !== undefined) {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allFilteredChanges);\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n\n } else {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n }\n }\n\n private _shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0, changeSet: ChangeSet) {\n const newIndexes = {};\n\n for (const key in changeSet.indexes) {\n const index = changeSet.indexes[key];\n if (index > startIndex) {\n newIndexes[Number(key) + shiftIndex] = index;\n } else {\n newIndexes[key] = index;\n }\n }\n changeSet.indexes = newIndexes;\n\n for (let i = 0; i < changeSet.operations.length; i++) {\n const index = changeSet.operations[i];\n if (index > startIndex) {\n changeSet.operations[i] = index + shiftIndex;\n }\n }\n }\n\n indexedOperation(index: number, operation: OPERATION, allChangesIndex: number = index) {\n this.indexedOperations[index] = operation;\n\n if (this.filteredChanges !== undefined) {\n setOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n setOperationAtIndex(this.filteredChanges, index);\n enqueueChangeTree(this.root, this, 'filteredChanges');\n\n } else {\n setOperationAtIndex(this.allChanges, allChangesIndex);\n setOperationAtIndex(this.changes, index);\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n getType(index?: number) {\n if (Metadata.isValidInstance(this.ref)) {\n const metadata = this.ref.constructor[Symbol.metadata] as Metadata;\n return metadata[index].type;\n\n } else {\n //\n // Get the child type from parent structure.\n // - [\"string\"] => \"string\"\n // - { map: \"string\" } => \"string\"\n // - { set: \"string\" } => \"string\"\n //\n return this.ref[$childType];\n }\n }\n\n getChange(index: number) {\n return this.indexedOperations[index];\n }\n\n //\n // used during `.encode()`\n //\n getValue(index: number, isEncodeAll: boolean = false) {\n //\n // `isEncodeAll` param is only used by ArraySchema\n //\n return this.ref[$getByIndex](index, isEncodeAll);\n }\n\n delete(index: number, operation?: OPERATION, allChangesIndex = index) {\n if (index === undefined) {\n try {\n throw new Error(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index '${index}'`);\n } catch (e) {\n console.warn(e);\n }\n return;\n }\n\n const changeSet = (this.filteredChanges !== undefined)\n ? this.filteredChanges\n : this.changes;\n\n this.indexedOperations[index] = operation ?? OPERATION.DELETE;\n setOperationAtIndex(changeSet, index);\n\n const previousValue = this.getValue(index);\n\n // remove `root` reference\n if (previousValue && previousValue[$changes]) {\n //\n // FIXME: this.root is \"undefined\"\n //\n // This method is being called at decoding time when a DELETE operation is found.\n //\n // - This is due to using the concrete Schema class at decoding time.\n // - \"Reflected\" structures do not have this problem.\n //\n // (The property descriptors should NOT be used at decoding time. only at encoding time.)\n //\n this.root?.remove(previousValue[$changes]);\n }\n\n deleteOperationAtIndex(this.allChanges, allChangesIndex);\n\n //\n // FIXME: this is looking a ugly and repeated\n //\n if (this.filteredChanges !== undefined) {\n deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n enqueueChangeTree(this.root, this, 'filteredChanges');\n\n } else {\n enqueueChangeTree(this.root, this, 'changes');\n }\n }\n\n endEncode() {\n this.indexedOperations = {};\n\n // // clear changes\n // this.changes.indexes = {};\n // this.changes.operations.length = 0;\n\n // ArraySchema and MapSchema have a custom \"encode end\" method\n this.ref[$onEncodeEnd]?.();\n\n // Not a new instance anymore\n this.isNew = false;\n }\n\n discard(discardAll: boolean = false) {\n //\n // > MapSchema:\n // Remove cached key to ensure ADD operations is unsed instead of\n // REPLACE in case same key is used on next patches.\n //\n this.ref[$onEncodeEnd]?.();\n\n this.indexedOperations = {};\n\n this.changes.indexes = {};\n this.changes.operations.length = 0;\n this.changes.queueRootIndex = undefined;\n\n if (this.filteredChanges !== undefined) {\n this.filteredChanges.indexes = {};\n this.filteredChanges.operations.length = 0;\n this.filteredChanges.queueRootIndex = undefined;\n }\n\n if (discardAll) {\n this.allChanges.indexes = {};\n this.allChanges.operations.length = 0;\n\n if (this.allFilteredChanges !== undefined) {\n this.allFilteredChanges.indexes = {};\n this.allFilteredChanges.operations.length = 0;\n }\n\n // remove children references\n this.forEachChild((changeTree, _) =>\n this.root?.remove(changeTree));\n }\n }\n\n /**\n * Recursively discard all changes from this, and child structures.\n */\n discardAll() {\n const keys = Object.keys(this.indexedOperations);\n for (let i = 0, len = keys.length; i < len; i++) {\n const value = this.getValue(Number(keys[i]));\n\n if (value && value[$changes]) {\n value[$changes].discardAll();\n }\n }\n\n this.discard();\n }\n\n ensureRefId() {\n // skip if refId is already set.\n if (this.refId !== undefined) {\n return;\n }\n\n this.refId = this.root.getNextUniqueId();\n }\n\n get changed() {\n return (Object.entries(this.indexedOperations).length > 0);\n }\n\n protected checkIsFiltered(parent: Ref, parentIndex: number) {\n const isNewChangeTree = this.root.add(this);\n\n if (this.root.types.hasFilters) {\n //\n // At Schema initialization, the \"root\" structure might not be available\n // yet, as it only does once the \"Encoder\" has been set up.\n //\n // So the \"parent\" may be already set without a \"root\".\n //\n this._checkFilteredByParent(parent, parentIndex);\n\n if (this.filteredChanges !== undefined) {\n enqueueChangeTree(this.root, this, 'filteredChanges');\n if (isNewChangeTree) {\n this.root.allFilteredChanges.push(this);\n }\n }\n }\n\n if (!this.isFiltered) {\n enqueueChangeTree(this.root, this, 'changes');\n if (isNewChangeTree) {\n this.root.allChanges.push(this);\n }\n }\n }\n\n protected _checkFilteredByParent(parent: Ref, parentIndex: number) {\n // skip if parent is not set\n if (!parent) { return; }\n\n //\n // ArraySchema | MapSchema - get the child type\n // (if refType is typeof string, the parentFiltered[key] below will always be invalid)\n //\n const refType = Metadata.isValidInstance(this.ref)\n ? this.ref.constructor\n : this.ref[$childType];\n\n if (!Metadata.isValidInstance(parent)) {\n const parentChangeTree = parent[$changes];\n parent = parentChangeTree.parent;\n parentIndex = parentChangeTree.parentIndex;\n }\n\n const parentConstructor = parent.constructor as typeof Schema;\n\n let key = `${this.root.types.getTypeId(refType as typeof Schema)}`;\n if (parentConstructor) {\n key += `-${this.root.types.schemas.get(parentConstructor)}`;\n }\n key += `-${parentIndex}`;\n\n this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered\n || this.root.types.parentFiltered[key];\n\n // const parentMetadata = parentConstructor?.[Symbol.metadata];\n // this.isFiltered = parentMetadata?.[$viewFieldIndexes]?.includes(parentIndex) || this.root.types.parentFiltered[key];\n\n //\n // TODO: refactor this!\n //\n // swapping `changes` and `filteredChanges` is required here\n // because \"isFiltered\" may not be imedialely available on `change()`\n // (this happens when instance is detached from root or parent)\n //\n if (this.isFiltered) {\n this.filteredChanges = { indexes: {}, operations: [] };\n this.allFilteredChanges = { indexes: {}, operations: [] };\n\n if (this.changes.operations.length > 0) {\n // swap changes reference\n const changes = this.changes;\n this.changes = this.filteredChanges;\n this.filteredChanges = changes;\n\n // swap \"all changes\" reference\n const allFilteredChanges = this.allFilteredChanges;\n this.allFilteredChanges = this.allChanges;\n this.allChanges = allFilteredChanges;\n }\n }\n }\n\n}\n"]}
|
package/lib/encoder/Root.js
CHANGED
|
@@ -61,15 +61,31 @@ class Root {
|
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
this.refCount[changeTree.refId] = refCount;
|
|
64
|
+
//
|
|
65
|
+
// When losing a reference to an instance, it is best to move the
|
|
66
|
+
// ChangeTree to the end of the encoding queue.
|
|
67
|
+
//
|
|
68
|
+
// This way, at decoding time, the instance that contains the
|
|
69
|
+
// ChangeTree will be available before the ChangeTree itself. If the
|
|
70
|
+
// containing instance is not available, the Decoder will throw
|
|
71
|
+
// "refId not found" error.
|
|
72
|
+
//
|
|
73
|
+
if (changeTree.filteredChanges !== undefined) {
|
|
74
|
+
this.removeChangeFromChangeSet("filteredChanges", changeTree);
|
|
75
|
+
(0, ChangeTree_1.enqueueChangeTree)(this, changeTree, "filteredChanges");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.removeChangeFromChangeSet("changes", changeTree);
|
|
79
|
+
(0, ChangeTree_1.enqueueChangeTree)(this, changeTree, "changes");
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
82
|
changeTree.forEachChild((child, _) => this.remove(child));
|
|
66
83
|
return refCount;
|
|
67
84
|
}
|
|
68
85
|
removeChangeFromChangeSet(changeSetName, changeTree) {
|
|
69
86
|
const changeSet = this[changeSetName];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(0, utils_1.spliceOne)(changeSet, index);
|
|
87
|
+
if ((0, utils_1.spliceOne)(changeSet, changeSet.indexOf(changeTree))) {
|
|
88
|
+
changeTree[changeSetName].queueRootIndex = -1;
|
|
73
89
|
// changeSet[index] = undefined;
|
|
74
90
|
}
|
|
75
91
|
}
|
package/lib/encoder/Root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Root.js","sourceRoot":"","sources":["../../src/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,oEAAoE;YACpE,+DAA+D;YAC/D,2BAA2B;YAC3B,EAAE;YACF,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;gBAC3C,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;gBAC9D,IAAA,8BAAiB,EAAC,IAAI,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;YAC3D,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,yBAAyB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;gBACtD,IAAA,8BAAiB,EAAC,IAAI,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;YACnD,CAAC;QACL,CAAC;QAED,UAAU,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAE1D,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,yBAAyB,CAAC,aAAkF,EAAE,UAAsB;QAChI,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QACtC,IAAI,IAAA,iBAAS,EAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YACtD,UAAU,CAAC,aAAa,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;YAC9C,gCAAgC;QACpC,CAAC;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5B,CAAC;CACJ;AAvGD,oBAuGC","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { TypeContext } from \"../types/TypeContext\";\nimport { spliceOne } from \"../types/utils\";\nimport { ChangeTree, enqueueChangeTree, setOperationAtIndex } from \"./ChangeTree\";\n\nexport class Root {\n protected nextUniqueId: number = 0;\n\n refCount: {[id: number]: number} = {};\n changeTrees: {[refId: number]: ChangeTree} = {};\n\n // all changes\n allChanges: ChangeTree[] = [];\n allFilteredChanges: ChangeTree[] = [];// TODO: do not initialize it if filters are not used\n\n // pending changes to be encoded\n changes: ChangeTree[] = [];\n filteredChanges: ChangeTree[] = [];// TODO: do not initialize it if filters are not used\n\n constructor(public types: TypeContext) { }\n\n getNextUniqueId() {\n return this.nextUniqueId++;\n }\n\n add(changeTree: ChangeTree) {\n // FIXME: move implementation of `ensureRefId` to `Root` class\n changeTree.ensureRefId();\n\n const isNewChangeTree = (this.changeTrees[changeTree.refId] === undefined);\n if (isNewChangeTree) { this.changeTrees[changeTree.refId] = changeTree; }\n\n const previousRefCount = this.refCount[changeTree.refId];\n if (previousRefCount === 0) {\n //\n // When a ChangeTree is re-added, it means that it was previously removed.\n // We need to re-add all changes to the `changes` map.\n //\n const ops = changeTree.allChanges.operations;\n let len = ops.length;\n while (len--) {\n changeTree.indexedOperations[ops[len]] = OPERATION.ADD;\n setOperationAtIndex(changeTree.changes, len);\n }\n }\n\n this.refCount[changeTree.refId] = (previousRefCount || 0) + 1;\n\n return isNewChangeTree;\n }\n\n remove(changeTree: ChangeTree) {\n const refCount = (this.refCount[changeTree.refId]) - 1;\n\n if (refCount <= 0) {\n //\n // Only remove \"root\" reference if it's the last reference\n //\n changeTree.root = undefined;\n delete this.changeTrees[changeTree.refId];\n\n this.removeChangeFromChangeSet(\"allChanges\", changeTree);\n this.removeChangeFromChangeSet(\"changes\", changeTree);\n\n if (changeTree.filteredChanges) {\n this.removeChangeFromChangeSet(\"allFilteredChanges\", changeTree);\n this.removeChangeFromChangeSet(\"filteredChanges\", changeTree);\n }\n\n this.refCount[changeTree.refId] = 0;\n\n } else {\n this.refCount[changeTree.refId] = refCount;\n\n //\n // When losing a reference to an instance, it is best to move the\n // ChangeTree to the end of the encoding queue.\n //\n // This way, at decoding time, the instance that contains the\n // ChangeTree will be available before the ChangeTree itself. If the\n // containing instance is not available, the Decoder will throw\n // \"refId not found\" error.\n //\n if (changeTree.filteredChanges !== undefined) {\n this.removeChangeFromChangeSet(\"filteredChanges\", changeTree);\n enqueueChangeTree(this, changeTree, \"filteredChanges\");\n } else {\n this.removeChangeFromChangeSet(\"changes\", changeTree);\n enqueueChangeTree(this, changeTree, \"changes\");\n }\n }\n\n changeTree.forEachChild((child, _) => this.remove(child));\n\n return refCount;\n }\n\n removeChangeFromChangeSet(changeSetName: \"allChanges\" | \"changes\" | \"filteredChanges\" | \"allFilteredChanges\", changeTree: ChangeTree) {\n const changeSet = this[changeSetName];\n if (spliceOne(changeSet, changeSet.indexOf(changeTree))) {\n changeTree[changeSetName].queueRootIndex = -1;\n // changeSet[index] = undefined;\n }\n }\n\n clear() {\n this.changes.length = 0;\n }\n}\n"]}
|
|
@@ -32,7 +32,6 @@ class ArraySchema {
|
|
|
32
32
|
* - Then, the encoder iterates over all "owned" properties per instance and encodes them.
|
|
33
33
|
*/
|
|
34
34
|
static [(_a = symbols_1.$encoder, _b = symbols_1.$decoder, symbols_1.$filter)](ref, index, view) {
|
|
35
|
-
// console.log("ArraSchema[$filter] VIEW??", !view)
|
|
36
35
|
return (!view ||
|
|
37
36
|
typeof (ref[symbols_1.$childType]) === "string" ||
|
|
38
37
|
// view.items.has(ref[$getByIndex](index)[$changes])
|
|
@@ -635,6 +634,7 @@ class ArraySchema {
|
|
|
635
634
|
}
|
|
636
635
|
[symbols_1.$deleteByIndex](index) {
|
|
637
636
|
this.items[index] = undefined;
|
|
637
|
+
this.tmpItems[index] = undefined; // TODO: do not try to get "tmpItems" at decoding time.
|
|
638
638
|
}
|
|
639
639
|
[symbols_1.$onEncodeEnd]() {
|
|
640
640
|
this.tmpItems = this.items.slice();
|
|
@@ -642,6 +642,7 @@ class ArraySchema {
|
|
|
642
642
|
}
|
|
643
643
|
[symbols_1.$onDecodeEnd]() {
|
|
644
644
|
this.items = this.items.filter((item) => item !== undefined);
|
|
645
|
+
this.tmpItems = this.items.slice(); // TODO: do no use "tmpItems" at decoding time.
|
|
645
646
|
}
|
|
646
647
|
toArray() {
|
|
647
648
|
return this.items.slice(0);
|