How juanjogondev/fastypest works
Main Components
• Fastypest Core Module: This is the central piece of the library (see src/core/fastypest.ts and src/core/index.ts). It provides the API (init, restoreData) used in test setups.
• Configuration Module: Located in src/core/config.ts, this component deals with the initial setup and connection details (using TypeORM) for the library.
• SQL Script Processor: Under src/core/sql-script, this module handles the execution of SQL queries. It includes:
• The main SQL-script handler (src/core/sql-script/sql-script.ts) that controls the flow.
• Database-specific query definitions stored as JSON files (e.g., cockroachdb.json, mysql.query.json, postgres.query.json) which detail how restoration is performed per database type.
• Additional types and interfaces (src/core/sql-script/types) to enforce the structure of these operations.
• Testing and Seeding Artifacts: In the tests folder, you have configuration (setup and ORM config files), seed definitions, entity samples, and Jest configuration. This shows how FASTYPEST is intended to be integrated with a test runner (like Jest) and demonstrates the use-case in which the library is resetting the database state between test runs.
Relationships and Interactions
• The Test Runner (Jest) initializes the FASTYPEST instance via the Fastypest class by providing a TypeORM connection.
• Once initialized (via init()), FASTYPEST uses the configuration module to access connection details.
• During test execution, after tests run, the restoreData method is called. This method internally interacts with the SQL Script Processor, which:
• Determines the correct SQL queries to use (depending on the target database—MySQL, PostgreSQL, etc.) by referring to the corresponding JSON query files.
• Executes these queries to quickly reset the database to its seeded state.
• The entire flow is wrapped with supporting scripts (like the ones in the “scripts” directory) and tool configurations (.github workflows, Docker Compose, etc.) that facilitate coding standards, CI/CD, and deployment for package updates.
Architectural Patterns & Technologies
• Modular Design: The separation into core, SQL script modules, and configuration promotes reusability and clarity.
• Adapter/Strategy Pattern: The way different database query JSON files are managed suggests an underlying strategy to choose which set of queries to run depending on the connected database.
• Integration with TypeORM: By requiring a TypeORM connection, FASTYPEST is clearly designed to plug into existing ORM-driven applications.
• Test-Oriented Design: The integration with Jest and the focus on database seeding and restoration underline that this library acts as a utility in test suites rather than as a full-stack service.
Final Touches
• Extensibility point (e.g., how additional databases can be supported by adding new JSON query files and possibly new strategies in the SQL Script Processor).