Skip to content

Commit

Permalink
Fix return type for FT.PROFILE
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
  • Loading branch information
acarbonetto committed Nov 8, 2024
1 parent 5032723 commit b108fe5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 74 deletions.
41 changes: 21 additions & 20 deletions node/src/server-modules/GlideFt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ export class GlideFt {
..._addFtAggregateOptions(options),
];

return _handleCustomCommand(client, args, options) as Promise<FtAggregateReturnType>;
return _handleCustomCommand(
client,
args,
options,
) as Promise<FtAggregateReturnType>;
}

/**
Expand Down Expand Up @@ -558,16 +562,15 @@ export class GlideFt {
args.push(..._addFtSearchOptions(options as FtSearchOptions));
}

return (_handleCustomCommand(
client,
args,
options as DecoderOption,
) as Promise<[FtSearchReturnType, GlideRecord<number>]>).then(v => {
return (
_handleCustomCommand(
client,
args,
options as DecoderOption,
) as Promise<[FtSearchReturnType, GlideRecord<number>]>
).then((v) => {
console.log(v[1]);
return [
v[0],
convertGlideRecordToRecord(v[1])
]
return [v[0], convertGlideRecordToRecord(v[1])];
});
}

Expand Down Expand Up @@ -630,18 +633,16 @@ export class GlideFt {
args.push(..._addFtAggregateOptions(options as FtAggregateOptions));
}

return (_handleCustomCommand(
client,
args,
options as DecoderOption,
) as Promise<[FtAggregateReturnType, GlideRecord<number>]>).then(v => {
return (
_handleCustomCommand(
client,
args,
options as DecoderOption,
) as Promise<[FtAggregateReturnType, GlideRecord<number>]>
).then((v) => {
console.log(v[1]);
return [
v[0],
convertGlideRecordToRecord(v[1]),
]
return [v[0], convertGlideRecordToRecord(v[1])];
});

}

/**
Expand Down
108 changes: 54 additions & 54 deletions node/tests/ServerModules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ProtocolVersion,
RequestError,
SortOrder,
VectorField
VectorField,
} from "..";
import { ValkeyCluster } from "../../utils/TestUtils";
import {
Expand Down Expand Up @@ -2759,15 +2759,16 @@ describe("Server Module Tests", () => {
),
).toEqual(expectedAggreg);

const aggregProfile: [FtAggregateReturnType, Record<string, number>] = (
await GlideFt.profileAggregate(
client,
indexBicycles,
"*",
options,
)
const aggregProfile: [
FtAggregateReturnType,
Record<string, number>,
] = await GlideFt.profileAggregate(
client,
indexBicycles,
"*",
options,
);
expect(aggregProfile[1].keys).toEqual([
expect(Object.keys(aggregProfile[1])).toEqual([
"parse.time",
"all.count",
"sync.time",
Expand Down Expand Up @@ -2946,15 +2947,16 @@ describe("Server Module Tests", () => {
.sort((a, b) => (a["genre"]! > b["genre"]! ? 1 : -1)),
).toEqual(expectedAggreg);

const aggregProfile: [FtAggregateReturnType, Record<string, number>] = (
await GlideFt.profileAggregate(
client,
indexMovies,
query,
options,
)
const aggregProfile: [
FtAggregateReturnType,
Record<string, number>,
] = await GlideFt.profileAggregate(
client,
indexMovies,
query,
options,
);
expect(aggregProfile[1].keys).toEqual([
expect(Object.keys(aggregProfile[1])).toEqual([
"parse.time",
"all.count",
"sync.time",
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -3107,22 +3105,23 @@ describe("Server Module Tests", () => {
];
expect(binaryResult).toEqual(expectedBinaryResult);

const binaryProfileResult: [FtSearchReturnType, Record<string, number>] = (
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<string, number>,
] = 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])(
Expand Down Expand Up @@ -3213,23 +3212,24 @@ describe("Server Module Tests", () => {
];
expect(stringResult).toEqual(expectedStringResult);

const stringProfileResult: [FtSearchReturnType, Record<string, number>] = (
await GlideFt.profileSearch(
client,
index,
query,
optionsWithLimit,
)
const stringProfileResult: [
FtSearchReturnType,
Record<string, number>,
] = await GlideFt.profileSearch(
client,
index,
query,
optionsWithLimit,
);
expect(stringProfileResult[1].keys).toEqual([
expect(Object.keys(stringProfileResult[1])).toEqual([
"all.count",
"sync.time",
"query.time",
"result.count",
"result.time",
]);
expect(stringProfileResult[0]).toEqual(expectedStringResult);
}
},
);

it("FT.EXPLAIN ft.explain FT.EXPLAINCLI ft.explaincli", async () => {
Expand All @@ -3239,34 +3239,34 @@ describe("Server Module Tests", () => {
ProtocolVersion.RESP3,
),
);

const index = uuidv4();
expect(
await GlideFt.create(client, index, [
{ type: "NUMERIC", name: "price" },
{ type: "TEXT", name: "title" },
]),
).toEqual("OK");

let explain = await GlideFt.explain(
client,
Buffer.from(index),
"@price:[0 10]",
);
expect(explain).toContain("price");
expect(explain).toContain("10");

explain = (
(await GlideFt.explain(client, index, "@price:[0 10]", {
decoder: Decoder.Bytes,
})) as Buffer
).toString();
expect(explain).toContain("price");
expect(explain).toContain("10");

explain = await GlideFt.explain(client, index, "*");
expect(explain).toContain("*");

let explaincli = (
await GlideFt.explaincli(
client,
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit b108fe5

Please sign in to comment.