@backstage/plugin-catalog-backend
Version:
The Backstage backend plugin that provides the Backstage catalog
48 lines (45 loc) • 1.24 kB
JavaScript
async function getOrphanedEntityProviderNames({
db,
providers
}) {
const dbProviderNames = await db.transaction(
async (tx) => db.listReferenceSourceKeys(tx)
);
const providerNames = providers.map((p) => p.getProviderName());
return dbProviderNames.filter(
(dbProviderName) => !providerNames.includes(dbProviderName)
);
}
async function removeEntitiesForProvider({
db,
providerName,
logger
}) {
try {
await db.transaction(async (tx) => {
await db.replaceUnprocessedEntities(tx, {
sourceKey: providerName,
type: "full",
items: []
});
});
logger.info(`Removed entities for orphaned provider ${providerName}`);
} catch (e) {
logger.error(
`Failed to remove entities for orphaned provider ${providerName}`,
e
);
}
}
async function evictEntitiesFromOrphanedProviders(options) {
for (const providerName of await getOrphanedEntityProviderNames(options)) {
await removeEntitiesForProvider({
db: options.db,
providerName,
logger: options.logger
});
}
}
exports.evictEntitiesFromOrphanedProviders = evictEntitiesFromOrphanedProviders;
//# sourceMappingURL=evictEntitiesFromOrphanedProviders.cjs.js.map
;