tywalch/electrodb

`.params()` doesn't work with TransactWriteItems and v3 SDK

furrycatherder opened this issue ยท 4 comments

Describe the bug
Trying to use a list of .params() with TransactWriteItemsCommand results in the cryptic error

TypeError: Cannot read properties of undefined (reading '0')

After some investigation, this seems to be the cause:
aws/aws-sdk-js-v3#3365 (comment)

.params() returns something like this:

{
    "Delete": {
        "Key": {
            "pk": "$sites#siteid_01gk976gqx9cqq63htxj0pbyer",
            "sk": "$devices#device_1#deviceid_01gqnz2pjv3cx8kx242dkjsw13"
        },
        "TableName": "dev-table-ng",
        "ConditionExpression": "attribute_exists(#pk) AND attribute_exists(#sk)",
        "ExpressionAttributeNames": {
            "#pk": "pk",
            "#sk": "sk"
        }
    }
}

But if I understand correctly it should be something like this:

{
    "Delete": {
        "Key": {
            "pk": {"S": "$sites#siteid_01gk976gqx9cqq63htxj0pbyer"},
            "sk": {"S": "$devices#device_1#deviceid_01gqnz2pjv3cx8kx242dkjsw13"}
        },
        "TableName": "dev-table-ng",
        "ConditionExpression": "attribute_exists(#pk) AND attribute_exists(#sk)",
        "ExpressionAttributeNames": {
            "#pk": "pk",
            "#sk": "sk"
        }
    }
}

ElectroDB Version
1.11.1

Hi @furrycatherder, ElectroDB returns unmarshalled params (used by the DocumentClient); If you're not able to use the DocumentClient, you could use the marshall function from the @aws-sdk/util-dynamodb module to get the format in your second example.

The goal with the library thus far has been to avoid loading it up with too many bloated aws dependencies, which for some users is a big deal when they're up against deployment restrictions. This could be an opportunity however new Entity/Service options for marshall/unmarshal functions be passed. If that interests you, let me know, I could probably add that pretty easily ๐Ÿ‘

Sure, that sounds good. We're committed to using the v3 SDK at this point.

Hey @furrycatherder ๐Ÿ‘‹

Version 2.5.0 was just shipped with transaction support, you can check it out here (works with the v3 client): https://electrodb.dev/en/mutations/transact-write/

If you have any issues, please let me know, I'll close this ticket for now but feel free to reopen it if I missed anything