moved out the matchers

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-11-23 16:39:41 +01:00
parent 969d028b93
commit a52d988201
2 changed files with 17 additions and 17 deletions
@@ -17,6 +17,18 @@
import { InputError } from '@backstage/errors';
import { EntityMatcherFn } from './types';
const allowedMatchers: Record<string, EntityMatcherFn> = {
labels: entity => {
return Object.keys(entity.metadata.labels ?? {}).length > 0;
},
annotations: entity => {
return Object.keys(entity.metadata.annotations ?? {}).length > 0;
},
links: entity => {
return (entity.metadata.links ?? []).length > 0;
},
};
/**
* Matches on the non-empty presence of different parts of the entity
*/
@@ -24,18 +36,6 @@ export function createHasMatcher(
parameters: string[],
onParseError: (error: Error) => void,
): EntityMatcherFn {
const allowedMatchers: Record<string, EntityMatcherFn> = {
labels: entity => {
return Object.keys(entity.metadata.labels ?? {}).length > 0;
},
annotations: entity => {
return Object.keys(entity.metadata.annotations ?? {}).length > 0;
},
links: entity => {
return (entity.metadata.links ?? []).length > 0;
},
};
const matchers = parameters.flatMap(parameter => {
const matcher = allowedMatchers[parameter.toLocaleLowerCase('en-US')];
if (!matcher) {
@@ -17,6 +17,11 @@
import { InputError } from '@backstage/errors';
import { EntityMatcherFn } from './types';
const allowedMatchers: Record<string, EntityMatcherFn> = {
orphan: entity =>
Boolean(entity.metadata.annotations?.['backstage.io/orphan']),
};
/**
* Matches on different semantic properties of the entity
*/
@@ -24,11 +29,6 @@ export function createIsMatcher(
parameters: string[],
onParseError: (error: Error) => void,
): EntityMatcherFn {
const allowedMatchers: Record<string, EntityMatcherFn> = {
orphan: entity =>
Boolean(entity.metadata.annotations?.['backstage.io/orphan']),
};
const matchers = parameters.flatMap(parameter => {
const matcher = allowedMatchers[parameter.toLocaleLowerCase('en-US')];
if (!matcher) {