monastery 1.33.0 → 1.36.0
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/.eslintrc.json +1 -1
- package/changelog.md +29 -0
- package/docs/readme.md +5 -2
- package/docs/schema/index.md +3 -3
- package/lib/index.js +37 -32
- package/lib/model-crud.js +189 -113
- package/lib/model-validate.js +37 -62
- package/lib/model.js +3 -4
- package/lib/monk-monkey-patches.js +73 -0
- package/lib/util.js +20 -18
- package/package.json +1 -1
- package/test/blacklisting.js +83 -26
- package/test/crud.js +59 -1
- package/test/monk.js +1 -1
- package/test/util.js +7 -0
package/.eslintrc.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"plugins": [],
|
|
22
22
|
"rules": {
|
|
23
23
|
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
|
|
24
|
-
"max-len": ["error", { "code":
|
|
24
|
+
"max-len": ["error", { "code": 125, "ignorePattern": "^\\s*<(rect|path|line)\\s" }],
|
|
25
25
|
"no-prototype-builtins": "off",
|
|
26
26
|
"no-unused-vars": ["error", { "args": "none" }],
|
|
27
27
|
"object-shorthand": ["error", "consistent"],
|
package/changelog.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
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.36.0](https://github.com/boycce/monastery/compare/1.35.0...1.36.0) (2022-04-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added findOneAndUpdate ([60b518a](https://github.com/boycce/monastery/commit/60b518a1d09002a794e72fe3476c39c43c0c3b5e))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* removed depreciation warnings ([6db73bb](https://github.com/boycce/monastery/commit/6db73bba7916b4c5c98a24fd03b34c0f776abb5c))
|
|
16
|
+
|
|
17
|
+
## [1.35.0](https://github.com/boycce/monastery/compare/1.34.0...1.35.0) (2022-04-08)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* Blacklist `false` removes all blacklisting, added tests for blacklisting/project stirng ([5999859](https://github.com/boycce/monastery/commit/599985972cc14b980148db26c03108feabf23756))
|
|
23
|
+
* Add project to insert/update/validate ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
|
|
24
|
+
* Whitelisting a parent will remove any previously blacklisted children ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
|
|
25
|
+
* Blacklist/project works the same across find/insert/update/validate ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
|
|
26
|
+
|
|
27
|
+
## [1.34.0](https://github.com/boycce/monastery/compare/1.33.0...1.34.0) (2022-04-05)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* added db.arraySchema / db.arrayWithSchema ([4210dc3](https://github.com/boycce/monastery/commit/4210dc33486de757a22d0973e661522e19230158))
|
|
33
|
+
|
|
5
34
|
## [1.33.0](https://github.com/boycce/monastery/compare/1.32.5...1.33.0) (2022-04-05)
|
|
6
35
|
|
|
7
36
|
|
package/docs/readme.md
CHANGED
|
@@ -87,10 +87,13 @@ Coming soon...
|
|
|
87
87
|
- Add before/afterInsertUpdate
|
|
88
88
|
- Bug: Setting an object literal on an ID field ('model') saves successfully
|
|
89
89
|
- Population within array items
|
|
90
|
-
-
|
|
90
|
+
- ~~Blacklist false removes all blacklisting~~
|
|
91
|
+
- ~~Add project to insert/update/validate~~
|
|
92
|
+
- ~~Whitelisting a parent will remove any previously blacklisted children~~
|
|
93
|
+
- ~~Blacklist/project works the same across find/insert/update/validate~~
|
|
91
94
|
- Automatic subdocument ids
|
|
92
95
|
- Remove ACL default 'public read'
|
|
93
|
-
- Public db.arrayWithSchema method
|
|
96
|
+
- ~~Public db.arrayWithSchema method~~
|
|
94
97
|
- Global after/before hooks
|
|
95
98
|
- Split away from Monk (unless updated)
|
|
96
99
|
- docs: Make the implicit ID query conversion more apparent
|
package/docs/schema/index.md
CHANGED
|
@@ -248,9 +248,9 @@ schema.messages = {
|
|
|
248
248
|
}
|
|
249
249
|
// You can also target any rules set on the array or sub arrays
|
|
250
250
|
// e.g.
|
|
251
|
-
// let arrayWithSchema = (array, schema) => { array.schema = schema; return array }
|
|
252
|
-
// petGroups = arrayWithSchema(
|
|
253
|
-
// [arrayWithSchema(
|
|
251
|
+
// // let arrayWithSchema = (array, schema) => { array.schema = schema; return array }, OR you can use db.arrayWithSchema
|
|
252
|
+
// petGroups = db.arrayWithSchema(
|
|
253
|
+
// [db.arrayWithSchema(
|
|
254
254
|
// [{ name: { type: 'string' }}],
|
|
255
255
|
// { minLength: 1 }
|
|
256
256
|
// )],
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
let util = require('./util')
|
|
2
|
-
let monk = require('monk')
|
|
3
1
|
let debug = require('debug')
|
|
2
|
+
let monk = require('monk')
|
|
3
|
+
let util = require('./util')
|
|
4
|
+
|
|
5
|
+
// Apply monk monkey patches
|
|
6
|
+
monk.manager.prototype.open = require('./monk-monkey-patches').open
|
|
7
|
+
monk.Collection.prototype.findOneAndUpdate = require('./monk-monkey-patches').findOneAndUpdate
|
|
4
8
|
|
|
5
9
|
module.exports = function(uri, opts, fn) {
|
|
6
10
|
/**
|
|
@@ -12,56 +16,51 @@ module.exports = function(uri, opts, fn) {
|
|
|
12
16
|
* @param {object} opts
|
|
13
17
|
* @return monk manager
|
|
14
18
|
*/
|
|
19
|
+
let monasteryOpts = [
|
|
20
|
+
'defaultObjects', 'imagePlugin', 'limit', 'nullObjects', 'timestamps', 'useMilliseconds'
|
|
21
|
+
]
|
|
22
|
+
|
|
15
23
|
if (!opts) opts = {}
|
|
16
24
|
if (util.isDefined(opts.defaultFields)) {
|
|
17
25
|
var depreciationWarningDefaultField = true
|
|
18
26
|
opts.timestamps = opts.defaultFields
|
|
27
|
+
delete opts.defaultFields
|
|
28
|
+
}
|
|
29
|
+
if (!util.isDefined(opts.timestamps)) {
|
|
30
|
+
opts.timestamps = true
|
|
19
31
|
}
|
|
20
|
-
let defaultObjects = opts.defaultObjects
|
|
21
|
-
let imagePlugin = opts.imagePlugin
|
|
22
|
-
let limit = opts.limit
|
|
23
|
-
let nullObjects = opts.nullObjects
|
|
24
|
-
let timestamps = util.isDefined(opts.timestamps)? opts.timestamps : true
|
|
25
|
-
let useMilliseconds = opts.useMilliseconds
|
|
26
|
-
delete opts.defaultFields
|
|
27
|
-
delete opts.defaultObjects
|
|
28
|
-
delete opts.imagePlugin
|
|
29
|
-
delete opts.limit
|
|
30
|
-
delete opts.nullObjects
|
|
31
|
-
delete opts.timestamps
|
|
32
|
-
delete opts.useMilliseconds
|
|
33
32
|
|
|
34
|
-
// Monk
|
|
33
|
+
// Monk manager instance or manager mock
|
|
35
34
|
// Monk manager instances have manager._db defined which is the raw mongodb connection
|
|
36
35
|
if (typeof uri === 'object') var manager = uri
|
|
37
|
-
else if (uri) manager = monk(uri, { useUnifiedTopology: true, ...opts }, fn)
|
|
36
|
+
else if (uri) manager = monk(uri, { useUnifiedTopology: true, ...util.omit(opts, monasteryOpts) }, fn)
|
|
38
37
|
else manager = { id: monk.id }
|
|
39
38
|
|
|
40
39
|
// Add monastery properties
|
|
41
|
-
manager.
|
|
42
|
-
manager.
|
|
43
|
-
manager.info = debug('monastery:info')
|
|
44
|
-
manager.model = require('./model')
|
|
45
|
-
manager.models = models
|
|
46
|
-
manager.defaultObjects = defaultObjects
|
|
47
|
-
manager.imagePlugin = imagePlugin
|
|
40
|
+
manager.arrayWithSchema = arrayWithSchema
|
|
41
|
+
manager.beforeModel = []
|
|
48
42
|
manager.imagePluginFile = require('../plugins/images')
|
|
49
43
|
manager.isId = util.isId.bind(util)
|
|
50
|
-
manager.
|
|
51
|
-
manager.
|
|
44
|
+
manager.model = require('./model')
|
|
45
|
+
manager.models = models
|
|
52
46
|
manager.parseData = util.parseData.bind(util)
|
|
53
|
-
manager.
|
|
54
|
-
manager.
|
|
55
|
-
manager.
|
|
47
|
+
manager.warn = debug('monastery:warn')
|
|
48
|
+
manager.error = debug('monastery:error*')
|
|
49
|
+
manager.info = debug('monastery:info')
|
|
50
|
+
|
|
51
|
+
// Add opts onto manager
|
|
52
|
+
for (let key of monasteryOpts) {
|
|
53
|
+
manager[key] = opts[key]
|
|
54
|
+
}
|
|
56
55
|
|
|
57
56
|
// Depreciation warnings
|
|
58
57
|
if (depreciationWarningDefaultField) {
|
|
59
|
-
manager.error('
|
|
58
|
+
manager.error('opts.defaultFields has been depreciated in favour of opts.timestamps')
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
// Initiate any plugins
|
|
63
62
|
if (manager.imagePlugin) {
|
|
64
|
-
manager.imagePluginFile.setup(manager, util.isObject(imagePlugin)? imagePlugin : {})
|
|
63
|
+
manager.imagePluginFile.setup(manager, util.isObject(manager.imagePlugin)? manager.imagePlugin : {})
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
// Catch mongodb connectivity errors
|
|
@@ -69,11 +68,17 @@ module.exports = function(uri, opts, fn) {
|
|
|
69
68
|
return manager
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
function
|
|
71
|
+
let arrayWithSchema = function(array, schema) {
|
|
72
|
+
array.schema = schema
|
|
73
|
+
return array
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let models = function(path) {
|
|
73
77
|
/**
|
|
74
78
|
* Setup model definitions from a folder location
|
|
75
79
|
* @param {string} pathname
|
|
76
80
|
* @return {object} - e.g. { user: , article: , .. }
|
|
81
|
+
* @this Manager
|
|
77
82
|
*/
|
|
78
83
|
let models = {}
|
|
79
84
|
if (!path || typeof path !== 'string') {
|