sonamu 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.swcrc.project-default +18 -0
- package/bin/cli.js +24 -0
- package/dist/ai/agents/agent.d.ts +11 -0
- package/dist/ai/agents/agent.d.ts.map +1 -0
- package/dist/ai/agents/agent.js +65 -0
- package/dist/ai/agents/index.d.ts +3 -0
- package/dist/ai/agents/index.d.ts.map +1 -0
- package/dist/ai/agents/index.js +4 -0
- package/dist/ai/agents/types.d.ts +43 -0
- package/dist/ai/agents/types.d.ts.map +1 -0
- package/dist/ai/agents/types.js +3 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +3 -0
- package/dist/ai/providers/rtzr/api.d.ts +22 -0
- package/dist/ai/providers/rtzr/api.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/api.js +28 -0
- package/dist/ai/providers/rtzr/error.d.ts +18 -0
- package/dist/ai/providers/rtzr/error.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/error.js +29 -0
- package/dist/ai/providers/rtzr/index.d.ts +5 -0
- package/dist/ai/providers/rtzr/index.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/index.js +6 -0
- package/dist/ai/providers/rtzr/model.d.ts +52 -0
- package/dist/ai/providers/rtzr/model.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/model.js +137 -0
- package/dist/ai/providers/rtzr/options.d.ts +7 -0
- package/dist/ai/providers/rtzr/options.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/options.js +47 -0
- package/dist/ai/providers/rtzr/provider.d.ts +18 -0
- package/dist/ai/providers/rtzr/provider.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/provider.js +54 -0
- package/dist/ai/providers/rtzr/utils.d.ts +19 -0
- package/dist/ai/providers/rtzr/utils.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/utils.js +88 -0
- package/dist/api/base-frame.d.ts +2 -2
- package/dist/api/base-frame.d.ts.map +1 -1
- package/dist/api/base-frame.js +2 -1
- package/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +6 -1
- package/dist/api/code-converters.d.ts +58 -14
- package/dist/api/code-converters.d.ts.map +1 -1
- package/dist/api/code-converters.js +178 -409
- package/dist/api/config.d.ts +27 -13
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +19 -26
- package/dist/api/context.d.ts +4 -3
- package/dist/api/context.d.ts.map +1 -1
- package/dist/api/context.js +1 -1
- package/dist/api/decorators.d.ts +20 -6
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +111 -18
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -3
- package/dist/api/sonamu.d.ts +7 -7
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +83 -51
- package/dist/api/validator.d.ts +6 -0
- package/dist/api/validator.d.ts.map +1 -0
- package/dist/api/validator.js +81 -0
- package/dist/bin/build-config.d.ts +5 -1
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +5 -2
- package/dist/bin/cli.js +165 -64
- package/dist/bin/loader-register.d.ts +2 -0
- package/dist/bin/loader-register.d.ts.map +1 -0
- package/dist/bin/loader-register.js +34 -0
- package/dist/database/_batch_update.d.ts +5 -3
- package/dist/database/_batch_update.d.ts.map +1 -1
- package/dist/database/_batch_update.js +30 -13
- package/dist/database/base-model.d.ts +96 -10
- package/dist/database/base-model.d.ts.map +1 -1
- package/dist/database/base-model.js +232 -89
- package/dist/database/base-model.types.d.ts +93 -0
- package/dist/database/base-model.types.d.ts.map +1 -0
- package/dist/database/base-model.types.js +10 -0
- package/dist/database/code-generator.d.ts +1 -1
- package/dist/database/code-generator.d.ts.map +1 -1
- package/dist/database/code-generator.js +11 -10
- package/dist/database/db.d.ts +5 -6
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +22 -25
- package/dist/database/puri-subset.test-d.js +81 -0
- package/dist/database/puri-subset.types.d.ts +123 -0
- package/dist/database/puri-subset.types.d.ts.map +1 -0
- package/dist/database/puri-subset.types.js +16 -0
- package/dist/database/puri-wrapper.d.ts +13 -11
- package/dist/database/puri-wrapper.d.ts.map +1 -1
- package/dist/database/puri-wrapper.js +2 -2
- package/dist/database/puri.d.ts +25 -14
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +83 -21
- package/dist/database/puri.types.d.ts +21 -7
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +4 -1
- package/dist/database/transaction-context.d.ts +1 -1
- package/dist/database/transaction-context.d.ts.map +1 -1
- package/dist/database/transaction-context.js +1 -1
- package/dist/database/upsert-builder.d.ts +9 -3
- package/dist/database/upsert-builder.d.ts.map +1 -1
- package/dist/database/upsert-builder.js +228 -78
- package/dist/entity/entity-manager.d.ts +165 -2
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +26 -10
- package/dist/entity/entity.d.ts +5 -3
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +153 -54
- package/dist/exceptions/error-handler.d.ts +1 -1
- package/dist/exceptions/error-handler.d.ts.map +1 -1
- package/dist/exceptions/error-handler.js +1 -1
- package/dist/exceptions/so-exceptions.d.ts +1 -1
- package/dist/exceptions/so-exceptions.d.ts.map +1 -1
- package/dist/exceptions/so-exceptions.js +1 -1
- package/dist/file-storage/driver.d.ts +1 -1
- package/dist/file-storage/driver.d.ts.map +1 -1
- package/dist/file-storage/driver.js +1 -1
- package/dist/file-storage/file-storage.js +2 -2
- package/dist/index.d.ts +18 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -13
- package/dist/migration/code-generation.d.ts +1 -1
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +123 -67
- package/dist/migration/migration-set.d.ts +2 -10
- package/dist/migration/migration-set.d.ts.map +1 -1
- package/dist/migration/migration-set.js +67 -218
- package/dist/migration/migrator.d.ts +24 -73
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +121 -301
- package/dist/migration/postgresql-schema-reader.d.ts +51 -0
- package/dist/migration/postgresql-schema-reader.d.ts.map +1 -0
- package/dist/migration/postgresql-schema-reader.js +245 -0
- package/dist/migration/types.d.ts +6 -38
- package/dist/migration/types.d.ts.map +1 -1
- package/dist/migration/types.js +1 -1
- package/dist/naite/messaging-types.d.ts +43 -0
- package/dist/naite/messaging-types.d.ts.map +1 -0
- package/dist/naite/messaging-types.js +7 -0
- package/dist/naite/naite-reporter.d.ts +41 -0
- package/dist/naite/naite-reporter.d.ts.map +1 -0
- package/dist/naite/naite-reporter.js +102 -0
- package/dist/naite/naite.d.ts +91 -8
- package/dist/naite/naite.d.ts.map +1 -1
- package/dist/naite/naite.js +285 -41
- package/dist/stream/sse.d.ts +2 -2
- package/dist/stream/sse.d.ts.map +1 -1
- package/dist/stream/sse.js +1 -1
- package/dist/syncer/api-parser.d.ts +3 -13
- package/dist/syncer/api-parser.d.ts.map +1 -1
- package/dist/syncer/api-parser.js +67 -56
- package/dist/syncer/checksum.d.ts +2 -2
- package/dist/syncer/checksum.d.ts.map +1 -1
- package/dist/syncer/checksum.js +11 -11
- package/dist/syncer/code-generator.d.ts +3 -3
- package/dist/syncer/code-generator.d.ts.map +1 -1
- package/dist/syncer/code-generator.js +37 -17
- package/dist/syncer/entity-operations.d.ts +2 -2
- package/dist/syncer/entity-operations.d.ts.map +1 -1
- package/dist/syncer/entity-operations.js +9 -8
- package/dist/syncer/file-patterns.d.ts +1 -1
- package/dist/syncer/file-patterns.d.ts.map +1 -1
- package/dist/syncer/file-patterns.js +1 -1
- package/dist/syncer/index.d.ts +4 -4
- package/dist/syncer/index.d.ts.map +1 -1
- package/dist/syncer/index.js +5 -5
- package/dist/syncer/module-loader.d.ts +4 -4
- package/dist/syncer/module-loader.d.ts.map +1 -1
- package/dist/syncer/module-loader.js +17 -12
- package/dist/syncer/syncer.d.ts +31 -24
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +92 -45
- package/dist/template/entity-converter.d.ts +1 -1
- package/dist/template/entity-converter.d.ts.map +1 -1
- package/dist/template/entity-converter.js +15 -8
- package/dist/template/helpers.d.ts +2 -2
- package/dist/template/helpers.d.ts.map +1 -1
- package/dist/template/helpers.js +3 -3
- package/dist/template/implementations/entity.template.d.ts +2 -2
- package/dist/template/implementations/entity.template.d.ts.map +1 -1
- package/dist/template/implementations/entity.template.js +4 -5
- package/dist/template/implementations/generated.template.d.ts +2 -3
- package/dist/template/implementations/generated.template.d.ts.map +1 -1
- package/dist/template/implementations/generated.template.js +46 -29
- package/dist/template/implementations/generated_http.template.d.ts +2 -3
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -1
- package/dist/template/implementations/generated_http.template.js +9 -9
- package/dist/template/implementations/generated_sso.template.d.ts +3 -4
- package/dist/template/implementations/generated_sso.template.d.ts.map +1 -1
- package/dist/template/implementations/generated_sso.template.js +54 -25
- package/dist/template/implementations/init_types.template.d.ts +2 -2
- package/dist/template/implementations/init_types.template.d.ts.map +1 -1
- package/dist/template/implementations/init_types.template.js +2 -2
- package/dist/template/implementations/model.template.d.ts +2 -2
- package/dist/template/implementations/model.template.d.ts.map +1 -1
- package/dist/template/implementations/model.template.js +47 -37
- package/dist/template/implementations/model_test.template.d.ts +2 -2
- package/dist/template/implementations/model_test.template.d.ts.map +1 -1
- package/dist/template/implementations/model_test.template.js +2 -2
- package/dist/template/implementations/service.template.d.ts +4 -4
- package/dist/template/implementations/service.template.d.ts.map +1 -1
- package/dist/template/implementations/service.template.js +24 -16
- package/dist/template/implementations/view_enums_buttonset.template.d.ts +2 -2
- package/dist/template/implementations/view_enums_buttonset.template.d.ts.map +1 -1
- package/dist/template/implementations/view_enums_buttonset.template.js +1 -1
- package/dist/template/implementations/view_enums_dropdown.template.d.ts +2 -2
- package/dist/template/implementations/view_enums_dropdown.template.d.ts.map +1 -1
- package/dist/template/implementations/view_enums_dropdown.template.js +2 -2
- package/dist/template/implementations/view_enums_select.template.d.ts +2 -2
- package/dist/template/implementations/view_enums_select.template.d.ts.map +1 -1
- package/dist/template/implementations/view_enums_select.template.js +2 -2
- package/dist/template/implementations/view_form.template.d.ts +2 -2
- package/dist/template/implementations/view_form.template.d.ts.map +1 -1
- package/dist/template/implementations/view_form.template.js +4 -4
- package/dist/template/implementations/view_id_all_select.template.d.ts +2 -2
- package/dist/template/implementations/view_id_all_select.template.d.ts.map +1 -1
- package/dist/template/implementations/view_id_all_select.template.js +1 -1
- package/dist/template/implementations/view_id_async_select.template.d.ts +2 -2
- package/dist/template/implementations/view_id_async_select.template.d.ts.map +1 -1
- package/dist/template/implementations/view_id_async_select.template.js +1 -1
- package/dist/template/implementations/view_list.template.d.ts +2 -2
- package/dist/template/implementations/view_list.template.d.ts.map +1 -1
- package/dist/template/implementations/view_list.template.js +29 -19
- package/dist/template/implementations/view_list_columns.template.d.ts +3 -3
- package/dist/template/implementations/view_list_columns.template.d.ts.map +1 -1
- package/dist/template/implementations/view_list_columns.template.js +1 -1
- package/dist/template/implementations/view_search_input.template.d.ts +2 -2
- package/dist/template/implementations/view_search_input.template.d.ts.map +1 -1
- package/dist/template/implementations/view_search_input.template.js +1 -1
- package/dist/template/index.d.ts +4 -2
- package/dist/template/index.d.ts.map +1 -1
- package/dist/template/index.js +5 -3
- package/dist/template/template-manager.d.ts +56 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +125 -0
- package/dist/template/template-types.d.ts +16 -0
- package/dist/template/template-types.d.ts.map +1 -0
- package/dist/template/template-types.js +7 -0
- package/dist/template/template.d.ts +12 -2
- package/dist/template/template.d.ts.map +1 -1
- package/dist/template/template.js +19 -6
- package/dist/template/zod-converter.d.ts +40 -7
- package/dist/template/zod-converter.d.ts.map +1 -1
- package/dist/template/zod-converter.js +341 -58
- package/dist/testing/_relation-graph.d.ts +1 -1
- package/dist/testing/_relation-graph.d.ts.map +1 -1
- package/dist/testing/_relation-graph.js +12 -3
- package/dist/testing/fixture-manager.d.ts +42 -11
- package/dist/testing/fixture-manager.d.ts.map +1 -1
- package/dist/testing/fixture-manager.js +338 -236
- package/dist/types/types.d.ts +709 -104
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +309 -52
- package/dist/typings/knex.d.js +2 -2
- package/dist/utils/async-utils.d.ts.map +1 -1
- package/dist/utils/async-utils.js +3 -3
- package/dist/utils/console-util.js +1 -1
- package/dist/utils/controller.d.ts +1 -0
- package/dist/utils/controller.d.ts.map +1 -1
- package/dist/utils/controller.js +4 -1
- package/dist/utils/esm-utils.d.ts +0 -6
- package/dist/utils/esm-utils.d.ts.map +1 -1
- package/dist/utils/esm-utils.js +2 -9
- package/dist/utils/formatter.d.ts +3 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +110 -0
- package/dist/utils/fs-utils.d.ts +1 -1
- package/dist/utils/fs-utils.d.ts.map +1 -1
- package/dist/utils/fs-utils.js +1 -1
- package/dist/utils/lodash-able.d.ts.map +1 -1
- package/dist/utils/lodash-able.js +1 -1
- package/dist/utils/object-utils.d.ts +44 -0
- package/dist/utils/object-utils.d.ts.map +1 -0
- package/dist/utils/object-utils.js +191 -0
- package/dist/utils/path-utils.d.ts +1 -1
- package/dist/utils/path-utils.d.ts.map +1 -1
- package/dist/utils/path-utils.js +3 -3
- package/dist/utils/process-utils.js +1 -1
- package/dist/utils/sql-parser.d.ts +5 -1
- package/dist/utils/sql-parser.d.ts.map +1 -1
- package/dist/utils/sql-parser.js +14 -3
- package/dist/utils/type-utils.d.ts +23 -0
- package/dist/utils/type-utils.d.ts.map +1 -0
- package/dist/utils/type-utils.js +45 -0
- package/dist/utils/utils.d.ts +7 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +44 -5
- package/dist/utils/zod-error.d.ts +1 -1
- package/dist/utils/zod-error.d.ts.map +1 -1
- package/dist/utils/zod-error.js +1 -1
- package/package.json +54 -29
- package/src/ai/agents/agent.ts +87 -0
- package/src/ai/agents/index.ts +2 -0
- package/src/ai/agents/types.ts +47 -0
- package/src/ai/index.ts +1 -0
- package/src/ai/providers/rtzr/api.ts +37 -0
- package/src/ai/providers/rtzr/error.ts +34 -0
- package/src/ai/providers/rtzr/index.ts +4 -0
- package/src/ai/providers/rtzr/model.ts +201 -0
- package/src/ai/providers/rtzr/options.ts +49 -0
- package/src/ai/providers/rtzr/provider.ts +91 -0
- package/src/ai/providers/rtzr/utils.ts +127 -0
- package/src/api/base-frame.ts +4 -2
- package/src/api/caster.ts +17 -23
- package/src/api/code-converters.ts +176 -533
- package/src/api/config.ts +39 -56
- package/src/api/context.ts +7 -18
- package/src/api/decorators.ts +175 -46
- package/src/api/index.ts +2 -2
- package/src/api/sonamu.ts +133 -124
- package/src/api/validator.ts +83 -0
- package/src/bin/build-config.ts +7 -1
- package/src/bin/cli.ts +192 -110
- package/src/bin/loader-register.ts +38 -0
- package/src/database/_batch_update.ts +46 -31
- package/src/database/base-model.ts +390 -182
- package/src/database/base-model.types.ts +155 -0
- package/src/database/code-generator.ts +13 -32
- package/src/database/db.ts +36 -50
- package/src/database/puri-subset.test-d.ts +471 -0
- package/src/database/puri-subset.types.ts +195 -0
- package/src/database/puri-wrapper.ts +58 -67
- package/src/database/puri.ts +182 -126
- package/src/database/puri.types.ts +64 -31
- package/src/database/transaction-context.ts +1 -1
- package/src/database/upsert-builder.ts +262 -132
- package/src/entity/entity-manager.ts +36 -28
- package/src/entity/entity.ts +330 -249
- package/src/exceptions/error-handler.ts +3 -3
- package/src/exceptions/so-exceptions.ts +11 -11
- package/src/file-storage/driver.ts +5 -5
- package/src/file-storage/file-storage.ts +2 -2
- package/src/index.ts +18 -12
- package/src/migration/code-generation.ts +185 -172
- package/src/migration/migration-set.ts +80 -293
- package/src/migration/migrator.ts +182 -425
- package/src/migration/mysql-schema-reader.ts.txt +272 -0
- package/src/migration/postgresql-schema-reader.ts +310 -0
- package/src/migration/types.ts +6 -39
- package/src/naite/messaging-types.ts +51 -0
- package/src/naite/naite-reporter.ts +128 -0
- package/src/naite/naite.ts +378 -33
- package/src/shared/web.shared.ts.txt +20 -24
- package/src/stream/sse.ts +5 -5
- package/src/syncer/api-parser.ts +52 -69
- package/src/syncer/checksum.ts +25 -37
- package/src/syncer/code-generator.ts +58 -62
- package/src/syncer/entity-operations.ts +12 -15
- package/src/syncer/file-patterns.ts +2 -2
- package/src/syncer/index.ts +4 -4
- package/src/syncer/module-loader.ts +28 -25
- package/src/syncer/syncer.ts +155 -162
- package/src/template/entity-converter.ts +18 -27
- package/src/template/helpers.ts +8 -11
- package/src/template/implementations/entity.template.ts +6 -6
- package/src/template/implementations/generated.template.ts +99 -99
- package/src/template/implementations/generated_http.template.ts +21 -54
- package/src/template/implementations/generated_sso.template.ts +78 -65
- package/src/template/implementations/init_types.template.ts +4 -6
- package/src/template/implementations/model.template.ts +47 -38
- package/src/template/implementations/model_test.template.ts +3 -3
- package/src/template/implementations/service.template.ts +56 -80
- package/src/template/implementations/view_enums_buttonset.template.ts +2 -2
- package/src/template/implementations/view_enums_dropdown.template.ts +4 -4
- package/src/template/implementations/view_enums_select.template.ts +3 -3
- package/src/template/implementations/view_form.template.ts +34 -75
- package/src/template/implementations/view_id_all_select.template.ts +2 -2
- package/src/template/implementations/view_id_async_select.template.ts +9 -23
- package/src/template/implementations/view_list.template.ts +54 -95
- package/src/template/implementations/view_list_columns.template.ts +4 -10
- package/src/template/implementations/view_search_input.template.ts +2 -2
- package/src/template/index.ts +4 -2
- package/src/template/template-manager.ts +166 -0
- package/src/template/template-types.ts +16 -0
- package/src/template/template.ts +29 -10
- package/src/template/zod-converter.ts +407 -101
- package/src/testing/_relation-graph.ts +18 -11
- package/src/testing/fixture-manager.ts +468 -362
- package/src/types/types.ts +516 -248
- package/src/typings/knex.d.ts +7 -9
- package/src/utils/async-utils.ts +8 -12
- package/src/utils/console-util.ts +1 -1
- package/src/utils/controller.ts +3 -0
- package/src/utils/esm-utils.ts +8 -18
- package/src/utils/formatter.ts +109 -0
- package/src/utils/fs-utils.ts +1 -1
- package/src/utils/lodash-able.ts +1 -4
- package/src/utils/object-utils.ts +217 -0
- package/src/utils/path-utils.ts +3 -6
- package/src/utils/process-utils.ts +1 -1
- package/src/utils/sql-parser.ts +23 -5
- package/src/utils/type-utils.ts +83 -0
- package/src/utils/utils.ts +58 -9
- package/src/utils/zod-error.ts +3 -3
- package/dist/bin/cli-wrapper.d.ts +0 -3
- package/dist/bin/cli-wrapper.d.ts.map +0 -1
- package/dist/bin/cli-wrapper.js +0 -72
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +0 -2
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +0 -1
- package/dist/database/knex-plugins/knex-on-duplicate-update.js +0 -39
- package/dist/entity/entity-utils.d.ts +0 -61
- package/dist/entity/entity-utils.d.ts.map +0 -1
- package/dist/entity/entity-utils.js +0 -210
- package/src/bin/cli-wrapper.ts +0 -82
- package/src/database/knex-plugins/knex-on-duplicate-update.ts +0 -45
- package/src/entity/entity-utils.ts +0 -291
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import assert from "assert";
|
|
1
2
|
import inflection from "inflection";
|
|
2
|
-
import
|
|
3
|
-
import { TemplateOptions } from "../../types/types";
|
|
4
|
-
import { EntityNamesRecord } from "../../entity/entity-manager";
|
|
5
|
-
import { ApiParamType, ApiParam } from "../../types/types";
|
|
3
|
+
import { diff, group, sort, unique } from "radashi";
|
|
6
4
|
import {
|
|
7
|
-
apiParamTypeToTsType,
|
|
8
5
|
apiParamToTsCode,
|
|
9
|
-
unwrapPromiseOnce,
|
|
10
|
-
zodTypeToTsTypeDef,
|
|
11
6
|
apiParamToTsCodeAsObject,
|
|
7
|
+
apiParamTypeToTsType,
|
|
8
|
+
unwrapPromiseOnce,
|
|
12
9
|
} from "../../api/code-converters";
|
|
13
|
-
import { ExtendedApi } from "../../api/decorators";
|
|
14
|
-
import { Template } from "../template";
|
|
10
|
+
import type { ExtendedApi } from "../../api/decorators";
|
|
15
11
|
import { Sonamu } from "../../api/sonamu";
|
|
12
|
+
import type { EntityNamesRecord } from "../../entity/entity-manager";
|
|
13
|
+
import { Naite } from "../../naite/naite";
|
|
14
|
+
import type { TemplateOptions } from "../../types/types";
|
|
15
|
+
import { type ApiParam, ApiParamType } from "../../types/types";
|
|
16
|
+
import { assertDefined } from "../../utils/utils";
|
|
17
|
+
import { Template } from "../template";
|
|
18
|
+
import { zodTypeToTsTypeDef } from "../zod-converter";
|
|
16
19
|
|
|
17
20
|
export class Template__service extends Template {
|
|
18
21
|
constructor() {
|
|
@@ -27,36 +30,32 @@ export class Template__service extends Template {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
render({ namesRecord }: TemplateOptions["service"]) {
|
|
33
|
+
Naite.t("render", { namesRecord });
|
|
34
|
+
|
|
30
35
|
const {
|
|
31
36
|
syncer: { apis },
|
|
32
37
|
} = Sonamu;
|
|
33
38
|
|
|
34
|
-
const apisForThisModel = apis.filter(
|
|
35
|
-
(api) => api.modelName === `${namesRecord.capital}Model`
|
|
36
|
-
);
|
|
39
|
+
const apisForThisModel = apis.filter((api) => api.modelName === `${namesRecord.capital}Model`);
|
|
37
40
|
|
|
38
41
|
// 서비스 TypeSource
|
|
39
42
|
const { lines, importKeys } = this.getTypeSource(apisForThisModel);
|
|
40
43
|
|
|
41
44
|
// AxiosProgressEvent 있는지 확인
|
|
42
45
|
const hasAxiosProgressEvent = apis.find((api) =>
|
|
43
|
-
(api.options.clients ?? []).includes("axios-multipart")
|
|
46
|
+
(api.options.clients ?? []).includes("axios-multipart"),
|
|
44
47
|
);
|
|
45
48
|
|
|
46
49
|
return {
|
|
47
50
|
...this.getTargetAndPath(namesRecord),
|
|
48
51
|
body: lines.join("\n"),
|
|
49
|
-
importKeys: importKeys.filter(
|
|
50
|
-
(key) => ["ListResult"].includes(key) === false
|
|
51
|
-
),
|
|
52
|
+
importKeys: importKeys.filter((key) => ["ListResult"].includes(key) === false),
|
|
52
53
|
customHeaders: [
|
|
53
54
|
`import { z } from 'zod';`,
|
|
54
55
|
`import qs from "qs";`,
|
|
55
|
-
`import useSWR, { SWRResponse } from "swr";`,
|
|
56
|
+
`import useSWR, { type SWRResponse } from "swr";`,
|
|
56
57
|
`import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher, EventHandlers, SSEStreamOptions, useSSEStream } from '../sonamu.shared';`,
|
|
57
|
-
...(hasAxiosProgressEvent
|
|
58
|
-
? [`import { AxiosProgressEvent } from 'axios';`]
|
|
59
|
-
: []),
|
|
58
|
+
...(hasAxiosProgressEvent ? [`import { type AxiosProgressEvent } from 'axios';`] : []),
|
|
60
59
|
],
|
|
61
60
|
};
|
|
62
61
|
}
|
|
@@ -70,10 +69,11 @@ export class Template__service extends Template {
|
|
|
70
69
|
// 제네릭에서 선언한 타입, importKeys에서 제외 필요
|
|
71
70
|
let typeParamNames: string[] = [];
|
|
72
71
|
|
|
73
|
-
const groups =
|
|
72
|
+
const groups = group(apis, (api) => api.modelName);
|
|
74
73
|
const body = Object.keys(groups)
|
|
75
74
|
.map((modelName) => {
|
|
76
75
|
const methods = groups[modelName];
|
|
76
|
+
assert(methods);
|
|
77
77
|
const methodCodes = methods
|
|
78
78
|
.map((api) => {
|
|
79
79
|
// 컨텍스트 제외된 파라미터 리스트
|
|
@@ -81,7 +81,7 @@ export class Template__service extends Template {
|
|
|
81
81
|
(param) =>
|
|
82
82
|
!ApiParamType.isContext(param.type) &&
|
|
83
83
|
!ApiParamType.isRefKnex(param.type) &&
|
|
84
|
-
!(param.optional === true && param.name.startsWith("_")) // _로 시작하는 파라미터는 제외
|
|
84
|
+
!(param.optional === true && param.name.startsWith("_")), // _로 시작하는 파라미터는 제외
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
// 파라미터 타입 정의
|
|
@@ -91,40 +91,31 @@ export class Template__service extends Template {
|
|
|
91
91
|
})
|
|
92
92
|
.join(", ");
|
|
93
93
|
typeParamNames = typeParamNames.concat(
|
|
94
|
-
api.typeParameters.map((typeParam) => typeParam.id)
|
|
94
|
+
api.typeParameters.map((typeParam) => typeParam.id),
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
// 파라미터 정의
|
|
98
|
-
const paramsDef = apiParamToTsCode(
|
|
99
|
-
paramsWithoutContext,
|
|
100
|
-
importKeys
|
|
101
|
-
);
|
|
98
|
+
const paramsDef = apiParamToTsCode(paramsWithoutContext, importKeys);
|
|
102
99
|
|
|
103
100
|
// 파라미터 정의 (객체 형태)
|
|
104
|
-
const paramsDefAsObject = apiParamToTsCodeAsObject(
|
|
105
|
-
paramsWithoutContext,
|
|
106
|
-
importKeys
|
|
107
|
-
);
|
|
101
|
+
const paramsDefAsObject = apiParamToTsCodeAsObject(paramsWithoutContext, importKeys);
|
|
108
102
|
|
|
109
103
|
// 리턴 타입 정의
|
|
110
104
|
const returnTypeDef = apiParamTypeToTsType(
|
|
111
|
-
unwrapPromiseOnce(api.returnType),
|
|
112
|
-
importKeys
|
|
105
|
+
assertDefined(unwrapPromiseOnce(api.returnType)),
|
|
106
|
+
importKeys,
|
|
113
107
|
);
|
|
114
108
|
|
|
115
109
|
// 페이로드 데이터 정의
|
|
116
|
-
const payloadDef = `{ ${paramsWithoutContext
|
|
117
|
-
.map((param) => param.name)
|
|
118
|
-
.join(", ")} }`;
|
|
110
|
+
const payloadDef = `{ ${paramsWithoutContext.map((param) => param.name).join(", ")} }`;
|
|
119
111
|
|
|
120
112
|
// 기본 URL
|
|
121
113
|
const apiBaseUrl = `${Sonamu.config.api.route.prefix}${api.path}`;
|
|
122
114
|
|
|
115
|
+
const clients = api.options.clients ?? [];
|
|
123
116
|
return [
|
|
124
117
|
// 클라이언트별로 생성
|
|
125
|
-
...
|
|
126
|
-
client === "swr" ? 0 : 1
|
|
127
|
-
).map((client) => {
|
|
118
|
+
...sort(clients, (client) => (client === "swr" ? 0 : 1)).map((client) => {
|
|
128
119
|
switch (client) {
|
|
129
120
|
case "axios":
|
|
130
121
|
return this.renderAxios(
|
|
@@ -133,7 +124,7 @@ export class Template__service extends Template {
|
|
|
133
124
|
typeParamsDef,
|
|
134
125
|
paramsDef,
|
|
135
126
|
returnTypeDef,
|
|
136
|
-
payloadDef
|
|
127
|
+
payloadDef,
|
|
137
128
|
);
|
|
138
129
|
case "axios-multipart":
|
|
139
130
|
return this.renderAxiosMultipart(
|
|
@@ -142,7 +133,7 @@ export class Template__service extends Template {
|
|
|
142
133
|
typeParamsDef,
|
|
143
134
|
paramsDef,
|
|
144
135
|
returnTypeDef,
|
|
145
|
-
paramsWithoutContext
|
|
136
|
+
paramsWithoutContext,
|
|
146
137
|
);
|
|
147
138
|
case "swr":
|
|
148
139
|
return this.renderSwr(
|
|
@@ -151,7 +142,7 @@ export class Template__service extends Template {
|
|
|
151
142
|
typeParamsDef,
|
|
152
143
|
paramsDef,
|
|
153
144
|
returnTypeDef,
|
|
154
|
-
payloadDef
|
|
145
|
+
payloadDef,
|
|
155
146
|
);
|
|
156
147
|
case "window-fetch":
|
|
157
148
|
return this.renderWindowFetch(
|
|
@@ -159,16 +150,14 @@ export class Template__service extends Template {
|
|
|
159
150
|
apiBaseUrl,
|
|
160
151
|
typeParamsDef,
|
|
161
152
|
paramsDef,
|
|
162
|
-
payloadDef
|
|
153
|
+
payloadDef,
|
|
163
154
|
);
|
|
164
155
|
default:
|
|
165
156
|
return `// Not supported ${inflection.camelize(client, true)} yet.`;
|
|
166
157
|
}
|
|
167
158
|
}),
|
|
168
159
|
// 스트리밍인 경우
|
|
169
|
-
...(api.streamOptions
|
|
170
|
-
? [this.renderStream(api, apiBaseUrl, paramsDefAsObject)]
|
|
171
|
-
: []),
|
|
160
|
+
...(api.streamOptions ? [this.renderStream(api, apiBaseUrl, paramsDefAsObject)] : []),
|
|
172
161
|
].join("\n");
|
|
173
162
|
})
|
|
174
163
|
.join("\n\n");
|
|
@@ -181,7 +170,7 @@ ${methodCodes}
|
|
|
181
170
|
|
|
182
171
|
return {
|
|
183
172
|
lines: [body],
|
|
184
|
-
importKeys:
|
|
173
|
+
importKeys: diff(unique(importKeys), typeParamNames),
|
|
185
174
|
};
|
|
186
175
|
}
|
|
187
176
|
|
|
@@ -191,10 +180,10 @@ ${methodCodes}
|
|
|
191
180
|
typeParamsDef: string,
|
|
192
181
|
paramsDef: string,
|
|
193
182
|
returnTypeDef: string,
|
|
194
|
-
payloadDef: string
|
|
183
|
+
payloadDef: string,
|
|
195
184
|
) {
|
|
196
185
|
const methodNameAxios = api.options.resourceName
|
|
197
|
-
?
|
|
186
|
+
? `get${inflection.camelize(api.options.resourceName)}`
|
|
198
187
|
: api.methodName;
|
|
199
188
|
|
|
200
189
|
if (api.options.httpMethod === "GET") {
|
|
@@ -227,7 +216,7 @@ export async function ${methodNameAxios}${typeParamsDef}(${paramsDef}): Promise<
|
|
|
227
216
|
typeParamsDef: string,
|
|
228
217
|
paramsDef: string,
|
|
229
218
|
returnTypeDef: string,
|
|
230
|
-
paramsWithoutContext: ApiParam[]
|
|
219
|
+
paramsWithoutContext: ApiParam[],
|
|
231
220
|
) {
|
|
232
221
|
const isMultiple = api.uploadOptions?.mode === "multiple";
|
|
233
222
|
const fileParamName = isMultiple ? "files" : "file";
|
|
@@ -235,17 +224,15 @@ export async function ${methodNameAxios}${typeParamsDef}(${paramsDef}): Promise<
|
|
|
235
224
|
|
|
236
225
|
const formDataDef = isMultiple
|
|
237
226
|
? [
|
|
238
|
-
`${fileParamName}.forEach(f => formData.append("${fileParamName}", f))
|
|
227
|
+
`${fileParamName}.forEach(f => { formData.append("${fileParamName}", f) } ); `,
|
|
239
228
|
...paramsWithoutContext.map(
|
|
240
|
-
(param) =>
|
|
241
|
-
`formData.append('${param.name}', String(${param.name}));`
|
|
229
|
+
(param) => `formData.append('${param.name}', String(${param.name}));`,
|
|
242
230
|
),
|
|
243
231
|
].join("\n")
|
|
244
232
|
: [
|
|
245
233
|
`formData.append("${fileParamName}", ${fileParamName});`,
|
|
246
234
|
...paramsWithoutContext.map(
|
|
247
|
-
(param) =>
|
|
248
|
-
`formData.append('${param.name}', String(${param.name}));`
|
|
235
|
+
(param) => `formData.append('${param.name}', String(${param.name}));`,
|
|
249
236
|
),
|
|
250
237
|
].join("\n");
|
|
251
238
|
|
|
@@ -278,23 +265,21 @@ export async function ${api.methodName}${typeParamsDef}(
|
|
|
278
265
|
typeParamsDef: string,
|
|
279
266
|
paramsDef: string,
|
|
280
267
|
returnTypeDef: string,
|
|
281
|
-
payloadDef: string
|
|
268
|
+
payloadDef: string,
|
|
282
269
|
) {
|
|
283
270
|
const methodNameSwr = api.options.resourceName
|
|
284
|
-
?
|
|
285
|
-
:
|
|
286
|
-
return ` export function ${inflection.camelize(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
271
|
+
? `use${inflection.camelize(api.options.resourceName)}`
|
|
272
|
+
: `use${inflection.camelize(api.methodName)}`;
|
|
273
|
+
return ` export function ${inflection.camelize(methodNameSwr, true)}${typeParamsDef}(${[
|
|
274
|
+
paramsDef,
|
|
275
|
+
"swrOptions?: SwrOptions",
|
|
276
|
+
]
|
|
290
277
|
.filter((p) => p !== "")
|
|
291
278
|
.join(",")}, ): SWRResponse<${returnTypeDef}, SWRError> {
|
|
292
279
|
return useSWR(handleConditional([
|
|
293
280
|
\`${apiBaseUrl}\`,
|
|
294
281
|
${payloadDef},
|
|
295
|
-
], swrOptions?.conditional)${
|
|
296
|
-
api.options.httpMethod === "POST" ? ", swrPostFetcher" : ""
|
|
297
|
-
}${
|
|
282
|
+
], swrOptions?.conditional)${api.options.httpMethod === "POST" ? ", swrPostFetcher" : ""}${
|
|
298
283
|
api.options.timeout ? `, { loadingTimeout: ${api.options.timeout} }` : ""
|
|
299
284
|
});
|
|
300
285
|
}`;
|
|
@@ -305,35 +290,26 @@ export async function ${api.methodName}${typeParamsDef}(
|
|
|
305
290
|
apiBaseUrl: string,
|
|
306
291
|
typeParamsDef: string,
|
|
307
292
|
paramsDef: string,
|
|
308
|
-
payloadDef: string
|
|
293
|
+
payloadDef: string,
|
|
309
294
|
) {
|
|
310
295
|
return `
|
|
311
296
|
export async function ${api.methodName}${typeParamsDef}(${paramsDef}): Promise<Response> {
|
|
312
297
|
return window.fetch(\`${apiBaseUrl}?\${qs.stringify(${payloadDef})}\`${
|
|
313
|
-
api.options.timeout
|
|
314
|
-
? `, { signal: AbortSignal.timeout(${api.options.timeout}) }`
|
|
315
|
-
: ""
|
|
298
|
+
api.options.timeout ? `, { signal: AbortSignal.timeout(${api.options.timeout}) }` : ""
|
|
316
299
|
});
|
|
317
300
|
}
|
|
318
301
|
`.trim();
|
|
319
302
|
}
|
|
320
303
|
|
|
321
|
-
renderStream(
|
|
322
|
-
api: ExtendedApi,
|
|
323
|
-
apiBaseUrl: string,
|
|
324
|
-
paramsDefAsObject: string
|
|
325
|
-
) {
|
|
304
|
+
renderStream(api: ExtendedApi, apiBaseUrl: string, paramsDefAsObject: string) {
|
|
326
305
|
if (!api.streamOptions) {
|
|
327
306
|
return "// streamOptions not found";
|
|
328
307
|
}
|
|
329
308
|
|
|
330
309
|
const methodNameStream = api.options.resourceName
|
|
331
|
-
?
|
|
332
|
-
:
|
|
333
|
-
const methodNameStreamCamelized = inflection.camelize(
|
|
334
|
-
methodNameStream,
|
|
335
|
-
true
|
|
336
|
-
);
|
|
310
|
+
? `use${inflection.camelize(api.options.resourceName)}`
|
|
311
|
+
: `use${inflection.camelize(api.methodName)}`;
|
|
312
|
+
const methodNameStreamCamelized = inflection.camelize(methodNameStream, true);
|
|
337
313
|
|
|
338
314
|
const eventsTypeDef = zodTypeToTsTypeDef(api.streamOptions.events);
|
|
339
315
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EntityManager, type EntityNamesRecord } from "../../entity/entity-manager";
|
|
2
|
+
import type { TemplateOptions } from "../../types/types";
|
|
3
3
|
import { Template } from "../template";
|
|
4
4
|
|
|
5
5
|
export class Template__view_enums_buttonset extends Template {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Template } from "../template";
|
|
1
|
+
import { EntityManager, type EntityNamesRecord } from "../../entity/entity-manager";
|
|
2
|
+
import type { TemplateOptions } from "../../types/types";
|
|
4
3
|
import { getLabel } from "../helpers";
|
|
4
|
+
import { Template } from "../template";
|
|
5
5
|
|
|
6
6
|
export class Template__view_enums_dropdown extends Template {
|
|
7
7
|
constructor() {
|
|
@@ -50,4 +50,4 @@ export function ${enumId}Dropdown(props: DropdownProps) {
|
|
|
50
50
|
importKeys: [],
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Template } from "../template";
|
|
1
|
+
import { EntityManager, type EntityNamesRecord } from "../../entity/entity-manager";
|
|
2
|
+
import type { TemplateOptions } from "../../types/types";
|
|
4
3
|
import { getLabel } from "../helpers";
|
|
4
|
+
import { Template } from "../template";
|
|
5
5
|
|
|
6
6
|
export class Template__view_enums_select extends Template {
|
|
7
7
|
constructor() {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import inflection from "inflection";
|
|
2
|
+
import { unique } from "radashi";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { EntityManager, type EntityNamesRecord } from "../../entity/entity-manager";
|
|
5
|
+
import type { RenderingNode, TemplateKey, TemplateOptions } from "../../types/types";
|
|
6
|
+
import { getEnumInfoFromColName, getRelationPropFromColName } from "../helpers";
|
|
7
|
+
import type { RenderedTemplate } from "../template";
|
|
6
8
|
import { Template } from "../template";
|
|
7
|
-
import { getRelationPropFromColName, getEnumInfoFromColName } from "../helpers";
|
|
8
|
-
import * as _ from "lodash-es";
|
|
9
9
|
import { getZodTypeById, zodTypeToRenderingNode } from "../zod-converter";
|
|
10
10
|
|
|
11
11
|
export class Template__view_form extends Template {
|
|
@@ -28,27 +28,17 @@ export class Template__view_form extends Template {
|
|
|
28
28
|
].join("\n");
|
|
29
29
|
}
|
|
30
30
|
wrapFG(body: string, label?: string): string {
|
|
31
|
-
return [
|
|
32
|
-
`<Form.Group widths="equal">`,
|
|
33
|
-
this.wrapFC(body, label),
|
|
34
|
-
`</Form.Group>`,
|
|
35
|
-
].join("\n");
|
|
31
|
+
return [`<Form.Group widths="equal">`, this.wrapFC(body, label), `</Form.Group>`].join("\n");
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
renderColumnImport(entityId: string, col: RenderingNode) {
|
|
39
35
|
if (col.renderType === "enums") {
|
|
40
|
-
const { id, targetEntityNames } = getEnumInfoFromColName(
|
|
41
|
-
entityId,
|
|
42
|
-
col.name
|
|
43
|
-
);
|
|
36
|
+
const { id, targetEntityNames } = getEnumInfoFromColName(entityId, col.name);
|
|
44
37
|
const componentId = `${id}Select`;
|
|
45
38
|
return `import { ${componentId} } from "src/components/${targetEntityNames.fs}/${componentId}";`;
|
|
46
39
|
} else if (col.renderType === "number-fk_id") {
|
|
47
40
|
try {
|
|
48
|
-
const relProp = getRelationPropFromColName(
|
|
49
|
-
entityId,
|
|
50
|
-
col.name.replace("_id", "")
|
|
51
|
-
);
|
|
41
|
+
const relProp = getRelationPropFromColName(entityId, col.name.replace("_id", ""));
|
|
52
42
|
const targetNames = EntityManager.getNamesFromId(relProp.with);
|
|
53
43
|
const componentId = `${relProp.with}IdAsyncSelect`;
|
|
54
44
|
return `import { ${componentId} } from "src/components/${targetNames.fs}/${componentId}";`;
|
|
@@ -64,17 +54,14 @@ export class Template__view_form extends Template {
|
|
|
64
54
|
entityId: string,
|
|
65
55
|
col: RenderingNode,
|
|
66
56
|
names: EntityNamesRecord,
|
|
67
|
-
parent: string = ""
|
|
57
|
+
parent: string = "",
|
|
68
58
|
): string {
|
|
69
59
|
let regExpr: string = "";
|
|
70
60
|
regExpr = `{...register(\`${parent}${col.name}\`)}`;
|
|
71
61
|
|
|
72
62
|
switch (col.renderType) {
|
|
73
63
|
case "string-plain":
|
|
74
|
-
if (
|
|
75
|
-
col.zodType instanceof z.ZodString &&
|
|
76
|
-
(col.zodType.maxLength ?? 0) <= 512
|
|
77
|
-
) {
|
|
64
|
+
if (col.zodType instanceof z.ZodString && (col.zodType.maxLength ?? 0) <= 512) {
|
|
78
65
|
return `<Input placeholder="${col.label}" ${regExpr} />`;
|
|
79
66
|
} else {
|
|
80
67
|
return `<TextArea rows={8} placeholder="${col.label}" ${regExpr} />`;
|
|
@@ -112,10 +99,7 @@ export class Template__view_form extends Template {
|
|
|
112
99
|
}
|
|
113
100
|
case "number-fk_id":
|
|
114
101
|
try {
|
|
115
|
-
const relProp = getRelationPropFromColName(
|
|
116
|
-
entityId,
|
|
117
|
-
col.name.replace("_id", "")
|
|
118
|
-
);
|
|
102
|
+
const relProp = getRelationPropFromColName(entityId, col.name.replace("_id", ""));
|
|
119
103
|
const fkId = `${relProp.with}IdAsyncSelect`;
|
|
120
104
|
return `<${fkId} {...register('${col.name}')} ${
|
|
121
105
|
col.optional || col.nullable ? "clearable" : ""
|
|
@@ -128,9 +112,7 @@ export class Template__view_form extends Template {
|
|
|
128
112
|
case "object":
|
|
129
113
|
return `<>${col.name} object</>`;
|
|
130
114
|
default:
|
|
131
|
-
throw new Error(
|
|
132
|
-
`대응 불가능한 렌더 타입 ${col.renderType} on ${col.name}`
|
|
133
|
-
);
|
|
115
|
+
throw new Error(`대응 불가능한 렌더 타입 ${col.renderType} on ${col.name}`);
|
|
134
116
|
}
|
|
135
117
|
}
|
|
136
118
|
|
|
@@ -167,7 +149,7 @@ export class Template__view_form extends Template {
|
|
|
167
149
|
result[col.name] = value;
|
|
168
150
|
return result;
|
|
169
151
|
},
|
|
170
|
-
{} as { [key: string]: unknown }
|
|
152
|
+
{} as { [key: string]: unknown },
|
|
171
153
|
);
|
|
172
154
|
}
|
|
173
155
|
|
|
@@ -180,9 +162,7 @@ export class Template__view_form extends Template {
|
|
|
180
162
|
const columns = (saveParamsNode.children as RenderingNode[])
|
|
181
163
|
.filter((col) => col.name !== "id")
|
|
182
164
|
.map((col) => {
|
|
183
|
-
const propCandidate = entity.props.find(
|
|
184
|
-
(prop) => prop.name === col.name
|
|
185
|
-
);
|
|
165
|
+
const propCandidate = entity.props.find((prop) => prop.name === col.name);
|
|
186
166
|
col.label = propCandidate?.desc ?? col.label;
|
|
187
167
|
return col;
|
|
188
168
|
});
|
|
@@ -190,9 +170,7 @@ export class Template__view_form extends Template {
|
|
|
190
170
|
const defaultValue = this.resolveDefaultValue(columns);
|
|
191
171
|
|
|
192
172
|
// 프리 템플릿
|
|
193
|
-
const preTemplates: RenderedTemplate["preTemplates"] = (
|
|
194
|
-
columns as RenderingNode[]
|
|
195
|
-
)
|
|
173
|
+
const preTemplates: RenderedTemplate["preTemplates"] = (columns as RenderingNode[])
|
|
196
174
|
.filter((col) => {
|
|
197
175
|
if (col.name === "id") {
|
|
198
176
|
return false;
|
|
@@ -219,16 +197,15 @@ export class Template__view_form extends Template {
|
|
|
219
197
|
let enumId: string | undefined;
|
|
220
198
|
if (col.renderType === "enums") {
|
|
221
199
|
key = "view_enums_select";
|
|
222
|
-
const { targetEntityNames: targetMDNames, id } =
|
|
223
|
-
|
|
200
|
+
const { targetEntityNames: targetMDNames, id } = getEnumInfoFromColName(
|
|
201
|
+
entityId,
|
|
202
|
+
col.name,
|
|
203
|
+
);
|
|
224
204
|
targetMdId = targetMDNames.capital;
|
|
225
205
|
enumId = id;
|
|
226
206
|
} else {
|
|
227
207
|
key = "view_id_async_select";
|
|
228
|
-
const relProp = getRelationPropFromColName(
|
|
229
|
-
entityId,
|
|
230
|
-
col.name.replace("_id", "")
|
|
231
|
-
);
|
|
208
|
+
const relProp = getRelationPropFromColName(entityId, col.name.replace("_id", ""));
|
|
232
209
|
targetMdId = relProp.with;
|
|
233
210
|
}
|
|
234
211
|
|
|
@@ -275,19 +252,15 @@ import { defaultCatch } from 'src/services/sonamu.shared';
|
|
|
275
252
|
// import { ImageUploader } from 'src/admin-common/ImageUploader';
|
|
276
253
|
// import { useCommonModal } from "src/admin-common/CommonModal";
|
|
277
254
|
|
|
278
|
-
import { ${names.capital}SaveParams } from 'src/services/${names.fs}/${
|
|
279
|
-
|
|
280
|
-
}.types';
|
|
281
|
-
import { ${names.capital}Service } from 'src/services/${names.fs}/${
|
|
282
|
-
names.fs
|
|
283
|
-
}.service';
|
|
255
|
+
import { ${names.capital}SaveParams } from 'src/services/${names.fs}/${names.fs}.types';
|
|
256
|
+
import { ${names.capital}Service } from 'src/services/${names.fs}/${names.fs}.service';
|
|
284
257
|
import { ${names.capital}SubsetA } from 'src/services/sonamu.generated';
|
|
285
|
-
${
|
|
258
|
+
${unique(
|
|
286
259
|
columns
|
|
287
260
|
.filter((col) => ["number-fk_id", "enums"].includes(col.renderType))
|
|
288
261
|
.map((col) => {
|
|
289
262
|
return this.renderColumnImport(entityId, col);
|
|
290
|
-
})
|
|
263
|
+
}),
|
|
291
264
|
).join("\n")}
|
|
292
265
|
|
|
293
266
|
export default function ${names.capitalPlural}FormPage() {
|
|
@@ -297,27 +270,20 @@ export default function ${names.capitalPlural}FormPage() {
|
|
|
297
270
|
id: searchParams.get('id') ?? undefined,
|
|
298
271
|
};
|
|
299
272
|
|
|
300
|
-
return <${
|
|
301
|
-
names.capitalPlural
|
|
302
|
-
}Form id={query?.id ? Number(query.id) : undefined} />;
|
|
273
|
+
return <${names.capitalPlural}Form id={query?.id ? Number(query.id) : undefined} />;
|
|
303
274
|
}
|
|
304
275
|
type ${names.capitalPlural}FormProps = {
|
|
305
276
|
id?: number;
|
|
306
277
|
mode?: 'page' | 'modal';
|
|
307
278
|
};
|
|
308
|
-
export function ${names.capitalPlural}Form({ id, mode }: ${
|
|
309
|
-
names.capitalPlural
|
|
310
|
-
}FormProps) {
|
|
279
|
+
export function ${names.capitalPlural}Form({ id, mode }: ${names.capitalPlural}FormProps) {
|
|
311
280
|
// 편집시 기존 row
|
|
312
281
|
const [row, setRow] = useState<${names.capital}SubsetA | undefined>();
|
|
313
282
|
|
|
314
283
|
// ${names.capital}SaveParams 폼
|
|
315
|
-
const { form, setForm, register } = useTypeForm(${
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
/"now\(\)"/g,
|
|
319
|
-
"DateTime.local().toSQL()!.slice(0, 19)"
|
|
320
|
-
)});
|
|
284
|
+
const { form, setForm, register } = useTypeForm(${names.capital}SaveParams, ${JSON.stringify(
|
|
285
|
+
defaultValue,
|
|
286
|
+
).replace(/"now\(\)"/g, "DateTime.local().toSQL()!.slice(0, 19)")});
|
|
321
287
|
|
|
322
288
|
// 수정일 때 기존 row 콜
|
|
323
289
|
useEffect(() => {
|
|
@@ -330,10 +296,7 @@ export function ${names.capitalPlural}Form({ id, mode }: ${
|
|
|
330
296
|
.filter((col) => col.renderType === "number-fk_id")
|
|
331
297
|
.map((col) => {
|
|
332
298
|
if (col.nullable) {
|
|
333
|
-
return `${col.name}: row.${col.name.replace(
|
|
334
|
-
"_id",
|
|
335
|
-
"?.id"
|
|
336
|
-
)} ?? null`;
|
|
299
|
+
return `${col.name}: row.${col.name.replace("_id", "?.id")} ?? null`;
|
|
337
300
|
} else {
|
|
338
301
|
return `${col.name}: row.${col.name.replace("_id", ".id")}`;
|
|
339
302
|
}
|
|
@@ -361,9 +324,7 @@ export function ${names.capitalPlural}Form({ id, mode }: ${
|
|
|
361
324
|
|
|
362
325
|
// 페이지
|
|
363
326
|
const PAGE = {
|
|
364
|
-
title: \`${
|
|
365
|
-
entity.title ?? names.capital
|
|
366
|
-
}\${id ? \`#\${id} 수정\` : ' 등록'}\`,
|
|
327
|
+
title: \`${entity.title ?? names.capital}\${id ? \`#\${id} 수정\` : ' 등록'}\`,
|
|
367
328
|
}
|
|
368
329
|
|
|
369
330
|
return (
|
|
@@ -386,7 +347,7 @@ export function ${names.capitalPlural}Form({ id, mode }: ${
|
|
|
386
347
|
if (col.name === "created_at") {
|
|
387
348
|
return `{form.id && (${this.wrapFG(
|
|
388
349
|
`<div className="p-8px">{formatDateTime(form.${col.name})}</div>`,
|
|
389
|
-
"등록일시"
|
|
350
|
+
"등록일시",
|
|
390
351
|
)})}`;
|
|
391
352
|
} else {
|
|
392
353
|
return this.wrapFG(
|
|
@@ -394,16 +355,14 @@ export function ${names.capitalPlural}Form({ id, mode }: ${
|
|
|
394
355
|
(() => {
|
|
395
356
|
if (col.label.endsWith("Id")) {
|
|
396
357
|
try {
|
|
397
|
-
const entity = EntityManager.get(
|
|
398
|
-
col.label.replace("Id", "")
|
|
399
|
-
);
|
|
358
|
+
const entity = EntityManager.get(col.label.replace("Id", ""));
|
|
400
359
|
return entity.title ?? col.label;
|
|
401
360
|
} catch {
|
|
402
361
|
return col.label;
|
|
403
362
|
}
|
|
404
363
|
}
|
|
405
364
|
return col.label;
|
|
406
|
-
})()
|
|
365
|
+
})(),
|
|
407
366
|
);
|
|
408
367
|
}
|
|
409
368
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EntityManager, type EntityNamesRecord } from "../../entity/entity-manager";
|
|
2
|
+
import type { TemplateOptions } from "../../types/types";
|
|
3
3
|
import { Template } from "../template";
|
|
4
4
|
|
|
5
5
|
export class Template__view_id_all_select extends Template {
|