UNPKG

@finos/legend-application-marketplace

Version:
80 lines 3.64 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 { IngestDeploymentServerConfig, } from '@finos/legend-server-lakehouse'; import { guaranteeNonNullable } from '@finos/legend-shared'; import { V1_AppDirLevel } from '@finos/legend-graph'; import { action, makeObservable, observable } from 'mobx'; export class LakehouseDataProductService { legendMarketplaceBaseStore; lakehousePlatformServerClient; lakehouseContractServerClient; didToEnvironmentRequestMap = new Map(); didToOwnersRequestMap = new Map(); didToEnvironmentMap = new Map(); didToOwnersMap = new Map(); constructor(legendMarketplaceBaseStore, lakehousePlatformServerClient, lakehouseContractServerClient) { this.legendMarketplaceBaseStore = legendMarketplaceBaseStore; this.lakehousePlatformServerClient = lakehousePlatformServerClient; this.lakehouseContractServerClient = lakehouseContractServerClient; makeObservable(this, { didToEnvironmentMap: observable, didToOwnersMap: observable, setEnvironment: action, setOwners: action, }); } setEnvironment(did, environment) { this.didToEnvironmentMap.set(did, environment); } setOwners(did, owners) { this.didToOwnersMap.set(did, owners); } async fetchEnvironmentForDID(did, token) { const rawResult = await this.lakehousePlatformServerClient.findProducerServer(did, V1_AppDirLevel.DEPLOYMENT, token); return IngestDeploymentServerConfig.serialization.fromJson(rawResult); } async getOrFetchEnvironmentForDID(did, token) { if (this.didToEnvironmentMap.has(did)) { return guaranteeNonNullable(this.didToEnvironmentMap.get(did)); } if (!this.didToEnvironmentRequestMap.has(did)) { this.didToEnvironmentRequestMap.set(did, this.fetchEnvironmentForDID(did, token)); } const environment = guaranteeNonNullable(await this.didToEnvironmentRequestMap.get(did)); this.didToEnvironmentRequestMap.delete(did); this.setEnvironment(did, environment); return environment; } async fetchOwnersForDID(did, token) { const rawResult = await this.lakehouseContractServerClient.getOwnersForDid(did, token); return this.legendMarketplaceBaseStore.applicationStore.pluginManager .getApplicationPlugins() .flatMap((plugin) => plugin.handleDataProductOwnersResponse?.(rawResult) ?? []); } async getOrFetchOwnersForDID(did, token) { if (this.didToOwnersMap.has(did)) { return guaranteeNonNullable(this.didToOwnersMap.get(did)); } if (!this.didToOwnersRequestMap.has(did)) { this.didToOwnersRequestMap.set(did, this.fetchOwnersForDID(did, token)); } const owners = guaranteeNonNullable(await this.didToOwnersRequestMap.get(did)); this.didToOwnersRequestMap.delete(did); this.setOwners(did, owners); return owners; } } //# sourceMappingURL=LakehouseDataProductService.js.map