From 3895c2d1ef245961bd01b0441631550fa549592b Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 19 Oct 2023 10:58:44 +0200 Subject: [PATCH] fix: members are generic --- .../{geo_pos_test.ts => geo_pos.test.ts} | 19 +++++++++++++++++++ pkg/commands/geo_pos.ts | 12 +++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) rename pkg/commands/{geo_pos_test.ts => geo_pos.test.ts} (74%) diff --git a/pkg/commands/geo_pos_test.ts b/pkg/commands/geo_pos.test.ts similarity index 74% rename from pkg/commands/geo_pos_test.ts rename to pkg/commands/geo_pos.test.ts index 7ed14334..c01efb71 100644 --- a/pkg/commands/geo_pos_test.ts +++ b/pkg/commands/geo_pos.test.ts @@ -48,3 +48,22 @@ Deno.test("should return empty array due to null value FooBar", async () => { const response = await new GeoPosCommand([key, "FooBar"]).exec(client); assertEquals(response, []); }); + +Deno.test("should work with object members", async () => { + const key = "Sicily"; + const members = [ + { name: "Palermo" }, + { name: "Catania" }, + { name: "Marsala" }, + ]; + await new GeoAddCommand([ + key, + { longitude: 13.361389, latitude: 38.115556, member: members[0] }, + { longitude: 15.087269, latitude: 37.502669, member: members[1] }, + { longitude: 12.4372, latitude: 37.7981, member: members[2] }, + ]).exec(client); + const response = await new GeoPosCommand([key, [...members, "FooBar"]]).exec( + client, + ); + assertEquals(response.length, 3); +}); diff --git a/pkg/commands/geo_pos.ts b/pkg/commands/geo_pos.ts index 17b1f716..3f64fd06 100644 --- a/pkg/commands/geo_pos.ts +++ b/pkg/commands/geo_pos.ts @@ -8,13 +8,13 @@ type Coordinates = { /** * @see https://redis.io/commands/geopos */ -export class GeoPosCommand extends Command< +export class GeoPosCommand extends Command< (string | null)[][], - TData + Coordinates[] > { constructor( - cmd: [string, ...string[]] | [string, string[]], - opts?: CommandOptions<(string | null)[][], TData> + cmd: [string, ...TMember[] | TMember[]], + opts?: CommandOptions<(string | null)[][], Coordinates[]>, ) { const [key] = cmd; // Check if the second argument is an array of strings (members). @@ -29,7 +29,9 @@ export class GeoPosCommand extends Command< } } -function transform(result: (string | null)[][]): TData { +function transform( + result: (string | null)[][], +): TData { const final: Coordinates[] = []; for (const pos of result) { if (!pos?.[0] || !pos?.[1]) continue;