UNPKG

@finos/legend-graph

Version:
87 lines 4.28 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { PureModel, CoreModel, SystemModel, GenerationModel, } from '../graph/PureModel.js'; import { DependencyManager } from '../graph/DependencyManager.js'; import { ActionState, } from '@finos/legend-shared'; import { InstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/mapping/InstanceSetImplementation.js'; import { EmbeddedFlatDataPropertyMapping } from '../graph/metamodel/pure/packageableElements/store/flatData/mapping/EmbeddedFlatDataPropertyMapping.js'; import { EmbeddedRelationalInstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/store/relational/mapping/EmbeddedRelationalInstanceSetImplementation.js'; export class AbstractPureGraphManagerExtension { graphManager; constructor(graphManager) { this.graphManager = graphManager; } } export class AbstractPureGraphManager { extensions = []; pluginManager; logService; constructor(pluginManager, logService) { this.pluginManager = pluginManager; this.logService = logService; this.extensions = pluginManager .getPureGraphManagerPlugins() .flatMap((plugin) => plugin.getExtraPureGraphManagerExtensionBuilders?.() ?? []) .map((builder) => builder(this)) .filter((extension) => extension.getSupportedProtocolVersion() === this.getSupportedProtocolVersion()); } async createBasicGraph(options) { const extensionElementClasses = this.pluginManager.getPureGraphPlugins(); const coreModel = new CoreModel(extensionElementClasses); const systemModel = new SystemModel(extensionElementClasses); if (options?.initializeSystem) { await this.buildSystem(coreModel, systemModel, ActionState.create()); systemModel.initializeAutoImports(); } const graph = new PureModel(coreModel, systemModel, this.pluginManager.getPureGraphPlugins()); return graph; } createDependencyManager() { return new DependencyManager(this.pluginManager.getPureGraphPlugins()); } createGenerationModel() { return new GenerationModel(this.pluginManager.getPureGraphPlugins()); } /** * Check if a mapping element is an instance set implementation * * NOTE: This would account for embedded property mappings as well * these are technically instance of `InstanceSetImplementation` * but since unlike Pure, Typescript cannot do multiple inheritance * we only can make embedded property mapping extends `PropertyMapping` * * Potentially, we might need to apply an extension mechanism on this */ isInstanceSetImplementation(setImplementation) { return (setImplementation instanceof InstanceSetImplementation || setImplementation instanceof EmbeddedFlatDataPropertyMapping || setImplementation instanceof EmbeddedRelationalInstanceSetImplementation); } /** * Filter the list of system elements that will be shown in selection options * to users. This is helpful to avoid overwhelming and confusing users in form * mode since many system elements are needed to build the graph, but should * not present at all as selection options in form mode. */ collectExposedSystemElements(systemElements) { const allowedSystemElements = this.pluginManager .getPureGraphManagerPlugins() .flatMap((plugin) => plugin.getExtraExposedSystemElementPath?.() ?? []); return systemElements.filter((element) => allowedSystemElements.includes(element.path)); } } //# sourceMappingURL=AbstractPureGraphManager.js.map