waibu-rest-api 2.9.1 → 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/lib/route-by-model-builder.js +16 -10
- package/lib/route-by-verb.js +4 -9
- package/package.json +1 -1
- package/wiki/CHANGES.md +11 -0
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import serveRoute from './serve-route.js'
|
|
3
3
|
|
|
4
|
+
export function extractHeaders (req, options) {
|
|
5
|
+
const { parseObject } = this.app.lib
|
|
6
|
+
const { isSet } = this.app.lib.aneka
|
|
7
|
+
options.count = true
|
|
8
|
+
options.refs = []
|
|
9
|
+
const headers = parseObject(req.headers, { parseValue: true })
|
|
10
|
+
if (headers['x-no-count']) options.count = false
|
|
11
|
+
if (isSet(headers['x-refs'])) options.refs = headers['x-refs']
|
|
12
|
+
if (typeof options.refs === 'string' && !['*', 'all'].includes(options.refs)) options.refs = [options.refs]
|
|
13
|
+
if (headers['x-warnings']) options.showWarnings = true
|
|
14
|
+
if (headers['x-formatted'] || headers['x-fmt']) options.fmt = true
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
|
|
5
18
|
const { readConfig } = this.app.bajo
|
|
6
|
-
const {
|
|
7
|
-
const { isSet, pascalCase } = this.app.lib.aneka
|
|
19
|
+
const { pascalCase } = this.app.lib.aneka
|
|
8
20
|
const { methodMap, getParams } = this.app.waibuDb
|
|
9
21
|
const { isFunction, camelCase, omit, merge, keys, filter } = this.app.lib._
|
|
10
22
|
const builder = await readConfig(file, { ns, ignoreError: true })
|
|
@@ -36,14 +48,8 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
|
|
|
36
48
|
handler: async function (req, reply) {
|
|
37
49
|
const helper = me.app.waibuDb[`${method === 'replace' ? 'update' : method}Record`]
|
|
38
50
|
const { fields } = getParams(req)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const headers = parseObject(req.headers, { parseValue: true })
|
|
42
|
-
if (headers['x-nocount']) count = false
|
|
43
|
-
if (isSet(headers['x-refs'])) refs = headers['x-refs']
|
|
44
|
-
if (typeof refs === 'string' && !['*', 'all'].includes(refs)) refs = [refs]
|
|
45
|
-
const options = { fields, count, refs, dynHooks: builder.hooks ?? [] }
|
|
46
|
-
if (headers['x-warnings']) options.showWarnings = true
|
|
51
|
+
const options = { fields, dynHooks: builder.hooks ?? [] }
|
|
52
|
+
extractHeaders.call(me, req, options)
|
|
47
53
|
options.hidden = builder.hidden ?? []
|
|
48
54
|
options.queryHandler = builder.queryHandler
|
|
49
55
|
if (method === 'replace') options.partial = false
|
package/lib/route-by-verb.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import serveRoute from './serve-route.js'
|
|
3
|
+
import { extractHeaders } from './route-by-model-builder.js'
|
|
3
4
|
|
|
4
5
|
async function routeByVerb ({ file, appCtx, dir, pathPrefix, ns, alias, parent }) {
|
|
5
6
|
const { importModule } = this.app.bajo
|
|
6
|
-
const { parseObject } = this.app.lib
|
|
7
|
-
const { isSet } = this.app.lib.aneka
|
|
8
7
|
const { methodMap, getParams } = this.app.waibuDb
|
|
9
8
|
const { isFunction, merge } = this.app.lib._
|
|
10
9
|
const me = this
|
|
@@ -44,13 +43,9 @@ async function routeByVerb ({ file, appCtx, dir, pathPrefix, ns, alias, parent }
|
|
|
44
43
|
mod.schema = merge({}, defSchema, mod.schema ?? {})
|
|
45
44
|
const oldHandler = mod.handler
|
|
46
45
|
mod.handler = async function (req, reply) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (isSet(headers['x-count'])) count = headers['x-count']
|
|
51
|
-
if (isSet(headers['x-refs'])) refs = headers['x-refs']
|
|
52
|
-
if (typeof refs === 'string' && !['*', 'all'].includes(refs)) refs = [refs]
|
|
53
|
-
const options = { fields, count, refs }
|
|
46
|
+
const { fields } = getParams(req)
|
|
47
|
+
const options = { fields, dynHooks: mod.hooks ?? [] }
|
|
48
|
+
extractHeaders.call(me, req, options)
|
|
54
49
|
if (method === 'find') options.forFind = true
|
|
55
50
|
if (method === 'replace') options.partial = false
|
|
56
51
|
const data = await oldHandler.call(me.app[ns], req, reply, options, this)
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-25
|
|
4
|
+
|
|
5
|
+
- [2.11.0] Change options to format value using the new key set by dobo
|
|
6
|
+
- [2.11.0] Remove ```options.retainOriginalValue``` since it is not needed anymore
|
|
7
|
+
- [2.11.0] Change related header to ```X-Fmt```
|
|
8
|
+
|
|
9
|
+
## 2026-04-11
|
|
10
|
+
|
|
11
|
+
- [2.10.0] Add support to format output values using header ```X-Format-Value```
|
|
12
|
+
- [2.10.0] Add support to retain original value using header ```X-Retain-Original``` if above key is ```true```
|
|
13
|
+
|
|
3
14
|
## 2026-04-02
|
|
4
15
|
|
|
5
16
|
- [2.9.1] Add missing ```hardCapped``` key
|