@@ -84,29 +84,41 @@ function generateService(
8484 // Generate the service interface
8585 f . print ( f . jsDoc ( service ) ) ;
8686 f . print ( "export interface " , localName ( service ) , " {" ) ;
87- for ( const method of service . methods ) {
87+ for ( let i = 0 ; i < service . methods . length ; i ++ ) {
88+ const method = service . methods [ i ] ;
8889 f . print ( f . jsDoc ( method , " " ) ) ;
89- f . print ( " " , method . name , "(" ) ;
9090 if ( method . methodKind === MethodKind . Unary ) {
91- f . print ( "request: " , method . input , ", abortSignal?: AbortSignal" ) ;
91+ f . print (
92+ " " ,
93+ method . name ,
94+ "(request: " , method . input , ", abortSignal?: AbortSignal): " ,
95+ "Promise<" , method . output , ">;"
96+ ) ;
9297 } else if ( method . methodKind === MethodKind . ServerStreaming ) {
93- f . print ( "request: " , method . input , ", abortSignal?: AbortSignal" ) ;
98+ f . print (
99+ " " ,
100+ method . name ,
101+ "(request: " , method . input , ", abortSignal?: AbortSignal): " ,
102+ MessageStream , "<" , method . output , ">;"
103+ ) ;
94104 } else if ( method . methodKind === MethodKind . ClientStreaming ) {
95- f . print ( "request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal" ) ;
105+ f . print (
106+ " " ,
107+ method . name ,
108+ "(request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal): " ,
109+ "Promise<" , method . output , ">;"
110+ ) ;
96111 } else if ( method . methodKind === MethodKind . BiDiStreaming ) {
97- f . print ( "request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal" ) ;
112+ f . print (
113+ " " ,
114+ method . name ,
115+ "(request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal): " ,
116+ MessageStream , "<" , method . output , ">;"
117+ ) ;
98118 }
99- f . print ( "): " ) ;
100- if ( method . methodKind === MethodKind . Unary ) {
101- f . print ( "Promise<" , method . output , ">" ) ;
102- } else if ( method . methodKind === MethodKind . ServerStreaming ) {
103- f . print ( MessageStream , "<" , method . output , ">" ) ;
104- } else if ( method . methodKind === MethodKind . ClientStreaming ) {
105- f . print ( "Promise<" , method . output , ">" ) ;
106- } else if ( method . methodKind === MethodKind . BiDiStreaming ) {
107- f . print ( MessageStream , "<" , method . output , ">" ) ;
119+ if ( i < service . methods . length - 1 ) {
120+ f . print ( ) ;
108121 }
109- f . print ( ) ;
110122 }
111123 f . print ( "}" ) ;
112124 f . print ( ) ;
@@ -133,21 +145,42 @@ function generateService(
133145
134146 const buildDecodeMessageTransformSymbol = createImportSymbol ( "buildDecodeMessageTransform" , "starpc" )
135147 const buildEncodeMessageTransformSymbol = createImportSymbol ( "buildEncodeMessageTransform" , "starpc" )
136- for ( const method of service . methods ) {
148+ for ( let i = 0 ; i < service . methods . length ; i ++ ) {
149+ const method = service . methods [ i ] ;
137150 f . print ( f . jsDoc ( method , " " ) ) ;
138- f . print ( " " , method . methodKind === MethodKind . Unary || method . methodKind === MethodKind . ClientStreaming ? "async " : "" , method . name , "(" ) ;
139151 if ( method . methodKind === MethodKind . Unary ) {
140- f . print ( "request: " , method . input , ", abortSignal?: AbortSignal" ) ;
152+ f . print (
153+ " " ,
154+ "async " ,
155+ method . name ,
156+ "(request: " , method . input , ", abortSignal?: AbortSignal): " ,
157+ "Promise<" , method . output , "> {"
158+ ) ;
141159 } else if ( method . methodKind === MethodKind . ServerStreaming ) {
142- f . print ( "request: " , method . input , ", abortSignal?: AbortSignal" ) ;
160+ f . print (
161+ " " ,
162+ method . name ,
163+ "(request: " , method . input , ", abortSignal?: AbortSignal): " ,
164+ MessageStream , "<" , method . output , "> {"
165+ ) ;
143166 } else if ( method . methodKind === MethodKind . ClientStreaming ) {
144- f . print ( "request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal" ) ;
167+ f . print (
168+ " " ,
169+ "async " ,
170+ method . name ,
171+ "(request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal): " ,
172+ "Promise<" , method . output , "> {"
173+ ) ;
145174 } else if ( method . methodKind === MethodKind . BiDiStreaming ) {
146- f . print ( "request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal" ) ;
175+ f . print (
176+ " " ,
177+ method . name ,
178+ "(request: " , MessageStream , "<" , method . input , ">, abortSignal?: AbortSignal): " ,
179+ MessageStream , "<" , method . output , "> {"
180+ ) ;
147181 }
148- f . print ( "): " ) ;
182+
149183 if ( method . methodKind === MethodKind . Unary ) {
150- f . print ( "Promise<" , method . output , "> {" ) ;
151184 f . print ( " const requestMsg = " , method . input , ".create(request)" ) ;
152185 f . print ( " const result = await this.rpc.request(" ) ;
153186 f . print ( " this.service," ) ;
@@ -156,9 +189,7 @@ function generateService(
156189 f . print ( " abortSignal || undefined," ) ;
157190 f . print ( " )" ) ;
158191 f . print ( " return " , method . output , ".fromBinary(result)" ) ;
159- f . print ( " }" ) ;
160192 } else if ( method . methodKind === MethodKind . ServerStreaming ) {
161- f . print ( MessageStream , "<" , method . output , "> {" ) ;
162193 f . print ( " const requestMsg = " , method . input , ".create(request)" ) ;
163194 f . print ( " const result = this.rpc.serverStreamingRequest(" ) ;
164195 f . print ( " this.service," ) ;
@@ -167,29 +198,27 @@ function generateService(
167198 f . print ( " abortSignal || undefined," ) ;
168199 f . print ( " )" ) ;
169200 f . print ( " return " , buildDecodeMessageTransformSymbol , "(" , method . output , ")(result)" ) ;
170- f . print ( " }" ) ;
171201 } else if ( method . methodKind === MethodKind . ClientStreaming ) {
172- f . print ( "Promise<" , method . output , "> {" ) ;
173202 f . print ( " const result = await this.rpc.clientStreamingRequest(" ) ;
174203 f . print ( " this.service," ) ;
175204 f . print ( " " , localName ( service ) , "Definition.methods." , method . name , ".name," ) ;
176205 f . print ( " " , buildEncodeMessageTransformSymbol , "(" , method . input , ")(request)," ) ;
177206 f . print ( " abortSignal || undefined," ) ;
178207 f . print ( " )" ) ;
179208 f . print ( " return " , method . output , ".fromBinary(result)" ) ;
180- f . print ( " }" ) ;
181209 } else if ( method . methodKind === MethodKind . BiDiStreaming ) {
182- f . print ( MessageStream , "<" , method . output , "> {" ) ;
183210 f . print ( " const result = this.rpc.bidirectionalStreamingRequest(" ) ;
184211 f . print ( " this.service," ) ;
185212 f . print ( " " , localName ( service ) , "Definition.methods." , method . name , ".name," ) ;
186213 f . print ( " " , buildEncodeMessageTransformSymbol , "(" , method . input , ")(request)," ) ;
187214 f . print ( " abortSignal || undefined," ) ;
188215 f . print ( " )" ) ;
189216 f . print ( " return " , buildDecodeMessageTransformSymbol , "(" , method . output , ")(result)" ) ;
190- f . print ( " }" ) ;
191217 }
192- f . print ( ) ;
218+ f . print ( " }" ) ;
219+ if ( i < service . methods . length - 1 ) {
220+ f . print ( ) ;
221+ }
193222 }
194223 f . print ( "}" ) ;
195224}
0 commit comments