monastery 1.32.0 → 1.32.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 +8 -0
- package/docs/image-plugin.md +1 -1
- package/lib/model-crud.js +1 -1
- package/package.json +1 -1
- package/plugins/images/index.js +18 -11
- package/test/plugin-images.js +16 -18
package/changelog.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.32.1](https://github.com/boycce/monastery/compare/1.32.0...1.32.1) (2022-03-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* processAfterFind bug ([3183b79](https://github.com/boycce/monastery/commit/3183b79fc288665000b63e0221fbe8acf6f482aa))
|
|
11
|
+
|
|
5
12
|
## [1.32.0](https://github.com/boycce/monastery/compare/1.31.7...1.32.0) (2022-02-28)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -22,6 +29,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
22
29
|
|
|
23
30
|
### Bug Fixes
|
|
24
31
|
|
|
32
|
+
* Fixed validateUndefined ([58daed1](https://github.com/boycce/monastery/commit/58daed1ca5317c061a4ddde280bf45b0a134ab30))
|
|
25
33
|
* added partial unqiue index tests ([ff6f193](https://github.com/boycce/monastery/commit/ff6f1938e333407ee17895873d2b42fa5263d7e3))
|
|
26
34
|
* scripts ([bc32680](https://github.com/boycce/monastery/commit/bc326809098ae24686158a0386fbbd6671d86c98))
|
|
27
35
|
|
package/docs/image-plugin.md
CHANGED
|
@@ -30,7 +30,7 @@ let user = db.model('user', { fields: {
|
|
|
30
30
|
formats: ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'tiff'],
|
|
31
31
|
filename: 'avatar',
|
|
32
32
|
filesize: 1000 * 1000 * 5, // max size in bytes
|
|
33
|
-
getSignedUrl: true, // get a s3 signed url
|
|
33
|
+
getSignedUrl: true, // get a s3 signed url after every `find()` operation (can be overridden per request)
|
|
34
34
|
params: {}, // upload params, https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
|
|
35
35
|
},
|
|
36
36
|
logos: [{
|
package/lib/model-crud.js
CHANGED
|
@@ -325,7 +325,7 @@ module.exports = {
|
|
|
325
325
|
return opts
|
|
326
326
|
},
|
|
327
327
|
|
|
328
|
-
_processAfterFind: function(data, projection, afterFindContext) {
|
|
328
|
+
_processAfterFind: function(data, projection={}, afterFindContext={}) {
|
|
329
329
|
/**
|
|
330
330
|
* Todo: Maybe make this method public?
|
|
331
331
|
* Recurses through fields that are models and populates missing default-fields and calls model.afterFind([fn,..])
|
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.32.
|
|
5
|
+
"version": "1.32.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/plugins/images/index.js
CHANGED
|
@@ -74,7 +74,7 @@ let plugin = module.exports = {
|
|
|
74
74
|
plugin.addImages(this, data).then(() => n(null, data)).catch(e => n(e))
|
|
75
75
|
})
|
|
76
76
|
model.afterFind.push(function(data, n) {
|
|
77
|
-
plugin.getSignedUrls(this, data).then(() => n(null, data)).catch(e => n(e))
|
|
77
|
+
plugin.getSignedUrls.call(model, this, data).then(() => n(null, data)).catch(e => n(e))
|
|
78
78
|
})
|
|
79
79
|
}
|
|
80
80
|
},
|
|
@@ -128,15 +128,15 @@ let plugin = module.exports = {
|
|
|
128
128
|
let uid = nanoid.nanoid()
|
|
129
129
|
let pathFilename = filesArr.imageField.filename ? '/' + filesArr.imageField.filename : ''
|
|
130
130
|
let image = {
|
|
131
|
-
bucket:
|
|
132
|
-
date:
|
|
131
|
+
bucket: plugin.awsBucket,
|
|
132
|
+
date: plugin.manager.useMilliseconds? Date.now() : Math.floor(Date.now() / 1000),
|
|
133
133
|
filename: file.name,
|
|
134
134
|
filesize: file.size,
|
|
135
135
|
path: `${plugin.bucketDir}/${uid}${pathFilename}.${file.ext}`,
|
|
136
136
|
// sizes: ['large', 'medium', 'small'],
|
|
137
137
|
uid: uid,
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
plugin.manager.info(
|
|
140
140
|
`Uploading '${image.filename}' to '${image.bucket}/${image.path}'`
|
|
141
141
|
)
|
|
142
142
|
if (test) {
|
|
@@ -144,7 +144,7 @@ let plugin = module.exports = {
|
|
|
144
144
|
resolve()
|
|
145
145
|
} else {
|
|
146
146
|
plugin.s3.upload({
|
|
147
|
-
Bucket:
|
|
147
|
+
Bucket: plugin.awsBucket,
|
|
148
148
|
Key: image.path,
|
|
149
149
|
Body: file.data,
|
|
150
150
|
// The IAM permission "s3:PutObjectACL" must be included in the appropriate policy
|
|
@@ -183,16 +183,23 @@ let plugin = module.exports = {
|
|
|
183
183
|
},
|
|
184
184
|
|
|
185
185
|
getSignedUrls: async function(options, data) {
|
|
186
|
+
/**
|
|
187
|
+
* Get signed urls for all image objects in data
|
|
188
|
+
* @param {object} options - monastery operation options {model, query, files, ..}
|
|
189
|
+
* @param {object} data
|
|
190
|
+
* @return promise(data)
|
|
191
|
+
* @this model
|
|
192
|
+
*/
|
|
186
193
|
// Not wanting signed urls for this operation?
|
|
187
194
|
if (util.isDefined(options.getSignedUrls) && !options.getSignedUrls) return
|
|
188
195
|
|
|
189
196
|
// Find all image objects in data
|
|
190
197
|
for (let doc of util.toArray(data)) {
|
|
191
|
-
for (let imageField of
|
|
198
|
+
for (let imageField of this.imageFields) {
|
|
192
199
|
if (options.getSignedUrls || imageField.getSignedUrl) {
|
|
193
200
|
let images = plugin._findImagesInData(doc, imageField, 0, '').filter(o => o.image)
|
|
194
201
|
for (let image of images) {
|
|
195
|
-
image.image.signedUrl =
|
|
202
|
+
image.image.signedUrl = plugin._getSignedUrl(image.image.path)
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
}
|
|
@@ -330,7 +337,7 @@ let plugin = module.exports = {
|
|
|
330
337
|
{ Key: `medium/${key}.jpg` },
|
|
331
338
|
{ Key: `large/${key}.jpg` }
|
|
332
339
|
)
|
|
333
|
-
|
|
340
|
+
plugin.manager.info(
|
|
334
341
|
`Removing '${pre.image.filename}' from '${pre.image.bucket}/${pre.image.path}'`
|
|
335
342
|
)
|
|
336
343
|
}
|
|
@@ -448,12 +455,12 @@ let plugin = module.exports = {
|
|
|
448
455
|
// Subdocument field
|
|
449
456
|
if (util.isSubdocument(field)) {//schema.isObject
|
|
450
457
|
// log(`Recurse 1: ${path2}`)
|
|
451
|
-
list = list.concat(
|
|
458
|
+
list = list.concat(plugin._findAndTransformImageFields(field, path2))
|
|
452
459
|
|
|
453
460
|
// Array field
|
|
454
461
|
} else if (util.isArray(field)) {//schema.isArray
|
|
455
462
|
// log(`Recurse 2: ${path2}`)
|
|
456
|
-
list = list.concat(
|
|
463
|
+
list = list.concat(plugin._findAndTransformImageFields(field, path2))
|
|
457
464
|
|
|
458
465
|
// Image field. Test for field.image as field.type may be 'any'
|
|
459
466
|
} else if (field.type == 'image' || field.image) {
|
|
@@ -507,7 +514,7 @@ let plugin = module.exports = {
|
|
|
507
514
|
if (`${dataPath}.${m}`.match(imageField.fullPathRegex)) {
|
|
508
515
|
list.push({ imageField: imageField, dataPath: `${dataPath}.${m}`, image: target[m] })
|
|
509
516
|
} else {
|
|
510
|
-
list.push(...
|
|
517
|
+
list.push(...plugin._findImagesInData(
|
|
511
518
|
target[m],
|
|
512
519
|
imageField,
|
|
513
520
|
imageFieldChunkIndex+i+1,
|
package/test/plugin-images.js
CHANGED
|
@@ -734,29 +734,27 @@ module.exports = function(monastery, opendb) {
|
|
|
734
734
|
photos2: [image, image],
|
|
735
735
|
})
|
|
736
736
|
|
|
737
|
-
// Find signed URL
|
|
737
|
+
// Find signed URL via query option
|
|
738
|
+
let imageWithSignedUrl = { ...image, signedUrl: expect.stringMatching(/^https/) }
|
|
738
739
|
await expect(db.user.findOne({ query: userInserted._id, getSignedUrls: true })).resolves.toEqual({
|
|
739
740
|
_id: expect.any(Object),
|
|
740
|
-
photos: [
|
|
741
|
-
|
|
742
|
-
{ ...image, signedUrl: expect.stringMatching(/^https/) },
|
|
743
|
-
],
|
|
744
|
-
photos2: [
|
|
745
|
-
{ ...image, signedUrl: expect.stringMatching(/^https/) },
|
|
746
|
-
{ ...image, signedUrl: expect.stringMatching(/^https/) },
|
|
747
|
-
]
|
|
741
|
+
photos: [imageWithSignedUrl, imageWithSignedUrl],
|
|
742
|
+
photos2: [imageWithSignedUrl, imageWithSignedUrl],
|
|
748
743
|
})
|
|
749
|
-
|
|
744
|
+
|
|
745
|
+
// Find signed URL via schema option
|
|
750
746
|
await expect(db.user.findOne({ query: userInserted._id })).resolves.toEqual({
|
|
751
747
|
_id: expect.any(Object),
|
|
752
|
-
photos: [
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
748
|
+
photos: [image, image],
|
|
749
|
+
photos2: [imageWithSignedUrl, imageWithSignedUrl],
|
|
750
|
+
})
|
|
751
|
+
|
|
752
|
+
// Works with _processAfterFind
|
|
753
|
+
let rawUser = await db.user._findOne({ _id: userInserted._id })
|
|
754
|
+
await expect(db.user._processAfterFind(rawUser)).resolves.toEqual({
|
|
755
|
+
_id: expect.any(Object),
|
|
756
|
+
photos: [image, image],
|
|
757
|
+
photos2: [imageWithSignedUrl, imageWithSignedUrl],
|
|
760
758
|
})
|
|
761
759
|
|
|
762
760
|
db.close()
|