( term: string, limit?: number, )
| 30 | // Searches the entire companies table by name (case-insensitive), rather than |
| 31 | // filtering an already-loaded page of results. |
| 32 | export async function searchCompanies( |
| 33 | term: string, |
| 34 | limit?: number, |
| 35 | ): Promise<CompanySearchResult[]> { |
| 36 | const trimmed = term.trim(); |
| 37 | |
| 38 | if (!trimmed) { |
| 39 | return []; |
| 40 | } |
| 41 | |
| 42 | const supabase = createClient(); |
| 43 | const baseQuery = () => |
| 44 | supabase |
| 45 | .from("companies") |
| 46 | .select("id, name, slug, image, location") |
| 47 | .ilike("name", `%${trimmed}%`) |
| 48 | .order("name", { ascending: true }); |
| 49 | |
| 50 | if (limit !== undefined) { |
| 51 | const { data } = await baseQuery().limit(limit); |
| 52 | return ((data ?? []) as CompanyRow[]).map(toSearchResult); |
| 53 | } |
| 54 | |
| 55 | const { data } = await fetchAllPages<CompanyRow>((from, to) => |
| 56 | baseQuery().range(from, to), |
| 57 | ); |
| 58 | |
| 59 | return (data ?? []).map(toSearchResult); |
| 60 | } |
| 61 | |
| 62 | export async function getMCPsClient({ |
| 63 | page = 1, |
no test coverage detected