@colyseus/schema 4.0.2 → 4.0.4

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 +18 -43
  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/{cjs/index.cjs → index.cjs} +8 -34
  28. package/build/index.cjs.map +1 -0
  29. package/build/index.d.ts +32 -0
  30. package/build/{umd/index.js → index.js} +8 -34
  31. package/build/{esm/index.mjs → index.mjs} +8 -34
  32. package/build/index.mjs.map +1 -0
  33. package/{lib → build}/types/HelperTypes.d.ts +6 -6
  34. package/{lib → build}/types/TypeContext.d.ts +1 -1
  35. package/{lib/src → build}/types/custom/ArraySchema.d.ts +8 -8
  36. package/{lib/src → build}/types/custom/CollectionSchema.d.ts +7 -7
  37. package/{lib → build}/types/custom/MapSchema.d.ts +7 -7
  38. package/{lib/src → build}/types/custom/SetSchema.d.ts +7 -7
  39. package/{lib/src → build}/types/registry.d.ts +2 -2
  40. package/{lib → build}/utils.d.ts +1 -1
  41. package/package.json +9 -10
  42. package/src/Metadata.ts +5 -5
  43. package/src/Reflection.ts +7 -7
  44. package/src/Schema.ts +11 -11
  45. package/src/annotations.ts +13 -13
  46. package/src/codegen/api.ts +3 -3
  47. package/src/codegen/cli.ts +2 -2
  48. package/src/codegen/languages/cpp.ts +2 -2
  49. package/src/codegen/languages/csharp.ts +3 -3
  50. package/src/codegen/languages/haxe.ts +2 -2
  51. package/src/codegen/languages/java.ts +2 -2
  52. package/src/codegen/languages/js.ts +2 -2
  53. package/src/codegen/languages/lua.ts +2 -2
  54. package/src/codegen/languages/ts.ts +2 -2
  55. package/src/codegen/parser.ts +6 -1
  56. package/src/decoder/DecodeOperation.ts +14 -14
  57. package/src/decoder/Decoder.ts +11 -11
  58. package/src/decoder/ReferenceTracker.ts +8 -8
  59. package/src/decoder/strategy/Callbacks.ts +27 -53
  60. package/src/decoder/strategy/RawChanges.ts +2 -2
  61. package/src/decoder/strategy/getDecoderStateCallbacks.ts +10 -10
  62. package/src/encoder/ChangeTree.ts +13 -13
  63. package/src/encoder/EncodeOperation.ts +9 -9
  64. package/src/encoder/Encoder.ts +10 -10
  65. package/src/encoder/Root.ts +4 -4
  66. package/src/encoder/StateView.ts +7 -7
  67. package/src/encoding/assert.ts +6 -6
  68. package/src/encoding/decode.ts +1 -1
  69. package/src/encoding/encode.ts +1 -1
  70. package/src/index.ts +27 -27
  71. package/src/types/HelperTypes.ts +6 -6
  72. package/src/types/TypeContext.ts +3 -3
  73. package/src/types/custom/ArraySchema.ts +11 -11
  74. package/src/types/custom/CollectionSchema.ts +9 -9
  75. package/src/types/custom/MapSchema.ts +10 -10
  76. package/src/types/custom/SetSchema.ts +9 -9
  77. package/src/types/registry.ts +3 -3
  78. package/src/utils.ts +3 -3
  79. package/src/v3_bench.ts +1 -1
  80. package/build/cjs/index.cjs.map +0 -1
  81. package/build/esm/index.mjs.map +0 -1
  82. package/lib/Metadata.js +0 -256
  83. package/lib/Metadata.js.map +0 -1
  84. package/lib/Reflection.js +0 -179
  85. package/lib/Reflection.js.map +0 -1
  86. package/lib/Schema.js +0 -352
  87. package/lib/Schema.js.map +0 -1
  88. package/lib/annotations.d.ts +0 -109
  89. package/lib/annotations.js +0 -473
  90. package/lib/annotations.js.map +0 -1
  91. package/lib/bench_encode.d.ts +0 -1
  92. package/lib/bench_encode.js +0 -91
  93. package/lib/bench_encode.js.map +0 -1
  94. package/lib/benchmark.d.ts +0 -1
  95. package/lib/benchmark.js +0 -218
  96. package/lib/benchmark.js.map +0 -1
  97. package/lib/codegen/api.js +0 -56
  98. package/lib/codegen/api.js.map +0 -1
  99. package/lib/codegen/argv.js +0 -39
  100. package/lib/codegen/argv.js.map +0 -1
  101. package/lib/codegen/cli.js +0 -58
  102. package/lib/codegen/cli.js.map +0 -1
  103. package/lib/codegen/languages/cpp.d.ts +0 -3
  104. package/lib/codegen/languages/cpp.js +0 -258
  105. package/lib/codegen/languages/cpp.js.map +0 -1
  106. package/lib/codegen/languages/csharp.d.ts +0 -4
  107. package/lib/codegen/languages/csharp.js +0 -154
  108. package/lib/codegen/languages/csharp.js.map +0 -1
  109. package/lib/codegen/languages/haxe.d.ts +0 -3
  110. package/lib/codegen/languages/haxe.js +0 -100
  111. package/lib/codegen/languages/haxe.js.map +0 -1
  112. package/lib/codegen/languages/java.js +0 -100
  113. package/lib/codegen/languages/java.js.map +0 -1
  114. package/lib/codegen/languages/js.d.ts +0 -3
  115. package/lib/codegen/languages/js.js +0 -101
  116. package/lib/codegen/languages/js.js.map +0 -1
  117. package/lib/codegen/languages/lua.d.ts +0 -3
  118. package/lib/codegen/languages/lua.js +0 -103
  119. package/lib/codegen/languages/lua.js.map +0 -1
  120. package/lib/codegen/languages/ts.d.ts +0 -3
  121. package/lib/codegen/languages/ts.js +0 -116
  122. package/lib/codegen/languages/ts.js.map +0 -1
  123. package/lib/codegen/parser.js +0 -327
  124. package/lib/codegen/parser.js.map +0 -1
  125. package/lib/codegen/types.js +0 -142
  126. package/lib/codegen/types.js.map +0 -1
  127. package/lib/decoder/DecodeOperation.js +0 -248
  128. package/lib/decoder/DecodeOperation.js.map +0 -1
  129. package/lib/decoder/Decoder.d.ts +0 -21
  130. package/lib/decoder/Decoder.js +0 -114
  131. package/lib/decoder/Decoder.js.map +0 -1
  132. package/lib/decoder/ReferenceTracker.js +0 -135
  133. package/lib/decoder/ReferenceTracker.js.map +0 -1
  134. package/lib/decoder/strategy/Callbacks.js +0 -336
  135. package/lib/decoder/strategy/Callbacks.js.map +0 -1
  136. package/lib/decoder/strategy/RawChanges.js +0 -4
  137. package/lib/decoder/strategy/RawChanges.js.map +0 -1
  138. package/lib/decoder/strategy/getDecoderStateCallbacks.js +0 -274
  139. package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
  140. package/lib/encoder/ChangeTree.js +0 -534
  141. package/lib/encoder/ChangeTree.js.map +0 -1
  142. package/lib/encoder/EncodeOperation.js +0 -132
  143. package/lib/encoder/EncodeOperation.js.map +0 -1
  144. package/lib/encoder/Encoder.js +0 -204
  145. package/lib/encoder/Encoder.js.map +0 -1
  146. package/lib/encoder/Root.d.ts +0 -28
  147. package/lib/encoder/Root.js +0 -229
  148. package/lib/encoder/Root.js.map +0 -1
  149. package/lib/encoder/StateView.d.ts +0 -34
  150. package/lib/encoder/StateView.js +0 -279
  151. package/lib/encoder/StateView.js.map +0 -1
  152. package/lib/encoding/assert.d.ts +0 -10
  153. package/lib/encoding/assert.js +0 -49
  154. package/lib/encoding/assert.js.map +0 -1
  155. package/lib/encoding/decode.d.ts +0 -67
  156. package/lib/encoding/decode.js +0 -217
  157. package/lib/encoding/decode.js.map +0 -1
  158. package/lib/encoding/encode.d.ts +0 -40
  159. package/lib/encoding/encode.js +0 -279
  160. package/lib/encoding/encode.js.map +0 -1
  161. package/lib/encoding/spec.js +0 -26
  162. package/lib/encoding/spec.js.map +0 -1
  163. package/lib/index.d.ts +0 -32
  164. package/lib/index.js +0 -39
  165. package/lib/index.js.map +0 -1
  166. package/lib/src/Metadata.d.ts +0 -49
  167. package/lib/src/Metadata.js +0 -256
  168. package/lib/src/Metadata.js.map +0 -1
  169. package/lib/src/Reflection.d.ts +0 -71
  170. package/lib/src/Reflection.js +0 -179
  171. package/lib/src/Reflection.js.map +0 -1
  172. package/lib/src/Schema.d.ts +0 -86
  173. package/lib/src/Schema.js +0 -352
  174. package/lib/src/Schema.js.map +0 -1
  175. package/lib/src/annotations.js +0 -473
  176. package/lib/src/annotations.js.map +0 -1
  177. package/lib/src/bench_encode.d.ts +0 -1
  178. package/lib/src/bench_encode.js +0 -91
  179. package/lib/src/bench_encode.js.map +0 -1
  180. package/lib/src/codegen/api.d.ts +0 -7
  181. package/lib/src/codegen/api.js +0 -56
  182. package/lib/src/codegen/api.js.map +0 -1
  183. package/lib/src/codegen/argv.d.ts +0 -6
  184. package/lib/src/codegen/argv.js +0 -39
  185. package/lib/src/codegen/argv.js.map +0 -1
  186. package/lib/src/codegen/cli.d.ts +0 -1
  187. package/lib/src/codegen/cli.js +0 -58
  188. package/lib/src/codegen/cli.js.map +0 -1
  189. package/lib/src/codegen/languages/cpp.d.ts +0 -3
  190. package/lib/src/codegen/languages/cpp.js +0 -258
  191. package/lib/src/codegen/languages/cpp.js.map +0 -1
  192. package/lib/src/codegen/languages/csharp.d.ts +0 -4
  193. package/lib/src/codegen/languages/csharp.js +0 -154
  194. package/lib/src/codegen/languages/csharp.js.map +0 -1
  195. package/lib/src/codegen/languages/haxe.d.ts +0 -3
  196. package/lib/src/codegen/languages/haxe.js +0 -100
  197. package/lib/src/codegen/languages/haxe.js.map +0 -1
  198. package/lib/src/codegen/languages/java.d.ts +0 -6
  199. package/lib/src/codegen/languages/java.js +0 -100
  200. package/lib/src/codegen/languages/java.js.map +0 -1
  201. package/lib/src/codegen/languages/js.d.ts +0 -3
  202. package/lib/src/codegen/languages/js.js +0 -101
  203. package/lib/src/codegen/languages/js.js.map +0 -1
  204. package/lib/src/codegen/languages/lua.d.ts +0 -3
  205. package/lib/src/codegen/languages/lua.js +0 -103
  206. package/lib/src/codegen/languages/lua.js.map +0 -1
  207. package/lib/src/codegen/languages/ts.d.ts +0 -3
  208. package/lib/src/codegen/languages/ts.js +0 -116
  209. package/lib/src/codegen/languages/ts.js.map +0 -1
  210. package/lib/src/codegen/parser.d.ts +0 -13
  211. package/lib/src/codegen/parser.js +0 -327
  212. package/lib/src/codegen/parser.js.map +0 -1
  213. package/lib/src/codegen/types.d.ts +0 -52
  214. package/lib/src/codegen/types.js +0 -142
  215. package/lib/src/codegen/types.js.map +0 -1
  216. package/lib/src/decoder/DecodeOperation.d.ts +0 -23
  217. package/lib/src/decoder/DecodeOperation.js +0 -248
  218. package/lib/src/decoder/DecodeOperation.js.map +0 -1
  219. package/lib/src/decoder/Decoder.js +0 -114
  220. package/lib/src/decoder/Decoder.js.map +0 -1
  221. package/lib/src/decoder/ReferenceTracker.d.ts +0 -25
  222. package/lib/src/decoder/ReferenceTracker.js +0 -135
  223. package/lib/src/decoder/ReferenceTracker.js.map +0 -1
  224. package/lib/src/decoder/strategy/Callbacks.d.ts +0 -154
  225. package/lib/src/decoder/strategy/Callbacks.js +0 -336
  226. package/lib/src/decoder/strategy/Callbacks.js.map +0 -1
  227. package/lib/src/decoder/strategy/RawChanges.d.ts +0 -3
  228. package/lib/src/decoder/strategy/RawChanges.js +0 -4
  229. package/lib/src/decoder/strategy/RawChanges.js.map +0 -1
  230. package/lib/src/decoder/strategy/getDecoderStateCallbacks.d.ts +0 -76
  231. package/lib/src/decoder/strategy/getDecoderStateCallbacks.js +0 -274
  232. package/lib/src/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
  233. package/lib/src/encoder/ChangeTree.d.ts +0 -135
  234. package/lib/src/encoder/ChangeTree.js +0 -534
  235. package/lib/src/encoder/ChangeTree.js.map +0 -1
  236. package/lib/src/encoder/EncodeOperation.d.ts +0 -22
  237. package/lib/src/encoder/EncodeOperation.js +0 -132
  238. package/lib/src/encoder/EncodeOperation.js.map +0 -1
  239. package/lib/src/encoder/Encoder.d.ts +0 -22
  240. package/lib/src/encoder/Encoder.js +0 -204
  241. package/lib/src/encoder/Encoder.js.map +0 -1
  242. package/lib/src/encoder/Root.js +0 -229
  243. package/lib/src/encoder/Root.js.map +0 -1
  244. package/lib/src/encoder/StateView.js +0 -279
  245. package/lib/src/encoder/StateView.js.map +0 -1
  246. package/lib/src/encoding/assert.js +0 -49
  247. package/lib/src/encoding/assert.js.map +0 -1
  248. package/lib/src/encoding/decode.js +0 -217
  249. package/lib/src/encoding/decode.js.map +0 -1
  250. package/lib/src/encoding/encode.js +0 -279
  251. package/lib/src/encoding/encode.js.map +0 -1
  252. package/lib/src/encoding/spec.d.ts +0 -24
  253. package/lib/src/encoding/spec.js +0 -26
  254. package/lib/src/encoding/spec.js.map +0 -1
  255. package/lib/src/index.d.ts +0 -32
  256. package/lib/src/index.js +0 -39
  257. package/lib/src/index.js.map +0 -1
  258. package/lib/src/symbol.shim.js +0 -3
  259. package/lib/src/symbol.shim.js.map +0 -1
  260. package/lib/src/types/HelperTypes.d.ts +0 -77
  261. package/lib/src/types/HelperTypes.js +0 -2
  262. package/lib/src/types/HelperTypes.js.map +0 -1
  263. package/lib/src/types/TypeContext.d.ts +0 -31
  264. package/lib/src/types/TypeContext.js +0 -143
  265. package/lib/src/types/TypeContext.js.map +0 -1
  266. package/lib/src/types/custom/ArraySchema.js +0 -733
  267. package/lib/src/types/custom/ArraySchema.js.map +0 -1
  268. package/lib/src/types/custom/CollectionSchema.js +0 -170
  269. package/lib/src/types/custom/CollectionSchema.js.map +0 -1
  270. package/lib/src/types/custom/MapSchema.d.ts +0 -51
  271. package/lib/src/types/custom/MapSchema.js +0 -222
  272. package/lib/src/types/custom/MapSchema.js.map +0 -1
  273. package/lib/src/types/custom/SetSchema.js +0 -178
  274. package/lib/src/types/custom/SetSchema.js.map +0 -1
  275. package/lib/src/types/registry.js +0 -30
  276. package/lib/src/types/registry.js.map +0 -1
  277. package/lib/src/types/symbols.js +0 -34
  278. package/lib/src/types/symbols.js.map +0 -1
  279. package/lib/src/types/utils.js +0 -13
  280. package/lib/src/types/utils.js.map +0 -1
  281. package/lib/src/utils.d.ts +0 -13
  282. package/lib/src/utils.js +0 -49
  283. package/lib/src/utils.js.map +0 -1
  284. package/lib/src/v3_bench.js +0 -128
  285. package/lib/src/v3_bench.js.map +0 -1
  286. package/lib/symbol.shim.d.ts +0 -6
  287. package/lib/symbol.shim.js +0 -3
  288. package/lib/symbol.shim.js.map +0 -1
  289. package/lib/types/HelperTypes.js +0 -2
  290. package/lib/types/HelperTypes.js.map +0 -1
  291. package/lib/types/TypeContext.js +0 -143
  292. package/lib/types/TypeContext.js.map +0 -1
  293. package/lib/types/custom/ArraySchema.d.ts +0 -270
  294. package/lib/types/custom/ArraySchema.js +0 -733
  295. package/lib/types/custom/ArraySchema.js.map +0 -1
  296. package/lib/types/custom/CollectionSchema.d.ts +0 -51
  297. package/lib/types/custom/CollectionSchema.js +0 -170
  298. package/lib/types/custom/CollectionSchema.js.map +0 -1
  299. package/lib/types/custom/MapSchema.js +0 -222
  300. package/lib/types/custom/MapSchema.js.map +0 -1
  301. package/lib/types/custom/SetSchema.d.ts +0 -48
  302. package/lib/types/custom/SetSchema.js +0 -178
  303. package/lib/types/custom/SetSchema.js.map +0 -1
  304. package/lib/types/registry.d.ts +0 -16
  305. package/lib/types/registry.js +0 -30
  306. package/lib/types/registry.js.map +0 -1
  307. package/lib/types/symbols.d.ts +0 -33
  308. package/lib/types/symbols.js +0 -34
  309. package/lib/types/symbols.js.map +0 -1
  310. package/lib/types/utils.d.ts +0 -1
  311. package/lib/types/utils.js +0 -13
  312. package/lib/types/utils.js.map +0 -1
  313. package/lib/utils.js +0 -49
  314. package/lib/utils.js.map +0 -1
  315. package/lib/v3_bench.d.ts +0 -1
  316. package/lib/v3_bench.js +0 -128
  317. package/lib/v3_bench.js.map +0 -1
  318. /package/{lib → build}/codegen/api.d.ts +0 -0
  319. /package/{lib → build}/codegen/argv.d.ts +0 -0
  320. /package/{lib → build}/codegen/cli.d.ts +0 -0
  321. /package/{lib → build}/codegen/types.d.ts +0 -0
  322. /package/{lib → build}/encoding/spec.d.ts +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
package/lib/Schema.js DELETED
@@ -1,352 +0,0 @@
1
- var _a, _b;
2
- import { OPERATION } from './encoding/spec';
3
- import { DEFAULT_VIEW_TAG } from "./annotations";
4
- import { ChangeTree } from './encoder/ChangeTree';
5
- import { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $refId, $track } from './types/symbols';
6
- import { encodeSchemaOperation } from './encoder/EncodeOperation';
7
- import { decodeSchemaOperation } from './decoder/DecodeOperation';
8
- import { getIndent } from './utils';
9
- /**
10
- * Schema encoder / decoder
11
- */
12
- export class Schema {
13
- static { this[_a] = encodeSchemaOperation; }
14
- static { this[_b] = decodeSchemaOperation; }
15
- /**
16
- * Assign the property descriptors required to track changes on this instance.
17
- * @param instance
18
- */
19
- static initialize(instance) {
20
- Object.defineProperty(instance, $changes, {
21
- value: new ChangeTree(instance),
22
- enumerable: false,
23
- writable: true
24
- });
25
- Object.defineProperties(instance, instance.constructor[Symbol.metadata]?.[$descriptors] || {});
26
- }
27
- static is(type) {
28
- return typeof (type[Symbol.metadata]) === "object";
29
- }
30
- /**
31
- * Track property changes
32
- */
33
- static [(Symbol.metadata, _a = $encoder, _b = $decoder, $track)](changeTree, index, operation = OPERATION.ADD) {
34
- changeTree.change(index, operation);
35
- }
36
- /**
37
- * Determine if a property must be filtered.
38
- * - If returns false, the property is NOT going to be encoded.
39
- * - If returns true, the property is going to be encoded.
40
- *
41
- * Encoding with "filters" happens in two steps:
42
- * - First, the encoder iterates over all "not owned" properties and encodes them.
43
- * - Then, the encoder iterates over all "owned" properties per instance and encodes them.
44
- */
45
- static [$filter](ref, index, view) {
46
- const metadata = ref.constructor[Symbol.metadata];
47
- const tag = metadata[index]?.tag;
48
- if (view === undefined) {
49
- // shared pass/encode: encode if doesn't have a tag
50
- return tag === undefined;
51
- }
52
- else if (tag === undefined) {
53
- // view pass: no tag
54
- return true;
55
- }
56
- else if (tag === DEFAULT_VIEW_TAG) {
57
- // view pass: default tag
58
- return view.isChangeTreeVisible(ref[$changes]);
59
- }
60
- else {
61
- // view pass: custom tag
62
- const tags = view.tags?.get(ref[$changes]);
63
- return tags && tags.has(tag);
64
- }
65
- }
66
- // allow inherited classes to have a constructor
67
- constructor(arg) {
68
- //
69
- // inline
70
- // Schema.initialize(this);
71
- //
72
- Schema.initialize(this);
73
- //
74
- // Assign initial values
75
- //
76
- if (arg) {
77
- Object.assign(this, arg);
78
- }
79
- }
80
- /**
81
- * Assign properties to the instance.
82
- * @param props Properties to assign to the instance
83
- * @returns
84
- */
85
- assign(props) {
86
- Object.assign(this, props);
87
- return this;
88
- }
89
- /**
90
- * Restore the instance from JSON data.
91
- * @param jsonData JSON data to restore the instance from
92
- * @returns
93
- */
94
- restore(jsonData) {
95
- const metadata = this.constructor[Symbol.metadata];
96
- for (const fieldIndex in metadata) {
97
- const field = metadata[fieldIndex];
98
- const fieldName = field.name;
99
- const fieldType = field.type;
100
- const value = jsonData[fieldName];
101
- if (value === undefined || value === null) {
102
- continue;
103
- }
104
- if (typeof fieldType === "string") {
105
- // Primitive type: assign directly
106
- this[fieldName] = value;
107
- }
108
- else if (Schema.is(fieldType)) {
109
- // Schema type: create instance and restore
110
- const instance = new fieldType();
111
- instance.restore(value);
112
- this[fieldName] = instance;
113
- }
114
- else if (typeof fieldType === "object") {
115
- // Collection types: { map: ... }, { array: ... }, etc.
116
- const collectionType = Object.keys(fieldType)[0];
117
- const childType = fieldType[collectionType];
118
- if (collectionType === "map") {
119
- const mapSchema = this[fieldName];
120
- for (const key in value) {
121
- if (Schema.is(childType)) {
122
- const childInstance = new childType();
123
- childInstance.restore(value[key]);
124
- mapSchema.set(key, childInstance);
125
- }
126
- else {
127
- mapSchema.set(key, value[key]);
128
- }
129
- }
130
- }
131
- else if (collectionType === "array") {
132
- const arraySchema = this[fieldName];
133
- for (let i = 0; i < value.length; i++) {
134
- if (Schema.is(childType)) {
135
- const childInstance = new childType();
136
- childInstance.restore(value[i]);
137
- arraySchema.push(childInstance);
138
- }
139
- else {
140
- arraySchema.push(value[i]);
141
- }
142
- }
143
- }
144
- }
145
- }
146
- return this;
147
- }
148
- /**
149
- * (Server-side): Flag a property to be encoded for the next patch.
150
- * @param instance Schema instance
151
- * @param property string representing the property name, or number representing the index of the property.
152
- * @param operation OPERATION to perform (detected automatically)
153
- */
154
- setDirty(property, operation) {
155
- const metadata = this.constructor[Symbol.metadata];
156
- this[$changes].change(metadata[metadata[property]].index, operation);
157
- }
158
- clone() {
159
- // Create instance without calling custom constructor
160
- const cloned = Object.create(this.constructor.prototype);
161
- Schema.initialize(cloned);
162
- const metadata = this.constructor[Symbol.metadata];
163
- //
164
- // TODO: clone all properties, not only annotated ones
165
- //
166
- // for (const field in this) {
167
- for (const fieldIndex in metadata) {
168
- const field = metadata[fieldIndex].name;
169
- if (typeof (this[field]) === "object" &&
170
- typeof (this[field]?.clone) === "function") {
171
- // deep clone
172
- cloned[field] = this[field].clone();
173
- }
174
- else {
175
- // primitive values
176
- cloned[field] = this[field];
177
- }
178
- }
179
- return cloned;
180
- }
181
- toJSON() {
182
- const obj = {};
183
- const metadata = this.constructor[Symbol.metadata];
184
- for (const index in metadata) {
185
- const field = metadata[index];
186
- const fieldName = field.name;
187
- if (!field.deprecated && this[fieldName] !== null && typeof (this[fieldName]) !== "undefined") {
188
- obj[fieldName] = (typeof (this[fieldName]['toJSON']) === "function")
189
- ? this[fieldName]['toJSON']()
190
- : this[fieldName];
191
- }
192
- }
193
- return obj;
194
- }
195
- /**
196
- * Used in tests only
197
- * @internal
198
- */
199
- discardAllChanges() {
200
- this[$changes].discardAll();
201
- }
202
- [$getByIndex](index) {
203
- const metadata = this.constructor[Symbol.metadata];
204
- return this[metadata[index].name];
205
- }
206
- [$deleteByIndex](index) {
207
- const metadata = this.constructor[Symbol.metadata];
208
- this[metadata[index].name] = undefined;
209
- }
210
- /**
211
- * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
212
- *
213
- * @param ref Schema instance
214
- * @param showContents display JSON contents of the instance
215
- * @returns
216
- */
217
- static debugRefIds(ref, showContents = false, level = 0, decoder, keyPrefix = "") {
218
- const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : "";
219
- const changeTree = ref[$changes];
220
- const refId = ref[$refId];
221
- const root = (decoder) ? decoder.root : changeTree.root;
222
- // log reference count if > 1
223
- const refCount = (root?.refCount?.[refId] > 1)
224
- ? ` [×${root.refCount[refId]}]`
225
- : '';
226
- let output = `${getIndent(level)}${keyPrefix}${ref.constructor.name} (refId: ${refId})${refCount}${contents}\n`;
227
- changeTree.forEachChild((childChangeTree, indexOrKey) => {
228
- let key = indexOrKey;
229
- if (typeof indexOrKey === 'number' && ref['$indexes']) {
230
- // MapSchema
231
- key = ref['$indexes'].get(indexOrKey) ?? indexOrKey;
232
- }
233
- const keyPrefix = (ref['forEach'] !== undefined && key !== undefined) ? `["${key}"]: ` : "";
234
- output += this.debugRefIds(childChangeTree.ref, showContents, level + 1, decoder, keyPrefix);
235
- });
236
- return output;
237
- }
238
- static debugRefIdEncodingOrder(ref, changeSet = 'allChanges') {
239
- let encodeOrder = [];
240
- let current = ref[$changes].root[changeSet].next;
241
- while (current) {
242
- if (current.changeTree) {
243
- encodeOrder.push(current.changeTree.ref[$refId]);
244
- }
245
- current = current.next;
246
- }
247
- return encodeOrder;
248
- }
249
- static debugRefIdsFromDecoder(decoder) {
250
- return this.debugRefIds(decoder.state, false, 0, decoder);
251
- }
252
- /**
253
- * Return a string representation of the changes on a Schema instance.
254
- * The list of changes is cleared after each encode.
255
- *
256
- * @param instance Schema instance
257
- * @param isEncodeAll Return "full encode" instead of current change set.
258
- * @returns
259
- */
260
- static debugChanges(instance, isEncodeAll = false) {
261
- const changeTree = instance[$changes];
262
- const changeSet = (isEncodeAll) ? changeTree.allChanges : changeTree.changes;
263
- const changeSetName = (isEncodeAll) ? "allChanges" : "changes";
264
- let output = `${instance.constructor.name} (${instance[$refId]}) -> .${changeSetName}:\n`;
265
- function dumpChangeSet(changeSet) {
266
- changeSet.operations
267
- .filter(op => op)
268
- .forEach((index) => {
269
- const operation = changeTree.indexedOperations[index];
270
- output += `- [${index}]: ${OPERATION[operation]} (${JSON.stringify(changeTree.getValue(Number(index), isEncodeAll))})\n`;
271
- });
272
- }
273
- dumpChangeSet(changeSet);
274
- // display filtered changes
275
- if (!isEncodeAll &&
276
- changeTree.filteredChanges &&
277
- (changeTree.filteredChanges.operations).filter(op => op).length > 0) {
278
- output += `${instance.constructor.name} (${instance[$refId]}) -> .filteredChanges:\n`;
279
- dumpChangeSet(changeTree.filteredChanges);
280
- }
281
- // display filtered changes
282
- if (isEncodeAll &&
283
- changeTree.allFilteredChanges &&
284
- (changeTree.allFilteredChanges.operations).filter(op => op).length > 0) {
285
- output += `${instance.constructor.name} (${instance[$refId]}) -> .allFilteredChanges:\n`;
286
- dumpChangeSet(changeTree.allFilteredChanges);
287
- }
288
- return output;
289
- }
290
- static debugChangesDeep(ref, changeSetName = "changes") {
291
- let output = "";
292
- const rootChangeTree = ref[$changes];
293
- const root = rootChangeTree.root;
294
- const changeTrees = new Map();
295
- const instanceRefIds = [];
296
- let totalOperations = 0;
297
- // TODO: FIXME: this method is not working as expected
298
- for (const [refId, changes] of Object.entries(root[changeSetName])) {
299
- const changeTree = root.changeTrees[refId];
300
- if (!changeTree) {
301
- continue;
302
- }
303
- let includeChangeTree = false;
304
- let parentChangeTrees = [];
305
- let parentChangeTree = changeTree.parent?.[$changes];
306
- if (changeTree === rootChangeTree) {
307
- includeChangeTree = true;
308
- }
309
- else {
310
- while (parentChangeTree !== undefined) {
311
- parentChangeTrees.push(parentChangeTree);
312
- if (parentChangeTree.ref === ref) {
313
- includeChangeTree = true;
314
- break;
315
- }
316
- parentChangeTree = parentChangeTree.parent?.[$changes];
317
- }
318
- }
319
- if (includeChangeTree) {
320
- instanceRefIds.push(changeTree.ref[$refId]);
321
- totalOperations += Object.keys(changes).length;
322
- changeTrees.set(changeTree, parentChangeTrees.reverse());
323
- }
324
- }
325
- output += "---\n";
326
- output += `root refId: ${rootChangeTree.ref[$refId]}\n`;
327
- output += `Total instances: ${instanceRefIds.length} (refIds: ${instanceRefIds.join(", ")})\n`;
328
- output += `Total changes: ${totalOperations}\n`;
329
- output += "---\n";
330
- // based on root.changes, display a tree of changes that has the "ref" instance as parent
331
- const visitedParents = new WeakSet();
332
- for (const [changeTree, parentChangeTrees] of changeTrees.entries()) {
333
- parentChangeTrees.forEach((parentChangeTree, level) => {
334
- if (!visitedParents.has(parentChangeTree)) {
335
- output += `${getIndent(level)}${parentChangeTree.ref.constructor.name} (refId: ${parentChangeTree.ref[$refId]})\n`;
336
- visitedParents.add(parentChangeTree);
337
- }
338
- });
339
- const changes = changeTree.indexedOperations;
340
- const level = parentChangeTrees.length;
341
- const indent = getIndent(level);
342
- const parentIndex = (level > 0) ? `(${changeTree.parentIndex}) ` : "";
343
- output += `${indent}${parentIndex}${changeTree.ref.constructor.name} (refId: ${changeTree.ref[$refId]}) - changes: ${Object.keys(changes).length}\n`;
344
- for (const index in changes) {
345
- const operation = changes[index];
346
- output += `${getIndent(level + 1)}${OPERATION[operation]}: ${index}\n`;
347
- }
348
- }
349
- return `${output}`;
350
- }
351
- }
352
- //# sourceMappingURL=Schema.js.map
package/lib/Schema.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAC;AAItE,OAAO,EAA4B,UAAU,EAAa,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGnI,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIlE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,MAAM;aAER,QAAU,GAAG,qBAAqB,CAAC;aACnC,QAAU,GAAG,qBAAqB,CAAC;IAI1C;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,QAAa;QAC3B,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE;YACtC,KAAK,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC;YAC/B,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAoB;QAC1B,OAAO,OAAM,CAAE,IAAsB,CAAC,MAAM,CAAC,QAA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C,CAAC;YAEhC,MAAM,WAAW,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,YAAY,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC;YAErJ,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC1B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,OAAO,GAAG,MAAM,EAAE,CAAC;IACvB,CAAC","sourcesContent":["import { OPERATION } from './encoding/spec';\nimport { DEFAULT_VIEW_TAG, type DefinitionType } from \"./annotations\";\n\nimport { AssignableProps, NonFunctionPropNames, ToJSON } from './types/HelperTypes';\n\nimport { ChangeSet, ChangeSetName, ChangeTree, IRef, Ref } from './encoder/ChangeTree';\nimport { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $refId, $track } from './types/symbols';\nimport { StateView } from './encoder/StateView';\n\nimport { encodeSchemaOperation } from './encoder/EncodeOperation';\nimport { decodeSchemaOperation } from './decoder/DecodeOperation';\n\nimport type { Decoder } from './decoder/Decoder';\nimport type { Metadata, MetadataField } from './Metadata';\nimport { getIndent } from './utils';\n\n/**\n * Schema encoder / decoder\n */\nexport class Schema<C = any> implements IRef {\n static [Symbol.metadata]: Metadata;\n static [$encoder] = encodeSchemaOperation;\n static [$decoder] = decodeSchemaOperation;\n\n [$refId]?: number;\n\n /**\n * Assign the property descriptors required to track changes on this instance.\n * @param instance\n */\n static initialize(instance: any) {\n Object.defineProperty(instance, $changes, {\n value: new ChangeTree(instance),\n enumerable: false,\n writable: true\n });\n\n Object.defineProperties(instance, instance.constructor[Symbol.metadata]?.[$descriptors] || {});\n }\n\n static is(type: DefinitionType) {\n return typeof((type as typeof Schema)[Symbol.metadata]) === \"object\";\n }\n\n /**\n * Track property changes\n */\n static [$track] (changeTree: ChangeTree, index: number, operation: OPERATION = OPERATION.ADD) {\n changeTree.change(index, operation);\n }\n\n /**\n * Determine if a property must be filtered.\n * - If returns false, the property is NOT going to be encoded.\n * - If returns true, the property is going to be encoded.\n *\n * Encoding with \"filters\" happens in two steps:\n * - First, the encoder iterates over all \"not owned\" properties and encodes them.\n * - Then, the encoder iterates over all \"owned\" properties per instance and encodes them.\n */\n static [$filter] (ref: Schema, index: number, view: StateView) {\n const metadata: Metadata = (ref.constructor as typeof Schema)[Symbol.metadata];\n const tag = metadata[index]?.tag;\n\n if (view === undefined) {\n // shared pass/encode: encode if doesn't have a tag\n return tag === undefined;\n\n } else if (tag === undefined) {\n // view pass: no tag\n return true;\n\n } else if (tag === DEFAULT_VIEW_TAG) {\n // view pass: default tag\n return view.isChangeTreeVisible(ref[$changes]);\n\n } else {\n // view pass: custom tag\n const tags = view.tags?.get(ref[$changes]);\n return tags && tags.has(tag);\n }\n }\n\n // allow inherited classes to have a constructor\n constructor(arg?: C) {\n //\n // inline\n // Schema.initialize(this);\n //\n Schema.initialize(this);\n\n //\n // Assign initial values\n //\n if (arg) {\n Object.assign(this, arg);\n }\n }\n\n /**\n * Assign properties to the instance.\n * @param props Properties to assign to the instance\n * @returns\n */\n public assign<T extends Partial<this>>(props: AssignableProps<T>,): this {\n Object.assign(this, props);\n return this;\n }\n\n /**\n * Restore the instance from JSON data.\n * @param jsonData JSON data to restore the instance from\n * @returns\n */\n public restore(jsonData: ToJSON<this>): this {\n const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];\n\n for (const fieldIndex in metadata) {\n const field = metadata[fieldIndex as any as number];\n const fieldName = field.name as keyof this;\n const fieldType = field.type;\n const value = (jsonData as any)[fieldName];\n\n if (value === undefined || value === null) {\n continue;\n }\n\n if (typeof fieldType === \"string\") {\n // Primitive type: assign directly\n this[fieldName] = value;\n\n } else if (Schema.is(fieldType)) {\n // Schema type: create instance and restore\n const instance = new (fieldType as typeof Schema)();\n instance.restore(value);\n this[fieldName] = instance as any;\n\n } else if (typeof fieldType === \"object\") {\n // Collection types: { map: ... }, { array: ... }, etc.\n const collectionType = Object.keys(fieldType)[0] as string;\n const childType = (fieldType as any)[collectionType];\n\n if (collectionType === \"map\") {\n const mapSchema = this[fieldName] as any;\n for (const key in value) {\n if (Schema.is(childType)) {\n const childInstance = new (childType as typeof Schema)();\n childInstance.restore(value[key]);\n mapSchema.set(key, childInstance);\n } else {\n mapSchema.set(key, value[key]);\n }\n }\n\n } else if (collectionType === \"array\") {\n const arraySchema = this[fieldName] as any;\n for (let i = 0; i < value.length; i++) {\n if (Schema.is(childType)) {\n const childInstance = new (childType as typeof Schema)();\n childInstance.restore(value[i]);\n arraySchema.push(childInstance);\n } else {\n arraySchema.push(value[i]);\n }\n }\n }\n }\n }\n\n return this;\n }\n\n /**\n * (Server-side): Flag a property to be encoded for the next patch.\n * @param instance Schema instance\n * @param property string representing the property name, or number representing the index of the property.\n * @param operation OPERATION to perform (detected automatically)\n */\n public setDirty<K extends NonFunctionPropNames<this>>(property: K | number, operation?: OPERATION) {\n const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];\n this[$changes].change(\n metadata[metadata[property as string]].index,\n operation\n );\n }\n\n clone (): this {\n // Create instance without calling custom constructor\n const cloned = Object.create(this.constructor.prototype);\n Schema.initialize(cloned);\n\n const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];\n\n //\n // TODO: clone all properties, not only annotated ones\n //\n // for (const field in this) {\n for (const fieldIndex in metadata) {\n const field = metadata[fieldIndex as any as number].name as keyof this;\n\n if (\n typeof (this[field]) === \"object\" &&\n typeof ((this[field] as any)?.clone) === \"function\"\n ) {\n // deep clone\n cloned[field] = (this[field] as any).clone();\n\n } else {\n // primitive values\n cloned[field] = this[field];\n }\n }\n\n return cloned;\n }\n\n toJSON (this: any): ToJSON<this> {\n const obj: any = {};\n const metadata = this.constructor[Symbol.metadata];\n for (const index in metadata) {\n const field = metadata[index] as MetadataField;\n const fieldName = field.name;\n if (!field.deprecated && this[fieldName] !== null && typeof (this[fieldName]) !== \"undefined\") {\n obj[fieldName] = (typeof (this[fieldName]['toJSON']) === \"function\")\n ? this[fieldName]['toJSON']()\n : this[fieldName];\n }\n }\n return obj;\n }\n\n /**\n * Used in tests only\n * @internal\n */\n discardAllChanges() {\n this[$changes].discardAll();\n }\n\n [$getByIndex](index: number): any {\n const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];\n return this[metadata[index].name as keyof this];\n }\n\n [$deleteByIndex](index: number): void {\n const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];\n this[metadata[index].name as keyof this] = undefined;\n }\n\n /**\n * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.\n *\n * @param ref Schema instance\n * @param showContents display JSON contents of the instance\n * @returns\n */\n static debugRefIds<T extends Schema>(ref: T, showContents: boolean = false, level: number = 0, decoder?: Decoder, keyPrefix: string = \"\") {\n const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : \"\";\n const changeTree: ChangeTree = ref[$changes];\n\n const refId = (ref as IRef)[$refId];\n const root = (decoder) ? decoder.root : changeTree.root;\n\n // log reference count if > 1\n const refCount = (root?.refCount?.[refId] > 1)\n ? ` [×${root.refCount[refId]}]`\n : '';\n\n let output = `${getIndent(level)}${keyPrefix}${ref.constructor.name} (refId: ${refId})${refCount}${contents}\\n`;\n\n changeTree.forEachChild((childChangeTree, indexOrKey) => {\n let key = indexOrKey;\n if (typeof indexOrKey === 'number' && (ref as any)['$indexes']) {\n // MapSchema\n key = (ref as any)['$indexes'].get(indexOrKey) ?? indexOrKey;\n }\n const keyPrefix = ((ref as any)['forEach'] !== undefined && key !== undefined) ? `[\"${key}\"]: ` : \"\";\n output += this.debugRefIds(childChangeTree.ref, showContents, level + 1, decoder, keyPrefix);\n });\n\n return output;\n }\n\n static debugRefIdEncodingOrder<T extends Ref>(ref: T, changeSet: ChangeSetName = 'allChanges') {\n let encodeOrder: number[] = [];\n let current = ref[$changes].root[changeSet].next;\n while (current) {\n if (current.changeTree) {\n encodeOrder.push(current.changeTree.ref[$refId]);\n }\n current = current.next;\n }\n return encodeOrder;\n }\n\n static debugRefIdsFromDecoder(decoder: Decoder) {\n return this.debugRefIds(decoder.state, false, 0, decoder);\n }\n\n /**\n * Return a string representation of the changes on a Schema instance.\n * The list of changes is cleared after each encode.\n *\n * @param instance Schema instance\n * @param isEncodeAll Return \"full encode\" instead of current change set.\n * @returns\n */\n static debugChanges<T extends Ref>(instance: T, isEncodeAll: boolean = false) {\n const changeTree: ChangeTree = instance[$changes];\n\n const changeSet = (isEncodeAll) ? changeTree.allChanges : changeTree.changes;\n const changeSetName = (isEncodeAll) ? \"allChanges\" : \"changes\";\n\n let output = `${instance.constructor.name} (${instance[$refId]}) -> .${changeSetName}:\\n`;\n\n function dumpChangeSet(changeSet: ChangeSet) {\n changeSet.operations\n .filter(op => op)\n .forEach((index) => {\n const operation = changeTree.indexedOperations[index];\n output += `- [${index}]: ${OPERATION[operation]} (${JSON.stringify(changeTree.getValue(Number(index), isEncodeAll))})\\n`\n });\n }\n\n dumpChangeSet(changeSet);\n\n // display filtered changes\n if (\n !isEncodeAll &&\n changeTree.filteredChanges &&\n (changeTree.filteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${instance[$refId]}) -> .filteredChanges:\\n`;\n dumpChangeSet(changeTree.filteredChanges);\n }\n\n // display filtered changes\n if (\n isEncodeAll &&\n changeTree.allFilteredChanges &&\n (changeTree.allFilteredChanges.operations).filter(op => op).length > 0\n ) {\n output += `${instance.constructor.name} (${instance[$refId]}) -> .allFilteredChanges:\\n`;\n dumpChangeSet(changeTree.allFilteredChanges);\n }\n\n return output;\n }\n\n static debugChangesDeep<T extends Schema>(ref: T, changeSetName: \"changes\" | \"allChanges\" | \"allFilteredChanges\" | \"filteredChanges\" = \"changes\") {\n let output = \"\";\n\n const rootChangeTree: ChangeTree = ref[$changes];\n const root = rootChangeTree.root;\n const changeTrees: Map<ChangeTree, ChangeTree[]> = new Map();\n\n const instanceRefIds = [];\n let totalOperations = 0;\n\n // TODO: FIXME: this method is not working as expected\n for (const [refId, changes] of Object.entries(root[changeSetName])) {\n const changeTree = root.changeTrees[refId as any as number];\n if (!changeTree) { continue; }\n\n let includeChangeTree = false;\n let parentChangeTrees: ChangeTree[] = [];\n let parentChangeTree = changeTree.parent?.[$changes];\n\n if (changeTree === rootChangeTree) {\n includeChangeTree = true;\n\n } else {\n while (parentChangeTree !== undefined) {\n parentChangeTrees.push(parentChangeTree);\n if (parentChangeTree.ref === ref) {\n includeChangeTree = true;\n break;\n }\n parentChangeTree = parentChangeTree.parent?.[$changes];\n }\n }\n\n if (includeChangeTree) {\n instanceRefIds.push(changeTree.ref[$refId]);\n totalOperations += Object.keys(changes).length;\n changeTrees.set(changeTree, parentChangeTrees.reverse());\n }\n }\n\n output += \"---\\n\"\n output += `root refId: ${rootChangeTree.ref[$refId]}\\n`;\n output += `Total instances: ${instanceRefIds.length} (refIds: ${instanceRefIds.join(\", \")})\\n`;\n output += `Total changes: ${totalOperations}\\n`;\n output += \"---\\n\"\n\n // based on root.changes, display a tree of changes that has the \"ref\" instance as parent\n const visitedParents = new WeakSet<ChangeTree>();\n for (const [changeTree, parentChangeTrees] of changeTrees.entries()) {\n parentChangeTrees.forEach((parentChangeTree, level) => {\n if (!visitedParents.has(parentChangeTree)) {\n output += `${getIndent(level)}${parentChangeTree.ref.constructor.name} (refId: ${parentChangeTree.ref[$refId]})\\n`;\n visitedParents.add(parentChangeTree);\n }\n });\n\n const changes = changeTree.indexedOperations;\n const level = parentChangeTrees.length;\n const indent = getIndent(level);\n\n const parentIndex = (level > 0) ? `(${changeTree.parentIndex}) ` : \"\";\n output += `${indent}${parentIndex}${changeTree.ref.constructor.name} (refId: ${changeTree.ref[$refId]}) - changes: ${Object.keys(changes).length}\\n`;\n\n for (const index in changes) {\n const operation = changes[index];\n output += `${getIndent(level + 1)}${OPERATION[operation]}: ${index}\\n`;\n }\n }\n\n return `${output}`;\n }\n\n\n}\n\n"]}
@@ -1,109 +0,0 @@
1
- import "./symbol.shim";
2
- import { Schema } from './Schema';
3
- import { ArraySchema } from './types/custom/ArraySchema';
4
- import { MapSchema } from './types/custom/MapSchema';
5
- import { TypeDefinition } from "./types/registry";
6
- import { OPERATION } from "./encoding/spec";
7
- import type { InferValueType, InferSchemaInstanceType, AssignableProps } from "./types/HelperTypes";
8
- import { CollectionSchema } from "./types/custom/CollectionSchema";
9
- import { SetSchema } from "./types/custom/SetSchema";
10
- export type RawPrimitiveType = "string" | "number" | "boolean" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "float32" | "float64" | "bigint64" | "biguint64";
11
- export type PrimitiveType = RawPrimitiveType | typeof Schema | object;
12
- export type DefinitionType<T extends PrimitiveType = PrimitiveType> = T | T[] | {
13
- type: T;
14
- default?: InferValueType<T>;
15
- view?: boolean | number;
16
- sync?: boolean;
17
- } | {
18
- array: T;
19
- default?: ArraySchema<InferValueType<T>>;
20
- view?: boolean | number;
21
- sync?: boolean;
22
- } | {
23
- map: T;
24
- default?: MapSchema<InferValueType<T>>;
25
- view?: boolean | number;
26
- sync?: boolean;
27
- } | {
28
- collection: T;
29
- default?: CollectionSchema<InferValueType<T>>;
30
- view?: boolean | number;
31
- sync?: boolean;
32
- } | {
33
- set: T;
34
- default?: SetSchema<InferValueType<T>>;
35
- view?: boolean | number;
36
- sync?: boolean;
37
- };
38
- export type Definition = {
39
- [field: string]: DefinitionType;
40
- };
41
- export interface TypeOptions {
42
- manual?: boolean;
43
- }
44
- export declare const DEFAULT_VIEW_TAG = -1;
45
- export declare function entity(constructor: any): any;
46
- /**
47
- * [See documentation](https://docs.colyseus.io/state/schema/)
48
- *
49
- * Annotate a Schema property to be serializeable.
50
- * \@type()'d fields are automatically flagged as "dirty" for the next patch.
51
- *
52
- * @example Standard usage, with automatic change tracking.
53
- * ```
54
- * \@type("string") propertyName: string;
55
- * ```
56
- *
57
- * @example You can provide the "manual" option if you'd like to manually control your patches via .setDirty().
58
- * ```
59
- * \@type("string", { manual: true })
60
- * ```
61
- */
62
- export declare function view<T>(tag?: number): (target: T, fieldName: string) => void;
63
- export declare function unreliable<T>(target: T, field: string): void;
64
- export declare function type(type: DefinitionType, options?: TypeOptions): PropertyDecorator;
65
- export declare function getPropertyDescriptor(fieldCached: string, fieldIndex: number, type: DefinitionType, complexTypeKlass: TypeDefinition): {
66
- get: (this: Schema) => number | ((index: number) => any) | ((index: number) => void) | (() => Schema<any>) | (<T extends Partial<Schema<any>>>(props: AssignableProps<T>) => Schema<any>) | ((jsonData: import(".").ToJSON<Schema<any>>) => Schema<any>) | (<K extends "~refId">(property: number | K, operation?: OPERATION) => void) | ((this: any) => import(".").ToJSON<Schema<any>>) | (() => void);
67
- set: (this: Schema, value: any) => void;
68
- enumerable: boolean;
69
- configurable: boolean;
70
- };
71
- /**
72
- * `@deprecated()` flag a field as deprecated.
73
- * The previous `@type()` annotation should remain along with this one.
74
- */
75
- export declare function deprecated(throws?: boolean): PropertyDecorator;
76
- export declare function defineTypes(target: typeof Schema, fields: Definition, options?: TypeOptions): typeof Schema;
77
- type ExtractInitProps<T> = T extends {
78
- initialize: (...args: infer P) => void;
79
- } ? P extends readonly [] ? never : P extends readonly [infer First] ? First extends object ? First : P : P : T extends Definition ? AssignableProps<InferSchemaInstanceType<T>> : never;
80
- type IsInitPropsRequired<T> = T extends {
81
- initialize: (props: any) => void;
82
- } ? true : T extends {
83
- initialize: (...args: infer P) => void;
84
- } ? P extends readonly [] ? false : true : false;
85
- export interface SchemaWithExtends<T extends Definition, P extends typeof Schema> {
86
- extends: <T2 extends Definition = Definition>(fields: T2 & ThisType<InferSchemaInstanceType<T & T2>>, name?: string) => SchemaWithExtendsConstructor<T & T2, ExtractInitProps<T2>, P>;
87
- }
88
- /**
89
- * Get the type of the schema defined via `schema({...})` method.
90
- *
91
- * @example
92
- * const Entity = schema({
93
- * x: "number",
94
- * y: "number",
95
- * });
96
- * type Entity = SchemaType<typeof Entity>;
97
- */
98
- export type SchemaType<T extends {
99
- '~type': any;
100
- }> = T['~type'];
101
- export interface SchemaWithExtendsConstructor<T extends Definition, InitProps, P extends typeof Schema> extends SchemaWithExtends<T, P> {
102
- '~type': InferSchemaInstanceType<T>;
103
- new (...args: [InitProps] extends [never] ? [] : InitProps extends readonly any[] ? InitProps : IsInitPropsRequired<T> extends true ? [InitProps] : [InitProps?]): InferSchemaInstanceType<T> & InstanceType<P>;
104
- prototype: InferSchemaInstanceType<T> & InstanceType<P> & {
105
- initialize(...args: [InitProps] extends [never] ? [] : InitProps extends readonly any[] ? InitProps : [InitProps]): void;
106
- };
107
- }
108
- export declare function schema<T extends Record<string, DefinitionType>, P extends typeof Schema = typeof Schema>(fieldsAndMethods: T & ThisType<InferSchemaInstanceType<T>>, name?: string, inherits?: P): SchemaWithExtendsConstructor<T, ExtractInitProps<T>, P>;
109
- export {};