Skip to content

castlecraft_engineer.abstractions.projection_store

castlecraft_engineer.abstractions.projection_store

ProjectionStore

Bases: ABC, Generic[TEventId]

Abstract base class for a store that manages the state of projections. This is crucial for projectors to know where they left off in an event stream.

Source code in src/castlecraft_engineer/abstractions/projection_store.py
class ProjectionStore(abc.ABC, Generic[TEventId]):
    """
    Abstract base class for a store that manages the state of projections.
    This is crucial for projectors to know where they left off in an event stream.
    """

    @abc.abstractmethod
    async def get_projection_state(
        self, projection_id: ProjectionId
    ) -> Optional[ProjectionState]:
        """
        Retrieves the current state of a given projection.

        Args:
            projection_id: The unique identifier of the projection.

        Returns:
            The ProjectionState object, or None if no state exists for the projection.
        """
        raise NotImplementedError

    @abc.abstractmethod
    async def save_projection_state(self, projection_state: ProjectionState) -> None:
        """
        Saves or updates the state of a projection.

        Args:
            projection_state: The ProjectionState object to persist.
        """
        raise NotImplementedError

    @abc.abstractmethod
    async def clear_projection_state(self, projection_id: ProjectionId) -> None:
        """
        Optional: Clears the state for a given projection.
        Useful for replaying a projection from the beginning.

        Args:
            projection_id: The ID of the projection whose state is to be cleared.
        """

clear_projection_state(projection_id) abstractmethod async

Optional: Clears the state for a given projection. Useful for replaying a projection from the beginning.

Parameters:

Name Type Description Default
projection_id ProjectionId

The ID of the projection whose state is to be cleared.

required
Source code in src/castlecraft_engineer/abstractions/projection_store.py
@abc.abstractmethod
async def clear_projection_state(self, projection_id: ProjectionId) -> None:
    """
    Optional: Clears the state for a given projection.
    Useful for replaying a projection from the beginning.

    Args:
        projection_id: The ID of the projection whose state is to be cleared.
    """

get_projection_state(projection_id) abstractmethod async

Retrieves the current state of a given projection.

Parameters:

Name Type Description Default
projection_id ProjectionId

The unique identifier of the projection.

required

Returns:

Type Description
Optional[ProjectionState]

The ProjectionState object, or None if no state exists for the projection.

Source code in src/castlecraft_engineer/abstractions/projection_store.py
@abc.abstractmethod
async def get_projection_state(
    self, projection_id: ProjectionId
) -> Optional[ProjectionState]:
    """
    Retrieves the current state of a given projection.

    Args:
        projection_id: The unique identifier of the projection.

    Returns:
        The ProjectionState object, or None if no state exists for the projection.
    """
    raise NotImplementedError

save_projection_state(projection_state) abstractmethod async

Saves or updates the state of a projection.

Parameters:

Name Type Description Default
projection_state ProjectionState

The ProjectionState object to persist.

required
Source code in src/castlecraft_engineer/abstractions/projection_store.py
@abc.abstractmethod
async def save_projection_state(self, projection_state: ProjectionState) -> None:
    """
    Saves or updates the state of a projection.

    Args:
        projection_state: The ProjectionState object to persist.
    """
    raise NotImplementedError