maleo-foundation 0.2.66__py3-none-any.whl → 0.2.68__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.
@@ -24,4 +24,26 @@ class BaseGeneralExpandedTypes:
24
24
  BaseTypes.ListOrDictOfAny
25
25
  ]
26
26
  ]
27
+ ]
28
+
29
+ #* Modification processor related types
30
+ FieldModificationProcessor = Callable[
31
+ [BaseGeneralParametersTransfers.FieldModificationProcessor],
32
+ BaseTypes.ListOrDictOfAny
33
+ ]
34
+
35
+ ListOfFieldModificationProcessor = List[
36
+ Callable[
37
+ [BaseGeneralParametersTransfers.FieldModificationProcessor],
38
+ BaseTypes.ListOrDictOfAny
39
+ ]
40
+ ]
41
+
42
+ OptionalListOfFieldModificationProcessor = Optional[
43
+ List[
44
+ Callable[
45
+ [BaseGeneralParametersTransfers.FieldModificationProcessor],
46
+ BaseTypes.ListOrDictOfAny
47
+ ]
48
+ ]
27
49
  ]
@@ -8,6 +8,8 @@ class BaseGeneralParametersTransfers:
8
8
  BaseParameterSchemas.Data
9
9
  ): pass
10
10
 
11
+ class FieldModificationProcessor(BaseParameterSchemas.Data): pass
12
+
11
13
  class GetSingleQuery(BaseParameterSchemas.OptionalListOfStatuses): pass
12
14
 
13
15
  class BaseGetSingle(
@@ -61,13 +61,14 @@ class BaseControllerUtils:
61
61
  return data
62
62
  elif isinstance(data, Dict):
63
63
  #* Apply each processor to current dict
64
- for processor in field_expansion_processors or []:
65
- raw_parameters = {"data": data, "expand": expand}
66
- parameters = (
67
- BaseGeneralParametersTransfers
68
- .FieldExpansionProcessor
69
- .model_validate(raw_parameters)
64
+ parameters = (
65
+ BaseGeneralParametersTransfers
66
+ .FieldExpansionProcessor(
67
+ data=data,
68
+ expand=expand
70
69
  )
70
+ )
71
+ for processor in field_expansion_processors or []:
71
72
  data = processor(parameters)
72
73
  for key in data.keys():
73
74
  if isinstance(data[key], (Dict, List)):
@@ -86,6 +87,61 @@ class BaseControllerUtils:
86
87
  result.content["data"] = recursive_expand(data, expand)
87
88
  result.process_response()
88
89
 
90
+ return result
91
+ return wrapper
92
+ return decorator
93
+
94
+ @staticmethod
95
+ def field_modification_handler(
96
+ field_modification_processors:BaseGeneralExpandedTypes.OptionalListOfFieldModificationProcessor = None
97
+ ):
98
+ """
99
+ Decorator to handle expandable fields validation and processing.
100
+
101
+ Args:
102
+ expandable_fields_dependencies_map: Dictionary where keys are dependency fields and values are lists of dependent fields
103
+ field_modification_processors: List of processor functions that handle that field's data
104
+ """
105
+ def decorator(func:Callable[..., Awaitable[BaseServiceRESTControllerResults]]):
106
+ @wraps(func)
107
+ async def wrapper(*args, **kwargs):
108
+ #* Call the original function
109
+ result = await func(*args, **kwargs)
110
+
111
+ if not isinstance(result.content, Dict):
112
+ return result
113
+
114
+ #* Recursive function to apply modification processors
115
+ def recursive_modify(data:Union[Dict, List]):
116
+ if isinstance(data, list):
117
+ for idx, item in enumerate(data):
118
+ data[idx] = recursive_modify(item)
119
+ return data
120
+ elif isinstance(data, Dict):
121
+ #* Apply each processor to current dict
122
+ parameters = (
123
+ BaseGeneralParametersTransfers
124
+ .FieldModificationProcessor(data=data)
125
+ )
126
+ for processor in field_modification_processors or []:
127
+ data = processor(parameters)
128
+ for key in data.keys():
129
+ if isinstance(data[key], (Dict, List)):
130
+ data[key] = recursive_modify(data[key])
131
+ return data
132
+ else:
133
+ return data
134
+
135
+ #* Process modifications recursively if needed
136
+ if (
137
+ result.success
138
+ and result.content.get("data", None) is not None
139
+ and field_modification_processors is not None
140
+ ):
141
+ data = result.content["data"]
142
+ result.content["data"] = recursive_modify(data)
143
+ result.process_response()
144
+
89
145
  return result
90
146
  return wrapper
91
147
  return decorator
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
2
  from fastapi import Request, status
3
+ from fastapi.encoders import jsonable_encoder
3
4
  from fastapi.exceptions import RequestValidationError
4
5
  from fastapi.responses import JSONResponse
5
6
  from functools import wraps
@@ -24,8 +25,9 @@ class BaseExceptions:
24
25
 
25
26
  @staticmethod
26
27
  async def validation_exception_handler(request:Request, exc:RequestValidationError):
28
+ serialized_error = jsonable_encoder(exc.errors())
27
29
  return JSONResponse(
28
- content=BaseResponses.ValidationError(other=exc.errors()).model_dump(mode="json"),
30
+ content=BaseResponses.ValidationError(other=serialized_error).model_dump(mode="json"),
29
31
  status_code=status.HTTP_422_UNPROCESSABLE_ENTITY
30
32
  )
31
33
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.66
3
+ Version: 0.2.68
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -21,7 +21,7 @@ maleo_foundation/client/services/hash/hmac.py,sha256=-L0sTv5tcmfu-UyBD_InpxFJ2w7
21
21
  maleo_foundation/client/services/hash/sha256.py,sha256=af08036kkEZ61IY_ktxwHmQnAACd6hWXYA_ZC9S1-tg,2142
22
22
  maleo_foundation/expanded_types/__init__.py,sha256=Jz2NoY9609QIM84UonmJU-10CMUR9t9fkk9ZFLnU7Js,384
23
23
  maleo_foundation/expanded_types/client.py,sha256=WvT911cDsfWtCCYVaDeQ90ba_eCYnzC-CRSXCHtLIuo,2414
24
- maleo_foundation/expanded_types/general.py,sha256=_nSG5jgMgA1ntjBdVjQqkg0h1WNytLsIqkUrsKDmrfU,832
24
+ maleo_foundation/expanded_types/general.py,sha256=vPWcUI3KTsppiLx1QVmafkawmcM5B0clkj9hrLdJjkM,1463
25
25
  maleo_foundation/expanded_types/hash.py,sha256=QOH_HczGY7CRUZJ5gC84RunCAiUzNSt7DYXI7uqtwkM,416
26
26
  maleo_foundation/expanded_types/key.py,sha256=qopQcO6V82RxiCtixe--IBce5MRT4buOun4RSA-LLm0,573
27
27
  maleo_foundation/expanded_types/repository.py,sha256=hemtQGDqSQO8N4_y7pktXqBlrcDacs4EiUZ3hFk4n2o,2482
@@ -68,7 +68,7 @@ maleo_foundation/models/transfers/general/signature.py,sha256=J9xQy2HjpCQOnES7RJ
68
68
  maleo_foundation/models/transfers/general/token.py,sha256=O_U6dQS7oMScJzqufl6Pe21pTxMsYhOzKH8aFLxjblQ,2895
69
69
  maleo_foundation/models/transfers/parameters/__init__.py,sha256=oKW4RPIEISISRjsJzD8lsCGY1HhZRTzshPpWHcJu86k,353
70
70
  maleo_foundation/models/transfers/parameters/client.py,sha256=wI2-ML99yn5HR0AciFg2C9EQixrWjbIR8x_bDbqKeDM,4069
71
- maleo_foundation/models/transfers/parameters/general.py,sha256=opezjUBygMhYMz85uNShx7sIgTPS5Y7JvefhMkCXve4,708
71
+ maleo_foundation/models/transfers/parameters/general.py,sha256=-nSIcn0thtodk-69Uwj6qdrX8zfe-PX-gWwD-_VCVyY,779
72
72
  maleo_foundation/models/transfers/parameters/key.py,sha256=ZhWcbPJZvl8AF_qlecG-4-9_Ym6EbU7nngRo3AtbScY,432
73
73
  maleo_foundation/models/transfers/parameters/service.py,sha256=-mCGqGYTuH4tKZXwtFrETlfyVx20Yc2wUfK0Nv4-wtY,6284
74
74
  maleo_foundation/models/transfers/parameters/signature.py,sha256=ysYkALwqNXn13HP8xUOnPlboL9pgFLmQ9f7OpZe9dDw,483
@@ -99,8 +99,8 @@ maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256
99
99
  maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
100
100
  maleo_foundation/utils/__init__.py,sha256=KoERe8U2ERGZeAKUNBPW_itk7g9YpH7v7_mD9_i050o,461
101
101
  maleo_foundation/utils/client.py,sha256=F5X9TUxWQgeOHjwsMpPoSRhZANQYZ_iFv0RJDTUVhrw,2820
102
- maleo_foundation/utils/controller.py,sha256=XhCcRy-OxJzv0xkZmVEBOkYqbaAckHaMaW6ND6Be-_c,4520
103
- maleo_foundation/utils/exceptions.py,sha256=kDLTWiUauvc-fSKrEyxlGvIi2NtZIAhJ9bV3OXnpTyo,6253
102
+ maleo_foundation/utils/controller.py,sha256=D8uUfqkMpPw8M8Ykn8Uxn7dfRGwxmBxSP1h9xSkYw1I,6945
103
+ maleo_foundation/utils/exceptions.py,sha256=eM__Mxo-BC5d7JmoBd-Wh-fmryUdfjNfOuY_eONK5Fk,6361
104
104
  maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
105
105
  maleo_foundation/utils/logging.py,sha256=W5Fhk_xAXVqSujaY8mv3hRH4wlQSpUn4ReuMoiKcQa4,7759
106
106
  maleo_foundation/utils/merger.py,sha256=z9GROLVtGpwx84bOiakBFphKazsI-9l3F3WauTDwQLs,597
@@ -118,7 +118,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
118
118
  maleo_foundation/utils/loaders/credential/google.py,sha256=SKsqPuFnAiCcYLf24CxKnMybhVHpgqnq1gGSlThqjts,994
119
119
  maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
120
120
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
121
- maleo_foundation-0.2.66.dist-info/METADATA,sha256=bY6sPTZ-OaBLRJpHBQS3Yqm3bpFPouOI1nhlvSqi9rs,3598
122
- maleo_foundation-0.2.66.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
123
- maleo_foundation-0.2.66.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
124
- maleo_foundation-0.2.66.dist-info/RECORD,,
121
+ maleo_foundation-0.2.68.dist-info/METADATA,sha256=So5IYXyl2wFd4nmK_7NKNTrXvNQ6rXFlYXdufF3C5eI,3598
122
+ maleo_foundation-0.2.68.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
123
+ maleo_foundation-0.2.68.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
124
+ maleo_foundation-0.2.68.dist-info/RECORD,,