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
@@ -6,9 +6,9 @@ import {
6
6
  isTimestampProp,
7
7
  TemplateOptions,
8
8
  } from "../types/types";
9
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
10
- import { SMD } from "../smd/smd";
11
- import { SMDPropNode, SubsetQuery } from "../types/types";
9
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
10
+ import { Entity } from "../entity/entity";
11
+ import { EntityPropNode, SubsetQuery } from "../types/types";
12
12
  import { propNodeToZodTypeDef } from "../api/code-converters";
13
13
  import { Template } from "./base-template";
14
14
 
@@ -17,21 +17,25 @@ export class Template__generated extends Template {
17
17
  super("generated");
18
18
  }
19
19
 
20
- getTargetAndPath(names: SMDNamesRecord) {
20
+ getTargetAndPath(names: EntityNamesRecord) {
21
21
  return {
22
22
  target: "api/src/application",
23
23
  path: `${names.fs}/${names.fs}.generated.ts`,
24
24
  };
25
25
  }
26
26
 
27
- render({ smdId }: TemplateOptions["generated"]) {
28
- const names = SMDManager.getNamesFromId(smdId);
29
- const smd = SMDManager.get(smdId);
27
+ render({ entityId }: TemplateOptions["generated"]) {
28
+ const entity = EntityManager.get(entityId);
30
29
 
31
30
  const typeSource = [
32
- this.getBaseSchemaTypeSource(smd),
33
- this.getBaseListParamsTypeSource(smd),
34
- this.getSubsetTypeSource(smd),
31
+ this.getEnumsTypeSource(entity),
32
+ this.getBaseSchemaTypeSource(entity),
33
+ ...(entity.parentId === undefined
34
+ ? [
35
+ this.getBaseListParamsTypeSource(entity),
36
+ this.getSubsetTypeSource(entity),
37
+ ]
38
+ : []),
35
39
  ].reduce(
36
40
  (result, ts) => {
37
41
  if (ts === null) {
@@ -48,49 +52,80 @@ export class Template__generated extends Template {
48
52
  }
49
53
  );
50
54
 
51
- const fieldExprs = smd
52
- .getFieldExprs()
53
- .map((fieldExpr) => `"${fieldExpr}"`)
54
- .join(" | ");
55
- const fieldExprsLine = `export type ${smd.id}FieldExpr = ${
56
- fieldExprs.length > 0 ? fieldExprs : "string"
57
- }`;
55
+ // targetAndPath
56
+ const names = EntityManager.getNamesFromId(entityId);
57
+ const targetAndPath = this.getTargetAndPath(names);
58
+
59
+ // import
60
+ const sonamuImports = [
61
+ "zArrayable",
62
+ ...(entity.props.find(
63
+ (p) => isTimestampProp(p) || isDateProp(p) || isDateTimeProp(p)
64
+ )
65
+ ? ["SQLDateTimeString"]
66
+ : []),
67
+ ];
58
68
 
59
69
  return {
60
- ...this.getTargetAndPath(names),
61
- body: [...typeSource!.lines, fieldExprsLine, "/* END Server-side Only */"]
70
+ ...targetAndPath,
71
+ body: [...typeSource!.lines, "/* END Server-side Only */"]
62
72
  .join("\n")
63
73
  .trim(),
64
74
  importKeys: typeSource?.importKeys ?? [],
65
75
  customHeaders: [
66
76
  `import { z } from 'zod';`,
67
- smd.props.length > 0
68
- ? `import { zArrayable${
69
- smd.props.find(
70
- (p) => isTimestampProp(p) || isDateProp(p) || isDateTimeProp(p)
71
- )
72
- ? ", SQLDateTimeString"
73
- : ""
74
- } } from "sonamu";`
77
+ entity.props.length > 0
78
+ ? `import { ${sonamuImports.join(",")} } from "sonamu";`
75
79
  : "",
76
80
  ],
77
81
  };
78
82
  }
79
83
 
84
+ getEnumsTypeSource(entity: Entity): {
85
+ lines: string[];
86
+ importKeys: string[];
87
+ } {
88
+ const childrenIds = EntityManager.getChildrenIds(entity.id);
89
+ const entities = [
90
+ entity,
91
+ ...childrenIds.map((id) => EntityManager.get(id)),
92
+ ];
93
+
94
+ return {
95
+ lines: [
96
+ "// Enums",
97
+ ...entities
98
+ .map((entity) =>
99
+ Object.entries(entity.enumLabels).map(([enumId, enumLabel]) => [
100
+ `export const ${enumId} = z.enum([${Object.keys(enumLabel).map(
101
+ (el) => `"${el}"`
102
+ )}]).describe("${enumId}");`,
103
+ `export type ${enumId} = z.infer<typeof ${enumId}>`,
104
+ `export const ${enumId}Label = ${JSON.stringify(enumLabel)}`,
105
+ ])
106
+ )
107
+ .flat()
108
+ .flat(),
109
+ "",
110
+ ],
111
+ importKeys: [],
112
+ };
113
+ }
114
+
80
115
  getBaseSchemaTypeSource(
81
- smd: SMD,
116
+ entity: Entity,
82
117
  depth: number = 0,
83
118
  importKeys: string[] = []
84
119
  ): {
85
120
  lines: string[];
86
121
  importKeys: string[];
87
122
  } {
88
- const childrenIds = SMDManager.getChildrenIds(smd.id);
123
+ const childrenIds = EntityManager.getChildrenIds(entity.id);
89
124
 
90
- const schemaName = `${smd.names.module}BaseSchema`;
91
- const propNode: SMDPropNode = {
125
+ const schemaName = `${entity.names.module}BaseSchema`;
126
+ const propNode: EntityPropNode = {
92
127
  nodeType: "object",
93
- children: smd.props.map((prop) => {
128
+ children: entity.props.map((prop) => {
94
129
  return {
95
130
  nodeType: "plain",
96
131
  prop,
@@ -105,7 +140,7 @@ export class Template__generated extends Template {
105
140
  `export type ${schemaName} = z.infer<typeof ${schemaName}>`,
106
141
  ...childrenIds
107
142
  .map((childId) => {
108
- const child = SMDManager.get(childId);
143
+ const child = EntityManager.get(childId);
109
144
  const { lines } = this.getBaseSchemaTypeSource(
110
145
  child,
111
146
  depth + 1,
@@ -122,23 +157,23 @@ export class Template__generated extends Template {
122
157
  };
123
158
  }
124
159
 
125
- getBaseListParamsTypeSource(smd: SMD): {
160
+ getBaseListParamsTypeSource(entity: Entity): {
126
161
  lines: string[];
127
162
  importKeys: string[];
128
163
  } {
129
164
  // Prop 없는 MD인 경우 생성 제외
130
- if (smd.props.length === 0) {
165
+ if (entity.props.length === 0) {
131
166
  return {
132
167
  lines: [],
133
168
  importKeys: [],
134
169
  };
135
170
  }
136
171
 
137
- const schemaName = `${smd.names.module}BaseListParams`;
172
+ const schemaName = `${entity.names.module}BaseListParams`;
138
173
 
139
- const filterProps = smd.props.filter((prop) => prop.toFilter === true);
174
+ const filterProps = entity.props.filter((prop) => prop.toFilter === true);
140
175
 
141
- const propNodes: SMDPropNode[] = filterProps.map((prop) => {
176
+ const propNodes: EntityPropNode[] = filterProps.map((prop) => {
142
177
  return {
143
178
  nodeType: "plain" as const,
144
179
  prop,
@@ -146,7 +181,7 @@ export class Template__generated extends Template {
146
181
  };
147
182
  });
148
183
 
149
- const importKeys: string[] = [`${smd.id}SearchField`, `${smd.id}OrderBy`];
184
+ const importKeys: string[] = [];
150
185
  const filterBody = propNodes
151
186
  .map((propNode) => propNodeToZodTypeDef(propNode, importKeys))
152
187
  .join("\n");
@@ -155,9 +190,9 @@ export class Template__generated extends Template {
155
190
  z.object({
156
191
  num: z.number().int().nonnegative(),
157
192
  page: z.number().int().min(1),
158
- search: ${smd.id}SearchField,
193
+ search: ${entity.id}SearchField,
159
194
  keyword: z.string(),
160
- orderBy: ${smd.id}OrderBy,
195
+ orderBy: ${entity.id}OrderBy,
161
196
  withoutCount: z.boolean(),
162
197
  id: zArrayable(z.number().int().positive()),${filterBody}
163
198
  }).partial();
@@ -174,19 +209,19 @@ z.object({
174
209
  };
175
210
  }
176
211
 
177
- getSubsetTypeSource(smd: SMD): {
212
+ getSubsetTypeSource(entity: Entity): {
178
213
  lines: string[];
179
214
  importKeys: string[];
180
215
  } | null {
181
- if (Object.keys(smd.subsets).length == 0) {
216
+ if (Object.keys(entity.subsets).length == 0) {
182
217
  return null;
183
218
  }
184
219
 
185
- const subsetKeys = Object.keys(smd.subsets);
220
+ const subsetKeys = Object.keys(entity.subsets);
186
221
 
187
222
  const subsetQueryObject = subsetKeys.reduce(
188
223
  (r, subsetKey) => {
189
- const subsetQuery = smd.getSubsetQuery(subsetKey);
224
+ const subsetQuery = entity.getSubsetQuery(subsetKey);
190
225
  r[subsetKey] = subsetQuery;
191
226
  return r;
192
227
  },
@@ -201,17 +236,17 @@ z.object({
201
236
  ...subsetKeys
202
237
  .map((subsetKey) => {
203
238
  // 서브셋에서 FieldExpr[] 가져옴
204
- const fieldExprs = smd.subsets[subsetKey];
239
+ const fieldExprs = entity.subsets[subsetKey];
205
240
 
206
- // FieldExpr[]로 MDPropNode[] 가져옴
207
- const propNodes = smd.fieldExprsToPropNodes(fieldExprs);
208
- const schemaName = `${smd.names.module}Subset${subsetKey}`;
209
- const propNode: SMDPropNode = {
241
+ // FieldExpr[]로 EntityPropNode[] 가져옴
242
+ const propNodes = entity.fieldExprsToPropNodes(fieldExprs);
243
+ const schemaName = `${entity.names.module}Subset${subsetKey}`;
244
+ const propNode: EntityPropNode = {
210
245
  nodeType: "object",
211
246
  children: propNodes,
212
247
  };
213
248
 
214
- // MDPropNode[]로 ZodTypeDef(string)을 가져옴
249
+ // EntityPropNode[]로 ZodTypeDef(string)을 가져옴
215
250
  const body = propNodeToZodTypeDef(propNode, importKeys);
216
251
 
217
252
  return [
@@ -222,20 +257,21 @@ z.object({
222
257
  })
223
258
  .flat(),
224
259
  "",
225
- `export type ${smd.names.module}SubsetMapping = {`,
260
+ `export type ${entity.names.module}SubsetMapping = {`,
226
261
  ...subsetKeys.map(
227
- (subsetKey) => ` ${subsetKey}: ${smd.names.module}Subset${subsetKey};`
262
+ (subsetKey) =>
263
+ ` ${subsetKey}: ${entity.names.module}Subset${subsetKey};`
228
264
  ),
229
265
  "}",
230
- `export const ${smd.names.module}SubsetKey = z.enum([${subsetKeys
266
+ `export const ${entity.names.module}SubsetKey = z.enum([${subsetKeys
231
267
  .map((k) => `"${k}"`)
232
268
  .join(",")}]);`,
233
- `export type ${smd.names.module}SubsetKey = z.infer<typeof ${smd.names.module}SubsetKey>`,
269
+ `export type ${entity.names.module}SubsetKey = z.infer<typeof ${entity.names.module}SubsetKey>`,
234
270
  "",
235
271
  "/* BEGIN- Server-side Only */",
236
272
  `import { SubsetQuery } from "sonamu";`,
237
- `export const ${camelize(smd.id, true)}SubsetQueries:{ [key in ${
238
- smd.names.module
273
+ `export const ${camelize(entity.id, true)}SubsetQueries:{ [key in ${
274
+ entity.names.module
239
275
  }SubsetKey]: SubsetQuery} = ${JSON.stringify(subsetQueryObject)}`,
240
276
  "",
241
277
  ];
@@ -1,7 +1,7 @@
1
1
  import qs from "qs";
2
2
  import { z } from "zod";
3
3
  import { TemplateOptions } from "../types/types";
4
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
4
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
5
5
  import { getZodObjectFromApi } from "../api/code-converters";
6
6
  import { ExtendedApi } from "../api/decorators";
7
7
  import { Template } from "./base-template";
@@ -14,15 +14,15 @@ export class Template__generated_http extends Template {
14
14
  super("generated_http");
15
15
  }
16
16
 
17
- getTargetAndPath(names: SMDNamesRecord) {
17
+ getTargetAndPath(names: EntityNamesRecord) {
18
18
  return {
19
19
  target: "api/src/application",
20
20
  path: `${names.fs}/${names.fs}.generated.http`,
21
21
  };
22
22
  }
23
23
 
24
- render({ smdId }: TemplateOptions["generated"], apis: ExtendedApi[]) {
25
- const names = SMDManager.getNamesFromId(smdId);
24
+ render({ entityId }: TemplateOptions["generated"], apis: ExtendedApi[]) {
25
+ const names = EntityManager.getNamesFromId(entityId);
26
26
  const references = Sonamu.syncer.types;
27
27
 
28
28
  const lines = apis.map((api) => {
@@ -1,5 +1,5 @@
1
1
  import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
2
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
3
3
  import { Template } from "./base-template";
4
4
 
5
5
  export class Template__init_types extends Template {
@@ -7,29 +7,29 @@ export class Template__init_types extends Template {
7
7
  super("init_types");
8
8
  }
9
9
 
10
- getTargetAndPath(names: SMDNamesRecord) {
10
+ getTargetAndPath(names: EntityNamesRecord) {
11
11
  return {
12
12
  target: "api/src/application",
13
13
  path: `${names.fs}/${names.fs}.types.ts`,
14
14
  };
15
15
  }
16
16
 
17
- render({ smdId }: TemplateOptions["init_types"]) {
18
- const names = SMDManager.getNamesFromId(smdId);
17
+ render({ entityId }: TemplateOptions["init_types"]) {
18
+ const names = EntityManager.getNamesFromId(entityId);
19
19
 
20
20
  return {
21
21
  ...this.getTargetAndPath(names),
22
22
  body: `
23
23
  import { z } from "zod";
24
- import { ${smdId}BaseSchema, ${smdId}BaseListParams } from "./${names.fs}.generated";
24
+ import { ${entityId}BaseSchema, ${entityId}BaseListParams } from "./${names.fs}.generated";
25
25
 
26
- // ${smdId} - ListParams
27
- export const ${smdId}ListParams = ${smdId}BaseListParams;
28
- export type ${smdId}ListParams = z.infer<typeof ${smdId}ListParams>;
26
+ // ${entityId} - ListParams
27
+ export const ${entityId}ListParams = ${entityId}BaseListParams;
28
+ export type ${entityId}ListParams = z.infer<typeof ${entityId}ListParams>;
29
29
 
30
- // ${smdId} - SaveParams
31
- export const ${smdId}SaveParams = ${smdId}BaseSchema.partial({ id: true });
32
- export type ${smdId}SaveParams = z.infer<typeof ${smdId}SaveParams>;
30
+ // ${entityId} - SaveParams
31
+ export const ${entityId}SaveParams = ${entityId}BaseSchema.partial({ id: true });
32
+ export type ${entityId}SaveParams = z.infer<typeof ${entityId}SaveParams>;
33
33
 
34
34
  `.trim(),
35
35
  importKeys: [],
@@ -1,5 +1,5 @@
1
1
  import { RenderingNode, TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
2
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
3
3
  import { Template } from "./base-template";
4
4
  import { Template__view_list } from "./view_list.template";
5
5
 
@@ -8,7 +8,7 @@ export class Template__model extends Template {
8
8
  super("model");
9
9
  }
10
10
 
11
- getTargetAndPath(names: SMDNamesRecord) {
11
+ getTargetAndPath(names: EntityNamesRecord) {
12
12
  return {
13
13
  target: "api/src/application",
14
14
  path: `${names.fs}/${names.fs}.model.ts`,
@@ -16,12 +16,12 @@ export class Template__model extends Template {
16
16
  }
17
17
 
18
18
  render(
19
- { smdId }: TemplateOptions["model"],
19
+ { entityId }: TemplateOptions["model"],
20
20
  _columnsNode: RenderingNode,
21
21
  listParamsNode: RenderingNode
22
22
  ) {
23
- const names = SMDManager.getNamesFromId(smdId);
24
- const smd = SMDManager.get(smdId);
23
+ const names = EntityManager.getNamesFromId(entityId);
24
+ const entity = EntityManager.get(entityId);
25
25
 
26
26
  const vlTpl = new Template__view_list();
27
27
  const def = vlTpl.getDefault(listParamsNode.children!);
@@ -31,23 +31,23 @@ export class Template__model extends Template {
31
31
  body: `
32
32
  import { BaseModelClass, ListResult, asArray, NotFoundException, BadRequestException, api } from 'sonamu';
33
33
  import {
34
- ${smdId}SubsetKey,
35
- ${smdId}SubsetMapping,
34
+ ${entityId}SubsetKey,
35
+ ${entityId}SubsetMapping,
36
36
  ${names.camel}SubsetQueries,
37
37
  } from "./${names.fs}.generated";
38
- import { ${smdId}ListParams, ${smdId}SaveParams } from "./${names.fs}.types";
38
+ import { ${entityId}ListParams, ${entityId}SaveParams } from "./${names.fs}.types";
39
39
 
40
40
  /*
41
- ${smdId} Model
41
+ ${entityId} Model
42
42
  */
43
- class ${smdId}ModelClass extends BaseModelClass {
44
- modelName = "${smdId}";
43
+ class ${entityId}ModelClass extends BaseModelClass {
44
+ modelName = "${entityId}";
45
45
 
46
- @api({ httpMethod: "GET", clients: ["axios", "swr"], resourceName: "${smdId}" })
47
- async findById<T extends ${smdId}SubsetKey>(
46
+ @api({ httpMethod: "GET", clients: ["axios", "swr"], resourceName: "${entityId}" })
47
+ async findById<T extends ${entityId}SubsetKey>(
48
48
  subset: T,
49
49
  id: number
50
- ): Promise<${smdId}SubsetMapping[T]> {
50
+ ): Promise<${entityId}SubsetMapping[T]> {
51
51
  const { rows } = await this.findMany(subset, {
52
52
  id,
53
53
  num: 1,
@@ -60,10 +60,10 @@ class ${smdId}ModelClass extends BaseModelClass {
60
60
  return rows[0];
61
61
  }
62
62
 
63
- async findOne<T extends ${smdId}SubsetKey>(
63
+ async findOne<T extends ${entityId}SubsetKey>(
64
64
  subset: T,
65
- listParams: ${smdId}ListParams
66
- ): Promise<${smdId}SubsetMapping[T] | null> {
65
+ listParams: ${entityId}ListParams
66
+ ): Promise<${entityId}SubsetMapping[T] | null> {
67
67
  const { rows } = await this.findMany(subset, {
68
68
  ...listParams,
69
69
  num: 1,
@@ -74,10 +74,10 @@ class ${smdId}ModelClass extends BaseModelClass {
74
74
  }
75
75
 
76
76
  @api({ httpMethod: "GET", clients: ["axios", "swr"], resourceName: "${names.capitalPlural}" })
77
- async findMany<T extends ${smdId}SubsetKey>(
77
+ async findMany<T extends ${entityId}SubsetKey>(
78
78
  subset: T,
79
- params: ${smdId}ListParams = {}
80
- ): Promise<ListResult<${smdId}SubsetMapping[T]>> {
79
+ params: ${entityId}ListParams = {}
80
+ ): Promise<ListResult<${entityId}SubsetMapping[T]>> {
81
81
  // params with defaults
82
82
  params = {
83
83
  num: 24,
@@ -95,15 +95,15 @@ class ${smdId}ModelClass extends BaseModelClass {
95
95
  build: ({ qb }) => {
96
96
  // id
97
97
  if (params.id) {
98
- qb.whereIn("${smd.table}.id", asArray(params.id));
98
+ qb.whereIn("${entity.table}.id", asArray(params.id));
99
99
  }
100
100
 
101
101
  // search-keyword
102
102
  if (params.search && params.keyword && params.keyword.length > 0) {
103
103
  if (params.search === "id") {
104
- qb.where("${smd.table}.id", params.keyword);
104
+ qb.where("${entity.table}.id", params.keyword);
105
105
  // } else if (params.search === "field") {
106
- // qb.where("${smd.table}.field", "like", \`%\${params.keyword}%\`);
106
+ // qb.where("${entity.table}.field", "like", \`%\${params.keyword}%\`);
107
107
  } else {
108
108
  throw new BadRequestException(
109
109
  \`구현되지 않은 검색 필드 \${params.search}\`
@@ -115,7 +115,7 @@ class ${smdId}ModelClass extends BaseModelClass {
115
115
  if (params.orderBy) {
116
116
  // default orderBy
117
117
  const [orderByField, orderByDirec] = params.orderBy.split("-");
118
- qb.orderBy("${smd.table}." + orderByField, orderByDirec);
118
+ qb.orderBy("${entity.table}." + orderByField, orderByDirec);
119
119
  }
120
120
 
121
121
  return qb;
@@ -131,19 +131,19 @@ class ${smdId}ModelClass extends BaseModelClass {
131
131
 
132
132
  @api({ httpMethod: "POST" })
133
133
  async save(
134
- saveParamsArray: ${smdId}SaveParams[]
134
+ saveParamsArray: ${entityId}SaveParams[]
135
135
  ): Promise<number[]> {
136
136
  const wdb = this.getDB("w");
137
137
  const ub = this.getUpsertBuilder();
138
138
 
139
139
  // register
140
140
  saveParamsArray.map((saveParams) => {
141
- ub.register("${smd.table}", saveParams);
141
+ ub.register("${entity.table}", saveParams);
142
142
  });
143
143
 
144
144
  // transaction
145
145
  return wdb.transaction(async (trx) => {
146
- const ids = await ub.upsert(trx, "${smd.table}");
146
+ const ids = await ub.upsert(trx, "${entity.table}");
147
147
 
148
148
  return ids;
149
149
  });
@@ -155,14 +155,14 @@ class ${smdId}ModelClass extends BaseModelClass {
155
155
 
156
156
  // transaction
157
157
  await wdb.transaction(async (trx) => {
158
- return trx("${smd.table}").whereIn("${smd.table}.id", ids).delete();
158
+ return trx("${entity.table}").whereIn("${entity.table}.id", ids).delete();
159
159
  });
160
160
 
161
161
  return ids.length;
162
162
  }
163
163
  }
164
164
 
165
- export const ${smdId}Model = new ${smdId}ModelClass();
165
+ export const ${entityId}Model = new ${entityId}ModelClass();
166
166
  `.trim(),
167
167
  importKeys: [],
168
168
  };
@@ -1,5 +1,5 @@
1
1
  import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
2
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
3
3
  import { Template } from "./base-template";
4
4
 
5
5
  export class Template__model_test extends Template {
@@ -7,15 +7,15 @@ export class Template__model_test extends Template {
7
7
  super("model_test");
8
8
  }
9
9
 
10
- getTargetAndPath(names: SMDNamesRecord) {
10
+ getTargetAndPath(names: EntityNamesRecord) {
11
11
  return {
12
12
  target: "api/src/application",
13
13
  path: `${names.fs}/${names.fs}.model.test.ts`,
14
14
  };
15
15
  }
16
16
 
17
- render({ smdId }: TemplateOptions["model_test"]) {
18
- const names = SMDManager.getNamesFromId(smdId);
17
+ render({ entityId }: TemplateOptions["model_test"]) {
18
+ const names = EntityManager.getNamesFromId(entityId);
19
19
 
20
20
  return {
21
21
  ...this.getTargetAndPath(names),
@@ -24,7 +24,7 @@ import { describe, test, expect } from "vitest";
24
24
  import { bootstrap } from '../../testing/bootstrap';
25
25
 
26
26
  bootstrap([]);
27
- describe.skip("${smdId}ModelTest", () => {
27
+ describe.skip("${entityId}ModelTest", () => {
28
28
  test("Query", async () => {
29
29
  expect(true).toBe(true);
30
30
  });
@@ -1,7 +1,7 @@
1
1
  import { camelize } from "inflection";
2
2
  import { groupBy, sortBy, difference, uniq } from "lodash";
3
3
  import { TemplateOptions } from "../types/types";
4
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
4
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
5
5
  import { ApiParamType, ApiParam } from "../types/types";
6
6
  import {
7
7
  apiParamTypeToTsType,
@@ -17,15 +17,15 @@ export class Template__service extends Template {
17
17
  super("service");
18
18
  }
19
19
 
20
- getTargetAndPath(names: SMDNamesRecord) {
20
+ getTargetAndPath(names: EntityNamesRecord) {
21
21
  return {
22
22
  target: ":target/src/services",
23
23
  path: `${names.fs}/${names.fs}.service.ts`,
24
24
  };
25
25
  }
26
26
 
27
- render({ smdId }: TemplateOptions["service"], apis: ExtendedApi[]) {
28
- const names = SMDManager.getNamesFromId(smdId);
27
+ render({ entityId }: TemplateOptions["service"], apis: ExtendedApi[]) {
28
+ const names = EntityManager.getNamesFromId(entityId);
29
29
 
30
30
  // 서비스 TypeSource
31
31
  const { lines, importKeys } = this.getTypeSource(apis);
@@ -1,5 +1,5 @@
1
1
  import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
2
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
3
3
  import { Template } from "./base-template";
4
4
 
5
5
  export class Template__view_enums_buttonset extends Template {
@@ -7,15 +7,15 @@ export class Template__view_enums_buttonset extends Template {
7
7
  super("view_enums_buttonset");
8
8
  }
9
9
 
10
- getTargetAndPath(names: SMDNamesRecord, componentId: string) {
10
+ getTargetAndPath(names: EntityNamesRecord, componentId: string) {
11
11
  return {
12
12
  target: "web/src/components",
13
13
  path: `${names.fs}/${componentId}ButtonSet.tsx`,
14
14
  };
15
15
  }
16
16
 
17
- render({ smdId, enumId }: TemplateOptions["view_enums_buttonset"]) {
18
- const names = SMDManager.getNamesFromId(smdId);
17
+ render({ entityId, enumId }: TemplateOptions["view_enums_buttonset"]) {
18
+ const names = EntityManager.getNamesFromId(entityId);
19
19
 
20
20
  return {
21
21
  ...this.getTargetAndPath(names, enumId),
@@ -24,7 +24,7 @@ export class Template__view_enums_buttonset extends Template {
24
24
  view_enums_buttonset
25
25
  ${JSON.stringify({
26
26
  key: this.key,
27
- options: smdId,
27
+ options: entityId,
28
28
  })}
29
29
  */
30
30
  `.trim(),
@@ -1,5 +1,5 @@
1
1
  import { TemplateOptions } from "../types/types";
2
- import { SMDManager, SMDNamesRecord } from "../smd/smd-manager";
2
+ import { EntityManager, EntityNamesRecord } from "../entity/entity-manager";
3
3
  import { Template } from "./base-template";
4
4
 
5
5
  export class Template__view_enums_dropdown extends Template {
@@ -7,7 +7,7 @@ export class Template__view_enums_dropdown extends Template {
7
7
  super("view_enums_dropdown");
8
8
  }
9
9
 
10
- getTargetAndPath(names: SMDNamesRecord, enumId: string) {
10
+ getTargetAndPath(names: EntityNamesRecord, enumId: string) {
11
11
  return {
12
12
  target: "web/src/components",
13
13
  path: `${names.fs}/${enumId}Dropdown.tsx`,
@@ -15,11 +15,11 @@ export class Template__view_enums_dropdown extends Template {
15
15
  }
16
16
 
17
17
  render({
18
- smdId,
18
+ entityId,
19
19
  enumId,
20
20
  idConstant,
21
21
  }: TemplateOptions["view_enums_dropdown"]) {
22
- const names = SMDManager.getNamesFromId(smdId);
22
+ const names = EntityManager.getNamesFromId(entityId);
23
23
  const label = getLabel(idConstant);
24
24
 
25
25
  return {