remove PluginDatabaseManager and PluginEndpointDiscovery

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-12-21 20:41:08 +01:00
parent d9d62ef90c
commit 8379bf4a80
25 changed files with 105 additions and 115 deletions
+12
View File
@@ -0,0 +1,12 @@
---
'@backstage/backend-dynamic-feature-service': patch
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/backend-defaults': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-auth-backend': patch
'@backstage/plugin-app-backend': patch
'@backstage/plugin-auth-node': patch
---
Remove usages of `PluginDatabaseManager` and `PluginEndpointDiscovery` and replace with their equivalent service types
@@ -28,7 +28,7 @@ import { Knex } from 'knex';
import { MysqlConnector } from './connectors/mysql';
import { PgConnector } from './connectors/postgres';
import { Sqlite3Connector } from './connectors/sqlite3';
import { Connector, PluginDatabaseManager } from './types';
import { Connector } from './types';
/**
* Provides a config lookup path for a plugin's config block.
@@ -72,7 +72,7 @@ export class DatabaseManagerImpl {
}
/**
* Generates a PluginDatabaseManager for consumption by plugins.
* Generates a DatabaseService for consumption by plugins.
*
* @param pluginId - The plugin that the database manager should be created for. Plugin names
* should be unique as they are used to look up database config overrides under
@@ -84,7 +84,7 @@ export class DatabaseManagerImpl {
logger: LoggerService;
lifecycle: LifecycleService;
},
): PluginDatabaseManager {
): DatabaseService {
const client = this.getClientType(pluginId).client;
const connector = this.connectors[client];
if (!connector) {
@@ -265,7 +265,7 @@ export class DatabaseManager {
private constructor(private readonly impl: DatabaseManagerImpl) {}
/**
* Generates a PluginDatabaseManager for consumption by plugins.
* Generates a DatabaseService for consumption by plugins.
*
* @param pluginId - The plugin that the database manager should be created for. Plugin names
* should be unique as they are used to look up database config overrides under
@@ -277,7 +277,7 @@ export class DatabaseManager {
logger: LoggerService;
lifecycle: LifecycleService;
},
): PluginDatabaseManager {
): DatabaseService {
return this.impl.forPlugin(pluginId, deps);
}
}
@@ -17,8 +17,6 @@
import { LifecycleService, LoggerService } from '@backstage/backend-plugin-api';
import { Knex } from 'knex';
export type { DatabaseService as PluginDatabaseManager } from '@backstage/backend-plugin-api';
export interface Connector {
getClient(
pluginId: string,
@@ -24,7 +24,7 @@ import { readHttpServerOptions } from '../rootHttpRouter/http/config';
type Target = string | { internal: string; external: string };
/**
* HostDiscovery is a basic PluginEndpointDiscovery implementation
* HostDiscovery is a basic DiscoveryService implementation
* that can handle plugins that are hosted in a single or multiple deployments.
*
* The deployment may be scaled horizontally, as long as the external URL
@@ -8,6 +8,8 @@ import { BackstagePackageJson } from '@backstage/cli-node';
import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
import { Config } from '@backstage/config';
import { ConfigSchema } from '@backstage/config-loader';
import { DatabaseService } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import { EventBroker } from '@backstage/plugin-events-node';
import { EventsBackend } from '@backstage/plugin-events-backend';
import { EventsService } from '@backstage/plugin-events-node';
@@ -22,8 +24,6 @@ import { PackageRole } from '@backstage/cli-node';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { PermissionPolicy } from '@backstage/plugin-permission-node';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { RootLoggerService } from '@backstage/backend-plugin-api';
import { Router } from 'express';
import { SchedulerService } from '@backstage/backend-plugin-api';
@@ -274,10 +274,10 @@ export interface LegacyBackendPluginInstaller {
export type LegacyPluginEnvironment = {
logger: Logger;
cache: PluginCacheManager;
database: PluginDatabaseManager;
database: DatabaseService;
config: Config;
reader: UrlReaderService;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
permissions: PermissionEvaluator;
scheduler: SchedulerService;
@@ -16,12 +16,7 @@
import { Logger } from 'winston';
import { Config } from '@backstage/config';
import {
PluginCacheManager,
PluginDatabaseManager,
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { PluginCacheManager, TokenManager } from '@backstage/backend-common';
import { Router } from 'express';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
@@ -36,6 +31,8 @@ import {
UrlReaderService,
SchedulerService,
SchedulerServiceTaskRunner,
DatabaseService,
DiscoveryService,
} from '@backstage/backend-plugin-api';
import { PackagePlatform, PackageRole } from '@backstage/cli-node';
import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
@@ -60,10 +57,10 @@ import { ScannedPluginPackage } from '../scanner';
export type LegacyPluginEnvironment = {
logger: Logger;
cache: PluginCacheManager;
database: PluginDatabaseManager;
database: DatabaseService;
config: Config;
reader: UrlReaderService;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
permissions: PermissionEvaluator;
scheduler: SchedulerService;
+5 -8
View File
@@ -16,12 +16,7 @@
import { Logger } from 'winston';
import { Config } from '@backstage/config';
import {
PluginCacheManager,
PluginDatabaseManager,
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { PluginCacheManager, TokenManager } from '@backstage/backend-common';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { EventBroker, EventsService } from '@backstage/plugin-events-node';
@@ -29,15 +24,17 @@ import { SignalsService } from '@backstage/plugin-signals-node';
import {
UrlReaderService,
SchedulerService,
DatabaseService,
DiscoveryService,
} from '@backstage/backend-plugin-api';
export type PluginEnvironment = {
logger: Logger;
cache: PluginCacheManager;
database: PluginDatabaseManager;
database: DatabaseService;
config: Config;
reader: UrlReaderService;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
permissions: PermissionEvaluator;
scheduler: SchedulerService;
-1
View File
@@ -57,7 +57,6 @@
"test": "backstage-cli package test"
},
"dependencies": {
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/config-loader": "workspace:^",
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { PluginDatabaseManager } from '@backstage/backend-common';
import { Knex } from 'knex';
import { DateTime } from 'luxon';
import partition from 'lodash/partition';
import { StaticAsset, StaticAssetInput, StaticAssetProvider } from './types';
import {
DatabaseService,
LoggerService,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
@@ -38,7 +38,7 @@ interface StaticAssetRow {
/** @internal */
export interface StaticAssetsStoreOptions {
database: PluginDatabaseManager;
database: DatabaseService;
logger: LoggerService;
}
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { DatabaseManager } from '@backstage/backend-common';
import {
DatabaseManager,
PluginDatabaseManager,
} from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
DatabaseService,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
import { Knex } from 'knex';
@@ -32,10 +32,10 @@ const migrationsDir = resolvePackagePath(
* asked for, and runs migrations.
*/
export class AuthDatabase {
readonly #database: PluginDatabaseManager;
readonly #database: DatabaseService;
#promise: Promise<Knex> | undefined;
static create(database: PluginDatabaseManager): AuthDatabase {
static create(database: DatabaseService): AuthDatabase {
return new AuthDatabase(database);
}
@@ -60,7 +60,7 @@ export class AuthDatabase {
});
}
private constructor(database: PluginDatabaseManager) {
private constructor(database: DatabaseService) {
this.#database = database;
}
+3 -5
View File
@@ -14,12 +14,10 @@
* limitations under the License.
*/
import {
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { TokenManager } from '@backstage/backend-common';
import {
AuthService,
DiscoveryService,
HttpAuthService,
LoggerService,
} from '@backstage/backend-plugin-api';
@@ -47,7 +45,7 @@ export function bindProviderRouters(
baseUrl: string;
config: Config;
logger: LoggerService;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
auth: AuthService;
httpAuth: HttpAuthService;
tokenManager?: TokenManager;
+2 -2
View File
@@ -6,6 +6,7 @@
import { BackstageIdentityResponse as BackstageIdentityResponse_2 } from '@backstage/plugin-auth-node';
import { BackstageSignInResult as BackstageSignInResult_2 } from '@backstage/plugin-auth-node';
import { Config } from '@backstage/config';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import { Entity } from '@backstage/catalog-model';
import { EntityFilterQuery } from '@backstage/catalog-client';
import express from 'express';
@@ -13,7 +14,6 @@ import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import { JsonValue } from '@backstage/types';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { Profile } from 'passport';
import { Request as Request_2 } from 'express';
import { Response as Response_2 } from 'express';
@@ -265,7 +265,7 @@ export class IdentityClient {
// @public
export type IdentityClientOptions = {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
issuer?: string;
algorithms?: string[];
};
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import {
decodeProtectedHeader,
exportJWK,
@@ -27,6 +27,7 @@ import { v4 as uuid } from 'uuid';
import { DefaultIdentityClient } from './DefaultIdentityClient';
import { IdentityApiGetIdentityRequest } from './IdentityApi';
import { DiscoveryService } from '@backstage/backend-plugin-api';
interface AnyJWK extends Record<string, string> {
use: 'sig';
@@ -87,7 +88,7 @@ function jwtKid(jwt: string): string {
const server = setupServer();
const mockBaseUrl = 'http://backstage:9191/i-am-a-mock-base';
const discovery: PluginEndpointDiscovery = {
const discovery: DiscoveryService = {
async getBaseUrl() {
return mockBaseUrl;
},
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { AuthenticationError } from '@backstage/errors';
import {
createRemoteJWKSet,
@@ -28,6 +27,7 @@ import { GetKeyFunction } from 'jose/dist/types/types';
import { getBearerTokenFromAuthorizationHeader } from './getBearerTokenFromAuthorizationHeader';
import { IdentityApi, IdentityApiGetIdentityRequest } from './IdentityApi';
import { BackstageIdentityResponse } from '../types';
import { DiscoveryService } from '@backstage/backend-plugin-api';
const CLOCK_MARGIN_S = 10;
@@ -38,7 +38,7 @@ const CLOCK_MARGIN_S = 10;
* @public
*/
export type IdentityClientOptions = {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
issuer?: string;
/** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
@@ -54,7 +54,7 @@ export type IdentityClientOptions = {
* @public
*/
export class DefaultIdentityClient implements IdentityApi {
private readonly discovery: PluginEndpointDiscovery;
private readonly discovery: DiscoveryService;
private readonly issuer?: string;
private readonly algorithms?: string[];
private keyStore?: GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { registerMswTestHooks } from '@backstage/backend-test-utils';
import {
decodeProtectedHeader,
@@ -28,6 +27,7 @@ import { setupServer } from 'msw/node';
import { v4 as uuid } from 'uuid';
import { IdentityClient } from './IdentityClient';
import { DiscoveryService } from '@backstage/backend-plugin-api';
interface AnyJWK extends Record<string, string> {
use: 'sig';
@@ -88,7 +88,7 @@ function jwtKid(jwt: string): string {
const server = setupServer();
const mockBaseUrl = 'http://backstage:9191/i-am-a-mock-base';
const discovery: PluginEndpointDiscovery = {
const discovery: DiscoveryService = {
async getBaseUrl() {
return mockBaseUrl;
},
@@ -10,6 +10,7 @@ import { CatalogApi } from '@backstage/catalog-client';
import { CatalogProcessor } from '@backstage/plugin-catalog-node';
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node';
import { Config } from '@backstage/config';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-node';
import { EntityProviderConnection } from '@backstage/plugin-catalog-node';
@@ -21,7 +22,6 @@ import { GithubIntegrationConfig } from '@backstage/integration';
import { graphql } from '@octokit/graphql';
import { LocationSpec } from '@backstage/plugin-catalog-node';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { SchedulerService } from '@backstage/backend-plugin-api';
import { SchedulerServiceTaskRunner } from '@backstage/backend-plugin-api';
import { ScmIntegrationRegistry } from '@backstage/integration';
@@ -127,7 +127,7 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer {
// @public (undocumented)
export type GithubLocationAnalyzerOptions = {
config: Config;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager?: TokenManager;
auth?: AuthService;
githubCredentialsProvider?: GithubCredentialsProvider;
@@ -32,7 +32,6 @@ jest.mock('@octokit/rest', () => {
return { Octokit };
});
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { GithubLocationAnalyzer } from './GithubLocationAnalyzer';
import {
registerMswTestHooks,
@@ -40,26 +39,21 @@ import {
} from '@backstage/backend-test-utils';
import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';
import { ConfigReader } from '@backstage/config';
const server = setupServer();
describe('GithubLocationAnalyzer', () => {
const mockDiscoveryApi: jest.Mocked<PluginEndpointDiscovery> = {
getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'),
getExternalBaseUrl: jest.fn(),
};
const mockDiscovery = mockServices.discovery.mock({
getBaseUrl: async () => 'http://localhost:7007',
});
const mockAuthService = mockServices.auth.mock({
getPluginRequestToken: async () => ({ token: 'abc123' }),
});
const config = new ConfigReader({
integrations: {
github: [
{
host: 'h.com',
token: 't',
},
],
const config = mockServices.rootConfig({
data: {
integrations: {
github: [{ host: 'h.com', token: 't' }],
},
},
});
@@ -121,7 +115,7 @@ describe('GithubLocationAnalyzer', () => {
});
const analyzer = new GithubLocationAnalyzer({
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
auth: mockAuthService,
config,
});
@@ -148,7 +142,7 @@ describe('GithubLocationAnalyzer', () => {
});
const analyzer = new GithubLocationAnalyzer({
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
auth: mockAuthService,
config,
});
@@ -174,7 +168,7 @@ describe('GithubLocationAnalyzer', () => {
});
const analyzer = new GithubLocationAnalyzer({
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
auth: mockAuthService,
config,
});
@@ -29,18 +29,17 @@ import {
ScmLocationAnalyzer,
} from '@backstage/plugin-catalog-node';
import {
PluginEndpointDiscovery,
TokenManager,
createLegacyAuthAdapters,
} from '@backstage/backend-common';
import { Config } from '@backstage/config';
import { AuthService } from '@backstage/backend-plugin-api';
import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';
import { extname } from 'path';
/** @public */
export type GithubLocationAnalyzerOptions = {
config: Config;
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager?: TokenManager;
auth?: AuthService;
githubCredentialsProvider?: GithubCredentialsProvider;
+3 -4
View File
@@ -56,7 +56,6 @@ import { PlaceholderResolver as PlaceholderResolver_2 } from '@backstage/plugin-
import { PlaceholderResolverParams as PlaceholderResolverParams_2 } from '@backstage/plugin-catalog-node';
import { PlaceholderResolverRead as PlaceholderResolverRead_2 } from '@backstage/plugin-catalog-node';
import { PlaceholderResolverResolveUrl as PlaceholderResolverResolveUrl_2 } from '@backstage/plugin-catalog-node';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { Router } from 'express';
import { SchedulerService } from '@backstage/backend-plugin-api';
@@ -283,7 +282,7 @@ export function createRandomProcessingInterval(options: {
// @public @deprecated (undocumented)
export class DefaultCatalogCollator {
constructor(options: {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
locationTemplate?: string;
filter?: GetEntitiesRequest['filter'];
@@ -297,7 +296,7 @@ export class DefaultCatalogCollator {
// (undocumented)
protected readonly catalogClient: CatalogApi;
// (undocumented)
protected discovery: PluginEndpointDiscovery;
protected discovery: DiscoveryService;
// (undocumented)
execute(): Promise<CatalogEntityDocument[]>;
// (undocumented)
@@ -306,7 +305,7 @@ export class DefaultCatalogCollator {
static fromConfig(
_config: Config,
options: {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
filter?: GetEntitiesRequest['filter'];
},
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { TokenManager } from '@backstage/backend-common';
import {
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { registerMswTestHooks } from '@backstage/backend-test-utils';
mockServices,
registerMswTestHooks,
} from '@backstage/backend-test-utils';
import { Entity } from '@backstage/catalog-model';
import { DefaultCatalogCollator } from './DefaultCatalogCollator';
import { setupServer } from 'msw/node';
@@ -58,22 +58,20 @@ const expectedEntities: Entity[] = [
];
describe('DefaultCatalogCollator', () => {
let mockDiscoveryApi: jest.Mocked<PluginEndpointDiscovery>;
const mockDiscovery = mockServices.discovery.mock({
getBaseUrl: async () => 'http://localhost:7007',
});
let mockTokenManager: jest.Mocked<TokenManager>;
let collator: DefaultCatalogCollator;
registerMswTestHooks(server);
beforeAll(() => {
mockDiscoveryApi = {
getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'),
getExternalBaseUrl: jest.fn(),
};
mockTokenManager = {
getToken: jest.fn().mockResolvedValue({ token: '' }),
authenticate: jest.fn(),
};
collator = new DefaultCatalogCollator({
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
tokenManager: mockTokenManager,
});
});
@@ -98,7 +96,7 @@ describe('DefaultCatalogCollator', () => {
it('fetches from the configured catalog service', async () => {
const documents = await collator.execute();
expect(mockDiscoveryApi.getBaseUrl).toHaveBeenCalledWith('catalog');
expect(mockDiscovery.getBaseUrl).toHaveBeenCalledWith('catalog');
expect(documents).toHaveLength(expectedEntities.length);
});
@@ -133,7 +131,7 @@ describe('DefaultCatalogCollator', () => {
it('maps a returned entity with a custom locationTemplate', async () => {
// Provide an alternate location template.
collator = new DefaultCatalogCollator({
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
tokenManager: mockTokenManager,
locationTemplate: '/software/:name',
});
@@ -147,7 +145,7 @@ describe('DefaultCatalogCollator', () => {
it('allows filtering of the retrieved catalog entities', async () => {
// Provide an alternate location template.
collator = DefaultCatalogCollator.fromConfig(new ConfigReader({}), {
discovery: mockDiscoveryApi,
discovery: mockDiscovery,
tokenManager: mockTokenManager,
filter: {
kind: ['Foo', 'Bar'],
@@ -14,10 +14,7 @@
* limitations under the License.
*/
import {
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { TokenManager } from '@backstage/backend-common';
import {
Entity,
isUserEntity,
@@ -32,6 +29,7 @@ import {
import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common/alpha';
import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
import { Permission } from '@backstage/plugin-permission-common';
import { DiscoveryService } from '@backstage/backend-plugin-api';
/**
* @public
@@ -39,7 +37,7 @@ import { Permission } from '@backstage/plugin-permission-common';
* use `DefaultCatalogCollatorFactory` instead.
*/
export class DefaultCatalogCollator {
protected discovery: PluginEndpointDiscovery;
protected discovery: DiscoveryService;
protected locationTemplate: string;
protected filter?: GetEntitiesRequest['filter'];
protected readonly catalogClient: CatalogApi;
@@ -51,7 +49,7 @@ export class DefaultCatalogCollator {
static fromConfig(
_config: Config,
options: {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
filter?: GetEntitiesRequest['filter'];
},
@@ -62,7 +60,7 @@ export class DefaultCatalogCollator {
}
constructor(options: {
discovery: PluginEndpointDiscovery;
discovery: DiscoveryService;
tokenManager: TokenManager;
locationTemplate?: string;
filter?: GetEntitiesRequest['filter'];
+1 -2
View File
@@ -39,7 +39,6 @@ import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { PermissionRule } from '@backstage/plugin-permission-node';
import { PermissionRuleParams } from '@backstage/plugin-permission-common';
import { PermissionsService } from '@backstage/backend-plugin-api';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { RESOURCE_TYPE_SCAFFOLDER_ACTION } from '@backstage/plugin-scaffolder-common/alpha';
import { RESOURCE_TYPE_SCAFFOLDER_TEMPLATE } from '@backstage/plugin-scaffolder-common/alpha';
import { ScaffolderEntitiesProcessor as ScaffolderEntitiesProcessor_2 } from '@backstage/plugin-catalog-backend-module-scaffolder-entity-model';
@@ -520,7 +519,7 @@ export class DatabaseTaskStore implements TaskStore {
// @public
export type DatabaseTaskStoreOptions = {
database: PluginDatabaseManager | Knex;
database: DatabaseService | Knex;
events?: EventsService;
};
@@ -15,8 +15,10 @@
*/
import { JsonObject } from '@backstage/types';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import {
DatabaseService,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
import { ConflictError, NotFoundError } from '@backstage/errors';
import { Knex } from 'knex';
import { v4 as uuid } from 'uuid';
@@ -78,19 +80,19 @@ export type RawDbTaskEventRow = {
* @public
*/
export type DatabaseTaskStoreOptions = {
database: PluginDatabaseManager | Knex;
database: DatabaseService | Knex;
events?: EventsService;
};
/**
* Type guard to help DatabaseTaskStore understand when database is PluginDatabaseManager vs. when database is a Knex instance.
* Type guard to help DatabaseTaskStore understand when database is DatabaseService vs. when database is a Knex instance.
*
* * @public
*/
function isPluginDatabaseManager(
opt: PluginDatabaseManager | Knex,
): opt is PluginDatabaseManager {
return (opt as PluginDatabaseManager).getClient !== undefined;
function isDatabaseService(
opt: DatabaseService | Knex,
): opt is DatabaseService {
return (opt as DatabaseService).getClient !== undefined;
}
const parseSqlDateToIsoString = <T>(input: T): T | string => {
@@ -152,9 +154,9 @@ export class DatabaseTaskStore implements TaskStore {
}
private static async getClient(
database: PluginDatabaseManager | Knex,
database: DatabaseService | Knex,
): Promise<Knex> {
if (isPluginDatabaseManager(database)) {
if (isDatabaseService(database)) {
return database.getClient();
}
@@ -162,10 +164,10 @@ export class DatabaseTaskStore implements TaskStore {
}
private static async runMigrations(
database: PluginDatabaseManager | Knex,
database: DatabaseService | Knex,
client: Knex,
): Promise<void> {
if (!isPluginDatabaseManager(database)) {
if (!isDatabaseService(database)) {
await client.migrate.latest({
directory: migrationsDir,
});
@@ -17,7 +17,6 @@
import {
DatabaseManager,
loggerToWinstonLogger,
PluginDatabaseManager,
} from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
@@ -52,6 +51,7 @@ import { AutocompleteHandler } from '@backstage/plugin-scaffolder-node/alpha';
import { UrlReaders } from '@backstage/backend-defaults/urlReader';
import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils';
import { EventsService } from '@backstage/plugin-events-node';
import { DatabaseService } from '@backstage/backend-plugin-api';
const mockAccess = jest.fn();
@@ -68,7 +68,7 @@ jest.mock('fs-extra', () => ({
remove: jest.fn(),
}));
function createDatabase(): PluginDatabaseManager {
function createDatabase(): DatabaseService {
return DatabaseManager.fromConfig(
new ConfigReader({
backend: {
-1
View File
@@ -4809,7 +4809,6 @@ __metadata:
resolution: "@backstage/plugin-app-backend@workspace:plugins/app-backend"
dependencies:
"@backstage/backend-app-api": "workspace:^"
"@backstage/backend-common": ^0.25.0
"@backstage/backend-defaults": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"