From 2ede0007a6001fbce96b9e3ab53a00e5e72caa25 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Mon, 22 Jul 2024 15:22:35 -0700 Subject: [PATCH 1/8] Converted LPosOptions class to type Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 5 ++- node/src/Commands.ts | 31 +++++++++++++++- node/src/Transaction.ts | 1 + node/src/commands/LPosOptions.ts | 64 -------------------------------- node/tests/SharedTests.ts | 63 +++++++++---------------------- node/tests/TestUtilities.ts | 8 +--- 6 files changed, 52 insertions(+), 120 deletions(-) delete mode 100644 node/src/commands/LPosOptions.ts diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 390c5ca22e..c441760c05 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -15,6 +15,7 @@ import { ExpireOptions, InsertPosition, KeyWeight, + LPosOptions, RangeByIndex, RangeByLex, RangeByScore, @@ -3345,8 +3346,8 @@ export class BaseClient { * @example * ```typescript * await client.rpush("myList", ["a", "b", "c", "d", "e", "e"]); - * console.log(await client.lpos("myList", "e", new LPosOptions({ rank: 2 }))); // Output: 5 - the second occurrence of "e" is at index 5. - * console.log(await client.lpos("myList", "e", new LPosOptions({ count: 3 }))); // Output: [ 4, 5 ] - indices for the occurrences of "e" in list "myList". + * console.log(await client.lpos("myList", "e", { rank: 2 })); // Output: 5 - the second occurrence of "e" is at index 5. + * console.log(await client.lpos("myList", "e", { count: 3 })); // Output: [ 4, 5 ] - indices for the occurrences of "e" in list "myList". * ``` */ public lpos( diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 3eeb042ad7..6da7cdcf60 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -1812,6 +1812,20 @@ export function createFlushDB(mode?: FlushMode): command_request.Command { } } +/** + * Optional arguments to LPOS command. + * + * See https://valkey.io/commands/lpos/ for more details. + */ +export type LPosOptions = { + /** The rank of the match to return. */ + rank?: number; + /** The specific number of matching indices from a list. */ + count?: number; + /** The maximum number of comparisons to make between the element and the items in the list. */ + maxLength?: number; +}; + /** * @internal */ @@ -1820,10 +1834,23 @@ export function createLPos( element: string, options?: LPosOptions, ): command_request.Command { - let args: string[] = [key, element]; + const args: string[] = [key, element]; if (options) { - args = args.concat(options.toArgs()); + if (options.rank !== undefined) { + args.push("RANK"); + args.push(options.rank.toString()); + } + + if (options.count !== undefined) { + args.push("COUNT"); + args.push(options.count.toString()); + } + + if (options.maxLength !== undefined) { + args.push("MAXLEN"); + args.push(options.maxLength.toString()); + } } return createCommand(RequestType.LPos, args); diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index c04bc96817..bc61ddd664 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -9,6 +9,7 @@ import { InsertPosition, KeyWeight, LolwutOptions, + LPosOptions, RangeByIndex, RangeByLex, RangeByScore, diff --git a/node/src/commands/LPosOptions.ts b/node/src/commands/LPosOptions.ts deleted file mode 100644 index de2c0bcc2a..0000000000 --- a/node/src/commands/LPosOptions.ts +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -/** - * Optional arguments to LPOS command. - * - * See https://valkey.io/commands/lpos/ for more details. - */ -export class LPosOptions { - /** Redis API keyword use to determine the rank of the match to return. */ - public static RANK_REDIS_API = "RANK"; - /** Redis API keyword used to extract specific number of matching indices from a list. */ - public static COUNT_REDIS_API = "COUNT"; - /** Redis API keyword used to determine the maximum number of list items to compare. */ - public static MAXLEN_REDIS_API = "MAXLEN"; - /** The rank of the match to return. */ - private rank?: number; - /** The specific number of matching indices from a list. */ - private count?: number; - /** The maximum number of comparisons to make between the element and the items in the list. */ - private maxLength?: number; - - constructor({ - rank, - count, - maxLength, - }: { - rank?: number; - count?: number; - maxLength?: number; - }) { - this.rank = rank; - this.count = count; - this.maxLength = maxLength; - } - - /** - * - * Converts LPosOptions into a string[]. - * - * @returns string[] - */ - public toArgs(): string[] { - const args: string[] = []; - - if (this.rank !== undefined) { - args.push(LPosOptions.RANK_REDIS_API); - args.push(this.rank.toString()); - } - - if (this.count !== undefined) { - args.push(LPosOptions.COUNT_REDIS_API); - args.push(this.count.toString()); - } - - if (this.maxLength !== undefined) { - args.push(LPosOptions.MAXLEN_REDIS_API); - args.push(this.maxLength.toString()); - } - - return args; - } -} diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index a60c789d6c..3125bbe2b1 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -32,7 +32,6 @@ import { BitmapIndexType, BitOffsetOptions, } from "../build-ts/src/commands/BitOffsetOptions"; -import { LPosOptions } from "../build-ts/src/commands/LPosOptions"; import { GeospatialData } from "../build-ts/src/commands/geospatial/GeospatialData"; import { GeoAddOptions } from "../build-ts/src/commands/geospatial/GeoAddOptions"; import { ConditionalChange } from "../build-ts/src/commands/ConditionalChange"; @@ -4203,44 +4202,32 @@ export function runBaseTests(config: { // simplest case expect(await client.lpos(key, "a")).toEqual(0); - expect( - await client.lpos(key, "b", new LPosOptions({ rank: 2 })), - ).toEqual(5); + expect(await client.lpos(key, "b", { rank: 2 })).toEqual(5); // element doesn't exist expect(await client.lpos(key, "e")).toBeNull(); // reverse traversal - expect( - await client.lpos(key, "b", new LPosOptions({ rank: -2 })), - ).toEqual(2); + expect(await client.lpos(key, "b", { rank: -2 })).toEqual(2); // unlimited comparisons expect( - await client.lpos( - key, - "a", - new LPosOptions({ rank: 1, maxLength: 0 }), - ), + await client.lpos(key, "a", { rank: 1, maxLength: 0 }), ).toEqual(0); // limited comparisons expect( - await client.lpos( - key, - "c", - new LPosOptions({ rank: 1, maxLength: 2 }), - ), + await client.lpos(key, "c", { rank: 1, maxLength: 2 }), ).toBeNull(); // invalid rank value await expect( - client.lpos(key, "a", new LPosOptions({ rank: 0 })), + client.lpos(key, "a", { rank: 0 }), ).rejects.toThrow(RequestError); // invalid maxlen value await expect( - client.lpos(key, "a", new LPosOptions({ maxLength: -1 })), + client.lpos(key, "a", { maxLength: -1 }), ).rejects.toThrow(RequestError); // non-existent key @@ -4256,45 +4243,29 @@ export function runBaseTests(config: { // invalid count value await expect( - client.lpos(key, "a", new LPosOptions({ count: -1 })), + client.lpos(key, "a", { count: -1 }), ).rejects.toThrow(RequestError); // with count + expect(await client.lpos(key, "a", { count: 2 })).toEqual([ + 0, 1, + ]); + expect(await client.lpos(key, "a", { count: 0 })).toEqual([ + 0, 1, 4, + ]); expect( - await client.lpos(key, "a", new LPosOptions({ count: 2 })), - ).toEqual([0, 1]); - expect( - await client.lpos(key, "a", new LPosOptions({ count: 0 })), - ).toEqual([0, 1, 4]); - expect( - await client.lpos( - key, - "a", - new LPosOptions({ rank: 1, count: 0 }), - ), + await client.lpos(key, "a", { rank: 1, count: 0 }), ).toEqual([0, 1, 4]); expect( - await client.lpos( - key, - "a", - new LPosOptions({ rank: 2, count: 0 }), - ), + await client.lpos(key, "a", { rank: 2, count: 0 }), ).toEqual([1, 4]); expect( - await client.lpos( - key, - "a", - new LPosOptions({ rank: 3, count: 0 }), - ), + await client.lpos(key, "a", { rank: 3, count: 0 }), ).toEqual([4]); // reverse traversal expect( - await client.lpos( - key, - "a", - new LPosOptions({ rank: -1, count: 0 }), - ), + await client.lpos(key, "a", { rank: -1, count: 0 }), ).toEqual([4, 1, 0]); }, protocol); }, diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index bb34980827..f9ee85c6ff 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -466,13 +466,9 @@ export async function transactionTest( field + "3", ]); args.push(5); - baseTransaction.lpos(key16, field + "1", new LPosOptions({ rank: 2 })); + baseTransaction.lpos(key16, field + "1", { rank: 2 }); args.push(1); - baseTransaction.lpos( - key16, - field + "1", - new LPosOptions({ rank: 2, count: 0 }), - ); + baseTransaction.lpos(key16, field + "1", { rank: 2, count: 0 }); args.push([1]); baseTransaction.sadd(key7, ["bar", "foo"]); args.push(2); From 064163a9c0f249c95e99ac2e53f90e8bf6c5619e Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Mon, 22 Jul 2024 18:47:46 -0700 Subject: [PATCH 2/8] Moved FlushMode to Commands.ts Signed-off-by: Guian Gumpac --- node/src/Commands.ts | 21 +++++++++++++++++++++ node/src/GlideClient.ts | 2 +- node/src/GlideClusterClient.ts | 2 +- node/src/Transaction.ts | 1 + node/src/commands/FlushMode.ts | 23 ----------------------- node/tests/RedisClient.test.ts | 2 +- node/tests/RedisClusterClient.test.ts | 2 +- node/tests/SharedTests.ts | 2 +- node/tests/TestUtilities.ts | 2 +- 9 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 node/src/commands/FlushMode.ts diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 6da7cdcf60..f08c6c0681 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -7,6 +7,10 @@ import Long from "long"; import { FlushMode } from "./commands/FlushMode"; import { LPosOptions } from "./commands/LPosOptions"; +/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ +import { GlideClient } from "src/GlideClient"; +/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ +import { GlideClusterClient } from "src/GlideClusterClient"; import { command_request } from "./ProtobufMessage"; import { BitOffsetOptions } from "./commands/BitOffsetOptions"; import { GeoAddOptions } from "./commands/geospatial/GeoAddOptions"; @@ -1616,6 +1620,23 @@ export function createBitCount( return createCommand(RequestType.BitCount, args); } +/** + * Defines flushing mode for {@link GlideClient.flushall}, {@link GlideClusterClient.flushall}, + * {@link GlideClient.flushdb} and {@link GlideClusterClient.flushdb} commands. + * + * See https://valkey.io/commands/flushall/ and https://valkey.io/commands/flushdb/ for details. + */ +export enum FlushMode { + /** + * Flushes synchronously. + * + * since Valkey version 6.2.0. + */ + SYNC = "SYNC", + /** Flushes asynchronously. */ + ASYNC = "ASYNC", +} + /** * @internal */ diff --git a/node/src/GlideClient.ts b/node/src/GlideClient.ts index b89e39a6c4..c63715b6df 100644 --- a/node/src/GlideClient.ts +++ b/node/src/GlideClient.ts @@ -10,6 +10,7 @@ import { ReturnType, } from "./BaseClient"; import { + FlushMode, InfoOptions, LolwutOptions, createClientGetName, @@ -35,7 +36,6 @@ import { } from "./Commands"; import { connection_request } from "./ProtobufMessage"; import { Transaction } from "./Transaction"; -import { FlushMode } from "./commands/FlushMode"; /* eslint-disable-next-line @typescript-eslint/no-namespace */ export namespace GlideClientConfiguration { diff --git a/node/src/GlideClusterClient.ts b/node/src/GlideClusterClient.ts index d552469812..bfcebc56ca 100644 --- a/node/src/GlideClusterClient.ts +++ b/node/src/GlideClusterClient.ts @@ -10,6 +10,7 @@ import { ReturnType, } from "./BaseClient"; import { + FlushMode, InfoOptions, LolwutOptions, createClientGetName, @@ -32,7 +33,6 @@ import { createPublish, createTime, } from "./Commands"; -import { FlushMode } from "./commands/FlushMode"; import { RequestError } from "./Errors"; import { command_request, connection_request } from "./ProtobufMessage"; import { ClusterTransaction } from "./Transaction"; diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index bc61ddd664..5cb2ab7fbd 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -5,6 +5,7 @@ import { AggregationType, ExpireOptions, + FlushMode, InfoOptions, InsertPosition, KeyWeight, diff --git a/node/src/commands/FlushMode.ts b/node/src/commands/FlushMode.ts deleted file mode 100644 index 78b9ca10c0..0000000000 --- a/node/src/commands/FlushMode.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -// Import below added to fix up the TSdoc link, but eslint blames for unused import. -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -import { GlideClient } from "src/GlideClient"; - -/** - * Defines flushing mode for {@link GlideClient.flushall|flushall} and {@link GlideClient.flushdb|flushdb} commands. - * - * See https://valkey.io/commands/flushall/ and https://valkey.io/commands/flushdb/ for details. - */ -export enum FlushMode { - /** - * Flushes synchronously. - * - * since Valkey version 6.2.0. - */ - SYNC = "SYNC", - /** Flushes asynchronously. */ - ASYNC = "ASYNC", -} diff --git a/node/tests/RedisClient.test.ts b/node/tests/RedisClient.test.ts index 853a8aa769..c9b926851d 100644 --- a/node/tests/RedisClient.test.ts +++ b/node/tests/RedisClient.test.ts @@ -20,7 +20,7 @@ import { Transaction, } from ".."; import { RedisCluster } from "../../utils/TestUtils.js"; -import { FlushMode } from "../build-ts/src/commands/FlushMode.js"; +import { FlushMode } from "../build-ts/src/Commands"; import { command_request } from "../src/ProtobufMessage"; import { checkIfServerVersionLessThan, runBaseTests } from "./SharedTests"; import { diff --git a/node/tests/RedisClusterClient.test.ts b/node/tests/RedisClusterClient.test.ts index e039c96ad5..b7a9444163 100644 --- a/node/tests/RedisClusterClient.test.ts +++ b/node/tests/RedisClusterClient.test.ts @@ -21,8 +21,8 @@ import { Routes, ScoreFilter, } from ".."; +import { FlushMode } from "../build-ts/src/Commands"; import { RedisCluster } from "../../utils/TestUtils.js"; -import { FlushMode } from "../build-ts/src/commands/FlushMode"; import { checkIfServerVersionLessThan, runBaseTests } from "./SharedTests"; import { checkClusterResponse, diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 3125bbe2b1..4255a168df 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -8,6 +8,7 @@ import { v4 as uuidv4 } from "uuid"; import { ClosingError, ExpireOptions, + FlushMode, GlideClient, GlideClusterClient, InfoOptions, @@ -35,7 +36,6 @@ import { import { GeospatialData } from "../build-ts/src/commands/geospatial/GeospatialData"; import { GeoAddOptions } from "../build-ts/src/commands/geospatial/GeoAddOptions"; import { ConditionalChange } from "../build-ts/src/commands/ConditionalChange"; -import { FlushMode } from "../build-ts/src/commands/FlushMode"; async function getVersion(): Promise<[number, number, number]> { const versionString = await new Promise((resolve, reject) => { diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index f9ee85c6ff..34c8ee8412 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -23,7 +23,7 @@ import { BitmapIndexType, BitOffsetOptions, } from "../build-ts/src/commands/BitOffsetOptions"; -import { FlushMode } from "../build-ts/src/commands/FlushMode"; +import { FlushMode } from "../build-ts/src/Commands"; import { GeospatialData } from "../build-ts/src/commands/geospatial/GeospatialData"; import { LPosOptions } from "../build-ts/src/commands/LPosOptions"; import { checkIfServerVersionLessThan } from "./SharedTests"; From 4cfa04442fe4bad1aa608a34a29903d2509803b7 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 10:24:01 -0700 Subject: [PATCH 3/8] Converted GeoAdd options classes to types Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 9 +- node/src/Commands.ts | 61 +++++++++++-- node/src/Transaction.ts | 6 +- node/src/commands/ConditionalChange.ts | 21 ----- node/src/commands/geospatial/GeoAddOptions.ts | 52 ----------- .../src/commands/geospatial/GeospatialData.ts | 37 -------- node/tests/SharedTests.ts | 91 ++++++++----------- node/tests/TestUtilities.ts | 10 +- 8 files changed, 107 insertions(+), 180 deletions(-) delete mode 100644 node/src/commands/ConditionalChange.ts delete mode 100644 node/src/commands/geospatial/GeoAddOptions.ts delete mode 100644 node/src/commands/geospatial/GeospatialData.ts diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index c441760c05..2f7e8a1f88 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -13,6 +13,8 @@ import { Buffer, BufferWriter, Reader, Writer } from "protobufjs"; import { AggregationType, ExpireOptions, + GeoAddOptions, + GeospatialData, InsertPosition, KeyWeight, LPosOptions, @@ -3398,8 +3400,11 @@ export class BaseClient { * * @example * ```typescript - * const options = new GeoAddOptions({updateMode: ConditionalChange.ONLY_IF_EXISTS, changed: true}); - * const num = await client.geoadd("mySortedSet", new Map([["Palermo", new GeospatialData(13.361389, 38.115556)]]), options); + * const options = {updateMode: ConditionalChange.ONLY_IF_EXISTS, changed: true}; + * const membersToCoordinates = new Map([ + * ["Palermo", { longitude: 13.361389, latitude: 38.115556 }], + * ]); + * const num = await client.geoadd("mySortedSet", membersToCoordinates, options); * console.log(num); // Output: 1 - Indicates that the position of an existing member in the sorted set "mySortedSet" has been updated. * ``` */ diff --git a/node/src/Commands.ts b/node/src/Commands.ts index f08c6c0681..d4ae79333d 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -4,17 +4,15 @@ import { createLeakedStringVec, MAX_REQUEST_ARGS_LEN } from "glide-rs"; import Long from "long"; -import { FlushMode } from "./commands/FlushMode"; -import { LPosOptions } from "./commands/LPosOptions"; +/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ +import { BaseClient } from "src/BaseClient"; /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ import { GlideClient } from "src/GlideClient"; /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ import { GlideClusterClient } from "src/GlideClusterClient"; import { command_request } from "./ProtobufMessage"; import { BitOffsetOptions } from "./commands/BitOffsetOptions"; -import { GeoAddOptions } from "./commands/geospatial/GeoAddOptions"; -import { GeospatialData } from "./commands/geospatial/GeospatialData"; import RequestType = command_request.RequestType; @@ -1884,6 +1882,48 @@ export function createDBSize(): command_request.Command { return createCommand(RequestType.DBSize, []); } +/** + * An optional condition to the {@link BaseClient.geoadd} command. + */ +export enum ConditionalChange { + /** + * Only update elements that already exist. Don't add new elements. Equivalent to `XX` in the Valkey API. + */ + ONLY_IF_EXISTS = "XX", + + /** + * Only add new elements. Don't update already existing elements. Equivalent to `NX` in the Valkey API. + * */ + ONLY_IF_DOES_NOT_EXIST = "NX", +} + +/** + * Represents a geographic position defined by longitude and latitude. + * The exact limits, as specified by `EPSG:900913 / EPSG:3785 / OSGEO:41001` are the + * following: + * + * Valid longitudes are from `-180` to `180` degrees. + * Valid latitudes are from `-85.05112878` to `85.05112878` degrees. + */ +export type GeospatialData = { + /** The longitude coordinate. */ + longitude: number; + /** The latitude coordinate. */ + latitude: number; +}; + +/** + * Optional arguments for the GeoAdd command. + * + * See https://valkey.io/commands/geoadd/ for more details. + */ +export type GeoAddOptions = { + /** Options for handling existing members. See {@link ConditionalChange}. */ + updateMode?: ConditionalChange; + /** If `true`, returns the count of changed elements instead of new elements added. */ + changed?: boolean; +}; + /** * @internal */ @@ -1895,11 +1935,20 @@ export function createGeoAdd( let args: string[] = [key]; if (options) { - args = args.concat(options.toArgs()); + if (options.updateMode) { + args.push(options.updateMode); + } + + if (options.changed) { + args.push("CH"); + } } membersToGeospatialData.forEach((coord, member) => { - args = args.concat(coord.toArgs()); + args = args.concat([ + coord.longitude.toString(), + coord.latitude.toString(), + ]); args.push(member); }); return createCommand(RequestType.GeoAdd, args); diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 5cb2ab7fbd..f24b837056 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -6,6 +6,8 @@ import { AggregationType, ExpireOptions, FlushMode, + GeoAddOptions, + GeospatialData, InfoOptions, InsertPosition, KeyWeight, @@ -145,10 +147,6 @@ import { } from "./Commands"; import { command_request } from "./ProtobufMessage"; import { BitOffsetOptions } from "./commands/BitOffsetOptions"; -import { FlushMode } from "./commands/FlushMode"; -import { LPosOptions } from "./commands/LPosOptions"; -import { GeoAddOptions } from "./commands/geospatial/GeoAddOptions"; -import { GeospatialData } from "./commands/geospatial/GeospatialData"; /** * Base class encompassing shared commands for both standalone and cluster mode implementations in a transaction. diff --git a/node/src/commands/ConditionalChange.ts b/node/src/commands/ConditionalChange.ts deleted file mode 100644 index 5904f90d32..0000000000 --- a/node/src/commands/ConditionalChange.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -import { BaseClient } from "src/BaseClient"; - -/** - * An optional condition to the {@link BaseClient.geoadd} command. - */ -export enum ConditionalChange { - /** - * Only update elements that already exist. Don't add new elements. Equivalent to `XX` in the Valkey API. - */ - ONLY_IF_EXISTS = "XX", - - /** - * Only add new elements. Don't update already existing elements. Equivalent to `NX` in the Valkey API. - * */ - ONLY_IF_DOES_NOT_EXIST = "NX", -} diff --git a/node/src/commands/geospatial/GeoAddOptions.ts b/node/src/commands/geospatial/GeoAddOptions.ts deleted file mode 100644 index 220dff8e19..0000000000 --- a/node/src/commands/geospatial/GeoAddOptions.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -import { ConditionalChange } from "../ConditionalChange"; - -/** - * Optional arguments for the GeoAdd command. - * - * See https://valkey.io/commands/geoadd/ for more details. - */ -export class GeoAddOptions { - /** Valkey API keyword use to modify the return value from the number of new elements added, to the total number of elements changed. */ - public static CHANGED_VALKEY_API = "CH"; - - private updateMode?: ConditionalChange; - - private changed?: boolean; - - /** - * Default constructor for GeoAddOptions. - * - * @param updateMode - Options for handling existing members. See {@link ConditionalChange}. - * @param latitude - If `true`, returns the count of changed elements instead of new elements added. - */ - constructor(options: { - updateMode?: ConditionalChange; - changed?: boolean; - }) { - this.updateMode = options.updateMode; - this.changed = options.changed; - } - - /** - * Converts GeoAddOptions into a string[]. - * - * @returns string[] - */ - public toArgs(): string[] { - const args: string[] = []; - - if (this.updateMode) { - args.push(this.updateMode); - } - - if (this.changed) { - args.push(GeoAddOptions.CHANGED_VALKEY_API); - } - - return args; - } -} diff --git a/node/src/commands/geospatial/GeospatialData.ts b/node/src/commands/geospatial/GeospatialData.ts deleted file mode 100644 index 63c15bdff0..0000000000 --- a/node/src/commands/geospatial/GeospatialData.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -/** - * Represents a geographic position defined by longitude and latitude. - * The exact limits, as specified by `EPSG:900913 / EPSG:3785 / OSGEO:41001` are the - * following: - * - * Valid longitudes are from `-180` to `180` degrees. - * Valid latitudes are from `-85.05112878` to `85.05112878` degrees. - */ -export class GeospatialData { - private longitude: number; - - private latitude: number; - - /** - * Default constructor for GeospatialData. - * - * @param longitude - The longitude coordinate. - * @param latitude - The latitude coordinate. - */ - constructor(longitude: number, latitude: number) { - this.longitude = longitude; - this.latitude = latitude; - } - - /** - * Converts GeospatialData into a string[]. - * - * @returns string[] - */ - public toArgs(): string[] { - return [this.longitude.toString(), this.latitude.toString()]; - } -} diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 4255a168df..dc853a47a4 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -19,6 +19,12 @@ import { Script, parseInfoResponse, } from "../"; +import { ConditionalChange, GeospatialData } from "../build-ts/src/Commands"; +import { SingleNodeRoute } from "../build-ts/src/GlideClusterClient"; +import { + BitOffsetOptions, + BitmapIndexType, +} from "../build-ts/src/commands/BitOffsetOptions"; import { Client, GetAndSetRandomValue, @@ -28,14 +34,6 @@ import { intoArray, intoString, } from "./TestUtilities"; -import { SingleNodeRoute } from "../build-ts/src/GlideClusterClient"; -import { - BitmapIndexType, - BitOffsetOptions, -} from "../build-ts/src/commands/BitOffsetOptions"; -import { GeospatialData } from "../build-ts/src/commands/geospatial/GeospatialData"; -import { GeoAddOptions } from "../build-ts/src/commands/geospatial/GeoAddOptions"; -import { ConditionalChange } from "../build-ts/src/commands/ConditionalChange"; async function getVersion(): Promise<[number, number, number]> { const versionString = await new Promise((resolve, reject) => { @@ -4411,14 +4409,14 @@ export function runBaseTests(config: { const key1 = uuidv4(); const key2 = uuidv4(); const membersToCoordinates = new Map(); - membersToCoordinates.set( - "Palermo", - new GeospatialData(13.361389, 38.115556), - ); - membersToCoordinates.set( - "Catania", - new GeospatialData(15.087269, 37.502669), - ); + membersToCoordinates.set("Palermo", { + longitude: 13.361389, + latitude: 38.115556, + }); + membersToCoordinates.set("Catania", { + longitude: 15.087269, + latitude: 37.502669, + }); // default geoadd expect(await client.geoadd(key1, membersToCoordinates)).toBe(2); @@ -4446,45 +4444,34 @@ export function runBaseTests(config: { expect(geopos).toEqual([null]); // with update mode options - membersToCoordinates.set( - "Catania", - new GeospatialData(15.087269, 39), - ); + membersToCoordinates.set("Catania", { + longitude: 15.087269, + latitude: 39, + }); expect( - await client.geoadd( - key1, - membersToCoordinates, - new GeoAddOptions({ - updateMode: - ConditionalChange.ONLY_IF_DOES_NOT_EXIST, - }), - ), + await client.geoadd(key1, membersToCoordinates, { + updateMode: ConditionalChange.ONLY_IF_DOES_NOT_EXIST, + }), ).toBe(0); expect( - await client.geoadd( - key1, - membersToCoordinates, - new GeoAddOptions({ - updateMode: ConditionalChange.ONLY_IF_EXISTS, - }), - ), + await client.geoadd(key1, membersToCoordinates, { + updateMode: ConditionalChange.ONLY_IF_EXISTS, + }), ).toBe(0); // with changed option - membersToCoordinates.set( - "Catania", - new GeospatialData(15.087269, 40), - ); - membersToCoordinates.set( - "Tel-Aviv", - new GeospatialData(32.0853, 34.7818), - ); + membersToCoordinates.set("Catania", { + longitude: 15.087269, + latitude: 40, + }); + membersToCoordinates.set("Tel-Aviv", { + longitude: 32.0853, + latitude: 34.7818, + }); expect( - await client.geoadd( - key1, - membersToCoordinates, - new GeoAddOptions({ changed: true }), - ), + await client.geoadd(key1, membersToCoordinates, { + changed: true, + }), ).toBe(2); // key exists but holding non-zset value @@ -4511,25 +4498,25 @@ export function runBaseTests(config: { await expect( client.geoadd( key, - new Map([["Place", new GeospatialData(-181, 0)]]), + new Map([["Place", { longitude: -181, latitude: 0 }]]), ), ).rejects.toThrow(); await expect( client.geoadd( key, - new Map([["Place", new GeospatialData(181, 0)]]), + new Map([["Place", { longitude: 181, latitude: 0 }]]), ), ).rejects.toThrow(); await expect( client.geoadd( key, - new Map([["Place", new GeospatialData(0, 86)]]), + new Map([["Place", { longitude: 0, latitude: 86 }]]), ), ).rejects.toThrow(); await expect( client.geoadd( key, - new Map([["Place", new GeospatialData(0, -86)]]), + new Map([["Place", { longitude: 0, latitude: -86 }]]), ), ).rejects.toThrow(); }, protocol); diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 34c8ee8412..ffc27df9c5 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -19,13 +19,11 @@ import { ScoreFilter, Transaction, } from ".."; +import { FlushMode, GeospatialData } from "../build-ts/src/Commands"; import { BitmapIndexType, BitOffsetOptions, } from "../build-ts/src/commands/BitOffsetOptions"; -import { FlushMode } from "../build-ts/src/Commands"; -import { GeospatialData } from "../build-ts/src/commands/geospatial/GeospatialData"; -import { LPosOptions } from "../build-ts/src/commands/LPosOptions"; import { checkIfServerVersionLessThan } from "./SharedTests"; beforeAll(() => { @@ -657,9 +655,9 @@ export async function transactionTest( args.push(3); baseTransaction.geoadd( key18, - new Map([ - ["Palermo", new GeospatialData(13.361389, 38.115556)], - ["Catania", new GeospatialData(15.087269, 37.502669)], + new Map([ + ["Palermo", { longitude: 13.361389, latitude: 38.115556 }], + ["Catania", { longitude: 15.087269, latitude: 37.502669 }], ]), ); args.push(2); From 958c09a926e156328e0e5f46a1ea4db008c41642 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 11:19:20 -0700 Subject: [PATCH 4/8] Resolved conflicts Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 3 --- node/tests/SharedTests.ts | 2 -- 2 files changed, 5 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 2f7e8a1f88..d6a795c5f8 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -132,9 +132,6 @@ import { createZScore, } from "./Commands"; import { BitOffsetOptions } from "./commands/BitOffsetOptions"; -import { GeoAddOptions } from "./commands/geospatial/GeoAddOptions"; -import { GeospatialData } from "./commands/geospatial/GeospatialData"; -import { LPosOptions } from "./commands/LPosOptions"; import { ClosingError, ConfigurationError, diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index dc853a47a4..34e305d56a 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -303,8 +303,6 @@ export function runBaseTests(config: { await client.set("foo", "bar"); const oldResult = await client.info([InfoOptions.Commandstats]); const oldResultAsString = intoString(oldResult); - console.log(oldResult); - console.log(oldResultAsString); expect(oldResultAsString).toContain("cmdstat_set"); checkSimple(await client.configResetStat()).toEqual("OK"); From 1d286a84a4fc5e8f4a1cdadd547a38426b8d73ac Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 14:54:12 -0700 Subject: [PATCH 5/8] Updated ZAddOptions Signed-off-by: Guian Gumpac --- node/npm/glide/index.ts | 2 ++ node/src/BaseClient.ts | 3 ++- node/src/Commands.ts | 32 +++++++++++++++++++++----------- node/tests/SharedTests.ts | 24 +++++++++++++++--------- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/node/npm/glide/index.ts b/node/npm/glide/index.ts index dce8b31649..7726ae0ac5 100644 --- a/node/npm/glide/index.ts +++ b/node/npm/glide/index.ts @@ -98,6 +98,7 @@ function initialize() { SetOptions, ZaddOptions, ScoreBoundry, + UpdateOptions, RangeByIndex, RangeByScore, RangeByLex, @@ -151,6 +152,7 @@ function initialize() { SetOptions, ZaddOptions, ScoreBoundry, + UpdateOptions, RangeByIndex, RangeByScore, RangeByLex, diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index d6a795c5f8..8afdccb5c4 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -2224,7 +2224,8 @@ export class BaseClient { * @example * ```typescript * // Example usage of the zadd method to update scores in an existing sorted set - * const result = await client.zadd("existing_sorted_set", { member1: 15.0, member2: 5.5 }, { conditionalChange: "onlyIfExists", changed: true }); + * const options = { conditionalChange: ConditionalChange.ONLY_IF_EXISTS, changed: true }; + * const result = await client.zadd("existing_sorted_set", { member1: 15.0, member2: 5.5 }, options); * console.log(result); // Output: 2 - Updates the scores of two existing members in the sorted set "existing_sorted_set." * ``` */ diff --git a/node/src/Commands.ts b/node/src/Commands.ts index d4ae79333d..8c73a8c57a 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -925,6 +925,16 @@ export function createTTL(key: string): command_request.Command { return createCommand(RequestType.TTL, [key]); } +/** + * Options for updating elements of a sorted set key. + */ +export enum UpdateOptions { + /** Only update existing elements if the new score is less than the current score. */ + LESS_THAN = "LT", + /** Only update existing elements if the new score is greater than the current score. */ + GREATER_THAN = "GT", +} + export type ZAddOptions = { /** * `onlyIfDoesNotExist` - Only add new elements. Don't update already existing @@ -932,14 +942,14 @@ export type ZAddOptions = { * elements that already exist. Don't add new elements. Equivalent to `XX` in * the Redis API. */ - conditionalChange?: "onlyIfExists" | "onlyIfDoesNotExist"; + conditionalChange?: ConditionalChange; /** * `scoreLessThanCurrent` - Only update existing elements if the new score is * less than the current score. Equivalent to `LT` in the Redis API. * `scoreGreaterThanCurrent` - Only update existing elements if the new score * is greater than the current score. Equivalent to `GT` in the Redis API. */ - updateOptions?: "scoreLessThanCurrent" | "scoreGreaterThanCurrent"; + updateOptions?: UpdateOptions; /** * Modify the return value from the number of new elements added, to the total number of elements changed. */ @@ -958,22 +968,22 @@ export function createZAdd( let args = [key]; if (options) { - if (options.conditionalChange === "onlyIfExists") { - args.push("XX"); - } else if (options.conditionalChange === "onlyIfDoesNotExist") { - if (options.updateOptions) { + if (options.conditionalChange) { + if ( + options.conditionalChange === + ConditionalChange.ONLY_IF_DOES_NOT_EXIST && + options.updateOptions + ) { throw new Error( `The GT, LT, and NX options are mutually exclusive. Cannot choose both ${options.updateOptions} and NX.`, ); } - args.push("NX"); + args.push(options.conditionalChange); } - if (options.updateOptions === "scoreLessThanCurrent") { - args.push("LT"); - } else if (options.updateOptions === "scoreGreaterThanCurrent") { - args.push("GT"); + if (options.updateOptions) { + args.push(options.updateOptions); } if (options.changed) { diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 34e305d56a..f77c638e7f 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -19,7 +19,11 @@ import { Script, parseInfoResponse, } from "../"; -import { ConditionalChange, GeospatialData } from "../build-ts/src/Commands"; +import { + ConditionalChange, + GeospatialData, + UpdateOptions, +} from "../build-ts/src/Commands"; import { SingleNodeRoute } from "../build-ts/src/GlideClusterClient"; import { BitOffsetOptions, @@ -2108,25 +2112,27 @@ export function runBaseTests(config: { const membersScores = { one: 1, two: 2, three: 3 }; expect( await client.zadd(key, membersScores, { - conditionalChange: "onlyIfExists", + conditionalChange: ConditionalChange.ONLY_IF_EXISTS, }), ).toEqual(0); expect( await client.zadd(key, membersScores, { - conditionalChange: "onlyIfDoesNotExist", + conditionalChange: + ConditionalChange.ONLY_IF_DOES_NOT_EXIST, }), ).toEqual(3); expect( await client.zaddIncr(key, "one", 5.0, { - conditionalChange: "onlyIfDoesNotExist", + conditionalChange: + ConditionalChange.ONLY_IF_DOES_NOT_EXIST, }), ).toEqual(null); expect( await client.zaddIncr(key, "one", 5.0, { - conditionalChange: "onlyIfExists", + conditionalChange: ConditionalChange.ONLY_IF_EXISTS, }), ).toEqual(6.0); }, protocol); @@ -2146,27 +2152,27 @@ export function runBaseTests(config: { expect( await client.zadd(key, membersScores, { - updateOptions: "scoreGreaterThanCurrent", + updateOptions: UpdateOptions.GREATER_THAN, changed: true, }), ).toEqual(1); expect( await client.zadd(key, membersScores, { - updateOptions: "scoreLessThanCurrent", + updateOptions: UpdateOptions.LESS_THAN, changed: true, }), ).toEqual(0); expect( await client.zaddIncr(key, "one", -3.0, { - updateOptions: "scoreLessThanCurrent", + updateOptions: UpdateOptions.LESS_THAN, }), ).toEqual(7.0); expect( await client.zaddIncr(key, "one", -3.0, { - updateOptions: "scoreGreaterThanCurrent", + updateOptions: UpdateOptions.GREATER_THAN, }), ).toEqual(null); }, protocol); From 8217c609c4029706a49aff2f81f37224a761488e Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 16:00:21 -0700 Subject: [PATCH 6/8] Converted BitOffsetOptions to type Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 2 +- node/src/Commands.ts | 53 ++++++++++++++---- node/src/Transaction.ts | 4 +- node/src/commands/BitOffsetOptions.ts | 60 -------------------- node/tests/SharedTests.ts | 79 ++++++++++++++------------- node/tests/TestUtilities.ts | 17 +++--- 6 files changed, 95 insertions(+), 120 deletions(-) delete mode 100644 node/src/commands/BitOffsetOptions.ts diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 8afdccb5c4..cc365dc57c 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -12,6 +12,7 @@ import * as net from "net"; import { Buffer, BufferWriter, Reader, Writer } from "protobufjs"; import { AggregationType, + BitOffsetOptions, ExpireOptions, GeoAddOptions, GeospatialData, @@ -131,7 +132,6 @@ import { createZRevRankWithScore, createZScore, } from "./Commands"; -import { BitOffsetOptions } from "./commands/BitOffsetOptions"; import { ClosingError, ConfigurationError, diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 8c73a8c57a..02a5229f0d 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -12,7 +12,6 @@ import { GlideClient } from "src/GlideClient"; /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ import { GlideClusterClient } from "src/GlideClusterClient"; import { command_request } from "./ProtobufMessage"; -import { BitOffsetOptions } from "./commands/BitOffsetOptions"; import RequestType = command_request.RequestType; @@ -937,17 +936,11 @@ export enum UpdateOptions { export type ZAddOptions = { /** - * `onlyIfDoesNotExist` - Only add new elements. Don't update already existing - * elements. Equivalent to `NX` in the Redis API. `onlyIfExists` - Only update - * elements that already exist. Don't add new elements. Equivalent to `XX` in - * the Redis API. + * Options for handling existing members. */ conditionalChange?: ConditionalChange; /** - * `scoreLessThanCurrent` - Only update existing elements if the new score is - * less than the current score. Equivalent to `LT` in the Redis API. - * `scoreGreaterThanCurrent` - Only update existing elements if the new score - * is greater than the current score. Equivalent to `GT` in the Redis API. + * Options for updating scores. */ updateOptions?: UpdateOptions; /** @@ -1616,6 +1609,40 @@ export function createFunctionLoad( return createCommand(RequestType.FunctionLoad, args); } +/** + * Enumeration specifying if index arguments are BYTE indexes or BIT indexes. + * Can be specified in {@link BitOffsetOptions}, which is an optional argument to the {@link BaseClient.bitcount|bitcount} command. + * + * since - Valkey version 7.0.0. + */ +export enum BitmapIndexType { + /** Specifies that indexes provided to {@link BitOffsetOptions} are byte indexes. */ + BYTE = "BYTE", + /** Specifies that indexes provided to {@link BitOffsetOptions} are bit indexes. */ + BIT = "BIT", +} + +/** + * Represents offsets specifying a string interval to analyze in the {@link BaseClient.bitcount|bitcount} command. The offsets are + * zero-based indexes, with `0` being the first index of the string, `1` being the next index and so on. + * The offsets can also be negative numbers indicating offsets starting at the end of the string, with `-1` being + * the last index of the string, `-2` being the penultimate, and so on. + * + * See https://valkey.io/commands/bitcount/ for more details. + */ +export type BitOffsetOptions = { + /** The starting offset index. */ + start: number; + /** The ending offset index. */ + end: number; + /** + * The index offset type. This option can only be specified if you are using server version 7.0.0 or above. + * Could be either {@link BitmapIndexType.BYTE} or {@link BitmapIndexType.BIT}. + * If no index type is provided, the indexes will be assumed to be byte indexes. + */ + indexType?: BitmapIndexType; +}; + /** * @internal */ @@ -1624,7 +1651,13 @@ export function createBitCount( options?: BitOffsetOptions, ): command_request.Command { const args = [key]; - if (options) args.push(...options.toArgs()); + + if (options) { + args.push(options.start.toString()); + args.push(options.end.toString()); + if (options.indexType) args.push(options.indexType); + } + return createCommand(RequestType.BitCount, args); } diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index f24b837056..87ba81ed28 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -4,6 +4,7 @@ import { AggregationType, + BitOffsetOptions, ExpireOptions, FlushMode, GeoAddOptions, @@ -11,8 +12,8 @@ import { InfoOptions, InsertPosition, KeyWeight, - LolwutOptions, LPosOptions, + LolwutOptions, RangeByIndex, RangeByLex, RangeByScore, @@ -146,7 +147,6 @@ import { createZScore, } from "./Commands"; import { command_request } from "./ProtobufMessage"; -import { BitOffsetOptions } from "./commands/BitOffsetOptions"; /** * Base class encompassing shared commands for both standalone and cluster mode implementations in a transaction. diff --git a/node/src/commands/BitOffsetOptions.ts b/node/src/commands/BitOffsetOptions.ts deleted file mode 100644 index 64f6f8a82e..0000000000 --- a/node/src/commands/BitOffsetOptions.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ - -// Import below added to fix up the TSdoc link, but eslint blames for unused import. -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -import { BaseClient } from "src/BaseClient"; - -/** - * Enumeration specifying if index arguments are BYTE indexes or BIT indexes. - * Can be specified in {@link BitOffsetOptions}, which is an optional argument to the {@link BaseClient.bitcount|bitcount} command. - * - * since - Valkey version 7.0.0. - */ -export enum BitmapIndexType { - /** Specifies that indexes provided to {@link BitOffsetOptions} are byte indexes. */ - BYTE = "BYTE", - /** Specifies that indexes provided to {@link BitOffsetOptions} are bit indexes. */ - BIT = "BIT", -} - -/** - * Represents offsets specifying a string interval to analyze in the {@link BaseClient.bitcount|bitcount} command. The offsets are - * zero-based indexes, with `0` being the first index of the string, `1` being the next index and so on. - * The offsets can also be negative numbers indicating offsets starting at the end of the string, with `-1` being - * the last index of the string, `-2` being the penultimate, and so on. - * - * See https://valkey.io/commands/bitcount/ for more details. - */ -export class BitOffsetOptions { - private start: number; - private end: number; - private indexType?: BitmapIndexType; - - /** - * @param start - The starting offset index. - * @param end - The ending offset index. - * @param indexType - The index offset type. This option can only be specified if you are using server version 7.0.0 or above. - * Could be either {@link BitmapIndexType.BYTE} or {@link BitmapIndexType.BIT}. - * If no index type is provided, the indexes will be assumed to be byte indexes. - */ - constructor(start: number, end: number, indexType?: BitmapIndexType) { - this.start = start; - this.end = end; - this.indexType = indexType; - } - - /** - * Converts BitOffsetOptions into a string[]. - * - * @returns string[] - */ - public toArgs(): string[] { - const args = [this.start.toString(), this.end.toString()]; - - if (this.indexType) args.push(this.indexType); - - return args; - } -} diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index f77c638e7f..9f15073aad 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -20,15 +20,12 @@ import { parseInfoResponse, } from "../"; import { + BitmapIndexType, ConditionalChange, GeospatialData, UpdateOptions, } from "../build-ts/src/Commands"; import { SingleNodeRoute } from "../build-ts/src/GlideClusterClient"; -import { - BitOffsetOptions, - BitmapIndexType, -} from "../build-ts/src/commands/BitOffsetOptions"; import { Client, GetAndSetRandomValue, @@ -4333,18 +4330,15 @@ export function runBaseTests(config: { checkSimple(await client.set(key1, value)).toEqual("OK"); expect(await client.bitcount(key1)).toEqual(26); expect( - await client.bitcount(key1, new BitOffsetOptions(1, 1)), + await client.bitcount(key1, { start: 1, end: 1 }), ).toEqual(6); expect( - await client.bitcount(key1, new BitOffsetOptions(0, -5)), + await client.bitcount(key1, { start: 0, end: -5 }), ).toEqual(10); // non-existing key expect(await client.bitcount(uuidv4())).toEqual(0); expect( - await client.bitcount( - uuidv4(), - new BitOffsetOptions(5, 30), - ), + await client.bitcount(uuidv4(), { start: 5, end: 30 }), ).toEqual(0); // key exists, but it is not a string expect(await client.sadd(key2, [value])).toEqual(1); @@ -4352,53 +4346,60 @@ export function runBaseTests(config: { RequestError, ); await expect( - client.bitcount(key2, new BitOffsetOptions(1, 1)), + client.bitcount(key2, { start: 1, end: 1 }), ).rejects.toThrow(RequestError); if (await checkIfServerVersionLessThan("7.0.0")) { await expect( - client.bitcount( - key1, - new BitOffsetOptions(2, 5, BitmapIndexType.BIT), - ), + client.bitcount(key1, { + start: 2, + end: 5, + indexType: BitmapIndexType.BIT, + }), ).rejects.toThrow(); await expect( - client.bitcount( - key1, - new BitOffsetOptions(2, 5, BitmapIndexType.BYTE), - ), + client.bitcount(key1, { + start: 2, + end: 5, + indexType: BitmapIndexType.BYTE, + }), ).rejects.toThrow(); } else { expect( - await client.bitcount( - key1, - new BitOffsetOptions(2, 5, BitmapIndexType.BYTE), - ), + await client.bitcount(key1, { + start: 2, + end: 5, + indexType: BitmapIndexType.BYTE, + }), ).toEqual(16); expect( - await client.bitcount( - key1, - new BitOffsetOptions(5, 30, BitmapIndexType.BIT), - ), + await client.bitcount(key1, { + start: 5, + end: 30, + indexType: BitmapIndexType.BIT, + }), ).toEqual(17); expect( - await client.bitcount( - key1, - new BitOffsetOptions(5, -5, BitmapIndexType.BIT), - ), + await client.bitcount(key1, { + start: 5, + end: -5, + indexType: BitmapIndexType.BIT, + }), ).toEqual(23); expect( - await client.bitcount( - uuidv4(), - new BitOffsetOptions(2, 5, BitmapIndexType.BYTE), - ), + await client.bitcount(uuidv4(), { + start: 2, + end: 5, + indexType: BitmapIndexType.BYTE, + }), ).toEqual(0); // key exists, but it is not a string await expect( - client.bitcount( - key2, - new BitOffsetOptions(1, 1, BitmapIndexType.BYTE), - ), + client.bitcount(key2, { + start: 1, + end: 1, + indexType: BitmapIndexType.BYTE, + }), ).rejects.toThrow(RequestError); } }, protocol); diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index ffc27df9c5..1dcd484b8e 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -19,11 +19,11 @@ import { ScoreFilter, Transaction, } from ".."; -import { FlushMode, GeospatialData } from "../build-ts/src/Commands"; import { BitmapIndexType, - BitOffsetOptions, -} from "../build-ts/src/commands/BitOffsetOptions"; + FlushMode, + GeospatialData, +} from "../build-ts/src/Commands"; import { checkIfServerVersionLessThan } from "./SharedTests"; beforeAll(() => { @@ -638,14 +638,15 @@ export async function transactionTest( args.push("OK"); baseTransaction.bitcount(key17); args.push(26); - baseTransaction.bitcount(key17, new BitOffsetOptions(1, 1)); + baseTransaction.bitcount(key17, { start: 1, end: 1 }); args.push(6); if (!(await checkIfServerVersionLessThan("7.0.0"))) { - baseTransaction.bitcount( - key17, - new BitOffsetOptions(5, 30, BitmapIndexType.BIT), - ); + baseTransaction.bitcount(key17, { + start: 5, + end: 30, + indexType: BitmapIndexType.BIT, + }); args.push(17); } From 704a685ebbf65c67797ef3b85fb20ac36c86a450 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 16:08:45 -0700 Subject: [PATCH 7/8] Fixed example in docs Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index cc365dc57c..43c8a31b83 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -3373,9 +3373,9 @@ export class BaseClient { * @example * ```typescript * console.log(await client.bitcount("my_key1")); // Output: 2 - The string stored at "my_key1" contains 2 set bits. - * console.log(await client.bitcount("my_key2", OffsetOptions(1, 3))); // Output: 2 - The second to fourth bytes of the string stored at "my_key2" contain 2 set bits. - * console.log(await client.bitcount("my_key3", OffsetOptions(1, 1, BitmapIndexType.BIT))); // Output: 1 - Indicates that the second bit of the string stored at "my_key3" is set. - * console.log(await client.bitcount("my_key3", OffsetOptions(-1, -1, BitmapIndexType.BIT))); // Output: 1 - Indicates that the last bit of the string stored at "my_key3" is set. + * console.log(await client.bitcount("my_key2", { start: 1, end: 3 })); // Output: 2 - The second to fourth bytes of the string stored at "my_key2" contain 2 set bits. + * console.log(await client.bitcount("my_key3", { start: 1, end: 1, indexType: BitmapIndexType.BIT })); // Output: 1 - Indicates that the second bit of the string stored at "my_key3" is set. + * console.log(await client.bitcount("my_key3", { start: -1, end: -1, indexType: BitmapIndexType.BIT })); // Output: 1 - Indicates that the last bit of the string stored at "my_key3" is set. * ``` */ public bitcount(key: string, options?: BitOffsetOptions): Promise { From 350bc30702a4aae4c1eef6dbb06bc7b01ef306e2 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Tue, 23 Jul 2024 16:24:56 -0700 Subject: [PATCH 8/8] Fixed example in docs Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 43c8a31b83..a4fd4aa30c 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -3430,7 +3430,7 @@ export class BaseClient { * * @example * ```typescript - * const data = new Map([["Palermo", new GeospatialData(13.361389, 38.115556)], ["Catania", new GeospatialData(15.087269, 37.502669)]]); + * const data = new Map([["Palermo", { longitude: 13.361389, latitude: 38.115556 }], ["Catania", { longitude: 15.087269, latitude: 37.502669 }]]); * await client.geoadd("mySortedSet", data); * const result = await client.geopos("mySortedSet", ["Palermo", "Catania", "NonExisting"]); * // When added via GEOADD, the geospatial coordinates are converted into a 52 bit geohash, so the coordinates