waibu-rest-api 1.1.3 → 1.1.5

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,7 +1,7 @@
1
1
  async function xml (req, reply, payload) {
2
2
  const { importPkg } = this.app.bajo
3
3
  const { XMLBuilder } = await importPkg('bajoExtra:fast-xml-parser', { returnDefault: false })
4
- const { get, set, isPlainObject, isArray } = this.app.bajo.lib._
4
+ const { get, set, isPlainObject, isArray } = this.lib._
5
5
  const { wrapper, valueAsAttributes, declaration } = this.config.format.xml.response
6
6
 
7
7
  reply.type('application/xml; charset=utf-8')
@@ -7,7 +7,7 @@ async function routeByModelBuilder ({ file, ctx, dir, pathPrefix, ns, parent })
7
7
  const { readConfig, parseObject, isSet } = this.app.bajo
8
8
  const { methodMap, getParams } = this.app.waibuDb
9
9
  const { getInfo } = this.app.dobo
10
- const { camelCase, omit, merge, keys } = this.app.bajo.lib._
10
+ const { camelCase, omit, merge, keys } = this.lib._
11
11
  const builder = await readConfig(file, { ns, ignoreError: true })
12
12
  const { schema } = getInfo(builder.model)
13
13
  const url = path.dirname(file).replace(`${dir}/${pathPrefix}`, '').replaceAll('@', ':')
@@ -4,7 +4,7 @@ import serveRoute from './serve-route.js'
4
4
  async function routeByVerb ({ file, ctx, appCtx, dir, pathPrefix, ns, alias, parent }) {
5
5
  const { importModule, parseObject, isSet } = this.app.bajo
6
6
  const { methodMap, getParams } = this.app.waibuDb
7
- const { isFunction, merge } = this.app.bajo.lib._
7
+ const { isFunction, merge } = this.lib._
8
8
  const me = this
9
9
  const url = path.dirname(file).replace(`${dir}/${pathPrefix}`, '')
10
10
  .replaceAll('@@', '*').replaceAll('@', ':')
@@ -1,7 +1,7 @@
1
1
  async function serveRoute ({ mod, ns, parent }) {
2
2
  const { defaultsDeep, importModule } = this.app.bajo
3
3
  const { getPluginPrefix } = this.app.waibu
4
- const { pick } = this.app.bajo.lib._
4
+ const { pick } = this.lib._
5
5
  const mergeRouteHooks = await importModule('waibu:/lib/webapp-scope/merge-route-hooks.js')
6
6
  const cfgWdb = this.app.waibuDb.config
7
7
  mod.config = mod.config ?? {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-rest-api",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "REST API for Waibu",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -60,13 +60,13 @@ async function factory (pkgName) {
60
60
  }
61
61
 
62
62
  init = async () => {
63
- const { uniq } = this.app.bajo.lib._
63
+ const { uniq } = this.lib._
64
64
  this.config.format.supported.push('json')
65
65
  this.config.format.supported = uniq(this.config.format.supported)
66
66
  }
67
67
 
68
68
  routePath = (name, { defFormat = '.json' } = {}) => {
69
- const { get, trimStart } = this.app.bajo.lib._
69
+ const { get, trimStart } = this.lib._
70
70
  const { fullPath, ns } = this.app.bajo.breakNsPath(name)
71
71
  const prefix = get(this.app[ns], 'config.waibu.prefix', this.app[ns].alias)
72
72
  const format = defFormat === false ? '' : (this.config.format.asExt ? defFormat : '')
@@ -76,7 +76,7 @@ async function factory (pkgName) {
76
76
 
77
77
  transformResult = ({ data, req, reply, options = {} }) => {
78
78
  const reformat = ({ data, req, reply, options = {} }) => {
79
- const { forOwn, get } = this.app.bajo.lib._
79
+ const { forOwn, get } = this.lib._
80
80
  const newData = {}
81
81
  forOwn(data, (v, k) => {
82
82
  let key = get(this.config, `responseKey.${k}`, k)
@@ -88,7 +88,7 @@ async function factory (pkgName) {
88
88
 
89
89
  const returnError = ({ data, req, reply, options = {} }) => {
90
90
  const { pascalCase } = this.app.bajo
91
- const { last, map, kebabCase, upperFirst, keys, each, get, isEmpty } = this.app.bajo.lib._
91
+ const { last, map, kebabCase, upperFirst, keys, each, get, isEmpty } = this.lib._
92
92
  const cfg = this.config
93
93
  const cfgWdb = this.app.waibuDb.config
94
94
  const errNames = kebabCase(data.constructor.name).split('-')
@@ -110,7 +110,7 @@ async function factory (pkgName) {
110
110
 
111
111
  const returnSuccess = ({ data, req, reply, options = {} }) => {
112
112
  const { pascalCase } = this.app.bajo
113
- const { each, keys, omit, get } = this.app.bajo.lib._
113
+ const { each, keys, omit, get } = this.lib._
114
114
  const cfg = this.config
115
115
  const cfgWdb = this.app.waibuDb.config
116
116
  if (reply) {
@@ -1,5 +1,5 @@
1
1
  async function buildErrResp (ctx) {
2
- const { cloneDeep, merge, each, get } = this.app.bajo.lib._
2
+ const { cloneDeep, merge, each, get } = this.lib._
3
3
  const cfg = this.config
4
4
  const cfgWdb = this.app.waibuDb.config
5
5
  const def = {
@@ -1,5 +1,5 @@
1
1
  async function docSchemaLib (ctx, name, obj) {
2
- const { merge } = this.app.bajo.lib._
2
+ const { merge } = this.lib._
3
3
  if (ctx.getSchema(name)) return
4
4
  const value = merge({}, obj, { $id: name })
5
5
  ctx.addSchema(value)
@@ -17,6 +17,9 @@ async function buildPropsReqs ({ schema, method, options = {} }) {
17
17
  for (const p of schema.properties) {
18
18
  if (hidden.includes(p.name)) continue
19
19
  properties[p.name] = { type: getType(p.type) }
20
+ if (properties[p.name].type === 'object') {
21
+ properties[p.name].additionalProperties = true
22
+ }
20
23
  if (!p.required) properties[p.name].nullable = true
21
24
  else if (method === 'create' && p.name !== 'id') required.push(p.name)
22
25
  if (['datetime'].includes(p.type)) properties[p.name].format = 'date-time'
@@ -45,7 +48,7 @@ async function buildPropsReqs ({ schema, method, options = {} }) {
45
48
  }
46
49
 
47
50
  async function buildResponse ({ ctx, schema, method, options }) {
48
- const { merge, cloneDeep } = this.app.bajo.lib._
51
+ const { merge, cloneDeep } = this.lib._
49
52
  const { transformResult } = this.app.waibuRestApi
50
53
  const cfgWdb = this.app.waibuDb.config
51
54
  const { properties } = await buildPropsReqs.call(this, { schema, method, options })
@@ -113,7 +116,7 @@ async function buildResponse ({ ctx, schema, method, options }) {
113
116
  async function docSchemaModel ({ model, method, ctx, options = {} }) {
114
117
  const { getInfo } = this.app.dobo
115
118
  const { schema } = getInfo(model)
116
- const { omit } = this.app.bajo.lib._
119
+ const { omit } = this.lib._
117
120
  const out = {
118
121
  description: options.description ?? this.docSchemaDescription(method),
119
122
  tags: [this.alias.toUpperCase(), ...(options.alias ?? [])]
@@ -1,5 +1,5 @@
1
1
  async function buildParams (ctx, paramName, ...args) {
2
- const { each, isEmpty, keys, last, isBoolean } = this.app.bajo.lib._
2
+ const { each, isEmpty, keys, last, isBoolean } = this.lib._
3
3
  const cfgWeb = this.app.waibu.config
4
4
  let transform = false
5
5
  if (isBoolean(last(args))) {
@@ -1,5 +1,5 @@
1
1
  async function buildParams (ctx, paramName, ...args) {
2
- const { each, isEmpty } = this.app.bajo.lib._
2
+ const { each, isEmpty } = this.lib._
3
3
  const item = {
4
4
  type: 'object',
5
5
  properties: {}
package/waibu/boot.js CHANGED
@@ -17,7 +17,7 @@ const boot = {
17
17
  level: 10,
18
18
  handler: async function (ctx, prefix) {
19
19
  const { importPkg, eachPlugins, importModule, runHook } = this.app.bajo
20
- const { fastGlob } = this.app.bajo.lib
20
+ const { fastGlob } = this.lib
21
21
  const { getPluginPrefix } = this.app.waibu
22
22
  const [bodyParser, accepts] = await importPkg('waibu:@fastify/formbody', 'waibu:@fastify/accepts')
23
23
  const routeHook = await importModule('waibu:/lib/webapp-scope/route-hook.js')