sonamu 0.4.12 → 0.4.13

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/.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-FYLFH3Q6.js → chunk-CXAVBVKC.js} +100 -100
  7. package/dist/{chunk-JQJTQQ7D.mjs → chunk-DDJ7T4MA.mjs} +2 -2
  8. package/dist/{chunk-ZLFDB43J.js → chunk-DMJSNO2L.js} +104 -53
  9. package/dist/chunk-DMJSNO2L.js.map +1 -0
  10. package/dist/{chunk-INTZUNZ6.js → chunk-DYFCACHD.js} +7 -7
  11. package/dist/{chunk-IEMX4VPN.js → chunk-J6S43O7G.js} +4 -4
  12. package/dist/{chunk-FKZK27YL.mjs → chunk-NI37CY4T.mjs} +2 -2
  13. package/dist/{chunk-NPLUHS5L.mjs → chunk-NIFOTHBW.mjs} +2 -2
  14. package/dist/{chunk-LNZTU4JC.mjs → chunk-QJFHDCBN.mjs} +103 -52
  15. package/dist/chunk-QJFHDCBN.mjs.map +1 -0
  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/code-converters.ts +7 -0
  32. package/src/api/decorators.ts +36 -4
  33. package/src/shared/web.shared.ts.txt +225 -0
  34. package/src/syncer/syncer.ts +7 -1
  35. package/src/templates/service.template.ts +50 -9
  36. package/dist/chunk-LNZTU4JC.mjs.map +0 -1
  37. package/dist/chunk-ZLFDB43J.js.map +0 -1
  38. package/dist/{chunk-FYLFH3Q6.js.map → chunk-CXAVBVKC.js.map} +0 -0
  39. package/dist/{chunk-JQJTQQ7D.mjs.map → chunk-DDJ7T4MA.mjs.map} +0 -0
  40. package/dist/{chunk-INTZUNZ6.js.map → chunk-DYFCACHD.js.map} +0 -0
  41. package/dist/{chunk-IEMX4VPN.js.map → chunk-J6S43O7G.js.map} +0 -0
  42. package/dist/{chunk-FKZK27YL.mjs.map → chunk-NI37CY4T.mjs.map} +0 -0
  43. package/dist/{chunk-NPLUHS5L.mjs.map → chunk-NIFOTHBW.mjs.map} +0 -0
  44. package/dist/{model-DWoinpJ7.d.mts → model-aFgomcdc.d.mts} +4 -4
  45. package/dist/{model-DWoinpJ7.d.ts → model-aFgomcdc.d.ts} +4 -4
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkZLFDB43Jjs = require('./chunk-ZLFDB43J.js');
5
+ var _chunkDMJSNO2Ljs = require('./chunk-DMJSNO2L.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, _chunkZLFDB43Jjs.DB.toClient(trx));
23
+ await executeUpdate(chunk, _chunkDMJSNO2Ljs.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 _chunkZLFDB43Jjs.EntityManager.getTableSpec(tableName);
90
+ return _chunkDMJSNO2Ljs.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(_chunkZLFDB43Jjs.nonNullable);
122
+ }).filter(_chunkDMJSNO2Ljs.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 = _chunkZLFDB43Jjs.DB.toClient(_wdb);
183
+ const wdb = _chunkDMJSNO2Ljs.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
- _chunkZLFDB43Jjs.DB.toClient(wdb),
267
+ _chunkDMJSNO2Ljs.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-INTZUNZ6.js.map
280
+ //# sourceMappingURL=chunk-DYFCACHD.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
- var _chunkZLFDB43Jjs = require('./chunk-ZLFDB43J.js');
3
+ var _chunkDMJSNO2Ljs = require('./chunk-DMJSNO2L.js');
4
4
 
5
5
  // src/database/base-model.ts
6
6
  var _luxon = require('luxon');
@@ -53,8 +53,8 @@ var BaseModelClassAbstract = (_class = class {constructor() { _class.prototype._
53
53
  db: _db,
54
54
  optimizeCountQuery
55
55
  }) {
56
- const db = _nullishCoalesce(_db, () => ( _chunkZLFDB43Jjs.DB.getDB(subset.startsWith("A") ? "w" : "r")));
57
- const dbClient = _chunkZLFDB43Jjs.DB.toClient(db);
56
+ const db = _nullishCoalesce(_db, () => ( _chunkDMJSNO2Ljs.DB.getDB(subset.startsWith("A") ? "w" : "r")));
57
+ const dbClient = _chunkDMJSNO2Ljs.DB.toClient(db);
58
58
  baseTable = _nullishCoalesce(baseTable, () => ( _inflection2.default.pluralize(_inflection2.default.underscore(this.modelName))));
59
59
  const queryMode = _nullishCoalesce(params.queryMode, () => ( (params.id !== void 0 ? "list" : "both")));
60
60
  const { select, virtual, joins, loaders } = subsetQuery;
@@ -228,4 +228,4 @@ var BaseModelClassAbstract = (_class = class {constructor() { _class.prototype._
228
228
 
229
229
 
230
230
  exports.BaseModelClassAbstract = BaseModelClassAbstract;
231
- //# sourceMappingURL=chunk-IEMX4VPN.js.map
231
+ //# sourceMappingURL=chunk-J6S43O7G.js.map
@@ -16,7 +16,7 @@ import {
16
16
  isStringProp,
17
17
  isTextProp,
18
18
  isVirtualProp
19
- } from "./chunk-LNZTU4JC.mjs";
19
+ } from "./chunk-QJFHDCBN.mjs";
20
20
 
21
21
  // src/entity/migrator.ts
22
22
  import _ from "lodash";
@@ -1578,4 +1578,4 @@ export {
1578
1578
  FixtureManagerClass,
1579
1579
  FixtureManager
1580
1580
  };
1581
- //# sourceMappingURL=chunk-FKZK27YL.mjs.map
1581
+ //# sourceMappingURL=chunk-NI37CY4T.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  DB,
3
3
  EntityManager,
4
4
  nonNullable
5
- } from "./chunk-LNZTU4JC.mjs";
5
+ } from "./chunk-QJFHDCBN.mjs";
6
6
 
7
7
  // src/database/upsert-builder.ts
8
8
  import { v4 as uuidv4 } from "uuid";
@@ -277,4 +277,4 @@ export {
277
277
  isRefField,
278
278
  UpsertBuilder
279
279
  };
280
- //# sourceMappingURL=chunk-NPLUHS5L.mjs.map
280
+ //# sourceMappingURL=chunk-NIFOTHBW.mjs.map
@@ -564,6 +564,9 @@ function apiParamToTsCode(params, injectImportKeys) {
564
564
  return `${param.name}${param.optional && !param.defaultDef ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`;
565
565
  }).join(", ");
566
566
  }
567
+ function apiParamToTsCodeAsObject(params, injectImportKeys) {
568
+ return `{ ${params.map((param) => `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`).join(", ")} }`;
569
+ }
567
570
  function apiParamTypeToTsType(paramType, injectImportKeys) {
568
571
  if ([
569
572
  "string",
@@ -778,13 +781,32 @@ function api(options = {}) {
778
781
  modelName.replace(/Model$/, "").replace(/Frame$/, ""),
779
782
  true
780
783
  )}/${inflection.camelize(propertyKey, true)}`;
781
- const api2 = {
784
+ registeredApis.push({
782
785
  modelName,
783
786
  methodName,
784
787
  path: options.path ?? defaultPath,
785
788
  options
786
- };
787
- registeredApis.push(api2);
789
+ });
790
+ };
791
+ }
792
+ function stream(options) {
793
+ return function(target, propertyKey) {
794
+ const modelName = target.constructor.name.match(/(.+)Class$/)[1];
795
+ const methodName = propertyKey;
796
+ const defaultPath = `/${inflection.camelize(
797
+ modelName.replace(/Model$/, "").replace(/Frame$/, ""),
798
+ true
799
+ )}/${inflection.camelize(propertyKey, true)}`;
800
+ registeredApis.push({
801
+ modelName,
802
+ methodName,
803
+ path: options.path ?? defaultPath,
804
+ options: {
805
+ ...options,
806
+ httpMethod: "GET"
807
+ },
808
+ streamOptions: options
809
+ });
788
810
  };
789
811
  }
790
812
 
@@ -4030,7 +4052,7 @@ var Template__service = class extends Template {
4030
4052
  `import { z } from 'zod';`,
4031
4053
  `import qs from "qs";`,
4032
4054
  `import useSWR, { SWRResponse } from "swr";`,
4033
- `import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher } from '../sonamu.shared';`,
4055
+ `import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher, EventHandlers, SSEStreamOptions, useSSEStream } from '../sonamu.shared';`,
4034
4056
  ...hasAxiosProgressEvent ? [`import { AxiosProgressEvent } from 'axios';`] : []
4035
4057
  ]
4036
4058
  };
@@ -4056,57 +4078,65 @@ var Template__service = class extends Template {
4056
4078
  paramsWithoutContext,
4057
4079
  importKeys
4058
4080
  );
4081
+ const paramsDefAsObject = apiParamToTsCodeAsObject(
4082
+ paramsWithoutContext,
4083
+ importKeys
4084
+ );
4059
4085
  const returnTypeDef = apiParamTypeToTsType(
4060
4086
  unwrapPromiseOnce(api2.returnType),
4061
4087
  importKeys
4062
4088
  );
4063
4089
  const payloadDef = `{ ${paramsWithoutContext.map((param) => param.name).join(", ")} }`;
4064
- return _9.sortBy(
4065
- api2.options.clients,
4066
- (client) => client === "swr" ? 0 : 1
4067
- ).map((client) => {
4068
- const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
4069
- switch (client) {
4070
- case "axios":
4071
- return this.renderAxios(
4072
- api2,
4073
- apiBaseUrl,
4074
- typeParamsDef,
4075
- paramsDef,
4076
- returnTypeDef,
4077
- payloadDef
4078
- );
4079
- case "axios-multipart":
4080
- return this.renderAxiosMultipart(
4081
- api2,
4082
- apiBaseUrl,
4083
- typeParamsDef,
4084
- paramsDef,
4085
- returnTypeDef,
4086
- paramsWithoutContext
4087
- );
4088
- case "swr":
4089
- return this.renderSwr(
4090
- api2,
4091
- apiBaseUrl,
4092
- typeParamsDef,
4093
- paramsDef,
4094
- returnTypeDef,
4095
- payloadDef
4096
- );
4097
- case "window-fetch":
4098
- return this.renderWindowFetch(
4099
- api2,
4100
- apiBaseUrl,
4101
- typeParamsDef,
4102
- paramsDef,
4103
- payloadDef
4104
- );
4105
- case "socketio":
4106
- default:
4107
- return `// Not supported ${inflection4.camelize(client, true)} yet.`;
4108
- }
4109
- }).join("\n");
4090
+ const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
4091
+ return [
4092
+ // 클라이언트별로 생성
4093
+ ..._9.sortBy(
4094
+ api2.options.clients,
4095
+ (client) => client === "swr" ? 0 : 1
4096
+ ).map((client) => {
4097
+ switch (client) {
4098
+ case "axios":
4099
+ return this.renderAxios(
4100
+ api2,
4101
+ apiBaseUrl,
4102
+ typeParamsDef,
4103
+ paramsDef,
4104
+ returnTypeDef,
4105
+ payloadDef
4106
+ );
4107
+ case "axios-multipart":
4108
+ return this.renderAxiosMultipart(
4109
+ api2,
4110
+ apiBaseUrl,
4111
+ typeParamsDef,
4112
+ paramsDef,
4113
+ returnTypeDef,
4114
+ paramsWithoutContext
4115
+ );
4116
+ case "swr":
4117
+ return this.renderSwr(
4118
+ api2,
4119
+ apiBaseUrl,
4120
+ typeParamsDef,
4121
+ paramsDef,
4122
+ returnTypeDef,
4123
+ payloadDef
4124
+ );
4125
+ case "window-fetch":
4126
+ return this.renderWindowFetch(
4127
+ api2,
4128
+ apiBaseUrl,
4129
+ typeParamsDef,
4130
+ paramsDef,
4131
+ payloadDef
4132
+ );
4133
+ default:
4134
+ return `// Not supported ${inflection4.camelize(client, true)} yet.`;
4135
+ }
4136
+ }),
4137
+ // 스트리밍인 경우
4138
+ ...api2.streamOptions ? [this.renderStream(api2, apiBaseUrl, paramsDefAsObject)] : []
4139
+ ].join("\n");
4110
4140
  }).join("\n\n");
4111
4141
  return `export namespace ${modelName.replace(/Model$/, "Service").replace(/Frame$/, "Service")} {
4112
4142
  ${methodCodes}
@@ -4187,6 +4217,23 @@ export async function ${api2.methodName}${typeParamsDef}(${paramsDef}): Promise<
4187
4217
  }
4188
4218
  `.trim();
4189
4219
  }
4220
+ renderStream(api2, apiBaseUrl, paramsDefAsObject) {
4221
+ if (!api2.streamOptions) {
4222
+ return "// streamOptions not found";
4223
+ }
4224
+ const methodNameStream = api2.options.resourceName ? "use" + inflection4.camelize(api2.options.resourceName) : "use" + inflection4.camelize(api2.methodName);
4225
+ const methodNameStreamCamelized = inflection4.camelize(
4226
+ methodNameStream,
4227
+ true
4228
+ );
4229
+ const eventsTypeDef = zodTypeToTsTypeDef(api2.streamOptions.events);
4230
+ return ` export function ${methodNameStreamCamelized}(
4231
+ params: ${paramsDefAsObject},
4232
+ handlers: EventHandlers<${eventsTypeDef} & { end?: () => void }>,
4233
+ options: SSEStreamOptions) {
4234
+ return useSSEStream<${eventsTypeDef}>(\`${apiBaseUrl}\`, params, handlers, options);
4235
+ }`;
4236
+ }
4190
4237
  };
4191
4238
 
4192
4239
  // src/templates/view_form.template.ts
@@ -5298,9 +5345,10 @@ var Syncer = class {
5298
5345
  }
5299
5346
  async sync() {
5300
5347
  const { targets } = Sonamu.config.sync;
5348
+ const currentDirname = __dirname.endsWith("/syncer") ? __dirname : path5.join(__dirname, "./syncer");
5301
5349
  await Promise.all(
5302
5350
  targets.map(async (target) => {
5303
- const srcCodePath = path5.join(__dirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
5351
+ const srcCodePath = path5.join(currentDirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
5304
5352
  if (!fs2.existsSync(srcCodePath)) {
5305
5353
  return;
5306
5354
  }
@@ -5320,6 +5368,7 @@ var Syncer = class {
5320
5368
  return;
5321
5369
  }
5322
5370
  fs2.writeFileSync(dstCodePath, fs2.readFileSync(srcCodePath));
5371
+ console.log(chalk.blue("shared.ts is synced"));
5323
5372
  })
5324
5373
  );
5325
5374
  let currentChecksums = await this.getCurrentChecksums();
@@ -7527,12 +7576,14 @@ export {
7527
7576
  propToZodTypeDef,
7528
7577
  zodTypeToZodCode,
7529
7578
  apiParamToTsCode,
7579
+ apiParamToTsCodeAsObject,
7530
7580
  apiParamTypeToTsType,
7531
7581
  unwrapPromiseOnce,
7532
7582
  serializeZodType,
7533
7583
  zodTypeToTsTypeDef,
7534
7584
  registeredApis,
7535
7585
  api,
7586
+ stream,
7536
7587
  SoException,
7537
7588
  isSoException,
7538
7589
  BadRequestException,
@@ -7569,4 +7620,4 @@ export {
7569
7620
  isTest,
7570
7621
  Sonamu
7571
7622
  };
7572
- //# sourceMappingURL=chunk-LNZTU4JC.mjs.map
7623
+ //# sourceMappingURL=chunk-QJFHDCBN.mjs.map