1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00
Files
node-redis/packages/time-series/lib/commands/MGET_WITHLABELS.ts
Bobby I. 20c16e0c2c (docs) add jsdoc comments to command parsers (#2984)
* (docs) bloom: add jsdocs for all commands

* (docs) json: add jsdocs

* (docs) search: add jsdocs for all commands

* (docs) jsdocs for std commands

* (docs) jsdoc comments to time series commands
2025-06-03 14:38:07 +03:00

69 lines
2.3 KiB
TypeScript

import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { TsMGetOptions, parseLatestArgument, parseFilterArgument } from './MGET';
import { RawLabelValue, resp2MapToValue, resp3MapToValue, SampleRawReply, transformRESP2Labels, transformSampleReply } from './helpers';
export interface TsMGetWithLabelsOptions extends TsMGetOptions {
SELECTED_LABELS?: RedisVariadicArgument;
}
export type MGetLabelsRawReply2<T extends RawLabelValue> = ArrayReply<
TuplesReply<[
key: BlobStringReply,
labels: ArrayReply<
TuplesReply<[
label: BlobStringReply,
value: T
]>
>,
sample: Resp2Reply<SampleRawReply>
]>
>;
export type MGetLabelsRawReply3<T extends RawLabelValue> = MapReply<
BlobStringReply,
TuplesReply<[
labels: MapReply<BlobStringReply, T>,
sample: SampleRawReply
]>
>;
export function createTransformMGetLabelsReply<T extends RawLabelValue>() {
return {
2(reply: MGetLabelsRawReply2<T>, _, typeMapping?: TypeMapping) {
return resp2MapToValue(reply, ([, labels, sample]) => {
return {
labels: transformRESP2Labels(labels),
sample: transformSampleReply[2](sample)
};
}, typeMapping);
},
3(reply: MGetLabelsRawReply3<T>) {
return resp3MapToValue(reply, ([labels, sample]) => {
return {
labels,
sample: transformSampleReply[3](sample)
};
});
}
} satisfies Command['transformReply'];
}
export default {
IS_READ_ONLY: true,
/**
* Gets the last samples matching a specific filter with labels
* @param parser - The command parser
* @param filter - Filter to match time series keys
* @param options - Optional parameters for the command
*/
parseCommand(parser: CommandParser, filter: RedisVariadicArgument, options?: TsMGetWithLabelsOptions) {
parser.push('TS.MGET');
parseLatestArgument(parser, options?.LATEST);
parser.push('WITHLABELS');
parseFilterArgument(parser, filter);
},
transformReply: createTransformMGetLabelsReply<BlobStringReply>(),
} as const satisfies Command;