-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#250 model metadata
- Loading branch information
Showing
35 changed files
with
859 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @module decorators | ||
*/ | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export const modelErrors = { | ||
gsiMultiplePk: (indexName: string, propDbName: string) => | ||
`there is already a partition key defined for global secondary index ${indexName} (property name: ${propDbName})`, | ||
gsiMultipleSk: (indexName: string, propDbName: string) => | ||
`there is already a sort key defined for global secondary index ${indexName} (property name: ${propDbName})`, | ||
lsiMultipleSk: (indexName: string, propDbName: string) => | ||
`only one sort key can be defined for the same local secondary index, ${propDbName} is already defined as sort key for index ${indexName}`, | ||
lsiRequiresPk: (indexName: string, propDbName: string) => | ||
`the local secondary index ${indexName} requires the partition key to be defined`, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// tslint:disable:max-classes-per-file | ||
import { GSIPartitionKey } from '../index/gsi-partition-key.decorator' | ||
import { GSISortKey } from '../index/gsi-sort-key.decorator' | ||
import { LSISortKey } from '../index/lsi-sort-key.decorator' | ||
import { PartitionKey } from '../key/partition-key.decorator' | ||
import { modelErrors } from './errors.const' | ||
import { Model } from './model.decorator' | ||
|
||
const IX_NAME = 'anIndexName' | ||
|
||
describe('@model decorator', () => { | ||
describe('getGlobalSecondaryIndexes', () => { | ||
// throws on applying decorator | ||
|
||
it('throws when defining multiple partitionKeys for same gsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@GSIPartitionKey(IX_NAME) | ||
pk1: string | ||
@GSIPartitionKey(IX_NAME) | ||
pk2: string | ||
@GSISortKey(IX_NAME) | ||
sk1: string | ||
} | ||
}).toThrow(modelErrors.gsiMultiplePk(IX_NAME, 'pk2')) | ||
}) | ||
it('throws when defining multiple sortKeys for same gsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@GSIPartitionKey(IX_NAME) | ||
pk1: string | ||
@GSISortKey(IX_NAME) | ||
sk1: string | ||
@GSISortKey(IX_NAME) | ||
sk2: string | ||
} | ||
}).toThrow(modelErrors.gsiMultipleSk(IX_NAME, 'sk2')) | ||
}) | ||
}) | ||
describe('getLocalSecondaryIndexes', () => { | ||
it('throws when defining LSI sortKey but no PartitionKey', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@LSISortKey(IX_NAME) | ||
sk1: string | ||
} | ||
}).toThrow(modelErrors.lsiRequiresPk(IX_NAME, 'sk1')) | ||
}) | ||
it('throws when defining multiple sortKeys for same lsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@PartitionKey() | ||
pk1: string | ||
@LSISortKey(IX_NAME) | ||
sk1: string | ||
@LSISortKey(IX_NAME) | ||
sk2: string | ||
} | ||
}).toThrow(modelErrors.lsiMultipleSk(IX_NAME, 'sk2')) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.