qena-shared-lib 0.1.19__py3-none-any.whl → 0.1.21__py3-none-any.whl

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.
@@ -1,3 +1,5 @@
1
+ from pydantic import Field
2
+
1
3
  from ._base import (
2
4
  ROUTE_HANDLER_ATTRIBUTE,
3
5
  APIRouter,
@@ -68,6 +70,7 @@ __all__ = [
68
70
  "Cookie",
69
71
  "delete",
70
72
  "Depends",
73
+ "Field",
71
74
  "File",
72
75
  "FileResponse",
73
76
  "Form",
@@ -14,7 +14,16 @@ from typing import (
14
14
 
15
15
  from bson.objectid import ObjectId
16
16
  from pydantic import BeforeValidator, Field, field_serializer
17
- from pymongo import AsyncMongoClient, IndexModel
17
+ from pymongo import (
18
+ ASCENDING,
19
+ DESCENDING,
20
+ GEO2D,
21
+ GEOSPHERE,
22
+ HASHED,
23
+ TEXT,
24
+ AsyncMongoClient,
25
+ IndexModel,
26
+ )
18
27
  from pymongo.asynchronous.client_session import AsyncClientSession
19
28
  from pymongo.asynchronous.collection import AsyncCollection
20
29
  from pymongo.asynchronous.database import AsyncDatabase
@@ -25,14 +34,22 @@ from .logging import LoggerFactory
25
34
 
26
35
  __all__ = [
27
36
  "AggregatedDocument",
37
+ "ASCENDING",
38
+ "AsyncClientSession",
39
+ "DESCENDING",
28
40
  "Document",
29
41
  "EmbeddedDocument",
42
+ "Field",
43
+ "GEO2D",
44
+ "GEOSPHERE",
45
+ "HASHED",
30
46
  "IndexManager",
31
47
  "IndexModel",
32
48
  "MongoDBManager",
33
49
  "MongoDBObjectId",
34
50
  "ProjectedDocument",
35
51
  "RepositoryBase",
52
+ "TEXT",
36
53
  "validate_object_id",
37
54
  ]
38
55
 
@@ -235,11 +252,9 @@ S = TypeVar("S")
235
252
 
236
253
 
237
254
  class RepositoryBase(Generic[T]):
238
- def __init__(
239
- self, db: MongoDBManager, session: AsyncClientSession | None = None
240
- ) -> None:
255
+ def __init__(self, db: MongoDBManager) -> None:
241
256
  self._db = db
242
- self._session = session
257
+ self._session = None
243
258
  self._document_type = None
244
259
 
245
260
  @property
@@ -254,6 +269,15 @@ class RepositoryBase(Generic[T]):
254
269
  def session(self) -> AsyncClientSession | None:
255
270
  return self._session
256
271
 
272
+ @session.setter
273
+ def session(self, session: AsyncClientSession) -> None:
274
+ if session.has_ended:
275
+ raise RuntimeError(
276
+ f"session with id {session.session_id} has already ended"
277
+ )
278
+
279
+ self._session = session
280
+
257
281
  @property
258
282
  def document_type(self) -> type[T]:
259
283
  document_type = self._document_type
@@ -364,25 +388,28 @@ class RepositoryBase(Generic[T]):
364
388
  session: AsyncClientSession | None = None,
365
389
  ) -> T | P | None:
366
390
  if projection is not None:
367
- return projection.from_raw_projected_document(
368
- await self.collection.find_one(
369
- filter=filter,
370
- projection=projection.get_projection(),
371
- skip=skip,
372
- sort=sort,
373
- session=session or self.session,
374
- )
391
+ document = await self.collection.find_one(
392
+ filter=filter,
393
+ projection=projection.get_projection(),
394
+ skip=skip,
395
+ sort=sort,
396
+ session=session or self.session,
375
397
  )
376
-
377
- return self.document_type.from_raw_document(
378
- await self.collection.find_one(
398
+ else:
399
+ document = await self.collection.find_one(
379
400
  filter=filter,
380
- projection=projection,
381
401
  skip=skip,
382
402
  sort=sort,
383
403
  session=session or self.session,
384
404
  )
385
- )
405
+
406
+ if document is None:
407
+ return None
408
+
409
+ if projection is not None:
410
+ return projection.from_raw_projected_document(document)
411
+
412
+ return self.document_type.from_raw_document(document)
386
413
 
387
414
  async def replace(
388
415
  self, replacement: T, session: AsyncClientSession | None = None
@@ -1,3 +1,5 @@
1
+ from pydantic import Field
2
+
1
3
  from ._inbound import (
2
4
  CamelCaseInboundMessage,
3
5
  InboundMessage,
@@ -12,6 +14,7 @@ from ._outbound import (
12
14
  __all__ = [
13
15
  "CamelCaseInboundMessage",
14
16
  "CamelCaseOutboundMessage",
17
+ "Field",
15
18
  "InboundMessage",
16
19
  "OutboundMessage",
17
20
  "SnakeCaseInboundMessage",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qena-shared-lib
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: A shared tools for other services
5
5
  Requires-Dist: fastapi[all]==0.115.6
6
6
  Requires-Dist: prometheus-client==0.21.1
@@ -10,7 +10,7 @@ qena_shared_lib/enums.py,sha256=qYOZUD8Or0O1uGoNRShMp-SzmkXDQ31djMVTG_yGxL4,107
10
10
  qena_shared_lib/eventbus.py,sha256=Qk4TiJHGlnUNQkLTIWEuHe3MPyRmwUmkjbk5Y4dNSxE,11501
11
11
  qena_shared_lib/exception_handling.py,sha256=oiPVaxD74y-dbB8hJsncPNd-Fphot60Q60tZQTbCZ50,13392
12
12
  qena_shared_lib/exceptions.py,sha256=pByxZnxesxLVyHF2ARd0C0ioWLYZZVOtxPytJnF5EDo,14567
13
- qena_shared_lib/http/__init__.py,sha256=nZmSw7Al8OawmDPsQ4i33DCbLOEcrSY7gMo1JArt7Ug,2014
13
+ qena_shared_lib/http/__init__.py,sha256=F6CqzPsRx55fa5ozRkk2lSNJu28KPw9uI8zQwoo4lVU,2055
14
14
  qena_shared_lib/http/_base.py,sha256=5jPAjiDmJIxjtMdhxNHpcTM_xbXC5eBMvy3U0tpB25Q,25199
15
15
  qena_shared_lib/http/_exception_handlers.py,sha256=fkxW7KqyCy923f4f6s1qmd8gO-Oaoi-mLR9gaIWC-PU,6265
16
16
  qena_shared_lib/http/_request.py,sha256=kppCnS5zZfvKl-hNO6ysqkVdtoXshFp6Ue_0O5apqXQ,426
@@ -21,7 +21,7 @@ qena_shared_lib/kafka/_consumer.py,sha256=aEOtAqMhFPIMYbKK_BMDwR2rd_eaDzBJ6xR3Ud
21
21
  qena_shared_lib/kafka/_exception_handlers.py,sha256=D7Xh5eSpSkumQKvPfBmVB_E6vQxD58y41bFpP5Jzhqk,4084
22
22
  qena_shared_lib/kafka/_producer.py,sha256=QtYfKzNtxeIT1EtGpS-tvFC342oPoleF1AOl20LfNXs,3941
23
23
  qena_shared_lib/logging.py,sha256=HZiqbXpmJsAI7hheAaQ9EA8uj9yU0pMVCg64d_V0wzA,1748
24
- qena_shared_lib/mongodb.py,sha256=RH0wa0XopJlFdQVZdZVyknnh26vsLRv-rKR-2t_cGD0,16630
24
+ qena_shared_lib/mongodb.py,sha256=J39ttzyhL1umxIT9lQvkUOV_1uHYZQcQvrYrO9Okr8I,17109
25
25
  qena_shared_lib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  qena_shared_lib/rabbitmq/__init__.py,sha256=g15fP9XQ1CHFBXZmeAxQcsppQ0Nx62gJ4VOK8nzW7T4,1254
27
27
  qena_shared_lib/rabbitmq/_base.py,sha256=pKJL0PNrhUOXw4XUJ1iZsuCPVY3ykvO8ebIfeX9HwXo,21502
@@ -31,7 +31,7 @@ qena_shared_lib/rabbitmq/_listener.py,sha256=BwZ3YVTGI2sIMJWMoL7SnYN_RGfjBr1tYxa
31
31
  qena_shared_lib/rabbitmq/_pool.py,sha256=eEJswSoWoWzjh290doFYccn1cwQW6DgbdpHeU-7nZSg,2006
32
32
  qena_shared_lib/rabbitmq/_publisher.py,sha256=57WruxVlZemA7XVDNHSNB3_2gI-ycIKDobepLGa_QoM,2511
33
33
  qena_shared_lib/rabbitmq/_rpc_client.py,sha256=DKYvyPnmaMfa8Ymw1nLKinuFeG_H0Lc1OL8EUjN8M6U,9353
34
- qena_shared_lib/rabbitmq/message/__init__.py,sha256=HsTg8uzDFUVAnAa-HYHdl0dSwZ2gZXYrKjp7IgAXSR8,398
34
+ qena_shared_lib/rabbitmq/message/__init__.py,sha256=J0wKjSuwOC7urUffWdxGZ7x_F9S5S6EryC9NxuysOhY,439
35
35
  qena_shared_lib/rabbitmq/message/_inbound.py,sha256=v744Vr4JZn9iE4GnD8uoQQLiD9TuKGZgLIiMwIcLGp4,272
36
36
  qena_shared_lib/rabbitmq/message/_outbound.py,sha256=axf7OF2rA05ixdjM3PiHG33I3dJU2gS8GP-ooefX4Jk,274
37
37
  qena_shared_lib/redis.py,sha256=N15rYGX5iMbFvFzCnSTtOBD_EIrdZ9xkoS1Sw9s-3tI,1262
@@ -45,6 +45,6 @@ qena_shared_lib/scheduler.py,sha256=Spp5PnpFJ0U4aLeFCNmje9zUA4zwkL-b7X8SSGkGssM,
45
45
  qena_shared_lib/security.py,sha256=RAXBkfhytJl-2SOXYQTJMnUb789-8DNZKRjRtpod16Y,6372
46
46
  qena_shared_lib/sync.py,sha256=79aGGWGYg_oGY9jTav1kghD8BSRY-_oNYdx3tuExr20,2541
47
47
  qena_shared_lib/utils.py,sha256=crD8NJD1Se7ZHPCaQBCi3c7Y46lMvk8OsN_bZTbcyto,1184
48
- qena_shared_lib-0.1.19.dist-info/WHEEL,sha256=k57ZwB-NkeM_6AsPnuOHv5gI5KM5kPD6Vx85WmGEcI0,78
49
- qena_shared_lib-0.1.19.dist-info/METADATA,sha256=bUaVtmWTCPymqMS9MqOdXfE48Xi3Xrww_eNaKrcQowQ,19281
50
- qena_shared_lib-0.1.19.dist-info/RECORD,,
48
+ qena_shared_lib-0.1.21.dist-info/WHEEL,sha256=k57ZwB-NkeM_6AsPnuOHv5gI5KM5kPD6Vx85WmGEcI0,78
49
+ qena_shared_lib-0.1.21.dist-info/METADATA,sha256=kAbusp4enrIcpkobDr6LX6wna8JGcYjCtz35Q9LAs1E,19281
50
+ qena_shared_lib-0.1.21.dist-info/RECORD,,