waibu-db 2.1.7 → 2.2.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.
@@ -4,7 +4,7 @@ async function addHandler ({ req, reply, model, params = {}, template, addOnsHan
4
4
  const { buildUrl } = this.app.waibuMpa
5
5
  const { defaultsDeep } = this.app.lib.aneka
6
6
  const { pick, map, merge, omit } = this.app.lib._
7
- const opts = {}
7
+ const opts = merge({}, options.modelOpts)
8
8
  model = pascalCase(model ?? req.params.model)
9
9
  const { schema } = await getSchemaExt(model, 'add', merge({}, { params }, options))
10
10
  if (schema.disabled.includes('create')) return await reply.view(templateDisabled, { action: 'add' })
@@ -3,7 +3,7 @@ async function deleteHandler ({ req, reply, model, params = {}, templateDisabled
3
3
  const { removeRecord, getSchemaExt } = this.app.waibuDb
4
4
  const { buildUrl } = this.app.waibuMpa
5
5
  const { reduce, merge } = this.app.lib._
6
- const opts = {}
6
+ const opts = merge({}, options.modelOpts)
7
7
  model = pascalCase(model ?? req.params.model)
8
8
  const { schema } = await getSchemaExt(model, 'add', merge({}, { params }, options))
9
9
  if (schema.disabled.includes('remove')) return await reply.view(templateDisabled, { action: 'delete' })
@@ -4,7 +4,7 @@ async function detailsHandler ({ req, reply, model, params = {}, id, template, a
4
4
  const { pascalCase } = this.app.lib.aneka
5
5
  const { getRecord, getSchemaExt } = this.app.waibuDb
6
6
  const { merge } = this.app.lib._
7
- const opts = { refs: '*' }
7
+ const opts = merge({ refs: '*' }, options.modelOpts)
8
8
  model = pascalCase(model ?? req.params.model)
9
9
  const { schema } = await getSchemaExt(model, 'details', merge({}, { params }, options))
10
10
  if (schema.disabled.includes('get')) return await reply.view(templateDisabled, { action: 'details' })
@@ -8,7 +8,7 @@ async function editHandler ({ req, reply, model, id, params = {}, template, addO
8
8
  const { fs } = this.app.lib
9
9
  const { defaultsDeep } = this.app.lib.aneka
10
10
  const { merge, isEmpty, omit } = this.app.lib._
11
- const opts = {}
11
+ const opts = merge({}, options.modelOpts)
12
12
  let error
13
13
  let resp
14
14
  let form
@@ -3,6 +3,8 @@ async function listHandler ({ req, reply, model, template, params = {}, addOnsHa
3
3
  const { findRecord, getSchemaExt } = this.app.waibuDb
4
4
  const { get, merge, isArray, upperFirst } = this.app.lib._
5
5
  const qsKey = this.app.waibu.config.qsKey
6
+
7
+ const opts = merge({}, { count: true, refs: '*' }, options.modelOpts)
6
8
  model = pascalCase(model ?? req.params.model)
7
9
  const { schema } = await getSchemaExt(model, 'list', merge({}, { params }, options))
8
10
  if (schema.disabled.includes('find')) return await reply.view(templateDisabled, { action: 'list' })
@@ -13,7 +15,7 @@ async function listHandler ({ req, reply, model, template, params = {}, addOnsHa
13
15
  }
14
16
  if (!req.query[qsKey.page]) req.query[qsKey.page] = 1
15
17
  // req.query.attachment = true
16
- const list = await findRecord({ model, req, options: { count: true, refs: '*' } })
18
+ const list = await findRecord({ model, req, options: opts })
17
19
  let addOns = []
18
20
  if (addOnsHandler) {
19
21
  addOns = await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: list, schema, options })
@@ -170,9 +170,9 @@ const handler = {
170
170
  async function getSchemaExt (modelName, view, options = {}) {
171
171
  const { readConfig } = this.app.bajo
172
172
  const { defaultsDeep } = this.app.lib.aneka
173
- const { pick } = this.app.lib._
173
+ const { pick, isString } = this.app.lib._
174
174
 
175
- const model = this.app.dobo.getModel(modelName)
175
+ const model = isString(modelName) ? this.app.dobo.getModel(modelName) : modelName
176
176
  const schema = pick(model, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view', 'hidden'])
177
177
  const base = path.basename(model.file, path.extname(model.file))
178
178
  let ext = await readConfig(`${model.plugin.ns}:/extend/waibuDb/schema/${base}.*`, { ignoreError: true, options })
package/lib/prep-crud.js CHANGED
@@ -2,7 +2,7 @@ async function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
2
2
  const { isSet } = this.app.lib.aneka
3
3
  const { parseFilter } = this.app.waibu
4
4
  const { pascalCase } = this.app.lib.aneka
5
- const { cloneDeep, has } = this.app.lib._
5
+ const { cloneDeep, has, isString } = this.app.lib._
6
6
  const { parseObject } = this.app.lib
7
7
  const cfgWeb = this.app.waibu.getConfig()
8
8
  const opts = cloneDeep(options)
@@ -28,8 +28,11 @@ async function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
28
28
  if (refs.length > 0) options.refs = refs
29
29
 
30
30
  const recId = id ?? params.id ?? req.query.id
31
- model = model ?? pascalCase(params.model)
32
- const mdl = this.app.dobo.getModel(model)
31
+ let mdl = model
32
+ if (isString(model)) {
33
+ model = model ?? pascalCase(params.model)
34
+ mdl = this.app.dobo.getModel(model)
35
+ }
33
36
  const input = await mdl.sanitizeBody({ body: body ?? params.body, partial: true, strict: true })
34
37
 
35
38
  opts.bboxLatField = req.query[cfgWeb.qsKey.bboxLatField]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.1.7",
3
+ "version": "2.2.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-01-24
4
+
5
+ - [2.2.0] Model's option can now be sent through ```modelOpts``` object in ```options``` handler
6
+ - [2.2.0] ```prepCrud()``` now accept model instance or model name only
7
+ - [2.2.0] ```getSchemaExt``` now accept model instance or model name only
8
+
3
9
  ## 2026-01-21
4
10
 
5
11
  - [2.1.7] Bug fix on page titles