nsj-rest-lib2 0.0.14__py3-none-any.whl → 0.0.15__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.
- nsj_rest_lib2/compiler/compiler.py +55 -18
- nsj_rest_lib2/compiler/edl_model/entity_model.py +2 -3
- nsj_rest_lib2/compiler/edl_model/entity_model_base.py +4 -0
- nsj_rest_lib2/compiler/edl_model/entity_model_mixin.py +7 -0
- nsj_rest_lib2/compiler/property_compiler.py +9 -8
- nsj_rest_lib2/service/entity_loader.py +6 -0
- {nsj_rest_lib2-0.0.14.dist-info → nsj_rest_lib2-0.0.15.dist-info}/METADATA +1 -1
- {nsj_rest_lib2-0.0.14.dist-info → nsj_rest_lib2-0.0.15.dist-info}/RECORD +10 -9
- {nsj_rest_lib2-0.0.14.dist-info → nsj_rest_lib2-0.0.15.dist-info}/WHEEL +0 -0
- {nsj_rest_lib2-0.0.14.dist-info → nsj_rest_lib2-0.0.15.dist-info}/top_level.txt +0 -0
|
@@ -9,6 +9,7 @@ from nsj_rest_lib2.compiler.compiler_structures import (
|
|
|
9
9
|
)
|
|
10
10
|
from nsj_rest_lib2.compiler.dto_compiler import DTOCompiler
|
|
11
11
|
from nsj_rest_lib2.compiler.edl_model.entity_model_base import EntityModelBase
|
|
12
|
+
from nsj_rest_lib2.compiler.edl_model.entity_model_mixin import EntityModelMixin
|
|
12
13
|
from nsj_rest_lib2.compiler.edl_model.primitives import REGEX_EXTERNAL_REF
|
|
13
14
|
from nsj_rest_lib2.compiler.entity_compiler import EntityCompiler
|
|
14
15
|
from nsj_rest_lib2.compiler.model import CompilerResult
|
|
@@ -22,7 +23,6 @@ from nsj_rest_lib2.settings import get_logger
|
|
|
22
23
|
# TODO Implementar suporte a conjuntos
|
|
23
24
|
# TODO Autenticação nas rotas
|
|
24
25
|
# TODO Atualizar o status da entidade pelo worker de compilação (e talvez parar uma compilação, quando se delete uma entidade)
|
|
25
|
-
# TODO Mixins
|
|
26
26
|
# TODO Classes Abstratas
|
|
27
27
|
# TODO Partial Classes
|
|
28
28
|
# TODO Migrations
|
|
@@ -44,8 +44,8 @@ class EDLCompiler:
|
|
|
44
44
|
compiler_results = []
|
|
45
45
|
for entity_model_id in entity_models:
|
|
46
46
|
entity_model = entity_models[entity_model_id]
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
compiler_result = self._compile_model(entity_model, entity_models)
|
|
48
|
+
if compiler_result:
|
|
49
49
|
compiler_results.append(compiler_result)
|
|
50
50
|
|
|
51
51
|
return compiler_results
|
|
@@ -54,27 +54,28 @@ class EDLCompiler:
|
|
|
54
54
|
self,
|
|
55
55
|
edl_json: dict[str, Any],
|
|
56
56
|
dependencies_edls: list[dict[str, Any]],
|
|
57
|
-
) -> CompilerResult:
|
|
57
|
+
) -> CompilerResult | None:
|
|
58
58
|
entity_model = EntityModel(**edl_json)
|
|
59
59
|
|
|
60
60
|
entity_models = []
|
|
61
61
|
for dependency_edl in dependencies_edls:
|
|
62
|
-
|
|
62
|
+
if "mixin" in dependency_edl and dependency_edl["mixin"]:
|
|
63
|
+
dependency_entity_model = EntityModelMixin(**dependency_edl)
|
|
64
|
+
else:
|
|
65
|
+
dependency_entity_model = EntityModel(**dependency_edl)
|
|
63
66
|
entity_models.append(dependency_entity_model)
|
|
64
67
|
|
|
65
68
|
return self.compile_model(entity_model, entity_models)
|
|
66
69
|
|
|
67
70
|
def compile_model(
|
|
68
71
|
self,
|
|
69
|
-
entity_model:
|
|
70
|
-
dependencies_models: list[
|
|
71
|
-
) -> CompilerResult:
|
|
72
|
+
entity_model: EntityModelBase,
|
|
73
|
+
dependencies_models: list[tuple[str, EntityModelBase]],
|
|
74
|
+
) -> CompilerResult | None:
|
|
72
75
|
entity_models = {}
|
|
73
76
|
for dependency_entity_model in dependencies_models:
|
|
74
|
-
complete_entity_id =
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
entity_models[complete_entity_id] = dependency_entity_model
|
|
77
|
+
complete_entity_id = dependency_entity_model[0]
|
|
78
|
+
entity_models[complete_entity_id] = dependency_entity_model[1]
|
|
78
79
|
|
|
79
80
|
return self._compile_model(entity_model, entity_models)
|
|
80
81
|
|
|
@@ -84,9 +85,11 @@ class EDLCompiler:
|
|
|
84
85
|
entity_models: dict[str, EntityModel],
|
|
85
86
|
escopo: str | None = None,
|
|
86
87
|
prefx_class_name: str = "",
|
|
87
|
-
) -> CompilerResult:
|
|
88
|
+
) -> CompilerResult | None:
|
|
89
|
+
if entity_model.mixin:
|
|
90
|
+
return None
|
|
88
91
|
|
|
89
|
-
if escopo is None and isinstance(entity_model, EntityModel):
|
|
92
|
+
if escopo is None and (isinstance(entity_model, EntityModel)):
|
|
90
93
|
escopo = entity_model.escopo
|
|
91
94
|
|
|
92
95
|
if not escopo:
|
|
@@ -148,6 +151,11 @@ class EDLCompiler:
|
|
|
148
151
|
prefx_class_name=f"{prefx_class_name}_{entity_model.id}",
|
|
149
152
|
)
|
|
150
153
|
|
|
154
|
+
if not component_compiled:
|
|
155
|
+
raise Exception(
|
|
156
|
+
f"Erro ao compilar o component '{component_key}' da entidade '{entity_model.id}'. Gerou saída None, como se fosse um mixin."
|
|
157
|
+
)
|
|
158
|
+
|
|
151
159
|
# Guardando o código gerado no buffer
|
|
152
160
|
if component_compiled.dto_code:
|
|
153
161
|
dto_code += component_compiled.dto_code + "\n\n"
|
|
@@ -195,6 +203,12 @@ class EDLCompiler:
|
|
|
195
203
|
compiler_result.api_verbs = entity_model.api.verbs
|
|
196
204
|
compiler_result.relations_dependencies = relations_dependencies_complete
|
|
197
205
|
|
|
206
|
+
get_logger().debug(f"código gerado para a entidade: {entity_model.id}")
|
|
207
|
+
get_logger().debug("DTO Code:")
|
|
208
|
+
get_logger().debug(f"\n{dto_code}")
|
|
209
|
+
get_logger().debug("Entity Code:")
|
|
210
|
+
get_logger().debug(f"\n{entity_code}")
|
|
211
|
+
|
|
198
212
|
return compiler_result
|
|
199
213
|
|
|
200
214
|
def _make_components_structures(
|
|
@@ -262,6 +276,19 @@ class EDLCompiler:
|
|
|
262
276
|
entity_model.repository.properties
|
|
263
277
|
)
|
|
264
278
|
|
|
279
|
+
# Populando com as propriedades dos mixins
|
|
280
|
+
if entity_model.mixins:
|
|
281
|
+
for mixin_id in entity_model.mixins:
|
|
282
|
+
if mixin_id not in entity_models:
|
|
283
|
+
raise Exception(f"Mixin '{mixin_id}' não encontrado.")
|
|
284
|
+
|
|
285
|
+
mixin_model = entity_models[mixin_id]
|
|
286
|
+
self._make_properties_structures(
|
|
287
|
+
properties_structure,
|
|
288
|
+
mixin_model,
|
|
289
|
+
entity_models,
|
|
290
|
+
)
|
|
291
|
+
|
|
265
292
|
def _make_unique_map_by_property(
|
|
266
293
|
self,
|
|
267
294
|
map_indexes_by_property: dict[str, list[IndexCompilerStructure]],
|
|
@@ -311,18 +338,25 @@ class EDLCompiler:
|
|
|
311
338
|
|
|
312
339
|
def list_dependencies(
|
|
313
340
|
self, edl_json: dict[str, Any]
|
|
314
|
-
) -> tuple[list[str],
|
|
315
|
-
|
|
341
|
+
) -> tuple[list[str], EntityModelBase]:
|
|
342
|
+
if edl_json.get("mixin", False):
|
|
343
|
+
entity_model = EntityModelMixin(**edl_json)
|
|
344
|
+
else:
|
|
345
|
+
entity_model = EntityModel(**edl_json)
|
|
316
346
|
|
|
317
347
|
return (self._list_dependencies(entity_model), entity_model)
|
|
318
348
|
|
|
319
|
-
def _list_dependencies(self, entity_model:
|
|
349
|
+
def _list_dependencies(self, entity_model: EntityModelBase) -> list[str]:
|
|
320
350
|
entities: list[str] = []
|
|
321
351
|
|
|
322
352
|
# Adicionando dependências por traits
|
|
323
353
|
if entity_model.trait_from:
|
|
324
354
|
entities.append(entity_model.trait_from)
|
|
325
355
|
|
|
356
|
+
# Adicionando dependências por mixins
|
|
357
|
+
if entity_model.mixins:
|
|
358
|
+
entities.extend(entity_model.mixins)
|
|
359
|
+
|
|
326
360
|
# Populando com as dependências de propriedades de relacionamento
|
|
327
361
|
relations = self._list_dependencies_relations(entity_model)
|
|
328
362
|
entities.extend(relations)
|
|
@@ -384,7 +418,10 @@ if __name__ == "__main__":
|
|
|
384
418
|
# Instanciando o objeto de modelo de entidade a partir do JSON,
|
|
385
419
|
# e já realizando as validações básicas de tipo e estrutura.
|
|
386
420
|
print(f"Validando arquivo: {file}")
|
|
387
|
-
|
|
421
|
+
if edl.get("mixin", False):
|
|
422
|
+
entity_model = EntityModelMixin(**edl)
|
|
423
|
+
else:
|
|
424
|
+
entity_model = EntityModel(**edl)
|
|
388
425
|
|
|
389
426
|
complete_entity_id = f"{entity_model.escopo}/{entity_model.id}"
|
|
390
427
|
entities[complete_entity_id] = entity_model
|
|
@@ -4,12 +4,11 @@ from pydantic import Field
|
|
|
4
4
|
from typing import Optional
|
|
5
5
|
|
|
6
6
|
from nsj_rest_lib2.compiler.edl_model.api_model import APIModel
|
|
7
|
-
from nsj_rest_lib2.compiler.edl_model.
|
|
7
|
+
from nsj_rest_lib2.compiler.edl_model.entity_model_mixin import EntityModelMixin
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class EntityModel(
|
|
10
|
+
class EntityModel(EntityModelMixin):
|
|
11
11
|
edl_version: Optional[str] = Field(default="1.0", description="Versão do EDL")
|
|
12
|
-
escopo: str = Field(..., description="Escopo do EDL (define a aplicação).")
|
|
13
12
|
version: Optional[str] = Field(
|
|
14
13
|
default="1.0", description="Versão da entidade (padrão: 1.0)."
|
|
15
14
|
)
|
|
@@ -28,6 +28,10 @@ class EntityModelBase(BaseModel):
|
|
|
28
28
|
required: Optional[List[str]] = Field(
|
|
29
29
|
None, description="Lista de campos obrigatórios no modelo."
|
|
30
30
|
)
|
|
31
|
+
mixin: Optional[bool] = Field(
|
|
32
|
+
False,
|
|
33
|
+
description="Indica se o modelo é um mixin (bloco reutilizável, que não gera contém tabela própria no banco).",
|
|
34
|
+
)
|
|
31
35
|
partition_data: Optional[List[str]] = Field(
|
|
32
36
|
None,
|
|
33
37
|
description="Lista de propriedades da entidade, que serã usadas para particionamento dos dados no banco (sendo obrigatórias em todas as chamadas, inclusive como um tipo de filtro obrigatório).",
|
|
@@ -64,14 +64,15 @@ class EDLPropertyCompiler:
|
|
|
64
64
|
if prop.pk:
|
|
65
65
|
pk_keys.append(pkey)
|
|
66
66
|
|
|
67
|
-
if
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
if not entity_model.mixin:
|
|
68
|
+
if len(pk_keys) > 1:
|
|
69
|
+
raise Exception(
|
|
70
|
+
f"Entidade '{entity_model.id}' possui mais de uma chave primária (ainda não suportado): {pk_keys}"
|
|
71
|
+
)
|
|
72
|
+
elif len(pk_keys) == 0:
|
|
73
|
+
raise Exception(
|
|
74
|
+
f"Entidade '{entity_model.id}' não tem nenhuma chave primária (ainda não suportado)"
|
|
75
|
+
)
|
|
75
76
|
|
|
76
77
|
# pk_key = pk_keys[0]
|
|
77
78
|
|
|
@@ -317,6 +317,12 @@ class EntityLoader:
|
|
|
317
317
|
namespace.module = module
|
|
318
318
|
namespace.entities_dict = module.__dict__
|
|
319
319
|
|
|
320
|
+
get_logger().debug(
|
|
321
|
+
f"Executando o código da entidade {entity_resource} no namespace {entity_config_key}. Código:"
|
|
322
|
+
)
|
|
323
|
+
get_logger().debug(f"Entity source:\n{source_entity}")
|
|
324
|
+
get_logger().debug(f"DTO source:\n{source_dto}")
|
|
325
|
+
|
|
320
326
|
self._safe_exec(source_entity, namespace.entities_dict, "Entity source")
|
|
321
327
|
self._safe_exec(source_dto, namespace.entities_dict, "DTO source")
|
|
322
328
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nsj_rest_lib2
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.15
|
|
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
|
|
@@ -4,18 +4,19 @@ nsj_rest_lib2/redis_config.py,sha256=4KLcvYS3nJO7PMQgF6F9_j6r-TyqcS7TBbd3LEQuKDU
|
|
|
4
4
|
nsj_rest_lib2/settings.py,sha256=Hn_o1HZmievnYb8D1kNT2Nq-OEjxbyNjOiOpbnFsMwE,367
|
|
5
5
|
nsj_rest_lib2/compiler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
nsj_rest_lib2/compiler/ai_compiler.py,sha256=shAtN4T0ai_52qh15L3mK1QbeC6glHOR6C3J3gj14II,9029
|
|
7
|
-
nsj_rest_lib2/compiler/compiler.py,sha256=
|
|
7
|
+
nsj_rest_lib2/compiler/compiler.py,sha256=HiBlaC_SDFFVE77UbwcWzXdcuF8G5Xaz4tzdpkHbIo4,16766
|
|
8
8
|
nsj_rest_lib2/compiler/compiler_structures.py,sha256=ZUeWnO-23f3JHq4bOfTcqszMDDXwuFEtMRhqMN7GeWQ,1214
|
|
9
9
|
nsj_rest_lib2/compiler/dto_compiler.py,sha256=KDdfzoghbsO0RpWAhuhZ4gsb11aoxgci-93dwxWNMuY,5400
|
|
10
10
|
nsj_rest_lib2/compiler/entity_compiler.py,sha256=7LypMMlgXnUIkpO7rEYtc2V1sKi9Nv1IxlXkgObX25s,4453
|
|
11
11
|
nsj_rest_lib2/compiler/model.py,sha256=QDBoM26qoZdiNcykl1nvXCrFDhg-6Q__QzVq6uY1QzE,1460
|
|
12
|
-
nsj_rest_lib2/compiler/property_compiler.py,sha256=
|
|
12
|
+
nsj_rest_lib2/compiler/property_compiler.py,sha256=AL0QW2-IqlCKJ7X4QFPEaafZ2MfNBElGF-e6KFPHPaA,35787
|
|
13
13
|
nsj_rest_lib2/compiler/edl_model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
nsj_rest_lib2/compiler/edl_model/ai_entity_edl.py,sha256=664QBDcOgVnyfwtUOXO1W7AKaZhueBG335x5DuogruY,7644
|
|
15
15
|
nsj_rest_lib2/compiler/edl_model/api_model.py,sha256=pH0Uiq_64AGvkHqwY44TrulWWZXbi6M0EKJWUhSqKj0,837
|
|
16
16
|
nsj_rest_lib2/compiler/edl_model/column_meta_model.py,sha256=s0sEVkoW1hV2_hto1mws4XhzKGH_b4NzhaOiwFH25Ks,694
|
|
17
|
-
nsj_rest_lib2/compiler/edl_model/entity_model.py,sha256
|
|
18
|
-
nsj_rest_lib2/compiler/edl_model/entity_model_base.py,sha256=
|
|
17
|
+
nsj_rest_lib2/compiler/edl_model/entity_model.py,sha256=-y_b9ZFZvdYiB_oxX64BdKyS9qDVHzknWd5R6muTEO8,857
|
|
18
|
+
nsj_rest_lib2/compiler/edl_model/entity_model_base.py,sha256=pkWBfrtz3ZTG1qvZwDUwJHE9qTkcqmOgesq3vgQKxBo,3472
|
|
19
|
+
nsj_rest_lib2/compiler/edl_model/entity_model_mixin.py,sha256=vGUYwMXcf24T4oF7Ie-cTzCvZLEa_bxCA-euBz8S7_Q,232
|
|
19
20
|
nsj_rest_lib2/compiler/edl_model/index_model.py,sha256=cXWlu0hxtro5vvYoirkDW4R3PCnBW5oCCWjRJ6AX5zE,508
|
|
20
21
|
nsj_rest_lib2/compiler/edl_model/primitives.py,sha256=GTo8e1mf9munvl_J1-fmaXgSJ8yQvGX56f2rwS85M1Y,1459
|
|
21
22
|
nsj_rest_lib2/compiler/edl_model/property_meta_model.py,sha256=x2SApvI-5MZTErAHeOXnR6qfjflhSs8r6Y9KMtCykV0,3960
|
|
@@ -28,8 +29,8 @@ nsj_rest_lib2/compiler/util/type_util.py,sha256=HTKOH4uRTOY0YgoM8oUv_6cEcReE_bgK
|
|
|
28
29
|
nsj_rest_lib2/controller/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
30
|
nsj_rest_lib2/controller/dynamic_controller.py,sha256=XMqxe1NW-NE5XwomXb4pSNdALQHpP74Hc26R4fnmXqg,15194
|
|
30
31
|
nsj_rest_lib2/service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
|
-
nsj_rest_lib2/service/entity_loader.py,sha256=
|
|
32
|
-
nsj_rest_lib2-0.0.
|
|
33
|
-
nsj_rest_lib2-0.0.
|
|
34
|
-
nsj_rest_lib2-0.0.
|
|
35
|
-
nsj_rest_lib2-0.0.
|
|
32
|
+
nsj_rest_lib2/service/entity_loader.py,sha256=uB0xXih9Px2jSTMdZNIu6_3dngE37K7adKX03cYSRug,15660
|
|
33
|
+
nsj_rest_lib2-0.0.15.dist-info/METADATA,sha256=ULdAQGwg_pghhmixzJCCPI9Qg0L-xuVonJqBkx5Rt3Y,1361
|
|
34
|
+
nsj_rest_lib2-0.0.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
35
|
+
nsj_rest_lib2-0.0.15.dist-info/top_level.txt,sha256=L6zh0EfH8_rur7OJ8_V-El-XEMf4qg3bkF8ADgqLVIA,14
|
|
36
|
+
nsj_rest_lib2-0.0.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|