backend-common: inline plugin database deps type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -234,7 +234,10 @@ export class Contexts {
|
||||
export function createDatabaseClient(
|
||||
dbConfig: Config,
|
||||
overrides?: Partial<Knex.Config>,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
): Knex<any, any[]>;
|
||||
|
||||
// @public
|
||||
@@ -257,7 +260,10 @@ export function createStatusCheckRouter(options: {
|
||||
export class DatabaseManager {
|
||||
forPlugin(
|
||||
pluginId: string,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
): PluginDatabaseManager;
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
@@ -577,12 +583,6 @@ export function notFoundHandler(): RequestHandler;
|
||||
|
||||
export { PluginCacheManager };
|
||||
|
||||
// @public
|
||||
export type PluginDatabaseDependencies = {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
};
|
||||
|
||||
export { PluginDatabaseManager };
|
||||
|
||||
export { PluginEndpointDiscovery };
|
||||
|
||||
@@ -27,9 +27,13 @@ import {
|
||||
ensureSchemaExists,
|
||||
normalizeConnection,
|
||||
} from './connection';
|
||||
import { PluginDatabaseDependencies, PluginDatabaseManager } from './types';
|
||||
import { PluginDatabaseManager } from './types';
|
||||
import path from 'path';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
LifecycleService,
|
||||
LoggerService,
|
||||
PluginMetadataService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { stringifyError } from '@backstage/errors';
|
||||
|
||||
/**
|
||||
@@ -96,7 +100,10 @@ export class DatabaseManager {
|
||||
*/
|
||||
forPlugin(
|
||||
pluginId: string,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
): PluginDatabaseManager {
|
||||
const _this = this;
|
||||
|
||||
@@ -312,7 +319,10 @@ export class DatabaseManager {
|
||||
*/
|
||||
private async getDatabase(
|
||||
pluginId: string,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
): Promise<Knex> {
|
||||
if (this.databaseCache.has(pluginId)) {
|
||||
return this.databaseCache.get(pluginId)!;
|
||||
|
||||
@@ -19,9 +19,13 @@ import { JsonObject } from '@backstage/types';
|
||||
import { InputError } from '@backstage/errors';
|
||||
import knexFactory, { Knex } from 'knex';
|
||||
import { mergeDatabaseConfig } from './config';
|
||||
import { DatabaseConnector, PluginDatabaseDependencies } from './types';
|
||||
import { DatabaseConnector } from './types';
|
||||
|
||||
import { mysqlConnector, pgConnector, sqlite3Connector } from './connectors';
|
||||
import {
|
||||
LifecycleService,
|
||||
PluginMetadataService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
type DatabaseClient =
|
||||
| 'pg'
|
||||
@@ -55,7 +59,10 @@ const ConnectorMapping: Record<DatabaseClient, DatabaseConnector> = {
|
||||
export function createDatabaseClient(
|
||||
dbConfig: Config,
|
||||
overrides?: Partial<Knex.Config>,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
) {
|
||||
const client: DatabaseClient = dbConfig.getString('client');
|
||||
|
||||
|
||||
@@ -20,7 +20,11 @@ import knexFactory, { Knex } from 'knex';
|
||||
import path from 'path';
|
||||
import { DevDataStore } from '@backstage/backend-dev-utils';
|
||||
import { mergeDatabaseConfig } from '../config';
|
||||
import { DatabaseConnector, PluginDatabaseDependencies } from '../types';
|
||||
import { DatabaseConnector } from '../types';
|
||||
import {
|
||||
LifecycleService,
|
||||
PluginMetadataService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Creates a knex SQLite3 database connection
|
||||
@@ -31,7 +35,10 @@ import { DatabaseConnector, PluginDatabaseDependencies } from '../types';
|
||||
export function createSqliteDatabaseClient(
|
||||
dbConfig: Config,
|
||||
overrides?: Knex.Config,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
) {
|
||||
const knexConfig = buildSqliteDatabaseConfig(dbConfig, overrides);
|
||||
const connConfig = knexConfig.connection as Knex.Sqlite3ConnectionConfig;
|
||||
|
||||
@@ -22,8 +22,5 @@ export * from './DatabaseManager';
|
||||
*/
|
||||
export { createDatabaseClient, ensureDatabaseExists } from './connection';
|
||||
|
||||
export type {
|
||||
PluginDatabaseManager,
|
||||
PluginDatabaseDependencies,
|
||||
} from './types';
|
||||
export type { PluginDatabaseManager } from './types';
|
||||
export { isDatabaseConflictError } from './util';
|
||||
|
||||
@@ -23,16 +23,6 @@ import { Knex } from 'knex';
|
||||
|
||||
export type { DatabaseService as PluginDatabaseManager } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Service dependencies for `PluginDatabaseManager`.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type PluginDatabaseDependencies = {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
};
|
||||
|
||||
/**
|
||||
* DatabaseConnector manages an underlying Knex database driver.
|
||||
*/
|
||||
@@ -43,7 +33,10 @@ export interface DatabaseConnector {
|
||||
createClient(
|
||||
dbConfig: Config,
|
||||
overrides?: Partial<Knex.Config>,
|
||||
deps?: PluginDatabaseDependencies,
|
||||
deps?: {
|
||||
lifecycle: LifecycleService;
|
||||
pluginMetadata: PluginMetadataService;
|
||||
},
|
||||
): Knex;
|
||||
/**
|
||||
* createNameOverride provides a partial knex config sufficient to override a
|
||||
|
||||
Reference in New Issue
Block a user