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