sera-2 1.7.1__py3-none-any.whl → 1.7.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.
@@ -241,8 +241,15 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
241
241
|
program.import_("mobx.makeObservable", True)
|
242
242
|
program.import_("mobx.observable", True)
|
243
243
|
program.import_("mobx.action", True)
|
244
|
+
program.import_("sera-db.validators", True)
|
244
245
|
|
245
|
-
program.root
|
246
|
+
program.root(
|
247
|
+
stmt.LineBreak(),
|
248
|
+
stmt.TypescriptStatement(
|
249
|
+
"const {getValidator, memoizeOneValidators} = validators;"
|
250
|
+
),
|
251
|
+
stmt.LineBreak(),
|
252
|
+
)
|
246
253
|
|
247
254
|
# make sure that the property stale is not in existing properties
|
248
255
|
if "stale" in cls.properties:
|
@@ -252,6 +259,7 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
252
259
|
cls_pk = None
|
253
260
|
observable_args: list[tuple[expr.Expr, expr.ExprIdent]] = []
|
254
261
|
prop_defs = []
|
262
|
+
prop_validators = []
|
255
263
|
prop_constructor_assigns = []
|
256
264
|
# attrs needed for the cls.create function
|
257
265
|
create_args = []
|
@@ -330,6 +338,25 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
330
338
|
else:
|
331
339
|
create_propvalue = tstype.get_default()
|
332
340
|
|
341
|
+
prop_validators.append(
|
342
|
+
(
|
343
|
+
expr.ExprIdent(propname),
|
344
|
+
expr.ExprFuncCall(
|
345
|
+
expr.ExprIdent("getValidator"),
|
346
|
+
[
|
347
|
+
PredefinedFn.list(
|
348
|
+
[
|
349
|
+
expr.ExprConstant(
|
350
|
+
constraint.get_typescript_constraint()
|
351
|
+
)
|
352
|
+
for constraint in prop.data.constraints
|
353
|
+
]
|
354
|
+
),
|
355
|
+
],
|
356
|
+
),
|
357
|
+
)
|
358
|
+
)
|
359
|
+
|
333
360
|
if prop.db is not None and prop.db.is_primary_key:
|
334
361
|
# for checking if the primary key is from the database or default (create_propvalue)
|
335
362
|
cls_pk = (expr.ExprIdent(propname), create_propvalue)
|
@@ -479,6 +506,26 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
479
506
|
)
|
480
507
|
)
|
481
508
|
|
509
|
+
# TODO: fix me!
|
510
|
+
prop_validators.append(
|
511
|
+
(
|
512
|
+
expr.ExprIdent(propname),
|
513
|
+
expr.ExprFuncCall(
|
514
|
+
expr.ExprIdent("getValidator"),
|
515
|
+
[
|
516
|
+
PredefinedFn.list(
|
517
|
+
[
|
518
|
+
expr.ExprConstant(
|
519
|
+
constraint.get_typescript_constraint()
|
520
|
+
)
|
521
|
+
for constraint in prop.data.constraints
|
522
|
+
]
|
523
|
+
),
|
524
|
+
],
|
525
|
+
),
|
526
|
+
)
|
527
|
+
)
|
528
|
+
|
482
529
|
prop_defs.append(stmt.DefClassVarStatement(propname, tstype.type))
|
483
530
|
prop_constructor_assigns.append(
|
484
531
|
stmt.AssignStatement(
|
@@ -530,6 +577,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
530
577
|
)
|
531
578
|
observable_args.sort(key=lambda x: {"observable": 0, "action": 1}[x[1].ident])
|
532
579
|
|
580
|
+
validators = expr.ExprFuncCall(
|
581
|
+
expr.ExprIdent("memoizeOneValidators"), [PredefinedFn.dict(prop_validators)]
|
582
|
+
)
|
583
|
+
|
533
584
|
program.root(
|
534
585
|
lambda ast00: ast00.class_like(
|
535
586
|
"interface",
|
@@ -623,6 +674,12 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
623
674
|
),
|
624
675
|
),
|
625
676
|
),
|
677
|
+
stmt.LineBreak(),
|
678
|
+
stmt.TypescriptStatement(
|
679
|
+
f"export const draft{cls.name}Validators = "
|
680
|
+
+ validators.to_typescript()
|
681
|
+
+ ";"
|
682
|
+
),
|
626
683
|
)
|
627
684
|
|
628
685
|
pkg.module("Draft" + cls.name).write(program)
|
@@ -869,6 +926,9 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
869
926
|
program.import_(
|
870
927
|
f"@.models.{pkg.dir.name}.Draft{cls.name}.Draft{cls.name}", True
|
871
928
|
)
|
929
|
+
program.import_(
|
930
|
+
f"@.models.{pkg.dir.name}.Draft{cls.name}.draft{cls.name}Validators", True
|
931
|
+
)
|
872
932
|
program.root(
|
873
933
|
stmt.LineBreak(),
|
874
934
|
stmt.TypescriptStatement(
|
@@ -960,6 +1020,10 @@ def make_typescript_data_model(schema: Schema, target_pkg: Package):
|
|
960
1020
|
+ "}"
|
961
1021
|
),
|
962
1022
|
),
|
1023
|
+
(
|
1024
|
+
expr.ExprIdent("validators"),
|
1025
|
+
expr.ExprIdent(f"draft{cls.name}Validators"),
|
1026
|
+
),
|
963
1027
|
]
|
964
1028
|
+ (
|
965
1029
|
[
|
@@ -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=E7HT3cmPnhw2HUdtWLOc3pz4EpvHW9EaMjHS_s1gvL4,48011
|
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.7.
|
33
|
-
sera_2-1.7.
|
34
|
-
sera_2-1.7.
|
32
|
+
sera_2-1.7.3.dist-info/METADATA,sha256=5HVujlhHjtBZxvO3R-6jbu2uYCjybYB9kAknXeSx4AY,856
|
33
|
+
sera_2-1.7.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
34
|
+
sera_2-1.7.3.dist-info/RECORD,,
|
File without changes
|