maleo-foundation 0.2.47__py3-none-any.whl → 0.2.49__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.
@@ -1,7 +1,7 @@
1
1
  import inspect
2
2
  from fastapi import status
3
3
  from functools import wraps
4
- from typing import Awaitable, Callable, Dict, List
4
+ from typing import Awaitable, Callable, Dict, List, Union
5
5
  from maleo_foundation.types import BaseTypes
6
6
  from maleo_foundation.models.responses import BaseResponses
7
7
  from maleo_foundation.models.transfers.parameters.general \
@@ -53,33 +53,37 @@ class BaseControllerUtils:
53
53
  if not isinstance(result.content, Dict):
54
54
  return result
55
55
 
56
- #* Process the fields if needed
57
- if (result.success
56
+ #* Recursive function to apply expansion processors
57
+ def recursive_expand(data:Union[Dict, List], expand:BaseTypes.OptionalListOfStrings):
58
+ if isinstance(data, list):
59
+ for idx, item in enumerate(data):
60
+ data[idx] = recursive_expand(item, expand)
61
+ return data
62
+ elif isinstance(data, Dict):
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)
70
+ )
71
+ data = processor(parameters)
72
+ for key in data.keys():
73
+ if isinstance(data[key], (Dict, List)):
74
+ data[key] = recursive_expand(data[key], expand)
75
+ return data
76
+ else:
77
+ return data
78
+
79
+ #* Process expansions recursively if needed
80
+ if (
81
+ result.success
58
82
  and result.content.get("data", None) is not None
59
83
  and field_expansion_processors is not None
60
84
  ):
61
85
  data = result.content["data"]
62
- if isinstance(data, List):
63
- for idx, dt in enumerate(data):
64
- for processor in field_expansion_processors:
65
- raw_parameters = {"data": dt, "expand": expand}
66
- parameters = (
67
- BaseGeneralParametersTransfers
68
- .FieldExpansionProcessor
69
- .model_validate(raw_parameters)
70
- )
71
- dt = processor(parameters)
72
- data[idx] = dt
73
- elif isinstance(data, Dict):
74
- raw_parameters = {"data": data, "expand": expand}
75
- parameters = (
76
- BaseGeneralParametersTransfers
77
- .FieldExpansionProcessor
78
- .model_validate(raw_parameters)
79
- )
80
- for processor in field_expansion_processors:
81
- data = processor(parameters)
82
- result.content["data"] = data
86
+ result.content["data"] = recursive_expand(data, expand)
83
87
  result.process_response()
84
88
 
85
89
  return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.47
3
+ Version: 0.2.49
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -99,7 +99,7 @@ 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=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZMdOthY,520
101
101
  maleo_foundation/utils/client.py,sha256=F5X9TUxWQgeOHjwsMpPoSRhZANQYZ_iFv0RJDTUVhrw,2820
102
- maleo_foundation/utils/controller.py,sha256=JppDEjXu4Ktlwr-0N497AEyihlRQbbn_ttOcQVGVwXw,4322
102
+ maleo_foundation/utils/controller.py,sha256=XhCcRy-OxJzv0xkZmVEBOkYqbaAckHaMaW6ND6Be-_c,4520
103
103
  maleo_foundation/utils/exceptions.py,sha256=kDLTWiUauvc-fSKrEyxlGvIi2NtZIAhJ9bV3OXnpTyo,6253
104
104
  maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
105
105
  maleo_foundation/utils/logging.py,sha256=W5Fhk_xAXVqSujaY8mv3hRH4wlQSpUn4ReuMoiKcQa4,7759
@@ -117,7 +117,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
117
117
  maleo_foundation/utils/loaders/credential/google.py,sha256=SKsqPuFnAiCcYLf24CxKnMybhVHpgqnq1gGSlThqjts,994
118
118
  maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
119
119
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
120
- maleo_foundation-0.2.47.dist-info/METADATA,sha256=TqcnGxmaqaccse8mzjdZL6ZgeGztSPQpDCTe6ozPyNQ,3598
121
- maleo_foundation-0.2.47.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
122
- maleo_foundation-0.2.47.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
123
- maleo_foundation-0.2.47.dist-info/RECORD,,
120
+ maleo_foundation-0.2.49.dist-info/METADATA,sha256=8U6ht0Me4xfpRVvEEqRlbdAyee_2wiIEXtPifCoQSBY,3598
121
+ maleo_foundation-0.2.49.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
122
+ maleo_foundation-0.2.49.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
123
+ maleo_foundation-0.2.49.dist-info/RECORD,,