waibu-db 2.10.3 → 2.12.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.
@@ -37,6 +37,7 @@
37
37
  "tsv": "TSV",
38
38
  "ndjson": "NDJSON",
39
39
  "dataValue": "Data value",
40
+ "suppressedError": "Error occured and suppressed. Please check error log for details",
40
41
  "op": {
41
42
  "equals": "Equals",
42
43
  "notEquals": "Not Equals",
@@ -37,6 +37,7 @@
37
37
  "tsv": "TSV",
38
38
  "ndjson": "NDJSON",
39
39
  "dataValue": "Nilai data",
40
+ "suppressedError": "Kesalahan terjadi dan tidak ditampilkan. Silahkan cek log kesalahan untuk detilnya",
40
41
  "op": {
41
42
  "equals": "Sama Dengan",
42
43
  "notEquals": "Tidak Sama Dengan",
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function countRecord ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -8,7 +8,7 @@ async function countRecord ({ model, req, reply, options = {}, transaction } = {
8
8
  return await mdl.countRecord(filter, opts)
9
9
  }
10
10
 
11
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
11
+ return await processHandler.call(this, { action: 'countRecord', model: mdl, handler, options: opts })
12
12
  }
13
13
 
14
14
  export default countRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function createAggregate ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -13,7 +13,7 @@ async function createAggregate ({ model, req, reply, options = {}, transaction }
13
13
  return await mdl.createAggregate(filter, params, opts)
14
14
  }
15
15
 
16
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
16
+ return await processHandler.call(this, { action: 'createAggregate', model: mdl, handler, options: opts })
17
17
  }
18
18
 
19
19
  export default createAggregate
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function createHistogram ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -13,7 +13,7 @@ async function createHistogram ({ model, req, reply, options = {}, transaction }
13
13
  return await mdl.createHistogram(filter, params, opts)
14
14
  }
15
15
 
16
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
16
+ return await processHandler.call(this, { action: 'createHistogram', model: mdl, handler, options: opts })
17
17
  }
18
18
 
19
19
  export default createHistogram
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function createRecord ({ model, req, reply, body, options = {}, transaction } = {}) {
4
4
  const { model: mdl, input, opts, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, body, options, args: ['model'], transaction })
@@ -10,7 +10,7 @@ async function createRecord ({ model, req, reply, body, options = {}, transactio
10
10
  return ret
11
11
  }
12
12
 
13
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
13
+ return await processHandler.call(this, { action: 'createRecord', model: mdl, handler, options: opts })
14
14
  }
15
15
 
16
16
  export default createRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findAllRecord ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -14,7 +14,7 @@ async function findAllRecord ({ model, req, reply, options = {}, transaction } =
14
14
  return ret
15
15
  }
16
16
 
17
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
17
+ return await processHandler.call(this, { action: 'findAllRecord', model: mdl, handler, options: opts })
18
18
  }
19
19
 
20
20
  export default findAllRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findOneRecord ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -10,7 +10,7 @@ async function findOneRecord ({ model, req, reply, options = {}, transaction } =
10
10
  return ret
11
11
  }
12
12
 
13
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
13
+ return await processHandler.call(this, { action: 'findOneRecord', model: mdl, handler, options: opts })
14
14
  }
15
15
 
16
16
  export default findOneRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud } from '../util.js'
1
+ import { prepCrud, processHandler } from '../util.js'
2
2
 
3
3
  async function findRecord ({ model, req, reply, options = {}, transaction } = {}) {
4
4
  const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
@@ -14,7 +14,7 @@ async function findRecord ({ model, req, reply, options = {}, transaction } = {}
14
14
  return ret
15
15
  }
16
16
 
17
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
17
+ return await processHandler.call(this, { action: 'findRecord', model: mdl, handler, options: opts })
18
18
  }
19
19
 
20
20
  export default findRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud, getOneRecord } from '../util.js'
1
+ import { prepCrud, getOneRecord, processHandler } from '../util.js'
2
2
 
3
3
  async function getRecord ({ model, req, reply, id, options = {}, transaction } = {}) {
4
4
  const { model: mdl, recId, filter, attachment, stats, mimeType, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction })
@@ -11,7 +11,7 @@ async function getRecord ({ model, req, reply, id, options = {}, transaction } =
11
11
  return data
12
12
  }
13
13
 
14
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
14
+ return await processHandler.call(this, { action: 'getRecord', model: mdl, handler, options: opts })
15
15
  }
16
16
 
17
17
  export default getRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud, getOneRecord } from '../util.js'
1
+ import { prepCrud, getOneRecord, processHandler } from '../util.js'
2
2
 
3
3
  async function removeRecord ({ model, req, reply, id, options = {}, transaction } = {}) {
4
4
  const { model: mdl, recId, opts, filter } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'], transaction })
@@ -11,7 +11,7 @@ async function removeRecord ({ model, req, reply, id, options = {}, transaction
11
11
  return await mdl.removeRecord(recId, opts)
12
12
  }
13
13
 
14
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
14
+ return await processHandler.call(this, { action: 'removeRecord', model: mdl, handler, options: opts })
15
15
  }
16
16
 
17
17
  export default removeRecord
@@ -1,4 +1,4 @@
1
- import { prepCrud, getOneRecord } from '../util.js'
1
+ import { prepCrud, getOneRecord, processHandler } from '../util.js'
2
2
 
3
3
  async function updateRecord ({ model, req, reply, id, body, options = {}, transaction } = {}) {
4
4
  const { model: mdl, filter, input, opts, recId, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, body, id, options, args: ['model', 'id'], transaction })
@@ -13,7 +13,7 @@ async function updateRecord ({ model, req, reply, id, body, options = {}, transa
13
13
  return ret
14
14
  }
15
15
 
16
- return opts.trx === true ? await mdl.transaction(handler) : await handler()
16
+ return await processHandler.call(this, { action: 'updateRecord', model: mdl, handler, options: opts })
17
17
  }
18
18
 
19
19
  export default updateRecord
package/lib/util.js CHANGED
@@ -1,3 +1,5 @@
1
+ export const actions = ['countRecord', 'createAggregate', 'createHistogram', 'createRecord', 'findAllRecord', 'findOneRecord', 'findRecord', 'getRecord', 'removeRecord', 'updateRecord']
2
+
1
3
  export async function prepCrud ({ model, body, id, req, reply, transaction, options = {}, args } = {}) {
2
4
  const { isSet } = this.app.lib.aneka
3
5
  const { importModule } = this.app.bajo
@@ -9,6 +11,9 @@ export async function prepCrud ({ model, body, id, req, reply, transaction, opti
9
11
 
10
12
  const cfgWeb = this.app.waibu.getConfig()
11
13
  const opts = cloneDeep(omit(options, ['trx']))
14
+ if (opts.suppressError === true) opts.suppressError = actions
15
+ else if (isString(opts.suppressError)) opts.suppressError = [opts.suppressError]
16
+ else opts.suppressError = opts.suppressError ?? []
12
17
  opts.trx = options.trx
13
18
  const params = this.getParams(req, ...args)
14
19
  for (const k of ['count', 'fields']) {
@@ -63,3 +68,21 @@ export async function getOneRecord (model, id, filter, options) {
63
68
  if (isEmpty(data.data) && options.throwNotFound) throw this.error('_notFound')
64
69
  return data
65
70
  }
71
+
72
+ export async function processHandler ({ action, model, handler, options } = {}) {
73
+ function suppressedReturn (err) {
74
+ this.log.error(err)
75
+ if (action === 'countRecord') return options.dataOnly ? 0 : { data: 0, warnings: [options.req.t('supppressedError')] }
76
+ if (['createRecord', 'getRecord'].includes(action)) return options.dataOnly ? {} : { data: {}, warnings: [options.req.t('supppressedError')] }
77
+ if (action === 'removeRecord') return options.dataOnly ? {} : { oldData: {}, warnings: [options.req.t('supppressedError')] }
78
+ if (action === 'updateRecord') return options.dataOnly ? {} : { data: {}, oldData: {}, warnings: [options.req.t('supppressedError')] }
79
+ return options.dataOnly ? [] : { data: [], count: 0, page: 1, warnings: [options.req.t('supppressedError')] }
80
+ }
81
+
82
+ try {
83
+ return options.trx === true ? (await model.transaction(handler)) : (await handler())
84
+ } catch (err) {
85
+ if (options.suppressError.includes(action)) return suppressedReturn.call(this, err)
86
+ throw err
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.10.3",
3
+ "version": "2.12.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-26
4
+
5
+ - [2.11.0] Adding ```suppressError``` to model options
6
+ - [2.12.0] ```suppressError``` can now be either one or more actions. If set to ```true```, it assumed to be all actions
7
+ - [2.12.0] Print error log even in ```suppressError```
8
+
3
9
  ## 2026-03-25
4
10
 
5
- - [2.10.13] Bug fix in ```getOneRecord()```
11
+ - [2.10.3] Bug fix in ```getOneRecord()```
6
12
 
7
13
  ## 2026-03-22
8
14