dobo 1.1.9 → 1.1.11

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.
@@ -36,7 +36,7 @@ async function sanitizeFullText (item) {
36
36
 
37
37
  async function sanitizeSchema (items) {
38
38
  const { freeze, fatal, importModule, defaultsDeep, join, breakNsPath, runHook } = this.app.bajo
39
- const { orderBy, map, keys, findIndex, find, each, isString, get, isPlainObject, camelCase, uniq, filter } = this.lib._
39
+ const { isEmpty, orderBy, map, keys, findIndex, find, each, isString, get, isPlainObject, camelCase, uniq, filter } = this.lib._
40
40
  const propTypes = keys(this.propType)
41
41
  const schemas = []
42
42
  this.log.debug('loadingDbSchemas')
@@ -64,7 +64,7 @@ async function sanitizeSchema (items) {
64
64
  maxLength = maxLength ?? 255
65
65
  prop = { name, type }
66
66
  if (type === 'string') prop.maxLength = parseInt(maxLength) || undefined
67
- if (index) prop.index = { type: index === 'true' ? 'default' : index }
67
+ if (!isEmpty(index)) prop.index = { type: index === 'true' ? 'default' : index }
68
68
  prop.required = required === 'true'
69
69
  item.properties[idx] = prop
70
70
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -342,6 +342,18 @@ async function factory (pkgName) {
342
342
  return cloned ? cloneDeep(schema) : schema
343
343
  }
344
344
 
345
+ getField = (name, model) => {
346
+ const { getInfo } = this.app.dobo
347
+ const { find } = this.lib._
348
+ const { schema } = getInfo(model)
349
+
350
+ return find(schema.properties, { name })
351
+ }
352
+
353
+ hasField = (name, model) => {
354
+ return !!this.getField(name, model)
355
+ }
356
+
345
357
  getMemdbStorage = (name, fields = []) => {
346
358
  const { map, pick } = this.lib._
347
359
  const all = this.memDb.storage[name] ?? []