Skip to content

Commit ac605d5

Browse files
authored
Remove reference to non-existent types from CLIENT_TYPES_MAP records (#318)
1 parent b98c59a commit ac605d5

File tree

6 files changed

+44
-25
lines changed

6 files changed

+44
-25
lines changed

.changeset/fresh-foxes-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Remove reference to non-existent types from CLIENT_TYPES_MAP records

scripts/generateClientTypesMap/getClientTypesMapWithKeysRemovedFromValues.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
import { hasReferenceToKeysInValues } from "./hasReferenceToKeysInValues";
1+
import { hasKeyReferenceInClientTypesMap } from "./hasKeyReferenceInClientTypesMap";
2+
import { hasKeyReferenceInValue } from "./hasKeyReferenceinValue";
23

34
/**
45
* Checks if any of the values have reference to key, and replaces them recursively.
56
*/
67
export const getClientTypesMapWithKeysRemovedFromValues = (
78
clientTypesMap: Record<string, string>
89
) => {
9-
if (!hasReferenceToKeysInValues(clientTypesMap)) {
10+
if (!hasKeyReferenceInClientTypesMap(clientTypesMap)) {
1011
return clientTypesMap;
1112
}
1213

1314
const newClientTypeMap = {};
1415
const keys = Object.keys(clientTypesMap);
1516

1617
for (const [key, value] of Object.entries(clientTypesMap)) {
17-
const refs = keys.filter((key) => value.includes(`<${key}>`));
18+
const refs = keys.filter((key) => hasKeyReferenceInValue(key, value));
1819
if (refs.length === 0) {
1920
newClientTypeMap[key] = value;
2021
} else {
2122
newClientTypeMap[key] = refs.reduce(
22-
(acc, ref) => acc.replace(`<${ref}>`, `<${clientTypesMap[ref]}>`),
23+
(acc, ref) =>
24+
acc
25+
.replace(`Array<${ref}>`, `Array<${clientTypesMap[ref]}>`)
26+
.replace(`Record<string, ${ref}>`, `Record<string, ${clientTypesMap[ref]}>`),
2327
value
2428
);
2529
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { hasKeyReferenceInValue } from "./hasKeyReferenceinValue";
2+
3+
/**
4+
* Checks if any of the values in the clientTypesMap has a reference to any of the keys.
5+
*/
6+
export const hasKeyReferenceInClientTypesMap = (clientTypesMap: Record<string, string>) => {
7+
const keys = Object.keys(clientTypesMap);
8+
for (const value of Object.values(clientTypesMap)) {
9+
if (keys.some((key) => hasKeyReferenceInValue(key, value))) {
10+
// console.log({ keys, value });
11+
return true;
12+
}
13+
}
14+
return false;
15+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Returns true if value contains reference to key.
3+
*
4+
* Reference is defined as key name inside brackets in Array/Record type
5+
* i.e. `Array<key>` or `Record<string, key>` for `key`.
6+
*/
7+
export const hasKeyReferenceInValue = (key: string, value: string) =>
8+
value.includes(`Array<${key}>`) || value.includes(`Record<string, ${key}>`);

scripts/generateClientTypesMap/hasReferenceToKeysInValues.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/transforms/v2-to-v3/config/CLIENT_TYPES_MAP.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
568568
ComponentEvents: "Record<string, ComponentEvent>",
569569
ComponentList: "Array<Component>",
570570
ComponentName: "string",
571-
ComponentOverrides: "Record<string, ComponentOverridesValue>",
571+
ComponentOverrides: "Record<string, Record<string, string>>",
572572
ComponentOverridesValue: "Record<string, string>",
573573
ComponentProperties: "Record<string, ComponentProperty>",
574574
ComponentPropertyList: "Array<ComponentProperty>",
@@ -1228,7 +1228,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
12281228
ConfigurationEventTime: "Date",
12291229
CustomComponentName: "string",
12301230
CWEMonitorEnabled: "boolean",
1231-
DetectedWorkload: "Record<string, WorkloadMetaData>",
1231+
DetectedWorkload: "Record<string, Record<string, string>>",
12321232
EbsCause: "string",
12331233
EbsEvent: "string",
12341234
EbsRequestId: "string",
@@ -5835,7 +5835,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
58355835
Boolean: "boolean",
58365836
ByteValue: "number",
58375837
DatasourcePackageIngestDetails: "Record<string, DatasourcePackageIngestDetail>",
5838-
DatasourcePackageIngestHistory: "Record<string, LastIngestStateChangeDates>",
5838+
DatasourcePackageIngestHistory: "Record<string, Record<string, TimestampForCollection>>",
58395839
DatasourcePackageIngestStates: "Record<string, DatasourcePackageIngestState>",
58405840
DatasourcePackageList: "Array<DatasourcePackage>",
58415841
EmailAddress: "string",
@@ -14078,7 +14078,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
1407814078
RuntimeHintValuesList: "Array<RuntimeHintValue>",
1407914079
SensitiveNonEmptyString: "string",
1408014080
SessionId: "string",
14081-
SlotHintsIntentMap: "Record<string, SlotHintsSlotMap>",
14081+
SlotHintsIntentMap: "Record<string, Record<string, RuntimeHintDetails>>",
1408214082
SlotHintsSlotMap: "Record<string, RuntimeHintDetails>",
1408314083
Slots: "Record<string, Slot>",
1408414084
String: "string",
@@ -15502,8 +15502,8 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
1550215502
__mapOf__string: "Record<string, string>",
1550315503
__string: "string",
1550415504
__timestampUnix: "Date",
15505-
ConfigurationAliasesRequest: "Record<string, __mapOf__string>",
15506-
ConfigurationAliasesResponse: "Record<string, __mapOf__string>",
15505+
ConfigurationAliasesRequest: "Record<string, Record<string, string>>",
15506+
ConfigurationAliasesResponse: "Record<string, Record<string, string>>",
1550715507
HttpPackageConfigurations: "Array<HttpPackageConfiguration>",
1550815508
Integer: "number",
1550915509
MaxResults: "number",
@@ -21994,7 +21994,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
2199421994
AccessTypeList: "Array<AccessType>",
2199521995
AccountList: "Array<string>",
2199621996
AccountSourcesList: "Array<AccountSources>",
21997-
AllDimensionsMap: "Record<string, TwoDimensionsMap>",
21997+
AllDimensionsMap: "Record<string, Record<string, Array<string>>>",
2199821998
AutoEnableNewRegionConfigurationList: "Array<AutoEnableNewRegionConfiguration>",
2199921999
AwsAccountId: "string",
2200022000
AwsSourceTypeList: "Array<AwsLogSourceType>",
@@ -22013,7 +22013,7 @@ export const CLIENT_TYPES_MAP: Record<string, Record<string, string>> = {
2201322013
LogsStatusList: "Array<LogsStatus>",
2201422014
Long: "number",
2201522015
RegionSet: "Array<Region>",
22016-
RegionSourceTypesAccountsList: "Array<Record<string, TwoDimensionsMap>>",
22016+
RegionSourceTypesAccountsList: "Array<Record<string, Record<string, Array<string>>>>",
2201722017
RetentionSettingList: "Array<RetentionSetting>",
2201822018
RetentionSettingRetentionPeriodInteger: "number",
2201922019
RoleArn: "string",

0 commit comments

Comments
 (0)