@finos/legend-query-builder 0.4.2 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. package/lib/components/QueryBuilder.d.ts +0 -1
  2. package/lib/components/QueryBuilder.d.ts.map +1 -1
  3. package/lib/components/QueryBuilderDiffPanel.d.ts +0 -1
  4. package/lib/components/QueryBuilderDiffPanel.d.ts.map +1 -1
  5. package/lib/components/QueryBuilderNavigationBlocker.d.ts.map +1 -1
  6. package/lib/components/QueryBuilderNavigationBlocker.js +1 -1
  7. package/lib/components/QueryBuilderNavigationBlocker.js.map +1 -1
  8. package/lib/components/QueryBuilderParametersPanel.d.ts +0 -1
  9. package/lib/components/QueryBuilderParametersPanel.d.ts.map +1 -1
  10. package/lib/components/QueryBuilderParametersPanel.js +15 -19
  11. package/lib/components/QueryBuilderParametersPanel.js.map +1 -1
  12. package/lib/components/QueryBuilderPropertyExpressionEditor.d.ts +0 -1
  13. package/lib/components/QueryBuilderPropertyExpressionEditor.d.ts.map +1 -1
  14. package/lib/components/QueryBuilderResultPanel.d.ts +0 -1
  15. package/lib/components/QueryBuilderResultPanel.d.ts.map +1 -1
  16. package/lib/components/QueryBuilderSideBar.d.ts +0 -1
  17. package/lib/components/QueryBuilderSideBar.d.ts.map +1 -1
  18. package/lib/components/QueryBuilderTextEditor.d.ts +0 -1
  19. package/lib/components/QueryBuilderTextEditor.d.ts.map +1 -1
  20. package/lib/components/QueryBuilderUnsupportedQueryEditor.d.ts +0 -1
  21. package/lib/components/QueryBuilderUnsupportedQueryEditor.d.ts.map +1 -1
  22. package/lib/components/explorer/QueryBuilderFunctionsExplorerPanel.d.ts +0 -1
  23. package/lib/components/explorer/QueryBuilderFunctionsExplorerPanel.d.ts.map +1 -1
  24. package/lib/components/explorer/QueryBuilderMilestoningEditor.d.ts +0 -1
  25. package/lib/components/explorer/QueryBuilderMilestoningEditor.d.ts.map +1 -1
  26. package/lib/components/explorer/QueryBuilderPropertySearchPanel.d.ts +0 -1
  27. package/lib/components/explorer/QueryBuilderPropertySearchPanel.d.ts.map +1 -1
  28. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts +0 -1
  29. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts.map +1 -1
  30. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts +0 -1
  31. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts.map +1 -1
  32. package/lib/components/fetch-structure/QueryBuilderOLAPGroupByPanel_.d.ts +0 -1
  33. package/lib/components/fetch-structure/QueryBuilderOLAPGroupByPanel_.d.ts.map +1 -1
  34. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.d.ts +0 -1
  35. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.d.ts.map +1 -1
  36. package/lib/components/fetch-structure/QueryBuilderPostTDSPanel.d.ts +0 -1
  37. package/lib/components/fetch-structure/QueryBuilderPostTDSPanel.d.ts.map +1 -1
  38. package/lib/components/fetch-structure/QueryBuilderResultModifierPanel.d.ts +0 -1
  39. package/lib/components/fetch-structure/QueryBuilderResultModifierPanel.d.ts.map +1 -1
  40. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts +0 -1
  41. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts.map +1 -1
  42. package/lib/components/filter/QueryBuilderFilterPanel.d.ts +0 -1
  43. package/lib/components/filter/QueryBuilderFilterPanel.d.ts.map +1 -1
  44. package/lib/components/shared/LambdaEditor.d.ts +0 -1
  45. package/lib/components/shared/LambdaEditor.d.ts.map +1 -1
  46. package/lib/components/shared/LambdaParameterValuesEditor.d.ts +0 -1
  47. package/lib/components/shared/LambdaParameterValuesEditor.d.ts.map +1 -1
  48. package/lib/components/watermark/QueryBuilderWatermark.d.ts +0 -1
  49. package/lib/components/watermark/QueryBuilderWatermark.d.ts.map +1 -1
  50. package/lib/index.css +1 -1
  51. package/lib/package.json +6 -6
  52. package/lib/stores/QueryBuilderResultState.d.ts +1 -2
  53. package/lib/stores/QueryBuilderResultState.d.ts.map +1 -1
  54. package/lib/stores/QueryBuilderResultState.js +7 -12
  55. package/lib/stores/QueryBuilderResultState.js.map +1 -1
  56. package/lib/stores/QueryBuilderValueSpecificationBuilder.d.ts.map +1 -1
  57. package/lib/stores/QueryBuilderValueSpecificationBuilder.js +9 -4
  58. package/lib/stores/QueryBuilderValueSpecificationBuilder.js.map +1 -1
  59. package/lib/stores/QueryBuilderValueSpecificationBuilderHelper.d.ts +1 -1
  60. package/lib/stores/QueryBuilderValueSpecificationBuilderHelper.d.ts.map +1 -1
  61. package/lib/stores/QueryBuilderValueSpecificationBuilderHelper.js +6 -2
  62. package/lib/stores/QueryBuilderValueSpecificationBuilderHelper.js.map +1 -1
  63. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.d.ts.map +1 -1
  64. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js +2 -2
  65. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js.map +1 -1
  66. package/lib/stores/filter/operators/QueryBuilderFilterOperatorValueSpecificationBuilder.d.ts.map +1 -1
  67. package/lib/stores/filter/operators/QueryBuilderFilterOperatorValueSpecificationBuilder.js +2 -2
  68. package/lib/stores/filter/operators/QueryBuilderFilterOperatorValueSpecificationBuilder.js.map +1 -1
  69. package/lib/stores/shared/LambdaParameterState.d.ts +14 -2
  70. package/lib/stores/shared/LambdaParameterState.d.ts.map +1 -1
  71. package/lib/stores/shared/LambdaParameterState.js +79 -6
  72. package/lib/stores/shared/LambdaParameterState.js.map +1 -1
  73. package/package.json +13 -13
  74. package/src/components/QueryBuilderNavigationBlocker.tsx +4 -0
  75. package/src/components/QueryBuilderParametersPanel.tsx +32 -47
  76. package/src/stores/QueryBuilderResultState.ts +19 -17
  77. package/src/stores/QueryBuilderValueSpecificationBuilder.ts +14 -7
  78. package/src/stores/QueryBuilderValueSpecificationBuilderHelper.ts +7 -0
  79. package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.ts +2 -0
  80. package/src/stores/filter/operators/QueryBuilderFilterOperatorValueSpecificationBuilder.ts +2 -0
  81. package/src/stores/shared/LambdaParameterState.ts +151 -10
@@ -14,7 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { useState } from 'react';
18
17
  import { observer } from 'mobx-react-lite';
19
18
  import type { QueryBuilderState } from '../stores/QueryBuilderState.js';
20
19
  import {
@@ -40,11 +39,12 @@ import {
40
39
  } from '../stores/QueryBuilderParametersState.js';
41
40
  import {
42
41
  type Type,
43
- MULTIPLICITY_INFINITE,
44
42
  VariableExpression,
45
43
  GenericTypeExplicitReference,
46
44
  GenericType,
47
45
  PrimitiveType,
46
+ Multiplicity,
47
+ getMultiplicityPrettyDescription,
48
48
  } from '@finos/legend-graph';
49
49
  import {
50
50
  type PackageableElementOption,
@@ -59,6 +59,15 @@ import { variableExpression_setName } from '../stores/shared/ValueSpecificationM
59
59
  import { LambdaParameterState } from '../stores/shared/LambdaParameterState.js';
60
60
  import { LambdaParameterValuesEditor } from './shared/LambdaParameterValuesEditor.js';
61
61
 
62
+ type MultiplicityOption = { label: string; value: Multiplicity };
63
+
64
+ const buildMultiplicityOption = (
65
+ multiplicity: Multiplicity,
66
+ ): MultiplicityOption => ({
67
+ label: getMultiplicityPrettyDescription(multiplicity),
68
+ value: multiplicity,
69
+ });
70
+
62
71
  const VariableExpressionEditor = observer(
63
72
  (props: {
64
73
  queryBuilderState: QueryBuilderState;
@@ -89,6 +98,7 @@ const VariableExpressionEditor = observer(
89
98
  const variableType =
90
99
  lambdaParameterState.variableType ?? PrimitiveType.STRING;
91
100
  const selectedType = buildElementOption(variableType);
101
+ const selectedMultiplicity = buildMultiplicityOption(multiplity);
92
102
  const typeOptions: PackageableElementOption<Type>[] =
93
103
  queryBuilderState.graphManagerState.graph.primitiveTypes
94
104
  .map(buildElementOption)
@@ -104,38 +114,15 @@ const VariableExpressionEditor = observer(
104
114
  };
105
115
 
106
116
  // multiplicity
107
- const changeLowerBound: React.ChangeEventHandler<HTMLInputElement> = (
108
- event,
109
- ) => {
110
- lambdaParameterState.changeMultiplicity(
111
- varState,
112
- parseInt(event.target.value),
113
- multiplity.upperBound,
114
- );
115
- };
116
- const [upperBound, setUppBound] = useState<string>(
117
- multiplity.upperBound === undefined
118
- ? MULTIPLICITY_INFINITE
119
- : multiplity.upperBound.toString(),
120
- );
121
- const changeUpperBound: React.ChangeEventHandler<HTMLInputElement> = (
122
- event,
123
- ) => {
124
- const value = event.target.value;
125
- if (
126
- value === MULTIPLICITY_INFINITE ||
127
- value === '' ||
128
- !isNaN(parseInt(value, 10))
129
- ) {
130
- lambdaParameterState.changeMultiplicity(
131
- varState,
132
- multiplity.lowerBound,
133
- value === MULTIPLICITY_INFINITE || value === ''
134
- ? undefined
135
- : parseInt(value, 10),
136
- );
137
- setUppBound(value);
138
- }
117
+ const validParamMultiplicityList = [
118
+ Multiplicity.ONE,
119
+ Multiplicity.ZERO_ONE,
120
+ Multiplicity.ZERO_MANY,
121
+ ];
122
+ const multilicityOptions: MultiplicityOption[] =
123
+ validParamMultiplicityList.map(buildMultiplicityOption);
124
+ const changeMultiplicity = (val: MultiplicityOption): void => {
125
+ lambdaParameterState.changeMultiplicity(varState, val.value);
139
126
  };
140
127
 
141
128
  const close = (): void => {
@@ -202,19 +189,17 @@ const VariableExpressionEditor = observer(
202
189
  The multiplity determines how many values a parameter can have.
203
190
  Default is set to mandatory single vlue.
204
191
  </div>
205
- <input
206
- className="panel__content__form__section__input panel__content__form__section__number-input"
207
- type="number"
208
- spellCheck={false}
209
- value={multiplity.lowerBound}
210
- onChange={changeLowerBound}
211
- />
212
- ..
213
- <input
214
- className="panel__content__form__section__input panel__content__form__section__number-input"
215
- spellCheck={false}
216
- value={upperBound}
217
- onChange={changeUpperBound}
192
+ <CustomSelectorInput
193
+ placeholder="Choose a multiplicity..."
194
+ options={multilicityOptions}
195
+ onChange={changeMultiplicity}
196
+ value={selectedMultiplicity}
197
+ hasError={
198
+ !validParamMultiplicityList.includes(
199
+ selectedMultiplicity.value,
200
+ )
201
+ }
202
+ darkMode={!applicationStore.TEMPORARY__isLightThemeEnabled}
218
203
  />
219
204
  </div>
220
205
  </ModalBody>
@@ -35,10 +35,13 @@ import {
35
35
  EXECUTION_SERIALIZATION_FORMAT,
36
36
  RawExecutionResult,
37
37
  buildRawLambdaFromLambdaFunction,
38
- ParameterValue,
39
38
  } from '@finos/legend-graph';
40
39
  import { buildLambdaFunction } from './QueryBuilderValueSpecificationBuilder.js';
41
40
  import { ExecutionPlanState } from '@finos/legend-application';
41
+ import {
42
+ buildExecutionParameterValues,
43
+ getExecutionQueryFromRawLambda,
44
+ } from './shared/LambdaParameterState.js';
42
45
 
43
46
  const DEFAULT_LIMIT = 1000;
44
47
 
@@ -125,24 +128,17 @@ export class QueryBuilderResultState {
125
128
  this.queryBuilderState.unsupportedQueryState.rawLambda,
126
129
  'Lambda is required to execute query',
127
130
  );
131
+ if (!this.queryBuilderState.isParameterSupportDisabled) {
132
+ return getExecutionQueryFromRawLambda(
133
+ query,
134
+ this.queryBuilderState.parametersState.parameterStates,
135
+ this.queryBuilderState.graphManagerState,
136
+ );
137
+ }
128
138
  }
129
139
  return query;
130
140
  }
131
141
 
132
- buildExecutionParameterValues(): ParameterValue[] {
133
- return this.queryBuilderState.parametersState.parameterStates.map(
134
- (queryParamState) => {
135
- const paramValue = new ParameterValue();
136
- paramValue.name = queryParamState.parameter.name;
137
- paramValue.value =
138
- this.queryBuilderState.graphManagerState.graphManager.serializeValueSpecification(
139
- guaranteeNonNullable(queryParamState.value),
140
- );
141
- return paramValue;
142
- },
143
- );
144
- }
145
-
146
142
  *exportData(
147
143
  serializationFormat: EXECUTION_SERIALIZATION_FORMAT,
148
144
  ): GeneratorFn<void> {
@@ -165,6 +161,10 @@ export class QueryBuilderResultState {
165
161
  this.queryBuilderState.graphManagerState.graph,
166
162
  {
167
163
  serializationFormat,
164
+ parameterValues: buildExecutionParameterValues(
165
+ this.queryBuilderState.parametersState.parameterStates,
166
+ this.queryBuilderState.graphManagerState,
167
+ ),
168
168
  },
169
169
  )) as ExecutionResult;
170
170
  let contentType: ContentType;
@@ -210,7 +210,6 @@ export class QueryBuilderResultState {
210
210
  `Runtime is required to execute query`,
211
211
  );
212
212
  const query = this.buildExecutionRawLambda();
213
- const parameterValues = this.buildExecutionParameterValues();
214
213
  const startTime = Date.now();
215
214
  const promise =
216
215
  this.queryBuilderState.graphManagerState.graphManager.executeMapping(
@@ -219,7 +218,10 @@ export class QueryBuilderResultState {
219
218
  runtime,
220
219
  this.queryBuilderState.graphManagerState.graph,
221
220
  {
222
- parameterValues: parameterValues,
221
+ parameterValues: buildExecutionParameterValues(
222
+ this.queryBuilderState.parametersState.parameterStates,
223
+ this.queryBuilderState.graphManagerState,
224
+ ),
223
225
  },
224
226
  );
225
227
  this.setQueryRunPromise(promise);
@@ -36,6 +36,7 @@ import type { LambdaFunctionBuilderOption } from './QueryBuilderValueSpecificati
36
36
  import type { QueryBuilderFetchStructureState } from './fetch-structure/QueryBuilderFetchStructureState.js';
37
37
  import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../graphManager/QueryBuilderSupportedFunctions.js';
38
38
  import { buildWatermarkExpression } from './watermark/QueryBuilderWatermarkValueSpecificationBuilder.js';
39
+ import { buildExecutionQueryFromLambdaFunction } from './shared/LambdaParameterState.js';
39
40
 
40
41
  const buildGetAllFunction = (
41
42
  _class: Class,
@@ -155,13 +156,19 @@ export const buildLambdaFunction = (
155
156
  );
156
157
 
157
158
  // build parameters
158
- if (
159
- !queryBuilderState.isParameterSupportDisabled &&
160
- queryBuilderState.parametersState.parameterStates.length
161
- ) {
162
- lambdaFunction.functionType.parameters =
163
- queryBuilderState.parametersState.parameterStates.map((e) => e.parameter);
159
+ if (queryBuilderState.parametersState.parameterStates.length) {
160
+ if (options?.isBuildingExecutionQuery) {
161
+ buildExecutionQueryFromLambdaFunction(
162
+ lambdaFunction,
163
+ queryBuilderState.parametersState.parameterStates,
164
+ queryBuilderState.graphManagerState,
165
+ );
166
+ } else {
167
+ lambdaFunction.functionType.parameters =
168
+ queryBuilderState.parametersState.parameterStates.map(
169
+ (e) => e.parameter,
170
+ );
171
+ }
164
172
  }
165
-
166
173
  return lambdaFunction;
167
174
  };
@@ -23,6 +23,7 @@ import {
23
23
  matchFunctionName,
24
24
  MILESTONING_STEREOTYPE,
25
25
  SimpleFunctionExpression,
26
+ VariableExpression,
26
27
  type ValueSpecification,
27
28
  } from '@finos/legend-graph';
28
29
  import {
@@ -133,6 +134,7 @@ const isDefaultDatePropagationSupported = (
133
134
  export const buildPropertyExpressionChain = (
134
135
  propertyExpression: AbstractPropertyExpression,
135
136
  queryBuilderState: QueryBuilderState,
137
+ lambdaParameterName: string,
136
138
  /**
137
139
  * As of now, we don't support date propagation for aggregation-class functions
138
140
  * so we have this temporary flag to disable date propagation, there could be other
@@ -223,6 +225,11 @@ export const buildPropertyExpressionChain = (
223
225
  );
224
226
  }
225
227
  }
228
+
229
+ // Update the root lambda name based on the parent's lambda parameter name.
230
+ if (currentExpression instanceof VariableExpression) {
231
+ currentExpression.name = lambdaParameterName;
232
+ }
226
233
  return newPropertyExpression;
227
234
  };
228
235
 
@@ -225,6 +225,7 @@ export const appendProjection = (
225
225
  buildPropertyExpressionChain(
226
226
  projectionColumnState.propertyExpressionState.propertyExpression,
227
227
  projectionColumnState.propertyExpressionState.queryBuilderState,
228
+ projectionColumnState.lambdaParameterName,
228
229
  true,
229
230
  ),
230
231
  ],
@@ -325,6 +326,7 @@ export const appendProjection = (
325
326
  buildPropertyExpressionChain(
326
327
  projectionColumnState.propertyExpressionState.propertyExpression,
327
328
  projectionColumnState.propertyExpressionState.queryBuilderState,
329
+ projectionColumnState.lambdaParameterName,
328
330
  ),
329
331
  ],
330
332
  queryBuilderState.graphManagerState.graph,
@@ -78,6 +78,7 @@ const buildFilterConditionExpressionWithExists = (
78
78
  buildPropertyExpressionChain(
79
79
  filterConditionState.propertyExpressionState.propertyExpression,
80
80
  filterConditionState.propertyExpressionState.queryBuilderState,
81
+ filterConditionState.filterState.lambdaParameterName,
81
82
  );
82
83
  while (
83
84
  currentPropertyExpression instanceof AbstractPropertyExpression ||
@@ -225,6 +226,7 @@ export const buildFilterConditionExpression = (
225
226
  const propertyExpression = buildPropertyExpressionChain(
226
227
  filterConditionState.propertyExpressionState.propertyExpression,
227
228
  filterConditionState.propertyExpressionState.queryBuilderState,
229
+ filterConditionState.filterState.lambdaParameterName,
228
230
  );
229
231
  expression.parametersValues.push(guaranteeNonNullable(propertyExpression));
230
232
  // NOTE: there are simple operators which do not require any params (e.g. isEmpty)
@@ -19,11 +19,26 @@ import {
19
19
  type Type,
20
20
  type ValueSpecification,
21
21
  type PureModel,
22
+ type GraphManagerState,
23
+ type RawLambda,
22
24
  GenericType,
23
25
  GenericTypeExplicitReference,
24
26
  observe_ValueSpecification,
25
27
  observe_VariableExpression,
26
28
  VariableExpression,
29
+ SimpleFunctionExpression,
30
+ PackageableElementExplicitReference,
31
+ LambdaFunction,
32
+ FunctionType,
33
+ CORE_PURE_PATH,
34
+ extractElementNameFromPath,
35
+ Multiplicity,
36
+ PrimitiveInstanceValue,
37
+ PrimitiveType,
38
+ SUPPORTED_FUNCTIONS,
39
+ areMultiplicitiesEqual,
40
+ ParameterValue,
41
+ buildRawLambdaFromLambdaFunction,
27
42
  } from '@finos/legend-graph';
28
43
  import {
29
44
  addUniqueEntry,
@@ -32,6 +47,8 @@ import {
32
47
  hashArray,
33
48
  IllegalStateError,
34
49
  uuid,
50
+ isNonNullable,
51
+ guaranteeNonNullable,
35
52
  } from '@finos/legend-shared';
36
53
  import { makeObservable, observable, action, computed } from 'mobx';
37
54
  import { generateVariableExpressionMockValue } from './ValueSpecificationEditorHelper.js';
@@ -49,6 +66,137 @@ enum LAMABA_PARAMETER_HASH_STRUCTURE {
49
66
  LAMBDA_PARAMETER_STATE = 'LAMBDA_PARAMETER_STATE',
50
67
  LAMBDA_PARAMETERS_STATE = 'LAMBDA_PARAMETERS_STATE',
51
68
  }
69
+
70
+ export const buildParametersLetLambdaFunc = (
71
+ graph: PureModel,
72
+ lambdaParametersStates: LambdaParameterState[],
73
+ ): LambdaFunction => {
74
+ const letlambdaFunction = new LambdaFunction(
75
+ new FunctionType(
76
+ PackageableElementExplicitReference.create(
77
+ graph.getType(CORE_PURE_PATH.ANY),
78
+ ),
79
+ Multiplicity.ONE,
80
+ ),
81
+ );
82
+ letlambdaFunction.expressionSequence = lambdaParametersStates
83
+ .map((queryParamState) => {
84
+ if (queryParamState.value) {
85
+ const letFunc = new SimpleFunctionExpression(
86
+ extractElementNameFromPath(SUPPORTED_FUNCTIONS.LET),
87
+ );
88
+ const letVar = new PrimitiveInstanceValue(
89
+ GenericTypeExplicitReference.create(
90
+ new GenericType(PrimitiveType.STRING),
91
+ ),
92
+ );
93
+ letVar.values = [queryParamState.variableName];
94
+ letFunc.parametersValues.push(letVar);
95
+ letFunc.parametersValues.push(queryParamState.value);
96
+ return letFunc;
97
+ }
98
+ return undefined;
99
+ })
100
+ .filter(isNonNullable);
101
+ return letlambdaFunction;
102
+ };
103
+
104
+ /**
105
+ * For most query executions we will use the stragtical method of sending in `paramValues` as part of the execution input payload.
106
+ * However when the user wants to use a function value as the parameter value, engine does not understand this i.e for date param the functions `now()`, `today()`.
107
+ * Engine Does not support this because those functions require a building of execution nodes inside the execution plan.
108
+ * To continue supporting this execution flow , we will add let statements for parameter values with function values so that they can be evaluated to constants in the execution plan.
109
+ */
110
+ export const doesLambdaParameterStateContainFunctionValues = (
111
+ parameterState: LambdaParameterState,
112
+ ): boolean =>
113
+ parameterState.value instanceof SimpleFunctionExpression &&
114
+ [Multiplicity.ONE, Multiplicity.ZERO_ONE].some((p) =>
115
+ areMultiplicitiesEqual(p, parameterState.parameter.multiplicity),
116
+ );
117
+
118
+ export const getParameterStatesWithFunctionValues = (
119
+ parameterStates: LambdaParameterState[],
120
+ ): LambdaParameterState[] =>
121
+ parameterStates.filter(doesLambdaParameterStateContainFunctionValues);
122
+
123
+ export const buildExecutionParameterValues = (
124
+ paramStates: LambdaParameterState[],
125
+ graphState: GraphManagerState,
126
+ ): ParameterValue[] =>
127
+ paramStates
128
+ .filter((ps) => !doesLambdaParameterStateContainFunctionValues(ps))
129
+ .map((queryParamState) => {
130
+ const paramValue = new ParameterValue();
131
+ paramValue.name = queryParamState.parameter.name;
132
+ paramValue.value = graphState.graphManager.serializeValueSpecification(
133
+ guaranteeNonNullable(queryParamState.value),
134
+ );
135
+ return paramValue;
136
+ });
137
+
138
+ export const getExecutionQueryFromRawLambda = (
139
+ rawLambda: RawLambda,
140
+ parameterStates: LambdaParameterState[],
141
+ graphManagerState: GraphManagerState,
142
+ ): RawLambda => {
143
+ const paramsWithLetStatements =
144
+ getParameterStatesWithFunctionValues(parameterStates);
145
+ if (paramsWithLetStatements.length > 0) {
146
+ const execuLambdaFunction = buildParametersLetLambdaFunc(
147
+ graphManagerState.graph,
148
+ paramsWithLetStatements,
149
+ );
150
+ // remove parameters added as let statements from lambda parameters
151
+ execuLambdaFunction.functionType.parameters = parameterStates
152
+ .filter((ps) => !paramsWithLetStatements.includes(ps))
153
+ .map((e) => e.parameter);
154
+ const execQuery = buildRawLambdaFromLambdaFunction(
155
+ execuLambdaFunction,
156
+ graphManagerState,
157
+ );
158
+ // reset paramaters
159
+ if (Array.isArray(rawLambda.body) && Array.isArray(execQuery.body)) {
160
+ execQuery.body = [
161
+ ...(execQuery.body as object[]),
162
+ ...(rawLambda.body as object[]),
163
+ ];
164
+ return execQuery;
165
+ }
166
+ }
167
+ return rawLambda;
168
+ };
169
+
170
+ export const buildExecutionQueryFromLambdaFunction = (
171
+ lambdaFunction: LambdaFunction,
172
+ parameterStates: LambdaParameterState[],
173
+ graphManagerState: GraphManagerState,
174
+ ): LambdaFunction => {
175
+ const funcParameterStates =
176
+ getParameterStatesWithFunctionValues(parameterStates);
177
+ if (funcParameterStates.length) {
178
+ // To handle parameter value with function calls we
179
+ // 1. remove those parameters from parameter list
180
+ // 2. add let statements with parameter values
181
+ lambdaFunction.functionType.parameters = parameterStates
182
+ .filter((ps) => !funcParameterStates.includes(ps))
183
+ .map((e) => e.parameter);
184
+ const letsFuncs = buildParametersLetLambdaFunc(
185
+ graphManagerState.graph,
186
+ funcParameterStates,
187
+ );
188
+ lambdaFunction.expressionSequence = [
189
+ ...letsFuncs.expressionSequence,
190
+ ...lambdaFunction.expressionSequence,
191
+ ];
192
+ } else {
193
+ lambdaFunction.functionType.parameters = parameterStates.map(
194
+ (e) => e.parameter,
195
+ );
196
+ }
197
+ return lambdaFunction;
198
+ };
199
+
52
200
  export class LambdaParameterState implements Hashable {
53
201
  readonly uuid = uuid();
54
202
  readonly parameter: VariableExpression;
@@ -109,18 +257,11 @@ export class LambdaParameterState implements Hashable {
109
257
 
110
258
  changeMultiplicity(
111
259
  variableExpression: VariableExpression,
112
- lowerBound: number,
113
- uppderBound: number | undefined,
260
+ mul: Multiplicity,
114
261
  ): void {
115
262
  const current = this.parameter.multiplicity;
116
- if (
117
- current.lowerBound !== lowerBound ||
118
- current.upperBound !== uppderBound
119
- ) {
120
- valueSpecification_setMultiplicity(
121
- variableExpression,
122
- this.graph.getMultiplicity(lowerBound, uppderBound),
123
- );
263
+ if (!areMultiplicitiesEqual(current, mul)) {
264
+ valueSpecification_setMultiplicity(variableExpression, mul);
124
265
  this.mockParameterValue();
125
266
  }
126
267
  }