@colyseus/schema 3.0.9 → 3.0.10

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.
@@ -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 instance Schema instance
3220
+ * @param ref Schema instance
3221
3221
  * @param showContents display JSON contents of the instance
3222
3222
  * @returns
3223
3223
  */
3224
- static debugRefIds(instance, showContents = false, level = 0) {
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: ${ref[$changes].refId})${contents}\n`;
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
  }
@@ -4041,7 +4041,7 @@
4041
4041
  const refCount = this.refCounts[refId];
4042
4042
  if (refCount === undefined) {
4043
4043
  try {
4044
- throw new DecodingWarning("trying to remove refId that doesn't exist");
4044
+ throw new DecodingWarning("trying to remove refId that doesn't exist: " + refId);
4045
4045
  }
4046
4046
  catch (e) {
4047
4047
  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 instance Schema instance
52
+ * @param ref Schema instance
53
53
  * @param showContents display JSON contents of the instance
54
54
  * @returns
55
55
  */
56
- static debugRefIds(instance: Ref, showContents?: boolean, level?: number): string;
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 instance Schema instance
149
+ * @param ref Schema instance
151
150
  * @param showContents display JSON contents of the instance
152
151
  * @returns
153
152
  */
154
- static debugRefIds(instance, showContents = false, level = 0) {
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: ${ref[symbols_1.$changes].refId})${contents}\n`;
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,KAAK;YACjB,QAAQ,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,sBAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,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AG,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 }\n\n\n}\n\n"]}
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;AAC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efinitionType } 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,EAAE,CAAC;QAC7C,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAEhC,cAAS,GAAyC,EAAE,CAAC;QAClD,iBAAY,GAAW,CAAC,CAAC;IAwHvC,CAAC;IAtHG,eAAe;QACX,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;IAED,eAAe;IACf,MAAM,CAAC,KAAa,EAAE,GAAQ,EAAE,iBAA0B,IAAI;QAC1D,IAAI,CAAC,IA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EAAE,CAAC;YAC3C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC;IAED,cAAc,CAAC,KAAa,EAAE,KAAsB,EAAE,QAAkB;QACpE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,IAAA,iBAAS,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;CAEJ;AApID,4CAoIC","sourcesContent":["import { Metadata } from \"../Metadata\";\nimport { $childType } from \"../types/symbols\";\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\");\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"]}
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,EAAE,CAAC;QAC7C,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAEhC,cAAS,GAAyC,EAAE,CAAC;QAClD,iBAAY,GAAW,CAAC,CAAC;IAwHvC,CAAC;IAtHG,eAAe;QACX,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;IAED,eAAe;IACf,MAAM,CAAC,KAAa,EAAE,GAAQ,EAAE,iBAA0B,IAAI;QAC1D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,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C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC;IAED,cAAc,CAAC,KAAa,EAAE,KAAsB,EAAE,QAAkB;QACpE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,IAAA,iBAAS,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;CAEJ;AApID,4CAoIC","sourcesContent":["import { Metadata } from \"../Metadata\";\nimport { $childType } from \"../types/symbols\";\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"]}
@@ -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);
@@ -1 +1 @@
1
- {"version":3,"file":"ArraySchema.js","sourceRoot":"","sources":["../../../src/types/custom/ArraySchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAwI;AAExI,yDAA2E;AAC3E,8CAAgD;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AC;IAClB,CAAC;IAAA,CAAC;;AAvxBN,kCAyxBC;AAED,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd } from \"../symbols\";\nimport type { Schema } from \"../../Schema\";\nimport { ChangeTree, setOperationAtIndex } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\n\nimport { encodeArray } from \"../../encoder/EncodeOperation\";\nimport { decodeArray } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport { assertInstanceType } from \"../../encoding/assert\";\n\nconst DEFAULT_SORT = (a: any, b: any) => {\n const A = a.toString();\n const B = b.toString();\n if (A < B) return -1;\n else if (A > B) return 1;\n else return 0\n}\n\nexport class ArraySchema<V = any> implements Array<V>, Collection<number, V> {\n [n: number]: V;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n\n static [$encoder] = encodeArray;\n static [$decoder] = decodeArray;\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: ArraySchema, index: number, view: StateView) {\n // console.log(\"ArraSchema[$filter] VIEW??\", !view)\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n // view.items.has(ref[$getByIndex](index)[$changes])\n view.items.has(ref['tmpItems'][index]?.[$changes])\n );\n }\n\n static is(type: any) {\n return (\n // type format: [\"string\"]\n Array.isArray(type) ||\n\n // type format: { array: \"string\" }\n (type['array'] !== undefined)\n );\n }\n\n static from<T>(iterable: Iterable<T> | ArrayLike<T>) {\n return new ArraySchema<T>(...Array.from(iterable));\n }\n\n constructor (...items: V[]) {\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n\n const proxy = new Proxy(this, {\n get: (obj, prop) => {\n if (\n typeof (prop) !== \"symbol\" &&\n // FIXME: d8 accuses this as low performance\n !isNaN(prop as any) // https://stackoverflow.com/a/175787/892698\n ) {\n return this.items[prop];\n\n } else {\n return Reflect.get(obj, prop);\n }\n },\n\n set: (obj, key, setValue) => {\n if (typeof (key) !== \"symbol\" && !isNaN(key as any)) {\n if (setValue === undefined || setValue === null) {\n obj.$deleteAt(key as unknown as number);\n\n } else {\n if (setValue[$changes]) {\n assertInstanceType(setValue, obj[$childType] as typeof Schema, obj, key);\n\n if (obj.items[key as unknown as number] !== undefined) {\n if (setValue[$changes].isNew) {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n this[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n } else {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n } else if (setValue[$changes].isNew) {\n this[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n this.items[key as unknown as number] = setValue;\n this.tmpItems[key as unknown as number] = setValue;\n }\n\n return true;\n } else {\n return Reflect.set(obj, key, setValue);\n }\n },\n\n deleteProperty: (obj, prop) => {\n if (typeof (prop) === \"number\") {\n obj.$deleteAt(prop);\n\n } else {\n delete obj[prop];\n }\n\n return true;\n },\n\n has: (obj, key) => {\n if (typeof (key) !== \"symbol\" && !isNaN(Number(key))) {\n return Reflect.has(this.items, key);\n }\n return Reflect.has(obj, key)\n }\n });\n\n this[$changes] = new ChangeTree(proxy);\n this[$changes].indexes = {};\n\n if (items.length > 0) {\n this.push(...items);\n }\n\n return proxy;\n }\n\n set length (newLength: number) {\n if (newLength === 0) {\n this.clear();\n } else if (newLength < this.items.length) {\n this.splice(newLength, this.length - newLength);\n } else {\n console.warn(\"ArraySchema: can't set .length to a higher value than its length.\");\n }\n }\n\n get length() {\n return this.items.length;\n }\n\n push(...values: V[]) {\n let length = this.tmpItems.length;\n\n const changeTree = this[$changes];\n\n // values.forEach((value, i) => {\n\n for (let i = 0, l = values.length; i < values.length; i++, length++) {\n const value = values[i];\n\n if (value === undefined || value === null) {\n // skip null values\n return;\n\n } else if (typeof (value) === \"object\" && this[$childType]) {\n assertInstanceType(value as any, this[$childType] as typeof Schema, this, i);\n // TODO: move value[$changes]?.setParent() to this block.\n }\n\n changeTree.indexedOperation(length, OPERATION.ADD, this.items.length);\n\n this.items.push(value);\n this.tmpItems.push(value);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, length);\n }\n\n // length++;\n // });\n\n return length;\n }\n\n /**\n * Removes the last element from an array and returns it.\n */\n pop(): V | undefined {\n let index: number = -1;\n\n // find last non-undefined index\n for (let i = this.tmpItems.length - 1; i >= 0; i--) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n index = i;\n break;\n }\n }\n\n if (index < 0) {\n return undefined;\n }\n\n this[$changes].delete(index, undefined, this.items.length - 1);\n\n // this.tmpItems[index] = undefined;\n // this.tmpItems.pop();\n\n this.deletedIndexes[index] = true;\n\n return this.items.pop();\n }\n\n at(index: number) {\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n return this.items[index];\n }\n\n // encoding only\n protected $changeAt(index: number, value: V) {\n if (value === undefined || value === null) {\n console.error(\"ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.\");\n return;\n }\n\n // skip if the value is the same as cached.\n if (this.items[index] === value) {\n return;\n }\n\n const changeTree = this[$changes];\n const operation = changeTree.indexes?.[index]?.op ?? OPERATION.ADD;\n\n changeTree.change(index, operation);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, index);\n }\n\n // encoding only\n protected $deleteAt(index: number, operation?: OPERATION) {\n this[$changes].delete(index, operation);\n }\n\n // decoding only\n protected $setAt(index: number, value: V, operation: OPERATION) {\n if (\n index === 0 &&\n operation === OPERATION.ADD &&\n this.items[index] !== undefined\n ) {\n // handle decoding unshift\n this.items.unshift(value);\n\n } else if (operation === OPERATION.DELETE_AND_MOVE) {\n this.items.splice(index, 1);\n this.items[index] = value;\n\n } else {\n this.items[index] = value;\n }\n }\n\n clear() {\n // skip if already clear\n if (this.items.length === 0) {\n return;\n }\n\n // discard previous operations.\n const changeTree = this[$changes];\n\n // discard children\n changeTree.forEachChild((changeTree, _) => {\n changeTree.discard(true);\n\n //\n // TODO: add tests with instance sharing + .clear()\n // FIXME: this.root? is required because it is being called at decoding time.\n //\n // TODO: do not use [$changes] at decoding time.\n //\n const root = changeTree.root;\n if (root !== undefined) {\n root.removeChangeFromChangeSet(\"changes\", changeTree);\n root.removeChangeFromChangeSet(\"allChanges\", changeTree);\n root.removeChangeFromChangeSet(\"allFilteredChanges\", changeTree);\n }\n });\n\n changeTree.discard(true);\n changeTree.operation(OPERATION.CLEAR);\n\n this.items.length = 0;\n this.tmpItems.length = 0;\n }\n\n /**\n * Combines two or more arrays.\n * @param items Additional items to add to the end of array1.\n */\n // @ts-ignore\n concat(...items: (V | ConcatArray<V>)[]): ArraySchema<V> {\n return new ArraySchema(...this.items.concat(...items));\n }\n\n /**\n * Adds all the elements of an array separated by the specified separator string.\n * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.\n */\n join(separator?: string): string {\n return this.items.join(separator);\n }\n\n /**\n * Reverses the elements in an Array.\n */\n // @ts-ignore\n reverse(): ArraySchema<V> {\n this[$changes].operation(OPERATION.REVERSE);\n this.items.reverse();\n this.tmpItems.reverse();\n return this;\n }\n\n /**\n * Removes the first element from an array and returns it.\n */\n shift(): V | undefined {\n if (this.items.length === 0) { return undefined; }\n\n // const index = Number(Object.keys(changeTree.indexes)[0]);\n const index = this.tmpItems.findIndex((item, i) => item === this.items[0]);\n const changeTree = this[$changes];\n\n changeTree.delete(index);\n changeTree.shiftAllChangeIndexes(-1, index);\n\n // this.deletedIndexes[index] = true;\n\n return this.items.shift();\n }\n\n /**\n * Returns a section of an array.\n * @param start The beginning of the specified portion of the array.\n * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.\n */\n slice(start?: number, end?: number): V[] {\n const sliced = new ArraySchema<V>();\n sliced.push(...this.items.slice(start, end));\n return sliced as unknown as V[];\n }\n\n /**\n * Sorts an array.\n * @param compareFn Function used to determine the order of the elements. It is expected to return\n * a negative value if first argument is less than second argument, zero if they're equal and a positive\n * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.\n * ```ts\n * [11,2,22,1].sort((a, b) => a - b)\n * ```\n */\n sort(compareFn: (a: V, b: V) => number = DEFAULT_SORT): this {\n const changeTree = this[$changes];\n const sortedItems = this.items.sort(compareFn);\n\n // wouldn't OPERATION.MOVE make more sense here?\n sortedItems.forEach((_, i) => changeTree.change(i, OPERATION.REPLACE));\n\n this.tmpItems.sort(compareFn);\n return this;\n }\n\n /**\n * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.\n * @param start The zero-based location in the array from which to start removing elements.\n * @param deleteCount The number of elements to remove.\n * @param insertItems Elements to insert into the array in place of the deleted elements.\n */\n splice(\n start: number,\n deleteCount: number = this.items.length - start,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const tmpItemsLength = this.tmpItems.length;\n const insertCount = insertItems.length;\n\n // build up-to-date list of indexes, excluding removed values.\n const indexes: number[] = [];\n for (let i = 0; i < tmpItemsLength; i++) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n // delete operations at correct index\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index);\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n }\n\n // force insert operations\n for (let i = 0; i < insertCount; i++) {\n const addIndex = indexes[start] + i;\n changeTree.indexedOperation(addIndex, OPERATION.ADD);\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\n\n //\n // delete exceeding indexes from \"allChanges\"\n // (prevent .encodeAll() from encoding non-existing items)\n //\n if (deleteCount > insertCount) {\n changeTree.shiftAllChangeIndexes(-(deleteCount - insertCount), indexes[start + insertCount]);\n }\n\n return this.items.splice(start, deleteCount, ...insertItems);\n }\n\n /**\n * Inserts new elements at the start of an array.\n * @param items Elements to insert at the start of the Array.\n */\n unshift(...items: V[]): number {\n const changeTree = this[$changes];\n\n // shift indexes\n changeTree.shiftChangeIndexes(items.length);\n\n // new index\n if (changeTree.isFiltered) {\n setOperationAtIndex(changeTree.filteredChanges, this.items.length);\n // changeTree.filteredChanges[this.items.length] = OPERATION.ADD;\n } else {\n setOperationAtIndex(changeTree.allChanges, this.items.length);\n // changeTree.allChanges[this.items.length] = OPERATION.ADD;\n }\n\n // FIXME: should we use OPERATION.MOVE here instead?\n items.forEach((_, index) => {\n changeTree.change(index, OPERATION.ADD)\n });\n\n this.tmpItems.unshift(...items);\n\n return this.items.unshift(...items);\n }\n\n /**\n * Returns the index of the first occurrence of a value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\n indexOf(searchElement: V, fromIndex?: number): number {\n return this.items.indexOf(searchElement, fromIndex);\n }\n\n /**\n * Returns the index of the last occurrence of a specified value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.\n */\n lastIndexOf(searchElement: V, fromIndex: number = this.length - 1): number {\n return this.items.lastIndexOf(searchElement, fromIndex);\n }\n\n /**\n * Determines whether all the members of an array satisfy the specified test.\n * @param callbackfn A function that accepts up to three arguments. The every method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value false, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n every<S extends V>(predicate: (value: V, index: number, array: V[]) => value is S, thisArg?: any): this is S[];\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean;\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.every(callbackfn, thisArg);\n }\n\n /**\n * Determines whether the specified callback function returns true for any element of an array.\n * @param callbackfn A function that accepts up to three arguments. The some method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value true, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n some(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.some(callbackfn, thisArg);\n }\n\n /**\n * Performs the specified action for each element in an array.\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n forEach(callbackfn: (value: V, index: number, array: V[]) => void, thisArg?: any): void {\n return this.items.forEach(callbackfn, thisArg);\n }\n\n /**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n map<U>(callbackfn: (value: V, index: number, array: V[]) => U, thisArg?: any): U[] {\n return this.items.map(callbackfn, thisArg);\n }\n\n /**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[]\n filter<S extends V>(callbackfn: (value: V, index: number, array: V[]) => value is S, thisArg?: any): V[] {\n return this.items.filter(callbackfn, thisArg);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduce<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduce(callbackfn, initialValue);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduceRight<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduceRight(callbackfn, initialValue);\n }\n\n /**\n * Returns the value of the first element in the array where predicate is true, and undefined\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n find(predicate: (value: V, index: number, obj: V[]) => boolean, thisArg?: any): V | undefined {\n return this.items.find(predicate, thisArg);\n }\n\n /**\n * Returns the index of the first element in the array where predicate is true, and -1\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findIndex immediately returns that element index. Otherwise, findIndex returns -1.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n findIndex(predicate: (value: V, index: number, obj: V[]) => unknown, thisArg?: any): number {\n return this.items.findIndex(predicate, thisArg);\n }\n\n /**\n * Returns the this object after filling the section identified by start and end with value\n * @param value value to fill array section with\n * @param start index to start filling the array at. If start is negative, it is treated as\n * length+start where length is the length of the array.\n * @param end index to stop filling the array at. If end is negative, it is treated as\n * length+end.\n */\n fill(value: V, start?: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#fill() not implemented\");\n // this.$items.fill(value, start, end);\n\n return this;\n }\n\n /**\n * Returns the this object after copying a section of the array identified by start and end\n * to the same array starting at position target\n * @param target If target is negative, it is treated as length+target where length is the\n * length of the array.\n * @param start If start is negative, it is treated as length+start. If end is negative, it\n * is treated as length+end.\n * @param end If not specified, length of the this object is used as its default value.\n */\n copyWithin(target: number, start: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#copyWithin() not implemented\");\n return this;\n }\n\n /**\n * Returns a string representation of an array.\n */\n toString(): string {\n return this.items.toString();\n }\n\n /**\n * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.\n */\n toLocaleString(): string {\n return this.items.toLocaleString()\n };\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.items[Symbol.iterator]();\n }\n\n static get [Symbol.species]() {\n return ArraySchema;\n }\n\n // WORKAROUND for compatibility\n // - TypeScript 4 defines @@unscopables as a function\n // - TypeScript 5 defines @@unscopables as an object\n [Symbol.unscopables]: any;\n\n /**\n * Returns an iterable of key, value pairs for every entry in the array\n */\n entries(): IterableIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): IterableIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): IterableIterator<V> { return this.items.values(); }\n\n /**\n * Determines whether an array includes a certain element, returning true or false as appropriate.\n * @param searchElement The element to search for.\n * @param fromIndex The position in this array at which to begin searching for searchElement.\n */\n includes(searchElement: V, fromIndex?: number): boolean {\n return this.items.includes(searchElement, fromIndex);\n }\n\n //\n // ES2022\n //\n\n /**\n * Calls a defined callback function on each element of an array. Then, flattens the result into\n * a new array.\n * This is identical to a map followed by flat with depth 1.\n *\n * @param callback A function that accepts up to three arguments. The flatMap method calls the\n * callback function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callback function. If\n * thisArg is omitted, undefined is used as the this value.\n */\n // @ts-ignore\n flatMap<U, This = undefined>(callback: (this: This, value: V, index: number, array: V[]) => U | ReadonlyArray<U>, thisArg?: This): U[] {\n // @ts-ignore\n throw new Error(\"ArraySchema#flatMap() is not supported.\");\n }\n\n /**\n * Returns a new array with all sub-array elements concatenated into it recursively up to the\n * specified depth.\n *\n * @param depth The maximum recursion depth\n */\n // @ts-ignore\n flat<A, D extends number = 1>(this: A, depth?: D): any {\n throw new Error(\"ArraySchema#flat() is not supported.\");\n }\n\n findLast() {\n // @ts-ignore\n return this.items.findLast.apply(this.items, arguments);\n }\n\n findLastIndex(...args) {\n // @ts-ignore\n return this.items.findLastIndex.apply(this.items, arguments);\n }\n\n //\n // ES2023\n //\n with(index: number, value: V): ArraySchema<V> {\n const copy = this.items.slice();\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n copy[index] = value;\n return new ArraySchema(...copy);\n }\n toReversed(): V[] {\n return this.items.slice().reverse();\n }\n toSorted(compareFn?: (a: V, b: V) => number): V[] {\n return this.items.slice().sort(compareFn);\n }\n toSpliced(start: number, deleteCount: number, ...items: V[]): V[];\n toSpliced(start: number, deleteCount?: number): V[];\n // @ts-ignore\n toSpliced(start: unknown, deleteCount?: unknown, ...items?: unknown[]): V[] {\n // @ts-ignore\n return this.items.toSpliced.apply(copy, arguments);\n }\n\n protected [$getByIndex](index: number, isEncodeAll: boolean = false) {\n //\n // TODO: avoid unecessary `this.tmpItems` check during decoding.\n //\n // ENCODING uses `this.tmpItems` (or `this.items` if `isEncodeAll` is true)\n // DECODING uses `this.items`\n //\n\n return (isEncodeAll)\n ? this.items[index]\n : this.deletedIndexes[index]\n ? this.items[index]\n : this.tmpItems[index] || this.items[index];\n\n // return (isEncodeAll)\n // ? this.items[index]\n // : this.tmpItems[index] ?? this.items[index];\n }\n\n protected [$deleteByIndex](index: number) {\n this.items[index] = undefined;\n }\n\n protected [$onEncodeEnd]() {\n this.tmpItems = this.items.slice();\n this.deletedIndexes = {};\n }\n\n protected [$onDecodeEnd]() {\n this.items = this.items.filter((item) => item !== undefined);\n }\n\n toArray() {\n return this.items.slice(0);\n }\n\n toJSON() {\n return this.toArray().map((value) => {\n return (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): ArraySchema<V> {\n let cloned: ArraySchema;\n\n if (isDecoding) {\n cloned = new ArraySchema();\n cloned.push(...this.items);\n\n } else {\n cloned = new ArraySchema(...this.map(item => (\n (item[$changes])\n ? (item as any as Schema).clone()\n : item\n )));\n }\n\n return cloned;\n };\n\n}\n\nregisterType(\"array\", { constructor: ArraySchema });"]}
1
+ {"version":3,"file":"ArraySchema.js","sourceRoot":"","sources":["../../../src/types/custom/ArraySchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAwI;AAExI,yDAA2E;AAC3E,8CAAgD;AAChD,0CAA2C;AAG3C,mEAA4D;AAC5D,mEAA4D;AAE5D,kDAA2D;AAE3D,MAAM,YAAY,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;IACpC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;;QACpB,OAAO,CAAC,CAAA;AACjB,CAAC,CAAA;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CAAC,CAAC;QAC7D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,+CAA+C;IACvF,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAChC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,UAAU,CAAC;gBAC5C,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBACnB,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,EAAE;IACF,qBAAqB;IACrB,EAAE;IACF,KAAK,CAAC,UAAoB;QACtB,IAAI,MAAmB,CAAC;QAExB,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC3B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAE/B,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CACzC,CAAC,IAAI,CAAC,kBAAQ,CAAC,CAAC;gBACZ,CAAC,CAAE,IAAsB,CAAC,KAAK,EAAE;gBACjC,CAAC,CAAC,IAAI,CACb,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAAA,CAAC;;AAxxBN,kCA0xBC;AAED,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd } from \"../symbols\";\nimport type { Schema } from \"../../Schema\";\nimport { ChangeTree, setOperationAtIndex } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\n\nimport { encodeArray } from \"../../encoder/EncodeOperation\";\nimport { decodeArray } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport { assertInstanceType } from \"../../encoding/assert\";\n\nconst DEFAULT_SORT = (a: any, b: any) => {\n const A = a.toString();\n const B = b.toString();\n if (A < B) return -1;\n else if (A > B) return 1;\n else return 0\n}\n\nexport class ArraySchema<V = any> implements Array<V>, Collection<number, V> {\n [n: number]: V;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n\n static [$encoder] = encodeArray;\n static [$decoder] = decodeArray;\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: ArraySchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n // view.items.has(ref[$getByIndex](index)[$changes])\n view.items.has(ref['tmpItems'][index]?.[$changes])\n );\n }\n\n static is(type: any) {\n return (\n // type format: [\"string\"]\n Array.isArray(type) ||\n\n // type format: { array: \"string\" }\n (type['array'] !== undefined)\n );\n }\n\n static from<T>(iterable: Iterable<T> | ArrayLike<T>) {\n return new ArraySchema<T>(...Array.from(iterable));\n }\n\n constructor (...items: V[]) {\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n\n const proxy = new Proxy(this, {\n get: (obj, prop) => {\n if (\n typeof (prop) !== \"symbol\" &&\n // FIXME: d8 accuses this as low performance\n !isNaN(prop as any) // https://stackoverflow.com/a/175787/892698\n ) {\n return this.items[prop];\n\n } else {\n return Reflect.get(obj, prop);\n }\n },\n\n set: (obj, key, setValue) => {\n if (typeof (key) !== \"symbol\" && !isNaN(key as any)) {\n if (setValue === undefined || setValue === null) {\n obj.$deleteAt(key as unknown as number);\n\n } else {\n if (setValue[$changes]) {\n assertInstanceType(setValue, obj[$childType] as typeof Schema, obj, key);\n\n if (obj.items[key as unknown as number] !== undefined) {\n if (setValue[$changes].isNew) {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n this[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n } else {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n } else if (setValue[$changes].isNew) {\n this[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n this.items[key as unknown as number] = setValue;\n this.tmpItems[key as unknown as number] = setValue;\n }\n\n return true;\n } else {\n return Reflect.set(obj, key, setValue);\n }\n },\n\n deleteProperty: (obj, prop) => {\n if (typeof (prop) === \"number\") {\n obj.$deleteAt(prop);\n\n } else {\n delete obj[prop];\n }\n\n return true;\n },\n\n has: (obj, key) => {\n if (typeof (key) !== \"symbol\" && !isNaN(Number(key))) {\n return Reflect.has(this.items, key);\n }\n return Reflect.has(obj, key)\n }\n });\n\n this[$changes] = new ChangeTree(proxy);\n this[$changes].indexes = {};\n\n if (items.length > 0) {\n this.push(...items);\n }\n\n return proxy;\n }\n\n set length (newLength: number) {\n if (newLength === 0) {\n this.clear();\n } else if (newLength < this.items.length) {\n this.splice(newLength, this.length - newLength);\n } else {\n console.warn(\"ArraySchema: can't set .length to a higher value than its length.\");\n }\n }\n\n get length() {\n return this.items.length;\n }\n\n push(...values: V[]) {\n let length = this.tmpItems.length;\n\n const changeTree = this[$changes];\n\n // values.forEach((value, i) => {\n\n for (let i = 0, l = values.length; i < values.length; i++, length++) {\n const value = values[i];\n\n if (value === undefined || value === null) {\n // skip null values\n return;\n\n } else if (typeof (value) === \"object\" && this[$childType]) {\n assertInstanceType(value as any, this[$childType] as typeof Schema, this, i);\n // TODO: move value[$changes]?.setParent() to this block.\n }\n\n changeTree.indexedOperation(length, OPERATION.ADD, this.items.length);\n\n this.items.push(value);\n this.tmpItems.push(value);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, length);\n }\n\n // length++;\n // });\n\n return length;\n }\n\n /**\n * Removes the last element from an array and returns it.\n */\n pop(): V | undefined {\n let index: number = -1;\n\n // find last non-undefined index\n for (let i = this.tmpItems.length - 1; i >= 0; i--) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n index = i;\n break;\n }\n }\n\n if (index < 0) {\n return undefined;\n }\n\n this[$changes].delete(index, undefined, this.items.length - 1);\n\n // this.tmpItems[index] = undefined;\n // this.tmpItems.pop();\n\n this.deletedIndexes[index] = true;\n\n return this.items.pop();\n }\n\n at(index: number) {\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n return this.items[index];\n }\n\n // encoding only\n protected $changeAt(index: number, value: V) {\n if (value === undefined || value === null) {\n console.error(\"ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.\");\n return;\n }\n\n // skip if the value is the same as cached.\n if (this.items[index] === value) {\n return;\n }\n\n const changeTree = this[$changes];\n const operation = changeTree.indexes?.[index]?.op ?? OPERATION.ADD;\n\n changeTree.change(index, operation);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, index);\n }\n\n // encoding only\n protected $deleteAt(index: number, operation?: OPERATION) {\n this[$changes].delete(index, operation);\n }\n\n // decoding only\n protected $setAt(index: number, value: V, operation: OPERATION) {\n if (\n index === 0 &&\n operation === OPERATION.ADD &&\n this.items[index] !== undefined\n ) {\n // handle decoding unshift\n this.items.unshift(value);\n\n } else if (operation === OPERATION.DELETE_AND_MOVE) {\n this.items.splice(index, 1);\n this.items[index] = value;\n\n } else {\n this.items[index] = value;\n }\n }\n\n clear() {\n // skip if already clear\n if (this.items.length === 0) {\n return;\n }\n\n // discard previous operations.\n const changeTree = this[$changes];\n\n // discard children\n changeTree.forEachChild((changeTree, _) => {\n changeTree.discard(true);\n\n //\n // TODO: add tests with instance sharing + .clear()\n // FIXME: this.root? is required because it is being called at decoding time.\n //\n // TODO: do not use [$changes] at decoding time.\n //\n const root = changeTree.root;\n if (root !== undefined) {\n root.removeChangeFromChangeSet(\"changes\", changeTree);\n root.removeChangeFromChangeSet(\"allChanges\", changeTree);\n root.removeChangeFromChangeSet(\"allFilteredChanges\", changeTree);\n }\n });\n\n changeTree.discard(true);\n changeTree.operation(OPERATION.CLEAR);\n\n this.items.length = 0;\n this.tmpItems.length = 0;\n }\n\n /**\n * Combines two or more arrays.\n * @param items Additional items to add to the end of array1.\n */\n // @ts-ignore\n concat(...items: (V | ConcatArray<V>)[]): ArraySchema<V> {\n return new ArraySchema(...this.items.concat(...items));\n }\n\n /**\n * Adds all the elements of an array separated by the specified separator string.\n * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.\n */\n join(separator?: string): string {\n return this.items.join(separator);\n }\n\n /**\n * Reverses the elements in an Array.\n */\n // @ts-ignore\n reverse(): ArraySchema<V> {\n this[$changes].operation(OPERATION.REVERSE);\n this.items.reverse();\n this.tmpItems.reverse();\n return this;\n }\n\n /**\n * Removes the first element from an array and returns it.\n */\n shift(): V | undefined {\n if (this.items.length === 0) { return undefined; }\n\n // const index = Number(Object.keys(changeTree.indexes)[0]);\n const index = this.tmpItems.findIndex((item, i) => item === this.items[0]);\n const changeTree = this[$changes];\n\n changeTree.delete(index);\n changeTree.shiftAllChangeIndexes(-1, index);\n\n // this.deletedIndexes[index] = true;\n\n return this.items.shift();\n }\n\n /**\n * Returns a section of an array.\n * @param start The beginning of the specified portion of the array.\n * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.\n */\n slice(start?: number, end?: number): V[] {\n const sliced = new ArraySchema<V>();\n sliced.push(...this.items.slice(start, end));\n return sliced as unknown as V[];\n }\n\n /**\n * Sorts an array.\n * @param compareFn Function used to determine the order of the elements. It is expected to return\n * a negative value if first argument is less than second argument, zero if they're equal and a positive\n * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.\n * ```ts\n * [11,2,22,1].sort((a, b) => a - b)\n * ```\n */\n sort(compareFn: (a: V, b: V) => number = DEFAULT_SORT): this {\n const changeTree = this[$changes];\n const sortedItems = this.items.sort(compareFn);\n\n // wouldn't OPERATION.MOVE make more sense here?\n sortedItems.forEach((_, i) => changeTree.change(i, OPERATION.REPLACE));\n\n this.tmpItems.sort(compareFn);\n return this;\n }\n\n /**\n * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.\n * @param start The zero-based location in the array from which to start removing elements.\n * @param deleteCount The number of elements to remove.\n * @param insertItems Elements to insert into the array in place of the deleted elements.\n */\n splice(\n start: number,\n deleteCount: number = this.items.length - start,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const tmpItemsLength = this.tmpItems.length;\n const insertCount = insertItems.length;\n\n // build up-to-date list of indexes, excluding removed values.\n const indexes: number[] = [];\n for (let i = 0; i < tmpItemsLength; i++) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n // delete operations at correct index\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index);\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n }\n\n // force insert operations\n for (let i = 0; i < insertCount; i++) {\n const addIndex = indexes[start] + i;\n changeTree.indexedOperation(addIndex, OPERATION.ADD);\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\n\n //\n // delete exceeding indexes from \"allChanges\"\n // (prevent .encodeAll() from encoding non-existing items)\n //\n if (deleteCount > insertCount) {\n changeTree.shiftAllChangeIndexes(-(deleteCount - insertCount), indexes[start + insertCount]);\n }\n\n return this.items.splice(start, deleteCount, ...insertItems);\n }\n\n /**\n * Inserts new elements at the start of an array.\n * @param items Elements to insert at the start of the Array.\n */\n unshift(...items: V[]): number {\n const changeTree = this[$changes];\n\n // shift indexes\n changeTree.shiftChangeIndexes(items.length);\n\n // new index\n if (changeTree.isFiltered) {\n setOperationAtIndex(changeTree.filteredChanges, this.items.length);\n // changeTree.filteredChanges[this.items.length] = OPERATION.ADD;\n } else {\n setOperationAtIndex(changeTree.allChanges, this.items.length);\n // changeTree.allChanges[this.items.length] = OPERATION.ADD;\n }\n\n // FIXME: should we use OPERATION.MOVE here instead?\n items.forEach((_, index) => {\n changeTree.change(index, OPERATION.ADD)\n });\n\n this.tmpItems.unshift(...items);\n\n return this.items.unshift(...items);\n }\n\n /**\n * Returns the index of the first occurrence of a value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\n indexOf(searchElement: V, fromIndex?: number): number {\n return this.items.indexOf(searchElement, fromIndex);\n }\n\n /**\n * Returns the index of the last occurrence of a specified value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.\n */\n lastIndexOf(searchElement: V, fromIndex: number = this.length - 1): number {\n return this.items.lastIndexOf(searchElement, fromIndex);\n }\n\n /**\n * Determines whether all the members of an array satisfy the specified test.\n * @param callbackfn A function that accepts up to three arguments. The every method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value false, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n every<S extends V>(predicate: (value: V, index: number, array: V[]) => value is S, thisArg?: any): this is S[];\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean;\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.every(callbackfn, thisArg);\n }\n\n /**\n * Determines whether the specified callback function returns true for any element of an array.\n * @param callbackfn A function that accepts up to three arguments. The some method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value true, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n some(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.some(callbackfn, thisArg);\n }\n\n /**\n * Performs the specified action for each element in an array.\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n forEach(callbackfn: (value: V, index: number, array: V[]) => void, thisArg?: any): void {\n return this.items.forEach(callbackfn, thisArg);\n }\n\n /**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n map<U>(callbackfn: (value: V, index: number, array: V[]) => U, thisArg?: any): U[] {\n return this.items.map(callbackfn, thisArg);\n }\n\n /**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[]\n filter<S extends V>(callbackfn: (value: V, index: number, array: V[]) => value is S, thisArg?: any): V[] {\n return this.items.filter(callbackfn, thisArg);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduce<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduce(callbackfn, initialValue);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduceRight<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduceRight(callbackfn, initialValue);\n }\n\n /**\n * Returns the value of the first element in the array where predicate is true, and undefined\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n find(predicate: (value: V, index: number, obj: V[]) => boolean, thisArg?: any): V | undefined {\n return this.items.find(predicate, thisArg);\n }\n\n /**\n * Returns the index of the first element in the array where predicate is true, and -1\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findIndex immediately returns that element index. Otherwise, findIndex returns -1.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n findIndex(predicate: (value: V, index: number, obj: V[]) => unknown, thisArg?: any): number {\n return this.items.findIndex(predicate, thisArg);\n }\n\n /**\n * Returns the this object after filling the section identified by start and end with value\n * @param value value to fill array section with\n * @param start index to start filling the array at. If start is negative, it is treated as\n * length+start where length is the length of the array.\n * @param end index to stop filling the array at. If end is negative, it is treated as\n * length+end.\n */\n fill(value: V, start?: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#fill() not implemented\");\n // this.$items.fill(value, start, end);\n\n return this;\n }\n\n /**\n * Returns the this object after copying a section of the array identified by start and end\n * to the same array starting at position target\n * @param target If target is negative, it is treated as length+target where length is the\n * length of the array.\n * @param start If start is negative, it is treated as length+start. If end is negative, it\n * is treated as length+end.\n * @param end If not specified, length of the this object is used as its default value.\n */\n copyWithin(target: number, start: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#copyWithin() not implemented\");\n return this;\n }\n\n /**\n * Returns a string representation of an array.\n */\n toString(): string {\n return this.items.toString();\n }\n\n /**\n * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.\n */\n toLocaleString(): string {\n return this.items.toLocaleString()\n };\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.items[Symbol.iterator]();\n }\n\n static get [Symbol.species]() {\n return ArraySchema;\n }\n\n // WORKAROUND for compatibility\n // - TypeScript 4 defines @@unscopables as a function\n // - TypeScript 5 defines @@unscopables as an object\n [Symbol.unscopables]: any;\n\n /**\n * Returns an iterable of key, value pairs for every entry in the array\n */\n entries(): IterableIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): IterableIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): IterableIterator<V> { return this.items.values(); }\n\n /**\n * Determines whether an array includes a certain element, returning true or false as appropriate.\n * @param searchElement The element to search for.\n * @param fromIndex The position in this array at which to begin searching for searchElement.\n */\n includes(searchElement: V, fromIndex?: number): boolean {\n return this.items.includes(searchElement, fromIndex);\n }\n\n //\n // ES2022\n //\n\n /**\n * Calls a defined callback function on each element of an array. Then, flattens the result into\n * a new array.\n * This is identical to a map followed by flat with depth 1.\n *\n * @param callback A function that accepts up to three arguments. The flatMap method calls the\n * callback function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callback function. If\n * thisArg is omitted, undefined is used as the this value.\n */\n // @ts-ignore\n flatMap<U, This = undefined>(callback: (this: This, value: V, index: number, array: V[]) => U | ReadonlyArray<U>, thisArg?: This): U[] {\n // @ts-ignore\n throw new Error(\"ArraySchema#flatMap() is not supported.\");\n }\n\n /**\n * Returns a new array with all sub-array elements concatenated into it recursively up to the\n * specified depth.\n *\n * @param depth The maximum recursion depth\n */\n // @ts-ignore\n flat<A, D extends number = 1>(this: A, depth?: D): any {\n throw new Error(\"ArraySchema#flat() is not supported.\");\n }\n\n findLast() {\n // @ts-ignore\n return this.items.findLast.apply(this.items, arguments);\n }\n\n findLastIndex(...args) {\n // @ts-ignore\n return this.items.findLastIndex.apply(this.items, arguments);\n }\n\n //\n // ES2023\n //\n with(index: number, value: V): ArraySchema<V> {\n const copy = this.items.slice();\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n copy[index] = value;\n return new ArraySchema(...copy);\n }\n toReversed(): V[] {\n return this.items.slice().reverse();\n }\n toSorted(compareFn?: (a: V, b: V) => number): V[] {\n return this.items.slice().sort(compareFn);\n }\n toSpliced(start: number, deleteCount: number, ...items: V[]): V[];\n toSpliced(start: number, deleteCount?: number): V[];\n // @ts-ignore\n toSpliced(start: unknown, deleteCount?: unknown, ...items?: unknown[]): V[] {\n // @ts-ignore\n return this.items.toSpliced.apply(copy, arguments);\n }\n\n protected [$getByIndex](index: number, isEncodeAll: boolean = false) {\n //\n // TODO: avoid unecessary `this.tmpItems` check during decoding.\n //\n // ENCODING uses `this.tmpItems` (or `this.items` if `isEncodeAll` is true)\n // DECODING uses `this.items`\n //\n\n return (isEncodeAll)\n ? this.items[index]\n : this.deletedIndexes[index]\n ? this.items[index]\n : this.tmpItems[index] || this.items[index];\n\n // return (isEncodeAll)\n // ? this.items[index]\n // : this.tmpItems[index] ?? this.items[index];\n }\n\n protected [$deleteByIndex](index: number) {\n this.items[index] = undefined;\n this.tmpItems[index] = undefined; // TODO: do not try to get \"tmpItems\" at decoding time.\n }\n\n protected [$onEncodeEnd]() {\n this.tmpItems = this.items.slice();\n this.deletedIndexes = {};\n }\n\n protected [$onDecodeEnd]() {\n this.items = this.items.filter((item) => item !== undefined);\n this.tmpItems = this.items.slice(); // TODO: do no use \"tmpItems\" at decoding time.\n }\n\n toArray() {\n return this.items.slice(0);\n }\n\n toJSON() {\n return this.toArray().map((value) => {\n return (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): ArraySchema<V> {\n let cloned: ArraySchema;\n\n if (isDecoding) {\n cloned = new ArraySchema();\n cloned.push(...this.items);\n\n } else {\n cloned = new ArraySchema(...this.map(item => (\n (item[$changes])\n ? (item as any as Schema).clone()\n : item\n )));\n }\n\n return cloned;\n };\n\n}\n\nregisterType(\"array\", { constructor: ArraySchema });"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "bin": {
6
6
  "schema-codegen": "./bin/schema-codegen",
package/src/Schema.ts CHANGED
@@ -19,8 +19,6 @@ export class Schema {
19
19
  static [$encoder] = encodeSchemaOperation;
20
20
  static [$decoder] = decodeSchemaOperation;
21
21
 
22
- // public [$changes]: ChangeTree;
23
-
24
22
  /**
25
23
  * Assign the property descriptors required to track changes on this instance.
26
24
  * @param instance
@@ -177,18 +175,18 @@ export class Schema {
177
175
  /**
178
176
  * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
179
177
  *
180
- * @param instance Schema instance
178
+ * @param ref Schema instance
181
179
  * @param showContents display JSON contents of the instance
182
180
  * @returns
183
181
  */
184
- static debugRefIds(instance: Ref, showContents: boolean = false, level: number = 0) {
185
- const ref = instance;
186
- const changeTree = ref[$changes];
187
-
182
+ static debugRefIds(ref: Ref, showContents: boolean = false, level: number = 0) {
188
183
  const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : "";
189
184
 
185
+ const changeTree: ChangeTree = ref[$changes];
186
+ const refId = changeTree.refId;
187
+
190
188
  let output = "";
191
- output += `${getIndent(level)}${ref.constructor.name} (refId: ${ref[$changes].refId})${contents}\n`;
189
+ output += `${getIndent(level)}${ref.constructor.name} (refId: ${refId})${contents}\n`;
192
190
 
193
191
  changeTree.forEachChild((childChangeTree) =>
194
192
  output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));
@@ -56,7 +56,7 @@ export class ReferenceTracker {
56
56
 
57
57
  if (refCount === undefined) {
58
58
  try {
59
- throw new DecodingWarning("trying to remove refId that doesn't exist");
59
+ throw new DecodingWarning("trying to remove refId that doesn't exist: " + refId);
60
60
  } catch (e) {
61
61
  console.warn(e);
62
62
  }
@@ -38,7 +38,6 @@ export class ArraySchema<V = any> implements Array<V>, Collection<number, V> {
38
38
  * - Then, the encoder iterates over all "owned" properties per instance and encodes them.
39
39
  */
40
40
  static [$filter] (ref: ArraySchema, index: number, view: StateView) {
41
- // console.log("ArraSchema[$filter] VIEW??", !view)
42
41
  return (
43
42
  !view ||
44
43
  typeof (ref[$childType]) === "string" ||
@@ -767,6 +766,7 @@ export class ArraySchema<V = any> implements Array<V>, Collection<number, V> {
767
766
 
768
767
  protected [$deleteByIndex](index: number) {
769
768
  this.items[index] = undefined;
769
+ this.tmpItems[index] = undefined; // TODO: do not try to get "tmpItems" at decoding time.
770
770
  }
771
771
 
772
772
  protected [$onEncodeEnd]() {
@@ -776,6 +776,7 @@ export class ArraySchema<V = any> implements Array<V>, Collection<number, V> {
776
776
 
777
777
  protected [$onDecodeEnd]() {
778
778
  this.items = this.items.filter((item) => item !== undefined);
779
+ this.tmpItems = this.items.slice(); // TODO: do no use "tmpItems" at decoding time.
779
780
  }
780
781
 
781
782
  toArray() {