@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 +0,0 @@
1
- {"version":3,"file":"lua.js","sourceRoot":"","sources":["../../../../src/codegen/languages/lua.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,gBAAgB,EAAE,kBAAkB,EAAW,MAAM,UAAU,CAAC;AAGhG;;;;EAIE;AAEF,MAAM,QAAQ,GAA8B;IACxC,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,IAAc,EAAE,EAAE,CAC9D,IAAI,CAAC,OAAO,C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AAC;QAED,IAAG,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACrB,QAAQ,GAAG,CAAC,aAAa,CAAC;gBACtB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE;gBACrB,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC;QAEhC,CAAC;aAAM,CAAC;YACJ,QAAQ,GAAG,CAAC,aAAa,CAAC;gBACtB,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,IAAI;gBACxC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,CAAC;QACnD,CAAC;IAEL,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,IAAI,CAAC,IAAI,QAAQ,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAc;IACxC,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC;IAE1B,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC/B,OAAO,aAAa,CAAC;IAEzB,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC7B,OAAO,WAAW,CAAC;IAEvB,CAAC;SAAM,CAAC;QACJ,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\n/**\n TODO:\n - Support inheritance\n - Support importing Schema dependencies\n*/\n\nconst typeMaps: { [key: string]: string } = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value: string, index: number, self: string[]) =>\n self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return context.classes.map(klass => ({\n name: klass.name + \".lua\",\n content: generateClass(klass, options.namespace, context.classes)\n }));\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\")) {\n allRefs.push(property);\n }\n });\n\n // Inheritance support\n const inherits = (klass.extends !== \"Schema\")\n ? `, ${klass.extends}`\n : \"\";\n\n return `${getCommentHeader().replace(/\\/\\//mg, \"--\")}\n\nlocal schema = require 'colyseus.serializer.schema.schema'\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `local ${childType} = require '${(namespace ? `${namespace}.` : '')}${childType}'`).\n join(\"\\n\")}\n\n---@class ${klass.name}: ${klass.extends}\n${klass.properties.map(prop => `---@field ${prop.name} ${getLUATypeAnnotation(prop)}`).join(\"\\n\")}\nlocal ${klass.name} = schema.define({\n${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(\",\\n\")},\n [\"_fields_by_index\"] = { ${klass.properties.map(prop => `\"${prop.name}\"`).join(\", \")} },\n}${inherits})\n\nreturn ${klass.name}\n`;\n}\n\nfunction generatePropertyDeclaration(prop: Property) {\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `${prop.childType}`;\n\n } else {\n typeArgs += `\"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n typeArgs = (isUpcaseFirst)\n ? `${prop.childType}`\n : `\"${prop.childType}\"`;\n\n } else {\n typeArgs = (isUpcaseFirst)\n ? `{ ${prop.type} = ${prop.childType} }`\n : `{ ${prop.type} = \"${prop.childType}\" }`;\n }\n\n } else {\n typeArgs = `\"${prop.type}\"`;\n }\n\n return ` [\"${prop.name}\"] = ${typeArgs}`;\n}\n\nfunction getLUATypeAnnotation(prop: Property) {\n if (prop.type === \"ref\") {\n return prop.childType;\n\n } else if (prop.type === \"array\") {\n return \"ArraySchema\";\n\n } else if (prop.type === \"map\") {\n return \"MapSchema\";\n\n } else {\n return typeMaps[prop.type];\n }\n}"]}
@@ -1,3 +0,0 @@
1
- import { File, Context } from "../types";
2
- import { GenerateOptions } from "../api";
3
- export declare function generate(context: Context, options: GenerateOptions): File[];
@@ -1,116 +0,0 @@
1
- import { getCommentHeader, getInheritanceTree } from "../types";
2
- const typeMaps = {
3
- "string": "string",
4
- "number": "number",
5
- "boolean": "boolean",
6
- "int8": "number",
7
- "uint8": "number",
8
- "int16": "number",
9
- "uint16": "number",
10
- "int32": "number",
11
- "uint32": "number",
12
- "int64": "number",
13
- "uint64": "number",
14
- "float32": "number",
15
- "float64": "number",
16
- };
17
- const distinct = (value, index, self) => self.indexOf(value) === index;
18
- export function generate(context, options) {
19
- return [
20
- ...context.classes.map(structure => ({
21
- name: structure.name + ".ts",
22
- content: generateClass(structure, options.namespace, context.classes)
23
- })),
24
- ...context.interfaces.map(structure => ({
25
- name: structure.name + ".ts",
26
- content: generateInterface(structure, options.namespace, context.classes),
27
- }))
28
- ];
29
- }
30
- function generateClass(klass, namespace, allClasses) {
31
- const allRefs = [];
32
- klass.properties.forEach(property => {
33
- let type = property.type;
34
- // keep all refs list
35
- if ((type === "ref" || type === "array" || type === "map" || type === "set")) {
36
- allRefs.push(property);
37
- }
38
- });
39
- return `${getCommentHeader()}
40
-
41
- import { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';
42
- ${allRefs.
43
- filter(ref => ref.childType && typeMaps[ref.childType] === undefined).
44
- map(ref => ref.childType).
45
- concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
46
- filter(distinct).
47
- map(childType => `import { ${childType} } from './${childType}'`).
48
- join("\n")}
49
-
50
- export class ${klass.name} extends ${klass.extends} {
51
- ${klass.properties.map(prop => ` ${generateProperty(prop)}`).join("\n")}
52
- }
53
- `;
54
- }
55
- function generateProperty(prop) {
56
- let langType;
57
- let initializer = "";
58
- let typeArgs;
59
- if (prop.childType) {
60
- const isUpcaseFirst = prop.childType.match(/^[A-Z]/);
61
- if (isUpcaseFirst) {
62
- typeArgs += `, ${prop.childType}`;
63
- }
64
- else {
65
- typeArgs += `, "${prop.childType}"`;
66
- }
67
- if (prop.type === "ref") {
68
- langType = `${prop.childType}`;
69
- initializer = `new ${prop.childType}()`;
70
- typeArgs = `${prop.childType}`;
71
- }
72
- else if (prop.type === "array") {
73
- langType = (isUpcaseFirst)
74
- ? `ArraySchema<${prop.childType}>`
75
- : `ArraySchema<${typeMaps[prop.childType]}>`;
76
- initializer = `new ${langType}()`;
77
- typeArgs = (isUpcaseFirst)
78
- ? `[ ${prop.childType} ]`
79
- : `[ "${prop.childType}" ]`;
80
- }
81
- else if (prop.type === "map") {
82
- langType = (isUpcaseFirst)
83
- ? `MapSchema<${prop.childType}>`
84
- : `MapSchema<${typeMaps[prop.childType]}>`;
85
- initializer = `new ${langType}()`;
86
- typeArgs = (isUpcaseFirst)
87
- ? `{ map: ${prop.childType} }`
88
- : `{ map: "${prop.childType}" }`;
89
- }
90
- else if (prop.type === "set") {
91
- langType = (isUpcaseFirst)
92
- ? `SetSchema<${prop.childType}>`
93
- : `SetSchema<${typeMaps[prop.childType]}>`;
94
- initializer = `new ${langType}()`;
95
- typeArgs = (isUpcaseFirst)
96
- ? `{ set: ${prop.childType} }`
97
- : `{ set: "${prop.childType}" }`;
98
- }
99
- }
100
- else {
101
- langType = typeMaps[prop.type];
102
- typeArgs = `"${prop.type}"`;
103
- }
104
- // TS1263: "Declarations with initializers cannot also have definite assignment assertions"
105
- const definiteAssertion = initializer ? "" : "!";
106
- return `@type(${typeArgs}) public ${prop.name}${definiteAssertion}: ${langType}${(initializer) ? ` = ${initializer}` : ""};`;
107
- }
108
- function generateInterface(structure, namespace, allClasses) {
109
- return `${getCommentHeader()}
110
-
111
- export interface ${structure.name} {
112
- ${structure.properties.map(prop => ` ${prop.name}: ${prop.type};`).join("\n")}
113
- }
114
- `;
115
- }
116
- //# sourceMappingURL=ts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ts.js","sourceRoot":"","sources":["../../../../src/codegen/languages/ts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,gBAAgB,EAAE,kBAAkB,EAAsB,MAAM,UAAU,CAAC;AAG3G,MAAM,QAAQ,GAA8B;IACxC,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,IAAc,EAAE,EAAE,CAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AAElC,MAAM,UAAU,QAAQ,CAAE,OAAgB,EAAE,OAAwB;IAChE,OAAO;QACH,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACjC,IAAI,EAAE,SAAS,CAAC,IAAI,GAAG,KAAK;YAC5B,OAAO,EAAE,aAAa,CAAC,SAAS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AAI,GAAG,iBAAiB,KAAK,QAAQ,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAA;AAChI,CAAC;AAGD,SAAS,iBAAiB,CAAC,SAAoB,EAAE,SAAiB,EAAE,UAAmB;IACnF,OAAO,GAAG,gBAAgB,EAAE;;mBAEb,SAAS,CAAC,IAAI;EAC/B,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;CAE/E,CAAC;AACF,CAAC","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context, Interface } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\nconst typeMaps: { [key: string]: string } = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value: string, index: number, self: string[]) =>\n self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return [\n ...context.classes.map(structure => ({\n name: structure.name + \".ts\",\n content: generateClass(structure, options.namespace, context.classes)\n })),\n ...context.interfaces.map(structure => ({\n name: structure.name + \".ts\",\n content: generateInterface(structure, options.namespace, context.classes),\n }))\n ];\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\" || type === \"set\")) {\n allRefs.push(property);\n }\n });\n\n return `${getCommentHeader()}\n\nimport { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `import { ${childType} } from './${childType}'`).\n join(\"\\n\")}\n\nexport class ${klass.name} extends ${klass.extends} {\n${klass.properties.map(prop => ` ${generateProperty(prop)}`).join(\"\\n\")}\n}\n`;\n}\n\nfunction generateProperty(prop: Property) {\n let langType: string;\n let initializer = \"\";\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `, ${prop.childType}`;\n\n } else {\n typeArgs += `, \"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n langType = `${prop.childType}`;\n initializer = `new ${prop.childType}()`;\n typeArgs = `${prop.childType}`;\n\n } else if(prop.type === \"array\") {\n langType = (isUpcaseFirst)\n ? `ArraySchema<${prop.childType}>`\n : `ArraySchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `[ ${prop.childType} ]`\n : `[ \"${prop.childType}\" ]`;\n\n } else if(prop.type === \"map\") {\n langType = (isUpcaseFirst)\n ? `MapSchema<${prop.childType}>`\n : `MapSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ map: ${prop.childType} }`\n : `{ map: \"${prop.childType}\" }`;\n } else if (prop.type === \"set\") {\n langType = (isUpcaseFirst)\n ? `SetSchema<${prop.childType}>`\n : `SetSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ set: ${prop.childType} }`\n : `{ set: \"${prop.childType}\" }`;\n }\n\n } else {\n langType = typeMaps[prop.type];\n typeArgs = `\"${prop.type}\"`;\n }\n\n // TS1263: \"Declarations with initializers cannot also have definite assignment assertions\"\n const definiteAssertion = initializer ? \"\" : \"!\";\n\n return `@type(${typeArgs}) public ${prop.name}${definiteAssertion}: ${langType}${(initializer) ? ` = ${initializer}` : \"\"};`\n}\n\n\nfunction generateInterface(structure: Interface, namespace: string, allClasses: Class[]) {\n return `${getCommentHeader()}\n\nexport interface ${structure.name} {\n${structure.properties.map(prop => ` ${prop.name}: ${prop.type};`).join(\"\\n\")}\n}\n`;\n}\n"]}
@@ -1,13 +0,0 @@
1
- import * as ts from "typescript";
2
- import { Class, Interface, Context, Enum } from "./types";
3
- export declare function parseFiles(fileNames: string[], decoratorName?: string, context?: Context): {
4
- classes: Class[];
5
- interfaces: Interface[];
6
- enums: Enum[];
7
- };
8
- /**
9
- * TypeScript 4.8+ has introduced a change on how to access decorators.
10
- * - https://github.com/microsoft/TypeScript/pull/49089
11
- * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees
12
- */
13
- export declare function getDecorators(node: ts.Node | null | undefined): undefined | ts.Decorator[];
@@ -1,327 +0,0 @@
1
- import * as ts from "typescript";
2
- import * as path from "path";
3
- import { readFileSync } from "fs";
4
- import { Class, Interface, Property, Context, Enum } from "./types";
5
- let currentStructure;
6
- let currentProperty;
7
- let globalContext;
8
- function defineProperty(property, initializer) {
9
- if (ts.isIdentifier(initializer)) {
10
- property.type = "ref";
11
- property.childType = initializer.text;
12
- }
13
- else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {
14
- property.type = initializer.properties[0].name.text;
15
- property.childType = initializer.properties[0].initializer.text;
16
- }
17
- else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {
18
- property.type = "array";
19
- property.childType = initializer.elements[0].text;
20
- }
21
- else {
22
- property.type = initializer.text;
23
- }
24
- }
25
- function inspectNode(node, context, decoratorName) {
26
- switch (node.kind) {
27
- case ts.SyntaxKind.ImportClause:
28
- const specifier = node.parent.moduleSpecifier;
29
- if (specifier && specifier.text.startsWith('.')) {
30
- const currentDir = path.dirname(node.getSourceFile().fileName);
31
- const pathToImport = path.resolve(currentDir, specifier.text);
32
- parseFiles([pathToImport], decoratorName, globalContext);
33
- }
34
- break;
35
- case ts.SyntaxKind.ClassDeclaration:
36
- currentStructure = new Class();
37
- const heritageClauses = node.heritageClauses;
38
- if (heritageClauses && heritageClauses.length > 0) {
39
- currentStructure.extends = heritageClauses[0].types[0].expression.getText();
40
- }
41
- context.addStructure(currentStructure);
42
- break;
43
- case ts.SyntaxKind.InterfaceDeclaration:
44
- //
45
- // Only generate Interfaces if it has "Message" on its name.
46
- // Example: MyMessage
47
- //
48
- const interfaceName = node.name.escapedText.toString();
49
- if (interfaceName.indexOf("Message") !== -1) {
50
- currentStructure = new Interface();
51
- currentStructure.name = interfaceName;
52
- context.addStructure(currentStructure);
53
- }
54
- break;
55
- case ts.SyntaxKind.EnumDeclaration:
56
- const enumName = node.name.escapedText.toString();
57
- currentStructure = new Enum();
58
- currentStructure.name = enumName;
59
- context.addStructure(currentStructure);
60
- break;
61
- case ts.SyntaxKind.ExtendsKeyword:
62
- // console.log(node.getText());
63
- break;
64
- case ts.SyntaxKind.PropertySignature:
65
- if (currentStructure instanceof Interface) {
66
- const interfaceDeclaration = node.parent;
67
- if (currentStructure.name !== interfaceDeclaration.name.escapedText.toString()) {
68
- // skip if property if for a another interface than the one we're interested in.
69
- break;
70
- }
71
- // define a property of an interface
72
- const property = new Property();
73
- property.name = node.name.escapedText.toString();
74
- property.type = node.type.getText();
75
- currentStructure.addProperty(property);
76
- }
77
- break;
78
- case ts.SyntaxKind.Identifier:
79
- if (node.getText() === "deprecated" &&
80
- node.parent.kind !== ts.SyntaxKind.ImportSpecifier) {
81
- currentProperty = new Property();
82
- currentProperty.deprecated = true;
83
- break;
84
- }
85
- if (node.getText() === decoratorName) {
86
- const prop = node.parent?.parent?.parent;
87
- const propDecorator = getDecorators(prop);
88
- const hasExpression = prop?.expression?.arguments;
89
- const hasDecorator = (propDecorator?.length > 0);
90
- /**
91
- * neither a `@type()` decorator or `type()` call. skip.
92
- */
93
- if (!hasDecorator && !hasExpression) {
94
- break;
95
- }
96
- // using as decorator
97
- if (propDecorator) {
98
- /**
99
- * Calling `@type()` as decorator
100
- */
101
- const typeDecorator = propDecorator.find((decorator => {
102
- return decorator.expression.expression.escapedText === decoratorName;
103
- })).expression;
104
- const property = currentProperty || new Property();
105
- property.name = prop.name.escapedText;
106
- currentStructure.addProperty(property);
107
- const typeArgument = typeDecorator.arguments[0];
108
- defineProperty(property, typeArgument);
109
- }
110
- else if (prop.expression.arguments?.[1] &&
111
- prop.expression.expression.arguments?.[0]) {
112
- /**
113
- * Calling `type()` as a regular method
114
- */
115
- const property = currentProperty || new Property();
116
- property.name = prop.expression.arguments[1].text;
117
- currentStructure.addProperty(property);
118
- const typeArgument = prop.expression.expression.arguments[0];
119
- defineProperty(property, typeArgument);
120
- }
121
- }
122
- else if (node.getText() === "setFields" &&
123
- (node.parent.kind === ts.SyntaxKind.CallExpression ||
124
- node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
125
- /**
126
- * Metadata.setFields(klassName, { ... })
127
- */
128
- const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)
129
- ? node.parent.parent
130
- : node.parent;
131
- /**
132
- * Skip if @codegen-ignore comment is found before the call expression
133
- * TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.
134
- */
135
- const sourceFile = node.getSourceFile();
136
- const fullText = sourceFile.getFullText();
137
- const nodeStart = callExpression.getFullStart();
138
- const textBeforeNode = fullText.substring(0, nodeStart);
139
- if (textBeforeNode.includes('@codegen-ignore')) {
140
- break;
141
- }
142
- if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
143
- break;
144
- }
145
- const classNameNode = callExpression.arguments[0];
146
- const className = ts.isClassExpression(classNameNode)
147
- ? classNameNode.name?.escapedText.toString()
148
- : classNameNode.getText();
149
- // skip if no className is provided
150
- if (!className) {
151
- break;
152
- }
153
- if (currentStructure?.name !== className) {
154
- currentStructure = new Class();
155
- }
156
- context.addStructure(currentStructure);
157
- currentStructure.extends = "Schema"; // force extends to Schema
158
- currentStructure.name = className;
159
- const types = callExpression.arguments[1];
160
- for (let i = 0; i < types.properties.length; i++) {
161
- const prop = types.properties[i];
162
- const property = currentProperty || new Property();
163
- property.name = prop.name.escapedText;
164
- currentStructure.addProperty(property);
165
- defineProperty(property, prop.initializer);
166
- }
167
- }
168
- else if (node.getText() === "defineTypes" &&
169
- (node.parent.kind === ts.SyntaxKind.CallExpression ||
170
- node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
171
- /**
172
- * JavaScript source file (`.js`)
173
- * Using `defineTypes()`
174
- */
175
- const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)
176
- ? node.parent.parent
177
- : node.parent;
178
- if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
179
- break;
180
- }
181
- const className = callExpression.arguments[0].getText();
182
- currentStructure.name = className;
183
- const types = callExpression.arguments[1];
184
- for (let i = 0; i < types.properties.length; i++) {
185
- const prop = types.properties[i];
186
- const property = currentProperty || new Property();
187
- property.name = prop.name.escapedText;
188
- currentStructure.addProperty(property);
189
- defineProperty(property, prop.initializer);
190
- }
191
- }
192
- if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {
193
- currentStructure.name = node.getText();
194
- }
195
- currentProperty = undefined;
196
- break;
197
- case ts.SyntaxKind.CallExpression:
198
- /**
199
- * Defining schema via `schema.schema({ ... })`
200
- * - schema.schema({})
201
- * - schema({})
202
- * - ClassName.extends({})
203
- */
204
- if (((node.expression?.getText() === "schema.schema" ||
205
- node.expression?.getText() === "schema") ||
206
- (node.expression?.getText().indexOf(".extends") !== -1)) &&
207
- node.arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression) {
208
- const callExpression = node;
209
- let className = callExpression.arguments[1]?.getText();
210
- if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {
211
- className = callExpression.parent.name?.getText();
212
- }
213
- // skip if no className is provided
214
- if (!className) {
215
- break;
216
- }
217
- if (currentStructure?.name !== className) {
218
- currentStructure = new Class();
219
- context.addStructure(currentStructure);
220
- }
221
- if (node.expression?.getText().indexOf(".extends") !== -1) {
222
- // if it's using `.extends({})`
223
- const extendsClass = node.expression?.expression?.escapedText;
224
- // skip if no extendsClass is provided
225
- if (!extendsClass) {
226
- break;
227
- }
228
- currentStructure.extends = extendsClass;
229
- }
230
- else {
231
- // if it's using `schema({})`
232
- currentStructure.extends = "Schema"; // force extends to Schema
233
- }
234
- currentStructure.name = className;
235
- const types = callExpression.arguments[0];
236
- for (let i = 0; i < types.properties.length; i++) {
237
- const prop = types.properties[i];
238
- const property = currentProperty || new Property();
239
- property.name = prop.name.escapedText;
240
- currentStructure.addProperty(property);
241
- defineProperty(property, prop.initializer);
242
- }
243
- }
244
- break;
245
- case ts.SyntaxKind.EnumMember:
246
- if (currentStructure instanceof Enum) {
247
- const initializer = node.initializer?.text;
248
- const name = node.getFirstToken().getText();
249
- const property = currentProperty || new Property();
250
- property.name = name;
251
- if (initializer !== undefined) {
252
- property.type = initializer;
253
- }
254
- currentStructure.addProperty(property);
255
- currentProperty = undefined;
256
- }
257
- break;
258
- }
259
- ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));
260
- }
261
- let parsedFiles;
262
- export function parseFiles(fileNames, decoratorName = "type", context = new Context()) {
263
- /**
264
- * Re-set globalContext for each test case
265
- */
266
- if (globalContext !== context) {
267
- parsedFiles = {};
268
- globalContext = context;
269
- }
270
- fileNames.forEach((fileName) => {
271
- let sourceFile;
272
- let sourceFileName;
273
- const fileNameAlternatives = [];
274
- if (!fileName.endsWith(".ts") &&
275
- !fileName.endsWith(".js") &&
276
- !fileName.endsWith(".mjs")) {
277
- fileNameAlternatives.push(`${fileName}.ts`);
278
- fileNameAlternatives.push(`${fileName}/index.ts`);
279
- }
280
- else {
281
- fileNameAlternatives.push(fileName);
282
- }
283
- for (let i = 0; i < fileNameAlternatives.length; i++) {
284
- try {
285
- sourceFileName = path.resolve(fileNameAlternatives[i]);
286
- if (parsedFiles[sourceFileName]) {
287
- break;
288
- }
289
- sourceFile = ts.createSourceFile(sourceFileName, readFileSync(sourceFileName).toString(), ts.ScriptTarget.Latest, true);
290
- parsedFiles[sourceFileName] = true;
291
- break;
292
- }
293
- catch (e) {
294
- // console.log(`${fileNameAlternatives[i]} => ${e.message}`);
295
- }
296
- }
297
- if (sourceFile) {
298
- inspectNode(sourceFile, context, decoratorName);
299
- }
300
- });
301
- return context.getStructures();
302
- }
303
- /**
304
- * TypeScript 4.8+ has introduced a change on how to access decorators.
305
- * - https://github.com/microsoft/TypeScript/pull/49089
306
- * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees
307
- */
308
- export function getDecorators(node) {
309
- if (node == undefined) {
310
- return undefined;
311
- }
312
- // TypeScript 4.7 and below
313
- // @ts-ignore
314
- if (node.decorators) {
315
- return node.decorators;
316
- }
317
- // TypeScript 4.8 and above
318
- // @ts-ignore
319
- if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {
320
- // @ts-ignore
321
- const decorators = ts.getDecorators(node);
322
- return decorators ? Array.from(decorators) : undefined;
323
- }
324
- // @ts-ignore
325
- return node.modifiers?.filter(ts.isDecorator);
326
- }
327
- //# sourceMappingURL=parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/codegen/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,IAAI,CAAC;AAChC,OAAO,EAAa,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAE9E,IAAI,gBAA4B,CAAC;AACjC,IAAI,eAAyB,CAAC;AAE9B,IAAI,aAAsB,CAAC;AAE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AAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACP,CAAC;gBAEF,WAAW,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;gBAEnC,MAAM;YACV,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,6DAA6D;YACjE,CAAC;QACL,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACb,WAAW,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACpD,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgC;IAC1D,IAAI,IAAI,IAAI,SAAS,EAAE,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;IAE5C,2BAA2B;IAC3B,aAAa;IACb,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAAC,OAAO,IAAI,CAAC,UAAU,CAAC;IAAC,CAAC;IAEhD,2BAA2B;IAC3B,aAAa;IACb,IAAI,EAAE,CAAC,iBAAiB,IAAI,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,aAAa;QACb,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAED,aAAa;IACb,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"path\";\nimport {readFileSync} from \"fs\";\nimport {IStructure, Class, Interface, Property, Context, Enum} from \"./types\";\n\nlet currentStructure: IStructure;\nlet currentProperty: Property;\n\nlet globalContext: Context;\n\nfunction defineProperty(property: Property, initializer: any) {\n if (ts.isIdentifier(initializer)) {\n property.type = \"ref\";\n property.childType = initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n property.type = initializer.properties[0].name.text;\n property.childType = initializer.properties[0].initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n property.type = \"array\";\n property.childType = initializer.elements[0].text;\n\n } else {\n property.type = initializer.text;\n }\n}\n\nfunction inspectNode(node: ts.Node, context: Context, decoratorName: string) {\n switch (node.kind) {\n case ts.SyntaxKind.ImportClause:\n const specifier = (node.parent as any).moduleSpecifier;\n if (specifier && (specifier.text as string).startsWith('.')) {\n const currentDir = path.dirname(node.getSourceFile().fileName);\n const pathToImport = path.resolve(currentDir, specifier.text);\n parseFiles([pathToImport], decoratorName, globalContext);\n }\n break;\n\n case ts.SyntaxKind.ClassDeclaration:\n currentStructure = new Class();\n\n const heritageClauses = (node as ts.ClassLikeDeclarationBase).heritageClauses;\n if (heritageClauses && heritageClauses.length > 0) {\n (currentStructure as Class).extends = heritageClauses[0].types[0].expression.getText();\n }\n\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.InterfaceDeclaration:\n //\n // Only generate Interfaces if it has \"Message\" on its name.\n // Example: MyMessage\n //\n const interfaceName = (node as ts.TypeParameterDeclaration).name.escapedText.toString();\n if (interfaceName.indexOf(\"Message\") !== -1) {\n currentStructure = new Interface();\n currentStructure.name = interfaceName;\n\n context.addStructure(currentStructure);\n }\n break;\n\n case ts.SyntaxKind.EnumDeclaration:\n const enumName = (\n node as ts.EnumDeclaration\n ).name.escapedText.toString();\n currentStructure = new Enum();\n currentStructure.name = enumName;\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.ExtendsKeyword:\n // console.log(node.getText());\n break;\n\n case ts.SyntaxKind.PropertySignature:\n if (currentStructure instanceof Interface) {\n const interfaceDeclaration = node.parent;\n\n if (\n currentStructure.name !== (interfaceDeclaration as ts.TypeParameterDeclaration).name.escapedText.toString()\n ) {\n // skip if property if for a another interface than the one we're interested in.\n break;\n }\n\n // define a property of an interface\n const property = new Property();\n property.name = (node as any).name.escapedText.toString();\n property.type = (node as any).type.getText();\n currentStructure.addProperty(property);\n }\n break;\n\n case ts.SyntaxKind.Identifier:\n if (\n node.getText() === \"deprecated\" &&\n node.parent.kind !== ts.SyntaxKind.ImportSpecifier\n ) {\n currentProperty = new Property();\n currentProperty.deprecated = true;\n break;\n }\n\n if (node.getText() === decoratorName) {\n const prop: any = node.parent?.parent?.parent;\n const propDecorator = getDecorators(prop);\n const hasExpression = prop?.expression?.arguments;\n const hasDecorator = (propDecorator?.length > 0);\n\n /**\n * neither a `@type()` decorator or `type()` call. skip.\n */\n if (!hasDecorator && !hasExpression) {\n break;\n }\n\n // using as decorator\n if (propDecorator) {\n /**\n * Calling `@type()` as decorator\n */\n const typeDecorator: any = propDecorator.find((decorator => {\n return (decorator.expression as any).expression.escapedText === decoratorName;\n })).expression;\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n const typeArgument = typeDecorator.arguments[0];\n defineProperty(property, typeArgument);\n\n } else if (\n prop.expression.arguments?.[1] &&\n prop.expression.expression.arguments?.[0]\n ) {\n /**\n * Calling `type()` as a regular method\n */\n const property = currentProperty || new Property();\n property.name = prop.expression.arguments[1].text;\n currentStructure.addProperty(property);\n\n const typeArgument = prop.expression.expression.arguments[0];\n defineProperty(property, typeArgument);\n }\n\n } else if (\n node.getText() === \"setFields\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * Metadata.setFields(klassName, { ... })\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n /**\n * Skip if @codegen-ignore comment is found before the call expression\n * TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.\n */\n const sourceFile = node.getSourceFile();\n const fullText = sourceFile.getFullText();\n const nodeStart = callExpression.getFullStart();\n const textBeforeNode = fullText.substring(0, nodeStart);\n if (textBeforeNode.includes('@codegen-ignore')) {\n break;\n }\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const classNameNode = callExpression.arguments[0];\n const className = ts.isClassExpression(classNameNode)\n ? classNameNode.name?.escapedText.toString()\n : classNameNode.getText();\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure?.name !== className) {\n currentStructure = new Class();\n }\n context.addStructure(currentStructure);\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n\n } else if (\n node.getText() === \"defineTypes\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * JavaScript source file (`.js`)\n * Using `defineTypes()`\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const className = callExpression.arguments[0].getText()\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n defineProperty(property, prop.initializer);\n }\n\n }\n\n if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {\n currentStructure.name = node.getText();\n }\n\n currentProperty = undefined;\n\n break;\n\n case ts.SyntaxKind.CallExpression:\n /**\n * Defining schema via `schema.schema({ ... })`\n * - schema.schema({})\n * - schema({})\n * - ClassName.extends({})\n */\n if (\n (\n (\n (node as ts.CallExpression).expression?.getText() === \"schema.schema\" ||\n (node as ts.CallExpression).expression?.getText() === \"schema\"\n ) ||\n (\n (node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1\n )\n ) &&\n (node as ts.CallExpression).arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression\n ) {\n const callExpression = node as ts.CallExpression;\n\n let className = callExpression.arguments[1]?.getText();\n\n if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {\n className = (callExpression.parent as ts.VariableDeclaration).name?.getText();\n }\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure?.name !== className) {\n currentStructure = new Class();\n context.addStructure(currentStructure);\n }\n\n if ((node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1) {\n // if it's using `.extends({})`\n const extendsClass = (node as any).expression?.expression?.escapedText;\n\n // skip if no extendsClass is provided\n if (!extendsClass) { break; }\n (currentStructure as Class).extends = extendsClass;\n\n } else {\n // if it's using `schema({})`\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n }\n\n currentStructure.name = className;\n\n const types = callExpression.arguments[0] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n }\n\n break;\n\n case ts.SyntaxKind.EnumMember:\n if (currentStructure instanceof Enum) {\n const initializer = (node as any).initializer?.text;\n const name = node.getFirstToken().getText();\n const property = currentProperty || new Property();\n property.name = name;\n if (initializer !== undefined) {\n property.type = initializer;\n }\n currentStructure.addProperty(property);\n currentProperty = undefined;\n }\n break;\n }\n\n ts.forEachChild(node, (n: ts.Node) => inspectNode(n, context, decoratorName));\n}\n\nlet parsedFiles: { [filename: string]: boolean };\n\nexport function parseFiles(\n fileNames: string[],\n decoratorName: string = \"type\",\n context: Context = new Context()\n) {\n /**\n * Re-set globalContext for each test case\n */\n if (globalContext !== context) {\n parsedFiles = {};\n globalContext = context;\n }\n\n fileNames.forEach((fileName) => {\n let sourceFile: ts.Node;\n let sourceFileName: string;\n\n const fileNameAlternatives = [];\n\n if (\n !fileName.endsWith(\".ts\") &&\n !fileName.endsWith(\".js\") &&\n !fileName.endsWith(\".mjs\")\n ) {\n fileNameAlternatives.push(`${fileName}.ts`);\n fileNameAlternatives.push(`${fileName}/index.ts`);\n\n } else {\n fileNameAlternatives.push(fileName);\n }\n\n for (let i = 0; i < fileNameAlternatives.length; i++) {\n try {\n sourceFileName = path.resolve(fileNameAlternatives[i]);\n\n if (parsedFiles[sourceFileName]) {\n break;\n }\n\n sourceFile = ts.createSourceFile(\n sourceFileName,\n readFileSync(sourceFileName).toString(),\n ts.ScriptTarget.Latest,\n true\n );\n\n parsedFiles[sourceFileName] = true;\n\n break;\n } catch (e) {\n // console.log(`${fileNameAlternatives[i]} => ${e.message}`);\n }\n }\n\n if (sourceFile) {\n inspectNode(sourceFile, context, decoratorName);\n }\n });\n\n return context.getStructures();\n}\n\n/**\n * TypeScript 4.8+ has introduced a change on how to access decorators.\n * - https://github.com/microsoft/TypeScript/pull/49089\n * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees\n */\nexport function getDecorators(node: ts.Node | null | undefined,): undefined | ts.Decorator[] {\n if (node == undefined) { return undefined; }\n\n // TypeScript 4.7 and below\n // @ts-ignore\n if (node.decorators) { return node.decorators; }\n\n // TypeScript 4.8 and above\n // @ts-ignore\n if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {\n // @ts-ignore\n const decorators = ts.getDecorators(node);\n return decorators ? Array.from(decorators) : undefined;\n }\n\n // @ts-ignore\n return node.modifiers?.filter(ts.isDecorator);\n}\n"]}
@@ -1,52 +0,0 @@
1
- export declare function getCommentHeader(singleLineComment?: string): string;
2
- export declare class Context {
3
- classes: Class[];
4
- interfaces: Interface[];
5
- enums: Enum[];
6
- getStructures(): {
7
- classes: Class[];
8
- interfaces: Interface[];
9
- enums: Enum[];
10
- };
11
- addStructure(structure: IStructure): void;
12
- private getParentClass;
13
- private isSchemaClass;
14
- }
15
- export interface IStructure {
16
- context: Context;
17
- name: string;
18
- properties: Property[];
19
- addProperty(property: Property): void;
20
- }
21
- export declare class Interface implements IStructure {
22
- context: Context;
23
- name: string;
24
- properties: Property[];
25
- addProperty(property: Property): void;
26
- }
27
- export declare class Class implements IStructure {
28
- context: Context;
29
- name: string;
30
- properties: Property[];
31
- extends: string;
32
- addProperty(property: Property): void;
33
- postProcessing(): void;
34
- }
35
- export declare class Enum implements IStructure {
36
- context: Context;
37
- name: string;
38
- properties: Property[];
39
- addProperty(property: Property): void;
40
- }
41
- export declare class Property {
42
- index: number;
43
- name: string;
44
- type: string;
45
- childType: string;
46
- deprecated?: boolean;
47
- }
48
- export interface File {
49
- name: string;
50
- content: string;
51
- }
52
- export declare function getInheritanceTree(klass: Class, allClasses: Class[], includeSelf?: boolean): Class[];