buz 2.15.0__py3-none-any.whl → 2.15.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -1,36 +1,19 @@
1
1
  from dataclasses import dataclass
2
+ from typing import Optional
2
3
 
3
-
4
- @dataclass(frozen=True)
5
- class CDCPayload:
6
- DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
7
-
8
- payload: str # json encoded
9
- event_id: str # uuid
10
- created_at: str
11
- event_fqn: str
12
-
13
- def validate(self) -> None:
14
- if not isinstance(self.payload, str):
15
- raise ValueError("The payload value is not a valid value")
16
- if not isinstance(self.event_id, str):
17
- raise ValueError("The event_id value is not a valid value")
18
- if not isinstance(self.created_at, str):
19
- raise ValueError("The created_at value is not a value")
20
- if not isinstance(self.event_fqn, str):
21
- raise ValueError("The event_fqn value is not a valid value")
22
-
23
- def __post_init__(self) -> None:
24
- self.validate()
4
+ from buz.kafka.infrastructure.cdc.cdc_payload import CDCPayload
25
5
 
26
6
 
27
7
  @dataclass(frozen=True)
28
8
  class CDCMessage:
29
9
  payload: CDCPayload
10
+ schema: Optional[dict]
30
11
 
31
12
  def validate(self) -> None:
32
13
  if not isinstance(self.payload, CDCPayload):
33
14
  raise ValueError("The payload value is not a valid value")
15
+ if self.schema is not None and not isinstance(self.schema, dict):
16
+ raise ValueError("The schema value is not a valid value")
34
17
 
35
18
  def __post_init__(self) -> None:
36
19
  self.validate()
@@ -0,0 +1,24 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass(frozen=True)
5
+ class CDCPayload:
6
+ DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
7
+
8
+ payload: str # json encoded
9
+ event_id: str # uuid
10
+ created_at: str
11
+ event_fqn: str
12
+
13
+ def validate(self) -> None:
14
+ if not isinstance(self.payload, str):
15
+ raise ValueError("The payload value is not a valid value")
16
+ if not isinstance(self.event_id, str):
17
+ raise ValueError("The event_id value is not a valid value")
18
+ if not isinstance(self.created_at, str):
19
+ raise ValueError("The created_at value is not a value")
20
+ if not isinstance(self.event_fqn, str):
21
+ raise ValueError("The event_fqn value is not a valid value")
22
+
23
+ def __post_init__(self) -> None:
24
+ self.validate()
@@ -0,0 +1,35 @@
1
+ from buz.message import Message
2
+
3
+
4
+ def generate_cdc_schema(message: Message) -> dict:
5
+ return {
6
+ "type": "struct",
7
+ "fields": [
8
+ {
9
+ "type": "string",
10
+ "optional": False,
11
+ "field": "payload",
12
+ },
13
+ {
14
+ "type": "string",
15
+ "optional": False,
16
+ "name": "io.debezium.data.Uuid",
17
+ "version": 1,
18
+ "field": "event_id",
19
+ },
20
+ {
21
+ "type": "string",
22
+ "optional": False,
23
+ "field": "event_fqn",
24
+ },
25
+ {
26
+ "type": "string",
27
+ "optional": False,
28
+ "name": "io.debezium.time.ZonedTimestamp",
29
+ "version": 1,
30
+ "field": "created_at",
31
+ },
32
+ ],
33
+ "optional": False,
34
+ "name": f"{message.fqn()}.Value",
35
+ }
@@ -7,7 +7,7 @@ import orjson
7
7
  from dacite import from_dict
8
8
 
9
9
  from buz.event import Event
10
- from buz.kafka.infrastructure.cdc.cdc_message import CDCMessage, CDCPayload
10
+ from buz.kafka.infrastructure.cdc.cdc_message import CDCPayload
11
11
  from buz.kafka.infrastructure.deserializers.bytes_to_message_deserializer import BytesToMessageDeserializer
12
12
  from buz.kafka.infrastructure.deserializers.implementations.cdc.not_valid_cdc_message_exception import (
13
13
  NotValidCDCMessageException,
@@ -25,11 +25,11 @@ class CDCRecordBytesToEventDeserializer(BytesToMessageDeserializer[Event], Gener
25
25
  def deserialize(self, data: bytes) -> T:
26
26
  decoded_string = data.decode(self.__STRING_ENCODING)
27
27
  try:
28
- cdc_message = self.__get_outbox_record_as_dict(decoded_string)
28
+ cdc_payload = self.__get_outbox_record_as_dict(decoded_string)
29
29
  return self.__event_class.restore(
30
- id=cdc_message.payload.event_id,
31
- created_at=self.__get_created_at_in_event_format(cdc_message.payload.created_at),
32
- **orjson.loads(cdc_message.payload.payload),
30
+ id=cdc_payload.event_id,
31
+ created_at=self.__get_created_at_in_event_format(cdc_payload.created_at),
32
+ **orjson.loads(cdc_payload.payload),
33
33
  )
34
34
  except Exception as exception:
35
35
  raise NotValidCDCMessageException(decoded_string, exception) from exception
@@ -38,12 +38,12 @@ class CDCRecordBytesToEventDeserializer(BytesToMessageDeserializer[Event], Gener
38
38
  created_at_datetime = datetime.strptime(cdc_payload_created_at, CDCPayload.DATE_TIME_FORMAT)
39
39
  return created_at_datetime.strftime(Event.DATE_TIME_FORMAT)
40
40
 
41
- def __get_outbox_record_as_dict(self, decoded_string: str) -> CDCMessage:
41
+ def __get_outbox_record_as_dict(self, decoded_string: str) -> CDCPayload:
42
42
  decoded_record: dict = orjson.loads(decoded_string)
43
43
 
44
44
  payload = decoded_record.get("payload")
45
+
45
46
  if not isinstance(payload, dict):
46
47
  raise ValueError("The provided payload value is not valid")
47
48
 
48
- cdc_message = CDCMessage(payload=from_dict(CDCPayload, payload))
49
- return cdc_message
49
+ return from_dict(CDCPayload, payload)
@@ -5,6 +5,7 @@ from datetime import datetime
5
5
 
6
6
  from buz.event import Event
7
7
  from buz.kafka.infrastructure.cdc.cdc_message import CDCMessage, CDCPayload
8
+ from buz.kafka.infrastructure.cdc.cdc_schema import generate_cdc_schema
8
9
  from buz.kafka.infrastructure.serializers.byte_serializer import ByteSerializer
9
10
  from buz.kafka.infrastructure.serializers.implementations.json_byte_serializer import JSONByteSerializer
10
11
 
@@ -20,7 +21,8 @@ class CDCRecordBytesToEventSerializer(ByteSerializer):
20
21
  created_at=self.__adapt_created_to_cdc_format(data.created_at),
21
22
  event_fqn=data.fqn(),
22
23
  payload=self.__serialize_payload(data),
23
- )
24
+ ),
25
+ schema=generate_cdc_schema(data),
24
26
  )
25
27
  return self.__json_serializer.serialize(asdict(cdc_message))
26
28
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: buz
3
- Version: 2.15.0
3
+ Version: 2.15.1
4
4
  Summary: Buz is a set of light, simple and extensible implementations of event, command and query buses.
5
5
  License: MIT
6
6
  Author: Luis Pintado Lozano
@@ -169,12 +169,15 @@ buz/kafka/infrastructure/aiokafka/rebalance/__init__.py,sha256=47DEQpj8HBSa-_TIm
169
169
  buz/kafka/infrastructure/aiokafka/rebalance/kafka_callback_rebalancer.py,sha256=3l7NkTrCt3rBktVIS73cTmCOvv6eFguoCbGMYIUfCFc,1774
170
170
  buz/kafka/infrastructure/aiokafka/translators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
171
171
  buz/kafka/infrastructure/aiokafka/translators/consumer_initial_offset_position_translator.py,sha256=WmxkQfoXeTy9mIJtGGhM0eDKeQxhcJczeVAGCbtonVI,617
172
- buz/kafka/infrastructure/cdc/cdc_message.py,sha256=zLWUbQ2-fLsh_fei-sF8oQse2w30z25JnaJGZDq5f0E,1080
172
+ buz/kafka/infrastructure/cdc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
173
+ buz/kafka/infrastructure/cdc/cdc_message.py,sha256=Cpv2nA19SG3HZGBLH-wIJbuokzTTZKT_HNFm1VwGSk4,585
174
+ buz/kafka/infrastructure/cdc/cdc_payload.py,sha256=tQ_HdiREkORHlDoQQraj-KQj0x5MRuV8vP-C4x3cgHY,793
175
+ buz/kafka/infrastructure/cdc/cdc_schema.py,sha256=JVSj6MSWNh2aaoWp1LL8UNJtjBvKggoBgMtOOT0vkQQ,940
173
176
  buz/kafka/infrastructure/deserializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
174
177
  buz/kafka/infrastructure/deserializers/byte_deserializer.py,sha256=4fc6t-zvcFx6F5eoyEixH2uN0cM6aB0YRGwowIzz1RA,211
175
178
  buz/kafka/infrastructure/deserializers/bytes_to_message_deserializer.py,sha256=r40yq67DIElPi6ClmElbtR3VGrG2grNwgwuflXWOh20,345
176
179
  buz/kafka/infrastructure/deserializers/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
177
- buz/kafka/infrastructure/deserializers/implementations/cdc/cdc_record_bytes_to_event_deserializer.py,sha256=JSXHYNdikMnFf0mSEeaWfsxzcYZphTdfR732-RrCQW0,2002
180
+ buz/kafka/infrastructure/deserializers/implementations/cdc/cdc_record_bytes_to_event_deserializer.py,sha256=iMTx9zI_QzHcHvCbpfUkq6Hp67O_LXK5iYE1nzt_mqA,1913
178
181
  buz/kafka/infrastructure/deserializers/implementations/cdc/not_valid_cdc_message_exception.py,sha256=hgLLwTcC-C2DuJSOWUhmQsrd1bO9I1469869IqfAPOk,414
179
182
  buz/kafka/infrastructure/deserializers/implementations/json_byte_deserializer.py,sha256=L4b164-KweiQUwyRONhTMIGnAz48UPk0btLqjGOTNdk,373
180
183
  buz/kafka/infrastructure/deserializers/implementations/json_bytes_to_message_deserializer.py,sha256=YwugXkmOudMNtkVfCC4BFe3pFVpbM8rAL9bT88bZMRk,756
@@ -189,7 +192,7 @@ buz/kafka/infrastructure/kafka_python/kafka_python_producer.py,sha256=DkqqLSSXHB
189
192
  buz/kafka/infrastructure/kafka_python/translators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
190
193
  buz/kafka/infrastructure/kafka_python/translators/consumer_initial_offset_position_translator.py,sha256=hJ48_eyMcnbFL_Y5TOiMbGXrQSryuKk9CvP59MdqNOY,620
191
194
  buz/kafka/infrastructure/serializers/byte_serializer.py,sha256=T83sLdX9V5Oh1mzjRwHi_1DsTFI7KefFj7kmnz7JVy4,207
192
- buz/kafka/infrastructure/serializers/implementations/cdc_record_bytes_to_event_serializer.py,sha256=rWIHE91COwrmo61GV9SyIE6CODOPzpYrdaKbMfPCSJc,1482
195
+ buz/kafka/infrastructure/serializers/implementations/cdc_record_bytes_to_event_serializer.py,sha256=Cw6kbzCMHC2PwHf6DNCIKZB2H-WCEZ-HeIDNxQbkTow,1601
193
196
  buz/kafka/infrastructure/serializers/implementations/json_byte_serializer.py,sha256=KGkTQE7lq8VB048zCew_IlYgoWPozkmERYKg0t4DjOA,1510
194
197
  buz/kafka/infrastructure/serializers/kafka_header_serializer.py,sha256=ws9xr5lsJF6J-uVIplPym7vboo00KtXHfLJf8JjG0lo,649
195
198
  buz/locator/__init__.py,sha256=my8qfHL5htIT9RFFjzV4zGIPVW72tu4SMQbKKqBeSKo,293
@@ -246,7 +249,7 @@ buz/serializer/message_to_json_bytes_serializer.py,sha256=RGZJ64t4t4Pz2FCASZZCv-
246
249
  buz/wrapper/__init__.py,sha256=GnRdJFcncn-qp0hzDG9dBHLmTJSbHFVjE_yr-MdW_n4,77
247
250
  buz/wrapper/async_to_sync.py,sha256=OfK-vrVUhuN-LLLvekLdMbQYtH0ue5lfbvuasj6ovMI,698
248
251
  buz/wrapper/event_loop.py,sha256=pfBJ1g-8A2a3YgW8Gf9Fg0kkewoh3-wgTy2KIFDyfHk,266
249
- buz-2.15.0.dist-info/LICENSE,sha256=Jytu2S-2SPEgsB0y6BF-_LUxIWY7402fl0JSh36TLZE,1062
250
- buz-2.15.0.dist-info/METADATA,sha256=QGRmI-gxSAfhDPtg8oeGCNdgbEdiXS5SXCX3i3oEVzQ,1659
251
- buz-2.15.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
252
- buz-2.15.0.dist-info/RECORD,,
252
+ buz-2.15.1.dist-info/LICENSE,sha256=Jytu2S-2SPEgsB0y6BF-_LUxIWY7402fl0JSh36TLZE,1062
253
+ buz-2.15.1.dist-info/METADATA,sha256=l97q8FugUX3QM1sBfMPtE0quiE4aIyEMgHkewN6k0NA,1659
254
+ buz-2.15.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
255
+ buz-2.15.1.dist-info/RECORD,,
File without changes
File without changes