@@ -31,6 +31,16 @@ import type {
3131
3232const { log, mongoLogId } = createLoggerAndTelemetry ( 'CONNECTION-STORAGE' ) ;
3333
34+ type ConnectionLegacyProps = {
35+ _id : string ;
36+ isFavorite ?: boolean ;
37+ name : string ;
38+ } ;
39+
40+ type ConnectionWithLegacyProps = {
41+ connectionInfo : ConnectionInfo ;
42+ } & ConnectionLegacyProps ;
43+
3444export class ConnectionStorage {
3545 private static calledOnce : boolean ;
3646 private static path : string ;
@@ -102,7 +112,7 @@ export class ConnectionStorage {
102112 }
103113 }
104114
105- private static async getConnections ( ) : Promise < any [ ] > {
115+ private static async getConnections ( ) : Promise < ConnectionWithLegacyProps [ ] > {
106116 const connectionIds = ( await fs . readdir ( this . getFolderPath ( ) ) )
107117 . filter ( ( file ) => file . endsWith ( '.json' ) )
108118 . map ( ( file ) => file . replace ( '.json' , '' ) ) ;
@@ -167,11 +177,8 @@ export class ConnectionStorage {
167177 return (
168178 connections
169179 // Ignore legacy connections and make sure connection has a connection string.
170- . filter (
171- ( x : { connectionInfo ?: ConnectionInfo } ) =>
172- x . connectionInfo ?. connectionOptions ?. connectionString
173- )
174- . map ( ( { connectionInfo } : { connectionInfo : ConnectionInfo } ) =>
180+ . filter ( ( x ) => x . connectionInfo ?. connectionOptions ?. connectionString )
181+ . map ( ( { connectionInfo } ) =>
175182 this . mapStoredConnectionToConnectionInfo (
176183 connectionInfo ,
177184 secrets [ connectionInfo . id ]
@@ -210,11 +217,16 @@ export class ConnectionStorage {
210217 throw new Error ( 'Connection string is required.' ) ;
211218 }
212219
220+ // While saving connections, we also save `_id` property
221+ // in order to support the downgrade of Compass to a version
222+ // where we use storage-mixin. storage-mixin uses this prop
223+ // to map keytar credentials to the stored connection.
224+
213225 // While testing, we don't use keychain to store secrets
214226 if ( process . env . COMPASS_E2E_DISABLE_KEYCHAIN_USAGE === 'true' ) {
215227 await fs . writeFile (
216228 this . getFilePath ( connectionInfo . id ) ,
217- JSON . stringify ( { connectionInfo } , null , 2 ) ,
229+ JSON . stringify ( { connectionInfo, _id : connectionInfo . id } , null , 2 ) ,
218230 'utf-8'
219231 ) ;
220232 } else {
@@ -225,6 +237,7 @@ export class ConnectionStorage {
225237 JSON . stringify (
226238 {
227239 connectionInfo : connectionInfoWithoutSecrets ,
240+ _id : connectionInfo . id ,
228241 } ,
229242 null ,
230243 2
0 commit comments