monastery 1.32.2 → 1.32.5

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 CHANGED
@@ -2,6 +2,22 @@
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.5](https://github.com/boycce/monastery/compare/1.32.4...1.32.5) (2022-03-21)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * dates not enforcing numbers ([d5a2a53](https://github.com/boycce/monastery/commit/d5a2a533f497b3c9e50cbeb66407cf9bc08dd2e4))
11
+
12
+ ### [1.32.4](https://github.com/boycce/monastery/compare/1.32.3...1.32.4) (2022-03-07)
13
+
14
+ ### [1.32.3](https://github.com/boycce/monastery/compare/1.32.2...1.32.3) (2022-03-07)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * fileSize warning ([3824b23](https://github.com/boycce/monastery/commit/3824b23883fad508e081d2a2bce1c340ec2775dc))
20
+
5
21
  ### [1.32.2](https://github.com/boycce/monastery/compare/1.32.1...1.32.2) (2022-03-04)
6
22
 
7
23
 
@@ -291,7 +291,7 @@ module.exports = {
291
291
 
292
292
  _ignoredRules: [ // todo: change name? i.e. 'specialFields'
293
293
  // Need to remove filesize and formats..
294
- 'default', 'defaultOverride', 'filename', 'filesize', 'formats', 'image', 'index', 'insertOnly',
294
+ 'default', 'defaultOverride', 'filename', 'filesize', 'fileSize', 'formats', 'image', 'index', 'insertOnly',
295
295
  'model', 'nullObject', 'params', 'getSignedUrl', 'timestampField', 'type', 'virtual'
296
296
  ]
297
297
 
package/lib/rules.js CHANGED
@@ -1,3 +1,4 @@
1
+ // Todo: remove stringnums in date/number/integer rules
1
2
  let ObjectId = require('mongodb').ObjectId
2
3
  let util = require('./util')
3
4
  let validator = require('validator')
@@ -48,12 +49,12 @@ module.exports = {
48
49
  message: 'Value was not a unix timestamp.',
49
50
  tryParse: function(x) {
50
51
  if (x === '') return null
51
- if (util.isString(x) && x.match(/^[+-]?[0-9]+$/)) return x // keep string nums intact
52
- return isNaN(parseInt(x))? x : parseInt(x)
52
+ if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return x // keep string nums intact
53
+ return isNaN(Number(x)) || (!x && x!==0) || x === true? x : Number(x)
53
54
  },
54
55
  fn: function(x) {
55
- if (util.isString(x) && x.match(/^[+-]?[0-9]+$/)) return true
56
- return typeof x === 'number' && (parseInt(x) === x)
56
+ if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return true
57
+ return typeof x === 'number'
57
58
  }
58
59
  },
59
60
  isImageObject: {
@@ -78,10 +79,10 @@ module.exports = {
78
79
  tryParse: function(x) {
79
80
  if (x === '') return null
80
81
  if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return x // keep string nums intact
81
- return isNaN(parseInt(x)) || (!x && x!==0) || x===true? x : parseInt(x)
82
+ return isNaN(parseInt(x)) || (!x && x!==0) || x === true? x : parseInt(x)
82
83
  },
83
84
  fn: function(x) {
84
- if (util.isString(x) && x.match(/^[+-]?[0-9]+$/)) return true
85
+ if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return true
85
86
  return typeof x === 'number' && (parseInt(x) === x)
86
87
  }
87
88
  },
@@ -91,7 +92,7 @@ module.exports = {
91
92
  tryParse: function(x) {
92
93
  if (x === '') return null
93
94
  if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return x // keep string nums intact
94
- return isNaN(Number(x)) || (!x && x!==0) || x===true? x : Number(x)
95
+ return isNaN(Number(x)) || (!x && x!==0) || x === true? x : Number(x)
95
96
  },
96
97
  fn: function(x) {
97
98
  if (util.isString(x) && x.match(/^[+-][0-9]+$/)) return true
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.2",
5
+ "version": "1.32.5",
6
6
  "license": "MIT",
7
7
  "repository": "github:boycce/monastery",
8
8
  "homepage": "https://boycce.github.io/monastery/",
package/test/crud.js CHANGED
@@ -3,6 +3,7 @@
3
3
  module.exports = function(monastery, opendb) {
4
4
 
5
5
  test('basic operator calls', async () => {
6
+ // Todo: take out and group query/id parsing tests
6
7
  let db = (await opendb(null)).db
7
8
  let user = db.model('user', {
8
9
  fields: {
@@ -53,20 +54,23 @@ module.exports = function(monastery, opendb) {
53
54
  let find6 = await user.find(inserted2[0]._id.toString())
54
55
  expect(find6).toEqual({ _id: inserted2[0]._id, name: 'Martin Luther1' })
55
56
 
56
- // Missing parameters
57
- await expect(user.find()).rejects.toThrow('Please pass an object or MongoId to options.query')
58
- await expect(user.find(undefined)).rejects.toThrow('Please pass an object or MongoId to options.query')
59
- await expect(user.find({})).rejects.toThrow('Please pass an object or MongoId to options.query')
60
- await expect(user.find({ query: null })).rejects.toThrow('Please pass an object or MongoId to options.query')
61
- await expect(user.find({ query: undefined })).rejects.toThrow('Please pass an object or MongoId to options.query')
62
- await expect(user.find({ query: { _id: undefined }}))
63
- .rejects.toThrow('Please pass an object or MongoId to options.query')
64
- await expect(user.find(1)).rejects.toThrow('Please pass an object or MongoId to options.query')
65
-
66
- // Bad MongoID
67
- await expect(user.find({ query: '' })).resolves.toEqual(null)
68
- await expect(user.find('bad-id')).resolves.toEqual(null)
57
+ // Bad ids
58
+ let badIdOrQuery = 'Please pass an object or MongoId to options.query'
59
+ await expect(user.find()).rejects.toThrow(badIdOrQuery)
60
+ await expect(user.find(1)).rejects.toThrow(badIdOrQuery)
61
+ await expect(user.find(null)).rejects.toThrow(badIdOrQuery)
62
+ await expect(user.find(undefined)).rejects.toThrow(badIdOrQuery)
63
+ await expect(user.find({})).rejects.toThrow(badIdOrQuery)
64
+ await expect(user.find({ query: null })).rejects.toThrow(badIdOrQuery)
65
+ await expect(user.find({ query: undefined })).rejects.toThrow(badIdOrQuery)
66
+ await expect(user.find({ query: { _id: undefined }})).rejects.toThrow(badIdOrQuery)
67
+
68
+ // Parseable
69
69
  await expect(user.find('')).resolves.toEqual(null)
70
+ await expect(user.find('invalid-id')).resolves.toEqual(null)
71
+ await expect(user.find({ query: '' })).resolves.toEqual(null)
72
+ await expect(user.find({ query: { _id: '' }})).resolves.toEqual(null)
73
+ await expect(user.find({ query: { _id: null }})).resolves.toEqual([]) // should throw error
70
74
 
71
75
  // FindOne (query id)
72
76
  let findOne = await user.findOne({ query: inserted._id })
@@ -417,7 +417,7 @@ module.exports = function(monastery, opendb) {
417
417
  imageSvgBad: { type: 'image' },
418
418
  imageSvgGood: { type: 'image', formats: ['svg'] },
419
419
  imageSvgAny: { type: 'image', formats: ['any'] },
420
- imageSize1: { type: 'image', fileSize: 1000 * 100 },
420
+ imageSize1: { type: 'image', filesize: 1000 * 100 },
421
421
  imageSize2: { type: 'image' },
422
422
  }})
423
423
 
package/test/validate.js CHANGED
@@ -1,3 +1,5 @@
1
+ // Todo: split out basic 'type' tests
2
+
1
3
  let validate = require('../lib/model-validate')
2
4
 
3
5
  module.exports = function(monastery, opendb) {
@@ -51,21 +53,55 @@ module.exports = function(monastery, opendb) {
51
53
  meta: { rule: 'isString', model: 'user', field: 'name' }
52
54
  })
53
55
 
56
+
54
57
  // Type error (date)
55
- await expect(user.validate({ name: 'a', date: null })).resolves.toEqual({ name: 'a', date: null })
56
- await expect(user.validate({ name: 'a', date: 'fe' })).rejects.toContainEqual({
58
+ let userdate = db.model('userdate', { fields: { amount: { type: 'date', required: true }}})
59
+ let userdate2 = db.model('userdate2', { fields: { amount: { type: 'date' }}})
60
+ await expect(userdate.validate({ amount: 0 })).resolves.toEqual({ amount: 0 })
61
+ await expect(userdate.validate({ amount: '0' })).resolves.toEqual({ amount: 0 })
62
+ await expect(userdate.validate({ amount: '1646778655000' })).resolves.toEqual({ amount: 1646778655000 })
63
+ await expect(userdate2.validate({ amount: '' })).resolves.toEqual({ amount: null })
64
+ await expect(userdate2.validate({ amount: null })).resolves.toEqual({ amount: null })
65
+ await expect(userdate.validate({ amount: 'badnum' })).rejects.toEqual([{
57
66
  status: '400',
58
- title: 'date',
67
+ title: 'amount',
59
68
  detail: 'Value was not a unix timestamp.',
60
- meta: { rule: 'isDate', model: 'user', field: 'date' }
61
- })
69
+ meta: { rule: 'isDate', model: 'userdate', field: 'amount' }
70
+ }])
71
+ await expect(userdate.validate({ amount: false })).rejects.toEqual([{
72
+ status: '400',
73
+ title: 'amount',
74
+ detail: 'Value was not a unix timestamp.',
75
+ meta: { rule: 'isDate', model: 'userdate', field: 'amount' }
76
+ }])
77
+ await expect(userdate.validate({ amount: undefined })).rejects.toEqual([{
78
+ status: '400',
79
+ title: 'amount',
80
+ detail: 'This field is required.',
81
+ meta: { rule: 'required', model: 'userdate', field: 'amount' },
82
+ }])
83
+ await expect(userdate.validate({ amount: null })).rejects.toEqual([{
84
+ status: '400',
85
+ title: 'amount',
86
+ detail: 'This field is required.',
87
+ meta: { rule: 'required', model: 'userdate', field: 'amount' },
88
+ }])
89
+
62
90
 
63
91
  // Type error (number)
64
92
  let usernum = db.model('usernum', { fields: { amount: { type: 'number', required: true }}})
65
93
  let usernum2 = db.model('usernum2', { fields: { amount: { type: 'number' }}})
66
94
  await expect(usernum.validate({ amount: 0 })).resolves.toEqual({ amount: 0 })
67
95
  await expect(usernum.validate({ amount: '0' })).resolves.toEqual({ amount: 0 })
96
+ await expect(usernum.validate({ amount: '1646778655000' })).resolves.toEqual({ amount: 1646778655000 })
68
97
  await expect(usernum2.validate({ amount: '' })).resolves.toEqual({ amount: null })
98
+ await expect(usernum2.validate({ amount: null })).resolves.toEqual({ amount: null })
99
+ await expect(usernum.validate({ amount: 'badnum' })).rejects.toEqual([{
100
+ status: '400',
101
+ title: 'amount',
102
+ detail: 'Value was not a number.',
103
+ meta: { rule: 'isNumber', model: 'usernum', field: 'amount' }
104
+ }])
69
105
  await expect(usernum.validate({ amount: false })).rejects.toEqual([{
70
106
  status: '400',
71
107
  title: 'amount',