Skip to content

Commit

Permalink
Add depot get version file generations by type API (#3659)
Browse files Browse the repository at this point in the history
  • Loading branch information
YannanGao-gs authored Nov 18, 2024
1 parent dca547e commit 58b2047
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-parents-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-server-depot': patch
---

Add depot get version file generations by type API
25 changes: 25 additions & 0 deletions packages/legend-server-depot/src/DepotServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { ProjectVersionPlatformDependency } from './models/ProjectVersionPl
import type { VersionedProjectData } from './models/VersionedProjectData.js';
import type { StoreProjectData } from './models/StoreProjectData.js';
import { resolveVersion } from './DepotVersionAliases.js';
import type { StoredFileGeneration } from './models/StoredFileGeneration.js';

export interface DepotServerClientConfig {
serverUrl: string;
Expand Down Expand Up @@ -299,6 +300,8 @@ export class DepotServerClient extends AbstractServerClient {
private _generationContent = (): string =>
`${this.baseUrl}/generationFileContent`;

private _generations = (): string => `${this.baseUrl}/generations`;

private _generationContentByGAV = (
groupId: string,
artifactId: string,
Expand All @@ -310,6 +313,15 @@ export class DepotServerClient extends AbstractServerClient {
versionId,
)}`;

private _generationsByGAV = (
groupId: string,
artifactId: string,
versionId: string,
): string =>
`${this._generations()}/${encodeURIComponent(
groupId,
)}/${encodeURIComponent(artifactId)}/${encodeURIComponent(versionId)}`;

getGenerationContentByPath = async (
project: StoreProjectData,
versionId: string,
Expand All @@ -325,6 +337,19 @@ export class DepotServerClient extends AbstractServerClient {
{ [HttpHeader.ACCEPT]: ContentType.TEXT_PLAIN },
);

getGenerationFilesByType = async (
project: StoreProjectData,
versionId: string,
type: string,
): Promise<PlainObject<StoredFileGeneration>[]> =>
this.get(
`${this._generationsByGAV(
project.groupId,
project.artifactId,
resolveVersion(versionId),
)}/types/${encodeURIComponent(type)}`,
);

// ------------------------------------------- Versions -------------------------------------------

private _versionedStoreProjectData = (
Expand Down
30 changes: 30 additions & 0 deletions packages/legend-server-depot/src/models/DepotGeneration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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 { SerializationFactory } from '@finos/legend-shared';
import { createModelSchema, primitive } from 'serializr';

export class DepotGeneration {
path!: string;
content!: string;

static readonly serialization = new SerializationFactory(
createModelSchema(DepotGeneration, {
path: primitive(),
content: primitive(),
}),
);
}
39 changes: 39 additions & 0 deletions packages/legend-server-depot/src/models/StoredFileGeneration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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 { createModelSchema, primitive } from 'serializr';
import { SerializationFactory, usingModelSchema } from '@finos/legend-shared';
import { DepotGeneration } from './DepotGeneration.js';

export class StoredFileGeneration {
groupId!: string;
artifactId!: string;
versionId!: string;
type!: string;
path!: string;
file!: DepotGeneration;

static readonly serialization = new SerializationFactory(
createModelSchema(StoredFileGeneration, {
groupId: primitive(),
artifactId: primitive(),
versionId: primitive(),
type: primitive(),
path: primitive(),
file: usingModelSchema(DepotGeneration.serialization.schema),
}),
);
}

0 comments on commit 58b2047

Please sign in to comment.