Skip to content

Conversation

@amyanger
Copy link

@amyanger amyanger commented Aug 3, 2025

Implements type-safe loadFlow function to prevent runtime errors from typos in .flyde file paths and type mismatches between flow definitions and usage.

Features:

  • Type generation from .flyde files via CLI tool
  • Compile-time path validation using TypeScript overloads
  • Input/output type inference from flow definitions
  • Backward compatibility with existing loadFlow usage
  • Zero runtime overhead - all checking at compile time

Usage:

# Generate types for flows
npm run generate-flow-types ./src ./src/generated/flow-types.ts

# Type-safe loading (path and types validated)
const flow = loadFlow("my-flow.flyde");
const result = await flow({name: "test"}).result;

# Backward compatible generic usage
const flow = loadFlow<{input: string}>("dynamic-path.flyde");

New files:

  • src/type-generation/generate-flow-types.ts - Core type generation logic
  • src/type-generation/cli.ts - Command-line interface
  • src/type-generation/generate-flow-types.spec.ts - Unit tests
  • EXAMPLE_USAGE.md - Usage documentation and examples
  • TEST_EVIDENCE.md - Test results and verification

Modified files:

  • src/runtime/index.ts - Added type-safe loadFlow overloads
  • src/index.ts - Export type generation utilities
  • package.json - Added generate-flow-types script

Test Results:

  • ✅ All unit tests passing (4/4)
  • ✅ Type generation CLI working on 60+ fixture files
  • ✅ TypeScript compilation successful
  • ✅ Backward compatibility maintained

Addresses #115 - Type safety for loadFlow function when using the extension

amyanger and others added 2 commits August 3, 2025 23:52
Implements type-safe loadFlow function to prevent runtime errors from typos
in .flyde file paths and type mismatches between flow definitions and usage.

Features:
- Type generation from .flyde files via CLI tool
- Compile-time path validation using TypeScript overloads
- Input/output type inference from flow definitions
- Backward compatibility with existing loadFlow usage
- Zero runtime overhead - all checking at compile time

Usage:
```bash
# Generate types for flows
npm run generate-flow-types ./src ./src/generated/flow-types.ts

# Type-safe loading (path and types validated)
const flow = loadFlow("my-flow.flyde");
const result = await flow({name: "test"}).result;

# Backward compatible generic usage
const flow = loadFlow<{input: string}>("dynamic-path.flyde");
```

New files:
- src/type-generation/generate-flow-types.ts - Core type generation logic
- src/type-generation/cli.ts - Command-line interface
- src/type-generation/generate-flow-types.spec.ts - Unit tests
- EXAMPLE_USAGE.md - Usage documentation and examples
- TEST_EVIDENCE.md - Test results and verification

Modified files:
- src/runtime/index.ts - Added type-safe loadFlow overloads
- src/index.ts - Export type generation utilities
- package.json - Added generate-flow-types script

Test Results:
- ✅ All unit tests passing (4/4)
- ✅ Type generation CLI working on 60+ fixture files
- ✅ TypeScript compilation successful
- ✅ Backward compatibility maintained

Addresses flydelabs#115 - Type safety for loadFlow function when using the extension
@GabiGrin
Copy link
Contributor

GabiGrin commented Aug 5, 2025

Hey! Looks very cool.
Unfortunately, I I will not have time to properly review this week
Hoping to get to it very soon

@amyanger
Copy link
Author

amyanger commented Aug 5, 2025

Hey! Looks very cool.
Unfortunately, I I will not have time to properly review this week
Hoping to get to it very soon

No worries!

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