1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00
Files
node-redis/packages/search/lib/commands/SUGGET_WITHSCORES_WITHPAYLOADS.ts

31 lines
1021 B
TypeScript

import { SugGetOptions, transformArguments as transformSugGetArguments } from './SUGGET';
import { SuggestionWithPayload } from './SUGGET_WITHPAYLOADS';
import { SuggestionWithScores } from './SUGGET_WITHSCORES';
export { IS_READ_ONLY } from './SUGGET';
export function transformArguments(key: string, prefix: string, options?: SugGetOptions): Array<string> {
return [
...transformSugGetArguments(key, prefix, options),
'WITHSCORES',
'WITHPAYLOADS'
];
}
type SuggestionWithScoresAndPayloads = SuggestionWithScores & SuggestionWithPayload;
export function transformReply(rawReply: Array<string | null> | null): Array<SuggestionWithScoresAndPayloads> | null {
if (rawReply === null) return null;
const transformedReply = [];
for (let i = 0; i < rawReply.length; i += 3) {
transformedReply.push({
suggestion: rawReply[i]!,
score: Number(rawReply[i + 1]!),
payload: rawReply[i + 2]
});
}
return transformedReply;
}