sonamu 0.4.13 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/.swcrc +15 -0
  2. package/dist/api/base-frame.d.ts +8 -0
  3. package/dist/api/base-frame.d.ts.map +1 -0
  4. package/dist/api/base-frame.js +2 -0
  5. package/dist/api/base-frame.js.map +1 -0
  6. package/dist/api/caster.d.ts +5 -0
  7. package/dist/api/caster.d.ts.map +1 -0
  8. package/dist/api/caster.js +2 -0
  9. package/dist/api/caster.js.map +1 -0
  10. package/dist/api/code-converters.d.ts +23 -0
  11. package/dist/api/code-converters.d.ts.map +1 -0
  12. package/dist/api/code-converters.js +2 -0
  13. package/dist/api/code-converters.js.map +1 -0
  14. package/dist/api/context.d.ts +16 -0
  15. package/dist/api/context.d.ts.map +1 -0
  16. package/dist/api/context.js +2 -0
  17. package/dist/api/context.js.map +1 -0
  18. package/dist/api/decorators.d.ts +50 -0
  19. package/dist/api/decorators.d.ts.map +1 -0
  20. package/dist/api/decorators.js +2 -0
  21. package/dist/api/decorators.js.map +1 -0
  22. package/dist/api/index.d.ts +8 -0
  23. package/dist/api/index.d.ts.map +1 -0
  24. package/dist/api/index.js +2 -0
  25. package/dist/api/index.js.map +1 -0
  26. package/dist/api/sonamu.d.ts +83 -0
  27. package/dist/api/sonamu.d.ts.map +1 -0
  28. package/dist/api/sonamu.js +2 -0
  29. package/dist/api/sonamu.js.map +1 -0
  30. package/dist/api/sonamu.types.d.ts +30 -0
  31. package/dist/api/sonamu.types.d.ts.map +1 -0
  32. package/dist/api/sonamu.types.js +2 -0
  33. package/dist/api/sonamu.types.js.map +1 -0
  34. package/dist/bin/build-config.d.ts +5 -0
  35. package/dist/bin/build-config.d.ts.map +1 -0
  36. package/dist/bin/build-config.js +2 -0
  37. package/dist/bin/build-config.js.map +1 -0
  38. package/dist/bin/cli-wrapper.d.ts +2 -0
  39. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  40. package/dist/bin/cli-wrapper.js +1 -38
  41. package/dist/bin/cli-wrapper.js.map +1 -1
  42. package/dist/bin/cli.d.ts +2 -2
  43. package/dist/bin/cli.d.ts.map +1 -0
  44. package/dist/bin/cli.js +1 -903
  45. package/dist/bin/cli.js.map +1 -1
  46. package/dist/bin/cli.mjs +2 -2
  47. package/dist/{chunk-DMJSNO2L.js → chunk-2WAC2GER.js} +44 -44
  48. package/dist/{chunk-DMJSNO2L.js.map → chunk-2WAC2GER.js.map} +1 -1
  49. package/dist/{chunk-NI37CY4T.mjs → chunk-C3IPIF6O.mjs} +2 -2
  50. package/dist/{chunk-DYFCACHD.js → chunk-EXHKSVTE.js} +7 -7
  51. package/dist/{chunk-QJFHDCBN.mjs → chunk-FCERKIIF.mjs} +2 -2
  52. package/dist/chunk-FCERKIIF.mjs.map +1 -0
  53. package/dist/{chunk-DDJ7T4MA.mjs → chunk-HGIBJYOU.mjs} +2 -2
  54. package/dist/{chunk-NIFOTHBW.mjs → chunk-JKSOJRQA.mjs} +2 -2
  55. package/dist/{chunk-CXAVBVKC.js → chunk-OTKKFP3Y.js} +100 -100
  56. package/dist/{chunk-J6S43O7G.js → chunk-UZ2IY5VE.js} +4 -4
  57. package/dist/database/_batch_update.d.ts +15 -0
  58. package/dist/database/_batch_update.d.ts.map +1 -0
  59. package/dist/database/_batch_update.js +2 -0
  60. package/dist/database/_batch_update.js.map +1 -0
  61. package/dist/database/base-model.d.ts +41 -0
  62. package/dist/database/base-model.d.ts.map +1 -0
  63. package/dist/database/base-model.js +2 -0
  64. package/dist/database/base-model.js.map +1 -0
  65. package/dist/database/code-generator.d.ts +13 -0
  66. package/dist/database/code-generator.d.ts.map +1 -0
  67. package/dist/database/code-generator.js +2 -0
  68. package/dist/database/code-generator.js.map +1 -0
  69. package/dist/database/db.d.ts +40 -0
  70. package/dist/database/db.d.ts.map +1 -0
  71. package/dist/database/db.js +2 -0
  72. package/dist/database/db.js.map +1 -0
  73. package/dist/database/drivers/knex/base-model.js +8 -8
  74. package/dist/database/drivers/knex/base-model.mjs +3 -3
  75. package/dist/database/drivers/kysely/base-model.js +9 -9
  76. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  77. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  78. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  79. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  80. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  81. package/dist/database/puri-wrapper.d.ts +34 -0
  82. package/dist/database/puri-wrapper.d.ts.map +1 -0
  83. package/dist/database/puri-wrapper.js +2 -0
  84. package/dist/database/puri-wrapper.js.map +1 -0
  85. package/dist/database/puri.d.ts +83 -0
  86. package/dist/database/puri.d.ts.map +1 -0
  87. package/dist/database/puri.js +2 -0
  88. package/dist/database/puri.js.map +1 -0
  89. package/dist/database/puri.types.d.ts +60 -0
  90. package/dist/database/puri.types.d.ts.map +1 -0
  91. package/dist/database/puri.types.js +2 -0
  92. package/dist/database/puri.types.js.map +1 -0
  93. package/dist/database/transaction-context.d.ts +9 -0
  94. package/dist/database/transaction-context.d.ts.map +1 -0
  95. package/dist/database/transaction-context.js +2 -0
  96. package/dist/database/transaction-context.js.map +1 -0
  97. package/dist/database/types.d.ts +39 -0
  98. package/dist/database/types.d.ts.map +1 -0
  99. package/dist/database/types.js +2 -0
  100. package/dist/database/types.js.map +1 -0
  101. package/dist/database/upsert-builder.d.ts +34 -0
  102. package/dist/database/upsert-builder.d.ts.map +1 -0
  103. package/dist/database/upsert-builder.js +2 -0
  104. package/dist/database/upsert-builder.js.map +1 -0
  105. package/dist/entity/entity-manager.d.ts +32 -0
  106. package/dist/entity/entity-manager.d.ts.map +1 -0
  107. package/dist/entity/entity-manager.js +2 -0
  108. package/dist/entity/entity-manager.js.map +1 -0
  109. package/dist/entity/entity-utils.d.ts +61 -0
  110. package/dist/entity/entity-utils.d.ts.map +1 -0
  111. package/dist/entity/entity-utils.js +2 -0
  112. package/dist/entity/entity-utils.js.map +1 -0
  113. package/dist/entity/entity.d.ts +62 -0
  114. package/dist/entity/entity.d.ts.map +1 -0
  115. package/dist/entity/entity.js +2 -0
  116. package/dist/entity/entity.js.map +1 -0
  117. package/dist/entity/migrator.d.ts +135 -0
  118. package/dist/entity/migrator.d.ts.map +1 -0
  119. package/dist/entity/migrator.js +2 -0
  120. package/dist/entity/migrator.js.map +1 -0
  121. package/dist/exceptions/error-handler.d.ts +3 -0
  122. package/dist/exceptions/error-handler.d.ts.map +1 -0
  123. package/dist/exceptions/error-handler.js +2 -0
  124. package/dist/exceptions/error-handler.js.map +1 -0
  125. package/dist/exceptions/so-exceptions.d.ts +48 -0
  126. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  127. package/dist/exceptions/so-exceptions.js +2 -0
  128. package/dist/exceptions/so-exceptions.js.map +1 -0
  129. package/dist/file-storage/driver.d.ts +45 -0
  130. package/dist/file-storage/driver.d.ts.map +1 -0
  131. package/dist/file-storage/driver.js +2 -0
  132. package/dist/file-storage/driver.js.map +1 -0
  133. package/dist/file-storage/file-storage.d.ts +50 -0
  134. package/dist/file-storage/file-storage.d.ts.map +1 -0
  135. package/dist/file-storage/file-storage.js +2 -0
  136. package/dist/file-storage/file-storage.js.map +1 -0
  137. package/dist/index.d.ts +22 -813
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +1 -433
  140. package/dist/index.js.map +1 -1
  141. package/dist/index.mjs +3 -3
  142. package/dist/migration/code-generation.d.ts +15 -0
  143. package/dist/migration/code-generation.d.ts.map +1 -0
  144. package/dist/migration/code-generation.js +2 -0
  145. package/dist/migration/code-generation.js.map +1 -0
  146. package/dist/migration/migration-set.d.ts +17 -0
  147. package/dist/migration/migration-set.d.ts.map +1 -0
  148. package/dist/migration/migration-set.js +2 -0
  149. package/dist/migration/migration-set.js.map +1 -0
  150. package/dist/migration/migrator.d.ts +130 -0
  151. package/dist/migration/migrator.d.ts.map +1 -0
  152. package/dist/migration/migrator.js +2 -0
  153. package/dist/migration/migrator.js.map +1 -0
  154. package/dist/migration/types.d.ts +52 -0
  155. package/dist/migration/types.d.ts.map +1 -0
  156. package/dist/migration/types.js +2 -0
  157. package/dist/migration/types.js.map +1 -0
  158. package/dist/smd/smd-manager.d.ts +28 -0
  159. package/dist/smd/smd-manager.d.ts.map +1 -0
  160. package/dist/smd/smd-manager.js +2 -0
  161. package/dist/smd/smd-manager.js.map +1 -0
  162. package/dist/smd/smd.d.ts +40 -0
  163. package/dist/smd/smd.d.ts.map +1 -0
  164. package/dist/smd/smd.js +2 -0
  165. package/dist/smd/smd.js.map +1 -0
  166. package/dist/syncer/index.d.ts +2 -0
  167. package/dist/syncer/index.d.ts.map +1 -0
  168. package/dist/syncer/index.js +2 -0
  169. package/dist/syncer/index.js.map +1 -0
  170. package/dist/syncer/syncer.d.ts +127 -0
  171. package/dist/syncer/syncer.d.ts.map +1 -0
  172. package/dist/syncer/syncer.js +2 -0
  173. package/dist/syncer/syncer.js.map +1 -0
  174. package/dist/templates/base-template.d.ts +13 -0
  175. package/dist/templates/base-template.d.ts.map +1 -0
  176. package/dist/templates/base-template.js +2 -0
  177. package/dist/templates/base-template.js.map +1 -0
  178. package/dist/templates/entity.template.d.ts +17 -0
  179. package/dist/templates/entity.template.d.ts.map +1 -0
  180. package/dist/templates/entity.template.js +2 -0
  181. package/dist/templates/entity.template.js.map +1 -0
  182. package/dist/templates/generated.template.d.ts +27 -0
  183. package/dist/templates/generated.template.d.ts.map +1 -0
  184. package/dist/templates/generated.template.js +2 -0
  185. package/dist/templates/generated.template.js.map +1 -0
  186. package/dist/templates/generated_http.template.d.ts +24 -0
  187. package/dist/templates/generated_http.template.d.ts.map +1 -0
  188. package/dist/templates/generated_http.template.js +2 -0
  189. package/dist/templates/generated_http.template.js.map +1 -0
  190. package/dist/templates/generated_sso.template.d.ts +20 -0
  191. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  192. package/dist/templates/generated_sso.template.js +2 -0
  193. package/dist/templates/generated_sso.template.js.map +1 -0
  194. package/dist/templates/index.d.ts +2 -0
  195. package/dist/templates/index.d.ts.map +1 -0
  196. package/dist/templates/index.js +2 -0
  197. package/dist/templates/index.js.map +1 -0
  198. package/dist/templates/init_types.template.d.ts +17 -0
  199. package/dist/templates/init_types.template.d.ts.map +1 -0
  200. package/dist/templates/init_types.template.js +2 -0
  201. package/dist/templates/init_types.template.js.map +1 -0
  202. package/dist/templates/model.template.d.ts +17 -0
  203. package/dist/templates/model.template.d.ts.map +1 -0
  204. package/dist/templates/model.template.js +2 -0
  205. package/dist/templates/model.template.js.map +1 -0
  206. package/dist/templates/model_test.template.d.ts +17 -0
  207. package/dist/templates/model_test.template.d.ts.map +1 -0
  208. package/dist/templates/model_test.template.js +2 -0
  209. package/dist/templates/model_test.template.js.map +1 -0
  210. package/dist/templates/service.template.d.ts +29 -0
  211. package/dist/templates/service.template.d.ts.map +1 -0
  212. package/dist/templates/service.template.js +2 -0
  213. package/dist/templates/service.template.js.map +1 -0
  214. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  215. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  216. package/dist/templates/view_enums_buttonset.template.js +2 -0
  217. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  218. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  219. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  220. package/dist/templates/view_enums_dropdown.template.js +2 -0
  221. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  222. package/dist/templates/view_enums_select.template.d.ts +17 -0
  223. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  224. package/dist/templates/view_enums_select.template.js +2 -0
  225. package/dist/templates/view_enums_select.template.js.map +1 -0
  226. package/dist/templates/view_form.template.d.ts +26 -0
  227. package/dist/templates/view_form.template.d.ts.map +1 -0
  228. package/dist/templates/view_form.template.js +2 -0
  229. package/dist/templates/view_form.template.js.map +1 -0
  230. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  231. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  232. package/dist/templates/view_id_all_select.template.js +2 -0
  233. package/dist/templates/view_id_all_select.template.js.map +1 -0
  234. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  235. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  236. package/dist/templates/view_id_async_select.template.js +2 -0
  237. package/dist/templates/view_id_async_select.template.js.map +1 -0
  238. package/dist/templates/view_list.template.d.ts +38 -0
  239. package/dist/templates/view_list.template.d.ts.map +1 -0
  240. package/dist/templates/view_list.template.js +2 -0
  241. package/dist/templates/view_list.template.js.map +1 -0
  242. package/dist/templates/view_list_columns.template.d.ts +17 -0
  243. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  244. package/dist/templates/view_list_columns.template.js +2 -0
  245. package/dist/templates/view_list_columns.template.js.map +1 -0
  246. package/dist/templates/view_search_input.template.d.ts +17 -0
  247. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  248. package/dist/templates/view_search_input.template.js +2 -0
  249. package/dist/templates/view_search_input.template.js.map +1 -0
  250. package/dist/testing/_relation-graph.d.ts +7 -0
  251. package/dist/testing/_relation-graph.d.ts.map +1 -0
  252. package/dist/testing/_relation-graph.js +2 -0
  253. package/dist/testing/_relation-graph.js.map +1 -0
  254. package/dist/testing/fixture-manager.d.ts +35 -0
  255. package/dist/testing/fixture-manager.d.ts.map +1 -0
  256. package/dist/testing/fixture-manager.js +2 -0
  257. package/dist/testing/fixture-manager.js.map +1 -0
  258. package/dist/types/types.d.ts +609 -0
  259. package/dist/types/types.d.ts.map +1 -0
  260. package/dist/types/types.js +2 -0
  261. package/dist/types/types.js.map +1 -0
  262. package/dist/typings/knex.d.js +2 -0
  263. package/dist/typings/knex.d.js.map +1 -0
  264. package/dist/utils/async-utils.d.ts +25 -0
  265. package/dist/utils/async-utils.d.ts.map +1 -0
  266. package/dist/utils/async-utils.js +2 -0
  267. package/dist/utils/async-utils.js.map +1 -0
  268. package/dist/utils/controller.d.ts +9 -0
  269. package/dist/utils/controller.d.ts.map +1 -0
  270. package/dist/utils/controller.js +2 -0
  271. package/dist/utils/controller.js.map +1 -0
  272. package/dist/utils/fs-utils.d.ts +9 -0
  273. package/dist/utils/fs-utils.d.ts.map +1 -0
  274. package/dist/utils/fs-utils.js +2 -0
  275. package/dist/utils/fs-utils.js.map +1 -0
  276. package/dist/utils/lodash-able.d.ts +2 -0
  277. package/dist/utils/lodash-able.d.ts.map +1 -0
  278. package/dist/utils/lodash-able.js +2 -0
  279. package/dist/utils/lodash-able.js.map +1 -0
  280. package/dist/utils/model.d.ts +17 -0
  281. package/dist/utils/model.d.ts.map +1 -0
  282. package/dist/utils/model.js +2 -0
  283. package/dist/utils/model.js.map +1 -0
  284. package/dist/utils/sql-parser.d.ts +4 -0
  285. package/dist/utils/sql-parser.d.ts.map +1 -0
  286. package/dist/utils/sql-parser.js +2 -0
  287. package/dist/utils/sql-parser.js.map +1 -0
  288. package/dist/utils/utils.d.ts +9 -0
  289. package/dist/utils/utils.d.ts.map +1 -0
  290. package/dist/utils/utils.js +2 -0
  291. package/dist/utils/utils.js.map +1 -0
  292. package/dist/utils/zod-error.d.ts +8 -0
  293. package/dist/utils/zod-error.d.ts.map +1 -0
  294. package/dist/utils/zod-error.js +2 -0
  295. package/dist/utils/zod-error.js.map +1 -0
  296. package/nodemon.json +6 -0
  297. package/package.json +29 -44
  298. package/src/api/base-frame.ts +3 -4
  299. package/src/api/caster.ts +22 -23
  300. package/src/api/code-converters.ts +170 -134
  301. package/src/api/context.ts +13 -6
  302. package/src/api/decorators.ts +146 -20
  303. package/src/api/index.ts +2 -0
  304. package/src/api/sonamu.ts +374 -165
  305. package/src/bin/build-config.ts +5 -0
  306. package/src/bin/cli-wrapper.ts +29 -40
  307. package/src/bin/cli.ts +132 -190
  308. package/src/database/_batch_update.ts +10 -15
  309. package/src/database/base-model.ts +300 -216
  310. package/src/database/db.ts +191 -21
  311. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  312. package/src/database/puri-wrapper.ts +129 -0
  313. package/src/database/puri.ts +808 -0
  314. package/src/database/puri.types.ts +222 -0
  315. package/src/database/transaction-context.ts +18 -0
  316. package/src/database/upsert-builder.ts +32 -35
  317. package/src/entity/entity-manager.ts +7 -15
  318. package/src/entity/entity.ts +9 -31
  319. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  320. package/src/file-storage/driver.ts +121 -0
  321. package/src/file-storage/file-storage.ts +100 -0
  322. package/src/index.ts +14 -11
  323. package/src/migration/code-generation.ts +777 -0
  324. package/src/migration/migration-set.ts +453 -0
  325. package/src/migration/migrator.ts +823 -0
  326. package/src/migration/types.ts +53 -0
  327. package/src/shared/web.shared.ts.txt +33 -2
  328. package/src/syncer/syncer.ts +294 -127
  329. package/src/templates/generated.template.ts +13 -1
  330. package/src/templates/generated_http.template.ts +15 -12
  331. package/src/templates/generated_sso.template.ts +50 -2
  332. package/src/templates/model.template.ts +138 -2
  333. package/src/templates/service.template.ts +0 -1
  334. package/src/templates/view_form.template.ts +11 -7
  335. package/src/templates/view_list.template.ts +12 -4
  336. package/src/testing/fixture-manager.ts +229 -174
  337. package/src/types/types.ts +102 -14
  338. package/src/utils/async-utils.ts +64 -0
  339. package/src/utils/fs-utils.ts +17 -0
  340. package/src/utils/model.ts +0 -2
  341. package/src/utils/utils.ts +14 -58
  342. package/src/utils/zod-error.ts +12 -176
  343. package/tsconfig.json +2 -0
  344. package/tsup.config.js +4 -2
  345. package/.pnp.cjs +0 -14363
  346. package/.pnp.loader.mjs +0 -2047
  347. package/.vscode/extensions.json +0 -6
  348. package/.vscode/settings.json +0 -9
  349. package/.yarnrc.yml +0 -5
  350. package/dist/chunk-QJFHDCBN.mjs.map +0 -1
  351. package/src/database/base-model.abstract.ts +0 -97
  352. package/src/database/db.abstract.ts +0 -75
  353. package/src/database/drivers/knex/base-model.ts +0 -55
  354. package/src/database/drivers/knex/client.ts +0 -209
  355. package/src/database/drivers/knex/db.ts +0 -232
  356. package/src/database/drivers/knex/generator.ts +0 -659
  357. package/src/database/drivers/kysely/base-model.ts +0 -89
  358. package/src/database/drivers/kysely/client.ts +0 -309
  359. package/src/database/drivers/kysely/db.ts +0 -238
  360. package/src/database/drivers/kysely/generator.ts +0 -714
  361. package/src/database/types.ts +0 -118
  362. package/src/entity/migrator.ts +0 -1400
  363. package/src/smd/smd-manager.ts +0 -139
  364. package/src/smd/smd.ts +0 -571
  365. package/src/templates/kysely_types.template.ts +0 -205
  366. /package/dist/{chunk-NI37CY4T.mjs.map → chunk-C3IPIF6O.mjs.map} +0 -0
  367. /package/dist/{chunk-DYFCACHD.js.map → chunk-EXHKSVTE.js.map} +0 -0
  368. /package/dist/{chunk-DDJ7T4MA.mjs.map → chunk-HGIBJYOU.mjs.map} +0 -0
  369. /package/dist/{chunk-NIFOTHBW.mjs.map → chunk-JKSOJRQA.mjs.map} +0 -0
  370. /package/dist/{chunk-CXAVBVKC.js.map → chunk-OTKKFP3Y.js.map} +0 -0
  371. /package/dist/{chunk-J6S43O7G.js.map → chunk-UZ2IY5VE.js.map} +0 -0
@@ -1,139 +0,0 @@
1
- import chalk from "chalk";
2
- import glob from "glob";
3
- import inflection from "inflection";
4
- import _ from "lodash";
5
- import path from "path";
6
- import { SMD } from "./smd";
7
- import { SMDInput } from "../types/types";
8
- import { Sonamu } from "../api/sonamu";
9
- import { EntityNamesRecord } from "../entity/entity-manager";
10
-
11
- type TableSpec = {
12
- name: string;
13
- uniqueColumns: string[];
14
- };
15
- class SMDManagerClass {
16
- private SMDs: Map<string, SMD> = new Map();
17
- public modulePaths: Map<string, string> = new Map();
18
- private tableSpecs: Map<string, TableSpec> = new Map();
19
- public isAutoloaded: boolean = false;
20
-
21
- // 경로 전달받아 모든 SMD 파일 로드
22
- async autoload(doSilent: boolean = false) {
23
- if (this.isAutoloaded) {
24
- return;
25
- }
26
- const pathPattern = path.join(
27
- Sonamu.apiRootPath,
28
- "/dist/application/**/*.smd.js"
29
- );
30
- !doSilent && console.log(chalk.yellow(`autoload ${pathPattern}`));
31
-
32
- return new Promise((resolve) => {
33
- glob.glob(path.resolve(pathPattern!), (_err, files) => {
34
- const importPaths = files.map((filePath) =>
35
- path.relative(__dirname, filePath)
36
- );
37
- Promise.all(
38
- importPaths.map(async (importPath) => {
39
- const imported = await import(importPath);
40
- Object.values(imported).map((smdInput) =>
41
- this.register(smdInput as SMDInput<string>)
42
- );
43
- return imported;
44
- })
45
- ).then(() => {
46
- resolve("ok");
47
- this.isAutoloaded = true;
48
- });
49
- });
50
- });
51
- }
52
-
53
- register(smdInput: SMDInput<string>): void {
54
- const smd = new SMD(smdInput);
55
- this.SMDs.set(smdInput.id, smd);
56
- }
57
-
58
- get(smdId: string): SMD {
59
- const smd = this.SMDs.get(smdId);
60
- if (smd === undefined) {
61
- throw new Error(`존재하지 않는 SMD 요청 ${smdId}`);
62
- }
63
-
64
- return smd;
65
- }
66
-
67
- exists(smdId: string): boolean {
68
- const smd = this.SMDs.get(smdId);
69
- return smd !== undefined;
70
- }
71
-
72
- getAllIds(): string[] {
73
- return Array.from(SMDManager.SMDs.keys());
74
- }
75
-
76
- getAllParentIds(): string[] {
77
- return this.getAllIds().filter((smdId) => {
78
- const smd = this.get(smdId);
79
- return smd.parentId === undefined;
80
- });
81
- }
82
-
83
- getChildrenIds(parentId: string): string[] {
84
- return this.getAllIds().filter((smdId) => {
85
- const smd = this.get(smdId);
86
- return smd.parentId === parentId;
87
- });
88
- }
89
-
90
- setModulePath(key: string, modulePath: string): void {
91
- // console.debug(chalk.cyan(`setModulePath :: ${key} :: ${modulePath}`));
92
- this.modulePaths.set(key, modulePath);
93
- }
94
-
95
- getModulePath(key: string): string {
96
- const modulePath = this.modulePaths.get(key);
97
- if (modulePath === undefined) {
98
- throw new Error(`존재하지 않는 모듈 패스 요청 ${key}`);
99
- }
100
-
101
- return modulePath;
102
- }
103
-
104
- setTableSpec(tableSpec: TableSpec) {
105
- this.tableSpecs.set(tableSpec.name, tableSpec);
106
- }
107
-
108
- getTableSpec(key: string): TableSpec {
109
- const tableSpec = this.tableSpecs.get(key);
110
- if (tableSpec === undefined) {
111
- throw new Error(`존재하지 않는 테이블 스펙 요청 ${key}`);
112
- }
113
-
114
- return tableSpec;
115
- }
116
-
117
- getNamesFromId(smdId: string): EntityNamesRecord {
118
- // entityId가 단복수 동형 단어인 경우 List 붙여서 생성
119
- const pluralized =
120
- inflection.pluralize(smdId) === smdId
121
- ? `${smdId}List`
122
- : inflection.pluralize(smdId);
123
-
124
- return {
125
- fs: inflection.dasherize(inflection.underscore(smdId)).toLowerCase(),
126
- fsPlural: inflection
127
- .dasherize(inflection.underscore(pluralized))
128
- .toLowerCase(),
129
- camel: inflection.camelize(smdId, true),
130
- camelPlural: inflection.camelize(pluralized, true),
131
- capital: smdId,
132
- capitalPlural: pluralized,
133
- upper: smdId.toUpperCase(),
134
- constant: inflection.underscore(smdId).toUpperCase(),
135
- };
136
- }
137
- }
138
-
139
- export const SMDManager = new SMDManagerClass();
package/src/smd/smd.ts DELETED
@@ -1,571 +0,0 @@
1
- import _ from "lodash";
2
- import {
3
- EntityProp,
4
- RelationProp,
5
- isRelationProp,
6
- SubsetQuery,
7
- isVirtualProp,
8
- isBelongsToOneRelationProp,
9
- isOneToOneRelationProp,
10
- isHasManyRelationProp,
11
- isManyToManyRelationProp,
12
- EntityPropNode,
13
- isEnumProp,
14
- StringProp,
15
- EntityIndex,
16
- EnumsLabelKo,
17
- SMDInput,
18
- } from "../types/types";
19
- import inflection from "inflection";
20
- import path from "path";
21
- import fs from "fs-extra";
22
- import { z } from "zod";
23
- import { Sonamu } from "../api/sonamu";
24
- import { SMDManager } from "./smd-manager";
25
-
26
- export class SMD {
27
- id: string;
28
- parentId?: string;
29
- table: string;
30
- title: string;
31
- names: {
32
- fs: string;
33
- module: string;
34
- };
35
- props: EntityProp[];
36
- propsDict: {
37
- [key: string]: EntityProp;
38
- };
39
- relations: {
40
- [key: string]: RelationProp;
41
- };
42
- indexes: EntityIndex[];
43
- subsets: {
44
- [key: string]: string[];
45
- };
46
- types: {
47
- [name: string]: z.ZodTypeAny;
48
- } = {};
49
- enums: {
50
- [name: string]: z.ZodEnum<any>;
51
- } = {};
52
- enumLabels: {
53
- [name: string]: EnumsLabelKo<string>;
54
- } = {};
55
-
56
- constructor({
57
- id,
58
- parentId,
59
- table,
60
- title,
61
- props,
62
- indexes,
63
- subsets,
64
- }: SMDInput<any>) {
65
- // id
66
- this.id = id;
67
- this.parentId = parentId;
68
- this.title = title ?? this.id;
69
- this.table = table ?? inflection.underscore(inflection.pluralize(id));
70
-
71
- // props
72
- if (props) {
73
- this.props = props.map((prop) => {
74
- if (isEnumProp(prop)) {
75
- if (prop.id.includes("$Model")) {
76
- prop.id = prop.id.replace("$Model", id);
77
- }
78
- }
79
- return prop;
80
- });
81
- this.propsDict = props.reduce((result, prop) => {
82
- return {
83
- ...result,
84
- [prop.name]: prop,
85
- };
86
- }, {});
87
-
88
- // relations
89
- this.relations = props
90
- .filter((prop) => isRelationProp(prop))
91
- .reduce((result, prop) => {
92
- return {
93
- ...result,
94
- [prop.name]: prop,
95
- };
96
- }, {});
97
- } else {
98
- this.props = [];
99
- this.propsDict = {};
100
- this.relations = {};
101
- }
102
-
103
- // indexes
104
- this.indexes = indexes ?? [];
105
-
106
- // subsets
107
- this.subsets = subsets ?? {};
108
-
109
- // names
110
- this.names = {
111
- fs:
112
- parentId === undefined
113
- ? inflection.dasherize(inflection.underscore(id)).toLowerCase()
114
- : inflection.dasherize(parentId).toLowerCase(),
115
- module: id,
116
- };
117
-
118
- this.registerModulePaths();
119
- this.registerTableSpecs();
120
- }
121
-
122
- /*
123
- subset SELECT/JOIN/LOADER 결과 리턴
124
- */
125
- getSubsetQuery(subsetKey: string): SubsetQuery {
126
- const subset = this.subsets[subsetKey];
127
-
128
- const result: SubsetQuery = this.resolveSubsetQuery("", subset);
129
- return result;
130
- }
131
-
132
- /*
133
- */
134
- resolveSubsetQuery(
135
- prefix: string,
136
- fields: string[],
137
- isAlreadyOuterJoined: boolean = false
138
- ): SubsetQuery {
139
- // prefix 치환 (prefix는 ToOneRelation이 복수로 붙은 경우 모두 __로 변경됨)
140
- prefix = prefix.replace(/\./g, "__");
141
-
142
- // 서브셋을 1뎁스만 분리하여 그룹핑
143
- const subsetGroup = _.groupBy(fields, (field) => {
144
- if (field.includes(".")) {
145
- const [rel] = field.split(".");
146
- return rel;
147
- } else {
148
- return "";
149
- }
150
- });
151
-
152
- const result = Object.keys(subsetGroup).reduce(
153
- (r, groupKey) => {
154
- const fields = subsetGroup[groupKey];
155
- // 현재 테이블 필드셋은 select, virtual에 추가하고 리턴
156
- if (groupKey === "") {
157
- const realFields = fields.filter(
158
- (field) => !isVirtualProp(this.propsDict[field])
159
- );
160
- const virtualFields = fields.filter((field) =>
161
- isVirtualProp(this.propsDict[field])
162
- );
163
-
164
- if (prefix === "") {
165
- // 현재 테이블인 경우
166
- r.select = r.select.concat(
167
- realFields.map((field) => `${this.table}.${field}`)
168
- );
169
- r.virtual = r.virtual.concat(virtualFields);
170
- } else {
171
- // 넘어온 테이블인 경우
172
- r.select = r.select.concat(
173
- realFields.map(
174
- (field) => `${prefix}.${field} as ${prefix}__${field}`
175
- )
176
- );
177
- }
178
-
179
- return r;
180
- }
181
-
182
- const relation = this.relations[groupKey];
183
- if (relation === undefined) {
184
- throw new Error(`존재하지 않는 relation 참조 ${groupKey}`);
185
- }
186
- const relSMD = SMDManager.get(relation.with);
187
-
188
- if (
189
- isOneToOneRelationProp(relation) ||
190
- isBelongsToOneRelationProp(relation)
191
- ) {
192
- // -One Relation: JOIN 으로 처리
193
- const relFields = fields.map((field) =>
194
- field.split(".").slice(1).join(".")
195
- );
196
-
197
- // -One Relation에서 id 필드만 참조하는 경우 릴레이션 넘기지 않고 리턴
198
- if (relFields.length === 1 && relFields[0] === "id") {
199
- if (prefix === "") {
200
- r.select = r.select.concat(`${this.table}.${groupKey}_id`);
201
- } else {
202
- r.select = r.select.concat(
203
- `${prefix}.${groupKey}_id as ${prefix}__${groupKey}_id`
204
- );
205
- }
206
- return r;
207
- }
208
-
209
- // innerOrOuter
210
- const innerOrOuter = (() => {
211
- if (isAlreadyOuterJoined) {
212
- return "outer";
213
- }
214
-
215
- if (isOneToOneRelationProp(relation)) {
216
- if (
217
- relation.hasJoinColumn === true &&
218
- (relation.nullable ?? false) === false
219
- ) {
220
- return "inner";
221
- } else {
222
- return "outer";
223
- }
224
- } else {
225
- if (relation.nullable) {
226
- return "outer";
227
- } else {
228
- return "inner";
229
- }
230
- }
231
- })();
232
- const relSubsetQuery = relSMD.resolveSubsetQuery(
233
- `${prefix !== "" ? prefix + "." : ""}${groupKey}`,
234
- relFields,
235
- innerOrOuter === "outer"
236
- );
237
- r.select = r.select.concat(relSubsetQuery.select);
238
- r.virtual = r.virtual.concat(relSubsetQuery.virtual);
239
-
240
- const joinAs = prefix === "" ? groupKey : prefix + "__" + groupKey;
241
- const fromTable = prefix === "" ? this.table : prefix;
242
-
243
- let joinClause;
244
- if (relation.customJoinClause) {
245
- joinClause = {
246
- custom: relation.customJoinClause,
247
- };
248
- } else {
249
- let from, to;
250
- if (isOneToOneRelationProp(relation)) {
251
- if (relation.hasJoinColumn) {
252
- from = `${fromTable}.${relation.name}_id`;
253
- to = `${joinAs}.id`;
254
- } else {
255
- from = `${fromTable}.id`;
256
- to = `${joinAs}.${inflection.underscore(
257
- this.names.fs.replace(/\-/g, "_")
258
- )}_id`;
259
- }
260
- } else {
261
- from = `${fromTable}.${relation.name}_id`;
262
- to = `${joinAs}.id`;
263
- }
264
- joinClause = {
265
- from,
266
- to,
267
- };
268
- }
269
-
270
- r.joins.push({
271
- as: joinAs,
272
- join: innerOrOuter,
273
- table: relSMD.table,
274
- ...joinClause,
275
- });
276
-
277
- // BelongsToOne 밑에 HasMany가 붙은 경우
278
- if (relSubsetQuery.loaders.length > 0) {
279
- const convertedLoaders = relSubsetQuery.loaders.map((loader) => {
280
- const newAs = [groupKey, loader.as].join("__");
281
- return {
282
- as: newAs,
283
- table: loader.table,
284
- manyJoin: loader.manyJoin,
285
- oneJoins: loader.oneJoins,
286
- select: loader.select,
287
- };
288
- });
289
-
290
- r.loaders = [...r.loaders, ...convertedLoaders];
291
- }
292
-
293
- r.joins = r.joins.concat(relSubsetQuery.joins);
294
- } else if (
295
- isHasManyRelationProp(relation) ||
296
- isManyToManyRelationProp(relation)
297
- ) {
298
- // -Many Relation: Loader 로 처리
299
- const relFields = fields.map((field) =>
300
- field.split(".").slice(1).join(".")
301
- );
302
- const relSubsetQuery = relSMD.resolveSubsetQuery("", relFields);
303
-
304
- let manyJoin: SubsetQuery["loaders"][number]["manyJoin"];
305
- if (isHasManyRelationProp(relation)) {
306
- manyJoin = {
307
- fromTable: this.table,
308
- fromCol: "id",
309
- idField: prefix === "" ? `id` : `${prefix}__id`,
310
- toTable: relSMD.table,
311
- toCol: relation.joinColumn,
312
- };
313
- } else if (isManyToManyRelationProp(relation)) {
314
- const [table1, table2] = relation.joinTable.split("__");
315
-
316
- manyJoin = {
317
- fromTable: this.table,
318
- fromCol: "id",
319
- idField: prefix === "" ? `id` : `${prefix}__id`,
320
- through: {
321
- table: relation.joinTable,
322
- fromCol: `${inflection.singularize(table1)}_id`,
323
- toCol: `${inflection.singularize(table2)}_id`,
324
- },
325
- toTable: relSMD.table,
326
- toCol: "id",
327
- };
328
- } else {
329
- throw new Error();
330
- }
331
-
332
- r.loaders.push({
333
- as: groupKey,
334
- table: relSMD.table,
335
- manyJoin,
336
- oneJoins: relSubsetQuery.joins,
337
- select: relSubsetQuery.select,
338
- loaders: relSubsetQuery.loaders,
339
- });
340
- }
341
-
342
- return r;
343
- },
344
- {
345
- select: [],
346
- virtual: [],
347
- joins: [],
348
- loaders: [],
349
- } as SubsetQuery
350
- );
351
- return result;
352
- }
353
-
354
- /*
355
- FieldExpr[] 을 SMDPropNode[] 로 변환
356
- */
357
- fieldExprsToPropNodes(
358
- fieldExprs: string[],
359
- smd: SMD = this
360
- ): EntityPropNode[] {
361
- const groups = fieldExprs.reduce(
362
- (result, fieldExpr) => {
363
- let key, value, elseExpr;
364
- if (fieldExpr.includes(".")) {
365
- [key, ...elseExpr] = fieldExpr.split(".");
366
- value = elseExpr.join(".");
367
- } else {
368
- key = "";
369
- value = fieldExpr;
370
- }
371
- result[key] = (result[key] ?? []).concat(value);
372
-
373
- return result;
374
- },
375
- {} as {
376
- [k: string]: string[];
377
- }
378
- );
379
-
380
- return Object.keys(groups)
381
- .map((key) => {
382
- const group = groups[key];
383
-
384
- // 일반 prop 처리
385
- if (key === "") {
386
- return group.map((propName) => {
387
- // uuid 개별 처리
388
- if (propName === "uuid") {
389
- return {
390
- nodeType: "plain" as const,
391
- prop: {
392
- type: "string",
393
- name: "uuid",
394
- length: 128,
395
- } as StringProp,
396
- children: [],
397
- };
398
- }
399
-
400
- const prop = smd.propsDict[propName];
401
- if (prop === undefined) {
402
- throw new Error(`${this.id} -- 잘못된 FieldExpr ${propName}`);
403
- }
404
- return {
405
- nodeType: "plain" as const,
406
- prop,
407
- children: [],
408
- };
409
- });
410
- }
411
-
412
- // relation prop 처리
413
- const prop = smd.propsDict[key];
414
- if (!isRelationProp(prop)) {
415
- throw new Error(`잘못된 FieldExpr ${key}.${group[0]}`);
416
- }
417
- const relSMD = SMDManager.get(prop.with);
418
-
419
- // relation -One 에 id 필드 하나인 경우
420
- if (isBelongsToOneRelationProp(prop) || isOneToOneRelationProp(prop)) {
421
- if (group.length == 1 && (group[0] === "id" || group[0] == "id?")) {
422
- // id 하나만 있는지 체크해서, 하나만 있으면 상위 prop으로 id를 리턴
423
- const idProp = relSMD.propsDict.id;
424
- return {
425
- nodeType: "plain" as const,
426
- prop: {
427
- ...idProp,
428
- name: key + "_id",
429
- nullable: prop.nullable,
430
- },
431
- children: [],
432
- };
433
- }
434
- }
435
-
436
- // -One 그외의 경우 object로 리턴
437
- // -Many의 경우 array로 리턴
438
- // Recursive 로 뎁스 처리
439
- const children = this.fieldExprsToPropNodes(group, relSMD);
440
- const nodeType =
441
- isBelongsToOneRelationProp(prop) || isOneToOneRelationProp(prop)
442
- ? ("object" as const)
443
- : ("array" as const);
444
-
445
- return {
446
- prop,
447
- children,
448
- nodeType,
449
- };
450
- })
451
- .flat();
452
- }
453
-
454
- getFieldExprs(
455
- prefix = "",
456
- maxDepth: number = 3,
457
- froms: string[] = []
458
- ): string[] {
459
- return this.props
460
- .map((prop) => {
461
- const propName = [prefix, prop.name].filter((v) => v !== "").join(".");
462
- if (propName === prefix) {
463
- return null;
464
- }
465
- if (isRelationProp(prop)) {
466
- if (maxDepth < 0) {
467
- return null;
468
- }
469
- if (froms.includes(prop.with)) {
470
- // 역방향 relation인 경우 제외
471
- return null;
472
- }
473
- // 정방향 relation인 경우 recursive 콜
474
- const relMd = SMDManager.get(prop.with);
475
- return relMd.getFieldExprs(propName, maxDepth - 1, [
476
- ...froms,
477
- this.id,
478
- ]);
479
- }
480
- return propName;
481
- })
482
- .flat()
483
- .filter((f) => f !== null) as string[];
484
- }
485
-
486
- registerModulePaths() {
487
- const basePath = `${this.names.fs}`;
488
-
489
- // base-scheme
490
- SMDManager.setModulePath(
491
- `${this.id}BaseSchema`,
492
- `${basePath}/${this.names.fs}.generated`
493
- );
494
-
495
- // subset
496
- if (Object.keys(this.subsets).length > 0) {
497
- SMDManager.setModulePath(
498
- `${this.id}SubsetKey`,
499
- `${basePath}/${this.names.fs}.generated`
500
- );
501
- SMDManager.setModulePath(
502
- `${this.id}SubsetMapping`,
503
- `${basePath}/${this.names.fs}.generated`
504
- );
505
- Object.keys(this.subsets).map((subsetKey) => {
506
- SMDManager.setModulePath(
507
- `${this.id}Subset${subsetKey.toUpperCase()}`,
508
- `${basePath}/${this.names.fs}.generated`
509
- );
510
- });
511
- }
512
-
513
- // types
514
- const typesModulePath = `${basePath}/${this.names.fs}.types`;
515
- const typesFileDistPath = path.join(
516
- Sonamu.apiRootPath,
517
- `dist/application/${typesModulePath}.js`
518
- );
519
-
520
- if (fs.existsSync(typesFileDistPath)) {
521
- const importPath = path.relative(__dirname, typesFileDistPath);
522
- import(importPath).then((t) => {
523
- this.types = Object.keys(t).reduce((result, key) => {
524
- SMDManager.setModulePath(key, typesModulePath);
525
- return {
526
- ...result,
527
- [key]: t[key],
528
- };
529
- }, {});
530
- });
531
- }
532
-
533
- // enums
534
- const enumsModulePath = `${basePath}/${this.names.fs}.enums`;
535
- const enumsFileDistPath = path.join(
536
- Sonamu.apiRootPath,
537
- `/dist/application/${enumsModulePath}.js`
538
- );
539
- if (fs.existsSync(enumsFileDistPath)) {
540
- const importPath = path.relative(__dirname, enumsFileDistPath);
541
- import(importPath).then((t) => {
542
- this.enums = Object.keys(t).reduce((result, key) => {
543
- SMDManager.setModulePath(key, enumsModulePath);
544
-
545
- // Enum Labels 별도 처리
546
- if (key === inflection.underscore(this.id).toUpperCase()) {
547
- this.enumLabels = t[key];
548
- }
549
- return {
550
- ...result,
551
- [key]: t[key],
552
- };
553
- }, {});
554
- });
555
- }
556
- }
557
-
558
- registerTableSpecs(): void {
559
- const uniqueColumns = _.uniq(
560
- this.indexes
561
- .filter((idx) => idx.type === "unique")
562
- .map((idx) => idx.columns)
563
- .flat()
564
- );
565
-
566
- SMDManager.setTableSpec({
567
- name: this.table,
568
- uniqueColumns,
569
- });
570
- }
571
- }