How to use the eventsourcing.domain.model.entity.TimestampedVersionedEntity function in eventsourcing

To help you get started, we’ve selected a few eventsourcing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnbywater / eventsourcing / eventsourcing / contrib / suffixtrees / domain / model / suffixtree.py View on Github external
def _canonize_suffix(self, suffix):
        """This canonizes the suffix, walking along its suffix string until it
        is explicit or there are no more matched nodes.
        """
        if not suffix.explicit():
            edge_id = make_edge_id(
                suffix.source_node_id, self.string[suffix.first_char_index]
            )
            e = self.edges[edge_id]
            if e.length <= suffix.length:
                suffix.first_char_index += e.length + 1
                suffix.source_node_id = e.dest_node_id
                self._canonize_suffix(suffix)


class Node(TimestampedVersionedEntity):
    """A node in the suffix tree.
    """

    class Created(Created):
        pass

    class AttributeChanged(AttributeChanged):
        pass

    class Discarded(Discarded):
        pass

    def __init__(self, suffix_node_id=None, *args, **kwargs):
        super(Node, self).__init__(*args, **kwargs)
        self._suffix_node_id = suffix_node_id
github johnbywater / eventsourcing / eventsourcing / domain / model / timebucketedlog.py View on Github external
ONE_HOUR = relativedelta(hours=1)
ONE_MINUTE = relativedelta(minutes=1)
ONE_SECOND = relativedelta(seconds=1)

BUCKET_SIZES = {
    "year": ONE_YEAR,
    "month": ONE_MONTH,
    "day": ONE_DAY,
    "hour": ONE_HOUR,
    "minute": ONE_MINUTE,
    "second": ONE_SECOND,
}


class Timebucketedlog(TimestampedVersionedEntity):
    class Event(TimestampedVersionedEntity.Event):
        """Supertype for events of time-bucketed log."""

    class Started(TimestampedVersionedEntity.Created, Event):
        pass

    class BucketSizeChanged(Event, TimestampedVersionedEntity.AttributeChanged):
        pass

    def __init__(self, name, bucket_size=None, **kwargs):
        super(Timebucketedlog, self).__init__(**kwargs)
        self._name = name
        self._bucket_size = bucket_size

    @property
    def name(self):
        return self._name
github johnbywater / eventsourcing / eventsourcing / contrib / suffixtrees / domain / model / suffixtree.py View on Github external
from uuid import uuid4

from eventsourcing.domain.model.decorators import attribute
from eventsourcing.domain.model.entity import (
    AttributeChanged,
    Created,
    Discarded,
    TimestampedVersionedEntity,
)
from eventsourcing.domain.model.events import publish
from eventsourcing.example.application import ExampleApplication
from eventsourcing.exceptions import RepositoryKeyError
from eventsourcing.infrastructure.eventsourcedrepository import EventSourcedRepository


class SuffixTree(TimestampedVersionedEntity):
    """A suffix tree for string matching. Uses Ukkonen's algorithm
    for construction.
    """

    class Created(Created):
        pass

    class AttributeChanged(AttributeChanged):
        pass

    class Discarded(Discarded):
        pass

    def __init__(self, root_node_id, case_insensitive=False, **kwargs):
        """
        string
github johnbywater / eventsourcing / eventsourcing / example / domainmodel.py View on Github external
from eventsourcing.domain.model.decorators import attribute
from eventsourcing.domain.model.entity import (
    AbstractEntityRepository,
    TimestampedVersionedEntity,
    EntityWithHashchain,
)


class Example(EntityWithHashchain, TimestampedVersionedEntity):
    """
    An example event sourced domain model entity.
    """

    class Event(EntityWithHashchain.Event, TimestampedVersionedEntity.Event):
        """Supertype for events of example entities."""

    class Created(
        Event, EntityWithHashchain.Created, TimestampedVersionedEntity.Created
    ):
        """Published when an Example is created."""

    class AttributeChanged(Event, TimestampedVersionedEntity.AttributeChanged):
        """Published when an Example is created."""

    class Discarded(Event, TimestampedVersionedEntity.Discarded):
github johnbywater / eventsourcing / eventsourcing / domain / model / sequence.py View on Github external
from abc import abstractproperty
from uuid import uuid5

import six
from six.moves._thread import get_ident

from eventsourcing.domain.model.decorators import retry
from eventsourcing.domain.model.entity import AbstractEntityRepository, TimestampedVersionedEntity
from eventsourcing.domain.model.events import publish
from eventsourcing.exceptions import CompoundSequenceFullError, ConcurrencyError, SequenceFullError


class SequenceMeta(TimestampedVersionedEntity):
    """
    This class represents an overall, which is
    initially empty. A specialised repository
    SequenceRepo returns a Sequence object which
    can append items to the sequence without
    loading all the events. It can also index,
    slice and iterate through items in the sequence
    without having to load all of them.
    """

    class Event(TimestampedVersionedEntity.Event):
        """Layer supertype."""

    class Started(Event, TimestampedVersionedEntity.Created):
        """Occurs when sequence is started."""
github johnbywater / eventsourcing / eventsourcing / domain / model / array.py View on Github external
from abc import abstractproperty
from math import ceil, log
from uuid import uuid5

from eventsourcing.domain.model.decorators import retry
from eventsourcing.domain.model.entity import (
    AbstractEntityRepository,
    TimestampedVersionedEntity,
)
from eventsourcing.domain.model.events import publish
from eventsourcing.exceptions import ArrayIndexError, ConcurrencyError


class ItemAssigned(TimestampedVersionedEntity.Event):
    """Occurs when an item is set at a position in an array."""

    def __init__(self, item, index, *args, **kwargs):
        kwargs["item"] = item
        super(ItemAssigned, self).__init__(originator_version=index, *args, **kwargs)

    @property
    def item(self):
        return self.__dict__["item"]

    @property
    def index(self):
        return self.originator_version


class Array(object):
github johnbywater / eventsourcing / eventsourcing / domain / model / aggregate.py View on Github external
"""
:mod:`eventsourcing.domain.model.aggregate`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"""
from collections import deque

from eventsourcing.domain.model.entity import TimestampedVersionedEntity
from eventsourcing.domain.model.events import publish


class AggregateRoot(TimestampedVersionedEntity):
    """
    Root entity for an aggregate in a domain driven design.
    """
    class Event(TimestampedVersionedEntity.Event):
        """Layer supertype."""

    class Created(Event, TimestampedVersionedEntity.Created):
        """Published when an AggregateRoot is created."""

    class AttributeChanged(Event, TimestampedVersionedEntity.AttributeChanged):
        """Published when an AggregateRoot is changed."""

    class Discarded(Event, TimestampedVersionedEntity.Discarded):
        """Published when an AggregateRoot is discarded."""

    def __init__(self, **kwargs):
github johnbywater / eventsourcing / eventsourcing / domain / model / aggregate.py View on Github external
"""
from collections import deque

from eventsourcing.domain.model.entity import TimestampedVersionedEntity
from eventsourcing.domain.model.events import publish


class AggregateRoot(TimestampedVersionedEntity):
    """
    Root entity for an aggregate in a domain driven design.
    """
    class Event(TimestampedVersionedEntity.Event):
        """Layer supertype."""

    class Created(Event, TimestampedVersionedEntity.Created):
        """Published when an AggregateRoot is created."""

    class AttributeChanged(Event, TimestampedVersionedEntity.AttributeChanged):
        """Published when an AggregateRoot is changed."""

    class Discarded(Event, TimestampedVersionedEntity.Discarded):
        """Published when an AggregateRoot is discarded."""

    def __init__(self, **kwargs):
        super(AggregateRoot, self).__init__(**kwargs)
        self._pending_events = deque()

    def _publish(self, event):
        self._pending_events.append(event)

    def save(self):
github johnbywater / eventsourcing / eventsourcing / domain / model / timebucketedlog.py View on Github external
ONE_DAY = relativedelta(days=1)
ONE_HOUR = relativedelta(hours=1)
ONE_MINUTE = relativedelta(minutes=1)
ONE_SECOND = relativedelta(seconds=1)

BUCKET_SIZES = {
    "year": ONE_YEAR,
    "month": ONE_MONTH,
    "day": ONE_DAY,
    "hour": ONE_HOUR,
    "minute": ONE_MINUTE,
    "second": ONE_SECOND,
}


class Timebucketedlog(TimestampedVersionedEntity):
    class Event(TimestampedVersionedEntity.Event):
        """Supertype for events of time-bucketed log."""

    class Started(TimestampedVersionedEntity.Created, Event):
        pass

    class BucketSizeChanged(Event, TimestampedVersionedEntity.AttributeChanged):
        pass

    def __init__(self, name, bucket_size=None, **kwargs):
        super(Timebucketedlog, self).__init__(**kwargs)
        self._name = name
        self._bucket_size = bucket_size

    @property
    def name(self):
github johnbywater / eventsourcing / eventsourcing / domain / model / collection.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from eventsourcing.domain.model.entity import (
    AbstractEntityRepository,
    TimestampedVersionedEntity,
)


class Collection(TimestampedVersionedEntity):
    class Event(TimestampedVersionedEntity.Event):
        """Supertype for events of collection entities."""

    class Created(Event, TimestampedVersionedEntity.Created):
        """Published when collection is created."""

    class Discarded(Event, TimestampedVersionedEntity.Discarded):
        """Published when collection is discarded."""

    class EventWithItem(Event):
        @property
        def item(self):
            return self.__dict__["item"]

    class ItemAdded(EventWithItem):
        def __mutate__(self, obj):
            obj = super(Collection.ItemAdded, self).__mutate__(obj)
            obj._items.add(self.item)
            return obj

    class ItemRemoved(EventWithItem):
        def __mutate__(self, obj):
            obj = super(Collection.ItemRemoved, self).__mutate__(obj)