Skip to content

Commit 9c60f3b

Browse files
author
wafuwafu13
committed
feat: Improve AWSIntegrationServices type
1 parent b90a696 commit 9c60f3b

File tree

3 files changed

+56
-18
lines changed

3 files changed

+56
-18
lines changed

awsintegrations.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
import { PayloadType } from "./mackerel.ts";
22

3+
const awsServices = [
4+
"EC2",
5+
"ELB",
6+
"ALB",
7+
"RDS",
8+
"Redshift",
9+
"ElastiCache",
10+
"SQS",
11+
"Lambda",
12+
"NLB",
13+
"DynamoDB",
14+
"CloudFront",
15+
"APIGateway",
16+
"Kinesis",
17+
"S3",
18+
"ES",
19+
"ECSCluster",
20+
"SES",
21+
"States",
22+
"EFS",
23+
"Firehose",
24+
"Batch",
25+
"WAF",
26+
"Billing",
27+
"Route53",
28+
"Connect",
29+
"DocDB",
30+
"CodeBuild",
31+
] as const;
32+
33+
type AWSService = typeof awsServices[number];
34+
35+
type AWSIntegrationService = {
36+
enable: boolean;
37+
role: string | null;
38+
excludedMetrics: string[];
39+
retireAutomatically?: boolean;
40+
};
41+
42+
export type AWSIntegrationServices = {
43+
[S in AWSService]?: AWSIntegrationService;
44+
};
45+
346
export type AWSIntegration = {
447
id: string;
548
name: string;
@@ -10,14 +53,7 @@ export type AWSIntegration = {
1053
region: string;
1154
includedTags: string;
1255
excludedTags: string;
13-
services: Record<string, AWSIntegrationService>;
14-
};
15-
16-
export type AWSIntegrationService = {
17-
enable: boolean;
18-
role: string | null;
19-
excludedMetrics: string[];
20-
retireAutomatically?: boolean;
56+
services: AWSIntegrationServices;
2157
};
2258

2359
export type RegisterAWSIntegrationParam = {
@@ -30,7 +66,7 @@ export type RegisterAWSIntegrationParam = {
3066
region: string;
3167
includedTags: string;
3268
excludedTags: string;
33-
services: Record<string, AWSIntegrationService>;
69+
services: AWSIntegrationServices;
3470
};
3571

3672
export type UpdateAWSIntegrationParam =
@@ -40,7 +76,9 @@ export type UpdateAWSIntegrationParam =
4076
"name" | "memo" | "region" | "includedTags" | "excludedTags" | "services"
4177
>;
4278

43-
export type ListAWSIntegrationExcludableMetrics = Record<string, string[]>;
79+
export type ListAWSIntegrationExcludableMetrics = {
80+
[S in AWSService]?: string[];
81+
};
4482

4583
export const listAwsIntegrationSettings = async (
4684
urlFor: (path: string) => URL,

awsintegrations_test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Deno.test("listAwsIntegrationSettings", async () => {
4141
const client = new Mackerel.Client(dummyApiKey, dummyBaseurl);
4242
const resp = await client.listAwsIntegrationSettings();
4343
assertEquals(resp[0].name, "test-aws-integration");
44-
assertEquals(resp[0].services["EC2"].retireAutomatically, false);
44+
assertEquals(resp[0].services["EC2"]!.retireAutomatically, false);
4545
mf.uninstall();
4646
});
4747

@@ -80,7 +80,7 @@ Deno.test("getAwsIntegrationSettings", async () => {
8080
const client = new Mackerel.Client(dummyApiKey, dummyBaseurl);
8181
const resp = await client.getAwsIntegrationSettings(awsIntegrationID);
8282
assertEquals(resp.id, awsIntegrationID);
83-
assertEquals(resp.services["EC2"].retireAutomatically, false);
83+
assertEquals(resp.services["EC2"]!.retireAutomatically, false);
8484
mf.uninstall();
8585
});
8686

@@ -124,7 +124,7 @@ Deno.test("registerAwsIntegrationSettings", async () => {
124124
const client = new Mackerel.Client(dummyApiKey, dummyBaseurl);
125125
const resp = await client.registerAwsIntegrationSettings(registerParam);
126126
assertEquals(resp.id, "testid");
127-
assertEquals(resp.services["S3"].enable, true);
127+
assertEquals(resp.services["S3"]!.enable, true);
128128
mf.uninstall();
129129
});
130130

@@ -174,7 +174,7 @@ Deno.test("updateAwsIntegrationSettings", async () => {
174174
updateParam,
175175
);
176176
assertEquals(resp.id, "testid");
177-
assertEquals(resp.services["ALB"].enable, true);
177+
assertEquals(resp.services["ALB"]!.enable, true);
178178
mf.uninstall();
179179
});
180180

@@ -213,7 +213,7 @@ Deno.test("deleteAwsIntegrationSettings", async () => {
213213
const client = new Mackerel.Client(dummyApiKey, dummyBaseurl);
214214
const resp = await client.deleteAwsIntegrationSettings(awsIntegrationID);
215215
assertEquals(resp.id, awsIntegrationID);
216-
assertEquals(resp.services["EC2"].retireAutomatically, false);
216+
assertEquals(resp.services["EC2"]!.retireAutomatically, false);
217217
mf.uninstall();
218218
});
219219

@@ -251,6 +251,6 @@ Deno.test("listExcludableMetricsForAwsIntegration", async () => {
251251
);
252252
const client = new Mackerel.Client(dummyApiKey, dummyBaseurl);
253253
const resp = await client.listExcludableMetricsForAwsIntegration();
254-
assertEquals(resp["ELB"][1], "testmetrics2");
254+
assertEquals(resp["ELB"]![1], "testmetrics2");
255255
mf.uninstall();
256256
});

mackerel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "./service.ts";
88
import {
99
AWSIntegration,
10-
AWSIntegrationService,
10+
AWSIntegrationServices,
1111
deleteAwsIntegrationSettings,
1212
generateAwsIntegrationExternalID,
1313
getAwsIntegrationSettings,
@@ -38,7 +38,7 @@ type ErrorType = {
3838
export type PayloadType =
3939
| Record<
4040
never | string,
41-
never | string | number | null | Record<string, AWSIntegrationService>
41+
never | string | number | null | AWSIntegrationServices
4242
>
4343
| null;
4444

0 commit comments

Comments
 (0)