import { getDb } from "../index"; import { Collection, Filter } from "mongodb"; import { Prompt } from "./prompts.types"; import { KnownProductKey } from "../../talkpilot"; export const getPromptsCollection = (): Collection => { return getDb().collection("prompts"); }; /** * Get a prompt by its unique name. * @param name prompt name * @returns the prompt or null if not found */ export const getPromptByName = async ( name: string, ): Promise => { return await getPromptsCollection().findOne({ name }); }; /** * Find prompts by filter. * @param filter filter to apply * @returns array of matching prompts */ export const findPrompts = async ( filter: Filter = {}, ): Promise => { return await getPromptsCollection().find(filter).toArray(); }; /** * Get all prompts. * @returns array of all prompts */ export const getAllPrompts = async (): Promise => { return await findPrompts(); }; /** * Get all prompts for a given product. * @param productName product key * @returns array of matching prompts */ export const getPromptsByProduct = async ( productName: KnownProductKey, ): Promise => { return await findPrompts({ productName }); };