nexo-schemas 0.0.16__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.
Files changed (69) hide show
  1. nexo/schemas/__init__.py +0 -0
  2. nexo/schemas/application.py +292 -0
  3. nexo/schemas/connection.py +134 -0
  4. nexo/schemas/data.py +27 -0
  5. nexo/schemas/document.py +237 -0
  6. nexo/schemas/error/__init__.py +476 -0
  7. nexo/schemas/error/constants.py +50 -0
  8. nexo/schemas/error/descriptor.py +354 -0
  9. nexo/schemas/error/enums.py +40 -0
  10. nexo/schemas/error/metadata.py +15 -0
  11. nexo/schemas/error/spec.py +312 -0
  12. nexo/schemas/exception/__init__.py +0 -0
  13. nexo/schemas/exception/exc.py +911 -0
  14. nexo/schemas/exception/factory.py +1928 -0
  15. nexo/schemas/exception/handlers.py +110 -0
  16. nexo/schemas/google.py +14 -0
  17. nexo/schemas/key/__init__.py +0 -0
  18. nexo/schemas/key/rsa.py +131 -0
  19. nexo/schemas/metadata.py +21 -0
  20. nexo/schemas/mixins/__init__.py +0 -0
  21. nexo/schemas/mixins/filter.py +140 -0
  22. nexo/schemas/mixins/general.py +65 -0
  23. nexo/schemas/mixins/hierarchy.py +19 -0
  24. nexo/schemas/mixins/identity.py +387 -0
  25. nexo/schemas/mixins/parameter.py +50 -0
  26. nexo/schemas/mixins/service.py +40 -0
  27. nexo/schemas/mixins/sort.py +111 -0
  28. nexo/schemas/mixins/timestamp.py +192 -0
  29. nexo/schemas/model.py +240 -0
  30. nexo/schemas/operation/__init__.py +0 -0
  31. nexo/schemas/operation/action/__init__.py +9 -0
  32. nexo/schemas/operation/action/base.py +14 -0
  33. nexo/schemas/operation/action/resource.py +371 -0
  34. nexo/schemas/operation/action/status.py +8 -0
  35. nexo/schemas/operation/action/system.py +6 -0
  36. nexo/schemas/operation/action/websocket.py +6 -0
  37. nexo/schemas/operation/base.py +289 -0
  38. nexo/schemas/operation/constants.py +18 -0
  39. nexo/schemas/operation/context.py +68 -0
  40. nexo/schemas/operation/dependency.py +26 -0
  41. nexo/schemas/operation/enums.py +168 -0
  42. nexo/schemas/operation/extractor.py +36 -0
  43. nexo/schemas/operation/mixins.py +53 -0
  44. nexo/schemas/operation/request.py +1066 -0
  45. nexo/schemas/operation/resource.py +839 -0
  46. nexo/schemas/operation/system.py +55 -0
  47. nexo/schemas/operation/websocket.py +55 -0
  48. nexo/schemas/pagination.py +67 -0
  49. nexo/schemas/parameter.py +60 -0
  50. nexo/schemas/payload.py +116 -0
  51. nexo/schemas/resource.py +64 -0
  52. nexo/schemas/response.py +1041 -0
  53. nexo/schemas/security/__init__.py +0 -0
  54. nexo/schemas/security/api_key.py +63 -0
  55. nexo/schemas/security/authentication.py +848 -0
  56. nexo/schemas/security/authorization.py +922 -0
  57. nexo/schemas/security/enums.py +32 -0
  58. nexo/schemas/security/impersonation.py +179 -0
  59. nexo/schemas/security/token.py +402 -0
  60. nexo/schemas/security/types.py +17 -0
  61. nexo/schemas/success/__init__.py +0 -0
  62. nexo/schemas/success/descriptor.py +100 -0
  63. nexo/schemas/success/enums.py +23 -0
  64. nexo/schemas/user_agent.py +46 -0
  65. nexo_schemas-0.0.16.dist-info/METADATA +87 -0
  66. nexo_schemas-0.0.16.dist-info/RECORD +69 -0
  67. nexo_schemas-0.0.16.dist-info/WHEEL +5 -0
  68. nexo_schemas-0.0.16.dist-info/licenses/LICENSE +21 -0
  69. nexo_schemas-0.0.16.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1041 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import (
3
+ Annotated,
4
+ Any,
5
+ Generic,
6
+ Literal,
7
+ Type,
8
+ TypeVar,
9
+ overload,
10
+ )
11
+ from nexo.types.boolean import BoolT
12
+ from nexo.types.dict import StrToAnyDict
13
+ from nexo.types.misc import IntOrStr, StrOrStrEnumT
14
+ from nexo.types.string import OptStr, OptListOfDoubleStrs
15
+ from .data import DataPair, AnyDataT, ModelDataT, PingData
16
+ from .error.descriptor import (
17
+ ErrorDescriptor,
18
+ BadRequestErrorDescriptor,
19
+ UnauthorizedErrorDescriptor,
20
+ ForbiddenErrorDescriptor,
21
+ NotFoundErrorDescriptor,
22
+ MethodNotAllowedErrorDescriptor,
23
+ ConflictErrorDescriptor,
24
+ UnprocessableEntityErrorDescriptor,
25
+ TooManyRequestsErrorDescriptor,
26
+ InternalServerErrorDescriptor,
27
+ NotImplementedErrorDescriptor,
28
+ BadGatewayErrorDescriptor,
29
+ ServiceUnavailableErrorDescriptor,
30
+ )
31
+ from .error.enums import ErrorCode
32
+ from .metadata import AnyMetadataT, ModelMetadataT
33
+ from .mixins.general import Success, Descriptor
34
+ from .pagination import OptPaginationT, PaginationT
35
+ from .payload import (
36
+ Payload,
37
+ NoDataPayload,
38
+ SingleDataPayload,
39
+ CreateSingleDataPayload,
40
+ ReadSingleDataPayload,
41
+ UpdateSingleDataPayload,
42
+ DeleteSingleDataPayload,
43
+ OptSingleDataPayload,
44
+ MultipleDataPayload,
45
+ CreateMultipleDataPayload,
46
+ ReadMultipleDataPayload,
47
+ UpdateMultipleDataPayload,
48
+ DeleteMultipleDataPayload,
49
+ OptMultipleDataPayload,
50
+ )
51
+ from .success.descriptor import (
52
+ SuccessDescriptor,
53
+ AnyDataSuccessDescriptor,
54
+ NoDataSuccessDescriptor,
55
+ SingleDataSuccessDescriptor,
56
+ OptSingleDataSuccessDescriptor,
57
+ CreateSingleDataSuccessDescriptor,
58
+ ReadSingleDataSuccessDescriptor,
59
+ UpdateSingleDataSuccessDescriptor,
60
+ DeleteSingleDataSuccessDescriptor,
61
+ MultipleDataSuccessDescriptor,
62
+ OptMultipleDataSuccessDescriptor,
63
+ CreateMultipleDataSuccessDescriptor,
64
+ ReadMultipleDataSuccessDescriptor,
65
+ UpdateMultipleDataSuccessDescriptor,
66
+ DeleteMultipleDataSuccessDescriptor,
67
+ )
68
+ from .success.enums import SuccessCode
69
+
70
+
71
+ class ResponseContext(BaseModel):
72
+ status_code: Annotated[int, Field(..., description="Status code")]
73
+ media_type: Annotated[OptStr, Field(None, description="Media type (Optional)")] = (
74
+ None
75
+ )
76
+ headers: Annotated[
77
+ OptListOfDoubleStrs, Field(None, description="Response's headers")
78
+ ] = None
79
+
80
+
81
+ OptResponseContext = ResponseContext | None
82
+ OptResponseContextT = TypeVar("OptResponseContextT", bound=OptResponseContext)
83
+
84
+
85
+ class ResponseContextMixin(BaseModel, Generic[OptResponseContextT]):
86
+ response_context: OptResponseContextT = Field(..., description="Response's context")
87
+
88
+
89
+ class Response(
90
+ Payload[AnyDataT, OptPaginationT, AnyMetadataT],
91
+ Descriptor[StrOrStrEnumT],
92
+ Success[BoolT],
93
+ BaseModel,
94
+ Generic[BoolT, StrOrStrEnumT, AnyDataT, OptPaginationT, AnyMetadataT],
95
+ ):
96
+ pass
97
+
98
+
99
+ OptResponse = Response | None
100
+
101
+
102
+ # Error Response
103
+ class ErrorResponse(
104
+ NoDataPayload[None],
105
+ ErrorDescriptor,
106
+ Response[Literal[False], ErrorCode, None, None, None],
107
+ ):
108
+ success: Literal[False] = False
109
+ data: None = None
110
+ pagination: None = None
111
+ metadata: None = None
112
+ other: Any = "Please try again later or contact administrator"
113
+
114
+
115
+ OptErrorResponse = ErrorResponse | None
116
+
117
+
118
+ class BadRequestResponse(
119
+ BadRequestErrorDescriptor,
120
+ ErrorResponse,
121
+ ):
122
+ pass
123
+
124
+
125
+ OptBadRequestResponse = BadRequestResponse | None
126
+
127
+
128
+ class UnauthorizedResponse(
129
+ UnauthorizedErrorDescriptor,
130
+ ErrorResponse,
131
+ ):
132
+ pass
133
+
134
+
135
+ OptUnauthorizedResponse = UnauthorizedResponse | None
136
+
137
+
138
+ class ForbiddenResponse(
139
+ ForbiddenErrorDescriptor,
140
+ ErrorResponse,
141
+ ):
142
+ pass
143
+
144
+
145
+ OptForbiddenResponse = ForbiddenResponse | None
146
+
147
+
148
+ class NotFoundResponse(
149
+ NotFoundErrorDescriptor,
150
+ ErrorResponse,
151
+ ):
152
+ pass
153
+
154
+
155
+ OptNotFoundResponse = NotFoundResponse | None
156
+
157
+
158
+ class MethodNotAllowedResponse(
159
+ MethodNotAllowedErrorDescriptor,
160
+ ErrorResponse,
161
+ ):
162
+ pass
163
+
164
+
165
+ OptMethodNotAllowedResponse = MethodNotAllowedResponse | None
166
+
167
+
168
+ class ConflictResponse(
169
+ ConflictErrorDescriptor,
170
+ ErrorResponse,
171
+ ):
172
+ pass
173
+
174
+
175
+ OptConflictResponse = ConflictResponse | None
176
+
177
+
178
+ class UnprocessableEntityResponse(
179
+ UnprocessableEntityErrorDescriptor,
180
+ ErrorResponse,
181
+ ):
182
+ pass
183
+
184
+
185
+ OptUnprocessableEntityResponse = UnprocessableEntityResponse | None
186
+
187
+
188
+ class TooManyRequestsResponse(
189
+ TooManyRequestsErrorDescriptor,
190
+ ErrorResponse,
191
+ ):
192
+ pass
193
+
194
+
195
+ OptTooManyRequestsResponse = TooManyRequestsResponse | None
196
+
197
+
198
+ class InternalServerErrorResponse(
199
+ InternalServerErrorDescriptor,
200
+ ErrorResponse,
201
+ ):
202
+ pass
203
+
204
+
205
+ OptInternalServerErrorResponse = InternalServerErrorResponse | None
206
+
207
+
208
+ class NotImplementedResponse(
209
+ NotImplementedErrorDescriptor,
210
+ ErrorResponse,
211
+ ):
212
+ pass
213
+
214
+
215
+ OptNotImplementedResponse = NotImplementedResponse | None
216
+
217
+
218
+ class BadGatewayResponse(
219
+ BadGatewayErrorDescriptor,
220
+ ErrorResponse,
221
+ ):
222
+ pass
223
+
224
+
225
+ OptBadGatewayResponse = BadGatewayResponse | None
226
+
227
+
228
+ class ServiceUnavailableResponse(
229
+ ServiceUnavailableErrorDescriptor,
230
+ ErrorResponse,
231
+ ):
232
+ pass
233
+
234
+
235
+ OptServiceUnavailableResponse = ServiceUnavailableResponse | None
236
+
237
+
238
+ AnyErrorResponseType = (
239
+ Type[BadRequestResponse]
240
+ | Type[UnauthorizedResponse]
241
+ | Type[ForbiddenResponse]
242
+ | Type[NotFoundResponse]
243
+ | Type[MethodNotAllowedResponse]
244
+ | Type[ConflictResponse]
245
+ | Type[UnprocessableEntityResponse]
246
+ | Type[TooManyRequestsResponse]
247
+ | Type[InternalServerErrorResponse]
248
+ | Type[NotImplementedResponse]
249
+ | Type[BadGatewayResponse]
250
+ | Type[ServiceUnavailableResponse]
251
+ )
252
+ AnyErrorResponse = (
253
+ BadRequestResponse
254
+ | UnauthorizedResponse
255
+ | ForbiddenResponse
256
+ | NotFoundResponse
257
+ | MethodNotAllowedResponse
258
+ | ConflictResponse
259
+ | UnprocessableEntityResponse
260
+ | TooManyRequestsResponse
261
+ | InternalServerErrorResponse
262
+ | NotImplementedResponse
263
+ | BadGatewayResponse
264
+ | ServiceUnavailableResponse
265
+ )
266
+ ErrorResponseT = TypeVar("ErrorResponseT", bound=AnyErrorResponse)
267
+ OptAnyErrorResponse = AnyErrorResponse | None
268
+ OptErrorResponseT = TypeVar("OptErrorResponseT", bound=OptAnyErrorResponse)
269
+
270
+
271
+ class ErrorResponseFactory:
272
+ @overload
273
+ @staticmethod
274
+ def cls_from_code(
275
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
276
+ /,
277
+ ) -> Type[BadRequestResponse]: ...
278
+ @overload
279
+ @staticmethod
280
+ def cls_from_code(
281
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
282
+ /,
283
+ ) -> Type[UnauthorizedResponse]: ...
284
+ @overload
285
+ @staticmethod
286
+ def cls_from_code(
287
+ code: Literal[ErrorCode.FORBIDDEN, 403],
288
+ /,
289
+ ) -> Type[ForbiddenResponse]: ...
290
+ @overload
291
+ @staticmethod
292
+ def cls_from_code(
293
+ code: Literal[ErrorCode.NOT_FOUND, 404],
294
+ /,
295
+ ) -> Type[NotFoundResponse]: ...
296
+ @overload
297
+ @staticmethod
298
+ def cls_from_code(
299
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
300
+ /,
301
+ ) -> Type[MethodNotAllowedResponse]: ...
302
+ @overload
303
+ @staticmethod
304
+ def cls_from_code(
305
+ code: Literal[ErrorCode.CONFLICT, 409],
306
+ /,
307
+ ) -> Type[ConflictResponse]: ...
308
+ @overload
309
+ @staticmethod
310
+ def cls_from_code(
311
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
312
+ /,
313
+ ) -> Type[UnprocessableEntityResponse]: ...
314
+ @overload
315
+ @staticmethod
316
+ def cls_from_code(
317
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
318
+ /,
319
+ ) -> Type[TooManyRequestsResponse]: ...
320
+ @overload
321
+ @staticmethod
322
+ def cls_from_code(
323
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
324
+ /,
325
+ ) -> Type[InternalServerErrorResponse]: ...
326
+ @overload
327
+ @staticmethod
328
+ def cls_from_code(
329
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
330
+ /,
331
+ ) -> Type[NotImplementedResponse]: ...
332
+ @overload
333
+ @staticmethod
334
+ def cls_from_code(
335
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
336
+ /,
337
+ ) -> Type[BadGatewayResponse]: ...
338
+ @overload
339
+ @staticmethod
340
+ def cls_from_code(
341
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
342
+ /,
343
+ ) -> Type[ServiceUnavailableResponse]: ...
344
+ @overload
345
+ @staticmethod
346
+ def cls_from_code(
347
+ code: ErrorCode | int,
348
+ /,
349
+ ) -> AnyErrorResponseType: ...
350
+ @staticmethod
351
+ def cls_from_code(
352
+ code: ErrorCode | int,
353
+ /,
354
+ ) -> AnyErrorResponseType:
355
+ if code is ErrorCode.BAD_REQUEST or code == 400:
356
+ return BadRequestResponse
357
+ elif code is ErrorCode.UNAUTHORIZED or code == 401:
358
+ return UnauthorizedResponse
359
+ elif code is ErrorCode.FORBIDDEN or code == 403:
360
+ return ForbiddenResponse
361
+ elif code is ErrorCode.NOT_FOUND or code == 404:
362
+ return NotFoundResponse
363
+ elif code is ErrorCode.METHOD_NOT_ALLOWED or code == 405:
364
+ return MethodNotAllowedResponse
365
+ elif code is ErrorCode.CONFLICT or code == 409:
366
+ return ConflictResponse
367
+ elif code is ErrorCode.UNPROCESSABLE_ENTITY or code == 422:
368
+ return UnprocessableEntityResponse
369
+ elif code is ErrorCode.TOO_MANY_REQUESTS or code == 429:
370
+ return TooManyRequestsResponse
371
+ elif code is ErrorCode.INTERNAL_SERVER_ERROR or code == 500:
372
+ return InternalServerErrorResponse
373
+ elif code is ErrorCode.NOT_IMPLEMENTED or code == 501:
374
+ return NotImplementedResponse
375
+ elif code is ErrorCode.BAD_GATEWAY or code == 502:
376
+ return BadGatewayResponse
377
+ elif code is ErrorCode.SERVICE_UNAVAILABLE or code == 503:
378
+ return ServiceUnavailableResponse
379
+ raise ValueError(f"Unable to determine error response class for code: {code}")
380
+
381
+ @overload
382
+ @staticmethod
383
+ def from_code(
384
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
385
+ *,
386
+ message: OptStr = None,
387
+ description: OptStr = None,
388
+ other: Any = None,
389
+ ) -> BadRequestResponse: ...
390
+ @overload
391
+ @staticmethod
392
+ def from_code(
393
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
394
+ *,
395
+ message: OptStr = None,
396
+ description: OptStr = None,
397
+ other: Any = None,
398
+ ) -> UnauthorizedResponse: ...
399
+ @overload
400
+ @staticmethod
401
+ def from_code(
402
+ code: Literal[ErrorCode.FORBIDDEN, 403],
403
+ *,
404
+ message: OptStr = None,
405
+ description: OptStr = None,
406
+ other: Any = None,
407
+ ) -> ForbiddenResponse: ...
408
+ @overload
409
+ @staticmethod
410
+ def from_code(
411
+ code: Literal[ErrorCode.NOT_FOUND, 404],
412
+ *,
413
+ message: OptStr = None,
414
+ description: OptStr = None,
415
+ other: Any = None,
416
+ ) -> NotFoundResponse: ...
417
+ @overload
418
+ @staticmethod
419
+ def from_code(
420
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
421
+ *,
422
+ message: OptStr = None,
423
+ description: OptStr = None,
424
+ other: Any = None,
425
+ ) -> MethodNotAllowedResponse: ...
426
+ @overload
427
+ @staticmethod
428
+ def from_code(
429
+ code: Literal[ErrorCode.CONFLICT, 409],
430
+ *,
431
+ message: OptStr = None,
432
+ description: OptStr = None,
433
+ other: Any = None,
434
+ ) -> ConflictResponse: ...
435
+ @overload
436
+ @staticmethod
437
+ def from_code(
438
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
439
+ *,
440
+ message: OptStr = None,
441
+ description: OptStr = None,
442
+ other: Any = None,
443
+ ) -> UnprocessableEntityResponse: ...
444
+ @overload
445
+ @staticmethod
446
+ def from_code(
447
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
448
+ *,
449
+ message: OptStr = None,
450
+ description: OptStr = None,
451
+ other: Any = None,
452
+ ) -> TooManyRequestsResponse: ...
453
+ @overload
454
+ @staticmethod
455
+ def from_code(
456
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
457
+ *,
458
+ message: OptStr = None,
459
+ description: OptStr = None,
460
+ other: Any = None,
461
+ ) -> InternalServerErrorResponse: ...
462
+ @overload
463
+ @staticmethod
464
+ def from_code(
465
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
466
+ *,
467
+ message: OptStr = None,
468
+ description: OptStr = None,
469
+ other: Any = None,
470
+ ) -> NotImplementedResponse: ...
471
+ @overload
472
+ @staticmethod
473
+ def from_code(
474
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
475
+ *,
476
+ message: OptStr = None,
477
+ description: OptStr = None,
478
+ other: Any = None,
479
+ ) -> BadGatewayResponse: ...
480
+ @overload
481
+ @staticmethod
482
+ def from_code(
483
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
484
+ *,
485
+ message: OptStr = None,
486
+ description: OptStr = None,
487
+ other: Any = None,
488
+ ) -> ServiceUnavailableResponse: ...
489
+ @overload
490
+ @staticmethod
491
+ def from_code(
492
+ code: ErrorCode | int,
493
+ *,
494
+ message: OptStr = None,
495
+ description: OptStr = None,
496
+ other: Any = None,
497
+ ) -> AnyErrorResponse: ...
498
+ @staticmethod
499
+ def from_code(
500
+ code: ErrorCode | int,
501
+ *,
502
+ message: OptStr = None,
503
+ description: OptStr = None,
504
+ other: Any = None,
505
+ ) -> AnyErrorResponse:
506
+ obj = {}
507
+ if message is not None:
508
+ obj["message"] = message
509
+ if description is not None:
510
+ obj["description"] = description
511
+ if other is not None:
512
+ obj["other"] = other
513
+ return ErrorResponseFactory.cls_from_code(code).model_validate(obj)
514
+
515
+
516
+ OTHER_RESPONSES: dict[
517
+ IntOrStr,
518
+ StrToAnyDict,
519
+ ] = {
520
+ 400: {
521
+ "description": "Bad Request Response",
522
+ "model": BadRequestResponse,
523
+ },
524
+ 401: {
525
+ "description": "Unauthorized Response",
526
+ "model": UnauthorizedResponse,
527
+ },
528
+ 403: {
529
+ "description": "Forbidden Response",
530
+ "model": ForbiddenResponse,
531
+ },
532
+ 404: {
533
+ "description": "Not Found Response",
534
+ "model": NotFoundResponse,
535
+ },
536
+ 405: {
537
+ "description": "Method Not Allowed Response",
538
+ "model": MethodNotAllowedResponse,
539
+ },
540
+ 409: {
541
+ "description": "Conflict Response",
542
+ "model": ConflictResponse,
543
+ },
544
+ 422: {
545
+ "description": "Unprocessable Entity Response",
546
+ "model": UnprocessableEntityResponse,
547
+ },
548
+ 429: {
549
+ "description": "Too Many Requests Response",
550
+ "model": TooManyRequestsResponse,
551
+ },
552
+ 500: {
553
+ "description": "Internal Server Error Response",
554
+ "model": InternalServerErrorResponse,
555
+ },
556
+ 501: {
557
+ "description": "Not Implemented Response",
558
+ "model": NotImplementedResponse,
559
+ },
560
+ 502: {
561
+ "description": "Bad Gateway Response",
562
+ "model": BadGatewayResponse,
563
+ },
564
+ 503: {
565
+ "description": "Service Unavailable Response",
566
+ "model": ServiceUnavailableResponse,
567
+ },
568
+ }
569
+
570
+
571
+ class SuccessResponse(
572
+ SuccessDescriptor,
573
+ Response[Literal[True], SuccessCode, AnyDataT, OptPaginationT, AnyMetadataT],
574
+ Generic[AnyDataT, OptPaginationT, AnyMetadataT],
575
+ ):
576
+ success: Literal[True] = True
577
+
578
+
579
+ class AnyDataResponse(
580
+ AnyDataSuccessDescriptor,
581
+ SuccessResponse[AnyDataT, OptPaginationT, AnyMetadataT],
582
+ Generic[AnyDataT, OptPaginationT, AnyMetadataT],
583
+ ):
584
+ pass
585
+
586
+
587
+ class NoDataResponse(
588
+ NoDataPayload[ModelMetadataT],
589
+ NoDataSuccessDescriptor,
590
+ SuccessResponse[None, None, ModelMetadataT],
591
+ Generic[ModelMetadataT],
592
+ ):
593
+ data: None = None
594
+ pagination: None = None
595
+
596
+ @classmethod
597
+ def new(
598
+ cls,
599
+ *,
600
+ message: OptStr = None,
601
+ description: OptStr = None,
602
+ metadata: ModelMetadataT = None,
603
+ other: Any = None,
604
+ ) -> "NoDataResponse[ModelMetadataT]":
605
+ descriptor = NoDataSuccessDescriptor()
606
+ return cls(
607
+ message=message if message is not None else descriptor.message,
608
+ description=(
609
+ description if description is not None else descriptor.description
610
+ ),
611
+ metadata=metadata,
612
+ other=other,
613
+ )
614
+
615
+
616
+ class SingleDataResponse(
617
+ SingleDataPayload[ModelDataT, ModelMetadataT],
618
+ SingleDataSuccessDescriptor,
619
+ SuccessResponse[ModelDataT, None, ModelMetadataT],
620
+ Generic[ModelDataT, ModelMetadataT],
621
+ ):
622
+ pagination: None = None
623
+
624
+ @classmethod
625
+ def new(
626
+ cls,
627
+ *,
628
+ message: OptStr = None,
629
+ description: OptStr = None,
630
+ data: ModelDataT,
631
+ metadata: ModelMetadataT = None,
632
+ other: Any = None,
633
+ ) -> "SingleDataResponse[ModelDataT, ModelMetadataT]":
634
+ descriptor = SingleDataSuccessDescriptor()
635
+ return cls(
636
+ message=message if message is not None else descriptor.message,
637
+ description=(
638
+ description if description is not None else descriptor.description
639
+ ),
640
+ data=data,
641
+ metadata=metadata,
642
+ other=other,
643
+ )
644
+
645
+
646
+ class PingResponse(SingleDataResponse[PingData, None]):
647
+ data: Annotated[PingData, Field(PingData(), description="Ping response's data")] = (
648
+ PingData()
649
+ )
650
+ metadata: Annotated[None, Field(None, description="Ping response's metadata")] = (
651
+ None
652
+ )
653
+
654
+
655
+ class CreateSingleDataResponse(
656
+ CreateSingleDataPayload[ModelDataT, ModelMetadataT],
657
+ CreateSingleDataSuccessDescriptor,
658
+ SuccessResponse[DataPair[None, ModelDataT], None, ModelMetadataT],
659
+ Generic[ModelDataT, ModelMetadataT],
660
+ ):
661
+ pagination: None = None
662
+
663
+ @classmethod
664
+ def new(
665
+ cls,
666
+ *,
667
+ message: OptStr = None,
668
+ description: OptStr = None,
669
+ data: ModelDataT,
670
+ metadata: ModelMetadataT = None,
671
+ other: Any = None,
672
+ ) -> "CreateSingleDataResponse[ModelDataT, ModelMetadataT]":
673
+ descriptor = CreateSingleDataSuccessDescriptor()
674
+ return cls(
675
+ message=message if message is not None else descriptor.message,
676
+ description=(
677
+ description if description is not None else descriptor.description
678
+ ),
679
+ data=DataPair[None, ModelDataT](
680
+ old=None,
681
+ new=data,
682
+ ),
683
+ metadata=metadata,
684
+ other=other,
685
+ )
686
+
687
+
688
+ class ReadSingleDataResponse(
689
+ ReadSingleDataPayload[ModelDataT, ModelMetadataT],
690
+ ReadSingleDataSuccessDescriptor,
691
+ SuccessResponse[DataPair[ModelDataT, None], None, ModelMetadataT],
692
+ Generic[ModelDataT, ModelMetadataT],
693
+ ):
694
+ pagination: None = None
695
+
696
+ @classmethod
697
+ def new(
698
+ cls,
699
+ *,
700
+ message: OptStr = None,
701
+ description: OptStr = None,
702
+ data: ModelDataT,
703
+ metadata: ModelMetadataT = None,
704
+ other: Any = None,
705
+ ) -> "ReadSingleDataResponse[ModelDataT, ModelMetadataT]":
706
+ descriptor = ReadSingleDataSuccessDescriptor()
707
+ return cls(
708
+ message=message if message is not None else descriptor.message,
709
+ description=(
710
+ description if description is not None else descriptor.description
711
+ ),
712
+ data=DataPair[ModelDataT, None](
713
+ old=data,
714
+ new=None,
715
+ ),
716
+ metadata=metadata,
717
+ other=other,
718
+ )
719
+
720
+
721
+ class UpdateSingleDataResponse(
722
+ UpdateSingleDataPayload[ModelDataT, ModelMetadataT],
723
+ UpdateSingleDataSuccessDescriptor,
724
+ SuccessResponse[DataPair[ModelDataT, ModelDataT], None, ModelMetadataT],
725
+ Generic[ModelDataT, ModelMetadataT],
726
+ ):
727
+ pagination: None = None
728
+
729
+ @classmethod
730
+ def new(
731
+ cls,
732
+ *,
733
+ message: OptStr = None,
734
+ description: OptStr = None,
735
+ old_data: ModelDataT,
736
+ new_data: ModelDataT,
737
+ metadata: ModelMetadataT = None,
738
+ other: Any = None,
739
+ ) -> "UpdateSingleDataResponse[ModelDataT, ModelMetadataT]":
740
+ descriptor = UpdateSingleDataSuccessDescriptor()
741
+ return cls(
742
+ message=message if message is not None else descriptor.message,
743
+ description=(
744
+ description if description is not None else descriptor.description
745
+ ),
746
+ data=DataPair[ModelDataT, ModelDataT](
747
+ old=old_data,
748
+ new=new_data,
749
+ ),
750
+ metadata=metadata,
751
+ other=other,
752
+ )
753
+
754
+
755
+ class DeleteSingleDataResponse(
756
+ DeleteSingleDataPayload[ModelDataT, ModelMetadataT],
757
+ DeleteSingleDataSuccessDescriptor,
758
+ SuccessResponse[DataPair[ModelDataT, None], None, ModelMetadataT],
759
+ Generic[ModelDataT, ModelMetadataT],
760
+ ):
761
+ pagination: None = None
762
+
763
+ @classmethod
764
+ def new(
765
+ cls,
766
+ *,
767
+ message: OptStr = None,
768
+ description: OptStr = None,
769
+ data: ModelDataT,
770
+ metadata: ModelMetadataT = None,
771
+ other: Any = None,
772
+ ) -> "DeleteSingleDataResponse[ModelDataT, ModelMetadataT]":
773
+ descriptor = DeleteSingleDataSuccessDescriptor()
774
+ return cls(
775
+ message=message if message is not None else descriptor.message,
776
+ description=(
777
+ description if description is not None else descriptor.description
778
+ ),
779
+ data=DataPair[ModelDataT, None](
780
+ old=data,
781
+ new=None,
782
+ ),
783
+ metadata=metadata,
784
+ other=other,
785
+ )
786
+
787
+
788
+ class OptSingleDataResponse(
789
+ OptSingleDataPayload[ModelDataT, ModelMetadataT],
790
+ OptSingleDataSuccessDescriptor,
791
+ SuccessResponse[ModelDataT | None, None, ModelMetadataT],
792
+ Generic[ModelDataT, ModelMetadataT],
793
+ ):
794
+ pagination: None = None
795
+
796
+ @classmethod
797
+ def new(
798
+ cls,
799
+ *,
800
+ message: OptStr = None,
801
+ description: OptStr = None,
802
+ data: ModelDataT | None = None,
803
+ metadata: ModelMetadataT = None,
804
+ other: Any = None,
805
+ ) -> "OptSingleDataResponse[ModelDataT, ModelMetadataT]":
806
+ descriptor = OptSingleDataSuccessDescriptor()
807
+ return cls(
808
+ message=message if message is not None else descriptor.message,
809
+ description=(
810
+ description if description is not None else descriptor.description
811
+ ),
812
+ data=data,
813
+ metadata=metadata,
814
+ other=other,
815
+ )
816
+
817
+
818
+ class MultipleDataResponse(
819
+ MultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
820
+ MultipleDataSuccessDescriptor,
821
+ SuccessResponse[list[ModelDataT], PaginationT, ModelMetadataT],
822
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
823
+ ):
824
+ @classmethod
825
+ def new(
826
+ cls,
827
+ *,
828
+ message: OptStr = None,
829
+ description: OptStr = None,
830
+ data: list[ModelDataT],
831
+ pagination: PaginationT,
832
+ metadata: ModelMetadataT = None,
833
+ other: Any = None,
834
+ ) -> "MultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
835
+ descriptor = MultipleDataSuccessDescriptor()
836
+ return cls(
837
+ message=message if message is not None else descriptor.message,
838
+ description=(
839
+ description if description is not None else descriptor.description
840
+ ),
841
+ data=data,
842
+ pagination=pagination,
843
+ metadata=metadata,
844
+ other=other,
845
+ )
846
+
847
+
848
+ class CreateMultipleDataResponse(
849
+ CreateMultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
850
+ CreateMultipleDataSuccessDescriptor,
851
+ SuccessResponse[DataPair[None, list[ModelDataT]], PaginationT, ModelMetadataT],
852
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
853
+ ):
854
+ @classmethod
855
+ def new(
856
+ cls,
857
+ *,
858
+ message: OptStr = None,
859
+ description: OptStr = None,
860
+ data: list[ModelDataT],
861
+ pagination: PaginationT,
862
+ metadata: ModelMetadataT = None,
863
+ other: Any = None,
864
+ ) -> "CreateMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
865
+ descriptor = CreateMultipleDataSuccessDescriptor()
866
+ return cls(
867
+ message=message if message is not None else descriptor.message,
868
+ description=(
869
+ description if description is not None else descriptor.description
870
+ ),
871
+ data=DataPair[None, list[ModelDataT]](
872
+ old=None,
873
+ new=data,
874
+ ),
875
+ pagination=pagination,
876
+ metadata=metadata,
877
+ other=other,
878
+ )
879
+
880
+
881
+ class ReadMultipleDataResponse(
882
+ ReadMultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
883
+ ReadMultipleDataSuccessDescriptor,
884
+ SuccessResponse[DataPair[list[ModelDataT], None], PaginationT, ModelMetadataT],
885
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
886
+ ):
887
+ @classmethod
888
+ def new(
889
+ cls,
890
+ *,
891
+ message: OptStr = None,
892
+ description: OptStr = None,
893
+ data: list[ModelDataT],
894
+ pagination: PaginationT,
895
+ metadata: ModelMetadataT = None,
896
+ other: Any = None,
897
+ ) -> "ReadMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
898
+ descriptor = ReadMultipleDataSuccessDescriptor()
899
+ return cls(
900
+ message=message if message is not None else descriptor.message,
901
+ description=(
902
+ description if description is not None else descriptor.description
903
+ ),
904
+ data=DataPair[list[ModelDataT], None](
905
+ old=data,
906
+ new=None,
907
+ ),
908
+ pagination=pagination,
909
+ metadata=metadata,
910
+ other=other,
911
+ )
912
+
913
+
914
+ class UpdateMultipleDataResponse(
915
+ UpdateMultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
916
+ UpdateMultipleDataSuccessDescriptor,
917
+ SuccessResponse[
918
+ DataPair[list[ModelDataT], list[ModelDataT]], PaginationT, ModelMetadataT
919
+ ],
920
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
921
+ ):
922
+ @classmethod
923
+ def new(
924
+ cls,
925
+ *,
926
+ message: OptStr = None,
927
+ description: OptStr = None,
928
+ old_data: list[ModelDataT],
929
+ new_data: list[ModelDataT],
930
+ pagination: PaginationT,
931
+ metadata: ModelMetadataT = None,
932
+ other: Any = None,
933
+ ) -> "UpdateMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
934
+ descriptor = UpdateMultipleDataSuccessDescriptor()
935
+ return cls(
936
+ message=message if message is not None else descriptor.message,
937
+ description=(
938
+ description if description is not None else descriptor.description
939
+ ),
940
+ data=DataPair[list[ModelDataT], list[ModelDataT]](
941
+ old=old_data,
942
+ new=new_data,
943
+ ),
944
+ pagination=pagination,
945
+ metadata=metadata,
946
+ other=other,
947
+ )
948
+
949
+
950
+ class DeleteMultipleDataResponse(
951
+ DeleteMultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
952
+ DeleteMultipleDataSuccessDescriptor,
953
+ SuccessResponse[DataPair[list[ModelDataT], None], PaginationT, ModelMetadataT],
954
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
955
+ ):
956
+ @classmethod
957
+ def new(
958
+ cls,
959
+ *,
960
+ message: OptStr = None,
961
+ description: OptStr = None,
962
+ data: list[ModelDataT],
963
+ pagination: PaginationT,
964
+ metadata: ModelMetadataT = None,
965
+ other: Any = None,
966
+ ) -> "DeleteMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
967
+ descriptor = DeleteMultipleDataSuccessDescriptor()
968
+ return cls(
969
+ message=message if message is not None else descriptor.message,
970
+ description=(
971
+ description if description is not None else descriptor.description
972
+ ),
973
+ data=DataPair[list[ModelDataT], None](
974
+ old=data,
975
+ new=None,
976
+ ),
977
+ pagination=pagination,
978
+ metadata=metadata,
979
+ other=other,
980
+ )
981
+
982
+
983
+ class OptMultipleDataResponse(
984
+ OptMultipleDataPayload[ModelDataT, PaginationT, ModelMetadataT],
985
+ OptMultipleDataSuccessDescriptor,
986
+ SuccessResponse[list[ModelDataT] | None, PaginationT, ModelMetadataT],
987
+ Generic[ModelDataT, PaginationT, ModelMetadataT],
988
+ ):
989
+ @classmethod
990
+ def new(
991
+ cls,
992
+ *,
993
+ message: OptStr = None,
994
+ description: OptStr = None,
995
+ data: list[ModelDataT] | None = None,
996
+ pagination: PaginationT,
997
+ metadata: ModelMetadataT = None,
998
+ other: Any = None,
999
+ ) -> "OptMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]":
1000
+ descriptor = OptMultipleDataSuccessDescriptor()
1001
+ return cls(
1002
+ message=message if message is not None else descriptor.message,
1003
+ description=(
1004
+ description if description is not None else descriptor.description
1005
+ ),
1006
+ data=data,
1007
+ pagination=pagination,
1008
+ metadata=metadata,
1009
+ other=other,
1010
+ )
1011
+
1012
+
1013
+ AnySuccessResponse = (
1014
+ AnyDataResponse[ModelDataT, OptPaginationT, ModelMetadataT]
1015
+ | NoDataResponse[ModelMetadataT]
1016
+ | SingleDataResponse[ModelDataT, ModelMetadataT]
1017
+ | CreateSingleDataResponse[ModelDataT, ModelMetadataT]
1018
+ | ReadSingleDataResponse[ModelDataT, ModelMetadataT]
1019
+ | UpdateSingleDataResponse[ModelDataT, ModelMetadataT]
1020
+ | DeleteSingleDataResponse[ModelDataT, ModelMetadataT]
1021
+ | OptSingleDataResponse[ModelDataT, ModelMetadataT]
1022
+ | MultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1023
+ | CreateMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1024
+ | ReadMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1025
+ | UpdateMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1026
+ | DeleteMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1027
+ | OptMultipleDataResponse[ModelDataT, PaginationT, ModelMetadataT]
1028
+ )
1029
+ SuccessResponseT = TypeVar("SuccessResponseT", bound=AnySuccessResponse)
1030
+ OptAnySuccessResponse = AnySuccessResponse | None
1031
+ OptSuccessResponseT = TypeVar("OptSuccessResponseT", bound=OptAnySuccessResponse)
1032
+
1033
+
1034
+ AnyResponse = AnyErrorResponse | AnySuccessResponse
1035
+ ResponseT = TypeVar("ResponseT", bound=AnyResponse)
1036
+ OptAnyResponse = AnyResponse | None
1037
+ OptResponseT = TypeVar("OptResponseT", bound=OptAnyResponse)
1038
+
1039
+
1040
+ class ResponseMixin(BaseModel, Generic[OptResponseT]):
1041
+ response: OptResponseT = Field(..., description="Response")