maleo-foundation 0.2.30__py3-none-any.whl → 0.2.31__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.
@@ -0,0 +1,61 @@
1
+ import asyncio
2
+ from functools import wraps
3
+ from pydantic import ValidationError
4
+ from typing import Optional, Type, Union
5
+ from maleo_foundation.types import BaseTypes
6
+ from maleo_foundation.models.transfers.results.client.service import \
7
+ BaseClientServiceResultsTransfers
8
+
9
+ class BaseClientUtils:
10
+ @staticmethod
11
+ def result_processor(
12
+ fail_class:Type[BaseClientServiceResultsTransfers.Fail],
13
+ data_found_class:Union[
14
+ Type[BaseClientServiceResultsTransfers.SingleData],
15
+ Type[BaseClientServiceResultsTransfers.UnpaginatedMultipleData],
16
+ Type[BaseClientServiceResultsTransfers.PaginatedMultipleData]
17
+ ],
18
+ no_data_class:Optional[Type[BaseClientServiceResultsTransfers.NoData]] = None,
19
+ ):
20
+ """Decorator to handle repository-related exceptions consistently."""
21
+ def decorator(func):
22
+ def _processor(result:BaseTypes.StringToAnyDict):
23
+ if "success" not in result and "data" not in result:
24
+ raise ValueError("Result did not have both 'success' and 'data' field")
25
+ success:bool = result.get("success")
26
+ data:BaseTypes.StringToAnyDict = result.get("data")
27
+ if not success:
28
+ validated_result = fail_class.model_validate(result)
29
+ return validated_result
30
+ else:
31
+ if data is None:
32
+ if no_data_class is None:
33
+ raise ValueError("'no_data_class' must be given to validate No Data")
34
+ validated_result = no_data_class.model_validate(result)
35
+ return validated_result
36
+ else:
37
+ validated_result = data_found_class.model_validate(result)
38
+ return validated_result
39
+ if asyncio.iscoroutinefunction(func):
40
+ @wraps(func)
41
+ async def async_wrapper(*args, **kwargs):
42
+ try:
43
+ result:BaseTypes.StringToAnyDict = await func(*args, **kwargs)
44
+ return _processor(result=result)
45
+ except ValidationError as e:
46
+ raise
47
+ except Exception as e:
48
+ raise
49
+ return async_wrapper
50
+ else:
51
+ @wraps(func)
52
+ def sync_wrapper(*args, **kwargs):
53
+ try:
54
+ result:BaseTypes.StringToAnyDict = func(*args, **kwargs)
55
+ return _processor(result=result)
56
+ except ValidationError as e:
57
+ raise
58
+ except Exception as e:
59
+ raise
60
+ return sync_wrapper
61
+ return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.30
3
+ Version: 0.2.31
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -97,6 +97,7 @@ maleo_foundation/models/transfers/results/service/repository.py,sha256=xz9RakOBE
97
97
  maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256=HZJWMy2dskzOCzLmp_UaL9rjbQ-sDMI7sd2bXb-4QOU,175
98
98
  maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
99
99
  maleo_foundation/utils/__init__.py,sha256=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZMdOthY,520
100
+ maleo_foundation/utils/client.py,sha256=F5X9TUxWQgeOHjwsMpPoSRhZANQYZ_iFv0RJDTUVhrw,2820
100
101
  maleo_foundation/utils/controller.py,sha256=3n9HcWHqywLhfpgTkzd_NrjWNJgTwGBSokqGgJKeBAU,4132
101
102
  maleo_foundation/utils/exceptions.py,sha256=kDLTWiUauvc-fSKrEyxlGvIi2NtZIAhJ9bV3OXnpTyo,6253
102
103
  maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
@@ -115,7 +116,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
115
116
  maleo_foundation/utils/loaders/credential/google.py,sha256=SKsqPuFnAiCcYLf24CxKnMybhVHpgqnq1gGSlThqjts,994
116
117
  maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
117
118
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
118
- maleo_foundation-0.2.30.dist-info/METADATA,sha256=4vzd8oLmEHLdC7C9fNuRfYBPFfKRalLzOncVtPZ7p3Y,3598
119
- maleo_foundation-0.2.30.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
120
- maleo_foundation-0.2.30.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
121
- maleo_foundation-0.2.30.dist-info/RECORD,,
119
+ maleo_foundation-0.2.31.dist-info/METADATA,sha256=cEibWJqK82D4zLoCjT8Vko17fGVcqqTgTEDDfK4HYXI,3598
120
+ maleo_foundation-0.2.31.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
121
+ maleo_foundation-0.2.31.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
122
+ maleo_foundation-0.2.31.dist-info/RECORD,,