waibu-db 1.1.1 → 1.1.3

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.
@@ -2,7 +2,7 @@ async function addHandler ({ req, reply, model, params = {}, template, addOnsHan
2
2
  const { pascalCase } = this.app.bajo
3
3
  const { recordCreate, recordGet, getSchemaExt } = this.app.waibuDb
4
4
  const { buildUrl } = this.app.waibuMpa
5
- const { pick, map, merge, defaultsDeep, omit, isEmpty } = this.app.bajo.lib._
5
+ const { pick, map, merge, defaultsDeep, omit, isEmpty } = this.lib._
6
6
  const options = {}
7
7
  model = model ?? pascalCase(req.params.model)
8
8
  const { schema } = await getSchemaExt(model, 'add', options)
@@ -18,7 +18,7 @@ const handler = {
18
18
  }
19
19
 
20
20
  async function allHandler ({ model, action, req, reply, template, params = {} }) {
21
- const { upperFirst, merge, keys } = this.app.bajo.lib._
21
+ const { upperFirst, merge, keys } = this.lib._
22
22
  if (!keys(handler).includes(action)) throw this.error('_notFound')
23
23
  if (['delete', 'export'].includes(action)) {
24
24
  if (req.method === 'GET') throw this.error('_notFound')
@@ -2,7 +2,7 @@ async function deleteHandler ({ req, reply, model, params = {}, templateDisabled
2
2
  const { pascalCase } = this.app.bajo
3
3
  const { recordRemove, getSchemaExt } = this.app.waibuDb
4
4
  const { buildUrl } = this.app.waibuMpa
5
- const { reduce } = this.app.bajo.lib._
5
+ const { reduce } = this.lib._
6
6
  const options = {}
7
7
  model = model ?? pascalCase(req.params.model)
8
8
  const { schema } = await getSchemaExt(model, 'add', options)
@@ -1,7 +1,7 @@
1
1
  async function detailsHandler ({ req, reply, model, params = {}, template, addOnsHandler, templateDisabled = 'waibuDb.template:/disabled.html' } = {}) {
2
2
  const { pascalCase } = this.app.bajo
3
3
  const { recordGet, getSchemaExt } = this.app.waibuDb
4
- const { merge } = this.app.bajo.lib._
4
+ const { merge } = this.lib._
5
5
  const options = {}
6
6
  model = model ?? pascalCase(req.params.model)
7
7
  const { schema } = await getSchemaExt(model, 'details', options)
@@ -2,7 +2,7 @@ async function editHandler ({ req, reply, model, params = {}, template, addOnsHa
2
2
  const { pascalCase } = this.app.bajo
3
3
  const { recordUpdate, recordGet, getSchemaExt } = this.app.waibuDb
4
4
  const { buildUrl } = this.app.waibuMpa
5
- const { merge, defaultsDeep } = this.app.bajo.lib._
5
+ const { merge, defaultsDeep } = this.lib._
6
6
  const options = {}
7
7
  model = model ?? pascalCase(req.params.model)
8
8
  const { schema } = await getSchemaExt(model, 'edit', options)
@@ -1,7 +1,7 @@
1
1
  async function addOnsHandler ({ req, reply, data, schema }) {
2
2
  const { base64JsonEncode } = this.app.waibuMpa
3
3
  const { statAggregate } = this.app.waibuDb
4
- const { get, map, pick, pullAt } = this.app.bajo.lib._
4
+ const { get, map, pick, pullAt } = this.lib._
5
5
  const opts = map(get(schema, 'view.stat.aggregate', []), item => {
6
6
  const dbOpts = pick(item, ['fields', 'group', 'aggregate'])
7
7
  const name = item.name ?? `field.${item.fields[0]}`
@@ -1,5 +1,5 @@
1
1
  function buildParams ({ model, req, reply, action }) {
2
- const { camelCase, kebabCase, map, upperFirst, get } = this.app.bajo.lib._
2
+ const { camelCase, kebabCase, map, upperFirst, get } = this.lib._
3
3
  const { getSchema } = this.app.dobo
4
4
  const [alias, ...names] = map(kebabCase(model).split('-'), n => upperFirst(n))
5
5
  const schema = getSchema(camelCase(model), false)
@@ -1,7 +1,7 @@
1
1
  async function listHandler ({ req, reply, model, template, params = {}, addOnsHandler, templateDisabled = 'waibuDb.template:/disabled.html' } = {}) {
2
2
  const { pascalCase } = this.app.bajo
3
3
  const { recordFind, getSchemaExt } = this.app.waibuDb
4
- const { get, merge, isArray, upperFirst } = this.app.bajo.lib._
4
+ const { get, merge, isArray, upperFirst } = this.lib._
5
5
  const qsKey = this.app.waibu.config.qsKey
6
6
  const options = { count: true }
7
7
  model = model ?? pascalCase(req.params.model)
package/lib/prep-crud.js CHANGED
@@ -1,7 +1,7 @@
1
1
  function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
2
2
  const { parseFilter } = this.app.waibu
3
3
  const { pascalCase } = this.app.bajo
4
- const { cloneDeep, has } = this.app.bajo.lib._
4
+ const { cloneDeep, has } = this.lib._
5
5
  const cfgWeb = this.app.waibu.config
6
6
  const opts = cloneDeep(options)
7
7
  const params = this.getParams(req, ...args)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,7 +2,7 @@ function modelsMenu (req) {
2
2
  const { getPluginPrefix } = this.app.waibu
3
3
  const { titleize, pascalCase } = this.app.bajo
4
4
  const { getAppTitle } = this.app.waibuMpa
5
- const { map, pick, groupBy, keys, kebabCase, filter, get } = this.app.bajo.lib._
5
+ const { map, pick, groupBy, keys, kebabCase, filter, get } = this.lib._
6
6
 
7
7
  const prefix = getPluginPrefix(this.name)
8
8
  const schemas = filter(this.app.dobo.schemas, s => {
@@ -1,5 +1,5 @@
1
1
  async function getLookupData ({ model, req, data, id = 'id', field, query }) {
2
- const { set, map } = this.app.bajo.lib._
2
+ const { set, map } = this.lib._
3
3
  const $in = map(data, id)
4
4
  const q = query ?? set({}, field, { $in })
5
5
  const options = {
@@ -1,5 +1,5 @@
1
1
  function getParams (req, ...items) {
2
- const { map, trim, get } = this.app.bajo.lib._
2
+ const { map, trim, get } = this.lib._
3
3
  let fields
4
4
  req.query = req.query ?? {}
5
5
  req.params = req.params ?? {}
@@ -3,7 +3,7 @@ import path from 'path'
3
3
  const defReadonly = ['id', 'createdAt', 'updatedAt']
4
4
 
5
5
  function getCommons (action, schema, ext, opts = {}) {
6
- const { map, get, set, without, uniq } = this.app.bajo.lib._
6
+ const { map, get, set, without, uniq } = this.lib._
7
7
  const label = get(ext, `view.${action}.label`, get(ext, 'common.label', {}))
8
8
  const hidden = get(ext, `view.${action}.hidden`, get(ext, 'common.hidden', []))
9
9
  hidden.push(...schema.hidden, ...(opts.hidden ?? []))
@@ -37,7 +37,7 @@ function autoLayout ({ action, schema, ext, layout, allWidgets }) {
37
37
  }
38
38
 
39
39
  function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
40
- const { find, omit, merge, isString } = this.app.bajo.lib._
40
+ const { find, omit, merge, isString } = this.lib._
41
41
  const items = [...layout]
42
42
  layout.splice(0, layout.length)
43
43
  for (const item of items) {
@@ -58,7 +58,7 @@ function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
58
58
  }
59
59
 
60
60
  function applyLayout (action, schema, ext) {
61
- const { set, get, isEmpty, map, find } = this.app.bajo.lib._
61
+ const { set, get, isEmpty, map, find } = this.lib._
62
62
  const { fields, label } = getCommons.call(this, action, schema, ext)
63
63
  const layout = get(ext, `view.${action}.layout`, get(ext, 'common.layout', []))
64
64
  const readonly = get(ext, `view.${action}.readonly`, get(ext, 'common.readonly', defReadonly))
@@ -95,7 +95,7 @@ function applyLayout (action, schema, ext) {
95
95
 
96
96
  const handler = {
97
97
  list: async function (schema, ext, opts) {
98
- const { get, set } = this.app.bajo.lib._
98
+ const { get, set } = this.lib._
99
99
  const { fields, label } = getCommons.call(this, 'list', schema, ext, opts)
100
100
  const qsFields = []
101
101
  for (const f of get(schema, 'view.qs.fields', '').split(',')) {
@@ -123,7 +123,7 @@ const handler = {
123
123
  async function getSchemaExt (model, view, opts) {
124
124
  const { readConfig } = this.app.bajo
125
125
  const { getSchema } = this.app.dobo
126
- const { pick } = this.app.bajo.lib._
126
+ const { pick } = this.lib._
127
127
 
128
128
  let schema = getSchema(model)
129
129
  const base = path.basename(schema.file, path.extname(schema.file))
@@ -23,7 +23,7 @@ async function table () {
23
23
  const { callHandler } = this.plugin.app.bajo
24
24
  const { escape } = this.plugin.app.waibu
25
25
  const { attrToArray, groupAttrs } = this.plugin.app.waibuMpa
26
- const { get, omit, set, find, isEmpty, without, isFunction } = this.plugin.app.bajo.lib._
26
+ const { get, omit, set, find, isEmpty, without, isFunction, merge } = this.plugin.app.bajo.lib._
27
27
  const group = groupAttrs(this.params.attr, ['body', 'head', 'foot'])
28
28
  this.params.attr = group._
29
29
  const prettyUrl = this.params.attr.prettyUrl
@@ -127,6 +127,8 @@ async function table () {
127
127
  if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
128
128
  if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
129
129
  const attr = { dataValue, dataKey: prop.name, dataType: prop.type, style: { cursor: 'pointer' } }
130
+ const cellFormatter = get(schema, `view.cellFormatter.${f}`)
131
+ if (cellFormatter) merge(attr, await cellFormatter(dataValue, d))
130
132
  if (!['object', 'array'].includes(prop.type)) {
131
133
  const noWrap = this.isNoWrap(f, schema) ? 'nowrap' : ''
132
134
  if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
@@ -140,13 +142,13 @@ async function table () {
140
142
  const formatter = get(schema, `view.formatter.${f}`)
141
143
  if (formatter) {
142
144
  if (isFunction(formatter)) value = await formatter(dataValue, d)
143
- else value = await callHandler(this.plugin.app[schema.ns], formatter, req, dataValue, d)
145
+ else value = await callHandler(formatter, req, dataValue, d)
144
146
  value = await this.component.buildSentence(value)
145
147
  }
146
148
  const line = await this.component.buildTag({ tag: 'td', attr, html: value })
147
149
  lines.push(line)
148
150
  }
149
- const attr = {}
151
+ const attr = { id: `rec-${d.id}` }
150
152
  if (!disableds.includes('update') || !disableds.includes('remove')) attr['@click'] = `toggle('${d.id}')`
151
153
  if (!disableds.includes('get')) attr['@dblclick'] = `goDetails('${d.id}')`
152
154
  items.push(await this.component.buildTag({ tag: 'tr', attr, html: lines.join('\n') }))