jararaca 0.3.11a16__py3-none-any.whl → 0.3.12__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.

Potentially problematic release.


This version of jararaca might be problematic. Click here for more details.

File without changes
@@ -0,0 +1,95 @@
1
+ from typing import Any, Callable, TypeVar, cast
2
+
3
+ from pydantic import BaseModel
4
+
5
+ DECORATED_FUNC = TypeVar("DECORATED_FUNC", bound=Callable[..., Any])
6
+
7
+
8
+ class QueryEndpoint:
9
+ """
10
+ Decorator to mark a endpoint function as a query endpoint for Typescript generation.
11
+ """
12
+
13
+ METADATA_KEY = "__jararaca_query_endpoint__"
14
+
15
+ def __init__(self, has_infinite_query: bool = False) -> None:
16
+ """
17
+ Initialize the QueryEndpoint decorator.
18
+
19
+ Args:
20
+ has_infinite_query: Whether the query endpoint supports infinite queries.
21
+ Important:
22
+ - Make sure a PaginatedQuery child instance is on the first argument
23
+ - Make sure the endpoint is a Patch (recommended) or Put method
24
+ - Make sure the endpoint returns a Paginated[T]
25
+ """
26
+ self.has_infinite_query = has_infinite_query
27
+
28
+ def __call__(self, func: DECORATED_FUNC) -> DECORATED_FUNC:
29
+ """
30
+ Decorate the function to mark it as a query endpoint.
31
+ """
32
+ setattr(func, self.METADATA_KEY, self)
33
+ return func
34
+
35
+ @staticmethod
36
+ def extract_query_endpoint(func: Any) -> "QueryEndpoint":
37
+ """
38
+ Check if the function is marked as a query endpoint.
39
+ """
40
+ return cast(QueryEndpoint, getattr(func, QueryEndpoint.METADATA_KEY, None))
41
+
42
+
43
+ class MutationEndpoint:
44
+ """
45
+ Decorator to mark a endpoint function as a mutation endpoint for Typescript generation.
46
+ """
47
+
48
+ METADATA_KEY = "__jararaca_mutation_endpoint__"
49
+
50
+ def __init__(self) -> None: ...
51
+
52
+ def __call__(self, func: DECORATED_FUNC) -> DECORATED_FUNC:
53
+ """
54
+ Decorate the function to mark it as a mutation endpoint.
55
+ """
56
+ setattr(func, self.METADATA_KEY, True)
57
+ return func
58
+
59
+ @staticmethod
60
+ def is_mutation(func: Any) -> bool:
61
+ """
62
+ Check if the function is marked as a mutation endpoint.
63
+ """
64
+ return getattr(func, MutationEndpoint.METADATA_KEY, False)
65
+
66
+
67
+ BASEMODEL_T = TypeVar("BASEMODEL_T", bound=BaseModel)
68
+
69
+
70
+ class SplitInputOutput:
71
+ """
72
+ Decorator to mark a Pydantic model to generate separate Input and Output TypeScript interfaces.
73
+
74
+ Input interface: Used for API inputs (mutations/queries), handles optional fields with defaults
75
+ Output interface: Used for API outputs, represents the complete object structure
76
+ """
77
+
78
+ METADATA_KEY = "__jararaca_split_input_output__"
79
+
80
+ def __init__(self) -> None:
81
+ pass
82
+
83
+ def __call__(self, cls: type[BASEMODEL_T]) -> type[BASEMODEL_T]:
84
+ """
85
+ Decorate the Pydantic model class to mark it for split interface generation.
86
+ """
87
+ setattr(cls, self.METADATA_KEY, True)
88
+ return cls
89
+
90
+ @staticmethod
91
+ def is_split_model(cls: type) -> bool:
92
+ """
93
+ Check if the Pydantic model is marked for split interface generation.
94
+ """
95
+ return getattr(cls, SplitInputOutput.METADATA_KEY, False)