monastery 3.0.10 → 3.0.12
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/image-plugin.md +1 -1
- package/docs/manager/index.md +1 -2
- package/docs/manager/models.md +4 -0
- package/docs/readme.md +4 -2
- package/lib/index.js +15 -4
- package/lib/model.js +1 -1
- package/package.json +1 -1
- package/plugins/images/index.js +8 -6
- package/test/model.js +12 -9
- package/test/plugin-images.js +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
|
+
### [3.0.12](https://github.com/boycce/monastery/compare/3.0.11...3.0.12) (2024-05-01)
|
|
6
|
+
|
|
7
|
+
### [3.0.11](https://github.com/boycce/monastery/compare/3.0.10...3.0.11) (2024-04-30)
|
|
8
|
+
|
|
5
9
|
### [3.0.10](https://github.com/boycce/monastery/compare/3.0.8...3.0.10) (2024-04-30)
|
|
6
10
|
|
|
7
11
|
### [3.0.9](https://github.com/boycce/monastery/compare/3.0.8...3.0.9) (2024-04-30)
|
package/docs/image-plugin.md
CHANGED
|
@@ -12,7 +12,7 @@ To use the default image plugin shipped with monastery, you need to use the opti
|
|
|
12
12
|
imagePlugin: {
|
|
13
13
|
awsAcl: 'public-read', // default
|
|
14
14
|
awsBucket: 'your-bucket-name',
|
|
15
|
-
awsRegion: undefined, //
|
|
15
|
+
awsRegion: undefined, // e.g. 'ap-southeast-2'
|
|
16
16
|
awsAccessKeyId: 'your-key-here',
|
|
17
17
|
awsSecretAccessKey: 'your-key-here',
|
|
18
18
|
filesize: undefined, // default (max filesize in bytes)
|
package/docs/manager/index.md
CHANGED
|
@@ -13,9 +13,8 @@ Monastery manager constructor.
|
|
|
13
13
|
`uri` *(string\|array)*: A [mongo connection string URI](https://www.mongodb.com/docs/v5.0/reference/connection-string/). Replica sets can be an array or comma separated.
|
|
14
14
|
|
|
15
15
|
[`options`] *(object)*:
|
|
16
|
-
- [`hideWarnings=false`] *(boolean)*: hide monastery warnings
|
|
17
|
-
- [`hideErrors=false`] *(boolean)*: hide monastery errors
|
|
18
16
|
- [`defaultObjects=false`] *(boolean)*: when [inserting](../model/insert.html#defaults-example), undefined embedded documents and arrays are defined
|
|
17
|
+
- [`logLevel=2`] *(number)*: 1=errors, 2=warnings, 3=info. You can also use the debug environment variable `DEBUG=monastery:info`
|
|
19
18
|
- [`nullObjects=false`] *(boolean)*: embedded documents and arrays can be set to null or an empty string (which gets converted to null). You can override this per field via `nullObject: true`.
|
|
20
19
|
- [`promise=false`] *(boolean)*: return a promise instead of the manager instance
|
|
21
20
|
- [`timestamps=true`] *(boolean)*: whether to use [`createdAt` and `updatedAt`](../definition), this can be overridden per operation
|
package/docs/manager/models.md
CHANGED
|
@@ -11,6 +11,10 @@ Setup model definitions from a folder location
|
|
|
11
11
|
|
|
12
12
|
`path` *(string)*: path to model definitions, the filenames are used as the corresponding model name. Make sure the model definition is exported as the default
|
|
13
13
|
|
|
14
|
+
[`options`] *(object)*:
|
|
15
|
+
- [`commonJs=false`] *(boolean)*: for old commonjs projects, you will need to set this to `true` which uses `require` instead of `import` (removed in `3.0.0`)
|
|
16
|
+
- [`waitForIndexes=false`] *(boolean)*: returns a proimse that waits for the Mongo collection indexes to be setup
|
|
17
|
+
|
|
14
18
|
### Returns
|
|
15
19
|
|
|
16
20
|
A promise with an array of [model](../model) instances, the model instances will also be available at:
|
package/docs/readme.md
CHANGED
|
@@ -133,10 +133,12 @@ You can view MongoDB's [compatibility table here](https://www.mongodb.com/docs/d
|
|
|
133
133
|
|
|
134
134
|
## Debugging
|
|
135
135
|
|
|
136
|
-
This package uses [debug](https://github.com/visionmedia/debug) which allows you to set
|
|
136
|
+
This package uses [debug](https://github.com/visionmedia/debug) which allows you to set the level of output via the `DEBUG` environment variable. Using `DEBUG` will override the manager's `logLevel` option, e.g. `monastery('...', { logLevel: 3 })`.
|
|
137
137
|
|
|
138
138
|
```bash
|
|
139
|
-
$ DEBUG=monastery:
|
|
139
|
+
$ DEBUG=monastery:error # level 1, shows errors
|
|
140
|
+
$ DEBUG=monastery:warn # level 2, shows warnings and depreciation notices
|
|
141
|
+
$ DEBUG=monastery:info # level 3, shows operation information
|
|
140
142
|
```
|
|
141
143
|
|
|
142
144
|
## Contributing
|
package/lib/index.js
CHANGED
|
@@ -31,11 +31,14 @@ function Manager(uri, opts) {
|
|
|
31
31
|
if (typeof opts.defaultFields != 'undefined') throw Error('opts.defaultFields has been depreciated, use opts.timestamps')
|
|
32
32
|
if (typeof opts.timestamps == 'undefined') opts.timestamps = true
|
|
33
33
|
|
|
34
|
+
// opts: logLevel
|
|
35
|
+
if (typeof opts.logLevel == 'undefined') opts.logLevel = 2
|
|
36
|
+
|
|
34
37
|
// opts: separate out monastery options
|
|
35
38
|
const mongoOpts = Object.keys(opts||{}).reduce((acc, key) => {
|
|
36
39
|
if (
|
|
37
40
|
![
|
|
38
|
-
'databaseName', 'defaultObjects', '
|
|
41
|
+
'databaseName', 'defaultObjects', 'logLevel', 'imagePlugin', 'limit', 'nullObjects',
|
|
39
42
|
'promise', 'timestamps', 'useMilliseconds',
|
|
40
43
|
].includes(key)) {
|
|
41
44
|
acc[key] = opts[key]
|
|
@@ -45,13 +48,20 @@ function Manager(uri, opts) {
|
|
|
45
48
|
|
|
46
49
|
// Add properties
|
|
47
50
|
this.uri = uri
|
|
48
|
-
this.
|
|
49
|
-
this.warn = debug('monastery:warn' + (opts.
|
|
50
|
-
this.
|
|
51
|
+
this.error = debug('monastery:error' + (opts.logLevel > 0 ? '*' : ''))
|
|
52
|
+
this.warn = debug('monastery:warn' + (opts.logLevel > 1 ? '*' : ''))
|
|
53
|
+
this.info = debug('monastery:info' + (opts.logLevel > 2 ? '*' : ''))
|
|
51
54
|
this.opts = opts
|
|
52
55
|
this.beforeModel = []
|
|
53
56
|
this.collections = {}
|
|
54
57
|
this._openQueue = []
|
|
58
|
+
|
|
59
|
+
// If there is no DEBUG= environment variable, we will need to force the debugs on (due to bug on debug@4.3.4)
|
|
60
|
+
if (!debug.namespaces) {
|
|
61
|
+
if (opts.logLevel > 0) this.error.enabled = true
|
|
62
|
+
if (opts.logLevel > 1) this.warn.enabled = true
|
|
63
|
+
if (opts.logLevel > 2) this.info.enabled = true
|
|
64
|
+
}
|
|
55
65
|
|
|
56
66
|
// Create a new MongoDB Client
|
|
57
67
|
if (typeof this.uri == 'string' || Array.isArray(this.uri)) {
|
|
@@ -272,6 +282,7 @@ Manager.prototype.parseData = function(obj) {
|
|
|
272
282
|
}
|
|
273
283
|
|
|
274
284
|
Manager.prototype.model = Model
|
|
285
|
+
Manager.prototype._getSignedUrl = imagePluginFile._getSignedUrl
|
|
275
286
|
|
|
276
287
|
inherits(Manager, EventEmitter)
|
|
277
288
|
module.exports = Manager
|
package/lib/model.js
CHANGED
|
@@ -263,7 +263,7 @@ Model.prototype._setupIndexes = async function(fields, opts={}) {
|
|
|
263
263
|
let textIndex = { name: 'text', key: {} }
|
|
264
264
|
|
|
265
265
|
// No db defined
|
|
266
|
-
if (!((model.manager||{})._state||
|
|
266
|
+
if (!((model.manager||{})._state||'').match(/^open/)) {
|
|
267
267
|
throw new Error(`Skipping createIndex on the '${model.name||''}' model, no mongodb connection found.`)
|
|
268
268
|
}
|
|
269
269
|
|
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.12",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/plugins/images/index.js
CHANGED
|
@@ -38,16 +38,16 @@ let plugin = module.exports = {
|
|
|
38
38
|
this.path = options.path || function (uid, basename, ext, file) { return `full/${uid}.${ext}` }
|
|
39
39
|
|
|
40
40
|
if (!options.awsBucket || !options.awsAccessKeyId || !options.awsSecretAccessKey) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
throw new Error('Monastery imagePlugin: awsRegion, awsBucket, awsAccessKeyId, or awsSecretAccessKey is not defined')
|
|
42
|
+
}
|
|
43
|
+
if (!options.awsRegion) {
|
|
44
|
+
throw new Error('Monastery imagePlugin: v3 requires awsRegion to be defined for signing urls, e.g. "ap-southeast-2"')
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// Create s3 'service' instance (defer require since it takes 120ms to load)
|
|
47
48
|
// v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
|
|
48
49
|
// v3: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/
|
|
49
50
|
// v3 examples: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html
|
|
50
|
-
manager._getSignedUrl = this._getSignedUrl
|
|
51
51
|
this.getS3Client = () => {
|
|
52
52
|
const { S3 } = require('@aws-sdk/client-s3')
|
|
53
53
|
return this._s3Client || (this._s3Client = new S3({
|
|
@@ -598,8 +598,10 @@ let plugin = module.exports = {
|
|
|
598
598
|
* @see v2: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
|
|
599
599
|
* @see v3: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#s3-presigned-url
|
|
600
600
|
*/
|
|
601
|
-
if (!plugin.
|
|
602
|
-
throw
|
|
601
|
+
if (!plugin.getS3Client) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
'To use db._getSignedUrl(), the imagePlugin manager option must be defined, e.g. `monastery(..., { imagePlugin })`'
|
|
604
|
+
)
|
|
603
605
|
}
|
|
604
606
|
const { GetObjectCommand } = require('@aws-sdk/client-s3')
|
|
605
607
|
const params = { Bucket: bucket || plugin.awsBucket, Key: path }
|
package/test/model.js
CHANGED
|
@@ -7,16 +7,18 @@ beforeAll(async () => { db = monastery('127.0.0.1/monastery') })
|
|
|
7
7
|
afterAll(async () => { db.close() })
|
|
8
8
|
|
|
9
9
|
test('model > model on manager', async () => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const db2 = monastery('127.0.0.1', { logLevel: 0 })
|
|
11
|
+
db2.model('user', { fields: {} })
|
|
12
|
+
let modelNamedConflict = db2.model('open', { fields: {} })
|
|
12
13
|
|
|
13
14
|
// Model added to manager[model]
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
15
|
+
expect(db2.user).toEqual(expect.any(Object))
|
|
16
|
+
expect(db2.models.user).toEqual(expect.any(Object))
|
|
16
17
|
|
|
17
18
|
// Model with a name conflict is only added to manager.models[name]
|
|
18
|
-
expect(
|
|
19
|
-
expect(
|
|
19
|
+
expect(db2.open).toEqual(expect.any(Function))
|
|
20
|
+
expect(db2.models.open).toEqual(modelNamedConflict)
|
|
21
|
+
db2.close()
|
|
20
22
|
})
|
|
21
23
|
|
|
22
24
|
test('model setup', async () => {
|
|
@@ -313,8 +315,8 @@ test('model setup with messages', async () => {
|
|
|
313
315
|
|
|
314
316
|
test('model reserved rules', async () => {
|
|
315
317
|
// Setup
|
|
316
|
-
|
|
317
|
-
let user =
|
|
318
|
+
const db2 = monastery('127.0.0.1/monastery', { logLevel: 0 })
|
|
319
|
+
let user = db2.model('user-model', {
|
|
318
320
|
fields: {
|
|
319
321
|
name: {
|
|
320
322
|
type: 'string',
|
|
@@ -324,7 +326,7 @@ test('model reserved rules', async () => {
|
|
|
324
326
|
},
|
|
325
327
|
rules: {
|
|
326
328
|
params: (value) => {
|
|
327
|
-
return false // shouldn'
|
|
329
|
+
return false // shouldn't run
|
|
328
330
|
},
|
|
329
331
|
},
|
|
330
332
|
})
|
|
@@ -333,6 +335,7 @@ test('model reserved rules', async () => {
|
|
|
333
335
|
createdAt: expect.any(Number),
|
|
334
336
|
updatedAt: expect.any(Number),
|
|
335
337
|
})
|
|
338
|
+
db2.close()
|
|
336
339
|
})
|
|
337
340
|
|
|
338
341
|
test('model indexes', async () => {
|
package/test/plugin-images.js
CHANGED
|
@@ -881,7 +881,7 @@ test('images options awsAcl, awsBucket, metadata, params, path', async () => {
|
|
|
881
881
|
test('images option depreciations', async () => {
|
|
882
882
|
// testing (filename bucketDir)
|
|
883
883
|
const db3 = monastery('127.0.0.1/monastery', {
|
|
884
|
-
|
|
884
|
+
logLevel: 1,
|
|
885
885
|
timestamps: false,
|
|
886
886
|
imagePlugin: {
|
|
887
887
|
awsBucket: 'fake',
|