From efc22af8a686ca29cf3a2e06dd7bf8cb59dada3d Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 11:14:51 -0800 Subject: [PATCH 01/31] Add basic test for api-unavailable-type --- .../__fixtures__/api-unavailable-type/global-import.input.ts | 4 ++++ .../__fixtures__/api-unavailable-type/global-import.output.ts | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts new file mode 100644 index 000000000..af7a77054 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts @@ -0,0 +1,4 @@ +import AWS from "aws-sdk"; + +// string +const arn: AWS.ACM.Arn = "arn"; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts new file mode 100644 index 000000000..1366e12ff --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts @@ -0,0 +1,3 @@ +// string +const arn: string = "arn"; + From b40f4260766615e86028af155c6d841eaf81296d Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 11:29:30 -0800 Subject: [PATCH 02/31] Add examples for native types and arrays --- .../api-unavailable-type/global-import.input.ts | 14 ++++++++++++-- .../api-unavailable-type/global-import.output.ts | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts index af7a77054..759de7b8a 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts @@ -1,4 +1,14 @@ import AWS from "aws-sdk"; -// string -const arn: AWS.ACM.Arn = "arn"; \ No newline at end of file +// Native types +const stringType: AWS.S3.AccountId = "string"; // string +const booleanType: AWS.S3.BucketKeyEnabled = true; // boolean +const numberType: AWS.S3.ContentLength = 123; // number + +// Uint8Array +const blobType: AWS.ACM.CertificateBodyBlob = new Uint8Array(); + +// Arrays +const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; // string[] +const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; // boolean[] +const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts index 1366e12ff..97ca6d52e 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts @@ -1,3 +1,12 @@ -// string -const arn: string = "arn"; +// Native types +const stringType: string = "string"; // string +const booleanType: boolean = true; // boolean +const numberType: number = 123; // number +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: string[] = ["string1", "string2"]; // string[] +const booleanArray: boolean[] = [true, false]; // boolean[] +const numberArray: number[] = [123, 456]; // number[] \ No newline at end of file From 992bb01f1b010bd8ef89fa2197b10641fb86477a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 11:34:43 -0800 Subject: [PATCH 03/31] Add structure arrays --- .../api-unavailable-type/global-import.input.ts | 4 +++- .../api-unavailable-type/global-import.output.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts index 759de7b8a..3d8ac9f14 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts @@ -11,4 +11,6 @@ const blobType: AWS.ACM.CertificateBodyBlob = new Uint8Array(); // Arrays const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; // string[] const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; // boolean[] -const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] \ No newline at end of file +const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] +const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; // ChecksumAlgorithm[] +const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts index 97ca6d52e..435f6d1dd 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts @@ -1,3 +1,5 @@ +import AWS_S3 from "@aws-sdk/client-s3"; + // Native types const stringType: string = "string"; // string const booleanType: boolean = true; // boolean @@ -9,4 +11,6 @@ const blobType: Uint8Array = new Uint8Array(); // Arrays const stringArray: string[] = ["string1", "string2"]; // string[] const booleanArray: boolean[] = [true, false]; // boolean[] -const numberArray: number[] = [123, 456]; // number[] \ No newline at end of file +const numberArray: number[] = [123, 456]; // number[] +const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; // ChecksumAlgorithm[] +const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file From 7bb465ce0f421f80facdf59e721265a038a97262 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 11:36:22 -0800 Subject: [PATCH 04/31] Add blog array --- .../__fixtures__/api-unavailable-type/global-import.input.ts | 1 + .../__fixtures__/api-unavailable-type/global-import.output.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts index 3d8ac9f14..f58e9001f 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts @@ -12,5 +12,6 @@ const blobType: AWS.ACM.CertificateBodyBlob = new Uint8Array(); const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; // string[] const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; // boolean[] const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] +const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; // Uint8Array[] const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; // ChecksumAlgorithm[] const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts index 435f6d1dd..4b684b6bf 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts @@ -12,5 +12,6 @@ const blobType: Uint8Array = new Uint8Array(); const stringArray: string[] = ["string1", "string2"]; // string[] const booleanArray: boolean[] = [true, false]; // boolean[] const numberArray: number[] = [123, 456]; // number[] +const blobArray: Uint8Array[] = [new Uint8Array()]; // Uint8Array[] const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; // ChecksumAlgorithm[] const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file From ccde09b33d157b1ec9fb408303f5e1ee9a89bc51 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 15:10:32 -0800 Subject: [PATCH 05/31] Rename word unavailable to redundant in test folder name --- .../global-import.input.ts | 0 .../global-import.output.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/transforms/v2-to-v3/__fixtures__/{api-unavailable-type => api-redundant-type}/global-import.input.ts (100%) rename src/transforms/v2-to-v3/__fixtures__/{api-unavailable-type => api-redundant-type}/global-import.output.ts (100%) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts similarity index 100% rename from src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.input.ts rename to src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts similarity index 100% rename from src/transforms/v2-to-v3/__fixtures__/api-unavailable-type/global-import.output.ts rename to src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts From 0e3377cb63b0f44cf2071a51ef35984e9473f4d2 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 15:33:08 -0800 Subject: [PATCH 06/31] Add tests for Maps --- .../api-redundant-type/global-import.input.ts | 10 ++++++++-- .../api-redundant-type/global-import.output.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts index f58e9001f..4cfcdbad5 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts @@ -6,7 +6,7 @@ const booleanType: AWS.S3.BucketKeyEnabled = true; // boolean const numberType: AWS.S3.ContentLength = 123; // number // Uint8Array -const blobType: AWS.ACM.CertificateBodyBlob = new Uint8Array(); +const blobType: AWS.RDSDataService._Blob = new Uint8Array(); // Arrays const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; // string[] @@ -14,4 +14,10 @@ const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; // boolean[ const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; // Uint8Array[] const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; // ChecksumAlgorithm[] -const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file +const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] + +// Maps +const stringMap: AWS.S3.Metadata = { key: "value" }; // Record +const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; // Record +const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; // Record +const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Record \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index 4b684b6bf..f8404ada3 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -1,4 +1,5 @@ import AWS_S3 from "@aws-sdk/client-s3"; +import AWS_APIGateway from "@aws-sdk/client-api-gateway"; // Native types const stringType: string = "string"; // string @@ -14,4 +15,10 @@ const booleanArray: boolean[] = [true, false]; // boolean[] const numberArray: number[] = [123, 456]; // number[] const blobArray: Uint8Array[] = [new Uint8Array()]; // Uint8Array[] const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; // ChecksumAlgorithm[] -const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] \ No newline at end of file +const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] + +// Maps +const stringMap: Record = { key: "value" }; // Record +const booleanMap: Record = { key: true }; // Record +const numberMap: Record = { key: 123 }; // Record +const structureMap: Record = { key: { apiKeyRequired: true } }; // Record \ No newline at end of file From 7be42f9c35a02616cbbb4b12b55be036472b2c30 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:28:00 -0800 Subject: [PATCH 07/31] Add Date --- .../__fixtures__/api-redundant-type/global-import.input.ts | 5 ++++- .../__fixtures__/api-redundant-type/global-import.output.ts | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts index 4cfcdbad5..f22db6189 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts @@ -5,6 +5,9 @@ const stringType: AWS.S3.AccountId = "string"; // string const booleanType: AWS.S3.BucketKeyEnabled = true; // boolean const numberType: AWS.S3.ContentLength = 123; // number +// Date +const dateType: AWS.S3.CreationDate = new Date(); // Date + // Uint8Array const blobType: AWS.RDSDataService._Blob = new Uint8Array(); @@ -20,4 +23,4 @@ const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] const stringMap: AWS.S3.Metadata = { key: "value" }; // Record const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; // Record const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; // Record -const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Record \ No newline at end of file +const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Record diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index f8404ada3..eeb3f564b 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -6,6 +6,9 @@ const stringType: string = "string"; // string const booleanType: boolean = true; // boolean const numberType: number = 123; // number +// Date +const dateType: Date = new Date(); // Date + // Uint8Array const blobType: Uint8Array = new Uint8Array(); From 1ba3a4527ebe878c21ca49482a01bfdd5f0fb91c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:37:00 -0800 Subject: [PATCH 08/31] Add test for nested arrays --- .../api-redundant-type/global-import.input.ts | 8 ++++++++ .../api-redundant-type/global-import.output.ts | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts index f22db6189..b1222b30b 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts @@ -24,3 +24,11 @@ const stringMap: AWS.S3.Metadata = { key: "value" }; // Record const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; // Record const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; // Record const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Record + +// Nested arrays +const arrayNestedTwice: AWS.SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; // number[][] +const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; // number[][][] +const arrayNestedFour: AWS.SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; // number[][][][] \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index eeb3f564b..ba10ccfba 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -24,4 +24,12 @@ const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] const stringMap: Record = { key: "value" }; // Record const booleanMap: Record = { key: true }; // Record const numberMap: Record = { key: 123 }; // Record -const structureMap: Record = { key: { apiKeyRequired: true } }; // Record \ No newline at end of file +const structureMap: Record = { key: { apiKeyRequired: true } }; // Record + +// Nested arrays +const arrayNestedTwice: number[][] = [[1, 2], [3, 4]]; // number[][] +const arrayNestedThrice: number[][][] = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; // number[][][] +const arrayNestedFour: number[][][][] = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; // number[][][][] \ No newline at end of file From 36ffc3e4fea710145d0aea6bce841bdfbe9c666c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:05:33 -0800 Subject: [PATCH 09/31] Added tests for nested arrays and maps --- .../api-redundant-type/global-import.input.ts | 15 ++++++++++++++- .../api-redundant-type/global-import.output.ts | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts index b1222b30b..afa7e5b2f 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts @@ -31,4 +31,17 @@ const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]] const arrayNestedFour: AWS.SageMakerGeospatial.LinearRingsList = [ [[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]] -]; // number[][][][] \ No newline at end of file +]; // number[][][][] + +// Nested maps +const mapNestedTwice: AWS.LexModelsV2.ConditionMap = { key: stringMap }; // Record> +const mapNestedTwiceStruct: AWS.APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; // Record> + +// Nested arrays and maps +const mapOfArrays: AWS.NetworkManager.FilterMap = { key: ["value"] }; // Record +const mapOfMapOfArrays: AWS.SecurityLake.AllDimensionsMap = { key: mapOfArrays }; // Record> +const mapOfArrayOfMaps: AWS.DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; // Record[]> +const mapOfArrayOfArrays: AWS.APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; // Record +const arrayOfMaps: AWS.SSM.InventoryItemEntryList = [stringMap]; // Record[] +const arrayOfMapOfArrays: AWS.SSM.TargetMaps = [mapOfArrays]; // Record[] +const arrayOfMapOfMapOfArrays: AWS.SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; // Record>[] \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index ba10ccfba..67d02b3b4 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -1,5 +1,6 @@ -import AWS_S3 from "@aws-sdk/client-s3"; import AWS_APIGateway from "@aws-sdk/client-api-gateway"; +import AWS_DynamoDB from "@aws-sdk/client-dynamodb"; +import AWS_S3 from "@aws-sdk/client-s3"; // Native types const stringType: string = "string"; // string @@ -32,4 +33,17 @@ const arrayNestedThrice: number[][][] = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; // const arrayNestedFour: number[][][][] = [ [[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]] -]; // number[][][][] \ No newline at end of file +]; // number[][][][] + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; // Record> +const mapNestedTwiceStruct: Record> = { key: structureMap }; // Record> + +// Nested arrays and maps +const mapOfArrays: Record = { key: ["value"] }; // Record +const mapOfMapOfArrays: Record> = { key: mapOfArrays }; // Record>> +const mapOfArrayOfMaps: Record[]> = { key: [{ key: { S:"A" }}] }; // Record[]> +const mapOfArrayOfArrays: Record = { key: [[1], [2]] }; // Record +const arrayOfMaps: Record[] = [stringMap]; // Record[] +const arrayOfMapOfArrays: Record[] = [mapOfArrays]; // Record[] +const arrayOfMapOfMapOfArrays: Record>[] = [mapOfMapOfArrays]; // Record>[] \ No newline at end of file From cfbd8dc8a6b7ef71ab58295833d80f34501aa54b Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 23:24:56 -0800 Subject: [PATCH 10/31] Create utility getV3ClientTypesCount --- src/transforms/v2-to-v3/config/index.ts | 1 + .../v2-to-v3/modules/addV3ClientImports.ts | 6 +++--- .../v2-to-v3/modules/addV3ClientRequires.ts | 6 +++--- .../v2-to-v3/ts-type/getV3ClientTypeNames.ts | 13 ------------- .../v2-to-v3/ts-type/getV3ClientTypesCount.ts | 19 +++++++++++++++++++ src/transforms/v2-to-v3/ts-type/index.ts | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) delete mode 100644 src/transforms/v2-to-v3/ts-type/getV3ClientTypeNames.ts create mode 100644 src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts diff --git a/src/transforms/v2-to-v3/config/index.ts b/src/transforms/v2-to-v3/config/index.ts index 0afc2f62e..d49f6e9f9 100644 --- a/src/transforms/v2-to-v3/config/index.ts +++ b/src/transforms/v2-to-v3/config/index.ts @@ -1,4 +1,5 @@ export * from "./CLIENT_NAMES"; export * from "./CLIENT_NAMES_MAP"; export * from "./CLIENT_PACKAGE_NAMES_MAP"; +export * from "./CLIENT_TYPES_MAP"; export * from "./constants"; diff --git a/src/transforms/v2-to-v3/modules/addV3ClientImports.ts b/src/transforms/v2-to-v3/modules/addV3ClientImports.ts index 912b90492..26cbb3299 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientImports.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientImports.ts @@ -1,6 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { getV3ClientTypeNames } from "../ts-type"; +import { getV3ClientTypesCount } from "../ts-type"; import { addV3ClientDefaultImport } from "./addV3ClientDefaultImport"; import { addV3ClientNamedImport } from "./addV3ClientNamedImport"; import { getClientTSTypeRefCount } from "./getClientTSTypeRefCount"; @@ -13,14 +13,14 @@ export const addV3ClientImports = ( options: V3ClientModulesOptions ): void => { const { v2ClientLocalName, v2ClientName, v2GlobalName } = options; - const v3ClientTypeNames = getV3ClientTypeNames(j, source, { + const v3ClientTypesCount = getV3ClientTypesCount(j, source, { v2ClientLocalName, v2ClientName, v2GlobalName, }); // Add default import for types, if needed. - if (v3ClientTypeNames.length > 0) { + if (v3ClientTypesCount > 0) { addV3ClientDefaultImport(j, source, options); } diff --git a/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts b/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts index 64eb1301a..1817da265 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts @@ -1,6 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { getV3ClientTypeNames } from "../ts-type"; +import { getV3ClientTypesCount } from "../ts-type"; import { addV3ClientDefaultRequire } from "./addV3ClientDefaultRequire"; import { addV3ClientNamedRequire } from "./addV3ClientNamedRequire"; import { getClientTSTypeRefCount } from "./getClientTSTypeRefCount"; @@ -13,14 +13,14 @@ export const addV3ClientRequires = ( options: V3ClientModulesOptions ): void => { const { v2ClientLocalName, v2ClientName, v2GlobalName } = options; - const v3ClientTypeNames = getV3ClientTypeNames(j, source, { + const v3ClientTypesCount = getV3ClientTypesCount(j, source, { v2ClientLocalName, v2ClientName, v2GlobalName, }); // Add default require for types, if needed. - if (v3ClientTypeNames.length > 0) { + if (v3ClientTypesCount > 0) { addV3ClientDefaultRequire(j, source, options); } diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeNames.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeNames.ts deleted file mode 100644 index 22ed6bdd6..000000000 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeNames.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Collection, JSCodeshift } from "jscodeshift"; - -import { getV2ClientTypeNames, GetV2ClientTypeNamesOptions } from "./getV2ClientTypeNames"; -import { getV3ClientTypeName } from "./getV3ClientTypeName"; - -export const getV3ClientTypeNames = ( - j: JSCodeshift, - source: Collection, - options: GetV2ClientTypeNamesOptions -) => - getV2ClientTypeNames(j, source, options).map((v2ClientTypeName) => - getV3ClientTypeName(v2ClientTypeName) - ); diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts new file mode 100644 index 000000000..70776434b --- /dev/null +++ b/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts @@ -0,0 +1,19 @@ +import { Collection, JSCodeshift } from "jscodeshift"; + +import { CLIENT_TYPES_MAP } from "../config"; +import { getV2ClientTypeNames, GetV2ClientTypeNamesOptions } from "./getV2ClientTypeNames"; + +export const getV3ClientTypesCount = ( + j: JSCodeshift, + source: Collection, + options: GetV2ClientTypeNamesOptions +) => { + const { v2ClientName } = options; + + const v2ClientTypeNames = getV2ClientTypeNames(j, source, options); + const v3ClientUnavailableTypes = Object.keys(CLIENT_TYPES_MAP[v2ClientName]); + + return v2ClientTypeNames.filter( + (v2ClientTypeName) => !v3ClientUnavailableTypes.includes(v2ClientTypeName) + ).length; +}; diff --git a/src/transforms/v2-to-v3/ts-type/index.ts b/src/transforms/v2-to-v3/ts-type/index.ts index eaf3fcc02..8f7202f64 100644 --- a/src/transforms/v2-to-v3/ts-type/index.ts +++ b/src/transforms/v2-to-v3/ts-type/index.ts @@ -1,4 +1,4 @@ export * from "./getV2ClientTypeNames"; export * from "./getV3ClientTypeName"; -export * from "./getV3ClientTypeNames"; +export * from "./getV3ClientTypesCount"; export * from "./replaceTSTypeReference"; From 7fe69fd80a78a7cfb883b35644fd7f8cf8f733fc Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Jan 2023 23:43:09 -0800 Subject: [PATCH 11/31] WIP implementation to getV3ClientTypeReference --- .../v2-to-v3/ts-type/getV3ClientTypeName.ts | 19 ------- .../ts-type/getV3ClientTypeReference.ts | 56 +++++++++++++++++++ src/transforms/v2-to-v3/ts-type/index.ts | 2 +- .../ts-type/replaceTSTypeReference.ts | 46 +++++---------- 4 files changed, 71 insertions(+), 52 deletions(-) delete mode 100644 src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts create mode 100644 src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts deleted file mode 100644 index a101fee3e..000000000 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { V2_CLIENT_INPUT_SUFFIX_LIST, V2_CLIENT_OUTPUT_SUFFIX_LIST } from "../config"; - -export const getV3ClientTypeName = (v2ClientTypeName: string) => { - for (const inputSuffix of V2_CLIENT_INPUT_SUFFIX_LIST) { - if (v2ClientTypeName.endsWith(inputSuffix)) { - return v2ClientTypeName.replace(new RegExp(`${inputSuffix}$`), "CommandInput"); - } - } - - for (const outputSuffix of V2_CLIENT_OUTPUT_SUFFIX_LIST) { - if (v2ClientTypeName.endsWith(outputSuffix)) { - return v2ClientTypeName.replace(new RegExp(`${outputSuffix}$`), "CommandOutput"); - } - } - - // ToDo: Handle v2 client name not present in v3. - // Test case: https://github.com/awslabs/aws-sdk-js-codemod/pull/274 - return v2ClientTypeName; -}; diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts new file mode 100644 index 000000000..b465d2108 --- /dev/null +++ b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts @@ -0,0 +1,56 @@ +import { JSCodeshift, TSTypeReference } from "jscodeshift"; + +import { + CLIENT_TYPES_MAP, + V2_CLIENT_INPUT_SUFFIX_LIST, + V2_CLIENT_OUTPUT_SUFFIX_LIST, +} from "../config"; +import { getV3ClientDefaultLocalName } from "../utils"; + +export interface GetV3ClientTypeReferenceOptions { + v2ClientLocalName: string; + v2ClientName: string; + v2ClientTypeName: string; +} + +const getTypeRefWithV3ClientDefaultLocalName = ( + j: JSCodeshift, + v2ClientLocalName: string, + v3ClientTypeName: string +) => + j.tsTypeReference( + j.identifier([getV3ClientDefaultLocalName(v2ClientLocalName), v3ClientTypeName].join(".")) + ); + +export const getV3ClientTypeReference = ( + j: JSCodeshift, + { v2ClientLocalName, v2ClientName, v2ClientTypeName }: GetV3ClientTypeReferenceOptions +): TSTypeReference => { + const clientTypesMap = CLIENT_TYPES_MAP[v2ClientName]; + if (Object.keys(clientTypesMap).includes(v2ClientTypeName)) { + // ToDo: Convert the string value into a TSTypeReference + return clientTypesMap[v2ClientTypeName]; + } + + for (const inputSuffix of V2_CLIENT_INPUT_SUFFIX_LIST) { + if (v2ClientTypeName.endsWith(inputSuffix)) { + return getTypeRefWithV3ClientDefaultLocalName( + j, + v2ClientLocalName, + v2ClientTypeName.replace(new RegExp(`${inputSuffix}$`), "CommandInput") + ); + } + } + + for (const outputSuffix of V2_CLIENT_OUTPUT_SUFFIX_LIST) { + if (v2ClientTypeName.endsWith(outputSuffix)) { + return getTypeRefWithV3ClientDefaultLocalName( + j, + v2ClientLocalName, + v2ClientTypeName.replace(new RegExp(`${outputSuffix}$`), "CommandOutput") + ); + } + } + + return getTypeRefWithV3ClientDefaultLocalName(j, v2ClientLocalName, v2ClientTypeName); +}; diff --git a/src/transforms/v2-to-v3/ts-type/index.ts b/src/transforms/v2-to-v3/ts-type/index.ts index 8f7202f64..95c8f8f6a 100644 --- a/src/transforms/v2-to-v3/ts-type/index.ts +++ b/src/transforms/v2-to-v3/ts-type/index.ts @@ -1,4 +1,4 @@ export * from "./getV2ClientTypeNames"; -export * from "./getV3ClientTypeName"; +export * from "./getV3ClientTypeReference"; export * from "./getV3ClientTypesCount"; export * from "./replaceTSTypeReference"; diff --git a/src/transforms/v2-to-v3/ts-type/replaceTSTypeReference.ts b/src/transforms/v2-to-v3/ts-type/replaceTSTypeReference.ts index 3fd3204c0..94f7d908c 100644 --- a/src/transforms/v2-to-v3/ts-type/replaceTSTypeReference.ts +++ b/src/transforms/v2-to-v3/ts-type/replaceTSTypeReference.ts @@ -1,8 +1,8 @@ import { Collection, Identifier, JSCodeshift, TSQualifiedName, TSTypeReference } from "jscodeshift"; -import { getV2ClientTSTypeRef, getV3ClientDefaultLocalName } from "../utils"; +import { getV2ClientTSTypeRef } from "../utils"; import { getV2ClientTypeNames } from "./getV2ClientTypeNames"; -import { getV3ClientTypeName } from "./getV3ClientTypeName"; +import { getV3ClientTypeReference } from "./getV3ClientTypeReference"; export interface ReplaceTSTypeReferenceOptions { v2ClientName: string; @@ -19,15 +19,6 @@ const getRightIdentifierName = (node: TSTypeReference) => const getIdentifierName = (node: TSTypeReference) => (node.typeName as Identifier).name; -const getV3ClientTypeReference = ( - j: JSCodeshift, - v2ClientLocalName: string, - v3ClientTypeName: string -) => - j.tsTypeReference( - j.identifier([getV3ClientDefaultLocalName(v2ClientLocalName), v3ClientTypeName].join(".")) - ); - // Replace v2 client type reference with v3 client type reference. export const replaceTSTypeReference = ( j: JSCodeshift, @@ -49,26 +40,20 @@ export const replaceTSTypeReference = ( getV2ClientTSTypeRef({ v2ClientName, v2GlobalName, withoutRightSection: true }) ) .filter((v2ClientType) => isRightSectionIdentifier(v2ClientType.node)) - .replaceWith((v2ClientType) => - getV3ClientTypeReference( - j, - v2ClientLocalName, - getV3ClientTypeName(getRightIdentifierName(v2ClientType.node)) - ) - ); + .replaceWith((v2ClientType) => { + const v2ClientTypeName = getRightIdentifierName(v2ClientType.node); + return getV3ClientTypeReference(j, { v2ClientName, v2ClientTypeName, v2ClientLocalName }); + }); } // Replace reference to client types created with client module. source .find(j.TSTypeReference, getV2ClientTSTypeRef({ v2ClientLocalName, withoutRightSection: true })) .filter((v2ClientType) => isRightSectionIdentifier(v2ClientType.node)) - .replaceWith((v2ClientType) => - getV3ClientTypeReference( - j, - v2ClientLocalName, - getV3ClientTypeName(getRightIdentifierName(v2ClientType.node)) - ) - ); + .replaceWith((v2ClientType) => { + const v2ClientTypeName = getRightIdentifierName(v2ClientType.node); + return getV3ClientTypeReference(j, { v2ClientName, v2ClientTypeName, v2ClientLocalName }); + }); // Replace type reference to client type with modules. const v2ClientTypeNames = getV2ClientTypeNames(j, source, { @@ -80,12 +65,9 @@ export const replaceTSTypeReference = ( for (const v2ClientTypeName of v2ClientTypeNames) { source .find(j.TSTypeReference, { typeName: { type: "Identifier", name: v2ClientTypeName } }) - .replaceWith((v2ClientType) => - getV3ClientTypeReference( - j, - v2ClientLocalName, - getV3ClientTypeName(getIdentifierName(v2ClientType.node)) - ) - ); + .replaceWith((v2ClientType) => { + const v2ClientTypeName = getIdentifierName(v2ClientType.node); + return getV3ClientTypeReference(j, { v2ClientName, v2ClientTypeName, v2ClientLocalName }); + }); } }; From 688248226f44ede0c571f5843ccce73714af2cb1 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 00:22:45 -0800 Subject: [PATCH 12/31] Create utility getTypeRefForString which returns a string --- src/transforms/v2-to-v3/transformer.spec.ts | 2 +- .../v2-to-v3/ts-type/getTypeRefForString.ts | 9 ++++++++ .../ts-type/getV3ClientTypeReference.ts | 23 +++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts diff --git a/src/transforms/v2-to-v3/transformer.spec.ts b/src/transforms/v2-to-v3/transformer.spec.ts index 8703e5ed9..5d614230d 100644 --- a/src/transforms/v2-to-v3/transformer.spec.ts +++ b/src/transforms/v2-to-v3/transformer.spec.ts @@ -35,7 +35,7 @@ describe("v2-to-v3", () => { return { input, outputCode }; }; - describe.each(fixtureSubDirs)("%s", (subDir) => { + describe.each(["api-redundant-type"])("%s", (subDir) => { const subDirPath = join(fixtureDir, subDir); it.concurrent.each(getTestFileMetadata(subDirPath))( `transforms: %s.%s`, diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts new file mode 100644 index 000000000..ae6fdd629 --- /dev/null +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -0,0 +1,9 @@ +import { JSCodeshift, TSType } from "jscodeshift"; + +export const getTypeRefForString = ( + j: JSCodeshift, + v3ClientDefaultLocalName: string, + v3ClientTypeString: string +): TSType => { + return j.tsStringKeyword(); +}; diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts index b465d2108..1d1435db4 100644 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts +++ b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeReference.ts @@ -1,4 +1,4 @@ -import { JSCodeshift, TSTypeReference } from "jscodeshift"; +import { JSCodeshift, TSType } from "jscodeshift"; import { CLIENT_TYPES_MAP, @@ -6,6 +6,7 @@ import { V2_CLIENT_OUTPUT_SUFFIX_LIST, } from "../config"; import { getV3ClientDefaultLocalName } from "../utils"; +import { getTypeRefForString } from "./getTypeRefForString"; export interface GetV3ClientTypeReferenceOptions { v2ClientLocalName: string; @@ -15,28 +16,26 @@ export interface GetV3ClientTypeReferenceOptions { const getTypeRefWithV3ClientDefaultLocalName = ( j: JSCodeshift, - v2ClientLocalName: string, + v3ClientDefaultLocalName: string, v3ClientTypeName: string -) => - j.tsTypeReference( - j.identifier([getV3ClientDefaultLocalName(v2ClientLocalName), v3ClientTypeName].join(".")) - ); +) => j.tsTypeReference(j.identifier([v3ClientDefaultLocalName, v3ClientTypeName].join("."))); export const getV3ClientTypeReference = ( j: JSCodeshift, { v2ClientLocalName, v2ClientName, v2ClientTypeName }: GetV3ClientTypeReferenceOptions -): TSTypeReference => { +): TSType => { const clientTypesMap = CLIENT_TYPES_MAP[v2ClientName]; + const v3ClientDefaultLocalName = getV3ClientDefaultLocalName(v2ClientLocalName); + if (Object.keys(clientTypesMap).includes(v2ClientTypeName)) { - // ToDo: Convert the string value into a TSTypeReference - return clientTypesMap[v2ClientTypeName]; + return getTypeRefForString(j, v3ClientDefaultLocalName, clientTypesMap[v2ClientTypeName]); } for (const inputSuffix of V2_CLIENT_INPUT_SUFFIX_LIST) { if (v2ClientTypeName.endsWith(inputSuffix)) { return getTypeRefWithV3ClientDefaultLocalName( j, - v2ClientLocalName, + v3ClientDefaultLocalName, v2ClientTypeName.replace(new RegExp(`${inputSuffix}$`), "CommandInput") ); } @@ -46,11 +45,11 @@ export const getV3ClientTypeReference = ( if (v2ClientTypeName.endsWith(outputSuffix)) { return getTypeRefWithV3ClientDefaultLocalName( j, - v2ClientLocalName, + v3ClientDefaultLocalName, v2ClientTypeName.replace(new RegExp(`${outputSuffix}$`), "CommandOutput") ); } } - return getTypeRefWithV3ClientDefaultLocalName(j, v2ClientLocalName, v2ClientTypeName); + return getTypeRefWithV3ClientDefaultLocalName(j, v3ClientDefaultLocalName, v2ClientTypeName); }; From 85dfd37990a044180d9f3f7e7ccfccb6a43367f6 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 00:27:41 -0800 Subject: [PATCH 13/31] Return type for number and boolean --- .../v2-to-v3/ts-type/getTypeRefForString.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts index ae6fdd629..99fbe05d7 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -5,5 +5,17 @@ export const getTypeRefForString = ( v3ClientDefaultLocalName: string, v3ClientTypeString: string ): TSType => { + if (v3ClientTypeString === "string") { + return j.tsStringKeyword(); + } + + if (v3ClientTypeString === "number") { + return j.tsNumberKeyword(); + } + + if (v3ClientTypeString === "boolean") { + return j.tsBooleanKeyword(); + } + return j.tsStringKeyword(); }; From a7a9ab70638a2a0e2f015fe8c53a2be86d19146c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 00:32:25 -0800 Subject: [PATCH 14/31] Add type creation for Date/Uint8Array --- src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts index 99fbe05d7..4e80d8655 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -17,5 +17,9 @@ export const getTypeRefForString = ( return j.tsBooleanKeyword(); } + if (["Date", "Uint8Array"].includes(v3ClientTypeString)) { + return j.tsTypeReference(j.identifier(v3ClientTypeString)); + } + return j.tsStringKeyword(); }; From 411ce75cafd0966b379a71ee0b0213390daeb937 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:10:45 -0800 Subject: [PATCH 15/31] Process values for non native types in getV3ClientTypesCount --- .../v2-to-v3/ts-type/getV3ClientTypesCount.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts index 70776434b..7bf349f81 100644 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts +++ b/src/transforms/v2-to-v3/ts-type/getV3ClientTypesCount.ts @@ -3,6 +3,17 @@ import { Collection, JSCodeshift } from "jscodeshift"; import { CLIENT_TYPES_MAP } from "../config"; import { getV2ClientTypeNames, GetV2ClientTypeNamesOptions } from "./getV2ClientTypeNames"; +const arrayBracketRegex = /<([\w]+)>/g; +const recordBracketRegex = //g; +const nativeTypes = ["string", "number", "boolean", "Date", "Uint8Array"]; + +const getTypesFromString = (str: string): string[] => { + const arraryMatches = [...str.matchAll(arrayBracketRegex)].map((match) => match[1]); + const recordMatches = [...str.matchAll(recordBracketRegex)].map((match) => match[1]); + + return [...arraryMatches, ...recordMatches]; +}; + export const getV3ClientTypesCount = ( j: JSCodeshift, source: Collection, @@ -11,9 +22,14 @@ export const getV3ClientTypesCount = ( const { v2ClientName } = options; const v2ClientTypeNames = getV2ClientTypeNames(j, source, options); - const v3ClientUnavailableTypes = Object.keys(CLIENT_TYPES_MAP[v2ClientName]); + const clientTypesMap = CLIENT_TYPES_MAP[v2ClientName]; + const v3ClientUnavailableTypes = Object.keys(clientTypesMap); - return v2ClientTypeNames.filter( - (v2ClientTypeName) => !v3ClientUnavailableTypes.includes(v2ClientTypeName) - ).length; + return v2ClientTypeNames.filter((v2ClientTypeName) => { + if (!v3ClientUnavailableTypes.includes(v2ClientTypeName)) { + return true; + } + const typesFromString = getTypesFromString(clientTypesMap[v2ClientTypeName]); + return typesFromString.some((type) => !nativeTypes.includes(type)); + }).length; }; From bd83efd71b256782400bd93a45eea66f8df72a60 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:14:30 -0800 Subject: [PATCH 16/31] Remove comments past variables in api-redundant-type --- .../api-redundant-type/global-import.input.ts | 52 +++++++++---------- .../global-import.output.ts | 52 +++++++++---------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts index afa7e5b2f..2554a568a 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.input.ts @@ -1,47 +1,47 @@ import AWS from "aws-sdk"; // Native types -const stringType: AWS.S3.AccountId = "string"; // string -const booleanType: AWS.S3.BucketKeyEnabled = true; // boolean -const numberType: AWS.S3.ContentLength = 123; // number +const stringType: AWS.S3.AccountId = "string"; +const booleanType: AWS.S3.BucketKeyEnabled = true; +const numberType: AWS.S3.ContentLength = 123; // Date -const dateType: AWS.S3.CreationDate = new Date(); // Date +const dateType: AWS.S3.CreationDate = new Date(); // Uint8Array const blobType: AWS.RDSDataService._Blob = new Uint8Array(); // Arrays -const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; // string[] -const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; // boolean[] -const numberArray: AWS.RDSDataService.LongArray = [123, 456]; // number[] -const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; // Uint8Array[] -const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; // ChecksumAlgorithm[] -const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Bucket[] +const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; +const numberArray: AWS.RDSDataService.LongArray = [123, 456]; +const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; // Maps -const stringMap: AWS.S3.Metadata = { key: "value" }; // Record -const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; // Record -const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; // Record -const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Record +const stringMap: AWS.S3.Metadata = { key: "value" }; +const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; // Nested arrays -const arrayNestedTwice: AWS.SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; // number[][] -const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; // number[][][] +const arrayNestedTwice: AWS.SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; const arrayNestedFour: AWS.SageMakerGeospatial.LinearRingsList = [ [[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]] -]; // number[][][][] +]; // Nested maps -const mapNestedTwice: AWS.LexModelsV2.ConditionMap = { key: stringMap }; // Record> -const mapNestedTwiceStruct: AWS.APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; // Record> +const mapNestedTwice: AWS.LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: AWS.APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; // Nested arrays and maps -const mapOfArrays: AWS.NetworkManager.FilterMap = { key: ["value"] }; // Record -const mapOfMapOfArrays: AWS.SecurityLake.AllDimensionsMap = { key: mapOfArrays }; // Record> -const mapOfArrayOfMaps: AWS.DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; // Record[]> -const mapOfArrayOfArrays: AWS.APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; // Record -const arrayOfMaps: AWS.SSM.InventoryItemEntryList = [stringMap]; // Record[] -const arrayOfMapOfArrays: AWS.SSM.TargetMaps = [mapOfArrays]; // Record[] -const arrayOfMapOfMapOfArrays: AWS.SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; // Record>[] \ No newline at end of file +const mapOfArrays: AWS.NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: AWS.SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: AWS.DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: AWS.APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: AWS.SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: AWS.SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: AWS.SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index 67d02b3b4..f7095859c 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -3,47 +3,47 @@ import AWS_DynamoDB from "@aws-sdk/client-dynamodb"; import AWS_S3 from "@aws-sdk/client-s3"; // Native types -const stringType: string = "string"; // string -const booleanType: boolean = true; // boolean -const numberType: number = 123; // number +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; // Date -const dateType: Date = new Date(); // Date +const dateType: Date = new Date(); // Uint8Array const blobType: Uint8Array = new Uint8Array(); // Arrays -const stringArray: string[] = ["string1", "string2"]; // string[] -const booleanArray: boolean[] = [true, false]; // boolean[] -const numberArray: number[] = [123, 456]; // number[] -const blobArray: Uint8Array[] = [new Uint8Array()]; // Uint8Array[] -const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; // ChecksumAlgorithm[] -const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Bucket[] +const stringArray: string[] = ["string1", "string2"]; +const booleanArray: boolean[] = [true, false]; +const numberArray: number[] = [123, 456]; +const blobArray: Uint8Array[] = [new Uint8Array()]; +const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; +const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; // Maps -const stringMap: Record = { key: "value" }; // Record -const booleanMap: Record = { key: true }; // Record -const numberMap: Record = { key: 123 }; // Record -const structureMap: Record = { key: { apiKeyRequired: true } }; // Record +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; // Nested arrays -const arrayNestedTwice: number[][] = [[1, 2], [3, 4]]; // number[][] -const arrayNestedThrice: number[][][] = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; // number[][][] +const arrayNestedTwice: number[][] = [[1, 2], [3, 4]]; +const arrayNestedThrice: number[][][] = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; const arrayNestedFour: number[][][][] = [ [[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]] -]; // number[][][][] +]; // Nested maps -const mapNestedTwice: Record> = { key: stringMap }; // Record> -const mapNestedTwiceStruct: Record> = { key: structureMap }; // Record> +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; // Nested arrays and maps -const mapOfArrays: Record = { key: ["value"] }; // Record -const mapOfMapOfArrays: Record> = { key: mapOfArrays }; // Record>> -const mapOfArrayOfMaps: Record[]> = { key: [{ key: { S:"A" }}] }; // Record[]> -const mapOfArrayOfArrays: Record = { key: [[1], [2]] }; // Record -const arrayOfMaps: Record[] = [stringMap]; // Record[] -const arrayOfMapOfArrays: Record[] = [mapOfArrays]; // Record[] -const arrayOfMapOfMapOfArrays: Record>[] = [mapOfMapOfArrays]; // Record>[] \ No newline at end of file +const mapOfArrays: Record = { key: ["value"] }; +const mapOfMapOfArrays: Record> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record[]> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record = { key: [[1], [2]] }; +const arrayOfMaps: Record[] = [stringMap]; +const arrayOfMapOfArrays: Record[] = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Record>[] = [mapOfMapOfArrays]; \ No newline at end of file From 1ac580d189a8ea6d4c8b2bdd9d075388aed0b982 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:17:28 -0800 Subject: [PATCH 17/31] Use Array instead of brackets --- .../global-import.output.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts index f7095859c..625095368 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts @@ -14,12 +14,12 @@ const dateType: Date = new Date(); const blobType: Uint8Array = new Uint8Array(); // Arrays -const stringArray: string[] = ["string1", "string2"]; -const booleanArray: boolean[] = [true, false]; -const numberArray: number[] = [123, 456]; -const blobArray: Uint8Array[] = [new Uint8Array()]; -const enumArray: AWS_S3.ChecksumAlgorithm[] = ["CRC32"]; -const structureArray: AWS_S3.Bucket[] = [{ Name: "bucketName" }]; +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; // Maps const stringMap: Record = { key: "value" }; @@ -28,9 +28,9 @@ const numberMap: Record = { key: 123 }; const structureMap: Record = { key: { apiKeyRequired: true } }; // Nested arrays -const arrayNestedTwice: number[][] = [[1, 2], [3, 4]]; -const arrayNestedThrice: number[][][] = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; -const arrayNestedFour: number[][][][] = [ +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ [[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]] ]; @@ -40,10 +40,10 @@ const mapNestedTwice: Record> = { key: stringMap const mapNestedTwiceStruct: Record> = { key: structureMap }; // Nested arrays and maps -const mapOfArrays: Record = { key: ["value"] }; -const mapOfMapOfArrays: Record> = { key: mapOfArrays }; -const mapOfArrayOfMaps: Record[]> = { key: [{ key: { S:"A" }}] }; -const mapOfArrayOfArrays: Record = { key: [[1], [2]] }; -const arrayOfMaps: Record[] = [stringMap]; -const arrayOfMapOfArrays: Record[] = [mapOfArrays]; -const arrayOfMapOfMapOfArrays: Record>[] = [mapOfMapOfArrays]; \ No newline at end of file +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From c0d768bc5be9de8f20e809cfc0fc307c0d844d9a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:33:09 -0800 Subject: [PATCH 18/31] Add support for array type --- .../v2-to-v3/ts-type/getTypeRefForString.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts index 4e80d8655..9576db090 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -1,5 +1,8 @@ import { JSCodeshift, TSType } from "jscodeshift"; +const arrayRegex = /^Array<(.*)>$/; +const recordRegex = /^Record$/; + export const getTypeRefForString = ( j: JSCodeshift, v3ClientDefaultLocalName: string, @@ -21,5 +24,16 @@ export const getTypeRefForString = ( return j.tsTypeReference(j.identifier(v3ClientTypeString)); } + if (v3ClientTypeString.startsWith("Array<")) { + const type = arrayRegex.exec(v3ClientTypeString)![1]; + const typeArgument = getTypeRefForString(j, v3ClientDefaultLocalName, type); + return j.tsTypeReference.from({ + typeName: j.identifier("Array"), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + typeParameters: j.tsTypeParameterInstantiation([typeArgument]), + }); + } + return j.tsStringKeyword(); }; From 46ff6ae3243eaae9620d322400483021b7a5ef0d Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:36:48 -0800 Subject: [PATCH 19/31] Return identifier with v3clientDefaultLocalName --- src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts index 9576db090..7d394517b 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -35,5 +35,5 @@ export const getTypeRefForString = ( }); } - return j.tsStringKeyword(); + return j.tsTypeReference(j.identifier([v3ClientDefaultLocalName, v3ClientTypeString].join("."))); }; From 915ce224bf30cf214c11c95ca8d127f65d7dea6c Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:37:53 -0800 Subject: [PATCH 20/31] Add support for Record --- .../v2-to-v3/ts-type/getTypeRefForString.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts index 7d394517b..428c82293 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeRefForString.ts @@ -35,5 +35,16 @@ export const getTypeRefForString = ( }); } + if (v3ClientTypeString.startsWith("Record<")) { + const type = recordRegex.exec(v3ClientTypeString)![1]; + const typeArgument = getTypeRefForString(j, v3ClientDefaultLocalName, type); + return j.tsTypeReference.from({ + typeName: j.identifier("Record"), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + typeParameters: j.tsTypeParameterInstantiation([j.tsStringKeyword(), typeArgument]), + }); + } + return j.tsTypeReference(j.identifier([v3ClientDefaultLocalName, v3ClientTypeString].join("."))); }; From 270f88413ef6592125656fc44b54c1b556384f0f Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:39:00 -0800 Subject: [PATCH 21/31] Undo changes in transformer.spec.ts --- src/transforms/v2-to-v3/transformer.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transforms/v2-to-v3/transformer.spec.ts b/src/transforms/v2-to-v3/transformer.spec.ts index 5d614230d..8703e5ed9 100644 --- a/src/transforms/v2-to-v3/transformer.spec.ts +++ b/src/transforms/v2-to-v3/transformer.spec.ts @@ -35,7 +35,7 @@ describe("v2-to-v3", () => { return { input, outputCode }; }; - describe.each(["api-redundant-type"])("%s", (subDir) => { + describe.each(fixtureSubDirs)("%s", (subDir) => { const subDirPath = join(fixtureDir, subDir); it.concurrent.each(getTestFileMetadata(subDirPath))( `transforms: %s.%s`, From c55da5bc2a68a12cb46619ddb95e325d130b7b10 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 08:35:11 -0800 Subject: [PATCH 22/31] yarn changeset --- .changeset/angry-apricots-push.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/angry-apricots-push.md diff --git a/.changeset/angry-apricots-push.md b/.changeset/angry-apricots-push.md new file mode 100644 index 000000000..763343ef5 --- /dev/null +++ b/.changeset/angry-apricots-push.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": minor +--- + +Support type definitions which are not available in v3 From fc3c0a461f95caf403f31f52b45151520cece833 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 08:44:18 -0800 Subject: [PATCH 23/31] Add test api-redundant-type/service-import --- .../service-import.input.ts | 56 +++++++++++++++++++ .../service-import.output.ts | 49 ++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.input.ts new file mode 100644 index 000000000..8057c594f --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.input.ts @@ -0,0 +1,56 @@ +import { APIGateway } from "aws-sdk"; +import { DynamoDB } from "aws-sdk"; +import { IoTFleetWise } from "aws-sdk"; +import { LexModelsV2 } from "aws-sdk"; +import { NetworkManager } from "aws-sdk"; +import { RDSDataService } from "aws-sdk"; +import { S3 } from "aws-sdk"; +import { SageMakerGeospatial } from "aws-sdk"; +import { SecurityLake } from "aws-sdk"; +import { SSM } from "aws-sdk"; + +// Native types +const stringType: S3.AccountId = "string"; +const booleanType: S3.BucketKeyEnabled = true; +const numberType: S3.ContentLength = 123; + +// Date +const dateType: S3.CreationDate = new Date(); + +// Uint8Array +const blobType: RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: RDSDataService.BooleanArray = [true, false]; +const numberArray: RDSDataService.LongArray = [123, 456]; +const blobArray: IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: S3.Metadata = { key: "value" }; +const booleanMap: APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.output.ts new file mode 100644 index 000000000..625095368 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.output.ts @@ -0,0 +1,49 @@ +import AWS_APIGateway from "@aws-sdk/client-api-gateway"; +import AWS_DynamoDB from "@aws-sdk/client-dynamodb"; +import AWS_S3 from "@aws-sdk/client-s3"; + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From 6c471fb200f8c6b4c3c48d3dc339e0b1f58b94ac Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 08:47:26 -0800 Subject: [PATCH 24/31] Add test api-redundant-type/service-import-deep --- .../service-import-deep.input.ts | 56 +++++++++++++++++++ .../service-import-deep.output.ts | 49 ++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.input.ts new file mode 100644 index 000000000..9d6adcf2b --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.input.ts @@ -0,0 +1,56 @@ +import APIGateway from "aws-sdk/clients/apigateway"; +import DynamoDB from "aws-sdk/clients/dynamodb"; +import IoTFleetWise from "aws-sdk/clients/iotfleetwise"; +import LexModelsV2 from "aws-sdk/clients/lexmodelsv2"; +import NetworkManager from "aws-sdk/clients/networkmanager"; +import RDSDataService from "aws-sdk/clients/rdsdataservice"; +import S3 from "aws-sdk/clients/s3"; +import SageMakerGeospatial from "aws-sdk/clients/sagemakergeospatial"; +import SecurityLake from "aws-sdk/clients/securitylake"; +import SSM from "aws-sdk/clients/ssm"; + +// Native types +const stringType: S3.AccountId = "string"; +const booleanType: S3.BucketKeyEnabled = true; +const numberType: S3.ContentLength = 123; + +// Date +const dateType: S3.CreationDate = new Date(); + +// Uint8Array +const blobType: RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: RDSDataService.BooleanArray = [true, false]; +const numberArray: RDSDataService.LongArray = [123, 456]; +const blobArray: IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: S3.Metadata = { key: "value" }; +const booleanMap: APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.output.ts new file mode 100644 index 000000000..625095368 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.output.ts @@ -0,0 +1,49 @@ +import AWS_APIGateway from "@aws-sdk/client-api-gateway"; +import AWS_DynamoDB from "@aws-sdk/client-dynamodb"; +import AWS_S3 from "@aws-sdk/client-s3"; + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From 09715d0be17aa7f8f2157e51dd2b99d37a9ce4d5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 08:49:43 -0800 Subject: [PATCH 25/31] Add test api-redundant-type/global-require --- .../global-require.input.ts | 47 +++++++++++++++++++ .../global-require.output.ts | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.input.ts new file mode 100644 index 000000000..ad5abc288 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.input.ts @@ -0,0 +1,47 @@ +const AWS = require("aws-sdk"); + +// Native types +const stringType: AWS.S3.AccountId = "string"; +const booleanType: AWS.S3.BucketKeyEnabled = true; +const numberType: AWS.S3.ContentLength = 123; + +// Date +const dateType: AWS.S3.CreationDate = new Date(); + +// Uint8Array +const blobType: AWS.RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; +const numberArray: AWS.RDSDataService.LongArray = [123, 456]; +const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: AWS.S3.Metadata = { key: "value" }; +const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: AWS.SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: AWS.SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: AWS.LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: AWS.APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: AWS.NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: AWS.SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: AWS.DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: AWS.APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: AWS.SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: AWS.SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: AWS.SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.output.ts new file mode 100644 index 000000000..d0c734eb9 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-require.output.ts @@ -0,0 +1,47 @@ +const AWS_APIGateway = require("@aws-sdk/client-api-gateway"), AWS_DynamoDB = require("@aws-sdk/client-dynamodb"), AWS_S3 = require("@aws-sdk/client-s3"); + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From 3898aa808a135f84f7461739de311f7185712c1a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:47:34 -0800 Subject: [PATCH 26/31] Add test api-redundant-type/service-require --- .../service-require.input.ts | 56 +++++++++++++++++++ .../service-require.output.ts | 49 ++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.input.ts new file mode 100644 index 000000000..dd60fd5b1 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.input.ts @@ -0,0 +1,56 @@ +const { APIGateway } = require("aws-sdk"); +const { DynamoDB } = require("aws-sdk"); +const { IoTFleetWise } = require("aws-sdk"); +const { LexModelsV2 } = require("aws-sdk"); +const { NetworkManager } = require("aws-sdk"); +const { RDSDataService } = require("aws-sdk"); +const { S3 } = require("aws-sdk"); +const { SageMakerGeospatial } = require("aws-sdk"); +const { SecurityLake } = require("aws-sdk"); +const { SSM } = require("aws-sdk"); + +// Native types +const stringType: S3.AccountId = "string"; +const booleanType: S3.BucketKeyEnabled = true; +const numberType: S3.ContentLength = 123; + +// Date +const dateType: S3.CreationDate = new Date(); + +// Uint8Array +const blobType: RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: RDSDataService.BooleanArray = [true, false]; +const numberArray: RDSDataService.LongArray = [123, 456]; +const blobArray: IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: S3.Metadata = { key: "value" }; +const booleanMap: APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.output.ts new file mode 100644 index 000000000..fa587af71 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require.output.ts @@ -0,0 +1,49 @@ +const AWS_APIGateway = require("@aws-sdk/client-api-gateway"); +const AWS_DynamoDB = require("@aws-sdk/client-dynamodb"); +const AWS_S3 = require("@aws-sdk/client-s3"); + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From 7270676f520fbca14451fb5d81df2e66814797af Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:51:51 -0800 Subject: [PATCH 27/31] Add test api-redundant-type/service-require-deep --- .../service-require-deep.input.ts | 56 +++++++++++++++++++ .../service-require-deep.output.ts | 49 ++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.input.ts new file mode 100644 index 000000000..77ad20869 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.input.ts @@ -0,0 +1,56 @@ +const APIGateway = require("aws-sdk/clients/apigateway"); +const DynamoDB = require("aws-sdk/clients/dynamodb"); +const IoTFleetWise = require("aws-sdk/clients/iotfleetwise"); +const LexModelsV2 = require("aws-sdk/clients/lexmodelsv2"); +const NetworkManager = require("aws-sdk/clients/networkmanager"); +const RDSDataService = require("aws-sdk/clients/rdsdataservice"); +const S3 = require("aws-sdk/clients/s3"); +const SageMakerGeospatial = require("aws-sdk/clients/sagemakergeospatial"); +const SecurityLake = require("aws-sdk/clients/securitylake"); +const SSM = require("aws-sdk/clients/ssm"); + +// Native types +const stringType: S3.AccountId = "string"; +const booleanType: S3.BucketKeyEnabled = true; +const numberType: S3.ContentLength = 123; + +// Date +const dateType: S3.CreationDate = new Date(); + +// Uint8Array +const blobType: RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: RDSDataService.BooleanArray = [true, false]; +const numberArray: RDSDataService.LongArray = [123, 456]; +const blobArray: IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: S3.Metadata = { key: "value" }; +const booleanMap: APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.output.ts new file mode 100644 index 000000000..fa587af71 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-require-deep.output.ts @@ -0,0 +1,49 @@ +const AWS_APIGateway = require("@aws-sdk/client-api-gateway"); +const AWS_DynamoDB = require("@aws-sdk/client-dynamodb"); +const AWS_S3 = require("@aws-sdk/client-s3"); + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From 68a0bf70e59151d3afef24e40ba62c365e07f3d5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:54:37 -0800 Subject: [PATCH 28/31] Add test api-redundant-type/global-import-equals --- .../global-import-equals.input.ts | 47 ++++++++++++++++++ .../global-import-equals.output.ts | 49 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.input.ts new file mode 100644 index 000000000..4bc089649 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.input.ts @@ -0,0 +1,47 @@ +import AWS = require("aws-sdk"); + +// Native types +const stringType: AWS.S3.AccountId = "string"; +const booleanType: AWS.S3.BucketKeyEnabled = true; +const numberType: AWS.S3.ContentLength = 123; + +// Date +const dateType: AWS.S3.CreationDate = new Date(); + +// Uint8Array +const blobType: AWS.RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: AWS.S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: AWS.RDSDataService.BooleanArray = [true, false]; +const numberArray: AWS.RDSDataService.LongArray = [123, 456]; +const blobArray: AWS.IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: AWS.S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: AWS.S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: AWS.S3.Metadata = { key: "value" }; +const booleanMap: AWS.APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: AWS.SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: AWS.APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: AWS.SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: AWS.SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: AWS.SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: AWS.LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: AWS.APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: AWS.NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: AWS.SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: AWS.DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: AWS.APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: AWS.SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: AWS.SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: AWS.SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.output.ts new file mode 100644 index 000000000..4f3389cab --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import-equals.output.ts @@ -0,0 +1,49 @@ +import AWS_APIGateway = require("@aws-sdk/client-api-gateway"); +import AWS_DynamoDB = require("@aws-sdk/client-dynamodb"); +import AWS_S3 = require("@aws-sdk/client-s3"); + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From e4d2b13e5e4ae272538b32f4464a5a09c17ed6f6 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:58:45 -0800 Subject: [PATCH 29/31] Add default import equals only if v3 client types are present --- .../v2-to-v3/modules/addV3ClientImportEquals.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts b/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts index aacf56028..5fb199c44 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts @@ -1,5 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; +import { getV3ClientTypesCount } from "../ts-type"; import { addV3ClientDefaultImportEquals } from "./addV3ClientDefaultImportEquals"; import { addV3ClientNamedImportEquals } from "./addV3ClientNamedImportEquals"; import { getClientTSTypeRefCount } from "./getClientTSTypeRefCount"; @@ -11,12 +12,16 @@ export const addV3ClientImportEquals = ( source: Collection, options: V3ClientModulesOptions ): void => { - addV3ClientDefaultImportEquals(j, source, options); + const v3ClientTypesCount = getV3ClientTypesCount(j, source, options); + const newExpressionCount = getNewExpressionCount(j, source, options); + const clientTSTypeRefCount = getClientTSTypeRefCount(j, source, options); - if ( - getNewExpressionCount(j, source, options) > 0 || - getClientTSTypeRefCount(j, source, options) > 0 - ) { + if (v3ClientTypesCount > 0) { + addV3ClientDefaultImportEquals(j, source, options); + } + + if (newExpressionCount || clientTSTypeRefCount) { + addV3ClientDefaultImportEquals(j, source, options); addV3ClientNamedImportEquals(j, source, options); } }; From 51e7ce763fe0075c389c5f22868b69e573a44f7a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 12:01:03 -0800 Subject: [PATCH 30/31] Add test api-redundant-type/service-import-equals --- .../service-import-equals.input.ts | 56 +++++++++++++++++++ .../service-import-equals.output.ts | 49 ++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.input.ts create mode 100644 src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.output.ts diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.input.ts new file mode 100644 index 000000000..12649ff5b --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.input.ts @@ -0,0 +1,56 @@ +import APIGateway = require("aws-sdk/clients/apigateway"); +import DynamoDB = require("aws-sdk/clients/dynamodb"); +import IoTFleetWise = require("aws-sdk/clients/iotfleetwise"); +import LexModelsV2 = require("aws-sdk/clients/lexmodelsv2"); +import NetworkManager = require("aws-sdk/clients/networkmanager"); +import RDSDataService = require("aws-sdk/clients/rdsdataservice"); +import S3 = require("aws-sdk/clients/s3"); +import SageMakerGeospatial = require("aws-sdk/clients/sagemakergeospatial"); +import SecurityLake = require("aws-sdk/clients/securitylake"); +import SSM = require("aws-sdk/clients/ssm"); + +// Native types +const stringType: S3.AccountId = "string"; +const booleanType: S3.BucketKeyEnabled = true; +const numberType: S3.ContentLength = 123; + +// Date +const dateType: S3.CreationDate = new Date(); + +// Uint8Array +const blobType: RDSDataService._Blob = new Uint8Array(); + +// Arrays +const stringArray: S3.AllowedHeaders = ["string1", "string2"]; +const booleanArray: RDSDataService.BooleanArray = [true, false]; +const numberArray: RDSDataService.LongArray = [123, 456]; +const blobArray: IoTFleetWise.NetworkFilesList = [new Uint8Array()]; +const enumArray: S3.ChecksumAlgorithmList = ["CRC32"]; +const structureArray: S3.Buckets = [{ Name: "bucketName" }]; + +// Maps +const stringMap: S3.Metadata = { key: "value" }; +const booleanMap: APIGateway.MapOfStringToBoolean = { key: true }; +const numberMap: SSM.AssociationStatusAggregatedCount = { key: 123 }; +const structureMap: APIGateway.MapOfMethodSnapshot = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: SageMakerGeospatial.LinearRing = [[1, 2], [3, 4]]; +const arrayNestedThrice: SageMakerGeospatial.LinearRings = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: SageMakerGeospatial.LinearRingsList = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: LexModelsV2.ConditionMap = { key: stringMap }; +const mapNestedTwiceStruct: APIGateway.PathToMapOfMethodSnapshot = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: NetworkManager.FilterMap = { key: ["value"] }; +const mapOfMapOfArrays: SecurityLake.AllDimensionsMap = { key: mapOfArrays }; +const mapOfArrayOfMaps: DynamoDB.BatchGetResponseMap = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: APIGateway.MapOfKeyUsages = { key: [[1], [2]] }; +const arrayOfMaps: SSM.InventoryItemEntryList = [stringMap]; +const arrayOfMapOfArrays: SSM.TargetMaps = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: SecurityLake.RegionSourceTypesAccountsList = [mapOfMapOfArrays]; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.output.ts new file mode 100644 index 000000000..4f3389cab --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-equals.output.ts @@ -0,0 +1,49 @@ +import AWS_APIGateway = require("@aws-sdk/client-api-gateway"); +import AWS_DynamoDB = require("@aws-sdk/client-dynamodb"); +import AWS_S3 = require("@aws-sdk/client-s3"); + +// Native types +const stringType: string = "string"; +const booleanType: boolean = true; +const numberType: number = 123; + +// Date +const dateType: Date = new Date(); + +// Uint8Array +const blobType: Uint8Array = new Uint8Array(); + +// Arrays +const stringArray: Array = ["string1", "string2"]; +const booleanArray: Array = [true, false]; +const numberArray: Array = [123, 456]; +const blobArray: Array = [new Uint8Array()]; +const enumArray: Array = ["CRC32"]; +const structureArray: Array = [{ Name: "bucketName" }]; + +// Maps +const stringMap: Record = { key: "value" }; +const booleanMap: Record = { key: true }; +const numberMap: Record = { key: 123 }; +const structureMap: Record = { key: { apiKeyRequired: true } }; + +// Nested arrays +const arrayNestedTwice: Array> = [[1, 2], [3, 4]]; +const arrayNestedThrice: Array>> = [[[1, 2], [3, 4]], [[4, 5], [6, 7]]]; +const arrayNestedFour: Array>>> = [ + [[[1], [2]], [[3], [4]]], + [[[5], [6]], [[7], [8]]] +]; + +// Nested maps +const mapNestedTwice: Record> = { key: stringMap }; +const mapNestedTwiceStruct: Record> = { key: structureMap }; + +// Nested arrays and maps +const mapOfArrays: Record> = { key: ["value"] }; +const mapOfMapOfArrays: Record>> = { key: mapOfArrays }; +const mapOfArrayOfMaps: Record>> = { key: [{ key: { S:"A" }}] }; +const mapOfArrayOfArrays: Record>> = { key: [[1], [2]] }; +const arrayOfMaps: Array> = [stringMap]; +const arrayOfMapOfArrays: Array>> = [mapOfArrays]; +const arrayOfMapOfMapOfArrays: Array>>> = [mapOfMapOfArrays]; \ No newline at end of file From b88da6a22deac7764a132bfe4c3e11e9fa668af4 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Jan 2023 12:06:26 -0800 Subject: [PATCH 31/31] Simplify code for addV3Client functions --- .../v2-to-v3/modules/addV3ClientImportEquals.ts | 2 +- .../v2-to-v3/modules/addV3ClientImports.ts | 14 ++++---------- .../v2-to-v3/modules/addV3ClientRequires.ts | 15 ++++----------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts b/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts index 5fb199c44..baba7f499 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientImportEquals.ts @@ -20,7 +20,7 @@ export const addV3ClientImportEquals = ( addV3ClientDefaultImportEquals(j, source, options); } - if (newExpressionCount || clientTSTypeRefCount) { + if (newExpressionCount > 0 || clientTSTypeRefCount > 0) { addV3ClientDefaultImportEquals(j, source, options); addV3ClientNamedImportEquals(j, source, options); } diff --git a/src/transforms/v2-to-v3/modules/addV3ClientImports.ts b/src/transforms/v2-to-v3/modules/addV3ClientImports.ts index 26cbb3299..8381e0a1c 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientImports.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientImports.ts @@ -12,22 +12,16 @@ export const addV3ClientImports = ( source: Collection, options: V3ClientModulesOptions ): void => { - const { v2ClientLocalName, v2ClientName, v2GlobalName } = options; - const v3ClientTypesCount = getV3ClientTypesCount(j, source, { - v2ClientLocalName, - v2ClientName, - v2GlobalName, - }); + const v3ClientTypesCount = getV3ClientTypesCount(j, source, options); + const newExpressionCount = getNewExpressionCount(j, source, options); + const clientTSTypeRefCount = getClientTSTypeRefCount(j, source, options); // Add default import for types, if needed. if (v3ClientTypesCount > 0) { addV3ClientDefaultImport(j, source, options); } - if ( - getNewExpressionCount(j, source, options) > 0 || - getClientTSTypeRefCount(j, source, options) > 0 - ) { + if (newExpressionCount > 0 || clientTSTypeRefCount > 0) { addV3ClientNamedImport(j, source, options); } }; diff --git a/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts b/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts index 1817da265..de70a58ff 100644 --- a/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts +++ b/src/transforms/v2-to-v3/modules/addV3ClientRequires.ts @@ -12,22 +12,15 @@ export const addV3ClientRequires = ( source: Collection, options: V3ClientModulesOptions ): void => { - const { v2ClientLocalName, v2ClientName, v2GlobalName } = options; - const v3ClientTypesCount = getV3ClientTypesCount(j, source, { - v2ClientLocalName, - v2ClientName, - v2GlobalName, - }); + const v3ClientTypesCount = getV3ClientTypesCount(j, source, options); + const newExpressionCount = getNewExpressionCount(j, source, options); + const clientTSTypeRefCount = getClientTSTypeRefCount(j, source, options); - // Add default require for types, if needed. if (v3ClientTypesCount > 0) { addV3ClientDefaultRequire(j, source, options); } - if ( - getNewExpressionCount(j, source, options) > 0 || - getClientTSTypeRefCount(j, source, options) > 0 - ) { + if (newExpressionCount > 0 || clientTSTypeRefCount > 0) { addV3ClientNamedRequire(j, source, options); } };