Skip to content

buillds with ts 5 + sdk v3 #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1,958 changes: 1,958 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dynamodb-geo",
"version": "0.4.0",
"version": "1.0.0-beta-1",
"description": "A javascript port of awslabs/dynamodb-geo, for dynamodb geospatial querying",
"scripts": {
"prepublish": "tsc -d",
Expand All @@ -14,21 +14,22 @@
"author": "Rob Hogan <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/core": "^3.588.0",
"@types/decimal.js": "^0.0.30",
"@types/long": ">=3",
"nodes2ts": "^1.1.10"
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "^3.588.0",
"@types/chai": "^4.0.0",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.27",
"aws-sdk": "^2.248.1",
"@types/node": "18",
"chai": "^4.0.1",
"mocha": "^3.3.0",
"ts-node": "^3.0.2",
"typescript": "^2.3.4"
"typescript": "^5.4.5"
},
"peerDependencies": {
"aws-sdk": "^2.176.0"
"@aws-sdk/client-dynamodb": "^3.588.0"
}
}
20 changes: 10 additions & 10 deletions src/GeoDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

import { AWSError, DynamoDB, Request } from "aws-sdk";
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { DynamoDBManager } from "./dynamodb/DynamoDBManager";
import { GeoDataManagerConfiguration } from "./GeoDataManagerConfiguration";
import {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class GeoDataManager {
*
* @return Result of put point request.
*/
public putPoint(putPointInput: PutPointInput): Request<PutPointOutput, AWSError> {
public putPoint(putPointInput: PutPointInput) {
return this.dynamoDBManager.putPoint(putPointInput);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ export class GeoDataManager {
*
* @return Result of batch put point request.
*/
public batchWritePoints(putPointInputs: PutPointInput[]): Request<BatchWritePointOutput, AWSError> {
public batchWritePoints(putPointInputs: PutPointInput[]) {
return this.dynamoDBManager.batchWritePoints(putPointInputs);
}

Expand All @@ -166,7 +166,7 @@ export class GeoDataManager {
*
* @return Result of get point request.
* */
public getPoint(getPointInput: GetPointInput): Request<GetPointOutput, AWSError> {
public getPoint(getPointInput: GetPointInput) {
return this.dynamoDBManager.getPoint(getPointInput);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ export class GeoDataManager {
*
* @return Result of rectangle query request.
*/
public async queryRectangle(queryRectangleInput: QueryRectangleInput): Promise<DynamoDB.ItemList> {
public async queryRectangle(queryRectangleInput: QueryRectangleInput) {
const latLngRect: S2LatLngRect = S2Util.latLngRectFromQueryRectangleInput(queryRectangleInput);

const covering = new Covering(new this.config.S2RegionCoverer().getCoveringCells(latLngRect));
Expand Down Expand Up @@ -226,7 +226,7 @@ export class GeoDataManager {
*
* @return Result of radius query request.
* */
public async queryRadius(queryRadiusInput: QueryRadiusInput): Promise<DynamoDB.ItemList> {
public async queryRadius(queryRadiusInput: QueryRadiusInput) {
const latLngRect: S2LatLngRect = S2Util.getBoundingLatLngRectFromQueryRadiusInput(queryRadiusInput);

const covering = new Covering(new this.config.S2RegionCoverer().getCoveringCells(latLngRect));
Expand Down Expand Up @@ -264,7 +264,7 @@ export class GeoDataManager {
*
* @return Result of update point request.
*/
public updatePoint(updatePointInput: UpdatePointInput): Request<UpdatePointOutput, AWSError> {
public updatePoint(updatePointInput: UpdatePointInput) {
return this.dynamoDBManager.updatePoint(updatePointInput);
}

Expand All @@ -289,7 +289,7 @@ export class GeoDataManager {
*
* @return Result of delete point request.
*/
public deletePoint(deletePointInput: DeletePointInput): Request<DeletePointOutput, AWSError> {
public deletePoint(deletePointInput: DeletePointInput) {
return this.dynamoDBManager.deletePoint(deletePointInput);
}

Expand Down Expand Up @@ -323,7 +323,7 @@ export class GeoDataManager {
* @param geoQueryInput
* @returns DynamoDB.ItemList
*/
private filterByRadius(list: DynamoDB.ItemList, geoQueryInput: QueryRadiusInput): DynamoDB.ItemList {
private filterByRadius(list, geoQueryInput: QueryRadiusInput) {
let centerLatLng: S2LatLng = null;
let radiusInMeter = 0;

Expand All @@ -350,7 +350,7 @@ export class GeoDataManager {
* @param geoQueryInput
* @returns DynamoDB.ItemList
*/
private filterByRectangle(list: DynamoDB.ItemList, geoQueryInput: QueryRectangleInput): DynamoDB.ItemList {
private filterByRectangle(list, geoQueryInput: QueryRectangleInput){
const latLngRect: S2LatLngRect = S2Util.latLngRectFromQueryRectangleInput(geoQueryInput);

return list.filter(item => {
Expand Down
5 changes: 3 additions & 2 deletions src/GeoDataManagerConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { DynamoDB } from "aws-sdk";
import {DynamoDBClient
} from '@aws-sdk/client-dynamodb'
import { S2RegionCoverer } from "nodes2ts";

export class GeoDataManagerConfiguration {
Expand Down Expand Up @@ -56,7 +57,7 @@ export class GeoDataManagerConfiguration {
*/
geoJsonPointType: 'Point' | 'POINT' = 'Point';

dynamoDBClient: DynamoDB;
dynamoDBClient: DynamoDBClient;

S2RegionCoverer: typeof S2RegionCoverer;

Expand Down
33 changes: 16 additions & 17 deletions src/dynamodb/DynamoDBManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { GeoDataManagerConfiguration } from "../GeoDataManagerConfiguration";
import { AWSError, DynamoDB, Request } from "aws-sdk";
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import {
BatchWritePointOutput,
DeletePointInput,
Expand All @@ -29,7 +29,7 @@ import {
import { S2Manager } from "../s2/S2Manager";
import { GeohashRange } from "../model/GeohashRange";
import * as Long from "long";
import { PutItemInput, PutRequest } from "aws-sdk/clients/dynamodb";
import {PutItemInput, PutRequest, GetItemCommand} from '@aws-sdk/client-dynamodb'

export class DynamoDBManager {
private config: GeoDataManagerConfiguration;
Expand All @@ -53,7 +53,7 @@ export class DynamoDBManager {
public async queryGeohash(queryInput: DynamoDB.QueryInput | undefined, hashKey: Long, range: GeohashRange): Promise<DynamoDB.QueryOutput[]> {
const queryOutputs: DynamoDB.QueryOutput[] = [];

const nextQuery = async (lastEvaluatedKey: DynamoDB.Key = null) => {
const nextQuery = async (lastEvaluatedKey: Record<string, DynamoDB.AttributeValue>= null) => {
const keyConditions: { [key: string]: DynamoDB.Condition } = {};

keyConditions[this.config.hashKeyAttributeName] = {
Expand All @@ -74,11 +74,10 @@ export class DynamoDBManager {
KeyConditions: keyConditions,
IndexName: this.config.geohashIndexName,
ConsistentRead: this.config.consistentRead,
ReturnConsumedCapacity: "TOTAL",
ExclusiveStartKey: lastEvaluatedKey
};

const queryOutput = await this.config.dynamoDBClient.query({ ...defaults, ...queryInput }).promise();
const queryOutput = await this.config.dynamoDBClient.send(new DynamoDB.QueryCommand({ ...defaults, ...queryInput }))
queryOutputs.push(queryOutput);
if (queryOutput.LastEvaluatedKey) {
return nextQuery(queryOutput.LastEvaluatedKey);
Expand All @@ -89,7 +88,7 @@ export class DynamoDBManager {
return queryOutputs;
}

public getPoint(getPointInput: GetPointInput): Request<GetPointOutput, AWSError> {
public getPoint(getPointInput: GetPointInput){
const geohash = S2Manager.generateGeohash(getPointInput.GeoPoint);
const hashKey = S2Manager.generateHashKey(geohash, this.config.hashKeyLength);

Expand All @@ -101,10 +100,10 @@ export class DynamoDBManager {
[this.config.rangeKeyAttributeName]: getPointInput.RangeKeyValue
};

return this.config.dynamoDBClient.getItem(getItemInput);
return this.config.dynamoDBClient.send(new GetItemCommand(getItemInput));
}

public putPoint(putPointInput: PutPointInput): Request<PutPointOutput, AWSError> {
public putPoint(putPointInput: PutPointInput) {
const geohash = S2Manager.generateGeohash(putPointInput.GeoPoint);
const hashKey = S2Manager.generateHashKey(geohash, this.config.hashKeyLength);
const putItemInput: PutItemInput = {
Expand All @@ -125,11 +124,11 @@ export class DynamoDBManager {
})
};

return this.config.dynamoDBClient.putItem(putItemInput);
return this.config.dynamoDBClient.send(new DynamoDB.PutItemCommand(putItemInput))
}


public batchWritePoints(putPointInputs: PutPointInput[]): Request<BatchWritePointOutput, AWSError> {
public batchWritePoints(putPointInputs: PutPointInput[]) {

const writeInputs: DynamoDB.WriteRequest[] = [];
putPointInputs.forEach(putPointInput => {
Expand All @@ -156,14 +155,14 @@ export class DynamoDBManager {
writeInputs.push({ PutRequest: putRequest });
});

return this.config.dynamoDBClient.batchWriteItem({
return this.config.dynamoDBClient.send(new DynamoDB.BatchWriteItemCommand({
RequestItems: {
[this.config.tableName]: writeInputs
}
});
}))
}

public updatePoint(updatePointInput: UpdatePointInput): Request<UpdatePointOutput, AWSError> {
public updatePoint(updatePointInput: UpdatePointInput) {
const geohash = S2Manager.generateGeohash(updatePointInput.GeoPoint);
const hashKey = S2Manager.generateHashKey(geohash, this.config.hashKeyLength);

Expand All @@ -182,20 +181,20 @@ export class DynamoDBManager {
delete updatePointInput.UpdateItemInput.AttributeUpdates[this.config.geoJsonAttributeName];
}

return this.config.dynamoDBClient.updateItem(updatePointInput.UpdateItemInput);
return this.config.dynamoDBClient.send(new DynamoDB.UpdateItemCommand(updatePointInput.UpdateItemInput))
}

public deletePoint(deletePointInput: DeletePointInput): Request<DeletePointOutput, AWSError> {
public deletePoint(deletePointInput: DeletePointInput){
const geohash = S2Manager.generateGeohash(deletePointInput.GeoPoint);
const hashKey = S2Manager.generateHashKey(geohash, this.config.hashKeyLength);

return this.config.dynamoDBClient.deleteItem({
return this.config.dynamoDBClient.send(new DynamoDB.DeleteItemCommand({
...deletePointInput.DeleteItemInput,
TableName: this.config.tableName,
Key: {
[this.config.hashKeyAttributeName]: { N: hashKey.toString(10) },
[this.config.rangeKeyAttributeName]: deletePointInput.RangeKeyValue
}
});
}))
}
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamoDB } from "aws-sdk";
import * as DynamoDB from "@aws-sdk/client-dynamodb";

export interface BatchWritePointOutput extends DynamoDB.BatchWriteItemOutput {
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/GeoTableUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/


import { DynamoDB } from "aws-sdk";
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { GeoDataManagerConfiguration } from "../GeoDataManagerConfiguration";
/**
* Utility class.
Expand Down
20 changes: 7 additions & 13 deletions test/integration/example.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import * as ddbGeo from "../../src";
import * as AWS from "aws-sdk";
import { expect } from "chai";

AWS.config.update({
accessKeyId: 'dummy',
secretAccessKey: 'dummy',
region: 'eu-west-1'
});
import {DynamoDB} from '@aws-sdk/client-dynamodb'

describe('Example', function () {
// Use a local DB for the example.
const ddb = new AWS.DynamoDB({ endpoint: 'http://127.0.0.1:8000' });
const ddb = new DynamoDB({ endpoint: 'http://127.0.0.1:8000' });

// Configuration for a new instance of a GeoDataManager. Each GeoDataManager instance represents a table
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'test-capitals');
Expand All @@ -25,10 +19,10 @@ describe('Example', function () {

// Use GeoTableUtil to help construct a CreateTableInput.
const createTableInput = ddbGeo.GeoTableUtil.getCreateTableRequest(config);
createTableInput.ProvisionedThroughput.ReadCapacityUnits = 2;
await ddb.createTable(createTableInput).promise();
//createTableInput.ProvisionedThroughput.ReadCapacityUnits = 2;
await ddb.createTable(createTableInput)
// Wait for it to become ready
await ddb.waitFor('tableExists', { TableName: config.tableName }).promise()
//await ddb.waitFor('tableExists', { TableName: config.tableName }) // needed?
// Load sample data in batches

console.log('Loading sample data from capitals.json');
Expand Down Expand Up @@ -63,7 +57,7 @@ describe('Example', function () {
thisBatch.push(itemToAdd);
}
console.log('Writing batch ' + (currentBatch++) + '/' + Math.ceil(data.length / BATCH_SIZE));
await capitalsManager.batchWritePoints(thisBatch).promise();
await capitalsManager.batchWritePoints(thisBatch);
// Sleep
await new Promise((resolve) => setInterval(resolve, WAIT_BETWEEN_BATCHES_MS));
return resumeWriting();
Expand Down Expand Up @@ -94,6 +88,6 @@ describe('Example', function () {

after(async function () {
this.timeout(10000);
await ddb.deleteTable({ TableName: config.tableName }).promise()
await ddb.deleteTable({ TableName: config.tableName })
});
});
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"target": "ES6",
"noImplicitAny": false,
"sourceMap": false,
"outDir": "dist",
"lib": [
"es2015"
"lib":[
"esnext"
]
},
"include": [ "src/**/*" ]
Expand Down
Loading