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

[SDK-3990] Fix PaginatedResult.next() behaviour when no next page #1543

Merged
merged 2 commits into from
Dec 11, 2023
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
4 changes: 2 additions & 2 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3460,13 +3460,13 @@ declare namespace Types {
*
* @param results - A function which, upon success, will be fulfilled with a page of results for message and presence history, stats, and REST presence requests. Upon failure, the function will be called with information about the error.
*/
next(results: paginatedResultCallback<T>): void;
next(results: StandardCallback<PaginatedResult<T> | null>): void;
/**
* Returns a new `PaginatedResult` loaded with the next page of results. If there are no further pages, then `null` is returned.
*
* @returns A promise which, upon success, will be fulfilled with a page of results for message and presence history, stats, and REST presence requests. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
*/
next(): Promise<PaginatedResult<T>>;
next(): Promise<PaginatedResult<T> | null>;
/**
* Returns the `PaginatedResult` for the current page of results.
*
Expand Down
10 changes: 5 additions & 5 deletions src/common/lib/client/paginatedresource.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Utils from '../util/utils';
import Logger from '../util/logger';
import Resource from './resource';
import ErrorInfo, { IPartialErrorInfo } from '../types/errorinfo';
import { IPartialErrorInfo } from '../types/errorinfo';
import { PaginatedResultCallback } from '../../types/utils';
import Rest from './rest';

Expand Down Expand Up @@ -187,29 +187,29 @@ export class PaginatedResult<T> {
const self = this;
if (relParams) {
if ('first' in relParams) {
this.first = function (callback: (result?: ErrorInfo | null) => void) {
this.first = function (callback) {
if (!callback && self.resource.rest.options.promises) {
return Utils.promisify(self, 'first', []);
}
self.get(relParams.first, callback);
};
}
if ('current' in relParams) {
this.current = function (callback: (results?: ErrorInfo | null) => void) {
this.current = function (callback) {
if (!callback && self.resource.rest.options.promises) {
return Utils.promisify(self, 'current', []);
}
self.get(relParams.current, callback);
};
}
this.next = function (callback: (results?: ErrorInfo | null) => void) {
this.next = function (callback) {
if (!callback && self.resource.rest.options.promises) {
return Utils.promisify(self, 'next', []);
}
if ('next' in relParams) {
self.get(relParams.next, callback);
} else {
callback(null);
callback(null, null);
}
};

Expand Down
20 changes: 20 additions & 0 deletions test/rest/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,26 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) {
}
});

restTestOnJsonMsgpack('history_no_next_page', function (done, rest, channelName) {
const channel = rest.channels.get(channelName);

channel.history(function (err, firstPage) {
if (err) {
done(err);
return;
}
firstPage.next(function (err, secondPage) {
if (err) {
done(err);
return;
}

expect(secondPage).to.equal(null);
done();
});
});
});

if (typeof Promise !== 'undefined') {
it('historyPromise', function (done) {
var rest = helper.AblyRest({ promises: true });
Expand Down