monastery 1.42.1 → 1.42.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 +2 -0
- package/docs/readme.md +1 -0
- package/lib/index.js +2 -2
- package/lib/model-crud.js +0 -4
- package/lib/model-validate.js +0 -6
- package/package.json +1 -1
- package/test/model.js +18 -0
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
|
+
### [1.42.2](https://github.com/boycce/monastery/compare/1.42.1...1.42.2) (2023-10-31)
|
|
6
|
+
|
|
5
7
|
### [1.42.1](https://github.com/boycce/monastery/compare/1.42.0...1.42.1) (2023-10-09)
|
|
6
8
|
|
|
7
9
|
## [1.42.0](https://github.com/boycce/monastery/compare/1.41.2...1.42.0) (2023-10-09)
|
package/docs/readme.md
CHANGED
|
@@ -104,6 +104,7 @@ Coming soon...
|
|
|
104
104
|
- Add a warning if an invalid model is referenced in jthe schema
|
|
105
105
|
- Remove leading forward slashes from custom image paths (AWS adds this as a seperate folder)
|
|
106
106
|
- double check await db.model.remove({ query: idfromparam }) doesnt cause issues for null, undefined or '', but continue to allow {}
|
|
107
|
+
- ~~can't insert/update model id (maybe we can allow this and add _id to default insert/update blacklists)~~
|
|
107
108
|
|
|
108
109
|
## Versions
|
|
109
110
|
|
package/lib/index.js
CHANGED
|
@@ -98,10 +98,10 @@ let models = async function(pathname, waitForIndexes) {
|
|
|
98
98
|
let name = filename.replace('.js', '')
|
|
99
99
|
let filepath = path.join(pathname, filename)
|
|
100
100
|
// We can't use require() here since we need to be able to import both CJS and ES6 modules
|
|
101
|
-
let definition = (await import(filepath))
|
|
101
|
+
let definition = ((await import(filepath))||{}).default
|
|
102
102
|
// When a commonJS project uses babel (e.g. `nodemon -r @babel/register`, similar to `-r esm`), import()
|
|
103
103
|
// will return ES6 model definitions in another nested `default` object
|
|
104
|
-
if (definition
|
|
104
|
+
if (definition && definition.default) definition = definition.default
|
|
105
105
|
if (!definition) throw new Error(`The model definition for '${name}' must export a default object`)
|
|
106
106
|
// Wait for indexes to be created?
|
|
107
107
|
if (waitForIndexes) out[name] = await this.model(name, { ...definition, waitForIndexes })
|
package/lib/model-crud.js
CHANGED
|
@@ -25,13 +25,9 @@ module.exports = {
|
|
|
25
25
|
try {
|
|
26
26
|
opts = await this._queryObject(opts, 'insert')
|
|
27
27
|
|
|
28
|
-
// console.log(11, opts.data )
|
|
29
|
-
|
|
30
28
|
// Validate
|
|
31
29
|
let data = await this.validate(opts.data || {}, opts) // was { ...opts }
|
|
32
30
|
|
|
33
|
-
// console.log(22, data)
|
|
34
|
-
|
|
35
31
|
// Insert
|
|
36
32
|
await util.runSeries(this.beforeInsert.map(f => f.bind(opts, data)))
|
|
37
33
|
let response = await this._insert(data, util.omit(opts, this._queryOptions))
|
package/lib/model-validate.js
CHANGED
|
@@ -108,8 +108,6 @@ module.exports = {
|
|
|
108
108
|
let data2 = util.isArray(fields)? [] : {}
|
|
109
109
|
let timestamps = util.isDefined(opts.timestamps)? opts.timestamps : this.manager.timestamps
|
|
110
110
|
|
|
111
|
-
// console.log(8888, fields)
|
|
112
|
-
|
|
113
111
|
util.forEach(util.forceArray(data), function(data, i) {
|
|
114
112
|
util.forEach(fields, function(field, fieldName) {
|
|
115
113
|
let verrors = []
|
|
@@ -133,11 +131,8 @@ module.exports = {
|
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
// console.log(333,path3)
|
|
137
|
-
|
|
138
134
|
// Ignore blacklisted
|
|
139
135
|
if (this._pathBlacklisted(path3, opts.projectionValidate) && !schema.defaultOverride) return
|
|
140
|
-
// console.log(444,path3)
|
|
141
136
|
// Ignore insert only
|
|
142
137
|
if (opts.update && schema.insertOnly) return
|
|
143
138
|
// Ignore virtual fields
|
|
@@ -146,7 +141,6 @@ module.exports = {
|
|
|
146
141
|
if (isTypeRule && util.isFunction(isTypeRule.tryParse)) {
|
|
147
142
|
value = isTypeRule.tryParse.call(dataRoot, value, fieldName, this)
|
|
148
143
|
}
|
|
149
|
-
// console.log(555,path3)
|
|
150
144
|
|
|
151
145
|
// Schema field (ignore object/array schemas)
|
|
152
146
|
if (util.isSchema(field) && fieldName !== 'schema') {
|
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.42.
|
|
5
|
+
"version": "1.42.2",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/test/model.js
CHANGED
|
@@ -462,6 +462,24 @@ module.exports = function(monastery, opendb) {
|
|
|
462
462
|
type: 'Point'
|
|
463
463
|
},
|
|
464
464
|
})
|
|
465
|
+
// Insert no 2dsphere point data
|
|
466
|
+
await expect(db.user3.insert({
|
|
467
|
+
data: {}
|
|
468
|
+
})).resolves.toEqual({
|
|
469
|
+
_id: expect.any(Object),
|
|
470
|
+
})
|
|
471
|
+
// Insert bad 2dsphere point data
|
|
472
|
+
let MongoError = require('mongodb').MongoError
|
|
473
|
+
let id = db.id()
|
|
474
|
+
await expect(db.user3.insert({
|
|
475
|
+
data: { _id: id, location: {} },
|
|
476
|
+
blacklist: ['-_id'],
|
|
477
|
+
})).rejects.toEqual(
|
|
478
|
+
new MongoError(
|
|
479
|
+
`Can't extract geo keys: { _id: ObjectId('${String(id)}'), location: { type: "Point" } }` +
|
|
480
|
+
' Point must be an array or object'
|
|
481
|
+
)
|
|
482
|
+
)
|
|
465
483
|
|
|
466
484
|
db.close()
|
|
467
485
|
})
|