dobo 2.34.0 → 2.35.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/lib/factory/adapter.js +13 -12
- package/lib/factory/model/sanitize-record.js +15 -12
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/lib/factory/adapter.js
CHANGED
|
@@ -175,10 +175,11 @@ async function adapterFactory () {
|
|
|
175
175
|
* Sanitizes a record retrieved from the database, converting data types as necessary
|
|
176
176
|
* and ensuring that the record conforms to the model's schema.
|
|
177
177
|
* @param {DoboModel} model - The model instance for which the record is being sanitized
|
|
178
|
-
* @param {object} record - The record retrieved from the database
|
|
178
|
+
* @param {object} [record={}] - The record retrieved from the database
|
|
179
|
+
* @param {object} [options={}] - Additional options for sanitization
|
|
179
180
|
* @returns {object} - Sanitized record
|
|
180
181
|
*/
|
|
181
|
-
sanitizeRecord (model, record = {}) {
|
|
182
|
+
sanitizeRecord (model, record = {}, options = {}) {
|
|
182
183
|
const { dayjs } = this.app.lib
|
|
183
184
|
const { isString } = this.app.lib._
|
|
184
185
|
const item = { ...record }
|
|
@@ -193,7 +194,7 @@ async function adapterFactory () {
|
|
|
193
194
|
if (prop.type === 'datetime') {
|
|
194
195
|
const dt = this.useUtc ? dayjs.utc(item[prop.name]) : dayjs(item[prop.name])
|
|
195
196
|
item[prop.name] = dt.toDate()
|
|
196
|
-
} else if (['object', 'array'].includes(prop.type)) item[prop.name] = JSON.parse(item[prop.name])
|
|
197
|
+
} else if (isString(item[prop.name]) && ['object', 'array'].includes(prop.type)) item[prop.name] = JSON.parse(item[prop.name])
|
|
197
198
|
} catch (err) {
|
|
198
199
|
item[prop.name] = null
|
|
199
200
|
}
|
|
@@ -461,7 +462,7 @@ async function adapterFactory () {
|
|
|
461
462
|
await this._attachHook('afterCreateRecord', model, body, result, options)
|
|
462
463
|
|
|
463
464
|
if (options.noResult) return
|
|
464
|
-
result.data = this.sanitizeRecord(model, result.data)
|
|
465
|
+
result.data = this.sanitizeRecord(model, result.data, options)
|
|
465
466
|
this._injectMeta(result, options)
|
|
466
467
|
return result
|
|
467
468
|
}
|
|
@@ -512,7 +513,7 @@ async function adapterFactory () {
|
|
|
512
513
|
await this._attachHook('afterGetRecord', model, id, result, options)
|
|
513
514
|
|
|
514
515
|
if (isEmpty(result.data) && options.throwNotFound) throw this.plugin.error('recordNotFound%s%s', id, model.name)
|
|
515
|
-
result.data = this.sanitizeRecord(model, result.data)
|
|
516
|
+
result.data = this.sanitizeRecord(model, result.data, options)
|
|
516
517
|
this._injectMeta(result, options)
|
|
517
518
|
return result
|
|
518
519
|
}
|
|
@@ -547,8 +548,8 @@ async function adapterFactory () {
|
|
|
547
548
|
await this._attachHook('afterUpdateRecord', model, id, body, result, options)
|
|
548
549
|
|
|
549
550
|
if (options.noResult) return
|
|
550
|
-
result.oldData = this.sanitizeRecord(model, result.oldData)
|
|
551
|
-
result.data = this.sanitizeRecord(model, result.data)
|
|
551
|
+
result.oldData = this.sanitizeRecord(model, result.oldData, options)
|
|
552
|
+
result.data = this.sanitizeRecord(model, result.data, options)
|
|
552
553
|
this._injectMeta(result, options)
|
|
553
554
|
return result
|
|
554
555
|
}
|
|
@@ -584,8 +585,8 @@ async function adapterFactory () {
|
|
|
584
585
|
await this._attachHook('afterUpsertRecord', model, body, result, options)
|
|
585
586
|
|
|
586
587
|
if (options.noResult) return
|
|
587
|
-
if (result.oldData) result.oldData = this.sanitizeRecord(model, result.oldData)
|
|
588
|
-
result.data = this.sanitizeRecord(model, result.data)
|
|
588
|
+
if (result.oldData) result.oldData = this.sanitizeRecord(model, result.oldData, options)
|
|
589
|
+
result.data = this.sanitizeRecord(model, result.data, options)
|
|
589
590
|
this._injectMeta(result, options)
|
|
590
591
|
return result
|
|
591
592
|
}
|
|
@@ -613,7 +614,7 @@ async function adapterFactory () {
|
|
|
613
614
|
await this._attachHook('afterRemoveRecord', model, id, result, options)
|
|
614
615
|
|
|
615
616
|
if (options.noResult) return
|
|
616
|
-
result.oldData = this.sanitizeRecord(model, result.oldData)
|
|
617
|
+
result.oldData = this.sanitizeRecord(model, result.oldData, options)
|
|
617
618
|
this._injectMeta(result, options)
|
|
618
619
|
return result
|
|
619
620
|
}
|
|
@@ -664,7 +665,7 @@ async function adapterFactory () {
|
|
|
664
665
|
}
|
|
665
666
|
|
|
666
667
|
for (const idx in result.data) {
|
|
667
|
-
result.data[idx] = this.sanitizeRecord(model, result.data[idx])
|
|
668
|
+
result.data[idx] = this.sanitizeRecord(model, result.data[idx], options)
|
|
668
669
|
}
|
|
669
670
|
this._injectMeta(result, options)
|
|
670
671
|
return result
|
|
@@ -698,7 +699,7 @@ async function adapterFactory () {
|
|
|
698
699
|
}
|
|
699
700
|
|
|
700
701
|
for (const idx in result.data) {
|
|
701
|
-
result.data[idx] = this.sanitizeRecord(model, result.data[idx])
|
|
702
|
+
result.data[idx] = this.sanitizeRecord(model, result.data[idx], options)
|
|
702
703
|
}
|
|
703
704
|
this._injectMeta(result, options)
|
|
704
705
|
return result
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* @param {boolean} [opts.forceNoHidden=false] - If `true`, force ALL fields to be picked, thus ignoring hidden fields. If an array, force all fields except those in the array to be picked.
|
|
11
11
|
* @param {boolean} [opts.fmt=false] - If `true`, add a `_fmt` property to the sanitized record with formatted values automatically based on the model's properties and rules
|
|
12
12
|
* @param {Object} [opts.req] - Request object, used for formatting values based on request context
|
|
13
|
-
* @param {Object} [opts.
|
|
14
|
-
* @param {string} [opts.
|
|
15
|
-
* @param {string} [opts.
|
|
16
|
-
* @param {string} [opts.
|
|
17
|
-
* @param {string} [opts.
|
|
13
|
+
* @param {Object} [opts.intl] - Internationalization options, used for formatting values based on i18n context
|
|
14
|
+
* @param {string} [opts.intl.lang] - Language code for formatting values
|
|
15
|
+
* @param {string} [opts.intl.datetime] - Date and time style for formatting datetime values
|
|
16
|
+
* @param {string} [opts.intl.date] - Date style for formatting date values
|
|
17
|
+
* @param {string} [opts.intl.time] - Time style for formatting time values
|
|
18
|
+
* @param {string} [opts.intl.timeZone] - Time zone for formatting date/time values
|
|
18
19
|
* @returns {Object} Returns sanitized record object
|
|
19
20
|
*/
|
|
20
21
|
async function sanitizeRecord (record = {}, opts = {}) {
|
|
@@ -56,14 +57,16 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
56
57
|
else if (isString(prop.format)) newRecord._fmt[key] = await callHandler(this.plugin, this, value, newRecord, opts)
|
|
57
58
|
else {
|
|
58
59
|
const options = {
|
|
59
|
-
lang: get(opts, '
|
|
60
|
-
datetime:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
lang: get(opts, 'intl.lang', get(opts, 'req.lang')),
|
|
61
|
+
datetime: get(opts, 'intl.datetime', get(opts, 'req.site.setting.bajo.intl.datetime')),
|
|
62
|
+
date: get(opts, 'intl.date', get(opts, 'req.site.setting.bajo.intl.date')),
|
|
63
|
+
time: get(opts, 'intl.time', get(opts, 'req.site.setting.bajo.intl.time')),
|
|
64
|
+
timeZone: get(opts, 'intl.timeZone', get(opts, 'req.site.setting.bajo.intl.timeZone')),
|
|
65
|
+
emptyValue: get(opts, 'intl.emptyValue', get(opts, 'req.site.setting.bajo.intl.emptyValue')),
|
|
66
|
+
unitSys: get(opts, 'intl.unitSys', get(opts, 'req.site.setting.bajo.intl.unitSys')),
|
|
65
67
|
latitude: ['lat', 'latitude'].includes(key),
|
|
66
|
-
longitude: ['lon', 'lng', 'longitude'].includes(key)
|
|
68
|
+
longitude: ['lon', 'lng', 'longitude'].includes(key),
|
|
69
|
+
field: key
|
|
67
70
|
}
|
|
68
71
|
newRecord._fmt[key] = format(value, prop.type, options)
|
|
69
72
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-07-29
|
|
4
|
+
|
|
5
|
+
- [2.35.0] Add parameter `options` to `adapter.sanitizeRecord()` to allow passing additional options for sanitization
|
|
6
|
+
- [2.35.0] Change `options.i18n` to `options.intl` in `adapter.sanitizeRecord()` for consistency with other methods
|
|
7
|
+
|
|
8
|
+
## 2026-07-28
|
|
9
|
+
|
|
10
|
+
- [2.34.1] Bug fix in `adapter.sanitizeRecord()`
|
|
11
|
+
|
|
3
12
|
## 2026-07-26
|
|
4
13
|
|
|
5
14
|
- [2.34.0] Add `options.i18n` to `model.sanitizeRecord()`
|