Skip to content
Closed

stuff #253

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,59 @@ export enum NonHotswappableReason {
NESTED_STACK_CREATION = 'nested-stack-creation',
}

export interface RejectionSubject {
/**
* The type of the rejection subject, e.g. Resource or Output
*/
readonly type: string;

/**
* The logical ID of the change that is not hotswappable
*/
readonly logicalId: string;
}

export interface ResourceSubject extends RejectionSubject {
/**
* A rejected resource
*/
readonly type: 'Resource';
/**
* The type of the rejected resource
*/
readonly resourceType: string;
/**
* The list of properties that are cause for the rejection
*/
readonly rejectedProperties?: string[];
}

export interface OutputSubject extends RejectionSubject {
/**
* A rejected output
*/
readonly type: 'Output';
}

/**
* A change that can not be hotswapped
*/
export interface NonHotswappableChange {
/**
* The subject of the change that was rejected
*/
readonly subject: ResourceSubject | OutputSubject;
/**
* Why was this change was deemed non-hotswappable
*/
readonly reason: NonHotswappableReason;
/**
* Tells the user exactly why this change was deemed non-hotswappable and what its logical ID is.
* If not specified, `displayReason` default to state that the properties listed in `rejectedChanges` are not hotswappable.
*/
readonly description: string;
}

/**
* Information about a hotswap deployment
*/
Expand All @@ -123,3 +176,31 @@ export interface HotswapDeployment {
*/
readonly mode: 'hotswap-only' | 'fall-back';
}

/**
* The result of an attempted hotswap deployment
*/
export interface HotswapResult {
/**
* The stack that was hotswapped
*/
readonly stack: cxapi.CloudFormationStackArtifact;
/**
* The mode the hotswap deployment was initiated with.
*/
readonly mode: 'hotswap-only' | 'fall-back';
/**
* Whether hotswapping happened or not.
*
* `false` indicates that the deployment could not be hotswapped and full deployment may be attempted as fallback.
*/
readonly hotswapped: boolean;
/**
* The changes that were deemed hotswappable
*/
readonly hotswappableChanges: HotswappableChange[];
/**
* The changes that were deemed not hotswappable
*/
readonly nonHotswappableChanges: NonHotswappableChange[];
}
32 changes: 32 additions & 0 deletions packages/@aws-cdk/tmp-toolkit-helpers/src/util/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,35 @@ export function splitBySize(data: any, maxSizeBytes: number): [any, any] {
];
}
}

type Exclude = { [key: string]: Exclude | true };

/**
* This function transforms all keys (recursively) in the provided `val` object.
*
* @param val The object whose keys need to be transformed.
* @param transform The function that will be applied to each key.
* @param exclude The keys that will not be transformed and copied to output directly
* @returns A new object with the same values as `val`, but with all keys transformed according to `transform`.
*/
export function transformObjectKeys(val: any, transform: (str: string) => string, exclude: Exclude = {}): any {
if (val == null || typeof val !== 'object') {
return val;
}
if (Array.isArray(val)) {
// For arrays we just pass parent's exclude object directly
// since it makes no sense to specify different exclude options for each array element
return val.map((input: any) => transformObjectKeys(input, transform, exclude));
}
const ret: { [k: string]: any } = {};
for (const [k, v] of Object.entries(val)) {
const childExclude = exclude[k];
if (childExclude === true) {
// we don't transform this object if the key is specified in exclude
ret[transform(k)] = v;
} else {
ret[transform(k)] = transformObjectKeys(v, transform, childExclude);
}
}
return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ function roundPercentage(num: number): number {
function millisecondsToSeconds(num: number): number {
return num / 1000;
}

/**
* This function lower cases the first character of the string provided.
*/
export function lowerCaseFirstCharacter(str: string): string {
return str.length > 0 ? `${str[0].toLowerCase()}${str.slice(1)}` : str;
}
Loading
Loading