sonamu 0.5.7 → 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 +13 -2
- package/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +71 -2
- 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 +258 -2
- package/dist/api/config.d.ts +90 -0
- package/dist/api/config.d.ts.map +1 -0
- package/dist/api/config.js +25 -0
- package/dist/api/context.d.ts +4 -2
- package/dist/api/context.d.ts.map +1 -1
- package/dist/api/context.js +3 -2
- package/dist/api/decorators.d.ts +20 -6
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +235 -2
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +9 -2
- package/dist/api/sonamu.d.ts +10 -24
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +514 -2
- 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 +6 -1
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +15 -2
- package/dist/bin/cli.js +519 -2
- package/dist/bin/hot-hook-register.d.ts +11 -0
- package/dist/bin/hot-hook-register.d.ts.map +1 -0
- package/dist/bin/hot-hook-register.js +21 -0
- 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 +95 -2
- 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 +390 -2
- 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 +54 -2
- package/dist/database/db.d.ts +6 -21
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +129 -2
- 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 +109 -2
- package/dist/database/puri.d.ts +41 -23
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +601 -2
- package/dist/database/puri.types.d.ts +25 -6
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +6 -2
- 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 +14 -2
- 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 +365 -2
- package/dist/entity/entity-manager.d.ts +167 -2
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +130 -2
- package/dist/entity/entity.d.ts +5 -3
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +750 -2
- 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 +29 -2
- 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 +85 -2
- 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 +79 -2
- package/dist/file-storage/file-storage.js +75 -2
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -2
- 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 +614 -2
- 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 +213 -2
- package/dist/migration/migrator.d.ts +24 -82
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +330 -2
- 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 +3 -2
- 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 +95 -0
- package/dist/naite/naite.d.ts.map +1 -0
- package/dist/naite/naite.js +316 -0
- package/dist/stream/index.js +3 -2
- package/dist/stream/sse.d.ts +2 -2
- package/dist/stream/sse.d.ts.map +1 -1
- package/dist/stream/sse.js +38 -2
- package/dist/syncer/api-parser.d.ts +10 -0
- package/dist/syncer/api-parser.d.ts.map +1 -0
- package/dist/syncer/api-parser.js +240 -0
- package/dist/syncer/checksum.d.ts +21 -0
- package/dist/syncer/checksum.d.ts.map +1 -0
- package/dist/syncer/checksum.js +98 -0
- package/dist/syncer/code-generator.d.ts +20 -0
- package/dist/syncer/code-generator.d.ts.map +1 -0
- package/dist/syncer/code-generator.js +161 -0
- package/dist/syncer/entity-operations.d.ts +17 -0
- package/dist/syncer/entity-operations.d.ts.map +1 -0
- package/dist/syncer/entity-operations.js +59 -0
- package/dist/syncer/file-patterns.d.ts +29 -0
- package/dist/syncer/file-patterns.d.ts.map +1 -0
- package/dist/syncer/file-patterns.js +38 -0
- package/dist/syncer/index.d.ts +6 -0
- package/dist/syncer/index.d.ts.map +1 -1
- package/dist/syncer/index.js +9 -2
- package/dist/syncer/module-loader.d.ts +35 -0
- package/dist/syncer/module-loader.d.ts.map +1 -0
- package/dist/syncer/module-loader.js +87 -0
- package/dist/syncer/syncer.d.ts +98 -106
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +422 -2
- package/dist/template/entity-converter.d.ts +14 -0
- package/dist/template/entity-converter.d.ts.map +1 -0
- package/dist/template/entity-converter.js +108 -0
- package/dist/template/helpers.d.ts +23 -0
- package/dist/template/helpers.d.ts.map +1 -0
- package/dist/template/helpers.js +64 -0
- package/dist/{templates → template/implementations}/entity.template.d.ts +3 -3
- package/dist/template/implementations/entity.template.d.ts.map +1 -0
- package/dist/template/implementations/entity.template.js +86 -0
- package/dist/{templates → template/implementations}/generated.template.d.ts +3 -4
- package/dist/template/implementations/generated.template.d.ts.map +1 -0
- package/dist/template/implementations/generated.template.js +249 -0
- package/dist/{templates → template/implementations}/generated_http.template.d.ts +3 -4
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -0
- package/dist/template/implementations/generated_http.template.js +131 -0
- package/dist/{templates → template/implementations}/generated_sso.template.d.ts +4 -5
- package/dist/template/implementations/generated_sso.template.d.ts.map +1 -0
- package/dist/template/implementations/generated_sso.template.js +134 -0
- package/dist/{templates → template/implementations}/init_types.template.d.ts +3 -3
- package/dist/template/implementations/init_types.template.d.ts.map +1 -0
- package/dist/template/implementations/init_types.template.js +38 -0
- package/dist/template/implementations/model.template.d.ts +17 -0
- package/dist/template/implementations/model.template.d.ts.map +1 -0
- package/dist/template/implementations/model.template.js +181 -0
- package/dist/{templates → template/implementations}/model_test.template.d.ts +3 -3
- package/dist/template/implementations/model_test.template.d.ts.map +1 -0
- package/dist/template/implementations/model_test.template.js +35 -0
- package/dist/{templates → template/implementations}/service.template.d.ts +6 -6
- package/dist/template/implementations/service.template.d.ts.map +1 -0
- package/dist/template/implementations/service.template.js +201 -0
- package/dist/{templates → template/implementations}/view_enums_buttonset.template.d.ts +3 -3
- package/dist/template/implementations/view_enums_buttonset.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_buttonset.template.js +31 -0
- package/dist/{templates → template/implementations}/view_enums_dropdown.template.d.ts +3 -4
- package/dist/template/implementations/view_enums_dropdown.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_dropdown.template.js +50 -0
- package/dist/{templates → template/implementations}/view_enums_select.template.d.ts +3 -3
- package/dist/template/implementations/view_enums_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_select.template.js +55 -0
- package/dist/{templates → template/implementations}/view_form.template.d.ts +5 -5
- package/dist/template/implementations/view_form.template.d.ts.map +1 -0
- package/dist/template/implementations/view_form.template.js +337 -0
- package/dist/{templates → template/implementations}/view_id_all_select.template.d.ts +3 -3
- package/dist/template/implementations/view_id_all_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_id_all_select.template.js +31 -0
- package/dist/{templates → template/implementations}/view_id_async_select.template.d.ts +3 -3
- package/dist/template/implementations/view_id_async_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_id_async_select.template.js +105 -0
- package/dist/{templates → template/implementations}/view_list.template.d.ts +5 -13
- package/dist/template/implementations/view_list.template.d.ts.map +1 -0
- package/dist/template/implementations/view_list.template.js +475 -0
- package/dist/template/implementations/view_list_columns.template.d.ts +17 -0
- package/dist/template/implementations/view_list_columns.template.d.ts.map +1 -0
- package/dist/template/implementations/view_list_columns.template.js +49 -0
- package/dist/{templates → template/implementations}/view_search_input.template.d.ts +3 -3
- package/dist/template/implementations/view_search_input.template.d.ts.map +1 -0
- package/dist/template/implementations/view_search_input.template.js +64 -0
- package/dist/template/index.d.ts +7 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +8 -0
- 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 +49 -0
- package/dist/template/template.d.ts.map +1 -0
- package/dist/template/template.js +60 -0
- package/dist/template/zod-converter.d.ts +51 -0
- package/dist/template/zod-converter.d.ts.map +1 -0
- package/dist/template/zod-converter.js +449 -0
- 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 +89 -2
- 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 +623 -2
- package/dist/types/types.d.ts +747 -143
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +546 -2
- package/dist/typings/knex.d.js +3 -2
- package/dist/utils/async-utils.d.ts +7 -0
- package/dist/utils/async-utils.d.ts.map +1 -1
- package/dist/utils/async-utils.js +57 -2
- package/dist/utils/console-util.d.ts +2 -0
- package/dist/utils/console-util.d.ts.map +1 -0
- package/dist/utils/console-util.js +6 -0
- package/dist/utils/controller.d.ts +1 -0
- package/dist/utils/controller.d.ts.map +1 -1
- package/dist/utils/controller.js +29 -2
- package/dist/utils/esm-utils.d.ts +39 -0
- package/dist/utils/esm-utils.d.ts.map +1 -0
- package/dist/utils/esm-utils.js +49 -0
- 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 +17 -2
- package/dist/utils/lodash-able.d.ts.map +1 -1
- package/dist/utils/lodash-able.js +6 -2
- package/dist/utils/model.js +22 -2
- 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 +89 -0
- package/dist/utils/path-utils.d.ts.map +1 -0
- package/dist/utils/path-utils.js +60 -0
- package/dist/utils/process-utils.d.ts +13 -0
- package/dist/utils/process-utils.d.ts.map +1 -0
- package/dist/utils/process-utils.js +36 -0
- 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 +46 -2
- 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 +10 -7
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +72 -2
- 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 +19 -2
- package/package.json +65 -27
- 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 +178 -535
- package/src/api/config.ts +125 -0
- package/src/api/context.ts +7 -17
- package/src/api/decorators.ts +176 -46
- package/src/api/index.ts +2 -2
- package/src/api/sonamu.ts +190 -167
- package/src/api/validator.ts +83 -0
- package/src/bin/build-config.ts +8 -1
- package/src/bin/cli.ts +258 -124
- package/src/bin/hot-hook-register.ts +22 -0
- 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 +40 -96
- 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 +229 -148
- package/src/database/puri.types.ts +76 -30
- package/src/database/transaction-context.ts +1 -1
- package/src/database/upsert-builder.ts +262 -132
- package/src/entity/entity-manager.ts +48 -36
- package/src/entity/entity.ts +330 -248
- 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 -10
- package/src/migration/code-generation.ts +185 -172
- package/src/migration/migration-set.ts +80 -293
- package/src/migration/migrator.ts +199 -571
- 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 +415 -0
- package/src/shared/web.shared.ts.txt +20 -24
- package/src/stream/sse.ts +5 -5
- package/src/syncer/api-parser.ts +282 -0
- package/src/syncer/checksum.ts +140 -0
- package/src/syncer/code-generator.ts +198 -0
- package/src/syncer/entity-operations.ts +65 -0
- package/src/syncer/file-patterns.ts +56 -0
- package/src/syncer/index.ts +6 -0
- package/src/syncer/module-loader.ts +128 -0
- package/src/syncer/syncer.ts +389 -1453
- package/src/template/entity-converter.ts +114 -0
- package/src/template/helpers.ts +81 -0
- package/src/{templates → template/implementations}/entity.template.ts +7 -7
- package/src/{templates → template/implementations}/generated.template.ts +101 -101
- package/src/{templates → template/implementations}/generated_http.template.ts +27 -57
- package/src/template/implementations/generated_sso.template.ts +151 -0
- package/src/{templates → template/implementations}/init_types.template.ts +5 -7
- package/src/{templates → template/implementations}/model.template.ts +52 -43
- package/src/{templates → template/implementations}/model_test.template.ts +5 -5
- package/src/{templates → template/implementations}/service.template.ts +66 -82
- package/src/{templates → template/implementations}/view_enums_buttonset.template.ts +3 -3
- package/src/{templates → template/implementations}/view_enums_dropdown.template.ts +4 -20
- package/src/{templates → template/implementations}/view_enums_select.template.ts +4 -4
- package/src/{templates → template/implementations}/view_form.template.ts +40 -83
- package/src/{templates → template/implementations}/view_id_all_select.template.ts +3 -3
- package/src/{templates → template/implementations}/view_id_async_select.template.ts +10 -24
- package/src/{templates → template/implementations}/view_list.template.ts +60 -152
- package/src/{templates → template/implementations}/view_list_columns.template.ts +5 -11
- package/src/{templates → template/implementations}/view_search_input.template.ts +3 -3
- package/src/template/index.ts +6 -0
- package/src/template/template-manager.ts +166 -0
- package/src/template/template-types.ts +16 -0
- package/src/template/template.ts +105 -0
- package/src/template/zod-converter.ts +525 -0
- package/src/testing/_relation-graph.ts +18 -11
- package/src/testing/fixture-manager.ts +472 -359
- package/src/types/types.ts +553 -308
- package/src/typings/knex.d.ts +7 -9
- package/src/utils/async-utils.ts +23 -10
- package/src/utils/console-util.ts +4 -0
- package/src/utils/controller.ts +3 -0
- package/src/utils/esm-utils.ts +59 -0
- 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 +99 -0
- package/src/utils/process-utils.ts +46 -0
- package/src/utils/sql-parser.ts +23 -5
- package/src/utils/type-utils.ts +83 -0
- package/src/utils/utils.ts +66 -43
- package/src/utils/zod-error.ts +3 -4
- package/dist/api/base-frame.js.map +0 -1
- package/dist/api/caster.js.map +0 -1
- package/dist/api/code-converters.js.map +0 -1
- package/dist/api/context.js.map +0 -1
- package/dist/api/decorators.js.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/sonamu.js.map +0 -1
- package/dist/bin/build-config.js.map +0 -1
- 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 -3
- package/dist/bin/cli-wrapper.js.map +0 -1
- package/dist/bin/cli.js.map +0 -1
- package/dist/database/_batch_update.js.map +0 -1
- package/dist/database/base-model.js.map +0 -1
- package/dist/database/code-generator.js.map +0 -1
- package/dist/database/db.js.map +0 -1
- 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 -2
- package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +0 -1
- package/dist/database/puri-wrapper.js.map +0 -1
- package/dist/database/puri.js.map +0 -1
- package/dist/database/puri.types.js.map +0 -1
- package/dist/database/transaction-context.js.map +0 -1
- package/dist/database/upsert-builder.js.map +0 -1
- package/dist/entity/entity-manager.js.map +0 -1
- 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 -2
- package/dist/entity/entity-utils.js.map +0 -1
- package/dist/entity/entity.js.map +0 -1
- package/dist/exceptions/error-handler.js.map +0 -1
- package/dist/exceptions/so-exceptions.js.map +0 -1
- package/dist/file-storage/driver.js.map +0 -1
- package/dist/file-storage/file-storage.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/migration/code-generation.js.map +0 -1
- package/dist/migration/migration-set.js.map +0 -1
- package/dist/migration/migrator.js.map +0 -1
- package/dist/migration/types.js.map +0 -1
- package/dist/stream/index.js.map +0 -1
- package/dist/stream/sse.js.map +0 -1
- package/dist/syncer/index.js.map +0 -1
- package/dist/syncer/syncer.js.map +0 -1
- package/dist/templates/base-template.d.ts +0 -13
- package/dist/templates/base-template.d.ts.map +0 -1
- package/dist/templates/base-template.js +0 -2
- package/dist/templates/base-template.js.map +0 -1
- package/dist/templates/entity.template.d.ts.map +0 -1
- package/dist/templates/entity.template.js +0 -2
- package/dist/templates/entity.template.js.map +0 -1
- package/dist/templates/generated.template.d.ts.map +0 -1
- package/dist/templates/generated.template.js +0 -2
- package/dist/templates/generated.template.js.map +0 -1
- package/dist/templates/generated_http.template.d.ts.map +0 -1
- package/dist/templates/generated_http.template.js +0 -2
- package/dist/templates/generated_http.template.js.map +0 -1
- package/dist/templates/generated_sso.template.d.ts.map +0 -1
- package/dist/templates/generated_sso.template.js +0 -2
- package/dist/templates/generated_sso.template.js.map +0 -1
- package/dist/templates/index.d.ts +0 -2
- package/dist/templates/index.d.ts.map +0 -1
- package/dist/templates/index.js +0 -2
- package/dist/templates/index.js.map +0 -1
- package/dist/templates/init_types.template.d.ts.map +0 -1
- package/dist/templates/init_types.template.js +0 -2
- package/dist/templates/init_types.template.js.map +0 -1
- package/dist/templates/model.template.d.ts +0 -17
- package/dist/templates/model.template.d.ts.map +0 -1
- package/dist/templates/model.template.js +0 -2
- package/dist/templates/model.template.js.map +0 -1
- package/dist/templates/model_test.template.d.ts.map +0 -1
- package/dist/templates/model_test.template.js +0 -2
- package/dist/templates/model_test.template.js.map +0 -1
- package/dist/templates/service.template.d.ts.map +0 -1
- package/dist/templates/service.template.js +0 -2
- package/dist/templates/service.template.js.map +0 -1
- package/dist/templates/view_enums_buttonset.template.d.ts.map +0 -1
- package/dist/templates/view_enums_buttonset.template.js +0 -2
- package/dist/templates/view_enums_buttonset.template.js.map +0 -1
- package/dist/templates/view_enums_dropdown.template.d.ts.map +0 -1
- package/dist/templates/view_enums_dropdown.template.js +0 -2
- package/dist/templates/view_enums_dropdown.template.js.map +0 -1
- package/dist/templates/view_enums_select.template.d.ts.map +0 -1
- package/dist/templates/view_enums_select.template.js +0 -2
- package/dist/templates/view_enums_select.template.js.map +0 -1
- package/dist/templates/view_form.template.d.ts.map +0 -1
- package/dist/templates/view_form.template.js +0 -2
- package/dist/templates/view_form.template.js.map +0 -1
- package/dist/templates/view_id_all_select.template.d.ts.map +0 -1
- package/dist/templates/view_id_all_select.template.js +0 -2
- package/dist/templates/view_id_all_select.template.js.map +0 -1
- package/dist/templates/view_id_async_select.template.d.ts.map +0 -1
- package/dist/templates/view_id_async_select.template.js +0 -2
- package/dist/templates/view_id_async_select.template.js.map +0 -1
- package/dist/templates/view_list.template.d.ts.map +0 -1
- package/dist/templates/view_list.template.js +0 -2
- package/dist/templates/view_list.template.js.map +0 -1
- package/dist/templates/view_list_columns.template.d.ts +0 -17
- package/dist/templates/view_list_columns.template.d.ts.map +0 -1
- package/dist/templates/view_list_columns.template.js +0 -2
- package/dist/templates/view_list_columns.template.js.map +0 -1
- package/dist/templates/view_search_input.template.d.ts.map +0 -1
- package/dist/templates/view_search_input.template.js +0 -2
- package/dist/templates/view_search_input.template.js.map +0 -1
- package/dist/testing/_relation-graph.js.map +0 -1
- package/dist/testing/fixture-manager.js.map +0 -1
- package/dist/types/types.js.map +0 -1
- package/dist/typings/knex.d.js.map +0 -1
- package/dist/utils/async-utils.js.map +0 -1
- package/dist/utils/controller.js.map +0 -1
- package/dist/utils/fs-utils.js.map +0 -1
- package/dist/utils/lodash-able.js.map +0 -1
- package/dist/utils/model.js.map +0 -1
- package/dist/utils/sql-parser.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/zod-error.js.map +0 -1
- package/src/bin/cli-wrapper.ts +0 -75
- package/src/database/knex-plugins/knex-on-duplicate-update.ts +0 -45
- package/src/entity/entity-utils.ts +0 -291
- package/src/templates/base-template.ts +0 -19
- package/src/templates/generated_sso.template.ts +0 -138
- package/src/templates/index.ts +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 템플릿 그룹 (관련 템플릿 묶음 실행)
|
|
3
|
+
*/
|
|
4
|
+
export type TemplateGroup = {
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
templates: Array<{
|
|
8
|
+
key: string;
|
|
9
|
+
getOptions: (baseOptions: Record<string, unknown>) => Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 템플릿 프리셋 (템플릿별 기본 옵션)
|
|
15
|
+
*/
|
|
16
|
+
export type TemplatePreset = Record<string, Record<string, unknown>>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import type { EntityNamesRecord } from "../entity/entity-manager";
|
|
3
|
+
import type { TemplateKey, TemplateOptions } from "../types/types";
|
|
4
|
+
import { globAsync } from "../utils/async-utils";
|
|
5
|
+
import { importMembers } from "../utils/esm-utils";
|
|
6
|
+
|
|
7
|
+
export type RenderedTemplate = {
|
|
8
|
+
target: string;
|
|
9
|
+
path: string;
|
|
10
|
+
body: string;
|
|
11
|
+
importKeys: string[];
|
|
12
|
+
customHeaders?: string[];
|
|
13
|
+
preTemplates?: {
|
|
14
|
+
key: TemplateKey;
|
|
15
|
+
options: TemplateOptions[TemplateKey];
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 템플릿을 나타내는 베이스 클래스입니다.
|
|
21
|
+
*/
|
|
22
|
+
export abstract class Template {
|
|
23
|
+
private static templates: Map<TemplateKey, Template> = new Map();
|
|
24
|
+
|
|
25
|
+
constructor(public key: TemplateKey) {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 템플릿 구현체가 있는 디렉토리의 모든 템플릿을 로드합니다.
|
|
29
|
+
* 템플릿이 필요(Template.find)해지기 전에 최소 한 번 호출해주셔야 합니다.
|
|
30
|
+
* @deprecated TemplateManager.autoload() 사용 권장
|
|
31
|
+
*/
|
|
32
|
+
public static async autoload() {
|
|
33
|
+
const templateFiles = await globAsync(
|
|
34
|
+
// Sonamu의 코드베이스는 항상 빌드된 채로 dist 속에 머무르므로,
|
|
35
|
+
// 현재 파일을 기준으로 마찬가지로 dist 속에 있는 템플릿 구현체 js 파일들을 찾습니다.
|
|
36
|
+
path.join(import.meta.dirname, "implementations/*.template.js"),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
for (const templateFile of templateFiles) {
|
|
40
|
+
// biome-ignore lint/suspicious/noExplicitAny: importMembers의 반환 타입을 명시적으로 지정할 수 없음
|
|
41
|
+
const templates = await importMembers<any>(templateFile);
|
|
42
|
+
if (
|
|
43
|
+
templates.length === 1 &&
|
|
44
|
+
typeof templates[0].value === "function" &&
|
|
45
|
+
templates[0].value.prototype instanceof Template
|
|
46
|
+
) {
|
|
47
|
+
// 클래스의 인스턴스를 생성하여 등록
|
|
48
|
+
const instance = new templates[0].value();
|
|
49
|
+
Template.templates.set(instance.key, instance);
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Template ${templateFile} should export only one class that extends Template`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// console.log(
|
|
58
|
+
// chalk.gray(`[Loading] Loaded ${this.templates.size} templates.`)
|
|
59
|
+
// );
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 템플릿 **인스턴스**를 key로 찾아옵니다.
|
|
64
|
+
* 만약 템플릿이 로드(loadAll)되지 않았거나 찾는 템플릿이 없다면 에러를 던집니다.
|
|
65
|
+
* @deprecated TemplateManager.get() 사용 권장
|
|
66
|
+
* @param key
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
public static find(key: TemplateKey): Template {
|
|
70
|
+
const instance = Template.templates.get(key);
|
|
71
|
+
if (!instance) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Template ${key} not found. It might be becasuse you tried to find a template before loading all templates. Did you call Template.loadAll()?`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return instance;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 내부용: TemplateManager에서 사용
|
|
81
|
+
*/
|
|
82
|
+
public static _getTemplatesMap(): Map<TemplateKey, Template> {
|
|
83
|
+
return Template.templates;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 내부용: TemplateManager에서 사용
|
|
88
|
+
*/
|
|
89
|
+
public static _clearTemplates(): void {
|
|
90
|
+
Template.templates.clear();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public abstract render(
|
|
94
|
+
options: TemplateOptions[TemplateKey],
|
|
95
|
+
...extra: unknown[]
|
|
96
|
+
): RenderedTemplate | Promise<RenderedTemplate>;
|
|
97
|
+
|
|
98
|
+
public abstract getTargetAndPath(
|
|
99
|
+
names?: EntityNamesRecord,
|
|
100
|
+
...extra: unknown[]
|
|
101
|
+
): {
|
|
102
|
+
target: string;
|
|
103
|
+
path: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zod-converter 구성
|
|
3
|
+
* 1. 유틸리티
|
|
4
|
+
* - getZodTypeById
|
|
5
|
+
*
|
|
6
|
+
* 2. Zod 타입 변환 (EntityProp -> ZodType)
|
|
7
|
+
* - propToZodType
|
|
8
|
+
*
|
|
9
|
+
* 3. EntityProp/Node -> Zod 코드 문자열
|
|
10
|
+
* - propToZodTypeDef
|
|
11
|
+
* - propNodeToZodTypeDef
|
|
12
|
+
*
|
|
13
|
+
* 4. Zod 타입 인스턴스를 해당하는 Zod 코드 문자열로 변환 (ZodType -> ZodCode)
|
|
14
|
+
* - zodTypeToZodCode
|
|
15
|
+
*
|
|
16
|
+
* 5. Zod 타입을 UI 렌더링에 사용할 수 있는 RenderingNode로 변환 (ZodType -> RenderingNode)
|
|
17
|
+
* - zodTypeToRenderingNode
|
|
18
|
+
* - resolveRenderType
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import inflection from "inflection";
|
|
22
|
+
import path from "path";
|
|
23
|
+
import { z } from "zod";
|
|
24
|
+
import type { $ZodLooseShape } from "zod/v4/core";
|
|
25
|
+
import { Sonamu } from "../api/sonamu";
|
|
26
|
+
import { EntityManager } from "../entity/entity-manager";
|
|
27
|
+
import {
|
|
28
|
+
type EntityProp,
|
|
29
|
+
type EntityPropNode,
|
|
30
|
+
isBelongsToOneRelationProp,
|
|
31
|
+
isBigIntegerArrayProp,
|
|
32
|
+
isBigIntegerSingleProp,
|
|
33
|
+
isBooleanArrayProp,
|
|
34
|
+
isBooleanSingleProp,
|
|
35
|
+
isDateArrayProp,
|
|
36
|
+
isDateSingleProp,
|
|
37
|
+
isEnumArrayProp,
|
|
38
|
+
isEnumSingleProp,
|
|
39
|
+
isIntegerArrayProp,
|
|
40
|
+
isIntegerSingleProp,
|
|
41
|
+
isJsonProp,
|
|
42
|
+
isNumberArrayProp,
|
|
43
|
+
isNumberSingleProp,
|
|
44
|
+
isNumericArrayProp,
|
|
45
|
+
isNumericSingleProp,
|
|
46
|
+
isOneToOneRelationProp,
|
|
47
|
+
isRelationProp,
|
|
48
|
+
isStringArrayProp,
|
|
49
|
+
isStringSingleProp,
|
|
50
|
+
isUuidArrayProp,
|
|
51
|
+
isUuidSingleProp,
|
|
52
|
+
isVirtualProp,
|
|
53
|
+
type RenderingNode,
|
|
54
|
+
} from "../types/types";
|
|
55
|
+
import { createImportUrl } from "../utils/esm-utils";
|
|
56
|
+
|
|
57
|
+
// <any>를 자제하고, Zod에서 제약하는 기본적인 Generic Type Parameter를 사용함.
|
|
58
|
+
type AnyZodRecord = z.ZodRecord<z.ZodString | z.ZodNumber | z.ZodSymbol, z.ZodType>;
|
|
59
|
+
type AnyZodObject = z.ZodObject<$ZodLooseShape>;
|
|
60
|
+
type AnyZodNullable = z.ZodNullable<z.ZodType>;
|
|
61
|
+
type AnyZodDefault = z.ZodDefault<z.ZodType>;
|
|
62
|
+
type AnyZodUnion = z.ZodUnion<z.ZodType[]>;
|
|
63
|
+
type AnyZodArray = z.ZodArray<z.ZodType>;
|
|
64
|
+
type AnyZodOptional = z.ZodOptional<z.ZodType>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Zod 타입 ID로부터 동적으로 Zod 스키마를 로드합니다.
|
|
68
|
+
* dist 디렉토리에서 ESM으로 import하여 가져옵니다.
|
|
69
|
+
*/
|
|
70
|
+
export async function getZodTypeById(zodTypeId: string): Promise<z.ZodTypeAny> {
|
|
71
|
+
const modulePath = EntityManager.getModulePath(zodTypeId);
|
|
72
|
+
const moduleAbsPath = path.join(Sonamu.apiRootPath, "dist", "application", `${modulePath}.js`);
|
|
73
|
+
const importUrl = createImportUrl(moduleAbsPath);
|
|
74
|
+
const imported = await import(importUrl);
|
|
75
|
+
|
|
76
|
+
if (!imported[zodTypeId]) {
|
|
77
|
+
throw new Error(`존재하지 않는 zodTypeId ${zodTypeId}`);
|
|
78
|
+
}
|
|
79
|
+
return imported[zodTypeId].describe(zodTypeId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* EntityProp을 Zod 타입으로 변환합니다.
|
|
84
|
+
* 각 prop의 타입에 따라 적절한 Zod validator를 생성합니다.
|
|
85
|
+
*/
|
|
86
|
+
export async function propToZodType(prop: EntityProp): Promise<z.ZodTypeAny> {
|
|
87
|
+
let zodType: z.ZodTypeAny = z.unknown();
|
|
88
|
+
if (isIntegerSingleProp(prop)) {
|
|
89
|
+
zodType = z.number().int();
|
|
90
|
+
} else if (isIntegerArrayProp(prop)) {
|
|
91
|
+
zodType = z.number().int().array();
|
|
92
|
+
} else if (isBigIntegerSingleProp(prop)) {
|
|
93
|
+
zodType = z.bigint();
|
|
94
|
+
} else if (isBigIntegerArrayProp(prop)) {
|
|
95
|
+
zodType = z.bigint().array();
|
|
96
|
+
} else if (isEnumSingleProp(prop)) {
|
|
97
|
+
zodType = await getZodTypeById(prop.id);
|
|
98
|
+
} else if (isEnumArrayProp(prop)) {
|
|
99
|
+
zodType = (await getZodTypeById(prop.id)).array();
|
|
100
|
+
} else if (isStringSingleProp(prop)) {
|
|
101
|
+
if (prop.length) {
|
|
102
|
+
zodType = z.string().max(prop.length);
|
|
103
|
+
} else {
|
|
104
|
+
zodType = z.string();
|
|
105
|
+
}
|
|
106
|
+
} else if (isStringArrayProp(prop)) {
|
|
107
|
+
if (prop.length) {
|
|
108
|
+
zodType = z.string().max(prop.length).array();
|
|
109
|
+
} else {
|
|
110
|
+
zodType = z.string().array();
|
|
111
|
+
}
|
|
112
|
+
} else if (isNumberSingleProp(prop)) {
|
|
113
|
+
zodType = z.number();
|
|
114
|
+
} else if (isNumberArrayProp(prop)) {
|
|
115
|
+
zodType = z.number().array();
|
|
116
|
+
} else if (isNumericSingleProp(prop)) {
|
|
117
|
+
zodType = z.string();
|
|
118
|
+
} else if (isNumericArrayProp(prop)) {
|
|
119
|
+
zodType = z.string().array();
|
|
120
|
+
} else if (isBooleanSingleProp(prop)) {
|
|
121
|
+
zodType = z.boolean();
|
|
122
|
+
} else if (isBooleanArrayProp(prop)) {
|
|
123
|
+
zodType = z.boolean().array();
|
|
124
|
+
} else if (isDateSingleProp(prop)) {
|
|
125
|
+
zodType = z.date();
|
|
126
|
+
} else if (isDateArrayProp(prop)) {
|
|
127
|
+
zodType = z.date().array();
|
|
128
|
+
} else if (isUuidSingleProp(prop)) {
|
|
129
|
+
zodType = z.uuid();
|
|
130
|
+
} else if (isUuidArrayProp(prop)) {
|
|
131
|
+
zodType = z.uuid().array();
|
|
132
|
+
} else if (isJsonProp(prop)) {
|
|
133
|
+
zodType = await getZodTypeById(prop.id);
|
|
134
|
+
} else if (isVirtualProp(prop)) {
|
|
135
|
+
zodType = await getZodTypeById(prop.id);
|
|
136
|
+
} else if (isRelationProp(prop)) {
|
|
137
|
+
if (isBelongsToOneRelationProp(prop) || (isOneToOneRelationProp(prop) && prop.hasJoinColumn)) {
|
|
138
|
+
zodType = z.number().int();
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
throw new Error(`prop을 zodType으로 변환하는데 실패 ${prop}}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if ((prop as { unsigned?: boolean }).unsigned) {
|
|
145
|
+
zodType = (zodType as z.ZodNumber).nonnegative();
|
|
146
|
+
}
|
|
147
|
+
if (prop.nullable) {
|
|
148
|
+
zodType = zodType.nullable();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return zodType;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* EntityProp을 Zod 타입 정의 코드 문자열로 변환합니다.
|
|
156
|
+
*/
|
|
157
|
+
export function propToZodTypeDef(prop: EntityProp, injectImportKeys: string[]): string {
|
|
158
|
+
let stmt: string;
|
|
159
|
+
if (isIntegerSingleProp(prop)) {
|
|
160
|
+
stmt = `${prop.name}: z.int()`;
|
|
161
|
+
} else if (isIntegerArrayProp(prop)) {
|
|
162
|
+
stmt = `${prop.name}: z.int().array()`;
|
|
163
|
+
} else if (isBigIntegerSingleProp(prop)) {
|
|
164
|
+
stmt = `${prop.name}: z.bigint()`;
|
|
165
|
+
} else if (isBigIntegerArrayProp(prop)) {
|
|
166
|
+
stmt = `${prop.name}: z.bigint().array()`;
|
|
167
|
+
} else if (isEnumSingleProp(prop)) {
|
|
168
|
+
stmt = `${prop.name}: ${prop.id}`;
|
|
169
|
+
injectImportKeys.push(prop.id);
|
|
170
|
+
} else if (isEnumArrayProp(prop)) {
|
|
171
|
+
stmt = `${prop.name}: ${prop.id}.array()`;
|
|
172
|
+
injectImportKeys.push(prop.id);
|
|
173
|
+
} else if (isStringSingleProp(prop)) {
|
|
174
|
+
if (prop.length) {
|
|
175
|
+
stmt = `${prop.name}: z.string().max(${prop.length})`;
|
|
176
|
+
} else {
|
|
177
|
+
stmt = `${prop.name}: z.string()`;
|
|
178
|
+
}
|
|
179
|
+
} else if (isStringArrayProp(prop)) {
|
|
180
|
+
if (prop.length) {
|
|
181
|
+
stmt = `${prop.name}: z.string().max(${prop.length}).array()`;
|
|
182
|
+
} else {
|
|
183
|
+
stmt = `${prop.name}: z.string().array()`;
|
|
184
|
+
}
|
|
185
|
+
} else if (isNumberSingleProp(prop)) {
|
|
186
|
+
stmt = `${prop.name}: z.number()`;
|
|
187
|
+
} else if (isNumberArrayProp(prop)) {
|
|
188
|
+
stmt = `${prop.name}: z.number().array()`;
|
|
189
|
+
} else if (isNumericSingleProp(prop)) {
|
|
190
|
+
stmt = `${prop.name}: z.string()`;
|
|
191
|
+
} else if (isNumericArrayProp(prop)) {
|
|
192
|
+
stmt = `${prop.name}: z.string().array()`;
|
|
193
|
+
} else if (isDateSingleProp(prop)) {
|
|
194
|
+
stmt = `${prop.name}: z.date()`;
|
|
195
|
+
} else if (isDateArrayProp(prop)) {
|
|
196
|
+
stmt = `${prop.name}: z.date().array()`;
|
|
197
|
+
} else if (isBooleanSingleProp(prop)) {
|
|
198
|
+
stmt = `${prop.name}: z.boolean()`;
|
|
199
|
+
} else if (isBooleanArrayProp(prop)) {
|
|
200
|
+
stmt = `${prop.name}: z.boolean().array()`;
|
|
201
|
+
} else if (isUuidSingleProp(prop)) {
|
|
202
|
+
stmt = `${prop.name}: z.uuid()`;
|
|
203
|
+
} else if (isUuidArrayProp(prop)) {
|
|
204
|
+
stmt = `${prop.name}: z.uuid().array()`;
|
|
205
|
+
} else if (isJsonProp(prop)) {
|
|
206
|
+
stmt = `${prop.name}: ${prop.id}`;
|
|
207
|
+
injectImportKeys.push(prop.id);
|
|
208
|
+
} else if (isVirtualProp(prop)) {
|
|
209
|
+
stmt = `${prop.name}: ${prop.id}`;
|
|
210
|
+
injectImportKeys.push(prop.id);
|
|
211
|
+
} else if (isRelationProp(prop)) {
|
|
212
|
+
if (isBelongsToOneRelationProp(prop) || (isOneToOneRelationProp(prop) && prop.hasJoinColumn)) {
|
|
213
|
+
stmt = `${prop.name}_id: z.int()`;
|
|
214
|
+
} else {
|
|
215
|
+
// 그외 relation 케이스 제외
|
|
216
|
+
return `// ${prop.name}: ${prop.relationType} ${prop.with}`;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
return "// unable to resolve";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if ((prop as { unsigned?: boolean }).unsigned) {
|
|
223
|
+
stmt += ".nonnegative()";
|
|
224
|
+
}
|
|
225
|
+
if (prop.nullable) {
|
|
226
|
+
stmt += ".nullable()";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return `${stmt},`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* EntityPropNode를 Zod 타입 정의 코드 문자열로 변환합니다.
|
|
234
|
+
* plain, array, object 노드 타입을 재귀적으로 처리하여 중첩 구조를 지원합니다.
|
|
235
|
+
*/
|
|
236
|
+
export function propNodeToZodTypeDef(propNode: EntityPropNode, injectImportKeys: string[]): string {
|
|
237
|
+
if (propNode.nodeType === "plain") {
|
|
238
|
+
return propToZodTypeDef(propNode.prop, injectImportKeys);
|
|
239
|
+
} else if (propNode.nodeType === "array") {
|
|
240
|
+
return [
|
|
241
|
+
propNode.prop ? `${propNode.prop.name}: ` : "",
|
|
242
|
+
"z.array(z.object({",
|
|
243
|
+
propNode.children
|
|
244
|
+
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys))
|
|
245
|
+
.join("\n"),
|
|
246
|
+
"",
|
|
247
|
+
"})),",
|
|
248
|
+
].join("\n");
|
|
249
|
+
} else if (propNode.nodeType === "object") {
|
|
250
|
+
return [
|
|
251
|
+
propNode.prop ? `${propNode.prop.name}: ` : "",
|
|
252
|
+
"z.object({",
|
|
253
|
+
propNode.children
|
|
254
|
+
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys))
|
|
255
|
+
.join("\n"),
|
|
256
|
+
"",
|
|
257
|
+
`})${propNode.prop?.nullable ? ".nullable()" : ""},`,
|
|
258
|
+
].join("\n");
|
|
259
|
+
} else {
|
|
260
|
+
throw Error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
|
|
265
|
+
export function zodTypeToTsTypeDef(zt: z.ZodType): string {
|
|
266
|
+
switch (zt.def.type) {
|
|
267
|
+
case "string":
|
|
268
|
+
case "number":
|
|
269
|
+
case "boolean":
|
|
270
|
+
case "bigint":
|
|
271
|
+
case "date":
|
|
272
|
+
case "null":
|
|
273
|
+
case "undefined":
|
|
274
|
+
case "any":
|
|
275
|
+
case "unknown":
|
|
276
|
+
case "never":
|
|
277
|
+
return zt.def.type;
|
|
278
|
+
case "nullable":
|
|
279
|
+
return `${zodTypeToTsTypeDef((zt as AnyZodNullable).def.innerType)} | null`;
|
|
280
|
+
case "default":
|
|
281
|
+
return zodTypeToTsTypeDef((zt as AnyZodDefault).def.innerType);
|
|
282
|
+
case "record": {
|
|
283
|
+
const recordType = zt as AnyZodRecord;
|
|
284
|
+
return `{ [ key: ${zodTypeToTsTypeDef(recordType.def.keyType)} ]: ${zodTypeToTsTypeDef(recordType.def.valueType)}}`;
|
|
285
|
+
}
|
|
286
|
+
case "literal":
|
|
287
|
+
return Array.from((zt as z.ZodLiteral).values)
|
|
288
|
+
.map((value) => {
|
|
289
|
+
if (typeof value === "string") {
|
|
290
|
+
return `"${value}"`;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (value === null) {
|
|
294
|
+
return `null`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (value === undefined) {
|
|
298
|
+
return `undefined`;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return `${value}`;
|
|
302
|
+
})
|
|
303
|
+
.join(" | ");
|
|
304
|
+
case "union":
|
|
305
|
+
return `${(zt as AnyZodUnion).options
|
|
306
|
+
.map((option) => zodTypeToTsTypeDef(option))
|
|
307
|
+
.join(" | ")}`;
|
|
308
|
+
case "enum":
|
|
309
|
+
return `${(zt as z.ZodEnum).options.map((val) => `"${val}"`).join(" | ")}`;
|
|
310
|
+
case "array":
|
|
311
|
+
return `${zodTypeToTsTypeDef((zt as AnyZodArray).element)}[]`;
|
|
312
|
+
case "object": {
|
|
313
|
+
const shape = (zt as AnyZodObject).shape;
|
|
314
|
+
return [
|
|
315
|
+
"{",
|
|
316
|
+
...Object.keys(shape).map((key) => {
|
|
317
|
+
if (shape[key].def.type === "optional") {
|
|
318
|
+
return `${key}?: ${zodTypeToTsTypeDef(shape[key].def.innerType)},`;
|
|
319
|
+
} else {
|
|
320
|
+
return `${key}: ${zodTypeToTsTypeDef(shape[key])},`;
|
|
321
|
+
}
|
|
322
|
+
}),
|
|
323
|
+
"}",
|
|
324
|
+
].join("\n");
|
|
325
|
+
}
|
|
326
|
+
case "optional":
|
|
327
|
+
return `${zodTypeToTsTypeDef((zt as AnyZodOptional).def.innerType)} | undefined`;
|
|
328
|
+
default:
|
|
329
|
+
throw new Error(`처리되지 않은 ZodType ${zt.def.type}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
|
|
334
|
+
/**
|
|
335
|
+
* Zod 타입 인스턴스를 해당하는 Zod 코드 문자열로 변환합니다.
|
|
336
|
+
*/
|
|
337
|
+
export function zodTypeToZodCode(zt: z.ZodType): string {
|
|
338
|
+
switch (zt.def.type) {
|
|
339
|
+
case "string":
|
|
340
|
+
return "z.string()";
|
|
341
|
+
case "number":
|
|
342
|
+
return "z.number()";
|
|
343
|
+
case "bigint":
|
|
344
|
+
return "z.bigint()";
|
|
345
|
+
case "boolean":
|
|
346
|
+
return "z.boolean()";
|
|
347
|
+
case "date":
|
|
348
|
+
return "z.date()";
|
|
349
|
+
case "null":
|
|
350
|
+
return "z.null()";
|
|
351
|
+
case "undefined":
|
|
352
|
+
return "z.undefined()";
|
|
353
|
+
case "any":
|
|
354
|
+
return "z.any()";
|
|
355
|
+
case "unknown":
|
|
356
|
+
return "z.unknown()";
|
|
357
|
+
case "never":
|
|
358
|
+
return "z.never()";
|
|
359
|
+
case "nullable":
|
|
360
|
+
return `${zodTypeToZodCode((zt as AnyZodNullable).def.innerType)}.nullable()`;
|
|
361
|
+
case "default": {
|
|
362
|
+
const zDefaultDef = (zt as AnyZodDefault).def;
|
|
363
|
+
return `${zodTypeToZodCode(zDefaultDef.innerType)}.default(${zDefaultDef.defaultValue})`;
|
|
364
|
+
}
|
|
365
|
+
case "record": {
|
|
366
|
+
const zRecordDef = (zt as AnyZodRecord).def;
|
|
367
|
+
return `z.record(${zodTypeToZodCode(zRecordDef.keyType)}, ${zodTypeToZodCode(
|
|
368
|
+
zRecordDef.valueType,
|
|
369
|
+
)})`;
|
|
370
|
+
}
|
|
371
|
+
case "literal": {
|
|
372
|
+
const items = Array.from((zt as z.ZodLiteral<string | number>).values).map((value) => {
|
|
373
|
+
if (typeof value === "string") {
|
|
374
|
+
return `"${value}"`;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (value === null) {
|
|
378
|
+
return `null`;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (value === undefined) {
|
|
382
|
+
return `undefined`;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return `${value}`;
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (items.length === 1) {
|
|
389
|
+
return `z.literal(${items[0]})`;
|
|
390
|
+
}
|
|
391
|
+
return `z.literal([${items.join(", ")}])`;
|
|
392
|
+
}
|
|
393
|
+
case "union":
|
|
394
|
+
return `z.union([${(zt as AnyZodUnion).def.options
|
|
395
|
+
.map((option: z.ZodType) => zodTypeToZodCode(option))
|
|
396
|
+
.join(",")}])`;
|
|
397
|
+
case "enum":
|
|
398
|
+
// NOTE: z.enum(["A", "B"])도 z.enum({ A: "A", B: "B" })로 처리됨.
|
|
399
|
+
return `z.enum({${Object.entries((zt as z.ZodEnum).def.entries)
|
|
400
|
+
.map(([key, val]) => (typeof val === "string" ? `${key}: "${val}"` : `${key}: ${val}`))
|
|
401
|
+
.join(", ")}})`;
|
|
402
|
+
case "array":
|
|
403
|
+
return `z.array(${zodTypeToZodCode((zt as z.ZodArray<z.ZodType>).def.element)})`;
|
|
404
|
+
case "object": {
|
|
405
|
+
const shape = (zt as AnyZodObject).shape;
|
|
406
|
+
return [
|
|
407
|
+
"z.object({",
|
|
408
|
+
...Object.keys(shape).map((key) => `${key}: ${zodTypeToZodCode(shape[key])},`),
|
|
409
|
+
"})",
|
|
410
|
+
].join("\n");
|
|
411
|
+
}
|
|
412
|
+
case "optional":
|
|
413
|
+
return `${zodTypeToZodCode((zt as z.ZodOptional<z.ZodType>).def.innerType)}.optional()`;
|
|
414
|
+
case "file":
|
|
415
|
+
return `z.file()`;
|
|
416
|
+
case "intersection": {
|
|
417
|
+
const zIntersectionDef = (zt as z.ZodIntersection<z.ZodType, z.ZodType>).def;
|
|
418
|
+
return `z.intersection(${zodTypeToZodCode(zIntersectionDef.left)}, ${zodTypeToZodCode(zIntersectionDef.right)})`;
|
|
419
|
+
}
|
|
420
|
+
default:
|
|
421
|
+
throw new Error(`처리되지 않은 ZodType ${zt.def.type}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Zod 타입을 UI 렌더링에 사용할 수 있는 RenderingNode로 변환합니다.
|
|
427
|
+
* 재귀적으로 중첩된 타입들을 처리합니다.
|
|
428
|
+
*/
|
|
429
|
+
export function zodTypeToRenderingNode(
|
|
430
|
+
zodType: z.ZodTypeAny,
|
|
431
|
+
baseKey: string = "root",
|
|
432
|
+
): RenderingNode {
|
|
433
|
+
const def = {
|
|
434
|
+
name: baseKey,
|
|
435
|
+
label: inflection.camelize(baseKey, false),
|
|
436
|
+
zodType,
|
|
437
|
+
};
|
|
438
|
+
if (zodType instanceof z.ZodObject) {
|
|
439
|
+
const columnKeys = Object.keys(zodType.shape);
|
|
440
|
+
const children = columnKeys.map((key) => {
|
|
441
|
+
const innerType = zodType.shape[key];
|
|
442
|
+
return zodTypeToRenderingNode(innerType, key);
|
|
443
|
+
});
|
|
444
|
+
return {
|
|
445
|
+
...def,
|
|
446
|
+
renderType: "object",
|
|
447
|
+
children,
|
|
448
|
+
};
|
|
449
|
+
} else if (zodType instanceof z.ZodArray) {
|
|
450
|
+
const innerType = (zodType as z.ZodArray<z.ZodTypeAny>).def.element;
|
|
451
|
+
if (innerType instanceof z.ZodString && baseKey.includes("images")) {
|
|
452
|
+
return {
|
|
453
|
+
...def,
|
|
454
|
+
renderType: "array-images",
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
...def,
|
|
459
|
+
renderType: "array",
|
|
460
|
+
element: zodTypeToRenderingNode(innerType, baseKey),
|
|
461
|
+
};
|
|
462
|
+
} else if (zodType instanceof z.ZodUnion) {
|
|
463
|
+
const optionNodes = (zodType as z.ZodUnion<z.ZodType[]>).def.options.map((opt) =>
|
|
464
|
+
zodTypeToRenderingNode(opt, baseKey),
|
|
465
|
+
);
|
|
466
|
+
// TODO: ZodUnion이 들어있는 경우 핸들링
|
|
467
|
+
return optionNodes[0];
|
|
468
|
+
} else if (zodType instanceof z.ZodOptional) {
|
|
469
|
+
return {
|
|
470
|
+
...zodTypeToRenderingNode((zodType as z.ZodOptional<z.ZodType>).def.innerType, baseKey),
|
|
471
|
+
optional: true,
|
|
472
|
+
};
|
|
473
|
+
} else if (zodType instanceof z.ZodNullable) {
|
|
474
|
+
return {
|
|
475
|
+
...zodTypeToRenderingNode((zodType as z.ZodNullable<z.ZodType>).def.innerType, baseKey),
|
|
476
|
+
nullable: true,
|
|
477
|
+
};
|
|
478
|
+
} else {
|
|
479
|
+
return {
|
|
480
|
+
...def,
|
|
481
|
+
renderType: resolveRenderType(baseKey, zodType),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Zod 타입과 키 이름으로부터 적절한 RenderType을 결정합니다.
|
|
488
|
+
*/
|
|
489
|
+
function resolveRenderType(key: string, zodType: z.ZodTypeAny): RenderingNode["renderType"] {
|
|
490
|
+
if (zodType instanceof z.ZodDate) {
|
|
491
|
+
return "datetime";
|
|
492
|
+
} else if (zodType instanceof z.ZodString) {
|
|
493
|
+
if (key.includes("img") || key.includes("image")) {
|
|
494
|
+
return "string-image";
|
|
495
|
+
} else if (zodType.description === "SQLDateTimeString") {
|
|
496
|
+
return "string-datetime";
|
|
497
|
+
} else if (key.endsWith("date")) {
|
|
498
|
+
return "string-date";
|
|
499
|
+
} else {
|
|
500
|
+
return "string-plain";
|
|
501
|
+
}
|
|
502
|
+
} else if (zodType instanceof z.ZodNumber) {
|
|
503
|
+
if (key === "id") {
|
|
504
|
+
return "number-id";
|
|
505
|
+
} else if (key.endsWith("_id")) {
|
|
506
|
+
return "number-fk_id";
|
|
507
|
+
} else {
|
|
508
|
+
return "number-plain";
|
|
509
|
+
}
|
|
510
|
+
} else if (zodType instanceof z.ZodBoolean) {
|
|
511
|
+
return "boolean";
|
|
512
|
+
} else if (zodType instanceof z.ZodEnum) {
|
|
513
|
+
return "enums";
|
|
514
|
+
} else if (zodType instanceof z.ZodRecord) {
|
|
515
|
+
return "record";
|
|
516
|
+
} else if (zodType instanceof z.ZodAny || zodType instanceof z.ZodUnknown) {
|
|
517
|
+
return "string-plain";
|
|
518
|
+
} else if (zodType instanceof z.ZodUnion) {
|
|
519
|
+
return "string-plain";
|
|
520
|
+
} else if (zodType instanceof z.ZodLiteral) {
|
|
521
|
+
return "string-plain";
|
|
522
|
+
} else {
|
|
523
|
+
throw new Error(`타입 파싱 불가 ${key} ${zodType.def.type}`);
|
|
524
|
+
}
|
|
525
|
+
}
|