waibu-rest-api 2.0.0 → 2.1.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.
Files changed (65) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/workflows/repo-lockdown.yml +24 -0
  3. package/.jsdoc.conf.json +45 -0
  4. package/LICENSE +0 -0
  5. package/README.md +33 -7
  6. package/docs/WaibuRestApi.html +3 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +3 -0
  12. package/docs/index.html +3 -0
  13. package/docs/index.js.html +180 -0
  14. package/docs/scripts/core.js +726 -0
  15. package/docs/scripts/core.min.js +23 -0
  16. package/docs/scripts/resize.js +90 -0
  17. package/docs/scripts/search.js +265 -0
  18. package/docs/scripts/search.min.js +6 -0
  19. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  20. package/docs/scripts/third-party/fuse.js +9 -0
  21. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  22. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  23. package/docs/scripts/third-party/hljs-original.js +5171 -0
  24. package/docs/scripts/third-party/hljs.js +1 -0
  25. package/docs/scripts/third-party/popper.js +5 -0
  26. package/docs/scripts/third-party/tippy.js +1 -0
  27. package/docs/scripts/third-party/tocbot.js +672 -0
  28. package/docs/scripts/third-party/tocbot.min.js +1 -0
  29. package/docs/static/bitcoin.jpeg +0 -0
  30. package/docs/static/home.md +23 -0
  31. package/docs/static/logo-ecosystem.png +0 -0
  32. package/docs/static/logo.png +0 -0
  33. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  34. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  35. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  36. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  37. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  38. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  39. package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +0 -0
  40. package/extend/bajo/hook/waibu@after-init.js +0 -0
  41. package/extend/bajo/intl/en-US.json +6 -1
  42. package/extend/bajo/intl/id.json +6 -1
  43. package/extend/waibu/boot.js +8 -8
  44. package/index.js +48 -11
  45. package/lib/decorate.js +0 -0
  46. package/lib/doc-schema/description.js +13 -0
  47. package/{method → lib}/doc-schema/for-find.js +2 -2
  48. package/{method → lib}/doc-schema/general.js +1 -1
  49. package/{method → lib}/doc-schema/lib.js +1 -1
  50. package/{method → lib}/doc-schema/model.js +30 -32
  51. package/{method → lib}/doc-schema/params.js +4 -4
  52. package/{method → lib}/doc-schema/qs.js +4 -4
  53. package/lib/error.js +0 -0
  54. package/lib/handle-response/xml.js +1 -1
  55. package/lib/handle-response.js +0 -0
  56. package/lib/not-found.js +1 -1
  57. package/lib/route-by-model-builder.js +11 -12
  58. package/lib/route-by-verb.js +6 -5
  59. package/lib/serve-route.js +2 -2
  60. package/lib/sub-app.js +2 -2
  61. package/package.json +46 -35
  62. package/wiki/CHANGES.md +6 -0
  63. package/wiki/CONFIG.md +3 -0
  64. package/wiki/CONTRIBUTING.md +5 -0
  65. package/method/doc-schema/description.js +0 -13
package/index.js CHANGED
@@ -1,11 +1,28 @@
1
+ import docSchemaDescription from './lib/doc-schema/description.js'
2
+ import docSchemaForFind from './lib/doc-schema/for-find.js'
3
+ import docSchemaGeneral from './lib/doc-schema/general.js'
4
+ import docSchemaLib from './lib/doc-schema/lib.js'
5
+ import docSchemaModel from './lib/doc-schema/model.js'
6
+ import docSchemaParams from './lib/doc-schema/params.js'
7
+ import docSchemaQs from './lib/doc-schema/qs.js'
8
+
9
+ /**
10
+ * Plugin factory
11
+ *
12
+ * @param {string} pkgName - NPM package name
13
+ * @returns {class}
14
+ */
1
15
  async function factory (pkgName) {
2
16
  const me = this
3
17
 
4
- return class WaibuRestApi extends this.lib.Plugin {
18
+ /**
19
+ * WaibuRestApi class
20
+ *
21
+ * @class
22
+ */
23
+ class WaibuRestApi extends this.app.baseClass.Base {
5
24
  constructor () {
6
25
  super(pkgName, me.app)
7
- this.alias = 'wra'
8
- this.dependencies = ['waibu', 'waibu-db', 'bajo-extra']
9
26
  this.routePathHandlers = ['restapi']
10
27
  this.config = {
11
28
  waibu: {
@@ -57,16 +74,26 @@ async function factory (pkgName) {
57
74
  disabled: [],
58
75
  rerouted: {}
59
76
  }
77
+
78
+ this.selfBind([
79
+ 'docSchemaDescription',
80
+ 'docSchemaForFind',
81
+ 'docSchemaGeneral',
82
+ 'docSchemaLib',
83
+ 'docSchemaModel',
84
+ 'docSchemaParams',
85
+ 'docSchemaQs'
86
+ ])
60
87
  }
61
88
 
62
89
  init = async () => {
63
- const { uniq } = this.lib._
90
+ const { uniq } = this.app.lib._
64
91
  this.config.format.supported.push('json')
65
92
  this.config.format.supported = uniq(this.config.format.supported)
66
93
  }
67
94
 
68
95
  routePath = (name, { defFormat = '.json', uriEncoded = true } = {}) => {
69
- const { get, trimStart } = this.lib._
96
+ const { get, trimStart } = this.app.lib._
70
97
  const { fullPath, ns } = this.app.bajo.breakNsPath(name)
71
98
  const prefix = get(this.app[ns], 'config.waibu.prefix', this.app[ns].alias)
72
99
  const format = defFormat === false ? '' : (this.config.format.asExt ? defFormat : '')
@@ -77,7 +104,7 @@ async function factory (pkgName) {
77
104
 
78
105
  transformResult = ({ data, req, reply, options = {} }) => {
79
106
  const reformat = ({ data, req, reply, options = {} }) => {
80
- const { forOwn, get } = this.lib._
107
+ const { forOwn, get } = this.app.lib._
81
108
  const newData = {}
82
109
  forOwn(data, (v, k) => {
83
110
  let key = get(this.config, `responseKey.${k}`, k)
@@ -88,13 +115,13 @@ async function factory (pkgName) {
88
115
  }
89
116
 
90
117
  const returnError = ({ data, req, reply, options = {} }) => {
91
- const { pascalCase } = this.lib.aneka
92
- const { last, map, kebabCase, upperFirst, keys, each, get, isEmpty } = this.lib._
118
+ const { pascalCase } = this.app.lib.aneka
119
+ const { last, map, kebabCase, upperFirst, keys, each, get, isEmpty } = this.app.lib._
93
120
  const cfg = this.config
94
121
  const cfgWdb = this.app.waibuDb.config
95
122
  const errNames = kebabCase(data.constructor.name).split('-')
96
123
  if (last(errNames) === 'error') errNames.pop()
97
- data.error = this.print.write(map(errNames, s => upperFirst(s)).join(' '))
124
+ data.error = this.t(map(errNames, s => upperFirst(s)).join(' '))
98
125
  data.success = false
99
126
  data.statusCode = data.statusCode ?? 500
100
127
  if (reply && cfgWdb.dbModel.dataOnly) {
@@ -110,8 +137,8 @@ async function factory (pkgName) {
110
137
  }
111
138
 
112
139
  const returnSuccess = ({ data, req, reply, options = {} }) => {
113
- const { pascalCase } = this.lib.aneka
114
- const { each, keys, omit, get } = this.lib._
140
+ const { pascalCase } = this.app.lib.aneka
141
+ const { each, keys, omit, get } = this.app.lib._
115
142
  const cfg = this.config
116
143
  const cfgWdb = this.app.waibuDb.config
117
144
  if (reply) {
@@ -131,7 +158,17 @@ async function factory (pkgName) {
131
158
  if (isError) return returnError({ data, req, reply, options })
132
159
  return returnSuccess({ data, req, reply, options })
133
160
  }
161
+
162
+ docSchemaDescription = docSchemaDescription
163
+ docSchemaForFind = docSchemaForFind
164
+ docSchemaGeneral = docSchemaGeneral
165
+ docSchemaLib = docSchemaLib
166
+ docSchemaModel = docSchemaModel
167
+ docSchemaParams = docSchemaParams
168
+ docSchemaQs = docSchemaQs
134
169
  }
170
+
171
+ return WaibuRestApi
135
172
  }
136
173
 
137
174
  export default factory
package/lib/decorate.js CHANGED
File without changes
@@ -0,0 +1,13 @@
1
+ function docSchemaDescription (method) {
2
+ const desc = {
3
+ create: 'postRecordWithBody',
4
+ find: 'findRecordsWithFilter',
5
+ get: 'getRecordById',
6
+ update: 'updateRecordByIdWithBody',
7
+ remove: 'removeRecordById'
8
+ }
9
+
10
+ return this.t(desc[method])
11
+ }
12
+
13
+ export default docSchemaDescription
@@ -1,4 +1,4 @@
1
- async function forFind (ctx, items) {
1
+ async function docSchemaForFind (ctx, items) {
2
2
  return {
3
3
  data: {
4
4
  type: 'array',
@@ -13,4 +13,4 @@ async function forFind (ctx, items) {
13
13
  }
14
14
  }
15
15
 
16
- export default forFind
16
+ export default docSchemaForFind
@@ -1,5 +1,5 @@
1
1
  async function buildErrResp (ctx) {
2
- const { cloneDeep, merge, each, get } = this.lib._
2
+ const { cloneDeep, merge, each, get } = this.app.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.lib._
2
+ const { merge } = this.app.lib._
3
3
  if (ctx.getSchema(name)) return
4
4
  const value = merge({}, obj, { $id: name })
5
5
  ctx.addSchema(value)
@@ -8,13 +8,12 @@ function getType (input) {
8
8
  return type
9
9
  }
10
10
 
11
- async function buildPropsReqs ({ schema, method, options = {} }) {
12
- const { getSchema } = this.app.dobo
11
+ async function buildPropsReqs ({ model, method, options = {} }) {
13
12
  const properties = {}
14
13
  const required = []
15
- const rels = {}
16
- const hidden = [...schema.hidden, ...(options.hidden ?? [])] ?? []
17
- for (const p of schema.properties) {
14
+ const refs = {}
15
+ const hidden = [...model.hidden, ...(options.hidden ?? [])] ?? []
16
+ for (const p of model.properties) {
18
17
  if (hidden.includes(p.name)) continue
19
18
  properties[p.name] = { type: getType(p.type) }
20
19
  if (properties[p.name].type === 'object') {
@@ -23,40 +22,40 @@ async function buildPropsReqs ({ schema, method, options = {} }) {
23
22
  if (!p.required) properties[p.name].nullable = true
24
23
  else if (method === 'create' && p.name !== 'id') required.push(p.name)
25
24
  if (['datetime'].includes(p.type)) properties[p.name].format = 'date-time'
26
- if (p.rel) {
27
- for (const key in p.rel) {
28
- const val = p.rel[key]
25
+ if (p.ref) {
26
+ for (const key in p.ref) {
27
+ const val = p.ref[key]
29
28
  if (val.fields.length === 0) continue
30
29
  const props = { type: 'object', properties: {} }
31
- const relschema = getSchema(val.schema)
30
+ const rModel = this.app.dobo.getModel(val.model)
32
31
  for (const f of val.fields) {
33
- const item = relschema.properties.find(s => s.name === f)
32
+ const item = rModel.properties.find(s => s.name === f)
34
33
  props.properties[item.name] = { type: getType(item.type) }
35
34
  }
36
35
  if (Object.keys(props.properties).length > 0) {
37
- if (val.type === 'one-to-many') {
38
- rels[key] = { type: 'array', items: props }
39
- } else if (val.type === 'one-to-one') {
40
- rels[key] = props
36
+ if (val.type === '1:n') {
37
+ refs[key] = { type: 'array', items: props }
38
+ } else if (val.type === '1:1') {
39
+ refs[key] = props
41
40
  }
42
41
  }
43
42
  }
44
43
  }
45
44
  }
46
- if (Object.keys(rels).length > 0) properties._rel = { type: 'object', properties: rels }
45
+ if (Object.keys(refs).length > 0) properties._ref = { type: 'object', properties: refs }
47
46
  return { properties, required }
48
47
  }
49
48
 
50
- async function buildResponse ({ ctx, schema, method, options }) {
51
- const { merge, cloneDeep } = this.lib._
49
+ async function buildResponse ({ ctx, model, method, options }) {
50
+ const { merge, cloneDeep } = this.app.lib._
52
51
  const { transformResult } = this.app.waibuRestApi
53
52
  const cfgWdb = this.app.waibuDb.config
54
- const { properties } = await buildPropsReqs.call(this, { schema, method, options })
53
+ const { properties } = await buildPropsReqs.call(this, { model, method, options })
55
54
 
56
55
  async function buildData (keys) {
57
56
  const data = {}
58
57
  for (const k of keys) {
59
- const name = 'model' + schema.name
58
+ const name = 'model' + model.name
60
59
  const props = cloneDeep(properties)
61
60
  await this.docSchemaLib(ctx, name, {
62
61
  type: 'object',
@@ -69,18 +68,18 @@ async function buildResponse ({ ctx, schema, method, options }) {
69
68
 
70
69
  const result = {
71
70
  '2xx': {
72
- description: this.print.write('successfulResponse'),
71
+ description: this.t('successfulResponse'),
73
72
  type: 'object'
74
73
  }
75
74
  }
76
75
  if (['create', 'update', 'replace'].includes(method)) {
77
76
  result['4xx'] = {
78
- description: this.print.write('docErrorResponse'),
77
+ description: this.t('docErrorResponse'),
79
78
  $ref: '4xxResp#'
80
79
  }
81
80
  }
82
81
  result['5xx'] = {
83
- description: this.print.write('generalErrorResponse'),
82
+ description: this.t('generalErrorResponse'),
84
83
  $ref: '5xxResp#'
85
84
  }
86
85
  if (cfgWdb.dbModel.dataOnly) {
@@ -114,9 +113,8 @@ async function buildResponse ({ ctx, schema, method, options }) {
114
113
  }
115
114
 
116
115
  async function docSchemaModel ({ model, method, ctx, options = {} }) {
117
- const { getInfo } = this.app.dobo
118
- const { schema } = getInfo(model)
119
- const { omit } = this.lib._
116
+ const mdl = this.app.dobo.getModel(model)
117
+ const { omit } = this.app.lib._
120
118
  const out = {
121
119
  description: options.description ?? this.docSchemaDescription(method),
122
120
  tags: [this.alias.toUpperCase(), ...(options.alias ?? [])]
@@ -129,8 +127,8 @@ async function docSchemaModel ({ model, method, ctx, options = {} }) {
129
127
  if (!options.noId) out.params = { $ref: 'paramsId#' }
130
128
  }
131
129
  if (['update'].includes(method)) {
132
- const { properties } = await buildPropsReqs.call(this, { schema, method, options })
133
- const name = 'model' + schema.name + 'Update'
130
+ const { properties } = await buildPropsReqs.call(this, { model: mdl, method, options })
131
+ const name = 'model' + mdl.name + 'Update'
134
132
  delete properties._rel
135
133
  await this.docSchemaLib(ctx, name, {
136
134
  type: 'object',
@@ -139,8 +137,8 @@ async function docSchemaModel ({ model, method, ctx, options = {} }) {
139
137
  out.body = { $ref: name + '#' }
140
138
  }
141
139
  if (['replace'].includes(method)) {
142
- const { properties, required } = await buildPropsReqs.call(this, { schema, method, options })
143
- const name = 'model' + schema.name + 'Replace'
140
+ const { properties, required } = await buildPropsReqs.call(this, { model: mdl, method, options })
141
+ const name = 'model' + model.name + 'Replace'
144
142
  delete properties._rel
145
143
  await this.docSchemaLib(ctx, name, {
146
144
  type: 'object',
@@ -150,8 +148,8 @@ async function docSchemaModel ({ model, method, ctx, options = {} }) {
150
148
  out.body = { $ref: name + '#' }
151
149
  }
152
150
  if (['create'].includes(method)) {
153
- const { properties, required } = await buildPropsReqs.call(this, { schema, method, options })
154
- const name = 'model' + schema.name + 'Create'
151
+ const { properties, required } = await buildPropsReqs.call(this, { model: mdl, method, options })
152
+ const name = 'model' + model.name + 'Create'
155
153
  delete properties._rel
156
154
  await this.docSchemaLib(ctx, name, {
157
155
  type: 'object',
@@ -161,7 +159,7 @@ async function docSchemaModel ({ model, method, ctx, options = {} }) {
161
159
  out.body = { $ref: name + '#' }
162
160
  out.querystring = { $ref: 'qsFields#' }
163
161
  }
164
- out.response = await buildResponse.call(this, { ctx, schema, method, options })
162
+ out.response = await buildResponse.call(this, { ctx, model: mdl, method, options })
165
163
  return out
166
164
  }
167
165
 
@@ -1,5 +1,5 @@
1
- async function buildParams (ctx, paramName, ...args) {
2
- const { each, isEmpty, keys, last, isBoolean } = this.lib._
1
+ async function docSchemaParams (ctx, paramName, ...args) {
2
+ const { each, isEmpty, keys, last, isBoolean } = this.app.lib._
3
3
  const cfgWeb = this.app.waibu.getConfig()
4
4
  let transform = false
5
5
  if (isBoolean(last(args))) {
@@ -12,7 +12,7 @@ async function buildParams (ctx, paramName, ...args) {
12
12
  each(args, a => {
13
13
  let [name, type, description, def] = a.split('|')
14
14
  if (isEmpty(type)) type = 'string'
15
- item.properties[name] = { type, description: this.print.write(description), default: def }
15
+ item.properties[name] = { type, description: this.t(description), default: def }
16
16
  })
17
17
  if (transform) {
18
18
  each(keys(cfgWeb.qsKey), k => {
@@ -25,4 +25,4 @@ async function buildParams (ctx, paramName, ...args) {
25
25
  if (!isEmpty(args)) await this.docSchemaLib(ctx, paramName, item)
26
26
  }
27
27
 
28
- export default buildParams
28
+ export default docSchemaParams
@@ -1,5 +1,5 @@
1
- async function buildParams (ctx, paramName, ...args) {
2
- const { each, isEmpty } = this.lib._
1
+ async function docSchemaQs (ctx, paramName, ...args) {
2
+ const { each, isEmpty } = this.app.lib._
3
3
  const item = {
4
4
  type: 'object',
5
5
  properties: {}
@@ -7,9 +7,9 @@ async function buildParams (ctx, paramName, ...args) {
7
7
  each(args, a => {
8
8
  let [name, type, description] = a.split(':')
9
9
  if (isEmpty(type)) type = 'string'
10
- item.properties[name] = { type, description: this.print.write(description) }
10
+ item.properties[name] = { type, description: this.t(description) }
11
11
  })
12
12
  if (!isEmpty(args)) await this.docSchemaLib(ctx, paramName, item)
13
13
  }
14
14
 
15
- export default buildParams
15
+ export default docSchemaQs
package/lib/error.js CHANGED
File without changes
@@ -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.lib._
4
+ const { get, set, isPlainObject, isArray } = this.app.lib._
5
5
  const { wrapper, valueAsAttributes, declaration } = this.config.format.xml.response
6
6
 
7
7
  reply.type('application/xml; charset=utf-8')
File without changes
package/lib/not-found.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function handler (req, reply, ctx) {
2
- const msg = this.print.write('routeNotFound%s%s', req.url, req.method)
2
+ const msg = this.t('routeNotFound%s%s', req.url, req.method)
3
3
  const data = ctx.httpErrors.createError(404, msg)
4
4
  return this.transformResult({ data, req, reply })
5
5
  }
@@ -2,25 +2,23 @@ import path from 'path'
2
2
  import serveRoute from './serve-route.js'
3
3
 
4
4
  async function routeByModelBuilder ({ file, ctx, dir, pathPrefix, ns, parent }) {
5
- const { getPlugin } = this.app.bajo
6
- getPlugin('dobo') // ensure dobo is loaded
7
- const { readConfig, parseObject } = this.app.bajo
8
- const { isSet } = this.lib.aneka
5
+ const { readConfig } = this.app.bajo
6
+ const { parseObject } = this.app.lib
7
+ const { isSet } = this.app.lib.aneka
9
8
  const { methodMap, getParams } = this.app.waibuDb
10
- const { getInfo } = this.app.dobo
11
- const { isFunction, camelCase, omit, merge, keys, filter } = this.lib._
9
+ const { isFunction, camelCase, omit, merge, keys, filter } = this.app.lib._
12
10
  const builder = await readConfig(file, { ns, ignoreError: true })
13
11
  builder.disabled = builder.disabled ?? []
14
- const { schema } = getInfo(builder.model)
15
12
  let url = path.dirname(file).replace(`${dir}/extend/${pathPrefix}`, '').replaceAll('@', ':')
16
13
  if (isFunction(builder.url)) url = await builder.url.call(this)
17
14
  const methods = keys(methodMap)
18
15
  if (this.config.enablePatch) methods.push('replace')
19
16
  const me = this
20
17
  const mods = []
18
+ const model = this.app.dobo.getModel(builder.model)
21
19
  for (const method of methods) {
22
- let disabled = schema.disabled.includes(method) || builder.disabled.includes(method)
23
- if (method === 'replace' && (schema.disabled.includes('update') || (builder.disabled ?? []).includes('update'))) disabled = true
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
24
22
  if (disabled) continue
25
23
  const mod = omit(builder, ['model', 'url', 'method', 'handler', 'hidden', ...methods])
26
24
  const customMod = builder[method] ?? {}
@@ -34,7 +32,7 @@ async function routeByModelBuilder ({ file, ctx, dir, pathPrefix, ns, parent })
34
32
  url: ['get', 'update', 'replace', 'remove'].includes(method) ? `${url}/:id` : url,
35
33
  method: mapmethod,
36
34
  handler: async function (req, reply) {
37
- const helper = me.app.waibuDb[camelCase(`record ${method === 'replace' ? 'update' : method}`)]
35
+ const helper = me.app.waibuDb[`${method === 'replace' ? 'update' : method}Record`]
38
36
  let { fields, count } = getParams(req)
39
37
  let rels = []
40
38
  const headers = parseObject(req.headers, { parseValue: true })
@@ -61,7 +59,7 @@ async function routeByModelBuilder ({ file, ctx, dir, pathPrefix, ns, parent })
61
59
  const supported = ['aggregate', 'histogram']
62
60
  builder.stat = filter(builder.stat ?? supported, item => supported.includes(item))
63
61
  const method = 'GET'
64
- const disabled = schema.disabled.includes(method) || builder.disabled.includes(method)
62
+ const disabled = model.disabled.includes(method) || builder.disabled.includes(method)
65
63
  if (disabled) return mods
66
64
  const mod = {
67
65
  schema: false,
@@ -69,7 +67,8 @@ async function routeByModelBuilder ({ file, ctx, dir, pathPrefix, ns, parent })
69
67
  url: `${url}/stat/:stat`,
70
68
  handler: async function (req, reply) {
71
69
  if (!supported.includes(req.params.stat)) throw me.error('_notFound')
72
- const helper = me.app.waibuDb[camelCase(`stat ${req.params.stat}`)]
70
+ const helper = me.app.waibuDb[camelCase(`create ${req.params.stat}`)]
71
+ if (!helper) throw this.error('_notFound')
73
72
  const options = { queryHandler: builder.queryHandler }
74
73
  const data = await helper({ model: builder.model, req, reply, ctx: this, options })
75
74
  data.success = true
@@ -2,10 +2,11 @@ import path from 'path'
2
2
  import serveRoute from './serve-route.js'
3
3
 
4
4
  async function routeByVerb ({ file, ctx, appCtx, dir, pathPrefix, ns, alias, parent }) {
5
- const { importModule, parseObject } = this.app.bajo
6
- const { isSet } = this.lib.aneka
5
+ const { importModule } = this.app.bajo
6
+ const { parseObject } = this.app.lib
7
+ const { isSet } = this.app.lib.aneka
7
8
  const { methodMap, getParams } = this.app.waibuDb
8
- const { isFunction, merge } = this.lib._
9
+ const { isFunction, merge } = this.app.lib._
9
10
  const me = this
10
11
  const url = path.dirname(file).replace(`${dir}/extend/${pathPrefix}`, '')
11
12
  .replaceAll('@@', '*').replaceAll('@', ':')
@@ -30,12 +31,12 @@ async function routeByVerb ({ file, ctx, appCtx, dir, pathPrefix, ns, alias, par
30
31
  }
31
32
  if (['create', 'update', 'replace'].includes(action)) {
32
33
  defSchema.response['4xx'] = {
33
- description: this.print.write('docErrorResponse'),
34
+ description: this.t('docErrorResponse'),
34
35
  $ref: '4xxResp#'
35
36
  }
36
37
  }
37
38
  defSchema.response['5xx'] = {
38
- description: this.print.write('generalErrorResponse'),
39
+ description: this.t('generalErrorResponse'),
39
40
  $ref: '5xxResp#'
40
41
  }
41
42
  if (action === 'find') defSchema.querystring = { $ref: 'qsFilter#' }
@@ -1,8 +1,8 @@
1
1
  async function serveRoute ({ mod, ns, parent }) {
2
- const { defaultsDeep } = this.lib.aneka
2
+ const { defaultsDeep } = this.app.lib.aneka
3
3
  const { importModule } = this.app.bajo
4
4
  const { getPluginPrefix } = this.app.waibu
5
- const { pick } = this.lib._
5
+ const { pick } = this.app.lib._
6
6
  const mergeRouteHooks = await importModule('waibu:/lib/webapp-scope/merge-route-hooks.js')
7
7
  const cfgWdb = this.app.waibuDb.config
8
8
  mod.config = mod.config ?? {}
package/lib/sub-app.js CHANGED
@@ -1,12 +1,12 @@
1
1
  async function subApp (ctx) {
2
2
  const { importModule, runHook } = this.app.bajo
3
3
  const { collect } = await importModule('waibu:/lib/app.js', { asDefaultImport: false })
4
- const mods = await collect.call(this.app[this.name], 'boot.js', 'waibuRestApi')
4
+ const mods = await collect.call(this.app[this.ns], 'boot.js', 'waibuRestApi')
5
5
  for (const m of mods) {
6
6
  this.log.debug('bootSubApp%s', m.ns)
7
7
  await ctx.register(async (subCtx) => {
8
8
  this.app[m.ns].instance = subCtx
9
- await runHook(`${this.name}.${m.alias}:afterCreateContext`, subCtx)
9
+ await runHook(`${this.ns}.${m.alias}:afterCreateContext`, subCtx)
10
10
  await m.handler.call(this.app[m.ns], subCtx, m.prefix)
11
11
  }, { prefix: m.prefix })
12
12
  }
package/package.json CHANGED
@@ -1,35 +1,46 @@
1
- {
2
- "name": "waibu-rest-api",
3
- "version": "2.0.0",
4
- "description": "REST API for Waibu",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "type": "module",
10
- "bajo": {
11
- "type": "plugin"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/ardhi/waibu-rest-api.git"
16
- },
17
- "keywords": [
18
- "api",
19
- "restful",
20
- "restapi",
21
- "waibu",
22
- "web",
23
- "webserver",
24
- "bajo",
25
- "framework",
26
- "fastify",
27
- "modular"
28
- ],
29
- "author": "Ardhi Lukianto <ardhi@lukianto.com>",
30
- "license": "MIT",
31
- "bugs": {
32
- "url": "https://github.com/ardhi/waibu-rest-api/issues"
33
- },
34
- "homepage": "https://github.com/ardhi/waibu-rest-api#readme"
35
- }
1
+ {
2
+ "name": "waibu-rest-api",
3
+ "version": "2.1.0",
4
+ "description": "REST API for Waibu",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build-doc": "jsdoc -c .jsdoc.conf.json",
8
+ "test": "mocha"
9
+ },
10
+ "type": "module",
11
+ "bajo": {
12
+ "type": "plugin",
13
+ "alias": "wra",
14
+ "dependencies": [
15
+ "waibu",
16
+ "waibu-db",
17
+ "bajo-extra"
18
+ ]
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ardhi/waibu-rest-api.git"
23
+ },
24
+ "keywords": [
25
+ "api",
26
+ "restful",
27
+ "restapi",
28
+ "waibu",
29
+ "web",
30
+ "webserver",
31
+ "bajo",
32
+ "framework",
33
+ "fastify",
34
+ "modular"
35
+ ],
36
+ "author": "Ardhi Lukianto <ardhi@lukianto.com>",
37
+ "license": "MIT",
38
+ "bugs": {
39
+ "url": "https://github.com/ardhi/waibu-rest-api/issues"
40
+ },
41
+ "homepage": "https://github.com/ardhi/waibu-rest-api#readme",
42
+ "devDependencies": {
43
+ "clean-jsdoc-theme": "^4.3.0",
44
+ "jsdoc-plugin-intersection": "^1.0.4"
45
+ }
46
+ }
@@ -0,0 +1,6 @@
1
+ # Changes
2
+
3
+ ## 2025-12-28
4
+
5
+ - [2.1.0] Ported to ```bajo@2.2.x``` specs
6
+ - [2.1.0] Add waibuRestApi end point ```/api/db/:model/stat/:stat```
package/wiki/CONFIG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Config Object
2
+
3
+ TBD
@@ -0,0 +1,5 @@
1
+ # Contributing
2
+
3
+ Thanks very much to everyone who wants to join as a contributor, but I have committed to devoting 100% of my time to this project. Therefore, I'm currently unable to accept pull requests from anyone until the project is large enough for me to manage it independently.
4
+
5
+ However, I am available if you encounter any bugs that require immediate fixes. Please report your issues in a GitHub issue, and I'll try to address them promptly. I'm also open to criticism and suggestions for improvements or requests for new features.
@@ -1,13 +0,0 @@
1
- const desc = {
2
- create: 'Post a new record',
3
- find: 'Find records by query, page size and number.',
4
- get: 'Get record by ID',
5
- update: 'Update record by ID',
6
- remove: 'Remove record by ID'
7
- }
8
-
9
- function docDescription (method) {
10
- return this.print.write(desc[method])
11
- }
12
-
13
- export default docDescription