From ce615767bbfce86a81d489d82c2b668c68f8e6a0 Mon Sep 17 00:00:00 2001 From: calebboyd Date: Sun, 13 Nov 2022 10:22:26 -0500 Subject: [PATCH] fix: tweak internal types --- src/redis.ts | 2 ++ src/stream.ts | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/redis.ts b/src/redis.ts index 6d66bc0..a12d603 100644 --- a/src/redis.ts +++ b/src/redis.ts @@ -102,6 +102,8 @@ function xreadgroup( if (noack) args.push('NOACK') if (isNumber(block)) args.push('BLOCK', block.toString()) debug(`xreadgroup ${args.join(' ')}`) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + // https://github.com/luin/ioredis/pull/1676#issue-1437398115 ;(client as any)[buffers ? 'xreadgroupBuffer' : 'xreadgroup']( ...args, 'STREAMS', diff --git a/src/stream.ts b/src/stream.ts index ab6dd68..d93b135 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -8,10 +8,13 @@ import { Mode, modes, env, + StreamEntry, } from './types.js' export { RedisStreamOptions, Mode } +type ResolvedForCaller = any + export class RedisStream { //static factoryFor() { //create factory that extends options } /** @@ -50,9 +53,9 @@ export class RedisStream { private itr = { name: '', - prev: undefined as any, - entry: undefined as any, - stream: undefined as any, + prev: undefined as StreamEntry | undefined, + entry: null as IterableIterator | null, + stream: null as IterableIterator | null | undefined, } /** @@ -147,14 +150,17 @@ export class RedisStream { else { this.streams.set(itr.name, this.group ? '>' : result.value[0].toString()) if (this.ackOnIterate) itr.prev = result.value - yield [itr.name, result.value] as any + const ret: XEntryResult = [itr.name, result.value] + yield ret as ResolvedForCaller } } } private moveCursors() { if (this.first) { - this.streams.forEach((v, k) => this.streams.set(k, '>')) + for (const [stream] of this.streams) { + this.streams.set(stream, '>') + } this.first = false } } @@ -176,13 +182,14 @@ export class RedisStream { } } - public ack(stream: string, ...ids: string[]): void { + public ack(stream: string, ...ids: string[]): undefined { if (!this.group) { throw new Error('Cannot ack entries read outside of a consumer group') } const acks = this.pendingAcks.get(stream) || [] acks.push(...ids) this.pendingAcks.set(stream, acks) + return } protected async return(): Promise {