Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Refactor: Modernize Configuration Management and Script Generation#63

Merged
Wizdave97 merged 7 commits into
mainfrom
improv/config-template
Jun 12, 2025
Merged

Refactor: Modernize Configuration Management and Script Generation#63
Wizdave97 merged 7 commits into
mainfrom
improv/config-template

Conversation

@vimoppa

@vimoppa vimoppa commented May 28, 2025

Copy link
Copy Markdown
Contributor

This PR completes a comprehensive refactoring of the indexer package's configuration management and build scripts, introducing type safety, schema validation, and template-based generation using Handlebars.

Changes

1. Handlebars Template Integration for Docker Compose

  • Refactored generate-compose.ts to use Handlebars templates instead of string concatenation
  • Added template files for Docker service generation with proper partials structure
  • Consistent pattern with the existing generate-chain-yamls.ts implementation

2. Centralized Configuration System

  • Created src/configs/index.ts as the single source of truth for configuration management
  • Implemented Zod schema validation for chain configurations with proper error messages
  • Added helper functions: getEnv(), getConfigs(), and getValidChains()
  • Validates both Substrate and EVM chain configurations with discriminated unions

3. TypeScript Migration

  • Converted all build scripts from JavaScript to TypeScript (.js.ts)
  • Migrated from CommonJS to ES modules with proper import/export syntax
  • Added ESM-compatible __dirname resolution using import.meta.url

4. Enhanced Type Safety

  • Defined ConfigObject and Configuration types derived from Zod schemas
  • Added Environment type for better environment handling
  • Proper type validation for EVM contract addresses and state machine IDs

Dependencies Added

  • zod@^3.25.32 - Runtime schema validation
  • handlebars@^4.7.8 - Template engine

@vimoppa vimoppa requested a review from Wizdave97 May 29, 2025 12:36
@vimoppa vimoppa self-assigned this May 29, 2025
@vimoppa vimoppa marked this pull request as ready for review May 29, 2025 12:36
@vimoppa vimoppa force-pushed the improv/config-template branch from b7dfe5a to 7bb9bac Compare June 9, 2025 15:28
vimoppa added 6 commits June 10, 2025 11:43
- Convert generate-chain-yamls.js and generate-compose.js to TypeScript
- Add ES module support with "type": "module" in package.json
- Replace CommonJS require/exports with ES module imports
- Use tsx runner for TypeScript script execution
- Consolidate handler templates into unified data-driven partial
- Move tsx to devDependencies where it belongs
- Add Zod for runtime configuration validation
- Create centralized config module with type-safe schemas
- Refactor scripts to use new config module instead of direct
  file/env access
- Validate chain configurations at load time to catch errors early
- Convert handler configuration from single `topic` property to `topics`
array to allow handlers to listen for multiple event topics.
- Update templates to iterate over topics array.
@vimoppa vimoppa force-pushed the improv/config-template branch from 7bb9bac to d8ba10f Compare June 10, 2025 10:50
@Wizdave97 Wizdave97 merged commit b501087 into main Jun 12, 2025
1 of 2 checks passed
@Wizdave97 Wizdave97 deleted the improv/config-template branch June 12, 2025 10:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants