nsj-rest-lib2 0.0.10__tar.gz → 0.0.12__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.
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/PKG-INFO +1 -1
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/compiler.py +21 -14
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/dto_compiler.py +28 -1
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/column_meta_model.py +1 -1
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/trait_property_meta_model.py +6 -0
- nsj_rest_lib2-0.0.12/nsj_rest_lib2/compiler/model.py +45 -0
- nsj_rest_lib2-0.0.12/nsj_rest_lib2/compiler/property_compiler.py +862 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/service/entity_loader.py +57 -11
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2.egg-info/PKG-INFO +1 -1
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2.egg-info/SOURCES.txt +2 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/setup.cfg +1 -1
- nsj_rest_lib2-0.0.10/nsj_rest_lib2/compiler/property_compiler.py +0 -522
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/README.md +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/ai_compiler.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/compiler_structures.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/ai_entity_edl.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/api_model.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/entity_model.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/index_model.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/primitives.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/property_meta_model.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/edl_model/repository_model.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/entity_compiler.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/util/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/util/str_util.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/util/type_naming_util.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/compiler/util/type_util.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/controller/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/controller/dynamic_controller.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/exception.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/redis_config.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/service/__init__.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2/settings.py +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2.egg-info/dependency_links.txt +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2.egg-info/requires.txt +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/nsj_rest_lib2.egg-info/top_level.txt +0 -0
- {nsj_rest_lib2-0.0.10 → nsj_rest_lib2-0.0.12}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nsj_rest_lib2
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.12
|
|
4
4
|
Summary: Biblioteca para permitir a distribuição de rotas dinâmicas numa API, configuradas por meio de EDLs declarativos (em formato JSON).
|
|
5
5
|
Home-page: https://github.com/Nasajon/nsj_rest_lib2
|
|
6
6
|
Author: Nasajon Sistemas
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
+
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
4
5
|
from nsj_rest_lib2.compiler.compiler_structures import (
|
|
@@ -7,8 +8,8 @@ from nsj_rest_lib2.compiler.compiler_structures import (
|
|
|
7
8
|
)
|
|
8
9
|
from nsj_rest_lib2.compiler.dto_compiler import DTOCompiler
|
|
9
10
|
from nsj_rest_lib2.compiler.edl_model.primitives import REGEX_EXTERNAL_REF
|
|
10
|
-
from nsj_rest_lib2.compiler.edl_model.repository_model import RepositoryModel
|
|
11
11
|
from nsj_rest_lib2.compiler.entity_compiler import EntityCompiler
|
|
12
|
+
from nsj_rest_lib2.compiler.model import CompilerResult
|
|
12
13
|
from nsj_rest_lib2.compiler.property_compiler import EDLPropertyCompiler
|
|
13
14
|
|
|
14
15
|
from nsj_rest_lib2.compiler.edl_model.entity_model import EntityModel
|
|
@@ -26,17 +27,6 @@ from nsj_rest_lib2.settings import get_logger
|
|
|
26
27
|
# TODO Criar imagem docker base para as aplicações, usando venv (para poderem atualizar o pydantic)
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
class CompilerResult:
|
|
30
|
-
def __init__(self):
|
|
31
|
-
self.dto_class_name: str | None = None
|
|
32
|
-
self.dto_code: str | None = None
|
|
33
|
-
self.entity_class_name: str | None = None
|
|
34
|
-
self.entity_code: str | None = None
|
|
35
|
-
self.api_expose: bool | None = None
|
|
36
|
-
self.api_resource: str | None = None
|
|
37
|
-
self.api_verbs: list[str] | None = None
|
|
38
|
-
|
|
39
|
-
|
|
40
30
|
class EDLCompiler:
|
|
41
31
|
def __init__(self) -> None:
|
|
42
32
|
self._properties_compiler = EDLPropertyCompiler()
|
|
@@ -114,6 +104,8 @@ class EDLCompiler:
|
|
|
114
104
|
props_pk,
|
|
115
105
|
enum_classes,
|
|
116
106
|
related_imports,
|
|
107
|
+
relations_dependencies,
|
|
108
|
+
fixed_filters,
|
|
117
109
|
) = self._properties_compiler.compile(
|
|
118
110
|
properties_structure,
|
|
119
111
|
map_unique_by_property,
|
|
@@ -123,7 +115,11 @@ class EDLCompiler:
|
|
|
123
115
|
|
|
124
116
|
# Gerando o código do DTO
|
|
125
117
|
dto_class_name, code_dto = self._dto_compiler.compile(
|
|
126
|
-
entity_model,
|
|
118
|
+
entity_model,
|
|
119
|
+
ast_dto_attributes,
|
|
120
|
+
enum_classes,
|
|
121
|
+
related_imports,
|
|
122
|
+
fixed_filters,
|
|
127
123
|
)
|
|
128
124
|
|
|
129
125
|
# Gerando o código da Entity
|
|
@@ -142,6 +138,7 @@ class EDLCompiler:
|
|
|
142
138
|
compiler_result.api_expose = entity_model.api.expose
|
|
143
139
|
compiler_result.api_resource = entity_model.api.resource
|
|
144
140
|
compiler_result.api_verbs = entity_model.api.verbs
|
|
141
|
+
compiler_result.relations_dependencies = relations_dependencies
|
|
145
142
|
|
|
146
143
|
return compiler_result
|
|
147
144
|
|
|
@@ -244,10 +241,20 @@ class EDLCompiler:
|
|
|
244
241
|
def _list_dependencies(self, entity_model: EntityModel) -> list[str]:
|
|
245
242
|
entities: list[str] = []
|
|
246
243
|
|
|
244
|
+
# Adicionando dependências por traits
|
|
247
245
|
if entity_model.trait_from:
|
|
248
246
|
entities.append(entity_model.trait_from)
|
|
249
247
|
|
|
250
|
-
# Populando com as dependências de propriedades de relacionamento
|
|
248
|
+
# Populando com as dependências de propriedades de relacionamento
|
|
249
|
+
relations = self._list_dependencies_relations(entity_model)
|
|
250
|
+
entities.extend(relations)
|
|
251
|
+
|
|
252
|
+
return entities
|
|
253
|
+
|
|
254
|
+
def _list_dependencies_relations(self, entity_model) -> list[str]:
|
|
255
|
+
entities = []
|
|
256
|
+
|
|
257
|
+
# Relacionamento 1_N
|
|
251
258
|
for pkey in entity_model.properties:
|
|
252
259
|
prop = entity_model.properties[pkey]
|
|
253
260
|
|
|
@@ -3,6 +3,7 @@ import ast
|
|
|
3
3
|
import black
|
|
4
4
|
|
|
5
5
|
from nsj_rest_lib2.compiler.edl_model.entity_model import EntityModel
|
|
6
|
+
from nsj_rest_lib2.compiler.edl_model.primitives import BasicTypes
|
|
6
7
|
from nsj_rest_lib2.compiler.util.str_util import CompilerStrUtil
|
|
7
8
|
from nsj_rest_lib2.compiler.util.type_naming_util import compile_dto_class_name
|
|
8
9
|
|
|
@@ -17,6 +18,7 @@ class DTOCompiler:
|
|
|
17
18
|
ast_dto_attributes: list[ast.stmt],
|
|
18
19
|
enum_classes: list[ast.stmt],
|
|
19
20
|
related_imports: list[tuple[str, str, str]],
|
|
21
|
+
fixed_filters: list[tuple[str, BasicTypes]],
|
|
20
22
|
) -> tuple[str, str]:
|
|
21
23
|
"""
|
|
22
24
|
Compila o código do DTO a partir do AST e retorna o código compilado.
|
|
@@ -71,6 +73,18 @@ class DTOCompiler:
|
|
|
71
73
|
names=[ast.alias(name="DTOBase", asname=None)],
|
|
72
74
|
level=0,
|
|
73
75
|
),
|
|
76
|
+
# from nsj_rest_lib.descriptor.dto_left_join_field import EntityRelationOwner
|
|
77
|
+
ast.ImportFrom(
|
|
78
|
+
module="nsj_rest_lib.descriptor.dto_left_join_field",
|
|
79
|
+
names=[ast.alias(name="EntityRelationOwner", asname=None)],
|
|
80
|
+
level=0,
|
|
81
|
+
),
|
|
82
|
+
# from nsj_rest_lib.descriptor.dto_object_field import DTOObjectField
|
|
83
|
+
ast.ImportFrom(
|
|
84
|
+
module="nsj_rest_lib.descriptor.dto_object_field",
|
|
85
|
+
names=[ast.alias(name="DTOObjectField", asname=None)],
|
|
86
|
+
level=0,
|
|
87
|
+
),
|
|
74
88
|
]
|
|
75
89
|
|
|
76
90
|
for import_ in related_imports:
|
|
@@ -89,6 +103,19 @@ class DTOCompiler:
|
|
|
89
103
|
)
|
|
90
104
|
)
|
|
91
105
|
|
|
106
|
+
# Keywords para tipos usados em fixed_filters
|
|
107
|
+
keywords_decorator_dto = []
|
|
108
|
+
for fixed_filter in fixed_filters:
|
|
109
|
+
keywords_decorator_dto.append(
|
|
110
|
+
ast.keyword(
|
|
111
|
+
arg="fixed_filters",
|
|
112
|
+
value=ast.Dict(
|
|
113
|
+
keys=[ast.Constant(value=fixed_filter[0])],
|
|
114
|
+
values=[ast.Constant(value=fixed_filter[1])],
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
|
|
92
119
|
# Criando o ast da classe
|
|
93
120
|
class_name = compile_dto_class_name(entity_model.id)
|
|
94
121
|
ast_class = ast.ClassDef(
|
|
@@ -99,7 +126,7 @@ class DTOCompiler:
|
|
|
99
126
|
ast.Call(
|
|
100
127
|
func=ast.Name(id="DTO", ctx=ast.Load()),
|
|
101
128
|
args=[],
|
|
102
|
-
keywords=
|
|
129
|
+
keywords=keywords_decorator_dto,
|
|
103
130
|
)
|
|
104
131
|
],
|
|
105
132
|
body=ast_dto_attributes,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
1
2
|
from pydantic import BaseModel, Field
|
|
2
3
|
|
|
3
4
|
from nsj_rest_lib2.compiler.edl_model.primitives import BasicTypes, PropertyType
|
|
5
|
+
from nsj_rest_lib2.compiler.edl_model.property_meta_model import DomainConfigModel
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
class TraitPropertyMetaModel(BaseModel):
|
|
@@ -8,3 +10,7 @@ class TraitPropertyMetaModel(BaseModel):
|
|
|
8
10
|
value: BasicTypes = Field(
|
|
9
11
|
..., description="Valor fixo da propriedade de condicionamento do trait."
|
|
10
12
|
)
|
|
13
|
+
domain_config: Optional[List[DomainConfigModel]] = Field(
|
|
14
|
+
None,
|
|
15
|
+
description="Lista de valores permitidos.",
|
|
16
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RelationDependency:
|
|
7
|
+
def __init__(self):
|
|
8
|
+
self.tenant: int | None = None
|
|
9
|
+
self.grupo_empresarial: uuid.UUID | None = None
|
|
10
|
+
self.entity_resource: str | None = None
|
|
11
|
+
self.entity_scope: str | None = None
|
|
12
|
+
|
|
13
|
+
def to_dict(self) -> dict[str, Any]:
|
|
14
|
+
return {
|
|
15
|
+
"tenant": self.tenant,
|
|
16
|
+
"grupo_empresarial": (
|
|
17
|
+
str(self.grupo_empresarial) if self.grupo_empresarial else None
|
|
18
|
+
),
|
|
19
|
+
"entity_resource": self.entity_resource,
|
|
20
|
+
"entity_scope": self.entity_scope,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def from_dict(self, data: dict[str, Any]) -> "RelationDependency":
|
|
24
|
+
self.tenant = data.get("tenant")
|
|
25
|
+
self.grupo_empresarial = (
|
|
26
|
+
uuid.UUID(data["grupo_empresarial"])
|
|
27
|
+
if data.get("grupo_empresarial")
|
|
28
|
+
else None
|
|
29
|
+
)
|
|
30
|
+
self.entity_resource = data.get("entity_resource")
|
|
31
|
+
self.entity_scope = data.get("entity_scope")
|
|
32
|
+
|
|
33
|
+
return self
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class CompilerResult:
|
|
37
|
+
def __init__(self):
|
|
38
|
+
self.dto_class_name: str | None = None
|
|
39
|
+
self.dto_code: str | None = None
|
|
40
|
+
self.entity_class_name: str | None = None
|
|
41
|
+
self.entity_code: str | None = None
|
|
42
|
+
self.api_expose: bool | None = None
|
|
43
|
+
self.api_resource: str | None = None
|
|
44
|
+
self.api_verbs: list[str] | None = None
|
|
45
|
+
self.relations_dependencies: list[RelationDependency] | None = None
|