sonamu 0.2.54 → 0.2.55

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 (48) hide show
  1. package/dist/base-model-BzMJ2E_I.d.mts +43 -0
  2. package/dist/base-model-CWRKUX49.d.ts +43 -0
  3. package/dist/bin/cli.js +118 -89
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/bin/cli.mjs +74 -45
  6. package/dist/bin/cli.mjs.map +1 -1
  7. package/dist/chunk-4K2F3SOM.mjs +231 -0
  8. package/dist/chunk-4K2F3SOM.mjs.map +1 -0
  9. package/dist/chunk-6SP5N5ND.mjs +1579 -0
  10. package/dist/chunk-6SP5N5ND.mjs.map +1 -0
  11. package/dist/chunk-EUP6N7EK.js +1579 -0
  12. package/dist/chunk-EUP6N7EK.js.map +1 -0
  13. package/dist/chunk-HVVCQLAU.mjs +280 -0
  14. package/dist/chunk-HVVCQLAU.mjs.map +1 -0
  15. package/dist/chunk-N6N3LENC.js +231 -0
  16. package/dist/chunk-N6N3LENC.js.map +1 -0
  17. package/dist/chunk-UAG3SKFM.js +280 -0
  18. package/dist/chunk-UAG3SKFM.js.map +1 -0
  19. package/dist/{chunk-JOHF7PK4.js → chunk-WJGRXAXE.js} +5301 -5623
  20. package/dist/chunk-WJGRXAXE.js.map +1 -0
  21. package/dist/{chunk-L4KELCY7.mjs → chunk-ZFLQLW37.mjs} +5252 -5574
  22. package/dist/chunk-ZFLQLW37.mjs.map +1 -0
  23. package/dist/database/drivers/knex/base-model.d.mts +16 -0
  24. package/dist/database/drivers/knex/base-model.d.ts +16 -0
  25. package/dist/database/drivers/knex/base-model.js +55 -0
  26. package/dist/database/drivers/knex/base-model.js.map +1 -0
  27. package/dist/database/drivers/knex/base-model.mjs +56 -0
  28. package/dist/database/drivers/knex/base-model.mjs.map +1 -0
  29. package/dist/database/drivers/kysely/base-model.d.mts +22 -0
  30. package/dist/database/drivers/kysely/base-model.d.ts +22 -0
  31. package/dist/database/drivers/kysely/base-model.js +64 -0
  32. package/dist/database/drivers/kysely/base-model.js.map +1 -0
  33. package/dist/database/drivers/kysely/base-model.mjs +65 -0
  34. package/dist/database/drivers/kysely/base-model.mjs.map +1 -0
  35. package/dist/index.d.mts +226 -931
  36. package/dist/index.d.ts +226 -931
  37. package/dist/index.js +13 -26
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +18 -31
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/model-CAH_4oQh.d.mts +1042 -0
  42. package/dist/model-CAH_4oQh.d.ts +1042 -0
  43. package/package.json +1 -1
  44. package/src/api/code-converters.ts +1 -1
  45. package/src/entity/migrator.ts +3 -0
  46. package/src/types/types.ts +1 -0
  47. package/dist/chunk-JOHF7PK4.js.map +0 -1
  48. package/dist/chunk-L4KELCY7.mjs.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { c as DatabaseDriver, d as DriverSpec, S as SubsetQuery, D as DBPreset, B as BaseListParams, K as KnexClient, b as KyselyClient } from './model-CAH_4oQh.mjs';
2
+
3
+ declare abstract class BaseModelClassAbstract<D extends DatabaseDriver> {
4
+ modelName: string;
5
+ protected abstract applyJoins(qb: DriverSpec[D]["adapter"], joins: SubsetQuery["joins"]): DriverSpec[D]["adapter"];
6
+ protected abstract executeCountQuery(qb: DriverSpec[D]["queryBuilder"]): Promise<number>;
7
+ abstract getDB(which: DBPreset): DriverSpec[D]["core"];
8
+ abstract destroy(): Promise<void>;
9
+ runSubsetQuery<T extends BaseListParams, U extends string>({ params, baseTable, subset, subsetQuery, build, debug, db: _db, optimizeCountQuery, }: {
10
+ subset: U;
11
+ params: T;
12
+ subsetQuery: SubsetQuery;
13
+ build: (buildParams: {
14
+ qb: DriverSpec[D]["queryBuilder"];
15
+ db: DriverSpec[D]["core"];
16
+ select: SubsetQuery["select"];
17
+ joins: SubsetQuery["joins"];
18
+ virtual: string[];
19
+ }) => DriverSpec[D]["queryBuilder"];
20
+ baseTable?: DriverSpec[D]["table"];
21
+ debug?: boolean | "list" | "count";
22
+ db?: DriverSpec[D]["core"];
23
+ optimizeCountQuery?: boolean;
24
+ }): Promise<{
25
+ rows: any[];
26
+ total?: number;
27
+ subsetQuery: SubsetQuery;
28
+ qb: DriverSpec[D]["queryBuilder"];
29
+ }>;
30
+ useLoaders(db: DriverSpec[D]["adapter"], rows: any[], loaders: SubsetQuery["loaders"]): Promise<any[]>;
31
+ protected buildHasManyQuery(db: DriverSpec[D]["adapter"], loader: SubsetQuery["loaders"][number], fromIds: any[]): Promise<{
32
+ subQ: KnexClient | KyselyClient;
33
+ col: string;
34
+ }>;
35
+ protected buildManyToManyQuery(db: DriverSpec[D]["adapter"], loader: SubsetQuery["loaders"][number], fromIds: any[]): Promise<{
36
+ subQ: KnexClient | KyselyClient;
37
+ col: string;
38
+ }>;
39
+ myNow(timestamp?: number): string;
40
+ hydrate<T>(rows: T[]): T[];
41
+ }
42
+
43
+ export { BaseModelClassAbstract as B };
@@ -0,0 +1,43 @@
1
+ import { c as DatabaseDriver, d as DriverSpec, S as SubsetQuery, D as DBPreset, B as BaseListParams, K as KnexClient, b as KyselyClient } from './model-CAH_4oQh.js';
2
+
3
+ declare abstract class BaseModelClassAbstract<D extends DatabaseDriver> {
4
+ modelName: string;
5
+ protected abstract applyJoins(qb: DriverSpec[D]["adapter"], joins: SubsetQuery["joins"]): DriverSpec[D]["adapter"];
6
+ protected abstract executeCountQuery(qb: DriverSpec[D]["queryBuilder"]): Promise<number>;
7
+ abstract getDB(which: DBPreset): DriverSpec[D]["core"];
8
+ abstract destroy(): Promise<void>;
9
+ runSubsetQuery<T extends BaseListParams, U extends string>({ params, baseTable, subset, subsetQuery, build, debug, db: _db, optimizeCountQuery, }: {
10
+ subset: U;
11
+ params: T;
12
+ subsetQuery: SubsetQuery;
13
+ build: (buildParams: {
14
+ qb: DriverSpec[D]["queryBuilder"];
15
+ db: DriverSpec[D]["core"];
16
+ select: SubsetQuery["select"];
17
+ joins: SubsetQuery["joins"];
18
+ virtual: string[];
19
+ }) => DriverSpec[D]["queryBuilder"];
20
+ baseTable?: DriverSpec[D]["table"];
21
+ debug?: boolean | "list" | "count";
22
+ db?: DriverSpec[D]["core"];
23
+ optimizeCountQuery?: boolean;
24
+ }): Promise<{
25
+ rows: any[];
26
+ total?: number;
27
+ subsetQuery: SubsetQuery;
28
+ qb: DriverSpec[D]["queryBuilder"];
29
+ }>;
30
+ useLoaders(db: DriverSpec[D]["adapter"], rows: any[], loaders: SubsetQuery["loaders"]): Promise<any[]>;
31
+ protected buildHasManyQuery(db: DriverSpec[D]["adapter"], loader: SubsetQuery["loaders"][number], fromIds: any[]): Promise<{
32
+ subQ: KnexClient | KyselyClient;
33
+ col: string;
34
+ }>;
35
+ protected buildManyToManyQuery(db: DriverSpec[D]["adapter"], loader: SubsetQuery["loaders"][number], fromIds: any[]): Promise<{
36
+ subQ: KnexClient | KyselyClient;
37
+ col: string;
38
+ }>;
39
+ myNow(timestamp?: number): string;
40
+ hydrate<T>(rows: T[]): T[];
41
+ }
42
+
43
+ export { BaseModelClassAbstract as B };
package/dist/bin/cli.js CHANGED
@@ -1,6 +1,7 @@
1
- "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
1
+ "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2;
2
2
 
3
3
 
4
+ var _chunkEUP6N7EKjs = require('../chunk-EUP6N7EK.js');
4
5
 
5
6
 
6
7
 
@@ -11,7 +12,10 @@
11
12
 
12
13
 
13
14
 
14
- var _chunkJOHF7PK4js = require('../chunk-JOHF7PK4.js');
15
+
16
+
17
+
18
+ var _chunkWJGRXAXEjs = require('../chunk-WJGRXAXE.js');
15
19
 
16
20
  // src/bin/cli.ts
17
21
  var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
@@ -20,9 +24,10 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
20
24
  var _tsicli = require('tsicli');
21
25
  var _child_process = require('child_process');
22
26
  var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
23
- var _knex = require('knex'); var _knex2 = _interopRequireDefault(_knex);
24
27
  var _inflection = require('inflection'); var _inflection2 = _interopRequireDefault(_inflection);
25
28
  var _prettier = require('prettier'); var _prettier2 = _interopRequireDefault(_prettier);
29
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
30
+ var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
26
31
 
27
32
  // src/smd/smd-manager.ts
28
33
 
@@ -31,11 +36,24 @@ var _glob = require('glob'); var _glob2 = _interopRequireDefault(_glob);
31
36
 
32
37
 
33
38
  // src/smd/smd.ts
34
- var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
35
39
 
36
40
 
37
41
 
38
- var SMD = class {
42
+
43
+ var SMD = (_class = class {
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ __init() {this.types = {}}
55
+ __init2() {this.enums = {}}
56
+ __init3() {this.enumLabels = {}}
39
57
  constructor({
40
58
  id,
41
59
  parentId,
@@ -44,17 +62,14 @@ var SMD = class {
44
62
  props,
45
63
  indexes,
46
64
  subsets
47
- }) {
48
- this.types = {};
49
- this.enums = {};
50
- this.enumLabels = {};
65
+ }) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
51
66
  this.id = id;
52
67
  this.parentId = parentId;
53
68
  this.title = _nullishCoalesce(title, () => ( this.id));
54
69
  this.table = _nullishCoalesce(table, () => ( _inflection2.default.underscore(_inflection2.default.pluralize(id))));
55
70
  if (props) {
56
71
  this.props = props.map((prop) => {
57
- if (_chunkJOHF7PK4js.isEnumProp.call(void 0, prop)) {
72
+ if (_chunkWJGRXAXEjs.isEnumProp.call(void 0, prop)) {
58
73
  if (prop.id.includes("$Model")) {
59
74
  prop.id = prop.id.replace("$Model", id);
60
75
  }
@@ -67,7 +82,7 @@ var SMD = class {
67
82
  [prop.name]: prop
68
83
  };
69
84
  }, {});
70
- this.relations = props.filter((prop) => _chunkJOHF7PK4js.isRelationProp.call(void 0, prop)).reduce((result, prop) => {
85
+ this.relations = props.filter((prop) => _chunkWJGRXAXEjs.isRelationProp.call(void 0, prop)).reduce((result, prop) => {
71
86
  return {
72
87
  ...result,
73
88
  [prop.name]: prop
@@ -112,10 +127,10 @@ var SMD = class {
112
127
  const fields2 = subsetGroup[groupKey];
113
128
  if (groupKey === "") {
114
129
  const realFields = fields2.filter(
115
- (field) => !_chunkJOHF7PK4js.isVirtualProp.call(void 0, this.propsDict[field])
130
+ (field) => !_chunkWJGRXAXEjs.isVirtualProp.call(void 0, this.propsDict[field])
116
131
  );
117
132
  const virtualFields = fields2.filter(
118
- (field) => _chunkJOHF7PK4js.isVirtualProp.call(void 0, this.propsDict[field])
133
+ (field) => _chunkWJGRXAXEjs.isVirtualProp.call(void 0, this.propsDict[field])
119
134
  );
120
135
  if (prefix === "") {
121
136
  r.select = r.select.concat(
@@ -136,7 +151,7 @@ var SMD = class {
136
151
  throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 relation \uCC38\uC870 ${groupKey}`);
137
152
  }
138
153
  const relSMD = SMDManager.get(relation.with);
139
- if (_chunkJOHF7PK4js.isOneToOneRelationProp.call(void 0, relation) || _chunkJOHF7PK4js.isBelongsToOneRelationProp.call(void 0, relation)) {
154
+ if (_chunkWJGRXAXEjs.isOneToOneRelationProp.call(void 0, relation) || _chunkWJGRXAXEjs.isBelongsToOneRelationProp.call(void 0, relation)) {
140
155
  const relFields = fields2.map(
141
156
  (field) => field.split(".").slice(1).join(".")
142
157
  );
@@ -154,7 +169,7 @@ var SMD = class {
154
169
  if (isAlreadyOuterJoined) {
155
170
  return "outer";
156
171
  }
157
- if (_chunkJOHF7PK4js.isOneToOneRelationProp.call(void 0, relation)) {
172
+ if (_chunkWJGRXAXEjs.isOneToOneRelationProp.call(void 0, relation)) {
158
173
  if (relation.hasJoinColumn === true && (_nullishCoalesce(relation.nullable, () => ( false))) === false) {
159
174
  return "inner";
160
175
  } else {
@@ -184,7 +199,7 @@ var SMD = class {
184
199
  };
185
200
  } else {
186
201
  let from, to;
187
- if (_chunkJOHF7PK4js.isOneToOneRelationProp.call(void 0, relation)) {
202
+ if (_chunkWJGRXAXEjs.isOneToOneRelationProp.call(void 0, relation)) {
188
203
  if (relation.hasJoinColumn) {
189
204
  from = `${fromTable}.${relation.name}_id`;
190
205
  to = `${joinAs}.id`;
@@ -223,13 +238,13 @@ var SMD = class {
223
238
  r.loaders = [...r.loaders, ...convertedLoaders];
224
239
  }
225
240
  r.joins = r.joins.concat(relSubsetQuery.joins);
226
- } else if (_chunkJOHF7PK4js.isHasManyRelationProp.call(void 0, relation) || _chunkJOHF7PK4js.isManyToManyRelationProp.call(void 0, relation)) {
241
+ } else if (_chunkWJGRXAXEjs.isHasManyRelationProp.call(void 0, relation) || _chunkWJGRXAXEjs.isManyToManyRelationProp.call(void 0, relation)) {
227
242
  const relFields = fields2.map(
228
243
  (field) => field.split(".").slice(1).join(".")
229
244
  );
230
245
  const relSubsetQuery = relSMD.resolveSubsetQuery("", relFields);
231
246
  let manyJoin;
232
- if (_chunkJOHF7PK4js.isHasManyRelationProp.call(void 0, relation)) {
247
+ if (_chunkWJGRXAXEjs.isHasManyRelationProp.call(void 0, relation)) {
233
248
  manyJoin = {
234
249
  fromTable: this.table,
235
250
  fromCol: "id",
@@ -237,7 +252,7 @@ var SMD = class {
237
252
  toTable: relSMD.table,
238
253
  toCol: relation.joinColumn
239
254
  };
240
- } else if (_chunkJOHF7PK4js.isManyToManyRelationProp.call(void 0, relation)) {
255
+ } else if (_chunkWJGRXAXEjs.isManyToManyRelationProp.call(void 0, relation)) {
241
256
  const [table1, table2] = relation.joinTable.split("__");
242
257
  manyJoin = {
243
258
  fromTable: this.table,
@@ -320,11 +335,11 @@ var SMD = class {
320
335
  });
321
336
  }
322
337
  const prop = smd.propsDict[key];
323
- if (!_chunkJOHF7PK4js.isRelationProp.call(void 0, prop)) {
338
+ if (!_chunkWJGRXAXEjs.isRelationProp.call(void 0, prop)) {
324
339
  throw new Error(`\uC798\uBABB\uB41C FieldExpr ${key}.${group[0]}`);
325
340
  }
326
341
  const relSMD = SMDManager.get(prop.with);
327
- if (_chunkJOHF7PK4js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkJOHF7PK4js.isOneToOneRelationProp.call(void 0, prop)) {
342
+ if (_chunkWJGRXAXEjs.isBelongsToOneRelationProp.call(void 0, prop) || _chunkWJGRXAXEjs.isOneToOneRelationProp.call(void 0, prop)) {
328
343
  if (group.length == 1 && (group[0] === "id" || group[0] == "id?")) {
329
344
  const idProp = relSMD.propsDict.id;
330
345
  return {
@@ -339,7 +354,7 @@ var SMD = class {
339
354
  }
340
355
  }
341
356
  const children = this.fieldExprsToPropNodes(group, relSMD);
342
- const nodeType = _chunkJOHF7PK4js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkJOHF7PK4js.isOneToOneRelationProp.call(void 0, prop) ? "object" : "array";
357
+ const nodeType = _chunkWJGRXAXEjs.isBelongsToOneRelationProp.call(void 0, prop) || _chunkWJGRXAXEjs.isOneToOneRelationProp.call(void 0, prop) ? "object" : "array";
343
358
  return {
344
359
  prop,
345
360
  children,
@@ -353,7 +368,7 @@ var SMD = class {
353
368
  if (propName === prefix) {
354
369
  return null;
355
370
  }
356
- if (_chunkJOHF7PK4js.isRelationProp.call(void 0, prop)) {
371
+ if (_chunkWJGRXAXEjs.isRelationProp.call(void 0, prop)) {
357
372
  if (maxDepth < 0) {
358
373
  return null;
359
374
  }
@@ -393,7 +408,7 @@ var SMD = class {
393
408
  }
394
409
  const typesModulePath = `${basePath}/${this.names.fs}.types`;
395
410
  const typesFileDistPath = _path2.default.join(
396
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
411
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
397
412
  `dist/application/${typesModulePath}.js`
398
413
  );
399
414
  if (_fsextra2.default.existsSync(typesFileDistPath)) {
@@ -410,7 +425,7 @@ var SMD = class {
410
425
  }
411
426
  const enumsModulePath = `${basePath}/${this.names.fs}.enums`;
412
427
  const enumsFileDistPath = _path2.default.join(
413
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
428
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
414
429
  `/dist/application/${enumsModulePath}.js`
415
430
  );
416
431
  if (_fsextra2.default.existsSync(enumsFileDistPath)) {
@@ -438,23 +453,21 @@ var SMD = class {
438
453
  uniqueColumns
439
454
  });
440
455
  }
441
- };
456
+ }, _class);
442
457
 
443
458
  // src/smd/smd-manager.ts
444
- var SMDManagerClass = class {
445
- constructor() {
446
- this.SMDs = /* @__PURE__ */ new Map();
447
- this.modulePaths = /* @__PURE__ */ new Map();
448
- this.tableSpecs = /* @__PURE__ */ new Map();
449
- this.isAutoloaded = false;
450
- }
459
+ var SMDManagerClass = (_class2 = class {constructor() { _class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this); }
460
+ __init4() {this.SMDs = /* @__PURE__ */ new Map()}
461
+ __init5() {this.modulePaths = /* @__PURE__ */ new Map()}
462
+ __init6() {this.tableSpecs = /* @__PURE__ */ new Map()}
463
+ __init7() {this.isAutoloaded = false}
451
464
  // 경로 전달받아 모든 SMD 파일 로드
452
465
  async autoload(doSilent = false) {
453
466
  if (this.isAutoloaded) {
454
467
  return;
455
468
  }
456
469
  const pathPattern = _path2.default.join(
457
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
470
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
458
471
  "/dist/application/**/*.smd.js"
459
472
  );
460
473
  !doSilent && console.log(_chalk2.default.yellow(`autoload ${pathPattern}`));
@@ -541,23 +554,22 @@ var SMDManagerClass = class {
541
554
  constant: _inflection2.default.underscore(smdId).toUpperCase()
542
555
  };
543
556
  }
544
- };
557
+ }, _class2);
545
558
  var SMDManager = new SMDManagerClass();
546
559
 
547
560
  // src/bin/cli.ts
548
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
549
561
  console.log(_chalk2.default.bgBlue(`BEGIN ${/* @__PURE__ */ new Date()}`));
550
562
  _dotenv2.default.config();
551
563
  var migrator;
552
564
  async function bootstrap() {
553
- await _chunkJOHF7PK4js.Sonamu.init(false, false);
565
+ await _chunkWJGRXAXEjs.Sonamu.init(false, false);
554
566
  await _tsicli.tsicli.call(void 0, _process2.default.argv, {
555
567
  types: {
556
568
  "#entityId": {
557
569
  type: "autocomplete",
558
570
  name: "#entityId",
559
571
  message: "Please input #entityId",
560
- choices: _chunkJOHF7PK4js.EntityManager.getAllParentIds().map((entityId) => ({
572
+ choices: _chunkWJGRXAXEjs.EntityManager.getAllParentIds().map((entityId) => ({
561
573
  title: entityId,
562
574
  value: entityId
563
575
  }))
@@ -574,6 +586,7 @@ async function bootstrap() {
574
586
  ["migrate", "rollback"],
575
587
  ["migrate", "reset"],
576
588
  ["migrate", "clear"],
589
+ ["migrate", "status"],
577
590
  ["stub", "practice", "#name"],
578
591
  ["stub", "entity", "#name"],
579
592
  ["scaffold", "model", "#entityId"],
@@ -589,6 +602,7 @@ async function bootstrap() {
589
602
  migrate_rollback,
590
603
  migrate_clear,
591
604
  migrate_reset,
605
+ migrate_status,
592
606
  fixture_init,
593
607
  fixture_import,
594
608
  fixture_sync,
@@ -607,18 +621,17 @@ bootstrap().finally(async () => {
607
621
  if (migrator) {
608
622
  await migrator.destroy();
609
623
  }
610
- await _chunkJOHF7PK4js.FixtureManager.destory();
611
- await _chunkJOHF7PK4js.BaseModel.destroy();
624
+ await _chunkEUP6N7EKjs.FixtureManager.destory();
612
625
  console.log(_chalk2.default.bgBlue(`END ${/* @__PURE__ */ new Date()}
613
626
  `));
614
627
  });
615
628
  async function setupMigrator() {
616
- migrator = new (0, _chunkJOHF7PK4js.Migrator)({
629
+ migrator = new (0, _chunkEUP6N7EKjs.Migrator)({
617
630
  mode: "dev"
618
631
  });
619
632
  }
620
633
  async function setupFixtureManager() {
621
- _chunkJOHF7PK4js.FixtureManager.init();
634
+ _chunkEUP6N7EKjs.FixtureManager.init();
622
635
  }
623
636
  async function migrate_run() {
624
637
  await setupMigrator();
@@ -630,6 +643,11 @@ async function migrate_check() {
630
643
  await migrator.cleanUpDist();
631
644
  await migrator.check();
632
645
  }
646
+ async function migrate_status() {
647
+ await setupMigrator();
648
+ const status = await migrator.getStatus();
649
+ console.log(status);
650
+ }
633
651
  async function migrate_rollback() {
634
652
  await setupMigrator();
635
653
  await migrator.rollback();
@@ -643,77 +661,88 @@ async function migrate_reset() {
643
661
  await migrator.resetAll();
644
662
  }
645
663
  async function fixture_init() {
646
- const srcConfig = _chunkJOHF7PK4js.Sonamu.dbConfig.development_master;
664
+ const _db = _chunkWJGRXAXEjs.DB.getClient("development_master");
665
+ const srcConn = _db.connectionInfo;
647
666
  const targets = [
648
667
  {
649
668
  label: "(REMOTE) Fixture DB",
650
- config: _chunkJOHF7PK4js.Sonamu.dbConfig.fixture_remote
669
+ connKey: "fixture_remote"
651
670
  },
652
671
  {
653
672
  label: "(LOCAL) Fixture DB",
654
- config: _chunkJOHF7PK4js.Sonamu.dbConfig.fixture_local,
655
- toSkip: (() => {
656
- const remoteConn = _chunkJOHF7PK4js.Sonamu.dbConfig.fixture_remote.connection;
657
- const localConn = _chunkJOHF7PK4js.Sonamu.dbConfig.fixture_local.connection;
658
- return remoteConn.host === localConn.host && remoteConn.database === localConn.database;
659
- })()
673
+ connKey: "fixture_local"
660
674
  },
661
675
  {
662
676
  label: "(LOCAL) Testing DB",
663
- config: _chunkJOHF7PK4js.Sonamu.dbConfig.test
677
+ connKey: "test"
664
678
  }
665
679
  ];
666
680
  console.log("DUMP...");
667
681
  const dumpFilename = `/tmp/sonamu-fixture-init-${Date.now()}.sql`;
668
- const srcConn = srcConfig.connection;
669
682
  const migrationsDump = `/tmp/sonamu-fixture-init-migrations-${Date.now()}.sql`;
670
683
  _child_process.execSync.call(void 0,
671
- `mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
684
+ `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
672
685
  );
673
- _child_process.execSync.call(void 0,
674
- `mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} knex_migrations knex_migrations_lock > ${migrationsDump}`
686
+ const dbClient = _chunkWJGRXAXEjs.DB.baseConfig.client;
687
+ const migrationTable = _chunkWJGRXAXEjs.DB.migrationTable;
688
+ const [migrations] = await _db.raw(
689
+ "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
690
+ [srcConn.database, migrationTable]
675
691
  );
676
- for await (const { label, config, toSkip } of targets) {
677
- const conn = config.connection;
678
- if (toSkip === true) {
692
+ if (migrations.count > 0) {
693
+ _child_process.execSync.call(void 0,
694
+ `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} ${migrationTable} ${migrationTable}_lock > ${migrationsDump}`
695
+ );
696
+ }
697
+ for await (const { label, connKey } of targets) {
698
+ const config = _chunkWJGRXAXEjs.DB.connectionInfo[connKey];
699
+ if (label === "(LOCAL) Fixture DB" && targets.find(
700
+ (t) => t.label === "(REMOTE) Fixture DB" && _chunkWJGRXAXEjs.DB.connectionInfo[t.connKey].host === config.host && _chunkWJGRXAXEjs.DB.connectionInfo[t.connKey].database === config.database
701
+ )) {
679
702
  console.log(_chalk2.default.red(`${label}: Skipped!`));
680
703
  continue;
681
704
  }
682
- const db = _knex2.default.call(void 0, {
683
- ...config,
684
- connection: {
685
- ..._nullishCoalesce(config.connection, () => ( {})),
686
- database: void 0
705
+ const db = (() => {
706
+ if (dbClient === "knex") {
707
+ const config2 = _lodash2.default.cloneDeep(_chunkWJGRXAXEjs.DB.fullConfig[connKey]);
708
+ config2.connection.database = void 0;
709
+ return new (0, _chunkWJGRXAXEjs.KnexClient)(config2);
710
+ } else {
711
+ const config2 = _lodash2.default.cloneDeep(_chunkWJGRXAXEjs.DB.fullConfig[connKey]);
712
+ config2.database = void 0;
713
+ return new (0, _chunkWJGRXAXEjs.KyselyClient)(config2);
687
714
  }
688
- });
689
- const [[row]] = await db.raw(`SHOW DATABASES LIKE "${conn.database}"`);
715
+ })();
716
+ const [row] = await db.raw(`SHOW DATABASES LIKE "${config.database}"`);
690
717
  if (row) {
691
718
  console.log(
692
- _chalk2.default.yellow(`${label}: Database "${conn.database}" Already exists`)
719
+ _chalk2.default.yellow(`${label}: Database "${config.database}" Already exists`)
693
720
  );
694
721
  await db.destroy();
695
722
  continue;
696
723
  }
697
724
  console.log(`SYNC to ${label}...`);
698
- const mysqlCmd = `mysql -h${conn.host} -u${conn.user} -p${conn.password}`;
699
- _child_process.execSync.call(void 0, `${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${conn.database}\`'`);
700
- _child_process.execSync.call(void 0, `${mysqlCmd} -e 'CREATE DATABASE \`${conn.database}\`'`);
701
- _child_process.execSync.call(void 0, `${mysqlCmd} ${conn.database} < ${dumpFilename}`);
702
- _child_process.execSync.call(void 0, `${mysqlCmd} ${conn.database} < ${migrationsDump}`);
725
+ const mysqlCmd = `mysql -h${config.host} -P${srcConn.port} -u${config.user} -p${config.password}`;
726
+ _child_process.execSync.call(void 0, `${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${config.database}\`'`);
727
+ _child_process.execSync.call(void 0, `${mysqlCmd} -e 'CREATE DATABASE \`${config.database}\`'`);
728
+ _child_process.execSync.call(void 0, `${mysqlCmd} ${config.database} < ${dumpFilename}`);
729
+ if (_fsextra2.default.existsSync(migrationsDump)) {
730
+ _child_process.execSync.call(void 0, `${mysqlCmd} ${config.database} < ${migrationsDump}`);
731
+ }
703
732
  await db.destroy();
704
733
  }
705
734
  }
706
735
  async function fixture_import(entityId, recordIds) {
707
736
  await setupFixtureManager();
708
- await _chunkJOHF7PK4js.FixtureManager.importFixture(entityId, recordIds);
709
- await _chunkJOHF7PK4js.FixtureManager.sync();
737
+ await _chunkEUP6N7EKjs.FixtureManager.importFixture(entityId, recordIds);
738
+ await _chunkEUP6N7EKjs.FixtureManager.sync();
710
739
  }
711
740
  async function fixture_sync() {
712
741
  await setupFixtureManager();
713
- await _chunkJOHF7PK4js.FixtureManager.sync();
742
+ await _chunkEUP6N7EKjs.FixtureManager.sync();
714
743
  }
715
744
  async function stub_practice(name) {
716
- const practiceDir = _path2.default.join(_chunkJOHF7PK4js.Sonamu.apiRootPath, "src", "practices");
745
+ const practiceDir = _path2.default.join(_chunkWJGRXAXEjs.Sonamu.apiRootPath, "src", "practices");
717
746
  const fileNames = _fsextra2.default.readdirSync(practiceDir);
718
747
  const maxSeqNo = (() => {
719
748
  if (_fsextra2.default.existsSync(practiceDir) === false) {
@@ -756,22 +785,22 @@ async function stub_practice(name) {
756
785
  _child_process.execSync.call(void 0, `echo "${runCode}" | pbcopy`);
757
786
  }
758
787
  async function stub_entity(entityId) {
759
- await _chunkJOHF7PK4js.Sonamu.syncer.createEntity({ entityId });
788
+ await _chunkWJGRXAXEjs.Sonamu.syncer.createEntity({ entityId });
760
789
  }
761
790
  async function scaffold_model(entityId) {
762
- await _chunkJOHF7PK4js.Sonamu.syncer.generateTemplate("model", {
791
+ await _chunkWJGRXAXEjs.Sonamu.syncer.generateTemplate("model", {
763
792
  entityId
764
793
  });
765
794
  }
766
795
  async function scaffold_model_test(entityId) {
767
- await _chunkJOHF7PK4js.Sonamu.syncer.generateTemplate("model_test", {
796
+ await _chunkWJGRXAXEjs.Sonamu.syncer.generateTemplate("model_test", {
768
797
  entityId
769
798
  });
770
799
  }
771
800
  async function ui() {
772
801
  try {
773
802
  const sonamuUI = await Promise.resolve().then(() => _interopRequireWildcard(require("@sonamu-kit/ui")));
774
- sonamuUI.startServers(_chunkJOHF7PK4js.Sonamu.apiRootPath);
803
+ sonamuUI.startServers(_chunkWJGRXAXEjs.Sonamu.apiRootPath);
775
804
  } catch (e) {
776
805
  if (e instanceof Error && e.message.includes("isn't declared")) {
777
806
  console.log(`You need to install ${_chalk2.default.blue(`@sonamu-kit/ui`)} first.`);
@@ -810,7 +839,7 @@ async function smd_migration() {
810
839
  const parentNames = SMDManager.getNamesFromId(_nullishCoalesce(smd.parentId, () => ( smd.id)));
811
840
  const names = SMDManager.getNamesFromId(smd.id);
812
841
  const dstPath = _path2.default.join(
813
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
842
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
814
843
  "src",
815
844
  "application",
816
845
  parentNames.fs,
@@ -822,7 +851,7 @@ async function smd_migration() {
822
851
  _fsextra2.default.writeFileSync(dstPath, formatted);
823
852
  console.log(_chalk2.default.blue(`CREATED: ${dstPath}`));
824
853
  const srcSmdPath = _path2.default.join(
825
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
854
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
826
855
  "src",
827
856
  "application",
828
857
  parentNames.fs,
@@ -830,7 +859,7 @@ async function smd_migration() {
830
859
  );
831
860
  const dstSmdPath = srcSmdPath.replace("/src/", "/dist/").replace(/\.ts$/, ".js");
832
861
  const srcEnumsPath = _path2.default.join(
833
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
862
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
834
863
  "src",
835
864
  "application",
836
865
  parentNames.fs,
@@ -838,7 +867,7 @@ async function smd_migration() {
838
867
  );
839
868
  const dstEnumsPath = srcEnumsPath.replace("/src/", "/dist/").replace(/\.ts$/, ".js");
840
869
  const srcGeneratedPath = _path2.default.join(
841
- _chunkJOHF7PK4js.Sonamu.apiRootPath,
870
+ _chunkWJGRXAXEjs.Sonamu.apiRootPath,
842
871
  "src",
843
872
  "application",
844
873
  parentNames.fs,
@@ -850,8 +879,8 @@ async function smd_migration() {
850
879
  dstSmdPath,
851
880
  srcEnumsPath,
852
881
  dstEnumsPath,
853
- ..._chunkJOHF7PK4js.Sonamu.config.sync.targets.map(
854
- (target) => srcEnumsPath.replace(_chunkJOHF7PK4js.Sonamu.apiRootPath, _path2.default.join(_chunkJOHF7PK4js.Sonamu.appRootPath, target)).replace("/src/application/", "/src/services/")
882
+ ..._chunkWJGRXAXEjs.Sonamu.config.sync.targets.map(
883
+ (target) => srcEnumsPath.replace(_chunkWJGRXAXEjs.Sonamu.apiRootPath, _path2.default.join(_chunkWJGRXAXEjs.Sonamu.appRootPath, target)).replace("/src/application/", "/src/services/")
855
884
  ),
856
885
  srcGeneratedPath,
857
886
  dstGeneratedPath
@@ -865,11 +894,11 @@ async function smd_migration() {
865
894
  });
866
895
  }
867
896
  console.log("Entity\uB85C \uB2E4\uC2DC \uB85C\uB4DC\uD569\uB2C8\uB2E4.");
868
- _chunkJOHF7PK4js.EntityManager.isAutoloaded = false;
869
- await _chunkJOHF7PK4js.EntityManager.autoload();
870
- const entityIds = _chunkJOHF7PK4js.EntityManager.getAllParentIds();
897
+ _chunkWJGRXAXEjs.EntityManager.isAutoloaded = false;
898
+ await _chunkWJGRXAXEjs.EntityManager.autoload();
899
+ const entityIds = _chunkWJGRXAXEjs.EntityManager.getAllParentIds();
871
900
  for await (const entityId of entityIds) {
872
- await _chunkJOHF7PK4js.Sonamu.syncer.generateTemplate("generated", { entityId });
901
+ await _chunkWJGRXAXEjs.Sonamu.syncer.generateTemplate("generated", { entityId });
873
902
  }
874
903
  }
875
904
  //# sourceMappingURL=cli.js.map