Skip to content

fix: pagination bug and drop page limit and page limit calculation #652

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

Merged
merged 3 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/base/Version.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ declare class Version {
}

declare namespace Version {
export interface PageLimitOptions {
export interface PageLimitOptions {
/**
* The maximum number of items to fetch
*/
limit: number;
limit: number;
/**
* The maximum number of items to return with every request
*/
Expand All @@ -86,7 +86,6 @@ declare namespace Version {
export interface PageLimit {
limit: number;
pageSize: number;
pageLimit: number;
}
}

Expand Down
12 changes: 3 additions & 9 deletions lib/base/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ Version.prototype.page = function(opts) {
*/
Version.prototype.readLimits = function(opts) {
var limit = opts.limit;
var pageLimit;
var pageSize = opts.pageSize;
if (!_.isNil(limit) && (!_.isFinite(limit) || limit <= 0)) {
throw new TypeError('Parameter limit must be a positive integer');
Expand All @@ -174,18 +173,13 @@ Version.prototype.readLimits = function(opts) {
throw new TypeError('Parameter pageSize must be a positive integer');
}

if (limit) {
if (!pageSize) {
pageSize = limit;
}

pageLimit = parseInt(Math.ceil(limit / parseFloat(pageSize)), 10);
if (limit && !pageSize) {
pageSize = limit;
}

return {
limit: limit,
pageSize: pageSize,
pageLimit: pageLimit,
pageSize: pageSize
};
};

Expand Down
4 changes: 1 addition & 3 deletions lib/rest/accounts/v1/credential/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ AwsList = function AwsList(version) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/accounts/v1/credential/publicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ PublicKeyList = function PublicKeyList(version) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ AccountList = function AccountList(version) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ AddressList = function AddressList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/address/dependentPhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ DependentPhoneNumberList = function DependentPhoneNumberList(version,
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ ApplicationList = function ApplicationList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/authorizedConnectApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ AuthorizedConnectAppList = function AuthorizedConnectAppList(version,
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ AvailablePhoneNumberCountryList = function
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ LocalList = function LocalList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ MachineToMachineList = function MachineToMachineList(version, accountSid,
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ MobileList = function MobileList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber/national.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ NationalList = function NationalList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ SharedCostList = function SharedCostList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber/tollFree.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ TollFreeList = function TollFreeList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/availablePhoneNumber/voip.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ VoipList = function VoipList(version, accountSid, countryCode) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ CallList = function CallList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/call/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ EventList = function EventList(version, accountSid, callSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/call/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ NotificationList = function NotificationList(version, accountSid, callSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/call/recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ RecordingList = function RecordingList(version, accountSid, callSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ ConferenceList = function ConferenceList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/conference/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ ParticipantList = function ParticipantList(version, accountSid, conferenceSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/conference/recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ RecordingList = function RecordingList(version, accountSid, conferenceSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/connectApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ ConnectAppList = function ConnectAppList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/incomingPhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ IncomingPhoneNumberList = function IncomingPhoneNumberList(version, accountSid)
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ AssignedAddOnList = function AssignedAddOnList(version, accountSid, resourceSid)
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ AssignedAddOnExtensionList = function AssignedAddOnExtensionList(version,
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/incomingPhoneNumber/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ LocalList = function LocalList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/incomingPhoneNumber/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ MobileList = function MobileList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/incomingPhoneNumber/tollFree.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ TollFreeList = function TollFreeList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ KeyList = function KeyList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/rest/api/v2010/account/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ MessageList = function MessageList(version, accountSid) {
callback(instance, onComplete);
});

if ((limits.pageLimit && limits.pageLimit <= currentPage)) {
onComplete();
} else if (!done) {
if (!done) {
currentPage++;
fetchNextPage(_.bind(page.nextPage, page));
}
Expand Down
Loading