@@ -34,6 +34,24 @@ interface FullProofkitTypegenJsonFile {
3434 config : AnyDataSourceConfig | AnyDataSourceConfig [ ] ;
3535}
3636
37+ // Helper function to normalize data sources by adding default type for backwards compatibility
38+ // This mirrors the zod preprocess in @proofkit /typegen that defaults type to "fmdapi"
39+ function normalizeDataSource ( ds : AnyDataSourceConfig ) : AnyDataSourceConfig {
40+ if ( ! ( "type" in ds ) || ds . type === undefined ) {
41+ return { ...( ds as object ) , type : "fmdapi" } as AnyDataSourceConfig ;
42+ }
43+ return ds ;
44+ }
45+
46+ function normalizeConfig (
47+ config : AnyDataSourceConfig | AnyDataSourceConfig [ ] ,
48+ ) : AnyDataSourceConfig | AnyDataSourceConfig [ ] {
49+ if ( Array . isArray ( config ) ) {
50+ return config . map ( normalizeDataSource ) ;
51+ }
52+ return normalizeDataSource ( config ) ;
53+ }
54+
3755// Helper functions for JSON config
3856async function readJsonConfigFile ( configPath : string ) : Promise < FullProofkitTypegenJsonFile | null > {
3957 if ( ! fs . existsSync ( configPath ) ) {
@@ -42,6 +60,10 @@ async function readJsonConfigFile(configPath: string): Promise<FullProofkitTypeg
4260 try {
4361 const fileContent = await fs . readFile ( configPath , "utf8" ) ;
4462 const parsed = parseJsonc ( fileContent ) as FullProofkitTypegenJsonFile ;
63+ // Normalize config to add default type for backwards compatibility
64+ if ( parsed . config ) {
65+ parsed . config = normalizeConfig ( parsed . config ) ;
66+ }
4567 return parsed ;
4668 } catch ( error ) {
4769 console . error ( `Error reading or parsing JSONC config at ${ configPath } :` , error ) ;
@@ -213,7 +235,9 @@ export function getClientSuffix({
213235 const fileContent = fs . readFileSync ( jsonConfigPath , "utf8" ) ;
214236 const parsed = parseJsonc ( fileContent ) as FullProofkitTypegenJsonFile ;
215237
216- const configToSearch = Array . isArray ( parsed . config ) ? parsed . config : [ parsed . config ] ;
238+ // Normalize config to add default type for backwards compatibility
239+ const normalizedConfig = normalizeConfig ( parsed . config ) ;
240+ const configToSearch = Array . isArray ( normalizedConfig ) ? normalizedConfig : [ normalizedConfig ] ;
217241
218242 const targetDataSource = configToSearch . find (
219243 ( ds ) : ds is FmdapiDataSourceConfig =>
@@ -242,7 +266,9 @@ export function getExistingSchemas({
242266 const fileContent = fs . readFileSync ( jsonConfigPath , "utf8" ) ;
243267 const parsed = parseJsonc ( fileContent ) as FullProofkitTypegenJsonFile ;
244268
245- const configToSearch = Array . isArray ( parsed . config ) ? parsed . config : [ parsed . config ] ;
269+ // Normalize config to add default type for backwards compatibility
270+ const normalizedConfig = normalizeConfig ( parsed . config ) ;
271+ const configToSearch = Array . isArray ( normalizedConfig ) ? normalizedConfig : [ normalizedConfig ] ;
246272
247273 const targetDataSource = configToSearch . find (
248274 ( ds ) : ds is FmdapiDataSourceConfig =>
0 commit comments