Skip to content

Commit

Permalink
revert to be v4 compat for xread/xreadgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Oct 6, 2024
1 parent 9adac9d commit 96dcdba
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
26 changes: 17 additions & 9 deletions packages/client/lib/commands/XREAD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
25 changes: 17 additions & 8 deletions packages/client/lib/commands/XREADGROUP.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
30 changes: 19 additions & 11 deletions packages/client/lib/commands/generic-transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,13 @@ export function transformStreamsMessagesReplyResp2(
reply: UnwrapReply<StreamsMessagesRawReply2 | NullReply>,
preserve?: any,
typeMapping?: TypeMapping
): MapReply<BlobStringReply | string, StreamMessagesReply> | NullReply {
): StreamsMessagesReply | NullReply {
// FUTURE: resposne type if resp3 was working, reverting to old v4 for now
//: MapReply<BlobStringReply | string, StreamMessagesReply> | 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<string, StreamMessagesReply>();
Expand All @@ -549,14 +551,6 @@ export function transformStreamsMessagesReplyResp2(
return ret as unknown as MapReply<string, StreamMessagesReply>;
}
*/
/* 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<BlobStringReply | StreamMessagesReply> = [];
Expand All @@ -572,7 +566,6 @@ export function transformStreamsMessagesReplyResp2(
return ret as unknown as MapReply<string, StreamMessagesReply>;
}
/*
default: {
const ret: Record<string, StreamMessagesReply> = Object.create(null);
Expand All @@ -588,6 +581,21 @@ export function transformStreamsMessagesReplyResp2(
return ret as unknown as MapReply<string, StreamMessagesReply>;
}
*/
// V4 compatible response type
default: {
const ret: StreamsMessagesReply = [];

for (let i=0; i < reply.length; i++) {
const stream = reply[i] as unknown as UnwrapReply<StreamMessagesRawReply>;

ret.push({
name: stream[0],
messages: transformStreamMessagesReply(stream[1])
});
}

return ret;
}
}
}

Expand Down

0 comments on commit 96dcdba

Please sign in to comment.