dobo 2.38.0 → 2.39.1
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/.bootorder +0 -0
- package/.github/FUNDING.yml +0 -0
- package/.github/workflows/repo-lockdown.yml +0 -0
- package/.jsdoc.conf.json +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/docs/Dobo.html +0 -0
- package/docs/DoboAction.html +0 -0
- package/docs/DoboAdapter.html +0 -0
- package/docs/DoboConnection.html +0 -0
- package/docs/DoboFeature.html +0 -0
- package/docs/DoboModel.html +0 -0
- package/docs/data/search.json +0 -0
- package/docs/extend_bajo_hook-docs.js.html +0 -0
- package/docs/external-Tools.html +0 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +0 -0
- package/docs/index.html +0 -0
- package/docs/index.js.html +0 -0
- package/docs/lib_factory_action.js.html +0 -0
- package/docs/lib_factory_adapter.js.html +0 -0
- package/docs/lib_factory_connection.js.html +0 -0
- package/docs/lib_factory_feature.js.html +0 -0
- package/docs/lib_factory_model.js.html +0 -0
- package/docs/lib_factory_model_build.js.html +0 -0
- package/docs/lib_factory_model_clear-record.js.html +0 -0
- package/docs/lib_factory_model_count-record.js.html +0 -0
- package/docs/lib_factory_model_create-record.js.html +0 -0
- package/docs/lib_factory_model_drop.js.html +0 -0
- package/docs/lib_factory_model_exists.js.html +0 -0
- package/docs/lib_factory_model_find-all-record.js.html +0 -0
- package/docs/lib_factory_model_find-one-record.js.html +0 -0
- package/docs/lib_factory_model_find-record.js.html +0 -0
- package/docs/lib_factory_model_get-record.js.html +0 -0
- package/docs/lib_factory_model_helper.js.html +0 -0
- package/docs/lib_factory_model_remove-record.js.html +0 -0
- package/docs/lib_factory_model_sanitize-body.js.html +0 -0
- package/docs/lib_factory_model_sanitize-fixture.js.html +0 -0
- package/docs/lib_factory_model_sanitize-record.js.html +0 -0
- package/docs/lib_factory_model_update-record.js.html +0 -0
- package/docs/lib_factory_model_upsert-record.js.html +0 -0
- package/docs/lib_factory_model_validate.js.html +0 -0
- package/docs/lib_helper.js.html +0 -0
- package/docs/module-Helper.html +0 -0
- package/docs/module-Helper_Model.html +0 -0
- package/docs/module-Hook.html +0 -0
- package/docs/scripts/core.js +0 -0
- package/docs/scripts/core.min.js +0 -0
- package/docs/scripts/resize.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/scripts/search.min.js +5 -5
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
- package/docs/scripts/third-party/fuse.js +0 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -0
- package/docs/scripts/third-party/hljs-line-num.js +0 -0
- package/docs/scripts/third-party/hljs-original.js +0 -0
- package/docs/scripts/third-party/hljs.js +0 -0
- package/docs/scripts/third-party/popper.js +0 -0
- package/docs/scripts/third-party/tippy.js +0 -0
- package/docs/scripts/third-party/tocbot.js +0 -0
- package/docs/scripts/third-party/tocbot.min.js +0 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +0 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +0 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
- package/docs/styles/clean-jsdoc-theme-light.css +0 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
- package/docs/styles/clean-jsdoc-theme.min.css +0 -0
- package/extend/bajo/hook.js +236 -236
- package/extend/bajo/intl/en-US.json +0 -0
- package/extend/bajo/intl/id.json +0 -0
- package/extend/bajoCli/applet/aggregate.js +0 -0
- package/extend/bajoCli/applet/clear-record.js +0 -0
- package/extend/bajoCli/applet/connection.js +0 -0
- package/extend/bajoCli/applet/count-record.js +0 -0
- package/extend/bajoCli/applet/create-record.js +0 -0
- package/extend/bajoCli/applet/find-record.js +0 -0
- package/extend/bajoCli/applet/get-record.js +0 -0
- package/extend/bajoCli/applet/histogram.js +0 -0
- package/extend/bajoCli/applet/lib/post-process.js +0 -0
- package/extend/bajoCli/applet/model.js +0 -0
- package/extend/bajoCli/applet/rebuild-model.js +0 -0
- package/extend/bajoCli/applet/remove-record.js +0 -0
- package/extend/bajoCli/applet/update-record.js +0 -0
- package/extend/bajoCli/applet.js +0 -0
- package/extend/dobo/adapter/memory.js +175 -175
- package/extend/dobo/feature/created-at.js +0 -0
- package/extend/dobo/feature/dt.js +0 -0
- package/extend/dobo/feature/image.js +0 -0
- package/extend/dobo/feature/immutable.js +0 -0
- package/extend/dobo/feature/removed-at.js +0 -0
- package/extend/dobo/feature/unique.js +0 -0
- package/extend/dobo/feature/updated-at.js +0 -0
- package/extend/waibuMpa/route/attachment/@model/@id/@field/@file.js +0 -0
- package/extend/waibuStatic/virtual.json +0 -0
- package/index.js +0 -0
- package/lib/factory/action.js +287 -287
- package/lib/factory/adapter.js +1055 -1055
- package/lib/factory/connection.js +109 -109
- package/lib/factory/feature.js +52 -52
- package/lib/factory/model/aggregate.js +23 -23
- package/lib/factory/model/build.js +25 -25
- package/lib/factory/model/bulk-create-record.js +36 -36
- package/lib/factory/model/clear-record.js +30 -30
- package/lib/factory/model/count-record.js +42 -42
- package/lib/factory/model/create-attachment.js +36 -36
- package/lib/factory/model/create-record.js +49 -49
- package/lib/factory/model/drop.js +26 -26
- package/lib/factory/model/exists.js +26 -26
- package/lib/factory/model/find-all-record.js +112 -112
- package/lib/factory/model/find-attachment.js +28 -28
- package/lib/factory/model/find-one-record.js +38 -38
- package/lib/factory/model/find-record.js +82 -82
- package/lib/factory/model/get-attachment.js +15 -15
- package/lib/factory/model/get-record.js +52 -52
- package/lib/factory/model/helper.js +575 -576
- package/lib/factory/model/histogram.js +23 -23
- package/lib/factory/model/list-attachment.js +40 -40
- package/lib/factory/model/load-fixtures.js +63 -63
- package/lib/factory/model/remove-attachment.js +24 -24
- package/lib/factory/model/remove-record.js +44 -44
- package/lib/factory/model/sanitize-body.js +57 -57
- package/lib/factory/model/sanitize-fixture.js +56 -56
- package/lib/factory/model/sanitize-record.js +80 -80
- package/lib/factory/model/transaction.js +15 -15
- package/lib/factory/model/update-attachment.js +9 -9
- package/lib/factory/model/update-record.js +58 -58
- package/lib/factory/model/upsert-record.js +71 -71
- package/lib/factory/model/validate.js +0 -0
- package/lib/factory/model.js +503 -503
- package/lib/helper.js +463 -463
- package/package.json +1 -1
- package/test/e2e/_run.js +12 -12
- package/test/e2e/e2e-factory-process.test.js +25 -25
- package/test/e2e/e2e-model-adapter-process.test.js +52 -52
- package/test/integration/aspect-01-start-connections.test.js +33 -33
- package/test/integration/aspect-02-query-regex.test.js +34 -34
- package/test/integration/aspect-03-model-adapter-flow.test.js +88 -88
- package/test/unit/_stub.js +244 -244
- package/test/unit/dobo-action.test.js +58 -58
- package/test/unit/dobo-connection.test.js +37 -37
- package/test/unit/dobo-core.test.js +136 -136
- package/test/unit/dobo-feature.test.js +25 -25
- package/test/unit/dobo-model.test.js +115 -115
- package/test/unit/helper-sanitize-all.test.js +40 -40
- package/test/unit/helper-sanitize-ref.test.js +64 -64
- package/wiki/APPLETS.md +0 -0
- package/wiki/CHANGES.md +477 -469
- package/wiki/CONFIG.md +0 -0
- package/wiki/CONTRIBUTING.md +0 -0
- package/wiki/DEV-GUIDE.md +0 -0
- package/wiki/ECOSYSTEM.md +0 -0
- package/wiki/GETTING-STARTED.md +0 -0
- package/wiki/QUERY-LANGUAGE.md +0 -0
- package/wiki/USER-GUIDE.md +0 -0
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef TOptions
|
|
3
|
-
* @memberof DoboConnection
|
|
4
|
-
* @property {string} [name='default'] - Connection name
|
|
5
|
-
* @property {string[]} models - List of model names to be used with this connection. Use this property to force models to be bound to this connection only.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Connection factory
|
|
10
|
-
*
|
|
11
|
-
* @async
|
|
12
|
-
*/
|
|
13
|
-
async function connectionFactory () {
|
|
14
|
-
const { Tools } = this.app.baseClass
|
|
15
|
-
const { omit } = this.app.lib._
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Connection class definition.
|
|
19
|
-
*
|
|
20
|
-
* @class
|
|
21
|
-
*/
|
|
22
|
-
class DoboConnection extends Tools {
|
|
23
|
-
constructor (plugin, options = {}) {
|
|
24
|
-
super(plugin)
|
|
25
|
-
/**
|
|
26
|
-
* Adapter object
|
|
27
|
-
* @type {Object}
|
|
28
|
-
*/
|
|
29
|
-
this.adapter = undefined
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Client instance
|
|
33
|
-
* @type {Object}
|
|
34
|
-
*/
|
|
35
|
-
this.client = undefined
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Connection name
|
|
39
|
-
* @type {string}
|
|
40
|
-
*/
|
|
41
|
-
this.name = options.name
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Connection options
|
|
45
|
-
* @type {DoboConnection.TOptions}
|
|
46
|
-
*/
|
|
47
|
-
this.options = {
|
|
48
|
-
models: []
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Options object from connection defined on ```dobo.config.connections```
|
|
53
|
-
* @type {Object}
|
|
54
|
-
*/
|
|
55
|
-
if (options instanceof this.app.baseClass.DoboNullAdapter) {
|
|
56
|
-
this.adapter = options
|
|
57
|
-
this.options.connName = 'nulladapter'
|
|
58
|
-
} else {
|
|
59
|
-
this.options = omit(options, ['name', 'adapter'])
|
|
60
|
-
this.options.connName = options.name
|
|
61
|
-
this.options.models = this.options.models ?? []
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Initialize the adapter for this connection. If the adapter is already an instance of `DoboAdapter`,
|
|
67
|
-
* it will be used directly. Otherwise, it will be retrieved from the plugin's adapter registry
|
|
68
|
-
* and sanitized with the connection options.
|
|
69
|
-
* @param {string} name - Adapter name
|
|
70
|
-
* @async
|
|
71
|
-
* @returns {Promise<void>}
|
|
72
|
-
*/
|
|
73
|
-
async initAdapter (name) {
|
|
74
|
-
if (name instanceof this.app.baseClass.DoboAdapter) this.adapter = name
|
|
75
|
-
else {
|
|
76
|
-
this.adapter = this.plugin.getAdapter(name)
|
|
77
|
-
await this.adapter.sanitizeConnection(this.options)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Establish this connection through the adapter to the actual database system. Adapter developer must
|
|
83
|
-
* provide a method named `connect()` to connect the underlying database and (optionally)
|
|
84
|
-
* return its client instance.
|
|
85
|
-
*
|
|
86
|
-
* @param {boolean} [noRebuild] - If `true`, the database table/collection won't be build automatically
|
|
87
|
-
* @retyrns {Promise<void>}
|
|
88
|
-
*/
|
|
89
|
-
async connect (noRebuild) {
|
|
90
|
-
const client = await this.adapter.connect(this, noRebuild)
|
|
91
|
-
if (client) this.client = client
|
|
92
|
-
this.connected = true
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Dispose this connection
|
|
97
|
-
* @async
|
|
98
|
-
* @returns {Promise<void>}
|
|
99
|
-
*/
|
|
100
|
-
dispose = async () => {
|
|
101
|
-
await super.dispose()
|
|
102
|
-
this.adapter = null
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
this.app.baseClass.DoboConnection = DoboConnection
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export default connectionFactory
|
|
1
|
+
/**
|
|
2
|
+
* @typedef TOptions
|
|
3
|
+
* @memberof DoboConnection
|
|
4
|
+
* @property {string} [name='default'] - Connection name
|
|
5
|
+
* @property {string[]} models - List of model names to be used with this connection. Use this property to force models to be bound to this connection only.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connection factory
|
|
10
|
+
*
|
|
11
|
+
* @async
|
|
12
|
+
*/
|
|
13
|
+
async function connectionFactory () {
|
|
14
|
+
const { Tools } = this.app.baseClass
|
|
15
|
+
const { omit } = this.app.lib._
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Connection class definition.
|
|
19
|
+
*
|
|
20
|
+
* @class
|
|
21
|
+
*/
|
|
22
|
+
class DoboConnection extends Tools {
|
|
23
|
+
constructor (plugin, options = {}) {
|
|
24
|
+
super(plugin)
|
|
25
|
+
/**
|
|
26
|
+
* Adapter object
|
|
27
|
+
* @type {Object}
|
|
28
|
+
*/
|
|
29
|
+
this.adapter = undefined
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Client instance
|
|
33
|
+
* @type {Object}
|
|
34
|
+
*/
|
|
35
|
+
this.client = undefined
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Connection name
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
this.name = options.name
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Connection options
|
|
45
|
+
* @type {DoboConnection.TOptions}
|
|
46
|
+
*/
|
|
47
|
+
this.options = {
|
|
48
|
+
models: []
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options object from connection defined on ```dobo.config.connections```
|
|
53
|
+
* @type {Object}
|
|
54
|
+
*/
|
|
55
|
+
if (options instanceof this.app.baseClass.DoboNullAdapter) {
|
|
56
|
+
this.adapter = options
|
|
57
|
+
this.options.connName = 'nulladapter'
|
|
58
|
+
} else {
|
|
59
|
+
this.options = omit(options, ['name', 'adapter'])
|
|
60
|
+
this.options.connName = options.name
|
|
61
|
+
this.options.models = this.options.models ?? []
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Initialize the adapter for this connection. If the adapter is already an instance of `DoboAdapter`,
|
|
67
|
+
* it will be used directly. Otherwise, it will be retrieved from the plugin's adapter registry
|
|
68
|
+
* and sanitized with the connection options.
|
|
69
|
+
* @param {string} name - Adapter name
|
|
70
|
+
* @async
|
|
71
|
+
* @returns {Promise<void>}
|
|
72
|
+
*/
|
|
73
|
+
async initAdapter (name) {
|
|
74
|
+
if (name instanceof this.app.baseClass.DoboAdapter) this.adapter = name
|
|
75
|
+
else {
|
|
76
|
+
this.adapter = this.plugin.getAdapter(name)
|
|
77
|
+
await this.adapter.sanitizeConnection(this.options)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Establish this connection through the adapter to the actual database system. Adapter developer must
|
|
83
|
+
* provide a method named `connect()` to connect the underlying database and (optionally)
|
|
84
|
+
* return its client instance.
|
|
85
|
+
*
|
|
86
|
+
* @param {boolean} [noRebuild] - If `true`, the database table/collection won't be build automatically
|
|
87
|
+
* @retyrns {Promise<void>}
|
|
88
|
+
*/
|
|
89
|
+
async connect (noRebuild) {
|
|
90
|
+
const client = await this.adapter.connect(this, noRebuild)
|
|
91
|
+
if (client) this.client = client
|
|
92
|
+
this.connected = true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Dispose this connection
|
|
97
|
+
* @async
|
|
98
|
+
* @returns {Promise<void>}
|
|
99
|
+
*/
|
|
100
|
+
dispose = async () => {
|
|
101
|
+
await super.dispose()
|
|
102
|
+
this.adapter = null
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.app.baseClass.DoboConnection = DoboConnection
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default connectionFactory
|
package/lib/factory/feature.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feature factory function.
|
|
3
|
-
*
|
|
4
|
-
* @async
|
|
5
|
-
* @returns {Promise<void>}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function featureFactory () {
|
|
9
|
-
const { Tools } = this.app.baseClass
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Feature class definition.
|
|
13
|
-
*
|
|
14
|
-
* `this.plugin` should be the one who owned this adapter
|
|
15
|
-
* @class
|
|
16
|
-
*/
|
|
17
|
-
class DoboFeature extends Tools {
|
|
18
|
-
/**
|
|
19
|
-
* Constructor.
|
|
20
|
-
*/
|
|
21
|
-
constructor (plugin, options = {}) {
|
|
22
|
-
super(plugin)
|
|
23
|
-
/**
|
|
24
|
-
* Feature name
|
|
25
|
-
* @type {string}
|
|
26
|
-
*/
|
|
27
|
-
this.name = options.name
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Feature handler function.
|
|
31
|
-
* @type {Function}
|
|
32
|
-
*/
|
|
33
|
-
this.handler = options.handler
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Dispose the instance and clean up resources.
|
|
38
|
-
* @async
|
|
39
|
-
* @method
|
|
40
|
-
* @returns {Promise<void>}
|
|
41
|
-
*/
|
|
42
|
-
dispose = async () => {
|
|
43
|
-
await super.dispose()
|
|
44
|
-
this.name = null
|
|
45
|
-
this.handler = null
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.app.baseClass.DoboFeature = DoboFeature
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default featureFactory
|
|
1
|
+
/**
|
|
2
|
+
* Feature factory function.
|
|
3
|
+
*
|
|
4
|
+
* @async
|
|
5
|
+
* @returns {Promise<void>}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function featureFactory () {
|
|
9
|
+
const { Tools } = this.app.baseClass
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Feature class definition.
|
|
13
|
+
*
|
|
14
|
+
* `this.plugin` should be the one who owned this adapter
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
class DoboFeature extends Tools {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor.
|
|
20
|
+
*/
|
|
21
|
+
constructor (plugin, options = {}) {
|
|
22
|
+
super(plugin)
|
|
23
|
+
/**
|
|
24
|
+
* Feature name
|
|
25
|
+
* @type {string}
|
|
26
|
+
*/
|
|
27
|
+
this.name = options.name
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Feature handler function.
|
|
31
|
+
* @type {Function}
|
|
32
|
+
*/
|
|
33
|
+
this.handler = options.handler
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Dispose the instance and clean up resources.
|
|
38
|
+
* @async
|
|
39
|
+
* @method
|
|
40
|
+
* @returns {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
dispose = async () => {
|
|
43
|
+
await super.dispose()
|
|
44
|
+
this.name = null
|
|
45
|
+
this.handler = null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.app.baseClass.DoboFeature = DoboFeature
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default featureFactory
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
-
const action = 'aggregate'
|
|
3
|
-
|
|
4
|
-
async function aggregate (...args) {
|
|
5
|
-
if (args.length === 0) return this.action(action, ...args)
|
|
6
|
-
const [_filter = {}, params = {}, opts = {}] = args
|
|
7
|
-
opts.dataOnly = opts.dataOnly ?? true
|
|
8
|
-
const { dataOnly } = opts
|
|
9
|
-
const { filter, options } = await getFilterAndOptions.call(this, _filter, opts, action)
|
|
10
|
-
const { getDefaultValues } = this.app.dobo
|
|
11
|
-
await execHook.call(this, 'beforeAggregate', filter, params, options)
|
|
12
|
-
await execModelHook.call(this, 'beforeAggregate', filter, params, options)
|
|
13
|
-
await execDynHook.call(this, 'beforeAggregate', filter, params, options)
|
|
14
|
-
const result = (await this.adapter._aggregate(this, filter, params, options)) ?? {}
|
|
15
|
-
const { warnings } = getDefaultValues(options)
|
|
16
|
-
if (!warnings) delete result.warnings
|
|
17
|
-
await execDynHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
18
|
-
await execModelHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
19
|
-
await execHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
20
|
-
return dataOnly ? result.data : result
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default aggregate
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
+
const action = 'aggregate'
|
|
3
|
+
|
|
4
|
+
async function aggregate (...args) {
|
|
5
|
+
if (args.length === 0) return this.action(action, ...args)
|
|
6
|
+
const [_filter = {}, params = {}, opts = {}] = args
|
|
7
|
+
opts.dataOnly = opts.dataOnly ?? true
|
|
8
|
+
const { dataOnly } = opts
|
|
9
|
+
const { filter, options } = await getFilterAndOptions.call(this, _filter, opts, action)
|
|
10
|
+
const { getDefaultValues } = this.app.dobo
|
|
11
|
+
await execHook.call(this, 'beforeAggregate', filter, params, options)
|
|
12
|
+
await execModelHook.call(this, 'beforeAggregate', filter, params, options)
|
|
13
|
+
await execDynHook.call(this, 'beforeAggregate', filter, params, options)
|
|
14
|
+
const result = (await this.adapter._aggregate(this, filter, params, options)) ?? {}
|
|
15
|
+
const { warnings } = getDefaultValues(options)
|
|
16
|
+
if (!warnings) delete result.warnings
|
|
17
|
+
await execDynHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
18
|
+
await execModelHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
19
|
+
await execHook.call(this, 'afterAggregate', filter, params, result, options)
|
|
20
|
+
return dataOnly ? result.data : result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default aggregate
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook } from './helper.js'
|
|
2
|
-
const action = 'build'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Build a model's definition based on its properties and rules.
|
|
6
|
-
*
|
|
7
|
-
* @async
|
|
8
|
-
* @memberof DoboModel
|
|
9
|
-
* @method
|
|
10
|
-
* @param {DoboModel.TOptions} opts - The options for building the model
|
|
11
|
-
* @returns {DoboModel.TResultRecord|DoboModel.TRecord}
|
|
12
|
-
*/
|
|
13
|
-
async function build (opts = {}) {
|
|
14
|
-
opts.dataOnly = opts.dataOnly ?? true
|
|
15
|
-
const { dataOnly } = opts
|
|
16
|
-
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
17
|
-
await execHook.call(this, 'beforeBuildModel', options)
|
|
18
|
-
await execModelHook.call(this, 'beforeBuildModel', options)
|
|
19
|
-
const result = (await this.adapter._buildModel(this, options)) ?? {}
|
|
20
|
-
await execModelHook.call(this, 'afterBuildModel', result, options)
|
|
21
|
-
await execHook.call(this, 'afterBuildModel', result, options)
|
|
22
|
-
return dataOnly ? result.data : result
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default build
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook } from './helper.js'
|
|
2
|
+
const action = 'build'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build a model's definition based on its properties and rules.
|
|
6
|
+
*
|
|
7
|
+
* @async
|
|
8
|
+
* @memberof DoboModel
|
|
9
|
+
* @method
|
|
10
|
+
* @param {DoboModel.TOptions} opts - The options for building the model
|
|
11
|
+
* @returns {DoboModel.TResultRecord|DoboModel.TRecord}
|
|
12
|
+
*/
|
|
13
|
+
async function build (opts = {}) {
|
|
14
|
+
opts.dataOnly = opts.dataOnly ?? true
|
|
15
|
+
const { dataOnly } = opts
|
|
16
|
+
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
17
|
+
await execHook.call(this, 'beforeBuildModel', options)
|
|
18
|
+
await execModelHook.call(this, 'beforeBuildModel', options)
|
|
19
|
+
const result = (await this.adapter._buildModel(this, options)) ?? {}
|
|
20
|
+
await execModelHook.call(this, 'afterBuildModel', result, options)
|
|
21
|
+
await execHook.call(this, 'afterBuildModel', result, options)
|
|
22
|
+
return dataOnly ? result.data : result
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default build
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook } from './helper.js'
|
|
2
|
-
|
|
3
|
-
export const onlyTypes = ['datetime', 'date', 'time', 'timestamp']
|
|
4
|
-
const action = 'bulkCreateRecord'
|
|
5
|
-
|
|
6
|
-
async function bulkCreateRecord (...args) {
|
|
7
|
-
if (args.length === 0) return this.action(action, ...args)
|
|
8
|
-
const [bodies = [], opts = {}] = args
|
|
9
|
-
const { cloneDeep, get } = this.app.lib._
|
|
10
|
-
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
11
|
-
const { truncateString, noBodySanitizer, noValidation } = options
|
|
12
|
-
const extFields = get(options, 'validation.extFields', [])
|
|
13
|
-
|
|
14
|
-
const inputs = cloneDeep(bodies)
|
|
15
|
-
if (!noBodySanitizer) {
|
|
16
|
-
for (const idx in inputs) {
|
|
17
|
-
inputs[idx] = await this.sanitizeBody({ body: inputs[idx], extFields, strict: true, truncateString, onlyTypes })
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
await execHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
21
|
-
await execModelHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
22
|
-
await execDynHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
23
|
-
if (!noValidation) {
|
|
24
|
-
for (const input of inputs) {
|
|
25
|
-
await execValidation.call(this, input, options)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// TODO: bulk don't return anything currently, it should return at least a stat
|
|
29
|
-
await this.adapter._bulkCreateRecord(this, inputs, options)
|
|
30
|
-
await execDynHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
31
|
-
await execModelHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
32
|
-
await execHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
33
|
-
return []
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default bulkCreateRecord
|
|
1
|
+
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook } from './helper.js'
|
|
2
|
+
|
|
3
|
+
export const onlyTypes = ['datetime', 'date', 'time', 'timestamp']
|
|
4
|
+
const action = 'bulkCreateRecord'
|
|
5
|
+
|
|
6
|
+
async function bulkCreateRecord (...args) {
|
|
7
|
+
if (args.length === 0) return this.action(action, ...args)
|
|
8
|
+
const [bodies = [], opts = {}] = args
|
|
9
|
+
const { cloneDeep, get } = this.app.lib._
|
|
10
|
+
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
11
|
+
const { truncateString, noBodySanitizer, noValidation } = options
|
|
12
|
+
const extFields = get(options, 'validation.extFields', [])
|
|
13
|
+
|
|
14
|
+
const inputs = cloneDeep(bodies)
|
|
15
|
+
if (!noBodySanitizer) {
|
|
16
|
+
for (const idx in inputs) {
|
|
17
|
+
inputs[idx] = await this.sanitizeBody({ body: inputs[idx], extFields, strict: true, truncateString, onlyTypes })
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
await execHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
21
|
+
await execModelHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
22
|
+
await execDynHook.call(this, 'beforeBulkCreateRecord', inputs, options)
|
|
23
|
+
if (!noValidation) {
|
|
24
|
+
for (const input of inputs) {
|
|
25
|
+
await execValidation.call(this, input, options)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// TODO: bulk don't return anything currently, it should return at least a stat
|
|
29
|
+
await this.adapter._bulkCreateRecord(this, inputs, options)
|
|
30
|
+
await execDynHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
31
|
+
await execModelHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
32
|
+
await execHook.call(this, 'afterBulkCreateRecord', inputs, options)
|
|
33
|
+
return []
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default bulkCreateRecord
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
-
const action = 'clearRecord'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Clears all records from the model's underlying data store.
|
|
6
|
-
*
|
|
7
|
-
* If no arguments are provided, it automatically turns into a chainable {@link DoboAction} object.
|
|
8
|
-
* @async
|
|
9
|
-
* @memberof DoboModel
|
|
10
|
-
* @method
|
|
11
|
-
* @param {DoboModel.TOptions} [opts={}] - Options object.
|
|
12
|
-
* @returns {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
|
|
13
|
-
*/
|
|
14
|
-
async function clearRecord (...args) {
|
|
15
|
-
if (args.length === 0) return this.action(action, ...args)
|
|
16
|
-
const [opts = {}] = args
|
|
17
|
-
opts.dataOnly = opts.dataOnly ?? true
|
|
18
|
-
const { dataOnly } = opts
|
|
19
|
-
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
20
|
-
await execHook.call(this, 'beforeClearRecord', options)
|
|
21
|
-
await execModelHook.call(this, 'beforeClearRecord', options)
|
|
22
|
-
await execDynHook.call(this, 'beforeClearRecord', options)
|
|
23
|
-
const result = (await this.adapter._clearRecord(this, options)) ?? {}
|
|
24
|
-
await execDynHook.call(this, 'afterClearRecord', result, options)
|
|
25
|
-
await execModelHook.call(this, 'afterClearRecord', result, options)
|
|
26
|
-
await execHook.call(this, 'afterClearRecord', result, options)
|
|
27
|
-
return dataOnly ? result.data : result
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default clearRecord
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
+
const action = 'clearRecord'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Clears all records from the model's underlying data store.
|
|
6
|
+
*
|
|
7
|
+
* If no arguments are provided, it automatically turns into a chainable {@link DoboAction} object.
|
|
8
|
+
* @async
|
|
9
|
+
* @memberof DoboModel
|
|
10
|
+
* @method
|
|
11
|
+
* @param {DoboModel.TOptions} [opts={}] - Options object.
|
|
12
|
+
* @returns {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
|
|
13
|
+
*/
|
|
14
|
+
async function clearRecord (...args) {
|
|
15
|
+
if (args.length === 0) return this.action(action, ...args)
|
|
16
|
+
const [opts = {}] = args
|
|
17
|
+
opts.dataOnly = opts.dataOnly ?? true
|
|
18
|
+
const { dataOnly } = opts
|
|
19
|
+
const { options } = await getFilterAndOptions.call(this, null, opts, action)
|
|
20
|
+
await execHook.call(this, 'beforeClearRecord', options)
|
|
21
|
+
await execModelHook.call(this, 'beforeClearRecord', options)
|
|
22
|
+
await execDynHook.call(this, 'beforeClearRecord', options)
|
|
23
|
+
const result = (await this.adapter._clearRecord(this, options)) ?? {}
|
|
24
|
+
await execDynHook.call(this, 'afterClearRecord', result, options)
|
|
25
|
+
await execModelHook.call(this, 'afterClearRecord', result, options)
|
|
26
|
+
await execHook.call(this, 'afterClearRecord', result, options)
|
|
27
|
+
return dataOnly ? result.data : result
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default clearRecord
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
-
const action = 'countRecord'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Counts the number of records in the model's underlying data store that match the provided filter criteria.
|
|
6
|
-
*
|
|
7
|
-
* If no arguments are provided, it automatically turns into a chainable {@link DoboAction} object.
|
|
8
|
-
* @async
|
|
9
|
-
* @memberof DoboModel
|
|
10
|
-
* @method
|
|
11
|
-
* @param {DoboModel.TFilter} [filter={}] - The filter criteria to apply when counting records.
|
|
12
|
-
* @param {DoboModel.TOptions} [opts={}] - Options object.
|
|
13
|
-
* @returns {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
|
|
14
|
-
*/
|
|
15
|
-
async function countRecord (...args) {
|
|
16
|
-
const { getDefaultValues } = this.app.dobo
|
|
17
|
-
if (args.length === 0) return this.action(action, ...args)
|
|
18
|
-
const [params = {}, opts = {}] = args
|
|
19
|
-
opts.dataOnly = opts.dataOnly ?? true
|
|
20
|
-
const { dataOnly } = opts
|
|
21
|
-
const { filter, options } = await getFilterAndOptions.call(this, params, opts, action)
|
|
22
|
-
const { hardCap, t } = getDefaultValues(options)
|
|
23
|
-
await execHook.call(this, 'beforeCountRecord', filter, options)
|
|
24
|
-
await execModelHook.call(this, 'beforeCountRecord', filter, options)
|
|
25
|
-
await execDynHook.call(this, 'beforeCountRecord', filter, options)
|
|
26
|
-
const result = (await this.adapter._countRecord(this, filter, options)) ?? {}
|
|
27
|
-
if (result.data > hardCap) {
|
|
28
|
-
result.warnings = result.warnings ?? []
|
|
29
|
-
result.warnings.push(t('hardCapWarning%s%s', result.data, hardCap))
|
|
30
|
-
result.orgCount = result.data
|
|
31
|
-
result.hardCapped = true
|
|
32
|
-
result.data = hardCap
|
|
33
|
-
}
|
|
34
|
-
const { warnings } = getDefaultValues(options)
|
|
35
|
-
if (!warnings) delete result.warnings
|
|
36
|
-
await execDynHook.call(this, 'afterCountRecord', filter, result, options)
|
|
37
|
-
await execModelHook.call(this, 'afterCountRecord', filter, result, options)
|
|
38
|
-
await execHook.call(this, 'afterCountRecord', filter, result, options)
|
|
39
|
-
return dataOnly ? result.data : result
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default countRecord
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook } from './helper.js'
|
|
2
|
+
const action = 'countRecord'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Counts the number of records in the model's underlying data store that match the provided filter criteria.
|
|
6
|
+
*
|
|
7
|
+
* If no arguments are provided, it automatically turns into a chainable {@link DoboAction} object.
|
|
8
|
+
* @async
|
|
9
|
+
* @memberof DoboModel
|
|
10
|
+
* @method
|
|
11
|
+
* @param {DoboModel.TFilter} [filter={}] - The filter criteria to apply when counting records.
|
|
12
|
+
* @param {DoboModel.TOptions} [opts={}] - Options object.
|
|
13
|
+
* @returns {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
|
|
14
|
+
*/
|
|
15
|
+
async function countRecord (...args) {
|
|
16
|
+
const { getDefaultValues } = this.app.dobo
|
|
17
|
+
if (args.length === 0) return this.action(action, ...args)
|
|
18
|
+
const [params = {}, opts = {}] = args
|
|
19
|
+
opts.dataOnly = opts.dataOnly ?? true
|
|
20
|
+
const { dataOnly } = opts
|
|
21
|
+
const { filter, options } = await getFilterAndOptions.call(this, params, opts, action)
|
|
22
|
+
const { hardCap, t } = getDefaultValues(options)
|
|
23
|
+
await execHook.call(this, 'beforeCountRecord', filter, options)
|
|
24
|
+
await execModelHook.call(this, 'beforeCountRecord', filter, options)
|
|
25
|
+
await execDynHook.call(this, 'beforeCountRecord', filter, options)
|
|
26
|
+
const result = (await this.adapter._countRecord(this, filter, options)) ?? {}
|
|
27
|
+
if (result.data > hardCap) {
|
|
28
|
+
result.warnings = result.warnings ?? []
|
|
29
|
+
result.warnings.push(t('hardCapWarning%s%s', result.data, hardCap))
|
|
30
|
+
result.orgCount = result.data
|
|
31
|
+
result.hardCapped = true
|
|
32
|
+
result.data = hardCap
|
|
33
|
+
}
|
|
34
|
+
const { warnings } = getDefaultValues(options)
|
|
35
|
+
if (!warnings) delete result.warnings
|
|
36
|
+
await execDynHook.call(this, 'afterCountRecord', filter, result, options)
|
|
37
|
+
await execModelHook.call(this, 'afterCountRecord', filter, result, options)
|
|
38
|
+
await execHook.call(this, 'afterCountRecord', filter, result, options)
|
|
39
|
+
return dataOnly ? result.data : result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default countRecord
|