cosa 6.3.0 → 6.4.0

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/lib/model.js CHANGED
@@ -1,4 +1,4 @@
1
- const joi = require('@hapi/joi');
1
+ const joi = require('joi');
2
2
  const etag = require('etag');
3
3
  const debug = require('debug')('cosa:model');
4
4
  const objectPath = require('object-path');
@@ -7,7 +7,7 @@ const { EJSON } = require('bson');
7
7
  const Cursor = require('./cursor');
8
8
  const errors = require('./errors');
9
9
  const { ObjectId } = require('bson');
10
- const { pathEq, complement, pick, omit } = require('omnibelt');
10
+ const { pathEq, complement, pick, omit, has } = require('omnibelt');
11
11
  const { buildPropertySchema } = require('./utils');
12
12
  const Immutable = require('./immutable');
13
13
  Immutable.use(require('./defined-object'));
@@ -23,6 +23,16 @@ const db = require('./db');
23
23
  // functions that are defined later on.
24
24
  let _serialize, _extend;
25
25
 
26
+ const shouldWait = (waitType) => {
27
+ return (options, definition) => {
28
+ if (has(waitType, options)) { return options[waitType]; }
29
+ return definition[waitType];
30
+ };
31
+ };
32
+
33
+ const shouldWaitAfterSave = shouldWait('waitAfterSave');
34
+ const shouldWaitAfterRemove = shouldWait('waitAfterRemove');
35
+
26
36
  const addVirtuals = (def, obj) => {
27
37
  if (def.type === 'array' && def.items && Array.isArray(obj)) {
28
38
  for (let i = 0, l = obj.length; i < l; i++) {
@@ -177,7 +187,7 @@ const _create = (data, definition) => {
177
187
  if ('function' === typeof newOrUpdatedModel.afterSaveCommit) {
178
188
  chain = chain.then(() => newOrUpdatedModel.afterSaveCommit(original, options));
179
189
  }
180
- if (options.waitAfterSave) {
190
+ if (shouldWaitAfterSave(options, definition)) {
181
191
  await chain;
182
192
  }
183
193
  }
@@ -333,7 +343,7 @@ const _create = (data, definition) => {
333
343
  if ('function' === typeof this.afterRemoveCommit) {
334
344
  chain = chain.then(() => this.afterRemoveCommit(options));
335
345
  }
336
- if (options.waitAfterRemove) {
346
+ if (shouldWaitAfterRemove(options, definition)) {
337
347
  await chain;
338
348
  }
339
349
  }
package/lib/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- const joi = require('@hapi/joi');
1
+ const joi = require('joi');
2
2
  const { ObjectId } = require('bson');
3
3
  const buildPropertySchema = (name, propertyDef) => { // eslint-disable-line complexity
4
4
  let schema = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosa",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "Cosa Models for MongoDB",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -40,20 +40,20 @@
40
40
  "debug": "^4.3.4",
41
41
  "error": "^7.0.2",
42
42
  "etag": "^1.8.1",
43
- "@hapi/joi": "^17.1.1",
44
- "mongodb": "~4.10.0",
43
+ "joi": "^17.6.4",
44
+ "mongodb": "~4.11.0",
45
45
  "object-path": "^0.11.8",
46
46
  "omnibelt": "^2.1.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@losant/eslint-config-losant": "^1.4.4",
50
- "husky": "^8.0.1",
49
+ "@losant/eslint-config-losant": "^1.5.0",
50
+ "husky": "^8.0.2",
51
51
  "lint-staged": "^13.0.3",
52
- "chai": "^4.3.6",
52
+ "chai": "^4.3.7",
53
53
  "chai-as-promised": "^7.1.1",
54
54
  "chai-datetime": "^1.8.0",
55
55
  "documentation": "^14.0.0",
56
- "mocha": "^10.0.0",
56
+ "mocha": "^10.1.0",
57
57
  "string-template": "^1.0.0"
58
58
  },
59
59
  "eslintConfig": {