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 use `@Property({ name })`, `@PartitionKey()` and `@GSISortKey(index)` together #280

Closed nolde closed 4 years ago

nolde commented 4 years ago

Describe the bug It is impossible to use @PartitionKey({ name: 'someOtherName' }), @PartitionKey and @GSISortKey decorators alongside each other, as dynamo-easy complains about the lack of primary key identifier.

To Reproduce Steps to reproduce the behavior:

// ...
class CoolModel {
  // ...
  @PartitionKey()
  @GSISortKey('gsiName')
  @Property({ name: 'entity' })
  readonly id: string = genid()
  // ...
}

const store = new DynamoStore(CoolModel)
const cool = new CoolModel({ /* ... */ })
store.put(cool).exec()

A code similar to the one above generates the following error:

ValidationException: One or more parameter values were invalid: Missing the key entity in the item
    at Request.extractError (<local-path>\node_modules\aws-sdk\lib\protocol\json.js:51:27)
    at Request.callListeners (<local-path>\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
    at Request.emit (<local-path>\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
    at Request.emit (<local-path>\node_modules\aws-sdk\lib\request.js:683:14)
    at Request.transition (<local-path>\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (<local-path>\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at <local-path>\node_modules\aws-sdk\lib\state_machine.js:26:10
    at Request.<anonymous> (<local-path>\node_modules\aws-sdk\lib\request.js:38:9)
    at Request.<anonymous> (<local-path>\node_modules\aws-sdk\lib\request.js:685:12)
    at Request.callListeners (<local-path>\node_modules\aws-sdk\lib\sequential_executor.js:116:18) {
  message: 'One or more parameter values were invalid: Missing the key entity in the item',
  code: 'ValidationException',
  time: 2020-02-27T12:31:16.675Z,
  requestId: '--x--',
  statusCode: 400,
  retryable: false,
  retryDelay: 6.40678295655337
}

Expected behavior The library should track the updated name and act accordingly, regardless of being a key.

Desktop (please complete the following information):

Additional context I've noticed the existence of issue #215 , which seems to be identical to this one. It says it has been released, but I am getting a similar issue... has this been reintroduced?

If I just change id to entity, code immediately works.

nolde commented 4 years ago

I made a mistake in some other part of my code. Sorry.