Skip to content

Commit 2eef537

Browse files
committed
more type fixes
1 parent c344d89 commit 2eef537

1 file changed

Lines changed: 19 additions & 30 deletions

File tree

packages/deploymentUtils/src/changesets/checkDestructiveChanges.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
import {
22
CloudFormationClient,
33
DescribeChangeSetCommand,
4-
DescribeChangeSetCommandOutput
4+
DescribeChangeSetCommandOutput,
5+
Change as CloudFormationChange
56
} from "@aws-sdk/client-cloudformation"
67

78
export type ChangeRequiringAttention = {
8-
logicalId: string;
9-
physicalId: string;
10-
resourceType: string;
11-
reason: string;
9+
logicalId: string;
10+
physicalId: string;
11+
resourceType: string;
12+
reason: string;
1213
}
1314

1415
export type AllowedDestructiveChange = {
15-
LogicalResourceId: string;
16-
PhysicalResourceId: string;
17-
ResourceType: string;
18-
ExpiryDate: string | Date;
19-
AllowedReason: string;
20-
}
21-
22-
type RawChange = {
23-
ResourceChange?: {
24-
LogicalResourceId?: string;
25-
PhysicalResourceId?: string;
26-
ResourceType?: string;
27-
Replacement?: unknown;
28-
Action?: string;
29-
} | null;
16+
LogicalResourceId: string;
17+
PhysicalResourceId: string;
18+
ResourceType: string;
19+
ExpiryDate: string | Date;
20+
AllowedReason: string;
3021
}
3122

3223
const requiresReplacement = (replacement: unknown): boolean => {
@@ -38,10 +29,6 @@ const requiresReplacement = (replacement: unknown): boolean => {
3829
return normalized === "True" || normalized === "Conditional"
3930
}
4031

41-
type ChangeSet = {
42-
Changes?: unknown;
43-
}
44-
4532
const toDate = (value: Date | string | number | undefined | null): Date | undefined => {
4633
if (value === undefined || value === null) {
4734
return undefined
@@ -51,16 +38,18 @@ const toDate = (value: Date | string | number | undefined | null): Date | undefi
5138
return Number.isNaN(date.getTime()) ? undefined : date
5239
}
5340

54-
export function checkDestructiveChanges(changeSet: ChangeSet | undefined | null): Array<ChangeRequiringAttention> {
41+
export function checkDestructiveChanges(
42+
changeSet: DescribeChangeSetCommandOutput | undefined | null
43+
): Array<ChangeRequiringAttention> {
5544
if (!changeSet || typeof changeSet !== "object") {
5645
throw new Error("A change set object must be provided")
5746
}
5847

59-
const {Changes} = changeSet as ChangeSet
60-
const changes = Array.isArray(Changes) ? (Changes as Array<RawChange>) : []
48+
const {Changes} = changeSet
49+
const changes = Array.isArray(Changes) ? (Changes as Array<CloudFormationChange>) : []
6150

6251
return changes
63-
.map((change: RawChange) => {
52+
.map((change: CloudFormationChange) => {
6453
const resourceChange = change?.ResourceChange
6554
if (!resourceChange) {
6655
return undefined
@@ -108,8 +97,8 @@ export async function checkDestructiveChangeSet(
10897
const remainingChanges = destructiveChanges.filter(change => {
10998
const waiver = allowedChanges.find(allowed =>
11099
allowed.LogicalResourceId === change.logicalId &&
111-
allowed.PhysicalResourceId === change.physicalId &&
112-
allowed.ResourceType === change.resourceType
100+
allowed.PhysicalResourceId === change.physicalId &&
101+
allowed.ResourceType === change.resourceType
113102
)
114103

115104
if (!waiver || !creationTime) {

0 commit comments

Comments
 (0)