sera-2 1.6.2__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.
@@ -5,7 +5,6 @@ from typing import Any, Callable
|
|
5
5
|
from codegen.models import AST, PredefinedFn, Program, expr, stmt
|
6
6
|
from codegen.models.var import DeferredVar
|
7
7
|
from loguru import logger
|
8
|
-
|
9
8
|
from sera.misc import (
|
10
9
|
assert_isinstance,
|
11
10
|
assert_not_null,
|
@@ -720,12 +719,13 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
720
719
|
return
|
721
720
|
|
722
721
|
program = Program()
|
723
|
-
prop_defs: list[tuple[expr.Expr, expr.Expr]] = []
|
722
|
+
prop_defs: list[tuple[DataProperty | ObjectProperty, expr.Expr, expr.Expr]] = []
|
724
723
|
|
725
724
|
for prop in cls.properties.values():
|
726
|
-
|
727
|
-
|
728
|
-
|
725
|
+
# we must include private properties that are needed during upsert for our forms.
|
726
|
+
# if prop.data.is_private:
|
727
|
+
# # skip private fields as this is for APIs exchange
|
728
|
+
# continue
|
729
729
|
propname = to_camel_case(prop.name)
|
730
730
|
tsprop = {}
|
731
731
|
|
@@ -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
|
[
|
@@ -822,13 +823,93 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
822
823
|
|
823
824
|
program.import_("sera-db.Schema", True)
|
824
825
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
|
826
|
+
program.import_(
|
827
|
+
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
828
|
+
)
|
825
829
|
program.root(
|
826
830
|
stmt.LineBreak(),
|
827
831
|
stmt.TypescriptStatement(
|
828
|
-
f"export
|
832
|
+
f"export type {cls.name}Properties = "
|
833
|
+
+ " | ".join(
|
834
|
+
[
|
835
|
+
expr.ExprConstant(to_camel_case(prop.name)).to_typescript()
|
836
|
+
for prop in cls.properties.values()
|
837
|
+
if not prop.data.is_private
|
838
|
+
]
|
839
|
+
)
|
840
|
+
+ ";"
|
841
|
+
),
|
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(),
|
864
|
+
stmt.TypescriptStatement(
|
865
|
+
f"export const {cls.name}Schema: Schema<{cls.name}, {cls.name}Properties> = "
|
829
866
|
+ PredefinedFn.dict(
|
830
867
|
[
|
831
|
-
(
|
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
|
+
)
|
832
913
|
]
|
833
914
|
+ (
|
834
915
|
[
|
@@ -855,29 +936,37 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
855
936
|
logger.info(f"Module {outmod.path} already exists, skip")
|
856
937
|
return
|
857
938
|
|
939
|
+
export_types = []
|
940
|
+
|
858
941
|
program = Program()
|
859
942
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
|
943
|
+
export_types.append(cls.name)
|
860
944
|
if cls.db is not None:
|
861
945
|
# only import the id if this class is stored in the database
|
862
946
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}Id", True)
|
863
|
-
|
864
|
-
|
865
|
-
|
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
|
+
|
866
957
|
program.import_(
|
867
958
|
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
868
959
|
)
|
960
|
+
export_types.append(f"Draft{cls.name}")
|
869
961
|
if cls.db is not None:
|
870
962
|
program.import_(
|
871
963
|
f"@.models.{pkg.dir.name}.{cls.name}Table.{cls.name}Table", True
|
872
964
|
)
|
965
|
+
export_types.append(f"{cls.name}Table")
|
873
966
|
|
874
967
|
program.root(
|
875
968
|
stmt.LineBreak(),
|
876
|
-
stmt.TypescriptStatement(
|
877
|
-
f"export {{ {cls.name}, Draft{cls.name}, {cls.name}Table, {cls.name}Schema }};"
|
878
|
-
if cls.db is not None
|
879
|
-
else f"export {{ {cls.name}, Draft{cls.name}, {cls.name}Schema }};"
|
880
|
-
),
|
969
|
+
stmt.TypescriptStatement("export { %s };" % (", ".join(export_types))),
|
881
970
|
(
|
882
971
|
stmt.TypescriptStatement(f"export type {{ {cls.name}Id }};")
|
883
972
|
if cls.db
|
@@ -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=
|
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.
|
31
|
-
sera_2-1.6.
|
32
|
-
sera_2-1.6.
|
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
|