waibu-rest-api 2.9.1 → 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.
@@ -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 { parseObject } = this.app.lib
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
- let count = true
40
- let refs = []
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
@@ -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
- let { fields, count } = getParams(req)
48
- let refs = []
49
- const headers = parseObject(req.headers, { parseValue: true })
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-rest-api",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "REST API for Waibu",
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-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
+
3
8
  ## 2026-04-02
4
9
 
5
10
  - [2.9.1] Add missing ```hardCapped``` key