catalog-model: add stringifyEntityRef and deprecate serializeEntityRef
Co-authored-by: Ben Lambert <ben@blam.sh> Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Co-authored-by: Fredrik Adelöw <freben@users.noreply.github.com> Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
afd45128a4
commit
67e13effa1
@@ -34,6 +34,7 @@ export {
|
||||
parseEntityName,
|
||||
parseEntityRef,
|
||||
serializeEntityRef,
|
||||
stringifyEntityRef,
|
||||
} from './ref';
|
||||
export {
|
||||
entityHasChanges,
|
||||
|
||||
@@ -172,6 +172,7 @@ export function parseEntityRef(
|
||||
* special/reserved characters, it outputs the string form, otherwise it
|
||||
* outputs the compound form.
|
||||
*
|
||||
* @deprecated Use `stringifyEntityRef` instead
|
||||
* @param ref The reference to serialize
|
||||
* @returns The same reference on either string or compound form
|
||||
*/
|
||||
@@ -212,6 +213,33 @@ export function serializeEntityRef(
|
||||
return `${kind ? `${kind}:` : ''}${namespace ? `${namespace}/` : ''}${name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an entity or entity name/reference, and returns the string form of an
|
||||
* entity ref.
|
||||
*
|
||||
* @param ref The reference to serialize
|
||||
* @returns The same reference on either string or compound form
|
||||
*/
|
||||
export function stringifyEntityRef(
|
||||
ref: Entity | { kind?: string; namespace?: string; name: string },
|
||||
): string {
|
||||
let kind;
|
||||
let namespace;
|
||||
let name;
|
||||
|
||||
if ('metadata' in ref) {
|
||||
kind = ref.kind;
|
||||
namespace = ref.metadata.namespace;
|
||||
name = ref.metadata.name;
|
||||
} else {
|
||||
kind = ref.kind;
|
||||
namespace = ref.namespace;
|
||||
name = ref.name;
|
||||
}
|
||||
|
||||
return `${kind ? `${kind}:` : ''}${namespace ? `${namespace}/` : ''}${name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares an entity to either a string reference or a compound reference.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user