sera-2 1.19.1__py3-none-any.whl → 1.19.3__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.
@@ -146,7 +146,11 @@ def make_python_data_model(
146
146
  mode: Literal["create", "update"],
147
147
  prop: DataProperty | ObjectProperty,
148
148
  ):
149
- value = PredefinedFn.attr_getter(slf, expr.ExprIdent(prop.name))
149
+ if isinstance(prop, ObjectProperty) and prop.target.db is not None:
150
+ propname = prop.name + "_id"
151
+ else:
152
+ propname = prop.name
153
+ value = PredefinedFn.attr_getter(slf, expr.ExprIdent(propname))
150
154
  if isinstance(prop, ObjectProperty):
151
155
  if (
152
156
  prop.target.db is not None
@@ -421,12 +425,14 @@ def make_python_data_model(
421
425
  elif isinstance(prop, ObjectProperty):
422
426
  if prop.target.db is not None:
423
427
  # if the target class is in the database, we expect the user to pass the foreign key for it.
428
+ propname = prop.name + "_id"
424
429
  pytype = (
425
430
  assert_not_null(prop.target.get_id_property())
426
431
  .get_data_model_datatype()
427
432
  .get_python_type()
428
433
  )
429
434
  else:
435
+ propname = prop.name
430
436
  pytype = PyTypeWithDep(
431
437
  f"Create{prop.target.name}",
432
438
  [
@@ -442,7 +448,7 @@ def make_python_data_model(
442
448
  for dep in pytype.deps:
443
449
  program.import_(dep, True)
444
450
 
445
- cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
451
+ cls_ast(stmt.DefClassVarStatement(propname, pytype.type))
446
452
 
447
453
  if is_on_create_value_updated:
448
454
  program.import_("typing.Optional", True)
@@ -604,13 +610,16 @@ def make_python_data_model(
604
610
  )
605
611
  elif isinstance(prop, ObjectProperty):
606
612
  if prop.target.db is not None:
613
+ propname = prop.name + "_id"
607
614
  # if the target class is in the database, we expect the user to pass the foreign key for it.
608
615
  pytype = (
609
616
  assert_not_null(prop.target.get_id_property())
610
617
  .get_data_model_datatype()
611
618
  .get_python_type()
612
619
  )
620
+
613
621
  else:
622
+ propname = prop.name
614
623
  pytype = PyTypeWithDep(
615
624
  f"Update{prop.target.name}",
616
625
  [
@@ -626,7 +635,7 @@ def make_python_data_model(
626
635
  for dep in pytype.deps:
627
636
  program.import_(dep, True)
628
637
 
629
- cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
638
+ cls_ast(stmt.DefClassVarStatement(propname, pytype.type))
630
639
 
631
640
  if is_on_update_value_updated:
632
641
  program.import_("typing.Optional", True)
@@ -740,6 +749,7 @@ def make_python_data_model(
740
749
  # skip private fields as this is for APIs exchange
741
750
  continue
742
751
 
752
+ propname = prop.name
743
753
  if isinstance(prop, DataProperty):
744
754
  pytype = prop.get_data_model_datatype().get_python_type()
745
755
  if prop.is_optional:
@@ -751,6 +761,7 @@ def make_python_data_model(
751
761
  cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
752
762
  elif isinstance(prop, ObjectProperty):
753
763
  if prop.target.db is not None:
764
+ propname = prop.name + "_id"
754
765
  pytype = (
755
766
  assert_not_null(prop.target.get_id_property())
756
767
  .get_data_model_datatype()
@@ -772,7 +783,7 @@ def make_python_data_model(
772
783
  for dep in pytype.deps:
773
784
  program.import_(dep, True)
774
785
 
775
- cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
786
+ cls_ast(stmt.DefClassVarStatement(propname, pytype.type))
776
787
 
777
788
  cls_ast(
778
789
  stmt.LineBreak(),
@@ -98,6 +98,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
98
98
  assert isinstance(prop, ObjectProperty)
99
99
  if prop.target.db is not None:
100
100
  # this class is stored in the database, we store the id instead
101
+ propname = propname + "Id"
101
102
  tstype = TsTypeWithDep(
102
103
  f"{prop.target.name}Id",
103
104
  [
@@ -113,7 +114,8 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
113
114
  (
114
115
  expr.ExprIdent(propname),
115
116
  PredefinedFn.attr_getter(
116
- expr.ExprIdent("data"), expr.ExprIdent(prop.name)
117
+ expr.ExprIdent("data"),
118
+ expr.ExprIdent(prop.name + "_id"),
117
119
  ),
118
120
  )
119
121
  )
@@ -300,6 +302,8 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
300
302
  # continue
301
303
 
302
304
  propname = to_camel_case(prop.name)
305
+ if isinstance(prop, ObjectProperty) and prop.target.db is not None:
306
+ propname = propname + "Id"
303
307
  prop2tsname[prop.name] = propname
304
308
 
305
309
  def _update_field_func(
@@ -544,7 +548,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
544
548
  )
545
549
  ser_args.append(
546
550
  (
547
- expr.ExprIdent(prop.name),
551
+ expr.ExprIdent(prop.name + "_id"),
548
552
  PredefinedFn.attr_getter(
549
553
  expr.ExprIdent("this"), expr.ExprIdent(propname)
550
554
  ),
@@ -784,7 +788,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
784
788
  )
785
789
  )
786
790
 
787
- # TODO: fix me!
791
+ # TODO: fix me! fix me what?? next time give more context.
788
792
  prop_validators.append(
789
793
  (
790
794
  expr.ExprIdent(propname),
@@ -1079,12 +1083,18 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
1079
1083
 
1080
1084
  query_args = []
1081
1085
  for prop in cls.properties.values():
1082
- propname = to_camel_case(prop.name)
1083
- if propname != prop.name:
1086
+ pypropname = prop.name
1087
+ tspropname = to_camel_case(prop.name)
1088
+
1089
+ if isinstance(prop, ObjectProperty) and prop.target.db is not None:
1090
+ tspropname = tspropname + "Id"
1091
+ pypropname = prop.name + "_id"
1092
+
1093
+ if tspropname != pypropname:
1084
1094
  query_args.append(
1085
1095
  (
1086
- expr.ExprIdent(propname),
1087
- expr.ExprConstant(prop.name),
1096
+ expr.ExprIdent(tspropname),
1097
+ expr.ExprConstant(pypropname),
1088
1098
  )
1089
1099
  )
1090
1100
 
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from dataclasses import dataclass
4
4
 
5
5
  from sera.models._class import Class
6
- from sera.models._property import DataProperty
6
+ from sera.models._property import DataProperty, ObjectProperty
7
7
 
8
8
 
9
9
  @dataclass
@@ -35,7 +35,17 @@ class DataCollection:
35
35
  ):
36
36
  # This property is not indexed, so we skip it
37
37
  continue
38
- field_names.add(prop.name)
38
+ if isinstance(prop, ObjectProperty) and prop.target.db is None:
39
+ # TODO: Implement this! This property is an embedded object property, we need to figure out
40
+ # which necessary properties are queryable and add them to the field names
41
+ continue
42
+ if isinstance(prop, ObjectProperty) and prop.target.db is not None:
43
+ # This property is an object property stored in the database, "_id" is added to the property name
44
+ propname = prop.name + "_id"
45
+ else:
46
+ # This property is a data property or an object property not stored in the database, so we use its name
47
+ propname = prop.name
48
+ field_names.add(propname)
39
49
  return field_names
40
50
 
41
51
  def get_service_name(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sera-2
3
- Version: 1.19.1
3
+ Version: 1.19.3
4
4
  Summary:
5
5
  Author: Binh Vu
6
6
  Author-email: bvu687@gmail.com
@@ -23,15 +23,15 @@ sera/make/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  sera/make/__main__.py,sha256=HRfOR53p351h6KblVvYm3DLhDIfEtk6R0kjl78_S_S8,1453
24
24
  sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
25
25
  sera/make/make_python_api.py,sha256=iXGbKQ3IJvsY1ur_fhurr_THFNnH66E3Wl85o0emUbw,26853
26
- sera/make/make_python_model.py,sha256=RfUATMs6d_glxbKnpLum9tsU2pNOyifvJX76S8pI_DY,62964
26
+ sera/make/make_python_model.py,sha256=UJ1rD-caGH5t-B-UrNkib0okwQtR4OC3uMWOD-b1ot4,63387
27
27
  sera/make/make_python_services.py,sha256=0ZpWLwQ7Nwfn8BXAikAB4JRpNknpSJyJgY5b1cjtxV4,2073
28
- sera/make/make_typescript_model.py,sha256=1ouYFCeqOlwEzsGBiXUn4VZtLJjJW7GSacdOSlQzhjI,67012
28
+ sera/make/make_typescript_model.py,sha256=laW27gFYGFhvLY5DfcVgh8tPlDqvmS824r-fbBnG7JI,67493
29
29
  sera/misc/__init__.py,sha256=rOmGMv7QNzpSKZSyxChbRmEnBr3O443UlLGS0FIs3AI,561
30
30
  sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
31
31
  sera/misc/_utils.py,sha256=_-17XbK6qp3HobcI9iLF4xfaATvFg1ckUzgg7r7Ctmw,7135
32
32
  sera/models/__init__.py,sha256=vJC5Kzo_N7wd16ocNPy1VvAZDGNiWeiAhWJ4ihATKvA,780
33
33
  sera/models/_class.py,sha256=1J4Bd_LanzhhDWwZFHWGtFYD7lupe_alaB3D02ebNDI,2862
34
- sera/models/_collection.py,sha256=ZnQEriKC4X88Zz48Kn1AVZKH-1_l8OgWa-zf2kcQOOE,1414
34
+ sera/models/_collection.py,sha256=AmEy6SoTTaxqFU4mBFVfFMGyutJuNnUGBaIV7xzGxbc,2143
35
35
  sera/models/_constraints.py,sha256=RpWDU-TfCslXaMUaTG9utWbl5z8Z6nzvF_fhqlek6ew,1987
36
36
  sera/models/_datatype.py,sha256=cC6Wm0IvobDF5Tq9Jy_ncbjPWBRl3ECGBy0wJyDDMzU,7281
37
37
  sera/models/_default.py,sha256=ABggW6qdPR4ZDqIPJdJ0GCGQ-7kfsfZmQ_DchgZEa-I,137
@@ -42,6 +42,6 @@ sera/models/_parse.py,sha256=ciTLzCkO0q6xA1R_rHbnYJYK3Duo2oh56WeuwxXwJaI,12392
42
42
  sera/models/_property.py,sha256=9yMDxrmbyuF6-29lQjiq163Xzwbk75TlmGBpu0NLpkI,7485
43
43
  sera/models/_schema.py,sha256=VxJEiqgVvbXgcSUK4UW6JnRcggk4nsooVSE6MyXmfNY,1636
44
44
  sera/typing.py,sha256=m4rir-fB6Cgcm7_ZSXXcNdla2LJgq96WXxtTTrDaJno,1058
45
- sera_2-1.19.1.dist-info/METADATA,sha256=vhXuNeYXDuvLW_dW_7jStIcyq0OhEqV9XXp74taTQzY,936
46
- sera_2-1.19.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
47
- sera_2-1.19.1.dist-info/RECORD,,
45
+ sera_2-1.19.3.dist-info/METADATA,sha256=zyrJH3__kBkyI9VrpNbK5j31dmOUucvlXppfgrkKkPI,936
46
+ sera_2-1.19.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
47
+ sera_2-1.19.3.dist-info/RECORD,,