Skip to content

Commit 0c21495

Browse files
authored
refactor(toolkit-lib): move message definitions to shared package (#220)
Move the message definitions to the shared package and make them public. This also required moving a bunch of type definitions to the shared package because they are used as payloads for the message types. In the CLI it's now possible to access those numbers and access their associated payload types in a type-checked way. A type-safe `switch` statement now looks like this: <img width="583" alt="image" src="https://github.com/user-attachments/assets/01c1cbf6-2e1a-4b8f-bd5c-180f72ff2f55" /> This change also makes the `data` field of an `IoMessage` required. The type of a message without payload is now `IoMessage<void>`: `data: void` is only inhabited by `data: undefined` which sort of tracks because `m.data === undefined` even if there is no payload (don't look too closely at the different behavior for `'data' in m` 😎 ). The type can no longer be `never` because a type like `{ data: never }` can not be inhabited by any values. We could also use `data: undefined`, *also* only admitting `undefined`, but `void` reads more clearly for its intent. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent e20f1a8 commit 0c21495

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+383
-324
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from './io-host';
22
export * from './io-message';
33
export * from './toolkit-action';
4+
export * from './payloads';
5+
export * from './messages';

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/io-message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface IoMessage<T> {
6262
/**
6363
* The data attached to the message.
6464
*/
65-
readonly data?: T;
65+
readonly data: T;
6666
}
6767

6868
/**

packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/messages.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type * as cxapi from '@aws-cdk/cx-api';
2-
import type { SdkTrace } from '../';
3-
import type { BootstrapEnvironmentProgress } from '../../../actions/bootstrap';
4-
import type { DeployConfirmationRequest, StackDeployProgress } from '../../../actions/deploy';
5-
import type { StackDestroyProgress } from '../../../actions/destroy';
6-
import type { StackDetailsPayload } from '../../../actions/list';
7-
import type { StackRollbackProgress } from '../../../actions/rollback';
8-
import type { FileWatchEvent, WatchSettings } from '../../../actions/watch';
9-
import type { AssemblyData, ConfirmationRequest, Duration, ErrorPayload, StackAndAssemblyData, SuccessfulDeployStackResult } from '../../../toolkit/types';
10-
import type { StackActivity, StackMonitoringControlEvent } from '../../aws-cdk';
11-
import type { MissingContext, UpdatedContext } from '../../cloud-assembly/context';
12-
import * as make from '../../shared-private';
2+
import type { BootstrapEnvironmentProgress } from './payloads/bootstrap-environment-progress';
3+
import type { MissingContext, UpdatedContext } from './payloads/context';
4+
import type { DeployConfirmationRequest, StackDeployProgress, SuccessfulDeployStackResult } from './payloads/deploy';
5+
import type { StackDestroyProgress } from './payloads/destroy';
6+
import type { StackDetailsPayload } from './payloads/list';
7+
import type { StackRollbackProgress } from './payloads/rollback';
8+
import type { SdkTrace } from './payloads/sdk-trace';
9+
import type { StackActivity, StackMonitoringControlEvent } from './payloads/stack-activity';
10+
import type { AssemblyData, ConfirmationRequest, Duration, ErrorPayload, StackAndAssemblyData } from './payloads/types';
11+
import type { FileWatchEvent, WatchSettings } from './payloads/watch';
12+
import * as make from './private';
1313

1414
/**
1515
* We have a rough system by which we assign message codes:
@@ -328,6 +328,10 @@ export const IO = {
328328
}),
329329

330330
// SDK codes
331+
CDK_SDK_I0000: make.trace({
332+
code: 'CDK_SDK_I0000',
333+
description: 'An SDK message.',
334+
}),
331335
CDK_SDK_I0100: make.trace<SdkTrace>({
332336
code: 'CDK_SDK_I0100',
333337
description: 'An SDK trace. SDK traces are emitted as traces to the IoHost, but contain the original SDK logging level.',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type * as cxapi from '@aws-cdk/cx-api';
2+
3+
export interface BootstrapEnvironmentProgress {
4+
/**
5+
* The total number of environments being deployed
6+
*/
7+
readonly total: number;
8+
/**
9+
* The count of the environment currently bootstrapped
10+
*
11+
* This is counting value, not an identifier.
12+
*/
13+
readonly current: number;
14+
/**
15+
* The environment that's currently being bootstrapped
16+
*/
17+
readonly environment: cxapi.Environment;
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { CloudFormationStackArtifact } from '@aws-cdk/cx-api';
2+
import type { PermissionChangeType } from './diff';
3+
import type { ConfirmationRequest } from './types';
4+
5+
export interface StackDeployProgress {
6+
/**
7+
* The total number of stacks being deployed
8+
*/
9+
readonly total: number;
10+
/**
11+
* The count of the stack currently attempted to be deployed
12+
*
13+
* This is counting value, not an identifier.
14+
*/
15+
readonly current: number;
16+
/**
17+
* The stack that's currently being deployed
18+
*/
19+
readonly stack: CloudFormationStackArtifact;
20+
}
21+
22+
/**
23+
* Payload for a yes/no confirmation in deploy. Includes information on
24+
* what kind of change is being made.
25+
*/
26+
export interface DeployConfirmationRequest extends ConfirmationRequest {
27+
/**
28+
* The type of change being made to the IAM permissions.
29+
*/
30+
readonly permissionChangeType: PermissionChangeType;
31+
}
32+
33+
export type DeployStackResult =
34+
| SuccessfulDeployStackResult
35+
| NeedRollbackFirstDeployStackResult
36+
| ReplacementRequiresRollbackStackResult
37+
;
38+
39+
/** Successfully deployed a stack */
40+
export interface SuccessfulDeployStackResult {
41+
readonly type: 'did-deploy-stack';
42+
readonly noOp: boolean;
43+
readonly outputs: { [name: string]: string };
44+
readonly stackArn: string;
45+
}
46+
47+
/** The stack is currently in a failpaused state, and needs to be rolled back before the deployment */
48+
export interface NeedRollbackFirstDeployStackResult {
49+
readonly type: 'failpaused-need-rollback-first';
50+
readonly reason: 'not-norollback' | 'replacement';
51+
readonly status: string;
52+
}
53+
54+
/** The upcoming change has a replacement, which requires deploying with --rollback */
55+
export interface ReplacementRequiresRollbackStackResult {
56+
readonly type: 'replacement-requires-rollback';
57+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { CloudFormationStackArtifact } from '@aws-cdk/cx-api';
2+
3+
export interface StackDestroyProgress {
4+
/**
5+
* The total number of stacks being destroyed
6+
*/
7+
readonly total: number;
8+
/**
9+
* The count of the stack currently attempted to be destroyed
10+
*
11+
* This is counting value, not an identifier.
12+
*/
13+
readonly current: number;
14+
/**
15+
* The stack that's currently being destroyed
16+
*/
17+
readonly stack: CloudFormationStackArtifact;
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Different types of permission related changes in a diff
3+
*/
4+
export enum PermissionChangeType {
5+
/**
6+
* No permission changes
7+
*/
8+
NONE = 'none',
9+
10+
/**
11+
* Permissions are broadening
12+
*/
13+
BROADENING = 'broadening',
14+
15+
/**
16+
* Permissions are changed but not broadening
17+
*/
18+
NON_BROADENING = 'non-broadening',
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export * from './bootstrap-environment-progress';
2+
export * from './deploy';
3+
export * from './destroy';
4+
export * from './list';
5+
export * from './sdk-trace';
6+
export * from './context';
7+
export * from './rollback';
8+
export * from './stack-activity';
9+
export * from './types';
10+
export * from './progress';
11+
export * from './watch';
12+
export * from './stack-details';
13+
export * from './diff';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { StackDetails } from './stack-details';
2+
3+
export interface StackDetailsPayload {
4+
stacks: StackDetails[];
5+
}

0 commit comments

Comments
 (0)