Comparing version 3.30.1 to 3.31.0
@@ -1,3 +0,8 @@ | ||
## 3.30.1 2022-05-31 | ||
## 3.31.0 2023-06-29 | ||
* Provide merged plugin options to the plugin preload function. | ||
## 3.30.1 2023-05-31 | ||
* Remove rebind decoration as not needed - seneca-entity handles own special case | ||
@@ -7,3 +12,3 @@ * Option debnug.datalen applies to test logs in all cases | ||
## 3.30.0 2022-02-10 | ||
## 3.30.0 2023-02-10 | ||
@@ -10,0 +15,0 @@ * Error intercept customization hook. |
@@ -31,2 +31,9 @@ /* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
tasks.normalize, | ||
{ | ||
name: 'pre_options', exec: (spec) => { | ||
if ('function' === typeof spec.data.plugin.define.preload) { | ||
return tasks.options(spec); | ||
} | ||
} | ||
}, | ||
tasks.preload, | ||
@@ -369,5 +376,155 @@ { name: 'pre_meta', exec: tasks.meta }, | ||
}, | ||
/* | ||
pre_options: (spec: TaskSpec) => { | ||
try { | ||
let plugin: any = spec.data.plugin | ||
// let delegate: any = spec.data.delegate | ||
let seneca = spec.ctx.seneca | ||
// let so = delegate.options() | ||
let so = seneca.options() | ||
let fullname = plugin.fullname | ||
let defaults = plugin.defaults | ||
let fullname_options = Object.assign( | ||
{}, | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname] : {}, | ||
so.plugin[fullname], | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname + '$' + plugin.tag] : {}, | ||
so.plugin[fullname + '$' + plugin.tag] | ||
) | ||
let shortname = fullname !== plugin.name ? plugin.name : null | ||
if (!shortname && fullname.indexOf('seneca-') === 0) { | ||
shortname = fullname.substring('seneca-'.length) | ||
} | ||
let shortname_options = Object.assign( | ||
{}, | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname] : {}, | ||
so.plugin[shortname], | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[shortname + '$' + plugin.tag] : {}, | ||
so.plugin[shortname + '$' + plugin.tag] | ||
) | ||
let base: any = {} | ||
// NOTE: plugin error codes are in their own namespaces | ||
// TODO: test this!!! | ||
let errors = plugin.errors || (plugin.define && plugin.define.errors) | ||
if (errors) { | ||
base.errors = errors | ||
} | ||
// TODO: these should deep merge | ||
let fullopts = Object.assign( | ||
base, | ||
shortname_options, | ||
fullname_options, | ||
plugin.options || {} | ||
) | ||
let resolved_options: any = {} | ||
// let valid = delegate.valid // Gubu validator: https://github.com/rjrodger/gubu | ||
let valid = seneca.valid // Gubu validator: https://github.com/rjrodger/gubu | ||
let err: Error | undefined = void 0 | ||
let joi_schema: any = null | ||
// let Joi = delegate.util.Joi | ||
let Joi = seneca.util.Joi | ||
let defaults_values = | ||
('function' === typeof (defaults) && !defaults.gubu) ? | ||
defaults({ valid, Joi }) : defaults | ||
if (null == defaults_values || | ||
0 === Object.keys(defaults_values).length || | ||
!so.valid.active || | ||
!so.valid.plugin | ||
) { | ||
resolved_options = fullopts | ||
} | ||
else { | ||
if (!so.legacy.options && !Joi.isSchema(defaults_values, { legacy: true })) { | ||
// TODO: use Gubu.isShape | ||
let isShape = defaults_values.gubu && defaults_values.gubu.gubu$ | ||
// TODO: when Gubu supports merge, also merge if isShape | ||
if (!isShape && null == defaults_values.errors && null != errors) { | ||
defaults_values.errors = {} | ||
} | ||
let optionShape = | ||
// isShape ? defaults_values : delegate.valid(defaults_values) | ||
isShape ? defaults_values : seneca.valid(defaults_values) | ||
let shapeErrors: any[] = [] | ||
resolved_options = optionShape(fullopts, { err: shapeErrors }) | ||
if (0 < shapeErrors.length) { | ||
//err = delegate.error('invalid_plugin_option', { | ||
err = seneca.error('invalid_plugin_option', { | ||
name: fullname, | ||
err_msg: shapeErrors.map((se: any) => se.t).join('; '), | ||
options: fullopts, | ||
}) | ||
} | ||
} | ||
else { | ||
let joi_schema: any = intern.prepare_spec( | ||
Joi, | ||
defaults_values, | ||
{ allow_unknown: true }, | ||
{} | ||
) | ||
let joi_out = joi_schema.validate(fullopts) | ||
if (joi_out.error) { | ||
// err = delegate.error('invalid_plugin_option', { | ||
err = seneca.error('invalid_plugin_option', { | ||
name: fullname, | ||
err_msg: joi_out.error.message, | ||
options: fullopts, | ||
}) | ||
} | ||
else { | ||
resolved_options = joi_out.value | ||
} | ||
} | ||
} | ||
return { | ||
op: 'seneca_options', | ||
err: err, | ||
out: { | ||
plugin: { | ||
options: resolved_options, | ||
options_schema: joi_schema | ||
} | ||
} | ||
} | ||
} catch (e: any) { | ||
console.log('PREOPTS', e) | ||
} | ||
}, | ||
*/ | ||
options: (spec) => { | ||
let plugin = spec.data.plugin; | ||
let delegate = spec.data.delegate; | ||
let delegate = spec.data.delegate || | ||
spec.ctx.seneca; // for preload | ||
let so = delegate.options(); | ||
@@ -374,0 +531,0 @@ let fullname = plugin.fullname; |
@@ -40,3 +40,13 @@ /* Copyright © 2020 Richard Rodger and other contributors, MIT License. */ | ||
tasks.normalize, | ||
{ | ||
name: 'pre_options', exec: (spec: TaskSpec) => { | ||
if ('function' === typeof spec.data.plugin.define.preload) { | ||
return tasks.options(spec) | ||
} | ||
} | ||
}, | ||
tasks.preload, | ||
{ name: 'pre_meta', exec: tasks.meta }, | ||
@@ -495,5 +505,157 @@ { name: 'pre_legacy_extend', exec: tasks.legacy_extend }, | ||
/* | ||
pre_options: (spec: TaskSpec) => { | ||
try { | ||
let plugin: any = spec.data.plugin | ||
// let delegate: any = spec.data.delegate | ||
let seneca = spec.ctx.seneca | ||
// let so = delegate.options() | ||
let so = seneca.options() | ||
let fullname = plugin.fullname | ||
let defaults = plugin.defaults | ||
let fullname_options = Object.assign( | ||
{}, | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname] : {}, | ||
so.plugin[fullname], | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname + '$' + plugin.tag] : {}, | ||
so.plugin[fullname + '$' + plugin.tag] | ||
) | ||
let shortname = fullname !== plugin.name ? plugin.name : null | ||
if (!shortname && fullname.indexOf('seneca-') === 0) { | ||
shortname = fullname.substring('seneca-'.length) | ||
} | ||
let shortname_options = Object.assign( | ||
{}, | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[fullname] : {}, | ||
so.plugin[shortname], | ||
// DEPRECATED: remove in 4 | ||
so.legacy.top_plugins ? so[shortname + '$' + plugin.tag] : {}, | ||
so.plugin[shortname + '$' + plugin.tag] | ||
) | ||
let base: any = {} | ||
// NOTE: plugin error codes are in their own namespaces | ||
// TODO: test this!!! | ||
let errors = plugin.errors || (plugin.define && plugin.define.errors) | ||
if (errors) { | ||
base.errors = errors | ||
} | ||
// TODO: these should deep merge | ||
let fullopts = Object.assign( | ||
base, | ||
shortname_options, | ||
fullname_options, | ||
plugin.options || {} | ||
) | ||
let resolved_options: any = {} | ||
// let valid = delegate.valid // Gubu validator: https://github.com/rjrodger/gubu | ||
let valid = seneca.valid // Gubu validator: https://github.com/rjrodger/gubu | ||
let err: Error | undefined = void 0 | ||
let joi_schema: any = null | ||
// let Joi = delegate.util.Joi | ||
let Joi = seneca.util.Joi | ||
let defaults_values = | ||
('function' === typeof (defaults) && !defaults.gubu) ? | ||
defaults({ valid, Joi }) : defaults | ||
if (null == defaults_values || | ||
0 === Object.keys(defaults_values).length || | ||
!so.valid.active || | ||
!so.valid.plugin | ||
) { | ||
resolved_options = fullopts | ||
} | ||
else { | ||
if (!so.legacy.options && !Joi.isSchema(defaults_values, { legacy: true })) { | ||
// TODO: use Gubu.isShape | ||
let isShape = defaults_values.gubu && defaults_values.gubu.gubu$ | ||
// TODO: when Gubu supports merge, also merge if isShape | ||
if (!isShape && null == defaults_values.errors && null != errors) { | ||
defaults_values.errors = {} | ||
} | ||
let optionShape = | ||
// isShape ? defaults_values : delegate.valid(defaults_values) | ||
isShape ? defaults_values : seneca.valid(defaults_values) | ||
let shapeErrors: any[] = [] | ||
resolved_options = optionShape(fullopts, { err: shapeErrors }) | ||
if (0 < shapeErrors.length) { | ||
//err = delegate.error('invalid_plugin_option', { | ||
err = seneca.error('invalid_plugin_option', { | ||
name: fullname, | ||
err_msg: shapeErrors.map((se: any) => se.t).join('; '), | ||
options: fullopts, | ||
}) | ||
} | ||
} | ||
else { | ||
let joi_schema: any = intern.prepare_spec( | ||
Joi, | ||
defaults_values, | ||
{ allow_unknown: true }, | ||
{} | ||
) | ||
let joi_out = joi_schema.validate(fullopts) | ||
if (joi_out.error) { | ||
// err = delegate.error('invalid_plugin_option', { | ||
err = seneca.error('invalid_plugin_option', { | ||
name: fullname, | ||
err_msg: joi_out.error.message, | ||
options: fullopts, | ||
}) | ||
} | ||
else { | ||
resolved_options = joi_out.value | ||
} | ||
} | ||
} | ||
return { | ||
op: 'seneca_options', | ||
err: err, | ||
out: { | ||
plugin: { | ||
options: resolved_options, | ||
options_schema: joi_schema | ||
} | ||
} | ||
} | ||
} catch (e: any) { | ||
console.log('PREOPTS', e) | ||
} | ||
}, | ||
*/ | ||
options: (spec: TaskSpec) => { | ||
let plugin: any = spec.data.plugin | ||
let delegate: any = spec.data.delegate | ||
let delegate: any = | ||
spec.data.delegate || | ||
spec.ctx.seneca // for preload | ||
@@ -500,0 +662,0 @@ let so = delegate.options() |
{ | ||
"name": "seneca", | ||
"description": "A Microservices Framework for Node.js", | ||
"version": "3.30.1", | ||
"version": "3.31.0", | ||
"license": "MIT", | ||
@@ -89,3 +89,3 @@ "homepage": "http://senecajs.org", | ||
"@hapi/wreck": "17", | ||
"@jsonic/jsonic-next": "2.9.1", | ||
"@jsonic/jsonic-next": "2.10.0", | ||
"eraro": "^2.1.0", | ||
@@ -100,3 +100,3 @@ "fast-safe-stringify": "^2.1.1", | ||
"nid": "^2.0.1", | ||
"norma": "^2.0.2", | ||
"norma": "^3.0.0", | ||
"optioner": "^5.0.1", | ||
@@ -114,3 +114,3 @@ "ordu": "^2.2.0", | ||
"@seneca/test-plugin": "0.1.0", | ||
"@types/node": "^20.2.5", | ||
"@types/node": "^20.3.2", | ||
"async": "^3.2.4", | ||
@@ -124,3 +124,3 @@ "bench": "^0.3.6", | ||
"prettier": "^2.8.8", | ||
"seneca-entity": "^22.0.0", | ||
"seneca-entity": "^22.1.0", | ||
"seneca-error-test": "^0.2.2", | ||
@@ -130,4 +130,4 @@ "seneca-joi": "^7.0.2", | ||
"summary": "^2.1.0", | ||
"typescript": "^5.0.4" | ||
"typescript": "^5.1.6" | ||
} | ||
} |
@@ -380,10 +380,8 @@ /* Copyright © 2010-2023 Richard Rodger and other contributors, MIT License. */ | ||
} | ||
module.exports = init; | ||
// Expose Seneca prototype for easier monkey-patching | ||
module.exports.Seneca = Seneca; | ||
exports.default = init; | ||
init.Seneca = Seneca; | ||
// To reference builtin loggers when defining logging options. | ||
module.exports.loghandler = Legacy.loghandler; | ||
init.loghandler = Legacy.loghandler; | ||
// Makes require('seneca').use(...) work by creating an on-the-fly instance. | ||
module.exports.use = function top_use() { | ||
init.use = function top_use() { | ||
var argsarr = new Array(arguments.length); | ||
@@ -393,16 +391,18 @@ for (var l = 0; l < argsarr.length; ++l) { | ||
} | ||
var instance = module.exports(); | ||
var instance = init(); | ||
return instance.use.apply(instance, argsarr); | ||
}; | ||
// Makes require('seneca').test() work. | ||
module.exports.test = function top_test() { | ||
return module.exports().test(...arguments); | ||
init.test = function top_test() { | ||
return init().test(...arguments); | ||
}; | ||
// Makes require('seneca').quiet() work. | ||
module.exports.quiet = function top_quiet() { | ||
return module.exports().quiet(...arguments); | ||
init.quiet = function top_quiet() { | ||
return init().quiet(...arguments); | ||
}; | ||
module.exports.util = seneca_util; | ||
module.exports.valid = Gubu; | ||
module.exports.test$ = { intern: intern }; | ||
init.util = seneca_util; | ||
init.valid = Gubu; | ||
init.test$ = { intern: intern }; | ||
exports.default = init; | ||
module.exports = init; | ||
// Create a new Seneca instance. | ||
@@ -409,0 +409,0 @@ function make_seneca(initial_opts) { |
Sorry, the diff of this file is not supported yet
620953
12223
77
+ Added@jsonic/csv@0.4.3(transitive)
+ Added@jsonic/jsonic-next@2.10.02.14.0(transitive)
+ Addednorma@3.1.1(transitive)
- Removed@jsonic/jsonic-next@2.9.1(transitive)
Updated@jsonic/jsonic-next@2.10.0
Updatednorma@^3.0.0