shiftcode / dynamo-easy

DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.
https://shiftcode.github.io/dynamo-easy/
MIT License
204 stars 27 forks source link

Cannot save empty nested array or object. #318

Open kdby-io opened 4 years ago

kdby-io commented 4 years ago

Describe the bug

When a nested array or object is empty, it is ignored on saving.

To Reproduce

@Model()
export class A{
  @PartitionKey()
  id: string

  @CollectionProperty({ sorted: true, itemType: B })
  bs: B[]
}

@Model()
export class B {
  props: { [key: string]: any };
}

const a1: A = {
  id: uuid(),
  bs: []
}
const a2: A = {
  id: uuid(),
  bs: [{
    props: {
      hello: {},
      world: 'a2'
    }
  }]
}
const a3: A = {
  id: uuid(),
  bs: [{
    props: {
      hello: {
        arr: []
      },
      world: 'a3'
    }
  }]
}

await this.store.put(a1).exec();  // { id: ..., bs: [] }
await this.store.put(a2).exec();  // { id: ..., bs: [{ props: { world: 'a2' } }] }
await this.store.put(a3).exec();  // { id: ..., bs: [{ props: { world: 'a3' } }] }

Expected behavior

a nested empty array or object can be saved.