11from collections .abc import AsyncGenerator
22
33from .client_configuration import ClientConfiguration
4- from .client_options import ClientOptions
54from .event .event_candidate import EventCandidate
65from .event .event_context import EventContext
76from .handlers .observe_events .observe_events import observe_events
@@ -27,66 +26,131 @@ def __init__(
2726 self ,
2827 base_url : str ,
2928 api_token : str ,
30- options : ClientOptions = ClientOptions ()
3129 ):
3230 configuration = ClientConfiguration (
3331 base_url = base_url ,
34- timeout_seconds = options .timeout_seconds ,
3532 api_token = api_token ,
36- protocol_version = options .protocol_version ,
37- max_tries = options .max_tries
3833 )
3934
4035 self .__http_client = HttpClient (configuration )
4136
37+ #TODO: is this necessary? __enter__, __exit__
4238 async def initialize (self ) -> None :
4339 await self .__http_client .initialize ()
4440
41+ #TODO: is this necessary? magic method __enter__, __exit__
4542 async def close (self ) -> None :
4643 await self .__http_client .close ()
4744
4845 @property
4946 def http_client (self ) -> HttpClient :
5047 return self .__http_client
5148
49+ # TODO: should we mix object orientation and functional programming?
5250 async def ping (self ) -> None :
53- return await ping (self )
54-
55- async def read_subjects (
51+ return await ping (client = self )
52+
53+ async def verify_api_token (self ) -> None :
54+ ...
55+
56+ async def write_events (
5657 self ,
57- base_subject : str
58- ) -> AsyncGenerator [str , None ]:
59- async for subject in read_subjects (self , base_subject ):
60- yield subject
61-
58+ event_candidates : list [EventCandidate ],
59+ preconditions : list [Precondition ] = None
60+ ) -> list [EventContext ]: # TODO: list[Event] of Events (complete)
61+ if preconditions is None :
62+ preconditions = []
63+ return await write_events (self , event_candidates , preconditions )
64+
6265 async def read_events (
6366 self ,
6467 subject : str ,
6568 options : ReadEventsOptions
66- ) -> AsyncGenerator [StoreItem , None ]:
69+ ) -> AsyncGenerator [StoreItem , None ]: # no StoreItem ... it is a Event
70+ #TODO: This is a code snippet for abort read events.
71+ """
72+ https://github.com/thenativeweb/eventsourcingdb-client-javascript/blob/main/src/Client.ts#L134-L152
73+ for await (const event of client.readEvents('/', { recursive: true })) {
74+ console.log(event);
75+
76+ if (event.ID === '100') {
77+ break;
78+ }
79+ }
80+
81+
82+ function handlePostRequest(abortController) {
83+ const signal = abortController.signal;
84+
85+ for await (const event of client.readEvents('/', { recursive: true }), signal) {
86+ console.log(event);
87+ }
88+
89+ return http.status(200);
90+ }
91+ """
6792 async for event in read_events (self , subject , options ):
6893 yield event
6994
70- async def read_event_types (self ) -> AsyncGenerator [EventType , None ]:
71- async for event_type in read_event_types (self ):
72- yield event_type
73-
74- async def register_event_schema (self , event_type : str , json_schema : str ) -> None :
75- await register_event_schema (self , event_type , json_schema )
95+ # TODO: run eventql query
96+ async def run_eventql_query (self , query : str ) -> AsyncGenerator [Event , None ]:
97+ """
98+ the issue like read_events. can be abort or canceled.
99+ """
76100
77101 async def observe_events (
78102 self ,
79103 subject : str ,
80104 options : ObserveEventsOptions
81- ) -> AsyncGenerator [StoreItem , None ]:
105+ ) -> AsyncGenerator [StoreItem , None ]: # no StoreItem ... it is a Event
106+ """
107+ TODO: the same issue like read_events. contextmanager
108+ """
82109 async for event in observe_events (self , subject , options ):
83110 yield event
84111
85- async def write_events (
112+ async def register_event_schema (self , event_type : str , json_schema : str ) -> None : # TODO: no json_schema is dict no string anymore
113+ # no context manager liek read_events
114+ await register_event_schema (self , event_type , json_schema )
115+
116+ async def read_subjects (
86117 self ,
87- event_candidates : list [EventCandidate ],
88- preconditions : list [Precondition ] = None
89- ) -> list [EventContext ]:
90- if preconditions is None :
91- preconditions = []
92- return await write_events (self , event_candidates , preconditions )
118+ base_subject : str
119+ ) -> AsyncGenerator [str , None ]:
120+ # TODO: the same issue like read_events. contextmanager
121+ async for subject in read_subjects (self , base_subject ):
122+ yield subject
123+
124+
125+ async def read_event_types (self ) -> AsyncGenerator [EventType , None ]:
126+ # TODO: the same issue like read_events. contextmanager
127+ async for event_type in read_event_types (self ):
128+ yield event_type
129+
130+
131+
132+ """ TODO:
133+
134+ f (response.status !== 200) {
135+ throw new Error(
136+ `Failed to read event types, got HTTP status code '${response.status}', expected '200'.`,
137+ );
138+ }
139+
140+ """
141+
142+ """
143+
144+ A: Ausdüngen und Exception
145+
146+ B: Contextmanager
147+
148+ C: Neue Methoden
149+
150+ D: Testcontainer: testcontainers.com Python "virtuelle Container für tests"
151+ - EventSourcingDB(DockerContainer):
152+ def __init__(self):
153+ https://github.com/thenativeweb/eventsourcingdb-client-javascript/blob/main/src/EventSourcingDbContainer.ts
154+ """
155+
156+ Dokumentationslink für Featurecheck : https :// docs .eventsourcingdb .io / client - sdks / compliance - criteria / #detailed-requirements
0 commit comments