@bedrock/account
Advanced tools
Comparing version 8.0.0 to 8.1.0
# bedrock-account ChangeLog | ||
## 8.1.0 - 2022-12-11 | ||
### Added | ||
- Add optional `explain` flag to `get()`. | ||
## 8.0.0 - 2022-04-29 | ||
@@ -4,0 +9,0 @@ |
@@ -176,6 +176,10 @@ /*! | ||
* @param {string} [options.email] - The email of the account to retrieve. | ||
* @param {boolean} [options.explain=false] - An optional explain boolean. | ||
* | ||
* @returns {Promise} Resolves to `{account, meta}`. | ||
* @returns {Promise | ExplainObject} - Returns a Promise that resolves to | ||
* the account record (`{account, meta}`) or an ExplainObject if | ||
* `explain=true`. | ||
*/ | ||
export async function get({id, email} = {}) { | ||
export async function get({id, email, explain} = {}) { | ||
assert.optionalString(id, 'id'); | ||
@@ -195,4 +199,13 @@ assert.optionalString(email, 'email'); | ||
const record = await database.collections.account.findOne( | ||
query, {projection: {_id: 0, account: 1, meta: 1}}); | ||
const projection = {_id: 0, account: 1, meta: 1}; | ||
const collection = database.collections.account; | ||
if(explain) { | ||
// 'find().limit(1)' is used here because 'findOne()' doesn't return a | ||
// cursor which allows the use of the explain function. | ||
const cursor = await collection.find(query, {projection}).limit(1); | ||
return cursor.explain('executionStats'); | ||
} | ||
const record = await collection.findOne(query, {projection}); | ||
if(!record) { | ||
@@ -199,0 +212,0 @@ throw new BedrockError( |
{ | ||
"name": "@bedrock/account", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "User accounts for Bedrock applications", |
@@ -131,2 +131,32 @@ /*! | ||
}); | ||
describe('Indexes', async () => { | ||
let accountId; | ||
// NOTE: the accounts collection is getting erased before each test | ||
// this allows for the creation of tokens using the same account info | ||
beforeEach(async () => { | ||
await helpers.prepareDatabase(mockData); | ||
accountId = mockData.accounts['alpha@example.com'].account.id; | ||
}); | ||
it(`is properly indexed for 'id'`, async () => { | ||
const { | ||
executionStats | ||
} = await brAccount.get({id: accountId, explain: true}); | ||
executionStats.nReturned.should.equal(1); | ||
executionStats.totalKeysExamined.should.equal(1); | ||
executionStats.totalDocsExamined.should.equal(1); | ||
executionStats.executionStages.inputStage.inputStage.inputStage.stage | ||
.should.equal('IXSCAN'); | ||
}); | ||
it(`is properly indexed for 'account.email'`, async () => { | ||
const { | ||
executionStats | ||
} = await brAccount.get({email: 'alpha@example.com', explain: true}); | ||
executionStats.nReturned.should.equal(1); | ||
executionStats.totalKeysExamined.should.equal(1); | ||
executionStats.totalDocsExamined.should.equal(1); | ||
executionStats.executionStages.inputStage.inputStage.inputStage.stage | ||
.should.equal('IXSCAN'); | ||
}); | ||
}); | ||
}); // end get API | ||
@@ -133,0 +163,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43207
765