sera-2 1.6.4__py3-none-any.whl → 1.6.5__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.
sera/libs/base_orm.py
CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
3
3
|
from typing import Optional
|
4
4
|
|
5
5
|
import orjson
|
6
|
+
from msgspec.json import decode, encode
|
6
7
|
from sera.typing import UNSET
|
7
8
|
from sqlalchemy import LargeBinary, TypeDecorator
|
8
9
|
from sqlalchemy import create_engine as sqlalchemy_create_engine
|
@@ -50,13 +51,12 @@ class DataclassType(TypeDecorator):
|
|
50
51
|
def process_bind_param(self, value, dialect):
|
51
52
|
if value is None:
|
52
53
|
return None
|
53
|
-
return
|
54
|
+
return encode(value)
|
54
55
|
|
55
56
|
def process_result_value(self, value, dialect):
|
56
57
|
if value is None:
|
57
58
|
return None
|
58
|
-
|
59
|
-
return self.cls.from_dict(result)
|
59
|
+
return decode(value, type=self.cls)
|
60
60
|
|
61
61
|
|
62
62
|
class ListDataclassType(TypeDecorator):
|
@@ -72,13 +72,12 @@ class ListDataclassType(TypeDecorator):
|
|
72
72
|
def process_bind_param(self, value, dialect):
|
73
73
|
if value is None:
|
74
74
|
return None
|
75
|
-
return
|
75
|
+
return encode(value)
|
76
76
|
|
77
77
|
def process_result_value(self, value, dialect):
|
78
78
|
if value is None:
|
79
79
|
return None
|
80
|
-
|
81
|
-
return [self.cls.from_dict(x) for x in result]
|
80
|
+
return decode(value, type=list[self.cls])
|
82
81
|
|
83
82
|
|
84
83
|
class DictDataclassType(TypeDecorator):
|
@@ -94,13 +93,12 @@ class DictDataclassType(TypeDecorator):
|
|
94
93
|
def process_bind_param(self, value, dialect):
|
95
94
|
if value is None:
|
96
95
|
return None
|
97
|
-
return
|
96
|
+
return encode(value)
|
98
97
|
|
99
98
|
def process_result_value(self, value, dialect):
|
100
99
|
if value is None:
|
101
100
|
return None
|
102
|
-
|
103
|
-
return {k: self.cls.from_dict(v) for k, v in result.items()}
|
101
|
+
return decode(value, type=dict[str, self.cls])
|
104
102
|
|
105
103
|
|
106
104
|
def create_engine(
|
@@ -49,6 +49,9 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
49
49
|
|
50
50
|
idprop = cls.get_id_property()
|
51
51
|
program = Program()
|
52
|
+
program.import_(
|
53
|
+
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
54
|
+
)
|
52
55
|
|
53
56
|
prop_defs = []
|
54
57
|
prop_constructor_assigns = []
|
@@ -202,6 +205,21 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
202
205
|
)
|
203
206
|
)
|
204
207
|
),
|
208
|
+
stmt.LineBreak(),
|
209
|
+
lambda ast13: ast13.func(
|
210
|
+
"toDraft",
|
211
|
+
[],
|
212
|
+
expr.ExprIdent(f"Draft{cls.name}"),
|
213
|
+
comment="Convert the class instance to a draft for editing",
|
214
|
+
)(
|
215
|
+
stmt.ReturnStatement(
|
216
|
+
expr.ExprMethodCall(
|
217
|
+
expr.ExprIdent(f"Draft{cls.name}"),
|
218
|
+
"update",
|
219
|
+
[expr.ExprIdent("this")],
|
220
|
+
)
|
221
|
+
),
|
222
|
+
),
|
205
223
|
),
|
206
224
|
)
|
207
225
|
|
@@ -821,85 +839,95 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
821
839
|
)
|
822
840
|
)
|
823
841
|
|
824
|
-
|
842
|
+
for type in ["Schema", "ObjectProperty", "DataProperty"]:
|
843
|
+
program.import_(f"sera-db.{type}", True)
|
844
|
+
|
825
845
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
|
846
|
+
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}Id", True)
|
826
847
|
program.import_(
|
827
848
|
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
828
849
|
)
|
829
850
|
program.root(
|
830
851
|
stmt.LineBreak(),
|
831
852
|
stmt.TypescriptStatement(
|
832
|
-
f"export type {cls.name}
|
833
|
-
+
|
853
|
+
f"export type {cls.name}SchemaType = "
|
854
|
+
+ PredefinedFn.dict(
|
834
855
|
[
|
835
|
-
expr.
|
836
|
-
|
837
|
-
|
856
|
+
(expr.ExprIdent("id"), expr.ExprIdent(f"{cls.name}Id")),
|
857
|
+
(
|
858
|
+
expr.ExprIdent("publicProperties"),
|
859
|
+
expr.ExprIdent(
|
860
|
+
" | ".join(
|
861
|
+
[
|
862
|
+
expr.ExprConstant(
|
863
|
+
to_camel_case(prop.name)
|
864
|
+
).to_typescript()
|
865
|
+
for prop in cls.properties.values()
|
866
|
+
if not prop.data.is_private
|
867
|
+
]
|
868
|
+
)
|
869
|
+
),
|
870
|
+
),
|
871
|
+
(
|
872
|
+
expr.ExprIdent("allProperties"),
|
873
|
+
expr.ExprIdent(
|
874
|
+
f"{cls.name}SchemaType['publicProperties']"
|
875
|
+
+ (
|
876
|
+
" | "
|
877
|
+
+ " | ".join(
|
878
|
+
[
|
879
|
+
expr.ExprConstant(
|
880
|
+
to_camel_case(prop.name)
|
881
|
+
).to_typescript()
|
882
|
+
for prop in cls.properties.values()
|
883
|
+
if prop.data.is_private
|
884
|
+
]
|
885
|
+
)
|
886
|
+
if any(
|
887
|
+
prop.data.is_private
|
888
|
+
for prop in cls.properties.values()
|
889
|
+
)
|
890
|
+
else ""
|
891
|
+
)
|
892
|
+
),
|
893
|
+
),
|
894
|
+
(
|
895
|
+
expr.ExprIdent("cls"),
|
896
|
+
expr.ExprIdent(cls.name),
|
897
|
+
),
|
898
|
+
(
|
899
|
+
expr.ExprIdent("draftCls"),
|
900
|
+
expr.ExprIdent(f"Draft{cls.name}"),
|
901
|
+
),
|
838
902
|
]
|
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
|
-
)
|
903
|
+
).to_typescript()
|
904
|
+
+ ";",
|
862
905
|
),
|
863
906
|
stmt.LineBreak(),
|
864
907
|
stmt.TypescriptStatement(
|
865
|
-
f"
|
908
|
+
f"const publicProperties: Record<{cls.name}SchemaType['publicProperties'], DataProperty | ObjectProperty> = "
|
866
909
|
+ PredefinedFn.dict(
|
867
910
|
[
|
868
|
-
(
|
869
|
-
|
870
|
-
|
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
|
-
),
|
911
|
+
(prop_name, prop_def)
|
912
|
+
for prop, prop_name, prop_def in prop_defs
|
913
|
+
if not prop.data.is_private
|
878
914
|
]
|
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
915
|
).to_typescript()
|
892
916
|
+ ";"
|
893
917
|
),
|
894
918
|
stmt.LineBreak(),
|
895
919
|
stmt.TypescriptStatement(
|
896
|
-
f"export const
|
920
|
+
f"export const {cls.name}Schema: Schema<{cls.name}SchemaType> = "
|
897
921
|
+ PredefinedFn.dict(
|
898
922
|
[
|
899
923
|
(
|
900
|
-
expr.ExprIdent("
|
924
|
+
expr.ExprIdent("publicProperties"),
|
925
|
+
expr.ExprIdent("publicProperties"),
|
926
|
+
),
|
927
|
+
(
|
928
|
+
expr.ExprIdent("allProperties"),
|
901
929
|
expr.ExprIdent(
|
902
|
-
|
930
|
+
"{ ...publicProperties, "
|
903
931
|
+ ", ".join(
|
904
932
|
[
|
905
933
|
f"{prop_name.to_typescript()}: {prop_def.to_typescript()}"
|
@@ -909,7 +937,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
909
937
|
)
|
910
938
|
+ "}"
|
911
939
|
),
|
912
|
-
)
|
940
|
+
),
|
913
941
|
]
|
914
942
|
+ (
|
915
943
|
[
|
@@ -937,6 +965,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
937
965
|
return
|
938
966
|
|
939
967
|
export_types = []
|
968
|
+
export_iso_types = [] # isolatedModules required separate export type clause
|
940
969
|
|
941
970
|
program = Program()
|
942
971
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
|
@@ -944,15 +973,16 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
944
973
|
if cls.db is not None:
|
945
974
|
# only import the id if this class is stored in the database
|
946
975
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}Id", True)
|
976
|
+
export_iso_types.append(f"{cls.name}Id")
|
947
977
|
|
948
|
-
|
949
|
-
f"{cls.name}Schema",
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
978
|
+
program.import_(
|
979
|
+
f"@.models.{pkg.dir.name}.{cls.name}Schema.{cls.name}Schema", True
|
980
|
+
)
|
981
|
+
export_types.append(f"{cls.name}Schema")
|
982
|
+
program.import_(
|
983
|
+
f"@.models.{pkg.dir.name}.{cls.name}Schema.{cls.name}SchemaType", True
|
984
|
+
)
|
985
|
+
export_iso_types.append(f"{cls.name}SchemaType")
|
956
986
|
|
957
987
|
program.import_(
|
958
988
|
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
@@ -968,9 +998,9 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
968
998
|
stmt.LineBreak(),
|
969
999
|
stmt.TypescriptStatement("export { %s };" % (", ".join(export_types))),
|
970
1000
|
(
|
971
|
-
stmt.TypescriptStatement(
|
972
|
-
|
973
|
-
|
1001
|
+
stmt.TypescriptStatement(
|
1002
|
+
"export type { %s };" % (", ".join(export_iso_types))
|
1003
|
+
)
|
974
1004
|
),
|
975
1005
|
)
|
976
1006
|
|
@@ -2,7 +2,7 @@ sera/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
sera/constants.py,sha256=mzAaMyIx8TJK0-RYYJ5I24C4s0Uvj26OLMJmBo0pxHI,123
|
3
3
|
sera/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
sera/libs/api_helper.py,sha256=hUEy0INHM18lxTQ348tgbXNceOHcjiAnqmuL_8CRpLQ,2509
|
5
|
-
sera/libs/base_orm.py,sha256=
|
5
|
+
sera/libs/base_orm.py,sha256=dyh0OT2sbHku5qPJXvRzYAHRTSXvvbQaS-Qwg65Bw04,2918
|
6
6
|
sera/libs/base_service.py,sha256=l5D4IjxIiz8LBRranUYddb8J0Y6SwSyetKYTLrCUdQA,4098
|
7
7
|
sera/make/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
sera/make/__main__.py,sha256=G5O7s6135-708honwqMFn2yPTs06WbGQTHpupID0eZ4,1417
|
@@ -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=KWseO3VGLlXfNVjwDF31Nh8q9Wat-hmiS4DJh0r0UCo,42303
|
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.5.dist-info/METADATA,sha256=Gv3f8FNU3Wke6T_yvsNb5r5S92YeYxmg2ogy8kgsOXo,856
|
31
|
+
sera_2-1.6.5.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
32
|
+
sera_2-1.6.5.dist-info/RECORD,,
|
File without changes
|