ballerina-core 1.0.84 → 1.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.ts CHANGED
@@ -99,6 +99,10 @@ export * from "./src/forms/domains/primitives/domains/secret/state";
99
99
  export * from "./src/forms/domains/primitives/domains/secret/template";
100
100
  export * from "./src/forms/domains/primitives/domains/map/state";
101
101
  export * from "./src/forms/domains/primitives/domains/map/template";
102
+ export * from "./src/forms/domains/primitives/domains/sum/state";
103
+ export * from "./src/forms/domains/primitives/domains/sum/template";
104
+ export * from "./src/forms/domains/primitives/domains/unit/state";
105
+ export * from "./src/forms/domains/primitives/domains/unit/template";
102
106
  export * from "./src/forms/domains/parser/state";
103
107
  export * from "./src/forms/domains/parser/template";
104
108
  export * from "./src/forms/domains/parser/coroutines/runner";
@@ -119,6 +123,8 @@ export * from "./src/forms/domains/parser/domains/injectables/state";
119
123
  export * from "./src/forms/domains/parser/domains/predicates/state";
120
124
  export * from "./src/forms/domains/launcher/domains/passthrough/state";
121
125
  export * from "./src/forms/domains/launcher/domains/passthrough/template";
126
+ export * from "./src/forms/domains/primitives/domains/tuple/state";
127
+ export * from "./src/forms/domains/primitives/domains/tuple/template";
122
128
 
123
129
  // import { simpleUpdater, simpleUpdaterWithChildren } from "./src/fun/domains/updater/domains/simpleUpdater/state"
124
130
  // 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.84",
5
+ "version": "1.0.86",
6
6
  "main": "main.ts",
7
7
  "scripts": {
8
8
  "prettier": "prettier --write ."
@@ -1,6 +1,9 @@
1
1
  import { List } from "immutable";
2
2
  import { Updater } from "../../../../../fun/domains/updater/state";
3
3
  import { BasicFun } from "../../../../../fun/state";
4
+ import { unit } from "../../../../../fun/domains/unit/state";
5
+ import { Option, Sum } from "../../../sum/state";
6
+ import { ValueOrErrors } from "../../../valueOrErrors/state";
4
7
 
5
8
  export const ListRepo = {
6
9
  Default: {},
@@ -32,5 +35,19 @@ export const ListRepo = {
32
35
  });
33
36
  },
34
37
  },
35
- Operations: {},
38
+ Operations: {
39
+ tryFind: <V>(elementIndex: number, list: List<V>): Option<V> =>
40
+ list.has(elementIndex)
41
+ ? Sum.Default.right(list.get(elementIndex)!)
42
+ : Sum.Default.left(unit),
43
+ tryFindWithError: <v, e>(
44
+ i: number,
45
+ m: List<v>,
46
+ e: () => e,
47
+ ): ValueOrErrors<v, e> =>
48
+ ValueOrErrors.Default.ofOption(
49
+ m.has(i) ? Sum.Default.right(m.get(i)!) : Sum.Default.left(unit),
50
+ e,
51
+ ),
52
+ },
36
53
  };
@@ -13,7 +13,6 @@ import {
13
13
  Sum,
14
14
  TypeName,
15
15
  unit,
16
- ValueRecord,
17
16
  ValueTuple,
18
17
  } from "../../../../../../main";
19
18
  import { ValueOrErrors } from "../../../../../collections/domains/valueOrErrors/state";
@@ -32,6 +31,7 @@ const simpleMapKeyToIdentifer = (key: any): string => {
32
31
  };
33
32
 
34
33
  export const PrimitiveTypes = [
34
+ "unit",
35
35
  "guid", //resolves to string
36
36
  "string",
37
37
  "number",
@@ -48,7 +48,9 @@ export const GenericTypes = [
48
48
  "List",
49
49
  "Map",
50
50
  "Union",
51
+ "Tuple",
51
52
  "Option",
53
+ "Sum",
52
54
  ] as const;
53
55
  export type GenericType = (typeof GenericTypes)[number];
54
56
 
@@ -61,7 +63,7 @@ export type ApiConverters<
61
63
  > = { [key in keyof T]: ApiConverter<T[key]["type"]> } & BuiltInApiConverters;
62
64
 
63
65
  export type VerifiedRawUnionCase = {
64
- case: string;
66
+ caseName: string;
65
67
  fields: Record<string, any>;
66
68
  };
67
69
 
@@ -71,7 +73,7 @@ export const VerifiedRawUnionCase = {
71
73
  return (
72
74
  typeof value == "object" &&
73
75
  "caseName" in value &&
74
- typeof value.case == "string" &&
76
+ typeof value.caseName == "string" &&
75
77
  "fields" in value &&
76
78
  typeof value.fields == "object"
77
79
  );
@@ -98,6 +100,15 @@ export const RawOption = {
98
100
  },
99
101
  };
100
102
 
103
+ export type RawSum = { Kind: "l" | "r"; Value: any };
104
+ export const RawSum = {
105
+ Operations: {
106
+ IsRawSum: (value: any): value is RawSum => {
107
+ return typeof value == "object" && "Kind" in value && "Value" in value;
108
+ },
109
+ },
110
+ };
111
+
101
112
  export type BuiltInApiConverters = {
102
113
  string: ApiConverter<string>;
103
114
  number: ApiConverter<number>;
@@ -114,6 +125,8 @@ export type BuiltInApiConverters = {
114
125
  >;
115
126
  List: ApiConverter<List<any>>;
116
127
  Map: ApiConverter<List<[any, any]>>;
128
+ Tuple: ApiConverter<List<any>>;
129
+ Sum: ApiConverter<Sum<any, any>>;
117
130
  };
118
131
 
119
132
  export type PrimitiveBuiltIn = {
@@ -125,6 +138,7 @@ export type BuiltIns = {
125
138
  primitives: Map<string, PrimitiveBuiltIn>;
126
139
  generics: Map<string, GenericBuiltIn>;
127
140
  renderers: {
141
+ unit: Set<string>;
128
142
  boolean: Set<string>;
129
143
  number: Set<string>;
130
144
  string: Set<string>;
@@ -137,12 +151,21 @@ export type BuiltIns = {
137
151
  streamMultiSelection: Set<string>;
138
152
  list: Set<string>;
139
153
  map: Set<string>;
154
+ tuple: Set<string>;
155
+ sum: Set<string>;
140
156
  };
141
157
  };
142
158
 
143
159
  export const builtInsFromFieldViews = (fieldViews: any): BuiltIns => {
144
160
  const builtins: BuiltIns = {
145
161
  primitives: Map<string, PrimitiveBuiltIn>([
162
+ [
163
+ "unit",
164
+ {
165
+ renderers: Set(["unit"]),
166
+ defaultValue: PredicateValue.Default.unit(),
167
+ },
168
+ ] as [string, PrimitiveBuiltIn],
146
169
  [
147
170
  "string",
148
171
  {
@@ -215,6 +238,21 @@ export const builtInsFromFieldViews = (fieldViews: any): BuiltIns => {
215
238
  string,
216
239
  GenericBuiltIn,
217
240
  ],
241
+ [
242
+ "Tuple",
243
+ {
244
+ defaultValue: (values: PredicateValue[]) =>
245
+ PredicateValue.Default.tuple(List(values)),
246
+ },
247
+ ] as [string, GenericBuiltIn],
248
+ [
249
+ "Sum",
250
+ {
251
+ defaultValue: PredicateValue.Default.sum(
252
+ Sum.Default.right(PredicateValue.Default.unit()),
253
+ ),
254
+ },
255
+ ],
218
256
  ["Union", { defaultValue: PredicateValue.Default.record(Map()) }] as [
219
257
  string,
220
258
  GenericBuiltIn,
@@ -230,6 +268,7 @@ export const builtInsFromFieldViews = (fieldViews: any): BuiltIns => {
230
268
  ] as [string, GenericBuiltIn],
231
269
  ]),
232
270
  renderers: {
271
+ unit: Set(),
233
272
  boolean: Set(),
234
273
  date: Set(),
235
274
  enumMultiSelection: Set(),
@@ -239,9 +278,11 @@ export const builtInsFromFieldViews = (fieldViews: any): BuiltIns => {
239
278
  number: Set(),
240
279
  string: Set(),
241
280
  list: Set(),
281
+ tuple: Set(),
242
282
  base64File: Set(),
243
283
  secret: Set(),
244
284
  map: Set(),
285
+ sum: Set(),
245
286
  },
246
287
  };
247
288
  Object.keys(builtins.renderers).forEach((_categoryName) => {
@@ -272,6 +313,15 @@ export const defaultValue =
272
313
  if (injectedPrimitive != undefined) return injectedPrimitive.defaultValue;
273
314
  }
274
315
 
316
+ if (t.kind == "application" && t.value == "Tuple") {
317
+ return builtIns.generics
318
+ .get("Tuple")!
319
+ .defaultValue(
320
+ t.args.map((_) =>
321
+ defaultValue(types, builtIns, injectedPrimitives)(_),
322
+ ),
323
+ );
324
+ }
275
325
  if (t.kind == "application") {
276
326
  const generic = builtIns.generics.get(t.value);
277
327
  if (generic) return generic.defaultValue;
@@ -309,13 +359,19 @@ export const fromAPIRawValue =
309
359
  injectedPrimitives?: InjectedPrimitives<T>,
310
360
  ) =>
311
361
  (raw: any): ValueOrErrors<PredicateValue, string> => {
312
- if (raw == undefined) {
362
+ // allow undefined for unit
363
+ if (raw == undefined && (t.kind !== "primitive" || t.value != "unit")) {
313
364
  return ValueOrErrors.Default.throwOne(
314
365
  `raw value is undefined for type ${JSON.stringify(t)}`,
315
366
  );
316
367
  }
317
368
 
318
369
  if (t.kind == "primitive") {
370
+ // unit is a special kind of primitive
371
+ if (t.value == "unit") {
372
+ return ValueOrErrors.Default.return(PredicateValue.Default.unit());
373
+ }
374
+
319
375
  if (!PredicateValue.Operations.IsPrimitive(raw)) {
320
376
  return ValueOrErrors.Default.throwOne(
321
377
  `primitive expected but got ${JSON.stringify(raw)}`,
@@ -331,10 +387,10 @@ export const fromAPIRawValue =
331
387
  `union expected but got ${JSON.stringify(raw)}`,
332
388
  );
333
389
  }
334
- const caseType = t.args.get(raw.case);
390
+ const caseType = t.args.get(raw.caseName);
335
391
  if (caseType == undefined) {
336
392
  return ValueOrErrors.Default.throwOne(
337
- `union case ${raw.case} not found in type ${JSON.stringify(t)}`,
393
+ `union case ${raw.caseName} not found in type ${JSON.stringify(t)}`,
338
394
  );
339
395
  }
340
396
  return fromAPIRawValue(
@@ -371,7 +427,7 @@ export const fromAPIRawValue =
371
427
  );
372
428
  }
373
429
  return ValueOrErrors.Default.return(
374
- PredicateValue.Default.unionCase(result.case, fields),
430
+ PredicateValue.Default.unionCase(result.caseName, fields),
375
431
  );
376
432
  });
377
433
  }
@@ -470,7 +526,7 @@ export const fromAPIRawValue =
470
526
 
471
527
  if (
472
528
  raw.some(
473
- (_) => typeof _ != "object" || !("key" in _) || !("value" in _),
529
+ (_) => typeof _ != "object" || !("Key" in _) || !("Value" in _),
474
530
  )
475
531
  ) {
476
532
  return ValueOrErrors.Default.throwOne(
@@ -479,7 +535,6 @@ export const fromAPIRawValue =
479
535
  )}`,
480
536
  );
481
537
  }
482
-
483
538
  const result = converters[t.value].fromAPIRawValue(raw);
484
539
 
485
540
  return ValueOrErrors.Operations.All(
@@ -512,6 +567,72 @@ export const fromAPIRawValue =
512
567
  ),
513
568
  );
514
569
  }
570
+
571
+ if (t.value == "Tuple") {
572
+ if (!Array.isArray(raw))
573
+ return ValueOrErrors.Default.throwOne(
574
+ `Array expected but got ${JSON.stringify(raw)}`,
575
+ );
576
+ if (raw.length != t.args.length)
577
+ return ValueOrErrors.Default.throwOne(
578
+ `Array length mismatch expected tuple length: ${t.args.length} expected but got ${raw.length}`,
579
+ );
580
+
581
+ const result = converters[t.value].fromAPIRawValue(raw);
582
+ return ValueOrErrors.Operations.All(
583
+ List<ValueOrErrors<PredicateValue, string>>(
584
+ result.map((_, index) =>
585
+ fromAPIRawValue(
586
+ t.args[index],
587
+ types,
588
+ builtIns,
589
+ converters,
590
+ injectedPrimitives,
591
+ )(_),
592
+ ),
593
+ ),
594
+ ).Then((values) =>
595
+ ValueOrErrors.Default.return(
596
+ PredicateValue.Default.tuple(List(values)),
597
+ ),
598
+ );
599
+ }
600
+
601
+ if (t.value === "Sum" && t.args.length === 2) {
602
+ if (!RawSum.Operations.IsRawSum(raw)) {
603
+ return ValueOrErrors.Default.throwOne(
604
+ `Sum expected but got ${JSON.stringify(raw)}`,
605
+ );
606
+ }
607
+
608
+ const result = converters[t.value].fromAPIRawValue(raw);
609
+
610
+ if (raw.Kind === "l") {
611
+ return fromAPIRawValue(
612
+ t.args[0],
613
+ types,
614
+ builtIns,
615
+ converters,
616
+ injectedPrimitives,
617
+ )(result.value).Then((value) =>
618
+ ValueOrErrors.Default.return(
619
+ PredicateValue.Default.sum(Sum.Default.left(value)),
620
+ ),
621
+ );
622
+ }
623
+
624
+ return fromAPIRawValue(
625
+ t.args[1],
626
+ types,
627
+ builtIns,
628
+ converters,
629
+ injectedPrimitives,
630
+ )(result.value).Then((value) =>
631
+ ValueOrErrors.Default.return(
632
+ PredicateValue.Default.sum(Sum.Default.right(value)),
633
+ ),
634
+ );
635
+ }
515
636
  }
516
637
 
517
638
  if (t.kind == "lookup")
@@ -572,7 +693,7 @@ export const toAPIRawValue =
572
693
  return ValueOrErrors.Operations.Return(
573
694
  converters[t.value as string | keyof T].toAPIRawValue([
574
695
  raw,
575
- formState.modifiedByUser,
696
+ formState.commonFormState.modifiedByUser,
576
697
  ]),
577
698
  );
578
699
  }
@@ -595,8 +716,8 @@ export const toAPIRawValue =
595
716
  }
596
717
  return ValueOrErrors.Operations.Return(
597
718
  converters[t.kind].toAPIRawValue([
598
- { case: raw.caseName, fields: raw.fields },
599
- formState.modifiedByUser,
719
+ { caseName: raw.caseName, fields: raw.fields },
720
+ formState.commonFormState.modifiedByUser,
600
721
  ]),
601
722
  );
602
723
  }
@@ -627,14 +748,14 @@ export const toAPIRawValue =
627
748
  return ValueOrErrors.Operations.Return(
628
749
  converters[t.value].toAPIRawValue([
629
750
  Sum.Default.left(rawValue),
630
- formState.modifiedByUser,
751
+ formState.commonFormState.modifiedByUser,
631
752
  ]),
632
753
  );
633
754
  } else {
634
755
  return ValueOrErrors.Operations.Return(
635
756
  converters[t.value].toAPIRawValue([
636
757
  Sum.Default.right("no selection"),
637
- formState.modifiedByUser,
758
+ formState.commonFormState.modifiedByUser,
638
759
  ]),
639
760
  );
640
761
  }
@@ -689,7 +810,7 @@ export const toAPIRawValue =
689
810
  })
690
811
  .toArray(),
691
812
  ),
692
- formState.modifiedByUser,
813
+ formState.commonFormState.modifiedByUser,
693
814
  ]),
694
815
  ),
695
816
  );
@@ -716,7 +837,7 @@ export const toAPIRawValue =
716
837
  ValueOrErrors.Default.return(
717
838
  converters["List"].toAPIRawValue([
718
839
  values,
719
- formState.modifiedByUser,
840
+ formState.commonFormState.modifiedByUser,
720
841
  ]),
721
842
  ),
722
843
  );
@@ -731,7 +852,7 @@ export const toAPIRawValue =
731
852
  injectedPrimitives,
732
853
  )(
733
854
  (keyValue as ValueTuple).values.get(0)!,
734
- formState.elementFormStates.get(index).KeyFormState.commonFormState,
855
+ formState.elementFormStates.get(index).KeyFormState,
735
856
  )
736
857
  .Then((possiblyUndefinedKey) => {
737
858
  if (
@@ -761,8 +882,7 @@ export const toAPIRawValue =
761
882
  injectedPrimitives,
762
883
  )(
763
884
  (keyValue as ValueTuple).values.get(1)!,
764
- formState.elementFormStates.get(index).ValueFormState
765
- .commonFormState,
885
+ formState.elementFormStates.get(index).ValueFormState,
766
886
  ).Then((value) =>
767
887
  ValueOrErrors.Default.return([key, value] as [any, any]),
768
888
  ),
@@ -783,6 +903,74 @@ export const toAPIRawValue =
783
903
  );
784
904
  });
785
905
  }
906
+
907
+ if (t.value === "Sum") {
908
+ if (!PredicateValue.Operations.IsSum(raw)) {
909
+ return ValueOrErrors.Default.throwOne(
910
+ `Sum expected but got ${JSON.stringify(raw)}`,
911
+ );
912
+ }
913
+
914
+ if (raw.value.kind === "l") {
915
+ return toAPIRawValue(
916
+ t.args[0],
917
+ types,
918
+ builtIns,
919
+ converters,
920
+ injectedPrimitives,
921
+ )(raw.value.value, formState.customFormState.left).Then((value) =>
922
+ ValueOrErrors.Default.return(
923
+ converters["Sum"].toAPIRawValue([
924
+ Sum.Default.left(value),
925
+ formState.commonFormState.modifiedByUser,
926
+ ]),
927
+ ),
928
+ );
929
+ }
930
+
931
+ return toAPIRawValue(
932
+ t.args[1],
933
+ types,
934
+ builtIns,
935
+ converters,
936
+ injectedPrimitives,
937
+ )(raw.value.value, formState.customFormState.right).Then((value) =>
938
+ ValueOrErrors.Default.return(
939
+ converters["Sum"].toAPIRawValue([
940
+ Sum.Default.right(value),
941
+ formState.commonFormState.modifiedByUser,
942
+ ]),
943
+ ),
944
+ );
945
+ }
946
+
947
+ if (t.value == "Tuple") {
948
+ if (!PredicateValue.Operations.IsTuple(raw)) {
949
+ return ValueOrErrors.Default.throwOne(
950
+ `Tuple expected but got ${JSON.stringify(raw)}`,
951
+ );
952
+ }
953
+ return ValueOrErrors.Operations.All(
954
+ List(
955
+ raw.values.map((value, index) => {
956
+ return toAPIRawValue(
957
+ t.args[index],
958
+ types,
959
+ builtIns,
960
+ converters,
961
+ injectedPrimitives,
962
+ )(value, formState.elementFormStates.get(index));
963
+ }),
964
+ ),
965
+ ).Then((values) =>
966
+ ValueOrErrors.Default.return(
967
+ converters["Tuple"].toAPIRawValue([
968
+ values,
969
+ formState.commonFormState.modifiedByUser,
970
+ ]),
971
+ ),
972
+ );
973
+ }
786
974
  }
787
975
 
788
976
  if (t.kind == "lookup")