Files
bmp-website-2026/src/utilities/publicationQuery.ts
2026-07-31 19:03:07 +02:00

38 lines
1.0 KiB
TypeScript

export type PublicationQueryOptions = Readonly<{
draft: boolean
overrideAccess: boolean
}>
const publicPublicationQuery = Object.freeze({
draft: false,
overrideAccess: false,
}) satisfies PublicationQueryOptions
const previewPublicationQuery = Object.freeze({
draft: true,
overrideAccess: true,
}) satisfies PublicationQueryOptions
/**
* Keeps public Local API reads access-controlled while allowing the authenticated
* Next.js draft-mode route to intentionally load the latest draft versions.
*/
export function getPublicationQueryOptions(isPreview: boolean): PublicationQueryOptions {
return isPreview ? previewPublicationQuery : publicPublicationQuery
}
/**
* Adds an explicit status predicate for public indexes such as sitemaps while
* retaining the same anonymous access and draft behavior as public routes.
*/
export function getPublicPublishedQueryOptions() {
return {
...getPublicationQueryOptions(false),
where: {
_status: {
equals: 'published' as const,
},
},
}
}