apexdevkit 1.8.9__tar.gz → 1.9.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.
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/PKG-INFO +1 -1
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/service.py +3 -3
- apexdevkit-1.9.1/apexdevkit/formatter.py +50 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/in_memory.py +3 -2
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/pyproject.toml +1 -1
- apexdevkit-1.8.9/apexdevkit/formatter.py +0 -38
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/LICENSE +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/README.md +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/error.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.8.9 → apexdevkit-1.9.1}/apexdevkit/testing/rest.py +0 -0
|
@@ -51,10 +51,10 @@ ItemT = TypeVar("ItemT")
|
|
|
51
51
|
|
|
52
52
|
@dataclass
|
|
53
53
|
class RestfulRepositoryBuilder(Generic[ItemT]):
|
|
54
|
-
formatter: Formatter[ItemT] = field(init=False)
|
|
54
|
+
formatter: Formatter[dict[str, Any], ItemT] = field(init=False)
|
|
55
55
|
repository: Repository[Any, ItemT] = field(init=False)
|
|
56
56
|
|
|
57
|
-
def with_formatter(self, formatter: Formatter[ItemT]) -> Self:
|
|
57
|
+
def with_formatter(self, formatter: Formatter[dict[str, Any], ItemT]) -> Self:
|
|
58
58
|
self.formatter = formatter
|
|
59
59
|
|
|
60
60
|
return self
|
|
@@ -70,7 +70,7 @@ class RestfulRepositoryBuilder(Generic[ItemT]):
|
|
|
70
70
|
|
|
71
71
|
@dataclass
|
|
72
72
|
class _RestfulRepository(RestfulService, Generic[ItemT]):
|
|
73
|
-
formatter: Formatter[ItemT]
|
|
73
|
+
formatter: Formatter[dict[str, Any], ItemT]
|
|
74
74
|
repository: Repository[Any, ItemT]
|
|
75
75
|
|
|
76
76
|
def create_one(self, item: RawItem) -> RawItem:
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from dataclasses import asdict, dataclass, field
|
|
3
|
+
from typing import Any, Generic, Protocol, Self, TypeVar
|
|
4
|
+
|
|
5
|
+
_SourceT = TypeVar("_SourceT")
|
|
6
|
+
_TargetT = TypeVar("_TargetT")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Formatter(Protocol[_SourceT, _TargetT]): # pragma: no cover
|
|
10
|
+
def load(self, source: _SourceT) -> _TargetT:
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
def dump(self, target: _TargetT) -> _SourceT:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ListFormatter(Generic[_SourceT, _TargetT]):
|
|
19
|
+
inner: Formatter[_SourceT, _TargetT]
|
|
20
|
+
|
|
21
|
+
def load(self, source: list[_SourceT]) -> list[_TargetT]:
|
|
22
|
+
return [self.inner.load(item) for item in source]
|
|
23
|
+
|
|
24
|
+
def dump(self, target: list[_TargetT]) -> list[_SourceT]:
|
|
25
|
+
return [self.inner.dump(item) for item in target]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class DataclassFormatter(Generic[_TargetT]):
|
|
30
|
+
resource: type[_TargetT]
|
|
31
|
+
sub_formatters: dict[str, Formatter[Any, Any]] = field(default_factory=dict)
|
|
32
|
+
|
|
33
|
+
def and_nested(self, **formatters: Formatter[Any, Any]) -> Self:
|
|
34
|
+
return self.with_nested(**formatters)
|
|
35
|
+
|
|
36
|
+
def with_nested(self, **formatters: Formatter[Any, Any]) -> Self:
|
|
37
|
+
self.sub_formatters.update(formatters)
|
|
38
|
+
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def load(self, raw: dict[str, Any]) -> _TargetT:
|
|
42
|
+
raw = deepcopy(raw)
|
|
43
|
+
|
|
44
|
+
for key, formatter in self.sub_formatters.items():
|
|
45
|
+
raw[key] = formatter.load(raw.pop(key))
|
|
46
|
+
|
|
47
|
+
return self.resource(**raw)
|
|
48
|
+
|
|
49
|
+
def dump(self, item: _TargetT) -> dict[str, Any]:
|
|
50
|
+
return asdict(item) # type: ignore
|
|
@@ -13,12 +13,13 @@ class _Item(Protocol): # pragma: no cover
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
ItemT = TypeVar("ItemT", bound=_Item)
|
|
16
|
+
_Raw = dict[str, Any]
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
@dataclass
|
|
19
20
|
class InMemoryRepository(Generic[ItemT]):
|
|
20
|
-
formatter: Formatter[ItemT]
|
|
21
|
-
items: dict[str,
|
|
21
|
+
formatter: Formatter[_Raw, ItemT]
|
|
22
|
+
items: dict[str, _Raw] = field(default_factory=dict)
|
|
22
23
|
|
|
23
24
|
_uniques: list[Criteria] = field(init=False, default_factory=list)
|
|
24
25
|
_search_by: list[str] = field(init=False, default_factory=list)
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from copy import deepcopy
|
|
2
|
-
from dataclasses import asdict, dataclass, field
|
|
3
|
-
from typing import Any, Generic, Protocol, Self, TypeVar
|
|
4
|
-
|
|
5
|
-
ItemT = TypeVar("ItemT")
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Formatter(Protocol[ItemT]): # pragma: no cover
|
|
9
|
-
def load(self, raw: dict[str, Any]) -> ItemT:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
def dump(self, item: ItemT) -> dict[str, Any]:
|
|
13
|
-
pass
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dataclass
|
|
17
|
-
class DataclassFormatter(Generic[ItemT]):
|
|
18
|
-
resource: type[ItemT]
|
|
19
|
-
sub_formatters: dict[str, Formatter[Any]] = field(default_factory=dict)
|
|
20
|
-
|
|
21
|
-
def and_nested(self, **formatters: Formatter[Any]) -> Self:
|
|
22
|
-
return self.with_nested(**formatters)
|
|
23
|
-
|
|
24
|
-
def with_nested(self, **formatters: Formatter[Any]) -> Self:
|
|
25
|
-
self.sub_formatters.update(formatters)
|
|
26
|
-
|
|
27
|
-
return self
|
|
28
|
-
|
|
29
|
-
def load(self, raw: dict[str, Any]) -> ItemT:
|
|
30
|
-
raw = deepcopy(raw)
|
|
31
|
-
|
|
32
|
-
for key, formatter in self.sub_formatters.items():
|
|
33
|
-
raw[key] = formatter.load(raw.pop(key))
|
|
34
|
-
|
|
35
|
-
return self.resource(**raw)
|
|
36
|
-
|
|
37
|
-
def dump(self, item: ItemT) -> dict[str, Any]:
|
|
38
|
-
return asdict(item) # type: ignore
|
|
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
|