Skip to content

Commit

Permalink
fix(types): inline the KeyType from '@aws-sdk/client-dynamodb'
Browse files Browse the repository at this point in the history
since the external one caused runtime issues, needs investigation
  • Loading branch information
Michael Wittwer committed Mar 20, 2023
1 parent 2ec7c3f commit b85e0b5
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/aws-sdk-v2.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export type ExpressionAttributeValueMap = { [key: string]: AttributeValue /* was
export type AttributeMap = { [key: string]: AttributeValue }

export type Key = { [key: string]: AttributeValue }

// FIXME somehow the import of KeyType from @aws-sdk/client-dynamodb does not work at runtime
export enum KeyType {
HASH = 'HASH',
RANGE = 'RANGE',
}
2 changes: 1 addition & 1 deletion src/decorator/impl/index/gsi-partition-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand Down
2 changes: 1 addition & 1 deletion src/decorator/impl/index/gsi-sort-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand Down
2 changes: 1 addition & 1 deletion src/decorator/impl/index/lsi-sort-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand Down
9 changes: 3 additions & 6 deletions src/decorator/impl/index/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
import { KEY_PROPERTY } from '../property/key-property.const'
Expand All @@ -12,7 +12,7 @@ import { IndexType } from './index-type.enum'
*/
export interface IndexData {
name: string
keyType: DynamoDB.KeyType
keyType: KeyType
}

/**
Expand Down Expand Up @@ -47,10 +47,7 @@ export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, ta
/**
* @hidden
*/
function initOrUpdateGSI(
indexes: Record<string, DynamoDB.KeyType>,
indexData: IndexData,
): Partial<PropertyMetadata<any>> {
function initOrUpdateGSI(indexes: Record<string, KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
if (indexes[indexData.name]) {
// 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
// throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/impl/key/partition-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { createOptModelLogger } from '../../../logger/logger'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/impl/key/sort-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'

export function SortKey(): PropertyDecorator {
Expand Down
4 changes: 2 additions & 2 deletions src/decorator/impl/model/model.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../../aws-sdk-v2.types'
import { kebabCase } from '../../../helper/kebab-case.function'
import { ModelMetadata } from '../../metadata/model-metadata.model'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
Expand Down Expand Up @@ -63,7 +63,7 @@ export function Model(opts: ModelData = {}): ClassDecorator {
*/
function testForGSI<T>(
property: PropertyMetadata<T>,
): property is PropertyMetadata<T> & { keyForGSI: Record<string, DynamoDB.KeyType> } {
): property is PropertyMetadata<T> & { keyForGSI: Record<string, KeyType> } {
return !!(property.keyForGSI && Object.keys(property.keyForGSI).length)
}

Expand Down
6 changes: 3 additions & 3 deletions src/decorator/metadata/property-metadata.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module metadata
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { KeyType } from '../../aws-sdk-v2.types'
import { MapperForType } from '../../mapper/for-type/base.mapper'
import { Attribute } from '../../mapper/type/attribute.type'
import { ModelConstructor } from '../../model/model-constructor'
Expand All @@ -12,7 +12,7 @@ export interface TypeInfo {
}

export interface Key {
type: DynamoDB.KeyType
type: KeyType
}

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

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

// holds all the the index names for which this property describes the sort key attribute
sortKeyForLSI?: string[]
Expand Down
2 changes: 1 addition & 1 deletion tools/tslint/test/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import * as moment from 'moment'
import * as DynamoDB from 'aws-sdk'
import { Config } from 'aws-sdk'
import { Key } from 'aws-sdk/clients/dynamodb'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [only wildcard import (import * as DynamoDB from 'aws-sdk/clients/dynamodb') is allowed for this module]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [only wildcard import (import * as DynamoDB from '@aws-sdk/client-dynamodb') is allowed for this module]

0 comments on commit b85e0b5

Please sign in to comment.