sonamu 0.4.1 → 0.4.3
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 +51 -51
- package/dist/bin/cli.js.map +1 -1
- package/dist/bin/cli.mjs +2 -2
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/{chunk-FLPD24HS.mjs → chunk-4K2F3SOM.mjs} +2 -2
- package/dist/{chunk-I2MMJRJN.mjs → chunk-HIUT56RE.mjs} +32 -15
- package/dist/chunk-HIUT56RE.mjs.map +1 -0
- package/dist/{chunk-QK5XXJUX.mjs → chunk-HVVCQLAU.mjs} +2 -2
- package/dist/{chunk-Z2P7XTXE.js → chunk-JBKIW5LD.js} +130 -113
- package/dist/chunk-JBKIW5LD.js.map +1 -0
- package/dist/{chunk-U636LQJJ.js → chunk-N6N3LENC.js} +4 -4
- package/dist/{chunk-W7KDVJLQ.js → chunk-UAG3SKFM.js} +7 -7
- package/dist/{chunk-XT6LHCX5.js → chunk-WJGRXAXE.js} +12 -4
- package/dist/chunk-WJGRXAXE.js.map +1 -0
- package/dist/{chunk-PP2PSSAG.mjs → chunk-ZFLQLW37.mjs} +12 -4
- package/dist/{chunk-PP2PSSAG.mjs.map → chunk-ZFLQLW37.mjs.map} +1 -1
- package/dist/database/drivers/knex/base-model.js +8 -8
- package/dist/database/drivers/knex/base-model.mjs +3 -3
- package/dist/database/drivers/kysely/base-model.js +9 -9
- package/dist/database/drivers/kysely/base-model.mjs +3 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +7 -7
- package/dist/index.mjs +3 -3
- package/package.json +2 -2
- package/src/api/sonamu.ts +17 -4
- package/src/bin/cli.ts +1 -0
- package/src/entity/migrator.ts +51 -19
- package/dist/chunk-I2MMJRJN.mjs.map +0 -1
- package/dist/chunk-XT6LHCX5.js.map +0 -1
- package/dist/chunk-Z2P7XTXE.js.map +0 -1
- /package/dist/{chunk-FLPD24HS.mjs.map → chunk-4K2F3SOM.mjs.map} +0 -0
- /package/dist/{chunk-QK5XXJUX.mjs.map → chunk-HVVCQLAU.mjs.map} +0 -0
- /package/dist/{chunk-U636LQJJ.js.map → chunk-N6N3LENC.js.map} +0 -0
- /package/dist/{chunk-W7KDVJLQ.js.map → chunk-UAG3SKFM.js.map} +0 -0
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkN6N3LENCjs = require('../../../chunk-N6N3LENC.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUAG3SKFMjs = require('../../../chunk-UAG3SKFM.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkWJGRXAXEjs = require('../../../chunk-WJGRXAXE.js');
|
|
11
11
|
|
|
12
12
|
// src/database/drivers/knex/base-model.ts
|
|
13
|
-
var BaseModelClass = class extends
|
|
13
|
+
var BaseModelClass = class extends _chunkN6N3LENCjs.BaseModelClassAbstract {
|
|
14
14
|
getDB(which) {
|
|
15
|
-
return
|
|
15
|
+
return _chunkWJGRXAXEjs.DB.getDB(which);
|
|
16
16
|
}
|
|
17
17
|
async destroy() {
|
|
18
|
-
return
|
|
18
|
+
return _chunkWJGRXAXEjs.DB.destroy();
|
|
19
19
|
}
|
|
20
20
|
getUpsertBuilder() {
|
|
21
|
-
return new (0,
|
|
21
|
+
return new (0, _chunkUAG3SKFMjs.UpsertBuilder)();
|
|
22
22
|
}
|
|
23
23
|
applyJoins(clonedQb, joins) {
|
|
24
24
|
for (const join of joins) {
|
|
25
|
-
if (
|
|
25
|
+
if (_chunkWJGRXAXEjs.isCustomJoinClause.call(void 0, join)) {
|
|
26
26
|
if (join.join === "inner") {
|
|
27
27
|
clonedQb.qb = clonedQb.qb.innerJoin(
|
|
28
28
|
`${join.table} as ${join.as}`,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseModelClassAbstract
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-4K2F3SOM.mjs";
|
|
4
4
|
import {
|
|
5
5
|
UpsertBuilder
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-HVVCQLAU.mjs";
|
|
7
7
|
import {
|
|
8
8
|
DB,
|
|
9
9
|
isCustomJoinClause
|
|
10
|
-
} from "../../../chunk-
|
|
10
|
+
} from "../../../chunk-ZFLQLW37.mjs";
|
|
11
11
|
import "../../../chunk-PTFDTOJU.mjs";
|
|
12
12
|
|
|
13
13
|
// src/database/drivers/knex/base-model.ts
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkN6N3LENCjs = require('../../../chunk-N6N3LENC.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUAG3SKFMjs = require('../../../chunk-UAG3SKFM.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkWJGRXAXEjs = require('../../../chunk-WJGRXAXE.js');
|
|
12
12
|
|
|
13
13
|
// src/database/drivers/kysely/base-model.ts
|
|
14
14
|
var _inflection = require('inflection'); var _inflection2 = _interopRequireDefault(_inflection);
|
|
15
|
-
var BaseModelClass = class extends
|
|
15
|
+
var BaseModelClass = class extends _chunkN6N3LENCjs.BaseModelClassAbstract {
|
|
16
16
|
getDB(which) {
|
|
17
|
-
return
|
|
17
|
+
return _chunkWJGRXAXEjs.DB.getDB(which);
|
|
18
18
|
}
|
|
19
19
|
async destroy() {
|
|
20
|
-
return
|
|
20
|
+
return _chunkWJGRXAXEjs.DB.destroy();
|
|
21
21
|
}
|
|
22
22
|
getUpsertBuilder() {
|
|
23
|
-
return new (0,
|
|
23
|
+
return new (0, _chunkUAG3SKFMjs.UpsertBuilder)();
|
|
24
24
|
}
|
|
25
25
|
applyJoins(clonedQb, joins) {
|
|
26
26
|
for (const join of joins) {
|
|
27
|
-
if (
|
|
27
|
+
if (_chunkWJGRXAXEjs.isCustomJoinClause.call(void 0, join)) {
|
|
28
28
|
throw new Error("Custom join clause is not supported in Kysely");
|
|
29
29
|
}
|
|
30
30
|
if (join.join === "inner") {
|
|
@@ -48,7 +48,7 @@ var BaseModelClass = class extends _chunkU636LQJJjs.BaseModelClassAbstract {
|
|
|
48
48
|
if (!column) {
|
|
49
49
|
throw new Error("parseOrderBy: Invalid column");
|
|
50
50
|
}
|
|
51
|
-
const entity =
|
|
51
|
+
const entity = _chunkWJGRXAXEjs.EntityManager.get(_inflection2.default.classify(table));
|
|
52
52
|
if (!entity.props.find((p) => p.name === column)) {
|
|
53
53
|
throw new Error("parseOrderBy: \uD604\uC7AC \uC5D4\uD2F0\uD2F0\uC5D0 \uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uCEEC\uB7FC\uC785\uB2C8\uB2E4: ");
|
|
54
54
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseModelClassAbstract
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-4K2F3SOM.mjs";
|
|
4
4
|
import {
|
|
5
5
|
UpsertBuilder
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-HVVCQLAU.mjs";
|
|
7
7
|
import {
|
|
8
8
|
DB,
|
|
9
9
|
EntityManager,
|
|
10
10
|
isCustomJoinClause
|
|
11
|
-
} from "../../../chunk-
|
|
11
|
+
} from "../../../chunk-ZFLQLW37.mjs";
|
|
12
12
|
import "../../../chunk-PTFDTOJU.mjs";
|
|
13
13
|
|
|
14
14
|
// src/database/drivers/kysely/base-model.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -324,7 +324,8 @@ declare class SonamuClass {
|
|
|
324
324
|
private _secrets;
|
|
325
325
|
set secrets(secrets: SonamuSecrets);
|
|
326
326
|
get secrets(): SonamuSecrets | null;
|
|
327
|
-
|
|
327
|
+
initForTesting(): Promise<void>;
|
|
328
|
+
init(doSilent?: boolean, enableSync?: boolean, apiRootPath?: string, forTesting?: boolean): Promise<void>;
|
|
328
329
|
withFastify(server: FastifyInstance<Server, IncomingMessage, ServerResponse>, config: SonamuFastifyConfig, options?: {
|
|
329
330
|
enableSync?: boolean;
|
|
330
331
|
doSilent?: boolean;
|
|
@@ -703,8 +704,8 @@ declare class Migrator {
|
|
|
703
704
|
getMigrationSetFromDB(compareDB: KnexClient | KyselyClient, table: string): Promise<MigrationSet | null>;
|
|
704
705
|
resolveDBColType(colType: string, colField: string): Pick<MigrationColumn, "type" | "unsigned" | "length" | "precision" | "scale">;
|
|
705
706
|
readTable(compareDB: KnexClient | KyselyClient, tableName: string): Promise<[DBColumn[], DBIndex[], DBForeign[]]>;
|
|
706
|
-
|
|
707
|
-
showMigrationSet(which:
|
|
707
|
+
getMigrationSetFromEntity(entity: Entity): MigrationSetAndJoinTable;
|
|
708
|
+
showMigrationSet(which: "Entity" | "DB", migrationSet: MigrationSet): void;
|
|
708
709
|
destroy(): Promise<void>;
|
|
709
710
|
}
|
|
710
711
|
type DBColumn = {
|
package/dist/index.d.ts
CHANGED
|
@@ -324,7 +324,8 @@ declare class SonamuClass {
|
|
|
324
324
|
private _secrets;
|
|
325
325
|
set secrets(secrets: SonamuSecrets);
|
|
326
326
|
get secrets(): SonamuSecrets | null;
|
|
327
|
-
|
|
327
|
+
initForTesting(): Promise<void>;
|
|
328
|
+
init(doSilent?: boolean, enableSync?: boolean, apiRootPath?: string, forTesting?: boolean): Promise<void>;
|
|
328
329
|
withFastify(server: FastifyInstance<Server, IncomingMessage, ServerResponse>, config: SonamuFastifyConfig, options?: {
|
|
329
330
|
enableSync?: boolean;
|
|
330
331
|
doSilent?: boolean;
|
|
@@ -703,8 +704,8 @@ declare class Migrator {
|
|
|
703
704
|
getMigrationSetFromDB(compareDB: KnexClient | KyselyClient, table: string): Promise<MigrationSet | null>;
|
|
704
705
|
resolveDBColType(colType: string, colField: string): Pick<MigrationColumn, "type" | "unsigned" | "length" | "precision" | "scale">;
|
|
705
706
|
readTable(compareDB: KnexClient | KyselyClient, tableName: string): Promise<[DBColumn[], DBIndex[], DBForeign[]]>;
|
|
706
|
-
|
|
707
|
-
showMigrationSet(which:
|
|
707
|
+
getMigrationSetFromEntity(entity: Entity): MigrationSetAndJoinTable;
|
|
708
|
+
showMigrationSet(which: "Entity" | "DB", migrationSet: MigrationSet): void;
|
|
708
709
|
destroy(): Promise<void>;
|
|
709
710
|
}
|
|
710
711
|
type DBColumn = {
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkJBKIW5LDjs = require('./chunk-JBKIW5LD.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkUAG3SKFMjs = require('./chunk-UAG3SKFM.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -86,13 +86,13 @@ var _chunkW7KDVJLQjs = require('./chunk-W7KDVJLQ.js');
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
var
|
|
89
|
+
var _chunkWJGRXAXEjs = require('./chunk-WJGRXAXE.js');
|
|
90
90
|
|
|
91
91
|
// src/exceptions/error-handler.ts
|
|
92
92
|
function setupErrorHandler(server) {
|
|
93
93
|
server.setErrorHandler((error, request, reply) => {
|
|
94
94
|
error.statusCode ??= 400;
|
|
95
|
-
if (
|
|
95
|
+
if (_chunkWJGRXAXEjs.isSoException.call(void 0, error) && error.payload && Array.isArray(error.payload)) {
|
|
96
96
|
const issues = error.payload;
|
|
97
97
|
const [issue] = issues;
|
|
98
98
|
const message = `${issue.message} (${issue.path.join("/")})`;
|
|
@@ -314,13 +314,13 @@ var i = {
|
|
|
314
314
|
function index(columns) {
|
|
315
315
|
return {
|
|
316
316
|
type: "index",
|
|
317
|
-
columns:
|
|
317
|
+
columns: _chunkWJGRXAXEjs.asArray.call(void 0, columns)
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
function unique(columns) {
|
|
321
321
|
return {
|
|
322
322
|
type: "unique",
|
|
323
|
-
columns:
|
|
323
|
+
columns: _chunkWJGRXAXEjs.asArray.call(void 0, columns)
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
|
|
@@ -410,5 +410,5 @@ function unique(columns) {
|
|
|
410
410
|
|
|
411
411
|
|
|
412
412
|
|
|
413
|
-
exports.AlreadyProcessedException =
|
|
413
|
+
exports.AlreadyProcessedException = _chunkWJGRXAXEjs.AlreadyProcessedException; exports.ApiParamType = _chunkWJGRXAXEjs.ApiParamType; exports.BadRequestException = _chunkWJGRXAXEjs.BadRequestException; exports.DB = _chunkWJGRXAXEjs.DB; exports.DuplicateRowException = _chunkWJGRXAXEjs.DuplicateRowException; exports.Entity = _chunkWJGRXAXEjs.Entity; exports.EntityManager = _chunkWJGRXAXEjs.EntityManager; exports.FixtureManager = _chunkJBKIW5LDjs.FixtureManager; exports.FixtureManagerClass = _chunkJBKIW5LDjs.FixtureManagerClass; exports.GenerateOptions = _chunkWJGRXAXEjs.GenerateOptions; exports.InternalServerErrorException = _chunkWJGRXAXEjs.InternalServerErrorException; exports.Migrator = _chunkJBKIW5LDjs.Migrator; exports.NotFoundException = _chunkWJGRXAXEjs.NotFoundException; exports.PathAndCode = _chunkWJGRXAXEjs.PathAndCode; exports.RenderingNode = _chunkWJGRXAXEjs.RenderingNode; exports.SQLDateTimeString = _chunkWJGRXAXEjs.SQLDateTimeString; exports.ServiceUnavailableException = _chunkWJGRXAXEjs.ServiceUnavailableException; exports.SoException = _chunkWJGRXAXEjs.SoException; exports.Sonamu = _chunkWJGRXAXEjs.Sonamu; exports.SonamuQueryMode = _chunkWJGRXAXEjs.SonamuQueryMode; exports.Syncer = _chunkWJGRXAXEjs.Syncer; exports.TargetNotFoundException = _chunkWJGRXAXEjs.TargetNotFoundException; exports.TemplateKey = _chunkWJGRXAXEjs.TemplateKey; exports.TemplateOptions = _chunkWJGRXAXEjs.TemplateOptions; exports.UnauthorizedException = _chunkWJGRXAXEjs.UnauthorizedException; exports.UpsertBuilder = _chunkUAG3SKFMjs.UpsertBuilder; exports.api = _chunkWJGRXAXEjs.api; exports.apiParamToTsCode = _chunkWJGRXAXEjs.apiParamToTsCode; exports.apiParamTypeToTsType = _chunkWJGRXAXEjs.apiParamTypeToTsType; exports.asArray = _chunkWJGRXAXEjs.asArray; exports.findApiRootPath = _chunkWJGRXAXEjs.findApiRootPath; exports.findAppRootPath = _chunkWJGRXAXEjs.findAppRootPath; exports.getTextTypeLength = _chunkWJGRXAXEjs.getTextTypeLength; exports.getZodObjectFromApi = _chunkWJGRXAXEjs.getZodObjectFromApi; exports.getZodObjectFromApiParams = _chunkWJGRXAXEjs.getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = _chunkWJGRXAXEjs.getZodTypeFromApiParamType; exports.globAsync = _chunkWJGRXAXEjs.globAsync; exports.hydrate = _chunkWJGRXAXEjs.hydrate; exports.i = i; exports.importMultiple = _chunkWJGRXAXEjs.importMultiple; exports.isBelongsToOneRelationProp = _chunkWJGRXAXEjs.isBelongsToOneRelationProp; exports.isBigIntegerProp = _chunkWJGRXAXEjs.isBigIntegerProp; exports.isBooleanProp = _chunkWJGRXAXEjs.isBooleanProp; exports.isCustomJoinClause = _chunkWJGRXAXEjs.isCustomJoinClause; exports.isDaemonServer = _chunkWJGRXAXEjs.isDaemonServer; exports.isDateProp = _chunkWJGRXAXEjs.isDateProp; exports.isDateTimeProp = _chunkWJGRXAXEjs.isDateTimeProp; exports.isDecimalProp = _chunkWJGRXAXEjs.isDecimalProp; exports.isDevelopment = _chunkWJGRXAXEjs.isDevelopment; exports.isDoubleProp = _chunkWJGRXAXEjs.isDoubleProp; exports.isEnumProp = _chunkWJGRXAXEjs.isEnumProp; exports.isFloatProp = _chunkWJGRXAXEjs.isFloatProp; exports.isHasManyRelationProp = _chunkWJGRXAXEjs.isHasManyRelationProp; exports.isInDocker = _chunkWJGRXAXEjs.isInDocker; exports.isIntegerProp = _chunkWJGRXAXEjs.isIntegerProp; exports.isJsonProp = _chunkWJGRXAXEjs.isJsonProp; exports.isKnexError = _chunkWJGRXAXEjs.isKnexError; exports.isKyselyError = _chunkWJGRXAXEjs.isKyselyError; exports.isLocal = _chunkWJGRXAXEjs.isLocal; exports.isManyToManyRelationProp = _chunkWJGRXAXEjs.isManyToManyRelationProp; exports.isOneToOneRelationProp = _chunkWJGRXAXEjs.isOneToOneRelationProp; exports.isProduction = _chunkWJGRXAXEjs.isProduction; exports.isRefField = _chunkUAG3SKFMjs.isRefField; exports.isRelationProp = _chunkWJGRXAXEjs.isRelationProp; exports.isRemote = _chunkWJGRXAXEjs.isRemote; exports.isSoException = _chunkWJGRXAXEjs.isSoException; exports.isStaging = _chunkWJGRXAXEjs.isStaging; exports.isStringProp = _chunkWJGRXAXEjs.isStringProp; exports.isTest = _chunkWJGRXAXEjs.isTest; exports.isTextProp = _chunkWJGRXAXEjs.isTextProp; exports.isTimeProp = _chunkWJGRXAXEjs.isTimeProp; exports.isTimestampProp = _chunkWJGRXAXEjs.isTimestampProp; exports.isUuidProp = _chunkWJGRXAXEjs.isUuidProp; exports.isVirtualProp = _chunkWJGRXAXEjs.isVirtualProp; exports.nonNullable = _chunkWJGRXAXEjs.nonNullable; exports.objToMap = _chunkWJGRXAXEjs.objToMap; exports.p = p; exports.propNodeToZodTypeDef = _chunkWJGRXAXEjs.propNodeToZodTypeDef; exports.propToZodTypeDef = _chunkWJGRXAXEjs.propToZodTypeDef; exports.registeredApis = _chunkWJGRXAXEjs.registeredApis; exports.serializeZodType = _chunkWJGRXAXEjs.serializeZodType; exports.setupErrorHandler = setupErrorHandler; exports.unwrapPromiseOnce = _chunkWJGRXAXEjs.unwrapPromiseOnce; exports.zArrayable = _chunkWJGRXAXEjs.zArrayable; exports.zodTypeToTsTypeDef = _chunkWJGRXAXEjs.zodTypeToTsTypeDef; exports.zodTypeToZodCode = _chunkWJGRXAXEjs.zodTypeToZodCode;
|
|
414
414
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
FixtureManager,
|
|
3
3
|
FixtureManagerClass,
|
|
4
4
|
Migrator
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HIUT56RE.mjs";
|
|
6
6
|
import {
|
|
7
7
|
UpsertBuilder,
|
|
8
8
|
isRefField
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-HVVCQLAU.mjs";
|
|
10
10
|
import {
|
|
11
11
|
AlreadyProcessedException,
|
|
12
12
|
ApiParamType,
|
|
@@ -86,7 +86,7 @@ import {
|
|
|
86
86
|
zArrayable,
|
|
87
87
|
zodTypeToTsTypeDef,
|
|
88
88
|
zodTypeToZodCode
|
|
89
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-ZFLQLW37.mjs";
|
|
90
90
|
import "./chunk-PTFDTOJU.mjs";
|
|
91
91
|
|
|
92
92
|
// src/exceptions/error-handler.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sonamu",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Sonamu — TypeScript Fullstack API Framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"dev": "
|
|
30
|
+
"dev": "tsup --config ./tsup.config.js --watch",
|
|
31
31
|
"build": "tsup --config ./tsup.config.js"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
package/src/api/sonamu.ts
CHANGED
|
@@ -140,16 +140,25 @@ class SonamuClass {
|
|
|
140
140
|
return this._secrets;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
async initForTesting() {
|
|
144
|
+
await this.init(true, false, undefined, true);
|
|
145
|
+
}
|
|
146
|
+
|
|
143
147
|
async init(
|
|
144
148
|
doSilent: boolean = false,
|
|
145
149
|
enableSync: boolean = true,
|
|
146
|
-
apiRootPath?: string
|
|
150
|
+
apiRootPath?: string,
|
|
151
|
+
forTesting: boolean = false
|
|
147
152
|
) {
|
|
148
153
|
if (this.isInitialized) {
|
|
149
154
|
return;
|
|
150
155
|
}
|
|
151
|
-
!doSilent &&
|
|
156
|
+
!doSilent &&
|
|
157
|
+
console.time(
|
|
158
|
+
chalk.cyan(`Sonamu.init${forTesting ? " for testing" : ""}`)
|
|
159
|
+
);
|
|
152
160
|
|
|
161
|
+
// API 루트 패스
|
|
153
162
|
this.apiRootPath = apiRootPath ?? (await findApiRootPath());
|
|
154
163
|
const configPath = path.join(this.apiRootPath, "sonamu.config.json");
|
|
155
164
|
const secretsPath = path.join(this.apiRootPath, "sonamu.secrets.json");
|
|
@@ -170,8 +179,12 @@ class SonamuClass {
|
|
|
170
179
|
this.dbClient = baseConfig.client;
|
|
171
180
|
DB.init(baseConfig as any);
|
|
172
181
|
this.dbConfig = DB.fullConfig;
|
|
173
|
-
|
|
174
|
-
//
|
|
182
|
+
|
|
183
|
+
// 테스팅인 경우 엔티티 로드 & 싱크 없이 중단
|
|
184
|
+
if (forTesting) {
|
|
185
|
+
this.isInitialized = true;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
175
188
|
|
|
176
189
|
// Entity 로드
|
|
177
190
|
await EntityManager.autoload(doSilent);
|
package/src/bin/cli.ts
CHANGED
package/src/entity/migrator.ts
CHANGED
|
@@ -178,7 +178,7 @@ export class Migrator {
|
|
|
178
178
|
if (onlyTs.length > 0) {
|
|
179
179
|
console.debug({ onlyTs });
|
|
180
180
|
throw new ServiceUnavailableException(
|
|
181
|
-
`There
|
|
181
|
+
`There are un-compiled TS migration files.\nPlease compile them first.\n\n${onlyTs
|
|
182
182
|
.map((f) => f.name)
|
|
183
183
|
.join("\n")}`
|
|
184
184
|
);
|
|
@@ -454,7 +454,7 @@ export class Migrator {
|
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
//
|
|
457
|
+
// Entity-DB간 비교하여 코드 생성 리턴
|
|
458
458
|
const codes = await this.compareMigrations(this.targets.compare!);
|
|
459
459
|
if (codes.length === 0) {
|
|
460
460
|
console.log(chalk.green("\n현재 모두 싱크된 상태입니다."));
|
|
@@ -667,10 +667,10 @@ export class Migrator {
|
|
|
667
667
|
async compareMigrations(
|
|
668
668
|
compareDB: KnexClient | KyselyClient
|
|
669
669
|
): Promise<GenMigrationCode[]> {
|
|
670
|
-
//
|
|
670
|
+
// Entity 순회하여 싱크
|
|
671
671
|
const entityIds = EntityManager.getAllIds();
|
|
672
672
|
|
|
673
|
-
// 조인테이블 포함하여
|
|
673
|
+
// 조인테이블 포함하여 Entity에서 MigrationSet 추출
|
|
674
674
|
const entitySetsWithJoinTable = entityIds
|
|
675
675
|
.filter((entityId) => {
|
|
676
676
|
const entity = EntityManager.get(entityId);
|
|
@@ -678,16 +678,28 @@ export class Migrator {
|
|
|
678
678
|
})
|
|
679
679
|
.map((entityId) => {
|
|
680
680
|
const entity = EntityManager.get(entityId);
|
|
681
|
-
return this.
|
|
681
|
+
return this.getMigrationSetFromEntity(entity);
|
|
682
682
|
});
|
|
683
683
|
|
|
684
684
|
// 조인테이블만 추출
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
(
|
|
688
|
-
|
|
685
|
+
const joinTablesWithDup = entitySetsWithJoinTable
|
|
686
|
+
.map((entitySet) => entitySet.joinTables)
|
|
687
|
+
.flat();
|
|
688
|
+
// 중복 제거 (중복인 경우 indexes를 병합)
|
|
689
|
+
const joinTables = Object.values(
|
|
690
|
+
_.groupBy(joinTablesWithDup, (jt) => jt.table)
|
|
691
|
+
).map((tables) => {
|
|
692
|
+
if (tables.length === 1) {
|
|
693
|
+
return tables[0];
|
|
689
694
|
}
|
|
690
|
-
|
|
695
|
+
return {
|
|
696
|
+
...tables[0],
|
|
697
|
+
indexes: _.uniqBy(
|
|
698
|
+
tables.flatMap((t) => t.indexes),
|
|
699
|
+
(index) => [index.type, ...index.columns.sort()].join("-")
|
|
700
|
+
),
|
|
701
|
+
};
|
|
702
|
+
});
|
|
691
703
|
|
|
692
704
|
// 조인테이블 포함하여 MigrationSet 배열
|
|
693
705
|
const entitySets: MigrationSet[] = [
|
|
@@ -695,7 +707,7 @@ export class Migrator {
|
|
|
695
707
|
...joinTables,
|
|
696
708
|
];
|
|
697
709
|
|
|
698
|
-
|
|
710
|
+
const codes: GenMigrationCode[] = (
|
|
699
711
|
await Promise.all(
|
|
700
712
|
entitySets.map(async (entitySet) => {
|
|
701
713
|
const dbSet = await this.getMigrationSetFromDB(
|
|
@@ -776,7 +788,7 @@ export class Migrator {
|
|
|
776
788
|
if (isEqualColumns && isEqualIndexes) {
|
|
777
789
|
return null;
|
|
778
790
|
} else {
|
|
779
|
-
// this.showMigrationSet("
|
|
791
|
+
// this.showMigrationSet("Entity", entitySet);
|
|
780
792
|
// this.showMigrationSet("DB", dbSet);
|
|
781
793
|
return DB.generator.generateAlterCode_ColumnAndIndexes(
|
|
782
794
|
entitySet.table,
|
|
@@ -807,7 +819,15 @@ export class Migrator {
|
|
|
807
819
|
).map((f) => replaceNoActionOnMySQL(f));
|
|
808
820
|
|
|
809
821
|
if (equal(entityForeigns, dbForeigns) === false) {
|
|
810
|
-
// console.dir(
|
|
822
|
+
// console.dir(
|
|
823
|
+
// {
|
|
824
|
+
// debugOn: "foreign",
|
|
825
|
+
// table: entitySet.table,
|
|
826
|
+
// entityForeigns,
|
|
827
|
+
// dbForeigns,
|
|
828
|
+
// },
|
|
829
|
+
// { depth: null }
|
|
830
|
+
// );
|
|
811
831
|
return DB.generator.generateAlterCode_Foreigns(
|
|
812
832
|
entitySet.table,
|
|
813
833
|
entityForeigns,
|
|
@@ -1081,9 +1101,9 @@ export class Migrator {
|
|
|
1081
1101
|
}
|
|
1082
1102
|
|
|
1083
1103
|
/*
|
|
1084
|
-
|
|
1104
|
+
Entity 내용 읽어서 MigrationSetAndJoinTable 추출
|
|
1085
1105
|
*/
|
|
1086
|
-
|
|
1106
|
+
getMigrationSetFromEntity(entity: Entity): MigrationSetAndJoinTable {
|
|
1087
1107
|
const migrationSet: MigrationSetAndJoinTable = entity.props.reduce(
|
|
1088
1108
|
(r, prop) => {
|
|
1089
1109
|
// virtual 필드 제외
|
|
@@ -1193,9 +1213,21 @@ export class Migrator {
|
|
|
1193
1213
|
},
|
|
1194
1214
|
],
|
|
1195
1215
|
foreigns: fields.map((field) => {
|
|
1216
|
+
// 현재 필드가 어떤 테이블에 속하는지 판단
|
|
1217
|
+
const col = field.split(".")[1];
|
|
1218
|
+
const to = (() => {
|
|
1219
|
+
if (
|
|
1220
|
+
inflection.singularize(join.to.split(".")[0]) + "_id" ===
|
|
1221
|
+
col
|
|
1222
|
+
) {
|
|
1223
|
+
return join.to;
|
|
1224
|
+
} else {
|
|
1225
|
+
return join.from;
|
|
1226
|
+
}
|
|
1227
|
+
})();
|
|
1196
1228
|
return {
|
|
1197
|
-
columns: [
|
|
1198
|
-
to
|
|
1229
|
+
columns: [col],
|
|
1230
|
+
to,
|
|
1199
1231
|
onUpdate: through.onUpdate,
|
|
1200
1232
|
onDelete: through.onDelete,
|
|
1201
1233
|
};
|
|
@@ -1255,10 +1287,10 @@ export class Migrator {
|
|
|
1255
1287
|
/*
|
|
1256
1288
|
마이그레이션 컬럼 배열 비교용 코드
|
|
1257
1289
|
*/
|
|
1258
|
-
showMigrationSet(which:
|
|
1290
|
+
showMigrationSet(which: "Entity" | "DB", migrationSet: MigrationSet): void {
|
|
1259
1291
|
const { columns, indexes, foreigns } = migrationSet;
|
|
1260
1292
|
const styledChalk =
|
|
1261
|
-
which === "
|
|
1293
|
+
which === "Entity" ? chalk.bgGreen.black : chalk.bgBlue.black;
|
|
1262
1294
|
console.log(
|
|
1263
1295
|
styledChalk(
|
|
1264
1296
|
`${which} ${migrationSet.table} Columns\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`
|