@atomic-ehr/codegen 0.0.1-canary.20251006092200.fdb4a88 → 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 -93
  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 -36
  76. package/dist/typeschema/generator.js +0 -243
  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 -261
  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,153 +0,0 @@
1
- /**
2
- * Abstract base class for language-specific type mapping
3
- *
4
- * This provides the interface that all language generators must implement
5
- * to convert FHIR TypeSchema types into their target language types.
6
- */
7
- /**
8
- * Abstract type mapper for language-specific type conversion
9
- */
10
- export class TypeMapper {
11
- options;
12
- constructor(options = {}) {
13
- this.options = {
14
- generateNullable: true,
15
- strictTypes: true,
16
- customMappings: {},
17
- preferArraySyntax: true,
18
- namingConvention: "PascalCase",
19
- ...options,
20
- };
21
- }
22
- // ==========================================
23
- // Concrete Methods - Shared functionality
24
- // ==========================================
25
- /**
26
- * Main entry point for type mapping
27
- * @param schemaType Type from TypeSchema
28
- */
29
- mapType(schemaType) {
30
- // Handle primitive types
31
- if (typeof schemaType === "string") {
32
- return this.mapPrimitive(schemaType);
33
- }
34
- // Handle complex types
35
- if (schemaType && typeof schemaType === "object") {
36
- const kind = schemaType.kind || schemaType.type;
37
- switch (kind) {
38
- case "primitive-type":
39
- return this.mapPrimitive(schemaType.name);
40
- case "reference":
41
- return this.mapReference(schemaType.targets || []);
42
- case "array": {
43
- const elementType = this.mapType(schemaType.element);
44
- return this.mapArray(elementType);
45
- }
46
- case "enum":
47
- case "coded":
48
- return this.mapEnum(schemaType.values || [], schemaType.name);
49
- case "complex-type":
50
- case "resource":
51
- return this.mapComplexType(schemaType);
52
- default:
53
- return this.mapUnknownType(schemaType);
54
- }
55
- }
56
- return this.mapUnknownType(schemaType);
57
- }
58
- /**
59
- * Map a complex type (resource, complex-type)
60
- * @param schemaType Complex type from schema
61
- */
62
- mapComplexType(schemaType) {
63
- const typeName = this.formatTypeName(schemaType.name || "Unknown");
64
- return {
65
- name: typeName,
66
- isPrimitive: false,
67
- importPath: this.calculateImportPath(schemaType),
68
- nullable: !schemaType.required && this.options.generateNullable,
69
- metadata: {
70
- kind: schemaType.kind,
71
- package: schemaType.package,
72
- },
73
- };
74
- }
75
- /**
76
- * Handle unknown/unmapped types
77
- * @param schemaType Unknown type
78
- */
79
- mapUnknownType(schemaType) {
80
- // console.warn(`Unknown type encountered:`, schemaType);
81
- return {
82
- name: "unknown",
83
- isPrimitive: true,
84
- nullable: true,
85
- metadata: {
86
- originalType: schemaType,
87
- warning: "unmapped_type",
88
- },
89
- };
90
- }
91
- /**
92
- * Calculate import path for a type
93
- * @param schemaType Type to calculate import for
94
- */
95
- calculateImportPath(schemaType) {
96
- if (!schemaType.name)
97
- return undefined;
98
- const fileName = this.formatFileName(schemaType.name);
99
- return `./${fileName}`;
100
- }
101
- /**
102
- * Apply naming convention to a string
103
- * @param name Input name
104
- */
105
- applyNamingConvention(name) {
106
- switch (this.options.namingConvention) {
107
- case "camelCase":
108
- return toCamelCase(name);
109
- case "PascalCase":
110
- return toPascalCase(name);
111
- case "snake_case":
112
- return toSnakeCase(name);
113
- case "kebab-case":
114
- return toKebabCase(name);
115
- default:
116
- return name;
117
- }
118
- }
119
- /**
120
- * Get custom mapping if available
121
- * @param type Original type name
122
- */
123
- getCustomMapping(type) {
124
- return this.options.customMappings[type];
125
- }
126
- /**
127
- * Check if type should be nullable
128
- * @param required Whether field is required
129
- */
130
- shouldBeNullable(required) {
131
- return !required && this.options.generateNullable;
132
- }
133
- }
134
- // ==========================================
135
- // Utility Functions
136
- // ==========================================
137
- function toCamelCase(str) {
138
- return str.replace(/[-_\s]+(.)?/g, (_, char) => char?.toUpperCase() || "");
139
- }
140
- function toPascalCase(str) {
141
- const camelCase = toCamelCase(str);
142
- return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
143
- }
144
- function toSnakeCase(str) {
145
- return str
146
- .replace(/([A-Z])/g, "_$1")
147
- .replace(/[-\s]+/g, "_")
148
- .toLowerCase()
149
- .replace(/^_/, "");
150
- }
151
- function toKebabCase(str) {
152
- return toSnakeCase(str).replace(/_/g, "-");
153
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * TypeScript-specific type mapper implementation
3
- */
4
- import type { Identifier } from "@typeschema/types";
5
- import { type LanguageType, TypeMapper, type TypeMapperOptions } from "./TypeMapper";
6
- /**
7
- * TypeScript-specific options
8
- */
9
- export interface TypeScriptTypeMapperOptions extends TypeMapperOptions {
10
- /** Whether to use 'unknown' or 'any' for unmapped types */
11
- preferUnknown?: boolean;
12
- /** Whether to generate branded types for primitives */
13
- useBrandedTypes?: boolean;
14
- /** Whether to use 'undefined' or 'null' for optional types */
15
- preferUndefined?: boolean;
16
- /** Module format for imports */
17
- moduleFormat?: "esm" | "commonjs";
18
- }
19
- /**
20
- * TypeScript type mapper
21
- */
22
- export declare class TypeScriptTypeMapper extends TypeMapper {
23
- private readonly tsOptions;
24
- constructor(options?: TypeScriptTypeMapperOptions);
25
- getLanguageName(): string;
26
- mapPrimitive(fhirType: string): LanguageType;
27
- mapReference(targets: Identifier[]): LanguageType;
28
- mapArray(elementType: LanguageType): LanguageType;
29
- mapOptional(type: LanguageType, required: boolean): LanguageType;
30
- mapEnum(values: string[], name?: string): LanguageType;
31
- formatTypeName(name: string): string;
32
- formatFieldName(name: string): string;
33
- formatFileName(name: string): string;
34
- /**
35
- * Generate TypeScript interface field
36
- * @param fieldName Field name
37
- * @param fieldType Field type
38
- * @param required Whether field is required
39
- */
40
- generateInterfaceField(fieldName: string, fieldType: LanguageType, required: boolean): string;
41
- /**
42
- * Generate import statement for a type
43
- * @param type Language type with import info
44
- */
45
- generateImportStatement(type: LanguageType): string | undefined;
46
- /**
47
- * Get all required imports for a set of types
48
- * @param types Array of language types
49
- */
50
- getRequiredImports(types: LanguageType[]): string[];
51
- }
@@ -1,232 +0,0 @@
1
- /**
2
- * TypeScript-specific type mapper implementation
3
- */
4
- import { TypeMapper } from "./TypeMapper";
5
- /**
6
- * TypeScript type mapper
7
- */
8
- export class TypeScriptTypeMapper extends TypeMapper {
9
- tsOptions;
10
- constructor(options = {}) {
11
- super(options);
12
- this.tsOptions = {
13
- ...this.options,
14
- preferUnknown: true,
15
- useBrandedTypes: false,
16
- preferUndefined: true,
17
- moduleFormat: "esm",
18
- ...options,
19
- };
20
- }
21
- getLanguageName() {
22
- return "TypeScript";
23
- }
24
- mapPrimitive(fhirType) {
25
- const customMapping = this.getCustomMapping(fhirType);
26
- if (customMapping) {
27
- return {
28
- name: customMapping,
29
- isPrimitive: true,
30
- nullable: false,
31
- };
32
- }
33
- const primitiveMap = {
34
- string: "string",
35
- integer: "number",
36
- decimal: "number",
37
- boolean: "boolean",
38
- dateTime: "string",
39
- date: "string",
40
- time: "string",
41
- instant: "string",
42
- uri: "string",
43
- url: "string",
44
- canonical: "string",
45
- oid: "string",
46
- uuid: "string",
47
- base64Binary: "string",
48
- code: "string",
49
- id: "string",
50
- markdown: "string",
51
- unsignedInt: "number",
52
- positiveInt: "number",
53
- xhtml: "string",
54
- json: "unknown",
55
- };
56
- const mappedType = primitiveMap[fhirType];
57
- if (!mappedType) {
58
- console.warn(`Unknown FHIR primitive type: ${fhirType}`);
59
- return {
60
- name: this.tsOptions.preferUnknown ? "unknown" : "any",
61
- isPrimitive: true,
62
- nullable: false,
63
- metadata: { warning: "unmapped_primitive", originalType: fhirType },
64
- };
65
- }
66
- if (this.tsOptions.useBrandedTypes && fhirType !== mappedType) {
67
- return {
68
- name: `${mappedType} & { readonly __brand: '${fhirType}' }`,
69
- isPrimitive: false,
70
- importPath: "./brands",
71
- nullable: false,
72
- metadata: { isBranded: true, originalFhirType: fhirType },
73
- };
74
- }
75
- return {
76
- name: mappedType,
77
- isPrimitive: true,
78
- nullable: false,
79
- };
80
- }
81
- mapReference(targets) {
82
- if (!targets || targets.length === 0) {
83
- return {
84
- name: "Reference",
85
- isPrimitive: false,
86
- importPath: "./Reference",
87
- generics: ["unknown"],
88
- nullable: false,
89
- };
90
- }
91
- if (targets.length === 1) {
92
- const targetName = targets[0]?.name || "unknown";
93
- const targetStringLiteral = targetName === "unknown" ? "unknown" : `'${targetName}'`;
94
- return {
95
- name: "Reference",
96
- isPrimitive: false,
97
- importPath: "./Reference",
98
- generics: [targetStringLiteral],
99
- nullable: false,
100
- metadata: {
101
- referencedType: targetName,
102
- referencedSchema: targets[0],
103
- },
104
- };
105
- }
106
- const targetStringLiterals = targets.map((t) => {
107
- const targetName = t.name || "unknown";
108
- return targetName === "unknown" ? "unknown" : `'${targetName}'`;
109
- });
110
- return {
111
- name: "Reference",
112
- isPrimitive: false,
113
- importPath: "./Reference",
114
- generics: [targetStringLiterals.join(" | ")],
115
- nullable: false,
116
- metadata: {
117
- referencedTypes: targets.map((t) => t.name || "unknown"),
118
- referencedSchemas: targets,
119
- },
120
- };
121
- }
122
- mapArray(elementType) {
123
- if (this.options.preferArraySyntax) {
124
- return {
125
- name: `${elementType.name}[]`,
126
- isPrimitive: elementType.isPrimitive,
127
- importPath: elementType.importPath,
128
- isArray: true,
129
- nullable: false,
130
- metadata: {
131
- elementType: elementType,
132
- arrayStyle: "suffix",
133
- },
134
- };
135
- }
136
- else {
137
- return {
138
- name: "Array",
139
- isPrimitive: false,
140
- generics: [elementType.name],
141
- isArray: true,
142
- nullable: false,
143
- metadata: {
144
- elementType: elementType,
145
- arrayStyle: "generic",
146
- },
147
- };
148
- }
149
- }
150
- mapOptional(type, required) {
151
- if (required || !this.shouldBeNullable(required)) {
152
- return type;
153
- }
154
- const nullType = this.tsOptions.preferUndefined ? "undefined" : "null";
155
- return {
156
- ...type,
157
- name: `${type.name} | ${nullType}`,
158
- nullable: true,
159
- metadata: {
160
- ...type.metadata,
161
- nullabilityType: nullType,
162
- wasOptional: true,
163
- },
164
- };
165
- }
166
- mapEnum(values, name) {
167
- const enumName = name ? this.formatTypeName(name) : "CodedValue";
168
- const unionType = values.map((v) => `'${v}'`).join(" | ");
169
- return {
170
- name: unionType,
171
- isPrimitive: false,
172
- nullable: false,
173
- metadata: {
174
- enumName,
175
- values,
176
- isUnionType: true,
177
- },
178
- };
179
- }
180
- formatTypeName(name) {
181
- return this.applyNamingConvention(name);
182
- }
183
- formatFieldName(name) {
184
- return toCamelCase(name);
185
- }
186
- formatFileName(name) {
187
- return this.applyNamingConvention(name);
188
- }
189
- /**
190
- * Generate TypeScript interface field
191
- * @param fieldName Field name
192
- * @param fieldType Field type
193
- * @param required Whether field is required
194
- */
195
- generateInterfaceField(fieldName, fieldType, required) {
196
- const formattedName = this.formatFieldName(fieldName);
197
- const optionalMarker = required ? "" : "?";
198
- return `${formattedName}${optionalMarker}: ${fieldType.name};`;
199
- }
200
- /**
201
- * Generate import statement for a type
202
- * @param type Language type with import info
203
- */
204
- generateImportStatement(type) {
205
- if (!type.importPath || type.isPrimitive) {
206
- return undefined;
207
- }
208
- if (this.tsOptions.moduleFormat === "esm") {
209
- return `import type { ${type.name} } from '${type.importPath}';`;
210
- }
211
- else {
212
- return `const { ${type.name} } = require('${type.importPath}');`;
213
- }
214
- }
215
- /**
216
- * Get all required imports for a set of types
217
- * @param types Array of language types
218
- */
219
- getRequiredImports(types) {
220
- const imports = new Set();
221
- for (const type of types) {
222
- const importStatement = this.generateImportStatement(type);
223
- if (importStatement) {
224
- imports.add(importStatement);
225
- }
226
- }
227
- return Array.from(imports).sort();
228
- }
229
- }
230
- function toCamelCase(str) {
231
- return str.replace(/[-_\s]+(.)?/g, (_, char) => char?.toUpperCase() || "");
232
- }
@@ -1,99 +0,0 @@
1
- /**
2
- * Directory builder for batch file operations
3
- *
4
- * Provides a fluent API for managing entire directories of files,
5
- * including subdirectories, index files, and batch operations.
6
- */
7
- import type { CodegenLogger } from "../../../../utils/codegen-logger";
8
- import type { FileManager } from "../FileManager";
9
- import type { FileBuilder } from "./FileBuilder";
10
- import type { IndexBuilder } from "./IndexBuilder";
11
- export interface DirectoryBuilderConfig {
12
- path: string;
13
- fileManager: FileManager;
14
- logger: CodegenLogger;
15
- }
16
- /**
17
- * Fluent builder for directory operations
18
- *
19
- * Features:
20
- * - Subdirectory management
21
- * - Batch file operations
22
- * - Index file generation
23
- * - Directory cleaning
24
- * - File listing for preview
25
- */
26
- export declare class DirectoryBuilder {
27
- private readonly config;
28
- private readonly files;
29
- private readonly subdirectories;
30
- private indexBuilder?;
31
- private shouldClean;
32
- constructor(config: DirectoryBuilderConfig);
33
- /**
34
- * Add a subdirectory
35
- * @param name Subdirectory name
36
- */
37
- withSubdirectory(name: string): DirectoryBuilder;
38
- /**
39
- * Add files to this directory
40
- * @param files Map of filename to FileBuilder
41
- */
42
- withFiles(files: Record<string, FileBuilder>): DirectoryBuilder;
43
- /**
44
- * Add a single file
45
- * @param filename File name
46
- * @param builder File builder
47
- */
48
- withFile(filename: string, builder: FileBuilder): DirectoryBuilder;
49
- /**
50
- * Set index builder for this directory
51
- * @param builder Index builder
52
- */
53
- withIndex(builder: IndexBuilder): DirectoryBuilder;
54
- /**
55
- * Clean directory before creating files
56
- */
57
- clean(): DirectoryBuilder;
58
- /**
59
- * Ensure directory exists
60
- */
61
- ensure(): Promise<DirectoryBuilder>;
62
- /**
63
- * Save all files in this directory
64
- */
65
- save(): Promise<string[]>;
66
- /**
67
- * Get all files that would be generated (for preview)
68
- */
69
- getFileList(): string[];
70
- /**
71
- * Get statistics about this directory
72
- */
73
- getStats(): {
74
- fileCount: number;
75
- subdirectoryCount: number;
76
- hasIndex: boolean;
77
- totalFiles: number;
78
- };
79
- /**
80
- * Check if directory would overwrite existing files
81
- */
82
- wouldOverwrite(): Promise<string[]>;
83
- /**
84
- * Get the path of this directory
85
- */
86
- getPath(): string;
87
- /**
88
- * Get all file builders (for testing/debugging)
89
- */
90
- getFiles(): Map<string, FileBuilder>;
91
- /**
92
- * Get all subdirectories (for testing/debugging)
93
- */
94
- getSubdirectories(): Map<string, DirectoryBuilder>;
95
- /**
96
- * Get index builder (for testing/debugging)
97
- */
98
- getIndexBuilder(): IndexBuilder | undefined;
99
- }