Overview
@woltz/rich-domain-export provides powerful multi-format export capabilities for your rich-domain entities. Export data to CSV, JSON, JSON Lines (JSONL), and custom formats with full type safety, custom formatting, and efficient streaming for large datasets.Multiple Formats
CSV, JSON, JSONL, and extensible for custom formats
Type-Safe Exports
Full TypeScript support with discriminated unions
Streaming Support
Memory-efficient export for large datasets
Progress Tracking
Real-time progress callbacks for long-running exports
Installation
Quick Start
Approach 1: Repository Extension
Extend your repository with export capabilities:Approach 2: Composition with ExportService
Use the standalone service to keep export logic separate:Supported Formats
CSV Format
Export entities to comma-separated values format:JSON Format
Export entities to standard JSON array:JSON Lines (JSONL) Format
Export entities to newline-delimited JSON (streaming-friendly):JSON Lines is ideal for streaming large datasets and is supported by many data processing tools. Learn more at jsonlines.org.
Common Use Cases
Export with Filters
Use Criteria to filter data before export:Custom Formatters (CSV)
Transform field values before CSV serialization:Custom Transformers (JSON)
Transform field values with any type (not just strings):Common Formatters
The library provides pre-built formatters for CSV:Date Formatters
Date Formatters
isoDate- ISO 8601 date stringlocaleDate- Locale date string (e.g., “1/1/2024”)localeDateTime- Locale datetime string
Number Formatters
Number Formatters
decimal2- Number with 2 decimal placescurrencyUSD- USD currency format ($X.XX)
Boolean Formatters
Boolean Formatters
yesNo- Boolean as “Yes” or “No”trueFalse- Boolean as “True” or “False”
Collection Formatters
Collection Formatters
array- Array as comma-separated stringjson- Object as JSON string
Text Formatters
Text Formatters
uppercase- Convert to uppercaselowercase- Convert to lowercasetrim- Trim whitespace
Progress Tracking
Monitor export progress for large datasets:Streaming for Large Datasets
For large datasets, use streaming to avoid loading everything into memory:CSV Stream
JSON Lines Stream (Recommended for Large JSON Exports)
HTTP Streaming (Fastify Example)
HTTP Streaming (Express Example)
Performance Considerations
Tips:
- Use
exportStream()for datasets > 10,000 records - Use JSON Lines (
jsonLines: true) for streaming large JSON exports - Adjust
batchSizeoption to control memory usage (default: 1000)