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,312 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import Generic, Literal, Type, TypeVar, overload
3
+ from typing_extensions import Annotated
4
+ from ..mixins.general import StatusCode
5
+ from .enums import ErrorType as ErrorTypeEnum
6
+ from .enums import ErrorCode
7
+
8
+
9
+ class ErrorType(BaseModel):
10
+ type: Annotated[
11
+ ErrorTypeEnum,
12
+ Field(ErrorTypeEnum.INTERNAL_SERVER_ERROR, description="Error type"),
13
+ ] = ErrorTypeEnum.INTERNAL_SERVER_ERROR
14
+
15
+
16
+ class ErrorSpec(StatusCode, ErrorType):
17
+ status_code: Annotated[
18
+ int, Field(500, description="Status code", ge=400, le=600)
19
+ ] = 500
20
+
21
+
22
+ ErrorSpecT = TypeVar("ErrorSpecT", bound=ErrorSpec)
23
+
24
+
25
+ class ErrorSpecMixin(BaseModel, Generic[ErrorSpecT]):
26
+ spec: Annotated[ErrorSpecT, Field(..., description="Error's Spec")]
27
+
28
+
29
+ class BadRequestErrorSpec(ErrorSpec):
30
+ type: ErrorTypeEnum = ErrorTypeEnum.BAD_REQUEST
31
+ status_code: int = 400
32
+
33
+
34
+ class UnauthorizedErrorSpec(ErrorSpec):
35
+ type: ErrorTypeEnum = ErrorTypeEnum.UNAUTHORIZED
36
+ status_code: int = 401
37
+
38
+
39
+ class ForbiddenErrorSpec(ErrorSpec):
40
+ type: ErrorTypeEnum = ErrorTypeEnum.FORBIDDEN
41
+ status_code: int = 403
42
+
43
+
44
+ class NotFoundErrorSpec(ErrorSpec):
45
+ type: ErrorTypeEnum = ErrorTypeEnum.NOT_FOUND
46
+ status_code: int = 404
47
+
48
+
49
+ class MethodNotAllowedErrorSpec(ErrorSpec):
50
+ type: ErrorTypeEnum = ErrorTypeEnum.METHOD_NOT_ALLOWED
51
+ status_code: int = 405
52
+
53
+
54
+ class ConflictErrorSpec(ErrorSpec):
55
+ type: ErrorTypeEnum = ErrorTypeEnum.CONFLICT
56
+ status_code: int = 409
57
+
58
+
59
+ class UnprocessableEntityErrorSpec(ErrorSpec):
60
+ type: ErrorTypeEnum = ErrorTypeEnum.UNPROCESSABLE_ENTITY
61
+ status_code: int = 422
62
+
63
+
64
+ class TooManyRequestsErrorSpec(ErrorSpec):
65
+ type: ErrorTypeEnum = ErrorTypeEnum.TOO_MANY_REQUESTS
66
+ status_code: int = 429
67
+
68
+
69
+ class InternalServerErrorSpec(ErrorSpec):
70
+ type: ErrorTypeEnum = ErrorTypeEnum.INTERNAL_SERVER_ERROR
71
+ status_code: int = 500
72
+
73
+
74
+ class NotImplementedErrorSpec(ErrorSpec):
75
+ type: ErrorTypeEnum = ErrorTypeEnum.NOT_IMPLEMENTED
76
+ status_code: int = 501
77
+
78
+
79
+ class BadGatewayErrorSpec(ErrorSpec):
80
+ type: ErrorTypeEnum = ErrorTypeEnum.BAD_GATEWAY
81
+ status_code: int = 502
82
+
83
+
84
+ class ServiceUnavailableErrorSpec(ErrorSpec):
85
+ type: ErrorTypeEnum = ErrorTypeEnum.SERVICE_UNAVAILABLE
86
+ status_code: int = 503
87
+
88
+
89
+ AnyErrorSpecType = (
90
+ Type[BadRequestErrorSpec]
91
+ | Type[UnauthorizedErrorSpec]
92
+ | Type[ForbiddenErrorSpec]
93
+ | Type[NotFoundErrorSpec]
94
+ | Type[MethodNotAllowedErrorSpec]
95
+ | Type[ConflictErrorSpec]
96
+ | Type[UnprocessableEntityErrorSpec]
97
+ | Type[TooManyRequestsErrorSpec]
98
+ | Type[InternalServerErrorSpec]
99
+ | Type[NotImplementedErrorSpec]
100
+ | Type[BadGatewayErrorSpec]
101
+ | Type[ServiceUnavailableErrorSpec]
102
+ )
103
+ AnyErrorSpec = (
104
+ BadRequestErrorSpec
105
+ | UnauthorizedErrorSpec
106
+ | ForbiddenErrorSpec
107
+ | NotFoundErrorSpec
108
+ | MethodNotAllowedErrorSpec
109
+ | ConflictErrorSpec
110
+ | UnprocessableEntityErrorSpec
111
+ | TooManyRequestsErrorSpec
112
+ | InternalServerErrorSpec
113
+ | NotImplementedErrorSpec
114
+ | BadGatewayErrorSpec
115
+ | ServiceUnavailableErrorSpec
116
+ )
117
+
118
+
119
+ class ErrorSpecFactory:
120
+ @overload
121
+ @staticmethod
122
+ def cls_from_code(
123
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
124
+ /,
125
+ ) -> Type[BadRequestErrorSpec]: ...
126
+ @overload
127
+ @staticmethod
128
+ def cls_from_code(
129
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
130
+ /,
131
+ ) -> Type[UnauthorizedErrorSpec]: ...
132
+ @overload
133
+ @staticmethod
134
+ def cls_from_code(
135
+ code: Literal[ErrorCode.FORBIDDEN, 403],
136
+ /,
137
+ ) -> Type[ForbiddenErrorSpec]: ...
138
+ @overload
139
+ @staticmethod
140
+ def cls_from_code(
141
+ code: Literal[ErrorCode.NOT_FOUND, 404],
142
+ /,
143
+ ) -> Type[NotFoundErrorSpec]: ...
144
+ @overload
145
+ @staticmethod
146
+ def cls_from_code(
147
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
148
+ /,
149
+ ) -> Type[MethodNotAllowedErrorSpec]: ...
150
+ @overload
151
+ @staticmethod
152
+ def cls_from_code(
153
+ code: Literal[ErrorCode.CONFLICT, 409],
154
+ /,
155
+ ) -> Type[ConflictErrorSpec]: ...
156
+ @overload
157
+ @staticmethod
158
+ def cls_from_code(
159
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
160
+ /,
161
+ ) -> Type[UnprocessableEntityErrorSpec]: ...
162
+ @overload
163
+ @staticmethod
164
+ def cls_from_code(
165
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
166
+ /,
167
+ ) -> Type[TooManyRequestsErrorSpec]: ...
168
+ @overload
169
+ @staticmethod
170
+ def cls_from_code(
171
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
172
+ /,
173
+ ) -> Type[InternalServerErrorSpec]: ...
174
+ @overload
175
+ @staticmethod
176
+ def cls_from_code(
177
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
178
+ /,
179
+ ) -> Type[NotImplementedErrorSpec]: ...
180
+ @overload
181
+ @staticmethod
182
+ def cls_from_code(
183
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
184
+ /,
185
+ ) -> Type[BadGatewayErrorSpec]: ...
186
+ @overload
187
+ @staticmethod
188
+ def cls_from_code(
189
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
190
+ /,
191
+ ) -> Type[ServiceUnavailableErrorSpec]: ...
192
+ @overload
193
+ @staticmethod
194
+ def cls_from_code(
195
+ code: ErrorCode | int,
196
+ /,
197
+ ) -> AnyErrorSpecType: ...
198
+ @staticmethod
199
+ def cls_from_code(
200
+ code: ErrorCode | int,
201
+ /,
202
+ ) -> AnyErrorSpecType:
203
+ if code is ErrorCode.BAD_REQUEST or code == 400:
204
+ return BadRequestErrorSpec
205
+ elif code is ErrorCode.UNAUTHORIZED or code == 401:
206
+ return UnauthorizedErrorSpec
207
+ elif code is ErrorCode.FORBIDDEN or code == 403:
208
+ return ForbiddenErrorSpec
209
+ elif code is ErrorCode.NOT_FOUND or code == 404:
210
+ return NotFoundErrorSpec
211
+ elif code is ErrorCode.METHOD_NOT_ALLOWED or code == 405:
212
+ return MethodNotAllowedErrorSpec
213
+ elif code is ErrorCode.CONFLICT or code == 409:
214
+ return ConflictErrorSpec
215
+ elif code is ErrorCode.UNPROCESSABLE_ENTITY or code == 422:
216
+ return UnprocessableEntityErrorSpec
217
+ elif code is ErrorCode.TOO_MANY_REQUESTS or code == 429:
218
+ return TooManyRequestsErrorSpec
219
+ elif code is ErrorCode.INTERNAL_SERVER_ERROR or code == 500:
220
+ return InternalServerErrorSpec
221
+ elif code is ErrorCode.NOT_IMPLEMENTED or code == 501:
222
+ return NotImplementedErrorSpec
223
+ elif code is ErrorCode.BAD_GATEWAY or code == 502:
224
+ return BadGatewayErrorSpec
225
+ elif code is ErrorCode.SERVICE_UNAVAILABLE or code == 503:
226
+ return ServiceUnavailableErrorSpec
227
+ raise ValueError(f"Unable to determine error descriptor class for code: {code}")
228
+
229
+ @overload
230
+ @staticmethod
231
+ def from_code(
232
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
233
+ /,
234
+ ) -> BadRequestErrorSpec: ...
235
+ @overload
236
+ @staticmethod
237
+ def from_code(
238
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
239
+ /,
240
+ ) -> UnauthorizedErrorSpec: ...
241
+ @overload
242
+ @staticmethod
243
+ def from_code(
244
+ code: Literal[ErrorCode.FORBIDDEN, 403],
245
+ /,
246
+ ) -> ForbiddenErrorSpec: ...
247
+ @overload
248
+ @staticmethod
249
+ def from_code(
250
+ code: Literal[ErrorCode.NOT_FOUND, 404],
251
+ /,
252
+ ) -> NotFoundErrorSpec: ...
253
+ @overload
254
+ @staticmethod
255
+ def from_code(
256
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
257
+ /,
258
+ ) -> MethodNotAllowedErrorSpec: ...
259
+ @overload
260
+ @staticmethod
261
+ def from_code(
262
+ code: Literal[ErrorCode.CONFLICT, 409],
263
+ /,
264
+ ) -> ConflictErrorSpec: ...
265
+ @overload
266
+ @staticmethod
267
+ def from_code(
268
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
269
+ /,
270
+ ) -> UnprocessableEntityErrorSpec: ...
271
+ @overload
272
+ @staticmethod
273
+ def from_code(
274
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
275
+ /,
276
+ ) -> TooManyRequestsErrorSpec: ...
277
+ @overload
278
+ @staticmethod
279
+ def from_code(
280
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
281
+ /,
282
+ ) -> InternalServerErrorSpec: ...
283
+ @overload
284
+ @staticmethod
285
+ def from_code(
286
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
287
+ /,
288
+ ) -> NotImplementedErrorSpec: ...
289
+ @overload
290
+ @staticmethod
291
+ def from_code(
292
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
293
+ /,
294
+ ) -> BadGatewayErrorSpec: ...
295
+ @overload
296
+ @staticmethod
297
+ def from_code(
298
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
299
+ /,
300
+ ) -> ServiceUnavailableErrorSpec: ...
301
+ @overload
302
+ @staticmethod
303
+ def from_code(
304
+ code: ErrorCode | int,
305
+ /,
306
+ ) -> AnyErrorSpec: ...
307
+ @staticmethod
308
+ def from_code(
309
+ code: ErrorCode | int,
310
+ /,
311
+ ) -> AnyErrorSpec:
312
+ return ErrorSpecFactory.cls_from_code(code)()
File without changes