Skip to content

Commit 1616c43

Browse files
committed
Merge branch 'release-5.0.3'
2 parents 60b446c + 747569f commit 1616c43

File tree

14 files changed

+1278
-814
lines changed

14 files changed

+1278
-814
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@dadi"
3+
}

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@dadi/prettier-config"

config.js

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ const fs = require('fs')
44
const DATABASE_SCHEMA = {
55
authDatabase: {
66
default: '',
7-
doc: 'The database to authenticate against when supplying a username and password',
7+
doc:
8+
'The database to authenticate against when supplying a username and password',
89
envTemplate: 'DB_{database}_AUTH_SOURCE',
910
format: String
1011
},
1112
authMechanism: {
1213
default: '',
13-
doc: 'If no authentication mechanism is specified or the mechanism DEFAULT is specified, the driver will attempt to authenticate using the SCRAM-SHA-1 authentication method if it is available on the MongoDB server. If the server does not support SCRAM-SHA-1 the driver will authenticate using MONGODB-CR.',
14+
doc:
15+
'If no authentication mechanism is specified or the mechanism DEFAULT is specified, the driver will attempt to authenticate using the SCRAM-SHA-1 authentication method if it is available on the MongoDB server. If the server does not support SCRAM-SHA-1 the driver will authenticate using MONGODB-CR.',
1416
envTemplate: 'DB_{database}_AUTH_MECHANISM',
1517
format: String
1618
},
@@ -21,7 +23,8 @@ const DATABASE_SCHEMA = {
2123
format: Boolean
2224
},
2325
hosts: {
24-
default: 'Comma-separated string of MongoDB hosts, including port (e.g. localhost,localhost:27018,localhost:27019)',
26+
default:
27+
'Comma-separated string of MongoDB hosts, including port (e.g. localhost,localhost:27018,localhost:27019)',
2528
doc: 'Database hosts',
2629
format: String,
2730
envTemplate: 'DB_{database}_HOSTS'
@@ -44,8 +47,15 @@ const DATABASE_SCHEMA = {
4447
envTemplate: 'DB_{database}_PASSWORD'
4548
},
4649
readPreference: {
47-
doc: 'How MongoDB routes read operations to the members of a replica set - see https://docs.mongodb.com/manual/reference/read-preference/',
48-
format: ['primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'],
50+
doc:
51+
'How MongoDB routes read operations to the members of a replica set - see https://docs.mongodb.com/manual/reference/read-preference/',
52+
format: [
53+
'primary',
54+
'primaryPreferred',
55+
'secondary',
56+
'secondaryPreferred',
57+
'nearest'
58+
],
4959
default: 'secondaryPreferred'
5060
},
5161
replicaSet: {
@@ -69,7 +79,8 @@ const DATABASE_SCHEMA = {
6979
const MAIN_SCHEMA = {
7080
databases: {
7181
default: [],
72-
doc: 'Configuration block for each of the databases used throughout the application',
82+
doc:
83+
'Configuration block for each of the databases used throughout the application',
7384
format: Array
7485
},
7586
enableCollectionDatabases: {
@@ -86,12 +97,14 @@ const MAIN_SCHEMA = {
8697
}
8798
}
8899

89-
function transformLegacyDatabaseBlock (name, block) {
90-
const hosts = block.hosts.map(({host, port}) => {
91-
return `${host}:${port || 27017}`
92-
}).join(',')
100+
function transformLegacyDatabaseBlock(name, block) {
101+
const hosts = block.hosts
102+
.map(({host, port}) => {
103+
return `${host}:${port || 27017}`
104+
})
105+
.join(',')
93106

94-
let newBlock = {
107+
const newBlock = {
95108
id: name
96109
}
97110

@@ -106,7 +119,7 @@ function transformLegacyDatabaseBlock (name, block) {
106119
return newBlock
107120
}
108121

109-
let mainConfig = convict(MAIN_SCHEMA)
122+
const mainConfig = convict(MAIN_SCHEMA)
110123

111124
const loadConfig = () => {
112125
// Load environment dependent configuration.
@@ -124,9 +137,13 @@ const loadConfig = () => {
124137
return transformLegacyDatabaseBlock(name, data.databases[name])
125138
})
126139

127-
const exampleConfig = JSON.stringify({
128-
databases: data.databases
129-
}, null, 2)
140+
const exampleConfig = JSON.stringify(
141+
{
142+
databases: data.databases
143+
},
144+
null,
145+
2
146+
)
130147

131148
console.warn(
132149
`The current MongoDB configuration uses a \`databases\` object. This syntax has been deprecated and will be removed in a future release. Please update your database configuration to:\n\n${exampleConfig}`
@@ -146,16 +163,22 @@ const loadConfig = () => {
146163
if (database.id === data.database) {
147164
data.databases[index].default = true
148165

149-
const exampleConfig = JSON.stringify({
150-
databases: data.databases
151-
}, null, 2)
152-
166+
const exampleConfig = JSON.stringify(
167+
{
168+
databases: data.databases
169+
},
170+
null,
171+
2
172+
)
173+
153174
console.warn(
154175
`The current MongoDB configuration uses a \`database\` property to indicate the default database. This syntax has been deprecated and will be removed in a future release. Please update your database configuration to:\n\n${exampleConfig}`
155176
)
156177

157178
return true
158179
}
180+
181+
return false
159182
})
160183
}
161184

@@ -172,15 +195,19 @@ const loadConfig = () => {
172195
readPreference: data.readPreference,
173196
replicaSet: data.replicaSet,
174197
ssl: data.ssl,
175-
username: data.username,
198+
username: data.username
176199
}
177200
const newBlock = transformLegacyDatabaseBlock(data.database, legacyBlock)
178-
201+
179202
data.databases.push(newBlock)
180203

181-
const exampleConfig = JSON.stringify({
182-
databases: [newBlock]
183-
}, null, 2)
204+
const exampleConfig = JSON.stringify(
205+
{
206+
databases: [newBlock]
207+
},
208+
null,
209+
2
210+
)
184211

185212
console.warn(
186213
`The current MongoDB configuration uses a \`hosts\` array at the root level. This syntax has been deprecated and will be removed in a future release. Please update your database configuration to:\n\n${exampleConfig}`
@@ -192,15 +219,15 @@ const loadConfig = () => {
192219

193220
// Validating databases.
194221
const databases = mainConfig.get('databases')
195-
222+
196223
databases.forEach((database, databaseIndex) => {
197224
const databaseConfig = convict(DATABASE_SCHEMA)
198-
225+
199226
databaseConfig.load(database)
200227
databaseConfig.validate()
201-
228+
202229
const schema = databaseConfig.getSchema().properties
203-
230+
204231
// Listening for database-specific environment variables.
205232
// e.g. DB_testdb_USERNAME
206233
Object.keys(schema).forEach(key => {

config/mongodb.test.json.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"database": "testdb",
32
"databases": [
43
{
54
"id": "authdb",
@@ -9,7 +8,8 @@
98
},
109
{
1110
"id": "defaultdb",
12-
"hosts": "127.0.0.1:27017"
11+
"hosts": "127.0.0.1:27017",
12+
"default": true
1313
},
1414
{
1515
"id": "invaliddb",

0 commit comments

Comments
 (0)