mirror of https://github.com/grpc/grpc-node.git
				
				
				
			Merge pull request #557 from WeiranFang/call-invocation-transformer
Call invocation transformer
This commit is contained in:
		
						commit
						8df65a91a2
					
				|  | @ -15,3 +15,8 @@ packages/grpc-native-core/src/node/ | ||||||
| 
 | 
 | ||||||
| .nyc_output/ | .nyc_output/ | ||||||
| reports/ | reports/ | ||||||
|  | 
 | ||||||
|  | package-lock.json | ||||||
|  | 
 | ||||||
|  | # Test generated files | ||||||
|  | coverage | ||||||
|  |  | ||||||
|  | @ -383,12 +383,16 @@ function Client(address, credentials, options) { | ||||||
|       .resolveInterceptorProviders(self.$interceptor_providers, method_definition) |       .resolveInterceptorProviders(self.$interceptor_providers, method_definition) | ||||||
|       .concat(self.$interceptors); |       .concat(self.$interceptors); | ||||||
|   }); |   }); | ||||||
|  | 
 | ||||||
|  |   this.$callInvocationTransformer = options.callInvocationTransformer; | ||||||
|  | 
 | ||||||
|   let channelOverride = options.channelOverride; |   let channelOverride = options.channelOverride; | ||||||
|   let channelFactoryOverride = options.channelFactoryOverride; |   let channelFactoryOverride = options.channelFactoryOverride; | ||||||
|   // Exclude channel options which have already been consumed
 |   // Exclude channel options which have already been consumed
 | ||||||
|   var channel_options = _.omit(options, |   var channel_options = _.omit(options, | ||||||
|      ['interceptors', 'interceptor_providers', |      ['interceptors', 'interceptor_providers', | ||||||
|       'channelOverride', 'channelFactoryOverride']); |       'channelOverride', 'channelFactoryOverride', | ||||||
|  |       'callInvocationTransformer']); | ||||||
|   /* Private fields use $ as a prefix instead of _ because it is an invalid |   /* Private fields use $ as a prefix instead of _ because it is an invalid | ||||||
|    * prefix of a method name */ |    * prefix of a method name */ | ||||||
|   if (channelOverride) { |   if (channelOverride) { | ||||||
|  | @ -480,22 +484,50 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize, | ||||||
| 
 | 
 | ||||||
|   metadata = metadata.clone(); |   metadata = metadata.clone(); | ||||||
| 
 | 
 | ||||||
|   var intercepting_call = client_interceptors.getInterceptingCall( |   var callProperties = { | ||||||
|     method_definition, |     argument: argument, | ||||||
|     options, |     metadata: metadata, | ||||||
|     Client.prototype.resolveCallInterceptors.call(this, method_definition, options.interceptors, options.interceptor_providers), |     call: new ClientUnaryCall(), | ||||||
|     this.$channel, |     channel: this.$channel, | ||||||
|     callback |     methodDefinition: method_definition, | ||||||
|   ); |     callOptions: options, | ||||||
|   var emitter = new ClientUnaryCall(intercepting_call); |     callback: callback | ||||||
|   var last_listener = client_interceptors.getLastListener( |   }; | ||||||
|     method_definition, | 
 | ||||||
|     emitter, |   // Transform call properties if specified.
 | ||||||
|     callback |   if (this.$callInvocationTransformer) { | ||||||
|  |     callProperties = this.$callInvocationTransformer(callProperties); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   var callOptions = callProperties.callOptions; | ||||||
|  |   var methodDefinition = callProperties.methodDefinition; | ||||||
|  | 
 | ||||||
|  |   var interceptors = Client.prototype.resolveCallInterceptors.call( | ||||||
|  |     this, | ||||||
|  |     methodDefinition, | ||||||
|  |     callOptions.interceptors, | ||||||
|  |     callOptions.interceptor_providers | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   intercepting_call.start(metadata, last_listener); |   var intercepting_call = client_interceptors.getInterceptingCall( | ||||||
|   intercepting_call.sendMessage(argument); |     methodDefinition, | ||||||
|  |     callOptions, | ||||||
|  |     interceptors, | ||||||
|  |     callProperties.channel, | ||||||
|  |     callProperties.callback | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   var emitter = callProperties.call; | ||||||
|  |   emitter.call = intercepting_call; | ||||||
|  | 
 | ||||||
|  |   var last_listener = client_interceptors.getLastListener( | ||||||
|  |     methodDefinition, | ||||||
|  |     emitter, | ||||||
|  |     callProperties.callback | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   intercepting_call.start(callProperties.metadata, last_listener); | ||||||
|  |   intercepting_call.sendMessage(callProperties.argument); | ||||||
|   intercepting_call.halfClose(); |   intercepting_call.halfClose(); | ||||||
| 
 | 
 | ||||||
|   return emitter; |   return emitter; | ||||||
|  | @ -555,21 +587,48 @@ Client.prototype.makeClientStreamRequest = function(path, serialize, | ||||||
| 
 | 
 | ||||||
|   metadata = metadata.clone(); |   metadata = metadata.clone(); | ||||||
| 
 | 
 | ||||||
|   var intercepting_call = client_interceptors.getInterceptingCall( |   var callProperties = { | ||||||
|     method_definition, |     metadata: metadata, | ||||||
|     options, |     call: new ClientWritableStream(), | ||||||
|     Client.prototype.resolveCallInterceptors.call(this, method_definition, options.interceptors, options.interceptor_providers), |     channel: this.$channel, | ||||||
|     this.$channel, |     methodDefinition: method_definition, | ||||||
|     callback |     callOptions: options, | ||||||
|   ); |     callback: callback | ||||||
|   var emitter = new ClientWritableStream(intercepting_call); |   }; | ||||||
|   var last_listener = client_interceptors.getLastListener( | 
 | ||||||
|     method_definition, |   // Transform call properties if specified.
 | ||||||
|     emitter, |   if (this.$callInvocationTransformer) { | ||||||
|     callback |     callProperties = this.$callInvocationTransformer(callProperties); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   var callOptions = callProperties.callOptions; | ||||||
|  |   var methodDefinition = callProperties.methodDefinition; | ||||||
|  | 
 | ||||||
|  |   var interceptors = Client.prototype.resolveCallInterceptors.call( | ||||||
|  |     this, | ||||||
|  |     methodDefinition, | ||||||
|  |     callOptions.interceptors, | ||||||
|  |     callOptions.interceptor_providers | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   intercepting_call.start(metadata, last_listener); |   var intercepting_call = client_interceptors.getInterceptingCall( | ||||||
|  |     methodDefinition, | ||||||
|  |     callOptions, | ||||||
|  |     interceptors, | ||||||
|  |     callProperties.channel, | ||||||
|  |     callProperties.callback | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   var emitter = callProperties.call; | ||||||
|  |   emitter.call = intercepting_call; | ||||||
|  | 
 | ||||||
|  |   var last_listener = client_interceptors.getLastListener( | ||||||
|  |     methodDefinition, | ||||||
|  |     emitter, | ||||||
|  |     callProperties.callback | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   intercepting_call.start(callProperties.metadata, last_listener); | ||||||
| 
 | 
 | ||||||
|   return emitter; |   return emitter; | ||||||
| }; | }; | ||||||
|  | @ -613,22 +672,46 @@ Client.prototype.makeServerStreamRequest = function(path, serialize, | ||||||
| 
 | 
 | ||||||
|   metadata = metadata.clone(); |   metadata = metadata.clone(); | ||||||
| 
 | 
 | ||||||
|   var emitter = new ClientReadableStream(); |   var callProperties = { | ||||||
|  |     argument: argument, | ||||||
|  |     metadata: metadata, | ||||||
|  |     call: new ClientReadableStream(), | ||||||
|  |     channel: this.$channel, | ||||||
|  |     methodDefinition: method_definition, | ||||||
|  |     callOptions: options, | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   // Transform call properties if specified.
 | ||||||
|  |   if (this.$callInvocationTransformer) { | ||||||
|  |     callProperties = this.$callInvocationTransformer(callProperties); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   var callOptions = callProperties.callOptions; | ||||||
|  |   var methodDefinition = callProperties.methodDefinition; | ||||||
|  | 
 | ||||||
|  |   var interceptors = Client.prototype.resolveCallInterceptors.call( | ||||||
|  |     this, | ||||||
|  |     methodDefinition, | ||||||
|  |     callOptions.interceptors, | ||||||
|  |     callOptions.interceptor_providers | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   var emitter = callProperties.call; | ||||||
|   var intercepting_call = client_interceptors.getInterceptingCall( |   var intercepting_call = client_interceptors.getInterceptingCall( | ||||||
|     method_definition, |     methodDefinition, | ||||||
|     options, |     callOptions, | ||||||
|     Client.prototype.resolveCallInterceptors.call(this, method_definition, options.interceptors, options.interceptor_providers), |     interceptors, | ||||||
|     this.$channel, |     callProperties.channel, | ||||||
|     emitter |     emitter | ||||||
|   ); |   ); | ||||||
|   emitter.call = intercepting_call; |   emitter.call = intercepting_call; | ||||||
|   var last_listener = client_interceptors.getLastListener( |   var last_listener = client_interceptors.getLastListener( | ||||||
|     method_definition, |     methodDefinition, | ||||||
|     emitter |     emitter | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   intercepting_call.start(metadata, last_listener); |   intercepting_call.start(callProperties.metadata, last_listener); | ||||||
|   intercepting_call.sendMessage(argument); |   intercepting_call.sendMessage(callProperties.argument); | ||||||
|   intercepting_call.halfClose(); |   intercepting_call.halfClose(); | ||||||
| 
 | 
 | ||||||
|   return emitter; |   return emitter; | ||||||
|  | @ -669,21 +752,45 @@ Client.prototype.makeBidiStreamRequest = function(path, serialize, | ||||||
| 
 | 
 | ||||||
|   metadata = metadata.clone(); |   metadata = metadata.clone(); | ||||||
| 
 | 
 | ||||||
|   var emitter = new ClientDuplexStream(); |   var callProperties = { | ||||||
|  |     metadata: metadata, | ||||||
|  |     call: new ClientDuplexStream(), | ||||||
|  |     channel: this.$channel, | ||||||
|  |     methodDefinition: method_definition, | ||||||
|  |     callOptions: options, | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   // Transform call properties if specified.
 | ||||||
|  |   if (this.$callInvocationTransformer) { | ||||||
|  |     callProperties = this.$callInvocationTransformer(callProperties); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   var callOptions = callProperties.callOptions; | ||||||
|  |   var methodDefinition = callProperties.methodDefinition; | ||||||
|  | 
 | ||||||
|  |   var interceptors = Client.prototype.resolveCallInterceptors.call( | ||||||
|  |     this, | ||||||
|  |     methodDefinition, | ||||||
|  |     callOptions.interceptors, | ||||||
|  |     callOptions.interceptor_providers | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   var emitter = callProperties.call; | ||||||
|   var intercepting_call = client_interceptors.getInterceptingCall( |   var intercepting_call = client_interceptors.getInterceptingCall( | ||||||
|     method_definition, |     methodDefinition, | ||||||
|     options, |     callOptions, | ||||||
|     Client.prototype.resolveCallInterceptors.call(this, method_definition, options.interceptors, options.interceptor_providers), |     interceptors, | ||||||
|     this.$channel, |     callProperties.channel, | ||||||
|     emitter |     emitter | ||||||
|   ); |   ); | ||||||
|   emitter.call = intercepting_call; |   emitter.call = intercepting_call; | ||||||
|   var last_listener = client_interceptors.getLastListener( |   var last_listener = client_interceptors.getLastListener( | ||||||
|     method_definition, |     methodDefinition, | ||||||
|     emitter |     emitter | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   intercepting_call.start(metadata, last_listener); |   intercepting_call.start(callProperties.metadata, last_listener); | ||||||
| 
 | 
 | ||||||
|   return emitter; |   return emitter; | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue