Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-sdk-v3): remove v2 types #422

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Conversation

nduthoit
Copy link

Addresses this TODO by using the built-in aws-sdk v3 types and removing the need for src/aws-sdk-v2.types.ts.

Type previous value replacement
BatchGetRequestMap { [key: string]: KeysAndAttributes } Record<string, KeysAndAttributes>
BatchWriteItemRequestMap { [key: string]: WriteRequest[] } Record<string, WriteRequest[]>
ExpressionAttributeNameMap { [key: string]: string } Record<string, string>
ExpressionAttributeValueMap { [key: string]: AttributeValue } Record<string, AttributeValue>
AttributeMap { [key: string]: AttributeValue } Record<string, AttributeValue>
Key { [key: string]: AttributeValue } Record<string, AttributeValue>

Also switches to using KeyType from @aws-sdk/client-dynamodb. Tested and it worked at runtime.

@michaelwittwer
Copy link
Member

@nduthoit Wow, Thanks a lot for that contribution. This looks great and happy to hear that it worked by using the KeyType from @aws-sdk/client-dynamodb. I am still a little hesitant if we can take your verification as "it works everywhere", the last issue was reported here in a react context, this might behave differently depending on the build pipeline. I can't remember where I hit the issue.
Added some minor comments, other than that this is ready to be merged.

@@ -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, AttributeValue>): Promise<T[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to stick with DynamoDB.AttributeValue to be consistent (import * as DynamoDB from '@aws-sdk/client-dynamodb')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also updated the KeyType imports to be consistent.

@@ -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, AttributeValue> = toDb(new ModelWithDateAsHashKey(now), ModelWithDateAsHashKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (DynamoDB.AttributeValue)

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, AttributeValue> = toDb(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (DynamoDB.AttributeValue)

@nduthoit nduthoit force-pushed the next branch 3 times, most recently from a511096 to ef63239 Compare April 16, 2024 21:13
@nduthoit
Copy link
Author

nduthoit commented Apr 16, 2024

@michaelwittwer yes, I hear you, "works on my machine" is not necessarily the best proof 😅

I tried replicating the reported issue with KeyType using @aws-sdk/[email protected] but was not able to.

@michaelwittwer
Copy link
Member

@nduthoit Thanks for the update. Do you use any bundler or plain tsc and then run with node?

@michaelwittwer michaelwittwer merged commit cc07fbc into shiftcode:next Apr 19, 2024
4 checks passed
Copy link

🎉 This PR is included in version 8.0.0-next.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@michaelwittwer
Copy link
Member

@nduthoit I just tried to compile our Angular application using v3.188.0 and it fails with:

../../node_modules/@shiftcoders/dynamo-easy/dist/_esm2022/decorator/impl/key/partition-key.decorator.js:27:16-37 - Error: export 'KeyType' (imported as 'DynamoDB') was not found in '@aws-sdk/client-dynamodb' (possible exports: ArchivalSummaryFilterSensitiveLog, AttributeDefinitionFilterSensitiveLog, AttributeValue, AttributeValueFilterSensitiveLog, AttributeValueUpdateFilterSensitiveLog, AutoScalingPolicyDescriptionFilterSensitiveLog, AutoScalingPolicyUpdateFilterSensitiveLog, AutoScalingSettingsDescriptionFilterSensitiveLog, AutoScalingSettingsUpdateFilterSensitiveLog, AutoScalingTargetTrackingScalingPolicyConfigurationDescriptionFilterSensitiveLog, AutoScalingTargetTrackingScalingPolicyConfigurationUpdateFilterSensitiveLog, BackupDescriptionFilterSensitiveLog, BackupDetailsFilterSensitiveLog, BackupInUseException, BackupNotFoundException, BackupSummaryFilterSensitiveLog, BackupType, BackupTypeFilter, BatchExecuteStatementCommand, BatchExecuteStatementInputFilterSensitiveLog, BatchExecuteStatementOutputFilterSensitiveLog, BatchGetItemCommand, BatchGetItemInputFilterSensitiveLog, BatchGetItemOutputFilterSensitiveLog, BatchStatementErrorCodeEnum, BatchStatementErrorFilterSensitiveLog, BatchStatementRequestFilterSensitiveLog, BatchStatementResponseFilterSensitiveLog, BatchWriteItemCommand, BatchWriteItemInputFilterSensitiveLog, BatchWriteItemOutputFilterSensitiveLog, BillingModeSummaryFilterSensitiveLog, CancellationReasonFilterSensitiveLog, CapacityFilterSensitiveLog, ConditionCheckFilterSensitiveLog, ConditionFilterSensitiveLog, ConditionalCheckFailedException, ConsumedCapacityFilterSensitiveLog, ContinuousBackupsDescriptionFilterSensitiveLog, ContinuousBackupsUnavailableException, ContributorInsightsSummaryFilterSensitiveLog, CreateBackupCommand, CreateBackupInputFilterSensitiveLog, CreateBackupOutputFilterSensitiveLog, CreateGlobalSecondaryIndexActionFilterSensitiveLog, CreateGlobalTableCommand, CreateGlobalTableInputFilterSensitiveLog, CreateGlobalTableOutputFilterSensitiveLog, CreateReplicaActionFilterSensitiveLog, CreateReplicationGroupMemberActionFilterSensitiveLog, CreateTableCommand, CreateTableInputFilterSensitiveLog, CreateTableOutputFilterSensitiveLog, CsvOptionsFilterSensitiveLog, DeleteBackupCommand, DeleteBackupInputFilterSensitiveLog, DeleteBackupOutputFilterSensitiveLog, DeleteFilterSensitiveLog, DeleteGlobalSecondaryIndexActionFilterSensitiveLog, DeleteItemCommand, DeleteItemInputFilterSensitiveLog, DeleteItemOutputFilterSensitiveLog, DeleteReplicaActionFilterSensitiveLog, DeleteReplicationGroupMemberActionFilterSensitiveLog, DeleteRequestFilterSensitiveLog, DeleteTableCommand, DeleteTableInputFilterSensitiveLog, DeleteTableOutputFilterSensitiveLog, DescribeBackupCommand, DescribeBackupInputFilterSensitiveLog, DescribeBackupOutputFilterSensitiveLog, DescribeContinuousBackupsCommand, DescribeContinuousBackupsInputFilterSensitiveLog, DescribeContinuousBackupsOutputFilterSensitiveLog, DescribeContributorInsightsCommand, DescribeContributorInsightsInputFilterSensitiveLog, DescribeContributorInsightsOutputFilterSensitiveLog, DescribeEndpointsCommand, DescribeEndpointsRequestFilterSensitiveLog, DescribeEndpointsResponseFilterSensitiveLog, DescribeExportCommand, DescribeExportInputFilterSensitiveLog, DescribeExportOutputFilterSensitiveLog, DescribeGlobalTableCommand, DescribeGlobalTableInputFilterSensitiveLog, DescribeGlobalTableOutputFilterSensitiveLog, DescribeGlobalTableSettingsCommand, DescribeGlobalTableSettingsInputFilterSensitiveLog, DescribeGlobalTableSettingsOutputFilterSensitiveLog, DescribeImportCommand, DescribeImportInputFilterSensitiveLog, DescribeImportOutputFilterSensitiveLog, DescribeKinesisStreamingDestinationCommand, DescribeKinesisStreamingDestinationInputFilterSensitiveLog, DescribeKinesisStreamingDestinationOutputFilterSensitiveLog, DescribeLimitsCommand, DescribeLimitsInputFilterSensitiveLog, DescribeLimitsOutputFilterSensitiveLog, DescribeTableCommand, DescribeTableInputFilterSensitiveLog, DescribeTableOutputFilterSensitiveLog, DescribeTableReplicaAutoScalingCommand, DescribeTableReplicaAutoScalingInputFilterSensitiveLog, DescribeTableReplicaAutoScalingOutputFilterSensitiveLog, DescribeTimeToLiveCommand, DescribeTimeToLiveInputFilterSensitiveLog, DescribeTimeToLiveOutputFilterSensitiveLog, DisableKinesisStreamingDestinationCommand, DuplicateItemException, DynamoDB, DynamoDBClient, DynamoDBServiceException, EnableKinesisStreamingDestinationCommand, EndpointFilterSensitiveLog, ExecuteStatementCommand, ExecuteStatementInputFilterSensitiveLog, ExecuteStatementOutputFilterSensitiveLog, ExecuteTransactionCommand, ExecuteTransactionInputFilterSensitiveLog, ExecuteTransactionOutputFilterSensitiveLog, ExpectedAttributeValueFilterSensitiveLog, ExportConflictException, ExportDescriptionFilterSensitiveLog, ExportFormat, ExportNotFoundException, ExportStatus, ExportSummaryFilterSensitiveLog, ExportTableToPointInTimeCommand, ExportTableToPointInTimeInputFilterSensitiveLog, ExportTableToPointInTimeOutputFilterSensitiveLog, FailureExceptionFilterSensitiveLog, GetFilterSensitiveLog, GetItemCommand, GetItemInputFilterSensitiveLog, GetItemOutputFilterSensitiveLog, GlobalSecondaryIndexAutoScalingUpdateFilterSensitiveLog, GlobalSecondaryIndexDescriptionFilterSensitiveLog, GlobalSecondaryIndexFilterSensitiveLog, GlobalSecondaryIndexInfoFilterSensitiveLog, GlobalSecondaryIndexUpdateFilterSensitiveLog, GlobalTableAlreadyExistsException, GlobalTableDescriptionFilterSensitiveLog, GlobalTableFilterSensitiveLog, GlobalTableGlobalSecondaryIndexSettingsUpdateFilterSensitiveLog, GlobalTableNotFoundException, IdempotentParameterMismatchException, ImportConflictException, ImportNotFoundException, ImportStatus, ImportSummaryFilterSensitiveLog, ImportTableCommand, ImportTableDescriptionFilterSensitiveLog, ImportTableInputFilterSensitiveLog, ImportTableOutputFilterSensitiveLog, IndexNotFoundException, InputCompressionType, InputFormat, InputFormatOptionsFilterSensitiveLog, InternalServerError, InvalidEndpointException, InvalidExportTimeException, InvalidRestoreTimeException, ItemCollectionMetricsFilterSensitiveLog, ItemCollectionSizeLimitExceededException, ItemResponseFilterSensitiveLog, KeySchemaElementFilterSensitiveLog, KeysAndAttributesFilterSensitiveLog, KinesisDataStreamDestinationFilterSensitiveLog, KinesisStreamingDestinationInputFilterSensitiveLog, KinesisStreamingDestinationOutputFilterSensitiveLog, LimitExceededException, ListBackupsCommand, ListBackupsInputFilterSensitiveLog, ListBackupsOutputFilterSensitiveLog, ListContributorInsightsCommand, ListContributorInsightsInputFilterSensitiveLog, ListContributorInsightsOutputFilterSensitiveLog, ListExportsCommand, ListExportsInputFilterSensitiveLog, ListExportsOutputFilterSensitiveLog, ListGlobalTablesCommand, ListGlobalTablesInputFilterSensitiveLog, ListGlobalTablesOutputFilterSensitiveLog, ListImportsCommand, ListImportsInputFilterSensitiveLog, ListImportsOutputFilterSensitiveLog, ListTablesCommand, ListTablesInputFilterSensitiveLog, ListTablesOutputFilterSensitiveLog, ListTagsOfResourceCommand, ListTagsOfResourceInputFilterSensitiveLog, ListTagsOfResourceOutputFilterSensitiveLog, LocalSecondaryIndexDescriptionFilterSensitiveLog, LocalSecondaryIndexFilterSensitiveLog, LocalSecondaryIndexInfoFilterSensitiveLog, ParameterizedStatementFilterSensitiveLog, PointInTimeRecoveryDescriptionFilterSensitiveLog, PointInTimeRecoverySpecificationFilterSensitiveLog, PointInTimeRecoveryUnavailableException, ProjectionFilterSensitiveLog, ProvisionedThroughputDescriptionFilterSensitiveLog, ProvisionedThroughputExceededException, ProvisionedThroughputFilterSensitiveLog, ProvisionedThroughputOverrideFilterSensitiveLog, PutFilterSensitiveLog, PutItemCommand, PutItemInputFilterSensitiveLog, PutItemOutputFilterSensitiveLog, PutRequestFilterSensitiveLog, QueryCommand, QueryInputFilterSensitiveLog, QueryOutputFilterSensitiveLog, ReplicaAlreadyExistsException, ReplicaAutoScalingDescriptionFilterSensitiveLog, ReplicaAutoScalingUpdateFilterSensitiveLog, ReplicaDescriptionFilterSensitiveLog, ReplicaFilterSensitiveLog, ReplicaGlobalSecondaryIndexAutoScalingDescriptionFilterSensitiveLog, ReplicaGlobalSecondaryIndexAutoScalingUpdateFilterSensitiveLog, ReplicaGlobalSecondaryIndexDescriptionFilterSensitiveLog, ReplicaGlobalSecondaryIndexFilterSensitiveLog, ReplicaGlobalSecondaryIndexSettingsDescriptionFilterSensitiveLog, ReplicaGlobalSecondaryIndexSettingsUpdateFilterSensitiveLog, ReplicaNotFoundException, ReplicaSettingsDescriptionFilterSensitiveLog, ReplicaSettingsUpdateFilterSensitiveLog, ReplicaUpdateFilterSensitiveLog, ReplicationGroupUpdateFilterSensitiveLog, RequestLimitExceeded, ResourceInUseException, ResourceNotFoundException, RestoreSummaryFilterSensitiveLog, RestoreTableFromBackupCommand, RestoreTableFromBackupInputFilterSensitiveLog, RestoreTableFromBackupOutputFilterSensitiveLog, RestoreTableToPointInTimeCommand, RestoreTableToPointInTimeInputFilterSensitiveLog, RestoreTableToPointInTimeOutputFilterSensitiveLog, S3BucketSourceFilterSensitiveLog, SSEDescriptionFilterSensitiveLog, SSESpecificationFilterSensitiveLog, ScanCommand, ScanInputFilterSensitiveLog, ScanOutputFilterSensitiveLog, SourceTableDetailsFilterSensitiveLog, SourceTableFeatureDetailsFilterSensitiveLog, StreamSpecificationFilterSensitiveLog, TableAlreadyExistsException, TableAutoScalingDescriptionFilterSensitiveLog, TableClass, TableClassSummaryFilterSensitiveLog, TableCreationParametersFilterSensitiveLog, TableDescriptionFilterSensitiveLog, TableInUseException, TableNotFoundException, TagFilterSensitiveLog, TagResourceCommand, TagResourceInputFilterSensitiveLog, TimeToLiveDescriptionFilterSensitiveLog, TimeToLiveSpecificationFilterSensitiveLog, TransactGetItemFilterSensitiveLog, TransactGetItemsCommand, TransactGetItemsInputFilterSensitiveLog, TransactGetItemsOutputFilterSensitiveLog, TransactWriteItemFilterSensitiveLog, TransactWriteItemsCommand, TransactWriteItemsInputFilterSensitiveLog, TransactWriteItemsOutputFilterSensitiveLog, TransactionCanceledException, TransactionConflictException, TransactionInProgressException, UntagResourceCommand, UntagResourceInputFilterSensitiveLog, UpdateContinuousBackupsCommand, UpdateContinuousBackupsInputFilterSensitiveLog, UpdateContinuousBackupsOutputFilterSensitiveLog, UpdateContributorInsightsCommand, UpdateContributorInsightsInputFilterSensitiveLog, UpdateContributorInsightsOutputFilterSensitiveLog, UpdateFilterSensitiveLog, UpdateGlobalSecondaryIndexActionFilterSensitiveLog, UpdateGlobalTableCommand, UpdateGlobalTableInputFilterSensitiveLog, UpdateGlobalTableOutputFilterSensitiveLog, UpdateGlobalTableSettingsCommand, UpdateGlobalTableSettingsInputFilterSensitiveLog, UpdateGlobalTableSettingsOutputFilterSensitiveLog, UpdateItemCommand, UpdateItemInputFilterSensitiveLog, UpdateItemOutputFilterSensitiveLog, UpdateReplicationGroupMemberActionFilterSensitiveLog, UpdateTableCommand, UpdateTableInputFilterSensitiveLog, UpdateTableOutputFilterSensitiveLog, UpdateTableReplicaAutoScalingCommand, UpdateTableReplicaAutoScalingInputFilterSensitiveLog, UpdateTableReplicaAutoScalingOutputFilterSensitiveLog, UpdateTimeToLiveCommand, UpdateTimeToLiveInputFilterSensitiveLog, UpdateTimeToLiveOutputFilterSensitiveLog, WriteRequestFilterSensitiveLog, paginateListContributorInsights, paginateListExports, paginateListImports, paginateListTables, paginateQuery, paginateScan, waitForTableExists, waitForTableNotExists, waitUntilTableExists, waitUntilTableNotExists)

I see the issue going away starting with version 3.214.0 (was fun to try and error 🙈 ), will push an updated version range.

@nduthoit
Copy link
Author

@nduthoit Thanks for the update. Do you use any bundler or plain tsc and then run with node?

We use webpack

Nice find on the version that includes the KeyType export!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants