@finos/legend-graph 1.3.0 → 2.0.2
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/lib/GraphManagerState.d.ts +2 -2
- package/lib/GraphManagerState.js +4 -4
- package/lib/GraphManagerState.js.map +1 -1
- package/lib/graph/BasicModel.d.ts.map +1 -1
- package/lib/graph/BasicModel.js +1 -0
- package/lib/graph/BasicModel.js.map +1 -1
- package/lib/graph/DependencyManager.d.ts.map +1 -1
- package/lib/graph/DependencyManager.js +2 -0
- package/lib/graph/DependencyManager.js.map +1 -1
- package/lib/graph/PureModel.d.ts.map +1 -1
- package/lib/graph/PureModel.js +2 -0
- package/lib/graph/PureModel.js.map +1 -1
- package/lib/graphManager/AbstractPureGraphManager.d.ts +8 -6
- package/lib/graphManager/AbstractPureGraphManager.d.ts.map +1 -1
- package/lib/graphManager/AbstractPureGraphManager.js.map +1 -1
- package/lib/graphManager/GraphBuilderReport.d.ts +10 -0
- package/lib/graphManager/GraphBuilderReport.d.ts.map +1 -1
- package/lib/graphManager/GraphBuilderReport.js +6 -0
- package/lib/graphManager/GraphBuilderReport.js.map +1 -1
- package/lib/graphManager/{GraphManagerLogEvent.d.ts → GraphManagerEvent.d.ts} +12 -19
- package/lib/graphManager/GraphManagerEvent.d.ts.map +1 -0
- package/lib/graphManager/GraphManagerEvent.js +45 -0
- package/lib/graphManager/GraphManagerEvent.js.map +1 -0
- package/lib/graphManager/GraphManagerTelemetry.d.ts +28 -0
- package/lib/graphManager/GraphManagerTelemetry.d.ts.map +1 -0
- package/lib/graphManager/GraphManagerTelemetry.js +22 -0
- package/lib/graphManager/GraphManagerTelemetry.js.map +1 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/models/protocols/pure/v1/V1_PureGraphManager.d.ts +56 -9
- package/lib/models/protocols/pure/v1/V1_PureGraphManager.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/V1_PureGraphManager.js +339 -198
- package/lib/models/protocols/pure/v1/V1_PureGraphManager.js.map +1 -1
- package/lib/models/protocols/pure/v1/engine/V1_Engine.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/engine/V1_Engine.js +2 -2
- package/lib/models/protocols/pure/v1/engine/V1_Engine.js.map +1 -1
- package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.d.ts +21 -0
- package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.d.ts.map +1 -0
- package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.js +22 -0
- package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.js.map +1 -0
- package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.d.ts +0 -5
- package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.js +0 -6
- package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.js.map +1 -1
- package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.d.ts +0 -2
- package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.js +0 -2
- package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.js.map +1 -1
- package/lib/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.d.ts +1 -1
- package/lib/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.js +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js +2 -2
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js +4 -4
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.js +4 -4
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.js +2 -2
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.d.ts.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js +3 -7
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js.map +1 -1
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.js +2 -2
- package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.js.map +1 -1
- package/lib/package.json +2 -2
- package/package.json +5 -5
- package/src/GraphManagerState.ts +4 -4
- package/src/graph/BasicModel.ts +2 -0
- package/src/graph/DependencyManager.ts +5 -0
- package/src/graph/PureModel.ts +8 -0
- package/src/graphManager/AbstractPureGraphManager.ts +19 -6
- package/src/graphManager/GraphBuilderReport.ts +15 -1
- package/src/graphManager/{GraphManagerLogEvent.ts → GraphManagerEvent.ts} +10 -20
- package/src/graphManager/GraphManagerTelemetry.ts +35 -0
- package/src/index.ts +5 -5
- package/src/models/protocols/pure/v1/V1_PureGraphManager.ts +547 -403
- package/src/models/protocols/pure/v1/engine/V1_Engine.ts +2 -2
- package/src/models/protocols/pure/v1/engine/V1_EngineEvent.ts +21 -0
- package/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts +0 -6
- package/src/models/protocols/pure/v1/model/context/V1_PureModelContext.ts +1 -5
- package/src/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.ts +1 -1
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.ts +2 -2
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.ts +4 -4
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.ts +4 -4
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.ts +2 -2
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.ts +4 -9
- package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.ts +2 -2
- package/tsconfig.json +3 -1
- package/lib/graphManager/GraphManagerLogEvent.d.ts.map +0 -1
- package/lib/graphManager/GraphManagerLogEvent.js +0 -53
- package/lib/graphManager/GraphManagerLogEvent.js.map +0 -1
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { flow, flowResult, makeObservable, runInAction } from 'mobx';
|
|
17
|
-
import {
|
|
17
|
+
import { GRAPH_MANAGER_EVENT } from '../../../../graphManager/GraphManagerEvent';
|
|
18
18
|
import { CORE_PURE_PATH, ELEMENT_PATH_DELIMITER, ROOT_PACKAGE_NAME, SOURCE_INFORMATION_KEY, } from '../../../../MetaModelConst';
|
|
19
|
-
import { TracerService, LogEvent, getClass, guaranteeNonNullable, UnsupportedOperationError, recursiveOmit, assertTrue, assertErrorThrown, promisify, } from '@finos/legend-shared';
|
|
19
|
+
import { TracerService, LogEvent, getClass, guaranteeNonNullable, UnsupportedOperationError, recursiveOmit, assertTrue, assertErrorThrown, promisify, StopWatch, assertNonEmptyString, } from '@finos/legend-shared';
|
|
20
20
|
import { AbstractPureGraphManager, } from '../../../../graphManager/AbstractPureGraphManager';
|
|
21
|
+
import { Mapping } from '../../../metamodels/pure/packageableElements/mapping/Mapping';
|
|
22
|
+
import { EngineRuntime, } from '../../../metamodels/pure/packageableElements/runtime/Runtime';
|
|
21
23
|
import { PureModel, } from '../../../../graph/PureModel';
|
|
22
24
|
import { RawLambda } from '../../../metamodels/pure/rawValueSpecification/RawLambda';
|
|
23
25
|
import { ServiceExecutionMode } from '../../../../graphManager/action/service/ServiceExecutionMode';
|
|
24
|
-
import { PureSingleExecution } from '../../../metamodels/pure/packageableElements/service/ServiceExecution';
|
|
26
|
+
import { KeyedExecutionParameter, PureMultiExecution, PureSingleExecution, } from '../../../metamodels/pure/packageableElements/service/ServiceExecution';
|
|
25
27
|
import { V1_deserializeRawValueSpecification, V1_serializeRawValueSpecification, } from './transformation/pureProtocol/serializationHelpers/V1_RawValueSpecificationSerializationHelper';
|
|
26
28
|
import { V1_serializeValueSpecification, V1_deserializeValueSpecification, } from './transformation/pureProtocol/serializationHelpers/V1_ValueSpecificationSerializer';
|
|
27
29
|
import V1_CORE_SYSTEM_MODELS from './V1_Core_SystemModels.json';
|
|
@@ -68,7 +70,7 @@ import { V1_transformRelationalDatabaseConnection } from './transformation/pureG
|
|
|
68
70
|
import { V1_FlatData } from './model/packageableElements/store/flatData/model/V1_FlatData';
|
|
69
71
|
import { V1_Database } from './model/packageableElements/store/relational/model/V1_Database';
|
|
70
72
|
import { V1_setupDatabaseSerialization } from './transformation/pureProtocol/serializationHelpers/V1_DatabaseSerializationHelper';
|
|
71
|
-
import { V1_setupEngineRuntimeSerialization, V1_setupLegacyRuntimeSerialization, } from './transformation/pureProtocol/serializationHelpers/V1_RuntimeSerializationHelper';
|
|
73
|
+
import { V1_PACKAGEABLE_RUNTIME_ELEMENT_PROTOCOL_TYPE, V1_setupEngineRuntimeSerialization, V1_setupLegacyRuntimeSerialization, } from './transformation/pureProtocol/serializationHelpers/V1_RuntimeSerializationHelper';
|
|
72
74
|
import { V1_GraphTransformerContextBuilder } from './transformation/pureGraph/from/V1_GraphTransformerContext';
|
|
73
75
|
import { V1_transformExecutionNode, V1_transformExecutionPlan, } from './transformation/pureGraph/from/executionPlan/V1_ExecutionPlanTransformer';
|
|
74
76
|
import { V1_deserializeExecutionPlan, V1_serializeExecutionNode, V1_serializeExecutionPlan, } from './transformation/pureProtocol/serializationHelpers/executionPlan/V1_ExecutionPlanSerializationHelper';
|
|
@@ -77,8 +79,13 @@ import { V1_buildQuery, V1_buildServiceTestResult, V1_buildServiceRegistrationRe
|
|
|
77
79
|
import { V1_buildExecutionResult } from './engine/V1_ExecutionHelper';
|
|
78
80
|
import { ENTITY_PATH_DELIMITER, } from '@finos/legend-model-storage';
|
|
79
81
|
import { DependencyGraphBuilderError, GraphBuilderError, SystemGraphBuilderError, } from '../../../../graphManager/GraphManagerUtils';
|
|
80
|
-
import { PackageableElementReference } from '../../../metamodels/pure/packageableElements/PackageableElementReference';
|
|
82
|
+
import { PackageableElementExplicitReference, PackageableElementReference, } from '../../../metamodels/pure/packageableElements/PackageableElementReference';
|
|
81
83
|
import { V1_ExternalFormatModelGenerationInput } from './engine/externalFormat/V1_ExternalFormatModelGeneration';
|
|
84
|
+
import { GraphBuilderReport } from '../../../../graphManager/GraphBuilderReport';
|
|
85
|
+
import { V1_PureMultiExecution, V1_PureSingleExecution, } from './model/packageableElements/service/V1_ServiceExecution';
|
|
86
|
+
import { V1_MAPPING_ELEMENT_PROTOCOL_TYPE } from './transformation/pureProtocol/serializationHelpers/V1_MappingSerializationHelper';
|
|
87
|
+
import { V1_SERVICE_ELEMENT_PROTOCOL_TYPE } from './transformation/pureProtocol/serializationHelpers/V1_ServiceSerializationHelper';
|
|
88
|
+
import { MappingInclude } from '../../../metamodels/pure/packageableElements/mapping/MappingInclude';
|
|
82
89
|
const V1_FUNCTION_SUFFIX_MULTIPLICITY_INFINITE = 'MANY';
|
|
83
90
|
const getMultiplicitySuffix = (multiplicity) => {
|
|
84
91
|
if (multiplicity.lowerBound === multiplicity.upperBound) {
|
|
@@ -115,7 +122,16 @@ class V1_PureModelContextDataIndex {
|
|
|
115
122
|
generationSpecifications = [];
|
|
116
123
|
otherElementsByBuilder = new Map();
|
|
117
124
|
}
|
|
118
|
-
const
|
|
125
|
+
const mergePureModelContextData = (...data) => {
|
|
126
|
+
const mergedData = new V1_PureModelContextData();
|
|
127
|
+
for (const _data of data) {
|
|
128
|
+
mergedData.elements = mergedData.elements.concat(_data.elements);
|
|
129
|
+
mergedData.serializer = _data.serializer ?? mergedData.serializer;
|
|
130
|
+
mergedData.origin = _data.origin ?? mergedData.origin;
|
|
131
|
+
}
|
|
132
|
+
return mergedData;
|
|
133
|
+
};
|
|
134
|
+
const indexPureModelContextData = (report, data, extensions) => {
|
|
119
135
|
const index = new V1_PureModelContextDataIndex();
|
|
120
136
|
index.elements = data.elements;
|
|
121
137
|
const otherElementsByClass = new Map();
|
|
@@ -181,6 +197,37 @@ const indexPureModelContextData = (data, extensions) => {
|
|
|
181
197
|
const builder = extensions.getExtraBuilderForProtocolClassOrThrow(_class);
|
|
182
198
|
index.otherElementsByBuilder.set(builder, (index.otherElementsByBuilder.get(builder) ?? []).concat(elements));
|
|
183
199
|
});
|
|
200
|
+
// report
|
|
201
|
+
report.elementCount.total = report.elementCount.total + index.elements.length;
|
|
202
|
+
report.elementCount.other =
|
|
203
|
+
(report.elementCount.other ?? 0) +
|
|
204
|
+
otherElementsByClass.size +
|
|
205
|
+
index.fileGenerations.length +
|
|
206
|
+
index.generationSpecifications.length;
|
|
207
|
+
report.elementCount.sectionIndex =
|
|
208
|
+
(report.elementCount.sectionIndex ?? 0) + index.sectionIndices.length;
|
|
209
|
+
report.elementCount.association =
|
|
210
|
+
(report.elementCount.association ?? 0) + index.associations.length;
|
|
211
|
+
report.elementCount.class =
|
|
212
|
+
(report.elementCount.class ?? 0) + index.classes.length;
|
|
213
|
+
report.elementCount.enumeration =
|
|
214
|
+
(report.elementCount.enumeration ?? 0) + index.enumerations.length;
|
|
215
|
+
report.elementCount.function =
|
|
216
|
+
(report.elementCount.function ?? 0) + index.functions.length;
|
|
217
|
+
report.elementCount.profile =
|
|
218
|
+
(report.elementCount.profile ?? 0) + index.profiles.length;
|
|
219
|
+
report.elementCount.measure =
|
|
220
|
+
(report.elementCount.measure ?? 0) + index.measures.length;
|
|
221
|
+
report.elementCount.store =
|
|
222
|
+
(report.elementCount.store ?? 0) + index.stores.length;
|
|
223
|
+
report.elementCount.mapping =
|
|
224
|
+
(report.elementCount.mapping ?? 0) + index.mappings.length;
|
|
225
|
+
report.elementCount.connection =
|
|
226
|
+
(report.elementCount.connection ?? 0) + index.connections.length;
|
|
227
|
+
report.elementCount.runtime =
|
|
228
|
+
(report.elementCount.runtime ?? 0) + index.runtimes.length;
|
|
229
|
+
report.elementCount.service =
|
|
230
|
+
(report.elementCount.service ?? 0) + index.services.length;
|
|
184
231
|
return index;
|
|
185
232
|
};
|
|
186
233
|
export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
@@ -193,6 +240,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
193
240
|
buildSystem: flow,
|
|
194
241
|
buildDependencies: flow,
|
|
195
242
|
buildGraph: flow,
|
|
243
|
+
buildGraphFromInputs: flow,
|
|
196
244
|
buildGenerations: flow,
|
|
197
245
|
initializeAndIndexElements: flow,
|
|
198
246
|
postProcess: flow,
|
|
@@ -200,11 +248,11 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
200
248
|
buildStores: flow,
|
|
201
249
|
buildMappings: flow,
|
|
202
250
|
buildConnectionsAndRuntimes: flow,
|
|
203
|
-
|
|
251
|
+
buildSectionIndices: flow,
|
|
204
252
|
buildOtherElements: flow,
|
|
205
253
|
buildServices: flow,
|
|
206
254
|
buildFileGenerations: flow,
|
|
207
|
-
|
|
255
|
+
buildGenerationSpecifications: flow,
|
|
208
256
|
});
|
|
209
257
|
// setup plugins
|
|
210
258
|
this.extensions = new V1_GraphBuilderExtensions(this.pluginManager.getPureProtocolProcessorPlugins());
|
|
@@ -227,209 +275,121 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
227
275
|
}
|
|
228
276
|
// --------------------------------------------- Graph Builder ---------------------------------------------
|
|
229
277
|
*buildSystem(coreModel, systemModel, options) {
|
|
230
|
-
const
|
|
278
|
+
const stopWatch = new StopWatch();
|
|
279
|
+
const report = new GraphBuilderReport();
|
|
280
|
+
const graphBuilderState = systemModel.buildState;
|
|
281
|
+
graphBuilderState.reset();
|
|
231
282
|
// Create a dummy graph for system processing. This is to ensure system model does not depend on the main graph
|
|
232
283
|
const graph = new PureModel(coreModel, systemModel, this.pluginManager.getPureGraphPlugins());
|
|
233
284
|
try {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
* Get all system entities.
|
|
238
|
-
*
|
|
239
|
-
* NOTE: right now, we are doing extra work here: JSON -> protocol -> entities -> protocol, since we are
|
|
240
|
-
* expecting to get these models from some a remote SDLC project in the future.
|
|
241
|
-
*/
|
|
242
|
-
V1_deserializePureModelContextData(V1_CORE_SYSTEM_MODELS)
|
|
243
|
-
.elements.concat(this.pluginManager
|
|
285
|
+
// deserialize
|
|
286
|
+
graphBuilderState.setMessage(`Collecting and deserializing elements...`);
|
|
287
|
+
const systemData = mergePureModelContextData(V1_deserializePureModelContextData(V1_CORE_SYSTEM_MODELS), ...this.pluginManager
|
|
244
288
|
.getPureProtocolProcessorPlugins()
|
|
245
289
|
.flatMap((plugin) => plugin.V1_getExtraSystemModels?.() ?? [])
|
|
246
|
-
.
|
|
247
|
-
|
|
248
|
-
|
|
290
|
+
.map((modelContextData) => V1_deserializePureModelContextData(modelContextData)));
|
|
291
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
|
|
292
|
+
// prepare build inputs
|
|
293
|
+
const buildInputs = [
|
|
249
294
|
{
|
|
250
295
|
model: systemModel,
|
|
251
|
-
data: indexPureModelContextData(systemData, this.extensions),
|
|
296
|
+
data: indexPureModelContextData(report, systemData, this.extensions),
|
|
252
297
|
},
|
|
253
298
|
];
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
systemModel.buildState.pass();
|
|
299
|
+
// build
|
|
300
|
+
yield flowResult(this.buildGraphFromInputs(graph, buildInputs, report, stopWatch, graphBuilderState, options));
|
|
301
|
+
graphBuilderState.pass();
|
|
302
|
+
report.timings = {
|
|
303
|
+
...Object.fromEntries(stopWatch.records),
|
|
304
|
+
[GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
|
|
305
|
+
};
|
|
306
|
+
return report;
|
|
263
307
|
}
|
|
264
308
|
catch (error) {
|
|
265
309
|
assertErrorThrown(error);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FAILURE), '[ERROR]', Date.now() - startTime, 'ms');
|
|
269
|
-
}
|
|
310
|
+
graphBuilderState.fail();
|
|
311
|
+
this.log.error(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE));
|
|
270
312
|
throw new SystemGraphBuilderError(error);
|
|
271
313
|
}
|
|
314
|
+
finally {
|
|
315
|
+
graphBuilderState.setMessage(undefined);
|
|
316
|
+
}
|
|
272
317
|
}
|
|
273
318
|
*buildDependencies(coreModel, systemModel, dependencyManager, dependencyEntitiesMap, options) {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
dependencyManager.buildState.reset();
|
|
319
|
+
const stopWatch = new StopWatch();
|
|
320
|
+
const report = new GraphBuilderReport();
|
|
321
|
+
const graphBuilderState = dependencyManager.buildState;
|
|
322
|
+
graphBuilderState.reset();
|
|
279
323
|
// Create a dummy graph for system processing. This is to ensure dependency models do not depend on the main graph
|
|
280
324
|
const graph = new PureModel(coreModel, systemModel, this.pluginManager.getPureGraphPlugins());
|
|
281
325
|
graph.setDependencyManager(dependencyManager);
|
|
282
326
|
try {
|
|
283
327
|
dependencyManager.initialize(dependencyEntitiesMap);
|
|
284
|
-
//
|
|
328
|
+
// deserialize
|
|
329
|
+
graphBuilderState.setMessage(`Partitioning and deserializing elements...`);
|
|
285
330
|
const dependencyDataMap = new Map();
|
|
286
331
|
yield Promise.all(Array.from(dependencyEntitiesMap.entries()).map(([dependencyKey, entities]) => {
|
|
287
332
|
const projectModelData = new V1_PureModelContextData();
|
|
288
333
|
dependencyDataMap.set(dependencyKey, projectModelData);
|
|
289
334
|
return V1_entitiesToPureModelContextData(entities, projectModelData, this.pluginManager.getPureProtocolProcessorPlugins());
|
|
290
335
|
}));
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const graphBuilderInput = Array.from(dependencyDataMap.entries()).map(([dependencyKey, dependencyData]) => ({
|
|
296
|
-
data: indexPureModelContextData(dependencyData, this.extensions),
|
|
336
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
|
|
337
|
+
// prepare build inputs
|
|
338
|
+
const buildInputs = Array.from(dependencyDataMap.entries()).map(([dependencyKey, dependencyData]) => ({
|
|
339
|
+
data: indexPureModelContextData(report, dependencyData, this.extensions),
|
|
297
340
|
model: graph.dependencyManager.getModel(dependencyKey),
|
|
298
341
|
}));
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
yield flowResult(this.buildOtherElements(graph, graphBuilderInput, options));
|
|
309
|
-
yield flowResult(this.postProcess(graph, graphBuilderInput));
|
|
310
|
-
const processingFinishedTime = Date.now();
|
|
311
|
-
if (!options?.quiet) {
|
|
312
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_PROCESSED), processingFinishedTime - preprocessingFinishedTime, 'ms');
|
|
313
|
-
}
|
|
314
|
-
dependencyManager.buildState.pass();
|
|
315
|
-
if (!options?.quiet) {
|
|
316
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_BUILT), '[TOTAL]', Date.now() - startTime, 'ms');
|
|
317
|
-
}
|
|
342
|
+
// build
|
|
343
|
+
yield flowResult(this.buildGraphFromInputs(graph, buildInputs, report, stopWatch, graphBuilderState, options));
|
|
344
|
+
graphBuilderState.pass();
|
|
345
|
+
report.otherStats.projectCount = dependencyEntitiesMap.size;
|
|
346
|
+
report.timings = {
|
|
347
|
+
...Object.fromEntries(stopWatch.records),
|
|
348
|
+
[GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
|
|
349
|
+
};
|
|
350
|
+
return report;
|
|
318
351
|
}
|
|
319
352
|
catch (error) {
|
|
320
353
|
assertErrorThrown(error);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.map((v) => v.allOwnElements)
|
|
324
|
-
.flat().length}]`);
|
|
325
|
-
}
|
|
326
|
-
dependencyManager.buildState.fail();
|
|
354
|
+
this.log.error(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE));
|
|
355
|
+
graphBuilderState.fail();
|
|
327
356
|
throw new DependencyGraphBuilderError(error);
|
|
328
357
|
}
|
|
358
|
+
finally {
|
|
359
|
+
graphBuilderState.setMessage(undefined);
|
|
360
|
+
}
|
|
329
361
|
}
|
|
330
362
|
*buildGraph(graph, entities, options) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
363
|
+
const stopWatch = new StopWatch();
|
|
364
|
+
const report = new GraphBuilderReport();
|
|
365
|
+
const graphBuilderState = graph.buildState;
|
|
366
|
+
graphBuilderState.reset();
|
|
334
367
|
try {
|
|
335
|
-
//
|
|
368
|
+
// deserialize
|
|
369
|
+
graphBuilderState.setMessage(`Deserializing elements...`);
|
|
336
370
|
const data = new V1_PureModelContextData();
|
|
337
371
|
yield V1_entitiesToPureModelContextData(entities, data, this.pluginManager.getPureProtocolProcessorPlugins());
|
|
338
|
-
|
|
372
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
|
|
373
|
+
// prepare build inputs
|
|
374
|
+
const buildInputs = [
|
|
339
375
|
{
|
|
340
376
|
model: graph,
|
|
341
|
-
data: indexPureModelContextData(data, this.extensions),
|
|
377
|
+
data: indexPureModelContextData(report, data, this.extensions),
|
|
342
378
|
},
|
|
343
379
|
];
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_ELEMENTS_INITIALIZED_AND_INDEXED), stepFinishedTime - stepStartTime, 'ms', `[element: ${data.elements.length}]`);
|
|
353
|
-
}
|
|
354
|
-
stepStartTime = stepFinishedTime;
|
|
355
|
-
// Section index
|
|
356
|
-
yield flowResult(this.buildSectionIndex(graph, graphBuilderInput, options));
|
|
357
|
-
stepFinishedTime = Date.now();
|
|
358
|
-
if (!options?.quiet) {
|
|
359
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SECTION_INDICES_BUILT), stepFinishedTime - stepStartTime, 'ms', `[sectionIndex: ${graph.ownSectionIndices.length}]`);
|
|
360
|
-
}
|
|
361
|
-
stepStartTime = stepFinishedTime;
|
|
362
|
-
// Types
|
|
363
|
-
yield flowResult(this.buildTypes(graph, graphBuilderInput, options));
|
|
364
|
-
stepFinishedTime = Date.now();
|
|
365
|
-
if (!options?.quiet) {
|
|
366
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DOMAIN_MODELS_BUILT), stepFinishedTime - stepStartTime, 'ms', `[class: ${graph.ownClasses.length}, enumeration: ${graph.ownEnumerations.length}, association: ${graph.ownAssociations.length}, profile: ${graph.ownProfiles.length}, functions: ${graph.ownFunctions.length}]`);
|
|
367
|
-
}
|
|
368
|
-
stepStartTime = stepFinishedTime;
|
|
369
|
-
// Stores
|
|
370
|
-
yield flowResult(this.buildStores(graph, graphBuilderInput, options));
|
|
371
|
-
stepFinishedTime = Date.now();
|
|
372
|
-
// TODO: we might want to detail out the number of stores by type
|
|
373
|
-
if (!options?.quiet) {
|
|
374
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_STORES_BUILT), stepFinishedTime - stepStartTime, 'ms', `[store: ${graph.ownStores.length}]`);
|
|
375
|
-
}
|
|
376
|
-
stepStartTime = stepFinishedTime;
|
|
377
|
-
// Mappings
|
|
378
|
-
yield flowResult(this.buildMappings(graph, graphBuilderInput, options));
|
|
379
|
-
stepFinishedTime = Date.now();
|
|
380
|
-
if (!options?.quiet) {
|
|
381
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_MAPPINGS_BUILT), stepFinishedTime - stepStartTime, 'ms', `[mapping: ${graph.ownMappings.length}]`);
|
|
382
|
-
}
|
|
383
|
-
stepStartTime = stepFinishedTime;
|
|
384
|
-
// Connections and runtimes
|
|
385
|
-
yield flowResult(this.buildConnectionsAndRuntimes(graph, graphBuilderInput, options));
|
|
386
|
-
stepFinishedTime = Date.now();
|
|
387
|
-
if (!options?.quiet) {
|
|
388
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_CONNECTIONS_BUILT), stepFinishedTime - stepStartTime, 'ms', `[connection: ${graph.ownConnections.length}]`);
|
|
389
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_RUNTIMES_BUILT), stepFinishedTime - stepStartTime, 'ms', `[runtime: ${graph.ownRuntimes.length}]`);
|
|
390
|
-
}
|
|
391
|
-
stepStartTime = stepFinishedTime;
|
|
392
|
-
// Services
|
|
393
|
-
yield flowResult(this.buildServices(graph, graphBuilderInput, options));
|
|
394
|
-
stepFinishedTime = Date.now();
|
|
395
|
-
if (!options?.quiet) {
|
|
396
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SERVICES_BUILT), stepFinishedTime - stepStartTime, 'ms', `[service: ${graph.ownServices.length}]`);
|
|
397
|
-
}
|
|
398
|
-
stepStartTime = stepFinishedTime;
|
|
399
|
-
// File Generation
|
|
400
|
-
yield flowResult(this.buildFileGenerations(graph, graphBuilderInput, options));
|
|
401
|
-
stepFinishedTime = Date.now();
|
|
402
|
-
if (!options?.quiet) {
|
|
403
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FILE_GENERATIONS_BUILT), stepFinishedTime - stepStartTime, 'ms', `[file-generation: ${graph.ownFileGenerations.length}]`);
|
|
404
|
-
}
|
|
405
|
-
stepStartTime = stepFinishedTime;
|
|
406
|
-
// Generation Specifications (tree)
|
|
407
|
-
yield flowResult(this.buildGenerationSpecificationss(graph, graphBuilderInput, options));
|
|
408
|
-
stepFinishedTime = Date.now();
|
|
409
|
-
if (!options?.quiet) {
|
|
410
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_GENERATION_TREE_BUILT), stepFinishedTime - stepStartTime, 'ms', `[generation-specification: ${graph.ownGenerationSpecifications.length}]`);
|
|
411
|
-
}
|
|
412
|
-
stepStartTime = stepFinishedTime;
|
|
413
|
-
// Other elements
|
|
414
|
-
yield flowResult(this.buildOtherElements(graph, graphBuilderInput, options));
|
|
415
|
-
stepFinishedTime = Date.now();
|
|
416
|
-
if (!options?.quiet) {
|
|
417
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_OTHER_ELEMENTS_BUILT), stepFinishedTime - stepStartTime, 'ms');
|
|
418
|
-
}
|
|
419
|
-
yield flowResult(this.postProcess(graph, graphBuilderInput, {
|
|
420
|
-
TEMPORARY__keepSectionIndex: options?.TEMPORARY__keepSectionIndex,
|
|
421
|
-
}));
|
|
422
|
-
graph.buildState.pass();
|
|
423
|
-
if (!options?.quiet) {
|
|
424
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_COMPLETED), '[TOTAL]', Date.now() - startTime, 'ms');
|
|
425
|
-
}
|
|
380
|
+
// build
|
|
381
|
+
yield flowResult(this.buildGraphFromInputs(graph, buildInputs, report, stopWatch, graphBuilderState, options));
|
|
382
|
+
graphBuilderState.pass();
|
|
383
|
+
report.timings = {
|
|
384
|
+
...Object.fromEntries(stopWatch.records),
|
|
385
|
+
[GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
|
|
386
|
+
};
|
|
387
|
+
return report;
|
|
426
388
|
}
|
|
427
389
|
catch (error) {
|
|
428
390
|
assertErrorThrown(error);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
graph.buildState.fail();
|
|
391
|
+
this.log.error(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE));
|
|
392
|
+
graphBuilderState.fail();
|
|
433
393
|
/**
|
|
434
394
|
* Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
|
|
435
395
|
* But we might want to rethink this decision in the future and throw appropriate type of error
|
|
@@ -438,47 +398,46 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
438
398
|
? error
|
|
439
399
|
: new GraphBuilderError(error);
|
|
440
400
|
}
|
|
401
|
+
finally {
|
|
402
|
+
graphBuilderState.setMessage(undefined);
|
|
403
|
+
}
|
|
441
404
|
}
|
|
442
405
|
*buildGenerations(graph, generatedEntities, options) {
|
|
443
|
-
const
|
|
406
|
+
const stopWatch = new StopWatch();
|
|
407
|
+
const report = new GraphBuilderReport();
|
|
444
408
|
const generatedModel = graph.generationModel;
|
|
445
|
-
generatedModel.buildState
|
|
409
|
+
const graphBuilderState = generatedModel.buildState;
|
|
410
|
+
graphBuilderState.reset();
|
|
446
411
|
try {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
412
|
+
// deserialize
|
|
413
|
+
graphBuilderState.setMessage(`Deserializing elements...`);
|
|
450
414
|
const generatedDataMap = new Map();
|
|
451
415
|
yield Promise.all(Array.from(generatedEntities.entries()).map(([generationParentPath, entities]) => {
|
|
452
416
|
const generatedData = new V1_PureModelContextData();
|
|
453
417
|
generatedDataMap.set(generationParentPath, generatedData);
|
|
454
418
|
return V1_entitiesToPureModelContextData(entities, generatedData, this.pluginManager.getPureProtocolProcessorPlugins());
|
|
455
419
|
}));
|
|
456
|
-
|
|
420
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
|
|
421
|
+
// prepare build inputs
|
|
422
|
+
const buildInputs = Array.from(generatedDataMap.entries()).map(([generationParentPath, generatedData]) => ({
|
|
457
423
|
parentElementPath: generationParentPath,
|
|
458
|
-
data: indexPureModelContextData(generatedData, this.extensions),
|
|
424
|
+
data: indexPureModelContextData(report, generatedData, this.extensions),
|
|
459
425
|
model: generatedModel,
|
|
460
426
|
}));
|
|
461
|
-
|
|
462
|
-
yield flowResult(this.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
yield flowResult(this.postProcess(graph, generationGraphBuilderInput));
|
|
471
|
-
generatedModel.buildState.pass();
|
|
472
|
-
if (!options?.quiet) {
|
|
473
|
-
this.log.info(LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_GENERATIONS_BUILT), Date.now() - stepStartTime, `${graph.generationModel.allOwnElements.length} generated elements processed`, 'ms');
|
|
474
|
-
}
|
|
427
|
+
// build
|
|
428
|
+
yield flowResult(this.buildGraphFromInputs(graph, buildInputs, report, stopWatch, graphBuilderState, options));
|
|
429
|
+
graphBuilderState.pass();
|
|
430
|
+
report.otherStats.generationCount = generatedDataMap.size;
|
|
431
|
+
report.timings = {
|
|
432
|
+
...Object.fromEntries(stopWatch.records),
|
|
433
|
+
[GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
|
|
434
|
+
};
|
|
435
|
+
return report;
|
|
475
436
|
}
|
|
476
437
|
catch (error) {
|
|
477
438
|
assertErrorThrown(error);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
generatedModel.buildState.fail();
|
|
439
|
+
this.log.error(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE));
|
|
440
|
+
graphBuilderState.fail();
|
|
482
441
|
/**
|
|
483
442
|
* Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
|
|
484
443
|
* But we might want to rethink this decision in the future and throw appropriate type of error
|
|
@@ -487,6 +446,51 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
487
446
|
? error
|
|
488
447
|
: new GraphBuilderError(error);
|
|
489
448
|
}
|
|
449
|
+
finally {
|
|
450
|
+
graphBuilderState.setMessage(undefined);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
*buildGraphFromInputs(graph, inputs, report, stopWatch, graphBuilderState, options) {
|
|
454
|
+
// index
|
|
455
|
+
graphBuilderState.setMessage(`Indexing ${report.elementCount.total} elements...`);
|
|
456
|
+
yield flowResult(this.initializeAndIndexElements(graph, inputs, options));
|
|
457
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_INDEXED);
|
|
458
|
+
// build section index
|
|
459
|
+
graphBuilderState.setMessage(`Building section indices...`);
|
|
460
|
+
yield flowResult(this.buildSectionIndices(graph, inputs, options));
|
|
461
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_SECTION_INDICES_BUILT);
|
|
462
|
+
// build types
|
|
463
|
+
graphBuilderState.setMessage(`Building domain models...`);
|
|
464
|
+
yield flowResult(this.buildTypes(graph, inputs, options));
|
|
465
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_DOMAIN_MODELS_BUILT);
|
|
466
|
+
// build stores
|
|
467
|
+
graphBuilderState.setMessage(`Building stores...`);
|
|
468
|
+
yield flowResult(this.buildStores(graph, inputs, options));
|
|
469
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_STORES_BUILT);
|
|
470
|
+
// build mappings
|
|
471
|
+
graphBuilderState.setMessage(`Building mappings...`);
|
|
472
|
+
yield flowResult(this.buildMappings(graph, inputs, options));
|
|
473
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_MAPPINGS_BUILT);
|
|
474
|
+
// build connections and runtimes
|
|
475
|
+
graphBuilderState.setMessage(`Building connections and runtimes...`);
|
|
476
|
+
yield flowResult(this.buildConnectionsAndRuntimes(graph, inputs, options));
|
|
477
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_CONNECTIONS_AND_RUNTIMES_BUILT);
|
|
478
|
+
// build services
|
|
479
|
+
graphBuilderState.setMessage(`Building services...`);
|
|
480
|
+
yield flowResult(this.buildServices(graph, inputs, options));
|
|
481
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_SERVICES_BUILT);
|
|
482
|
+
// build other elements
|
|
483
|
+
graphBuilderState.setMessage(`Building other elements...`);
|
|
484
|
+
yield flowResult(this.buildFileGenerations(graph, inputs, options));
|
|
485
|
+
yield flowResult(this.buildGenerationSpecifications(graph, inputs, options));
|
|
486
|
+
yield flowResult(this.buildOtherElements(graph, inputs, options));
|
|
487
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_OTHER_ELEMENTS_BUILT);
|
|
488
|
+
// post-process
|
|
489
|
+
graphBuilderState.setMessage(`Post-processing graph...`);
|
|
490
|
+
yield flowResult(this.postProcess(graph, inputs, {
|
|
491
|
+
TEMPORARY__keepSectionIndex: options?.TEMPORARY__keepSectionIndex,
|
|
492
|
+
}));
|
|
493
|
+
stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_POST_PROCESSED);
|
|
490
494
|
}
|
|
491
495
|
getBuilderContext(graph, currentSubGraph, element, options) {
|
|
492
496
|
return new V1_GraphBuilderContextBuilder(graph, currentSubGraph, this.extensions, this.log, options)
|
|
@@ -565,10 +569,10 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
565
569
|
*buildFileGenerations(graph, inputs, options) {
|
|
566
570
|
yield Promise.all(inputs.flatMap((input) => input.data.fileGenerations.map((element) => this.visitWithErrorHandling(element, new V1_ProtocolToMetaModelGraphSecondPassBuilder(this.getBuilderContext(graph, input.model, element, options))))));
|
|
567
571
|
}
|
|
568
|
-
*
|
|
572
|
+
*buildGenerationSpecifications(graph, inputs, options) {
|
|
569
573
|
yield Promise.all(inputs.flatMap((input) => input.data.generationSpecifications.map((element) => this.visitWithErrorHandling(element, new V1_ProtocolToMetaModelGraphSecondPassBuilder(this.getBuilderContext(graph, input.model, element, options))))));
|
|
570
574
|
}
|
|
571
|
-
*
|
|
575
|
+
*buildSectionIndices(graph, inputs, options) {
|
|
572
576
|
yield Promise.all(inputs.flatMap((input) => input.data.sectionIndices.map((element) => this.visitWithErrorHandling(element, new V1_ProtocolToMetaModelGraphSecondPassBuilder(this.getBuilderContext(graph, input.model, element, options))))));
|
|
573
577
|
}
|
|
574
578
|
*buildOtherElements(graph, inputs, options) {
|
|
@@ -595,13 +599,13 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
595
599
|
const startTime = Date.now();
|
|
596
600
|
const graphData = this.graphToPureModelContextData(graph);
|
|
597
601
|
const grammarToJson = await this.engine.pureModelContextDataToPureCode(graphData);
|
|
598
|
-
this.log.info(LogEvent.create(
|
|
602
|
+
this.log.info(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED), Date.now() - startTime, 'ms');
|
|
599
603
|
return grammarToJson;
|
|
600
604
|
}
|
|
601
605
|
async entitiesToPureCode(entities) {
|
|
602
606
|
const startTime = Date.now();
|
|
603
607
|
const grammarToJson = await this.engine.pureModelContextDataToPureCode(await this.entitiesToPureModelContextData(entities));
|
|
604
|
-
this.log.info(LogEvent.create(
|
|
608
|
+
this.log.info(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED), Date.now() - startTime, 'ms');
|
|
605
609
|
return grammarToJson;
|
|
606
610
|
}
|
|
607
611
|
async pureCodeToEntities(code, options) {
|
|
@@ -730,7 +734,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
730
734
|
async entitiesToPureProtocolText(entities) {
|
|
731
735
|
return JSON.stringify(V1_serializePureModelContext(await this.entitiesToPureModelContextData(entities)), undefined, this.engine.config.tabSize);
|
|
732
736
|
}
|
|
733
|
-
|
|
737
|
+
pureProtocolTextToEntities = (protocol) => {
|
|
734
738
|
const graphData = V1_deserializePureModelContextData(JSON.parse(protocol));
|
|
735
739
|
return this.pureModelContextDataToEntities(graphData);
|
|
736
740
|
};
|
|
@@ -873,6 +877,143 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
873
877
|
async getLightQuery(queryId) {
|
|
874
878
|
return V1_buildLightQuery(await this.engine.getQuery(queryId), this.engine.getEngineServerClient().currentUserId);
|
|
875
879
|
}
|
|
880
|
+
async indexEntitiesWithDependencyIntoGraph(graph, _entities, dependencyEntities, entityFilterFunc) {
|
|
881
|
+
let entities = _entities;
|
|
882
|
+
graph.dependencyManager.initialize(dependencyEntities);
|
|
883
|
+
if (entityFilterFunc) {
|
|
884
|
+
Array.from(dependencyEntities.entries()).forEach(([dependencyKey, dEntities]) => {
|
|
885
|
+
dependencyEntities.set(dependencyKey, dEntities.filter(entityFilterFunc));
|
|
886
|
+
});
|
|
887
|
+
entities = _entities.filter(entityFilterFunc);
|
|
888
|
+
}
|
|
889
|
+
const report = new GraphBuilderReport();
|
|
890
|
+
// build dependency pmcd models
|
|
891
|
+
const dependencyDataMap = new Map();
|
|
892
|
+
await Promise.all(Array.from(dependencyEntities.entries()).map(([dependencyKey, value]) => {
|
|
893
|
+
const projectModelData = new V1_PureModelContextData();
|
|
894
|
+
dependencyDataMap.set(dependencyKey, projectModelData);
|
|
895
|
+
return V1_entitiesToPureModelContextData(value, projectModelData, this.pluginManager.getPureProtocolProcessorPlugins());
|
|
896
|
+
}));
|
|
897
|
+
const dependencyGraphBuilderInput = Array.from(dependencyDataMap.entries()).map(([dependencyKey, dependencyData]) => ({
|
|
898
|
+
data: indexPureModelContextData(report, dependencyData, this.extensions),
|
|
899
|
+
model: graph.dependencyManager.getModel(dependencyKey),
|
|
900
|
+
}));
|
|
901
|
+
// build main pmcd
|
|
902
|
+
const data = new V1_PureModelContextData();
|
|
903
|
+
await V1_entitiesToPureModelContextData(entities, data, this.pluginManager.getPureProtocolProcessorPlugins());
|
|
904
|
+
const mainGraphBuilderInput = [
|
|
905
|
+
{
|
|
906
|
+
model: graph,
|
|
907
|
+
data: indexPureModelContextData(report, data, this.extensions),
|
|
908
|
+
},
|
|
909
|
+
];
|
|
910
|
+
const graphBuilderInput = [
|
|
911
|
+
...dependencyGraphBuilderInput,
|
|
912
|
+
...mainGraphBuilderInput,
|
|
913
|
+
];
|
|
914
|
+
await flowResult(this.initializeAndIndexElements(graph, graphBuilderInput));
|
|
915
|
+
return graphBuilderInput;
|
|
916
|
+
}
|
|
917
|
+
// We could optimize this further by omitting parts of the entities we don't need
|
|
918
|
+
async buildGraphForCreateQuerySetup(graph, entities, dependencyEntities) {
|
|
919
|
+
try {
|
|
920
|
+
const graphBuilderInput = await this.indexEntitiesWithDependencyIntoGraph(graph, entities, dependencyEntities, (entity) => entity.content
|
|
921
|
+
._type === V1_MAPPING_ELEMENT_PROTOCOL_TYPE ||
|
|
922
|
+
entity.content
|
|
923
|
+
._type === V1_PACKAGEABLE_RUNTIME_ELEMENT_PROTOCOL_TYPE);
|
|
924
|
+
// handle mapping includes
|
|
925
|
+
const mappings = [
|
|
926
|
+
...graph.ownMappings,
|
|
927
|
+
...graph.dependencyManager.mappings,
|
|
928
|
+
];
|
|
929
|
+
const v1Mappings = graphBuilderInput
|
|
930
|
+
.map((e) => e.data.elements.filter((type) => type instanceof V1_Mapping))
|
|
931
|
+
.flat();
|
|
932
|
+
const context = new V1_GraphBuilderContextBuilder(graph, graph, this.extensions, this.log).build();
|
|
933
|
+
// build include index for compatible runtime analysis
|
|
934
|
+
v1Mappings.forEach((element) => {
|
|
935
|
+
const mapping = mappings.find((e) => e.path === element.path);
|
|
936
|
+
if (mapping) {
|
|
937
|
+
mapping.includes = element.includedMappings.map((i) => {
|
|
938
|
+
assertNonEmptyString(i.includedMappingPath, `Mapping include 'includedMappingPath' field is missing or empty`);
|
|
939
|
+
return new MappingInclude(mapping, context.resolveMapping(i.includedMappingPath));
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
// handle runtimes
|
|
944
|
+
const runtimes = [
|
|
945
|
+
...graph.ownRuntimes,
|
|
946
|
+
...graph.dependencyManager.runtimes,
|
|
947
|
+
];
|
|
948
|
+
const v1Runtimes = graphBuilderInput
|
|
949
|
+
.map((e) => e.data.elements.filter((type) => type instanceof V1_PackageableRuntime))
|
|
950
|
+
.flat();
|
|
951
|
+
v1Runtimes.forEach((element) => {
|
|
952
|
+
const runtime = runtimes.find((e) => e.path === element.path);
|
|
953
|
+
if (runtime) {
|
|
954
|
+
const runtimeValue = new EngineRuntime();
|
|
955
|
+
runtime.setRuntimeValue(runtimeValue);
|
|
956
|
+
runtimeValue.setMappings(element.runtimeValue.mappings.map((mapping) => context.resolveMapping(mapping.path)));
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
graph.buildState.pass();
|
|
960
|
+
}
|
|
961
|
+
catch (error) {
|
|
962
|
+
assertErrorThrown(error);
|
|
963
|
+
graph.buildState.fail();
|
|
964
|
+
/**
|
|
965
|
+
* Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
|
|
966
|
+
* But we might want to rethink this decision in the future and throw appropriate type of error
|
|
967
|
+
*/
|
|
968
|
+
throw error instanceof GraphBuilderError
|
|
969
|
+
? error
|
|
970
|
+
: new GraphBuilderError(error);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
// We could optimize this further by omitting parts of the entities we don't need
|
|
974
|
+
// i.e service entity would only keep execution
|
|
975
|
+
async buildGraphForServiceQuerySetup(graph, entities, dependencyEntities) {
|
|
976
|
+
try {
|
|
977
|
+
const graphBuilderInput = await this.indexEntitiesWithDependencyIntoGraph(graph, entities, dependencyEntities, (entity) => entity.content
|
|
978
|
+
._type === V1_SERVICE_ELEMENT_PROTOCOL_TYPE);
|
|
979
|
+
// handle servicess
|
|
980
|
+
const services = [
|
|
981
|
+
...graph.ownServices,
|
|
982
|
+
...graph.dependencyManager.services,
|
|
983
|
+
];
|
|
984
|
+
const v1Services = graphBuilderInput
|
|
985
|
+
.map((e) => e.data.elements.filter((type) => type instanceof V1_Service))
|
|
986
|
+
.flat();
|
|
987
|
+
// build service multi execution keys
|
|
988
|
+
v1Services.forEach((element) => {
|
|
989
|
+
const service = services.find((e) => e.path === element.path);
|
|
990
|
+
if (service) {
|
|
991
|
+
const serviceExecution = element.execution;
|
|
992
|
+
if (serviceExecution instanceof V1_PureMultiExecution) {
|
|
993
|
+
const execution = new PureMultiExecution(serviceExecution.executionKey, RawLambda.createStub(), service);
|
|
994
|
+
execution.executionParameters =
|
|
995
|
+
serviceExecution.executionParameters.map((keyedExecutionParameter) => new KeyedExecutionParameter(keyedExecutionParameter.key, PackageableElementExplicitReference.create(new Mapping('')), new EngineRuntime()));
|
|
996
|
+
service.setExecution(execution);
|
|
997
|
+
}
|
|
998
|
+
else if (serviceExecution instanceof V1_PureSingleExecution) {
|
|
999
|
+
service.setExecution(new PureSingleExecution(RawLambda.createStub(), service, PackageableElementExplicitReference.create(new Mapping('')), new EngineRuntime()));
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
graph.buildState.pass();
|
|
1004
|
+
}
|
|
1005
|
+
catch (error) {
|
|
1006
|
+
assertErrorThrown(error);
|
|
1007
|
+
graph.buildState.fail();
|
|
1008
|
+
/**
|
|
1009
|
+
* Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
|
|
1010
|
+
* But we might want to rethink this decision in the future and throw appropriate type of error
|
|
1011
|
+
*/
|
|
1012
|
+
throw error instanceof GraphBuilderError
|
|
1013
|
+
? error
|
|
1014
|
+
: new GraphBuilderError(error);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
876
1017
|
async getQuery(queryId, graph) {
|
|
877
1018
|
return V1_buildQuery(await this.engine.getQuery(queryId), graph, this.engine.getEngineServerClient().currentUserId);
|
|
878
1019
|
}
|
|
@@ -1038,7 +1179,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
1038
1179
|
graphData.elements = graph.allOwnElements.map((element) => this.elementToProtocol(element, {
|
|
1039
1180
|
keepSourceInformation: options?.keepSourceInformation,
|
|
1040
1181
|
}));
|
|
1041
|
-
this.log.info(LogEvent.create(
|
|
1182
|
+
this.log.info(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_META_MODEL_TO_PROTOCOL_TRANSFORMED), Date.now() - startTime, 'ms');
|
|
1042
1183
|
return graphData;
|
|
1043
1184
|
};
|
|
1044
1185
|
getGraphCompileContext = (graph) => {
|
|
@@ -1050,7 +1191,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
1050
1191
|
...dependencyManager.allElements,
|
|
1051
1192
|
...generatedModel.allOwnElements,
|
|
1052
1193
|
].map((element) => this.elementToProtocol(element));
|
|
1053
|
-
this.log.info(LogEvent.create(
|
|
1194
|
+
this.log.info(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_COMPILE_CONTEXT_COLLECTED), Date.now() - startTime, 'ms');
|
|
1054
1195
|
return graphData;
|
|
1055
1196
|
};
|
|
1056
1197
|
// --------------------------------------------- Utilities ---------------------------------------------
|
|
@@ -1148,7 +1289,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
|
|
|
1148
1289
|
}
|
|
1149
1290
|
catch (error) {
|
|
1150
1291
|
assertErrorThrown(error);
|
|
1151
|
-
this.log.warn(LogEvent.create(
|
|
1292
|
+
this.log.warn(LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MANAGER_FAILURE), `Can't extract assertion result`);
|
|
1152
1293
|
json = undefined;
|
|
1153
1294
|
}
|
|
1154
1295
|
if (!json) {
|