nsj-rest-lib2 0.0.29__py3-none-any.whl → 0.0.31__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.
@@ -1,5 +1,3 @@
1
- import re
2
-
3
1
  from typing import Any
4
2
 
5
3
  from nsj_rest_lib2.compiler.compiler_structures import (
@@ -18,7 +16,6 @@ from nsj_rest_lib2.compiler.function_model import (
18
16
  )
19
17
  from nsj_rest_lib2.compiler.edl_model.entity_model_base import EntityModelBase
20
18
  from nsj_rest_lib2.compiler.edl_model.entity_model_root import EntityModelRoot
21
- from nsj_rest_lib2.compiler.edl_model.primitives import REGEX_EXTERNAL_REF
22
19
  from nsj_rest_lib2.compiler.entity_compiler import EntityCompiler
23
20
  from nsj_rest_lib2.compiler.model import CompilerResult, RelationDependency
24
21
  from nsj_rest_lib2.compiler.property_compiler import EDLPropertyCompiler
@@ -28,6 +25,7 @@ from nsj_rest_lib2.compiler.util.type_naming_util import (
28
25
  compile_entity_class_name,
29
26
  compile_namespace_keys,
30
27
  )
28
+ from nsj_rest_lib2.compiler.util.relation_ref import RelationRefParser
31
29
 
32
30
  from nsj_rest_lib2.compiler.edl_model.entity_model import EntityModel
33
31
 
@@ -496,6 +494,7 @@ class EDLCompiler:
496
494
  properties_structure: PropertiesCompilerStructure,
497
495
  entity_model: EntityModelBase,
498
496
  entity_models: dict[str, EntityModel],
497
+ relation_type: str = "self",
499
498
  ):
500
499
  if not entity_model:
501
500
  return
@@ -511,6 +510,7 @@ class EDLCompiler:
511
510
  properties_structure,
512
511
  mixin_model,
513
512
  entity_models,
513
+ relation_type="mixin",
514
514
  )
515
515
 
516
516
  # Populando com as propriedades da superclasse (extends)
@@ -521,6 +521,7 @@ class EDLCompiler:
521
521
  properties_structure,
522
522
  super_model,
523
523
  entity_models,
524
+ relation_type="extends",
524
525
  )
525
526
 
526
527
  # Populando com as propriedades do trait
@@ -531,10 +532,18 @@ class EDLCompiler:
531
532
  properties_structure,
532
533
  trait_model,
533
534
  entity_models,
535
+ relation_type="trait",
534
536
  )
535
537
 
536
538
  # Populando com as propriedades da entidade atual
537
539
  properties_structure.properties.update(entity_model.properties)
540
+ for prop_name in entity_model.properties or {}:
541
+ # Preferimos não sobrescrever quando já marcado como 'self'
542
+ if (
543
+ prop_name not in properties_structure.property_origins
544
+ or relation_type == "self"
545
+ ):
546
+ properties_structure.property_origins[prop_name] = relation_type
538
547
  if entity_model.main_properties:
539
548
  for main_property in entity_model.main_properties:
540
549
  if not isinstance(main_property, str):
@@ -706,10 +715,10 @@ class EDLCompiler:
706
715
  prop = entity_model.properties[pkey]
707
716
 
708
717
  if isinstance(prop.type, str):
709
- external_match = re.match(REGEX_EXTERNAL_REF, prop.type)
710
- if external_match:
711
- external_dependency = external_match.group(0)
712
- entities.append(external_dependency)
718
+ relation_ref = RelationRefParser.parse(prop.type)
719
+ if relation_ref and relation_ref.is_external:
720
+ if relation_ref.entity_key:
721
+ entities.append(relation_ref.entity_key)
713
722
 
714
723
  return entities
715
724
 
@@ -27,6 +27,7 @@ class PropertiesCompilerStructure:
27
27
  self.trait_properties: dict[str, TraitPropertyMetaModel] = {}
28
28
  self.extends_properties: dict[str, ExtendsPropertyMetaModel] = {}
29
29
  self.composed_properties: dict[str, list[str]] = {}
30
+ self.property_origins: dict[str, str] = {}
30
31
 
31
32
 
32
33
  class ComponentsCompilerStructure:
@@ -41,6 +41,11 @@ class DTOCompiler:
41
41
  imports = [
42
42
  # import datetime
43
43
  ast.Import(names=[ast.alias(name="datetime", asname=None)]),
44
+ # import dateutil
45
+ ast.ImportFrom(module="dateutil.relativedelta",
46
+ names=[ast.alias(name="relativedelta")],
47
+ level=0),
48
+
44
49
  # import enum
45
50
  ast.Import(names=[ast.alias(name="enum", asname=None)]),
46
51
  # import uuid
@@ -81,10 +86,10 @@ class DTOCompiler:
81
86
  names=[ast.alias(name="EntityRelationOwner", asname=None)],
82
87
  level=0,
83
88
  ),
84
- # from nsj_rest_lib.descriptor.dto_object_field import DTOObjectField
89
+ # from nsj_rest_lib.descriptor.dto_object_field import DTOOneToOneField
85
90
  ast.ImportFrom(
86
- module="nsj_rest_lib.descriptor.dto_object_field",
87
- names=[ast.alias(name="DTOObjectField", asname=None)],
91
+ module="nsj_rest_lib.descriptor.dto_one_to_one_field",
92
+ names=[ast.alias(name="DTOOneToOneField", asname=None), ast.alias(name="OTORelationType", asname=None) ],
88
93
  level=0,
89
94
  ),
90
95
  # from nsj_rest_lib.descriptor import DTOAggregator
@@ -94,6 +99,7 @@ class DTOCompiler:
94
99
  level=0,
95
100
  ),
96
101
  ]
102
+
97
103
 
98
104
  for import_ in related_imports:
99
105
  imports.append(
@@ -4,15 +4,20 @@ from typing import Annotated, List, Union
4
4
  from pydantic import StringConstraints
5
5
 
6
6
  REGEX_EXTERNAL_REF = r"^(\w+)\/(\w+)$"
7
- REGEX_INTERNAL_REF = r"^#\/components\/(\w+)$"
7
+ REGEX_EXTERNAL_COMPONENT_REF = r"^(\w+)\/(\w+)\/([\w\/#]+)$"
8
+ REGEX_INTERNAL_REF = r"^#\/components\/([\w\/#]+)$"
8
9
 
9
10
  ExternalRefType = Annotated[str, StringConstraints(pattern=REGEX_EXTERNAL_REF)]
11
+ ExternalComponentRefType = Annotated[
12
+ str, StringConstraints(pattern=REGEX_EXTERNAL_COMPONENT_REF)
13
+ ]
10
14
  InternalRefType = Annotated[str, StringConstraints(pattern=REGEX_INTERNAL_REF)]
11
15
 
12
16
 
13
17
  class PrimitiveTypes(enum.Enum):
14
18
  # TODO Validar esses tipos
15
19
  STRING = "string"
20
+ TEXT = "text"
16
21
  NUMBER = "number"
17
22
  INTEGER = "integer"
18
23
  BOOLEAN = "boolean"
@@ -25,12 +30,16 @@ class PrimitiveTypes(enum.Enum):
25
30
  EMAIL = "email"
26
31
  DATE = "date"
27
32
  DATETIME = "datetime"
33
+ DURATION = "duration"
28
34
 
29
35
 
30
- PropertyType = Union[PrimitiveTypes, ExternalRefType, InternalRefType]
36
+ PropertyType = Union[
37
+ PrimitiveTypes, ExternalRefType, ExternalComponentRefType, InternalRefType
38
+ ]
31
39
 
32
40
  MAPPING_PRIMITIVE_TYPES_TO_PYTHON = {
33
41
  PrimitiveTypes.STRING: "str",
42
+ PrimitiveTypes.TEXT: "str",
34
43
  PrimitiveTypes.NUMBER: "float",
35
44
  PrimitiveTypes.INTEGER: "int",
36
45
  PrimitiveTypes.BOOLEAN: "bool",
@@ -43,6 +52,7 @@ MAPPING_PRIMITIVE_TYPES_TO_PYTHON = {
43
52
  PrimitiveTypes.EMAIL: "str",
44
53
  PrimitiveTypes.DATE: "datetime.date",
45
54
  PrimitiveTypes.DATETIME: "datetime.datetime",
55
+ PrimitiveTypes.DURATION: "relativedelta",
46
56
  }
47
57
 
48
58
  BasicTypes = int | bool | float | str
@@ -50,6 +60,7 @@ DefaultTypes = BasicTypes | List[BasicTypes]
50
60
 
51
61
  STR_BASED_TYPES = {
52
62
  PrimitiveTypes.STRING,
63
+ PrimitiveTypes.TEXT,
53
64
  PrimitiveTypes.EMAIL,
54
65
  PrimitiveTypes.CPF,
55
66
  PrimitiveTypes.CNPJ,
@@ -24,6 +24,10 @@ class EntityCompiler:
24
24
  imports = [
25
25
  # import datetime
26
26
  ast.Import(names=[ast.alias(name="datetime", asname=None)]),
27
+ # import dateutil
28
+ ast.ImportFrom(module="dateutil.relativedelta",
29
+ names=[ast.alias(name="relativedelta")],
30
+ level=0),
27
31
  # import uuid
28
32
  ast.Import(names=[ast.alias(name="uuid", asname=None)]),
29
33
  # from nsj_rest_lib.entity.entity_base import EntityBase