monastery 2.2.3 → 2.2.4
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/lib/index.js +14 -7
- 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
|
+
### [2.2.4](https://github.com/boycce/monastery/compare/2.2.3...2.2.4) (2024-04-30)
|
|
6
|
+
|
|
5
7
|
### [2.2.3](https://github.com/boycce/monastery/compare/2.2.2...2.2.3) (2024-04-28)
|
|
6
8
|
|
|
7
9
|
### [2.2.2](https://github.com/boycce/monastery/compare/2.2.1...2.2.2) (2024-04-07)
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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": "2.2.
|
|
5
|
+
"version": "2.2.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|