monastery 2.2.3 → 3.0.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 +10 -1
- package/changelog.md +1 -1
- package/docs/_config.yml +2 -2
- package/docs/assets/imgs/monastery.jpg +0 -0
- package/docs/definition/index.md +1 -2
- package/docs/manager/index.md +19 -11
- package/docs/manager/model.md +1 -1
- package/docs/manager/models.md +2 -3
- package/docs/model/...rawMethods.md +289 -0
- package/docs/model/count.md +25 -0
- package/docs/model/find.md +5 -9
- package/docs/model/findOne.md +1 -1
- package/docs/model/findOneAndUpdate.md +1 -1
- package/docs/model/index.md +5 -30
- package/docs/model/insert.md +4 -6
- package/docs/model/remove.md +4 -6
- package/docs/model/update.md +4 -6
- package/docs/readme.md +80 -47
- package/lib/collection.js +324 -0
- package/lib/index.js +207 -67
- package/lib/model-crud.js +605 -619
- package/lib/model-validate.js +227 -245
- package/lib/model.js +70 -91
- package/lib/rules.js +36 -35
- package/lib/util.js +69 -15
- package/package.json +12 -12
- package/plugins/images/index.js +15 -26
- package/test/blacklisting.js +506 -537
- package/test/collection.js +445 -0
- package/test/crud.js +810 -730
- package/test/index.test.js +26 -0
- package/test/manager.js +77 -0
- package/test/mock/blacklisting.js +23 -23
- package/test/model.js +611 -572
- package/test/plugin-images.js +880 -965
- package/test/populate.js +249 -262
- package/test/util.js +126 -45
- package/test/validate.js +1074 -1121
- package/test/virtuals.js +222 -227
- package/lib/monk-monkey-patches.js +0 -90
- package/test/monk.js +0 -53
- package/test/test.js +0 -38
package/test/util.js
CHANGED
|
@@ -1,49 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = function(monastery, opendb) {
|
|
4
|
-
|
|
5
|
-
test('utilities formdata', async () => {
|
|
6
|
-
expect(await util.parseFormData({
|
|
7
|
-
'name': 'Martin',
|
|
8
|
-
'pets[]': '',
|
|
9
|
-
'deep[companyLogo]': 'a',
|
|
10
|
-
'deep[companyLogos][0]': 'b',
|
|
11
|
-
'deep[companyLogos2][0][logo]':'c',
|
|
12
|
-
'deep[companyLogos2][1][logo]': '',
|
|
13
|
-
'users[0][first]': 'Martin',
|
|
14
|
-
'users[0][last]': 'Luther',
|
|
15
|
-
'users[1][first]': 'Bruce',
|
|
16
|
-
'users[1][last]': 'Lee',
|
|
17
|
-
})).toEqual({
|
|
18
|
-
name: 'Martin',
|
|
19
|
-
pets: expect.any(Array),
|
|
20
|
-
deep: {
|
|
21
|
-
companyLogo: 'a',
|
|
22
|
-
companyLogos: ['b'],
|
|
23
|
-
companyLogos2: [{ logo: 'c' }, { logo: '' }]
|
|
24
|
-
},
|
|
25
|
-
users: [
|
|
26
|
-
{ 'first': 'Martin', 'last': 'Luther' },
|
|
27
|
-
{ 'first': 'Bruce', 'last': 'Lee' },
|
|
28
|
-
]
|
|
29
|
-
})
|
|
30
|
-
expect(util.parseFormData({ 'users[][\'name\']': 'Martin' })).rejects
|
|
31
|
-
.toEqual('Array items in bracket notation need array indexes "users[][\'name\']", e.g. users[0][name]')
|
|
32
|
-
})
|
|
1
|
+
const util = require('../lib/util.js')
|
|
2
|
+
const monastery = require('../lib/index.js')
|
|
33
3
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
4
|
+
test('util > formdata', async () => {
|
|
5
|
+
expect(await util.parseFormData({
|
|
6
|
+
'name': 'Martin',
|
|
7
|
+
'pets[]': '',
|
|
8
|
+
'deep[companyLogo]': 'a',
|
|
9
|
+
'deep[companyLogos][0]': 'b',
|
|
10
|
+
'deep[companyLogos2][0][logo]':'c',
|
|
11
|
+
'deep[companyLogos2][1][logo]': '',
|
|
12
|
+
'users[0][first]': 'Martin',
|
|
13
|
+
'users[0][last]': 'Luther',
|
|
14
|
+
'users[1][first]': 'Bruce',
|
|
15
|
+
'users[1][last]': 'Lee',
|
|
16
|
+
})).toEqual({
|
|
17
|
+
name: 'Martin',
|
|
18
|
+
pets: expect.any(Array),
|
|
19
|
+
deep: {
|
|
20
|
+
companyLogo: 'a',
|
|
21
|
+
companyLogos: ['b'],
|
|
22
|
+
companyLogos2: [{ logo: 'c' }, { logo: '' }],
|
|
23
|
+
},
|
|
24
|
+
users: [
|
|
25
|
+
{ 'first': 'Martin', 'last': 'Luther' },
|
|
26
|
+
{ 'first': 'Bruce', 'last': 'Lee' },
|
|
27
|
+
],
|
|
40
28
|
})
|
|
29
|
+
expect(util.parseFormData({ 'users[][\'name\']': 'Martin' })).rejects
|
|
30
|
+
.toEqual('Array items in bracket notation need array indexes "users[][\'name\']", e.g. users[0][name]')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('util > isId', async () => {
|
|
34
|
+
expect(util.isId('')).toEqual(false)
|
|
35
|
+
expect(util.isId(1234)).toEqual(false)
|
|
36
|
+
expect(util.isId('1234')).toEqual(false)
|
|
37
|
+
expect(util.isId('5ff50fe955da2c00170de734')).toEqual(true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('util > arrayWithSchema', async () => {
|
|
41
|
+
let res = monastery.prototype.arrayWithSchema([{ name: { type: 'string' }}], { minLength: 1 })
|
|
42
|
+
expect(res).toContainEqual({ name: { type: 'string' }})
|
|
43
|
+
expect(res.schema).toEqual({ minLength: 1 })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// --- ids ------------------------------
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
test('id > to string', () => {
|
|
50
|
+
const oid = util.id('4ee0fd75d6bd52107c000118')
|
|
51
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('id > id id string', () => {
|
|
55
|
+
const oid = util.id(util.id('4ee0fd75d6bd52107c000118'))
|
|
56
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('id > new', () => {
|
|
60
|
+
const oid = util.id()
|
|
61
|
+
expect(typeof oid.toHexString()).toBe('string')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// --- cast -----------------------------
|
|
65
|
+
|
|
66
|
+
test('cast > should cast ids inside $and', () => {
|
|
67
|
+
const cast = util.cast({ $and: [{ _id: '4ee0fd75d6bd52107c000118' }] })
|
|
68
|
+
const oid = util.id(cast.$and[0]._id)
|
|
69
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('cast > should cast ids inside $nor', () => {
|
|
73
|
+
const cast = util.cast({ $nor: [{ _id: '4ee0fd75d6bd52107c000118' }] })
|
|
74
|
+
const oid = util.id(cast.$nor[0]._id)
|
|
75
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('cast > should cast ids inside $not queries', () => {
|
|
79
|
+
const cast = util.cast({ $not: { _id: '4ee0fd75d6bd52107c000118' } })
|
|
80
|
+
const oid = util.id(cast.$not._id)
|
|
81
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('cast > should cast ids inside $ne queries', () => {
|
|
85
|
+
const cast = util.cast({ _id: { $ne: '4ee0fd75d6bd52107c000118' } })
|
|
86
|
+
const oid = util.id(cast._id.$ne)
|
|
87
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('cast > should cast ids inside $in queries', () => {
|
|
91
|
+
const cast = util.cast({ _id: { $in: ['4ee0fd75d6bd52107c000118'] } })
|
|
92
|
+
const oid = util.id(cast._id.$in[0])
|
|
93
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('cast > should cast ids inside $nin queries', () => {
|
|
97
|
+
const cast = util.cast({ _id: { $nin: ['4ee0fd75d6bd52107c000118'] } })
|
|
98
|
+
const oid = util.id(cast._id.$nin[0])
|
|
99
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('cast > should cast ids inside $set queries', () => {
|
|
103
|
+
const cast = util.cast({ $set: { _id: '4ee0fd75d6bd52107c000118' } })
|
|
104
|
+
const oid = util.id(cast.$set._id)
|
|
105
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('cast > should cast ids inside $or', () => {
|
|
109
|
+
const cast = util.cast({ $or: [{ _id: '4ee0fd75d6bd52107c000118' }] })
|
|
110
|
+
const oid = util.id(cast.$or[0]._id)
|
|
111
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('cast > should cast nested ids', () => {
|
|
115
|
+
const cast = util.cast({ $pull: { items: [{ _id: '4ee0fd75d6bd52107c000118' }] } })
|
|
116
|
+
const oid = util.id(cast.$pull.items[0]._id)
|
|
117
|
+
expect(oid.toHexString()).toBe('4ee0fd75d6bd52107c000118')
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('cast > should not fail when casting 0', () => {
|
|
121
|
+
const cast = util.cast(0)
|
|
122
|
+
expect(cast).toBe(0)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('cast > should not fail when casting null', () => {
|
|
126
|
+
const cast = util.cast(null)
|
|
127
|
+
expect(cast).toBe(null)
|
|
128
|
+
})
|
|
41
129
|
|
|
42
|
-
test('utilities arrayWithSchema', async () => {
|
|
43
|
-
let db = (await opendb(false)).db
|
|
44
|
-
let res = db.arrayWithSchema([{ name: { type: 'string' }}], { minLength: 1 })
|
|
45
|
-
expect(res).toContainEqual({ name: { type: 'string' }})
|
|
46
|
-
expect(res.schema).toEqual({ minLength: 1 })
|
|
47
|
-
})
|
|
48
130
|
|
|
49
|
-
}
|