Data sources
@olgax.com/datasource is a narrow resolver layer: a component declares "pull N items from a Payload collection, filtered by one field" and receives them as a resolved items prop. It deliberately does not support a general query language - one equality filter, a limit, nothing more.
// lib/puck.config.ts - shared by the editor and the render route
import { createCollectionResolverFetch } from "@olgax.com/datasource";
import { registerRelatedPages } from "@olgax.com/components";
registerRelatedPages(createCollectionResolverFetch("/api/related-pages"));// app/(frontend)/api/related-pages/route.ts - the Route Handler it calls
import { NextResponse } from "next/server";
import { queryCollectionFromSearchParams } from "@olgax.com/datasource";
import { getPayloadClient } from "@/lib/payload";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const items = await queryCollectionFromSearchParams(getPayloadClient, searchParams);
return NextResponse.json(items);
}The author sets collection, optionally filterField/filterValue, and limit in the Puck editor - items is resolved automatically (via Puck's resolveData) and marked read-only. See @olgax.com/components's RelatedPages block for a complete example.
createCollectionResolverFetch is safe to share with the client <Puck> editor because it only ever calls fetch() - the actual Payload query runs inside the Route Handler, which is always server-only. A direct createCollectionResolver(getPayload) variant also exists, but it must only be used in a config that never reaches client-bundled code.