Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: paginator factory #1115

Merged
merged 1 commit into from
Dec 18, 2023
Merged

feat: paginator factory #1115

merged 1 commit into from
Dec 18, 2023

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Dec 15, 2023

Creates a paginator template function to reduce generated code of paginators.

The type returned by the paginator factory is identical to the pre-existing pagination functions. ✅

sample diff: aws/aws-sdk-js-v3#5590

before

import { ListFunctionsCommand, } from "../commands/ListFunctionsCommand";
import { LambdaClient } from "../LambdaClient";
const makePagedClientRequest = async (client, input, ...args) => {
    return await client.send(new ListFunctionsCommand(input), ...args);
};
export async function* paginateListFunctions(config, input, ...additionalArguments) {
    let token = config.startingToken || undefined;
    let hasNext = true;
    let page;
    while (hasNext) {
        input.Marker = token;
        input["MaxItems"] = config.pageSize;
        if (config.client instanceof LambdaClient) {
            page = await makePagedClientRequest(config.client, input, ...additionalArguments);
        }
        else {
            throw new Error("Invalid client, expected Lambda | LambdaClient");
        }
        yield page;
        const prevToken = token;
        token = page.NextMarker;
        hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
    }
    return undefined;
}

after

import { createPaginator } from "@smithy/core";
import { ListFunctionsCommand, } from "../commands/ListFunctionsCommand";
import { LambdaClient } from "../LambdaClient";
export const paginateListFunctions = 
  createPaginator(LambdaClient, ListFunctionsCommand, "Marker", "NextMarker", "MaxItems");

@kuhe kuhe merged commit 12adf84 into smithy-lang:main Dec 18, 2023
7 checks passed
@kuhe kuhe deleted the feat/createPaginator branch December 18, 2023 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants