@finos/legend-query-builder 1.0.6 → 2.0.1

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 (71) hide show
  1. package/lib/application/QueryBuilderEvent.d.ts +7 -7
  2. package/lib/application/QueryBuilderEvent.d.ts.map +1 -1
  3. package/lib/application/QueryBuilderEvent.js +7 -7
  4. package/lib/application/QueryBuilderEvent.js.map +1 -1
  5. package/lib/components/QueryBuilder.js +1 -1
  6. package/lib/components/QueryBuilder.js.map +1 -1
  7. package/lib/components/QueryBuilderResultPanel.d.ts.map +1 -1
  8. package/lib/components/QueryBuilderResultPanel.js +13 -2
  9. package/lib/components/QueryBuilderResultPanel.js.map +1 -1
  10. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js +2 -2
  11. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js.map +1 -1
  12. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts +3 -2
  13. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts.map +1 -1
  14. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.js +53 -13
  15. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.js.map +1 -1
  16. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.d.ts.map +1 -1
  17. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js +3 -2
  18. package/lib/components/fetch-structure/QueryBuilderTDSWindowPanel.js.map +1 -1
  19. package/lib/graphManager/QueryBuilderSupportedFunctions.d.ts +1 -0
  20. package/lib/graphManager/QueryBuilderSupportedFunctions.d.ts.map +1 -1
  21. package/lib/graphManager/QueryBuilderSupportedFunctions.js +1 -0
  22. package/lib/graphManager/QueryBuilderSupportedFunctions.js.map +1 -1
  23. package/lib/index.css +2 -2
  24. package/lib/index.css.map +1 -1
  25. package/lib/package.json +7 -7
  26. package/lib/stores/QueryBuilderStateBuilder.d.ts +2 -1
  27. package/lib/stores/QueryBuilderStateBuilder.d.ts.map +1 -1
  28. package/lib/stores/QueryBuilderStateBuilder.js +8 -1
  29. package/lib/stores/QueryBuilderStateBuilder.js.map +1 -1
  30. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts +1 -0
  31. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts.map +1 -1
  32. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.js.map +1 -1
  33. package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.d.ts.map +1 -1
  34. package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.js +3 -2
  35. package/lib/stores/fetch-structure/QueryBuilderFetchStructureState.js.map +1 -1
  36. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts +49 -1
  37. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts.map +1 -1
  38. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js +126 -0
  39. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js.map +1 -1
  40. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.d.ts +1 -0
  41. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.d.ts.map +1 -1
  42. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.js +85 -4
  43. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.js.map +1 -1
  44. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.d.ts +3 -2
  45. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.d.ts.map +1 -1
  46. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.js +96 -14
  47. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.js.map +1 -1
  48. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts +1 -0
  49. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
  50. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +6 -0
  51. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
  52. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts +1 -0
  53. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.d.ts.map +1 -1
  54. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js +10 -1
  55. package/lib/stores/fetch-structure/tds/window/QueryBuilderWindowState.js.map +1 -1
  56. package/package.json +14 -14
  57. package/src/application/QueryBuilderEvent.ts +7 -7
  58. package/src/components/QueryBuilder.tsx +1 -1
  59. package/src/components/QueryBuilderResultPanel.tsx +16 -1
  60. package/src/components/fetch-structure/QueryBuilderFetchStructurePanel.tsx +2 -2
  61. package/src/components/fetch-structure/QueryBuilderGraphFetchTreePanel.tsx +240 -5
  62. package/src/components/fetch-structure/QueryBuilderTDSWindowPanel.tsx +8 -5
  63. package/src/graphManager/QueryBuilderSupportedFunctions.ts +1 -0
  64. package/src/stores/QueryBuilderStateBuilder.ts +20 -0
  65. package/src/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.ts +2 -0
  66. package/src/stores/fetch-structure/QueryBuilderFetchStructureState.ts +3 -2
  67. package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.ts +158 -0
  68. package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.ts +258 -4
  69. package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeValueSpecificationBuilder.ts +166 -24
  70. package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +7 -0
  71. package/src/stores/fetch-structure/tds/window/QueryBuilderWindowState.ts +14 -1
@@ -24,6 +24,7 @@ import {
24
24
  PackageableElementExplicitReference,
25
25
  RootGraphFetchTree,
26
26
  getAllSuperclasses,
27
+ type Binding,
27
28
  } from '@finos/legend-graph';
28
29
  import {
29
30
  type QueryBuilderGraphFetchTreeData,
@@ -54,6 +55,145 @@ import {
54
55
  import { QUERY_BUILDER_HASH_STRUCTURE } from '../../../graphManager/QueryBuilderHashUtils.js';
55
56
  import { isValueExpressionReferencedInValue } from '../../QueryBuilderValueSpecificationHelper.js';
56
57
 
58
+ export enum SERIALIZATION_TYPE {
59
+ PURE = 'PURE',
60
+ EXTERNAL_FORMAT = 'EXTERNAL_FORMAT',
61
+ }
62
+
63
+ const DEFAULT_PURE_CONFIG_TYPE_NAME = '@type';
64
+
65
+ export class PureSerializationConfig {
66
+ typeKeyName: string;
67
+ includeType: boolean;
68
+ includeEnumType: boolean;
69
+ removePropertiesWithNullValues: boolean;
70
+ removePropertiesWithEmptySets: boolean;
71
+ fullyQualifiedTypePath: boolean;
72
+ includeObjectReference: boolean;
73
+
74
+ constructor() {
75
+ // default values
76
+ this.typeKeyName = DEFAULT_PURE_CONFIG_TYPE_NAME;
77
+ this.includeType = true;
78
+ this.includeEnumType = true;
79
+ this.removePropertiesWithNullValues = true;
80
+ this.removePropertiesWithEmptySets = false;
81
+ this.fullyQualifiedTypePath = true;
82
+ this.includeObjectReference = false;
83
+ makeObservable(this, {
84
+ typeKeyName: observable,
85
+ includeType: observable,
86
+ includeEnumType: observable,
87
+ removePropertiesWithNullValues: observable,
88
+ removePropertiesWithEmptySets: observable,
89
+ fullyQualifiedTypePath: observable,
90
+ includeObjectReference: observable,
91
+ setTypeName: action,
92
+ setIncludeObjectReference: action,
93
+ setIncludeType: action,
94
+ setFullyQualifiedTypePath: action,
95
+ setRemovePropertiesWithEmptySets: action,
96
+ setInclueEnumType: action,
97
+ setRemovePropertiesWithNullValues: action,
98
+ });
99
+ }
100
+
101
+ setTypeName(val: string): void {
102
+ this.typeKeyName = val;
103
+ }
104
+
105
+ setIncludeType(val: boolean): void {
106
+ this.includeType = val;
107
+ }
108
+
109
+ setInclueEnumType(val: boolean): void {
110
+ this.includeEnumType = val;
111
+ }
112
+
113
+ setRemovePropertiesWithNullValues(val: boolean): void {
114
+ this.removePropertiesWithNullValues = val;
115
+ }
116
+
117
+ setRemovePropertiesWithEmptySets(val: boolean): void {
118
+ this.removePropertiesWithEmptySets = val;
119
+ }
120
+
121
+ setFullyQualifiedTypePath(val: boolean): void {
122
+ this.fullyQualifiedTypePath = val;
123
+ }
124
+
125
+ setIncludeObjectReference(val: boolean): void {
126
+ this.includeObjectReference = val;
127
+ }
128
+ }
129
+
130
+ export abstract class GraphFetchSerializationState {
131
+ readonly queryBuilderGraphFetchTreeState: QueryBuilderGraphFetchTreeState;
132
+
133
+ constructor(graphFetchTreeState: QueryBuilderGraphFetchTreeState) {
134
+ this.queryBuilderGraphFetchTreeState = graphFetchTreeState;
135
+ }
136
+
137
+ abstract getLabel(): string;
138
+ }
139
+
140
+ export class GraphFetchPureSerializationState extends GraphFetchSerializationState {
141
+ config: PureSerializationConfig | undefined;
142
+ configModal = false;
143
+
144
+ constructor(graphFetchTreeState: QueryBuilderGraphFetchTreeState) {
145
+ super(graphFetchTreeState);
146
+ makeObservable(this, {
147
+ config: observable,
148
+ configModal: observable,
149
+ setConfigModal: action,
150
+ });
151
+ }
152
+
153
+ setConfig(value: PureSerializationConfig | undefined): void {
154
+ this.config = value;
155
+ }
156
+
157
+ setConfigModal(val: boolean): void {
158
+ this.configModal = val;
159
+ }
160
+
161
+ override getLabel(): string {
162
+ return SERIALIZATION_TYPE.PURE;
163
+ }
164
+ }
165
+
166
+ export class GraphFetchExternalFormatSerializationState extends GraphFetchSerializationState {
167
+ targetBinding: Binding;
168
+ treeData: QueryBuilderGraphFetchTreeData | undefined;
169
+
170
+ constructor(
171
+ graphFetchTreeState: QueryBuilderGraphFetchTreeState,
172
+ targetBinding: Binding,
173
+ treeData: QueryBuilderGraphFetchTreeData | undefined,
174
+ ) {
175
+ super(graphFetchTreeState);
176
+ makeObservable(this, {
177
+ targetBinding: observable,
178
+ treeData: observable.ref,
179
+ });
180
+ this.targetBinding = targetBinding;
181
+ this.treeData = treeData;
182
+ }
183
+
184
+ setBinding(value: Binding): void {
185
+ this.targetBinding = value;
186
+ }
187
+
188
+ setGraphFetchTree(val: QueryBuilderGraphFetchTreeData | undefined): void {
189
+ this.treeData = val;
190
+ }
191
+
192
+ override getLabel(): string {
193
+ return SERIALIZATION_TYPE.EXTERNAL_FORMAT;
194
+ }
195
+ }
196
+
57
197
  export class QueryBuilderGraphFetchTreeState
58
198
  extends QueryBuilderFetchStructureImplementationState
59
199
  implements Hashable
@@ -66,6 +206,11 @@ export class QueryBuilderGraphFetchTreeState
66
206
  */
67
207
  isChecked = false;
68
208
 
209
+ /**
210
+ * Used to describe how the graph fetch tree is serialized to the final result set
211
+ */
212
+ serializationState: GraphFetchSerializationState;
213
+
69
214
  constructor(
70
215
  queryBuilderState: QueryBuilderState,
71
216
  fetchStructureState: QueryBuilderFetchStructureState,
@@ -75,13 +220,18 @@ export class QueryBuilderGraphFetchTreeState
75
220
  makeObservable(this, {
76
221
  treeData: observable.ref,
77
222
  isChecked: observable,
223
+ serializationState: observable,
78
224
  TEMPORARY__showPostFetchStructurePanel: computed,
79
225
  setGraphFetchTree: action,
226
+ setSerializationState: action,
80
227
  setChecked: action,
228
+ initialize: action,
81
229
  });
82
230
 
83
231
  // try to initialize the graph-fetch tree data using the setup class
84
232
  this.updateTreeData(this.queryBuilderState.class);
233
+ // we will default to standard pure serialization with no config
234
+ this.serializationState = new GraphFetchPureSerializationState(this);
85
235
  }
86
236
 
87
237
  get type(): string {
@@ -143,6 +293,14 @@ export class QueryBuilderGraphFetchTreeState
143
293
  return undefined;
144
294
  }
145
295
 
296
+ override initialize(): void {
297
+ this.queryBuilderState.filterState.setShowPanel(true);
298
+ }
299
+
300
+ setSerializationState(val: GraphFetchSerializationState): void {
301
+ this.serializationState = val;
302
+ }
303
+
146
304
  setGraphFetchTree(val: QueryBuilderGraphFetchTreeData | undefined): void {
147
305
  this.treeData = val;
148
306
  }
@@ -15,19 +15,45 @@
15
15
  */
16
16
 
17
17
  import {
18
+ PrimitiveInstanceValue,
19
+ type KeyExpression,
20
+ PRIMITIVE_TYPE,
18
21
  type LambdaFunction,
19
22
  GraphFetchTreeInstanceValue,
20
23
  matchFunctionName,
21
24
  RootGraphFetchTree,
22
25
  SimpleFunctionExpression,
26
+ InstanceValue,
27
+ PackageableElementReference,
28
+ Binding,
29
+ SUPPORTED_FUNCTIONS,
30
+ Class,
31
+ PURE_SERIALIZE_CONFIG_CLASS,
32
+ KeyExpressionInstanceValue,
33
+ CollectionInstanceValue,
34
+ getClassProperty,
35
+ PrimitiveType,
23
36
  } from '@finos/legend-graph';
24
- import { assertTrue, guaranteeType } from '@finos/legend-shared';
37
+ import {
38
+ assertIsBoolean,
39
+ assertIsString,
40
+ assertTrue,
41
+ guaranteeIsString,
42
+ guaranteeNonNullable,
43
+ guaranteeType,
44
+ } from '@finos/legend-shared';
25
45
  import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../graphManager/QueryBuilderSupportedFunctions.js';
26
46
  import type { QueryBuilderState } from '../../QueryBuilderState.js';
27
47
  import { QueryBuilderValueSpecificationProcessor } from '../../QueryBuilderStateBuilder.js';
28
48
  import { FETCH_STRUCTURE_IMPLEMENTATION } from '../QueryBuilderFetchStructureImplementationState.js';
29
- import { QueryBuilderGraphFetchTreeState } from './QueryBuilderGraphFetchTreeState.js';
49
+ import {
50
+ GraphFetchExternalFormatSerializationState,
51
+ GraphFetchPureSerializationState,
52
+ PureSerializationConfig,
53
+ QueryBuilderGraphFetchTreeState,
54
+ } from './QueryBuilderGraphFetchTreeState.js';
30
55
  import { buildGraphFetchTreeData } from './QueryBuilderGraphFetchTreeUtil.js';
56
+ import {} from 'mobx';
31
57
 
32
58
  export const processGraphFetchExpression = (
33
59
  expression: SimpleFunctionExpression,
@@ -77,6 +103,67 @@ export const processGraphFetchExpression = (
77
103
  }
78
104
  };
79
105
 
106
+ type PropertyValue = object | string | number | boolean;
107
+
108
+ // Dynamically sets key values of config
109
+ // TODO we can further enhance this by making configInstance just a list of key value pairs and using class config definition to render in query builder
110
+ const processKeyExpressionValueOnSerializationConfig = (
111
+ keyExpression: KeyExpression,
112
+ configInstance: Record<PropertyKey, PropertyValue>,
113
+ configClassDef: Class,
114
+ idx: number,
115
+ ): void => {
116
+ // initial checks
117
+ const expressionKey = guaranteeType(
118
+ keyExpression.key,
119
+ PrimitiveInstanceValue,
120
+ `Can't process serialize() expression: serialization config key expression ${idx} key expected to be a primitive value`,
121
+ );
122
+ assertTrue(
123
+ expressionKey.genericType.value.rawType.path === PRIMITIVE_TYPE.STRING,
124
+ `Can't process serialize() expression: serialization config key expression ${idx} key expected to be a primitive string value`,
125
+ );
126
+ const keyValue = guaranteeIsString(
127
+ expressionKey.values[0],
128
+ `Can't process serialize() expression: serialization config key expression ${idx} expected to be a non-nullable primitive string value`,
129
+ );
130
+ // check instance
131
+ const properties = Object.getOwnPropertyNames(configInstance);
132
+ guaranteeNonNullable(
133
+ properties.find((prop) => prop === keyValue),
134
+ `Property name '${keyValue}' not defined in serialization config, accepted properties are ${properties.join(
135
+ ',',
136
+ )}`,
137
+ );
138
+ // check class
139
+ const _classProperty = getClassProperty(configClassDef, keyValue);
140
+ const _classType = guaranteeType(
141
+ _classProperty.genericType.value.rawType,
142
+ PrimitiveType,
143
+ `Only primitive types suppported for config. Property ${keyValue} for class ${PURE_SERIALIZE_CONFIG_CLASS} is of type ${_classProperty.genericType.value.rawType.path}`,
144
+ );
145
+ const expressionValue = guaranteeNonNullable(
146
+ guaranteeType(
147
+ keyExpression.expression,
148
+ PrimitiveInstanceValue,
149
+ `Can't process serialize() expression: config key expression's value expected to be a primitive instance value`,
150
+ ).values[0],
151
+ `Can't process serialize() expression: config key expression's value expected to be a non nullable primitive value`,
152
+ );
153
+ // TODO move to separate method and make it more robust
154
+ switch (_classType.path) {
155
+ case PRIMITIVE_TYPE.STRING:
156
+ assertIsString(expressionValue);
157
+ break;
158
+ case PRIMITIVE_TYPE.BOOLEAN:
159
+ assertIsBoolean(expressionValue);
160
+ break;
161
+ default:
162
+ return;
163
+ }
164
+ configInstance[keyValue] = expressionValue as PropertyValue;
165
+ };
166
+
80
167
  export const processGraphFetchSerializeExpression = (
81
168
  expression: SimpleFunctionExpression,
82
169
  queryBuilderState: QueryBuilderState,
@@ -89,8 +176,9 @@ export const processGraphFetchSerializeExpression = (
89
176
 
90
177
  // check parameters
91
178
  assertTrue(
92
- expression.parametersValues.length === 2,
93
- `Can't process serialize() expression: serialize() expects 1 argument`,
179
+ expression.parametersValues.length === 2 ||
180
+ expression.parametersValues.length === 3,
181
+ `Can't process serialize() expression: serialize() expects 1 or 2 argument`,
94
182
  );
95
183
 
96
184
  // check preceding expression
@@ -132,5 +220,171 @@ export const processGraphFetchSerializeExpression = (
132
220
  graphFetchTreeState.setGraphFetchTree(
133
221
  buildGraphFetchTreeData(graphFetchTreeRoot),
134
222
  );
223
+
224
+ const serializeConfigParameter = expression.parametersValues[2];
225
+ if (serializeConfigParameter) {
226
+ const pureConfigFunction = guaranteeType(
227
+ serializeConfigParameter,
228
+ SimpleFunctionExpression,
229
+ `Can't process serialize() expression: serialize() function expects a function to configure custom serialization`,
230
+ );
231
+ assertTrue(
232
+ matchFunctionName(pureConfigFunction.functionName, [
233
+ SUPPORTED_FUNCTIONS.NEW,
234
+ ]),
235
+ `Can't process serialize() expression: config expects 'new' function instaniate new config class`,
236
+ );
237
+
238
+ const pureSerializationState = guaranteeType(
239
+ graphFetchTreeState.serializationState,
240
+ GraphFetchPureSerializationState,
241
+ `Can't process serialize() expression: serialization state expected to be of type pure with serialize()`,
242
+ );
243
+ // first para: config class
244
+ const configClass = guaranteeType(
245
+ guaranteeType(
246
+ guaranteeType(
247
+ pureConfigFunction.parametersValues[0],
248
+ InstanceValue,
249
+ `Can't process serialize() expression: serialization config expects first param to be an instance value`,
250
+ ).values[0],
251
+ PackageableElementReference,
252
+ `Can't process serialize() expression: serialization config expects first param to be a packageable element`,
253
+ ).value,
254
+ Class,
255
+ `Can't process serialize() expression: serialization config expects first param to be a class`,
256
+ );
257
+ assertTrue(
258
+ configClass.path === PURE_SERIALIZE_CONFIG_CLASS,
259
+ `Can't process serialize() expression: serialiaztion config class expected to be ${PURE_SERIALIZE_CONFIG_CLASS}, got : ${configClass.path}`,
260
+ );
261
+ // 2nd param: empty string
262
+ // TODO: Investigate why `new` function as the second input as empty string
263
+
264
+ // 2rd param: key expression values representing property values of config
265
+ const collectionInstanceValue = guaranteeType(
266
+ pureConfigFunction.parametersValues[2],
267
+ CollectionInstanceValue,
268
+ `Can't process serialize() expression: serialization config expects third param to be a collection instance of key expressions`,
269
+ );
270
+ const serializationConfig = new PureSerializationConfig();
271
+ collectionInstanceValue.values.forEach((val, idx) => {
272
+ const keyExpInstance = guaranteeType(
273
+ val,
274
+ KeyExpressionInstanceValue,
275
+ `Can't process serialize() expression: collection instance value expects value ${
276
+ idx + 1
277
+ } to be key expression instance `,
278
+ );
279
+ const keyExpression = guaranteeNonNullable(
280
+ keyExpInstance.values[0],
281
+ `Can't process serialize() expression: serialization config key expression ${idx} expected to non null`,
282
+ );
283
+ processKeyExpressionValueOnSerializationConfig(
284
+ keyExpression,
285
+ serializationConfig as unknown as Record<PropertyKey, PropertyValue>,
286
+ configClass,
287
+ idx,
288
+ );
289
+ });
290
+ pureSerializationState.setConfig(serializationConfig);
291
+ }
292
+ }
293
+ };
294
+
295
+ export const processGraphFetchExternalizeExpression = (
296
+ expression: SimpleFunctionExpression,
297
+ queryBuilderState: QueryBuilderState,
298
+ parentLambda: LambdaFunction,
299
+ ): void => {
300
+ // update fetch-structure
301
+ queryBuilderState.fetchStructureState.changeImplementation(
302
+ FETCH_STRUCTURE_IMPLEMENTATION.GRAPH_FETCH,
303
+ );
304
+
305
+ // check parameters
306
+ assertTrue(
307
+ expression.parametersValues.length === 3,
308
+ `Can't process externalize() expression: externalize() expects 2 argument`,
309
+ );
310
+
311
+ const precedingExpression = guaranteeType(
312
+ expression.parametersValues[0],
313
+ SimpleFunctionExpression,
314
+ `Can't process externalize() expression: only support externalize() immediately following an expression`,
315
+ );
316
+
317
+ // build preceding expression
318
+ assertTrue(
319
+ matchFunctionName(precedingExpression.functionName, [
320
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH,
321
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.GRAPH_FETCH_CHECKED,
322
+ ]),
323
+ `Can't process externalize() expression: only support externalize() in graph-fetch expression`,
324
+ );
325
+ QueryBuilderValueSpecificationProcessor.process(
326
+ precedingExpression,
327
+ parentLambda,
328
+ queryBuilderState,
329
+ );
330
+
331
+ // build state
332
+ if (
333
+ queryBuilderState.fetchStructureState.implementation instanceof
334
+ QueryBuilderGraphFetchTreeState
335
+ ) {
336
+ const graphFetchTreeState =
337
+ queryBuilderState.fetchStructureState.implementation;
338
+ // TODO: move to graph fetch processing once we completely deattach serialize graph fetch from main graphfetch tree
339
+ const mainGraphFetchTree = guaranteeType(
340
+ precedingExpression.parametersValues[1],
341
+ GraphFetchTreeInstanceValue,
342
+ `Can't process graphfetch() expression: externalize() graph-fetch is missing`,
343
+ );
344
+ const mainGraphFetchTreeRoot = guaranteeType(
345
+ mainGraphFetchTree.values[0],
346
+ RootGraphFetchTree,
347
+ `Can't process graphfetch() expression: graph-fetch tree root is missing`,
348
+ );
349
+ graphFetchTreeState.setGraphFetchTree(
350
+ buildGraphFetchTreeData(mainGraphFetchTreeRoot),
351
+ );
352
+
353
+ // build externalizeState
354
+ const instanceExpression = guaranteeType(
355
+ expression.parametersValues[1],
356
+ InstanceValue,
357
+ `Can't process externalize() expression: only support externalize() with 1st parameter as instance value`,
358
+ );
359
+ const binding = guaranteeType(
360
+ guaranteeType(
361
+ instanceExpression.values[0],
362
+ PackageableElementReference,
363
+ `Can't process externalize() expression: only support externalize() with 1st parameter as packagableElement value`,
364
+ ).value,
365
+ Binding,
366
+ `Can't process externalize() expression: only support externalize() with 1st parameter as binding value`,
367
+ );
368
+
369
+ const externalizeState = new GraphFetchExternalFormatSerializationState(
370
+ graphFetchTreeState,
371
+ binding,
372
+ undefined,
373
+ );
374
+ graphFetchTreeState.setSerializationState(externalizeState);
375
+
376
+ const graphFetchTree = guaranteeType(
377
+ expression.parametersValues[2],
378
+ GraphFetchTreeInstanceValue,
379
+ `Can't process externalize() expression: externalize() graph-fetch is missing`,
380
+ );
381
+ const graphFetchTreeRoot = guaranteeType(
382
+ graphFetchTree.values[0],
383
+ RootGraphFetchTree,
384
+ `Can't process externalize() expression: externalize() graph-fetch tree root is missing`,
385
+ );
386
+ externalizeState.setGraphFetchTree(
387
+ buildGraphFetchTreeData(graphFetchTreeRoot),
388
+ );
135
389
  }
136
390
  };