From b108fe51e7dc7859aaf4d70cc3de16e2e6654c3e Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Fri, 8 Nov 2024 00:03:04 -0800 Subject: [PATCH] Fix return type for FT.PROFILE Signed-off-by: Andrew Carbonetto --- node/src/server-modules/GlideFt.ts | 41 +++++------ node/tests/ServerModules.test.ts | 108 ++++++++++++++--------------- 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/node/src/server-modules/GlideFt.ts b/node/src/server-modules/GlideFt.ts index 1086f762a7..2a2afff1e4 100644 --- a/node/src/server-modules/GlideFt.ts +++ b/node/src/server-modules/GlideFt.ts @@ -317,7 +317,11 @@ export class GlideFt { ..._addFtAggregateOptions(options), ]; - return _handleCustomCommand(client, args, options) as Promise; + return _handleCustomCommand( + client, + args, + options, + ) as Promise; } /** @@ -558,16 +562,15 @@ export class GlideFt { args.push(..._addFtSearchOptions(options as FtSearchOptions)); } - return (_handleCustomCommand( - client, - args, - options as DecoderOption, - ) as Promise<[FtSearchReturnType, GlideRecord]>).then(v => { + return ( + _handleCustomCommand( + client, + args, + options as DecoderOption, + ) as Promise<[FtSearchReturnType, GlideRecord]> + ).then((v) => { console.log(v[1]); - return [ - v[0], - convertGlideRecordToRecord(v[1]) - ] + return [v[0], convertGlideRecordToRecord(v[1])]; }); } @@ -630,18 +633,16 @@ export class GlideFt { args.push(..._addFtAggregateOptions(options as FtAggregateOptions)); } - return (_handleCustomCommand( - client, - args, - options as DecoderOption, - ) as Promise<[FtAggregateReturnType, GlideRecord]>).then(v => { + return ( + _handleCustomCommand( + client, + args, + options as DecoderOption, + ) as Promise<[FtAggregateReturnType, GlideRecord]> + ).then((v) => { console.log(v[1]); - return [ - v[0], - convertGlideRecordToRecord(v[1]), - ] + return [v[0], convertGlideRecordToRecord(v[1])]; }); - } /** diff --git a/node/tests/ServerModules.test.ts b/node/tests/ServerModules.test.ts index eb709922a6..311a30146a 100644 --- a/node/tests/ServerModules.test.ts +++ b/node/tests/ServerModules.test.ts @@ -26,7 +26,7 @@ import { ProtocolVersion, RequestError, SortOrder, - VectorField + VectorField, } from ".."; import { ValkeyCluster } from "../../utils/TestUtils"; import { @@ -2759,15 +2759,16 @@ describe("Server Module Tests", () => { ), ).toEqual(expectedAggreg); - const aggregProfile: [FtAggregateReturnType, Record] = ( - await GlideFt.profileAggregate( - client, - indexBicycles, - "*", - options, - ) + const aggregProfile: [ + FtAggregateReturnType, + Record, + ] = await GlideFt.profileAggregate( + client, + indexBicycles, + "*", + options, ); - expect(aggregProfile[1].keys).toEqual([ + expect(Object.keys(aggregProfile[1])).toEqual([ "parse.time", "all.count", "sync.time", @@ -2946,15 +2947,16 @@ describe("Server Module Tests", () => { .sort((a, b) => (a["genre"]! > b["genre"]! ? 1 : -1)), ).toEqual(expectedAggreg); - const aggregProfile: [FtAggregateReturnType, Record] = ( - await GlideFt.profileAggregate( - client, - indexMovies, - query, - options, - ) + const aggregProfile: [ + FtAggregateReturnType, + Record, + ] = await GlideFt.profileAggregate( + client, + indexMovies, + query, + options, ); - expect(aggregProfile[1].keys).toEqual([ + expect(Object.keys(aggregProfile[1])).toEqual([ "parse.time", "all.count", "sync.time", @@ -3049,15 +3051,11 @@ describe("Server Module Tests", () => { timeout: 10000, count: true, }; - const binaryResultCount: FtSearchReturnType = await GlideFt.search( - client, - index, - query, - { + const binaryResultCount: FtSearchReturnType = + await GlideFt.search(client, index, query, { decoder: Decoder.Bytes, ...optionsWithCount, - }, - ); + }); expect(binaryResultCount).toEqual([2]); const options: FtSearchOptions = { @@ -3107,22 +3105,23 @@ describe("Server Module Tests", () => { ]; expect(binaryResult).toEqual(expectedBinaryResult); - const binaryProfileResult: [FtSearchReturnType, Record] = ( - await GlideFt.profileSearch(client, index, query, { - decoder: Decoder.Bytes, - ...options, - }) - ); - expect(binaryProfileResult[1].keys).toEqual([ - Buffer.from("sync.time"), - Buffer.from("query.time"), - Buffer.from("vector.count"), - Buffer.from("vector.time"), - Buffer.from("result.count"), - Buffer.from("result.time"), + const binaryProfileResult: [ + FtSearchReturnType, + Record, + ] = await GlideFt.profileSearch(client, index, query, { + decoder: Decoder.Bytes, + ...options, + }); + expect(Object.keys(binaryProfileResult[1])).toEqual([ + "sync.time", + "query.time", + "vector.count", + "vector.time", + "result.count", + "result.time", ]); expect(binaryProfileResult[0]).toEqual(expectedBinaryResult); - } + }, ); it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( @@ -3213,15 +3212,16 @@ describe("Server Module Tests", () => { ]; expect(stringResult).toEqual(expectedStringResult); - const stringProfileResult: [FtSearchReturnType, Record] = ( - await GlideFt.profileSearch( - client, - index, - query, - optionsWithLimit, - ) + const stringProfileResult: [ + FtSearchReturnType, + Record, + ] = await GlideFt.profileSearch( + client, + index, + query, + optionsWithLimit, ); - expect(stringProfileResult[1].keys).toEqual([ + expect(Object.keys(stringProfileResult[1])).toEqual([ "all.count", "sync.time", "query.time", @@ -3229,7 +3229,7 @@ describe("Server Module Tests", () => { "result.time", ]); expect(stringProfileResult[0]).toEqual(expectedStringResult); - } + }, ); it("FT.EXPLAIN ft.explain FT.EXPLAINCLI ft.explaincli", async () => { @@ -3239,7 +3239,7 @@ describe("Server Module Tests", () => { ProtocolVersion.RESP3, ), ); - + const index = uuidv4(); expect( await GlideFt.create(client, index, [ @@ -3247,7 +3247,7 @@ describe("Server Module Tests", () => { { type: "TEXT", name: "title" }, ]), ).toEqual("OK"); - + let explain = await GlideFt.explain( client, Buffer.from(index), @@ -3255,7 +3255,7 @@ describe("Server Module Tests", () => { ); expect(explain).toContain("price"); expect(explain).toContain("10"); - + explain = ( (await GlideFt.explain(client, index, "@price:[0 10]", { decoder: Decoder.Bytes, @@ -3263,10 +3263,10 @@ describe("Server Module Tests", () => { ).toString(); expect(explain).toContain("price"); expect(explain).toContain("10"); - + explain = await GlideFt.explain(client, index, "*"); expect(explain).toContain("*"); - + let explaincli = ( await GlideFt.explaincli( client, @@ -3277,7 +3277,7 @@ describe("Server Module Tests", () => { expect(explaincli).toContain("price"); expect(explaincli).toContain("0"); expect(explaincli).toContain("10"); - + explaincli = ( await GlideFt.explaincli(client, index, "@price:[0 10]", { decoder: Decoder.Bytes, @@ -3286,7 +3286,7 @@ describe("Server Module Tests", () => { expect(explaincli).toContain("price"); expect(explaincli).toContain("0"); expect(explaincli).toContain("10"); - + expect(await GlideFt.dropindex(client, index)).toEqual("OK"); // querying a missing index await expect(GlideFt.explain(client, index, "*")).rejects.toThrow(