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

chore: Uint8Array map was not traversing maps and unions #27071

Merged
merged 3 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ export function coerceToUint8Array(obj: any, path: string[]): any {
return coerceValueToUint8Array(obj);
}

if (path[0] === '*' && Array.isArray(obj)) {
return obj.map((e) => coerceToUint8Array(e, path.slice(1)));
if (path[0] === '*') {
if (Array.isArray(obj)) {
return obj.map((e) => coerceToUint8Array(e, path.slice(1)));
}
if (obj && typeof obj === 'object') {
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, coerceToUint8Array(value, path.slice(1))]));
}
// The value should have been an array or dict here, but let's be safe and return the original value anyway
return obj;
}

if (obj && typeof obj === 'object') {
Expand Down
244 changes: 238 additions & 6 deletions packages/@aws-cdk/sdk-v2-to-v3-adapter/lib/parameter-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated from the aws-sdk-js-v3 at Thu Sep 07 2023 15:56:12 GMT+0100 (British Summer Time)
// This file was generated from the aws-sdk-js-v3 at Fri Sep 08 2023 19:02:40 GMT+0200 (Central European Summer Time)
/* eslint-disable quote-props,comma-dangle */
export interface TypeCoercionMap {
[service: string]: {
Expand Down Expand Up @@ -71,6 +71,72 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'InlineChunk'
]
},
'clouddirectory': {
'addfacettoobject': [
'ObjectAttributeList.*.Value.BinaryValue'
],
'attachtypedlink': [
'Attributes.*.Value.BinaryValue'
],
'batchread': [
'Operations.*.GetLinkAttributes.TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue',
'Operations.*.ListIncomingTypedLinks.FilterAttributeRanges.*.Range.EndValue.BinaryValue',
'Operations.*.ListIncomingTypedLinks.FilterAttributeRanges.*.Range.StartValue.BinaryValue',
'Operations.*.ListIndex.RangesOnIndexedValues.*.Range.EndValue.BinaryValue',
'Operations.*.ListIndex.RangesOnIndexedValues.*.Range.StartValue.BinaryValue',
'Operations.*.ListOutgoingTypedLinks.FilterAttributeRanges.*.Range.EndValue.BinaryValue',
'Operations.*.ListOutgoingTypedLinks.FilterAttributeRanges.*.Range.StartValue.BinaryValue'
],
'batchwrite': [
'Operations.*.AddFacetToObject.ObjectAttributeList.*.Value.BinaryValue',
'Operations.*.AttachTypedLink.Attributes.*.Value.BinaryValue',
'Operations.*.CreateObject.ObjectAttributeList.*.Value.BinaryValue',
'Operations.*.DetachTypedLink.TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue',
'Operations.*.UpdateLinkAttributes.AttributeUpdates.*.AttributeAction.AttributeUpdateValue.BinaryValue',
'Operations.*.UpdateLinkAttributes.TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue',
'Operations.*.UpdateObjectAttributes.AttributeUpdates.*.ObjectAttributeAction.ObjectAttributeUpdateValue.BinaryValue'
],
'createfacet': [
'Attributes.*.AttributeDefinition.DefaultValue.BinaryValue'
],
'createobject': [
'ObjectAttributeList.*.Value.BinaryValue'
],
'createtypedlinkfacet': [
'Facet.Attributes.*.DefaultValue.BinaryValue'
],
'detachtypedlink': [
'TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue'
],
'getlinkattributes': [
'TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue'
],
'listincomingtypedlinks': [
'FilterAttributeRanges.*.Range.EndValue.BinaryValue',
'FilterAttributeRanges.*.Range.StartValue.BinaryValue'
],
'listindex': [
'RangesOnIndexedValues.*.Range.EndValue.BinaryValue',
'RangesOnIndexedValues.*.Range.StartValue.BinaryValue'
],
'listoutgoingtypedlinks': [
'FilterAttributeRanges.*.Range.EndValue.BinaryValue',
'FilterAttributeRanges.*.Range.StartValue.BinaryValue'
],
'updatefacet': [
'AttributeUpdates.*.Attribute.AttributeDefinition.DefaultValue.BinaryValue'
],
'updatelinkattributes': [
'AttributeUpdates.*.AttributeAction.AttributeUpdateValue.BinaryValue',
'TypedLinkSpecifier.IdentityAttributeValues.*.Value.BinaryValue'
],
'updateobjectattributes': [
'AttributeUpdates.*.ObjectAttributeAction.ObjectAttributeUpdateValue.BinaryValue'
],
'updatetypedlinkfacet': [
'AttributeUpdates.*.Attribute.DefaultValue.BinaryValue'
]
},
'cloudfront': {
'createfunction': [
'FunctionCode'
Expand Down Expand Up @@ -149,6 +215,106 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'CertificateWallet'
]
},
'dynamodb': {
'batchexecutestatement': [
'Statements.*.Parameters.*.B',
'Statements.*.Parameters.*.BS.*'
],
'batchgetitem': [
'RequestItems.*.Keys.*.*.B',
'RequestItems.*.Keys.*.*.BS.*'
],
'batchwriteitem': [
'RequestItems.*.*.DeleteRequest.Key.*.B',
'RequestItems.*.*.DeleteRequest.Key.*.BS.*',
'RequestItems.*.*.PutRequest.Item.*.B',
'RequestItems.*.*.PutRequest.Item.*.BS.*'
],
'deleteitem': [
'Expected.*.AttributeValueList.*.B',
'Expected.*.AttributeValueList.*.BS.*',
'Expected.*.Value.B',
'Expected.*.Value.BS.*',
'ExpressionAttributeValues.*.B',
'ExpressionAttributeValues.*.BS.*',
'Key.*.B',
'Key.*.BS.*'
],
'executestatement': [
'Parameters.*.B',
'Parameters.*.BS.*'
],
'executetransaction': [
'TransactStatements.*.Parameters.*.B',
'TransactStatements.*.Parameters.*.BS.*'
],
'getitem': [
'Key.*.B',
'Key.*.BS.*'
],
'putitem': [
'Expected.*.AttributeValueList.*.B',
'Expected.*.AttributeValueList.*.BS.*',
'Expected.*.Value.B',
'Expected.*.Value.BS.*',
'ExpressionAttributeValues.*.B',
'ExpressionAttributeValues.*.BS.*',
'Item.*.B',
'Item.*.BS.*'
],
'query': [
'ExclusiveStartKey.*.B',
'ExclusiveStartKey.*.BS.*',
'ExpressionAttributeValues.*.B',
'ExpressionAttributeValues.*.BS.*',
'KeyConditions.*.AttributeValueList.*.B',
'KeyConditions.*.AttributeValueList.*.BS.*',
'QueryFilter.*.AttributeValueList.*.B',
'QueryFilter.*.AttributeValueList.*.BS.*'
],
'scan': [
'ExclusiveStartKey.*.B',
'ExclusiveStartKey.*.BS.*',
'ExpressionAttributeValues.*.B',
'ExpressionAttributeValues.*.BS.*',
'ScanFilter.*.AttributeValueList.*.B',
'ScanFilter.*.AttributeValueList.*.BS.*'
],
'transactgetitems': [
'TransactItems.*.Get.Key.*.B',
'TransactItems.*.Get.Key.*.BS.*'
],
'transactwriteitems': [
'TransactItems.*.ConditionCheck.ExpressionAttributeValues.*.B',
'TransactItems.*.ConditionCheck.ExpressionAttributeValues.*.BS.*',
'TransactItems.*.ConditionCheck.Key.*.B',
'TransactItems.*.ConditionCheck.Key.*.BS.*',
'TransactItems.*.Delete.ExpressionAttributeValues.*.B',
'TransactItems.*.Delete.ExpressionAttributeValues.*.BS.*',
'TransactItems.*.Delete.Key.*.B',
'TransactItems.*.Delete.Key.*.BS.*',
'TransactItems.*.Put.ExpressionAttributeValues.*.B',
'TransactItems.*.Put.ExpressionAttributeValues.*.BS.*',
'TransactItems.*.Put.Item.*.B',
'TransactItems.*.Put.Item.*.BS.*',
'TransactItems.*.Update.ExpressionAttributeValues.*.B',
'TransactItems.*.Update.ExpressionAttributeValues.*.BS.*',
'TransactItems.*.Update.Key.*.B',
'TransactItems.*.Update.Key.*.BS.*'
],
'updateitem': [
'AttributeUpdates.*.Value.B',
'AttributeUpdates.*.Value.BS.*',
'Expected.*.AttributeValueList.*.B',
'Expected.*.AttributeValueList.*.BS.*',
'Expected.*.Value.B',
'Expected.*.Value.BS.*',
'ExpressionAttributeValues.*.B',
'ExpressionAttributeValues.*.BS.*',
'Key.*.B',
'Key.*.BS.*'
]
},
'ebs': {
'putsnapshotblock': [
'BlockData'
Expand Down Expand Up @@ -189,6 +355,11 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'Records.*.Data'
]
},
'frauddetector': {
'geteventprediction': [
'externalModelEndpointDataBlobs.*.byteBuffer'
]
},
'gamelift': {
'createscript': [
'ZipFile'
Expand All @@ -212,10 +383,12 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
},
'glue': {
'updatecolumnstatisticsforpartition': [
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MaximumValue.UnscaledValue'
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MaximumValue.UnscaledValue',
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MinimumValue.UnscaledValue'
],
'updatecolumnstatisticsfortable': [
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MaximumValue.UnscaledValue'
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MaximumValue.UnscaledValue',
'ColumnStatisticsList.*.StatisticsData.DecimalColumnStatisticsData.MinimumValue.UnscaledValue'
]
},
'greengrass': {
Expand Down Expand Up @@ -315,7 +488,8 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'Recipient.AttestationDocument'
],
'importkeymaterial': [
'EncryptedKeyMaterial'
'EncryptedKeyMaterial',
'ImportToken'
],
'reencrypt': [
'CiphertextBlob'
Expand Down Expand Up @@ -361,6 +535,9 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
],
'recognizeutterance': [
'inputStream'
],
'startconversation': [
'requestEventStream.AudioInputEvent.audioChunk'
]
},
'lookoutvision': {
Expand All @@ -376,6 +553,12 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'Body'
]
},
'medical-imaging': {
'updateimagesetmetadata': [
'updateImageSetMetadataUpdates.DICOMUpdates.removableAttributes',
'updateImageSetMetadataUpdates.DICOMUpdates.updatableAttributes'
]
},
'mobiletargeting': {
'sendmessages': [
'MessageRequest.MessageConfiguration.EmailMessage.RawEmail.Data'
Expand All @@ -395,9 +578,18 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'AssetBundleImportSource.Body'
]
},
'rds-data': {
'batchexecutestatement': [
'parameterSets.*.*.value.blobValue'
],
'executestatement': [
'parameters.*.value.blobValue'
]
},
'rekognition': {
'comparefaces': [
'SourceImage.Bytes'
'SourceImage.Bytes',
'TargetImage.Bytes'
],
'detectcustomlabels': [
'Image.Bytes'
Expand Down Expand Up @@ -431,6 +623,9 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
],
'updatedatasetentries': [
'Changes.GroundTruth'
],
'startfacelivenesssession': [
'LivenessRequestStream.VideoEvent.VideoChunk'
]
},
's3': {
Expand Down Expand Up @@ -481,6 +676,28 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'payload'
]
},
'sns': {
'publish': [
'MessageAttributes.*.BinaryValue'
],
'publishbatch': [
'PublishBatchRequestEntries.*.MessageAttributes.*.BinaryValue'
]
},
'sqs': {
'sendmessage': [
'MessageAttributes.*.BinaryListValues.*',
'MessageAttributes.*.BinaryValue',
'MessageSystemAttributes.*.BinaryListValues.*',
'MessageSystemAttributes.*.BinaryValue'
],
'sendmessagebatch': [
'Entries.*.MessageAttributes.*.BinaryListValues.*',
'Entries.*.MessageAttributes.*.BinaryValue',
'Entries.*.MessageSystemAttributes.*.BinaryListValues.*',
'Entries.*.MessageSystemAttributes.*.BinaryValue'
]
},
'ssm': {
'registertaskwithmaintenancewindow': [
'TaskInvocationParameters.Lambda.Payload'
Expand Down Expand Up @@ -516,6 +733,17 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'Document.Bytes'
]
},
'transcribe': {
'startcallanalyticsstreamtranscription': [
'AudioStream.AudioEvent.AudioChunk'
],
'startmedicalstreamtranscription': [
'AudioStream.AudioEvent.AudioChunk'
],
'startstreamtranscription': [
'AudioStream.AudioEvent.AudioChunk'
]
},
'translate': {
'importterminology': [
'TerminologyData.File'
Expand Down Expand Up @@ -556,7 +784,11 @@ export const UINT8ARRAY_PARAMETERS: TypeCoercionMap = {
'DeviceTypeAndroid.Logo',
'DeviceTypeIos.Logo',
'DeviceTypeIos.Logo2x',
'DeviceTypeIos.Logo3x'
'DeviceTypeIos.Logo3x',
'DeviceTypeLinux.Logo',
'DeviceTypeOsx.Logo',
'DeviceTypeWeb.Logo',
'DeviceTypeWindows.Logo'
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,22 @@ describe('given an api call description', () => {
],
});
});

test('can convert string parameters to Uint8Array in map & union', async () => {
const params = coerceApiParametersToUint8Array('dynamodb', 'putItem', {
Item: {
Binary: {
B: 'abc',
},
},
});

expect(params).toMatchObject({
Item: {
Binary: {
B: new Uint8Array([97, 98, 99]),
},
},
});
});
});
3 changes: 2 additions & 1 deletion scripts/update-sdkv3-parameters-model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tmpdir=$(mktemp -d)
zip=https://github.com/aws/aws-sdk-js-v3/archive/refs/heads/main.zip
ziprootentry=aws-sdk-js-v3-main
target_file=packages/@aws-cdk/sdk-v2-to-v3-adapter/lib/parameter-types.ts
smithy_subdir=codegen/sdk-codegen/aws-models

# Use the GitHub feature to download a zip archive of the current state of a branch
# (Cloning --depth 1 takes about twice as long, cloning with full depth many minutes)
Expand All @@ -13,7 +14,7 @@ curl -SfL -o $tmpdir/main.zip "$zip"
(cd $tmpdir && unzip -q main.zip)

echo "🖨️ Generating..."
npx ts-node $scriptdir/update-sdkv3-parameters-model.ts $tmpdir/$ziprootentry > "$target_file"
npx ts-node $scriptdir/update-sdkv3-parameters-model.ts $tmpdir/$ziprootentry/$smithy_subdir > "$target_file"

echo "🚮 Cleaning up..."
rm -rf $tmpdir
Expand Down
Loading
Loading