Skip to content

Commit 88db2b9

Browse files
committed
fix: merge conflict
1 parent bddfb03 commit 88db2b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1678
-0
lines changed

eventsourcingdb/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .client import Client as EsdbClient
2+
from .client_options import ClientOptions as EsdbClientOptions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from abc import ABC, abstractmethod
2+
from .http_client.http_client import HttpClient
3+
4+
5+
class AbstractBaseClient(ABC):
6+
@property
7+
@abstractmethod
8+
def http_client(self) -> HttpClient:
9+
raise NotImplementedError()

eventsourcingdb/client.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from collections.abc import AsyncGenerator
2+
3+
from .abstract_base_client import AbstractBaseClient
4+
from .client_configuration import ClientConfiguration
5+
from .client_options import ClientOptions
6+
from .event.event_candidate import EventCandidate
7+
from .event.event_context import EventContext
8+
from .handlers.observe_events.observe_events import observe_events
9+
from .handlers.observe_events.observe_events_options import ObserveEventsOptions
10+
from .handlers.read_event_types.event_type import EventType
11+
from .handlers.read_event_types.read_event_types import read_event_types
12+
from .handlers.register_event_schema.register_event_schema import register_event_schema
13+
from .http_client.http_client import HttpClient
14+
from .handlers.ping import ping
15+
from .handlers.read_events import read_events, ReadEventsOptions
16+
from .handlers.read_subjects import read_subjects
17+
from .handlers.store_item import StoreItem
18+
from .handlers.write_events import Precondition, write_events
19+
20+
21+
# pylint: disable=R6007
22+
# Reason: This class explicitly specifies the return type as None
23+
# for better readability. Even though it is not necessary,
24+
# it makes the return type clear without needing to read any
25+
# documentation or code.
26+
class Client(AbstractBaseClient):
27+
def __init__(
28+
self,
29+
base_url: str,
30+
access_token: str,
31+
options: ClientOptions = ClientOptions()
32+
):
33+
configuration = ClientConfiguration(
34+
base_url=base_url,
35+
timeout_seconds=options.timeout_seconds,
36+
access_token=access_token,
37+
protocol_version=options.protocol_version,
38+
max_tries=options.max_tries
39+
)
40+
41+
self.__http_client = HttpClient(configuration)
42+
43+
async def initialize(self) -> None:
44+
await self.__http_client.initialize()
45+
46+
async def close(self) -> None:
47+
await self.__http_client.close()
48+
49+
@property
50+
def http_client(self) -> HttpClient:
51+
return self.__http_client
52+
53+
async def ping(self) -> None:
54+
return await ping(self)
55+
56+
async def read_subjects(
57+
self,
58+
base_subject: str
59+
) -> AsyncGenerator[str, None]:
60+
async for subject in read_subjects(self, base_subject):
61+
yield subject
62+
63+
async def read_events(
64+
self,
65+
subject: str,
66+
options: ReadEventsOptions
67+
) -> AsyncGenerator[StoreItem, None]:
68+
async for event in read_events(self, subject, options):
69+
yield event
70+
71+
async def read_event_types(self) -> AsyncGenerator[EventType, None]:
72+
async for event_type in read_event_types(self):
73+
yield event_type
74+
75+
async def register_event_schema(self, event_type: str, json_schema: str) -> None:
76+
await register_event_schema(self, event_type, json_schema)
77+
78+
async def observe_events(
79+
self,
80+
subject: str,
81+
options: ObserveEventsOptions
82+
) -> AsyncGenerator[StoreItem, None]:
83+
async for event in observe_events(self, subject, options):
84+
yield event
85+
86+
async def write_events(
87+
self,
88+
event_candidates: list[EventCandidate],
89+
preconditions: list[Precondition] = None
90+
) -> list[EventContext]:
91+
if preconditions is None:
92+
preconditions = []
93+
return await write_events(self, event_candidates, preconditions)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class ClientConfiguration:
6+
base_url: str
7+
timeout_seconds: int
8+
access_token: str
9+
protocol_version: str
10+
max_tries: int

eventsourcingdb/client_options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class ClientOptions:
6+
timeout_seconds: int = 10
7+
protocol_version: str = '1.0.0'
8+
max_tries: int = 10

eventsourcingdb/errors/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .custom_error import CustomError
2+
3+
4+
class ClientError(CustomError):
5+
def __init__(self, cause: str):
6+
super().__init__(f'Client error occurred: {cause}')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class CustomError(Exception):
2+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .custom_error import CustomError
2+
3+
4+
class InternalError(CustomError):
5+
def __init__(self, cause: str):
6+
super().__init__(f'Internal error occurred: {cause}')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .custom_error import CustomError
2+
3+
4+
class InvalidParameterError(CustomError):
5+
def __init__(self, parameter_name: str, reason: str):
6+
super().__init__(
7+
f'Parameter \'{parameter_name}\' is invalid: {reason}')

0 commit comments

Comments
 (0)