ballerina-core 1.0.74 → 1.0.78

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 (23) hide show
  1. package/main.ts +5 -0
  2. package/package.json +1 -1
  3. package/src/collections/domains/immutable/domains/list/state.ts +17 -0
  4. package/src/forms/domains/integrated-forms/domains/launcher/coroutines/runner.ts +61 -0
  5. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/coroutines/runner.ts +80 -0
  6. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/state.ts +98 -0
  7. package/src/forms/domains/integrated-forms/domains/launcher/domains/integrated-form/template.tsx +74 -0
  8. package/src/forms/domains/integrated-forms/domains/launcher/state.ts +38 -0
  9. package/src/forms/domains/integrated-forms/domains/launcher/template.tsx +53 -0
  10. package/src/forms/domains/integrated-forms/domains/parser/coroutines/runner.ts +38 -0
  11. package/src/forms/domains/integrated-forms/domains/parser/state.ts +138 -0
  12. package/src/forms/domains/integrated-forms/domains/validator/state.ts +192 -0
  13. package/src/forms/domains/launcher/domains/create/state.ts +0 -1
  14. package/src/forms/domains/launcher/state.ts +0 -5
  15. package/src/forms/domains/launcher/template.tsx +0 -1
  16. package/src/forms/domains/parser/coroutines/runner.ts +3 -3
  17. package/src/forms/domains/parser/domains/renderer/state.ts +30 -29
  18. package/src/forms/domains/parser/state.tsx +114 -101
  19. package/src/forms/domains/primitives/domains/list/state.ts +6 -0
  20. package/src/forms/domains/primitives/domains/list/template.tsx +32 -10
  21. package/src/forms/domains/primitives/domains/map/template.tsx +4 -4
  22. package/src/forms/domains/singleton/state.ts +2 -1
  23. package/src/forms/domains/singleton/template.tsx +14 -12
package/main.ts CHANGED
@@ -118,6 +118,11 @@ 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
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"
121
126
 
122
127
  // import { simpleUpdater, simpleUpdaterWithChildren } from "./src/fun/domains/updater/domains/simpleUpdater/state"
123
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.74",
5
+ "version": "1.0.78",
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
  },
@@ -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
+ }
@@ -0,0 +1,138 @@
1
+ import { Map } from "immutable"
2
+
3
+ import { FormFieldPredicateEvaluation, simpleUpdater, unit, Unit, BasicFun, Synchronized, Template, Injectables, PredicateValue, fromAPIRawValue, toAPIRawValue, ValueOrErrors, Debounced } from "../../../../../../main"
4
+ import { EnumOptionsSources, InfiniteStreamSources, ParseForms } from "../../../parser/state"
5
+ import { BuiltIns } from "../../../../../../main";
6
+ import { ApiConverters, InjectedPrimitives } from "../../../../../../main";
7
+ import { ParsedIntegratedFormJSON } from "../validator/state";
8
+ import { IntegratedFormContext, IntegratedFormForeignMutationsExpected, IntegratedFormState } from "../launcher/domains/integrated-form/state";
9
+ import { IntegratedFormTemplate } from "../launcher/domains/integrated-form/template";
10
+ import { LoadValidateAndParseIntegratedFormsConfig } from "./coroutines/runner";
11
+
12
+ export const IntegratedFormsParserTemplate = <T extends {[key in keyof T] : {type: any, state: any}} = Unit>() => LoadValidateAndParseIntegratedFormsConfig<T>()
13
+
14
+ export type ParsedIntegratedLaunchers = Map<string, <Entity, FormState, ExtraContext>() =>
15
+ {
16
+ form:
17
+ Template<IntegratedLauncherContext<Entity, FormState, ExtraContext> & IntegratedFormState<Entity, FormState>,
18
+ IntegratedFormState<Entity, FormState>, IntegratedFormForeignMutationsExpected<Entity, FormState>>,
19
+ initialState: IntegratedFormState<Entity, FormState>,
20
+ fromApiParser: (value: any) => Entity,
21
+ toApiParser: (value: any, formState: any, checkKeys: boolean) => any,
22
+ parseGlobalConfiguration: (raw: any) => ValueOrErrors<PredicateValue, string>
23
+ }>
24
+
25
+ export type IntegratedLauncherContext<Entity, FormState, ExtraContext> =
26
+ Omit<
27
+ IntegratedFormContext<Entity, FormState> &
28
+ IntegratedFormState<Entity, FormState> & {
29
+ extraContext: ExtraContext,
30
+ containerFormView: any,
31
+ containerWrapper: any
32
+ }, "api" | "actualForm">
33
+
34
+ export type IntegratedFormParsingResult = ValueOrErrors<ParsedIntegratedLaunchers, string>
35
+
36
+ export const parseIntegratedFormsToLaunchers =
37
+ <T extends { [key in keyof T]: { type: any; state: any; }; },>(
38
+ builtIns: BuiltIns,
39
+ injectedPrimitives: InjectedPrimitives<T> | undefined,
40
+ apiConverters: ApiConverters<T>,
41
+ containerFormView: any,
42
+ nestedContainerFormView: any,
43
+ fieldViews: any,
44
+ infiniteStreamSources: InfiniteStreamSources,
45
+ enumOptionsSources: EnumOptionsSources,
46
+ ) =>
47
+ (formsConfig: ParsedIntegratedFormJSON<T>):
48
+ IntegratedFormParsingResult => {
49
+
50
+ return ParseForms(
51
+ builtIns,
52
+ injectedPrimitives,
53
+ nestedContainerFormView,
54
+ fieldViews,
55
+ infiniteStreamSources,
56
+ enumOptionsSources,
57
+ )(formsConfig).Then(parsedForms => {
58
+ let parsedLaunchers: ParsedIntegratedLaunchers = Map()
59
+ formsConfig.launchers.forEach((launcher, launcherName) => {
60
+ const parsedForm = parsedForms.get(launcher.form)!
61
+ const form = parsedForm.form
62
+ const globalConfigurationType = formsConfig.types.get(launcher.globalConfigurationType)!
63
+ const initialState = parsedForm.initialFormState
64
+ const formType = parsedForm.formDef.type;
65
+ const visibilityPredicateExpressions = parsedForm.visibilityPredicateExpressions
66
+ const disabledPredicatedExpressions = parsedForm.disabledPredicatedExpressions
67
+ parsedLaunchers = parsedLaunchers.set(
68
+ launcherName,
69
+ <Entity, FormState, ExtraContext, Context extends IntegratedLauncherContext<Entity, FormState, ExtraContext>>() => ({
70
+ form: IntegratedFormTemplate<Entity, FormState>().mapContext((parentContext: Context) =>
71
+ ({
72
+ initialRawEntity: parentContext.initialRawEntity,
73
+ entity: parentContext.entity,
74
+ globalConfiguration: parentContext.globalConfiguration,
75
+ commonFormState: parentContext.commonFormState,
76
+ customFormState: parentContext.customFormState,
77
+ formFieldStates: parentContext.formFieldStates,
78
+ extraContext: parentContext.extraContext,
79
+ visibilityPredicateExpressions,
80
+ disabledPredicatedExpressions,
81
+ types: formsConfig.types,
82
+ formType: formType,
83
+ onRawEntityChange: parentContext.onRawEntityChange,
84
+ parseGlobalConfiguration: (raw: any) => PredicateValue.Operations.parse(raw, globalConfigurationType, formsConfig.types),
85
+ fromApiParser: (value: any) => fromAPIRawValue(formType, formsConfig.types, builtIns, apiConverters, injectedPrimitives)(value),
86
+ toApiParser: (value: any, formState: any, checkKeys: boolean) => toAPIRawValue(formType , formsConfig.types, builtIns, apiConverters, injectedPrimitives)(value, formState, checkKeys),
87
+ actualForm: form.withView(containerFormView).mapContext((_: any) => ({
88
+ value: _.value,
89
+ entity: _.entity,
90
+ toApiParser: parentContext.toApiParser,
91
+ fromApiParser: parentContext.fromApiParser,
92
+ parseGlobalConfiguration: parentContext.parseGlobalConfiguration,
93
+ formFieldStates: parentContext.formFieldStates,
94
+ rootValue: _.value,
95
+ extraContext: parentContext.extraContext,
96
+ commonFormState: parentContext.commonFormState,
97
+ predicateEvaluations: parentContext.customFormState.predicateEvaluations,
98
+ visibilities: _.visibilities,
99
+ disabledFields: _.disabledFields,
100
+ }))
101
+ }) as any)
102
+ .withViewFromProps(props => props.context.containerWrapper)
103
+ .mapForeignMutationsFromProps(props => props.foreignMutations as any),
104
+ initialState: IntegratedFormState<Entity, FormState>().Default(initialState.formFieldStates, initialState.commonFormState),
105
+ fromApiParser: (value: any): Entity => fromAPIRawValue(formType, formsConfig.types, builtIns, apiConverters, injectedPrimitives)(value),
106
+ toApiParser: (value: any, formState: any, checkKeys: boolean) => toAPIRawValue(formType , formsConfig.types, builtIns, apiConverters, injectedPrimitives)(value, formState, checkKeys),
107
+ parseGlobalConfiguration: (raw: any) => PredicateValue.Operations.parse(raw, globalConfigurationType, formsConfig.types),
108
+ })
109
+ )
110
+ })
111
+ return ValueOrErrors.Default.return(parsedLaunchers)
112
+ })
113
+
114
+ }
115
+
116
+ export type IntegratedFormsParserContext<T extends {[key in keyof T] : {type: any, state: any}}> = {
117
+ containerFormView: any,
118
+ nestedContainerFormView: any,
119
+ fieldViews: any,
120
+ fieldTypeConverters: ApiConverters<T>,
121
+ infiniteStreamSources: InfiniteStreamSources,
122
+ enumOptionsSources: EnumOptionsSources,
123
+ injectedPrimitives?: Injectables<T>,
124
+ formsConfig: any,
125
+ getFormsConfig: BasicFun<void, Promise<any>>
126
+ }
127
+
128
+ export type IntegratedFormsParserState = {
129
+ formsConfig: Synchronized<Unit, IntegratedFormParsingResult>
130
+ }
131
+ export const IntegratedFormsParserState = {
132
+ Default: (): IntegratedFormsParserState => ({
133
+ formsConfig: Synchronized.Default(unit)
134
+ }),
135
+ Updaters: {
136
+ ...simpleUpdater<IntegratedFormsParserState>()("formsConfig")
137
+ }
138
+ }