@colyseus/schema 3.0.26 → 3.0.27

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.
@@ -1,6 +1,6 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('util')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'util'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
@@ -977,10 +977,18 @@
977
977
  }
978
978
  }
979
979
  function deleteOperationAtIndex(changeSet, index) {
980
- const operationsIndex = changeSet.indexes[index];
981
- if (operationsIndex !== undefined) {
982
- changeSet.operations[operationsIndex] = undefined;
980
+ let operationsIndex = changeSet.indexes[index];
981
+ if (operationsIndex === undefined) {
982
+ //
983
+ // if index is not found, we need to find the last operation
984
+ // FIXME: this is not very efficient
985
+ //
986
+ // > See "should allow consecutive splices (same place)" tests
987
+ //
988
+ operationsIndex = Object.values(changeSet.indexes).at(-1);
989
+ index = Object.entries(changeSet.indexes).find(([_, value]) => value === operationsIndex)?.[0];
983
990
  }
991
+ changeSet.operations[operationsIndex] = undefined;
984
992
  delete changeSet.indexes[index];
985
993
  }
986
994
  function enqueueChangeTree(root, changeTree, changeSet, queueRootIndex = changeTree[changeSet].queueRootIndex) {
@@ -1165,15 +1173,22 @@
1165
1173
  }
1166
1174
  _shiftAllChangeIndexes(shiftIndex, startIndex = 0, changeSet) {
1167
1175
  const newIndexes = {};
1176
+ let newKey = 0;
1168
1177
  for (const key in changeSet.indexes) {
1169
- const index = changeSet.indexes[key];
1170
- if (index > startIndex) {
1171
- newIndexes[Number(key) + shiftIndex] = index;
1172
- }
1173
- else {
1174
- newIndexes[key] = index;
1175
- }
1176
- }
1178
+ newIndexes[newKey++] = changeSet.indexes[key];
1179
+ }
1180
+ // const newIndexes = {};
1181
+ // let newKey = 0;
1182
+ // for (const key in changeSet.indexes) {
1183
+ // const index = changeSet.indexes[key];
1184
+ // newIndexes[newKey++] = changeSet.indexes[key];
1185
+ // console.log("...shiftAllChangeIndexes", { index: key, targetIndex: index, startIndex, shiftIndex });
1186
+ // if (index > startIndex) {
1187
+ // newIndexes[Number(key) + shiftIndex] = index;
1188
+ // } else {
1189
+ // newIndexes[Number(key)] = index;
1190
+ // }
1191
+ // }
1177
1192
  changeSet.indexes = newIndexes;
1178
1193
  for (let i = 0; i < changeSet.operations.length; i++) {
1179
1194
  const index = changeSet.operations[i];
@@ -1516,6 +1531,7 @@
1516
1531
  }
1517
1532
  const type = changeTree.getType(field);
1518
1533
  const value = changeTree.getValue(field, isEncodeAll);
1534
+ // console.log({ type, field, value });
1519
1535
  // console.log("encodeArray -> ", {
1520
1536
  // ref: changeTree.ref.constructor.name,
1521
1537
  // field,
@@ -1994,8 +2010,6 @@
1994
2010
  return undefined;
1995
2011
  }
1996
2012
  this[$changes].delete(index, undefined, this.items.length - 1);
1997
- // this.tmpItems[index] = undefined;
1998
- // this.tmpItems.pop();
1999
2013
  this.deletedIndexes[index] = true;
2000
2014
  return this.items.pop();
2001
2015
  }
@@ -2146,31 +2160,50 @@
2146
2160
  * @param deleteCount The number of elements to remove.
2147
2161
  * @param insertItems Elements to insert into the array in place of the deleted elements.
2148
2162
  */
2149
- splice(start, deleteCount = this.items.length - start, ...insertItems) {
2163
+ splice(start, deleteCount, ...insertItems) {
2150
2164
  const changeTree = this[$changes];
2165
+ const itemsLength = this.items.length;
2151
2166
  const tmpItemsLength = this.tmpItems.length;
2152
2167
  const insertCount = insertItems.length;
2153
2168
  // build up-to-date list of indexes, excluding removed values.
2154
2169
  const indexes = [];
2155
2170
  for (let i = 0; i < tmpItemsLength; i++) {
2156
- // if (this.tmpItems[i] !== undefined) {
2157
2171
  if (this.deletedIndexes[i] !== true) {
2158
2172
  indexes.push(i);
2159
2173
  }
2160
2174
  }
2161
- // delete operations at correct index
2162
- for (let i = start; i < start + deleteCount; i++) {
2163
- const index = indexes[i];
2164
- changeTree.delete(index);
2165
- // this.tmpItems[index] = undefined;
2166
- this.deletedIndexes[index] = true;
2175
+ if (itemsLength > start) {
2176
+ // if deleteCount is not provided, delete all items from start to end
2177
+ if (deleteCount === undefined) {
2178
+ deleteCount = itemsLength - start;
2179
+ }
2180
+ //
2181
+ // delete operations at correct index
2182
+ //
2183
+ for (let i = start; i < start + deleteCount; i++) {
2184
+ const index = indexes[i];
2185
+ changeTree.delete(index, exports.OPERATION.DELETE);
2186
+ this.deletedIndexes[index] = true;
2187
+ }
2167
2188
  }
2168
- // force insert operations
2169
- for (let i = 0; i < insertCount; i++) {
2170
- const addIndex = indexes[start] + i;
2171
- changeTree.indexedOperation(addIndex, exports.OPERATION.ADD);
2172
- // set value's parent/root
2173
- insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);
2189
+ else {
2190
+ // not enough items to delete
2191
+ deleteCount = 0;
2192
+ }
2193
+ // insert operations
2194
+ if (insertCount > 0) {
2195
+ if (insertCount > deleteCount) {
2196
+ console.error("Inserting more elements than deleting during ArraySchema#splice()");
2197
+ throw new Error("ArraySchema#splice(): insertCount must be equal or lower than deleteCount.");
2198
+ }
2199
+ for (let i = 0; i < insertCount; i++) {
2200
+ const addIndex = (indexes[start] ?? itemsLength) + i;
2201
+ changeTree.indexedOperation(addIndex, (this.deletedIndexes[addIndex])
2202
+ ? exports.OPERATION.DELETE_AND_ADD
2203
+ : exports.OPERATION.ADD);
2204
+ // set value's parent/root
2205
+ insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);
2206
+ }
2174
2207
  }
2175
2208
  //
2176
2209
  // delete exceeding indexes from "allChanges"
@@ -2178,6 +2211,16 @@
2178
2211
  //
2179
2212
  if (deleteCount > insertCount) {
2180
2213
  changeTree.shiftAllChangeIndexes(-(deleteCount - insertCount), indexes[start + insertCount]);
2214
+ // debugChangeSet("AFTER SHIFT indexes", changeTree.allChanges);
2215
+ }
2216
+ //
2217
+ // FIXME: this code block is duplicated on ChangeTree
2218
+ //
2219
+ if (changeTree.filteredChanges !== undefined) {
2220
+ enqueueChangeTree(changeTree.root, changeTree, 'filteredChanges');
2221
+ }
2222
+ else {
2223
+ enqueueChangeTree(changeTree.root, changeTree, 'changes');
2181
2224
  }
2182
2225
  return this.items.splice(start, deleteCount, ...insertItems);
2183
2226
  }
@@ -2433,9 +2476,6 @@
2433
2476
  : this.deletedIndexes[index]
2434
2477
  ? this.items[index]
2435
2478
  : this.tmpItems[index] || this.items[index];
2436
- // return (isEncodeAll)
2437
- // ? this.items[index]
2438
- // : this.tmpItems[index] ?? this.items[index];
2439
2479
  }
2440
2480
  [$deleteByIndex](index) {
2441
2481
  this.items[index] = undefined;
@@ -3807,10 +3847,10 @@
3807
3847
  view.invisible.delete(changeTree); // remove from invisible list
3808
3848
  }
3809
3849
  }
3810
- const operations = changeTree[changeSetName];
3850
+ const changeSet = changeTree[changeSetName];
3811
3851
  const ref = changeTree.ref;
3812
3852
  // TODO: avoid iterating over change tree if no changes were made
3813
- const numChanges = operations.operations.length;
3853
+ const numChanges = changeSet.operations.length;
3814
3854
  if (numChanges === 0) {
3815
3855
  continue;
3816
3856
  }
@@ -3825,7 +3865,7 @@
3825
3865
  encode.number(buffer, changeTree.refId, it);
3826
3866
  }
3827
3867
  for (let j = 0; j < numChanges; j++) {
3828
- const fieldIndex = operations.operations[j];
3868
+ const fieldIndex = changeSet.operations[j];
3829
3869
  const operation = (fieldIndex < 0)
3830
3870
  ? Math.abs(fieldIndex) // "pure" operation without fieldIndex (e.g. CLEAR, REVERSE, etc.)
3831
3871
  : (isEncodeAll)
@@ -24,11 +24,12 @@ export interface ChangeSet {
24
24
  indexes: {
25
25
  [index: number]: number;
26
26
  };
27
- operations: OPERATION[];
27
+ operations: number[];
28
28
  queueRootIndex?: number;
29
29
  }
30
30
  export declare function setOperationAtIndex(changeSet: ChangeSet, index: number): void;
31
- export declare function deleteOperationAtIndex(changeSet: ChangeSet, index: number): void;
31
+ export declare function deleteOperationAtIndex(changeSet: ChangeSet, index: number | string): void;
32
+ export declare function debugChangeSet(label: string, changeSet: ChangeSet): void;
32
33
  export declare function enqueueChangeTree(root: Root, changeTree: ChangeTree, changeSet: 'changes' | 'filteredChanges' | 'allFilteredChanges', queueRootIndex?: number): void;
33
34
  export declare class ChangeTree<T extends Ref = any> {
34
35
  ref: T;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChangeTree = void 0;
4
4
  exports.setOperationAtIndex = setOperationAtIndex;
5
5
  exports.deleteOperationAtIndex = deleteOperationAtIndex;
6
+ exports.debugChangeSet = debugChangeSet;
6
7
  exports.enqueueChangeTree = enqueueChangeTree;
8
+ const util = require("util");
7
9
  const spec_1 = require("../encoding/spec");
8
10
  const symbols_1 = require("../types/symbols");
9
11
  const Metadata_1 = require("../Metadata");
@@ -20,12 +22,37 @@ function setOperationAtIndex(changeSet, index) {
20
22
  }
21
23
  }
22
24
  function deleteOperationAtIndex(changeSet, index) {
23
- const operationsIndex = changeSet.indexes[index];
24
- if (operationsIndex !== undefined) {
25
- changeSet.operations[operationsIndex] = undefined;
25
+ let operationsIndex = changeSet.indexes[index];
26
+ if (operationsIndex === undefined) {
27
+ //
28
+ // if index is not found, we need to find the last operation
29
+ // FIXME: this is not very efficient
30
+ //
31
+ // > See "should allow consecutive splices (same place)" tests
32
+ //
33
+ operationsIndex = Object.values(changeSet.indexes).at(-1);
34
+ index = Object.entries(changeSet.indexes).find(([_, value]) => value === operationsIndex)?.[0];
26
35
  }
36
+ changeSet.operations[operationsIndex] = undefined;
27
37
  delete changeSet.indexes[index];
28
38
  }
39
+ function debugChangeSet(label, changeSet) {
40
+ let indexes = [];
41
+ let operations = [];
42
+ for (const index in changeSet.indexes) {
43
+ indexes.push(`\t${util.inspect(index, { colors: true })} => [${util.inspect(changeSet.indexes[index], { colors: true })}]`);
44
+ }
45
+ for (let i = 0; i < changeSet.operations.length; i++) {
46
+ const index = changeSet.operations[i];
47
+ if (index !== undefined) {
48
+ operations.push(`\t[${util.inspect(i, { colors: true })}] => ${util.inspect(index, { colors: true })}`);
49
+ }
50
+ }
51
+ console.log(`${label} =>\nindexes (${Object.keys(changeSet.indexes).length}) {`);
52
+ console.log(indexes.join("\n"), "\n}");
53
+ console.log(`operations (${changeSet.operations.filter(op => op !== undefined).length}) {`);
54
+ console.log(operations.join("\n"), "\n}");
55
+ }
29
56
  function enqueueChangeTree(root, changeTree, changeSet, queueRootIndex = changeTree[changeSet].queueRootIndex) {
30
57
  if (!root) {
31
58
  // skip
@@ -208,15 +235,22 @@ class ChangeTree {
208
235
  }
209
236
  _shiftAllChangeIndexes(shiftIndex, startIndex = 0, changeSet) {
210
237
  const newIndexes = {};
238
+ let newKey = 0;
211
239
  for (const key in changeSet.indexes) {
212
- const index = changeSet.indexes[key];
213
- if (index > startIndex) {
214
- newIndexes[Number(key) + shiftIndex] = index;
215
- }
216
- else {
217
- newIndexes[key] = index;
218
- }
219
- }
240
+ newIndexes[newKey++] = changeSet.indexes[key];
241
+ }
242
+ // const newIndexes = {};
243
+ // let newKey = 0;
244
+ // for (const key in changeSet.indexes) {
245
+ // const index = changeSet.indexes[key];
246
+ // newIndexes[newKey++] = changeSet.indexes[key];
247
+ // console.log("...shiftAllChangeIndexes", { index: key, targetIndex: index, startIndex, shiftIndex });
248
+ // if (index > startIndex) {
249
+ // newIndexes[Number(key) + shiftIndex] = index;
250
+ // } else {
251
+ // newIndexes[Number(key)] = index;
252
+ // }
253
+ // }
220
254
  changeSet.indexes = newIndexes;
221
255
  for (let i = 0; i < changeSet.operations.length; i++) {
222
256
  const index = changeSet.operations[i];
@@ -1 +1 @@
1
- {"version":3,"file":"ChangeTree.js","sourceRoot":"","sources":["../../src/encoder/ChangeTree.ts"],"names":[],"mappings":";;;AAiDA,kDAOC;AAED,wDAMC;AAED,8CAaC;AA/ED,2CAA6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AG,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChE,CAAC;QACD,GAAG,IAAI,IAAI,WAAW,EAAE,CAAC;QAEzB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,kBAAQ,CAAC,CAAC,UAAU,CAAC,qCAAqC;eAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC;eACnC,iBAAiB,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,2BAAiB,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;QAExF,EAAE;QACF,yHAAyH;QACzH,wGAAwG;QACxG,EAAE;QACF,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;gBACxB,IAAI,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC;gBACzC,IAAI,CAAC,kBAAkB,GAAG,eAAe,EAAE,CAAC;YAChD,CAAC;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACtC,mBAAmB,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACzC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;gBAEzD,IAAI,CAAC,OAAO,GAAG,eAAe,EAAE,CAAC;gBACjC,IAAI,CAAC,UAAU,GAAG,eAAe,EAAE,CAAC;YACxC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAteD,gCAseC","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\";\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\nfunction createChangeSet(): ChangeSet {\n return { indexes: {}, operations: [] };\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) {\n // skip\n return;\n\n } else if (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.indexes[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 deleteOperationAtIndex(this.allChanges, allChangesIndex);\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 enqueueChangeTree(this.root, this, 'changes');\n }\n\n return previousValue;\n }\n\n endEncode(changeSetName: ChangeSetName) {\n this.indexedOperations = {};\n\n // clear changeset\n this[changeSetName].indexes = {};\n this[changeSetName].operations.length = 0;\n this[changeSetName].queueRootIndex = undefined;\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 || parentConstructor?.[Symbol.metadata]?.[$viewFieldIndexes]?.includes(parentIndex);\n\n //\n // \"isFiltered\" may not be imedialely available during `change()` due to the instance not being attached to the root yet.\n // when it's available, we need to enqueue the \"changes\" changeset into the \"filteredChanges\" changeset.\n //\n if (this.isFiltered) {\n if (!this.filteredChanges) {\n this.filteredChanges = createChangeSet();\n this.allFilteredChanges = createChangeSet();\n }\n\n if (this.changes.operations.length > 0) {\n this.changes.operations.forEach((index) =>\n setOperationAtIndex(this.filteredChanges, index));\n\n this.allChanges.operations.forEach((index) =>\n setOperationAtIndex(this.allFilteredChanges, index));\n\n this.changes = createChangeSet();\n this.allChanges = createChangeSet();\n }\n }\n }\n\n}\n"]}
1
+ {"version":3,"file":"ChangeTree.js","sourceRoot":"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,CAAC;YAChD,CAAC;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACtC,mBAAmB,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACzC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;gBAEzD,IAAI,CAAC,OAAO,GAAG,eAAe,EAAE,CAAC;gBACjC,IAAI,CAAC,UAAU,GAAG,eAAe,EAAE,CAAC;YACxC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AA/eD,gCA+eC","sourcesContent":["import * as util from \"util\";\n\nimport { 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\";\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: number[];\n queueRootIndex?: number; // index of ChangeTree structure in `root.changes` or `root.filteredChanges`\n}\n\nfunction createChangeSet(): ChangeSet {\n return { indexes: {}, operations: [] };\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 | string) {\n let operationsIndex = changeSet.indexes[index];\n if (operationsIndex === undefined) {\n //\n // if index is not found, we need to find the last operation\n // FIXME: this is not very efficient\n //\n // > See \"should allow consecutive splices (same place)\" tests\n //\n operationsIndex = Object.values(changeSet.indexes).at(-1);\n index = Object.entries(changeSet.indexes).find(([_, value]) => value === operationsIndex)?.[0];\n }\n changeSet.operations[operationsIndex] = undefined;\n delete changeSet.indexes[index];\n}\n\nexport function debugChangeSet(label: string, changeSet: ChangeSet) {\n let indexes: string[] = [];\n let operations: string[] = [];\n\n for (const index in changeSet.indexes) {\n indexes.push(`\\t${util.inspect(index, { colors: true })} => [${util.inspect(changeSet.indexes[index], { colors: true })}]`);\n }\n\n for (let i = 0; i < changeSet.operations.length; i++) {\n const index = changeSet.operations[i];\n if (index !== undefined) {\n operations.push(`\\t[${util.inspect(i, { colors: true })}] => ${util.inspect(index, { colors: true })}`);\n }\n }\n\n console.log(`${label} =>\\nindexes (${Object.keys(changeSet.indexes).length}) {`);\n console.log(indexes.join(\"\\n\"), \"\\n}\");\n console.log(`operations (${changeSet.operations.filter(op => op !== undefined).length}) {`);\n console.log(operations.join(\"\\n\"), \"\\n}\");\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) {\n // skip\n return;\n\n } else if (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.indexes[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 let newKey = 0;\n for (const key in changeSet.indexes) {\n newIndexes[newKey++] = changeSet.indexes[key];\n }\n\n // const newIndexes = {};\n // let newKey = 0;\n // for (const key in changeSet.indexes) {\n // const index = changeSet.indexes[key];\n // newIndexes[newKey++] = changeSet.indexes[key];\n // console.log(\"...shiftAllChangeIndexes\", { index: key, targetIndex: index, startIndex, shiftIndex });\n // if (index > startIndex) {\n // newIndexes[Number(key) + shiftIndex] = index;\n // } else {\n // newIndexes[Number(key)] = index;\n // }\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 deleteOperationAtIndex(this.allChanges, allChangesIndex);\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 enqueueChangeTree(this.root, this, 'changes');\n }\n\n return previousValue;\n }\n\n endEncode(changeSetName: ChangeSetName) {\n this.indexedOperations = {};\n\n // clear changeset\n this[changeSetName].indexes = {};\n this[changeSetName].operations.length = 0;\n this[changeSetName].queueRootIndex = undefined;\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 || parentConstructor?.[Symbol.metadata]?.[$viewFieldIndexes]?.includes(parentIndex);\n\n //\n // \"isFiltered\" may not be imedialely available during `change()` due to the instance not being attached to the root yet.\n // when it's available, we need to enqueue the \"changes\" changeset into the \"filteredChanges\" changeset.\n //\n if (this.isFiltered) {\n if (!this.filteredChanges) {\n this.filteredChanges = createChangeSet();\n this.allFilteredChanges = createChangeSet();\n }\n\n if (this.changes.operations.length > 0) {\n this.changes.operations.forEach((index) =>\n setOperationAtIndex(this.filteredChanges, index));\n\n this.allChanges.operations.forEach((index) =>\n setOperationAtIndex(this.allFilteredChanges, index));\n\n this.changes = createChangeSet();\n this.allChanges = createChangeSet();\n }\n }\n }\n\n}\n"]}
@@ -128,6 +128,7 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
128
128
  }
129
129
  const type = changeTree.getType(field);
130
130
  const value = changeTree.getValue(field, isEncodeAll);
131
+ // console.log({ type, field, value });
131
132
  // console.log("encodeArray -> ", {
132
133
  // ref: changeTree.ref.constructor.name,
133
134
  // field,
@@ -1 +1 @@
1
- {"version":3,"file":"EncodeOperation.js","sourceRoot":"","sources":["../../src/encoder/EncodeOperation.ts"],"names":[],"mappings":";;;AAyBA,kCA8BC;AAvDD,2CAA6C;AAC7C,8CAAqE;AAErE,+CAA4C;AAsB5C,SAAgB,WAAW,CACvB,OAAgB,EAChB,KAAa,EACb,IAAS,EACT,KAAU,EACV,SAAoB,EACpB,EAAY;IAEZ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC7B,eAAM,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAErC,CAAC;SAAM,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAC7C,EAAE;QACF,kCAAkC;QAClC,6EAA6E;QAC7E,EAAE;QACF,eAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,kBAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAEhD,4DAA4D;QAC5D,IAAI,CAAC,SAAS,GAAG,gBAAS,CAAC,GAAG,CAAC,KAAK,gBAAS,CAAC,GAAG,EAAE,CAAC;YAChD,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,IAAqB,EAAE,KAA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C;IACnC,4CAA4C;IAC5C,aAAa;IACb,uCAAuC;IACvC,8BAA8B;IAC9B,2BAA2B;IAC3B,MAAM;IAEN,yDAAyD;IACzD,WAAW,CACP,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,SAAS,EACT,EAAE,CACL,CAAC;AACN,CAAC,CAAA;AApEY,QAAA,WAAW,eAoEvB","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { $changes, $childType, $getByIndex } from \"../types/symbols\";\n\nimport { encode } from \"../encoding/encode\";\n\nimport type { ChangeTree, Ref } from \"./ChangeTree\";\nimport type { Encoder } from \"./Encoder\";\nimport type { Schema } from \"../Schema\";\n\nimport type { Iterator } from \"../encoding/decode\";\nimport type { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { Metadata } from \"../Metadata\";\n\nexport type EncodeOperation<T extends Ref = any> = (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<T>,\n index: number,\n operation: OPERATION,\n it: Iterator,\n isEncodeAll: boolean,\n hasView: boolean,\n metadata?: Metadata,\n) => void;\n\nexport function encodeValue(\n encoder: Encoder,\n bytes: Buffer,\n type: any,\n value: any,\n operation: OPERATION,\n it: Iterator,\n) {\n if (typeof (type) === \"string\") {\n encode[type]?.(bytes, value, it);\n\n } else if (type[Symbol.metadata] !== undefined) {\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId, it);\n\n // Try to encode inherited TYPE_ID if it's an ADD operation.\n if ((operation & OPERATION.ADD) === OPERATION.ADD) {\n encoder.tryEncodeTypeId(bytes, type as typeof Schema, value.constructor as typeof Schema, it);\n }\n\n } else {\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId, it);\n }\n}\n\n/**\n * Used for Schema instances.\n * @private\n */\nexport const encodeSchemaOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<Schema>,\n index: number,\n operation: OPERATION,\n it: Iterator,\n _: any,\n __: any,\n metadata: Metadata,\n) {\n // \"compress\" field index + operation\n bytes[it.offset++] = (index | operation) & 255;\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const ref = changeTree.ref;\n const field = metadata[index];\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n metadata[index].type,\n ref[field.name],\n operation,\n it\n );\n}\n\n/**\n * Used for collections (MapSchema, CollectionSchema, SetSchema)\n * @private\n */\nexport const encodeKeyValueOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree,\n index: number,\n operation: OPERATION,\n it: Iterator,\n) {\n // encode operation\n bytes[it.offset++] = operation & 255;\n\n // custom operations\n if (operation === OPERATION.CLEAR) {\n return;\n }\n\n // encode index\n encode.number(bytes, index, it);\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const ref = changeTree.ref;\n\n //\n // encode \"alias\" for dynamic fields (maps)\n //\n if ((operation & OPERATION.ADD) === OPERATION.ADD) { // ADD or DELETE_AND_ADD\n if (typeof(ref['set']) === \"function\") {\n //\n // MapSchema dynamic key\n //\n const dynamicIndex = changeTree.ref['$indexes'].get(index);\n encode.string(bytes, dynamicIndex, it);\n }\n }\n\n const type = ref[$childType];\n const value = ref[$getByIndex](index);\n\n // try { throw new Error(); } catch (e) {\n // // only print if not coming from Reflection.ts\n // if (!e.stack.includes(\"src/Reflection.ts\")) {\n // console.log(\"encodeKeyValueOperation -> \", {\n // ref: changeTree.ref.constructor.name,\n // field,\n // operation: OPERATION[operation],\n // value: value?.toJSON(),\n // items: ref.toJSON(),\n // });\n // }\n // }\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n type,\n value,\n operation,\n it\n );\n}\n\n/**\n * Used for collections (MapSchema, ArraySchema, etc.)\n * @private\n */\nexport const encodeArray: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<ArraySchema>,\n field: number,\n operation: OPERATION,\n it: Iterator,\n isEncodeAll: boolean,\n hasView: boolean,\n) {\n const ref = changeTree.ref;\n const useOperationByRefId = hasView && changeTree.isFiltered && (typeof (changeTree.getType(field)) !== \"string\");\n\n let refOrIndex: number;\n\n if (useOperationByRefId) {\n refOrIndex = ref['tmpItems'][field][$changes].refId;\n\n if (operation === OPERATION.DELETE) {\n operation = OPERATION.DELETE_BY_REFID;\n\n } else if (operation === OPERATION.ADD) {\n operation = OPERATION.ADD_BY_REFID;\n }\n\n } else {\n refOrIndex = field;\n }\n\n // encode operation\n bytes[it.offset++] = operation & 255;\n\n // custom operations\n if (\n operation === OPERATION.CLEAR ||\n operation === OPERATION.REVERSE\n ) {\n return;\n }\n\n // encode index\n encode.number(bytes, refOrIndex, it);\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const type = changeTree.getType(field);\n const value = changeTree.getValue(field, isEncodeAll);\n\n // console.log(\"encodeArray -> \", {\n // ref: changeTree.ref.constructor.name,\n // field,\n // operation: OPERATION[operation],\n // value: value?.toJSON(),\n // items: ref.toJSON(),\n // });\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n type,\n value,\n operation,\n it\n );\n}"]}
1
+ {"version":3,"file":"EncodeOperation.js","sourceRoot":"","sources":["../../src/encoder/EncodeOperation.ts"],"names":[],"mappings":";;;AAyBA,kCA8BC;AAvDD,2CAA6C;AAC7C,8CAAqE;AAErE,+CAA4C;AAsB5C,SAAgB,WAAW,CACvB,OAAgB,EAChB,KAAa,EACb,IAAS,EACT,KAAU,EACV,SAAoB,EACpB,EAAY;IAEZ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC7B,eAAM,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAErC,CAAC;SA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AAS,KAAK,gBAAS,CAAC,OAAO,EACjC,CAAC;QACC,OAAO;IACX,CAAC;IAED,eAAe;IACf,eAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAErC,4CAA4C;IAC5C,IAAI,SAAS,KAAK,gBAAS,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO;IACX,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAEtD,uCAAuC;IAEvC,mCAAmC;IACnC,4CAA4C;IAC5C,aAAa;IACb,uCAAuC;IACvC,8BAA8B;IAC9B,2BAA2B;IAC3B,MAAM;IAEN,yDAAyD;IACzD,WAAW,CACP,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,SAAS,EACT,EAAE,CACL,CAAC;AACN,CAAC,CAAA;AAtEY,QAAA,WAAW,eAsEvB","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { $changes, $childType, $getByIndex } from \"../types/symbols\";\n\nimport { encode } from \"../encoding/encode\";\n\nimport type { ChangeTree, Ref } from \"./ChangeTree\";\nimport type { Encoder } from \"./Encoder\";\nimport type { Schema } from \"../Schema\";\n\nimport type { Iterator } from \"../encoding/decode\";\nimport type { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { Metadata } from \"../Metadata\";\n\nexport type EncodeOperation<T extends Ref = any> = (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<T>,\n index: number,\n operation: OPERATION,\n it: Iterator,\n isEncodeAll: boolean,\n hasView: boolean,\n metadata?: Metadata,\n) => void;\n\nexport function encodeValue(\n encoder: Encoder,\n bytes: Buffer,\n type: any,\n value: any,\n operation: OPERATION,\n it: Iterator,\n) {\n if (typeof (type) === \"string\") {\n encode[type]?.(bytes, value, it);\n\n } else if (type[Symbol.metadata] !== undefined) {\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId, it);\n\n // Try to encode inherited TYPE_ID if it's an ADD operation.\n if ((operation & OPERATION.ADD) === OPERATION.ADD) {\n encoder.tryEncodeTypeId(bytes, type as typeof Schema, value.constructor as typeof Schema, it);\n }\n\n } else {\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId, it);\n }\n}\n\n/**\n * Used for Schema instances.\n * @private\n */\nexport const encodeSchemaOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<Schema>,\n index: number,\n operation: OPERATION,\n it: Iterator,\n _: any,\n __: any,\n metadata: Metadata,\n) {\n // \"compress\" field index + operation\n bytes[it.offset++] = (index | operation) & 255;\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const ref = changeTree.ref;\n const field = metadata[index];\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n metadata[index].type,\n ref[field.name],\n operation,\n it\n );\n}\n\n/**\n * Used for collections (MapSchema, CollectionSchema, SetSchema)\n * @private\n */\nexport const encodeKeyValueOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree,\n index: number,\n operation: OPERATION,\n it: Iterator,\n) {\n // encode operation\n bytes[it.offset++] = operation & 255;\n\n // custom operations\n if (operation === OPERATION.CLEAR) {\n return;\n }\n\n // encode index\n encode.number(bytes, index, it);\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const ref = changeTree.ref;\n\n //\n // encode \"alias\" for dynamic fields (maps)\n //\n if ((operation & OPERATION.ADD) === OPERATION.ADD) { // ADD or DELETE_AND_ADD\n if (typeof(ref['set']) === \"function\") {\n //\n // MapSchema dynamic key\n //\n const dynamicIndex = changeTree.ref['$indexes'].get(index);\n encode.string(bytes, dynamicIndex, it);\n }\n }\n\n const type = ref[$childType];\n const value = ref[$getByIndex](index);\n\n // try { throw new Error(); } catch (e) {\n // // only print if not coming from Reflection.ts\n // if (!e.stack.includes(\"src/Reflection.ts\")) {\n // console.log(\"encodeKeyValueOperation -> \", {\n // ref: changeTree.ref.constructor.name,\n // field,\n // operation: OPERATION[operation],\n // value: value?.toJSON(),\n // items: ref.toJSON(),\n // });\n // }\n // }\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n type,\n value,\n operation,\n it\n );\n}\n\n/**\n * Used for collections (MapSchema, ArraySchema, etc.)\n * @private\n */\nexport const encodeArray: EncodeOperation = function (\n encoder: Encoder,\n bytes: Buffer,\n changeTree: ChangeTree<ArraySchema>,\n field: number,\n operation: OPERATION,\n it: Iterator,\n isEncodeAll: boolean,\n hasView: boolean,\n) {\n const ref = changeTree.ref;\n const useOperationByRefId = hasView && changeTree.isFiltered && (typeof (changeTree.getType(field)) !== \"string\");\n\n let refOrIndex: number;\n\n if (useOperationByRefId) {\n refOrIndex = ref['tmpItems'][field][$changes].refId;\n\n if (operation === OPERATION.DELETE) {\n operation = OPERATION.DELETE_BY_REFID;\n\n } else if (operation === OPERATION.ADD) {\n operation = OPERATION.ADD_BY_REFID;\n }\n\n } else {\n refOrIndex = field;\n }\n\n // encode operation\n bytes[it.offset++] = operation & 255;\n\n // custom operations\n if (\n operation === OPERATION.CLEAR ||\n operation === OPERATION.REVERSE\n ) {\n return;\n }\n\n // encode index\n encode.number(bytes, refOrIndex, it);\n\n // Do not encode value for DELETE operations\n if (operation === OPERATION.DELETE) {\n return;\n }\n\n const type = changeTree.getType(field);\n const value = changeTree.getValue(field, isEncodeAll);\n\n // console.log({ type, field, value });\n\n // console.log(\"encodeArray -> \", {\n // ref: changeTree.ref.constructor.name,\n // field,\n // operation: OPERATION[operation],\n // value: value?.toJSON(),\n // items: ref.toJSON(),\n // });\n\n // TODO: inline this function call small performance gain\n encodeValue(\n encoder,\n bytes,\n type,\n value,\n operation,\n it\n );\n}"]}
@@ -3,6 +3,7 @@ import { TypeContext } from "../types/TypeContext";
3
3
  import type { Iterator } from "../encoding/decode";
4
4
  import { Root } from "./Root";
5
5
  import type { StateView } from "./StateView";
6
+ import type { ChangeSetName } from "./ChangeTree";
6
7
  export declare class Encoder<T extends Schema = any> {
7
8
  static BUFFER_SIZE: number;
8
9
  sharedBuffer: Buffer;
@@ -11,7 +12,7 @@ export declare class Encoder<T extends Schema = any> {
11
12
  root: Root;
12
13
  constructor(state: T);
13
14
  protected setState(state: T): void;
14
- encode(it?: Iterator, view?: StateView, buffer?: Buffer, changeSetName?: "changes" | "allChanges" | "filteredChanges" | "allFilteredChanges", isEncodeAll?: boolean, initialOffset?: number): Buffer;
15
+ encode(it?: Iterator, view?: StateView, buffer?: Buffer, changeSetName?: ChangeSetName, isEncodeAll?: boolean, initialOffset?: number): Buffer;
15
16
  encodeAll(it?: Iterator, buffer?: Buffer): Buffer;
16
17
  encodeAllView(view: StateView, sharedOffset: number, it: Iterator, bytes?: Buffer): Buffer;
17
18
  debugChanges(field: "changes" | "allFilteredChanges" | "allChanges" | "filteredChanges"): void;
@@ -47,10 +47,10 @@ class Encoder {
47
47
  view.invisible.delete(changeTree); // remove from invisible list
48
48
  }
49
49
  }
50
- const operations = changeTree[changeSetName];
50
+ const changeSet = changeTree[changeSetName];
51
51
  const ref = changeTree.ref;
52
52
  // TODO: avoid iterating over change tree if no changes were made
53
- const numChanges = operations.operations.length;
53
+ const numChanges = changeSet.operations.length;
54
54
  if (numChanges === 0) {
55
55
  continue;
56
56
  }
@@ -65,7 +65,7 @@ class Encoder {
65
65
  encode_1.encode.number(buffer, changeTree.refId, it);
66
66
  }
67
67
  for (let j = 0; j < numChanges; j++) {
68
- const fieldIndex = operations.operations[j];
68
+ const fieldIndex = changeSet.operations[j];
69
69
  const operation = (fieldIndex < 0)
70
70
  ? Math.abs(fieldIndex) // "pure" operation without fieldIndex (e.g. CLEAR, REVERSE, etc.)
71
71
  : (isEncodeAll)