diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 68d50911d6..2aecebdda7 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -596,7 +596,7 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { // Warning: (ae-missing-release-tag) "DatabaseLocationsCatalog" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export class DatabaseLocationsCatalog implements LocationsCatalog { constructor(database: Database); // (undocumented) @@ -1157,7 +1157,7 @@ export class LocationReaders implements LocationReader { // Warning: (ae-missing-release-tag) "LocationResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type LocationResponse = { data: Location_2; currentStatus: LocationUpdateStatus; @@ -1165,7 +1165,7 @@ export type LocationResponse = { // Warning: (ae-missing-release-tag) "LocationsCatalog" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type LocationsCatalog = { addLocation(location: Location_2): Promise; removeLocation(id: string): Promise; @@ -1220,7 +1220,7 @@ export interface LocationStore { // Warning: (ae-missing-release-tag) "LocationUpdateLogEvent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type LocationUpdateLogEvent = { id: string; status: 'fail' | 'success'; @@ -1232,7 +1232,7 @@ export type LocationUpdateLogEvent = { // Warning: (ae-missing-release-tag) "LocationUpdateStatus" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type LocationUpdateStatus = { timestamp: string | null; status: string | null; diff --git a/plugins/catalog-backend/src/catalog/index.ts b/plugins/catalog-backend/src/catalog/index.ts index f95d16a69f..7ac0150eef 100644 --- a/plugins/catalog-backend/src/catalog/index.ts +++ b/plugins/catalog-backend/src/catalog/index.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -export { DatabaseLocationsCatalog } from './DatabaseLocationsCatalog'; export type { EntitiesCatalog, EntitiesRequest, @@ -22,9 +21,5 @@ export type { EntityAncestryResponse, EntityUpsertRequest, EntityUpsertResponse, - LocationResponse, - LocationsCatalog, - LocationUpdateLogEvent, - LocationUpdateStatus, PageInfo, } from './types'; diff --git a/plugins/catalog-backend/src/catalog/types.ts b/plugins/catalog-backend/src/catalog/types.ts index 217e077434..cd2590a26b 100644 --- a/plugins/catalog-backend/src/catalog/types.ts +++ b/plugins/catalog-backend/src/catalog/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Entity, EntityRelationSpec, Location } from '@backstage/catalog-model'; +import { Entity, EntityRelationSpec } from '@backstage/catalog-model'; import { EntityFilter, EntityPagination } from '../database/types'; // @@ -41,11 +41,13 @@ export type EntitiesResponse = { pageInfo: PageInfo; }; +/** @deprecated This was part of the legacy catalog engine */ export type EntityUpsertRequest = { entity: Entity; relations: EntityRelationSpec[]; }; +/** @deprecated This was part of the legacy catalog engine */ export type EntityUpsertResponse = { entityId: string; entity?: Entity; @@ -79,12 +81,14 @@ export type EntitiesCatalog = { /** * Writes a number of entities efficiently to storage. * + * @deprecated This method was part of the legacy catalog engine an will be removed. + * * @param requests - The entities and their relations * @param options.locationId - The location that they all belong to (default none) * @param options.dryRun - Whether to throw away the results (default false) * @param options.outputEntities - Whether to return the resulting entities (default false) */ - batchAddOrUpdateEntities( + batchAddOrUpdateEntities?( requests: EntityUpsertRequest[], options?: { locationId?: string; @@ -100,44 +104,3 @@ export type EntitiesCatalog = { */ entityAncestry(entityRef: string): Promise; }; - -// -// Locations -// - -export type LocationUpdateStatus = { - timestamp: string | null; - status: string | null; - message: string | null; -}; - -export type LocationUpdateLogEvent = { - id: string; - status: 'fail' | 'success'; - location_id: string; - entity_name: string; - created_at?: string; - message?: string; -}; - -export type LocationResponse = { - data: Location; - currentStatus: LocationUpdateStatus; -}; - -export type LocationsCatalog = { - addLocation(location: Location): Promise; - removeLocation(id: string): Promise; - locations(): Promise; - location(id: string): Promise; - locationHistory(id: string): Promise; - logUpdateSuccess( - locationId: string, - entityName?: string | string[], - ): Promise; - logUpdateFailure( - locationId: string, - error?: Error, - entityName?: string, - ): Promise; -}; diff --git a/plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.test.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.test.ts similarity index 98% rename from plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.test.ts rename to plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.test.ts index 8bd8e86b8e..24bcc79db1 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.test.ts +++ b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DatabaseManager } from '../database'; +import { DatabaseManager } from '../../database'; import { DatabaseLocationsCatalog } from './DatabaseLocationsCatalog'; const bootstrapLocation = { diff --git a/plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts similarity index 94% rename from plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.ts rename to plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts index e81c72a3da..4e3b6975a4 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseLocationsCatalog.ts +++ b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts @@ -15,13 +15,14 @@ */ import { Location } from '@backstage/catalog-model'; -import type { Database } from '../database'; +import type { Database } from '../../database'; import { DatabaseLocationUpdateLogEvent, DatabaseLocationUpdateLogStatus, -} from '../database/types'; +} from '../../database/types'; import { LocationResponse, LocationsCatalog } from './types'; +/** @deprecated This was part of the legacy catalog engine */ export class DatabaseLocationsCatalog implements LocationsCatalog { constructor(private readonly database: Database) {} diff --git a/plugins/catalog-backend/src/legacy/catalog/index.ts b/plugins/catalog-backend/src/legacy/catalog/index.ts index 237eb4c08e..96828d03d1 100644 --- a/plugins/catalog-backend/src/legacy/catalog/index.ts +++ b/plugins/catalog-backend/src/legacy/catalog/index.ts @@ -15,3 +15,10 @@ */ export { DatabaseEntitiesCatalog } from './DatabaseEntitiesCatalog'; +export { DatabaseLocationsCatalog } from './DatabaseLocationsCatalog'; +export type { + LocationResponse, + LocationsCatalog, + LocationUpdateLogEvent, + LocationUpdateStatus, +} from './types'; diff --git a/plugins/catalog-backend/src/legacy/catalog/types.ts b/plugins/catalog-backend/src/legacy/catalog/types.ts new file mode 100644 index 0000000000..7ca1f3620a --- /dev/null +++ b/plugins/catalog-backend/src/legacy/catalog/types.ts @@ -0,0 +1,62 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Location } from '@backstage/catalog-model'; + +// +// Locations +// + +/** @deprecated This was part of the legacy catalog engine */ +export type LocationUpdateStatus = { + timestamp: string | null; + status: string | null; + message: string | null; +}; + +/** @deprecated This was part of the legacy catalog engine */ +export type LocationUpdateLogEvent = { + id: string; + status: 'fail' | 'success'; + location_id: string; + entity_name: string; + created_at?: string; + message?: string; +}; + +/** @deprecated This was part of the legacy catalog engine */ +export type LocationResponse = { + data: Location; + currentStatus: LocationUpdateStatus; +}; + +/** @deprecated This was part of the legacy catalog engine */ +export type LocationsCatalog = { + addLocation(location: Location): Promise; + removeLocation(id: string): Promise; + locations(): Promise; + location(id: string): Promise; + locationHistory(id: string): Promise; + logUpdateSuccess( + locationId: string, + entityName?: string | string[], + ): Promise; + logUpdateFailure( + locationId: string, + error?: Error, + entityName?: string, + ): Promise; +}; diff --git a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts index 3f7fccf024..5508b4d8a2 100644 --- a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts +++ b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts @@ -16,14 +16,15 @@ import { getVoidLogger } from '@backstage/backend-common'; import { Entity, Location, LocationSpec } from '@backstage/catalog-model'; -import { EntitiesCatalog, LocationsCatalog } from '../../catalog'; -import { LocationUpdateStatus } from '../../catalog/types'; +import { EntitiesCatalog } from '../../catalog'; +import { LocationsCatalog } from '../catalog'; +import { LocationUpdateStatus } from '../catalog/types'; import { DatabaseLocationUpdateLogStatus } from '../../database/types'; import { HigherOrderOperations } from './HigherOrderOperations'; import { LocationReader } from './types'; describe('HigherOrderOperations', () => { - let entitiesCatalog: jest.Mocked; + let entitiesCatalog: jest.Mocked>; let locationsCatalog: jest.Mocked; let locationReader: jest.Mocked; let higherOrderOperation: HigherOrderOperations; diff --git a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.ts b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.ts index 8d7ab6ff7c..9189b91fe8 100644 --- a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.ts +++ b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.ts @@ -21,7 +21,8 @@ import { } from '@backstage/catalog-model'; import { v4 as uuidv4 } from 'uuid'; import { Logger } from 'winston'; -import { EntitiesCatalog, LocationsCatalog } from '../../catalog'; +import { EntitiesCatalog } from '../../catalog'; +import { LocationsCatalog } from '../catalog'; import { durationText } from '../../util'; import { AddLocationResult, @@ -95,14 +96,12 @@ export class HigherOrderOperations implements HigherOrderOperation { return { location, entities: [] }; } - const writtenEntities = await this.entitiesCatalog.batchAddOrUpdateEntities( - readerOutput.entities, - { - locationId: dryRun ? undefined : location.id, - dryRun, - outputEntities: true, - }, - ); + const writtenEntities = await this.entitiesCatalog + .batchAddOrUpdateEntities!(readerOutput.entities, { + locationId: dryRun ? undefined : location.id, + dryRun, + outputEntities: true, + }); const entities = writtenEntities.map(e => e.entity!); @@ -186,7 +185,7 @@ export class HigherOrderOperations implements HigherOrderOperation { startTimestamp = process.hrtime(); try { - await this.entitiesCatalog.batchAddOrUpdateEntities( + await this.entitiesCatalog.batchAddOrUpdateEntities!( readerOutput.entities, { locationId: location.id }, ); diff --git a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts index c5b3281f9a..dee096ce7d 100644 --- a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts @@ -26,12 +26,12 @@ import { } from '@backstage/catalog-model'; import { ScmIntegrations } from '@backstage/integration'; import lodash from 'lodash'; +import { EntitiesCatalog } from '../../catalog'; import { + DatabaseEntitiesCatalog, DatabaseLocationsCatalog, - EntitiesCatalog, LocationsCatalog, -} from '../../catalog'; -import { DatabaseEntitiesCatalog } from '../catalog'; +} from '../catalog'; import { DatabaseManager } from '../../database'; import { AnnotateLocationEntityProcessor, diff --git a/plugins/catalog-backend/src/legacy/service/router.test.ts b/plugins/catalog-backend/src/legacy/service/router.test.ts index 3fc655d761..d15d3799b5 100644 --- a/plugins/catalog-backend/src/legacy/service/router.test.ts +++ b/plugins/catalog-backend/src/legacy/service/router.test.ts @@ -20,15 +20,15 @@ import { NotFoundError } from '@backstage/errors'; import type { Entity, LocationSpec } from '@backstage/catalog-model'; import express from 'express'; import request from 'supertest'; -import { EntitiesCatalog, LocationsCatalog } from '../../catalog'; -import { LocationResponse } from '../../catalog/types'; +import { EntitiesCatalog } from '../../catalog'; +import { LocationResponse, LocationsCatalog } from '../catalog/types'; import { HigherOrderOperation } from '../ingestion/types'; import { createRouter } from './router'; import { basicEntityFilter } from '../../service/request'; import { RefreshService } from '../../next'; describe('createRouter readonly disabled', () => { - let entitiesCatalog: jest.Mocked; + let entitiesCatalog: jest.Mocked>; let locationsCatalog: jest.Mocked; let higherOrderOperation: jest.Mocked; let app: express.Express; diff --git a/plugins/catalog-backend/src/legacy/service/router.ts b/plugins/catalog-backend/src/legacy/service/router.ts index 651880720e..4dfa9e49f9 100644 --- a/plugins/catalog-backend/src/legacy/service/router.ts +++ b/plugins/catalog-backend/src/legacy/service/router.ts @@ -26,7 +26,8 @@ import express from 'express'; import Router from 'express-promise-router'; import { Logger } from 'winston'; import yn from 'yn'; -import { EntitiesCatalog, LocationsCatalog } from '../../catalog'; +import { EntitiesCatalog } from '../../catalog'; +import { LocationsCatalog } from '../catalog'; import { LocationAnalyzer } from '../../ingestion/types'; import { HigherOrderOperation } from '../ingestion/types'; import { @@ -124,7 +125,7 @@ export async function createRouter( disallowReadonlyMode(readonlyEnabled); const body = await requireRequestBody(req); - const [result] = await entitiesCatalog.batchAddOrUpdateEntities([ + const [result] = await entitiesCatalog.batchAddOrUpdateEntities!([ { entity: body as Entity, relations: [] }, ]); const response = await entitiesCatalog.entities({ diff --git a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts index 615f3c55e1..77c87f38ff 100644 --- a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts +++ b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts @@ -33,11 +33,8 @@ import { ScmIntegrations } from '@backstage/integration'; import { createHash } from 'crypto'; import { Router } from 'express'; import lodash from 'lodash'; -import { - DatabaseLocationsCatalog, - EntitiesCatalog, - LocationsCatalog, -} from '../catalog'; +import { EntitiesCatalog } from '../catalog'; +import { DatabaseLocationsCatalog, LocationsCatalog } from '../legacy/catalog'; import { CommonDatabase } from '../database/CommonDatabase'; import { AnnotateLocationEntityProcessor, @@ -289,6 +286,7 @@ export class NextCatalogBuilder { */ async build(): Promise<{ entitiesCatalog: EntitiesCatalog; + /** @deprecated This will be removed */ locationsCatalog: LocationsCatalog; locationAnalyzer: LocationAnalyzer; processingEngine: CatalogProcessingEngine;