waibu-db 1.1.0 → 1.1.2

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.0",
3
+ "version": "1.1.2",
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))
@@ -4,7 +4,7 @@ async function table () {
4
4
  const WdbBase = await wdbBase.call(this)
5
5
 
6
6
  return class WdbTable extends WdbBase {
7
- isRightAligned (field, schema) {
7
+ isRightAligned = (field, schema) => {
8
8
  const { get, find } = this.plugin.app.bajo.lib._
9
9
  const prop = find(schema.properties, { name: field })
10
10
  if (!prop) return false
@@ -13,7 +13,7 @@ async function table () {
13
13
  return value
14
14
  }
15
15
 
16
- isNoWrap (field, schema) {
16
+ isNoWrap = (field, schema) => {
17
17
  const { get } = this.plugin.app.bajo.lib._
18
18
  return get(schema, 'view.noWrap', []).includes(field)
19
19
  }
@@ -140,7 +140,7 @@ async function table () {
140
140
  const formatter = get(schema, `view.formatter.${f}`)
141
141
  if (formatter) {
142
142
  if (isFunction(formatter)) value = await formatter(dataValue, d)
143
- else value = await callHandler(formatter, req, dataValue, d)
143
+ else value = await callHandler(this.plugin.app[schema.ns], formatter, req, dataValue, d)
144
144
  value = await this.component.buildSentence(value)
145
145
  }
146
146
  const line = await this.component.buildTag({ tag: 'td', attr, html: value })