Files
dbx/apps/desktop/src/lib/mongo/mongoCapabilities.ts
T

30 lines
1.6 KiB
TypeScript

import type { ConnectionConfig } from "@/types/database";
import { connectionIsEffectivelyReadOnly } from "@/lib/database/readOnlyWriteAccess";
type MongoConnectionProfile = Pick<ConnectionConfig, "db_type" | "driver_profile" | "read_only"> & Partial<Pick<ConnectionConfig, "id">>;
/** Accept historical Legacy profile spellings while persisted configs are normalized. */
export function isMongoLegacyDriverProfile(driverProfile?: string): boolean {
const profile = driverProfile?.trim().toLowerCase();
return profile === "mongodb-legacy" || profile === "mongodb_legacy" || profile === "legacy";
}
/** Capabilities implemented by both the native driver and the Legacy Agent. */
export function supportsMongoAllDriverMutations(connection?: MongoConnectionProfile): boolean {
return connection?.db_type === "mongodb" && !connectionIsEffectivelyReadOnly(connection);
}
/** MongoDB views do not own indexes; collections and time-series collections do. */
export function mongoCollectionSupportsIndexes(collectionKind?: string): boolean {
return collectionKind?.trim().toLowerCase() !== "view";
}
export function supportsMongoIndexMutations(connection?: MongoConnectionProfile, collectionKind?: string): boolean {
return supportsMongoAllDriverMutations(connection) && mongoCollectionSupportsIndexes(collectionKind);
}
/** Capabilities which require the native Rust MongoDB driver. */
export function supportsNativeMongoDriverMutations(connection?: MongoConnectionProfile): boolean {
return supportsMongoAllDriverMutations(connection) && !isMongoLegacyDriverProfile(connection?.driver_profile);
}