Skip to content

Can't conditionally update custom mapped list of strings with empty value #335

@LucasDachman

Description

@LucasDachman

Describe the bug

If I have a property with a custom mapper like

@Model()
class MyModel {
  @Property({ mapper: stringArrayOrEmptyMapper })
  myList: string[]
}

export const stringArrayOrEmptyMapper: MapperForType<
  string[],
  ListAttribute<StringAttribute>
> = {
  fromDb: attributeValue =>
    attributeValue?.L?.map((item: { S: string }) => item.S) ?? [],
  toDb: propertyValue =>
    propertyValue?.length
      ? { L: propertyValue.map(item => ({ S: item })) }
      : { L: [] },
};

and I try to do a conditional transact update like:

new TransactUpdate(MyModel, PK, SK)
  .onlyIfAttribute('myList')
  .eq([])
  .updateAttribute('myList)
  .set(['liststuff'])

I get Error: expected 1 value(s) for operator =, this is not the right amount of method parameters for this operator

This works fine if the list is populated but fails when the list is empty

Expected behavior
I expect the operation to succeed if the list is empty and fail if the list is not empty. I do not expect an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions