ballerina-core 1.0.72 → 1.0.77

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.
Files changed (34) hide show
  1. package/main.ts +6 -0
  2. package/package.json +1 -1
  3. package/src/collections/domains/immutable/domains/list/state.ts +17 -0
  4. package/src/collections/domains/valueOrErrors/state.ts +13 -15
  5. package/src/forms/domains/integrated-forms/domains/launcher/coroutines/runner.ts +61 -0
  6. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/coroutines/runner.ts +80 -0
  7. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/state.ts +98 -0
  8. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/template.tsx +74 -0
  9. package/src/forms/domains/integrated-forms/domains/launcher/state.ts +38 -0
  10. package/src/forms/domains/integrated-forms/domains/launcher/template.tsx +53 -0
  11. package/src/forms/domains/integrated-forms/domains/parser/coroutines/runner.ts +38 -0
  12. package/src/forms/domains/integrated-forms/domains/parser/state.ts +138 -0
  13. package/src/forms/domains/integrated-forms/domains/validator/state.ts +191 -0
  14. package/src/forms/domains/launcher/coroutines/runner.ts +7 -1
  15. package/src/forms/domains/launcher/domains/create/coroutines/runner.ts +139 -15
  16. package/src/forms/domains/launcher/domains/create/state.ts +44 -9
  17. package/src/forms/domains/launcher/domains/create/template.tsx +10 -1
  18. package/src/forms/domains/launcher/domains/edit/coroutines/runner.ts +165 -35
  19. package/src/forms/domains/launcher/domains/edit/state.ts +45 -9
  20. package/src/forms/domains/launcher/domains/edit/template.tsx +15 -4
  21. package/src/forms/domains/launcher/state.ts +1 -6
  22. package/src/forms/domains/launcher/template.tsx +6 -1
  23. package/src/forms/domains/parser/coroutines/runner.ts +4 -3
  24. package/src/forms/domains/parser/domains/built-ins/state.ts +18 -14
  25. package/src/forms/domains/parser/domains/predicates/state.ts +434 -0
  26. package/src/forms/domains/parser/domains/renderer/state.ts +87 -63
  27. package/src/forms/domains/parser/domains/types/state.ts +31 -16
  28. package/src/forms/domains/parser/domains/validator/state.ts +32 -10
  29. package/src/forms/domains/parser/state.tsx +201 -147
  30. package/src/forms/domains/primitives/domains/list/state.ts +6 -0
  31. package/src/forms/domains/primitives/domains/list/template.tsx +39 -14
  32. package/src/forms/domains/primitives/domains/map/template.tsx +12 -8
  33. package/src/forms/domains/singleton/state.ts +6 -5
  34. package/src/forms/domains/singleton/template.tsx +42 -25
package/main.ts CHANGED
@@ -117,6 +117,12 @@ export * from "./src/forms/domains/launcher/state"
117
117
  export * from "./src/forms/domains/launcher/template"
118
118
  export * from "./src/forms/domains/parser/domains/injectables/state"
119
119
  export * from "./src/forms/domains/collection/domains/unionCase/state"
120
+ export * from "./src/forms/domains/parser/domains/predicates/state"
121
+ export * from "./src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/state"
122
+ export * from "./src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/template"
123
+ export * from "./src/forms/domains/integrated-forms/domains/parser/state"
124
+ export * from "./src/forms/domains/integrated-forms/domains/launcher/state"
125
+ export * from "./src/forms/domains/integrated-forms/domains/launcher/template"
120
126
 
121
127
  // import { simpleUpdater, simpleUpdaterWithChildren } from "./src/fun/domains/updater/domains/simpleUpdater/state"
122
128
  // import { Updater } from "./src/fun/domains/updater/state"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ballerina-core",
3
3
  "author": "Dr. Giuseppe Maggiore",
4
4
  "private": false,
5
- "version": "1.0.72",
5
+ "version": "1.0.77",
6
6
  "main": "main.ts",
7
7
  "dependencies": {
8
8
  "immutable": "^5.0.0-beta.5",
@@ -13,9 +13,26 @@ export const ListRepo = {
13
13
  push<V>(v:V): Updater<List<V>> {
14
14
  return Updater((_) => _.push(v));
15
15
  },
16
+ insert<V>(elementIndex:number, v:V): Updater<List<V>> {
17
+ return Updater((_) => _.insert(elementIndex, v));
18
+ },
16
19
  filter<V>(predicate: BasicFun<V, boolean>): Updater<List<V>> {
17
20
  return Updater((_) => _.filter(predicate));
18
21
  },
22
+ move<V>(elementIndex:number, to:number): Updater<List<V>> {
23
+ return Updater((_) => {
24
+ const element = _.get(elementIndex)
25
+ if(element == undefined) return _
26
+ return _.remove(elementIndex).insert(to, element)
27
+ });
28
+ },
29
+ duplicate<V>(elementIndex:number): Updater<List<V>> {
30
+ return Updater((_) => {
31
+ const element = _.get(elementIndex)
32
+ if(element == undefined) return _
33
+ return _.insert(elementIndex + 1, element)
34
+ });
35
+ },
19
36
  },
20
37
  Operations: {
21
38
  },
@@ -2,7 +2,7 @@ import { List } from "immutable";
2
2
  import { BasicFun, BasicFun2, Fun } from "../../../fun/state";
3
3
  import { Value } from "../../../value/state";
4
4
  import { Errors } from "../errors/state"
5
- import { unit, Unit, Updater, Option } from "../../../../main";
5
+ import { unit, Unit, Updater, Option, Sum } from "../../../../main";
6
6
 
7
7
  export type ValueOrErrors<v, e> = (
8
8
  | (Value<v> & { kind: "value" })
@@ -122,25 +122,23 @@ export const ValueOrErrors = {
122
122
  ValueOrErrors.Operations.Map<a, ValueOrErrors<b, e>, e>(k)(_)
123
123
  )
124
124
  ),
125
+ Catch: <v, e>(_: ValueOrErrors<v, e>): ValueOrErrors<Sum<v, List<e>>, e> =>
126
+ _.kind == "errors" ?
127
+ ValueOrErrors.Default.return(Sum.Default.right(_.errors)) : ValueOrErrors.Default.return(Sum.Default.left(_.value)),
125
128
  Fold: <v, e, c>(
126
129
  l: BasicFun<v, c>,
127
130
  r: BasicFun<List<e>, c>
128
131
  ): Fun<ValueOrErrors<v, e>, c> =>
129
132
  Fun((_) => (_.kind == "value" ? l(_.value) : r(_.errors))),
130
133
  All: <v, e>(_: List<ValueOrErrors<v, e>>): ValueOrErrors<List<v>, e> =>
131
- _.reduce(
132
- (reduction, value) =>
133
- ValueOrErrors.Operations.Fold<v, e, ValueOrErrors<List<v>, e>>(
134
- (v: v) =>
135
- reduction.kind == "errors"
136
- ? reduction
137
- : reduction.Map((_) => _.concat(v)),
138
- (es: List<e>) =>
139
- reduction.kind == "errors"
140
- ? reduction.MapErrors((_) => _.concat(es))
141
- : ValueOrErrors.Default.throw(es)
142
- )(value),
143
- ValueOrErrors.Default.return(List<v>())
144
- ),
134
+ _.size == 0 ?
135
+ ValueOrErrors.Default.return(List())
136
+ : ValueOrErrors.Operations.Catch(_.first()!).Then(res_p =>
137
+ res_p.kind == "l" ?
138
+ ValueOrErrors.Operations.All(_.slice(1).toList()).Then(values =>
139
+ ValueOrErrors.Default.return(List<v>().push(res_p.value).concat(values))
140
+ )
141
+ : ValueOrErrors.Default.throw(res_p.value)
142
+ )
145
143
  },
146
144
  };
@@ -0,0 +1,61 @@
1
+ import { List } from "immutable"
2
+ import { id, replaceWith, Sum, ValueOrErrors } from "../../../../../../../main"
3
+ import { AsyncState } from "../../../../../../async/state"
4
+ import { CoTypedFactory } from "../../../../../../coroutines/builder"
5
+ import { IntegratedFormRunnerForeignMutationsExpected, IntegratedFormRunnerState, IntegratedFormRunnerContext, IntegratedForm } from "../state"
6
+ import { IntegratedFormRunnerErrorsTemplate } from "../template"
7
+
8
+ export const IntegratedFormRunnerLoader = <E,>() => {
9
+ const Co = CoTypedFactory<IntegratedFormRunnerContext<E>, IntegratedFormRunnerState<E>>()
10
+
11
+ return Co.Template<IntegratedFormRunnerForeignMutationsExpected>(
12
+ Co.GetState().then(current =>
13
+ !AsyncState.Operations.hasValue(current.formsConfig.sync) ?
14
+ Co.Wait(0)
15
+ : Co.UpdateState(_ => {
16
+ if (!AsyncState.Operations.hasValue(current.formsConfig.sync)) return id
17
+ if (current.formsConfig.sync.value.kind == "errors")
18
+ return IntegratedFormRunnerState<E>().Updaters.form(
19
+ replaceWith(
20
+ Sum.Default.left(
21
+ IntegratedFormRunnerErrorsTemplate(current.formsConfig.sync.value)
22
+ )
23
+ )
24
+ )
25
+
26
+ const formRef = current.formRef
27
+
28
+ const form = current.formsConfig.sync.value.value.get(formRef.formName)
29
+ if (form == undefined)
30
+ return IntegratedFormRunnerState<E>().Updaters.form(
31
+ replaceWith(
32
+ Sum.Default.left(
33
+ IntegratedFormRunnerErrorsTemplate(ValueOrErrors.Default.throw(List([`Cannot find form '${formRef.formName}'`])))
34
+ )
35
+ )
36
+ )
37
+ const instantiatedForm = form()
38
+ return IntegratedFormRunnerState<E>().Updaters.form(
39
+ replaceWith<Sum<IntegratedForm<E>, "not initialized">>(
40
+ Sum.Default.left<IntegratedForm<E>, "not initialized">({
41
+ form: instantiatedForm.form,
42
+ formFieldStates: instantiatedForm.initialState.formFieldStates,
43
+ commonFormState: instantiatedForm.initialState.commonFormState,
44
+ customFormState: instantiatedForm.initialState.customFormState,
45
+ fromApiParser: instantiatedForm.fromApiParser as (value: any) => E,
46
+ toApiParser: instantiatedForm.toApiParser,
47
+ parseGlobalConfiguration: instantiatedForm.parseGlobalConfiguration
48
+ })
49
+ )
50
+ )
51
+ })
52
+ ),
53
+ {
54
+ interval: 15,
55
+ runFilter: props =>
56
+ AsyncState.Operations.hasValue(props.context.formsConfig.sync) &&
57
+ props.context.form.kind == "r"
58
+ }
59
+ )
60
+ }
61
+
@@ -0,0 +1,80 @@
1
+ import { List } from "immutable";
2
+ import { Synchronize, Unit, replaceWith, Sum, ValueOrErrors, Debounce, id } from "../../../../../../../../../main";
3
+ import { ApiResultStatus } from "../../../../../../../../apiResultStatus/state";
4
+ import { AsyncState } from "../../../../../../../../async/state";
5
+ import { CoTypedFactory } from "../../../../../../../../coroutines/builder";
6
+ import { Debounced } from "../../../../../../../../debounced/state";
7
+ import { PredicateValue, evaluatePredicates, FormFieldPredicateEvaluation } from "../../../../../../parser/domains/predicates/state";
8
+ import { IntegratedFormContext, IntegratedFormForeignMutationsExpected, IntegratedFormWritableState, IntegratedFormState } from "../state";
9
+
10
+
11
+ export const integratedFormRunner = <E, FS>() => {
12
+ const Co = CoTypedFactory<
13
+ IntegratedFormContext<E, FS> & IntegratedFormForeignMutationsExpected<E, FS> & { onRawEntityChange: (updatedRawEntity: any, path: List<string>) => void },
14
+ IntegratedFormWritableState<E, FS>
15
+ >();
16
+
17
+ const calculateInitialVisibilities = Co.GetState().then((current) => {
18
+ const parsedRootPredicate = PredicateValue.Operations.parse(current.initialRawEntity.value, current.formType, current.types)
19
+
20
+ if(parsedRootPredicate.kind == "errors") {
21
+ console.error('error parsing bindings', parsedRootPredicate)
22
+ return Co.Do(() => {})
23
+ }
24
+ if(typeof parsedRootPredicate.value != "object" || !("kind" in parsedRootPredicate.value) || parsedRootPredicate.value.kind != "record") {
25
+ return Co.Do(() => {})
26
+ }
27
+ return Co.SetState(IntegratedFormState<E, FS>().Updaters.Core.customFormState.children.predicateEvaluations(
28
+ replaceWith(Debounced.Default(evaluatePredicates({
29
+ global: current.globalConfiguration.value,
30
+ types: current.types,
31
+ visibilityPredicateExpressions: current.visibilityPredicateExpressions,
32
+ disabledPredicatedExpressions: current.disabledPredicatedExpressions
33
+ }, parsedRootPredicate.value)))).then(IntegratedFormState<E, FS>().Updaters.Core.customFormState.children.isInitialized(replaceWith(true)))
34
+ )
35
+ })
36
+
37
+ const PredicatesCo = CoTypedFactory<IntegratedFormWritableState<E, FS> & IntegratedFormContext<E, FS>, ValueOrErrors<{
38
+ visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
39
+ disabledPredicateEvaluations: FormFieldPredicateEvaluation;
40
+ }, string>>();
41
+
42
+ const calculateVisibilities = Co.Repeat(
43
+ Debounce<ValueOrErrors<{visiblityPredicateEvaluations: FormFieldPredicateEvaluation; disabledPredicateEvaluations: FormFieldPredicateEvaluation;}, string>, IntegratedFormContext<E, FS> & IntegratedFormWritableState<E, FS>>(
44
+ PredicatesCo.GetState().then((current) => {
45
+ if(current.entity.kind == "r" || current.globalConfiguration.kind == "r") {
46
+ return PredicatesCo.Return<ApiResultStatus>("permanent failure")
47
+ }
48
+ const parsedEntity = current.toApiParser(current.entity.value, current, false)
49
+ if(parsedEntity.kind == "errors") {
50
+ console.error('error parsing entity', parsedEntity)
51
+ return PredicatesCo.Return<ApiResultStatus>("permanent failure")
52
+ }
53
+ const parseRootPredicate = PredicateValue.Operations.parse(parsedEntity.value, current.formType, current.types)
54
+ if(parseRootPredicate.kind == "errors") {
55
+ console.error('error parsing', parseRootPredicate)
56
+ return PredicatesCo.Return<ApiResultStatus>("permanent failure")
57
+ }
58
+ return PredicatesCo.SetState(replaceWith(evaluatePredicates({
59
+ global: current.globalConfiguration.value,
60
+ types: current.types,
61
+ visibilityPredicateExpressions: current.visibilityPredicateExpressions,
62
+ disabledPredicatedExpressions: current.disabledPredicatedExpressions
63
+ }, parseRootPredicate.value))).then(() => PredicatesCo.Return<ApiResultStatus>("success"))})
64
+ , 50)
65
+ .embed(
66
+ (_) => ({ ..._, ..._.customFormState.predicateEvaluations }),
67
+ IntegratedFormState<E, FS>().Updaters.Core.customFormState.children.predicateEvaluations)
68
+ )
69
+
70
+ return Co.Template<IntegratedFormForeignMutationsExpected<E, FS>>(calculateInitialVisibilities, {
71
+ interval: 15,
72
+ runFilter: (props) => !props.context.customFormState.isInitialized && props.context.globalConfiguration.kind != "r" && props.context.initialRawEntity.kind != "r"
73
+ }).any([
74
+ Co.Template<IntegratedFormForeignMutationsExpected<E, FS>>(calculateVisibilities, {
75
+ interval: 15,
76
+ runFilter: (props) =>
77
+ Debounced.Operations.shouldCoroutineRun(props.context.customFormState.predicateEvaluations)
78
+ }),
79
+ ]);
80
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ ParsedType,
3
+ Template,
4
+ Value,
5
+ ValueOrErrors,
6
+ PredicateValue,
7
+ FieldPredicateExpressions,
8
+ CommonFormState,
9
+ FormFieldPredicateEvaluation,
10
+ simpleUpdater,
11
+ Debounced,
12
+ simpleUpdaterWithChildren,
13
+ Updater,
14
+ id,
15
+ ForeignMutationsInput,
16
+ Sum
17
+ } from "../../../../../../../../main";
18
+ import { List, Map } from "immutable";
19
+
20
+ export type IntegratedFormContext<E, FS> = {
21
+ formType: ParsedType<E>;
22
+ types: Map<string, ParsedType<E>>;
23
+ globalConfiguration: Sum<PredicateValue, "not initialized">;
24
+ initialRawEntity: Sum<any, "not initialized">;
25
+ entity: Sum<E, "not initialized">;
26
+ onRawEntityChange: (updater: Updater<E>, path: List<string>) => void;
27
+ toApiParser: (
28
+ entity: E,
29
+ formstate: IntegratedFormState<E,FS>,
30
+ checkKeys: boolean
31
+ ) => ValueOrErrors<E, string>;
32
+ fromApiParser: (raw: any) => any;
33
+ parseGlobalConfiguration: (raw: any) => ValueOrErrors<PredicateValue, string>;
34
+ visibilityPredicateExpressions: FieldPredicateExpressions;
35
+ disabledPredicatedExpressions: FieldPredicateExpressions;
36
+ actualForm: Template<
37
+ Value<E> & { formFieldStates: FS } & {
38
+ commonFormState: CommonFormState;
39
+ } & { visibilities: FormFieldPredicateEvaluation | undefined } & {
40
+ disabledFields: FormFieldPredicateEvaluation | undefined;
41
+ },
42
+ { formFieldStates: FS } & { commonFormState: CommonFormState },
43
+ { onChange: (e: Updater<E>, path: List<string>) => void }
44
+ >;
45
+ };
46
+
47
+ export type IntegratedFormState<E,FS> = {
48
+ formFieldStates: FS,
49
+ commonFormState: CommonFormState,
50
+ customFormState: {
51
+ isInitialized: boolean,
52
+ predicateEvaluations: Debounced<ValueOrErrors<{
53
+ visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
54
+ disabledPredicateEvaluations: FormFieldPredicateEvaluation;
55
+ }, string>>,
56
+ }
57
+ }
58
+
59
+ export const IntegratedFormState = <E,FS>() => ({
60
+ Default:(formFieldStates:FS, commonFormState: CommonFormState) : IntegratedFormState<E,FS> => ({
61
+ formFieldStates,
62
+ commonFormState,
63
+ customFormState: {
64
+ isInitialized: false,
65
+ predicateEvaluations: Debounced.Default(ValueOrErrors.Default.return({
66
+ visiblityPredicateEvaluations: FormFieldPredicateEvaluation.Default.form(false, Map()),
67
+ disabledPredicateEvaluations: FormFieldPredicateEvaluation.Default.form(false, Map())
68
+ }))
69
+ }
70
+ }),
71
+ Updaters:{
72
+ Core:{
73
+ ...simpleUpdater<IntegratedFormState<E,FS>>()("formFieldStates"),
74
+ ...simpleUpdaterWithChildren<IntegratedFormState<E,FS>>()({
75
+ ...simpleUpdater<IntegratedFormState<E,FS>["customFormState"]>()("predicateEvaluations"),
76
+ ...simpleUpdater<IntegratedFormState<E,FS>["customFormState"]>()("isInitialized"),
77
+ })("customFormState"),
78
+ ...simpleUpdater<IntegratedFormState<E,FS>>()("commonFormState"),
79
+ },
80
+ Template:{
81
+ recalculatePredicates: () : Updater<IntegratedFormState<E,FS>> =>
82
+ IntegratedFormState<E,FS>().Updaters.Core.customFormState.children.predicateEvaluations(
83
+ Debounced.Updaters.Template.value(
84
+ id
85
+ )
86
+ )
87
+ }
88
+ },
89
+ ForeignMutations: (_: ForeignMutationsInput<IntegratedFormContext<E,FS>, IntegratedFormWritableState<E,FS>>) => ({
90
+
91
+ })
92
+ })
93
+
94
+ export type IntegratedFormWritableState<E, FS> = IntegratedFormState<E,FS>
95
+ export type IntegratedFormForeignMutationsExposed<E,FS> = ReturnType<ReturnType<typeof IntegratedFormState<E,FS>>["ForeignMutations"]>
96
+ export type IntegratedFormForeignMutationsExpected<E, FS> = {
97
+
98
+ }
@@ -0,0 +1,74 @@
1
+ import { unit } from "../../../../../../../../main";
2
+ import { Template } from "../../../../../../../template/state";
3
+ import { IntegratedFormContext, IntegratedFormForeignMutationsExpected, IntegratedFormState, IntegratedFormWritableState } from "./state";
4
+ import { integratedFormRunner } from "./coroutines/runner";
5
+ export type IntegratedFormView<E, FS> =
6
+ Template<
7
+ IntegratedFormContext<E, FS> & IntegratedFormWritableState<E, FS>,
8
+ IntegratedFormWritableState<E, FS>,
9
+ IntegratedFormForeignMutationsExpected<E, FS>,
10
+ {
11
+ actualForm: JSX.Element | undefined
12
+ }>
13
+ export type IntegratedFormTemplate<E, FS> =
14
+ Template<
15
+ IntegratedFormContext<E, FS> & IntegratedFormWritableState<E, FS>,
16
+ IntegratedFormWritableState<E, FS>,
17
+ IntegratedFormForeignMutationsExpected<E, FS>,
18
+ IntegratedFormView<E, FS>>
19
+ export const IntegratedFormTemplate = <E, FS>(): IntegratedFormTemplate<E, FS> =>
20
+ Template.Default<
21
+ IntegratedFormContext<E, FS> & IntegratedFormWritableState<E, FS>,
22
+ IntegratedFormWritableState<E, FS>,
23
+ IntegratedFormForeignMutationsExpected<E, FS>,
24
+ IntegratedFormView<E, FS>>(props => {
25
+ if(props.context.entity.kind == "r" || props.context.globalConfiguration.kind == "r") {
26
+ return <>
27
+ </>
28
+ }
29
+ const visibilities = props.context.customFormState.predicateEvaluations.kind == "value" &&
30
+ props.context.customFormState.predicateEvaluations.value.visiblityPredicateEvaluations.kind == "form" ?
31
+ props.context.customFormState.predicateEvaluations.value.visiblityPredicateEvaluations : undefined;
32
+ const disabledFields = props.context.customFormState.predicateEvaluations.kind == "value"
33
+ && props.context.customFormState.predicateEvaluations.value.disabledPredicateEvaluations.kind == "form" ?
34
+ props.context.customFormState.predicateEvaluations.value.disabledPredicateEvaluations : undefined;
35
+ return <>
36
+ {
37
+ props.view({
38
+ ...props,
39
+ ...props.foreignMutations,
40
+ view: {
41
+ ...props.view,
42
+ actualForm:
43
+ props.context.actualForm({
44
+ context: {
45
+ value: props.context.entity.value,
46
+ formFieldStates: props.context.formFieldStates,
47
+ commonFormState: props.context.commonFormState,
48
+ visibilities,
49
+ disabledFields
50
+ },
51
+ setState: _ => {
52
+ props.setState(__ => ({
53
+ ...__,
54
+ formFieldStates: _(__).formFieldStates,
55
+ commonFormState: _(__).commonFormState
56
+ }))
57
+ },
58
+ foreignMutations: {
59
+ onChange: (updater, path) => {
60
+ if(props.context.entity.kind == "r")
61
+ return
62
+ props.context.onRawEntityChange(updater, path)
63
+ props.setState(IntegratedFormState<E, FS>().Updaters.Template.recalculatePredicates())
64
+ }
65
+ },
66
+ view: unit
67
+ })
68
+ }
69
+ })
70
+ }
71
+ </>
72
+ }).any([
73
+ integratedFormRunner<E, FS>()
74
+ ])
@@ -0,0 +1,38 @@
1
+ import { List } from "immutable"
2
+ import { PredicateValue, Sum, Unit, ValueOrErrors, simpleUpdater } from "../../../../../../main"
3
+ import { BasicFun } from "../../../../../fun/state"
4
+ import { IntegratedFormParsingResult, IntegratedFormsParserState } from "../parser/state"
5
+
6
+ export type IntegratedFormRef = {
7
+ formName:string
8
+ }
9
+
10
+ export type IntegratedFormRunnerContext<E> = {
11
+ extraContext:any,
12
+ initialRawEntity: Sum<any, "not initialized">,
13
+ entity: Sum<E, "not initialized">,
14
+ globalConfiguration: Sum<PredicateValue, "not initialized">,
15
+ containerWrapper: any,
16
+ formRef:IntegratedFormRef,
17
+ showFormParsingErrors: BasicFun<IntegratedFormParsingResult, JSX.Element>
18
+ } & IntegratedFormsParserState
19
+
20
+ export type IntegratedForm<E> = { form:any, formFieldStates:any, commonFormState:any, customFormState:any, fromApiParser: (value: any) => E, toApiParser: (value: E, formState: any, checkKeys: boolean) => ValueOrErrors<any, string>, parseGlobalConfiguration: (raw: any) => ValueOrErrors<PredicateValue, string> }
21
+
22
+ export type IntegratedFormRunnerState<E> = {
23
+ form: Sum<IntegratedForm<E>, "not initialized">,
24
+ shouldUpdate: boolean
25
+ }
26
+ export type IntegratedFormRunnerForeignMutationsExpected = {
27
+ onRawEntityChange: (updatedRawEntity: any, path: List<string>) => void
28
+ }
29
+ export const IntegratedFormRunnerState = <E,>() => ({
30
+ Default:(): IntegratedFormRunnerState<E> => ({
31
+ form: Sum.Default.right("not initialized"),
32
+ shouldUpdate: false
33
+ }),
34
+ Updaters:{
35
+ ...simpleUpdater<IntegratedFormRunnerState<E>>()("form"),
36
+ ...simpleUpdater<IntegratedFormRunnerState<E>>()("shouldUpdate"),
37
+ }
38
+ })
@@ -0,0 +1,53 @@
1
+ import { BasicUpdater, Sum, unit } from "../../../../../../main"
2
+ import { Template } from "../../../../../template/state"
3
+
4
+ import { IntegratedFormRunnerContext, IntegratedFormRunnerForeignMutationsExpected, IntegratedFormRunnerState } from "./state"
5
+ import { IntegratedFormParsingResult } from "../parser/state"
6
+ import { IntegratedFormRunnerLoader } from "./coroutines/runner"
7
+
8
+ export const IntegratedFormRunnerErrorsTemplate = <E,>(parsedFormsConfig: IntegratedFormParsingResult) => ({
9
+ form: Template.Default<IntegratedFormRunnerContext<E> & IntegratedFormRunnerState<E>, IntegratedFormRunnerState<E>, IntegratedFormRunnerForeignMutationsExpected>(props =>
10
+ <>
11
+ {JSON.stringify(parsedFormsConfig)}
12
+ <br />
13
+ {JSON.stringify(props)}
14
+ </>),
15
+ formFieldStates: unit,
16
+ commonFormState: unit,
17
+ customFormState: unit,
18
+ fromApiParser: (value: any) => value,
19
+ toApiParser: (value: any, formState: any, checkKeys: boolean) => value,
20
+ parseGlobalConfiguration: (raw: any) => raw,
21
+ })
22
+
23
+ export const IntegratedFormRunnerTemplate = <E,>() => {
24
+ return Template.Default<IntegratedFormRunnerContext<E> & IntegratedFormRunnerState<E>, IntegratedFormRunnerState<E>, IntegratedFormRunnerForeignMutationsExpected>(props => {
25
+ if (props.context.form.kind == "r") return <></>
26
+ return <>
27
+ <props.context.form.value.form
28
+ context={{
29
+ initialRawEntity: props.context.initialRawEntity,
30
+ entity: props.context.entity,
31
+ globalConfiguration: props.context.globalConfiguration,
32
+ formFieldStates: props.context.form.value.formFieldStates,
33
+ commonFormState: props.context.form.value.commonFormState,
34
+ customFormState: props.context.form.value.customFormState,
35
+ containerWrapper: props.context.containerWrapper,
36
+ onRawEntityChange: props.foreignMutations.onRawEntityChange,
37
+ extraContext: {
38
+ ...props.context.extraContext,
39
+ },
40
+ }}
41
+ setState={(_: BasicUpdater<any>) => props.setState(
42
+ IntegratedFormRunnerState<E>().Updaters.form(Sum.Updaters.left(_))
43
+ )}
44
+ view={unit}
45
+ foreignMutations={{
46
+ }}
47
+ />
48
+
49
+ </>
50
+ }).any([
51
+ IntegratedFormRunnerLoader()
52
+ ])
53
+ }
@@ -0,0 +1,38 @@
1
+ import { AsyncState, builtInsFromFieldViews, injectablesFromFieldViews, Synchronize, Unit } from "../../../../../../../main"
2
+ import { CoTypedFactory } from "../../../../../../coroutines/builder"
3
+ import { IntegratedFormsConfig } from "../../validator/state"
4
+ import { IntegratedFormParsingResult, IntegratedFormsParserContext, IntegratedFormsParserState, parseIntegratedFormsToLaunchers } from "../state"
5
+ export const LoadValidateAndParseIntegratedFormsConfig = <T extends {[key in keyof T] : {type: any, state: any}}>() => {
6
+ const Co = CoTypedFactory<IntegratedFormsParserContext<T>, IntegratedFormsParserState>()
7
+
8
+ return Co.Template<Unit>(
9
+ Co.GetState().then(current =>
10
+ Synchronize<Unit, IntegratedFormParsingResult>(async() => {
11
+ const rawFormsConfig = await current.getFormsConfig();
12
+ const builtIns = builtInsFromFieldViews(current.fieldViews)
13
+ const injectedPrimitives = current.injectedPrimitives ? injectablesFromFieldViews(current.fieldViews, current.injectedPrimitives) : undefined
14
+ return IntegratedFormsConfig.Default.validateAndParseIntegratedFormConfig(builtIns, current.fieldTypeConverters, injectedPrimitives)(rawFormsConfig).Then(
15
+ validationResult =>
16
+ parseIntegratedFormsToLaunchers(
17
+ builtIns,
18
+ injectedPrimitives,
19
+ current.fieldTypeConverters,
20
+ current.containerFormView,
21
+ current.nestedContainerFormView,
22
+ current.fieldViews,
23
+ current.infiniteStreamSources,
24
+ current.enumOptionsSources,
25
+ )(validationResult)
26
+ )
27
+ }, _ => "transient failure", 5, 50)
28
+ .embed(
29
+ _ => _.formsConfig,
30
+ IntegratedFormsParserState.Updaters.formsConfig
31
+ )
32
+ ),
33
+ {
34
+ interval:15,
35
+ runFilter:props => !AsyncState.Operations.hasValue(props.context.formsConfig.sync)
36
+ }
37
+ )
38
+ }