structure icon indicating copy to clipboard operation
structure copied to clipboard

Support Map types with itemType

Open loweoj opened this issue 6 years ago • 3 comments

It would be really useful to support Map types with itemType. Currently specifying an attribute as type Map results in "attribute.map is not a function" on attribute serialization. Is this something that could be added? If it's just a case of implementing a .map function for Map then that would be relatively trivial?

My use case is storing itemType's ID value as a key on Map.

Thanks!

loweoj avatar Oct 03 '18 14:10 loweoj

This would be an excellent feature. We are currently working with DynamoDB and we often bump into cases where we want objects with dynamic property naming. This is an excelent use case for saving dictionaries and/or hashtables.

Both JavaScript and DynamoDB supports this use scenario and it would be a great addition to structure.

LeoGigliotti avatar Nov 28 '18 15:11 LeoGigliotti

As discusses, we're gonna define the key and item type like this:

{
  permissions: {
    type: Map,
    itemType: { key: String, value: Permission }
  }
}

talyssonoc avatar Mar 01 '19 19:03 talyssonoc

Where the value of key is a property on Permission? e.g.

  permissions: {
    type: Map,
    itemType: { key: 'permissionId', value: Permission }
  }

Or does this mean that keys will be coerced to a string?

loweoj avatar Mar 01 '19 23:03 loweoj