Skip to content

Commit 4bbfb9d

Browse files
committed
IoHelper
1 parent 7ef9d82 commit 4bbfb9d

File tree

10 files changed

+34
-33
lines changed

10 files changed

+34
-33
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './action-aware';
1+
export * from './io-helper';
22
export * from './level-priority';
33
export * from './message-maker';
44
export * from './types';

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/action-aware.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/io-helper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ export type ActionLessMessage<T> = Omit<IoMessage<T>, 'action'>;
88
export type ActionLessRequest<T, U> = Omit<IoRequest<T, U>, 'action'>;
99

1010
/**
11-
* Helper type for IoHosts that are action aware
11+
* Helper for IO messaging.
12+
*
13+
* Wraps a client provided IoHost and provides additional features & services to toolkit internal classes.
1214
*/
13-
export interface ActionAwareIoHost extends IIoHost {
15+
export interface IoHelper extends IIoHost {
1416
action: ToolkitAction;
1517
notify<T>(msg: ActionLessMessage<T>): Promise<void>;
1618
requestResponse<T, U>(msg: ActionLessRequest<T, U>): Promise<U>;
1719
}
1820

1921
/**
20-
* An IoHost wrapper that adds the given action to an actionless message before
21-
* sending the message to the given IoHost
22+
* Wraps an IoHost and creates an IoHelper from it
2223
*/
23-
export function withAction(ioHost: IIoHost, action: ToolkitAction): ActionAwareIoHost {
24+
export function asIoHelper(ioHost: IIoHost, action: ToolkitAction): IoHelper {
2425
return {
2526
action,
2627
notify: async <T>(msg: Omit<IoMessage<T>, 'action'>) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IoMessageCode, IoMessageLevel } from '../io-message';
2-
import type { ActionLessMessage, ActionLessRequest } from './action-aware';
2+
import type { ActionLessMessage, ActionLessRequest } from './io-helper';
33

44
/**
55
* Information for each IO Message Code.

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type * as cxapi from '@aws-cdk/cx-api';
33
import type { ToolkitServices } from '../../../toolkit/private';
44
import { type Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk';
55
import { CODES } from '../../io/private';
6-
import type { ActionAwareIoHost } from '../../shared-private';
6+
import type { IoHelper } from '../../shared-private';
77
import { ToolkitError } from '../../shared-public';
88
import type { ICloudAssemblySource } from '../types';
99

@@ -43,7 +43,7 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource {
4343
private canLookup: boolean;
4444
private context: Context;
4545
private contextFile: string;
46-
private ioHost: ActionAwareIoHost;
46+
private ioHost: IoHelper;
4747

4848
constructor(private readonly source: ICloudAssemblySource, private readonly props: ContextAwareCloudAssemblyProps) {
4949
this.canLookup = props.lookups ?? true;

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailable
99
import { splitBySize } from '../../../private/util';
1010
import type { ToolkitServices } from '../../../toolkit/private';
1111
import { CODES } from '../../io/private';
12-
import type { ActionAwareIoHost } from '../../shared-private';
12+
import type { IoHelper } from '../../shared-private';
1313
import { ToolkitError } from '../../shared-public';
1414
import type { AppSynthOptions, LoadAssemblyOptions } from '../source-builder';
1515

@@ -130,7 +130,7 @@ export async function withContext<T>(
130130
*
131131
* @param assembly the assembly to check
132132
*/
133-
export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly, ioHost: ActionAwareIoHost): Promise<void> {
133+
export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly, ioHost: IoHelper): Promise<void> {
134134
const tree = loadTree(assembly);
135135
const frameworkDoesNotSupportContextOverflow = some(tree, node => {
136136
const fqn = node.constructInfo?.fqn;
@@ -149,7 +149,7 @@ export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly,
149149
/**
150150
* Safely create an assembly from a cloud assembly directory
151151
*/
152-
export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionAwareIoHost, loadOptions: LoadAssemblyOptions = {}) {
152+
export async function assemblyFromDirectory(assemblyDir: string, ioHost: IoHelper, loadOptions: LoadAssemblyOptions = {}) {
153153
try {
154154
const assembly = new cxapi.CloudAssembly(assemblyDir, {
155155
skipVersionCheck: !(loadOptions.checkVersion ?? true),

packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { inspect } from 'util';
33
import type { Logger } from '@smithy/types';
44
import { CODES } from './codes';
55
import { replacerBufferWithInfo } from '../../../private/util';
6-
import type { ActionAwareIoHost } from '../../shared-private';
6+
import type { IoHelper } from '../../shared-private';
77

88
/**
99
* An SDK logging trace.
@@ -27,7 +27,7 @@ export interface SdkTrace {
2727
readonly content: any;
2828
}
2929

30-
export function asSdkLogger(ioHost: ActionAwareIoHost): Logger {
30+
export function asSdkLogger(ioHost: IoHelper): Logger {
3131
return new class implements Logger {
3232
// This is too much detail for our logs
3333
public trace(..._content: any[]) {

packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { format } from 'util';
22
import { CODES } from './codes';
33
import { formatTime } from '../../../private/util';
4-
import type { ActionAwareIoHost } from '../../shared-private';
4+
import type { IoHelper } from '../../shared-private';
55

66
/**
77
* Helper class to measure the time of code.
@@ -37,7 +37,7 @@ export class Timer {
3737
* Ends the current timer as a specified timing and notifies the IoHost.
3838
* @returns the elapsed time
3939
*/
40-
public async endAs(ioHost: ActionAwareIoHost, type: 'synth' | 'deploy' | 'rollback' | 'destroy' | 'bootstrap') {
40+
public async endAs(ioHost: IoHelper, type: 'synth' | 'deploy' | 'rollback' | 'destroy' | 'bootstrap') {
4141
const duration = this.end();
4242
await ioHost.notify(timerMessage(type, duration));
4343
return duration;

packages/@aws-cdk/toolkit-lib/lib/toolkit/private/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import type { SdkProvider } from '../../api/aws-cdk';
33
import type { ICloudAssemblySource } from '../../api/cloud-assembly';
44
import { CachedCloudAssemblySource, StackAssembly } from '../../api/cloud-assembly/private';
5-
import type { ActionAwareIoHost } from '../../api/shared-private';
5+
import type { IoHelper } from '../../api/shared-private';
66

77
/**
88
* Helper struct to pass internal services around.
99
*/
1010
export interface ToolkitServices {
1111
sdkProvider: SdkProvider;
12-
ioHost: ActionAwareIoHost;
12+
ioHost: IoHelper;
1313
}
1414

1515
/**

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import type { StackAssembly } from '../api/cloud-assembly/private';
2626
import { ALL_STACKS, CloudAssemblySourceBuilder, IdentityCloudAssemblySource } from '../api/cloud-assembly/private';
2727
import type { IIoHost, IoMessageLevel } from '../api/io';
2828
import { Timer, CODES, asSdkLogger, withoutColor, withoutEmojis, withTrimmedWhitespace } from '../api/io/private';
29-
import type { ActionAwareIoHost } from '../api/shared-private';
30-
import { withAction } from '../api/shared-private';
29+
import type { IoHelper } from '../api/shared-private';
30+
import { asIoHelper } from '../api/shared-private';
3131
import type { ToolkitAction } from '../api/shared-public';
3232
import { ToolkitError } from '../api/shared-public';
3333
import { obscureTemplate, serializeStructure, validateSnsTopicArn, formatTime, formatErrorMessage } from '../private/util';
@@ -130,7 +130,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
130130
if (!this._sdkProvider) {
131131
this._sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
132132
...this.props.sdkConfig,
133-
logger: asSdkLogger(withAction(this.ioHost, action)),
133+
logger: asSdkLogger(asIoHelper(this.ioHost, action)),
134134
});
135135
}
136136

@@ -142,7 +142,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
142142
*/
143143
protected override async sourceBuilderServices(): Promise<ToolkitServices> {
144144
return {
145-
ioHost: withAction(this.ioHost, 'assembly'),
145+
ioHost: asIoHelper(this.ioHost, 'assembly'),
146146
sdkProvider: await this.sdkProvider('assembly'),
147147
};
148148
}
@@ -151,7 +151,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
151151
* Bootstrap Action
152152
*/
153153
public async bootstrap(environments: BootstrapEnvironments, options: BootstrapOptions): Promise<void> {
154-
const ioHost = withAction(this.ioHost, 'bootstrap');
154+
const ioHost = asIoHelper(this.ioHost, 'bootstrap');
155155
const bootstrapEnvironments = await environments.getEnvironments();
156156
const source = options.source ?? BootstrapSource.default();
157157
const parameters = options.parameters;
@@ -197,7 +197,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
197197
* Synth Action
198198
*/
199199
public async synth(cx: ICloudAssemblySource, options: SynthOptions = {}): Promise<ICloudAssemblySource> {
200-
const ioHost = withAction(this.ioHost, 'synth');
200+
const ioHost = asIoHelper(this.ioHost, 'synth');
201201
const synthTimer = Timer.start();
202202
const assembly = await assemblyFromSource(cx);
203203
const stacks = assembly.selectStacksV2(options.stacks ?? ALL_STACKS);
@@ -242,7 +242,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
242242
* List selected stacks and their dependencies
243243
*/
244244
public async list(cx: ICloudAssemblySource, options: ListOptions = {}): Promise<StackDetails[]> {
245-
const ioHost = withAction(this.ioHost, 'list');
245+
const ioHost = asIoHelper(this.ioHost, 'list');
246246
const synthTimer = Timer.start();
247247
const assembly = await assemblyFromSource(cx);
248248
const stackCollection = await assembly.selectStacksV2(options.stacks ?? ALL_STACKS);
@@ -269,7 +269,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
269269
* Helper to allow deploy being called as part of the watch action.
270270
*/
271271
private async _deploy(assembly: StackAssembly, action: 'deploy' | 'watch', options: ExtendedDeployOptions = {}) {
272-
const ioHost = withAction(this.ioHost, action);
272+
const ioHost = asIoHelper(this.ioHost, action);
273273
const synthTimer = Timer.start();
274274
const stackCollection = assembly.selectStacksV2(options.stacks ?? ALL_STACKS);
275275
await this.validateStacksMetadata(stackCollection, ioHost);
@@ -571,7 +571,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
571571
*/
572572
public async watch(cx: ICloudAssemblySource, options: WatchOptions): Promise<void> {
573573
const assembly = await assemblyFromSource(cx, false);
574-
const ioHost = withAction(this.ioHost, 'watch');
574+
const ioHost = asIoHelper(this.ioHost, 'watch');
575575
const rootDir = options.watchDir ?? process.cwd();
576576

577577
if (options.include === undefined && options.exclude === undefined) {
@@ -694,7 +694,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
694694
* Helper to allow rollback being called as part of the deploy or watch action.
695695
*/
696696
private async _rollback(assembly: StackAssembly, action: 'rollback' | 'deploy' | 'watch', options: RollbackOptions): Promise<void> {
697-
const ioHost = withAction(this.ioHost, action);
697+
const ioHost = asIoHelper(this.ioHost, action);
698698
const synthTimer = Timer.start();
699699
const stacks = assembly.selectStacksV2(options.stacks);
700700
await this.validateStacksMetadata(stacks, ioHost);
@@ -752,7 +752,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
752752
* Helper to allow destroy being called as part of the deploy action.
753753
*/
754754
private async _destroy(assembly: StackAssembly, action: 'deploy' | 'destroy', options: DestroyOptions): Promise<void> {
755-
const ioHost = withAction(this.ioHost, action);
755+
const ioHost = asIoHelper(this.ioHost, action);
756756
const synthTimer = Timer.start();
757757
// The stacks will have been ordered for deployment, so reverse them for deletion.
758758
const stacks = await assembly.selectStacksV2(options.stacks).reversed();
@@ -794,7 +794,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
794794
/**
795795
* Validate the stacks for errors and warnings according to the CLI's current settings
796796
*/
797-
private async validateStacksMetadata(stacks: StackCollection, ioHost: ActionAwareIoHost) {
797+
private async validateStacksMetadata(stacks: StackCollection, ioHost: IoHelper) {
798798
const builder = (level: IoMessageLevel) => {
799799
switch (level) {
800800
case 'error': return CODES.CDK_ASSEMBLY_E9999;

packages/aws-cdk/lib/api/resource-import/importer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as cxapi from '@aws-cdk/cx-api';
55
import * as chalk from 'chalk';
66
import * as fs from 'fs-extra';
77
import * as promptly from 'promptly';
8-
import { ActionAwareIoHost, withAction } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private';
8+
import { IoHelper, asIoHelper } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private';
99
import { error, info, warn } from '../../cli/messages';
1010
import type { IIoHost, IoMessaging } from '../../toolkit/cli-io-host';
1111
import { ToolkitError } from '../../toolkit/error';
@@ -103,15 +103,15 @@ export class ResourceImporter {
103103

104104
private readonly stack: cxapi.CloudFormationStackArtifact;
105105
private readonly cfn: Deployments;
106-
private readonly ioHost: ActionAwareIoHost;
106+
private readonly ioHost: IoHelper;
107107

108108
constructor(
109109
stack: cxapi.CloudFormationStackArtifact,
110110
props: ResourceImporterProps,
111111
) {
112112
this.stack = stack;
113113
this.cfn = props.deployments;
114-
this.ioHost = withAction(props.ioHost, props.action as any);
114+
this.ioHost = asIoHelper(props.ioHost, props.action as any);
115115
}
116116

117117
/**

0 commit comments

Comments
 (0)