@finos/legend-query-builder 4.6.0 → 4.7.0

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 (42) hide show
  1. package/lib/components/QueryBuilderConstantExpressionPanel.d.ts.map +1 -1
  2. package/lib/components/QueryBuilderConstantExpressionPanel.js +39 -9
  3. package/lib/components/QueryBuilderConstantExpressionPanel.js.map +1 -1
  4. package/lib/components/QueryBuilderParametersPanel.d.ts.map +1 -1
  5. package/lib/components/QueryBuilderParametersPanel.js.map +1 -1
  6. package/lib/components/shared/BasicValueSpecificationEditor.d.ts.map +1 -1
  7. package/lib/components/shared/BasicValueSpecificationEditor.js +1 -1
  8. package/lib/components/shared/BasicValueSpecificationEditor.js.map +1 -1
  9. package/lib/components/shared/LambdaEditor.d.ts +11 -0
  10. package/lib/components/shared/LambdaEditor.d.ts.map +1 -1
  11. package/lib/components/shared/LambdaEditor.js +3 -3
  12. package/lib/components/shared/LambdaEditor.js.map +1 -1
  13. package/lib/components/shared/QueryBuilderVariableSelector.d.ts +9 -2
  14. package/lib/components/shared/QueryBuilderVariableSelector.d.ts.map +1 -1
  15. package/lib/components/shared/QueryBuilderVariableSelector.js +39 -28
  16. package/lib/components/shared/QueryBuilderVariableSelector.js.map +1 -1
  17. package/lib/index.css +1 -17
  18. package/lib/index.css.map +1 -1
  19. package/lib/package.json +1 -1
  20. package/lib/stores/QueryBuilderConfig.d.ts +2 -1
  21. package/lib/stores/QueryBuilderConfig.d.ts.map +1 -1
  22. package/lib/stores/QueryBuilderConfig.js +1 -0
  23. package/lib/stores/QueryBuilderConfig.js.map +1 -1
  24. package/lib/stores/QueryBuilderConstantsState.d.ts +23 -6
  25. package/lib/stores/QueryBuilderConstantsState.d.ts.map +1 -1
  26. package/lib/stores/QueryBuilderConstantsState.js +96 -9
  27. package/lib/stores/QueryBuilderConstantsState.js.map +1 -1
  28. package/lib/stores/QueryBuilderStateBuilder.js +1 -1
  29. package/lib/stores/QueryBuilderStateBuilder.js.map +1 -1
  30. package/lib/stores/QueryBuilderValueSpecificationBuilder.d.ts.map +1 -1
  31. package/lib/stores/QueryBuilderValueSpecificationBuilder.js +14 -4
  32. package/lib/stores/QueryBuilderValueSpecificationBuilder.js.map +1 -1
  33. package/package.json +5 -5
  34. package/src/components/QueryBuilderConstantExpressionPanel.tsx +79 -6
  35. package/src/components/QueryBuilderParametersPanel.tsx +0 -1
  36. package/src/components/shared/BasicValueSpecificationEditor.tsx +3 -6
  37. package/src/components/shared/LambdaEditor.tsx +4 -2
  38. package/src/components/shared/QueryBuilderVariableSelector.tsx +191 -93
  39. package/src/stores/QueryBuilderConfig.ts +1 -0
  40. package/src/stores/QueryBuilderConstantsState.ts +146 -10
  41. package/src/stores/QueryBuilderStateBuilder.ts +1 -1
  42. package/src/stores/QueryBuilderValueSpecificationBuilder.ts +31 -3
@@ -17,11 +17,13 @@
17
17
  import {
18
18
  type Type,
19
19
  type ValueSpecification,
20
- type INTERNAL__UnknownValueSpecification,
21
20
  GenericType,
22
21
  GenericTypeExplicitReference,
23
22
  observe_ValueSpecification,
24
23
  VariableExpression,
24
+ buildSourceInformationSourceId,
25
+ ParserError,
26
+ GRAPH_MANAGER_EVENT,
25
27
  } from '@finos/legend-graph';
26
28
  import {
27
29
  type Hashable,
@@ -31,34 +33,40 @@ import {
31
33
  IllegalStateError,
32
34
  uuid,
33
35
  assertErrorThrown,
36
+ type GeneratorFn,
37
+ type PlainObject,
38
+ LogEvent,
39
+ changeEntry,
40
+ assertTrue,
34
41
  } from '@finos/legend-shared';
35
42
  import { action, makeObservable, observable } from 'mobx';
36
43
  import { QUERY_BUILDER_STATE_HASH_STRUCTURE } from './QueryBuilderStateHashUtils.js';
37
44
  import type { QueryBuilderState } from './QueryBuilderState.js';
38
- import { buildDefaultInstanceValue } from './shared/ValueSpecificationEditorHelper.js';
45
+ import {
46
+ buildDefaultEmptyStringRawLambda,
47
+ buildDefaultInstanceValue,
48
+ } from './shared/ValueSpecificationEditorHelper.js';
39
49
  import { valueSpecification_setGenericType } from './shared/ValueSpecificationModifierHelper.js';
50
+ import { LambdaEditorState } from './shared/LambdaEditorState.js';
51
+ import { QUERY_BUILDER_SOURCE_ID_LABEL } from './QueryBuilderConfig.js';
40
52
 
41
53
  export abstract class QueryBuilderConstantExpressionState implements Hashable {
42
54
  readonly queryBuilderState: QueryBuilderState;
43
55
  readonly uuid = uuid();
44
56
  variable: VariableExpression;
45
- value: ValueSpecification;
46
57
 
47
58
  constructor(
48
59
  queryBuilderState: QueryBuilderState,
49
60
  variable: VariableExpression,
50
- value: ValueSpecification,
51
61
  ) {
52
62
  this.queryBuilderState = queryBuilderState;
53
63
  this.variable = variable;
54
- this.value = value;
55
64
  }
56
65
 
57
66
  get hashCode(): string {
58
67
  return hashArray([
59
68
  QUERY_BUILDER_STATE_HASH_STRUCTURE.CONSTANT_EXPRESSION_STATE,
60
69
  this.variable.name,
61
- this.value,
62
70
  ]);
63
71
  }
64
72
  }
@@ -67,12 +75,14 @@ export class QueryBuilderSimpleConstantExpressionState
67
75
  extends QueryBuilderConstantExpressionState
68
76
  implements Hashable
69
77
  {
78
+ value: ValueSpecification;
79
+
70
80
  constructor(
71
81
  queryBuilderState: QueryBuilderState,
72
82
  variable: VariableExpression,
73
83
  value: ValueSpecification,
74
84
  ) {
75
- super(queryBuilderState, variable, value);
85
+ super(queryBuilderState, variable);
76
86
  makeObservable(this, {
77
87
  variable: observable,
78
88
  value: observable,
@@ -129,24 +139,126 @@ export class QueryBuilderSimpleConstantExpressionState
129
139
  );
130
140
  }
131
141
  }
142
+
143
+ override get hashCode(): string {
144
+ return hashArray([
145
+ QUERY_BUILDER_STATE_HASH_STRUCTURE.CONSTANT_EXPRESSION_STATE,
146
+ this.variable.name,
147
+ this.value,
148
+ ]);
149
+ }
150
+ }
151
+
152
+ export class QueryBuilderConstantLambdaEditorState extends LambdaEditorState {
153
+ readonly queryBuilderState: QueryBuilderState;
154
+ calculatedState: QueryBuilderCalculatedConstantExpressionState;
155
+ constructor(calculatedState: QueryBuilderCalculatedConstantExpressionState) {
156
+ super('', '');
157
+ makeObservable(this, {
158
+ calculatedState: observable,
159
+ buildEmptyValueSpec: observable,
160
+ });
161
+ this.calculatedState = calculatedState;
162
+ this.queryBuilderState = calculatedState.queryBuilderState;
163
+ }
164
+
165
+ buildEmptyValueSpec(): PlainObject {
166
+ return this.queryBuilderState.graphManagerState.graphManager.serializeRawValueSpecification(
167
+ buildDefaultEmptyStringRawLambda(
168
+ this.queryBuilderState.graphManagerState,
169
+ this.queryBuilderState.observerContext,
170
+ ),
171
+ );
172
+ }
173
+
174
+ get lambdaId(): string {
175
+ return buildSourceInformationSourceId([
176
+ // TODO: to be reworked
177
+ // See https://github.com/finos/legend-studio/issues/1168
178
+ QUERY_BUILDER_SOURCE_ID_LABEL.QUERY_BUILDER,
179
+ QUERY_BUILDER_SOURCE_ID_LABEL.CONSTANT,
180
+ this.calculatedState.uuid,
181
+ ]);
182
+ }
183
+
184
+ override *convertLambdaGrammarStringToObject(): GeneratorFn<void> {
185
+ if (this.lambdaString) {
186
+ try {
187
+ const valSpec =
188
+ (yield this.queryBuilderState.graphManagerState.graphManager.pureCodeToValueSpecification(
189
+ this.fullLambdaString,
190
+ )) as PlainObject<ValueSpecification>;
191
+ this.setParserError(undefined);
192
+ this.calculatedState.setValue(valSpec);
193
+ } catch (error) {
194
+ assertErrorThrown(error);
195
+ if (error instanceof ParserError) {
196
+ this.setParserError(error);
197
+ }
198
+ this.queryBuilderState.applicationStore.logService.error(
199
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
200
+ error,
201
+ );
202
+ }
203
+ } else {
204
+ this.clearErrors();
205
+ this.calculatedState.setValue(this.buildEmptyValueSpec());
206
+ }
207
+ }
208
+ override *convertLambdaObjectToGrammarString(
209
+ options?:
210
+ | {
211
+ pretty?: boolean | undefined;
212
+ preserveCompilationError?: boolean | undefined;
213
+ }
214
+ | undefined,
215
+ ): GeneratorFn<void> {
216
+ try {
217
+ const value = this.calculatedState.value;
218
+ const grammarText =
219
+ (yield this.queryBuilderState.graphManagerState.graphManager.valueSpecificationToPureCode(
220
+ value,
221
+ options?.pretty,
222
+ )) as string;
223
+ this.setLambdaString(grammarText);
224
+ this.clearErrors({
225
+ preserveCompilationError: options?.preserveCompilationError,
226
+ });
227
+ } catch (error) {
228
+ assertErrorThrown(error);
229
+ this.queryBuilderState.applicationStore.logService.error(
230
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
231
+ error,
232
+ );
233
+ }
234
+ }
132
235
  }
133
236
 
134
237
  export class QueryBuilderCalculatedConstantExpressionState
135
238
  extends QueryBuilderConstantExpressionState
136
239
  implements Hashable
137
240
  {
138
- declare value: INTERNAL__UnknownValueSpecification;
241
+ value: PlainObject;
242
+ lambdaState: QueryBuilderConstantLambdaEditorState;
139
243
 
140
244
  constructor(
141
245
  queryBuilderState: QueryBuilderState,
142
246
  variable: VariableExpression,
143
- value: INTERNAL__UnknownValueSpecification,
247
+ value: PlainObject,
144
248
  ) {
145
- super(queryBuilderState, variable, value);
249
+ super(queryBuilderState, variable);
146
250
  makeObservable(this, {
147
251
  variable: observable,
252
+ lambdaState: observable,
148
253
  value: observable,
254
+ setValue: action,
149
255
  });
256
+ this.value = value;
257
+ this.lambdaState = new QueryBuilderConstantLambdaEditorState(this);
258
+ }
259
+
260
+ setValue(val: PlainObject): void {
261
+ this.value = val;
150
262
  }
151
263
  }
152
264
 
@@ -167,6 +279,7 @@ export class QueryBuilderConstantsState implements Hashable {
167
279
  removeConstant: action,
168
280
  setShowConstantPanel: action,
169
281
  setSelectedConstant: action,
282
+ convertToCalculated: action,
170
283
  });
171
284
  }
172
285
 
@@ -201,6 +314,29 @@ export class QueryBuilderConstantsState implements Hashable {
201
314
  return false;
202
315
  }
203
316
 
317
+ convertToCalculated(val: QueryBuilderSimpleConstantExpressionState): void {
318
+ try {
319
+ const content =
320
+ this.queryBuilderState.graphManagerState.graphManager.serializeValueSpecification(
321
+ val.value,
322
+ );
323
+ const constantState = new QueryBuilderCalculatedConstantExpressionState(
324
+ this.queryBuilderState,
325
+ val.variable,
326
+ content,
327
+ );
328
+ assertTrue(
329
+ changeEntry(this.constants, val, constantState),
330
+ 'Unable to convert to calculated constant',
331
+ );
332
+ } catch (error) {
333
+ assertErrorThrown(error);
334
+ this.queryBuilderState.applicationStore.notificationService.notifyError(
335
+ error,
336
+ );
337
+ }
338
+ }
339
+
204
340
  get hashCode(): string {
205
341
  return hashArray([
206
342
  QUERY_BUILDER_STATE_HASH_STRUCTURE.CONSTANT_STATE,
@@ -152,7 +152,7 @@ const processLetExpression = (
152
152
  constantExpression = new QueryBuilderCalculatedConstantExpressionState(
153
153
  queryBuilderState,
154
154
  varExp,
155
- rightSide,
155
+ rightSide.content,
156
156
  );
157
157
  } else {
158
158
  constantExpression = new QueryBuilderSimpleConstantExpressionState(
@@ -14,9 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { guaranteeNonNullable, guaranteeType } from '@finos/legend-shared';
17
+ import {
18
+ UnsupportedOperationError,
19
+ guaranteeNonNullable,
20
+ guaranteeType,
21
+ } from '@finos/legend-shared';
18
22
  import {
19
23
  type Class,
24
+ type ValueSpecification,
20
25
  Multiplicity,
21
26
  getMilestoneTemporalStereotype,
22
27
  extractElementNameFromPath,
@@ -32,6 +37,7 @@ import {
32
37
  PrimitiveType,
33
38
  SUPPORTED_FUNCTIONS,
34
39
  RuntimePointer,
40
+ INTERNAL__UnknownValueSpecification,
35
41
  } from '@finos/legend-graph';
36
42
  import type { QueryBuilderState } from './QueryBuilderState.js';
37
43
  import { buildFilterExpression } from './filter/QueryBuilderFilterValueSpecificationBuilder.js';
@@ -40,7 +46,11 @@ import type { QueryBuilderFetchStructureState } from './fetch-structure/QueryBui
40
46
  import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../graph/QueryBuilderMetaModelConst.js';
41
47
  import { buildWatermarkExpression } from './watermark/QueryBuilderWatermarkValueSpecificationBuilder.js';
42
48
  import { buildExecutionQueryFromLambdaFunction } from './shared/LambdaParameterState.js';
43
- import { type QueryBuilderConstantExpressionState } from './QueryBuilderConstantsState.js';
49
+ import {
50
+ QueryBuilderSimpleConstantExpressionState,
51
+ type QueryBuilderConstantExpressionState,
52
+ QueryBuilderCalculatedConstantExpressionState,
53
+ } from './QueryBuilderConstantsState.js';
44
54
  import {
45
55
  QueryBuilderEmbeddedFromExecutionContextState,
46
56
  type QueryBuilderExecutionContextState,
@@ -84,7 +94,6 @@ const buildLetExpression = (
84
94
  constantExpressionState: QueryBuilderConstantExpressionState,
85
95
  ): SimpleFunctionExpression => {
86
96
  const varName = constantExpressionState.variable.name;
87
- const value = constantExpressionState.value;
88
97
  const leftSide = new PrimitiveInstanceValue(
89
98
  GenericTypeExplicitReference.create(new GenericType(PrimitiveType.STRING)),
90
99
  );
@@ -92,6 +101,25 @@ const buildLetExpression = (
92
101
  const letFunc = new SimpleFunctionExpression(
93
102
  extractElementNameFromPath(SUPPORTED_FUNCTIONS.LET),
94
103
  );
104
+ let value: ValueSpecification;
105
+ if (
106
+ constantExpressionState instanceof QueryBuilderSimpleConstantExpressionState
107
+ ) {
108
+ value = constantExpressionState.value;
109
+ } else if (
110
+ constantExpressionState instanceof
111
+ QueryBuilderCalculatedConstantExpressionState
112
+ ) {
113
+ value = new INTERNAL__UnknownValueSpecification(
114
+ constantExpressionState.value,
115
+ );
116
+ } else {
117
+ throw new UnsupportedOperationError(
118
+ `Can't build let() expression: unsupported constant state`,
119
+ constantExpressionState,
120
+ );
121
+ }
122
+
95
123
  letFunc.parametersValues = [leftSide, value];
96
124
  return letFunc;
97
125
  };