mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 03:03:06 +00:00
Some checks are pending
Deploy / preflight (push) Waiting to run
Deploy / verify (push) Blocked by required conditions
Deploy / deploy staging (teqo-staging) (push) Blocked by required conditions
Deploy / requeue when main advanced (push) Blocked by required conditions
Deploy / deploy production (teqo-1313) (push) Blocked by required conditions
35 lines
1.3 KiB
TypeScript
35 lines
1.3 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')
|
|
|
|
export const revalidateJinglesListing = () => revalidateCollectionListing('jingle')
|