mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 01:10:15 -04:00
e4d76be290
## Before Partners fetch is showing stale data from a few months ago ## After Partners fetch can be revalidated by tag. The revalidation will be triggered by a DB function when the partners table is changed.
38 lines
1018 B
TypeScript
38 lines
1018 B
TypeScript
/**
|
|
* Next.js extends native `fetch` with revalidation options.
|
|
*
|
|
* This module provides some reusable utility functions to set revalidation
|
|
* options for `fetch`, for example when it needs to be passed to a
|
|
* third-party API.
|
|
*/
|
|
|
|
import { ONE_DAY_IN_SECONDS } from './helpers.time'
|
|
|
|
export const REVALIDATION_TAGS = {
|
|
GRAPHQL: 'graphql',
|
|
PARTNERS: 'partners',
|
|
WRAPPERS: 'wrappers',
|
|
} as const
|
|
// Casting to avoid problems with using this as a Zod enum, TypeScript does
|
|
// not recognize the casted type as a supertype of the original type
|
|
export const VALID_REVALIDATION_TAGS = Object.values(REVALIDATION_TAGS) as unknown as readonly [
|
|
string,
|
|
...string[],
|
|
]
|
|
|
|
function fetchWithNextOptions({
|
|
next,
|
|
cache,
|
|
}: {
|
|
next?: NextFetchRequestConfig
|
|
cache?: RequestInit['cache']
|
|
}) {
|
|
return (info: RequestInfo) => fetch(info, { next, cache })
|
|
}
|
|
|
|
const fetchRevalidatePerDay = fetchWithNextOptions({
|
|
next: { revalidate: ONE_DAY_IN_SECONDS },
|
|
})
|
|
|
|
export { fetchRevalidatePerDay, fetchWithNextOptions }
|