GitHub

API reference for event.

Events (Effect's eventlog/Event): a tag, the schema of its payload, success and error, and how its primary key is read from a payload.

An event is written to an event log and replayed by its handler, which the log finds by the tag::

UserCreated = event.make(
    "UserCreated", primary_key=lambda p: p["id"], payload=S.Struct(User)
)

Types

TypeDefinitionDescription
AnyEventtype AnyEvent = Event[Any, Any, Any]

An event of any payload, success and error (Effect's Event.Any).

AnyWritetype AnyWrite[A, E] = Write[Any, A, E]

A write of any payload whose handler gives A or fails with E: building the Write already checked its payload against its event.

Classes

Functions

make

make[P = None, A = None, E = Never](tag: str, *, primary_key: Callable[[P], str], payload: _C[P] | None = None, success: _C[A] | None = None, error: _C[E] | None = None) -> Event[P, A, E]
make[A = None, E = Never](tag: str, *, primary_key: Callable[[None], str], success: _C[A] | None = None, error: _C[E] | None = None) -> Event[None, A, E]

An event (Effect's Event.make). The payload and the success default to None, the error to none.

ParameterTypeDescription
tag
primary_key
payload= None
success= None
error= None
@overload
def make[P = None, A = None, E = Never](
    tag: str,
    *,
    primary_key: Callable[[P], str],
    payload: _C[P] | None = None,
    success: _C[A] | None = None,
    error: _C[E] | None = None,
) -> Event[P, A, E]: ...
@overload
def make[A = None, E = Never](
    tag: str,
    *,
    primary_key: Callable[[None], str],
    success: _C[A] | None = None,
    error: _C[E] | None = None,
) -> Event[None, A, E]: ...
def make(
    tag: str,
    *,
    primary_key: Callable[[Any], str],
    payload: _C[Any] | None = None,
    success: _C[Any] | None = None,
    error: _C[Any] | None = None,
) -> Event[Any, Any, Any]:
    """An event (Effect's ``Event.make``). The payload and the success
    default to ``None``, the error to none."""
    return Event(
        tag,
        primary_key,
        S.Null if payload is None else payload,
        S.Null if success is None else success,
        S.Never if error is None else error,
    )

add_error

add_error[P, A, E, E2](event, error) -> Event[P, A, E | E2]

event whose handler may also fail with error (Effect's Event.addError).

ParameterTypeDescription
eventEvent[P, A, E]
error_C[E2]

Returns Event[P, A, E | E2]

def add_error[P, A, E, E2](event: Event[P, A, E], error: _C[E2], /) -> Event[P, A, E | E2]:
    """``event`` whose handler may also fail with ``error`` (Effect's
    ``Event.addError``)."""
    return Event(
        event.tag,
        event.primary_key,
        event.payload,
        event.success,
        S.Union(event.error, error),
    )

is_event

is_event(value) -> TypeGuard[AnyEvent]

Whether value is an event (Effect's isEvent).

ParameterTypeDescription
valueobject

Returns TypeGuard[AnyEvent]

def is_event(value: object) -> TypeGuard[AnyEvent]:
    """Whether ``value`` is an event (Effect's ``isEvent``)."""
    return isinstance(value, Event)