nsj-rest-lib2 0.0.22__py3-none-any.whl → 0.0.23__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.
@@ -88,6 +88,10 @@ class EDLPropertyCompiler:
88
88
  if properties_structure.properties is None:
89
89
  return (ast_dto_attributes, ast_entity_attributes, props_pk, aux_classes)
90
90
 
91
+ trait_fixed_filters = self._merge_trait_extends_properties(
92
+ properties_structure
93
+ )
94
+
91
95
  composed_properties = properties_structure.composed_properties or {}
92
96
 
93
97
  aggregator_class_names: dict[str, str] = {}
@@ -151,6 +155,9 @@ class EDLPropertyCompiler:
151
155
  prefx_class_name,
152
156
  )
153
157
 
158
+ if pkey in trait_fixed_filters:
159
+ fixed_filters.append((pkey, trait_fixed_filters[pkey]))
160
+
154
161
  elif isinstance(prop.type, str):
155
162
  # Tratando propriedade de relacionamento
156
163
  external_match = re.match(REGEX_EXTERNAL_REF, prop.type)
@@ -193,40 +200,6 @@ class EDLPropertyCompiler:
193
200
  f"Tipo da propriedade '{pkey}' não suportado: {prop.type}"
194
201
  )
195
202
 
196
- for pkey in properties_structure.trait_properties:
197
- prop = properties_structure.trait_properties[pkey]
198
-
199
- self._compile_trait_extends_property(
200
- properties_structure,
201
- map_unique_by_property,
202
- pkey,
203
- prop,
204
- ast_dto_attributes,
205
- ast_entity_attributes,
206
- fixed_filters,
207
- escopo,
208
- entity_model,
209
- aux_classes,
210
- prefx_class_name,
211
- )
212
-
213
- for pkey in properties_structure.extends_properties:
214
- prop = properties_structure.extends_properties[pkey]
215
-
216
- self._compile_trait_extends_property(
217
- properties_structure,
218
- map_unique_by_property,
219
- pkey,
220
- prop,
221
- ast_dto_attributes,
222
- ast_entity_attributes,
223
- fixed_filters,
224
- escopo,
225
- entity_model,
226
- aux_classes,
227
- prefx_class_name,
228
- )
229
-
230
203
  for composed_key, class_name in aggregator_class_names.items():
231
204
  dto_attributes = aggregator_dto_attributes.get(composed_key, [])
232
205
 
@@ -254,199 +227,6 @@ class EDLPropertyCompiler:
254
227
  fixed_filters,
255
228
  )
256
229
 
257
- def _compile_trait_extends_property(
258
- self,
259
- properties_structure: PropertiesCompilerStructure,
260
- map_unique_by_property: dict[str, IndexCompilerStructure],
261
- pkey: str,
262
- prop: TraitPropertyMetaModel,
263
- ast_dto_attributes: list[ast.stmt],
264
- ast_entity_attributes: list[ast.stmt],
265
- fixed_filters: list[tuple[str, BasicTypes]],
266
- escopo: str,
267
- entity_model: EntityModelBase,
268
- aux_classes: list[ast.stmt],
269
- prefx_class_name: str,
270
- ):
271
- enum_class_name = None
272
- keywords = []
273
-
274
- if (
275
- properties_structure.main_properties
276
- and pkey in properties_structure.main_properties
277
- ):
278
- keywords.append(ast.keyword(arg="resume", value=ast.Constant(True)))
279
-
280
- if properties_structure.required and pkey in properties_structure.required:
281
- keywords.append(ast.keyword(arg="not_null", value=ast.Constant(True)))
282
-
283
- if (
284
- properties_structure.partition_data
285
- and pkey in properties_structure.partition_data
286
- ):
287
- keywords.append(ast.keyword(arg="partition_data", value=ast.Constant(True)))
288
-
289
- if pkey in map_unique_by_property:
290
- unique = map_unique_by_property[pkey].index_model
291
- keywords.append(
292
- ast.keyword(
293
- arg="unique",
294
- value=ast.Constant(unique.name),
295
- )
296
- )
297
-
298
- if (
299
- properties_structure.search_properties
300
- and pkey in properties_structure.search_properties
301
- ):
302
- keywords.append(ast.keyword(arg="search", value=ast.Constant(True)))
303
- else:
304
- keywords.append(ast.keyword(arg="search", value=ast.Constant(False)))
305
-
306
- if (
307
- properties_structure.metric_label
308
- and pkey in properties_structure.metric_label
309
- ):
310
- keywords.append(ast.keyword(arg="metric_label", value=ast.Constant(True)))
311
-
312
- if prop.type == PrimitiveTypes.CPF:
313
- keywords.append(
314
- ast.keyword(
315
- arg="validator",
316
- value=ast.Attribute(
317
- value=ast.Call(
318
- func=ast.Name(id="DTOFieldValidators", ctx=ast.Load()),
319
- args=[],
320
- keywords=[],
321
- ),
322
- attr="validate_cpf",
323
- ctx=ast.Load(),
324
- ),
325
- )
326
- )
327
- elif prop.type == PrimitiveTypes.CNPJ:
328
- keywords.append(
329
- ast.keyword(
330
- arg="validator",
331
- value=ast.Attribute(
332
- value=ast.Call(
333
- func=ast.Name(id="DTOFieldValidators", ctx=ast.Load()),
334
- args=[],
335
- keywords=[],
336
- ),
337
- attr="validate_cnpj",
338
- ctx=ast.Load(),
339
- ),
340
- )
341
- )
342
- elif prop.type == PrimitiveTypes.CPF_CNPJ:
343
- keywords.append(
344
- ast.keyword(
345
- arg="validator",
346
- value=ast.Attribute(
347
- value=ast.Call(
348
- func=ast.Name(id="DTOFieldValidators", ctx=ast.Load()),
349
- args=[],
350
- keywords=[],
351
- ),
352
- attr="validate_cpf_or_cnpj",
353
- ctx=ast.Load(),
354
- ),
355
- )
356
- )
357
- elif prop.type == PrimitiveTypes.EMAIL:
358
- keywords.append(
359
- ast.keyword(
360
- arg="validator",
361
- value=ast.Attribute(
362
- value=ast.Call(
363
- func=ast.Name(id="DTOFieldValidators", ctx=ast.Load()),
364
- args=[],
365
- keywords=[],
366
- ),
367
- attr="validate_email",
368
- ctx=ast.Load(),
369
- ),
370
- )
371
- )
372
-
373
- # Trtando de uma definição de enum
374
- if prop.domain_config:
375
- result = self._compile_domain_config(
376
- pkey, prop, escopo, entity_model, prefx_class_name
377
- )
378
- if not result:
379
- raise Exception(f"Erro desconhecido ao compilar a propriedade {pkey}")
380
-
381
- enum_class_name, ast_enum_class = result
382
- aux_classes.append(ast_enum_class)
383
-
384
- # Resolvendo o nome da propriedade no Entity
385
- if (
386
- properties_structure.entity_properties
387
- and pkey in properties_structure.entity_properties
388
- ):
389
- entity_field_name = properties_structure.entity_properties[pkey].column
390
- else:
391
- entity_field_name = pkey
392
-
393
- # Escrevendo, se necessário, o alias para o nome da entity
394
- if entity_field_name != pkey:
395
- keywords.append(
396
- ast.keyword(
397
- arg="entity_field",
398
- value=ast.Constant(value=entity_field_name),
399
- )
400
- )
401
-
402
- # Instanciando o atributo AST
403
- if not isinstance(prop.type, PrimitiveTypes):
404
- raise Exception(
405
- f"Tipo da trait_property '{pkey}' não suportado: {prop.type} (deveria ser um Tipo Primitivo)"
406
- )
407
-
408
- # Instanciando o atributo AST
409
- if enum_class_name:
410
- prop_type = enum_class_name
411
- else:
412
- prop_type = TypeUtil.property_type_to_python_type(prop.type)
413
-
414
- ast_attr = ast.AnnAssign(
415
- target=ast.Name(id=CompilerStrUtil.to_snake_case(pkey), ctx=ast.Store()),
416
- annotation=ast.Name(
417
- id=prop_type,
418
- ctx=ast.Load(),
419
- ),
420
- value=ast.Call(
421
- func=ast.Name(id="DTOField", ctx=ast.Load()),
422
- args=[],
423
- keywords=keywords,
424
- ),
425
- simple=1,
426
- )
427
-
428
- ast_dto_attributes.append(ast_attr)
429
-
430
- # Entity
431
- ast_entity_attr = ast.AnnAssign(
432
- target=ast.Name(
433
- id=CompilerStrUtil.to_snake_case(entity_field_name),
434
- ctx=ast.Store(),
435
- ),
436
- annotation=ast.Name(
437
- id=TypeUtil.property_type_to_python_type(prop.type),
438
- ctx=ast.Load(),
439
- ),
440
- value=ast.Constant(value=None),
441
- simple=1,
442
- )
443
-
444
- ast_entity_attributes.append(ast_entity_attr)
445
-
446
- # Guardando como um fixed_filter
447
- # TODO Pensar em validações para esse value (se está de acordo com o tipo ou enum)
448
- fixed_filters.append((pkey, prop.value))
449
-
450
230
  def _build_aggregator_class_ast(
451
231
  self,
452
232
  class_name: str,
@@ -1165,6 +945,47 @@ class EDLPropertyCompiler:
1165
945
  ctx=ast.Load(),
1166
946
  )
1167
947
 
948
+ def _merge_trait_extends_properties(
949
+ self, properties_structure: PropertiesCompilerStructure
950
+ ) -> dict[str, BasicTypes]:
951
+ fixed_filters: dict[str, BasicTypes] = {}
952
+
953
+ trait_sources = (
954
+ properties_structure.trait_properties or {},
955
+ properties_structure.extends_properties or {},
956
+ )
957
+
958
+ for prop_dict in trait_sources:
959
+ for pkey, tprop in prop_dict.items():
960
+ if not isinstance(tprop.type, PrimitiveTypes):
961
+ raise ValueError(
962
+ f"Propriedade '{pkey}' definida em trait/extends precisa ser um tipo primitivo."
963
+ )
964
+
965
+ base_prop = properties_structure.properties.get(pkey)
966
+
967
+ if base_prop:
968
+ if base_prop.type != tprop.type:
969
+ raise ValueError(
970
+ f"Tipo da propriedade '{pkey}' em trait/extends não coincide com a definição existente."
971
+ )
972
+
973
+ base_prop.default = tprop.value
974
+
975
+ if tprop.domain_config and not base_prop.domain_config:
976
+ base_prop.domain_config = tprop.domain_config
977
+ else:
978
+ base_prop = PropertyMetaModel(
979
+ type=tprop.type,
980
+ default=tprop.value,
981
+ domain_config=tprop.domain_config,
982
+ )
983
+ properties_structure.properties[pkey] = base_prop
984
+
985
+ fixed_filters[pkey] = tprop.value
986
+
987
+ return fixed_filters
988
+
1168
989
  def _build_primitive_default_value_ast(
1169
990
  self,
1170
991
  pkey: str,
@@ -1249,9 +1070,7 @@ class EDLPropertyCompiler:
1249
1070
  )
1250
1071
 
1251
1072
  value_to_convert = (
1252
- default_value.strip()
1253
- if isinstance(default_value, str)
1254
- else default_value
1073
+ default_value.strip() if isinstance(default_value, str) else default_value
1255
1074
  )
1256
1075
 
1257
1076
  if forbid_fraction and isinstance(value_to_convert, float):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nsj_rest_lib2
3
- Version: 0.0.22
3
+ Version: 0.0.23
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
@@ -9,7 +9,7 @@ nsj_rest_lib2/compiler/compiler_structures.py,sha256=a_DF_nU4VgCt0sWJI03Ky6fPHvo
9
9
  nsj_rest_lib2/compiler/dto_compiler.py,sha256=mvZo19owtpFTjanCE20T0jmBKjhKXIVUsnR5raiGoRM,6728
10
10
  nsj_rest_lib2/compiler/entity_compiler.py,sha256=-mDA1-dHKYp0umQi1A4GbA0F1hlaC-gQRqj69vkADC4,6536
11
11
  nsj_rest_lib2/compiler/model.py,sha256=QDBoM26qoZdiNcykl1nvXCrFDhg-6Q__QzVq6uY1QzE,1460
12
- nsj_rest_lib2/compiler/property_compiler.py,sha256=3PIt0l8jrUeSxwTfM48X5fjwAYe0_0s0PGq9Z4cMmBQ,49713
12
+ nsj_rest_lib2/compiler/property_compiler.py,sha256=pJMZb2JPfle_svOixuGD1JUnQUYhlWrNiay2tmTgl0Q,43600
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
@@ -30,7 +30,7 @@ nsj_rest_lib2/controller/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
30
30
  nsj_rest_lib2/controller/dynamic_controller.py,sha256=XMqxe1NW-NE5XwomXb4pSNdALQHpP74Hc26R4fnmXqg,15194
31
31
  nsj_rest_lib2/service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  nsj_rest_lib2/service/entity_loader.py,sha256=-Adgj8shMkLXrIV4ZDAqpOLSN--B5k9Uokfy9nrQA4I,15585
33
- nsj_rest_lib2-0.0.22.dist-info/METADATA,sha256=-YyM5sMuF6_0dZ0r09vyzQuZoDcZb0FEsKzOBF31PjM,1094
34
- nsj_rest_lib2-0.0.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
- nsj_rest_lib2-0.0.22.dist-info/top_level.txt,sha256=L6zh0EfH8_rur7OJ8_V-El-XEMf4qg3bkF8ADgqLVIA,14
36
- nsj_rest_lib2-0.0.22.dist-info/RECORD,,
33
+ nsj_rest_lib2-0.0.23.dist-info/METADATA,sha256=ABA2f_Qw57RKKdb8BGZhZjiSjqIY1GDQH36U_l0k1G4,1094
34
+ nsj_rest_lib2-0.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ nsj_rest_lib2-0.0.23.dist-info/top_level.txt,sha256=L6zh0EfH8_rur7OJ8_V-El-XEMf4qg3bkF8ADgqLVIA,14
36
+ nsj_rest_lib2-0.0.23.dist-info/RECORD,,