airbyte-cdk 6.60.0.post14.dev16483785754__py3-none-any.whl → 6.60.0.post15.dev16484441057__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.
- airbyte_cdk/models/airbyte_protocol_serializers.py +85 -23
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/METADATA +1 -1
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/RECORD +7 -7
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/LICENSE_SHORT +0 -0
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/WHEEL +0 -0
- {airbyte_cdk-6.60.0.post14.dev16483785754.dist-info → airbyte_cdk-6.60.0.post15.dev16484441057.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,9 @@
|
|
1
1
|
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
|
2
2
|
import sys
|
3
|
-
from typing import Any, Dict
|
3
|
+
from typing import Any, Dict, Type, TypeVar
|
4
|
+
|
5
|
+
import orjson
|
6
|
+
from pydantic import ValidationError
|
4
7
|
|
5
8
|
from .airbyte_protocol import ( # type: ignore[attr-defined] # all classes are imported to airbyte_protocol via *
|
6
9
|
AirbyteCatalog,
|
@@ -17,39 +20,98 @@ from .airbyte_protocol import ( # type: ignore[attr-defined] # all classes are
|
|
17
20
|
USE_RUST_BACKEND = sys.platform != "emscripten"
|
18
21
|
"""When run in WASM, use the pure Python backend for serpyco."""
|
19
22
|
|
20
|
-
if USE_RUST_BACKEND:
|
21
|
-
from serpyco_rs import CustomType, Serializer
|
22
|
-
else:
|
23
|
-
from serpyco import CustomType, Serializer
|
24
23
|
|
24
|
+
T = TypeVar("T")
|
25
|
+
|
26
|
+
class CustomSerializer:
|
27
|
+
"""Custom serializer that mimics serpyco-rs Serializer API"""
|
28
|
+
|
29
|
+
def __init__(
|
30
|
+
self,
|
31
|
+
model_class: Type[T],
|
32
|
+
omit_none: bool = False,
|
33
|
+
custom_type_resolver: Callable | None = None,
|
34
|
+
):
|
35
|
+
self.model_class = model_class
|
36
|
+
self.omit_none = omit_none
|
37
|
+
self.custom_type_resolver = custom_type_resolver
|
38
|
+
|
39
|
+
def dump(self, obj: T) -> Dict[str, Any]:
|
40
|
+
"""Convert dataclass to dictionary, omitting None values if configured"""
|
41
|
+
if hasattr(obj, "__dict__"):
|
42
|
+
result = {}
|
43
|
+
for key, value in obj.__dict__.items():
|
44
|
+
if self.omit_none and value is None:
|
45
|
+
continue
|
46
|
+
# Handle custom types like AirbyteStateBlob
|
47
|
+
if self.custom_type_resolver and hasattr(value, "__class__"):
|
48
|
+
custom_handler = self.custom_type_resolver(value.__class__)
|
49
|
+
if custom_handler:
|
50
|
+
value = custom_handler.serialize(value)
|
51
|
+
# Recursively handle nested objects
|
52
|
+
if hasattr(value, "__dict__"):
|
53
|
+
value = self._serialize_nested(value)
|
54
|
+
elif isinstance(value, list):
|
55
|
+
value = [
|
56
|
+
self._serialize_nested(item) if hasattr(item, "__dict__") else item
|
57
|
+
for item in value
|
58
|
+
]
|
59
|
+
result[key] = value
|
60
|
+
return result
|
61
|
+
return obj.__dict__ if hasattr(obj, "__dict__") else {}
|
25
62
|
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
return
|
63
|
+
def load(self, data: Dict[str, Any]) -> T:
|
64
|
+
"""Convert dictionary to dataclass instance"""
|
65
|
+
# Handle custom types
|
66
|
+
return self.model_class(**data)
|
67
|
+
|
68
|
+
def _serialize_nested(self, obj: Any) -> Any:
|
69
|
+
"""Helper to serialize nested objects"""
|
70
|
+
if hasattr(obj, "__dict__"):
|
71
|
+
result = {}
|
72
|
+
for key, value in obj.__dict__.items():
|
73
|
+
if self.omit_none and value is None:
|
74
|
+
continue
|
75
|
+
result[key] = value
|
76
|
+
return result
|
77
|
+
return obj
|
78
|
+
|
79
|
+
|
80
|
+
if USE_RUST_BACKEND:
|
81
|
+
from serpyco_rs import CustomType, Serializer # type: ignore[import]
|
30
82
|
|
31
|
-
|
32
|
-
return AirbyteStateBlob(value)
|
83
|
+
SERIALIZER = Serializer if USE_RUST_BACKEND else CustomSerializer
|
33
84
|
|
34
|
-
|
35
|
-
|
85
|
+
# Making this a no-op for now:
|
86
|
+
custom_type_resolver = None
|
36
87
|
|
88
|
+
# No idea why this is here. Commenting out for now.
|
89
|
+
# def custom_type_resolver(t: type) -> AirbyteStateBlobType | None:
|
90
|
+
# return AirbyteStateBlobType() if t is AirbyteStateBlob else None
|
91
|
+
#
|
92
|
+
# class AirbyteStateBlobType(CustomType[AirbyteStateBlob, Dict[str, Any]]):
|
93
|
+
# def serialize(self, value: AirbyteStateBlob) -> Dict[str, Any]:
|
94
|
+
# # cant use orjson.dumps() directly because private attributes are excluded, e.g. "__ab_full_refresh_sync_complete"
|
95
|
+
# return {k: v for k, v in value.__dict__.items()}
|
37
96
|
|
38
|
-
def
|
39
|
-
|
97
|
+
# def deserialize(self, value: Dict[str, Any]) -> AirbyteStateBlob:
|
98
|
+
# return AirbyteStateBlob(value)
|
40
99
|
|
100
|
+
# def get_json_schema(self) -> Dict[str, Any]:
|
101
|
+
# return {"type": "object"}
|
41
102
|
|
42
|
-
|
43
|
-
|
44
|
-
|
103
|
+
# Create serializer instances maintaining the same API
|
104
|
+
AirbyteCatalogSerializer = SERIALIZER(AirbyteCatalog, omit_none=True)
|
105
|
+
AirbyteStreamSerializer = SERIALIZER(AirbyteStream, omit_none=True)
|
106
|
+
AirbyteStreamStateSerializer = SERIALIZER(
|
45
107
|
AirbyteStreamState, omit_none=True, custom_type_resolver=custom_type_resolver
|
46
108
|
)
|
47
|
-
AirbyteStateMessageSerializer =
|
109
|
+
AirbyteStateMessageSerializer = SERIALIZER(
|
48
110
|
AirbyteStateMessage, omit_none=True, custom_type_resolver=custom_type_resolver
|
49
111
|
)
|
50
|
-
AirbyteMessageSerializer =
|
112
|
+
AirbyteMessageSerializer = SERIALIZER(
|
51
113
|
AirbyteMessage, omit_none=True, custom_type_resolver=custom_type_resolver
|
52
114
|
)
|
53
|
-
ConfiguredAirbyteCatalogSerializer =
|
54
|
-
ConfiguredAirbyteStreamSerializer =
|
55
|
-
ConnectorSpecificationSerializer =
|
115
|
+
ConfiguredAirbyteCatalogSerializer = SERIALIZER(ConfiguredAirbyteCatalog, omit_none=True)
|
116
|
+
ConfiguredAirbyteStreamSerializer = SERIALIZER(ConfiguredAirbyteStream, omit_none=True)
|
117
|
+
ConnectorSpecificationSerializer = SERIALIZER(ConnectorSpecification, omit_none=True)
|
@@ -50,7 +50,7 @@ airbyte_cdk/manifest_migrations/migrations/registry.yaml,sha256=F-hdapvl_vZnsI7C
|
|
50
50
|
airbyte_cdk/manifest_migrations/migrations_registry.py,sha256=zly2fwaOxDukqC7eowzrDlvhA2v71FjW74kDzvRXhSY,2619
|
51
51
|
airbyte_cdk/models/__init__.py,sha256=Et9wJWs5VOWynGbb-3aJRhsdAHAiLkNNLxdwqJAuqkw,2114
|
52
52
|
airbyte_cdk/models/airbyte_protocol.py,sha256=KpKBePA74K_ay231JBIuQVePCwZa-b8qb0RKRdy-nGk,3707
|
53
|
-
airbyte_cdk/models/airbyte_protocol_serializers.py,sha256=
|
53
|
+
airbyte_cdk/models/airbyte_protocol_serializers.py,sha256=4lJUZrnoLypM3BFagf4R64XyhRbsMfUffZ_1nHCDNKQ,4503
|
54
54
|
airbyte_cdk/models/connector_metadata.py,sha256=BD6CO8c3mHavxRJAcwP29sHtNNVLVSNFNQLgHOVxrwA,3229
|
55
55
|
airbyte_cdk/models/well_known_types.py,sha256=EquepbisGPuCSrs_D7YVVnMR9-ShhUr21wnFz3COiJs,156
|
56
56
|
airbyte_cdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -424,9 +424,9 @@ airbyte_cdk/utils/slice_hasher.py,sha256=EDxgROHDbfG-QKQb59m7h_7crN1tRiawdf5uU7G
|
|
424
424
|
airbyte_cdk/utils/spec_schema_transformations.py,sha256=-5HTuNsnDBAhj-oLeQXwpTGA0HdcjFOf2zTEMUTTg_Y,816
|
425
425
|
airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
|
426
426
|
airbyte_cdk/utils/traced_exception.py,sha256=C8uIBuCL_E4WnBAOPSxBicD06JAldoN9fGsQDp463OY,6292
|
427
|
-
airbyte_cdk-6.60.0.
|
428
|
-
airbyte_cdk-6.60.0.
|
429
|
-
airbyte_cdk-6.60.0.
|
430
|
-
airbyte_cdk-6.60.0.
|
431
|
-
airbyte_cdk-6.60.0.
|
432
|
-
airbyte_cdk-6.60.0.
|
427
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
|
428
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/LICENSE_SHORT,sha256=aqF6D1NcESmpn-cqsxBtszTEnHKnlsp8L4x9wAh3Nxg,55
|
429
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/METADATA,sha256=tM0itT4fBMskZDLi6wZ-R8gLDUJgqowr5R_CCoY0Oc0,6512
|
430
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
431
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/entry_points.txt,sha256=AKWbEkHfpzzk9nF9tqBUaw1MbvTM4mGtEzmZQm0ZWvM,139
|
432
|
+
airbyte_cdk-6.60.0.post15.dev16484441057.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|