mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-22 22:15:20 +00:00
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:
parent
4ee7d12085
commit
7ddd0feb0f
2 changed files with 18 additions and 11 deletions
|
|
@ -19,16 +19,20 @@ export async function getGlobal<Slug extends Global>(slug: Slug, depth?: number)
|
||||||
|
|
||||||
const getTag = (slug: string) => `global_${slug}`
|
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) => {
|
export const getCachedGlobal = <Slug extends Global>(slug: Slug, depth?: number) => {
|
||||||
const tag = getTag(slug)
|
const tag = getTag(slug)
|
||||||
const cacheKey = `${tag}:${depth ?? 0}`
|
const cacheKey = `${tag}:${depth ?? 0}`
|
||||||
let factory = cachedGlobalFactories.get(cacheKey)
|
const existing = cachedGlobalFactories.get(cacheKey) as CachedGlobalFactory<Slug> | undefined
|
||||||
if (!factory) {
|
if (existing) return existing
|
||||||
factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], { tags: [tag] })
|
|
||||||
cachedGlobalFactories.set(cacheKey, factory)
|
const factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], {
|
||||||
}
|
tags: [tag],
|
||||||
|
}) as CachedGlobalFactory<Slug>
|
||||||
|
cachedGlobalFactories.set(cacheKey, factory as CachedGlobalFactory)
|
||||||
return factory
|
return factory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,14 @@ const nucleusOptionsSelect = {
|
||||||
slug: true,
|
slug: true,
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
type NucleusOptionDoc = Pick<ElectoralNucleus, 'id' | 'name' | 'slug'>
|
||||||
|
|
||||||
export const loadAccessibleNucleusOptions = async (
|
export const loadAccessibleNucleusOptions = async (
|
||||||
payload: Pick<Payload, 'find'>,
|
payload: Pick<Payload, 'find'>,
|
||||||
user: CampaignUser,
|
user: CampaignUser,
|
||||||
coordinatorNucleusIds?: number[],
|
coordinatorNucleusIds?: number[],
|
||||||
): Promise<SupporterNucleusOption[]> => {
|
): Promise<SupporterNucleusOption[]> => {
|
||||||
let result: { docs: ElectoralNucleus[] }
|
let result: { docs: NucleusOptionDoc[] }
|
||||||
|
|
||||||
if (user.role === 'coordenador' && coordinatorNucleusIds !== undefined) {
|
if (user.role === 'coordenador' && coordinatorNucleusIds !== undefined) {
|
||||||
if (coordinatorNucleusIds.length === 0) return []
|
if (coordinatorNucleusIds.length === 0) return []
|
||||||
|
|
@ -86,10 +88,11 @@ export const loadAccessibleNucleusOptions = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.docs.map((nucleus) => {
|
return result.docs.map((nucleus) => ({
|
||||||
const doc = nucleus as ElectoralNucleus
|
id: nucleus.id,
|
||||||
return { id: doc.id, name: doc.name, slug: doc.slug }
|
name: nucleus.name,
|
||||||
})
|
slug: nucleus.slug,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadSupporterListPageData = async (
|
export const loadSupporterListPageData = async (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue