waibu-rest-api 2.9.0 → 2.10.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 +2 -0
- package/lib/route-by-model-builder.js +17 -10
- package/lib/route-by-verb.js +4 -9
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/index.js
CHANGED
|
@@ -60,6 +60,7 @@ async function factory (pkgName) {
|
|
|
60
60
|
statusCode: 'code',
|
|
61
61
|
error: 'error',
|
|
62
62
|
cached: 'cached',
|
|
63
|
+
hardCapped: 'hardCapped',
|
|
63
64
|
message: 'message',
|
|
64
65
|
warnings: 'warnings',
|
|
65
66
|
details: 'details'
|
|
@@ -105,6 +106,7 @@ async function factory (pkgName) {
|
|
|
105
106
|
|
|
106
107
|
transformResult = ({ data, req, reply, options = {} }) => {
|
|
107
108
|
const reformat = ({ data, req, reply, options = {} }) => {
|
|
109
|
+
// console.log(data)
|
|
108
110
|
const { forOwn, get } = this.app.lib._
|
|
109
111
|
const newData = {}
|
|
110
112
|
forOwn(data, (v, k) => {
|
|
@@ -1,10 +1,23 @@
|
|
|
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-format-value']) options.formatValue = true
|
|
15
|
+
if (headers['x-retain-original']) options.retainOriginalValue = true
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
|
|
5
19
|
const { readConfig } = this.app.bajo
|
|
6
|
-
const {
|
|
7
|
-
const { isSet, pascalCase } = this.app.lib.aneka
|
|
20
|
+
const { pascalCase } = this.app.lib.aneka
|
|
8
21
|
const { methodMap, getParams } = this.app.waibuDb
|
|
9
22
|
const { isFunction, camelCase, omit, merge, keys, filter } = this.app.lib._
|
|
10
23
|
const builder = await readConfig(file, { ns, ignoreError: true })
|
|
@@ -36,14 +49,8 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
|
|
|
36
49
|
handler: async function (req, reply) {
|
|
37
50
|
const helper = me.app.waibuDb[`${method === 'replace' ? 'update' : method}Record`]
|
|
38
51
|
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
|
|
52
|
+
const options = { fields, dynHooks: builder.hooks ?? [] }
|
|
53
|
+
extractHeaders.call(me, req, options)
|
|
47
54
|
options.hidden = builder.hidden ?? []
|
|
48
55
|
options.queryHandler = builder.queryHandler
|
|
49
56
|
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,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-11
|
|
4
|
+
|
|
5
|
+
- [2.10.0] Add support to format output values using header ```X-Format-Value```
|
|
6
|
+
- [2.10.0] Add support to retain original value using header ```X-Retain-Original``` if above key is ```true```
|
|
7
|
+
|
|
8
|
+
## 2026-04-02
|
|
9
|
+
|
|
10
|
+
- [2.9.1] Add missing ```hardCapped``` key
|
|
11
|
+
|
|
3
12
|
## 2026-03-30
|
|
4
13
|
|
|
5
14
|
- [2.8.0] Add inter site module support
|