monastery 1.36.2 → 1.36.3
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 +7 -0
- package/lib/util.js +13 -1
- package/package.json +1 -1
- package/test/crud.js +71 -0
- package/test/validate.js +7 -5
package/changelog.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.3](https://github.com/boycce/monastery/compare/1.36.2...1.36.3) (2022-05-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* order maintained when mixing of formData/dotNotation with normal key values ([898fa90](https://github.com/boycce/monastery/commit/898fa90a25e81ae1d2413e32ca67173fdef733a9))
|
|
11
|
+
|
|
5
12
|
### [1.36.2](https://github.com/boycce/monastery/compare/1.36.1...1.36.2) (2022-05-26)
|
|
6
13
|
|
|
7
14
|
|
package/lib/util.js
CHANGED
|
@@ -163,8 +163,15 @@ module.exports = {
|
|
|
163
163
|
* Mutates dot notation objects into a deep object
|
|
164
164
|
* @param {object}
|
|
165
165
|
*/
|
|
166
|
+
let original = this.deepCopy(obj)
|
|
166
167
|
for (let key in obj) {
|
|
167
|
-
if (key.indexOf('.') !== -1)
|
|
168
|
+
if (key.indexOf('.') !== -1) {
|
|
169
|
+
recurse(key, obj[key], obj)
|
|
170
|
+
} else {
|
|
171
|
+
// Ordinary values may of been updated by the bracket notation values, we are
|
|
172
|
+
// reassigning, trying to preserve the order of keys (not always guaranteed in for loops)
|
|
173
|
+
obj[key] = original[key]
|
|
174
|
+
}
|
|
168
175
|
}
|
|
169
176
|
return obj
|
|
170
177
|
function recurse(str, val, obj) {
|
|
@@ -188,6 +195,7 @@ module.exports = {
|
|
|
188
195
|
},
|
|
189
196
|
|
|
190
197
|
parseFormData: function(obj) {
|
|
198
|
+
let original = this.deepCopy(obj)
|
|
191
199
|
/**
|
|
192
200
|
* Mutates FormData (bracket notation) objects into a deep object
|
|
193
201
|
* @param {object}
|
|
@@ -203,6 +211,10 @@ module.exports = {
|
|
|
203
211
|
}
|
|
204
212
|
if (key.indexOf('[') !== -1) {
|
|
205
213
|
setup(key)
|
|
214
|
+
} else {
|
|
215
|
+
// Ordinary values may of been updated by the bracket notation values, we are
|
|
216
|
+
// reassigning, trying to preserve the order of keys (not always guaranteed in for loops)
|
|
217
|
+
obj[key] = original[key]
|
|
206
218
|
}
|
|
207
219
|
}
|
|
208
220
|
res(obj)
|
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.36.
|
|
5
|
+
"version": "1.36.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:boycce/monastery",
|
|
8
8
|
"homepage": "https://boycce.github.io/monastery/",
|
package/test/crud.js
CHANGED
|
@@ -309,6 +309,77 @@ module.exports = function(monastery, opendb) {
|
|
|
309
309
|
db.close()
|
|
310
310
|
})
|
|
311
311
|
|
|
312
|
+
test('update mixing formData', async() => {
|
|
313
|
+
// Mixing data
|
|
314
|
+
let db = (await opendb(null)).db
|
|
315
|
+
let consignment = db.model('consignment', {
|
|
316
|
+
fields: {
|
|
317
|
+
specialInstructions: [{
|
|
318
|
+
text: { type: 'string' },
|
|
319
|
+
createdAt: { type: 'date' },
|
|
320
|
+
updatedByName: { type: 'string' },
|
|
321
|
+
importance: { type: 'string' },
|
|
322
|
+
}],
|
|
323
|
+
},
|
|
324
|
+
})
|
|
325
|
+
let inserted = await consignment.insert({
|
|
326
|
+
data: {
|
|
327
|
+
specialInstructions: [{
|
|
328
|
+
text: 'filler',
|
|
329
|
+
createdAt: 1653601752472,
|
|
330
|
+
updatedByName: 'Paul',
|
|
331
|
+
importance: 'low'
|
|
332
|
+
}]
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
let specialInstructions = [
|
|
336
|
+
{
|
|
337
|
+
text: 'POD added by driver',
|
|
338
|
+
createdAt: 1653603212886,
|
|
339
|
+
updatedByName: 'Paul Driver 3',
|
|
340
|
+
importance: 'low'
|
|
341
|
+
}, {
|
|
342
|
+
text: 'filler',
|
|
343
|
+
createdAt: 1653601752472,
|
|
344
|
+
updatedByName: 'Paul',
|
|
345
|
+
importance: 'low'
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
// Key order maintained (not always guaranteed)
|
|
349
|
+
await consignment.update({
|
|
350
|
+
query: inserted._id,
|
|
351
|
+
data: {
|
|
352
|
+
'specialInstructions[0][text]': 'filler',
|
|
353
|
+
'specialInstructions[0][createdAt]': 1653601752472,
|
|
354
|
+
'specialInstructions[0][updatedByName]': 'Paul',
|
|
355
|
+
'specialInstructions[0][importance]': 'low',
|
|
356
|
+
specialInstructions: specialInstructions.map(o => ({ ...o })),
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
await expect(consignment.findOne({ query: inserted._id })).resolves.toEqual({
|
|
360
|
+
_id: expect.any(Object),
|
|
361
|
+
specialInstructions: specialInstructions,
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
// Key order maintained (not always guaranteed)
|
|
365
|
+
await consignment.update({
|
|
366
|
+
query: inserted._id,
|
|
367
|
+
data: {
|
|
368
|
+
specialInstructions: specialInstructions.map(o => ({ ...o })),
|
|
369
|
+
'specialInstructions[0][text]': 'filler',
|
|
370
|
+
'specialInstructions[0][createdAt]': 1653601752472,
|
|
371
|
+
'specialInstructions[0][updatedByName]': 'Paul',
|
|
372
|
+
'specialInstructions[0][importance]': 'low',
|
|
373
|
+
}
|
|
374
|
+
})
|
|
375
|
+
await expect(consignment.findOne({ query: inserted._id })).resolves.toEqual({
|
|
376
|
+
_id: expect.any(Object),
|
|
377
|
+
specialInstructions: [specialInstructions[1], specialInstructions[1]],
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
db.close()
|
|
381
|
+
})
|
|
382
|
+
|
|
312
383
|
test('insert with id casting', async () => {
|
|
313
384
|
let db = (await opendb(null)).db
|
|
314
385
|
db.model('company', { fields: {
|
package/test/validate.js
CHANGED
|
@@ -906,16 +906,18 @@ module.exports = function(monastery, opendb) {
|
|
|
906
906
|
},
|
|
907
907
|
},
|
|
908
908
|
})
|
|
909
|
-
|
|
910
|
-
// Subdocument data (null/string)
|
|
911
|
-
await expect(user.validate({ location: null })).rejects.toEqual([{
|
|
909
|
+
let requiredError = [{
|
|
912
910
|
'detail': 'This field is required.',
|
|
913
911
|
'meta': {'detailLong': undefined, 'field': 'location', 'model': 'user', 'rule': 'required'},
|
|
914
912
|
'status': '400',
|
|
915
913
|
'title': 'location'
|
|
916
|
-
}]
|
|
914
|
+
}]
|
|
915
|
+
// required errors
|
|
916
|
+
await expect(user.validate({ location: null })).rejects.toEqual(requiredError)
|
|
917
|
+
await expect(user.validate({ location: '' })).rejects.toEqual(requiredError)
|
|
918
|
+
await expect(user.validate({ location: undefined })).rejects.toEqual(requiredError)
|
|
919
|
+
// required no error
|
|
917
920
|
await expect(user.validate({ location: {} })).resolves.toEqual({ location: {} })
|
|
918
|
-
|
|
919
921
|
db.close()
|
|
920
922
|
})
|
|
921
923
|
|