@@ -58,7 +58,11 @@ import type {
5858 ConnectionFleOptions ,
5959 ConnectionOptions ,
6060} from './connection-options' ;
61- import type { InstanceDetails } from './instance-detail-helper' ;
61+ import type {
62+ CollectionDetails ,
63+ DatabaseDetails ,
64+ InstanceDetails ,
65+ } from './instance-detail-helper' ;
6266import {
6367 isNotAuthorized ,
6468 isNotSupportedPipelineStage ,
@@ -312,7 +316,7 @@ export interface DataService {
312316 | ConnectionStatusWithPrivileges [ 'authInfo' ] [ 'authenticatedUserPrivileges' ]
313317 | null ;
314318 }
315- ) : Promise < ReturnType < typeof adaptCollectionInfo > [ ] > ;
319+ ) : Promise < CollectionDetails [ ] > ;
316320
317321 /**
318322 * Returns normalized collection info provided by listCollection command for a
@@ -419,7 +423,7 @@ export interface DataService {
419423 roles ?:
420424 | ConnectionStatusWithPrivileges [ 'authInfo' ] [ 'authenticatedUserRoles' ]
421425 | null ;
422- } ) : Promise < { _id : string ; name : string } [ ] > ;
426+ } ) : Promise < Omit < DatabaseDetails , 'collections' > [ ] > ;
423427
424428 /**
425429 * Get the stats for a database.
@@ -1291,7 +1295,16 @@ class DataServiceImpl extends WithLogContext implements DataService {
12911295 | ConnectionStatusWithPrivileges [ 'authInfo' ] [ 'authenticatedUserPrivileges' ]
12921296 | null ;
12931297 } = { }
1294- ) : Promise < ReturnType < typeof adaptCollectionInfo > [ ] > {
1298+ ) : Promise < CollectionDetails [ ] > {
1299+ const listCollections = async ( ) => {
1300+ const colls = await this . _listCollections ( databaseName , filter , {
1301+ nameOnly,
1302+ } ) ;
1303+ return colls . map ( ( coll ) => ( {
1304+ ns_source : 'provisioned' as const ,
1305+ ...coll ,
1306+ } ) ) ;
1307+ } ;
12951308 const getCollectionsFromPrivileges = async ( ) => {
12961309 const databases = getPrivilegesByDatabaseAndCollection (
12971310 await this . _getPrivilegesOrFallback ( privileges ) ,
@@ -1307,11 +1320,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
13071320 // those registered as "real" collection names
13081321 Boolean
13091322 )
1310- . map ( ( name ) => ( { name } ) ) ;
1323+ . map ( ( name ) => ( { name, ns_source : 'privileges' as const } ) ) ;
13111324 } ;
13121325
13131326 const [ listedCollections , collectionsFromPrivileges ] = await Promise . all ( [
1314- this . _listCollections ( databaseName , filter , { nameOnly } ) ,
1327+ listCollections ( ) ,
13151328 // If the filter is not empty, we can't meaningfully derive collections
13161329 // from privileges and filter them as the criteria might include any key
13171330 // from the listCollections result object and there is no such info in
@@ -1325,7 +1338,10 @@ class DataServiceImpl extends WithLogContext implements DataService {
13251338 // if they were fetched successfully
13261339 [ ...collectionsFromPrivileges , ...listedCollections ] ,
13271340 'name'
1328- ) . map ( ( coll ) => adaptCollectionInfo ( { db : databaseName , ...coll } ) ) ;
1341+ ) . map ( ( coll ) => ( {
1342+ ns_source : coll . ns_source ,
1343+ ...adaptCollectionInfo ( { db : databaseName , ...coll } ) ,
1344+ } ) ) ;
13291345
13301346 return collections ;
13311347 }
@@ -1348,7 +1364,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
13481364 roles ?:
13491365 | ConnectionStatusWithPrivileges [ 'authInfo' ] [ 'authenticatedUserRoles' ]
13501366 | null ;
1351- } = { } ) : Promise < { _id : string ; name : string } [ ] > {
1367+ } = { } ) : Promise < Omit < DatabaseDetails , 'collections' > [ ] > {
13521368 const adminDb = this . _database ( 'admin' , 'CRUD' ) ;
13531369
13541370 const listDatabases = async ( ) => {
@@ -1363,7 +1379,10 @@ class DataServiceImpl extends WithLogContext implements DataService {
13631379 } ,
13641380 { enableUtf8Validation : false }
13651381 ) ;
1366- return databases ;
1382+ return databases . map ( ( x ) => ( {
1383+ ...x ,
1384+ ns_source : 'provisioned' as const ,
1385+ } ) ) ;
13671386 } catch ( err ) {
13681387 // Currently Compass should not fail if listDatabase failed for any
13691388 // possible reason to preserve current behavior. We probably want this
@@ -1395,7 +1414,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
13951414 // out
13961415 Boolean
13971416 )
1398- . map ( ( name ) => ( { name } ) ) ;
1417+ . map ( ( name ) => ( { name, ns_source : 'privileges' as const } ) ) ;
13991418 } ;
14001419
14011420 const getDatabasesFromRoles = async ( ) => {
@@ -1410,7 +1429,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
14101429 // have custom privileges that we can't currently fetch.
14111430 [ 'read' , 'readWrite' , 'dbAdmin' , 'dbOwner' ]
14121431 ) ;
1413- return databases . map ( ( name ) => ( { name } ) ) ;
1432+ return databases . map ( ( name ) => ( { name, ns_source : 'roles' as const } ) ) ;
14141433 } ;
14151434
14161435 const [ listedDatabases , databasesFromPrivileges , databasesFromRoles ] =
@@ -1426,7 +1445,12 @@ class DataServiceImpl extends WithLogContext implements DataService {
14261445 [ ...databasesFromRoles , ...databasesFromPrivileges , ...listedDatabases ] ,
14271446 'name'
14281447 ) . map ( ( db ) => {
1429- return { _id : db . name , name : db . name , ...adaptDatabaseInfo ( db ) } ;
1448+ return {
1449+ _id : db . name ,
1450+ name : db . name ,
1451+ ns_source : db . ns_source ,
1452+ ...adaptDatabaseInfo ( db ) ,
1453+ } ;
14301454 } ) ;
14311455
14321456 return databases ;
0 commit comments