1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00
Files
node-redis/packages/client/lib/commands/FUNCTION_LIST.ts
Shaya Potter 4708736f3b new "transform arguments" API for better key and metadata extraction (#2733)
* Parser support with all commands

* remove "dist" from all imports for consistency

* address most of my review comments

* small tweak to multi type mapping handling

* tweak multi commands / fix addScript cases

* nits

* addressed all in person review comments

* revert addCommand/addScript changes to multi-commands

addCommand needs to be there for sendCommand like ability within a multi.

If its there, it might as well be used by createCommand() et al, to avoid repeating code.

addScript is there (even though only used once), but now made private to keep the logic for bookkeeping near each other.
2024-10-31 12:16:59 -04:00

51 lines
1.7 KiB
TypeScript

import { CommandParser } from '../client/parser';
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NullReply, SetReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
export interface FunctionListOptions {
LIBRARYNAME?: RedisArgument;
}
export type FunctionListReplyItem = [
[BlobStringReply<'library_name'>, BlobStringReply | NullReply],
[BlobStringReply<'engine'>, BlobStringReply],
[BlobStringReply<'functions'>, ArrayReply<TuplesToMapReply<[
[BlobStringReply<'name'>, BlobStringReply],
[BlobStringReply<'description'>, BlobStringReply | NullReply],
[BlobStringReply<'flags'>, SetReply<BlobStringReply>],
]>>]
];
export type FunctionListReply = ArrayReply<TuplesToMapReply<FunctionListReplyItem>>;
export default {
NOT_KEYED_COMMAND: true,
IS_READ_ONLY: false,
parseCommand(parser: CommandParser, options?: FunctionListOptions) {
parser.push('FUNCTION', 'LIST');
if (options?.LIBRARYNAME) {
parser.push('LIBRARYNAME', options.LIBRARYNAME);
}
},
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<FunctionListReply>>) => {
return reply.map(library => {
const unwrapped = library as unknown as UnwrapReply<typeof library>;
return {
library_name: unwrapped[1],
engine: unwrapped[3],
functions: (unwrapped[5] as unknown as UnwrapReply<typeof unwrapped[5]>).map(fn => {
const unwrapped = fn as unknown as UnwrapReply<typeof fn>;
return {
name: unwrapped[1],
description: unwrapped[3],
flags: unwrapped[5]
};
})
};
});
},
3: undefined as unknown as () => FunctionListReply
}
} as const satisfies Command;