monastery 3.4.2 → 3.5.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/model.js CHANGED
@@ -3,11 +3,11 @@ const Model = require('../lib/model.js')
3
3
  const monastery = require('../lib/index.js')
4
4
 
5
5
  let db
6
- beforeAll(async () => { db = monastery('127.0.0.1/monastery') })
6
+ beforeAll(async () => { db = monastery.manager('127.0.0.1/monastery') })
7
7
  afterAll(async () => { db.close() })
8
8
 
9
9
  test('model > model on manager', async () => {
10
- const db2 = monastery('127.0.0.1', { logLevel: 0 })
10
+ const db2 = monastery.manager('127.0.0.1', { logLevel: 0 })
11
11
  db2.model('user', { fields: {} })
12
12
  let modelNamedConflict = db2.model('open', { fields: {} })
13
13
 
@@ -132,7 +132,7 @@ test('model setup basics', async () => {
132
132
  })
133
133
 
134
134
  test('model setup with default objects', async () => {
135
- const db2 = monastery('127.0.0.1/monastery', { defaultObjects: true })
135
+ const db2 = monastery.manager('127.0.0.1/monastery', { defaultObjects: true })
136
136
  let user = db2.model('user', { fields: {
137
137
  name: { type: 'string' },
138
138
  pets: [{ type: 'string' }],
@@ -376,7 +376,7 @@ test('model setup with messages', async () => {
376
376
 
377
377
  test('model setup with reserved and invalid rules', async () => {
378
378
  // Setup
379
- const db2 = monastery('127.0.0.1/monastery', { logLevel: 0 })
379
+ const db2 = monastery.manager('127.0.0.1/monastery', { logLevel: 0 })
380
380
  let user = db2.model('user-model', {
381
381
  fields: {
382
382
  name: {
@@ -449,12 +449,11 @@ test('model indexes basic', async () => {
449
449
 
450
450
  // Unique & text index
451
451
  let userIndexModel = await db.model('userIndex', {
452
- waitForIndexes: true,
453
452
  fields: {
454
453
  email: { type: 'string', index: 'unique' },
455
454
  name: { type: 'string', index: 'text' },
456
455
  },
457
- })
456
+ }, { waitForIndexes: true })
458
457
 
459
458
  let userIndexModelIndexes = await db.db.collection('userIndex').indexes()
460
459
  expect(userIndexModelIndexes[0]).toEqual({
@@ -504,7 +503,6 @@ test('model indexes unique', async () => {
504
503
 
505
504
  // Partial unique indexes (allows mulitple null values)
506
505
  await db.model('userUniqueIndex', {
507
- waitForIndexes: true,
508
506
  fields: {
509
507
  email: {
510
508
  type: 'string',
@@ -516,7 +514,7 @@ test('model indexes unique', async () => {
516
514
  },
517
515
  },
518
516
  },
519
- })
517
+ }, { waitForIndexes: true })
520
518
 
521
519
  let indexes2 = await db.db.collection('userUniqueIndex').indexes()
522
520
  expect(indexes2[0]).toEqual({
@@ -648,7 +646,6 @@ test('model indexes 2dsphere', async () => {
648
646
  // Setup. The tested model needs to be unique as race condition issue arises when the same model
649
647
  // with text indexes are setup at the same time
650
648
  await db.model('user99', {
651
- waitForIndexes: true,
652
649
  fields: {
653
650
  location: {
654
651
  index: '2dsphere',
@@ -661,7 +658,7 @@ test('model indexes 2dsphere', async () => {
661
658
  coordinates: [{ type: 'number' }], // lat, lng
662
659
  },
663
660
  },
664
- })
661
+ }, { waitForIndexes: true })
665
662
 
666
663
  // Schema check
667
664
  expect(db.user99.fields.location).toEqual({
@@ -7,14 +7,14 @@ const imagePluginFakeOpts = { awsBucket: 'fake', awsRegion: 'fake', awsAccessKey
7
7
  let db
8
8
  afterAll(async () => { db.close() })
9
9
  beforeAll(async () => {
10
- db = monastery('127.0.0.1/monastery', {
10
+ db = monastery.manager('127.0.0.1/monastery', {
11
11
  timestamps: false,
12
12
  imagePlugin: imagePluginFakeOpts,
13
13
  })
14
14
  })
15
15
 
16
16
  test('images no initialisation', async () => {
17
- const db2 = monastery('127.0.0.1/monastery', { timestamps: false })
17
+ const db2 = monastery.manager('127.0.0.1/monastery', { timestamps: false })
18
18
  db2.model('company', {
19
19
  fields: {
20
20
  logo: { type: 'image' },
@@ -666,7 +666,7 @@ test('images option defaults', async () => {
666
666
  })
667
667
 
668
668
  test('images options formats & filesizes', async () => {
669
- const db3 = monastery('127.0.0.1/monastery', {
669
+ const db3 = monastery.manager('127.0.0.1/monastery', {
670
670
  timestamps: false,
671
671
  imagePlugin: {
672
672
  ...imagePluginFakeOpts,
@@ -745,7 +745,7 @@ test('images options formats & filesizes', async () => {
745
745
 
746
746
  test('images option getSignedUrls', async () => {
747
747
  // latest (2022.02)
748
- const db3 = monastery('127.0.0.1/monastery', {
748
+ const db3 = monastery.manager('127.0.0.1/monastery', {
749
749
  timestamps: false,
750
750
  imagePlugin: {
751
751
  ...imagePluginFakeOpts,
@@ -778,32 +778,31 @@ test('images option getSignedUrls', async () => {
778
778
  })
779
779
 
780
780
  // Find signed URL via query option
781
- // await expect(db3.user.findOne({ query: userInserted._id, getSignedUrls: true })).resolves.toEqual({
782
- // _id: expect.any(Object),
783
- // photos: [imageWithSignedUrl, imageWithSignedUrl],
784
- // photos2: [imageWithSignedUrl, imageWithSignedUrl],
785
- // })
786
-
787
- // // Find signed URL via schema option
788
- // await expect(db3.user.findOne({ query: userInserted._id })).resolves.toEqual({
789
- // _id: expect.any(Object),
790
- // photos: [image, image],
791
- // photos2: [imageWithSignedUrl, imageWithSignedUrl],
792
- // })
781
+ await expect(db3.user.findOne({ query: userInserted._id, getSignedUrls: true })).resolves.toEqual({
782
+ _id: expect.any(Object),
783
+ photos: [imageWithSignedUrl, imageWithSignedUrl],
784
+ photos2: [imageWithSignedUrl, imageWithSignedUrl],
785
+ })
786
+
787
+ // Find signed URL via schema option
788
+ await expect(db3.user.findOne({ query: userInserted._id })).resolves.toEqual({
789
+ _id: expect.any(Object),
790
+ photos: [image, image],
791
+ photos2: [imageWithSignedUrl, imageWithSignedUrl],
792
+ })
793
793
 
794
794
  // Works with _processAfterFind
795
795
  let rawUser = await db3.user._findOne({ _id: userInserted._id })
796
- db3.user._processAfterFind(rawUser)
797
- // await expect(db3.user._processAfterFind(rawUser)).resolves.toEqual({
798
- // _id: expect.any(Object),
799
- // photos: [image, image],
800
- // photos2: [imageWithSignedUrl, imageWithSignedUrl],
801
- // })
796
+ await expect(db3.user._processAfterFind(rawUser)).resolves.toEqual({
797
+ _id: expect.any(Object),
798
+ photos: [image, image],
799
+ photos2: [imageWithSignedUrl, imageWithSignedUrl],
800
+ })
802
801
  db3.close()
803
802
  })
804
803
 
805
804
  test('images options awsAcl, awsBucket, metadata, params, path', async () => {
806
- const db3 = monastery('127.0.0.1/monastery', {
805
+ const db3 = monastery.manager('127.0.0.1/monastery', {
807
806
  timestamps: false,
808
807
  imagePlugin: {
809
808
  ...imagePluginFakeOpts,
@@ -903,7 +902,7 @@ test('images options awsAcl, awsBucket, metadata, params, path', async () => {
903
902
 
904
903
  test('images option depreciations', async () => {
905
904
  // testing (filename bucketDir)
906
- const db3 = monastery('127.0.0.1/monastery', {
905
+ const db3 = monastery.manager('127.0.0.1/monastery', {
907
906
  logLevel: 1,
908
907
  timestamps: false,
909
908
  imagePlugin: {
package/test/populate.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const monastery = require('../lib/index.js')
2
2
 
3
3
  let db
4
- beforeAll(async () => { db = monastery('127.0.0.1/monastery', { timestamps: false }) })
4
+ beforeAll(async () => { db = monastery.manager('127.0.0.1/monastery', { timestamps: false }) })
5
5
  afterAll(async () => { db.close() })
6
6
 
7
7
  test('model populate', async () => {
package/test/util.js CHANGED
@@ -254,7 +254,7 @@ test('util > isId', async () => {
254
254
  expect(util.isId({})).toEqual(false)
255
255
  expect(util.isId(['5ff50fe955da2c00170de734'])).toEqual(false)
256
256
  expect(util.isId('5ff50fe955da2c00170de734')).toEqual(true)
257
- expect(util.isId(monastery.prototype.id())).toEqual(true)
257
+ expect(util.isId(monastery.id())).toEqual(true)
258
258
  })
259
259
 
260
260
  test('util > isHex24', async () => {
@@ -265,12 +265,12 @@ test('util > isHex24', async () => {
265
265
  expect(util.isHex24({})).toEqual(false)
266
266
  expect(util.isHex24(['5ff50fe955da2c00170de734'])).toEqual(false)
267
267
  expect(util.isHex24('5ff50fe955da2c00170de734')).toEqual(true)
268
- expect(util.isHex24(monastery.prototype.id())).toEqual(true)
268
+ expect(util.isHex24(monastery.id())).toEqual(true)
269
269
  })
270
270
 
271
271
 
272
272
  test('util > arrayWithSchema', async () => {
273
- let res = monastery.prototype.arrayWithSchema([{ name: { type: 'string' }}], { minLength: 1 })
273
+ let res = monastery.arrayWithSchema([{ name: { type: 'string' }}], { minLength: 1 })
274
274
  expect(res).toContainEqual({ name: { type: 'string' }})
275
275
  expect(res.schema).toEqual({ minLength: 1 })
276
276
  })
package/test/validate.js CHANGED
@@ -3,7 +3,7 @@ const monastery = require('../lib/index.js')
3
3
  const Model = require('../lib/model.js')
4
4
 
5
5
  let db
6
- beforeAll(async () => { db = monastery('127.0.0.1/monastery', { timestamps: false }) })
6
+ beforeAll(async () => { db = monastery.manager('127.0.0.1/monastery', { timestamps: false }) })
7
7
  afterAll(async () => { db.close() })
8
8
 
9
9
  test('validation basic errors', async () => {
@@ -171,7 +171,7 @@ test('validation type any', async () => {
171
171
  })
172
172
 
173
173
  test('validation schema with reserved and invalid rules', async () => {
174
- const db2 = monastery('127.0.0.1/monastery', { logLevel: 0 })
174
+ const db2 = monastery.manager('127.0.0.1/monastery', { logLevel: 0 })
175
175
  let user = db2.model('user-model', {
176
176
  fields: {
177
177
  sub: {
@@ -972,7 +972,7 @@ test('schema options default', async () => {
972
972
  })
973
973
 
974
974
  test('schema options objects', async () => {
975
- const db2 = monastery('127.0.0.1/monastery', { nullObjects: true, timestamps: false })
975
+ const db2 = monastery.manager('127.0.0.1/monastery', { nullObjects: true, timestamps: false })
976
976
  let user = db2.model('user', {
977
977
  fields: {
978
978
  location: {
@@ -998,7 +998,7 @@ test('schema options objects', async () => {
998
998
  })
999
999
 
1000
1000
  test('validate defaultObjects', async () => {
1001
- const db2 = monastery('127.0.0.1/monastery', { defaultObjects: true, timestamps: false })
1001
+ const db2 = monastery.manager('127.0.0.1/monastery', { defaultObjects: true, timestamps: false })
1002
1002
  // let base = { names: [], animals: { dogs: [] }}
1003
1003
  let user = db2.model('user', { fields: {
1004
1004
  name: { type: 'string' },
@@ -1018,7 +1018,7 @@ test('validate defaultObjects', async () => {
1018
1018
  })
1019
1019
 
1020
1020
  test('validate nullObjects', async () => {
1021
- const db2 = monastery('127.0.0.1/monastery', { nullObjects: true, timestamps: false })
1021
+ const db2 = monastery.manager('127.0.0.1/monastery', { nullObjects: true, timestamps: false })
1022
1022
  let user = db2.model('user', { fields: {
1023
1023
  names: [{ type: 'string' }],
1024
1024
  animals: {
package/test/virtuals.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const monastery = require('../lib/index.js')
2
2
 
3
3
  let db
4
- beforeAll(async () => { db = monastery('127.0.0.1/monastery', { timestamps: false }) })
4
+ beforeAll(async () => { db = monastery.manager('127.0.0.1/monastery', { timestamps: false }) })
5
5
  afterAll(async () => { db.close() })
6
6
 
7
7
  test('virtuals', async () => {