Skip to content

Commit

Permalink
Merge pull request #513 from mittwald/refactor/listcommand-getdata
Browse files Browse the repository at this point in the history
Make "mapData" implementation for list commands optional
  • Loading branch information
martin-helmich authored May 29, 2024
2 parents 7516df4 + c31753c commit 2c1739a
Show file tree
Hide file tree
Showing 34 changed files with 77 additions and 239 deletions.
17 changes: 7 additions & 10 deletions src/commands/app/dependency/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import {
ListBaseCommand,
SorterFunction,
} from "../../../lib/basecommands/ListBaseCommand.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";

type ResponseItem = Simplify<
Expand All @@ -19,20 +21,15 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
...ListBaseCommand.baseFlags,
};

protected sorter: SorterFunction<ResponseItem> = (a, b) =>
a.tags[0].localeCompare(b.tags[0]) || a.name.localeCompare(b.name);

public async getData(): Promise<Response> {
return await this.apiClient.app.listSystemsoftwares({
pathParameters: {},
} as Parameters<typeof this.apiClient.app.listSystemsoftwares>[0]);
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
data.sort(
(a, b) =>
a.tags[0].localeCompare(b.tags[0]) || a.name.localeCompare(b.name),
);
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id } = super.getColumns(data);
return {
Expand Down
16 changes: 7 additions & 9 deletions src/commands/app/dependency/versions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { assertStatus, Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import {
ListBaseCommand,
SorterFunction,
} from "../../../lib/basecommands/ListBaseCommand.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
import { SemVer } from "semver";
import { Args } from "@oclif/core";
Expand Down Expand Up @@ -30,6 +32,9 @@ export class Versions extends ListBaseCommand<
...ListBaseCommand.baseFlags,
};

sorter: SorterFunction<ResponseItem> = (a, b) =>
new SemVer(a.externalVersion).compare(b.externalVersion);

public async getData(): Promise<Response> {
const systemSoftwareName = this.args["systemsoftware"];

Expand All @@ -49,13 +54,6 @@ export class Versions extends ListBaseCommand<
} as Parameters<typeof this.apiClient.app.listSystemsoftwareversions>[0]);
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
data.sort((a, b) =>
new SemVer(a.externalVersion).compare(b.externalVersion),
);
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const baseColumns = super.getColumns(data);
return {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/app/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { spawnInProcess } from "../../rendering/process/process_exec.js";
import { sshConnectionFlags } from "../../lib/resources/ssh/flags.js";
import { sshUsageDocumentation } from "../../lib/resources/ssh/doc.js";
import {
filterFileToRsyncFlagsIfPresent,
appInstallationSyncFlags,
appInstallationSyncFlagsToRsyncFlags,
filterFileDocumentation,
filterFileToRsyncFlagsIfPresent,
} from "../../lib/resources/app/sync.js";
import { hasBinaryInPath } from "../../lib/util/fs/hasBinaryInPath.js";

Expand Down
7 changes: 0 additions & 7 deletions src/commands/backup/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Response, Simplify } from "@mittwald/api-client-commons";
import type { MittwaldAPIV2 } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../lib/resources/project/flags.js";
import { ListColumns } from "../../rendering/formatter/ListFormatter.js";
Expand All @@ -22,12 +21,6 @@ export class List extends ListBaseCommand<typeof List, ListItem, ListResponse> {
static aliases = ["project:backup:list"];
static deprecateAliases = true;

protected mapData(
data: SuccessfulResponse<ListResponse, 200>["data"],
): ListItem[] | Promise<ListItem[]> {
return data;
}

public async getData(): Promise<ListResponse> {
const projectId = await this.withProjectId(List);
return await this.apiClient.backup.listProjectBackups({
Expand Down
5 changes: 0 additions & 5 deletions src/commands/backup/schedule/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import {
Expand Down Expand Up @@ -42,10 +41,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id, createdAt } = super.getColumns(data);
return {
Expand Down
9 changes: 2 additions & 7 deletions src/commands/conversation/categories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../rendering/formatter/ListFormatter.js";
import { ListBaseCommand } from "../../lib/basecommands/ListBaseCommand.js";

Expand All @@ -23,12 +22,8 @@ export default class Categories extends ListBaseCommand<
...ListBaseCommand.baseFlags,
};

public async getData(): Promise<Response> {
return await this.apiClient.conversation.listCategories();
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
public getData(): Promise<Response> {
return this.apiClient.conversation.listCategories();
}

protected getColumns(): ListColumns<ResponseItem> {
Expand Down
5 changes: 0 additions & 5 deletions src/commands/conversation/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../rendering/formatter/ListFormatter.js";
import { formatRelativeDate } from "../../rendering/textformat/formatDate.js";
import { ListBaseCommand } from "../../lib/basecommands/ListBaseCommand.js";
Expand Down Expand Up @@ -29,10 +28,6 @@ export default class List extends ListBaseCommand<
return await this.apiClient.conversation.listConversations();
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
conversationId: {
Expand Down
5 changes: 0 additions & 5 deletions src/commands/cronjob/execution/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { Flags } from "@oclif/core";
Expand Down Expand Up @@ -35,10 +34,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
return await this.apiClient.cronjob.listExecutions({ cronjobId });
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
id: {},
Expand Down
7 changes: 0 additions & 7 deletions src/commands/cronjob/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../lib/resources/project/flags.js";
import { ListColumns } from "../../rendering/formatter/ListFormatter.js";
Expand Down Expand Up @@ -31,12 +30,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
return await this.apiClient.cronjob.listCronjobs({ projectId });
}

protected mapData(
data: SuccessfulResponse<Response, 200>["data"],
): ResponseItem[] | Promise<ResponseItem[]> {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id, shortId, createdAt } = super.getColumns(data);
return {
Expand Down
9 changes: 3 additions & 6 deletions src/commands/database/mysql/charsets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";

Expand All @@ -24,15 +23,13 @@ export class Charsets extends ListBaseCommand<
...ListBaseCommand.baseFlags,
};

protected sorter = (a: ResponseItem, b: ResponseItem) =>
a.name.localeCompare(b.name);

public async getData(): Promise<Response> {
return await this.apiClient.database.listMysqlCharsets({});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
data.sort((a, b) => a.name.localeCompare(b.name));
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
name: {},
Expand Down
5 changes: 0 additions & 5 deletions src/commands/database/mysql/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../../lib/resources/project/flags.js";
Expand Down Expand Up @@ -28,10 +27,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(ignoredData: ResponseItem[]): ListColumns<ResponseItem> {
const { id, name, createdAt } = super.getColumns(ignoredData, {
shortIdKey: "name",
Expand Down
5 changes: 0 additions & 5 deletions src/commands/database/mysql/user/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../../lib/basecommands/ListBaseCommand.js";
import { Flags } from "@oclif/core";
import { ListColumns } from "../../../../rendering/formatter/ListFormatter.js";
Expand Down Expand Up @@ -30,10 +29,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id, name, createdAt } = super.getColumns(data, {
shortIdKey: "name",
Expand Down
5 changes: 0 additions & 5 deletions src/commands/database/mysql/versions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";

Expand All @@ -27,10 +26,6 @@ export class Versions extends ListBaseCommand<
return await this.apiClient.database.listMysqlVersions({});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
id: { header: "ID" },
Expand Down
5 changes: 0 additions & 5 deletions src/commands/database/redis/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../../lib/resources/project/flags.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
Expand All @@ -26,10 +25,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
return await this.apiClient.database.listRedisDatabases({ projectId });
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id, name, createdAt } = super.getColumns(data, {
shortIdKey: "name",
Expand Down
5 changes: 0 additions & 5 deletions src/commands/database/redis/versions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../../lib/resources/project/flags.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
Expand Down Expand Up @@ -32,10 +31,6 @@ export default class Versions extends ListBaseCommand<
});
}

protected mapData(data: SuccessfulResponse<Response, 200>["data"]) {
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
id: { header: "ID" },
Expand Down
7 changes: 0 additions & 7 deletions src/commands/domain/dnszone/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { projectFlags } from "../../../lib/resources/project/flags.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { Simplify } from "@mittwald/api-client-commons";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
import {
isCustomARecord,
Expand Down Expand Up @@ -38,12 +37,6 @@ export default class List extends ListBaseCommand<
return this.apiClient.domain.dnsListDnsZones({ projectId });
}

protected mapData(
data: SuccessfulResponse<Response, 200>["data"],
): ResponseItem[] | Promise<ResponseItem[]> {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const { id } = super.getColumns(data);
return {
Expand Down
7 changes: 0 additions & 7 deletions src/commands/domain/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { ListBaseCommand } from "../../lib/basecommands/ListBaseCommand.js";
import { projectFlags } from "../../lib/resources/project/flags.js";
import { SuccessfulResponse } from "../../lib/apiutil/SuccessfulResponse.js";
import { ListColumns } from "../../rendering/formatter/ListFormatter.js";

type ResponseItem = Simplify<
Expand All @@ -28,12 +27,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
});
}

protected mapData(
data: SuccessfulResponse<Response, 200>["data"],
): ResponseItem[] | Promise<ResponseItem[]> {
return data;
}

protected getColumns(): ListColumns<ResponseItem> {
return {
id: {
Expand Down
7 changes: 0 additions & 7 deletions src/commands/domain/virtualhost/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Simplify } from "@mittwald/api-client-commons";
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
import { SuccessfulResponse } from "../../../lib/apiutil/SuccessfulResponse.js";
import { ListBaseCommand } from "../../../lib/basecommands/ListBaseCommand.js";
import { Flags } from "@oclif/core";
import { ListColumns } from "../../../rendering/formatter/ListFormatter.js";
Expand Down Expand Up @@ -40,12 +39,6 @@ export class List extends ListBaseCommand<typeof List, ResponseItem, Response> {
});
}

protected mapData(
data: SuccessfulResponse<Response, 200>["data"],
): ResponseItem[] | Promise<ResponseItem[]> {
return data;
}

protected getColumns(data: ResponseItem[]): ListColumns<ResponseItem> {
const baseColumns = super.getColumns(data);
const columns: ListColumns<ResponseItem> = {
Expand Down
1 change: 1 addition & 0 deletions src/commands/mail/address/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as crypto from "crypto";
import { Value } from "../../../rendering/react/components/Value.js";
import { FlagInput, OutputFlags } from "@oclif/core/lib/interfaces/parser.js";
import ByteQuantity from "../../../lib/units/ByteQuantity.js";

type CreateResult = {
addressId: string;
generatedPassword: string | null;
Expand Down
Loading

0 comments on commit 2c1739a

Please sign in to comment.