@nahisaho/musubix-core 1.0.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 (214) hide show
  1. package/bin/musubix.js +18 -0
  2. package/dist/__tests__/index.test.d.ts +2 -0
  3. package/dist/__tests__/index.test.d.ts.map +1 -0
  4. package/dist/__tests__/index.test.js +27 -0
  5. package/dist/__tests__/index.test.js.map +1 -0
  6. package/dist/auth/auth-manager.d.ts +320 -0
  7. package/dist/auth/auth-manager.d.ts.map +1 -0
  8. package/dist/auth/auth-manager.js +580 -0
  9. package/dist/auth/auth-manager.js.map +1 -0
  10. package/dist/cli/base.d.ts +58 -0
  11. package/dist/cli/base.d.ts.map +1 -0
  12. package/dist/cli/base.js +93 -0
  13. package/dist/cli/base.js.map +1 -0
  14. package/dist/cli/commands/help.d.ts +17 -0
  15. package/dist/cli/commands/help.d.ts.map +1 -0
  16. package/dist/cli/commands/help.js +228 -0
  17. package/dist/cli/commands/help.js.map +1 -0
  18. package/dist/cli/commands/index.d.ts +14 -0
  19. package/dist/cli/commands/index.d.ts.map +1 -0
  20. package/dist/cli/commands/index.js +25 -0
  21. package/dist/cli/commands/index.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts +38 -0
  23. package/dist/cli/commands/init.d.ts.map +1 -0
  24. package/dist/cli/commands/init.js +258 -0
  25. package/dist/cli/commands/init.js.map +1 -0
  26. package/dist/cli/index.d.ts +9 -0
  27. package/dist/cli/index.d.ts.map +1 -0
  28. package/dist/cli/index.js +9 -0
  29. package/dist/cli/index.js.map +1 -0
  30. package/dist/codegen/coding-standards.d.ts +250 -0
  31. package/dist/codegen/coding-standards.d.ts.map +1 -0
  32. package/dist/codegen/coding-standards.js +976 -0
  33. package/dist/codegen/coding-standards.js.map +1 -0
  34. package/dist/codegen/coverage-reporter.d.ts +264 -0
  35. package/dist/codegen/coverage-reporter.d.ts.map +1 -0
  36. package/dist/codegen/coverage-reporter.js +697 -0
  37. package/dist/codegen/coverage-reporter.js.map +1 -0
  38. package/dist/codegen/dependency-analyzer.d.ts +271 -0
  39. package/dist/codegen/dependency-analyzer.d.ts.map +1 -0
  40. package/dist/codegen/dependency-analyzer.js +661 -0
  41. package/dist/codegen/dependency-analyzer.js.map +1 -0
  42. package/dist/codegen/generator.d.ts +275 -0
  43. package/dist/codegen/generator.d.ts.map +1 -0
  44. package/dist/codegen/generator.js +781 -0
  45. package/dist/codegen/generator.js.map +1 -0
  46. package/dist/codegen/index.d.ts +18 -0
  47. package/dist/codegen/index.d.ts.map +1 -0
  48. package/dist/codegen/index.js +27 -0
  49. package/dist/codegen/index.js.map +1 -0
  50. package/dist/codegen/integration-test-generator.d.ts +312 -0
  51. package/dist/codegen/integration-test-generator.d.ts.map +1 -0
  52. package/dist/codegen/integration-test-generator.js +765 -0
  53. package/dist/codegen/integration-test-generator.js.map +1 -0
  54. package/dist/codegen/pattern-conformance.d.ts +309 -0
  55. package/dist/codegen/pattern-conformance.d.ts.map +1 -0
  56. package/dist/codegen/pattern-conformance.js +590 -0
  57. package/dist/codegen/pattern-conformance.js.map +1 -0
  58. package/dist/codegen/quality-metrics.d.ts +235 -0
  59. package/dist/codegen/quality-metrics.d.ts.map +1 -0
  60. package/dist/codegen/quality-metrics.js +439 -0
  61. package/dist/codegen/quality-metrics.js.map +1 -0
  62. package/dist/codegen/security-scanner.d.ts +179 -0
  63. package/dist/codegen/security-scanner.d.ts.map +1 -0
  64. package/dist/codegen/security-scanner.js +495 -0
  65. package/dist/codegen/security-scanner.js.map +1 -0
  66. package/dist/codegen/static-analyzer.d.ts +188 -0
  67. package/dist/codegen/static-analyzer.d.ts.map +1 -0
  68. package/dist/codegen/static-analyzer.js +490 -0
  69. package/dist/codegen/static-analyzer.js.map +1 -0
  70. package/dist/codegen/unit-test-generator.d.ts +289 -0
  71. package/dist/codegen/unit-test-generator.d.ts.map +1 -0
  72. package/dist/codegen/unit-test-generator.js +634 -0
  73. package/dist/codegen/unit-test-generator.js.map +1 -0
  74. package/dist/design/adr-generator.d.ts +227 -0
  75. package/dist/design/adr-generator.d.ts.map +1 -0
  76. package/dist/design/adr-generator.js +423 -0
  77. package/dist/design/adr-generator.js.map +1 -0
  78. package/dist/design/c4-generator.d.ts +267 -0
  79. package/dist/design/c4-generator.d.ts.map +1 -0
  80. package/dist/design/c4-generator.js +453 -0
  81. package/dist/design/c4-generator.js.map +1 -0
  82. package/dist/design/framework-optimizer.d.ts +190 -0
  83. package/dist/design/framework-optimizer.d.ts.map +1 -0
  84. package/dist/design/framework-optimizer.js +589 -0
  85. package/dist/design/framework-optimizer.js.map +1 -0
  86. package/dist/design/index.d.ts +12 -0
  87. package/dist/design/index.d.ts.map +1 -0
  88. package/dist/design/index.js +13 -0
  89. package/dist/design/index.js.map +1 -0
  90. package/dist/design/pattern-detector.d.ts +270 -0
  91. package/dist/design/pattern-detector.d.ts.map +1 -0
  92. package/dist/design/pattern-detector.js +621 -0
  93. package/dist/design/pattern-detector.js.map +1 -0
  94. package/dist/design/solid-validator.d.ts +188 -0
  95. package/dist/design/solid-validator.d.ts.map +1 -0
  96. package/dist/design/solid-validator.js +579 -0
  97. package/dist/design/solid-validator.js.map +1 -0
  98. package/dist/error/data-persistence.d.ts +311 -0
  99. package/dist/error/data-persistence.d.ts.map +1 -0
  100. package/dist/error/data-persistence.js +586 -0
  101. package/dist/error/data-persistence.js.map +1 -0
  102. package/dist/error/graceful-degradation.d.ts +309 -0
  103. package/dist/error/graceful-degradation.d.ts.map +1 -0
  104. package/dist/error/graceful-degradation.js +510 -0
  105. package/dist/error/graceful-degradation.js.map +1 -0
  106. package/dist/error/index.d.ts +11 -0
  107. package/dist/error/index.d.ts.map +1 -0
  108. package/dist/error/index.js +19 -0
  109. package/dist/error/index.js.map +1 -0
  110. package/dist/explanation/explanation-generator.d.ts +228 -0
  111. package/dist/explanation/explanation-generator.d.ts.map +1 -0
  112. package/dist/explanation/explanation-generator.js +662 -0
  113. package/dist/explanation/explanation-generator.js.map +1 -0
  114. package/dist/explanation/index.d.ts +11 -0
  115. package/dist/explanation/index.d.ts.map +1 -0
  116. package/dist/explanation/index.js +19 -0
  117. package/dist/explanation/index.js.map +1 -0
  118. package/dist/explanation/reasoning-chain.d.ts +314 -0
  119. package/dist/explanation/reasoning-chain.d.ts.map +1 -0
  120. package/dist/explanation/reasoning-chain.js +414 -0
  121. package/dist/explanation/reasoning-chain.js.map +1 -0
  122. package/dist/explanation/visual-explanation.d.ts +315 -0
  123. package/dist/explanation/visual-explanation.d.ts.map +1 -0
  124. package/dist/explanation/visual-explanation.js +667 -0
  125. package/dist/explanation/visual-explanation.js.map +1 -0
  126. package/dist/index.d.ts +33 -0
  127. package/dist/index.d.ts.map +1 -0
  128. package/dist/index.js +47 -0
  129. package/dist/index.js.map +1 -0
  130. package/dist/requirements/decomposer.d.ts +235 -0
  131. package/dist/requirements/decomposer.d.ts.map +1 -0
  132. package/dist/requirements/decomposer.js +587 -0
  133. package/dist/requirements/decomposer.js.map +1 -0
  134. package/dist/requirements/related-finder.d.ts +261 -0
  135. package/dist/requirements/related-finder.d.ts.map +1 -0
  136. package/dist/requirements/related-finder.js +629 -0
  137. package/dist/requirements/related-finder.js.map +1 -0
  138. package/dist/traceability/impact.d.ts +196 -0
  139. package/dist/traceability/impact.d.ts.map +1 -0
  140. package/dist/traceability/impact.js +438 -0
  141. package/dist/traceability/impact.js.map +1 -0
  142. package/dist/traceability/index.d.ts +9 -0
  143. package/dist/traceability/index.d.ts.map +1 -0
  144. package/dist/traceability/index.js +10 -0
  145. package/dist/traceability/index.js.map +1 -0
  146. package/dist/traceability/manager.d.ts +266 -0
  147. package/dist/traceability/manager.d.ts.map +1 -0
  148. package/dist/traceability/manager.js +412 -0
  149. package/dist/traceability/manager.js.map +1 -0
  150. package/dist/types/common.d.ts +294 -0
  151. package/dist/types/common.d.ts.map +1 -0
  152. package/dist/types/common.js +15 -0
  153. package/dist/types/common.js.map +1 -0
  154. package/dist/types/ears.d.ts +158 -0
  155. package/dist/types/ears.d.ts.map +1 -0
  156. package/dist/types/ears.js +33 -0
  157. package/dist/types/ears.js.map +1 -0
  158. package/dist/types/errors.d.ts +176 -0
  159. package/dist/types/errors.d.ts.map +1 -0
  160. package/dist/types/errors.js +55 -0
  161. package/dist/types/errors.js.map +1 -0
  162. package/dist/types/index.d.ts +10 -0
  163. package/dist/types/index.d.ts.map +1 -0
  164. package/dist/types/index.js +10 -0
  165. package/dist/types/index.js.map +1 -0
  166. package/dist/utils/data-protector.d.ts +122 -0
  167. package/dist/utils/data-protector.d.ts.map +1 -0
  168. package/dist/utils/data-protector.js +275 -0
  169. package/dist/utils/data-protector.js.map +1 -0
  170. package/dist/utils/error-handler.d.ts +101 -0
  171. package/dist/utils/error-handler.d.ts.map +1 -0
  172. package/dist/utils/error-handler.js +324 -0
  173. package/dist/utils/error-handler.js.map +1 -0
  174. package/dist/utils/i18n-manager.d.ts +259 -0
  175. package/dist/utils/i18n-manager.d.ts.map +1 -0
  176. package/dist/utils/i18n-manager.js +554 -0
  177. package/dist/utils/i18n-manager.js.map +1 -0
  178. package/dist/utils/index.d.ts +10 -0
  179. package/dist/utils/index.d.ts.map +1 -0
  180. package/dist/utils/index.js +10 -0
  181. package/dist/utils/index.js.map +1 -0
  182. package/dist/utils/logger.d.ts +120 -0
  183. package/dist/utils/logger.d.ts.map +1 -0
  184. package/dist/utils/logger.js +237 -0
  185. package/dist/utils/logger.js.map +1 -0
  186. package/dist/utils/performance-profiler.d.ts +251 -0
  187. package/dist/utils/performance-profiler.d.ts.map +1 -0
  188. package/dist/utils/performance-profiler.js +458 -0
  189. package/dist/utils/performance-profiler.js.map +1 -0
  190. package/dist/utils/scalability-optimizer.d.ts +294 -0
  191. package/dist/utils/scalability-optimizer.d.ts.map +1 -0
  192. package/dist/utils/scalability-optimizer.js +606 -0
  193. package/dist/utils/scalability-optimizer.js.map +1 -0
  194. package/dist/utils/structured-logger.d.ts +294 -0
  195. package/dist/utils/structured-logger.d.ts.map +1 -0
  196. package/dist/utils/structured-logger.js +630 -0
  197. package/dist/utils/structured-logger.js.map +1 -0
  198. package/dist/utils/version-compatibility.d.ts +217 -0
  199. package/dist/utils/version-compatibility.d.ts.map +1 -0
  200. package/dist/utils/version-compatibility.js +443 -0
  201. package/dist/utils/version-compatibility.js.map +1 -0
  202. package/dist/validators/ears-validator.d.ts +182 -0
  203. package/dist/validators/ears-validator.d.ts.map +1 -0
  204. package/dist/validators/ears-validator.js +357 -0
  205. package/dist/validators/ears-validator.js.map +1 -0
  206. package/dist/validators/index.d.ts +8 -0
  207. package/dist/validators/index.d.ts.map +1 -0
  208. package/dist/validators/index.js +9 -0
  209. package/dist/validators/index.js.map +1 -0
  210. package/dist/version.d.ts +8 -0
  211. package/dist/version.d.ts.map +1 -0
  212. package/dist/version.js +8 -0
  213. package/dist/version.js.map +1 -0
  214. package/package.json +100 -0
@@ -0,0 +1,781 @@
1
+ /**
2
+ * Code Generator
3
+ *
4
+ * Generates code from design specifications
5
+ *
6
+ * @packageDocumentation
7
+ * @module codegen/generator
8
+ *
9
+ * @see REQ-COD-001 - Code Generation
10
+ * @see Article V - Code Generation Standards
11
+ */
12
+ /**
13
+ * Default options
14
+ */
15
+ export const DEFAULT_GENERATOR_OPTIONS = {
16
+ language: 'typescript',
17
+ strictMode: true,
18
+ generateDocs: true,
19
+ indent: ' ',
20
+ lineEnding: '\n',
21
+ maxLineLength: 100,
22
+ styleGuide: 'standard',
23
+ };
24
+ /**
25
+ * Language configurations
26
+ */
27
+ const LANGUAGE_CONFIGS = {
28
+ typescript: {
29
+ fileExtension: '.ts',
30
+ typePrefix: '',
31
+ typeSuffix: '',
32
+ visibility: { public: 'public', private: 'private', protected: 'protected' },
33
+ nullableSymbol: '?',
34
+ asyncKeyword: 'async',
35
+ classKeyword: 'class',
36
+ interfaceKeyword: 'interface',
37
+ importStyle: 'es6',
38
+ },
39
+ javascript: {
40
+ fileExtension: '.js',
41
+ typePrefix: '',
42
+ typeSuffix: '',
43
+ visibility: { public: '', private: '#', protected: '' },
44
+ nullableSymbol: '',
45
+ asyncKeyword: 'async',
46
+ classKeyword: 'class',
47
+ interfaceKeyword: '',
48
+ importStyle: 'es6',
49
+ },
50
+ python: {
51
+ fileExtension: '.py',
52
+ typePrefix: '',
53
+ typeSuffix: '',
54
+ visibility: { public: '', private: '_', protected: '_' },
55
+ nullableSymbol: ' | None',
56
+ asyncKeyword: 'async',
57
+ classKeyword: 'class',
58
+ interfaceKeyword: '',
59
+ importStyle: 'python',
60
+ },
61
+ java: {
62
+ fileExtension: '.java',
63
+ typePrefix: '',
64
+ typeSuffix: '',
65
+ visibility: { public: 'public', private: 'private', protected: 'protected' },
66
+ nullableSymbol: '',
67
+ asyncKeyword: '',
68
+ classKeyword: 'class',
69
+ interfaceKeyword: 'interface',
70
+ importStyle: 'java',
71
+ },
72
+ csharp: {
73
+ fileExtension: '.cs',
74
+ typePrefix: '',
75
+ typeSuffix: '',
76
+ visibility: { public: 'public', private: 'private', protected: 'protected' },
77
+ nullableSymbol: '?',
78
+ asyncKeyword: 'async',
79
+ classKeyword: 'class',
80
+ interfaceKeyword: 'interface',
81
+ importStyle: 'csharp',
82
+ },
83
+ go: {
84
+ fileExtension: '.go',
85
+ typePrefix: '',
86
+ typeSuffix: '',
87
+ visibility: { public: '', private: '', protected: '' },
88
+ nullableSymbol: '*',
89
+ asyncKeyword: '',
90
+ classKeyword: 'type',
91
+ interfaceKeyword: 'type',
92
+ importStyle: 'go',
93
+ },
94
+ rust: {
95
+ fileExtension: '.rs',
96
+ typePrefix: '',
97
+ typeSuffix: '',
98
+ visibility: { public: 'pub', private: '', protected: 'pub(crate)' },
99
+ nullableSymbol: 'Option<>',
100
+ asyncKeyword: 'async',
101
+ classKeyword: 'struct',
102
+ interfaceKeyword: 'trait',
103
+ importStyle: 'rust',
104
+ },
105
+ };
106
+ /**
107
+ * Code Generator
108
+ */
109
+ export class CodeGenerator {
110
+ options;
111
+ langConfig;
112
+ constructor(options) {
113
+ this.options = { ...DEFAULT_GENERATOR_OPTIONS, ...options };
114
+ this.langConfig = LANGUAGE_CONFIGS[this.options.language];
115
+ }
116
+ /**
117
+ * Generate code from structure definition
118
+ */
119
+ generate(definition) {
120
+ const warnings = [];
121
+ let code = '';
122
+ // Generate imports
123
+ const imports = this.generateImports(definition.dependencies ?? []);
124
+ if (imports) {
125
+ code += imports + this.options.lineEnding + this.options.lineEnding;
126
+ }
127
+ // Generate documentation
128
+ if (this.options.generateDocs && definition.description) {
129
+ code += this.generateDocumentation(definition.description);
130
+ }
131
+ // Generate decorators
132
+ if (definition.decorators) {
133
+ code += this.generateDecorators(definition.decorators);
134
+ }
135
+ // Generate structure based on type
136
+ switch (definition.type) {
137
+ case 'class':
138
+ case 'service':
139
+ case 'controller':
140
+ case 'repository':
141
+ code += this.generateClass(definition);
142
+ break;
143
+ case 'interface':
144
+ code += this.generateInterface(definition);
145
+ break;
146
+ case 'function':
147
+ code += this.generateFunction(definition);
148
+ break;
149
+ case 'module':
150
+ code += this.generateModule(definition);
151
+ break;
152
+ case 'model':
153
+ code += this.generateModel(definition);
154
+ break;
155
+ case 'api-endpoint':
156
+ code += this.generateApiEndpoint(definition);
157
+ break;
158
+ default:
159
+ warnings.push(`Unknown template type: ${definition.type}`);
160
+ code += this.generateClass(definition);
161
+ }
162
+ return {
163
+ code,
164
+ language: this.options.language,
165
+ fileName: this.generateFileName(definition.name),
166
+ imports: this.extractImportModules(definition.dependencies ?? []),
167
+ dependencies: this.extractDependencies(definition.dependencies ?? []),
168
+ warnings,
169
+ };
170
+ }
171
+ /**
172
+ * Generate multiple structures
173
+ */
174
+ generateBatch(definitions) {
175
+ return definitions.map((def) => this.generate(def));
176
+ }
177
+ /**
178
+ * Generate imports
179
+ */
180
+ generateImports(dependencies) {
181
+ if (dependencies.length === 0)
182
+ return '';
183
+ const lines = [];
184
+ for (const dep of dependencies) {
185
+ lines.push(this.formatImport(dep));
186
+ }
187
+ return lines.join(this.options.lineEnding);
188
+ }
189
+ /**
190
+ * Format single import
191
+ */
192
+ formatImport(dep) {
193
+ const { language } = this.options;
194
+ const imports = dep.imports.join(', ');
195
+ switch (language) {
196
+ case 'typescript':
197
+ case 'javascript':
198
+ if (dep.typeOnly && language === 'typescript') {
199
+ return `import type { ${imports} } from '${dep.module}';`;
200
+ }
201
+ return `import { ${imports} } from '${dep.module}';`;
202
+ case 'python':
203
+ return `from ${dep.module} import ${imports}`;
204
+ case 'java':
205
+ return dep.imports.map((i) => `import ${dep.module}.${i};`).join('\n');
206
+ case 'csharp':
207
+ return `using ${dep.module};`;
208
+ case 'go':
209
+ return `import "${dep.module}"`;
210
+ case 'rust':
211
+ return `use ${dep.module}::{${imports}};`;
212
+ default:
213
+ return `import { ${imports} } from '${dep.module}';`;
214
+ }
215
+ }
216
+ /**
217
+ * Generate documentation comment
218
+ */
219
+ generateDocumentation(description, params) {
220
+ const { language, indent } = this.options;
221
+ const lines = [];
222
+ switch (language) {
223
+ case 'typescript':
224
+ case 'javascript':
225
+ case 'java':
226
+ case 'csharp':
227
+ lines.push('/**');
228
+ lines.push(` * ${description}`);
229
+ if (params) {
230
+ lines.push(' *');
231
+ for (const p of params) {
232
+ lines.push(` * @param ${p.name} ${p.description ?? p.type}`);
233
+ }
234
+ }
235
+ lines.push(' */');
236
+ break;
237
+ case 'python':
238
+ lines.push('"""');
239
+ lines.push(description);
240
+ if (params) {
241
+ lines.push('');
242
+ lines.push('Args:');
243
+ for (const p of params) {
244
+ lines.push(`${indent}${p.name}: ${p.description ?? p.type}`);
245
+ }
246
+ }
247
+ lines.push('"""');
248
+ break;
249
+ case 'go':
250
+ lines.push(`// ${description}`);
251
+ break;
252
+ case 'rust':
253
+ lines.push(`/// ${description}`);
254
+ break;
255
+ }
256
+ return lines.join(this.options.lineEnding) + this.options.lineEnding;
257
+ }
258
+ /**
259
+ * Generate decorators
260
+ */
261
+ generateDecorators(decorators) {
262
+ const { language } = this.options;
263
+ const lines = [];
264
+ for (const dec of decorators) {
265
+ switch (language) {
266
+ case 'typescript':
267
+ case 'javascript':
268
+ if (dec.arguments?.length) {
269
+ lines.push(`@${dec.name}(${dec.arguments.join(', ')})`);
270
+ }
271
+ else {
272
+ lines.push(`@${dec.name}()`);
273
+ }
274
+ break;
275
+ case 'python':
276
+ if (dec.arguments?.length) {
277
+ lines.push(`@${dec.name}(${dec.arguments.join(', ')})`);
278
+ }
279
+ else {
280
+ lines.push(`@${dec.name}`);
281
+ }
282
+ break;
283
+ case 'java':
284
+ if (dec.arguments?.length) {
285
+ lines.push(`@${dec.name}(${dec.arguments.join(', ')})`);
286
+ }
287
+ else {
288
+ lines.push(`@${dec.name}`);
289
+ }
290
+ break;
291
+ case 'csharp':
292
+ if (dec.arguments?.length) {
293
+ lines.push(`[${dec.name}(${dec.arguments.join(', ')})]`);
294
+ }
295
+ else {
296
+ lines.push(`[${dec.name}]`);
297
+ }
298
+ break;
299
+ default:
300
+ // Go and Rust don't have decorators
301
+ break;
302
+ }
303
+ }
304
+ return lines.length > 0
305
+ ? lines.join(this.options.lineEnding) + this.options.lineEnding
306
+ : '';
307
+ }
308
+ /**
309
+ * Generate class
310
+ */
311
+ generateClass(definition) {
312
+ const { language, indent } = this.options;
313
+ const lines = [];
314
+ // Class declaration
315
+ const inheritance = this.formatInheritance(definition.inheritance);
316
+ switch (language) {
317
+ case 'typescript':
318
+ case 'javascript':
319
+ lines.push(`export ${this.langConfig.classKeyword} ${definition.name}${inheritance} {`);
320
+ break;
321
+ case 'python':
322
+ lines.push(`class ${definition.name}${inheritance}:`);
323
+ break;
324
+ case 'java':
325
+ case 'csharp':
326
+ lines.push(`public ${this.langConfig.classKeyword} ${definition.name}${inheritance} {`);
327
+ break;
328
+ case 'go':
329
+ lines.push(`type ${definition.name} struct {`);
330
+ break;
331
+ case 'rust':
332
+ lines.push(`pub struct ${definition.name} {`);
333
+ break;
334
+ }
335
+ // Properties
336
+ if (definition.properties) {
337
+ for (const prop of definition.properties) {
338
+ lines.push(this.generateProperty(prop));
339
+ }
340
+ if (definition.methods?.length) {
341
+ lines.push('');
342
+ }
343
+ }
344
+ // Constructor (for some languages)
345
+ if (language === 'python' && definition.properties?.length) {
346
+ lines.push(this.generatePythonInit(definition.properties));
347
+ }
348
+ // Methods
349
+ if (definition.methods) {
350
+ for (const method of definition.methods) {
351
+ lines.push(this.generateMethod(method));
352
+ }
353
+ }
354
+ // Close class
355
+ switch (language) {
356
+ case 'python':
357
+ if (!definition.properties?.length && !definition.methods?.length) {
358
+ lines.push(`${indent}pass`);
359
+ }
360
+ break;
361
+ default:
362
+ lines.push('}');
363
+ }
364
+ return lines.join(this.options.lineEnding);
365
+ }
366
+ /**
367
+ * Generate interface
368
+ */
369
+ generateInterface(definition) {
370
+ const { language, indent } = this.options;
371
+ const lines = [];
372
+ switch (language) {
373
+ case 'typescript':
374
+ lines.push(`export interface ${definition.name} {`);
375
+ for (const prop of definition.properties ?? []) {
376
+ const optional = prop.optional ? '?' : '';
377
+ lines.push(`${indent}${prop.name}${optional}: ${prop.type};`);
378
+ }
379
+ for (const method of definition.methods ?? []) {
380
+ const params = this.formatParameters(method.parameters ?? []);
381
+ lines.push(`${indent}${method.name}(${params}): ${method.returnType ?? 'void'};`);
382
+ }
383
+ lines.push('}');
384
+ break;
385
+ case 'java':
386
+ lines.push(`public interface ${definition.name} {`);
387
+ for (const method of definition.methods ?? []) {
388
+ const params = this.formatParameters(method.parameters ?? []);
389
+ lines.push(`${indent}${method.returnType ?? 'void'} ${method.name}(${params});`);
390
+ }
391
+ lines.push('}');
392
+ break;
393
+ case 'go':
394
+ lines.push(`type ${definition.name} interface {`);
395
+ for (const method of definition.methods ?? []) {
396
+ const params = this.formatParameters(method.parameters ?? []);
397
+ lines.push(`${indent}${method.name}(${params}) ${method.returnType ?? ''}`);
398
+ }
399
+ lines.push('}');
400
+ break;
401
+ case 'rust':
402
+ lines.push(`pub trait ${definition.name} {`);
403
+ for (const method of definition.methods ?? []) {
404
+ const params = this.formatParameters(method.parameters ?? []);
405
+ const ret = method.returnType ? ` -> ${method.returnType}` : '';
406
+ lines.push(`${indent}fn ${method.name}(&self, ${params})${ret};`);
407
+ }
408
+ lines.push('}');
409
+ break;
410
+ default:
411
+ // Python, JavaScript, C# - use abstract class or type alias
412
+ return this.generateClass({ ...definition, type: 'class' });
413
+ }
414
+ return lines.join(this.options.lineEnding);
415
+ }
416
+ /**
417
+ * Generate function
418
+ */
419
+ generateFunction(definition) {
420
+ const { language, indent } = this.options;
421
+ const method = definition.methods?.[0];
422
+ if (!method)
423
+ return '';
424
+ const lines = [];
425
+ const params = this.formatParameters(method.parameters ?? []);
426
+ const async = method.async ? this.langConfig.asyncKeyword + ' ' : '';
427
+ switch (language) {
428
+ case 'typescript':
429
+ lines.push(`export ${async}function ${method.name}(${params}): ${method.returnType ?? 'void'} {`);
430
+ lines.push(`${indent}// TODO: Implement`);
431
+ lines.push(`${indent}throw new Error('Not implemented');`);
432
+ lines.push('}');
433
+ break;
434
+ case 'javascript':
435
+ lines.push(`export ${async}function ${method.name}(${params}) {`);
436
+ lines.push(`${indent}// TODO: Implement`);
437
+ lines.push(`${indent}throw new Error('Not implemented');`);
438
+ lines.push('}');
439
+ break;
440
+ case 'python':
441
+ const retType = method.returnType ? ` -> ${method.returnType}` : '';
442
+ lines.push(`${async}def ${method.name}(${params})${retType}:`);
443
+ lines.push(`${indent}# TODO: Implement`);
444
+ lines.push(`${indent}raise NotImplementedError()`);
445
+ break;
446
+ case 'go':
447
+ lines.push(`func ${method.name}(${params}) ${method.returnType ?? ''} {`);
448
+ lines.push(`${indent}// TODO: Implement`);
449
+ lines.push(`${indent}panic("not implemented")`);
450
+ lines.push('}');
451
+ break;
452
+ case 'rust':
453
+ const ret = method.returnType ? ` -> ${method.returnType}` : '';
454
+ lines.push(`pub ${async}fn ${method.name}(${params})${ret} {`);
455
+ lines.push(`${indent}// TODO: Implement`);
456
+ lines.push(`${indent}todo!()`);
457
+ lines.push('}');
458
+ break;
459
+ default:
460
+ lines.push(`// Function: ${method.name}`);
461
+ }
462
+ return lines.join(this.options.lineEnding);
463
+ }
464
+ /**
465
+ * Generate module
466
+ */
467
+ generateModule(definition) {
468
+ const { language } = this.options;
469
+ const lines = [];
470
+ // Generate exports for all properties and methods
471
+ switch (language) {
472
+ case 'typescript':
473
+ case 'javascript':
474
+ for (const prop of definition.properties ?? []) {
475
+ lines.push(`export const ${prop.name}: ${prop.type} = ${prop.defaultValue ?? 'undefined'};`);
476
+ }
477
+ for (const method of definition.methods ?? []) {
478
+ const funcDef = {
479
+ name: method.name,
480
+ type: 'function',
481
+ methods: [method],
482
+ };
483
+ lines.push(this.generateFunction(funcDef));
484
+ }
485
+ break;
486
+ default:
487
+ lines.push(this.generateClass(definition));
488
+ }
489
+ return lines.join(this.options.lineEnding + this.options.lineEnding);
490
+ }
491
+ /**
492
+ * Generate model
493
+ */
494
+ generateModel(definition) {
495
+ // Models are typically data classes
496
+ return this.generateClass(definition);
497
+ }
498
+ /**
499
+ * Generate API endpoint
500
+ */
501
+ generateApiEndpoint(definition) {
502
+ const { language, indent } = this.options;
503
+ const lines = [];
504
+ switch (language) {
505
+ case 'typescript':
506
+ lines.push(`export class ${definition.name}Controller {`);
507
+ for (const method of definition.methods ?? []) {
508
+ const route = method.decorators?.find((d) => ['Get', 'Post', 'Put', 'Delete', 'Patch'].includes(d.name));
509
+ if (route) {
510
+ lines.push(`${indent}@${route.name}(${route.arguments?.map((a) => `'${a}'`).join(', ') ?? ''})`);
511
+ }
512
+ const params = this.formatParameters(method.parameters ?? []);
513
+ lines.push(`${indent}async ${method.name}(${params}): Promise<${method.returnType ?? 'void'}> {`);
514
+ lines.push(`${indent}${indent}// TODO: Implement`);
515
+ lines.push(`${indent}${indent}throw new Error('Not implemented');`);
516
+ lines.push(`${indent}}`);
517
+ lines.push('');
518
+ }
519
+ lines.push('}');
520
+ break;
521
+ default:
522
+ return this.generateClass(definition);
523
+ }
524
+ return lines.join(this.options.lineEnding);
525
+ }
526
+ /**
527
+ * Generate property
528
+ */
529
+ generateProperty(prop) {
530
+ const { language, indent } = this.options;
531
+ const visibility = this.formatVisibility(prop.visibility ?? 'public');
532
+ const readonly = prop.readonly ? 'readonly ' : '';
533
+ switch (language) {
534
+ case 'typescript':
535
+ const optional = prop.optional ? '?' : '';
536
+ const defaultVal = prop.defaultValue ? ` = ${prop.defaultValue}` : '';
537
+ return `${indent}${visibility}${readonly}${prop.name}${optional}: ${prop.type}${defaultVal};`;
538
+ case 'javascript':
539
+ const prefix = prop.visibility === 'private' ? '#' : '';
540
+ return `${indent}${prefix}${prop.name} = ${prop.defaultValue ?? 'undefined'};`;
541
+ case 'python':
542
+ return `${indent}${prop.name}: ${prop.type}`;
543
+ case 'java':
544
+ return `${indent}${visibility}${prop.type} ${prop.name};`;
545
+ case 'csharp':
546
+ return `${indent}${visibility}${prop.type} ${prop.name} { get; set; }`;
547
+ case 'go':
548
+ const goVisibility = prop.visibility === 'public'
549
+ ? prop.name.charAt(0).toUpperCase() + prop.name.slice(1)
550
+ : prop.name;
551
+ return `${indent}${goVisibility} ${prop.type}`;
552
+ case 'rust':
553
+ const rustVis = prop.visibility === 'public' ? 'pub ' : '';
554
+ return `${indent}${rustVis}${prop.name}: ${prop.type},`;
555
+ default:
556
+ return `${indent}${prop.name}: ${prop.type}`;
557
+ }
558
+ }
559
+ /**
560
+ * Generate method
561
+ */
562
+ generateMethod(method) {
563
+ const { language, indent } = this.options;
564
+ const lines = [];
565
+ const visibility = this.formatVisibility(method.visibility ?? 'public');
566
+ const params = this.formatParameters(method.parameters ?? []);
567
+ const async = method.async ? this.langConfig.asyncKeyword + ' ' : '';
568
+ const staticMod = method.static ? 'static ' : '';
569
+ // Documentation
570
+ if (this.options.generateDocs && method.description) {
571
+ const doc = this.generateDocumentation(method.description, method.parameters);
572
+ lines.push(doc.split('\n').map((l) => indent + l).join('\n'));
573
+ }
574
+ // Decorators
575
+ if (method.decorators) {
576
+ const decs = this.generateDecorators(method.decorators);
577
+ lines.push(decs.split('\n').map((l) => indent + l).join('\n'));
578
+ }
579
+ switch (language) {
580
+ case 'typescript':
581
+ lines.push(`${indent}${visibility}${staticMod}${async}${method.name}(${params}): ${method.returnType ?? 'void'} {`);
582
+ lines.push(`${indent}${indent}// TODO: Implement`);
583
+ if (method.implementation) {
584
+ lines.push(`${indent}${indent}${method.implementation}`);
585
+ }
586
+ else {
587
+ lines.push(`${indent}${indent}throw new Error('Not implemented');`);
588
+ }
589
+ lines.push(`${indent}}`);
590
+ break;
591
+ case 'javascript':
592
+ lines.push(`${indent}${staticMod}${async}${method.name}(${params}) {`);
593
+ lines.push(`${indent}${indent}// TODO: Implement`);
594
+ lines.push(`${indent}${indent}throw new Error('Not implemented');`);
595
+ lines.push(`${indent}}`);
596
+ break;
597
+ case 'python':
598
+ const pyStatic = method.static ? '@staticmethod\n' : '';
599
+ const retType = method.returnType ? ` -> ${method.returnType}` : '';
600
+ const selfParam = method.static ? '' : 'self, ';
601
+ lines.push(`${indent}${pyStatic}${indent}${async}def ${method.name}(${selfParam}${params})${retType}:`);
602
+ lines.push(`${indent}${indent}# TODO: Implement`);
603
+ lines.push(`${indent}${indent}raise NotImplementedError()`);
604
+ break;
605
+ case 'java':
606
+ lines.push(`${indent}${visibility}${staticMod}${method.returnType ?? 'void'} ${method.name}(${params}) {`);
607
+ lines.push(`${indent}${indent}// TODO: Implement`);
608
+ lines.push(`${indent}${indent}throw new UnsupportedOperationException();`);
609
+ lines.push(`${indent}}`);
610
+ break;
611
+ case 'csharp':
612
+ lines.push(`${indent}${visibility}${staticMod}${async}${method.returnType ?? 'void'} ${method.name}(${params}) {`);
613
+ lines.push(`${indent}${indent}// TODO: Implement`);
614
+ lines.push(`${indent}${indent}throw new NotImplementedException();`);
615
+ lines.push(`${indent}}`);
616
+ break;
617
+ case 'go':
618
+ lines.push(`func (r *${method.name}) ${method.name}(${params}) ${method.returnType ?? ''} {`);
619
+ lines.push(`${indent}// TODO: Implement`);
620
+ lines.push(`${indent}panic("not implemented")`);
621
+ lines.push('}');
622
+ break;
623
+ case 'rust':
624
+ const ret = method.returnType ? ` -> ${method.returnType}` : '';
625
+ lines.push(`${indent}pub ${async}fn ${method.name}(&self, ${params})${ret} {`);
626
+ lines.push(`${indent}${indent}// TODO: Implement`);
627
+ lines.push(`${indent}${indent}todo!()`);
628
+ lines.push(`${indent}}`);
629
+ break;
630
+ }
631
+ return lines.join(this.options.lineEnding);
632
+ }
633
+ /**
634
+ * Generate Python __init__ method
635
+ */
636
+ generatePythonInit(properties) {
637
+ const { indent } = this.options;
638
+ const lines = [];
639
+ const params = properties.map((p) => {
640
+ const optional = p.optional ? ` = ${p.defaultValue ?? 'None'}` : '';
641
+ return `${p.name}: ${p.type}${optional}`;
642
+ }).join(', ');
643
+ lines.push(`${indent}def __init__(self, ${params}):`);
644
+ for (const prop of properties) {
645
+ lines.push(`${indent}${indent}self.${prop.name} = ${prop.name}`);
646
+ }
647
+ return lines.join(this.options.lineEnding) + this.options.lineEnding;
648
+ }
649
+ /**
650
+ * Format inheritance
651
+ */
652
+ formatInheritance(inheritance) {
653
+ if (!inheritance)
654
+ return '';
655
+ const { language } = this.options;
656
+ const parts = [];
657
+ switch (language) {
658
+ case 'typescript':
659
+ case 'javascript':
660
+ if (inheritance.extends)
661
+ parts.push(`extends ${inheritance.extends}`);
662
+ if (inheritance.implements?.length) {
663
+ parts.push(`implements ${inheritance.implements.join(', ')}`);
664
+ }
665
+ return parts.length > 0 ? ' ' + parts.join(' ') : '';
666
+ case 'python':
667
+ const bases = [
668
+ inheritance.extends,
669
+ ...(inheritance.implements ?? []),
670
+ ].filter(Boolean);
671
+ return bases.length > 0 ? `(${bases.join(', ')})` : '';
672
+ case 'java':
673
+ case 'csharp':
674
+ if (inheritance.extends)
675
+ parts.push(`extends ${inheritance.extends}`);
676
+ if (inheritance.implements?.length) {
677
+ parts.push(`implements ${inheritance.implements.join(', ')}`);
678
+ }
679
+ return parts.length > 0 ? ' ' + parts.join(' ') : '';
680
+ default:
681
+ return '';
682
+ }
683
+ }
684
+ /**
685
+ * Format visibility
686
+ */
687
+ formatVisibility(visibility) {
688
+ const vis = this.langConfig.visibility[visibility] ?? '';
689
+ return vis ? vis + ' ' : '';
690
+ }
691
+ /**
692
+ * Format parameters
693
+ */
694
+ formatParameters(parameters) {
695
+ const { language } = this.options;
696
+ return parameters.map((p) => {
697
+ const optional = p.optional ? '?' : '';
698
+ const defaultVal = p.defaultValue ? ` = ${p.defaultValue}` : '';
699
+ switch (language) {
700
+ case 'typescript':
701
+ return `${p.name}${optional}: ${p.type}${defaultVal}`;
702
+ case 'javascript':
703
+ return `${p.name}${defaultVal}`;
704
+ case 'python':
705
+ return `${p.name}: ${p.type}${defaultVal}`;
706
+ case 'java':
707
+ case 'csharp':
708
+ return `${p.type} ${p.name}`;
709
+ case 'go':
710
+ return `${p.name} ${p.type}`;
711
+ case 'rust':
712
+ return `${p.name}: ${p.type}`;
713
+ default:
714
+ return `${p.name}: ${p.type}`;
715
+ }
716
+ }).join(', ');
717
+ }
718
+ /**
719
+ * Generate file name
720
+ */
721
+ generateFileName(name) {
722
+ const { language } = this.options;
723
+ const ext = this.langConfig.fileExtension;
724
+ // Convert to appropriate case
725
+ switch (language) {
726
+ case 'typescript':
727
+ case 'javascript':
728
+ return this.toKebabCase(name) + ext;
729
+ case 'python':
730
+ return this.toSnakeCase(name) + ext;
731
+ case 'java':
732
+ case 'csharp':
733
+ return name + ext;
734
+ case 'go':
735
+ return this.toSnakeCase(name) + ext;
736
+ case 'rust':
737
+ return this.toSnakeCase(name) + ext;
738
+ default:
739
+ return name + ext;
740
+ }
741
+ }
742
+ /**
743
+ * Extract import modules
744
+ */
745
+ extractImportModules(dependencies) {
746
+ return dependencies.map((d) => d.module);
747
+ }
748
+ /**
749
+ * Extract dependencies (external packages)
750
+ */
751
+ extractDependencies(dependencies) {
752
+ return dependencies
753
+ .filter((d) => !d.module.startsWith('.') && !d.module.startsWith('/'))
754
+ .map((d) => d.module.split('/')[0]);
755
+ }
756
+ /**
757
+ * Convert to kebab-case
758
+ */
759
+ toKebabCase(str) {
760
+ return str
761
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
762
+ .replace(/[\s_]+/g, '-')
763
+ .toLowerCase();
764
+ }
765
+ /**
766
+ * Convert to snake_case
767
+ */
768
+ toSnakeCase(str) {
769
+ return str
770
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
771
+ .replace(/[\s-]+/g, '_')
772
+ .toLowerCase();
773
+ }
774
+ }
775
+ /**
776
+ * Create code generator instance
777
+ */
778
+ export function createCodeGenerator(options) {
779
+ return new CodeGenerator(options);
780
+ }
781
+ //# sourceMappingURL=generator.js.map