bajo 0.2.25 → 0.2.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { last, isPlainObject, each, isArray, get } from 'lodash-es'
1
+ import { last, isPlainObject, each, isArray, get, isEmpty, merge } from 'lodash-es'
2
2
  import getPluginName from './get-plugin-name.js'
3
3
 
4
4
  /**
@@ -18,6 +18,7 @@ Error.stackTraceLimit = 15
18
18
 
19
19
  function formatErrorDetails (value, ns) {
20
20
  const { print } = this.bajo.helper
21
+ const result = {}
21
22
  each(value, (v, i) => {
22
23
  if (!v.context) {
23
24
  v.error = print.__(v.error, { ns })
@@ -25,11 +26,15 @@ function formatErrorDetails (value, ns) {
25
26
  }
26
27
  v.context.message = v.message
27
28
  if (v.type === 'any.only') v.context.ref = print.__(`field.${get(v, 'context.valids.0.key')}`, { ns })
29
+ const field = get(v, 'context.key')
30
+ const val = get(v, 'context.value')
28
31
  value[i] = {
29
- field: get(v, 'context.key'),
32
+ field,
30
33
  error: print.__(`validation.${v.type}`, v.context, { ns })
31
34
  }
35
+ result[field] = val
32
36
  })
37
+ return result
33
38
  }
34
39
 
35
40
  function error (msg = 'Internal server error', ...args) {
@@ -55,13 +60,16 @@ function error (msg = 'Internal server error', ...args) {
55
60
  if (isPlainObject(payload)) {
56
61
  delete payload.class
57
62
  delete payload.ns
63
+ const values = {}
58
64
  for (const key in payload) {
59
65
  const value = payload[key]
60
66
  if (key === 'details' && isArray(value) && orgMsg === 'Validation Error') {
61
- formatErrorDetails.call(this, value, ns)
67
+ const result = formatErrorDetails.call(this, value, ns)
68
+ if (result) merge(values, result)
62
69
  }
63
70
  err[key] = value
64
71
  }
72
+ if (!isEmpty(values)) err.values = values
65
73
  }
66
74
  return err
67
75
  }
package/boot/lib/print.js CHANGED
@@ -31,12 +31,12 @@ export class Print {
31
31
  }
32
32
 
33
33
  setText (text, ...args) {
34
- // const { dayjs } = this.scope.bajo.helper
34
+ const { dayjs } = this.scope.bajo.helper
35
35
  text = this.__(text, ...args)
36
36
  this.setOpts(args)
37
37
  const prefixes = []
38
38
  const texts = []
39
- // if (this.opts.showDatetime) prefixes.push('[' + dayjs().toISOString() + ']')
39
+ if (this.opts.showDatetime) prefixes.push('[' + dayjs().toISOString() + ']')
40
40
  if (this.opts.showCounter) texts.push('[' + this.getElapsed() + ']')
41
41
  if (prefixes.length > 0) this.ora.prefixText = this.ora.prefixText + prefixes.join(' ')
42
42
  if (texts.length > 0) text = texts.join(' ') + ' ' + text
package/boot/run-tool.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isString, map, find } from 'lodash-es'
2
+ import Path from 'path'
2
3
  const tools = []
3
4
 
4
5
  async function runTool () {
@@ -27,8 +28,14 @@ async function runTool () {
27
28
  if (!tool) print.fatal('Sidetool \'%s\' not found. Aborted!', name)
28
29
  const opts = { ns, toc, path, params, args: config.args }
29
30
  const mod = await importModule(tool.file)
30
- const handler = mod.handler ?? mod
31
- await handler.call(this, opts)
31
+ if (mod === 'defCliHandler' && this.bajoCli) {
32
+ const { runToolMethod } = this.bajoCli.helper
33
+ const dir = `${Path.dirname(tool.file)}/tool`
34
+ await runToolMethod({ path, args: config.args, dir })
35
+ } else {
36
+ const handler = mod.handler ?? mod
37
+ await handler.call(this, opts)
38
+ }
32
39
  }
33
40
 
34
41
  export default runTool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {