apexdevkit 1.16.3__tar.gz → 1.16.5__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.
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/PKG-INFO +1 -1
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/resource.py +9 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/router.py +27 -2
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/schema.py +26 -7
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/service.py +3 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/testing/rest.py +7 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/pyproject.toml +1 -1
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/LICENSE +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/README.md +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/environment.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/error.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/name.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/request.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/key_fn.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/decorator.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/mongo.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/mssql.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/server.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/synchronization.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.16.3 → apexdevkit-1.16.5}/apexdevkit/value.py +0 -0
|
@@ -49,6 +49,15 @@ class RestfulResource:
|
|
|
49
49
|
|
|
50
50
|
return endpoint
|
|
51
51
|
|
|
52
|
+
def read_many(self, Service, QueryParams) -> _Endpoint: # type: ignore
|
|
53
|
+
def endpoint(service: Service, params: QueryParams) -> _Response:
|
|
54
|
+
try:
|
|
55
|
+
return self.response.found_many(list(service.read_many(**dict(params))))
|
|
56
|
+
except ForbiddenError as e:
|
|
57
|
+
return JSONResponse(self.response.forbidden(e), 403)
|
|
58
|
+
|
|
59
|
+
return endpoint
|
|
60
|
+
|
|
52
61
|
def read_all(self, Service) -> _Endpoint: # type: ignore
|
|
53
62
|
def endpoint(service: Service) -> _Response:
|
|
54
63
|
try:
|
|
@@ -2,15 +2,16 @@ from dataclasses import dataclass, field
|
|
|
2
2
|
from functools import cached_property
|
|
3
3
|
from typing import Annotated, Any, Protocol, Self, TypeVar
|
|
4
4
|
|
|
5
|
-
from fastapi import APIRouter, Depends, Path
|
|
5
|
+
from fastapi import APIRouter, Depends, Path, Query
|
|
6
6
|
from fastapi.responses import JSONResponse
|
|
7
7
|
|
|
8
8
|
from apexdevkit.fastapi.builder import RestfulServiceBuilder
|
|
9
9
|
from apexdevkit.fastapi.name import RestfulName
|
|
10
10
|
from apexdevkit.fastapi.resource import RestfulResource
|
|
11
11
|
from apexdevkit.fastapi.response import RestfulResponse
|
|
12
|
-
from apexdevkit.fastapi.schema import RestfulSchema, SchemaFields
|
|
12
|
+
from apexdevkit.fastapi.schema import RestfulSchema, Schema, SchemaFields
|
|
13
13
|
from apexdevkit.fastapi.service import RawCollection, RawItem, RestfulService
|
|
14
|
+
from apexdevkit.fluent import FluentDict
|
|
14
15
|
|
|
15
16
|
_Response = JSONResponse | dict[str, Any]
|
|
16
17
|
|
|
@@ -135,6 +136,30 @@ class RestfulRouter:
|
|
|
135
136
|
|
|
136
137
|
return self
|
|
137
138
|
|
|
139
|
+
def with_read_many_endpoint(
|
|
140
|
+
self,
|
|
141
|
+
dependency: Dependency,
|
|
142
|
+
query: FluentDict[Any],
|
|
143
|
+
is_documented: bool = True,
|
|
144
|
+
) -> Self:
|
|
145
|
+
self.router.add_api_route(
|
|
146
|
+
"",
|
|
147
|
+
self.resource.read_many(
|
|
148
|
+
Service=dependency.as_dependable(),
|
|
149
|
+
QueryParams=Annotated[
|
|
150
|
+
Schema(self.name).optional_schema_for("ReadMany", query), Query()
|
|
151
|
+
],
|
|
152
|
+
),
|
|
153
|
+
methods=["GET"],
|
|
154
|
+
status_code=200,
|
|
155
|
+
responses={},
|
|
156
|
+
response_model=self.schema.for_collection(),
|
|
157
|
+
include_in_schema=is_documented,
|
|
158
|
+
summary="Read Many",
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
return self
|
|
162
|
+
|
|
138
163
|
def with_read_all_endpoint(
|
|
139
164
|
self,
|
|
140
165
|
dependency: Dependency,
|
|
@@ -46,13 +46,7 @@ class RestfulSchema:
|
|
|
46
46
|
|
|
47
47
|
def _schema_for(self, action: str, fields: dict[str, Any]) -> type[BaseModel]:
|
|
48
48
|
if action not in self.schemas:
|
|
49
|
-
self.schemas[action] =
|
|
50
|
-
self.name.singular.capitalize() + action,
|
|
51
|
-
**{
|
|
52
|
-
field_name: (field_type, ...)
|
|
53
|
-
for field_name, field_type in fields.items()
|
|
54
|
-
},
|
|
55
|
-
)
|
|
49
|
+
self.schemas[action] = Schema(self.name).schema_for(action, fields)
|
|
56
50
|
|
|
57
51
|
return self.schemas[action]
|
|
58
52
|
|
|
@@ -134,3 +128,28 @@ class RestfulSchema:
|
|
|
134
128
|
return [dict(item) for item in request.model_dump()[self.name.plural]]
|
|
135
129
|
|
|
136
130
|
return _
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@dataclass(frozen=True)
|
|
134
|
+
class Schema:
|
|
135
|
+
name: RestfulName
|
|
136
|
+
|
|
137
|
+
def schema_for(self, action: str, fields: dict[str, Any]) -> type[BaseModel]:
|
|
138
|
+
return create_model(
|
|
139
|
+
self.name.singular.capitalize() + action,
|
|
140
|
+
**{
|
|
141
|
+
field_name: (field_type, ...)
|
|
142
|
+
for field_name, field_type in fields.items()
|
|
143
|
+
},
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def optional_schema_for(
|
|
147
|
+
self, action: str, fields: dict[str, Any]
|
|
148
|
+
) -> type[BaseModel]:
|
|
149
|
+
return create_model(
|
|
150
|
+
self.name.singular.capitalize() + action,
|
|
151
|
+
**{
|
|
152
|
+
field_name: (field_type | None, None)
|
|
153
|
+
for field_name, field_type in fields.items()
|
|
154
|
+
},
|
|
155
|
+
)
|
|
@@ -30,6 +30,9 @@ class RestfulService(ABC): # pragma: no cover
|
|
|
30
30
|
def read_one(self, item_id: str) -> RawItem:
|
|
31
31
|
raise NotImplementedError(self.read_one.__name__)
|
|
32
32
|
|
|
33
|
+
def read_many(self, **params: Any) -> RawCollection:
|
|
34
|
+
raise NotImplementedError(self.read_many.__name__)
|
|
35
|
+
|
|
33
36
|
def read_all(self) -> RawCollection:
|
|
34
37
|
raise NotImplementedError(self.read_all.__name__)
|
|
35
38
|
|
|
@@ -42,6 +42,13 @@ class _RestResource:
|
|
|
42
42
|
),
|
|
43
43
|
)
|
|
44
44
|
|
|
45
|
+
def read_many(self, **params: Any) -> _TestRequest:
|
|
46
|
+
http = self.http.with_endpoint(self.name.plural)
|
|
47
|
+
for p, v in params.items():
|
|
48
|
+
http = http.with_param(p, v)
|
|
49
|
+
|
|
50
|
+
return _TestRequest(self.name, HttpRequest(HttpMethod.get, http))
|
|
51
|
+
|
|
45
52
|
def read_all(self) -> _TestRequest:
|
|
46
53
|
return _TestRequest(
|
|
47
54
|
self.name,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|