sonamu 0.0.42 → 0.1.2

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 (208) hide show
  1. package/.pnp.cjs +1963 -951
  2. package/.pnp.loader.mjs +1816 -54
  3. package/.yarnrc.yml +1 -1
  4. package/dist/api/code-converters.d.ts +3 -3
  5. package/dist/api/code-converters.d.ts.map +1 -1
  6. package/dist/api/code-converters.js +5 -15
  7. package/dist/api/code-converters.js.map +1 -1
  8. package/dist/api/context.d.ts +1 -1
  9. package/dist/api/context.d.ts.map +1 -1
  10. package/dist/api/decorators.d.ts +3 -3
  11. package/dist/api/decorators.d.ts.map +1 -1
  12. package/dist/api/sonamu.d.ts +3 -3
  13. package/dist/api/sonamu.d.ts.map +1 -1
  14. package/dist/api/sonamu.js +6 -6
  15. package/dist/api/sonamu.js.map +1 -1
  16. package/dist/bin/cli.js +132 -33
  17. package/dist/bin/cli.js.map +1 -1
  18. package/dist/database/db.d.ts +2 -2
  19. package/dist/database/db.d.ts.map +1 -1
  20. package/dist/database/db.js +1 -1
  21. package/dist/database/db.js.map +1 -1
  22. package/dist/database/upsert-builder.d.ts +2 -2
  23. package/dist/database/upsert-builder.d.ts.map +1 -1
  24. package/dist/database/upsert-builder.js +10 -8
  25. package/dist/database/upsert-builder.js.map +1 -1
  26. package/dist/entity/entity-manager.d.ts +29 -0
  27. package/dist/entity/entity-manager.d.ts.map +1 -0
  28. package/dist/entity/entity-manager.js +128 -0
  29. package/dist/entity/entity-manager.js.map +1 -0
  30. package/dist/entity/entity-utils.d.ts +61 -0
  31. package/dist/entity/entity-utils.d.ts.map +1 -0
  32. package/dist/entity/entity-utils.js +121 -0
  33. package/dist/entity/entity-utils.js.map +1 -0
  34. package/dist/entity/entity.d.ts +54 -0
  35. package/dist/entity/entity.d.ts.map +1 -0
  36. package/dist/entity/entity.js +596 -0
  37. package/dist/entity/entity.js.map +1 -0
  38. package/dist/entity/migrator.d.ts +143 -0
  39. package/dist/entity/migrator.d.ts.map +1 -0
  40. package/dist/entity/migrator.js +1385 -0
  41. package/dist/entity/migrator.js.map +1 -0
  42. package/dist/entity/smd-utils.d.ts +61 -0
  43. package/dist/entity/smd-utils.d.ts.map +1 -0
  44. package/dist/entity/smd-utils.js +121 -0
  45. package/dist/entity/smd-utils.js.map +1 -0
  46. package/dist/index.d.ts +3 -3
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +3 -3
  49. package/dist/index.js.map +1 -1
  50. package/dist/smd/entity-manager.d.ts +28 -0
  51. package/dist/smd/entity-manager.d.ts.map +1 -0
  52. package/dist/smd/entity-manager.js +119 -0
  53. package/dist/smd/entity-manager.js.map +1 -0
  54. package/dist/smd/entity.d.ts +40 -0
  55. package/dist/smd/entity.d.ts.map +1 -0
  56. package/dist/smd/entity.js +430 -0
  57. package/dist/smd/entity.js.map +1 -0
  58. package/dist/smd/migrator.d.ts +2 -2
  59. package/dist/smd/migrator.d.ts.map +1 -1
  60. package/dist/smd/migrator.js +5 -5
  61. package/dist/smd/migrator.js.map +1 -1
  62. package/dist/smd/smd-manager.d.ts +3 -3
  63. package/dist/smd/smd-manager.d.ts.map +1 -1
  64. package/dist/smd/smd-manager.js +2 -2
  65. package/dist/smd/smd-manager.js.map +1 -1
  66. package/dist/smd/smd-utils.d.ts +3 -3
  67. package/dist/smd/smd-utils.d.ts.map +1 -1
  68. package/dist/smd/smd.d.ts +5 -6
  69. package/dist/smd/smd.d.ts.map +1 -1
  70. package/dist/smd/smd.js +3 -3
  71. package/dist/smd/smd.js.map +1 -1
  72. package/dist/syncer/syncer.d.ts +15 -11
  73. package/dist/syncer/syncer.d.ts.map +1 -1
  74. package/dist/syncer/syncer.js +134 -74
  75. package/dist/syncer/syncer.js.map +1 -1
  76. package/dist/templates/base-template.d.ts +2 -2
  77. package/dist/templates/base-template.d.ts.map +1 -1
  78. package/dist/templates/entity.template.d.ts +17 -0
  79. package/dist/templates/entity.template.d.ts.map +1 -0
  80. package/dist/templates/entity.template.js +46 -0
  81. package/dist/templates/entity.template.js.map +1 -0
  82. package/dist/templates/generated.template.d.ts +11 -7
  83. package/dist/templates/generated.template.d.ts.map +1 -1
  84. package/dist/templates/generated.template.js +72 -43
  85. package/dist/templates/generated.template.js.map +1 -1
  86. package/dist/templates/generated_http.template.d.ts +3 -3
  87. package/dist/templates/generated_http.template.d.ts.map +1 -1
  88. package/dist/templates/generated_http.template.js +3 -3
  89. package/dist/templates/generated_http.template.js.map +1 -1
  90. package/dist/templates/init_enums.template.d.ts +2 -2
  91. package/dist/templates/init_enums.template.d.ts.map +1 -1
  92. package/dist/templates/init_enums.template.js +2 -2
  93. package/dist/templates/init_enums.template.js.map +1 -1
  94. package/dist/templates/init_generated.template.d.ts +3 -3
  95. package/dist/templates/init_generated.template.d.ts.map +1 -1
  96. package/dist/templates/init_generated.template.js +13 -14
  97. package/dist/templates/init_generated.template.js.map +1 -1
  98. package/dist/templates/init_types.template.d.ts +3 -3
  99. package/dist/templates/init_types.template.d.ts.map +1 -1
  100. package/dist/templates/init_types.template.js +10 -10
  101. package/dist/templates/init_types.template.js.map +1 -1
  102. package/dist/templates/model.template.d.ts +3 -3
  103. package/dist/templates/model.template.d.ts.map +1 -1
  104. package/dist/templates/model.template.js +28 -28
  105. package/dist/templates/model.template.js.map +1 -1
  106. package/dist/templates/model_test.template.d.ts +3 -3
  107. package/dist/templates/model_test.template.d.ts.map +1 -1
  108. package/dist/templates/model_test.template.js +4 -4
  109. package/dist/templates/model_test.template.js.map +1 -1
  110. package/dist/templates/service.template.d.ts +3 -3
  111. package/dist/templates/service.template.d.ts.map +1 -1
  112. package/dist/templates/service.template.js +3 -3
  113. package/dist/templates/service.template.js.map +1 -1
  114. package/dist/templates/smd.template.d.ts +2 -2
  115. package/dist/templates/smd.template.d.ts.map +1 -1
  116. package/dist/templates/smd.template.js +2 -2
  117. package/dist/templates/smd.template.js.map +1 -1
  118. package/dist/templates/view_enums_buttonset.template.d.ts +3 -3
  119. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -1
  120. package/dist/templates/view_enums_buttonset.template.js +4 -4
  121. package/dist/templates/view_enums_buttonset.template.js.map +1 -1
  122. package/dist/templates/view_enums_dropdown.template.d.ts +3 -3
  123. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -1
  124. package/dist/templates/view_enums_dropdown.template.js +3 -3
  125. package/dist/templates/view_enums_dropdown.template.js.map +1 -1
  126. package/dist/templates/view_enums_select.template.d.ts +3 -3
  127. package/dist/templates/view_enums_select.template.d.ts.map +1 -1
  128. package/dist/templates/view_enums_select.template.js +3 -3
  129. package/dist/templates/view_enums_select.template.js.map +1 -1
  130. package/dist/templates/view_form.template.d.ts +25 -29
  131. package/dist/templates/view_form.template.d.ts.map +1 -1
  132. package/dist/templates/view_form.template.js +19 -19
  133. package/dist/templates/view_form.template.js.map +1 -1
  134. package/dist/templates/view_id_all_select.template.d.ts +3 -3
  135. package/dist/templates/view_id_all_select.template.d.ts.map +1 -1
  136. package/dist/templates/view_id_all_select.template.js +4 -4
  137. package/dist/templates/view_id_all_select.template.js.map +1 -1
  138. package/dist/templates/view_id_async_select.template.d.ts +3 -3
  139. package/dist/templates/view_id_async_select.template.d.ts.map +1 -1
  140. package/dist/templates/view_id_async_select.template.js +6 -6
  141. package/dist/templates/view_id_async_select.template.js.map +1 -1
  142. package/dist/templates/view_list.template.d.ts +30 -34
  143. package/dist/templates/view_list.template.d.ts.map +1 -1
  144. package/dist/templates/view_list.template.js +40 -40
  145. package/dist/templates/view_list.template.js.map +1 -1
  146. package/dist/templates/view_list_columns.template.d.ts +3 -3
  147. package/dist/templates/view_list_columns.template.d.ts.map +1 -1
  148. package/dist/templates/view_list_columns.template.js +3 -3
  149. package/dist/templates/view_list_columns.template.js.map +1 -1
  150. package/dist/templates/view_search_input.template.d.ts +3 -3
  151. package/dist/templates/view_search_input.template.d.ts.map +1 -1
  152. package/dist/templates/view_search_input.template.js +3 -3
  153. package/dist/templates/view_search_input.template.js.map +1 -1
  154. package/dist/testing/fixture-manager.d.ts +2 -2
  155. package/dist/testing/fixture-manager.d.ts.map +1 -1
  156. package/dist/testing/fixture-manager.js +18 -16
  157. package/dist/testing/fixture-manager.js.map +1 -1
  158. package/dist/types/smd.types.d.ts +741 -0
  159. package/dist/types/smd.types.d.ts.map +1 -0
  160. package/dist/types/smd.types.js +292 -0
  161. package/dist/types/smd.types.js.map +1 -0
  162. package/dist/types/types.d.ts +187 -190
  163. package/dist/types/types.d.ts.map +1 -1
  164. package/dist/types/types.js +22 -30
  165. package/dist/types/types.js.map +1 -1
  166. package/dist/utils/model.d.ts +2 -2
  167. package/dist/utils/model.d.ts.map +1 -1
  168. package/dist/utils/utils.d.ts +1 -0
  169. package/dist/utils/utils.d.ts.map +1 -1
  170. package/dist/utils/utils.js +6 -2
  171. package/dist/utils/utils.js.map +1 -1
  172. package/package.json +11 -8
  173. package/src/api/code-converters.ts +9 -17
  174. package/src/api/sonamu.ts +10 -6
  175. package/src/bin/cli.ts +156 -27
  176. package/src/database/upsert-builder.ts +2 -2
  177. package/src/entity/entity-manager.ts +150 -0
  178. package/src/{smd/smd-utils.ts → entity/entity-utils.ts} +3 -3
  179. package/src/entity/entity.ts +774 -0
  180. package/src/{smd → entity}/migrator.ts +426 -106
  181. package/src/index.ts +3 -3
  182. package/src/smd/smd-manager.ts +3 -13
  183. package/src/smd/smd.ts +13 -10
  184. package/src/syncer/syncer.ts +125 -73
  185. package/src/templates/base-template.ts +2 -2
  186. package/src/templates/entity.template.ts +50 -0
  187. package/src/templates/generated.template.ts +93 -57
  188. package/src/templates/generated_http.template.ts +4 -4
  189. package/src/templates/init_types.template.ts +11 -11
  190. package/src/templates/model.template.ts +29 -29
  191. package/src/templates/model_test.template.ts +5 -5
  192. package/src/templates/service.template.ts +4 -4
  193. package/src/templates/view_enums_buttonset.template.ts +5 -5
  194. package/src/templates/view_enums_dropdown.template.ts +4 -4
  195. package/src/templates/view_enums_select.template.ts +8 -4
  196. package/src/templates/view_form.template.ts +21 -21
  197. package/src/templates/view_id_all_select.template.ts +5 -5
  198. package/src/templates/view_id_async_select.template.ts +9 -7
  199. package/src/templates/view_list.template.ts +54 -44
  200. package/src/templates/view_list_columns.template.ts +4 -4
  201. package/src/templates/view_search_input.template.ts +4 -4
  202. package/src/testing/fixture-manager.ts +12 -12
  203. package/src/types/types.ts +59 -39
  204. package/src/utils/utils.ts +4 -0
  205. package/tsconfig.json +4 -1
  206. package/src/templates/init_enums.template.ts +0 -71
  207. package/src/templates/init_generated.template.ts +0 -51
  208. package/src/templates/smd.template.ts +0 -53
@@ -3,7 +3,7 @@ import knex, { Knex } from "knex";
3
3
  import { uniq } from "lodash";
4
4
  import { Sonamu } from "../api";
5
5
  import { BaseModel } from "../database/base-model";
6
- import { SMDManager } from "../smd/smd-manager";
6
+ import { EntityManager } from "../entity/entity-manager";
7
7
  import {
8
8
  isBelongsToOneRelationProp,
9
9
  isOneToOneRelationProp,
@@ -160,12 +160,12 @@ export class FixtureManagerClass {
160
160
  await frdb.destroy();
161
161
  }
162
162
 
163
- async importFixture(smdId: string, ids: number[]) {
163
+ async importFixture(entityId: string, ids: number[]) {
164
164
  const queries = uniq(
165
165
  (
166
166
  await Promise.all(
167
167
  ids.map(async (id) => {
168
- return await this.getImportQueries(smdId, "id", id);
168
+ return await this.getImportQueries(entityId, "id", id);
169
169
  })
170
170
  )
171
171
  ).flat()
@@ -182,18 +182,18 @@ export class FixtureManagerClass {
182
182
  }
183
183
 
184
184
  async getImportQueries(
185
- smdId: string,
185
+ entityId: string,
186
186
  field: string,
187
187
  id: number
188
188
  ): Promise<string[]> {
189
- console.log({ smdId, field, id });
190
- const smd = SMDManager.get(smdId);
189
+ console.log({ entityId, field, id });
190
+ const entity = EntityManager.get(entityId);
191
191
  const wdb = BaseModel.getDB("w");
192
192
 
193
193
  // 여기서 실DB의 row 가져옴
194
- const [row] = await wdb(smd.table).where(field, id).limit(1);
194
+ const [row] = await wdb(entity.table).where(field, id).limit(1);
195
195
  if (row === undefined) {
196
- throw new Error(`${smdId}#${id} row를 찾을 수 없습니다.`);
196
+ throw new Error(`${entityId}#${id} row를 찾을 수 없습니다.`);
197
197
  }
198
198
 
199
199
  // 픽스쳐DB, 실DB
@@ -202,9 +202,9 @@ export class FixtureManagerClass {
202
202
  const realDatabase = (Sonamu.dbConfig.production_master.connection as any)
203
203
  .database;
204
204
 
205
- 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})`;
206
206
 
207
- const args = Object.entries(smd.relations)
207
+ const args = Object.entries(entity.relations)
208
208
  .filter(
209
209
  ([, relation]) =>
210
210
  isBelongsToOneRelationProp(relation) ||
@@ -230,7 +230,7 @@ export class FixtureManagerClass {
230
230
  id = row[`${relation.name}_id`];
231
231
  }
232
232
  return {
233
- smdId: relation.with,
233
+ entityId: relation.with,
234
234
  field,
235
235
  id,
236
236
  };
@@ -239,7 +239,7 @@ export class FixtureManagerClass {
239
239
 
240
240
  const relQueries = await Promise.all(
241
241
  args.map(async (args) => {
242
- return this.getImportQueries(args.smdId, args.field, args.id);
242
+ return this.getImportQueries(args.entityId, args.field, args.id);
243
243
  })
244
244
  );
245
245
 
@@ -97,14 +97,14 @@ export type TimestampProp = CommonProp & {
97
97
  };
98
98
  export type JsonProp = CommonProp & {
99
99
  type: "json";
100
- as: { ref: string } | z.ZodTypeAny;
100
+ id: string;
101
101
  };
102
102
  export type UuidProp = CommonProp & {
103
103
  type: "uuid";
104
104
  };
105
105
  export type VirtualProp = CommonProp & {
106
106
  type: "virtual";
107
- as: { ref: string } | z.ZodTypeAny;
107
+ id: string;
108
108
  };
109
109
 
110
110
  export type RelationType =
@@ -162,7 +162,7 @@ export type RelationProp =
162
162
  | HasManyRelationProp
163
163
  | ManyToManyRelationProp;
164
164
 
165
- export type SMDProp =
165
+ export type EntityProp =
166
166
  | IntegerProp
167
167
  | BigIntegerProp
168
168
  | TextProp
@@ -181,19 +181,47 @@ export type SMDProp =
181
181
  | VirtualProp
182
182
  | RelationProp;
183
183
 
184
- export type SMDIndex = {
184
+ export type EntityIndex = {
185
185
  type: "index" | "unique";
186
186
  columns: string[];
187
187
  name?: string;
188
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">;
189
216
 
217
+ // SMD Legacy
190
218
  export type SMDInput<T extends string> = {
191
219
  id: string;
192
220
  parentId?: string;
193
221
  table?: string;
194
222
  title?: string;
195
- props?: SMDProp[];
196
- indexes?: SMDIndex[];
223
+ props?: EntityProp[];
224
+ indexes?: EntityIndex[];
197
225
  subsets?: {
198
226
  [subset: string]: T[];
199
227
  };
@@ -203,15 +231,15 @@ export type SMDInput<T extends string> = {
203
231
  PropNode
204
232
  */
205
233
 
206
- export type SMDPropNode =
234
+ export type EntityPropNode =
207
235
  | {
208
236
  nodeType: "plain";
209
- prop: SMDProp;
237
+ prop: EntityProp;
210
238
  }
211
239
  | {
212
240
  nodeType: "object" | "array";
213
- prop?: SMDProp;
214
- children: SMDPropNode[];
241
+ prop?: EntityProp;
242
+ children: EntityPropNode[];
215
243
  };
216
244
 
217
245
  /*
@@ -574,47 +602,41 @@ export type RenderingNode = {
574
602
  };
575
603
 
576
604
  export const TemplateOptions = z.object({
577
- smd: z.object({
578
- smdId: z.string(),
605
+ entity: z.object({
606
+ entityId: z.string(),
607
+ parentId: z.string().optional(),
579
608
  title: z.string(),
580
- refCode: z.string().optional(),
581
- }),
582
- init_enums: z.object({
583
- smdId: z.string(),
584
- def: z.record(z.record(z.string())).optional(),
609
+ table: z.string().optional(),
585
610
  }),
586
611
  init_types: z.object({
587
- smdId: z.string(),
588
- }),
589
- init_generated: z.object({
590
- smdId: z.string(),
612
+ entityId: z.string(),
591
613
  }),
592
614
  generated: z.object({
593
- smdId: z.string(),
615
+ entityId: z.string(),
594
616
  }),
595
617
  generated_http: z.object({
596
- smdId: z.string(),
618
+ entityId: z.string(),
597
619
  }),
598
620
  model: z.object({
599
- smdId: z.string(),
621
+ entityId: z.string(),
600
622
  defaultSearchField: z.string(),
601
623
  defaultOrderBy: z.string(),
602
624
  }),
603
625
  model_test: z.object({
604
- smdId: z.string(),
626
+ entityId: z.string(),
605
627
  }),
606
628
  bridge: z.object({
607
- smdId: z.string(),
629
+ entityId: z.string(),
608
630
  }),
609
631
  service: z.object({
610
- smdId: z.string(),
632
+ entityId: z.string(),
611
633
  }),
612
634
  view_list: z.object({
613
- smdId: z.string(),
635
+ entityId: z.string(),
614
636
  extra: z.unknown(),
615
637
  }),
616
638
  view_list_columns: z.object({
617
- smdId: z.string(),
639
+ entityId: z.string(),
618
640
  columns: z
619
641
  .object({
620
642
  name: z.string(),
@@ -625,30 +647,30 @@ export const TemplateOptions = z.object({
625
647
  columnImports: z.string(),
626
648
  }),
627
649
  view_search_input: z.object({
628
- smdId: z.string(),
650
+ entityId: z.string(),
629
651
  }),
630
652
  view_form: z.object({
631
- smdId: z.string(),
653
+ entityId: z.string(),
632
654
  }),
633
655
  view_id_all_select: z.object({
634
- smdId: z.string(),
656
+ entityId: z.string(),
635
657
  }),
636
658
  view_id_async_select: z.object({
637
- smdId: z.string(),
659
+ entityId: z.string(),
638
660
  textField: z.string(),
639
661
  }),
640
662
  view_enums_select: z.object({
641
- smdId: z.string(),
663
+ entityId: z.string(),
642
664
  enumId: z.string(),
643
665
  idConstant: z.string(),
644
666
  }),
645
667
  view_enums_dropdown: z.object({
646
- smdId: z.string(),
668
+ entityId: z.string(),
647
669
  enumId: z.string(),
648
670
  idConstant: z.string(),
649
671
  }),
650
672
  view_enums_buttonset: z.object({
651
- smdId: z.string(),
673
+ entityId: z.string(),
652
674
  enumId: z.string(),
653
675
  idConstant: z.string(),
654
676
  }),
@@ -656,10 +678,8 @@ export const TemplateOptions = z.object({
656
678
  export type TemplateOptions = z.infer<typeof TemplateOptions>;
657
679
 
658
680
  export const TemplateKey = z.enum([
659
- "smd",
660
- "init_enums",
681
+ "entity",
661
682
  "init_types",
662
- "init_generated",
663
683
  "generated",
664
684
  "generated_http",
665
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
- }