Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ragaeeb/shamela/llms.txt

Use this file to discover all available pages before exploring further.

Function Signature

denormalizeBooks(master: MasterData): DenormalizedBook[]

Description

Resolves the relationships within the MasterData object, returning a flat list of books where author and category IDs have been replaced with their respective objects. It also parses complex fields like metadata and pdf_links from JSON strings into structured objects. This transformation makes the data easier to work with by eliminating the need for manual ID lookups and JSON parsing.

Parameters

master
MasterData
required
The master data object returned from getMaster() containing authors, books, categories, and version information

Returns

Returns an array of DenormalizedBook objects:
DenormalizedBook[]
array
required

Example

import { getMaster, denormalizeBooks } from 'shamela';

const master = await getMaster();
const books = denormalizeBooks(master);

// Access denormalized data directly
const book = books[0];

console.log(`Book: ${book.name}`);
console.log(`Author: ${book.author.name}`);
console.log(`Category: ${book.category.name}`);
console.log(`Version: ${book.version}`);
console.log(`Date: ${book.metadata.date}`);

// Check if book has co-authors
if (book.metadata.coauthor) {
  console.log('Co-authors:');
  book.metadata.coauthor.forEach(author => {
    console.log(`  - ${author.name}`);
  });
}

// Access PDF information
if (book.pdf_links?.files) {
  console.log('PDF files:');
  book.pdf_links.files.forEach(file => {
    console.log(`  - ${file.name} ${file.part || ''}`);
  });
}

// Filter books by category
const categoryName = 'الحديث الشريف';
const hadithBooks = books.filter(b => b.category.name === categoryName);
console.log(`Books in ${categoryName}: ${hadithBooks.length}`);

Use Cases

  1. Building Search Interfaces: Filter and search books without manual ID lookups
  2. Creating Library Catalogs: Display books with full author and category information
  3. Data Analysis: Analyze book collections with easy access to relationships
  4. API Responses: Serve denormalized data to clients for better performance

Performance Notes

  • This function processes all books in the master database
  • For large datasets (10,000+ books), consider caching the result
  • The transformation is synchronous and completes quickly (typically < 100ms)

Build docs developers (and LLMs) love