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 ); };