Skip to content

Commit

Permalink
Remove redundant type annotations in PaginatedResource bodyHandler
Browse files Browse the repository at this point in the history
(I’m also not sure why the compiler was accepting the code that
described the `body` parameter as having type `any`, given that in
BodyHandler it’s of type `unknown`.)
  • Loading branch information
lawrence-forooghian committed Nov 8, 2023
1 parent d986ea2 commit 9973109
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/common/lib/client/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ class Channel extends EventEmitter {

const options = this.channelOptions;
new PaginatedResource(client, this.basePath + '/messages', headers, envelope, async function (
body: any,
headers: Record<string, string>,
unpacked?: boolean
body,
headers,
unpacked
) {
return await Message.fromResponseBody(body, options, client._MsgPack, unpacked ? undefined : format);
return await Message.fromResponseBody(body as Message[], options, client._MsgPack, unpacked ? undefined : format);
}).get(params as Record<string, unknown>, callback);
}

Expand Down
16 changes: 6 additions & 10 deletions src/common/lib/client/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ class Presence extends EventEmitter {
Utils.mixin(headers, client.options.headers);

const options = this.channel.channelOptions;
new PaginatedResource(client, this.basePath, headers, envelope, async function (
body: any,
headers: Record<string, string>,
unpacked?: boolean
) {
new PaginatedResource(client, this.basePath, headers, envelope, async function (body, headers, unpacked) {
return await PresenceMessage.fromResponseBody(
body,
body as Record<string, unknown>[],
options as CipherOptions,
client._MsgPack,
unpacked ? undefined : format
Expand Down Expand Up @@ -83,12 +79,12 @@ class Presence extends EventEmitter {

const options = this.channel.channelOptions;
new PaginatedResource(client, this.basePath + '/history', headers, envelope, async function (
body: any,
headers: Record<string, string>,
unpacked?: boolean
body,
headers,
unpacked
) {
return await PresenceMessage.fromResponseBody(
body,
body as Record<string, unknown>[],
options as CipherOptions,
client._MsgPack,
unpacked ? undefined : format
Expand Down
30 changes: 17 additions & 13 deletions src/common/lib/client/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,15 @@ class DeviceRegistrations {
Utils.mixin(headers, client.options.headers);

new PaginatedResource(client, '/push/deviceRegistrations', headers, envelope, async function (
body: any,
headers: Record<string, string>,
unpacked?: boolean
body,
headers,
unpacked
) {
return DeviceDetails.fromResponseBody(body, client._MsgPack, unpacked ? undefined : format);
return DeviceDetails.fromResponseBody(
body as Record<string, unknown>[],
client._MsgPack,
unpacked ? undefined : format
);
}).get(params, callback);
}

Expand Down Expand Up @@ -269,11 +273,15 @@ class ChannelSubscriptions {
Utils.mixin(headers, client.options.headers);

new PaginatedResource(client, '/push/channelSubscriptions', headers, envelope, async function (
body: any,
headers: Record<string, string>,
unpacked?: boolean
body,
headers,
unpacked
) {
return PushChannelSubscription.fromResponseBody(body, client._MsgPack, unpacked ? undefined : format);
return PushChannelSubscription.fromResponseBody(
body as Record<string, unknown>[],
client._MsgPack,
unpacked ? undefined : format
);
}).get(params, callback);
}

Expand Down Expand Up @@ -310,11 +318,7 @@ class ChannelSubscriptions {

if (client.options.pushFullWait) Utils.mixin(params, { fullWait: 'true' });

new PaginatedResource(client, '/push/channels', headers, envelope, async function (
body: unknown,
headers: Record<string, string>,
unpacked?: boolean
) {
new PaginatedResource(client, '/push/channels', headers, envelope, async function (body, headers, unpacked) {
const parsedBody = (
!unpacked && format ? Utils.decodeBody(body, client._MsgPack, format) : body
) as Array<string>;
Expand Down
8 changes: 2 additions & 6 deletions src/common/lib/client/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ export class Rest {

Utils.mixin(headers, this.client.options.headers);

new PaginatedResource(this.client, '/stats', headers, envelope, function (
body: unknown,
headers: Record<string, string>,
unpacked?: boolean
) {
new PaginatedResource(this.client, '/stats', headers, envelope, function (body, headers, unpacked) {
const statsValues = unpacked ? body : JSON.parse(body as string);
for (let i = 0; i < statsValues.length; i++) statsValues[i] = Stats.fromValues(statsValues[i]);
return statsValues;
Expand Down Expand Up @@ -160,7 +156,7 @@ export class Rest {
path,
headers,
envelope,
async function (resbody: unknown, headers: Record<string, string>, unpacked?: boolean) {
async function (resbody, headers, unpacked) {
return Utils.ensureArray(unpacked ? resbody : decoder(resbody as string & Buffer));
},
/* useHttpPaginatedResponse: */ true
Expand Down

0 comments on commit 9973109

Please sign in to comment.