dobo 2.11.3 → 2.12.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/.bootorder ADDED
@@ -0,0 +1 @@
1
+ 10
@@ -171,23 +171,25 @@ export async function getSingleRef (record = {}, options = {}) {
171
171
  if (props.length > 0) {
172
172
  for (const prop of props) {
173
173
  for (const key in prop.ref) {
174
- if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
175
- const ref = prop.ref[key]
176
- if (ref.fields.length === 0) continue
177
- if (get(record, `_ref.${key}`)) continue
178
- const rModel = this.app.dobo.getModel(ref.model)
179
- const query = {}
180
- query[ref.propName] = record[prop.name]
181
- if (ref.propName === 'id') query[ref.propName] = this.sanitizeId(query[ref.propName])
182
- const rFilter = { query }
183
- const rOptions = { dataOnly: true, refs: [] }
184
- const results = await rModel.findRecord(rFilter, rOptions)
185
- const fields = [...ref.fields]
186
- const data = []
187
- for (const res of results) {
188
- data.push(await rModel.sanitizeRecord(res, { fields }))
189
- }
190
- refs[key] = ['1:1'].includes(ref.type) ? data[0] : data
174
+ try {
175
+ if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
176
+ const ref = prop.ref[key]
177
+ if (ref.fields.length === 0) continue
178
+ if (get(record, `_ref.${key}`)) continue
179
+ const rModel = this.app.dobo.getModel(ref.model)
180
+ const query = {}
181
+ query[ref.propName] = record[prop.name]
182
+ if (ref.propName === 'id') query[ref.propName] = this.sanitizeId(query[ref.propName])
183
+ const rFilter = { query }
184
+ const rOptions = { dataOnly: true, refs: [] }
185
+ const results = await rModel.findRecord(rFilter, rOptions)
186
+ const fields = [...ref.fields]
187
+ const data = []
188
+ for (const res of results) {
189
+ data.push(await rModel.sanitizeRecord(res, { fields }))
190
+ }
191
+ refs[key] = ['1:1'].includes(ref.type) ? data[0] : data
192
+ } catch (err) {}
191
193
  }
192
194
  }
193
195
  }
@@ -202,31 +204,33 @@ export async function getMultiRefs (records = [], options = {}) {
202
204
  if (props.length > 0) {
203
205
  for (const prop of props) {
204
206
  for (const key in prop.ref) {
205
- if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
206
- const ref = prop.ref[key]
207
- if (ref.fields.length === 0) continue
208
- if (ref.type !== '1:1') continue
209
- if (get(records, `0._ref.${key}`)) continue
210
- const rModel = this.app.dobo.getModel(ref.model)
211
- let matches = []
212
- for (const r of records) {
213
- matches.push(rModel.sanitizeId(r[prop.name]))
214
- }
215
- matches = uniq(without(matches, undefined, null, NaN))
216
- const query = {}
217
- query[ref.propName] = { $in: matches }
218
- const rFilter = { query, limit: matches.length }
219
- const rOptions = { dataOnly: true, refs: [] }
220
- const results = await rModel.findRecord(rFilter, rOptions)
221
- const fields = [...ref.fields]
222
- if (!fields.includes(prop.name)) fields.push(prop.name)
223
- for (const i in records) {
224
- records[i]._ref = records[i]._ref ?? {}
225
- const rec = records[i]
226
- const res = results.find(res => (res[ref.propName] + '') === rec[prop.name] + '')
227
- if (res) records[i]._ref[key] = await rModel.sanitizeRecord(res, { fields })
228
- else records[i]._ref[key] = {}
229
- }
207
+ try {
208
+ if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
209
+ const ref = prop.ref[key]
210
+ if (ref.fields.length === 0) continue
211
+ if (ref.type !== '1:1') continue
212
+ if (get(records, `0._ref.${key}`)) continue
213
+ const rModel = this.app.dobo.getModel(ref.model)
214
+ let matches = []
215
+ for (const r of records) {
216
+ matches.push(rModel.sanitizeId(r[prop.name]))
217
+ }
218
+ matches = uniq(without(matches, undefined, null, NaN))
219
+ const query = {}
220
+ query[ref.propName] = { $in: matches }
221
+ const rFilter = { query, limit: matches.length }
222
+ const rOptions = { dataOnly: true, refs: [] }
223
+ const results = await rModel.findRecord(rFilter, rOptions)
224
+ const fields = [...ref.fields]
225
+ if (!fields.includes(prop.name)) fields.push(prop.name)
226
+ for (const i in records) {
227
+ records[i]._ref = records[i]._ref ?? {}
228
+ const rec = records[i]
229
+ const res = results.find(res => (res[ref.propName] + '') === rec[prop.name] + '')
230
+ if (res) records[i]._ref[key] = await rModel.sanitizeRecord(res, { fields })
231
+ else records[i]._ref[key] = {}
232
+ }
233
+ } catch (err) {}
230
234
  }
231
235
  }
232
236
  }
@@ -238,7 +238,7 @@ async function validate (body, joiModel, opts = {}) {
238
238
  try {
239
239
  return await joiModel.validateAsync(body, params)
240
240
  } catch (err) {
241
- const payload = { details: err.details, statusCode: 422, code: 'DB_VALIDATION' }
241
+ const payload = { details: err.details, statusCode: 422, code: 'DB_VALIDATION', model: this.name }
242
242
  if (err.values) payload.values = err.values
243
243
  throw this.plugin.error('validationError', payload)
244
244
  }
@@ -109,7 +109,9 @@ async function modelFactory () {
109
109
  if (isEmpty(field)) field = 'id'
110
110
  const { getModel } = this.app.dobo
111
111
  const ref = getModel(model)
112
- const rec = await ref.findOneRecord({ query }, { noHook: true, noCache: true, ...options })
112
+ const opts = { noHook: true, noCache: true, ...options }
113
+ opts.dataOnly = true
114
+ const rec = await ref.findOneRecord({ query }, opts)
113
115
  return get(rec, field, null)
114
116
  }
115
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "2.11.3",
3
+ "version": "2.12.0",
4
4
  "description": "DBMS for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-30
4
+
5
+ - [2.12.0] Add ```.bootorder``` level 10
6
+ - [2.12.0] Bug fix in ```model._simpleLookup()```
7
+ - [2.12.0] Add model name in validation error's payload
8
+
9
+ ## 2026-03-26
10
+
11
+ - [2.11.4] Exceptions thrown in ```getSingleRef()``` && ```getMultiRefs()``` will be catched and are ignored
12
+
3
13
  ## 2026-03-25
4
14
 
5
15
  - [2.11.2] Bug fix in result sets cache