nlbone 0.8.2__py3-none-any.whl → 0.8.4__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.
@@ -14,6 +14,7 @@ def assemble_response(
14
14
  session,
15
15
  base_schema: type[BaseModel] | None,
16
16
  scope_map: dict[str, set[str]] = None,
17
+ **kwargs,
17
18
  ) -> Dict[str, Any]:
18
19
  base = {f: getattr(obj, f, None) for f in reg.default_fields - set(reg.rules.keys())}
19
20
  if base_schema:
@@ -24,6 +25,7 @@ def assemble_response(
24
25
  "entity": obj,
25
26
  "db": session,
26
27
  "pricing_service": Container.pricing_service(),
28
+ **kwargs,
27
29
  }
28
30
  roots = {name.split(".", 1)[0] for name in selected_rules.keys()}
29
31
  for root in roots:
@@ -1,6 +1,7 @@
1
1
  import json
2
+ import re
2
3
  from math import ceil
3
- from typing import Any, List, Optional
4
+ from typing import Any, List, Optional, Dict, Union
4
5
 
5
6
  from fastapi import Query
6
7
 
@@ -53,36 +54,58 @@ class PaginateRequest:
53
54
  return result
54
55
 
55
56
  @staticmethod
56
- def _parse_filters(filters: str) -> dict[str, Any]:
57
+ def _parse_filters(filters: str) -> Dict[str, Any]:
57
58
  if not filters:
58
59
  return {}
59
- # JSON object or array
60
- try:
61
- if filters.strip().startswith(("{", "[")):
62
- data = json.loads(filters)
60
+
61
+ stripped_filters = filters.strip()
62
+
63
+ if stripped_filters.startswith(("{", "[")):
64
+ try:
65
+ data = json.loads(stripped_filters)
63
66
  return dict(data) if isinstance(data, dict) else {"$": data}
64
- except Exception:
65
- pass
67
+ except (json.JSONDecodeError, TypeError):
68
+ pass
69
+
70
+ pattern = re.compile(r"(?P<key>[^:,]+):\s*(?P<value>\[.*?\]|[^,]+)")
71
+ filters_dict: Dict[str, Any] = {}
72
+
73
+ for match in pattern.finditer(stripped_filters):
74
+ key = match.group("key").strip().strip("'\"")
75
+ value_raw = match.group("value").strip()
76
+
77
+ filters_dict[key] = PaginateRequest._process_value(value_raw)
66
78
 
67
- # CSV key:value pairs
68
- filters_dict: dict[str, Any] = {}
69
- for part in filters.split(","):
70
- part = part.strip()
71
- if not part or ":" not in part:
72
- continue
73
- key, value = part.split(":", 1)
74
- key = key.strip().strip("'\"")
75
- value_raw = value.strip().strip("'\"")
76
- # cast common primitives
77
- if value_raw.isdigit():
78
- value_cast: Any = int(value_raw)
79
- elif value_raw.lower() in {"true", "false"}:
80
- value_cast = value_raw.lower() == "true"
81
- else:
82
- value_cast = value_raw
83
- filters_dict[key] = value_cast
84
79
  return filters_dict
85
80
 
81
+ @staticmethod
82
+ def _process_value(value: str) -> Any:
83
+ if value.startswith("[") and value.endswith("]"):
84
+ content = value[1:-1]
85
+ if not content.strip():
86
+ return []
87
+ return [PaginateRequest._cast_primitive(item.strip()) for item in content.split(",")]
88
+
89
+ return PaginateRequest._cast_primitive(value)
90
+
91
+ @staticmethod
92
+ def _cast_primitive(value: str) -> Union[int, float, bool, str]:
93
+ clean_value = value.strip("'\"")
94
+ lower_value = clean_value.lower()
95
+
96
+ if lower_value == "true":
97
+ return True
98
+ if lower_value == "false":
99
+ return False
100
+
101
+ if clean_value.isdigit():
102
+ return int(clean_value)
103
+
104
+ try:
105
+ return float(clean_value)
106
+ except ValueError:
107
+ return clean_value
108
+
86
109
  def remove_deleted(self, deleted_at_field: str = "deleted_at"):
87
110
  self.filters = self.filters | {"deleted_at": None}
88
111
 
@@ -0,0 +1,13 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+
5
+ def load_json_file(file_path: str) -> dict:
6
+ path = Path(file_path)
7
+
8
+ if not path.exists():
9
+ raise FileNotFoundError(f"No file found at {file_path}")
10
+
11
+ with path.open(mode='r', encoding='utf-8') as file:
12
+ return json.load(file)
13
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nlbone
3
- Version: 0.8.2
3
+ Version: 0.8.4
4
4
  Summary: Backbone package for interfaces and infrastructure in Python projects
5
5
  Author-email: Amir Hosein Kahkbazzadeh <a.khakbazzadeh@gmail.com>
6
6
  License: MIT
@@ -75,7 +75,7 @@ nlbone/interfaces/api/exceptions.py,sha256=IggZxV9q6l4jqw-G7SWEmuyXnWgbNXJJT-rmn
75
75
  nlbone/interfaces/api/routers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  nlbone/interfaces/api/schemas.py,sha256=34Tz2EeXyf12rFL9iyYWaB2ftuaXUebQQQxSO9ouV94,133
77
77
  nlbone/interfaces/api/additional_filed/__init__.py,sha256=BWemliLSQV9iq1vdUaF733q0FOSipSWBOQk9eYj732Q,318
78
- nlbone/interfaces/api/additional_filed/assembler.py,sha256=80sFuNiquqdLPOcx7MoQ_ud9fAJtA327M77Z9V47pIU,1956
78
+ nlbone/interfaces/api/additional_filed/assembler.py,sha256=E_TGxorIQ-hC5FiCup5WQ0MmbSGfNaypEf5Plc-rjJs,1988
79
79
  nlbone/interfaces/api/additional_filed/field_registry.py,sha256=IhIvzHWOMtKv8iTdFu7LzQboi4SFTLOyJqKdYPY8xFE,5418
80
80
  nlbone/interfaces/api/additional_filed/resolver.py,sha256=jv1TIBBHN4LBIMwHGipcy4iq0uP0r6udyaqvhRzb8Bk,4655
81
81
  nlbone/interfaces/api/additional_filed/default_field_rules/__init__.py,sha256=LUSAOO3xRUt5ptlraIx7H-7dSkdr1D-WprmnqXRB16g,48
@@ -91,7 +91,7 @@ nlbone/interfaces/api/middleware/access_log.py,sha256=vIkxxxfy2HcjqqKb8XCfGCcSri
91
91
  nlbone/interfaces/api/middleware/add_request_context.py,sha256=o8mdo-D6fODM9OyHunE5UodkVxsh4F__5tDv8ju8Sxg,1952
92
92
  nlbone/interfaces/api/middleware/authentication.py,sha256=Bt6sYu4KtXAyUQnSIp-Z2Z1yKNNtfRy9Y3rOZcYTFhw,3299
93
93
  nlbone/interfaces/api/pagination/__init__.py,sha256=pA1uC4rK6eqDI5IkLVxmgO2B6lExnOm8Pje2-hifJZw,431
94
- nlbone/interfaces/api/pagination/offset_base.py,sha256=60X8a9uDOSd3qG45M49dqNG_FUjSxEDrgEyb9JD9V-o,4113
94
+ nlbone/interfaces/api/pagination/offset_base.py,sha256=pdfNgmP99eFC5qCWyY1JgW8hNhOuEGnmrlvQPGArdj8,4709
95
95
  nlbone/interfaces/api/schema/__init__.py,sha256=LAqgynfupeqOQ6u0I5ucrcYnojRMZUg9yW8IjKSQTNI,119
96
96
  nlbone/interfaces/api/schema/adaptive_schema.py,sha256=bdWBNpP2NfOJ_in4btXn0lrZOK70x-OqfmZ-NpIJdoQ,3347
97
97
  nlbone/interfaces/api/schema/base_response_model.py,sha256=EpbxolYLeWgtmXaMbYuL-9FcRQdDtT0d8n_8SOXcoyk,1062
@@ -113,10 +113,11 @@ nlbone/utils/flatten_dict.py,sha256=nkx8gAcJkjCKG3I5y9clqtjGMZCWyUWRhgD2R8zGEqM,
113
113
  nlbone/utils/flatten_sqlalchemy_result.py,sha256=JGwQEauoJVjhzvXrOtqabj3wQ7zp2-OPwhuh44sUdUE,625
114
114
  nlbone/utils/http.py,sha256=llb4aPDL-Uvrht3c_VwJdngdKeT4WsCu1pXSoeI7vWA,1114
115
115
  nlbone/utils/normalize_mobile.py,sha256=sGH4tV9gX-6eVKozviNWJhm1DN1J28Nj-ERldCYkS_E,732
116
+ nlbone/utils/read_files.py,sha256=mx8dfvtaaARQFRp_U7OOiERg-GT62h09_lpTzIQsVhs,291
116
117
  nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
117
118
  nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
118
- nlbone-0.8.2.dist-info/METADATA,sha256=U98QL0qunT7iz-N8KrbuowCD_QYC47K_YiYcPfH8IuY,2294
119
- nlbone-0.8.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
120
- nlbone-0.8.2.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
121
- nlbone-0.8.2.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
122
- nlbone-0.8.2.dist-info/RECORD,,
119
+ nlbone-0.8.4.dist-info/METADATA,sha256=MzTXTMT3XbPIK5o3RH0uy28AQpzn-vj1dXRbZBFqa4I,2294
120
+ nlbone-0.8.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
121
+ nlbone-0.8.4.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
122
+ nlbone-0.8.4.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
+ nlbone-0.8.4.dist-info/RECORD,,
File without changes