sonamu 0.4.12 → 0.4.14

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 (46) hide show
  1. package/.pnp.cjs +5 -5
  2. package/dist/{base-model-BvVra-8f.d.mts → base-model-CEB0H0aO.d.mts} +1 -1
  3. package/dist/{base-model-Br6krkwK.d.ts → base-model-CrqDMYhI.d.ts} +1 -1
  4. package/dist/bin/cli.js +51 -51
  5. package/dist/bin/cli.mjs +2 -2
  6. package/dist/{chunk-ZLFDB43J.js → chunk-2WAC2GER.js} +147 -96
  7. package/dist/chunk-2WAC2GER.js.map +1 -0
  8. package/dist/{chunk-FKZK27YL.mjs → chunk-C3IPIF6O.mjs} +2 -2
  9. package/dist/{chunk-INTZUNZ6.js → chunk-EXHKSVTE.js} +7 -7
  10. package/dist/{chunk-LNZTU4JC.mjs → chunk-FCERKIIF.mjs} +104 -53
  11. package/dist/chunk-FCERKIIF.mjs.map +1 -0
  12. package/dist/{chunk-JQJTQQ7D.mjs → chunk-HGIBJYOU.mjs} +2 -2
  13. package/dist/{chunk-NPLUHS5L.mjs → chunk-JKSOJRQA.mjs} +2 -2
  14. package/dist/{chunk-FYLFH3Q6.js → chunk-OTKKFP3Y.js} +100 -100
  15. package/dist/{chunk-IEMX4VPN.js → chunk-UZ2IY5VE.js} +4 -4
  16. package/dist/database/drivers/knex/base-model.d.mts +2 -2
  17. package/dist/database/drivers/knex/base-model.d.ts +2 -2
  18. package/dist/database/drivers/knex/base-model.js +8 -8
  19. package/dist/database/drivers/knex/base-model.mjs +3 -3
  20. package/dist/database/drivers/kysely/base-model.d.mts +2 -2
  21. package/dist/database/drivers/kysely/base-model.d.ts +2 -2
  22. package/dist/database/drivers/kysely/base-model.js +9 -9
  23. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  24. package/dist/index.d.mts +17 -4
  25. package/dist/index.d.ts +17 -4
  26. package/dist/index.js +13 -9
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +7 -3
  29. package/dist/index.mjs.map +1 -1
  30. package/package.json +2 -2
  31. package/src/api/caster.ts +2 -2
  32. package/src/api/code-converters.ts +7 -0
  33. package/src/api/decorators.ts +36 -4
  34. package/src/shared/web.shared.ts.txt +225 -0
  35. package/src/syncer/syncer.ts +7 -1
  36. package/src/templates/service.template.ts +50 -9
  37. package/dist/chunk-LNZTU4JC.mjs.map +0 -1
  38. package/dist/chunk-ZLFDB43J.js.map +0 -1
  39. package/dist/{chunk-FKZK27YL.mjs.map → chunk-C3IPIF6O.mjs.map} +0 -0
  40. package/dist/{chunk-INTZUNZ6.js.map → chunk-EXHKSVTE.js.map} +0 -0
  41. package/dist/{chunk-JQJTQQ7D.mjs.map → chunk-HGIBJYOU.mjs.map} +0 -0
  42. package/dist/{chunk-NPLUHS5L.mjs.map → chunk-JKSOJRQA.mjs.map} +0 -0
  43. package/dist/{chunk-FYLFH3Q6.js.map → chunk-OTKKFP3Y.js.map} +0 -0
  44. package/dist/{chunk-IEMX4VPN.js.map → chunk-UZ2IY5VE.js.map} +0 -0
  45. package/dist/{model-DWoinpJ7.d.mts → model-aFgomcdc.d.mts} +4 -4
  46. package/dist/{model-DWoinpJ7.d.ts → model-aFgomcdc.d.ts} +4 -4
@@ -566,6 +566,9 @@ function apiParamToTsCode(params, injectImportKeys) {
566
566
  return `${param.name}${param.optional && !param.defaultDef ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`;
567
567
  }).join(", ");
568
568
  }
569
+ function apiParamToTsCodeAsObject(params, injectImportKeys) {
570
+ return `{ ${params.map((param) => `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`).join(", ")} }`;
571
+ }
569
572
  function apiParamTypeToTsType(paramType, injectImportKeys) {
570
573
  if ([
571
574
  "string",
@@ -780,13 +783,32 @@ function api(options = {}) {
780
783
  modelName.replace(/Model$/, "").replace(/Frame$/, ""),
781
784
  true
782
785
  )}/${_inflection2.default.camelize(propertyKey, true)}`;
783
- const api2 = {
786
+ registeredApis.push({
784
787
  modelName,
785
788
  methodName,
786
789
  path: _nullishCoalesce(options.path, () => ( defaultPath)),
787
790
  options
788
- };
789
- registeredApis.push(api2);
791
+ });
792
+ };
793
+ }
794
+ function stream(options) {
795
+ return function(target, propertyKey) {
796
+ const modelName = target.constructor.name.match(/(.+)Class$/)[1];
797
+ const methodName = propertyKey;
798
+ const defaultPath = `/${_inflection2.default.camelize(
799
+ modelName.replace(/Model$/, "").replace(/Frame$/, ""),
800
+ true
801
+ )}/${_inflection2.default.camelize(propertyKey, true)}`;
802
+ registeredApis.push({
803
+ modelName,
804
+ methodName,
805
+ path: _nullishCoalesce(options.path, () => ( defaultPath)),
806
+ options: {
807
+ ...options,
808
+ httpMethod: "GET"
809
+ },
810
+ streamOptions: options
811
+ });
790
812
  };
791
813
  }
792
814
 
@@ -969,7 +991,7 @@ function isZodNumberAnyway(zodType) {
969
991
  } else if (zodType instanceof _zod.z.ZodNullable && zodType._def.innerType instanceof _zod.z.ZodNumber) {
970
992
  return true;
971
993
  } else if (zodType instanceof _zod.z.ZodOptional && zodType._def.innerType instanceof _zod.z.ZodNumber) {
972
- } else if (zodType instanceof _zod.z.ZodOptional && zodType._def.innerType instanceof _zod.z.ZodOptional && zodType._type.def.innerType instanceof _zod.z.ZodNumber) {
994
+ } else if (zodType instanceof _zod.z.ZodOptional && _optionalChain([zodType, 'access', _63 => _63._def, 'optionalAccess', _64 => _64.innerType]) instanceof _zod.z.ZodOptional && _optionalChain([zodType, 'access', _65 => _65._type, 'optionalAccess', _66 => _66.def, 'optionalAccess', _67 => _67.innerType]) instanceof _zod.z.ZodNumber) {
973
995
  return true;
974
996
  }
975
997
  return false;
@@ -1317,13 +1339,13 @@ var Template__entity = class extends Template {
1317
1339
  }
1318
1340
  })();
1319
1341
  return {
1320
- ...this.getTargetAndPath(names, _nullishCoalesce(_optionalChain([parent, 'optionalAccess', _63 => _63.names]), () => ( names))),
1342
+ ...this.getTargetAndPath(names, _nullishCoalesce(_optionalChain([parent, 'optionalAccess', _68 => _68.names]), () => ( names))),
1321
1343
  body: JSON.stringify({
1322
1344
  id: entityId,
1323
1345
  title: _nullishCoalesce(title, () => ( entityId)),
1324
1346
  parentId,
1325
1347
  table: _nullishCoalesce(table, () => ( names.fsPlural.replace(/\-/g, "_"))),
1326
- props: _optionalChain([options, 'access', _64 => _64.props, 'optionalAccess', _65 => _65.length]) ? options.props : [
1348
+ props: _optionalChain([options, 'access', _69 => _69.props, 'optionalAccess', _70 => _70.length]) ? options.props : [
1327
1349
  { name: "id", type: "integer", unsigned: true, desc: "ID" },
1328
1350
  ...parent ? [
1329
1351
  {
@@ -1414,7 +1436,7 @@ var Template__view_list = class extends Template {
1414
1436
  return `<>{/* object ${colName} */}</>`;
1415
1437
  case "object-pick":
1416
1438
  const pickedChild = col.children.find(
1417
- (child) => child.name === _optionalChain([col, 'access', _66 => _66.config, 'optionalAccess', _67 => _67.picked])
1439
+ (child) => child.name === _optionalChain([col, 'access', _71 => _71.config, 'optionalAccess', _72 => _72.picked])
1418
1440
  );
1419
1441
  if (!pickedChild) {
1420
1442
  throw new Error(`object-pick \uC120\uD0DD \uC2E4\uD328 (\uC624\uBE0C\uC81D\uD2B8: ${col.name})`);
@@ -1528,13 +1550,13 @@ var Template__view_list = class extends Template {
1528
1550
  orderBy: "id-desc",
1529
1551
  search: "title"
1530
1552
  };
1531
- const orderByZodType = _optionalChain([columns, 'access', _68 => _68.find, 'call', _69 => _69(
1553
+ const orderByZodType = _optionalChain([columns, 'access', _73 => _73.find, 'call', _74 => _74(
1532
1554
  (col) => col.name === "orderBy"
1533
- ), 'optionalAccess', _70 => _70.zodType]);
1555
+ ), 'optionalAccess', _75 => _75.zodType]);
1534
1556
  if (orderByZodType && orderByZodType instanceof _zod.z.ZodEnum) {
1535
1557
  def.orderBy = Object.keys(orderByZodType.Enum)[0];
1536
1558
  }
1537
- const searchZodType = _optionalChain([columns, 'access', _71 => _71.find, 'call', _72 => _72((col) => col.name === "search"), 'optionalAccess', _73 => _73.zodType]);
1559
+ const searchZodType = _optionalChain([columns, 'access', _76 => _76.find, 'call', _77 => _77((col) => col.name === "search"), 'optionalAccess', _78 => _78.zodType]);
1538
1560
  if (searchZodType && searchZodType instanceof _zod.z.ZodEnum) {
1539
1561
  def.search = Object.keys(searchZodType.Enum)[0];
1540
1562
  }
@@ -1547,7 +1569,7 @@ var Template__view_list = class extends Template {
1547
1569
  const propCandidate = entity.props.find((p) => p.name === col.name);
1548
1570
  return {
1549
1571
  name: col.name,
1550
- label: _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _74 => _74.desc]), () => ( col.label)),
1572
+ label: _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _79 => _79.desc]), () => ( col.label)),
1551
1573
  tc: `(row) => ${this.renderColumn(entityId, col, names)}`
1552
1574
  };
1553
1575
  });
@@ -2506,11 +2528,11 @@ var KnexClient = (_class = class _KnexClient {
2506
2528
  __init() {this.generator = new KnexGenerator()}
2507
2529
  get connectionInfo() {
2508
2530
  return {
2509
- host: _nullishCoalesce(_optionalChain([this, 'access', _75 => _75.knex, 'access', _76 => _76.client, 'access', _77 => _77.config, 'access', _78 => _78.connection, 'optionalAccess', _79 => _79.host]), () => ( "localhost")),
2510
- port: _nullishCoalesce(_optionalChain([this, 'access', _80 => _80.knex, 'access', _81 => _81.client, 'access', _82 => _82.config, 'access', _83 => _83.connection, 'optionalAccess', _84 => _84.port]), () => ( 3306)),
2511
- database: _nullishCoalesce(_optionalChain([this, 'access', _85 => _85.knex, 'access', _86 => _86.client, 'access', _87 => _87.config, 'access', _88 => _88.connection, 'optionalAccess', _89 => _89.database]), () => ( "")),
2512
- user: _nullishCoalesce(_optionalChain([this, 'access', _90 => _90.knex, 'access', _91 => _91.client, 'access', _92 => _92.config, 'access', _93 => _93.connection, 'optionalAccess', _94 => _94.user]), () => ( "")),
2513
- password: _nullishCoalesce(_optionalChain([this, 'access', _95 => _95.knex, 'access', _96 => _96.client, 'access', _97 => _97.config, 'access', _98 => _98.connection, 'optionalAccess', _99 => _99.password]), () => ( ""))
2531
+ host: _nullishCoalesce(_optionalChain([this, 'access', _80 => _80.knex, 'access', _81 => _81.client, 'access', _82 => _82.config, 'access', _83 => _83.connection, 'optionalAccess', _84 => _84.host]), () => ( "localhost")),
2532
+ port: _nullishCoalesce(_optionalChain([this, 'access', _85 => _85.knex, 'access', _86 => _86.client, 'access', _87 => _87.config, 'access', _88 => _88.connection, 'optionalAccess', _89 => _89.port]), () => ( 3306)),
2533
+ database: _nullishCoalesce(_optionalChain([this, 'access', _90 => _90.knex, 'access', _91 => _91.client, 'access', _92 => _92.config, 'access', _93 => _93.connection, 'optionalAccess', _94 => _94.database]), () => ( "")),
2534
+ user: _nullishCoalesce(_optionalChain([this, 'access', _95 => _95.knex, 'access', _96 => _96.client, 'access', _97 => _97.config, 'access', _98 => _98.connection, 'optionalAccess', _99 => _99.user]), () => ( "")),
2535
+ password: _nullishCoalesce(_optionalChain([this, 'access', _100 => _100.knex, 'access', _101 => _101.client, 'access', _102 => _102.config, 'access', _103 => _103.connection, 'optionalAccess', _104 => _104.password]), () => ( ""))
2514
2536
  };
2515
2537
  }
2516
2538
 
@@ -2605,13 +2627,13 @@ var KnexClient = (_class = class _KnexClient {
2605
2627
  return this.qb.pluck(column);
2606
2628
  }
2607
2629
  createRawQuery(query, bindings) {
2608
- if (_optionalChain([bindings, 'optionalAccess', _100 => _100.length])) {
2630
+ if (_optionalChain([bindings, 'optionalAccess', _105 => _105.length])) {
2609
2631
  return this.knex.raw(query, bindings).toQuery();
2610
2632
  }
2611
2633
  return this.knex.raw(query).toQuery();
2612
2634
  }
2613
2635
  async raw(query, bindings) {
2614
- if (_optionalChain([bindings, 'optionalAccess', _101 => _101.length])) {
2636
+ if (_optionalChain([bindings, 'optionalAccess', _106 => _106.length])) {
2615
2637
  return (await this.knex.raw(query, bindings))[0];
2616
2638
  }
2617
2639
  return (await this.knex.raw(query))[0];
@@ -2811,7 +2833,7 @@ var KyselyClient = class _KyselyClient {
2811
2833
  return result.map((row) => row[column]);
2812
2834
  }
2813
2835
  createRawQuery(query, bindings) {
2814
- if (_optionalChain([bindings, 'optionalAccess', _102 => _102.length])) {
2836
+ if (_optionalChain([bindings, 'optionalAccess', _107 => _107.length])) {
2815
2837
  query = query.replace(
2816
2838
  /\?/g,
2817
2839
  () => _kysely.sql.lit(bindings.shift()).compile(this.kysely).sql
@@ -2820,7 +2842,7 @@ var KyselyClient = class _KyselyClient {
2820
2842
  return _kysely.sql.raw(query).compile(this.kysely).sql;
2821
2843
  }
2822
2844
  async raw(query, bindings) {
2823
- if (_optionalChain([bindings, 'optionalAccess', _103 => _103.length])) {
2845
+ if (_optionalChain([bindings, 'optionalAccess', _108 => _108.length])) {
2824
2846
  query = query.replace(
2825
2847
  /\?/g,
2826
2848
  () => _kysely.sql.lit(bindings.shift()).compile(this.kysely).sql
@@ -2873,14 +2895,14 @@ var KyselyClient = class _KyselyClient {
2873
2895
  if (error) {
2874
2896
  throw error;
2875
2897
  }
2876
- return [0, _optionalChain([results, 'optionalAccess', _104 => _104.map, 'call', _105 => _105((r) => r.migrationName)])];
2898
+ return [0, _optionalChain([results, 'optionalAccess', _109 => _109.map, 'call', _110 => _110((r) => r.migrationName)])];
2877
2899
  }
2878
2900
  async rollback() {
2879
2901
  const { results, error } = await this.migrator.migrateDown();
2880
2902
  if (error) {
2881
2903
  throw error;
2882
2904
  }
2883
- return [0, _optionalChain([results, 'optionalAccess', _106 => _106.map, 'call', _107 => _107((r) => r.migrationName)])];
2905
+ return [0, _optionalChain([results, 'optionalAccess', _111 => _111.map, 'call', _112 => _112((r) => r.migrationName)])];
2884
2906
  }
2885
2907
  async rollbackAll() {
2886
2908
  while (true) {
@@ -2912,7 +2934,7 @@ var DBClass = class {
2912
2934
  async getBaseConfig(rootPath) {
2913
2935
  const baseConfigPath = _path2.default.join(rootPath, "/dist/configs/db.js");
2914
2936
  const module = await Promise.resolve().then(() => _interopRequireWildcard(require(baseConfigPath)));
2915
- const config = _nullishCoalesce(_nullishCoalesce(_optionalChain([module, 'access', _108 => _108.default, 'optionalAccess', _109 => _109.default]), () => ( module.default)), () => ( module));
2937
+ const config = _nullishCoalesce(_nullishCoalesce(_optionalChain([module, 'access', _113 => _113.default, 'optionalAccess', _114 => _114.default]), () => ( module.default)), () => ( module));
2916
2938
  return config;
2917
2939
  }
2918
2940
  getCurrentConfig(which) {
@@ -3112,15 +3134,15 @@ var DBKnexClass = (_class2 = class extends DBClass {
3112
3134
  database: `${config.database}_test`
3113
3135
  }
3114
3136
  },
3115
- _optionalChain([config, 'access', _110 => _110.environments, 'optionalAccess', _111 => _111.test])
3137
+ _optionalChain([config, 'access', _115 => _115.environments, 'optionalAccess', _116 => _116.test])
3116
3138
  );
3117
3139
  const fixture_local = _lodash2.default.merge({}, defaultKnexConfig, {
3118
3140
  connection: {
3119
3141
  database: `${config.database}_fixture`
3120
3142
  }
3121
3143
  });
3122
- const devMasterOptions = _optionalChain([config, 'access', _112 => _112.environments, 'optionalAccess', _113 => _113.development]);
3123
- const devSlaveOptions = _optionalChain([config, 'access', _114 => _114.environments, 'optionalAccess', _115 => _115.development_slave]);
3144
+ const devMasterOptions = _optionalChain([config, 'access', _117 => _117.environments, 'optionalAccess', _118 => _118.development]);
3145
+ const devSlaveOptions = _optionalChain([config, 'access', _119 => _119.environments, 'optionalAccess', _120 => _120.development_slave]);
3124
3146
  const development_master = _lodash2.default.merge({}, defaultKnexConfig, devMasterOptions);
3125
3147
  const development_slave = _lodash2.default.merge(
3126
3148
  {},
@@ -3133,8 +3155,8 @@ var DBKnexClass = (_class2 = class extends DBClass {
3133
3155
  database: `${config.database}_fixture`
3134
3156
  }
3135
3157
  });
3136
- const prodMasterOptions = _nullishCoalesce(_optionalChain([config, 'access', _116 => _116.environments, 'optionalAccess', _117 => _117.production]), () => ( {}));
3137
- const prodSlaveOptions = _nullishCoalesce(_optionalChain([config, 'access', _118 => _118.environments, 'optionalAccess', _119 => _119.production_slave]), () => ( {}));
3158
+ const prodMasterOptions = _nullishCoalesce(_optionalChain([config, 'access', _121 => _121.environments, 'optionalAccess', _122 => _122.production]), () => ( {}));
3159
+ const prodSlaveOptions = _nullishCoalesce(_optionalChain([config, 'access', _123 => _123.environments, 'optionalAccess', _124 => _124.production_slave]), () => ( {}));
3138
3160
  const production_master = _lodash2.default.merge({}, defaultKnexConfig, prodMasterOptions);
3139
3161
  const production_slave = _lodash2.default.merge(
3140
3162
  {},
@@ -3875,8 +3897,8 @@ var DBKyselyClass = (_class3 = class extends DBClass {
3875
3897
  const fixture_local = _lodash2.default.merge({}, defaultKyselyConfig, {
3876
3898
  database: `${config.database}_fixture`
3877
3899
  });
3878
- const devMasterOptions = _optionalChain([config, 'access', _120 => _120.environments, 'optionalAccess', _121 => _121.development]);
3879
- const devSlaveOptions = _optionalChain([config, 'access', _122 => _122.environments, 'optionalAccess', _123 => _123.development_slave]);
3900
+ const devMasterOptions = _optionalChain([config, 'access', _125 => _125.environments, 'optionalAccess', _126 => _126.development]);
3901
+ const devSlaveOptions = _optionalChain([config, 'access', _127 => _127.environments, 'optionalAccess', _128 => _128.development_slave]);
3880
3902
  const development_master = _lodash2.default.merge(
3881
3903
  {},
3882
3904
  defaultKyselyConfig,
@@ -3891,8 +3913,8 @@ var DBKyselyClass = (_class3 = class extends DBClass {
3891
3913
  const fixture_remote = _lodash2.default.merge({}, defaultKyselyConfig, devMasterOptions, {
3892
3914
  database: `${config.database}_fixture`
3893
3915
  });
3894
- const prodMasterOptions = _nullishCoalesce(_optionalChain([config, 'access', _124 => _124.environments, 'optionalAccess', _125 => _125.production]), () => ( {}));
3895
- const prodSlaveOptions = _nullishCoalesce(_optionalChain([config, 'access', _126 => _126.environments, 'optionalAccess', _127 => _127.production_slave]), () => ( {}));
3916
+ const prodMasterOptions = _nullishCoalesce(_optionalChain([config, 'access', _129 => _129.environments, 'optionalAccess', _130 => _130.production]), () => ( {}));
3917
+ const prodSlaveOptions = _nullishCoalesce(_optionalChain([config, 'access', _131 => _131.environments, 'optionalAccess', _132 => _132.production_slave]), () => ( {}));
3896
3918
  const production_master = _lodash2.default.merge(
3897
3919
  {},
3898
3920
  defaultKyselyConfig,
@@ -3936,7 +3958,7 @@ var dbConfigPath = _path2.default.join(
3936
3958
  );
3937
3959
  var knexfileModule = __require(dbConfigPath);
3938
3960
  var DB = (() => {
3939
- const config = _nullishCoalesce(_nullishCoalesce(_optionalChain([knexfileModule, 'access', _128 => _128.default, 'optionalAccess', _129 => _129.default]), () => ( knexfileModule.default)), () => ( knexfileModule));
3961
+ const config = _nullishCoalesce(_nullishCoalesce(_optionalChain([knexfileModule, 'access', _133 => _133.default, 'optionalAccess', _134 => _134.default]), () => ( knexfileModule.default)), () => ( knexfileModule));
3940
3962
  if (config.client === "knex") {
3941
3963
  return new DBKnexClass();
3942
3964
  } else if (config.client === "kysely") {
@@ -3960,7 +3982,7 @@ var Template__model = class extends Template {
3960
3982
  render({ entityId }, _columnsNode, listParamsNode) {
3961
3983
  const names = EntityManager.getNamesFromId(entityId);
3962
3984
  const vlTpl = new Template__view_list();
3963
- if (_optionalChain([listParamsNode, 'optionalAccess', _130 => _130.children]) === void 0) {
3985
+ if (_optionalChain([listParamsNode, 'optionalAccess', _135 => _135.children]) === void 0) {
3964
3986
  throw new Error(`listParamsNode\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. ${entityId}`);
3965
3987
  }
3966
3988
  const def = vlTpl.getDefault(listParamsNode.children);
@@ -4032,7 +4054,7 @@ var Template__service = class extends Template {
4032
4054
  `import { z } from 'zod';`,
4033
4055
  `import qs from "qs";`,
4034
4056
  `import useSWR, { SWRResponse } from "swr";`,
4035
- `import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher } from '../sonamu.shared';`,
4057
+ `import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher, EventHandlers, SSEStreamOptions, useSSEStream } from '../sonamu.shared';`,
4036
4058
  ...hasAxiosProgressEvent ? [`import { AxiosProgressEvent } from 'axios';`] : []
4037
4059
  ]
4038
4060
  };
@@ -4058,57 +4080,65 @@ var Template__service = class extends Template {
4058
4080
  paramsWithoutContext,
4059
4081
  importKeys
4060
4082
  );
4083
+ const paramsDefAsObject = apiParamToTsCodeAsObject(
4084
+ paramsWithoutContext,
4085
+ importKeys
4086
+ );
4061
4087
  const returnTypeDef = apiParamTypeToTsType(
4062
4088
  unwrapPromiseOnce(api2.returnType),
4063
4089
  importKeys
4064
4090
  );
4065
4091
  const payloadDef = `{ ${paramsWithoutContext.map((param) => param.name).join(", ")} }`;
4066
- return _lodash2.default.sortBy(
4067
- api2.options.clients,
4068
- (client) => client === "swr" ? 0 : 1
4069
- ).map((client) => {
4070
- const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
4071
- switch (client) {
4072
- case "axios":
4073
- return this.renderAxios(
4074
- api2,
4075
- apiBaseUrl,
4076
- typeParamsDef,
4077
- paramsDef,
4078
- returnTypeDef,
4079
- payloadDef
4080
- );
4081
- case "axios-multipart":
4082
- return this.renderAxiosMultipart(
4083
- api2,
4084
- apiBaseUrl,
4085
- typeParamsDef,
4086
- paramsDef,
4087
- returnTypeDef,
4088
- paramsWithoutContext
4089
- );
4090
- case "swr":
4091
- return this.renderSwr(
4092
- api2,
4093
- apiBaseUrl,
4094
- typeParamsDef,
4095
- paramsDef,
4096
- returnTypeDef,
4097
- payloadDef
4098
- );
4099
- case "window-fetch":
4100
- return this.renderWindowFetch(
4101
- api2,
4102
- apiBaseUrl,
4103
- typeParamsDef,
4104
- paramsDef,
4105
- payloadDef
4106
- );
4107
- case "socketio":
4108
- default:
4109
- return `// Not supported ${_inflection2.default.camelize(client, true)} yet.`;
4110
- }
4111
- }).join("\n");
4092
+ const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
4093
+ return [
4094
+ // 클라이언트별로 생성
4095
+ ..._lodash2.default.sortBy(
4096
+ api2.options.clients,
4097
+ (client) => client === "swr" ? 0 : 1
4098
+ ).map((client) => {
4099
+ switch (client) {
4100
+ case "axios":
4101
+ return this.renderAxios(
4102
+ api2,
4103
+ apiBaseUrl,
4104
+ typeParamsDef,
4105
+ paramsDef,
4106
+ returnTypeDef,
4107
+ payloadDef
4108
+ );
4109
+ case "axios-multipart":
4110
+ return this.renderAxiosMultipart(
4111
+ api2,
4112
+ apiBaseUrl,
4113
+ typeParamsDef,
4114
+ paramsDef,
4115
+ returnTypeDef,
4116
+ paramsWithoutContext
4117
+ );
4118
+ case "swr":
4119
+ return this.renderSwr(
4120
+ api2,
4121
+ apiBaseUrl,
4122
+ typeParamsDef,
4123
+ paramsDef,
4124
+ returnTypeDef,
4125
+ payloadDef
4126
+ );
4127
+ case "window-fetch":
4128
+ return this.renderWindowFetch(
4129
+ api2,
4130
+ apiBaseUrl,
4131
+ typeParamsDef,
4132
+ paramsDef,
4133
+ payloadDef
4134
+ );
4135
+ default:
4136
+ return `// Not supported ${_inflection2.default.camelize(client, true)} yet.`;
4137
+ }
4138
+ }),
4139
+ // 스트리밍인 경우
4140
+ ...api2.streamOptions ? [this.renderStream(api2, apiBaseUrl, paramsDefAsObject)] : []
4141
+ ].join("\n");
4112
4142
  }).join("\n\n");
4113
4143
  return `export namespace ${modelName.replace(/Model$/, "Service").replace(/Frame$/, "Service")} {
4114
4144
  ${methodCodes}
@@ -4189,6 +4219,23 @@ export async function ${api2.methodName}${typeParamsDef}(${paramsDef}): Promise<
4189
4219
  }
4190
4220
  `.trim();
4191
4221
  }
4222
+ renderStream(api2, apiBaseUrl, paramsDefAsObject) {
4223
+ if (!api2.streamOptions) {
4224
+ return "// streamOptions not found";
4225
+ }
4226
+ const methodNameStream = api2.options.resourceName ? "use" + _inflection2.default.camelize(api2.options.resourceName) : "use" + _inflection2.default.camelize(api2.methodName);
4227
+ const methodNameStreamCamelized = _inflection2.default.camelize(
4228
+ methodNameStream,
4229
+ true
4230
+ );
4231
+ const eventsTypeDef = zodTypeToTsTypeDef(api2.streamOptions.events);
4232
+ return ` export function ${methodNameStreamCamelized}(
4233
+ params: ${paramsDefAsObject},
4234
+ handlers: EventHandlers<${eventsTypeDef} & { end?: () => void }>,
4235
+ options: SSEStreamOptions) {
4236
+ return useSSEStream<${eventsTypeDef}>(\`${apiBaseUrl}\`, params, handlers, options);
4237
+ }`;
4238
+ }
4192
4239
  };
4193
4240
 
4194
4241
  // src/templates/view_form.template.ts
@@ -4341,7 +4388,7 @@ var Template__view_form = class extends Template {
4341
4388
  const propCandidate = entity.props.find(
4342
4389
  (prop) => prop.name === col.name
4343
4390
  );
4344
- col.label = _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _131 => _131.desc]), () => ( col.label));
4391
+ col.label = _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _136 => _136.desc]), () => ( col.label));
4345
4392
  return col;
4346
4393
  });
4347
4394
  const defaultValue = this.resolveDefaultValue(columns);
@@ -5144,8 +5191,8 @@ var Template__kysely_interface = class extends Template {
5144
5191
  getTargetAndPath() {
5145
5192
  const { dir } = Sonamu.config.api;
5146
5193
  const { types } = DB.baseConfig;
5147
- const outDir = _nullishCoalesce(_optionalChain([types, 'optionalAccess', _132 => _132.outDir]), () => ( "src/typings"));
5148
- const fileName = _nullishCoalesce(_optionalChain([types, 'optionalAccess', _133 => _133.fileName]), () => ( "database.types.ts"));
5194
+ const outDir = _nullishCoalesce(_optionalChain([types, 'optionalAccess', _137 => _137.outDir]), () => ( "src/typings"));
5195
+ const fileName = _nullishCoalesce(_optionalChain([types, 'optionalAccess', _138 => _138.fileName]), () => ( "database.types.ts"));
5149
5196
  return {
5150
5197
  target: `${dir}/${outDir}`,
5151
5198
  path: fileName
@@ -5300,9 +5347,10 @@ var Syncer = (_class4 = class {
5300
5347
  }
5301
5348
  async sync() {
5302
5349
  const { targets } = Sonamu.config.sync;
5350
+ const currentDirname = __dirname.endsWith("/syncer") ? __dirname : _path2.default.join(__dirname, "./syncer");
5303
5351
  await Promise.all(
5304
5352
  targets.map(async (target) => {
5305
- const srcCodePath = _path2.default.join(__dirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
5353
+ const srcCodePath = _path2.default.join(currentDirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
5306
5354
  if (!_fsextra2.default.existsSync(srcCodePath)) {
5307
5355
  return;
5308
5356
  }
@@ -5322,6 +5370,7 @@ var Syncer = (_class4 = class {
5322
5370
  return;
5323
5371
  }
5324
5372
  _fsextra2.default.writeFileSync(dstCodePath, _fsextra2.default.readFileSync(srcCodePath));
5373
+ console.log(_chalk2.default.blue("shared.ts is synced"));
5325
5374
  })
5326
5375
  );
5327
5376
  let currentChecksums = await this.getCurrentChecksums();
@@ -5367,7 +5416,7 @@ var Syncer = (_class4 = class {
5367
5416
  if (diffTypes.includes("entity") || diffTypes.includes("types")) {
5368
5417
  console.log("// \uC561\uC158: \uC2A4\uD0A4\uB9C8 \uC0DD\uC131");
5369
5418
  await this.actionGenerateSchemas();
5370
- if (_optionalChain([DB, 'access', _135 => _135.baseConfig, 'optionalAccess', _136 => _136.client]) === "kysely" && _optionalChain([DB, 'access', _137 => _137.baseConfig, 'access', _138 => _138.types, 'optionalAccess', _139 => _139.enabled]) !== false) {
5419
+ if (_optionalChain([DB, 'access', _140 => _140.baseConfig, 'optionalAccess', _141 => _141.client]) === "kysely" && _optionalChain([DB, 'access', _142 => _142.baseConfig, 'access', _143 => _143.types, 'optionalAccess', _144 => _144.enabled]) !== false) {
5371
5420
  console.log("// \uC561\uC158: kysely \uC778\uD130\uD398\uC774\uC2A4 \uC0DD\uC131");
5372
5421
  await this.generateTemplate(
5373
5422
  "kysely_interface",
@@ -5642,7 +5691,7 @@ var Syncer = (_class4 = class {
5642
5691
  return extendedApis;
5643
5692
  }
5644
5693
  resolveTypeNode(typeNode) {
5645
- switch (_optionalChain([typeNode, 'optionalAccess', _140 => _140.kind])) {
5694
+ switch (_optionalChain([typeNode, 'optionalAccess', _145 => _145.kind])) {
5646
5695
  case _typescript2.default.SyntaxKind.AnyKeyword:
5647
5696
  return "any";
5648
5697
  case _typescript2.default.SyntaxKind.UnknownKeyword:
@@ -5718,7 +5767,7 @@ var Syncer = (_class4 = class {
5718
5767
  return {
5719
5768
  t: "ref",
5720
5769
  id: typeNode.typeName.escapedText.toString(),
5721
- args: _optionalChain([typeNode, 'access', _141 => _141.typeArguments, 'optionalAccess', _142 => _142.map, 'call', _143 => _143(
5770
+ args: _optionalChain([typeNode, 'access', _146 => _146.typeArguments, 'optionalAccess', _147 => _147.map, 'call', _148 => _148(
5722
5771
  (typeArg) => this.resolveTypeNode(typeArg)
5723
5772
  )])
5724
5773
  };
@@ -5772,7 +5821,7 @@ var Syncer = (_class4 = class {
5772
5821
  name: name.escapedText ? name.escapedText.toString() : `nonameAt${index}`,
5773
5822
  type,
5774
5823
  optional: paramDec.optional === true,
5775
- defaultDef: _optionalChain([paramDec, 'optionalAccess', _144 => _144.defaultDef])
5824
+ defaultDef: _optionalChain([paramDec, 'optionalAccess', _149 => _149.defaultDef])
5776
5825
  };
5777
5826
  if (_typescript2.default.isObjectBindingPattern(name) && _typescript2.default.isTypeReferenceNode(paramDec.type) && _typescript2.default.isIdentifier(paramDec.type.typeName)) {
5778
5827
  result.name = _inflection2.default.camelize(paramDec.type.typeName.text, true);
@@ -6112,7 +6161,7 @@ var Syncer = (_class4 = class {
6112
6161
  },
6113
6162
  {}
6114
6163
  );
6115
- if (_optionalChain([propNode, 'access', _145 => _145.prop, 'optionalAccess', _146 => _146.nullable]) === true) {
6164
+ if (_optionalChain([propNode, 'access', _150 => _150.prop, 'optionalAccess', _151 => _151.nullable]) === true) {
6116
6165
  return _zod.z.object(obj).nullable();
6117
6166
  } else {
6118
6167
  return _zod.z.object(obj);
@@ -6511,7 +6560,7 @@ var SonamuClass = (_class5 = class {constructor() { _class5.prototype.__init15.c
6511
6560
  __init16() {this.asyncLocalStorage = new (0, _async_hooks.AsyncLocalStorage)()}
6512
6561
  getContext() {
6513
6562
  const store = this.asyncLocalStorage.getStore();
6514
- if (_optionalChain([store, 'optionalAccess', _147 => _147.context])) {
6563
+ if (_optionalChain([store, 'optionalAccess', _152 => _152.context])) {
6515
6564
  return store.context;
6516
6565
  }
6517
6566
  throw new Error("Sonamu cannot find context");
@@ -6626,7 +6675,7 @@ var SonamuClass = (_class5 = class {constructor() { _class5.prototype.__init15.c
6626
6675
  }
6627
6676
  async withFastify(server, config, options) {
6628
6677
  if (this.isInitialized === false) {
6629
- await this.init(_optionalChain([options, 'optionalAccess', _148 => _148.doSilent]), _optionalChain([options, 'optionalAccess', _149 => _149.enableSync]));
6678
+ await this.init(_optionalChain([options, 'optionalAccess', _153 => _153.doSilent]), _optionalChain([options, 'optionalAccess', _154 => _154.enableSync]));
6630
6679
  }
6631
6680
  server.get(
6632
6681
  `${this.config.route.prefix}/routes`,
@@ -6762,7 +6811,7 @@ var EntityManagerClass = (_class6 = class {constructor() { _class6.prototype.__i
6762
6811
  Sonamu.apiRootPath,
6763
6812
  `dist/application/sonamu.generated.js?t=${Date.now()}`
6764
6813
  );
6765
- if (_optionalChain([__require, 'optionalAccess', _150 => _150.cache]) && __require.cache[sonamuPath]) {
6814
+ if (_optionalChain([__require, 'optionalAccess', _155 => _155.cache]) && __require.cache[sonamuPath]) {
6766
6815
  delete __require.cache[sonamuPath];
6767
6816
  }
6768
6817
  return await this.autoload(doSilent);
@@ -7058,7 +7107,7 @@ var Entity = (_class7 = class {
7058
7107
  const relSubsetQuery = relEntity.resolveSubsetQuery("", relFields);
7059
7108
  let manyJoin;
7060
7109
  if (isHasManyRelationProp(relation)) {
7061
- const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _151 => _151.fromColumn]), () => ( "id"));
7110
+ const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _156 => _156.fromColumn]), () => ( "id"));
7062
7111
  manyJoin = {
7063
7112
  fromTable: this.table,
7064
7113
  fromCol,
@@ -7570,5 +7619,7 @@ var Entity = (_class7 = class {
7570
7619
 
7571
7620
 
7572
7621
 
7573
- exports.SQLDateTimeString = SQLDateTimeString; exports.zArrayable = zArrayable; exports.isIntegerProp = isIntegerProp; exports.isBigIntegerProp = isBigIntegerProp; exports.isTextProp = isTextProp; exports.isStringProp = isStringProp; exports.isEnumProp = isEnumProp; exports.isFloatProp = isFloatProp; exports.isDoubleProp = isDoubleProp; exports.isDecimalProp = isDecimalProp; exports.isBooleanProp = isBooleanProp; exports.isDateProp = isDateProp; exports.isDateTimeProp = isDateTimeProp; exports.isTimeProp = isTimeProp; exports.isTimestampProp = isTimestampProp; exports.isJsonProp = isJsonProp; exports.isUuidProp = isUuidProp; exports.isVirtualProp = isVirtualProp; exports.isRelationProp = isRelationProp; exports.isOneToOneRelationProp = isOneToOneRelationProp; exports.isBelongsToOneRelationProp = isBelongsToOneRelationProp; exports.isHasManyRelationProp = isHasManyRelationProp; exports.isManyToManyRelationProp = isManyToManyRelationProp; exports.isCustomJoinClause = isCustomJoinClause; exports.SonamuQueryMode = SonamuQueryMode; exports.isKnexError = isKnexError; exports.isKyselyError = isKyselyError; exports.ApiParamType = ApiParamType; exports.RenderingNode = RenderingNode; exports.TemplateOptions = TemplateOptions; exports.TemplateKey = TemplateKey; exports.GenerateOptions = GenerateOptions; exports.PathAndCode = PathAndCode; exports.getZodObjectFromApi = getZodObjectFromApi; exports.getZodObjectFromApiParams = getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = getZodTypeFromApiParamType; exports.propNodeToZodTypeDef = propNodeToZodTypeDef; exports.getTextTypeLength = getTextTypeLength; exports.propToZodTypeDef = propToZodTypeDef; exports.zodTypeToZodCode = zodTypeToZodCode; exports.apiParamToTsCode = apiParamToTsCode; exports.apiParamTypeToTsType = apiParamTypeToTsType; exports.unwrapPromiseOnce = unwrapPromiseOnce; exports.serializeZodType = serializeZodType; exports.zodTypeToTsTypeDef = zodTypeToTsTypeDef; exports.registeredApis = registeredApis; exports.api = api; exports.SoException = SoException; exports.isSoException = isSoException; exports.BadRequestException = BadRequestException; exports.UnauthorizedException = UnauthorizedException; exports.NotFoundException = NotFoundException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.InternalServerErrorException = InternalServerErrorException; exports.AlreadyProcessedException = AlreadyProcessedException; exports.DuplicateRowException = DuplicateRowException; exports.TargetNotFoundException = TargetNotFoundException; exports.globAsync = globAsync; exports.importMultiple = importMultiple; exports.findAppRootPath = findAppRootPath; exports.findApiRootPath = findApiRootPath; exports.nonNullable = nonNullable; exports.hydrate = hydrate; exports.Entity = Entity; exports.EntityManager = EntityManager; exports.asArray = asArray; exports.objToMap = objToMap; exports.KnexClient = KnexClient; exports.KyselyClient = KyselyClient; exports.DBKnexClass = DBKnexClass; exports.DBKyselyClass = DBKyselyClass; exports.DB = DB; exports.Syncer = Syncer; exports.isLocal = isLocal; exports.isRemote = isRemote; exports.isInDocker = isInDocker; exports.isDaemonServer = isDaemonServer; exports.isDevelopment = isDevelopment; exports.isStaging = isStaging; exports.isProduction = isProduction; exports.isTest = isTest; exports.Sonamu = Sonamu;
7574
- //# sourceMappingURL=chunk-ZLFDB43J.js.map
7622
+
7623
+
7624
+ exports.SQLDateTimeString = SQLDateTimeString; exports.zArrayable = zArrayable; exports.isIntegerProp = isIntegerProp; exports.isBigIntegerProp = isBigIntegerProp; exports.isTextProp = isTextProp; exports.isStringProp = isStringProp; exports.isEnumProp = isEnumProp; exports.isFloatProp = isFloatProp; exports.isDoubleProp = isDoubleProp; exports.isDecimalProp = isDecimalProp; exports.isBooleanProp = isBooleanProp; exports.isDateProp = isDateProp; exports.isDateTimeProp = isDateTimeProp; exports.isTimeProp = isTimeProp; exports.isTimestampProp = isTimestampProp; exports.isJsonProp = isJsonProp; exports.isUuidProp = isUuidProp; exports.isVirtualProp = isVirtualProp; exports.isRelationProp = isRelationProp; exports.isOneToOneRelationProp = isOneToOneRelationProp; exports.isBelongsToOneRelationProp = isBelongsToOneRelationProp; exports.isHasManyRelationProp = isHasManyRelationProp; exports.isManyToManyRelationProp = isManyToManyRelationProp; exports.isCustomJoinClause = isCustomJoinClause; exports.SonamuQueryMode = SonamuQueryMode; exports.isKnexError = isKnexError; exports.isKyselyError = isKyselyError; exports.ApiParamType = ApiParamType; exports.RenderingNode = RenderingNode; exports.TemplateOptions = TemplateOptions; exports.TemplateKey = TemplateKey; exports.GenerateOptions = GenerateOptions; exports.PathAndCode = PathAndCode; exports.getZodObjectFromApi = getZodObjectFromApi; exports.getZodObjectFromApiParams = getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = getZodTypeFromApiParamType; exports.propNodeToZodTypeDef = propNodeToZodTypeDef; exports.getTextTypeLength = getTextTypeLength; exports.propToZodTypeDef = propToZodTypeDef; exports.zodTypeToZodCode = zodTypeToZodCode; exports.apiParamToTsCode = apiParamToTsCode; exports.apiParamToTsCodeAsObject = apiParamToTsCodeAsObject; exports.apiParamTypeToTsType = apiParamTypeToTsType; exports.unwrapPromiseOnce = unwrapPromiseOnce; exports.serializeZodType = serializeZodType; exports.zodTypeToTsTypeDef = zodTypeToTsTypeDef; exports.registeredApis = registeredApis; exports.api = api; exports.stream = stream; exports.SoException = SoException; exports.isSoException = isSoException; exports.BadRequestException = BadRequestException; exports.UnauthorizedException = UnauthorizedException; exports.NotFoundException = NotFoundException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.InternalServerErrorException = InternalServerErrorException; exports.AlreadyProcessedException = AlreadyProcessedException; exports.DuplicateRowException = DuplicateRowException; exports.TargetNotFoundException = TargetNotFoundException; exports.globAsync = globAsync; exports.importMultiple = importMultiple; exports.findAppRootPath = findAppRootPath; exports.findApiRootPath = findApiRootPath; exports.nonNullable = nonNullable; exports.hydrate = hydrate; exports.Entity = Entity; exports.EntityManager = EntityManager; exports.asArray = asArray; exports.objToMap = objToMap; exports.KnexClient = KnexClient; exports.KyselyClient = KyselyClient; exports.DBKnexClass = DBKnexClass; exports.DBKyselyClass = DBKyselyClass; exports.DB = DB; exports.Syncer = Syncer; exports.isLocal = isLocal; exports.isRemote = isRemote; exports.isInDocker = isInDocker; exports.isDaemonServer = isDaemonServer; exports.isDevelopment = isDevelopment; exports.isStaging = isStaging; exports.isProduction = isProduction; exports.isTest = isTest; exports.Sonamu = Sonamu;
7625
+ //# sourceMappingURL=chunk-2WAC2GER.js.map