rhea-promise
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -125,3 +125,3 @@ "use strict"; | ||
if (abortSignal && abortSignal.aborted) { | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] %s", this.connection.id, err.message); | ||
@@ -146,3 +146,3 @@ return reject(err); | ||
" map of sender '%s' on amqp session '%s' and cleared the timer: %s.", this.connection.id, delivery.id, this.name, this.session.id, deleteResult); | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] %s", this.connection.id, err.message); | ||
@@ -149,0 +149,0 @@ promise.reject(err); |
@@ -19,2 +19,3 @@ "use strict"; | ||
} | ||
const maxListenerLimit = 1000; | ||
/** | ||
@@ -45,6 +46,6 @@ * Describes the AMQP Connection. | ||
if (connectionOptions.webSocketOptions) { | ||
const ws = rhea_1.websocket_connect(connectionOptions.webSocketOptions.webSocket); | ||
const ws = (0, rhea_1.websocket_connect)(connectionOptions.webSocketOptions.webSocket); | ||
connectionOptions.connection_details = ws(connectionOptions.webSocketOptions.url, connectionOptions.webSocketOptions.protocol, connectionOptions.webSocketOptions.options); | ||
} | ||
this._connection = rhea_1.create_connection(connectionOptions); | ||
this._connection = (0, rhea_1.create_connection)(connectionOptions); | ||
this.container = container_1.Container.copyFromContainerInstance(this._connection.container); | ||
@@ -56,2 +57,5 @@ options = connectionOptions; | ||
this._initializeEventListeners(); | ||
// Set max listeners on the connection to 1000 because Session and Link add their own listeners | ||
// and the default value of 10 in NodeJS is too low. | ||
this._connection.setMaxListeners(maxListenerLimit); | ||
} | ||
@@ -119,7 +123,3 @@ /** | ||
if (!this.isOpen()) { | ||
let onOpen; | ||
let onClose; | ||
let onAbort; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer; | ||
const removeListeners = () => { | ||
@@ -135,3 +135,3 @@ clearTimeout(waitTimer); | ||
}; | ||
onOpen = (context) => { | ||
const onOpen = (context) => { | ||
removeListeners(); | ||
@@ -141,3 +141,3 @@ log.connection("[%s] Resolving the promise with amqp connection.", this.id); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -148,6 +148,6 @@ const err = context.error || context.connection.error || Error('Failed to connect'); | ||
}; | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
this._connection.close(); | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.id, err.message); | ||
@@ -166,3 +166,3 @@ return reject(err); | ||
this._connection.once(rhea_1.ConnectionEvents.disconnected, onClose); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
log.connection("[%s] Trying to create a new amqp connection.", this.id); | ||
@@ -200,8 +200,3 @@ this._connection.connect(); | ||
if (this.isOpen()) { | ||
let onClose; | ||
let onError; | ||
let onDisconnected; | ||
let onAbort; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer; | ||
const removeListeners = () => { | ||
@@ -217,3 +212,3 @@ clearTimeout(waitTimer); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -223,3 +218,3 @@ log.connection("[%s] Resolving the promise as the connection has been successfully closed.", this.id); | ||
}; | ||
onError = (context) => { | ||
const onError = (context) => { | ||
removeListeners(); | ||
@@ -229,3 +224,3 @@ log.error("[%s] Error occurred while closing amqp connection: %O.", this.id, context.connection.error); | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -237,5 +232,5 @@ const error = context.connection && context.connection.error | ||
}; | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.id, err.message); | ||
@@ -254,3 +249,3 @@ return reject(err); | ||
this._connection.once(rhea_1.ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
this._connection.close(); | ||
@@ -343,3 +338,3 @@ this.actionInitiated++; | ||
const rejectOnAbort = () => { | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.id, err.message); | ||
@@ -379,6 +374,2 @@ return reject(err); | ||
session.actionInitiated++; | ||
let onOpen; | ||
let onClose; | ||
let onDisconnected; | ||
let waitTimer; | ||
const removeListeners = () => { | ||
@@ -394,3 +385,3 @@ clearTimeout(waitTimer); | ||
}; | ||
onOpen = (context) => { | ||
const onOpen = (context) => { | ||
removeListeners(); | ||
@@ -400,3 +391,3 @@ log.session("[%s] Resolving the promise with amqp session '%s'.", this.id, session.id); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -406,3 +397,3 @@ log.error("[%s] Error occurred while establishing a session over amqp connection: %O.", this.id, context.session.error); | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -426,3 +417,3 @@ const error = context.connection && context.connection.error | ||
log.session("[%s] Calling amqp session.begin().", this.id); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options.operationTimeoutInSeconds * 1000); | ||
rheaSession.begin(); | ||
@@ -537,3 +528,3 @@ }); | ||
} | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -552,3 +543,3 @@ } | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -563,3 +554,3 @@ this._connection.on(rhea_1.SenderEvents.senderClose, (context) => { | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -575,3 +566,3 @@ // Receiver | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -586,3 +577,3 @@ this._connection.on(rhea_1.ReceiverEvents.receiverClose, (context) => { | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -598,3 +589,3 @@ // Session | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -609,3 +600,3 @@ this._connection.on(rhea_1.SessionEvents.sessionClose, (context) => { | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -612,0 +603,0 @@ if (typeof this._connection.eventNames === "function") { |
@@ -25,3 +25,3 @@ "use strict"; | ||
else { | ||
this._container = rhea_1.create_container(options); | ||
this._container = (0, rhea_1.create_container)(options); | ||
} | ||
@@ -28,0 +28,0 @@ this.options = this._container.options; |
@@ -6,6 +6,9 @@ "use strict"; | ||
exports.EventContext = void 0; | ||
const connection_1 = require("./connection"); | ||
const session_1 = require("./session"); | ||
const link_1 = require("./link"); | ||
const log = require("./log"); | ||
function hasConnection(val) { | ||
return val && val.connection; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
var EventContext; | ||
@@ -22,5 +25,5 @@ (function (EventContext) { | ||
function translate(rheaContext, emitter, eventName) { | ||
const connection = emitter instanceof connection_1.Connection | ||
? emitter | ||
: emitter.connection; | ||
const connection = hasConnection(emitter) | ||
? emitter.connection | ||
: emitter; | ||
log.contextTranslator("[%s] Translating the context for event: '%s'.", connection.id, eventName); | ||
@@ -27,0 +30,0 @@ // initialize the result |
@@ -200,6 +200,2 @@ "use strict"; | ||
: rhea_1.ReceiverEvents.receiverClose; | ||
let onError; | ||
let onClose; | ||
let onDisconnected; | ||
let waitTimer; | ||
const removeListeners = () => { | ||
@@ -212,3 +208,3 @@ clearTimeout(waitTimer); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -219,3 +215,3 @@ log[this.type]("[%s] Resolving the promise as the %s '%s' on amqp session '%s' " + | ||
}; | ||
onError = (context) => { | ||
const onError = (context) => { | ||
removeListeners(); | ||
@@ -232,3 +228,3 @@ let error = context.session.error; | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -252,3 +248,3 @@ const error = context.connection && context.connection.error | ||
this._link.connection.once(rhea_1.ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
this._link.close(); | ||
@@ -290,3 +286,3 @@ this.actionInitiated++; | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -293,0 +289,0 @@ } |
@@ -132,8 +132,8 @@ "use strict"; | ||
if (this.isOpen()) { | ||
let onError; | ||
let onClose; | ||
let onDisconnected; | ||
let onAbort; | ||
// let onError: Func<RheaEventContext, void>; | ||
// let onClose: Func<RheaEventContext, void>; | ||
// let onDisconnected: Func<RheaEventContext, void>; | ||
// let onAbort: Func<void, void>; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer; | ||
// let waitTimer: any; | ||
const removeListeners = () => { | ||
@@ -149,3 +149,3 @@ clearTimeout(waitTimer); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -155,3 +155,3 @@ log.session("[%s] Resolving the promise as the amqp session '%s' has been closed.", this.connection.id, this.id); | ||
}; | ||
onError = (context) => { | ||
const onError = (context) => { | ||
removeListeners(); | ||
@@ -161,3 +161,3 @@ log.error("[%s] Error occurred while closing amqp session '%s'.", this.connection.id, this.id, context.session.error); | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -169,5 +169,5 @@ const error = context.connection && context.connection.error | ||
}; | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.connection.id, err.message); | ||
@@ -187,3 +187,3 @@ return reject(err); | ||
log.session("[%s] Calling session.close() for amqp session '%s'.", this.connection.id, this.id); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
this._session.close(); | ||
@@ -245,3 +245,3 @@ this.actionInitiated++; | ||
const rejectOnAbort = () => { | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.connection.id, err.message); | ||
@@ -294,6 +294,2 @@ return reject(err); | ||
receiver.actionInitiated++; | ||
let onOpen; | ||
let onClose; | ||
let onDisconnected; | ||
let waitTimer; | ||
if (options && options.onMessage) { | ||
@@ -325,3 +321,3 @@ receiver.on(rhea_1.ReceiverEvents.message, options.onMessage); | ||
}; | ||
onOpen = (context) => { | ||
const onOpen = (context) => { | ||
removeListeners(); | ||
@@ -331,3 +327,3 @@ log.receiver("[%s] Resolving the promise with amqp receiver '%s' on amqp session '%s'.", this.connection.id, receiver.name, this.id); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -338,3 +334,3 @@ log.error("[%s] Error occurred while creating the amqp receiver '%s' on amqp session " + | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -359,3 +355,3 @@ const error = context.connection && context.connection.error | ||
rheaReceiver.session.connection.on(rhea_1.ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
}); | ||
@@ -404,3 +400,3 @@ } | ||
const rejectOnAbort = () => { | ||
const err = utils_1.createAbortError(); | ||
const err = (0, utils_1.createAbortError)(); | ||
log.error("[%s] [%s]", this.connection.id, err.message); | ||
@@ -457,6 +453,6 @@ return reject(err); | ||
sender.actionInitiated++; | ||
let onSendable; | ||
let onClose; | ||
let onDisconnected; | ||
let waitTimer; | ||
// let onSendable: Func<RheaEventContext, void>; | ||
// let onClose: Func<RheaEventContext, void>; | ||
// let onDisconnected: Func<RheaEventContext, void>; | ||
// let waitTimer: any; | ||
// listeners provided by the user in the options object should be added | ||
@@ -496,3 +492,3 @@ // to our (rhea-promise) object. | ||
}; | ||
onSendable = (context) => { | ||
const onSendable = (context) => { | ||
removeListeners(); | ||
@@ -502,3 +498,3 @@ log.sender("[%s] Resolving the promise with amqp sender '%s' on amqp session '%s'.", this.connection.id, sender.name, this.id); | ||
}; | ||
onClose = (context) => { | ||
const onClose = (context) => { | ||
removeListeners(); | ||
@@ -509,3 +505,3 @@ log.error("[%s] Error occurred while creating the amqp sender '%s' on amqp session '%s' " + | ||
}; | ||
onDisconnected = (context) => { | ||
const onDisconnected = (context) => { | ||
removeListeners(); | ||
@@ -530,3 +526,3 @@ const error = context.connection && context.connection.error | ||
rheaSender.session.connection.on(rhea_1.ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options.operationTimeoutInSeconds * 1000); | ||
}); | ||
@@ -550,3 +546,3 @@ } | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -565,3 +561,3 @@ } | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -576,3 +572,3 @@ this._session.on(rhea_1.SenderEvents.senderClose, (context) => { | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -588,3 +584,3 @@ // Receiver | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -599,3 +595,3 @@ this._session.on(rhea_1.ReceiverEvents.receiverClose, (context) => { | ||
}; | ||
utils_1.emitEvent(params); | ||
(0, utils_1.emitEvent)(params); | ||
}); | ||
@@ -602,0 +598,0 @@ if (typeof this._session.eventNames === "function") { |
@@ -36,4 +36,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
export interface AwaitableSenderOptions extends BaseSenderOptions { | ||
} | ||
export type AwaitableSenderOptions = BaseSenderOptions | ||
@@ -228,3 +227,5 @@ export interface AwaitableSendOptions { | ||
const removeAbortListener = () => { | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
@@ -245,3 +246,5 @@ | ||
if (abortSignal) { abortSignal.addEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.addEventListener("abort", onAbort); | ||
} | ||
} else { | ||
@@ -248,0 +251,0 @@ // Please send the message after some time. |
@@ -34,3 +34,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
abortSignal?: AbortSignalLike; | ||
abortSignal?: AbortSignalLike; | ||
} | ||
@@ -59,3 +59,3 @@ | ||
*/ | ||
abortSignal?: AbortSignalLike; | ||
abortSignal?: AbortSignalLike; | ||
} | ||
@@ -72,3 +72,3 @@ | ||
*/ | ||
abortSignal?: AbortSignalLike; | ||
abortSignal?: AbortSignalLike; | ||
} | ||
@@ -140,8 +140,8 @@ | ||
*/ | ||
protocol: string[], | ||
/*** | ||
protocol: string[]; | ||
/** * | ||
* @property {any} {options} - Options to be passed to the function returned by | ||
* rhea.websocket_connect() | ||
*/ | ||
options?: any | ||
options?: any; | ||
}; | ||
@@ -209,2 +209,4 @@ }; | ||
const maxListenerLimit = 1000; | ||
/** | ||
@@ -264,2 +266,6 @@ * Describes the AMQP Connection. | ||
this._initializeEventListeners(); | ||
// Set max listeners on the connection to 1000 because Session and Link add their own listeners | ||
// and the default value of 10 in NodeJS is too low. | ||
this._connection.setMaxListeners(maxListenerLimit); | ||
} | ||
@@ -336,9 +342,5 @@ | ||
let onOpen: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onAbort: Func<void, void>; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer: any; | ||
const removeListeners: Function = () => { | ||
const removeListeners = () => { | ||
clearTimeout(waitTimer); | ||
@@ -349,6 +351,8 @@ this.actionInitiated--; | ||
this._connection.removeListener(ConnectionEvents.disconnected, onClose); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onOpen = (context: RheaEventContext) => { | ||
const onOpen = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -359,3 +363,3 @@ log.connection("[%s] Resolving the promise with amqp connection.", this.id); | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -368,3 +372,3 @@ const err = context.error || context.connection.error || Error('Failed to connect'); | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
@@ -379,3 +383,3 @@ this._connection.close(); | ||
removeListeners(); | ||
const msg: string = `Unable to open the amqp connection "${this.id}" due to operation timeout.`; | ||
const msg = `Unable to open the amqp connection "${this.id}" due to operation timeout.`; | ||
log.error("[%s] %s", this.id, msg); | ||
@@ -389,3 +393,3 @@ return reject(new Error(msg)); | ||
this._connection.once(ConnectionEvents.disconnected, onClose); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
log.connection("[%s] Trying to create a new amqp connection.", this.id); | ||
@@ -424,8 +428,3 @@ this._connection.connect(); | ||
if (this.isOpen()) { | ||
let onClose: Func<RheaEventContext, void>; | ||
let onError: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let onAbort: Func<void, void>; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer: any; | ||
@@ -438,6 +437,8 @@ const removeListeners = () => { | ||
this._connection.removeListener(ConnectionEvents.disconnected, onDisconnected); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -449,3 +450,3 @@ log.connection("[%s] Resolving the promise as the connection has been successfully closed.", | ||
onError = (context: RheaEventContext) => { | ||
const onError = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -457,3 +458,3 @@ log.error("[%s] Error occurred while closing amqp connection: %O.", | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -466,3 +467,3 @@ const error = context.connection && context.connection.error | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
@@ -476,3 +477,3 @@ const err = createAbortError(); | ||
removeListeners(); | ||
const msg: string = `Unable to close the amqp connection "${this.id}" due to operation timeout.`; | ||
const msg = `Unable to close the amqp connection "${this.id}" due to operation timeout.`; | ||
log.error("[%s] %s", this.id, msg); | ||
@@ -486,3 +487,3 @@ return reject(new Error(msg)); | ||
this._connection.once(ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
this._connection.close(); | ||
@@ -509,3 +510,3 @@ this.actionInitiated++; | ||
isOpen(): boolean { | ||
let result: boolean = false; | ||
let result = false; | ||
if (this._connection && this._connection.is_open && this._connection.is_open()) { | ||
@@ -619,6 +620,2 @@ result = true; | ||
session.actionInitiated++; | ||
let onOpen: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let waitTimer: any; | ||
@@ -631,6 +628,8 @@ const removeListeners = () => { | ||
rheaSession.connection.removeListener(ConnectionEvents.disconnected, onDisconnected); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onOpen = (context: RheaEventContext) => { | ||
const onOpen = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -641,3 +640,3 @@ log.session("[%s] Resolving the promise with amqp session '%s'.", this.id, session.id); | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -649,3 +648,3 @@ log.error("[%s] Error occurred while establishing a session over amqp connection: %O.", | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -662,3 +661,3 @@ const error = context.connection && context.connection.error | ||
removeListeners(); | ||
const msg: string = `Unable to create the amqp session due to operation timeout.`; | ||
const msg = `Unable to create the amqp session due to operation timeout.`; | ||
log.error("[%s] %s", this.id, msg); | ||
@@ -673,3 +672,3 @@ return reject(new OperationTimeoutError(msg)); | ||
log.session("[%s] Calling amqp session.begin().", this.id); | ||
waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.options!.operationTimeoutInSeconds! * 1000); | ||
rheaSession.begin(); | ||
@@ -676,0 +675,0 @@ }); |
@@ -18,3 +18,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
actionInitiated: number = 0; | ||
actionInitiated = 0; | ||
constructor() { | ||
@@ -21,0 +21,0 @@ super(); |
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the Apache License. See License in the project root for license information. | ||
import { Connection } from "./connection"; | ||
import { Container } from "./container"; | ||
import type { Connection } from "./connection"; | ||
import type { Container } from "./container"; | ||
import { Session } from "./session"; | ||
@@ -84,3 +84,8 @@ import { | ||
export module EventContext { | ||
function hasConnection(val: any): val is Link | Session { | ||
return val && val.connection; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
export namespace EventContext { | ||
/** | ||
@@ -98,5 +103,5 @@ * Translates rhea's EventContext into rhea-promise EventContext | ||
eventName: string): EventContext { | ||
const connection: Connection = emitter instanceof Connection | ||
? emitter | ||
: (emitter as Link | Session).connection; | ||
const connection = hasConnection(emitter) | ||
? emitter.connection | ||
: emitter; | ||
@@ -103,0 +108,0 @@ log.contextTranslator("[%s] Translating the context for event: '%s'.", connection.id, eventName); |
@@ -11,3 +11,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
import { Connection } from "./connection"; | ||
import { Func, emitEvent, EmitParameters } from './util/utils'; | ||
import { emitEvent, EmitParameters } from './util/utils'; | ||
import { Entity } from "./entity"; | ||
@@ -247,6 +247,2 @@ import { OperationTimeoutError } from "./errorDefinitions"; | ||
: ReceiverEvents.receiverClose; | ||
let onError: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let waitTimer: any; | ||
@@ -261,3 +257,3 @@ const removeListeners = () => { | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -269,3 +265,3 @@ log[this.type]("[%s] Resolving the promise as the %s '%s' on amqp session '%s' " + | ||
onError = (context: RheaEventContext) => { | ||
const onError = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -284,3 +280,3 @@ let error = context.session!.error; | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -306,3 +302,3 @@ const error = context.connection && context.connection.error | ||
this._link.connection.once(ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, | ||
const waitTimer = setTimeout(actionAfterTimeout, | ||
this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
@@ -309,0 +305,0 @@ this._link.close(); |
@@ -103,7 +103,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
format?: number; | ||
/** | ||
* The message tag if any. | ||
*/ | ||
tag?: Buffer | string; | ||
format?: number; | ||
/** | ||
* The message tag if any. | ||
*/ | ||
tag?: Buffer | string; | ||
} | ||
@@ -110,0 +110,0 @@ |
@@ -81,3 +81,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
get id(): string { | ||
let result: string = ""; | ||
let result = ""; | ||
const session: any = this._session; | ||
@@ -167,8 +167,8 @@ if (session.local) { | ||
if (this.isOpen()) { | ||
let onError: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let onAbort: Func<void, void>; | ||
// let onError: Func<RheaEventContext, void>; | ||
// let onClose: Func<RheaEventContext, void>; | ||
// let onDisconnected: Func<RheaEventContext, void>; | ||
// let onAbort: Func<void, void>; | ||
const abortSignal = options && options.abortSignal; | ||
let waitTimer: any; | ||
// let waitTimer: any; | ||
@@ -181,6 +181,8 @@ const removeListeners = () => { | ||
this._session.connection.removeListener(ConnectionEvents.disconnected, onDisconnected); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -192,3 +194,3 @@ log.session("[%s] Resolving the promise as the amqp session '%s' has been closed.", | ||
onError = (context: RheaEventContext) => { | ||
const onError = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -200,3 +202,3 @@ log.error("[%s] Error occurred while closing amqp session '%s'.", | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -210,3 +212,3 @@ const error = context.connection && context.connection.error | ||
onAbort = () => { | ||
const onAbort = () => { | ||
removeListeners(); | ||
@@ -220,3 +222,3 @@ const err = createAbortError(); | ||
removeListeners(); | ||
const msg: string = `Unable to close the amqp session ${this.id} due to operation timeout.`; | ||
const msg = `Unable to close the amqp session ${this.id} due to operation timeout.`; | ||
log.error("[%s] %s", this.connection.id, msg); | ||
@@ -231,3 +233,3 @@ reject(new OperationTimeoutError(msg)); | ||
log.session("[%s] Calling session.close() for amqp session '%s'.", this.connection.id, this.id); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
this._session.close(); | ||
@@ -265,3 +267,3 @@ this.actionInitiated++; | ||
*/ | ||
createReceiver(options?: ReceiverOptions & { abortSignal?: AbortSignalLike; }): Promise<Receiver> { | ||
createReceiver(options?: ReceiverOptions & { abortSignal?: AbortSignalLike }): Promise<Receiver> { | ||
return new Promise((resolve, reject) => { | ||
@@ -341,6 +343,2 @@ if (options && | ||
receiver.actionInitiated++; | ||
let onOpen: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let waitTimer: any; | ||
@@ -376,6 +374,8 @@ if (options && options.onMessage) { | ||
rheaReceiver.session.connection.removeListener(ConnectionEvents.disconnected, onDisconnected); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onOpen = (context: RheaEventContext) => { | ||
const onOpen = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -387,3 +387,3 @@ log.receiver("[%s] Resolving the promise with amqp receiver '%s' on amqp session '%s'.", | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -396,3 +396,3 @@ log.error("[%s] Error occurred while creating the amqp receiver '%s' on amqp session " + | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -419,3 +419,3 @@ const error = context.connection && context.connection.error | ||
rheaReceiver.session.connection.on(ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
}); | ||
@@ -432,3 +432,3 @@ } | ||
*/ | ||
createSender(options?: SenderOptions & { abortSignal?: AbortSignalLike; }): Promise<Sender> { | ||
createSender(options?: SenderOptions & { abortSignal?: AbortSignalLike }): Promise<Sender> { | ||
return this._createSender(SenderType.sender, options) as Promise<Sender>; | ||
@@ -452,3 +452,3 @@ } | ||
*/ | ||
createAwaitableSender(options?: AwaitableSenderOptions & { abortSignal?: AbortSignalLike; }): Promise<AwaitableSender> { | ||
createAwaitableSender(options?: AwaitableSenderOptions & { abortSignal?: AbortSignalLike }): Promise<AwaitableSender> { | ||
return this._createSender(SenderType.AwaitableSender, options) as Promise<AwaitableSender>; | ||
@@ -465,3 +465,3 @@ } | ||
type: SenderType, | ||
options?: (SenderOptions | AwaitableSenderOptions) & { abortSignal?: AbortSignalLike; }): Promise<Sender | AwaitableSender> { | ||
options?: (SenderOptions | AwaitableSenderOptions) & { abortSignal?: AbortSignalLike }): Promise<Sender | AwaitableSender> { | ||
return new Promise((resolve, reject) => { | ||
@@ -526,6 +526,6 @@ const abortSignal = options && options.abortSignal; | ||
sender.actionInitiated++; | ||
let onSendable: Func<RheaEventContext, void>; | ||
let onClose: Func<RheaEventContext, void>; | ||
let onDisconnected: Func<RheaEventContext, void>; | ||
let waitTimer: any; | ||
// let onSendable: Func<RheaEventContext, void>; | ||
// let onClose: Func<RheaEventContext, void>; | ||
// let onDisconnected: Func<RheaEventContext, void>; | ||
// let waitTimer: any; | ||
@@ -563,6 +563,8 @@ // listeners provided by the user in the options object should be added | ||
rheaSender.session.connection.removeListener(ConnectionEvents.disconnected, onDisconnected); | ||
if (abortSignal) { abortSignal.removeEventListener("abort", onAbort); } | ||
if (abortSignal) { | ||
abortSignal.removeEventListener("abort", onAbort); | ||
} | ||
}; | ||
onSendable = (context: RheaEventContext) => { | ||
const onSendable = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -574,3 +576,3 @@ log.sender("[%s] Resolving the promise with amqp sender '%s' on amqp session '%s'.", | ||
onClose = (context: RheaEventContext) => { | ||
const onClose = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -583,3 +585,3 @@ log.error("[%s] Error occurred while creating the amqp sender '%s' on amqp session '%s' " + | ||
onDisconnected = (context: RheaEventContext) => { | ||
const onDisconnected = (context: RheaEventContext) => { | ||
removeListeners(); | ||
@@ -606,3 +608,3 @@ const error = context.connection && context.connection.error | ||
rheaSender.session.connection.on(ConnectionEvents.disconnected, onDisconnected); | ||
waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
const waitTimer = setTimeout(actionAfterTimeout, this.connection.options!.operationTimeoutInSeconds! * 1000); | ||
}); | ||
@@ -609,0 +611,0 @@ } |
@@ -96,3 +96,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
} | ||
let result: boolean = false; | ||
let result = false; | ||
if (((err.condition && typeof err.condition === "string") && (err.description && typeof err.description === "string")) | ||
@@ -192,3 +192,3 @@ || (err.value && Array.isArray(err.value)) | ||
"this happened before the promise for create/close was resolved.", params.connectionId, | ||
params.emitterType, params.eventName); | ||
params.emitterType, params.eventName); | ||
// setTimeout() without any time is equivalent to process.nextTick() and works in node.js and | ||
@@ -195,0 +195,0 @@ // browsers. We wait for a tick to emit error events in general. This should give enough |
{ | ||
"name": "rhea-promise", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "A Promisified layer over rhea AMQP client", | ||
@@ -9,5 +9,5 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"debug": "^3.1.0", | ||
"debug": "^4.0.0", | ||
"rhea": "^3.0.0", | ||
"tslib": "^2.2.0" | ||
"tslib": "^2.6.0" | ||
}, | ||
@@ -21,22 +21,32 @@ "keywords": [ | ||
], | ||
"files": [ | ||
"dist/lib/", | ||
"lib/", | ||
"typings/lib/", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"devDependencies": { | ||
"@azure/abort-controller": "^1.0.1", | ||
"@types/chai": "^4.2.11", | ||
"@types/debug": "^0.0.31", | ||
"@types/dotenv": "^6.1.1", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^8.0.37", | ||
"chai": "^4.2.0", | ||
"dotenv": "^8.0.0", | ||
"mocha": "^6.2.3", | ||
"rimraf": "^2.6.3", | ||
"ts-node": "^8.2.0", | ||
"tslint": "^5.17.0", | ||
"typescript": "~4.3.0" | ||
"@types/chai": "^4.3.7", | ||
"@types/debug": "^4.0.0", | ||
"@types/mocha": "^10.0.0", | ||
"@types/node": "^16.0.0", | ||
"@typescript-eslint/eslint-plugin": "~7.8.0", | ||
"@typescript-eslint/parser": "~7.8.0", | ||
"chai": "^4.3.10", | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.42.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-jsdoc": "^46.2.6", | ||
"mocha": "^10.0.0", | ||
"rimraf": "^5.0.5", | ||
"ts-node": "^10.0.0", | ||
"typescript": "~5.0.4" | ||
}, | ||
"scripts": { | ||
"tslint": "tslint -p . -c tslint.json --exclude test/**/*.ts", | ||
"lint": "eslint .", | ||
"tsc": "tsc", | ||
"prebuild": "rimraf dist && rimraf typings", | ||
"build": "npm run tslint && npm run tsc", | ||
"build": "npm run lint && npm run tsc", | ||
"test": "npm run build && mocha -r ts-node/register ./test/*.spec.ts", | ||
@@ -43,0 +53,0 @@ "prepack": "npm i && npm run build" |
@@ -182,3 +182,2 @@ # rhea-promise | ||
}, | ||
sendTimeoutInSeconds: 10 | ||
}; | ||
@@ -199,3 +198,5 @@ | ||
// You will notice that `delivery.settled` will be `true`, irrespective of whether the promise resolves or rejects. | ||
const delivery: Delivery = await sender.send(message); | ||
const delivery: Delivery = await sender.send(message, { | ||
timeoutInSeconds: 10 | ||
}); | ||
console.log( | ||
@@ -202,0 +203,0 @@ "[%s] await sendMessage -> Delivery id: %d, settled: %s", |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Delivery, Message, Sender as RheaSender } from "rhea"; | ||
@@ -25,4 +26,3 @@ import { BaseSender, BaseSenderOptions } from "./sender"; | ||
} | ||
export interface AwaitableSenderOptions extends BaseSenderOptions { | ||
} | ||
export type AwaitableSenderOptions = BaseSenderOptions; | ||
export interface AwaitableSendOptions { | ||
@@ -29,0 +29,0 @@ /** |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { PeerCertificate } from "tls"; | ||
@@ -89,3 +90,3 @@ import { Socket } from "net"; | ||
*/ | ||
export declare type ConnectionOptions = RheaConnectionOptions & { | ||
export type ConnectionOptions = RheaConnectionOptions & { | ||
/** | ||
@@ -120,3 +121,3 @@ * @property {number} [operationTimeoutInSeconds] - The duration in which the promise should | ||
protocol: string[]; | ||
/*** | ||
/** * | ||
* @property {any} {options} - Options to be passed to the function returned by | ||
@@ -123,0 +124,0 @@ * rhea.websocket_connect() |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Container as RheaContainer, ContainerOptions as ContainerOptionsBase, Filter, Types, MessageUtil, Sasl } from "rhea"; | ||
@@ -3,0 +6,0 @@ import { EventEmitter } from "events"; |
@@ -1,3 +0,3 @@ | ||
import { Connection } from "./connection"; | ||
import { Container } from "./container"; | ||
import type { Connection } from "./connection"; | ||
import type { Container } from "./container"; | ||
import { Session } from "./session"; | ||
@@ -13,3 +13,3 @@ import { Delivery, Message, ConnectionError, EventContext as RheaEventContext } from "rhea"; | ||
*/ | ||
export declare type OnAmqpEvent = (context: EventContext) => void; | ||
export type OnAmqpEvent = (context: EventContext) => void; | ||
/** | ||
@@ -76,3 +76,3 @@ * Defines the AMQP Connection context. This context is provided when you add an | ||
} | ||
export declare module EventContext { | ||
export declare namespace EventContext { | ||
/** | ||
@@ -79,0 +79,0 @@ * Translates rhea's EventContext into rhea-promise EventContext |
@@ -6,3 +6,3 @@ import * as debugModule from "debug"; | ||
*/ | ||
export declare const container: debugModule.IDebugger; | ||
export declare const container: debugModule.Debugger; | ||
/** | ||
@@ -12,3 +12,3 @@ * @ignore | ||
*/ | ||
export declare const connection: debugModule.IDebugger; | ||
export declare const connection: debugModule.Debugger; | ||
/** | ||
@@ -18,3 +18,3 @@ * @ignore | ||
*/ | ||
export declare const session: debugModule.IDebugger; | ||
export declare const session: debugModule.Debugger; | ||
/** | ||
@@ -24,3 +24,3 @@ * @ignore | ||
*/ | ||
export declare const sender: debugModule.IDebugger; | ||
export declare const sender: debugModule.Debugger; | ||
/** | ||
@@ -30,3 +30,3 @@ * @ignore | ||
*/ | ||
export declare const receiver: debugModule.IDebugger; | ||
export declare const receiver: debugModule.Debugger; | ||
/** | ||
@@ -36,3 +36,3 @@ * @ignore | ||
*/ | ||
export declare const error: debugModule.IDebugger; | ||
export declare const error: debugModule.Debugger; | ||
/** | ||
@@ -42,3 +42,3 @@ * @ignore | ||
*/ | ||
export declare const eventHandler: debugModule.IDebugger; | ||
export declare const eventHandler: debugModule.Debugger; | ||
/** | ||
@@ -48,3 +48,3 @@ * @ignore | ||
*/ | ||
export declare const contextTranslator: debugModule.IDebugger; | ||
export declare const contextTranslator: debugModule.Debugger; | ||
//# sourceMappingURL=log.d.ts.map |
@@ -70,3 +70,3 @@ import { EventContext as RheaEventContext } from "rhea"; | ||
*/ | ||
export declare type Func<T, V> = (a: T) => V; | ||
export type Func<T, V> = (a: T) => V; | ||
/** | ||
@@ -99,3 +99,3 @@ * Determines whether the given error object is like an AmqpError object. | ||
*/ | ||
export declare type ParsedOutput<T> = { | ||
export type ParsedOutput<T> = { | ||
[P in keyof T]: T[P]; | ||
@@ -102,0 +102,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
301
369612
16
73
6180
- Removeddebug@3.2.7(transitive)
Updateddebug@^4.0.0
Updatedtslib@^2.6.0