sonamu 0.5.7 → 0.6.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/dist/api/base-frame.js +12 -2
- package/dist/api/caster.js +66 -2
- package/dist/api/code-converters.js +489 -2
- package/dist/api/config.d.ts +76 -0
- package/dist/api/config.d.ts.map +1 -0
- package/dist/api/config.js +32 -0
- package/dist/api/context.d.ts +1 -0
- package/dist/api/context.d.ts.map +1 -1
- package/dist/api/context.js +3 -2
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +142 -2
- package/dist/api/index.js +9 -2
- package/dist/api/sonamu.d.ts +8 -22
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +482 -2
- package/dist/bin/build-config.d.ts +2 -1
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +12 -2
- package/dist/bin/cli-wrapper.js +71 -2
- package/dist/bin/cli.js +418 -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/database/_batch_update.js +78 -2
- package/dist/database/base-model.js +247 -2
- package/dist/database/code-generator.js +53 -2
- package/dist/database/db.d.ts +2 -16
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +132 -2
- package/dist/database/knex-plugins/knex-on-duplicate-update.js +39 -2
- package/dist/database/puri-wrapper.js +109 -2
- package/dist/database/puri.d.ts +23 -16
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +539 -2
- package/dist/database/puri.types.d.ts +8 -3
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +3 -2
- package/dist/database/transaction-context.js +14 -2
- package/dist/database/upsert-builder.js +215 -2
- package/dist/entity/entity-manager.d.ts +3 -1
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +114 -2
- package/dist/entity/entity-utils.js +210 -2
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +651 -2
- package/dist/exceptions/error-handler.js +29 -2
- package/dist/exceptions/so-exceptions.js +85 -2
- package/dist/file-storage/driver.js +79 -2
- package/dist/file-storage/file-storage.js +75 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/migration/code-generation.js +558 -2
- package/dist/migration/migration-set.js +364 -2
- package/dist/migration/migrator.d.ts +0 -9
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +510 -2
- package/dist/migration/types.js +3 -2
- package/dist/naite/naite.d.ts +12 -0
- package/dist/naite/naite.d.ts.map +1 -0
- package/dist/naite/naite.js +72 -0
- package/dist/stream/index.js +3 -2
- package/dist/stream/sse.js +38 -2
- package/dist/syncer/api-parser.d.ts +20 -0
- package/dist/syncer/api-parser.d.ts.map +1 -0
- package/dist/syncer/api-parser.js +229 -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 +141 -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 +58 -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 +82 -0
- package/dist/syncer/syncer.d.ts +93 -108
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +375 -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 +101 -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 +87 -0
- package/dist/{templates → template/implementations}/generated.template.d.ts +3 -3
- package/dist/template/implementations/generated.template.d.ts.map +1 -0
- package/dist/template/implementations/generated.template.js +232 -0
- package/dist/{templates → template/implementations}/generated_http.template.d.ts +3 -3
- 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 +3 -3
- package/dist/template/implementations/generated_sso.template.d.ts.map +1 -0
- package/dist/template/implementations/generated_sso.template.js +105 -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 +171 -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 +193 -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 +465 -0
- package/dist/{templates → template/implementations}/view_list_columns.template.d.ts +3 -3
- 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 +5 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +6 -0
- package/dist/template/template.d.ts +39 -0
- package/dist/template/template.d.ts.map +1 -0
- package/dist/template/template.js +47 -0
- package/dist/template/zod-converter.d.ts +18 -0
- package/dist/template/zod-converter.d.ts.map +1 -0
- package/dist/template/zod-converter.js +166 -0
- package/dist/testing/_relation-graph.js +80 -2
- package/dist/testing/fixture-manager.d.ts.map +1 -1
- package/dist/testing/fixture-manager.js +521 -2
- package/dist/types/types.d.ts +39 -40
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +289 -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.js +26 -2
- package/dist/utils/esm-utils.d.ts +45 -0
- package/dist/utils/esm-utils.d.ts.map +1 -0
- package/dist/utils/esm-utils.js +56 -0
- package/dist/utils/fs-utils.js +17 -2
- package/dist/utils/lodash-able.js +6 -2
- package/dist/utils/model.js +22 -2
- 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.js +35 -2
- package/dist/utils/utils.d.ts +4 -7
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +33 -2
- package/dist/utils/zod-error.d.ts.map +1 -1
- package/dist/utils/zod-error.js +19 -2
- package/package.json +21 -8
- package/src/api/code-converters.ts +2 -2
- package/src/api/config.ts +142 -0
- package/src/api/context.ts +1 -0
- package/src/api/decorators.ts +1 -0
- package/src/api/sonamu.ts +81 -67
- package/src/bin/build-config.ts +2 -1
- package/src/bin/cli-wrapper.ts +10 -3
- package/src/bin/cli.ts +108 -56
- package/src/bin/hot-hook-register.ts +22 -0
- package/src/database/base-model.ts +1 -1
- package/src/database/code-generator.ts +1 -1
- package/src/database/db.ts +10 -52
- package/src/database/puri.ts +78 -53
- package/src/database/puri.types.ts +18 -5
- package/src/database/upsert-builder.ts +1 -1
- package/src/entity/entity-manager.ts +19 -15
- package/src/entity/entity.ts +4 -3
- package/src/index.ts +2 -0
- package/src/migration/code-generation.ts +1 -1
- package/src/migration/migration-set.ts +1 -1
- package/src/migration/migrator.ts +23 -152
- package/src/naite/naite.ts +70 -0
- package/src/syncer/api-parser.ts +299 -0
- package/src/syncer/checksum.ts +152 -0
- package/src/syncer/code-generator.ts +202 -0
- package/src/syncer/entity-operations.ts +68 -0
- package/src/syncer/file-patterns.ts +56 -0
- package/src/syncer/index.ts +6 -0
- package/src/syncer/module-loader.ts +125 -0
- package/src/syncer/syncer.ts +363 -1420
- package/src/template/entity-converter.ts +123 -0
- package/src/template/helpers.ts +84 -0
- package/src/{templates → template/implementations}/entity.template.ts +4 -4
- package/src/{templates → template/implementations}/generated.template.ts +9 -9
- package/src/{templates → template/implementations}/generated_http.template.ts +9 -6
- package/src/{templates → template/implementations}/generated_sso.template.ts +7 -7
- package/src/{templates → template/implementations}/init_types.template.ts +4 -4
- package/src/{templates → template/implementations}/model.template.ts +9 -9
- package/src/{templates → template/implementations}/model_test.template.ts +5 -5
- package/src/{templates → template/implementations}/service.template.ts +19 -11
- package/src/{templates → template/implementations}/view_enums_buttonset.template.ts +3 -3
- package/src/{templates → template/implementations}/view_enums_dropdown.template.ts +5 -21
- package/src/{templates → template/implementations}/view_enums_select.template.ts +4 -4
- package/src/{templates → template/implementations}/view_form.template.ts +11 -13
- package/src/{templates → template/implementations}/view_id_all_select.template.ts +3 -3
- package/src/{templates → template/implementations}/view_id_async_select.template.ts +3 -3
- package/src/{templates → template/implementations}/view_list.template.ts +13 -64
- package/src/{templates → template/implementations}/view_list_columns.template.ts +3 -3
- package/src/{templates → template/implementations}/view_search_input.template.ts +3 -3
- package/src/template/index.ts +4 -0
- package/src/template/template.ts +86 -0
- package/src/template/zod-converter.ts +219 -0
- package/src/testing/fixture-manager.ts +8 -1
- package/src/types/types.ts +38 -61
- package/src/utils/async-utils.ts +17 -0
- package/src/utils/console-util.ts +4 -0
- package/src/utils/esm-utils.ts +69 -0
- package/src/utils/path-utils.ts +102 -0
- package/src/utils/process-utils.ts +46 -0
- package/src/utils/sql-parser.ts +1 -1
- package/src/utils/utils.ts +14 -40
- package/src/utils/zod-error.ts +0 -1
- 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.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.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.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.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/templates/base-template.ts +0 -19
- package/src/templates/index.ts +0 -1
package/src/bin/cli-wrapper.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
TSC_TYPE_CHECK_COMMAND,
|
|
11
11
|
} from "./build-config";
|
|
12
12
|
|
|
13
|
-
const scriptPath = resolve(
|
|
13
|
+
const scriptPath = resolve(import.meta.dirname, "cli.js");
|
|
14
14
|
const args = process.argv.slice(2);
|
|
15
15
|
|
|
16
16
|
// build 명령어는 dist 없이도 실행 가능하도록 cli.ts 외부에서 처리(Sonamu.init에서 dist 필요)
|
|
@@ -56,7 +56,7 @@ if (args[0] === "build") {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (args[0] === "dev:serve") {
|
|
59
|
-
build();
|
|
59
|
+
// build();
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!existsSync(scriptPath)) {
|
|
@@ -66,7 +66,14 @@ if (!existsSync(scriptPath)) {
|
|
|
66
66
|
|
|
67
67
|
const result = spawnSync(
|
|
68
68
|
process.execPath,
|
|
69
|
-
[
|
|
69
|
+
[
|
|
70
|
+
"--import",
|
|
71
|
+
"@sonamu-kit/loader", // Sonamu UI도 syncer를 다루므로, ts 로드 능력이 필요합니다.
|
|
72
|
+
"--enable-source-maps",
|
|
73
|
+
"--no-warnings",
|
|
74
|
+
scriptPath,
|
|
75
|
+
...args
|
|
76
|
+
],
|
|
70
77
|
{
|
|
71
78
|
stdio: "inherit",
|
|
72
79
|
}
|
package/src/bin/cli.ts
CHANGED
|
@@ -3,25 +3,24 @@ import dotenv from "dotenv";
|
|
|
3
3
|
dotenv.config();
|
|
4
4
|
|
|
5
5
|
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
6
7
|
import { tsicli } from "tsicli";
|
|
7
|
-
import { execSync } from "child_process";
|
|
8
|
-
import { mkdir, readdir,
|
|
8
|
+
import { execSync, spawn } from "child_process";
|
|
9
|
+
import { mkdir, readdir, writeFile } from "fs/promises";
|
|
9
10
|
import { exists } from "../utils/fs-utils";
|
|
10
11
|
import process from "process";
|
|
11
12
|
import { Sonamu } from "../api";
|
|
12
13
|
import knex, { Knex } from "knex";
|
|
13
|
-
import { findApiRootPath } from "../utils/utils";
|
|
14
14
|
import { EntityManager } from "../entity/entity-manager";
|
|
15
15
|
import { Migrator } from "../migration/migrator";
|
|
16
16
|
import { FixtureManager } from "../testing/fixture-manager";
|
|
17
|
-
|
|
18
|
-
import { NodemonSettings } from "nodemon";
|
|
17
|
+
import { findApiRootPath } from "../utils/utils";
|
|
19
18
|
|
|
20
19
|
let migrator: Migrator;
|
|
21
20
|
|
|
22
21
|
async function bootstrap() {
|
|
23
|
-
// dev
|
|
24
|
-
if (process.argv[2] !== "dev
|
|
22
|
+
// dev 명령어가 아닌 경우에만 Sonamu 초기화
|
|
23
|
+
if (process.argv[2] !== "dev") {
|
|
25
24
|
await Sonamu.init(false, false);
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -56,8 +55,8 @@ async function bootstrap() {
|
|
|
56
55
|
["scaffold", "view_list", "#entityId"],
|
|
57
56
|
["scaffold", "view_form", "#entityId"],
|
|
58
57
|
["ui"],
|
|
59
|
-
["dev
|
|
60
|
-
["
|
|
58
|
+
["dev"],
|
|
59
|
+
["start"],
|
|
61
60
|
],
|
|
62
61
|
runners: {
|
|
63
62
|
migrate_run,
|
|
@@ -76,8 +75,8 @@ async function bootstrap() {
|
|
|
76
75
|
ui,
|
|
77
76
|
// scaffold_view_list,
|
|
78
77
|
// scaffold_view_form,
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
dev,
|
|
79
|
+
start,
|
|
81
80
|
},
|
|
82
81
|
});
|
|
83
82
|
}
|
|
@@ -88,45 +87,57 @@ bootstrap().finally(async () => {
|
|
|
88
87
|
await FixtureManager.destroy();
|
|
89
88
|
});
|
|
90
89
|
|
|
91
|
-
async function
|
|
92
|
-
const
|
|
90
|
+
async function dev() {
|
|
91
|
+
const apiRoot = findApiRootPath();
|
|
92
|
+
const entryPoint = 'src/index.ts';
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
const projectNodemonPath = path.join(findApiRootPath(), "nodemon.json");
|
|
96
|
-
const hasProjectNodemon = await exists(projectNodemonPath);
|
|
94
|
+
console.log(chalk.yellow.bold('🚀 Starting Sonamu dev server...\n'));
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const serverProcess = spawn(
|
|
97
|
+
"hot-runner",
|
|
98
|
+
[
|
|
99
|
+
"--clear-screen=false",
|
|
100
|
+
"--node-args=--import=@sonamu-kit/loader",
|
|
101
|
+
"--node-args=--import=sonamu/hot-hook-register",
|
|
102
|
+
"--node-args=--enable-source-maps",
|
|
103
|
+
entryPoint,
|
|
104
|
+
],
|
|
105
|
+
{
|
|
106
|
+
cwd: apiRoot,
|
|
107
|
+
stdio: "inherit",
|
|
108
|
+
env: {
|
|
109
|
+
...process.env,
|
|
110
|
+
NODE_ENV: "development",
|
|
111
|
+
HOT: "yes",
|
|
112
|
+
API_ROOT_PATH: apiRoot,
|
|
113
|
+
},
|
|
100
114
|
}
|
|
115
|
+
);
|
|
101
116
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// SWC_BUILD_COMMAND,
|
|
107
|
-
"node --no-warnings -r source-map-support/register -r dotenv/config dist/index.js",
|
|
108
|
-
].join(" && "),
|
|
109
|
-
} as NodemonSettings;
|
|
110
|
-
})();
|
|
111
|
-
nodemon.default(nodemonConfig);
|
|
112
|
-
|
|
113
|
-
// 프로세스 종료 처리
|
|
114
|
-
const cleanup = async () => {
|
|
115
|
-
await Sonamu.server?.close();
|
|
117
|
+
// 종료 처리
|
|
118
|
+
const cleanup = () => {
|
|
119
|
+
console.log(chalk.yellow('\n\n👋 Shutting down...'));
|
|
120
|
+
serverProcess.kill('SIGTERM');
|
|
116
121
|
process.exit(0);
|
|
117
122
|
};
|
|
118
123
|
|
|
119
|
-
process.on(
|
|
120
|
-
process.on(
|
|
121
|
-
|
|
124
|
+
process.on('SIGINT', cleanup);
|
|
125
|
+
process.on('SIGTERM', cleanup);
|
|
126
|
+
|
|
127
|
+
serverProcess.on('exit', (code) => {
|
|
128
|
+
if (code !== 0) {
|
|
129
|
+
console.error(chalk.red(`❌ Server exited with code ${code}`));
|
|
130
|
+
process.exit(code || 1);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
async function
|
|
125
|
-
const
|
|
135
|
+
async function start() {
|
|
136
|
+
const entryPoint = 'dist/index.js';
|
|
126
137
|
|
|
127
|
-
if (!(await exists(
|
|
138
|
+
if (!(await exists(entryPoint))) {
|
|
128
139
|
console.log(
|
|
129
|
-
chalk.red(
|
|
140
|
+
chalk.red(`${entryPoint} not found. Please build your project first.`)
|
|
130
141
|
);
|
|
131
142
|
console.log(chalk.blue("Run: yarn sonamu build"));
|
|
132
143
|
return;
|
|
@@ -135,7 +146,7 @@ async function serve() {
|
|
|
135
146
|
const { spawn } = await import("child_process");
|
|
136
147
|
const serverProcess = spawn(
|
|
137
148
|
"node",
|
|
138
|
-
["-
|
|
149
|
+
["--enable-source-maps", "-r", "dotenv/config", entryPoint],
|
|
139
150
|
{
|
|
140
151
|
cwd: Sonamu.apiRootPath,
|
|
141
152
|
stdio: "inherit",
|
|
@@ -162,14 +173,12 @@ async function setupFixtureManager() {
|
|
|
162
173
|
async function migrate_run() {
|
|
163
174
|
await setupMigrator();
|
|
164
175
|
|
|
165
|
-
await migrator.cleanUpDist();
|
|
166
176
|
await migrator.run();
|
|
167
177
|
}
|
|
168
178
|
|
|
169
179
|
async function migrate_check() {
|
|
170
180
|
await setupMigrator();
|
|
171
181
|
|
|
172
|
-
await migrator.cleanUpDist();
|
|
173
182
|
await migrator.check();
|
|
174
183
|
}
|
|
175
184
|
|
|
@@ -347,7 +356,7 @@ async function stub_practice(name: string) {
|
|
|
347
356
|
|
|
348
357
|
execSync(`code ${dstPath}`);
|
|
349
358
|
|
|
350
|
-
const runCode = `yarn node -r dotenv/config -
|
|
359
|
+
const runCode = `yarn node -r dotenv/config --enable-source-maps dist/practices/${fileName.replace(
|
|
351
360
|
".ts",
|
|
352
361
|
".js"
|
|
353
362
|
)}`;
|
|
@@ -373,23 +382,66 @@ async function scaffold_model_test(entityId: string) {
|
|
|
373
382
|
|
|
374
383
|
async function ui() {
|
|
375
384
|
try {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
385
|
+
// @sonamu-kit/ui의 run-ui.ts 스크립트 경로 찾기
|
|
386
|
+
const uiModulePath = await import.meta.resolve("@sonamu-kit/ui");
|
|
387
|
+
const uiNodePath = path.join(
|
|
388
|
+
path.dirname(fileURLToPath(uiModulePath)),
|
|
389
|
+
"run-ui.js"
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
if (!(await exists(uiNodePath))) {
|
|
393
|
+
console.log(
|
|
394
|
+
chalk.red(
|
|
395
|
+
`UI runner script not found at ${uiNodePath}. Please rebuild @sonamu-kit/ui.`
|
|
396
|
+
)
|
|
397
|
+
);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// UI를 별도 프로세스로 실행 (hot-hook 활성화)
|
|
402
|
+
const uiProcess = spawn(
|
|
403
|
+
process.execPath,
|
|
404
|
+
[
|
|
405
|
+
"--import", "@sonamu-kit/loader",
|
|
406
|
+
"--import", "sonamu/hot-hook-register",
|
|
407
|
+
"--enable-source-maps",
|
|
408
|
+
"--no-warnings",
|
|
409
|
+
uiNodePath,
|
|
410
|
+
],
|
|
411
|
+
{
|
|
412
|
+
stdio: "inherit",
|
|
413
|
+
env: {
|
|
414
|
+
...process.env,
|
|
415
|
+
HOT: "yes",
|
|
416
|
+
PROJECT_NAME:
|
|
417
|
+
Sonamu.config.projectName ?? path.basename(Sonamu.apiRootPath),
|
|
418
|
+
API_ROOT_PATH: Sonamu.apiRootPath,
|
|
419
|
+
UI_PORT: (Sonamu.config.ui?.port ?? 57000).toString(),
|
|
420
|
+
},
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
// 종료 처리
|
|
425
|
+
const cleanup = () => {
|
|
426
|
+
console.log(chalk.yellow("\n\n👋 Shutting down UI server..."));
|
|
427
|
+
uiProcess.kill("SIGTERM");
|
|
428
|
+
process.exit(0);
|
|
380
429
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
430
|
+
|
|
431
|
+
process.on("SIGINT", cleanup);
|
|
432
|
+
process.on("SIGTERM", cleanup);
|
|
433
|
+
|
|
434
|
+
uiProcess.on("exit", (code) => {
|
|
435
|
+
if (code !== 0) {
|
|
436
|
+
console.error(chalk.red(`❌ UI server exited with code ${code}`));
|
|
437
|
+
process.exit(code || 1);
|
|
438
|
+
}
|
|
389
439
|
});
|
|
390
440
|
} catch (e: unknown) {
|
|
391
441
|
if (e instanceof Error && e.message.includes("isn't declared")) {
|
|
392
|
-
console.log(
|
|
442
|
+
console.log(
|
|
443
|
+
`You need to install ${chalk.blue(`@sonamu-kit/ui`)} first.`
|
|
444
|
+
);
|
|
393
445
|
return;
|
|
394
446
|
}
|
|
395
447
|
throw e;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hot-hook 초기화하는 모듈입니다.
|
|
3
|
+
*
|
|
4
|
+
* 이 파일은 --import 플래그로 프로세스 시작 시 로드되어야 합니다.
|
|
5
|
+
*
|
|
6
|
+
* 환경변수:
|
|
7
|
+
* - API_ROOT_PATH: 사용자 프로젝트의 API 루트 경로
|
|
8
|
+
* - HOT: 'yes'일 때만 hot-hook 활성화
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
if (process.env.HOT === "yes" && process.env.API_ROOT_PATH) {
|
|
12
|
+
const { hot } = await import("@sonamu-kit/hot-hook");
|
|
13
|
+
|
|
14
|
+
await hot.init({
|
|
15
|
+
rootDirectory: process.env.API_ROOT_PATH, // 이 친구가 프로젝트 API 경로로 잘 설정되어야 아래 바운더리가 작동합니다.
|
|
16
|
+
boundaries: [`./src/**/*.ts`], // 프로젝트의 이 친구들이 바운더리가 됩니다.
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
console.log("🔥 Hot-hook initialized");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
|
-
import { chunk, groupBy, isObject, omit, set, uniq } from "lodash";
|
|
3
|
+
import { chunk, groupBy, isObject, omit, set, uniq } from "lodash-es";
|
|
4
4
|
import { DBPreset, DB } from "./db";
|
|
5
5
|
import { isCustomJoinClause, type SubsetQuery } from "../types/types";
|
|
6
6
|
import type { BaseListParams } from "../utils/model";
|
package/src/database/db.ts
CHANGED
|
@@ -1,32 +1,10 @@
|
|
|
1
1
|
export type DBPreset = "w" | "r";
|
|
2
2
|
import knex, { Knex } from "knex";
|
|
3
|
-
import
|
|
4
|
-
import _ from "lodash";
|
|
3
|
+
import * as _ from "lodash-es";
|
|
5
4
|
import { Sonamu } from "../api";
|
|
6
|
-
import { ServiceUnavailableException } from "../exceptions/so-exceptions";
|
|
7
5
|
import { AsyncLocalStorage } from "async_hooks";
|
|
8
6
|
import { TransactionContext } from "./transaction-context";
|
|
9
|
-
|
|
10
|
-
type MySQLConfig = Omit<Knex.Config, "connection"> & {
|
|
11
|
-
connection?: Knex.MySql2ConnectionConfig;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type SonamuDBBaseConfig = {
|
|
15
|
-
// 기본 데이터베이스 이름
|
|
16
|
-
database: string;
|
|
17
|
-
|
|
18
|
-
// 모든 환경에 적용될 기본 Knex 옵션
|
|
19
|
-
defaultOptions?: MySQLConfig;
|
|
20
|
-
|
|
21
|
-
// 환경별 설정
|
|
22
|
-
environments?: {
|
|
23
|
-
development?: MySQLConfig;
|
|
24
|
-
development_slave?: MySQLConfig;
|
|
25
|
-
production?: MySQLConfig;
|
|
26
|
-
production_slave?: MySQLConfig;
|
|
27
|
-
remote_fixture?: MySQLConfig;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
7
|
+
import { DatabaseConfig, SonamuConfig } from "../api/config";
|
|
30
8
|
|
|
31
9
|
export type SonamuDBConfig = {
|
|
32
10
|
development_master: Knex.Config;
|
|
@@ -52,25 +30,6 @@ class DBClass {
|
|
|
52
30
|
return this.transactionStorage.getStore() ?? new TransactionContext();
|
|
53
31
|
}
|
|
54
32
|
|
|
55
|
-
async readKnexfile(): Promise<SonamuDBConfig> {
|
|
56
|
-
const dbConfigPath: string = path.join(
|
|
57
|
-
Sonamu.apiRootPath,
|
|
58
|
-
"/dist/configs/db.js"
|
|
59
|
-
);
|
|
60
|
-
try {
|
|
61
|
-
const knexfileModule = await import(dbConfigPath);
|
|
62
|
-
const config =
|
|
63
|
-
knexfileModule.default?.default ??
|
|
64
|
-
knexfileModule.default ??
|
|
65
|
-
knexfileModule;
|
|
66
|
-
return this.generateDBConfig(config);
|
|
67
|
-
} catch {}
|
|
68
|
-
|
|
69
|
-
throw new ServiceUnavailableException(
|
|
70
|
-
`다음 경로에서 DB설정 파일을 찾을 수 없습니다: ${dbConfigPath}. 먼저 빌드(yarn build)를 수행해주세요.`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
33
|
getDB(which: DBPreset): Knex {
|
|
75
34
|
const dbConfig = Sonamu.dbConfig;
|
|
76
35
|
|
|
@@ -134,8 +93,8 @@ class DBClass {
|
|
|
134
93
|
}
|
|
135
94
|
}
|
|
136
95
|
|
|
137
|
-
|
|
138
|
-
const defaultKnexConfig: Partial<
|
|
96
|
+
public generateDBConfig(config: SonamuConfig["database"]): SonamuDBConfig {
|
|
97
|
+
const defaultKnexConfig: Partial<DatabaseConfig> = _.merge(
|
|
139
98
|
{
|
|
140
99
|
client: "mysql2",
|
|
141
100
|
pool: {
|
|
@@ -143,11 +102,10 @@ class DBClass {
|
|
|
143
102
|
max: 5,
|
|
144
103
|
},
|
|
145
104
|
migrations: {
|
|
146
|
-
|
|
147
|
-
directory: "./dist/migrations",
|
|
105
|
+
directory: "./src/migrations",
|
|
148
106
|
},
|
|
149
107
|
connection: {
|
|
150
|
-
database: config.
|
|
108
|
+
database: config.name,
|
|
151
109
|
...config.defaultOptions?.connection,
|
|
152
110
|
},
|
|
153
111
|
},
|
|
@@ -155,16 +113,16 @@ class DBClass {
|
|
|
155
113
|
);
|
|
156
114
|
|
|
157
115
|
// 로컬 환경 설정
|
|
158
|
-
const test:
|
|
116
|
+
const test: DatabaseConfig = _.merge({}, defaultKnexConfig, {
|
|
159
117
|
connection: {
|
|
160
|
-
database: `${config.
|
|
118
|
+
database: `${config.name}_test`,
|
|
161
119
|
...config.defaultOptions?.connection,
|
|
162
120
|
},
|
|
163
121
|
});
|
|
164
122
|
|
|
165
123
|
const fixture_local = _.merge({}, defaultKnexConfig, {
|
|
166
124
|
connection: {
|
|
167
|
-
database: `${config.
|
|
125
|
+
database: `${config.name}_fixture_local`,
|
|
168
126
|
...config.defaultOptions?.connection,
|
|
169
127
|
},
|
|
170
128
|
});
|
|
@@ -186,7 +144,7 @@ class DBClass {
|
|
|
186
144
|
devMasterOptions,
|
|
187
145
|
{
|
|
188
146
|
connection: {
|
|
189
|
-
database: `${config.
|
|
147
|
+
database: `${config.name}_fixture_remote`,
|
|
190
148
|
},
|
|
191
149
|
},
|
|
192
150
|
config.environments?.remote_fixture
|
package/src/database/puri.ts
CHANGED
|
@@ -15,13 +15,9 @@ import type {
|
|
|
15
15
|
} from "./puri.types";
|
|
16
16
|
import chalk from "chalk";
|
|
17
17
|
import assert from "assert";
|
|
18
|
+
import { Naite } from "../naite/naite";
|
|
18
19
|
|
|
19
|
-
export class Puri<
|
|
20
|
-
TSchema,
|
|
21
|
-
TTables extends Record<string, any>,
|
|
22
|
-
TResult,
|
|
23
|
-
TResolved = Expand<TResult>[],
|
|
24
|
-
> {
|
|
20
|
+
export class Puri<TSchema, TTables extends Record<string, any>, TResult> {
|
|
25
21
|
private knexQuery: Knex.QueryBuilder;
|
|
26
22
|
|
|
27
23
|
// 생성자 시그니처들
|
|
@@ -31,7 +27,7 @@ export class Puri<
|
|
|
31
27
|
tableSpec: Record<string, string | Puri<TSchema, any, any>>
|
|
32
28
|
);
|
|
33
29
|
constructor(
|
|
34
|
-
|
|
30
|
+
public knex: Knex,
|
|
35
31
|
tableNameOrSpec: any
|
|
36
32
|
) {
|
|
37
33
|
if (typeof tableNameOrSpec === "string") {
|
|
@@ -129,7 +125,7 @@ export class Puri<
|
|
|
129
125
|
return { _type: "sql_expression", _return: "date", _sql: sql };
|
|
130
126
|
}
|
|
131
127
|
|
|
132
|
-
// SELECT
|
|
128
|
+
// SELECT (overwrite)
|
|
133
129
|
select<TSelect extends SelectObject<TTables>>(
|
|
134
130
|
selectObj: TSelect
|
|
135
131
|
): Puri<TSchema, TTables, ParseSelectObject<TTables, TSelect>> {
|
|
@@ -161,6 +157,13 @@ export class Puri<
|
|
|
161
157
|
return this as any;
|
|
162
158
|
}
|
|
163
159
|
|
|
160
|
+
// SELECT (select는 overwrite, appendSelect는 append)
|
|
161
|
+
appendSelect<TSelect extends SelectObject<TTables>>(
|
|
162
|
+
selectObj: TSelect
|
|
163
|
+
): Puri<TSchema, TTables, TResult & ParseSelectObject<TTables, TSelect>> {
|
|
164
|
+
return this.select(selectObj) as any;
|
|
165
|
+
}
|
|
166
|
+
|
|
164
167
|
// SELECT *
|
|
165
168
|
selectAll(): this {
|
|
166
169
|
this.knexQuery.select("*");
|
|
@@ -354,7 +357,7 @@ export class Puri<
|
|
|
354
357
|
// WHERE: 컬럼 - 사용: .where("u.id", ">", 10)
|
|
355
358
|
where<TColumn extends AvailableColumns<TTables>>(
|
|
356
359
|
column: TColumn,
|
|
357
|
-
operator: ComparisonOperator,
|
|
360
|
+
operator: ComparisonOperator | "like" | "not like",
|
|
358
361
|
value: ExtractColumnType<TTables, TColumn & string>
|
|
359
362
|
): this;
|
|
360
363
|
// WHERE: 컬럼 - 사용: .where("u.id", "like", "%test%")
|
|
@@ -479,101 +482,86 @@ export class Puri<
|
|
|
479
482
|
}
|
|
480
483
|
|
|
481
484
|
// 실행 메서드들 - thenable 구현
|
|
482
|
-
then<TResult1 =
|
|
485
|
+
then<TResult1 = Expand<TResult>[], TResult2 = never>(
|
|
483
486
|
onfulfilled?:
|
|
484
|
-
| ((value:
|
|
487
|
+
| ((value: Expand<TResult>[]) => TResult1 | PromiseLike<TResult1>)
|
|
485
488
|
| null,
|
|
486
489
|
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
487
490
|
): Promise<TResult1 | TResult2> {
|
|
491
|
+
Naite.t("puri-query", this.toQuery());
|
|
488
492
|
return this.knexQuery.then(onfulfilled as any, onrejected);
|
|
489
493
|
}
|
|
490
494
|
catch<TResult2 = never>(
|
|
491
495
|
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
492
|
-
): Promise<
|
|
496
|
+
): Promise<TResult | TResult2> {
|
|
493
497
|
return this.knexQuery.catch(onrejected);
|
|
494
498
|
}
|
|
495
|
-
finally(onfinally?: (() => void) | null): Promise<
|
|
499
|
+
finally(onfinally?: (() => void) | null): Promise<TResult> {
|
|
496
500
|
return this.knexQuery.finally(onfinally);
|
|
497
501
|
}
|
|
498
502
|
|
|
499
503
|
// 하나만 쿼리
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
// 하나만 쿼리 실패 시 에러
|
|
504
|
-
async firstOrFail(): Promise<TResult> {
|
|
505
|
-
const result = await this.knexQuery.first();
|
|
506
|
-
if (!result) {
|
|
507
|
-
throw new Error("No results found");
|
|
508
|
-
}
|
|
509
|
-
return result;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// 쿼리 후 인덱스 리턴
|
|
513
|
-
async at(index: number): Promise<Expand<TResult> | undefined> {
|
|
514
|
-
const results = (await this) as any[];
|
|
515
|
-
return results[index];
|
|
516
|
-
}
|
|
517
|
-
// 쿼리 후 인덱스 리턴 실패 시 에러
|
|
518
|
-
async assertAt(index: number): Promise<Expand<TResult>> {
|
|
519
|
-
const results = (await this) as any[];
|
|
520
|
-
const result = results[index];
|
|
521
|
-
if (result === undefined) {
|
|
522
|
-
throw new Error(`No result found at index ${index}`);
|
|
523
|
-
}
|
|
524
|
-
return result;
|
|
504
|
+
first(): ResolvedPuri<Expand<TResult>, never> {
|
|
505
|
+
this.knexQuery.first();
|
|
506
|
+
return new ResolvedPuri(this.knexQuery);
|
|
525
507
|
}
|
|
526
508
|
|
|
527
509
|
// 쿼리한 레코드에서 특정 컬럼만 추출한 배열 리턴
|
|
528
|
-
|
|
510
|
+
pluck<
|
|
511
|
+
TColumn extends keyof TResult | ResultAvailableColumns<TTables, TResult>,
|
|
512
|
+
>(
|
|
529
513
|
column: TColumn
|
|
530
|
-
):
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
514
|
+
): ResolvedPuri<
|
|
515
|
+
TColumn extends keyof TResult
|
|
516
|
+
? TResult[TColumn][]
|
|
517
|
+
: ExtractColumnType<TTables, TColumn & string>[],
|
|
518
|
+
never
|
|
519
|
+
> {
|
|
520
|
+
this.knexQuery.pluck(column as string);
|
|
521
|
+
return new ResolvedPuri(this.knexQuery);
|
|
534
522
|
}
|
|
535
523
|
|
|
536
524
|
// INSERT
|
|
537
525
|
insert(
|
|
538
526
|
data: InsertData<SingleTableValue<TTables>>
|
|
539
|
-
):
|
|
527
|
+
): ResolvedPuri<[number], never> {
|
|
540
528
|
this.knexQuery.insert(data);
|
|
541
|
-
return this
|
|
529
|
+
return new ResolvedPuri(this.knexQuery);
|
|
542
530
|
}
|
|
543
531
|
|
|
544
532
|
// UPDATE
|
|
545
|
-
update(data: WhereCondition<TTables>):
|
|
533
|
+
update(data: WhereCondition<TTables>): ResolvedPuri<TResult, number> {
|
|
546
534
|
this.knexQuery.update(data);
|
|
547
|
-
return this
|
|
535
|
+
return new ResolvedPuri(this.knexQuery);
|
|
548
536
|
}
|
|
549
537
|
|
|
550
538
|
// Increment
|
|
551
539
|
increment<TColumn extends AvailableColumns<TTables>>(
|
|
552
540
|
column: TColumn,
|
|
553
541
|
value: number
|
|
554
|
-
):
|
|
542
|
+
): ResolvedPuri<number, never> {
|
|
555
543
|
if (value <= 0) {
|
|
556
544
|
throw new Error("Increment value must be greater than 0");
|
|
557
545
|
}
|
|
558
546
|
this.knexQuery.increment(column, value);
|
|
559
|
-
return this;
|
|
547
|
+
return new ResolvedPuri(this.knexQuery);
|
|
560
548
|
}
|
|
561
549
|
// Decrement
|
|
562
550
|
decrement<TColumn extends AvailableColumns<TTables>>(
|
|
563
551
|
column: TColumn,
|
|
564
552
|
value: number
|
|
565
|
-
):
|
|
553
|
+
): ResolvedPuri<number, never> {
|
|
566
554
|
if (value <= 0) {
|
|
567
555
|
throw new Error("Decrement value must be greater than 0");
|
|
568
556
|
}
|
|
569
557
|
this.knexQuery.decrement(column, value);
|
|
570
|
-
return this;
|
|
558
|
+
return new ResolvedPuri(this.knexQuery);
|
|
571
559
|
}
|
|
572
560
|
|
|
573
561
|
// DELETE
|
|
574
|
-
delete():
|
|
562
|
+
delete(): ResolvedPuri<number, never> {
|
|
575
563
|
this.knexQuery.delete();
|
|
576
|
-
return this
|
|
564
|
+
return new ResolvedPuri(this.knexQuery);
|
|
577
565
|
}
|
|
578
566
|
|
|
579
567
|
// 확인 쿼리 리턴
|
|
@@ -800,3 +788,40 @@ export class JoinClauseGroup<
|
|
|
800
788
|
return this;
|
|
801
789
|
}
|
|
802
790
|
}
|
|
791
|
+
|
|
792
|
+
/*
|
|
793
|
+
TResolved: 쿼리 실행 후 반환될 결과 타입
|
|
794
|
+
_TReturning: 추후 RETURNING 절에 사용될 타입
|
|
795
|
+
*/
|
|
796
|
+
export class ResolvedPuri<TResolved, _TReturning> {
|
|
797
|
+
constructor(public knexQuery: Knex.QueryBuilder) {}
|
|
798
|
+
|
|
799
|
+
toQuery(): string {
|
|
800
|
+
return this.knexQuery.toQuery();
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
debug(): this {
|
|
804
|
+
console.log(
|
|
805
|
+
`${chalk.cyan("[Puri Debug]")} ${chalk.yellow(this.toQuery())}`
|
|
806
|
+
);
|
|
807
|
+
return this;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
then<TResult1 = TResolved, TResult2 = never>(
|
|
811
|
+
onfulfilled?:
|
|
812
|
+
| ((value: TResolved) => TResult1 | PromiseLike<TResult1>)
|
|
813
|
+
| null,
|
|
814
|
+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
815
|
+
): Promise<TResult1 | TResult2> {
|
|
816
|
+
Naite.t("puri-query", this.toQuery());
|
|
817
|
+
return this.knexQuery.then(onfulfilled as any, onrejected);
|
|
818
|
+
}
|
|
819
|
+
catch<TResult2 = never>(
|
|
820
|
+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
821
|
+
): Promise<TResolved | TResult2> {
|
|
822
|
+
return this.knexQuery.catch(onrejected);
|
|
823
|
+
}
|
|
824
|
+
finally(onfinally?: (() => void) | null): Promise<TResolved> {
|
|
825
|
+
return this.knexQuery.finally(onfinally);
|
|
826
|
+
}
|
|
827
|
+
}
|