GitHub

EventJournalService

API reference for EventJournalService.

What a journal does (Effect's EventJournal service).

Attributes

AttributeTypeDescription
entriesEffect[list[Entry], EventJournalError]

Every entry, in id order.

changesEffect[Subscription[Entry], Never, Scope]

A subscription to the entries written locally.

destroyEffect[None, EventJournalError]

Remove every entry and every remote's progress.

Functions

entries_by_id

entries_by_id(ids) -> Effect[list[Entry | None], EventJournalError]

The entry of each id, None when unknown, in the ids' order.

ParameterTypeDescription
idsSequence[EntryId]

Returns Effect[list[Entry | None], EventJournalError]

@abstractmethod
def entries_by_id(
    self, ids: Sequence[EntryId], /
) -> Effect[list[Entry | None], EventJournalError]:
    """The entry of each id, ``None`` when unknown, in the ids' order."""

write

write[A, E, R](*, event, primary_key, payload, effect) -> Effect[A, EventJournalError | E, R]

Write one entry, committed only when effect succeeds.

ParameterTypeDescription
eventstr
primary_keystr
payloadbytes
effectCallable[[Entry], Effect[A, E, R]]

Returns Effect[A, EventJournalError | E, R]

def write[A, E, R](
    self,
    *,
    event: str,
    primary_key: str,
    payload: bytes,
    effect: Callable[[Entry], Effect[A, E, R]],
) -> Effect[A, EventJournalError | E, R]:
    """Write one entry, committed only when ``effect`` succeeds."""
    return self.write_many(
        [EntryInput(event, primary_key, payload)], lambda written: effect(written[0])
    )

write_many

write_many[A, E, R](entries, effect) -> Effect[A, EventJournalError | E, R]

Write the (non-empty) entries, committed only when effect succeeds.

ParameterTypeDescription
entriesSequence[EntryInput]
effectCallable[[list[Entry]], Effect[A, E, R]]

Returns Effect[A, EventJournalError | E, R]

@abstractmethod
def write_many[A, E, R](
    self,
    entries: Sequence[EntryInput],
    effect: Callable[[list[Entry]], Effect[A, E, R]],
    /,
) -> Effect[A, EventJournalError | E, R]:
    """Write the (non-empty) ``entries``, committed only when
    ``effect`` succeeds."""

write_from_remote

write_from_remote(*, remote_id, entries, effect, compact=None) -> Effect[list[Entry], EventJournalError]

Import a remote's entries: the new ones (compacted by compact) are replayed by effect in one batch with their conflicts, then committed with the remote's sequence. Succeeds with the entries that were already stored.

ParameterTypeDescription
remote_idRemoteId
entriesSequence[RemoteEntry]
effectReplayBatch
compactCompact | None = None

Returns Effect[list[Entry], EventJournalError]

@abstractmethod
def write_from_remote(
    self,
    *,
    remote_id: RemoteId,
    entries: Sequence[RemoteEntry],
    effect: ReplayBatch,
    compact: Compact | None = None,
) -> Effect[list[Entry], EventJournalError]:
    """Import a remote's entries: the new ones (compacted by
    ``compact``) are replayed by ``effect`` in one batch with their
    conflicts, then committed with the remote's sequence. Succeeds
    with the entries that were already stored."""

with_remote_uncommitted

with_remote_uncommitted[A, E, R](remote_id, f) -> Effect[Option[A], EventJournalError | E, R]

Run f on the entries remote_id has not seen, if any; they count as seen when it succeeds (Effect's withRemoteUncommited).

ParameterTypeDescription
remote_idRemoteId
fCallable[[list[Entry]], Effect[A, E, R]]

Returns Effect[Option[A], EventJournalError | E, R]

@abstractmethod
def with_remote_uncommitted[A, E, R](
    self, remote_id: RemoteId, f: Callable[[list[Entry]], Effect[A, E, R]], /
) -> Effect[Option[A], EventJournalError | E, R]:
    """Run ``f`` on the entries ``remote_id`` has not seen, if any; they
    count as seen when it succeeds (Effect's ``withRemoteUncommited``)."""

write_remote_acks

write_remote_acks(*, remote_id, acks, first_sequence=None) -> Effect[None, EventJournalError]

Record the sequences remote_id acknowledged.

ParameterTypeDescription
remote_idRemoteId
acksSequence[RemoteAck]
first_sequenceint | None = None

Returns Effect[None, EventJournalError]

@abstractmethod
def write_remote_acks(
    self, *, remote_id: RemoteId, acks: Sequence[RemoteAck], first_sequence: int | None = None
) -> Effect[None, EventJournalError]:
    """Record the sequences ``remote_id`` acknowledged."""

next_remote_sequence

next_remote_sequence(remote_id) -> Effect[int, EventJournalError]

The next sequence to read from remote_id.

ParameterTypeDescription
remote_idRemoteId

Returns Effect[int, EventJournalError]

@abstractmethod
def next_remote_sequence(self, remote_id: RemoteId, /) -> Effect[int, EventJournalError]:
    """The next sequence to read from ``remote_id``."""

with_lock

with_lock(store_id) -> WithLock

Run an effect holding the lock of store_id.

ParameterTypeDescription
store_idStoreId

Returns WithLock

@abstractmethod
def with_lock(self, store_id: StoreId, /) -> WithLock:
    """Run an effect holding the lock of ``store_id``."""