monastery 3.2.0 → 3.2.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 +2 -0
- package/docs/model/update.md +11 -1
- package/lib/model-validate.js +7 -3
- package/package.json +1 -1
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.2.1](https://github.com/boycce/monastery/compare/3.2.0...3.2.1) (2024-08-05)
|
|
6
|
+
|
|
5
7
|
## [3.2.0](https://github.com/boycce/monastery/compare/3.1.0...3.2.0) (2024-07-17)
|
|
6
8
|
|
|
7
9
|
### [3.1.1](https://github.com/boycce/monastery/compare/3.1.0...3.1.1) (2024-05-27)
|
package/docs/model/update.md
CHANGED
|
@@ -22,7 +22,17 @@ Update document(s) in a collection and calls model hooks: `beforeUpdate`, `afte
|
|
|
22
22
|
|
|
23
23
|
### Returns
|
|
24
24
|
|
|
25
|
-
A promise
|
|
25
|
+
`{Promise<Object>}` A promise that resolves to an object with the updated fields.
|
|
26
|
+
|
|
27
|
+
You can also access the native MongoDB output via `result._output`, a prototype property:
|
|
28
|
+
```js
|
|
29
|
+
{
|
|
30
|
+
acknowledged: true,
|
|
31
|
+
modifiedCount: 1,
|
|
32
|
+
matchedCount: 1,
|
|
33
|
+
...
|
|
34
|
+
}
|
|
35
|
+
```
|
|
26
36
|
|
|
27
37
|
### Example
|
|
28
38
|
|
package/lib/model-validate.js
CHANGED
|
@@ -140,6 +140,7 @@ Model.prototype._validateFields = function (dataRoot, fields, data, opts, parent
|
|
|
140
140
|
// Field is a subdocument
|
|
141
141
|
if (schema.isObject) {
|
|
142
142
|
// Object schema errors
|
|
143
|
+
let res
|
|
143
144
|
const verrors = this._validateRules(dataRoot, schema, value, opts, path)
|
|
144
145
|
if (verrors.length) errors.push(...verrors)
|
|
145
146
|
// Recurse if inserting, value is a subdocument, or a deep property (todo: not dot-notation)
|
|
@@ -148,21 +149,22 @@ Model.prototype._validateFields = function (dataRoot, fields, data, opts, parent
|
|
|
148
149
|
util.isObject(value) ||
|
|
149
150
|
(util.isDefined(opts.validateUndefined) ? opts.validateUndefined : (path||'').indexOf('.') !== -1)
|
|
150
151
|
) {
|
|
151
|
-
|
|
152
|
+
res = this._validateFields(dataRoot, field, value, opts, path, path2)
|
|
152
153
|
if (res[0].length) errors.push(...res[0])
|
|
153
154
|
}
|
|
154
155
|
if (util.isDefined(value) && !verrors.length) {
|
|
155
|
-
data2[indexOrFieldName] = res? res[1] : value
|
|
156
|
+
data2[indexOrFieldName] = res ? res[1] : value
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
// Field is an array
|
|
159
160
|
} else if (schema.isArray) {
|
|
160
161
|
// Array schema errors
|
|
162
|
+
let res2
|
|
161
163
|
const verrors = this._validateRules(dataRoot, schema, value, opts, path)
|
|
162
164
|
if (verrors.length) errors.push(...verrors)
|
|
163
165
|
// Data value is array too
|
|
164
166
|
if (util.isArray(value)) {
|
|
165
|
-
|
|
167
|
+
res2 = this._validateFields(dataRoot, field, value, opts, path, path2)
|
|
166
168
|
if (res2[0].length) errors.push(...res2[0])
|
|
167
169
|
}
|
|
168
170
|
if (util.isDefined(value) && !verrors.length) {
|
|
@@ -209,6 +211,8 @@ Model.prototype._validateRules = function (dataRoot, fieldSchema, value, opts, p
|
|
|
209
211
|
if (opts.skipValidation === true) return []
|
|
210
212
|
|
|
211
213
|
// Skip validation for a field, takes in to account if a parent has been skipped.
|
|
214
|
+
// Todo: Maybe we can use model-crud:blacklisted logic? But just allow it to skip all [0-9] paths via '$'
|
|
215
|
+
// if (!parentPath && fieldName == 'categories') console.timeEnd(i + ' - ' + m + ' - ' + fieldName + ' - 1')/////
|
|
212
216
|
if (opts.skipValidation.length) {
|
|
213
217
|
//console.log(path, field, opts)
|
|
214
218
|
let pathChunks = path.split('.')
|
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.2.
|
|
5
|
+
"version": "3.2.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|