sera-2 1.6.3__py3-none-any.whl → 1.6.4__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.
@@ -719,7 +719,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
719
719
  return
720
720
 
721
721
  program = Program()
722
- prop_defs: list[tuple[expr.Expr, expr.Expr]] = []
722
+ prop_defs: list[tuple[DataProperty | ObjectProperty, expr.Expr, expr.Expr]] = []
723
723
 
724
724
  for prop in cls.properties.values():
725
725
  # we must include private properties that are needed during upsert for our forms.
@@ -798,6 +798,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
798
798
 
799
799
  prop_defs.append(
800
800
  (
801
+ prop,
801
802
  expr.ExprIdent(propname),
802
803
  PredefinedFn.dict(
803
804
  [
@@ -821,6 +822,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
821
822
  )
822
823
 
823
824
  program.import_("sera-db.Schema", True)
825
+ program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
824
826
  program.import_(
825
827
  f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
826
828
  )
@@ -832,16 +834,82 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
832
834
  [
833
835
  expr.ExprConstant(to_camel_case(prop.name)).to_typescript()
834
836
  for prop in cls.properties.values()
837
+ if not prop.data.is_private
835
838
  ]
836
839
  )
837
840
  + ";"
838
841
  ),
839
842
  stmt.LineBreak(),
843
+ (
844
+ stmt.TypescriptStatement(
845
+ f"export type Draft{cls.name}Properties = {cls.name}Properties"
846
+ + (
847
+ " | "
848
+ + " | ".join(
849
+ [
850
+ expr.ExprConstant(
851
+ to_camel_case(prop.name)
852
+ ).to_typescript()
853
+ for prop in cls.properties.values()
854
+ if prop.data.is_private
855
+ ]
856
+ )
857
+ if any(prop.data.is_private for prop in cls.properties.values())
858
+ else ""
859
+ )
860
+ + ";"
861
+ )
862
+ ),
863
+ stmt.LineBreak(),
840
864
  stmt.TypescriptStatement(
841
- f"export const {cls.name}Schema: Schema<Draft{cls.name}, {cls.name}Properties> = "
865
+ f"export const {cls.name}Schema: Schema<{cls.name}, {cls.name}Properties> = "
842
866
  + PredefinedFn.dict(
843
867
  [
844
- (expr.ExprIdent("properties"), PredefinedFn.dict(prop_defs)),
868
+ (
869
+ expr.ExprIdent("properties"),
870
+ PredefinedFn.dict(
871
+ [
872
+ (prop_name, prop_def)
873
+ for prop, prop_name, prop_def in prop_defs
874
+ if not prop.data.is_private
875
+ ]
876
+ ),
877
+ ),
878
+ ]
879
+ + (
880
+ [
881
+ (
882
+ expr.ExprIdent("primaryKey"),
883
+ expr.ExprConstant(
884
+ assert_not_null(cls.get_id_property()).name
885
+ ),
886
+ )
887
+ ]
888
+ if cls.db is not None
889
+ else []
890
+ )
891
+ ).to_typescript()
892
+ + ";"
893
+ ),
894
+ stmt.LineBreak(),
895
+ stmt.TypescriptStatement(
896
+ f"export const Draft{cls.name}Schema: Schema<Draft{cls.name}, Draft{cls.name}Properties> = "
897
+ + PredefinedFn.dict(
898
+ [
899
+ (
900
+ expr.ExprIdent("properties"),
901
+ expr.ExprIdent(
902
+ f"{{ ...{cls.name}Schema.properties, "
903
+ + ", ".join(
904
+ [
905
+ f"{prop_name.to_typescript()}: {prop_def.to_typescript()}"
906
+ for prop, prop_name, prop_def in prop_defs
907
+ if prop.data.is_private
908
+ ]
909
+ )
910
+ + "}"
911
+ ),
912
+ )
845
913
  ]
846
914
  + (
847
915
  [
@@ -868,29 +936,37 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
868
936
  logger.info(f"Module {outmod.path} already exists, skip")
869
937
  return
870
938
 
939
+ export_types = []
940
+
871
941
  program = Program()
872
942
  program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
943
+ export_types.append(cls.name)
873
944
  if cls.db is not None:
874
945
  # only import the id if this class is stored in the database
875
946
  program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}Id", True)
876
- program.import_(
877
- f"@.models.{pkg.dir.name}.{cls.name}Schema.{cls.name}Schema", True
878
- )
947
+
948
+ for type in [
949
+ f"{cls.name}Schema",
950
+ f"Draft{cls.name}Schema",
951
+ f"{cls.name}Properties",
952
+ f"Draft{cls.name}Properties",
953
+ ]:
954
+ program.import_(f"@.models.{pkg.dir.name}.{cls.name}Schema.{type}", True)
955
+ export_types.append(type)
956
+
879
957
  program.import_(
880
958
  f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
881
959
  )
960
+ export_types.append(f"Draft{cls.name}")
882
961
  if cls.db is not None:
883
962
  program.import_(
884
963
  f"@.models.{pkg.dir.name}.{cls.name}Table.{cls.name}Table", True
885
964
  )
965
+ export_types.append(f"{cls.name}Table")
886
966
 
887
967
  program.root(
888
968
  stmt.LineBreak(),
889
- stmt.TypescriptStatement(
890
- f"export {{ {cls.name}, Draft{cls.name}, {cls.name}Table, {cls.name}Schema }};"
891
- if cls.db is not None
892
- else f"export {{ {cls.name}, Draft{cls.name}, {cls.name}Schema }};"
893
- ),
969
+ stmt.TypescriptStatement("export { %s };" % (", ".join(export_types))),
894
970
  (
895
971
  stmt.TypescriptStatement(f"export type {{ {cls.name}Id }};")
896
972
  if cls.db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sera-2
3
- Version: 1.6.3
3
+ Version: 1.6.4
4
4
  Summary:
5
5
  Author: Binh Vu
6
6
  Author-email: bvu687@gmail.com
@@ -10,7 +10,7 @@ sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
10
10
  sera/make/make_python_api.py,sha256=RuJUm9z-4plBEtjobeOPr12o27OT-0tSeXI4ZlM3IY0,29433
11
11
  sera/make/make_python_model.py,sha256=xf4revAwVWEnF6QhxbbqPyUGgXOOB--Gu3jPxsESg0Y,36593
12
12
  sera/make/make_python_services.py,sha256=RsinYZdfkrTlTn9CT50VgqGs9w6IZawsJx-KEmqfnEY,2062
13
- sera/make/make_typescript_model.py,sha256=rm_QUGSSmGeXAvFcTeJ4qeq1dFog2DERZ0Mo1r1Yak0,37553
13
+ sera/make/make_typescript_model.py,sha256=RPfMDpEY3MwBSAV_NH0Rsm5dI2FvOSJj0oWwHAIYGdg,40606
14
14
  sera/misc/__init__.py,sha256=Dh4uDq0D4N53h3zhvmwfa5a0TPVRSUvLzb0hkFuPirk,411
15
15
  sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
16
16
  sera/misc/_utils.py,sha256=V5g4oLGHOhUCR75Kkcn1w01pAvGvaepK-T8Z3pIgHjI,1450
@@ -27,6 +27,6 @@ sera/models/_parse.py,sha256=sJYfQtwek96ltpgxExG4xUbiLnU3qvNYhTP1CeyXGjs,9746
27
27
  sera/models/_property.py,sha256=CmEmgOShtSyNFq05YW3tGupwCIVRzPMKudXWld8utPk,5530
28
28
  sera/models/_schema.py,sha256=r-Gqg9Lb_wR3UrbNvfXXgt_qs5bts0t2Ve7aquuF_OI,1155
29
29
  sera/typing.py,sha256=Q4QMfbtfrCjC9tFfsZPhsAnbNX4lm4NHQ9lmjNXYdV0,772
30
- sera_2-1.6.3.dist-info/METADATA,sha256=BBwuS2iLs2Ubc7WnJa6Q8sOR4Fz8aqXx9iTkLd3PO4M,856
31
- sera_2-1.6.3.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
32
- sera_2-1.6.3.dist-info/RECORD,,
30
+ sera_2-1.6.4.dist-info/METADATA,sha256=_VtnA4zI_oLY9RjlfftgNh3cyssJnWboBOLF53bieog,856
31
+ sera_2-1.6.4.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
32
+ sera_2-1.6.4.dist-info/RECORD,,
File without changes