apexdevkit 1.9.5__tar.gz → 1.9.6__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.9.5 → apexdevkit-1.9.6}/PKG-INFO +1 -1
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/schema.py +13 -28
- apexdevkit-1.9.6/apexdevkit/fluent.py +40 -0
- apexdevkit-1.9.6/apexdevkit/http/json.py +5 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/testing/rest.py +2 -16
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/pyproject.toml +1 -1
- apexdevkit-1.9.5/apexdevkit/http/json.py +0 -38
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/LICENSE +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/README.md +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/error.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/mongo.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.9.5 → apexdevkit-1.9.6}/apexdevkit/testing/fake.py +0 -0
|
@@ -5,22 +5,22 @@ from typing import Any, Callable, Iterable, List
|
|
|
5
5
|
|
|
6
6
|
from pydantic import BaseModel, create_model
|
|
7
7
|
|
|
8
|
-
from apexdevkit.
|
|
8
|
+
from apexdevkit.fluent import FluentDict
|
|
9
9
|
from apexdevkit.testing import RestfulName
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class SchemaFields(ABC):
|
|
13
|
-
def id(self) ->
|
|
13
|
+
def id(self) -> FluentDict[type]:
|
|
14
14
|
return self.readable().select("id")
|
|
15
15
|
|
|
16
|
-
def writable(self) ->
|
|
16
|
+
def writable(self) -> FluentDict[type]:
|
|
17
17
|
return self.readable().drop("id")
|
|
18
18
|
|
|
19
|
-
def editable(self) ->
|
|
19
|
+
def editable(self) -> FluentDict[type]:
|
|
20
20
|
return self.readable().drop("id")
|
|
21
21
|
|
|
22
22
|
@abstractmethod
|
|
23
|
-
def readable(self) ->
|
|
23
|
+
def readable(self) -> FluentDict[type]: # pragma: no cover
|
|
24
24
|
pass
|
|
25
25
|
|
|
26
26
|
|
|
@@ -38,26 +38,11 @@ class RestfulSchema:
|
|
|
38
38
|
"UpdateManyItem", self.fields.editable().merge(self.fields.id())
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
-
self._schema_for(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
self._schema_for(
|
|
46
|
-
"Collection",
|
|
47
|
-
JsonDict({self.name.plural: List[schema]}).with_a(count=int),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
self._schema_for(
|
|
51
|
-
"CreateMany",
|
|
52
|
-
JsonDict({self.name.plural: List[create_schema]}),
|
|
53
|
-
)
|
|
54
|
-
self._schema_for(
|
|
55
|
-
"UpdateMany",
|
|
56
|
-
JsonDict({self.name.plural: List[update_many_item]}),
|
|
57
|
-
)
|
|
58
|
-
self._schema_for(
|
|
59
|
-
"ReplaceMany", JsonDict({self.name.plural: List[replace_schema]})
|
|
60
|
-
)
|
|
41
|
+
self._schema_for("Item", {self.name.singular: schema})
|
|
42
|
+
self._schema_for("Collection", {self.name.plural: List[schema], "count": int})
|
|
43
|
+
self._schema_for("CreateMany", {self.name.plural: List[create_schema]})
|
|
44
|
+
self._schema_for("UpdateMany", {self.name.plural: List[update_many_item]})
|
|
45
|
+
self._schema_for("ReplaceMany", {self.name.plural: List[replace_schema]})
|
|
61
46
|
|
|
62
47
|
def _schema_for(self, action: str, fields: dict[str, Any]) -> type[BaseModel]:
|
|
63
48
|
if action not in self.schemas:
|
|
@@ -81,13 +66,13 @@ class RestfulSchema:
|
|
|
81
66
|
|
|
82
67
|
return self._schema_for(
|
|
83
68
|
"NoDataResponse",
|
|
84
|
-
|
|
69
|
+
FluentDict[type]().with_a(status=str).and_a(code=int).and_a(data=NoData),
|
|
85
70
|
)
|
|
86
71
|
|
|
87
72
|
def for_item(self) -> type[BaseModel]:
|
|
88
73
|
return self._schema_for(
|
|
89
74
|
"ItemResponse",
|
|
90
|
-
|
|
75
|
+
FluentDict[type]()
|
|
91
76
|
.with_a(status=str)
|
|
92
77
|
.and_a(code=int)
|
|
93
78
|
.and_a(data=self.schemas["Item"]),
|
|
@@ -96,7 +81,7 @@ class RestfulSchema:
|
|
|
96
81
|
def for_collection(self) -> type[BaseModel]:
|
|
97
82
|
return self._schema_for(
|
|
98
83
|
"CollectionResponse",
|
|
99
|
-
|
|
84
|
+
FluentDict[type]()
|
|
100
85
|
.with_a(status=str)
|
|
101
86
|
.and_a(code=int)
|
|
102
87
|
.and_a(data=self.schemas["Collection"]),
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Callable, Generic, TypeVar
|
|
5
|
+
|
|
6
|
+
ItemT = TypeVar("ItemT")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FluentDict(dict[str, ItemT]):
|
|
10
|
+
def value_of(self, key: str) -> FluentElement[ItemT]:
|
|
11
|
+
return FluentElement(self[key])
|
|
12
|
+
|
|
13
|
+
def and_a(self, **fields: ItemT) -> FluentDict[ItemT]:
|
|
14
|
+
return self.with_a(**fields)
|
|
15
|
+
|
|
16
|
+
def with_a(self, **fields: ItemT) -> FluentDict[ItemT]:
|
|
17
|
+
return self.merge(FluentDict[ItemT](fields))
|
|
18
|
+
|
|
19
|
+
def merge(self, other: FluentDict[ItemT]) -> FluentDict[ItemT]:
|
|
20
|
+
return FluentDict[ItemT]({**self, **other})
|
|
21
|
+
|
|
22
|
+
def drop(self, *keys: str) -> FluentDict[ItemT]:
|
|
23
|
+
return self.select(*set(self.keys()).difference(keys))
|
|
24
|
+
|
|
25
|
+
def select(self, *keys: str) -> FluentDict[ItemT]:
|
|
26
|
+
return FluentDict[ItemT]({k: v for k, v in self.items() if k in keys})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class FluentElement(Generic[ItemT]):
|
|
31
|
+
value: ItemT
|
|
32
|
+
|
|
33
|
+
def to(self, a_type: Callable[[ItemT], ConvertedT]) -> ConvertedT:
|
|
34
|
+
return a_type(self.value)
|
|
35
|
+
|
|
36
|
+
def __str__(self) -> str:
|
|
37
|
+
return str(self.value)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
ConvertedT = TypeVar("ConvertedT")
|
|
@@ -260,27 +260,13 @@ class RestResponse:
|
|
|
260
260
|
return self.with_item(value)
|
|
261
261
|
|
|
262
262
|
def with_item(self, value: Any) -> Self:
|
|
263
|
-
return self.with_data(
|
|
264
|
-
**{
|
|
265
|
-
self.resource.singular: dict(value)
|
|
266
|
-
if isinstance(value, JsonDict)
|
|
267
|
-
else value
|
|
268
|
-
}
|
|
269
|
-
)
|
|
263
|
+
return self.with_data(**{self.resource.singular: value})
|
|
270
264
|
|
|
271
265
|
def and_collection(self, value: list[Any]) -> Self:
|
|
272
266
|
return self.with_collection(value)
|
|
273
267
|
|
|
274
268
|
def with_collection(self, values: list[Any]) -> Self:
|
|
275
|
-
return self.with_data(
|
|
276
|
-
**{
|
|
277
|
-
self.resource.plural: [
|
|
278
|
-
dict(value) if isinstance(value, JsonDict) else value
|
|
279
|
-
for value in values
|
|
280
|
-
],
|
|
281
|
-
},
|
|
282
|
-
count=len(values),
|
|
283
|
-
)
|
|
269
|
+
return self.with_data(**{self.resource.plural: values}, count=len(values))
|
|
284
270
|
|
|
285
271
|
def and_no_data(self) -> Self:
|
|
286
272
|
return self.no_data()
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, Callable, TypeVar
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class JsonDict(dict[str, Any]):
|
|
8
|
-
def value_of(self, key: str) -> FluentElement:
|
|
9
|
-
return FluentElement(self[key])
|
|
10
|
-
|
|
11
|
-
def and_a(self, **fields: Any) -> JsonDict:
|
|
12
|
-
return self.with_a(**fields)
|
|
13
|
-
|
|
14
|
-
def with_a(self, **fields: Any) -> JsonDict:
|
|
15
|
-
return self.merge(JsonDict(fields))
|
|
16
|
-
|
|
17
|
-
def merge(self, other: JsonDict) -> JsonDict:
|
|
18
|
-
return JsonDict({**self, **other})
|
|
19
|
-
|
|
20
|
-
def drop(self, *keys: str) -> JsonDict:
|
|
21
|
-
return self.select(*set(self.keys()).difference(keys))
|
|
22
|
-
|
|
23
|
-
def select(self, *keys: str) -> JsonDict:
|
|
24
|
-
return JsonDict({k: v for k, v in self.items() if k in keys})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass
|
|
28
|
-
class FluentElement:
|
|
29
|
-
value: Any
|
|
30
|
-
|
|
31
|
-
def to(self, a_type: Callable[[Any], ConvertedT]) -> ConvertedT:
|
|
32
|
-
return a_type(self.value)
|
|
33
|
-
|
|
34
|
-
def __str__(self) -> str:
|
|
35
|
-
return str(self.value)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ConvertedT = TypeVar("ConvertedT")
|
|
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
|