Skip to content

Commit 6c34d6b

Browse files
committed
more work on review comments
1 parent 6e60233 commit 6c34d6b

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

packages/client/lib/RESP/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,15 @@ export interface MapReply<K, V> extends RespType<
128128
Map<any, any> | Array<any>
129129
> {}
130130

131-
type MapKeyValue = [key: SimpleStringReply, value: unknown];
131+
type MapKeyValue = [key: BlobStringReply | SimpleStringReply, value: unknown];
132132

133133
type MapTuples = Array<MapKeyValue>;
134134

135-
type ExtractMapKey<T> = T extends SimpleStringReply<infer S> ? S : never;
135+
type ExtractMapKey<T> = (
136+
T extends BlobStringReply<infer S> ? S :
137+
T extends SimpleStringReply<infer S> ? S :
138+
never
139+
);
136140

137141
export interface TuplesToMapReply<T extends MapTuples> extends RespType<
138142
RESP_TYPES['MAP'],

packages/json/lib/commands/TYPE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
return args;
1818
},
1919
transformReply: {
20-
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply>,
20+
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply | NullReply>,
2121
3: undefined as unknown as () => ArrayReply<NullReply | BlobStringReply | ArrayReply<BlobStringReply | NullReply>>
2222
},
2323
unstableResp3Module: true

packages/search/lib/commands/EXPLAIN.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { strict as assert } from 'node:assert';
22
import EXPLAIN from './EXPLAIN';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { SCHEMA_FIELD_TYPE } from './CREATE';
35

46
describe('EXPLAIN', () => {
57
describe('transformArguments', () => {
@@ -30,4 +32,15 @@ describe('EXPLAIN', () => {
3032
);
3133
});
3234
});
35+
36+
testUtils.testWithClient('client.ft.dropIndex', async client => {
37+
const [, reply] = await Promise.all([
38+
client.ft.create('index', {
39+
field: SCHEMA_FIELD_TYPE.TEXT
40+
}),
41+
client.ft.explain('index', '*')
42+
]);
43+
44+
assert.equal('<WILDCARD>}\n', reply);
45+
}, GLOBAL.SERVERS.OPEN);
3346
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default {
5858
3(reply: UnwrapReply<MGetRawReply3>): Array<MGetReply3> {
5959
return reply.map(([key, _, sample]) => ({
6060
key,
61-
sample: transformSampleReply[3](sample)
61+
sample: transformSampleReply[3](sample as unknown as UnwrapReply<SampleRawReply3>)
6262
}));
6363
}
6464
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RedisArgument, Command, CommandArguments, ReplyUnion, UnwrapReply, ArrayReply, BlobStringReply } from '@redis/client/dist/lib/RESP/types';
22
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
3-
import { RawLabels, SampleRawReply2, SampleReply2, Timestamp, transformSamplesReply } from '.';
3+
import { RawLabels, SampleRawReply2, SampleReply2, Timestamp, transformSampleReply } from '.';
44
import { TsRangeOptions, pushRangeArguments } from './RANGE';
55
import { pushFilterArgument } from './MGET';
66

@@ -77,10 +77,12 @@ export default {
7777
2: (reply: UnwrapReply<MRangeRawReply2>): Array<MRangeReplyItem2> => {
7878
const args = [];
7979

80-
for (const [key, _, samples] of reply) {
80+
for (const [key, _, samples] of reply) {
81+
const uSamples = samples as unknown as UnwrapReply<ArrayReply<SampleRawReply2>>;
82+
8183
args.push({
8284
key,
83-
samples: transformSamplesReply(samples as unknown as UnwrapReply<ArrayReply<SampleRawReply2>>)
85+
samples: uSamples.map(sample => transformSampleReply['2'](sample as unknown as UnwrapReply<SampleRawReply2>))
8486
});
8587
}
8688

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RedisArgument, Command, ReplyUnion, UnwrapReply, ArrayReply } from '@redis/client/dist/lib/RESP/types';
22
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
33
import { MRangeRawReply2, MRangeReplyItem2, TsMRangeOptions, pushGroupByArgument } from './MRANGE';
4-
import { Labels, SampleRawReply2, Timestamp, pushWithLabelsArgument, transformLablesReply, transformSamplesReply } from '.';
4+
import { Labels, SampleRawReply2, Timestamp, pushWithLabelsArgument, transformLablesReply, transformSampleReply } from '.';
55
import { pushFilterArgument } from './MGET';
66
import { pushRangeArguments } from './RANGE';
77

@@ -35,10 +35,12 @@ export default {
3535
const args = [];
3636

3737
for (const [key, labels, samples] of reply) {
38+
const uSamples = samples as unknown as UnwrapReply<ArrayReply<SampleRawReply2>>;
39+
3840
args.push({
3941
key,
4042
labels: transformLablesReply(labels),
41-
samples: transformSamplesReply(samples as unknown as UnwrapReply<ArrayReply<SampleRawReply2>>)
43+
samples: uSamples.map(sample => transformSampleReply['2'](sample as unknown as UnwrapReply<SampleRawReply2>))
4244
});
4345
}
4446

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default {
112112
return reply.map(sample => transformSampleReply['2'](sample as unknown as UnwrapReply<SampleRawReply2>));
113113
},
114114
3(reply: UnwrapReply<ArrayReply<SampleRawReply3>>) {
115-
return reply.map(sample => transformSampleReply['3'](sample));
115+
return reply.map(sample => transformSampleReply['3'](sample as unknown as UnwrapReply<SampleRawReply3>));
116116
}
117117
}
118118
} as const satisfies Command;

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ArrayReply, BlobStringReply, CommandArguments, DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
1+
import type { BlobStringReply, CommandArguments, DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
22
import ADD from './ADD';
33
import ALTER from './ALTER';
44
import CREATE from './CREATE';
@@ -141,10 +141,7 @@ export function pushLabelsArgument(args: Array<RedisArgument>, labels?: Labels)
141141

142142
export type SampleRawReply2 = TuplesReply<[timestamp: NumberReply, value: BlobStringReply]>;
143143

144-
export interface SampleRawReply3 {
145-
timestamp: NumberReply
146-
value: DoubleReply
147-
}
144+
export type SampleRawReply3 = TuplesReply<[timestamp: NumberReply, value: DoubleReply]>;
148145

149146
export interface SampleReply2 {
150147
timestamp: NumberReply;
@@ -156,27 +153,17 @@ export interface SampleReply3 {
156153
value: DoubleReply;
157154
}
158155

159-
export function transformSamplesReply(samples: UnwrapReply<ArrayReply<SampleRawReply2>>): Array<SampleReply2> {
160-
const reply = [];
161-
162-
for (const sample of samples) {
163-
reply.push(transformSampleReply[2](sample as unknown as UnwrapReply<SampleRawReply2>));
164-
}
165-
166-
return reply;
167-
}
168-
169156
export const transformSampleReply = {
170157
2(reply: UnwrapReply<SampleRawReply2>): SampleReply2 {
171158
return {
172159
timestamp: reply[0],
173160
value: Number(reply[1])
174161
};
175162
},
176-
3(reply: SampleRawReply3): SampleReply3 {
163+
3(reply: UnwrapReply<SampleRawReply3>): SampleReply3 {
177164
return {
178-
timestamp: reply.timestamp,
179-
value: reply.value
165+
timestamp: reply[0],
166+
value: reply[1]
180167
};
181168
}
182169
};

0 commit comments

Comments
 (0)