Skip to content

Commit

Permalink
Merge pull request #365 from mollie/pimm/dont-count-on-it
Browse files Browse the repository at this point in the history
Remove Page::count.
  • Loading branch information
Pimm authored Sep 10, 2024
2 parents e4466f3 + 85acd77 commit cfc1ef8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/binders/Binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Binder<R, T extends Omit<R, '_links' | '_embedded'>> {
/**
* Injects `nextPage`, `nextPageCursor`, `previousPage`, and `previousPageCursor` into the passed list.
*/
protected injectPaginationHelpers<P>(input: Array<T> & Pick<Page<T>, 'count' | 'links'>, list: (parameters: P) => Promise<Page<T>>, selfParameters: P = {} as P): Page<T> {
protected injectPaginationHelpers<P>(input: Array<T> & Pick<Page<T>, 'links'>, list: (parameters: P) => Promise<Page<T>>, selfParameters: P = {} as P): Page<T> {
const { links } = input;
let nextPage: Maybe<() => Promise<Page<T>>>;
let nextPageCursor: Maybe<string>;
Expand Down
9 changes: 3 additions & 6 deletions src/communication/NetworkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,15 @@ export default class NetworkClient {
return embedded[binderName] as R[];
}

async page<R>(pathname: string, binderName: string, query?: SearchParameters): Promise<R[] & Pick<Page<R>, 'links' | 'count'>> {
async page<R>(pathname: string, binderName: string, query?: SearchParameters): Promise<R[] & Pick<Page<R>, 'links'>> {
const data = await this.request(buildUrl(pathname, query));
try {
/* eslint-disable-next-line no-var */
var { _embedded: embedded, _links: links, count } = data;
var { _embedded: embedded, _links: links } = data;
} catch (error) {
throw new ApiError('Received unexpected response from the server');
}
return Object.assign(embedded[binderName] as R[], {
links,
count,
});
return Object.assign(embedded[binderName] as R[], { links });
}

iterate<R>(pathname: string, binderName: string, query: Maybe<SearchParameters>, valuesPerMinute = 5000): HelpfulIterator<R> {
Expand Down
4 changes: 2 additions & 2 deletions src/communication/TransformingNetworkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class TransformingNetworkClient {

async page<R extends Model<any, any>, U>(...passingArguments: Parameters<NetworkClient['page']>) {
const response = await this.networkClient.page<R>(...passingArguments);
const { count, links } = response;
return Object.assign(response.map(this.transform) as U[], { count, links });
const { links } = response;
return Object.assign(response.map(this.transform) as U[], { links });
}

iterate<R extends Model<any, any>, U>(...passingArguments: Parameters<NetworkClient['iterate']>) {
Expand Down
4 changes: 0 additions & 4 deletions src/data/page/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { type Links, type Url } from '../global';

export default interface Page<T> extends Array<T> {
links: PageLinks;
/**
* @deprecated Use `list.length` instead.
*/
count: number;
nextPageCursor: Maybe<string>;
previousPageCursor: Maybe<string>;
nextPage: Maybe<() => Promise<Page<T>>>;
Expand Down

0 comments on commit cfc1ef8

Please sign in to comment.