Skip to content

Commit

Permalink
feat(aws-sdk-v3): remove v2 types
Browse files Browse the repository at this point in the history
  • Loading branch information
nduthoit committed Apr 16, 2024
1 parent 01a0be7 commit 0c84a39
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 64 deletions.
21 changes: 0 additions & 21 deletions src/aws-sdk-v2.types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions 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-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand All @@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
export function GSIPartitionKey(indexName: string): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
if (typeof propertyKey === 'string') {
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: KeyType.HASH }, target, propertyKey)
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: DynamoDB.KeyType.HASH }, target, propertyKey)
}
}
}
4 changes: 2 additions & 2 deletions 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-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand All @@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
export function GSISortKey(indexName: string): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
if (typeof propertyKey === 'string') {
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: KeyType.RANGE }, target, propertyKey)
initOrUpdateIndex(IndexType.GSI, { name: indexName, keyType: DynamoDB.KeyType.RANGE }, target, propertyKey)
}
}
}
4 changes: 2 additions & 2 deletions 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-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { IndexType } from './index-type.enum'
import { initOrUpdateIndex } from './util'

Expand All @@ -11,7 +11,7 @@ import { initOrUpdateIndex } from './util'
export function LSISortKey(indexName: string): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
if (typeof propertyKey === 'string') {
initOrUpdateIndex(IndexType.LSI, { name: indexName, keyType: KeyType.RANGE }, target, propertyKey)
initOrUpdateIndex(IndexType.LSI, { name: indexName, keyType: DynamoDB.KeyType.RANGE }, target, propertyKey)
}
}
}
6 changes: 3 additions & 3 deletions src/decorator/impl/index/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module decorators
*/
import { KeyType } from '../../../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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: KeyType
keyType: DynamoDB.KeyType
}

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, ta
/**
* @hidden
*/
function initOrUpdateGSI(indexes: Record<string, KeyType>, indexData: IndexData): Partial<PropertyMetadata<any>> {
function initOrUpdateGSI(indexes: Record<string, DynamoDB.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
4 changes: 2 additions & 2 deletions 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-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { createOptModelLogger } from '../../../logger/logger'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
Expand Down Expand Up @@ -32,7 +32,7 @@ export function PartitionKey(): PropertyDecorator {
}
}

initOrUpdateProperty({ key: { type: KeyType.HASH } }, target, propertyKey)
initOrUpdateProperty({ key: { type: DynamoDB.KeyType.HASH } }, target, propertyKey)
}
}
}
4 changes: 2 additions & 2 deletions src/decorator/impl/key/sort-key.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @module decorators
*/
import { KeyType } from '../../../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'

export function SortKey(): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
if (typeof propertyKey === 'string') {
initOrUpdateProperty({ key: { type: KeyType.RANGE } }, target, propertyKey)
initOrUpdateProperty({ key: { type: DynamoDB.KeyType.RANGE } }, target, propertyKey)
}
}
}
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 { KeyType } from '../../../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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, KeyType> } {
): property is PropertyMetadata<T> & { keyForGSI: Record<string, DynamoDB.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 { KeyType } from '../../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
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: KeyType
type: DynamoDB.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, KeyType>
keyForGSI?: Record<string, DynamoDB.KeyType>

// holds all the the index names for which this property describes the sort key attribute
sortKeyForLSI?: string[]
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/batchget/batch-get-full.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module multi-model-requests/batch-get
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
import { BatchGetResponse } from './batch-get.response'

/**
Expand All @@ -16,7 +15,7 @@ export interface BatchGetFullResponse {
/**
* 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.
*/
UnprocessedKeys?: DynamoDBv2.BatchGetRequestMap
UnprocessedKeys?: Record<string, DynamoDB.KeysAndAttributes>
/**
* 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.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/batchget/batch-get-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module multi-model-requests/batch-get
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
import { promiseDelay } from '../../helper/promise-delay.function'
import { DynamoDbWrapper } from '../dynamo-db-wrapper'

Expand Down Expand Up @@ -45,7 +44,7 @@ export function batchGetItemsFetchAll(
* @hidden
*/
export type BatchGetItemOutputWithUnprocessedKeys = DynamoDB.BatchGetItemOutput & {
UnprocessedKeys: DynamoDBv2.BatchGetRequestMap
UnprocessedKeys: Record<string, DynamoDB.KeysAndAttributes>
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/batchwrite/batch-write-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module multi-model-requests/batch-write
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
import { promiseDelay } from '../../helper/promise-delay.function'
import { DynamoDbWrapper } from '../dynamo-db-wrapper'

Expand Down Expand Up @@ -45,7 +44,7 @@ export function batchWriteItemsWriteAll(
* @hidden
*/
export type BatchWriteItemOutputWithUnprocessedItems = DynamoDB.BatchWriteItemOutput & {
UnprocessedItems: DynamoDBv2.BatchWriteItemRequestMap
UnprocessedItems: Record<string, DynamoDB.WriteRequest[]>
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/dynamo/expression/param-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module expression
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
import { isEmpty } from '../../helper/is-empty.function'
import { isString } from '../../helper/is-string.function'
import { ConditionalParams } from '../operation-params.type'
Expand All @@ -27,12 +26,12 @@ export function addExpression(
) {
const nameSafeCondition = resolveAttributeValueNameConflicts(condition, params)

const expressionAttributeNames = <DynamoDBv2.ExpressionAttributeNameMap>{
const expressionAttributeNames = <Record<string, string>>{
...params.ExpressionAttributeNames,
...nameSafeCondition.attributeNames,
}

const expressionAttributeValues = <DynamoDBv2.ExpressionAttributeValueMap>{
const expressionAttributeValues = <Record<string, DynamoDB.AttributeValue>>{
...params.ExpressionAttributeValues,
...nameSafeCondition.attributeValues,
}
Expand Down
5 changes: 2 additions & 3 deletions src/dynamo/operation-params.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module dynamo-easy
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../aws-sdk-v2.types'

/**
* @hidden
Expand All @@ -15,8 +14,8 @@ export interface ConditionalParamsHost {
* @hidden
*/
export interface ConditionalParams {
expressionAttributeNames?: DynamoDBv2.ExpressionAttributeNameMap
expressionAttributeValues?: DynamoDBv2.ExpressionAttributeValueMap
expressionAttributeNames?: Record<string, string>
expressionAttributeValues?: Record<string, DynamoDB.AttributeValue>
[key: string]: any
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module store-requests
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'

/**
* Response from {@link BatchGetSingleTableRequest}::exec
Expand All @@ -15,7 +14,7 @@ export interface BatchGetSingleTableResponse<T> {
/**
* 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.
*/
UnprocessedKeys?: DynamoDBv2.BatchGetRequestMap
UnprocessedKeys?: Record<string, DynamoDB.KeysAndAttributes>
/**
* 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.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/request/query/query.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module store-requests
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'

/**
* copied from aws-sdk/clients/dynamoDb QueryOutput but added generics, because we process the items and map them
Expand All @@ -24,7 +23,7 @@ export interface QueryResponse<T> {
/**
* 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.
*/
LastEvaluatedKey?: DynamoDBv2.Key
LastEvaluatedKey?: Record<string, DynamoDB.AttributeValue>
/**
* 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.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/request/read-many.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module store-requests
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../aws-sdk-v2.types'
import { SecondaryIndex } from '../../decorator/impl/index/secondary-index'
import { fetchAll } from '../../helper/fetch-all.function'
import { promiseTap } from '../../helper/promise-tap.function'
Expand Down Expand Up @@ -59,7 +58,7 @@ export abstract class ReadManyRequest<
* @param key A map representing the start id which is included in next call, if null is delivered
* startKey will be removed from params
*/
exclusiveStartKey(key: DynamoDBv2.Key | null): this {
exclusiveStartKey(key: Record<string, DynamoDB.AttributeValue> | null): this {
// TODO ENHANCEMENT exclusiveStartKey(item: Partial<T>)
if (key) {
this.params.ExclusiveStartKey = key
Expand Down
3 changes: 1 addition & 2 deletions src/dynamo/request/scan/scan.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module store-requests
*/
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import * as DynamoDBv2 from '../../../aws-sdk-v2.types'

export interface ScanResponse<T> {
/**
Expand All @@ -20,7 +19,7 @@ export interface ScanResponse<T> {
/**
* 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.
*/
LastEvaluatedKey?: DynamoDBv2.Key
LastEvaluatedKey?: Record<string, DynamoDB.AttributeValue>
/**
* 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.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/helper/fetch-all.function.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module helper
*/
import * as DynamoDBv2 from '../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { QueryRequest } from '../dynamo/request/query/query.request'
import { ReadManyRequest } from '../dynamo/request/read-many.request'
import { ScanRequest } from '../dynamo/request/scan/scan.request'
Expand All @@ -11,7 +11,7 @@ import { ScanRequest } from '../dynamo/request/scan/scan.request'
* available. This can be used with scan and query requests.
*/

export function fetchAll<T>(request: ScanRequest<T> | QueryRequest<T>, startKey?: DynamoDBv2.Key): Promise<T[]> {
export function fetchAll<T>(request: ScanRequest<T> | QueryRequest<T>, startKey?: Record<string, DynamoDB.AttributeValue>): Promise<T[]> {
request.limit(ReadManyRequest.INFINITE_LIMIT)
if (startKey) {
request.exclusiveStartKey(startKey)
Expand Down
6 changes: 3 additions & 3 deletions src/mapper/mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
NestedModelWithCustomMapper,
} from '../../test/models/model-with-nested-model-with-custom-mapper.model'
import { NestedComplexModel } from '../../test/models/nested-complex.model'
import * as DynamoDBv2 from '../aws-sdk-v2.types'
import * as DynamoDB from '@aws-sdk/client-dynamodb'
import { metadataForModel } from '../decorator/metadata/metadata-for-model.function'
import { PropertyMetadata } from '../decorator/metadata/property-metadata.model'
import { createKeyAttributes, createToKeyFn, fromDb, fromDbOne, toDb, toDbOne, toKey } from './mapper'
Expand Down Expand Up @@ -713,13 +713,13 @@ describe('Mapper', () => {
describe('model with non string/number/binary keys', () => {
it('should accept date as HASH or RANGE key', () => {
const now = new Date()
const toDbVal: DynamoDBv2.AttributeMap = toDb(new ModelWithDateAsHashKey(now), ModelWithDateAsHashKey)
const toDbVal: Record<string, DynamoDB.AttributeValue> = toDb(new ModelWithDateAsHashKey(now), ModelWithDateAsHashKey)
expect(toDbVal.startDate.S).toBeDefined()
expect(toDbVal.startDate.S).toEqual(now.toISOString())
})
it('should accept date as HASH or RANGE key on GSI', () => {
const now = new Date()
const toDbVal: DynamoDBv2.AttributeMap = toDb(
const toDbVal: Record<string, DynamoDB.AttributeValue> = toDb(
new ModelWithDateAsIndexHashKey(0, now),
ModelWithDateAsIndexHashKey,
)
Expand Down

0 comments on commit 0c84a39

Please sign in to comment.