/** * Data access layer for Śrī Īśopaniṣad (ISO). * * Delegates to the generic book data layer (BFF API) for prose intro segments, * and to lib/api.ts for verse (mantra) lookups. */ import { getBookMeta, getIntroSegments, getIntroSegment, getContent, getSidebarItems, type BookMeta, type IntroSegment, type Chapter, type SidebarItem, } from "@/lib/books"; import { getSingleVerse, type VerseRecord } from "@/lib/api"; const CODE = "iso"; export type IsoMeta = BookMeta; export type IsoIntroSegment = IntroSegment; export type IsoChapter = Chapter; export type IsoSidebarItem = SidebarItem; export type IsoVerse = VerseRecord; export async function getIsoMeta() { return getBookMeta(CODE); } export async function getIsoIntroSegments() { return getIntroSegments(CODE); } export async function getIsoIntroSegment(slug: string) { return getIntroSegment(CODE, slug); } /** * A single verse/mantra by slug. * * ISO verses are stored with: book "iso", no division, * chapter = mantra number (0 for invocation), verse = 1. */ export async function getIsoVerse(slug: string): Promise { let mantraNum: number; if (slug === "invocation") { mantraNum = 0; } else { const num = parseInt(slug, 10); if (isNaN(num) || num < 1 || num > 18) return null; mantraNum = num; } return getSingleVerse(CODE, null, mantraNum, 1); } export async function getIsoContent( slug: string, ): Promise { // Try as verse/mantra first (numeric slug or "invocation") if (slug === "invocation" || /^\d+$/.test(slug)) { const verse = await getIsoVerse(slug); if (verse) return verse; } // Fall back to prose content (intro segments, etc.) return getContent(CODE, slug); } export async function getIsoSidebarItems() { return getSidebarItems(CODE); }