sera-2 1.11.2__py3-none-any.whl → 1.11.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.
- sera/make/make_python_model.py +17 -5
- sera/make/make_typescript_model.py +22 -0
- sera/models/_datatype.py +7 -0
- {sera_2-1.11.2.dist-info → sera_2-1.11.3.dist-info}/METADATA +1 -1
- {sera_2-1.11.2.dist-info → sera_2-1.11.3.dist-info}/RECORD +6 -6
- {sera_2-1.11.2.dist-info → sera_2-1.11.3.dist-info}/WHEEL +0 -0
sera/make/make_python_model.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
+
from operator import is_
|
3
4
|
from typing import Callable, Sequence
|
4
5
|
|
5
6
|
from codegen.models import AST, DeferredVar, PredefinedFn, Program, expr, stmt
|
@@ -296,11 +297,14 @@ def make_python_data_model(
|
|
296
297
|
],
|
297
298
|
)
|
298
299
|
|
300
|
+
if prop.cardinality.is_star_to_many():
|
301
|
+
pytype = pytype.as_list_type()
|
302
|
+
elif prop.is_optional:
|
303
|
+
pytype = pytype.as_optional_type()
|
304
|
+
|
299
305
|
for dep in pytype.deps:
|
300
306
|
program.import_(dep, True)
|
301
307
|
|
302
|
-
if prop.cardinality.is_star_to_many():
|
303
|
-
pytype = pytype.as_list_type()
|
304
308
|
cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
|
305
309
|
|
306
310
|
# has_to_db = True
|
@@ -453,11 +457,14 @@ def make_python_data_model(
|
|
453
457
|
],
|
454
458
|
)
|
455
459
|
|
460
|
+
if prop.cardinality.is_star_to_many():
|
461
|
+
pytype = pytype.as_list_type()
|
462
|
+
elif prop.is_optional:
|
463
|
+
pytype = pytype.as_optional_type()
|
464
|
+
|
456
465
|
for dep in pytype.deps:
|
457
466
|
program.import_(dep, True)
|
458
467
|
|
459
|
-
if prop.cardinality.is_star_to_many():
|
460
|
-
pytype = pytype.as_list_type()
|
461
468
|
cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
|
462
469
|
|
463
470
|
cls_ast(
|
@@ -690,7 +697,12 @@ def make_python_relational_model(
|
|
690
697
|
program.import_(dep, True)
|
691
698
|
|
692
699
|
propname = prop.name
|
693
|
-
|
700
|
+
|
701
|
+
if prop.is_optional:
|
702
|
+
program.import_("typing.Optional", True)
|
703
|
+
proptype = f"Mapped[Optional[{sqltype.mapped_pytype}]]"
|
704
|
+
else:
|
705
|
+
proptype = f"Mapped[{sqltype.mapped_pytype}]"
|
694
706
|
|
695
707
|
propvalargs: list[expr.Expr] = [expr.ExprIdent(sqltype.type)]
|
696
708
|
if prop.db.is_primary_key:
|
@@ -74,6 +74,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
74
74
|
if idprop is not None and prop.name == idprop.name:
|
75
75
|
# use id type alias
|
76
76
|
tstype = TsTypeWithDep(f"{cls.name}Id")
|
77
|
+
|
78
|
+
if prop.is_optional:
|
79
|
+
# convert type to optional
|
80
|
+
tstype = tstype.as_optional_type()
|
77
81
|
|
78
82
|
deser_args.append(
|
79
83
|
(
|
@@ -95,6 +99,9 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
95
99
|
)
|
96
100
|
if prop.cardinality.is_star_to_many():
|
97
101
|
tstype = tstype.as_list_type()
|
102
|
+
elif prop.is_optional:
|
103
|
+
# convert type to optional only if it isn't a list
|
104
|
+
tstype = tstype.as_optional_type()
|
98
105
|
deser_args.append(
|
99
106
|
(
|
100
107
|
expr.ExprIdent(propname),
|
@@ -134,6 +141,9 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
134
141
|
)
|
135
142
|
)
|
136
143
|
else:
|
144
|
+
if prop.is_optional:
|
145
|
+
# convert type to optional only if it isn't a list
|
146
|
+
tstype = tstype.as_optional_type()
|
137
147
|
deser_args.append(
|
138
148
|
(
|
139
149
|
expr.ExprIdent(propname),
|
@@ -329,6 +339,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
329
339
|
# for none id properties, we need to include a type for "invalid" value
|
330
340
|
tstype = _inject_type_for_invalid_value(tstype)
|
331
341
|
|
342
|
+
if prop.is_optional:
|
343
|
+
# convert type to optional
|
344
|
+
tstype = tstype.as_optional_type()
|
345
|
+
|
332
346
|
for dep in tstype.deps:
|
333
347
|
program.import_(dep, True)
|
334
348
|
|
@@ -438,6 +452,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
438
452
|
tstype = tstype.as_list_type()
|
439
453
|
create_propvalue = expr.ExprConstant([])
|
440
454
|
else:
|
455
|
+
if prop.is_optional:
|
456
|
+
# convert type to optional - for list type, we don't need to do this
|
457
|
+
# as we will use empty list as no value
|
458
|
+
tstype = tstype.as_optional_type()
|
441
459
|
# if target class has an auto-increment primary key, we set a different default value
|
442
460
|
# to be -1 to avoid start from 0
|
443
461
|
target_idprop = prop.target.get_id_property()
|
@@ -496,6 +514,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
496
514
|
)
|
497
515
|
)
|
498
516
|
else:
|
517
|
+
if prop.is_optional:
|
518
|
+
# convert type to optional - for list type, we don't need to do this
|
519
|
+
# as we will use empty list as no value
|
520
|
+
tstype = tstype.as_optional_type()
|
499
521
|
create_propvalue = expr.ExprMethodCall(
|
500
522
|
expr.ExprIdent(tstype.type),
|
501
523
|
"create",
|
sera/models/_datatype.py
CHANGED
@@ -97,6 +97,13 @@ class TsTypeWithDep:
|
|
97
97
|
list_type = f"{self.type}[]"
|
98
98
|
return TsTypeWithDep(type=list_type, deps=self.deps)
|
99
99
|
|
100
|
+
def as_optional_type(self) -> TsTypeWithDep:
|
101
|
+
if "undefined" in self.type:
|
102
|
+
raise NotImplementedError(
|
103
|
+
f"Have not handle nested optional yet: {self.type}"
|
104
|
+
)
|
105
|
+
return TsTypeWithDep(type=f"{self.type} | undefined", deps=self.deps)
|
106
|
+
|
100
107
|
|
101
108
|
@dataclass
|
102
109
|
class SQLTypeWithDep:
|
@@ -13,9 +13,9 @@ sera/make/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
sera/make/__main__.py,sha256=G5O7s6135-708honwqMFn2yPTs06WbGQTHpupID0eZ4,1417
|
14
14
|
sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
|
15
15
|
sera/make/make_python_api.py,sha256=kq5DClmEeeNgg-a3Bb_8GN9jxvjnhjmW3RfBHNzynO8,25407
|
16
|
-
sera/make/make_python_model.py,sha256=
|
16
|
+
sera/make/make_python_model.py,sha256=AlNJyyovb99TWocS2jtfTxy0C5YaFizx-Bhwdw1mUNw,41923
|
17
17
|
sera/make/make_python_services.py,sha256=RsinYZdfkrTlTn9CT50VgqGs9w6IZawsJx-KEmqfnEY,2062
|
18
|
-
sera/make/make_typescript_model.py,sha256
|
18
|
+
sera/make/make_typescript_model.py,sha256=Mv6vXhvwQYzbKCMudzymxN_FH1utqaGGJB2dgyB5sIM,52601
|
19
19
|
sera/misc/__init__.py,sha256=Dh4uDq0D4N53h3zhvmwfa5a0TPVRSUvLzb0hkFuPirk,411
|
20
20
|
sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
|
21
21
|
sera/misc/_utils.py,sha256=V5g4oLGHOhUCR75Kkcn1w01pAvGvaepK-T8Z3pIgHjI,1450
|
@@ -23,7 +23,7 @@ sera/models/__init__.py,sha256=vJC5Kzo_N7wd16ocNPy1VvAZDGNiWeiAhWJ4ihATKvA,780
|
|
23
23
|
sera/models/_class.py,sha256=Wf0e8x6-szG9TzoFkAlqj7_dG0SCICMBw_333n3paxk,2514
|
24
24
|
sera/models/_collection.py,sha256=ZnQEriKC4X88Zz48Kn1AVZKH-1_l8OgWa-zf2kcQOOE,1414
|
25
25
|
sera/models/_constraints.py,sha256=L6QwKL3hRJ5DvvIB4JNgLoyvTKbE9FrpYRzezM4CweE,1484
|
26
|
-
sera/models/_datatype.py,sha256=
|
26
|
+
sera/models/_datatype.py,sha256=RDn0lDl_b0O_PwRqobcD1O903owEAEoMzRf4dyRcgBk,6819
|
27
27
|
sera/models/_default.py,sha256=ABggW6qdPR4ZDqIPJdJ0GCGQ-7kfsfZmQ_DchgZEa-I,137
|
28
28
|
sera/models/_enum.py,sha256=sy0q7E646F-APsqrVQ52r1fAQ_DCAeaNq5YM5QN3zIk,2070
|
29
29
|
sera/models/_module.py,sha256=8QRSCubZmdDP9rL58rGAS6X5VCrkc1ZHvuMu1I1KrWk,5043
|
@@ -32,6 +32,6 @@ sera/models/_parse.py,sha256=uw6fvvh1ucGqE2jFTCCr-e6_qMfZfSVpaPolNxmrHww,9897
|
|
32
32
|
sera/models/_property.py,sha256=SJSm5fZJimd2rQuL4UH_aZuNyp9v7x64xMbEVbtYx8Q,5633
|
33
33
|
sera/models/_schema.py,sha256=r-Gqg9Lb_wR3UrbNvfXXgt_qs5bts0t2Ve7aquuF_OI,1155
|
34
34
|
sera/typing.py,sha256=Q4QMfbtfrCjC9tFfsZPhsAnbNX4lm4NHQ9lmjNXYdV0,772
|
35
|
-
sera_2-1.11.
|
36
|
-
sera_2-1.11.
|
37
|
-
sera_2-1.11.
|
35
|
+
sera_2-1.11.3.dist-info/METADATA,sha256=Rw99XGPK9fkwo5e278P34cjeiLdiEq41e-jl7N269hI,857
|
36
|
+
sera_2-1.11.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
37
|
+
sera_2-1.11.3.dist-info/RECORD,,
|
File without changes
|