monastery 3.0.6 → 3.0.7

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 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.7](https://github.com/boycce/monastery/compare/3.0.5...3.0.7) (2024-04-29)
6
+
5
7
  ### [3.0.6](https://github.com/boycce/monastery/compare/3.0.5...3.0.6) (2024-04-29)
6
8
 
7
9
  ### [3.0.5](https://github.com/boycce/monastery/compare/3.0.4...3.0.5) (2024-04-29)
package/docs/readme.md CHANGED
@@ -92,6 +92,7 @@ You can view MongoDB's [compatibility table here](https://www.mongodb.com/docs/d
92
92
  - db._client moved to db.client
93
93
  - db._db moved to db.db
94
94
  - db.catch/then() moved to db.onError/db.onOpen()
95
+ - next() is now redundant when returning promises from hooks, e.g. `afterFind: [async (data) => {...}]`
95
96
 
96
97
  ## Roadmap
97
98
 
package/lib/util.js CHANGED
@@ -328,8 +328,9 @@ module.exports = {
328
328
  console.error(`Monastery ${info} error: you cannot return a promise AND call next()`)
329
329
  return
330
330
  }
331
+ current++
331
332
  results.push(result)
332
- if (!err && ++current < tasks.length) callTask(current)
333
+ if (!err && current < tasks.length) callTask(current)
333
334
  else done(err)
334
335
  }
335
336
  function done(err) {
@@ -345,7 +346,7 @@ module.exports = {
345
346
  const next2 = next.bind(null, i)
346
347
  const res = tasks[i](next2)
347
348
  if (res instanceof Promise) {
348
- res.then((result) => next2(null, result)).catch(next2)
349
+ res.then((result) => next2(null, result)).catch((e) => next2(e))
349
350
  }
350
351
  }
351
352
 
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.6",
5
+ "version": "3.0.7",
6
6
  "license": "MIT",
7
7
  "repository": "github:boycce/monastery",
8
8
  "homepage": "https://boycce.github.io/monastery/",
package/test/crud.js CHANGED
@@ -902,6 +902,7 @@ test('hooks > async and next conflict', async () => {
902
902
  fields: { age: { type: 'number'} },
903
903
  afterFind: [
904
904
  async (data, next) => {
905
+ data.age = data.age + 1
905
906
  next() // should console an error for empty promise
906
907
  },
907
908
  async (data, next) => {
@@ -909,7 +910,7 @@ test('hooks > async and next conflict', async () => {
909
910
  },
910
911
  ],
911
912
  })
912
- let user4 = db.model('user3', {
913
+ let user4 = db.model('user4', {
913
914
  fields: { age: { type: 'number'} },
914
915
  afterFind: [
915
916
  async (data, next) => {
@@ -926,10 +927,27 @@ test('hooks > async and next conflict', async () => {
926
927
  },
927
928
  ],
928
929
  })
930
+
931
+ let user5 = db.model('user5', {
932
+ fields: { age: { type: 'number'} },
933
+ afterFind: [
934
+ async (data, next) => {
935
+ const promise = Promise.reject(new Error('An async error occurred with Martin3'))
936
+ next(new Error('An async error occurred with Martin3'))
937
+ return promise
938
+ },
939
+ async (data, next) => {
940
+ data.age = data.age + 1 // shouldn't be reached
941
+ },
942
+ ],
943
+ })
944
+
945
+
929
946
  let user1Doc = await user1.insert({ data: { age: 0 } })
930
947
  let user2Doc = await user2.insert({ data: { age: 0 } })
931
948
  let user3Doc = await user3.insert({ data: { age: 0 } })
932
949
  let user4Doc = await user4.insert({ data: { age: 0 } })
950
+ let user5Doc = await user5.insert({ data: { age: 0 } })
933
951
 
934
952
  const logSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
935
953
 
@@ -946,4 +964,7 @@ test('hooks > async and next conflict', async () => {
946
964
  await expect(user4.find({ query: user4Doc._id })).resolves.toEqual({ _id: expect.any(Object), age: 2 })
947
965
  expect(logSpy).toHaveBeenCalledWith('Monastery afterFind error: you cannot return a promise AND call next()')
948
966
 
967
+ await expect(user5.find({ query: user5Doc._id })).rejects.toThrow('An async error occurred with Martin3')
968
+ expect(logSpy).toHaveBeenCalledWith('Monastery afterFind error: you cannot return a promise AND call next()')
969
+
949
970
  })