@@ -47,6 +47,7 @@ type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & {
47
47
outputTemplate : string ;
48
48
inputBranded : boolean ;
49
49
outputBranded : boolean ;
50
+ suppressPermissiveTypes : boolean ;
50
51
}
51
52
52
53
class TextFormatter {
@@ -146,7 +147,11 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv
146
147
}
147
148
} else {
148
149
if ( dependency instanceof Protobuf . Type || dependency instanceof Protobuf . Enum ) {
149
- importedTypes = `${ inputName ( dependency . name ) } as ${ inputName ( typeInterfaceName ) } , ${ outputName ( dependency . name ) } as ${ outputName ( typeInterfaceName ) } ` ;
150
+ if ( options . suppressPermissiveTypes ) {
151
+ importedTypes = `${ outputName ( dependency . name ) } as ${ outputName ( typeInterfaceName ) } ` ;
152
+ } else {
153
+ importedTypes = `${ inputName ( dependency . name ) } as ${ inputName ( typeInterfaceName ) } , ${ outputName ( dependency . name ) } as ${ outputName ( typeInterfaceName ) } ` ;
154
+ }
150
155
} else if ( dependency instanceof Protobuf . Service ) {
151
156
importedTypes = `${ dependency . name } Client as ${ typeInterfaceName } Client, ${ dependency . name } Definition as ${ typeInterfaceName } Definition` ;
152
157
} else {
@@ -457,17 +462,21 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob
457
462
for ( const childType of childTypes . sort ( compareName ) ) {
458
463
const nameOverride = getTypeInterfaceName ( childType ) ;
459
464
if ( childType instanceof Protobuf . Type ) {
460
- generatePermissiveMessageInterface ( formatter , childType , options , nameOverride ) ;
461
- formatter . writeLine ( '' ) ;
465
+ if ( ! options . suppressPermissiveTypes ) {
466
+ generatePermissiveMessageInterface ( formatter , childType , options , nameOverride ) ;
467
+ formatter . writeLine ( '' ) ;
468
+ }
462
469
generateRestrictedMessageInterface ( formatter , childType , options , nameOverride ) ;
463
470
} else {
464
471
generateEnumInterface ( formatter , childType , options , nameOverride ) ;
465
472
}
466
473
formatter . writeLine ( '' ) ;
467
474
}
468
475
469
- generatePermissiveMessageInterface ( formatter , messageType , options ) ;
470
- formatter . writeLine ( '' ) ;
476
+ if ( ! options . suppressPermissiveTypes ) {
477
+ generatePermissiveMessageInterface ( formatter , messageType , options ) ;
478
+ formatter . writeLine ( '' ) ;
479
+ }
471
480
generateRestrictedMessageInterface ( formatter , messageType , options ) ;
472
481
}
473
482
@@ -491,20 +500,22 @@ function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum
491
500
formatter . writeLine ( '} as const;' ) ;
492
501
493
502
// Permissive Type
494
- formatter . writeLine ( '' ) ;
495
- if ( options . includeComments ) {
496
- formatComment ( formatter , enumType . comment , enumType . options ) ;
497
- }
498
- formatter . writeLine ( `export type ${ inputName ( name ) } =` )
499
- formatter . indent ( ) ;
500
- for ( const key of Object . keys ( enumType . values ) ) {
503
+ if ( ! options . suppressPermissiveTypes ) {
504
+ formatter . writeLine ( '' ) ;
501
505
if ( options . includeComments ) {
502
- formatComment ( formatter , enumType . comments [ key ] ) ;
506
+ formatComment ( formatter , enumType . comment , enumType . options ) ;
503
507
}
504
- formatter . writeLine ( `| '${ key } '` ) ;
505
- formatter . writeLine ( `| ${ enumType . values [ key ] } ` ) ;
508
+ formatter . writeLine ( `export type ${ inputName ( name ) } =` )
509
+ formatter . indent ( ) ;
510
+ for ( const key of Object . keys ( enumType . values ) ) {
511
+ if ( options . includeComments ) {
512
+ formatComment ( formatter , enumType . comments [ key ] ) ;
513
+ }
514
+ formatter . writeLine ( `| '${ key } '` ) ;
515
+ formatter . writeLine ( `| ${ enumType . values [ key ] } ` ) ;
516
+ }
517
+ formatter . unindent ( ) ;
506
518
}
507
- formatter . unindent ( ) ;
508
519
509
520
// Restrictive Type
510
521
formatter . writeLine ( '' ) ;
@@ -877,6 +888,7 @@ async function runScript() {
877
888
. option ( 'outputTemplate' , { string : true , default : `${ templateStr } __Output` } )
878
889
. option ( 'inputBranded' , boolDefaultFalseOption )
879
890
. option ( 'outputBranded' , boolDefaultFalseOption )
891
+ . option ( 'suppressPermissiveTypes' , boolDefaultFalseOption )
880
892
. coerce ( 'longs' , value => {
881
893
switch ( value ) {
882
894
case 'String' : return String ;
@@ -916,6 +928,7 @@ async function runScript() {
916
928
outputTemplate : 'Template for mapping output or "restricted" type names' ,
917
929
inputBranded : 'Output property for branded type for "permissive" types with fullName of the Message as its value' ,
918
930
outputBranded : 'Output property for branded type for "restricted" types with fullName of the Message as its value' ,
931
+ suppressPermissiveTypes : `Don't output "permissive" types` ,
919
932
} ) . demandOption ( [ 'outDir' ] )
920
933
. demand ( 1 )
921
934
. usage ( '$0 [options] filenames...' )
0 commit comments