@apistudio/apim-cli
Version:
CLI for API Management Products
57 lines (45 loc) • 1.69 kB
text/typescript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import {
BaseAsset,
PolicySeqAsset,
PolicySeqSpec,
RefObj,
} from "../../../model/assets-model.js";
import { isNullOrUndefined } from "../../common/data-helper.js";
import { AssetCacheModel } from "../../../model/asset-cache-model.js";
import { POLICY } from "../../../constants/app-constants.js";
function addAssetRefValuesForStage(
refObjects: RefObj[],
result: AssetCacheModel[]
) {
if (!isNullOrUndefined(refObjects)) {
refObjects.forEach((policy) => {
if (!isNullOrUndefined(policy.$ref)) {
result.push({ kind: POLICY, ref: policy.$ref, isNewlyAdded: true });
}
});
}
}
const getRefsFromPolicySeqAsset = (asset: BaseAsset): AssetCacheModel[] => {
const policySeqAsset = asset as unknown as PolicySeqAsset;
const spec: PolicySeqSpec = policySeqAsset.spec;
const result: AssetCacheModel[] = [];
const transport = spec.transport as RefObj[];
addAssetRefValuesForStage(transport, result);
const monitoring = spec.monitoring as RefObj[];
addAssetRefValuesForStage(monitoring, result);
const reqProcessing = spec["req-processing"] as RefObj[];
addAssetRefValuesForStage(reqProcessing, result);
const respProcessing = spec["res-processing"] as RefObj[];
addAssetRefValuesForStage(respProcessing, result);
const iam = spec.iam as RefObj[];
addAssetRefValuesForStage(iam, result);
const errorProcessing = spec["error-handling"] as RefObj[];
addAssetRefValuesForStage(errorProcessing, result);
const routing = spec.routing as RefObj[];
addAssetRefValuesForStage(routing, result);
return result;
};
export { getRefsFromPolicySeqAsset };