apexdevkit 1.9.7__tar.gz → 1.9.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.
Files changed (39) hide show
  1. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/PKG-INFO +1 -1
  2. apexdevkit-1.9.9/apexdevkit/repository/decorator.py +36 -0
  3. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/in_memory.py +38 -17
  4. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/pyproject.toml +1 -1
  5. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/LICENSE +0 -0
  6. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/README.md +0 -0
  7. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/__init__.py +0 -0
  8. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/annotation/__init__.py +0 -0
  9. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/annotation/deprecate.py +0 -0
  10. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/error.py +0 -0
  11. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/__init__.py +0 -0
  12. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/builder.py +0 -0
  13. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/dependable.py +0 -0
  14. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/docs.py +0 -0
  15. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/resource.py +0 -0
  16. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/response.py +0 -0
  17. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/router.py +0 -0
  18. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/schema.py +0 -0
  19. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fastapi/service.py +0 -0
  20. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/fluent.py +0 -0
  21. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/formatter.py +0 -0
  22. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/__init__.py +0 -0
  23. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/fake.py +0 -0
  24. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/fluent.py +0 -0
  25. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/httpx.py +0 -0
  26. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/json.py +0 -0
  27. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/http/url.py +0 -0
  28. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/py.typed +0 -0
  29. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/__init__.py +0 -0
  30. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/base.py +0 -0
  31. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/connector.py +0 -0
  32. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/database.py +0 -0
  33. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/interface.py +0 -0
  34. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/mongo.py +0 -0
  35. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/repository/sqlite.py +0 -0
  36. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/testing/__init__.py +0 -0
  37. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/testing/database.py +0 -0
  38. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/testing/fake.py +0 -0
  39. {apexdevkit-1.9.7 → apexdevkit-1.9.9}/apexdevkit/testing/rest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.9.7
3
+ Version: 1.9.9
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -0,0 +1,36 @@
1
+ from dataclasses import dataclass
2
+ from typing import Generic, Iterator, TypeVar
3
+
4
+ from apexdevkit.repository import Repository
5
+
6
+ ItemT = TypeVar("ItemT")
7
+ IdT = TypeVar("IdT", contravariant=True)
8
+
9
+
10
+ @dataclass
11
+ class RepositoryDecorator(Generic[IdT, ItemT]):
12
+ inner: Repository[IdT, ItemT]
13
+
14
+ def create(self, item: ItemT) -> ItemT:
15
+ return self.inner.create(item)
16
+
17
+ def create_many(self, items: list[ItemT]) -> list[ItemT]:
18
+ return self.inner.create_many(items)
19
+
20
+ def read(self, item_id: IdT) -> ItemT:
21
+ return self.inner.read(item_id)
22
+
23
+ def update(self, item: ItemT) -> None:
24
+ self.inner.update(item)
25
+
26
+ def update_many(self, items: list[ItemT]) -> None:
27
+ self.inner.update_many(items)
28
+
29
+ def delete(self, item_id: IdT) -> None:
30
+ self.inner.delete(item_id)
31
+
32
+ def __iter__(self) -> Iterator[ItemT]:
33
+ return self.inner.__iter__()
34
+
35
+ def __len__(self) -> int:
36
+ return self.inner.__len__()
@@ -1,8 +1,9 @@
1
1
  from copy import deepcopy
2
2
  from dataclasses import dataclass, field
3
- from typing import Any, Generic, Iterable, Iterator, Protocol, Self, TypeVar
3
+ from typing import Any, Callable, Generic, Iterable, Iterator, Protocol, Self, TypeVar
4
4
 
5
- from apexdevkit.error import Criteria, DoesNotExistError, ExistsError
5
+ from apexdevkit.annotation import deprecated
6
+ from apexdevkit.error import DoesNotExistError, ExistsError
6
7
  from apexdevkit.formatter import DataclassFormatter, Formatter
7
8
 
8
9
 
@@ -12,32 +13,54 @@ class _Item(Protocol): # pragma: no cover
12
13
  pass
13
14
 
14
15
 
16
+ KeyFunction = Callable[[Any], str]
17
+
15
18
  ItemT = TypeVar("ItemT", bound=_Item)
16
19
  _Raw = dict[str, Any]
17
20
 
18
21
 
22
+ @dataclass
23
+ class AttributeKey:
24
+ name: str
25
+
26
+ def __call__(self, item: Any) -> str:
27
+ return str(getattr(item, self.name))
28
+
29
+
19
30
  @dataclass
20
31
  class InMemoryRepository(Generic[ItemT]):
21
32
  formatter: Formatter[_Raw, ItemT]
22
33
  items: dict[str, _Raw] = field(default_factory=dict)
23
34
 
24
- _uniques: list[Criteria] = field(init=False, default_factory=list)
25
- _search_by: list[str] = field(init=False, default_factory=list)
35
+ _key_functions: list[KeyFunction] = field(init=False, default_factory=list)
26
36
 
27
37
  @classmethod
28
38
  def for_dataclass(cls, value: type[ItemT]) -> "InMemoryRepository[ItemT]":
29
39
  return cls(DataclassFormatter(value))
30
40
 
31
41
  def __post_init__(self) -> None:
32
- self._search_by = ["id", *self._search_by]
33
-
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
+ )
34
50
  def with_searchable(self, attribute: str) -> Self:
35
- self._search_by.append(attribute)
51
+ return self.with_key(AttributeKey(attribute))
36
52
 
37
- return self
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)
38
61
 
39
- def with_unique(self, criteria: Criteria) -> Self:
40
- self._uniques.append(criteria)
62
+ def with_key(self, function: KeyFunction) -> Self:
63
+ self._key_functions.append(function)
41
64
 
42
65
  return self
43
66
 
@@ -62,18 +85,16 @@ class InMemoryRepository(Generic[ItemT]):
62
85
  for existing in self:
63
86
  error = ExistsError(existing)
64
87
 
65
- for criteria in self._uniques:
66
- if criteria(new) == criteria(existing):
67
- error.with_duplicate(criteria)
88
+ for key in self._key_functions:
89
+ if key(new) == key(existing):
90
+ error.with_duplicate(key)
68
91
 
69
92
  error.fire()
70
93
 
71
- assert str(new.id) not in self.items, f"Item with id<{new.id}> already exists"
72
-
73
94
  def read(self, item_id: Any) -> ItemT:
74
95
  for item in self:
75
- for attribute in self._search_by:
76
- if getattr(item, attribute) == item_id:
96
+ for key in self._key_functions:
97
+ if key(item) == str(item_id):
77
98
  return item
78
99
 
79
100
  raise DoesNotExistError(item_id)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.9.7"
3
+ version = "1.9.9"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
File without changes
File without changes