Skip to content

Warn when list responses contain more pages - #120

Draft
penalosa wants to merge 3 commits into
mainfrom
investigate/issue-20
Draft

penalosa wants to merge 3 commits into
mainfrom
investigate/issue-20

Conversation

@penalosa

Copy link
Copy Markdown
Collaborator

Summary

  • Print a stderr notice when an unfiltered page-number list response reports more pages, while keeping JSON stdout unchanged.
  • Pass the query context from generated GET commands with page and per_page, and suppress the notice when other query values may filter the API's total count.
  • Add a patch changeset and tests for Workers, KV namespaces, and filtered Zones results.

Refs #20

Verification

  • pnpm check
  • pnpm build
  • Focused Vitest runs: 34 tests passed across output, Workers, KV, and Zones tests.
@pkg-pr-new

pkg-pr-new Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@120

commit: f2c9578

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 334.0 ms 5.5 ms 324.2 ms 342.5 ms
base 328.1 ms 7.1 ms 322.5 ms 353.9 ms

Δ (PR vs base): ↑ +5.9 ms (+1.8%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

Comment on lines +68 to +72
const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${data.result.length} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use --page ${page + 1} for more.\n`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --per-page was supplied, suggesting only --page changes the page size back to the API default. Page offsets depend on that size, so the suggested invocation can repeat entries from the displayed page. Preserve the requested page size in the hint.

Suggested change
const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${data.result.length} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use --page ${page + 1} for more.\n`;
const requestedPerPage = positiveInteger(
(query as Record<string, unknown>).per_page
);
const nextPage = `--page ${page + 1}${requestedPerPage === undefined ? "" : ` --per-page ${requestedPerPage}`}`;
const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${data.result.length} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use ${nextPage} for more.\n`;
@ask-bonk

ask-bonk Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.
🤖 I've done a thorough review of your PR.
Adds pagination notices to generated page-number list commands.

  1. Warning: Posted an inline suggestion to preserve explicit --per-page in next-page hints.

github run

Comment on lines +28 to +73
if (
query === undefined ||
Object.entries(query).some(
([key, value]) => key !== "page" && key !== "per_page" && value != null
) ||
data === null ||
typeof data !== "object" ||
!("result" in data) ||
!Array.isArray(data.result) ||
!("result_info" in data) ||
data.result_info === null ||
typeof data.result_info !== "object"
) {
return undefined;
}

const info = data.result_info as Record<string, unknown>;
const page = positiveInteger(info.page);
const count =
info.count === undefined ? undefined : positiveInteger(info.count);
if (
page === undefined ||
data.result.length === 0 ||
(count !== undefined && count !== data.result.length) ||
(info.count !== undefined && count === undefined)
) {
return undefined;
}

const totalCount = positiveInteger(info.total_count);
const perPage = positiveInteger(info.per_page);
const reportedTotalPages = positiveInteger(info.total_pages);
const totalPages =
reportedTotalPages ??
(totalCount !== undefined && perPage !== undefined
? Math.ceil(totalCount / perPage)
: undefined);
if (totalPages === undefined || page >= totalPages) {
return undefined;
}

const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${data.result.length} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use --page ${page + 1} for more.\n`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only recognizes Cloudflare-envelope pagination (result / result_info), but the generator also opts in commands whose SDK response puts pagination at the root. For example, cf cloudforce-one threat-signals feeds list passes paginationQuery here, while ListFeedsResponse is { feeds, count, page, per_page, total_count }; this function returns at the result guard and never prints the new notice. Accept root-level count/page metadata as well so these page-number list responses receive the advertised warning.

Suggested change
if (
query === undefined ||
Object.entries(query).some(
([key, value]) => key !== "page" && key !== "per_page" && value != null
) ||
data === null ||
typeof data !== "object" ||
!("result" in data) ||
!Array.isArray(data.result) ||
!("result_info" in data) ||
data.result_info === null ||
typeof data.result_info !== "object"
) {
return undefined;
}
const info = data.result_info as Record<string, unknown>;
const page = positiveInteger(info.page);
const count =
info.count === undefined ? undefined : positiveInteger(info.count);
if (
page === undefined ||
data.result.length === 0 ||
(count !== undefined && count !== data.result.length) ||
(info.count !== undefined && count === undefined)
) {
return undefined;
}
const totalCount = positiveInteger(info.total_count);
const perPage = positiveInteger(info.per_page);
const reportedTotalPages = positiveInteger(info.total_pages);
const totalPages =
reportedTotalPages ??
(totalCount !== undefined && perPage !== undefined
? Math.ceil(totalCount / perPage)
: undefined);
if (totalPages === undefined || page >= totalPages) {
return undefined;
}
const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${data.result.length} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use --page ${page + 1} for more.\n`;
if (
query === undefined ||
Object.entries(query).some(
([key, value]) => key !== "page" && key !== "per_page" && value != null
) ||
data === null ||
typeof data !== "object"
) {
return undefined;
}
const response = data as Record<string, unknown>;
const result = Array.isArray(response.result) ? response.result : undefined;
const info =
response.result_info !== null && typeof response.result_info === "object"
? (response.result_info as Record<string, unknown>)
: response;
const resultCount = result?.length ?? positiveInteger(info.count);
const page = positiveInteger(info.page);
const count =
info.count === undefined ? undefined : positiveInteger(info.count);
if (
page === undefined ||
resultCount === undefined ||
resultCount === 0 ||
(count !== undefined && count !== resultCount) ||
(info.count !== undefined && count === undefined)
) {
return undefined;
}
const totalCount = positiveInteger(info.total_count);
const perPage = positiveInteger(info.per_page);
const reportedTotalPages = positiveInteger(info.total_pages);
const totalPages =
reportedTotalPages ??
(totalCount !== undefined && perPage !== undefined
? Math.ceil(totalCount / perPage)
: undefined);
if (totalPages === undefined || page >= totalPages) {
return undefined;
}
const shown =
totalCount === undefined
? `Showing page ${page} of ${totalPages}`
: `Showing ${resultCount} of ${totalCount} results (page ${page} of ${totalPages})`;
return `${shown}; use --page ${page + 1} for more.\n`;
@ask-bonk

ask-bonk Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🤖 I've done a thorough review of your PR.

Adds pagination notices for generated page-number list commands.

  1. Warning: Posted an inline suggestion for root-level pagination responses that currently never emit the notice.
  2. Warning: The existing --per-page preservation suggestion remains applicable.

github run

actualHttpMethod === "GET" && hasPageQuery && hasPerPageQuery;
const formatOutputCall = (indent: string): string =>
`${indent}formatOutput(result, { successLabel: \`${escapeForTemplateLiteral(labels.success)}\` });`;
`${indent}formatOutput(result, { successLabel: \`${escapeForTemplateLiteral(labels.success)}\`${checkPagination ? ", paginationQuery: queryParams" : ""} });`;

@ask-bonk ask-bonk Bot Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--quiet is documented to suppress non-essential output, but this newly added pagination hint is still emitted because the generated call always supplies queryParams. Keep the JSON result while disabling only this advisory under --quiet.

Suggested change
`${indent}formatOutput(result, { successLabel: \`${escapeForTemplateLiteral(labels.success)}\`${checkPagination ? ", paginationQuery: queryParams" : ""} });`;
`${indent}formatOutput(result, { successLabel: \`${escapeForTemplateLiteral(labels.success)}\`${checkPagination ? ", paginationQuery: argv.quiet ? undefined : queryParams" : ""} });`;
@ask-bonk

ask-bonk Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.
Posted 1 new inline suggestion.

github run

@ask-bonk

ask-bonk Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

No new concerns since the last review

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants