@grpc/grpc-js
Advanced tools
Comparing version 0.6.11 to 0.6.12
@@ -56,3 +56,7 @@ "use strict"; | ||
this.disconnectListener = () => { | ||
this.endCall({ code: constants_1.Status.UNAVAILABLE, details: 'Connection dropped', metadata: new metadata_1.Metadata() }); | ||
this.endCall({ | ||
code: constants_1.Status.UNAVAILABLE, | ||
details: 'Connection dropped', | ||
metadata: new metadata_1.Metadata(), | ||
}); | ||
}; | ||
@@ -59,0 +63,0 @@ } |
@@ -86,5 +86,5 @@ import { Deadline, Call, Http2CallStream } from './call-stream'; | ||
getTarget(): string; | ||
getConnectivityState(): ConnectivityState; | ||
getConnectivityState(tryToConnect: boolean): ConnectivityState; | ||
watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void; | ||
createCall(method: string, deadline: Deadline | null | undefined, host: string | null | undefined, parentCall: Call | null | undefined, propagateFlags: number | null | undefined): Call; | ||
} |
@@ -148,3 +148,7 @@ "use strict"; | ||
updateState(newState) { | ||
logging_1.trace(constants_1.LogVerbosity.DEBUG, 'connectivity_state', this.target + ' ' + ConnectivityState[this.connectivityState] + ' -> ' + ConnectivityState[newState]); | ||
logging_1.trace(constants_1.LogVerbosity.DEBUG, 'connectivity_state', this.target + | ||
' ' + | ||
ConnectivityState[this.connectivityState] + | ||
' -> ' + | ||
ConnectivityState[newState]); | ||
this.connectivityState = newState; | ||
@@ -171,4 +175,8 @@ const watchersCopy = this.connectivityStateWatchers.slice(); | ||
} | ||
getConnectivityState() { | ||
return this.connectivityState; | ||
getConnectivityState(tryToConnect) { | ||
const connectivityState = this.connectivityState; | ||
if (tryToConnect) { | ||
this.resolvingLoadBalancer.exitIdle(); | ||
} | ||
return connectivityState; | ||
} | ||
@@ -175,0 +183,0 @@ watchConnectivityState(currentState, deadline, callback) { |
import { Metadata } from './metadata'; | ||
import { Call, Listener, MetadataListener, MessageListener, StatusListener, InterceptingListener, WriteObject, WriteCallback } from './call-stream'; | ||
import { Listener, MetadataListener, MessageListener, StatusListener, InterceptingListener, MessageContext } from './call-stream'; | ||
import { Status } from './constants'; | ||
@@ -8,2 +8,6 @@ import { Channel } from './channel'; | ||
import { ClientMethodDefinition } from './make-client'; | ||
/** | ||
* Error class associated with passing both interceptors and interceptor | ||
* providers to a client constructor or as call options. | ||
*/ | ||
export declare class InterceptorConfigurationError extends Error { | ||
@@ -24,2 +28,5 @@ constructor(message: string); | ||
} | ||
/** | ||
* An object with methods for intercepting and modifying outgoing call operations. | ||
*/ | ||
export interface FullRequester { | ||
@@ -55,20 +62,40 @@ start: MetadataRequester; | ||
} | ||
export declare class InterceptingCall implements Call { | ||
export interface InterceptingCallInterface { | ||
cancelWithStatus(status: Status, details: string): void; | ||
getPeer(): string; | ||
start(metadata: Metadata, listener?: Partial<InterceptingListener>): void; | ||
sendMessageWithContext(context: MessageContext, message: any): void; | ||
sendMessage(message: any): void; | ||
startRead(): void; | ||
halfClose(): void; | ||
setCredentials(credentials: CallCredentials): void; | ||
} | ||
export declare class InterceptingCall implements InterceptingCallInterface { | ||
private nextCall; | ||
/** | ||
* The requester that this InterceptingCall uses to modify outgoing operations | ||
*/ | ||
private requester; | ||
constructor(nextCall: Call, requester?: Requester); | ||
/** | ||
* Indicates that a message has been passed to the listener's onReceiveMessage | ||
* method it has not been passed to the corresponding next callback | ||
*/ | ||
private processingMessage; | ||
/** | ||
* Indicates that a status was received but could not be propagated because | ||
* a message was still being processed. | ||
*/ | ||
private pendingHalfClose; | ||
constructor(nextCall: InterceptingCallInterface, requester?: Requester); | ||
cancelWithStatus(status: Status, details: string): void; | ||
getPeer(): string; | ||
start(metadata: Metadata, interceptingListener: InterceptingListener): void; | ||
write(writeObj: WriteObject, callback: WriteCallback): void; | ||
start(metadata: Metadata, interceptingListener?: Partial<InterceptingListener>): void; | ||
sendMessageWithContext(context: MessageContext, message: any): void; | ||
sendMessage(message: any): void; | ||
startRead(): void; | ||
halfClose(): void; | ||
getDeadline(): number | Date; | ||
getCredentials(): CallCredentials; | ||
setCredentials(credentials: CallCredentials): void; | ||
getMethod(): string; | ||
getHost(): string; | ||
} | ||
export interface NextCall { | ||
(options: InterceptorOptions): Call; | ||
(options: InterceptorOptions): InterceptingCallInterface; | ||
} | ||
@@ -87,2 +114,2 @@ export interface Interceptor { | ||
} | ||
export declare function getInterceptingCall(interceptorArgs: InterceptorArguments, methodDefinition: ClientMethodDefinition<any, any>, options: CallOptions, channel: Channel): Call; | ||
export declare function getInterceptingCall(interceptorArgs: InterceptorArguments, methodDefinition: ClientMethodDefinition<any, any>, options: CallOptions, channel: Channel): InterceptingCallInterface; |
@@ -22,2 +22,6 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
/** | ||
* Error class associated with passing both interceptors and interceptor | ||
* providers to a client constructor or as call options. | ||
*/ | ||
class InterceptorConfigurationError extends Error { | ||
@@ -53,3 +57,3 @@ constructor(message) { | ||
onReceiveMessage: this.message, | ||
onReceiveStatus: this.status | ||
onReceiveStatus: this.status, | ||
}; | ||
@@ -87,3 +91,3 @@ } | ||
halfClose: this.halfClose, | ||
cancel: this.cancel | ||
cancel: this.cancel, | ||
}; | ||
@@ -93,2 +97,6 @@ } | ||
exports.RequesterBuilder = RequesterBuilder; | ||
/** | ||
* A Listener with a default pass-through implementation of each method. Used | ||
* for filling out Listeners with some methods omitted. | ||
*/ | ||
const defaultListener = { | ||
@@ -103,4 +111,8 @@ onReceiveMetadata: (metadata, next) => { | ||
next(status); | ||
} | ||
}, | ||
}; | ||
/** | ||
* A Requester with a default pass-through implementation of each method. Used | ||
* for filling out Requesters with some methods omitted. | ||
*/ | ||
const defaultRequester = { | ||
@@ -113,19 +125,29 @@ start: (metadata, listener, next) => { | ||
}, | ||
halfClose: (next) => { | ||
halfClose: next => { | ||
next(); | ||
}, | ||
cancel: (next) => { | ||
cancel: next => { | ||
next(); | ||
} | ||
}, | ||
}; | ||
class InterceptingCall { | ||
constructor(nextCall, requester) { | ||
var _a, _b, _c, _d; | ||
this.nextCall = nextCall; | ||
/** | ||
* Indicates that a message has been passed to the listener's onReceiveMessage | ||
* method it has not been passed to the corresponding next callback | ||
*/ | ||
this.processingMessage = false; | ||
/** | ||
* Indicates that a status was received but could not be propagated because | ||
* a message was still being processed. | ||
*/ | ||
this.pendingHalfClose = false; | ||
if (requester) { | ||
// Undefined elements overwrite, unset ones do not | ||
this.requester = { | ||
start: requester.start || defaultRequester.start, | ||
sendMessage: requester.sendMessage || defaultRequester.sendMessage, | ||
halfClose: requester.halfClose || defaultRequester.halfClose, | ||
cancel: requester.cancel || defaultRequester.cancel | ||
start: (_a = requester.start, (_a !== null && _a !== void 0 ? _a : defaultRequester.start)), | ||
sendMessage: (_b = requester.sendMessage, (_b !== null && _b !== void 0 ? _b : defaultRequester.sendMessage)), | ||
halfClose: (_c = requester.halfClose, (_c !== null && _c !== void 0 ? _c : defaultRequester.halfClose)), | ||
cancel: (_d = requester.cancel, (_d !== null && _d !== void 0 ? _d : defaultRequester.cancel)), | ||
}; | ||
@@ -146,3 +168,10 @@ } | ||
start(metadata, interceptingListener) { | ||
this.requester.start(metadata, interceptingListener, (md, listener) => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
const fullInterceptingListener = { | ||
onReceiveMetadata: (_c = (_b = (_a = interceptingListener) === null || _a === void 0 ? void 0 : _a.onReceiveMetadata) === null || _b === void 0 ? void 0 : _b.bind(interceptingListener), (_c !== null && _c !== void 0 ? _c : (metadata => { }))), | ||
onReceiveMessage: (_f = (_e = (_d = interceptingListener) === null || _d === void 0 ? void 0 : _d.onReceiveMessage) === null || _e === void 0 ? void 0 : _e.bind(interceptingListener), (_f !== null && _f !== void 0 ? _f : (message => { }))), | ||
onReceiveStatus: (_j = (_h = (_g = interceptingListener) === null || _g === void 0 ? void 0 : _g.onReceiveStatus) === null || _h === void 0 ? void 0 : _h.bind(interceptingListener), (_j !== null && _j !== void 0 ? _j : (status => { }))), | ||
}; | ||
this.requester.start(metadata, fullInterceptingListener, (md, listener) => { | ||
var _a, _b, _c; | ||
let finalInterceptingListener; | ||
@@ -154,7 +183,7 @@ if (call_stream_1.isInterceptingListener(listener)) { | ||
const fullListener = { | ||
onReceiveMetadata: listener.onReceiveMetadata || defaultListener.onReceiveMetadata, | ||
onReceiveMessage: listener.onReceiveMessage || defaultListener.onReceiveMessage, | ||
onReceiveStatus: listener.onReceiveStatus || defaultListener.onReceiveStatus | ||
onReceiveMetadata: (_a = listener.onReceiveMetadata, (_a !== null && _a !== void 0 ? _a : defaultListener.onReceiveMetadata)), | ||
onReceiveMessage: (_b = listener.onReceiveMessage, (_b !== null && _b !== void 0 ? _b : defaultListener.onReceiveMessage)), | ||
onReceiveStatus: (_c = listener.onReceiveStatus, (_c !== null && _c !== void 0 ? _c : defaultListener.onReceiveStatus)), | ||
}; | ||
finalInterceptingListener = new call_stream_1.InterceptingListenerImpl(fullListener, interceptingListener); | ||
finalInterceptingListener = new call_stream_1.InterceptingListenerImpl(fullListener, fullInterceptingListener); | ||
} | ||
@@ -164,7 +193,17 @@ this.nextCall.start(md, finalInterceptingListener); | ||
} | ||
write(writeObj, callback) { | ||
this.requester.sendMessage(writeObj.message, (message) => { | ||
this.nextCall.write({ message: message, flags: writeObj.flags }, callback); | ||
// tslint:disable-next-line no-any | ||
sendMessageWithContext(context, message) { | ||
this.processingMessage = true; | ||
this.requester.sendMessage(message, finalMessage => { | ||
this.processingMessage = false; | ||
this.nextCall.sendMessageWithContext(context, finalMessage); | ||
if (this.pendingHalfClose) { | ||
this.nextCall.halfClose(); | ||
} | ||
}); | ||
} | ||
// tslint:disable-next-line no-any | ||
sendMessage(message) { | ||
this.sendMessageWithContext({}, message); | ||
} | ||
startRead() { | ||
@@ -175,32 +214,25 @@ this.nextCall.startRead(); | ||
this.requester.halfClose(() => { | ||
this.nextCall.halfClose(); | ||
if (this.processingMessage) { | ||
this.pendingHalfClose = true; | ||
} | ||
else { | ||
this.nextCall.halfClose(); | ||
} | ||
}); | ||
} | ||
getDeadline() { | ||
return this.nextCall.getDeadline(); | ||
} | ||
getCredentials() { | ||
return this.nextCall.getCredentials(); | ||
} | ||
setCredentials(credentials) { | ||
this.nextCall.setCredentials(credentials); | ||
} | ||
getMethod() { | ||
return this.nextCall.getHost(); | ||
} | ||
getHost() { | ||
return this.nextCall.getHost(); | ||
} | ||
} | ||
exports.InterceptingCall = InterceptingCall; | ||
function getCall(channel, path, options) { | ||
var deadline; | ||
var host; | ||
var parent; | ||
var propagate_flags; | ||
var credentials; | ||
let deadline; | ||
let host; | ||
const parent = null; | ||
let propagateFlags; | ||
let credentials; | ||
if (options) { | ||
deadline = options.deadline; | ||
host = options.host; | ||
propagate_flags = options.propagate_flags; | ||
propagateFlags = options.propagate_flags; | ||
credentials = options.credentials; | ||
@@ -211,3 +243,3 @@ } | ||
} | ||
var call = channel.createCall(path, deadline, host, parent, propagate_flags); | ||
const call = channel.createCall(path, deadline, host, parent, propagateFlags); | ||
if (credentials) { | ||
@@ -218,47 +250,135 @@ call.setCredentials(credentials); | ||
} | ||
/** | ||
* InterceptingCall implementation that directly owns the underlying Call | ||
* object and handles serialization and deseraizliation. | ||
*/ | ||
class BaseInterceptingCall { | ||
// tslint:disable-next-line no-any | ||
constructor(call, methodDefinition) { | ||
this.call = call; | ||
this.methodDefinition = methodDefinition; | ||
} | ||
cancelWithStatus(status, details) { | ||
this.call.cancelWithStatus(status, details); | ||
} | ||
getPeer() { | ||
return this.call.getPeer(); | ||
} | ||
setCredentials(credentials) { | ||
this.call.setCredentials(credentials); | ||
} | ||
// tslint:disable-next-line no-any | ||
sendMessageWithContext(context, message) { | ||
let serialized; | ||
try { | ||
serialized = this.methodDefinition.requestSerialize(message); | ||
this.call.sendMessageWithContext(context, serialized); | ||
} | ||
catch (e) { | ||
this.call.cancelWithStatus(constants_1.Status.INTERNAL, 'Serialization failure'); | ||
} | ||
} | ||
// tslint:disable-next-line no-any | ||
sendMessage(message) { | ||
this.sendMessageWithContext({}, message); | ||
} | ||
start(metadata, interceptingListener) { | ||
let readError = null; | ||
this.call.start(metadata, { | ||
onReceiveMetadata: metadata => { | ||
var _a, _b, _c; | ||
(_c = (_a = interceptingListener) === null || _a === void 0 ? void 0 : (_b = _a).onReceiveMetadata) === null || _c === void 0 ? void 0 : _c.call(_b, metadata); | ||
}, | ||
onReceiveMessage: message => { | ||
var _a, _b, _c; | ||
// tslint:disable-next-line no-any | ||
let deserialized; | ||
try { | ||
deserialized = this.methodDefinition.responseDeserialize(message); | ||
(_c = (_a = interceptingListener) === null || _a === void 0 ? void 0 : (_b = _a).onReceiveMessage) === null || _c === void 0 ? void 0 : _c.call(_b, deserialized); | ||
} | ||
catch (e) { | ||
readError = { | ||
code: constants_1.Status.INTERNAL, | ||
details: 'Failed to parse server response', | ||
metadata: new metadata_1.Metadata(), | ||
}; | ||
this.call.cancelWithStatus(readError.code, readError.details); | ||
} | ||
}, | ||
onReceiveStatus: status => { | ||
var _a, _b, _c, _d, _e, _f; | ||
if (readError) { | ||
(_c = (_a = interceptingListener) === null || _a === void 0 ? void 0 : (_b = _a).onReceiveStatus) === null || _c === void 0 ? void 0 : _c.call(_b, readError); | ||
} | ||
else { | ||
(_f = (_d = interceptingListener) === null || _d === void 0 ? void 0 : (_e = _d).onReceiveStatus) === null || _f === void 0 ? void 0 : _f.call(_e, status); | ||
} | ||
}, | ||
}); | ||
} | ||
startRead() { | ||
this.call.startRead(); | ||
} | ||
halfClose() { | ||
this.call.halfClose(); | ||
} | ||
} | ||
/** | ||
* BaseInterceptingCall with special-cased behavior for methods with unary | ||
* responses. | ||
*/ | ||
class BaseUnaryInterceptingCall extends BaseInterceptingCall { | ||
// tslint:disable-next-line no-any | ||
constructor(call, methodDefinition) { | ||
super(call, methodDefinition); | ||
} | ||
start(metadata, listener) { | ||
var _a, _b, _c; | ||
let receivedMessage = false; | ||
const wrapperListener = { | ||
onReceiveMetadata: (_c = (_b = (_a = listener) === null || _a === void 0 ? void 0 : _a.onReceiveMetadata) === null || _b === void 0 ? void 0 : _b.bind(listener), (_c !== null && _c !== void 0 ? _c : (metadata => { }))), | ||
// tslint:disable-next-line no-any | ||
onReceiveMessage: (message) => { | ||
var _a, _b, _c; | ||
receivedMessage = true; | ||
(_c = (_a = listener) === null || _a === void 0 ? void 0 : (_b = _a).onReceiveMessage) === null || _c === void 0 ? void 0 : _c.call(_b, message); | ||
}, | ||
onReceiveStatus: (status) => { | ||
var _a, _b, _c, _d, _e, _f; | ||
if (!receivedMessage) { | ||
(_c = (_a = listener) === null || _a === void 0 ? void 0 : (_b = _a).onReceiveMessage) === null || _c === void 0 ? void 0 : _c.call(_b, null); | ||
} | ||
(_f = (_d = listener) === null || _d === void 0 ? void 0 : (_e = _d).onReceiveStatus) === null || _f === void 0 ? void 0 : _f.call(_e, status); | ||
}, | ||
}; | ||
super.start(metadata, wrapperListener); | ||
this.call.startRead(); | ||
} | ||
} | ||
/** | ||
* BaseInterceptingCall with special-cased behavior for methods with streaming | ||
* responses. | ||
*/ | ||
class BaseStreamingInterceptingCall extends BaseInterceptingCall { | ||
} | ||
// tslint:disable-next-line no-any | ||
function getBottomInterceptingCall(channel, path, options, methodDefinition) { | ||
const call = getCall(channel, path, options); | ||
return new InterceptingCall(call, { | ||
start: (metadata, listener, next) => { | ||
let readError = null; | ||
next(metadata, { | ||
onReceiveMessage: (message, next) => { | ||
let deserialized; | ||
try { | ||
deserialized = methodDefinition.responseDeserialize(message); | ||
next(deserialized); | ||
} | ||
catch (e) { | ||
readError = { code: constants_1.Status.INTERNAL, details: 'Failed to parse server response', metadata: new metadata_1.Metadata() }; | ||
call.cancelWithStatus(readError.code, readError.details); | ||
} | ||
}, | ||
onReceiveStatus: (status, next) => { | ||
if (status.code === constants_1.Status.OK && readError !== null) { | ||
next(readError); | ||
} | ||
else { | ||
next(status); | ||
} | ||
} | ||
}); | ||
}, | ||
sendMessage: (message, next) => { | ||
let serialized; | ||
try { | ||
serialized = methodDefinition.requestSerialize(message); | ||
next(serialized); | ||
} | ||
catch (e) { | ||
call.cancelWithStatus(constants_1.Status.INTERNAL, 'Serialization failure'); | ||
} | ||
} | ||
}); | ||
if (methodDefinition.responseStream) { | ||
return new BaseStreamingInterceptingCall(call, methodDefinition); | ||
} | ||
else { | ||
return new BaseUnaryInterceptingCall(call, methodDefinition); | ||
} | ||
} | ||
// tslint:disable-next-line no-any | ||
function getInterceptingCall(interceptorArgs, methodDefinition, options, channel) { | ||
if (interceptorArgs.clientInterceptors.length > 0 && interceptorArgs.clientInterceptorProviders.length > 0) { | ||
if (interceptorArgs.clientInterceptors.length > 0 && | ||
interceptorArgs.clientInterceptorProviders.length > 0) { | ||
throw new InterceptorConfigurationError('Both interceptors and interceptor_providers were passed as options ' + | ||
'to the client constructor. Only one of these is allowed.'); | ||
} | ||
if (interceptorArgs.callInterceptors.length > 0 && interceptorArgs.callInterceptorProviders.length > 0) { | ||
if (interceptorArgs.callInterceptors.length > 0 && | ||
interceptorArgs.callInterceptorProviders.length > 0) { | ||
throw new InterceptorConfigurationError('Both interceptors and interceptor_providers were passed as call ' + | ||
@@ -269,11 +389,18 @@ 'options. Only one of these is allowed.'); | ||
// Interceptors passed to the call override interceptors passed to the client constructor | ||
if (interceptorArgs.callInterceptors.length > 0 || interceptorArgs.callInterceptorProviders.length > 0) { | ||
interceptors = [].concat(interceptorArgs.callInterceptors, interceptorArgs.callInterceptorProviders.map(provider => provider(methodDefinition))).filter(interceptor => interceptor); | ||
if (interceptorArgs.callInterceptors.length > 0 || | ||
interceptorArgs.callInterceptorProviders.length > 0) { | ||
interceptors = [] | ||
.concat(interceptorArgs.callInterceptors, interceptorArgs.callInterceptorProviders.map(provider => provider(methodDefinition))) | ||
.filter(interceptor => interceptor); | ||
// Filter out falsy values when providers return nothing | ||
} | ||
else { | ||
interceptors = [].concat(interceptorArgs.clientInterceptors, interceptorArgs.clientInterceptorProviders.map(provider => provider(methodDefinition))).filter(interceptor => interceptor); | ||
interceptors = [] | ||
.concat(interceptorArgs.clientInterceptors, interceptorArgs.clientInterceptorProviders.map(provider => provider(methodDefinition))) | ||
.filter(interceptor => interceptor); | ||
// Filter out falsy values when providers return nothing | ||
} | ||
const interceptorOptions = Object.assign({}, options, { method_definition: methodDefinition }); | ||
const interceptorOptions = Object.assign({}, options, { | ||
method_definition: methodDefinition, | ||
}); | ||
/* For each interceptor in the list, the nextCall function passed to it is | ||
@@ -283,6 +410,7 @@ * based on the next interceptor in the list, using a nextCall function | ||
* initialValue, which is effectively at the end of the list, is a nextCall | ||
* function that invokes getBottomInterceptingCall, which handles | ||
* (de)serialization and also gets the underlying call from the channel */ | ||
const getCall = interceptors.reduceRight((previousValue, currentValue) => { | ||
return currentOptions => currentValue(currentOptions, previousValue); | ||
* function that invokes getBottomInterceptingCall, the result of which | ||
* handles (de)serialization and also gets the underlying call from the | ||
* channel. */ | ||
const getCall = interceptors.reduceRight((nextCall, nextInterceptor) => { | ||
return currentOptions => nextInterceptor(currentOptions, nextCall); | ||
}, (finalOptions) => getBottomInterceptingCall(channel, methodDefinition.path, finalOptions, methodDefinition)); | ||
@@ -289,0 +417,0 @@ return getCall(interceptorOptions); |
@@ -38,6 +38,6 @@ /// <reference types="node" /> | ||
export declare const closeClient: (client: Client) => void; | ||
export declare const waitForClientReady: (client: Client, deadline: number | Date, callback: (error?: Error | undefined) => void) => void; | ||
export declare const waitForClientReady: (client: Client, deadline: Deadline, callback: (error?: Error | undefined) => void) => void; | ||
export { ChannelCredentials, CallCredentials, Deadline, Serialize as serialize, Deserialize as deserialize, ClientUnaryCall, ClientReadableStream, ClientWritableStream, ClientDuplexStream, CallOptions, StatusObject, ServiceError, ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream, ServiceDefinition, UntypedHandleCall, UntypedServiceImplementation, }; | ||
/**** Server ****/ | ||
export { handleBidiStreamingCall, handleServerStreamingCall, handleUnaryCall, }; | ||
export { handleBidiStreamingCall, handleServerStreamingCall, handleUnaryCall }; | ||
export declare type Call = ClientUnaryCall | ClientReadableStream<any> | ClientWritableStream<any> | ClientDuplexStream<any, any>; | ||
@@ -44,0 +44,0 @@ export declare type MetadataListener = (metadata: Metadata, next: Function) => void; |
@@ -91,3 +91,3 @@ "use strict"; | ||
[channel_1.ConnectivityState.SHUTDOWN]: 0, | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0 | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0, | ||
}; | ||
@@ -110,3 +110,5 @@ this.subchannelStateListener = (subchannel, previousState, newState) => { | ||
else { | ||
if (this.triedAllSubchannels && this.subchannelStateCounts[channel_1.ConnectivityState.IDLE] === this.subchannels.length) { | ||
if (this.triedAllSubchannels && | ||
this.subchannelStateCounts[channel_1.ConnectivityState.IDLE] === | ||
this.subchannels.length) { | ||
/* If all of the subchannels are IDLE we should go back to a | ||
@@ -123,3 +125,4 @@ * basic IDLE state where there is no subchannel list to avoid | ||
} | ||
else if (this.subchannelStateCounts[channel_1.ConnectivityState.TRANSIENT_FAILURE] > 0) { | ||
else if (this.subchannelStateCounts[channel_1.ConnectivityState.TRANSIENT_FAILURE] > | ||
0) { | ||
newLBState = channel_1.ConnectivityState.TRANSIENT_FAILURE; | ||
@@ -156,3 +159,4 @@ } | ||
} | ||
else if (this.subchannelStateCounts[channel_1.ConnectivityState.TRANSIENT_FAILURE] > 0) { | ||
else if (this.subchannelStateCounts[channel_1.ConnectivityState.TRANSIENT_FAILURE] > | ||
0) { | ||
newLBState = channel_1.ConnectivityState.TRANSIENT_FAILURE; | ||
@@ -211,3 +215,4 @@ } | ||
channel_1.ConnectivityState.IDLE) { | ||
trace('Start connecting to subchannel with address ' + this.subchannels[subchannelIndex].getAddress()); | ||
trace('Start connecting to subchannel with address ' + | ||
this.subchannels[subchannelIndex].getAddress()); | ||
process.nextTick(() => { | ||
@@ -235,3 +240,5 @@ this.subchannels[subchannelIndex].startConnecting(); | ||
updateState(newState, picker) { | ||
trace(channel_1.ConnectivityState[this.currentState] + ' -> ' + channel_1.ConnectivityState[newState]); | ||
trace(channel_1.ConnectivityState[this.currentState] + | ||
' -> ' + | ||
channel_1.ConnectivityState[newState]); | ||
this.currentState = newState; | ||
@@ -251,3 +258,3 @@ this.channelControlHelper.updateState(newState, picker); | ||
[channel_1.ConnectivityState.SHUTDOWN]: 0, | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0 | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0, | ||
}; | ||
@@ -297,3 +304,4 @@ this.subchannels = []; | ||
* address list is different from the existing one */ | ||
if (this.subchannels.length === 0 || !this.latestAddressList.every((value, index) => addressList[index] === value)) { | ||
if (this.subchannels.length === 0 || | ||
!this.latestAddressList.every((value, index) => addressList[index] === value)) { | ||
this.latestAddressList = addressList; | ||
@@ -312,3 +320,4 @@ this.connectToAddressList(); | ||
} | ||
if (this.currentState === channel_1.ConnectivityState.IDLE || this.triedAllSubchannels) { | ||
if (this.currentState === channel_1.ConnectivityState.IDLE || | ||
this.triedAllSubchannels) { | ||
this.channelControlHelper.requestReresolution(); | ||
@@ -315,0 +324,0 @@ } |
@@ -34,3 +34,3 @@ "use strict"; | ||
subchannel: pickedSubchannel, | ||
status: null | ||
status: null, | ||
}; | ||
@@ -59,3 +59,3 @@ } | ||
[channel_1.ConnectivityState.SHUTDOWN]: 0, | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0 | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0, | ||
}; | ||
@@ -69,3 +69,4 @@ this.subchannelStateListener = (subchannel, previousState, newState) => { | ||
} | ||
if (newState === channel_1.ConnectivityState.TRANSIENT_FAILURE || newState === channel_1.ConnectivityState.IDLE) { | ||
if (newState === channel_1.ConnectivityState.TRANSIENT_FAILURE || | ||
newState === channel_1.ConnectivityState.IDLE) { | ||
subchannel.startConnecting(); | ||
@@ -117,3 +118,3 @@ } | ||
[channel_1.ConnectivityState.SHUTDOWN]: 0, | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0 | ||
[channel_1.ConnectivityState.TRANSIENT_FAILURE]: 0, | ||
}; | ||
@@ -128,3 +129,4 @@ this.subchannels = []; | ||
this.subchannelStateCounts[subchannelState] += 1; | ||
if (subchannelState === channel_1.ConnectivityState.IDLE || subchannelState === channel_1.ConnectivityState.TRANSIENT_FAILURE) { | ||
if (subchannelState === channel_1.ConnectivityState.IDLE || | ||
subchannelState === channel_1.ConnectivityState.TRANSIENT_FAILURE) { | ||
subchannel.startConnecting(); | ||
@@ -131,0 +133,0 @@ } |
@@ -52,7 +52,9 @@ "use strict"; | ||
}; | ||
const enabledTracers = process.env.GRPC_TRACE ? process.env.GRPC_TRACE.split(',') : []; | ||
const enabledTracers = process.env.GRPC_TRACE | ||
? process.env.GRPC_TRACE.split(',') | ||
: []; | ||
const allEnabled = enabledTracers.includes('all'); | ||
function trace(severity, tracer, text) { | ||
if (allEnabled || enabledTracers.includes(tracer)) { | ||
exports.log(severity, (new Date().toISOString() + ' | ' + tracer + ' | ' + text)); | ||
exports.log(severity, new Date().toISOString() + ' | ' + tracer + ' | ' + text); | ||
} | ||
@@ -59,0 +61,0 @@ } |
@@ -19,2 +19,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logging_1 = require("./logging"); | ||
const constants_1 = require("./constants"); | ||
const LEGAL_KEY_REGEX = /^[0-9a-z_.-]+$/; | ||
@@ -232,4 +234,4 @@ const LEGAL_NON_BINARY_VALUE_REGEX = /^[ -~]*$/; | ||
catch (error) { | ||
error.message = `Failed to add metadata entry ${key}: ${values}. ${error.message}`; | ||
process.emitWarning(error); | ||
const message = `Failed to add metadata entry ${key}: ${values}. ${error.message}. For more information see https://github.com/grpc/grpc-node/issues/1173`; | ||
logging_1.log(constants_1.LogVerbosity.ERROR, message); | ||
} | ||
@@ -236,0 +238,0 @@ }); |
@@ -116,3 +116,4 @@ "use strict"; | ||
const result = []; | ||
for (let i = 0; i < Math.max.apply(null, arrays.map(array => array.length)); i++) { | ||
for (let i = 0; i < | ||
Math.max.apply(null, arrays.map(array => array.length)); i++) { | ||
for (const array of arrays) { | ||
@@ -226,3 +227,6 @@ if (i < array.length) { | ||
}, err => { | ||
trace('Resolution error for target ' + this.target + ': ' + err.message); | ||
trace('Resolution error for target ' + | ||
this.target + | ||
': ' + | ||
err.message); | ||
this.pendingResultPromise = null; | ||
@@ -229,0 +233,0 @@ this.listener.onError(this.defaultResolutionError); |
@@ -67,3 +67,3 @@ "use strict"; | ||
function getDefaultAuthority(target) { | ||
for (const prefix of Object.keys(registerDefaultResolver)) { | ||
for (const prefix of Object.keys(registeredResolvers)) { | ||
if (target.startsWith(prefix)) { | ||
@@ -70,0 +70,0 @@ return registeredResolvers[prefix].getDefaultAuthority(target); |
@@ -279,3 +279,4 @@ "use strict"; | ||
this.innerResolver.updateResolution(); | ||
if (this.innerLoadBalancer === null || this.innerBalancerState === channel_1.ConnectivityState.IDLE) { | ||
if (this.innerLoadBalancer === null || | ||
this.innerBalancerState === channel_1.ConnectivityState.IDLE) { | ||
this.updateState(channel_1.ConnectivityState.CONNECTING, new picker_1.QueuePicker(this)); | ||
@@ -285,3 +286,7 @@ } | ||
updateState(connectivitystate, picker) { | ||
trace(this.target + ' ' + channel_1.ConnectivityState[this.currentState] + ' -> ' + channel_1.ConnectivityState[connectivitystate]); | ||
trace(this.target + | ||
' ' + | ||
channel_1.ConnectivityState[this.currentState] + | ||
' -> ' + | ||
channel_1.ConnectivityState[connectivitystate]); | ||
this.currentState = connectivitystate; | ||
@@ -305,3 +310,4 @@ this.channelControlHelper.updateState(connectivitystate, picker); | ||
handleResolutionFailure(error) { | ||
if (this.innerLoadBalancer === null || this.innerBalancerState === channel_1.ConnectivityState.IDLE) { | ||
if (this.innerLoadBalancer === null || | ||
this.innerBalancerState === channel_1.ConnectivityState.IDLE) { | ||
this.updateState(channel_1.ConnectivityState.TRANSIENT_FAILURE, new picker_1.UnavailablePicker(error)); | ||
@@ -308,0 +314,0 @@ } |
@@ -56,4 +56,3 @@ "use strict"; | ||
const subchannelObjArray = this.pool[channelTarget][subchannelTarget]; | ||
const refedSubchannels = subchannelObjArray | ||
.filter(value => !value.subchannel.unrefIfOneRef()); | ||
const refedSubchannels = subchannelObjArray.filter(value => !value.subchannel.unrefIfOneRef()); | ||
if (refedSubchannels.length > 0) { | ||
@@ -60,0 +59,0 @@ allSubchannelsUnrefed = false; |
@@ -39,3 +39,3 @@ "use strict"; | ||
* to calculate it */ | ||
const KEEPALIVE_TIME_MS = ~(1 << 31); | ||
const KEEPALIVE_MAX_TIME_MS = ~(1 << 31); | ||
const KEEPALIVE_TIMEOUT_MS = 20000; | ||
@@ -97,3 +97,3 @@ const { HTTP2_HEADER_AUTHORITY, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_METHOD, HTTP2_HEADER_PATH, HTTP2_HEADER_TE, HTTP2_HEADER_USER_AGENT, } = http2.constants; | ||
*/ | ||
this.keepaliveTimeMs = KEEPALIVE_TIME_MS; | ||
this.keepaliveTimeMs = KEEPALIVE_MAX_TIME_MS; | ||
/** | ||
@@ -210,5 +210,6 @@ * The amount of time to wait for an acknowledgement after sending a ping | ||
* https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md#basic-keepalive */ | ||
if (errorCode === http2.constants.NGHTTP2_ENHANCE_YOUR_CALM && opaqueData.equals(tooManyPingsData)) { | ||
if (errorCode === http2.constants.NGHTTP2_ENHANCE_YOUR_CALM && | ||
opaqueData.equals(tooManyPingsData)) { | ||
logging.log(constants_1.LogVerbosity.ERROR, `Connection to ${this.channelTarget} rejected by server because of excess pings`); | ||
this.keepaliveTimeMs *= 2; | ||
this.keepaliveTimeMs = Math.min(2 * this.keepaliveTimeMs, KEEPALIVE_MAX_TIME_MS); | ||
} | ||
@@ -234,3 +235,7 @@ this.transitionToState([channel_1.ConnectivityState.CONNECTING, channel_1.ConnectivityState.READY], channel_1.ConnectivityState.IDLE); | ||
} | ||
trace(this.subchannelAddress + ' ' + channel_1.ConnectivityState[this.connectivityState] + ' -> ' + channel_1.ConnectivityState[newState]); | ||
trace(this.subchannelAddress + | ||
' ' + | ||
channel_1.ConnectivityState[this.connectivityState] + | ||
' -> ' + | ||
channel_1.ConnectivityState[newState]); | ||
const previousState = this.connectivityState; | ||
@@ -237,0 +242,0 @@ this.connectivityState = newState; |
{ | ||
"name": "@grpc/grpc-js", | ||
"version": "0.6.11", | ||
"version": "0.6.12", | ||
"description": "gRPC Library for Node - pure JS implementation", | ||
@@ -61,5 +61,6 @@ "homepage": "https://grpc.io/", | ||
"files": [ | ||
"build/src/*.{js,d.ts}", | ||
"src/*.ts", | ||
"build/src/*.{js,d.ts,js.map}", | ||
"LICENSE" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
729841
158
15430