monastery 1.42.1 → 1.42.3

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
@@ -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.42.3](https://github.com/boycce/monastery/compare/1.42.2...1.42.3) (2024-04-30)
6
+
7
+ ### [1.42.2](https://github.com/boycce/monastery/compare/1.42.1...1.42.2) (2023-10-31)
8
+
5
9
  ### [1.42.1](https://github.com/boycce/monastery/compare/1.42.0...1.42.1) (2023-10-09)
6
10
 
7
11
  ## [1.42.0](https://github.com/boycce/monastery/compare/1.41.2...1.42.0) (2023-10-09)
File without changes
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
@@ -80,10 +80,12 @@ let arrayWithSchema = function(array, schema) {
80
80
  return array
81
81
  }
82
82
 
83
- let models = async function(pathname, waitForIndexes) {
83
+ let models = async function(pathname, waitForIndexes, commonJs) {
84
84
  /**
85
85
  * Setup model definitions from a folder location
86
86
  * @param {string} pathname
87
+ * @param {boolean} waitForIndexes - Wait for indexes to be created?
88
+ * @param {boolean} commonJs - Use commonJs require() instead of ES6 import()
87
89
  * @return {Promise(object)} - e.g. { user: , article: , .. }
88
90
  * @this Manager
89
91
  */
@@ -97,12 +99,17 @@ let models = async function(pathname, waitForIndexes) {
97
99
  if (!filename.match(/\.[cm]?js$/)) continue
98
100
  let name = filename.replace('.js', '')
99
101
  let filepath = path.join(pathname, filename)
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))?.default
102
- // When a commonJS project uses babel (e.g. `nodemon -r @babel/register`, similar to `-r esm`), import()
103
- // will return ES6 model definitions in another nested `default` object
104
- if (definition?.default) definition = definition.default
105
- if (!definition) throw new Error(`The model definition for '${name}' must export a default object`)
102
+ let definition
103
+ if (commonJs) {
104
+ definition = require(require('path').join(path, filename)).default
105
+ } else {
106
+ // We can't use require() here since we need to be able to import both CJS and ES6 modules
107
+ definition = ((await import(filepath))||{}).default
108
+ // When a commonJS project uses babel (e.g. `nodemon -r @babel/register`, similar to `-r esm`), import()
109
+ // will return ES6 model definitions in another nested `default` object
110
+ if (definition && definition.default) definition = definition.default
111
+ if (!definition) throw new Error(`The model definition for '${name}' must export a default object`)
112
+ }
106
113
  // Wait for indexes to be created?
107
114
  if (waitForIndexes) out[name] = await this.model(name, { ...definition, waitForIndexes })
108
115
  else out[name] = this.model(name, definition)
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))
@@ -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.1",
5
+ "version": "1.42.3",
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
  })