muffin-rest 12.0.3__py3-none-any.whl → 13.0.1__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.
muffin_rest/handler.py CHANGED
@@ -82,7 +82,7 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
82
82
 
83
83
  else:
84
84
  router.bind(cls, f"/{ cls.meta.name }", methods=methods, **params)
85
- router.bind(cls, f"/{ cls.meta.name }/{{pk}}", methods=methods, **params)
85
+ router.bind(cls, f"/{ cls.meta.name }/{{id}}", methods=methods, **params)
86
86
 
87
87
  for _, method in inspect.getmembers(cls, lambda m: hasattr(m, "__route__")):
88
88
  paths, methods = method.__route__
@@ -147,7 +147,7 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
147
147
 
148
148
  async def prepare_resource(self, request: Request) -> Any:
149
149
  """Load a resource."""
150
- return request["path_params"].get("pk")
150
+ return request["path_params"].get("id")
151
151
 
152
152
  async def filter(self, request: Request, collection: TVCollection) -> tuple[TVCollection, Any]:
153
153
  """Filter the collection."""
@@ -86,13 +86,13 @@ class MongoRESTHandler(RESTHandler[TVResource]):
86
86
 
87
87
  async def prepare_resource(self, request: Request) -> TVResource | None:
88
88
  """Load a resource."""
89
- pk = request["path_params"].get("pk")
90
- if not pk:
89
+ key = request["path_params"].get("id")
90
+ if not key:
91
91
  return None
92
92
 
93
93
  try:
94
94
  return await self.collection.find_one(
95
- {self.meta.collection_id: bson.ObjectId(pk)},
95
+ {self.meta.collection_id: bson.ObjectId(key)},
96
96
  )
97
97
  except InvalidId as exc:
98
98
  raise APIError.NOT_FOUND() from exc
muffin_rest/openapi.py CHANGED
@@ -199,7 +199,7 @@ class OpenAPIMixin:
199
199
  schema_ref = {"$ref": f"#/components/schemas/{ meta.Schema.__name__ }"}
200
200
  for method in route_to_methods(route):
201
201
  operations[method] = {"tags": [tags[cls]]}
202
- is_resource_route = isinstance(route, DynamicRoute) and route.params.get("pk")
202
+ is_resource_route = isinstance(route, DynamicRoute) and route.params.get("id")
203
203
 
204
204
  if method == "get" and not is_resource_route:
205
205
  operations[method]["parameters"] = []
@@ -58,15 +58,15 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
58
58
 
59
59
  async def prepare_resource(self, request: Request) -> TVModel | None:
60
60
  """Load a resource."""
61
- pk = request["path_params"].get("pk")
62
- if not pk:
61
+ key = request["path_params"].get("id")
62
+ if not key:
63
63
  return None
64
64
 
65
65
  meta = self.meta
66
66
 
67
67
  try:
68
68
  resource = await meta.manager.fetchone(
69
- self.collection.where(meta.model_pk == pk),
69
+ self.collection.where(meta.model_pk == key),
70
70
  )
71
71
  except Exception: # noqa: BLE001
72
72
  resource = None
@@ -22,7 +22,7 @@ class PeeweeOpenAPIMixin(OpenAPIMixin):
22
22
  def openapi(cls, route: Route, spec: APISpec, tags: dict) -> dict:
23
23
  """Get openapi specs for the endpoint."""
24
24
  operations = super(PeeweeOpenAPIMixin, cls).openapi(route, spec, tags)
25
- is_resource_route = getattr(route, "params", {}).get("pk")
25
+ is_resource_route = getattr(route, "params", {}).get("id")
26
26
  if not is_resource_route and "delete" in operations:
27
27
  operations["delete"].setdefault("parameters", [])
28
28
  operations["delete"]["requestBody"] = {
@@ -143,11 +143,11 @@ class SARESTHandler(RESTHandler[TVResource]):
143
143
 
144
144
  async def prepare_resource(self, request: Request) -> TVResource | None:
145
145
  """Load a resource."""
146
- pk = request["path_params"].get("pk")
147
- if not pk:
146
+ key = request["path_params"].get("id")
147
+ if not key:
148
148
  return None
149
149
 
150
- qs = self.collection.where(self.meta.table_pk == pk)
150
+ qs = self.collection.where(self.meta.table_pk == key)
151
151
  resource = await self.meta.database.fetch_one(qs)
152
152
  if resource is None:
153
153
  raise APIError.NOT_FOUND("Resource not found")
@@ -176,11 +176,11 @@ class SARESTHandler(RESTHandler[TVResource]):
176
176
  async def remove(self, request: Request, resource: TVResource | None = None):
177
177
  """Remove the given resource."""
178
178
  table_pk = cast("sa.Column", self.meta.table_pk)
179
- pks = [resource[table_pk.name]] if resource else await request.data()
180
- if not pks:
179
+ keys = [resource[table_pk.name]] if resource else await request.data()
180
+ if not keys:
181
181
  raise APIError.NOT_FOUND()
182
182
 
183
- delete = self.meta.table.delete().where(table_pk.in_(cast("list[Any]", pks)))
183
+ delete = self.meta.table.delete().where(table_pk.in_(cast("list[Any]", keys)))
184
184
  await self.meta.database.execute(delete)
185
185
 
186
186
  delete = remove
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: muffin-rest
3
- Version: 12.0.3
3
+ Version: 13.0.1
4
4
  Summary: The package provides enhanced support for writing REST APIs with Muffin framework
5
5
  License: MIT
6
6
  Keywords: rest,api,muffin,asgi,asyncio,trio
@@ -2,21 +2,21 @@ muffin_rest/__init__.py,sha256=JnwsHQNDmJpOqETeIjjPheG891T5WQ0JBaiEV72Wcmg,1242
2
2
  muffin_rest/api.py,sha256=bdbXMPiZi5yXf7_u3XB_gaGDHZKzDPqnnFnrwHoO1Rs,3799
3
3
  muffin_rest/errors.py,sha256=Todg7CrCE1ufOsyyARI2Bv-RqNPH4Rl1p-Tkpq7VYrA,1151
4
4
  muffin_rest/filters.py,sha256=nWlwDLuId-mmP3tgZjp1joYCVx0k9ekV42fPIMMKphM,5920
5
- muffin_rest/handler.py,sha256=qpG4ioIagdYqGFOrlT7pBx-0czgS2ZI3AvqKXz9EzcA,10762
5
+ muffin_rest/handler.py,sha256=97nkx5rGB2CE_7oPG4UOLVw7b4UcGbubkSt1m_LrHhk,10762
6
6
  muffin_rest/limits.py,sha256=Fnlu4Wj3B-BzpahLK-rDbd1GEd7CEQ3zxyOD0vee7GE,2007
7
7
  muffin_rest/marshmallow.py,sha256=-MyMKiaMTfiWw4y-4adpfoQd05HV1vEKqSXJh8eD3xg,548
8
- muffin_rest/mongo/__init__.py,sha256=xKwIJtDhQFZBmLUWZrZox9ootK3S4UVy0EZ14oF0L20,4662
8
+ muffin_rest/mongo/__init__.py,sha256=dck5zDEv0P3v_2CdlPI7Nbg8xay-EIzy9Y0yksEZkxw,4665
9
9
  muffin_rest/mongo/filters.py,sha256=yIxIDVqMn6SoDgVhCqiTxYetw0hoaf_3jIvX2Vnizok,964
10
10
  muffin_rest/mongo/schema.py,sha256=y4OEPQnlV_COTIIQ3cKmpqDpD2r18eAWn0rijQldWm0,1205
11
11
  muffin_rest/mongo/sorting.py,sha256=iJBnaFwE7g_JMwpGpQkoqSqbQK9XULx1K3skiRRgLgY,870
12
12
  muffin_rest/mongo/types.py,sha256=jaODScgwwYbzHis3DY4bPzU1ahiMJMSwquH5_Thi-Gg,200
13
13
  muffin_rest/mongo/utils.py,sha256=jirD2Hxk28Wadpq_F08t40dYBygq6W1_0cD3261kCgo,3949
14
- muffin_rest/openapi.py,sha256=VrkyZr_T0ykAQsvkFQ_yarZ-Zs55AmAGf4aNLsUdjGA,8715
14
+ muffin_rest/openapi.py,sha256=FDHhgzsrCMEjUY63ro4CBlYHpPQHlYJRWRnzF9GyTw4,8715
15
15
  muffin_rest/options.py,sha256=Mzv0mq6YylL6cNtad9JhEhkmA4RgmDsu-On2hn5VEiw,2208
16
16
  muffin_rest/peewee/__init__.py,sha256=94DSj_ftT6fbPksHlBv40AH2HWaiZommUFOMN2jd9a4,129
17
17
  muffin_rest/peewee/filters.py,sha256=8CqleDEn4vVQvBLXEaGOjM2N7sY117EQ4GThPhlDPE8,2494
18
- muffin_rest/peewee/handler.py,sha256=MhRYQokaEt-NIrMdFiJLcZwp4h0A5LKCwHOb36vm5m0,5402
19
- muffin_rest/peewee/openapi.py,sha256=ktgsmB9wFNvcTbTaDkMQFLdQxk3osDFW5LkUSFVjcQo,1093
18
+ muffin_rest/peewee/handler.py,sha256=xepN3ydOBbNbZBWkGJf4HqIXq-nXmu23JA2pGyHkHkw,5405
19
+ muffin_rest/peewee/openapi.py,sha256=4E97_muocjBOTw0rL7lc1CRnQEg-vLI9H_Tu_vOuag0,1093
20
20
  muffin_rest/peewee/options.py,sha256=TimJtErC9e8B7BRiEkHiBZd71_bZbYr-FE2PIlQvfH0,1455
21
21
  muffin_rest/peewee/schemas.py,sha256=hQG2UKR7gEMsz0n75L3tvkVzUX3baXMJ94emgIc1Scw,439
22
22
  muffin_rest/peewee/sorting.py,sha256=aBtQkj3iSo6XjBZ8evJuprIkhv1nHFi7wFb0an6Dn34,1963
@@ -26,14 +26,14 @@ muffin_rest/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  muffin_rest/redoc.html,sha256=GtuHIMvTuSi8Ro6bgI-G8VB94AljMyfjcZseqtBmGCY,559
27
27
  muffin_rest/schemas.py,sha256=BW3dF82C6Q6STs4tZjej1x8Ii1rI3EZUJZR4mNNKmu4,875
28
28
  muffin_rest/sorting.py,sha256=nu4SGW5uxLETJIywE-1UTCCya9QAvYWcq-P8dPWQixI,2822
29
- muffin_rest/sqlalchemy/__init__.py,sha256=GMtnX3C5H9okEYjkaTHXd6Wna8F1Y6YAr1upT-cFOiM,6335
29
+ muffin_rest/sqlalchemy/__init__.py,sha256=xeOJZ9apF9wc3jezgKW8m2FWpQk8JR1NJXrC7Pp9Duk,6341
30
30
  muffin_rest/sqlalchemy/filters.py,sha256=Lf1nPOQjDT7Nv1HAwowfWYTHWCrIMpw-4aWwoaNVlVU,2475
31
31
  muffin_rest/sqlalchemy/sorting.py,sha256=qmzP18ongriCGs2Ok_OllEybqWgppU-Kakg0JL1DM_M,1690
32
32
  muffin_rest/sqlalchemy/types.py,sha256=Exm-zAQCtPAwXvYcCTtPRqSa-wTEWRcH_v2YSsJkB6s,198
33
33
  muffin_rest/swagger.html,sha256=2uGLu_KpkYf925KnDKHBJmV9pm6OHn5C3BWScESsUS8,1736
34
34
  muffin_rest/types.py,sha256=5NY9gPTIptv6U2Qab2xMXlS_jZuTuR0bquFFwWRURcA,510
35
35
  muffin_rest/utils.py,sha256=c08E4HJ4SLYC-91GKPEbsyKTZ4sZbTN4qDqJbNg_HTE,2076
36
- muffin_rest-12.0.3.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
37
- muffin_rest-12.0.3.dist-info/METADATA,sha256=T3T6CJgnSSKsPNuRdmtGt5rOxG1X88KXopVorg7SldQ,4912
38
- muffin_rest-12.0.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
39
- muffin_rest-12.0.3.dist-info/RECORD,,
36
+ muffin_rest-13.0.1.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
37
+ muffin_rest-13.0.1.dist-info/METADATA,sha256=314stUC6_wkJlpM9Ms8IJqiodDBH3eojfuQwq6mvH_8,4912
38
+ muffin_rest-13.0.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
39
+ muffin_rest-13.0.1.dist-info/RECORD,,