Skip to content

Conversation

@sharshi
Copy link
Member

@sharshi sharshi commented Jan 30, 2026

Summary

This PR introduces two new entry points to the @shafeh/tanach package to support size-constrained environments (edge functions, serverless, etc.):

  1. /preferred – A lightweight module (~50 KB) for preferred verse lookups without importing the full Tanach data
  2. /dynamic – An async module that fetches per-book JSON files on-demand instead of bundling the entire 6+ MB dataset

Key Changes

  • New entry points in package.json: Added exports for ./preferred and ./dynamic alongside the main entry point
  • Build system updates: Modified vite.config.ts to build three separate entry points with proper file naming (index.cjs/index.js, preferred.cjs/preferred.js, dynamic.cjs/dynamic.js)
  • Data generation scripts:
    • scripts/generate-preferred-with-text.ts – Generates src/preferred-verses-data.ts with 457 preferred verses and their embedded text
    • scripts/generate-book-data.ts – Splits the full Tanach data into 24 per-book JSON files (5–215 KB each) for dynamic loading
  • New modules:
    • src/preferred.ts – Synchronous preferred verse lookups with embedded text (no data import needed)
    • src/dynamic.ts – Async data functions that fetch books on-demand from a configurable base URL
  • Comprehensive tests:
    • src/preferred.test.ts – Tests for the lightweight preferred verses module
    • src/dynamic.test.ts – Tests for dynamic loading with mocked fetch
  • Letter normalization: Updated src/preferred-verses.ts to normalize final-form Hebrew letters (ם→מ, ך→כ, etc.) in lookup keys for consistency

Implementation Details

  • Preferred verses data: The preferredVersesWithText array is auto-generated and includes full verse text, Hebrew/English book names, and metadata—enabling zero-dependency preferred verse lookups
  • Dynamic module: Implements in-memory caching of fetched books and provides a configure() function to set the base URL for book JSON files. All data functions are async and fetch books in parallel
  • Hebrew letter utilities: Shared utility functions (normalizeHebrewLetter, extractHebrewLetters, getAllLetterForms) are available in both /preferred and /dynamic modules
  • Build process: The main build script now runs Vite, TypeScript declaration generation, and the book data generation script in sequence

Size Benefits

  • Main entry point: ~6+ MB (full Tanach data bundled)
  • Preferred entry point: ~50 KB (457 preferred verses only)
  • Dynamic entry point: ~5 KB (no data bundled; books fetched on-demand at 5–215 KB each)

https://claude.ai/code/session_01XDYfksN1mSwXwrduTMtrtQ

…on size

The full library bundles 6+ MB of Tanach data into a single entry point,
causing edge functions that only need preferred verse lookups to exceed
Vercel's 1 MB size limit (2.69 MB). This adds a separate subpath export
at @shafeh/tanach/preferred (122 KB) with pre-embedded verse text, so
consumers can import only what they need.

Changes:
- Add src/preferred-verses-data.ts with 457 preferred verses + embedded text
- Add src/preferred.ts as lightweight entry point (no data.ts dependency)
- Add scripts/generate-preferred-with-text.ts to regenerate enriched data
- Update vite.config.ts with multi-entry build (index + preferred)
- Add ./preferred subpath export in package.json
- Fix final-form letter normalization bug in preferred verse map lookup
- Fix build order: vite build first, then tsc --emitDeclarationOnly

https://claude.ai/code/session_01XDYfksN1mSwXwrduTMtrtQ
…ions

The full library bundles 6+ MB of Tanach data, exceeding Vercel's 1 MB
edge function limit. The new @shafeh/tanach/dynamic entry point (8 KB)
fetches per-book JSON files at runtime instead of bundling them, giving
access to the full Tanach data without any size constraints.

Changes:
- Add src/dynamic.ts: async API that fetches per-book data on demand
  - All data functions (tanach, findPesukimByName, etc.) are async
  - Books fetched in parallel and cached in memory
  - getPreferredPasukForName remains sync (uses embedded data)
  - configure({ baseUrl }) sets where to fetch book JSON files
  - clearCache() frees memory after use
- Add scripts/generate-book-data.ts: splits data.ts into 39 JSON files
  (largest book: Yirmiyahu at 214 KB, smallest: Ovadiah at 3 KB)
- Add ./dynamic subpath export in package.json
- Build now generates dist/books/*.json alongside bundles
- Add comprehensive tests with mocked fetch (131 total tests pass)

Usage in edge function:
  import { configure, findPesukimByName } from '@shafeh/tanach/dynamic';
  configure({ baseUrl: 'https://myapp.com/data/tanach/books' });
  const verses = await findPesukimByName("ד", "ד"); // no maxResults cap

https://claude.ai/code/session_01XDYfksN1mSwXwrduTMtrtQ
@sharshi sharshi merged commit 5ba0200 into master Jan 30, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants