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

Multiple GSI Sort keys on the same property Results in error #297

Closed hookercookerman closed 4 years ago

hookercookerman commented 4 years ago

To Reproduce

Model Below

export class User {
  @PartitionKey()
  pk: string;

  @SortKey()
  @GSISortKey(User.EMAIL_GSI)
  @GSISortKey(User.PHONE_NUMBER_GSI)
  sk: string;

  @GSIPartitionKey(User.EMAIL_GSI)
  email: string;

  @GSIPartitionKey(User.PHONE_NUMBER_GSI)
  phoneNumber: string;
}

export namespace User {
  export const TYPENAME = 'User';
  export const SORT_KEY = 'UR';
  export const ID_PREFIX = 'user';
  export const EMAIL_GSI = 'email-gsi';
  export const PHONE_NUMBER_GSI = 'phone-number-gsi';
}

Expected behavior

Having multiply @GSISortKey on the same property results in the following errors. One would expect this to work; especially since single table design is the new hotness :)

line of pain

https://github.com/shiftcode/dynamo-easy/blob/master/src/decorator/impl/model/model.decorator.ts#L93

NOTE

the undefined might be an indicator that this is me; as I think from my quick glance you handle this usecase

{
    "errorType": "Error",
    "errorMessage": "there is already a partition key defined for global secondary index undefined (property name: phoneNumber)",
    "stack": [
        "Error: there is already a partition key defined for global secondary index undefined (property name: phoneNumber)",
        "    at /var/task/node_modules/@shiftcoders/dynamo-easy/src/decorator/impl/model/model.decorator.ts:93:19",
        "    at Array.forEach (<anonymous>)",
        "    at /var/task/node_modules/@shiftcoders/dynamo-easy/src/decorator/impl/model/model.decorator.ts:83:37",
        "    at Array.reduce (<anonymous>)",
        "    at getGlobalSecondaryIndexes (/var/task/node_modules/@shiftcoders/dynamo-easy/src/decorator/impl/model/model.decorator.ts:81:40)",
        "    at /var/task/node_modules/@shiftcoders/dynamo-easy/src/decorator/impl/model/model.decorator.ts:38:41",
        "    at DecorateConstructor (/var/task/node_modules/reflect-metadata/Reflect.js:541:33)",
        "    at Object.decorate (/var/task/node_modules/reflect-metadata/Reflect.js:130:24)",
        "    at __decorate (/var/task/node_modules/@holiday-fox/user-models/dist/models/user.js:4:92)",
        "    at Object.<anonymous> (/var/task/node_modules/@holiday-fox/user-models/src/models/user.ts:12:18)"
    ]
}

Additional context Add any other context about the problem here.

hookercookerman commented 4 years ago

closing due to be being enlighten by the reflect metadata and constant definitions after their usage: )