Skip to content

Commit

Permalink
Release 3.3.0-beta.5. Type FluentDynameh class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff committed Mar 29, 2019
1 parent 5c8956a commit c498446
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dynameh",
"version": "3.3.0-beta.4",
"version": "3.3.0-beta.5",
"description": "DynamoDB on Node more easier",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 9 additions & 7 deletions src/FluentDynameh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class FluentRequestBuilder<TRequest, TResponse, TResult> {
return this.resultGetter(await this.execute());
}

addProjection(attributes: string[]): FluentRequestBuilder<TRequest, TResponse, TResult> {
addProjection(attributes: string[]): FluentRequestBuilder<TRequest, TResponse, Partial<TResult>> {
const req = requestBuilder.addProjection(this.tableSchema, this.request, attributes);
return new FluentRequestBuilder(this.tableSchema, req, this.executor, this.resultGetter);
}
Expand All @@ -48,18 +48,18 @@ function emptyResultGetter(): {} {
return {};
}

export class FluentDynameh {
export class FluentDynameh<T extends object> {

constructor(public tableSchema: TableSchema, public client: aws.DynamoDB) {
checkSchema(tableSchema);
}

getItem<T>(partitionKeyValue: DynamoKey, sortKeyValue?: DynamoKey): FluentRequestBuilder<aws.DynamoDB.GetItemInput, aws.DynamoDB.GetItemOutput, T> {
getItem(partitionKeyValue: DynamoKey, sortKeyValue?: DynamoKey): FluentRequestBuilder<aws.DynamoDB.GetItemInput, aws.DynamoDB.GetItemOutput, T> {
const req = requestBuilder.buildGetInput(this.tableSchema, partitionKeyValue, sortKeyValue);
return new FluentRequestBuilder(this.tableSchema, req, this.client.getItem, responseUnwrapper.unwrapGetOutput);
}

putItem(item: object): FluentRequestBuilder<aws.DynamoDB.PutItemInput, aws.DynamoDB.PutItemOutput, {}> {
putItem(item: T): FluentRequestBuilder<aws.DynamoDB.PutItemInput, aws.DynamoDB.PutItemOutput, {}> {
const req = requestBuilder.buildPutInput(this.tableSchema, item);
return new FluentRequestBuilder(this.tableSchema, req, this.client.putItem, emptyResultGetter);
}
Expand All @@ -69,19 +69,21 @@ export class FluentDynameh {
return new FluentRequestBuilder(this.tableSchema, req, this.client.updateItem, emptyResultGetter);
}

deleteItem(itemToDelete: object): FluentRequestBuilder<aws.DynamoDB.DeleteItemInput, aws.DynamoDB.DeleteItemOutput, {}> {
deleteItem(itemToDelete: Partial<T>): FluentRequestBuilder<aws.DynamoDB.DeleteItemInput, aws.DynamoDB.DeleteItemOutput, {}> {
const req = requestBuilder.buildDeleteInput(this.tableSchema, itemToDelete);
return new FluentRequestBuilder(this.tableSchema, req, this.client.deleteItem, emptyResultGetter);
}

query<T>(partitionKeyValue: DynamoKey, sortKeyOp?: DynamoQueryConditionOperator, ...sortKeyValues: DynamoKey[]): FluentRequestBuilder<aws.DynamoDB.QueryInput, aws.DynamoDB.QueryOutput, T[]> {
query(partitionKeyValue: DynamoKey, sortKeyOp?: DynamoQueryConditionOperator, ...sortKeyValues: DynamoKey[]): FluentRequestBuilder<aws.DynamoDB.QueryInput, aws.DynamoDB.QueryOutput, T[]> {
const req = requestBuilder.buildQueryInput(this.tableSchema, partitionKeyValue, sortKeyOp, ...sortKeyValues);
return new FluentRequestBuilder(this.tableSchema, req, this.client.query, responseUnwrapper.unwrapQueryOutput);
// TODO executor should get ALL query results with paging
}

scan<T>(...filter: Condition[]): FluentRequestBuilder<aws.DynamoDB.ScanInput, aws.DynamoDB.ScanOutput, T[]> {
scan(...filter: Condition[]): FluentRequestBuilder<aws.DynamoDB.ScanInput, aws.DynamoDB.ScanOutput, T[]> {
const req = requestBuilder.buildScanInput(this.tableSchema, ...filter);
return new FluentRequestBuilder(this.tableSchema, req, this.client.scan, responseUnwrapper.unwrapScanOutput);
// TODO executor should get ALL scan results with paging
}

transactWriteItems(...input: FluentRequestBuilder<aws.DynamoDB.PutItemInput | aws.DynamoDB.DeleteItemInput | aws.DynamoDB.UpdateItemInput, any, {}>[]): FluentRequestBuilder<aws.DynamoDB.TransactWriteItemsInput, aws.DynamoDB.TransactWriteItemsOutput, {}> {
Expand Down

0 comments on commit c498446

Please sign in to comment.