dobo 2.16.0 → 2.17.0
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
|
@@ -390,17 +390,21 @@ async function factory (pkgName) {
|
|
|
390
390
|
return parseInt(value) || null
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
sanitizeObject = (value) => {
|
|
393
|
+
sanitizeObject = (value, { strict = false } = {}) => {
|
|
394
394
|
const { isString } = this.app.lib._
|
|
395
395
|
let result = null
|
|
396
396
|
if (isString(value)) {
|
|
397
397
|
try {
|
|
398
398
|
result = JSON.parse(value)
|
|
399
|
-
} catch (err) {
|
|
399
|
+
} catch (err) {
|
|
400
|
+
if (strict) throw err
|
|
401
|
+
}
|
|
400
402
|
} else {
|
|
401
403
|
try {
|
|
402
404
|
result = JSON.parse(JSON.stringify(value))
|
|
403
|
-
} catch (err) {
|
|
405
|
+
} catch (err) {
|
|
406
|
+
if (strict) throw err
|
|
407
|
+
}
|
|
404
408
|
}
|
|
405
409
|
return result
|
|
406
410
|
}
|
|
@@ -21,7 +21,7 @@ async function sanitizeBody ({ body = {}, partial, strict, extFields = [], noDef
|
|
|
21
21
|
|
|
22
22
|
const sanitize = (name, type) => {
|
|
23
23
|
if (onlyTypes.length > 0 && !onlyTypes.includes(type)) return
|
|
24
|
-
if (['object', 'array'].includes(type)) result[name] = sanitizeObject(result[name])
|
|
24
|
+
if (['object', 'array'].includes(type)) result[name] = sanitizeObject(result[name], { strict })
|
|
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 })
|
|
27
27
|
else if (['integer', 'smallint'].includes(type)) result[name] = sanitizeInt(result[name], { strict })
|
|
@@ -28,16 +28,17 @@ 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]
|
|
31
32
|
if (prop.format) {
|
|
32
|
-
if (isFunction(prop.format)) newRecord[key] = await prop.format.call(this,
|
|
33
|
-
else if (isString(prop.format)) newRecord[key] = await callHandler(this.plugin, this,
|
|
33
|
+
if (isFunction(prop.format)) newRecord[key] = await prop.format.call(this, value, newRecord, opts)
|
|
34
|
+
else if (isString(prop.format)) newRecord[key] = await callHandler(this.plugin, this, value, newRecord, opts)
|
|
34
35
|
} else {
|
|
35
36
|
const options = {
|
|
36
37
|
lang: get(opts, 'req.lang'),
|
|
37
38
|
latitude: ['lat', 'latitude'].includes(key),
|
|
38
39
|
longitude: ['lon', 'lng', 'longitude'].includes(key)
|
|
39
40
|
}
|
|
40
|
-
newRecord[key] = format(
|
|
41
|
+
newRecord[key] = format(value, prop.type, options)
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -57,6 +57,7 @@ async function updateRecord (...args) {
|
|
|
57
57
|
const { truncateString, noResult, noBodySanitizer, noResultSanitizer, noValidation, partial } = options
|
|
58
58
|
const extFields = get(options, 'validation.extFields', [])
|
|
59
59
|
id = this.sanitizeId(id)
|
|
60
|
+
|
|
60
61
|
let input = noBodySanitizer ? cloneDeep(body) : await this.sanitizeBody({ body, extFields, strict: true, truncateString, partial, onlyTypes })
|
|
61
62
|
const immutables = this.properties.filter(prop => prop.immutable)
|
|
62
63
|
if (immutables.length > 0) input = omit(input, immutables)
|
package/package.json
CHANGED