sera-2 1.7.3__py3-none-any.whl → 1.8.1__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.
@@ -235,6 +235,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
235
235
|
idprop = cls.get_id_property()
|
236
236
|
|
237
237
|
draft_clsname = "Draft" + cls.name
|
238
|
+
draft_validators = f"draft{cls.name}Validators"
|
238
239
|
|
239
240
|
program = Program()
|
240
241
|
program.import_(f"@.models.{pkg.dir.name}.{cls.name}.{cls.name}", True)
|
@@ -259,7 +260,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
259
260
|
cls_pk = None
|
260
261
|
observable_args: list[tuple[expr.Expr, expr.ExprIdent]] = []
|
261
262
|
prop_defs = []
|
262
|
-
prop_validators = []
|
263
|
+
prop_validators: list[tuple[expr.ExprIdent, expr.Expr]] = []
|
263
264
|
prop_constructor_assigns = []
|
264
265
|
# attrs needed for the cls.create function
|
265
266
|
create_args = []
|
@@ -267,12 +268,15 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
267
268
|
ser_args = []
|
268
269
|
update_field_funcs: list[Callable[[AST], Any]] = []
|
269
270
|
|
271
|
+
prop2tsname = {}
|
272
|
+
|
270
273
|
for prop in cls.properties.values():
|
271
274
|
# if prop.data.is_private:
|
272
275
|
# # skip private fields as this is for APIs exchange
|
273
276
|
# continue
|
274
277
|
|
275
278
|
propname = to_camel_case(prop.name)
|
279
|
+
prop2tsname[prop.name] = propname
|
276
280
|
|
277
281
|
def _update_field_func(
|
278
282
|
prop: DataProperty | ObjectProperty,
|
@@ -373,8 +377,32 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
373
377
|
ser_args.append(
|
374
378
|
(
|
375
379
|
expr.ExprIdent(prop.name),
|
376
|
-
|
377
|
-
expr.
|
380
|
+
(
|
381
|
+
expr.ExprTernary(
|
382
|
+
PredefinedFn.attr_getter(
|
383
|
+
expr.ExprFuncCall(
|
384
|
+
PredefinedFn.attr_getter(
|
385
|
+
expr.ExprIdent(draft_validators),
|
386
|
+
expr.ExprIdent(propname),
|
387
|
+
),
|
388
|
+
[
|
389
|
+
PredefinedFn.attr_getter(
|
390
|
+
expr.ExprIdent("this"),
|
391
|
+
expr.ExprIdent(propname),
|
392
|
+
)
|
393
|
+
],
|
394
|
+
),
|
395
|
+
expr.ExprIdent("isValid"),
|
396
|
+
),
|
397
|
+
PredefinedFn.attr_getter(
|
398
|
+
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
399
|
+
),
|
400
|
+
expr.ExprIdent("undefined"),
|
401
|
+
)
|
402
|
+
if prop.is_optional
|
403
|
+
else PredefinedFn.attr_getter(
|
404
|
+
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
405
|
+
)
|
378
406
|
),
|
379
407
|
)
|
380
408
|
)
|
@@ -614,7 +642,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
614
642
|
stmt.LineBreak(),
|
615
643
|
lambda ast11: (
|
616
644
|
ast11.func(
|
617
|
-
"
|
645
|
+
"isNewRecord",
|
618
646
|
[],
|
619
647
|
expr.ExprIdent("boolean"),
|
620
648
|
comment="Check if this draft is for creating a new record",
|
@@ -664,10 +692,27 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
664
692
|
*update_field_funcs,
|
665
693
|
stmt.LineBreak(),
|
666
694
|
lambda ast14: ast14.func(
|
695
|
+
"isValid",
|
696
|
+
[],
|
697
|
+
expr.ExprIdent("boolean"),
|
698
|
+
comment="Check if the draft is valid (only check the required fields as the non-required fields if it's invalid will be set to undefined)",
|
699
|
+
)(
|
700
|
+
stmt.ReturnStatement(
|
701
|
+
stmt.TypescriptStatement(
|
702
|
+
" && ".join(
|
703
|
+
f"{draft_validators}.{prop2tsname[prop.name]}(this.{prop2tsname[prop.name]}).isValid"
|
704
|
+
for prop in cls.properties.values()
|
705
|
+
if not prop.is_optional
|
706
|
+
)
|
707
|
+
)
|
708
|
+
)
|
709
|
+
),
|
710
|
+
stmt.LineBreak(),
|
711
|
+
lambda ast15: ast15.func(
|
667
712
|
"ser",
|
668
713
|
[],
|
669
714
|
expr.ExprIdent("any"),
|
670
|
-
comment="Serialize the draft to communicate with the server",
|
715
|
+
comment="Serialize the draft to communicate with the server. `isValid` must be called first to ensure all data is valid",
|
671
716
|
)(
|
672
717
|
stmt.ReturnStatement(
|
673
718
|
PredefinedFn.dict(ser_args),
|
@@ -676,9 +721,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
676
721
|
),
|
677
722
|
stmt.LineBreak(),
|
678
723
|
stmt.TypescriptStatement(
|
679
|
-
f"export const
|
680
|
-
+ validators.to_typescript()
|
681
|
-
+ ";"
|
724
|
+
f"export const {draft_validators} = " + validators.to_typescript() + ";"
|
682
725
|
),
|
683
726
|
)
|
684
727
|
|
@@ -12,7 +12,7 @@ sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
|
|
12
12
|
sera/make/make_python_api.py,sha256=RuJUm9z-4plBEtjobeOPr12o27OT-0tSeXI4ZlM3IY0,29433
|
13
13
|
sera/make/make_python_model.py,sha256=xf4revAwVWEnF6QhxbbqPyUGgXOOB--Gu3jPxsESg0Y,36593
|
14
14
|
sera/make/make_python_services.py,sha256=RsinYZdfkrTlTn9CT50VgqGs9w6IZawsJx-KEmqfnEY,2062
|
15
|
-
sera/make/make_typescript_model.py,sha256=
|
15
|
+
sera/make/make_typescript_model.py,sha256=8p4rW8VUcBvoMT4a5qxBDDtRWNGKT1TtwLUaVlAQKcE,50313
|
16
16
|
sera/misc/__init__.py,sha256=Dh4uDq0D4N53h3zhvmwfa5a0TPVRSUvLzb0hkFuPirk,411
|
17
17
|
sera/misc/_formatter.py,sha256=aCGYL08l8f3aLODHxSocxBBwkRYEo3K1QzCDEn3suj0,1685
|
18
18
|
sera/misc/_utils.py,sha256=V5g4oLGHOhUCR75Kkcn1w01pAvGvaepK-T8Z3pIgHjI,1450
|
@@ -29,6 +29,6 @@ sera/models/_parse.py,sha256=sJYfQtwek96ltpgxExG4xUbiLnU3qvNYhTP1CeyXGjs,9746
|
|
29
29
|
sera/models/_property.py,sha256=CmEmgOShtSyNFq05YW3tGupwCIVRzPMKudXWld8utPk,5530
|
30
30
|
sera/models/_schema.py,sha256=r-Gqg9Lb_wR3UrbNvfXXgt_qs5bts0t2Ve7aquuF_OI,1155
|
31
31
|
sera/typing.py,sha256=Q4QMfbtfrCjC9tFfsZPhsAnbNX4lm4NHQ9lmjNXYdV0,772
|
32
|
-
sera_2-1.
|
33
|
-
sera_2-1.
|
34
|
-
sera_2-1.
|
32
|
+
sera_2-1.8.1.dist-info/METADATA,sha256=sC0YgpGbfu40AIY15e8606v8v1CyTvBDRSEbIisRhkg,856
|
33
|
+
sera_2-1.8.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
34
|
+
sera_2-1.8.1.dist-info/RECORD,,
|
File without changes
|