sonamu 0.2.37 → 0.2.38

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 (85) hide show
  1. package/.pnp.cjs +2117 -86
  2. package/dist/api/decorators.js +5 -2
  3. package/dist/api/decorators.js.map +1 -1
  4. package/dist/api/sonamu.js +3 -3
  5. package/dist/api/sonamu.js.map +1 -1
  6. package/dist/bin/cli-wrapper.d.ts +3 -0
  7. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  8. package/dist/bin/cli-wrapper.js +27 -0
  9. package/dist/bin/cli-wrapper.js.map +1 -0
  10. package/dist/bin/cli.js +10 -10
  11. package/dist/bin/cli.js.map +1 -1
  12. package/dist/database/base-model.d.ts.map +1 -1
  13. package/dist/database/base-model.js +14 -13
  14. package/dist/database/base-model.js.map +1 -1
  15. package/dist/database/db.js +1 -1
  16. package/dist/database/db.js.map +1 -1
  17. package/dist/database/upsert-builder.js +8 -5
  18. package/dist/database/upsert-builder.js.map +1 -1
  19. package/dist/entity/entity-manager.d.ts.map +1 -1
  20. package/dist/entity/entity-manager.js +14 -12
  21. package/dist/entity/entity-manager.js.map +1 -1
  22. package/dist/entity/entity-utils.js +5 -2
  23. package/dist/entity/entity-utils.js.map +1 -1
  24. package/dist/entity/entity.d.ts.map +1 -1
  25. package/dist/entity/entity.js +20 -18
  26. package/dist/entity/entity.js.map +1 -1
  27. package/dist/entity/migrator.d.ts.map +1 -1
  28. package/dist/entity/migrator.js +56 -52
  29. package/dist/entity/migrator.js.map +1 -1
  30. package/dist/smd/smd-manager.d.ts.map +1 -1
  31. package/dist/smd/smd-manager.js +13 -9
  32. package/dist/smd/smd-manager.js.map +1 -1
  33. package/dist/smd/smd.d.ts.map +1 -1
  34. package/dist/smd/smd.js +13 -14
  35. package/dist/smd/smd.js.map +1 -1
  36. package/dist/syncer/syncer.d.ts +1 -1
  37. package/dist/syncer/syncer.d.ts.map +1 -1
  38. package/dist/syncer/syncer.js +68 -67
  39. package/dist/syncer/syncer.js.map +1 -1
  40. package/dist/templates/generated.template.js +6 -3
  41. package/dist/templates/generated.template.js.map +1 -1
  42. package/dist/templates/generated_sso.template.js +7 -4
  43. package/dist/templates/generated_sso.template.js.map +1 -1
  44. package/dist/templates/service.template.js +13 -10
  45. package/dist/templates/service.template.js.map +1 -1
  46. package/dist/templates/view_enums_dropdown.template.js +5 -2
  47. package/dist/templates/view_enums_dropdown.template.js.map +1 -1
  48. package/dist/templates/view_form.template.d.ts.map +1 -1
  49. package/dist/templates/view_form.template.js +7 -4
  50. package/dist/templates/view_form.template.js.map +1 -1
  51. package/dist/templates/view_id_async_select.template.js.map +1 -1
  52. package/dist/templates/view_list.template.js +10 -7
  53. package/dist/templates/view_list.template.js.map +1 -1
  54. package/dist/testing/fixture-manager.js +3 -3
  55. package/dist/testing/fixture-manager.js.map +1 -1
  56. package/dist/utils/sql-parser.js +5 -2
  57. package/dist/utils/sql-parser.js.map +1 -1
  58. package/dist/utils/utils.js +2 -2
  59. package/dist/utils/utils.js.map +1 -1
  60. package/package.json +19 -5
  61. package/src/api/decorators.ts +3 -3
  62. package/src/api/sonamu.ts +3 -3
  63. package/src/bin/cli-wrapper.ts +34 -0
  64. package/src/bin/cli.ts +10 -16
  65. package/src/database/base-model.ts +18 -15
  66. package/src/database/db.ts +1 -1
  67. package/src/database/upsert-builder.ts +5 -5
  68. package/src/entity/entity-manager.ts +14 -12
  69. package/src/entity/entity-utils.ts +2 -2
  70. package/src/entity/entity.ts +13 -11
  71. package/src/entity/migrator.ts +70 -82
  72. package/src/smd/smd-manager.ts +13 -9
  73. package/src/smd/smd.ts +10 -11
  74. package/src/syncer/syncer.ts +44 -44
  75. package/src/templates/generated.template.ts +3 -3
  76. package/src/templates/generated_sso.template.ts +4 -4
  77. package/src/templates/service.template.ts +10 -10
  78. package/src/templates/view_enums_dropdown.template.ts +2 -2
  79. package/src/templates/view_form.template.ts +36 -33
  80. package/src/templates/view_id_async_select.template.ts +4 -4
  81. package/src/templates/view_list.template.ts +18 -18
  82. package/src/testing/fixture-manager.ts +3 -3
  83. package/src/utils/sql-parser.ts +2 -2
  84. package/src/utils/utils.ts +2 -2
  85. package/tsup.config.js +21 -0
@@ -1,6 +1,5 @@
1
- import { groupBy, uniq } from "lodash";
1
+ import _ from "lodash";
2
2
  import { EntityManager as EntityManager } from "./entity-manager";
3
- import { dasherize, pluralize, underscore } from "inflection";
4
3
  import {
5
4
  EntityProp,
6
5
  RelationProp,
@@ -20,7 +19,7 @@ import {
20
19
  } from "../types/types";
21
20
  import inflection from "inflection";
22
21
  import path from "path";
23
- import { existsSync, writeFileSync } from "fs";
22
+ import fs from "fs-extra";
24
23
  import { z } from "zod";
25
24
  import { Sonamu } from "../api/sonamu";
26
25
  import prettier from "prettier";
@@ -73,7 +72,7 @@ export class Entity {
73
72
  this.id = id;
74
73
  this.parentId = parentId;
75
74
  this.title = title ?? this.id;
76
- this.table = table ?? underscore(pluralize(id));
75
+ this.table = table ?? inflection.underscore(inflection.pluralize(id));
77
76
 
78
77
  // props
79
78
  if (props) {
@@ -128,8 +127,10 @@ export class Entity {
128
127
 
129
128
  // names
130
129
  this.names = {
131
- parentFs: dasherize(underscore(parentId ?? id)).toLowerCase(),
132
- fs: dasherize(underscore(id)).toLowerCase(),
130
+ parentFs: inflection
131
+ .dasherize(inflection.underscore(parentId ?? id))
132
+ .toLowerCase(),
133
+ fs: inflection.dasherize(inflection.underscore(id)).toLowerCase(),
133
134
  module: id,
134
135
  };
135
136
 
@@ -158,7 +159,7 @@ export class Entity {
158
159
  prefix = prefix.replace(/\./g, "__");
159
160
 
160
161
  // 서브셋을 1뎁스만 분리하여 그룹핑
161
- const subsetGroup = groupBy(fields, (field) => {
162
+ const subsetGroup = _.groupBy(fields, (field) => {
162
163
  if (field.includes(".")) {
163
164
  const [rel] = field.split(".");
164
165
  return rel;
@@ -271,7 +272,7 @@ export class Entity {
271
272
  to = `${joinAs}.id`;
272
273
  } else {
273
274
  from = `${fromTable}.id`;
274
- to = `${joinAs}.${underscore(
275
+ to = `${joinAs}.${inflection.underscore(
275
276
  this.names.fs.replace(/\-/g, "_")
276
277
  )}_id`;
277
278
  }
@@ -302,6 +303,7 @@ export class Entity {
302
303
  manyJoin: loader.manyJoin,
303
304
  oneJoins: loader.oneJoins,
304
305
  select: loader.select,
306
+ loaders: loader.loaders,
305
307
  };
306
308
  });
307
309
 
@@ -575,7 +577,7 @@ export class Entity {
575
577
  `dist/application/${typesModulePath}.js`
576
578
  );
577
579
 
578
- if (existsSync(typesFileDistPath)) {
580
+ if (fs.existsSync(typesFileDistPath)) {
579
581
  const importPath = path.relative(__dirname, typesFileDistPath);
580
582
  import(importPath).then((t) => {
581
583
  this.types = Object.keys(t).reduce((result, key) => {
@@ -629,7 +631,7 @@ export class Entity {
629
631
  `src/application/${this.names.parentFs}/${this.names.fs}.entity.json`
630
632
  );
631
633
  const json = this.toJson();
632
- writeFileSync(
634
+ fs.writeFileSync(
633
635
  jsonPath,
634
636
  await prettier.format(JSON.stringify(json), {
635
637
  parser: "json",
@@ -650,7 +652,7 @@ export class Entity {
650
652
 
651
653
  const subsets = _subsets ?? this.subsets;
652
654
  const subsetKeys = Object.keys(subsets);
653
- const allFields = uniq(subsetKeys.map((key) => subsets[key]).flat());
655
+ const allFields = _.uniq(subsetKeys.map((key) => subsets[key]).flat());
654
656
 
655
657
  return this.props.map((prop) => {
656
658
  if (
@@ -1,29 +1,11 @@
1
- import _, {
2
- difference,
3
- differenceBy,
4
- differenceWith,
5
- groupBy,
6
- intersection,
7
- intersectionBy,
8
- pick,
9
- sortBy,
10
- sum,
11
- uniq,
12
- uniqBy,
13
- } from "lodash";
1
+ import _ from "lodash";
14
2
  import knex, { Knex } from "knex";
15
3
  import prettier from "prettier";
16
4
  import chalk from "chalk";
17
5
  import { DateTime } from "luxon";
18
- import {
19
- existsSync,
20
- mkdirSync,
21
- readdirSync,
22
- unlinkSync,
23
- writeFileSync,
24
- } from "fs";
6
+ import fs from "fs-extra";
25
7
  import equal from "fast-deep-equal";
26
- import { capitalize, pluralize, singularize, underscore } from "inflection";
8
+ import inflection from "inflection";
27
9
  import prompts from "prompts";
28
10
  import { execSync } from "child_process";
29
11
  import path from "path";
@@ -141,24 +123,26 @@ export class Migrator {
141
123
  const srcMigrationsDir = `${Sonamu.apiRootPath}/src/migrations`;
142
124
  const distMigrationsDir = `${Sonamu.apiRootPath}/dist/migrations`;
143
125
 
144
- if (existsSync(srcMigrationsDir) === false) {
145
- mkdirSync(srcMigrationsDir, {
126
+ if (fs.existsSync(srcMigrationsDir) === false) {
127
+ fs.mkdirSync(srcMigrationsDir, {
146
128
  recursive: true,
147
129
  });
148
130
  }
149
- if (existsSync(distMigrationsDir) === false) {
150
- mkdirSync(distMigrationsDir, {
131
+ if (fs.existsSync(distMigrationsDir) === false) {
132
+ fs.mkdirSync(distMigrationsDir, {
151
133
  recursive: true,
152
134
  });
153
135
  }
154
- const srcMigrations = readdirSync(srcMigrationsDir)
136
+ const srcMigrations = fs
137
+ .readdirSync(srcMigrationsDir)
155
138
  .filter((f) => f.endsWith(".ts"))
156
139
  .map((f) => f.split(".")[0]);
157
- const distMigrations = readdirSync(distMigrationsDir)
140
+ const distMigrations = fs
141
+ .readdirSync(distMigrationsDir)
158
142
  .filter((f) => f.endsWith(".js"))
159
143
  .map((f) => f.split(".")[0]);
160
144
 
161
- const normal = intersection(srcMigrations, distMigrations)
145
+ const normal = _.intersection(srcMigrations, distMigrations)
162
146
  .map((filename) => {
163
147
  return {
164
148
  name: filename,
@@ -167,19 +151,23 @@ export class Migrator {
167
151
  })
168
152
  .sort((a, b) => (a > b ? 1 : -1));
169
153
 
170
- const onlyTs = difference(srcMigrations, distMigrations).map((filename) => {
171
- return {
172
- name: filename,
173
- path: path.join(srcMigrationsDir, filename) + ".ts",
174
- };
175
- });
154
+ const onlyTs = _.difference(srcMigrations, distMigrations).map(
155
+ (filename) => {
156
+ return {
157
+ name: filename,
158
+ path: path.join(srcMigrationsDir, filename) + ".ts",
159
+ };
160
+ }
161
+ );
176
162
 
177
- const onlyJs = difference(distMigrations, srcMigrations).map((filename) => {
178
- return {
179
- name: filename,
180
- path: path.join(distMigrationsDir, filename) + ".js",
181
- };
182
- });
163
+ const onlyJs = _.difference(distMigrations, srcMigrations).map(
164
+ (filename) => {
165
+ return {
166
+ name: filename,
167
+ path: path.join(distMigrationsDir, filename) + ".js",
168
+ };
169
+ }
170
+ );
183
171
 
184
172
  return {
185
173
  normal,
@@ -306,7 +294,7 @@ export class Migrator {
306
294
  }[]
307
295
  > {
308
296
  // get uniq knex configs
309
- const configs = uniqBy(
297
+ const configs = _.uniqBy(
310
298
  targets
311
299
  .map((target) => ({
312
300
  connKey: target,
@@ -388,15 +376,15 @@ export class Migrator {
388
376
 
389
377
  const res = await Promise.all(
390
378
  delFiles.map((delFile) => {
391
- if (existsSync(delFile)) {
379
+ if (fs.existsSync(delFile)) {
392
380
  console.log(chalk.red(`DELETE: ${delFile}`));
393
- unlinkSync(delFile);
381
+ fs.unlinkSync(delFile);
394
382
  return delFiles.includes(".ts") ? 1 : 0;
395
383
  }
396
384
  return 0;
397
385
  })
398
386
  );
399
- return sum(res);
387
+ return _.sum(res);
400
388
  }
401
389
 
402
390
  async generatePreparedCodes(): Promise<number> {
@@ -415,7 +403,7 @@ export class Migrator {
415
403
  .plus({ seconds: index })
416
404
  .toFormat("yyyyMMddHHmmss");
417
405
  const filePath = `${migrationsDir}/${dateTag}_${pcode.title}.ts`;
418
- writeFileSync(filePath, pcode.formatted!);
406
+ fs.writeFileSync(filePath, pcode.formatted!);
419
407
  console.log(chalk.green(`MIGRTAION CREATED ${filePath}`));
420
408
  });
421
409
 
@@ -435,8 +423,8 @@ export class Migrator {
435
423
  return path.join(migrationsDir, df.file).replace(".js", ".ts");
436
424
  });
437
425
  for (let p of delList) {
438
- if (existsSync(p)) {
439
- unlinkSync(p);
426
+ if (fs.existsSync(p)) {
427
+ fs.unlinkSync(p);
440
428
  }
441
429
  }
442
430
  await this.cleanUpDist(true);
@@ -526,7 +514,7 @@ export class Migrator {
526
514
  .plus({ seconds: index })
527
515
  .toFormat("yyyyMMddHHmmss");
528
516
  const filePath = `${migrationsDir}/${dateTag}_${code.title}.ts`;
529
- writeFileSync(filePath, code.formatted!);
517
+ fs.writeFileSync(filePath, code.formatted!);
530
518
  console.log(chalk.green(`MIGRTAION CREATED ${filePath}`));
531
519
  });
532
520
  }
@@ -551,14 +539,14 @@ export class Migrator {
551
539
  which,
552
540
  "migrations"
553
541
  );
554
- if (existsSync(migrationPath) === false) {
555
- mkdirSync(migrationPath, {
542
+ if (fs.existsSync(migrationPath) === false) {
543
+ fs.mkdirSync(migrationPath, {
556
544
  recursive: true,
557
545
  });
558
546
  }
559
- const files = readdirSync(migrationPath).filter(
560
- (filename) => filename.startsWith(".") === false
561
- );
547
+ const files = fs
548
+ .readdirSync(migrationPath)
549
+ .filter((filename) => filename.startsWith(".") === false);
562
550
  r[which] = files;
563
551
  return r;
564
552
  },
@@ -568,7 +556,7 @@ export class Migrator {
568
556
  }
569
557
  );
570
558
 
571
- const diffOnSrc = differenceBy(
559
+ const diffOnSrc = _.differenceBy(
572
560
  files.src,
573
561
  files.dist,
574
562
  (filename) => filename.split(".")[0]
@@ -579,7 +567,7 @@ export class Migrator {
579
567
  );
580
568
  }
581
569
 
582
- const diffOnDist = differenceBy(
570
+ const diffOnDist = _.differenceBy(
583
571
  files.dist,
584
572
  files.src,
585
573
  (filename) => filename.split(".")[0]
@@ -604,7 +592,7 @@ export class Migrator {
604
592
  return path.join(Sonamu.apiRootPath, "dist", "migrations", filename);
605
593
  });
606
594
  filesToRm.map((filePath) => {
607
- unlinkSync(filePath);
595
+ fs.unlinkSync(filePath);
608
596
  });
609
597
  console.log(chalk.green(`${filesToRm.length}건 삭제되었습니다!`));
610
598
  }
@@ -728,7 +716,7 @@ export class Migrator {
728
716
  });
729
717
 
730
718
  // 조인테이블만 추출
731
- const joinTables = uniqBy(
719
+ const joinTables = _.uniqBy(
732
720
  entitySetsWithJoinTable.map((entitySet) => entitySet.joinTables).flat(),
733
721
  (joinTable) => {
734
722
  return joinTable.table;
@@ -786,11 +774,11 @@ export class Migrator {
786
774
  }
787
775
  return col;
788
776
  };
789
- const entityColumns = sortBy(
777
+ const entityColumns = _.sortBy(
790
778
  entitySet.columns,
791
779
  (a) => a.name
792
780
  ).map(replaceColumnDefaultTo);
793
- const dbColumns = sortBy(dbSet.columns, (a) => a.name).map(
781
+ const dbColumns = _.sortBy(dbSet.columns, (a) => a.name).map(
794
782
  replaceColumnDefaultTo
795
783
  );
796
784
 
@@ -804,13 +792,13 @@ export class Migrator {
804
792
  console.debug({ entityColumn, dbColumn });
805
793
  */
806
794
 
807
- const entityIndexes = sortBy(entitySet.indexes, (a) =>
795
+ const entityIndexes = _.sortBy(entitySet.indexes, (a) =>
808
796
  [
809
797
  a.type,
810
798
  ...a.columns.sort((c1, c2) => (c1 > c2 ? 1 : -1)),
811
799
  ].join("-")
812
800
  );
813
- const dbIndexes = sortBy(dbSet.indexes, (a) =>
801
+ const dbIndexes = _.sortBy(dbSet.indexes, (a) =>
814
802
  [
815
803
  a.type,
816
804
  ...a.columns.sort((c1, c2) => (c1 > c2 ? 1 : -1)),
@@ -845,10 +833,10 @@ export class Migrator {
845
833
  };
846
834
  };
847
835
 
848
- const entityForeigns = sortBy(entitySet.foreigns, (a) =>
836
+ const entityForeigns = _.sortBy(entitySet.foreigns, (a) =>
849
837
  [a.to, ...a.columns].join("-")
850
838
  ).map((f) => replaceNoActionOnMySQL(f));
851
- const dbForeigns = sortBy(dbSet.foreigns, (a) =>
839
+ const dbForeigns = _.sortBy(dbSet.foreigns, (a) =>
852
840
  [a.to, ...a.columns].join("-")
853
841
  ).map((f) => replaceNoActionOnMySQL(f));
854
842
 
@@ -929,7 +917,7 @@ export class Migrator {
929
917
  };
930
918
  });
931
919
 
932
- const dbIndexesGroup = groupBy(
920
+ const dbIndexesGroup = _.groupBy(
933
921
  dbIndexes.filter(
934
922
  (dbIndex) =>
935
923
  dbIndex.Key_name !== "PRIMARY" &&
@@ -1180,8 +1168,8 @@ export class Migrator {
1180
1168
  const join = {
1181
1169
  from: `${entity.table}.id`,
1182
1170
  through: {
1183
- from: `${prop.joinTable}.${singularize(table1)}_id`,
1184
- to: `${prop.joinTable}.${singularize(table2)}_id`,
1171
+ from: `${prop.joinTable}.${inflection.singularize(table1)}_id`,
1172
+ to: `${prop.joinTable}.${inflection.singularize(table2)}_id`,
1185
1173
  onUpdate: prop.onUpdate,
1186
1174
  onDelete: prop.onDelete,
1187
1175
  },
@@ -1255,7 +1243,7 @@ export class Migrator {
1255
1243
  });
1256
1244
  r.foreigns.push({
1257
1245
  columns: [idColumnName],
1258
- to: `${underscore(pluralize(prop.with)).toLowerCase()}.id`,
1246
+ to: `${inflection.underscore(inflection.pluralize(prop.with)).toLowerCase()}.id`,
1259
1247
  onUpdate: prop.onUpdate,
1260
1248
  onDelete: prop.onDelete,
1261
1249
  });
@@ -1349,7 +1337,7 @@ export class Migrator {
1349
1337
  if (indexes.length === 0) {
1350
1338
  return [];
1351
1339
  }
1352
- const lines = uniq(
1340
+ const lines = _.uniq(
1353
1341
  indexes.reduce((r, index) => {
1354
1342
  r.push(
1355
1343
  `table.${index.type}([${index.columns
@@ -1490,7 +1478,7 @@ export class Migrator {
1490
1478
  console.table(
1491
1479
  columns.map((column) => {
1492
1480
  return {
1493
- ...pick(column, [
1481
+ ..._.pick(column, [
1494
1482
  "name",
1495
1483
  "type",
1496
1484
  "nullable",
@@ -1523,7 +1511,7 @@ export class Migrator {
1523
1511
  console.table(
1524
1512
  indexes.map((index) => {
1525
1513
  return {
1526
- ...pick(index, ["type", "columns", "name"]),
1514
+ ..._.pick(index, ["type", "columns", "name"]),
1527
1515
  };
1528
1516
  })
1529
1517
  );
@@ -1538,7 +1526,7 @@ export class Migrator {
1538
1526
  console.table(
1539
1527
  foreigns.map((foreign) => {
1540
1528
  return {
1541
- ...pick(foreign, ["columns", "to", "onUpdate", "onDelete"]),
1529
+ ..._.pick(foreign, ["columns", "to", "onUpdate", "onDelete"]),
1542
1530
  };
1543
1531
  })
1544
1532
  );
@@ -1650,8 +1638,8 @@ export class Migrator {
1650
1638
 
1651
1639
  // 컬럼명 기준 비교
1652
1640
  const extraColumns = {
1653
- db: differenceBy(dbColumns, entityColumns, (col) => col.name),
1654
- entity: differenceBy(entityColumns, dbColumns, (col) => col.name),
1641
+ db: _.differenceBy(dbColumns, entityColumns, (col) => col.name),
1642
+ entity: _.differenceBy(entityColumns, dbColumns, (col) => col.name),
1655
1643
  };
1656
1644
  if (extraColumns.entity.length > 0) {
1657
1645
  columnsTo.add = columnsTo.add.concat(extraColumns.entity);
@@ -1661,17 +1649,17 @@ export class Migrator {
1661
1649
  }
1662
1650
 
1663
1651
  // 동일 컬럼명의 세부 필드 비교
1664
- const sameDbColumns = intersectionBy(
1652
+ const sameDbColumns = _.intersectionBy(
1665
1653
  dbColumns,
1666
1654
  entityColumns,
1667
1655
  (col) => col.name
1668
1656
  );
1669
- const sameMdColumns = intersectionBy(
1657
+ const sameMdColumns = _.intersectionBy(
1670
1658
  entityColumns,
1671
1659
  dbColumns,
1672
1660
  (col) => col.name
1673
1661
  );
1674
- columnsTo.alter = differenceWith(sameDbColumns, sameMdColumns, (a, b) =>
1662
+ columnsTo.alter = _.differenceWith(sameDbColumns, sameMdColumns, (a, b) =>
1675
1663
  equal(a, b)
1676
1664
  );
1677
1665
 
@@ -1728,11 +1716,11 @@ export class Migrator {
1728
1716
  }
1729
1717
 
1730
1718
  // 컬럼 변경사항
1731
- const columnDiffUp = difference(
1719
+ const columnDiffUp = _.difference(
1732
1720
  this.genColumnDefinitions([entityColumn]),
1733
1721
  this.genColumnDefinitions([dbColumn])
1734
1722
  );
1735
- const columnDiffDown = difference(
1723
+ const columnDiffDown = _.difference(
1736
1724
  this.genColumnDefinitions([dbColumn]),
1737
1725
  this.genColumnDefinitions([entityColumn])
1738
1726
  );
@@ -1770,10 +1758,10 @@ export class Migrator {
1770
1758
  drop: [] as MigrationIndex[],
1771
1759
  };
1772
1760
  const extraIndexes = {
1773
- db: differenceBy(dbIndexes, entityIndexes, (col) =>
1761
+ db: _.differenceBy(dbIndexes, entityIndexes, (col) =>
1774
1762
  [col.type, col.columns.join("-")].join("//")
1775
1763
  ),
1776
- entity: differenceBy(entityIndexes, dbIndexes, (col) =>
1764
+ entity: _.differenceBy(entityIndexes, dbIndexes, (col) =>
1777
1765
  [col.type, col.columns.join("-")].join("//")
1778
1766
  ),
1779
1767
  };
@@ -1816,7 +1804,7 @@ export class Migrator {
1816
1804
  )
1817
1805
  .map(
1818
1806
  (index) =>
1819
- `table.drop${capitalize(index.type)}([${index.columns
1807
+ `table.drop${inflection.capitalize(index.type)}([${index.columns
1820
1808
  .map((columnName) => `'${columnName}'`)
1821
1809
  .join(",")}])`
1822
1810
  ),
@@ -1834,7 +1822,7 @@ export class Migrator {
1834
1822
  )
1835
1823
  .map(
1836
1824
  (index) =>
1837
- `table.drop${capitalize(index.type)}([${index.columns
1825
+ `table.drop${inflection.capitalize(index.type)}([${index.columns
1838
1826
  .map((columnName) => `'${columnName}'`)
1839
1827
  .join(",")}])`
1840
1828
  ),
@@ -1,6 +1,6 @@
1
1
  import chalk from "chalk";
2
- import { glob } from "glob";
3
- import { dasherize, underscore, pluralize, camelize } from "inflection";
2
+ import glob from "glob";
3
+ import inflection from "inflection";
4
4
  import _ from "lodash";
5
5
  import path from "path";
6
6
  import { SMD } from "./smd";
@@ -30,7 +30,7 @@ class SMDManagerClass {
30
30
  !doSilent && console.log(chalk.yellow(`autoload ${pathPattern}`));
31
31
 
32
32
  return new Promise((resolve) => {
33
- glob(path.resolve(pathPattern!), (_err, files) => {
33
+ glob.glob(path.resolve(pathPattern!), (_err, files) => {
34
34
  const importPaths = files.map((filePath) =>
35
35
  path.relative(__dirname, filePath)
36
36
  );
@@ -117,17 +117,21 @@ class SMDManagerClass {
117
117
  getNamesFromId(smdId: string): EntityNamesRecord {
118
118
  // entityId가 단복수 동형 단어인 경우 List 붙여서 생성
119
119
  const pluralized =
120
- pluralize(smdId) === smdId ? `${smdId}List` : pluralize(smdId);
120
+ inflection.pluralize(smdId) === smdId
121
+ ? `${smdId}List`
122
+ : inflection.pluralize(smdId);
121
123
 
122
124
  return {
123
- fs: dasherize(underscore(smdId)).toLowerCase(),
124
- fsPlural: dasherize(underscore(pluralized)).toLowerCase(),
125
- camel: camelize(smdId, true),
126
- camelPlural: camelize(pluralized, true),
125
+ fs: inflection.dasherize(inflection.underscore(smdId)).toLowerCase(),
126
+ fsPlural: inflection
127
+ .dasherize(inflection.underscore(pluralized))
128
+ .toLowerCase(),
129
+ camel: inflection.camelize(smdId, true),
130
+ camelPlural: inflection.camelize(pluralized, true),
127
131
  capital: smdId,
128
132
  capitalPlural: pluralized,
129
133
  upper: smdId.toUpperCase(),
130
- constant: underscore(smdId).toUpperCase(),
134
+ constant: inflection.underscore(smdId).toUpperCase(),
131
135
  };
132
136
  }
133
137
  }
package/src/smd/smd.ts CHANGED
@@ -1,5 +1,4 @@
1
- import _, { uniq } from "lodash";
2
- import { dasherize, pluralize, underscore } from "inflection";
1
+ import _ from "lodash";
3
2
  import {
4
3
  EntityProp,
5
4
  RelationProp,
@@ -19,7 +18,7 @@ import {
19
18
  } from "../types/types";
20
19
  import inflection from "inflection";
21
20
  import path from "path";
22
- import { existsSync } from "fs";
21
+ import fs from "fs-extra";
23
22
  import { z } from "zod";
24
23
  import { Sonamu } from "../api/sonamu";
25
24
  import { SMDManager } from "./smd-manager";
@@ -67,7 +66,7 @@ export class SMD {
67
66
  this.id = id;
68
67
  this.parentId = parentId;
69
68
  this.title = title ?? this.id;
70
- this.table = table ?? underscore(pluralize(id));
69
+ this.table = table ?? inflection.underscore(inflection.pluralize(id));
71
70
 
72
71
  // props
73
72
  if (props) {
@@ -111,8 +110,8 @@ export class SMD {
111
110
  this.names = {
112
111
  fs:
113
112
  parentId === undefined
114
- ? dasherize(underscore(id)).toLowerCase()
115
- : dasherize(parentId).toLowerCase(),
113
+ ? inflection.dasherize(inflection.underscore(id)).toLowerCase()
114
+ : inflection.dasherize(parentId).toLowerCase(),
116
115
  module: id,
117
116
  };
118
117
 
@@ -254,7 +253,7 @@ export class SMD {
254
253
  to = `${joinAs}.id`;
255
254
  } else {
256
255
  from = `${fromTable}.id`;
257
- to = `${joinAs}.${underscore(
256
+ to = `${joinAs}.${inflection.underscore(
258
257
  this.names.fs.replace(/\-/g, "_")
259
258
  )}_id`;
260
259
  }
@@ -518,7 +517,7 @@ export class SMD {
518
517
  `dist/application/${typesModulePath}.js`
519
518
  );
520
519
 
521
- if (existsSync(typesFileDistPath)) {
520
+ if (fs.existsSync(typesFileDistPath)) {
522
521
  const importPath = path.relative(__dirname, typesFileDistPath);
523
522
  import(importPath).then((t) => {
524
523
  this.types = Object.keys(t).reduce((result, key) => {
@@ -537,14 +536,14 @@ export class SMD {
537
536
  Sonamu.apiRootPath,
538
537
  `/dist/application/${enumsModulePath}.js`
539
538
  );
540
- if (existsSync(enumsFileDistPath)) {
539
+ if (fs.existsSync(enumsFileDistPath)) {
541
540
  const importPath = path.relative(__dirname, enumsFileDistPath);
542
541
  import(importPath).then((t) => {
543
542
  this.enums = Object.keys(t).reduce((result, key) => {
544
543
  SMDManager.setModulePath(key, enumsModulePath);
545
544
 
546
545
  // Enum Labels 별도 처리
547
- if (key === underscore(this.id).toUpperCase()) {
546
+ if (key === inflection.underscore(this.id).toUpperCase()) {
548
547
  this.enumLabels = t[key];
549
548
  }
550
549
  return {
@@ -557,7 +556,7 @@ export class SMD {
557
556
  }
558
557
 
559
558
  registerTableSpecs(): void {
560
- const uniqueColumns = uniq(
559
+ const uniqueColumns = _.uniq(
561
560
  this.indexes
562
561
  .filter((idx) => idx.type === "unique")
563
562
  .map((idx) => idx.columns)