Skip to content

Commit b85e0b5

Browse files
author
Michael Wittwer
committed
fix(types): inline the KeyType from '@aws-sdk/client-dynamodb'
since the external one caused runtime issues, needs investigation
1 parent 2ec7c3f commit b85e0b5

10 files changed

+20
-17
lines changed

src/aws-sdk-v2.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ export type ExpressionAttributeValueMap = { [key: string]: AttributeValue /* was
1313
export type AttributeMap = { [key: string]: AttributeValue }
1414

1515
export type Key = { [key: string]: AttributeValue }
16+
17+
// FIXME somehow the import of KeyType from @aws-sdk/client-dynamodb does not work at runtime
18+
export enum KeyType {
19+
HASH = 'HASH',
20+
RANGE = 'RANGE',
21+
}

src/decorator/impl/index/gsi-partition-key.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

src/decorator/impl/index/gsi-sort-key.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

src/decorator/impl/index/lsi-sort-key.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

src/decorator/impl/index/util.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import * as DynamoDB from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { PropertyMetadata } from '../../metadata/property-metadata.model'
66
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
77
import { KEY_PROPERTY } from '../property/key-property.const'
@@ -12,7 +12,7 @@ import { IndexType } from './index-type.enum'
1212
*/
1313
export interface IndexData {
1414
name: string
15-
keyType: DynamoDB.KeyType
15+
keyType: KeyType
1616
}
1717

1818
/**
@@ -47,10 +47,7 @@ export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, ta
4747
/**
4848
* @hidden
4949
*/
50-
function initOrUpdateGSI(
51-
indexes: Record<string, DynamoDB.KeyType>,
52-
indexData: IndexData,
53-
): Partial<PropertyMetadata<any>> {
50+
function initOrUpdateGSI(indexes: Record<string, KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
5451
if (indexes[indexData.name]) {
5552
// TODO INVESTIGATE when we throw an error we have a problem where multiple different classes extend one base class, this will be executed multiple times
5653
// throw new Error(

src/decorator/impl/key/partition-key.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { createOptModelLogger } from '../../../logger/logger'
66
import { PropertyMetadata } from '../../metadata/property-metadata.model'
77
import { initOrUpdateProperty } from '../property/init-or-update-property.function'

src/decorator/impl/key/sort-key.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
66

77
export function SortKey(): PropertyDecorator {

src/decorator/impl/model/model.decorator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import * as DynamoDB from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../../aws-sdk-v2.types'
55
import { kebabCase } from '../../../helper/kebab-case.function'
66
import { ModelMetadata } from '../../metadata/model-metadata.model'
77
import { PropertyMetadata } from '../../metadata/property-metadata.model'
@@ -63,7 +63,7 @@ export function Model(opts: ModelData = {}): ClassDecorator {
6363
*/
6464
function testForGSI<T>(
6565
property: PropertyMetadata<T>,
66-
): property is PropertyMetadata<T> & { keyForGSI: Record<string, DynamoDB.KeyType> } {
66+
): property is PropertyMetadata<T> & { keyForGSI: Record<string, KeyType> } {
6767
return !!(property.keyForGSI && Object.keys(property.keyForGSI).length)
6868
}
6969

src/decorator/metadata/property-metadata.model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module metadata
33
*/
4-
import * as DynamoDB from '@aws-sdk/client-dynamodb'
4+
import { KeyType } from '../../aws-sdk-v2.types'
55
import { MapperForType } from '../../mapper/for-type/base.mapper'
66
import { Attribute } from '../../mapper/type/attribute.type'
77
import { ModelConstructor } from '../../model/model-constructor'
@@ -12,7 +12,7 @@ export interface TypeInfo {
1212
}
1313

1414
export interface Key {
15-
type: DynamoDB.KeyType
15+
type: KeyType
1616
}
1717

1818
export interface PropertyMetadata<T, R extends Attribute = Attribute> {
@@ -41,7 +41,7 @@ export interface PropertyMetadata<T, R extends Attribute = Attribute> {
4141
mapperForSingleItem?: () => MapperForType<any, any>
4242

4343
// maps the index name to the key type to describe for which GSI this property describes a key attribute
44-
keyForGSI?: Record<string, DynamoDB.KeyType>
44+
keyForGSI?: Record<string, KeyType>
4545

4646
// holds all the the index names for which this property describes the sort key attribute
4747
sortKeyForLSI?: string[]

tools/tslint/test/test.ts.lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import * as moment from 'moment'
22
import * as DynamoDB from 'aws-sdk'
33
import { Config } from 'aws-sdk'
44
import { Key } from 'aws-sdk/clients/dynamodb'
5-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [only wildcard import (import * as DynamoDB from 'aws-sdk/clients/dynamodb') is allowed for this module]
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [only wildcard import (import * as DynamoDB from '@aws-sdk/client-dynamodb') is allowed for this module]

0 commit comments

Comments
 (0)