-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for AWS SDK v3's DynamoDB and DynamoDBClient (#13)
BREAKING CHANGE: `index.ts` exports are removed and `TypeSafeDynamoDB` is now renamed to `TypeSafeDyanmoDBv2`
- Loading branch information
sam
authored
Feb 10, 2022
1 parent
e70beba
commit ed48689
Showing
15 changed files
with
1,194 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,130 @@ | ||
import type { | ||
DynamoDB, | ||
ReturnValue as DynamoDBReturnValue, | ||
} from "@aws-sdk/client-dynamodb"; | ||
import { MetadataBearer } from "@aws-sdk/types"; | ||
import { Callback } from "./callback"; | ||
import { DeleteItemInput, DeleteItemOutput } from "./delete-item"; | ||
import { GetItemInput, GetItemOutput } from "./get-item"; | ||
import { KeyAttribute } from "./key"; | ||
import { PutItemInput, PutItemOutput } from "./put-item"; | ||
import { QueryInput, QueryOutput } from "./query"; | ||
|
||
export interface TypeSafeDynamoDBv3< | ||
Item extends object, | ||
PartitionKey extends keyof Item, | ||
RangeKey extends keyof Item | undefined = undefined | ||
> extends Omit<DynamoDB, "getItem" | "deleteItem" | "putItem" | "query"> { | ||
getItem< | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
AttributesToGet extends keyof Item | undefined = undefined, | ||
ProjectionExpression extends string | undefined = undefined | ||
>( | ||
params: GetItemInput< | ||
Item, | ||
Key, | ||
PartitionKey, | ||
RangeKey, | ||
AttributesToGet, | ||
ProjectionExpression | ||
> | ||
): Promise< | ||
GetItemOutput<Item, Key, AttributesToGet, ProjectionExpression> & | ||
MetadataBearer | ||
>; | ||
|
||
getItem< | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
AttributesToGet extends keyof Item | undefined = undefined, | ||
ProjectionExpression extends string | undefined = undefined | ||
>( | ||
params: GetItemInput< | ||
Item, | ||
Key, | ||
PartitionKey, | ||
RangeKey, | ||
AttributesToGet, | ||
ProjectionExpression | ||
>, | ||
callback: Callback< | ||
GetItemOutput<Item, Key, AttributesToGet, ProjectionExpression>, | ||
any | ||
> | ||
): void; | ||
|
||
deleteItem< | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
ConditionExpression extends string | undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
>( | ||
params: DeleteItemInput< | ||
Item, | ||
PartitionKey, | ||
RangeKey, | ||
Key, | ||
ConditionExpression, | ||
ReturnValue | ||
> | ||
): Promise<DeleteItemOutput<Item, ReturnValue> & MetadataBearer>; | ||
|
||
deleteItem< | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
ConditionExpression extends string | undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
>( | ||
params: DeleteItemInput< | ||
Item, | ||
PartitionKey, | ||
RangeKey, | ||
Key, | ||
ConditionExpression, | ||
ReturnValue | ||
>, | ||
callback: Callback< | ||
DeleteItemOutput<Item, ReturnValue> & MetadataBearer, | ||
any | ||
> | ||
): void; | ||
|
||
putItem< | ||
ConditionExpression extends string | undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
>( | ||
params: PutItemInput<Item, ConditionExpression, ReturnValue> | ||
): Promise<PutItemOutput<Item, ReturnValue> & MetadataBearer>; | ||
|
||
putItem< | ||
ConditionExpression extends string | undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
>( | ||
params: PutItemInput<Item, ConditionExpression, ReturnValue>, | ||
callback: Callback<PutItemOutput<Item, ReturnValue> & MetadataBearer, any> | ||
): void; | ||
|
||
query< | ||
KeyConditionExpression extends string | undefined = undefined, | ||
FilterExpression extends string | undefined = undefined, | ||
AttributesToGet extends keyof Item | undefined = undefined | ||
>( | ||
params: QueryInput< | ||
Item, | ||
KeyConditionExpression, | ||
FilterExpression, | ||
AttributesToGet | ||
> | ||
): Promise<QueryOutput<Item, AttributesToGet> & MetadataBearer>; | ||
|
||
query< | ||
KeyConditionExpression extends string | undefined = undefined, | ||
FilterExpression extends string | undefined = undefined, | ||
AttributesToGet extends keyof Item | undefined = undefined | ||
>( | ||
params: QueryInput< | ||
Item, | ||
KeyConditionExpression, | ||
FilterExpression, | ||
AttributesToGet | ||
>, | ||
callback: Callback<QueryOutput<Item, AttributesToGet> & MetadataBearer, any> | ||
): void; | ||
} |
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,59 @@ | ||
import { | ||
DynamoDBClientResolvedConfig, | ||
DeleteItemCommand as _DeleteItemCommand, | ||
ReturnValue as DynamoDBReturnValue, | ||
} from "@aws-sdk/client-dynamodb"; | ||
import type { Command } from "@aws-sdk/smithy-client"; | ||
import { DeleteItemInput, DeleteItemOutput } from "./delete-item"; | ||
import { MetadataBearer } from "@aws-sdk/types"; | ||
import { KeyAttribute } from "./key"; | ||
|
||
export interface DeleteItemCommand< | ||
Item extends object, | ||
PartitionKey extends keyof Item, | ||
RangeKey extends keyof Item | undefined, | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
ConditionExpression extends string | undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
> extends Command< | ||
DeleteItemInput< | ||
Item, | ||
PartitionKey, | ||
RangeKey, | ||
Key, | ||
ConditionExpression, | ||
ReturnValue | ||
>, | ||
DeleteItemOutput<Item, ReturnValue> & MetadataBearer, | ||
DynamoDBClientResolvedConfig | ||
> { | ||
_brand: "DeleteItemCommand"; | ||
} | ||
|
||
export function TypeSafeDeleteItemCommand< | ||
Item extends object, | ||
PartitionKey extends keyof Item, | ||
RangeKey extends keyof Item | undefined | ||
>(): new < | ||
Key extends KeyAttribute<Item, PartitionKey, RangeKey>, | ||
ConditionExpression extends string | undefined = undefined, | ||
ReturnValue extends DynamoDBReturnValue = "NONE" | ||
>( | ||
input: DeleteItemInput< | ||
Item, | ||
PartitionKey, | ||
RangeKey, | ||
Key, | ||
ConditionExpression, | ||
ReturnValue | ||
> | ||
) => DeleteItemCommand< | ||
Item, | ||
PartitionKey, | ||
RangeKey, | ||
Key, | ||
ConditionExpression, | ||
ReturnValue | ||
> { | ||
return _DeleteItemCommand as any; | ||
} |
Oops, something went wrong.