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.
Files changed (35) hide show
  1. package/dist/bin/cli.js +51 -51
  2. package/dist/bin/cli.js.map +1 -1
  3. package/dist/bin/cli.mjs +2 -2
  4. package/dist/bin/cli.mjs.map +1 -1
  5. package/dist/{chunk-FLPD24HS.mjs → chunk-4K2F3SOM.mjs} +2 -2
  6. package/dist/{chunk-I2MMJRJN.mjs → chunk-HIUT56RE.mjs} +32 -15
  7. package/dist/chunk-HIUT56RE.mjs.map +1 -0
  8. package/dist/{chunk-QK5XXJUX.mjs → chunk-HVVCQLAU.mjs} +2 -2
  9. package/dist/{chunk-Z2P7XTXE.js → chunk-JBKIW5LD.js} +130 -113
  10. package/dist/chunk-JBKIW5LD.js.map +1 -0
  11. package/dist/{chunk-U636LQJJ.js → chunk-N6N3LENC.js} +4 -4
  12. package/dist/{chunk-W7KDVJLQ.js → chunk-UAG3SKFM.js} +7 -7
  13. package/dist/{chunk-XT6LHCX5.js → chunk-WJGRXAXE.js} +12 -4
  14. package/dist/chunk-WJGRXAXE.js.map +1 -0
  15. package/dist/{chunk-PP2PSSAG.mjs → chunk-ZFLQLW37.mjs} +12 -4
  16. package/dist/{chunk-PP2PSSAG.mjs.map → chunk-ZFLQLW37.mjs.map} +1 -1
  17. package/dist/database/drivers/knex/base-model.js +8 -8
  18. package/dist/database/drivers/knex/base-model.mjs +3 -3
  19. package/dist/database/drivers/kysely/base-model.js +9 -9
  20. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  21. package/dist/index.d.mts +4 -3
  22. package/dist/index.d.ts +4 -3
  23. package/dist/index.js +7 -7
  24. package/dist/index.mjs +3 -3
  25. package/package.json +2 -2
  26. package/src/api/sonamu.ts +17 -4
  27. package/src/bin/cli.ts +1 -0
  28. package/src/entity/migrator.ts +51 -19
  29. package/dist/chunk-I2MMJRJN.mjs.map +0 -1
  30. package/dist/chunk-XT6LHCX5.js.map +0 -1
  31. package/dist/chunk-Z2P7XTXE.js.map +0 -1
  32. /package/dist/{chunk-FLPD24HS.mjs.map → chunk-4K2F3SOM.mjs.map} +0 -0
  33. /package/dist/{chunk-QK5XXJUX.mjs.map → chunk-HVVCQLAU.mjs.map} +0 -0
  34. /package/dist/{chunk-U636LQJJ.js.map → chunk-N6N3LENC.js.map} +0 -0
  35. /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 _chunkU636LQJJjs = require('../../../chunk-U636LQJJ.js');
3
+ var _chunkN6N3LENCjs = require('../../../chunk-N6N3LENC.js');
4
4
 
5
5
 
6
- var _chunkW7KDVJLQjs = require('../../../chunk-W7KDVJLQ.js');
6
+ var _chunkUAG3SKFMjs = require('../../../chunk-UAG3SKFM.js');
7
7
 
8
8
 
9
9
 
10
- var _chunkXT6LHCX5js = require('../../../chunk-XT6LHCX5.js');
10
+ var _chunkWJGRXAXEjs = require('../../../chunk-WJGRXAXE.js');
11
11
 
12
12
  // src/database/drivers/knex/base-model.ts
13
- var BaseModelClass = class extends _chunkU636LQJJjs.BaseModelClassAbstract {
13
+ var BaseModelClass = class extends _chunkN6N3LENCjs.BaseModelClassAbstract {
14
14
  getDB(which) {
15
- return _chunkXT6LHCX5js.DB.getDB(which);
15
+ return _chunkWJGRXAXEjs.DB.getDB(which);
16
16
  }
17
17
  async destroy() {
18
- return _chunkXT6LHCX5js.DB.destroy();
18
+ return _chunkWJGRXAXEjs.DB.destroy();
19
19
  }
20
20
  getUpsertBuilder() {
21
- return new (0, _chunkW7KDVJLQjs.UpsertBuilder)();
21
+ return new (0, _chunkUAG3SKFMjs.UpsertBuilder)();
22
22
  }
23
23
  applyJoins(clonedQb, joins) {
24
24
  for (const join of joins) {
25
- if (_chunkXT6LHCX5js.isCustomJoinClause.call(void 0, join)) {
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-FLPD24HS.mjs";
3
+ } from "../../../chunk-4K2F3SOM.mjs";
4
4
  import {
5
5
  UpsertBuilder
6
- } from "../../../chunk-QK5XXJUX.mjs";
6
+ } from "../../../chunk-HVVCQLAU.mjs";
7
7
  import {
8
8
  DB,
9
9
  isCustomJoinClause
10
- } from "../../../chunk-PP2PSSAG.mjs";
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 _chunkU636LQJJjs = require('../../../chunk-U636LQJJ.js');
3
+ var _chunkN6N3LENCjs = require('../../../chunk-N6N3LENC.js');
4
4
 
5
5
 
6
- var _chunkW7KDVJLQjs = require('../../../chunk-W7KDVJLQ.js');
6
+ var _chunkUAG3SKFMjs = require('../../../chunk-UAG3SKFM.js');
7
7
 
8
8
 
9
9
 
10
10
 
11
- var _chunkXT6LHCX5js = require('../../../chunk-XT6LHCX5.js');
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 _chunkU636LQJJjs.BaseModelClassAbstract {
15
+ var BaseModelClass = class extends _chunkN6N3LENCjs.BaseModelClassAbstract {
16
16
  getDB(which) {
17
- return _chunkXT6LHCX5js.DB.getDB(which);
17
+ return _chunkWJGRXAXEjs.DB.getDB(which);
18
18
  }
19
19
  async destroy() {
20
- return _chunkXT6LHCX5js.DB.destroy();
20
+ return _chunkWJGRXAXEjs.DB.destroy();
21
21
  }
22
22
  getUpsertBuilder() {
23
- return new (0, _chunkW7KDVJLQjs.UpsertBuilder)();
23
+ return new (0, _chunkUAG3SKFMjs.UpsertBuilder)();
24
24
  }
25
25
  applyJoins(clonedQb, joins) {
26
26
  for (const join of joins) {
27
- if (_chunkXT6LHCX5js.isCustomJoinClause.call(void 0, join)) {
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 = _chunkXT6LHCX5js.EntityManager.get(_inflection2.default.classify(table));
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-FLPD24HS.mjs";
3
+ } from "../../../chunk-4K2F3SOM.mjs";
4
4
  import {
5
5
  UpsertBuilder
6
- } from "../../../chunk-QK5XXJUX.mjs";
6
+ } from "../../../chunk-HVVCQLAU.mjs";
7
7
  import {
8
8
  DB,
9
9
  EntityManager,
10
10
  isCustomJoinClause
11
- } from "../../../chunk-PP2PSSAG.mjs";
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
- init(doSilent?: boolean, enableSync?: boolean, apiRootPath?: string): Promise<void>;
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
- getMigrationSetFromMD(entity: Entity): MigrationSetAndJoinTable;
707
- showMigrationSet(which: string, migrationSet: MigrationSet): void;
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
- init(doSilent?: boolean, enableSync?: boolean, apiRootPath?: string): Promise<void>;
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
- getMigrationSetFromMD(entity: Entity): MigrationSetAndJoinTable;
707
- showMigrationSet(which: string, migrationSet: MigrationSet): void;
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 _chunkZ2P7XTXEjs = require('./chunk-Z2P7XTXE.js');
5
+ var _chunkJBKIW5LDjs = require('./chunk-JBKIW5LD.js');
6
6
 
7
7
 
8
8
 
9
- var _chunkW7KDVJLQjs = require('./chunk-W7KDVJLQ.js');
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 _chunkXT6LHCX5js = require('./chunk-XT6LHCX5.js');
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 (_chunkXT6LHCX5js.isSoException.call(void 0, error) && error.payload && Array.isArray(error.payload)) {
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: _chunkXT6LHCX5js.asArray.call(void 0, 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: _chunkXT6LHCX5js.asArray.call(void 0, 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 = _chunkXT6LHCX5js.AlreadyProcessedException; exports.ApiParamType = _chunkXT6LHCX5js.ApiParamType; exports.BadRequestException = _chunkXT6LHCX5js.BadRequestException; exports.DB = _chunkXT6LHCX5js.DB; exports.DuplicateRowException = _chunkXT6LHCX5js.DuplicateRowException; exports.Entity = _chunkXT6LHCX5js.Entity; exports.EntityManager = _chunkXT6LHCX5js.EntityManager; exports.FixtureManager = _chunkZ2P7XTXEjs.FixtureManager; exports.FixtureManagerClass = _chunkZ2P7XTXEjs.FixtureManagerClass; exports.GenerateOptions = _chunkXT6LHCX5js.GenerateOptions; exports.InternalServerErrorException = _chunkXT6LHCX5js.InternalServerErrorException; exports.Migrator = _chunkZ2P7XTXEjs.Migrator; exports.NotFoundException = _chunkXT6LHCX5js.NotFoundException; exports.PathAndCode = _chunkXT6LHCX5js.PathAndCode; exports.RenderingNode = _chunkXT6LHCX5js.RenderingNode; exports.SQLDateTimeString = _chunkXT6LHCX5js.SQLDateTimeString; exports.ServiceUnavailableException = _chunkXT6LHCX5js.ServiceUnavailableException; exports.SoException = _chunkXT6LHCX5js.SoException; exports.Sonamu = _chunkXT6LHCX5js.Sonamu; exports.SonamuQueryMode = _chunkXT6LHCX5js.SonamuQueryMode; exports.Syncer = _chunkXT6LHCX5js.Syncer; exports.TargetNotFoundException = _chunkXT6LHCX5js.TargetNotFoundException; exports.TemplateKey = _chunkXT6LHCX5js.TemplateKey; exports.TemplateOptions = _chunkXT6LHCX5js.TemplateOptions; exports.UnauthorizedException = _chunkXT6LHCX5js.UnauthorizedException; exports.UpsertBuilder = _chunkW7KDVJLQjs.UpsertBuilder; exports.api = _chunkXT6LHCX5js.api; exports.apiParamToTsCode = _chunkXT6LHCX5js.apiParamToTsCode; exports.apiParamTypeToTsType = _chunkXT6LHCX5js.apiParamTypeToTsType; exports.asArray = _chunkXT6LHCX5js.asArray; exports.findApiRootPath = _chunkXT6LHCX5js.findApiRootPath; exports.findAppRootPath = _chunkXT6LHCX5js.findAppRootPath; exports.getTextTypeLength = _chunkXT6LHCX5js.getTextTypeLength; exports.getZodObjectFromApi = _chunkXT6LHCX5js.getZodObjectFromApi; exports.getZodObjectFromApiParams = _chunkXT6LHCX5js.getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = _chunkXT6LHCX5js.getZodTypeFromApiParamType; exports.globAsync = _chunkXT6LHCX5js.globAsync; exports.hydrate = _chunkXT6LHCX5js.hydrate; exports.i = i; exports.importMultiple = _chunkXT6LHCX5js.importMultiple; exports.isBelongsToOneRelationProp = _chunkXT6LHCX5js.isBelongsToOneRelationProp; exports.isBigIntegerProp = _chunkXT6LHCX5js.isBigIntegerProp; exports.isBooleanProp = _chunkXT6LHCX5js.isBooleanProp; exports.isCustomJoinClause = _chunkXT6LHCX5js.isCustomJoinClause; exports.isDaemonServer = _chunkXT6LHCX5js.isDaemonServer; exports.isDateProp = _chunkXT6LHCX5js.isDateProp; exports.isDateTimeProp = _chunkXT6LHCX5js.isDateTimeProp; exports.isDecimalProp = _chunkXT6LHCX5js.isDecimalProp; exports.isDevelopment = _chunkXT6LHCX5js.isDevelopment; exports.isDoubleProp = _chunkXT6LHCX5js.isDoubleProp; exports.isEnumProp = _chunkXT6LHCX5js.isEnumProp; exports.isFloatProp = _chunkXT6LHCX5js.isFloatProp; exports.isHasManyRelationProp = _chunkXT6LHCX5js.isHasManyRelationProp; exports.isInDocker = _chunkXT6LHCX5js.isInDocker; exports.isIntegerProp = _chunkXT6LHCX5js.isIntegerProp; exports.isJsonProp = _chunkXT6LHCX5js.isJsonProp; exports.isKnexError = _chunkXT6LHCX5js.isKnexError; exports.isKyselyError = _chunkXT6LHCX5js.isKyselyError; exports.isLocal = _chunkXT6LHCX5js.isLocal; exports.isManyToManyRelationProp = _chunkXT6LHCX5js.isManyToManyRelationProp; exports.isOneToOneRelationProp = _chunkXT6LHCX5js.isOneToOneRelationProp; exports.isProduction = _chunkXT6LHCX5js.isProduction; exports.isRefField = _chunkW7KDVJLQjs.isRefField; exports.isRelationProp = _chunkXT6LHCX5js.isRelationProp; exports.isRemote = _chunkXT6LHCX5js.isRemote; exports.isSoException = _chunkXT6LHCX5js.isSoException; exports.isStaging = _chunkXT6LHCX5js.isStaging; exports.isStringProp = _chunkXT6LHCX5js.isStringProp; exports.isTest = _chunkXT6LHCX5js.isTest; exports.isTextProp = _chunkXT6LHCX5js.isTextProp; exports.isTimeProp = _chunkXT6LHCX5js.isTimeProp; exports.isTimestampProp = _chunkXT6LHCX5js.isTimestampProp; exports.isUuidProp = _chunkXT6LHCX5js.isUuidProp; exports.isVirtualProp = _chunkXT6LHCX5js.isVirtualProp; exports.nonNullable = _chunkXT6LHCX5js.nonNullable; exports.objToMap = _chunkXT6LHCX5js.objToMap; exports.p = p; exports.propNodeToZodTypeDef = _chunkXT6LHCX5js.propNodeToZodTypeDef; exports.propToZodTypeDef = _chunkXT6LHCX5js.propToZodTypeDef; exports.registeredApis = _chunkXT6LHCX5js.registeredApis; exports.serializeZodType = _chunkXT6LHCX5js.serializeZodType; exports.setupErrorHandler = setupErrorHandler; exports.unwrapPromiseOnce = _chunkXT6LHCX5js.unwrapPromiseOnce; exports.zArrayable = _chunkXT6LHCX5js.zArrayable; exports.zodTypeToTsTypeDef = _chunkXT6LHCX5js.zodTypeToTsTypeDef; exports.zodTypeToZodCode = _chunkXT6LHCX5js.zodTypeToZodCode;
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-I2MMJRJN.mjs";
5
+ } from "./chunk-HIUT56RE.mjs";
6
6
  import {
7
7
  UpsertBuilder,
8
8
  isRefField
9
- } from "./chunk-QK5XXJUX.mjs";
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-PP2PSSAG.mjs";
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.1",
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": "yarn tsc -w -p ./tsconfig.json",
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 && console.time(chalk.cyan("Sonamu.init"));
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
- !doSilent && console.log(chalk.green("DB Config Loaded!"));
174
- // attachOnDuplicateUpdate();
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
@@ -126,6 +126,7 @@ async function migrate_status() {
126
126
  await setupMigrator();
127
127
 
128
128
  const status = await migrator.getStatus();
129
+ // status;
129
130
  console.log(status);
130
131
  }
131
132
 
@@ -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 is an un-compiled TS migration files.\nPlease compile them first.\n\n${onlyTs
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
- // MD-DB간 비교하여 코드 생성 리턴
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
- // MD 순회하여 싱크
670
+ // Entity 순회하여 싱크
671
671
  const entityIds = EntityManager.getAllIds();
672
672
 
673
- // 조인테이블 포함하여 MD에서 MigrationSet 추출
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.getMigrationSetFromMD(entity);
681
+ return this.getMigrationSetFromEntity(entity);
682
682
  });
683
683
 
684
684
  // 조인테이블만 추출
685
- const joinTables = _.uniqBy(
686
- entitySetsWithJoinTable.map((entitySet) => entitySet.joinTables).flat(),
687
- (joinTable) => {
688
- return joinTable.table;
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
- let codes: GenMigrationCode[] = (
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("MD", entitySet);
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({ entityForeigns, dbForeigns }, { depth: null });
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
- MD 내용 읽어서 MigrationSetAndJoinTable 추출
1104
+ Entity 내용 읽어서 MigrationSetAndJoinTable 추출
1085
1105
  */
1086
- getMigrationSetFromMD(entity: Entity): MigrationSetAndJoinTable {
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: [field.split(".")[1]],
1198
- to: through.to.includes(field) ? join.to : join.from,
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: string, migrationSet: MigrationSet): void {
1290
+ showMigrationSet(which: "Entity" | "DB", migrationSet: MigrationSet): void {
1259
1291
  const { columns, indexes, foreigns } = migrationSet;
1260
1292
  const styledChalk =
1261
- which === "MD" ? chalk.bgGreen.black : chalk.bgBlue.black;
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`