Skip to content

Commit

Permalink
Add generics for any types
Browse files Browse the repository at this point in the history
  • Loading branch information
zwhitfield3 committed Jul 18, 2024
1 parent 27a915f commit 8db83e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/domains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ www.example.com CNAME www.example.herokudns.com

async run() {
const {flags} = await this.parse(DomainsIndex)
const domains = await paginateRequest(this.heroku, `/apps/${flags.app}/domains`, 1000)
const domains = await paginateRequest<Heroku.Domain>(this.heroku, `/apps/${flags.app}/domains`, 1000)
const herokuDomain = domains.find((domain: Heroku.Domain) => domain.kind === 'heroku')
let customDomains = domains.filter((domain: Heroku.Domain) => domain.kind === 'custom')
let displayTotalDomains = false
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/lib/utils/paginator.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-await-in-loop */
// page size ranges from 200 - 1000 seen here
// https://devcenter.heroku.com/articles/platform-api-reference#ranges

// This paginator uses status code to determine passing the Next-Range header
import {APIClient} from '@heroku-cli/command'
import HTTP from 'http-call'

export async function paginateRequest(client: APIClient, url: string, pageSize = 200) {
export async function paginateRequest<T = unknown>(client: APIClient, url: string, pageSize = 200): Promise<T[]> {
let isPartial = true
let isFirstRequest = true
let nextRange: string | undefined = ''
let aggregatedResponseBody: any[] = []
let aggregatedResponseBody: T[] = []

while (isPartial) {
const response: any = await client.get<Array<any>>(url, {
const response: HTTP<T[]> = await client.get<T[]>(url, {
headers: {
Range: `${(isPartial && !isFirstRequest) ? `${nextRange}` : `id ..; max=${pageSize};`}`,
},
Expand All @@ -23,7 +23,7 @@ export async function paginateRequest(client: APIClient, url: string, pageSize =
isFirstRequest = false

if (response.statusCode === 206) {
nextRange = response.headers['next-range']
nextRange = response.headers['next-range'] as string
} else {
isPartial = false
}
Expand Down

0 comments on commit 8db83e2

Please sign in to comment.