monastery 1.37.0 → 1.37.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/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
+ ### [1.37.1](https://github.com/boycce/monastery/compare/1.37.0...1.37.1) (2022-06-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add _id to upserted document ([a78512f](https://github.com/boycce/monastery/commit/a78512f16b39422160756fe91ef4d4a3239f5890))
11
+
5
12
  ## [1.37.0](https://github.com/boycce/monastery/compare/1.36.3...1.37.0) (2022-06-12)
6
13
 
7
14
 
package/lib/model-crud.js CHANGED
@@ -255,7 +255,11 @@ module.exports = {
255
255
  // Update
256
256
  let update = await this['_' + type](opts.query, operators, util.omit(opts, this._queryOptions))
257
257
  if (type == 'findOneAndUpdate') response = update
258
- else if (update.n) response = Object.assign(Object.create({ _output: update }), operators['$set']||{})
258
+ else if (update.n) response = Object.assign(
259
+ Object.create({ _output: update }),
260
+ operators['$set'] || {},
261
+ (update.upserted||[])[0] ? { _id: update.upserted[0]._id } : {},
262
+ )
259
263
 
260
264
  // Hook: afterUpdate (doesn't have access to validated data)
261
265
  if (response) await util.runSeries(this.afterUpdate.map(f => f.bind(opts, response)))
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "monastery",
3
3
  "description": "⛪ A straight forward MongoDB ODM built around Monk",
4
4
  "author": "Ricky Boyce",
5
- "version": "1.37.0",
5
+ "version": "1.37.1",
6
6
  "license": "MIT",
7
7
  "repository": "github:boycce/monastery",
8
8
  "homepage": "https://boycce.github.io/monastery/",
package/test/crud.js CHANGED
@@ -201,6 +201,15 @@ module.exports = function(monastery, opendb) {
201
201
  name: 'Martin Luther3'
202
202
  }
203
203
  ])
204
+
205
+ // Upsert
206
+ let newId = db.id()
207
+ await expect(user.update({ query: newId, data: { name: 'Martin Luther3' }, upsert: true }))
208
+ .resolves.toEqual({ _id: newId, name: 'Martin Luther3' }) // inserted
209
+
210
+ await expect(user.update({ query: inserted._id, data: { name: 'Martin Luther4' }, upsert: true }))
211
+ .resolves.toEqual({ name: 'Martin Luther4' }) // updated
212
+
204
213
  db.close()
205
214
  })
206
215