Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
next(metadata, newListener);
},
sendMessage: function(message, next) {
// console.log("sendmessage", message);
next(message);
},
halfClose: function(next) {
// console.log("halfclose");
next();
},
cancel: function(message, next) {
// console.log("cancel", message);
next();
}
};
return new grpc.InterceptingCall(nextCall(options), requester);
};
function grpcDeadlineInterceptor (options, nextCall) {
// The method_definition object is defined in the grpc nodejs docs here:
// https://grpc.io/grpc/node/grpc.html#~MethodDefinition
const {
requestStream,
responseStream
} = options.method_definition
// If the request is a stream, then we do not want to set a deadline. Setting
// a deadline on a stream will break it at that particular interval.
if (requestStream || responseStream) {
return new grpc.InterceptingCall(nextCall(options))
}
// Check to make sure deadline isn't set in the individual options of a specific call
if (!options.hasOwnProperty('deadline')) {
options.deadline = grpcDeadline()
}
return new grpc.InterceptingCall(nextCall(options))
}
var loggingInterceptor = function(options, nextCall) {
return new grpc.InterceptingCall(nextCall(options), {
sendMessage: function(message, next) {
pinoLogger.warn('intercepted', message);
next(message);
}
});
};
public intercept(options: grpc.CallOptions, nextCall: NextCall): grpc.InterceptingCall {
if (isMutationRequest(options)) {
return new grpc.InterceptingCall(nextCall(options), this.requestInterceptor);
}
return new grpc.InterceptingCall(nextCall(options), this.blankInterceptor);
}
public intercept(options: grpc.CallOptions, nextCall: NextCall): grpc.InterceptingCall {
if (isMutationRequest(options)) {
return new grpc.InterceptingCall(nextCall(options), this.requestInterceptor);
}
return new grpc.InterceptingCall(nextCall(options), this.blankInterceptor);
}
return (options, nextCall) => {
return new grpc.InterceptingCall(nextCall(options), {
start: function (metadata, listener, next) {
let parent = getParent(asyncHooks.triggerAsyncId())
if (parent) {
tracer.inject(parent.span, 'FORMAT_GRPC_METADATA', metadata)
}
next(metadata, listener)
}
})
}
}