-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TJ Zhang
committed
Jul 19, 2024
1 parent
34e253c
commit bad84c5
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* | ||
* An optional condition to the 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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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 { | ||
/** Redis 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 !== undefined) { | ||
args.push(this.updateMode.toString()); | ||
} | ||
|
||
if (this.changed !== undefined) { | ||
args.push(GeoAddOptions.CHANGED_VALKEY_API); | ||
args.push(this.changed.toString()); | ||
} | ||
|
||
return args; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* 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(coord: { longitude: number; latitude: number }) { | ||
this.longitude = coord.longitude; | ||
this.latitude = coord.latitude; | ||
} | ||
|
||
/** | ||
* | ||
* Converts GeospatialData into a string[]. | ||
* | ||
* @returns string[] | ||
*/ | ||
public toArgs(): string[] { | ||
return [this.longitude.toString(), this.latitude.toString()]; | ||
} | ||
} |