@@ -9,16 +9,13 @@ import * as fs from "node:fs";
99import * as afs from "node:fs/promises" ;
1010import * as Path from "node:path" ;
1111import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager" ;
12- import type { GeneratedFile } from "@root/api/generators/base/types" ;
1312import { CSharp } from "@root/api/writer-generator/csharp/csharp" ;
1413import { registerFromManager } from "@root/typeschema/register" ;
15- import { mkTypeSchemaIndex , type TreeShake , treeShake } from "@root/typeschema/utils" ;
16- import { generateTypeSchemas , TypeSchemaCache , TypeSchemaGenerator , TypeSchemaParser } from "@typeschema/index" ;
14+ import { mkTypeSchemaIndex , type TreeShake , type TypeSchemaIndex , treeShake } from "@root/typeschema/utils" ;
15+ import { generateTypeSchemas , TypeSchemaGenerator , TypeSchemaParser } from "@typeschema/index" ;
1716import { extractNameFromCanonical , packageMetaToFhir , packageMetaToNpm , type TypeSchema } from "@typeschema/types" ;
18- import type { Config , TypeSchemaConfig } from "../config" ;
17+ import type { TypeSchemaConfig } from "../config" ;
1918import { CodegenLogger , createLogger } from "../utils/codegen-logger" ;
20- import type { GeneratorInput } from "./generators/base/BaseGenerator" ;
21- import { TypeScriptGenerator as TypeScriptGeneratorDepricated } from "./generators/typescript" ;
2219import { TypeScript , type TypeScriptOptions } from "./writer-generator/typescript" ;
2320import type { Writer , WriterOptions } from "./writer-generator/writer" ;
2421
@@ -57,6 +54,14 @@ export interface GenerationResult {
5754 duration : number ;
5855}
5956
57+ export interface GeneratedFile {
58+ path : string ;
59+ filename : string ;
60+ timestamp : Date ;
61+ }
62+
63+ export type GeneratorInput = { schemas : TypeSchema [ ] ; index : TypeSchemaIndex } ;
64+
6065interface Generator {
6166 generate : ( input : GeneratorInput ) => Promise < GeneratedFile [ ] > ;
6267 setOutputDir : ( outputDir : string ) => void ;
@@ -65,13 +70,10 @@ interface Generator {
6570
6671const writerToGenerator = ( writerGen : Writer ) : Generator => {
6772 const getGeneratedFiles = ( ) => {
68- return writerGen . writtenFiles ( ) . map ( ( fn : string ) => {
73+ return writerGen . writtenFiles ( ) . map ( ( fn : string ) : GeneratedFile => {
6974 return {
7075 path : Path . normalize ( Path . join ( writerGen . opts . outputDir , fn ) ) ,
7176 filename : fn . replace ( / ^ .* [ \\ / ] / , "" ) ,
72- content : "" ,
73- exports : [ ] ,
74- size : 0 ,
7577 timestamp : new Date ( ) ,
7678 } ;
7779 } ) ;
@@ -206,7 +208,6 @@ export class APIBuilder {
206208 private schemas : TypeSchema [ ] = [ ] ;
207209 private options : APIBuilderConfig ;
208210 private generators : Map < string , Generator > = new Map ( ) ;
209- private cache ?: TypeSchemaCache ;
210211 private pendingOperations : Promise < void > [ ] = [ ] ;
211212 private typeSchemaGenerator ?: TypeSchemaGenerator ;
212213 private logger : CodegenLogger ;
@@ -238,10 +239,6 @@ export class APIBuilder {
238239 verbose : this . options . verbose ,
239240 prefix : "API" ,
240241 } ) ;
241-
242- if ( this . options . cache ) {
243- this . cache = new TypeSchemaCache ( this . typeSchemaConfig ) ;
244- }
245242 }
246243
247244 fromPackage ( packageName : string , version ?: string ) : APIBuilder {
@@ -268,47 +265,6 @@ export class APIBuilder {
268265 return this ;
269266 }
270267
271- typescriptDepricated (
272- options : {
273- moduleFormat ?: "esm" | "cjs" ;
274- generateIndex ?: boolean ;
275- includeDocuments ?: boolean ;
276- namingConvention ?: "PascalCase" | "camelCase" ;
277- includeExtensions ?: boolean ;
278- includeProfiles ?: boolean ;
279- generateValueSets ?: boolean ;
280- includeValueSetHelpers ?: boolean ;
281- valueSetStrengths ?: ( "required" | "preferred" | "extensible" | "example" ) [ ] ;
282- valueSetMode ?: "all" | "required-only" | "custom" ;
283- valueSetDirectory ?: string ;
284- } = { } ,
285- ) : APIBuilder {
286- const typesOutputDir = `${ this . options . outputDir } /types` ;
287-
288- const generator = new TypeScriptGeneratorDepricated ( {
289- outputDir : typesOutputDir ,
290- moduleFormat : options . moduleFormat || "esm" ,
291- generateIndex : options . generateIndex ?? true ,
292- includeDocuments : options . includeDocuments ?? true ,
293- namingConvention : options . namingConvention || "PascalCase" ,
294- includeExtensions : options . includeExtensions ?? false ,
295- includeProfiles : options . includeProfiles ?? false ,
296- generateValueSets : options . generateValueSets ?? false ,
297- includeValueSetHelpers : options . includeValueSetHelpers ?? false ,
298- valueSetStrengths : options . valueSetStrengths ?? [ "required" ] ,
299- logger : this . logger . child ( "TS" ) ,
300- valueSetMode : options . valueSetMode ?? "required-only" ,
301- valueSetDirectory : options . valueSetDirectory ?? "valuesets" ,
302- verbose : this . options . verbose ,
303- validate : true , // Enable validation for debugging
304- overwrite : this . options . overwrite ,
305- } ) ;
306-
307- this . generators . set ( "typescript" , generator ) ;
308- this . logger . debug ( `Configured TypeScript generator (${ options . moduleFormat || "esm" } )` ) ;
309- return this ;
310- }
311-
312268 typescript ( userOpts : Partial < TypeScriptOptions > ) {
313269 const defaultWriterOpts : WriterOptions = {
314270 logger : this . logger ,
@@ -510,14 +466,11 @@ export class APIBuilder {
510466
511467 private async loadFromFiles ( filePaths : string [ ] ) : Promise < void > {
512468 if ( ! this . typeSchemaGenerator ) {
513- this . typeSchemaGenerator = new TypeSchemaGenerator (
514- {
515- verbose : this . options . verbose ,
516- logger : this . logger . child ( "Schema" ) ,
517- treeshake : this . typeSchemaConfig ?. treeshake ,
518- } ,
519- this . typeSchemaConfig ,
520- ) ;
469+ this . typeSchemaGenerator = new TypeSchemaGenerator ( {
470+ verbose : this . options . verbose ,
471+ logger : this . logger . child ( "Schema" ) ,
472+ treeshake : this . typeSchemaConfig ?. treeshake ,
473+ } ) ;
521474 }
522475
523476 const parser = new TypeSchemaParser ( {
@@ -526,10 +479,6 @@ export class APIBuilder {
526479
527480 const schemas = await parser . parseFromFiles ( filePaths ) ;
528481 this . schemas = [ ...this . schemas , ...schemas ] ;
529-
530- if ( this . cache ) {
531- this . cache . setMany ( schemas ) ;
532- }
533482 }
534483
535484 private async executeGenerators ( result : GenerationResult , input : GeneratorInput ) : Promise < void > {
@@ -549,36 +498,3 @@ export class APIBuilder {
549498 }
550499 }
551500}
552-
553- /**
554- * Create an API builder instance from a configuration object
555- */
556- export function createAPIFromConfig ( config : Config ) : APIBuilder {
557- const builder = new APIBuilder ( {
558- outputDir : config . outputDir ,
559- verbose : config . verbose ,
560- overwrite : config . overwrite ,
561- cache : config . cache ,
562- cleanOutput : config . cleanOutput ,
563- typeSchemaConfig : config . typeSchema ,
564- } ) ;
565-
566- // Add packages if specified
567- if ( config . packages && config . packages . length > 0 ) {
568- for ( const pkg of config . packages ) {
569- builder . fromPackage ( pkg ) ;
570- }
571- }
572-
573- // Add files if specified
574- if ( config . files && config . files . length > 0 ) {
575- builder . fromFiles ( ...config . files ) ;
576- }
577-
578- // Configure TypeScript generator if specified
579- if ( config . typescript ) {
580- builder . typescriptDepricated ( config . typescript ) ;
581- }
582-
583- return builder ;
584- }
0 commit comments