sonamu 0.4.13 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/.swcrc +15 -0
  2. package/dist/api/base-frame.d.ts +8 -0
  3. package/dist/api/base-frame.d.ts.map +1 -0
  4. package/dist/api/base-frame.js +2 -0
  5. package/dist/api/base-frame.js.map +1 -0
  6. package/dist/api/caster.d.ts +5 -0
  7. package/dist/api/caster.d.ts.map +1 -0
  8. package/dist/api/caster.js +2 -0
  9. package/dist/api/caster.js.map +1 -0
  10. package/dist/api/code-converters.d.ts +23 -0
  11. package/dist/api/code-converters.d.ts.map +1 -0
  12. package/dist/api/code-converters.js +2 -0
  13. package/dist/api/code-converters.js.map +1 -0
  14. package/dist/api/context.d.ts +16 -0
  15. package/dist/api/context.d.ts.map +1 -0
  16. package/dist/api/context.js +2 -0
  17. package/dist/api/context.js.map +1 -0
  18. package/dist/api/decorators.d.ts +50 -0
  19. package/dist/api/decorators.d.ts.map +1 -0
  20. package/dist/api/decorators.js +2 -0
  21. package/dist/api/decorators.js.map +1 -0
  22. package/dist/api/index.d.ts +8 -0
  23. package/dist/api/index.d.ts.map +1 -0
  24. package/dist/api/index.js +2 -0
  25. package/dist/api/index.js.map +1 -0
  26. package/dist/api/sonamu.d.ts +83 -0
  27. package/dist/api/sonamu.d.ts.map +1 -0
  28. package/dist/api/sonamu.js +2 -0
  29. package/dist/api/sonamu.js.map +1 -0
  30. package/dist/api/sonamu.types.d.ts +30 -0
  31. package/dist/api/sonamu.types.d.ts.map +1 -0
  32. package/dist/api/sonamu.types.js +2 -0
  33. package/dist/api/sonamu.types.js.map +1 -0
  34. package/dist/bin/build-config.d.ts +5 -0
  35. package/dist/bin/build-config.d.ts.map +1 -0
  36. package/dist/bin/build-config.js +2 -0
  37. package/dist/bin/build-config.js.map +1 -0
  38. package/dist/bin/cli-wrapper.d.ts +2 -0
  39. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  40. package/dist/bin/cli-wrapper.js +1 -38
  41. package/dist/bin/cli-wrapper.js.map +1 -1
  42. package/dist/bin/cli.d.ts +2 -2
  43. package/dist/bin/cli.d.ts.map +1 -0
  44. package/dist/bin/cli.js +1 -903
  45. package/dist/bin/cli.js.map +1 -1
  46. package/dist/bin/cli.mjs +2 -2
  47. package/dist/{chunk-DMJSNO2L.js → chunk-2WAC2GER.js} +44 -44
  48. package/dist/{chunk-DMJSNO2L.js.map → chunk-2WAC2GER.js.map} +1 -1
  49. package/dist/{chunk-NI37CY4T.mjs → chunk-C3IPIF6O.mjs} +2 -2
  50. package/dist/{chunk-DYFCACHD.js → chunk-EXHKSVTE.js} +7 -7
  51. package/dist/{chunk-QJFHDCBN.mjs → chunk-FCERKIIF.mjs} +2 -2
  52. package/dist/chunk-FCERKIIF.mjs.map +1 -0
  53. package/dist/{chunk-DDJ7T4MA.mjs → chunk-HGIBJYOU.mjs} +2 -2
  54. package/dist/{chunk-NIFOTHBW.mjs → chunk-JKSOJRQA.mjs} +2 -2
  55. package/dist/{chunk-CXAVBVKC.js → chunk-OTKKFP3Y.js} +100 -100
  56. package/dist/{chunk-J6S43O7G.js → chunk-UZ2IY5VE.js} +4 -4
  57. package/dist/database/_batch_update.d.ts +15 -0
  58. package/dist/database/_batch_update.d.ts.map +1 -0
  59. package/dist/database/_batch_update.js +2 -0
  60. package/dist/database/_batch_update.js.map +1 -0
  61. package/dist/database/base-model.d.ts +41 -0
  62. package/dist/database/base-model.d.ts.map +1 -0
  63. package/dist/database/base-model.js +2 -0
  64. package/dist/database/base-model.js.map +1 -0
  65. package/dist/database/code-generator.d.ts +13 -0
  66. package/dist/database/code-generator.d.ts.map +1 -0
  67. package/dist/database/code-generator.js +2 -0
  68. package/dist/database/code-generator.js.map +1 -0
  69. package/dist/database/db.d.ts +40 -0
  70. package/dist/database/db.d.ts.map +1 -0
  71. package/dist/database/db.js +2 -0
  72. package/dist/database/db.js.map +1 -0
  73. package/dist/database/drivers/knex/base-model.js +8 -8
  74. package/dist/database/drivers/knex/base-model.mjs +3 -3
  75. package/dist/database/drivers/kysely/base-model.js +9 -9
  76. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  77. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  78. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  79. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  80. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  81. package/dist/database/puri-wrapper.d.ts +34 -0
  82. package/dist/database/puri-wrapper.d.ts.map +1 -0
  83. package/dist/database/puri-wrapper.js +2 -0
  84. package/dist/database/puri-wrapper.js.map +1 -0
  85. package/dist/database/puri.d.ts +83 -0
  86. package/dist/database/puri.d.ts.map +1 -0
  87. package/dist/database/puri.js +2 -0
  88. package/dist/database/puri.js.map +1 -0
  89. package/dist/database/puri.types.d.ts +60 -0
  90. package/dist/database/puri.types.d.ts.map +1 -0
  91. package/dist/database/puri.types.js +2 -0
  92. package/dist/database/puri.types.js.map +1 -0
  93. package/dist/database/transaction-context.d.ts +9 -0
  94. package/dist/database/transaction-context.d.ts.map +1 -0
  95. package/dist/database/transaction-context.js +2 -0
  96. package/dist/database/transaction-context.js.map +1 -0
  97. package/dist/database/types.d.ts +39 -0
  98. package/dist/database/types.d.ts.map +1 -0
  99. package/dist/database/types.js +2 -0
  100. package/dist/database/types.js.map +1 -0
  101. package/dist/database/upsert-builder.d.ts +34 -0
  102. package/dist/database/upsert-builder.d.ts.map +1 -0
  103. package/dist/database/upsert-builder.js +2 -0
  104. package/dist/database/upsert-builder.js.map +1 -0
  105. package/dist/entity/entity-manager.d.ts +32 -0
  106. package/dist/entity/entity-manager.d.ts.map +1 -0
  107. package/dist/entity/entity-manager.js +2 -0
  108. package/dist/entity/entity-manager.js.map +1 -0
  109. package/dist/entity/entity-utils.d.ts +61 -0
  110. package/dist/entity/entity-utils.d.ts.map +1 -0
  111. package/dist/entity/entity-utils.js +2 -0
  112. package/dist/entity/entity-utils.js.map +1 -0
  113. package/dist/entity/entity.d.ts +62 -0
  114. package/dist/entity/entity.d.ts.map +1 -0
  115. package/dist/entity/entity.js +2 -0
  116. package/dist/entity/entity.js.map +1 -0
  117. package/dist/entity/migrator.d.ts +135 -0
  118. package/dist/entity/migrator.d.ts.map +1 -0
  119. package/dist/entity/migrator.js +2 -0
  120. package/dist/entity/migrator.js.map +1 -0
  121. package/dist/exceptions/error-handler.d.ts +3 -0
  122. package/dist/exceptions/error-handler.d.ts.map +1 -0
  123. package/dist/exceptions/error-handler.js +2 -0
  124. package/dist/exceptions/error-handler.js.map +1 -0
  125. package/dist/exceptions/so-exceptions.d.ts +48 -0
  126. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  127. package/dist/exceptions/so-exceptions.js +2 -0
  128. package/dist/exceptions/so-exceptions.js.map +1 -0
  129. package/dist/file-storage/driver.d.ts +45 -0
  130. package/dist/file-storage/driver.d.ts.map +1 -0
  131. package/dist/file-storage/driver.js +2 -0
  132. package/dist/file-storage/driver.js.map +1 -0
  133. package/dist/file-storage/file-storage.d.ts +50 -0
  134. package/dist/file-storage/file-storage.d.ts.map +1 -0
  135. package/dist/file-storage/file-storage.js +2 -0
  136. package/dist/file-storage/file-storage.js.map +1 -0
  137. package/dist/index.d.ts +22 -813
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +1 -433
  140. package/dist/index.js.map +1 -1
  141. package/dist/index.mjs +3 -3
  142. package/dist/migration/code-generation.d.ts +15 -0
  143. package/dist/migration/code-generation.d.ts.map +1 -0
  144. package/dist/migration/code-generation.js +2 -0
  145. package/dist/migration/code-generation.js.map +1 -0
  146. package/dist/migration/migration-set.d.ts +17 -0
  147. package/dist/migration/migration-set.d.ts.map +1 -0
  148. package/dist/migration/migration-set.js +2 -0
  149. package/dist/migration/migration-set.js.map +1 -0
  150. package/dist/migration/migrator.d.ts +130 -0
  151. package/dist/migration/migrator.d.ts.map +1 -0
  152. package/dist/migration/migrator.js +2 -0
  153. package/dist/migration/migrator.js.map +1 -0
  154. package/dist/migration/types.d.ts +52 -0
  155. package/dist/migration/types.d.ts.map +1 -0
  156. package/dist/migration/types.js +2 -0
  157. package/dist/migration/types.js.map +1 -0
  158. package/dist/smd/smd-manager.d.ts +28 -0
  159. package/dist/smd/smd-manager.d.ts.map +1 -0
  160. package/dist/smd/smd-manager.js +2 -0
  161. package/dist/smd/smd-manager.js.map +1 -0
  162. package/dist/smd/smd.d.ts +40 -0
  163. package/dist/smd/smd.d.ts.map +1 -0
  164. package/dist/smd/smd.js +2 -0
  165. package/dist/smd/smd.js.map +1 -0
  166. package/dist/syncer/index.d.ts +2 -0
  167. package/dist/syncer/index.d.ts.map +1 -0
  168. package/dist/syncer/index.js +2 -0
  169. package/dist/syncer/index.js.map +1 -0
  170. package/dist/syncer/syncer.d.ts +127 -0
  171. package/dist/syncer/syncer.d.ts.map +1 -0
  172. package/dist/syncer/syncer.js +2 -0
  173. package/dist/syncer/syncer.js.map +1 -0
  174. package/dist/templates/base-template.d.ts +13 -0
  175. package/dist/templates/base-template.d.ts.map +1 -0
  176. package/dist/templates/base-template.js +2 -0
  177. package/dist/templates/base-template.js.map +1 -0
  178. package/dist/templates/entity.template.d.ts +17 -0
  179. package/dist/templates/entity.template.d.ts.map +1 -0
  180. package/dist/templates/entity.template.js +2 -0
  181. package/dist/templates/entity.template.js.map +1 -0
  182. package/dist/templates/generated.template.d.ts +27 -0
  183. package/dist/templates/generated.template.d.ts.map +1 -0
  184. package/dist/templates/generated.template.js +2 -0
  185. package/dist/templates/generated.template.js.map +1 -0
  186. package/dist/templates/generated_http.template.d.ts +24 -0
  187. package/dist/templates/generated_http.template.d.ts.map +1 -0
  188. package/dist/templates/generated_http.template.js +2 -0
  189. package/dist/templates/generated_http.template.js.map +1 -0
  190. package/dist/templates/generated_sso.template.d.ts +20 -0
  191. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  192. package/dist/templates/generated_sso.template.js +2 -0
  193. package/dist/templates/generated_sso.template.js.map +1 -0
  194. package/dist/templates/index.d.ts +2 -0
  195. package/dist/templates/index.d.ts.map +1 -0
  196. package/dist/templates/index.js +2 -0
  197. package/dist/templates/index.js.map +1 -0
  198. package/dist/templates/init_types.template.d.ts +17 -0
  199. package/dist/templates/init_types.template.d.ts.map +1 -0
  200. package/dist/templates/init_types.template.js +2 -0
  201. package/dist/templates/init_types.template.js.map +1 -0
  202. package/dist/templates/model.template.d.ts +17 -0
  203. package/dist/templates/model.template.d.ts.map +1 -0
  204. package/dist/templates/model.template.js +2 -0
  205. package/dist/templates/model.template.js.map +1 -0
  206. package/dist/templates/model_test.template.d.ts +17 -0
  207. package/dist/templates/model_test.template.d.ts.map +1 -0
  208. package/dist/templates/model_test.template.js +2 -0
  209. package/dist/templates/model_test.template.js.map +1 -0
  210. package/dist/templates/service.template.d.ts +29 -0
  211. package/dist/templates/service.template.d.ts.map +1 -0
  212. package/dist/templates/service.template.js +2 -0
  213. package/dist/templates/service.template.js.map +1 -0
  214. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  215. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  216. package/dist/templates/view_enums_buttonset.template.js +2 -0
  217. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  218. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  219. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  220. package/dist/templates/view_enums_dropdown.template.js +2 -0
  221. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  222. package/dist/templates/view_enums_select.template.d.ts +17 -0
  223. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  224. package/dist/templates/view_enums_select.template.js +2 -0
  225. package/dist/templates/view_enums_select.template.js.map +1 -0
  226. package/dist/templates/view_form.template.d.ts +26 -0
  227. package/dist/templates/view_form.template.d.ts.map +1 -0
  228. package/dist/templates/view_form.template.js +2 -0
  229. package/dist/templates/view_form.template.js.map +1 -0
  230. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  231. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  232. package/dist/templates/view_id_all_select.template.js +2 -0
  233. package/dist/templates/view_id_all_select.template.js.map +1 -0
  234. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  235. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  236. package/dist/templates/view_id_async_select.template.js +2 -0
  237. package/dist/templates/view_id_async_select.template.js.map +1 -0
  238. package/dist/templates/view_list.template.d.ts +38 -0
  239. package/dist/templates/view_list.template.d.ts.map +1 -0
  240. package/dist/templates/view_list.template.js +2 -0
  241. package/dist/templates/view_list.template.js.map +1 -0
  242. package/dist/templates/view_list_columns.template.d.ts +17 -0
  243. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  244. package/dist/templates/view_list_columns.template.js +2 -0
  245. package/dist/templates/view_list_columns.template.js.map +1 -0
  246. package/dist/templates/view_search_input.template.d.ts +17 -0
  247. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  248. package/dist/templates/view_search_input.template.js +2 -0
  249. package/dist/templates/view_search_input.template.js.map +1 -0
  250. package/dist/testing/_relation-graph.d.ts +7 -0
  251. package/dist/testing/_relation-graph.d.ts.map +1 -0
  252. package/dist/testing/_relation-graph.js +2 -0
  253. package/dist/testing/_relation-graph.js.map +1 -0
  254. package/dist/testing/fixture-manager.d.ts +35 -0
  255. package/dist/testing/fixture-manager.d.ts.map +1 -0
  256. package/dist/testing/fixture-manager.js +2 -0
  257. package/dist/testing/fixture-manager.js.map +1 -0
  258. package/dist/types/types.d.ts +609 -0
  259. package/dist/types/types.d.ts.map +1 -0
  260. package/dist/types/types.js +2 -0
  261. package/dist/types/types.js.map +1 -0
  262. package/dist/typings/knex.d.js +2 -0
  263. package/dist/typings/knex.d.js.map +1 -0
  264. package/dist/utils/async-utils.d.ts +25 -0
  265. package/dist/utils/async-utils.d.ts.map +1 -0
  266. package/dist/utils/async-utils.js +2 -0
  267. package/dist/utils/async-utils.js.map +1 -0
  268. package/dist/utils/controller.d.ts +9 -0
  269. package/dist/utils/controller.d.ts.map +1 -0
  270. package/dist/utils/controller.js +2 -0
  271. package/dist/utils/controller.js.map +1 -0
  272. package/dist/utils/fs-utils.d.ts +9 -0
  273. package/dist/utils/fs-utils.d.ts.map +1 -0
  274. package/dist/utils/fs-utils.js +2 -0
  275. package/dist/utils/fs-utils.js.map +1 -0
  276. package/dist/utils/lodash-able.d.ts +2 -0
  277. package/dist/utils/lodash-able.d.ts.map +1 -0
  278. package/dist/utils/lodash-able.js +2 -0
  279. package/dist/utils/lodash-able.js.map +1 -0
  280. package/dist/utils/model.d.ts +17 -0
  281. package/dist/utils/model.d.ts.map +1 -0
  282. package/dist/utils/model.js +2 -0
  283. package/dist/utils/model.js.map +1 -0
  284. package/dist/utils/sql-parser.d.ts +4 -0
  285. package/dist/utils/sql-parser.d.ts.map +1 -0
  286. package/dist/utils/sql-parser.js +2 -0
  287. package/dist/utils/sql-parser.js.map +1 -0
  288. package/dist/utils/utils.d.ts +9 -0
  289. package/dist/utils/utils.d.ts.map +1 -0
  290. package/dist/utils/utils.js +2 -0
  291. package/dist/utils/utils.js.map +1 -0
  292. package/dist/utils/zod-error.d.ts +8 -0
  293. package/dist/utils/zod-error.d.ts.map +1 -0
  294. package/dist/utils/zod-error.js +2 -0
  295. package/dist/utils/zod-error.js.map +1 -0
  296. package/nodemon.json +6 -0
  297. package/package.json +29 -44
  298. package/src/api/base-frame.ts +3 -4
  299. package/src/api/caster.ts +22 -23
  300. package/src/api/code-converters.ts +170 -134
  301. package/src/api/context.ts +13 -6
  302. package/src/api/decorators.ts +146 -20
  303. package/src/api/index.ts +2 -0
  304. package/src/api/sonamu.ts +374 -165
  305. package/src/bin/build-config.ts +5 -0
  306. package/src/bin/cli-wrapper.ts +29 -40
  307. package/src/bin/cli.ts +132 -190
  308. package/src/database/_batch_update.ts +10 -15
  309. package/src/database/base-model.ts +300 -216
  310. package/src/database/db.ts +191 -21
  311. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  312. package/src/database/puri-wrapper.ts +129 -0
  313. package/src/database/puri.ts +808 -0
  314. package/src/database/puri.types.ts +222 -0
  315. package/src/database/transaction-context.ts +18 -0
  316. package/src/database/upsert-builder.ts +32 -35
  317. package/src/entity/entity-manager.ts +7 -15
  318. package/src/entity/entity.ts +9 -31
  319. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  320. package/src/file-storage/driver.ts +121 -0
  321. package/src/file-storage/file-storage.ts +100 -0
  322. package/src/index.ts +14 -11
  323. package/src/migration/code-generation.ts +777 -0
  324. package/src/migration/migration-set.ts +453 -0
  325. package/src/migration/migrator.ts +823 -0
  326. package/src/migration/types.ts +53 -0
  327. package/src/shared/web.shared.ts.txt +33 -2
  328. package/src/syncer/syncer.ts +294 -127
  329. package/src/templates/generated.template.ts +13 -1
  330. package/src/templates/generated_http.template.ts +15 -12
  331. package/src/templates/generated_sso.template.ts +50 -2
  332. package/src/templates/model.template.ts +138 -2
  333. package/src/templates/service.template.ts +0 -1
  334. package/src/templates/view_form.template.ts +11 -7
  335. package/src/templates/view_list.template.ts +12 -4
  336. package/src/testing/fixture-manager.ts +229 -174
  337. package/src/types/types.ts +102 -14
  338. package/src/utils/async-utils.ts +64 -0
  339. package/src/utils/fs-utils.ts +17 -0
  340. package/src/utils/model.ts +0 -2
  341. package/src/utils/utils.ts +14 -58
  342. package/src/utils/zod-error.ts +12 -176
  343. package/tsconfig.json +2 -0
  344. package/tsup.config.js +4 -2
  345. package/.pnp.cjs +0 -14363
  346. package/.pnp.loader.mjs +0 -2047
  347. package/.vscode/extensions.json +0 -6
  348. package/.vscode/settings.json +0 -9
  349. package/.yarnrc.yml +0 -5
  350. package/dist/chunk-QJFHDCBN.mjs.map +0 -1
  351. package/src/database/base-model.abstract.ts +0 -97
  352. package/src/database/db.abstract.ts +0 -75
  353. package/src/database/drivers/knex/base-model.ts +0 -55
  354. package/src/database/drivers/knex/client.ts +0 -209
  355. package/src/database/drivers/knex/db.ts +0 -232
  356. package/src/database/drivers/knex/generator.ts +0 -659
  357. package/src/database/drivers/kysely/base-model.ts +0 -89
  358. package/src/database/drivers/kysely/client.ts +0 -309
  359. package/src/database/drivers/kysely/db.ts +0 -238
  360. package/src/database/drivers/kysely/generator.ts +0 -714
  361. package/src/database/types.ts +0 -118
  362. package/src/entity/migrator.ts +0 -1400
  363. package/src/smd/smd-manager.ts +0 -139
  364. package/src/smd/smd.ts +0 -571
  365. package/src/templates/kysely_types.template.ts +0 -205
  366. /package/dist/{chunk-NI37CY4T.mjs.map → chunk-C3IPIF6O.mjs.map} +0 -0
  367. /package/dist/{chunk-DYFCACHD.js.map → chunk-EXHKSVTE.js.map} +0 -0
  368. /package/dist/{chunk-DDJ7T4MA.mjs.map → chunk-HGIBJYOU.mjs.map} +0 -0
  369. /package/dist/{chunk-NIFOTHBW.mjs.map → chunk-JKSOJRQA.mjs.map} +0 -0
  370. /package/dist/{chunk-CXAVBVKC.js.map → chunk-OTKKFP3Y.js.map} +0 -0
  371. /package/dist/{chunk-J6S43O7G.js.map → chunk-UZ2IY5VE.js.map} +0 -0
@@ -1,6 +1,19 @@
1
+ import type { GuardKey } from "./../api/decorators";
2
+ import type { FastifyCorsOptions } from "@fastify/cors";
3
+ import type { FastifyFormbodyOptions } from "@fastify/formbody";
4
+ import type {
5
+ FastifyInstance,
6
+ FastifyReply,
7
+ FastifyRequest,
8
+ FastifyServerOptions,
9
+ } from "fastify";
10
+ import type { QsPluginOptions } from "fastify-qs";
1
11
  import { z } from "zod";
12
+ import type { Context, ApiDecoratorOptions } from "../api";
13
+ import type { FastifyMultipartOptions } from "@fastify/multipart";
14
+ import type { Driver } from "../file-storage/driver";
2
15
 
3
- /*
16
+ /*
4
17
  Enums
5
18
  */
6
19
  export type EnumsLabel<T extends string, L extends "ko" | "en"> = {
@@ -26,7 +39,7 @@ export type SQLDateTimeString = z.infer<typeof SQLDateTimeString>;
26
39
  */
27
40
  export function zArrayable<T extends z.ZodTypeAny>(
28
41
  shape: T
29
- ): z.ZodUnion<[T, z.ZodArray<T, "many">]> {
42
+ ): z.ZodUnion<[T, z.ZodArray<T>]> {
30
43
  return z.union([shape, shape.array()]);
31
44
  }
32
45
  export type DistributiveOmit<T, K extends keyof any> = T extends any
@@ -186,9 +199,10 @@ export type EntityProp =
186
199
  | RelationProp;
187
200
 
188
201
  export type EntityIndex = {
189
- type: "index" | "unique";
202
+ type: "index" | "unique" | "fulltext";
190
203
  columns: string[];
191
204
  name?: string;
205
+ parser?: "built-in" | "ngram";
192
206
  };
193
207
  export type EntityJson = {
194
208
  id: string;
@@ -412,9 +426,6 @@ export type KnexError = {
412
426
  export function isKnexError(e: any): e is KnexError {
413
427
  return e.code && e.sqlMessage && e.sqlState;
414
428
  }
415
- export function isKyselyError(e: any): e is KnexError {
416
- return e.code && e.sqlMessage && e.sqlState;
417
- }
418
429
 
419
430
  export type KnexColumnType =
420
431
  | "string"
@@ -446,7 +457,8 @@ export type MigrationColumn = {
446
457
  };
447
458
  export type MigrationIndex = {
448
459
  columns: string[];
449
- type: "unique" | "index";
460
+ type: "unique" | "index" | "fulltext";
461
+ parser?: "built-in" | "ngram";
450
462
  };
451
463
  export type MigrationForeign = {
452
464
  columns: string[];
@@ -593,11 +605,6 @@ export namespace ApiParamType {
593
605
  export function isRefKnex(v: any): v is ApiParamType.Ref {
594
606
  return v?.t === "ref" && v.id === "Knex";
595
607
  }
596
- export function isRefKysely(v: any): v is ApiParamType.Ref {
597
- return (
598
- v?.t === "ref" && (v.id === "Kysely" || v.id.startsWith("Transaction"))
599
- );
600
- }
601
608
  export function isTypeParam(v: any): v is ApiParamType.TypeParam {
602
609
  return v?.t === "type-param";
603
610
  }
@@ -635,6 +642,7 @@ export type RenderingNode = {
635
642
  | "string-image"
636
643
  | "string-datetime"
637
644
  | "string-date"
645
+ | "datetime"
638
646
  | "number-plain"
639
647
  | "number-id"
640
648
  | "number-fk_id"
@@ -738,7 +746,6 @@ export const TemplateOptions = z.object({
738
746
  entityId: z.string(),
739
747
  enumId: z.string(),
740
748
  }),
741
- kysely_interface: z.object({}),
742
749
  });
743
750
  export type TemplateOptions = z.infer<typeof TemplateOptions>;
744
751
 
@@ -761,7 +768,6 @@ export const TemplateKey = z.enum([
761
768
  "view_enums_select",
762
769
  "view_enums_dropdown",
763
770
  "view_enums_buttonset",
764
- "kysely_interface",
765
771
  ]);
766
772
  export type TemplateKey = z.infer<typeof TemplateKey>;
767
773
 
@@ -812,3 +818,85 @@ export type RelationNode = {
812
818
  entityId: string;
813
819
  related: Set<string>;
814
820
  };
821
+
822
+ export interface DatabaseSchemaExtend {}
823
+ export type ManyToManyBaseSchema<
824
+ FromIdKey extends string,
825
+ ToIdKey extends string
826
+ > = {
827
+ id: number;
828
+ } & {
829
+ [K in `${FromIdKey}_id`]: number;
830
+ } & {
831
+ [K in `${ToIdKey}_id`]: number;
832
+ };
833
+
834
+ export type SonamuFastifyConfig = {
835
+ contextProvider: (
836
+ defaultContext: Pick<Context, "request" | "reply" | "headers">,
837
+ request: FastifyRequest,
838
+ reply: FastifyReply
839
+ ) => Context;
840
+ guardHandler: (
841
+ guard: GuardKey,
842
+ request: FastifyRequest,
843
+ api: {
844
+ typeParameters: ApiParamType.TypeParam[];
845
+ parameters: ApiParam[];
846
+ returnType: ApiParamType;
847
+ modelName: string;
848
+ methodName: string;
849
+ path: string;
850
+ options: ApiDecoratorOptions;
851
+ }
852
+ ) => void;
853
+ cache?: {
854
+ get: (key: string) => Promise<unknown | null>;
855
+ put: (key: string, value: unknown, ttl?: number) => Promise<void>;
856
+ resolveKey: (
857
+ path: string,
858
+ reqBody: {
859
+ [key: string]: unknown;
860
+ }
861
+ ) =>
862
+ | {
863
+ cache: false;
864
+ }
865
+ | {
866
+ cache: true;
867
+ key: string;
868
+ ttl?: number;
869
+ };
870
+ };
871
+ };
872
+
873
+ export type SonamuServerOptions = {
874
+ fastify?: FastifyServerOptions;
875
+
876
+ listen?: {
877
+ port: number;
878
+ host?: string;
879
+ };
880
+
881
+ plugins?: {
882
+ formbody?: boolean | FastifyFormbodyOptions;
883
+ qs?: boolean | QsPluginOptions;
884
+ cors?: boolean | FastifyCorsOptions;
885
+ multipart?: boolean | FastifyMultipartOptions;
886
+ custom?: (server: FastifyInstance) => void;
887
+ };
888
+
889
+ apiConfig: SonamuFastifyConfig;
890
+
891
+ storage?: Driver;
892
+
893
+ lifecycle?: {
894
+ onStart?: (server: FastifyInstance) => Promise<void> | void;
895
+ onShutdown?: (server: FastifyInstance) => Promise<void> | void;
896
+ onError?: (
897
+ error: Error,
898
+ request: FastifyRequest,
899
+ reply: FastifyReply
900
+ ) => Promise<void> | void;
901
+ };
902
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 비동기 조건으로 배열을 필터링합니다
3
+ * @example
4
+ * const filtered = await filterAsync([1, 2, 3], async (x) => x > 1);
5
+ */
6
+ export async function filterAsync<T>(
7
+ arr: T[],
8
+ predicate: (item: T, index: number, array: T[]) => Promise<boolean>
9
+ ): Promise<T[]> {
10
+ const results = await Promise.all(
11
+ arr.map((item, index) =>
12
+ predicate(item, index, arr).then((keep) => ({ item, keep }))
13
+ )
14
+ );
15
+ return results.filter((r) => r.keep).map((r) => r.item);
16
+ }
17
+
18
+ /**
19
+ * 비동기 조건이 모든 요소에 대해 참인지 확인합니다
20
+ * @example
21
+ * const allValid = await everyAsync([1, 2, 3], async (x) => x > 0);
22
+ */
23
+ export async function everyAsync<T>(
24
+ arr: T[],
25
+ predicate: (item: T, index: number, array: T[]) => Promise<boolean>
26
+ ): Promise<boolean> {
27
+ for (let i = 0; i < arr.length; i++) {
28
+ if (!(await predicate(arr[i], i, arr))) {
29
+ return false;
30
+ }
31
+ }
32
+ return true;
33
+ }
34
+
35
+ /**
36
+ * 비동기 변환 함수를 배열의 각 요소에 적용합니다
37
+ * @example
38
+ * const doubled = await mapAsync([1, 2, 3], async (x) => x * 2);
39
+ */
40
+ export async function mapAsync<T, U>(
41
+ arr: T[],
42
+ mapper: (item: T, index: number, array: T[]) => Promise<U>
43
+ ): Promise<U[]> {
44
+ return Promise.all(
45
+ arr.map((item, index) => mapper(item, index, arr))
46
+ );
47
+ }
48
+
49
+ /**
50
+ * 비동기 리듀서로 배열을 축약합니다
51
+ * @example
52
+ * const sum = await reduceAsync([1, 2, 3], async (acc, x) => acc + x, 0);
53
+ */
54
+ export async function reduceAsync<T, U>(
55
+ arr: T[],
56
+ reducer: (accumulator: U, currentValue: T, index: number, array: T[]) => Promise<U>,
57
+ initialValue: U
58
+ ): Promise<U> {
59
+ let accumulator = initialValue;
60
+ for (let i = 0; i < arr.length; i++) {
61
+ accumulator = await reducer(accumulator, arr[i], i, arr);
62
+ }
63
+ return accumulator;
64
+ }
@@ -0,0 +1,17 @@
1
+ import { PathLike, constants } from "fs";
2
+ import { access } from "fs/promises";
3
+
4
+ /**
5
+ * fs/promises에는 exists가 없어요. 대신 access가 있습니다.
6
+ * 근데 얘는 인터페이스가 쓰기 불편해요. 그래서 감싸주었습니다.
7
+ * @param path
8
+ * @returns
9
+ */
10
+ export async function exists(path: PathLike): Promise<boolean> {
11
+ try {
12
+ await access(path, constants.F_OK);
13
+ return true;
14
+ } catch {
15
+ return false;
16
+ }
17
+ }
@@ -1,5 +1,3 @@
1
- import _ from "lodash";
2
-
3
1
  export type ListResult<T> = {
4
2
  rows: T[];
5
3
  total?: number;
@@ -1,18 +1,13 @@
1
1
  import path from "path";
2
- import glob from "glob";
3
- import fs from "fs-extra";
4
- import _ from "lodash";
2
+ import { glob } from "fs/promises";
3
+ import fs from "fs";
5
4
 
6
- export function globAsync(pathPattern: string): Promise<string[]> {
7
- return new Promise((resolve, reject) => {
8
- glob(path.resolve(pathPattern), (err, files) => {
9
- if (err) {
10
- reject(err);
11
- } else {
12
- resolve(files);
13
- }
14
- });
15
- });
5
+ export async function globAsync(pathPattern: string): Promise<string[]> {
6
+ const files: string[] = [];
7
+ for await (const file of glob(path.resolve(pathPattern))) {
8
+ files.push(file);
9
+ }
10
+ return files;
16
11
  }
17
12
  export async function importMultiple(
18
13
  filePaths: string[],
@@ -46,6 +41,12 @@ export async function findAppRootPath() {
46
41
  }
47
42
 
48
43
  export function findApiRootPath() {
44
+ // NOTE: for support npm / yarn workspaces
45
+ const workspacePath = process.env["INIT_CWD"];
46
+ if (workspacePath && workspacePath.length !== 0) {
47
+ return workspacePath;
48
+ }
49
+
49
50
  const basePath = require.main?.path ?? __dirname;
50
51
  let dir = path.dirname(basePath);
51
52
  if (dir.includes("/.yarn/")) {
@@ -63,48 +64,3 @@ export function findApiRootPath() {
63
64
  export function nonNullable<T>(value: T): value is NonNullable<T> {
64
65
  return value !== null && value !== undefined;
65
66
  }
66
-
67
- export function hydrate<T>(rows: T[]): T[] {
68
- return rows.map((row: any) => {
69
- // nullable relation인 경우 관련된 필드가 전부 null로 생성되는 것 방지하는 코드
70
- const nestedKeys = Object.keys(row).filter((key) => key.includes("__"));
71
- const groups = _.groupBy(nestedKeys, (key) => key.split("__")[0]);
72
- const nullKeys = Object.keys(groups).filter(
73
- (key) =>
74
- groups[key].length > 1 &&
75
- groups[key].every((field) => row[field] === null)
76
- );
77
-
78
- const hydrated = Object.keys(row).reduce((r, field) => {
79
- if (!field.includes("__")) {
80
- if (Array.isArray(row[field]) && _.isObject(row[field][0])) {
81
- r[field] = hydrate(row[field]);
82
- return r;
83
- } else {
84
- r[field] = row[field];
85
- return r;
86
- }
87
- }
88
-
89
- const parts = field.split("__");
90
- const objPath =
91
- parts[0] +
92
- parts
93
- .slice(1)
94
- .map((part) => `[${part}]`)
95
- .join("");
96
- _.set(
97
- r,
98
- objPath,
99
- row[field] && Array.isArray(row[field]) && _.isObject(row[field][0])
100
- ? hydrate(row[field])
101
- : row[field]
102
- );
103
-
104
- return r;
105
- }, {} as any);
106
- nullKeys.map((nullKey) => (hydrated[nullKey] = null));
107
-
108
- return hydrated;
109
- });
110
- }
@@ -1,4 +1,5 @@
1
- import { z } from "zod";
1
+
2
+ import { z } from 'zod';
2
3
 
3
4
  type ValidationError = {
4
5
  path: string[];
@@ -6,184 +7,19 @@ type ValidationError = {
6
7
  };
7
8
 
8
9
  export function humanizeZodError(error: z.ZodError): ValidationError[] {
9
- return error.issues.map((issue) => {
10
- const pathAsStrings = issue.path.map(String);
11
- const path = issue.path.reduce((acc, cur, i) => {
12
- if (typeof cur === "number") {
13
- return `${acc}[${cur}]`;
10
+ return error.issues.map(({ path: originPath, message }) => {
11
+ const path = originPath.map(item => {
12
+ if (typeof item === "symbol") {
13
+ return item.description ?? item.toString();
14
14
  }
15
- return i === 0 ? cur : `${acc}.${cur}`;
16
- }, "");
17
-
18
- switch (issue.code) {
19
- case z.ZodIssueCode.invalid_type:
20
- return {
21
- path: pathAsStrings,
22
- message: `${path} should be a ${issue.expected}, received ${issue.received}.`,
23
- };
24
-
25
- case z.ZodIssueCode.unrecognized_keys:
26
- return {
27
- path: pathAsStrings,
28
- message: `Unrecognized keys in ${path}: ${issue.keys.join(", ")}.`,
29
- };
30
-
31
- case z.ZodIssueCode.invalid_union:
32
- return {
33
- path: pathAsStrings,
34
- message: `${path} failed union validation. Inner errors: ${issue.unionErrors
35
- .map((e) => e.issues.map((i) => i.message).join("; "))
36
- .join(" OR ")}.`,
37
- };
38
-
39
- case z.ZodIssueCode.invalid_enum_value:
40
- return {
41
- path: pathAsStrings,
42
- message: `${path} must be one of: ${issue.options.join(", ")}.`,
43
- };
44
-
45
- case z.ZodIssueCode.invalid_arguments:
46
- return {
47
- path: pathAsStrings,
48
- message: `Invalid function arguments: ${issue.argumentsError.issues
49
- .map((i) => i.message)
50
- .join("; ")}.`,
51
- };
52
-
53
- case z.ZodIssueCode.invalid_return_type:
54
- return {
55
- path: pathAsStrings,
56
- message: `Invalid function return type: ${issue.returnTypeError.issues
57
- .map((i) => i.message)
58
- .join("; ")}.`,
59
- };
60
15
 
61
- case z.ZodIssueCode.invalid_date:
62
- return {
63
- path: pathAsStrings,
64
- message: `${path} must be a valid date.`,
65
- };
66
-
67
- case z.ZodIssueCode.invalid_string:
68
- const validationType = issue.validation;
69
- return {
70
- path: pathAsStrings,
71
- message: `${path} must be a valid ${validationType}.`,
72
- };
73
-
74
- case z.ZodIssueCode.too_small:
75
- return {
76
- path: pathAsStrings,
77
- message: `${path} ${getMinimumMessage(issue)}.`,
78
- };
79
-
80
- case z.ZodIssueCode.too_big:
81
- return {
82
- path: pathAsStrings,
83
- message: `${path} ${getMaximumMessage(issue)}`,
84
- };
85
-
86
- case z.ZodIssueCode.not_multiple_of:
87
- return {
88
- path: pathAsStrings,
89
- message: `${path} must be a multiple of ${issue.multipleOf.toString()}.`,
90
- };
16
+ if (typeof item === "number") {
17
+ return `[${item}]`;
18
+ }
91
19
 
92
- case z.ZodIssueCode.custom:
93
- return {
94
- path: pathAsStrings,
95
- message: issue.message || `${path} failed custom validation.`,
96
- };
20
+ return item;
21
+ });
97
22
 
98
- default:
99
- return {
100
- path: pathAsStrings,
101
- message: issue.message,
102
- };
103
- }
23
+ return { path, message: message };
104
24
  });
105
25
  }
106
-
107
- function getMinimumMessage(
108
- issue: z.ZodIssue & { code: typeof z.ZodIssueCode.too_small }
109
- ) {
110
- switch (issue.type) {
111
- case "string":
112
- return `must be ${
113
- issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"
114
- } ${issue.minimum} character${issue.minimum === 1 ? "" : "s"}`;
115
-
116
- case "number":
117
- return `must be ${
118
- issue.exact
119
- ? "exactly"
120
- : issue.inclusive
121
- ? "greater than or equal to"
122
- : "greater than"
123
- } ${issue.minimum.toString()}`;
124
-
125
- case "array":
126
- case "set":
127
- return `must contain ${
128
- issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"
129
- } ${issue.minimum} item${issue.minimum === 1 ? "" : "s"}`;
130
-
131
- case "date":
132
- return `must be ${
133
- issue.exact ? "exactly" : issue.inclusive ? "at or after" : "after"
134
- } ${formatDateConstraint(issue.minimum)}`;
135
-
136
- default:
137
- return "is too small";
138
- }
139
- }
140
-
141
- function getMaximumMessage(
142
- issue: z.ZodIssue & { code: typeof z.ZodIssueCode.too_big }
143
- ) {
144
- switch (issue.type) {
145
- case "string":
146
- return `must be ${
147
- issue.exact ? "exactly" : issue.inclusive ? "at most" : "less than"
148
- } ${issue.maximum} character${issue.maximum === 1 ? "" : "s"}`;
149
-
150
- case "number":
151
- return `must be ${
152
- issue.exact
153
- ? "exactly"
154
- : issue.inclusive
155
- ? "less than or equal to"
156
- : "less than"
157
- } ${issue.maximum.toString()}`;
158
-
159
- case "array":
160
- case "set":
161
- return `must contain ${
162
- issue.exact ? "exactly" : issue.inclusive ? "at most" : "fewer than"
163
- } ${issue.maximum} item${issue.maximum === 1 ? "" : "s"}`;
164
-
165
- case "date":
166
- return `must be ${
167
- issue.exact ? "exactly" : issue.inclusive ? "at or before" : "before"
168
- } ${formatDateConstraint(issue.maximum)}`;
169
-
170
- default:
171
- return "is too big";
172
- }
173
- }
174
-
175
- function formatDateConstraint(value: number | bigint): string {
176
- try {
177
- if (typeof value === "bigint") {
178
- if (
179
- value > BigInt(Number.MAX_SAFE_INTEGER) ||
180
- value < BigInt(Number.MIN_SAFE_INTEGER)
181
- ) {
182
- return value.toString();
183
- }
184
- }
185
- return new Date(Number(value)).toISOString();
186
- } catch {
187
- return value.toString();
188
- }
189
- }
package/tsconfig.json CHANGED
@@ -24,6 +24,8 @@
24
24
  "noUnusedParameters": true,
25
25
  "noImplicitReturns": true,
26
26
  "noFallthroughCasesInSwitch": true,
27
+ "skipLibCheck": true,
28
+ // "noUncheckedIndexedAccess": true, // FIXME
27
29
 
28
30
  /* Module Resolution Options */
29
31
  "moduleResolution": "node",
package/tsup.config.js CHANGED
@@ -11,7 +11,10 @@ export default defineConfig({
11
11
  "src/database/drivers/kysely/base-model.ts",
12
12
  ],
13
13
  dts: true,
14
- format: ["cjs", "esm"],
14
+ format: [
15
+ "cjs",
16
+ // "esm"
17
+ ],
15
18
  target: "esnext",
16
19
  clean: true,
17
20
  sourcemap: true,
@@ -24,7 +27,6 @@ export default defineConfig({
24
27
  "dotenv",
25
28
  "fast-deep-equal",
26
29
  "fastify",
27
- "fs-extra",
28
30
  "glob",
29
31
  "inflection",
30
32
  "knex",