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.
- package/.swcrc +15 -0
- package/dist/api/base-frame.d.ts +8 -0
- package/dist/api/base-frame.d.ts.map +1 -0
- package/dist/api/base-frame.js +2 -0
- package/dist/api/base-frame.js.map +1 -0
- package/dist/api/caster.d.ts +5 -0
- package/dist/api/caster.d.ts.map +1 -0
- package/dist/api/caster.js +2 -0
- package/dist/api/caster.js.map +1 -0
- package/dist/api/code-converters.d.ts +23 -0
- package/dist/api/code-converters.d.ts.map +1 -0
- package/dist/api/code-converters.js +2 -0
- package/dist/api/code-converters.js.map +1 -0
- package/dist/api/context.d.ts +19 -0
- package/dist/api/context.d.ts.map +1 -0
- package/dist/api/context.js +2 -0
- package/dist/api/context.js.map +1 -0
- package/dist/api/decorators.d.ts +50 -0
- package/dist/api/decorators.d.ts.map +1 -0
- package/dist/api/decorators.js +2 -0
- package/dist/api/decorators.js.map +1 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/sonamu.d.ts +84 -0
- package/dist/api/sonamu.d.ts.map +1 -0
- package/dist/api/sonamu.js +2 -0
- package/dist/api/sonamu.js.map +1 -0
- package/dist/bin/build-config.d.ts +9 -0
- package/dist/bin/build-config.d.ts.map +1 -0
- package/dist/bin/build-config.js +2 -0
- package/dist/bin/build-config.js.map +1 -0
- package/dist/bin/cli-wrapper.d.ts +2 -0
- package/dist/bin/cli-wrapper.d.ts.map +1 -0
- package/dist/bin/cli-wrapper.js +1 -38
- package/dist/bin/cli-wrapper.js.map +1 -1
- package/dist/bin/cli.d.ts +2 -2
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +1 -903
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/_batch_update.d.ts +15 -0
- package/dist/database/_batch_update.d.ts.map +1 -0
- package/dist/database/_batch_update.js +2 -0
- package/dist/database/_batch_update.js.map +1 -0
- package/dist/database/base-model.d.ts +48 -0
- package/dist/database/base-model.d.ts.map +1 -0
- package/dist/database/base-model.js +2 -0
- package/dist/database/base-model.js.map +1 -0
- package/dist/database/code-generator.d.ts +13 -0
- package/dist/database/code-generator.d.ts.map +1 -0
- package/dist/database/code-generator.js +2 -0
- package/dist/database/code-generator.js.map +1 -0
- package/dist/database/db.d.ts +40 -0
- package/dist/database/db.d.ts.map +1 -0
- package/dist/database/db.js +2 -0
- package/dist/database/db.js.map +1 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
- package/dist/database/puri-wrapper.d.ts +34 -0
- package/dist/database/puri-wrapper.d.ts.map +1 -0
- package/dist/database/puri-wrapper.js +2 -0
- package/dist/database/puri-wrapper.js.map +1 -0
- package/dist/database/puri.d.ts +83 -0
- package/dist/database/puri.d.ts.map +1 -0
- package/dist/database/puri.js +2 -0
- package/dist/database/puri.js.map +1 -0
- package/dist/database/puri.types.d.ts +60 -0
- package/dist/database/puri.types.d.ts.map +1 -0
- package/dist/database/puri.types.js +2 -0
- package/dist/database/puri.types.js.map +1 -0
- package/dist/database/transaction-context.d.ts +9 -0
- package/dist/database/transaction-context.d.ts.map +1 -0
- package/dist/database/transaction-context.js +2 -0
- package/dist/database/transaction-context.js.map +1 -0
- package/dist/database/upsert-builder.d.ts +34 -0
- package/dist/database/upsert-builder.d.ts.map +1 -0
- package/dist/database/upsert-builder.js +2 -0
- package/dist/database/upsert-builder.js.map +1 -0
- package/dist/entity/entity-manager.d.ts +32 -0
- package/dist/entity/entity-manager.d.ts.map +1 -0
- package/dist/entity/entity-manager.js +2 -0
- package/dist/entity/entity-manager.js.map +1 -0
- package/dist/entity/entity-utils.d.ts +61 -0
- package/dist/entity/entity-utils.d.ts.map +1 -0
- package/dist/entity/entity-utils.js +2 -0
- package/dist/entity/entity-utils.js.map +1 -0
- package/dist/entity/entity.d.ts +62 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entity.js +2 -0
- package/dist/entity/entity.js.map +1 -0
- package/dist/entity/migrator.d.ts +135 -0
- package/dist/entity/migrator.d.ts.map +1 -0
- package/dist/entity/migrator.js +2 -0
- package/dist/entity/migrator.js.map +1 -0
- package/dist/exceptions/error-handler.d.ts +3 -0
- package/dist/exceptions/error-handler.d.ts.map +1 -0
- package/dist/exceptions/error-handler.js +2 -0
- package/dist/exceptions/error-handler.js.map +1 -0
- package/dist/exceptions/so-exceptions.d.ts +48 -0
- package/dist/exceptions/so-exceptions.d.ts.map +1 -0
- package/dist/exceptions/so-exceptions.js +2 -0
- package/dist/exceptions/so-exceptions.js.map +1 -0
- package/dist/file-storage/driver.d.ts +48 -0
- package/dist/file-storage/driver.d.ts.map +1 -0
- package/dist/file-storage/driver.js +2 -0
- package/dist/file-storage/driver.js.map +1 -0
- package/dist/file-storage/file-storage.d.ts +50 -0
- package/dist/file-storage/file-storage.d.ts.map +1 -0
- package/dist/file-storage/file-storage.js +2 -0
- package/dist/file-storage/file-storage.js.map +1 -0
- package/dist/index.d.ts +23 -813
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -433
- package/dist/index.js.map +1 -1
- package/dist/migration/code-generation.d.ts +15 -0
- package/dist/migration/code-generation.d.ts.map +1 -0
- package/dist/migration/code-generation.js +2 -0
- package/dist/migration/code-generation.js.map +1 -0
- package/dist/migration/migration-set.d.ts +17 -0
- package/dist/migration/migration-set.d.ts.map +1 -0
- package/dist/migration/migration-set.js +2 -0
- package/dist/migration/migration-set.js.map +1 -0
- package/dist/migration/migrator.d.ts +130 -0
- package/dist/migration/migrator.d.ts.map +1 -0
- package/dist/migration/migrator.js +2 -0
- package/dist/migration/migrator.js.map +1 -0
- package/dist/migration/types.d.ts +52 -0
- package/dist/migration/types.d.ts.map +1 -0
- package/dist/migration/types.js +2 -0
- package/dist/migration/types.js.map +1 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/index.js +2 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/sse.d.ts +13 -0
- package/dist/stream/sse.d.ts.map +1 -0
- package/dist/stream/sse.js +2 -0
- package/dist/stream/sse.js.map +1 -0
- package/dist/syncer/index.d.ts +2 -0
- package/dist/syncer/index.d.ts.map +1 -0
- package/dist/syncer/index.js +2 -0
- package/dist/syncer/index.js.map +1 -0
- package/dist/syncer/syncer.d.ts +127 -0
- package/dist/syncer/syncer.d.ts.map +1 -0
- package/dist/syncer/syncer.js +2 -0
- package/dist/syncer/syncer.js.map +1 -0
- package/dist/templates/base-template.d.ts +13 -0
- package/dist/templates/base-template.d.ts.map +1 -0
- package/dist/templates/base-template.js +2 -0
- package/dist/templates/base-template.js.map +1 -0
- package/dist/templates/entity.template.d.ts +17 -0
- package/dist/templates/entity.template.d.ts.map +1 -0
- package/dist/templates/entity.template.js +2 -0
- package/dist/templates/entity.template.js.map +1 -0
- package/dist/templates/generated.template.d.ts +27 -0
- package/dist/templates/generated.template.d.ts.map +1 -0
- package/dist/templates/generated.template.js +2 -0
- package/dist/templates/generated.template.js.map +1 -0
- package/dist/templates/generated_http.template.d.ts +24 -0
- package/dist/templates/generated_http.template.d.ts.map +1 -0
- package/dist/templates/generated_http.template.js +2 -0
- package/dist/templates/generated_http.template.js.map +1 -0
- package/dist/templates/generated_sso.template.d.ts +20 -0
- package/dist/templates/generated_sso.template.d.ts.map +1 -0
- package/dist/templates/generated_sso.template.js +2 -0
- package/dist/templates/generated_sso.template.js.map +1 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +2 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/init_types.template.d.ts +17 -0
- package/dist/templates/init_types.template.d.ts.map +1 -0
- package/dist/templates/init_types.template.js +2 -0
- package/dist/templates/init_types.template.js.map +1 -0
- package/dist/templates/model.template.d.ts +17 -0
- package/dist/templates/model.template.d.ts.map +1 -0
- package/dist/templates/model.template.js +2 -0
- package/dist/templates/model.template.js.map +1 -0
- package/dist/templates/model_test.template.d.ts +17 -0
- package/dist/templates/model_test.template.d.ts.map +1 -0
- package/dist/templates/model_test.template.js +2 -0
- package/dist/templates/model_test.template.js.map +1 -0
- package/dist/templates/service.template.d.ts +29 -0
- package/dist/templates/service.template.d.ts.map +1 -0
- package/dist/templates/service.template.js +2 -0
- package/dist/templates/service.template.js.map +1 -0
- package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
- package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
- package/dist/templates/view_enums_buttonset.template.js +2 -0
- package/dist/templates/view_enums_buttonset.template.js.map +1 -0
- package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
- package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
- package/dist/templates/view_enums_dropdown.template.js +2 -0
- package/dist/templates/view_enums_dropdown.template.js.map +1 -0
- package/dist/templates/view_enums_select.template.d.ts +17 -0
- package/dist/templates/view_enums_select.template.d.ts.map +1 -0
- package/dist/templates/view_enums_select.template.js +2 -0
- package/dist/templates/view_enums_select.template.js.map +1 -0
- package/dist/templates/view_form.template.d.ts +26 -0
- package/dist/templates/view_form.template.d.ts.map +1 -0
- package/dist/templates/view_form.template.js +2 -0
- package/dist/templates/view_form.template.js.map +1 -0
- package/dist/templates/view_id_all_select.template.d.ts +17 -0
- package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
- package/dist/templates/view_id_all_select.template.js +2 -0
- package/dist/templates/view_id_all_select.template.js.map +1 -0
- package/dist/templates/view_id_async_select.template.d.ts +17 -0
- package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
- package/dist/templates/view_id_async_select.template.js +2 -0
- package/dist/templates/view_id_async_select.template.js.map +1 -0
- package/dist/templates/view_list.template.d.ts +38 -0
- package/dist/templates/view_list.template.d.ts.map +1 -0
- package/dist/templates/view_list.template.js +2 -0
- package/dist/templates/view_list.template.js.map +1 -0
- package/dist/templates/view_list_columns.template.d.ts +17 -0
- package/dist/templates/view_list_columns.template.d.ts.map +1 -0
- package/dist/templates/view_list_columns.template.js +2 -0
- package/dist/templates/view_list_columns.template.js.map +1 -0
- package/dist/templates/view_search_input.template.d.ts +17 -0
- package/dist/templates/view_search_input.template.d.ts.map +1 -0
- package/dist/templates/view_search_input.template.js +2 -0
- package/dist/templates/view_search_input.template.js.map +1 -0
- package/dist/testing/_relation-graph.d.ts +7 -0
- package/dist/testing/_relation-graph.d.ts.map +1 -0
- package/dist/testing/_relation-graph.js +2 -0
- package/dist/testing/_relation-graph.js.map +1 -0
- package/dist/testing/fixture-manager.d.ts +35 -0
- package/dist/testing/fixture-manager.d.ts.map +1 -0
- package/dist/testing/fixture-manager.js +2 -0
- package/dist/testing/fixture-manager.js.map +1 -0
- package/dist/types/types.d.ts +611 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/typings/knex.d.js +2 -0
- package/dist/typings/knex.d.js.map +1 -0
- package/dist/utils/async-utils.d.ts +25 -0
- package/dist/utils/async-utils.d.ts.map +1 -0
- package/dist/utils/async-utils.js +2 -0
- package/dist/utils/async-utils.js.map +1 -0
- package/dist/utils/controller.d.ts +9 -0
- package/dist/utils/controller.d.ts.map +1 -0
- package/dist/utils/controller.js +2 -0
- package/dist/utils/controller.js.map +1 -0
- package/dist/utils/fs-utils.d.ts +9 -0
- package/dist/utils/fs-utils.d.ts.map +1 -0
- package/dist/utils/fs-utils.js +2 -0
- package/dist/utils/fs-utils.js.map +1 -0
- package/dist/utils/lodash-able.d.ts +2 -0
- package/dist/utils/lodash-able.d.ts.map +1 -0
- package/dist/utils/lodash-able.js +2 -0
- package/dist/utils/lodash-able.js.map +1 -0
- package/dist/utils/model.d.ts +17 -0
- package/dist/utils/model.d.ts.map +1 -0
- package/dist/utils/model.js +2 -0
- package/dist/utils/model.js.map +1 -0
- package/dist/utils/sql-parser.d.ts +4 -0
- package/dist/utils/sql-parser.d.ts.map +1 -0
- package/dist/utils/sql-parser.js +2 -0
- package/dist/utils/sql-parser.js.map +1 -0
- package/dist/utils/utils.d.ts +9 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +2 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/zod-error.d.ts +8 -0
- package/dist/utils/zod-error.d.ts.map +1 -0
- package/dist/utils/zod-error.js +2 -0
- package/dist/utils/zod-error.js.map +1 -0
- package/nodemon.json +6 -0
- package/package.json +32 -45
- package/src/api/base-frame.ts +3 -4
- package/src/api/caster.ts +22 -23
- package/src/api/code-converters.ts +170 -134
- package/src/api/context.ts +15 -3
- package/src/api/decorators.ts +144 -20
- package/src/api/index.ts +2 -0
- package/src/api/sonamu.ts +408 -165
- package/src/bin/build-config.ts +10 -0
- package/src/bin/cli-wrapper.ts +35 -32
- package/src/bin/cli.ts +141 -204
- package/src/database/_batch_update.ts +10 -15
- package/src/database/base-model.ts +326 -216
- package/src/database/db.ts +191 -21
- package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
- package/src/database/puri-wrapper.ts +129 -0
- package/src/database/puri.ts +808 -0
- package/src/database/puri.types.ts +222 -0
- package/src/database/transaction-context.ts +18 -0
- package/src/database/upsert-builder.ts +32 -35
- package/src/entity/entity-manager.ts +7 -15
- package/src/entity/entity.ts +9 -31
- package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
- package/src/file-storage/driver.ts +131 -0
- package/src/file-storage/file-storage.ts +100 -0
- package/src/index.ts +15 -11
- package/src/migration/code-generation.ts +777 -0
- package/src/migration/migration-set.ts +453 -0
- package/src/migration/migrator.ts +823 -0
- package/src/migration/types.ts +53 -0
- package/src/shared/web.shared.ts.txt +33 -2
- package/src/stream/index.ts +1 -0
- package/src/stream/sse.ts +49 -0
- package/src/syncer/syncer.ts +294 -127
- package/src/templates/generated.template.ts +13 -1
- package/src/templates/generated_http.template.ts +15 -12
- package/src/templates/generated_sso.template.ts +50 -2
- package/src/templates/model.template.ts +138 -2
- package/src/templates/service.template.ts +0 -1
- package/src/templates/view_form.template.ts +11 -7
- package/src/templates/view_list.template.ts +12 -4
- package/src/testing/fixture-manager.ts +229 -174
- package/src/types/types.ts +108 -14
- package/src/utils/async-utils.ts +64 -0
- package/src/utils/fs-utils.ts +17 -0
- package/src/utils/model.ts +0 -2
- package/src/utils/utils.ts +14 -58
- package/src/utils/zod-error.ts +12 -176
- package/tsconfig.json +6 -0
- package/tsup.config.js +4 -2
- package/.pnp.cjs +0 -14363
- package/.pnp.loader.mjs +0 -2047
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -9
- package/.yarnrc.yml +0 -5
- package/dist/base-model-CEB0H0aO.d.mts +0 -43
- package/dist/base-model-CrqDMYhI.d.ts +0 -43
- package/dist/bin/cli-wrapper.d.mts +0 -1
- package/dist/bin/cli-wrapper.mjs +0 -43
- package/dist/bin/cli-wrapper.mjs.map +0 -1
- package/dist/bin/cli.d.mts +0 -2
- package/dist/bin/cli.mjs +0 -907
- package/dist/bin/cli.mjs.map +0 -1
- package/dist/chunk-2WAC2GER.js +0 -7625
- package/dist/chunk-2WAC2GER.js.map +0 -1
- package/dist/chunk-C3IPIF6O.mjs +0 -1581
- package/dist/chunk-C3IPIF6O.mjs.map +0 -1
- package/dist/chunk-EXHKSVTE.js +0 -280
- package/dist/chunk-EXHKSVTE.js.map +0 -1
- package/dist/chunk-FCERKIIF.mjs +0 -7623
- package/dist/chunk-FCERKIIF.mjs.map +0 -1
- package/dist/chunk-HGIBJYOU.mjs +0 -231
- package/dist/chunk-HGIBJYOU.mjs.map +0 -1
- package/dist/chunk-JKSOJRQA.mjs +0 -280
- package/dist/chunk-JKSOJRQA.mjs.map +0 -1
- package/dist/chunk-OTKKFP3Y.js +0 -1581
- package/dist/chunk-OTKKFP3Y.js.map +0 -1
- package/dist/chunk-PTFDTOJU.mjs +0 -19
- package/dist/chunk-PTFDTOJU.mjs.map +0 -1
- package/dist/chunk-UZ2IY5VE.js +0 -231
- package/dist/chunk-UZ2IY5VE.js.map +0 -1
- package/dist/database/drivers/knex/base-model.d.mts +0 -16
- package/dist/database/drivers/knex/base-model.d.ts +0 -16
- package/dist/database/drivers/knex/base-model.js +0 -55
- package/dist/database/drivers/knex/base-model.js.map +0 -1
- package/dist/database/drivers/knex/base-model.mjs +0 -56
- package/dist/database/drivers/knex/base-model.mjs.map +0 -1
- package/dist/database/drivers/kysely/base-model.d.mts +0 -22
- package/dist/database/drivers/kysely/base-model.d.ts +0 -22
- package/dist/database/drivers/kysely/base-model.js +0 -64
- package/dist/database/drivers/kysely/base-model.js.map +0 -1
- package/dist/database/drivers/kysely/base-model.mjs +0 -65
- package/dist/database/drivers/kysely/base-model.mjs.map +0 -1
- package/dist/index.d.mts +0 -813
- package/dist/index.mjs +0 -435
- package/dist/index.mjs.map +0 -1
- package/dist/model-aFgomcdc.d.mts +0 -1112
- package/dist/model-aFgomcdc.d.ts +0 -1112
- package/src/database/base-model.abstract.ts +0 -97
- package/src/database/db.abstract.ts +0 -75
- package/src/database/drivers/knex/base-model.ts +0 -55
- package/src/database/drivers/knex/client.ts +0 -209
- package/src/database/drivers/knex/db.ts +0 -232
- package/src/database/drivers/knex/generator.ts +0 -659
- package/src/database/drivers/kysely/base-model.ts +0 -89
- package/src/database/drivers/kysely/client.ts +0 -309
- package/src/database/drivers/kysely/db.ts +0 -238
- package/src/database/drivers/kysely/generator.ts +0 -714
- package/src/database/types.ts +0 -118
- package/src/entity/migrator.ts +0 -1400
- package/src/smd/smd-manager.ts +0 -139
- package/src/smd/smd.ts +0 -571
- package/src/templates/kysely_types.template.ts +0 -205
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWC 빌드 명령어
|
|
3
|
+
*/
|
|
4
|
+
export const SWC_BUILD_COMMAND =
|
|
5
|
+
"swc src -d dist --strip-leading-paths --source-maps -C module.type=commonjs -C jsc.parser.syntax=typescript -C jsc.parser.decorators=true -C jsc.target=es5";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TSC 타입 체크 명령어
|
|
9
|
+
*/
|
|
10
|
+
export const TSC_TYPE_CHECK_COMMAND = "tsc --noEmit";
|
package/src/bin/cli-wrapper.ts
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
2
|
|
|
3
|
-
import { spawnSync } from "child_process";
|
|
4
|
-
import {
|
|
5
|
-
import { existsSync
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// 환경 변수에서 ESM 여부 확인
|
|
20
|
-
if (process.env.USE_ESM === "true") {
|
|
21
|
-
return true;
|
|
3
|
+
import { spawnSync, execSync } from "child_process";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { SWC_BUILD_COMMAND, TSC_TYPE_CHECK_COMMAND } from "./build-config";
|
|
8
|
+
|
|
9
|
+
const scriptPath = resolve(__dirname, "cli.js");
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
// build 명령어는 dist 없이도 실행 가능하도록 cli.ts 외부에서 처리(Sonamu.init에서 dist 필요)
|
|
13
|
+
function build(checkTypes: boolean = false) {
|
|
14
|
+
try {
|
|
15
|
+
execSync(SWC_BUILD_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error(chalk.red("Build failed."), error);
|
|
18
|
+
process.exit(1);
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return true;
|
|
21
|
+
if (checkTypes) {
|
|
22
|
+
try {
|
|
23
|
+
console.log(chalk.blue("Checking types with tsc..."));
|
|
24
|
+
execSync(TSC_TYPE_CHECK_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(chalk.red("Type check failed."), error);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
33
29
|
}
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (args[0] === "build") {
|
|
33
|
+
console.log(chalk.blue("Building the project..."));
|
|
34
|
+
build(true);
|
|
35
|
+
console.log(chalk.green("Build completed successfully."));
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
if (args[0] === "dev:serve") {
|
|
40
|
+
build();
|
|
41
|
+
}
|
|
39
42
|
|
|
40
43
|
if (!existsSync(scriptPath)) {
|
|
41
44
|
console.error(`Error: Script not found at ${scriptPath}`);
|
|
@@ -44,7 +47,7 @@ if (!existsSync(scriptPath)) {
|
|
|
44
47
|
|
|
45
48
|
const result = spawnSync(
|
|
46
49
|
process.execPath,
|
|
47
|
-
[scriptPath, ...
|
|
50
|
+
["--no-warnings", scriptPath, ...args],
|
|
48
51
|
{
|
|
49
52
|
stdio: "inherit",
|
|
50
53
|
}
|
package/src/bin/cli.ts
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
/* Global Begin */
|
|
2
1
|
import chalk from "chalk";
|
|
3
|
-
console.log(chalk.bgBlue(`BEGIN ${new Date()}`));
|
|
4
|
-
|
|
5
2
|
import dotenv from "dotenv";
|
|
6
3
|
dotenv.config();
|
|
7
4
|
|
|
8
5
|
import path from "path";
|
|
9
6
|
import { tsicli } from "tsicli";
|
|
10
7
|
import { execSync } from "child_process";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import prettier from "prettier";
|
|
8
|
+
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
9
|
+
import { exists } from "../utils/fs-utils";
|
|
14
10
|
import process from "process";
|
|
15
|
-
import _ from "lodash";
|
|
16
11
|
import { Sonamu } from "../api";
|
|
12
|
+
import knex, { Knex } from "knex";
|
|
13
|
+
import { findApiRootPath } from "../utils/utils";
|
|
17
14
|
import { EntityManager } from "../entity/entity-manager";
|
|
18
|
-
import { Migrator } from "../
|
|
15
|
+
import { Migrator } from "../migration/migrator";
|
|
19
16
|
import { FixtureManager } from "../testing/fixture-manager";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
KnexConfig,
|
|
24
|
-
KyselyConfig,
|
|
25
|
-
SonamuKnexDBConfig,
|
|
26
|
-
SonamuKyselyDBConfig,
|
|
27
|
-
} from "../database/types";
|
|
28
|
-
import { KnexClient } from "../database/drivers/knex/client";
|
|
29
|
-
import { KyselyClient } from "../database/drivers/kysely/client";
|
|
17
|
+
// import { SWC_BUILD_COMMAND } from "./build-config";
|
|
18
|
+
import { NodemonSettings } from "nodemon";
|
|
30
19
|
|
|
31
20
|
let migrator: Migrator;
|
|
32
21
|
|
|
33
22
|
async function bootstrap() {
|
|
34
|
-
|
|
23
|
+
// dev:serve 명령어가 아닌 경우에만 Sonamu 초기화
|
|
24
|
+
if (process.argv[2] !== "dev:serve") {
|
|
25
|
+
await Sonamu.init(false, false);
|
|
26
|
+
}
|
|
35
27
|
|
|
36
28
|
await tsicli(process.argv, {
|
|
37
29
|
types: {
|
|
@@ -64,7 +56,8 @@ async function bootstrap() {
|
|
|
64
56
|
["scaffold", "view_list", "#entityId"],
|
|
65
57
|
["scaffold", "view_form", "#entityId"],
|
|
66
58
|
["ui"],
|
|
67
|
-
["
|
|
59
|
+
["dev:serve"],
|
|
60
|
+
["serve"],
|
|
68
61
|
],
|
|
69
62
|
runners: {
|
|
70
63
|
migrate_run,
|
|
@@ -83,7 +76,8 @@ async function bootstrap() {
|
|
|
83
76
|
ui,
|
|
84
77
|
// scaffold_view_list,
|
|
85
78
|
// scaffold_view_form,
|
|
86
|
-
|
|
79
|
+
"dev:serve": dev_serve,
|
|
80
|
+
serve,
|
|
87
81
|
},
|
|
88
82
|
});
|
|
89
83
|
}
|
|
@@ -91,12 +85,69 @@ bootstrap().finally(async () => {
|
|
|
91
85
|
if (migrator) {
|
|
92
86
|
await migrator.destroy();
|
|
93
87
|
}
|
|
94
|
-
await FixtureManager.
|
|
95
|
-
|
|
96
|
-
/* Global End */
|
|
97
|
-
console.log(chalk.bgBlue(`END ${new Date()}\n`));
|
|
88
|
+
await FixtureManager.destroy();
|
|
98
89
|
});
|
|
99
90
|
|
|
91
|
+
async function dev_serve() {
|
|
92
|
+
const nodemon = await import("nodemon");
|
|
93
|
+
|
|
94
|
+
const nodemonConfig = await (async () => {
|
|
95
|
+
const projectNodemonPath = path.join(findApiRootPath(), "nodemon.json");
|
|
96
|
+
const hasProjectNodemon = await exists(projectNodemonPath);
|
|
97
|
+
|
|
98
|
+
if (hasProjectNodemon) {
|
|
99
|
+
return JSON.parse(await readFile(projectNodemonPath, "utf8"));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
watch: ["src/index.ts"],
|
|
104
|
+
ignore: ["dist/**", "**/*.js", "**/*.d.ts"],
|
|
105
|
+
exec: [
|
|
106
|
+
// SWC_BUILD_COMMAND,
|
|
107
|
+
"node --no-warnings -r source-map-support/register -r dotenv/config dist/index.js",
|
|
108
|
+
].join(" && "),
|
|
109
|
+
} as NodemonSettings;
|
|
110
|
+
})();
|
|
111
|
+
nodemon.default(nodemonConfig);
|
|
112
|
+
|
|
113
|
+
// 프로세스 종료 처리
|
|
114
|
+
const cleanup = async () => {
|
|
115
|
+
await Sonamu.server?.close();
|
|
116
|
+
process.exit(0);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
process.on("SIGINT", cleanup);
|
|
120
|
+
process.on("SIGTERM", cleanup);
|
|
121
|
+
process.on("SIGUSR2", cleanup);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function serve() {
|
|
125
|
+
const distIndexPath = path.join(Sonamu.apiRootPath, "dist", "index.js");
|
|
126
|
+
|
|
127
|
+
if (!(await exists(distIndexPath))) {
|
|
128
|
+
console.log(
|
|
129
|
+
chalk.red("dist/index.js not found. Please build your project first.")
|
|
130
|
+
);
|
|
131
|
+
console.log(chalk.blue("Run: yarn sonamu build"));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { spawn } = await import("child_process");
|
|
136
|
+
const serverProcess = spawn(
|
|
137
|
+
"node",
|
|
138
|
+
["-r", "source-map-support/register", "-r", "dotenv/config", distIndexPath],
|
|
139
|
+
{
|
|
140
|
+
cwd: Sonamu.apiRootPath,
|
|
141
|
+
stdio: "inherit",
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
process.on("SIGINT", () => {
|
|
146
|
+
serverProcess.kill("SIGTERM");
|
|
147
|
+
process.exit(0);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
100
151
|
async function setupMigrator() {
|
|
101
152
|
// migrator
|
|
102
153
|
migrator = new Migrator({
|
|
@@ -149,97 +200,93 @@ async function migrate_reset() {
|
|
|
149
200
|
}
|
|
150
201
|
|
|
151
202
|
async function fixture_init() {
|
|
152
|
-
const
|
|
153
|
-
const srcConn = _db.connectionInfo;
|
|
154
|
-
|
|
203
|
+
const srcConfig = Sonamu.dbConfig.development_master;
|
|
155
204
|
const targets = [
|
|
156
205
|
{
|
|
157
206
|
label: "(REMOTE) Fixture DB",
|
|
158
|
-
|
|
207
|
+
config: Sonamu.dbConfig.fixture_remote,
|
|
159
208
|
},
|
|
160
209
|
{
|
|
161
210
|
label: "(LOCAL) Fixture DB",
|
|
162
|
-
|
|
211
|
+
config: Sonamu.dbConfig.fixture_local,
|
|
212
|
+
toSkip: (() => {
|
|
213
|
+
const remoteConn = Sonamu.dbConfig.fixture_remote
|
|
214
|
+
.connection as Knex.ConnectionConfig;
|
|
215
|
+
const localConn = Sonamu.dbConfig.fixture_local
|
|
216
|
+
.connection as Knex.ConnectionConfig;
|
|
217
|
+
return (
|
|
218
|
+
remoteConn.host === localConn.host &&
|
|
219
|
+
remoteConn.database === localConn.database
|
|
220
|
+
);
|
|
221
|
+
})(),
|
|
163
222
|
},
|
|
164
223
|
{
|
|
165
224
|
label: "(LOCAL) Testing DB",
|
|
166
|
-
|
|
225
|
+
config: Sonamu.dbConfig.test,
|
|
167
226
|
},
|
|
168
227
|
] as {
|
|
169
228
|
label: string;
|
|
170
|
-
|
|
229
|
+
config: Knex.Config;
|
|
230
|
+
toSkip?: boolean;
|
|
171
231
|
}[];
|
|
172
232
|
|
|
173
233
|
// 1. 기준DB 스키마를 덤프
|
|
174
234
|
console.log("DUMP...");
|
|
175
235
|
const dumpFilename = `/tmp/sonamu-fixture-init-${Date.now()}.sql`;
|
|
236
|
+
const srcConn = srcConfig.connection as Knex.ConnectionConfig;
|
|
176
237
|
const migrationsDump = `/tmp/sonamu-fixture-init-migrations-${Date.now()}.sql`;
|
|
177
238
|
execSync(
|
|
178
|
-
`mysqldump -h${srcConn.host} -
|
|
239
|
+
`mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
|
|
179
240
|
);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const [migrations] = await _db.raw<{ count: number }>(
|
|
185
|
-
"SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
|
|
186
|
-
[srcConn.database, migrationTable]
|
|
241
|
+
const _db = knex(srcConfig);
|
|
242
|
+
const [[migrations]] = await _db.raw(
|
|
243
|
+
"SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = 'knex_migrations'",
|
|
244
|
+
[srcConn.database]
|
|
187
245
|
);
|
|
188
246
|
if (migrations.count > 0) {
|
|
189
247
|
execSync(
|
|
190
|
-
`mysqldump -h${srcConn.host} -
|
|
248
|
+
`mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} knex_migrations knex_migrations_lock > ${migrationsDump}`
|
|
191
249
|
);
|
|
192
250
|
}
|
|
193
251
|
|
|
194
252
|
// 2. 대상DB 각각에 대하여 존재여부 확인 후 붓기
|
|
195
|
-
for await (const { label,
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
label === "(LOCAL) Fixture DB" &&
|
|
200
|
-
targets.find(
|
|
201
|
-
(t) =>
|
|
202
|
-
t.label === "(REMOTE) Fixture DB" &&
|
|
203
|
-
DB.connectionInfo[t.connKey].host === config.host &&
|
|
204
|
-
DB.connectionInfo[t.connKey].database === config.database
|
|
205
|
-
)
|
|
206
|
-
) {
|
|
253
|
+
for await (const { label, config, toSkip } of targets) {
|
|
254
|
+
const conn = config.connection as Knex.ConnectionConfig;
|
|
255
|
+
|
|
256
|
+
if (toSkip === true) {
|
|
207
257
|
console.log(chalk.red(`${label}: Skipped!`));
|
|
208
258
|
continue;
|
|
209
259
|
}
|
|
210
260
|
|
|
211
|
-
const db = (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
config.connection
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return new KyselyClient(config);
|
|
220
|
-
}
|
|
221
|
-
})();
|
|
222
|
-
|
|
223
|
-
const [row] = await db.raw(`SHOW DATABASES LIKE "${config.database}"`);
|
|
261
|
+
const db = knex({
|
|
262
|
+
...config,
|
|
263
|
+
connection: {
|
|
264
|
+
...((config.connection ?? {}) as Knex.ConnectionConfig),
|
|
265
|
+
database: undefined,
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
const [[row]] = await db.raw(`SHOW DATABASES LIKE "${conn.database}"`);
|
|
224
269
|
if (row) {
|
|
225
270
|
console.log(
|
|
226
|
-
chalk.yellow(`${label}: Database "${
|
|
271
|
+
chalk.yellow(`${label}: Database "${conn.database}" Already exists`)
|
|
227
272
|
);
|
|
228
273
|
await db.destroy();
|
|
229
274
|
continue;
|
|
230
275
|
}
|
|
231
276
|
|
|
232
277
|
console.log(`SYNC to ${label}...`);
|
|
233
|
-
const mysqlCmd = `mysql -h${
|
|
234
|
-
execSync(`${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${
|
|
235
|
-
execSync(`${mysqlCmd} -e 'CREATE DATABASE \`${
|
|
236
|
-
execSync(`${mysqlCmd} ${
|
|
237
|
-
if (
|
|
238
|
-
execSync(`${mysqlCmd} ${
|
|
278
|
+
const mysqlCmd = `mysql -h${conn.host} -u${conn.user} -p${conn.password}`;
|
|
279
|
+
execSync(`${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${conn.database}\`'`);
|
|
280
|
+
execSync(`${mysqlCmd} -e 'CREATE DATABASE \`${conn.database}\`'`);
|
|
281
|
+
execSync(`${mysqlCmd} ${conn.database} < ${dumpFilename}`);
|
|
282
|
+
if (await exists(migrationsDump)) {
|
|
283
|
+
execSync(`${mysqlCmd} ${conn.database} < ${migrationsDump}`);
|
|
239
284
|
}
|
|
240
285
|
|
|
241
286
|
await db.destroy();
|
|
242
287
|
}
|
|
288
|
+
|
|
289
|
+
await _db.destroy();
|
|
243
290
|
}
|
|
244
291
|
|
|
245
292
|
async function fixture_import(entityId: string, recordIds: number[]) {
|
|
@@ -257,11 +304,11 @@ async function fixture_sync() {
|
|
|
257
304
|
|
|
258
305
|
async function stub_practice(name: string) {
|
|
259
306
|
const practiceDir = path.join(Sonamu.apiRootPath, "src", "practices");
|
|
260
|
-
const fileNames =
|
|
307
|
+
const fileNames = await readdir(practiceDir);
|
|
261
308
|
|
|
262
|
-
const maxSeqNo = (() => {
|
|
263
|
-
if (
|
|
264
|
-
|
|
309
|
+
const maxSeqNo = await (async () => {
|
|
310
|
+
if (!(await exists(practiceDir))) {
|
|
311
|
+
await mkdir(practiceDir, { recursive: true });
|
|
265
312
|
}
|
|
266
313
|
|
|
267
314
|
const filteredSeqs = fileNames
|
|
@@ -285,25 +332,22 @@ async function stub_practice(name: string) {
|
|
|
285
332
|
const fileName = `p${currentSeqNo}-${name}.ts`;
|
|
286
333
|
const dstPath = path.join(practiceDir, fileName);
|
|
287
334
|
|
|
288
|
-
// FIXME
|
|
289
335
|
const code = [
|
|
290
|
-
`import {
|
|
336
|
+
`import { Sonamu } from "sonamu";`,
|
|
291
337
|
"",
|
|
292
338
|
`console.clear();`,
|
|
293
339
|
`console.log("${fileName}");`,
|
|
294
340
|
"",
|
|
295
|
-
`async
|
|
341
|
+
`Sonamu.runScript(async () => {`,
|
|
296
342
|
` // TODO`,
|
|
297
|
-
`}`,
|
|
298
|
-
`bootstrap().finally(async () => {`,
|
|
299
|
-
`await BaseModel.destroy();`,
|
|
300
343
|
`});`,
|
|
344
|
+
"",
|
|
301
345
|
].join("\n");
|
|
302
|
-
|
|
346
|
+
await writeFile(dstPath, code);
|
|
303
347
|
|
|
304
348
|
execSync(`code ${dstPath}`);
|
|
305
349
|
|
|
306
|
-
const runCode = `yarn node -r source-map-support/register dist/practices/${fileName.replace(
|
|
350
|
+
const runCode = `yarn node -r dotenv/config -r source-map-support/register dist/practices/${fileName.replace(
|
|
307
351
|
".ts",
|
|
308
352
|
".js"
|
|
309
353
|
)}`;
|
|
@@ -329,10 +373,20 @@ async function scaffold_model_test(entityId: string) {
|
|
|
329
373
|
|
|
330
374
|
async function ui() {
|
|
331
375
|
try {
|
|
376
|
+
type StartServersOptions = {
|
|
377
|
+
projectName: string;
|
|
378
|
+
apiRootPath: string;
|
|
379
|
+
port: number;
|
|
380
|
+
};
|
|
332
381
|
const sonamuUI: {
|
|
333
|
-
startServers: (
|
|
382
|
+
startServers: (options: StartServersOptions) => void;
|
|
334
383
|
} = await import("@sonamu-kit/ui" as string);
|
|
335
|
-
sonamuUI.startServers(
|
|
384
|
+
sonamuUI.startServers({
|
|
385
|
+
projectName:
|
|
386
|
+
Sonamu.config.projectName ?? path.basename(Sonamu.apiRootPath),
|
|
387
|
+
apiRootPath: Sonamu.apiRootPath,
|
|
388
|
+
port: Sonamu.config.ui?.port ?? 57000,
|
|
389
|
+
});
|
|
336
390
|
} catch (e: unknown) {
|
|
337
391
|
if (e instanceof Error && e.message.includes("isn't declared")) {
|
|
338
392
|
console.log(`You need to install ${chalk.blue(`@sonamu-kit/ui`)} first.`);
|
|
@@ -341,120 +395,3 @@ async function ui() {
|
|
|
341
395
|
throw e;
|
|
342
396
|
}
|
|
343
397
|
}
|
|
344
|
-
|
|
345
|
-
async function smd_migration() {
|
|
346
|
-
await SMDManager.autoload();
|
|
347
|
-
const smdIds = SMDManager.getAllIds();
|
|
348
|
-
|
|
349
|
-
function enumLabelsToEntityEnums(
|
|
350
|
-
entityId: string,
|
|
351
|
-
enumLabels: {
|
|
352
|
-
[enumName: string]: { [name: string]: { ko: string } };
|
|
353
|
-
}
|
|
354
|
-
): { [enumName: string]: { [name: string]: string } } {
|
|
355
|
-
return Object.fromEntries(
|
|
356
|
-
Object.entries(enumLabels).map(([enumLabelName, enumLabel]) => {
|
|
357
|
-
const enumName =
|
|
358
|
-
entityId + inflection.camelize(enumLabelName.toLowerCase(), false);
|
|
359
|
-
return [
|
|
360
|
-
enumName,
|
|
361
|
-
Object.fromEntries(
|
|
362
|
-
Object.entries(enumLabel).map(([name, { ko }]) => [name, ko])
|
|
363
|
-
),
|
|
364
|
-
];
|
|
365
|
-
})
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
for await (const smdId of smdIds) {
|
|
369
|
-
const smd = SMDManager.get(smdId);
|
|
370
|
-
const entityJson = {
|
|
371
|
-
id: smd.id,
|
|
372
|
-
...(smd.parentId && { parentId: smd.parentId }),
|
|
373
|
-
title: smd.title,
|
|
374
|
-
props: smd.props,
|
|
375
|
-
indexes: smd.indexes,
|
|
376
|
-
subsets: smd.subsets,
|
|
377
|
-
enums: enumLabelsToEntityEnums(smd.id, smd.enumLabels),
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
const parentNames = SMDManager.getNamesFromId(smd.parentId ?? smd.id);
|
|
381
|
-
const names = SMDManager.getNamesFromId(smd.id);
|
|
382
|
-
const dstPath = path.join(
|
|
383
|
-
Sonamu.apiRootPath,
|
|
384
|
-
"src",
|
|
385
|
-
"application",
|
|
386
|
-
parentNames.fs,
|
|
387
|
-
`${names.fs}.entity.json`
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
const formatted = await prettier.format(JSON.stringify(entityJson), {
|
|
391
|
-
parser: "json",
|
|
392
|
-
});
|
|
393
|
-
fs.writeFileSync(dstPath, formatted);
|
|
394
|
-
console.log(chalk.blue(`CREATED: ${dstPath}`));
|
|
395
|
-
|
|
396
|
-
// smd.ts, enums.ts, genereated.ts 삭제 (트랜스파일 된 js파일도 삭제)
|
|
397
|
-
const srcSmdPath = path.join(
|
|
398
|
-
Sonamu.apiRootPath,
|
|
399
|
-
"src",
|
|
400
|
-
"application",
|
|
401
|
-
parentNames.fs,
|
|
402
|
-
`${names.fs}.smd.ts`
|
|
403
|
-
);
|
|
404
|
-
const dstSmdPath = srcSmdPath
|
|
405
|
-
.replace("/src/", "/dist/")
|
|
406
|
-
.replace(/\.ts$/, ".js");
|
|
407
|
-
const srcEnumsPath = path.join(
|
|
408
|
-
Sonamu.apiRootPath,
|
|
409
|
-
"src",
|
|
410
|
-
"application",
|
|
411
|
-
parentNames.fs,
|
|
412
|
-
`${names.fs}.enums.ts`
|
|
413
|
-
);
|
|
414
|
-
const dstEnumsPath = srcEnumsPath
|
|
415
|
-
.replace("/src/", "/dist/")
|
|
416
|
-
.replace(/\.ts$/, ".js");
|
|
417
|
-
const srcGeneratedPath = path.join(
|
|
418
|
-
Sonamu.apiRootPath,
|
|
419
|
-
"src",
|
|
420
|
-
"application",
|
|
421
|
-
parentNames.fs,
|
|
422
|
-
`${names.fs}.generated.ts`
|
|
423
|
-
);
|
|
424
|
-
const dstGeneratedPath = srcGeneratedPath
|
|
425
|
-
.replace("/src/", "/dist/")
|
|
426
|
-
.replace(/\.ts$/, ".js");
|
|
427
|
-
|
|
428
|
-
[
|
|
429
|
-
srcSmdPath,
|
|
430
|
-
dstSmdPath,
|
|
431
|
-
srcEnumsPath,
|
|
432
|
-
dstEnumsPath,
|
|
433
|
-
...Sonamu.config.sync.targets.map((target) =>
|
|
434
|
-
srcEnumsPath
|
|
435
|
-
.replace(Sonamu.apiRootPath, path.join(Sonamu.appRootPath, target))
|
|
436
|
-
.replace("/src/application/", "/src/services/")
|
|
437
|
-
),
|
|
438
|
-
srcGeneratedPath,
|
|
439
|
-
dstGeneratedPath,
|
|
440
|
-
].map((p) => {
|
|
441
|
-
if (fs.existsSync(p) === false) {
|
|
442
|
-
console.log(chalk.yellow(`NOT FOUND: ${p}`));
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
fs.unlinkSync(p);
|
|
446
|
-
console.log(chalk.red(`DELETED: ${p}`));
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Entity로 reload
|
|
451
|
-
console.log("Entity로 다시 로드합니다.");
|
|
452
|
-
EntityManager.isAutoloaded = false;
|
|
453
|
-
await EntityManager.autoload();
|
|
454
|
-
|
|
455
|
-
// Entity를 통해 generated.ts 재생성
|
|
456
|
-
const entityIds = EntityManager.getAllParentIds();
|
|
457
|
-
for await (const entityId of entityIds) {
|
|
458
|
-
await Sonamu.syncer.generateTemplate("generated", { entityId });
|
|
459
|
-
}
|
|
460
|
-
}
|
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Knex } from "knex";
|
|
7
|
-
import { DB } from "./db";
|
|
8
|
-
import { KnexClient } from "./drivers/knex/client";
|
|
9
|
-
import { KyselyClient } from "./drivers/kysely/client";
|
|
10
|
-
import { Transaction } from "kysely";
|
|
11
|
-
import { Database } from "./types";
|
|
12
7
|
|
|
13
8
|
export type RowWithId<Id extends string> = {
|
|
14
9
|
[key in Id]: any;
|
|
@@ -24,12 +19,12 @@ export type RowWithId<Id extends string> = {
|
|
|
24
19
|
* @param trx
|
|
25
20
|
*/
|
|
26
21
|
export async function batchUpdate<Id extends string>(
|
|
27
|
-
|
|
22
|
+
knex: Knex,
|
|
28
23
|
tableName: string,
|
|
29
24
|
ids: Id[],
|
|
30
25
|
rows: RowWithId<Id>[],
|
|
31
26
|
chunkSize = 50,
|
|
32
|
-
trx: Knex.Transaction |
|
|
27
|
+
trx: Knex.Transaction | null = null
|
|
33
28
|
) {
|
|
34
29
|
const chunks: RowWithId<Id>[][] = [];
|
|
35
30
|
for (let i = 0; i < rows.length; i += chunkSize) {
|
|
@@ -38,18 +33,18 @@ export async function batchUpdate<Id extends string>(
|
|
|
38
33
|
|
|
39
34
|
const executeUpdate = async (
|
|
40
35
|
chunk: RowWithId<Id>[],
|
|
41
|
-
transaction:
|
|
36
|
+
transaction: Knex.Transaction
|
|
42
37
|
) => {
|
|
43
|
-
const sql = generateBatchUpdateSQL(
|
|
44
|
-
return
|
|
38
|
+
const sql = generateBatchUpdateSQL(knex, tableName, chunk, ids);
|
|
39
|
+
return knex.raw(sql).transacting(transaction);
|
|
45
40
|
};
|
|
46
41
|
|
|
47
42
|
if (trx) {
|
|
48
43
|
for (const chunk of chunks) {
|
|
49
|
-
await executeUpdate(chunk,
|
|
44
|
+
await executeUpdate(chunk, trx);
|
|
50
45
|
}
|
|
51
46
|
} else {
|
|
52
|
-
await
|
|
47
|
+
await knex.transaction(async (newTrx) => {
|
|
53
48
|
for (const chunk of chunks) {
|
|
54
49
|
await executeUpdate(chunk, newTrx);
|
|
55
50
|
}
|
|
@@ -75,7 +70,7 @@ function generateKeySetFromData(data: Record<string, any>[]) {
|
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
function generateBatchUpdateSQL<Id extends string>(
|
|
78
|
-
db:
|
|
73
|
+
db: Knex,
|
|
79
74
|
tableName: string,
|
|
80
75
|
data: Record<string, any>[],
|
|
81
76
|
identifiers: Id[]
|
|
@@ -117,10 +112,10 @@ function generateBatchUpdateSQL<Id extends string>(
|
|
|
117
112
|
data.map((row) => row[col])
|
|
118
113
|
);
|
|
119
114
|
|
|
120
|
-
const sql = db.
|
|
115
|
+
const sql = db.raw(
|
|
121
116
|
`UPDATE \`${tableName}\` SET ${cases.join(", ")} WHERE ${whereInClauses}`,
|
|
122
117
|
[...bindings, ...whereInBindings]
|
|
123
118
|
);
|
|
124
119
|
|
|
125
|
-
return sql;
|
|
120
|
+
return sql.toQuery();
|
|
126
121
|
}
|