({
page = 1,
limit = 36,
fetchAll = false,
}: {
page?: number;
limit?: number;
fetchAll?: boolean;
} = {})
| 331 | // --------------------------------------------------------------------------- |
| 332 | |
| 333 | export async function getPlugins({ |
| 334 | page = 1, |
| 335 | limit = 36, |
| 336 | fetchAll = false, |
| 337 | }: { |
| 338 | page?: number; |
| 339 | limit?: number; |
| 340 | fetchAll?: boolean; |
| 341 | } = {}): Promise<{ data: PluginRow[] | null; error: unknown }> { |
| 342 | "use cache"; |
| 343 | cacheLife("hours"); |
| 344 | cacheTag("plugins"); |
| 345 | |
| 346 | const supabase = await createClient(); |
| 347 | |
| 348 | const baseQuery = () => |
| 349 | supabase |
| 350 | .from("plugins") |
| 351 | .select("*, plugin_components(*)") |
| 352 | .eq("active", true) |
| 353 | .order("created_at", { ascending: false }); |
| 354 | |
| 355 | if (fetchAll) { |
| 356 | return fetchAllPages<PluginRow>(async (from, to) => { |
| 357 | const { data, error } = await baseQuery().range(from, to); |
| 358 | return { data: data as PluginRow[] | null, error }; |
| 359 | }, 100); |
| 360 | } |
| 361 | |
| 362 | const { data, error } = await baseQuery() |
| 363 | .limit(limit) |
| 364 | .range((page - 1) * limit, page * limit - 1); |
| 365 | |
| 366 | return { data: data as PluginRow[] | null, error }; |
| 367 | } |
| 368 | |
| 369 | // Slugs of every `rule` component on an active plugin. Legacy rule URLs |
| 370 | // (`/{rule-slug}`) prerender a redirect to the parent plugin, and there are |
no test coverage detected