@colyseus/schema 3.0.76 → 4.0.0

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.
Files changed (160) hide show
  1. package/build/cjs/index.js +781 -434
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/index.mjs +779 -435
  4. package/build/esm/index.mjs.map +1 -1
  5. package/build/umd/index.js +781 -434
  6. package/lib/Metadata.js +1 -5
  7. package/lib/Metadata.js.map +1 -1
  8. package/lib/Reflection.d.ts +50 -17
  9. package/lib/Reflection.js +151 -202
  10. package/lib/Reflection.js.map +1 -1
  11. package/lib/Schema.d.ts +13 -1
  12. package/lib/Schema.js +73 -9
  13. package/lib/Schema.js.map +1 -1
  14. package/lib/annotations.d.ts +6 -1
  15. package/lib/annotations.js +8 -34
  16. package/lib/annotations.js.map +1 -1
  17. package/lib/bench_encode.js +34 -1
  18. package/lib/bench_encode.js.map +1 -1
  19. package/lib/codegen/api.js +35 -2
  20. package/lib/codegen/api.js.map +1 -1
  21. package/lib/codegen/cli.js +4 -1
  22. package/lib/codegen/cli.js.map +1 -1
  23. package/lib/codegen/parser.js +35 -2
  24. package/lib/codegen/parser.js.map +1 -1
  25. package/lib/codegen/types.js +34 -1
  26. package/lib/codegen/types.js.map +1 -1
  27. package/lib/decoder/DecodeOperation.d.ts +2 -2
  28. package/lib/decoder/DecodeOperation.js +3 -3
  29. package/lib/decoder/DecodeOperation.js.map +1 -1
  30. package/lib/decoder/Decoder.d.ts +3 -3
  31. package/lib/decoder/Decoder.js +2 -2
  32. package/lib/decoder/Decoder.js.map +1 -1
  33. package/lib/decoder/ReferenceTracker.d.ts +0 -1
  34. package/lib/decoder/ReferenceTracker.js +9 -7
  35. package/lib/decoder/ReferenceTracker.js.map +1 -1
  36. package/lib/decoder/strategy/Callbacks.d.ts +154 -0
  37. package/lib/decoder/strategy/Callbacks.js +340 -0
  38. package/lib/decoder/strategy/Callbacks.js.map +1 -0
  39. package/lib/decoder/strategy/{StateCallbacks.d.ts → getDecoderStateCallbacks.d.ts} +6 -0
  40. package/lib/decoder/strategy/{StateCallbacks.js → getDecoderStateCallbacks.js} +17 -10
  41. package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +1 -0
  42. package/lib/encoder/ChangeTree.d.ts +2 -2
  43. package/lib/encoder/ChangeTree.js.map +1 -1
  44. package/lib/encoder/EncodeOperation.d.ts +2 -2
  45. package/lib/encoder/EncodeOperation.js +3 -3
  46. package/lib/encoder/EncodeOperation.js.map +1 -1
  47. package/lib/encoder/Encoder.d.ts +6 -6
  48. package/lib/encoder/Encoder.js +19 -18
  49. package/lib/encoder/Encoder.js.map +1 -1
  50. package/lib/encoder/Root.js +17 -14
  51. package/lib/encoder/Root.js.map +1 -1
  52. package/lib/encoder/StateView.js +13 -12
  53. package/lib/encoder/StateView.js.map +1 -1
  54. package/lib/encoding/decode.d.ts +2 -2
  55. package/lib/encoding/encode.d.ts +3 -1
  56. package/lib/encoding/encode.js.map +1 -1
  57. package/lib/index.d.ts +3 -2
  58. package/lib/index.js +7 -3
  59. package/lib/index.js.map +1 -1
  60. package/lib/types/HelperTypes.d.ts +7 -14
  61. package/lib/types/HelperTypes.js.map +1 -1
  62. package/lib/types/custom/ArraySchema.d.ts +2 -1
  63. package/lib/types/custom/ArraySchema.js.map +1 -1
  64. package/lib/types/custom/CollectionSchema.d.ts +2 -1
  65. package/lib/types/custom/CollectionSchema.js.map +1 -1
  66. package/lib/types/custom/MapSchema.d.ts +3 -2
  67. package/lib/types/custom/MapSchema.js.map +1 -1
  68. package/lib/types/custom/SetSchema.d.ts +2 -1
  69. package/lib/types/custom/SetSchema.js.map +1 -1
  70. package/lib/types/symbols.d.ts +1 -0
  71. package/lib/types/symbols.js +2 -1
  72. package/lib/types/symbols.js.map +1 -1
  73. package/lib/utils.js +1 -1
  74. package/lib/utils.js.map +1 -1
  75. package/package.json +12 -16
  76. package/src/Metadata.ts +1 -5
  77. package/src/Reflection.ts +185 -174
  78. package/src/Schema.ts +81 -13
  79. package/src/annotations.ts +14 -40
  80. package/src/codegen/parser.ts +1 -1
  81. package/src/decoder/DecodeOperation.ts +9 -9
  82. package/src/decoder/Decoder.ts +6 -6
  83. package/src/decoder/ReferenceTracker.ts +10 -8
  84. package/src/decoder/strategy/Callbacks.ts +547 -0
  85. package/src/decoder/strategy/{StateCallbacks.ts → getDecoderStateCallbacks.ts} +17 -11
  86. package/src/encoder/ChangeTree.ts +4 -7
  87. package/src/encoder/EncodeOperation.ts +9 -9
  88. package/src/encoder/Encoder.ts +26 -18
  89. package/src/encoder/Root.ts +20 -15
  90. package/src/encoder/StateView.ts +15 -13
  91. package/src/encoding/encode.ts +1 -1
  92. package/src/index.ts +3 -2
  93. package/src/types/HelperTypes.ts +13 -11
  94. package/src/types/custom/ArraySchema.ts +2 -1
  95. package/src/types/custom/CollectionSchema.ts +4 -2
  96. package/src/types/custom/MapSchema.ts +4 -2
  97. package/src/types/custom/SetSchema.ts +3 -1
  98. package/src/types/symbols.ts +1 -0
  99. package/src/utils.ts +2 -2
  100. package/lib/Decoder.d.ts +0 -16
  101. package/lib/Decoder.js +0 -182
  102. package/lib/Decoder.js.map +0 -1
  103. package/lib/Encoder.d.ts +0 -13
  104. package/lib/Encoder.js +0 -79
  105. package/lib/Encoder.js.map +0 -1
  106. package/lib/changes/ChangeSet.d.ts +0 -12
  107. package/lib/changes/ChangeSet.js +0 -35
  108. package/lib/changes/ChangeSet.js.map +0 -1
  109. package/lib/changes/ChangeTree.d.ts +0 -53
  110. package/lib/changes/ChangeTree.js +0 -202
  111. package/lib/changes/ChangeTree.js.map +0 -1
  112. package/lib/changes/DecodeOperation.d.ts +0 -15
  113. package/lib/changes/DecodeOperation.js +0 -186
  114. package/lib/changes/DecodeOperation.js.map +0 -1
  115. package/lib/changes/EncodeOperation.d.ts +0 -18
  116. package/lib/changes/EncodeOperation.js +0 -130
  117. package/lib/changes/EncodeOperation.js.map +0 -1
  118. package/lib/changes/ReferenceTracker.d.ts +0 -14
  119. package/lib/changes/ReferenceTracker.js +0 -83
  120. package/lib/changes/ReferenceTracker.js.map +0 -1
  121. package/lib/changes/consts.d.ts +0 -14
  122. package/lib/changes/consts.js +0 -18
  123. package/lib/changes/consts.js.map +0 -1
  124. package/lib/decoder/strategy/StateCallbacks.js.map +0 -1
  125. package/lib/decoding/decode.d.ts +0 -48
  126. package/lib/decoding/decode.js +0 -267
  127. package/lib/decoding/decode.js.map +0 -1
  128. package/lib/ecs.d.ts +0 -11
  129. package/lib/ecs.js +0 -160
  130. package/lib/ecs.js.map +0 -1
  131. package/lib/filters/index.d.ts +0 -8
  132. package/lib/filters/index.js +0 -24
  133. package/lib/filters/index.js.map +0 -1
  134. package/lib/spec.d.ts +0 -13
  135. package/lib/spec.js +0 -42
  136. package/lib/spec.js.map +0 -1
  137. package/lib/types/ArraySchema.d.ts +0 -238
  138. package/lib/types/ArraySchema.js +0 -555
  139. package/lib/types/ArraySchema.js.map +0 -1
  140. package/lib/types/CollectionSchema.d.ts +0 -35
  141. package/lib/types/CollectionSchema.js +0 -150
  142. package/lib/types/CollectionSchema.js.map +0 -1
  143. package/lib/types/MapSchema.d.ts +0 -38
  144. package/lib/types/MapSchema.js +0 -215
  145. package/lib/types/MapSchema.js.map +0 -1
  146. package/lib/types/SetSchema.d.ts +0 -32
  147. package/lib/types/SetSchema.js +0 -162
  148. package/lib/types/SetSchema.js.map +0 -1
  149. package/lib/types/typeRegistry.d.ts +0 -5
  150. package/lib/types/typeRegistry.js +0 -13
  151. package/lib/types/typeRegistry.js.map +0 -1
  152. package/lib/usage.d.ts +0 -1
  153. package/lib/usage.js +0 -22
  154. package/lib/usage.js.map +0 -1
  155. package/lib/v3.d.ts +0 -1
  156. package/lib/v3.js +0 -427
  157. package/lib/v3.js.map +0 -1
  158. package/lib/v3_experiment.d.ts +0 -1
  159. package/lib/v3_experiment.js +0 -407
  160. package/lib/v3_experiment.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ArraySchema.js","sourceRo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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 { type IRef, 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>, IRef {\n [n: number]: V;\n [$changes]: ChangeTree;\n\n protected [$childType]: string | typeof Schema;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n protected isMovingItems = false;\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.isChangeTreeVisible(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 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 as unknown as number];\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 const previousValue = obj.items[key as unknown as number];\n\n if (!obj.isMovingItems) {\n obj.$changeAt(Number(key), setValue);\n\n } else {\n if (previousValue !== undefined) {\n if (setValue[$changes].isNew) {\n obj[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n obj[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n\n } else {\n obj[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n\n } else if (setValue[$changes].isNew) {\n obj[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n\n setValue[$changes].setParent(this, obj[$changes].root, key);\n }\n\n if (previousValue !== undefined) {\n // remove root reference from previous value\n previousValue[$changes].root?.remove(previousValue[$changes]);\n }\n\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n obj.items[key as unknown as number] = setValue;\n obj.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 as unknown as number];\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 Object.defineProperty(this, $changes, {\n value: new ChangeTree(proxy),\n enumerable: false,\n writable: true,\n });\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 for (let i = 0, l = values.length; i < l; 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 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.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 operation = (this.items[index] !== undefined)\n ? typeof(value) === \"object\"\n ? OPERATION.DELETE_AND_ADD // schema child\n : OPERATION.REPLACE // primitive\n : OPERATION.ADD;\n\n const changeTree = this[$changes];\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 // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\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 changeTree = this[$changes];\n\n const index = this.tmpItems.findIndex(item => item === this.items[0]);\n const allChangesIndex = this.items.findIndex(item => item === this.items[0]);\n\n changeTree.delete(index, OPERATION.DELETE, allChangesIndex);\n changeTree.shiftAllChangeIndexes(-1, allChangesIndex);\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 this.isMovingItems = true;\n\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\n this.isMovingItems = false;\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,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const itemsLength = this.items.length;\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.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n if (itemsLength > start) {\n // if deleteCount is not provided, delete all items from start to end\n if (deleteCount === undefined) {\n deleteCount = itemsLength - start;\n }\n\n //\n // delete operations at correct index\n //\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index, OPERATION.DELETE);\n this.deletedIndexes[index] = true;\n }\n\n } else {\n // not enough items to delete\n deleteCount = 0;\n }\n\n // insert operations\n if (insertCount > 0) {\n if (insertCount > deleteCount) {\n console.error(\"Inserting more elements than deleting during ArraySchema#splice()\");\n throw new Error(\"ArraySchema#splice(): insertCount must be equal or lower than deleteCount.\");\n }\n\n for (let i = 0; i < insertCount; i++) {\n const addIndex = (indexes[start] ?? itemsLength) + i;\n\n changeTree.indexedOperation(\n addIndex,\n (this.deletedIndexes[addIndex])\n ? OPERATION.DELETE_AND_ADD\n : OPERATION.ADD\n );\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\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 // debugChangeSet(\"AFTER SHIFT indexes\", changeTree.allChanges);\n }\n\n //\n // FIXME: this code block is duplicated on ChangeTree\n //\n if (changeTree.filteredChanges !== undefined) {\n changeTree.root?.enqueueChangeTree(changeTree, 'filteredChanges');\n\n } else {\n changeTree.root?.enqueueChangeTree(changeTree, 'changes');\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](): ArrayIterator<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(): ArrayIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): ArrayIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): ArrayIterator<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: any[]) {\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 shuffle() {\n return this.move((_) => {\n let currentIndex = this.items.length;\n while (currentIndex != 0) {\n let randomIndex = Math.floor(Math.random() * currentIndex);\n currentIndex--;\n [this[currentIndex], this[randomIndex]] = [this[randomIndex], this[currentIndex]];\n }\n });\n }\n\n /**\n * Allows to move items around in the array.\n *\n * Example:\n * state.cards.move((cards) => {\n * [cards[4], cards[3]] = [cards[3], cards[4]];\n * [cards[3], cards[2]] = [cards[2], cards[3]];\n * [cards[2], cards[0]] = [cards[0], cards[2]];\n * [cards[1], cards[1]] = [cards[1], cards[1]];\n * [cards[0], cards[0]] = [cards[0], cards[0]];\n * })\n *\n * @param cb\n * @returns\n */\n move(cb: (arr: this) => void) {\n this.isMovingItems = true;\n cb(this);\n this.isMovingItems = false;\n return this;\n }\n\n [$getByIndex](index: number, isEncodeAll: boolean = false): any {\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\n [$deleteByIndex](index: number): void {\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: any) => {\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 });\n"]}
1
+ {"version":3,"file":"ArraySchema.js","sourceRoot":"","sources":["../../../src/types/custom/ArraySchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAgJ;AAEhJ,yDAAsF;AACtF,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;AAED,MAAa,WAAW;aAYb,QAAU,GAAG,6BAAW,AAAd,CAAe;aACzB,QAAU,GAAG,6BAAW,AAAd,CAAe;IAEhC;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAgB,E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BAAqB;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;;AAn2BN,kCAq2BC;AAED,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $refId } from \"../symbols\";\nimport type { Schema } from \"../../Schema\";\nimport { type IRef, 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>, IRef {\n [n: number]: V;\n [$changes]: ChangeTree;\n [$refId]?: number;\n\n protected [$childType]: string | typeof Schema;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n protected isMovingItems = false;\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.isChangeTreeVisible(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 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 as unknown as number];\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 const previousValue = obj.items[key as unknown as number];\n\n if (!obj.isMovingItems) {\n obj.$changeAt(Number(key), setValue);\n\n } else {\n if (previousValue !== undefined) {\n if (setValue[$changes].isNew) {\n obj[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n obj[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n\n } else {\n obj[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n\n } else if (setValue[$changes].isNew) {\n obj[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n\n setValue[$changes].setParent(this, obj[$changes].root, key);\n }\n\n if (previousValue !== undefined) {\n // remove root reference from previous value\n previousValue[$changes].root?.remove(previousValue[$changes]);\n }\n\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n obj.items[key as unknown as number] = setValue;\n obj.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 as unknown as number];\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 Object.defineProperty(this, $changes, {\n value: new ChangeTree(proxy),\n enumerable: false,\n writable: true,\n });\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 for (let i = 0, l = values.length; i < l; 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 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.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 operation = (this.items[index] !== undefined)\n ? typeof(value) === \"object\"\n ? OPERATION.DELETE_AND_ADD // schema child\n : OPERATION.REPLACE // primitive\n : OPERATION.ADD;\n\n const changeTree = this[$changes];\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 // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\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 changeTree = this[$changes];\n\n const index = this.tmpItems.findIndex(item => item === this.items[0]);\n const allChangesIndex = this.items.findIndex(item => item === this.items[0]);\n\n changeTree.delete(index, OPERATION.DELETE, allChangesIndex);\n changeTree.shiftAllChangeIndexes(-1, allChangesIndex);\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 this.isMovingItems = true;\n\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\n this.isMovingItems = false;\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,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const itemsLength = this.items.length;\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.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n if (itemsLength > start) {\n // if deleteCount is not provided, delete all items from start to end\n if (deleteCount === undefined) {\n deleteCount = itemsLength - start;\n }\n\n //\n // delete operations at correct index\n //\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index, OPERATION.DELETE);\n this.deletedIndexes[index] = true;\n }\n\n } else {\n // not enough items to delete\n deleteCount = 0;\n }\n\n // insert operations\n if (insertCount > 0) {\n if (insertCount > deleteCount) {\n console.error(\"Inserting more elements than deleting during ArraySchema#splice()\");\n throw new Error(\"ArraySchema#splice(): insertCount must be equal or lower than deleteCount.\");\n }\n\n for (let i = 0; i < insertCount; i++) {\n const addIndex = (indexes[start] ?? itemsLength) + i;\n\n changeTree.indexedOperation(\n addIndex,\n (this.deletedIndexes[addIndex])\n ? OPERATION.DELETE_AND_ADD\n : OPERATION.ADD\n );\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\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 // debugChangeSet(\"AFTER SHIFT indexes\", changeTree.allChanges);\n }\n\n //\n // FIXME: this code block is duplicated on ChangeTree\n //\n if (changeTree.filteredChanges !== undefined) {\n changeTree.root?.enqueueChangeTree(changeTree, 'filteredChanges');\n\n } else {\n changeTree.root?.enqueueChangeTree(changeTree, 'changes');\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](): ArrayIterator<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(): ArrayIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): ArrayIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): ArrayIterator<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: any[]) {\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 shuffle() {\n return this.move((_) => {\n let currentIndex = this.items.length;\n while (currentIndex != 0) {\n let randomIndex = Math.floor(Math.random() * currentIndex);\n currentIndex--;\n [this[currentIndex], this[randomIndex]] = [this[randomIndex], this[currentIndex]];\n }\n });\n }\n\n /**\n * Allows to move items around in the array.\n *\n * Example:\n * state.cards.move((cards) => {\n * [cards[4], cards[3]] = [cards[3], cards[4]];\n * [cards[3], cards[2]] = [cards[2], cards[3]];\n * [cards[2], cards[0]] = [cards[0], cards[2]];\n * [cards[1], cards[1]] = [cards[1], cards[1]];\n * [cards[0], cards[0]] = [cards[0], cards[0]];\n * })\n *\n * @param cb\n * @returns\n */\n move(cb: (arr: this) => void) {\n this.isMovingItems = true;\n cb(this);\n this.isMovingItems = false;\n return this;\n }\n\n [$getByIndex](index: number, isEncodeAll: boolean = false): any {\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\n [$deleteByIndex](index: number): void {\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: any) => {\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 });\n"]}
@@ -1,4 +1,4 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd } from "../symbols";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
2
2
  import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
3
3
  import { Collection } from "../HelperTypes";
4
4
  import type { StateView } from "../../encoder/StateView";
@@ -6,6 +6,7 @@ import type { Schema } from "../../Schema";
6
6
  type K = number;
7
7
  export declare class CollectionSchema<V = any> implements Collection<K, V>, IRef {
8
8
  [$changes]: ChangeTree;
9
+ [$refId]?: number;
9
10
  protected [$childType]: string | typeof Schema;
10
11
  protected $items: Map<number, V>;
11
12
  protected $indexes: Map<number, number>;
@@ -1 +1 @@
1
- {"version":3,"file":"CollectionSchema.js","sourceRoot":"","sources":["../../../src/types/custom/CollectionSchema.ts"],"names":[],"mappings":";;;;AAAA,wCAA0H;AAC1H,yDAAiE;AACjE,8CAAgD;AAChD,0CAA2C;AAE3C,mEAAwE;AACxE,mEAAwE;AAMxE,MAAa,gBAAgB;aAUlB,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;aACrC,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAqB,EAAE,KAAa,EAAE,IAAe;QACnE,OAAO,CACH,CAAC,IAAI;YACL,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ;YACrC,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,qBAAW,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAQ,CAAC,CAAC,CAC3F,CAAC;IACN,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAS;QACf,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,SAAS,CAAC;IAC5C,CAAC;IAED,YAAa,aAAwB;QA9B3B,WAAM,GAAmB,IAAI,GAAG,EAAa,CAAC;QAC9C,aAAQ,GAAwB,IAAI,GAAG,EAAk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AAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;gBACxB,IAAI,KAAK,CAAC,kBAAQ,CAAC,EAAE,CAAC;oBAClB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACJ,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACtB,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;;AA/ML,4CAiNC;AAED,IAAA,uBAAY,EAAC,YAAY,EAAE,EAAE,WAAW,EAAE,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd } from \"../symbols\";\nimport { ChangeTree, type IRef } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\n\ntype K = number; // TODO: allow to specify K generic on MapSchema.\n\nexport class CollectionSchema<V=any> implements Collection<K, V>, IRef {\n public [$changes]: ChangeTree;\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<number, V> = new Map<number, V>();\n protected $indexes: Map<number, number> = new Map<number, number>();\n protected deletedItems: { [field: string]: V } = {};\n\n protected $refId: number = 0;\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: CollectionSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.isChangeTreeVisible((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['collection'] !== undefined;\n }\n\n constructor (initialValues?: Array<V>) {\n this[$changes] = new ChangeTree(this);\n this[$changes].indexes = {};\n\n if (initialValues) {\n initialValues.forEach((v) => this.add(v));\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n add(value: V) {\n // set \"index\" for reference.\n const index = this.$refId++;\n\n const isRef = (value[$changes]) !== undefined;\n if (isRef) {\n value[$changes].setParent(this, this[$changes].root, index);\n }\n\n this[$changes].indexes[index] = index;\n\n this.$indexes.set(index, index);\n this.$items.set(index, value);\n\n this[$changes].change(index);\n\n return index;\n }\n\n at(index: number): V | undefined {\n const key = Array.from(this.$items.keys())[index];\n return this.$items.get(key);\n }\n\n entries() {\n return this.$items.entries();\n }\n\n delete(item: V) {\n const entries = this.$items.entries();\n\n let index: K;\n let entry: IteratorResult<[number, V]>;\n while (entry = entries.next()) {\n if (entry.done) { break; }\n\n if (item === entry.value[1]) {\n index = entry.value[0];\n break;\n }\n }\n\n if (index === undefined) {\n return false;\n }\n\n this.deletedItems[index] = this[$changes].delete(index);\n this.$indexes.delete(index);\n\n return this.$items.delete(index);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\n });\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (value: V): boolean {\n return Array.from(this.$items.values()).some((v) => v === value);\n }\n\n forEach(callbackfn: (value: V, key: K, collection: CollectionSchema<V>) => void) {\n this.$items.forEach((value, key, _) => callbackfn(value, key, this));\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.$items.values();\n }\n\n protected setIndex(index: number, key: number) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): any {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n this.deletedItems = {};\n }\n\n toArray() {\n return Array.from(this.$items.values());\n }\n\n toJSON() {\n const values: V[] = [];\n\n this.forEach((value: any, key: K) => {\n values.push(\n (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value\n );\n });\n\n return values;\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): CollectionSchema<V> {\n let cloned: CollectionSchema;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new CollectionSchema(), this);\n\n } else {\n // server-side\n cloned = new CollectionSchema();\n this.forEach((value: any) => {\n if (value[$changes]) {\n cloned.add(value['clone']());\n } else {\n cloned.add(value);\n }\n })\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"collection\", { constructor: CollectionSchema, });\n"]}
1
+ {"version":3,"file":"CollectionSchema.js","sourceRoot":"","sources":["../../../src/types/custom/CollectionSchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAkI;AAClI,yDAAiE;AACjE,8CAAgD;AAChD,0CAA2C;AAE3C,mEAAwE;AACxE,mEAAwE;AAMxE,MAAa,gBAAgB;aAYlB,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;aACrC,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAqB,EAAE,KAAa,EAAE,IA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KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,UAAU,CAAC;gBACrC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBACnB,CAAC,CAAC,KAAK,CACd,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,EAAE;IACF,qBAAqB;IACrB,EAAE;IACF,KAAK,CAAC,UAAoB;QACtB,IAAI,MAAwB,CAAC;QAE7B,IAAI,UAAU,EAAE,CAAC;YACb,cAAc;YACd,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAAC;QAEzD,CAAC;aAAM,CAAC;YACJ,cAAc;YACd,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;gBACxB,IAAI,KAAK,CAAC,kBAAQ,CAAC,EAAE,CAAC;oBAClB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACJ,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACtB,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;;AAjNL,4CAmNC;AAED,IAAA,uBAAY,EAAC,YAAY,EAAE,EAAE,WAAW,EAAE,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from \"../symbols\";\nimport { ChangeTree, type IRef } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\n\ntype K = number; // TODO: allow to specify K generic on MapSchema.\n\nexport class CollectionSchema<V=any> implements Collection<K, V>, IRef {\n [$changes]: ChangeTree;\n [$refId]?: number;\n\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<number, V> = new Map<number, V>();\n protected $indexes: Map<number, number> = new Map<number, number>();\n protected deletedItems: { [field: string]: V } = {};\n\n protected $refId: number = 0;\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: CollectionSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.isChangeTreeVisible((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['collection'] !== undefined;\n }\n\n constructor (initialValues?: Array<V>) {\n this[$changes] = new ChangeTree(this);\n this[$changes].indexes = {};\n\n if (initialValues) {\n initialValues.forEach((v) => this.add(v));\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n add(value: V) {\n // set \"index\" for reference.\n const index = this.$refId++;\n\n const isRef = (value[$changes]) !== undefined;\n if (isRef) {\n value[$changes].setParent(this, this[$changes].root, index);\n }\n\n this[$changes].indexes[index] = index;\n\n this.$indexes.set(index, index);\n this.$items.set(index, value);\n\n this[$changes].change(index);\n\n return index;\n }\n\n at(index: number): V | undefined {\n const key = Array.from(this.$items.keys())[index];\n return this.$items.get(key);\n }\n\n entries() {\n return this.$items.entries();\n }\n\n delete(item: V) {\n const entries = this.$items.entries();\n\n let index: K;\n let entry: IteratorResult<[number, V]>;\n while (entry = entries.next()) {\n if (entry.done) { break; }\n\n if (item === entry.value[1]) {\n index = entry.value[0];\n break;\n }\n }\n\n if (index === undefined) {\n return false;\n }\n\n this.deletedItems[index] = this[$changes].delete(index);\n this.$indexes.delete(index);\n\n return this.$items.delete(index);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\n });\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (value: V): boolean {\n return Array.from(this.$items.values()).some((v) => v === value);\n }\n\n forEach(callbackfn: (value: V, key: K, collection: CollectionSchema<V>) => void) {\n this.$items.forEach((value, key, _) => callbackfn(value, key, this));\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.$items.values();\n }\n\n protected setIndex(index: number, key: number) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): any {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n this.deletedItems = {};\n }\n\n toArray() {\n return Array.from(this.$items.values());\n }\n\n toJSON() {\n const values: V[] = [];\n\n this.forEach((value: any, key: K) => {\n values.push(\n (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value\n );\n });\n\n return values;\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): CollectionSchema<V> {\n let cloned: CollectionSchema;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new CollectionSchema(), this);\n\n } else {\n // server-side\n cloned = new CollectionSchema();\n this.forEach((value: any) => {\n if (value[$changes]) {\n cloned.add(value['clone']());\n } else {\n cloned.add(value);\n }\n })\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"collection\", { constructor: CollectionSchema, });\n"]}
@@ -1,11 +1,12 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex } from "../symbols";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $refId } from "../symbols";
2
2
  import { ChangeTree, IRef } from "../../encoder/ChangeTree";
3
3
  import { Collection } from "../HelperTypes";
4
4
  import type { StateView } from "../../encoder/StateView";
5
5
  import type { Schema } from "../../Schema";
6
6
  export declare class MapSchema<V = any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {
7
- protected childType: new () => V;
8
7
  [$changes]: ChangeTree;
8
+ [$refId]?: number;
9
+ protected childType: new () => V;
9
10
  protected [$childType]: string | typeof Schema;
10
11
  protected $items: Map<K, V>;
11
12
  protected $indexes: Map<number, K>;
@@ -1 +1 @@
1
- {"version":3,"file":"MapSchema.js","sourceRoot":"","sources":["../../../src/types/custom/MapSchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAsI;AACtI,yDAA4D;AAC5D,8CAAgD;AAChD,0CAA2C;AAE3C,mEAAwE;AACxE,mEAAwE;AAGxE,kDAA2D;AAE3D,MAAa,SAAS;aASX,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;aACrC,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAc,EAAE,KAAa,EAAE,IAAe;QAC5D,OAAO,CACH,CAAC,IAAI;YACL,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ;YACrC,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,qBAAW,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,YAAY,CA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AAC,CAAA;QAEN,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;;AA/QL,8BAiRC;AAED,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $numFields } from \"../symbols\";\nimport { ChangeTree, IRef } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\nimport { assertInstanceType } from \"../../encoding/assert\";\n\nexport class MapSchema<V=any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {\n protected childType: new () => V;\n [$changes]: ChangeTree;\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<K, V> = new Map<K, V>();\n protected $indexes: Map<number, K> = new Map<number, K>();\n protected deletedItems: { [index: string]: V } = {};\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: MapSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.isChangeTreeVisible((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['map'] !== undefined;\n }\n\n constructor (initialValues?: Map<K, V> | Record<K, V>) {\n const changeTree = new ChangeTree(this);\n changeTree.indexes = {};\n\n Object.defineProperty(this, $changes, {\n value: changeTree,\n enumerable: false,\n writable: true,\n });\n\n if (initialValues) {\n if (\n initialValues instanceof Map ||\n initialValues instanceof MapSchema\n ) {\n initialValues.forEach((v, k) => this.set(k, v));\n\n } else {\n for (const k in initialValues) {\n this.set(k, initialValues[k]);\n }\n }\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<[K, V]> { return this.$items[Symbol.iterator](); }\n get [Symbol.toStringTag]() { return this.$items[Symbol.toStringTag] }\n\n static get [Symbol.species]() { return MapSchema; }\n\n set(key: K, value: V) {\n if (value === undefined || value === null) {\n throw new Error(`MapSchema#set('${key}', ${value}): trying to set ${value} value on '${key}'.`);\n\n } else if (typeof(value) === \"object\" && this[$childType]) {\n assertInstanceType(value as any, this[$childType] as typeof Schema, this, key);\n }\n\n // Force \"key\" as string\n // See: https://github.com/colyseus/colyseus/issues/561#issuecomment-1646733468\n key = key.toString() as K;\n\n const changeTree = this[$changes];\n const isRef = (value[$changes]) !== undefined;\n\n let index: number;\n let operation: OPERATION;\n\n // IS REPLACE?\n if (typeof(changeTree.indexes[key]) !== \"undefined\") {\n index = changeTree.indexes[key];\n operation = OPERATION.REPLACE;\n\n const previousValue = this.$items.get(key);\n if (previousValue === value) {\n // if value is the same, avoid re-encoding it.\n return;\n\n } else if (isRef) {\n // if is schema, force ADD operation if value differ from previous one.\n operation = OPERATION.DELETE_AND_ADD;\n\n // remove reference from previous value\n if (previousValue !== undefined) {\n previousValue[$changes].root?.remove(previousValue[$changes]);\n }\n }\n\n if (this.deletedItems[index]) {\n delete this.deletedItems[index];\n }\n\n } else {\n index = changeTree.indexes[$numFields] ?? 0;\n operation = OPERATION.ADD;\n\n this.$indexes.set(index, key);\n changeTree.indexes[key] = index;\n changeTree.indexes[$numFields] = index + 1;\n }\n\n this.$items.set(key, value);\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 if (isRef) {\n value[$changes].setParent(this, changeTree.root, index);\n }\n\n return this;\n }\n\n get(key: K): V | undefined {\n return this.$items.get(key);\n }\n\n delete(key: K) {\n if (!this.$items.has(key)) {\n return false;\n }\n\n const index = this[$changes].indexes[key];\n\n this.deletedItems[index] = this[$changes].delete(index);\n\n return this.$items.delete(key);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\n });\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (key: K) {\n return this.$items.has(key);\n }\n\n forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void) {\n this.$items.forEach(callbackfn);\n }\n\n entries () {\n return this.$items.entries();\n }\n\n keys () {\n return this.$items.keys();\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n protected setIndex(index: number, key: K) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): V | undefined {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n const changeTree = this[$changes];\n\n // - cleanup changeTree.indexes\n // - cleanup $indexes\n for (const indexStr in this.deletedItems) {\n const index = parseInt(indexStr);\n const key = this.$indexes.get(index);\n // TODO: refactor this.\n // it shouldn't be necessary to keep track of indexes both on changeTree and on $indexes\n delete changeTree.indexes[key];\n this.$indexes.delete(index);\n }\n\n this.deletedItems = {};\n }\n\n toJSON() {\n const map: any = {};\n\n this.forEach((value: any, key) => {\n map[key] = (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n\n return map;\n }\n\n //\n // Decoding utilities\n //\n // @ts-ignore\n clone(isDecoding?: boolean): MapSchema<V> {\n let cloned: MapSchema<V>;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new MapSchema(), this);\n\n } else {\n // server-side\n cloned = new MapSchema();\n\n this.forEach((value: any, key) => {\n if (value[$changes]) {\n cloned.set(key, value['clone']());\n } else {\n cloned.set(key, value);\n }\n })\n\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"map\", { constructor: MapSchema });\n"]}
1
+ {"version":3,"file":"MapSchema.js","sourceRoot":"","sources":["../../../src/types/custom/MapSchema.ts"],"names":[],"mappings":";;;;AAAA,wCAA8I;AAC9I,yDAA4D;AAC5D,8CAAgD;AAChD,0CAA2C;AAE3C,mEAAwE;AACxE,mEAAwE;AAGxE,kDAA2D;AAE3D,MAAa,SAAS;aAWX,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;aACrC,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAc,EAAE,KAAa,EAAE,IAAe;QAC5D,OAAO,CACH,CAAC,IAAI;YACL,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ;YACrC,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,qBAAW,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAQ,CAAC,CAAC,CAC3F,CAAC;IACN,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAS;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;IACrC,CAAC;IAED,YAAa,aAAwC;QA5B3C,WAAM,GAAc,IAAI,GAAG,EAAQ,CAAC;QACpC,aAAQ,GAAmB,IAAI,GAAG,EAAa,CAAC;QAChD,iBAA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AE,CAAC;QAEpB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,UAAU,CAAC;gBAChD,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBACnB,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACf,CAAC;IAED,EAAE;IACF,qBAAqB;IACrB,EAAE;IACF,aAAa;IACb,KAAK,CAAC,UAAoB;QACtB,IAAI,MAAoB,CAAC;QAEzB,IAAI,UAAU,EAAE,CAAC;YACb,cAAc;YACd,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;QAElD,CAAC;aAAM,CAAC;YACJ,cAAc;YACd,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAEzB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;gBAC7B,IAAI,KAAK,CAAC,kBAAQ,CAAC,EAAE,CAAC;oBAClB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBACJ,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC3B,CAAC;YACL,CAAC,CAAC,CAAA;QAEN,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;;AAjRL,8BAmRC;AAED,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $numFields, $refId } from \"../symbols\";\nimport { ChangeTree, IRef } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\nimport { assertInstanceType } from \"../../encoding/assert\";\n\nexport class MapSchema<V=any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {\n [$changes]: ChangeTree;\n [$refId]?: number;\n\n protected childType: new () => V;\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<K, V> = new Map<K, V>();\n protected $indexes: Map<number, K> = new Map<number, K>();\n protected deletedItems: { [index: string]: V } = {};\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: MapSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.isChangeTreeVisible((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['map'] !== undefined;\n }\n\n constructor (initialValues?: Map<K, V> | Record<K, V>) {\n const changeTree = new ChangeTree(this);\n changeTree.indexes = {};\n\n Object.defineProperty(this, $changes, {\n value: changeTree,\n enumerable: false,\n writable: true,\n });\n\n if (initialValues) {\n if (\n initialValues instanceof Map ||\n initialValues instanceof MapSchema\n ) {\n initialValues.forEach((v, k) => this.set(k, v));\n\n } else {\n for (const k in initialValues) {\n this.set(k, initialValues[k]);\n }\n }\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<[K, V]> { return this.$items[Symbol.iterator](); }\n get [Symbol.toStringTag]() { return this.$items[Symbol.toStringTag] }\n\n static get [Symbol.species]() { return MapSchema; }\n\n set(key: K, value: V) {\n if (value === undefined || value === null) {\n throw new Error(`MapSchema#set('${key}', ${value}): trying to set ${value} value on '${key}'.`);\n\n } else if (typeof(value) === \"object\" && this[$childType]) {\n assertInstanceType(value as any, this[$childType] as typeof Schema, this, key);\n }\n\n // Force \"key\" as string\n // See: https://github.com/colyseus/colyseus/issues/561#issuecomment-1646733468\n key = key.toString() as K;\n\n const changeTree = this[$changes];\n const isRef = (value[$changes]) !== undefined;\n\n let index: number;\n let operation: OPERATION;\n\n // IS REPLACE?\n if (typeof(changeTree.indexes[key]) !== \"undefined\") {\n index = changeTree.indexes[key];\n operation = OPERATION.REPLACE;\n\n const previousValue = this.$items.get(key);\n if (previousValue === value) {\n // if value is the same, avoid re-encoding it.\n return;\n\n } else if (isRef) {\n // if is schema, force ADD operation if value differ from previous one.\n operation = OPERATION.DELETE_AND_ADD;\n\n // remove reference from previous value\n if (previousValue !== undefined) {\n previousValue[$changes].root?.remove(previousValue[$changes]);\n }\n }\n\n if (this.deletedItems[index]) {\n delete this.deletedItems[index];\n }\n\n } else {\n index = changeTree.indexes[$numFields] ?? 0;\n operation = OPERATION.ADD;\n\n this.$indexes.set(index, key);\n changeTree.indexes[key] = index;\n changeTree.indexes[$numFields] = index + 1;\n }\n\n this.$items.set(key, value);\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 if (isRef) {\n value[$changes].setParent(this, changeTree.root, index);\n }\n\n return this;\n }\n\n get(key: K): V | undefined {\n return this.$items.get(key);\n }\n\n delete(key: K) {\n if (!this.$items.has(key)) {\n return false;\n }\n\n const index = this[$changes].indexes[key];\n\n this.deletedItems[index] = this[$changes].delete(index);\n\n return this.$items.delete(key);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // remove children references\n changeTree.forEachChild((childChangeTree, _) => {\n changeTree.root?.remove(childChangeTree);\n });\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (key: K) {\n return this.$items.has(key);\n }\n\n forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void) {\n this.$items.forEach(callbackfn);\n }\n\n entries () {\n return this.$items.entries();\n }\n\n keys () {\n return this.$items.keys();\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n protected setIndex(index: number, key: K) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): V | undefined {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n const changeTree = this[$changes];\n\n // - cleanup changeTree.indexes\n // - cleanup $indexes\n for (const indexStr in this.deletedItems) {\n const index = parseInt(indexStr);\n const key = this.$indexes.get(index);\n // TODO: refactor this.\n // it shouldn't be necessary to keep track of indexes both on changeTree and on $indexes\n delete changeTree.indexes[key];\n this.$indexes.delete(index);\n }\n\n this.deletedItems = {};\n }\n\n toJSON() {\n const map: any = {};\n\n this.forEach((value: any, key) => {\n map[key] = (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n\n return map;\n }\n\n //\n // Decoding utilities\n //\n // @ts-ignore\n clone(isDecoding?: boolean): MapSchema<V> {\n let cloned: MapSchema<V>;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new MapSchema(), this);\n\n } else {\n // server-side\n cloned = new MapSchema();\n\n this.forEach((value: any, key) => {\n if (value[$changes]) {\n cloned.set(key, value['clone']());\n } else {\n cloned.set(key, value);\n }\n })\n\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"map\", { constructor: MapSchema });\n"]}
@@ -1,10 +1,11 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd } from "../symbols";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
2
2
  import { Collection } from "../HelperTypes";
3
3
  import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
4
4
  import type { StateView } from "../../encoder/StateView";
5
5
  import type { Schema } from "../../Schema";
6
6
  export declare class SetSchema<V = any> implements Collection<number, V>, IRef {
7
7
  [$changes]: ChangeTree;
8
+ [$refId]?: number;
8
9
  protected [$childType]: string | typeof Schema;
9
10
  protected $items: Map<number, V>;
10
11
  protected $indexes: Map<number, number>;
@@ -1 +1 @@
1
- {"version":3,"file":"SetSchema.js","sourceRoot":"","sources":["../../../src/types/custom/SetSchema.ts"],"names":[],"mappings":";;;;AAAA,8CAAgD;AAChD,0CAA2C;AAC3C,wCAA0H;AAE1H,yDAAiE;AACjE,mEAAwE;AACxE,mEAAwE;AAIxE,MAAa,SAAS;aAUX,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;aACrC,QAAU,GAAG,yCAAuB,AAA1B,CAA2B;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAc,EAAE,KAAa,EAAE,IAAe;QAC5D,OAAO,CACH,CAAC,IAAI;YACL,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ;YACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,qBAAW,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAQ,CAAC,CAAC,CACnF,CAAC;IACN,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IA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AAK,CAAC,UAAoB;QACtB,IAAI,MAAiB,CAAC;QAEtB,IAAI,UAAU,EAAE,CAAC;YACb,cAAc;YACd,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;QAElD,CAAC;aAAM,CAAC;YACJ,cAAc;YACd,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;gBACxB,IAAI,KAAK,CAAC,kBAAQ,CAAC,EAAE,CAAC;oBAClB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACJ,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACtB,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;;AArNL,8BAuNC;AAED,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC","sourcesContent":["import { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd } from \"../symbols\";\nimport { Collection } from \"../HelperTypes\";\nimport { ChangeTree, type IRef } from \"../../encoder/ChangeTree\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\n\nexport class SetSchema<V=any> implements Collection<number, V>, IRef {\n [$changes]: ChangeTree;\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<number, V> = new Map<number, V>();\n protected $indexes: Map<number, number> = new Map<number, number>();\n protected deletedItems: { [field: string]: V } = {};\n\n protected $refId: number = 0;\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: SetSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.visible.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['set'] !== undefined;\n }\n\n constructor (initialValues?: Array<V>) {\n this[$changes] = new ChangeTree(this);\n this[$changes].indexes = {};\n\n if (initialValues) {\n initialValues.forEach((v) => this.add(v));\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n add(value: V) {\n // immediatelly return false if value already added.\n if (this.has(value)) { return false; }\n\n // set \"index\" for reference.\n const index = this.$refId++;\n\n if ((value[$changes]) !== undefined) {\n value[$changes].setParent(this, this[$changes].root, index);\n }\n\n const operation = this[$changes].indexes[index]?.op ?? OPERATION.ADD;\n\n this[$changes].indexes[index] = index;\n\n this.$indexes.set(index, index);\n this.$items.set(index, value);\n\n this[$changes].change(index, operation);\n return index;\n }\n\n entries () {\n return this.$items.entries();\n }\n\n delete(item: V) {\n const entries = this.$items.entries();\n\n let index: number;\n let entry: IteratorResult<[number, V]>;\n while (entry = entries.next()) {\n if (entry.done) { break; }\n\n if (item === entry.value[1]) {\n index = entry.value[0];\n break;\n }\n }\n\n if (index === undefined) {\n return false;\n }\n\n this.deletedItems[index] = this[$changes].delete(index);\n this.$indexes.delete(index);\n\n return this.$items.delete(index);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (value: V): boolean {\n const values = this.$items.values();\n\n let has = false;\n let entry: IteratorResult<V>;\n\n while (entry = values.next()) {\n if (entry.done) { break; }\n if (value === entry.value) {\n has = true;\n break;\n }\n }\n\n return has;\n }\n\n forEach(callbackfn: (value: V, key: number, collection: SetSchema<V>) => void) {\n this.$items.forEach((value, key, _) => callbackfn(value, key, this));\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.$items.values();\n }\n\n protected setIndex(index: number, key: number) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): any {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n this.deletedItems = {};\n }\n\n toArray() {\n return Array.from(this.$items.values());\n }\n\n toJSON() {\n const values: V[] = [];\n\n this.forEach((value: any, key: number) => {\n values.push(\n (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value\n );\n });\n\n return values;\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): SetSchema<V> {\n let cloned: SetSchema;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new SetSchema(), this);\n\n } else {\n // server-side\n cloned = new SetSchema();\n this.forEach((value: any) => {\n if (value[$changes]) {\n cloned.add(value['clone']());\n } else {\n cloned.add(value);\n }\n })\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"set\", { constructor: SetSchema });"]}
1
+ {"version":3,"file":"SetSchema.js","sourceRoot":"","sources":["../../../src/types/custom/SetSchema.ts"],"names":[],"mappings":";;;;AAAA,8CAAgD;AAChD,0CAA2C;AAC3C,wCAAkI;AAElI,yDAAiE;AACjE,mEAAwE;AACxE,mEAAwE;AAIxE,MAAa,SAAS;aAYX,QAAU,GAAG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nimport { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from \"../symbols\";\nimport { Collection } from \"../HelperTypes\";\nimport { ChangeTree, type IRef } from \"../../encoder/ChangeTree\";\nimport { encodeKeyValueOperation } from \"../../encoder/EncodeOperation\";\nimport { decodeKeyValueOperation } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport type { Schema } from \"../../Schema\";\n\nexport class SetSchema<V=any> implements Collection<number, V>, IRef {\n [$changes]: ChangeTree;\n [$refId]?: number;\n\n protected [$childType]: string | typeof Schema;\n\n protected $items: Map<number, V> = new Map<number, V>();\n protected $indexes: Map<number, number> = new Map<number, number>();\n protected deletedItems: { [field: string]: V } = {};\n\n protected $refId: number = 0;\n\n static [$encoder] = encodeKeyValueOperation;\n static [$decoder] = decodeKeyValueOperation;\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: SetSchema, index: number, view: StateView) {\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n view.visible.has((ref[$getByIndex](index) ?? ref.deletedItems[index])[$changes])\n );\n }\n\n static is(type: any) {\n return type['set'] !== undefined;\n }\n\n constructor (initialValues?: Array<V>) {\n this[$changes] = new ChangeTree(this);\n this[$changes].indexes = {};\n\n if (initialValues) {\n initialValues.forEach((v) => this.add(v));\n }\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n }\n\n add(value: V) {\n // immediatelly return false if value already added.\n if (this.has(value)) { return false; }\n\n // set \"index\" for reference.\n const index = this.$refId++;\n\n if ((value[$changes]) !== undefined) {\n value[$changes].setParent(this, this[$changes].root, index);\n }\n\n const operation = this[$changes].indexes[index]?.op ?? OPERATION.ADD;\n\n this[$changes].indexes[index] = index;\n\n this.$indexes.set(index, index);\n this.$items.set(index, value);\n\n this[$changes].change(index, operation);\n return index;\n }\n\n entries () {\n return this.$items.entries();\n }\n\n delete(item: V) {\n const entries = this.$items.entries();\n\n let index: number;\n let entry: IteratorResult<[number, V]>;\n while (entry = entries.next()) {\n if (entry.done) { break; }\n\n if (item === entry.value[1]) {\n index = entry.value[0];\n break;\n }\n }\n\n if (index === undefined) {\n return false;\n }\n\n this.deletedItems[index] = this[$changes].delete(index);\n this.$indexes.delete(index);\n\n return this.$items.delete(index);\n }\n\n clear() {\n const changeTree = this[$changes];\n\n // discard previous operations.\n changeTree.discard(true);\n changeTree.indexes = {};\n\n // clear previous indexes\n this.$indexes.clear();\n\n // clear items\n this.$items.clear();\n\n changeTree.operation(OPERATION.CLEAR);\n }\n\n has (value: V): boolean {\n const values = this.$items.values();\n\n let has = false;\n let entry: IteratorResult<V>;\n\n while (entry = values.next()) {\n if (entry.done) { break; }\n if (value === entry.value) {\n has = true;\n break;\n }\n }\n\n return has;\n }\n\n forEach(callbackfn: (value: V, key: number, collection: SetSchema<V>) => void) {\n this.$items.forEach((value, key, _) => callbackfn(value, key, this));\n }\n\n values() {\n return this.$items.values();\n }\n\n get size () {\n return this.$items.size;\n }\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.$items.values();\n }\n\n protected setIndex(index: number, key: number) {\n this.$indexes.set(index, key);\n }\n\n protected getIndex(index: number) {\n return this.$indexes.get(index);\n }\n\n [$getByIndex](index: number): any {\n return this.$items.get(this.$indexes.get(index));\n }\n\n [$deleteByIndex](index: number): void {\n const key = this.$indexes.get(index);\n this.$items.delete(key);\n this.$indexes.delete(index);\n }\n\n protected [$onEncodeEnd]() {\n this.deletedItems = {};\n }\n\n toArray() {\n return Array.from(this.$items.values());\n }\n\n toJSON() {\n const values: V[] = [];\n\n this.forEach((value: any, key: number) => {\n values.push(\n (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value\n );\n });\n\n return values;\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): SetSchema<V> {\n let cloned: SetSchema;\n\n if (isDecoding) {\n // client-side\n cloned = Object.assign(new SetSchema(), this);\n\n } else {\n // server-side\n cloned = new SetSchema();\n this.forEach((value: any) => {\n if (value[$changes]) {\n cloned.add(value['clone']());\n } else {\n cloned.add(value);\n }\n })\n }\n\n return cloned;\n }\n\n}\n\nregisterType(\"set\", { constructor: SetSchema });"]}
@@ -1,3 +1,4 @@
1
+ export declare const $refId = "~refId";
1
2
  export declare const $track = "~track";
2
3
  export declare const $encoder = "~encoder";
3
4
  export declare const $decoder = "~decoder";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.$fieldIndexesByViewTag = exports.$viewFieldIndexes = exports.$refTypeFieldIndexes = exports.$numFields = exports.$descriptors = exports.$onDecodeEnd = exports.$onEncodeEnd = exports.$childType = exports.$changes = exports.$deleteByIndex = exports.$getByIndex = exports.$filter = exports.$decoder = exports.$encoder = exports.$track = void 0;
3
+ exports.$fieldIndexesByViewTag = exports.$viewFieldIndexes = exports.$refTypeFieldIndexes = exports.$numFields = exports.$descriptors = exports.$onDecodeEnd = exports.$onEncodeEnd = exports.$childType = exports.$changes = exports.$deleteByIndex = exports.$getByIndex = exports.$filter = exports.$decoder = exports.$encoder = exports.$track = exports.$refId = void 0;
4
+ exports.$refId = "~refId";
4
5
  exports.$track = "~track";
5
6
  exports.$encoder = "~encoder";
6
7
  exports.$decoder = "~decoder";
@@ -1 +1 @@
1
- {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/types/symbols.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,QAAQ,GAAG,UAAU,CAAC;AACtB,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEtB,QAAA,OAAO,GAAG,SAAS,CAAC;AAEpB,QAAA,WAAW,GAAG,aAAa,CAAC;AAC5B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAE/C;;GAEG;AACU,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEnC;;;GAGG;AACU,QAAA,UAAU,GAAG,YAAY,CAAC;AAEvC;;;GAGG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAE3C;;GAEG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAE3C;;GAEG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,UAAU,GAAG,cAAc,CAAC;AAC5B,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAChD,QAAA,iBAAiB,GAAG,qBAAqB,CAAC;AAC1C,QAAA,sBAAsB,GAAG,0BAA0B,CAAC","sourcesContent":["export const $track = \"~track\";\nexport const $encoder = \"~encoder\";\nexport const $decoder = \"~decoder\";\n\nexport const $filter = \"~filter\";\n\nexport const $getByIndex = \"~getByIndex\";\nexport const $deleteByIndex = \"~deleteByIndex\";\n\n/**\n * Used to hold ChangeTree instances whitin the structures\n */\nexport const $changes = '~changes';\n\n/**\n * Used to keep track of the type of the child elements of a collection\n * (MapSchema, ArraySchema, etc.)\n */\nexport const $childType = '~childType';\n\n/**\n * Optional \"discard\" method for custom types (ArraySchema)\n * (Discards changes for next serialization)\n */\nexport const $onEncodeEnd = '~onEncodeEnd';\n\n/**\n * When decoding, this method is called after the instance is fully decoded\n */\nexport const $onDecodeEnd = \"~onDecodeEnd\";\n\n/**\n * Metadata\n */\nexport const $descriptors = \"~descriptors\";\nexport const $numFields = \"~__numFields\";\nexport const $refTypeFieldIndexes = \"~__refTypeFieldIndexes\";\nexport const $viewFieldIndexes = \"~__viewFieldIndexes\";\nexport const $fieldIndexesByViewTag = \"$__fieldIndexesByViewTag\";"]}
1
+ {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/types/symbols.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,QAAQ,GAAG,UAAU,CAAC;AACtB,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEtB,QAAA,OAAO,GAAG,SAAS,CAAC;AAEpB,QAAA,WAAW,GAAG,aAAa,CAAC;AAC5B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAE/C;;GAEG;AACU,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEnC;;;GAGG;AACU,QAAA,UAAU,GAAG,YAAY,CAAC;AAEvC;;;GAGG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAE3C;;GAEG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAE3C;;GAEG;AACU,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,UAAU,GAAG,cAAc,CAAC;AAC5B,QAAA,oBAAoB,GAAG,wBAAwB,CAAC;AAChD,QAAA,iBAAiB,GAAG,qBAAqB,CAAC;AAC1C,QAAA,sBAAsB,GAAG,0BAA0B,CAAC","sourcesContent":["export const $refId = \"~refId\";\nexport const $track = \"~track\";\nexport const $encoder = \"~encoder\";\nexport const $decoder = \"~decoder\";\n\nexport const $filter = \"~filter\";\n\nexport const $getByIndex = \"~getByIndex\";\nexport const $deleteByIndex = \"~deleteByIndex\";\n\n/**\n * Used to hold ChangeTree instances whitin the structures\n */\nexport const $changes = '~changes';\n\n/**\n * Used to keep track of the type of the child elements of a collection\n * (MapSchema, ArraySchema, etc.)\n */\nexport const $childType = '~childType';\n\n/**\n * Optional \"discard\" method for custom types (ArraySchema)\n * (Discards changes for next serialization)\n */\nexport const $onEncodeEnd = '~onEncodeEnd';\n\n/**\n * When decoding, this method is called after the instance is fully decoded\n */\nexport const $onDecodeEnd = \"~onDecodeEnd\";\n\n/**\n * Metadata\n */\nexport const $descriptors = \"~descriptors\";\nexport const $numFields = \"~__numFields\";\nexport const $refTypeFieldIndexes = \"~__refTypeFieldIndexes\";\nexport const $viewFieldIndexes = \"~__viewFieldIndexes\";\nexport const $fieldIndexesByViewTag = \"$__fieldIndexesByViewTag\";"]}
package/lib/utils.js CHANGED
@@ -24,7 +24,7 @@ function dumpChanges(schema) {
24
24
  continue;
25
25
  }
26
26
  const changes = changeTree.indexedOperations;
27
- dump.refs.push(`refId#${changeTree.refId}`);
27
+ dump.refs.push(`refId#${changeTree.ref[symbols_1.$refId]}`);
28
28
  for (const index in changes) {
29
29
  const op = changes[index];
30
30
  const opName = spec_1.OPERATION[op];
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAaA,8BAIC;AAED,kCA+BC;AAED,0CAeC;AAlED,0CAA4C;AAC5C,6CAA2C;AAW3C,SAAgB,SAAS,CAAC,KAAa;IACnC,OAAO,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC3C,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CACpC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,WAAW,CAAC,MAAc;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,kBAAQ,CAAC,CAAC,IAAI,CAAC;IAEpC,MAAM,IAAI,GAAe;QACrB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,EAAE;KACX,CAAC;IAEF,uCAAuC;IACvC,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC,OAAO,OAAO,EAAE,CAAC;QACb,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,kCAAkC;QAClC,IAAI,UAAU,KAAK,SAAS,EAAG,CAAC;YAC5B,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YACvB,SAAS;QACb,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAE7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,MAAM,GAAG,gBAAS,CAAC,EAAE,CAAC,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAiC,CAAC,EAAE,CAAC;gBAAC,IAAI,CAAC,GAAG,CAAC,MAAiC,CAAC,GAAG,CAAC,CAAC;YAAC,CAAC;YACtG,IAAI,CAAC,GAAG,CAAC,gBAAS,CAAC,EAAE,CAA4B,CAAC,EAAE,CAAC;QACzD,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC1C,+CAA+C;IAC/C,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,gDAAgD;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC;QAChB,MAAM,KAAK,CAAC,CAAC;QACb,WAAW,EAAE,CAAC;IAClB,CAAC;IAED,6BAA6B;IAC7B,OAAO,CAAC,IAAI,WAAW,CAAC;AAC5B,CAAC","sourcesContent":["import type { Schema } from \"./Schema\";\nimport { OPERATION } from \"./encoding/spec\";\nimport { $changes } from \"./types/symbols\";\n\ninterface ChangeDump {\n ops: {\n ADD?: number;\n REMOVE?: number;\n REPLACE?: number;\n },\n refs: string[],\n}\n\nexport function getIndent(level: number) {\n return (new Array(level).fill(0)).map((_, i) =>\n (i === level - 1) ? `└─ ` : ` `\n ).join(\"\");\n}\n\nexport function dumpChanges(schema: Schema) {\n const $root = schema[$changes].root;\n\n const dump: ChangeDump = {\n ops: {},\n refs: []\n };\n\n // for (const refId in $root.changes) {\n let current = $root.changes.next;\n while (current) {\n const changeTree = current.changeTree;\n // skip if ChangeTree is undefined\n if (changeTree === undefined) {\n current = current.next;\n continue;\n }\n\n const changes = changeTree.indexedOperations;\n\n dump.refs.push(`refId#${changeTree.refId}`);\n for (const index in changes) {\n const op = changes[index];\n const opName = OPERATION[op];\n if (!dump.ops[opName as keyof ChangeDump['ops']]) { dump.ops[opName as keyof ChangeDump['ops']] = 0; }\n dump.ops[OPERATION[op] as keyof ChangeDump['ops']]++;\n }\n current = current.next;\n }\n\n return dump;\n}\n\nexport function getNextPowerOf2(number: number) {\n // If number is already a power of 2, return it\n if ((number & (number - 1)) === 0) {\n return number;\n }\n\n // Find the position of the most significant bit\n let msbPosition = 0;\n while (number > 0) {\n number >>= 1;\n msbPosition++;\n }\n\n // Return the next power of 2\n return 1 << msbPosition;\n}"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAaA,8BAIC;AAED,kCA+BC;AAED,0CAeC;AAlED,0CAA4C;AAC5C,6CAAmD;AAWnD,SAAgB,SAAS,CAAC,KAAa;IACnC,OAAO,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC3C,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CACpC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,WAAW,CAAC,MAAc;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,kBAAQ,CAAC,CAAC,IAAI,CAAC;IAEpC,MAAM,IAAI,G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C;QAChB,MAAM,KAAK,CAAC,CAAC;QACb,WAAW,EAAE,CAAC;IAClB,CAAC;IAED,6BAA6B;IAC7B,OAAO,CAAC,IAAI,WAAW,CAAC;AAC5B,CAAC","sourcesContent":["import type { Schema } from \"./Schema\";\nimport { OPERATION } from \"./encoding/spec\";\nimport { $changes, $refId } from \"./types/symbols\";\n\ninterface ChangeDump {\n ops: {\n ADD?: number;\n REMOVE?: number;\n REPLACE?: number;\n },\n refs: string[],\n}\n\nexport function getIndent(level: number) {\n return (new Array(level).fill(0)).map((_, i) =>\n (i === level - 1) ? `└─ ` : ` `\n ).join(\"\");\n}\n\nexport function dumpChanges(schema: Schema) {\n const $root = schema[$changes].root;\n\n const dump: ChangeDump = {\n ops: {},\n refs: []\n };\n\n // for (const refId in $root.changes) {\n let current = $root.changes.next;\n while (current) {\n const changeTree = current.changeTree;\n // skip if ChangeTree is undefined\n if (changeTree === undefined) {\n current = current.next;\n continue;\n }\n\n const changes = changeTree.indexedOperations;\n\n dump.refs.push(`refId#${changeTree.ref[$refId]}`);\n for (const index in changes) {\n const op = changes[index];\n const opName = OPERATION[op];\n if (!dump.ops[opName as keyof ChangeDump['ops']]) { dump.ops[opName as keyof ChangeDump['ops']] = 0; }\n dump.ops[OPERATION[op] as keyof ChangeDump['ops']]++;\n }\n current = current.next;\n }\n\n return dump;\n}\n\nexport function getNextPowerOf2(number: number) {\n // If number is already a power of 2, return it\n if ((number & (number - 1)) === 0) {\n return number;\n }\n\n // Find the position of the most significant bit\n let msbPosition = 0;\n while (number > 0) {\n number >>= 1;\n msbPosition++;\n }\n\n // Return the next power of 2\n return 1 << msbPosition;\n}"]}