Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

seneca

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seneca - npm Package Compare versions

Comparing version 3.24.1 to 3.25.0

lib/sub.d.ts

5

CHANGES.md

@@ -0,1 +1,6 @@

## 3.25.0 2021-11-03
* Seneca.add now uses Ordu to run add-action tasks, thus easier to customize.
## 3.24.1 2021-10-12

@@ -2,0 +7,0 @@

30

lib/act.js

@@ -77,3 +77,11 @@ /* Copyright © 2019 Richard Rodger and other contributors, MIT License. */

if (!timedout) {
intern.handle_reply(meta, actctxt, actmsg, err, out, reply_meta)
intern.handle_reply(
opts,
meta,
actctxt,
actmsg,
err,
out,
reply_meta
)
}

@@ -85,3 +93,3 @@ done()

var ex = Util.isError(e) ? e : new Error(Util.inspect(e))
intern.handle_reply(meta, actctxt, actmsg, ex)
intern.handle_reply(opts, meta, actctxt, actmsg, ex)
done()

@@ -105,3 +113,3 @@ }

intern.handle_reply(meta, actctxt, actmsg, timeout_err)
intern.handle_reply(opts, meta, actctxt, actmsg, timeout_err)
}

@@ -226,3 +234,3 @@

handle_reply: function (meta, actctxt, actmsg, err, out, reply_meta) {
handle_reply: function (opts, meta, actctxt, actmsg, err, out, reply_meta) {
meta.end = Date.now()

@@ -271,3 +279,8 @@

try {
reply.call(delegate, data.err, data.res, data.meta)
if (opts.legacy.meta_arg_remove) {
// Non-existence != undefined, so must be a separate call.
reply.call(delegate, data.err, data.res)
} else {
reply.call(delegate, data.err, data.res, data.meta)
}
} catch (thrown_obj) {

@@ -372,3 +385,8 @@ intern.callback_error(delegate, thrown_obj, actctxt, data)

actdef.func.call(delegate, data.msg, data.reply, data.meta)
if (opts.legacy.meta_arg_remove) {
// Non-existence != undefined, so must be a separate call.
actdef.func.call(delegate, data.msg, data.reply)
} else {
actdef.func.call(delegate, data.msg, data.reply, data.meta)
}
},

@@ -375,0 +393,0 @@

2

lib/actions.js

@@ -55,3 +55,2 @@ /* Copyright © 2014-2021 Richard Rodger and other contributors, MIT License. */

} else {
//stats = Common.deep(private$.stats)
stats = Object.assign({}, private$.stats)

@@ -65,3 +64,2 @@ stats.now = new Date()

var summary = null == msg.summary || Common.boolify(msg.summary)
//(/^false$/i.exec(msg.summary) ? false : !!msg.summary)

@@ -68,0 +66,0 @@ if (summary) {

/* Copyright © 2019 Richard Rodger and other contributors, MIT License. */
'use strict'
const Jsonic = require('jsonic')
const Common = require('./common')
// TODO: convert to latest ordu
exports.api_add = function () {
var self = this
var private$ = self.private$
var opts = self.options()
var args = Common.parsePattern(self, arguments, 'action:f? actdef:o?')
let ctx = {
opts: this.options(),
args: Common.parsePattern(this, arguments, 'action:f? actdef:o?'),
private: this.private$,
instance: this,
}
var raw_pattern = args.pattern
var pattern = self.util.clean(raw_pattern)
let data = {
actdef: null,
pattern: null,
action: null,
strict_add: null,
addroute: null,
}
var action =
args.action ||
function default_action(msg, done, meta) {
done.call(this, null, meta.dflt || null)
// Senecca.order.add tasks are defined in main seneca file.
let res = this.order.add.execSync(ctx, data)
if (res.err) {
throw res.err
}
return this
}
exports.task = {
prepare(spec) {
const args = spec.ctx.args
let raw_pattern = args.pattern
let pattern = Common.clean(raw_pattern)
let action =
args.action ||
function default_action(msg, done, meta) {
if (meta) {
done.call(this, null, meta.dflt || null, meta)
} else {
done.call(this, null, null)
}
}
let actdef = Common.deep(args.actdef) || {}
actdef.raw = Common.deep({}, raw_pattern)
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
action,
pattern,
},
}
},
var actdef = self.util.deep(args.actdef) || {}
plugin(spec) {
const actdef = spec.data.actdef
actdef.raw = Common.deep({}, raw_pattern)
// TODO: change root$ to root as plugin_name should not contain $
actdef.plugin_name = actdef.plugin_name || 'root$'
actdef.plugin_fullname =
actdef.plugin_fullname ||
actdef.plugin_name +
((actdef.plugin_tag === '-' ? void 0 : actdef.plugin_tag)
? '$' + actdef.plugin_tag
: '')
// TODO: change root$ to root as plugin_name should not contain $
actdef.plugin_name = actdef.plugin_name || 'root$'
actdef.plugin_fullname =
actdef.plugin_fullname ||
actdef.plugin_name +
((actdef.plugin_tag === '-' ? void 0 : actdef.plugin_tag)
? '$' + actdef.plugin_tag
: '')
actdef.plugin = {
name: actdef.plugin_name,
tag: actdef.plugin_tag,
fullname: actdef.plugin_fullname,
}
actdef.plugin = {
name: actdef.plugin_name,
tag: actdef.plugin_tag,
fullname: actdef.plugin_fullname,
}
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
},
}
},
var add_callpoint = private$.callpoint()
if (add_callpoint) {
actdef.callpoint = add_callpoint
}
callpoint(spec) {
const private$ = spec.ctx.private
const actdef = spec.data.actdef
actdef.sub = !!raw_pattern.sub$
actdef.client = !!raw_pattern.client$
let add_callpoint = private$.callpoint()
if (add_callpoint) {
actdef.callpoint = add_callpoint
}
// Deprecate a pattern by providing a string message using deprecate$ key.
actdef.deprecate = raw_pattern.deprecate$
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
},
}
},
actdef.fixed = self.util.Jsonic(raw_pattern.fixed$ || {})
actdef.custom = self.util.Jsonic(raw_pattern.custom$ || {})
flags(spec) {
const actdef = spec.data.actdef
const pattern = spec.data.pattern
const opts = spec.ctx.opts
var strict_add =
raw_pattern.strict$ && raw_pattern.strict$.add !== null
? !!raw_pattern.strict$.add
: !!opts.strict.add
actdef.sub = !!actdef.raw.sub$
actdef.client = !!actdef.raw.client$
var addroute = true
// Deprecate a pattern by providing a string message using deprecate$ key.
actdef.deprecate = actdef.raw.deprecate$
if (opts.legacy.actdef) {
actdef.args = Common.deep(pattern)
}
actdef.fixed = Jsonic(actdef.raw.fixed$ || {})
actdef.custom = Jsonic(actdef.raw.custom$ || {})
var action_name =
null == action.name || '' === action.name ? 'action' : action.name
actdef.id = action_name + '_' + private$.next_action_id()
actdef.name = action_name
actdef.func = action
var strict_add =
actdef.raw.strict$ && actdef.raw.strict$.add !== null
? !!actdef.raw.strict$.add
: !!opts.strict.add
// Canonical string form of the action pattern.
actdef.pattern = Common.pattern(pattern)
if (opts.legacy.actdef) {
actdef.args = Common.deep(pattern)
}
// Canonical object form of the action pattern.
actdef.msgcanon = self.util.Jsonic(actdef.pattern)
// Canonical string form of the action pattern.
actdef.pattern = Common.pattern(pattern)
var priordef = self.find(pattern)
// Canonical object form of the action pattern.
actdef.msgcanon = Jsonic(actdef.pattern)
if (priordef && strict_add && priordef.pattern !== actdef.pattern) {
// only exact action patterns are overridden
// use .wrap for pin-based patterns
priordef = null
}
// Canonical string form of the action pattern.
actdef.pattern = Common.pattern(pattern)
if (priordef) {
// Clients needs special handling so that the catchall
// pattern does not submit all patterns into the handle
if (
'function' === typeof priordef.handle &&
((priordef.client && actdef.client) ||
(!priordef.client && !actdef.client))
) {
//priordef.handle(args.pattern, action)
priordef.handle(actdef)
addroute = false
} else {
actdef.priordef = priordef
// Canonical object form of the action pattern.
actdef.msgcanon = Jsonic(actdef.pattern)
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
strict_add,
},
}
actdef.priorpath = priordef.id + ';' + priordef.priorpath
} else {
actdef.priorpath = ''
}
},
if ('function' === typeof action.handle) {
actdef.handle = action.handle
}
action(spec) {
const actdef = spec.data.actdef
const action = spec.data.action
const private$ = spec.ctx.private
private$.stats.actmap[actdef.pattern] =
private$.stats.actmap[actdef.pattern] || intern.make_action_stats(actdef)
var action_name =
null == action.name || '' === action.name ? 'action' : action.name
actdef.id = action_name + '_' + private$.next_action_id()
actdef.name = action_name
actdef.func = action
var pattern_rules = {}
Common.each(raw_pattern, function (v, k) {
if (v && 'object' === typeof v && !~k.indexOf('$')) {
pattern_rules[k] = v
delete pattern[k]
if ('function' === typeof action.handle) {
actdef.handle = action.handle
}
})
actdef.rules = pattern_rules
if (addroute) {
self.log.debug({
kind: 'add',
case: actdef.sub ? 'SUB' : 'ADD',
action: actdef.id,
pattern: actdef.pattern,
callpoint: private$.callpoint(true),
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
},
}
},
prior(spec) {
const actdef = spec.data.actdef
const pattern = spec.data.pattern
const strict_add = spec.data.strict_add
const instance = spec.ctx.instance
let addroute = true
var priordef = instance.find(pattern)
if (priordef && strict_add && priordef.pattern !== actdef.pattern) {
// only exact action patterns are overridden
// use .wrap for pin-based patterns
priordef = null
}
if (priordef) {
// Clients needs special handling so that the catchall
// pattern does not submit all patterns into the handle
if (
'function' === typeof priordef.handle &&
((priordef.client && actdef.client) ||
(!priordef.client && !actdef.client))
) {
//priordef.handle(args.pattern, action)
priordef.handle(actdef)
addroute = false
} else {
actdef.priordef = priordef
}
actdef.priorpath = priordef.id + ';' + priordef.priorpath
} else {
actdef.priorpath = ''
}
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
addroute,
},
}
},
rules(spec) {
const actdef = spec.data.actdef
const pattern = spec.data.pattern
var pattern_rules = {}
Common.each(actdef.raw, function (v, k) {
if (v && 'object' === typeof v && !~k.indexOf('$')) {
pattern_rules[k] = v
delete pattern[k]
}
})
actdef.rules = pattern_rules
private$.actrouter.add(pattern, actdef)
}
return {
// TODO: simple op:set would be faster
op: 'merge',
out: {
actdef,
},
}
},
private$.actdef[actdef.id] = actdef
register(spec) {
const actdef = spec.data.actdef
const pattern = spec.data.pattern
const addroute = spec.data.addroute
intern.deferred_modify_action(self, actdef)
const private$ = spec.ctx.private
const instance = spec.ctx.instance
return self
if (addroute) {
instance.log.debug({
kind: 'add',
case: actdef.sub ? 'SUB' : 'ADD',
action: actdef.id,
pattern: actdef.pattern,
callpoint: private$.callpoint(true),
})
private$.actrouter.add(pattern, actdef)
}
private$.stats.actmap[actdef.pattern] =
private$.stats.actmap[actdef.pattern] || intern.make_action_stats(actdef)
private$.actdef[actdef.id] = actdef
return {
op: 'next',
}
},
modify(spec) {
const actdef = spec.data.actdef
const instance = spec.ctx.instance
intern.deferred_modify_action(instance, actdef)
return {
op: 'next',
}
},
}

@@ -140,0 +286,0 @@

@@ -1,2 +0,2 @@

/* Copyright © 2010-2018 Richard Rodger and other contributors, MIT License. */
/* Copyright © 2010-2021 Richard Rodger and other contributors, MIT License. */
'use strict'

@@ -221,2 +221,3 @@

exports.prior = function () {
const opts = this.options()
if (null == this.private$.act) {

@@ -243,3 +244,9 @@ // TODO: should be a top level api method: seneca.fail

out = null == out ? out : Object.assign({}, out)
return reply.call(this, null, out, meta)
if (opts.legacy.meta_arg_remove) {
// Non-existence != undefined, so must be a separate call.
return reply.call(this, null, out)
} else {
return reply.call(this, null, out, meta)
}
}

@@ -246,0 +253,0 @@ }

@@ -524,2 +524,3 @@ /* Copyright © 2010-2021 Richard Rodger and other contributors, MIT License. */

return error.callpoint(new Error(), [
'/ordu.js',
'/seneca/seneca.js',

@@ -526,0 +527,0 @@ '/seneca/lib/',

@@ -147,9 +147,12 @@ /* Copyright © 2014-2020 Richard Rodger and other contributors, MIT License. */

adjusted.legacy = {
transport: false,
meta: false,
actdef: false,
logging: false,
action_signature: false,
error: false,
error_codes: false,
error: false,
fail: false,
logging: false,
meta: false,
meta_arg_remove: false,
transport: false,
timeout_string: false,
}

@@ -156,0 +159,0 @@ }

/* Copyright © 2020 Richard Rodger and other contributors, MIT License. */
'use strict'
const Common = require('./common')
//const errlog = Common.make_standard_err_log_entry
'use strict';
const Common = require('./common');
// Subscribe to messages.
exports.api_sub = function () {
var self = this
var subargs = Common.parsePattern(self, arguments, 'action:f')
var pattern = subargs.pattern
var action = subargs.action
var is_inward = !!pattern.in$
var is_outward = !!pattern.out$
if (!is_outward) {
is_inward = true // Default if nothing specified
}
var sub_pattern = self.util.clean(pattern)
var routers = [
is_inward ? self.private$.subrouter.inward : null,
is_outward ? self.private$.subrouter.outward : null,
].filter((r) => r)
routers.forEach((router) => {
// Exact match, create if needed
var sub_actions = router.find(sub_pattern, true)
if (!sub_actions) {
router.add(sub_pattern, (sub_actions = []))
sub_actions.pattern = Common.pattern(sub_pattern)
const self = this;
const subargs = Common.parsePattern(self, arguments, 'action:f');
const pattern = subargs.pattern;
const action = subargs.action;
let is_inward = !!pattern.in$;
let is_outward = !!pattern.out$;
if (!is_outward) {
is_inward = true; // Default if nothing specified
}
sub_actions.push(action)
})
return self
}
const sub_pattern = self.util.clean(pattern);
const routers = [
is_inward ? self.private$.subrouter.inward : null,
is_outward ? self.private$.subrouter.outward : null,
].filter((r) => r);
routers.forEach((router) => {
// Exact match, create if needed
let sub_actions = router.find(sub_pattern, true);
if (!sub_actions) {
router.add(sub_pattern, (sub_actions = []));
sub_actions.pattern = Common.pattern(sub_pattern);
}
sub_actions.push(action);
});
return self;
};
//# sourceMappingURL=sub.js.map
{
"name": "seneca",
"description": "A Microservices Framework for Node.js",
"version": "3.24.1",
"version": "3.25.0",
"license": "MIT",

@@ -83,3 +83,4 @@ "homepage": "http://senecajs.org",

"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
"repo-publish": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && npm run clean && npm i --registry https://registry.npmjs.org && npm run prettier && npm run build && npm test && npm run repo-tag --registry https://registry.npmjs.org && npm publish --registry https://registry.npmjs.org && npm dist-tag add seneca@$REPO_VERSION next --registry https://registry.npmjs.org && npm dist-tag add seneca@$REPO_VERSION plugin --registry https://registry.npmjs.org"
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
"repo-publish-quick": "npm run prettier && npm run build && npm run test && npm run repo-tag && npm publish --access public --registry https://registry.npmjs.org "
},

@@ -91,3 +92,3 @@ "dependencies": {

"fast-safe-stringify": "^2.1.1",
"gate-executor": "^3.0.0",
"gate-executor": "^3.1.1",
"jsonic": "^1.0.1",

@@ -101,6 +102,6 @@ "lodash.defaultsdeep": "^4.6.1",

"optioner": "^5.0.1",
"ordu": "^2.0.0",
"ordu": "^2.1.1",
"patrun": "^7.1.0",
"qs": "^6.10.1",
"rolling-stats": "^0.1.1",
"rolling-stats": "^0.2.1",
"seneca-transport": "^6.0.0",

@@ -114,3 +115,3 @@ "use-plugin": "^8.2.0"

"@seneca/test-plugin": "0.0.1",
"async": "^3.2.1",
"async": "^3.2.2",
"bench": "^0.3.6",

@@ -122,3 +123,3 @@ "coveralls": "^3.1.1",

"prettier": "^2.4.1",
"seneca-entity": "^15.0.0",
"seneca-entity": "^16.0.3",
"seneca-error-test": "^0.2.2",

@@ -128,5 +129,5 @@ "seneca-joi": "^7.0.2",

"gex": "^3.1.0",
"typescript": "^4.4.3",
"@types/node": "^16.10.3"
"typescript": "^4.4.4",
"@types/node": "^16.11.6"
}
}

@@ -15,3 +15,3 @@ /* Copyright © 2010-2020 Richard Rodger and other contributors, MIT License. */

const Stats = require('rolling-stats')
const { LegacyOrdu } = require('ordu')
const { Ordu, LegacyOrdu } = require('ordu')
const Eraro = require('eraro')

@@ -237,7 +237,10 @@ const Optioner = require('optioner')

legacy: {
// Add legacy properties
actdef: false,
// Action callback must always have signature callback(error, result).
action_signature: false,
// Logger can be changed by options method.
logging: false,
// Use old error handling.
error: true,

@@ -247,7 +250,7 @@ // Use old error codes. REMOVE in Seneca 4.x

// Use old error handling.
error: true,
// Use old fail method
fail: false,
// Use seneca-transport plugin.
transport: true,
// Logger can be changed by options method.
logging: false,

@@ -257,7 +260,7 @@ // Add meta$ property to messages.

// Add legacy properties
actdef: false,
// Remove meta argument in action arguments and callbacks.
meta_arg_remove: false,
// Use old fail method
fail: false,
// Use seneca-transport plugin.
transport: true,

@@ -267,2 +270,17 @@ // Insert "[TIMEOUT]" into timeout error message

},
// Processing task ordering.
order: {
// Action add task ordering.
add: {
// Print task execution log.
debug: false,
},
// Plugin load task ordering.
use: {
// Print task execution log.
debug: false,
},
},
}

@@ -479,17 +497,11 @@

// API for Ordu-defined processes.
root$.order = {}
// TODO: rename back to plugins
const api_use = Plugin.api_use(callpoint, { debug: !!start_opts.debug.ordu })
const api_use = Plugin.api_use(callpoint, {
debug: !!start_opts.debug.ordu || !!start_opts.order.use.debug,
})
root$.use = api_use.use // Define and load a plugin.
// const api_use_impl = Plugin.api_use(callpoint, { debug: !!start_opts.debug.ordu })
// const api_use = function(...args) {
// if('entity' === args[0]) {
// console.trace()
// }
// return api_use_impl.use.apply(this, args)
// }
// root$.use = api_use
root$.order.plugin = api_use.ordu

@@ -662,2 +674,15 @@

root$.order.add = new Ordu({
debug: !!start_opts.debug.ordu || !!start_opts.order.add.debug,
})
.add(Add.task.prepare)
.add(Add.task.plugin)
.add(Add.task.callpoint)
.add(Add.task.flags)
.add(Add.task.action)
.add(Add.task.prior)
.add(Add.task.rules)
.add(Add.task.register)
.add(Add.task.modify)
private$.inward = LegacyOrdu({ name: 'inward' })

@@ -664,0 +689,0 @@ .add(Inward.msg_modify)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc