Skip to content

Commit

Permalink
v3.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Mar 3, 2019
1 parent 486376b commit 9ff0b92
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 65 deletions.
28 changes: 12 additions & 16 deletions lib/api.js
Expand Up @@ -277,40 +277,36 @@ exports.translate = function(from_in, to_in, pick_in) {
var to = 'string' === typeof to_in ? Jsonic(to_in) : to_in

var pick = {}
if('string' === typeof(pick_in)) {

if ('string' === typeof pick_in) {
pick_in = pick_in.split(/\s*,\s*/)
}

if(Array.isArray(pick_in)) {
if (Array.isArray(pick_in)) {
pick_in.forEach(function(prop) {
if(prop.startsWith('-')) {
if (prop.startsWith('-')) {
pick[prop.substring(1)] = false
}
else {
} else {
pick[prop] = true
}
})
}
else if ('object' === typeof(pick_in) ) {
pick = Object.assign({},pick_in)
}
else {
} else if ('object' === typeof pick_in) {
pick = Object.assign({}, pick_in)
} else {
pick = null
}

this.add(from, function(msg, reply) {
var pick_msg

if(pick) {
if (pick) {
pick_msg = {}
Object.keys(pick).forEach(function(prop) {
if(pick[prop]) {
if (pick[prop]) {
pick_msg[prop] = msg[prop]
}
})
}
else {
} else {
pick_msg = this.util.clean(msg)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common.js
Expand Up @@ -512,10 +512,10 @@ exports.make_standard_act_log_entry = function(
exports.make_standard_err_log_entry = function(err, ctxt) {
if (!err) return ctxt

if(err.details && ctxt && ctxt.caller) {
if (err.details && ctxt && ctxt.caller) {
err.details.caller = ctxt.caller
}

return _.extend(
{
notice: err.message,
Expand Down
12 changes: 5 additions & 7 deletions lib/logging.js
Expand Up @@ -69,7 +69,7 @@ logging.preload = function() {

return {
extend: {
logger: logger,
logger: logger
}
}
}
Expand All @@ -78,7 +78,7 @@ function build_test_log(seneca, origspec, data) {
var logstr
var time = data.when - seneca.start_time
var datalen = seneca.private$.exports.options.debug.datalen

if ('test' === origspec || 'print' === origspec) {
var logb = [
time +
Expand Down Expand Up @@ -127,8 +127,7 @@ function build_test_log(seneca, origspec, data) {
logb.push(data.name)
} else if ('plugin' === data.kind) {
logb.push(
data.plugin_name +
(data.plugin_tag ? '$' + data.plugin_tag : '')
data.plugin_name + (data.plugin_tag ? '$' + data.plugin_tag : '')
)
} else if ('options' === data.kind) {
// deliberately omit
Expand All @@ -152,10 +151,10 @@ function build_test_log(seneca, origspec, data) {
)
}

if(data.did) {
if (data.did) {
logb.push(data.did)
}

logstr = logb.join('\t')
} else {
logstr = Util.inspect(data, { depth: null })
Expand All @@ -169,7 +168,6 @@ function build_test_log(seneca, origspec, data) {
return logstr
}


// TODO: needs massive refactor

function logfilter(options) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "seneca",
"description": "A Microservices Framework for Node.js",
"version": "3.8.3",
"version": "3.8.4",
"license": "MIT",
"homepage": "http://senecajs.org",
"keywords": [
Expand Down
18 changes: 10 additions & 8 deletions seneca.js
Expand Up @@ -199,7 +199,7 @@ var option_defaults = {

// Setup event listeners before starting
events: {},

// Backwards compatibility settings.
legacy: {
// Action callback must always have signature callback(error, result).
Expand Down Expand Up @@ -352,18 +352,20 @@ function make_seneca(initial_options) {

// Expose private data to plugins.
root$.private$ = private$

// Resolve initial options.
private$.optioner = Optioner(module, option_defaults, initial_options)
var opts = { $: private$.optioner.get() }

// Setup event handlers, if defined
;['log','act_in','act_out','act_err','ready','close'].forEach(function(event_name){
if( 'function' === typeof(opts.$.events[event_name]) ) {

// Setup event handlers, if defined
;['log', 'act_in', 'act_out', 'act_err', 'ready', 'close'].forEach(function(
event_name
) {
if ('function' === typeof opts.$.events[event_name]) {
root$.on(event_name, opts.$.events[event_name])
}
})

// Create internal tools.
private$.actnid = Nid({ length: opts.$.idlen })
private$.didnid = Nid({ length: opts.$.didlen })
Expand Down Expand Up @@ -1116,7 +1118,7 @@ function make_log(instance, modifier) {
instance.log ||
function log(data) {
instance.private$.logger(this, data)
instance.emit('log',data)
instance.emit('log', data)
}

log = prepare_log(instance, make_modified_log(log, modifier))
Expand Down
46 changes: 22 additions & 24 deletions test/api.test.js
Expand Up @@ -91,8 +91,7 @@ describe('api', function() {
})

it('translate', function(fin) {
si
.test()
si.test()
.add('a:2', function(msg, reply) {
reply(msg)
})
Expand All @@ -103,22 +102,21 @@ describe('api', function() {
reply(msg)
})
.add('a:5', function(msg, reply) {
reply({a:5,x:msg.x,y:msg.y})
reply({ a: 5, x: msg.x, y: msg.y })
})
.add('e:5,f:1', function(msg, reply) {
reply(msg)
})

si
.translate('a:1', 'a:2')
si.translate('a:1', 'a:2')
.translate({ a: 3 }, { a: 4 })
.translate('c:3,d:4', 'b:3')
.translate('a:6', 'a:5', 'x')
.translate('a:7', 'a:5', '-x,y')
.translate('a:8', 'a:5', ['x'])
.translate('a:9', 'a:5', ['-x','y'])
.translate('a:10', 'a:5', {x:true})
.translate('a:11', 'a:5', {x:false,y:true})
.translate('a:9', 'a:5', ['-x', 'y'])
.translate('a:10', 'a:5', { x: true })
.translate('a:11', 'a:5', { x: false, y: true })
.translate('e:6,g:1', 'e:5,f:1', 'x')
.translate('e:7,g:1', 'e:5,f:1', 'x,g')

Expand All @@ -133,41 +131,41 @@ describe('api', function() {
expect(out).contains({ b: 3, c: 3, d: 4 })
})

// y is removed as not picked
// y is removed as not picked
.act('a:6,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, x: 1})
expect(out).contains({ a: 5, x: 1 })
})
// x is removed as not picked
// x is removed as not picked
.act('a:7,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, y: 2})
expect(out).contains({ a: 5, y: 2 })
})

// y is removed as not picked
// y is removed as not picked
.act('a:8,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, x: 1})
expect(out).contains({ a: 5, x: 1 })
})
// x is removed as not picked
// x is removed as not picked
.act('a:9,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, y: 2})
expect(out).contains({ a: 5, y: 2 })
})

// y is removed as not picked
// y is removed as not picked
.act('a:10,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, x: 1})
expect(out).contains({ a: 5, x: 1 })
})
// x is removed as not picked
// x is removed as not picked
.act('a:11,x:1,y:2', function(err, out) {
expect(out).contains({ a: 5, y: 2})
expect(out).contains({ a: 5, y: 2 })
})

// with pick, unused from props are dropped
// with pick, unused from props are dropped
.act('e:6,g:1,x:1,y:2', function(err, out) {
expect(this.util.clean(out)).equals({ e: 5, x: 1, f: 1})
expect(this.util.clean(out)).equals({ e: 5, x: 1, f: 1 })
})

// ... unless explicitly added
// ... unless explicitly added
.act('e:7,g:1,x:1,y:2', function(err, out) {
expect(this.util.clean(out)).equals({ e: 5, g: 1, x: 1, f: 1})
expect(this.util.clean(out)).equals({ e: 5, g: 1, x: 1, f: 1 })
})

.ready(fin)
Expand Down
16 changes: 9 additions & 7 deletions test/logging.test.js
Expand Up @@ -38,24 +38,26 @@ describe('logging', function() {
it('event', function(fin) {
var loga = []
var logb = []
Seneca({events:{
log: function(data) {
loga.push(data)
Seneca({
events: {
log: function(data) {
loga.push(data)
}
}
}})
})
.test()
.on('log', function(data) {
logb.push(data)
})
.ready(function() {
expect(loga.length).above(logb.length)
var last_entry = logb[logb.length-1]
expect(last_entry).contains({kind:'notice',level:'info'})
var last_entry = logb[logb.length - 1]
expect(last_entry).contains({ kind: 'notice', level: 'info' })
expect(last_entry.notice).startsWith('hello')
fin()
})
})

it('quiet', function(fin) {
Seneca()
.quiet()
Expand Down

0 comments on commit 9ff0b92

Please sign in to comment.