UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

55 lines (46 loc) 1.3 kB
/** * Copyright Super iPaaS Integration LLC, an IBM Company 2024 */ import { BaseAsset } from "../../model/assets-model.js"; import { isNullOrUndefined } from "../common/data-helper.js"; import { COLON, POLICY } from "../../constants/app-constants.js"; import { isPolicyKind } from "./asset-kinds/policy-helper.js"; const isValidAsset = (asset: BaseAsset) => { if (isNullOrUndefined(asset)) { return false; } if (isNullOrUndefined(asset.kind)) { return false; } if (isNullOrUndefined(asset.metadata)) { return false; } return ( !isNullOrUndefined(asset.metadata.name) && !isNullOrUndefined(asset.metadata.version) ); }; const isValidAssetRefValue = (assetRefValue: string): boolean => { if (isNullOrUndefined(assetRefValue)) { return false; } return ( assetRefValue.split(COLON).length >= 1 && assetRefValue.split(COLON).length <= 3 ); }; const hasNamespace = (asset: BaseAsset): boolean => { if (isNullOrUndefined(asset) || isNullOrUndefined(asset.metadata)) { return false; } return !isNullOrUndefined(asset.metadata.namespace); }; const getTargetModelAssetKind = (kind: string) => { return isPolicyKind(kind) ? POLICY : kind; }; export { isValidAsset, hasNamespace, isValidAssetRefValue, getTargetModelAssetKind, };