sam-goodwin / typesafe-dynamodb

TypeSafe type definitions for the AWS DynamoDB API
Apache License 2.0
205 stars 11 forks source link

fix: add specific commands for V3's DocumentClient #36

Closed sam-goodwin closed 2 years ago

sam-goodwin commented 2 years ago

Fixes #33

There was a bug in the V3 Commands for the Document Client. Instead of using the Command from @aws-sdk/lib-dynamodb, we were re-using the @aws-sdk/client-dynamodb Commands which expect the data to be in the Attribute Value format. This resulted in serialization errors.

See: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/dynamodb-example-dynamodb-utilities.html for official documentation on how to use the DocumentClient with V3's AWS SDK.

This change adds new Commands specific to v3's document client. The new commands follow the naming convention: TypeSafe*DocumentCommand:

Example:

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import { TypeSafeGetDocumentCommand } from "../src/get-document-command";

const client = new DynamoDBClient({});

const docClient = DynamoDBDocumentClient.from(
  client
);

const MyCommand = new TypeSafeGetDocumentCommand<Type, PK, SK>();

docClient.send(new MyCommand({
  ..
});

BREAKING CHANGE: JsonFormat removed from V3 command's type parameters