waibu-db 2.34.4 → 2.35.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.
@@ -1,7 +1,5 @@
1
1
  <c:card border>
2
- <c:card-header>
3
- <c:card-title t:content="<%= attr.name %>" />
4
- </c:card-header>
2
+ <c:card-header tag="h6" t:content="<%= attr.name %>" />
5
3
  <c:card-body>
6
4
  <c:wdb-echarts style="height: 150px;" setting="<%= attr.setting %>">
7
5
  </c:wdb-echarts>
@@ -24,7 +24,7 @@ async function table () {
24
24
  const { escape, attrToArray } = this.app.waibu
25
25
  const { groupAttrs } = this.app.waibuMpa
26
26
  const { isHtmlLink } = this.app.bajoExtra
27
- const { getTruncated } = this.app.bajoTemplate
27
+ const { createTruncatedText } = this.app.lib.aneka
28
28
  const { get, omit, set, find, isEmpty, without, merge, intersection, isPlainObject } = this.app.lib._
29
29
  const { isSet } = this.app.lib.aneka
30
30
  const group = groupAttrs(this.params.attr, ['body', 'head', 'foot'])
@@ -168,7 +168,7 @@ async function table () {
168
168
  }
169
169
  value = formatted
170
170
  }
171
- if (['object', 'array'].includes(prop.type) && !isHtmlLink(value)) value = getTruncated(value, 20) // TODO: should be handle by css instead
171
+ if (['object', 'array'].includes(prop.type) && !isHtmlLink(value)) value = createTruncatedText(value, 20) // TODO: should be handle by css instead
172
172
  if (!get(this.schema, 'view.noEscape', []).includes(f) && !isHtmlLink(value)) value = escape(value)
173
173
  const line = await buildTag({ tag: 'td', attr, html: value })
174
174
  lines.push(line)
@@ -198,27 +198,32 @@ async function query () {
198
198
  } else {
199
199
  let placeholder = this.params.attr.placeholder
200
200
  if (!placeholder) placeholder = scanables.length > 0 ? req.t('queryHint%s', join(scanables, { separator: ', ', lastSeparator: 'or' })) : req.t('query')
201
+ const submitBtn = `
202
+ <c:form-input-addon>
203
+ <c:btn t:content="submit" @click="submit" @on-submit.window="submit()" />
204
+ </c:form-input-addon>`
201
205
  this.params.html = await this.component.buildSentence(`
202
- <c:form-input type="search" placeholder="${placeholder}" id="${id}" x-data="{ query: '' }" x-init="
206
+ <c:div x-data="{
207
+ query: '',
208
+ submit () {
209
+ const val = document.getElementById('${id}').value ?? ''
210
+ const url = new URL(window.location.href)
211
+ const params = new URLSearchParams(url.search)
212
+ params.set('${qsKey.page}', 1)
213
+ params.set('${qsKey.query}', val)
214
+ window.location.href = '?' + params.toString()
215
+ }
216
+ }" x-init="
203
217
  const url = new URL(window.location.href)
204
218
  query = url.searchParams.get('${qsKey.query}') ?? ''
205
- " x-model="query" @on-query.window="query = $event.detail ?? ''" @keyup.enter="$dispatch('on-submit')">
206
- <c:form-input-addon>
207
- ${this.modal({ container, models, columns, fields, id })}
208
- </c:form-input-addon>
209
- <c:form-input-addon>
210
- <c:btn t:content="submit" x-data="{
211
- submit () {
212
- const val = document.getElementById('${id}').value ?? ''
213
- const url = new URL(window.location.href)
214
- const params = new URLSearchParams(url.search)
215
- params.set('${qsKey.page}', 1)
216
- params.set('${qsKey.query}', val)
217
- window.location.href = '?' + params.toString()
218
- }
219
- }" @click="submit" @on-submit.window="submit()" />
220
- </c:form-input-addon>
221
- </c:form-input>
219
+ ">
220
+ <c:form-input type="search" placeholder="${placeholder}" id="${id}" x-model="query" @on-query.window="query = $event.detail ?? ''" @keyup.enter="submit()">
221
+ <c:form-input-addon>
222
+ ${this.modal({ container, models, columns, fields, id })}
223
+ </c:form-input-addon>
224
+ ${this.params.attr.noSubmitButton ? '' : submitBtn}
225
+ </c:form-input>
226
+ </c:div>
222
227
  `)
223
228
  }
224
229
  }
@@ -1,12 +1,13 @@
1
1
  import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function createRecord ({ model, req, body, reply, options = {}, transaction } = {}) {
4
- const { model: mdl, opts, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, opts, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
5
6
 
6
7
  async function handler (trx) {
7
8
  if (opts.trx === true) opts.trx = trx
8
- const ret = await mdl.createRecord(body ?? req.body, { ...opts, partial: true, strict: true })
9
- if (attachment) ret.data._attachment = await mdl.findAttachment(ret.data.id, { stats, mimeType })
9
+ const ret = await mdl.createRecord(body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
10
+ if (!isEmpty(attachment)) ret.data._attachment = await mdl.findAttachment(ret.data.id, attachment)
10
11
  return ret
11
12
  }
12
13
 
@@ -1,14 +1,15 @@
1
1
  import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findAllRecord ({ model, req, reply, options = {}, noAutoFilter, transaction } = {}) {
4
- const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
5
6
 
6
7
  async function handler (trx) {
7
8
  if (opts.trx === true) opts.trx = trx
8
- const ret = await mdl.findAllRecord(filter, opts)
9
- if (attachment) {
9
+ const ret = await mdl.findAllRecord(filter, { ...opts, dataOnly: false })
10
+ if (!isEmpty(attachment)) {
10
11
  for (const d of ret.data) {
11
- d._attachment = await mdl.findAttachment(d.id, { stats, mimeType })
12
+ d._attachment = await mdl.findAttachment(d.id, attachment)
12
13
  }
13
14
  }
14
15
  return ret
@@ -1,12 +1,13 @@
1
1
  import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findOneRecord ({ model, req, reply, options = {}, noAutoFilter, transaction } = {}) {
4
- const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
5
6
 
6
7
  async function handler (trx) {
7
8
  if (opts.trx === true) opts.trx = trx
8
- const ret = await mdl.findOneRecord(filter, opts)
9
- if (attachment) ret.data._attachment = await mdl.findAttachment(ret.data.id, { stats, mimeType })
9
+ const ret = await mdl.findOneRecord(filter, { ...opts, dataOnly: false })
10
+ if (!isEmpty(attachment)) ret.data._attachment = await mdl.findAttachment(ret.data.id, attachment)
10
11
  return ret
11
12
  }
12
13
 
@@ -1,14 +1,15 @@
1
1
  import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findRecord ({ model, req, reply, noAutoFilter, options = {}, transaction } = {}) {
4
- const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, opts, filter, attachment } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], noAutoFilter, transaction })
5
6
 
6
7
  async function handler (trx) {
7
8
  if (opts.trx === true) opts.trx = trx
8
- const ret = await mdl.findRecord(filter, opts)
9
- if (attachment) {
9
+ const ret = await mdl.findRecord(filter, { ...opts, dataOnly: false })
10
+ if (!isEmpty(attachment)) {
10
11
  for (const d of ret.data) {
11
- d._attachment = await mdl.findAttachment(d.id, { stats, mimeType })
12
+ d._attachment = await mdl.findAttachment(d.id, attachment)
12
13
  }
13
14
  }
14
15
  return ret
@@ -1,13 +1,14 @@
1
1
  import { prepCrud, getOneRecord, processHandler } from '../util.js'
2
2
 
3
3
  async function getRecord ({ model, req, reply, id, options = {}, transaction, noAutoFilter } = {}) {
4
- const { model: mdl, recId, filter, attachment, stats, mimeType, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction, noAutoFilter })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, recId, filter, attachment, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction, noAutoFilter })
5
6
  const me = this
6
7
 
7
8
  async function handler (trx) {
8
9
  if (opts.trx === true) opts.trx = trx
9
- const data = await getOneRecord.call(me, mdl, recId, filter, opts)
10
- if (attachment) data._attachment = await mdl.findAttachment(data.id, { stats, mimeType })
10
+ const data = await getOneRecord.call(me, mdl, recId, filter, { ...opts, dataOnly: false })
11
+ if (!isEmpty(attachment)) data._attachment = await mdl.findAttachment(data.id, attachment)
11
12
  return data
12
13
  }
13
14
 
@@ -1,17 +1,18 @@
1
1
  import { prepCrud, getOneRecord, processHandler } from '../util.js'
2
2
 
3
3
  async function updateRecord ({ model, req, reply, id, body, options = {}, transaction } = {}) {
4
- const { model: mdl, filter, opts, recId, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction })
4
+ const { isEmpty } = this.app.lib._
5
+ const { model: mdl, filter, opts, recId, attachment } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction })
5
6
  const me = this
6
7
 
7
8
  async function handler (trx) {
8
9
  if (opts.trx === true) opts.trx = trx
9
10
  if (!opts._data) {
10
- const resp = await getOneRecord.call(me, mdl, recId, filter, opts)
11
+ const resp = await getOneRecord.call(me, mdl, recId, filter, { ...opts, dataOnly: false })
11
12
  opts._data = resp.data
12
13
  }
13
- const ret = await mdl.updateRecord(recId, body ?? req.body, { ...opts, partial: true, strict: true })
14
- if (attachment) ret.data._attachment = await mdl.findAttachment(id, { stats, mimeType })
14
+ const ret = await mdl.updateRecord(recId, body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
15
+ if (!isEmpty(attachment)) ret.data._attachment = await mdl.findAttachment(recId, attachment)
15
16
  return ret
16
17
  }
17
18
 
package/lib/util.js CHANGED
@@ -54,12 +54,12 @@ export async function prepCrud (options = {}) {
54
54
  const { importModule } = this.app.bajo
55
55
  const { parseFilter } = this.app.waibu
56
56
  const { pascalCase } = this.app.lib.aneka
57
- const { cloneDeep, has, isString, omit } = this.app.lib._
57
+ const { cloneDeep, has, isString, omit, merge } = this.app.lib._
58
58
  const { parseObject } = this.app.lib
59
59
  const { buildFilterQuery, buildFilterSearch } = await importModule('dobo:/lib/factory/model/helper.js', { asDefaultImport: false })
60
60
 
61
61
  const cfgWeb = this.app.waibu.getConfig()
62
- const opts = cloneDeep(omit(_options, ['trx']))
62
+ const opts = cloneDeep(omit(_options, ['trx', 'query', 'search', 'mergeQuery', 'limit', 'sort', 'page']))
63
63
  opts.throwNotFound = true
64
64
  if (opts.suppressError === true) opts.suppressError = actions
65
65
  else if (isString(opts.suppressError)) opts.suppressError = [opts.suppressError]
@@ -74,10 +74,10 @@ export async function prepCrud (options = {}) {
74
74
  opts.reply = reply
75
75
  opts.trx = opts.trx ?? _options.trx ?? transaction ?? true
76
76
 
77
- let { attachment, stats, mimeType } = opts
78
- attachment = attachment ?? req.query.attachment
79
- stats = stats ?? req.query.stats
80
- mimeType = mimeType ?? req.query.mimeType
77
+ let attachment = opts.attachment ?? req.query.attachment ?? {}
78
+ if (attachment === true) attachment = { stats: true, mimeType: true, thumbnail: true }
79
+ attachment.stats = attachment.stats ?? req.query.stats
80
+ attachment.mimeType = attachment.mimeType ?? req.query.mimeType
81
81
 
82
82
  let refs = []
83
83
  const headers = parseObject(req.headers, { parseValue: true })
@@ -101,14 +101,19 @@ export async function prepCrud (options = {}) {
101
101
  filter.query = buildFilterQuery.call(mdl, filter)
102
102
  filter.search = buildFilterSearch.call(mdl, filter)
103
103
  }
104
- if (_options.query) filter.query = cloneDeep(_options.query)
104
+ if (_options.query) {
105
+ if (_options.mergeQuery) {
106
+ if (filter.query.$and) filter.query.$and.push(_options.query)
107
+ else filter.query = merge({}, filter.query, _options.query)
108
+ } else filter.query = cloneDeep(_options.query)
109
+ }
105
110
  if (_options.search) filter.search = cloneDeep(_options.search)
106
111
  if (_options.limit) filter.limit = _options.limit
107
112
  if (_options.sort) filter.sort = _options.sort
108
113
  if (_options.page) filter.page = _options.page
109
114
  if (opts.fields && opts.fields.length > 0 && mdl.hasProperty('_immutable')) opts.fields.push('_immutable')
110
115
  const input = cloneDeep(req.body) ?? {}
111
- return { model: mdl, input, recId, opts, filter, attachment, stats, mimeType }
116
+ return { model: mdl, input, recId, opts, filter, attachment }
112
117
  }
113
118
 
114
119
  /**
@@ -165,7 +170,8 @@ export async function processHandler (opts = {}) {
165
170
  if (options.trx === true && ['createRecord', 'updateRecord', 'upsertRecord', 'removeRecord'].includes(action)) {
166
171
  return await model.transaction(handler, action, options)
167
172
  }
168
- return await handler()
173
+ const resp = await handler()
174
+ return options.dataOnly ? resp.data : resp
169
175
  } catch (err) {
170
176
  if (options.suppressError.includes(action)) return suppressedReturn.call(this, err)
171
177
  throw err
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.34.4",
3
+ "version": "2.35.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-11-20
4
+
5
+ - [2.35.0] `attachment` options can now accept plain object too
6
+ - [2.35.0] Bug fix in `attachment` handling
7
+ - [2.35.0] Bug fix in `dataOnly` handling
8
+ - [2.35.0] Submit button can be omitted in `query` widget
9
+
3
10
  ## 2026-11-08
4
11
 
5
12
  - [2.34.4] Bug fix in `echarts.js`