From 95ef9e2094a95134e2316220e75b15289ea6b1ef Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 11 Dec 2023 12:18:35 -0300 Subject: [PATCH 1/2] Remove some redundant type annotations --- src/common/lib/client/paginatedresource.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/lib/client/paginatedresource.ts b/src/common/lib/client/paginatedresource.ts index 4d16a3b894..73eb89872d 100644 --- a/src/common/lib/client/paginatedresource.ts +++ b/src/common/lib/client/paginatedresource.ts @@ -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'; @@ -187,7 +187,7 @@ export class PaginatedResult { 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', []); } @@ -195,14 +195,14 @@ export class PaginatedResult { }; } 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', []); } From 8bd17068f8e444f36ad86ce13ffecf0b4ba04456 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 11 Dec 2023 12:21:33 -0300 Subject: [PATCH 2/2] Fix PaginatedResult.next() behaviour when no next page It is meant to return `null` (per TG4 and our documentation comments), but was returning `undefined`. Resolves #1542. --- ably.d.ts | 4 ++-- src/common/lib/client/paginatedresource.ts | 2 +- test/rest/history.test.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ably.d.ts b/ably.d.ts index 08088741a1..0eb8e3f4f4 100644 --- a/ably.d.ts +++ b/ably.d.ts @@ -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): void; + next(results: StandardCallback | 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>; + next(): Promise | null>; /** * Returns the `PaginatedResult` for the current page of results. * diff --git a/src/common/lib/client/paginatedresource.ts b/src/common/lib/client/paginatedresource.ts index 73eb89872d..700dba83c5 100644 --- a/src/common/lib/client/paginatedresource.ts +++ b/src/common/lib/client/paginatedresource.ts @@ -209,7 +209,7 @@ export class PaginatedResult { if ('next' in relParams) { self.get(relParams.next, callback); } else { - callback(null); + callback(null, null); } }; diff --git a/test/rest/history.test.js b/test/rest/history.test.js index f686c0db71..50f1059072 100644 --- a/test/rest/history.test.js +++ b/test/rest/history.test.js @@ -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 });