sonamu 0.0.41 → 0.1.0

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 (219) hide show
  1. package/.pnp.cjs +1968 -956
  2. package/.pnp.loader.mjs +1816 -54
  3. package/.yarnrc.yml +1 -1
  4. package/dist/api/caster.d.ts +2 -4
  5. package/dist/api/caster.d.ts.map +1 -1
  6. package/dist/api/code-converters.d.ts +3 -3
  7. package/dist/api/code-converters.d.ts.map +1 -1
  8. package/dist/api/code-converters.js +5 -15
  9. package/dist/api/code-converters.js.map +1 -1
  10. package/dist/api/context.d.ts +1 -1
  11. package/dist/api/context.d.ts.map +1 -1
  12. package/dist/api/decorators.d.ts +3 -3
  13. package/dist/api/decorators.d.ts.map +1 -1
  14. package/dist/api/sonamu.d.ts +3 -3
  15. package/dist/api/sonamu.d.ts.map +1 -1
  16. package/dist/api/sonamu.js +6 -6
  17. package/dist/api/sonamu.js.map +1 -1
  18. package/dist/bin/cli.js +240 -26
  19. package/dist/bin/cli.js.map +1 -1
  20. package/dist/database/db.d.ts +2 -2
  21. package/dist/database/db.d.ts.map +1 -1
  22. package/dist/database/db.js +1 -1
  23. package/dist/database/db.js.map +1 -1
  24. package/dist/database/upsert-builder.d.ts +2 -2
  25. package/dist/database/upsert-builder.d.ts.map +1 -1
  26. package/dist/database/upsert-builder.js +10 -8
  27. package/dist/database/upsert-builder.js.map +1 -1
  28. package/dist/entity/entity-manager.d.ts +29 -0
  29. package/dist/entity/entity-manager.d.ts.map +1 -0
  30. package/dist/entity/entity-manager.js +128 -0
  31. package/dist/entity/entity-manager.js.map +1 -0
  32. package/dist/entity/entity-utils.d.ts +61 -0
  33. package/dist/entity/entity-utils.d.ts.map +1 -0
  34. package/dist/entity/entity-utils.js +121 -0
  35. package/dist/entity/entity-utils.js.map +1 -0
  36. package/dist/entity/entity.d.ts +49 -0
  37. package/dist/entity/entity.d.ts.map +1 -0
  38. package/dist/entity/entity.js +504 -0
  39. package/dist/entity/entity.js.map +1 -0
  40. package/dist/entity/migrator.d.ts +143 -0
  41. package/dist/entity/migrator.d.ts.map +1 -0
  42. package/dist/entity/migrator.js +1385 -0
  43. package/dist/entity/migrator.js.map +1 -0
  44. package/dist/entity/smd-utils.d.ts +61 -0
  45. package/dist/entity/smd-utils.d.ts.map +1 -0
  46. package/dist/entity/smd-utils.js +121 -0
  47. package/dist/entity/smd-utils.js.map +1 -0
  48. package/dist/index.d.ts +3 -3
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +3 -3
  51. package/dist/index.js.map +1 -1
  52. package/dist/smd/entity-manager.d.ts +28 -0
  53. package/dist/smd/entity-manager.d.ts.map +1 -0
  54. package/dist/smd/entity-manager.js +119 -0
  55. package/dist/smd/entity-manager.js.map +1 -0
  56. package/dist/smd/entity.d.ts +40 -0
  57. package/dist/smd/entity.d.ts.map +1 -0
  58. package/dist/smd/entity.js +430 -0
  59. package/dist/smd/entity.js.map +1 -0
  60. package/dist/smd/migrator.d.ts +2 -2
  61. package/dist/smd/migrator.d.ts.map +1 -1
  62. package/dist/smd/migrator.js +5 -5
  63. package/dist/smd/migrator.js.map +1 -1
  64. package/dist/smd/smd-manager.d.ts +3 -3
  65. package/dist/smd/smd-manager.d.ts.map +1 -1
  66. package/dist/smd/smd-manager.js +2 -2
  67. package/dist/smd/smd-manager.js.map +1 -1
  68. package/dist/smd/smd-utils.d.ts +4 -4
  69. package/dist/smd/smd-utils.d.ts.map +1 -1
  70. package/dist/smd/smd-utils.js.map +1 -1
  71. package/dist/smd/smd.d.ts +5 -6
  72. package/dist/smd/smd.d.ts.map +1 -1
  73. package/dist/smd/smd.js +3 -3
  74. package/dist/smd/smd.js.map +1 -1
  75. package/dist/syncer/syncer.d.ts +15 -11
  76. package/dist/syncer/syncer.d.ts.map +1 -1
  77. package/dist/syncer/syncer.js +134 -74
  78. package/dist/syncer/syncer.js.map +1 -1
  79. package/dist/templates/base-template.d.ts +2 -2
  80. package/dist/templates/base-template.d.ts.map +1 -1
  81. package/dist/templates/entity.template.d.ts +17 -0
  82. package/dist/templates/entity.template.d.ts.map +1 -0
  83. package/dist/templates/entity.template.js +46 -0
  84. package/dist/templates/entity.template.js.map +1 -0
  85. package/dist/templates/generated.template.d.ts +11 -7
  86. package/dist/templates/generated.template.d.ts.map +1 -1
  87. package/dist/templates/generated.template.js +72 -43
  88. package/dist/templates/generated.template.js.map +1 -1
  89. package/dist/templates/generated_http.template.d.ts +3 -3
  90. package/dist/templates/generated_http.template.d.ts.map +1 -1
  91. package/dist/templates/generated_http.template.js +3 -3
  92. package/dist/templates/generated_http.template.js.map +1 -1
  93. package/dist/templates/init_enums.template.d.ts +2 -2
  94. package/dist/templates/init_enums.template.d.ts.map +1 -1
  95. package/dist/templates/init_enums.template.js +2 -2
  96. package/dist/templates/init_enums.template.js.map +1 -1
  97. package/dist/templates/init_generated.template.d.ts +3 -3
  98. package/dist/templates/init_generated.template.d.ts.map +1 -1
  99. package/dist/templates/init_generated.template.js +13 -14
  100. package/dist/templates/init_generated.template.js.map +1 -1
  101. package/dist/templates/init_types.template.d.ts +3 -3
  102. package/dist/templates/init_types.template.d.ts.map +1 -1
  103. package/dist/templates/init_types.template.js +10 -10
  104. package/dist/templates/init_types.template.js.map +1 -1
  105. package/dist/templates/model.template.d.ts +3 -3
  106. package/dist/templates/model.template.d.ts.map +1 -1
  107. package/dist/templates/model.template.js +28 -28
  108. package/dist/templates/model.template.js.map +1 -1
  109. package/dist/templates/model_test.template.d.ts +3 -3
  110. package/dist/templates/model_test.template.d.ts.map +1 -1
  111. package/dist/templates/model_test.template.js +4 -4
  112. package/dist/templates/model_test.template.js.map +1 -1
  113. package/dist/templates/service.template.d.ts +3 -3
  114. package/dist/templates/service.template.d.ts.map +1 -1
  115. package/dist/templates/service.template.js +3 -3
  116. package/dist/templates/service.template.js.map +1 -1
  117. package/dist/templates/smd.template.d.ts +2 -2
  118. package/dist/templates/smd.template.d.ts.map +1 -1
  119. package/dist/templates/smd.template.js +2 -2
  120. package/dist/templates/smd.template.js.map +1 -1
  121. package/dist/templates/view_enums_buttonset.template.d.ts +3 -3
  122. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -1
  123. package/dist/templates/view_enums_buttonset.template.js +4 -4
  124. package/dist/templates/view_enums_buttonset.template.js.map +1 -1
  125. package/dist/templates/view_enums_dropdown.template.d.ts +3 -3
  126. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -1
  127. package/dist/templates/view_enums_dropdown.template.js +3 -3
  128. package/dist/templates/view_enums_dropdown.template.js.map +1 -1
  129. package/dist/templates/view_enums_select.template.d.ts +3 -3
  130. package/dist/templates/view_enums_select.template.d.ts.map +1 -1
  131. package/dist/templates/view_enums_select.template.js +3 -3
  132. package/dist/templates/view_enums_select.template.js.map +1 -1
  133. package/dist/templates/view_form.template.d.ts +25 -29
  134. package/dist/templates/view_form.template.d.ts.map +1 -1
  135. package/dist/templates/view_form.template.js +19 -19
  136. package/dist/templates/view_form.template.js.map +1 -1
  137. package/dist/templates/view_id_all_select.template.d.ts +3 -3
  138. package/dist/templates/view_id_all_select.template.d.ts.map +1 -1
  139. package/dist/templates/view_id_all_select.template.js +4 -4
  140. package/dist/templates/view_id_all_select.template.js.map +1 -1
  141. package/dist/templates/view_id_async_select.template.d.ts +3 -3
  142. package/dist/templates/view_id_async_select.template.d.ts.map +1 -1
  143. package/dist/templates/view_id_async_select.template.js +6 -6
  144. package/dist/templates/view_id_async_select.template.js.map +1 -1
  145. package/dist/templates/view_list.template.d.ts +30 -34
  146. package/dist/templates/view_list.template.d.ts.map +1 -1
  147. package/dist/templates/view_list.template.js +40 -40
  148. package/dist/templates/view_list.template.js.map +1 -1
  149. package/dist/templates/view_list_columns.template.d.ts +3 -3
  150. package/dist/templates/view_list_columns.template.d.ts.map +1 -1
  151. package/dist/templates/view_list_columns.template.js +3 -3
  152. package/dist/templates/view_list_columns.template.js.map +1 -1
  153. package/dist/templates/view_search_input.template.d.ts +3 -3
  154. package/dist/templates/view_search_input.template.d.ts.map +1 -1
  155. package/dist/templates/view_search_input.template.js +3 -3
  156. package/dist/templates/view_search_input.template.js.map +1 -1
  157. package/dist/testing/fixture-manager.d.ts +2 -3
  158. package/dist/testing/fixture-manager.d.ts.map +1 -1
  159. package/dist/testing/fixture-manager.js +21 -42
  160. package/dist/testing/fixture-manager.js.map +1 -1
  161. package/dist/types/smd.types.d.ts +741 -0
  162. package/dist/types/smd.types.d.ts.map +1 -0
  163. package/dist/types/smd.types.js +292 -0
  164. package/dist/types/smd.types.js.map +1 -0
  165. package/dist/types/types.d.ts +185 -190
  166. package/dist/types/types.d.ts.map +1 -1
  167. package/dist/types/types.js +22 -30
  168. package/dist/types/types.js.map +1 -1
  169. package/dist/ui/index.d.ts +4 -0
  170. package/dist/ui/index.d.ts.map +1 -0
  171. package/dist/ui/index.js +14 -0
  172. package/dist/ui/index.js.map +1 -0
  173. package/dist/ui/main.d.ts +4 -0
  174. package/dist/ui/main.d.ts.map +1 -0
  175. package/dist/ui/main.js +15 -0
  176. package/dist/ui/main.js.map +1 -0
  177. package/dist/utils/model.d.ts +2 -2
  178. package/dist/utils/model.d.ts.map +1 -1
  179. package/dist/utils/utils.d.ts +1 -0
  180. package/dist/utils/utils.d.ts.map +1 -1
  181. package/dist/utils/utils.js +6 -2
  182. package/dist/utils/utils.js.map +1 -1
  183. package/package.json +11 -8
  184. package/src/api/code-converters.ts +9 -17
  185. package/src/api/sonamu.ts +10 -6
  186. package/src/bin/cli.ts +247 -26
  187. package/src/database/upsert-builder.ts +2 -2
  188. package/src/entity/entity-manager.ts +150 -0
  189. package/src/{smd/smd-utils.ts → entity/entity-utils.ts} +4 -7
  190. package/src/entity/entity.ts +666 -0
  191. package/src/{smd → entity}/migrator.ts +426 -106
  192. package/src/index.ts +3 -3
  193. package/src/smd/smd-manager.ts +3 -13
  194. package/src/smd/smd.ts +13 -10
  195. package/src/syncer/syncer.ts +125 -73
  196. package/src/templates/base-template.ts +2 -2
  197. package/src/templates/entity.template.ts +50 -0
  198. package/src/templates/generated.template.ts +93 -57
  199. package/src/templates/generated_http.template.ts +4 -4
  200. package/src/templates/init_types.template.ts +11 -11
  201. package/src/templates/model.template.ts +29 -29
  202. package/src/templates/model_test.template.ts +5 -5
  203. package/src/templates/service.template.ts +4 -4
  204. package/src/templates/view_enums_buttonset.template.ts +5 -5
  205. package/src/templates/view_enums_dropdown.template.ts +4 -4
  206. package/src/templates/view_enums_select.template.ts +8 -4
  207. package/src/templates/view_form.template.ts +21 -21
  208. package/src/templates/view_id_all_select.template.ts +5 -5
  209. package/src/templates/view_id_async_select.template.ts +9 -7
  210. package/src/templates/view_list.template.ts +54 -44
  211. package/src/templates/view_list_columns.template.ts +4 -4
  212. package/src/templates/view_search_input.template.ts +4 -4
  213. package/src/testing/fixture-manager.ts +19 -60
  214. package/src/types/types.ts +59 -41
  215. package/src/utils/utils.ts +4 -0
  216. package/tsconfig.json +4 -1
  217. package/src/templates/init_enums.template.ts +0 -71
  218. package/src/templates/init_generated.template.ts +0 -51
  219. package/src/templates/smd.template.ts +0 -53
@@ -1,10 +1,9 @@
1
1
  import chalk from "chalk";
2
- import { execSync } from "child_process";
3
2
  import knex, { Knex } from "knex";
4
3
  import { uniq } from "lodash";
5
4
  import { Sonamu } from "../api";
6
5
  import { BaseModel } from "../database/base-model";
7
- import { SMDManager } from "../smd/smd-manager";
6
+ import { EntityManager } from "../entity/entity-manager";
8
7
  import {
9
8
  isBelongsToOneRelationProp,
10
9
  isOneToOneRelationProp,
@@ -44,10 +43,14 @@ export class FixtureManagerClass {
44
43
  const pConn = Sonamu.dbConfig.production_master
45
44
  .connection as Knex.ConnectionConfig & { port?: number };
46
45
  if (
47
- `${tConn.host ?? "localhost"}:${tConn.port ?? 3306}` ===
48
- `${pConn.host ?? "localhost"}:${pConn.port ?? 3306}`
46
+ `${tConn.host ?? "localhost"}:${tConn.port ?? 3306}/${
47
+ tConn.database
48
+ }` ===
49
+ `${pConn.host ?? "localhost"}:${pConn.port ?? 3306}/${pConn.database}`
49
50
  ) {
50
- throw new Error("테스트DB와 프로덕션DB의 접속 정보가 동일합니다.");
51
+ throw new Error(
52
+ `테스트DB와 프로덕션DB에 동일한 데이터베이스가 사용되었습니다.`
53
+ );
51
54
  }
52
55
  }
53
56
 
@@ -102,50 +105,6 @@ export class FixtureManagerClass {
102
105
  // console.timeEnd("FIXTURE-CleanAndSeed");
103
106
  }
104
107
 
105
- // TODO: 추후 작업
106
- async initFixtureDB() {
107
- const connectArgs = `-uDB_USER -pDB_PASS`;
108
-
109
- console.log("DUMP...");
110
- execSync(
111
- `mysqldump -hwdb.closedshops.com ${connectArgs} --single-transaction -d --no-create-db --triggers --ignore-table=closedshops.pm_backup closedshops > /tmp/closedshops_scheme.sql`
112
- );
113
- console.log("SYNC to (TESTING) LOCAL closedshops...");
114
- execSync(
115
- `mysql -hlocal.closedshops.com ${connectArgs} -e 'DROP DATABASE closedshops'`
116
- );
117
- execSync(
118
- `mysql -hlocal.closedshops.com ${connectArgs} -e 'CREATE DATABASE closedshops'`
119
- );
120
- execSync(
121
- `mysql -hlocal.closedshops.com ${connectArgs} closedshops < /tmp/closedshops_scheme.sql;`
122
- );
123
- console.log("SED database names...");
124
- execSync(
125
- `sed -i'' -e 's/\`closedshops\`/\`closedshops_fixture\`/g' /tmp/closedshops_scheme.sql`
126
- );
127
- console.log("SYNC to (REMOTE FIXTURE) REMOTE closedshops_fixture...");
128
- execSync(
129
- `mysql -hwdb.closedshops.com ${connectArgs} -e 'DROP DATABASE closedshops_fixture'`
130
- );
131
- execSync(
132
- `mysql -hwdb.closedshops.com ${connectArgs} -e 'CREATE DATABASE closedshops_fixture'`
133
- );
134
- execSync(
135
- `mysql -hwdb.closedshops.com ${connectArgs} closedshops_fixture < /tmp/closedshops_scheme.sql;`
136
- );
137
- console.log("SYNC to (LOCAL FIXTURE) closedshops_fixture...");
138
- execSync(
139
- `mysql -hlocal.closedshops.com ${connectArgs} -e 'DROP DATABASE closedshops_fixture'`
140
- );
141
- execSync(
142
- `mysql -hlocal.closedshops.com ${connectArgs} -e 'CREATE DATABASE closedshops_fixture'`
143
- );
144
- execSync(
145
- `mysql -hlocal.closedshops.com ${connectArgs} closedshops_fixture < /tmp/closedshops_scheme.sql;`
146
- );
147
- }
148
-
149
108
  async getChecksum(db: Knex, tableName: string) {
150
109
  const [[checksumRow]] = await db.raw(`CHECKSUM TABLE ${tableName}`);
151
110
  return checksumRow.Checksum;
@@ -201,12 +160,12 @@ export class FixtureManagerClass {
201
160
  await frdb.destroy();
202
161
  }
203
162
 
204
- async importFixture(smdId: string, ids: number[]) {
163
+ async importFixture(entityId: string, ids: number[]) {
205
164
  const queries = uniq(
206
165
  (
207
166
  await Promise.all(
208
167
  ids.map(async (id) => {
209
- return await this.getImportQueries(smdId, "id", id);
168
+ return await this.getImportQueries(entityId, "id", id);
210
169
  })
211
170
  )
212
171
  ).flat()
@@ -223,18 +182,18 @@ export class FixtureManagerClass {
223
182
  }
224
183
 
225
184
  async getImportQueries(
226
- smdId: string,
185
+ entityId: string,
227
186
  field: string,
228
187
  id: number
229
188
  ): Promise<string[]> {
230
- console.log({ smdId, field, id });
231
- const smd = SMDManager.get(smdId);
189
+ console.log({ entityId, field, id });
190
+ const entity = EntityManager.get(entityId);
232
191
  const wdb = BaseModel.getDB("w");
233
192
 
234
193
  // 여기서 실DB의 row 가져옴
235
- const [row] = await wdb(smd.table).where(field, id).limit(1);
194
+ const [row] = await wdb(entity.table).where(field, id).limit(1);
236
195
  if (row === undefined) {
237
- throw new Error(`${smdId}#${id} row를 찾을 수 없습니다.`);
196
+ throw new Error(`${entityId}#${id} row를 찾을 수 없습니다.`);
238
197
  }
239
198
 
240
199
  // 픽스쳐DB, 실DB
@@ -243,9 +202,9 @@ export class FixtureManagerClass {
243
202
  const realDatabase = (Sonamu.dbConfig.production_master.connection as any)
244
203
  .database;
245
204
 
246
- const selfQuery = `INSERT IGNORE INTO \`${fixtureDatabase}\`.\`${smd.table}\` (SELECT * FROM \`${realDatabase}\`.\`${smd.table}\` WHERE \`id\` = ${id})`;
205
+ const selfQuery = `INSERT IGNORE INTO \`${fixtureDatabase}\`.\`${entity.table}\` (SELECT * FROM \`${realDatabase}\`.\`${entity.table}\` WHERE \`id\` = ${id})`;
247
206
 
248
- const args = Object.entries(smd.relations)
207
+ const args = Object.entries(entity.relations)
249
208
  .filter(
250
209
  ([, relation]) =>
251
210
  isBelongsToOneRelationProp(relation) ||
@@ -271,7 +230,7 @@ export class FixtureManagerClass {
271
230
  id = row[`${relation.name}_id`];
272
231
  }
273
232
  return {
274
- smdId: relation.with,
233
+ entityId: relation.with,
275
234
  field,
276
235
  id,
277
236
  };
@@ -280,7 +239,7 @@ export class FixtureManagerClass {
280
239
 
281
240
  const relQueries = await Promise.all(
282
241
  args.map(async (args) => {
283
- return this.getImportQueries(args.smdId, args.field, args.id);
242
+ return this.getImportQueries(args.entityId, args.field, args.id);
284
243
  })
285
244
  );
286
245
 
@@ -39,8 +39,6 @@ export type DistributiveOmit<T, K extends keyof any> = T extends any
39
39
  export type CommonProp = {
40
40
  name: string;
41
41
  nullable?: boolean;
42
- index?: true | string[];
43
- unique?: true | string[];
44
42
  toFilter?: true;
45
43
  desc?: string;
46
44
  dbDefault?: string | number | { raw: string };
@@ -99,14 +97,14 @@ export type TimestampProp = CommonProp & {
99
97
  };
100
98
  export type JsonProp = CommonProp & {
101
99
  type: "json";
102
- as: { ref: string } | z.ZodTypeAny;
100
+ id: string;
103
101
  };
104
102
  export type UuidProp = CommonProp & {
105
103
  type: "uuid";
106
104
  };
107
105
  export type VirtualProp = CommonProp & {
108
106
  type: "virtual";
109
- as: { ref: string } | z.ZodTypeAny;
107
+ id: string;
110
108
  };
111
109
 
112
110
  export type RelationType =
@@ -164,7 +162,7 @@ export type RelationProp =
164
162
  | HasManyRelationProp
165
163
  | ManyToManyRelationProp;
166
164
 
167
- export type SMDProp =
165
+ export type EntityProp =
168
166
  | IntegerProp
169
167
  | BigIntegerProp
170
168
  | TextProp
@@ -183,19 +181,47 @@ export type SMDProp =
183
181
  | VirtualProp
184
182
  | RelationProp;
185
183
 
186
- export type SMDIndex = {
184
+ export type EntityIndex = {
187
185
  type: "index" | "unique";
188
186
  columns: string[];
189
187
  name?: string;
190
188
  };
189
+ export type EntityJson = {
190
+ id: string;
191
+ parentId?: string;
192
+ table: string;
193
+ title?: string;
194
+ props: EntityProp[];
195
+ indexes: EntityIndex[];
196
+ subsets: {
197
+ [subset: string]: string[];
198
+ };
199
+ enums: {
200
+ [enumId: string]: {
201
+ [key: string]: string;
202
+ };
203
+ };
204
+ };
205
+ export type EntitySubsetRow = {
206
+ field: string;
207
+ has: {
208
+ [key: string]: boolean;
209
+ };
210
+ children: EntitySubsetRow[];
211
+ prefixes: string[];
212
+ relationEntity?: string;
213
+ isOpen?: boolean;
214
+ };
215
+ export type FlattenSubsetRow = Omit<EntitySubsetRow, "children">;
191
216
 
217
+ // SMD Legacy
192
218
  export type SMDInput<T extends string> = {
193
219
  id: string;
194
220
  parentId?: string;
195
221
  table?: string;
196
222
  title?: string;
197
- props?: SMDProp[];
198
- indexes?: SMDIndex[];
223
+ props?: EntityProp[];
224
+ indexes?: EntityIndex[];
199
225
  subsets?: {
200
226
  [subset: string]: T[];
201
227
  };
@@ -205,15 +231,15 @@ export type SMDInput<T extends string> = {
205
231
  PropNode
206
232
  */
207
233
 
208
- export type SMDPropNode =
234
+ export type EntityPropNode =
209
235
  | {
210
236
  nodeType: "plain";
211
- prop: SMDProp;
237
+ prop: EntityProp;
212
238
  }
213
239
  | {
214
240
  nodeType: "object" | "array";
215
- prop?: SMDProp;
216
- children: SMDPropNode[];
241
+ prop?: EntityProp;
242
+ children: EntityPropNode[];
217
243
  };
218
244
 
219
245
  /*
@@ -576,47 +602,41 @@ export type RenderingNode = {
576
602
  };
577
603
 
578
604
  export const TemplateOptions = z.object({
579
- smd: z.object({
580
- smdId: z.string(),
605
+ entity: z.object({
606
+ entityId: z.string(),
607
+ parentId: z.string().optional(),
581
608
  title: z.string(),
582
- refCode: z.string().optional(),
583
- }),
584
- init_enums: z.object({
585
- smdId: z.string(),
586
- def: z.record(z.record(z.string())).optional(),
609
+ table: z.string().optional(),
587
610
  }),
588
611
  init_types: z.object({
589
- smdId: z.string(),
590
- }),
591
- init_generated: z.object({
592
- smdId: z.string(),
612
+ entityId: z.string(),
593
613
  }),
594
614
  generated: z.object({
595
- smdId: z.string(),
615
+ entityId: z.string(),
596
616
  }),
597
617
  generated_http: z.object({
598
- smdId: z.string(),
618
+ entityId: z.string(),
599
619
  }),
600
620
  model: z.object({
601
- smdId: z.string(),
621
+ entityId: z.string(),
602
622
  defaultSearchField: z.string(),
603
623
  defaultOrderBy: z.string(),
604
624
  }),
605
625
  model_test: z.object({
606
- smdId: z.string(),
626
+ entityId: z.string(),
607
627
  }),
608
628
  bridge: z.object({
609
- smdId: z.string(),
629
+ entityId: z.string(),
610
630
  }),
611
631
  service: z.object({
612
- smdId: z.string(),
632
+ entityId: z.string(),
613
633
  }),
614
634
  view_list: z.object({
615
- smdId: z.string(),
635
+ entityId: z.string(),
616
636
  extra: z.unknown(),
617
637
  }),
618
638
  view_list_columns: z.object({
619
- smdId: z.string(),
639
+ entityId: z.string(),
620
640
  columns: z
621
641
  .object({
622
642
  name: z.string(),
@@ -627,30 +647,30 @@ export const TemplateOptions = z.object({
627
647
  columnImports: z.string(),
628
648
  }),
629
649
  view_search_input: z.object({
630
- smdId: z.string(),
650
+ entityId: z.string(),
631
651
  }),
632
652
  view_form: z.object({
633
- smdId: z.string(),
653
+ entityId: z.string(),
634
654
  }),
635
655
  view_id_all_select: z.object({
636
- smdId: z.string(),
656
+ entityId: z.string(),
637
657
  }),
638
658
  view_id_async_select: z.object({
639
- smdId: z.string(),
659
+ entityId: z.string(),
640
660
  textField: z.string(),
641
661
  }),
642
662
  view_enums_select: z.object({
643
- smdId: z.string(),
663
+ entityId: z.string(),
644
664
  enumId: z.string(),
645
665
  idConstant: z.string(),
646
666
  }),
647
667
  view_enums_dropdown: z.object({
648
- smdId: z.string(),
668
+ entityId: z.string(),
649
669
  enumId: z.string(),
650
670
  idConstant: z.string(),
651
671
  }),
652
672
  view_enums_buttonset: z.object({
653
- smdId: z.string(),
673
+ entityId: z.string(),
654
674
  enumId: z.string(),
655
675
  idConstant: z.string(),
656
676
  }),
@@ -658,10 +678,8 @@ export const TemplateOptions = z.object({
658
678
  export type TemplateOptions = z.infer<typeof TemplateOptions>;
659
679
 
660
680
  export const TemplateKey = z.enum([
661
- "smd",
662
- "init_enums",
681
+ "entity",
663
682
  "init_types",
664
- "init_generated",
665
683
  "generated",
666
684
  "generated_http",
667
685
  "model",
@@ -46,3 +46,7 @@ export async function findApiRootPath() {
46
46
  } while (dir.split(path.sep).length > 1);
47
47
  throw new Error("Cannot find AppRoot using Sonamu -2");
48
48
  }
49
+
50
+ export function nonNullable<T>(value: T): value is NonNullable<T> {
51
+ return value !== null && value !== undefined;
52
+ }
package/tsconfig.json CHANGED
@@ -8,7 +8,6 @@
8
8
  "lib": ["esnext", "dom"],
9
9
  "declaration": true,
10
10
  "declarationMap": true,
11
- "esModuleInterop": true,
12
11
 
13
12
  /* Strict Type-Checking Options */
14
13
  "strict": true,
@@ -26,6 +25,10 @@
26
25
  "noImplicitReturns": true,
27
26
  "noFallthroughCasesInSwitch": true,
28
27
 
28
+ /* Module Resolution Options */
29
+ "moduleResolution": "node",
30
+ "esModuleInterop": true,
31
+
29
32
  /* Experimental Options */
30
33
  "experimentalDecorators": true,
31
34
  "emitDecoratorMetadata": true,
@@ -1,71 +0,0 @@
1
- import { camelize } from "inflection";
2
- import { TemplateOptions } from "../types/types";
3
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
4
- import { Template } from "./base-template";
5
-
6
- export class Template__init_enums extends Template {
7
- constructor() {
8
- super("init_enums");
9
- }
10
-
11
- getTargetAndPath(names: SMDNamesRecord) {
12
- return {
13
- target: "api/src/application",
14
- path: `${names.fs}/${names.fs}.enums.ts`,
15
- };
16
- }
17
-
18
- render(options: TemplateOptions["init_enums"]) {
19
- const { smdId, def } = options;
20
- const names = SMDManager.getNamesFromId(smdId);
21
-
22
- const record = def ?? {};
23
- record.ORDER_BY ??= {
24
- "id-desc": "최신순",
25
- };
26
- record.SEARCH_FIELD ??= {
27
- id: "ID",
28
- };
29
-
30
- return {
31
- ...this.getTargetAndPath(names),
32
- body: `
33
- import { z } from "zod";
34
- import { EnumsLabelKo } from "sonamu";
35
-
36
- ${Object.entries(record)
37
- .map(
38
- ([key, value]) => `export const ${smdId}${camelize(
39
- key.toLowerCase(),
40
- false
41
- )} = z.enum([${Object.keys(value)
42
- .map((v) => `"${v}"`)
43
- .join(",")}]);
44
- export type ${smdId}${camelize(
45
- key.toLowerCase(),
46
- false
47
- )} = z.infer<typeof ${smdId}${camelize(key.toLowerCase(), false)}>;`
48
- )
49
- .join("\n")}
50
-
51
- export namespace ${names.constant} {
52
- ${Object.entries(record)
53
- .map(
54
- ([key, value]) => `// ${key}
55
- export const ${key}:EnumsLabelKo<${smdId}${camelize(
56
- key.toLowerCase(),
57
- false
58
- )}> = {
59
- ${Object.entries(value)
60
- .map(([ek, ev]) => `"${ek}": { ko: "${ev}" }`)
61
- .join(",")}
62
- };
63
- `
64
- )
65
- .join("\n")}
66
- }
67
- `.trim(),
68
- importKeys: [],
69
- };
70
- }
71
- }
@@ -1,51 +0,0 @@
1
- import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
3
- import { Template } from "./base-template";
4
-
5
- export class Template__init_generated extends Template {
6
- constructor() {
7
- super("init_generated");
8
- }
9
-
10
- getTargetAndPath(names: SMDNamesRecord) {
11
- return {
12
- target: "api/src/application",
13
- path: `${names.fs}/${names.fs}.generated.ts`,
14
- };
15
- }
16
-
17
- render({ smdId }: TemplateOptions["init_generated"]) {
18
- const names = SMDManager.getNamesFromId(smdId);
19
-
20
- return {
21
- ...this.getTargetAndPath(names),
22
- body: `
23
- import { z } from "zod";
24
- import { ${smdId}SearchField, ${smdId}OrderBy } from "./${names.fs}.enums";
25
-
26
- export const ${smdId}BaseSchema = z.object({});
27
- export type ${smdId}BaseSchema = z.infer<typeof ${smdId}BaseSchema>;
28
-
29
- export const ${smdId}BaseListParams = z.object({
30
- num: z.number().int().min(0),
31
- page: z.number().int().min(1),
32
- search: ${smdId}SearchField,
33
- keyword: z.string(),
34
- orderBy: ${smdId}OrderBy,
35
- withoutCount: z.boolean(),
36
- }).partial();
37
- export type ${smdId}BaseListParams = z.infer<typeof ${smdId}BaseListParams>;
38
-
39
- export type ${smdId}SubsetKey = never;
40
- export type ${smdId}SubsetMapping = {};
41
- /* BEGIN- Server-side Only */
42
- import { SubsetQuery } from "sonamu";
43
- export const ${names.camel}SubsetQueries: { [key in ${smdId}SubsetKey]: SubsetQuery } = {};
44
-
45
- export type ${smdId}FieldExpr = string;
46
- /* END- Server-side Only */
47
- `.trim(),
48
- importKeys: [],
49
- };
50
- }
51
- }
@@ -1,53 +0,0 @@
1
- import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
3
- import { Template } from "./base-template";
4
-
5
- export class Template__smd extends Template {
6
- constructor() {
7
- super("smd");
8
- }
9
-
10
- getTargetAndPath(names: SMDNamesRecord) {
11
- return {
12
- target: "api/src/application",
13
- path: `${names.fs}/${names.fs}.smd.ts`,
14
- };
15
- }
16
-
17
- render(options: TemplateOptions["smd"]) {
18
- const { smdId, title, refCode } = options;
19
- const names = SMDManager.getNamesFromId(smdId);
20
-
21
- return {
22
- ...this.getTargetAndPath(names),
23
- body: `
24
- import { p, i, SMDInput } from "sonamu";
25
- import { ${smdId}FieldExpr } from "./${names.fs}.generated";
26
-
27
- /*
28
- ${smdId} SMD
29
- */
30
-
31
- export const ${names.camel}SmdInput: SMDInput<${smdId}FieldExpr> = {
32
- id: "${smdId}",
33
- title: "${title ?? smdId}",
34
- props: [
35
- p.integer("id", { unsigned: true }),
36
- p.timestamp("created_at", {
37
- now: true,
38
- }),
39
- ],
40
- indexes: [
41
- i.index('created_at'),
42
- //
43
- ],
44
- subsets: {
45
- A: [ 'id', 'created_at' ]
46
- }
47
- };
48
- ${refCode ? `\n/* REFERENCE\n\n${refCode}\n*/` : ""}
49
- `.trim(),
50
- importKeys: [],
51
- };
52
- }
53
- }