waibu-db 2.10.3 → 2.11.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.
- package/extend/bajo/intl/en-US.json +1 -0
- package/extend/bajo/intl/id.json +1 -0
- package/lib/method/count-record.js +2 -2
- package/lib/method/create-aggregate.js +2 -2
- package/lib/method/create-histogram.js +2 -2
- package/lib/method/create-record.js +2 -2
- package/lib/method/find-all-record.js +2 -2
- package/lib/method/find-one-record.js +2 -2
- package/lib/method/find-record.js +2 -2
- package/lib/method/get-record.js +2 -2
- package/lib/method/remove-record.js +2 -2
- package/lib/method/update-record.js +2 -2
- package/lib/util.js +17 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -1
package/extend/bajo/intl/id.json
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
17
|
+
return await processHandler.call(this, { action: 'findRecord', model: mdl, handler, options: opts })
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export default findRecord
|
package/lib/method/get-record.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
@@ -63,3 +63,20 @@ export async function getOneRecord (model, id, filter, options) {
|
|
|
63
63
|
if (isEmpty(data.data) && options.throwNotFound) throw this.error('_notFound')
|
|
64
64
|
return data
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
export async function processHandler ({ action, model, handler, options } = {}) {
|
|
68
|
+
function suppressedReturn () {
|
|
69
|
+
if (action === 'countRecord') return options.dataOnly ? 0 : { data: 0, warnings: [options.req.t('supppressedError')] }
|
|
70
|
+
if (['createRecord', 'getRecord'].includes(action)) return options.dataOnly ? {} : { data: {}, warnings: [options.req.t('supppressedError')] }
|
|
71
|
+
if (action === 'removeRecord') return options.dataOnly ? {} : { oldData: {}, warnings: [options.req.t('supppressedError')] }
|
|
72
|
+
if (action === 'updateRecord') return options.dataOnly ? {} : { data: {}, oldData: {}, warnings: [options.req.t('supppressedError')] }
|
|
73
|
+
return options.dataOnly ? [] : { data: [], count: 0, page: 1, warnings: [options.req.t('supppressedError')] }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
return options.trx === true ? (await model.transaction(handler)) : (await handler())
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (options.suppressError) return suppressedReturn()
|
|
80
|
+
throw err
|
|
81
|
+
}
|
|
82
|
+
}
|
package/package.json
CHANGED