apexdevkit 1.4.1__tar.gz → 1.4.2__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.
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/PKG-INFO +1 -1
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/router.py +78 -21
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/pyproject.toml +1 -1
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/LICENSE +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/README.md +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/error.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.4.1 → apexdevkit-1.4.2}/apexdevkit/testing/rest.py +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import Annotated, Any, Iterable, Self, TypeVar
|
|
4
|
+
from typing import Annotated, Any, Callable, Iterable, Self, TypeVar
|
|
5
5
|
|
|
6
6
|
from fastapi import APIRouter, Depends, Path
|
|
7
|
+
from fastapi.requests import Request
|
|
7
8
|
from fastapi.responses import JSONResponse
|
|
8
9
|
|
|
9
10
|
from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
|
|
@@ -107,6 +108,10 @@ class PreBuiltRestfulService(RestfulServiceBuilder):
|
|
|
107
108
|
return self.service
|
|
108
109
|
|
|
109
110
|
|
|
111
|
+
def no_user(request: Request) -> None:
|
|
112
|
+
pass
|
|
113
|
+
|
|
114
|
+
|
|
110
115
|
@dataclass
|
|
111
116
|
class RestfulRouter:
|
|
112
117
|
service: RestfulService | None = None
|
|
@@ -173,7 +178,11 @@ class RestfulRouter:
|
|
|
173
178
|
|
|
174
179
|
return self
|
|
175
180
|
|
|
176
|
-
def with_create_one_endpoint(
|
|
181
|
+
def with_create_one_endpoint(
|
|
182
|
+
self,
|
|
183
|
+
is_documented: bool = True,
|
|
184
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
185
|
+
) -> Self:
|
|
177
186
|
parent_id_type = Annotated[
|
|
178
187
|
str,
|
|
179
188
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -191,9 +200,13 @@ class RestfulRouter:
|
|
|
191
200
|
response_model=self.schema.for_item(),
|
|
192
201
|
include_in_schema=is_documented,
|
|
193
202
|
)
|
|
194
|
-
def create_one(
|
|
203
|
+
def create_one(
|
|
204
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
205
|
+
parent_id: parent_id_type,
|
|
206
|
+
item: item_type,
|
|
207
|
+
) -> _Response:
|
|
195
208
|
try:
|
|
196
|
-
service = self.infra.with_parent(parent_id).build()
|
|
209
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
197
210
|
except DoesNotExistError as e:
|
|
198
211
|
return JSONResponse(
|
|
199
212
|
RestfulResponse(RestfulName(self.parent)).not_found(e), 404
|
|
@@ -208,7 +221,11 @@ class RestfulRouter:
|
|
|
208
221
|
|
|
209
222
|
return self
|
|
210
223
|
|
|
211
|
-
def with_create_many_endpoint(
|
|
224
|
+
def with_create_many_endpoint(
|
|
225
|
+
self,
|
|
226
|
+
is_documented: bool = True,
|
|
227
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
228
|
+
) -> Self:
|
|
212
229
|
parent_id_type = Annotated[
|
|
213
230
|
str,
|
|
214
231
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -226,9 +243,13 @@ class RestfulRouter:
|
|
|
226
243
|
response_model=self.schema.for_collection(),
|
|
227
244
|
include_in_schema=is_documented,
|
|
228
245
|
)
|
|
229
|
-
def create_many(
|
|
246
|
+
def create_many(
|
|
247
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
248
|
+
parent_id: parent_id_type,
|
|
249
|
+
items: collection_type,
|
|
250
|
+
) -> _Response:
|
|
230
251
|
try:
|
|
231
|
-
service = self.infra.with_parent(parent_id).build()
|
|
252
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
232
253
|
except DoesNotExistError as e:
|
|
233
254
|
return JSONResponse(
|
|
234
255
|
RestfulResponse(RestfulName(self.parent)).not_found(e), 404
|
|
@@ -241,7 +262,11 @@ class RestfulRouter:
|
|
|
241
262
|
|
|
242
263
|
return self
|
|
243
264
|
|
|
244
|
-
def with_read_one_endpoint(
|
|
265
|
+
def with_read_one_endpoint(
|
|
266
|
+
self,
|
|
267
|
+
is_documented: bool = True,
|
|
268
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
269
|
+
) -> Self:
|
|
245
270
|
id_type = Annotated[str, Path(alias=self.id_alias)]
|
|
246
271
|
parent_id_type = Annotated[
|
|
247
272
|
str,
|
|
@@ -255,8 +280,12 @@ class RestfulRouter:
|
|
|
255
280
|
response_model=self.schema.for_item(),
|
|
256
281
|
include_in_schema=is_documented,
|
|
257
282
|
)
|
|
258
|
-
def read_one(
|
|
259
|
-
|
|
283
|
+
def read_one(
|
|
284
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
285
|
+
parent_id: parent_id_type,
|
|
286
|
+
item_id: id_type,
|
|
287
|
+
) -> _Response:
|
|
288
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
260
289
|
|
|
261
290
|
try:
|
|
262
291
|
return self.response.found_one(service.read_one(item_id))
|
|
@@ -265,7 +294,11 @@ class RestfulRouter:
|
|
|
265
294
|
|
|
266
295
|
return self
|
|
267
296
|
|
|
268
|
-
def with_read_all_endpoint(
|
|
297
|
+
def with_read_all_endpoint(
|
|
298
|
+
self,
|
|
299
|
+
is_documented: bool = True,
|
|
300
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
301
|
+
) -> Self:
|
|
269
302
|
parent_id_type = Annotated[
|
|
270
303
|
str,
|
|
271
304
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -278,14 +311,21 @@ class RestfulRouter:
|
|
|
278
311
|
response_model=self.schema.for_collection(),
|
|
279
312
|
include_in_schema=is_documented,
|
|
280
313
|
)
|
|
281
|
-
def read_all(
|
|
282
|
-
|
|
314
|
+
def read_all(
|
|
315
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
316
|
+
parent_id: parent_id_type,
|
|
317
|
+
) -> _Response:
|
|
318
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
283
319
|
|
|
284
320
|
return self.response.found_many(list(service.read_all()))
|
|
285
321
|
|
|
286
322
|
return self
|
|
287
323
|
|
|
288
|
-
def with_update_one_endpoint(
|
|
324
|
+
def with_update_one_endpoint(
|
|
325
|
+
self,
|
|
326
|
+
is_documented: bool = True,
|
|
327
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
328
|
+
) -> Self:
|
|
289
329
|
parent_id_type = Annotated[
|
|
290
330
|
str,
|
|
291
331
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -304,11 +344,12 @@ class RestfulRouter:
|
|
|
304
344
|
include_in_schema=is_documented,
|
|
305
345
|
)
|
|
306
346
|
def update_one(
|
|
347
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
307
348
|
parent_id: parent_id_type,
|
|
308
349
|
item_id: id_type,
|
|
309
350
|
updates: update_type,
|
|
310
351
|
) -> _Response:
|
|
311
|
-
service = self.infra.with_parent(parent_id).build()
|
|
352
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
312
353
|
|
|
313
354
|
try:
|
|
314
355
|
service.update_one(item_id, **updates)
|
|
@@ -321,7 +362,11 @@ class RestfulRouter:
|
|
|
321
362
|
|
|
322
363
|
return self
|
|
323
364
|
|
|
324
|
-
def with_update_many_endpoint(
|
|
365
|
+
def with_update_many_endpoint(
|
|
366
|
+
self,
|
|
367
|
+
is_documented: bool = True,
|
|
368
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
369
|
+
) -> Self:
|
|
325
370
|
parent_id_type = Annotated[
|
|
326
371
|
str,
|
|
327
372
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -338,8 +383,12 @@ class RestfulRouter:
|
|
|
338
383
|
response_model=self.schema.for_no_data(),
|
|
339
384
|
include_in_schema=is_documented,
|
|
340
385
|
)
|
|
341
|
-
def update_many(
|
|
342
|
-
|
|
386
|
+
def update_many(
|
|
387
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
388
|
+
parent_id: parent_id_type,
|
|
389
|
+
items: collection_type,
|
|
390
|
+
) -> _Response:
|
|
391
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
343
392
|
|
|
344
393
|
service.update_many(items)
|
|
345
394
|
|
|
@@ -347,7 +396,11 @@ class RestfulRouter:
|
|
|
347
396
|
|
|
348
397
|
return self
|
|
349
398
|
|
|
350
|
-
def with_delete_one_endpoint(
|
|
399
|
+
def with_delete_one_endpoint(
|
|
400
|
+
self,
|
|
401
|
+
is_documented: bool = True,
|
|
402
|
+
extract_user: Callable[[Request], Any] = no_user,
|
|
403
|
+
) -> Self:
|
|
351
404
|
parent_id_type = Annotated[
|
|
352
405
|
str,
|
|
353
406
|
Path(alias=self.parent_id_alias, default_factory=str),
|
|
@@ -361,8 +414,12 @@ class RestfulRouter:
|
|
|
361
414
|
response_model=self.schema.for_no_data(),
|
|
362
415
|
include_in_schema=is_documented,
|
|
363
416
|
)
|
|
364
|
-
def delete_one(
|
|
365
|
-
|
|
417
|
+
def delete_one(
|
|
418
|
+
user: Annotated[Any, Depends(extract_user)],
|
|
419
|
+
parent_id: parent_id_type,
|
|
420
|
+
item_id: id_type,
|
|
421
|
+
) -> _Response:
|
|
422
|
+
service = self.infra.with_user(user).with_parent(parent_id).build()
|
|
366
423
|
|
|
367
424
|
try:
|
|
368
425
|
service.delete_one(item_id)
|
|
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
|