feat: export locationSpecToLocationEntity
Export function `locationSpecToLocationEntity` which helps with converting `LocationSpec` to `LocationEntityV1alpha1` and hereby, make it usable in other packages/plugins. Change signature to be easier to extend in the future. Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': minor
|
||||
---
|
||||
|
||||
export `locationSpecToLocationEntity`
|
||||
@@ -16,6 +16,7 @@ import { Entity } from '@backstage/catalog-model';
|
||||
import { EntityPolicy } from '@backstage/catalog-model';
|
||||
import { GetEntitiesRequest } from '@backstage/catalog-client';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { LocationEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import { Logger } from 'winston';
|
||||
import { Permission } from '@backstage/plugin-permission-common';
|
||||
import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
|
||||
@@ -458,6 +459,12 @@ export type LocationSpec = {
|
||||
presence?: 'optional' | 'required';
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export function locationSpecToLocationEntity(opts: {
|
||||
location: LocationSpec;
|
||||
parentEntity?: Entity;
|
||||
}): LocationEntityV1alpha1;
|
||||
|
||||
// @public (undocumented)
|
||||
export function parseEntityYaml(
|
||||
data: Buffer,
|
||||
|
||||
@@ -24,7 +24,8 @@ export * from './api';
|
||||
export * from './catalog';
|
||||
export * from './ingestion';
|
||||
export * from './modules';
|
||||
export * from './search';
|
||||
export * from './processing';
|
||||
export * from './service';
|
||||
export * from './permissions';
|
||||
export * from './processing';
|
||||
export * from './search';
|
||||
export * from './service';
|
||||
export * from './util';
|
||||
|
||||
@@ -60,8 +60,10 @@ export class ConfigLocationEntityProvider implements EntityProvider {
|
||||
const type = location.getString('type');
|
||||
const target = location.getString('target');
|
||||
const entity = locationSpecToLocationEntity({
|
||||
type,
|
||||
target: type === 'file' ? path.resolve(target) : target,
|
||||
location: {
|
||||
type,
|
||||
target: type === 'file' ? path.resolve(target) : target,
|
||||
},
|
||||
});
|
||||
const locationKey = getEntityLocationRef(entity);
|
||||
return { entity, locationKey };
|
||||
|
||||
@@ -58,7 +58,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider {
|
||||
|
||||
return inner;
|
||||
});
|
||||
const entity = locationSpecToLocationEntity(location);
|
||||
const entity = locationSpecToLocationEntity({ location });
|
||||
await this.connection.applyMutation({
|
||||
type: 'delta',
|
||||
added: [{ entity, locationKey: getEntityLocationRef(entity) }],
|
||||
@@ -100,7 +100,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider {
|
||||
await tx<DbLocationsRow>('locations').where({ id }).del();
|
||||
return location;
|
||||
});
|
||||
const entity = locationSpecToLocationEntity(deleted);
|
||||
const entity = locationSpecToLocationEntity({ location: deleted });
|
||||
await this.connection.applyMutation({
|
||||
type: 'delta',
|
||||
added: [],
|
||||
@@ -122,7 +122,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider {
|
||||
const locations = await this.locations();
|
||||
|
||||
const entities = locations.map(location => {
|
||||
const entity = locationSpecToLocationEntity(location);
|
||||
const entity = locationSpecToLocationEntity({ location });
|
||||
return { entity, locationKey: getEntityLocationRef(entity) };
|
||||
});
|
||||
|
||||
|
||||
@@ -106,10 +106,10 @@ export class ProcessorOutputCollector {
|
||||
|
||||
this.deferredEntities.push({ entity, locationKey: location });
|
||||
} else if (i.type === 'location') {
|
||||
const entity = locationSpecToLocationEntity(
|
||||
i.location,
|
||||
this.parentEntity,
|
||||
);
|
||||
const entity = locationSpecToLocationEntity({
|
||||
location: i.location,
|
||||
parentEntity: this.parentEntity,
|
||||
});
|
||||
const locationKey = getEntityLocationRef(entity);
|
||||
this.deferredEntities.push({ entity, locationKey });
|
||||
} else if (i.type === 'relation') {
|
||||
|
||||
@@ -32,10 +32,14 @@ export function locationSpecToMetadataName(location: LocationSpec) {
|
||||
return `generated-${hash}`;
|
||||
}
|
||||
|
||||
export function locationSpecToLocationEntity(
|
||||
location: LocationSpec,
|
||||
parentEntity?: Entity,
|
||||
): LocationEntityV1alpha1 {
|
||||
/** @public */
|
||||
export function locationSpecToLocationEntity(opts: {
|
||||
location: LocationSpec;
|
||||
parentEntity?: Entity;
|
||||
}): LocationEntityV1alpha1 {
|
||||
const location = opts.location;
|
||||
const parentEntity = opts.parentEntity;
|
||||
|
||||
let ownLocation: string;
|
||||
let originLocation: string;
|
||||
if (parentEntity) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { locationSpecToLocationEntity } from './conversion';
|
||||
Reference in New Issue
Block a user