Fix review comments
- Combine the various exported types; the only API surface is now the `PluginDatabaseClientFactory` which is a free function. - Rename to the SingleConnectionManager class. - Refactor the PluginEnvironment type to use databaseClientFactory for clarity. - Fix mergeDatabaseConfig to not override the input dictionary.
This commit is contained in:
@@ -29,8 +29,7 @@ import {
|
||||
getRootLogger,
|
||||
useHotMemoize,
|
||||
notFoundHandler,
|
||||
SingleDatabaseConfiguration,
|
||||
SingleDatabaseManager,
|
||||
SingleConnectionManager,
|
||||
SingleHostDiscovery,
|
||||
UrlReaders,
|
||||
} from '@backstage/backend-common';
|
||||
@@ -55,15 +54,14 @@ function makeCreateEnv(config: ConfigReader) {
|
||||
|
||||
root.info(`Created UrlReader ${reader}`);
|
||||
|
||||
const databaseConfig = new SingleDatabaseConfiguration(
|
||||
const databaseManager = new SingleConnectionManager(
|
||||
config.getConfig('backend.database'),
|
||||
);
|
||||
const databaseManager = new SingleDatabaseManager(databaseConfig);
|
||||
|
||||
return (plugin: string): PluginEnvironment => {
|
||||
const logger = root.child({ type: 'plugin', plugin });
|
||||
const databaseFactory = databaseManager.getDatabaseFactory(plugin);
|
||||
return { logger, database: databaseFactory, config, reader, discovery };
|
||||
const databaseFactory = databaseManager.getDatabaseClientFactory(plugin);
|
||||
return { logger, databaseClientFactory: databaseFactory, config, reader, discovery };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,14 @@ import { PluginEnvironment } from '../types';
|
||||
|
||||
export default async function createPlugin({
|
||||
logger,
|
||||
database,
|
||||
databaseClientFactory,
|
||||
config,
|
||||
discovery,
|
||||
}: PluginEnvironment) {
|
||||
return await createRouter({ logger, config, database, discovery });
|
||||
return await createRouter({
|
||||
logger,
|
||||
config,
|
||||
database: databaseClientFactory,
|
||||
discovery,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ export default async function createPlugin({
|
||||
logger,
|
||||
config,
|
||||
reader,
|
||||
database,
|
||||
databaseClientFactory,
|
||||
}: PluginEnvironment) {
|
||||
const locationReader = new LocationReaders({ logger, reader, config });
|
||||
|
||||
const db = await DatabaseManager.createDatabase(
|
||||
await database.getDatabase(),
|
||||
await databaseClientFactory(),
|
||||
{ logger },
|
||||
);
|
||||
const entitiesCatalog = new DatabaseEntitiesCatalog(db);
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
PluginDatabaseFactory,
|
||||
PluginDatabaseClientFactory,
|
||||
PluginEndpointDiscovery,
|
||||
UrlReader
|
||||
} from '@backstage/backend-common';
|
||||
|
||||
export type PluginEnvironment = {
|
||||
logger: Logger;
|
||||
database: PluginDatabaseFactory;
|
||||
databaseClientFactory: PluginDatabaseClientFactory;
|
||||
config: Config;
|
||||
reader: UrlReader;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
|
||||
Reference in New Issue
Block a user