waibu-rest-api 2.6.1 → 2.7.1
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/doc-schema/model.js +3 -3
- package/lib/route-by-model-builder.js +11 -8
- package/package.json +1 -1
- package/wiki/CHANGES.md +8 -0
package/lib/doc-schema/model.js
CHANGED
|
@@ -129,7 +129,7 @@ async function docSchemaModel ({ model, method, options = {} }) {
|
|
|
129
129
|
if (['update'].includes(method)) {
|
|
130
130
|
const { properties } = await buildPropsReqs.call(this, { model: mdl, method, options })
|
|
131
131
|
const name = 'model' + mdl.name + 'Update'
|
|
132
|
-
delete properties.
|
|
132
|
+
delete properties._ref
|
|
133
133
|
await this.docSchemaLib(name, {
|
|
134
134
|
type: 'object',
|
|
135
135
|
properties: omit(properties, ['id'])
|
|
@@ -139,7 +139,7 @@ async function docSchemaModel ({ model, method, options = {} }) {
|
|
|
139
139
|
if (['replace'].includes(method)) {
|
|
140
140
|
const { properties, required } = await buildPropsReqs.call(this, { model: mdl, method, options })
|
|
141
141
|
const name = 'model' + model.name + 'Replace'
|
|
142
|
-
delete properties.
|
|
142
|
+
delete properties._ref
|
|
143
143
|
await this.docSchemaLib(name, {
|
|
144
144
|
type: 'object',
|
|
145
145
|
properties: omit(properties, ['id']),
|
|
@@ -150,7 +150,7 @@ async function docSchemaModel ({ model, method, options = {} }) {
|
|
|
150
150
|
if (['create'].includes(method)) {
|
|
151
151
|
const { properties, required } = await buildPropsReqs.call(this, { model: mdl, method, options })
|
|
152
152
|
const name = 'model' + model.name + 'Create'
|
|
153
|
-
delete properties.
|
|
153
|
+
delete properties._ref
|
|
154
154
|
await this.docSchemaLib(name, {
|
|
155
155
|
type: 'object',
|
|
156
156
|
properties,
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-03-22
|
|
4
|
+
|
|
5
|
+
- [2.7.1] bug fix in reference records
|
|
6
|
+
|
|
7
|
+
## 2026-03-14
|
|
8
|
+
|
|
9
|
+
- [2.7.0] Accept model's name from ```req.params``` in ```route-by-model-builder.js```
|
|
10
|
+
|
|
3
11
|
## 2026-03-06
|
|
4
12
|
|
|
5
13
|
- [2.6.1] Bug fix on schema enforcement. Only apply when it's stated explicitely in route handler
|