muffin-rest 10.0.0__py3-none-any.whl → 11.0.0__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 +12 -3
- muffin_rest/marshmallow.py +4 -10
- muffin_rest/peewee/handler.py +8 -12
- {muffin_rest-10.0.0.dist-info → muffin_rest-11.0.0.dist-info}/METADATA +1 -1
- {muffin_rest-10.0.0.dist-info → muffin_rest-11.0.0.dist-info}/RECORD +7 -7
- {muffin_rest-10.0.0.dist-info → muffin_rest-11.0.0.dist-info}/WHEEL +1 -1
- {muffin_rest-10.0.0.dist-info → muffin_rest-11.0.0.dist-info}/LICENSE +0 -0
muffin_rest/handler.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import (
|
|
|
8
8
|
Generic,
|
|
9
9
|
Iterable,
|
|
10
10
|
Literal,
|
|
11
|
+
Mapping,
|
|
11
12
|
Optional,
|
|
12
13
|
Sequence,
|
|
13
14
|
Union,
|
|
@@ -222,14 +223,22 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
222
223
|
schema_options.setdefault("exclude", query.get("schema_exclude", ()))
|
|
223
224
|
return self.meta.Schema(**schema_options)
|
|
224
225
|
|
|
226
|
+
async def load_data(self, request: Request):
|
|
227
|
+
"""Load data from request and create/update a resource."""
|
|
228
|
+
try:
|
|
229
|
+
data = await request.data(raise_errors=True)
|
|
230
|
+
except (ValueError, TypeError) as err:
|
|
231
|
+
raise APIError.BAD_REQUEST(str(err)) from err
|
|
232
|
+
|
|
233
|
+
return data
|
|
234
|
+
|
|
225
235
|
async def load(
|
|
226
236
|
self, request: Request, resource: Optional[TVResource] = None, **schema_options
|
|
227
237
|
) -> TVData[TVResource]:
|
|
228
238
|
"""Load data from request and create/update a resource."""
|
|
229
239
|
schema = self.get_schema(request, resource=resource, **schema_options)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
)
|
|
240
|
+
data = cast(Union[Mapping, list], await self.load_data(request))
|
|
241
|
+
return cast(TVData[TVResource], await load_data(data, schema, partial=resource is not None))
|
|
233
242
|
|
|
234
243
|
@overload
|
|
235
244
|
async def dump( # type: ignore[misc]
|
muffin_rest/marshmallow.py
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from typing import TYPE_CHECKING, Optional, Union, cast
|
|
3
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
5
4
|
|
|
6
5
|
from marshmallow import Schema, ValidationError
|
|
7
6
|
|
|
8
7
|
from muffin_rest.errors import APIError
|
|
9
8
|
|
|
10
9
|
if TYPE_CHECKING:
|
|
11
|
-
from
|
|
10
|
+
from collections.abc import Mapping
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
async def load_data(
|
|
15
|
-
try:
|
|
16
|
-
data = await request.data(raise_errors=True)
|
|
17
|
-
except (ValueError, TypeError) as err:
|
|
18
|
-
raise APIError.BAD_REQUEST(str(err)) from err
|
|
19
|
-
|
|
13
|
+
async def load_data(data: Union[Mapping, list], schema: Optional[Schema] = None, **params):
|
|
20
14
|
if schema is None:
|
|
21
15
|
return data
|
|
22
16
|
|
|
23
17
|
try:
|
|
24
|
-
return schema.load(
|
|
18
|
+
return schema.load(data, many=isinstance(data, list), **params)
|
|
25
19
|
except ValidationError as err:
|
|
26
20
|
raise APIError.BAD_REQUEST("Bad request data", errors=err.messages) from err
|
muffin_rest/peewee/handler.py
CHANGED
|
@@ -43,15 +43,13 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
43
43
|
async def prepare_collection(
|
|
44
44
|
self: PWRESTBase[TVAIOModel],
|
|
45
45
|
_: Request,
|
|
46
|
-
) -> AIOModelSelect[TVAIOModel]:
|
|
47
|
-
...
|
|
46
|
+
) -> AIOModelSelect[TVAIOModel]: ...
|
|
48
47
|
|
|
49
48
|
@overload
|
|
50
49
|
async def prepare_collection(
|
|
51
50
|
self: PWRESTBase[pw.Model],
|
|
52
51
|
_: Request,
|
|
53
|
-
) -> pw.ModelSelect:
|
|
54
|
-
...
|
|
52
|
+
) -> pw.ModelSelect: ...
|
|
55
53
|
|
|
56
54
|
# NOTE: there is not a default sorting for peewee (conflict with muffin-admin)
|
|
57
55
|
async def prepare_collection(self, _: Request):
|
|
@@ -81,14 +79,12 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
81
79
|
@overload
|
|
82
80
|
async def paginate(
|
|
83
81
|
self: PWRESTBase[TVAIOModel], _: Request, *, limit: int = 0, offset: int = 0
|
|
84
|
-
) -> tuple[AIOModelSelect[TVAIOModel], int | None]:
|
|
85
|
-
...
|
|
82
|
+
) -> tuple[AIOModelSelect[TVAIOModel], int | None]: ...
|
|
86
83
|
|
|
87
84
|
@overload
|
|
88
85
|
async def paginate(
|
|
89
86
|
self: PWRESTBase[pw.Model], _: Request, *, limit: int = 0, offset: int = 0
|
|
90
|
-
) -> tuple[pw.ModelSelect, int | None]:
|
|
91
|
-
...
|
|
87
|
+
) -> tuple[pw.ModelSelect, int | None]: ...
|
|
92
88
|
|
|
93
89
|
async def paginate(self, _: Request, *, limit: int = 0, offset: int = 0):
|
|
94
90
|
"""Paginate the collection."""
|
|
@@ -136,9 +132,7 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
136
132
|
return
|
|
137
133
|
|
|
138
134
|
model_pk = cast(pw.Field, meta.model_pk)
|
|
139
|
-
resources = await meta.manager.fetchall(
|
|
140
|
-
self.collection.where(model_pk << data),
|
|
141
|
-
)
|
|
135
|
+
resources = await meta.manager.fetchall(self.collection.where(model_pk << data)) # type: ignore[]
|
|
142
136
|
|
|
143
137
|
if not resources:
|
|
144
138
|
raise APIError.NOT_FOUND()
|
|
@@ -151,7 +145,9 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
151
145
|
for res in resources:
|
|
152
146
|
await meta.manager.delete_instance(res, recursive=meta.delete_recursive)
|
|
153
147
|
|
|
154
|
-
|
|
148
|
+
return resource.get_id() if resource else [r.get_id() for r in resources]
|
|
149
|
+
|
|
150
|
+
async def delete(self, request: Request, resource: Optional[TVModel] = None): # type: ignore[override]
|
|
155
151
|
return await self.remove(request, resource)
|
|
156
152
|
|
|
157
153
|
def get_schema(
|
|
@@ -2,9 +2,9 @@ muffin_rest/__init__.py,sha256=NBZeOEJgQHtFFhVgd9d0fpApFRgU405sbm0cu1y1MOU,1242
|
|
|
2
2
|
muffin_rest/api.py,sha256=zssoHjqTsa8UCAyxj6TxQVluYPX9Sigyiph6SRxBY6I,3870
|
|
3
3
|
muffin_rest/errors.py,sha256=mxEBhNPo3pwpG2em6zaQonbfRgHFBJ3I8WunVYWDjvM,1163
|
|
4
4
|
muffin_rest/filters.py,sha256=hc-fhBODwrgJM_CvXNtTVH6jIOkjLog8En0iKKYXAGU,5947
|
|
5
|
-
muffin_rest/handler.py,sha256=
|
|
5
|
+
muffin_rest/handler.py,sha256=xRKUMzR2zISva0SbXS-piQ3Xq3d1zu-rZg6H2K7Oy0I,10824
|
|
6
6
|
muffin_rest/limits.py,sha256=Fnlu4Wj3B-BzpahLK-rDbd1GEd7CEQ3zxyOD0vee7GE,2007
|
|
7
|
-
muffin_rest/marshmallow.py,sha256=
|
|
7
|
+
muffin_rest/marshmallow.py,sha256=UeHxZLtETlrheDAlMZn7Xv_7vWPxvJQo-sj05nql9gM,574
|
|
8
8
|
muffin_rest/mongo/__init__.py,sha256=SiYSbX6ySJl43fw9aGREIs8ZsS8Qk_ieizoPOj4DjJc,4656
|
|
9
9
|
muffin_rest/mongo/filters.py,sha256=yIxIDVqMn6SoDgVhCqiTxYetw0hoaf_3jIvX2Vnizok,964
|
|
10
10
|
muffin_rest/mongo/schema.py,sha256=y4OEPQnlV_COTIIQ3cKmpqDpD2r18eAWn0rijQldWm0,1205
|
|
@@ -15,7 +15,7 @@ muffin_rest/openapi.py,sha256=0QU7qrfBjGl0vl378SJC5boZZI2ogddl45fS9WL4Axw,8751
|
|
|
15
15
|
muffin_rest/options.py,sha256=38y7AasyAghXNffxX-3xgqLbWDQ1RxAhg77ze7c0Mu0,2232
|
|
16
16
|
muffin_rest/peewee/__init__.py,sha256=94DSj_ftT6fbPksHlBv40AH2HWaiZommUFOMN2jd9a4,129
|
|
17
17
|
muffin_rest/peewee/filters.py,sha256=p813eJqyTkAhmS3C1P8rWFWb9Tl33OtADjgLctqKnns,2475
|
|
18
|
-
muffin_rest/peewee/handler.py,sha256=
|
|
18
|
+
muffin_rest/peewee/handler.py,sha256=otADwlTnNkook7fNo26yNKtpTV_0OBGKT2IY0QzfdSA,5361
|
|
19
19
|
muffin_rest/peewee/openapi.py,sha256=lDnLnoXi33p0YeFVwRgaVrndyrG2XL93RH-BzbxinOY,1105
|
|
20
20
|
muffin_rest/peewee/options.py,sha256=TimJtErC9e8B7BRiEkHiBZd71_bZbYr-FE2PIlQvfH0,1455
|
|
21
21
|
muffin_rest/peewee/schemas.py,sha256=w6jBziUp40mOOjkz_4RCXuY0x5ZDIe9Ob25k1FnZSfc,469
|
|
@@ -33,7 +33,7 @@ muffin_rest/sqlalchemy/types.py,sha256=Exm-zAQCtPAwXvYcCTtPRqSa-wTEWRcH_v2YSsJkB
|
|
|
33
33
|
muffin_rest/swagger.html,sha256=2uGLu_KpkYf925KnDKHBJmV9pm6OHn5C3BWScESsUS8,1736
|
|
34
34
|
muffin_rest/types.py,sha256=m27-g6BI7qdSWGym4fWALBJa2ZpWR0_m0nlrDx7iTCo,566
|
|
35
35
|
muffin_rest/utils.py,sha256=c08E4HJ4SLYC-91GKPEbsyKTZ4sZbTN4qDqJbNg_HTE,2076
|
|
36
|
-
muffin_rest-
|
|
37
|
-
muffin_rest-
|
|
38
|
-
muffin_rest-
|
|
39
|
-
muffin_rest-
|
|
36
|
+
muffin_rest-11.0.0.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
|
37
|
+
muffin_rest-11.0.0.dist-info/METADATA,sha256=SNFRlceJDr6y9Hghj_a8GGlHz3Bmg-uwjUkzjDMmVAo,4147
|
|
38
|
+
muffin_rest-11.0.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
39
|
+
muffin_rest-11.0.0.dist-info/RECORD,,
|
|
File without changes
|