waibu-rest-api 1.0.5 → 1.0.7

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.
@@ -7,7 +7,7 @@ const waibuRestApiPreParsing = {
7
7
  reply.header('Content-Language', req.lang)
8
8
  if (this.config.format.asExt && req.params.format) {
9
9
  if (!this.config.format.supported.includes(req.params.format)) {
10
- throw this.error('Unsupported format \'%s\'', req.params.format, { statusCode: 406 })
10
+ throw this.error('unsupportedFormat%s', req.params.format, { statusCode: 406 })
11
11
  }
12
12
  }
13
13
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "unsupportedFormat%s": "Unsupported format '%s'",
3
+ "successfulResponse": "Successfull response",
4
+ "docErrorResponse": "Document error response",
5
+ "generalErrorResponse": "General error response"
6
+ }
package/bajo/intl/id.json CHANGED
@@ -1,3 +1,6 @@
1
1
  {
2
- "Unprocessable Entity Error": "Kesalahan Entitas yang Tidak Dapat Diproses"
2
+ "unsupportedFormat%s": "Format tidak didukung '%s'",
3
+ "successfulResponse": "Respon sukses",
4
+ "docErrorResponse": "Respon kesalahan dokumen",
5
+ "generalErrorResponse": "Respon kesalahan umum"
3
6
  }
@@ -66,18 +66,18 @@ async function buildResponse ({ ctx, schema, method, options }) {
66
66
 
67
67
  const result = {
68
68
  '2xx': {
69
- description: this.print.write('Successfull response'),
69
+ description: this.print.write('successfulResponse'),
70
70
  type: 'object'
71
71
  }
72
72
  }
73
73
  if (['create', 'update', 'replace'].includes(method)) {
74
74
  result['4xx'] = {
75
- description: this.print.write('Document error response'),
75
+ description: this.print.write('docErrorResponse'),
76
76
  $ref: '4xxResp#'
77
77
  }
78
78
  }
79
79
  result['5xx'] = {
80
- description: this.print.write('General error response'),
80
+ description: this.print.write('generalErrorResponse'),
81
81
  $ref: '5xxResp#'
82
82
  }
83
83
  if (cfgWdb.dbModel.dataOnly) {
package/lib/error.js CHANGED
@@ -3,7 +3,7 @@ import { handler } from './not-found.js'
3
3
  const extHandler = async function (err, req, reply, ctx) {
4
4
  const code = err.statusCode ?? 500
5
5
  const msg = err.message
6
- if (msg === 'notFound') {
6
+ if (msg === '_notFound') {
7
7
  return handler.call(this, req, reply, ctx)
8
8
  }
9
9
  const data = ctx.httpErrors.createError(code, msg)
package/lib/not-found.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function handler (ctx, req, reply) {
2
- const msg = this.print.write('Route \'%s (%s)\' not found', req.url, req.method)
2
+ const msg = this.print.write('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
  }
@@ -28,12 +28,12 @@ async function routeByVerb ({ file, ctx, appCtx, dir, pathPrefix, ns, alias, par
28
28
  }
29
29
  if (['create', 'update', 'replace'].includes(action)) {
30
30
  defSchema.response['4xx'] = {
31
- description: this.print.write('Document error response'),
31
+ description: this.print.write('docErrorResponse'),
32
32
  $ref: '4xxResp#'
33
33
  }
34
34
  }
35
35
  defSchema.response['5xx'] = {
36
- description: this.print.write('General error response'),
36
+ description: this.print.write('generalErrorResponse'),
37
37
  $ref: '5xxResp#'
38
38
  }
39
39
  if (action === 'find') defSchema.querystring = { $ref: 'qsFilter#' }
package/lib/sub-app.js CHANGED
@@ -3,7 +3,7 @@ async function subApp (ctx) {
3
3
  const { collect } = await importModule('waibu:/lib/app.js', { asDefaultImport: false })
4
4
  const mods = await collect.call(this.app[this.name], 'boot.js', 'waibuRestApi')
5
5
  for (const m of mods) {
6
- this.log.debug('Boot sub app: %s', m.ns)
6
+ this.log.debug('bootSubApp%s', m.ns)
7
7
  await ctx.register(async (subCtx) => {
8
8
  this.app[m.ns].instance = subCtx
9
9
  await runHook(`${this.name}.${m.alias}:afterCreateContext`, subCtx)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-rest-api",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "REST API for Waibu",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/waibu/boot.js CHANGED
@@ -51,7 +51,7 @@ const boot = {
51
51
  const me = this
52
52
 
53
53
  await eachPlugins(async function ({ dir, alias, ns }) {
54
- const appPrefix = '/' + (ns === me.app.bajo.mainNs && getPluginPrefix(ns, 'waibuRestApi'))
54
+ const appPrefix = '/' + (ns === me.app.bajo.mainNs ? '' : getPluginPrefix(ns, 'waibuRestApi'))
55
55
  const pattern = [
56
56
  `${dir}/${pathPrefix}/**/{${actions.join(',')}}.js`,
57
57
  `${dir}/${pathPrefix}/**/model-builder.*`
@@ -68,14 +68,14 @@ const boot = {
68
68
  const fullPath = appPrefix === '/' ? mod.url : (appPrefix + mod.url)
69
69
  const isRouteDisabled = await importModule('waibu:/lib/webapp-scope/is-route-disabled.js')
70
70
  if (await isRouteDisabled.call(this, fullPath, mod.method, me.config.disabled)) {
71
- this.log.warn('Route %s (%s) is disabled', `${prefix}${fullPath}`, mod.method)
71
+ this.log.warn('routeDisabled%s%s', `${prefix}${fullPath}`, mod.method)
72
72
  continue
73
73
  }
74
74
  const rpath = await reroutedPath.call(this, fullPath, me.config.rerouted)
75
75
  if (me.config.format.asExt) mod.url = formatExt(mod.url)
76
76
  if (rpath) {
77
77
  mod.config.pathReroutedTo = rpath
78
- this.log.warn('Rerouted %s -> %s', `${prefix}${fullPath}`, `${prefix}${rpath}`)
78
+ this.log.warn('rerouted%s%s', `${prefix}${fullPath}`, `${prefix}${rpath}`)
79
79
  mod.url = me.config.format.asExt ? formatExt(rpath) : rpath
80
80
  await ctx.route(mod)
81
81
  } else await appCtx.route(mod)