Skip to content

Commit 2baf1f9

Browse files
authored
fix(time-series): honour typeMapping for labels in RESP2 replies (#3412)
1 parent 96dd4be commit 2baf1f9

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

packages/time-series/lib/commands/MGET_WITHLABELS.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import MGET_WITHLABELS from './MGET_WITHLABELS';
44
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
5+
import { RESP_TYPES } from '@redis/client';
56

67
describe('TS.MGET_WITHLABELS', () => {
78
it('transformArguments', () => {
@@ -11,6 +12,19 @@ describe('TS.MGET_WITHLABELS', () => {
1112
);
1213
});
1314

15+
it('transformReply maps labels with the MAP type mapping', () => {
16+
const reply = MGET_WITHLABELS.transformReply[2](
17+
[['key', [['label', 'value']], [0, '1']]] as never,
18+
undefined,
19+
{ [RESP_TYPES.MAP]: Map }
20+
) as unknown as Map<string, { labels: unknown }>;
21+
22+
assert.deepEqual(
23+
reply.get('key')?.labels,
24+
new Map([['label', 'value']])
25+
);
26+
});
27+
1428
testUtils.testWithClient('client.ts.mGetWithLabels', async client => {
1529
const [, reply] = await Promise.all([
1630
client.ts.add('key', 0, 0, {

packages/time-series/lib/commands/MGET_WITHLABELS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function createTransformMGetLabelsReply<T extends RawLabelValue>() {
3434
2(reply: MGetLabelsRawReply2<T>, _, typeMapping?: TypeMapping) {
3535
return resp2MapToValue(reply, ([, labels, sample]) => {
3636
return {
37-
labels: transformRESP2Labels(labels),
37+
labels: transformRESP2Labels(labels, typeMapping),
3838
sample: transformSampleReply[2](sample)
3939
};
4040
}, typeMapping);

packages/time-series/lib/commands/MRANGE_WITHLABELS_GROUPBY.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import MRANGE_WITHLABELS_GROUPBY from './MRANGE_WITHLABELS_GROUPBY';
44
import { TIME_SERIES_REDUCERS } from './MRANGE_GROUPBY';
55
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
66
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
7+
import { RESP_TYPES } from '@redis/client';
78

89
describe('TS.MRANGE_WITHLABELS_GROUPBY', () => {
910
it('transformArguments', () => {
@@ -40,6 +41,24 @@ describe('TS.MRANGE_WITHLABELS_GROUPBY', () => {
4041
);
4142
});
4243

44+
it('transformReply maps labels with the MAP type mapping', () => {
45+
const reply = MRANGE_WITHLABELS_GROUPBY.transformReply[2](
46+
[[
47+
'key',
48+
[['label', 'value'], ['__reducer__', 'avg'], ['__source__', 'source']],
49+
[[0, '1']]
50+
]] as never,
51+
undefined,
52+
{ [RESP_TYPES.MAP]: Map }
53+
) as unknown as Map<string, { labels: unknown, sources: Array<string> }>;
54+
55+
assert.deepEqual(
56+
reply.get('key')?.labels,
57+
new Map([['label', 'value']])
58+
);
59+
assert.deepEqual(reply.get('key')?.sources, ['source']);
60+
});
61+
4362
testUtils.testWithClient('client.ts.mRangeWithLabelsGroupBy', async client => {
4463
const [, reply] = await Promise.all([
4564
client.ts.add('key', 0, 0, {

packages/time-series/lib/commands/MRANGE_WITHLABELS_GROUPBY.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default {
5757
transformReply: {
5858
2(reply: TsMRangeWithLabelsGroupByRawReply2, _?: unknown, typeMapping?: TypeMapping) {
5959
return resp2MapToValue(reply, ([_key, labels, samples]) => {
60-
const transformed = transformRESP2LabelsWithSources(labels);
60+
const transformed = transformRESP2LabelsWithSources(labels, typeMapping);
6161
return {
6262
labels: transformed.labels,
6363
sources: transformed.sources,

0 commit comments

Comments
 (0)