apexdevkit 1.9.3__tar.gz → 1.9.5__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 (38) hide show
  1. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/PKG-INFO +1 -1
  2. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/connector.py +2 -4
  3. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/database.py +1 -53
  4. apexdevkit-1.9.5/apexdevkit/repository/mongo.py +110 -0
  5. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/pyproject.toml +2 -1
  6. apexdevkit-1.9.3/apexdevkit/repository/mongo.py +0 -79
  7. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/LICENSE +0 -0
  8. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/README.md +0 -0
  9. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/__init__.py +0 -0
  10. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/annotation/__init__.py +0 -0
  11. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/annotation/deprecate.py +0 -0
  12. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/error.py +0 -0
  13. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/__init__.py +0 -0
  14. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/builder.py +0 -0
  15. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/dependable.py +0 -0
  16. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/docs.py +0 -0
  17. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/resource.py +0 -0
  18. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/response.py +0 -0
  19. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/router.py +0 -0
  20. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/schema.py +0 -0
  21. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/fastapi/service.py +0 -0
  22. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/formatter.py +0 -0
  23. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/__init__.py +0 -0
  24. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/fake.py +0 -0
  25. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/fluent.py +0 -0
  26. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/httpx.py +0 -0
  27. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/json.py +0 -0
  28. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/http/url.py +0 -0
  29. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/py.typed +0 -0
  30. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/__init__.py +0 -0
  31. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/base.py +0 -0
  32. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/in_memory.py +0 -0
  33. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/interface.py +0 -0
  34. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/repository/sqlite.py +0 -0
  35. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/testing/__init__.py +0 -0
  36. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/testing/database.py +0 -0
  37. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/testing/fake.py +0 -0
  38. {apexdevkit-1.9.3 → apexdevkit-1.9.5}/apexdevkit/testing/rest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.9.3
3
+ Version: 1.9.5
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -35,10 +35,8 @@ class SqliteInMemoryConnector:
35
35
 
36
36
 
37
37
  @dataclass
38
- class MongoDBConnector:
38
+ class PyMongoConnector:
39
39
  dsn: str
40
40
 
41
41
  def connect(self) -> ContextManager[MongoClient[Any]]:
42
- connection: MongoClient[Any] = MongoClient(self.dsn)
43
-
44
- return connection
42
+ return MongoClient(self.dsn)
@@ -1,11 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass, field
4
- from typing import Any, ContextManager, Dict, Iterable, Iterator, Protocol, Self
5
-
6
- from pymongo import MongoClient
7
- from pymongo.collection import Collection, ReturnDocument
8
- from pymongo.results import DeleteResult, InsertOneResult
4
+ from typing import Any, ContextManager, Iterable, Protocol, Self
9
5
 
10
6
  _RawData = dict[str, Any]
11
7
 
@@ -46,59 +42,11 @@ class Database:
46
42
  return [dict(raw or {}) for raw in raw]
47
43
 
48
44
 
49
- @dataclass
50
- class MongoDatabase:
51
- connector: MongoConnector
52
- database_name: str
53
- collection_name: str
54
-
55
- def collection(self, client: MongoClient[Any]) -> Collection[Any]:
56
- return client[self.database_name][self.collection_name]
57
-
58
- def __iter__(self) -> Iterator[Any]:
59
- with self.connector.connect() as client:
60
- for raw in self.collection(client).find():
61
- yield raw
62
-
63
- def __len__(self) -> int:
64
- with self.connector.connect() as client:
65
- return self.collection(client).count_documents({})
66
-
67
- def create(self, item: Dict[str, Any]) -> InsertOneResult:
68
- with self.connector.connect() as client:
69
- return self.collection(client).insert_one(item)
70
-
71
- def read(self, item_id: str) -> Dict[str, Any] | None:
72
- with self.connector.connect() as client:
73
- return self.collection(client).find_one({"id": item_id})
74
-
75
- def update(self, item_id: str, item: Dict[str, Any]) -> Any:
76
- with self.connector.connect() as client:
77
- return self.collection(client).find_one_and_update(
78
- {"id": item_id},
79
- {"$set": item},
80
- return_document=ReturnDocument.AFTER,
81
- )
82
-
83
- def delete(self, item_id: str) -> DeleteResult:
84
- with self.connector.connect() as client:
85
- return self.collection(client).delete_one({"id": item_id})
86
-
87
- def delete_all(self) -> DeleteResult:
88
- with self.connector.connect() as client:
89
- return self.collection(client).delete_many({})
90
-
91
-
92
45
  class Connector(Protocol): # pragma: no cover
93
46
  def connect(self) -> ContextManager[Connection]:
94
47
  pass
95
48
 
96
49
 
97
- class MongoConnector(Protocol): # pragma: no cover
98
- def connect(self) -> ContextManager[MongoClient[Any]]:
99
- pass
100
-
101
-
102
50
  class Connection(Protocol): # pragma: no cover
103
51
  def cursor(self) -> Cursor:
104
52
  pass
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, ContextManager, Dict, Generic, Iterator, Protocol, TypeVar
5
+
6
+ from pymongo import MongoClient, ReturnDocument
7
+ from pymongo.collection import Collection
8
+ from pymongo.results import DeleteResult, InsertOneResult
9
+
10
+ from apexdevkit.error import DoesNotExistError, ExistsError
11
+ from apexdevkit.formatter import Formatter
12
+
13
+
14
+ class _Item(Protocol): # pragma: no cover
15
+ @property
16
+ def id(self) -> Any:
17
+ pass
18
+
19
+
20
+ ItemT = TypeVar("ItemT", bound=_Item)
21
+
22
+
23
+ @dataclass
24
+ class MongoRepository(Generic[ItemT]):
25
+ database: MongoDatabase
26
+ formatter: Formatter[dict[str, Any], ItemT]
27
+
28
+ def __iter__(self) -> Iterator[ItemT]:
29
+ for raw in self.database:
30
+ yield self.formatter.load(raw)
31
+
32
+ def __len__(self) -> int:
33
+ return len(self.database)
34
+
35
+ def create(self, item: ItemT) -> ItemT:
36
+ try:
37
+ self.read(item.id)
38
+ raise ExistsError(item).with_duplicate(
39
+ lambda i: f"_Item with id<{i.id}> already exists."
40
+ )
41
+ except DoesNotExistError:
42
+ self.database.create(self.formatter.dump(item))
43
+ return item
44
+
45
+ def create_many(self, items: list[ItemT]) -> list[ItemT]:
46
+ return [self.create(item) for item in items]
47
+
48
+ def read(self, item_id: str) -> ItemT:
49
+ raw = self.database.read(item_id)
50
+
51
+ if not raw:
52
+ raise DoesNotExistError(item_id)
53
+
54
+ return self.formatter.load(raw)
55
+
56
+ def update(self, item: ItemT) -> None:
57
+ self.database.update(item.id, self.formatter.dump(item))
58
+
59
+ def update_many(self, items: list[ItemT]) -> None:
60
+ for item in items:
61
+ self.update(item)
62
+
63
+ def delete(self, item_id: str) -> None:
64
+ result = self.database.delete(item_id)
65
+ if result.deleted_count == 0:
66
+ raise DoesNotExistError(item_id)
67
+
68
+
69
+ @dataclass
70
+ class MongoDatabase:
71
+ connector: MongoConnector
72
+ database_name: str
73
+ collection_name: str
74
+
75
+ def collection(self, client: MongoClient[Any]) -> Collection[Any]:
76
+ return client[self.database_name][self.collection_name]
77
+
78
+ def __iter__(self) -> Iterator[Any]:
79
+ with self.connector.connect() as client:
80
+ for raw in self.collection(client).find():
81
+ yield raw
82
+
83
+ def __len__(self) -> int:
84
+ with self.connector.connect() as client:
85
+ return self.collection(client).count_documents({})
86
+
87
+ def create(self, item: Dict[str, Any]) -> InsertOneResult:
88
+ with self.connector.connect() as client:
89
+ return self.collection(client).insert_one(item)
90
+
91
+ def read(self, item_id: str) -> Dict[str, Any] | None:
92
+ with self.connector.connect() as client:
93
+ return self.collection(client).find_one({"id": item_id})
94
+
95
+ def update(self, item_id: str, item: Dict[str, Any]) -> Any:
96
+ with self.connector.connect() as client:
97
+ return self.collection(client).find_one_and_update(
98
+ {"id": item_id},
99
+ {"$set": item},
100
+ return_document=ReturnDocument.AFTER,
101
+ )
102
+
103
+ def delete(self, item_id: str) -> DeleteResult:
104
+ with self.connector.connect() as client:
105
+ return self.collection(client).delete_one({"id": item_id})
106
+
107
+
108
+ class MongoConnector(Protocol): # pragma: no cover
109
+ def connect(self) -> ContextManager[MongoClient[Any]]:
110
+ pass
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.9.3"
3
+ version = "1.9.5"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
@@ -17,6 +17,7 @@ pytest-cov = "*"
17
17
  pytest-recording = "*"
18
18
  coverage = "*"
19
19
  faker = "*"
20
+ mongomock = "*"
20
21
 
21
22
  [tool.poetry.group.lint.dependencies]
22
23
  mypy = "*"
@@ -1,79 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import Any, Dict, Generic, Iterator, Protocol, TypeVar
5
-
6
- from apexdevkit.error import DoesNotExistError, ExistsError
7
- from apexdevkit.repository.database import MongoDatabase
8
-
9
-
10
- class _Item(Protocol): # pragma: no cover
11
- @property
12
- def id(self) -> Any:
13
- pass
14
-
15
-
16
- ItemT = TypeVar("ItemT", bound=_Item)
17
-
18
-
19
- @dataclass
20
- class MongoDBRepository(Generic[ItemT]):
21
- database: MongoDatabase
22
- table: MongoTable[ItemT]
23
-
24
- def __iter__(self) -> Iterator[ItemT]:
25
- for raw in self.database:
26
- yield self.table.load(raw)
27
-
28
- def __len__(self) -> int:
29
- return len(self.database)
30
-
31
- def create(self, item: ItemT) -> ItemT:
32
- try:
33
- self.read(item.id)
34
- raise ExistsError(item).with_duplicate(
35
- lambda i: f"_Item with id<{i.id}> already exists."
36
- )
37
- except DoesNotExistError:
38
- self.database.create(self.table.to_dict(item))
39
- return item
40
-
41
- def create_many(self, items: list[ItemT]) -> list[ItemT]:
42
- return [self.create(item) for item in items]
43
-
44
- def read(self, item_id: str) -> ItemT:
45
- raw = self.database.read(item_id)
46
-
47
- if not raw:
48
- raise DoesNotExistError(item_id)
49
-
50
- return self.table.load(raw)
51
-
52
- def update(self, item: ItemT) -> None:
53
- self.database.update(
54
- self.table.get_id(item),
55
- self.table.to_dict(item),
56
- )
57
-
58
- def update_many(self, items: list[ItemT]) -> None:
59
- for item in items:
60
- self.update(item)
61
-
62
- def delete(self, item_id: str) -> None:
63
- result = self.database.delete(item_id)
64
- if result.deleted_count == 0:
65
- raise DoesNotExistError(item_id)
66
-
67
- def delete_all(self) -> None:
68
- self.database.delete_all()
69
-
70
-
71
- class MongoTable(Generic[ItemT]):
72
- def to_dict(self, item: ItemT) -> Dict[str, Any]:
73
- raise NotImplementedError("Not implemented")
74
-
75
- def load(self, data: Dict[str, Any]) -> ItemT:
76
- raise NotImplementedError("Not implemented")
77
-
78
- def get_id(self, item: ItemT) -> str:
79
- raise NotImplementedError("Not implemented")
File without changes
File without changes