@finos/legend-query-builder 1.0.6 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/application/QueryBuilderEvent.d.ts +7 -7
- package/lib/application/QueryBuilderEvent.d.ts.map +1 -1
- package/lib/application/QueryBuilderEvent.js +7 -7
- package/lib/application/QueryBuilderEvent.js.map +1 -1
- package/lib/components/QueryBuilder.js +1 -1
- package/lib/components/QueryBuilder.js.map +1 -1
- package/lib/components/QueryBuilderResultPanel.d.ts.map +1 -1
- package/lib/components/QueryBuilderResultPanel.js +13 -2
- package/lib/components/QueryBuilderResultPanel.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js +2 -2
- package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts +3 -2
- package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.js +53 -13
- package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.d.ts.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js +3 -2
- package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js.map +1 -1
- package/lib/graphManager/QueryBuilderSupportedFunctions.d.ts +1 -0
- package/lib/graphManager/QueryBuilderSupportedFunctions.d.ts.map +1 -1
- package/lib/graphManager/QueryBuilderSupportedFunctions.js +1 -0
- package/lib/graphManager/QueryBuilderSupportedFunctions.js.map +1 -1
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/package.json +7 -7
- package/lib/stores/QueryBuilderStateBuilder.d.ts +2 -1
- package/lib/stores/QueryBuilderStateBuilder.d.ts.map +1 -1
- package/lib/stores/QueryBuilderStateBuilder.js +8 -1
- package/lib/stores/QueryBuilderStateBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts +1 -0
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.js.map +1 -1
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.js +3 -2
- package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.js.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts +49 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js +126 -0
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.d.ts +1 -0
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.d.ts.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.js +85 -4
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.d.ts +3 -2
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.d.ts.map +1 -1
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.js +96 -14
- package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts +1 -0
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +6 -0
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
- package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts +1 -0
- package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js +10 -1
- package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js.map +1 -1
- package/package.json +14 -14
- package/src/application/QueryBuilderEvent.ts +7 -7
- package/src/components/QueryBuilder.tsx +1 -1
- package/src/components/QueryBuilderResultPanel.tsx +16 -1
- package/src/components/fetch-structure/QueryBuilderFetchStructurePanel.tsx +2 -2
- package/src/components/fetch-structure/QueryBuilderGraphFetchTreePanel.tsx +240 -5
- package/src/components/fetch-structure/QueryBuilderTDSWindowPanel.tsx +8 -5
- package/src/graphManager/QueryBuilderSupportedFunctions.ts +1 -0
- package/src/stores/QueryBuilderStateBuilder.ts +20 -0
- package/src/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.ts +2 -0
- package/src/stores/fetch-structure/QueryBuilderFetchStructureState.ts +3 -2
- package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.ts +158 -0
- package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.ts +258 -4
- package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.ts +166 -24
- package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +7 -0
- package/src/stores/fetch-structure/tds/window/QueryBuilderWindowState.ts +14 -1
@@ -15,20 +15,37 @@
|
|
15
15
|
*/
|
16
16
|
|
17
17
|
import {
|
18
|
+
type ValueSpecification,
|
19
|
+
type LambdaFunction,
|
20
|
+
type PureModel,
|
18
21
|
extractElementNameFromPath,
|
19
22
|
GenericType,
|
20
23
|
GenericTypeExplicitReference,
|
21
24
|
matchFunctionName,
|
22
25
|
PrimitiveInstanceValue,
|
23
26
|
SimpleFunctionExpression,
|
24
|
-
type ValueSpecification,
|
25
|
-
type LambdaFunction,
|
26
27
|
GraphFetchTreeInstanceValue,
|
27
28
|
PrimitiveType,
|
29
|
+
InstanceValue,
|
30
|
+
Multiplicity,
|
31
|
+
PackageableElementExplicitReference,
|
32
|
+
SUPPORTED_FUNCTIONS,
|
33
|
+
PURE_SERIALIZE_CONFIG_CLASS,
|
34
|
+
CollectionInstanceValue,
|
35
|
+
KeyExpressionInstanceValue,
|
36
|
+
KeyExpression,
|
28
37
|
} from '@finos/legend-graph';
|
29
|
-
import {
|
38
|
+
import {
|
39
|
+
UnsupportedOperationError,
|
40
|
+
guaranteeNonNullable,
|
41
|
+
guaranteeType,
|
42
|
+
} from '@finos/legend-shared';
|
30
43
|
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../graphManager/QueryBuilderSupportedFunctions.js';
|
31
|
-
import
|
44
|
+
import {
|
45
|
+
GraphFetchExternalFormatSerializationState,
|
46
|
+
GraphFetchPureSerializationState,
|
47
|
+
type QueryBuilderGraphFetchTreeState,
|
48
|
+
} from './QueryBuilderGraphFetchTreeState.js';
|
32
49
|
import { isGraphFetchTreeDataEmpty } from './QueryBuilderGraphFetchTreeUtil.js';
|
33
50
|
|
34
51
|
const appendTakeLimit = (
|
@@ -79,6 +96,67 @@ const appendTakeLimit = (
|
|
79
96
|
return lambda;
|
80
97
|
};
|
81
98
|
|
99
|
+
export const buildPureSerializationConfig = (
|
100
|
+
config: Record<PropertyKey, boolean>,
|
101
|
+
graph: PureModel,
|
102
|
+
): SimpleFunctionExpression => {
|
103
|
+
const configClass = graph.getClass(PURE_SERIALIZE_CONFIG_CLASS);
|
104
|
+
const newFunction = new SimpleFunctionExpression(
|
105
|
+
extractElementNameFromPath(SUPPORTED_FUNCTIONS.NEW),
|
106
|
+
);
|
107
|
+
// build instance
|
108
|
+
const instance = new InstanceValue(Multiplicity.ONE, undefined);
|
109
|
+
instance.values[0] = PackageableElementExplicitReference.create(configClass);
|
110
|
+
// build values
|
111
|
+
const primitiveInstance = new PrimitiveInstanceValue(
|
112
|
+
GenericTypeExplicitReference.create(new GenericType(PrimitiveType.STRING)),
|
113
|
+
);
|
114
|
+
primitiveInstance.values = [''];
|
115
|
+
const pureConfigCollection = new CollectionInstanceValue(
|
116
|
+
Multiplicity.ONE,
|
117
|
+
undefined,
|
118
|
+
);
|
119
|
+
configClass.properties.forEach((classProperty) => {
|
120
|
+
const property = Object.getOwnPropertyNames(config).find(
|
121
|
+
(p) => p === classProperty.name,
|
122
|
+
);
|
123
|
+
if (property) {
|
124
|
+
const keyExpressionInstance = new KeyExpressionInstanceValue();
|
125
|
+
// key expression
|
126
|
+
const keyInstance = new PrimitiveInstanceValue(
|
127
|
+
GenericTypeExplicitReference.create(
|
128
|
+
new GenericType(PrimitiveType.STRING),
|
129
|
+
),
|
130
|
+
);
|
131
|
+
keyInstance.values = [property];
|
132
|
+
// primitive
|
133
|
+
const keyPrimitiveInstance = new PrimitiveInstanceValue(
|
134
|
+
GenericTypeExplicitReference.create(
|
135
|
+
new GenericType(classProperty.genericType.value.rawType),
|
136
|
+
),
|
137
|
+
);
|
138
|
+
keyPrimitiveInstance.values = [config[property]];
|
139
|
+
const keyExpression = new KeyExpression(
|
140
|
+
keyInstance,
|
141
|
+
keyPrimitiveInstance,
|
142
|
+
false,
|
143
|
+
);
|
144
|
+
keyExpressionInstance.values = [keyExpression];
|
145
|
+
pureConfigCollection.values.push(keyExpressionInstance);
|
146
|
+
}
|
147
|
+
});
|
148
|
+
pureConfigCollection.multiplicity = new Multiplicity(
|
149
|
+
pureConfigCollection.values.length,
|
150
|
+
pureConfigCollection.values.length,
|
151
|
+
);
|
152
|
+
newFunction.parametersValues = [
|
153
|
+
instance,
|
154
|
+
primitiveInstance,
|
155
|
+
pureConfigCollection,
|
156
|
+
];
|
157
|
+
return newFunction;
|
158
|
+
};
|
159
|
+
|
82
160
|
export const appendGraphFetch = (
|
83
161
|
graphFetchTreeState: QueryBuilderGraphFetchTreeState,
|
84
162
|
lambdaFunction: LambdaFunction,
|
@@ -97,30 +175,94 @@ export const appendGraphFetch = (
|
|
97
175
|
`Can't build graph-fetch tree expression: preceding expression is not defined`,
|
98
176
|
);
|
99
177
|
|
100
|
-
|
101
|
-
if (
|
102
|
-
|
103
|
-
|
178
|
+
const seriaizationState = graphFetchTreeState.serializationState;
|
179
|
+
if (seriaizationState instanceof GraphFetchPureSerializationState) {
|
180
|
+
// build graph-fetch tree
|
181
|
+
if (
|
182
|
+
graphFetchTreeState.treeData &&
|
183
|
+
!isGraphFetchTreeDataEmpty(graphFetchTreeState.treeData)
|
184
|
+
) {
|
185
|
+
const graphFetchInstance = new GraphFetchTreeInstanceValue();
|
186
|
+
graphFetchInstance.values = [graphFetchTreeState.treeData.tree];
|
187
|
+
const serializeFunction = new SimpleFunctionExpression(
|
188
|
+
extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.SERIALIZE),
|
189
|
+
);
|
190
|
+
const graphFetchFunc = new SimpleFunctionExpression(
|
191
|
+
graphFetchTreeState.isChecked
|
192
|
+
? extractElementNameFromPath(
|
193
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH_CHECKED,
|
194
|
+
)
|
195
|
+
: extractElementNameFromPath(
|
196
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH,
|
197
|
+
),
|
198
|
+
);
|
199
|
+
graphFetchFunc.parametersValues = [
|
200
|
+
precedingExpression,
|
201
|
+
graphFetchInstance,
|
202
|
+
];
|
203
|
+
serializeFunction.parametersValues = [graphFetchFunc, graphFetchInstance];
|
204
|
+
if (seriaizationState.config) {
|
205
|
+
const configFunction = buildPureSerializationConfig(
|
206
|
+
seriaizationState.config as unknown as Record<PropertyKey, boolean>,
|
207
|
+
graphFetchTreeState.queryBuilderState.graphManagerState.graph,
|
208
|
+
);
|
209
|
+
serializeFunction.parametersValues.push(configFunction);
|
210
|
+
}
|
211
|
+
lambdaFunction.expressionSequence[0] = serializeFunction;
|
212
|
+
}
|
213
|
+
} else if (
|
214
|
+
seriaizationState instanceof GraphFetchExternalFormatSerializationState
|
104
215
|
) {
|
105
|
-
const
|
106
|
-
|
107
|
-
const serializeFunction = new SimpleFunctionExpression(
|
108
|
-
extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.SERIALIZE),
|
216
|
+
const externalizeFunction = new SimpleFunctionExpression(
|
217
|
+
extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.EXTERNALIZE),
|
109
218
|
);
|
110
|
-
const
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
219
|
+
const mainGraphTree = graphFetchTreeState.treeData;
|
220
|
+
const externalizeTree = seriaizationState.treeData;
|
221
|
+
if (
|
222
|
+
mainGraphTree &&
|
223
|
+
externalizeTree &&
|
224
|
+
!isGraphFetchTreeDataEmpty(mainGraphTree) &&
|
225
|
+
!isGraphFetchTreeDataEmpty(externalizeTree)
|
226
|
+
) {
|
227
|
+
// 0th param
|
228
|
+
const graphFetchInstance = new GraphFetchTreeInstanceValue();
|
229
|
+
graphFetchInstance.values = [mainGraphTree.tree];
|
230
|
+
const graphFetchFunc = new SimpleFunctionExpression(
|
231
|
+
graphFetchTreeState.isChecked
|
232
|
+
? extractElementNameFromPath(
|
233
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH_CHECKED,
|
234
|
+
)
|
235
|
+
: extractElementNameFromPath(
|
236
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH,
|
237
|
+
),
|
238
|
+
);
|
239
|
+
graphFetchFunc.parametersValues = [
|
240
|
+
precedingExpression,
|
241
|
+
graphFetchInstance,
|
242
|
+
];
|
243
|
+
// 1st param
|
244
|
+
const bindingInstance = new InstanceValue(Multiplicity.ONE, undefined);
|
245
|
+
bindingInstance.values = [
|
246
|
+
PackageableElementExplicitReference.create(
|
247
|
+
seriaizationState.targetBinding,
|
248
|
+
),
|
249
|
+
];
|
250
|
+
// 2nd parameter
|
251
|
+
const xtGraphFetchInstance = new GraphFetchTreeInstanceValue();
|
252
|
+
xtGraphFetchInstance.values = [externalizeTree.tree];
|
253
|
+
// build externalize
|
254
|
+
externalizeFunction.parametersValues = [
|
255
|
+
graphFetchFunc,
|
256
|
+
bindingInstance,
|
257
|
+
xtGraphFetchInstance,
|
258
|
+
];
|
259
|
+
lambdaFunction.expressionSequence[0] = externalizeFunction;
|
260
|
+
}
|
261
|
+
} else {
|
262
|
+
throw new UnsupportedOperationError(
|
263
|
+
`Unsupported serialization state ${seriaizationState.getLabel()}`,
|
118
264
|
);
|
119
|
-
graphFetchFunc.parametersValues = [precedingExpression, graphFetchInstance];
|
120
|
-
serializeFunction.parametersValues = [graphFetchFunc, graphFetchInstance];
|
121
|
-
lambdaFunction.expressionSequence[0] = serializeFunction;
|
122
265
|
}
|
123
|
-
|
124
266
|
// build result set modifier: i.e. preview limit
|
125
267
|
if (options?.isBuildingExecutionQuery) {
|
126
268
|
appendTakeLimit(lambdaFunction, queryBuilderState.resultState.previewLimit);
|
@@ -135,6 +135,7 @@ export class QueryBuilderTDSState
|
|
135
135
|
addColumn: action,
|
136
136
|
moveColumn: action,
|
137
137
|
replaceColumn: action,
|
138
|
+
initialize: action,
|
138
139
|
setShowPostFilterPanel: action,
|
139
140
|
setShowWindowFuncPanel: action,
|
140
141
|
convertDerivationProjectionObjects: flow,
|
@@ -294,6 +295,12 @@ export class QueryBuilderTDSState
|
|
294
295
|
);
|
295
296
|
}
|
296
297
|
|
298
|
+
override initialize(): void {
|
299
|
+
this.queryBuilderState.filterState.setShowPanel(true);
|
300
|
+
this.setShowPostFilterPanel(false);
|
301
|
+
this.setShowWindowFuncPanel(false);
|
302
|
+
}
|
303
|
+
|
297
304
|
isColumnInUse(tdsCol: QueryBuilderTDSColumnState): boolean {
|
298
305
|
return Boolean(
|
299
306
|
[
|
@@ -23,7 +23,7 @@ import {
|
|
23
23
|
uniq,
|
24
24
|
type Hashable,
|
25
25
|
} from '@finos/legend-shared';
|
26
|
-
import { action, makeObservable, observable } from 'mobx';
|
26
|
+
import { action, computed, makeObservable, observable } from 'mobx';
|
27
27
|
import { QUERY_BUILDER_HASH_STRUCTURE } from '../../../../graphManager/QueryBuilderHashUtils.js';
|
28
28
|
import { DEFAULT_LAMBDA_VARIABLE_NAME } from '../../../QueryBuilderConfig.js';
|
29
29
|
import type { QueryBuilderProjectionColumnDragSource } from '../projection/QueryBuilderProjectionColumnState.js';
|
@@ -333,6 +333,7 @@ export class QueryBuilderWindowState implements Hashable {
|
|
333
333
|
makeObservable(this, {
|
334
334
|
windowColumns: observable,
|
335
335
|
editColumn: observable,
|
336
|
+
validationIssues: computed,
|
336
337
|
addWindowColumn: action,
|
337
338
|
removeColumn: action,
|
338
339
|
moveColumn: action,
|
@@ -346,6 +347,18 @@ export class QueryBuilderWindowState implements Hashable {
|
|
346
347
|
return !this.windowColumns.length;
|
347
348
|
}
|
348
349
|
|
350
|
+
get validationIssues(): string[] | undefined {
|
351
|
+
const hasDuplicatedWindowColumns = this.windowColumns.some(
|
352
|
+
(column) =>
|
353
|
+
this.windowColumns.filter((c) => c.columnName === column.columnName)
|
354
|
+
.length > 1,
|
355
|
+
);
|
356
|
+
if (hasDuplicatedWindowColumns) {
|
357
|
+
return ['Query has duplicated window columns'];
|
358
|
+
}
|
359
|
+
return undefined;
|
360
|
+
}
|
361
|
+
|
349
362
|
get referencedTDSColumns(): QueryBuilderTDSColumnState[] {
|
350
363
|
return uniq(this.windowColumns.map((c) => c.referencedTDSColumns).flat());
|
351
364
|
}
|