import { sanityFetch, type DynamicFetchOptions } from "@/sanity/lib/live"; import { PAGE_QUERY, PAGES_SLUGS_QUERY } from "@/sanity/queries/page"; import { NAVIGATION_QUERY } from "@/sanity/queries/navigation"; import { SETTINGS_QUERY } from "@/sanity/queries/settings"; import { POST_QUERY, POSTS_QUERY, POSTS_SLUGS_QUERY, } from "@/sanity/queries/post"; import { SERVICE_QUERY, SERVICES_QUERY, SERVICES_SLUGS_QUERY, } from "@/sanity/queries/service"; import { ALL_FAQS_QUERY } from "@/sanity/queries/faqs"; import { VENUES_QUERY } from "@/sanity/queries/venue"; import { TESTIMONIALS_QUERY } from "@/sanity/queries/testimonial"; import { PAGE_QUERY_RESULT, POST_QUERY_RESULT, POSTS_QUERY_RESULT, NAVIGATION_QUERY_RESULT, SETTINGS_QUERY_RESULT, SERVICE_QUERY_RESULT, SERVICES_QUERY_RESULT, ALL_FAQS_QUERY_RESULT, VENUES_QUERY_RESULT, TESTIMONIALS_QUERY_RESULT, } from "@/sanity.types"; export async function fetchSanityPageBySlug({ slug, perspective, stega, }: { slug: string; } & DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: PAGE_QUERY, params: { slug }, perspective, stega, }); return data as PAGE_QUERY_RESULT; } catch (err) { return null; } } export async function fetchSanityPosts({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: POSTS_QUERY, perspective, stega, }); return (data as POSTS_QUERY_RESULT) ?? []; } catch (err) { return []; } } export async function fetchSanityPostBySlug({ slug, perspective, stega, }: { slug: string; } & DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: POST_QUERY, params: { slug }, perspective, stega, }); return data as POST_QUERY_RESULT; } catch (err) { return null; } } export async function fetchSanityNavigation({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: NAVIGATION_QUERY, perspective, stega, }); return (data as NAVIGATION_QUERY_RESULT) ?? []; } catch (err) { return []; } } export async function fetchSanitySettings({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: SETTINGS_QUERY, perspective, stega, }); return data as SETTINGS_QUERY_RESULT; } catch (err) { return null; } } export async function fetchSanityServiceBySlug({ slug, perspective, stega, }: { slug: string; } & DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: SERVICE_QUERY, params: { slug }, perspective, stega, }); return data as SERVICE_QUERY_RESULT; } catch (err) { return null; } } export async function fetchSanityServices({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: SERVICES_QUERY, perspective, stega, }); return (data as SERVICES_QUERY_RESULT) ?? []; } catch (err) { return []; } } export async function fetchSanityFaqs({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: ALL_FAQS_QUERY, perspective, stega, }); return (data as ALL_FAQS_QUERY_RESULT) ?? []; } catch (err) { return []; } } export type SanityVenueItem = VENUES_QUERY_RESULT[number]; export async function fetchSanityVenues({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: VENUES_QUERY, perspective, stega, }); return (data as VENUES_QUERY_RESULT) ?? []; } catch (err) { return []; } } export async function fetchSanityTestimonials({ perspective, stega, }: DynamicFetchOptions): Promise { "use cache"; try { const { data } = await sanityFetch({ query: TESTIMONIALS_QUERY, perspective, stega, }); return (data as TESTIMONIALS_QUERY_RESULT) ?? []; } catch (err) { return []; } } export async function getCurrentYear(): Promise { "use cache"; return new Date().getFullYear(); } export { PAGES_SLUGS_QUERY, POSTS_SLUGS_QUERY, SERVICES_SLUGS_QUERY };