sonamu 0.4.14 → 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 (348) 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/database/_batch_update.d.ts +15 -0
  47. package/dist/database/_batch_update.d.ts.map +1 -0
  48. package/dist/database/_batch_update.js +2 -0
  49. package/dist/database/_batch_update.js.map +1 -0
  50. package/dist/database/base-model.d.ts +41 -0
  51. package/dist/database/base-model.d.ts.map +1 -0
  52. package/dist/database/base-model.js +2 -0
  53. package/dist/database/base-model.js.map +1 -0
  54. package/dist/database/code-generator.d.ts +13 -0
  55. package/dist/database/code-generator.d.ts.map +1 -0
  56. package/dist/database/code-generator.js +2 -0
  57. package/dist/database/code-generator.js.map +1 -0
  58. package/dist/database/db.d.ts +40 -0
  59. package/dist/database/db.d.ts.map +1 -0
  60. package/dist/database/db.js +2 -0
  61. package/dist/database/db.js.map +1 -0
  62. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  63. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  64. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  65. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  66. package/dist/database/puri-wrapper.d.ts +34 -0
  67. package/dist/database/puri-wrapper.d.ts.map +1 -0
  68. package/dist/database/puri-wrapper.js +2 -0
  69. package/dist/database/puri-wrapper.js.map +1 -0
  70. package/dist/database/puri.d.ts +83 -0
  71. package/dist/database/puri.d.ts.map +1 -0
  72. package/dist/database/puri.js +2 -0
  73. package/dist/database/puri.js.map +1 -0
  74. package/dist/database/puri.types.d.ts +60 -0
  75. package/dist/database/puri.types.d.ts.map +1 -0
  76. package/dist/database/puri.types.js +2 -0
  77. package/dist/database/puri.types.js.map +1 -0
  78. package/dist/database/transaction-context.d.ts +9 -0
  79. package/dist/database/transaction-context.d.ts.map +1 -0
  80. package/dist/database/transaction-context.js +2 -0
  81. package/dist/database/transaction-context.js.map +1 -0
  82. package/dist/database/types.d.ts +39 -0
  83. package/dist/database/types.d.ts.map +1 -0
  84. package/dist/database/types.js +2 -0
  85. package/dist/database/types.js.map +1 -0
  86. package/dist/database/upsert-builder.d.ts +34 -0
  87. package/dist/database/upsert-builder.d.ts.map +1 -0
  88. package/dist/database/upsert-builder.js +2 -0
  89. package/dist/database/upsert-builder.js.map +1 -0
  90. package/dist/entity/entity-manager.d.ts +32 -0
  91. package/dist/entity/entity-manager.d.ts.map +1 -0
  92. package/dist/entity/entity-manager.js +2 -0
  93. package/dist/entity/entity-manager.js.map +1 -0
  94. package/dist/entity/entity-utils.d.ts +61 -0
  95. package/dist/entity/entity-utils.d.ts.map +1 -0
  96. package/dist/entity/entity-utils.js +2 -0
  97. package/dist/entity/entity-utils.js.map +1 -0
  98. package/dist/entity/entity.d.ts +62 -0
  99. package/dist/entity/entity.d.ts.map +1 -0
  100. package/dist/entity/entity.js +2 -0
  101. package/dist/entity/entity.js.map +1 -0
  102. package/dist/entity/migrator.d.ts +135 -0
  103. package/dist/entity/migrator.d.ts.map +1 -0
  104. package/dist/entity/migrator.js +2 -0
  105. package/dist/entity/migrator.js.map +1 -0
  106. package/dist/exceptions/error-handler.d.ts +3 -0
  107. package/dist/exceptions/error-handler.d.ts.map +1 -0
  108. package/dist/exceptions/error-handler.js +2 -0
  109. package/dist/exceptions/error-handler.js.map +1 -0
  110. package/dist/exceptions/so-exceptions.d.ts +48 -0
  111. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  112. package/dist/exceptions/so-exceptions.js +2 -0
  113. package/dist/exceptions/so-exceptions.js.map +1 -0
  114. package/dist/file-storage/driver.d.ts +45 -0
  115. package/dist/file-storage/driver.d.ts.map +1 -0
  116. package/dist/file-storage/driver.js +2 -0
  117. package/dist/file-storage/driver.js.map +1 -0
  118. package/dist/file-storage/file-storage.d.ts +50 -0
  119. package/dist/file-storage/file-storage.d.ts.map +1 -0
  120. package/dist/file-storage/file-storage.js +2 -0
  121. package/dist/file-storage/file-storage.js.map +1 -0
  122. package/dist/index.d.ts +22 -813
  123. package/dist/index.d.ts.map +1 -0
  124. package/dist/index.js +1 -433
  125. package/dist/index.js.map +1 -1
  126. package/dist/migration/code-generation.d.ts +15 -0
  127. package/dist/migration/code-generation.d.ts.map +1 -0
  128. package/dist/migration/code-generation.js +2 -0
  129. package/dist/migration/code-generation.js.map +1 -0
  130. package/dist/migration/migration-set.d.ts +17 -0
  131. package/dist/migration/migration-set.d.ts.map +1 -0
  132. package/dist/migration/migration-set.js +2 -0
  133. package/dist/migration/migration-set.js.map +1 -0
  134. package/dist/migration/migrator.d.ts +130 -0
  135. package/dist/migration/migrator.d.ts.map +1 -0
  136. package/dist/migration/migrator.js +2 -0
  137. package/dist/migration/migrator.js.map +1 -0
  138. package/dist/migration/types.d.ts +52 -0
  139. package/dist/migration/types.d.ts.map +1 -0
  140. package/dist/migration/types.js +2 -0
  141. package/dist/migration/types.js.map +1 -0
  142. package/dist/smd/smd-manager.d.ts +28 -0
  143. package/dist/smd/smd-manager.d.ts.map +1 -0
  144. package/dist/smd/smd-manager.js +2 -0
  145. package/dist/smd/smd-manager.js.map +1 -0
  146. package/dist/smd/smd.d.ts +40 -0
  147. package/dist/smd/smd.d.ts.map +1 -0
  148. package/dist/smd/smd.js +2 -0
  149. package/dist/smd/smd.js.map +1 -0
  150. package/dist/syncer/index.d.ts +2 -0
  151. package/dist/syncer/index.d.ts.map +1 -0
  152. package/dist/syncer/index.js +2 -0
  153. package/dist/syncer/index.js.map +1 -0
  154. package/dist/syncer/syncer.d.ts +127 -0
  155. package/dist/syncer/syncer.d.ts.map +1 -0
  156. package/dist/syncer/syncer.js +2 -0
  157. package/dist/syncer/syncer.js.map +1 -0
  158. package/dist/templates/base-template.d.ts +13 -0
  159. package/dist/templates/base-template.d.ts.map +1 -0
  160. package/dist/templates/base-template.js +2 -0
  161. package/dist/templates/base-template.js.map +1 -0
  162. package/dist/templates/entity.template.d.ts +17 -0
  163. package/dist/templates/entity.template.d.ts.map +1 -0
  164. package/dist/templates/entity.template.js +2 -0
  165. package/dist/templates/entity.template.js.map +1 -0
  166. package/dist/templates/generated.template.d.ts +27 -0
  167. package/dist/templates/generated.template.d.ts.map +1 -0
  168. package/dist/templates/generated.template.js +2 -0
  169. package/dist/templates/generated.template.js.map +1 -0
  170. package/dist/templates/generated_http.template.d.ts +24 -0
  171. package/dist/templates/generated_http.template.d.ts.map +1 -0
  172. package/dist/templates/generated_http.template.js +2 -0
  173. package/dist/templates/generated_http.template.js.map +1 -0
  174. package/dist/templates/generated_sso.template.d.ts +20 -0
  175. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  176. package/dist/templates/generated_sso.template.js +2 -0
  177. package/dist/templates/generated_sso.template.js.map +1 -0
  178. package/dist/templates/index.d.ts +2 -0
  179. package/dist/templates/index.d.ts.map +1 -0
  180. package/dist/templates/index.js +2 -0
  181. package/dist/templates/index.js.map +1 -0
  182. package/dist/templates/init_types.template.d.ts +17 -0
  183. package/dist/templates/init_types.template.d.ts.map +1 -0
  184. package/dist/templates/init_types.template.js +2 -0
  185. package/dist/templates/init_types.template.js.map +1 -0
  186. package/dist/templates/model.template.d.ts +17 -0
  187. package/dist/templates/model.template.d.ts.map +1 -0
  188. package/dist/templates/model.template.js +2 -0
  189. package/dist/templates/model.template.js.map +1 -0
  190. package/dist/templates/model_test.template.d.ts +17 -0
  191. package/dist/templates/model_test.template.d.ts.map +1 -0
  192. package/dist/templates/model_test.template.js +2 -0
  193. package/dist/templates/model_test.template.js.map +1 -0
  194. package/dist/templates/service.template.d.ts +29 -0
  195. package/dist/templates/service.template.d.ts.map +1 -0
  196. package/dist/templates/service.template.js +2 -0
  197. package/dist/templates/service.template.js.map +1 -0
  198. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  199. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  200. package/dist/templates/view_enums_buttonset.template.js +2 -0
  201. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  202. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  203. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  204. package/dist/templates/view_enums_dropdown.template.js +2 -0
  205. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  206. package/dist/templates/view_enums_select.template.d.ts +17 -0
  207. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  208. package/dist/templates/view_enums_select.template.js +2 -0
  209. package/dist/templates/view_enums_select.template.js.map +1 -0
  210. package/dist/templates/view_form.template.d.ts +26 -0
  211. package/dist/templates/view_form.template.d.ts.map +1 -0
  212. package/dist/templates/view_form.template.js +2 -0
  213. package/dist/templates/view_form.template.js.map +1 -0
  214. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  215. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  216. package/dist/templates/view_id_all_select.template.js +2 -0
  217. package/dist/templates/view_id_all_select.template.js.map +1 -0
  218. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  219. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  220. package/dist/templates/view_id_async_select.template.js +2 -0
  221. package/dist/templates/view_id_async_select.template.js.map +1 -0
  222. package/dist/templates/view_list.template.d.ts +38 -0
  223. package/dist/templates/view_list.template.d.ts.map +1 -0
  224. package/dist/templates/view_list.template.js +2 -0
  225. package/dist/templates/view_list.template.js.map +1 -0
  226. package/dist/templates/view_list_columns.template.d.ts +17 -0
  227. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  228. package/dist/templates/view_list_columns.template.js +2 -0
  229. package/dist/templates/view_list_columns.template.js.map +1 -0
  230. package/dist/templates/view_search_input.template.d.ts +17 -0
  231. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  232. package/dist/templates/view_search_input.template.js +2 -0
  233. package/dist/templates/view_search_input.template.js.map +1 -0
  234. package/dist/testing/_relation-graph.d.ts +7 -0
  235. package/dist/testing/_relation-graph.d.ts.map +1 -0
  236. package/dist/testing/_relation-graph.js +2 -0
  237. package/dist/testing/_relation-graph.js.map +1 -0
  238. package/dist/testing/fixture-manager.d.ts +35 -0
  239. package/dist/testing/fixture-manager.d.ts.map +1 -0
  240. package/dist/testing/fixture-manager.js +2 -0
  241. package/dist/testing/fixture-manager.js.map +1 -0
  242. package/dist/types/types.d.ts +609 -0
  243. package/dist/types/types.d.ts.map +1 -0
  244. package/dist/types/types.js +2 -0
  245. package/dist/types/types.js.map +1 -0
  246. package/dist/typings/knex.d.js +2 -0
  247. package/dist/typings/knex.d.js.map +1 -0
  248. package/dist/utils/async-utils.d.ts +25 -0
  249. package/dist/utils/async-utils.d.ts.map +1 -0
  250. package/dist/utils/async-utils.js +2 -0
  251. package/dist/utils/async-utils.js.map +1 -0
  252. package/dist/utils/controller.d.ts +9 -0
  253. package/dist/utils/controller.d.ts.map +1 -0
  254. package/dist/utils/controller.js +2 -0
  255. package/dist/utils/controller.js.map +1 -0
  256. package/dist/utils/fs-utils.d.ts +9 -0
  257. package/dist/utils/fs-utils.d.ts.map +1 -0
  258. package/dist/utils/fs-utils.js +2 -0
  259. package/dist/utils/fs-utils.js.map +1 -0
  260. package/dist/utils/lodash-able.d.ts +2 -0
  261. package/dist/utils/lodash-able.d.ts.map +1 -0
  262. package/dist/utils/lodash-able.js +2 -0
  263. package/dist/utils/lodash-able.js.map +1 -0
  264. package/dist/utils/model.d.ts +17 -0
  265. package/dist/utils/model.d.ts.map +1 -0
  266. package/dist/utils/model.js +2 -0
  267. package/dist/utils/model.js.map +1 -0
  268. package/dist/utils/sql-parser.d.ts +4 -0
  269. package/dist/utils/sql-parser.d.ts.map +1 -0
  270. package/dist/utils/sql-parser.js +2 -0
  271. package/dist/utils/sql-parser.js.map +1 -0
  272. package/dist/utils/utils.d.ts +9 -0
  273. package/dist/utils/utils.d.ts.map +1 -0
  274. package/dist/utils/utils.js +2 -0
  275. package/dist/utils/utils.js.map +1 -0
  276. package/dist/utils/zod-error.d.ts +8 -0
  277. package/dist/utils/zod-error.d.ts.map +1 -0
  278. package/dist/utils/zod-error.js +2 -0
  279. package/dist/utils/zod-error.js.map +1 -0
  280. package/nodemon.json +6 -0
  281. package/package.json +29 -44
  282. package/src/api/base-frame.ts +3 -4
  283. package/src/api/caster.ts +22 -23
  284. package/src/api/code-converters.ts +170 -134
  285. package/src/api/context.ts +13 -6
  286. package/src/api/decorators.ts +146 -20
  287. package/src/api/index.ts +2 -0
  288. package/src/api/sonamu.ts +374 -165
  289. package/src/bin/build-config.ts +5 -0
  290. package/src/bin/cli-wrapper.ts +29 -40
  291. package/src/bin/cli.ts +132 -190
  292. package/src/database/_batch_update.ts +10 -15
  293. package/src/database/base-model.ts +300 -216
  294. package/src/database/db.ts +191 -21
  295. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  296. package/src/database/puri-wrapper.ts +129 -0
  297. package/src/database/puri.ts +808 -0
  298. package/src/database/puri.types.ts +222 -0
  299. package/src/database/transaction-context.ts +18 -0
  300. package/src/database/upsert-builder.ts +32 -35
  301. package/src/entity/entity-manager.ts +7 -15
  302. package/src/entity/entity.ts +9 -31
  303. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  304. package/src/file-storage/driver.ts +121 -0
  305. package/src/file-storage/file-storage.ts +100 -0
  306. package/src/index.ts +14 -11
  307. package/src/migration/code-generation.ts +777 -0
  308. package/src/migration/migration-set.ts +453 -0
  309. package/src/migration/migrator.ts +823 -0
  310. package/src/migration/types.ts +53 -0
  311. package/src/shared/web.shared.ts.txt +33 -2
  312. package/src/syncer/syncer.ts +294 -127
  313. package/src/templates/generated.template.ts +13 -1
  314. package/src/templates/generated_http.template.ts +15 -12
  315. package/src/templates/generated_sso.template.ts +50 -2
  316. package/src/templates/model.template.ts +138 -2
  317. package/src/templates/service.template.ts +0 -1
  318. package/src/templates/view_form.template.ts +11 -7
  319. package/src/templates/view_list.template.ts +12 -4
  320. package/src/testing/fixture-manager.ts +229 -174
  321. package/src/types/types.ts +102 -14
  322. package/src/utils/async-utils.ts +64 -0
  323. package/src/utils/fs-utils.ts +17 -0
  324. package/src/utils/model.ts +0 -2
  325. package/src/utils/utils.ts +14 -58
  326. package/src/utils/zod-error.ts +12 -176
  327. package/tsconfig.json +2 -0
  328. package/tsup.config.js +4 -2
  329. package/.pnp.cjs +0 -14363
  330. package/.pnp.loader.mjs +0 -2047
  331. package/.vscode/extensions.json +0 -6
  332. package/.vscode/settings.json +0 -9
  333. package/.yarnrc.yml +0 -5
  334. package/src/database/base-model.abstract.ts +0 -97
  335. package/src/database/db.abstract.ts +0 -75
  336. package/src/database/drivers/knex/base-model.ts +0 -55
  337. package/src/database/drivers/knex/client.ts +0 -209
  338. package/src/database/drivers/knex/db.ts +0 -232
  339. package/src/database/drivers/knex/generator.ts +0 -659
  340. package/src/database/drivers/kysely/base-model.ts +0 -89
  341. package/src/database/drivers/kysely/client.ts +0 -309
  342. package/src/database/drivers/kysely/db.ts +0 -238
  343. package/src/database/drivers/kysely/generator.ts +0 -714
  344. package/src/database/types.ts +0 -118
  345. package/src/entity/migrator.ts +0 -1400
  346. package/src/smd/smd-manager.ts +0 -139
  347. package/src/smd/smd.ts +0 -571
  348. package/src/templates/kysely_types.template.ts +0 -205
@@ -1,7 +1,10 @@
1
- import { z, ZodRecord } from "zod";
1
+ import { z } from "zod";
2
2
  import {
3
3
  ApiParam,
4
4
  ApiParamType,
5
+ EntityProp,
6
+ EntityPropNode,
7
+ TextProp,
5
8
  isBelongsToOneRelationProp,
6
9
  isBigIntegerProp,
7
10
  isBooleanProp,
@@ -21,9 +24,6 @@ import {
21
24
  isTimestampProp,
22
25
  isUuidProp,
23
26
  isVirtualProp,
24
- EntityProp,
25
- EntityPropNode,
26
- TextProp,
27
27
  } from "../types/types";
28
28
  import { ExtendedApi } from "./decorators";
29
29
 
@@ -53,7 +53,6 @@ export function getZodObjectFromApi(
53
53
  (param) =>
54
54
  !ApiParamType.isContext(param.type) &&
55
55
  !ApiParamType.isRefKnex(param.type) &&
56
- !ApiParamType.isRefKysely(param.type) &&
57
56
  !(param.optional === true && param.name.startsWith("_")) // _로 시작하는 파라미터는 제외
58
57
  ),
59
58
  references
@@ -69,7 +68,7 @@ export function getZodObjectFromApiParams(
69
68
  references: {
70
69
  [id: string]: z.ZodObject<any>;
71
70
  } = {}
72
- ): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}> {
71
+ ): z.ZodObject {
73
72
  return z.object(
74
73
  apiParams.reduce((r, param) => {
75
74
  let zodType = getZodTypeFromApiParamType(param.type, references);
@@ -124,6 +123,11 @@ export function getZodTypeFromApiParamType(
124
123
  args?: ApiParamType[];
125
124
  };
126
125
 
126
+ // Date 타입 처리
127
+ if (refType.id === "Date") {
128
+ return z.date();
129
+ }
130
+
127
131
  // 객체 키 관리 유틸리티
128
132
  if (["Pick", "Omit"].includes(refType.id)) {
129
133
  if (refType.args?.length !== 2) {
@@ -134,11 +138,11 @@ export function getZodTypeFromApiParamType(
134
138
  ) as [z.ZodObject<any>, z.ZodUnion<any> | z.ZodLiteral<string>];
135
139
  let keys: string[] = [];
136
140
  if (literalOrUnion instanceof z.ZodUnion) {
137
- keys = literalOrUnion._def.options.map(
138
- (option: { _def: { value: string } }) => option._def.value
141
+ keys = literalOrUnion.def.options.map(
142
+ (option: { def: { value: string } }) => option.def.value
139
143
  );
140
144
  } else {
141
- keys = [(literalOrUnion as z.ZodLiteral<string>)._def.value];
145
+ keys = (literalOrUnion as z.ZodLiteral<string>).def.values;
142
146
  }
143
147
  const keyRecord = keys.reduce((result, key) => {
144
148
  return {
@@ -277,7 +281,7 @@ export function propToZodTypeDef(
277
281
  ): string {
278
282
  let stmt: string;
279
283
  if (isIntegerProp(prop)) {
280
- stmt = `${prop.name}: z.number().int()`;
284
+ stmt = `${prop.name}: z.int()`;
281
285
  } else if (isBigIntegerProp(prop)) {
282
286
  stmt = `${prop.name}: z.bigint()`;
283
287
  } else if (isTextProp(prop)) {
@@ -298,14 +302,14 @@ export function propToZodTypeDef(
298
302
  } else if (isTimeProp(prop)) {
299
303
  stmt = `${prop.name}: z.string().length(8)`;
300
304
  } else if (isDateTimeProp(prop)) {
301
- stmt = `${prop.name}: SQLDateTimeString`;
305
+ stmt = `${prop.name}: z.date()`;
302
306
  } else if (isTimestampProp(prop)) {
303
- stmt = `${prop.name}: SQLDateTimeString`;
307
+ stmt = `${prop.name}: z.date()`;
304
308
  } else if (isJsonProp(prop)) {
305
309
  stmt = `${prop.name}: ${prop.id}`;
306
310
  injectImportKeys.push(prop.id);
307
311
  } else if (isUuidProp(prop)) {
308
- stmt = `${prop.name}: z.string().uuid()`;
312
+ stmt = `${prop.name}: z.uuid()`;
309
313
  } else if (isVirtualProp(prop)) {
310
314
  stmt = `${prop.name}: ${prop.id}`;
311
315
  injectImportKeys.push(prop.id);
@@ -314,7 +318,7 @@ export function propToZodTypeDef(
314
318
  isBelongsToOneRelationProp(prop) ||
315
319
  (isOneToOneRelationProp(prop) && prop.hasJoinColumn)
316
320
  ) {
317
- stmt = `${prop.name}_id: z.number().int()`;
321
+ stmt = `${prop.name}_id: z.int()`;
318
322
  } else {
319
323
  // 그외 relation 케이스 제외
320
324
  return `// ${prop.name}: ${prop.relationType} ${prop.with}`;
@@ -333,58 +337,76 @@ export function propToZodTypeDef(
333
337
  return stmt + ",";
334
338
  }
335
339
 
336
- export function zodTypeToZodCode(
337
- zt: z.ZodFirstPartySchemaTypes | z.ZodObject<any>
338
- ): string {
339
- switch (zt._def.typeName) {
340
- case "ZodString":
340
+ // TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
341
+ export function zodTypeToZodCode(zt: z.ZodType<any>): string {
342
+ switch (zt.def.type) {
343
+ case "string":
341
344
  return "z.string()";
342
- case "ZodNumber":
345
+ case "number":
343
346
  return "z.number()";
344
- case "ZodBoolean":
345
- return "z.boolean()";
346
- case "ZodBigInt":
347
+ case "bigint":
347
348
  return "z.bigint()";
348
- case "ZodDate":
349
+ case "boolean":
350
+ return "z.boolean()";
351
+ case "date":
349
352
  return "z.date()";
350
- case "ZodNull":
353
+ case "null":
351
354
  return "z.null()";
352
- case "ZodUndefined":
355
+ case "undefined":
353
356
  return "z.undefined()";
354
- case "ZodAny":
357
+ case "any":
355
358
  return "z.any()";
356
- case "ZodUnknown":
359
+ case "unknown":
357
360
  return "z.unknown()";
358
- case "ZodNever":
361
+ case "never":
359
362
  return "z.never()";
360
- case "ZodNullable":
361
- return zodTypeToZodCode(zt._def.innerType) + ".nullable()";
362
- case "ZodDefault":
363
+ case "nullable":
364
+ return zodTypeToZodCode((zt as z.ZodNullable<any>).def.innerType) + ".nullable()";
365
+ case "default":
366
+ const zDefaultDef = (zt as z.ZodDefault<any>).def;
363
367
  return (
364
- zodTypeToZodCode(zt._def.innerType) +
365
- `.default(${zt._def.defaultValue()})`
368
+ zodTypeToZodCode(zDefaultDef.innerType) +
369
+ `.default(${zDefaultDef.defaultValue()})`
366
370
  );
367
- case "ZodRecord":
368
- return `z.record(${zodTypeToZodCode(zt._def.keyType)}, ${zodTypeToZodCode(
369
- zt._def.valueType
371
+ case "record":
372
+ const zRecordDef = (zt as z.ZodRecord<any, any>).def;
373
+ return `z.record(${zodTypeToZodCode(zRecordDef.keyType)}, ${zodTypeToZodCode(
374
+ zRecordDef.valueType
370
375
  )})`;
371
- case "ZodLiteral":
372
- if (typeof zt._def.value === "string") {
373
- return `z.literal("${zt._def.value}")`;
374
- } else {
375
- return `z.literal(${zt._def.value})`;
376
+ case "literal":
377
+ const items = Array.from((zt as z.ZodLiteral<any>).values).map(value => {
378
+ if (typeof value === "string") {
379
+ return `"${value}"`;
380
+ }
381
+
382
+ if (value === null) {
383
+ return `null`;
384
+ }
385
+
386
+ if (value === undefined) {
387
+ return `undefined`;
388
+ }
389
+
390
+ return `${value}`;
391
+ });
392
+
393
+ if (items.length === 1) {
394
+ return `z.literal(${items[0]})`;
376
395
  }
377
- case "ZodUnion":
378
- return `z.union([${zt._def.options
379
- .map((option: z.ZodTypeAny) => zodTypeToZodCode(option))
396
+ return `z.literal([${items.join(", ")}])`;
397
+ case "union":
398
+ return `z.union([${(zt as z.ZodUnion<any>).def.options
399
+ .map((option: z.ZodType<any>) => zodTypeToZodCode(option))
380
400
  .join(",")}])`;
381
- case "ZodEnum":
382
- return `z.enum([${zt._def.values
383
- .map((val: string) => `"${val}"`)
384
- .join(", ")}])`;
385
- case "ZodArray":
386
- return `z.array(${zodTypeToZodCode(zt._def.type)})`;
387
- case "ZodObject":
401
+ case "enum":
402
+ // NOTE: z.enum(["A", "B"])도 z.enum({ A: "A", B: "B" })로 처리됨.
403
+ return `z.enum([${Object.entries((zt as z.ZodEnum).def.entries)
404
+ .map(([key, val]) =>
405
+ typeof val === "string" ? `${key}: "${val}"` : `${key}: ${val}`)
406
+ .join(", ")}})`;
407
+ case "array":
408
+ return `z.array(${zodTypeToZodCode((zt as z.ZodArray<z.ZodType>).def.element)})`;
409
+ case "object":
388
410
  const shape = (zt as any).shape;
389
411
  return [
390
412
  "z.object({",
@@ -393,10 +415,17 @@ export function zodTypeToZodCode(
393
415
  ),
394
416
  "})",
395
417
  ].join("\n");
396
- case "ZodOptional":
397
- return zodTypeToZodCode(zt._def.innerType) + ".optional()";
418
+ case "optional":
419
+ return zodTypeToZodCode((zt as z.ZodOptional<z.ZodType>).def.innerType) + ".optional()";
420
+ case "file":
421
+ return `z.file()`;
422
+ case "intersection":
423
+ const zIntersectionDef = (zt as z.ZodIntersection<z.ZodType, z.ZodType>).def;
424
+ return `z.intersection(${zodTypeToZodCode(zIntersectionDef.left)}, ${zodTypeToZodCode(zIntersectionDef.right)})`;
425
+ case "file":
426
+ return `z.file()`;
398
427
  default:
399
- throw new Error(`처리되지 않은 ZodType ${zt._def.typeName}`);
428
+ throw new Error(`처리되지 않은 ZodType ${zt.def.type}`);
400
429
  }
401
430
  }
402
431
 
@@ -419,7 +448,15 @@ export function apiParamToTsCodeAsObject(
419
448
  params: ApiParam[],
420
449
  injectImportKeys: string[]
421
450
  ): string {
422
- return `{ ${params.map((param) => `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`).join(", ")} }`;
451
+ return `{ ${params
452
+ .map(
453
+ (param) =>
454
+ `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(
455
+ param.type,
456
+ injectImportKeys
457
+ )}${param.defaultDef ? `= ${param.defaultDef}` : ""}`
458
+ )
459
+ .join(", ")} }`;
423
460
  }
424
461
 
425
462
  export function apiParamTypeToTsType(
@@ -461,7 +498,8 @@ export function apiParamTypeToTsType(
461
498
  );
462
499
  } else if (ApiParamType.isRef(paramType)) {
463
500
  if (
464
- ["Pick", "Omit", "Promise", "Partial"].includes(paramType.id) === false
501
+ ["Pick", "Omit", "Promise", "Partial", "Date"].includes(paramType.id) ===
502
+ false
465
503
  ) {
466
504
  // importKeys 인젝션
467
505
  injectImportKeys.push(paramType.id);
@@ -504,9 +542,10 @@ export function unwrapPromiseOnce(paramType: ApiParamType) {
504
542
  }
505
543
  }
506
544
 
545
+ // TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
507
546
  export function serializeZodType(zt: z.ZodTypeAny): any {
508
- switch (zt._def.typeName) {
509
- case "ZodObject":
547
+ switch (zt.def.type) {
548
+ case "object":
510
549
  return {
511
550
  type: "object",
512
551
  shape: Object.keys((zt as z.ZodObject<any>).shape).reduce(
@@ -519,130 +558,127 @@ export function serializeZodType(zt: z.ZodTypeAny): any {
519
558
  {}
520
559
  ),
521
560
  };
522
- case "ZodArray":
561
+ case "array":
523
562
  return {
524
563
  type: "array",
525
- element: serializeZodType(zt._def.type),
564
+ element: serializeZodType((zt as z.ZodArray<any>).def.element),
526
565
  };
527
- case "ZodEnum":
566
+ case "enum":
528
567
  return {
529
568
  type: "enum",
530
- values: zt._def.values,
569
+ values: (zt as z.ZodEnum).def.entries,
531
570
  };
532
- case "ZodString":
571
+ case "string":
533
572
  return {
534
573
  type: "string",
535
- checks: zt._def.checks,
574
+ checks: zt.def.checks,
536
575
  };
537
- case "ZodNumber":
576
+ case "number":
538
577
  return {
539
578
  type: "number",
540
- checks: zt._def.checks,
579
+ checks: zt.def.checks,
541
580
  };
542
- case "ZodBoolean":
581
+ case "boolean":
543
582
  return {
544
583
  type: "boolean",
545
584
  };
546
- case "ZodNullable":
585
+ case "nullable":
547
586
  return {
548
- ...serializeZodType(zt._def.innerType),
587
+ ...serializeZodType((zt as z.ZodNullable<any>).def.innerType),
549
588
  nullable: true,
550
589
  };
551
- case "ZodOptional":
590
+ case "optional":
552
591
  return {
553
- ...serializeZodType(zt._def.innerType),
592
+ ...serializeZodType((zt as z.ZodOptional<any>).def.innerType),
554
593
  optional: true,
555
594
  };
556
- case "ZodAny":
595
+ case "any":
557
596
  return {
558
597
  type: "any",
559
598
  };
560
- case "ZodRecord":
599
+ case "record":
561
600
  return {
562
601
  type: "record",
563
- keyType: serializeZodType((zt as ZodRecord)._def.keyType),
564
- valueType: serializeZodType((zt as ZodRecord)._def.valueType),
602
+ keyType: serializeZodType((zt as z.ZodRecord<any, any>).def.keyType),
603
+ valueType: serializeZodType((zt as z.ZodRecord<any, any>).def.valueType),
565
604
  };
566
- case "ZodUnion":
605
+ case "union":
567
606
  return {
568
607
  type: "union",
569
- options: (zt._def as z.ZodUnionDef).options.map((option) =>
608
+ options: (zt.def as z.ZodUnion<z.ZodType<any>[]>).options.map((option) =>
570
609
  serializeZodType(option)
571
610
  ),
572
611
  };
573
612
  default:
574
613
  throw new Error(
575
- `Serialize 로직이 정의되지 않은 ZodType: ${zt._def.typeName}`
614
+ `Serialize 로직이 정의되지 않은 ZodType: ${zt.def.type}`
576
615
  );
577
616
  }
578
617
  }
579
618
 
580
- export function zodTypeToTsTypeDef(
581
- zt: z.ZodFirstPartySchemaTypes | z.ZodObject<any>
582
- ): string {
583
- if (zt._def.description) {
584
- return zt._def.description;
585
- }
586
-
587
- switch (zt._def.typeName) {
588
- case "ZodString":
589
- return "string";
590
- case "ZodNumber":
591
- return "number";
592
- case "ZodBoolean":
593
- return "boolean";
594
- case "ZodBigInt":
595
- return "bigint";
596
- case "ZodDate":
597
- return "date";
598
- case "ZodNull":
599
- return "null";
600
- case "ZodUndefined":
601
- return "undefined";
602
- case "ZodAny":
603
- return "any";
604
- case "ZodUnknown":
605
- return "unknown";
606
- case "ZodNever":
607
- return "never";
608
- case "ZodNullable":
609
- return zodTypeToTsTypeDef(zt._def.innerType) + " | null";
610
- case "ZodDefault":
611
- return zodTypeToTsTypeDef(zt._def.innerType);
612
- case "ZodRecord":
619
+ // TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
620
+ export function zodTypeToTsTypeDef(zt: z.ZodType): string {
621
+ switch (zt.def.type) {
622
+ case "string":
623
+ case "number":
624
+ case "boolean":
625
+ case "bigint":
626
+ case "date":
627
+ case "null":
628
+ case "undefined":
629
+ case "any":
630
+ case "unknown":
631
+ case "never":
632
+ return zt.def.type;
633
+ case "nullable":
634
+ return zodTypeToTsTypeDef((zt as z.ZodNullable<any>).def.innerType) + " | null";
635
+ case "default":
636
+ return zodTypeToTsTypeDef((zt as z.ZodDefault<any>).def.innerType);
637
+ case "record":
638
+ const recordType = zt as z.ZodRecord<any, any>;
613
639
  return `{ [ key: ${zodTypeToTsTypeDef(
614
- zt._def.keyType
615
- )} ]: ${zodTypeToTsTypeDef(zt._def.valueType)}}`;
616
- case "ZodLiteral":
617
- if (typeof zt._def.value === "string") {
618
- return `"${zt._def.value}"`;
619
- } else {
620
- return `${zt._def.value}`;
621
- }
622
- case "ZodUnion":
623
- return `${zt._def.options
624
- .map((option: z.ZodTypeAny) => zodTypeToTsTypeDef(option))
640
+ recordType.def.keyType
641
+ )} ]: ${zodTypeToTsTypeDef(recordType.def.valueType)}}`;
642
+ case "literal":
643
+ return Array.from((zt as z.ZodLiteral<any>).values).map(value => {
644
+ if (typeof value === "string") {
645
+ return `"${value}"`;
646
+ }
647
+
648
+ if (value === null) {
649
+ return `null`;
650
+ }
651
+
652
+ if (value === undefined) {
653
+ return `undefined`;
654
+ }
655
+
656
+ return `${value}`;
657
+ }).join(" | ")
658
+ case "union":
659
+ return `${(zt as z.ZodUnion<z.ZodTypeAny[]>).options
660
+ .map((option) => zodTypeToTsTypeDef(option))
625
661
  .join(" | ")}`;
626
- case "ZodEnum":
627
- return `${zt._def.values.map((val: string) => `"${val}"`).join(" | ")}`;
628
- case "ZodArray":
629
- return `${zodTypeToTsTypeDef(zt._def.type)}[]`;
630
- case "ZodObject":
631
- const shape = (zt as any).shape;
662
+ case "enum":
663
+ return `${(zt as z.ZodEnum).options.map((val) => `"${val}"`).join(" | ")}`;
664
+ case "array":
665
+ return `${zodTypeToTsTypeDef((zt as z.ZodArray<any>).element.type)}[]`;
666
+ case "object":
667
+ const shape = (zt as z.ZodObject<any>).shape;
632
668
  return [
633
669
  "{",
634
670
  ...Object.keys(shape).map((key) => {
635
- if (shape[key]._def.typeName === "ZodOptional") {
636
- return `${key}?: ${zodTypeToTsTypeDef(shape[key]._def.innerType)},`;
671
+ if (shape[key].def.type === "optional") {
672
+ return `${key}?: ${zodTypeToTsTypeDef(shape[key].def.innerType)},`;
637
673
  } else {
638
674
  return `${key}: ${zodTypeToTsTypeDef(shape[key])},`;
639
675
  }
640
676
  }),
641
677
  "}",
642
678
  ].join("\n");
643
- case "ZodOptional":
644
- return zodTypeToTsTypeDef(zt._def.innerType) + " | undefined";
679
+ case "optional":
680
+ return zodTypeToTsTypeDef((zt as z.ZodOptional<any>).def.innerType) + " | undefined";
645
681
  default:
646
- throw new Error(`처리되지 않은 ZodType ${zt._def.typeName}`);
682
+ throw new Error(`처리되지 않은 ZodType ${zt.def.type}`);
647
683
  }
648
684
  }
@@ -1,14 +1,16 @@
1
- import { FastifyReply } from "fastify";
2
- import { RouteGenericInterface } from "fastify/types/route";
1
+ import type { FastifyReply, FastifyRequest } from "fastify";
2
+ import type { RouteGenericInterface } from "fastify/types/route";
3
3
  import {
4
- Server,
5
- IncomingMessage,
6
- ServerResponse,
7
- IncomingHttpHeaders,
4
+ type Server,
5
+ type IncomingMessage,
6
+ type ServerResponse,
7
+ type IncomingHttpHeaders,
8
8
  } from "http";
9
+ import type { FileStorage } from "../file-storage/file-storage";
9
10
 
10
11
  export interface ContextExtend {}
11
12
  export type Context = {
13
+ request: FastifyRequest;
12
14
  reply: FastifyReply<
13
15
  Server,
14
16
  IncomingMessage,
@@ -18,3 +20,8 @@ export type Context = {
18
20
  >;
19
21
  headers: IncomingHttpHeaders;
20
22
  } & ContextExtend;
23
+
24
+ export type UploadContext = {
25
+ file?: FileStorage;
26
+ files: FileStorage[];
27
+ };