waibu 2.10.0 → 2.11.1

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 CHANGED
@@ -579,6 +579,20 @@ async function factory (pkgName) {
579
579
  })
580
580
  return result.join(delimiter)
581
581
  }
582
+
583
+ getSetting = (key, { defValue, req = {} } = {}) => {
584
+ const { breakNsPath } = this.app.bajo
585
+ const { get, isPlainObject, isArray } = this.app.lib._
586
+ const { defaultsDeep } = this.app.lib.aneka
587
+ let { ns, path } = breakNsPath(key)
588
+ const paths = path.replaceAll('/', '.').split('.')
589
+ if (paths[0] === '') paths.shift()
590
+ path = paths.join('.')
591
+ const cfgValue = get(this.app, `${ns}.config.${path}`)
592
+ const reqValue = get(req, `site.setting.${ns}.${path}`)
593
+ if (isPlainObject(cfgValue) || isArray(cfgValue)) return defaultsDeep({}, reqValue, cfgValue, defValue)
594
+ return reqValue ?? cfgValue ?? defValue
595
+ }
582
596
  }
583
597
 
584
598
  return Waibu
package/lib/decorate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  async function decorate () {
2
- const { get } = this.app.lib._
3
- const { breakNsPath } = this.app.bajo
2
+ const { isPlainObject, isArray } = this.app.lib._
3
+ const { defaultsDeep } = this.app.lib.aneka
4
4
  const me = this
5
5
  this.instance.decorateRequest('lang', null)
6
6
  this.instance.decorateRequest('t', () => {})
@@ -9,12 +9,9 @@ async function decorate () {
9
9
  this.instance.decorateRequest('site', null)
10
10
  this.instance.decorateRequest('ns', null)
11
11
  this.instance.decorateRequest('getSetting', function (key, defValue) {
12
- let { ns, path } = breakNsPath(key)
13
- const paths = path.replaceAll('/', '.').split('.')
14
- if (paths[0] === '') paths.shift()
15
- path = paths.join('.')
16
- const cfgValue = get(me.app, `${ns}.config.${path}`, defValue)
17
- return get(this, `site.setting.${ns}.${path}`, cfgValue)
12
+ const value = me.app.waibu.getSetting(key, { req: this })
13
+ if (isPlainObject(value) || isArray(value)) return defaultsDeep({}, value, defValue)
14
+ return value ?? defValue
18
15
  })
19
16
  }
20
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.10.0",
3
+ "version": "2.11.1",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-04-19
4
+
5
+ - [2.11.1] Bug fix in ```getSetting()```
6
+ - [2.11.1] Bug fix in ```decorate.js```
7
+
8
+ ## 2026-04-13
9
+
10
+ - [2.11.0] Add ```getSetting()```
11
+ - [2.11.0] ```req.getSetting()``` now accept setting ```site.setting``` too
12
+
3
13
  ## 2026-04-11
4
14
 
5
15
  - [2.10.0] Move all decorator to own file ```decorator.js```