cosmos-explorer/src/Common/OfferUtility.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-11-19 17:13:11 -08:00
import { Offer, SDKOfferDefinition } from "../Contracts/DataModels";
import { OfferResponse } from "@azure/cosmos";
import { HttpHeaders } from "./Constants";
2020-11-19 17:13:11 -08:00
export const parseSDKOfferResponse = (offerResponse: OfferResponse): Offer | undefined => {
const offerDefinition: SDKOfferDefinition | undefined = offerResponse?.resource;
if (!offerDefinition) {
return undefined;
}
2020-11-19 17:13:11 -08:00
const offerContent = offerDefinition.content;
if (!offerContent) {
return undefined;
}
const minimumThroughput = offerContent.collectionThroughputInfo?.minimumRUForCollection;
const autopilotSettings = offerContent.offerAutopilotSettings;
if (autopilotSettings && autopilotSettings.maxThroughput && minimumThroughput) {
2020-11-19 17:13:11 -08:00
return {
id: offerDefinition.id,
autoscaleMaxThroughput: autopilotSettings.maxThroughput,
manualThroughput: undefined,
minimumThroughput,
offerDefinition,
2021-01-20 09:15:01 -06:00
offerReplacePending: offerResponse.headers?.[HttpHeaders.offerReplacePending] === "true",
2020-11-19 17:13:11 -08:00
};
}
return {
id: offerDefinition.id,
autoscaleMaxThroughput: undefined,
manualThroughput: offerContent.offerThroughput,
minimumThroughput,
offerDefinition,
2021-01-20 09:15:01 -06:00
offerReplacePending: offerResponse.headers?.[HttpHeaders.offerReplacePending] === "true",
2020-11-19 17:13:11 -08:00
};
};