Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/dapper-fake/src/fakers/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,49 @@ export const getFakePackageVersions = async (
});
};

const fakePackageVersionDependencies = range(25).map(() => ({
description: faker.company.buzzPhrase(),
icon_url: getFakeImg(256, 256),
is_active: faker.datatype.boolean(0.5),
name: faker.word.words(3).split(" ").join("_"),
namespace: faker.word.sample(),
version_number: getVersionNumber(),
is_removed: faker.datatype.boolean(0.5),
}));

export const getFakePackageVersionDependencies = async (
namespace: string,
name: string,
version: string,
page?: number
) => {
setSeed(`${namespace}-${name}-${version}`);
page = page ?? 1;

// Split the fake data into pages of 10 items each.

const start = (page - 1) * 10;
const end = start + 10;
const items = fakePackageVersionDependencies.slice(start, end);

return {
count: fakePackageVersionDependencies.length,
next:
end < fakePackageVersionDependencies.length
? `https://thunderstore.io/api/cyberstorm/package/${namespace}/${name}/v/${version}/dependencies/?page=${
page + 1
}`
: null,
previous:
page > 1
? `https://thunderstore.io/api/cyberstorm/package/${namespace}/${name}/v/${version}/dependencies/?page=${
page - 1
}`
: null,
results: items,
};
};

const getVersionNumber = (min = 0, max = 10) => {
const major = faker.number.int({ min, max });
const minor = faker.number.int({ min, max });
Expand Down
2 changes: 2 additions & 0 deletions packages/dapper-fake/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getFakePackageListingDetails,
getFakePackageListings,
getFakePackagePermissions,
getFakePackageVersionDependencies,
getFakePackageVersions,
getFakePackageSource,
} from "./fakers/package";
Expand All @@ -35,6 +36,7 @@ export class DapperFake implements DapperInterface {
public getPackageReadme = getFakeReadme;
public getPackageVersions = getFakePackageVersions;
public getPackageSource = getFakePackageSource;
public getPackageVersionDependencies = getFakePackageVersionDependencies;
public getTeamDetails = getFakeTeamDetails;
public getTeamMembers = getFakeTeamMembers;
public getTeamServiceAccounts = getFakeServiceAccounts;
Expand Down
12 changes: 12 additions & 0 deletions packages/dapper-ts/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DapperTs } from "../index";
const communityId = "test-community-1";
const namespaceId = "Test_Team_0";
const packageName = "Test_Package_0";
const packageVersion = "1.0.0";
let dapper: DapperTs;

beforeAll(() => {
Expand Down Expand Up @@ -37,6 +38,17 @@ it("executes getPackageChangelog without errors", async () => {
).resolves.not.toThrowError();
});

// TODO: Disabled temporarily until we decide on a testing strategy/policy regarding e2e tests
test.skip("executes getPackageVersionDependencies without errors", async () => {
await expect(
dapper.getPackageVersionDependencies(
namespaceId,
packageName,
packageVersion
)
).resolves.not.toThrowError();
});

it("executes getPackageListingDetails without errors", async () => {
await expect(
dapper.getPackageListingDetails(communityId, namespaceId, packageName)
Expand Down
4 changes: 4 additions & 0 deletions packages/dapper-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getPackageWikiPage,
getPackagePermissions,
getPackageSource,
getPackageVersionDependencies,
} from "./methods/package";
import {
getPackageListingDetails,
Expand Down Expand Up @@ -51,6 +52,8 @@ export class DapperTs implements DapperTsInterface {
this.getPackageListingDetails = this.getPackageListingDetails.bind(this);
this.getPackageReadme = this.getPackageReadme.bind(this);
this.getPackageVersions = this.getPackageVersions.bind(this);
this.getPackageVersionDependencies =
this.getPackageVersionDependencies.bind(this);
this.getPackageWiki = this.getPackageWiki.bind(this);
this.getPackageWikiPage = this.getPackageWikiPage.bind(this);
this.getPackagePermissions = this.getPackagePermissions.bind(this);
Expand All @@ -76,6 +79,7 @@ export class DapperTs implements DapperTsInterface {
public getPackageListingDetails = getPackageListingDetails;
public getPackageReadme = getPackageReadme;
public getPackageVersions = getPackageVersions;
public getPackageVersionDependencies = getPackageVersionDependencies;
public getPackageWiki = getPackageWiki;
public getPackageWikiPage = getPackageWikiPage;
public getPackagePermissions = getPackagePermissions;
Expand Down
30 changes: 30 additions & 0 deletions packages/dapper-ts/src/methods/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
fetchPackagePermissions,
fetchPackageSource,
ApiError,
fetchPackageVersionDependencies,
PackageVersionDependenciesRequestQueryParams,
} from "@thunderstore/thunderstore-api";
import { z } from "zod";

Expand Down Expand Up @@ -101,6 +103,34 @@ export async function getPackageVersions(

return data;
}
export async function getPackageVersionDependencies(
this: DapperTsInterface,
namespaceId: string,
packageName: string,
versionNumber: string,
page?: number
) {
const options: PackageVersionDependenciesRequestQueryParams = [
{
key: "page",
value: page,
impotent: 1,
},
];

const data = await fetchPackageVersionDependencies({
config: this.config,
params: {
namespace_id: namespaceId,
package_name: packageName,
version_number: versionNumber,
},
data: {},
queryParams: options,
});

return data;
}

export async function getPackageWiki(
this: DapperTsInterface,
Expand Down
1 change: 1 addition & 0 deletions packages/dapper/src/dapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DapperInterface {
getPackageListings: methods.GetPackageListings;
getPackageReadme: methods.GetPackageReadme;
getPackageVersions: methods.GetPackageVersions;
getPackageVersionDependencies: methods.GetPackageVersionDependencies;
getPackagePermissions: methods.GetPackagePermissions;
getPackageSource: methods.GetPackageSource;
getTeamDetails: methods.GetTeamDetails;
Expand Down
8 changes: 8 additions & 0 deletions packages/dapper/src/types/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type PackageSource,
type PackageSubmissionResponse,
type PackageVersion,
type PackageVersionDependencies,
} from "./package";
import { type PackageListingType } from "./props";
import { type HTMLContentResponse, type MarkdownResponse } from "./shared";
Expand Down Expand Up @@ -65,6 +66,13 @@ export type GetPackageVersions = (
name: string
) => Promise<PackageVersion[]>;

export type GetPackageVersionDependencies = (
namespace: string,
name: string,
version: string,
page?: number
) => Promise<PackageVersionDependencies>;

export type GetPackagePermissions = (
namespaceId: string,
communityId: string,
Expand Down
17 changes: 17 additions & 0 deletions packages/dapper/src/types/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ export interface PackageVersion {
install_url: string;
}

export interface PackageVersionDependency {
description: string;
icon_url: string;
is_active: boolean;
name: string;
namespace: string;
version_number: string;
is_removed: boolean;
}

export type PackageVersionDependencies = {
count: number;
previous: string | null;
next: string | null;
results: PackageVersionDependency[];
};

export interface PackagePermissions {
package: {
community_id: string;
Expand Down
Loading