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