sonamu 0.2.28 → 0.2.29
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/bin/cli.js +8 -3
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/upsert-builder.d.ts.map +1 -1
- package/dist/database/upsert-builder.js +4 -2
- package/dist/database/upsert-builder.js.map +1 -1
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +4 -0
- package/dist/entity/entity-manager.js.map +1 -1
- package/dist/entity/migrator.d.ts.map +1 -1
- package/dist/entity/migrator.js +26 -16
- package/dist/entity/migrator.js.map +1 -1
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +3 -0
- package/dist/syncer/syncer.js.map +1 -1
- package/dist/templates/entity.template.d.ts.map +1 -1
- package/dist/templates/entity.template.js +3 -1
- package/dist/templates/entity.template.js.map +1 -1
- package/dist/templates/generated.template.d.ts.map +1 -1
- package/dist/templates/generated.template.js +3 -1
- package/dist/templates/generated.template.js.map +1 -1
- package/dist/templates/generated_http.template.d.ts.map +1 -1
- package/dist/templates/generated_http.template.js +2 -1
- package/dist/templates/generated_http.template.js.map +1 -1
- package/dist/templates/generated_sso.template.d.ts.map +1 -1
- package/dist/templates/generated_sso.template.js +3 -1
- package/dist/templates/generated_sso.template.js.map +1 -1
- package/dist/templates/init_types.template.d.ts.map +1 -1
- package/dist/templates/init_types.template.js +3 -1
- package/dist/templates/init_types.template.js.map +1 -1
- package/dist/templates/model.template.d.ts.map +1 -1
- package/dist/templates/model.template.js +3 -1
- package/dist/templates/model.template.js.map +1 -1
- package/dist/templates/model_test.template.d.ts.map +1 -1
- package/dist/templates/model_test.template.js +3 -1
- package/dist/templates/model_test.template.js.map +1 -1
- package/dist/testing/fixture-manager.js +1 -1
- package/package.json +1 -1
- package/src/bin/cli.ts +13 -3
- package/src/database/upsert-builder.ts +4 -1
- package/src/entity/entity-manager.ts +8 -0
- package/src/entity/migrator.ts +30 -22
- package/src/syncer/syncer.ts +6 -0
- package/src/templates/entity.template.ts +4 -1
- package/src/templates/generated.template.ts +4 -1
- package/src/templates/generated_http.template.ts +3 -1
- package/src/templates/generated_sso.template.ts +4 -1
- package/src/templates/init_types.template.ts +4 -1
- package/src/templates/model.template.ts +4 -1
- package/src/templates/model_test.template.ts +4 -1
- package/src/testing/fixture-manager.ts +1 -1
package/src/entity/migrator.ts
CHANGED
|
@@ -57,7 +57,6 @@ import { EntityManager } from "./entity-manager";
|
|
|
57
57
|
import { Entity } from "./entity";
|
|
58
58
|
import { Sonamu } from "../api";
|
|
59
59
|
import { ServiceUnavailableException } from "../exceptions/so-exceptions";
|
|
60
|
-
import { nonNullable } from "../utils/utils";
|
|
61
60
|
|
|
62
61
|
type MigratorMode = "dev" | "deploy";
|
|
63
62
|
export type MigratorOptions = {
|
|
@@ -104,7 +103,12 @@ export class Migrator {
|
|
|
104
103
|
if (
|
|
105
104
|
(dbConfig.fixture_local.connection as Knex.MySql2ConnectionConfig)
|
|
106
105
|
.host !==
|
|
107
|
-
|
|
106
|
+
(dbConfig.fixture_remote.connection as Knex.MySql2ConnectionConfig)
|
|
107
|
+
.host ||
|
|
108
|
+
(dbConfig.fixture_local.connection as Knex.MySql2ConnectionConfig)
|
|
109
|
+
.database !==
|
|
110
|
+
(dbConfig.fixture_remote.connection as Knex.MySql2ConnectionConfig)
|
|
111
|
+
.database
|
|
108
112
|
) {
|
|
109
113
|
const fixtureRemoteDB = knex(dbConfig.fixture_remote);
|
|
110
114
|
applyDBs.push(fixtureRemoteDB);
|
|
@@ -190,7 +194,7 @@ export class Migrator {
|
|
|
190
194
|
if (onlyTs.length > 0) {
|
|
191
195
|
console.debug({ onlyTs });
|
|
192
196
|
throw new ServiceUnavailableException(
|
|
193
|
-
`There is an un-compiled TS migration files.\nPlease
|
|
197
|
+
`There is an un-compiled TS migration files.\nPlease compile them first.\n\n${onlyTs
|
|
194
198
|
.map((f) => f.name)
|
|
195
199
|
.join("\n")}`
|
|
196
200
|
);
|
|
@@ -302,23 +306,27 @@ export class Migrator {
|
|
|
302
306
|
applied: string[];
|
|
303
307
|
}[]
|
|
304
308
|
> {
|
|
305
|
-
// get
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
309
|
+
// get uniq knex configs
|
|
310
|
+
const configs = uniqBy(
|
|
311
|
+
targets
|
|
312
|
+
.map((target) => ({
|
|
313
|
+
connKey: target,
|
|
314
|
+
options: Sonamu.dbConfig[target as keyof typeof Sonamu.dbConfig],
|
|
315
|
+
}))
|
|
316
|
+
.filter((c) => c.options !== undefined),
|
|
317
|
+
({ options }) =>
|
|
318
|
+
`${(options.connection as Knex.MySql2ConnectionConfig).host}:${
|
|
319
|
+
(options.connection as Knex.MySql2ConnectionConfig).port ?? 3306
|
|
320
|
+
}/${(options.connection as Knex.MySql2ConnectionConfig).database}`
|
|
321
|
+
);
|
|
314
322
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
)
|
|
321
|
-
)
|
|
323
|
+
// get connections
|
|
324
|
+
const conns = await Promise.all(
|
|
325
|
+
configs.map(async (config) => ({
|
|
326
|
+
connKey: config.connKey,
|
|
327
|
+
knex: knex(config.options),
|
|
328
|
+
}))
|
|
329
|
+
);
|
|
322
330
|
|
|
323
331
|
// action
|
|
324
332
|
const result = await (async () => {
|
|
@@ -629,8 +637,8 @@ export class Migrator {
|
|
|
629
637
|
|
|
630
638
|
// 기존 ShadowDB 리셋
|
|
631
639
|
console.log(chalk.magenta(`${shadowDatabase} 리셋`));
|
|
632
|
-
await tdb.raw(`DROP DATABASE IF EXISTS
|
|
633
|
-
await tdb.raw(`CREATE DATABASE
|
|
640
|
+
await tdb.raw(`DROP DATABASE IF EXISTS \`${shadowDatabase}\`;`);
|
|
641
|
+
await tdb.raw(`CREATE DATABASE \`${shadowDatabase}\`;`);
|
|
634
642
|
|
|
635
643
|
// ShadowDB 테이블 + 데이터 생성
|
|
636
644
|
console.log(chalk.magenta(`${shadowDatabase} 데이터베이스 생성`));
|
|
@@ -660,7 +668,7 @@ export class Migrator {
|
|
|
660
668
|
|
|
661
669
|
// 생성한 Shadow DB 삭제
|
|
662
670
|
console.log(chalk.magenta(`${shadowDatabase} 삭제`));
|
|
663
|
-
await sdb.raw(`DROP DATABASE IF EXISTS
|
|
671
|
+
await sdb.raw(`DROP DATABASE IF EXISTS \`${shadowDatabase}\`;`);
|
|
664
672
|
|
|
665
673
|
return [
|
|
666
674
|
{
|
package/src/syncer/syncer.ts
CHANGED
|
@@ -1332,6 +1332,12 @@ export class Syncer {
|
|
|
1332
1332
|
table?: string,
|
|
1333
1333
|
title?: string
|
|
1334
1334
|
) {
|
|
1335
|
+
if (/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(entityId) === false) {
|
|
1336
|
+
throw new BadRequestException(
|
|
1337
|
+
"entityId는 자바스크립트 변수명 규칙을 따라야 합니다."
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1335
1341
|
await this.generateTemplate("entity", {
|
|
1336
1342
|
entityId,
|
|
1337
1343
|
parentId,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TemplateOptions } from "../types/types";
|
|
2
2
|
import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
|
|
3
3
|
import { Template } from "./base-template";
|
|
4
|
+
import { Sonamu } from "../api";
|
|
4
5
|
|
|
5
6
|
export class Template__entity extends Template {
|
|
6
7
|
constructor() {
|
|
@@ -8,8 +9,10 @@ export class Template__entity extends Template {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
getTargetAndPath(names: EntityNamesRecord, parentNames?: EntityNamesRecord) {
|
|
12
|
+
const { dir } = Sonamu.config.api;
|
|
13
|
+
|
|
11
14
|
return {
|
|
12
|
-
target:
|
|
15
|
+
target: `${dir}/src/application`,
|
|
13
16
|
path: `${(parentNames ?? names).fs}/${names.fs}.entity.json`,
|
|
14
17
|
};
|
|
15
18
|
}
|
|
@@ -6,6 +6,7 @@ import { EntityPropNode } from "../types/types";
|
|
|
6
6
|
import { propNodeToZodTypeDef, zodTypeToZodCode } from "../api/code-converters";
|
|
7
7
|
import { Template } from "./base-template";
|
|
8
8
|
import { nonNullable } from "../utils/utils";
|
|
9
|
+
import { Sonamu } from "../api";
|
|
9
10
|
|
|
10
11
|
export type SourceCode = {
|
|
11
12
|
label: string;
|
|
@@ -18,8 +19,10 @@ export class Template__generated extends Template {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
getTargetAndPath() {
|
|
22
|
+
const { dir } = Sonamu.config.api;
|
|
23
|
+
|
|
21
24
|
return {
|
|
22
|
-
target:
|
|
25
|
+
target: `${dir}/src/application`,
|
|
23
26
|
path: `sonamu.generated.ts`,
|
|
24
27
|
};
|
|
25
28
|
}
|
|
@@ -13,8 +13,10 @@ export class Template__generated_http extends Template {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
getTargetAndPath() {
|
|
16
|
+
const { dir } = Sonamu.config.api;
|
|
17
|
+
|
|
16
18
|
return {
|
|
17
|
-
target:
|
|
19
|
+
target: `${dir}/src/application`,
|
|
18
20
|
path: `sonamu.generated.http`,
|
|
19
21
|
};
|
|
20
22
|
}
|
|
@@ -5,6 +5,7 @@ import { camelize } from "inflection";
|
|
|
5
5
|
import { SourceCode } from "./generated.template";
|
|
6
6
|
import { uniq } from "lodash";
|
|
7
7
|
import { nonNullable } from "../utils/utils";
|
|
8
|
+
import { Sonamu } from "../api";
|
|
8
9
|
|
|
9
10
|
export class Template__generated_sso extends Template {
|
|
10
11
|
constructor() {
|
|
@@ -12,8 +13,10 @@ export class Template__generated_sso extends Template {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
getTargetAndPath() {
|
|
16
|
+
const { dir } = Sonamu.config.api;
|
|
17
|
+
|
|
15
18
|
return {
|
|
16
|
-
target:
|
|
19
|
+
target: `${dir}/src/application`,
|
|
17
20
|
path: `sonamu.generated.sso.ts`,
|
|
18
21
|
};
|
|
19
22
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TemplateOptions } from "../types/types";
|
|
2
2
|
import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
|
|
3
3
|
import { Template } from "./base-template";
|
|
4
|
+
import { Sonamu } from "../api";
|
|
4
5
|
|
|
5
6
|
export class Template__init_types extends Template {
|
|
6
7
|
constructor() {
|
|
@@ -8,8 +9,10 @@ export class Template__init_types extends Template {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
getTargetAndPath(names: EntityNamesRecord) {
|
|
12
|
+
const { dir } = Sonamu.config.api;
|
|
13
|
+
|
|
11
14
|
return {
|
|
12
|
-
target:
|
|
15
|
+
target: `${dir}/src/application`,
|
|
13
16
|
path: `${names.fs}/${names.fs}.types.ts`,
|
|
14
17
|
};
|
|
15
18
|
}
|
|
@@ -2,6 +2,7 @@ import { RenderingNode, TemplateOptions } from "../types/types";
|
|
|
2
2
|
import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
|
|
3
3
|
import { Template } from "./base-template";
|
|
4
4
|
import { Template__view_list } from "./view_list.template";
|
|
5
|
+
import { Sonamu } from "../api";
|
|
5
6
|
|
|
6
7
|
export class Template__model extends Template {
|
|
7
8
|
constructor() {
|
|
@@ -9,8 +10,10 @@ export class Template__model extends Template {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
getTargetAndPath(names: EntityNamesRecord) {
|
|
13
|
+
const { dir } = Sonamu.config.api;
|
|
14
|
+
|
|
12
15
|
return {
|
|
13
|
-
target:
|
|
16
|
+
target: `${dir}/src/application`,
|
|
14
17
|
path: `${names.fs}/${names.fs}.model.ts`,
|
|
15
18
|
};
|
|
16
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TemplateOptions } from "../types/types";
|
|
2
2
|
import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
|
|
3
3
|
import { Template } from "./base-template";
|
|
4
|
+
import { Sonamu } from "../api";
|
|
4
5
|
|
|
5
6
|
export class Template__model_test extends Template {
|
|
6
7
|
constructor() {
|
|
@@ -8,8 +9,10 @@ export class Template__model_test extends Template {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
getTargetAndPath(names: EntityNamesRecord) {
|
|
12
|
+
const { dir } = Sonamu.config.api;
|
|
13
|
+
|
|
11
14
|
return {
|
|
12
|
-
target:
|
|
15
|
+
target: `${dir}/src/application`,
|
|
13
16
|
path: `${names.fs}/${names.fs}.model.test.ts`,
|
|
14
17
|
};
|
|
15
18
|
}
|