Skip to content
Permalink
Browse files

v3.9.0

  • Loading branch information
rjrodger committed May 6, 2019
1 parent 2713167 commit 98af1536196d4461e050ab6b71ca7563ea79ed8f
Showing with 65 additions and 52 deletions.
  1. +5 −0 CHANGES.md
  2. +7 −4 lib/common.js
  3. +4 −6 lib/inward.js
  4. +1 −1 package.json
  5. +9 −9 seneca.js
  6. +39 −32 test/custom.test.js
@@ -1,3 +1,8 @@
## 3.9.0 2019-05-06

* Added custom$ and fixed$ directives to seneca.add - see test/custom.test.js:custom-add - allows fixed message arguments and meta custom values on individual messages.


## 3.8.4 2019-03-03

* Seneca.translate can include/exclude message properties.
@@ -293,9 +293,8 @@ exports.makedie = function(instance, ctxt) {
// undead is only for testing, do not use in production
var undead = (so.debug && so.debug.undead) || (err && err.undead)
var full =
(so.debug && so.debug.print && 'full' === so.debug.print.fatal) || false
var print_env =
(so.debug && so.debug.print.env) || false
(so.debug && so.debug.print && 'full' === so.debug.print.fatal) || false
var print_env = (so.debug && so.debug.print.env) || false

if (0 < diecount) {
if (!undead) {
@@ -344,7 +343,11 @@ exports.makedie = function(instance, ctxt) {
(!full ? '' : ', path=' + process.execPath) +
', argv=' +
Util.inspect(process.argv).replace(/\n/g, '') +
(!full ? '' : (!print_env ? '' : ', env=' + Util.inspect(process.env).replace(/\n/g, '')))
(!full
? ''
: !print_env
? ''
: ', env=' + Util.inspect(process.env).replace(/\n/g, ''))

var when = new Date()

@@ -23,19 +23,18 @@ module.exports = {
announce: inward_announce
}


function inward_msg_modify(ctxt, data) {
var meta = data.meta

if (ctxt.actdef) {
var fixed = ctxt.actdef.fixed
var custom = ctxt.actdef.custom

if(fixed) {
Object.assign(data.msg,fixed)
if (fixed) {
Object.assign(data.msg, fixed)
}

if(custom) {
if (custom) {
meta.custom = meta.custom || {}
Object.assign(meta.custom, custom)
}
@@ -281,7 +280,6 @@ function inward_msg_meta(ctxt, data) {
)
}


function inward_prepare_delegate(ctxt, data) {
Assert(data.reply)

@@ -1,7 +1,7 @@
{
"name": "seneca",
"description": "A Microservices Framework for Node.js",
"version": "3.8.4",
"version": "3.9.0",
"license": "MIT",
"homepage": "http://senecajs.org",
"keywords": [
@@ -101,7 +101,7 @@ var option_defaults = {
argv: null,

// Length of data description in logs
datalen: 111,
datalen: 111
},

// Enforce strict behaviours. Relax when backwards compatibility needed.
@@ -598,7 +598,7 @@ function make_seneca(initial_options) {
function api_add() {
var self = this
var args = Common.parsePattern(self, arguments, 'action:f? actdef:o?')

var raw_pattern = args.pattern
var pattern = self.util.clean(raw_pattern)

@@ -640,7 +640,7 @@ function make_seneca(initial_options) {

actdef.fixed = Jsonic(raw_pattern.fixed$ || {})
actdef.custom = Jsonic(raw_pattern.custom$ || {})

var strict_add =
raw_pattern.strict$ && raw_pattern.strict$.add !== null
? !!raw_pattern.strict$.add
@@ -950,7 +950,7 @@ function make_seneca(initial_options) {
instance.private$.ge.add(execspec)
}

function api_fix(patargs,msgargs,custom) {
function api_fix(patargs, msgargs, custom) {
var self = this

// var defargs = Common.parsePattern(self, arguments)
@@ -961,11 +961,11 @@ function make_seneca(initial_options) {
fix_delegate.add = function fix_add() {
var args = Common.parsePattern(this, arguments, 'rest:.*', patargs)
var addargs = [args.pattern]
.concat({
fixed$:Object.assign({},msgargs,args.pattern.fixed$),
custom$:Object.assign({},custom,args.pattern.custom$),
})
.concat(args.rest)
.concat({
fixed$: Object.assign({}, msgargs, args.pattern.fixed$),
custom$: Object.assign({}, custom, args.pattern.custom$)
})
.concat(args.rest)
return self.add.apply(this, addargs)
}

@@ -386,16 +386,19 @@ describe('custom', function() {
})

lab.it('custom-add', test_opts, async () => {
var si = await Seneca({legacy:{transport:false}})
.test()
.use('promisify')
// TODO: extend seneca.message in promisify to handle this form
.add('foo:true',{fixed$:{bar:1},custom$:{zed:'a'}},
function foo_true(msg,reply, meta) {
msg.custom_zed = meta.custom.zed
reply(msg)
})
.ready()
var si = await Seneca({ legacy: { transport: false } })
.test()
.use('promisify')
// TODO: extend seneca.message in promisify to handle this form
.add(
'foo:true',
{ fixed$: { bar: 1 }, custom$: { zed: 'a' } },
function foo_true(msg, reply, meta) {
msg.custom_zed = meta.custom.zed
reply(msg)
}
)
.ready()

var out = await si.post('foo:true')
expect(out).equal({ foo: true, bar: 1, custom_zed: 'a' })
@@ -405,7 +408,7 @@ describe('custom', function() {
})

out = await si.post('foo:false')
expect(out).equal({foo: false})
expect(out).equal({ foo: false })

si.message('foo:true', async function foo_true_a(msg) {
// TODO: this is adding plugin$ to msg and should not
@@ -415,35 +418,40 @@ describe('custom', function() {
var out = await si.post('foo:true')
expect(out).equal({ foo: true, bar: 1, custom_zed: 'a' })

si.add('foo:true',{fixed$:'bar:2,qaz:3',custom$:'zed:"b",dez:"c"'},
function foo_true(msg,reply, meta) {
msg.custom_zed = meta.custom.zed
msg.custom_dez = meta.custom.dez
reply(msg)
})

var out = await si.post('foo:true')
expect(out).equal({ foo: true, bar: 2, qaz: 3, custom_zed: 'b', custom_dez: 'c' })
si.add(
'foo:true',
{ fixed$: 'bar:2,qaz:3', custom$: 'zed:"b",dez:"c"' },
function foo_true(msg, reply, meta) {
msg.custom_zed = meta.custom.zed
msg.custom_dez = meta.custom.dez
reply(msg)
}
)

var out = await si.post('foo:true')
expect(out).equal({
foo: true,
bar: 2,
qaz: 3,
custom_zed: 'b',
custom_dez: 'c'
})
})


lab.it('custom-add-fix', test_opts, async () => {
var si = await Seneca({legacy:{transport:false}})
.test()
.use('promisify')
var si = await Seneca({ legacy: { transport: false } })
.test()
.use('promisify')

si.message('role:qaz,foo:false', async function(msg) {
return msg
})

si
.fix({role:'qaz'},{bar:1},{zed:'a'})
.add('foo:true',
function foo_true(msg,reply, meta) {
msg.custom_zed = meta.custom.zed
reply(msg)
})
si.fix({ role: 'qaz' }, { bar: 1 }, { zed: 'a' })
.add('foo:true', function foo_true(msg, reply, meta) {
msg.custom_zed = meta.custom.zed
reply(msg)
})
.ready()

var out = await si.post('role:qaz,foo:true')
@@ -460,5 +468,4 @@ describe('custom', function() {
var out = await si.post('role:qaz,foo:true')
expect(out).equal({ role: 'qaz', foo: true, bar: 1, custom_zed: 'a' })
})

})

0 comments on commit 98af153

Please sign in to comment.
You can’t perform that action at this time.