dobo 2.24.0 → 2.25.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.
@@ -225,6 +225,9 @@
225
225
  "required": "Required",
226
226
  "only": "Must match with %(ref)s"
227
227
  },
228
+ "array": {
229
+ "base": "Required"
230
+ },
228
231
  "string": {
229
232
  "alphanum": "Must only contain alpha-numeric characters",
230
233
  "base": "Must be a string",
@@ -224,6 +224,9 @@
224
224
  "required": "Harus diisi/dipilih",
225
225
  "only": "Harus sesuai dengan %(ref)s"
226
226
  },
227
+ "array": {
228
+ "base": "Required"
229
+ },
227
230
  "string": {
228
231
  "alphanum": "Harus berupa alfa numerik karakter saja",
229
232
  "base": "Harus berupa string",
@@ -1,6 +1,6 @@
1
1
  async function beforeRemoveRecord (id, opts, options) {
2
2
  const { get } = this.app.lib._
3
- if (get(options, 'req.user.interSiteAdmin')) return
3
+ if (get(options, 'req.user.isXSiteAdmin')) return
4
4
  const record = await this.driver.getRecord(this, id)
5
5
  const immutable = get(record.data, opts.field)
6
6
  if (immutable) throw this.plugin.error('recordImmutable%s%s', id, this.name, { statusCode: 423 })
package/index.js CHANGED
@@ -73,11 +73,11 @@ const propertyType = {
73
73
  rules: []
74
74
  },
75
75
  object: {
76
- validator: null,
76
+ validator: 'object',
77
77
  rules: []
78
78
  },
79
79
  array: {
80
- validator: null,
80
+ validator: 'array',
81
81
  rules: []
82
82
  }
83
83
  }
@@ -188,7 +188,7 @@ export async function getRefs (records = [], options = {}) {
188
188
  if (!rModel) return
189
189
  let matches = []
190
190
  for (const rec of records) {
191
- const items = isValues ? [...rec[prop.name]] : [rec[prop.name]]
191
+ const items = isValues ? [...(rec[prop.name] ?? [])] : (rec[prop.name] ? [rec[prop.name]] : [])
192
192
  matches.push(...items.map(item => prop.name === 'id' ? rModel.sanitizeId(item) : item))
193
193
  }
194
194
  matches = uniq(without(matches, undefined, null, NaN)).map(i => i + '')
@@ -211,7 +211,7 @@ export async function getRefs (records = [], options = {}) {
211
211
  for (const i in records) {
212
212
  records[i]._ref = records[i]._ref ?? {}
213
213
  const rec = records[i]
214
- let items = isValues ? [...rec[prop.name]] : [rec[prop.name]]
214
+ let items = isValues ? [...(rec[prop.name] ?? [])] : (rec[prop.name] ? [rec[prop.name]] : [])
215
215
  items = items.map(item => item + '')
216
216
  const res = results.filter(r => items.includes(r[ref.field] + ''))
217
217
  if (res.length === 0) records[i]._ref[key] = isValues ? [] : {}
@@ -27,7 +27,7 @@ async function exec ({ item, spinner, options, result, items } = {}) {
27
27
  async function loadFixtures ({ spinner, ignoreError = true, collectItems = false, noLookup = false } = {}, options = {}) {
28
28
  const { readConfig } = this.app.bajo
29
29
  const { resolvePath, isSet } = this.app.lib.aneka
30
- const { isEmpty, isString, isArray } = this.app.lib._
30
+ const { isEmpty, isString, isArray, pullAt } = this.app.lib._
31
31
  if (this.connection.proxy) {
32
32
  this.log.warn('proxiedConnBound%s', this.name)
33
33
  return
@@ -39,8 +39,10 @@ async function loadFixtures ({ spinner, ignoreError = true, collectItems = false
39
39
  const opts = { ...options, noMagic: true }
40
40
  for (const item of items) {
41
41
  const lv = {}
42
+ const deleted = {}
42
43
  for (const key in item) {
43
44
  const val = item[key]
45
+ deleted[key] = deleted[key] ?? []
44
46
  if (!noLookup) {
45
47
  if (isString(val) && val.slice(0, 2) === '?:') {
46
48
  item[key] = await this._simpleLookup(val.slice(2), lv, opts)
@@ -50,11 +52,14 @@ async function loadFixtures ({ spinner, ignoreError = true, collectItems = false
50
52
  if (isString(val[idx]) && val[idx].slice(0, 2) === '?:') {
51
53
  item[key][idx] = await this._simpleLookup(val[idx].slice(2), lv, opts)
52
54
  if (isSet(item[key][idx])) item[key][idx] += ''
55
+ else deleted[key].push(idx)
53
56
  lv[`${key}.${idx}`] = item[key][idx]
54
57
  }
55
58
  }
59
+ if (deleted[key].length > 0) pullAt(item[key], deleted[key])
56
60
  }
57
61
  }
62
+ delete deleted[key]
58
63
  if (val === null) item[key] = undefined
59
64
  else {
60
65
  const prop = this.properties.find(item => item.name === key)
@@ -1,6 +1,6 @@
1
1
  import joi from 'joi'
2
2
 
3
- const excludedTypes = ['object', 'array']
3
+ const excludedTypes = ['object']
4
4
  const excludedNames = []
5
5
 
6
6
  /**
@@ -142,7 +142,9 @@ async function buildFromDbModel (opts = {}) {
142
142
  const resp = await callHandler(prop.values)
143
143
  items = resp.map(item => item.value)
144
144
  }
145
- obj = obj.valid(...items)
145
+ if (prop.type === 'array') {
146
+ obj = obj.items(joi.string().valid(...items))
147
+ } else obj = obj.valid(...items)
146
148
  }
147
149
  if (prop.rulesMsg) {
148
150
  const msgs = {}
@@ -185,6 +187,9 @@ async function buildFromDbModel (opts = {}) {
185
187
  case 'boolean':
186
188
  item = await applyFieldRules(p, joi.boolean())
187
189
  break
190
+ case 'array':
191
+ item = await applyFieldRules(p, joi.array())
192
+ break
188
193
  }
189
194
  if (item) {
190
195
  if (item.$_root && !p.required) obj[p.name] = item.allow(null, '')
@@ -96,11 +96,16 @@ async function modelFactory () {
96
96
  return namesOnly ? items.map(item => item.name) : items
97
97
  }
98
98
 
99
- getVirtualProperties = ({ namesOnly }) => {
99
+ getVirtualProperties = (namesOnly) => {
100
100
  const items = this.properties.filter(prop => prop.virtual)
101
101
  return namesOnly ? items.map(item => item.name) : items
102
102
  }
103
103
 
104
+ getNonVirtualProperties = (namesOnly) => {
105
+ const items = this.properties.filter(prop => !prop.virtual)
106
+ return namesOnly ? items.map(item => item.name) : items
107
+ }
108
+
104
109
  getIndexes = () => {
105
110
  return this.indexes
106
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "2.24.0",
3
+ "version": "2.25.0",
4
4
  "description": "DBMS for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-22
4
+
5
+ - [2.25.0] Add ```array``` & ```object``` validator handling
6
+ - [2.25.0] Change ```interSite``` definition to ```xSite```
7
+ - [2.25.0] Add ```model.getNonVirtualProperties()```
8
+ - [2.25.0] Bug fix in ```model.loadFixtures()```
9
+ - [2.25.0] Handle ```array``` validation schema
10
+
3
11
  ## 2026-05-16
4
12
 
5
13
  - [2.24.0] Change ```dobo:immutable``` feature, field no longer hidden