ballerina-core 1.0.83 → 1.0.84
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.
- package/package.json +1 -1
- package/src/forms/domains/parser/domains/built-ins/state.ts +41 -11
- package/src/forms/domains/parser/domains/predicates/state.ts +175 -58
- package/src/forms/domains/parser/domains/renderer/state.ts +35 -35
- package/src/forms/domains/parser/domains/types/state.ts +15 -8
- package/src/forms/domains/parser/state.tsx +15 -9
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
PredicateValue,
|
|
13
13
|
Sum,
|
|
14
14
|
TypeName,
|
|
15
|
+
unit,
|
|
15
16
|
ValueRecord,
|
|
16
17
|
ValueTuple,
|
|
17
18
|
} from "../../../../../../main";
|
|
@@ -60,7 +61,7 @@ export type ApiConverters<
|
|
|
60
61
|
> = { [key in keyof T]: ApiConverter<T[key]["type"]> } & BuiltInApiConverters;
|
|
61
62
|
|
|
62
63
|
export type VerifiedRawUnionCase = {
|
|
63
|
-
|
|
64
|
+
case: string;
|
|
64
65
|
fields: Record<string, any>;
|
|
65
66
|
};
|
|
66
67
|
|
|
@@ -70,7 +71,7 @@ export const VerifiedRawUnionCase = {
|
|
|
70
71
|
return (
|
|
71
72
|
typeof value == "object" &&
|
|
72
73
|
"caseName" in value &&
|
|
73
|
-
typeof value.
|
|
74
|
+
typeof value.case == "string" &&
|
|
74
75
|
"fields" in value &&
|
|
75
76
|
typeof value.fields == "object"
|
|
76
77
|
);
|
|
@@ -325,8 +326,19 @@ export const fromAPIRawValue =
|
|
|
325
326
|
);
|
|
326
327
|
}
|
|
327
328
|
if (t.kind == "union") {
|
|
329
|
+
if (!VerifiedRawUnionCase.Operations.IsVerifiedRawUnionCase(raw)) {
|
|
330
|
+
return ValueOrErrors.Default.throwOne(
|
|
331
|
+
`union expected but got ${JSON.stringify(raw)}`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const caseType = t.args.get(raw.case);
|
|
335
|
+
if (caseType == undefined) {
|
|
336
|
+
return ValueOrErrors.Default.throwOne(
|
|
337
|
+
`union case ${raw.case} not found in type ${JSON.stringify(t)}`,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
328
340
|
return fromAPIRawValue(
|
|
329
|
-
|
|
341
|
+
caseType,
|
|
330
342
|
types,
|
|
331
343
|
builtIns,
|
|
332
344
|
converters,
|
|
@@ -340,12 +352,28 @@ export const fromAPIRawValue =
|
|
|
340
352
|
);
|
|
341
353
|
}
|
|
342
354
|
const result = converters[t.kind].fromAPIRawValue(raw);
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
355
|
+
return fromAPIRawValue(
|
|
356
|
+
t.fields == unit
|
|
357
|
+
? {
|
|
358
|
+
kind: "form",
|
|
359
|
+
value: "unionCase",
|
|
360
|
+
fields: Map<string, ParsedType<T>>(),
|
|
361
|
+
}
|
|
362
|
+
: t.fields,
|
|
363
|
+
types,
|
|
364
|
+
builtIns,
|
|
365
|
+
converters,
|
|
366
|
+
injectedPrimitives,
|
|
367
|
+
)(result.fields).Then((fields) => {
|
|
368
|
+
if (!PredicateValue.Operations.IsRecord(fields)) {
|
|
369
|
+
return ValueOrErrors.Default.throwOne(
|
|
370
|
+
`record expected but got ${JSON.stringify(fields)}`,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
return ValueOrErrors.Default.return(
|
|
374
|
+
PredicateValue.Default.unionCase(result.case, fields),
|
|
375
|
+
);
|
|
376
|
+
});
|
|
349
377
|
}
|
|
350
378
|
if (t.kind == "application") {
|
|
351
379
|
if (t.value == "SingleSelection") {
|
|
@@ -567,7 +595,7 @@ export const toAPIRawValue =
|
|
|
567
595
|
}
|
|
568
596
|
return ValueOrErrors.Operations.Return(
|
|
569
597
|
converters[t.kind].toAPIRawValue([
|
|
570
|
-
{
|
|
598
|
+
{ case: raw.caseName, fields: raw.fields },
|
|
571
599
|
formState.modifiedByUser,
|
|
572
600
|
]),
|
|
573
601
|
);
|
|
@@ -637,7 +665,9 @@ export const toAPIRawValue =
|
|
|
637
665
|
!EnumReference.Operations.IsEnumReference(fieldsObject)
|
|
638
666
|
) {
|
|
639
667
|
return ValueOrErrors.Default.throwOne(
|
|
640
|
-
`CollectionReference or EnumReference expected but got ${JSON.stringify(
|
|
668
|
+
`CollectionReference or EnumReference expected but got ${JSON.stringify(
|
|
669
|
+
fieldsObject,
|
|
670
|
+
)}`,
|
|
641
671
|
);
|
|
642
672
|
}
|
|
643
673
|
return ValueOrErrors.Default.return(fieldsObject);
|
|
@@ -177,6 +177,9 @@ export type PredicateValue =
|
|
|
177
177
|
| ValueOption
|
|
178
178
|
| ValueVarLookup;
|
|
179
179
|
|
|
180
|
+
export type ExprLambda = { kind: "lambda"; parameter: string; body: Expr };
|
|
181
|
+
export type ExprMatchCase = { kind: "matchCase"; operands: Expr[] };
|
|
182
|
+
export type ExprCase = { kind: "caseName"; caseName: string; handler: ExprLambda };
|
|
180
183
|
export type ExprFieldLookup = { kind: "fieldLookup"; operands: [Expr, string] };
|
|
181
184
|
export type ExprIsCase = { kind: "isCase"; operands: [Expr, string] };
|
|
182
185
|
export type ExprBinaryOperator = {
|
|
@@ -188,7 +191,10 @@ export type Expr =
|
|
|
188
191
|
| PredicateValue
|
|
189
192
|
| ExprFieldLookup
|
|
190
193
|
| ExprIsCase
|
|
191
|
-
| ExprBinaryOperator
|
|
194
|
+
| ExprBinaryOperator
|
|
195
|
+
| ExprLambda
|
|
196
|
+
| ExprMatchCase
|
|
197
|
+
| ExprCase;
|
|
192
198
|
|
|
193
199
|
export const BinaryOperators = ["or", "equals"] as const;
|
|
194
200
|
export const BinaryOperatorsSet = Set(BinaryOperators);
|
|
@@ -451,11 +457,6 @@ export const PredicateValue = {
|
|
|
451
457
|
return PredicateValue.Operations.parse(json, subType, types);
|
|
452
458
|
}
|
|
453
459
|
if (type.kind == "unionCase") {
|
|
454
|
-
if (Object.keys(type.fields).length > 0) {
|
|
455
|
-
return ValueOrErrors.Default.throwOne(
|
|
456
|
-
`Error: union case ${type} has fields, not a valid enum`,
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
460
|
return PredicateValue.Operations.ParseAsUnionCase({
|
|
460
461
|
kind: "unionCase",
|
|
461
462
|
caseName: json,
|
|
@@ -466,7 +467,7 @@ export const PredicateValue = {
|
|
|
466
467
|
const unionCase = type.args.get(json);
|
|
467
468
|
if (unionCase == undefined) {
|
|
468
469
|
return ValueOrErrors.Default.throwOne(
|
|
469
|
-
`Error: cannot find union case ${json} in types`,
|
|
470
|
+
`Error: cannot find union case ${JSON.stringify(json)} in types`,
|
|
470
471
|
);
|
|
471
472
|
}
|
|
472
473
|
return PredicateValue.Operations.parse(json, unionCase, types);
|
|
@@ -658,6 +659,20 @@ export const Expr = {
|
|
|
658
659
|
kind: op,
|
|
659
660
|
operands: [e1, e2],
|
|
660
661
|
}),
|
|
662
|
+
matchCase: (operands: Expr[]): Expr => ({
|
|
663
|
+
kind: "matchCase",
|
|
664
|
+
operands,
|
|
665
|
+
}),
|
|
666
|
+
lambda: (parameter: string, body: Expr): Expr => ({
|
|
667
|
+
kind: "lambda",
|
|
668
|
+
parameter,
|
|
669
|
+
body,
|
|
670
|
+
}),
|
|
671
|
+
case: (caseName: string, handler: ExprLambda): Expr => ({
|
|
672
|
+
kind: "caseName",
|
|
673
|
+
caseName,
|
|
674
|
+
handler,
|
|
675
|
+
}),
|
|
661
676
|
},
|
|
662
677
|
Operations: {
|
|
663
678
|
IsFieldLookup: (e: Expr): e is ExprFieldLookup => {
|
|
@@ -681,6 +696,30 @@ export const Expr = {
|
|
|
681
696
|
BinaryOperatorsSet.has(e.kind as BinaryOperator)
|
|
682
697
|
);
|
|
683
698
|
},
|
|
699
|
+
IsCase: (e: Expr): e is ExprCase => {
|
|
700
|
+
return (
|
|
701
|
+
typeof e == "object" &&
|
|
702
|
+
!PredicateValue.Operations.IsDate(e) &&
|
|
703
|
+
e.kind == "caseName"
|
|
704
|
+
);
|
|
705
|
+
},
|
|
706
|
+
IsCaseArray: (e: Expr[]): e is ExprCase[] => {
|
|
707
|
+
return e.every((e) => Expr.Operations.IsCase(e));
|
|
708
|
+
},
|
|
709
|
+
IsMatchCase: (e: Expr): e is ExprMatchCase => {
|
|
710
|
+
return (
|
|
711
|
+
typeof e == "object" &&
|
|
712
|
+
!PredicateValue.Operations.IsDate(e) &&
|
|
713
|
+
e.kind == "matchCase"
|
|
714
|
+
);
|
|
715
|
+
},
|
|
716
|
+
IsLambda: (e: Expr): e is ExprLambda => {
|
|
717
|
+
return (
|
|
718
|
+
typeof e == "object" &&
|
|
719
|
+
!PredicateValue.Operations.IsDate(e) &&
|
|
720
|
+
e.kind == "lambda"
|
|
721
|
+
);
|
|
722
|
+
},
|
|
684
723
|
parse: (json: any): ValueOrErrors<Expr, string> => {
|
|
685
724
|
const asValue = PredicateValue.Operations.parse(
|
|
686
725
|
json,
|
|
@@ -688,27 +727,22 @@ export const Expr = {
|
|
|
688
727
|
Map<string, ParsedType<unknown>>(),
|
|
689
728
|
);
|
|
690
729
|
if (asValue.kind == "value") return asValue;
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
"operands"
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
730
|
+
|
|
731
|
+
if (Expr.Operations.IsFieldLookup(json)) {
|
|
732
|
+
const [first, second]: Array<any> = json["operands"];
|
|
733
|
+
return Expr.Operations.parse(first).Then((first) =>
|
|
734
|
+
ValueOrErrors.Default.return(Expr.Default.fieldLookup(first, second)),
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
if (Expr.Operations.IsIsCase(json)) {
|
|
738
|
+
const [first, second]: Array<any> = json["operands"];
|
|
739
|
+
return Expr.Operations.parse(first).Then((first) =>
|
|
740
|
+
ValueOrErrors.Default.return(Expr.Default.isCase(first, second)),
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (Expr.Operations.IsBinaryOperator(json)) {
|
|
699
745
|
const [first, second]: Array<any> = json["operands"];
|
|
700
|
-
if (json["kind"] == "fieldLookup" && typeof second == "string") {
|
|
701
|
-
return Expr.Operations.parse(first).Then((first) =>
|
|
702
|
-
ValueOrErrors.Default.return(
|
|
703
|
-
Expr.Default.fieldLookup(first, second),
|
|
704
|
-
),
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
if (json["kind"] == "isCase" && typeof second == "string") {
|
|
708
|
-
return Expr.Operations.parse(first).Then((first) =>
|
|
709
|
-
ValueOrErrors.Default.return(Expr.Default.isCase(first, second)),
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
746
|
if (BinaryOperatorsSet.contains(json["kind"] as BinaryOperator)) {
|
|
713
747
|
return Expr.Operations.parse(first).Then((first) =>
|
|
714
748
|
Expr.Operations.parse(second).Then((second) =>
|
|
@@ -719,6 +753,36 @@ export const Expr = {
|
|
|
719
753
|
);
|
|
720
754
|
}
|
|
721
755
|
}
|
|
756
|
+
|
|
757
|
+
if (Expr.Operations.IsMatchCase(json)) {
|
|
758
|
+
return ValueOrErrors.Operations.All(
|
|
759
|
+
List<ValueOrErrors<Expr, string>>(
|
|
760
|
+
json["operands"].map((operand) => Expr.Operations.parse(operand)),
|
|
761
|
+
),
|
|
762
|
+
).Then((operands) =>
|
|
763
|
+
ValueOrErrors.Default.return(
|
|
764
|
+
Expr.Default.matchCase(operands.toArray()),
|
|
765
|
+
),
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
if (Expr.Operations.IsLambda(json)) {
|
|
769
|
+
return Expr.Operations.parse(json["body"]).Then((body) =>
|
|
770
|
+
ValueOrErrors.Default.return(
|
|
771
|
+
Expr.Default.lambda(json["parameter"], body),
|
|
772
|
+
),
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
if (Expr.Operations.IsCase(json)) {
|
|
776
|
+
return Expr.Operations.parse(json["handler"]).Then((handler) =>
|
|
777
|
+
Expr.Operations.IsLambda(handler)
|
|
778
|
+
? ValueOrErrors.Default.return(
|
|
779
|
+
Expr.Default.case(json["caseName"], handler),
|
|
780
|
+
)
|
|
781
|
+
: ValueOrErrors.Default.throwOne(
|
|
782
|
+
`Error: expected lambda, got ${JSON.stringify(handler)}`,
|
|
783
|
+
),
|
|
784
|
+
);
|
|
785
|
+
}
|
|
722
786
|
return ValueOrErrors.Default.throwOne(
|
|
723
787
|
`Error: cannot parse ${JSON.stringify(json)} to Expr.`,
|
|
724
788
|
);
|
|
@@ -747,6 +811,26 @@ export const Expr = {
|
|
|
747
811
|
`Error: expected boolean, got ${JSON.stringify(e)}`,
|
|
748
812
|
)
|
|
749
813
|
: ValueOrErrors.Default.return(e),
|
|
814
|
+
MatchCase:
|
|
815
|
+
(vars: Bindings) =>
|
|
816
|
+
(
|
|
817
|
+
e: ValueUnionCase,
|
|
818
|
+
cases: ExprCase[],
|
|
819
|
+
): ValueOrErrors<PredicateValue, string> => {
|
|
820
|
+
const matchedCase = cases.find((c) => c.caseName == e.caseName);
|
|
821
|
+
if (matchedCase == undefined) {
|
|
822
|
+
return ValueOrErrors.Default.throwOne(
|
|
823
|
+
`Error: cannot find match case ${JSON.stringify(
|
|
824
|
+
e.caseName,
|
|
825
|
+
)} in ${JSON.stringify(cases)}`,
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
const updatedBindings = vars.set(
|
|
829
|
+
matchedCase.handler.parameter,
|
|
830
|
+
e.fields,
|
|
831
|
+
);
|
|
832
|
+
return Expr.Operations.Evaluate(updatedBindings)(matchedCase.handler);
|
|
833
|
+
},
|
|
750
834
|
Evaluate:
|
|
751
835
|
(vars: Bindings) =>
|
|
752
836
|
(e: Expr): ValueOrErrors<PredicateValue, string> => {
|
|
@@ -767,8 +851,8 @@ export const Expr = {
|
|
|
767
851
|
)
|
|
768
852
|
: Expr.Operations.IsFieldLookup(e)
|
|
769
853
|
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then(
|
|
770
|
-
(
|
|
771
|
-
Expr.Operations.EvaluateAsRecord(vars)(
|
|
854
|
+
(maybeRecord: PredicateValue) =>
|
|
855
|
+
Expr.Operations.EvaluateAsRecord(vars)(maybeRecord).Then(
|
|
772
856
|
(record: ValueRecord) =>
|
|
773
857
|
MapRepo.Operations.tryFindWithError(
|
|
774
858
|
e.operands[1],
|
|
@@ -782,39 +866,68 @@ export const Expr = {
|
|
|
782
866
|
)
|
|
783
867
|
: Expr.Operations.IsIsCase(e)
|
|
784
868
|
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then(
|
|
785
|
-
(
|
|
786
|
-
Expr.Operations.EvaluateAsUnionCase(vars)(
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
),
|
|
792
|
-
)
|
|
793
|
-
: Expr.Operations.IsBinaryOperator(e) && e.kind == "equals"
|
|
794
|
-
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then((v1) =>
|
|
795
|
-
Expr.Operations.Evaluate(vars)(e.operands[1]).Then((v2) =>
|
|
796
|
-
PredicateValue.Operations.Equals(vars)(v1, v2).Then(
|
|
797
|
-
(eq) => ValueOrErrors.Default.return(eq),
|
|
869
|
+
(maybeUnionCase: PredicateValue) =>
|
|
870
|
+
Expr.Operations.EvaluateAsUnionCase(vars)(
|
|
871
|
+
maybeUnionCase,
|
|
872
|
+
).Then((unionCase: ValueUnionCase) =>
|
|
873
|
+
ValueOrErrors.Default.return(
|
|
874
|
+
unionCase.caseName == e.operands[1],
|
|
798
875
|
),
|
|
799
876
|
),
|
|
877
|
+
)
|
|
878
|
+
: Expr.Operations.IsMatchCase(e)
|
|
879
|
+
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then(
|
|
880
|
+
(maybeUnionCase: PredicateValue) =>
|
|
881
|
+
Expr.Operations.EvaluateAsUnionCase(vars)(
|
|
882
|
+
maybeUnionCase,
|
|
883
|
+
).Then((unionCase: ValueUnionCase) => {
|
|
884
|
+
const cases = e.operands.slice(1);
|
|
885
|
+
if (!Expr.Operations.IsCaseArray(cases)) {
|
|
886
|
+
return ValueOrErrors.Default.throwOne(
|
|
887
|
+
`Error: expected cases, got ${JSON.stringify(cases)}`,
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
return Expr.Operations.MatchCase(vars)(
|
|
891
|
+
unionCase,
|
|
892
|
+
cases,
|
|
893
|
+
);
|
|
894
|
+
}),
|
|
800
895
|
)
|
|
801
|
-
: Expr.Operations.
|
|
802
|
-
? Expr.Operations.Evaluate(vars)(e.
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
896
|
+
: Expr.Operations.IsLambda(e)
|
|
897
|
+
? Expr.Operations.Evaluate(vars)(e.body)
|
|
898
|
+
: Expr.Operations.IsBinaryOperator(e) && e.kind == "equals"
|
|
899
|
+
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then(
|
|
900
|
+
(v1) =>
|
|
901
|
+
Expr.Operations.Evaluate(vars)(e.operands[1]).Then(
|
|
902
|
+
(v2) =>
|
|
903
|
+
PredicateValue.Operations.Equals(vars)(
|
|
904
|
+
v1,
|
|
808
905
|
v2,
|
|
809
|
-
).Then((
|
|
810
|
-
ValueOrErrors.Default.return(
|
|
906
|
+
).Then((eq) =>
|
|
907
|
+
ValueOrErrors.Default.return(eq),
|
|
811
908
|
),
|
|
812
909
|
),
|
|
813
|
-
)
|
|
814
|
-
)
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
910
|
+
)
|
|
911
|
+
: Expr.Operations.IsBinaryOperator(e) && e.kind == "or"
|
|
912
|
+
? Expr.Operations.Evaluate(vars)(e.operands[0]).Then(
|
|
913
|
+
(v1) =>
|
|
914
|
+
Expr.Operations.Evaluate(vars)(
|
|
915
|
+
e.operands[1],
|
|
916
|
+
).Then((v2) =>
|
|
917
|
+
Expr.Operations.EvaluateAsBoolean(vars)(
|
|
918
|
+
v1,
|
|
919
|
+
).Then((v1) =>
|
|
920
|
+
Expr.Operations.EvaluateAsBoolean(vars)(
|
|
921
|
+
v2,
|
|
922
|
+
).Then((v2) =>
|
|
923
|
+
ValueOrErrors.Default.return(v1 || v2),
|
|
924
|
+
),
|
|
925
|
+
),
|
|
926
|
+
),
|
|
927
|
+
)
|
|
928
|
+
: ValueOrErrors.Default.throwOne(
|
|
929
|
+
`Error: unsupported expression ${JSON.stringify(e)}`,
|
|
930
|
+
);
|
|
818
931
|
},
|
|
819
932
|
},
|
|
820
933
|
};
|
|
@@ -960,7 +1073,9 @@ export const evaluatePredicates = <T>(
|
|
|
960
1073
|
const valueLocal = kv.values.get(1)!;
|
|
961
1074
|
if (keyLocal == undefined || valueLocal == undefined) {
|
|
962
1075
|
return ValueOrErrors.Default.throwOne(
|
|
963
|
-
`Error: cannot find key or value of ${JSON.stringify(
|
|
1076
|
+
`Error: cannot find key or value of ${JSON.stringify(
|
|
1077
|
+
kv,
|
|
1078
|
+
)} in local ${JSON.stringify(raw)}`,
|
|
964
1079
|
);
|
|
965
1080
|
}
|
|
966
1081
|
const keyBindings = bindings.set("local", keyLocal);
|
|
@@ -998,7 +1113,9 @@ export const evaluatePredicates = <T>(
|
|
|
998
1113
|
});
|
|
999
1114
|
}
|
|
1000
1115
|
return ValueOrErrors.Default.throwOne(
|
|
1001
|
-
`Error: parsing expected tuple of key value pairs, got ${JSON.stringify(
|
|
1116
|
+
`Error: parsing expected tuple of key value pairs, got ${JSON.stringify(
|
|
1117
|
+
raw,
|
|
1118
|
+
)}`,
|
|
1002
1119
|
);
|
|
1003
1120
|
});
|
|
1004
1121
|
}
|
|
@@ -348,41 +348,41 @@ export const ParsedRenderer = {
|
|
|
348
348
|
case "enum":
|
|
349
349
|
case "stream":
|
|
350
350
|
return Expr.Operations.parse(parsedRenderer.visible ?? true).Then(
|
|
351
|
-
(visibilityExpr) =>
|
|
352
|
-
Expr.Operations.parse(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
351
|
+
(visibilityExpr) => {
|
|
352
|
+
return Expr.Operations.parse(
|
|
353
|
+
parsedRenderer.disabled ?? false,
|
|
354
|
+
).Then((disabledExpr) =>
|
|
355
|
+
ValueOrErrors.Default.return({
|
|
356
|
+
form: {
|
|
357
|
+
renderer: ParsedRenderer.Operations.FormRenderers(
|
|
358
|
+
parsedRenderer,
|
|
359
|
+
parsingContext.formViews,
|
|
360
|
+
viewKind,
|
|
361
|
+
parsedRenderer.renderer,
|
|
362
|
+
parsedRenderer.label,
|
|
363
|
+
parsedRenderer.tooltip,
|
|
364
|
+
parsedRenderer.details,
|
|
365
|
+
parsingContext.enumOptionsSources,
|
|
366
|
+
parsingContext.injectedPrimitives,
|
|
367
|
+
),
|
|
368
|
+
initialValue: parsingContext.defaultValue(
|
|
369
|
+
parsedRenderer.type,
|
|
370
|
+
),
|
|
371
|
+
initialState: ParsedRenderer.Operations.FormStates(
|
|
372
|
+
parsedRenderer,
|
|
373
|
+
viewKind,
|
|
374
|
+
parsedRenderer.renderer,
|
|
375
|
+
parsingContext.infiniteStreamSources,
|
|
376
|
+
parsingContext.injectedPrimitives,
|
|
377
|
+
),
|
|
378
|
+
},
|
|
379
|
+
visibilityPredicateExpression:
|
|
380
|
+
FieldPredicateExpression.Default.primitive(visibilityExpr),
|
|
381
|
+
disabledPredicatedExpression:
|
|
382
|
+
FieldPredicateExpression.Default.primitive(disabledExpr),
|
|
383
|
+
}),
|
|
384
|
+
);
|
|
385
|
+
},
|
|
386
386
|
);
|
|
387
387
|
case "form":
|
|
388
388
|
return Expr.Operations.parse(parsedRenderer.visible ?? true).Then(
|
|
@@ -41,7 +41,7 @@ export const RawType = {
|
|
|
41
41
|
_.fun == "Union" &&
|
|
42
42
|
Array.isArray(_["args"]) &&
|
|
43
43
|
_["args"].every(
|
|
44
|
-
(__) => typeof __ == "object" && "
|
|
44
|
+
(__) => typeof __ == "object" && "caseName"ame" in __ && "fields" in __,
|
|
45
45
|
),
|
|
46
46
|
};
|
|
47
47
|
export type RawApplicationType<T> = {
|
|
@@ -114,7 +114,7 @@ export const RawFieldType = {
|
|
|
114
114
|
_.fun == "MultiSelection" &&
|
|
115
115
|
_.args.length == 1,
|
|
116
116
|
isUnionCase: <T>(_: RawFieldType<T>): _ is { case: string; fields: object } =>
|
|
117
|
-
typeof _ == "object" && "
|
|
117
|
+
typeof _ == "object" && "caseName"ame" in _ && "fields" in _,
|
|
118
118
|
isUnion: <T>(
|
|
119
119
|
_: RawFieldType<T>,
|
|
120
120
|
): _ is { fun: "Union"; args: Array<{ case: string; fields: object }> } =>
|
|
@@ -124,7 +124,7 @@ export const RawFieldType = {
|
|
|
124
124
|
_.fun == "Union" &&
|
|
125
125
|
_.args.length > 0 &&
|
|
126
126
|
_.args.every(
|
|
127
|
-
(__) => typeof __ == "object" && "
|
|
127
|
+
(__) => typeof __ == "object" && "caseName"ame" in __ && "fields" in __,
|
|
128
128
|
),
|
|
129
129
|
isForm: <T>(_: RawFieldType<T>): _ is { fields: Object } =>
|
|
130
130
|
typeof _ == "object" && "fields" in _ && isObject(_.fields),
|
|
@@ -153,7 +153,7 @@ export type FormFields<T> = Map<FieldName, ParsedType<T>>;
|
|
|
153
153
|
export type ParsedUnionCase<T> = {
|
|
154
154
|
kind: "unionCase";
|
|
155
155
|
name: CaseName;
|
|
156
|
-
fields: ParsedType<T
|
|
156
|
+
fields: ParsedType<T>;
|
|
157
157
|
};
|
|
158
158
|
export type ParsedType<T> =
|
|
159
159
|
| ParsedUnionCase<T>
|
|
@@ -168,7 +168,7 @@ export const ParsedType = {
|
|
|
168
168
|
Default: {
|
|
169
169
|
unionCase: <T>(
|
|
170
170
|
name: CaseName,
|
|
171
|
-
fields: ParsedType<T
|
|
171
|
+
fields: ParsedType<T>,
|
|
172
172
|
): ParsedUnionCase<T> => ({ kind: "unionCase", name, fields }),
|
|
173
173
|
option: <T>(value: ParsedType<T>): ParsedType<T> => ({
|
|
174
174
|
kind: "option",
|
|
@@ -329,7 +329,7 @@ export const ParsedType = {
|
|
|
329
329
|
injectedPrimitives,
|
|
330
330
|
).Then((parsedFields) =>
|
|
331
331
|
ValueOrErrors.Default.return(
|
|
332
|
-
ParsedType.Default.unionCase(rawFieldType.case,
|
|
332
|
+
ParsedType.Default.unionCase(rawFieldType.case, parsedFields),
|
|
333
333
|
),
|
|
334
334
|
);
|
|
335
335
|
}
|
|
@@ -344,8 +344,15 @@ export const ParsedType = {
|
|
|
344
344
|
)} is not a valid union case`,
|
|
345
345
|
);
|
|
346
346
|
}
|
|
347
|
-
return
|
|
348
|
-
|
|
347
|
+
return ParsedType.Operations.ParseRawFieldType(
|
|
348
|
+
unionCase.case,
|
|
349
|
+
unionCase,
|
|
350
|
+
types,
|
|
351
|
+
injectedPrimitives,
|
|
352
|
+
).Then((parsedFields) =>
|
|
353
|
+
ValueOrErrors.Default.return(
|
|
354
|
+
ParsedType.Default.unionCase(unionCase.case, parsedFields),
|
|
355
|
+
),
|
|
349
356
|
);
|
|
350
357
|
}),
|
|
351
358
|
),
|
|
@@ -432,11 +432,13 @@ export const parseFormsToLaunchers =
|
|
|
432
432
|
formType: formType,
|
|
433
433
|
api: api,
|
|
434
434
|
parseGlobalConfiguration: (raw: any) =>
|
|
435
|
-
|
|
436
|
-
raw,
|
|
435
|
+
fromAPIRawValue(
|
|
437
436
|
globalConfigurationType,
|
|
438
437
|
formsConfig.types,
|
|
439
|
-
|
|
438
|
+
builtIns,
|
|
439
|
+
apiConverters,
|
|
440
|
+
injectedPrimitives,
|
|
441
|
+
)(raw),
|
|
440
442
|
fromApiParser: (value: any) =>
|
|
441
443
|
fromAPIRawValue(
|
|
442
444
|
formType,
|
|
@@ -546,11 +548,13 @@ export const parseFormsToLaunchers =
|
|
|
546
548
|
formType: formType,
|
|
547
549
|
api: api,
|
|
548
550
|
parseGlobalConfiguration: (raw: any) =>
|
|
549
|
-
|
|
550
|
-
raw,
|
|
551
|
+
fromAPIRawValue(
|
|
551
552
|
globalConfigurationType,
|
|
552
553
|
formsConfig.types,
|
|
553
|
-
|
|
554
|
+
builtIns,
|
|
555
|
+
apiConverters,
|
|
556
|
+
injectedPrimitives,
|
|
557
|
+
)(raw),
|
|
554
558
|
fromApiParser: (value: any) =>
|
|
555
559
|
fromAPIRawValue(
|
|
556
560
|
formType,
|
|
@@ -653,11 +657,13 @@ export const parseFormsToLaunchers =
|
|
|
653
657
|
formType: formType,
|
|
654
658
|
onEntityChange: parentContext.onEntityChange,
|
|
655
659
|
parseGlobalConfiguration: (raw: any) =>
|
|
656
|
-
|
|
657
|
-
raw,
|
|
660
|
+
fromAPIRawValue(
|
|
658
661
|
globalConfigurationType,
|
|
659
662
|
formsConfig.types,
|
|
660
|
-
|
|
663
|
+
builtIns,
|
|
664
|
+
apiConverters,
|
|
665
|
+
injectedPrimitives,
|
|
666
|
+
)(raw),
|
|
661
667
|
fromApiParser: (value: any) =>
|
|
662
668
|
fromAPIRawValue(
|
|
663
669
|
formType,
|