muffin-rest 12.0.2__tar.gz → 13.0.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.
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/PKG-INFO +1 -1
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/handler.py +2 -2
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/__init__.py +6 -6
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/openapi.py +1 -1
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/handler.py +9 -9
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/openapi.py +1 -1
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/sqlalchemy/__init__.py +8 -8
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/pyproject.toml +1 -1
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/LICENSE +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/README.md +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/__init__.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/api.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/errors.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/filters.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/limits.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/marshmallow.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/filters.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/schema.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/sorting.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/types.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/mongo/utils.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/options.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/__init__.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/filters.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/options.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/schemas.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/sorting.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/types.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/peewee/utils.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/py.typed +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/redoc.html +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/schemas.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/sorting.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/sqlalchemy/filters.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/sqlalchemy/sorting.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/sqlalchemy/types.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/swagger.html +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/types.py +0 -0
- {muffin_rest-12.0.2 → muffin_rest-13.0.1}/muffin_rest/utils.py +0 -0
|
@@ -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 }/{{
|
|
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("
|
|
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."""
|
|
@@ -52,12 +52,12 @@ class MongoRESTHandler(RESTHandler[TVResource]):
|
|
|
52
52
|
meta: MongoRESTOptions
|
|
53
53
|
meta_class: type[MongoRESTOptions] = MongoRESTOptions
|
|
54
54
|
|
|
55
|
-
async def prepare_collection(self,
|
|
55
|
+
async def prepare_collection(self, request: Request) -> MongoChain:
|
|
56
56
|
"""Initialize Peeewee QuerySet for a binded to the resource model."""
|
|
57
57
|
return MongoChain(self.meta.collection)
|
|
58
58
|
|
|
59
59
|
async def paginate(
|
|
60
|
-
self,
|
|
60
|
+
self, request: Request, *, limit: int = 0, offset: int = 0
|
|
61
61
|
) -> tuple[motor.AsyncIOMotorCursor, int | None]:
|
|
62
62
|
"""Paginate collection."""
|
|
63
63
|
if self.meta.aggregate:
|
|
@@ -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
|
-
|
|
90
|
-
if not
|
|
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(
|
|
95
|
+
{self.meta.collection_id: bson.ObjectId(key)},
|
|
96
96
|
)
|
|
97
97
|
except InvalidId as exc:
|
|
98
98
|
raise APIError.NOT_FOUND() from exc
|
|
@@ -103,7 +103,7 @@ class MongoRESTHandler(RESTHandler[TVResource]):
|
|
|
103
103
|
"""Initialize marshmallow schema for serialization/deserialization."""
|
|
104
104
|
return super().get_schema(request, instance=resource, **schema_options)
|
|
105
105
|
|
|
106
|
-
async def save(self,
|
|
106
|
+
async def save(self, request: Request, resource: TVResource, *, update=False) -> TVResource:
|
|
107
107
|
"""Save the given resource."""
|
|
108
108
|
meta = self.meta
|
|
109
109
|
collection_id = meta.collection_id
|
|
@@ -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("
|
|
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"] = []
|
|
@@ -42,31 +42,31 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
42
42
|
@overload
|
|
43
43
|
async def prepare_collection(
|
|
44
44
|
self: PWRESTBase[TVAIOModel],
|
|
45
|
-
|
|
45
|
+
request: Request,
|
|
46
46
|
) -> AIOModelSelect[TVAIOModel]: ...
|
|
47
47
|
|
|
48
48
|
@overload
|
|
49
49
|
async def prepare_collection(
|
|
50
50
|
self: PWRESTBase[pw.Model],
|
|
51
|
-
|
|
51
|
+
request: Request,
|
|
52
52
|
) -> pw.ModelSelect: ...
|
|
53
53
|
|
|
54
54
|
# NOTE: there is not a default sorting for peewee (conflict with muffin-admin)
|
|
55
|
-
async def prepare_collection(self,
|
|
55
|
+
async def prepare_collection(self, request: Request):
|
|
56
56
|
"""Initialize Peeewee QuerySet for a binded to the resource model."""
|
|
57
57
|
return self.meta.model.select()
|
|
58
58
|
|
|
59
59
|
async def prepare_resource(self, request: Request) -> TVModel | None:
|
|
60
60
|
"""Load a resource."""
|
|
61
|
-
|
|
62
|
-
if not
|
|
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 ==
|
|
69
|
+
self.collection.where(meta.model_pk == key),
|
|
70
70
|
)
|
|
71
71
|
except Exception: # noqa: BLE001
|
|
72
72
|
resource = None
|
|
@@ -78,15 +78,15 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
78
78
|
|
|
79
79
|
@overload
|
|
80
80
|
async def paginate(
|
|
81
|
-
self: PWRESTBase[TVAIOModel],
|
|
81
|
+
self: PWRESTBase[TVAIOModel], request: Request, *, limit: int = 0, offset: int = 0
|
|
82
82
|
) -> tuple[AIOModelSelect[TVAIOModel], int | None]: ...
|
|
83
83
|
|
|
84
84
|
@overload
|
|
85
85
|
async def paginate(
|
|
86
|
-
self: PWRESTBase[pw.Model],
|
|
86
|
+
self: PWRESTBase[pw.Model], request: Request, *, limit: int = 0, offset: int = 0
|
|
87
87
|
) -> tuple[pw.ModelSelect, int | None]: ...
|
|
88
88
|
|
|
89
|
-
async def paginate(self,
|
|
89
|
+
async def paginate(self, request: Request, *, limit: int = 0, offset: int = 0):
|
|
90
90
|
"""Paginate the collection."""
|
|
91
91
|
if self.meta.limit_total:
|
|
92
92
|
cqs = cast("pw.ModelSelect", self.collection.order_by())
|
|
@@ -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("
|
|
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"] = {
|
|
@@ -114,13 +114,13 @@ class SARESTHandler(RESTHandler[TVResource]):
|
|
|
114
114
|
meta_class: type[SARESTOptions] = SARESTOptions
|
|
115
115
|
collection: sa.sql.Select
|
|
116
116
|
|
|
117
|
-
async def prepare_collection(self,
|
|
117
|
+
async def prepare_collection(self, request: Request) -> sa.sql.Select:
|
|
118
118
|
"""Initialize Peeewee QuerySet for a binded to the resource model."""
|
|
119
119
|
return self.meta.table.select()
|
|
120
120
|
|
|
121
121
|
async def paginate(
|
|
122
122
|
self,
|
|
123
|
-
|
|
123
|
+
request: Request,
|
|
124
124
|
*,
|
|
125
125
|
limit: int = 0,
|
|
126
126
|
offset: int = 0,
|
|
@@ -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
|
-
|
|
147
|
-
if not
|
|
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 ==
|
|
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
|
-
|
|
180
|
-
if not
|
|
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]",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|