muffin-rest 6.0.1__py3-none-any.whl → 7.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 +8 -10
- muffin_rest/mongo/__init__.py +7 -19
- muffin_rest/peewee/handler.py +3 -7
- muffin_rest/sqlalchemy/__init__.py +6 -16
- {muffin_rest-6.0.1.dist-info → muffin_rest-7.0.0.dist-info}/METADATA +1 -1
- {muffin_rest-6.0.1.dist-info → muffin_rest-7.0.0.dist-info}/RECORD +8 -8
- {muffin_rest-6.0.1.dist-info → muffin_rest-7.0.0.dist-info}/LICENSE +0 -0
- {muffin_rest-6.0.1.dist-info → muffin_rest-7.0.0.dist-info}/WHEEL +0 -0
muffin_rest/handler.py
CHANGED
|
@@ -53,7 +53,6 @@ class RESTHandlerMeta(HandlerMeta):
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
56
|
-
|
|
57
56
|
"""Load/save resources."""
|
|
58
57
|
|
|
59
58
|
auth: Any
|
|
@@ -207,20 +206,20 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
207
206
|
|
|
208
207
|
# Parse data
|
|
209
208
|
# -----------
|
|
210
|
-
|
|
209
|
+
def get_schema(
|
|
210
|
+
self, request: Request, *, resource: Optional[TVResource] = None, **options
|
|
211
|
+
) -> ma.Schema:
|
|
211
212
|
"""Initialize marshmallow schema for serialization/deserialization."""
|
|
212
|
-
assert self.meta.Schema, "RESTHandler.meta.Schema is required."
|
|
213
213
|
query = request.url.query
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
214
|
+
options.setdefault("only", query.get("schema_only"))
|
|
215
|
+
options.setdefault("exclude", query.get("schema_exclude", ()))
|
|
216
|
+
return self.meta.Schema(**options)
|
|
218
217
|
|
|
219
218
|
async def load(
|
|
220
219
|
self, request: Request, resource: Optional[TVResource] = None
|
|
221
220
|
) -> TVData[TVResource]:
|
|
222
221
|
"""Load data from request and create/update a resource."""
|
|
223
|
-
schema =
|
|
222
|
+
schema = self.get_schema(request, resource=resource)
|
|
224
223
|
return cast(
|
|
225
224
|
TVData[TVResource], await load_data(request, schema, partial=resource is not None)
|
|
226
225
|
)
|
|
@@ -244,8 +243,7 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
244
243
|
**dump_schema_opts,
|
|
245
244
|
) -> Union[TSchemaRes, List[TSchemaRes]]:
|
|
246
245
|
"""Serialize the given response."""
|
|
247
|
-
|
|
248
|
-
schema = await self.get_schema(request, resource=resource)
|
|
246
|
+
schema = self.get_schema(request)
|
|
249
247
|
return schema.dump(data, many=many, **dump_schema_opts)
|
|
250
248
|
|
|
251
249
|
async def get(self, request: Request, *, resource: Optional[TVResource] = None) -> ResponseJSON:
|
muffin_rest/mongo/__init__.py
CHANGED
|
@@ -94,26 +94,18 @@ class MongoRESTHandler(RESTHandler[TVResource]):
|
|
|
94
94
|
except InvalidId as exc:
|
|
95
95
|
raise APIError.NOT_FOUND() from exc
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
self, request: Request, resource: Optional[TVResource] = None, **
|
|
97
|
+
def get_schema(
|
|
98
|
+
self, request: Request, resource: Optional[TVResource] = None, **options
|
|
99
99
|
) -> ma.Schema:
|
|
100
100
|
"""Initialize marshmallow schema for serialization/deserialization."""
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
exclude=request.url.query.get("schema_exclude", ()),
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
async def save(
|
|
108
|
-
self, _: Request, resource: TVResource, *, update=False
|
|
109
|
-
) -> TVResource:
|
|
101
|
+
return super().get_schema(request, instance=resource, **options)
|
|
102
|
+
|
|
103
|
+
async def save(self, _: Request, resource: TVResource, *, update=False) -> TVResource:
|
|
110
104
|
"""Save the given resource."""
|
|
111
105
|
meta = self.meta
|
|
112
106
|
collection_id = meta.collection_id
|
|
113
107
|
if update:
|
|
114
|
-
await self.collection.replace_one(
|
|
115
|
-
{collection_id: resource[collection_id]}, resource
|
|
116
|
-
)
|
|
108
|
+
await self.collection.replace_one({collection_id: resource[collection_id]}, resource)
|
|
117
109
|
|
|
118
110
|
else:
|
|
119
111
|
updated = await meta.collection.insert_one(resource)
|
|
@@ -124,11 +116,7 @@ class MongoRESTHandler(RESTHandler[TVResource]):
|
|
|
124
116
|
async def delete(self, request: Request, resource: Optional[TVResource] = None):
|
|
125
117
|
"""Remove the given resource(s)."""
|
|
126
118
|
meta = self.meta
|
|
127
|
-
oids = (
|
|
128
|
-
[resource[meta.collection_id]]
|
|
129
|
-
if resource
|
|
130
|
-
else cast(List[str], await request.data())
|
|
131
|
-
)
|
|
119
|
+
oids = [resource[meta.collection_id]] if resource else cast(List[str], await request.data())
|
|
132
120
|
if not oids:
|
|
133
121
|
raise APIError.NOT_FOUND()
|
|
134
122
|
|
muffin_rest/peewee/handler.py
CHANGED
|
@@ -152,15 +152,11 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
152
152
|
async def delete(self, request: Request, resource: Optional[TVModel] = None):
|
|
153
153
|
return await self.remove(request, resource)
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
self, request: Request, resource: Optional[TVModel] = None, **
|
|
155
|
+
def get_schema(
|
|
156
|
+
self, request: Request, *, resource: Optional[TVModel] = None, **options
|
|
157
157
|
) -> ma.Schema:
|
|
158
158
|
"""Initialize marshmallow schema for serialization/deserialization."""
|
|
159
|
-
return
|
|
160
|
-
instance=resource,
|
|
161
|
-
only=request.url.query.get("schema_only"),
|
|
162
|
-
exclude=request.url.query.get("schema_exclude", ()),
|
|
163
|
-
)
|
|
159
|
+
return super().get_schema(request, instance=resource, **options)
|
|
164
160
|
|
|
165
161
|
|
|
166
162
|
class PWRESTHandler(PWRESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
@@ -35,9 +35,7 @@ class SQLAlchemyAutoSchema(BaseSQLAlchemyAutoSchema):
|
|
|
35
35
|
|
|
36
36
|
https://github.com/encode/databases/issues/72
|
|
37
37
|
"""
|
|
38
|
-
cols_to_fields = {
|
|
39
|
-
f.attribute or f.name: f for f in self.declared_fields.values()
|
|
40
|
-
}
|
|
38
|
+
cols_to_fields = {f.attribute or f.name: f for f in self.declared_fields.values()}
|
|
41
39
|
if not partial:
|
|
42
40
|
for column in self.opts.table.columns:
|
|
43
41
|
field = cols_to_fields.get(column.name)
|
|
@@ -155,19 +153,15 @@ class SARESTHandler(RESTHandler[TVResource]):
|
|
|
155
153
|
raise APIError.NOT_FOUND("Resource not found")
|
|
156
154
|
return cast(TVResource, dict(resource))
|
|
157
155
|
|
|
158
|
-
|
|
156
|
+
def get_schema(
|
|
159
157
|
self,
|
|
160
158
|
request: Request,
|
|
161
159
|
*,
|
|
162
160
|
resource: Optional[TVResource] = None,
|
|
163
|
-
**
|
|
161
|
+
**options,
|
|
164
162
|
) -> ma.Schema:
|
|
165
163
|
"""Initialize marshmallow schema for serialization/deserialization."""
|
|
166
|
-
return
|
|
167
|
-
instance=resource,
|
|
168
|
-
only=request.url.query.get("schema_only"),
|
|
169
|
-
exclude=request.url.query.get("schema_exclude", ()),
|
|
170
|
-
)
|
|
164
|
+
return super().get_schema(request, instance=resource, **options)
|
|
171
165
|
|
|
172
166
|
async def save(self, _: Request, resource: TVData[TVResource], *, update=False):
|
|
173
167
|
"""Save the given resource."""
|
|
@@ -175,15 +169,11 @@ class SARESTHandler(RESTHandler[TVResource]):
|
|
|
175
169
|
insert_query = meta.table.insert()
|
|
176
170
|
table_pk = cast(sa.Column, meta.table_pk)
|
|
177
171
|
if update:
|
|
178
|
-
update_query = self.meta.table.update().where(
|
|
179
|
-
table_pk == resource[table_pk.name]
|
|
180
|
-
)
|
|
172
|
+
update_query = self.meta.table.update().where(table_pk == resource[table_pk.name])
|
|
181
173
|
await meta.database.execute(update_query, resource)
|
|
182
174
|
|
|
183
175
|
else:
|
|
184
|
-
resource[table_pk.name] = await meta.database.execute(
|
|
185
|
-
insert_query, resource
|
|
186
|
-
)
|
|
176
|
+
resource[table_pk.name] = await meta.database.execute(insert_query, resource)
|
|
187
177
|
|
|
188
178
|
return resource
|
|
189
179
|
|
|
@@ -2,9 +2,9 @@ muffin_rest/__init__.py,sha256=NBZeOEJgQHtFFhVgd9d0fpApFRgU405sbm0cu1y1MOU,1242
|
|
|
2
2
|
muffin_rest/api.py,sha256=gCqRb5PgKEMkE84Y0ZnJw_laVRmVWZRxzBqBv0ns6w8,3882
|
|
3
3
|
muffin_rest/errors.py,sha256=TIXSADZYSwx70dOVPRAzuNwGLfpLuzZZ1ugMZMwIGDo,1169
|
|
4
4
|
muffin_rest/filters.py,sha256=7oO_K5s51Q8FANb_-emKKms_9LBbrHdrS1_zp7Kqcgo,5607
|
|
5
|
-
muffin_rest/handler.py,sha256=
|
|
5
|
+
muffin_rest/handler.py,sha256=6xgqFPuMXHxKcTXBl48TvzjMKBP-Bhp1AKCp8WZ1ams,10022
|
|
6
6
|
muffin_rest/marshmallow.py,sha256=hHPLTLdaSz5jTLWBqyHeOwo2xfBv7aMIuJFD_trHRuE,715
|
|
7
|
-
muffin_rest/mongo/__init__.py,sha256=
|
|
7
|
+
muffin_rest/mongo/__init__.py,sha256=uqshETgrSLY0YuHeCVXANXLpmPLXUs_2pBXA5JgteE8,4592
|
|
8
8
|
muffin_rest/mongo/filters.py,sha256=y2FleM_BqkICKGq3PmM_StOgKlE7RoSxt2NdQfCvnOE,921
|
|
9
9
|
muffin_rest/mongo/schema.py,sha256=y4OEPQnlV_COTIIQ3cKmpqDpD2r18eAWn0rijQldWm0,1205
|
|
10
10
|
muffin_rest/mongo/sorting.py,sha256=iJBnaFwE7g_JMwpGpQkoqSqbQK9XULx1K3skiRRgLgY,870
|
|
@@ -14,7 +14,7 @@ muffin_rest/openapi.py,sha256=XNhU4EffbKvFKr1HMCqFM-ZrukPqLyZwm3aJe2dNs40,8770
|
|
|
14
14
|
muffin_rest/options.py,sha256=PcrGY1qq3exgOdeJp8tYYC2V83c5vVMQrARgUkxrNTM,1927
|
|
15
15
|
muffin_rest/peewee/__init__.py,sha256=94DSj_ftT6fbPksHlBv40AH2HWaiZommUFOMN2jd9a4,129
|
|
16
16
|
muffin_rest/peewee/filters.py,sha256=ziqpD7uH9vzx_yHKUpOYmduNmM8w-8b7CtRaSoCqECU,2382
|
|
17
|
-
muffin_rest/peewee/handler.py,sha256=
|
|
17
|
+
muffin_rest/peewee/handler.py,sha256=oUkPFfNQT2vg5duptwFBldQZjHY_W3DFHQKoyhOLTk0,5260
|
|
18
18
|
muffin_rest/peewee/openapi.py,sha256=ZZuh7nJVuK9cTJqtOJ_XASe9iJgter-xIjj9YJ8xszI,1111
|
|
19
19
|
muffin_rest/peewee/options.py,sha256=02E8yOXHaHl0smKV8qI6er7YS3IcuroDPl7GR_YuLjo,1489
|
|
20
20
|
muffin_rest/peewee/schemas.py,sha256=6xaNxKFpdXjoiPFI9yc0tBN7B535A2IFLRE9x6unrZM,1215
|
|
@@ -24,14 +24,14 @@ muffin_rest/peewee/utils.py,sha256=wXeneVE1IZl1ROnY28re73H62Y1_tEmoEQYzPhuOyBI,7
|
|
|
24
24
|
muffin_rest/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
25
|
muffin_rest/redoc.html,sha256=GtuHIMvTuSi8Ro6bgI-G8VB94AljMyfjcZseqtBmGCY,559
|
|
26
26
|
muffin_rest/sorting.py,sha256=x-3UE9MMV7RzmNDTIgsM1RDVd42mPeq03LbkaaKuM4g,2803
|
|
27
|
-
muffin_rest/sqlalchemy/__init__.py,sha256=
|
|
27
|
+
muffin_rest/sqlalchemy/__init__.py,sha256=Kjov2jNe2nNW30oEwGrJwR8hhmjTqyQFHGHLhTIJTt4,6311
|
|
28
28
|
muffin_rest/sqlalchemy/filters.py,sha256=bTT7ndx_d0YaDSviDfpzwN9T46dQrV9WbeG8YH9KVBg,2466
|
|
29
29
|
muffin_rest/sqlalchemy/sorting.py,sha256=YlFKpIet4TUy7fJ2UBLC8b9lAOwY66QBpPDDApbyh8M,1643
|
|
30
30
|
muffin_rest/sqlalchemy/types.py,sha256=JnIw44XJ2ClWzOv-mTUrvFw1JPxAlvdX_jf7r4zau-s,204
|
|
31
31
|
muffin_rest/swagger.html,sha256=2uGLu_KpkYf925KnDKHBJmV9pm6OHn5C3BWScESsUS8,1736
|
|
32
32
|
muffin_rest/types.py,sha256=vy55ShzMcvs9zXjFpdjWlagv09dMrcmxb2-U4hTL3NM,521
|
|
33
33
|
muffin_rest/utils.py,sha256=-nf6WCGFlVoOcBT-n6eiIpbZSmPY8ynm2UlMelgmn8o,2059
|
|
34
|
-
muffin_rest-
|
|
35
|
-
muffin_rest-
|
|
36
|
-
muffin_rest-
|
|
37
|
-
muffin_rest-
|
|
34
|
+
muffin_rest-7.0.0.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
|
35
|
+
muffin_rest-7.0.0.dist-info/METADATA,sha256=SkWzF-CDKJxm7UJV_IoIO4VQ1S_T1EqWs1Mf7QQDd60,4126
|
|
36
|
+
muffin_rest-7.0.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
37
|
+
muffin_rest-7.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|