sonamu 0.4.14 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/.swcrc +15 -0
  2. package/dist/api/base-frame.d.ts +8 -0
  3. package/dist/api/base-frame.d.ts.map +1 -0
  4. package/dist/api/base-frame.js +2 -0
  5. package/dist/api/base-frame.js.map +1 -0
  6. package/dist/api/caster.d.ts +5 -0
  7. package/dist/api/caster.d.ts.map +1 -0
  8. package/dist/api/caster.js +2 -0
  9. package/dist/api/caster.js.map +1 -0
  10. package/dist/api/code-converters.d.ts +23 -0
  11. package/dist/api/code-converters.d.ts.map +1 -0
  12. package/dist/api/code-converters.js +2 -0
  13. package/dist/api/code-converters.js.map +1 -0
  14. package/dist/api/context.d.ts +19 -0
  15. package/dist/api/context.d.ts.map +1 -0
  16. package/dist/api/context.js +2 -0
  17. package/dist/api/context.js.map +1 -0
  18. package/dist/api/decorators.d.ts +50 -0
  19. package/dist/api/decorators.d.ts.map +1 -0
  20. package/dist/api/decorators.js +2 -0
  21. package/dist/api/decorators.js.map +1 -0
  22. package/dist/api/index.d.ts +8 -0
  23. package/dist/api/index.d.ts.map +1 -0
  24. package/dist/api/index.js +2 -0
  25. package/dist/api/index.js.map +1 -0
  26. package/dist/api/sonamu.d.ts +84 -0
  27. package/dist/api/sonamu.d.ts.map +1 -0
  28. package/dist/api/sonamu.js +2 -0
  29. package/dist/api/sonamu.js.map +1 -0
  30. package/dist/bin/build-config.d.ts +9 -0
  31. package/dist/bin/build-config.d.ts.map +1 -0
  32. package/dist/bin/build-config.js +2 -0
  33. package/dist/bin/build-config.js.map +1 -0
  34. package/dist/bin/cli-wrapper.d.ts +2 -0
  35. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  36. package/dist/bin/cli-wrapper.js +1 -38
  37. package/dist/bin/cli-wrapper.js.map +1 -1
  38. package/dist/bin/cli.d.ts +2 -2
  39. package/dist/bin/cli.d.ts.map +1 -0
  40. package/dist/bin/cli.js +1 -903
  41. package/dist/bin/cli.js.map +1 -1
  42. package/dist/database/_batch_update.d.ts +15 -0
  43. package/dist/database/_batch_update.d.ts.map +1 -0
  44. package/dist/database/_batch_update.js +2 -0
  45. package/dist/database/_batch_update.js.map +1 -0
  46. package/dist/database/base-model.d.ts +48 -0
  47. package/dist/database/base-model.d.ts.map +1 -0
  48. package/dist/database/base-model.js +2 -0
  49. package/dist/database/base-model.js.map +1 -0
  50. package/dist/database/code-generator.d.ts +13 -0
  51. package/dist/database/code-generator.d.ts.map +1 -0
  52. package/dist/database/code-generator.js +2 -0
  53. package/dist/database/code-generator.js.map +1 -0
  54. package/dist/database/db.d.ts +40 -0
  55. package/dist/database/db.d.ts.map +1 -0
  56. package/dist/database/db.js +2 -0
  57. package/dist/database/db.js.map +1 -0
  58. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  59. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  60. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  61. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  62. package/dist/database/puri-wrapper.d.ts +34 -0
  63. package/dist/database/puri-wrapper.d.ts.map +1 -0
  64. package/dist/database/puri-wrapper.js +2 -0
  65. package/dist/database/puri-wrapper.js.map +1 -0
  66. package/dist/database/puri.d.ts +83 -0
  67. package/dist/database/puri.d.ts.map +1 -0
  68. package/dist/database/puri.js +2 -0
  69. package/dist/database/puri.js.map +1 -0
  70. package/dist/database/puri.types.d.ts +60 -0
  71. package/dist/database/puri.types.d.ts.map +1 -0
  72. package/dist/database/puri.types.js +2 -0
  73. package/dist/database/puri.types.js.map +1 -0
  74. package/dist/database/transaction-context.d.ts +9 -0
  75. package/dist/database/transaction-context.d.ts.map +1 -0
  76. package/dist/database/transaction-context.js +2 -0
  77. package/dist/database/transaction-context.js.map +1 -0
  78. package/dist/database/upsert-builder.d.ts +34 -0
  79. package/dist/database/upsert-builder.d.ts.map +1 -0
  80. package/dist/database/upsert-builder.js +2 -0
  81. package/dist/database/upsert-builder.js.map +1 -0
  82. package/dist/entity/entity-manager.d.ts +32 -0
  83. package/dist/entity/entity-manager.d.ts.map +1 -0
  84. package/dist/entity/entity-manager.js +2 -0
  85. package/dist/entity/entity-manager.js.map +1 -0
  86. package/dist/entity/entity-utils.d.ts +61 -0
  87. package/dist/entity/entity-utils.d.ts.map +1 -0
  88. package/dist/entity/entity-utils.js +2 -0
  89. package/dist/entity/entity-utils.js.map +1 -0
  90. package/dist/entity/entity.d.ts +62 -0
  91. package/dist/entity/entity.d.ts.map +1 -0
  92. package/dist/entity/entity.js +2 -0
  93. package/dist/entity/entity.js.map +1 -0
  94. package/dist/entity/migrator.d.ts +135 -0
  95. package/dist/entity/migrator.d.ts.map +1 -0
  96. package/dist/entity/migrator.js +2 -0
  97. package/dist/entity/migrator.js.map +1 -0
  98. package/dist/exceptions/error-handler.d.ts +3 -0
  99. package/dist/exceptions/error-handler.d.ts.map +1 -0
  100. package/dist/exceptions/error-handler.js +2 -0
  101. package/dist/exceptions/error-handler.js.map +1 -0
  102. package/dist/exceptions/so-exceptions.d.ts +48 -0
  103. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  104. package/dist/exceptions/so-exceptions.js +2 -0
  105. package/dist/exceptions/so-exceptions.js.map +1 -0
  106. package/dist/file-storage/driver.d.ts +48 -0
  107. package/dist/file-storage/driver.d.ts.map +1 -0
  108. package/dist/file-storage/driver.js +2 -0
  109. package/dist/file-storage/driver.js.map +1 -0
  110. package/dist/file-storage/file-storage.d.ts +50 -0
  111. package/dist/file-storage/file-storage.d.ts.map +1 -0
  112. package/dist/file-storage/file-storage.js +2 -0
  113. package/dist/file-storage/file-storage.js.map +1 -0
  114. package/dist/index.d.ts +23 -813
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +1 -433
  117. package/dist/index.js.map +1 -1
  118. package/dist/migration/code-generation.d.ts +15 -0
  119. package/dist/migration/code-generation.d.ts.map +1 -0
  120. package/dist/migration/code-generation.js +2 -0
  121. package/dist/migration/code-generation.js.map +1 -0
  122. package/dist/migration/migration-set.d.ts +17 -0
  123. package/dist/migration/migration-set.d.ts.map +1 -0
  124. package/dist/migration/migration-set.js +2 -0
  125. package/dist/migration/migration-set.js.map +1 -0
  126. package/dist/migration/migrator.d.ts +130 -0
  127. package/dist/migration/migrator.d.ts.map +1 -0
  128. package/dist/migration/migrator.js +2 -0
  129. package/dist/migration/migrator.js.map +1 -0
  130. package/dist/migration/types.d.ts +52 -0
  131. package/dist/migration/types.d.ts.map +1 -0
  132. package/dist/migration/types.js +2 -0
  133. package/dist/migration/types.js.map +1 -0
  134. package/dist/stream/index.d.ts +2 -0
  135. package/dist/stream/index.d.ts.map +1 -0
  136. package/dist/stream/index.js +2 -0
  137. package/dist/stream/index.js.map +1 -0
  138. package/dist/stream/sse.d.ts +13 -0
  139. package/dist/stream/sse.d.ts.map +1 -0
  140. package/dist/stream/sse.js +2 -0
  141. package/dist/stream/sse.js.map +1 -0
  142. package/dist/syncer/index.d.ts +2 -0
  143. package/dist/syncer/index.d.ts.map +1 -0
  144. package/dist/syncer/index.js +2 -0
  145. package/dist/syncer/index.js.map +1 -0
  146. package/dist/syncer/syncer.d.ts +127 -0
  147. package/dist/syncer/syncer.d.ts.map +1 -0
  148. package/dist/syncer/syncer.js +2 -0
  149. package/dist/syncer/syncer.js.map +1 -0
  150. package/dist/templates/base-template.d.ts +13 -0
  151. package/dist/templates/base-template.d.ts.map +1 -0
  152. package/dist/templates/base-template.js +2 -0
  153. package/dist/templates/base-template.js.map +1 -0
  154. package/dist/templates/entity.template.d.ts +17 -0
  155. package/dist/templates/entity.template.d.ts.map +1 -0
  156. package/dist/templates/entity.template.js +2 -0
  157. package/dist/templates/entity.template.js.map +1 -0
  158. package/dist/templates/generated.template.d.ts +27 -0
  159. package/dist/templates/generated.template.d.ts.map +1 -0
  160. package/dist/templates/generated.template.js +2 -0
  161. package/dist/templates/generated.template.js.map +1 -0
  162. package/dist/templates/generated_http.template.d.ts +24 -0
  163. package/dist/templates/generated_http.template.d.ts.map +1 -0
  164. package/dist/templates/generated_http.template.js +2 -0
  165. package/dist/templates/generated_http.template.js.map +1 -0
  166. package/dist/templates/generated_sso.template.d.ts +20 -0
  167. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  168. package/dist/templates/generated_sso.template.js +2 -0
  169. package/dist/templates/generated_sso.template.js.map +1 -0
  170. package/dist/templates/index.d.ts +2 -0
  171. package/dist/templates/index.d.ts.map +1 -0
  172. package/dist/templates/index.js +2 -0
  173. package/dist/templates/index.js.map +1 -0
  174. package/dist/templates/init_types.template.d.ts +17 -0
  175. package/dist/templates/init_types.template.d.ts.map +1 -0
  176. package/dist/templates/init_types.template.js +2 -0
  177. package/dist/templates/init_types.template.js.map +1 -0
  178. package/dist/templates/model.template.d.ts +17 -0
  179. package/dist/templates/model.template.d.ts.map +1 -0
  180. package/dist/templates/model.template.js +2 -0
  181. package/dist/templates/model.template.js.map +1 -0
  182. package/dist/templates/model_test.template.d.ts +17 -0
  183. package/dist/templates/model_test.template.d.ts.map +1 -0
  184. package/dist/templates/model_test.template.js +2 -0
  185. package/dist/templates/model_test.template.js.map +1 -0
  186. package/dist/templates/service.template.d.ts +29 -0
  187. package/dist/templates/service.template.d.ts.map +1 -0
  188. package/dist/templates/service.template.js +2 -0
  189. package/dist/templates/service.template.js.map +1 -0
  190. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  191. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  192. package/dist/templates/view_enums_buttonset.template.js +2 -0
  193. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  194. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  195. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  196. package/dist/templates/view_enums_dropdown.template.js +2 -0
  197. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  198. package/dist/templates/view_enums_select.template.d.ts +17 -0
  199. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  200. package/dist/templates/view_enums_select.template.js +2 -0
  201. package/dist/templates/view_enums_select.template.js.map +1 -0
  202. package/dist/templates/view_form.template.d.ts +26 -0
  203. package/dist/templates/view_form.template.d.ts.map +1 -0
  204. package/dist/templates/view_form.template.js +2 -0
  205. package/dist/templates/view_form.template.js.map +1 -0
  206. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  207. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  208. package/dist/templates/view_id_all_select.template.js +2 -0
  209. package/dist/templates/view_id_all_select.template.js.map +1 -0
  210. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  211. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  212. package/dist/templates/view_id_async_select.template.js +2 -0
  213. package/dist/templates/view_id_async_select.template.js.map +1 -0
  214. package/dist/templates/view_list.template.d.ts +38 -0
  215. package/dist/templates/view_list.template.d.ts.map +1 -0
  216. package/dist/templates/view_list.template.js +2 -0
  217. package/dist/templates/view_list.template.js.map +1 -0
  218. package/dist/templates/view_list_columns.template.d.ts +17 -0
  219. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  220. package/dist/templates/view_list_columns.template.js +2 -0
  221. package/dist/templates/view_list_columns.template.js.map +1 -0
  222. package/dist/templates/view_search_input.template.d.ts +17 -0
  223. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  224. package/dist/templates/view_search_input.template.js +2 -0
  225. package/dist/templates/view_search_input.template.js.map +1 -0
  226. package/dist/testing/_relation-graph.d.ts +7 -0
  227. package/dist/testing/_relation-graph.d.ts.map +1 -0
  228. package/dist/testing/_relation-graph.js +2 -0
  229. package/dist/testing/_relation-graph.js.map +1 -0
  230. package/dist/testing/fixture-manager.d.ts +35 -0
  231. package/dist/testing/fixture-manager.d.ts.map +1 -0
  232. package/dist/testing/fixture-manager.js +2 -0
  233. package/dist/testing/fixture-manager.js.map +1 -0
  234. package/dist/types/types.d.ts +611 -0
  235. package/dist/types/types.d.ts.map +1 -0
  236. package/dist/types/types.js +2 -0
  237. package/dist/types/types.js.map +1 -0
  238. package/dist/typings/knex.d.js +2 -0
  239. package/dist/typings/knex.d.js.map +1 -0
  240. package/dist/utils/async-utils.d.ts +25 -0
  241. package/dist/utils/async-utils.d.ts.map +1 -0
  242. package/dist/utils/async-utils.js +2 -0
  243. package/dist/utils/async-utils.js.map +1 -0
  244. package/dist/utils/controller.d.ts +9 -0
  245. package/dist/utils/controller.d.ts.map +1 -0
  246. package/dist/utils/controller.js +2 -0
  247. package/dist/utils/controller.js.map +1 -0
  248. package/dist/utils/fs-utils.d.ts +9 -0
  249. package/dist/utils/fs-utils.d.ts.map +1 -0
  250. package/dist/utils/fs-utils.js +2 -0
  251. package/dist/utils/fs-utils.js.map +1 -0
  252. package/dist/utils/lodash-able.d.ts +2 -0
  253. package/dist/utils/lodash-able.d.ts.map +1 -0
  254. package/dist/utils/lodash-able.js +2 -0
  255. package/dist/utils/lodash-able.js.map +1 -0
  256. package/dist/utils/model.d.ts +17 -0
  257. package/dist/utils/model.d.ts.map +1 -0
  258. package/dist/utils/model.js +2 -0
  259. package/dist/utils/model.js.map +1 -0
  260. package/dist/utils/sql-parser.d.ts +4 -0
  261. package/dist/utils/sql-parser.d.ts.map +1 -0
  262. package/dist/utils/sql-parser.js +2 -0
  263. package/dist/utils/sql-parser.js.map +1 -0
  264. package/dist/utils/utils.d.ts +9 -0
  265. package/dist/utils/utils.d.ts.map +1 -0
  266. package/dist/utils/utils.js +2 -0
  267. package/dist/utils/utils.js.map +1 -0
  268. package/dist/utils/zod-error.d.ts +8 -0
  269. package/dist/utils/zod-error.d.ts.map +1 -0
  270. package/dist/utils/zod-error.js +2 -0
  271. package/dist/utils/zod-error.js.map +1 -0
  272. package/nodemon.json +6 -0
  273. package/package.json +32 -45
  274. package/src/api/base-frame.ts +3 -4
  275. package/src/api/caster.ts +22 -23
  276. package/src/api/code-converters.ts +170 -134
  277. package/src/api/context.ts +15 -3
  278. package/src/api/decorators.ts +144 -20
  279. package/src/api/index.ts +2 -0
  280. package/src/api/sonamu.ts +408 -165
  281. package/src/bin/build-config.ts +10 -0
  282. package/src/bin/cli-wrapper.ts +35 -32
  283. package/src/bin/cli.ts +141 -204
  284. package/src/database/_batch_update.ts +10 -15
  285. package/src/database/base-model.ts +326 -216
  286. package/src/database/db.ts +191 -21
  287. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  288. package/src/database/puri-wrapper.ts +129 -0
  289. package/src/database/puri.ts +808 -0
  290. package/src/database/puri.types.ts +222 -0
  291. package/src/database/transaction-context.ts +18 -0
  292. package/src/database/upsert-builder.ts +32 -35
  293. package/src/entity/entity-manager.ts +7 -15
  294. package/src/entity/entity.ts +9 -31
  295. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  296. package/src/file-storage/driver.ts +131 -0
  297. package/src/file-storage/file-storage.ts +100 -0
  298. package/src/index.ts +15 -11
  299. package/src/migration/code-generation.ts +777 -0
  300. package/src/migration/migration-set.ts +453 -0
  301. package/src/migration/migrator.ts +823 -0
  302. package/src/migration/types.ts +53 -0
  303. package/src/shared/web.shared.ts.txt +33 -2
  304. package/src/stream/index.ts +1 -0
  305. package/src/stream/sse.ts +49 -0
  306. package/src/syncer/syncer.ts +294 -127
  307. package/src/templates/generated.template.ts +13 -1
  308. package/src/templates/generated_http.template.ts +15 -12
  309. package/src/templates/generated_sso.template.ts +50 -2
  310. package/src/templates/model.template.ts +138 -2
  311. package/src/templates/service.template.ts +0 -1
  312. package/src/templates/view_form.template.ts +11 -7
  313. package/src/templates/view_list.template.ts +12 -4
  314. package/src/testing/fixture-manager.ts +229 -174
  315. package/src/types/types.ts +108 -14
  316. package/src/utils/async-utils.ts +64 -0
  317. package/src/utils/fs-utils.ts +17 -0
  318. package/src/utils/model.ts +0 -2
  319. package/src/utils/utils.ts +14 -58
  320. package/src/utils/zod-error.ts +12 -176
  321. package/tsconfig.json +6 -0
  322. package/tsup.config.js +4 -2
  323. package/.pnp.cjs +0 -14363
  324. package/.pnp.loader.mjs +0 -2047
  325. package/.vscode/extensions.json +0 -6
  326. package/.vscode/settings.json +0 -9
  327. package/.yarnrc.yml +0 -5
  328. package/dist/base-model-CEB0H0aO.d.mts +0 -43
  329. package/dist/base-model-CrqDMYhI.d.ts +0 -43
  330. package/dist/bin/cli-wrapper.d.mts +0 -1
  331. package/dist/bin/cli-wrapper.mjs +0 -43
  332. package/dist/bin/cli-wrapper.mjs.map +0 -1
  333. package/dist/bin/cli.d.mts +0 -2
  334. package/dist/bin/cli.mjs +0 -907
  335. package/dist/bin/cli.mjs.map +0 -1
  336. package/dist/chunk-2WAC2GER.js +0 -7625
  337. package/dist/chunk-2WAC2GER.js.map +0 -1
  338. package/dist/chunk-C3IPIF6O.mjs +0 -1581
  339. package/dist/chunk-C3IPIF6O.mjs.map +0 -1
  340. package/dist/chunk-EXHKSVTE.js +0 -280
  341. package/dist/chunk-EXHKSVTE.js.map +0 -1
  342. package/dist/chunk-FCERKIIF.mjs +0 -7623
  343. package/dist/chunk-FCERKIIF.mjs.map +0 -1
  344. package/dist/chunk-HGIBJYOU.mjs +0 -231
  345. package/dist/chunk-HGIBJYOU.mjs.map +0 -1
  346. package/dist/chunk-JKSOJRQA.mjs +0 -280
  347. package/dist/chunk-JKSOJRQA.mjs.map +0 -1
  348. package/dist/chunk-OTKKFP3Y.js +0 -1581
  349. package/dist/chunk-OTKKFP3Y.js.map +0 -1
  350. package/dist/chunk-PTFDTOJU.mjs +0 -19
  351. package/dist/chunk-PTFDTOJU.mjs.map +0 -1
  352. package/dist/chunk-UZ2IY5VE.js +0 -231
  353. package/dist/chunk-UZ2IY5VE.js.map +0 -1
  354. package/dist/database/drivers/knex/base-model.d.mts +0 -16
  355. package/dist/database/drivers/knex/base-model.d.ts +0 -16
  356. package/dist/database/drivers/knex/base-model.js +0 -55
  357. package/dist/database/drivers/knex/base-model.js.map +0 -1
  358. package/dist/database/drivers/knex/base-model.mjs +0 -56
  359. package/dist/database/drivers/knex/base-model.mjs.map +0 -1
  360. package/dist/database/drivers/kysely/base-model.d.mts +0 -22
  361. package/dist/database/drivers/kysely/base-model.d.ts +0 -22
  362. package/dist/database/drivers/kysely/base-model.js +0 -64
  363. package/dist/database/drivers/kysely/base-model.js.map +0 -1
  364. package/dist/database/drivers/kysely/base-model.mjs +0 -65
  365. package/dist/database/drivers/kysely/base-model.mjs.map +0 -1
  366. package/dist/index.d.mts +0 -813
  367. package/dist/index.mjs +0 -435
  368. package/dist/index.mjs.map +0 -1
  369. package/dist/model-aFgomcdc.d.mts +0 -1112
  370. package/dist/model-aFgomcdc.d.ts +0 -1112
  371. package/src/database/base-model.abstract.ts +0 -97
  372. package/src/database/db.abstract.ts +0 -75
  373. package/src/database/drivers/knex/base-model.ts +0 -55
  374. package/src/database/drivers/knex/client.ts +0 -209
  375. package/src/database/drivers/knex/db.ts +0 -232
  376. package/src/database/drivers/knex/generator.ts +0 -659
  377. package/src/database/drivers/kysely/base-model.ts +0 -89
  378. package/src/database/drivers/kysely/client.ts +0 -309
  379. package/src/database/drivers/kysely/db.ts +0 -238
  380. package/src/database/drivers/kysely/generator.ts +0 -714
  381. package/src/database/types.ts +0 -118
  382. package/src/entity/migrator.ts +0 -1400
  383. package/src/smd/smd-manager.ts +0 -139
  384. package/src/smd/smd.ts +0 -571
  385. package/src/templates/kysely_types.template.ts +0 -205
@@ -1,6 +1,20 @@
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";
15
+ import type { SsePluginOptions } from "fastify-sse-v2/lib/types";
2
16
 
3
- /*
17
+ /*
4
18
  Enums
5
19
  */
6
20
  export type EnumsLabel<T extends string, L extends "ko" | "en"> = {
@@ -26,7 +40,7 @@ export type SQLDateTimeString = z.infer<typeof SQLDateTimeString>;
26
40
  */
27
41
  export function zArrayable<T extends z.ZodTypeAny>(
28
42
  shape: T
29
- ): z.ZodUnion<[T, z.ZodArray<T, "many">]> {
43
+ ): z.ZodUnion<[T, z.ZodArray<T>]> {
30
44
  return z.union([shape, shape.array()]);
31
45
  }
32
46
  export type DistributiveOmit<T, K extends keyof any> = T extends any
@@ -186,9 +200,10 @@ export type EntityProp =
186
200
  | RelationProp;
187
201
 
188
202
  export type EntityIndex = {
189
- type: "index" | "unique";
203
+ type: "index" | "unique" | "fulltext";
190
204
  columns: string[];
191
205
  name?: string;
206
+ parser?: "built-in" | "ngram";
192
207
  };
193
208
  export type EntityJson = {
194
209
  id: string;
@@ -412,9 +427,6 @@ export type KnexError = {
412
427
  export function isKnexError(e: any): e is KnexError {
413
428
  return e.code && e.sqlMessage && e.sqlState;
414
429
  }
415
- export function isKyselyError(e: any): e is KnexError {
416
- return e.code && e.sqlMessage && e.sqlState;
417
- }
418
430
 
419
431
  export type KnexColumnType =
420
432
  | "string"
@@ -446,7 +458,8 @@ export type MigrationColumn = {
446
458
  };
447
459
  export type MigrationIndex = {
448
460
  columns: string[];
449
- type: "unique" | "index";
461
+ type: "unique" | "index" | "fulltext";
462
+ parser?: "built-in" | "ngram";
450
463
  };
451
464
  export type MigrationForeign = {
452
465
  columns: string[];
@@ -593,11 +606,6 @@ export namespace ApiParamType {
593
606
  export function isRefKnex(v: any): v is ApiParamType.Ref {
594
607
  return v?.t === "ref" && v.id === "Knex";
595
608
  }
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
609
  export function isTypeParam(v: any): v is ApiParamType.TypeParam {
602
610
  return v?.t === "type-param";
603
611
  }
@@ -635,6 +643,7 @@ export type RenderingNode = {
635
643
  | "string-image"
636
644
  | "string-datetime"
637
645
  | "string-date"
646
+ | "datetime"
638
647
  | "number-plain"
639
648
  | "number-id"
640
649
  | "number-fk_id"
@@ -738,7 +747,6 @@ export const TemplateOptions = z.object({
738
747
  entityId: z.string(),
739
748
  enumId: z.string(),
740
749
  }),
741
- kysely_interface: z.object({}),
742
750
  });
743
751
  export type TemplateOptions = z.infer<typeof TemplateOptions>;
744
752
 
@@ -761,7 +769,6 @@ export const TemplateKey = z.enum([
761
769
  "view_enums_select",
762
770
  "view_enums_dropdown",
763
771
  "view_enums_buttonset",
764
- "kysely_interface",
765
772
  ]);
766
773
  export type TemplateKey = z.infer<typeof TemplateKey>;
767
774
 
@@ -812,3 +819,90 @@ export type RelationNode = {
812
819
  entityId: string;
813
820
  related: Set<string>;
814
821
  };
822
+
823
+ export interface DatabaseSchemaExtend {}
824
+ export type ManyToManyBaseSchema<
825
+ FromIdKey extends string,
826
+ ToIdKey extends string,
827
+ > = {
828
+ id: number;
829
+ } & {
830
+ [K in `${FromIdKey}_id`]: number;
831
+ } & {
832
+ [K in `${ToIdKey}_id`]: number;
833
+ };
834
+
835
+ export type SonamuFastifyConfig = {
836
+ contextProvider: (
837
+ defaultContext: Pick<
838
+ Context,
839
+ "request" | "reply" | "headers" | "createSSE"
840
+ >,
841
+ request: FastifyRequest,
842
+ reply: FastifyReply
843
+ ) => Context;
844
+ guardHandler: (
845
+ guard: GuardKey,
846
+ request: FastifyRequest,
847
+ api: {
848
+ typeParameters: ApiParamType.TypeParam[];
849
+ parameters: ApiParam[];
850
+ returnType: ApiParamType;
851
+ modelName: string;
852
+ methodName: string;
853
+ path: string;
854
+ options: ApiDecoratorOptions;
855
+ }
856
+ ) => void;
857
+ cache?: {
858
+ get: (key: string) => Promise<unknown | null>;
859
+ put: (key: string, value: unknown, ttl?: number) => Promise<void>;
860
+ resolveKey: (
861
+ path: string,
862
+ reqBody: {
863
+ [key: string]: unknown;
864
+ }
865
+ ) =>
866
+ | {
867
+ cache: false;
868
+ }
869
+ | {
870
+ cache: true;
871
+ key: string;
872
+ ttl?: number;
873
+ };
874
+ };
875
+ };
876
+
877
+ export type SonamuServerOptions = {
878
+ fastify?: FastifyServerOptions;
879
+
880
+ listen?: {
881
+ port: number;
882
+ host?: string;
883
+ };
884
+
885
+ plugins?: {
886
+ cors?: boolean | FastifyCorsOptions;
887
+ formbody?: boolean | FastifyFormbodyOptions;
888
+ multipart?: boolean | FastifyMultipartOptions;
889
+ qs?: boolean | QsPluginOptions;
890
+ sse?: boolean | SsePluginOptions;
891
+
892
+ custom?: (server: FastifyInstance) => void;
893
+ };
894
+
895
+ apiConfig: SonamuFastifyConfig;
896
+
897
+ storage?: Driver;
898
+
899
+ lifecycle?: {
900
+ onStart?: (server: FastifyInstance) => Promise<void> | void;
901
+ onShutdown?: (server: FastifyInstance) => Promise<void> | void;
902
+ onError?: (
903
+ error: Error,
904
+ request: FastifyRequest,
905
+ reply: FastifyReply
906
+ ) => Promise<void> | void;
907
+ };
908
+ };
@@ -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
@@ -6,6 +6,10 @@
6
6
  "outDir": "dist",
7
7
  "sourceMap": true,
8
8
  "lib": ["esnext", "dom"],
9
+
10
+ // NOTE(Haze, 251106): SSE 관련 fastify 타입 이슈로 명시적으로 추가함.
11
+ "types": ["fastify-sse-v2"],
12
+
9
13
  "declaration": true,
10
14
  "declarationMap": true,
11
15
 
@@ -24,6 +28,8 @@
24
28
  "noUnusedParameters": true,
25
29
  "noImplicitReturns": true,
26
30
  "noFallthroughCasesInSwitch": true,
31
+ "skipLibCheck": true,
32
+ // "noUncheckedIndexedAccess": true, // FIXME
27
33
 
28
34
  /* Module Resolution Options */
29
35
  "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",