sonamu 0.4.10 → 0.4.12

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 (45) hide show
  1. package/dist/{base-model-w9EuyYif.d.ts → base-model-Br6krkwK.d.ts} +1 -1
  2. package/dist/{base-model-ChAfKHR7.d.mts → base-model-BvVra-8f.d.mts} +1 -1
  3. package/dist/bin/cli.js +51 -51
  4. package/dist/bin/cli.mjs +2 -2
  5. package/dist/{chunk-C7NTXZWZ.mjs → chunk-FKZK27YL.mjs} +2 -2
  6. package/dist/{chunk-IPTFUZN2.js → chunk-FYLFH3Q6.js} +100 -100
  7. package/dist/{chunk-I7O4VXTH.js → chunk-IEMX4VPN.js} +4 -4
  8. package/dist/{chunk-QT3GBIMP.js → chunk-INTZUNZ6.js} +7 -7
  9. package/dist/{chunk-IPFCELQ3.mjs → chunk-JQJTQQ7D.mjs} +2 -2
  10. package/dist/{chunk-EEUCHV4P.mjs → chunk-LNZTU4JC.mjs} +70 -41
  11. package/dist/chunk-LNZTU4JC.mjs.map +1 -0
  12. package/dist/{chunk-M6MCZP64.mjs → chunk-NPLUHS5L.mjs} +2 -2
  13. package/dist/{chunk-E2I4OSFY.js → chunk-ZLFDB43J.js} +70 -41
  14. package/dist/chunk-ZLFDB43J.js.map +1 -0
  15. package/dist/database/drivers/knex/base-model.d.mts +2 -2
  16. package/dist/database/drivers/knex/base-model.d.ts +2 -2
  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.d.mts +2 -2
  20. package/dist/database/drivers/kysely/base-model.d.ts +2 -2
  21. package/dist/database/drivers/kysely/base-model.js +9 -9
  22. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  23. package/dist/index.d.mts +13 -5
  24. package/dist/index.d.ts +13 -5
  25. package/dist/index.js +18 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +14 -3
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/{model-BF9CDic2.d.ts → model-DWoinpJ7.d.mts} +73 -5
  30. package/dist/{model-BF9CDic2.d.mts → model-DWoinpJ7.d.ts} +73 -5
  31. package/package.json +1 -1
  32. package/src/api/base-frame.ts +14 -0
  33. package/src/api/decorators.ts +2 -1
  34. package/src/index.ts +1 -0
  35. package/src/syncer/syncer.ts +77 -40
  36. package/src/templates/service.template.ts +4 -6
  37. package/src/types/types.ts +11 -1
  38. package/dist/chunk-E2I4OSFY.js.map +0 -1
  39. package/dist/chunk-EEUCHV4P.mjs.map +0 -1
  40. /package/dist/{chunk-C7NTXZWZ.mjs.map → chunk-FKZK27YL.mjs.map} +0 -0
  41. /package/dist/{chunk-IPTFUZN2.js.map → chunk-FYLFH3Q6.js.map} +0 -0
  42. /package/dist/{chunk-I7O4VXTH.js.map → chunk-IEMX4VPN.js.map} +0 -0
  43. /package/dist/{chunk-QT3GBIMP.js.map → chunk-INTZUNZ6.js.map} +0 -0
  44. /package/dist/{chunk-IPFCELQ3.mjs.map → chunk-JQJTQQ7D.mjs.map} +0 -0
  45. /package/dist/{chunk-M6MCZP64.mjs.map → chunk-NPLUHS5L.mjs.map} +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkE2I4OSFYjs = require('./chunk-E2I4OSFY.js');
5
+ var _chunkZLFDB43Jjs = require('./chunk-ZLFDB43J.js');
6
6
 
7
7
  // src/database/upsert-builder.ts
8
8
  var _uuid = require('uuid');
@@ -20,7 +20,7 @@ async function batchUpdate(db, tableName, ids, rows, chunkSize = 50, trx = null)
20
20
  };
21
21
  if (trx) {
22
22
  for (const chunk of chunks) {
23
- await executeUpdate(chunk, _chunkE2I4OSFYjs.DB.toClient(trx));
23
+ await executeUpdate(chunk, _chunkZLFDB43Jjs.DB.toClient(trx));
24
24
  }
25
25
  } else {
26
26
  await db.trx(async (newTrx) => {
@@ -87,7 +87,7 @@ var UpsertBuilder = class {
87
87
  if (table === void 0) {
88
88
  const tableSpec = (() => {
89
89
  try {
90
- return _chunkE2I4OSFYjs.EntityManager.getTableSpec(tableName);
90
+ return _chunkZLFDB43Jjs.EntityManager.getTableSpec(tableName);
91
91
  } catch (e) {
92
92
  return null;
93
93
  }
@@ -119,7 +119,7 @@ var UpsertBuilder = class {
119
119
  return null;
120
120
  }
121
121
  return uniqueKeyArray.join("---delimiter--");
122
- }).filter(_chunkE2I4OSFYjs.nonNullable);
122
+ }).filter(_chunkZLFDB43Jjs.nonNullable);
123
123
  const uuid = (() => {
124
124
  if (uniqueKeys.length > 0) {
125
125
  for (const uniqueKey of uniqueKeys) {
@@ -180,7 +180,7 @@ var UpsertBuilder = class {
180
180
  )) {
181
181
  throw new Error(`${tableName} \uD574\uACB0\uB418\uC9C0 \uC54A\uC740 \uCC38\uC870\uAC00 \uC788\uC2B5\uB2C8\uB2E4.`);
182
182
  }
183
- const wdb = _chunkE2I4OSFYjs.DB.toClient(_wdb);
183
+ const wdb = _chunkZLFDB43Jjs.DB.toClient(_wdb);
184
184
  const { references, refTables } = Array.from(this.tables).reduce(
185
185
  (r, [, table2]) => {
186
186
  const reference = Array.from(table2.references.values()).find(
@@ -264,7 +264,7 @@ var UpsertBuilder = class {
264
264
  return row;
265
265
  });
266
266
  await batchUpdate(
267
- _chunkE2I4OSFYjs.DB.toClient(wdb),
267
+ _chunkZLFDB43Jjs.DB.toClient(wdb),
268
268
  tableName,
269
269
  whereColumns,
270
270
  rows,
@@ -277,4 +277,4 @@ var UpsertBuilder = class {
277
277
 
278
278
 
279
279
  exports.isRefField = isRefField; exports.UpsertBuilder = UpsertBuilder;
280
- //# sourceMappingURL=chunk-QT3GBIMP.js.map
280
+ //# sourceMappingURL=chunk-INTZUNZ6.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DB
3
- } from "./chunk-EEUCHV4P.mjs";
3
+ } from "./chunk-LNZTU4JC.mjs";
4
4
 
5
5
  // src/database/base-model.ts
6
6
  import { DateTime } from "luxon";
@@ -228,4 +228,4 @@ var BaseModelClassAbstract = class {
228
228
  export {
229
229
  BaseModelClassAbstract
230
230
  };
231
- //# sourceMappingURL=chunk-IPFCELQ3.mjs.map
231
+ //# sourceMappingURL=chunk-JQJTQQ7D.mjs.map
@@ -187,7 +187,17 @@ var TemplateOptions = z.object({
187
187
  entityId: z.string()
188
188
  }),
189
189
  service: z.object({
190
- entityId: z.string()
190
+ namesRecord: z.object({
191
+ fs: z.string(),
192
+ fsPlural: z.string(),
193
+ camel: z.string(),
194
+ camelPlural: z.string(),
195
+ capital: z.string(),
196
+ capitalPlural: z.string(),
197
+ upper: z.string(),
198
+ constant: z.string()
199
+ }),
200
+ modelTsPath: z.string()
191
201
  }),
192
202
  view_list: z.object({
193
203
  entityId: z.string(),
@@ -765,7 +775,7 @@ function api(options = {}) {
765
775
  const modelName = target.constructor.name.match(/(.+)Class$/)[1];
766
776
  const methodName = propertyKey;
767
777
  const defaultPath = `/${inflection.camelize(
768
- modelName.replace(/Model$/, ""),
778
+ modelName.replace(/Model$/, "").replace(/Frame$/, ""),
769
779
  true
770
780
  )}/${inflection.camelize(propertyKey, true)}`;
771
781
  const api2 = {
@@ -4005,14 +4015,13 @@ var Template__service = class extends Template {
4005
4015
  path: `${names.fs}/${names.fs}.service.ts`
4006
4016
  };
4007
4017
  }
4008
- render({ entityId }, apis) {
4009
- const names = EntityManager.getNamesFromId(entityId);
4018
+ render({ namesRecord }, apis) {
4010
4019
  const { lines, importKeys } = this.getTypeSource(apis);
4011
4020
  const hasAxiosProgressEvent = apis.find(
4012
4021
  (api2) => (api2.options.clients ?? []).includes("axios-multipart")
4013
4022
  );
4014
4023
  return {
4015
- ...this.getTargetAndPath(names),
4024
+ ...this.getTargetAndPath(namesRecord),
4016
4025
  body: lines.join("\n"),
4017
4026
  importKeys: importKeys.filter(
4018
4027
  (key) => ["ListResult"].includes(key) === false
@@ -4099,7 +4108,7 @@ var Template__service = class extends Template {
4099
4108
  }
4100
4109
  }).join("\n");
4101
4110
  }).join("\n\n");
4102
- return `export namespace ${modelName.replace(/Model$/, "Service")} {
4111
+ return `export namespace ${modelName.replace(/Model$/, "Service").replace(/Frame$/, "Service")} {
4103
4112
  ${methodCodes}
4104
4113
  }`;
4105
4114
  }).join("\n\n");
@@ -5348,7 +5357,7 @@ var Syncer = class {
5348
5357
  console.log("Changed Files: ", diffFiles);
5349
5358
  const diffGroups = _13.groupBy(diffFiles, (r) => {
5350
5359
  const matched = r.match(
5351
- /\.(model|types|functions|entity|generated)\.[tj]s/
5360
+ /\.(model|types|functions|entity|generated|frame)\.[tj]s/
5352
5361
  );
5353
5362
  return matched[1];
5354
5363
  });
@@ -5382,12 +5391,38 @@ var Syncer = class {
5382
5391
  );
5383
5392
  await this.actionSyncFilesToTargets(tsPaths);
5384
5393
  }
5385
- if (diffTypes.includes("model")) {
5386
- const entityIds = this.getEntityIdFromPath(diffGroups["model"]);
5394
+ if (diffTypes.includes("model") || diffTypes.includes("frame")) {
5387
5395
  console.log("// \uC561\uC158: \uC11C\uBE44\uC2A4 \uC0DD\uC131");
5388
- await this.actionGenerateServices(entityIds);
5396
+ const mergedGroup = [
5397
+ ...diffGroups["model"] ?? [],
5398
+ ...diffGroups["frame"] ?? []
5399
+ ];
5400
+ const params = mergedGroup.map((modelPath) => {
5401
+ if (modelPath.endsWith(".model.js")) {
5402
+ const entityId = this.getEntityIdFromPath([modelPath])[0];
5403
+ return {
5404
+ namesRecord: EntityManager.getNamesFromId(entityId),
5405
+ modelTsPath: path5.join(
5406
+ Sonamu.apiRootPath,
5407
+ modelPath.replace("/dist/", "/src/").replace(".model.js", ".model.ts")
5408
+ )
5409
+ };
5410
+ }
5411
+ if (modelPath.endsWith("frame.js")) {
5412
+ const [, frameName] = modelPath.match(/.+\/(.+)\.frame.js$/) ?? [];
5413
+ return {
5414
+ namesRecord: EntityManager.getNamesFromId(frameName),
5415
+ modelTsPath: path5.join(
5416
+ Sonamu.apiRootPath,
5417
+ modelPath.replace("/dist/", "/src/").replace(".frame.js", ".frame.ts")
5418
+ )
5419
+ };
5420
+ }
5421
+ throw new Error("not reachable");
5422
+ });
5423
+ await this.actionGenerateServices(params);
5389
5424
  console.log("// \uC561\uC158: HTTP\uD30C\uC77C \uC0DD\uC131");
5390
- await this.actionGenerateHttps(entityIds);
5425
+ await this.actionGenerateHttps();
5391
5426
  }
5392
5427
  await this.saveChecksums(currentChecksums);
5393
5428
  this.isSyncing = false;
@@ -5408,25 +5443,19 @@ var Syncer = class {
5408
5443
  this.generateTemplate("generated", {}, { overwrite: true })
5409
5444
  ])).flat().flat();
5410
5445
  }
5411
- async actionGenerateServices(entityIds) {
5446
+ async actionGenerateServices(paramsArray) {
5412
5447
  return (await Promise.all(
5413
- entityIds.map(
5414
- async (entityId) => this.generateTemplate(
5415
- "service",
5416
- {
5417
- entityId
5418
- },
5419
- {
5420
- overwrite: true
5421
- }
5422
- )
5448
+ paramsArray.map(
5449
+ async (params) => this.generateTemplate("service", params, {
5450
+ overwrite: true
5451
+ })
5423
5452
  )
5424
5453
  )).flat().flat();
5425
5454
  }
5426
- async actionGenerateHttps(entityIds) {
5455
+ async actionGenerateHttps() {
5427
5456
  const [res] = await this.generateTemplate(
5428
5457
  "generated_http",
5429
- { entityId: entityIds[0] },
5458
+ {},
5430
5459
  { overwrite: true }
5431
5460
  );
5432
5461
  return res;
@@ -5482,7 +5511,8 @@ var Syncer = class {
5482
5511
  generated: Sonamu.apiRootPath + "/src/application/sonamu.generated.ts",
5483
5512
  functions: Sonamu.apiRootPath + "/src/application/**/*.functions.ts",
5484
5513
  /* compiled-JS 체크 */
5485
- model: Sonamu.apiRootPath + "/dist/application/**/*.model.js"
5514
+ model: Sonamu.apiRootPath + "/dist/application/**/*.model.js",
5515
+ frame: Sonamu.apiRootPath + "/dist/application/**/*.frame.js"
5486
5516
  };
5487
5517
  const filePaths = (await Promise.all(
5488
5518
  Object.entries(PatternGroup).map(async ([_fileType, pattern]) => {
@@ -5593,6 +5623,9 @@ var Syncer = class {
5593
5623
  (method) => method.modelName === api2.modelName && method.methodName === api2.methodName
5594
5624
  );
5595
5625
  });
5626
+ if (currentModelApis.length === 0) {
5627
+ throw new Error(`\uD604\uC7AC \uD30C\uC77C\uC5D0 \uC0AC\uC804 \uB4F1\uB85D\uB41C API\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. ${filePath}`);
5628
+ }
5596
5629
  const extendedApis = currentModelApis.map((api2) => {
5597
5630
  const foundMethod = methods.find(
5598
5631
  (method) => method.modelName === api2.modelName && method.methodName === api2.methodName
@@ -5754,7 +5787,7 @@ var Syncer = class {
5754
5787
  async autoloadApis() {
5755
5788
  const pathPattern = path5.join(
5756
5789
  Sonamu.apiRootPath,
5757
- "/src/application/**/*.model.ts"
5790
+ "/src/application/**/*.{model,frame}.ts"
5758
5791
  );
5759
5792
  const filePaths = await globAsync(pathPattern);
5760
5793
  const result = await Promise.all(
@@ -5766,7 +5799,7 @@ var Syncer = class {
5766
5799
  async autoloadModels() {
5767
5800
  const pathPattern = path5.join(
5768
5801
  Sonamu.apiRootPath,
5769
- "dist/application/**/*.model.js"
5802
+ "dist/application/**/*.{model,frame}.js"
5770
5803
  );
5771
5804
  const filePaths = (await globAsync(pathPattern)).filter((path9) => {
5772
5805
  const srcPath = path9.replace("/dist/", "/src/").replace(".js", ".ts");
@@ -5775,7 +5808,9 @@ var Syncer = class {
5775
5808
  const modules = await importMultiple(filePaths);
5776
5809
  const functions = modules.map(({ imported }) => Object.entries(imported)).flat();
5777
5810
  this.models = Object.fromEntries(
5778
- functions.filter(([name]) => name.endsWith("Model"))
5811
+ functions.filter(
5812
+ ([name]) => name.endsWith("Model") || name.endsWith("Frame")
5813
+ )
5779
5814
  );
5780
5815
  return this.models;
5781
5816
  }
@@ -5842,18 +5877,12 @@ var Syncer = class {
5842
5877
  async renderTemplate(key, options) {
5843
5878
  const template = this.getTemplate(key);
5844
5879
  let extra = [];
5845
- if (["service", "generated_http", "model", "view_list", "view_form"].includes(
5846
- key
5847
- )) {
5880
+ if (key === "service") {
5881
+ const { modelTsPath } = options;
5882
+ extra = [await this.readApisFromFile(modelTsPath)];
5883
+ } else if (["model", "view_list", "view_form"].includes(key)) {
5848
5884
  const entityId = options.entityId;
5849
- if (key === "service" || key === "generated_http") {
5850
- const entity = EntityManager.get(entityId);
5851
- const modelTsPath = `${path5.join(
5852
- Sonamu.apiRootPath,
5853
- "/src/application"
5854
- )}/${entity.names.fs}/${entity.names.fs}.model.ts`;
5855
- extra = [await this.readApisFromFile(modelTsPath)];
5856
- } else if (key === "view_list" || key === "model") {
5885
+ if (key === "view_list" || key === "model") {
5857
5886
  const columnsNode = await this.getColumnsNode(entityId, "A");
5858
5887
  const listParamsZodType = await this.getZodTypeById(
5859
5888
  `${entityId}ListParams`
@@ -6286,7 +6315,7 @@ var Syncer = class {
6286
6315
  await EntityManager.reload();
6287
6316
  await Promise.all([
6288
6317
  this.actionGenerateSchemas(),
6289
- ...form.entityId === void 0 ? [
6318
+ ...form.parentId === void 0 ? [
6290
6319
  this.generateTemplate("init_types", {
6291
6320
  entityId: form.entityId
6292
6321
  })
@@ -7540,4 +7569,4 @@ export {
7540
7569
  isTest,
7541
7570
  Sonamu
7542
7571
  };
7543
- //# sourceMappingURL=chunk-EEUCHV4P.mjs.map
7572
+ //# sourceMappingURL=chunk-LNZTU4JC.mjs.map