dobo 2.18.0 → 2.18.2

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.
package/index.js CHANGED
@@ -501,9 +501,12 @@ async function factory (pkgName) {
501
501
  }
502
502
 
503
503
  getDefaultValues = (options = {}) => {
504
+ const { defaultsDeep } = this.app.lib.aneka
504
505
  const key = 'default.filter'
505
- let config = this.app.dobo.getConfig(key)
506
- if (options.req) config = options.req.getSetting(`dobo:${key}`, config)
506
+ let config = this.getConfig(key)
507
+ config.hardCap = this.config.default.hardCap
508
+ config.warnings = this.config.default.warnings
509
+ if (options.req) config = defaultsDeep({}, options.req.getSetting('dobo:default'), config)
507
510
  const { limit, maxLimit, maxPage, hardCap, warnings } = config
508
511
  const t = options.req ? options.req.t : this.t
509
512
  return { limit, maxLimit, hardCap, maxPage, warnings, t }
@@ -10,7 +10,7 @@ import actionFactory from './factory/action.js'
10
10
  * @param {Array} [indexes] - Container array to fill up found index
11
11
  */
12
12
  async function sanitizeProp (model, prop, indexes) {
13
- const { isEmpty, isString, keys, pick, isArray, isPlainObject } = this.app.lib._
13
+ const { isEmpty, isString, keys, pick, isArray, isPlainObject, omit } = this.app.lib._
14
14
  const allPropKeys = this.getAllPropertyKeys(model.connection.driver)
15
15
  const propType = this.constructor.propertyType
16
16
  if (isString(prop)) {
@@ -39,7 +39,9 @@ async function sanitizeProp (model, prop, indexes) {
39
39
  else {
40
40
  const feature = this.getFeature(prop.type)
41
41
  if (!feature) this.fatal('unknownPropType%s%s', prop.type, model.name)
42
- await applyFeature.call(this, model, feature, { field: prop.name }, indexes)
42
+ const opts = omit(prop, ['name', 'type'])
43
+ opts.field = prop.name
44
+ await applyFeature.call(this, model, feature, opts, indexes)
43
45
  }
44
46
  }
45
47
 
@@ -6,10 +6,12 @@ async function createAttachment (...args) {
6
6
  if (args.length === 0) return this.action(action, ...args)
7
7
  const [id, opts = {}] = args
8
8
  const { fs } = this.app.lib
9
- const { isEmpty } = this.app.lib._
9
+ const { isEmpty, last } = this.app.lib._
10
10
  const { source, field = 'file', file, fullPath, stats, mimeType, req } = opts
11
11
  if (isEmpty(file)) return
12
12
  if (!source) throw this.plugin.error('isMissing%s', this.plugin.t('field.source'))
13
+ const [, filename] = last(source.split('/')).split('@')
14
+ if (isEmpty(filename)) return
13
15
  const baseDir = await getAttachmentPath.call(this, id, field, file, { dirOnly: true })
14
16
  let dir = `${baseDir}/${field}`
15
17
  if ((field || '').endsWith('[]')) dir = `${baseDir}/${field.replace('[]', '')}`
@@ -20,7 +20,7 @@ async function sanitizeBody ({ body = {}, partial, strict, extFields = [], noDef
20
20
  const result = {}
21
21
 
22
22
  const sanitize = (name, type) => {
23
- if (onlyTypes.length > 0 && !onlyTypes.includes(type)) return
23
+ // if (onlyTypes.length > 0 && !onlyTypes.includes(type)) return
24
24
  if (['object', 'array'].includes(type)) result[name] = sanitizeObject(result[name], { strict, action, model: this.name })
25
25
  else if (type === 'boolean') result[name] = sanitizeBoolean(result[name])
26
26
  else if (['float', 'double'].includes(type)) result[name] = sanitizeFloat(result[name], { strict })
@@ -28,16 +28,28 @@ async function sanitizeRecord (record = {}, opts = {}) {
28
28
  for (const key in newRecord) {
29
29
  const prop = this.getProperty(key)
30
30
  if (!prop) continue
31
- const value = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord[key]) : newRecord[key]
32
31
  if (prop.formatValue && opts.retainOriginalValue) {
33
- const value = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord._orig[key]) : newRecord._orig[key]
34
- if (isFunction(prop.formatValue)) newRecord._orig[key] = await prop.formatValue.call(this, value, newRecord._orig, opts)
35
- else if (isString(prop.formatValue)) newRecord._orig[key] = await callHandler(this.plugin, this, value, newRecord._orig, opts)
32
+ const val = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord._orig[key]) : newRecord._orig[key]
33
+ if (isFunction(prop.formatValue)) newRecord._orig[key] = await prop.formatValue.call(this, val, newRecord._orig, opts)
34
+ else if (isString(prop.formatValue)) newRecord._orig[key] = await callHandler(this.plugin, this, val, newRecord._orig, opts)
36
35
  }
37
- if (prop.format) {
38
- if (isFunction(prop.format)) newRecord[key] = await prop.format.call(this, value, newRecord, opts)
39
- else if (isString(prop.format)) newRecord[key] = await callHandler(this.plugin, this, value, newRecord, opts)
40
- } else {
36
+ let value = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord[key]) : newRecord[key]
37
+ if (prop.values) {
38
+ const values = (isString(prop.values) ? await callHandler(prop.values) : [...prop.values]).map(v => {
39
+ if (isString(v)) v = { value: v, text: v }
40
+ if (opts.req) {
41
+ const { camelCase } = this.app.lib._
42
+ const key = camelCase(`${prop.name} ${v.text}`)
43
+ if (opts.req.te(key)) v.text = opts.req.t(key)
44
+ }
45
+ return v
46
+ })
47
+ value = (values.find(v => v.value === value) ?? {}).text ?? value
48
+ }
49
+ if (prop.format === false) newRecord[key] = value + ''
50
+ else if (isFunction(prop.format)) newRecord[key] = await prop.format.call(this, value, newRecord, opts)
51
+ else if (isString(prop.format)) newRecord[key] = await callHandler(this.plugin, this, value, newRecord, opts)
52
+ else {
41
53
  const options = {
42
54
  lang: get(opts, 'req.lang'),
43
55
  latitude: ['lat', 'latitude'].includes(key),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "2.18.0",
3
+ "version": "2.18.2",
4
4
  "description": "DBMS for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-04-18
4
+
5
+ - [2.18.2] Bug fix in ```config``` object
6
+ - [2.18.2] Bug fix in ```getDefaultValues```
7
+ - [2.18.2] Bug fix in ```sanitizeProp()``` in ```collect-models.js```
8
+ - [2.18.2] Bug fix in ```sanitizeRecord()``` for prop with ```format``` set to ```false```
9
+
10
+ ## 2026-04-17
11
+
12
+ - [2.18.1] Bug fix in ```model.createAttachment()```
13
+ - [2.18.1] Bug fix in ```model.sanitizeBody()```
14
+ - [2.18.1] Bug fix in ```model.sanitizeRecord()```
15
+
3
16
  ## 2026-04-16
4
17
 
5
18
  - [2.18.0] Add parameter options to ```sanitizeObject()```