ballerina-core 1.0.190 → 1.0.192

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/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.190",
5
+ "version": "1.0.192",
6
6
  "main": "main.ts",
7
7
  "scripts": {
8
8
  "prettier": "prettier --write ."
@@ -8,6 +8,7 @@ import {
8
8
  DispatchOnChange,
9
9
  ListType,
10
10
  ValueCallbackWithOptionalFlags,
11
+ ValueUnit,
11
12
  VoidCallbackWithOptionalFlags,
12
13
  } from "../../../../../../../../main";
13
14
  import { Unit } from "../../../../../../../fun/domains/unit/state";
@@ -21,7 +22,7 @@ export type ListAbstractRendererReadonlyContext<
21
22
  ExtraContext,
22
23
  > = CommonAbstractRendererReadonlyContext<
23
24
  ListType<any>,
24
- ValueTuple,
25
+ ValueTuple | ValueUnit,
25
26
  CustomPresentationContext,
26
27
  ExtraContext
27
28
  >;
@@ -16,10 +16,7 @@ import {
16
16
  } from "../../../../../../../../main";
17
17
  import { Template } from "../../../../../../../template/state";
18
18
  import { ListMethods } from "../../../../deserializer/domains/specification/domains/forms/domains/renderer/domains/list/state";
19
- import {
20
- DispatchParsedType,
21
- StringSerializedType,
22
- } from "../../../../deserializer/domains/specification/domains/types/state";
19
+ import { DispatchParsedType } from "../../../../deserializer/domains/specification/domains/types/state";
23
20
  import {
24
21
  ListAbstractRendererForeignMutationsExpected,
25
22
  ListAbstractRendererReadonlyContext,
@@ -63,8 +60,9 @@ export const ListAbstractRenderer = <
63
60
  ) => ({
64
61
  disabled: _.disabled,
65
62
  locked: _.locked,
66
- value:
67
- _.value.values?.get(elementIndex) || GetDefaultElementValue(),
63
+ value: PredicateValue.Operations.IsUnit(_.value)
64
+ ? _.value
65
+ : _.value.values.get(elementIndex) || GetDefaultElementValue(),
68
66
  ...(_.elementFormStates?.get(elementIndex) ||
69
67
  GetDefaultElementState()),
70
68
  bindings: _.bindings,
@@ -154,15 +152,18 @@ export const ListAbstractRenderer = <
154
152
  >((props) => {
155
153
  const domNodeId = props.context.domNodeAncestorPath + "[list]";
156
154
 
157
- if (!PredicateValue.Operations.IsTuple(props.context.value)) {
155
+ if (
156
+ !PredicateValue.Operations.IsTuple(props.context.value) &&
157
+ !PredicateValue.Operations.IsUnit(props.context.value)
158
+ ) {
158
159
  console.error(
159
- `Tuple value expected but got: ${JSON.stringify(
160
+ `Tuple or unit value expected but got: ${JSON.stringify(
160
161
  props.context.value,
161
162
  )}\n...When rendering \n...${domNodeId}`,
162
163
  );
163
164
  return (
164
165
  <ErrorRenderer
165
- message={`${domNodeId}: Tuple value expected for list but got ${JSON.stringify(
166
+ message={`${domNodeId}: Tuple or unit value expected for list but got ${JSON.stringify(
166
167
  props.context.value,
167
168
  )}`}
168
169
  />
@@ -6,6 +6,7 @@ import {
6
6
  simpleUpdater,
7
7
  Template,
8
8
  Updater,
9
+ ValueUnit,
9
10
  ValueRecord,
10
11
  View,
11
12
  DispatchOnChange,
@@ -23,7 +24,7 @@ export type RecordAbstractRendererReadonlyContext<
23
24
  ExtraContext,
24
25
  > = CommonAbstractRendererReadonlyContext<
25
26
  RecordType<any>,
26
- ValueRecord,
27
+ ValueRecord | ValueUnit,
27
28
  CustomPresentationContext,
28
29
  ExtraContext
29
30
  >;
@@ -93,7 +93,9 @@ export const RecordAbstractRenderer = <
93
93
  > &
94
94
  RecordAbstractRendererState,
95
95
  ) => ({
96
- value: _.value.fields.get(fieldName)!,
96
+ value: PredicateValue.Operations.IsUnit(_.value)
97
+ ? _.value
98
+ : _.value.fields.get(fieldName)!,
97
99
  type: _.type.fields.get(fieldName)!,
98
100
  ...(_.fieldStates?.get(fieldName) ||
99
101
  FieldTemplates.get(fieldName)!.GetDefaultState()),
@@ -201,15 +203,18 @@ export const RecordAbstractRenderer = <
201
203
  >((props) => {
202
204
  const domNodeId = props.context.domNodeAncestorPath + "[record]";
203
205
 
204
- if (!PredicateValue.Operations.IsRecord(props.context.value)) {
206
+ if (
207
+ !PredicateValue.Operations.IsRecord(props.context.value) &&
208
+ !PredicateValue.Operations.IsUnit(props.context.value)
209
+ ) {
205
210
  console.error(
206
- `Record expected but got: ${JSON.stringify(
211
+ `Record or unit value expected but got: ${JSON.stringify(
207
212
  props.context.value,
208
213
  )}\n...When rendering \n...${domNodeId}`,
209
214
  );
210
215
  return (
211
216
  <ErrorRenderer
212
- message={`${domNodeId}: Record value expected but got ${JSON.stringify(
217
+ message={`${domNodeId}: Record or unit value expected but got ${JSON.stringify(
213
218
  props.context.value,
214
219
  )}`}
215
220
  />
@@ -504,9 +504,6 @@ export const TableAbstractRenderer = <
504
504
  .flatMap((_, column) => {
505
505
  const EmbeddedCell = EmbeddedCellTemplates.get(column);
506
506
  if (EmbeddedCell == undefined) {
507
- console.error(
508
- `Cannot find column ${column} in fields ${rowData.fields.keySeq().toArray()}, this is likely due to a mismatch between the data we are trying to parse and the specs.`,
509
- );
510
507
  return [];
511
508
  }
512
509
  return [
@@ -78,31 +78,77 @@ export const RendererTraversal = {
78
78
 
79
79
  if (
80
80
  renderer.kind == "lookupType-lookupRenderer" ||
81
- renderer.kind == "inlinedType-lookupRenderer" ||
82
- renderer.kind == "lookupType-inlinedRenderer"
81
+ renderer.kind == "lookupType-inlinedRenderer" ||
82
+ renderer.kind == "inlinedType-lookupRenderer"
83
83
  ) {
84
84
  if (
85
85
  renderer.kind == "lookupType-lookupRenderer" ||
86
- renderer.kind == "inlinedType-lookupRenderer"
86
+ renderer.kind == "lookupType-inlinedRenderer"
87
87
  ) {
88
- // renderer.renderer.renderer is the form name
89
- // this is a form lookup, so "local" changes here to the traversed value
90
88
  return LookupRenderer.Operations.ResolveRenderer(
91
89
  renderer,
92
90
  traversalContext.forms,
93
91
  ).Then((resolvedRenderer) =>
94
92
  rec(resolvedRenderer, traversalContext).Then(
95
93
  (valueTraversal: Option<ValueTraversal<T, Res>>) =>
96
- ValueOrErrors.Default.return(
97
- mapEvalContext((ctx) => ({
98
- ...ctx,
99
- local: ctx.traversalIterator,
100
- }))(valueTraversal),
101
- ),
94
+ ValueOrErrors.Default.return<
95
+ Option<ValueTraversal<T, Res>>,
96
+ string
97
+ >(
98
+ // reassign local if it's a lookup renderer
99
+ renderer.kind == "lookupType-lookupRenderer"
100
+ ? mapEvalContext((ctx) => ({
101
+ ...ctx,
102
+ local: ctx.traversalIterator,
103
+ }))(valueTraversal)
104
+ : valueTraversal,
105
+ ).Then((resolvedTraversal) => {
106
+ if (
107
+ traverseNode.kind == "l" &&
108
+ resolvedTraversal.kind == "l"
109
+ ) {
110
+ return ValueOrErrors.Default.return(Option.Default.none());
111
+ }
112
+
113
+ if (traverseNode.kind == "l") {
114
+ return ValueOrErrors.Default.return(resolvedTraversal);
115
+ }
116
+
117
+ if (resolvedTraversal.kind == "l") {
118
+ return ValueOrErrors.Default.return(
119
+ Option.Default.some((evalContext: EvalContext<T, Res>) =>
120
+ traverseNode
121
+ .value(evalContext)
122
+ .Then((nodeResult) =>
123
+ ValueOrErrors.Default.return(nodeResult),
124
+ ),
125
+ ),
126
+ );
127
+ }
128
+
129
+ return ValueOrErrors.Default.return(
130
+ Option.Default.some((evalContext: EvalContext<T, Res>) => {
131
+ return resolvedTraversal
132
+ .value(evalContext)
133
+ .Then((resolvedTraversal) =>
134
+ traverseNode
135
+ .value(evalContext)
136
+ .Then((nodeResult) =>
137
+ ValueOrErrors.Default.return<Res, string>(
138
+ traversalContext.joinRes([
139
+ nodeResult,
140
+ resolvedTraversal,
141
+ ]),
142
+ ),
143
+ ),
144
+ );
145
+ }),
146
+ );
147
+ }),
102
148
  ),
103
149
  );
104
150
  }
105
- // otherwise the form is inlined, so the local doesn't change
151
+
106
152
  return LookupRenderer.Operations.ResolveRenderer(
107
153
  renderer,
108
154
  traversalContext.forms,
@@ -113,6 +159,54 @@ export const RendererTraversal = {
113
159
  ),
114
160
  );
115
161
  }
162
+
163
+ if (
164
+ renderer.type.kind == "readOnly" &&
165
+ renderer.kind == "readOnlyRenderer"
166
+ ) {
167
+ return rec(renderer.childRenderer.renderer, traversalContext).Then(
168
+ (valueTraversal: Option<ValueTraversal<T, Res>>) => {
169
+ if (valueTraversal.kind == "l" && traverseNode.kind == "l") {
170
+ return ValueOrErrors.Default.return(Option.Default.none());
171
+ }
172
+ return ValueOrErrors.Default.return(
173
+ Option.Default.some((evalContext: EvalContext<T, Res>) => {
174
+ const iterator = evalContext.traversalIterator;
175
+ if (!PredicateValue.Operations.IsReadOnly(iterator)) {
176
+ return ValueOrErrors.Default.throwOne<Res, string>(
177
+ `Error: traversal iterator is not read only, got ${JSON.stringify(
178
+ iterator,
179
+ undefined,
180
+ 2,
181
+ )}`,
182
+ );
183
+ }
184
+ return (
185
+ valueTraversal.kind == "r"
186
+ ? valueTraversal.value({
187
+ ...evalContext,
188
+ traversalIterator: iterator.ReadOnly,
189
+ })
190
+ : ValueOrErrors.Default.return<Res, string>(
191
+ traversalContext.zeroRes(unit),
192
+ )
193
+ ).Then((valueResult) =>
194
+ traverseNode.kind == "r"
195
+ ? traverseNode
196
+ .value(evalContext)
197
+ .Then((nodeResult) =>
198
+ ValueOrErrors.Default.return(
199
+ traversalContext.joinRes([valueResult, nodeResult]),
200
+ ),
201
+ )
202
+ : ValueOrErrors.Default.return(valueResult),
203
+ );
204
+ }),
205
+ );
206
+ },
207
+ );
208
+ }
209
+
116
210
  if (renderer.type.kind == "record" && renderer.kind == "recordRenderer") {
117
211
  return ValueOrErrors.Operations.All(
118
212
  List(