-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(instance-model, database-model, collection-model): Refactor ins…
…tance db coll models COMPASS-5208 COMPASS-5209 COMPASS-5210 (#2558) * chore(collection-model, database-model, instance-model): Update mocha and eslint * refactor(mongodb-data-service): Change and provide new methods for databases/collections info fetching - Remove db/coll fetching from instance method - Add databaseStats public method to fetch dbStats - Add listCollectionsNamesOnly that safely fetches collection names with priviliges fallback - Add collectionInfo method that gets coll info for a single collection from listCollections - Allow nameOnly option in listDatabases * chore(compass-schema-validation): Refactor schema-validation to use new dataService.collectionInfo method * feat(collection-model): Add fetch method to the collection model and collection so it can handle it's own data loading * feat(database-model): Add fetch method to the database model and collection so it can handle it's own data loading * refactor(instance-model): Refactor instance fetch method * refactor(compass-app-stores): Refactor instance store to use new instance/db/coll fetch methods * fix(compass-home): Do not show overlay from compass-home It races with the one in app-stores plugin, no need for that * refactor(compass-sidebar): Refactor sidebar instance state handling to match new app-stores behaviour, update mocks in tests * chore: Update package-lock * chore: Address review feedback - Use async methods in data-service instead of callbacks - Rename extended-model to model * chore(sidebar): Destruct arguments * chore: Mention relevant NODE ticket * test(data-service): Don't forget to call done in tests * test(instance-model): Update instance method mock * test(app-stores): Update instance method mock
- Loading branch information
1 parent
a8d8731
commit c0f3789
Showing
56 changed files
with
2,235 additions
and
4,224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
ignores: [ | ||
"lodash.result", | ||
"electron" | ||
] | ||
ignores: ['@mongodb-js/prettier-config-compass'] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['@mongodb-js/eslint-config-compass'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@mongodb-js/prettier-config-compass" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var ExtendedCollectionModel = require('./lib/extended-model'); | ||
var ExtendedCollectionModelCollection = require('./lib/extended-model').Collection; | ||
var ExtendedCollectionModel = require('./lib/model'); | ||
var ExtendedCollectionModelCollection = require('./lib/model').Collection; | ||
|
||
module.exports = ExtendedCollectionModel; | ||
module.exports.Collection = ExtendedCollectionModelCollection; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const AmpersandModel = require('ampersand-model'); | ||
const AmpersandCollection = require('ampersand-collection'); | ||
const { promisify } = require('util'); | ||
const toNs = require('mongodb-ns'); | ||
|
||
const CollectionModel = AmpersandModel.extend({ | ||
modelType: 'Collection', | ||
idAttribute: '_id', | ||
props: { | ||
_id: 'string', | ||
|
||
// Normalized values from listCollections command | ||
name: { type: 'string', required: true }, | ||
database: { type: 'string', required: true }, | ||
type: { type: 'string', required: true }, | ||
system: { type: 'boolean', required: true }, | ||
oplog: { type: 'boolean', required: true }, | ||
command: { type: 'boolean', required: true }, | ||
special: { type: 'boolean', required: true }, | ||
specialish: { type: 'boolean', required: true }, | ||
normal: { type: 'boolean', required: true }, | ||
readonly: 'boolean', | ||
collation: 'object', | ||
pipeline: 'array', | ||
validation: 'object', | ||
|
||
// Normalized values from collStats command | ||
ns: 'string', | ||
is_capped: 'boolean', | ||
max: 'number', | ||
is_power_of_two: 'boolean', | ||
index_sizes: 'object', | ||
document_count: 'number', | ||
document_size: 'number', | ||
storage_size: 'number', | ||
index_count: 'number', | ||
index_size: 'number', | ||
padding_factor: 'number', | ||
extent_count: 'number', | ||
extent_last_size: 'number', | ||
flags_user: 'number', | ||
max_document_size: 'number', | ||
size: 'number', | ||
index_details: 'object', | ||
wired_tiger: 'object', | ||
}, | ||
/** | ||
* @param {{ dataService: import('mongodb-data-service').DataService }} dataService | ||
* @returns | ||
*/ | ||
async fetch({ dataService }) { | ||
const collectionStatsAsync = promisify( | ||
dataService.collectionStats.bind(dataService) | ||
); | ||
const [collStats, collectionInfo] = await Promise.all([ | ||
collectionStatsAsync(this.getId()), | ||
dataService.collectionInfo(this.database, this.name), | ||
]); | ||
return this.set({ ...collStats, ...collectionInfo }); | ||
}, | ||
}); | ||
|
||
const CollectionCollection = AmpersandCollection.extend({ | ||
modelType: 'CollectionCollection', | ||
mainIndex: '_id', | ||
indexes: ['name'], | ||
comparator: '_id', | ||
model: CollectionModel, | ||
/** | ||
* @param {{ dataService: import('mongodb-data-service').DataService }} dataService | ||
* @returns | ||
*/ | ||
fetch({ dataService }) { | ||
return new Promise((resolve, reject) => { | ||
const databaseName = this.parent && this.parent.getId(); | ||
|
||
if (!databaseName) { | ||
throw new Error( | ||
"Trying to fetch MongoDBCollectionCollection that doesn't have the parent model" | ||
); | ||
} | ||
|
||
dataService.listCollectionsNamesOnly(databaseName, (err, collections) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve( | ||
this.set( | ||
collections.filter((coll) => { | ||
// TODO: This is not the best place to do this kind of | ||
// filtering, but for now this preserves the current behavior | ||
// and changing it right away will expand the scope of the | ||
// refactor significantly. We can address this in COMPASS-5211 | ||
return toNs(`${databaseName}.${coll.name}`).system === false; | ||
}) | ||
) | ||
); | ||
}); | ||
}); | ||
}, | ||
}); | ||
|
||
module.exports = CollectionModel; | ||
module.exports.Collection = CollectionCollection; |
Oops, something went wrong.