monastery 1.32.5 → 1.35.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/test/crud.js CHANGED
@@ -391,7 +391,10 @@ module.exports = function(monastery, opendb) {
391
391
  expect(find1).toEqual({
392
392
  _id: inserted2._id,
393
393
  name: 'Martin Luther',
394
- addresses: [{ city: 'Frankfurt', country: 'Germany' }, { city: 'Christchurch', country: 'New Zealand' }],
394
+ addresses: [
395
+ { city: 'Frankfurt', country: 'Germany' },
396
+ { city: 'Christchurch', country: 'New Zealand' }
397
+ ],
395
398
  address: { country: 'Germany' },
396
399
  pet: { dog: { _id: inserted._id, name: 'Scruff', user: inserted2._id }},
397
400
  dogs: [{ _id: inserted._id, name: 'Scruff', user: inserted2._id }]
@@ -407,6 +410,7 @@ module.exports = function(monastery, opendb) {
407
410
  as: 'dogs'
408
411
  }],
409
412
  blacklist: ['address', 'addresses.country', 'dogs.name']
413
+ // ^ great test (address should cancel addresses if not stopping at the .)
410
414
  })
411
415
  expect(find2).toEqual({
412
416
  _id: inserted2._id,
package/test/model.js CHANGED
@@ -411,169 +411,4 @@ module.exports = function(monastery, opendb) {
411
411
  db.close()
412
412
  })
413
413
 
414
- test('model findBL findBLProject', async () => {
415
- let db = (await opendb(null)).db
416
- db.model('bird', { fields: {
417
- name: { type: 'string' }
418
- }})
419
- let user = db.model('user', {
420
- findBL: [
421
- 'pets.hiddenAge',
422
- 'animals.hiddenCat',
423
- 'hiddenDog',
424
- 'hiddenPets',
425
- 'hiddenList',
426
- 'deep.deep2.hiddenDeep3',
427
- 'hiddenDeeper',
428
- 'hiddenDeepModel',
429
- 'hiddenDeepModels'
430
- ],
431
- fields: {
432
- list: [{ type: 'number' }],
433
- pet: { type: 'string' },
434
- anyPet: { type: 'any' },
435
- pets: [{ name: { type: 'string'}, hiddenAge: { type: 'number'} }],
436
- animals: {
437
- dog: { type: 'string' },
438
- hiddenCat: { type: 'string' }
439
- },
440
- deep: {
441
- deep2: {
442
- hiddenDeep3: {
443
- deep4: { type: 'string' }
444
- }
445
- }
446
- },
447
- deepModel: {
448
- myBird: { model: 'bird' }
449
- },
450
- deepModel2: {
451
- myBird: { model: 'bird' }
452
- },
453
- hiddenDog: { type: 'string' },
454
- hiddenPets: [{
455
- name: { type: 'string'}
456
- }],
457
- hiddenList: [{ type: 'number'}],
458
- hiddenDeeper: {
459
- deeper2: {
460
- deeper3: {
461
- deeper4: { type: 'string' }
462
- }
463
- }
464
- },
465
- hiddenDeepModel: {
466
- myBird: { model: 'bird' }
467
- },
468
- hiddenDeepModels: [{ model: 'bird' }]
469
- }
470
- })
471
-
472
- // Test find whitelist
473
- // expect(user.fieldlist.filter(o => !user.findBL.includes(o))).toEqual([
474
- // 'list',
475
- // 'pet',
476
- // 'anyPet',
477
- // 'pets.name',
478
- // 'animals.dog',
479
- // 'deepModel.myBird',
480
- // 'deepModel2.myBird'
481
- // ])
482
-
483
- // Test findBLProject
484
- expect(user.findBLProject).toEqual({
485
- 'pets.hiddenAge': 0,
486
- 'animals.hiddenCat': 0,
487
- 'hiddenDog': 0,
488
- 'hiddenPets': 0,
489
- 'hiddenList': 0,
490
- 'deep.deep2.hiddenDeep3': 0,
491
- 'hiddenDeeper': 0,
492
- 'hiddenDeepModel': 0,
493
- 'hiddenDeepModels': 0
494
- })
495
-
496
- // Test inclusion of deep model blacklists
497
- var findBLProject = user._addDeepBlacklists(user.findBLProject, [
498
- 'deepModel.myBird',
499
- 'hiddenDeepModel.myBird',
500
- 'hiddenDeepModels',
501
- {
502
- // raw $lookup object
503
- as: 'deepModel2.myBird'
504
- }
505
- ])
506
- expect(findBLProject).toEqual({
507
- 'pets.hiddenAge': 0,
508
- 'animals.hiddenCat': 0,
509
- 'hiddenDog': 0,
510
- 'hiddenPets': 0,
511
- 'hiddenList': 0,
512
- 'deep.deep2.hiddenDeep3': 0,
513
- 'hiddenDeeper': 0,
514
- 'hiddenDeepModel': 0,
515
- 'hiddenDeepModels': 0,
516
- // Deep model blacklists
517
- 'deepModel.myBird.password': 0,
518
- 'deepModel2.myBird.password': 0
519
- })
520
-
521
- // Test whitelisting
522
- expect(user._addBlacklist(findBLProject, ['-pets', '-deep.deep2.hiddenDeep3'])).toEqual({
523
- // 'pets.hiddenAge': 0,
524
- // 'deep.deep2.hiddenDeep3': 0,
525
- 'animals.hiddenCat': 0,
526
- 'hiddenDog': 0,
527
- 'hiddenPets': 0,
528
- 'hiddenList': 0,
529
- 'hiddenDeeper': 0,
530
- 'hiddenDeepModel': 0,
531
- 'hiddenDeepModels': 0,
532
- // Deep model blacklists
533
- 'deepModel.myBird.password': 0,
534
- 'deepModel2.myBird.password': 0
535
- })
536
-
537
- // Test aggregate with projection exclusions. This is mainly to test how $lookup reacts
538
- let bird1 = await db.bird.insert({ data: { name: 'bird1' } })
539
- let bird2 = await db.bird.insert({ data: { name: 'bird2' } })
540
- let user1 = await db.user.insert({ data: {
541
- pet: 'carla',
542
- pets: [{ name: 'carla', hiddenAge: 12 }, { name: 'sparky', hiddenAge: 14 }],
543
- anyPet: { hi: 1234 },
544
- hiddenDeepModel: { myBird: bird1._id },
545
- hiddenDeepModels: [bird1._id, bird2._id]
546
- }})
547
- let res = await db.user._aggregate([
548
- { $match: { _id: user1._id } },
549
- { $lookup: {
550
- from: 'bird',
551
- localField: 'hiddenDeepModel.myBird',
552
- foreignField: '_id',
553
- as: 'hiddenDeepModel.myBird'
554
- }},
555
- { $lookup: {
556
- from: 'bird',
557
- localField: 'hiddenDeepModels',
558
- foreignField: '_id',
559
- as: 'hiddenDeepModels'
560
- }},
561
- { $project: {
562
- 'anyPet': 0,
563
- 'pets.hiddenAge': 0,
564
- 'hiddenDeepModel.myBird': 0,
565
- 'hiddenDeepModels.name': 0,
566
- }}
567
- ])
568
- expect(res[0]).toEqual({
569
- _id: user1._id,
570
- pet: 'carla',
571
- pets: [ { name: 'carla' }, { name: 'sparky' } ],
572
- hiddenDeepModel: {},
573
- hiddenDeepModels: [ { _id: bird1._id }, { _id: bird2._id } ]
574
- })
575
-
576
- db.close()
577
- })
578
-
579
414
  }
package/test/util.js CHANGED
@@ -39,4 +39,11 @@ module.exports = function(monastery, opendb) {
39
39
  expect(db.isId('5ff50fe955da2c00170de734')).toEqual(true)
40
40
  })
41
41
 
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
+
42
49
  }