monastery 1.42.2 → 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,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.3](https://github.com/boycce/monastery/compare/1.42.2...1.42.3) (2024-04-30)
6
+
5
7
  ### [1.42.2](https://github.com/boycce/monastery/compare/1.42.1...1.42.2) (2023-10-31)
6
8
 
7
9
  ### [1.42.1](https://github.com/boycce/monastery/compare/1.42.0...1.42.1) (2023-10-09)
File without changes
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 && 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/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.2",
5
+ "version": "1.42.3",
6
6
  "license": "MIT",
7
7
  "repository": "github:boycce/monastery",
8
8
  "homepage": "https://boycce.github.io/monastery/",