@mojaloop/database-lib 11.3.7 → 11.3.8
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/.circleci/config.yml +1 -1
- package/.ncurc.js +18 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +1 -1
- package/audit-ci.jsonc +0 -1
- package/package.json +22 -18
- package/src/database.js +26 -0
- package/src/index.js +26 -0
- package/src/migrations.js +26 -0
- package/src/table.js +44 -14
- package/src/utils.js +26 -0
- package/test/integration/database.test.js +26 -0
- package/test/unit/database.test.js +28 -3
- package/test/unit/index.test.js +26 -0
- package/test/unit/migrations.test.js +26 -0
- package/test/unit/table.test.js +80 -4
- package/test/unit/utils.test.js +26 -0
package/.circleci/config.yml
CHANGED
package/.ncurc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
reject: [
|
|
3
|
+
// knex is the core runtime dependency of this library — the entire Table/Database
|
|
4
|
+
// abstraction wraps the Knex query builder and migration API. A major bump (3.x -> 4.x)
|
|
5
|
+
// can change query-builder behaviour, pool handling and migration semantics, so it needs a
|
|
6
|
+
// deliberate, well-tested migration rather than a routine maintenance bump. Pin to 3.x.
|
|
7
|
+
'knex',
|
|
8
|
+
// mysql / mysql2 are the database drivers consumed directly by knex at runtime. Driver
|
|
9
|
+
// major bumps can change connection/auth behaviour and SQL handling; upgrade only with a
|
|
10
|
+
// dedicated integration-test pass against a live database. Keep within current majors.
|
|
11
|
+
'mysql',
|
|
12
|
+
'mysql2',
|
|
13
|
+
// standard-version is deprecated and its last release is 9.5.0; there is no non-major
|
|
14
|
+
// successor under the same name (the maintained fork is commit-and-tag-version). Pin to
|
|
15
|
+
// avoid ncu offering a cross-package/major change as part of routine updates.
|
|
16
|
+
'standard-version'
|
|
17
|
+
]
|
|
18
|
+
}
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
24.18.0
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [11.3.8](https://github.com/mojaloop/database-lib/compare/v11.3.7...v11.3.8) (2026-06-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* upgrade dependencies ([#192](https://github.com/mojaloop/database-lib/issues/192)) ([68d2cc6](https://github.com/mojaloop/database-lib/commit/68d2cc655042dce0076df2f86bae8c0ca9e99112))
|
|
11
|
+
|
|
5
12
|
### [11.3.7](https://github.com/mojaloop/database-lib/compare/v11.3.6...v11.3.7) (2026-02-18)
|
|
6
13
|
|
|
7
14
|
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# LICENSE
|
|
2
2
|
|
|
3
|
-
Copyright © 2020-
|
|
3
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
4
4
|
|
|
5
5
|
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License.
|
|
6
6
|
|
package/audit-ci.jsonc
CHANGED
|
@@ -4,6 +4,5 @@
|
|
|
4
4
|
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
|
|
5
5
|
"moderate": true,
|
|
6
6
|
"allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
|
|
7
|
-
"GHSA-2g4f-4pwh-qvx6" // ajv ReDoS with $data option - transitive via eslint, override breaks standardjs linter
|
|
8
7
|
]
|
|
9
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/database-lib",
|
|
3
|
-
"version": "11.3.
|
|
3
|
+
"version": "11.3.8",
|
|
4
4
|
"description": "Shared database code for central services",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"pre-commit": [
|
|
21
21
|
"standard",
|
|
22
22
|
"dep:check",
|
|
23
|
-
"test"
|
|
23
|
+
"test",
|
|
24
|
+
"license:check"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"pretest": "npm run lint",
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"test:integration": "./test/scripts/test-integration.sh",
|
|
40
41
|
"audit:fix": "npm audit fix",
|
|
41
42
|
"audit:check": "npx audit-ci --config ./audit-ci.jsonc",
|
|
43
|
+
"license:check": "npx @mojaloop/license-scanner-tool .",
|
|
42
44
|
"dep:check": "npx ncu -e 2",
|
|
43
45
|
"dep:update": "npx ncu -u",
|
|
44
46
|
"release": "standard-version --releaseCommitMessageFormat 'chore(release): {{currentTag}} [skip ci]'"
|
|
@@ -46,13 +48,13 @@
|
|
|
46
48
|
"dependencies": {
|
|
47
49
|
"@mojaloop/central-services-error-handling": "13.1.6",
|
|
48
50
|
"async-exit-hook": "^2.0.1",
|
|
49
|
-
"knex": "3.
|
|
50
|
-
"lodash": "4.17.23",
|
|
51
|
+
"knex": "3.2.10",
|
|
51
52
|
"mysql": "^2.18.1",
|
|
52
|
-
"mysql2": "^3.
|
|
53
|
+
"mysql2": "^3.22.5"
|
|
53
54
|
},
|
|
54
55
|
"overrides": {
|
|
55
56
|
"form-data": "4.0.4",
|
|
57
|
+
"js-yaml": "4.2.0",
|
|
56
58
|
"tar": "6.2.1",
|
|
57
59
|
"@mojaloop/ml-schema-transformer-lib": {
|
|
58
60
|
"@mojaloop/central-services-shared": {
|
|
@@ -73,29 +75,31 @@
|
|
|
73
75
|
},
|
|
74
76
|
"cross-spawn": "7.0.6",
|
|
75
77
|
"trim": "0.0.3",
|
|
76
|
-
"undici": "6.23.
|
|
78
|
+
"undici": "6.23.1",
|
|
79
|
+
"immutable": "5.1.5",
|
|
77
80
|
"yargs-parser": "21.1.1",
|
|
78
81
|
"validator": "13.15.22",
|
|
79
|
-
"fast-xml-parser": "5.
|
|
82
|
+
"fast-xml-parser": "5.5.6",
|
|
80
83
|
"qs": "6.14.2",
|
|
81
|
-
"axios": "1.13.
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
+
"axios": "1.13.6",
|
|
85
|
+
"ajv": "6.14.0",
|
|
86
|
+
"brace-expansion": "2.0.3",
|
|
87
|
+
"lodash": "4.18.1"
|
|
84
88
|
},
|
|
85
89
|
"devDependencies": {
|
|
86
|
-
"@mojaloop/
|
|
90
|
+
"@mojaloop/license-scanner-tool": "^1.1.1",
|
|
87
91
|
"audit-ci": "^7.1.0",
|
|
88
|
-
"jest": "^30.2
|
|
89
|
-
"npm-check-updates": "
|
|
90
|
-
"nyc": "
|
|
91
|
-
"pre-commit": "
|
|
92
|
+
"jest": "^30.4.2",
|
|
93
|
+
"npm-check-updates": "22.2.7",
|
|
94
|
+
"nyc": "18.0.0",
|
|
95
|
+
"pre-commit": "2.0.0",
|
|
92
96
|
"proxyquire": "2.1.3",
|
|
93
|
-
"sinon": "
|
|
97
|
+
"sinon": "22.0.0",
|
|
94
98
|
"standard": "17.1.2",
|
|
95
99
|
"standard-version": "9.5.0",
|
|
96
|
-
"tap-spec": "
|
|
100
|
+
"tap-spec": "5.0.0",
|
|
97
101
|
"tap-xunit": "2.4.1",
|
|
98
|
-
"tape": "5.
|
|
102
|
+
"tape": "5.10.2",
|
|
99
103
|
"tapes": "4.1.0"
|
|
100
104
|
},
|
|
101
105
|
"publishConfig": {
|
package/src/database.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const Knex = require('knex')
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const Database = require('./database')
|
package/src/migrations.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const Knex = require('knex')
|
package/src/table.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
|
-
const
|
|
29
|
+
const assert = require('node:assert')
|
|
4
30
|
|
|
5
31
|
class Table {
|
|
6
32
|
constructor (name, knex) {
|
|
@@ -41,7 +67,7 @@ class Table {
|
|
|
41
67
|
|
|
42
68
|
destroy (criteria) {
|
|
43
69
|
const builder = this._createBuilder()
|
|
44
|
-
return this._addWhere(criteria, builder).del(
|
|
70
|
+
return this._addWhere(criteria, builder).del().then(deleted => {
|
|
45
71
|
if (deleted.length === 0) return null
|
|
46
72
|
return deleted.length === 1 ? deleted[0] : deleted
|
|
47
73
|
})
|
|
@@ -76,20 +102,24 @@ class Table {
|
|
|
76
102
|
|
|
77
103
|
_addWhere (params, builder) {
|
|
78
104
|
const criteria = params || {}
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
if (Object.keys(criteria).length === 0) {
|
|
106
|
+
return builder
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
Object.keys(criteria).forEach(key => {
|
|
110
|
+
const value = criteria[key]
|
|
111
|
+
assert(value)
|
|
112
|
+
const condition = this._parseCriteriaKey(key)
|
|
113
|
+
if (condition.length === 1) {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
builder = builder.whereIn(condition[0], value)
|
|
88
116
|
} else {
|
|
89
|
-
builder = builder.where(condition[0],
|
|
117
|
+
builder = builder.where(condition[0], value)
|
|
90
118
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
119
|
+
} else {
|
|
120
|
+
builder = builder.where(condition[0], condition[1], value)
|
|
121
|
+
}
|
|
122
|
+
})
|
|
93
123
|
return builder
|
|
94
124
|
}
|
|
95
125
|
|
package/src/utils.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
/**
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
/* global describe, beforeEach, afterEach, test, expect */
|
|
2
28
|
const Database = require('../../src/database')
|
|
3
29
|
const fs = require('fs')
|
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const src = '../../src'
|
|
4
30
|
const Test = require('tapes')(require('tape'))
|
|
5
31
|
const Sinon = require('sinon')
|
|
6
32
|
const Proxyquire = require('proxyquire')
|
|
7
|
-
const lodash = require('lodash')
|
|
8
33
|
|
|
9
34
|
Test('database', databaseTest => {
|
|
10
35
|
let sandbox
|
|
@@ -157,7 +182,7 @@ Test('database', databaseTest => {
|
|
|
157
182
|
|
|
158
183
|
connectTest.test('throw error for invalid database schema', async (test) => {
|
|
159
184
|
try {
|
|
160
|
-
const connectionConfigDuplicate =
|
|
185
|
+
const connectionConfigDuplicate = structuredClone(connectionConfig)
|
|
161
186
|
connectionConfigDuplicate.connection.database = undefined
|
|
162
187
|
await dbInstance.connect(connectionConfigDuplicate)
|
|
163
188
|
test.fail('Should have thrown error')
|
|
@@ -170,7 +195,7 @@ Test('database', databaseTest => {
|
|
|
170
195
|
})
|
|
171
196
|
|
|
172
197
|
connectTest.test('connect using connection config pg and setup table properties', async test => {
|
|
173
|
-
const connectionConfigDuplicate =
|
|
198
|
+
const connectionConfigDuplicate = structuredClone(connectionConfig)
|
|
174
199
|
connectionConfigDuplicate.client = 'pg'
|
|
175
200
|
knexConnStub.client = { config: { client: 'pg' } }
|
|
176
201
|
await dbInstance.connect(connectionConfigDuplicate)
|
package/test/unit/index.test.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const Test = require('tape')
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const Test = require('tapes')(require('tape'))
|
package/test/unit/table.test.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const src = '../../src'
|
|
@@ -368,7 +394,8 @@ Test('table', tableTest => {
|
|
|
368
394
|
.then(record => {
|
|
369
395
|
test.equal(record, deleted)
|
|
370
396
|
test.ok(builderStub.where.calledWith('id', 1))
|
|
371
|
-
test.ok(delStub.
|
|
397
|
+
test.ok(delStub.calledOnce)
|
|
398
|
+
test.ok(delStub.calledWith())
|
|
372
399
|
test.end()
|
|
373
400
|
})
|
|
374
401
|
})
|
|
@@ -385,7 +412,8 @@ Test('table', tableTest => {
|
|
|
385
412
|
.then(records => {
|
|
386
413
|
test.equal(records, deleted)
|
|
387
414
|
test.ok(builderStub.where.calledWith('accountId', 3))
|
|
388
|
-
test.ok(delStub.
|
|
415
|
+
test.ok(delStub.calledOnce)
|
|
416
|
+
test.ok(delStub.calledWith())
|
|
389
417
|
test.end()
|
|
390
418
|
})
|
|
391
419
|
})
|
|
@@ -413,7 +441,8 @@ Test('table', tableTest => {
|
|
|
413
441
|
table.destroy({})
|
|
414
442
|
.then(records => {
|
|
415
443
|
test.equal(records, deleted)
|
|
416
|
-
test.ok(builderStub.del.
|
|
444
|
+
test.ok(builderStub.del.calledOnce)
|
|
445
|
+
test.ok(builderStub.del.calledWith())
|
|
417
446
|
test.end()
|
|
418
447
|
})
|
|
419
448
|
})
|
|
@@ -426,7 +455,8 @@ Test('table', tableTest => {
|
|
|
426
455
|
table.destroy(null)
|
|
427
456
|
.then(records => {
|
|
428
457
|
test.equal(records, deleted)
|
|
429
|
-
test.ok(builderStub.del.
|
|
458
|
+
test.ok(builderStub.del.calledOnce)
|
|
459
|
+
test.ok(builderStub.del.calledWith())
|
|
430
460
|
test.end()
|
|
431
461
|
})
|
|
432
462
|
})
|
|
@@ -530,5 +560,51 @@ Test('table', tableTest => {
|
|
|
530
560
|
queryFuncTest.end()
|
|
531
561
|
})
|
|
532
562
|
|
|
563
|
+
tableTest.test('_addWhere should', addWhereTest => {
|
|
564
|
+
addWhereTest.test('return builder unchanged when params is null or empty', test => {
|
|
565
|
+
test.equal(table._addWhere(null, builderStub), builderStub)
|
|
566
|
+
test.equal(table._addWhere(undefined, builderStub), builderStub)
|
|
567
|
+
test.equal(table._addWhere({}, builderStub), builderStub)
|
|
568
|
+
test.end()
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
addWhereTest.test('call where for simple equality criteria', test => {
|
|
572
|
+
const mockBuilder = { where: sandbox.stub().returnsThis() }
|
|
573
|
+
table._addWhere({ id: 1, name: 'test' }, mockBuilder)
|
|
574
|
+
test.ok(mockBuilder.where.calledWith('id', 1))
|
|
575
|
+
test.ok(mockBuilder.where.calledWith('name', 'test'))
|
|
576
|
+
test.end()
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
addWhereTest.test('call whereIn when value is an array', test => {
|
|
580
|
+
const mockBuilder = { whereIn: sandbox.stub().returnsThis() }
|
|
581
|
+
table._addWhere({ id: [1, 2, 3] }, mockBuilder)
|
|
582
|
+
test.ok(mockBuilder.whereIn.calledWith('id', [1, 2, 3]))
|
|
583
|
+
test.end()
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
addWhereTest.test('call where with operator for comparison criteria', test => {
|
|
587
|
+
const mockBuilder = { where: sandbox.stub().returnsThis() }
|
|
588
|
+
table._addWhere({ 'id >=': 5, 'num <': 10 }, mockBuilder)
|
|
589
|
+
test.ok(mockBuilder.where.calledWith('id', '>=', 5))
|
|
590
|
+
test.ok(mockBuilder.where.calledWith('num', '<', 10))
|
|
591
|
+
test.end()
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
addWhereTest.test('handle mixed criteria types', test => {
|
|
595
|
+
const mockBuilder = {
|
|
596
|
+
where: sandbox.stub().returnsThis(),
|
|
597
|
+
whereIn: sandbox.stub().returnsThis()
|
|
598
|
+
}
|
|
599
|
+
table._addWhere({ id: 1, 'num >': 5, tags: ['a', 'b'] }, mockBuilder)
|
|
600
|
+
test.ok(mockBuilder.where.calledWith('id', 1))
|
|
601
|
+
test.ok(mockBuilder.where.calledWith('num', '>', 5))
|
|
602
|
+
test.ok(mockBuilder.whereIn.calledWith('tags', ['a', 'b']))
|
|
603
|
+
test.end()
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
addWhereTest.end()
|
|
607
|
+
})
|
|
608
|
+
|
|
533
609
|
tableTest.end()
|
|
534
610
|
})
|
package/test/unit/utils.test.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
*****/
|
|
26
|
+
|
|
1
27
|
'use strict'
|
|
2
28
|
|
|
3
29
|
const src = '../../src'
|