bajo 2.12.0 → 2.13.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/class/bajo.js +30 -17
- package/class/plugin/err.js +4 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/class/bajo.js
CHANGED
|
@@ -851,42 +851,55 @@ class Bajo extends Plugin {
|
|
|
851
851
|
readConfig = async (file, options = {}) => {
|
|
852
852
|
const { parseObject } = this.app.lib
|
|
853
853
|
const { defaultsDeep } = this.app.lib.aneka
|
|
854
|
-
const { uniq, isString, isArray, findIndex, isPlainObject } = this.app.lib._
|
|
855
|
-
let { ns, baseNs, extend, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
854
|
+
const { uniq, isString, isArray, findIndex, isPlainObject, merge } = this.app.lib._
|
|
855
|
+
let { ns, baseNs, extend, checkOverride, merge: merged, pattern, ignoreError = true, defValue = {}, parserOpts = {}, globOpts = {} } = options
|
|
856
|
+
|
|
857
|
+
const getParseOptsArgs = (opts, orig) => {
|
|
858
|
+
opts.parserOpts = opts.parserOpts ?? {}
|
|
859
|
+
opts.parserOpts.args = opts.parserOpts.args ?? []
|
|
860
|
+
const idx = findIndex(opts.parserOpts.args, item => {
|
|
861
|
+
return isPlainObject(item) && Object.keys(item)[0] === '_orig'
|
|
862
|
+
})
|
|
863
|
+
if (idx > -1) opts.parserOpts.args[idx] = { _orig: orig }
|
|
864
|
+
else opts.parserOpts.args.push({ _orig: orig })
|
|
865
|
+
}
|
|
856
866
|
|
|
857
867
|
const output = async (obj) => {
|
|
858
|
-
|
|
868
|
+
let orig = parseObject(obj)
|
|
859
869
|
if (!baseNs || extend === false) return orig
|
|
860
870
|
const { suffix = '', keys = [] } = options
|
|
861
871
|
let bases = this.app.getAllNs()
|
|
862
872
|
if (isString(extend)) extend = extend.split(',').map(i => i.trim)
|
|
863
873
|
if (isArray(extend)) bases = [...extend, 'main']
|
|
864
874
|
bases = uniq(bases)
|
|
865
|
-
let ext = isArray(
|
|
875
|
+
let ext = isArray(orig) ? [] : {}
|
|
866
876
|
const dir = this.app[ns].dir.pkg
|
|
867
877
|
let [names, _path] = file.split(':')
|
|
868
878
|
if (file.slice(0, names.length + 1) !== `${ns}:`) _path = file.slice(dir.length + 1)
|
|
869
879
|
if (_path.startsWith('extend/')) _path = _path.slice(7)
|
|
870
880
|
if (_path.startsWith(`${baseNs}/`)) _path = _path.slice(baseNs.length + 1)
|
|
871
881
|
_path = _path.slice(0, -(path.extname(_path).length)) + '.*'
|
|
882
|
+
// check for override? Override only exists in main plugin
|
|
872
883
|
const opts = omit(options, ['suffix', 'keys', 'extend'])
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
884
|
+
if (checkOverride) {
|
|
885
|
+
getParseOptsArgs(opts, orig)
|
|
886
|
+
const fileExt = `${this.app.main.dir.pkg}/extend/${baseNs}/override/${ns}${suffix}/${_path}`
|
|
887
|
+
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, checkOverride: false, merge: false }))
|
|
888
|
+
if (!isEmpty(result)) orig = result
|
|
889
|
+
}
|
|
890
|
+
getParseOptsArgs(opts, orig)
|
|
891
|
+
const binder = merged ? merge : defaultsDeep
|
|
881
892
|
for (const base of bases) {
|
|
882
893
|
if (!this.app[base]) continue
|
|
883
894
|
const fileExt = `${this.app[base].dir.pkg}/extend/${baseNs}/extend/${ns}${suffix}/${_path}`
|
|
884
|
-
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false }))
|
|
895
|
+
const result = parseObject(await this.readConfig(fileExt, { ...opts, extend: false, merge: false }))
|
|
885
896
|
if (isEmpty(result)) continue
|
|
886
897
|
if (isArray(result)) ext = [...result, ...ext]
|
|
887
|
-
else ext =
|
|
898
|
+
else ext = binder({}, result, ext)
|
|
888
899
|
}
|
|
889
|
-
|
|
900
|
+
if (isArray(orig)) return [...orig, ...ext]
|
|
901
|
+
const item = keys.length > 0 ? pick(ext, keys) : ext
|
|
902
|
+
return binder({}, item, orig)
|
|
890
903
|
}
|
|
891
904
|
|
|
892
905
|
parserOpts.readFromFile = true
|
|
@@ -983,13 +996,13 @@ class Bajo extends Plugin {
|
|
|
983
996
|
let ext = {}
|
|
984
997
|
// default config file
|
|
985
998
|
try {
|
|
986
|
-
cfg = await this.readConfig(`${path}
|
|
999
|
+
cfg = await this.readConfig(`${path}.*`)
|
|
987
1000
|
} catch (err) {
|
|
988
1001
|
if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
|
|
989
1002
|
}
|
|
990
1003
|
// env based config file
|
|
991
1004
|
try {
|
|
992
|
-
ext = await this.readConfig(`${path}-${this.config.env}
|
|
1005
|
+
ext = await this.readConfig(`${path}-${this.config.env}.*`)
|
|
993
1006
|
} catch (err) {
|
|
994
1007
|
if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
|
|
995
1008
|
}
|
package/class/plugin/err.js
CHANGED
|
@@ -103,7 +103,10 @@ class Err extends Tools {
|
|
|
103
103
|
const detailsMessage = []
|
|
104
104
|
each(value, (v, i) => {
|
|
105
105
|
if (isString(v)) v = { error: v }
|
|
106
|
-
if (!v.context)
|
|
106
|
+
if (!v.context) {
|
|
107
|
+
v.error = me.plugin.t(v.error)
|
|
108
|
+
return undefined
|
|
109
|
+
}
|
|
107
110
|
v.context.message = v.message
|
|
108
111
|
if (v.type === 'any.only') {
|
|
109
112
|
const items = without(get(v, 'context.valids', []))
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-28
|
|
4
|
+
|
|
5
|
+
- [2.13.0] Add ```options.merge``` to ```readConfig()```
|
|
6
|
+
- [2.13.0] Bug fix in ```err.js```
|
|
7
|
+
|
|
8
|
+
## 2026-04-25
|
|
9
|
+
|
|
10
|
+
- [2.12.1] Bug fix in ```readConfig()```
|
|
11
|
+
|
|
3
12
|
## 2026-04-23
|
|
4
13
|
|
|
5
14
|
- [2.12.0] Remove ```breakNsPathFromFile()```
|