@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,143 +0,0 @@
1
- import { Metadata } from "../Metadata";
2
- import { Schema } from "../Schema";
3
- import { $viewFieldIndexes } from "./symbols";
4
- export class TypeContext {
5
- /**
6
- * For inheritance support
7
- * Keeps track of which classes extends which. (parent -> children)
8
- */
9
- static { this.inheritedTypes = new Map(); }
10
- static { this.cachedContexts = new Map(); }
11
- static register(target) {
12
- const parent = Object.getPrototypeOf(target);
13
- if (parent !== Schema) {
14
- let inherits = TypeContext.inheritedTypes.get(parent);
15
- if (!inherits) {
16
- inherits = new Set();
17
- TypeContext.inheritedTypes.set(parent, inherits);
18
- }
19
- inherits.add(target);
20
- }
21
- }
22
- static cache(rootClass) {
23
- let context = TypeContext.cachedContexts.get(rootClass);
24
- if (!context) {
25
- context = new TypeContext(rootClass);
26
- TypeContext.cachedContexts.set(rootClass, context);
27
- }
28
- return context;
29
- }
30
- constructor(rootClass) {
31
- this.types = {};
32
- this.schemas = new Map();
33
- this.hasFilters = false;
34
- this.parentFiltered = {};
35
- if (rootClass) {
36
- this.discoverTypes(rootClass);
37
- }
38
- }
39
- has(schema) {
40
- return this.schemas.has(schema);
41
- }
42
- get(typeid) {
43
- return this.types[typeid];
44
- }
45
- add(schema, typeid = this.schemas.size) {
46
- // skip if already registered
47
- if (this.schemas.has(schema)) {
48
- return false;
49
- }
50
- this.types[typeid] = schema;
51
- //
52
- // Workaround to allow using an empty Schema (with no `@type()` fields)
53
- //
54
- if (schema[Symbol.metadata] === undefined) {
55
- Metadata.initialize(schema);
56
- }
57
- this.schemas.set(schema, typeid);
58
- return true;
59
- }
60
- getTypeId(klass) {
61
- return this.schemas.get(klass);
62
- }
63
- discoverTypes(klass, parentType, parentIndex, parentHasViewTag) {
64
- if (parentHasViewTag) {
65
- this.registerFilteredByParent(klass, parentType, parentIndex);
66
- }
67
- // skip if already registered
68
- if (!this.add(klass)) {
69
- return;
70
- }
71
- // add classes inherited from this base class
72
- TypeContext.inheritedTypes.get(klass)?.forEach((child) => {
73
- this.discoverTypes(child, parentType, parentIndex, parentHasViewTag);
74
- });
75
- // add parent classes
76
- let parent = klass;
77
- while ((parent = Object.getPrototypeOf(parent)) &&
78
- parent !== Schema && // stop at root (Schema)
79
- parent !== Function.prototype // stop at root (non-Schema)
80
- ) {
81
- this.discoverTypes(parent);
82
- }
83
- const metadata = (klass[Symbol.metadata] ??= {});
84
- // if any schema/field has filters, mark "context" as having filters.
85
- if (metadata[$viewFieldIndexes]) {
86
- this.hasFilters = true;
87
- }
88
- for (const fieldIndex in metadata) {
89
- const index = fieldIndex;
90
- const fieldType = metadata[index].type;
91
- const fieldHasViewTag = (metadata[index].tag !== undefined);
92
- if (typeof (fieldType) === "string") {
93
- continue;
94
- }
95
- if (typeof (fieldType) === "function") {
96
- this.discoverTypes(fieldType, klass, index, parentHasViewTag || fieldHasViewTag);
97
- }
98
- else {
99
- const type = Object.values(fieldType)[0];
100
- // skip primitive types
101
- if (typeof (type) === "string") {
102
- continue;
103
- }
104
- this.discoverTypes(type, klass, index, parentHasViewTag || fieldHasViewTag);
105
- }
106
- }
107
- }
108
- /**
109
- * Keep track of which classes have filters applied.
110
- * Format: `${typeid}-${parentTypeid}-${parentIndex}`
111
- */
112
- registerFilteredByParent(schema, parentType, parentIndex) {
113
- const typeid = this.schemas.get(schema) ?? this.schemas.size;
114
- let key = `${typeid}`;
115
- if (parentType) {
116
- key += `-${this.schemas.get(parentType)}`;
117
- }
118
- key += `-${parentIndex}`;
119
- this.parentFiltered[key] = true;
120
- }
121
- debug() {
122
- let parentFiltered = "";
123
- for (const key in this.parentFiltered) {
124
- const keys = key.split("-").map(Number);
125
- const fieldIndex = keys.pop();
126
- parentFiltered += `\n\t\t`;
127
- parentFiltered += `${key}: ${keys.reverse().map((id, i) => {
128
- const klass = this.types[id];
129
- const metadata = klass[Symbol.metadata];
130
- let txt = klass.name;
131
- if (i === 0) {
132
- txt += `[${metadata[fieldIndex].name}]`;
133
- }
134
- return `${txt}`;
135
- }).join(" -> ")}`;
136
- }
137
- return `TypeContext ->\n` +
138
- `\tSchema types: ${this.schemas.size}\n` +
139
- `\thasFilters: ${this.hasFilters}\n` +
140
- `\tparentFiltered:${parentFiltered}`;
141
- }
142
- }
143
- //# sourceMappingURL=TypeContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeContext.js","sourceRoot":"","sources":["../../src/types/TypeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,OAAO,WAAW;IAOpB;;;OAGG;aACI,mBAAc,GAAG,IAAI,GAAG,EAAqC,AAA/C,CAAgD;aAC9D,mBAAc,GAAG,IAAI,GAAG,EAA8B,AAAxC,CAAyC;IAE9D,MAAM,CAAC,QAAQ,CAAC,MAAqB;QACjC,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC7C,IAA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CAAC;QAED,OAAO,kBAAkB;YACrB,mBAAmB,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI;YACxC,iBAAiB,IAAI,CAAC,UAAU,IAAI;YACpC,oBAAoB,cAAc,EAAE,CAAC;IAC7C,CAAC","sourcesContent":["import { Metadata } from \"../Metadata\";\nimport { Schema } from \"../Schema\";\nimport { $viewFieldIndexes } from \"./symbols\";\n\nexport class TypeContext {\n types: { [id: number]: typeof Schema; } = {};\n schemas = new Map<typeof Schema, number>();\n\n hasFilters: boolean = false;\n parentFiltered: {[typeIdAndParentIndex: string]: boolean} = {};\n\n /**\n * For inheritance support\n * Keeps track of which classes extends which. (parent -> children)\n */\n static inheritedTypes = new Map<typeof Schema, Set<typeof Schema>>();\n static cachedContexts = new Map<typeof Schema, TypeContext>();\n\n static register(target: typeof Schema) {\n const parent = Object.getPrototypeOf(target);\n if (parent !== Schema) {\n let inherits = TypeContext.inheritedTypes.get(parent);\n if (!inherits) {\n inherits = new Set<typeof Schema>();\n TypeContext.inheritedTypes.set(parent, inherits);\n }\n inherits.add(target);\n }\n }\n\n static cache (rootClass: typeof Schema) {\n let context = TypeContext.cachedContexts.get(rootClass);\n if (!context) {\n context = new TypeContext(rootClass);\n TypeContext.cachedContexts.set(rootClass, context);\n }\n return context;\n }\n\n constructor(rootClass?: typeof Schema) {\n if (rootClass) {\n this.discoverTypes(rootClass);\n }\n }\n\n has(schema: typeof Schema) {\n return this.schemas.has(schema);\n }\n\n get(typeid: number) {\n return this.types[typeid];\n }\n\n add(schema: typeof Schema, typeid = this.schemas.size) {\n // skip if already registered\n if (this.schemas.has(schema)) {\n return false;\n }\n\n this.types[typeid] = schema;\n\n //\n // Workaround to allow using an empty Schema (with no `@type()` fields)\n //\n if (schema[Symbol.metadata] === undefined) {\n Metadata.initialize(schema);\n }\n\n this.schemas.set(schema, typeid);\n return true;\n }\n\n getTypeId(klass: typeof Schema) {\n return this.schemas.get(klass);\n }\n\n private discoverTypes(klass: typeof Schema, parentType?: typeof Schema, parentIndex?: number, parentHasViewTag?: boolean) {\n if (parentHasViewTag) {\n this.registerFilteredByParent(klass, parentType, parentIndex);\n }\n\n // skip if already registered\n if (!this.add(klass)) { return; }\n\n // add classes inherited from this base class\n TypeContext.inheritedTypes.get(klass)?.forEach((child) => {\n this.discoverTypes(child, parentType, parentIndex, parentHasViewTag);\n });\n\n // add parent classes\n let parent: any = klass;\n while (\n (parent = Object.getPrototypeOf(parent)) &&\n parent !== Schema && // stop at root (Schema)\n parent !== Function.prototype // stop at root (non-Schema)\n ) {\n this.discoverTypes(parent);\n }\n\n const metadata: Metadata = (klass[Symbol.metadata] ??= {} as Metadata);\n\n // if any schema/field has filters, mark \"context\" as having filters.\n if (metadata[$viewFieldIndexes]) {\n this.hasFilters = true;\n }\n\n for (const fieldIndex in metadata) {\n const index = fieldIndex as any as number;\n\n const fieldType = metadata[index].type;\n const fieldHasViewTag = (metadata[index].tag !== undefined);\n\n if (typeof (fieldType) === \"string\") {\n continue;\n }\n\n if (typeof (fieldType) === \"function\") {\n this.discoverTypes(fieldType as typeof Schema, klass, index, parentHasViewTag || fieldHasViewTag);\n\n } else {\n const type = Object.values(fieldType)[0];\n\n // skip primitive types\n if (typeof (type) === \"string\") {\n continue;\n }\n\n this.discoverTypes(type as typeof Schema, klass, index, parentHasViewTag || fieldHasViewTag);\n }\n }\n }\n\n /**\n * Keep track of which classes have filters applied.\n * Format: `${typeid}-${parentTypeid}-${parentIndex}`\n */\n private registerFilteredByParent(schema: typeof Schema, parentType?: typeof Schema, parentIndex?: number) {\n const typeid = this.schemas.get(schema) ?? this.schemas.size;\n\n let key = `${typeid}`;\n if (parentType) { key += `-${this.schemas.get(parentType)}`; }\n\n key += `-${parentIndex}`;\n this.parentFiltered[key] = true;\n }\n\n debug() {\n let parentFiltered = \"\";\n\n for (const key in this.parentFiltered) {\n const keys: number[] = key.split(\"-\").map(Number);\n const fieldIndex = keys.pop();\n\n parentFiltered += `\\n\\t\\t`;\n parentFiltered += `${key}: ${keys.reverse().map((id, i) => {\n const klass = this.types[id];\n const metadata: Metadata = klass[Symbol.metadata];\n let txt = klass.name;\n if (i === 0) { txt += `[${metadata[fieldIndex].name}]`; }\n return `${txt}`;\n }).join(\" -> \")}`;\n }\n\n return `TypeContext ->\\n` +\n `\\tSchema types: ${this.schemas.size}\\n` +\n `\\thasFilters: ${this.hasFilters}\\n` +\n `\\tparentFiltered:${parentFiltered}`;\n }\n\n}\n"]}
@@ -1,270 +0,0 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $refId } from "../symbols";
2
- import type { Schema } from "../../Schema";
3
- import { type IRef, ChangeTree } from "../../encoder/ChangeTree";
4
- import { OPERATION } from "../../encoding/spec";
5
- import { Collection } from "../HelperTypes";
6
- import type { StateView } from "../../encoder/StateView";
7
- export declare class ArraySchema<V = any> implements Array<V>, Collection<number, V>, IRef {
8
- [n: number]: V;
9
- [$changes]: ChangeTree;
10
- [$refId]?: number;
11
- protected [$childType]: string | typeof Schema;
12
- protected items: V[];
13
- protected tmpItems: V[];
14
- protected deletedIndexes: {
15
- [index: number]: boolean;
16
- };
17
- protected isMovingItems: boolean;
18
- static [$encoder]: import("../../encoder/EncodeOperation").EncodeOperation<any>;
19
- static [$decoder]: import("../../decoder/DecodeOperation").DecodeOperation<any>;
20
- /**
21
- * Determine if a property must be filtered.
22
- * - If returns false, the property is NOT going to be encoded.
23
- * - If returns true, the property is going to be encoded.
24
- *
25
- * Encoding with "filters" happens in two steps:
26
- * - First, the encoder iterates over all "not owned" properties and encodes them.
27
- * - Then, the encoder iterates over all "owned" properties per instance and encodes them.
28
- */
29
- static [$filter](ref: ArraySchema, index: number, view: StateView): boolean;
30
- static is(type: any): boolean;
31
- static from<T>(iterable: Iterable<T> | ArrayLike<T>): ArraySchema<T>;
32
- constructor(...items: V[]);
33
- set length(newLength: number);
34
- get length(): number;
35
- push(...values: V[]): number;
36
- /**
37
- * Removes the last element from an array and returns it.
38
- */
39
- pop(): V | undefined;
40
- at(index: number): V;
41
- protected $changeAt(index: number, value: V): void;
42
- protected $deleteAt(index: number, operation?: OPERATION): void;
43
- protected $setAt(index: number, value: V, operation: OPERATION): void;
44
- clear(): void;
45
- /**
46
- * Combines two or more arrays.
47
- * @param items Additional items to add to the end of array1.
48
- */
49
- concat(...items: (V | ConcatArray<V>)[]): ArraySchema<V>;
50
- /**
51
- * Adds all the elements of an array separated by the specified separator string.
52
- * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
53
- */
54
- join(separator?: string): string;
55
- /**
56
- * Reverses the elements in an Array.
57
- */
58
- reverse(): ArraySchema<V>;
59
- /**
60
- * Removes the first element from an array and returns it.
61
- */
62
- shift(): V | undefined;
63
- /**
64
- * Returns a section of an array.
65
- * @param start The beginning of the specified portion of the array.
66
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
67
- */
68
- slice(start?: number, end?: number): V[];
69
- /**
70
- * Sorts an array.
71
- * @param compareFn Function used to determine the order of the elements. It is expected to return
72
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
73
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
74
- * ```ts
75
- * [11,2,22,1].sort((a, b) => a - b)
76
- * ```
77
- */
78
- sort(compareFn?: (a: V, b: V) => number): this;
79
- /**
80
- * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
81
- * @param start The zero-based location in the array from which to start removing elements.
82
- * @param deleteCount The number of elements to remove.
83
- * @param insertItems Elements to insert into the array in place of the deleted elements.
84
- */
85
- splice(start: number, deleteCount?: number, ...insertItems: V[]): V[];
86
- /**
87
- * Inserts new elements at the start of an array.
88
- * @param items Elements to insert at the start of the Array.
89
- */
90
- unshift(...items: V[]): number;
91
- /**
92
- * Returns the index of the first occurrence of a value in an array.
93
- * @param searchElement The value to locate in the array.
94
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
95
- */
96
- indexOf(searchElement: V, fromIndex?: number): number;
97
- /**
98
- * Returns the index of the last occurrence of a specified value in an array.
99
- * @param searchElement The value to locate in the array.
100
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
101
- */
102
- lastIndexOf(searchElement: V, fromIndex?: number): number;
103
- /**
104
- * Determines whether all the members of an array satisfy the specified test.
105
- * @param callbackfn A function that accepts up to three arguments. The every method calls
106
- * the callbackfn function for each element in the array until the callbackfn returns a value
107
- * which is coercible to the Boolean value false, or until the end of the array.
108
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
109
- * If thisArg is omitted, undefined is used as the this value.
110
- */
111
- every<S extends V>(predicate: (value: V, index: number, array: V[]) => value is S, thisArg?: any): this is S[];
112
- every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean;
113
- /**
114
- * Determines whether the specified callback function returns true for any element of an array.
115
- * @param callbackfn A function that accepts up to three arguments. The some method calls
116
- * the callbackfn function for each element in the array until the callbackfn returns a value
117
- * which is coercible to the Boolean value true, or until the end of the array.
118
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
119
- * If thisArg is omitted, undefined is used as the this value.
120
- */
121
- some(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean;
122
- /**
123
- * Performs the specified action for each element in an array.
124
- * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
125
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
126
- */
127
- forEach(callbackfn: (value: V, index: number, array: V[]) => void, thisArg?: any): void;
128
- /**
129
- * Calls a defined callback function on each element of an array, and returns an array that contains the results.
130
- * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
131
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
132
- */
133
- map<U>(callbackfn: (value: V, index: number, array: V[]) => U, thisArg?: any): U[];
134
- /**
135
- * Returns the elements of an array that meet the condition specified in a callback function.
136
- * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
137
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
138
- */
139
- filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[];
140
- /**
141
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
142
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
143
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
144
- */
145
- reduce<U = V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U;
146
- /**
147
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
148
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
149
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
150
- */
151
- reduceRight<U = V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U;
152
- /**
153
- * Returns the value of the first element in the array where predicate is true, and undefined
154
- * otherwise.
155
- * @param predicate find calls predicate once for each element of the array, in ascending
156
- * order, until it finds one where predicate returns true. If such an element is found, find
157
- * immediately returns that element value. Otherwise, find returns undefined.
158
- * @param thisArg If provided, it will be used as the this value for each invocation of
159
- * predicate. If it is not provided, undefined is used instead.
160
- */
161
- find(predicate: (value: V, index: number, obj: V[]) => boolean, thisArg?: any): V | undefined;
162
- /**
163
- * Returns the index of the first element in the array where predicate is true, and -1
164
- * otherwise.
165
- * @param predicate find calls predicate once for each element of the array, in ascending
166
- * order, until it finds one where predicate returns true. If such an element is found,
167
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
168
- * @param thisArg If provided, it will be used as the this value for each invocation of
169
- * predicate. If it is not provided, undefined is used instead.
170
- */
171
- findIndex(predicate: (value: V, index: number, obj: V[]) => unknown, thisArg?: any): number;
172
- /**
173
- * Returns the this object after filling the section identified by start and end with value
174
- * @param value value to fill array section with
175
- * @param start index to start filling the array at. If start is negative, it is treated as
176
- * length+start where length is the length of the array.
177
- * @param end index to stop filling the array at. If end is negative, it is treated as
178
- * length+end.
179
- */
180
- fill(value: V, start?: number, end?: number): this;
181
- /**
182
- * Returns the this object after copying a section of the array identified by start and end
183
- * to the same array starting at position target
184
- * @param target If target is negative, it is treated as length+target where length is the
185
- * length of the array.
186
- * @param start If start is negative, it is treated as length+start. If end is negative, it
187
- * is treated as length+end.
188
- * @param end If not specified, length of the this object is used as its default value.
189
- */
190
- copyWithin(target: number, start: number, end?: number): this;
191
- /**
192
- * Returns a string representation of an array.
193
- */
194
- toString(): string;
195
- /**
196
- * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.
197
- */
198
- toLocaleString(): string;
199
- /** Iterator */
200
- [Symbol.iterator](): ArrayIterator<V>;
201
- static get [Symbol.species](): typeof ArraySchema;
202
- [Symbol.unscopables]: any;
203
- /**
204
- * Returns an iterable of key, value pairs for every entry in the array
205
- */
206
- entries(): ArrayIterator<[number, V]>;
207
- /**
208
- * Returns an iterable of keys in the array
209
- */
210
- keys(): ArrayIterator<number>;
211
- /**
212
- * Returns an iterable of values in the array
213
- */
214
- values(): ArrayIterator<V>;
215
- /**
216
- * Determines whether an array includes a certain element, returning true or false as appropriate.
217
- * @param searchElement The element to search for.
218
- * @param fromIndex The position in this array at which to begin searching for searchElement.
219
- */
220
- includes(searchElement: V, fromIndex?: number): boolean;
221
- /**
222
- * Calls a defined callback function on each element of an array. Then, flattens the result into
223
- * a new array.
224
- * This is identical to a map followed by flat with depth 1.
225
- *
226
- * @param callback A function that accepts up to three arguments. The flatMap method calls the
227
- * callback function one time for each element in the array.
228
- * @param thisArg An object to which the this keyword can refer in the callback function. If
229
- * thisArg is omitted, undefined is used as the this value.
230
- */
231
- flatMap<U, This = undefined>(callback: (this: This, value: V, index: number, array: V[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
232
- /**
233
- * Returns a new array with all sub-array elements concatenated into it recursively up to the
234
- * specified depth.
235
- *
236
- * @param depth The maximum recursion depth
237
- */
238
- flat<A, D extends number = 1>(this: A, depth?: D): any;
239
- findLast(): any;
240
- findLastIndex(...args: any[]): any;
241
- with(index: number, value: V): ArraySchema<V>;
242
- toReversed(): V[];
243
- toSorted(compareFn?: (a: V, b: V) => number): V[];
244
- toSpliced(start: number, deleteCount: number, ...items: V[]): V[];
245
- toSpliced(start: number, deleteCount?: number): V[];
246
- shuffle(): this;
247
- /**
248
- * Allows to move items around in the array.
249
- *
250
- * Example:
251
- * state.cards.move((cards) => {
252
- * [cards[4], cards[3]] = [cards[3], cards[4]];
253
- * [cards[3], cards[2]] = [cards[2], cards[3]];
254
- * [cards[2], cards[0]] = [cards[0], cards[2]];
255
- * [cards[1], cards[1]] = [cards[1], cards[1]];
256
- * [cards[0], cards[0]] = [cards[0], cards[0]];
257
- * })
258
- *
259
- * @param cb
260
- * @returns
261
- */
262
- move(cb: (arr: this) => void): this;
263
- [$getByIndex](index: number, isEncodeAll?: boolean): any;
264
- [$deleteByIndex](index: number): void;
265
- protected [$onEncodeEnd](): void;
266
- protected [$onDecodeEnd](): void;
267
- toArray(): V[];
268
- toJSON(): any[];
269
- clone(isDecoding?: boolean): ArraySchema<V>;
270
- }