dynamodb-toolbox/dynamodb-toolbox

Feature request: readonly property for attributes

Opened this issue · 0 comments

napter commented

A read only property on an attribute would allow query requests to the entity but update requests with the property set should throw an error. Alternatively, adding an onUpdate event where the entity could review the contents of the update and throw an error if the update shouldn't be allowed to proceed, would allow this (and other checks).

@jeremydaly I just want to thank you for this library and lambda-api. I have started a small middleware that connects the two with a config file. It reads dynamodb entities and registers api paths for them so that in a single config file you can add new simple CRUD apis for dynamodb entities. What do you think of adding something like that to either of the libraries?

It just seems like there are a sequence of steps that need to be reimplemented every time you need a new lambda for dynamodb: create the api path, validate the input properties, call the appropriate dynamodb operation. It requires a lot of boilerplate code. If there was an intermediary that could glue api-gateway/lambda and dynamodb together with simple configurations I think the code would be faster to write and cleaner. I tried searching but couldn't find anything existing that does this.

In this setup, it makes sense to me to use the entity objects to validate that the shape of the data is valid before pushing it. The read only flag or an onUpdate would help with that.