diff --git a/packages/search/lib/commands/ALIASLIST.spec.ts b/packages/search/lib/commands/ALIASLIST.spec.ts new file mode 100644 index 00000000000..bf4e821222e --- /dev/null +++ b/packages/search/lib/commands/ALIASLIST.spec.ts @@ -0,0 +1,56 @@ +import { strict as assert } from 'node:assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import ALIASLIST from './ALIASLIST'; +import { SCHEMA_FIELD_TYPE } from './CREATE'; +import { parseArgs } from '@redis/client/lib/commands/generic-transformers'; + +describe('FT.ALIASLIST', () => { + it('transformArguments', () => { + assert.deepEqual( + parseArgs(ALIASLIST, 'index'), + ['FT.ALIASLIST', 'index'] + ); + }); + + testUtils.testWithClient('client.ft.aliasList on index without aliases', async client => { + const [, reply] = await Promise.all([ + client.ft.create('index', { + field: SCHEMA_FIELD_TYPE.TEXT + }), + client.ft.aliasList('index') + ]); + + assert.deepEqual(reply, []); + }, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] }); + + testUtils.testWithClient('client.ft.aliasList with aliases', async client => { + const [, , , reply] = await Promise.all([ + client.ft.create('index', { + field: SCHEMA_FIELD_TYPE.TEXT + }), + client.ft.aliasAdd('alias1', 'index'), + client.ft.aliasAdd('alias2', 'index'), + client.ft.aliasList('index') + ]); + + // ordering is not part of the contract + assert.deepEqual( + [...reply].sort(), + ['alias1', 'alias2'] + ); + }, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] }); + + testUtils.testWithClient('client.ft.aliasList on missing index rejects with index-not-found', async client => { + await assert.rejects( + client.ft.aliasList('nonexistent'), + err => { + assert.ok(err instanceof Error); + assert.ok( + err.message.startsWith('SEARCH_INDEX_NOT_FOUND'), + `expected SEARCH_INDEX_NOT_FOUND prefix, got: ${err.message}` + ); + return true; + } + ); + }, { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 10] }); +}); diff --git a/packages/search/lib/commands/ALIASLIST.ts b/packages/search/lib/commands/ALIASLIST.ts new file mode 100644 index 00000000000..b67bea8687d --- /dev/null +++ b/packages/search/lib/commands/ALIASLIST.ts @@ -0,0 +1,14 @@ +import { CommandParser } from '@redis/client/dist/lib/client/parser'; +import { RedisArgument, ArrayReply, SetReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types'; + +export default { + NOT_KEYED_COMMAND: true, + IS_READ_ONLY: true, + parseCommand(parser: CommandParser, index: RedisArgument) { + parser.push('FT.ALIASLIST', index); + }, + transformReply: { + 2: undefined as unknown as () => ArrayReply, + 3: undefined as unknown as () => SetReply + } +} as const satisfies Command; diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index 20e03f74c80..d1e9cf63b4e 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -4,6 +4,7 @@ import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR'; import AGGREGATE from './AGGREGATE'; import ALIASADD from './ALIASADD'; import ALIASDEL from './ALIASDEL'; +import ALIASLIST from './ALIASLIST'; import ALIASUPDATE from './ALIASUPDATE'; import CONFIG_GET from './CONFIG_GET'; import CONFIG_SET from './CONFIG_SET'; @@ -121,6 +122,16 @@ export default { * @param alias - The alias to remove */ aliasDel: ALIASDEL, + /** + * Lists all aliases associated with the given index. + * @param index - The index name whose aliases to list + */ + ALIASLIST, + /** + * Lists all aliases associated with the given index. + * @param index - The index name whose aliases to list + */ + aliasList: ALIASLIST, /** * Updates the index pointed to by an existing alias. * @param alias - The existing alias to update