|
7 | 7 | from typing import Annotated, Any, Dict, List, Mapping, Optional, Union |
8 | 8 |
|
9 | 9 | from airbyte_protocol_dataclasses.models import * # noqa: F403 # Allow '*' |
10 | | - |
11 | | -if sys.platform == 'emscripten': |
12 | | - from serpyco.metadata import Alias |
13 | | -else: |
14 | | - from serpyco_rs.metadata import Alias |
15 | | - |
16 | | -# ruff: noqa: F405 # ignore fuzzy import issues with 'import *' |
17 | | - |
18 | | - |
19 | | -@dataclass |
20 | | -class AirbyteStateBlob: |
21 | | - """ |
22 | | - A dataclass that dynamically sets attributes based on provided keyword arguments and positional arguments. |
23 | | - Used to "mimic" pydantic Basemodel with ConfigDict(extra='allow') option. |
24 | | -
|
25 | | - The `AirbyteStateBlob` class allows for flexible instantiation by accepting any number of keyword arguments |
26 | | - and positional arguments. These are used to dynamically update the instance's attributes. This class is useful |
27 | | - in scenarios where the attributes of an object are not known until runtime and need to be set dynamically. |
28 | | -
|
29 | | - Attributes: |
30 | | - kwargs (InitVar[Mapping[str, Any]]): A dictionary of keyword arguments used to set attributes dynamically. |
31 | | -
|
32 | | - Methods: |
33 | | - __init__(*args: Any, **kwargs: Any) -> None: |
34 | | - Initializes the `AirbyteStateBlob` by setting attributes from the provided arguments. |
35 | | -
|
36 | | - __eq__(other: object) -> bool: |
37 | | - Checks equality between two `AirbyteStateBlob` instances based on their internal dictionaries. |
38 | | - Returns `False` if the other object is not an instance of `AirbyteStateBlob`. |
39 | | - """ |
40 | | - |
41 | | - kwargs: InitVar[Mapping[str, Any]] |
42 | | - |
43 | | - def __init__(self, *args: Any, **kwargs: Any) -> None: |
44 | | - # Set any attribute passed in through kwargs |
45 | | - for arg in args: |
46 | | - self.__dict__.update(arg) |
47 | | - for key, value in kwargs.items(): |
48 | | - setattr(self, key, value) |
49 | | - |
50 | | - def __eq__(self, other: object) -> bool: |
51 | | - return ( |
52 | | - False |
53 | | - if not isinstance(other, AirbyteStateBlob) |
54 | | - else bool(self.__dict__ == other.__dict__) |
55 | | - ) |
56 | | - |
57 | | - |
58 | | -# The following dataclasses have been redeclared to include the new version of AirbyteStateBlob |
59 | | -@dataclass |
60 | | -class AirbyteStreamState: |
61 | | - stream_descriptor: StreamDescriptor # type: ignore [name-defined] |
62 | | - stream_state: Optional[AirbyteStateBlob] = None |
63 | | - |
64 | | - |
65 | | -@dataclass |
66 | | -class AirbyteGlobalState: |
67 | | - stream_states: List[AirbyteStreamState] |
68 | | - shared_state: Optional[AirbyteStateBlob] = None |
69 | | - |
70 | | - |
71 | | -@dataclass |
72 | | -class AirbyteStateMessage: |
73 | | - type: Optional[AirbyteStateType] = None # type: ignore [name-defined] |
74 | | - stream: Optional[AirbyteStreamState] = None |
75 | | - global_: Annotated[AirbyteGlobalState | None, Alias("global")] = ( |
76 | | - None # "global" is a reserved keyword in python ⇒ Alias is used for (de-)serialization |
77 | | - ) |
78 | | - data: Optional[Dict[str, Any]] = None |
79 | | - sourceStats: Optional[AirbyteStateStats] = None # type: ignore [name-defined] |
80 | | - destinationStats: Optional[AirbyteStateStats] = None # type: ignore [name-defined] |
81 | | - |
82 | | - |
83 | | -@dataclass |
84 | | -class AirbyteMessage: |
85 | | - type: Type # type: ignore [name-defined] |
86 | | - log: Optional[AirbyteLogMessage] = None # type: ignore [name-defined] |
87 | | - spec: Optional[ConnectorSpecification] = None # type: ignore [name-defined] |
88 | | - connectionStatus: Optional[AirbyteConnectionStatus] = None # type: ignore [name-defined] |
89 | | - catalog: Optional[AirbyteCatalog] = None # type: ignore [name-defined] |
90 | | - record: Optional[AirbyteRecordMessage] = None # type: ignore [name-defined] |
91 | | - state: Optional[AirbyteStateMessage] = None |
92 | | - trace: Optional[AirbyteTraceMessage] = None # type: ignore [name-defined] |
93 | | - control: Optional[AirbyteControlMessage] = None # type: ignore [name-defined] |
0 commit comments