ballerina-core 1.0.194 → 1.0.195

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 (35) hide show
  1. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/domains/apis/state.d.ts +28 -40
  2. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/domains/apis/state.d.ts.map +1 -1
  3. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/domains/apis/state.js +39 -30
  4. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/domains/apis/state.js.map +1 -1
  5. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/state.d.ts.map +1 -1
  6. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/state.js +6 -0
  7. package/bin/src/forms/domains/dispatched-forms/deserializer/domains/specification/state.js.map +1 -1
  8. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_debouncer.d.ts +1 -1
  9. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeOne.d.ts +1 -1
  10. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeOne.d.ts.map +1 -1
  11. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeOne.js +1 -0
  12. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeOne.js.map +1 -1
  13. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeStream.d.ts +1 -1
  14. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/builder.d.ts +87 -87
  15. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/runner.d.ts +4 -4
  16. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/runner.d.ts.map +1 -1
  17. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/runner.js +3 -1
  18. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/runner.js.map +1 -1
  19. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/state.d.ts +1 -1
  20. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/state.d.ts.map +1 -1
  21. package/bin/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/template.d.ts +1 -1
  22. package/bin/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.d.ts +2 -2
  23. package/bin/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.d.ts.map +1 -1
  24. package/bin/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.js +42 -25
  25. package/bin/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/forms/domains/dispatched-forms/built-ins/state.ts +59 -33
  28. package/src/forms/domains/dispatched-forms/deserializer/domains/specification/domains/apis/state.ts +65 -71
  29. package/src/forms/domains/dispatched-forms/deserializer/state.ts +11 -8
  30. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeOne.ts +28 -64
  31. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/_initializeStream.ts +2 -1
  32. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/coroutines/runner.ts +7 -3
  33. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/state.ts +13 -9
  34. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/one/template.tsx +2 -1
  35. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.ts +33 -26
@@ -14,7 +14,6 @@ import {
14
14
  Option,
15
15
  } from "../../../../../../../../../main";
16
16
  import { InitializeCo } from "./builder";
17
- import { initializeStream } from "./_initializeStream";
18
17
 
19
18
  export const initializeOne = <
20
19
  CustomPresentationContext = Unit,
@@ -23,11 +22,6 @@ export const initializeOne = <
23
22
  InitializeCo<CustomPresentationContext, ExtraContext>()
24
23
  .GetState()
25
24
  .then((current) => {
26
- const InstantiatedInitializeCo = InitializeCo<
27
- CustomPresentationContext,
28
- ExtraContext
29
- >();
30
-
31
25
  const maybeId = OneAbstractRendererState.Operations.GetIdFromContext(
32
26
  current,
33
27
  ).MapErrors((_) =>
@@ -38,71 +32,41 @@ export const initializeOne = <
38
32
 
39
33
  if (maybeId.kind === "errors") {
40
34
  console.error(maybeId.errors.join("\n"));
41
- return InstantiatedInitializeCo.Wait(0);
42
- }
43
-
44
- const initializationCompletedCo = InitializeCo<
45
- CustomPresentationContext,
46
- ExtraContext
47
- >().Seq([
48
- InstantiatedInitializeCo.SetState(
49
- current.customFormState.status == "open"
50
- ? OneAbstractRendererState.Updaters.Core.customFormState.children.stream(
51
- Sum.Updaters.left(
52
- ValueInfiniteStreamState.Updaters.Template.loadMore(),
53
- ),
54
- )
55
- : IdUpdater,
56
- ),
57
- ]);
58
-
59
- const hasInitialValue =
60
- (PredicateValue.Operations.IsOption(current.value) &&
61
- current.value.isSome) ||
62
- PredicateValue.Operations.IsUnit(current.value);
63
-
64
- if (hasInitialValue) {
65
- return InstantiatedInitializeCo.Seq([initializationCompletedCo]);
35
+ return InitializeCo<CustomPresentationContext, ExtraContext>().Wait(0);
66
36
  }
67
37
 
68
- const initializeValueCo = InitializeCo<
69
- CustomPresentationContext,
70
- ExtraContext
71
- >()
38
+ return InitializeCo<CustomPresentationContext, ExtraContext>()
72
39
  .Await(
73
- () => current.getApi(maybeId.value),
40
+ // get Api being defined is in the run condition and is a sign that this could be lazy loaded
41
+ () => current.getApi!(maybeId.value),
74
42
  (_) => console.error("error while getting api value for the one", _),
75
43
  )
76
44
  .then((value) =>
77
- InstantiatedInitializeCo.Do(() => {
78
- return current.fromApiParser(value.value).Then((result) => {
79
- const updater = replaceWith<ValueOption | ValueUnit>(
80
- ValueOption.Default.some(result),
81
- );
82
- const delta: DispatchDelta<BaseFlags> = {
83
- kind: "OneReplace",
84
- replace: result,
85
- flags: {
86
- kind: "localOnly",
87
- },
88
- type: current.type,
89
- sourceAncestorLookupTypeNames: current.lookupTypeAncestorNames,
90
- };
91
- current.onChange(Option.Default.some(updater), delta);
45
+ InitializeCo<CustomPresentationContext, ExtraContext>().Do(() => {
46
+ current
47
+ .fromApiParser(value.value)
48
+ .Then((result) => {
49
+ const updater = replaceWith<ValueOption | ValueUnit>(
50
+ ValueOption.Default.some(result),
51
+ );
52
+ const delta: DispatchDelta<BaseFlags> = {
53
+ kind: "OneReplace",
54
+ replace: result,
55
+ flags: {
56
+ kind: "localOnly",
57
+ },
58
+ type: current.type,
59
+ sourceAncestorLookupTypeNames:
60
+ current.lookupTypeAncestorNames,
61
+ };
62
+ current.onChange(Option.Default.some(updater), delta);
92
63
 
93
- return ValueOrErrors.Default.return(result);
94
- });
64
+ return ValueOrErrors.Default.return(result);
65
+ })
66
+ .MapErrors((_) => {
67
+ console.error("error while parsing api value for the one", _);
68
+ return _;
69
+ });
95
70
  }),
96
71
  );
97
-
98
- const initializeStreamCo = initializeStream<
99
- CustomPresentationContext,
100
- ExtraContext
101
- >();
102
-
103
- return InstantiatedInitializeCo.Seq([
104
- initializeValueCo,
105
- initializeStreamCo,
106
- initializationCompletedCo,
107
- ]);
108
72
  });
@@ -30,7 +30,8 @@ export const initializeStream = <
30
30
  Sum.Default.left(
31
31
  ValueInfiniteStreamState.Default(
32
32
  100,
33
- current.customFormState.getChunkWithParams(maybeId.value)(
33
+ // safe because we check for undefined in the runFilter
34
+ current.customFormState.getChunkWithParams!(maybeId.value)(
34
35
  current.customFormState.streamParams.value,
35
36
  ),
36
37
  ),
@@ -33,7 +33,9 @@ export const initializeOneRunner = <
33
33
  // if the value is some, we already have something to pass to the renderers
34
34
  // -> we don't have to run the initialization coroutine
35
35
  // if the inner value is unit, we are rendering a partial one
36
- props.context.value.kind === "option" && !props.context.value.isSome,
36
+ props.context.value.kind === "option" &&
37
+ !props.context.value.isSome &&
38
+ props.context.getApi != undefined,
37
39
  });
38
40
 
39
41
  export const initializeStreamRunner = <
@@ -45,7 +47,9 @@ export const initializeStreamRunner = <
45
47
  OneAbstractRendererForeignMutationsExpected<Flags>
46
48
  >(initializeStream<CustomPresentationContext, ExtraContext>(), {
47
49
  interval: 15,
48
- runFilter: (props) => props.context.customFormState.stream.kind === "r",
50
+ runFilter: (props) =>
51
+ props.context.customFormState.stream.kind === "r" &&
52
+ props.context.customFormState.getChunkWithParams !== undefined,
49
53
  });
50
54
 
51
55
  export const oneTableDebouncerRunner = <
@@ -60,7 +64,7 @@ export const oneTableDebouncerRunner = <
60
64
  runFilter: (props) =>
61
65
  Debounced.Operations.shouldCoroutineRun(
62
66
  props.context.customFormState.streamParams,
63
- ),
67
+ ) && props.context.customFormState.getChunkWithParams !== undefined,
64
68
  });
65
69
 
66
70
  export const oneTableLoaderRunner = <
@@ -43,7 +43,7 @@ export type OneAbstractRendererReadonlyContext<
43
43
  CustomPresentationContext,
44
44
  ExtraContext
45
45
  > & {
46
- getApi: BasicFun<Guid, Promise<unknown>>;
46
+ getApi?: BasicFun<Guid, Promise<unknown>>;
47
47
  fromApiParser: (value: unknown) => ValueOrErrors<ValueRecord, string>;
48
48
  remoteEntityVersionIdentifier: string;
49
49
  };
@@ -55,19 +55,23 @@ export type OneAbstractRendererState = CommonAbstractRendererState & {
55
55
  streamParams: Debounced<Value<Map<string, string>>>;
56
56
  status: "open" | "closed";
57
57
  stream: Sum<ValueInfiniteStreamState, "not initialized">;
58
- getChunkWithParams: BasicFun<
59
- string,
60
- BasicFun<Map<string, string>, ValueInfiniteStreamState["getChunk"]>
61
- >;
58
+ getChunkWithParams:
59
+ | BasicFun<
60
+ string,
61
+ BasicFun<Map<string, string>, ValueInfiniteStreamState["getChunk"]>
62
+ >
63
+ | undefined;
62
64
  };
63
65
  };
64
66
 
65
67
  export const OneAbstractRendererState = {
66
68
  Default: (
67
- getChunk: BasicFun<
68
- string,
69
- BasicFun<Map<string, string>, ValueInfiniteStreamState["getChunk"]>
70
- >,
69
+ getChunk:
70
+ | BasicFun<
71
+ string,
72
+ BasicFun<Map<string, string>, ValueInfiniteStreamState["getChunk"]>
73
+ >
74
+ | undefined,
71
75
  ): OneAbstractRendererState => ({
72
76
  ...CommonAbstractRendererState.Default(),
73
77
  customFormState: {
@@ -450,7 +450,8 @@ export const OneAbstractRenderer = <
450
450
  OneAbstractRendererState.Updaters.Core.customFormState.children.stream(
451
451
  Sum.Updaters.left(
452
452
  ValueInfiniteStreamState.Updaters.Template.reload(
453
- props.context.customFormState.getChunkWithParams(
453
+ // safe because we check for undefined in the runFilter
454
+ props.context.customFormState.getChunkWithParams!(
454
455
  maybeId.value,
455
456
  )(props.context.customFormState.streamParams.value),
456
457
  ),
@@ -45,39 +45,46 @@ export const OneDispatcher = {
45
45
  CustomPresentationContexts,
46
46
  ExtraContext,
47
47
  >(
48
- api: string | string[],
48
+ api: string[],
49
49
  dispatcherContext: DispatcherContext<
50
50
  any,
51
51
  Flags,
52
52
  CustomPresentationContexts,
53
53
  ExtraContext
54
54
  >,
55
- ): ValueOrErrors<BasicFun<Guid, Promise<any>>, string> =>
56
- typeof api == "string"
57
- ? ValueOrErrors.Default.throwOne(
58
- `Attempted to use a table API for a one, this is not allowed`,
59
- )
60
- : Array.isArray(api) &&
61
- api.length == 2 &&
62
- api.every((_) => typeof _ == "string")
63
- ? dispatcherContext.lookupSources == undefined
64
- ? ValueOrErrors.Default.throwOne(`lookup apis are undefined`)
65
- : dispatcherContext
66
- .lookupSources(api[0])
67
- .Then((lookupSource) =>
68
- lookupSource.one == undefined
69
- ? ValueOrErrors.Default.throwOne(
70
- `lookup source missing "one" api`,
55
+ ): ValueOrErrors<BasicFun<Guid, Promise<any>> | undefined, string> =>
56
+ Array.isArray(api) &&
57
+ api.length == 2 &&
58
+ api.every((_) => typeof _ == "string")
59
+ ? dispatcherContext.specApis.lookups == undefined
60
+ ? ValueOrErrors.Default.return(undefined)
61
+ : dispatcherContext.specApis.lookups.get(api[0]) == undefined
62
+ ? ValueOrErrors.Default.return(undefined)
63
+ : dispatcherContext.specApis.lookups.get(api[0])?.one == undefined
64
+ ? ValueOrErrors.Default.return(undefined)
65
+ : dispatcherContext.specApis.lookups.get(api[0])?.one.get(api[1])
66
+ ?.methods.get == false
67
+ ? ValueOrErrors.Default.return(undefined)
68
+ : dispatcherContext.lookupSources == undefined
69
+ ? ValueOrErrors.Default.throwOne(
70
+ `lookup api sources are undefined`,
71
+ )
72
+ : dispatcherContext
73
+ .lookupSources(api[0])
74
+ .Then((lookupSource) =>
75
+ lookupSource.one == undefined
76
+ ? ValueOrErrors.Default.throwOne(
77
+ `lookup source missing "one" api`,
78
+ )
79
+ : lookupSource
80
+ .one(api[1])
81
+ .Then((source) =>
82
+ ValueOrErrors.Default.return(source.get),
83
+ ),
71
84
  )
72
- : lookupSource
73
- .one(api[1])
74
- .Then((source) =>
75
- ValueOrErrors.Default.return(source.get),
76
- ),
77
- )
78
- : ValueOrErrors.Default.throwOne(
79
- `api must be a string or an array of strings`,
80
- ),
85
+ : ValueOrErrors.Default.throwOne(
86
+ `api must be a string or an array of strings`,
87
+ ),
81
88
  Dispatch: <
82
89
  T extends DispatchInjectablesTypes<T>,
83
90
  Flags,