-
Notifications
You must be signed in to change notification settings - Fork 184
Node: Convert classes to types #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,14 @@ | |
|
|
||
| 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; | ||
|
|
||
|
|
@@ -976,21 +977,25 @@ export function createTTL(key: string): command_request.Command { | |
| return createCommand(RequestType.TTL, [key]); | ||
| } | ||
|
|
||
| /** | ||
| * Options for updating elements of a sorted set key. | ||
|
GumpacG marked this conversation as resolved.
|
||
| */ | ||
| export enum UpdateByScore { | ||
| /** 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 | ||
| * 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?: "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. | ||
| * Options for updating scores. | ||
| */ | ||
| updateOptions?: "scoreLessThanCurrent" | "scoreGreaterThanCurrent"; | ||
| updateOptions?: UpdateByScore; | ||
| /** | ||
| * Modify the return value from the number of new elements added, to the total number of elements changed. | ||
| */ | ||
|
|
@@ -1009,22 +1014,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) { | ||
|
|
@@ -1694,6 +1699,27 @@ export function createFunctionLoad( | |
| return createCommand(RequestType.FunctionLoad, args); | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
|
|
@@ -1702,7 +1728,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); | ||
| } | ||
|
|
||
|
|
@@ -1747,6 +1779,24 @@ export function createBitPos( | |
| return createCommand(RequestType.BitPos, args); | ||
| } | ||
|
|
||
| /** | ||
| * Defines flushing mode for {@link GlideClient.flushall}, {@link GlideClusterClient.flushall}, | ||
| * {@link GlideClient.functionFlush}, {@link GlideClusterClient.functionFlush}, | ||
| * {@link GlideClient.flushdb} and {@link GlideClusterClient.flushdb} commands. | ||
| * | ||
|
GumpacG marked this conversation as resolved.
|
||
| * 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", | ||
| } | ||
|
|
||
| export type StreamReadOptions = { | ||
| /** | ||
| * If set, the read request will block for the set amount of milliseconds or | ||
|
|
@@ -1932,6 +1982,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 | ||
| */ | ||
|
|
@@ -1940,10 +2004,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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you just use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do that with non-number types however, we can't do that with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be careful. The string value |
||
| 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); | ||
|
|
@@ -1956,6 +2033,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 | ||
| */ | ||
|
|
@@ -1967,11 +2086,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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a place to put string constants?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not currently, I think if we want to do this, it should be a part of a different PR as we may want to convert other types with string constants to enums. Would potentially be big enough on it's own. |
||
| } | ||
| } | ||
|
|
||
| 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); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.