monastery 3.0.0 → 3.0.1
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/docs/model/{...rawMethods.md → rawMethods.md} +33 -32
- package/docs/readme.md +11 -23
- package/package.json +2 -1
- package/plugins/images/index.js +15 -4
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
|
+
### [3.0.1](https://github.com/boycce/monastery/compare/3.0.0...3.0.1) (2024-04-28)
|
|
6
|
+
|
|
5
7
|
## [3.0.0](https://github.com/boycce/monastery/compare/2.2.2...3.0.0) (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)
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: ...
|
|
2
|
+
title: ...collection methods
|
|
3
3
|
parent: Model
|
|
4
|
+
nav_order: 9
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
#
|
|
7
|
+
# Collection Methods
|
|
7
8
|
|
|
8
9
|
These MongoDB collection methods are made available if you need to test or run any method without hooks or Monastery argument/return processing.
|
|
9
10
|
|
|
10
|
-
These methods can be accessed via
|
|
11
|
+
These methods can be accessed via `model._*`.
|
|
11
12
|
|
|
12
13
|
## Returns
|
|
13
14
|
|
|
@@ -15,25 +16,25 @@ All methods return a promise.
|
|
|
15
16
|
|
|
16
17
|
## Methods
|
|
17
18
|
|
|
18
|
-
* model.[_aggregate](#
|
|
19
|
-
* model.[_bulkWrite](#
|
|
20
|
-
* model.[_count](#
|
|
21
|
-
* model.[_createIndex](#
|
|
22
|
-
* model.[_createIndexes](#
|
|
23
|
-
* model.[_distinct](#
|
|
24
|
-
* model.[_drop](#
|
|
25
|
-
* model.[_dropIndex](#
|
|
26
|
-
* model.[_dropIndexes](#
|
|
27
|
-
* model.[_find](#
|
|
28
|
-
* model.[_findOne](#
|
|
29
|
-
* model.[_findOneAndDelete](#
|
|
30
|
-
* model.[_findOneAndUpdate](#
|
|
31
|
-
* model.[_indexes](#
|
|
32
|
-
* model.[_indexInformation](#
|
|
33
|
-
* model.[_insert](#
|
|
34
|
-
* model.[_remove](#
|
|
35
|
-
* model.[_stats](#
|
|
36
|
-
* model.[_update](#
|
|
19
|
+
* model.[_aggregate](#model_aggregate)
|
|
20
|
+
* model.[_bulkWrite](#model_bulkwrite)
|
|
21
|
+
* model.[_count](#model_count)
|
|
22
|
+
* model.[_createIndex](#model_createindex)
|
|
23
|
+
* model.[_createIndexes](#model_createindexes)
|
|
24
|
+
* model.[_distinct](#model_distinct)
|
|
25
|
+
* model.[_drop](#model_drop)
|
|
26
|
+
* model.[_dropIndex](#model_dropindex)
|
|
27
|
+
* model.[_dropIndexes](#model_dropindexes)
|
|
28
|
+
* model.[_find](#model_find)
|
|
29
|
+
* model.[_findOne](#model_findone)
|
|
30
|
+
* model.[_findOneAndDelete](#model_findoneanddelete)
|
|
31
|
+
* model.[_findOneAndUpdate](#model_findoneandupdate)
|
|
32
|
+
* model.[_indexes](#model_indexes)
|
|
33
|
+
* model.[_indexInformation](#model_indexinformation)
|
|
34
|
+
* model.[_insert](#model_insert)
|
|
35
|
+
* model.[_remove](#model_remove)
|
|
36
|
+
* model.[_stats](#model_stats)
|
|
37
|
+
* model.[_update](#model_update)
|
|
37
38
|
|
|
38
39
|
### [`model._aggregate`](https://mongodb.github.io/node-mongodb-native/5.9/classes/Collection.html#aggregate)
|
|
39
40
|
|
|
@@ -74,7 +75,7 @@ All methods return a promise.
|
|
|
74
75
|
|
|
75
76
|
Returns the count of documents that would match a find() query. The method uses collection.countDocuments() in the mongo driver. Arguments:
|
|
76
77
|
|
|
77
|
-
1. `[Filter]` *(string
|
|
78
|
+
1. `[Filter]` *(string\|objectId\|object)*
|
|
78
79
|
2. `[Options]` *(object)*
|
|
79
80
|
|
|
80
81
|
```js
|
|
@@ -93,7 +94,7 @@ All methods return a promise.
|
|
|
93
94
|
|
|
94
95
|
Creates an index on the db and collection collection. Arguments:
|
|
95
96
|
|
|
96
|
-
1. `IndexSpec` *(string
|
|
97
|
+
1. `IndexSpec` *(string\|array\|object)* - The field name or index specification to create an index for
|
|
97
98
|
2. `[Options]` *(object)*
|
|
98
99
|
|
|
99
100
|
```js
|
|
@@ -133,7 +134,7 @@ All methods return a promise.
|
|
|
133
134
|
Returns a list of distinct values for the given key across a collection. Arguments:
|
|
134
135
|
|
|
135
136
|
1. `Key` *(string)*
|
|
136
|
-
2. `[Filter]` *(string
|
|
137
|
+
2. `[Filter]` *(string\|objectId\|object)*
|
|
137
138
|
3. `[Options]` *(object)*
|
|
138
139
|
|
|
139
140
|
```js
|
|
@@ -172,7 +173,7 @@ All methods return a promise.
|
|
|
172
173
|
|
|
173
174
|
Finds documents in the collection. Arguments:
|
|
174
175
|
|
|
175
|
-
1. `[Filter]` *(string
|
|
176
|
+
1. `[Filter]` *(string\|objectId\|object)*
|
|
176
177
|
2. `[Options]` *(object)*
|
|
177
178
|
|
|
178
179
|
```js
|
|
@@ -192,7 +193,7 @@ All methods return a promise.
|
|
|
192
193
|
|
|
193
194
|
Fetches the first document that matches the filter. Arguments:
|
|
194
195
|
|
|
195
|
-
1. `[Filter]` *(string
|
|
196
|
+
1. `[Filter]` *(string\|objectId\|object)*
|
|
196
197
|
2. `[Options]` *(object)*
|
|
197
198
|
|
|
198
199
|
```js
|
|
@@ -204,7 +205,7 @@ All methods return a promise.
|
|
|
204
205
|
|
|
205
206
|
Find a document and delete it in one atomic operation. Requires a write lock for the duration of the operation. Arguments:
|
|
206
207
|
|
|
207
|
-
1. `[Filter]` *(string
|
|
208
|
+
1. `[Filter]` *(string\|objectId\|object)*
|
|
208
209
|
2. `[Options]` *(object)*
|
|
209
210
|
|
|
210
211
|
```js
|
|
@@ -215,7 +216,7 @@ All methods return a promise.
|
|
|
215
216
|
|
|
216
217
|
Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation. Arguments:
|
|
217
218
|
|
|
218
|
-
1. `Filter` *(string
|
|
219
|
+
1. `Filter` *(string\|objectId\|object)*
|
|
219
220
|
2. `Update` *(object)*
|
|
220
221
|
3. `[Options]` *(object)*
|
|
221
222
|
|
|
@@ -247,7 +248,7 @@ All methods return a promise.
|
|
|
247
248
|
|
|
248
249
|
Inserts one or more documents into the collection. Arguments:
|
|
249
250
|
|
|
250
|
-
1. `Doc` *(object
|
|
251
|
+
1. `Doc` *(object\|array)* - one or many documents
|
|
251
252
|
2. `[Options]` *(object)*
|
|
252
253
|
|
|
253
254
|
```js
|
|
@@ -259,7 +260,7 @@ All methods return a promise.
|
|
|
259
260
|
|
|
260
261
|
Removes one or more document(s) from the collection. Arguments:
|
|
261
262
|
|
|
262
|
-
1. `Filter` *(string
|
|
263
|
+
1. `Filter` *(string\|objectId\|object)*
|
|
263
264
|
2. `[Options]` *(object)*
|
|
264
265
|
|
|
265
266
|
```js
|
|
@@ -280,7 +281,7 @@ All methods return a promise.
|
|
|
280
281
|
|
|
281
282
|
Updates one or more document(s) from the collection. Arguments:
|
|
282
283
|
|
|
283
|
-
1. `Filter` *(string
|
|
284
|
+
1. `Filter` *(string\|objectId\|object)*
|
|
284
285
|
1. `Update` *(object)*
|
|
285
286
|
2. `[Options]` *(object)*
|
|
286
287
|
|
package/docs/readme.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/monastery) [](https://app.travis-ci.com/github/boycce/monastery)
|
|
4
4
|
|
|
5
|
-
> [
|
|
6
|
-
> v3.0 has been released 🎉 refer to [breaking changes](#v3.0BreakingChanges) below when upgrading from v2.x.
|
|
5
|
+
> v3.0 has been released 🎉 refer to [breaking changes](#v3-breaking-changes) below when upgrading from v2.x.
|
|
7
6
|
|
|
8
7
|
## Features
|
|
9
8
|
|
|
@@ -13,7 +12,7 @@
|
|
|
13
12
|
* Normalized error responses objects ready for client consumption
|
|
14
13
|
* Custom error messages can be defined in your model definitions
|
|
15
14
|
* Blacklist sensitive fields once in your model definition, or per operation
|
|
16
|
-
* Model methods can accept bracket (multipart/form
|
|
15
|
+
* Model methods can accept data in bracket (multipart/form) and dot notation, you can also mix these together
|
|
17
16
|
* Automatic Mongo index creation
|
|
18
17
|
|
|
19
18
|
#### Why Monastery over Mongoose?
|
|
@@ -22,7 +21,7 @@
|
|
|
22
21
|
* Model schema and configurations are all defined within a single object (model definition)
|
|
23
22
|
* You can blacklist/exclude sensitive model fields in the model definition for each CRUD operation
|
|
24
23
|
* Model population uses a single aggregation call instead of multiple queries for faster responses
|
|
25
|
-
* Errors throw normalized error objects that contain the model
|
|
24
|
+
* Errors throw normalized error objects that contain the model, field, error message etc, handy in the client
|
|
26
25
|
|
|
27
26
|
## Install
|
|
28
27
|
|
|
@@ -83,16 +82,14 @@ You can view MongoDB's [compatibility table here](https://www.mongodb.com/docs/d
|
|
|
83
82
|
| `2.x` | [`3.7.x`](https://mongodb.github.io/node-mongodb-native/3.7/api/) | `>=2.6 <=6.x` | `>=4.x <=14.x` |
|
|
84
83
|
|
|
85
84
|
|
|
86
|
-
## v3
|
|
85
|
+
## v3 Breaking Changes
|
|
87
86
|
|
|
88
87
|
- Removed callback functions on all model methods, you can use the returned promise instead
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
- MongoDB connection can be found here `db.db` changed from `db._db`
|
|
95
|
-
- `model._indexes()` now returns `collection._indexes()` not `collection._indexInformation()`
|
|
88
|
+
- model.update() now returns the following _update property: `{ acknowledged: true, matchedCount: 1, modifiedCount: 1, upsertedCount: 0, upsertedId: null }` instead of `{ n: 1, nModified: 1, ok: 1 }`
|
|
89
|
+
- model.remove() now returns `{ acknowledged: true, deletedCount: 1 }`, instead of `{ results: {n:1, ok:1} }`
|
|
90
|
+
- Models are now added to db.models instead of db.model, e.g. db.models.user
|
|
91
|
+
- MongoDB connection can be found here db.db changed from db._db
|
|
92
|
+
- model._indexes() now returns collection._indexes() not collection._indexInformation()
|
|
96
93
|
|
|
97
94
|
## Roadmap
|
|
98
95
|
|
|
@@ -121,9 +118,9 @@ You can view MongoDB's [compatibility table here](https://www.mongodb.com/docs/d
|
|
|
121
118
|
- timstamps are blacklisted by default (instead of the `timestamps` opt), and can be switched off via blacklisting
|
|
122
119
|
- Allow rules on image types, e.g. `required`
|
|
123
120
|
- Test importing of models
|
|
124
|
-
- Docs: model.methods
|
|
121
|
+
- ~~Docs: model.methods~~
|
|
125
122
|
- ~~Convert hooks to promises~~
|
|
126
|
-
- ~~added `model.count()
|
|
123
|
+
- ~~added `model.count()`~~
|
|
127
124
|
|
|
128
125
|
## Debugging
|
|
129
126
|
|
|
@@ -148,12 +145,3 @@ npm run dev -- -t 'Model indexes'
|
|
|
148
145
|
## License
|
|
149
146
|
|
|
150
147
|
Copyright 2024 Ricky Boyce. Code released under the MIT license.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
///////////////////////////////
|
|
158
|
-
/////3. add 'Collection' to monastery docs sidebar ( also add model.count)
|
|
159
|
-
//// docs sapcing.... +4px
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "monastery",
|
|
3
3
|
"description": "⛪ A simple, straightforward MongoDB ODM",
|
|
4
4
|
"author": "Ricky Boyce",
|
|
5
|
-
"version": "3.0.
|
|
5
|
+
"version": "3.0.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@aws-sdk/client-s3": "3.549.0",
|
|
36
|
+
"@aws-sdk/lib-storage": "3.549.0",
|
|
36
37
|
"@aws-sdk/s3-request-presigner": "3.549.0",
|
|
37
38
|
"debug": "4.3.4",
|
|
38
39
|
"file-type": "^16.5.4",
|
package/plugins/images/index.js
CHANGED
|
@@ -174,11 +174,22 @@ let plugin = module.exports = {
|
|
|
174
174
|
plugin._addImageObjectsToData(filesArr.inputPath, data, image)
|
|
175
175
|
resolve(s3Options)
|
|
176
176
|
} else {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
plugin.
|
|
180
|
-
|
|
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
|
}))
|