@colyseus/schema 4.0.2 → 4.0.3

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 (326) hide show
  1. package/{lib → build}/Metadata.d.ts +2 -2
  2. package/{lib → build}/Reflection.d.ts +13 -13
  3. package/{lib → build}/Schema.d.ts +10 -10
  4. package/{lib/src → build}/annotations.d.ts +10 -10
  5. package/build/codegen/languages/cpp.d.ts +3 -0
  6. package/build/codegen/languages/csharp.d.ts +4 -0
  7. package/build/codegen/languages/haxe.d.ts +3 -0
  8. package/{lib → build}/codegen/languages/java.d.ts +2 -2
  9. package/build/codegen/languages/js.d.ts +3 -0
  10. package/build/codegen/languages/lua.d.ts +3 -0
  11. package/build/codegen/languages/ts.d.ts +3 -0
  12. package/{lib → build}/codegen/parser.d.ts +1 -1
  13. package/{lib → build}/decoder/DecodeOperation.d.ts +5 -5
  14. package/{lib/src → build}/decoder/Decoder.d.ts +7 -7
  15. package/{lib → build}/decoder/ReferenceTracker.d.ts +1 -1
  16. package/{lib → build}/decoder/strategy/Callbacks.d.ts +11 -11
  17. package/{lib → build}/decoder/strategy/RawChanges.d.ts +2 -2
  18. package/{lib → build}/decoder/strategy/getDecoderStateCallbacks.d.ts +3 -3
  19. package/{lib → build}/encoder/ChangeTree.d.ts +11 -11
  20. package/{lib → build}/encoder/EncodeOperation.d.ts +5 -5
  21. package/{lib → build}/encoder/Encoder.d.ts +6 -6
  22. package/{lib/src → build}/encoder/Root.d.ts +2 -2
  23. package/{lib/src → build}/encoder/StateView.d.ts +1 -1
  24. package/{lib/src → build}/encoding/assert.d.ts +6 -6
  25. package/{lib/src → build}/encoding/decode.d.ts +1 -1
  26. package/{lib/src → build}/encoding/encode.d.ts +1 -1
  27. package/build/index.cjs.map +1 -0
  28. package/build/index.d.ts +32 -0
  29. package/build/index.mjs.map +1 -0
  30. package/{lib → build}/types/HelperTypes.d.ts +6 -6
  31. package/{lib → build}/types/TypeContext.d.ts +1 -1
  32. package/{lib/src → build}/types/custom/ArraySchema.d.ts +8 -8
  33. package/{lib/src → build}/types/custom/CollectionSchema.d.ts +7 -7
  34. package/{lib → build}/types/custom/MapSchema.d.ts +7 -7
  35. package/{lib/src → build}/types/custom/SetSchema.d.ts +7 -7
  36. package/{lib/src → build}/types/registry.d.ts +2 -2
  37. package/{lib → build}/utils.d.ts +1 -1
  38. package/package.json +9 -10
  39. package/src/Metadata.ts +5 -5
  40. package/src/Reflection.ts +7 -7
  41. package/src/Schema.ts +11 -11
  42. package/src/annotations.ts +13 -13
  43. package/src/codegen/api.ts +3 -3
  44. package/src/codegen/cli.ts +2 -2
  45. package/src/codegen/languages/cpp.ts +2 -2
  46. package/src/codegen/languages/csharp.ts +3 -3
  47. package/src/codegen/languages/haxe.ts +2 -2
  48. package/src/codegen/languages/java.ts +2 -2
  49. package/src/codegen/languages/js.ts +2 -2
  50. package/src/codegen/languages/lua.ts +2 -2
  51. package/src/codegen/languages/ts.ts +2 -2
  52. package/src/codegen/parser.ts +6 -1
  53. package/src/decoder/DecodeOperation.ts +14 -14
  54. package/src/decoder/Decoder.ts +11 -11
  55. package/src/decoder/ReferenceTracker.ts +8 -8
  56. package/src/decoder/strategy/Callbacks.ts +12 -12
  57. package/src/decoder/strategy/RawChanges.ts +2 -2
  58. package/src/decoder/strategy/getDecoderStateCallbacks.ts +10 -10
  59. package/src/encoder/ChangeTree.ts +13 -13
  60. package/src/encoder/EncodeOperation.ts +9 -9
  61. package/src/encoder/Encoder.ts +10 -10
  62. package/src/encoder/Root.ts +4 -4
  63. package/src/encoder/StateView.ts +7 -7
  64. package/src/encoding/assert.ts +6 -6
  65. package/src/encoding/decode.ts +1 -1
  66. package/src/encoding/encode.ts +1 -1
  67. package/src/index.ts +27 -27
  68. package/src/types/HelperTypes.ts +6 -6
  69. package/src/types/TypeContext.ts +3 -3
  70. package/src/types/custom/ArraySchema.ts +11 -11
  71. package/src/types/custom/CollectionSchema.ts +9 -9
  72. package/src/types/custom/MapSchema.ts +10 -10
  73. package/src/types/custom/SetSchema.ts +9 -9
  74. package/src/types/registry.ts +3 -3
  75. package/src/utils.ts +3 -3
  76. package/src/v3_bench.ts +1 -1
  77. package/build/cjs/index.cjs.map +0 -1
  78. package/build/esm/index.mjs.map +0 -1
  79. package/lib/Metadata.js +0 -256
  80. package/lib/Metadata.js.map +0 -1
  81. package/lib/Reflection.js +0 -179
  82. package/lib/Reflection.js.map +0 -1
  83. package/lib/Schema.js +0 -352
  84. package/lib/Schema.js.map +0 -1
  85. package/lib/annotations.d.ts +0 -109
  86. package/lib/annotations.js +0 -473
  87. package/lib/annotations.js.map +0 -1
  88. package/lib/bench_encode.d.ts +0 -1
  89. package/lib/bench_encode.js +0 -91
  90. package/lib/bench_encode.js.map +0 -1
  91. package/lib/benchmark.d.ts +0 -1
  92. package/lib/benchmark.js +0 -218
  93. package/lib/benchmark.js.map +0 -1
  94. package/lib/codegen/api.js +0 -56
  95. package/lib/codegen/api.js.map +0 -1
  96. package/lib/codegen/argv.js +0 -39
  97. package/lib/codegen/argv.js.map +0 -1
  98. package/lib/codegen/cli.js +0 -58
  99. package/lib/codegen/cli.js.map +0 -1
  100. package/lib/codegen/languages/cpp.d.ts +0 -3
  101. package/lib/codegen/languages/cpp.js +0 -258
  102. package/lib/codegen/languages/cpp.js.map +0 -1
  103. package/lib/codegen/languages/csharp.d.ts +0 -4
  104. package/lib/codegen/languages/csharp.js +0 -154
  105. package/lib/codegen/languages/csharp.js.map +0 -1
  106. package/lib/codegen/languages/haxe.d.ts +0 -3
  107. package/lib/codegen/languages/haxe.js +0 -100
  108. package/lib/codegen/languages/haxe.js.map +0 -1
  109. package/lib/codegen/languages/java.js +0 -100
  110. package/lib/codegen/languages/java.js.map +0 -1
  111. package/lib/codegen/languages/js.d.ts +0 -3
  112. package/lib/codegen/languages/js.js +0 -101
  113. package/lib/codegen/languages/js.js.map +0 -1
  114. package/lib/codegen/languages/lua.d.ts +0 -3
  115. package/lib/codegen/languages/lua.js +0 -103
  116. package/lib/codegen/languages/lua.js.map +0 -1
  117. package/lib/codegen/languages/ts.d.ts +0 -3
  118. package/lib/codegen/languages/ts.js +0 -116
  119. package/lib/codegen/languages/ts.js.map +0 -1
  120. package/lib/codegen/parser.js +0 -327
  121. package/lib/codegen/parser.js.map +0 -1
  122. package/lib/codegen/types.js +0 -142
  123. package/lib/codegen/types.js.map +0 -1
  124. package/lib/decoder/DecodeOperation.js +0 -248
  125. package/lib/decoder/DecodeOperation.js.map +0 -1
  126. package/lib/decoder/Decoder.d.ts +0 -21
  127. package/lib/decoder/Decoder.js +0 -114
  128. package/lib/decoder/Decoder.js.map +0 -1
  129. package/lib/decoder/ReferenceTracker.js +0 -135
  130. package/lib/decoder/ReferenceTracker.js.map +0 -1
  131. package/lib/decoder/strategy/Callbacks.js +0 -336
  132. package/lib/decoder/strategy/Callbacks.js.map +0 -1
  133. package/lib/decoder/strategy/RawChanges.js +0 -4
  134. package/lib/decoder/strategy/RawChanges.js.map +0 -1
  135. package/lib/decoder/strategy/getDecoderStateCallbacks.js +0 -274
  136. package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
  137. package/lib/encoder/ChangeTree.js +0 -534
  138. package/lib/encoder/ChangeTree.js.map +0 -1
  139. package/lib/encoder/EncodeOperation.js +0 -132
  140. package/lib/encoder/EncodeOperation.js.map +0 -1
  141. package/lib/encoder/Encoder.js +0 -204
  142. package/lib/encoder/Encoder.js.map +0 -1
  143. package/lib/encoder/Root.d.ts +0 -28
  144. package/lib/encoder/Root.js +0 -229
  145. package/lib/encoder/Root.js.map +0 -1
  146. package/lib/encoder/StateView.d.ts +0 -34
  147. package/lib/encoder/StateView.js +0 -279
  148. package/lib/encoder/StateView.js.map +0 -1
  149. package/lib/encoding/assert.d.ts +0 -10
  150. package/lib/encoding/assert.js +0 -49
  151. package/lib/encoding/assert.js.map +0 -1
  152. package/lib/encoding/decode.d.ts +0 -67
  153. package/lib/encoding/decode.js +0 -217
  154. package/lib/encoding/decode.js.map +0 -1
  155. package/lib/encoding/encode.d.ts +0 -40
  156. package/lib/encoding/encode.js +0 -279
  157. package/lib/encoding/encode.js.map +0 -1
  158. package/lib/encoding/spec.js +0 -26
  159. package/lib/encoding/spec.js.map +0 -1
  160. package/lib/index.d.ts +0 -32
  161. package/lib/index.js +0 -39
  162. package/lib/index.js.map +0 -1
  163. package/lib/src/Metadata.d.ts +0 -49
  164. package/lib/src/Metadata.js +0 -256
  165. package/lib/src/Metadata.js.map +0 -1
  166. package/lib/src/Reflection.d.ts +0 -71
  167. package/lib/src/Reflection.js +0 -179
  168. package/lib/src/Reflection.js.map +0 -1
  169. package/lib/src/Schema.d.ts +0 -86
  170. package/lib/src/Schema.js +0 -352
  171. package/lib/src/Schema.js.map +0 -1
  172. package/lib/src/annotations.js +0 -473
  173. package/lib/src/annotations.js.map +0 -1
  174. package/lib/src/bench_encode.d.ts +0 -1
  175. package/lib/src/bench_encode.js +0 -91
  176. package/lib/src/bench_encode.js.map +0 -1
  177. package/lib/src/codegen/api.d.ts +0 -7
  178. package/lib/src/codegen/api.js +0 -56
  179. package/lib/src/codegen/api.js.map +0 -1
  180. package/lib/src/codegen/argv.d.ts +0 -6
  181. package/lib/src/codegen/argv.js +0 -39
  182. package/lib/src/codegen/argv.js.map +0 -1
  183. package/lib/src/codegen/cli.d.ts +0 -1
  184. package/lib/src/codegen/cli.js +0 -58
  185. package/lib/src/codegen/cli.js.map +0 -1
  186. package/lib/src/codegen/languages/cpp.d.ts +0 -3
  187. package/lib/src/codegen/languages/cpp.js +0 -258
  188. package/lib/src/codegen/languages/cpp.js.map +0 -1
  189. package/lib/src/codegen/languages/csharp.d.ts +0 -4
  190. package/lib/src/codegen/languages/csharp.js +0 -154
  191. package/lib/src/codegen/languages/csharp.js.map +0 -1
  192. package/lib/src/codegen/languages/haxe.d.ts +0 -3
  193. package/lib/src/codegen/languages/haxe.js +0 -100
  194. package/lib/src/codegen/languages/haxe.js.map +0 -1
  195. package/lib/src/codegen/languages/java.d.ts +0 -6
  196. package/lib/src/codegen/languages/java.js +0 -100
  197. package/lib/src/codegen/languages/java.js.map +0 -1
  198. package/lib/src/codegen/languages/js.d.ts +0 -3
  199. package/lib/src/codegen/languages/js.js +0 -101
  200. package/lib/src/codegen/languages/js.js.map +0 -1
  201. package/lib/src/codegen/languages/lua.d.ts +0 -3
  202. package/lib/src/codegen/languages/lua.js +0 -103
  203. package/lib/src/codegen/languages/lua.js.map +0 -1
  204. package/lib/src/codegen/languages/ts.d.ts +0 -3
  205. package/lib/src/codegen/languages/ts.js +0 -116
  206. package/lib/src/codegen/languages/ts.js.map +0 -1
  207. package/lib/src/codegen/parser.d.ts +0 -13
  208. package/lib/src/codegen/parser.js +0 -327
  209. package/lib/src/codegen/parser.js.map +0 -1
  210. package/lib/src/codegen/types.d.ts +0 -52
  211. package/lib/src/codegen/types.js +0 -142
  212. package/lib/src/codegen/types.js.map +0 -1
  213. package/lib/src/decoder/DecodeOperation.d.ts +0 -23
  214. package/lib/src/decoder/DecodeOperation.js +0 -248
  215. package/lib/src/decoder/DecodeOperation.js.map +0 -1
  216. package/lib/src/decoder/Decoder.js +0 -114
  217. package/lib/src/decoder/Decoder.js.map +0 -1
  218. package/lib/src/decoder/ReferenceTracker.d.ts +0 -25
  219. package/lib/src/decoder/ReferenceTracker.js +0 -135
  220. package/lib/src/decoder/ReferenceTracker.js.map +0 -1
  221. package/lib/src/decoder/strategy/Callbacks.d.ts +0 -154
  222. package/lib/src/decoder/strategy/Callbacks.js +0 -336
  223. package/lib/src/decoder/strategy/Callbacks.js.map +0 -1
  224. package/lib/src/decoder/strategy/RawChanges.d.ts +0 -3
  225. package/lib/src/decoder/strategy/RawChanges.js +0 -4
  226. package/lib/src/decoder/strategy/RawChanges.js.map +0 -1
  227. package/lib/src/decoder/strategy/getDecoderStateCallbacks.d.ts +0 -76
  228. package/lib/src/decoder/strategy/getDecoderStateCallbacks.js +0 -274
  229. package/lib/src/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
  230. package/lib/src/encoder/ChangeTree.d.ts +0 -135
  231. package/lib/src/encoder/ChangeTree.js +0 -534
  232. package/lib/src/encoder/ChangeTree.js.map +0 -1
  233. package/lib/src/encoder/EncodeOperation.d.ts +0 -22
  234. package/lib/src/encoder/EncodeOperation.js +0 -132
  235. package/lib/src/encoder/EncodeOperation.js.map +0 -1
  236. package/lib/src/encoder/Encoder.d.ts +0 -22
  237. package/lib/src/encoder/Encoder.js +0 -204
  238. package/lib/src/encoder/Encoder.js.map +0 -1
  239. package/lib/src/encoder/Root.js +0 -229
  240. package/lib/src/encoder/Root.js.map +0 -1
  241. package/lib/src/encoder/StateView.js +0 -279
  242. package/lib/src/encoder/StateView.js.map +0 -1
  243. package/lib/src/encoding/assert.js +0 -49
  244. package/lib/src/encoding/assert.js.map +0 -1
  245. package/lib/src/encoding/decode.js +0 -217
  246. package/lib/src/encoding/decode.js.map +0 -1
  247. package/lib/src/encoding/encode.js +0 -279
  248. package/lib/src/encoding/encode.js.map +0 -1
  249. package/lib/src/encoding/spec.d.ts +0 -24
  250. package/lib/src/encoding/spec.js +0 -26
  251. package/lib/src/encoding/spec.js.map +0 -1
  252. package/lib/src/index.d.ts +0 -32
  253. package/lib/src/index.js +0 -39
  254. package/lib/src/index.js.map +0 -1
  255. package/lib/src/symbol.shim.js +0 -3
  256. package/lib/src/symbol.shim.js.map +0 -1
  257. package/lib/src/types/HelperTypes.d.ts +0 -77
  258. package/lib/src/types/HelperTypes.js +0 -2
  259. package/lib/src/types/HelperTypes.js.map +0 -1
  260. package/lib/src/types/TypeContext.d.ts +0 -31
  261. package/lib/src/types/TypeContext.js +0 -143
  262. package/lib/src/types/TypeContext.js.map +0 -1
  263. package/lib/src/types/custom/ArraySchema.js +0 -733
  264. package/lib/src/types/custom/ArraySchema.js.map +0 -1
  265. package/lib/src/types/custom/CollectionSchema.js +0 -170
  266. package/lib/src/types/custom/CollectionSchema.js.map +0 -1
  267. package/lib/src/types/custom/MapSchema.d.ts +0 -51
  268. package/lib/src/types/custom/MapSchema.js +0 -222
  269. package/lib/src/types/custom/MapSchema.js.map +0 -1
  270. package/lib/src/types/custom/SetSchema.js +0 -178
  271. package/lib/src/types/custom/SetSchema.js.map +0 -1
  272. package/lib/src/types/registry.js +0 -30
  273. package/lib/src/types/registry.js.map +0 -1
  274. package/lib/src/types/symbols.js +0 -34
  275. package/lib/src/types/symbols.js.map +0 -1
  276. package/lib/src/types/utils.js +0 -13
  277. package/lib/src/types/utils.js.map +0 -1
  278. package/lib/src/utils.d.ts +0 -13
  279. package/lib/src/utils.js +0 -49
  280. package/lib/src/utils.js.map +0 -1
  281. package/lib/src/v3_bench.js +0 -128
  282. package/lib/src/v3_bench.js.map +0 -1
  283. package/lib/symbol.shim.d.ts +0 -6
  284. package/lib/symbol.shim.js +0 -3
  285. package/lib/symbol.shim.js.map +0 -1
  286. package/lib/types/HelperTypes.js +0 -2
  287. package/lib/types/HelperTypes.js.map +0 -1
  288. package/lib/types/TypeContext.js +0 -143
  289. package/lib/types/TypeContext.js.map +0 -1
  290. package/lib/types/custom/ArraySchema.d.ts +0 -270
  291. package/lib/types/custom/ArraySchema.js +0 -733
  292. package/lib/types/custom/ArraySchema.js.map +0 -1
  293. package/lib/types/custom/CollectionSchema.d.ts +0 -51
  294. package/lib/types/custom/CollectionSchema.js +0 -170
  295. package/lib/types/custom/CollectionSchema.js.map +0 -1
  296. package/lib/types/custom/MapSchema.js +0 -222
  297. package/lib/types/custom/MapSchema.js.map +0 -1
  298. package/lib/types/custom/SetSchema.d.ts +0 -48
  299. package/lib/types/custom/SetSchema.js +0 -178
  300. package/lib/types/custom/SetSchema.js.map +0 -1
  301. package/lib/types/registry.d.ts +0 -16
  302. package/lib/types/registry.js +0 -30
  303. package/lib/types/registry.js.map +0 -1
  304. package/lib/types/symbols.d.ts +0 -33
  305. package/lib/types/symbols.js +0 -34
  306. package/lib/types/symbols.js.map +0 -1
  307. package/lib/types/utils.d.ts +0 -1
  308. package/lib/types/utils.js +0 -13
  309. package/lib/types/utils.js.map +0 -1
  310. package/lib/utils.js +0 -49
  311. package/lib/utils.js.map +0 -1
  312. package/lib/v3_bench.d.ts +0 -1
  313. package/lib/v3_bench.js +0 -128
  314. package/lib/v3_bench.js.map +0 -1
  315. /package/{lib → build}/codegen/api.d.ts +0 -0
  316. /package/{lib → build}/codegen/argv.d.ts +0 -0
  317. /package/{lib → build}/codegen/cli.d.ts +0 -0
  318. /package/{lib → build}/codegen/types.d.ts +0 -0
  319. /package/{lib → build}/encoding/spec.d.ts +0 -0
  320. /package/build/{cjs/index.cjs → index.cjs} +0 -0
  321. /package/build/{umd/index.js → index.js} +0 -0
  322. /package/build/{esm/index.mjs → index.mjs} +0 -0
  323. /package/{lib/src → build}/symbol.shim.d.ts +0 -0
  324. /package/{lib/src → build}/types/symbols.d.ts +0 -0
  325. /package/{lib/src → build}/types/utils.d.ts +0 -0
  326. /package/{lib/src → build}/v3_bench.d.ts +0 -0
@@ -1,534 +0,0 @@
1
- import { OPERATION } from "../encoding/spec";
2
- import { $changes, $childType, $onEncodeEnd, $getByIndex, $refId, $refTypeFieldIndexes, $viewFieldIndexes } from "../types/symbols";
3
- import { Metadata } from "../Metadata";
4
- function createChangeSet(queueRootNode) {
5
- return { indexes: {}, operations: [], queueRootNode };
6
- }
7
- // Linked list helper functions
8
- export function createChangeTreeList() {
9
- return { next: undefined, tail: undefined };
10
- }
11
- export function setOperationAtIndex(changeSet, index) {
12
- const operationsIndex = changeSet.indexes[index];
13
- if (operationsIndex === undefined) {
14
- changeSet.indexes[index] = changeSet.operations.push(index) - 1;
15
- }
16
- else {
17
- changeSet.operations[operationsIndex] = index;
18
- }
19
- }
20
- export function deleteOperationAtIndex(changeSet, index) {
21
- let operationsIndex = changeSet.indexes[index];
22
- if (operationsIndex === undefined) {
23
- //
24
- // if index is not found, we need to find the last operation
25
- // FIXME: this is not very efficient
26
- //
27
- // > See "should allow consecutive splices (same place)" tests
28
- //
29
- operationsIndex = Object.values(changeSet.indexes).at(-1);
30
- index = Object.entries(changeSet.indexes).find(([_, value]) => value === operationsIndex)?.[0];
31
- }
32
- changeSet.operations[operationsIndex] = undefined;
33
- delete changeSet.indexes[index];
34
- }
35
- export function debugChangeSet(label, changeSet) {
36
- let indexes = [];
37
- let operations = [];
38
- for (const index in changeSet.indexes) {
39
- indexes.push(`\t${index} => [${changeSet.indexes[index]}]`);
40
- }
41
- for (let i = 0; i < changeSet.operations.length; i++) {
42
- const index = changeSet.operations[i];
43
- if (index !== undefined) {
44
- operations.push(`\t[${i}] => ${index}`);
45
- }
46
- }
47
- console.log(`${label} =>\nindexes (${Object.keys(changeSet.indexes).length}) {`);
48
- console.log(indexes.join("\n"), "\n}");
49
- console.log(`operations (${changeSet.operations.filter(op => op !== undefined).length}) {`);
50
- console.log(operations.join("\n"), "\n}");
51
- }
52
- export class ChangeTree {
53
- constructor(ref) {
54
- /**
55
- * Whether this structure is parent of a filtered structure.
56
- */
57
- this.isFiltered = false;
58
- this.indexedOperations = {};
59
- //
60
- // TODO:
61
- // try storing the index + operation per item.
62
- // example: 1024 & 1025 => ADD, 1026 => DELETE
63
- //
64
- // => https://chatgpt.com/share/67107d0c-bc20-8004-8583-83b17dd7c196
65
- //
66
- this.changes = { indexes: {}, operations: [] };
67
- this.allChanges = { indexes: {}, operations: [] };
68
- /**
69
- * Is this a new instance? Used on ArraySchema to determine OPERATION.MOVE_AND_ADD operation.
70
- */
71
- this.isNew = true;
72
- this.ref = ref;
73
- this.metadata = ref.constructor[Symbol.metadata];
74
- //
75
- // Does this structure have "filters" declared?
76
- //
77
- if (this.metadata?.[$viewFieldIndexes]) {
78
- this.allFilteredChanges = { indexes: {}, operations: [] };
79
- this.filteredChanges = { indexes: {}, operations: [] };
80
- }
81
- }
82
- setRoot(root) {
83
- this.root = root;
84
- const isNewChangeTree = this.root.add(this);
85
- this.checkIsFiltered(this.parent, this.parentIndex, isNewChangeTree);
86
- // Recursively set root on child structures
87
- if (isNewChangeTree) {
88
- this.forEachChild((child, _) => {
89
- if (child.root !== root) {
90
- child.setRoot(root);
91
- }
92
- else {
93
- root.add(child); // increment refCount
94
- }
95
- });
96
- }
97
- }
98
- setParent(parent, root, parentIndex) {
99
- this.addParent(parent, parentIndex);
100
- // avoid setting parents with empty `root`
101
- if (!root) {
102
- return;
103
- }
104
- const isNewChangeTree = root.add(this);
105
- // skip if parent is already set
106
- if (root !== this.root) {
107
- this.root = root;
108
- this.checkIsFiltered(parent, parentIndex, isNewChangeTree);
109
- }
110
- // assign same parent on child structures
111
- if (isNewChangeTree) {
112
- //
113
- // assign same parent on child structures
114
- //
115
- this.forEachChild((child, index) => {
116
- if (child.root === root) {
117
- //
118
- // re-assigning a child of the same root, move it next to parent
119
- // so encoding order is preserved
120
- //
121
- root.add(child);
122
- root.moveNextToParent(child);
123
- return;
124
- }
125
- child.setParent(this.ref, root, index);
126
- });
127
- }
128
- }
129
- forEachChild(callback) {
130
- //
131
- // assign same parent on child structures
132
- //
133
- if (this.ref[$childType]) {
134
- if (typeof (this.ref[$childType]) !== "string") {
135
- // MapSchema / ArraySchema, etc.
136
- for (const [key, value] of this.ref.entries()) {
137
- if (!value) {
138
- continue;
139
- } // sparse arrays can have undefined values
140
- callback(value[$changes], this.indexes?.[key] ?? key);
141
- }
142
- ;
143
- }
144
- }
145
- else {
146
- for (const index of this.metadata?.[$refTypeFieldIndexes] ?? []) {
147
- const field = this.metadata[index];
148
- const value = this.ref[field.name];
149
- if (!value) {
150
- continue;
151
- }
152
- callback(value[$changes], index);
153
- }
154
- }
155
- }
156
- operation(op) {
157
- // operations without index use negative values to represent them
158
- // this is checked during .encode() time.
159
- if (this.filteredChanges !== undefined) {
160
- this.filteredChanges.operations.push(-op);
161
- this.root?.enqueueChangeTree(this, 'filteredChanges');
162
- }
163
- else {
164
- this.changes.operations.push(-op);
165
- this.root?.enqueueChangeTree(this, 'changes');
166
- }
167
- }
168
- change(index, operation = OPERATION.ADD) {
169
- const isFiltered = this.isFiltered || (this.metadata?.[index]?.tag !== undefined);
170
- const changeSet = (isFiltered)
171
- ? this.filteredChanges
172
- : this.changes;
173
- const previousOperation = this.indexedOperations[index];
174
- if (!previousOperation || previousOperation === OPERATION.DELETE) {
175
- const op = (!previousOperation)
176
- ? operation
177
- : (previousOperation === OPERATION.DELETE)
178
- ? OPERATION.DELETE_AND_ADD
179
- : operation;
180
- //
181
- // TODO: are DELETE operations being encoded as ADD here ??
182
- //
183
- this.indexedOperations[index] = op;
184
- }
185
- setOperationAtIndex(changeSet, index);
186
- if (isFiltered) {
187
- setOperationAtIndex(this.allFilteredChanges, index);
188
- if (this.root) {
189
- this.root.enqueueChangeTree(this, 'filteredChanges');
190
- this.root.enqueueChangeTree(this, 'allFilteredChanges');
191
- }
192
- }
193
- else {
194
- setOperationAtIndex(this.allChanges, index);
195
- this.root?.enqueueChangeTree(this, 'changes');
196
- }
197
- }
198
- shiftChangeIndexes(shiftIndex) {
199
- //
200
- // Used only during:
201
- //
202
- // - ArraySchema#unshift()
203
- //
204
- const changeSet = (this.isFiltered)
205
- ? this.filteredChanges
206
- : this.changes;
207
- const newIndexedOperations = {};
208
- const newIndexes = {};
209
- for (const index in this.indexedOperations) {
210
- newIndexedOperations[Number(index) + shiftIndex] = this.indexedOperations[index];
211
- newIndexes[Number(index) + shiftIndex] = changeSet.indexes[index];
212
- }
213
- this.indexedOperations = newIndexedOperations;
214
- changeSet.indexes = newIndexes;
215
- changeSet.operations = changeSet.operations.map((index) => index + shiftIndex);
216
- }
217
- shiftAllChangeIndexes(shiftIndex, startIndex = 0) {
218
- //
219
- // Used only during:
220
- //
221
- // - ArraySchema#splice()
222
- //
223
- if (this.filteredChanges !== undefined) {
224
- this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allFilteredChanges);
225
- this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);
226
- }
227
- else {
228
- this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);
229
- }
230
- }
231
- _shiftAllChangeIndexes(shiftIndex, startIndex = 0, changeSet) {
232
- const newIndexes = {};
233
- let newKey = 0;
234
- for (const key in changeSet.indexes) {
235
- newIndexes[newKey++] = changeSet.indexes[key];
236
- }
237
- changeSet.indexes = newIndexes;
238
- for (let i = 0; i < changeSet.operations.length; i++) {
239
- const index = changeSet.operations[i];
240
- if (index > startIndex) {
241
- changeSet.operations[i] = index + shiftIndex;
242
- }
243
- }
244
- }
245
- indexedOperation(index, operation, allChangesIndex = index) {
246
- this.indexedOperations[index] = operation;
247
- if (this.filteredChanges !== undefined) {
248
- setOperationAtIndex(this.allFilteredChanges, allChangesIndex);
249
- setOperationAtIndex(this.filteredChanges, index);
250
- this.root?.enqueueChangeTree(this, 'filteredChanges');
251
- }
252
- else {
253
- setOperationAtIndex(this.allChanges, allChangesIndex);
254
- setOperationAtIndex(this.changes, index);
255
- this.root?.enqueueChangeTree(this, 'changes');
256
- }
257
- }
258
- getType(index) {
259
- return (
260
- //
261
- // Get the child type from parent structure.
262
- // - ["string"] => "string"
263
- // - { map: "string" } => "string"
264
- // - { set: "string" } => "string"
265
- //
266
- this.ref[$childType] || // ArraySchema | MapSchema | SetSchema | CollectionSchema
267
- this.metadata[index].type // Schema
268
- );
269
- }
270
- getChange(index) {
271
- return this.indexedOperations[index];
272
- }
273
- //
274
- // used during `.encode()`
275
- //
276
- getValue(index, isEncodeAll = false) {
277
- //
278
- // `isEncodeAll` param is only used by ArraySchema
279
- //
280
- return this.ref[$getByIndex](index, isEncodeAll);
281
- }
282
- delete(index, operation, allChangesIndex = index) {
283
- if (index === undefined) {
284
- try {
285
- throw new Error(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index '${index}'`);
286
- }
287
- catch (e) {
288
- console.warn(e);
289
- }
290
- return;
291
- }
292
- const changeSet = (this.filteredChanges !== undefined)
293
- ? this.filteredChanges
294
- : this.changes;
295
- this.indexedOperations[index] = operation ?? OPERATION.DELETE;
296
- setOperationAtIndex(changeSet, index);
297
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
298
- const previousValue = this.getValue(index);
299
- // remove `root` reference
300
- if (previousValue && previousValue[$changes]) {
301
- //
302
- // FIXME: this.root is "undefined"
303
- //
304
- // This method is being called at decoding time when a DELETE operation is found.
305
- //
306
- // - This is due to using the concrete Schema class at decoding time.
307
- // - "Reflected" structures do not have this problem.
308
- //
309
- // (The property descriptors should NOT be used at decoding time. only at encoding time.)
310
- //
311
- this.root?.remove(previousValue[$changes]);
312
- }
313
- //
314
- // FIXME: this is looking a ugly and repeated
315
- //
316
- if (this.filteredChanges !== undefined) {
317
- deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
318
- this.root?.enqueueChangeTree(this, 'filteredChanges');
319
- }
320
- else {
321
- this.root?.enqueueChangeTree(this, 'changes');
322
- }
323
- return previousValue;
324
- }
325
- endEncode(changeSetName) {
326
- this.indexedOperations = {};
327
- // clear changeset
328
- this[changeSetName] = createChangeSet();
329
- // ArraySchema and MapSchema have a custom "encode end" method
330
- this.ref[$onEncodeEnd]?.();
331
- // Not a new instance anymore
332
- this.isNew = false;
333
- }
334
- discard(discardAll = false) {
335
- //
336
- // > MapSchema:
337
- // Remove cached key to ensure ADD operations is unsed instead of
338
- // REPLACE in case same key is used on next patches.
339
- //
340
- this.ref[$onEncodeEnd]?.();
341
- this.indexedOperations = {};
342
- this.changes = createChangeSet(this.changes.queueRootNode);
343
- if (this.filteredChanges !== undefined) {
344
- this.filteredChanges = createChangeSet(this.filteredChanges.queueRootNode);
345
- }
346
- if (discardAll) {
347
- // preserve queueRootNode references
348
- this.allChanges = createChangeSet(this.allChanges.queueRootNode);
349
- if (this.allFilteredChanges !== undefined) {
350
- this.allFilteredChanges = createChangeSet(this.allFilteredChanges.queueRootNode);
351
- }
352
- }
353
- }
354
- /**
355
- * Recursively discard all changes from this, and child structures.
356
- * (Used in tests only)
357
- */
358
- discardAll() {
359
- const keys = Object.keys(this.indexedOperations);
360
- for (let i = 0, len = keys.length; i < len; i++) {
361
- const value = this.getValue(Number(keys[i]));
362
- if (value && value[$changes]) {
363
- value[$changes].discardAll();
364
- }
365
- }
366
- this.discard();
367
- }
368
- get changed() {
369
- return (Object.entries(this.indexedOperations).length > 0);
370
- }
371
- checkIsFiltered(parent, parentIndex, isNewChangeTree) {
372
- if (this.root.types.hasFilters) {
373
- //
374
- // At Schema initialization, the "root" structure might not be available
375
- // yet, as it only does once the "Encoder" has been set up.
376
- //
377
- // So the "parent" may be already set without a "root".
378
- //
379
- this._checkFilteredByParent(parent, parentIndex);
380
- if (this.filteredChanges !== undefined) {
381
- this.root?.enqueueChangeTree(this, 'filteredChanges');
382
- if (isNewChangeTree) {
383
- this.root?.enqueueChangeTree(this, 'allFilteredChanges');
384
- }
385
- }
386
- }
387
- if (!this.isFiltered) {
388
- this.root?.enqueueChangeTree(this, 'changes');
389
- if (isNewChangeTree) {
390
- this.root?.enqueueChangeTree(this, 'allChanges');
391
- }
392
- }
393
- }
394
- _checkFilteredByParent(parent, parentIndex) {
395
- // skip if parent is not set
396
- if (!parent) {
397
- return;
398
- }
399
- //
400
- // ArraySchema | MapSchema - get the child type
401
- // (if refType is typeof string, the parentFiltered[key] below will always be invalid)
402
- //
403
- const refType = Metadata.isValidInstance(this.ref)
404
- ? this.ref.constructor
405
- : this.ref[$childType];
406
- let parentChangeTree;
407
- let parentIsCollection = !Metadata.isValidInstance(parent);
408
- if (parentIsCollection) {
409
- parentChangeTree = parent[$changes];
410
- parent = parentChangeTree.parent;
411
- parentIndex = parentChangeTree.parentIndex;
412
- }
413
- else {
414
- parentChangeTree = parent[$changes];
415
- }
416
- const parentConstructor = parent.constructor;
417
- let key = `${this.root.types.getTypeId(refType)}`;
418
- if (parentConstructor) {
419
- key += `-${this.root.types.schemas.get(parentConstructor)}`;
420
- }
421
- key += `-${parentIndex}`;
422
- const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
423
- this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
424
- || this.root.types.parentFiltered[key]
425
- || fieldHasViewTag;
426
- //
427
- // "isFiltered" may not be imedialely available during `change()` due to the instance not being attached to the root yet.
428
- // when it's available, we need to enqueue the "changes" changeset into the "filteredChanges" changeset.
429
- //
430
- if (this.isFiltered) {
431
- this.isVisibilitySharedWithParent = (parentChangeTree.isFiltered &&
432
- typeof (refType) !== "string" &&
433
- !fieldHasViewTag &&
434
- parentIsCollection);
435
- if (!this.filteredChanges) {
436
- this.filteredChanges = createChangeSet();
437
- this.allFilteredChanges = createChangeSet();
438
- }
439
- if (this.changes.operations.length > 0) {
440
- this.changes.operations.forEach((index) => setOperationAtIndex(this.filteredChanges, index));
441
- this.allChanges.operations.forEach((index) => setOperationAtIndex(this.allFilteredChanges, index));
442
- this.changes = createChangeSet();
443
- this.allChanges = createChangeSet();
444
- }
445
- }
446
- }
447
- /**
448
- * Get the immediate parent
449
- */
450
- get parent() {
451
- return this.parentChain?.ref;
452
- }
453
- /**
454
- * Get the immediate parent index
455
- */
456
- get parentIndex() {
457
- return this.parentChain?.index;
458
- }
459
- /**
460
- * Add a parent to the chain
461
- */
462
- addParent(parent, index) {
463
- // Check if this parent already exists in the chain
464
- if (this.hasParent((p, _) => p[$changes] === parent[$changes])) {
465
- // if (this.hasParent((p, i) => p[$changes] === parent[$changes] && i === index)) {
466
- this.parentChain.index = index;
467
- return;
468
- }
469
- this.parentChain = {
470
- ref: parent,
471
- index,
472
- next: this.parentChain
473
- };
474
- }
475
- /**
476
- * Remove a parent from the chain
477
- * @param parent - The parent to remove
478
- * @returns true if parent was removed
479
- */
480
- removeParent(parent = this.parent) {
481
- let current = this.parentChain;
482
- let previous = null;
483
- while (current) {
484
- //
485
- // FIXME: it is required to check against `$changes` here because
486
- // ArraySchema is instance of Proxy
487
- //
488
- if (current.ref[$changes] === parent[$changes]) {
489
- if (previous) {
490
- previous.next = current.next;
491
- }
492
- else {
493
- this.parentChain = current.next;
494
- }
495
- return true;
496
- }
497
- previous = current;
498
- current = current.next;
499
- }
500
- return this.parentChain === undefined;
501
- }
502
- /**
503
- * Find a specific parent in the chain
504
- */
505
- findParent(predicate) {
506
- let current = this.parentChain;
507
- while (current) {
508
- if (predicate(current.ref, current.index)) {
509
- return current;
510
- }
511
- current = current.next;
512
- }
513
- return undefined;
514
- }
515
- /**
516
- * Check if this ChangeTree has a specific parent
517
- */
518
- hasParent(predicate) {
519
- return this.findParent(predicate) !== undefined;
520
- }
521
- /**
522
- * Get all parents as an array (for debugging/testing)
523
- */
524
- getAllParents() {
525
- const parents = [];
526
- let current = this.parentChain;
527
- while (current) {
528
- parents.push({ ref: current.ref, index: current.index });
529
- current = current.next;
530
- }
531
- return parents;
532
- }
533
- }
534
- //# sourceMappingURL=ChangeTree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChangeTree.js","sourceRoot":"","sources":["../../src/encoder/ChangeTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAY,YAAY,EAAY,WAAW,EAAE,MAAM,EAAE,oBAAoB,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC;AAQ7K,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqDvC,SAAS,eAAe,CAAC,aAA8B;IACnD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC;AAC1D,CAAC;AAED,+BAA+B;AAC/B,MAAM,UAAU,oBAAoB;IAChC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,U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AAO,CAAC,KAAK,EAAE,CAAC,CAAC;YACzD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CAEJ","sourcesContent":["import { OPERATION } from \"../encoding/spec\";\nimport { Schema } from \"../Schema\";\nimport { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refId, $refTypeFieldIndexes, $viewFieldIndexes, type $deleteByIndex } from \"../types/symbols\";\n\nimport type { MapSchema } from \"../types/custom/MapSchema\";\nimport type { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { CollectionSchema } from \"../types/custom/CollectionSchema\";\nimport type { SetSchema } from \"../types/custom/SetSchema\";\n\nimport { Root } from \"./Root\";\nimport { Metadata } from \"../Metadata\";\nimport type { EncodeOperation } from \"./EncodeOperation\";\nimport type { DecodeOperation } from \"../decoder/DecodeOperation\";\n\ndeclare global {\n interface Object {\n // FIXME: not a good practice to extend globals here\n [$changes]?: ChangeTree;\n // [$refId]?: number;\n [$encoder]?: EncodeOperation,\n [$decoder]?: DecodeOperation,\n }\n}\n\nexport interface IRef {\n [$changes]?: ChangeTree;\n [$refId]?: number;\n [$getByIndex]?: (index: number, isEncodeAll?: boolean) => any;\n [$deleteByIndex]?: (index: number) => void;\n}\n\nexport type Ref = Schema | ArraySchema | MapSchema | CollectionSchema | SetSchema;\n\nexport type ChangeSetName = \"changes\"\n | \"allChanges\"\n | \"filteredChanges\"\n | \"allFilteredChanges\";\n\nexport interface IndexedOperations {\n [index: number]: OPERATION;\n}\n\n// Linked list node for change trees\nexport interface ChangeTreeNode {\n changeTree: ChangeTree;\n next?: ChangeTreeNode;\n prev?: ChangeTreeNode;\n position: number; // Cached position in the linked list for O(1) lookup\n}\n\n// Linked list for change trees\nexport interface ChangeTreeList {\n next?: ChangeTreeNode;\n tail?: ChangeTreeNode;\n}\n\nexport interface ChangeSet {\n // field index -> operation index\n indexes: { [index: number]: number };\n operations: number[];\n queueRootNode?: ChangeTreeNode; // direct reference to ChangeTreeNode in the linked list\n}\n\nfunction createChangeSet(queueRootNode?: ChangeTreeNode): ChangeSet {\n return { indexes: {}, operations: [], queueRootNode };\n}\n\n// Linked list helper functions\nexport function createChangeTreeList(): ChangeTreeList {\n return { next: undefined, tail: undefined };\n}\n\nexport function setOperationAtIndex(changeSet: ChangeSet, index: number) {\n const operationsIndex = changeSet.indexes[index];\n if (operationsIndex === undefined) {\n changeSet.indexes[index] = changeSet.operations.push(index) - 1;\n } else {\n changeSet.operations[operationsIndex] = index;\n }\n}\n\nexport function deleteOperationAtIndex(changeSet: ChangeSet, index: number | string) {\n let operationsIndex = changeSet.indexes[index as any as number];\n if (operationsIndex === undefined) {\n //\n // if index is not found, we need to find the last operation\n // FIXME: this is not very efficient\n //\n // > See \"should allow consecutive splices (same place)\" tests\n //\n operationsIndex = Object.values(changeSet.indexes).at(-1);\n index = Object.entries(changeSet.indexes).find(([_, value]) => value === operationsIndex)?.[0];\n }\n changeSet.operations[operationsIndex] = undefined;\n delete changeSet.indexes[index as any as number];\n}\n\nexport function debugChangeSet(label: string, changeSet: ChangeSet) {\n let indexes: string[] = [];\n let operations: string[] = [];\n\n for (const index in changeSet.indexes) {\n indexes.push(`\\t${index} => [${changeSet.indexes[index]}]`);\n }\n\n for (let i = 0; i < changeSet.operations.length; i++) {\n const index = changeSet.operations[i];\n if (index !== undefined) {\n operations.push(`\\t[${i}] => ${index}`);\n }\n }\n\n console.log(`${label} =>\\nindexes (${Object.keys(changeSet.indexes).length}) {`);\n console.log(indexes.join(\"\\n\"), \"\\n}\");\n console.log(`operations (${changeSet.operations.filter(op => op !== undefined).length}) {`);\n console.log(operations.join(\"\\n\"), \"\\n}\");\n}\n\nexport interface ParentChain {\n ref: Ref;\n index: number;\n next?: ParentChain;\n}\n\nexport class ChangeTree<T extends Ref = any> {\n ref: T;\n metadata: Metadata;\n\n root?: Root;\n parentChain?: ParentChain; // Linked list for tracking parents\n\n /**\n * Whether this structure is parent of a filtered structure.\n */\n isFiltered: boolean = false;\n isVisibilitySharedWithParent?: boolean; // See test case: 'should not be required to manually call view.add() items to child arrays without @view() tag'\n\n indexedOperations: IndexedOperations = {};\n\n //\n // TODO:\n // try storing the index + operation per item.\n // example: 1024 & 1025 => ADD, 1026 => DELETE\n //\n // => https://chatgpt.com/share/67107d0c-bc20-8004-8583-83b17dd7c196\n //\n changes: ChangeSet = { indexes: {}, operations: [] };\n allChanges: ChangeSet = { indexes: {}, operations: [] };\n filteredChanges: ChangeSet;\n allFilteredChanges: ChangeSet;\n\n indexes: { [index: string]: any }; // TODO: remove this, only used by MapSchema/SetSchema/CollectionSchema (`encodeKeyValueOperation`)\n\n /**\n * Is this a new instance? Used on ArraySchema to determine OPERATION.MOVE_AND_ADD operation.\n */\n isNew = true;\n\n constructor(ref: T) {\n this.ref = ref;\n this.metadata = (ref.constructor as typeof Schema)[Symbol.metadata];\n\n //\n // Does this structure have \"filters\" declared?\n //\n if (this.metadata?.[$viewFieldIndexes]) {\n this.allFilteredChanges = { indexes: {}, operations: [] };\n this.filteredChanges = { indexes: {}, operations: [] };\n }\n }\n\n setRoot(root: Root) {\n this.root = root;\n\n const isNewChangeTree = this.root.add(this);\n\n this.checkIsFiltered(this.parent, this.parentIndex, isNewChangeTree);\n\n // Recursively set root on child structures\n if (isNewChangeTree) {\n this.forEachChild((child, _) => {\n if (child.root !== root) {\n child.setRoot(root);\n } else {\n root.add(child); // increment refCount\n }\n });\n }\n }\n\n setParent(\n parent: Ref,\n root?: Root,\n parentIndex?: number,\n ) {\n this.addParent(parent, parentIndex);\n\n // avoid setting parents with empty `root`\n if (!root) { return; }\n\n const isNewChangeTree = root.add(this);\n\n // skip if parent is already set\n if (root !== this.root) {\n this.root = root;\n this.checkIsFiltered(parent, parentIndex, isNewChangeTree);\n }\n\n // assign same parent on child structures\n if (isNewChangeTree) {\n //\n // assign same parent on child structures\n //\n this.forEachChild((child, index) => {\n if (child.root === root) {\n //\n // re-assigning a child of the same root, move it next to parent\n // so encoding order is preserved\n //\n root.add(child);\n root.moveNextToParent(child);\n return;\n }\n child.setParent(this.ref, root, index);\n });\n }\n }\n\n forEachChild(callback: (change: ChangeTree, at: any) => void) {\n //\n // assign same parent on child structures\n //\n if ((this.ref as any)[$childType]) {\n if (typeof ((this.ref as any)[$childType]) !== \"string\") {\n // MapSchema / ArraySchema, etc.\n for (const [key, value] of (this.ref as MapSchema).entries()) {\n if (!value) { continue; } // sparse arrays can have undefined values\n callback(value[$changes], this.indexes?.[key] ?? key);\n };\n }\n\n } else {\n for (const index of this.metadata?.[$refTypeFieldIndexes] ?? []) {\n const field = this.metadata[index as any as number];\n const value = this.ref[field.name as keyof Ref];\n if (!value) { continue; }\n callback(value[$changes], index);\n }\n }\n }\n\n operation(op: OPERATION) {\n // operations without index use negative values to represent them\n // this is checked during .encode() time.\n if (this.filteredChanges !== undefined) {\n this.filteredChanges.operations.push(-op);\n this.root?.enqueueChangeTree(this, 'filteredChanges');\n\n } else {\n this.changes.operations.push(-op);\n this.root?.enqueueChangeTree(this, 'changes');\n }\n }\n\n change(index: number, operation: OPERATION = OPERATION.ADD) {\n const isFiltered = this.isFiltered || (this.metadata?.[index]?.tag !== undefined);\n const changeSet = (isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const previousOperation = this.indexedOperations[index];\n if (!previousOperation || previousOperation === OPERATION.DELETE) {\n const op = (!previousOperation)\n ? operation\n : (previousOperation === OPERATION.DELETE)\n ? OPERATION.DELETE_AND_ADD\n : operation\n //\n // TODO: are DELETE operations being encoded as ADD here ??\n //\n this.indexedOperations[index] = op;\n }\n\n setOperationAtIndex(changeSet, index);\n\n if (isFiltered) {\n setOperationAtIndex(this.allFilteredChanges, index);\n\n if (this.root) {\n this.root.enqueueChangeTree(this, 'filteredChanges');\n this.root.enqueueChangeTree(this, 'allFilteredChanges');\n }\n\n } else {\n setOperationAtIndex(this.allChanges, index);\n this.root?.enqueueChangeTree(this, 'changes');\n }\n }\n\n shiftChangeIndexes(shiftIndex: number) {\n //\n // Used only during:\n //\n // - ArraySchema#unshift()\n //\n const changeSet = (this.isFiltered)\n ? this.filteredChanges\n : this.changes;\n\n const newIndexedOperations: any = {};\n const newIndexes: { [index: number]: number } = {};\n for (const index in this.indexedOperations) {\n newIndexedOperations[Number(index) + shiftIndex] = this.indexedOperations[index];\n newIndexes[Number(index) + shiftIndex] = changeSet.indexes[index];\n }\n this.indexedOperations = newIndexedOperations;\n changeSet.indexes = newIndexes;\n\n changeSet.operations = changeSet.operations.map((index) => index + shiftIndex);\n }\n\n shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0) {\n //\n // Used only during:\n //\n // - ArraySchema#splice()\n //\n if (this.filteredChanges !== undefined) {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allFilteredChanges);\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n\n } else {\n this._shiftAllChangeIndexes(shiftIndex, startIndex, this.allChanges);\n }\n }\n\n private _shiftAllChangeIndexes(shiftIndex: number, startIndex: number = 0, changeSet: ChangeSet) {\n const newIndexes: { [index: number]: number } = {};\n let newKey = 0;\n for (const key in changeSet.indexes) {\n newIndexes[newKey++] = changeSet.indexes[key];\n }\n changeSet.indexes = newIndexes;\n\n for (let i = 0; i < changeSet.operations.length; i++) {\n const index = changeSet.operations[i];\n if (index > startIndex) {\n changeSet.operations[i] = index + shiftIndex;\n }\n }\n }\n\n indexedOperation(index: number, operation: OPERATION, allChangesIndex: number = index) {\n this.indexedOperations[index] = operation;\n\n if (this.filteredChanges !== undefined) {\n setOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n setOperationAtIndex(this.filteredChanges, index);\n this.root?.enqueueChangeTree(this, 'filteredChanges');\n\n } else {\n setOperationAtIndex(this.allChanges, allChangesIndex);\n setOperationAtIndex(this.changes, index);\n this.root?.enqueueChangeTree(this, 'changes');\n }\n }\n\n getType(index?: number) {\n return (\n //\n // Get the child type from parent structure.\n // - [\"string\"] => \"string\"\n // - { map: \"string\" } => \"string\"\n // - { set: \"string\" } => \"string\"\n //\n (this.ref as any)[$childType] || // ArraySchema | MapSchema | SetSchema | CollectionSchema\n this.metadata[index].type // Schema\n );\n }\n\n getChange(index: number) {\n return this.indexedOperations[index];\n }\n\n //\n // used during `.encode()`\n //\n getValue(index: number, isEncodeAll: boolean = false) {\n //\n // `isEncodeAll` param is only used by ArraySchema\n //\n return (this.ref as any)[$getByIndex](index, isEncodeAll);\n }\n\n delete(index: number, operation?: OPERATION, allChangesIndex = index) {\n if (index === undefined) {\n try {\n throw new Error(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index '${index}'`);\n } catch (e) {\n console.warn(e);\n }\n return;\n }\n\n const changeSet = (this.filteredChanges !== undefined)\n ? this.filteredChanges\n : this.changes;\n\n this.indexedOperations[index] = operation ?? OPERATION.DELETE;\n setOperationAtIndex(changeSet, index);\n deleteOperationAtIndex(this.allChanges, allChangesIndex);\n\n const previousValue = this.getValue(index);\n\n // remove `root` reference\n if (previousValue && previousValue[$changes]) {\n //\n // FIXME: this.root is \"undefined\"\n //\n // This method is being called at decoding time when a DELETE operation is found.\n //\n // - This is due to using the concrete Schema class at decoding time.\n // - \"Reflected\" structures do not have this problem.\n //\n // (The property descriptors should NOT be used at decoding time. only at encoding time.)\n //\n this.root?.remove(previousValue[$changes]);\n }\n\n //\n // FIXME: this is looking a ugly and repeated\n //\n if (this.filteredChanges !== undefined) {\n deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);\n this.root?.enqueueChangeTree(this, 'filteredChanges');\n\n } else {\n this.root?.enqueueChangeTree(this, 'changes');\n }\n\n return previousValue;\n }\n\n endEncode(changeSetName: ChangeSetName) {\n this.indexedOperations = {};\n\n // clear changeset\n this[changeSetName] = createChangeSet();\n\n // ArraySchema and MapSchema have a custom \"encode end\" method\n (this.ref as any)[$onEncodeEnd]?.();\n\n // Not a new instance anymore\n this.isNew = false;\n }\n\n discard(discardAll: boolean = false) {\n //\n // > MapSchema:\n // Remove cached key to ensure ADD operations is unsed instead of\n // REPLACE in case same key is used on next patches.\n //\n (this.ref as any)[$onEncodeEnd]?.();\n\n this.indexedOperations = {};\n this.changes = createChangeSet(this.changes.queueRootNode);\n\n if (this.filteredChanges !== undefined) {\n this.filteredChanges = createChangeSet(this.filteredChanges.queueRootNode);\n }\n\n if (discardAll) {\n // preserve queueRootNode references\n this.allChanges = createChangeSet(this.allChanges.queueRootNode);\n\n if (this.allFilteredChanges !== undefined) {\n this.allFilteredChanges = createChangeSet(this.allFilteredChanges.queueRootNode);\n }\n }\n }\n\n /**\n * Recursively discard all changes from this, and child structures.\n * (Used in tests only)\n */\n discardAll() {\n const keys = Object.keys(this.indexedOperations);\n for (let i = 0, len = keys.length; i < len; i++) {\n const value = this.getValue(Number(keys[i]));\n\n if (value && value[$changes]) {\n value[$changes].discardAll();\n }\n }\n\n this.discard();\n }\n\n get changed() {\n return (Object.entries(this.indexedOperations).length > 0);\n }\n\n protected checkIsFiltered(parent: Ref, parentIndex: number, isNewChangeTree: boolean) {\n if (this.root.types.hasFilters) {\n //\n // At Schema initialization, the \"root\" structure might not be available\n // yet, as it only does once the \"Encoder\" has been set up.\n //\n // So the \"parent\" may be already set without a \"root\".\n //\n this._checkFilteredByParent(parent, parentIndex);\n\n if (this.filteredChanges !== undefined) {\n this.root?.enqueueChangeTree(this, 'filteredChanges');\n\n if (isNewChangeTree) {\n this.root?.enqueueChangeTree(this, 'allFilteredChanges');\n }\n }\n }\n\n if (!this.isFiltered) {\n this.root?.enqueueChangeTree(this, 'changes');\n\n if (isNewChangeTree) {\n this.root?.enqueueChangeTree(this, 'allChanges');\n }\n }\n }\n\n protected _checkFilteredByParent(parent: Ref, parentIndex: number) {\n // skip if parent is not set\n if (!parent) { return; }\n\n //\n // ArraySchema | MapSchema - get the child type\n // (if refType is typeof string, the parentFiltered[key] below will always be invalid)\n //\n const refType = Metadata.isValidInstance(this.ref)\n ? this.ref.constructor\n : (this.ref as any)[$childType];\n\n let parentChangeTree: ChangeTree;\n\n let parentIsCollection = !Metadata.isValidInstance(parent);\n if (parentIsCollection) {\n parentChangeTree = parent[$changes];\n parent = parentChangeTree.parent;\n parentIndex = parentChangeTree.parentIndex;\n\n } else {\n parentChangeTree = parent[$changes]\n }\n\n const parentConstructor = parent.constructor as typeof Schema;\n\n let key = `${this.root.types.getTypeId(refType as typeof Schema)}`;\n if (parentConstructor) {\n key += `-${this.root.types.schemas.get(parentConstructor)}`;\n }\n key += `-${parentIndex}`;\n\n const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);\n\n this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered\n || this.root.types.parentFiltered[key]\n || fieldHasViewTag;\n\n //\n // \"isFiltered\" may not be imedialely available during `change()` due to the instance not being attached to the root yet.\n // when it's available, we need to enqueue the \"changes\" changeset into the \"filteredChanges\" changeset.\n //\n if (this.isFiltered) {\n\n this.isVisibilitySharedWithParent = (\n parentChangeTree.isFiltered &&\n typeof (refType) !== \"string\" &&\n !fieldHasViewTag &&\n parentIsCollection\n );\n\n if (!this.filteredChanges) {\n this.filteredChanges = createChangeSet();\n this.allFilteredChanges = createChangeSet();\n }\n\n if (this.changes.operations.length > 0) {\n this.changes.operations.forEach((index) =>\n setOperationAtIndex(this.filteredChanges, index));\n\n this.allChanges.operations.forEach((index) =>\n setOperationAtIndex(this.allFilteredChanges, index));\n\n this.changes = createChangeSet();\n this.allChanges = createChangeSet();\n }\n }\n }\n\n /**\n * Get the immediate parent\n */\n get parent(): Ref | undefined {\n return this.parentChain?.ref;\n }\n\n /**\n * Get the immediate parent index\n */\n get parentIndex(): number | undefined {\n return this.parentChain?.index;\n }\n\n /**\n * Add a parent to the chain\n */\n addParent(parent: Ref, index: number) {\n // Check if this parent already exists in the chain\n if (this.hasParent((p, _) => p[$changes] === parent[$changes])) {\n // if (this.hasParent((p, i) => p[$changes] === parent[$changes] && i === index)) {\n this.parentChain.index = index;\n return;\n }\n\n this.parentChain = {\n ref: parent,\n index,\n next: this.parentChain\n };\n }\n\n /**\n * Remove a parent from the chain\n * @param parent - The parent to remove\n * @returns true if parent was removed\n */\n removeParent(parent: Ref = this.parent): boolean {\n let current = this.parentChain;\n let previous = null;\n while (current) {\n //\n // FIXME: it is required to check against `$changes` here because\n // ArraySchema is instance of Proxy\n //\n if (current.ref[$changes] === parent[$changes]) {\n if (previous) {\n previous.next = current.next;\n } else {\n this.parentChain = current.next;\n }\n return true;\n }\n previous = current;\n current = current.next;\n }\n return this.parentChain === undefined;\n }\n\n /**\n * Find a specific parent in the chain\n */\n findParent(predicate: (parent: Ref, index: number) => boolean): ParentChain | undefined {\n let current = this.parentChain;\n while (current) {\n if (predicate(current.ref, current.index)) {\n return current;\n }\n current = current.next;\n }\n return undefined;\n }\n\n /**\n * Check if this ChangeTree has a specific parent\n */\n hasParent(predicate: (parent: Ref, index: number) => boolean): boolean {\n return this.findParent(predicate) !== undefined;\n }\n\n /**\n * Get all parents as an array (for debugging/testing)\n */\n getAllParents(): Array<{ ref: Ref, index: number }> {\n const parents: Array<{ ref: Ref, index: number }> = [];\n let current = this.parentChain;\n while (current) {\n parents.push({ ref: current.ref, index: current.index });\n current = current.next;\n }\n return parents;\n }\n\n}\n"]}