sera-2 1.11.3__py3-none-any.whl → 1.12.0__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.
@@ -74,7 +74,7 @@ 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
|
-
|
77
|
+
|
78
78
|
if prop.is_optional:
|
79
79
|
# convert type to optional
|
80
80
|
tstype = tstype.as_optional_type()
|
@@ -280,6 +280,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
280
280
|
create_args = []
|
281
281
|
update_args = []
|
282
282
|
ser_args = []
|
283
|
+
to_record_args = []
|
283
284
|
update_field_funcs: list[Callable[[AST], Any]] = []
|
284
285
|
|
285
286
|
prop2tsname = {}
|
@@ -424,6 +425,41 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
424
425
|
),
|
425
426
|
)
|
426
427
|
)
|
428
|
+
|
429
|
+
if not prop.data.is_private:
|
430
|
+
# private property does not include in the public record
|
431
|
+
to_record_args.append(
|
432
|
+
(
|
433
|
+
expr.ExprIdent(propname),
|
434
|
+
(
|
435
|
+
expr.ExprTernary(
|
436
|
+
PredefinedFn.attr_getter(
|
437
|
+
expr.ExprFuncCall(
|
438
|
+
PredefinedFn.attr_getter(
|
439
|
+
expr.ExprIdent(draft_validators),
|
440
|
+
expr.ExprIdent(propname),
|
441
|
+
),
|
442
|
+
[
|
443
|
+
PredefinedFn.attr_getter(
|
444
|
+
expr.ExprIdent("this"),
|
445
|
+
expr.ExprIdent(propname),
|
446
|
+
)
|
447
|
+
],
|
448
|
+
),
|
449
|
+
expr.ExprIdent("isValid"),
|
450
|
+
),
|
451
|
+
PredefinedFn.attr_getter(
|
452
|
+
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
453
|
+
),
|
454
|
+
expr.ExprIdent("undefined"),
|
455
|
+
)
|
456
|
+
if prop.is_optional
|
457
|
+
else PredefinedFn.attr_getter(
|
458
|
+
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
459
|
+
)
|
460
|
+
),
|
461
|
+
)
|
462
|
+
)
|
427
463
|
if not (prop.db is not None and prop.db.is_primary_key):
|
428
464
|
# skip observable for primary key as it is not needed
|
429
465
|
observable_args.append(
|
@@ -481,6 +517,17 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
481
517
|
),
|
482
518
|
)
|
483
519
|
)
|
520
|
+
|
521
|
+
if not prop.data.is_private:
|
522
|
+
# private property does not include in the public record
|
523
|
+
to_record_args.append(
|
524
|
+
(
|
525
|
+
expr.ExprIdent(propname),
|
526
|
+
PredefinedFn.attr_getter(
|
527
|
+
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
528
|
+
),
|
529
|
+
)
|
530
|
+
)
|
484
531
|
else:
|
485
532
|
# we are going to store the whole object
|
486
533
|
tstype = TsTypeWithDep(
|
@@ -510,9 +557,61 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
510
557
|
expr.ExprIdent("this"), expr.ExprIdent(propname)
|
511
558
|
),
|
512
559
|
lambda item: expr.ExprMethodCall(item, "ser", []),
|
560
|
+
(
|
561
|
+
(
|
562
|
+
lambda item: PredefinedFn.attr_getter(
|
563
|
+
expr.ExprFuncCall(
|
564
|
+
PredefinedFn.attr_getter(
|
565
|
+
expr.ExprIdent(
|
566
|
+
draft_validators
|
567
|
+
),
|
568
|
+
expr.ExprIdent(propname),
|
569
|
+
),
|
570
|
+
[item],
|
571
|
+
),
|
572
|
+
expr.ExprIdent("isValid"),
|
573
|
+
)
|
574
|
+
)
|
575
|
+
if prop.is_optional
|
576
|
+
else None
|
577
|
+
),
|
513
578
|
),
|
514
579
|
)
|
515
580
|
)
|
581
|
+
if not prop.data.is_private:
|
582
|
+
# private property does not include in the public record
|
583
|
+
to_record_args.append(
|
584
|
+
(
|
585
|
+
expr.ExprIdent(propname),
|
586
|
+
PredefinedFn.map_list(
|
587
|
+
PredefinedFn.attr_getter(
|
588
|
+
expr.ExprIdent("this"),
|
589
|
+
expr.ExprIdent(propname),
|
590
|
+
),
|
591
|
+
lambda item: expr.ExprMethodCall(
|
592
|
+
item, "toRecord", []
|
593
|
+
),
|
594
|
+
(
|
595
|
+
(
|
596
|
+
lambda item: PredefinedFn.attr_getter(
|
597
|
+
expr.ExprFuncCall(
|
598
|
+
PredefinedFn.attr_getter(
|
599
|
+
expr.ExprIdent(
|
600
|
+
draft_validators
|
601
|
+
),
|
602
|
+
expr.ExprIdent(propname),
|
603
|
+
),
|
604
|
+
[item],
|
605
|
+
),
|
606
|
+
expr.ExprIdent("isValid"),
|
607
|
+
)
|
608
|
+
)
|
609
|
+
if prop.is_optional
|
610
|
+
else None
|
611
|
+
),
|
612
|
+
),
|
613
|
+
)
|
614
|
+
)
|
516
615
|
else:
|
517
616
|
if prop.is_optional:
|
518
617
|
# convert type to optional - for list type, we don't need to do this
|
@@ -532,18 +631,103 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
532
631
|
),
|
533
632
|
],
|
534
633
|
)
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
634
|
+
|
635
|
+
if prop.is_optional:
|
636
|
+
ser_args.append(
|
637
|
+
(
|
638
|
+
expr.ExprIdent(prop.name),
|
639
|
+
expr.ExprTernary(
|
640
|
+
PredefinedFn.attr_getter(
|
641
|
+
expr.ExprFuncCall(
|
642
|
+
PredefinedFn.attr_getter(
|
643
|
+
expr.ExprIdent(draft_validators),
|
644
|
+
expr.ExprIdent(propname),
|
645
|
+
),
|
646
|
+
[
|
647
|
+
PredefinedFn.attr_getter(
|
648
|
+
expr.ExprIdent("this"),
|
649
|
+
expr.ExprIdent(propname),
|
650
|
+
)
|
651
|
+
],
|
652
|
+
),
|
653
|
+
expr.ExprIdent("isValid"),
|
654
|
+
),
|
655
|
+
expr.ExprMethodCall(
|
656
|
+
PredefinedFn.attr_getter(
|
657
|
+
expr.ExprIdent("this"),
|
658
|
+
expr.ExprIdent(propname),
|
659
|
+
),
|
660
|
+
"ser",
|
661
|
+
[],
|
662
|
+
),
|
663
|
+
expr.ExprIdent("undefined"),
|
541
664
|
),
|
542
|
-
|
543
|
-
[],
|
544
|
-
),
|
665
|
+
)
|
545
666
|
)
|
546
|
-
|
667
|
+
if not prop.data.is_private:
|
668
|
+
# private property does not include in the public record
|
669
|
+
to_record_args.append(
|
670
|
+
(
|
671
|
+
expr.ExprIdent(propname),
|
672
|
+
expr.ExprTernary(
|
673
|
+
PredefinedFn.attr_getter(
|
674
|
+
expr.ExprFuncCall(
|
675
|
+
PredefinedFn.attr_getter(
|
676
|
+
expr.ExprIdent(
|
677
|
+
draft_validators
|
678
|
+
),
|
679
|
+
expr.ExprIdent(propname),
|
680
|
+
),
|
681
|
+
[
|
682
|
+
PredefinedFn.attr_getter(
|
683
|
+
expr.ExprIdent("this"),
|
684
|
+
expr.ExprIdent(propname),
|
685
|
+
)
|
686
|
+
],
|
687
|
+
),
|
688
|
+
expr.ExprIdent("isValid"),
|
689
|
+
),
|
690
|
+
expr.ExprMethodCall(
|
691
|
+
PredefinedFn.attr_getter(
|
692
|
+
expr.ExprIdent("this"),
|
693
|
+
expr.ExprIdent(propname),
|
694
|
+
),
|
695
|
+
"toRecord",
|
696
|
+
[],
|
697
|
+
),
|
698
|
+
expr.ExprIdent("undefined"),
|
699
|
+
),
|
700
|
+
)
|
701
|
+
)
|
702
|
+
else:
|
703
|
+
ser_args.append(
|
704
|
+
(
|
705
|
+
expr.ExprIdent(prop.name),
|
706
|
+
expr.ExprMethodCall(
|
707
|
+
PredefinedFn.attr_getter(
|
708
|
+
expr.ExprIdent("this"),
|
709
|
+
expr.ExprIdent(propname),
|
710
|
+
),
|
711
|
+
"ser",
|
712
|
+
[],
|
713
|
+
),
|
714
|
+
)
|
715
|
+
)
|
716
|
+
if not prop.data.is_private:
|
717
|
+
# private property does not include in the public record
|
718
|
+
to_record_args.append(
|
719
|
+
(
|
720
|
+
expr.ExprIdent(propname),
|
721
|
+
expr.ExprMethodCall(
|
722
|
+
PredefinedFn.attr_getter(
|
723
|
+
expr.ExprIdent("this"),
|
724
|
+
expr.ExprIdent(propname),
|
725
|
+
),
|
726
|
+
"toRecord",
|
727
|
+
[],
|
728
|
+
),
|
729
|
+
)
|
730
|
+
)
|
547
731
|
|
548
732
|
for dep in tstype.deps:
|
549
733
|
program.import_(
|
@@ -752,6 +936,20 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
752
936
|
PredefinedFn.dict(ser_args),
|
753
937
|
),
|
754
938
|
),
|
939
|
+
stmt.LineBreak(),
|
940
|
+
lambda ast16: ast16.func(
|
941
|
+
"toRecord",
|
942
|
+
[],
|
943
|
+
expr.ExprIdent(cls.name),
|
944
|
+
comment="Convert the draft to a normal record. `isValid` must be called first to ensure all data is valid",
|
945
|
+
)(
|
946
|
+
stmt.ReturnStatement(
|
947
|
+
expr.ExprNewInstance(
|
948
|
+
expr.ExprIdent(cls.name),
|
949
|
+
[PredefinedFn.dict(to_record_args)],
|
950
|
+
),
|
951
|
+
)
|
952
|
+
),
|
755
953
|
),
|
756
954
|
stmt.LineBreak(),
|
757
955
|
stmt.TypescriptStatement(
|
@@ -15,7 +15,7 @@ sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
|
|
15
15
|
sera/make/make_python_api.py,sha256=kq5DClmEeeNgg-a3Bb_8GN9jxvjnhjmW3RfBHNzynO8,25407
|
16
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=-Z3vHblUcEpWvMMdzQGZ9XWhUjLv99PBJGqZHsF0m1o,63686
|
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
|
@@ -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.
|
36
|
-
sera_2-1.
|
37
|
-
sera_2-1.
|
35
|
+
sera_2-1.12.0.dist-info/METADATA,sha256=9OsTsh39Me41u3v-tRUiddDVkLKE-Qra7eMQLa8Kt2k,857
|
36
|
+
sera_2-1.12.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
37
|
+
sera_2-1.12.0.dist-info/RECORD,,
|
File without changes
|