Skip to content

Commit 1d18054

Browse files
committed
chore(cli): code org
1 parent ff953f2 commit 1d18054

File tree

11 files changed

+80
-83
lines changed

11 files changed

+80
-83
lines changed

packages/@aws-cdk/tmp-toolkit-helpers/src/util/objects.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,35 @@ export function splitBySize(data: any, maxSizeBytes: number): [any, any] {
215215
];
216216
}
217217
}
218+
219+
type Exclude = { [key: string]: Exclude | true };
220+
221+
/**
222+
* This function transforms all keys (recursively) in the provided `val` object.
223+
*
224+
* @param val The object whose keys need to be transformed.
225+
* @param transform The function that will be applied to each key.
226+
* @param exclude The keys that will not be transformed and copied to output directly
227+
* @returns A new object with the same values as `val`, but with all keys transformed according to `transform`.
228+
*/
229+
export function transformObjectKeys(val: any, transform: (str: string) => string, exclude: Exclude = {}): any {
230+
if (val == null || typeof val !== 'object') {
231+
return val;
232+
}
233+
if (Array.isArray(val)) {
234+
// For arrays we just pass parent's exclude object directly
235+
// since it makes no sense to specify different exclude options for each array element
236+
return val.map((input: any) => transformObjectKeys(input, transform, exclude));
237+
}
238+
const ret: { [k: string]: any } = {};
239+
for (const [k, v] of Object.entries(val)) {
240+
const childExclude = exclude[k];
241+
if (childExclude === true) {
242+
// we don't transform this object if the key is specified in exclude
243+
ret[transform(k)] = v;
244+
} else {
245+
ret[transform(k)] = transformObjectKeys(v, transform, childExclude);
246+
}
247+
}
248+
return ret;
249+
}

packages/@aws-cdk/tmp-toolkit-helpers/src/util/string-manipulation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ function roundPercentage(num: number): number {
3535
function millisecondsToSeconds(num: number): number {
3636
return num / 1000;
3737
}
38+
39+
/**
40+
* This function lower cases the first character of the string provided.
41+
*/
42+
export function lowerCaseFirstCharacter(str: string): string {
43+
return str.length > 0 ? `${str[0].toLowerCase()}${str.slice(1)}` : str;
44+
}

packages/aws-cdk/lib/api/deployments/hotswap-deployments.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-templ
1717
import { isHotswappableAppSyncChange } from '../hotswap/appsync-mapping-templates';
1818
import { isHotswappableCodeBuildProjectChange } from '../hotswap/code-build-projects';
1919
import type {
20-
ChangeHotswapResult,
20+
HotswapChange,
2121
HotswapOperation,
22-
NonHotswappableChange,
22+
RejectedChange,
2323
HotswapPropertyOverrides,
2424
ClassifiedResourceChanges,
2525
HotswapResult,
@@ -48,7 +48,7 @@ type HotswapDetector = (
4848
change: ResourceChange,
4949
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
5050
hotswapPropertyOverrides: HotswapPropertyOverrides,
51-
) => Promise<ChangeHotswapResult>;
51+
) => Promise<HotswapChange[]>;
5252

5353
type HotswapMode = 'hotswap-only' | 'fall-back';
5454

@@ -72,7 +72,7 @@ const RESOURCE_DETECTORS: { [key: string]: HotswapDetector } = {
7272
logicalId: string,
7373
change: ResourceChange,
7474
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
75-
): Promise<ChangeHotswapResult> => {
75+
): Promise<HotswapChange[]> => {
7676
// If the policy is for a S3BucketDeploymentChange, we can ignore the change
7777
if (await skipChangeForS3DeployCustomResourcePolicy(logicalId, change, evaluateCfnTemplate)) {
7878
return [];
@@ -209,9 +209,9 @@ async function classifyResourceChanges(
209209
): Promise<ClassifiedResourceChanges> {
210210
const resourceDifferences = getStackResourceDifferences(stackChanges);
211211

212-
const promises: Array<() => Promise<ChangeHotswapResult>> = [];
212+
const promises: Array<() => Promise<HotswapChange[]>> = [];
213213
const hotswappableResources = new Array<HotswapOperation>();
214-
const nonHotswappableResources = new Array<NonHotswappableChange>();
214+
const nonHotswappableResources = new Array<RejectedChange>();
215215
for (const logicalId of Object.keys(stackChanges.outputs.changes)) {
216216
nonHotswappableResources.push({
217217
hotswappable: false,
@@ -267,7 +267,7 @@ async function classifyResourceChanges(
267267
}
268268

269269
// resolve all detector results
270-
const changesDetectionResults: Array<ChangeHotswapResult> = [];
270+
const changesDetectionResults: Array<HotswapChange[]> = [];
271271
for (const detectorResultPromises of promises) {
272272
// Constant set of promises per resource
273273
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
@@ -425,7 +425,7 @@ function makeRenameDifference(
425425
function isCandidateForHotswapping(
426426
change: cfn_diff.ResourceDifference,
427427
logicalId: string,
428-
): HotswapOperation | NonHotswappableChange | ResourceChange {
428+
): HotswapOperation | RejectedChange | ResourceChange {
429429
// a resource has been removed OR a resource has been added; we can't short-circuit that change
430430
if (!change.oldValue) {
431431
return {
@@ -530,7 +530,7 @@ function formatWaiterErrorResult(result: WaiterResult) {
530530

531531
async function logNonHotswappableChanges(
532532
ioSpan: IMessageSpan<any>,
533-
nonHotswappableChanges: NonHotswappableChange[],
533+
nonHotswappableChanges: RejectedChange[],
534534
hotswapMode: HotswapMode,
535535
): Promise<void> {
536536
if (nonHotswappableChanges.length === 0) {

packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import type {
33
GetSchemaCreationStatusCommandInput,
44
} from '@aws-sdk/client-appsync';
55
import {
6-
type ChangeHotswapResult,
6+
type HotswapChange,
77
classifyChanges,
8-
lowerCaseFirstCharacter,
9-
transformObjectKeys,
108
} from './common';
119
import type { ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
1210
import { ToolkitError } from '../../toolkit/error';
11+
import { lowerCaseFirstCharacter, transformObjectKeys } from '../../util';
1312
import type { SDK } from '../aws-auth';
1413

1514
import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
@@ -18,7 +17,7 @@ export async function isHotswappableAppSyncChange(
1817
logicalId: string,
1918
change: ResourceChange,
2019
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
21-
): Promise<ChangeHotswapResult> {
20+
): Promise<HotswapChange[]> {
2221
const isResolver = change.newValue.Type === 'AWS::AppSync::Resolver';
2322
const isFunction = change.newValue.Type === 'AWS::AppSync::FunctionConfiguration';
2423
const isGraphQLSchema = change.newValue.Type === 'AWS::AppSync::GraphQLSchema';
@@ -27,7 +26,7 @@ export async function isHotswappableAppSyncChange(
2726
return [];
2827
}
2928

30-
const ret: ChangeHotswapResult = [];
29+
const ret: HotswapChange[] = [];
3130

3231
const classifiedChanges = classifyChanges(change, [
3332
'RequestMappingTemplate',

packages/aws-cdk/lib/api/hotswap/code-build-projects.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import type { UpdateProjectCommandInput } from '@aws-sdk/client-codebuild';
22
import {
3-
type ChangeHotswapResult,
3+
type HotswapChange,
44
classifyChanges,
5-
lowerCaseFirstCharacter,
6-
transformObjectKeys,
75
} from './common';
86
import type { ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
7+
import { lowerCaseFirstCharacter, transformObjectKeys } from '../../util';
98
import type { SDK } from '../aws-auth';
109
import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
1110

1211
export async function isHotswappableCodeBuildProjectChange(
1312
logicalId: string,
1413
change: ResourceChange,
1514
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
16-
): Promise<ChangeHotswapResult> {
15+
): Promise<HotswapChange[]> {
1716
if (change.newValue.Type !== 'AWS::CodeBuild::Project') {
1817
return [];
1918
}
2019

21-
const ret: ChangeHotswapResult = [];
20+
const ret: HotswapChange[] = [];
2221

2322
const classifiedChanges = classifyChanges(change, ['Source', 'Environment', 'SourceVersion']);
2423
classifiedChanges.reportNonHotswappablePropertyChanges(ret);

packages/aws-cdk/lib/api/hotswap/common.ts

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface HotswapOperation {
5454
readonly apply: (sdk: SDK) => Promise<void>;
5555
}
5656

57-
export interface NonHotswappableChange {
57+
export interface RejectedChange {
5858
readonly hotswappable: false;
5959
readonly resourceType: string;
6060
readonly rejectedChanges: Array<string>;
@@ -77,11 +77,11 @@ export interface NonHotswappableChange {
7777
readonly hotswapOnlyVisible?: boolean;
7878
}
7979

80-
export type ChangeHotswapResult = Array<HotswapOperation | NonHotswappableChange>;
80+
export type HotswapChange = HotswapOperation | RejectedChange;
8181

8282
export interface ClassifiedResourceChanges {
8383
hotswapOperations: HotswapOperation[];
84-
nonHotswappableChanges: NonHotswappableChange[];
84+
nonHotswappableChanges: RejectedChange[];
8585
}
8686

8787
export enum HotswapMode {
@@ -101,8 +101,6 @@ export enum HotswapMode {
101101
FULL_DEPLOYMENT = 'full-deployment',
102102
}
103103

104-
type Exclude = { [key: string]: Exclude | true };
105-
106104
/**
107105
* Represents configuration property overrides for hotswap deployments
108106
*/
@@ -149,54 +147,17 @@ export class EcsHotswapProperties {
149147
}
150148
}
151149

152-
/**
153-
* This function transforms all keys (recursively) in the provided `val` object.
154-
*
155-
* @param val The object whose keys need to be transformed.
156-
* @param transform The function that will be applied to each key.
157-
* @param exclude The keys that will not be transformed and copied to output directly
158-
* @returns A new object with the same values as `val`, but with all keys transformed according to `transform`.
159-
*/
160-
export function transformObjectKeys(val: any, transform: (str: string) => string, exclude: Exclude = {}): any {
161-
if (val == null || typeof val !== 'object') {
162-
return val;
163-
}
164-
if (Array.isArray(val)) {
165-
// For arrays we just pass parent's exclude object directly
166-
// since it makes no sense to specify different exclude options for each array element
167-
return val.map((input: any) => transformObjectKeys(input, transform, exclude));
168-
}
169-
const ret: { [k: string]: any } = {};
170-
for (const [k, v] of Object.entries(val)) {
171-
const childExclude = exclude[k];
172-
if (childExclude === true) {
173-
// we don't transform this object if the key is specified in exclude
174-
ret[transform(k)] = v;
175-
} else {
176-
ret[transform(k)] = transformObjectKeys(v, transform, childExclude);
177-
}
178-
}
179-
return ret;
180-
}
181-
182-
/**
183-
* This function lower cases the first character of the string provided.
184-
*/
185-
export function lowerCaseFirstCharacter(str: string): string {
186-
return str.length > 0 ? `${str[0].toLowerCase()}${str.slice(1)}` : str;
187-
}
188-
189150
type PropDiffs = Record<string, PropertyDifference<any>>;
190151

191-
export class ClassifiedChanges {
152+
class ClassifiedChanges {
192153
public constructor(
193154
public readonly change: ResourceChange,
194155
public readonly hotswappableProps: PropDiffs,
195156
public readonly nonHotswappableProps: PropDiffs,
196157
) {
197158
}
198159

199-
public reportNonHotswappablePropertyChanges(ret: ChangeHotswapResult): void {
160+
public reportNonHotswappablePropertyChanges(ret: HotswapChange[]): void {
200161
const nonHotswappablePropNames = Object.keys(this.nonHotswappableProps);
201162
if (nonHotswappablePropNames.length > 0) {
202163
const tagOnlyChange = nonHotswappablePropNames.length === 1 && nonHotswappablePropNames[0] === 'Tags';
@@ -234,7 +195,7 @@ export function classifyChanges(xs: ResourceChange, hotswappablePropNames: strin
234195
}
235196

236197
export function reportNonHotswappableChange(
237-
ret: ChangeHotswapResult,
198+
ret: HotswapChange[],
238199
change: ResourceChange,
239200
reason: NonHotswappableReason,
240201
nonHotswappableProps?: PropDiffs,
@@ -256,7 +217,7 @@ export function reportNonHotswappableResource(
256217
change: ResourceChange,
257218
reason: NonHotswappableReason,
258219
description?: string,
259-
): ChangeHotswapResult {
220+
): HotswapChange[] {
260221
return [
261222
{
262223
hotswappable: false,

packages/aws-cdk/lib/api/hotswap/ecs-services.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type {
22
HotswapPropertyOverrides,
3-
ChangeHotswapResult,
3+
HotswapChange,
44
} from './common';
55
import {
6-
classifyChanges, lowerCaseFirstCharacter,
6+
classifyChanges,
77
reportNonHotswappableChange,
8-
transformObjectKeys,
98
} from './common';
109
import { NonHotswappableReason, type ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
10+
import { lowerCaseFirstCharacter, transformObjectKeys } from '../../util';
1111
import type { SDK } from '../aws-auth';
1212
import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
1313

@@ -18,13 +18,13 @@ export async function isHotswappableEcsServiceChange(
1818
change: ResourceChange,
1919
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
2020
hotswapPropertyOverrides: HotswapPropertyOverrides,
21-
): Promise<ChangeHotswapResult> {
21+
): Promise<HotswapChange[]> {
2222
// the only resource change we can evaluate here is an ECS TaskDefinition
2323
if (change.newValue.Type !== 'AWS::ECS::TaskDefinition') {
2424
return [];
2525
}
2626

27-
const ret: ChangeHotswapResult = [];
27+
const ret: HotswapChange[] = [];
2828

2929
// We only allow a change in the ContainerDefinitions of the TaskDefinition for now -
3030
// it contains the image and environment variables, so seems like a safe bet for now.

packages/aws-cdk/lib/api/hotswap/lambda-functions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Writable } from 'stream';
22
import type { PropertyDifference } from '@aws-cdk/cloudformation-diff';
33
import type { FunctionConfiguration, UpdateFunctionConfigurationCommandInput } from '@aws-sdk/client-lambda';
4-
import type { ChangeHotswapResult } from './common';
4+
import type { HotswapChange } from './common';
55
import { classifyChanges } from './common';
66
import type { AffectedResource, ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
77
import { ToolkitError } from '../../toolkit/error';
@@ -17,7 +17,7 @@ export async function isHotswappableLambdaFunctionChange(
1717
logicalId: string,
1818
change: ResourceChange,
1919
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
20-
): Promise<ChangeHotswapResult> {
20+
): Promise<HotswapChange[]> {
2121
// if the change is for a Lambda Version, we just ignore it
2222
// we will publish a new version when we get to hotswapping the actual Function this Version points to
2323
// (Versions can't be changed in CloudFormation anyway, they're immutable)
@@ -35,7 +35,7 @@ export async function isHotswappableLambdaFunctionChange(
3535
return [];
3636
}
3737

38-
const ret: ChangeHotswapResult = [];
38+
const ret: HotswapChange[] = [];
3939
const classifiedChanges = classifyChanges(change, ['Code', 'Environment', 'Description']);
4040
classifiedChanges.reportNonHotswappablePropertyChanges(ret);
4141

@@ -145,8 +145,8 @@ export async function isHotswappableLambdaFunctionChange(
145145
/**
146146
* Determines which changes to this Alias are hotswappable or not
147147
*/
148-
function classifyAliasChanges(change: ResourceChange): ChangeHotswapResult {
149-
const ret: ChangeHotswapResult = [];
148+
function classifyAliasChanges(change: ResourceChange): HotswapChange[] {
149+
const ret: HotswapChange[] = [];
150150
const classifiedChanges = classifyChanges(change, ['FunctionVersion']);
151151
classifiedChanges.reportNonHotswappablePropertyChanges(ret);
152152

packages/aws-cdk/lib/api/hotswap/s3-bucket-deployments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ChangeHotswapResult } from './common';
1+
import type { HotswapChange } from './common';
22
import type { ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
33
import type { SDK } from '../aws-auth';
44
import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
@@ -15,10 +15,10 @@ export async function isHotswappableS3BucketDeploymentChange(
1515
logicalId: string,
1616
change: ResourceChange,
1717
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
18-
): Promise<ChangeHotswapResult> {
18+
): Promise<HotswapChange[]> {
1919
// In old-style synthesis, the policy used by the lambda to copy assets Ref's the assets directly,
2020
// meaning that the changes made to the Policy are artifacts that can be safely ignored
21-
const ret: ChangeHotswapResult = [];
21+
const ret: HotswapChange[] = [];
2222

2323
if (change.newValue.Type !== CDK_BUCKET_DEPLOYMENT_CFN_TYPE) {
2424
return [];

packages/aws-cdk/lib/api/hotswap/stepfunctions-state-machines.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ChangeHotswapResult, classifyChanges } from './common';
1+
import { type HotswapChange, classifyChanges } from './common';
22
import type { ResourceChange } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/payloads/hotswap';
33
import type { SDK } from '../aws-auth';
44
import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
@@ -7,11 +7,11 @@ export async function isHotswappableStateMachineChange(
77
logicalId: string,
88
change: ResourceChange,
99
evaluateCfnTemplate: EvaluateCloudFormationTemplate,
10-
): Promise<ChangeHotswapResult> {
10+
): Promise<HotswapChange[]> {
1111
if (change.newValue.Type !== 'AWS::StepFunctions::StateMachine') {
1212
return [];
1313
}
14-
const ret: ChangeHotswapResult = [];
14+
const ret: HotswapChange[] = [];
1515
const classifiedChanges = classifyChanges(change, ['DefinitionString']);
1616
classifiedChanges.reportNonHotswappablePropertyChanges(ret);
1717

0 commit comments

Comments
 (0)