Skip to content

Commit

Permalink
CHANGE - added a little type lvl restrictions to aws utility
Browse files Browse the repository at this point in the history
  • Loading branch information
sromic committed Aug 11, 2023
1 parent 39f5ea3 commit 63ed97f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client, Command } from "@smithy/smithy-client";
import { MetadataBearer } from "@smithy/types";
import Globals from "./globals";

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ function evaluateBoolean(value: any, defaultValue: boolean): boolean {
* @param nextRequestTokenKey - The response key name that has the next paging token value
* @param params - Parameters to send in the request
*/
async function getAWSPagedResults<ClientOutput, ClientInputCommand, ClientOutputCommand>(
async function getAWSPagedResults<ClientOutput, ClientInputCommand extends object, ClientOutputCommand extends MetadataBearer>(
client: Client<any, any, any, any>,
resultsKey: keyof ClientOutputCommand,
nextTokenKey: keyof ClientInputCommand,
Expand Down
26 changes: 19 additions & 7 deletions test/unit-tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import { expect } from "./base";
import { getAWSPagedResults } from "../../src/utils";
import { mockClient } from "aws-sdk-client-mock";
import { ACMClient, ListCertificatesCommand } from "@aws-sdk/client-acm";
import { ACMClient, CertificateSummary, ListCertificatesCommand, ListCertificatesCommandInput, ListCertificatesCommandOutput } from "@aws-sdk/client-acm";
import { Client } from "@aws-sdk/smithy-client";
import {
APIGatewayClient,
BasePathMapping,
GetBasePathMappingsCommand,
GetBasePathMappingsCommandInput,
GetBasePathMappingsCommandOutput
} from "@aws-sdk/client-api-gateway";
import {
ApiGatewayV2Client,
ApiMapping,
GetApiMappingsCommand,
GetApiMappingsCommandInput,
GetApiMappingsCommandOutput
} from "@aws-sdk/client-apigatewayv2";
import {
CloudFormationClient,
Export,
ListExportsCommand,
ListExportsCommandInput,
ListExportsCommandOutput
} from "@aws-sdk/client-cloudformation";
import {
HostedZone,
ListHostedZonesCommand,
Route53Client,
ListHostedZonesCommandInput,
ListHostedZonesCommandOutput,
Route53Client
} from "@aws-sdk/client-route-53";

describe("Utils checks", () => {
Expand Down Expand Up @@ -48,7 +60,7 @@ describe("Utils checks", () => {

const certStatuses = ["PENDING_VALIDATION", "ISSUED", "INACTIVE"];

const certs = await getAWSPagedResults(
const certs = await getAWSPagedResults<CertificateSummary, ListCertificatesCommandInput, ListCertificatesCommandOutput>(
ACMCMock as unknown as Client<any, any, any, any>,
"CertificateSummaryList",
"NextToken",
Expand Down Expand Up @@ -84,7 +96,7 @@ describe("Utils checks", () => {
],
});

const items = await getAWSPagedResults(
const items = await getAWSPagedResults<BasePathMapping, GetBasePathMappingsCommandInput, GetBasePathMappingsCommandOutput>(
APIGatewayCMock as unknown as Client<any, any, any, any>,
"items",
"position",
Expand Down Expand Up @@ -141,7 +153,7 @@ describe("Utils checks", () => {
],
});

const items = await getAWSPagedResults(
const items = await getAWSPagedResults<ApiMapping, GetApiMappingsCommandInput, GetApiMappingsCommandOutput>(
APIGatewayV2CMock as unknown as Client<any, any, any, any>,
"Items",
"NextToken",
Expand Down Expand Up @@ -181,7 +193,7 @@ describe("Utils checks", () => {
],
});

const items = await getAWSPagedResults(
const items = await getAWSPagedResults<Export, ListExportsCommandInput, ListExportsCommandOutput>(
CloudFormationCMock as unknown as Client<any, any, any, any>,
"Exports",
"NextToken",
Expand Down Expand Up @@ -227,7 +239,7 @@ describe("Utils checks", () => {
],
});

const items = await getAWSPagedResults(
const items = await getAWSPagedResults<HostedZone, ListHostedZonesCommandInput, ListHostedZonesCommandOutput>(
Route53CMock as unknown as Client<any, any, any, any>,
"HostedZones",
"Marker",
Expand Down

0 comments on commit 63ed97f

Please sign in to comment.