apexdevkit 1.6.5__tar.gz → 1.7.1__tar.gz

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.
Files changed (35) hide show
  1. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/PKG-INFO +1 -1
  2. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/resource.py +11 -16
  3. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/response.py +30 -91
  4. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/router.py +45 -28
  5. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/pyproject.toml +5 -2
  6. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/LICENSE +0 -0
  7. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/README.md +0 -0
  8. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/__init__.py +0 -0
  9. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/annotation/__init__.py +0 -0
  10. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/annotation/deprecate.py +0 -0
  11. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/error.py +0 -0
  12. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/__init__.py +0 -0
  13. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/builder.py +0 -0
  14. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/dependable.py +0 -0
  15. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/docs.py +0 -0
  16. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/schema.py +0 -0
  17. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/fastapi/service.py +0 -0
  18. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/formatter.py +0 -0
  19. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/__init__.py +0 -0
  20. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/fake.py +0 -0
  21. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/fluent.py +0 -0
  22. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/httpx.py +0 -0
  23. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/json.py +0 -0
  24. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/http/url.py +0 -0
  25. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/py.typed +0 -0
  26. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/__init__.py +0 -0
  27. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/base.py +0 -0
  28. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/connector.py +0 -0
  29. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/database.py +0 -0
  30. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/in_memory.py +0 -0
  31. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/repository/interface.py +0 -0
  32. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/testing/__init__.py +0 -0
  33. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/testing/database.py +0 -0
  34. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/testing/fake.py +0 -0
  35. {apexdevkit-1.6.5 → apexdevkit-1.7.1}/apexdevkit/testing/rest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.6.5
3
+ Version: 1.7.1
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -1,25 +1,20 @@
1
1
  from dataclasses import dataclass
2
- from functools import cached_property
3
2
  from typing import Any, Callable
4
3
 
5
4
  from starlette.responses import JSONResponse
6
5
 
7
6
  from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
8
7
  from apexdevkit.fastapi.response import RestfulResponse
9
- from apexdevkit.testing import RestfulName
10
8
 
11
9
  _Response = JSONResponse | dict[str, Any]
10
+ _Endpoint = Callable[..., _Response]
12
11
 
13
12
 
14
13
  @dataclass
15
14
  class RestfulResource:
16
- name: RestfulName
15
+ response: RestfulResponse
17
16
 
18
- @cached_property
19
- def response(self) -> RestfulResponse:
20
- return RestfulResponse(name=self.name)
21
-
22
- def create_one(self, Service, Item) -> Callable[..., _Response]: # type: ignore
17
+ def create_one(self, Service, Item) -> _Endpoint: # type: ignore
23
18
  def endpoint(service: Service, item: Item) -> _Response:
24
19
  try:
25
20
  item = service.create_one(item)
@@ -32,7 +27,7 @@ class RestfulResource:
32
27
 
33
28
  return endpoint
34
29
 
35
- def create_many(self, Service, Collection) -> Callable[..., _Response]: # type: ignore
30
+ def create_many(self, Service, Collection) -> _Endpoint: # type: ignore
36
31
  def endpoint(service: Service, items: Collection) -> _Response:
37
32
  try:
38
33
  return self.response.created_many(service.create_many(items))
@@ -43,7 +38,7 @@ class RestfulResource:
43
38
 
44
39
  return endpoint
45
40
 
46
- def read_one(self, Service, ItemId) -> Callable[..., _Response]: # type: ignore
41
+ def read_one(self, Service, ItemId) -> _Endpoint: # type: ignore
47
42
  def endpoint(service: Service, item_id: ItemId) -> _Response:
48
43
  try:
49
44
  return self.response.found_one(service.read_one(item_id))
@@ -54,7 +49,7 @@ class RestfulResource:
54
49
 
55
50
  return endpoint
56
51
 
57
- def read_all(self, Service) -> Callable[..., _Response]: # type: ignore
52
+ def read_all(self, Service) -> _Endpoint: # type: ignore
58
53
  def endpoint(service: Service) -> _Response:
59
54
  try:
60
55
  return self.response.found_many(list(service.read_all()))
@@ -63,7 +58,7 @@ class RestfulResource:
63
58
 
64
59
  return endpoint
65
60
 
66
- def update_one(self, Service, ItemId, Updates) -> Callable[..., _Response]: # type: ignore
61
+ def update_one(self, Service, ItemId, Updates) -> _Endpoint: # type: ignore
67
62
  def endpoint(service: Service, item_id: ItemId, updates: Updates) -> _Response:
68
63
  try:
69
64
  service.update_one(item_id, **updates)
@@ -76,7 +71,7 @@ class RestfulResource:
76
71
 
77
72
  return endpoint
78
73
 
79
- def update_many(self, Service, Collection) -> Callable[..., _Response]: # type: ignore
74
+ def update_many(self, Service, Collection) -> _Endpoint: # type: ignore
80
75
  def endpoint(service: Service, items: Collection) -> _Response:
81
76
  try:
82
77
  service.update_many(items)
@@ -89,7 +84,7 @@ class RestfulResource:
89
84
 
90
85
  return endpoint
91
86
 
92
- def replace_one(self, Service, Item) -> Callable[..., _Response]: # type: ignore
87
+ def replace_one(self, Service, Item) -> _Endpoint: # type: ignore
93
88
  def endpoint(service: Service, item: Item) -> _Response:
94
89
  try:
95
90
  service.replace_one(item)
@@ -102,7 +97,7 @@ class RestfulResource:
102
97
 
103
98
  return endpoint
104
99
 
105
- def replace_many(self, Service, Collection) -> Callable[..., _Response]: # type: ignore
100
+ def replace_many(self, Service, Collection) -> _Endpoint: # type: ignore
106
101
  def endpoint(service: Service, items: Collection) -> _Response:
107
102
  try:
108
103
  service.replace_many(items)
@@ -115,7 +110,7 @@ class RestfulResource:
115
110
 
116
111
  return endpoint
117
112
 
118
- def delete_one(self, Service, ItemId) -> Callable[..., _Response]: # type: ignore
113
+ def delete_one(self, Service, ItemId) -> _Endpoint: # type: ignore
119
114
  def endpoint(service: Service, item_id: ItemId) -> _Response:
120
115
  try:
121
116
  service.delete_one(item_id)
@@ -3,94 +3,35 @@ from __future__ import annotations
3
3
  from dataclasses import dataclass
4
4
  from typing import Any, Iterable
5
5
 
6
- from fastapi import status
7
- from fastapi.responses import JSONResponse
8
-
9
6
  from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
10
7
  from apexdevkit.testing import RestfulName
11
8
 
12
9
 
13
- class SuccessResponse(dict[str, Any]):
14
- def __init__(self, status_code: int, **kwargs: Any):
15
- super().__init__(
16
- {
17
- "status": "success",
18
- "code": status_code,
19
- "data": {**kwargs},
20
- }
21
- )
22
-
23
-
24
- class ResourceFound(SuccessResponse):
25
- def __init__(self, **kwargs: Any):
26
- super().__init__(status_code=status.HTTP_200_OK, **kwargs)
27
-
28
-
29
- class ResourceCreated(SuccessResponse):
30
- def __init__(self, **kwargs: Any):
31
- super().__init__(status_code=status.HTTP_201_CREATED, **kwargs)
32
-
33
-
34
- class ErrorResponse(JSONResponse):
35
- def __init__(self, status_code: int, message: str, **kwargs: Any):
36
- content = {
37
- "status": "fail",
38
- "code": status_code,
39
- "error": {"message": message},
40
- }
41
-
42
- if kwargs:
43
- content["data"] = {**kwargs}
44
-
45
- super().__init__(status_code=status_code, content=content)
46
-
47
-
48
- class BadRequest(ErrorResponse):
49
- def __init__(self, message: str, **kwargs: Any) -> None:
50
- super().__init__(
51
- status_code=status.HTTP_400_BAD_REQUEST,
52
- message=message,
53
- **kwargs,
54
- )
55
-
56
-
57
- class ResourceNotFound(ErrorResponse):
58
- def __init__(self, message: str):
59
- super().__init__(status_code=status.HTTP_404_NOT_FOUND, message=message)
60
-
61
-
62
- class ResourceExists(ErrorResponse):
63
- def __init__(self, message: str, **kwargs: Any):
64
- super().__init__(
65
- status_code=status.HTTP_409_CONFLICT,
66
- message=message,
67
- **kwargs,
68
- )
69
-
70
-
71
10
  @dataclass
72
11
  class RestfulResponse:
73
12
  name: RestfulName
74
13
 
75
- def _response(self, code: int, data: Any, error: str = "") -> dict[str, Any]:
76
- content: dict[str, Any] = {"code": code, "status": "success"}
14
+ def ok(self) -> dict[str, Any]:
15
+ return self._response(200, data=None)
77
16
 
78
- if error:
79
- content["status"] = "fail"
80
- content["error"] = {"message": error}
17
+ def found_one(self, item: Any) -> dict[str, Any]:
18
+ return self._response(200, item)
81
19
 
82
- match data:
83
- case None:
84
- content["data"] = {}
85
- case list():
86
- content["data"] = {self.name.plural: data, "count": len(data)}
87
- case _:
88
- content["data"] = {self.name.singular: data}
20
+ def found_many(self, items: list[Any]) -> dict[str, Any]:
21
+ return self._response(200, items)
89
22
 
90
- return content
23
+ def created_one(self, item: Any) -> dict[str, Any]:
24
+ return self._response(201, item)
91
25
 
92
- def ok(self) -> dict[str, Any]:
93
- return self._response(200, data=None)
26
+ def created_many(self, items: Iterable[Any]) -> dict[str, Any]:
27
+ return self._response(201, list(items))
28
+
29
+ def forbidden(self, e: ForbiddenError) -> dict[str, Any]:
30
+ return self._response(
31
+ 403,
32
+ data={"id": str(e.id)},
33
+ error=e.message,
34
+ )
94
35
 
95
36
  def not_found(self, e: DoesNotExistError) -> dict[str, Any]:
96
37
  name = self.name.singular.capitalize()
@@ -110,21 +51,19 @@ class RestfulResponse:
110
51
  error=f"An item<{name}> with the {e} already exists.",
111
52
  )
112
53
 
113
- def forbidden(self, e: ForbiddenError) -> dict[str, Any]:
114
- return self._response(
115
- 403,
116
- data={"id": str(e.id)},
117
- error=e.message,
118
- )
119
-
120
- def created_one(self, item: Any) -> dict[str, Any]:
121
- return self._response(201, item)
54
+ def _response(self, code: int, data: Any, error: str = "") -> dict[str, Any]:
55
+ content: dict[str, Any] = {"code": code, "status": "success"}
122
56
 
123
- def created_many(self, items: Iterable[Any]) -> dict[str, Any]:
124
- return self._response(201, list(items))
57
+ if error:
58
+ content["status"] = "fail"
59
+ content["error"] = {"message": error}
125
60
 
126
- def found_one(self, item: Any) -> dict[str, Any]:
127
- return self._response(200, item)
61
+ match data:
62
+ case None:
63
+ content["data"] = {}
64
+ case list():
65
+ content["data"] = {self.name.plural: data, "count": len(data)}
66
+ case _:
67
+ content["data"] = {self.name.singular: data}
128
68
 
129
- def found_many(self, items: list[Any]) -> dict[str, Any]:
130
- return self._response(200, items)
69
+ return content
@@ -7,6 +7,7 @@ from fastapi.responses import JSONResponse
7
7
 
8
8
  from apexdevkit.fastapi.builder import RestfulServiceBuilder
9
9
  from apexdevkit.fastapi.resource import RestfulResource
10
+ from apexdevkit.fastapi.response import RestfulResponse
10
11
  from apexdevkit.fastapi.schema import RestfulSchema, SchemaFields
11
12
  from apexdevkit.fastapi.service import RawCollection, RawItem, RestfulService
12
13
  from apexdevkit.testing import RestfulName
@@ -16,7 +17,7 @@ _Response = JSONResponse | dict[str, Any]
16
17
  T = TypeVar("T")
17
18
 
18
19
 
19
- class Dependable(Protocol):
20
+ class Dependency(Protocol): # pragma: no cover
20
21
  def as_dependable(self) -> type[RestfulService]:
21
22
  pass
22
23
 
@@ -42,7 +43,7 @@ class RestfulRouter:
42
43
 
43
44
  @property
44
45
  def resource(self) -> RestfulResource:
45
- return RestfulResource(self.name)
46
+ return RestfulResource(RestfulResponse(self.name))
46
47
 
47
48
  @property
48
49
  def id_alias(self) -> str:
@@ -64,13 +65,13 @@ class RestfulRouter:
64
65
 
65
66
  def with_create_one_endpoint(
66
67
  self,
67
- dependable: Dependable,
68
+ dependency: Dependency,
68
69
  is_documented: bool = True,
69
70
  ) -> Self:
70
71
  self.router.add_api_route(
71
72
  "",
72
73
  self.resource.create_one(
73
- Service=dependable.as_dependable(),
74
+ Service=dependency.as_dependable(),
74
75
  Item=Annotated[
75
76
  RawItem,
76
77
  Depends(self.schema.for_create_one()),
@@ -87,12 +88,14 @@ class RestfulRouter:
87
88
  return self
88
89
 
89
90
  def with_create_many_endpoint(
90
- self, dependable: Dependable, is_documented: bool = True
91
+ self,
92
+ dependency: Dependency,
93
+ is_documented: bool = True,
91
94
  ) -> Self:
92
95
  self.router.add_api_route(
93
96
  "/batch",
94
97
  self.resource.create_many(
95
- Service=dependable.as_dependable(),
98
+ Service=dependency.as_dependable(),
96
99
  Collection=Annotated[
97
100
  RawCollection,
98
101
  Depends(self.schema.for_create_many()),
@@ -109,12 +112,14 @@ class RestfulRouter:
109
112
  return self
110
113
 
111
114
  def with_read_one_endpoint(
112
- self, dependable: Dependable, is_documented: bool = True
115
+ self,
116
+ dependency: Dependency,
117
+ is_documented: bool = True,
113
118
  ) -> Self:
114
119
  self.router.add_api_route(
115
120
  self.item_path,
116
121
  self.resource.read_one(
117
- Service=dependable.as_dependable(),
122
+ Service=dependency.as_dependable(),
118
123
  ItemId=Annotated[
119
124
  str,
120
125
  Path(alias=self.id_alias),
@@ -131,12 +136,14 @@ class RestfulRouter:
131
136
  return self
132
137
 
133
138
  def with_read_all_endpoint(
134
- self, dependable: Dependable, is_documented: bool = True
139
+ self,
140
+ dependency: Dependency,
141
+ is_documented: bool = True,
135
142
  ) -> Self:
136
143
  self.router.add_api_route(
137
144
  "",
138
145
  self.resource.read_all(
139
- Service=dependable.as_dependable(),
146
+ Service=dependency.as_dependable(),
140
147
  ),
141
148
  methods=["GET"],
142
149
  status_code=200,
@@ -149,12 +156,14 @@ class RestfulRouter:
149
156
  return self
150
157
 
151
158
  def with_update_one_endpoint(
152
- self, dependable: Dependable, is_documented: bool = True
159
+ self,
160
+ dependency: Dependency,
161
+ is_documented: bool = True,
153
162
  ) -> Self:
154
163
  self.router.add_api_route(
155
164
  self.item_path,
156
165
  self.resource.update_one(
157
- Service=dependable.as_dependable(),
166
+ Service=dependency.as_dependable(),
158
167
  ItemId=Annotated[
159
168
  str,
160
169
  Path(alias=self.id_alias),
@@ -175,12 +184,14 @@ class RestfulRouter:
175
184
  return self
176
185
 
177
186
  def with_update_many_endpoint(
178
- self, dependable: Dependable, is_documented: bool = True
187
+ self,
188
+ dependency: Dependency,
189
+ is_documented: bool = True,
179
190
  ) -> Self:
180
191
  self.router.add_api_route(
181
192
  "",
182
193
  self.resource.update_many(
183
- Service=dependable.as_dependable(),
194
+ Service=dependency.as_dependable(),
184
195
  Collection=Annotated[
185
196
  RawCollection,
186
197
  Depends(self.schema.for_update_many()),
@@ -197,12 +208,14 @@ class RestfulRouter:
197
208
  return self
198
209
 
199
210
  def with_replace_one_endpoint(
200
- self, dependable: Dependable, is_documented: bool = True
211
+ self,
212
+ dependency: Dependency,
213
+ is_documented: bool = True,
201
214
  ) -> Self:
202
215
  self.router.add_api_route(
203
216
  "",
204
217
  self.resource.replace_one(
205
- Service=dependable.as_dependable(),
218
+ Service=dependency.as_dependable(),
206
219
  Item=Annotated[
207
220
  RawItem,
208
221
  Depends(self.schema.for_replace_one()),
@@ -219,12 +232,14 @@ class RestfulRouter:
219
232
  return self
220
233
 
221
234
  def with_replace_many_endpoint(
222
- self, dependable: Dependable, is_documented: bool = True
235
+ self,
236
+ dependency: Dependency,
237
+ is_documented: bool = True,
223
238
  ) -> Self:
224
239
  self.router.add_api_route(
225
240
  "/batch",
226
241
  self.resource.replace_many(
227
- Service=dependable.as_dependable(),
242
+ Service=dependency.as_dependable(),
228
243
  Collection=Annotated[
229
244
  RawCollection,
230
245
  Depends(self.schema.for_replace_many()),
@@ -241,12 +256,14 @@ class RestfulRouter:
241
256
  return self
242
257
 
243
258
  def with_delete_one_endpoint(
244
- self, dependable: Dependable, is_documented: bool = True
259
+ self,
260
+ dependency: Dependency,
261
+ is_documented: bool = True,
245
262
  ) -> Self:
246
263
  self.router.add_api_route(
247
264
  self.item_path,
248
265
  self.resource.delete_one(
249
- Service=dependable.as_dependable(),
266
+ Service=dependency.as_dependable(),
250
267
  ItemId=Annotated[
251
268
  str,
252
269
  Path(alias=self.id_alias),
@@ -269,15 +286,15 @@ class RestfulRouter:
269
286
 
270
287
  return self
271
288
 
272
- def default(self, dependable: Dependable) -> Self:
289
+ def default(self, dependency: Dependency) -> Self:
273
290
  return (
274
- self.with_create_one_endpoint(dependable)
275
- .with_create_many_endpoint(dependable)
276
- .with_read_one_endpoint(dependable)
277
- .with_read_all_endpoint(dependable)
278
- .with_update_one_endpoint(dependable)
279
- .with_update_many_endpoint(dependable)
280
- .with_delete_one_endpoint(dependable)
291
+ self.with_create_one_endpoint(dependency)
292
+ .with_create_many_endpoint(dependency)
293
+ .with_read_one_endpoint(dependency)
294
+ .with_read_all_endpoint(dependency)
295
+ .with_update_one_endpoint(dependency)
296
+ .with_update_many_endpoint(dependency)
297
+ .with_delete_one_endpoint(dependency)
281
298
  )
282
299
 
283
300
  def build(self) -> APIRouter:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.6.5"
3
+ version = "1.7.1"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
@@ -25,7 +25,10 @@ ruff = "*"
25
25
  python_version = "3.11"
26
26
  ignore_missing_imports = true
27
27
  strict = true
28
- exclude = ["apexdevkit/fastapi/schema.py", "apexdevkit/fastapi/dependable.py"]
28
+ exclude = [
29
+ "apexdevkit/fastapi/schema.py",
30
+ "apexdevkit/fastapi/dependable.py",
31
+ ]
29
32
 
30
33
  [tool.ruff]
31
34
  target-version = "py311"
File without changes
File without changes