File tree Expand file tree Collapse file tree 3 files changed +33
-12
lines changed
Expand file tree Collapse file tree 3 files changed +33
-12
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ message HelloReply {
5959Service typings are not essential, but it's nice to have them
6060
6161``` sh
62- $ deno run --allow-read https://deno.land/x/grpc_basic@0.4.2 /gen/dts.ts ./greeter.proto > ./greeter.d.ts
62+ $ deno run --allow-read https://deno.land/x/grpc_basic@0.4.3 /gen/dts.ts ./greeter.proto > ./greeter.d.ts
6363```
6464
6565``` ts
@@ -80,7 +80,7 @@ export interface HelloReply {
8080### ` server.ts `
8181
8282``` ts
83- import { GrpcServer } from " https://deno.land/x/grpc_basic@0.4.2 /server.ts" ;
83+ import { GrpcServer } from " https://deno.land/x/grpc_basic@0.4.3 /server.ts" ;
8484import { Greeter } from " ./greeter.d.ts" ;
8585
8686const port = 15070 ;
@@ -114,7 +114,7 @@ for await (const conn of Deno.listen({ port })) {
114114### ` client.ts `
115115
116116``` ts
117- import { getClient } from " https://deno.land/x/grpc_basic@0.4.2 /client.ts" ;
117+ import { getClient } from " https://deno.land/x/grpc_basic@0.4.3 /client.ts" ;
118118import { Greeter } from " ./greeter.d.ts" ;
119119
120120const protoPath = new URL (" ./greeter.proto" , import .meta .url );
Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ export class GrpcClientImpl implements GrpcClient {
162162 return ;
163163 }
164164 this . flushing = true ;
165+ await this . ensureConnection ( ) ;
165166
166167 while ( this . frames . length ) {
167168 const f = this . frames . shift ( ) ;
@@ -236,7 +237,7 @@ export class GrpcClientImpl implements GrpcClient {
236237 f . headers = this . hd . decompress ( f . data ) ;
237238 }
238239
239- this . c . _receive ( f , ( ) => { } ) ;
240+ this . c . _write ( f , '' , ( ) => { } ) ;
240241 }
241242 }
242243 }
@@ -293,11 +294,11 @@ export class GrpcClientImpl implements GrpcClient {
293294 ] ) ;
294295
295296 if ( frame . type === "DATA" ) {
296- const res = this . root
297- . lookupType ( method . responseType )
298- . decode ( frame . data . slice ( 5 ) ) as unknown as Res ;
297+ const res = this . root
298+ . lookupType ( method . responseType )
299+ . decode ( frame . data . slice ( 5 ) ) as unknown as Res ;
299300
300- return res ;
301+ return res ;
301302 }
302303
303304 if ( frame . type === "HEADERS" && frame . flags . END_STREAM ) {
Original file line number Diff line number Diff line change 11export const logData = false ;
22
3- export const noop = ( ) => { } ;
3+ import { hexdump } from "https://deno.land/x/prohazko@1.3.5/hex.ts" ;
4+
5+ function consoleLog ( level : string , ...args : any [ ] ) {
6+ if ( ! logData ) {
7+ return ;
8+ }
9+ let [ more , msg ] = args || [ ] ;
10+
11+ if ( more && more . frame ) {
12+ more = `frame ${ more . frame . type } of s:${
13+ more . frame . stream
14+ } with flags ${ JSON . stringify ( more . frame . flags ) } `;
15+ }
16+
17+ if ( more && more . data ) {
18+ more = "\n" + hexdump ( more . data ) . trim ( ) ;
19+ }
20+
21+ console . log ( `${ new Date ( ) . toISOString ( ) } ${ level [ 0 ] } ${ msg } ` , more ) ;
22+ }
23+
424export const consoleLogger = ( ) => ( {
5- debug : ( ...args : any [ ] ) => ( logData ? console . log ( ... args ) : noop ( ) ) ,
6- trace : ( ...args : any [ ] ) => ( logData ? console . log ( ... args ) : noop ( ) ) ,
7- error : ( ...args : any [ ] ) => ( logData ? console . error ( ... args ) : noop ( ) ) ,
25+ debug : ( ...args : any [ ] ) => consoleLog ( "debug" , ... args ) ,
26+ trace : ( ...args : any [ ] ) => consoleLog ( "trace" , ... args ) ,
27+ error : ( ...args : any [ ] ) => consoleLog ( "error" , ... args ) ,
828} ) ;
You can’t perform that action at this time.
0 commit comments