Skip to content

v.2.1.0

Choose a tag to compare

@hideokamoto hideokamoto released this 25 Aug 05:34

Added

  • Generic type support for custom type resolution: Added TType generic parameter to ResolveTarget interface
  • Custom object type handling: Support for complex objects beyond simple strings in the supports() method
  • Domain-specific object resolution: Ability to handle Stripe events, database records, or custom business objects
  • Enhanced type safety: Full TypeScript support for custom types while maintaining backward compatibility
  • Comprehensive test coverage: Added tests demonstrating Stripe Event handling with complex types

Changed

  • Interface signature: ResolveTarget<TArgs, TReturn, TType> now supports custom types for the supports() method
  • Resolver class: Updated to support custom types through generic type parameters
  • Documentation: Enhanced README with advanced type support examples and usage patterns

Technical Details

  • Type Parameters:
    • TArgs: Arguments array for the handle() method (unchanged)
    • TReturn: Return type of the handle() method (unchanged)
    • TType: Type for the supports() method (new, defaults to string)

Backward Compatibility

  • Fully backward compatible: All existing code continues to work without changes
  • Default behavior: TType defaults to string, maintaining existing functionality
  • Existing interfaces: ResolveTarget<[], string> syntax remains unchanged

Examples

Before (v2.0.0)

class StringHandler implements ResolveTarget<[], string> {
  supports(type: string): boolean {
    return type === 'my-type';
  }
  handle(): string {
    return 'result';
  }
}

After (v2.1.0) - Enhanced

interface CustomEvent {
  type: string;
  data: any;
}

class CustomHandler implements ResolveTarget<[CustomEvent], string, CustomEvent> {
  supports(event: CustomEvent): boolean {
    return event.type === 'payment_intent.succeeded';
  }
  
  handle(event: CustomEvent): string {
    return `Handled: ${event.type}`;
  }
}

Use Cases

  • Stripe Integration: Handle different Stripe event types with type-safe resolution
  • Database Operations: Resolve handlers based on complex database record types
  • Business Logic: Create domain-specific object resolution systems
  • Event Processing: Handle custom event objects with full type safety

Migration Guide

No migration required for existing code. To use new features, simply add the third type parameter:

// Existing code (continues to work)
class MyHandler implements ResolveTarget<[], string> { ... }

// New enhanced code
class MyHandler implements ResolveTarget<[], string, CustomType> { ... }