sonamu 0.6.0 → 0.7.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 (406) hide show
  1. package/.swcrc.project-default +18 -0
  2. package/bin/cli.js +24 -0
  3. package/dist/ai/agents/agent.d.ts +11 -0
  4. package/dist/ai/agents/agent.d.ts.map +1 -0
  5. package/dist/ai/agents/agent.js +65 -0
  6. package/dist/ai/agents/index.d.ts +3 -0
  7. package/dist/ai/agents/index.d.ts.map +1 -0
  8. package/dist/ai/agents/index.js +4 -0
  9. package/dist/ai/agents/types.d.ts +43 -0
  10. package/dist/ai/agents/types.d.ts.map +1 -0
  11. package/dist/ai/agents/types.js +3 -0
  12. package/dist/ai/index.d.ts +2 -0
  13. package/dist/ai/index.d.ts.map +1 -0
  14. package/dist/ai/index.js +3 -0
  15. package/dist/ai/providers/rtzr/api.d.ts +22 -0
  16. package/dist/ai/providers/rtzr/api.d.ts.map +1 -0
  17. package/dist/ai/providers/rtzr/api.js +28 -0
  18. package/dist/ai/providers/rtzr/error.d.ts +18 -0
  19. package/dist/ai/providers/rtzr/error.d.ts.map +1 -0
  20. package/dist/ai/providers/rtzr/error.js +29 -0
  21. package/dist/ai/providers/rtzr/index.d.ts +5 -0
  22. package/dist/ai/providers/rtzr/index.d.ts.map +1 -0
  23. package/dist/ai/providers/rtzr/index.js +6 -0
  24. package/dist/ai/providers/rtzr/model.d.ts +52 -0
  25. package/dist/ai/providers/rtzr/model.d.ts.map +1 -0
  26. package/dist/ai/providers/rtzr/model.js +137 -0
  27. package/dist/ai/providers/rtzr/options.d.ts +7 -0
  28. package/dist/ai/providers/rtzr/options.d.ts.map +1 -0
  29. package/dist/ai/providers/rtzr/options.js +47 -0
  30. package/dist/ai/providers/rtzr/provider.d.ts +18 -0
  31. package/dist/ai/providers/rtzr/provider.d.ts.map +1 -0
  32. package/dist/ai/providers/rtzr/provider.js +54 -0
  33. package/dist/ai/providers/rtzr/utils.d.ts +19 -0
  34. package/dist/ai/providers/rtzr/utils.d.ts.map +1 -0
  35. package/dist/ai/providers/rtzr/utils.js +88 -0
  36. package/dist/api/base-frame.d.ts +2 -2
  37. package/dist/api/base-frame.d.ts.map +1 -1
  38. package/dist/api/base-frame.js +2 -1
  39. package/dist/api/caster.d.ts.map +1 -1
  40. package/dist/api/caster.js +6 -1
  41. package/dist/api/code-converters.d.ts +58 -14
  42. package/dist/api/code-converters.d.ts.map +1 -1
  43. package/dist/api/code-converters.js +178 -409
  44. package/dist/api/config.d.ts +27 -13
  45. package/dist/api/config.d.ts.map +1 -1
  46. package/dist/api/config.js +19 -26
  47. package/dist/api/context.d.ts +4 -3
  48. package/dist/api/context.d.ts.map +1 -1
  49. package/dist/api/context.js +1 -1
  50. package/dist/api/decorators.d.ts +20 -6
  51. package/dist/api/decorators.d.ts.map +1 -1
  52. package/dist/api/decorators.js +111 -18
  53. package/dist/api/index.d.ts +2 -2
  54. package/dist/api/index.d.ts.map +1 -1
  55. package/dist/api/index.js +3 -3
  56. package/dist/api/sonamu.d.ts +7 -7
  57. package/dist/api/sonamu.d.ts.map +1 -1
  58. package/dist/api/sonamu.js +83 -51
  59. package/dist/api/validator.d.ts +6 -0
  60. package/dist/api/validator.d.ts.map +1 -0
  61. package/dist/api/validator.js +81 -0
  62. package/dist/bin/build-config.d.ts +5 -1
  63. package/dist/bin/build-config.d.ts.map +1 -1
  64. package/dist/bin/build-config.js +5 -2
  65. package/dist/bin/cli.js +165 -64
  66. package/dist/bin/loader-register.d.ts +2 -0
  67. package/dist/bin/loader-register.d.ts.map +1 -0
  68. package/dist/bin/loader-register.js +34 -0
  69. package/dist/database/_batch_update.d.ts +5 -3
  70. package/dist/database/_batch_update.d.ts.map +1 -1
  71. package/dist/database/_batch_update.js +30 -13
  72. package/dist/database/base-model.d.ts +96 -10
  73. package/dist/database/base-model.d.ts.map +1 -1
  74. package/dist/database/base-model.js +232 -89
  75. package/dist/database/base-model.types.d.ts +93 -0
  76. package/dist/database/base-model.types.d.ts.map +1 -0
  77. package/dist/database/base-model.types.js +10 -0
  78. package/dist/database/code-generator.d.ts +1 -1
  79. package/dist/database/code-generator.d.ts.map +1 -1
  80. package/dist/database/code-generator.js +11 -10
  81. package/dist/database/db.d.ts +5 -6
  82. package/dist/database/db.d.ts.map +1 -1
  83. package/dist/database/db.js +22 -25
  84. package/dist/database/puri-subset.test-d.js +81 -0
  85. package/dist/database/puri-subset.types.d.ts +123 -0
  86. package/dist/database/puri-subset.types.d.ts.map +1 -0
  87. package/dist/database/puri-subset.types.js +16 -0
  88. package/dist/database/puri-wrapper.d.ts +13 -11
  89. package/dist/database/puri-wrapper.d.ts.map +1 -1
  90. package/dist/database/puri-wrapper.js +2 -2
  91. package/dist/database/puri.d.ts +25 -14
  92. package/dist/database/puri.d.ts.map +1 -1
  93. package/dist/database/puri.js +83 -21
  94. package/dist/database/puri.types.d.ts +21 -7
  95. package/dist/database/puri.types.d.ts.map +1 -1
  96. package/dist/database/puri.types.js +4 -1
  97. package/dist/database/transaction-context.d.ts +1 -1
  98. package/dist/database/transaction-context.d.ts.map +1 -1
  99. package/dist/database/transaction-context.js +1 -1
  100. package/dist/database/upsert-builder.d.ts +9 -3
  101. package/dist/database/upsert-builder.d.ts.map +1 -1
  102. package/dist/database/upsert-builder.js +228 -78
  103. package/dist/entity/entity-manager.d.ts +165 -2
  104. package/dist/entity/entity-manager.d.ts.map +1 -1
  105. package/dist/entity/entity-manager.js +26 -10
  106. package/dist/entity/entity.d.ts +5 -3
  107. package/dist/entity/entity.d.ts.map +1 -1
  108. package/dist/entity/entity.js +153 -54
  109. package/dist/exceptions/error-handler.d.ts +1 -1
  110. package/dist/exceptions/error-handler.d.ts.map +1 -1
  111. package/dist/exceptions/error-handler.js +1 -1
  112. package/dist/exceptions/so-exceptions.d.ts +1 -1
  113. package/dist/exceptions/so-exceptions.d.ts.map +1 -1
  114. package/dist/exceptions/so-exceptions.js +1 -1
  115. package/dist/file-storage/driver.d.ts +1 -1
  116. package/dist/file-storage/driver.d.ts.map +1 -1
  117. package/dist/file-storage/driver.js +1 -1
  118. package/dist/file-storage/file-storage.js +2 -2
  119. package/dist/index.d.ts +18 -11
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +19 -13
  122. package/dist/migration/code-generation.d.ts +1 -1
  123. package/dist/migration/code-generation.d.ts.map +1 -1
  124. package/dist/migration/code-generation.js +123 -67
  125. package/dist/migration/migration-set.d.ts +2 -10
  126. package/dist/migration/migration-set.d.ts.map +1 -1
  127. package/dist/migration/migration-set.js +67 -218
  128. package/dist/migration/migrator.d.ts +24 -73
  129. package/dist/migration/migrator.d.ts.map +1 -1
  130. package/dist/migration/migrator.js +121 -301
  131. package/dist/migration/postgresql-schema-reader.d.ts +51 -0
  132. package/dist/migration/postgresql-schema-reader.d.ts.map +1 -0
  133. package/dist/migration/postgresql-schema-reader.js +245 -0
  134. package/dist/migration/types.d.ts +6 -38
  135. package/dist/migration/types.d.ts.map +1 -1
  136. package/dist/migration/types.js +1 -1
  137. package/dist/naite/messaging-types.d.ts +43 -0
  138. package/dist/naite/messaging-types.d.ts.map +1 -0
  139. package/dist/naite/messaging-types.js +7 -0
  140. package/dist/naite/naite-reporter.d.ts +41 -0
  141. package/dist/naite/naite-reporter.d.ts.map +1 -0
  142. package/dist/naite/naite-reporter.js +102 -0
  143. package/dist/naite/naite.d.ts +91 -8
  144. package/dist/naite/naite.d.ts.map +1 -1
  145. package/dist/naite/naite.js +285 -41
  146. package/dist/stream/sse.d.ts +2 -2
  147. package/dist/stream/sse.d.ts.map +1 -1
  148. package/dist/stream/sse.js +1 -1
  149. package/dist/syncer/api-parser.d.ts +3 -13
  150. package/dist/syncer/api-parser.d.ts.map +1 -1
  151. package/dist/syncer/api-parser.js +67 -56
  152. package/dist/syncer/checksum.d.ts +2 -2
  153. package/dist/syncer/checksum.d.ts.map +1 -1
  154. package/dist/syncer/checksum.js +11 -11
  155. package/dist/syncer/code-generator.d.ts +3 -3
  156. package/dist/syncer/code-generator.d.ts.map +1 -1
  157. package/dist/syncer/code-generator.js +37 -17
  158. package/dist/syncer/entity-operations.d.ts +2 -2
  159. package/dist/syncer/entity-operations.d.ts.map +1 -1
  160. package/dist/syncer/entity-operations.js +9 -8
  161. package/dist/syncer/file-patterns.d.ts +1 -1
  162. package/dist/syncer/file-patterns.d.ts.map +1 -1
  163. package/dist/syncer/file-patterns.js +1 -1
  164. package/dist/syncer/index.d.ts +4 -4
  165. package/dist/syncer/index.d.ts.map +1 -1
  166. package/dist/syncer/index.js +5 -5
  167. package/dist/syncer/module-loader.d.ts +4 -4
  168. package/dist/syncer/module-loader.d.ts.map +1 -1
  169. package/dist/syncer/module-loader.js +17 -12
  170. package/dist/syncer/syncer.d.ts +31 -24
  171. package/dist/syncer/syncer.d.ts.map +1 -1
  172. package/dist/syncer/syncer.js +92 -45
  173. package/dist/template/entity-converter.d.ts +1 -1
  174. package/dist/template/entity-converter.d.ts.map +1 -1
  175. package/dist/template/entity-converter.js +15 -8
  176. package/dist/template/helpers.d.ts +2 -2
  177. package/dist/template/helpers.d.ts.map +1 -1
  178. package/dist/template/helpers.js +3 -3
  179. package/dist/template/implementations/entity.template.d.ts +2 -2
  180. package/dist/template/implementations/entity.template.d.ts.map +1 -1
  181. package/dist/template/implementations/entity.template.js +4 -5
  182. package/dist/template/implementations/generated.template.d.ts +2 -3
  183. package/dist/template/implementations/generated.template.d.ts.map +1 -1
  184. package/dist/template/implementations/generated.template.js +46 -29
  185. package/dist/template/implementations/generated_http.template.d.ts +2 -3
  186. package/dist/template/implementations/generated_http.template.d.ts.map +1 -1
  187. package/dist/template/implementations/generated_http.template.js +9 -9
  188. package/dist/template/implementations/generated_sso.template.d.ts +3 -4
  189. package/dist/template/implementations/generated_sso.template.d.ts.map +1 -1
  190. package/dist/template/implementations/generated_sso.template.js +54 -25
  191. package/dist/template/implementations/init_types.template.d.ts +2 -2
  192. package/dist/template/implementations/init_types.template.d.ts.map +1 -1
  193. package/dist/template/implementations/init_types.template.js +2 -2
  194. package/dist/template/implementations/model.template.d.ts +2 -2
  195. package/dist/template/implementations/model.template.d.ts.map +1 -1
  196. package/dist/template/implementations/model.template.js +47 -37
  197. package/dist/template/implementations/model_test.template.d.ts +2 -2
  198. package/dist/template/implementations/model_test.template.d.ts.map +1 -1
  199. package/dist/template/implementations/model_test.template.js +2 -2
  200. package/dist/template/implementations/service.template.d.ts +4 -4
  201. package/dist/template/implementations/service.template.d.ts.map +1 -1
  202. package/dist/template/implementations/service.template.js +24 -16
  203. package/dist/template/implementations/view_enums_buttonset.template.d.ts +2 -2
  204. package/dist/template/implementations/view_enums_buttonset.template.d.ts.map +1 -1
  205. package/dist/template/implementations/view_enums_buttonset.template.js +1 -1
  206. package/dist/template/implementations/view_enums_dropdown.template.d.ts +2 -2
  207. package/dist/template/implementations/view_enums_dropdown.template.d.ts.map +1 -1
  208. package/dist/template/implementations/view_enums_dropdown.template.js +2 -2
  209. package/dist/template/implementations/view_enums_select.template.d.ts +2 -2
  210. package/dist/template/implementations/view_enums_select.template.d.ts.map +1 -1
  211. package/dist/template/implementations/view_enums_select.template.js +2 -2
  212. package/dist/template/implementations/view_form.template.d.ts +2 -2
  213. package/dist/template/implementations/view_form.template.d.ts.map +1 -1
  214. package/dist/template/implementations/view_form.template.js +4 -4
  215. package/dist/template/implementations/view_id_all_select.template.d.ts +2 -2
  216. package/dist/template/implementations/view_id_all_select.template.d.ts.map +1 -1
  217. package/dist/template/implementations/view_id_all_select.template.js +1 -1
  218. package/dist/template/implementations/view_id_async_select.template.d.ts +2 -2
  219. package/dist/template/implementations/view_id_async_select.template.d.ts.map +1 -1
  220. package/dist/template/implementations/view_id_async_select.template.js +1 -1
  221. package/dist/template/implementations/view_list.template.d.ts +2 -2
  222. package/dist/template/implementations/view_list.template.d.ts.map +1 -1
  223. package/dist/template/implementations/view_list.template.js +29 -19
  224. package/dist/template/implementations/view_list_columns.template.d.ts +3 -3
  225. package/dist/template/implementations/view_list_columns.template.d.ts.map +1 -1
  226. package/dist/template/implementations/view_list_columns.template.js +1 -1
  227. package/dist/template/implementations/view_search_input.template.d.ts +2 -2
  228. package/dist/template/implementations/view_search_input.template.d.ts.map +1 -1
  229. package/dist/template/implementations/view_search_input.template.js +1 -1
  230. package/dist/template/index.d.ts +4 -2
  231. package/dist/template/index.d.ts.map +1 -1
  232. package/dist/template/index.js +5 -3
  233. package/dist/template/template-manager.d.ts +56 -0
  234. package/dist/template/template-manager.d.ts.map +1 -0
  235. package/dist/template/template-manager.js +125 -0
  236. package/dist/template/template-types.d.ts +16 -0
  237. package/dist/template/template-types.d.ts.map +1 -0
  238. package/dist/template/template-types.js +7 -0
  239. package/dist/template/template.d.ts +12 -2
  240. package/dist/template/template.d.ts.map +1 -1
  241. package/dist/template/template.js +19 -6
  242. package/dist/template/zod-converter.d.ts +40 -7
  243. package/dist/template/zod-converter.d.ts.map +1 -1
  244. package/dist/template/zod-converter.js +341 -58
  245. package/dist/testing/_relation-graph.d.ts +1 -1
  246. package/dist/testing/_relation-graph.d.ts.map +1 -1
  247. package/dist/testing/_relation-graph.js +12 -3
  248. package/dist/testing/fixture-manager.d.ts +42 -11
  249. package/dist/testing/fixture-manager.d.ts.map +1 -1
  250. package/dist/testing/fixture-manager.js +338 -236
  251. package/dist/types/types.d.ts +709 -104
  252. package/dist/types/types.d.ts.map +1 -1
  253. package/dist/types/types.js +309 -52
  254. package/dist/typings/knex.d.js +2 -2
  255. package/dist/utils/async-utils.d.ts.map +1 -1
  256. package/dist/utils/async-utils.js +3 -3
  257. package/dist/utils/console-util.js +1 -1
  258. package/dist/utils/controller.d.ts +1 -0
  259. package/dist/utils/controller.d.ts.map +1 -1
  260. package/dist/utils/controller.js +4 -1
  261. package/dist/utils/esm-utils.d.ts +0 -6
  262. package/dist/utils/esm-utils.d.ts.map +1 -1
  263. package/dist/utils/esm-utils.js +2 -9
  264. package/dist/utils/formatter.d.ts +3 -0
  265. package/dist/utils/formatter.d.ts.map +1 -0
  266. package/dist/utils/formatter.js +110 -0
  267. package/dist/utils/fs-utils.d.ts +1 -1
  268. package/dist/utils/fs-utils.d.ts.map +1 -1
  269. package/dist/utils/fs-utils.js +1 -1
  270. package/dist/utils/lodash-able.d.ts.map +1 -1
  271. package/dist/utils/lodash-able.js +1 -1
  272. package/dist/utils/object-utils.d.ts +44 -0
  273. package/dist/utils/object-utils.d.ts.map +1 -0
  274. package/dist/utils/object-utils.js +191 -0
  275. package/dist/utils/path-utils.d.ts +1 -1
  276. package/dist/utils/path-utils.d.ts.map +1 -1
  277. package/dist/utils/path-utils.js +3 -3
  278. package/dist/utils/process-utils.js +1 -1
  279. package/dist/utils/sql-parser.d.ts +5 -1
  280. package/dist/utils/sql-parser.d.ts.map +1 -1
  281. package/dist/utils/sql-parser.js +14 -3
  282. package/dist/utils/type-utils.d.ts +23 -0
  283. package/dist/utils/type-utils.d.ts.map +1 -0
  284. package/dist/utils/type-utils.js +45 -0
  285. package/dist/utils/utils.d.ts +7 -1
  286. package/dist/utils/utils.d.ts.map +1 -1
  287. package/dist/utils/utils.js +44 -5
  288. package/dist/utils/zod-error.d.ts +1 -1
  289. package/dist/utils/zod-error.d.ts.map +1 -1
  290. package/dist/utils/zod-error.js +1 -1
  291. package/package.json +54 -29
  292. package/src/ai/agents/agent.ts +87 -0
  293. package/src/ai/agents/index.ts +2 -0
  294. package/src/ai/agents/types.ts +47 -0
  295. package/src/ai/index.ts +1 -0
  296. package/src/ai/providers/rtzr/api.ts +37 -0
  297. package/src/ai/providers/rtzr/error.ts +34 -0
  298. package/src/ai/providers/rtzr/index.ts +4 -0
  299. package/src/ai/providers/rtzr/model.ts +201 -0
  300. package/src/ai/providers/rtzr/options.ts +49 -0
  301. package/src/ai/providers/rtzr/provider.ts +91 -0
  302. package/src/ai/providers/rtzr/utils.ts +127 -0
  303. package/src/api/base-frame.ts +4 -2
  304. package/src/api/caster.ts +17 -23
  305. package/src/api/code-converters.ts +176 -533
  306. package/src/api/config.ts +39 -56
  307. package/src/api/context.ts +7 -18
  308. package/src/api/decorators.ts +175 -46
  309. package/src/api/index.ts +2 -2
  310. package/src/api/sonamu.ts +133 -124
  311. package/src/api/validator.ts +83 -0
  312. package/src/bin/build-config.ts +7 -1
  313. package/src/bin/cli.ts +192 -110
  314. package/src/bin/loader-register.ts +38 -0
  315. package/src/database/_batch_update.ts +46 -31
  316. package/src/database/base-model.ts +390 -182
  317. package/src/database/base-model.types.ts +155 -0
  318. package/src/database/code-generator.ts +13 -32
  319. package/src/database/db.ts +36 -50
  320. package/src/database/puri-subset.test-d.ts +471 -0
  321. package/src/database/puri-subset.types.ts +195 -0
  322. package/src/database/puri-wrapper.ts +58 -67
  323. package/src/database/puri.ts +182 -126
  324. package/src/database/puri.types.ts +64 -31
  325. package/src/database/transaction-context.ts +1 -1
  326. package/src/database/upsert-builder.ts +262 -132
  327. package/src/entity/entity-manager.ts +36 -28
  328. package/src/entity/entity.ts +330 -249
  329. package/src/exceptions/error-handler.ts +3 -3
  330. package/src/exceptions/so-exceptions.ts +11 -11
  331. package/src/file-storage/driver.ts +5 -5
  332. package/src/file-storage/file-storage.ts +2 -2
  333. package/src/index.ts +18 -12
  334. package/src/migration/code-generation.ts +185 -172
  335. package/src/migration/migration-set.ts +80 -293
  336. package/src/migration/migrator.ts +182 -425
  337. package/src/migration/mysql-schema-reader.ts.txt +272 -0
  338. package/src/migration/postgresql-schema-reader.ts +310 -0
  339. package/src/migration/types.ts +6 -39
  340. package/src/naite/messaging-types.ts +51 -0
  341. package/src/naite/naite-reporter.ts +128 -0
  342. package/src/naite/naite.ts +378 -33
  343. package/src/shared/web.shared.ts.txt +20 -24
  344. package/src/stream/sse.ts +5 -5
  345. package/src/syncer/api-parser.ts +52 -69
  346. package/src/syncer/checksum.ts +25 -37
  347. package/src/syncer/code-generator.ts +58 -62
  348. package/src/syncer/entity-operations.ts +12 -15
  349. package/src/syncer/file-patterns.ts +2 -2
  350. package/src/syncer/index.ts +4 -4
  351. package/src/syncer/module-loader.ts +28 -25
  352. package/src/syncer/syncer.ts +155 -162
  353. package/src/template/entity-converter.ts +18 -27
  354. package/src/template/helpers.ts +8 -11
  355. package/src/template/implementations/entity.template.ts +6 -6
  356. package/src/template/implementations/generated.template.ts +99 -99
  357. package/src/template/implementations/generated_http.template.ts +21 -54
  358. package/src/template/implementations/generated_sso.template.ts +78 -65
  359. package/src/template/implementations/init_types.template.ts +4 -6
  360. package/src/template/implementations/model.template.ts +47 -38
  361. package/src/template/implementations/model_test.template.ts +3 -3
  362. package/src/template/implementations/service.template.ts +56 -80
  363. package/src/template/implementations/view_enums_buttonset.template.ts +2 -2
  364. package/src/template/implementations/view_enums_dropdown.template.ts +4 -4
  365. package/src/template/implementations/view_enums_select.template.ts +3 -3
  366. package/src/template/implementations/view_form.template.ts +34 -75
  367. package/src/template/implementations/view_id_all_select.template.ts +2 -2
  368. package/src/template/implementations/view_id_async_select.template.ts +9 -23
  369. package/src/template/implementations/view_list.template.ts +54 -95
  370. package/src/template/implementations/view_list_columns.template.ts +4 -10
  371. package/src/template/implementations/view_search_input.template.ts +2 -2
  372. package/src/template/index.ts +4 -2
  373. package/src/template/template-manager.ts +166 -0
  374. package/src/template/template-types.ts +16 -0
  375. package/src/template/template.ts +29 -10
  376. package/src/template/zod-converter.ts +407 -101
  377. package/src/testing/_relation-graph.ts +18 -11
  378. package/src/testing/fixture-manager.ts +468 -362
  379. package/src/types/types.ts +516 -248
  380. package/src/typings/knex.d.ts +7 -9
  381. package/src/utils/async-utils.ts +8 -12
  382. package/src/utils/console-util.ts +1 -1
  383. package/src/utils/controller.ts +3 -0
  384. package/src/utils/esm-utils.ts +8 -18
  385. package/src/utils/formatter.ts +109 -0
  386. package/src/utils/fs-utils.ts +1 -1
  387. package/src/utils/lodash-able.ts +1 -4
  388. package/src/utils/object-utils.ts +217 -0
  389. package/src/utils/path-utils.ts +3 -6
  390. package/src/utils/process-utils.ts +1 -1
  391. package/src/utils/sql-parser.ts +23 -5
  392. package/src/utils/type-utils.ts +83 -0
  393. package/src/utils/utils.ts +58 -9
  394. package/src/utils/zod-error.ts +3 -3
  395. package/dist/bin/cli-wrapper.d.ts +0 -3
  396. package/dist/bin/cli-wrapper.d.ts.map +0 -1
  397. package/dist/bin/cli-wrapper.js +0 -72
  398. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +0 -2
  399. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +0 -1
  400. package/dist/database/knex-plugins/knex-on-duplicate-update.js +0 -39
  401. package/dist/entity/entity-utils.d.ts +0 -61
  402. package/dist/entity/entity-utils.d.ts.map +0 -1
  403. package/dist/entity/entity-utils.js +0 -210
  404. package/src/bin/cli-wrapper.ts +0 -82
  405. package/src/database/knex-plugins/knex-on-duplicate-update.ts +0 -45
  406. package/src/entity/entity-utils.ts +0 -291
@@ -0,0 +1,155 @@
1
+ /**
2
+ * BaseModel 타입 시스템
3
+ *
4
+ * BaseModelClass에서 사용하는 타입 유틸리티들.
5
+ * Enhancer, SubsetQuery 교집합 등 Model 계층에서 필요한 타입 정의.
6
+ */
7
+
8
+ import type { DatabaseSchemaExtend } from "../types/types";
9
+ import type { Puri } from "./puri";
10
+ import type { PuriSubsetFn } from "./puri-subset.types";
11
+
12
+ // ============================================================================
13
+ // Puri 테이블 추출 유틸리티
14
+ // ============================================================================
15
+
16
+ /**
17
+ * Puri 인스턴스에서 TTables 타입 추출
18
+ */
19
+ export type ExtractPuriTables<T> = T extends Puri<any, infer TTables, any> ? TTables : never;
20
+
21
+ /**
22
+ * SubsetQueries에서 모든 TTables의 유니온 추출
23
+ * getSubsetQueries의 qb 타입 정의에 사용
24
+ */
25
+ export type UnionExtractedTTables<
26
+ TSubsetKey extends string,
27
+ TSubsetQueries extends Record<TSubsetKey, PuriSubsetFn>,
28
+ > = ExtractPuriTables<ReturnType<TSubsetQueries[TSubsetKey]>>;
29
+
30
+ // ============================================================================
31
+ // Subset 교집합 계산 (onSubset 메서드용)
32
+ // ============================================================================
33
+
34
+ /**
35
+ * 두 Puri의 테이블 교집합을 가진 새로운 Puri 생성
36
+ */
37
+ type MergePuriTables<A, B, TA = ExtractPuriTables<A>, TB = ExtractPuriTables<B>> = Puri<
38
+ DatabaseSchemaExtend,
39
+ Pick<TA, Extract<keyof TA, keyof TB>>,
40
+ any
41
+ >;
42
+
43
+ /**
44
+ * 서브셋 키 배열을 순회하며 테이블 교집합 Puri 계산
45
+ *
46
+ * onSubset(['A', 'P'])와 같이 여러 subset을 지정했을 때,
47
+ * 공통으로 사용 가능한 테이블만 포함된 Puri 타입 반환
48
+ */
49
+ export type ResolveSubsetIntersection<
50
+ Keys extends readonly string[],
51
+ Queries extends Record<string, (...args: any) => any>,
52
+ > = Keys extends [infer Head extends string, ...infer Tail extends string[]]
53
+ ? Tail extends []
54
+ ? ReturnType<Queries[Head]>
55
+ : MergePuriTables<ReturnType<Queries[Head]>, ResolveSubsetIntersection<Tail, Queries>>
56
+ : never;
57
+
58
+ // ============================================================================
59
+ // Enhancer
60
+ // ============================================================================
61
+
62
+ /**
63
+ * 단일 Enhancer 함수 타입
64
+ * computed 결과를 받아 최종 mapping 타입으로 변환
65
+ */
66
+ export type EnhancerFn<TComputed, TMapping> = (row: TComputed) => TMapping | Promise<TMapping>;
67
+
68
+ /**
69
+ * Enhancer가 필수인 SubsetKey 추출
70
+ *
71
+ * ComputedResults[K]가 SubsetMapping[K]에 할당 불가능하면 해당 K는 필수
72
+ * (즉, virtual 필드 등 추가 변환이 필요한 경우)
73
+ */
74
+ export type RequiredEnhancerKeys<
75
+ TSubsetKey extends string,
76
+ TComputedResults extends Record<TSubsetKey, any>,
77
+ TSubsetMapping extends Record<TSubsetKey, any>,
78
+ > = {
79
+ [K in TSubsetKey]: TComputedResults[K] extends TSubsetMapping[K] ? never : K;
80
+ }[TSubsetKey];
81
+
82
+ /**
83
+ * Enhancer 객체 타입 정의
84
+ *
85
+ * - ComputedResults[K]가 SubsetMapping[K]에 assignable하면 → enhancer 선택적
86
+ * - 그렇지 않으면 → enhancer 필수
87
+ *
88
+ * @example
89
+ * // virtual 필드 employee_count가 있는 경우
90
+ * type Computed = { id: number; name: string }
91
+ * type Mapping = { id: number; name: string; employee_count: number }
92
+ * // → Enhancer 필수 (employee_count 계산 필요)
93
+ */
94
+ export type EnhancerMap<
95
+ TSubsetKey extends string,
96
+ TComputedResults extends Record<TSubsetKey, any>,
97
+ TSubsetMapping extends Record<TSubsetKey, any>,
98
+ > = {
99
+ // Computed가 Mapping에 호환되면 선택적
100
+ [K in TSubsetKey as TComputedResults[K] extends TSubsetMapping[K] ? K : never]?: EnhancerFn<
101
+ TComputedResults[K],
102
+ TSubsetMapping[K]
103
+ >;
104
+ } & {
105
+ // 호환되지 않으면 필수
106
+ [K in TSubsetKey as TComputedResults[K] extends TSubsetMapping[K] ? never : K]: EnhancerFn<
107
+ TComputedResults[K],
108
+ TSubsetMapping[K]
109
+ >;
110
+ };
111
+
112
+ // ============================================================================
113
+ // executeSubsetQuery
114
+ // ============================================================================
115
+
116
+ /**
117
+ * executeSubsetQuery 기본 파라미터
118
+ */
119
+ export type ExecuteSubsetQueryBaseParams<TSubsetKey extends string> = {
120
+ subset: TSubsetKey;
121
+ qb: Puri<any, any, any>;
122
+ params: {
123
+ num?: number;
124
+ page?: number;
125
+ queryMode?: "list" | "count" | "both";
126
+ };
127
+ debug?: boolean;
128
+ optimizeCountQuery?: boolean;
129
+ };
130
+
131
+ /**
132
+ * executeSubsetQuery 파라미터 (Enhancer 포함)
133
+ *
134
+ * RequiredEnhancerKeys가 없으면 enhancers 선택적, 있으면 필수
135
+ */
136
+ export type ExecuteSubsetQueryParams<
137
+ TSubsetKey extends string,
138
+ TComputedResults extends Record<TSubsetKey, any>,
139
+ TSubsetMapping extends Record<TSubsetKey, any>,
140
+ T extends TSubsetKey,
141
+ > = ExecuteSubsetQueryBaseParams<T> &
142
+ ([RequiredEnhancerKeys<TSubsetKey, TComputedResults, TSubsetMapping>] extends [never]
143
+ ? { enhancers?: EnhancerMap<TSubsetKey, TComputedResults, TSubsetMapping> }
144
+ : { enhancers: EnhancerMap<TSubsetKey, TComputedResults, TSubsetMapping> });
145
+
146
+ /**
147
+ * executeSubsetQuery 반환 타입
148
+ */
149
+ export type ExecuteSubsetQueryResult<
150
+ TSubsetMapping extends Record<string, any>,
151
+ T extends string,
152
+ > = {
153
+ rows: TSubsetMapping[T][];
154
+ total: number;
155
+ };
@@ -1,12 +1,10 @@
1
- import * as _ from "lodash-es";
2
1
  import equal from "fast-deep-equal";
3
- import { MigrationColumn, MigrationIndex } from "../types/types";
2
+ import { diff } from "radashi";
3
+ import type { MigrationColumn, MigrationIndex } from "../types/types";
4
+ import { differenceWith, intersectionBy } from "../utils/utils";
4
5
 
5
6
  export class CodeGenerator {
6
- getAlterColumnsTo(
7
- entityColumns: MigrationColumn[],
8
- dbColumns: MigrationColumn[]
9
- ) {
7
+ getAlterColumnsTo(entityColumns: MigrationColumn[], dbColumns: MigrationColumn[]) {
10
8
  const columnsTo = {
11
9
  add: [] as MigrationColumn[],
12
10
  drop: [] as MigrationColumn[],
@@ -15,8 +13,8 @@ export class CodeGenerator {
15
13
 
16
14
  // 컬럼명 기준 비교
17
15
  const extraColumns = {
18
- db: _.differenceBy(dbColumns, entityColumns, (col) => col.name),
19
- entity: _.differenceBy(entityColumns, dbColumns, (col) => col.name),
16
+ db: diff(dbColumns, entityColumns, (col) => col.name),
17
+ entity: diff(entityColumns, dbColumns, (col) => col.name),
20
18
  };
21
19
  if (extraColumns.entity.length > 0) {
22
20
  columnsTo.add = columnsTo.add.concat(extraColumns.entity);
@@ -26,39 +24,22 @@ export class CodeGenerator {
26
24
  }
27
25
 
28
26
  // 동일 컬럼명의 세부 필드 비교
29
- const sameDbColumns = _.intersectionBy(
30
- dbColumns,
31
- entityColumns,
32
- (col) => col.name
33
- );
34
- const sameMdColumns = _.intersectionBy(
35
- entityColumns,
36
- dbColumns,
37
- (col) => col.name
38
- );
39
- columnsTo.alter = _.differenceWith(sameDbColumns, sameMdColumns, (a, b) =>
40
- equal(a, b)
41
- );
27
+ const sameDbColumns = intersectionBy(dbColumns, entityColumns, (col) => col.name);
28
+ const sameMdColumns = intersectionBy(entityColumns, dbColumns, (col) => col.name);
29
+ columnsTo.alter = differenceWith(sameDbColumns, sameMdColumns, (a, b) => equal(a, b));
42
30
 
43
31
  return columnsTo;
44
32
  }
45
33
 
46
- getAlterIndexesTo(
47
- entityIndexes: MigrationIndex[],
48
- dbIndexes: MigrationIndex[]
49
- ) {
34
+ getAlterIndexesTo(entityIndexes: MigrationIndex[], dbIndexes: MigrationIndex[]) {
50
35
  // 인덱스 비교
51
- let indexesTo = {
36
+ const indexesTo = {
52
37
  add: [] as MigrationIndex[],
53
38
  drop: [] as MigrationIndex[],
54
39
  };
55
40
  const extraIndexes = {
56
- db: _.differenceBy(dbIndexes, entityIndexes, (col) =>
57
- [col.type, col.columns.join("-")].join("//")
58
- ),
59
- entity: _.differenceBy(entityIndexes, dbIndexes, (col) =>
60
- [col.type, col.columns.join("-")].join("//")
61
- ),
41
+ db: diff(dbIndexes, entityIndexes, (col) => [col.type, col.columns.join("-")].join("//")),
42
+ entity: diff(entityIndexes, dbIndexes, (col) => [col.type, col.columns.join("-")].join("//")),
62
43
  };
63
44
  if (extraIndexes.entity.length > 0) {
64
45
  indexesTo.add = indexesTo.add.concat(extraIndexes.entity);
@@ -1,22 +1,22 @@
1
- export type DBPreset = "w" | "r";
2
- import knex, { Knex } from "knex";
3
- import * as _ from "lodash-es";
4
- import { Sonamu } from "../api";
5
1
  import { AsyncLocalStorage } from "async_hooks";
2
+ import knex, { type Knex } from "knex";
3
+ import { assign } from "radashi";
4
+ import { Sonamu } from "../api";
5
+ import type { DatabaseConfig, SonamuConfig } from "../api/config";
6
6
  import { TransactionContext } from "./transaction-context";
7
- import { DatabaseConfig, SonamuConfig } from "../api/config";
7
+
8
+ export type DBPreset = "w" | "r";
8
9
 
9
10
  export type SonamuDBConfig = {
10
11
  development_master: Knex.Config;
11
12
  development_slave: Knex.Config;
12
13
  test: Knex.Config;
13
- fixture_local: Knex.Config;
14
14
  fixture_remote: Knex.Config;
15
15
  production_master: Knex.Config;
16
16
  production_slave: Knex.Config;
17
17
  };
18
18
 
19
- class DBClass {
19
+ export class DBClass {
20
20
  private wdb?: Knex;
21
21
  private rdb?: Knex;
22
22
 
@@ -40,15 +40,15 @@ class DBClass {
40
40
  } else if (this.wdb) {
41
41
  return this.wdb;
42
42
  } else {
43
- this["wdb"] = knex({
44
- ...dbConfig["test"],
43
+ this.wdb = knex({
44
+ ...dbConfig.test,
45
45
  // 단일 풀
46
46
  pool: {
47
47
  min: 1,
48
48
  max: 1,
49
49
  },
50
50
  });
51
- return this["wdb"];
51
+ return this.wdb;
52
52
  }
53
53
  }
54
54
 
@@ -61,25 +61,22 @@ class DBClass {
61
61
  case "staging":
62
62
  config =
63
63
  which === "w"
64
- ? dbConfig["development_master"]
65
- : (dbConfig["development_slave"] ??
66
- dbConfig["development_master"]);
64
+ ? dbConfig.development_master
65
+ : (dbConfig.development_slave ?? dbConfig.development_master);
67
66
  break;
68
67
  case "production":
69
68
  config =
70
69
  which === "w"
71
- ? dbConfig["production_master"]
72
- : (dbConfig["production_slave"] ?? dbConfig["production_master"]);
70
+ ? dbConfig.production_master
71
+ : (dbConfig.production_slave ?? dbConfig.production_master);
73
72
  break;
74
73
  default:
75
- throw new Error(
76
- `현재 ENV ${process.env.NODE_ENV}에는 설정 가능한 DB설정이 없습니다.`
77
- );
74
+ throw new Error(`현재 ENV ${process.env.NODE_ENV}에는 설정 가능한 DB설정이 없습니다.`);
78
75
  }
79
76
  this[instanceName] = knex(config);
80
77
  }
81
78
 
82
- return this[instanceName]!;
79
+ return this[instanceName];
83
80
  }
84
81
 
85
82
  async destroy(): Promise<void> {
@@ -94,9 +91,9 @@ class DBClass {
94
91
  }
95
92
 
96
93
  public generateDBConfig(config: SonamuConfig["database"]): SonamuDBConfig {
97
- const defaultKnexConfig: Partial<DatabaseConfig> = _.merge(
94
+ const defaultKnexConfig: Partial<DatabaseConfig> = assign(
98
95
  {
99
- client: "mysql2",
96
+ client: "pg",
100
97
  pool: {
101
98
  min: 1,
102
99
  max: 5,
@@ -109,61 +106,46 @@ class DBClass {
109
106
  ...config.defaultOptions?.connection,
110
107
  },
111
108
  },
112
- config.defaultOptions
109
+ config.defaultOptions,
113
110
  );
114
111
 
115
112
  // 로컬 환경 설정
116
- const test: DatabaseConfig = _.merge({}, defaultKnexConfig, {
113
+ const test: DatabaseConfig = assign(defaultKnexConfig, {
117
114
  connection: {
118
115
  database: `${config.name}_test`,
119
116
  ...config.defaultOptions?.connection,
120
117
  },
121
118
  });
122
119
 
123
- const fixture_local = _.merge({}, defaultKnexConfig, {
124
- connection: {
125
- database: `${config.name}_fixture_local`,
126
- ...config.defaultOptions?.connection,
127
- },
128
- });
129
-
130
120
  // 개발 환경 설정
131
121
  const devMasterOptions = config.environments?.development;
132
122
  const devSlaveOptions = config.environments?.development_slave;
133
- const development_master = _.merge({}, defaultKnexConfig, devMasterOptions);
134
- const development_slave = _.merge(
135
- {},
136
- defaultKnexConfig,
137
- devMasterOptions,
138
- devSlaveOptions
123
+ const development_master = assign(defaultKnexConfig, devMasterOptions ?? {});
124
+ const development_slave = assign(
125
+ assign(defaultKnexConfig, devMasterOptions ?? {}),
126
+ devSlaveOptions ?? {},
139
127
  );
140
128
  // NOTE: fixture remote는 default connection의 DB를 override해선 안됨.
141
- const fixture_remote = _.merge(
142
- {},
143
- defaultKnexConfig,
144
- devMasterOptions,
145
- {
129
+ const fixture_remote = assign(
130
+ assign(assign(defaultKnexConfig, devMasterOptions ?? {}), {
146
131
  connection: {
147
132
  database: `${config.name}_fixture_remote`,
148
133
  },
149
- },
150
- config.environments?.remote_fixture
134
+ }),
135
+ config.environments?.remote_fixture ?? {},
151
136
  );
152
137
 
153
138
  // 프로덕션 환경 설정
154
139
  const prodMasterOptions = config.environments?.production ?? {};
155
140
  const prodSlaveOptions = config.environments?.production_slave ?? {};
156
- const production_master = _.merge({}, defaultKnexConfig, prodMasterOptions);
157
- const production_slave = _.merge(
158
- {},
159
- defaultKnexConfig,
160
- prodMasterOptions,
161
- prodSlaveOptions
141
+ const production_master = assign(defaultKnexConfig, prodMasterOptions);
142
+ const production_slave = assign(
143
+ assign(defaultKnexConfig, prodMasterOptions),
144
+ prodSlaveOptions ?? {},
162
145
  );
163
146
 
164
147
  return {
165
148
  test,
166
- fixture_local,
167
149
  fixture_remote,
168
150
  development_master,
169
151
  development_slave,
@@ -183,5 +165,9 @@ class DBClass {
183
165
  await this.testTransaction?.rollback();
184
166
  this.testTransaction = null;
185
167
  }
168
+ async getTestConnection(): Promise<Knex> {
169
+ const db = this.getDB("w");
170
+ return db;
171
+ }
186
172
  }
187
173
  export const DB = new DBClass();