UNPKG

@finos/legend-server-depot

Version:
132 lines 8.31 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 { EntitiesWithOrigin, } from '@finos/legend-storage'; import { AbstractServerClient, HttpHeader, ContentType, } from '@finos/legend-shared'; import { ProjectVersionEntities, } from './models/ProjectVersionEntities.js'; import { resolveVersion } from './DepotVersionAliases.js'; export class DepotServerClient extends AbstractServerClient { constructor(config) { super({ baseUrl: config.serverUrl, }); } // ------------------------------------------- Projects ------------------------------------------- _projects = () => `${this.baseUrl}/projects`; _projectConfigurations = () => `${this.baseUrl}/project-configurations`; _project = (groupId, artifactId) => `${this._projects()}/${encodeURIComponent(groupId)}/${encodeURIComponent(artifactId)}`; getProjects = () => this.get(this._projectConfigurations()); getProject = (groupId, artifactId) => this.get(`${this._projectConfigurations()}/${encodeURIComponent(groupId)}/${encodeURIComponent(artifactId)}`); // ------------------------------------------- Entities ------------------------------------------- _versions = (groupId, artifactId) => `${this._project(groupId, artifactId)}/versions`; _version = (groupId, artifactId, version, classifier) => `${this._versions(groupId, artifactId)}/${encodeURIComponent(version)}${classifier ? `/classifiers/${classifier}` : ``}`; getAllVersions = (groupId, artifactId) => this.get(this._versions(groupId, artifactId)); getVersionEntities = (groupId, artifactId, version, classifier) => this.get(this._version(groupId, artifactId, version, classifier)); getEntities(project, versionId, classifier) { return this.getVersionEntities(project.groupId, project.artifactId, resolveVersion(versionId), classifier); } getVersionEntity = (groupId, artifactId, version, entityPath) => this.get(`${this._version(groupId, artifactId, version)}/entities/${encodeURIComponent(entityPath)}`); getEntity(project, versionId, entityPath) { return this.getVersionEntity(project.groupId, project.artifactId, resolveVersion(versionId), entityPath); } // NOTE: this is experimental API to get elements by classifier path DEPRECATED_getEntitiesByClassifierPath = (classifierPath, options) => this.get(`${this.baseUrl}/entitiesByClassifierPath/${encodeURIComponent(classifierPath)}`, undefined, undefined, { search: options?.search, scope: options?.scope, limit: options?.limit, }); getEntitiesByClassifier = (classifierPath, options) => this.get(`${this.baseUrl}/classifiers/${encodeURIComponent(classifierPath)}/entities`, undefined, undefined, { scope: options?.scope, }); getEntitiesSummaryByClassifier = (classifierPath, options) => this.get(`${this.baseUrl}/classifiers/${encodeURIComponent(classifierPath)}`, undefined, undefined, { scope: options?.scope, summary: options?.summary, latest: options?.latest, }); // ------------------------------------------- Dependants ------------------------------------------- getAllDependantProjects = (groupId, artifactId) => this.get(`${this._versions(groupId, artifactId)}/all/dependantProjects`, undefined, undefined); getDependantProjects = (groupId, artifactId, version) => this.get(`${this._version(groupId, artifactId, version)}/dependantProjects`, undefined, undefined); async getIndexedDependantProjects(groupId, artifactId, version) { const dependants = version ? await this.getDependantProjects(groupId, artifactId, version) : await this.getAllDependantProjects(groupId, artifactId); return dependants; } // ------------------------------------------- Dependencies ------------------------------------------- getDependencyEntities = (groupId, artifactId, version, /** * Flag indicating if transitive dependencies should be returned. */ transitive, /** * Flag indicating whether to return the root of the dependency tree. */ includeOrigin, classifier) => this.get(`${this._version(groupId, artifactId, version)}${classifier ? `/classifiers/${classifier}` : ''}/dependencies`, undefined, undefined, { transitive, includeOrigin, versioned: false, // we don't need to add version prefix to entity path }); async getIndexedDependencyEntities(project, versionId, classifier) { const dependencyEntitiesIndex = new Map(); const dependencies = await this.getDependencyEntities(project.groupId, project.artifactId, resolveVersion(versionId), true, false, classifier); dependencies .map((v) => ProjectVersionEntities.serialization.fromJson(v)) .forEach((dependencyInfo) => { dependencyEntitiesIndex.set(dependencyInfo.id, new EntitiesWithOrigin(dependencyInfo.groupId, dependencyInfo.artifactId, dependencyInfo.versionId, dependencyInfo.entities)); }); return dependencyEntitiesIndex; } collectDependencyEntities = ( /** * List of (direct) dependencies. */ dependencies, /** * Flag indicating if transitive dependencies should be returned. */ transitive, /** * Flag indicating whether to return the root of the dependency tree. */ includeOrigin) => this.post(`${this._projects()}/dependencies`, dependencies, undefined, undefined, { transitive, includeOrigin, versioned: false, // we don't need to add version prefix to entity path }); analyzeDependencyTree = ( /** * List of (direct) dependencies. */ dependencies) => this.post(`${this._projects()}/analyzeDependencyTree`, dependencies); // ------------------------------------------- File Generation ------------------------------------------- _generationContent = () => `${this.baseUrl}/generationFileContent`; _generations = () => `${this.baseUrl}/generations`; _generationContentByGAV = (groupId, artifactId, versionId) => `${this._generationContent()}/${encodeURIComponent(groupId)}/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}`; _generationsByGAV = (groupId, artifactId, versionId) => `${this._generations()}/${encodeURIComponent(groupId)}/${encodeURIComponent(artifactId)}/${encodeURIComponent(versionId)}`; getGenerationContentByPath = async (project, versionId, filePath) => this.get(`${this._generationContentByGAV(project.groupId, project.artifactId, resolveVersion(versionId))}/file/${encodeURIComponent(filePath)}`, {}, { [HttpHeader.ACCEPT]: ContentType.TEXT_PLAIN }); getGenerationFilesByType = async (project, versionId, type) => this.get(`${this._generationsByGAV(project.groupId, project.artifactId, resolveVersion(versionId))}/types/${encodeURIComponent(type)}`); // ------------------------------------------- Versions ------------------------------------------- _versionedStoreProjectData = (groupId, artifactId) => `${this.baseUrl}/versions/${encodeURIComponent(groupId)}/${encodeURIComponent(artifactId)}`; getVersions = (groupId, artifactId, /** * Flag indicating whether to return the snapshot versions or not */ snapshots) => this.get(`${this._project(groupId, artifactId)}/versions`, undefined, undefined, { snapshots: snapshots, }); getLatestVersion = (groupId, artifactId) => this.get(`${this._versionedStoreProjectData(groupId, artifactId)}/latest`); getVersionedProjectData = (groupId, artifactId, versionId) => this.get(`${this._versionedStoreProjectData(groupId, artifactId)}/${encodeURIComponent(versionId)}`); } //# sourceMappingURL=DepotServerClient.js.map