@@ -46,8 +46,8 @@ export function commandIsInPath(cmd: string): boolean {
46
46
}
47
47
}
48
48
49
- type ReaderMethod = keyof BinaryReader ;
50
- type WriterMethod = keyof BinaryWriter ;
49
+ type ReaderMethod = keyof BinaryReader | "map" ;
50
+ type WriterMethod = keyof BinaryWriter | "map" ;
51
51
52
52
interface Descriptor {
53
53
defaultValue : string ;
@@ -183,6 +183,21 @@ export function getDescriptor(
183
183
identifierTable ,
184
184
fileDescriptorProto
185
185
) ;
186
+ // Hack until better option:
187
+ // https://github.com/protocolbuffers/protobuf/issues/9369
188
+ const isMap =
189
+ _type . endsWith ( "Entry" ) && ! field . toArray ( ) [ 0 ] . endsWith ( "Entry" ) ;
190
+
191
+ if ( isMap ) {
192
+ return {
193
+ defaultValue : "{}" ,
194
+ optional,
195
+ read : "map" ,
196
+ repeated : false ,
197
+ tsType : name . slice ( 0 , name . lastIndexOf ( "Entry" ) ) ,
198
+ write : "map" ,
199
+ } ;
200
+ }
186
201
187
202
return {
188
203
defaultValue : "undefined" ,
@@ -445,6 +460,7 @@ interface MessageOpts {
445
460
fullyQualifiedName : string ;
446
461
fields : Field [ ] ;
447
462
comments ?: Comments ;
463
+ isMap : boolean ;
448
464
}
449
465
450
466
type EnumType = { type : "enum" ; content : EnumOpts } ;
@@ -627,15 +643,22 @@ export function processTypes(
627
643
}
628
644
629
645
function getMessage ( namespacing : string , node : DescriptorProto ) : MessageOpts {
630
- const name = node . getName ( ) ;
646
+ let name = node . getName ( ) ;
631
647
if ( ! name ) {
632
648
throw new Error ( `Expected name for ${ node } ` ) ;
633
649
}
650
+
651
+ // Hack until better option:
652
+ // https://github.com/protocolbuffers/protobuf/issues/9369
653
+ const isMap = name . endsWith ( "Entry" ) && node . getFieldList ( ) . length == 2 ;
654
+ name = isMap ? name . slice ( 0 , name . lastIndexOf ( "Entry" ) ) : name ;
655
+
634
656
const opts : MessageOpts = {
635
657
name,
636
658
fullyQualifiedName : applyNamespace ( namespacing , name , {
637
659
removeLeadingPeriod : true ,
638
660
} ) ,
661
+ isMap,
639
662
fields : node
640
663
. getFieldList ( )
641
664
. map ( ( value ) => {
0 commit comments