dobo 2.21.0 → 2.21.1
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/extend/bajo/intl/en-US.json +1 -1
- package/extend/bajo/intl/id.json +1 -1
- package/lib/collect-models.js +6 -5
- package/lib/factory/driver.js +2 -2
- package/lib/factory/model/_util.js +2 -2
- package/lib/factory/model/create-record.js +1 -1
- package/lib/factory/model/find-all-record.js +1 -1
- package/lib/factory/model/find-record.js +1 -2
- package/lib/factory/model/get-record.js +1 -1
- package/lib/factory/model/sanitize-record.js +2 -2
- package/lib/factory/model/update-record.js +1 -1
- package/lib/factory/model/upsert-record.js +1 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +8 -0
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
"maxPageError%s%s": "Page number (%s) above the allowed threshold (%s)",
|
|
151
151
|
"duplicateRefKeys%s%s": "Duplicate reference keys found in '%s' (%s)",
|
|
152
152
|
"sanitizeBodyError": "Error sanitizing body",
|
|
153
|
-
"virtualFieldIn%s%s": "Virtual field can't be used in '%s' on %s",
|
|
153
|
+
"virtualFieldIn%s%s%s": "Virtual field '%s' can't be used in '%s' on %s",
|
|
154
154
|
"field": {
|
|
155
155
|
"id": "ID",
|
|
156
156
|
"code": "Kode",
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
"maxPageError%s%s": "Nomor halaman (%s) melampaui batas yang diijinkan (%s)",
|
|
149
149
|
"duplicateRefKeys%s%s": "Ditemukan kunci referensi duplikat di '%s' (%s)",
|
|
150
150
|
"sanitizeBodyError": "Kesalahan saat sanitasi body",
|
|
151
|
-
"virtualFieldIn%s%s": "Kolom virtual tidak bisa digunakan di '%s' pada %s",
|
|
151
|
+
"virtualFieldIn%s%s%s": "Kolom virtual '%s' tidak bisa digunakan di '%s' pada %s",
|
|
152
152
|
"field": {
|
|
153
153
|
"id": "ID",
|
|
154
154
|
"code": "Kode",
|
package/lib/collect-models.js
CHANGED
|
@@ -29,6 +29,7 @@ async function sanitizeProp (model, prop, indexes) {
|
|
|
29
29
|
})
|
|
30
30
|
} else if (!isString(prop.values)) delete prop.values
|
|
31
31
|
if (prop.hidden) model.hidden.push(prop.name)
|
|
32
|
+
if (prop.scanable) model.scanables.push(prop.scanable)
|
|
32
33
|
if (prop.virtual) {
|
|
33
34
|
const keys = Object.keys(propType)
|
|
34
35
|
if (!keys.includes(prop.type)) this.fatal('unknownPropType%s%s', `${prop.name}:${prop.type}`, model.name)
|
|
@@ -160,7 +161,7 @@ export async function sanitizeRef (model, models) {
|
|
|
160
161
|
}
|
|
161
162
|
ref.field = ref.field ?? 'id'
|
|
162
163
|
ref.type = ref.type ?? '1:1'
|
|
163
|
-
ref.searchField = ref.searchField ??
|
|
164
|
+
ref.searchField = ref.searchField ?? ref.field
|
|
164
165
|
ref.labelField = ref.labelField ?? ref.searchField
|
|
165
166
|
const rModel = find(models, { name: ref.model })
|
|
166
167
|
if (!rModel) {
|
|
@@ -318,7 +319,7 @@ async function collectModels () {
|
|
|
318
319
|
|
|
319
320
|
const base = path.basename(file, path.extname(file))
|
|
320
321
|
const defName = pascalCase(`${this.alias} ${base}`)
|
|
321
|
-
const item = await readConfig(file, { ns: this.ns, baseNs: me.ns })
|
|
322
|
+
const item = await readConfig(file, { ns: this.ns, baseNs: me.ns, merge: true })
|
|
322
323
|
if (isEmpty(item)) return undefined
|
|
323
324
|
if (!isPlainObject(item)) me.fatal('invalidModel%s', defName)
|
|
324
325
|
item.name = item.name ?? defName
|
|
@@ -345,12 +346,12 @@ async function collectModels () {
|
|
|
345
346
|
for (const item of model.indexes) {
|
|
346
347
|
for (const field of item.fields) {
|
|
347
348
|
const prop = model.properties.find(p => p.name === field)
|
|
348
|
-
if (!prop || (prop && prop.virtual)) throw this.error('virtualFieldIn%s%s', 'index', model.name)
|
|
349
|
+
if (!prop || (prop && prop.virtual)) throw this.error('virtualFieldIn%s%s%s', field, 'index', model.name)
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
|
-
for (const field of model.
|
|
352
|
+
for (const field of model.scanables) {
|
|
352
353
|
const prop = model.properties.find(p => p.name === field)
|
|
353
|
-
if (!prop || (prop && prop.virtual)) throw this.error('virtualFieldIn%s%s', 'scanable', model.name)
|
|
354
|
+
if (!prop || (prop && prop.virtual)) throw this.error('virtualFieldIn%s%s%s', field, 'scanable', model.name)
|
|
354
355
|
}
|
|
355
356
|
}
|
|
356
357
|
this.log.debug('collected%s%d', this.t('model'), this.models.length)
|
package/lib/factory/driver.js
CHANGED
|
@@ -272,7 +272,7 @@ async function driverFactory () {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
async _updateRecord (model, id, input = {}, options = {}) {
|
|
275
|
-
let body = omit(input, this.getVirtualFields())
|
|
275
|
+
let body = omit(input, this.getVirtualFields(model))
|
|
276
276
|
if (!options.noUniqueCheck) {
|
|
277
277
|
if (!this.support.uniqueIndex) await this._checkUnique(model, body, options)
|
|
278
278
|
}
|
|
@@ -292,7 +292,7 @@ async function driverFactory () {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
async _upsertRecord (model, input = {}, options = {}) {
|
|
295
|
-
let body = omit(input, this.getVirtualFields())
|
|
295
|
+
let body = omit(input, this.getVirtualFields(model))
|
|
296
296
|
if (!options.noUniqueCheck) {
|
|
297
297
|
if (!this.uniqueIndexSupport) await this._checkUnique(model, body, options)
|
|
298
298
|
}
|
|
@@ -232,7 +232,7 @@ export async function getMultiRefs (records = [], options = {}) {
|
|
|
232
232
|
if (!rModel) return
|
|
233
233
|
let matches = []
|
|
234
234
|
for (const r of records) {
|
|
235
|
-
matches.push(rModel.sanitizeId(r[prop.name]))
|
|
235
|
+
matches.push(prop.name === 'id' ? rModel.sanitizeId(r[prop.name]) : r[prop.name])
|
|
236
236
|
}
|
|
237
237
|
matches = uniq(without(matches, undefined, null, NaN)).map(i => i + '')
|
|
238
238
|
let query = {}
|
|
@@ -438,7 +438,7 @@ export function preparePagination (filter = {}, options = {}) {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
export async function clearCache (id) {
|
|
441
|
-
const { clear } = this.app.bajoCache
|
|
441
|
+
const { clear } = this.app.bajoCache ?? {}
|
|
442
442
|
if (!clear) return
|
|
443
443
|
await clear({ key: `dobo|${this.name}|getRecord|${id}` })
|
|
444
444
|
await clear({ key: `dobo|${this.name}|findRecord` })
|
|
@@ -24,8 +24,8 @@ async function createRecord (...args) {
|
|
|
24
24
|
result = result ?? {}
|
|
25
25
|
const { warnings } = getDefaultValues(options)
|
|
26
26
|
if (!warnings) delete result.warnings
|
|
27
|
-
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
28
27
|
if (isSet(options.refs)) await getSingleRef.call(this, result.data, options)
|
|
28
|
+
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
29
29
|
await handleReq.call(this, result.data.id, 'created', options)
|
|
30
30
|
await execDynHook.call(this, 'afterCreateRecord', input, result, options)
|
|
31
31
|
await execModelHook.call(this, 'afterCreateRecord', input, result, options)
|
|
@@ -37,12 +37,12 @@ async function native (...args) {
|
|
|
37
37
|
result.pages = options.count ? Math.ceil(result.count / filter.limit) : undefined
|
|
38
38
|
if (!warnings) delete result.warnings
|
|
39
39
|
|
|
40
|
+
if (isSet(options.refs)) await getMultiRefs.call(this, result.data, options)
|
|
40
41
|
if (!noResultSanitizer) {
|
|
41
42
|
for (const idx in result.data) {
|
|
42
43
|
result.data[idx] = await this.sanitizeRecord(result.data[idx], options)
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
if (isSet(options.refs)) await getMultiRefs.call(this, result.data, options)
|
|
46
46
|
await execDynHook.call(this, 'afterFindRecord', filter, result, options)
|
|
47
47
|
await execModelHook.call(this, 'afterFindRecord', filter, result, options)
|
|
48
48
|
await execHook.call(this, 'afterFindRecord', filter, result, options)
|
|
@@ -101,13 +101,12 @@ async function findRecord (...args) {
|
|
|
101
101
|
}
|
|
102
102
|
result.pages = options.count ? Math.ceil(result.count / filter.limit) : undefined
|
|
103
103
|
if (!warnings) delete result.warnings
|
|
104
|
-
|
|
104
|
+
if (isSet(options.refs)) await getMultiRefs.call(this, result.data, options)
|
|
105
105
|
if (!noResultSanitizer) {
|
|
106
106
|
for (const idx in result.data) {
|
|
107
107
|
result.data[idx] = await this.sanitizeRecord(result.data[idx], options)
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
if (isSet(options.refs)) await getMultiRefs.call(this, result.data, options)
|
|
111
110
|
await execDynHook.call(this, 'afterFindRecord', filter, result, options)
|
|
112
111
|
await execModelHook.call(this, 'afterFindRecord', filter, result, options)
|
|
113
112
|
await execHook.call(this, 'afterFindRecord', filter, result, options)
|
|
@@ -68,8 +68,8 @@ async function getRecord (...args) {
|
|
|
68
68
|
const { warnings } = getDefaultValues(options)
|
|
69
69
|
if (!warnings) delete result.warnings
|
|
70
70
|
if (isEmpty(result.data) && !options.throwNotFound) return dataOnly ? undefined : { data: undefined }
|
|
71
|
-
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
72
71
|
if (isSet(options.refs)) await getSingleRef.call(this, result.data, options)
|
|
72
|
+
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
73
73
|
await execDynHook.call(this, 'afterGetRecord', id, result, options)
|
|
74
74
|
await execModelHook.call(this, 'afterGetRecord', id, result, options)
|
|
75
75
|
await execHook.call(this, 'afterGetRecord', id, result, options)
|
|
@@ -25,13 +25,14 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
25
25
|
newFields = without(newFields, ...allHidden)
|
|
26
26
|
const body = fillObject(record, newFields, null)
|
|
27
27
|
const newRecord = await this.sanitizeBody({ body, noDefault: true })
|
|
28
|
+
if (record._ref) newRecord._ref = cloneDeep(record._ref)
|
|
28
29
|
for (const key in newRecord) {
|
|
29
30
|
const prop = this.getProperty(key)
|
|
31
|
+
if (!prop) continue
|
|
30
32
|
const val = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord[key]) : newRecord[key]
|
|
31
33
|
if (isFunction(prop.getValue)) newRecord[key] = await prop.getValue.call(this, val, newRecord, opts)
|
|
32
34
|
else if (isString(prop.getValue)) newRecord[key] = await callHandler(this.plugin, this, val, newRecord, opts)
|
|
33
35
|
}
|
|
34
|
-
|
|
35
36
|
if (opts.fmt) {
|
|
36
37
|
newRecord._fmt = cloneDeep(newRecord)
|
|
37
38
|
for (const key in newRecord) {
|
|
@@ -55,7 +56,6 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
if (record._ref) newRecord._ref = record._ref
|
|
59
59
|
return newRecord
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -71,11 +71,11 @@ async function updateRecord (...args) {
|
|
|
71
71
|
if (noResult) return
|
|
72
72
|
const { warnings } = getDefaultValues(options)
|
|
73
73
|
if (!warnings) delete result.warnings
|
|
74
|
+
if (isSet(options.refs)) await getSingleRef.call(this, result.data, options)
|
|
74
75
|
if (!noResultSanitizer) {
|
|
75
76
|
result.data = await this.sanitizeRecord(result.data, options)
|
|
76
77
|
result.oldData = await this.sanitizeRecord(result.oldData, options)
|
|
77
78
|
}
|
|
78
|
-
if (isSet(options.refs)) await getSingleRef.call(this, result.data, options)
|
|
79
79
|
await handleReq.call(this, result.data.id, 'updated', options)
|
|
80
80
|
await execDynHook.call(this, 'afterUpdateRecord', id, input, result, options)
|
|
81
81
|
await execModelHook.call(this, 'afterUpdateRecord', id, input, result, options)
|
|
@@ -20,8 +20,8 @@ async function native (body = {}, opts = {}) {
|
|
|
20
20
|
if (noResult) return
|
|
21
21
|
const { warnings } = getDefaultValues(options)
|
|
22
22
|
if (!warnings) delete result.warnings
|
|
23
|
-
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
24
23
|
if (isSet(options.refs)) await getSingleRef.call(this, result.data, options)
|
|
24
|
+
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
25
25
|
await handleReq.call(this, result.data.id, 'upserted', options)
|
|
26
26
|
await execDynHook.call(this, 'afterUpsertRecord', input, result, options)
|
|
27
27
|
await execModelHook.call(this, 'afterUpsertRecord', input, result, options)
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-28
|
|
4
|
+
|
|
5
|
+
- [2.21.1] Bug fix in ```collect-models.js```
|
|
6
|
+
- [2.21.1] Bug fix in ```driver._updateRecord()```
|
|
7
|
+
- [2.21.1] Bug fix in ```util.getMultiRef()```
|
|
8
|
+
- [2.21.1] Bug fix in setting references
|
|
9
|
+
- [2.21.1] Bug fix in ```model.sanitizeRecord()```
|
|
10
|
+
|
|
3
11
|
## 2026-04-25
|
|
4
12
|
|
|
5
13
|
- [2.21.0] Change ```options.formatValue``` to ```options.fmt```
|