Comparing version 3.32.1 to 3.33.0
@@ -0,1 +1,6 @@ | ||
## 3.33.0 2023-11-05 | ||
* Remove norma library, replace functionality with update gubu library. | ||
## 3.32.1 2023-09-16 | ||
@@ -2,0 +7,0 @@ |
"use strict"; | ||
/* Copyright © 2019-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const gubu_1 = require("gubu"); | ||
const meta_1 = require("./meta"); | ||
const common_1 = require("./common"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const ActArgu = Argu('act', { | ||
props: (0, gubu_1.One)((0, gubu_1.Empty)(String), Object), | ||
moreprops: (0, gubu_1.Skip)(Object), | ||
reply: (0, gubu_1.Skip)(Function), | ||
}); | ||
// Perform an action and optionally return the result by callback. | ||
@@ -12,3 +19,8 @@ // The properties of the combined arguments are matched against known | ||
const opts = instance.options(); | ||
const spec = (0, common_1.build_message)(instance, [...arguments], 'reply:f?', instance.fixedargs); | ||
const spec = | ||
// build_message(instance, [...arguments], 'reply:f?', instance.fixedargs) | ||
ActArgu(arguments); | ||
spec.msg = Object.assign({}, spec.moreprops ? spec.moreprops : null, 'string' === typeof spec.props ? | ||
(0, common_1.parse_jsonic)(spec.props, 'msg_jsonic_syntax') : | ||
spec.props, instance.fixedargs); | ||
const msg = spec.msg; | ||
@@ -15,0 +27,0 @@ const reply = spec.reply; |
@@ -1,4 +0,6 @@ | ||
/* Copyright © 2019-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
import { Gubu, MakeArgu, Open, Skip, One, Empty } from 'gubu' | ||
import { Meta } from './meta' | ||
@@ -8,3 +10,3 @@ | ||
import { | ||
build_message, | ||
// build_message, | ||
inspect, | ||
@@ -17,5 +19,16 @@ noop, | ||
make_standard_act_log_entry, | ||
parse_jsonic, | ||
} from './common' | ||
const Argu = MakeArgu('seneca') | ||
const ActArgu: any = Argu('act', { | ||
props: One(Empty(String), Object), | ||
moreprops: Skip(Object), | ||
reply: Skip(Function), | ||
}) | ||
// Perform an action and optionally return the result by callback. | ||
@@ -29,3 +42,14 @@ // The properties of the combined arguments are matched against known | ||
const spec = | ||
build_message(instance, [...arguments], 'reply:f?', instance.fixedargs) | ||
// build_message(instance, [...arguments], 'reply:f?', instance.fixedargs) | ||
ActArgu(arguments) | ||
spec.msg = Object.assign( | ||
{}, | ||
spec.moreprops ? spec.moreprops : null, | ||
'string' === typeof spec.props ? | ||
parse_jsonic(spec.props, 'msg_jsonic_syntax') : | ||
spec.props, | ||
instance.fixedargs, | ||
) | ||
const msg = spec.msg | ||
@@ -32,0 +56,0 @@ const reply = spec.reply |
@@ -23,9 +23,10 @@ "use strict"; | ||
exports.addActions = addActions; | ||
function cmd_ping(msg, reply) { | ||
reply(this.ping()); | ||
function cmd_ping(_msg, reply) { | ||
let ping = this.ping(); | ||
reply(ping); | ||
} | ||
function action_seneca_fatal(msg, reply) { | ||
function action_seneca_fatal(_msg, reply) { | ||
reply(); | ||
} | ||
function action_seneca_close(msg, reply) { | ||
function action_seneca_close(_msg, reply) { | ||
this.emit('close'); | ||
@@ -32,0 +33,0 @@ reply(); |
@@ -33,11 +33,15 @@ /* Copyright © 2014-2022 Richard Rodger and other contributors, MIT License. */ | ||
function cmd_ping(this: any, msg: any, reply: any) { | ||
reply(this.ping()) | ||
function cmd_ping(this: any, _msg: any, reply: any) { | ||
let ping = this.ping() | ||
reply(ping) | ||
} | ||
function action_seneca_fatal(this: any, msg: any, reply: any) { | ||
function action_seneca_fatal(this: any, _msg: any, reply: any) { | ||
reply() | ||
} | ||
function action_seneca_close(this: any, msg: any, reply: any) { | ||
function action_seneca_close(this: any, _msg: any, reply: any) { | ||
this.emit('close') | ||
@@ -47,2 +51,3 @@ reply() | ||
function make_action_seneca_stats(private$: any) { | ||
@@ -49,0 +54,0 @@ return function action_seneca_stats(this: any, msg: any, reply: any) { |
"use strict"; | ||
/* Copyright © 2019-2021 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,6 +7,17 @@ exports.task = exports.api_add = void 0; | ||
const common_1 = require("./common"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const AddArgu = Argu('add', { | ||
props: (0, gubu_1.One)((0, gubu_1.Empty)(String), Object), | ||
moreprops: (0, gubu_1.Skip)(Object), | ||
action: (0, gubu_1.Skip)(Function), | ||
actdef: (0, gubu_1.Skip)(Object), | ||
}); | ||
function api_add() { | ||
let args = AddArgu(arguments); | ||
args.pattern = Object.assign({}, args.moreprops ? args.moreprops : null, 'string' === typeof args.props ? | ||
(0, common_1.parse_jsonic)(args.props, 'add_string_pattern_syntax') : | ||
args.props); | ||
let ctx = { | ||
opts: this.options(), | ||
args: (0, common_1.parsePattern)(this, arguments, 'action:f? actdef:o?'), | ||
args, | ||
private: this.private$, | ||
@@ -34,3 +45,2 @@ instance: this, | ||
let raw_pattern = args.pattern; | ||
// console.log('ADD TRANSLATE', raw_pattern) | ||
let pattern = null; | ||
@@ -37,0 +47,0 @@ if (false !== raw_pattern.translate$) { |
@@ -1,2 +0,2 @@ | ||
/* Copyright © 2019-2021 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
@@ -6,6 +6,5 @@ | ||
import { Gubu, Open } from 'gubu' | ||
import { Gubu, MakeArgu, Open, Skip, One, Empty } from 'gubu' | ||
import { | ||
@@ -15,4 +14,4 @@ clean, | ||
each, | ||
parsePattern, | ||
pattern, | ||
parse_jsonic, | ||
} from './common' | ||
@@ -22,9 +21,27 @@ | ||
const Argu = MakeArgu('seneca') | ||
const AddArgu: any = Argu('add', { | ||
props: One(Empty(String), Object), | ||
moreprops: Skip(Object), | ||
action: Skip(Function), | ||
actdef: Skip(Object), | ||
}) | ||
function api_add(this: any) { | ||
let args = AddArgu(arguments) | ||
args.pattern = Object.assign( | ||
{}, | ||
args.moreprops ? args.moreprops : null, | ||
'string' === typeof args.props ? | ||
parse_jsonic(args.props, 'add_string_pattern_syntax') : | ||
args.props, | ||
) | ||
let ctx = { | ||
opts: this.options(), | ||
args: parsePattern(this, arguments, 'action:f? actdef:o?'), | ||
args, | ||
private: this.private$, | ||
@@ -57,4 +74,2 @@ instance: this, | ||
// console.log('ADD TRANSLATE', raw_pattern) | ||
let pattern = null | ||
@@ -61,0 +76,0 @@ |
222
lib/api.js
@@ -5,8 +5,9 @@ "use strict"; | ||
exports.API = void 0; | ||
const Norma = require('norma'); | ||
const gubu_1 = require("gubu"); | ||
const common_1 = require("./common"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const errlog = common_1.make_standard_err_log_entry; | ||
const intern = {}; | ||
function wrap(pin, actdef, wrapper) { | ||
var pinthis = this; | ||
const pinthis = this; | ||
wrapper = 'function' === typeof actdef ? actdef : wrapper; | ||
@@ -23,6 +24,7 @@ actdef = 'function' === typeof actdef ? {} : actdef; | ||
function fix(patargs, msgargs, custom) { | ||
var self = this; | ||
const self = this; | ||
patargs = self.util.Jsonic(patargs || {}); | ||
var fix_delegate = self.delegate(patargs); | ||
const fix_delegate = self.delegate(patargs); | ||
// TODO: attach msgargs and custom to delegate.private$ in some way for debugging | ||
// TODO: this is very brittle. Use a directive instead. | ||
fix_delegate.add = function fix_add() { | ||
@@ -37,4 +39,4 @@ return self.add.apply(this, intern.fix_args(arguments, patargs, msgargs, custom)); | ||
function options(options, chain) { | ||
var self = this; | ||
var private$ = self.private$; | ||
const self = this; | ||
const private$ = self.private$; | ||
if (null == options) { | ||
@@ -51,5 +53,5 @@ return private$.optioner.get(); | ||
} | ||
var out_opts = (private$.exports.options = private$.optioner.set(options)); | ||
let out_opts = (private$.exports.options = private$.optioner.set(options)); | ||
if ('string' === typeof options.tag) { | ||
var oldtag = self.root.tag; | ||
const oldtag = self.root.tag; | ||
self.root.tag = options.tag; | ||
@@ -63,3 +65,3 @@ self.root.id = | ||
if (options.log) { | ||
var logspec = private$.logging.build_log(self); | ||
const logspec = private$.logging.build_log(self); | ||
out_opts = private$.exports.options = private$.optioner.set({ | ||
@@ -76,3 +78,3 @@ log: logspec, | ||
if (options && options.log && Array.isArray(options.log.map)) { | ||
for (var i = 0; i < options.log.map.length; ++i) { | ||
for (let i = 0; i < options.log.map.length; ++i) { | ||
self.logroute(options.log.map[i]); | ||
@@ -91,3 +93,3 @@ } | ||
return function api_close(done) { | ||
var seneca = this; | ||
const seneca = this; | ||
if (false !== done && null == done) { | ||
@@ -112,3 +114,3 @@ return (0, common_1.promiser)(intern.close.bind(seneca, callpoint)); | ||
else if (false === toggle) { | ||
var out = this.private$.explain; | ||
const out = this.private$.explain; | ||
delete this.private$.explain; | ||
@@ -128,14 +130,14 @@ return out; | ||
} | ||
var plugin_fullname = this.fixedargs && this.fixedargs.plugin$ && this.fixedargs.plugin$.full; | ||
var plugin = null != plugin_fullname | ||
const plugin_fullname = this.fixedargs && this.fixedargs.plugin$ && this.fixedargs.plugin$.full; | ||
const plugin = null != plugin_fullname | ||
? this.private$.plugins[plugin_fullname] | ||
: this.context.plugin; | ||
var error = null; | ||
let err = null; | ||
if (plugin && plugin.eraro && plugin.eraro.has(first)) { | ||
error = plugin.eraro.apply(this, arguments); | ||
err = plugin.eraro.apply(this, arguments); | ||
} | ||
else { | ||
error = common_1.error.apply(this, arguments); | ||
err = common_1.error.apply(this, arguments); | ||
} | ||
return error; | ||
return err; | ||
} | ||
@@ -169,5 +171,3 @@ } | ||
function inward() { | ||
// TODO: norma should support f/x where x = # args | ||
var args = Norma('inward:f', arguments); | ||
// this.private$.inward.add(args.inward) | ||
const args = Argu(arguments, { inward: Function }); | ||
this.root.order.inward.add(args.inward); | ||
@@ -177,4 +177,3 @@ return this; | ||
function outward() { | ||
var args = Norma('outward:f', arguments); | ||
// this.private$.outward.add(args.outward) | ||
const args = Argu(arguments, { outward: Function }); | ||
this.root.order.outward.add(args.outward); | ||
@@ -185,8 +184,8 @@ return this; | ||
function delegate(fixedargs, fixedmeta) { | ||
var self = this; | ||
var root = this.root; | ||
var opts = this.options(); | ||
const self = this; | ||
const root = this.root; | ||
const opts = this.options(); | ||
fixedargs = fixedargs || {}; | ||
fixedmeta = fixedmeta || {}; | ||
var delegate = Object.create(self); | ||
const delegate = Object.create(self); | ||
delegate.private$ = Object.create(self.private$); | ||
@@ -200,9 +199,9 @@ delegate.did = | ||
delegate_log.self = () => delegate; | ||
var strdesc; | ||
let strdesc; | ||
function delegate_toString() { | ||
if (strdesc) | ||
return strdesc; | ||
var vfa = {}; | ||
const vfa = {}; | ||
Object.keys(fixedargs).forEach((k) => { | ||
var v = fixedargs[k]; | ||
const v = fixedargs[k]; | ||
if (~k.indexOf('$')) | ||
@@ -217,11 +216,11 @@ return; | ||
} | ||
var delegate_fixedargs = opts.strict.fixedargs | ||
const delegate_fixedargs = opts.strict.fixedargs | ||
? Object.assign({}, fixedargs, self.fixedargs) | ||
: Object.assign({}, self.fixedargs, fixedargs); | ||
var delegate_fixedmeta = opts.strict.fixedmeta | ||
const delegate_fixedmeta = opts.strict.fixedmeta | ||
? Object.assign({}, fixedmeta, self.fixedmeta) | ||
: Object.assign({}, self.fixedmeta, fixedmeta); | ||
function delegate_delegate(further_fixedargs, further_fixedmeta) { | ||
var args = Object.assign({}, delegate.fixedargs, further_fixedargs || {}); | ||
var meta = Object.assign({}, delegate.fixedmeta, further_fixedmeta || {}); | ||
const args = Object.assign({}, delegate.fixedargs, further_fixedargs || {}); | ||
const meta = Object.assign({}, delegate.fixedmeta, further_fixedmeta || {}); | ||
return self.delegate.call(this, args, meta); | ||
@@ -231,3 +230,3 @@ } | ||
// For example, data for individual web requests. | ||
var delegate_context = Object.assign({}, self.context); | ||
const delegate_context = Object.assign({}, self.context); | ||
// Prevents incorrect prototype properties in mocha test contexts | ||
@@ -246,9 +245,13 @@ Object.defineProperties(delegate, { | ||
function depends() { | ||
var self = this; | ||
var private$ = this.private$; | ||
var error = this.util.error; | ||
var args = Norma('{pluginname:s deps:a? moredeps:s*}', arguments); | ||
var deps = args.deps || args.moredeps || []; | ||
for (var i = 0; i < deps.length; i++) { | ||
var depname = deps[i]; | ||
const self = this; | ||
const private$ = this.private$; | ||
const error = this.util.error; | ||
const args = Argu(arguments, { | ||
pluginname: String, | ||
deps: (0, gubu_1.Skip)([String]), | ||
moredeps: (0, gubu_1.Rest)(String), | ||
}); | ||
const deps = args.deps || args.moredeps || []; | ||
for (let i = 0; i < deps.length; i++) { | ||
const depname = deps[i]; | ||
if (!private$.plugin_order.byname.includes(depname) && | ||
@@ -265,6 +268,6 @@ !private$.plugin_order.byname.includes('seneca-' + depname)) { | ||
function export$(key) { | ||
var self = this; | ||
var private$ = this.private$; | ||
var error = this.util.error; | ||
var opts = this.options(); | ||
const self = this; | ||
const private$ = this.private$; | ||
const error = this.util.error; | ||
const opts = this.options(); | ||
// Legacy aliases | ||
@@ -274,3 +277,3 @@ if (key === 'util') { | ||
} | ||
var exportval = private$.exports[key]; | ||
const exportval = private$.exports[key]; | ||
if (!exportval && opts.strict.exports) { | ||
@@ -283,3 +286,3 @@ return self.die(error('export_not_found', { key: key })); | ||
flags = flags || {}; | ||
var quiet_opts = { | ||
const quiet_opts = { | ||
test: false, | ||
@@ -290,3 +293,3 @@ quiet: true, | ||
}; | ||
var opts = this.options(quiet_opts); | ||
const opts = this.options(quiet_opts); | ||
// An override from env or args is possible. | ||
@@ -303,3 +306,3 @@ // Only flip to test mode if called from test() method | ||
function test(errhandler, logspec) { | ||
var opts = this.options(); | ||
const opts = this.options(); | ||
if ('-' != opts.tag) { | ||
@@ -316,3 +319,3 @@ this.root.id = | ||
logspec = true === logspec || 'true' === logspec ? 'test' : logspec; | ||
var test_opts = { | ||
const test_opts = { | ||
errhandler: null == errhandler ? null : errhandler, | ||
@@ -325,3 +328,3 @@ test: true, | ||
}; | ||
var set_opts = this.options(test_opts); | ||
const set_opts = this.options(test_opts); | ||
// An override from env or args is possible. | ||
@@ -342,3 +345,3 @@ if (set_opts.quiet) { | ||
function ping() { | ||
var now = Date.now(); | ||
const now = Date.now(); | ||
return { | ||
@@ -401,7 +404,4 @@ now: now, | ||
this.private$.translationrouter.add(from, translate); | ||
// console.log('TTT', translate({ c: 3, q: 9 })) | ||
// console.log(this.private$.translationrouter + '') | ||
let translation_action = function (msg, reply) { | ||
let transmsg = translate(msg); | ||
// console.log('ACT T', msg, transmsg) | ||
this.act(transmsg, reply); | ||
@@ -428,7 +428,7 @@ }; | ||
function find_plugin(plugindesc, tag) { | ||
var plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
const plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
return this.private$.plugins[plugin_key]; | ||
} | ||
function has_plugin(plugindesc, tag) { | ||
var plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
const plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
return !!this.private$.plugins[plugin_key]; | ||
@@ -441,4 +441,4 @@ } | ||
} | ||
var plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
var resolved_ignore = (this.private$.ignore_plugins[plugin_key] = | ||
const plugin_key = (0, common_1.make_plugin_key)(plugindesc, tag); | ||
const resolved_ignore = (this.private$.ignore_plugins[plugin_key] = | ||
null == ignore ? true : !!ignore); | ||
@@ -455,7 +455,7 @@ this.log.info({ | ||
function find(pattern, flags) { | ||
var seneca = this; | ||
var pat = 'string' === typeof pattern ? seneca.util.Jsonic(pattern) : pattern; | ||
const seneca = this; | ||
let pat = 'string' === typeof pattern ? seneca.util.Jsonic(pattern) : pattern; | ||
pat = seneca.util.clean(pat); | ||
pat = pat || {}; | ||
var actdef = seneca.private$.actrouter.find(pat, flags && flags.exact); | ||
let actdef = seneca.private$.actrouter.find(pat, flags && flags.exact); | ||
if (!actdef) { | ||
@@ -479,5 +479,5 @@ actdef = seneca.private$.actrouter.find({}); | ||
flags = flags || {}; | ||
var hist = this.private$.history.stats(); | ||
const hist = this.private$.history.stats(); | ||
hist.log = this.private$.history.list(); | ||
var status = { | ||
const status = { | ||
stats: this.stats(flags.stats), | ||
@@ -492,4 +492,4 @@ history: hist, | ||
function reply(spec) { | ||
var instance = this; | ||
var actctxt = null; | ||
const instance = this; | ||
let actctxt = null; | ||
if (spec && spec.meta) { | ||
@@ -506,5 +506,5 @@ actctxt = instance.private$.history.get(spec.meta.id); | ||
return function api_listen(...argsarr) { | ||
var private$ = this.private$; | ||
var self = this; | ||
var done = argsarr[argsarr.length - 1]; | ||
const private$ = this.private$; | ||
const self = this; | ||
let done = argsarr[argsarr.length - 1]; | ||
if (typeof done === 'function') { | ||
@@ -522,4 +522,4 @@ argsarr.pop(); | ||
}); | ||
var opts = self.options().transport || {}; | ||
var config = intern.resolve_config(intern.parse_config(argsarr), opts); | ||
const opts = self.options().transport || {}; | ||
const config = intern.resolve_config(intern.parse_config(argsarr), opts); | ||
self.act('role:transport,cmd:listen', { config: config, gate$: true }, function (err, result) { | ||
@@ -538,5 +538,5 @@ if (err) { | ||
return function api_client() { | ||
var private$ = this.private$; | ||
var argsarr = Array.prototype.slice.call(arguments); | ||
var self = this; | ||
const private$ = this.private$; | ||
const argsarr = Array.prototype.slice.call(arguments); | ||
const self = this; | ||
self.log.info({ | ||
@@ -548,10 +548,10 @@ kind: 'client', | ||
}); | ||
var legacy = self.options().legacy || {}; | ||
var opts = self.options().transport || {}; | ||
var raw_config = intern.parse_config(argsarr); | ||
const legacy = self.options().legacy || {}; | ||
const opts = self.options().transport || {}; | ||
const raw_config = intern.parse_config(argsarr); | ||
// pg: pin group | ||
raw_config.pg = (0, common_1.pincanon)(raw_config.pin || raw_config.pins); | ||
var config = intern.resolve_config(raw_config, opts); | ||
const config = intern.resolve_config(raw_config, opts); | ||
config.id = config.id || (0, common_1.pattern)(raw_config); | ||
var pins = config.pins || | ||
let pins = config.pins || | ||
(Array.isArray(config.pin) ? config.pin : [config.pin || '']); | ||
@@ -564,3 +564,3 @@ pins = pins.map((pin) => { | ||
// ... but is this necessary at all? | ||
var task_res = self.order.plugin.task.delegate.exec({ | ||
const task_res = self.order.plugin.task.delegate.exec({ | ||
ctx: { | ||
@@ -577,5 +577,5 @@ seneca: self, | ||
}); | ||
var sd = task_res.out.delegate; | ||
var sendclient; | ||
var transport_client = function transport_client(msg, reply, meta) { | ||
const sd = task_res.out.delegate; | ||
let sendclient; | ||
const transport_client = function transport_client(msg, reply, meta) { | ||
if (legacy.meta) { | ||
@@ -627,15 +627,14 @@ meta = meta || msg.meta$; | ||
} | ||
// Inspired by https://github.com/hapijs/hapi/blob/master/lib/plugin.js decorate | ||
// TODO: convert to plugin configuration, with standard errors | ||
function decorate() { | ||
var args = Norma('property:s value:.', arguments); | ||
var property = args.property; | ||
if ('_' === property[0]) { | ||
throw new Error('property cannot start with _'); | ||
} | ||
let args = Argu(arguments, { | ||
property: (0, gubu_1.Check)(/^[^_]/, String) | ||
.Fault('Decorate property cannot start with underscore (was $VALUE)'), | ||
value: (0, gubu_1.Any)() | ||
}); | ||
let property = args.property; | ||
if (this.private$.decorations[property]) { | ||
throw new Error('seneca is already decorated with the property: ' + property); | ||
throw new Error('seneca: Decoration already exists: ' + property); | ||
} | ||
if (this.root[property]) { | ||
throw new Error('cannot override a core seneca property: ' + property); | ||
throw new Error('seneca: Decoration overrides core property:' + property); | ||
} | ||
@@ -645,5 +644,5 @@ this.root[property] = this.private$.decorations[property] = args.value; | ||
intern.parse_config = function (args) { | ||
var out = {}; | ||
var config = args.filter((x) => null != x); | ||
var arglen = config.length; | ||
let out = {}; | ||
const config = args.filter((x) => null != x); | ||
const arglen = config.length; | ||
// TODO: use Joi for better error msgs | ||
@@ -670,5 +669,5 @@ if (arglen === 1) { | ||
intern.resolve_config = function (config, options) { | ||
var out = Object.assign({}, config); | ||
let out = Object.assign({}, config); | ||
Object.keys(options).forEach((key) => { | ||
var value = options[key]; | ||
const value = options[key]; | ||
if (value && 'object' === typeof value) { | ||
@@ -685,3 +684,3 @@ return; | ||
} | ||
var base = options[out.type] || {}; | ||
const base = options[out.type] || {}; | ||
out = Object.assign({}, base, out); | ||
@@ -696,6 +695,6 @@ if (out.type === 'web' || out.type === 'tcp') { | ||
intern.close = function (callpoint, done) { | ||
var seneca = this; | ||
var options = seneca.options(); | ||
var done_called = false; | ||
var safe_done = function safe_done(err) { | ||
const seneca = this; | ||
const options = seneca.options(); | ||
let done_called = false; | ||
const safe_done = function safe_done(err) { | ||
if (!done_called && 'function' === typeof done) { | ||
@@ -711,3 +710,3 @@ done_called = true; | ||
seneca.ready(do_close); | ||
var close_timeout = setTimeout(do_close, options.close_delay); | ||
const close_timeout = setTimeout(do_close, options.close_delay); | ||
function do_close() { | ||
@@ -751,6 +750,17 @@ clearTimeout(close_timeout); | ||
}; | ||
const FixArgu = Argu('fix', { | ||
props: (0, gubu_1.One)((0, gubu_1.Empty)(String), Object), | ||
moreprops: (0, gubu_1.Skip)(Object), | ||
rest: (0, gubu_1.Rest)((0, gubu_1.Any)()), | ||
}); | ||
// TODO; this should happen inside .add using a directive | ||
intern.fix_args = | ||
function (origargs, patargs, msgargs, custom) { | ||
var args = (0, common_1.parsePattern)(this, origargs, 'rest:.*', patargs); | ||
var fixargs = [args.pattern] | ||
// const args = parsePattern(this, origargs, { rest: Rest(Any()) }, patargs) | ||
// const args = parsePattern(this, origargs, 'rest:.*', patargs) | ||
const args = FixArgu(origargs); | ||
args.pattern = Object.assign({}, args.moreprops ? args.moreprops : null, 'string' === typeof args.props ? | ||
(0, common_1.parse_jsonic)(args.props, 'add_string_pattern_syntax') : | ||
args.props, patargs); | ||
const fixargs = [args.pattern] | ||
.concat({ | ||
@@ -757,0 +767,0 @@ fixed$: Object.assign({}, msgargs, args.pattern.fixed$), |
253
lib/api.ts
/* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
const Norma = require('norma') | ||
import { MakeArgu, Any, Check, Rest, Skip, One, Empty } from 'gubu' | ||
@@ -15,6 +15,10 @@ import { | ||
clean, | ||
parsePattern, | ||
// parsePattern, | ||
jsonic_stringify, | ||
parse_jsonic, | ||
} from './common' | ||
const Argu = MakeArgu('seneca') | ||
const errlog = make_standard_err_log_entry | ||
@@ -26,3 +30,3 @@ | ||
function wrap(this: any, pin: any, actdef: any, wrapper: any) { | ||
var pinthis = this | ||
const pinthis = this | ||
@@ -44,10 +48,11 @@ wrapper = 'function' === typeof actdef ? actdef : wrapper | ||
function fix(this: any, patargs: any, msgargs: any, custom: any) { | ||
var self = this | ||
const self = this | ||
patargs = self.util.Jsonic(patargs || {}) | ||
var fix_delegate = self.delegate(patargs) | ||
const fix_delegate = self.delegate(patargs) | ||
// TODO: attach msgargs and custom to delegate.private$ in some way for debugging | ||
// TODO: this is very brittle. Use a directive instead. | ||
fix_delegate.add = function fix_add() { | ||
@@ -72,4 +77,4 @@ return self.add.apply( | ||
function options(this: any, options: any, chain: any) { | ||
var self = this | ||
var private$ = self.private$ | ||
const self = this | ||
const private$ = self.private$ | ||
@@ -89,6 +94,6 @@ if (null == options) { | ||
var out_opts = (private$.exports.options = private$.optioner.set(options)) | ||
let out_opts = (private$.exports.options = private$.optioner.set(options)) | ||
if ('string' === typeof options.tag) { | ||
var oldtag = self.root.tag | ||
const oldtag = self.root.tag | ||
self.root.tag = options.tag | ||
@@ -103,3 +108,3 @@ self.root.id = | ||
if (options.log) { | ||
var logspec = private$.logging.build_log(self) | ||
const logspec = private$.logging.build_log(self) | ||
out_opts = private$.exports.options = private$.optioner.set({ | ||
@@ -118,3 +123,3 @@ log: logspec, | ||
if (options && options.log && Array.isArray(options.log.map)) { | ||
for (var i = 0; i < options.log.map.length; ++i) { | ||
for (let i = 0; i < options.log.map.length; ++i) { | ||
self.logroute(options.log.map[i]) | ||
@@ -136,3 +141,3 @@ } | ||
return function api_close(this: any, done: any) { | ||
var seneca = this | ||
const seneca = this | ||
@@ -164,3 +169,3 @@ if (false !== done && null == done) { | ||
} else if (false === toggle) { | ||
var out = this.private$.explain | ||
const out = this.private$.explain | ||
delete this.private$.explain | ||
@@ -177,3 +182,4 @@ return out | ||
return this | ||
} else { | ||
} | ||
else { | ||
if (null == first) { | ||
@@ -183,6 +189,6 @@ throw this.util.error('no_error_code') | ||
var plugin_fullname = | ||
const plugin_fullname = | ||
this.fixedargs && this.fixedargs.plugin$ && this.fixedargs.plugin$.full | ||
var plugin = | ||
const plugin = | ||
null != plugin_fullname | ||
@@ -192,13 +198,15 @@ ? this.private$.plugins[plugin_fullname] | ||
var error = null | ||
let err = null | ||
if (plugin && plugin.eraro && plugin.eraro.has(first)) { | ||
error = plugin.eraro.apply(this, arguments) | ||
} else { | ||
error = common_error.apply(this, arguments) | ||
err = plugin.eraro.apply(this, arguments) | ||
} | ||
else { | ||
err = common_error.apply(this, arguments) | ||
} | ||
return error | ||
return err | ||
} | ||
} | ||
// NOTE: plugin error codes are in their own namespaces | ||
@@ -237,5 +245,3 @@ function fail(this: any, ...args: any[]) { | ||
function inward(this: any) { | ||
// TODO: norma should support f/x where x = # args | ||
var args = Norma('inward:f', arguments) | ||
// this.private$.inward.add(args.inward) | ||
const args = Argu(arguments, { inward: Function }) | ||
this.root.order.inward.add(args.inward) | ||
@@ -247,4 +253,3 @@ return this | ||
function outward(this: any) { | ||
var args = Norma('outward:f', arguments) | ||
// this.private$.outward.add(args.outward) | ||
const args = Argu(arguments, { outward: Function }) | ||
this.root.order.outward.add(args.outward) | ||
@@ -257,5 +262,5 @@ return this | ||
function delegate(this: any, fixedargs: any, fixedmeta: any) { | ||
var self = this | ||
var root = this.root | ||
var opts = this.options() | ||
const self = this | ||
const root = this.root | ||
const opts = this.options() | ||
@@ -265,3 +270,3 @@ fixedargs = fixedargs || {} | ||
var delegate = Object.create(self) | ||
const delegate = Object.create(self) | ||
@@ -280,9 +285,9 @@ delegate.private$ = Object.create(self.private$) | ||
var strdesc: any | ||
let strdesc: any | ||
function delegate_toString() { | ||
if (strdesc) return strdesc | ||
var vfa: any = {} | ||
const vfa: any = {} | ||
Object.keys(fixedargs).forEach((k) => { | ||
var v = fixedargs[k] | ||
const v = fixedargs[k] | ||
if (~k.indexOf('$')) return | ||
@@ -299,7 +304,7 @@ vfa[k] = v | ||
var delegate_fixedargs = opts.strict.fixedargs | ||
const delegate_fixedargs = opts.strict.fixedargs | ||
? Object.assign({}, fixedargs, self.fixedargs) | ||
: Object.assign({}, self.fixedargs, fixedargs) | ||
var delegate_fixedmeta = opts.strict.fixedmeta | ||
const delegate_fixedmeta = opts.strict.fixedmeta | ||
? Object.assign({}, fixedmeta, self.fixedmeta) | ||
@@ -313,4 +318,4 @@ : Object.assign({}, self.fixedmeta, fixedmeta) | ||
) { | ||
var args = Object.assign({}, delegate.fixedargs, further_fixedargs || {}) | ||
var meta = Object.assign({}, delegate.fixedmeta, further_fixedmeta || {}) | ||
const args = Object.assign({}, delegate.fixedargs, further_fixedargs || {}) | ||
const meta = Object.assign({}, delegate.fixedmeta, further_fixedmeta || {}) | ||
return self.delegate.call(this, args, meta) | ||
@@ -321,3 +326,3 @@ } | ||
// For example, data for individual web requests. | ||
var delegate_context = Object.assign({}, self.context) | ||
const delegate_context = Object.assign({}, self.context) | ||
@@ -340,12 +345,17 @@ // Prevents incorrect prototype properties in mocha test contexts | ||
function depends(this: any) { | ||
var self = this | ||
var private$ = this.private$ | ||
var error = this.util.error | ||
var args = Norma('{pluginname:s deps:a? moredeps:s*}', arguments) | ||
const self = this | ||
const private$ = this.private$ | ||
const error = this.util.error | ||
var deps = args.deps || args.moredeps || [] | ||
const args = Argu(arguments, { | ||
pluginname: String, | ||
deps: Skip([String]), | ||
moredeps: Rest(String), | ||
}) | ||
for (var i = 0; i < deps.length; i++) { | ||
var depname = deps[i] | ||
const deps = args.deps || args.moredeps || [] | ||
for (let i = 0; i < deps.length; i++) { | ||
const depname = deps[i] | ||
if ( | ||
@@ -368,6 +378,6 @@ !private$.plugin_order.byname.includes(depname) && | ||
function export$(this: any, key: any) { | ||
var self = this | ||
var private$ = this.private$ | ||
var error = this.util.error | ||
var opts = this.options() | ||
const self = this | ||
const private$ = this.private$ | ||
const error = this.util.error | ||
const opts = this.options() | ||
@@ -379,3 +389,3 @@ // Legacy aliases | ||
var exportval = private$.exports[key] | ||
const exportval = private$.exports[key] | ||
@@ -393,3 +403,3 @@ if (!exportval && opts.strict.exports) { | ||
var quiet_opts = { | ||
const quiet_opts = { | ||
test: false, | ||
@@ -401,3 +411,3 @@ quiet: true, | ||
var opts = this.options(quiet_opts) | ||
const opts = this.options(quiet_opts) | ||
@@ -417,3 +427,3 @@ // An override from env or args is possible. | ||
function test(this: any, errhandler: any, logspec: any) { | ||
var opts = this.options() | ||
const opts = this.options() | ||
@@ -434,3 +444,3 @@ if ('-' != opts.tag) { | ||
var test_opts = { | ||
const test_opts = { | ||
errhandler: null == errhandler ? null : errhandler, | ||
@@ -444,3 +454,3 @@ test: true, | ||
var set_opts = this.options(test_opts) | ||
const set_opts = this.options(test_opts) | ||
@@ -465,3 +475,3 @@ // An override from env or args is possible. | ||
function ping(this: any) { | ||
var now = Date.now() | ||
const now = Date.now() | ||
return { | ||
@@ -541,8 +551,4 @@ now: now, | ||
// console.log('TTT', translate({ c: 3, q: 9 })) | ||
// console.log(this.private$.translationrouter + '') | ||
let translation_action = function(this: any, msg: any, reply: any) { | ||
let transmsg = translate(msg) | ||
// console.log('ACT T', msg, transmsg) | ||
this.act(transmsg, reply) | ||
@@ -580,3 +586,3 @@ } | ||
function find_plugin(this: any, plugindesc: any, tag: any) { | ||
var plugin_key = make_plugin_key(plugindesc, tag) | ||
const plugin_key = make_plugin_key(plugindesc, tag) | ||
return this.private$.plugins[plugin_key] | ||
@@ -587,3 +593,3 @@ } | ||
function has_plugin(this: any, plugindesc: any, tag: any) { | ||
var plugin_key = make_plugin_key(plugindesc, tag) | ||
const plugin_key = make_plugin_key(plugindesc, tag) | ||
return !!this.private$.plugins[plugin_key] | ||
@@ -598,4 +604,4 @@ } | ||
} | ||
var plugin_key = make_plugin_key(plugindesc, tag) | ||
var resolved_ignore = (this.private$.ignore_plugins[plugin_key] = | ||
const plugin_key = make_plugin_key(plugindesc, tag) | ||
const resolved_ignore = (this.private$.ignore_plugins[plugin_key] = | ||
null == ignore ? true : !!ignore) | ||
@@ -616,9 +622,9 @@ | ||
function find(this: any, pattern: any, flags: any) { | ||
var seneca = this | ||
const seneca = this | ||
var pat = 'string' === typeof pattern ? seneca.util.Jsonic(pattern) : pattern | ||
let pat = 'string' === typeof pattern ? seneca.util.Jsonic(pattern) : pattern | ||
pat = seneca.util.clean(pat) | ||
pat = pat || {} | ||
var actdef = seneca.private$.actrouter.find(pat, flags && flags.exact) | ||
let actdef = seneca.private$.actrouter.find(pat, flags && flags.exact) | ||
@@ -651,6 +657,6 @@ if (!actdef) { | ||
var hist = this.private$.history.stats() | ||
const hist = this.private$.history.stats() | ||
hist.log = this.private$.history.list() | ||
var status = { | ||
const status = { | ||
stats: this.stats(flags.stats), | ||
@@ -668,4 +674,4 @@ history: hist, | ||
function reply(this: any, spec: any) { | ||
var instance = this | ||
var actctxt = null | ||
const instance = this | ||
let actctxt = null | ||
@@ -686,9 +692,10 @@ if (spec && spec.meta) { | ||
return function api_listen(this: any, ...argsarr: any[]) { | ||
var private$ = this.private$ | ||
var self = this | ||
const private$ = this.private$ | ||
const self = this | ||
var done = argsarr[argsarr.length - 1] | ||
let done = argsarr[argsarr.length - 1] | ||
if (typeof done === 'function') { | ||
argsarr.pop() | ||
} else { | ||
} | ||
else { | ||
done = () => { } | ||
@@ -704,4 +711,4 @@ } | ||
var opts = self.options().transport || {} | ||
var config = intern.resolve_config(intern.parse_config(argsarr), opts) | ||
const opts = self.options().transport || {} | ||
const config = intern.resolve_config(intern.parse_config(argsarr), opts) | ||
@@ -729,5 +736,5 @@ self.act( | ||
return function api_client(this: any) { | ||
var private$ = this.private$ | ||
var argsarr = Array.prototype.slice.call(arguments) | ||
var self = this | ||
const private$ = this.private$ | ||
const argsarr = Array.prototype.slice.call(arguments) | ||
const self = this | ||
@@ -741,6 +748,6 @@ self.log.info({ | ||
var legacy = self.options().legacy || {} | ||
var opts = self.options().transport || {} | ||
const legacy = self.options().legacy || {} | ||
const opts = self.options().transport || {} | ||
var raw_config = intern.parse_config(argsarr) | ||
const raw_config = intern.parse_config(argsarr) | ||
@@ -750,7 +757,7 @@ // pg: pin group | ||
var config = intern.resolve_config(raw_config, opts) | ||
const config = intern.resolve_config(raw_config, opts) | ||
config.id = config.id || pattern(raw_config) | ||
var pins = | ||
let pins = | ||
config.pins || | ||
@@ -766,3 +773,3 @@ (Array.isArray(config.pin) ? config.pin : [config.pin || '']) | ||
// ... but is this necessary at all? | ||
var task_res = self.order.plugin.task.delegate.exec({ | ||
const task_res = self.order.plugin.task.delegate.exec({ | ||
ctx: { | ||
@@ -780,7 +787,7 @@ seneca: self, | ||
var sd = task_res.out.delegate | ||
const sd = task_res.out.delegate | ||
var sendclient: any | ||
let sendclient: any | ||
var transport_client: any = | ||
const transport_client: any = | ||
function transport_client(this: any, msg: any, reply: any, meta: any) { | ||
@@ -855,16 +862,16 @@ if (legacy.meta) { | ||
// Inspired by https://github.com/hapijs/hapi/blob/master/lib/plugin.js decorate | ||
// TODO: convert to plugin configuration, with standard errors | ||
function decorate(this: any) { | ||
var args = Norma('property:s value:.', arguments) | ||
let args = Argu(arguments, { | ||
property: Check(/^[^_]/, String) | ||
.Fault('Decorate property cannot start with underscore (was $VALUE)'), | ||
value: Any() | ||
}) | ||
var property = args.property | ||
if ('_' === property[0]) { | ||
throw new Error('property cannot start with _') | ||
} | ||
let property = args.property | ||
if (this.private$.decorations[property]) { | ||
throw new Error('seneca is already decorated with the property: ' + property) | ||
throw new Error('seneca: Decoration already exists: ' + property) | ||
} | ||
if (this.root[property]) { | ||
throw new Error('cannot override a core seneca property: ' + property) | ||
throw new Error('seneca: Decoration overrides core property:' + property) | ||
} | ||
@@ -876,8 +883,9 @@ | ||
intern.parse_config = function(args: any) { | ||
var out: any = {} | ||
let out: any = {} | ||
var config = args.filter((x: any) => null != x) | ||
const config = args.filter((x: any) => null != x) | ||
var arglen = config.length | ||
const arglen = config.length | ||
@@ -906,6 +914,6 @@ // TODO: use Joi for better error msgs | ||
intern.resolve_config = function(config: any, options: any) { | ||
var out = Object.assign({}, config) | ||
let out = Object.assign({}, config) | ||
Object.keys(options).forEach((key) => { | ||
var value = options[key] | ||
const value = options[key] | ||
if (value && 'object' === typeof value) { | ||
@@ -925,3 +933,3 @@ return | ||
var base = options[out.type] || {} | ||
const base = options[out.type] || {} | ||
@@ -941,7 +949,7 @@ out = Object.assign({}, base, out) | ||
intern.close = function(this: any, callpoint: any, done: any) { | ||
var seneca = this | ||
var options = seneca.options() | ||
const seneca = this | ||
const options = seneca.options() | ||
var done_called = false | ||
var safe_done: any = function safe_done(err: any) { | ||
let done_called = false | ||
const safe_done: any = function safe_done(err: any) { | ||
if (!done_called && 'function' === typeof done) { | ||
@@ -959,3 +967,3 @@ done_called = true | ||
seneca.ready(do_close) | ||
var close_timeout = setTimeout(do_close, options.close_delay) | ||
const close_timeout = setTimeout(do_close, options.close_delay) | ||
@@ -1013,6 +1021,28 @@ function do_close() { | ||
const FixArgu: any = Argu('fix', { | ||
props: One(Empty(String), Object), | ||
moreprops: Skip(Object), | ||
rest: Rest(Any()), | ||
}) | ||
// TODO; this should happen inside .add using a directive | ||
intern.fix_args = | ||
function(this: any, origargs: any, patargs: any, msgargs: any, custom: any) { | ||
var args = parsePattern(this, origargs, 'rest:.*', patargs) | ||
var fixargs = [args.pattern] | ||
// const args = parsePattern(this, origargs, { rest: Rest(Any()) }, patargs) | ||
// const args = parsePattern(this, origargs, 'rest:.*', patargs) | ||
const args = FixArgu(origargs) | ||
args.pattern = Object.assign( | ||
{}, | ||
args.moreprops ? args.moreprops : null, | ||
'string' === typeof args.props ? | ||
parse_jsonic(args.props, 'add_string_pattern_syntax') : | ||
args.props, | ||
patargs, | ||
) | ||
const fixargs = [args.pattern] | ||
.concat({ | ||
@@ -1023,2 +1053,3 @@ fixed$: Object.assign({}, msgargs, args.pattern.fixed$), | ||
.concat(args.rest) | ||
return fixargs | ||
@@ -1025,0 +1056,0 @@ } |
@@ -11,5 +11,2 @@ /// <reference types="node" /> | ||
declare function parse_jsonic(str: any, code: any): any; | ||
declare function parse_pattern(_instance: any, rawargs: any, normaspec: any, fixed?: any): any; | ||
declare const parsePattern: typeof parse_pattern; | ||
declare function build_message(instance: any, rawargs: any, normaspec: any, fixed: any): any; | ||
declare function pattern(patobj: any): any; | ||
@@ -60,2 +57,2 @@ declare function pincanon(inpin: any): any; | ||
} | ||
export { promiser, stringify, wrap_error, make_plugin_key, boolify, parse_jsonic, parse_pattern, build_message, pattern, pincanon, noop, clean, deep, each, makedie, make_standard_act_log_entry, make_standard_err_log_entry, resolve_option, autoincr, make_callpoint, make_trace_desc, history, print, parsePattern, tagnid, inspect, error, msgstr, jsonic_stringify, TRACE_PATTERN, TRACE_ID, TRACE_INSTANCE, TRACE_TAG, TRACE_VERSION, TRACE_START, TRACE_END, TRACE_SYNC, TRACE_ACTION, }; | ||
export { promiser, stringify, wrap_error, make_plugin_key, boolify, parse_jsonic, pattern, pincanon, noop, clean, deep, each, makedie, make_standard_act_log_entry, make_standard_err_log_entry, resolve_option, autoincr, make_callpoint, make_trace_desc, history, print, tagnid, inspect, error, msgstr, jsonic_stringify, TRACE_PATTERN, TRACE_ID, TRACE_INSTANCE, TRACE_TAG, TRACE_VERSION, TRACE_START, TRACE_END, TRACE_SYNC, TRACE_ACTION, }; |
@@ -7,12 +7,12 @@ /* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TRACE_ACTION = exports.TRACE_SYNC = exports.TRACE_END = exports.TRACE_START = exports.TRACE_VERSION = exports.TRACE_TAG = exports.TRACE_INSTANCE = exports.TRACE_ID = exports.TRACE_PATTERN = exports.jsonic_stringify = exports.msgstr = exports.error = exports.inspect = exports.tagnid = exports.parsePattern = exports.print = exports.history = exports.make_trace_desc = exports.make_callpoint = exports.autoincr = exports.resolve_option = exports.make_standard_err_log_entry = exports.make_standard_act_log_entry = exports.makedie = exports.each = exports.deep = exports.clean = exports.noop = exports.pincanon = exports.pattern = exports.build_message = exports.parse_pattern = exports.parse_jsonic = exports.boolify = exports.make_plugin_key = exports.wrap_error = exports.stringify = exports.promiser = void 0; | ||
exports.TRACE_ACTION = exports.TRACE_SYNC = exports.TRACE_END = exports.TRACE_START = exports.TRACE_VERSION = exports.TRACE_TAG = exports.TRACE_INSTANCE = exports.TRACE_ID = exports.TRACE_PATTERN = exports.jsonic_stringify = exports.msgstr = exports.error = exports.inspect = exports.tagnid = exports.print = exports.history = exports.make_trace_desc = exports.make_callpoint = exports.autoincr = exports.resolve_option = exports.make_standard_err_log_entry = exports.make_standard_act_log_entry = exports.makedie = exports.each = exports.deep = exports.clean = exports.noop = exports.pincanon = exports.pattern = exports.parse_jsonic = exports.boolify = exports.make_plugin_key = exports.wrap_error = exports.stringify = exports.promiser = void 0; | ||
const util_1 = __importDefault(require("util")); | ||
const errors_1 = __importDefault(require("./errors")); | ||
const Stringify = require('fast-safe-stringify'); | ||
const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify")); | ||
const jsonic_next_1 = __importDefault(require("@jsonic/jsonic-next")); | ||
const nid_1 = __importDefault(require("nid")); | ||
const Eraro = require('eraro'); | ||
const Jsonic = require('@jsonic/jsonic-next'); | ||
const nid_1 = __importDefault(require("nid")); | ||
const Norma = require('norma'); | ||
const DefaultsDeep = require('lodash.defaultsdeep'); | ||
const { Print } = require('./print'); | ||
const errors_1 = __importDefault(require("./errors")); | ||
// const Argu = MakeArgu('seneca') | ||
const error = (exports.error = | ||
@@ -41,3 +41,3 @@ exports.eraro = | ||
function stringify() { | ||
return Stringify(...arguments); | ||
return fast_safe_stringify_1.default(...arguments); | ||
} | ||
@@ -102,3 +102,3 @@ exports.stringify = stringify; | ||
try { | ||
return null == str ? null : Jsonic(str); | ||
return null == str ? null : (0, jsonic_next_1.default)(str); | ||
} | ||
@@ -115,20 +115,2 @@ catch (e) { | ||
exports.parse_jsonic = parse_jsonic; | ||
// string args override object args | ||
// TODO: fix name | ||
function parse_pattern(_instance, rawargs, normaspec, fixed) { | ||
let args = Norma('{strargs:s? objargs:o? moreobjargs:o? ' + (normaspec || '') + '}', rawargs); | ||
// Precedence of arguments in add,act is left-to-right | ||
args.pattern = Object.assign({}, args.moreobjargs ? args.moreobjargs : null, args.objargs ? args.objargs : null, parse_jsonic(args.strargs, 'add_string_pattern_syntax'), fixed); | ||
return args; | ||
} | ||
exports.parse_pattern = parse_pattern; | ||
const parsePattern = parse_pattern; | ||
exports.parsePattern = parsePattern; | ||
function build_message(instance, rawargs, normaspec, fixed) { | ||
let args = Norma('{strargs:s? objargs:o? moreobjargs:o? ' + (normaspec || '') + '}', rawargs); | ||
// Precedence of arguments in add,act is left-to-right | ||
args.msg = Object.assign({}, args.moreobjargs, args.objargs, parse_jsonic(args.strargs, 'msg_jsonic_syntax'), fixed); | ||
return args; | ||
} | ||
exports.build_message = build_message; | ||
// Convert pattern object into a normalized jsonic String. | ||
@@ -153,3 +135,3 @@ function pattern(patobj) { | ||
if ('string' == typeof inpin) { | ||
return pattern(Jsonic(inpin)); | ||
return pattern((0, jsonic_next_1.default)(inpin)); | ||
} | ||
@@ -156,0 +138,0 @@ else if (Array.isArray(inpin)) { |
@@ -7,19 +7,17 @@ /* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
import Stringify from 'fast-safe-stringify' | ||
import Jsonic from '@jsonic/jsonic-next' | ||
import Nid from 'nid' | ||
import Errors from './errors' | ||
const Stringify = require('fast-safe-stringify') | ||
const Eraro = require('eraro') | ||
const Jsonic = require('@jsonic/jsonic-next') | ||
import Nid from 'nid' | ||
const Norma = require('norma') | ||
const DefaultsDeep = require('lodash.defaultsdeep') | ||
const { Print } = require('./print') | ||
import Errors from './errors' | ||
// const Argu = MakeArgu('seneca') | ||
const error = | ||
@@ -51,3 +49,3 @@ (exports.error = | ||
function stringify() { | ||
return Stringify(...arguments) | ||
return (Stringify as any)(...arguments) | ||
} | ||
@@ -137,54 +135,3 @@ | ||
// string args override object args | ||
// TODO: fix name | ||
function parse_pattern( | ||
_instance: any, | ||
rawargs: any, | ||
normaspec: any, | ||
fixed?: any | ||
) { | ||
let args = Norma( | ||
'{strargs:s? objargs:o? moreobjargs:o? ' + (normaspec || '') + '}', | ||
rawargs | ||
) | ||
// Precedence of arguments in add,act is left-to-right | ||
args.pattern = Object.assign( | ||
{}, | ||
args.moreobjargs ? args.moreobjargs : null, | ||
args.objargs ? args.objargs : null, | ||
parse_jsonic(args.strargs, 'add_string_pattern_syntax'), | ||
fixed | ||
) | ||
return args | ||
} | ||
const parsePattern = parse_pattern | ||
function build_message( | ||
instance: any, | ||
rawargs: any, | ||
normaspec: any, | ||
fixed: any | ||
) { | ||
let args = Norma( | ||
'{strargs:s? objargs:o? moreobjargs:o? ' + (normaspec || '') + '}', | ||
rawargs | ||
) | ||
// Precedence of arguments in add,act is left-to-right | ||
args.msg = Object.assign( | ||
{}, | ||
args.moreobjargs, | ||
args.objargs, | ||
parse_jsonic(args.strargs, 'msg_jsonic_syntax'), | ||
fixed | ||
) | ||
return args | ||
} | ||
// Convert pattern object into a normalized jsonic String. | ||
@@ -833,4 +780,4 @@ function pattern(patobj: any) { | ||
parse_jsonic, | ||
parse_pattern, | ||
build_message, | ||
// parse_pattern, | ||
// build_message, | ||
pattern, | ||
@@ -851,3 +798,3 @@ pincanon, | ||
print, | ||
parsePattern, | ||
// parsePattern, | ||
tagnid, | ||
@@ -854,0 +801,0 @@ inspect, |
@@ -82,2 +82,3 @@ declare function inward_msg_modify(spec: any): void; | ||
error: any; | ||
props: any; | ||
}; | ||
@@ -84,0 +85,0 @@ log: { |
"use strict"; | ||
/* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -186,2 +186,3 @@ exports.Inward = void 0; | ||
error: err, | ||
props: err.gubu ? err.props : [], | ||
}, | ||
@@ -188,0 +189,0 @@ log: { |
@@ -1,2 +0,2 @@ | ||
/* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
@@ -235,2 +235,3 @@ | ||
error: err, | ||
props: err.gubu ? err.props : [], | ||
}, | ||
@@ -237,0 +238,0 @@ log: { |
"use strict"; | ||
/* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -12,5 +12,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const Eraro = require('eraro'); | ||
const Norma = require('norma'); | ||
const Jsonic = require('@jsonic/jsonic-next'); | ||
const Common = require('./common'); | ||
const gubu_1 = require("gubu"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const internals = { | ||
@@ -155,3 +156,6 @@ error: Eraro({ | ||
var self = this; | ||
var args = Norma('{execute:b actargs:.*}', arguments); | ||
const args = Argu(arguments, { | ||
execute: Boolean, | ||
actargs: (0, gubu_1.Rest)((0, gubu_1.Any)()), | ||
}); | ||
if (args.execute) { | ||
@@ -158,0 +162,0 @@ return self.act.apply(self, args.actargs); |
@@ -1,2 +0,2 @@ | ||
/* Copyright © 2010-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
@@ -11,3 +11,2 @@ | ||
const Eraro = require('eraro') | ||
const Norma = require('norma') | ||
const Jsonic = require('@jsonic/jsonic-next') | ||
@@ -17,3 +16,7 @@ | ||
import { MakeArgu, Rest, Any } from 'gubu' | ||
const Argu = MakeArgu('seneca') | ||
const internals = { | ||
@@ -190,4 +193,8 @@ error: Eraro({ | ||
var self = this | ||
var args = Norma('{execute:b actargs:.*}', arguments) | ||
const args = Argu(arguments, { | ||
execute: Boolean, | ||
actargs: Rest(Any()), | ||
}) | ||
if (args.execute) { | ||
@@ -194,0 +201,0 @@ return self.act.apply(self, args.actargs) |
@@ -294,2 +294,4 @@ /* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
let argsarr = [...arguments]; | ||
// TODO: this is very brittle. | ||
// Instead pass in plugin details using a directive. | ||
let actdef = argsarr[argsarr.length - 1] || {}; | ||
@@ -300,8 +302,10 @@ if ('function' === typeof actdef) { | ||
} | ||
actdef.plugin_name = plugin.name || '-'; | ||
actdef.plugin_tag = plugin.tag || '-'; | ||
actdef.plugin_fullname = plugin.fullname; | ||
// TODO: is this necessary? | ||
actdef.log = delegate.log; | ||
actdeflist.push(actdef); | ||
if (null != actdef && 'object' === typeof actdef) { | ||
actdef.plugin_name = plugin.name || '-'; | ||
actdef.plugin_tag = plugin.tag || '-'; | ||
actdef.plugin_fullname = plugin.fullname; | ||
// TODO: is this necessary? | ||
actdef.log = delegate.log; | ||
actdeflist.push(actdef); | ||
} | ||
seneca.add.apply(delegate, argsarr); | ||
@@ -308,0 +312,0 @@ return this; |
@@ -397,2 +397,5 @@ /* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
let argsarr = [...arguments] | ||
// TODO: this is very brittle. | ||
// Instead pass in plugin details using a directive. | ||
let actdef = argsarr[argsarr.length - 1] || {} | ||
@@ -405,10 +408,12 @@ | ||
actdef.plugin_name = plugin.name || '-' | ||
actdef.plugin_tag = plugin.tag || '-' | ||
actdef.plugin_fullname = plugin.fullname | ||
if (null != actdef && 'object' === typeof actdef) { | ||
actdef.plugin_name = plugin.name || '-' | ||
actdef.plugin_tag = plugin.tag || '-' | ||
actdef.plugin_fullname = plugin.fullname | ||
// TODO: is this necessary? | ||
actdef.log = delegate.log | ||
// TODO: is this necessary? | ||
actdef.log = delegate.log | ||
actdeflist.push(actdef) | ||
actdeflist.push(actdef) | ||
} | ||
@@ -415,0 +420,0 @@ seneca.add.apply(delegate, argsarr) |
"use strict"; | ||
/* Copyright © 2019-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,7 +9,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const util_1 = __importDefault(require("util")); | ||
const gubu_1 = require("gubu"); | ||
const { Ordu } = require('ordu'); | ||
const Common = require('./common'); | ||
// const Common = require('./common') | ||
const { Inward } = require('./inward'); | ||
const Act = require('./act'); | ||
const { Meta } = require('./meta'); | ||
const common_1 = require("./common"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const ActArgu = Argu('prior', { | ||
props: (0, gubu_1.One)((0, gubu_1.Empty)(String), Object), | ||
moreprops: (0, gubu_1.Skip)(Object), | ||
reply: (0, gubu_1.Skip)(Function), | ||
}); | ||
const prior_inward = new Ordu({ | ||
@@ -30,3 +38,8 @@ name: 'prior_inward', | ||
var priordef = this.private$.act.def.priordef; | ||
var spec = Common.build_message(this, arguments, 'reply:f?', this.fixedargs); | ||
// var spec = Common.build_message(this, arguments, 'reply:f?', this.fixedargs) | ||
const spec = ActArgu(arguments); | ||
// TODO: duplicated, should be utility | ||
spec.msg = Object.assign({}, spec.moreprops ? spec.moreprops : null, 'string' === typeof spec.props ? | ||
(0, common_1.parse_jsonic)(spec.props, 'msg_jsonic_syntax') : | ||
spec.props); | ||
// TODO: clean sufficiently so that seneca.util.clean not needed | ||
@@ -33,0 +46,0 @@ var msg = spec.msg; |
@@ -1,2 +0,2 @@ | ||
/* Copyright © 2019-2022 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2019-2023 Richard Rodger and other contributors, MIT License. */ | ||
@@ -6,5 +6,8 @@ | ||
import { Gubu, MakeArgu, Open, Skip, One, Empty } from 'gubu' | ||
const { Ordu } = require('ordu') | ||
const Common = require('./common') | ||
// const Common = require('./common') | ||
const { Inward } = require('./inward') | ||
@@ -14,2 +17,18 @@ const Act = require('./act') | ||
import { | ||
parse_jsonic, | ||
} from './common' | ||
const Argu = MakeArgu('seneca') | ||
const ActArgu: any = Argu('prior', { | ||
props: One(Empty(String), Object), | ||
moreprops: Skip(Object), | ||
reply: Skip(Function), | ||
}) | ||
const prior_inward = new Ordu({ | ||
@@ -34,4 +53,16 @@ name: 'prior_inward', | ||
var spec = Common.build_message(this, arguments, 'reply:f?', this.fixedargs) | ||
// var spec = Common.build_message(this, arguments, 'reply:f?', this.fixedargs) | ||
const spec = ActArgu(arguments) | ||
// TODO: duplicated, should be utility | ||
spec.msg = Object.assign( | ||
{}, | ||
spec.moreprops ? spec.moreprops : null, | ||
'string' === typeof spec.props ? | ||
parse_jsonic(spec.props, 'msg_jsonic_syntax') : | ||
spec.props, | ||
) | ||
// TODO: clean sufficiently so that seneca.util.clean not needed | ||
@@ -38,0 +69,0 @@ var msg = spec.msg |
@@ -21,2 +21,3 @@ "use strict"; | ||
exports.make_ready = make_ready; | ||
// TODO should callback with plugin errs, or throw them! | ||
function api_ready(ready_func) { | ||
@@ -23,0 +24,0 @@ var self = this; |
@@ -23,2 +23,4 @@ /* Copyright © 2019-2022 Richard Rodger and other contributors, MIT License. */ | ||
// TODO should callback with plugin errs, or throw them! | ||
function api_ready(this: any, ready_func: any) { | ||
@@ -25,0 +27,0 @@ var self = this |
@@ -1,12 +0,24 @@ | ||
/* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2020-2023 Richard Rodger and other contributors, MIT License. */ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.api_sub = void 0; | ||
const Common = require('./common'); | ||
const gubu_1 = require("gubu"); | ||
const common_1 = require("./common"); | ||
const Argu = (0, gubu_1.MakeArgu)('seneca'); | ||
const SubArgu = Argu('sub', { | ||
props: (0, gubu_1.One)((0, gubu_1.Empty)(String), Object), | ||
moreprops: (0, gubu_1.Skip)(Object), | ||
action: Function, | ||
}); | ||
// Subscribe to messages. | ||
function api_sub() { | ||
const self = this; | ||
const subargs = Common.parsePattern(self, arguments, 'action:f'); | ||
const raw_pattern = subargs.pattern; | ||
const action = subargs.action; | ||
// const subargs = Common.parsePattern(self, arguments, 'action:f') | ||
const args = SubArgu(arguments); | ||
// TODO: this is duplicated - need to be a util | ||
args.pattern = Object.assign({}, args.moreprops ? args.moreprops : null, 'string' === typeof args.props ? | ||
(0, common_1.parse_jsonic)(args.props, 'add_string_pattern_syntax') : | ||
args.props); | ||
const raw_pattern = args.pattern; | ||
const action = args.action; | ||
let is_inward = !!raw_pattern.in$; | ||
@@ -35,3 +47,3 @@ let is_outward = !!raw_pattern.out$; | ||
router.add(sub_pattern, (sub_actions = [])); | ||
sub_actions.pattern = Common.pattern(sub_pattern); | ||
sub_actions.pattern = (0, common_1.pattern)(sub_pattern); | ||
} | ||
@@ -38,0 +50,0 @@ sub_actions.push(action); |
@@ -1,14 +0,44 @@ | ||
/* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2020-2023 Richard Rodger and other contributors, MIT License. */ | ||
'use strict' | ||
const Common = require('./common') | ||
import { MakeArgu, Skip, One, Empty } from 'gubu' | ||
import { | ||
pattern as common_pattern, | ||
parse_jsonic, | ||
} from './common' | ||
const Argu = MakeArgu('seneca') | ||
const SubArgu: any = Argu('sub', { | ||
props: One(Empty(String), Object), | ||
moreprops: Skip(Object), | ||
action: Function, | ||
}) | ||
// Subscribe to messages. | ||
function api_sub(this: any) { | ||
const self = this | ||
const subargs = Common.parsePattern(self, arguments, 'action:f') | ||
const raw_pattern = subargs.pattern | ||
const action = subargs.action | ||
// const subargs = Common.parsePattern(self, arguments, 'action:f') | ||
const args = SubArgu(arguments) | ||
// TODO: this is duplicated - need to be a util | ||
args.pattern = Object.assign( | ||
{}, | ||
args.moreprops ? args.moreprops : null, | ||
'string' === typeof args.props ? | ||
parse_jsonic(args.props, 'add_string_pattern_syntax') : | ||
args.props, | ||
) | ||
const raw_pattern = args.pattern | ||
const action = args.action | ||
let is_inward = !!raw_pattern.in$ | ||
@@ -45,3 +75,3 @@ let is_outward = !!raw_pattern.out$ | ||
router.add(sub_pattern, (sub_actions = [])) | ||
sub_actions.pattern = Common.pattern(sub_pattern) | ||
sub_actions.pattern = common_pattern(sub_pattern) | ||
} | ||
@@ -48,0 +78,0 @@ sub_actions.push(action) |
@@ -358,3 +358,4 @@ "use strict"; | ||
function web_modify_request(seneca, spec) { | ||
spec.body = stringifyJSON(externalize_msg(seneca, spec.msg, spec.meta)); | ||
let extmsg = externalize_msg(seneca, spec.msg, spec.meta); | ||
spec.body = stringifyJSON(extmsg); | ||
spec.headers['Content-Length'] = Buffer.byteLength(spec.body); | ||
@@ -361,0 +362,0 @@ spec.wreck = { |
@@ -412,3 +412,2 @@ /* Copyright © 2015-2022 Richard Rodger and other contributors, MIT License. */ | ||
spec = config.modify_request(seneca, spec) | ||
const wreck_req = config.wreck.request(spec.method, spec.url, spec.wreck) | ||
@@ -454,3 +453,4 @@ wreck_req | ||
function web_modify_request(seneca: any, spec: any) { | ||
spec.body = stringifyJSON(externalize_msg(seneca, spec.msg, spec.meta)) | ||
let extmsg = externalize_msg(seneca, spec.msg, spec.meta) | ||
spec.body = stringifyJSON(extmsg) | ||
spec.headers['Content-Length'] = Buffer.byteLength(spec.body) | ||
@@ -457,0 +457,0 @@ |
{ | ||
"name": "seneca", | ||
"description": "A Microservices Framework for Node.js", | ||
"version": "3.32.1", | ||
"version": "3.33.0", | ||
"license": "MIT", | ||
@@ -93,3 +93,3 @@ "homepage": "http://senecajs.org", | ||
"gate-executor": "^3.1.1", | ||
"gubu": "5.0.1", | ||
"gubu": "6.0.1", | ||
"lodash.defaultsdeep": "^4.6.1", | ||
@@ -100,3 +100,2 @@ "lodash.flatten": "^4.4.0", | ||
"nid": "^2.0.1", | ||
"norma": "^3.0.0", | ||
"optioner": "^5.0.1", | ||
@@ -114,4 +113,4 @@ "ordu": "^2.2.0", | ||
"@seneca/test-plugin": "0.1.0", | ||
"@types/node": "^20.6.2", | ||
"async": "^3.2.4", | ||
"@types/node": "^20.8.10", | ||
"async": "^3.2.5", | ||
"bench": "^0.3.6", | ||
@@ -124,3 +123,3 @@ "coveralls": "^3.1.1", | ||
"prettier": "^3.0.3", | ||
"seneca-entity": "^24.0.1", | ||
"seneca-entity": "^25.0.0", | ||
"seneca-error-test": "^0.2.2", | ||
@@ -127,0 +126,0 @@ "seneca-joi": "^7.0.2", |
@@ -197,2 +197,7 @@ /* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
}, | ||
// System actions. | ||
action: { | ||
// Add system actions. | ||
add: true | ||
}, | ||
}, | ||
@@ -676,3 +681,5 @@ // Internal functionality. Reserved for objects and functions only. | ||
}; | ||
addActions(root$); | ||
if (start_opts.system.action.add) { | ||
addActions(root$); | ||
} | ||
// root$.act('role:seneca,cmd:pingx') | ||
@@ -679,0 +686,0 @@ if (!start_opts.legacy.transport) { |
@@ -265,2 +265,9 @@ /* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
}, | ||
// System actions. | ||
action: { | ||
// Add system actions. | ||
add: true | ||
}, | ||
}, | ||
@@ -877,3 +884,5 @@ | ||
addActions(root$) | ||
if (start_opts.system.action.add) { | ||
addActions(root$) | ||
} | ||
@@ -880,0 +889,0 @@ // root$.act('role:seneca,cmd:pingx') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
681562
19
13282
+ Addedgubu@6.0.1(transitive)
- Removednorma@^3.0.0
- Removedgubu@5.0.1(transitive)
- Removednorma@3.1.1(transitive)
Updatedgubu@6.0.1