Skip to content

Commit cc07fbc

Browse files
Merge pull request #422 from nduthoit/next
feat(aws-sdk-v3): remove v2 types
2 parents 9a64894 + 0c84a39 commit cc07fbc

20 files changed

+34
-64
lines changed

src/aws-sdk-v2.types.ts

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

@@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
1111
export function GSIPartitionKey(indexName: string): PropertyDecorator {
1212
return (target: any, propertyKey: string | symbol) => {
1313
if (typeof propertyKey === 'string') {
14-
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: KeyType.HASH }, target, propertyKey)
14+
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: DynamoDB.KeyType.HASH }, target, propertyKey)
1515
}
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

@@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
1111
export function GSISortKey(indexName: string): PropertyDecorator {
1212
return (target: any, propertyKey: string | symbol) => {
1313
if (typeof propertyKey === 'string') {
14-
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: KeyType.RANGE }, target, propertyKey)
14+
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: DynamoDB.KeyType.RANGE }, target, propertyKey)
1515
}
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { IndexType } from './index-type.enum'
66
import { initOrUpdateIndex } from './util'
77

@@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
1111
export function LSISortKey(indexName: string): PropertyDecorator {
1212
return (target: any, propertyKey: string | symbol) => {
1313
if (typeof propertyKey === 'string') {
14-
initOrUpdateIndex(IndexType.LSI, { name: indexName, keyType: KeyType.RANGE }, target, propertyKey)
14+
initOrUpdateIndex(IndexType.LSI, { name: indexName, keyType: DynamoDB.KeyType.RANGE }, target, propertyKey)
1515
}
1616
}
1717
}

src/decorator/impl/index/util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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: KeyType
15+
keyType: DynamoDB.KeyType
1616
}
1717

1818
/**
@@ -47,7 +47,7 @@ export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, ta
4747
/**
4848
* @hidden
4949
*/
50-
function initOrUpdateGSI(indexes: Record<string, KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
50+
function initOrUpdateGSI(indexes: Record<string, DynamoDB.KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
5151
if (indexes[indexData.name]) {
5252
// 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
5353
// throw new Error(

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { createOptModelLogger } from '../../../logger/logger'
66
import { PropertyMetadata } from '../../metadata/property-metadata.model'
77
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
@@ -32,7 +32,7 @@ export function PartitionKey(): PropertyDecorator {
3232
}
3333
}
3434

35-
initOrUpdateProperty({ key: { type: KeyType.HASH } }, target, propertyKey)
35+
initOrUpdateProperty({ key: { type: DynamoDB.KeyType.HASH } }, target, propertyKey)
3636
}
3737
}
3838
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
66

77
export function SortKey(): PropertyDecorator {
88
return (target: any, propertyKey: string | symbol) => {
99
if (typeof propertyKey === 'string') {
10-
initOrUpdateProperty({ key: { type: KeyType.RANGE } }, target, propertyKey)
10+
initOrUpdateProperty({ key: { type: DynamoDB.KeyType.RANGE } }, target, propertyKey)
1111
}
1212
}
1313
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module decorators
33
*/
4-
import { KeyType } from '../../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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, KeyType> } {
66+
): property is PropertyMetadata<T> & { keyForGSI: Record<string, DynamoDB.KeyType> } {
6767
return !!(property.keyForGSI && Object.keys(property.keyForGSI).length)
6868
}
6969

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module metadata
33
*/
4-
import { KeyType } from '../../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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: KeyType
15+
type: DynamoDB.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, KeyType>
44+
keyForGSI?: Record<string, DynamoDB.KeyType>
4545

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

src/dynamo/batchget/batch-get-full.response.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module multi-model-requests/batch-get
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
65
import { BatchGetResponse } from './batch-get.response'
76

87
/**
@@ -16,7 +15,7 @@ export interface BatchGetFullResponse {
1615
/**
1716
* A map of tables and their respective keys that were not processed with the current response. The UnprocessedKeys value is in the same form as RequestItems, so the value can be provided directly to a subsequent BatchGetItem operation. For more information, see RequestItems in the Request Parameters section. Each element consists of: Keys - An array of primary key attribute values that define specific items in the table. ProjectionExpression - One or more attributes to be retrieved from the table or index. By default, all attributes are returned. If a requested attribute is not found, it does not appear in the result. ConsistentRead - The consistency of a read operation. If set to true, then a strongly consistent read is used; otherwise, an eventually consistent read is used. If there are no unprocessed keys remaining, the response contains an empty UnprocessedKeys map.
1817
*/
19-
UnprocessedKeys?: DynamoDBv2.BatchGetRequestMap
18+
UnprocessedKeys?: Record<string, DynamoDB.KeysAndAttributes>
2019
/**
2120
* The read capacity units consumed by the entire BatchGetItem operation. Each element consists of: TableName - The table that consumed the provisioned throughput. CapacityUnits - The total number of capacity units consumed.
2221
*/

src/dynamo/batchget/batch-get-utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module multi-model-requests/batch-get
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
65
import { promiseDelay } from '../../helper/promise-delay.function'
76
import { DynamoDbWrapper } from '../dynamo-db-wrapper'
87

@@ -45,7 +44,7 @@ export function batchGetItemsFetchAll(
4544
* @hidden
4645
*/
4746
export type BatchGetItemOutputWithUnprocessedKeys = DynamoDB.BatchGetItemOutput & {
48-
UnprocessedKeys: DynamoDBv2.BatchGetRequestMap
47+
UnprocessedKeys: Record<string, DynamoDB.KeysAndAttributes>
4948
}
5049

5150
/**

src/dynamo/batchwrite/batch-write-utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module multi-model-requests/batch-write
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
65
import { promiseDelay } from '../../helper/promise-delay.function'
76
import { DynamoDbWrapper } from '../dynamo-db-wrapper'
87

@@ -45,7 +44,7 @@ export function batchWriteItemsWriteAll(
4544
* @hidden
4645
*/
4746
export type BatchWriteItemOutputWithUnprocessedItems = DynamoDB.BatchWriteItemOutput & {
48-
UnprocessedItems: DynamoDBv2.BatchWriteItemRequestMap
47+
UnprocessedItems: Record<string, DynamoDB.WriteRequest[]>
4948
}
5049

5150
/**

src/dynamo/expression/param-util.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module expression
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
65
import { isEmpty } from '../../helper/is-empty.function'
76
import { isString } from '../../helper/is-string.function'
87
import { ConditionalParams } from '../operation-params.type'
@@ -27,12 +26,12 @@ export function addExpression(
2726
) {
2827
const nameSafeCondition = resolveAttributeValueNameConflicts(condition, params)
2928

30-
const expressionAttributeNames = <DynamoDBv2.ExpressionAttributeNameMap>{
29+
const expressionAttributeNames = <Record<string, string>>{
3130
...params.ExpressionAttributeNames,
3231
...nameSafeCondition.attributeNames,
3332
}
3433

35-
const expressionAttributeValues = <DynamoDBv2.ExpressionAttributeValueMap>{
34+
const expressionAttributeValues = <Record<string, DynamoDB.AttributeValue>>{
3635
...params.ExpressionAttributeValues,
3736
...nameSafeCondition.attributeValues,
3837
}

src/dynamo/operation-params.type.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module dynamo-easy
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../aws-sdk-v2.types'
65

76
/**
87
* @hidden
@@ -15,8 +14,8 @@ export interface ConditionalParamsHost {
1514
* @hidden
1615
*/
1716
export interface ConditionalParams {
18-
expressionAttributeNames?: DynamoDBv2.ExpressionAttributeNameMap
19-
expressionAttributeValues?: DynamoDBv2.ExpressionAttributeValueMap
17+
expressionAttributeNames?: Record<string, string>
18+
expressionAttributeValues?: Record<string, DynamoDB.AttributeValue>
2019
[key: string]: any
2120
}
2221

src/dynamo/request/batchgetsingletable/batch-get-single-table.response.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module store-requests
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'
65

76
/**
87
* Response from {@link BatchGetSingleTableRequest}::exec
@@ -15,7 +14,7 @@ export interface BatchGetSingleTableResponse<T> {
1514
/**
1615
* A map of tables and their respective keys that were not processed with the current response. The UnprocessedKeys value is in the same form as RequestItems, so the value can be provided directly to a subsequent BatchGetItem operation. For more information, see RequestItems in the Request Parameters section. Each element consists of: Keys - An array of primary key attribute values that define specific items in the table. ProjectionExpression - One or more attributes to be retrieved from the table or index. By default, all attributes are returned. If a requested attribute is not found, it does not appear in the result. ConsistentRead - The consistency of a read operation. If set to true, then a strongly consistent read is used; otherwise, an eventually consistent read is used. If there are no unprocessed keys remaining, the response contains an empty UnprocessedKeys map.
1716
*/
18-
UnprocessedKeys?: DynamoDBv2.BatchGetRequestMap
17+
UnprocessedKeys?: Record<string, DynamoDB.KeysAndAttributes>
1918
/**
2019
* The read capacity units consumed by the entire BatchGetItem operation. Each element consists of: TableName - The table that consumed the provisioned throughput. CapacityUnits - The total number of capacity units consumed.
2120
*/

src/dynamo/request/query/query.response.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module store-requests
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'
65

76
/**
87
* copied from aws-sdk/clients/dynamoDb QueryOutput but added generics, because we process the items and map them
@@ -24,7 +23,7 @@ export interface QueryResponse<T> {
2423
/**
2524
* The primary key of the item where the operation stopped, inclusive of the previous result set. Use this value to start a new operation, excluding this value in the new request. If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved. If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set. The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty.
2625
*/
27-
LastEvaluatedKey?: DynamoDBv2.Key
26+
LastEvaluatedKey?: Record<string, DynamoDB.AttributeValue>
2827
/**
2928
* The capacity units consumed by the Query operation. The data returned includes the total provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity parameter was specified For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
3029
*/

src/dynamo/request/read-many.request.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module store-requests
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
65
import { SecondaryIndex } from '../../decorator/impl/index/secondary-index'
76
import { fetchAll } from '../../helper/fetch-all.function'
87
import { promiseTap } from '../../helper/promise-tap.function'
@@ -59,7 +58,7 @@ export abstract class ReadManyRequest<
5958
* @param key A map representing the start id which is included in next call, if null is delivered
6059
* startKey will be removed from params
6160
*/
62-
exclusiveStartKey(key: DynamoDBv2.Key | null): this {
61+
exclusiveStartKey(key: Record<string, DynamoDB.AttributeValue> | null): this {
6362
// TODO ENHANCEMENT exclusiveStartKey(item: Partial<T>)
6463
if (key) {
6564
this.params.ExclusiveStartKey = key

src/dynamo/request/scan/scan.response.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @module store-requests
33
*/
44
import * as DynamoDB from '@aws-sdk/client-dynamodb'
5-
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'
65

76
export interface ScanResponse<T> {
87
/**
@@ -20,7 +19,7 @@ export interface ScanResponse<T> {
2019
/**
2120
* The primary key of the item where the operation stopped, inclusive of the previous result set. Use this value to start a new operation, excluding this value in the new request. If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved. If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set. The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty.
2221
*/
23-
LastEvaluatedKey?: DynamoDBv2.Key
22+
LastEvaluatedKey?: Record<string, DynamoDB.AttributeValue>
2423
/**
2524
* The capacity units consumed by the Scan operation. The data returned includes the total provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity parameter was specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
2625
*/

src/helper/fetch-all.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module helper
33
*/
4-
import * as DynamoDBv2 from '../aws-sdk-v2.types'
4+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
55
import { QueryRequest } from '../dynamo/request/query/query.request'
66
import { ReadManyRequest } from '../dynamo/request/read-many.request'
77
import { ScanRequest } from '../dynamo/request/scan/scan.request'
@@ -11,7 +11,7 @@ import { ScanRequest } from '../dynamo/request/scan/scan.request'
1111
* available. This can be used with scan and query requests.
1212
*/
1313

14-
export function fetchAll<T>(request: ScanRequest<T> | QueryRequest<T>, startKey?: DynamoDBv2.Key): Promise<T[]> {
14+
export function fetchAll<T>(request: ScanRequest<T> | QueryRequest<T>, startKey?: Record<string, DynamoDB.AttributeValue>): Promise<T[]> {
1515
request.limit(ReadManyRequest.INFINITE_LIMIT)
1616
if (startKey) {
1717
request.exclusiveStartKey(startKey)

src/mapper/mapper.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
NestedModelWithCustomMapper,
4242
} from '../../test/models/model-with-nested-model-with-custom-mapper.model'
4343
import { NestedComplexModel } from '../../test/models/nested-complex.model'
44-
import * as DynamoDBv2 from '../aws-sdk-v2.types'
44+
import * as DynamoDB from '@aws-sdk/client-dynamodb'
4545
import { metadataForModel } from '../decorator/metadata/metadata-for-model.function'
4646
import { PropertyMetadata } from '../decorator/metadata/property-metadata.model'
4747
import { createKeyAttributes, createToKeyFn, fromDb, fromDbOne, toDb, toDbOne, toKey } from './mapper'
@@ -713,13 +713,13 @@ describe('Mapper', () => {
713713
describe('model with non string/number/binary keys', () => {
714714
it('should accept date as HASH or RANGE key', () => {
715715
const now = new Date()
716-
const toDbVal: DynamoDBv2.AttributeMap = toDb(new ModelWithDateAsHashKey(now), ModelWithDateAsHashKey)
716+
const toDbVal: Record<string, DynamoDB.AttributeValue> = toDb(new ModelWithDateAsHashKey(now), ModelWithDateAsHashKey)
717717
expect(toDbVal.startDate.S).toBeDefined()
718718
expect(toDbVal.startDate.S).toEqual(now.toISOString())
719719
})
720720
it('should accept date as HASH or RANGE key on GSI', () => {
721721
const now = new Date()
722-
const toDbVal: DynamoDBv2.AttributeMap = toDb(
722+
const toDbVal: Record<string, DynamoDB.AttributeValue> = toDb(
723723
new ModelWithDateAsIndexHashKey(0, now),
724724
ModelWithDateAsIndexHashKey,
725725
)

0 commit comments

Comments
 (0)