mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 10:43:07 +00:00
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import 'server-only'
|
|
|
|
import type { Config } from '@/payload-types'
|
|
|
|
import { revalidateTag } from 'next/cache'
|
|
|
|
// Tag vocabulary + revalidation helpers only. This module is imported by
|
|
// collections (afterChange hooks), which payload.config.ts aggregates — so it
|
|
// must NOT import `@payload-config`, or the module graph becomes circular
|
|
// (payload.config → collection → here → payload.config). Config-dependent
|
|
// cached reads live in `documentReads.ts`.
|
|
|
|
type Collection = keyof Config['collections']
|
|
|
|
export const getDocumentCacheTag = <Slug extends Collection>(
|
|
collection: Slug,
|
|
id: string | number,
|
|
) => `document_${collection}:${id}`
|
|
|
|
export const revalidateDocumentById = <Slug extends Collection>(
|
|
collection: Slug,
|
|
id: string | number,
|
|
) => revalidateTag(getDocumentCacheTag(collection, id))
|
|
|
|
export const getCollectionListingTag = <Slug extends Collection>(collection: Slug) =>
|
|
`${collection}s`
|
|
|
|
const revalidateCollectionListing = <Slug extends Collection>(collection: Slug) =>
|
|
revalidateTag(getCollectionListingTag(collection))
|
|
|
|
export const revalidatePostsListing = () => revalidateCollectionListing('post')
|
|
|
|
export const revalidateShareLinksListing = () => revalidateCollectionListing('shareLink')
|