waibu-db 2.1.6 → 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.
- package/index.js +2 -2
- package/lib/crud/add-handler.js +1 -1
- package/lib/crud/delete-handler.js +1 -1
- package/lib/crud/details-handler.js +1 -1
- package/lib/crud/edit-handler.js +1 -1
- package/lib/crud/helper/build-params.js +1 -1
- package/lib/crud/list-handler.js +3 -1
- package/lib/method/get-schema-ext.js +2 -2
- package/lib/prep-crud.js +6 -3
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
package/index.js
CHANGED
|
@@ -96,7 +96,7 @@ async function factory (pkgName) {
|
|
|
96
96
|
adminMenu = async (locals, req) => {
|
|
97
97
|
const { getPluginPrefix } = this.app.waibu
|
|
98
98
|
const { pascalCase } = this.app.lib.aneka
|
|
99
|
-
const {
|
|
99
|
+
const { getPluginTitle } = this.app.waibuMpa
|
|
100
100
|
const { camelCase, map, groupBy, keys, kebabCase, filter, get, isArray } = this.app.lib._
|
|
101
101
|
|
|
102
102
|
const prefix = getPluginPrefix(this.ns)
|
|
@@ -112,7 +112,7 @@ async function factory (pkgName) {
|
|
|
112
112
|
})
|
|
113
113
|
const omenu = groupBy(map(models, s => {
|
|
114
114
|
const item = { name: s.name, ns: s.plugin.ns }
|
|
115
|
-
item.nsTitle =
|
|
115
|
+
item.nsTitle = getPluginTitle(s.plugin.ns)
|
|
116
116
|
return item
|
|
117
117
|
}), 'nsTitle')
|
|
118
118
|
const menu = []
|
package/lib/crud/add-handler.js
CHANGED
|
@@ -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' })
|
package/lib/crud/edit-handler.js
CHANGED
|
@@ -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
|
|
@@ -2,7 +2,7 @@ function buildParams ({ model, req, reply, action, options = {} }) {
|
|
|
2
2
|
const { camelCase, kebabCase, map, upperFirst, get } = this.app.lib._
|
|
3
3
|
const [, ...names] = map(kebabCase(model).split('-'), n => upperFirst(n))
|
|
4
4
|
const mdl = this.app.dobo.getModel(model)
|
|
5
|
-
const prefix = this.app.waibuMpa ? this.app.waibuMpa.
|
|
5
|
+
const prefix = this.app.waibuMpa ? this.app.waibuMpa.getPluginTitle(mdl.plugin.ns) : mdl.plugin.ns
|
|
6
6
|
const modelTitle = req.t(prefix) + ': ' + req.t(camelCase(names.join(' ')))
|
|
7
7
|
const page = {
|
|
8
8
|
title: req.t(get(req, 'routeOptions.config.title', this.app[mdl.plugin.ns].title)),
|
package/lib/crud/list-handler.js
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
32
|
-
|
|
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
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
9
|
+
## 2026-01-21
|
|
10
|
+
|
|
11
|
+
- [2.1.7] Bug fix on page titles
|
|
12
|
+
|
|
3
13
|
## 2026-01-19
|
|
4
14
|
|
|
5
15
|
- [2.1.6] Bug fix on app title
|