From 4aeef078f2df0af083aec55a0fdc25a89bac1152 Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Sat, 30 Jan 2021 17:57:07 -0800 Subject: [PATCH 1/2] Add typescript support --- index.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ package-lock.json | 15 ++++++++++++++- package.json | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c6358a7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,38 @@ +import { RedisClient } from 'redis' +export type Point = { + latitude: number + longitude: number +} + +export type GeoCallback = (err: Error, reply: TReply) => void + +export type NearbyOptions = { + withCoordinates: boolean // Will provide coordinates with locations, default false + withHashes: boolean // Will provide a 52bit Geohash Integer, default false + withDistances: boolean // Will provide distance from query, default false + order: 'ASC' | 'DESC' // or 'DESC' or true (same as 'ASC'), default false + units: 'm' | 'km' | 'mi' | 'ft' // or 'km', 'mi', 'ft', default 'm' + count: number // Number of results to return, default undefined + accurate: boolean // Useful if in emulated mode and accuracy is important, default false +} + +export type GeoRedis = { + delete(callback?: (err: Error) => void): void + removeLocations( + locationNames: string[], + callback?: GeoCallback + ): void + addLocation( + locationName: string, + position: Point, + callback?: GeoCallback + ): void + nearby( + locationName: string, + radius: number, + options?: NearbyOptions, + callback?: GeoCallback + ): void +} + +export function initialize(client: RedisClient): GeoRedis diff --git a/package-lock.json b/package-lock.json index ad360ea..ca6f97b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "georedis", - "version": "3.1.2", + "version": "3.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -159,6 +159,19 @@ "to-fast-properties": "^2.0.0" } }, + "@types/node": { + "version": "14.14.22", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz", + "integrity": "sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw==" + }, + "@types/redis": { + "version": "2.8.28", + "resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.28.tgz", + "integrity": "sha512-8l2gr2OQ969ypa7hFOeKqtFoY70XkHxISV0pAwmQ2nm6CSPb1brmTmqJCGGrekCo+pAZyWlNXr+Kvo6L/1wijA==", + "requires": { + "@types/node": "*" + } + }, "acorn": { "version": "7.4.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz", diff --git a/package.json b/package.json index 34a9962..2d3e337 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "url": "https://github.com/arjunmehta/node-georedis" }, "dependencies": { + "@types/redis": "^2.8.28", "geolib": "2.0.24", "ngeohash": "0.6.3" }, From fb17a7b282b40ab8d425c7289000ff625501f210 Mon Sep 17 00:00:00 2001 From: Ben Allfree Date: Fri, 5 Feb 2021 22:15:09 -0800 Subject: [PATCH 2/2] Readme update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2ee411c..3b56322 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Other bonuses: npm install --save georedis ``` +Note: A promise-based wrapper is available via `npm install --save georedis-promised`. The API is identical, but promises are used instead of callbacks. + ## Basic Usage Usage of this module should be extremely simple. Just make sure that your Redis server is accessible to your Node environment. Because this module uses Redis as a store, almost all methods have integrated error handling for queries.