ballerina-core 1.0.81 → 1.0.83

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 (40) hide show
  1. package/main.ts +0 -1
  2. package/package.json +1 -1
  3. package/src/forms/domains/collection/domains/reference/state.ts +10 -0
  4. package/src/forms/domains/launcher/coroutines/runner.ts +0 -8
  5. package/src/forms/domains/launcher/domains/create/coroutines/runner.ts +84 -146
  6. package/src/forms/domains/launcher/domains/create/state.ts +43 -52
  7. package/src/forms/domains/launcher/domains/create/template.tsx +18 -18
  8. package/src/forms/domains/launcher/domains/edit/coroutines/runner.ts +73 -144
  9. package/src/forms/domains/launcher/domains/edit/state.ts +43 -54
  10. package/src/forms/domains/launcher/domains/edit/template.tsx +21 -19
  11. package/src/forms/domains/launcher/domains/passthrough/coroutines/runner.ts +22 -48
  12. package/src/forms/domains/launcher/domains/passthrough/state.ts +28 -28
  13. package/src/forms/domains/launcher/domains/passthrough/template.tsx +18 -18
  14. package/src/forms/domains/launcher/state.ts +6 -6
  15. package/src/forms/domains/launcher/template.tsx +2 -11
  16. package/src/forms/domains/parser/domains/built-ins/state.ts +461 -209
  17. package/src/forms/domains/parser/domains/predicates/state.ts +272 -114
  18. package/src/forms/domains/parser/domains/renderer/state.ts +65 -100
  19. package/src/forms/domains/parser/domains/types/state.ts +49 -5
  20. package/src/forms/domains/parser/domains/validator/state.ts +1 -1
  21. package/src/forms/domains/parser/state.tsx +60 -69
  22. package/src/forms/domains/primitives/domains/boolean/state.ts +0 -15
  23. package/src/forms/domains/primitives/domains/boolean/template.tsx +0 -40
  24. package/src/forms/domains/primitives/domains/date/state.ts +2 -4
  25. package/src/forms/domains/primitives/domains/date/template.tsx +13 -6
  26. package/src/forms/domains/primitives/domains/enum/state.ts +17 -22
  27. package/src/forms/domains/primitives/domains/enum/template.tsx +19 -26
  28. package/src/forms/domains/primitives/domains/enum-multiselect/state.ts +7 -13
  29. package/src/forms/domains/primitives/domains/enum-multiselect/template.tsx +58 -68
  30. package/src/forms/domains/primitives/domains/list/state.ts +12 -15
  31. package/src/forms/domains/primitives/domains/list/template.tsx +76 -57
  32. package/src/forms/domains/primitives/domains/map/state.ts +17 -21
  33. package/src/forms/domains/primitives/domains/map/template.tsx +96 -53
  34. package/src/forms/domains/primitives/domains/searchable-infinite-stream/state.ts +39 -33
  35. package/src/forms/domains/primitives/domains/searchable-infinite-stream/template.tsx +34 -38
  36. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/state.ts +7 -8
  37. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/template.tsx +46 -37
  38. package/src/forms/domains/singleton/state.ts +21 -71
  39. package/src/forms/domains/singleton/template.tsx +21 -33
  40. package/src/forms/domains/collection/domains/unionCase/state.ts +0 -21
package/main.ts CHANGED
@@ -116,7 +116,6 @@ export * from "./src/forms/domains/launcher/coroutines/runner";
116
116
  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
- export * from "./src/forms/domains/collection/domains/unionCase/state";
120
119
  export * from "./src/forms/domains/parser/domains/predicates/state";
121
120
  export * from "./src/forms/domains/launcher/domains/passthrough/state";
122
121
  export * from "./src/forms/domains/launcher/domains/passthrough/template";
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.81",
5
+ "version": "1.0.83",
6
6
  "main": "main.ts",
7
7
  "scripts": {
8
8
  "prettier": "prettier --write ."
@@ -24,6 +24,11 @@ export const CollectionReference = {
24
24
  ...simpleUpdater<CollectionReference>()("Id"),
25
25
  ...simpleUpdater<CollectionReference>()("DisplayValue"),
26
26
  },
27
+ Operations: {
28
+ IsCollectionReference: (value: any): value is CollectionReference => {
29
+ return typeof value == "object" && value.Id && value.DisplayValue;
30
+ },
31
+ },
27
32
  };
28
33
 
29
34
  export type EnumReference = {
@@ -36,4 +41,9 @@ export const EnumReference = {
36
41
  Updaters: {
37
42
  ...simpleUpdater<EnumReference>()("Value"),
38
43
  },
44
+ Operations: {
45
+ IsEnumReference: (value: any): value is EnumReference => {
46
+ return typeof value == "object" && value.Value;
47
+ },
48
+ },
39
49
  };
@@ -58,13 +58,10 @@ export const FormRunnerLoader = () => {
58
58
  formFieldStates:
59
59
  instantiatedForm.initialState.formFieldStates,
60
60
  entity: instantiatedForm.initialState.entity,
61
- rawEntity: instantiatedForm.initialState.rawEntity,
62
61
  commonFormState:
63
62
  instantiatedForm.initialState.commonFormState,
64
63
  customFormState:
65
64
  instantiatedForm.initialState.customFormState,
66
- rawGlobalConfiguration:
67
- instantiatedForm.initialState.rawGlobalConfiguration,
68
65
  globalConfiguration:
69
66
  instantiatedForm.initialState.globalConfiguration,
70
67
  }),
@@ -94,13 +91,10 @@ export const FormRunnerLoader = () => {
94
91
  formFieldStates:
95
92
  instantiatedForm.initialState.formFieldStates,
96
93
  entity: instantiatedForm.initialState.entity,
97
- rawEntity: instantiatedForm.initialState.rawEntity,
98
94
  commonFormState:
99
95
  instantiatedForm.initialState.commonFormState,
100
96
  customFormState:
101
97
  instantiatedForm.initialState.customFormState,
102
- rawGlobalConfiguration:
103
- instantiatedForm.initialState.rawGlobalConfiguration,
104
98
  globalConfiguration:
105
99
  instantiatedForm.initialState.globalConfiguration,
106
100
  }),
@@ -134,8 +128,6 @@ export const FormRunnerLoader = () => {
134
128
  customFormState:
135
129
  instantiatedForm.initialState.customFormState,
136
130
  entity: undefined,
137
- rawEntity: undefined,
138
- rawGlobalConfiguration: undefined,
139
131
  globalConfiguration: undefined,
140
132
  }),
141
133
  ),
@@ -21,69 +21,84 @@ import {
21
21
  import { CoTypedFactory } from "../../../../../../coroutines/builder";
22
22
  import { CreateFormContext, CreateFormWritableState } from "../state";
23
23
 
24
- export const createFormRunner = <E, FS>() => {
24
+ export const createFormRunner = <T, FS>() => {
25
25
  const Co = CoTypedFactory<
26
- CreateFormContext<E, FS> & CreateFormForeignMutationsExpected<E, FS>,
27
- CreateFormWritableState<E, FS>
26
+ CreateFormContext<T, FS> & CreateFormForeignMutationsExpected<T, FS>,
27
+ CreateFormWritableState<T, FS>
28
28
  >();
29
29
 
30
30
  const init = Co.GetState().then((current) =>
31
31
  Co.Seq([
32
32
  Co.SetState(
33
- CreateFormState<
34
- E,
35
- FS
36
- >().Updaters.Core.customFormState.children.initApiChecker(
37
- ApiResponseChecker.Updaters().toUnchecked(),
38
- ),
33
+ CreateFormState<T, FS>()
34
+ .Updaters.Core.customFormState.children.initApiChecker(
35
+ ApiResponseChecker.Updaters().toUnchecked(),
36
+ )
37
+ .then(
38
+ CreateFormState<
39
+ T,
40
+ FS
41
+ >().Updaters.Core.customFormState.children.configApiChecker(
42
+ ApiResponseChecker.Updaters().toUnchecked(),
43
+ ),
44
+ ),
39
45
  ),
40
46
  Co.All([
41
- Synchronize<Unit, E>(
42
- () => current.api.default(),
47
+ Synchronize<Unit, PredicateValue>(
48
+ () =>
49
+ current.api.default().then((raw) => {
50
+ const result = current.fromApiParser(raw);
51
+ return result.kind == "errors"
52
+ ? Promise.reject(result.errors)
53
+ : Promise.resolve(result.value);
54
+ }),
43
55
  (_) => "transient failure",
44
56
  5,
45
57
  50,
46
- ).embed(
47
- (_) => _.rawEntity,
48
- CreateFormState<E, FS>().Updaters.Core.rawEntity,
49
- ),
50
- Synchronize<Unit, any>(
51
- () => current.api.getGlobalConfiguration(),
58
+ ).embed((_) => _.entity, CreateFormState<T, FS>().Updaters.Core.entity),
59
+ Synchronize<Unit, PredicateValue>(
60
+ () =>
61
+ current.api.getGlobalConfiguration().then((raw) => {
62
+ const result = current.parseGlobalConfiguration(raw);
63
+ return result.kind == "errors"
64
+ ? Promise.reject(result.errors)
65
+ : Promise.resolve(result.value);
66
+ }),
52
67
  (_) => "transient failure",
53
68
  5,
54
69
  50,
55
70
  ).embed(
56
- (_) => _.rawGlobalConfiguration,
57
- CreateFormState<E, FS>().Updaters.Core.rawGlobalConfiguration,
71
+ (_) => _.globalConfiguration,
72
+ CreateFormState<T, FS>().Updaters.Core.globalConfiguration,
58
73
  ),
59
74
  ]),
60
75
  HandleApiResponse<
61
- CreateFormWritableState<E, FS>,
62
- CreateFormContext<E, FS>,
76
+ CreateFormWritableState<T, FS>,
77
+ CreateFormContext<T, FS>,
63
78
  any
64
- >((_) => _.rawEntity.sync, {
79
+ >((_) => _.entity.sync, {
65
80
  handleSuccess: current.apiHandlers?.onDefaultSuccess,
66
81
  handleError: current.apiHandlers?.onDefaultError,
67
82
  }),
68
83
  Co.SetState(
69
84
  CreateFormState<
70
- E,
85
+ T,
71
86
  FS
72
87
  >().Updaters.Core.customFormState.children.initApiChecker(
73
88
  ApiResponseChecker.Updaters().toChecked(),
74
89
  ),
75
90
  ),
76
91
  HandleApiResponse<
77
- CreateFormWritableState<E, FS>,
78
- CreateFormContext<E, FS>,
92
+ CreateFormWritableState<T, FS>,
93
+ CreateFormContext<T, FS>,
79
94
  any
80
- >((_) => _.rawGlobalConfiguration.sync, {
95
+ >((_) => _.globalConfiguration.sync, {
81
96
  handleSuccess: current.apiHandlers?.onConfigSuccess,
82
97
  handleError: current.apiHandlers?.onConfigError,
83
98
  }),
84
99
  Co.SetState(
85
100
  CreateFormState<
86
- E,
101
+ T,
87
102
  FS
88
103
  >().Updaters.Core.customFormState.children.configApiChecker(
89
104
  ApiResponseChecker.Updaters().toChecked(),
@@ -92,73 +107,27 @@ export const createFormRunner = <E, FS>() => {
92
107
  ]),
93
108
  );
94
109
 
95
- const parseEntity = Co.GetState().then((current) => {
96
- if (current.rawEntity.sync.kind == "loaded") {
97
- const parsed = current.fromApiParser(current.rawEntity.sync.value);
98
- return Synchronize<Unit, any>(
99
- () => Promise.resolve(parsed),
100
- (_) => "transient failure",
101
- 5,
102
- 50,
103
- ).embed((_) => _.entity, CreateFormState<E, FS>().Updaters.Core.entity);
104
- }
105
- return Co.Do(() => {});
106
- });
107
-
108
- const parseGlobalConfiguration = Co.GetState().then((current) => {
109
- if (current.rawGlobalConfiguration.sync.kind == "loaded") {
110
- const parsed = current.parseGlobalConfiguration(
111
- current.rawGlobalConfiguration.sync.value,
112
- );
113
- if (parsed.kind == "value")
114
- return Co.SetState(
115
- CreateFormState<E, FS>().Updaters.Core.globalConfiguration(
116
- replaceWith(Sum.Default.left(parsed.value)),
117
- ),
118
- );
119
- }
120
- return Co.Do(() => {});
121
- });
122
-
123
110
  const calculateInitialVisibilities = Co.GetState().then((current) => {
124
111
  if (
125
- current.rawEntity.sync.kind == "loaded" &&
126
- current.rawGlobalConfiguration.sync.kind == "loaded"
112
+ current.entity.sync.kind == "loaded" &&
113
+ current.globalConfiguration.sync.kind == "loaded"
127
114
  ) {
128
- const parsedRootPredicate = PredicateValue.Operations.parse(
129
- current.rawEntity.sync.value,
130
- current.formType,
131
- current.types,
132
- );
133
-
134
- if (
135
- parsedRootPredicate.kind == "errors" ||
136
- current.globalConfiguration.kind == "r"
137
- )
138
- return Co.Do(() => {});
139
- if (
140
- typeof parsedRootPredicate.value != "object" ||
141
- !("kind" in parsedRootPredicate.value) ||
142
- parsedRootPredicate.value.kind != "record"
143
- )
144
- return Co.Do(() => {});
145
115
  return Co.SetState(
146
116
  CreateFormState<
147
- E,
117
+ T,
148
118
  FS
149
119
  >().Updaters.Core.customFormState.children.predicateEvaluations(
150
120
  replaceWith(
151
121
  Debounced.Default(
152
122
  evaluatePredicates(
153
123
  {
154
- global: current.globalConfiguration.value,
155
- types: current.types,
124
+ global: current.globalConfiguration.sync.value,
156
125
  visibilityPredicateExpressions:
157
126
  current.visibilityPredicateExpressions,
158
127
  disabledPredicatedExpressions:
159
128
  current.disabledPredicatedExpressions,
160
129
  },
161
- parsedRootPredicate.value,
130
+ current.entity.sync.value,
162
131
  ),
163
132
  ),
164
133
  ),
@@ -169,7 +138,7 @@ export const createFormRunner = <E, FS>() => {
169
138
  });
170
139
 
171
140
  const PredicatesCo = CoTypedFactory<
172
- CreateFormWritableState<E, FS> & CreateFormContext<E, FS>,
141
+ CreateFormWritableState<T, FS> & CreateFormContext<T, FS>,
173
142
  ValueOrErrors<
174
143
  {
175
144
  visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
@@ -188,45 +157,27 @@ export const createFormRunner = <E, FS>() => {
188
157
  },
189
158
  string
190
159
  >,
191
- CreateFormContext<E, FS> & CreateFormWritableState<E, FS>
160
+ CreateFormContext<T, FS> & CreateFormWritableState<T, FS>
192
161
  >(
193
162
  PredicatesCo.GetState().then((current) => {
194
163
  if (
195
- current.globalConfiguration.kind == "r" ||
164
+ current.globalConfiguration.sync.kind != "loaded" ||
196
165
  current.entity.sync.kind != "loaded"
197
166
  ) {
198
167
  return PredicatesCo.Return<ApiResultStatus>("permanent failure");
199
168
  }
200
- const parsedEntity = current.toApiParser(
201
- current.entity.sync.value,
202
- current,
203
- false,
204
- );
205
- if (parsedEntity.kind == "errors") {
206
- console.error("parsedEntity", parsedEntity);
207
- return PredicatesCo.Return<ApiResultStatus>("permanent failure");
208
- }
209
- const parseRootPredicate = PredicateValue.Operations.parse(
210
- parsedEntity.value,
211
- current.formType,
212
- current.types,
213
- );
214
- if (parseRootPredicate.kind == "errors") {
215
- console.error("parseRootPredicate", parseRootPredicate);
216
- return PredicatesCo.Return<ApiResultStatus>("permanent failure");
217
- }
169
+
218
170
  return PredicatesCo.SetState(
219
171
  replaceWith(
220
172
  evaluatePredicates(
221
173
  {
222
- global: current.globalConfiguration.value,
223
- types: current.types,
174
+ global: current.globalConfiguration.sync.value,
224
175
  visibilityPredicateExpressions:
225
176
  current.visibilityPredicateExpressions,
226
177
  disabledPredicatedExpressions:
227
178
  current.disabledPredicatedExpressions,
228
179
  },
229
- parseRootPredicate.value,
180
+ current.entity.sync.value,
230
181
  ),
231
182
  ),
232
183
  ).then(() => PredicatesCo.Return<ApiResultStatus>("success"));
@@ -234,29 +185,34 @@ export const createFormRunner = <E, FS>() => {
234
185
  50,
235
186
  ).embed(
236
187
  (_) => ({ ..._, ..._.customFormState.predicateEvaluations }),
237
- CreateFormState<E, FS>().Updaters.Core.customFormState.children
188
+ CreateFormState<T, FS>().Updaters.Core.customFormState.children
238
189
  .predicateEvaluations,
239
190
  ),
240
191
  );
241
192
 
193
+ const SynchronizeCo = CoTypedFactory<
194
+ CreateFormWritableState<T, FS>,
195
+ Synchronized<Unit, ApiErrors>
196
+ >();
197
+
242
198
  const synchronize = Co.Repeat(
243
- Co.GetState().then((current) =>
199
+ Co.GetState().then((createFormState) =>
244
200
  Co.Seq([
245
201
  Co.SetState(
246
202
  CreateFormState<
247
- E,
203
+ T,
248
204
  FS
249
205
  >().Updaters.Core.customFormState.children.createApiChecker(
250
206
  ApiResponseChecker.Updaters().toUnchecked(),
251
207
  ),
252
208
  ),
253
- Debounce<Synchronized<Unit, ApiErrors>, CreateFormWritableState<E, FS>>(
254
- (() => {
209
+ Debounce<Synchronized<Unit, ApiErrors>, CreateFormWritableState<T, FS>>(
210
+ SynchronizeCo.GetState().then((current) => {
255
211
  if (current.entity.sync.kind != "loaded") {
256
212
  return Synchronize<
257
213
  Unit,
258
214
  ApiErrors,
259
- CreateFormWritableState<E, FS>
215
+ CreateFormWritableState<T, FS>
260
216
  >(
261
217
  (_) => Promise.resolve([]),
262
218
  (_) => "transient failure",
@@ -264,39 +220,38 @@ export const createFormRunner = <E, FS>() => {
264
220
  50,
265
221
  );
266
222
  }
267
- const parsed = current.toApiParser(
223
+ const parsed = createFormState.toApiParser(
268
224
  current.entity.sync.value,
269
225
  current,
270
- true,
271
226
  );
272
227
 
273
- return Synchronize<Unit, ApiErrors, CreateFormWritableState<E, FS>>(
228
+ return Synchronize<Unit, ApiErrors, CreateFormWritableState<T, FS>>(
274
229
  (_) =>
275
230
  parsed.kind == "errors"
276
231
  ? Promise.reject(parsed.errors)
277
- : current.api.create(parsed),
232
+ : createFormState.api.create(parsed),
278
233
  (_) => "transient failure",
279
234
  parsed.kind == "errors" ? 1 : 5,
280
235
  50,
281
236
  );
282
- })(),
237
+ }),
283
238
  15,
284
239
  ).embed(
285
240
  (_) => ({ ..._, ..._.customFormState.apiRunner }),
286
- CreateFormState<E, FS>().Updaters.Core.customFormState.children
241
+ CreateFormState<T, FS>().Updaters.Core.customFormState.children
287
242
  .apiRunner,
288
243
  ),
289
244
  HandleApiResponse<
290
- CreateFormWritableState<E, FS>,
291
- CreateFormContext<E, FS>,
245
+ CreateFormWritableState<T, FS>,
246
+ CreateFormContext<T, FS>,
292
247
  ApiErrors
293
248
  >((_) => _.customFormState.apiRunner.sync, {
294
- handleSuccess: current.apiHandlers?.onCreateSuccess,
295
- handleError: current.apiHandlers?.onCreateError,
249
+ handleSuccess: createFormState.apiHandlers?.onCreateSuccess,
250
+ handleError: createFormState.apiHandlers?.onCreateError,
296
251
  }),
297
252
  Co.SetState(
298
253
  CreateFormState<
299
- E,
254
+ T,
300
255
  FS
301
256
  >().Updaters.Core.customFormState.children.createApiChecker(
302
257
  ApiResponseChecker.Updaters().toChecked(),
@@ -306,45 +261,28 @@ export const createFormRunner = <E, FS>() => {
306
261
  ),
307
262
  );
308
263
 
309
- return Co.Template<CreateFormForeignMutationsExpected<E, FS>>(init, {
264
+ return Co.Template<CreateFormForeignMutationsExpected<T, FS>>(init, {
310
265
  interval: 15,
311
266
  runFilter: (props) =>
312
- !AsyncState.Operations.hasValue(props.context.rawEntity.sync) ||
313
- !AsyncState.Operations.hasValue(
314
- props.context.rawGlobalConfiguration.sync,
315
- ) ||
267
+ !AsyncState.Operations.hasValue(props.context.entity.sync) ||
268
+ !AsyncState.Operations.hasValue(props.context.globalConfiguration.sync) ||
316
269
  !ApiResponseChecker.Operations.checked(
317
270
  props.context.customFormState.initApiChecker,
318
271
  ),
319
272
  }).any([
320
- Co.Template<CreateFormForeignMutationsExpected<E, FS>>(parseEntity, {
321
- interval: 15,
322
- runFilter: (props) =>
323
- props.context.rawEntity.sync.kind == "loaded" &&
324
- !AsyncState.Operations.hasValue(props.context.entity.sync),
325
- }),
326
- Co.Template<CreateFormForeignMutationsExpected<E, FS>>(
327
- parseGlobalConfiguration,
328
- {
329
- interval: 15,
330
- runFilter: (props) =>
331
- props.context.rawGlobalConfiguration.sync.kind == "loaded" &&
332
- props.context.globalConfiguration.kind == "r",
333
- },
334
- ),
335
- Co.Template<CreateFormForeignMutationsExpected<E, FS>>(
273
+ Co.Template<CreateFormForeignMutationsExpected<T, FS>>(
336
274
  calculateInitialVisibilities,
337
275
  {
338
276
  interval: 15,
339
277
  runFilter: (props) =>
340
- props.context.rawEntity.sync.kind == "loaded" &&
341
- props.context.globalConfiguration.kind == "l",
278
+ props.context.entity.sync.kind == "loaded" &&
279
+ props.context.globalConfiguration.sync.kind == "loaded",
342
280
  },
343
281
  ),
344
- Co.Template<CreateFormForeignMutationsExpected<E, FS>>(synchronize, {
282
+ Co.Template<CreateFormForeignMutationsExpected<T, FS>>(synchronize, {
345
283
  interval: 15,
346
284
  runFilter: (props) =>
347
- props.context.entity.sync.kind === "loaded" &&
285
+ props.context.entity.sync.kind == "loaded" &&
348
286
  (Debounced.Operations.shouldCoroutineRun(
349
287
  props.context.customFormState.apiRunner,
350
288
  ) ||
@@ -352,13 +290,13 @@ export const createFormRunner = <E, FS>() => {
352
290
  props.context.customFormState.createApiChecker,
353
291
  )),
354
292
  }),
355
- Co.Template<CreateFormForeignMutationsExpected<E, FS>>(
293
+ Co.Template<CreateFormForeignMutationsExpected<T, FS>>(
356
294
  calculateVisibilities,
357
295
  {
358
296
  interval: 15,
359
297
  runFilter: (props) =>
360
298
  props.context.entity.sync.kind == "loaded" &&
361
- props.context.globalConfiguration.kind == "l" &&
299
+ props.context.globalConfiguration.sync.kind == "loaded" &&
362
300
  Debounced.Operations.shouldCoroutineRun(
363
301
  props.context.customFormState.predicateEvaluations,
364
302
  ),