From 7d805070ff0e104d5eb89b23fb8701be822456b7 Mon Sep 17 00:00:00 2001 From: Christopher Yovanovitch Date: Thu, 4 Jul 2024 23:12:21 +0200 Subject: [PATCH 1/2] bug: add a failing test --- src/test/integration-tests.ts | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/test/integration-tests.ts b/src/test/integration-tests.ts index 04a6132..0c52e5a 100644 --- a/src/test/integration-tests.ts +++ b/src/test/integration-tests.ts @@ -128,7 +128,7 @@ describe('Subscribe to buffer', () => { // when using messageBuffer, with redis instance the channel name is not a string but a buffer const pubSub = new RedisPubSub({ messageEventName: 'messageBuffer'}); const payload = 'This is amazing'; - + pubSub.subscribe('Posts', message => { try { expect(message).to.be.instanceOf(Buffer); @@ -173,3 +173,38 @@ describe('PubSubCluster', () => { }); }).timeout(2000); }); + + +describe("Don't transform wanted types", () => { + it('base64 string in serializer' , done => { + const payload = 'This is amazing'; + + // when using messageBuffer, with redis instance the channel name is not a string but a buffer + const pubSub = new RedisPubSub({ + // messageEventName: 'messageBuffer', + serializer: v => Buffer.from(v).toString('base64'), + deserializer: v => { + if (typeof v === 'string') { + return Buffer.from(v, 'base64').toString('utf-8'); + } + + throw new Error('Invalid data'); + } + }); + + pubSub.subscribe('Posts', message => { + try { + expect(message).to.be.equal(payload); + done(); + } catch (e) { + done(e); + } + }).then(async subId => { + try { + await pubSub.publish('Posts', payload); + } catch (e) { + done(e); + } + }); + }); +}) From ac94fbdf457cfd8bbf70e65f45be37180ea3a55a Mon Sep 17 00:00:00 2001 From: Christopher Yovanovitch Date: Sat, 10 Aug 2024 21:17:01 +0200 Subject: [PATCH 2/2] fix: iterator type --- src/redis-pubsub.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-pubsub.ts b/src/redis-pubsub.ts index 9ca6f48..c2d586c 100644 --- a/src/redis-pubsub.ts +++ b/src/redis-pubsub.ts @@ -168,7 +168,7 @@ export class RedisPubSub implements PubSubEngine { delete this.subscriptionMap[subId]; } - public asyncIterator(triggers: string | string[], options?: unknown): AsyncIterator { + public asyncIterator(triggers: string | string[], options?: unknown): AsyncIterableIterator { return new PubSubAsyncIterator(this, triggers, options); }