apexdevkit 1.14.1__tar.gz → 1.14.2__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.14.1 → apexdevkit-1.14.2}/PKG-INFO +1 -1
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/formatter.py +7 -6
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/key_fn.py +1 -1
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/__init__.py +2 -2
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/in_memory.py +69 -33
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/pyproject.toml +1 -1
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/LICENSE +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/README.md +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/environment.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/error.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/decorator.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/mongo.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.14.1 → apexdevkit-1.14.2}/apexdevkit/testing/rest.py +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import pickle
|
|
1
2
|
from copy import deepcopy
|
|
2
3
|
from dataclasses import asdict, dataclass, field
|
|
3
4
|
from typing import Any, Generic, Protocol, Self, TypeVar
|
|
4
5
|
|
|
5
6
|
_SourceT = TypeVar("_SourceT")
|
|
6
7
|
_TargetT = TypeVar("_TargetT")
|
|
8
|
+
_ItemT = TypeVar("_ItemT")
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
class Formatter(Protocol[_SourceT, _TargetT]): # pragma: no cover
|
|
@@ -14,13 +16,12 @@ class Formatter(Protocol[_SourceT, _TargetT]): # pragma: no cover
|
|
|
14
16
|
pass
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return source
|
|
19
|
+
class PickleFormatter(Generic[_ItemT]):
|
|
20
|
+
def dump(self, item: _ItemT) -> bytes:
|
|
21
|
+
return pickle.dumps(item)
|
|
21
22
|
|
|
22
|
-
def
|
|
23
|
-
return
|
|
23
|
+
def load(self, raw: bytes) -> _ItemT:
|
|
24
|
+
return pickle.loads(raw) # type: ignore
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
@dataclass
|
|
@@ -7,7 +7,7 @@ from apexdevkit.repository.database import (
|
|
|
7
7
|
DatabaseCommand,
|
|
8
8
|
)
|
|
9
9
|
from apexdevkit.repository.in_memory import (
|
|
10
|
-
|
|
10
|
+
InMemoryByteStore,
|
|
11
11
|
InMemoryRepository,
|
|
12
12
|
KeyValueStore,
|
|
13
13
|
)
|
|
@@ -20,7 +20,7 @@ __all__ = [
|
|
|
20
20
|
"Database",
|
|
21
21
|
"DatabaseCommand",
|
|
22
22
|
"InMemoryRepository",
|
|
23
|
-
"
|
|
23
|
+
"InMemoryByteStore",
|
|
24
24
|
"KeyValueStore",
|
|
25
25
|
"Repository",
|
|
26
26
|
"RepositoryBase",
|
|
@@ -1,54 +1,65 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from contextlib import suppress
|
|
3
4
|
from dataclasses import dataclass, field
|
|
4
5
|
from typing import Any, Callable, Generic, Iterable, Iterator, Protocol, Self
|
|
5
6
|
|
|
6
7
|
from apexdevkit.error import DoesNotExistError, ExistsError
|
|
7
|
-
from apexdevkit.formatter import Formatter,
|
|
8
|
+
from apexdevkit.formatter import Formatter, PickleFormatter
|
|
8
9
|
from apexdevkit.key_fn import AttributeKey
|
|
9
10
|
from apexdevkit.repository import RepositoryBase
|
|
10
11
|
from apexdevkit.repository.interface import ItemT, Repository
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
_Raw = dict[str, Any]
|
|
13
|
+
_KeyFunction = Callable[[ItemT], str]
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
@dataclass
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
17
|
class InMemoryRepository(Generic[ItemT]):
|
|
18
|
-
store: KeyValueStore[ItemT] = field(default_factory=lambda:
|
|
19
|
-
keys: list[
|
|
20
|
-
seeds:
|
|
21
|
-
|
|
22
|
-
def
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
store: KeyValueStore[ItemT] = field(default_factory=lambda: InMemoryByteStore())
|
|
19
|
+
keys: list[_KeyFunction[ItemT]] = field(default_factory=list)
|
|
20
|
+
seeds: frozenset[ItemT] = field(default_factory=frozenset)
|
|
21
|
+
|
|
22
|
+
def with_namespace(self, value: str) -> InMemoryRepository[ItemT]:
|
|
23
|
+
return InMemoryRepository[ItemT](
|
|
24
|
+
store=StoreNamespace(value, self.store),
|
|
25
|
+
keys=self.keys,
|
|
26
|
+
seeds=self.seeds,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def with_store(self, value: KeyValueStore[ItemT]) -> InMemoryRepository[ItemT]:
|
|
30
|
+
return InMemoryRepository[ItemT](
|
|
31
|
+
store=value,
|
|
32
|
+
keys=self.keys,
|
|
33
|
+
seeds=self.seeds,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def and_key(self, function: _KeyFunction[ItemT]) -> InMemoryRepository[ItemT]:
|
|
31
37
|
return self.with_key(function)
|
|
32
38
|
|
|
33
|
-
def with_key(self, function:
|
|
34
|
-
|
|
39
|
+
def with_key(self, function: _KeyFunction[ItemT]) -> InMemoryRepository[ItemT]:
|
|
40
|
+
return InMemoryRepository[ItemT](
|
|
41
|
+
store=self.store,
|
|
42
|
+
keys=[*self.keys, function],
|
|
43
|
+
seeds=self.seeds,
|
|
44
|
+
)
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def and_seeded(self, *items: ItemT) -> Self:
|
|
46
|
+
def and_seeded(self, *items: ItemT) -> InMemoryRepository[ItemT]:
|
|
39
47
|
return self.with_seeded(*items)
|
|
40
48
|
|
|
41
|
-
def with_seeded(self, *items: ItemT) ->
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
def with_seeded(self, *items: ItemT) -> InMemoryRepository[ItemT]:
|
|
50
|
+
return InMemoryRepository(
|
|
51
|
+
store=self.store,
|
|
52
|
+
keys=self.keys,
|
|
53
|
+
seeds=self.seeds.union(set(items)),
|
|
54
|
+
)
|
|
45
55
|
|
|
46
56
|
def build(self) -> Repository[ItemT]:
|
|
47
57
|
return self._seed(self._create())
|
|
48
58
|
|
|
49
59
|
def _seed(self, repository: Repository[ItemT]) -> Repository[ItemT]:
|
|
50
60
|
for seed in self.seeds:
|
|
51
|
-
|
|
61
|
+
with suppress(ExistsError):
|
|
62
|
+
repository.create(seed)
|
|
52
63
|
|
|
53
64
|
return repository
|
|
54
65
|
|
|
@@ -80,9 +91,10 @@ class KeyValueStore(Protocol[ItemT]): # pragma: no cover
|
|
|
80
91
|
|
|
81
92
|
|
|
82
93
|
@dataclass
|
|
83
|
-
class
|
|
84
|
-
formatter: Formatter[
|
|
85
|
-
|
|
94
|
+
class InMemoryByteStore(Generic[ItemT]):
|
|
95
|
+
formatter: Formatter[bytes, ItemT] = field(default_factory=PickleFormatter)
|
|
96
|
+
|
|
97
|
+
items: dict[str, bytes] = field(default_factory=dict)
|
|
86
98
|
|
|
87
99
|
def count(self) -> int:
|
|
88
100
|
return len(self.items)
|
|
@@ -101,10 +113,34 @@ class InMemoryKeyValueStore(Generic[ItemT]):
|
|
|
101
113
|
yield self.formatter.load(raw)
|
|
102
114
|
|
|
103
115
|
|
|
116
|
+
@dataclass
|
|
117
|
+
class StoreNamespace(Generic[ItemT]):
|
|
118
|
+
name: str
|
|
119
|
+
inner: KeyValueStore[ItemT]
|
|
120
|
+
|
|
121
|
+
def count(self) -> int:
|
|
122
|
+
return self.inner.count()
|
|
123
|
+
|
|
124
|
+
def values(self) -> Iterable[ItemT]:
|
|
125
|
+
return self.inner.values()
|
|
126
|
+
|
|
127
|
+
def set(self, key: str, value: ItemT) -> None:
|
|
128
|
+
self.inner.set(self._expand(key), value)
|
|
129
|
+
|
|
130
|
+
def get(self, key: str) -> ItemT:
|
|
131
|
+
return self.inner.get(self._expand(key))
|
|
132
|
+
|
|
133
|
+
def drop(self, key: str) -> None:
|
|
134
|
+
self.inner.drop(self._expand(key))
|
|
135
|
+
|
|
136
|
+
def _expand(self, key: str) -> str:
|
|
137
|
+
return "-".join([self.name, key])
|
|
138
|
+
|
|
139
|
+
|
|
104
140
|
@dataclass
|
|
105
141
|
class _SingleKeyRepository(RepositoryBase[ItemT]):
|
|
106
142
|
store: KeyValueStore[ItemT]
|
|
107
|
-
pk:
|
|
143
|
+
pk: _KeyFunction[ItemT]
|
|
108
144
|
|
|
109
145
|
def bind(self, **kwargs: Any) -> Self: # pragma: no cover
|
|
110
146
|
return self
|
|
@@ -150,7 +186,7 @@ class _SingleKeyRepository(RepositoryBase[ItemT]):
|
|
|
150
186
|
class _ManyKeyRepository(RepositoryBase[ItemT]):
|
|
151
187
|
store: KeyValueStore[ItemT]
|
|
152
188
|
|
|
153
|
-
keys: list[
|
|
189
|
+
keys: list[_KeyFunction[ItemT]] = field(default_factory=list)
|
|
154
190
|
|
|
155
191
|
def bind(self, **kwargs: Any) -> Self: # pragma: no cover
|
|
156
192
|
return self
|
|
@@ -171,7 +207,7 @@ class _ManyKeyRepository(RepositoryBase[ItemT]):
|
|
|
171
207
|
|
|
172
208
|
error.fire()
|
|
173
209
|
|
|
174
|
-
def _pk(self, item: ItemT) ->
|
|
210
|
+
def _pk(self, item: ItemT) -> str:
|
|
175
211
|
return self.keys[0](item)
|
|
176
212
|
|
|
177
213
|
def update(self, item: ItemT) -> None:
|
|
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
|