cosmos-explorer/src/Shared/AddCollectionUtility.ts

24 lines
918 B
TypeScript
Raw Normal View History

import { any } from "underscore";
import { CollectionCreationDefaults } from "../Contracts/ViewModels";
import Explorer from "../Explorer/Explorer";
export const getMaxThroughput = (defaults: CollectionCreationDefaults, container: Explorer): number => {
const throughput = defaults.throughput.unlimited;
if (typeof throughput === "number") {
return throughput;
} else {
return _exceedsThreshold(throughput.collectionThreshold, container)
? throughput.greatThanThreshold
: throughput.lessThanOrEqualToThreshold;
}
};
const _exceedsThreshold = (unlimitedThreshold: number, container: Explorer): boolean => {
const databases = (container && container.databases && container.databases()) || [];
return any(
databases,
database =>
database && database.collections && database.collections() && database.collections().length > unlimitedThreshold
);
};