diff --git a/packages/client/lib/commands/XREAD.spec.ts b/packages/client/lib/commands/XREAD.spec.ts index b2b7df9cfd..b5d6cdafd5 100644 --- a/packages/client/lib/commands/XREAD.spec.ts +++ b/packages/client/lib/commands/XREAD.spec.ts @@ -101,14 +101,7 @@ describe('XREAD', () => { }), ]) - const arr = ['key', [{ - 'id': id, - 'message': [ - 'field', - 'value', - ] - }]]; - + // FUTURE resp3 compatible const obj = Object.assign(Object.create(null), { 'key': [{ id: id, @@ -122,7 +115,22 @@ describe('XREAD', () => { }] }); - assert.deepStrictEqual(reply, arr); + // v4 compatible + const expected = [{ + name: 'key', + messages: [{ + id: id, + message: Object.create(null, { + field: { + value: 'value', + configurable: true, + enumerable: true + } + }) + }] + }]; + + assert.deepStrictEqual(reply, expected); }, { client: GLOBAL.SERVERS.OPEN, cluster: GLOBAL.CLUSTERS.OPEN diff --git a/packages/client/lib/commands/XREADGROUP.spec.ts b/packages/client/lib/commands/XREADGROUP.spec.ts index be6e176c6f..026318e9d6 100644 --- a/packages/client/lib/commands/XREADGROUP.spec.ts +++ b/packages/client/lib/commands/XREADGROUP.spec.ts @@ -123,14 +123,8 @@ describe('XREADGROUP', () => { }) ]); - const arr = ['key', [{ - 'id': id, - 'message': [ - 'field', - 'value', - ] - }]]; + // FUTURE resp3 compatible const obj = Object.assign(Object.create(null), { 'key': [{ id: id, @@ -144,7 +138,22 @@ describe('XREADGROUP', () => { }] }); - assert.deepStrictEqual(readGroupReply, arr); + // v4 compatible + const expected = [{ + name: 'key', + messages: [{ + id: id, + message: Object.create(null, { + field: { + value: 'value', + configurable: true, + enumerable: true + } + }) + }] + }]; + + assert.deepStrictEqual(readGroupReply, expected); }, { client: GLOBAL.SERVERS.OPEN, cluster: GLOBAL.CLUSTERS.OPEN diff --git a/packages/client/lib/commands/generic-transformers.ts b/packages/client/lib/commands/generic-transformers.ts index bea59463b9..c90d712151 100644 --- a/packages/client/lib/commands/generic-transformers.ts +++ b/packages/client/lib/commands/generic-transformers.ts @@ -530,11 +530,13 @@ export function transformStreamsMessagesReplyResp2( reply: UnwrapReply, preserve?: any, typeMapping?: TypeMapping -): MapReply | NullReply { +): StreamsMessagesReply | NullReply { + // FUTURE: resposne type if resp3 was working, reverting to old v4 for now + //: MapReply | NullReply { if (reply === null) return null as unknown as NullReply; switch (typeMapping? typeMapping[RESP_TYPES.MAP] : undefined) { -/* +/* FUTURE: a response type for when resp3 is working properly case Map: { const ret = new Map(); @@ -549,14 +551,6 @@ export function transformStreamsMessagesReplyResp2( return ret as unknown as MapReply; } -*/ - /* work around for now */ - default: - if (!typeMapping) { - typeMapping = {}; - } - // console.log("forcing map type map to array"); - // typeMapping[RESP_TYPES.MAP] = Array; case Array: { const ret: Array = []; @@ -572,7 +566,6 @@ export function transformStreamsMessagesReplyResp2( return ret as unknown as MapReply; } -/* default: { const ret: Record = Object.create(null); @@ -588,6 +581,21 @@ export function transformStreamsMessagesReplyResp2( return ret as unknown as MapReply; } */ + // V4 compatible response type + default: { + const ret: StreamsMessagesReply = []; + + for (let i=0; i < reply.length; i++) { + const stream = reply[i] as unknown as UnwrapReply; + + ret.push({ + name: stream[0], + messages: transformStreamMessagesReply(stream[1]) + }); + } + + return ret; + } } }