From f5df64c82295782c8fb148dc6f3600e91536355c Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 7 Oct 2021 17:59:00 +0200 Subject: [PATCH] feat: moved the deprecated database implemmentation to legacy catalog Signed-off-by: blam Co-authored-by: Johan Haals Co-authored-by: Patrik Oldsberg --- plugins/catalog-backend/api-report.md | 58 +++++++++--------- plugins/catalog-backend/src/catalog/index.ts | 3 + plugins/catalog-backend/src/catalog/types.ts | 48 +++++++++++++-- plugins/catalog-backend/src/index.ts | 1 - .../catalog/DatabaseEntitiesCatalog.test.ts | 2 +- .../legacy/catalog/DatabaseEntitiesCatalog.ts | 4 +- .../catalog/DatabaseLocationsCatalog.test.ts | 2 +- .../catalog/DatabaseLocationsCatalog.ts | 4 +- .../database/CommonDatabase.test.ts | 2 +- .../{ => legacy}/database/CommonDatabase.ts | 5 +- .../{ => legacy}/database/DatabaseManager.ts | 2 + .../src/{ => legacy}/database/index.ts | 3 - .../src/{ => legacy}/database/search.test.ts | 0 .../src/{ => legacy}/database/search.ts | 0 .../src/{ => legacy}/database/types.ts | 60 +++++-------------- plugins/catalog-backend/src/legacy/index.ts | 1 + .../ingestion/HigherOrderOperations.test.ts | 2 +- .../src/legacy/service/CatalogBuilder.test.ts | 2 +- .../src/legacy/service/CatalogBuilder.ts | 2 +- .../src/next/NextCatalogBuilder.ts | 8 ++- .../src/next/NextEntitiesCatalog.ts | 3 +- .../src/next/database/DatabaseManager.ts | 3 +- .../database/DefaultProcessingDatabase.ts | 21 +++---- .../src/next/database/metrics.ts | 3 +- .../src/next/database/tables.ts | 9 +++ .../src/next/database/types.ts | 8 ++- .../src/service/request/basicEntityFilter.ts | 2 +- .../request/parseEntityFilterParams.ts | 2 +- .../request/parseEntityPaginationParams.ts | 2 +- .../src/service/standaloneServer.ts | 2 +- 30 files changed, 148 insertions(+), 116 deletions(-) rename plugins/catalog-backend/src/{ => legacy}/database/CommonDatabase.test.ts (99%) rename plugins/catalog-backend/src/{ => legacy}/database/CommonDatabase.ts (99%) rename plugins/catalog-backend/src/{ => legacy}/database/DatabaseManager.ts (96%) rename plugins/catalog-backend/src/{ => legacy}/database/index.ts (94%) rename plugins/catalog-backend/src/{ => legacy}/database/search.test.ts (100%) rename plugins/catalog-backend/src/{ => legacy}/database/search.ts (100%) rename plugins/catalog-backend/src/{ => legacy}/database/types.ts (85%) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 2aecebdda7..6b7d966b28 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -435,7 +435,7 @@ export class CodeOwnersProcessor implements CatalogProcessor { // Warning: (ae-missing-release-tag) "CommonDatabase" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public +// @public @deprecated export class CommonDatabase implements Database { constructor(database: Knex, logger: Logger_2); // (undocumented) @@ -499,7 +499,7 @@ export class CommonDatabase implements Database { // Warning: (ae-missing-release-tag) "CreateDatabaseOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type CreateDatabaseOptions = { logger: Logger_2; }; @@ -528,7 +528,7 @@ export function createRouter(options: RouterOptions): Promise; // Warning: (ae-missing-release-tag) "Database" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public +// @public @deprecated export type Database = { transaction(fn: (tx: Transaction) => Promise): Promise; addEntities( @@ -624,7 +624,7 @@ export class DatabaseLocationsCatalog implements LocationsCatalog { // Warning: (ae-missing-release-tag) "DatabaseLocationUpdateLogEvent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DatabaseLocationUpdateLogEvent = { id: string; status: DatabaseLocationUpdateLogStatus; @@ -646,7 +646,7 @@ export enum DatabaseLocationUpdateLogStatus { // Warning: (ae-missing-release-tag) "DatabaseManager" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export class DatabaseManager { // (undocumented) static createDatabase( @@ -665,7 +665,7 @@ export class DatabaseManager { // Warning: (ae-missing-release-tag) "DbEntitiesRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbEntitiesRequest = { filter?: EntityFilter; pagination?: EntityPagination; @@ -673,7 +673,7 @@ export type DbEntitiesRequest = { // Warning: (ae-missing-release-tag) "DbEntitiesResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbEntitiesResponse = { entities: DbEntityResponse[]; pageInfo: DbPageInfo; @@ -681,7 +681,7 @@ export type DbEntitiesResponse = { // Warning: (ae-missing-release-tag) "DbEntityRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbEntityRequest = { locationId?: string; entity: Entity; @@ -690,7 +690,7 @@ export type DbEntityRequest = { // Warning: (ae-missing-release-tag) "DbEntityResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbEntityResponse = { locationId?: string; entity: Entity; @@ -698,7 +698,7 @@ export type DbEntityResponse = { // Warning: (ae-missing-release-tag) "DbLocationsRow" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbLocationsRow = { id: string; type: string; @@ -707,7 +707,7 @@ export type DbLocationsRow = { // Warning: (ae-missing-release-tag) "DbLocationsRowWithStatus" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbLocationsRowWithStatus = DbLocationsRow & { status: string | null; timestamp: string | null; @@ -716,7 +716,7 @@ export type DbLocationsRowWithStatus = DbLocationsRow & { // Warning: (ae-missing-release-tag) "DbPageInfo" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type DbPageInfo = | { hasNextPage: false; @@ -812,7 +812,7 @@ export function durationText(startTimestamp: [number, number]): string; export type EntitiesCatalog = { entities(request?: EntitiesRequest): Promise; removeEntityByUid(uid: string): Promise; - batchAddOrUpdateEntities( + batchAddOrUpdateEntities?( requests: EntityUpsertRequest[], options?: { locationId?: string; @@ -943,7 +943,7 @@ export type EntityProviderMutation = // Warning: (ae-missing-release-tag) "EntityUpsertRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type EntityUpsertRequest = { entity: Entity; relations: EntityRelationSpec[]; @@ -951,7 +951,7 @@ export type EntityUpsertRequest = { // Warning: (ae-missing-release-tag) "EntityUpsertResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public (undocumented) +// @public @deprecated (undocumented) export type EntityUpsertResponse = { entityId: string; entity?: Entity; @@ -1487,7 +1487,7 @@ export class StaticLocationProcessor implements StaticLocationProcessor { // Warning: (ae-missing-release-tag) "Transaction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public +// @public @deprecated export type Transaction = { rollback(): Promise; }; @@ -1512,20 +1512,20 @@ export class UrlReaderProcessor implements CatalogProcessor { // Warnings were encountered during analysis: // -// src/catalog/types.d.ts:52:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters -// src/catalog/types.d.ts:53:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters -// src/catalog/types.d.ts:54:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters -// src/database/types.d.ts:125:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:131:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:132:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:146:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:147:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:148:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:150:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:163:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:164:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen -// src/database/types.d.ts:165:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/catalog/types.d.ts:97:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters +// src/catalog/types.d.ts:98:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters +// src/catalog/types.d.ts:99:8 - (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters // src/ingestion/processors/GithubMultiOrgReaderProcessor.d.ts:23:9 - (ae-forgotten-export) The symbol "GithubMultiOrgConfig" needs to be exported by the entry point index.d.ts // src/ingestion/types.d.ts:8:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:98:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:104:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:105:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:119:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:120:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:121:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:123:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:136:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:137:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen +// src/legacy/database/types.d.ts:138:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // src/legacy/ingestion/types.d.ts:19:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen ``` diff --git a/plugins/catalog-backend/src/catalog/index.ts b/plugins/catalog-backend/src/catalog/index.ts index 7ac0150eef..885a2f5389 100644 --- a/plugins/catalog-backend/src/catalog/index.ts +++ b/plugins/catalog-backend/src/catalog/index.ts @@ -22,4 +22,7 @@ export type { EntityUpsertRequest, EntityUpsertResponse, PageInfo, + EntitiesSearchFilter, + EntityFilter, + EntityPagination, } from './types'; diff --git a/plugins/catalog-backend/src/catalog/types.ts b/plugins/catalog-backend/src/catalog/types.ts index cd2590a26b..0bc0ec4311 100644 --- a/plugins/catalog-backend/src/catalog/types.ts +++ b/plugins/catalog-backend/src/catalog/types.ts @@ -15,11 +15,51 @@ */ import { Entity, EntityRelationSpec } from '@backstage/catalog-model'; -import { EntityFilter, EntityPagination } from '../database/types'; -// -// Entities -// +/** + * A filter expression for entities. + * + * Any (at least one) of the outer sets must match, within which all of the + * individual filters must match. + */ +export type EntityFilter = { + anyOf: { allOf: EntitiesSearchFilter[] }[]; +}; + +/** + * A pagination rule for entities. + */ +export type EntityPagination = { + limit?: number; + offset?: number; + after?: string; +}; + +/** + * Matches rows in the entities_search table. + */ +export type EntitiesSearchFilter = { + /** + * The key to match on. + * + * Matches are always case insensitive. + */ + key: string; + + /** + * Match on plain equality of values. + * + * If undefined, this factor is not taken into account. Otherwise, match on + * values that are equal to any of the given array items. Matches are always + * case insensitive. + */ + matchValueIn?: string[]; + + /** + * Match on existence of key. + */ + matchValueExists?: boolean; +}; export type PageInfo = | { diff --git a/plugins/catalog-backend/src/index.ts b/plugins/catalog-backend/src/index.ts index af0c32f73b..4d84330f27 100644 --- a/plugins/catalog-backend/src/index.ts +++ b/plugins/catalog-backend/src/index.ts @@ -21,7 +21,6 @@ */ export * from './catalog'; -export * from './database'; export * from './ingestion'; export * from './legacy'; export * from './search'; diff --git a/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.test.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.test.ts index 953e08d07a..e2db8a0fc0 100644 --- a/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.test.ts +++ b/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.test.ts @@ -16,7 +16,7 @@ import { getVoidLogger } from '@backstage/backend-common'; import { Entity, LOCATION_ANNOTATION } from '@backstage/catalog-model'; -import { Database, DatabaseManager, Transaction } from '../../database'; +import { Database, DatabaseManager, Transaction } from '../database'; import { basicEntityFilter } from '../../service/request'; import { DatabaseEntitiesCatalog } from './DatabaseEntitiesCatalog'; import { EntityUpsertRequest } from '../../catalog/types'; diff --git a/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.ts index f4f8fd320e..8776a5a4dc 100644 --- a/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/legacy/catalog/DatabaseEntitiesCatalog.ts @@ -26,8 +26,8 @@ import { ConflictError } from '@backstage/errors'; import { chunk, groupBy } from 'lodash'; import limiterFactory from 'p-limit'; import { Logger } from 'winston'; -import type { Database, DbEntityResponse, Transaction } from '../../database'; -import { DbEntitiesRequest } from '../../database/types'; +import type { Database, DbEntityResponse, Transaction } from '../database'; +import { DbEntitiesRequest } from '../database/types'; import { basicEntityFilter } from '../../service/request'; import { durationText } from '../../util/timing'; import type { diff --git a/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.test.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.test.ts index 24bcc79db1..8bd8e86b8e 100644 --- a/plugins/catalog-backend/src/legacy/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/legacy/catalog/DatabaseLocationsCatalog.ts b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts index 4e3b6975a4..1273e193b2 100644 --- a/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts +++ b/plugins/catalog-backend/src/legacy/catalog/DatabaseLocationsCatalog.ts @@ -15,11 +15,11 @@ */ 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 */ diff --git a/plugins/catalog-backend/src/database/CommonDatabase.test.ts b/plugins/catalog-backend/src/legacy/database/CommonDatabase.test.ts similarity index 99% rename from plugins/catalog-backend/src/database/CommonDatabase.test.ts rename to plugins/catalog-backend/src/legacy/database/CommonDatabase.test.ts index f459cbc446..ca2e6c2934 100644 --- a/plugins/catalog-backend/src/database/CommonDatabase.test.ts +++ b/plugins/catalog-backend/src/legacy/database/CommonDatabase.test.ts @@ -16,7 +16,7 @@ import { Entity, Location, parseEntityRef } from '@backstage/catalog-model'; import { ConflictError } from '@backstage/errors'; -import { basicEntityFilter } from '../service/request'; +import { basicEntityFilter } from '../../service/request'; import { DatabaseManager } from './DatabaseManager'; import type { DbEntityRequest, diff --git a/plugins/catalog-backend/src/database/CommonDatabase.ts b/plugins/catalog-backend/src/legacy/database/CommonDatabase.ts similarity index 99% rename from plugins/catalog-backend/src/database/CommonDatabase.ts rename to plugins/catalog-backend/src/legacy/database/CommonDatabase.ts index 79cad3bd23..5cc31b5be5 100644 --- a/plugins/catalog-backend/src/database/CommonDatabase.ts +++ b/plugins/catalog-backend/src/legacy/database/CommonDatabase.ts @@ -44,9 +44,9 @@ import { DbLocationsRow, DbLocationsRowWithStatus, DbPageInfo, - EntityPagination, Transaction, } from './types'; +import { EntityPagination } from '../../catalog/types'; // The number of items that are sent per batch to the database layer, when // doing .batchInsert calls to knex. This needs to be low enough to not cause @@ -55,7 +55,8 @@ import { const BATCH_SIZE = 50; /** - * The core database implementation. + * The core database implementation.. + * @deprecated This was part of the legacy catalog engin */ export class CommonDatabase implements Database { constructor( diff --git a/plugins/catalog-backend/src/database/DatabaseManager.ts b/plugins/catalog-backend/src/legacy/database/DatabaseManager.ts similarity index 96% rename from plugins/catalog-backend/src/database/DatabaseManager.ts rename to plugins/catalog-backend/src/legacy/database/DatabaseManager.ts index 2e43290fb5..9bb75a1043 100644 --- a/plugins/catalog-backend/src/database/DatabaseManager.ts +++ b/plugins/catalog-backend/src/legacy/database/DatabaseManager.ts @@ -26,6 +26,7 @@ const migrationsDir = resolvePackagePath( 'migrations', ); +/** @deprecated This was part of the legacy catalog engine */ export type CreateDatabaseOptions = { logger: Logger; }; @@ -34,6 +35,7 @@ const defaultOptions: CreateDatabaseOptions = { logger: getVoidLogger(), }; +/** @deprecated This was part of the legacy catalog engine */ export class DatabaseManager { public static async createDatabase( knex: Knex, diff --git a/plugins/catalog-backend/src/database/index.ts b/plugins/catalog-backend/src/legacy/database/index.ts similarity index 94% rename from plugins/catalog-backend/src/database/index.ts rename to plugins/catalog-backend/src/legacy/database/index.ts index 028b0caa4b..909c1de26c 100644 --- a/plugins/catalog-backend/src/database/index.ts +++ b/plugins/catalog-backend/src/legacy/database/index.ts @@ -21,9 +21,6 @@ export type { Database, DbEntityRequest, DbEntityResponse, - EntitiesSearchFilter, - EntityFilter, - EntityPagination, Transaction, DbEntitiesRequest, DbEntitiesResponse, diff --git a/plugins/catalog-backend/src/database/search.test.ts b/plugins/catalog-backend/src/legacy/database/search.test.ts similarity index 100% rename from plugins/catalog-backend/src/database/search.test.ts rename to plugins/catalog-backend/src/legacy/database/search.test.ts diff --git a/plugins/catalog-backend/src/database/search.ts b/plugins/catalog-backend/src/legacy/database/search.ts similarity index 100% rename from plugins/catalog-backend/src/database/search.ts rename to plugins/catalog-backend/src/legacy/database/search.ts diff --git a/plugins/catalog-backend/src/database/types.ts b/plugins/catalog-backend/src/legacy/database/types.ts similarity index 85% rename from plugins/catalog-backend/src/database/types.ts rename to plugins/catalog-backend/src/legacy/database/types.ts index e1a253decc..b68681b4bd 100644 --- a/plugins/catalog-backend/src/database/types.ts +++ b/plugins/catalog-backend/src/legacy/database/types.ts @@ -20,7 +20,9 @@ import type { EntityRelationSpec, Location, } from '@backstage/catalog-model'; +import { EntityFilter, EntityPagination } from '../../catalog/types'; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntitiesRow = { id: string; location_id: string | null; @@ -30,22 +32,26 @@ export type DbEntitiesRow = { data: string; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntityRequest = { locationId?: string; entity: Entity; relations: EntityRelationSpec[]; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntitiesRequest = { filter?: EntityFilter; pagination?: EntityPagination; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntitiesResponse = { entities: DbEntityResponse[]; pageInfo: DbPageInfo; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbPageInfo = | { hasNextPage: false; @@ -55,11 +61,13 @@ export type DbPageInfo = endCursor: string; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntityResponse = { locationId?: string; entity: Entity; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntitiesRelationsRow = { originating_entity_id: string; source_full_name: string; @@ -67,18 +75,21 @@ export type DbEntitiesRelationsRow = { target_full_name: string; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbEntitiesSearchRow = { entity_id: string; key: string; value: string | null; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbLocationsRow = { id: string; type: string; target: string; }; +/** @deprecated This was part of the legacy catalog engine */ export type DbLocationsRowWithStatus = DbLocationsRow & { status: string | null; timestamp: string | null; @@ -90,6 +101,7 @@ export enum DatabaseLocationUpdateLogStatus { SUCCESS = 'success', } +/** @deprecated This was part of the legacy catalog engine */ export type DatabaseLocationUpdateLogEvent = { id: string; status: DatabaseLocationUpdateLogStatus; @@ -99,53 +111,10 @@ export type DatabaseLocationUpdateLogEvent = { message?: string; }; -/** - * Matches rows in the entities_search table. - */ -export type EntitiesSearchFilter = { - /** - * The key to match on. - * - * Matches are always case insensitive. - */ - key: string; - - /** - * Match on plain equality of values. - * - * If undefined, this factor is not taken into account. Otherwise, match on - * values that are equal to any of the given array items. Matches are always - * case insensitive. - */ - matchValueIn?: string[]; - - /** - * Match on existence of key. - */ - matchValueExists?: boolean; -}; - -/** - * A filter expression for entities. - * - * Any (at least one) of the outer sets must match, within which all of the - * individual filters must match. - */ -export type EntityFilter = { - anyOf: { allOf: EntitiesSearchFilter[] }[]; -}; - -/** - * A pagination rule for entities. - */ -export type EntityPagination = { - limit?: number; - offset?: number; - after?: string; -}; - /** * An abstraction for transactions of the underlying database technology. + * + * @deprecated This was part of the legacy catalog engine */ export type Transaction = { rollback(): Promise; @@ -154,6 +123,7 @@ export type Transaction = { /** * An abstraction on top of the underlying database, wrapping the basic CRUD * needs. + * @deprecated This was part of the legacy catalog engine */ export type Database = { /** diff --git a/plugins/catalog-backend/src/legacy/index.ts b/plugins/catalog-backend/src/legacy/index.ts index 74074aa319..be8c7b8d63 100644 --- a/plugins/catalog-backend/src/legacy/index.ts +++ b/plugins/catalog-backend/src/legacy/index.ts @@ -17,3 +17,4 @@ export * from './catalog'; export * from './ingestion'; export * from './service'; +export * from './database'; diff --git a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts index 5508b4d8a2..e6c042421b 100644 --- a/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts +++ b/plugins/catalog-backend/src/legacy/ingestion/HigherOrderOperations.test.ts @@ -19,7 +19,7 @@ import { Entity, Location, LocationSpec } from '@backstage/catalog-model'; import { EntitiesCatalog } from '../../catalog'; import { LocationsCatalog } from '../catalog'; import { LocationUpdateStatus } from '../catalog/types'; -import { DatabaseLocationUpdateLogStatus } from '../../database/types'; +import { DatabaseLocationUpdateLogStatus } from '../database/types'; import { HigherOrderOperations } from './HigherOrderOperations'; import { LocationReader } from './types'; diff --git a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.test.ts b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.test.ts index 5d3a4dd326..1b366130ed 100644 --- a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.test.ts +++ b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.test.ts @@ -19,7 +19,7 @@ import { Entity } from '@backstage/catalog-model'; import { ConfigReader } from '@backstage/config'; import { Knex } from 'knex'; import yaml from 'yaml'; -import { DatabaseManager } from '../../database'; +import { DatabaseManager } from '../database'; import { CatalogProcessorParser } from '../../ingestion'; import * as result from '../../ingestion/processors/results'; import { CatalogBuilder } from './CatalogBuilder'; diff --git a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts index dee096ce7d..1a151b77d6 100644 --- a/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/legacy/service/CatalogBuilder.ts @@ -32,7 +32,7 @@ import { DatabaseLocationsCatalog, LocationsCatalog, } from '../catalog'; -import { DatabaseManager } from '../../database'; +import { DatabaseManager } from '../database'; import { AnnotateLocationEntityProcessor, BitbucketDiscoveryProcessor, diff --git a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts index 77c87f38ff..700c5a5163 100644 --- a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts +++ b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts @@ -34,8 +34,12 @@ import { createHash } from 'crypto'; import { Router } from 'express'; import lodash from 'lodash'; import { EntitiesCatalog } from '../catalog'; -import { DatabaseLocationsCatalog, LocationsCatalog } from '../legacy/catalog'; -import { CommonDatabase } from '../database/CommonDatabase'; +import { + DatabaseLocationsCatalog, + LocationsCatalog, + CommonDatabase, +} from '../legacy'; + import { AnnotateLocationEntityProcessor, BitbucketDiscoveryProcessor, diff --git a/plugins/catalog-backend/src/next/NextEntitiesCatalog.ts b/plugins/catalog-backend/src/next/NextEntitiesCatalog.ts index 14fda4ea24..4fde078a8b 100644 --- a/plugins/catalog-backend/src/next/NextEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/next/NextEntitiesCatalog.ts @@ -22,13 +22,14 @@ import { EntitiesRequest, EntitiesResponse, EntityAncestryResponse, + EntityPagination, } from '../catalog/types'; -import { DbPageInfo, EntityPagination } from '../database/types'; import { DbFinalEntitiesRow, DbRefreshStateReferencesRow, DbRefreshStateRow, DbSearchRow, + DbPageInfo, } from './database/tables'; function parsePagination(input?: EntityPagination): { diff --git a/plugins/catalog-backend/src/next/database/DatabaseManager.ts b/plugins/catalog-backend/src/next/database/DatabaseManager.ts index 124e8227b7..3b31542025 100644 --- a/plugins/catalog-backend/src/next/database/DatabaseManager.ts +++ b/plugins/catalog-backend/src/next/database/DatabaseManager.ts @@ -18,8 +18,7 @@ import { getVoidLogger, resolvePackagePath } from '@backstage/backend-common'; import knexFactory, { Knex } from 'knex'; import { v4 as uuid } from 'uuid'; import { Logger } from 'winston'; -import { CommonDatabase } from '../../database/CommonDatabase'; -import { Database } from '../../database/types'; +import { CommonDatabase, Database } from '../../legacy'; export type CreateDatabaseOptions = { logger: Logger; diff --git a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts index 7b32bec5e9..b47154a46f 100644 --- a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts +++ b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts @@ -20,17 +20,8 @@ import { Knex } from 'knex'; import lodash from 'lodash'; import { v4 as uuid } from 'uuid'; import type { Logger } from 'winston'; -import { Transaction } from '../../database'; -import { DeferredEntity } from '../processing/types'; -import { RefreshIntervalFunction } from '../refresh'; -import { rethrowError, timestampToDateTime } from './conversion'; -import { initDatabaseMetrics } from './metrics'; -import { - DbRefreshStateReferencesRow, - DbRefreshStateRow, - DbRelationsRow, -} from './tables'; import { + Transaction, GetProcessableEntitiesResult, ProcessingDatabase, RefreshStateItem, @@ -41,6 +32,16 @@ import { ListAncestorsResult, UpdateEntityCacheOptions, } from './types'; +import { DeferredEntity } from '../processing/types'; +import { RefreshIntervalFunction } from '../refresh'; +import { rethrowError, timestampToDateTime } from './conversion'; +import { initDatabaseMetrics } from './metrics'; +import { + DbRefreshStateReferencesRow, + DbRefreshStateRow, + DbRelationsRow, +} from './tables'; + import { generateStableHash } from './util'; // The number of items that are sent per batch to the database layer, when diff --git a/plugins/catalog-backend/src/next/database/metrics.ts b/plugins/catalog-backend/src/next/database/metrics.ts index a41ad512f0..4ad319ed10 100644 --- a/plugins/catalog-backend/src/next/database/metrics.ts +++ b/plugins/catalog-backend/src/next/database/metrics.ts @@ -15,9 +15,8 @@ */ import { Knex } from 'knex'; -import { DbLocationsRow } from '../../database/types'; import { createGaugeMetric } from '../metrics'; -import { DbRefreshStateRow, DbRelationsRow } from './tables'; +import { DbRefreshStateRow, DbRelationsRow, DbLocationsRow } from './tables'; export function initDatabaseMetrics(knex: Knex) { const seen = new Set(); diff --git a/plugins/catalog-backend/src/next/database/tables.ts b/plugins/catalog-backend/src/next/database/tables.ts index e064b17d7b..40b4cb9a12 100644 --- a/plugins/catalog-backend/src/next/database/tables.ts +++ b/plugins/catalog-backend/src/next/database/tables.ts @@ -14,6 +14,15 @@ * limitations under the License. */ +export type DbPageInfo = + | { + hasNextPage: false; + } + | { + hasNextPage: true; + endCursor: string; + }; + export type DbLocationsRow = { id: string; type: string; diff --git a/plugins/catalog-backend/src/next/database/types.ts b/plugins/catalog-backend/src/next/database/types.ts index 3f1a4784fb..041a3fdc5b 100644 --- a/plugins/catalog-backend/src/next/database/types.ts +++ b/plugins/catalog-backend/src/next/database/types.ts @@ -17,9 +17,15 @@ import { Entity, EntityRelationSpec } from '@backstage/catalog-model'; import { JsonObject } from '@backstage/config'; import { DateTime } from 'luxon'; -import { Transaction } from '../../database/types'; import { DeferredEntity } from '../processing/types'; +/** + * An abstraction for transactions of the underlying database technology. + */ +export type Transaction = { + rollback(): Promise; +}; + export type AddUnprocessedEntitiesResult = {}; export type UpdateProcessedEntityOptions = { diff --git a/plugins/catalog-backend/src/service/request/basicEntityFilter.ts b/plugins/catalog-backend/src/service/request/basicEntityFilter.ts index a3ad1c2f73..1cf9ca95f0 100644 --- a/plugins/catalog-backend/src/service/request/basicEntityFilter.ts +++ b/plugins/catalog-backend/src/service/request/basicEntityFilter.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { EntitiesSearchFilter, EntityFilter } from '../../database'; +import { EntitiesSearchFilter, EntityFilter } from '../../catalog'; /** * Forms a full EntityFilter based on a single key-value(s) object. diff --git a/plugins/catalog-backend/src/service/request/parseEntityFilterParams.ts b/plugins/catalog-backend/src/service/request/parseEntityFilterParams.ts index c63b366bc7..452958b7ae 100644 --- a/plugins/catalog-backend/src/service/request/parseEntityFilterParams.ts +++ b/plugins/catalog-backend/src/service/request/parseEntityFilterParams.ts @@ -15,7 +15,7 @@ */ import { InputError } from '@backstage/errors'; -import { EntitiesSearchFilter, EntityFilter } from '../../database'; +import { EntitiesSearchFilter, EntityFilter } from '../../catalog'; import { parseStringsParam } from './common'; /** diff --git a/plugins/catalog-backend/src/service/request/parseEntityPaginationParams.ts b/plugins/catalog-backend/src/service/request/parseEntityPaginationParams.ts index c22dcd5935..c91c0b0214 100644 --- a/plugins/catalog-backend/src/service/request/parseEntityPaginationParams.ts +++ b/plugins/catalog-backend/src/service/request/parseEntityPaginationParams.ts @@ -15,7 +15,7 @@ */ import { InputError } from '@backstage/errors'; -import { EntityPagination } from '../../database'; +import { EntityPagination } from '../../catalog'; import { parseIntegerParam, parseStringParam } from './common'; /** diff --git a/plugins/catalog-backend/src/service/standaloneServer.ts b/plugins/catalog-backend/src/service/standaloneServer.ts index 4a3409802f..7aae3cd47c 100644 --- a/plugins/catalog-backend/src/service/standaloneServer.ts +++ b/plugins/catalog-backend/src/service/standaloneServer.ts @@ -22,7 +22,7 @@ import { } from '@backstage/backend-common'; import { Server } from 'http'; import { Logger } from 'winston'; -import { DatabaseManager } from '../database'; +import { DatabaseManager } from '../legacy/database'; import { CatalogBuilder } from '../legacy/service/CatalogBuilder'; import { createRouter } from '../legacy/service';