monastery 3.0.4 → 3.0.5
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/changelog.md +2 -0
- package/lib/index.js +5 -2
- package/package.json +1 -1
- package/test/manager.js +21 -5
package/changelog.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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
|
+
### [3.0.5](https://github.com/boycce/monastery/compare/3.0.4...3.0.5) (2024-04-29)
|
|
6
|
+
|
|
5
7
|
### [3.0.4](https://github.com/boycce/monastery/compare/3.0.3...3.0.4) (2024-04-29)
|
|
6
8
|
|
|
7
9
|
### [3.0.3](https://github.com/boycce/monastery/compare/3.0.2...3.0.3) (2024-04-28)
|
package/lib/index.js
CHANGED
|
@@ -215,7 +215,7 @@ Manager.prototype.onError = function(fn) {
|
|
|
215
215
|
resolve(err)
|
|
216
216
|
})
|
|
217
217
|
}).then((err) => {
|
|
218
|
-
fn(err)
|
|
218
|
+
return fn(err)
|
|
219
219
|
})
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -226,6 +226,9 @@ Manager.prototype.onOpen = function(fn) {
|
|
|
226
226
|
* @return {Promise(manager)}
|
|
227
227
|
*/
|
|
228
228
|
return new Promise((resolve, reject) => {
|
|
229
|
+
if (this._state == 'open') {
|
|
230
|
+
resolve(this)
|
|
231
|
+
}
|
|
229
232
|
this.on('open', () => {
|
|
230
233
|
resolve(this)
|
|
231
234
|
})
|
|
@@ -233,7 +236,7 @@ Manager.prototype.onOpen = function(fn) {
|
|
|
233
236
|
reject(err)
|
|
234
237
|
})
|
|
235
238
|
}).then((err) => { // If `then` is not chained, the error will be thrown, detached!
|
|
236
|
-
fn(err)
|
|
239
|
+
return fn(err)
|
|
237
240
|
})
|
|
238
241
|
}
|
|
239
242
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "monastery",
|
|
3
3
|
"description": "⛪ A simple, straightforward MongoDB ODM",
|
|
4
4
|
"author": "Ricky Boyce",
|
|
5
|
-
"version": "3.0.
|
|
5
|
+
"version": "3.0.5",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/test/manager.js
CHANGED
|
@@ -18,18 +18,34 @@ test('manager > uri error', async () => {
|
|
|
18
18
|
|
|
19
19
|
test('manager > onError', async () => {
|
|
20
20
|
// Bad port (thrown by MongoDB)
|
|
21
|
-
let error
|
|
22
21
|
const db = monastery('localhost:1234/monastery', { serverSelectionTimeoutMS: 500 })
|
|
23
|
-
|
|
22
|
+
let error, isAPromise
|
|
23
|
+
await db.onError((res) => { error = res.message }).then(() => { isAPromise = true })
|
|
24
24
|
expect(error).toEqual('connect ECONNREFUSED 127.0.0.1:1234')
|
|
25
|
+
expect(isAPromise).toEqual(true)
|
|
25
26
|
db.close()
|
|
26
27
|
})
|
|
27
28
|
|
|
28
29
|
test('manager > onOpen', async () => {
|
|
29
|
-
let manager
|
|
30
30
|
const db = monastery('localhost/monastery', { serverSelectionTimeoutMS: 500 })
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
32
|
+
let manager1
|
|
33
|
+
await db.onOpen((res) => { manager1 = res })
|
|
34
|
+
expect(manager1.open).toEqual(expect.any(Function))
|
|
35
|
+
|
|
36
|
+
// Wait until after the client has been connected
|
|
37
|
+
await new Promise((resolve, reject) => {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
resolve()
|
|
40
|
+
}, 1000)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// This should still run after the client has been connected
|
|
44
|
+
let manager2
|
|
45
|
+
let isAPromise
|
|
46
|
+
await db.onOpen((res) => { manager2 = res }).then(() => { isAPromise = true })
|
|
47
|
+
expect(manager2.open).toEqual(expect.any(Function))
|
|
48
|
+
expect(isAPromise).toEqual(true)
|
|
33
49
|
db.close()
|
|
34
50
|
})
|
|
35
51
|
|