monastery 1.40.5 → 1.41.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 +4 -0
- package/docs/definition/index.md +11 -6
- package/docs/model/remove.md +1 -0
- package/lib/model.js +7 -1
- package/lib/util.js +2 -0
- package/package.json +1 -1
- package/test/model.js +46 -0
package/changelog.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
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.41.1](https://github.com/boycce/monastery/compare/1.41.0...1.41.1) (2023-04-17)
|
|
6
|
+
|
|
7
|
+
## [1.41.0](https://github.com/boycce/monastery/compare/1.40.5...1.41.0) (2023-04-16)
|
|
8
|
+
|
|
5
9
|
### [1.40.5](https://github.com/boycce/monastery/compare/1.40.4...1.40.5) (2023-02-22)
|
|
6
10
|
|
|
7
11
|
### [1.40.4](https://github.com/boycce/monastery/compare/1.40.3...1.40.4) (2022-12-21)
|
package/docs/definition/index.md
CHANGED
|
@@ -43,15 +43,20 @@ Model definition object.
|
|
|
43
43
|
pets: [{ // array of embedded documents
|
|
44
44
|
name: { type: 'string' },
|
|
45
45
|
type: { type: 'string' },
|
|
46
|
-
}]
|
|
47
|
-
// You can add a rule on
|
|
48
|
-
|
|
49
|
-
type:
|
|
46
|
+
}],
|
|
47
|
+
// You can add a rule on an embedded-document/array using the following structure
|
|
48
|
+
address: {
|
|
49
|
+
name: { type: 'string' },
|
|
50
|
+
type: { type: 'string' },
|
|
51
|
+
schema: { minLength: 1 },
|
|
52
|
+
},
|
|
53
|
+
pets: db.arrayWithSchema(
|
|
54
|
+
[{
|
|
50
55
|
name: { type: 'string' },
|
|
51
56
|
type: { type: 'string' },
|
|
52
57
|
}],
|
|
53
|
-
minLength: 1,
|
|
54
|
-
|
|
58
|
+
{ minLength: 1 },
|
|
59
|
+
)
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
```
|
package/docs/model/remove.md
CHANGED
|
@@ -13,6 +13,7 @@ Remove document(s) in a collection and calls model hooks: `beforeRemove`, `afte
|
|
|
13
13
|
|
|
14
14
|
- `query` *(object\|id)*: [`MongoDB query document`](https://www.mongodb.com/docs/v4.4/tutorial/query-documents/), or id
|
|
15
15
|
- [`sort`] *(string\|object\|array)*: same as the mongodb option, but allows for string parsing e.g. 'name', 'name:1'
|
|
16
|
+
- [`multi`] *(boolean)*: set to false remove only the first document that match the query criteria
|
|
16
17
|
- [[`any mongodb option`](http://mongodb.github.io/node-mongodb-native/3.2/api/Collection.html#remove)] *(any)*
|
|
17
18
|
|
|
18
19
|
[`callback`] *(function)*: pass instead of return a promise
|
package/lib/model.js
CHANGED
|
@@ -195,7 +195,13 @@ Model.prototype._setupFields = function(fields) {
|
|
|
195
195
|
field.schema.index = index2dsphere
|
|
196
196
|
delete field.index
|
|
197
197
|
}
|
|
198
|
-
field.schema = {
|
|
198
|
+
field.schema = {
|
|
199
|
+
type: 'object',
|
|
200
|
+
isObject: true,
|
|
201
|
+
default: objectDefault,
|
|
202
|
+
nullObject: nullObject,
|
|
203
|
+
...field.schema
|
|
204
|
+
}
|
|
199
205
|
this._setupFields(field)
|
|
200
206
|
}
|
|
201
207
|
}, this)
|
package/lib/util.js
CHANGED
|
@@ -109,6 +109,8 @@ module.exports = {
|
|
|
109
109
|
|
|
110
110
|
isSubdocument: function(value) {
|
|
111
111
|
/**
|
|
112
|
+
* "are all fields objects/arrays?"
|
|
113
|
+
*
|
|
112
114
|
* Is the value a subdocument which contains more fields? Or a just a field definition?
|
|
113
115
|
* @param {object} value - object to check
|
|
114
116
|
* E.g. isSubdocument = {
|
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.
|
|
5
|
+
"version": "1.41.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/test/model.js
CHANGED
|
@@ -115,6 +115,52 @@ module.exports = function(monastery, opendb) {
|
|
|
115
115
|
})
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
+
test('model setup with schema', async () => {
|
|
119
|
+
// Setup
|
|
120
|
+
let db = (await opendb(false)).db
|
|
121
|
+
let objectSchemaTypeRef = { name: { type: 'string', minLength: 5 } }
|
|
122
|
+
let user = db.model('user', {
|
|
123
|
+
fields: {
|
|
124
|
+
pet: { ...objectSchemaTypeRef, schema: { virtual: true }},
|
|
125
|
+
pets: db.arrayWithSchema(
|
|
126
|
+
[objectSchemaTypeRef],
|
|
127
|
+
{ virtual: true },
|
|
128
|
+
),
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
// Object with schema
|
|
132
|
+
expect(user.fields.pet).toEqual({
|
|
133
|
+
name: {
|
|
134
|
+
type: 'string',
|
|
135
|
+
isString: true,
|
|
136
|
+
minLength: 5,
|
|
137
|
+
},
|
|
138
|
+
schema: {
|
|
139
|
+
type: 'object',
|
|
140
|
+
isObject: true,
|
|
141
|
+
virtual: true,
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
// Array with schema
|
|
145
|
+
expect(user.fields.pets[0]).toEqual({
|
|
146
|
+
name: {
|
|
147
|
+
type: 'string',
|
|
148
|
+
isString: true,
|
|
149
|
+
minLength: 5,
|
|
150
|
+
},
|
|
151
|
+
schema: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
isObject: true,
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
expect(user.fields.pets.schema).toEqual({
|
|
157
|
+
type: 'array',
|
|
158
|
+
isArray: true,
|
|
159
|
+
virtual: true,
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
|
|
118
164
|
test('model reserved rules', async () => {
|
|
119
165
|
// Setup
|
|
120
166
|
let db = (await opendb(false, { hideErrors: true })).db // hide debug error
|