monastery 1.42.2 → 1.42.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 +4 -0
- package/docs/assets/imgs/monastery.jpg +0 -0
- package/lib/index.js +21 -7
- package/package.json +1 -1
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.4](https://github.com/boycce/monastery/compare/1.42.3...1.42.4) (2024-04-30)
|
|
6
|
+
|
|
7
|
+
### [1.42.3](https://github.com/boycce/monastery/compare/1.42.2...1.42.3) (2024-04-30)
|
|
8
|
+
|
|
5
9
|
### [1.42.2](https://github.com/boycce/monastery/compare/1.42.1...1.42.2) (2023-10-31)
|
|
6
10
|
|
|
7
11
|
### [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,14 +80,23 @@ let arrayWithSchema = function(array, schema) {
|
|
|
80
80
|
return array
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
let models = async function(pathname,
|
|
83
|
+
let models = async function(pathname, opts) {
|
|
84
84
|
/**
|
|
85
85
|
* Setup model definitions from a folder location
|
|
86
86
|
* @param {string} pathname
|
|
87
|
+
* @param {object} opts:
|
|
88
|
+
* @param {boolean} opts.waitForIndexes - Wait for indexes to be created?
|
|
89
|
+
* @param {boolean} opts.commonJs - Use commonJs require() instead of ES6 import()
|
|
87
90
|
* @return {Promise(object)} - e.g. { user: , article: , .. }
|
|
88
91
|
* @this Manager
|
|
89
92
|
*/
|
|
90
93
|
let out = {}
|
|
94
|
+
opts = true
|
|
95
|
+
if (opts === true) {
|
|
96
|
+
opts = { waitForIndexes: true } // legacy support
|
|
97
|
+
console.warn('Depreciating: please use `{ waitForIndexes: true }` instead of `true` in db.models(pathname, `true`)')
|
|
98
|
+
}
|
|
99
|
+
let { waitForIndexes, commonJs } = opts || {}
|
|
91
100
|
if (!pathname || typeof pathname !== 'string') {
|
|
92
101
|
throw 'The path must be a valid pathname'
|
|
93
102
|
}
|
|
@@ -97,12 +106,17 @@ let models = async function(pathname, waitForIndexes) {
|
|
|
97
106
|
if (!filename.match(/\.[cm]?js$/)) continue
|
|
98
107
|
let name = filename.replace('.js', '')
|
|
99
108
|
let filepath = path.join(pathname, filename)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
let definition
|
|
110
|
+
if (commonJs) {
|
|
111
|
+
definition = require(filepath).default
|
|
112
|
+
} else {
|
|
113
|
+
// We can't use require() here since we need to be able to import both CJS and ES6 modules
|
|
114
|
+
definition = ((await import(filepath))||{}).default
|
|
115
|
+
// When a commonJS project uses babel (e.g. `nodemon -r @babel/register`, similar to `-r esm`), import()
|
|
116
|
+
// will return ES6 model definitions in another nested `default` object
|
|
117
|
+
if (definition && definition.default) definition = definition.default
|
|
118
|
+
if (!definition) throw new Error(`The model definition for '${name}' must export a default object`)
|
|
119
|
+
}
|
|
106
120
|
// Wait for indexes to be created?
|
|
107
121
|
if (waitForIndexes) out[name] = await this.model(name, { ...definition, waitForIndexes })
|
|
108
122
|
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.
|
|
5
|
+
"version": "1.42.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|