monastery 1.34.0 → 1.36.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/.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": 120, "ignorePattern": "^\\s*<(rect|path|line)\\s" }],
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.1](https://github.com/boycce/monastery/compare/1.36.0...1.36.1) (2022-04-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * findOneAndUpdate population, blacklisting, etc ([19c4fc9](https://github.com/boycce/monastery/commit/19c4fc96d8c94d9dd68af2a74af693c8dc7a4c17))
11
+
12
+ ## [1.36.0](https://github.com/boycce/monastery/compare/1.35.0...1.36.0) (2022-04-15)
13
+
14
+
15
+ ### Features
16
+
17
+ * added findOneAndUpdate ([60b518a](https://github.com/boycce/monastery/commit/60b518a1d09002a794e72fe3476c39c43c0c3b5e))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * removed depreciation warnings ([6db73bb](https://github.com/boycce/monastery/commit/6db73bba7916b4c5c98a24fd03b34c0f776abb5c))
23
+
24
+ ## [1.35.0](https://github.com/boycce/monastery/compare/1.34.0...1.35.0) (2022-04-08)
25
+
26
+
27
+ ### Features
28
+
29
+ * Blacklist `false` removes all blacklisting, added tests for blacklisting/project stirng ([5999859](https://github.com/boycce/monastery/commit/599985972cc14b980148db26c03108feabf23756))
30
+ * Add project to insert/update/validate ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
31
+ * Whitelisting a parent will remove any previously blacklisted children ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
32
+ * Blacklist/project works the same across find/insert/update/validate ([1b1eb12](https://github.com/boycce/monastery/commit/1b1eb12bc476ff82445a46489db64b37c13f9513))
33
+
5
34
  ## [1.34.0](https://github.com/boycce/monastery/compare/1.33.0...1.34.0) (2022-04-05)
6
35
 
7
36
 
package/docs/readme.md CHANGED
@@ -83,18 +83,20 @@ Coming soon...
83
83
 
84
84
  ## Roadmap
85
85
 
86
- - Add FindOneAndUpdate
86
+ - ~~Add FindOneAndUpdate~~
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
- - ~~Blackislisitng which aggregates from the order of appearance~~
90
+ - ~~Blacklist false removes all blacklisting~~
91
+ - ~~Add project to insert/update/validate~~
91
92
  - ~~Whitelisting a parent will remove any previously blacklisted children~~
93
+ - ~~Blacklist/project works the same across find/insert/update/validate~~
92
94
  - Automatic subdocument ids
93
95
  - Remove ACL default 'public read'
94
- - Public db.arrayWithSchema method
96
+ - ~~Public db.arrayWithSchema method~~
95
97
  - Global after/before hooks
96
- - Split away from Monk (unless updated)
97
98
  - docs: Make the implicit ID query conversion more apparent
99
+ - Split away from Monk (unless updated)
98
100
 
99
101
  ## Special Thanks
100
102
 
@@ -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,59 +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 Manager instance or manager mock
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.error = debug('monastery:error*')
42
- manager.warn = debug('monastery:warn')
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.limit = limit
51
- manager.nullObjects = nullObjects
44
+ manager.model = require('./model')
45
+ manager.models = models
52
46
  manager.parseData = util.parseData.bind(util)
53
- manager.timestamps = timestamps
54
- manager.useMilliseconds = useMilliseconds
55
- manager.beforeModel = []
56
- manager.arrayWithSchema = manager.arraySchema = (array, schema) => {
57
- array.schema = schema; return array
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]
58
54
  }
59
55
 
60
56
  // Depreciation warnings
61
57
  if (depreciationWarningDefaultField) {
62
- manager.error('manager.defaultFields has been depreciated in favour of manager.timestamps')
58
+ manager.error('opts.defaultFields has been depreciated in favour of opts.timestamps')
63
59
  }
64
60
 
65
61
  // Initiate any plugins
66
62
  if (manager.imagePlugin) {
67
- manager.imagePluginFile.setup(manager, util.isObject(imagePlugin)? imagePlugin : {})
63
+ manager.imagePluginFile.setup(manager, util.isObject(manager.imagePlugin)? manager.imagePlugin : {})
68
64
  }
69
65
 
70
66
  // Catch mongodb connectivity errors
@@ -72,11 +68,17 @@ module.exports = function(uri, opts, fn) {
72
68
  return manager
73
69
  }
74
70
 
75
- function models(path) {
71
+ let arrayWithSchema = function(array, schema) {
72
+ array.schema = schema
73
+ return array
74
+ }
75
+
76
+ let models = function(path) {
76
77
  /**
77
78
  * Setup model definitions from a folder location
78
79
  * @param {string} pathname
79
80
  * @return {object} - e.g. { user: , article: , .. }
81
+ * @this Manager
80
82
  */
81
83
  let models = {}
82
84
  if (!path || typeof path !== 'string') {