monastery 2.2.2 → 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 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
+ ### [2.2.4](https://github.com/boycce/monastery/compare/2.2.3...2.2.4) (2024-04-30)
6
+
7
+ ### [2.2.3](https://github.com/boycce/monastery/compare/2.2.2...2.2.3) (2024-04-28)
8
+
5
9
  ### [2.2.2](https://github.com/boycce/monastery/compare/2.2.1...2.2.2) (2024-04-07)
6
10
 
7
11
  ### [2.2.1](https://github.com/boycce/monastery/compare/2.2.0...2.2.1) (2024-04-07)
File without changes
package/docs/readme.md CHANGED
@@ -65,6 +65,12 @@ db.user.insert({
65
65
  // }]
66
66
  })
67
67
  ```
68
+ ## Versions
69
+
70
+ - Monk: `v7.3.4`
71
+ - MongoDB NodeJS driver: `v3.7.4` ([MongoDB compatibility](https://www.mongodb.com/docs/drivers/node/current/compatibility/#compatibility))
72
+ - MongoDB: [`v5.0.0`](https://www.mongodb.com/docs/v5.0/reference/) [(`v6.0.0` partial support)](https://www.mongodb.com/docs/v6.0/reference/)
73
+
68
74
  ## Debugging
69
75
 
70
76
  This package uses [debug](https://github.com/visionmedia/debug) which allows you to set different levels of output via the `DEBUG` environment variable. Due to known limations `monastery:warning` and `monastery:error` are forced on, you can however disable these via [manager settings](./manager).
@@ -101,7 +107,7 @@ Coming soon...
101
107
  - Global after/before hooks
102
108
  - before hooks can receive a data array, remove this
103
109
  - docs: Make the implicit ID query conversion more apparent
104
- - Split away from Monk (unless updated)
110
+ - Split away from Monk so we can update the MongoDB NodeJS Driver version
105
111
  - Add a warning if an invalid model is referenced in jthe schema
106
112
  - Remove leading forward slashes from custom image paths (AWS adds this as a seperate folder)
107
113
  - double check await db.model.remove({ query: idfromparam }) doesnt cause issues for null, undefined or '', but continue to allow {}
@@ -111,12 +117,6 @@ Coming soon...
111
117
  - test importing of models
112
118
  - Docs: model.methods
113
119
 
114
- ## Versions
115
-
116
- - Monk: `v7.3.4`
117
- - MongoDB NodeJS driver: `v3.2.3` ([compatibility](https://www.mongodb.com/docs/drivers/node/current/compatibility/#compatibility))
118
- - MongoDB: [`v4.0.0`](https://www.mongodb.com/docs/v4.2/reference/)
119
-
120
120
  ## Special Thanks
121
121
 
122
122
  [Jerome Gravel-Niquet](https://github.com/jeromegn)
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": "2.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/",
@@ -30,11 +30,12 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@aws-sdk/client-s3": "3.549.0",
33
+ "@aws-sdk/lib-storage": "3.549.0",
33
34
  "@aws-sdk/s3-request-presigner": "3.549.0",
34
35
  "debug": "4.3.4",
35
36
  "file-type": "^16.5.4",
36
- "monk": "7.3.4",
37
37
  "mongodb": "^3.2.3",
38
+ "monk": "7.3.4",
38
39
  "nanoid": "3.2.0",
39
40
  "validator": "13.7.0"
40
41
  },
@@ -174,11 +174,22 @@ let plugin = module.exports = {
174
174
  plugin._addImageObjectsToData(filesArr.inputPath, data, image)
175
175
  resolve(s3Options)
176
176
  } else {
177
- plugin.getS3Client().upload(s3Options, (err, response) => {
178
- if (err) return reject(err)
179
- plugin._addImageObjectsToData(filesArr.inputPath, data, image)
180
- resolve(s3Options)
177
+ const { Upload } = require('@aws-sdk/lib-storage')
178
+ const upload = new Upload({
179
+ client: plugin.getS3Client(),
180
+ params: s3Options,
181
181
  })
182
+ // upload.on('httpUploadProgress', (progress) => {
183
+ // console.log(progress)
184
+ // })
185
+ upload.done()
186
+ .then((res) => {
187
+ plugin._addImageObjectsToData(filesArr.inputPath, data, image)
188
+ resolve(s3Options)
189
+ })
190
+ .catch((err) => {
191
+ reject(err)
192
+ })
182
193
  }
183
194
  })
184
195
  }))
package/test/monk.js CHANGED
@@ -37,4 +37,17 @@ module.exports = function(monastery, opendb) {
37
37
  })
38
38
  })
39
39
 
40
+ test('Monk basic operations', async () => {
41
+ let db = monastery('localhost/monastery', { serverSelectionTimeoutMS: 2000 })
42
+ let userCol = db.get('user')
43
+
44
+ // Insert (returns whole document)
45
+ let res1 = await userCol.insert({ woot: 'b' })
46
+ expect(res1).toEqual(expect.objectContaining({ woot: 'b', _id: expect.any(Object) }))
47
+
48
+ // Update (returns whole document)
49
+ let res2 = await userCol.update({ woot: 'b' }, { $set: { woot: 'c' }})
50
+ expect(res2).toEqual(expect.objectContaining({ n: 1, nModified: 1, ok: 1 }))
51
+ })
52
+
40
53
  }