@silenteer/natsu
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -13,18 +13,6 @@ "use strict"; | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
const { urls, handlers = {}, user, pass, verbose } = params; | ||
if (Object.keys(handlers).length === 0) { | ||
const { natsService, handlers = {} } = params; | ||
if (!natsService || Object.keys(handlers).length === 0) { | ||
throw new Error(`Must register handlers before starting client`); | ||
} | ||
const client = yield (0, nats_1.connect)({ | ||
servers: urls, | ||
user, | ||
pass, | ||
pingInterval: 30 * 1000, | ||
maxPingOut: 10, | ||
verbose, | ||
reconnect: true, | ||
maxReconnectAttempts: 3, | ||
reconnectTimeWait: 1000, | ||
}); | ||
const natsService = createNatsService(client); | ||
Object.entries(handlers).forEach(([subject, { handler, injection: registeredInjection, middlewares }]) => { | ||
@@ -132,3 +120,2 @@ const subcription = natsService.subscribe(subject); | ||
}); | ||
return natsService; | ||
}); | ||
@@ -465,11 +452,10 @@ } | ||
let natsService; | ||
let isStarted; | ||
const client = { | ||
start: () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
natsService = yield start({ | ||
urls, | ||
yield start({ | ||
natsService, | ||
handlers: natsHandlers, | ||
user, | ||
pass, | ||
verbose, | ||
}); | ||
isStarted = true; | ||
}), | ||
@@ -480,5 +466,19 @@ stop: () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
natsHandlers = undefined; | ||
isStarted = false; | ||
}), | ||
register: (handlers) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
const isStarted = !!natsService; | ||
if (!natsService) { | ||
const natsConnection = yield (0, nats_1.connect)({ | ||
servers: urls, | ||
user, | ||
pass, | ||
pingInterval: 30 * 1000, | ||
maxPingOut: 10, | ||
verbose, | ||
reconnect: true, | ||
maxReconnectAttempts: 3, | ||
reconnectTimeWait: 1000, | ||
}); | ||
natsService = createNatsService(natsConnection); | ||
} | ||
if (isStarted) { | ||
@@ -485,0 +485,0 @@ throw new Error(`Can't register more handler after nats client started`); |
{ | ||
"name": "@silenteer/natsu", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "private": false, |
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
52090