From 64dea77ede13f98efb527d7ad8dfd1b6bb958ec7 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 7 Oct 2022 12:52:33 +0200 Subject: [PATCH] move type to common package Signed-off-by: Kiss Miklos --- .../catalog-backend/src/ingestion/types.ts | 21 +++++------ plugins/catalog-common/api-report.md | 8 ++++- plugins/catalog-common/src/common.ts | 32 +++++++++++++++++ plugins/catalog-common/src/index.ts | 1 + .../src/ingestion/LocationAnalyzer.ts | 2 +- plugins/catalog-node/api-report.md | 35 +++++++++---------- plugins/catalog-node/package.json | 1 + plugins/catalog-node/src/api/common.ts | 8 ++--- .../catalog-node/src/api/processingResult.ts | 3 +- plugins/catalog-node/src/api/processor.ts | 3 +- yarn.lock | 1 + 11 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 plugins/catalog-common/src/common.ts diff --git a/plugins/catalog-backend/src/ingestion/types.ts b/plugins/catalog-backend/src/ingestion/types.ts index 467fe498b2..416fa968ab 100644 --- a/plugins/catalog-backend/src/ingestion/types.ts +++ b/plugins/catalog-backend/src/ingestion/types.ts @@ -15,23 +15,23 @@ */ import { - AnalyzeLocationRequest as ExaltedAnalyzeLocationRequest, - AnalyzeLocationResponse as ExaltedAnalyzeLocationResponse, - AnalyzeLocationExistingEntity as ExaltedAnalyzeLocationExistingEntity, - AnalyzeLocationGenerateEntity as ExaltedAnalyzeLocationGenerateEntity, - AnalyzeLocationEntityField as ExaltedAnalyzeLocationEntityField, + AnalyzeLocationRequest as NonDeprecatedAnalyzeLocationRequest, + AnalyzeLocationResponse as NonDeprecatedAnalyzeLocationResponse, + AnalyzeLocationExistingEntity as NonDeprecatedAnalyzeLocationExistingEntity, + AnalyzeLocationGenerateEntity as NonDeprecatedAnalyzeLocationGenerateEntity, + AnalyzeLocationEntityField as NonDeprecatedAnalyzeLocationEntityField, } from '@backstage/plugin-catalog-common'; /** * @public * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ -export type AnalyzeLocationRequest = ExaltedAnalyzeLocationRequest; +export type AnalyzeLocationRequest = NonDeprecatedAnalyzeLocationRequest; /** * @public * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ -export type AnalyzeLocationResponse = ExaltedAnalyzeLocationResponse; +export type AnalyzeLocationResponse = NonDeprecatedAnalyzeLocationResponse; /** * If the folder pointed to already contained catalog info yaml files, they are @@ -42,7 +42,7 @@ export type AnalyzeLocationResponse = ExaltedAnalyzeLocationResponse; * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ export type AnalyzeLocationExistingEntity = - ExaltedAnalyzeLocationExistingEntity; + NonDeprecatedAnalyzeLocationExistingEntity; /** * This is some form of representation of what the analyzer could deduce. * We should probably have a chat about how this can best be conveyed to @@ -53,7 +53,7 @@ export type AnalyzeLocationExistingEntity = * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ export type AnalyzeLocationGenerateEntity = - ExaltedAnalyzeLocationGenerateEntity; + NonDeprecatedAnalyzeLocationGenerateEntity; /** * @@ -63,7 +63,8 @@ export type AnalyzeLocationGenerateEntity = * @public * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ -export type AnalyzeLocationEntityField = ExaltedAnalyzeLocationEntityField; +export type AnalyzeLocationEntityField = + NonDeprecatedAnalyzeLocationEntityField; /** @public */ export type LocationAnalyzer = { diff --git a/plugins/catalog-common/api-report.md b/plugins/catalog-common/api-report.md index 867454f9bd..1bef626c79 100644 --- a/plugins/catalog-common/api-report.md +++ b/plugins/catalog-common/api-report.md @@ -6,7 +6,6 @@ import { BasicPermission } from '@backstage/plugin-permission-common'; import { Entity } from '@backstage/catalog-model'; import { IndexableDocument } from '@backstage/plugin-search-common'; -import { LocationSpec } from '@backstage/plugin-catalog-node'; import { ResourcePermission } from '@backstage/plugin-permission-common'; // @public (undocumented) @@ -93,6 +92,13 @@ export const catalogPermissions: ( | ResourcePermission<'catalog-entity'> )[]; +// @public +export type LocationSpec = { + type: string; + target: string; + presence?: 'optional' | 'required'; +}; + // @alpha export const RESOURCE_TYPE_CATALOG_ENTITY = 'catalog-entity'; ``` diff --git a/plugins/catalog-common/src/common.ts b/plugins/catalog-common/src/common.ts new file mode 100644 index 0000000000..c926a94b28 --- /dev/null +++ b/plugins/catalog-common/src/common.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2022 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. + */ + +/** + * Holds the entity location information. + * + * @remarks + * + * `presence` flag: when using repo importer plugin, location is being created before the component yaml file is merged to the main branch. + * This flag is then set to indicate that the file can be not present. + * default value: 'required'. + * + * @public + */ +export type LocationSpec = { + type: string; + target: string; + presence?: 'optional' | 'required'; +}; diff --git a/plugins/catalog-common/src/index.ts b/plugins/catalog-common/src/index.ts index a37fd122f9..95bd65bc92 100644 --- a/plugins/catalog-common/src/index.ts +++ b/plugins/catalog-common/src/index.ts @@ -36,3 +36,4 @@ export type { CatalogEntityPermission } from './permissions'; export * from './search'; export * from './ingestion'; +export type { LocationSpec } from './common'; diff --git a/plugins/catalog-common/src/ingestion/LocationAnalyzer.ts b/plugins/catalog-common/src/ingestion/LocationAnalyzer.ts index 8d570894cf..08ae5ef0cb 100644 --- a/plugins/catalog-common/src/ingestion/LocationAnalyzer.ts +++ b/plugins/catalog-common/src/ingestion/LocationAnalyzer.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { LocationSpec } from '@backstage/plugin-catalog-node'; +import { LocationSpec } from '../common'; import { Entity } from '@backstage/catalog-model'; import { RecursivePartial } from './RecursivePartial'; diff --git a/plugins/catalog-node/api-report.md b/plugins/catalog-node/api-report.md index 525516be54..09a05ec7d9 100644 --- a/plugins/catalog-node/api-report.md +++ b/plugins/catalog-node/api-report.md @@ -10,6 +10,7 @@ import { CompoundEntityRef } from '@backstage/catalog-model'; import { Entity } from '@backstage/catalog-model'; import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { JsonValue } from '@backstage/types'; +import { LocationSpec as LocationSpec_2 } from '@backstage/plugin-catalog-common'; import { ServiceRef } from '@backstage/backend-plugin-api'; // @alpha (undocumented) @@ -31,7 +32,7 @@ export const catalogProcessingExtensionPoint: ExtensionPoint; preProcessEntity?( entity: Entity, - location: LocationSpec, + location: LocationSpec_2, emit: CatalogProcessorEmit, - originLocation: LocationSpec, + originLocation: LocationSpec_2, cache: CatalogProcessorCache, ): Promise; validateEntityKind?(entity: Entity): Promise; postProcessEntity?( entity: Entity, - location: LocationSpec, + location: LocationSpec_2, emit: CatalogProcessorEmit, cache: CatalogProcessorCache, ): Promise; @@ -66,26 +67,26 @@ export type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void; export type CatalogProcessorEntityResult = { type: 'entity'; entity: Entity; - location: LocationSpec; + location: LocationSpec_2; }; // @public (undocumented) export type CatalogProcessorErrorResult = { type: 'error'; error: Error; - location: LocationSpec; + location: LocationSpec_2; }; // @public (undocumented) export type CatalogProcessorLocationResult = { type: 'location'; - location: LocationSpec; + location: LocationSpec_2; }; // @public export type CatalogProcessorParser = (options: { data: Buffer; - location: LocationSpec; + location: LocationSpec_2; }) => AsyncIterable; // @public (undocumented) @@ -153,30 +154,26 @@ export type EntityRelationSpec = { target: CompoundEntityRef; }; -// @public -export type LocationSpec = { - type: string; - target: string; - presence?: 'optional' | 'required'; -}; +// @public @deprecated +export type LocationSpec = LocationSpec_2; // @public export const processingResult: Readonly<{ readonly notFoundError: ( - atLocation: LocationSpec, + atLocation: LocationSpec_2, message: string, ) => CatalogProcessorResult; readonly inputError: ( - atLocation: LocationSpec, + atLocation: LocationSpec_2, message: string, ) => CatalogProcessorResult; readonly generalError: ( - atLocation: LocationSpec, + atLocation: LocationSpec_2, message: string, ) => CatalogProcessorResult; - readonly location: (newLocation: LocationSpec) => CatalogProcessorResult; + readonly location: (newLocation: LocationSpec_2) => CatalogProcessorResult; readonly entity: ( - atLocation: LocationSpec, + atLocation: LocationSpec_2, newEntity: Entity, ) => CatalogProcessorResult; readonly relation: (spec: EntityRelationSpec) => CatalogProcessorResult; diff --git a/plugins/catalog-node/package.json b/plugins/catalog-node/package.json index 0a7e687bb7..7cbbac1531 100644 --- a/plugins/catalog-node/package.json +++ b/plugins/catalog-node/package.json @@ -28,6 +28,7 @@ "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/errors": "workspace:^", + "@backstage/plugin-catalog-common": "workspace:^", "@backstage/types": "workspace:^" }, "devDependencies": { diff --git a/plugins/catalog-node/src/api/common.ts b/plugins/catalog-node/src/api/common.ts index f3b4a387ba..c91aeca2d9 100644 --- a/plugins/catalog-node/src/api/common.ts +++ b/plugins/catalog-node/src/api/common.ts @@ -15,6 +15,7 @@ */ import { CompoundEntityRef } from '@backstage/catalog-model'; +import { LocationSpec as NonDeprecatedLocationSpec } from '@backstage/plugin-catalog-common'; /** * Holds the entity location information. @@ -26,12 +27,9 @@ import { CompoundEntityRef } from '@backstage/catalog-model'; * default value: 'required'. * * @public + * @deprecated use the same type from `@backstage/plugin-catalog-common` instead */ -export type LocationSpec = { - type: string; - target: string; - presence?: 'optional' | 'required'; -}; +export type LocationSpec = NonDeprecatedLocationSpec; /** * Holds the relation data for entities. diff --git a/plugins/catalog-node/src/api/processingResult.ts b/plugins/catalog-node/src/api/processingResult.ts index 84f1f4b70d..d8b6f3ae02 100644 --- a/plugins/catalog-node/src/api/processingResult.ts +++ b/plugins/catalog-node/src/api/processingResult.ts @@ -17,7 +17,8 @@ import { InputError, NotFoundError } from '@backstage/errors'; import { Entity } from '@backstage/catalog-model'; import { CatalogProcessorResult } from './processor'; -import { EntityRelationSpec, LocationSpec } from './common'; +import { EntityRelationSpec } from './common'; +import { LocationSpec } from '@backstage/plugin-catalog-common'; /** * Factory functions for the standard processing result types. diff --git a/plugins/catalog-node/src/api/processor.ts b/plugins/catalog-node/src/api/processor.ts index 44e8b298b0..3ad080f014 100644 --- a/plugins/catalog-node/src/api/processor.ts +++ b/plugins/catalog-node/src/api/processor.ts @@ -16,7 +16,8 @@ import { Entity } from '@backstage/catalog-model'; import { JsonValue } from '@backstage/types'; -import { EntityRelationSpec, LocationSpec } from './common'; +import { EntityRelationSpec } from './common'; +import { LocationSpec } from '@backstage/plugin-catalog-common'; /** * @public diff --git a/yarn.lock b/yarn.lock index 71d139f97d..aca25a583e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4838,6 +4838,7 @@ __metadata: "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/errors": "workspace:^" + "@backstage/plugin-catalog-common": "workspace:^" "@backstage/types": "workspace:^" languageName: unknown linkType: soft