catalog-model: Prefix annotations with ANNOTATION_

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-02-15 09:30:41 +01:00
parent 80c627d098
commit 27eccab216
33 changed files with 197 additions and 115 deletions
+4 -4
View File
@@ -15,10 +15,10 @@
*/
import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
EntityName,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
parseEntityRef,
stringifyEntityRef,
stringifyLocationRef,
@@ -253,7 +253,7 @@ export class CatalogClient implements CatalogApi {
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound =
entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION];
entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION];
if (!locationCompound) {
return undefined;
}
@@ -274,7 +274,7 @@ export class CatalogClient implements CatalogApi {
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound = entity.metadata.annotations?.[LOCATION_ANNOTATION];
const locationCompound = entity.metadata.annotations?.[ANNOTATION_LOCATION];
if (!locationCompound) {
return undefined;
}
+21 -5
View File
@@ -13,6 +13,22 @@ export interface AlphaEntity extends Entity {
status?: EntityStatus;
}
// @public
export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url';
// @public
export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location';
// @public
export const ANNOTATION_ORIGIN_LOCATION =
'backstage.io/managed-by-origin-location';
// @public
export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location';
// @public
export const ANNOTATION_VIEW_URL = 'backstage.io/view-url';
// @public
interface ApiEntityV1alpha1 extends Entity {
// (undocumented)
@@ -105,7 +121,7 @@ export { DomainEntityV1alpha1 };
// @public
export const domainEntityV1alpha1Validator: KindValidator;
// @public
// @public @deprecated
export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url';
// @public
@@ -325,7 +341,7 @@ type Location_2 = {
} & LocationSpec;
export { Location_2 as Location };
// @public
// @public @deprecated
export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location';
// @public
@@ -365,7 +381,7 @@ export class NoForeignRootFieldsEntityPolicy implements EntityPolicy {
enforce(entity: Entity): Promise<Entity>;
}
// @public
// @public @deprecated
export const ORIGIN_LOCATION_ANNOTATION =
'backstage.io/managed-by-origin-location';
@@ -489,7 +505,7 @@ export class SchemaValidEntityPolicy implements EntityPolicy {
enforce(entity: Entity): Promise<Entity>;
}
// @public
// @public @deprecated
export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location';
// @public
@@ -595,6 +611,6 @@ export type Validators = {
isValidTag(value: unknown): boolean;
};
// @public
// @public @deprecated
export const VIEW_URL_ANNOTATION = 'backstage.io/view-url';
```
@@ -37,6 +37,7 @@ export const ENTITY_META_GENERATED_FIELDS = [
* Annotation for linking to entity page from catalog pages.
*
* @public
* @deprecated use {@link ANNOTATION_VIEW_URL} instead.
*/
export const VIEW_URL_ANNOTATION = 'backstage.io/view-url';
@@ -44,5 +45,20 @@ export const VIEW_URL_ANNOTATION = 'backstage.io/view-url';
* Annotation for linking to entity edit page from catalog pages.
*
* @public
* @deprecated use {@link ANNOTATION_EDIT_URL} instead.
*/
export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url';
/**
* Annotation for linking to entity page from catalog pages.
*
* @public
*/
export const ANNOTATION_VIEW_URL = 'backstage.io/view-url';
/**
* Annotation for linking to entity edit page from catalog pages.
*
* @public
*/
export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url';
@@ -19,6 +19,8 @@ export {
ENTITY_DEFAULT_NAMESPACE,
ENTITY_META_GENERATED_FIELDS,
VIEW_URL_ANNOTATION,
ANNOTATION_EDIT_URL,
ANNOTATION_VIEW_URL,
} from './constants';
export type {
AlphaEntity,
@@ -17,17 +17,41 @@
/**
* Constant storing location annotation.
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_LOCATION} instead.
* */
export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location';
/**
* Constant storing origin location annotation
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_ORIGIN_LOCATION} instead.
*/
export const ORIGIN_LOCATION_ANNOTATION =
'backstage.io/managed-by-origin-location';
/**
* Contant storing source location annotation
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_SOURCE_LOCATION} instead.
* */
export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location';
/**
* Constant storing location annotation.
*
* @public */
export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location';
/**
* Constant storing origin location annotation
*
* @public */
export const ANNOTATION_ORIGIN_LOCATION =
'backstage.io/managed-by-origin-location';
/**
* Contant storing source location annotation
*
* @public */
export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location';
@@ -14,8 +14,9 @@
* limitations under the License.
*/
import { ANNOTATION_SOURCE_LOCATION } from '.';
import { Entity, stringifyEntityRef } from '../entity';
import { LOCATION_ANNOTATION, SOURCE_LOCATION_ANNOTATION } from './annotation';
import { ANNOTATION_LOCATION } from './annotation';
/**
* Parses a string form location reference.
@@ -142,8 +143,8 @@ export function getEntitySourceLocation(entity: Entity): {
target: string;
} {
const locationRef =
entity.metadata?.annotations?.[SOURCE_LOCATION_ANNOTATION] ??
entity.metadata?.annotations?.[LOCATION_ANNOTATION];
entity.metadata?.annotations?.[ANNOTATION_SOURCE_LOCATION] ??
entity.metadata?.annotations?.[ANNOTATION_LOCATION];
if (!locationRef) {
throw new Error(
@@ -15,6 +15,9 @@
*/
export {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
ANNOTATION_SOURCE_LOCATION,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
SOURCE_LOCATION_ANNOTATION,