Skip to content

livePreviewUrl

livePreviewUrl<TCollectionSlug>(slug, resolve): LivePreviewServerUrl

Defined in: packages/core/src/livePreview/urlHelpers.ts:42

Types a collection’s { server } preview-URL resolver against a real collection — the textValidator of live preview.

Needed for the same reason field validators need theirs: defineCollection is a per-collection factory with no access to the project’s data model, so a resolver declared there has nothing to type ctx from. Passing the slug types doc; the DataModel type argument types ctx.

NOT needed in the root admin.livePreview.collections map — the key supplies the document type, so a resolver declared there is written inline. ctx is the project’s own VexQueryCtx in every form, from the DataModel vex generate writes into the type augmentation; no model is threaded by hand.

TCollectionSlug extends string

TCollectionSlug

The owning collection’s slug, used only to infer the document type.

(props) => string | Promise<string | undefined> | undefined

The resolver, checked against that collection’s real document.

LivePreviewServerUrl

The { server } wrapper, re-typed to the loose public url form.

// Beside the collection. In the root map, write the resolver inline instead.
defineCollection({
slug: "authors",
admin: {
livePreview: {
url: livePreviewUrl<"authors">("authors", async ({ ctx, doc }) => {
const page = await ctx.db
.query("pages")
.withIndex("by_author", (q) => q.eq("author", doc._id))
.first();
return page ? `/${page.slug}` : undefined;
}),
},
},
});