@@ -31,6 +31,10 @@ type GlobalFieldCache = {
3131 [ prop : string ] : { definition : string } ;
3232} ;
3333
34+ type ModularBlockCache = {
35+ [ prop : string ] : string ;
36+ } ;
37+
3438enum TypeFlags {
3539 BuiltinJS = 1 << 0 ,
3640 BuiltinCS = 1 << 1 ,
@@ -65,7 +69,10 @@ export default function (userOptions: TSGenOptions) {
6569 const visitedGlobalFields = new Set < string > ( ) ;
6670 const visitedContentTypes = new Set < string > ( ) ;
6771 const cachedGlobalFields : GlobalFieldCache = { } ;
72+ const cachedModularBlocks : ModularBlockCache = { } ;
6873 const modularBlockInterfaces = new Set < string > ( ) ;
74+ const uniqueBlockInterfaces = new Set < string > ( ) ;
75+ let counter = 1 ;
6976
7077 const typeMap : TypeMap = {
7178 text : { func : type_text , track : true , flag : TypeFlags . BuiltinJS } ,
@@ -188,21 +195,6 @@ export default function (userOptions: TSGenOptions) {
188195 return op_paren ( choices . map ( ( v ) => get_value ( v ) ) . join ( " | " ) ) ;
189196 }
190197
191- function visit_block_names (
192- field : ContentstackTypes . Field ,
193- except : ContentstackTypes . Block
194- ) {
195- const uids : string [ ] = [ ] ;
196-
197- field . blocks . forEach ( ( block ) => {
198- if ( block . uid !== except . uid ) {
199- uids . push ( `${ block . uid } : undefined;` ) ;
200- }
201- } ) ;
202-
203- return uids . join ( "\n" ) ;
204- }
205-
206198 function visit_field_type ( field : ContentstackTypes . Field ) {
207199 let type = "any" ;
208200
@@ -280,7 +272,8 @@ export default function (userOptions: TSGenOptions) {
280272 }
281273
282274 function type_modular_blocks ( field : ContentstackTypes . Field ) : string {
283- const blockInterfaceName = name_type ( field . uid ) ;
275+ let blockInterfaceName = name_type ( field . uid ) ;
276+
284277 const blockInterfaces = field . blocks . map ( ( block ) => {
285278 const fieldType =
286279 block . reference_to && cachedGlobalFields [ name_type ( block . reference_to ) ]
@@ -292,6 +285,16 @@ export default function (userOptions: TSGenOptions) {
292285 : `{\n ${ fieldType } }` ;
293286 return `${ block . uid } : ${ schema } ` ;
294287 } ) ;
288+ const blockInterfacesKey = blockInterfaces . join ( ";" ) ;
289+
290+ if ( ! uniqueBlockInterfaces . has ( blockInterfacesKey ) ) {
291+ uniqueBlockInterfaces . add ( blockInterfacesKey ) ;
292+ // Keep appending a counter until a unique name is found
293+ while ( cachedModularBlocks [ blockInterfaceName ] ) {
294+ blockInterfaceName = `${ blockInterfaceName } ${ counter } ` ;
295+ counter ++ ;
296+ }
297+ }
295298
296299 const modularInterface = [
297300 `export interface ${ blockInterfaceName } {` ,
0 commit comments