Fix getCachedGlobal typing so production builds typecheck again.

The Onda 0 factory Map erased Slug generics to any, breaking keyword/social metadata inference during next build.
This commit is contained in:
Francisco Ignácio Fontoura Solla 2026-07-19 04:27:04 -03:00
parent 4ee7d12085
commit 7ddd0feb0f
2 changed files with 18 additions and 11 deletions

View file

@ -19,16 +19,20 @@ export async function getGlobal<Slug extends Global>(slug: Slug, depth?: number)
const getTag = (slug: string) => `global_${slug}`
const cachedGlobalFactories = new Map<string, ReturnType<typeof unstable_cache>>()
type CachedGlobalFactory<Slug extends Global = Global> = () => Promise<Config['globals'][Slug]>
const cachedGlobalFactories = new Map<string, CachedGlobalFactory>()
export const getCachedGlobal = <Slug extends Global>(slug: Slug, depth?: number) => {
const tag = getTag(slug)
const cacheKey = `${tag}:${depth ?? 0}`
let factory = cachedGlobalFactories.get(cacheKey)
if (!factory) {
factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], { tags: [tag] })
cachedGlobalFactories.set(cacheKey, factory)
}
const existing = cachedGlobalFactories.get(cacheKey) as CachedGlobalFactory<Slug> | undefined
if (existing) return existing
const factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], {
tags: [tag],
}) as CachedGlobalFactory<Slug>
cachedGlobalFactories.set(cacheKey, factory as CachedGlobalFactory)
return factory
}

View file

@ -52,12 +52,14 @@ const nucleusOptionsSelect = {
slug: true,
} as const
type NucleusOptionDoc = Pick<ElectoralNucleus, 'id' | 'name' | 'slug'>
export const loadAccessibleNucleusOptions = async (
payload: Pick<Payload, 'find'>,
user: CampaignUser,
coordinatorNucleusIds?: number[],
): Promise<SupporterNucleusOption[]> => {
let result: { docs: ElectoralNucleus[] }
let result: { docs: NucleusOptionDoc[] }
if (user.role === 'coordenador' && coordinatorNucleusIds !== undefined) {
if (coordinatorNucleusIds.length === 0) return []
@ -86,10 +88,11 @@ export const loadAccessibleNucleusOptions = async (
})
}
return result.docs.map((nucleus) => {
const doc = nucleus as ElectoralNucleus
return { id: doc.id, name: doc.name, slug: doc.slug }
})
return result.docs.map((nucleus) => ({
id: nucleus.id,
name: nucleus.name,
slug: nucleus.slug,
}))
}
export const loadSupporterListPageData = async (