dobo 2.11.2 → 2.11.4

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.
@@ -227,8 +227,8 @@ export async function sanitizeAll (model) {
227
227
  async function createSchema (item) {
228
228
  const { readConfig } = this.app.bajo
229
229
  const { fastGlob } = this.app.lib
230
- const { find, isPlainObject, orderBy } = this.app.lib._
231
- const { mergeObjectsByKey } = this.app.lib.aneka
230
+ const { find, isPlainObject, orderBy, get, cloneDeep } = this.app.lib._
231
+ const { mergeObjectsByKey, defaultsDeep } = this.app.lib.aneka
232
232
  if (item.file && !item.base) item.base = path.basename(item.file, path.extname(item.file))
233
233
  item.attachment = item.attachment ?? true
234
234
  const feats = item.features ?? []
@@ -245,8 +245,6 @@ async function createSchema (item) {
245
245
  item.hooks = item.hooks ?? []
246
246
  item.disabled = item.disabled ?? []
247
247
  item.scanables = item.scanables ?? []
248
- item.cache = item.cache ?? this.config.default.cache
249
- if (item.cache === true) item.cache = this.config.default.cache
250
248
  if (item.disabled === 'all') item.disabled = ['find', 'get', 'create', 'update', 'remove']
251
249
  else if (item.disabled === 'readonly') item.disabled = ['create', 'update', 'remove']
252
250
  // Is there any overwritten connection?
@@ -257,6 +255,11 @@ async function createSchema (item) {
257
255
  if (!item.connection && conn === 'default') item.connection = this.getConnection('memory')
258
256
  }
259
257
  if (!item.connection) this.fatal('unknownConn%s%s', conn, item.name)
258
+ const defCache = cloneDeep(get(this, 'app.bajoCache.config.default', this.config.default.cache))
259
+ item.cache = item.cache ?? item.connection.options.cache ?? defCache
260
+ if (item.cache === true) item.cache = get(item, 'connection.options.cache', defCache)
261
+ else if (item.cache === false) item.cache = { ttlDur: 0 }
262
+ item.cache = defaultsDeep(get(this, `app.bajoCache.config.dobo.${item.name}`), item.cache)
260
263
  await findAllProps.call(this, item, props, indexes)
261
264
  await findAllFeats.call(this, item, feats, indexes)
262
265
  await findAllIndexes.call(this, item, indexes)
@@ -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
  }
@@ -6,7 +6,7 @@ async function native (...args) {
6
6
  const { cloneDeep } = this.app.lib._
7
7
  const [params = {}, opts = {}] = args
8
8
  const { dataOnly = true } = opts
9
- const { get: getCache, set: setCache } = this.app.bajoCache
9
+ const { get: getCache, set: setCache } = this.app.bajoCache ?? {}
10
10
  const { filter, options } = await getFilterAndOptions.call(this, params, opts, action)
11
11
  if (dataOnly) options.count = false
12
12
  let { noResultSanitizer, noCache } = options
@@ -70,7 +70,7 @@ async function findRecord (...args) {
70
70
  const { isSet } = this.app.lib.aneka
71
71
  const { cloneDeep } = this.app.lib._
72
72
  const { dataOnly = true } = opts
73
- const { get: getCache, set: setCache } = this.app.bajoCache
73
+ const { get: getCache, set: setCache } = this.app.bajoCache ?? {}
74
74
  const { filter, options } = await getFilterAndOptions.call(this, params, opts, action)
75
75
  if (dataOnly) options.count = false
76
76
  let { noResultSanitizer, noCache } = options
@@ -47,7 +47,7 @@ async function getRecord (...args) {
47
47
  let [id, opts = {}] = args
48
48
  const { isEmpty } = this.app.lib._
49
49
  const { isSet } = this.app.lib.aneka
50
- const { get: getCache, set: setCache } = this.app.bajoCache
50
+ const { get: getCache, set: setCache } = this.app.bajoCache ?? {}
51
51
  const { dataOnly = true } = opts
52
52
  const { options } = await getFilterAndOptions.call(this, null, opts, action)
53
53
  let { noResultSanitizer, noCache } = options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
4
4
  "description": "DBMS for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-26
4
+
5
+ - [2.11.4] Exceptions thrown in ```getSingleRef()``` && ```getMultiRefs()``` will be catched and are ignored
6
+
3
7
  ## 2026-03-25
4
8
 
5
9
  - [2.11.2] Bug fix in result sets cache
10
+ - [2.11.3] Bug fix in cache handling if ```bajoCache``` isn't loaded
6
11
 
7
12
  ## 2026-03-17
8
13