Skip to content

feat: Component version infrastructure #697

@tyevco

Description

@tyevco

Overview

Implement the foundational version tracking infrastructure for component schema migrations.

Parent Issue

Requirements

Attribute Support

  • Add Version property to [Component] attribute (default: 1)
  • Validate version is positive integer at compile time

Source Generator

  • Generate ComponentMigrationMetadata class
  • GetVersion<T>() method for compile-time known types
  • GetVersion(Type) method for runtime lookup
  • Generate version lookup table (AOT-compatible)

Serialization Format Changes

  • Binary format: Add version field (int16) after component type ID
  • JSON format: Add $version property to component objects
  • Backward compatibility: Treat missing version as v1

Version Mismatch Detection

  • Detect version mismatch during deserialization
  • Throw ComponentVersionException with clear message
  • Include component name, serialized version, current version

Example

[Component(Version = 2)]
public partial struct Health
{
    public int Current;
    public int Max;
    public int Shield;
}

// Generated:
public static partial class ComponentMigrationMetadata
{
    public static int GetVersion<T>() where T : struct, IComponent
    {
        if (typeof(T) == typeof(Health)) return 2;
        // ... other components
        return 1; // default
    }
}

Acceptance Criteria

  • Components can declare version via attribute
  • Version metadata accessible at runtime (AOT-compatible)
  • Serialized data includes version information
  • Version mismatch throws descriptive exception
  • Unit tests for version metadata generation
  • Unit tests for serialization format changes

Technical Notes

  • No reflection allowed (Native AOT compatibility)
  • Version stored as int16 in binary format (max 32,767 versions)
  • Source generator in KeenEyes.Generators

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions