@atomic-ehr/codegen 0.0.1-canary.20251006070905.fb6ed98 → 0.0.1-canary.20251006094042.7f0be72

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 (90) hide show
  1. package/dist/cli/index.js +45 -124
  2. package/dist/index.d.ts +2130 -62
  3. package/dist/index.js +5865 -84
  4. package/dist/index.js.map +1 -0
  5. package/package.json +3 -7
  6. package/dist/api/builder.d.ts +0 -154
  7. package/dist/api/builder.js +0 -341
  8. package/dist/api/generators/base/BaseGenerator.d.ts +0 -186
  9. package/dist/api/generators/base/BaseGenerator.js +0 -565
  10. package/dist/api/generators/base/FileManager.d.ts +0 -88
  11. package/dist/api/generators/base/FileManager.js +0 -202
  12. package/dist/api/generators/base/PythonTypeMapper.d.ts +0 -16
  13. package/dist/api/generators/base/PythonTypeMapper.js +0 -71
  14. package/dist/api/generators/base/TemplateEngine.d.ts +0 -126
  15. package/dist/api/generators/base/TemplateEngine.js +0 -133
  16. package/dist/api/generators/base/TypeMapper.d.ts +0 -129
  17. package/dist/api/generators/base/TypeMapper.js +0 -153
  18. package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +0 -51
  19. package/dist/api/generators/base/TypeScriptTypeMapper.js +0 -232
  20. package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +0 -99
  21. package/dist/api/generators/base/builders/DirectoryBuilder.js +0 -215
  22. package/dist/api/generators/base/builders/FileBuilder.d.ts +0 -160
  23. package/dist/api/generators/base/builders/FileBuilder.js +0 -406
  24. package/dist/api/generators/base/builders/IndexBuilder.d.ts +0 -126
  25. package/dist/api/generators/base/builders/IndexBuilder.js +0 -290
  26. package/dist/api/generators/base/enhanced-errors.d.ts +0 -84
  27. package/dist/api/generators/base/enhanced-errors.js +0 -259
  28. package/dist/api/generators/base/error-handler.d.ts +0 -89
  29. package/dist/api/generators/base/error-handler.js +0 -243
  30. package/dist/api/generators/base/errors.d.ts +0 -251
  31. package/dist/api/generators/base/errors.js +0 -692
  32. package/dist/api/generators/base/index.d.ts +0 -99
  33. package/dist/api/generators/base/index.js +0 -160
  34. package/dist/api/generators/base/types.d.ts +0 -433
  35. package/dist/api/generators/base/types.js +0 -12
  36. package/dist/api/generators/types.d.ts +0 -53
  37. package/dist/api/generators/types.js +0 -4
  38. package/dist/api/generators/typescript.d.ts +0 -190
  39. package/dist/api/generators/typescript.js +0 -819
  40. package/dist/api/index.d.ts +0 -51
  41. package/dist/api/index.js +0 -50
  42. package/dist/cli/commands/generate/typescript.d.ts +0 -10
  43. package/dist/cli/commands/generate/typescript.js +0 -52
  44. package/dist/cli/commands/generate.d.ts +0 -15
  45. package/dist/cli/commands/generate.js +0 -159
  46. package/dist/cli/commands/index.d.ts +0 -29
  47. package/dist/cli/commands/index.js +0 -100
  48. package/dist/cli/commands/typeschema/generate.d.ts +0 -19
  49. package/dist/cli/commands/typeschema/generate.js +0 -124
  50. package/dist/cli/commands/typeschema.d.ts +0 -10
  51. package/dist/cli/commands/typeschema.js +0 -47
  52. package/dist/cli/index.d.ts +0 -9
  53. package/dist/cli/utils/log.d.ts +0 -10
  54. package/dist/cli/utils/log.js +0 -23
  55. package/dist/cli/utils/prompts.d.ts +0 -56
  56. package/dist/cli/utils/prompts.js +0 -202
  57. package/dist/cli/utils/spinner.d.ts +0 -110
  58. package/dist/cli/utils/spinner.js +0 -266
  59. package/dist/config.d.ts +0 -217
  60. package/dist/config.js +0 -591
  61. package/dist/logger.d.ts +0 -157
  62. package/dist/logger.js +0 -281
  63. package/dist/typeschema/cache.d.ts +0 -80
  64. package/dist/typeschema/cache.js +0 -239
  65. package/dist/typeschema/core/binding.d.ts +0 -11
  66. package/dist/typeschema/core/binding.js +0 -143
  67. package/dist/typeschema/core/field-builder.d.ts +0 -12
  68. package/dist/typeschema/core/field-builder.js +0 -123
  69. package/dist/typeschema/core/identifier.d.ts +0 -13
  70. package/dist/typeschema/core/identifier.js +0 -94
  71. package/dist/typeschema/core/nested-types.d.ts +0 -9
  72. package/dist/typeschema/core/nested-types.js +0 -94
  73. package/dist/typeschema/core/transformer.d.ts +0 -11
  74. package/dist/typeschema/core/transformer.js +0 -235
  75. package/dist/typeschema/generator.d.ts +0 -43
  76. package/dist/typeschema/generator.js +0 -264
  77. package/dist/typeschema/index.d.ts +0 -15
  78. package/dist/typeschema/index.js +0 -15
  79. package/dist/typeschema/parser.d.ts +0 -79
  80. package/dist/typeschema/parser.js +0 -274
  81. package/dist/typeschema/profile/processor.d.ts +0 -14
  82. package/dist/typeschema/profile/processor.js +0 -262
  83. package/dist/typeschema/register.d.ts +0 -21
  84. package/dist/typeschema/register.js +0 -117
  85. package/dist/typeschema/types.d.ts +0 -240
  86. package/dist/typeschema/types.js +0 -19
  87. package/dist/utils/codegen-logger.d.ts +0 -102
  88. package/dist/utils/codegen-logger.js +0 -196
  89. package/dist/utils.d.ts +0 -22
  90. package/dist/utils.js +0 -42
@@ -1,406 +0,0 @@
1
- /**
2
- * Fluent file builder with lifecycle hooks and validation
3
- *
4
- * This provides a clean, chainable API for building files with imports,
5
- * exports, content generation, and lifecycle hooks for customization.
6
- */
7
- import { FileOperationError, TemplateError } from "../errors";
8
- /**
9
- * Fluent builder for creating files with lifecycle hooks
10
- *
11
- * Features:
12
- * - Fluent API for content building
13
- * - Template integration
14
- * - Import/export management
15
- * - Lifecycle hooks (before/after save, error handling)
16
- * - Content validation
17
- * - Automatic import path resolution
18
- */
19
- export class FileBuilder {
20
- config;
21
- content = "";
22
- imports = new Map();
23
- exports = new Set();
24
- metadata = new Map();
25
- // Lifecycle hooks
26
- beforeSaveHooks = [];
27
- afterSaveHooks = [];
28
- errorHooks = [];
29
- // Options
30
- options = {
31
- template: undefined,
32
- importStrategy: "auto",
33
- validation: "strict",
34
- prettify: true,
35
- formatting: {
36
- indentSize: 2,
37
- useTabs: false,
38
- maxLineLength: 100,
39
- },
40
- encoding: "utf-8",
41
- };
42
- constructor(config) {
43
- this.config = config;
44
- }
45
- // ==========================================
46
- // Content Building Methods
47
- // ==========================================
48
- /**
49
- * Set content directly
50
- * @param content File content
51
- */
52
- withContent(content) {
53
- this.content = typeof content === "string" ? content : content();
54
- return this;
55
- }
56
- /**
57
- * Generate content from template
58
- * @param templateName Template to use
59
- * @param context Template context
60
- */
61
- withTemplate(templateName, context) {
62
- if (!this.config.templateEngine) {
63
- throw new TemplateError(`Template engine is required for template rendering. Template: '${templateName}'`, templateName, context);
64
- }
65
- this.options.template = templateName;
66
- try {
67
- this.content = this.config.templateEngine.render(templateName, {
68
- ...context,
69
- imports: this.imports,
70
- exports: this.exports,
71
- filename: this.config.filename,
72
- });
73
- }
74
- catch (_error) {
75
- throw new TemplateError(`Failed to render template '${templateName}'`, templateName, context, {
76
- availableTemplates: this.config.templateEngine.getAvailableTemplates?.() || [],
77
- });
78
- }
79
- return this;
80
- }
81
- /**
82
- * Append content to existing content
83
- * @param content Content to append
84
- */
85
- appendContent(content) {
86
- this.content += content;
87
- return this;
88
- }
89
- /**
90
- * Prepend content to existing content
91
- * @param content Content to prepend
92
- */
93
- prependContent(content) {
94
- this.content = content + this.content;
95
- return this;
96
- }
97
- // ==========================================
98
- // Import/Export Management
99
- // ==========================================
100
- /**
101
- * Set all imports at once
102
- * @param imports Map of symbol name to import path
103
- */
104
- withImports(imports) {
105
- this.imports.clear();
106
- for (const [symbol, path] of imports) {
107
- this.imports.set(symbol, path);
108
- }
109
- return this;
110
- }
111
- /**
112
- * Add a single import
113
- * @param symbol Symbol to import
114
- * @param from Import path
115
- */
116
- addImport(symbol, from) {
117
- this.imports.set(symbol, from);
118
- return this;
119
- }
120
- /**
121
- * Add multiple imports from the same path
122
- * @param symbols Symbols to import
123
- * @param from Import path
124
- */
125
- addImports(symbols, from) {
126
- for (const symbol of symbols) {
127
- this.imports.set(symbol, from);
128
- }
129
- return this;
130
- }
131
- /**
132
- * Set all exports at once
133
- * @param exports Array of export names
134
- */
135
- withExports(exports) {
136
- this.exports.clear();
137
- for (const exp of exports) {
138
- this.exports.add(exp);
139
- }
140
- return this;
141
- }
142
- /**
143
- * Add a single export
144
- * @param name Export name
145
- */
146
- addExport(name) {
147
- this.exports.add(name);
148
- return this;
149
- }
150
- /**
151
- * Add multiple exports
152
- * @param names Export names
153
- */
154
- addExports(names) {
155
- for (const name of names) {
156
- this.exports.add(name);
157
- }
158
- return this;
159
- }
160
- // ==========================================
161
- // Metadata and Options
162
- // ==========================================
163
- /**
164
- * Set metadata for the file
165
- * @param key Metadata key
166
- * @param value Metadata value
167
- */
168
- withMetadata(key, value) {
169
- this.metadata.set(key, value);
170
- return this;
171
- }
172
- /**
173
- * Set file builder options
174
- * @param options Options to set
175
- */
176
- withOptions(options) {
177
- this.options = { ...this.options, ...options };
178
- return this;
179
- }
180
- // ==========================================
181
- // Lifecycle Hooks
182
- // ==========================================
183
- /**
184
- * Add hook to run before saving
185
- * @param hook Hook function
186
- */
187
- onBeforeSave(hook) {
188
- this.beforeSaveHooks.push(hook);
189
- return this;
190
- }
191
- /**
192
- * Add hook to run after successful save
193
- * @param hook Hook function
194
- */
195
- onAfterSave(hook) {
196
- this.afterSaveHooks.push(hook);
197
- return this;
198
- }
199
- /**
200
- * Add hook to run when error occurs
201
- * @param hook Hook function
202
- */
203
- onError(hook) {
204
- this.errorHooks.push(hook);
205
- return this;
206
- }
207
- // ==========================================
208
- // Execution Methods
209
- // ==========================================
210
- /**
211
- * Build final content without saving
212
- * @returns File context with final content
213
- */
214
- build() {
215
- const finalContent = this.buildFinalContent();
216
- return {
217
- filename: this.config.filename,
218
- content: finalContent,
219
- imports: new Map(this.imports),
220
- exports: new Set(this.exports),
221
- metadata: Object.fromEntries(this.metadata),
222
- templateName: this.options.template,
223
- };
224
- }
225
- /**
226
- * Save the file
227
- * @returns Promise resolving to file path
228
- */
229
- async save() {
230
- const context = this.build();
231
- try {
232
- // Run before-save hooks
233
- for (const hook of this.beforeSaveHooks) {
234
- await hook(context);
235
- }
236
- // Validate content if enabled
237
- if (this.options.validation !== "none") {
238
- await this.validateContent(context.content);
239
- }
240
- // Write file
241
- const result = await this.config.fileManager.writeFile(this.config.filename, context.content, {
242
- encoding: this.options.encoding,
243
- });
244
- const stats = {
245
- size: result.size,
246
- generationTime: 0, // Set by caller if needed
247
- writeTime: result.writeTime,
248
- };
249
- // Run after-save hooks
250
- for (const hook of this.afterSaveHooks) {
251
- await hook(result.path, stats);
252
- }
253
- this.config.logger.debug(`Saved ${this.config.filename} successfully`);
254
- return result.path;
255
- }
256
- catch (error) {
257
- // Run error hooks
258
- for (const hook of this.errorHooks) {
259
- try {
260
- await hook(error instanceof Error ? error : new Error(String(error)), context);
261
- }
262
- catch (hookError) {
263
- this.config.logger.warn(`Error hook failed: ${hookError instanceof Error ? hookError.message : String(hookError)}`);
264
- }
265
- }
266
- throw error;
267
- }
268
- }
269
- // ==========================================
270
- // Private Helper Methods
271
- // ==========================================
272
- /**
273
- * Build final content with imports and exports
274
- */
275
- buildFinalContent() {
276
- const parts = [];
277
- // Add imports
278
- if (this.imports.size > 0 && this.options.importStrategy !== "none") {
279
- parts.push(this.generateImportStatements());
280
- parts.push(""); // Empty line after imports
281
- }
282
- // Add main content
283
- if (this.content) {
284
- parts.push(this.content);
285
- }
286
- // Add exports if not already in content
287
- if (this.exports.size > 0 && !this.content.includes("export")) {
288
- parts.push(""); // Empty line before exports
289
- parts.push(this.generateExportStatements());
290
- }
291
- let finalContent = parts.join("\n");
292
- // Prettify if enabled
293
- if (this.options.prettify) {
294
- finalContent = this.prettifyContent(finalContent);
295
- }
296
- return finalContent;
297
- }
298
- /**
299
- * Generate import statements
300
- */
301
- generateImportStatements() {
302
- const lines = [];
303
- // Group imports by path
304
- const importsByPath = new Map();
305
- for (const [symbol, path] of this.imports) {
306
- const resolvedPath = this.options.importStrategy === "auto"
307
- ? this.config.fileManager.getRelativeImportPath(this.config.filename, path)
308
- : path;
309
- if (!importsByPath.has(resolvedPath)) {
310
- importsByPath.set(resolvedPath, []);
311
- }
312
- importsByPath.get(resolvedPath)?.push(symbol);
313
- }
314
- // Generate import statements
315
- for (const [path, symbols] of importsByPath) {
316
- if (symbols.length === 1) {
317
- lines.push(`import type { ${symbols[0]} } from '${path}';`);
318
- }
319
- else {
320
- const sortedSymbols = symbols.sort();
321
- if (sortedSymbols.length <= 3) {
322
- lines.push(`import type { ${sortedSymbols.join(", ")} } from '${path}';`);
323
- }
324
- else {
325
- lines.push(`import type {`);
326
- const indent = "\t";
327
- sortedSymbols.forEach((symbol, index) => {
328
- const isLast = index === sortedSymbols.length - 1;
329
- lines.push(`${indent}${symbol}${isLast ? "" : ","}`);
330
- });
331
- lines.push(`} from '${path}';`);
332
- }
333
- }
334
- }
335
- return lines.join("\n");
336
- }
337
- /**
338
- * Generate export statements
339
- */
340
- generateExportStatements() {
341
- const exports = Array.from(this.exports).sort();
342
- return exports.map((exp) => `export { ${exp} };`).join("\n");
343
- }
344
- /**
345
- * Prettify content (basic implementation)
346
- */
347
- prettifyContent(content) {
348
- // Basic prettification
349
- return content
350
- .replace(/\n{3,}/g, "\n\n") // Max 2 consecutive newlines
351
- .replace(/\t/g, this.options.formatting?.useTabs ? "\t" : " ".repeat(this.options.formatting?.indentSize || 2))
352
- .trim();
353
- }
354
- /**
355
- * Validate generated content
356
- */
357
- async validateContent(content) {
358
- if (this.options.validation === "none")
359
- return;
360
- // Basic validation - check for syntax errors
361
- const issues = [];
362
- // Check for unmatched braces
363
- const openBraces = (content.match(/\{/g) || []).length;
364
- const closeBraces = (content.match(/\}/g) || []).length;
365
- if (openBraces !== closeBraces) {
366
- issues.push(`Unmatched braces: ${openBraces} open, ${closeBraces} close`);
367
- }
368
- // Check for unmatched parentheses
369
- const openParens = (content.match(/\(/g) || []).length;
370
- const closeParens = (content.match(/\)/g) || []).length;
371
- if (openParens !== closeParens) {
372
- issues.push(`Unmatched parentheses: ${openParens} open, ${closeParens} close`);
373
- }
374
- // Check for basic TypeScript syntax issues
375
- if (this.config.filename.endsWith(".ts") || this.config.filename.endsWith(".tsx")) {
376
- if (content.includes("interface") && !content.match(/interface\s+\w+\s*\{/)) {
377
- issues.push("Invalid interface syntax detected");
378
- }
379
- }
380
- if (issues.length > 0 && this.options.validation === "strict") {
381
- throw new FileOperationError(`Content validation failed for ${this.config.filename}: ${issues.join(", ")}`, "write", this.config.filename);
382
- }
383
- else if (issues.length > 0) {
384
- // Just warn for non-strict validation
385
- this.config.logger.warn(`Validation issues in ${this.config.filename}: ${issues.join(", ")}`);
386
- }
387
- }
388
- /**
389
- * Get current content (for testing/debugging)
390
- */
391
- getContent() {
392
- return this.content;
393
- }
394
- /**
395
- * Get current imports (for testing/debugging)
396
- */
397
- getImports() {
398
- return new Map(this.imports);
399
- }
400
- /**
401
- * Get current exports (for testing/debugging)
402
- */
403
- getExports() {
404
- return new Set(this.exports);
405
- }
406
- }
@@ -1,126 +0,0 @@
1
- /**
2
- * Index file builder for automated exports
3
- *
4
- * Automatically generates index files that export all types and functions
5
- * from a directory, with support for grouping and namespaces.
6
- */
7
- import type { CodegenLogger } from "../../../../utils/codegen-logger";
8
- import type { FileManager } from "../FileManager";
9
- import type { TemplateEngine } from "../types";
10
- export interface IndexBuilderConfig {
11
- directory: string;
12
- fileManager: FileManager;
13
- templateEngine?: TemplateEngine;
14
- logger: CodegenLogger;
15
- }
16
- /**
17
- * Builder for index files with intelligent export management
18
- *
19
- * Features:
20
- * - Automatic export detection
21
- * - Namespace support
22
- * - Export grouping
23
- * - Custom headers
24
- * - Template support
25
- */
26
- export declare class IndexBuilder {
27
- private readonly config;
28
- private readonly exports;
29
- private readonly namespaces;
30
- private readonly reExports;
31
- private header;
32
- private footer;
33
- private groupingFunction?;
34
- private sortFunction?;
35
- constructor(config: IndexBuilderConfig);
36
- /**
37
- * Add exports from a specific file
38
- * @param exportNames Export names
39
- * @param fromPath Path to file (without extension)
40
- */
41
- withExports(exportNames: string[], fromPath: string): IndexBuilder;
42
- /**
43
- * Add a single export
44
- * @param exportName Export name
45
- * @param fromPath Path to file
46
- */
47
- withExport(exportName: string, fromPath: string): IndexBuilder;
48
- /**
49
- * Add namespace exports
50
- * @param namespaces Map of namespace to path
51
- */
52
- withNamespaces(namespaces: Record<string, string>): IndexBuilder;
53
- /**
54
- * Add namespace export
55
- * @param namespace Namespace name
56
- * @param path Path to export as namespace
57
- */
58
- withNamespace(namespace: string, path: string): IndexBuilder;
59
- /**
60
- * Re-export all from paths
61
- * @param paths Paths to re-export all from
62
- */
63
- withReExports(paths: string[]): IndexBuilder;
64
- /**
65
- * Add re-export
66
- * @param path Path to re-export all from
67
- */
68
- withReExport(path: string): IndexBuilder;
69
- /**
70
- * Set header content
71
- * @param header Header content
72
- */
73
- withHeader(header: string): IndexBuilder;
74
- /**
75
- * Set footer content
76
- * @param footer Footer content
77
- */
78
- withFooter(footer: string): IndexBuilder;
79
- /**
80
- * Group exports by function
81
- * @param fn Function that returns group name for export
82
- */
83
- groupBy(fn: (exportName: string) => string): IndexBuilder;
84
- /**
85
- * Sort exports by function
86
- * @param fn Sort function for [exportName, fromPath] tuples
87
- */
88
- sortBy(fn: (a: [string, string], b: [string, string]) => number): IndexBuilder;
89
- /**
90
- * Auto-discover exports from directory
91
- * @param filePattern Pattern to match files (e.g., "*.ts")
92
- */
93
- autoDiscover(_filePattern?: string): Promise<IndexBuilder>;
94
- /**
95
- * Save the index file
96
- */
97
- save(): Promise<string>;
98
- /**
99
- * Build content without saving (for preview)
100
- */
101
- build(): string;
102
- /**
103
- * Generate the index file content
104
- */
105
- private generateContent;
106
- /**
107
- * Generate simple exports without grouping
108
- */
109
- private generateSimpleExports;
110
- /**
111
- * Generate grouped exports
112
- */
113
- private generateGroupedExports;
114
- /**
115
- * Get current exports (for testing/debugging)
116
- */
117
- getExports(): Map<string, string>;
118
- /**
119
- * Get current namespaces (for testing/debugging)
120
- */
121
- getNamespaces(): Map<string, string>;
122
- /**
123
- * Get current re-exports (for testing/debugging)
124
- */
125
- getReExports(): Map<string, string>;
126
- }