waibu-rest-api 2.6.1 → 2.7.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.
@@ -4,7 +4,7 @@ import serveRoute from './serve-route.js'
4
4
  async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
5
5
  const { readConfig } = this.app.bajo
6
6
  const { parseObject } = this.app.lib
7
- const { isSet } = this.app.lib.aneka
7
+ const { isSet, pascalCase } = this.app.lib.aneka
8
8
  const { methodMap, getParams } = this.app.waibuDb
9
9
  const { isFunction, camelCase, omit, merge, keys, filter } = this.app.lib._
10
10
  const builder = await readConfig(file, { ns, ignoreError: true })
@@ -15,15 +15,16 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
15
15
  if (this.config.enablePatch) methods.push('replace')
16
16
  const me = this
17
17
  const mods = []
18
- const model = this.app.dobo.getModel(builder.model)
18
+ let model = {}
19
+ if (!builder.model.startsWith(':')) model = this.app.dobo.getModel(builder.model)
19
20
  for (const method of methods) {
20
- let disabled = model.disabled.includes(method) || builder.disabled.includes(method)
21
- if (method === 'replace' && (model.disabled.includes('update') || (builder.disabled ?? []).includes('update'))) disabled = true
21
+ let disabled = (model.disabled ?? []).includes(method) || builder.disabled.includes(method)
22
+ if (method === 'replace' && ((model.disabled ?? []).includes('update') || (builder.disabled ?? []).includes('update'))) disabled = true
22
23
  if (disabled) continue
23
24
  const mod = omit(builder, ['model', 'url', 'method', 'handler', 'hidden', ...methods])
24
25
  const customMod = builder[method] ?? {}
25
26
  customMod.schema = customMod.schema ?? false
26
- if (customMod.schema === true) customMod.schema = await this.docSchemaModel({ model: builder.model, method, options: { hidden: builder.hidden } })
27
+ if (customMod.schema === true && !builder.model.startsWith(':')) customMod.schema = await this.docSchemaModel({ model: builder.model, method, options: { hidden: builder.hidden } })
27
28
  let mapmethod = methodMap[method]
28
29
  if (this.config.enablePatch) {
29
30
  if (method === 'replace') mapmethod = 'PUT'
@@ -45,7 +46,8 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
45
46
  options.queryHandler = builder.queryHandler
46
47
  if (method === 'replace') options.partial = false
47
48
  if (['get', 'remove', 'update'].includes(method)) options.throwNotFound = true
48
- const data = await helper({ model: builder.model, req, reply, options, transaction: builder.transaction })
49
+ const model = builder.model.startsWith(':') ? pascalCase(req.params[builder.model.slice(1)]) : builder.model
50
+ const data = await helper({ model, req, reply, options, transaction: builder.transaction })
49
51
  data.success = true
50
52
  data.statusCode = method === 'create' ? 201 : 200
51
53
  if (method === 'find') options.forFind = true
@@ -61,7 +63,7 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
61
63
  const supported = ['aggregate', 'histogram']
62
64
  builder.stat = filter(builder.stat ?? supported, item => supported.includes(item))
63
65
  const method = 'GET'
64
- const disabled = model.disabled.includes(method) || builder.disabled.includes(method)
66
+ const disabled = (model.disabled ?? []).includes(method) || builder.disabled.includes(method)
65
67
  if (disabled) return mods
66
68
  const mod = {
67
69
  schema: false,
@@ -72,7 +74,8 @@ async function routeByModelBuilder ({ file, dir, pathPrefix, ns, parent }) {
72
74
  const helper = me.app.waibuDb[camelCase(`create ${req.params.stat}`)]
73
75
  if (!helper) throw this.error('_notFound')
74
76
  const options = { queryHandler: builder.queryHandler }
75
- const data = await helper({ model: builder.model, req, reply, options })
77
+ const model = builder.model.startsWith(':') ? pascalCase(req.params[builder.model.slice(1)]) : builder.model
78
+ const data = await helper({ model, req, reply, options })
76
79
  data.success = true
77
80
  data.statusCode = method === 'create' ? 201 : 200
78
81
  options.forFind = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-rest-api",
3
- "version": "2.6.1",
3
+ "version": "2.7.0",
4
4
  "description": "REST API for Waibu",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-14
4
+
5
+ - [2.7.0] Accept model's name from ```req.params``` in ```route-by-model-builder.js```
6
+
3
7
  ## 2026-03-06
4
8
 
5
9
  - [2.6.1] Bug fix on schema enforcement. Only apply when it's stated explicitely in route handler