import { getDb } from "../index"; import { Collection, Filter } from "mongodb"; import { InternalModel } from "./internalModels.types"; import { INTERNAL_MODELS_COLLECTION } from "./internalModels.constants"; export const getInternalModelsCollection = (): Collection => { return getDb().collection(INTERNAL_MODELS_COLLECTION); }; /** * Get an internal model config by its unique name */ export const getInternalModelByName = async ( name: string ): Promise => { return await getInternalModelsCollection().findOne({ name }); }; /** * Find internal models by filter. */ export const findInternalModels = async ( filter: Filter = {} ): Promise => { return await getInternalModelsCollection().find(filter).toArray(); }; /** * Get all internal models. */ export const getAllInternalModels = async (): Promise => { return await findInternalModels(); };