@bedrockio/model 0.22.0 → 0.22.2

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
@@ -1,3 +1,11 @@
1
+ ## 0.22.2
2
+
3
+ - Small fixes around upsert reporting.
4
+
5
+ ## 0.22.1
6
+
7
+ - Indicate whether document was created or not in upsert.
8
+
1
9
  ## 0.22.0
2
10
 
3
11
  - Removed regex parsing in search.
@@ -15,9 +15,17 @@ function applyUpsert(schema) {
15
15
  let doc = await this.findOne(query);
16
16
  if (doc) {
17
17
  doc.assign(fields);
18
- await doc.save();
18
+ if (doc.isModified()) {
19
+ await doc.save();
20
+ doc.$locals.updated = true;
21
+ } else {
22
+ doc.$locals.updated = false;
23
+ }
24
+ doc.$locals.created = false;
19
25
  } else {
20
26
  doc = await this.create(fields);
27
+ doc.$locals.created = true;
28
+ doc.$locals.updated = false;
21
29
  }
22
30
  return doc;
23
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/upsert.js CHANGED
@@ -11,9 +11,18 @@ export function applyUpsert(schema) {
11
11
 
12
12
  if (doc) {
13
13
  doc.assign(fields);
14
- await doc.save();
14
+
15
+ if (doc.isModified()) {
16
+ await doc.save();
17
+ doc.$locals.updated = true;
18
+ } else {
19
+ doc.$locals.updated = false;
20
+ }
21
+ doc.$locals.created = false;
15
22
  } else {
16
23
  doc = await this.create(fields);
24
+ doc.$locals.created = true;
25
+ doc.$locals.updated = false;
17
26
  }
18
27
 
19
28
  return doc;
@@ -1 +1 @@
1
- {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/upsert.js"],"names":[],"mappings":"AAAA,+CAgCC"}
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../src/upsert.js"],"names":[],"mappings":"AAAA,+CAyCC"}