@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.
Files changed (92) hide show
  1. package/lib/GraphManagerState.d.ts +2 -2
  2. package/lib/GraphManagerState.js +4 -4
  3. package/lib/GraphManagerState.js.map +1 -1
  4. package/lib/graph/BasicModel.d.ts.map +1 -1
  5. package/lib/graph/BasicModel.js +1 -0
  6. package/lib/graph/BasicModel.js.map +1 -1
  7. package/lib/graph/DependencyManager.d.ts.map +1 -1
  8. package/lib/graph/DependencyManager.js +2 -0
  9. package/lib/graph/DependencyManager.js.map +1 -1
  10. package/lib/graph/PureModel.d.ts.map +1 -1
  11. package/lib/graph/PureModel.js +2 -0
  12. package/lib/graph/PureModel.js.map +1 -1
  13. package/lib/graphManager/AbstractPureGraphManager.d.ts +8 -6
  14. package/lib/graphManager/AbstractPureGraphManager.d.ts.map +1 -1
  15. package/lib/graphManager/AbstractPureGraphManager.js.map +1 -1
  16. package/lib/graphManager/GraphBuilderReport.d.ts +10 -0
  17. package/lib/graphManager/GraphBuilderReport.d.ts.map +1 -1
  18. package/lib/graphManager/GraphBuilderReport.js +6 -0
  19. package/lib/graphManager/GraphBuilderReport.js.map +1 -1
  20. package/lib/graphManager/{GraphManagerLogEvent.d.ts → GraphManagerEvent.d.ts} +12 -19
  21. package/lib/graphManager/GraphManagerEvent.d.ts.map +1 -0
  22. package/lib/graphManager/GraphManagerEvent.js +45 -0
  23. package/lib/graphManager/GraphManagerEvent.js.map +1 -0
  24. package/lib/graphManager/GraphManagerTelemetry.d.ts +28 -0
  25. package/lib/graphManager/GraphManagerTelemetry.d.ts.map +1 -0
  26. package/lib/graphManager/GraphManagerTelemetry.js +22 -0
  27. package/lib/graphManager/GraphManagerTelemetry.js.map +1 -0
  28. package/lib/index.d.ts +5 -2
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/index.js +5 -2
  31. package/lib/index.js.map +1 -1
  32. package/lib/models/protocols/pure/v1/V1_PureGraphManager.d.ts +56 -9
  33. package/lib/models/protocols/pure/v1/V1_PureGraphManager.d.ts.map +1 -1
  34. package/lib/models/protocols/pure/v1/V1_PureGraphManager.js +339 -198
  35. package/lib/models/protocols/pure/v1/V1_PureGraphManager.js.map +1 -1
  36. package/lib/models/protocols/pure/v1/engine/V1_Engine.d.ts.map +1 -1
  37. package/lib/models/protocols/pure/v1/engine/V1_Engine.js +2 -2
  38. package/lib/models/protocols/pure/v1/engine/V1_Engine.js.map +1 -1
  39. package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.d.ts +21 -0
  40. package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.d.ts.map +1 -0
  41. package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.js +22 -0
  42. package/lib/models/protocols/pure/v1/engine/V1_EngineEvent.js.map +1 -0
  43. package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.d.ts +0 -5
  44. package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.d.ts.map +1 -1
  45. package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.js +0 -6
  46. package/lib/models/protocols/pure/v1/engine/V1_EngineServerClient.js.map +1 -1
  47. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.d.ts +0 -2
  48. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.d.ts.map +1 -1
  49. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.js +0 -2
  50. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContext.js.map +1 -1
  51. package/lib/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.d.ts +1 -1
  52. package/lib/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.js +1 -1
  53. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js +2 -2
  54. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js.map +1 -1
  55. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js +4 -4
  56. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js.map +1 -1
  57. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.js +4 -4
  58. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.js.map +1 -1
  59. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.js +2 -2
  60. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.js.map +1 -1
  61. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.d.ts.map +1 -1
  62. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js +3 -7
  63. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js.map +1 -1
  64. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.js +2 -2
  65. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.js.map +1 -1
  66. package/lib/package.json +2 -2
  67. package/package.json +5 -5
  68. package/src/GraphManagerState.ts +4 -4
  69. package/src/graph/BasicModel.ts +2 -0
  70. package/src/graph/DependencyManager.ts +5 -0
  71. package/src/graph/PureModel.ts +8 -0
  72. package/src/graphManager/AbstractPureGraphManager.ts +19 -6
  73. package/src/graphManager/GraphBuilderReport.ts +15 -1
  74. package/src/graphManager/{GraphManagerLogEvent.ts → GraphManagerEvent.ts} +10 -20
  75. package/src/graphManager/GraphManagerTelemetry.ts +35 -0
  76. package/src/index.ts +5 -5
  77. package/src/models/protocols/pure/v1/V1_PureGraphManager.ts +547 -403
  78. package/src/models/protocols/pure/v1/engine/V1_Engine.ts +2 -2
  79. package/src/models/protocols/pure/v1/engine/V1_EngineEvent.ts +21 -0
  80. package/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts +0 -6
  81. package/src/models/protocols/pure/v1/model/context/V1_PureModelContext.ts +1 -5
  82. package/src/models/protocols/pure/v1/model/valueSpecification/raw/V1_HackedUnit.ts +1 -1
  83. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.ts +2 -2
  84. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.ts +4 -4
  85. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_SectionBuilderHelper.ts +4 -4
  86. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ServiceBuilderHelper.ts +2 -2
  87. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.ts +4 -9
  88. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationPathResolver.ts +2 -2
  89. package/tsconfig.json +3 -1
  90. package/lib/graphManager/GraphManagerLogEvent.d.ts.map +0 -1
  91. package/lib/graphManager/GraphManagerLogEvent.js +0 -53
  92. package/lib/graphManager/GraphManagerLogEvent.js.map +0 -1
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { flow, flowResult, makeObservable, runInAction } from 'mobx';
18
- import { GRAPH_MANAGER_LOG_EVENT } from '../../../../graphManager/GraphManagerLogEvent';
18
+ import { GRAPH_MANAGER_EVENT } from '../../../../graphManager/GraphManagerEvent';
19
19
  import {
20
20
  CORE_PURE_PATH,
21
21
  ELEMENT_PATH_DELIMITER,
@@ -37,6 +37,9 @@ import {
37
37
  assertTrue,
38
38
  assertErrorThrown,
39
39
  promisify,
40
+ type ActionState,
41
+ StopWatch,
42
+ assertNonEmptyString,
40
43
  } from '@finos/legend-shared';
41
44
  import type { TEMPORARY__AbstractEngineConfig } from '../../../../graphManager/action/TEMPORARY__AbstractEngineConfig';
42
45
  import {
@@ -45,8 +48,11 @@ import {
45
48
  type GraphBuilderOptions,
46
49
  type ExecutionOptions,
47
50
  } from '../../../../graphManager/AbstractPureGraphManager';
48
- import type { Mapping } from '../../../metamodels/pure/packageableElements/mapping/Mapping';
49
- import type { Runtime } from '../../../metamodels/pure/packageableElements/runtime/Runtime';
51
+ import { Mapping } from '../../../metamodels/pure/packageableElements/mapping/Mapping';
52
+ import {
53
+ type Runtime,
54
+ EngineRuntime,
55
+ } from '../../../metamodels/pure/packageableElements/runtime/Runtime';
50
56
  import type {
51
57
  ImportConfigurationDescription,
52
58
  ImportMode,
@@ -74,7 +80,11 @@ import type { ExecutionResult } from '../../../../graphManager/action/execution/
74
80
  import type { GenerationOutput } from '../../../../graphManager/action/generation/GenerationOutput';
75
81
  import type { ValueSpecification } from '../../../metamodels/pure/valueSpecification/ValueSpecification';
76
82
  import { ServiceExecutionMode } from '../../../../graphManager/action/service/ServiceExecutionMode';
77
- import { PureSingleExecution } from '../../../metamodels/pure/packageableElements/service/ServiceExecution';
83
+ import {
84
+ KeyedExecutionParameter,
85
+ PureMultiExecution,
86
+ PureSingleExecution,
87
+ } from '../../../metamodels/pure/packageableElements/service/ServiceExecution';
78
88
  import {
79
89
  V1_deserializeRawValueSpecification,
80
90
  V1_serializeRawValueSpecification,
@@ -160,6 +170,7 @@ import type { V1_Multiplicity } from './model/packageableElements/domain/V1_Mult
160
170
  import type { V1_RawVariable } from './model/rawValueSpecification/V1_RawVariable';
161
171
  import { V1_setupDatabaseSerialization } from './transformation/pureProtocol/serializationHelpers/V1_DatabaseSerializationHelper';
162
172
  import {
173
+ V1_PACKAGEABLE_RUNTIME_ELEMENT_PROTOCOL_TYPE,
163
174
  V1_setupEngineRuntimeSerialization,
164
175
  V1_setupLegacyRuntimeSerialization,
165
176
  } from './transformation/pureProtocol/serializationHelpers/V1_RuntimeSerializationHelper';
@@ -206,12 +217,23 @@ import {
206
217
  GraphBuilderError,
207
218
  SystemGraphBuilderError,
208
219
  } from '../../../../graphManager/GraphManagerUtils';
209
- import { PackageableElementReference } from '../../../metamodels/pure/packageableElements/PackageableElementReference';
220
+ import {
221
+ PackageableElementExplicitReference,
222
+ PackageableElementReference,
223
+ } from '../../../metamodels/pure/packageableElements/PackageableElementReference';
210
224
  import type { GraphPluginManager } from '../../../../GraphPluginManager';
211
225
  import type { QuerySearchSpecification } from '../../../../graphManager/action/query/QuerySearchSpecification';
212
226
  import type { ExternalFormatDescription } from '../../../../graphManager/action/externalFormat/ExternalFormatDescription';
213
227
  import type { ConfigurationProperty } from '../../../metamodels/pure/packageableElements/fileGeneration/ConfigurationProperty';
214
228
  import { V1_ExternalFormatModelGenerationInput } from './engine/externalFormat/V1_ExternalFormatModelGeneration';
229
+ import { GraphBuilderReport } from '../../../../graphManager/GraphBuilderReport';
230
+ import {
231
+ V1_PureMultiExecution,
232
+ V1_PureSingleExecution,
233
+ } from './model/packageableElements/service/V1_ServiceExecution';
234
+ import { V1_MAPPING_ELEMENT_PROTOCOL_TYPE } from './transformation/pureProtocol/serializationHelpers/V1_MappingSerializationHelper';
235
+ import { V1_SERVICE_ELEMENT_PROTOCOL_TYPE } from './transformation/pureProtocol/serializationHelpers/V1_ServiceSerializationHelper';
236
+ import { MappingInclude } from '../../../metamodels/pure/packageableElements/mapping/MappingInclude';
215
237
 
216
238
  const V1_FUNCTION_SUFFIX_MULTIPLICITY_INFINITE = 'MANY';
217
239
 
@@ -271,7 +293,20 @@ class V1_PureModelContextDataIndex {
271
293
  >();
272
294
  }
273
295
 
296
+ const mergePureModelContextData = (
297
+ ...data: V1_PureModelContextData[]
298
+ ): V1_PureModelContextData => {
299
+ const mergedData = new V1_PureModelContextData();
300
+ for (const _data of data) {
301
+ mergedData.elements = mergedData.elements.concat(_data.elements);
302
+ mergedData.serializer = _data.serializer ?? mergedData.serializer;
303
+ mergedData.origin = _data.origin ?? mergedData.origin;
304
+ }
305
+ return mergedData;
306
+ };
307
+
274
308
  const indexPureModelContextData = (
309
+ report: GraphBuilderReport,
275
310
  data: V1_PureModelContextData,
276
311
  extensions: V1_GraphBuilderExtensions,
277
312
  ): V1_PureModelContextDataIndex => {
@@ -331,6 +366,42 @@ const indexPureModelContextData = (
331
366
  (index.otherElementsByBuilder.get(builder) ?? []).concat(elements),
332
367
  );
333
368
  });
369
+
370
+ // report
371
+ report.elementCount.total = report.elementCount.total + index.elements.length;
372
+ report.elementCount.other =
373
+ (report.elementCount.other ?? 0) +
374
+ otherElementsByClass.size +
375
+ index.fileGenerations.length +
376
+ index.generationSpecifications.length;
377
+ report.elementCount.sectionIndex =
378
+ (report.elementCount.sectionIndex ?? 0) + index.sectionIndices.length;
379
+
380
+ report.elementCount.association =
381
+ (report.elementCount.association ?? 0) + index.associations.length;
382
+ report.elementCount.class =
383
+ (report.elementCount.class ?? 0) + index.classes.length;
384
+ report.elementCount.enumeration =
385
+ (report.elementCount.enumeration ?? 0) + index.enumerations.length;
386
+ report.elementCount.function =
387
+ (report.elementCount.function ?? 0) + index.functions.length;
388
+ report.elementCount.profile =
389
+ (report.elementCount.profile ?? 0) + index.profiles.length;
390
+ report.elementCount.measure =
391
+ (report.elementCount.measure ?? 0) + index.measures.length;
392
+
393
+ report.elementCount.store =
394
+ (report.elementCount.store ?? 0) + index.stores.length;
395
+ report.elementCount.mapping =
396
+ (report.elementCount.mapping ?? 0) + index.mappings.length;
397
+ report.elementCount.connection =
398
+ (report.elementCount.connection ?? 0) + index.connections.length;
399
+ report.elementCount.runtime =
400
+ (report.elementCount.runtime ?? 0) + index.runtimes.length;
401
+
402
+ report.elementCount.service =
403
+ (report.elementCount.service ?? 0) + index.services.length;
404
+
334
405
  return index;
335
406
  };
336
407
 
@@ -358,22 +429,24 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
358
429
 
359
430
  makeObservable<
360
431
  V1_PureGraphManager,
432
+ | 'buildGraphFromInputs'
361
433
  | 'initializeAndIndexElements'
362
434
  | 'postProcess'
363
435
  | 'buildTypes'
364
436
  | 'buildStores'
365
437
  | 'buildMappings'
366
438
  | 'buildConnectionsAndRuntimes'
367
- | 'buildSectionIndex'
439
+ | 'buildSectionIndices'
368
440
  | 'buildOtherElements'
369
441
  | 'buildServices'
370
442
  | 'buildFileGenerations'
371
- | 'buildGenerationSpecificationss'
443
+ | 'buildGenerationSpecifications'
372
444
  >(this, {
373
445
  initialize: flow,
374
446
  buildSystem: flow,
375
447
  buildDependencies: flow,
376
448
  buildGraph: flow,
449
+ buildGraphFromInputs: flow,
377
450
  buildGenerations: flow,
378
451
  initializeAndIndexElements: flow,
379
452
  postProcess: flow,
@@ -381,11 +454,11 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
381
454
  buildStores: flow,
382
455
  buildMappings: flow,
383
456
  buildConnectionsAndRuntimes: flow,
384
- buildSectionIndex: flow,
457
+ buildSectionIndices: flow,
385
458
  buildOtherElements: flow,
386
459
  buildServices: flow,
387
460
  buildFileGenerations: flow,
388
- buildGenerationSpecificationss: flow,
461
+ buildGenerationSpecifications: flow,
389
462
  });
390
463
 
391
464
  // setup plugins
@@ -433,8 +506,11 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
433
506
  coreModel: CoreModel,
434
507
  systemModel: SystemModel,
435
508
  options?: GraphBuilderOptions,
436
- ): GeneratorFn<void> {
437
- const startTime = Date.now();
509
+ ): GeneratorFn<GraphBuilderReport> {
510
+ const stopWatch = new StopWatch();
511
+ const report = new GraphBuilderReport();
512
+ const graphBuilderState = systemModel.buildState;
513
+ graphBuilderState.reset();
438
514
 
439
515
  // Create a dummy graph for system processing. This is to ensure system model does not depend on the main graph
440
516
  const graph = new PureModel(
@@ -442,63 +518,56 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
442
518
  systemModel,
443
519
  this.pluginManager.getPureGraphPlugins(),
444
520
  );
521
+
445
522
  try {
446
- const systemData = new V1_PureModelContextData();
447
- yield V1_entitiesToPureModelContextData(
448
- /**
449
- * Get all system entities.
450
- *
451
- * NOTE: right now, we are doing extra work here: JSON -> protocol -> entities -> protocol, since we are
452
- * expecting to get these models from some a remote SDLC project in the future.
453
- */
454
- V1_deserializePureModelContextData(V1_CORE_SYSTEM_MODELS)
455
- .elements.concat(
456
- this.pluginManager
457
- .getPureProtocolProcessorPlugins()
458
- .flatMap((plugin) => plugin.V1_getExtraSystemModels?.() ?? [])
459
- .flatMap(
460
- (modelContextData) =>
461
- V1_deserializePureModelContextData(modelContextData).elements,
462
- ),
463
- )
464
- .map((element) => this.elementProtocolToEntity(element)),
465
- systemData,
466
- this.pluginManager.getPureProtocolProcessorPlugins(),
523
+ // deserialize
524
+ graphBuilderState.setMessage(`Collecting and deserializing elements...`);
525
+ const systemData = mergePureModelContextData(
526
+ V1_deserializePureModelContextData(V1_CORE_SYSTEM_MODELS),
527
+ ...this.pluginManager
528
+ .getPureProtocolProcessorPlugins()
529
+ .flatMap((plugin) => plugin.V1_getExtraSystemModels?.() ?? [])
530
+ .map((modelContextData) =>
531
+ V1_deserializePureModelContextData(modelContextData),
532
+ ),
467
533
  );
468
- const systemGraphBuilderInput = [
534
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
535
+
536
+ // prepare build inputs
537
+ const buildInputs = [
469
538
  {
470
539
  model: systemModel,
471
- data: indexPureModelContextData(systemData, this.extensions),
540
+ data: indexPureModelContextData(report, systemData, this.extensions),
472
541
  },
473
542
  ];
543
+
544
+ // build
474
545
  yield flowResult(
475
- this.initializeAndIndexElements(graph, systemGraphBuilderInput),
546
+ this.buildGraphFromInputs(
547
+ graph,
548
+ buildInputs,
549
+ report,
550
+ stopWatch,
551
+ graphBuilderState,
552
+ options,
553
+ ),
476
554
  );
477
- // NOTE: right now we only have profile and enumeration for system, we might need to generalize this step in the future
478
- yield flowResult(this.buildTypes(graph, systemGraphBuilderInput));
479
- yield flowResult(this.buildOtherElements(graph, systemGraphBuilderInput));
480
- yield flowResult(this.postProcess(graph, systemGraphBuilderInput));
481
- if (!options?.quiet) {
482
- this.log.info(
483
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SYSTEM_BUILT),
484
- Date.now() - startTime,
485
- 'ms',
486
- `[class: ${systemModel.ownClasses.length}, profile: ${systemModel.ownProfiles.length}, enumeration: ${systemModel.ownEnumerations.length}]`,
487
- );
488
- }
489
- systemModel.buildState.pass();
555
+
556
+ graphBuilderState.pass();
557
+ report.timings = {
558
+ ...Object.fromEntries(stopWatch.records),
559
+ [GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
560
+ };
561
+ return report;
490
562
  } catch (error) {
491
563
  assertErrorThrown(error);
492
- systemModel.buildState.fail();
493
- if (!options?.quiet) {
494
- this.log.info(
495
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FAILURE),
496
- '[ERROR]',
497
- Date.now() - startTime,
498
- 'ms',
499
- );
500
- }
564
+ graphBuilderState.fail();
565
+ this.log.error(
566
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE),
567
+ );
501
568
  throw new SystemGraphBuilderError(error);
569
+ } finally {
570
+ graphBuilderState.setMessage(undefined);
502
571
  }
503
572
  }
504
573
 
@@ -508,21 +577,12 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
508
577
  dependencyManager: DependencyManager,
509
578
  dependencyEntitiesMap: Map<string, Entity[]>,
510
579
  options?: GraphBuilderOptions,
511
- ): GeneratorFn<void> {
512
- const startTime = Date.now();
513
- if (!options?.quiet) {
514
- this.log.info(
515
- LogEvent.create(
516
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_ENTITIES_FETCHED,
517
- ),
518
- Date.now() - startTime,
519
- 'ms',
520
- `[projects: ${dependencyEntitiesMap.size}, entities: ${
521
- Array.from(dependencyEntitiesMap.values()).flat().length
522
- }]`,
523
- );
524
- }
525
- dependencyManager.buildState.reset();
580
+ ): GeneratorFn<GraphBuilderReport> {
581
+ const stopWatch = new StopWatch();
582
+ const report = new GraphBuilderReport();
583
+ const graphBuilderState = dependencyManager.buildState;
584
+ graphBuilderState.reset();
585
+
526
586
  // Create a dummy graph for system processing. This is to ensure dependency models do not depend on the main graph
527
587
  const graph = new PureModel(
528
588
  coreModel,
@@ -530,9 +590,14 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
530
590
  this.pluginManager.getPureGraphPlugins(),
531
591
  );
532
592
  graph.setDependencyManager(dependencyManager);
593
+
533
594
  try {
534
595
  dependencyManager.initialize(dependencyEntitiesMap);
535
- // Parse/Build Data
596
+
597
+ // deserialize
598
+ graphBuilderState.setMessage(
599
+ `Partitioning and deserializing elements...`,
600
+ );
536
601
  const dependencyDataMap = new Map<string, V1_PureModelContextData>();
537
602
  yield Promise.all(
538
603
  Array.from(dependencyEntitiesMap.entries()).map(
@@ -547,84 +612,48 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
547
612
  },
548
613
  ),
549
614
  );
550
- const preprocessingFinishedTime = Date.now();
551
- if (!options?.quiet) {
552
- this.log.info(
553
- LogEvent.create(
554
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_PREPROCESSED,
555
- ),
556
- preprocessingFinishedTime - startTime,
557
- 'ms',
558
- );
559
- }
615
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
560
616
 
561
- const graphBuilderInput: V1_GraphBuilderInput[] = Array.from(
617
+ // prepare build inputs
618
+ const buildInputs: V1_GraphBuilderInput[] = Array.from(
562
619
  dependencyDataMap.entries(),
563
620
  ).map(([dependencyKey, dependencyData]) => ({
564
- data: indexPureModelContextData(dependencyData, this.extensions),
621
+ data: indexPureModelContextData(
622
+ report,
623
+ dependencyData,
624
+ this.extensions,
625
+ ),
565
626
  model: graph.dependencyManager.getModel(dependencyKey),
566
627
  }));
628
+
629
+ // build
567
630
  yield flowResult(
568
- this.initializeAndIndexElements(graph, graphBuilderInput, options),
569
- );
570
- // NOTE: we might need to process sectionIndex if we support unresolved element paths in dependencies
571
- yield flowResult(this.buildTypes(graph, graphBuilderInput, options));
572
- yield flowResult(this.buildStores(graph, graphBuilderInput, options));
573
- yield flowResult(this.buildMappings(graph, graphBuilderInput, options));
574
- yield flowResult(
575
- this.buildConnectionsAndRuntimes(graph, graphBuilderInput, options),
576
- );
577
- yield flowResult(this.buildServices(graph, graphBuilderInput, options));
578
- yield flowResult(
579
- this.buildFileGenerations(graph, graphBuilderInput, options),
580
- );
581
- yield flowResult(
582
- this.buildGenerationSpecificationss(graph, graphBuilderInput, options),
583
- );
584
- yield flowResult(
585
- this.buildOtherElements(graph, graphBuilderInput, options),
631
+ this.buildGraphFromInputs(
632
+ graph,
633
+ buildInputs,
634
+ report,
635
+ stopWatch,
636
+ graphBuilderState,
637
+ options,
638
+ ),
586
639
  );
587
640
 
588
- yield flowResult(this.postProcess(graph, graphBuilderInput));
589
- const processingFinishedTime = Date.now();
590
- if (!options?.quiet) {
591
- this.log.info(
592
- LogEvent.create(
593
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_PROCESSED,
594
- ),
595
- processingFinishedTime - preprocessingFinishedTime,
596
- 'ms',
597
- );
598
- }
599
-
600
- dependencyManager.buildState.pass();
601
- if (!options?.quiet) {
602
- this.log.info(
603
- LogEvent.create(
604
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_BUILT,
605
- ),
606
- '[TOTAL]',
607
- Date.now() - startTime,
608
- 'ms',
609
- );
610
- }
641
+ graphBuilderState.pass();
642
+ report.otherStats.projectCount = dependencyEntitiesMap.size;
643
+ report.timings = {
644
+ ...Object.fromEntries(stopWatch.records),
645
+ [GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
646
+ };
647
+ return report;
611
648
  } catch (error) {
612
649
  assertErrorThrown(error);
613
- if (!options?.quiet) {
614
- this.log.info(
615
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FAILURE),
616
- '[ERROR]',
617
- Date.now() - startTime,
618
- 'ms',
619
- `[elements: ${
620
- Array.from(dependencyManager.projectDependencyModelsIndex.values())
621
- .map((v) => v.allOwnElements)
622
- .flat().length
623
- }]`,
624
- );
625
- }
626
- dependencyManager.buildState.fail();
650
+ this.log.error(
651
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE),
652
+ );
653
+ graphBuilderState.fail();
627
654
  throw new DependencyGraphBuilderError(error);
655
+ } finally {
656
+ graphBuilderState.setMessage(undefined);
628
657
  }
629
658
  }
630
659
 
@@ -632,221 +661,55 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
632
661
  graph: PureModel,
633
662
  entities: Entity[],
634
663
  options?: GraphBuilderOptions,
635
- ): GeneratorFn<void> {
636
- let stepStartTime = Date.now();
637
- let stepFinishedTime;
638
- const startTime = stepStartTime;
664
+ ): GeneratorFn<GraphBuilderReport> {
665
+ const stopWatch = new StopWatch();
666
+ const report = new GraphBuilderReport();
667
+ const graphBuilderState = graph.buildState;
668
+ graphBuilderState.reset();
669
+
639
670
  try {
640
- // Parse/Build Data
671
+ // deserialize
672
+ graphBuilderState.setMessage(`Deserializing elements...`);
641
673
  const data = new V1_PureModelContextData();
642
674
  yield V1_entitiesToPureModelContextData(
643
675
  entities,
644
676
  data,
645
677
  this.pluginManager.getPureProtocolProcessorPlugins(),
646
678
  );
679
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
647
680
 
648
- const graphBuilderInput: V1_GraphBuilderInput[] = [
681
+ // prepare build inputs
682
+ const buildInputs: V1_GraphBuilderInput[] = [
649
683
  {
650
684
  model: graph,
651
- data: indexPureModelContextData(data, this.extensions),
685
+ data: indexPureModelContextData(report, data, this.extensions),
652
686
  },
653
687
  ];
654
- stepFinishedTime = Date.now();
655
- if (!options?.quiet) {
656
- this.log.info(
657
- LogEvent.create(
658
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DATA_MODEL_PARSED,
659
- ),
660
- stepFinishedTime - stepStartTime,
661
- 'ms',
662
- );
663
- }
664
- stepStartTime = stepFinishedTime;
665
-
666
- yield flowResult(
667
- this.initializeAndIndexElements(graph, graphBuilderInput, options),
668
- );
669
- stepFinishedTime = Date.now();
670
- if (!options?.quiet) {
671
- this.log.info(
672
- LogEvent.create(
673
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_ELEMENTS_INITIALIZED_AND_INDEXED,
674
- ),
675
- stepFinishedTime - stepStartTime,
676
- 'ms',
677
- `[element: ${data.elements.length}]`,
678
- );
679
- }
680
- stepStartTime = stepFinishedTime;
681
-
682
- // Section index
683
- yield flowResult(
684
- this.buildSectionIndex(graph, graphBuilderInput, options),
685
- );
686
- stepFinishedTime = Date.now();
687
- if (!options?.quiet) {
688
- this.log.info(
689
- LogEvent.create(
690
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SECTION_INDICES_BUILT,
691
- ),
692
- stepFinishedTime - stepStartTime,
693
- 'ms',
694
- `[sectionIndex: ${graph.ownSectionIndices.length}]`,
695
- );
696
- }
697
- stepStartTime = stepFinishedTime;
698
- // Types
699
- yield flowResult(this.buildTypes(graph, graphBuilderInput, options));
700
- stepFinishedTime = Date.now();
701
- if (!options?.quiet) {
702
- this.log.info(
703
- LogEvent.create(
704
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DOMAIN_MODELS_BUILT,
705
- ),
706
- stepFinishedTime - stepStartTime,
707
- 'ms',
708
- `[class: ${graph.ownClasses.length}, enumeration: ${graph.ownEnumerations.length}, association: ${graph.ownAssociations.length}, profile: ${graph.ownProfiles.length}, functions: ${graph.ownFunctions.length}]`,
709
- );
710
- }
711
- stepStartTime = stepFinishedTime;
712
-
713
- // Stores
714
- yield flowResult(this.buildStores(graph, graphBuilderInput, options));
715
- stepFinishedTime = Date.now();
716
- // TODO: we might want to detail out the number of stores by type
717
- if (!options?.quiet) {
718
- this.log.info(
719
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_STORES_BUILT),
720
- stepFinishedTime - stepStartTime,
721
- 'ms',
722
- `[store: ${graph.ownStores.length}]`,
723
- );
724
- }
725
- stepStartTime = stepFinishedTime;
726
-
727
- // Mappings
728
- yield flowResult(this.buildMappings(graph, graphBuilderInput, options));
729
- stepFinishedTime = Date.now();
730
- if (!options?.quiet) {
731
- this.log.info(
732
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_MAPPINGS_BUILT),
733
- stepFinishedTime - stepStartTime,
734
- 'ms',
735
- `[mapping: ${graph.ownMappings.length}]`,
736
- );
737
- }
738
- stepStartTime = stepFinishedTime;
739
-
740
- // Connections and runtimes
741
- yield flowResult(
742
- this.buildConnectionsAndRuntimes(graph, graphBuilderInput, options),
743
- );
744
- stepFinishedTime = Date.now();
745
- if (!options?.quiet) {
746
- this.log.info(
747
- LogEvent.create(
748
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_CONNECTIONS_BUILT,
749
- ),
750
- stepFinishedTime - stepStartTime,
751
- 'ms',
752
- `[connection: ${graph.ownConnections.length}]`,
753
- );
754
- this.log.info(
755
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_RUNTIMES_BUILT),
756
- stepFinishedTime - stepStartTime,
757
- 'ms',
758
- `[runtime: ${graph.ownRuntimes.length}]`,
759
- );
760
- }
761
- stepStartTime = stepFinishedTime;
762
-
763
- // Services
764
- yield flowResult(this.buildServices(graph, graphBuilderInput, options));
765
- stepFinishedTime = Date.now();
766
- if (!options?.quiet) {
767
- this.log.info(
768
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SERVICES_BUILT),
769
- stepFinishedTime - stepStartTime,
770
- 'ms',
771
- `[service: ${graph.ownServices.length}]`,
772
- );
773
- }
774
- stepStartTime = stepFinishedTime;
775
-
776
- // File Generation
777
- yield flowResult(
778
- this.buildFileGenerations(graph, graphBuilderInput, options),
779
- );
780
- stepFinishedTime = Date.now();
781
- if (!options?.quiet) {
782
- this.log.info(
783
- LogEvent.create(
784
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FILE_GENERATIONS_BUILT,
785
- ),
786
- stepFinishedTime - stepStartTime,
787
- 'ms',
788
- `[file-generation: ${graph.ownFileGenerations.length}]`,
789
- );
790
- }
791
- stepStartTime = stepFinishedTime;
792
-
793
- // Generation Specifications (tree)
794
- yield flowResult(
795
- this.buildGenerationSpecificationss(graph, graphBuilderInput, options),
796
- );
797
- stepFinishedTime = Date.now();
798
- if (!options?.quiet) {
799
- this.log.info(
800
- LogEvent.create(
801
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_GENERATION_TREE_BUILT,
802
- ),
803
- stepFinishedTime - stepStartTime,
804
- 'ms',
805
- `[generation-specification: ${graph.ownGenerationSpecifications.length}]`,
806
- );
807
- }
808
- stepStartTime = stepFinishedTime;
809
688
 
810
- // Other elements
689
+ // build
811
690
  yield flowResult(
812
- this.buildOtherElements(graph, graphBuilderInput, options),
691
+ this.buildGraphFromInputs(
692
+ graph,
693
+ buildInputs,
694
+ report,
695
+ stopWatch,
696
+ graphBuilderState,
697
+ options,
698
+ ),
813
699
  );
814
- stepFinishedTime = Date.now();
815
- if (!options?.quiet) {
816
- this.log.info(
817
- LogEvent.create(
818
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_OTHER_ELEMENTS_BUILT,
819
- ),
820
- stepFinishedTime - stepStartTime,
821
- 'ms',
822
- );
823
- }
824
700
 
825
- yield flowResult(
826
- this.postProcess(graph, graphBuilderInput, {
827
- TEMPORARY__keepSectionIndex: options?.TEMPORARY__keepSectionIndex,
828
- }),
829
- );
830
- graph.buildState.pass();
831
- if (!options?.quiet) {
832
- this.log.info(
833
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_COMPLETED),
834
- '[TOTAL]',
835
- Date.now() - startTime,
836
- 'ms',
837
- );
838
- }
701
+ graphBuilderState.pass();
702
+ report.timings = {
703
+ ...Object.fromEntries(stopWatch.records),
704
+ [GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
705
+ };
706
+ return report;
839
707
  } catch (error) {
840
708
  assertErrorThrown(error);
841
- if (!options?.quiet) {
842
- this.log.info(
843
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FAILURE),
844
- '[ERROR]',
845
- Date.now() - startTime,
846
- 'ms',
847
- );
848
- }
849
- graph.buildState.fail();
709
+ this.log.error(
710
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE),
711
+ );
712
+ graphBuilderState.fail();
850
713
  /**
851
714
  * Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
852
715
  * But we might want to rethink this decision in the future and throw appropriate type of error
@@ -854,6 +717,8 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
854
717
  throw error instanceof GraphBuilderError
855
718
  ? error
856
719
  : new GraphBuilderError(error);
720
+ } finally {
721
+ graphBuilderState.setMessage(undefined);
857
722
  }
858
723
  }
859
724
 
@@ -861,18 +726,16 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
861
726
  graph: PureModel,
862
727
  generatedEntities: Map<string, Entity[]>,
863
728
  options?: GraphBuilderOptions,
864
- ): GeneratorFn<void> {
865
- const stepStartTime = Date.now();
729
+ ): GeneratorFn<GraphBuilderReport> {
730
+ const stopWatch = new StopWatch();
731
+ const report = new GraphBuilderReport();
866
732
  const generatedModel = graph.generationModel;
867
- generatedModel.buildState.reset();
733
+ const graphBuilderState = generatedModel.buildState;
734
+ graphBuilderState.reset();
735
+
868
736
  try {
869
- if (!options?.quiet) {
870
- this.log.info(
871
- LogEvent.create(
872
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DATA_MODEL_PARSED,
873
- ),
874
- );
875
- }
737
+ // deserialize
738
+ graphBuilderState.setMessage(`Deserializing elements...`);
876
739
  const generatedDataMap = new Map<string, V1_PureModelContextData>();
877
740
  yield Promise.all(
878
741
  Array.from(generatedEntities.entries()).map(
@@ -887,57 +750,46 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
887
750
  },
888
751
  ),
889
752
  );
890
- const generationGraphBuilderInput = Array.from(
891
- generatedDataMap.entries(),
892
- ).map(([generationParentPath, generatedData]) => ({
893
- parentElementPath: generationParentPath,
894
- data: indexPureModelContextData(generatedData, this.extensions),
895
- model: generatedModel,
896
- }));
897
-
898
- yield flowResult(
899
- this.initializeAndIndexElements(graph, generationGraphBuilderInput),
753
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_DESERIALIZED);
754
+
755
+ // prepare build inputs
756
+ const buildInputs = Array.from(generatedDataMap.entries()).map(
757
+ ([generationParentPath, generatedData]) => ({
758
+ parentElementPath: generationParentPath,
759
+ data: indexPureModelContextData(
760
+ report,
761
+ generatedData,
762
+ this.extensions,
763
+ ),
764
+ model: generatedModel,
765
+ }),
900
766
  );
901
767
 
902
- yield flowResult(this.buildTypes(graph, generationGraphBuilderInput));
903
- yield flowResult(this.buildStores(graph, generationGraphBuilderInput));
904
- yield flowResult(this.buildMappings(graph, generationGraphBuilderInput));
905
- yield flowResult(
906
- this.buildConnectionsAndRuntimes(graph, generationGraphBuilderInput),
907
- );
908
- yield flowResult(this.buildServices(graph, generationGraphBuilderInput));
909
- yield flowResult(
910
- this.buildFileGenerations(graph, generationGraphBuilderInput),
911
- );
912
- yield flowResult(
913
- this.buildGenerationSpecificationss(graph, generationGraphBuilderInput),
914
- );
768
+ // build
915
769
  yield flowResult(
916
- this.buildOtherElements(graph, generationGraphBuilderInput),
770
+ this.buildGraphFromInputs(
771
+ graph,
772
+ buildInputs,
773
+ report,
774
+ stopWatch,
775
+ graphBuilderState,
776
+ options,
777
+ ),
917
778
  );
918
779
 
919
- yield flowResult(this.postProcess(graph, generationGraphBuilderInput));
920
- generatedModel.buildState.pass();
921
- if (!options?.quiet) {
922
- this.log.info(
923
- LogEvent.create(
924
- GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_GENERATIONS_BUILT,
925
- ),
926
- Date.now() - stepStartTime,
927
- `${graph.generationModel.allOwnElements.length} generated elements processed`,
928
- 'ms',
929
- );
930
- }
780
+ graphBuilderState.pass();
781
+ report.otherStats.generationCount = generatedDataMap.size;
782
+ report.timings = {
783
+ ...Object.fromEntries(stopWatch.records),
784
+ [GRAPH_MANAGER_EVENT.GRAPH_BUILDER_COMPLETED]: stopWatch.elapsed,
785
+ };
786
+ return report;
931
787
  } catch (error) {
932
788
  assertErrorThrown(error);
933
- if (!options?.quiet) {
934
- this.log.info(
935
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_FAILURE),
936
- Date.now() - stepStartTime,
937
- 'ms',
938
- );
939
- }
940
- generatedModel.buildState.fail();
789
+ this.log.error(
790
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_FAILURE),
791
+ );
792
+ graphBuilderState.fail();
941
793
  /**
942
794
  * Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
943
795
  * But we might want to rethink this decision in the future and throw appropriate type of error
@@ -945,9 +797,77 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
945
797
  throw error instanceof GraphBuilderError
946
798
  ? error
947
799
  : new GraphBuilderError(error);
800
+ } finally {
801
+ graphBuilderState.setMessage(undefined);
948
802
  }
949
803
  }
950
804
 
805
+ private *buildGraphFromInputs(
806
+ graph: PureModel,
807
+ inputs: V1_GraphBuilderInput[],
808
+ report: GraphBuilderReport,
809
+ stopWatch: StopWatch,
810
+ graphBuilderState: ActionState,
811
+ options?: GraphBuilderOptions,
812
+ ): GeneratorFn<void> {
813
+ // index
814
+ graphBuilderState.setMessage(
815
+ `Indexing ${report.elementCount.total} elements...`,
816
+ );
817
+ yield flowResult(this.initializeAndIndexElements(graph, inputs, options));
818
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_ELEMENTS_INDEXED);
819
+
820
+ // build section index
821
+ graphBuilderState.setMessage(`Building section indices...`);
822
+ yield flowResult(this.buildSectionIndices(graph, inputs, options));
823
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_SECTION_INDICES_BUILT);
824
+
825
+ // build types
826
+ graphBuilderState.setMessage(`Building domain models...`);
827
+ yield flowResult(this.buildTypes(graph, inputs, options));
828
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_DOMAIN_MODELS_BUILT);
829
+
830
+ // build stores
831
+ graphBuilderState.setMessage(`Building stores...`);
832
+ yield flowResult(this.buildStores(graph, inputs, options));
833
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_STORES_BUILT);
834
+
835
+ // build mappings
836
+ graphBuilderState.setMessage(`Building mappings...`);
837
+ yield flowResult(this.buildMappings(graph, inputs, options));
838
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_MAPPINGS_BUILT);
839
+
840
+ // build connections and runtimes
841
+ graphBuilderState.setMessage(`Building connections and runtimes...`);
842
+ yield flowResult(this.buildConnectionsAndRuntimes(graph, inputs, options));
843
+ stopWatch.record(
844
+ GRAPH_MANAGER_EVENT.GRAPH_BUILDER_CONNECTIONS_AND_RUNTIMES_BUILT,
845
+ );
846
+
847
+ // build services
848
+ graphBuilderState.setMessage(`Building services...`);
849
+ yield flowResult(this.buildServices(graph, inputs, options));
850
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_SERVICES_BUILT);
851
+
852
+ // build other elements
853
+ graphBuilderState.setMessage(`Building other elements...`);
854
+ yield flowResult(this.buildFileGenerations(graph, inputs, options));
855
+ yield flowResult(
856
+ this.buildGenerationSpecifications(graph, inputs, options),
857
+ );
858
+ yield flowResult(this.buildOtherElements(graph, inputs, options));
859
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_OTHER_ELEMENTS_BUILT);
860
+
861
+ // post-process
862
+ graphBuilderState.setMessage(`Post-processing graph...`);
863
+ yield flowResult(
864
+ this.postProcess(graph, inputs, {
865
+ TEMPORARY__keepSectionIndex: options?.TEMPORARY__keepSectionIndex,
866
+ }),
867
+ );
868
+ stopWatch.record(GRAPH_MANAGER_EVENT.GRAPH_BUILDER_POST_PROCESSED);
869
+ }
870
+
951
871
  private getBuilderContext(
952
872
  graph: PureModel,
953
873
  currentSubGraph: BasicModel,
@@ -1332,7 +1252,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1332
1252
  );
1333
1253
  }
1334
1254
 
1335
- private *buildGenerationSpecificationss(
1255
+ private *buildGenerationSpecifications(
1336
1256
  graph: PureModel,
1337
1257
  inputs: V1_GraphBuilderInput[],
1338
1258
  options?: GraphBuilderOptions,
@@ -1351,7 +1271,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1351
1271
  );
1352
1272
  }
1353
1273
 
1354
- private *buildSectionIndex(
1274
+ private *buildSectionIndices(
1355
1275
  graph: PureModel,
1356
1276
  inputs: V1_GraphBuilderInput[],
1357
1277
  options?: GraphBuilderOptions,
@@ -1479,9 +1399,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1479
1399
  graphData,
1480
1400
  );
1481
1401
  this.log.info(
1482
- LogEvent.create(
1483
- GRAPH_MANAGER_LOG_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED,
1484
- ),
1402
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED),
1485
1403
  Date.now() - startTime,
1486
1404
  'ms',
1487
1405
  );
@@ -1494,9 +1412,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1494
1412
  await this.entitiesToPureModelContextData(entities),
1495
1413
  );
1496
1414
  this.log.info(
1497
- LogEvent.create(
1498
- GRAPH_MANAGER_LOG_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED,
1499
- ),
1415
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MODEL_TO_GRAMMAR_TRANSFORMED),
1500
1416
  Date.now() - startTime,
1501
1417
  'ms',
1502
1418
  );
@@ -1816,7 +1732,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1816
1732
  );
1817
1733
  }
1818
1734
 
1819
- pureProtocolToEntities = (protocol: string): Entity[] => {
1735
+ pureProtocolTextToEntities = (protocol: string): Entity[] => {
1820
1736
  const graphData = V1_deserializePureModelContextData(JSON.parse(protocol));
1821
1737
  return this.pureModelContextDataToEntities(graphData);
1822
1738
  };
@@ -2119,6 +2035,234 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
2119
2035
  );
2120
2036
  }
2121
2037
 
2038
+ async indexEntitiesWithDependencyIntoGraph(
2039
+ graph: PureModel,
2040
+ _entities: Entity[],
2041
+ dependencyEntities: Map<string, Entity[]>,
2042
+ entityFilterFunc?: (entity: Entity) => boolean,
2043
+ ): Promise<V1_GraphBuilderInput[]> {
2044
+ let entities = _entities;
2045
+ graph.dependencyManager.initialize(dependencyEntities);
2046
+ if (entityFilterFunc) {
2047
+ Array.from(dependencyEntities.entries()).forEach(
2048
+ ([dependencyKey, dEntities]) => {
2049
+ dependencyEntities.set(
2050
+ dependencyKey,
2051
+ dEntities.filter(entityFilterFunc),
2052
+ );
2053
+ },
2054
+ );
2055
+ entities = _entities.filter(entityFilterFunc);
2056
+ }
2057
+ const report = new GraphBuilderReport();
2058
+ // build dependency pmcd models
2059
+ const dependencyDataMap = new Map<string, V1_PureModelContextData>();
2060
+ await Promise.all(
2061
+ Array.from(dependencyEntities.entries()).map(([dependencyKey, value]) => {
2062
+ const projectModelData = new V1_PureModelContextData();
2063
+ dependencyDataMap.set(dependencyKey, projectModelData);
2064
+ return V1_entitiesToPureModelContextData(
2065
+ value,
2066
+ projectModelData,
2067
+
2068
+ this.pluginManager.getPureProtocolProcessorPlugins(),
2069
+ );
2070
+ }),
2071
+ );
2072
+ const dependencyGraphBuilderInput: V1_GraphBuilderInput[] = Array.from(
2073
+ dependencyDataMap.entries(),
2074
+ ).map(([dependencyKey, dependencyData]) => ({
2075
+ data: indexPureModelContextData(report, dependencyData, this.extensions),
2076
+ model: graph.dependencyManager.getModel(dependencyKey),
2077
+ }));
2078
+ // build main pmcd
2079
+ const data = new V1_PureModelContextData();
2080
+ await V1_entitiesToPureModelContextData(
2081
+ entities,
2082
+ data,
2083
+ this.pluginManager.getPureProtocolProcessorPlugins(),
2084
+ );
2085
+ const mainGraphBuilderInput: V1_GraphBuilderInput[] = [
2086
+ {
2087
+ model: graph,
2088
+ data: indexPureModelContextData(report, data, this.extensions),
2089
+ },
2090
+ ];
2091
+ const graphBuilderInput = [
2092
+ ...dependencyGraphBuilderInput,
2093
+ ...mainGraphBuilderInput,
2094
+ ];
2095
+ await flowResult(this.initializeAndIndexElements(graph, graphBuilderInput));
2096
+ return graphBuilderInput;
2097
+ }
2098
+
2099
+ // We could optimize this further by omitting parts of the entities we don't need
2100
+ async buildGraphForCreateQuerySetup(
2101
+ graph: PureModel,
2102
+ entities: Entity[],
2103
+ dependencyEntities: Map<string, Entity[]>,
2104
+ ): Promise<void> {
2105
+ try {
2106
+ const graphBuilderInput = await this.indexEntitiesWithDependencyIntoGraph(
2107
+ graph,
2108
+ entities,
2109
+ dependencyEntities,
2110
+ (entity: Entity): boolean =>
2111
+ ((entity.content as PlainObject<V1_PackageableElement>)
2112
+ ._type as string) === V1_MAPPING_ELEMENT_PROTOCOL_TYPE ||
2113
+ ((entity.content as PlainObject<V1_PackageableElement>)
2114
+ ._type as string) === V1_PACKAGEABLE_RUNTIME_ELEMENT_PROTOCOL_TYPE,
2115
+ );
2116
+ // handle mapping includes
2117
+ const mappings = [
2118
+ ...graph.ownMappings,
2119
+ ...graph.dependencyManager.mappings,
2120
+ ];
2121
+ const v1Mappings = graphBuilderInput
2122
+ .map((e) =>
2123
+ e.data.elements.filter(
2124
+ (type: V1_PackageableElement): type is V1_Mapping =>
2125
+ type instanceof V1_Mapping,
2126
+ ),
2127
+ )
2128
+ .flat();
2129
+ const context = new V1_GraphBuilderContextBuilder(
2130
+ graph,
2131
+ graph,
2132
+ this.extensions,
2133
+ this.log,
2134
+ ).build();
2135
+ // build include index for compatible runtime analysis
2136
+ v1Mappings.forEach((element) => {
2137
+ const mapping = mappings.find((e) => e.path === element.path);
2138
+ if (mapping) {
2139
+ mapping.includes = element.includedMappings.map((i) => {
2140
+ assertNonEmptyString(
2141
+ i.includedMappingPath,
2142
+ `Mapping include 'includedMappingPath' field is missing or empty`,
2143
+ );
2144
+ return new MappingInclude(
2145
+ mapping,
2146
+ context.resolveMapping(i.includedMappingPath),
2147
+ );
2148
+ });
2149
+ }
2150
+ });
2151
+ // handle runtimes
2152
+ const runtimes = [
2153
+ ...graph.ownRuntimes,
2154
+ ...graph.dependencyManager.runtimes,
2155
+ ];
2156
+ const v1Runtimes = graphBuilderInput
2157
+ .map((e) =>
2158
+ e.data.elements.filter(
2159
+ (type: V1_PackageableElement): type is V1_PackageableRuntime =>
2160
+ type instanceof V1_PackageableRuntime,
2161
+ ),
2162
+ )
2163
+ .flat();
2164
+ v1Runtimes.forEach((element) => {
2165
+ const runtime = runtimes.find((e) => e.path === element.path);
2166
+ if (runtime) {
2167
+ const runtimeValue = new EngineRuntime();
2168
+ runtime.setRuntimeValue(runtimeValue);
2169
+ runtimeValue.setMappings(
2170
+ element.runtimeValue.mappings.map((mapping) =>
2171
+ context.resolveMapping(mapping.path),
2172
+ ),
2173
+ );
2174
+ }
2175
+ });
2176
+ graph.buildState.pass();
2177
+ } catch (error) {
2178
+ assertErrorThrown(error);
2179
+ graph.buildState.fail();
2180
+ /**
2181
+ * Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
2182
+ * But we might want to rethink this decision in the future and throw appropriate type of error
2183
+ */
2184
+ throw error instanceof GraphBuilderError
2185
+ ? error
2186
+ : new GraphBuilderError(error);
2187
+ }
2188
+ }
2189
+
2190
+ // We could optimize this further by omitting parts of the entities we don't need
2191
+ // i.e service entity would only keep execution
2192
+ async buildGraphForServiceQuerySetup(
2193
+ graph: PureModel,
2194
+ entities: Entity[],
2195
+ dependencyEntities: Map<string, Entity[]>,
2196
+ ): Promise<void> {
2197
+ try {
2198
+ const graphBuilderInput = await this.indexEntitiesWithDependencyIntoGraph(
2199
+ graph,
2200
+ entities,
2201
+ dependencyEntities,
2202
+ (entity: Entity): boolean =>
2203
+ ((entity.content as PlainObject<V1_PackageableElement>)
2204
+ ._type as string) === V1_SERVICE_ELEMENT_PROTOCOL_TYPE,
2205
+ );
2206
+ // handle servicess
2207
+ const services = [
2208
+ ...graph.ownServices,
2209
+ ...graph.dependencyManager.services,
2210
+ ];
2211
+ const v1Services = graphBuilderInput
2212
+ .map((e) =>
2213
+ e.data.elements.filter(
2214
+ (type: V1_PackageableElement): type is V1_Service =>
2215
+ type instanceof V1_Service,
2216
+ ),
2217
+ )
2218
+ .flat();
2219
+ // build service multi execution keys
2220
+ v1Services.forEach((element) => {
2221
+ const service = services.find((e) => e.path === element.path);
2222
+ if (service) {
2223
+ const serviceExecution = element.execution;
2224
+ if (serviceExecution instanceof V1_PureMultiExecution) {
2225
+ const execution = new PureMultiExecution(
2226
+ serviceExecution.executionKey,
2227
+ RawLambda.createStub(),
2228
+ service,
2229
+ );
2230
+ execution.executionParameters =
2231
+ serviceExecution.executionParameters.map(
2232
+ (keyedExecutionParameter) =>
2233
+ new KeyedExecutionParameter(
2234
+ keyedExecutionParameter.key,
2235
+ PackageableElementExplicitReference.create(new Mapping('')),
2236
+ new EngineRuntime(),
2237
+ ),
2238
+ );
2239
+ service.setExecution(execution);
2240
+ } else if (serviceExecution instanceof V1_PureSingleExecution) {
2241
+ service.setExecution(
2242
+ new PureSingleExecution(
2243
+ RawLambda.createStub(),
2244
+ service,
2245
+ PackageableElementExplicitReference.create(new Mapping('')),
2246
+ new EngineRuntime(),
2247
+ ),
2248
+ );
2249
+ }
2250
+ }
2251
+ });
2252
+ graph.buildState.pass();
2253
+ } catch (error) {
2254
+ assertErrorThrown(error);
2255
+ graph.buildState.fail();
2256
+ /**
2257
+ * Wrap all error with `GraphBuilderError`, as we throw a lot of assertion error in the graph builder
2258
+ * But we might want to rethink this decision in the future and throw appropriate type of error
2259
+ */
2260
+ throw error instanceof GraphBuilderError
2261
+ ? error
2262
+ : new GraphBuilderError(error);
2263
+ }
2264
+ }
2265
+
2122
2266
  async getQuery(queryId: string, graph: PureModel): Promise<Query> {
2123
2267
  return V1_buildQuery(
2124
2268
  await this.engine.getQuery(queryId),
@@ -2374,7 +2518,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
2374
2518
  );
2375
2519
  this.log.info(
2376
2520
  LogEvent.create(
2377
- GRAPH_MANAGER_LOG_EVENT.GRAPH_META_MODEL_TO_PROTOCOL_TRANSFORMED,
2521
+ GRAPH_MANAGER_EVENT.GRAPH_META_MODEL_TO_PROTOCOL_TRANSFORMED,
2378
2522
  ),
2379
2523
  Date.now() - startTime,
2380
2524
  'ms',
@@ -2394,7 +2538,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
2394
2538
  ...generatedModel.allOwnElements,
2395
2539
  ].map((element) => this.elementToProtocol(element));
2396
2540
  this.log.info(
2397
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_COMPILE_CONTEXT_COLLECTED),
2541
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_COMPILE_CONTEXT_COLLECTED),
2398
2542
  Date.now() - startTime,
2399
2543
  'ms',
2400
2544
  );
@@ -2522,7 +2666,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
2522
2666
  } catch (error) {
2523
2667
  assertErrorThrown(error);
2524
2668
  this.log.warn(
2525
- LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_MANAGER_FAILURE),
2669
+ LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MANAGER_FAILURE),
2526
2670
  `Can't extract assertion result`,
2527
2671
  );
2528
2672
  json = undefined;