apexdevkit 1.5.8__tar.gz → 1.5.9__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.5.8 → apexdevkit-1.5.9}/PKG-INFO +1 -1
- apexdevkit-1.5.9/apexdevkit/fastapi/service.py +154 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/pyproject.toml +1 -1
- apexdevkit-1.5.8/apexdevkit/fastapi/service.py +0 -80
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/LICENSE +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/README.md +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/error.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.5.8 → apexdevkit-1.5.9}/apexdevkit/testing/rest.py +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from dataclasses import asdict, dataclass, field, replace
|
|
3
|
+
from typing import Any, Generic, Iterable, Self, TypeVar
|
|
4
|
+
|
|
5
|
+
from apexdevkit.formatter import DataclassFormatter, Formatter
|
|
6
|
+
from apexdevkit.repository.interface import Repository
|
|
7
|
+
|
|
8
|
+
RawItem = dict[str, Any]
|
|
9
|
+
RawCollection = Iterable[RawItem]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RestfulService(ABC):
|
|
13
|
+
def create_one(self, item: RawItem) -> RawItem:
|
|
14
|
+
raise NotImplementedError(self.create_one.__name__)
|
|
15
|
+
|
|
16
|
+
def create_many(self, items: RawCollection) -> RawCollection:
|
|
17
|
+
raise NotImplementedError(self.create_many.__name__)
|
|
18
|
+
|
|
19
|
+
def read_one(self, item_id: str) -> RawItem:
|
|
20
|
+
raise NotImplementedError(self.read_one.__name__)
|
|
21
|
+
|
|
22
|
+
def read_all(self) -> RawCollection:
|
|
23
|
+
raise NotImplementedError(self.read_all.__name__)
|
|
24
|
+
|
|
25
|
+
def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
|
|
26
|
+
raise NotImplementedError(self.update_one.__name__)
|
|
27
|
+
|
|
28
|
+
def update_many(self, items: RawCollection) -> RawCollection:
|
|
29
|
+
raise NotImplementedError(self.update_many.__name__)
|
|
30
|
+
|
|
31
|
+
def delete_one(self, item_id: str) -> None:
|
|
32
|
+
raise NotImplementedError(self.delete_one.__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _as_raw_collection(value: Iterable[Any]) -> RawCollection:
|
|
36
|
+
return [_as_raw_item(item) for item in value]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _as_raw_item(value: Any) -> RawItem:
|
|
40
|
+
return asdict(value)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
ItemT = TypeVar("ItemT")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class RestfulRepositoryBuilder(Generic[ItemT]):
|
|
48
|
+
resource: type[ItemT] | None = field(init=False, default=None)
|
|
49
|
+
formatter: Formatter[ItemT] | None = field(init=False, default=None)
|
|
50
|
+
repository: Repository[Any, ItemT] = field(init=False)
|
|
51
|
+
|
|
52
|
+
def with_resource(self, resource: type[ItemT]) -> Self:
|
|
53
|
+
self.resource = resource
|
|
54
|
+
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
def with_formatter(self, formatter: Formatter[ItemT]) -> Self:
|
|
58
|
+
self.formatter = formatter
|
|
59
|
+
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
def with_repository(self, repository: Repository[Any, ItemT]) -> Self:
|
|
63
|
+
self.repository = repository
|
|
64
|
+
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def build(self) -> RestfulService:
|
|
68
|
+
if not self.formatter and self.resource:
|
|
69
|
+
self.formatter = DataclassFormatter(self.resource)
|
|
70
|
+
|
|
71
|
+
assert self.formatter, "Must provide either resource or formatter"
|
|
72
|
+
|
|
73
|
+
return _RestfulNestedRepository(self.formatter, self.repository)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class _RestfulNestedRepository(RestfulService, Generic[ItemT]):
|
|
78
|
+
formatter: Formatter[ItemT]
|
|
79
|
+
repository: Repository[Any, ItemT]
|
|
80
|
+
|
|
81
|
+
def create_one(self, item: RawItem) -> RawItem:
|
|
82
|
+
return self.formatter.dump(self.repository.create(self.formatter.load(item)))
|
|
83
|
+
|
|
84
|
+
def create_many(self, items: RawCollection) -> RawCollection:
|
|
85
|
+
return [
|
|
86
|
+
self.formatter.dump(item)
|
|
87
|
+
for item in self.repository.create_many(
|
|
88
|
+
[self.formatter.load(fields) for fields in items]
|
|
89
|
+
)
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
def read_one(self, item_id: str) -> RawItem:
|
|
93
|
+
return self.formatter.dump(self.repository.read(item_id))
|
|
94
|
+
|
|
95
|
+
def read_all(self) -> RawCollection:
|
|
96
|
+
return [self.formatter.dump(item) for item in self.repository]
|
|
97
|
+
|
|
98
|
+
def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
|
|
99
|
+
result = replace(self.repository.read(item_id), **with_fields) # type: ignore
|
|
100
|
+
|
|
101
|
+
self.repository.update(result)
|
|
102
|
+
|
|
103
|
+
return self.formatter.dump(result)
|
|
104
|
+
|
|
105
|
+
def update_many(self, items: RawCollection) -> RawCollection:
|
|
106
|
+
result = [self.formatter.load(fields) for fields in items]
|
|
107
|
+
|
|
108
|
+
self.repository.update_many(result)
|
|
109
|
+
|
|
110
|
+
return [self.formatter.dump(item) for item in result]
|
|
111
|
+
|
|
112
|
+
def delete_one(self, item_id: str) -> None:
|
|
113
|
+
self.repository.delete(item_id)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@dataclass
|
|
117
|
+
class RestfulRepository(RestfulService):
|
|
118
|
+
resource: type[Any]
|
|
119
|
+
repository: Repository[Any, Any]
|
|
120
|
+
|
|
121
|
+
def create_one(self, item: RawItem) -> RawItem:
|
|
122
|
+
return _as_raw_item(self.repository.create(self.resource(**item)))
|
|
123
|
+
|
|
124
|
+
def create_many(self, items: RawCollection) -> RawCollection:
|
|
125
|
+
return _as_raw_collection(
|
|
126
|
+
self.repository.create_many([self.resource(**fields) for fields in items])
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def read_one(self, item_id: str) -> RawItem:
|
|
130
|
+
result = self.repository.read(item_id)
|
|
131
|
+
|
|
132
|
+
return _as_raw_item(result)
|
|
133
|
+
|
|
134
|
+
def read_all(self) -> RawCollection:
|
|
135
|
+
result = self.repository
|
|
136
|
+
|
|
137
|
+
return _as_raw_collection(result)
|
|
138
|
+
|
|
139
|
+
def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
|
|
140
|
+
result = replace(self.repository.read(item_id), **with_fields)
|
|
141
|
+
|
|
142
|
+
self.repository.update(result)
|
|
143
|
+
|
|
144
|
+
return _as_raw_item(result)
|
|
145
|
+
|
|
146
|
+
def update_many(self, items: RawCollection) -> RawCollection:
|
|
147
|
+
result = [self.resource(**fields) for fields in items]
|
|
148
|
+
|
|
149
|
+
self.repository.update_many(result)
|
|
150
|
+
|
|
151
|
+
return _as_raw_collection(result)
|
|
152
|
+
|
|
153
|
+
def delete_one(self, item_id: str) -> None:
|
|
154
|
+
self.repository.delete(item_id)
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
from abc import ABC
|
|
2
|
-
from dataclasses import asdict, dataclass, replace
|
|
3
|
-
from typing import Any, Iterable
|
|
4
|
-
|
|
5
|
-
from apexdevkit.repository.interface import Repository
|
|
6
|
-
|
|
7
|
-
RawItem = dict[str, Any]
|
|
8
|
-
RawCollection = Iterable[RawItem]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class RestfulService(ABC):
|
|
12
|
-
def create_one(self, item: RawItem) -> RawItem:
|
|
13
|
-
raise NotImplementedError(self.create_one.__name__)
|
|
14
|
-
|
|
15
|
-
def create_many(self, items: RawCollection) -> RawCollection:
|
|
16
|
-
raise NotImplementedError(self.create_many.__name__)
|
|
17
|
-
|
|
18
|
-
def read_one(self, item_id: str) -> RawItem:
|
|
19
|
-
raise NotImplementedError(self.read_one.__name__)
|
|
20
|
-
|
|
21
|
-
def read_all(self) -> RawCollection:
|
|
22
|
-
raise NotImplementedError(self.read_all.__name__)
|
|
23
|
-
|
|
24
|
-
def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
|
|
25
|
-
raise NotImplementedError(self.update_one.__name__)
|
|
26
|
-
|
|
27
|
-
def update_many(self, items: RawCollection) -> RawCollection:
|
|
28
|
-
raise NotImplementedError(self.update_many.__name__)
|
|
29
|
-
|
|
30
|
-
def delete_one(self, item_id: str) -> None:
|
|
31
|
-
raise NotImplementedError(self.delete_one.__name__)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def _as_raw_collection(value: Iterable[Any]) -> RawCollection:
|
|
35
|
-
return [_as_raw_item(item) for item in value]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _as_raw_item(value: Any) -> RawItem:
|
|
39
|
-
return asdict(value)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@dataclass
|
|
43
|
-
class RestfulRepository(RestfulService):
|
|
44
|
-
resource: type[Any]
|
|
45
|
-
repository: Repository[Any, Any]
|
|
46
|
-
|
|
47
|
-
def create_one(self, item: RawItem) -> RawItem:
|
|
48
|
-
return _as_raw_item(self.repository.create(self.resource(**item)))
|
|
49
|
-
|
|
50
|
-
def create_many(self, items: RawCollection) -> RawCollection:
|
|
51
|
-
return _as_raw_collection(
|
|
52
|
-
self.repository.create_many([self.resource(**fields) for fields in items])
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
def read_one(self, item_id: str) -> RawItem:
|
|
56
|
-
result = self.repository.read(item_id)
|
|
57
|
-
|
|
58
|
-
return _as_raw_item(result)
|
|
59
|
-
|
|
60
|
-
def read_all(self) -> RawCollection:
|
|
61
|
-
result = self.repository
|
|
62
|
-
|
|
63
|
-
return _as_raw_collection(result)
|
|
64
|
-
|
|
65
|
-
def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
|
|
66
|
-
result = replace(self.repository.read(item_id), **with_fields)
|
|
67
|
-
|
|
68
|
-
self.repository.update(result)
|
|
69
|
-
|
|
70
|
-
return _as_raw_item(result)
|
|
71
|
-
|
|
72
|
-
def update_many(self, items: RawCollection) -> RawCollection:
|
|
73
|
-
result = [self.resource(**fields) for fields in items]
|
|
74
|
-
|
|
75
|
-
self.repository.update_many(result)
|
|
76
|
-
|
|
77
|
-
return _as_raw_collection(result)
|
|
78
|
-
|
|
79
|
-
def delete_one(self, item_id: str) -> None:
|
|
80
|
-
self.repository.delete(item_id)
|
|
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
|