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.
Type Parameters
Section titled “Type Parameters”TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string
Parameters
Section titled “Parameters”TCollectionSlug
The owning collection’s slug, used only to infer the document type.
resolve
Section titled “resolve”(props) => string | Promise<string | undefined> | undefined
The resolver, checked against that collection’s real document.
Returns
Section titled “Returns”The { server } wrapper, re-typed to the loose public url form.
Example
Section titled “Example”// 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; }), }, },});