nats-hemera
Advanced tools
Comparing version 5.1.2 to 5.1.3
@@ -0,0 +0,0 @@ 'use strict' |
@@ -1001,3 +1001,3 @@ /** | ||
* | ||
* @param {any} definition | ||
* @param {any} pattern | ||
* @param {any} cb | ||
@@ -1007,4 +1007,4 @@ * | ||
*/ | ||
add(definition, cb) { | ||
if (!definition) { | ||
add(pattern, cb) { | ||
if (!pattern) { | ||
let error = new Errors.HemeraError( | ||
@@ -1018,8 +1018,8 @@ 'Pattern is required to define a server action' | ||
// check for use quick syntax for JSON objects | ||
if (typeof definition === 'string') { | ||
definition = TinySonic(definition) | ||
if (typeof pattern === 'string') { | ||
pattern = TinySonic(pattern) | ||
} | ||
// topic is needed to subscribe on a subject in NATS | ||
if (!definition.topic) { | ||
if (!pattern.topic) { | ||
let error = new Errors.HemeraError( | ||
@@ -1033,18 +1033,16 @@ 'Topic is required and must be from type string', | ||
let schema = Util.extractSchema(definition) | ||
let patternOnly = Util.cleanPattern(definition) | ||
let schema = Util.extractSchema(pattern) | ||
let patternOnly = Util.cleanPattern(pattern) | ||
const addDef = { | ||
let addDefinition = new Add({ | ||
schema: schema, | ||
pattern: patternOnly, | ||
transport: { | ||
topic: definition.topic, | ||
pubsub: definition.pubsub$, | ||
maxMessages: definition.maxMessages$, | ||
queue: definition.queue$ | ||
topic: pattern.topic, | ||
pubsub: pattern.pubsub$, | ||
maxMessages: pattern.maxMessages$, | ||
queue: pattern.queue$ | ||
} | ||
} | ||
}) | ||
let addDefinition = new Add(addDef) | ||
if (cb) { | ||
@@ -1077,8 +1075,8 @@ // set callback | ||
// check for invalid topic subscriptions | ||
// it's not possible to register multiple patterns | ||
// with different transport options with the same topic | ||
// it's not possible to susbcribe to the same topic with different transport options | ||
// because we use one subscription for the topic | ||
const def = this._checkForTransportCollision(addDefinition) | ||
if (def) { | ||
this.log.error( | ||
'Could not register pattern "%s" because pattern "%s" has different transport configuration but the same topic. Please use a different topic name!', | ||
'Topic is already registered with special transport options. Please use a different topic name.', | ||
Util.pattern(addDefinition.pattern), | ||
@@ -1088,3 +1086,3 @@ Util.pattern(def.pattern) | ||
throw new Errors.HemeraError( | ||
'Transport options differs from the first registration of this topic' | ||
'Topic is already registered with special transport options' | ||
) | ||
@@ -1135,17 +1133,8 @@ } | ||
_checkForTransportCollision(addDefinition) { | ||
const definitions = this._router.list() | ||
definitions.push(addDefinition) | ||
for (var i = 0; i < definitions.length; i++) { | ||
const def = definitions[i] | ||
const mT2 = addDefinition.transport | ||
for (const def of this._router) { | ||
const mT1 = def.transport | ||
const mT2 = addDefinition.transport | ||
// looking for another pattern with same topic but | ||
// different transport options | ||
if ( | ||
!Object.is(addDefinition, def) && | ||
addDefinition.pattern.topic === def.pattern.topic | ||
) { | ||
if (addDefinition.pattern.topic === def.pattern.topic) { | ||
if ( | ||
@@ -1160,3 +1149,2 @@ mT1.maxMessages !== mT2.maxMessages || | ||
} | ||
return null | ||
@@ -1163,0 +1151,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict' |
@@ -0,0 +0,0 @@ 'use strict' |
@@ -0,0 +0,0 @@ 'use strict' |
{ | ||
"name": "nats-hemera", | ||
"author": "Dustin Deus (https://github.com/StarpTech)", | ||
"version": "5.1.2", | ||
"version": "5.1.3", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://hemerajs.github.io/hemera/", |
@@ -0,0 +0,0 @@ # Hemera package |
78207
3141