jararaca 0.3.12a5__py3-none-any.whl → 0.3.12a6__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.
- jararaca/__init__.py +5 -0
- jararaca/cli.py +2 -0
- jararaca/tools/typescript/__init__.py +0 -0
- jararaca/tools/typescript/decorators.py +51 -0
- jararaca/tools/typescript/interface_parser.py +55 -7
- {jararaca-0.3.12a5.dist-info → jararaca-0.3.12a6.dist-info}/METADATA +1 -1
- {jararaca-0.3.12a5.dist-info → jararaca-0.3.12a6.dist-info}/RECORD +11 -9
- pyproject.toml +1 -1
- {jararaca-0.3.12a5.dist-info → jararaca-0.3.12a6.dist-info}/LICENSE +0 -0
- {jararaca-0.3.12a5.dist-info → jararaca-0.3.12a6.dist-info}/WHEEL +0 -0
- {jararaca-0.3.12a5.dist-info → jararaca-0.3.12a6.dist-info}/entry_points.txt +0 -0
jararaca/__init__.py
CHANGED
|
@@ -160,6 +160,7 @@ if TYPE_CHECKING:
|
|
|
160
160
|
from .presentation.websocket.websocket_interceptor import WebSocketInterceptor
|
|
161
161
|
from .scheduler.decorators import ScheduledAction
|
|
162
162
|
from .tools.app_config.interceptor import AppConfigurationInterceptor
|
|
163
|
+
from .tools.typescript.decorators import MutationEndpoint, QueryEndpoint
|
|
163
164
|
|
|
164
165
|
__all__ = [
|
|
165
166
|
"SetMetadata",
|
|
@@ -261,6 +262,8 @@ if TYPE_CHECKING:
|
|
|
261
262
|
"MessageBusPublisherInterceptor",
|
|
262
263
|
"RedisWebSocketConnectionBackend",
|
|
263
264
|
"AppConfigurationInterceptor",
|
|
265
|
+
"QueryEndpoint",
|
|
266
|
+
"MutationEndpoint",
|
|
264
267
|
"UseMiddleware",
|
|
265
268
|
"UseDependency",
|
|
266
269
|
"GlobalHttpErrorHandler",
|
|
@@ -473,6 +476,8 @@ _dynamic_imports: "dict[str, tuple[str, str, str | None]]" = {
|
|
|
473
476
|
"tools.app_config.interceptor",
|
|
474
477
|
None,
|
|
475
478
|
),
|
|
479
|
+
"QueryEndpoint": (__SPEC_PARENT__, "tools.typescript.decorators", None),
|
|
480
|
+
"MutationEndpoint": (__SPEC_PARENT__, "tools.typescript.decorators", None),
|
|
476
481
|
"UseMiddleware": (__SPEC_PARENT__, "presentation.decorators", None),
|
|
477
482
|
"UseDependency": (__SPEC_PARENT__, "presentation.decorators", None),
|
|
478
483
|
"GlobalHttpErrorHandler": (__SPEC_PARENT__, "rpc.http.decorators", None),
|
jararaca/cli.py
CHANGED
|
@@ -5,6 +5,7 @@ import multiprocessing
|
|
|
5
5
|
import os
|
|
6
6
|
import sys
|
|
7
7
|
import time
|
|
8
|
+
import traceback
|
|
8
9
|
from codecs import StreamWriter
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
from typing import Any, Callable
|
|
@@ -615,6 +616,7 @@ def generate_interfaces(
|
|
|
615
616
|
return content
|
|
616
617
|
except Exception as e:
|
|
617
618
|
click.echo(f"Error generating TypeScript interfaces: {e}", file=sys.stderr)
|
|
619
|
+
traceback.print_exc(file=sys.stderr)
|
|
618
620
|
return ""
|
|
619
621
|
|
|
620
622
|
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Any, Callable, TypeVar
|
|
2
|
+
|
|
3
|
+
DECORATED_FUNC = TypeVar("DECORATED_FUNC", bound=Callable[..., Any])
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class QueryEndpoint:
|
|
7
|
+
"""
|
|
8
|
+
Decorator to mark a endpoint function as a query endpoint for Typescript generation.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
METADATA_KEY = "__jararaca_query_endpoint__"
|
|
12
|
+
|
|
13
|
+
def __init__(self) -> None: ...
|
|
14
|
+
|
|
15
|
+
def __call__(self, func: DECORATED_FUNC) -> DECORATED_FUNC:
|
|
16
|
+
"""
|
|
17
|
+
Decorate the function to mark it as a query endpoint.
|
|
18
|
+
"""
|
|
19
|
+
setattr(func, self.METADATA_KEY, True)
|
|
20
|
+
return func
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def is_query(func: Any) -> bool:
|
|
24
|
+
"""
|
|
25
|
+
Check if the function is marked as a query endpoint.
|
|
26
|
+
"""
|
|
27
|
+
return getattr(func, QueryEndpoint.METADATA_KEY, False)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class MutationEndpoint:
|
|
31
|
+
"""
|
|
32
|
+
Decorator to mark a endpoint function as a mutation endpoint for Typescript generation.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
METADATA_KEY = "__jararaca_mutation_endpoint__"
|
|
36
|
+
|
|
37
|
+
def __init__(self) -> None: ...
|
|
38
|
+
|
|
39
|
+
def __call__(self, func: DECORATED_FUNC) -> DECORATED_FUNC:
|
|
40
|
+
"""
|
|
41
|
+
Decorate the function to mark it as a mutation endpoint.
|
|
42
|
+
"""
|
|
43
|
+
setattr(func, self.METADATA_KEY, True)
|
|
44
|
+
return func
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def is_mutation(func: Any) -> bool:
|
|
48
|
+
"""
|
|
49
|
+
Check if the function is marked as a mutation endpoint.
|
|
50
|
+
"""
|
|
51
|
+
return getattr(func, MutationEndpoint.METADATA_KEY, False)
|
|
@@ -8,7 +8,7 @@ from datetime import date, datetime, time
|
|
|
8
8
|
from decimal import Decimal
|
|
9
9
|
from enum import Enum
|
|
10
10
|
from io import StringIO
|
|
11
|
-
from types import NoneType, UnionType
|
|
11
|
+
from types import FunctionType, NoneType, UnionType
|
|
12
12
|
from typing import (
|
|
13
13
|
IO,
|
|
14
14
|
Annotated,
|
|
@@ -35,6 +35,7 @@ from jararaca.presentation.websocket.decorators import RegisterWebSocketMessage
|
|
|
35
35
|
from jararaca.presentation.websocket.websocket_interceptor import (
|
|
36
36
|
WebSocketMessageWrapper,
|
|
37
37
|
)
|
|
38
|
+
from jararaca.tools.typescript.decorators import MutationEndpoint, QueryEndpoint
|
|
38
39
|
|
|
39
40
|
CONSTANT_PATTERN = re.compile(r"^[A-Z_]+$")
|
|
40
41
|
|
|
@@ -67,6 +68,13 @@ def snake_to_camel(snake_str: str) -> str:
|
|
|
67
68
|
return components[0] + "".join(x.title() for x in components[1:])
|
|
68
69
|
|
|
69
70
|
|
|
71
|
+
def pascal_to_camel(pascal_str: str) -> str:
|
|
72
|
+
"""Convert a PascalCase string to camelCase."""
|
|
73
|
+
if not pascal_str:
|
|
74
|
+
return pascal_str
|
|
75
|
+
return pascal_str[0].lower() + pascal_str[1:]
|
|
76
|
+
|
|
77
|
+
|
|
70
78
|
def parse_literal_value(value: Any) -> str:
|
|
71
79
|
if value is None:
|
|
72
80
|
return "null"
|
|
@@ -354,12 +362,17 @@ def write_microservice_to_typescript_interface(
|
|
|
354
362
|
if rest_controller is None:
|
|
355
363
|
continue
|
|
356
364
|
|
|
357
|
-
|
|
358
|
-
|
|
365
|
+
controller_class_strio, types, hooks_strio = (
|
|
366
|
+
write_rest_controller_to_typescript_interface(
|
|
367
|
+
rest_controller,
|
|
368
|
+
controller,
|
|
369
|
+
)
|
|
359
370
|
)
|
|
360
371
|
|
|
361
372
|
mapped_types_set.update(types)
|
|
362
|
-
rest_controller_buffer.write(
|
|
373
|
+
rest_controller_buffer.write(controller_class_strio.getvalue())
|
|
374
|
+
if hooks_strio is not None:
|
|
375
|
+
rest_controller_buffer.write(hooks_strio.getvalue())
|
|
363
376
|
|
|
364
377
|
registered = RegisterWebSocketMessage.get(controller)
|
|
365
378
|
|
|
@@ -376,6 +389,7 @@ def write_microservice_to_typescript_interface(
|
|
|
376
389
|
|
|
377
390
|
final_buffer.write(
|
|
378
391
|
"""
|
|
392
|
+
import { createClassQueryHooks , createClassMutationHooks, createClassInfiniteQueryHooks } from "@jararaca/core";
|
|
379
393
|
export type WebSocketMessageMap = {
|
|
380
394
|
%s
|
|
381
395
|
}
|
|
@@ -494,11 +508,16 @@ def is_primitive(field_type: Any) -> bool:
|
|
|
494
508
|
|
|
495
509
|
def write_rest_controller_to_typescript_interface(
|
|
496
510
|
rest_controller: RestController, controller: type
|
|
497
|
-
) -> tuple[
|
|
511
|
+
) -> tuple[StringIO, set[Any], StringIO | None]:
|
|
512
|
+
|
|
513
|
+
class_name = controller.__name__
|
|
514
|
+
|
|
515
|
+
decorated_queries: list[tuple[str, FunctionType]] = []
|
|
516
|
+
decorated_mutations: list[tuple[str, FunctionType]] = []
|
|
498
517
|
|
|
499
518
|
class_buffer = StringIO()
|
|
500
519
|
|
|
501
|
-
class_buffer.write(f"export class {
|
|
520
|
+
class_buffer.write(f"export class {class_name} extends HttpService {{\n")
|
|
502
521
|
|
|
503
522
|
mapped_types: set[Any] = set()
|
|
504
523
|
|
|
@@ -514,6 +533,11 @@ def write_rest_controller_to_typescript_interface(
|
|
|
514
533
|
if return_type is None:
|
|
515
534
|
return_type = NoneType
|
|
516
535
|
|
|
536
|
+
if QueryEndpoint.is_query(member):
|
|
537
|
+
decorated_queries.append((name, member))
|
|
538
|
+
if MutationEndpoint.is_mutation(member):
|
|
539
|
+
decorated_mutations.append((name, member))
|
|
540
|
+
|
|
517
541
|
mapped_types.update(extract_all_envolved_types(return_type))
|
|
518
542
|
|
|
519
543
|
return_value_repr = get_field_type_for_ts(return_type)
|
|
@@ -588,7 +612,31 @@ def write_rest_controller_to_typescript_interface(
|
|
|
588
612
|
|
|
589
613
|
class_buffer.write("}\n")
|
|
590
614
|
|
|
591
|
-
|
|
615
|
+
controller_hooks_builder: StringIO | None = None
|
|
616
|
+
|
|
617
|
+
if decorated_queries or decorated_mutations:
|
|
618
|
+
controller_hooks_builder = StringIO()
|
|
619
|
+
controller_hooks_builder.write(
|
|
620
|
+
f"export const {pascal_to_camel(class_name)} = {{\n"
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
if decorated_queries:
|
|
624
|
+
controller_hooks_builder.write(
|
|
625
|
+
f"\t...createClassQueryHooks({class_name},\n"
|
|
626
|
+
)
|
|
627
|
+
for name, member in decorated_queries:
|
|
628
|
+
controller_hooks_builder.write(f'\t\t"{snake_to_camel(name)}",\n')
|
|
629
|
+
controller_hooks_builder.write("\t),\n")
|
|
630
|
+
if decorated_mutations:
|
|
631
|
+
controller_hooks_builder.write(
|
|
632
|
+
f"\t...createClassMutationHooks({class_name},\n"
|
|
633
|
+
)
|
|
634
|
+
for name, member in decorated_mutations:
|
|
635
|
+
controller_hooks_builder.write(f'\t\t"{snake_to_camel(name)}",\n')
|
|
636
|
+
controller_hooks_builder.write("\t),\n")
|
|
637
|
+
controller_hooks_builder.write("};\n")
|
|
638
|
+
|
|
639
|
+
return class_buffer, mapped_types, controller_hooks_builder
|
|
592
640
|
|
|
593
641
|
|
|
594
642
|
EXCLUDED_REQUESTS_TYPES = [Request, Response]
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
2
2
|
README.md,sha256=2qMM__t_MoLKZr4IY9tXjo-Jn6LKjuHMb1qbyXpgL08,3401
|
|
3
|
-
pyproject.toml,sha256=
|
|
4
|
-
jararaca/__init__.py,sha256=
|
|
3
|
+
pyproject.toml,sha256=3e1dOSeKg1pARRUHFxJ0d5wOPiGtoe4YiAqf3VngI6o,2040
|
|
4
|
+
jararaca/__init__.py,sha256=jN3paW2ujI97485DNZTcRe_8ORwO-OQbJUG5mmSI9LI,21226
|
|
5
5
|
jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
|
|
6
6
|
jararaca/broker_backend/__init__.py,sha256=GzEIuHR1xzgCJD4FE3harNjoaYzxHMHoEL0_clUaC-k,3528
|
|
7
7
|
jararaca/broker_backend/mapper.py,sha256=vTsi7sWpNvlga1PWPFg0rCJ5joJ0cdzykkIc2Tuvenc,696
|
|
8
8
|
jararaca/broker_backend/redis_broker_backend.py,sha256=a7DHchy3NAiD71Ix8SwmQOUnniu7uup-Woa4ON_4J7I,5786
|
|
9
|
-
jararaca/cli.py,sha256=
|
|
9
|
+
jararaca/cli.py,sha256=n3fTOVSNFNICmbZrLCJNGctpbqLWp39xTSkqlIB6Rds,32005
|
|
10
10
|
jararaca/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
jararaca/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
jararaca/core/providers.py,sha256=wktH84FK7c1s2wNq-fudf1uMfi3CQBR0neU2czJ_L0U,434
|
|
@@ -66,12 +66,14 @@ jararaca/scheduler/types.py,sha256=4HEQOmVIDp-BYLSzqmqSFIio1bd51WFmgFPIzPpVu04,1
|
|
|
66
66
|
jararaca/tools/app_config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
67
|
jararaca/tools/app_config/decorators.py,sha256=-ckkMZ1dswOmECdo1rFrZ15UAku--txaNXMp8fd1Ndk,941
|
|
68
68
|
jararaca/tools/app_config/interceptor.py,sha256=HV8h4AxqUc_ACs5do4BSVlyxlRXzx7HqJtoVO9tfRnQ,2611
|
|
69
|
-
jararaca/tools/typescript/
|
|
69
|
+
jararaca/tools/typescript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
|
+
jararaca/tools/typescript/decorators.py,sha256=F-4de0OKN4VrXCwtfsts1XaycGkXqSGuDKW6ElryMsY,1409
|
|
71
|
+
jararaca/tools/typescript/interface_parser.py,sha256=dc-h74yaySqXklqIDXuIQUN9wwqEE7q4uGWQ4nByI84,33462
|
|
70
72
|
jararaca/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
71
73
|
jararaca/utils/rabbitmq_utils.py,sha256=ytdAFUyv-OBkaVnxezuJaJoLrmN7giZgtKeet_IsMBs,10918
|
|
72
74
|
jararaca/utils/retry.py,sha256=DzPX_fXUvTqej6BQ8Mt2dvLo9nNlTBm7Kx2pFZ26P2Q,4668
|
|
73
|
-
jararaca-0.3.
|
|
74
|
-
jararaca-0.3.
|
|
75
|
-
jararaca-0.3.
|
|
76
|
-
jararaca-0.3.
|
|
77
|
-
jararaca-0.3.
|
|
75
|
+
jararaca-0.3.12a6.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
76
|
+
jararaca-0.3.12a6.dist-info/METADATA,sha256=XPCPH0zrpKaicneY3XJSnwbgVvLlDlS4kfSWblCorWE,4995
|
|
77
|
+
jararaca-0.3.12a6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
78
|
+
jararaca-0.3.12a6.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
|
|
79
|
+
jararaca-0.3.12a6.dist-info/RECORD,,
|
pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|