apexdevkit 1.9.9__tar.gz → 1.11.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.9.9 → apexdevkit-1.11.1}/PKG-INFO +1 -1
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/in_memory.py +20 -48
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/pyproject.toml +1 -1
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/LICENSE +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/README.md +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/error.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/decorator.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/mongo.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.9.9 → apexdevkit-1.11.1}/apexdevkit/testing/rest.py +0 -0
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
from copy import deepcopy
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
|
-
from typing import Any, Callable,
|
|
3
|
+
from typing import Any, Callable, Iterable, Iterator, Self
|
|
4
4
|
|
|
5
|
-
from apexdevkit.annotation import deprecated
|
|
6
5
|
from apexdevkit.error import DoesNotExistError, ExistsError
|
|
7
|
-
from apexdevkit.formatter import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class _Item(Protocol): # pragma: no cover
|
|
11
|
-
@property
|
|
12
|
-
def id(self) -> Any:
|
|
13
|
-
pass
|
|
14
|
-
|
|
6
|
+
from apexdevkit.formatter import Formatter
|
|
7
|
+
from apexdevkit.repository import RepositoryBase
|
|
8
|
+
from apexdevkit.repository.interface import IdT, ItemT
|
|
15
9
|
|
|
16
10
|
KeyFunction = Callable[[Any], str]
|
|
17
|
-
|
|
18
|
-
ItemT = TypeVar("ItemT", bound=_Item)
|
|
19
11
|
_Raw = dict[str, Any]
|
|
20
12
|
|
|
21
13
|
|
|
@@ -28,37 +20,12 @@ class AttributeKey:
|
|
|
28
20
|
|
|
29
21
|
|
|
30
22
|
@dataclass
|
|
31
|
-
class InMemoryRepository(
|
|
23
|
+
class InMemoryRepository(RepositoryBase[IdT, ItemT]):
|
|
32
24
|
formatter: Formatter[_Raw, ItemT]
|
|
33
25
|
items: dict[str, _Raw] = field(default_factory=dict)
|
|
34
26
|
|
|
35
27
|
_key_functions: list[KeyFunction] = field(init=False, default_factory=list)
|
|
36
28
|
|
|
37
|
-
@classmethod
|
|
38
|
-
def for_dataclass(cls, value: type[ItemT]) -> "InMemoryRepository[ItemT]":
|
|
39
|
-
return cls(DataclassFormatter(value))
|
|
40
|
-
|
|
41
|
-
def __post_init__(self) -> None:
|
|
42
|
-
self._key_functions = [AttributeKey("id")]
|
|
43
|
-
|
|
44
|
-
@deprecated(
|
|
45
|
-
"""
|
|
46
|
-
.with_searchable() is deprecated. Use .with_key() instead.
|
|
47
|
-
Instead of .with_searchable("code") use .with_key(AttributeKey("code"))
|
|
48
|
-
"""
|
|
49
|
-
)
|
|
50
|
-
def with_searchable(self, attribute: str) -> Self:
|
|
51
|
-
return self.with_key(AttributeKey(attribute))
|
|
52
|
-
|
|
53
|
-
@deprecated(
|
|
54
|
-
"""
|
|
55
|
-
.with_unique() is deprecated. Use .with_key() instead.
|
|
56
|
-
Instead of .with_unique(criteria) use .with_key(criteria)
|
|
57
|
-
"""
|
|
58
|
-
)
|
|
59
|
-
def with_unique(self, criteria: KeyFunction) -> Self:
|
|
60
|
-
return self.with_key(criteria)
|
|
61
|
-
|
|
62
29
|
def with_key(self, function: KeyFunction) -> Self:
|
|
63
30
|
self._key_functions.append(function)
|
|
64
31
|
|
|
@@ -77,7 +44,7 @@ class InMemoryRepository(Generic[ItemT]):
|
|
|
77
44
|
|
|
78
45
|
def create(self, item: ItemT) -> ItemT:
|
|
79
46
|
self._ensure_does_not_exist(item)
|
|
80
|
-
self.items[
|
|
47
|
+
self.items[self._key_functions[0](item)] = deepcopy(self.formatter.dump(item))
|
|
81
48
|
|
|
82
49
|
return item
|
|
83
50
|
|
|
@@ -91,27 +58,32 @@ class InMemoryRepository(Generic[ItemT]):
|
|
|
91
58
|
|
|
92
59
|
error.fire()
|
|
93
60
|
|
|
94
|
-
def read(self, item_id:
|
|
95
|
-
for
|
|
96
|
-
for
|
|
61
|
+
def read(self, item_id: IdT) -> ItemT:
|
|
62
|
+
for key in self._key_functions:
|
|
63
|
+
for item in self:
|
|
97
64
|
if key(item) == str(item_id):
|
|
98
65
|
return item
|
|
99
66
|
|
|
100
67
|
raise DoesNotExistError(item_id)
|
|
101
68
|
|
|
102
69
|
def update(self, item: ItemT) -> None:
|
|
103
|
-
|
|
70
|
+
try:
|
|
71
|
+
del self.items[self._key_functions[0](item)]
|
|
72
|
+
except KeyError:
|
|
73
|
+
raise DoesNotExistError(self._key_functions[0](item))
|
|
104
74
|
self.create(item)
|
|
105
75
|
|
|
106
76
|
def update_many(self, items: list[ItemT]) -> None:
|
|
107
77
|
for item in items:
|
|
108
78
|
self.update(item)
|
|
109
79
|
|
|
110
|
-
def delete(self, item_id:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
80
|
+
def delete(self, item_id: IdT) -> None:
|
|
81
|
+
for key in self._key_functions:
|
|
82
|
+
for item in self:
|
|
83
|
+
if key(item) == str(item_id):
|
|
84
|
+
del self.items[self._key_functions[0](item)]
|
|
85
|
+
return
|
|
86
|
+
raise DoesNotExistError(item_id)
|
|
115
87
|
|
|
116
88
|
def search(self, **kwargs: Any) -> Iterable[ItemT]:
|
|
117
89
|
items = []
|
|
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
|