bajo 0.2.24 → 0.2.26

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
  }
@@ -7,7 +7,7 @@ function fatal (...args) {
7
7
  const [msg, ...params] = args
8
8
  const err = error(msg, ...params)
9
9
  console.error(err)
10
- process.exit(1)
10
+ process.kill(process.pid, 'SIGINT')
11
11
  }
12
12
 
13
13
  export default fatal
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
@@ -127,7 +127,7 @@ export class Print {
127
127
  if (this.opts.isLog) return log.fatal(text, ...args)
128
128
  this.setText(text, ...args)
129
129
  this.ora.fail()
130
- process.exit(1)
130
+ process.kill(process.pid, 'SIGINT')
131
131
  }
132
132
  }
133
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {