sonamu 0.4.14 → 0.5.1

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 (385) 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 +19 -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 +84 -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/bin/build-config.d.ts +9 -0
  31. package/dist/bin/build-config.d.ts.map +1 -0
  32. package/dist/bin/build-config.js +2 -0
  33. package/dist/bin/build-config.js.map +1 -0
  34. package/dist/bin/cli-wrapper.d.ts +2 -0
  35. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  36. package/dist/bin/cli-wrapper.js +1 -38
  37. package/dist/bin/cli-wrapper.js.map +1 -1
  38. package/dist/bin/cli.d.ts +2 -2
  39. package/dist/bin/cli.d.ts.map +1 -0
  40. package/dist/bin/cli.js +1 -903
  41. package/dist/bin/cli.js.map +1 -1
  42. package/dist/database/_batch_update.d.ts +15 -0
  43. package/dist/database/_batch_update.d.ts.map +1 -0
  44. package/dist/database/_batch_update.js +2 -0
  45. package/dist/database/_batch_update.js.map +1 -0
  46. package/dist/database/base-model.d.ts +48 -0
  47. package/dist/database/base-model.d.ts.map +1 -0
  48. package/dist/database/base-model.js +2 -0
  49. package/dist/database/base-model.js.map +1 -0
  50. package/dist/database/code-generator.d.ts +13 -0
  51. package/dist/database/code-generator.d.ts.map +1 -0
  52. package/dist/database/code-generator.js +2 -0
  53. package/dist/database/code-generator.js.map +1 -0
  54. package/dist/database/db.d.ts +40 -0
  55. package/dist/database/db.d.ts.map +1 -0
  56. package/dist/database/db.js +2 -0
  57. package/dist/database/db.js.map +1 -0
  58. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  59. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  60. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  61. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  62. package/dist/database/puri-wrapper.d.ts +34 -0
  63. package/dist/database/puri-wrapper.d.ts.map +1 -0
  64. package/dist/database/puri-wrapper.js +2 -0
  65. package/dist/database/puri-wrapper.js.map +1 -0
  66. package/dist/database/puri.d.ts +83 -0
  67. package/dist/database/puri.d.ts.map +1 -0
  68. package/dist/database/puri.js +2 -0
  69. package/dist/database/puri.js.map +1 -0
  70. package/dist/database/puri.types.d.ts +60 -0
  71. package/dist/database/puri.types.d.ts.map +1 -0
  72. package/dist/database/puri.types.js +2 -0
  73. package/dist/database/puri.types.js.map +1 -0
  74. package/dist/database/transaction-context.d.ts +9 -0
  75. package/dist/database/transaction-context.d.ts.map +1 -0
  76. package/dist/database/transaction-context.js +2 -0
  77. package/dist/database/transaction-context.js.map +1 -0
  78. package/dist/database/upsert-builder.d.ts +34 -0
  79. package/dist/database/upsert-builder.d.ts.map +1 -0
  80. package/dist/database/upsert-builder.js +2 -0
  81. package/dist/database/upsert-builder.js.map +1 -0
  82. package/dist/entity/entity-manager.d.ts +32 -0
  83. package/dist/entity/entity-manager.d.ts.map +1 -0
  84. package/dist/entity/entity-manager.js +2 -0
  85. package/dist/entity/entity-manager.js.map +1 -0
  86. package/dist/entity/entity-utils.d.ts +61 -0
  87. package/dist/entity/entity-utils.d.ts.map +1 -0
  88. package/dist/entity/entity-utils.js +2 -0
  89. package/dist/entity/entity-utils.js.map +1 -0
  90. package/dist/entity/entity.d.ts +62 -0
  91. package/dist/entity/entity.d.ts.map +1 -0
  92. package/dist/entity/entity.js +2 -0
  93. package/dist/entity/entity.js.map +1 -0
  94. package/dist/entity/migrator.d.ts +135 -0
  95. package/dist/entity/migrator.d.ts.map +1 -0
  96. package/dist/entity/migrator.js +2 -0
  97. package/dist/entity/migrator.js.map +1 -0
  98. package/dist/exceptions/error-handler.d.ts +3 -0
  99. package/dist/exceptions/error-handler.d.ts.map +1 -0
  100. package/dist/exceptions/error-handler.js +2 -0
  101. package/dist/exceptions/error-handler.js.map +1 -0
  102. package/dist/exceptions/so-exceptions.d.ts +48 -0
  103. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  104. package/dist/exceptions/so-exceptions.js +2 -0
  105. package/dist/exceptions/so-exceptions.js.map +1 -0
  106. package/dist/file-storage/driver.d.ts +48 -0
  107. package/dist/file-storage/driver.d.ts.map +1 -0
  108. package/dist/file-storage/driver.js +2 -0
  109. package/dist/file-storage/driver.js.map +1 -0
  110. package/dist/file-storage/file-storage.d.ts +50 -0
  111. package/dist/file-storage/file-storage.d.ts.map +1 -0
  112. package/dist/file-storage/file-storage.js +2 -0
  113. package/dist/file-storage/file-storage.js.map +1 -0
  114. package/dist/index.d.ts +23 -813
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +1 -433
  117. package/dist/index.js.map +1 -1
  118. package/dist/migration/code-generation.d.ts +15 -0
  119. package/dist/migration/code-generation.d.ts.map +1 -0
  120. package/dist/migration/code-generation.js +2 -0
  121. package/dist/migration/code-generation.js.map +1 -0
  122. package/dist/migration/migration-set.d.ts +17 -0
  123. package/dist/migration/migration-set.d.ts.map +1 -0
  124. package/dist/migration/migration-set.js +2 -0
  125. package/dist/migration/migration-set.js.map +1 -0
  126. package/dist/migration/migrator.d.ts +130 -0
  127. package/dist/migration/migrator.d.ts.map +1 -0
  128. package/dist/migration/migrator.js +2 -0
  129. package/dist/migration/migrator.js.map +1 -0
  130. package/dist/migration/types.d.ts +52 -0
  131. package/dist/migration/types.d.ts.map +1 -0
  132. package/dist/migration/types.js +2 -0
  133. package/dist/migration/types.js.map +1 -0
  134. package/dist/stream/index.d.ts +2 -0
  135. package/dist/stream/index.d.ts.map +1 -0
  136. package/dist/stream/index.js +2 -0
  137. package/dist/stream/index.js.map +1 -0
  138. package/dist/stream/sse.d.ts +13 -0
  139. package/dist/stream/sse.d.ts.map +1 -0
  140. package/dist/stream/sse.js +2 -0
  141. package/dist/stream/sse.js.map +1 -0
  142. package/dist/syncer/index.d.ts +2 -0
  143. package/dist/syncer/index.d.ts.map +1 -0
  144. package/dist/syncer/index.js +2 -0
  145. package/dist/syncer/index.js.map +1 -0
  146. package/dist/syncer/syncer.d.ts +127 -0
  147. package/dist/syncer/syncer.d.ts.map +1 -0
  148. package/dist/syncer/syncer.js +2 -0
  149. package/dist/syncer/syncer.js.map +1 -0
  150. package/dist/templates/base-template.d.ts +13 -0
  151. package/dist/templates/base-template.d.ts.map +1 -0
  152. package/dist/templates/base-template.js +2 -0
  153. package/dist/templates/base-template.js.map +1 -0
  154. package/dist/templates/entity.template.d.ts +17 -0
  155. package/dist/templates/entity.template.d.ts.map +1 -0
  156. package/dist/templates/entity.template.js +2 -0
  157. package/dist/templates/entity.template.js.map +1 -0
  158. package/dist/templates/generated.template.d.ts +27 -0
  159. package/dist/templates/generated.template.d.ts.map +1 -0
  160. package/dist/templates/generated.template.js +2 -0
  161. package/dist/templates/generated.template.js.map +1 -0
  162. package/dist/templates/generated_http.template.d.ts +24 -0
  163. package/dist/templates/generated_http.template.d.ts.map +1 -0
  164. package/dist/templates/generated_http.template.js +2 -0
  165. package/dist/templates/generated_http.template.js.map +1 -0
  166. package/dist/templates/generated_sso.template.d.ts +20 -0
  167. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  168. package/dist/templates/generated_sso.template.js +2 -0
  169. package/dist/templates/generated_sso.template.js.map +1 -0
  170. package/dist/templates/index.d.ts +2 -0
  171. package/dist/templates/index.d.ts.map +1 -0
  172. package/dist/templates/index.js +2 -0
  173. package/dist/templates/index.js.map +1 -0
  174. package/dist/templates/init_types.template.d.ts +17 -0
  175. package/dist/templates/init_types.template.d.ts.map +1 -0
  176. package/dist/templates/init_types.template.js +2 -0
  177. package/dist/templates/init_types.template.js.map +1 -0
  178. package/dist/templates/model.template.d.ts +17 -0
  179. package/dist/templates/model.template.d.ts.map +1 -0
  180. package/dist/templates/model.template.js +2 -0
  181. package/dist/templates/model.template.js.map +1 -0
  182. package/dist/templates/model_test.template.d.ts +17 -0
  183. package/dist/templates/model_test.template.d.ts.map +1 -0
  184. package/dist/templates/model_test.template.js +2 -0
  185. package/dist/templates/model_test.template.js.map +1 -0
  186. package/dist/templates/service.template.d.ts +29 -0
  187. package/dist/templates/service.template.d.ts.map +1 -0
  188. package/dist/templates/service.template.js +2 -0
  189. package/dist/templates/service.template.js.map +1 -0
  190. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  191. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  192. package/dist/templates/view_enums_buttonset.template.js +2 -0
  193. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  194. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  195. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  196. package/dist/templates/view_enums_dropdown.template.js +2 -0
  197. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  198. package/dist/templates/view_enums_select.template.d.ts +17 -0
  199. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  200. package/dist/templates/view_enums_select.template.js +2 -0
  201. package/dist/templates/view_enums_select.template.js.map +1 -0
  202. package/dist/templates/view_form.template.d.ts +26 -0
  203. package/dist/templates/view_form.template.d.ts.map +1 -0
  204. package/dist/templates/view_form.template.js +2 -0
  205. package/dist/templates/view_form.template.js.map +1 -0
  206. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  207. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  208. package/dist/templates/view_id_all_select.template.js +2 -0
  209. package/dist/templates/view_id_all_select.template.js.map +1 -0
  210. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  211. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  212. package/dist/templates/view_id_async_select.template.js +2 -0
  213. package/dist/templates/view_id_async_select.template.js.map +1 -0
  214. package/dist/templates/view_list.template.d.ts +38 -0
  215. package/dist/templates/view_list.template.d.ts.map +1 -0
  216. package/dist/templates/view_list.template.js +2 -0
  217. package/dist/templates/view_list.template.js.map +1 -0
  218. package/dist/templates/view_list_columns.template.d.ts +17 -0
  219. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  220. package/dist/templates/view_list_columns.template.js +2 -0
  221. package/dist/templates/view_list_columns.template.js.map +1 -0
  222. package/dist/templates/view_search_input.template.d.ts +17 -0
  223. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  224. package/dist/templates/view_search_input.template.js +2 -0
  225. package/dist/templates/view_search_input.template.js.map +1 -0
  226. package/dist/testing/_relation-graph.d.ts +7 -0
  227. package/dist/testing/_relation-graph.d.ts.map +1 -0
  228. package/dist/testing/_relation-graph.js +2 -0
  229. package/dist/testing/_relation-graph.js.map +1 -0
  230. package/dist/testing/fixture-manager.d.ts +35 -0
  231. package/dist/testing/fixture-manager.d.ts.map +1 -0
  232. package/dist/testing/fixture-manager.js +2 -0
  233. package/dist/testing/fixture-manager.js.map +1 -0
  234. package/dist/types/types.d.ts +611 -0
  235. package/dist/types/types.d.ts.map +1 -0
  236. package/dist/types/types.js +2 -0
  237. package/dist/types/types.js.map +1 -0
  238. package/dist/typings/knex.d.js +2 -0
  239. package/dist/typings/knex.d.js.map +1 -0
  240. package/dist/utils/async-utils.d.ts +25 -0
  241. package/dist/utils/async-utils.d.ts.map +1 -0
  242. package/dist/utils/async-utils.js +2 -0
  243. package/dist/utils/async-utils.js.map +1 -0
  244. package/dist/utils/controller.d.ts +9 -0
  245. package/dist/utils/controller.d.ts.map +1 -0
  246. package/dist/utils/controller.js +2 -0
  247. package/dist/utils/controller.js.map +1 -0
  248. package/dist/utils/fs-utils.d.ts +9 -0
  249. package/dist/utils/fs-utils.d.ts.map +1 -0
  250. package/dist/utils/fs-utils.js +2 -0
  251. package/dist/utils/fs-utils.js.map +1 -0
  252. package/dist/utils/lodash-able.d.ts +2 -0
  253. package/dist/utils/lodash-able.d.ts.map +1 -0
  254. package/dist/utils/lodash-able.js +2 -0
  255. package/dist/utils/lodash-able.js.map +1 -0
  256. package/dist/utils/model.d.ts +17 -0
  257. package/dist/utils/model.d.ts.map +1 -0
  258. package/dist/utils/model.js +2 -0
  259. package/dist/utils/model.js.map +1 -0
  260. package/dist/utils/sql-parser.d.ts +4 -0
  261. package/dist/utils/sql-parser.d.ts.map +1 -0
  262. package/dist/utils/sql-parser.js +2 -0
  263. package/dist/utils/sql-parser.js.map +1 -0
  264. package/dist/utils/utils.d.ts +9 -0
  265. package/dist/utils/utils.d.ts.map +1 -0
  266. package/dist/utils/utils.js +2 -0
  267. package/dist/utils/utils.js.map +1 -0
  268. package/dist/utils/zod-error.d.ts +8 -0
  269. package/dist/utils/zod-error.d.ts.map +1 -0
  270. package/dist/utils/zod-error.js +2 -0
  271. package/dist/utils/zod-error.js.map +1 -0
  272. package/nodemon.json +6 -0
  273. package/package.json +32 -45
  274. package/src/api/base-frame.ts +3 -4
  275. package/src/api/caster.ts +22 -23
  276. package/src/api/code-converters.ts +170 -134
  277. package/src/api/context.ts +15 -3
  278. package/src/api/decorators.ts +144 -20
  279. package/src/api/index.ts +2 -0
  280. package/src/api/sonamu.ts +408 -165
  281. package/src/bin/build-config.ts +10 -0
  282. package/src/bin/cli-wrapper.ts +35 -32
  283. package/src/bin/cli.ts +141 -204
  284. package/src/database/_batch_update.ts +10 -15
  285. package/src/database/base-model.ts +326 -216
  286. package/src/database/db.ts +191 -21
  287. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  288. package/src/database/puri-wrapper.ts +129 -0
  289. package/src/database/puri.ts +808 -0
  290. package/src/database/puri.types.ts +222 -0
  291. package/src/database/transaction-context.ts +18 -0
  292. package/src/database/upsert-builder.ts +32 -35
  293. package/src/entity/entity-manager.ts +7 -15
  294. package/src/entity/entity.ts +9 -31
  295. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  296. package/src/file-storage/driver.ts +131 -0
  297. package/src/file-storage/file-storage.ts +100 -0
  298. package/src/index.ts +15 -11
  299. package/src/migration/code-generation.ts +777 -0
  300. package/src/migration/migration-set.ts +453 -0
  301. package/src/migration/migrator.ts +823 -0
  302. package/src/migration/types.ts +53 -0
  303. package/src/shared/web.shared.ts.txt +33 -2
  304. package/src/stream/index.ts +1 -0
  305. package/src/stream/sse.ts +49 -0
  306. package/src/syncer/syncer.ts +294 -127
  307. package/src/templates/generated.template.ts +13 -1
  308. package/src/templates/generated_http.template.ts +15 -12
  309. package/src/templates/generated_sso.template.ts +50 -2
  310. package/src/templates/model.template.ts +138 -2
  311. package/src/templates/service.template.ts +0 -1
  312. package/src/templates/view_form.template.ts +11 -7
  313. package/src/templates/view_list.template.ts +12 -4
  314. package/src/testing/fixture-manager.ts +229 -174
  315. package/src/types/types.ts +108 -14
  316. package/src/utils/async-utils.ts +64 -0
  317. package/src/utils/fs-utils.ts +17 -0
  318. package/src/utils/model.ts +0 -2
  319. package/src/utils/utils.ts +14 -58
  320. package/src/utils/zod-error.ts +12 -176
  321. package/tsconfig.json +6 -0
  322. package/tsup.config.js +4 -2
  323. package/.pnp.cjs +0 -14363
  324. package/.pnp.loader.mjs +0 -2047
  325. package/.vscode/extensions.json +0 -6
  326. package/.vscode/settings.json +0 -9
  327. package/.yarnrc.yml +0 -5
  328. package/dist/base-model-CEB0H0aO.d.mts +0 -43
  329. package/dist/base-model-CrqDMYhI.d.ts +0 -43
  330. package/dist/bin/cli-wrapper.d.mts +0 -1
  331. package/dist/bin/cli-wrapper.mjs +0 -43
  332. package/dist/bin/cli-wrapper.mjs.map +0 -1
  333. package/dist/bin/cli.d.mts +0 -2
  334. package/dist/bin/cli.mjs +0 -907
  335. package/dist/bin/cli.mjs.map +0 -1
  336. package/dist/chunk-2WAC2GER.js +0 -7625
  337. package/dist/chunk-2WAC2GER.js.map +0 -1
  338. package/dist/chunk-C3IPIF6O.mjs +0 -1581
  339. package/dist/chunk-C3IPIF6O.mjs.map +0 -1
  340. package/dist/chunk-EXHKSVTE.js +0 -280
  341. package/dist/chunk-EXHKSVTE.js.map +0 -1
  342. package/dist/chunk-FCERKIIF.mjs +0 -7623
  343. package/dist/chunk-FCERKIIF.mjs.map +0 -1
  344. package/dist/chunk-HGIBJYOU.mjs +0 -231
  345. package/dist/chunk-HGIBJYOU.mjs.map +0 -1
  346. package/dist/chunk-JKSOJRQA.mjs +0 -280
  347. package/dist/chunk-JKSOJRQA.mjs.map +0 -1
  348. package/dist/chunk-OTKKFP3Y.js +0 -1581
  349. package/dist/chunk-OTKKFP3Y.js.map +0 -1
  350. package/dist/chunk-PTFDTOJU.mjs +0 -19
  351. package/dist/chunk-PTFDTOJU.mjs.map +0 -1
  352. package/dist/chunk-UZ2IY5VE.js +0 -231
  353. package/dist/chunk-UZ2IY5VE.js.map +0 -1
  354. package/dist/database/drivers/knex/base-model.d.mts +0 -16
  355. package/dist/database/drivers/knex/base-model.d.ts +0 -16
  356. package/dist/database/drivers/knex/base-model.js +0 -55
  357. package/dist/database/drivers/knex/base-model.js.map +0 -1
  358. package/dist/database/drivers/knex/base-model.mjs +0 -56
  359. package/dist/database/drivers/knex/base-model.mjs.map +0 -1
  360. package/dist/database/drivers/kysely/base-model.d.mts +0 -22
  361. package/dist/database/drivers/kysely/base-model.d.ts +0 -22
  362. package/dist/database/drivers/kysely/base-model.js +0 -64
  363. package/dist/database/drivers/kysely/base-model.js.map +0 -1
  364. package/dist/database/drivers/kysely/base-model.mjs +0 -65
  365. package/dist/database/drivers/kysely/base-model.mjs.map +0 -1
  366. package/dist/index.d.mts +0 -813
  367. package/dist/index.mjs +0 -435
  368. package/dist/index.mjs.map +0 -1
  369. package/dist/model-aFgomcdc.d.mts +0 -1112
  370. package/dist/model-aFgomcdc.d.ts +0 -1112
  371. package/src/database/base-model.abstract.ts +0 -97
  372. package/src/database/db.abstract.ts +0 -75
  373. package/src/database/drivers/knex/base-model.ts +0 -55
  374. package/src/database/drivers/knex/client.ts +0 -209
  375. package/src/database/drivers/knex/db.ts +0 -232
  376. package/src/database/drivers/knex/generator.ts +0 -659
  377. package/src/database/drivers/kysely/base-model.ts +0 -89
  378. package/src/database/drivers/kysely/client.ts +0 -309
  379. package/src/database/drivers/kysely/db.ts +0 -238
  380. package/src/database/drivers/kysely/generator.ts +0 -714
  381. package/src/database/types.ts +0 -118
  382. package/src/entity/migrator.ts +0 -1400
  383. package/src/smd/smd-manager.ts +0 -139
  384. package/src/smd/smd.ts +0 -571
  385. package/src/templates/kysely_types.template.ts +0 -205
package/dist/bin/cli.js CHANGED
@@ -1,904 +1,2 @@
1
- "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2;
2
-
3
-
4
- var _chunkOTKKFP3Yjs = require('../chunk-OTKKFP3Y.js');
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
- var _chunk2WAC2GERjs = require('../chunk-2WAC2GER.js');
19
-
20
- // src/bin/cli.ts
21
- var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
22
- var _dotenv = require('dotenv'); var _dotenv2 = _interopRequireDefault(_dotenv);
23
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
24
- var _tsicli = require('tsicli');
25
- var _child_process = require('child_process');
26
- var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
27
- var _inflection = require('inflection'); var _inflection2 = _interopRequireDefault(_inflection);
28
- var _prettier = require('prettier'); var _prettier2 = _interopRequireDefault(_prettier);
29
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
30
- var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
31
-
32
- // src/smd/smd-manager.ts
33
-
34
- var _glob = require('glob'); var _glob2 = _interopRequireDefault(_glob);
35
-
36
-
37
-
38
- // src/smd/smd.ts
39
-
40
-
41
-
42
-
43
- var SMD = (_class = class {
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
- __init() {this.types = {}}
55
- __init2() {this.enums = {}}
56
- __init3() {this.enumLabels = {}}
57
- constructor({
58
- id,
59
- parentId,
60
- table,
61
- title,
62
- props,
63
- indexes,
64
- subsets
65
- }) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
66
- this.id = id;
67
- this.parentId = parentId;
68
- this.title = _nullishCoalesce(title, () => ( this.id));
69
- this.table = _nullishCoalesce(table, () => ( _inflection2.default.underscore(_inflection2.default.pluralize(id))));
70
- if (props) {
71
- this.props = props.map((prop) => {
72
- if (_chunk2WAC2GERjs.isEnumProp.call(void 0, prop)) {
73
- if (prop.id.includes("$Model")) {
74
- prop.id = prop.id.replace("$Model", id);
75
- }
76
- }
77
- return prop;
78
- });
79
- this.propsDict = props.reduce((result, prop) => {
80
- return {
81
- ...result,
82
- [prop.name]: prop
83
- };
84
- }, {});
85
- this.relations = props.filter((prop) => _chunk2WAC2GERjs.isRelationProp.call(void 0, prop)).reduce((result, prop) => {
86
- return {
87
- ...result,
88
- [prop.name]: prop
89
- };
90
- }, {});
91
- } else {
92
- this.props = [];
93
- this.propsDict = {};
94
- this.relations = {};
95
- }
96
- this.indexes = _nullishCoalesce(indexes, () => ( []));
97
- this.subsets = _nullishCoalesce(subsets, () => ( {}));
98
- this.names = {
99
- fs: parentId === void 0 ? _inflection2.default.dasherize(_inflection2.default.underscore(id)).toLowerCase() : _inflection2.default.dasherize(parentId).toLowerCase(),
100
- module: id
101
- };
102
- this.registerModulePaths();
103
- this.registerTableSpecs();
104
- }
105
- /*
106
- subset SELECT/JOIN/LOADER 결과 리턴
107
- */
108
- getSubsetQuery(subsetKey) {
109
- const subset = this.subsets[subsetKey];
110
- const result = this.resolveSubsetQuery("", subset);
111
- return result;
112
- }
113
- /*
114
- */
115
- resolveSubsetQuery(prefix, fields, isAlreadyOuterJoined = false) {
116
- prefix = prefix.replace(/\./g, "__");
117
- const subsetGroup = _lodash2.default.groupBy(fields, (field) => {
118
- if (field.includes(".")) {
119
- const [rel] = field.split(".");
120
- return rel;
121
- } else {
122
- return "";
123
- }
124
- });
125
- const result = Object.keys(subsetGroup).reduce(
126
- (r, groupKey) => {
127
- const fields2 = subsetGroup[groupKey];
128
- if (groupKey === "") {
129
- const realFields = fields2.filter(
130
- (field) => !_chunk2WAC2GERjs.isVirtualProp.call(void 0, this.propsDict[field])
131
- );
132
- const virtualFields = fields2.filter(
133
- (field) => _chunk2WAC2GERjs.isVirtualProp.call(void 0, this.propsDict[field])
134
- );
135
- if (prefix === "") {
136
- r.select = r.select.concat(
137
- realFields.map((field) => `${this.table}.${field}`)
138
- );
139
- r.virtual = r.virtual.concat(virtualFields);
140
- } else {
141
- r.select = r.select.concat(
142
- realFields.map(
143
- (field) => `${prefix}.${field} as ${prefix}__${field}`
144
- )
145
- );
146
- }
147
- return r;
148
- }
149
- const relation = this.relations[groupKey];
150
- if (relation === void 0) {
151
- throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 relation \uCC38\uC870 ${groupKey}`);
152
- }
153
- const relSMD = SMDManager.get(relation.with);
154
- if (_chunk2WAC2GERjs.isOneToOneRelationProp.call(void 0, relation) || _chunk2WAC2GERjs.isBelongsToOneRelationProp.call(void 0, relation)) {
155
- const relFields = fields2.map(
156
- (field) => field.split(".").slice(1).join(".")
157
- );
158
- if (relFields.length === 1 && relFields[0] === "id") {
159
- if (prefix === "") {
160
- r.select = r.select.concat(`${this.table}.${groupKey}_id`);
161
- } else {
162
- r.select = r.select.concat(
163
- `${prefix}.${groupKey}_id as ${prefix}__${groupKey}_id`
164
- );
165
- }
166
- return r;
167
- }
168
- const innerOrOuter = (() => {
169
- if (isAlreadyOuterJoined) {
170
- return "outer";
171
- }
172
- if (_chunk2WAC2GERjs.isOneToOneRelationProp.call(void 0, relation)) {
173
- if (relation.hasJoinColumn === true && (_nullishCoalesce(relation.nullable, () => ( false))) === false) {
174
- return "inner";
175
- } else {
176
- return "outer";
177
- }
178
- } else {
179
- if (relation.nullable) {
180
- return "outer";
181
- } else {
182
- return "inner";
183
- }
184
- }
185
- })();
186
- const relSubsetQuery = relSMD.resolveSubsetQuery(
187
- `${prefix !== "" ? prefix + "." : ""}${groupKey}`,
188
- relFields,
189
- innerOrOuter === "outer"
190
- );
191
- r.select = r.select.concat(relSubsetQuery.select);
192
- r.virtual = r.virtual.concat(relSubsetQuery.virtual);
193
- const joinAs = prefix === "" ? groupKey : prefix + "__" + groupKey;
194
- const fromTable = prefix === "" ? this.table : prefix;
195
- let joinClause;
196
- if (relation.customJoinClause) {
197
- joinClause = {
198
- custom: relation.customJoinClause
199
- };
200
- } else {
201
- let from, to;
202
- if (_chunk2WAC2GERjs.isOneToOneRelationProp.call(void 0, relation)) {
203
- if (relation.hasJoinColumn) {
204
- from = `${fromTable}.${relation.name}_id`;
205
- to = `${joinAs}.id`;
206
- } else {
207
- from = `${fromTable}.id`;
208
- to = `${joinAs}.${_inflection2.default.underscore(
209
- this.names.fs.replace(/\-/g, "_")
210
- )}_id`;
211
- }
212
- } else {
213
- from = `${fromTable}.${relation.name}_id`;
214
- to = `${joinAs}.id`;
215
- }
216
- joinClause = {
217
- from,
218
- to
219
- };
220
- }
221
- r.joins.push({
222
- as: joinAs,
223
- join: innerOrOuter,
224
- table: relSMD.table,
225
- ...joinClause
226
- });
227
- if (relSubsetQuery.loaders.length > 0) {
228
- const convertedLoaders = relSubsetQuery.loaders.map((loader) => {
229
- const newAs = [groupKey, loader.as].join("__");
230
- return {
231
- as: newAs,
232
- table: loader.table,
233
- manyJoin: loader.manyJoin,
234
- oneJoins: loader.oneJoins,
235
- select: loader.select
236
- };
237
- });
238
- r.loaders = [...r.loaders, ...convertedLoaders];
239
- }
240
- r.joins = r.joins.concat(relSubsetQuery.joins);
241
- } else if (_chunk2WAC2GERjs.isHasManyRelationProp.call(void 0, relation) || _chunk2WAC2GERjs.isManyToManyRelationProp.call(void 0, relation)) {
242
- const relFields = fields2.map(
243
- (field) => field.split(".").slice(1).join(".")
244
- );
245
- const relSubsetQuery = relSMD.resolveSubsetQuery("", relFields);
246
- let manyJoin;
247
- if (_chunk2WAC2GERjs.isHasManyRelationProp.call(void 0, relation)) {
248
- manyJoin = {
249
- fromTable: this.table,
250
- fromCol: "id",
251
- idField: prefix === "" ? `id` : `${prefix}__id`,
252
- toTable: relSMD.table,
253
- toCol: relation.joinColumn
254
- };
255
- } else if (_chunk2WAC2GERjs.isManyToManyRelationProp.call(void 0, relation)) {
256
- const [table1, table2] = relation.joinTable.split("__");
257
- manyJoin = {
258
- fromTable: this.table,
259
- fromCol: "id",
260
- idField: prefix === "" ? `id` : `${prefix}__id`,
261
- through: {
262
- table: relation.joinTable,
263
- fromCol: `${_inflection2.default.singularize(table1)}_id`,
264
- toCol: `${_inflection2.default.singularize(table2)}_id`
265
- },
266
- toTable: relSMD.table,
267
- toCol: "id"
268
- };
269
- } else {
270
- throw new Error();
271
- }
272
- r.loaders.push({
273
- as: groupKey,
274
- table: relSMD.table,
275
- manyJoin,
276
- oneJoins: relSubsetQuery.joins,
277
- select: relSubsetQuery.select,
278
- loaders: relSubsetQuery.loaders
279
- });
280
- }
281
- return r;
282
- },
283
- {
284
- select: [],
285
- virtual: [],
286
- joins: [],
287
- loaders: []
288
- }
289
- );
290
- return result;
291
- }
292
- /*
293
- FieldExpr[] 을 SMDPropNode[] 로 변환
294
- */
295
- fieldExprsToPropNodes(fieldExprs, smd = this) {
296
- const groups = fieldExprs.reduce(
297
- (result, fieldExpr) => {
298
- let key, value, elseExpr;
299
- if (fieldExpr.includes(".")) {
300
- [key, ...elseExpr] = fieldExpr.split(".");
301
- value = elseExpr.join(".");
302
- } else {
303
- key = "";
304
- value = fieldExpr;
305
- }
306
- result[key] = (_nullishCoalesce(result[key], () => ( []))).concat(value);
307
- return result;
308
- },
309
- {}
310
- );
311
- return Object.keys(groups).map((key) => {
312
- const group = groups[key];
313
- if (key === "") {
314
- return group.map((propName) => {
315
- if (propName === "uuid") {
316
- return {
317
- nodeType: "plain",
318
- prop: {
319
- type: "string",
320
- name: "uuid",
321
- length: 128
322
- },
323
- children: []
324
- };
325
- }
326
- const prop2 = smd.propsDict[propName];
327
- if (prop2 === void 0) {
328
- throw new Error(`${this.id} -- \uC798\uBABB\uB41C FieldExpr ${propName}`);
329
- }
330
- return {
331
- nodeType: "plain",
332
- prop: prop2,
333
- children: []
334
- };
335
- });
336
- }
337
- const prop = smd.propsDict[key];
338
- if (!_chunk2WAC2GERjs.isRelationProp.call(void 0, prop)) {
339
- throw new Error(`\uC798\uBABB\uB41C FieldExpr ${key}.${group[0]}`);
340
- }
341
- const relSMD = SMDManager.get(prop.with);
342
- if (_chunk2WAC2GERjs.isBelongsToOneRelationProp.call(void 0, prop) || _chunk2WAC2GERjs.isOneToOneRelationProp.call(void 0, prop)) {
343
- if (group.length == 1 && (group[0] === "id" || group[0] == "id?")) {
344
- const idProp = relSMD.propsDict.id;
345
- return {
346
- nodeType: "plain",
347
- prop: {
348
- ...idProp,
349
- name: key + "_id",
350
- nullable: prop.nullable
351
- },
352
- children: []
353
- };
354
- }
355
- }
356
- const children = this.fieldExprsToPropNodes(group, relSMD);
357
- const nodeType = _chunk2WAC2GERjs.isBelongsToOneRelationProp.call(void 0, prop) || _chunk2WAC2GERjs.isOneToOneRelationProp.call(void 0, prop) ? "object" : "array";
358
- return {
359
- prop,
360
- children,
361
- nodeType
362
- };
363
- }).flat();
364
- }
365
- getFieldExprs(prefix = "", maxDepth = 3, froms = []) {
366
- return this.props.map((prop) => {
367
- const propName = [prefix, prop.name].filter((v) => v !== "").join(".");
368
- if (propName === prefix) {
369
- return null;
370
- }
371
- if (_chunk2WAC2GERjs.isRelationProp.call(void 0, prop)) {
372
- if (maxDepth < 0) {
373
- return null;
374
- }
375
- if (froms.includes(prop.with)) {
376
- return null;
377
- }
378
- const relMd = SMDManager.get(prop.with);
379
- return relMd.getFieldExprs(propName, maxDepth - 1, [
380
- ...froms,
381
- this.id
382
- ]);
383
- }
384
- return propName;
385
- }).flat().filter((f) => f !== null);
386
- }
387
- registerModulePaths() {
388
- const basePath = `${this.names.fs}`;
389
- SMDManager.setModulePath(
390
- `${this.id}BaseSchema`,
391
- `${basePath}/${this.names.fs}.generated`
392
- );
393
- if (Object.keys(this.subsets).length > 0) {
394
- SMDManager.setModulePath(
395
- `${this.id}SubsetKey`,
396
- `${basePath}/${this.names.fs}.generated`
397
- );
398
- SMDManager.setModulePath(
399
- `${this.id}SubsetMapping`,
400
- `${basePath}/${this.names.fs}.generated`
401
- );
402
- Object.keys(this.subsets).map((subsetKey) => {
403
- SMDManager.setModulePath(
404
- `${this.id}Subset${subsetKey.toUpperCase()}`,
405
- `${basePath}/${this.names.fs}.generated`
406
- );
407
- });
408
- }
409
- const typesModulePath = `${basePath}/${this.names.fs}.types`;
410
- const typesFileDistPath = _path2.default.join(
411
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
412
- `dist/application/${typesModulePath}.js`
413
- );
414
- if (_fsextra2.default.existsSync(typesFileDistPath)) {
415
- const importPath = _path2.default.relative(__dirname, typesFileDistPath);
416
- Promise.resolve().then(() => _interopRequireWildcard(require(importPath))).then((t) => {
417
- this.types = Object.keys(t).reduce((result, key) => {
418
- SMDManager.setModulePath(key, typesModulePath);
419
- return {
420
- ...result,
421
- [key]: t[key]
422
- };
423
- }, {});
424
- });
425
- }
426
- const enumsModulePath = `${basePath}/${this.names.fs}.enums`;
427
- const enumsFileDistPath = _path2.default.join(
428
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
429
- `/dist/application/${enumsModulePath}.js`
430
- );
431
- if (_fsextra2.default.existsSync(enumsFileDistPath)) {
432
- const importPath = _path2.default.relative(__dirname, enumsFileDistPath);
433
- Promise.resolve().then(() => _interopRequireWildcard(require(importPath))).then((t) => {
434
- this.enums = Object.keys(t).reduce((result, key) => {
435
- SMDManager.setModulePath(key, enumsModulePath);
436
- if (key === _inflection2.default.underscore(this.id).toUpperCase()) {
437
- this.enumLabels = t[key];
438
- }
439
- return {
440
- ...result,
441
- [key]: t[key]
442
- };
443
- }, {});
444
- });
445
- }
446
- }
447
- registerTableSpecs() {
448
- const uniqueColumns = _lodash2.default.uniq(
449
- this.indexes.filter((idx) => idx.type === "unique").map((idx) => idx.columns).flat()
450
- );
451
- SMDManager.setTableSpec({
452
- name: this.table,
453
- uniqueColumns
454
- });
455
- }
456
- }, _class);
457
-
458
- // src/smd/smd-manager.ts
459
- var SMDManagerClass = (_class2 = class {constructor() { _class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this); }
460
- __init4() {this.SMDs = /* @__PURE__ */ new Map()}
461
- __init5() {this.modulePaths = /* @__PURE__ */ new Map()}
462
- __init6() {this.tableSpecs = /* @__PURE__ */ new Map()}
463
- __init7() {this.isAutoloaded = false}
464
- // 경로 전달받아 모든 SMD 파일 로드
465
- async autoload(doSilent = false) {
466
- if (this.isAutoloaded) {
467
- return;
468
- }
469
- const pathPattern = _path2.default.join(
470
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
471
- "/dist/application/**/*.smd.js"
472
- );
473
- !doSilent && console.log(_chalk2.default.yellow(`autoload ${pathPattern}`));
474
- return new Promise((resolve) => {
475
- _glob2.default.glob(_path2.default.resolve(pathPattern), (_err, files) => {
476
- const importPaths = files.map(
477
- (filePath) => _path2.default.relative(__dirname, filePath)
478
- );
479
- Promise.all(
480
- importPaths.map(async (importPath) => {
481
- const imported = await Promise.resolve().then(() => _interopRequireWildcard(require(importPath)));
482
- Object.values(imported).map(
483
- (smdInput) => this.register(smdInput)
484
- );
485
- return imported;
486
- })
487
- ).then(() => {
488
- resolve("ok");
489
- this.isAutoloaded = true;
490
- });
491
- });
492
- });
493
- }
494
- register(smdInput) {
495
- const smd = new SMD(smdInput);
496
- this.SMDs.set(smdInput.id, smd);
497
- }
498
- get(smdId) {
499
- const smd = this.SMDs.get(smdId);
500
- if (smd === void 0) {
501
- throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 SMD \uC694\uCCAD ${smdId}`);
502
- }
503
- return smd;
504
- }
505
- exists(smdId) {
506
- const smd = this.SMDs.get(smdId);
507
- return smd !== void 0;
508
- }
509
- getAllIds() {
510
- return Array.from(SMDManager.SMDs.keys());
511
- }
512
- getAllParentIds() {
513
- return this.getAllIds().filter((smdId) => {
514
- const smd = this.get(smdId);
515
- return smd.parentId === void 0;
516
- });
517
- }
518
- getChildrenIds(parentId) {
519
- return this.getAllIds().filter((smdId) => {
520
- const smd = this.get(smdId);
521
- return smd.parentId === parentId;
522
- });
523
- }
524
- setModulePath(key, modulePath) {
525
- this.modulePaths.set(key, modulePath);
526
- }
527
- getModulePath(key) {
528
- const modulePath = this.modulePaths.get(key);
529
- if (modulePath === void 0) {
530
- throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4C8 \uD328\uC2A4 \uC694\uCCAD ${key}`);
531
- }
532
- return modulePath;
533
- }
534
- setTableSpec(tableSpec) {
535
- this.tableSpecs.set(tableSpec.name, tableSpec);
536
- }
537
- getTableSpec(key) {
538
- const tableSpec = this.tableSpecs.get(key);
539
- if (tableSpec === void 0) {
540
- throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uD14C\uC774\uBE14 \uC2A4\uD399 \uC694\uCCAD ${key}`);
541
- }
542
- return tableSpec;
543
- }
544
- getNamesFromId(smdId) {
545
- const pluralized = _inflection2.default.pluralize(smdId) === smdId ? `${smdId}List` : _inflection2.default.pluralize(smdId);
546
- return {
547
- fs: _inflection2.default.dasherize(_inflection2.default.underscore(smdId)).toLowerCase(),
548
- fsPlural: _inflection2.default.dasherize(_inflection2.default.underscore(pluralized)).toLowerCase(),
549
- camel: _inflection2.default.camelize(smdId, true),
550
- camelPlural: _inflection2.default.camelize(pluralized, true),
551
- capital: smdId,
552
- capitalPlural: pluralized,
553
- upper: smdId.toUpperCase(),
554
- constant: _inflection2.default.underscore(smdId).toUpperCase()
555
- };
556
- }
557
- }, _class2);
558
- var SMDManager = new SMDManagerClass();
559
-
560
- // src/bin/cli.ts
561
- console.log(_chalk2.default.bgBlue(`BEGIN ${/* @__PURE__ */ new Date()}`));
562
- _dotenv2.default.config();
563
- var migrator;
564
- async function bootstrap() {
565
- await _chunk2WAC2GERjs.Sonamu.init(false, false);
566
- await _tsicli.tsicli.call(void 0, _process2.default.argv, {
567
- types: {
568
- "#entityId": {
569
- type: "autocomplete",
570
- name: "#entityId",
571
- message: "Please input #entityId",
572
- choices: _chunk2WAC2GERjs.EntityManager.getAllParentIds().map((entityId) => ({
573
- title: entityId,
574
- value: entityId
575
- }))
576
- },
577
- "#recordIds": "number[]",
578
- "#name": "string"
579
- },
580
- args: [
581
- ["fixture", "init"],
582
- ["fixture", "import", "#entityId", "#recordIds"],
583
- ["fixture", "sync"],
584
- ["migrate", "run"],
585
- ["migrate", "check"],
586
- ["migrate", "rollback"],
587
- ["migrate", "reset"],
588
- ["migrate", "clear"],
589
- ["migrate", "status"],
590
- ["stub", "practice", "#name"],
591
- ["stub", "entity", "#name"],
592
- ["scaffold", "model", "#entityId"],
593
- ["scaffold", "model_test", "#entityId"],
594
- ["scaffold", "view_list", "#entityId"],
595
- ["scaffold", "view_form", "#entityId"],
596
- ["ui"],
597
- ["smd_migration"]
598
- ],
599
- runners: {
600
- migrate_run,
601
- migrate_check,
602
- migrate_rollback,
603
- migrate_clear,
604
- migrate_reset,
605
- migrate_status,
606
- fixture_init,
607
- fixture_import,
608
- fixture_sync,
609
- stub_practice,
610
- stub_entity,
611
- scaffold_model,
612
- scaffold_model_test,
613
- ui,
614
- // scaffold_view_list,
615
- // scaffold_view_form,
616
- smd_migration
617
- }
618
- });
619
- }
620
- bootstrap().finally(async () => {
621
- if (migrator) {
622
- await migrator.destroy();
623
- }
624
- await _chunkOTKKFP3Yjs.FixtureManager.destory();
625
- console.log(_chalk2.default.bgBlue(`END ${/* @__PURE__ */ new Date()}
626
- `));
627
- });
628
- async function setupMigrator() {
629
- migrator = new (0, _chunkOTKKFP3Yjs.Migrator)({
630
- mode: "dev"
631
- });
632
- }
633
- async function setupFixtureManager() {
634
- _chunkOTKKFP3Yjs.FixtureManager.init();
635
- }
636
- async function migrate_run() {
637
- await setupMigrator();
638
- await migrator.cleanUpDist();
639
- await migrator.run();
640
- }
641
- async function migrate_check() {
642
- await setupMigrator();
643
- await migrator.cleanUpDist();
644
- await migrator.check();
645
- }
646
- async function migrate_status() {
647
- await setupMigrator();
648
- const status = await migrator.getStatus();
649
- console.log(status);
650
- }
651
- async function migrate_rollback() {
652
- await setupMigrator();
653
- await migrator.rollback();
654
- }
655
- async function migrate_clear() {
656
- await setupMigrator();
657
- await migrator.clearPendingList();
658
- }
659
- async function migrate_reset() {
660
- await setupMigrator();
661
- await migrator.resetAll();
662
- }
663
- async function fixture_init() {
664
- const _db = _chunk2WAC2GERjs.DB.getClient("development_master");
665
- const srcConn = _db.connectionInfo;
666
- const targets = [
667
- {
668
- label: "(REMOTE) Fixture DB",
669
- connKey: "fixture_remote"
670
- },
671
- {
672
- label: "(LOCAL) Fixture DB",
673
- connKey: "fixture_local"
674
- },
675
- {
676
- label: "(LOCAL) Testing DB",
677
- connKey: "test"
678
- }
679
- ];
680
- console.log("DUMP...");
681
- const dumpFilename = `/tmp/sonamu-fixture-init-${Date.now()}.sql`;
682
- const migrationsDump = `/tmp/sonamu-fixture-init-migrations-${Date.now()}.sql`;
683
- _child_process.execSync.call(void 0,
684
- `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
685
- );
686
- const dbClient = _chunk2WAC2GERjs.DB.baseConfig.client;
687
- const migrationTable = _chunk2WAC2GERjs.DB.migrationTable;
688
- const [migrations] = await _db.raw(
689
- "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
690
- [srcConn.database, migrationTable]
691
- );
692
- if (migrations.count > 0) {
693
- _child_process.execSync.call(void 0,
694
- `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} ${migrationTable} ${migrationTable}_lock > ${migrationsDump}`
695
- );
696
- }
697
- for await (const { label, connKey } of targets) {
698
- const config = _chunk2WAC2GERjs.DB.connectionInfo[connKey];
699
- if (label === "(LOCAL) Fixture DB" && targets.find(
700
- (t) => t.label === "(REMOTE) Fixture DB" && _chunk2WAC2GERjs.DB.connectionInfo[t.connKey].host === config.host && _chunk2WAC2GERjs.DB.connectionInfo[t.connKey].database === config.database
701
- )) {
702
- console.log(_chalk2.default.red(`${label}: Skipped!`));
703
- continue;
704
- }
705
- const db = (() => {
706
- if (dbClient === "knex") {
707
- const config2 = _lodash2.default.cloneDeep(_chunk2WAC2GERjs.DB.fullConfig[connKey]);
708
- config2.connection.database = void 0;
709
- return new (0, _chunk2WAC2GERjs.KnexClient)(config2);
710
- } else {
711
- const config2 = _lodash2.default.cloneDeep(_chunk2WAC2GERjs.DB.fullConfig[connKey]);
712
- config2.database = void 0;
713
- return new (0, _chunk2WAC2GERjs.KyselyClient)(config2);
714
- }
715
- })();
716
- const [row] = await db.raw(`SHOW DATABASES LIKE "${config.database}"`);
717
- if (row) {
718
- console.log(
719
- _chalk2.default.yellow(`${label}: Database "${config.database}" Already exists`)
720
- );
721
- await db.destroy();
722
- continue;
723
- }
724
- console.log(`SYNC to ${label}...`);
725
- const mysqlCmd = `mysql -h${config.host} -P${srcConn.port} -u${config.user} -p${config.password}`;
726
- _child_process.execSync.call(void 0, `${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${config.database}\`'`);
727
- _child_process.execSync.call(void 0, `${mysqlCmd} -e 'CREATE DATABASE \`${config.database}\`'`);
728
- _child_process.execSync.call(void 0, `${mysqlCmd} ${config.database} < ${dumpFilename}`);
729
- if (_fsextra2.default.existsSync(migrationsDump)) {
730
- _child_process.execSync.call(void 0, `${mysqlCmd} ${config.database} < ${migrationsDump}`);
731
- }
732
- await db.destroy();
733
- }
734
- }
735
- async function fixture_import(entityId, recordIds) {
736
- await setupFixtureManager();
737
- await _chunkOTKKFP3Yjs.FixtureManager.importFixture(entityId, recordIds);
738
- await _chunkOTKKFP3Yjs.FixtureManager.sync();
739
- }
740
- async function fixture_sync() {
741
- await setupFixtureManager();
742
- await _chunkOTKKFP3Yjs.FixtureManager.sync();
743
- }
744
- async function stub_practice(name) {
745
- const practiceDir = _path2.default.join(_chunk2WAC2GERjs.Sonamu.apiRootPath, "src", "practices");
746
- const fileNames = _fsextra2.default.readdirSync(practiceDir);
747
- const maxSeqNo = (() => {
748
- if (_fsextra2.default.existsSync(practiceDir) === false) {
749
- _fsextra2.default.mkdirSync(practiceDir, { recursive: true });
750
- }
751
- const filteredSeqs = fileNames.filter(
752
- (fileName2) => fileName2.startsWith("p") && fileName2.endsWith(".ts")
753
- ).map((fileName2) => {
754
- const [, seqNo] = _nullishCoalesce(fileName2.match(/^p([0-9]+)\-/), () => ( ["0", "0"]));
755
- return parseInt(seqNo);
756
- }).sort((a, b) => b - a);
757
- if (filteredSeqs.length > 0) {
758
- return filteredSeqs[0];
759
- }
760
- return 0;
761
- })();
762
- const currentSeqNo = maxSeqNo + 1;
763
- const fileName = `p${currentSeqNo}-${name}.ts`;
764
- const dstPath = _path2.default.join(practiceDir, fileName);
765
- const code = [
766
- `import { BaseModel } from "sonamu";`,
767
- "",
768
- `console.clear();`,
769
- `console.log("${fileName}");`,
770
- "",
771
- `async function bootstrap() {`,
772
- ` // TODO`,
773
- `}`,
774
- `bootstrap().finally(async () => {`,
775
- `await BaseModel.destroy();`,
776
- `});`
777
- ].join("\n");
778
- _fsextra2.default.writeFileSync(dstPath, code);
779
- _child_process.execSync.call(void 0, `code ${dstPath}`);
780
- const runCode = `yarn node -r source-map-support/register dist/practices/${fileName.replace(
781
- ".ts",
782
- ".js"
783
- )}`;
784
- console.log(`${_chalk2.default.blue(runCode)} copied to clipboard.`);
785
- _child_process.execSync.call(void 0, `echo "${runCode}" | pbcopy`);
786
- }
787
- async function stub_entity(entityId) {
788
- await _chunk2WAC2GERjs.Sonamu.syncer.createEntity({ entityId });
789
- }
790
- async function scaffold_model(entityId) {
791
- await _chunk2WAC2GERjs.Sonamu.syncer.generateTemplate("model", {
792
- entityId
793
- });
794
- }
795
- async function scaffold_model_test(entityId) {
796
- await _chunk2WAC2GERjs.Sonamu.syncer.generateTemplate("model_test", {
797
- entityId
798
- });
799
- }
800
- async function ui() {
801
- try {
802
- const sonamuUI = await Promise.resolve().then(() => _interopRequireWildcard(require("@sonamu-kit/ui")));
803
- sonamuUI.startServers(_chunk2WAC2GERjs.Sonamu.apiRootPath);
804
- } catch (e) {
805
- if (e instanceof Error && e.message.includes("isn't declared")) {
806
- console.log(`You need to install ${_chalk2.default.blue(`@sonamu-kit/ui`)} first.`);
807
- return;
808
- }
809
- throw e;
810
- }
811
- }
812
- async function smd_migration() {
813
- await SMDManager.autoload();
814
- const smdIds = SMDManager.getAllIds();
815
- function enumLabelsToEntityEnums(entityId, enumLabels) {
816
- return Object.fromEntries(
817
- Object.entries(enumLabels).map(([enumLabelName, enumLabel]) => {
818
- const enumName = entityId + _inflection2.default.camelize(enumLabelName.toLowerCase(), false);
819
- return [
820
- enumName,
821
- Object.fromEntries(
822
- Object.entries(enumLabel).map(([name, { ko }]) => [name, ko])
823
- )
824
- ];
825
- })
826
- );
827
- }
828
- for await (const smdId of smdIds) {
829
- const smd = SMDManager.get(smdId);
830
- const entityJson = {
831
- id: smd.id,
832
- ...smd.parentId && { parentId: smd.parentId },
833
- title: smd.title,
834
- props: smd.props,
835
- indexes: smd.indexes,
836
- subsets: smd.subsets,
837
- enums: enumLabelsToEntityEnums(smd.id, smd.enumLabels)
838
- };
839
- const parentNames = SMDManager.getNamesFromId(_nullishCoalesce(smd.parentId, () => ( smd.id)));
840
- const names = SMDManager.getNamesFromId(smd.id);
841
- const dstPath = _path2.default.join(
842
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
843
- "src",
844
- "application",
845
- parentNames.fs,
846
- `${names.fs}.entity.json`
847
- );
848
- const formatted = await _prettier2.default.format(JSON.stringify(entityJson), {
849
- parser: "json"
850
- });
851
- _fsextra2.default.writeFileSync(dstPath, formatted);
852
- console.log(_chalk2.default.blue(`CREATED: ${dstPath}`));
853
- const srcSmdPath = _path2.default.join(
854
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
855
- "src",
856
- "application",
857
- parentNames.fs,
858
- `${names.fs}.smd.ts`
859
- );
860
- const dstSmdPath = srcSmdPath.replace("/src/", "/dist/").replace(/\.ts$/, ".js");
861
- const srcEnumsPath = _path2.default.join(
862
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
863
- "src",
864
- "application",
865
- parentNames.fs,
866
- `${names.fs}.enums.ts`
867
- );
868
- const dstEnumsPath = srcEnumsPath.replace("/src/", "/dist/").replace(/\.ts$/, ".js");
869
- const srcGeneratedPath = _path2.default.join(
870
- _chunk2WAC2GERjs.Sonamu.apiRootPath,
871
- "src",
872
- "application",
873
- parentNames.fs,
874
- `${names.fs}.generated.ts`
875
- );
876
- const dstGeneratedPath = srcGeneratedPath.replace("/src/", "/dist/").replace(/\.ts$/, ".js");
877
- [
878
- srcSmdPath,
879
- dstSmdPath,
880
- srcEnumsPath,
881
- dstEnumsPath,
882
- ..._chunk2WAC2GERjs.Sonamu.config.sync.targets.map(
883
- (target) => srcEnumsPath.replace(_chunk2WAC2GERjs.Sonamu.apiRootPath, _path2.default.join(_chunk2WAC2GERjs.Sonamu.appRootPath, target)).replace("/src/application/", "/src/services/")
884
- ),
885
- srcGeneratedPath,
886
- dstGeneratedPath
887
- ].map((p) => {
888
- if (_fsextra2.default.existsSync(p) === false) {
889
- console.log(_chalk2.default.yellow(`NOT FOUND: ${p}`));
890
- return;
891
- }
892
- _fsextra2.default.unlinkSync(p);
893
- console.log(_chalk2.default.red(`DELETED: ${p}`));
894
- });
895
- }
896
- console.log("Entity\uB85C \uB2E4\uC2DC \uB85C\uB4DC\uD569\uB2C8\uB2E4.");
897
- _chunk2WAC2GERjs.EntityManager.isAutoloaded = false;
898
- await _chunk2WAC2GERjs.EntityManager.autoload();
899
- const entityIds = _chunk2WAC2GERjs.EntityManager.getAllParentIds();
900
- for await (const entityId of entityIds) {
901
- await _chunk2WAC2GERjs.Sonamu.syncer.generateTemplate("generated", { entityId });
902
- }
903
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});var _chalk=/*#__PURE__*/_interop_require_default(require("chalk"));var _dotenv=/*#__PURE__*/_interop_require_default(require("dotenv"));var _path=/*#__PURE__*/_interop_require_default(require("path"));var _tsicli=require("tsicli");var _child_process=require("child_process");var _promises=require("fs/promises");var _fsutils=require("../utils/fs-utils");var _process=/*#__PURE__*/_interop_require_default(require("process"));var _api=require("../api");var _knex=/*#__PURE__*/_interop_require_default(require("knex"));var _utils=require("../utils/utils");var _entitymanager=require("../entity/entity-manager");var _migrator=require("../migration/migrator");var _fixturemanager=require("../testing/fixture-manager");function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function _async_iterator(iterable){var method,async,sync,retry=2;for("undefined"!=typeof Symbol&&(async=Symbol.asyncIterator,sync=Symbol.iterator);retry--;){if(async&&null!=(method=iterable[async]))return method.call(iterable);if(sync&&null!=(method=iterable[sync]))return new AsyncFromSyncIterator(method.call(iterable));async="@@asyncIterator",sync="@@iterator"}throw new TypeError("Object is not async iterable")}function AsyncFromSyncIterator(s){function AsyncFromSyncIteratorContinuation(r){if(Object(r)!==r)return Promise.reject(new TypeError(r+" is not an object."));var done=r.done;return Promise.resolve(r.value).then(function(value){return{value:value,done:done}})}return AsyncFromSyncIterator=function(s){this.s=s,this.n=s.next},AsyncFromSyncIterator.prototype={s:null,n:null,next:function(){return AsyncFromSyncIteratorContinuation(this.n.apply(this.s,arguments))},return:function(value){var ret=this.s.return;return void 0===ret?Promise.resolve({value:value,done:!0}):AsyncFromSyncIteratorContinuation(ret.apply(this.s,arguments))},throw:function(value){var thr=this.s.return;return void 0===thr?Promise.reject(value):AsyncFromSyncIteratorContinuation(thr.apply(this.s,arguments))}},new AsyncFromSyncIterator(s)}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}function _interop_require_default(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}_dotenv.default.config();var migrator;function bootstrap(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!(_process.default.argv[2]!=="dev:serve"))return[3,2];return[4,_api.Sonamu.init(false,false)];case 1:_state.sent();_state.label=2;case 2:return[4,(0,_tsicli.tsicli)(_process.default.argv,{types:{"#entityId":{type:"autocomplete",name:"#entityId",message:"Please input #entityId",choices:_entitymanager.EntityManager.getAllParentIds().map(function(entityId){return{title:entityId,value:entityId}})},"#recordIds":"number[]","#name":"string"},args:[["fixture","init"],["fixture","import","#entityId","#recordIds"],["fixture","sync"],["migrate","run"],["migrate","check"],["migrate","rollback"],["migrate","reset"],["migrate","clear"],["migrate","status"],["stub","practice","#name"],["stub","entity","#name"],["scaffold","model","#entityId"],["scaffold","model_test","#entityId"],["scaffold","view_list","#entityId"],["scaffold","view_form","#entityId"],["ui"],["dev:serve"],["serve"]],runners:{migrate_run:migrate_run,migrate_check:migrate_check,migrate_rollback:migrate_rollback,migrate_clear:migrate_clear,migrate_reset:migrate_reset,migrate_status:migrate_status,fixture_init:fixture_init,fixture_import:fixture_import,fixture_sync:fixture_sync,stub_practice:stub_practice,stub_entity:stub_entity,scaffold_model:scaffold_model,scaffold_model_test:scaffold_model_test,ui:ui,"dev:serve":dev_serve,serve:serve}})];case 3:_state.sent();return[2]}})})()}bootstrap().finally(function(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!migrator)return[3,2];return[4,migrator.destroy()];case 1:_state.sent();_state.label=2;case 2:return[4,_fixturemanager.FixtureManager.destroy()];case 3:_state.sent();return[2]}})})()});function dev_serve(){return _async_to_generator(function(){var nodemon,nodemonConfig,cleanup;return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,Promise.resolve().then(function(){return /*#__PURE__*/_interop_require_wildcard(require("nodemon"))})];case 1:nodemon=_state.sent();return[4,function(){return _async_to_generator(function(){var projectNodemonPath,hasProjectNodemon,_;return _ts_generator(this,function(_state){switch(_state.label){case 0:projectNodemonPath=_path.default.join((0,_utils.findApiRootPath)(),"nodemon.json");return[4,(0,_fsutils.exists)(projectNodemonPath)];case 1:hasProjectNodemon=_state.sent();if(!hasProjectNodemon)return[3,3];_=JSON.parse;return[4,(0,_promises.readFile)(projectNodemonPath,"utf8")];case 2:return[2,_.apply(JSON,[_state.sent()])];case 3:return[2,{watch:["src/index.ts"],ignore:["dist/**","**/*.js","**/*.d.ts"],exec:["node --no-warnings -r source-map-support/register -r dotenv/config dist/index.js"].join(" && ")}]}})})()}()];case 2:nodemonConfig=_state.sent();nodemon.default(nodemonConfig);cleanup=function(){return _async_to_generator(function(){var _Sonamu_server;return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,(_Sonamu_server=_api.Sonamu.server)===null||_Sonamu_server===void 0?void 0:_Sonamu_server.close()];case 1:_state.sent();_process.default.exit(0);return[2]}})})()};_process.default.on("SIGINT",cleanup);_process.default.on("SIGTERM",cleanup);_process.default.on("SIGUSR2",cleanup);return[2]}})})()}function serve(){return _async_to_generator(function(){var distIndexPath,spawn,serverProcess;return _ts_generator(this,function(_state){switch(_state.label){case 0:distIndexPath=_path.default.join(_api.Sonamu.apiRootPath,"dist","index.js");return[4,(0,_fsutils.exists)(distIndexPath)];case 1:if(!_state.sent()){console.log(_chalk.default.red("dist/index.js not found. Please build your project first."));console.log(_chalk.default.blue("Run: yarn sonamu build"));return[2]}return[4,Promise.resolve().then(function(){return /*#__PURE__*/_interop_require_wildcard(require("child_process"))})];case 2:spawn=_state.sent().spawn;serverProcess=spawn("node",["-r","source-map-support/register","-r","dotenv/config",distIndexPath],{cwd:_api.Sonamu.apiRootPath,stdio:"inherit"});_process.default.on("SIGINT",function(){serverProcess.kill("SIGTERM");_process.default.exit(0)});return[2]}})})()}function setupMigrator(){return _async_to_generator(function(){return _ts_generator(this,function(_state){migrator=new _migrator.Migrator({mode:"dev"});return[2]})})()}function setupFixtureManager(){return _async_to_generator(function(){return _ts_generator(this,function(_state){_fixturemanager.FixtureManager.init();return[2]})})()}function migrate_run(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.cleanUpDist()];case 2:_state.sent();return[4,migrator.run()];case 3:_state.sent();return[2]}})})()}function migrate_check(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.cleanUpDist()];case 2:_state.sent();return[4,migrator.check()];case 3:_state.sent();return[2]}})})()}function migrate_status(){return _async_to_generator(function(){var status;return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.getStatus()];case 2:status=_state.sent();console.log(status);return[2]}})})()}function migrate_rollback(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.rollback()];case 2:_state.sent();return[2]}})})()}function migrate_clear(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.clearPendingList()];case 2:_state.sent();return[2]}})})()}function migrate_reset(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupMigrator()];case 1:_state.sent();return[4,migrator.resetAll()];case 2:_state.sent();return[2]}})})()}function fixture_init(){return _async_to_generator(function(){var srcConfig,targets,dumpFilename,srcConn,migrationsDump,_db,_ref,_ref_,migrations,_iteratorAbruptCompletion,_didIteratorError,_iteratorError,_iterator,_step,_value,label,config,toSkip,conn,_config_connection,db,_ref1,_ref_1,row,mysqlCmd,err;return _ts_generator(this,function(_state){switch(_state.label){case 0:srcConfig=_api.Sonamu.dbConfig.development_master;targets=[{label:"(REMOTE) Fixture DB",config:_api.Sonamu.dbConfig.fixture_remote},{label:"(LOCAL) Fixture DB",config:_api.Sonamu.dbConfig.fixture_local,toSkip:function(){var remoteConn=_api.Sonamu.dbConfig.fixture_remote.connection;var localConn=_api.Sonamu.dbConfig.fixture_local.connection;return remoteConn.host===localConn.host&&remoteConn.database===localConn.database}()},{label:"(LOCAL) Testing DB",config:_api.Sonamu.dbConfig.test}];console.log("DUMP...");dumpFilename="/tmp/sonamu-fixture-init-".concat(Date.now(),".sql");srcConn=srcConfig.connection;migrationsDump="/tmp/sonamu-fixture-init-migrations-".concat(Date.now(),".sql");(0,_child_process.execSync)("mysqldump -h".concat(srcConn.host," -u").concat(srcConn.user," -p").concat(srcConn.password," --single-transaction -d --no-create-db --triggers ").concat(srcConn.database," > ").concat(dumpFilename));_db=(0,_knex.default)(srcConfig);return[4,_db.raw("SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = 'knex_migrations'",[srcConn.database])];case 1:_ref=_sliced_to_array.apply(void 0,[_state.sent(),1]),_ref_=_sliced_to_array(_ref[0],1),migrations=_ref_[0];if(migrations.count>0){(0,_child_process.execSync)("mysqldump -h".concat(srcConn.host," -u").concat(srcConn.user," -p").concat(srcConn.password," --single-transaction --no-create-db --triggers ").concat(srcConn.database," knex_migrations knex_migrations_lock > ").concat(migrationsDump))}_iteratorAbruptCompletion=false,_didIteratorError=false;_state.label=2;case 2:_state.trys.push([2,12,13,18]);_iterator=_async_iterator(targets);_state.label=3;case 3:return[4,_iterator.next()];case 4:if(!(_iteratorAbruptCompletion=!(_step=_state.sent()).done))return[3,11];_value=_step.value;label=_value.label,config=_value.config,toSkip=_value.toSkip;conn=config.connection;if(toSkip===true){console.log(_chalk.default.red("".concat(label,": Skipped!")));return[3,10]}db=(0,_knex.default)(_object_spread_props(_object_spread({},config),{connection:_object_spread_props(_object_spread({},(_config_connection=config.connection)!==null&&_config_connection!==void 0?_config_connection:{}),{database:undefined})}));return[4,db.raw('SHOW DATABASES LIKE "'.concat(conn.database,'"'))];case 5:_ref1=_sliced_to_array.apply(void 0,[_state.sent(),1]),_ref_1=_sliced_to_array(_ref1[0],1),row=_ref_1[0];if(!row)return[3,7];console.log(_chalk.default.yellow("".concat(label,': Database "').concat(conn.database,'" Already exists')));return[4,db.destroy()];case 6:_state.sent();return[3,10];case 7:console.log("SYNC to ".concat(label,"..."));mysqlCmd="mysql -h".concat(conn.host," -u").concat(conn.user," -p").concat(conn.password);(0,_child_process.execSync)("".concat(mysqlCmd," -e 'DROP DATABASE IF EXISTS `").concat(conn.database,"`'"));(0,_child_process.execSync)("".concat(mysqlCmd," -e 'CREATE DATABASE `").concat(conn.database,"`'"));(0,_child_process.execSync)("".concat(mysqlCmd," ").concat(conn.database," < ").concat(dumpFilename));return[4,(0,_fsutils.exists)(migrationsDump)];case 8:if(_state.sent()){(0,_child_process.execSync)("".concat(mysqlCmd," ").concat(conn.database," < ").concat(migrationsDump))}return[4,db.destroy()];case 9:_state.sent();_state.label=10;case 10:_iteratorAbruptCompletion=false;return[3,3];case 11:return[3,18];case 12:err=_state.sent();_didIteratorError=true;_iteratorError=err;return[3,18];case 13:_state.trys.push([13,,16,17]);if(!(_iteratorAbruptCompletion&&_iterator.return!=null))return[3,15];return[4,_iterator.return()];case 14:_state.sent();_state.label=15;case 15:return[3,17];case 16:if(_didIteratorError){throw _iteratorError}return[7];case 17:return[7];case 18:return[4,_db.destroy()];case 19:_state.sent();return[2]}})})()}function fixture_import(entityId,recordIds){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupFixtureManager()];case 1:_state.sent();return[4,_fixturemanager.FixtureManager.importFixture(entityId,recordIds)];case 2:_state.sent();return[4,_fixturemanager.FixtureManager.sync()];case 3:_state.sent();return[2]}})})()}function fixture_sync(){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,setupFixtureManager()];case 1:_state.sent();return[4,_fixturemanager.FixtureManager.sync()];case 2:_state.sent();return[2]}})})()}function stub_practice(name){return _async_to_generator(function(){var practiceDir,fileNames,maxSeqNo,currentSeqNo,fileName,dstPath,code,runCode;return _ts_generator(this,function(_state){switch(_state.label){case 0:practiceDir=_path.default.join(_api.Sonamu.apiRootPath,"src","practices");return[4,(0,_promises.readdir)(practiceDir)];case 1:fileNames=_state.sent();return[4,function(){return _async_to_generator(function(){var filteredSeqs;return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,(0,_fsutils.exists)(practiceDir)];case 1:if(!!_state.sent())return[3,3];return[4,(0,_promises.mkdir)(practiceDir,{recursive:true})];case 2:_state.sent();_state.label=3;case 3:filteredSeqs=fileNames.filter(function(fileName){return fileName.startsWith("p")&&fileName.endsWith(".ts")}).map(function(fileName){var _fileName_match;var _ref=_sliced_to_array((_fileName_match=fileName.match(/^p([0-9]+)\-/))!==null&&_fileName_match!==void 0?_fileName_match:["0","0"],2),seqNo=_ref[1];return parseInt(seqNo)}).sort(function(a,b){return b-a});if(filteredSeqs.length>0){return[2,filteredSeqs[0]]}return[2,0]}})})()}()];case 2:maxSeqNo=_state.sent();currentSeqNo=maxSeqNo+1;fileName="p".concat(currentSeqNo,"-").concat(name,".ts");dstPath=_path.default.join(practiceDir,fileName);code=['import { Sonamu } from "sonamu";',"","console.clear();",'console.log("'.concat(fileName,'");'),"","Sonamu.runScript(async () => {"," // TODO","});",""].join("\n");return[4,(0,_promises.writeFile)(dstPath,code)];case 3:_state.sent();(0,_child_process.execSync)("code ".concat(dstPath));runCode="yarn node -r dotenv/config -r source-map-support/register dist/practices/".concat(fileName.replace(".ts",".js"));console.log("".concat(_chalk.default.blue(runCode)," copied to clipboard."));(0,_child_process.execSync)('echo "'.concat(runCode,'" | pbcopy'));return[2]}})})()}function stub_entity(entityId){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,_api.Sonamu.syncer.createEntity({entityId:entityId})];case 1:_state.sent();return[2]}})})()}function scaffold_model(entityId){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,_api.Sonamu.syncer.generateTemplate("model",{entityId:entityId})];case 1:_state.sent();return[2]}})})()}function scaffold_model_test(entityId){return _async_to_generator(function(){return _ts_generator(this,function(_state){switch(_state.label){case 0:return[4,_api.Sonamu.syncer.generateTemplate("model_test",{entityId:entityId})];case 1:_state.sent();return[2]}})})()}function ui(){return _async_to_generator(function(){var _Sonamu_config_ui,sonamuUI,_Sonamu_config_projectName,_Sonamu_config_ui_port,e;return _ts_generator(this,function(_state){switch(_state.label){case 0:_state.trys.push([0,2,,3]);return[4,Promise.resolve().then(function(){return /*#__PURE__*/_interop_require_wildcard(require("@sonamu-kit/ui"))})];case 1:sonamuUI=_state.sent();sonamuUI.startServers({projectName:(_Sonamu_config_projectName=_api.Sonamu.config.projectName)!==null&&_Sonamu_config_projectName!==void 0?_Sonamu_config_projectName:_path.default.basename(_api.Sonamu.apiRootPath),apiRootPath:_api.Sonamu.apiRootPath,port:(_Sonamu_config_ui_port=(_Sonamu_config_ui=_api.Sonamu.config.ui)===null||_Sonamu_config_ui===void 0?void 0:_Sonamu_config_ui.port)!==null&&_Sonamu_config_ui_port!==void 0?_Sonamu_config_ui_port:57e3});return[3,3];case 2:e=_state.sent();if(_instanceof(e,Error)&&e.message.includes("isn't declared")){console.log("You need to install ".concat(_chalk.default.blue("@sonamu-kit/ui")," first."));return[2]}throw e;case 3:return[2]}})})()}
904
2
  //# sourceMappingURL=cli.js.map