import { ProtobufValue , MessageValue , PrimitiveValue } from './protobuf' ; type Proc = ( s : string ) => string ; function applyToProto ( v , proc ) { switch ( v . type . tag ) { case 'message' : return applyToProtoMessage ( v as MessageValue , proc ) ; case 'primitive' : return applyToProtoPrimitive ( v as PrimitiveValue , proc ) ; case 'enum' : return v ; } } export function applyToProtoMessage ( v , proc ) { const singleFields = v . singleFields . map ( ( [ name , v ] ) : [ string , ProtobufValue ] => [ name , applyToProto ( v , proc ) ] ) ; const repeatedFields = v . repeatedFields . map ( ( [ name , vs ] ) : [ string , ProtobufValue [ ] ] => [ name , vs . map ( v => applyToProto ( v , proc ) ) , ] ) ; const oneOfFields = v . oneOfFields . map ( ( [ name , [ sub , v ] ] ) : [ string , [ string , ProtobufValue ] ] => [ name , [ sub , applyToProto ( v , proc ) ] , ] ) ; const mapFields = v . mapFields . map ( ( [ name , kvPairs ] ) : [ string , [ string , ProtobufValue ] [ ] ] => [ name , kvPairs . map ( ( [ k , v ] ) => [ k , applyToProto ( v , proc ) ] ) , ] ) ; return { type : v . type , singleFields , repeatedFields , oneOfFields , mapFields , } ; } function applyToProtoPrimitive ( v , proc ) { const { type , value } = v ; return { type , value : proc ( value ) , } ; }