Skip to content
Draft
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/jest": "^29.5.14",
"aws-sdk-client-mock": "4.1.0",
"aws-sdk-client-mock-jest": "4.1.0",
"@cdklabs/typewriter": "^0.0.12",
"@cdklabs/typewriter": "^0.0.14",
"jest": "^29.7.0",
"sinon": "^9.2.4",
"nock": "^13.5.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/mixins-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
"@aws-cdk/service-spec-types": "^0.0.193",
"@aws-cdk/spec2cdk": "0.0.0",
"@cdklabs/tskb": "^0.0.4",
"@cdklabs/typewriter": "^0.0.12",
"@cdklabs/typewriter": "^0.0.14",
"@types/jest": "^29.5.14",
"aws-cdk-lib": "0.0.0",
"constructs": "^10.0.0",
Expand Down
18 changes: 7 additions & 11 deletions packages/@aws-cdk/mixins-preview/scripts/spec2logs/builder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Resource, Service, SpecDatabase } from '@aws-cdk/service-spec-types';
import { naming, util } from '@aws-cdk/spec2cdk';
import { CDK_CORE, CONSTRUCTS } from '@aws-cdk/spec2cdk/lib/cdk/cdk';
import { CDK_CORE, CDK_INTERFACES, CONSTRUCTS } from '@aws-cdk/spec2cdk/lib/cdk/cdk';
import type { Method } from '@cdklabs/typewriter';
import { Module, ExternalModule, ClassType, Stability, Type, expr, stmt, ThingSymbol, $this, CallableProxy, NewExpression, $E } from '@cdklabs/typewriter';
import { CDK_AWS_LOGS, MIXINS_LOGS_DELIVERY, REF_INTERFACES } from './helpers';
import type { ServiceSubmoduleProps, SelectiveImport, LocatedModule } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
import { CDK_AWS_LOGS, MIXINS_LOGS_DELIVERY } from './helpers';
import type { ServiceSubmoduleProps, LocatedModule } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
import { BaseServiceSubmodule, relativeImportPath } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
import type { AddServiceProps, LibraryBuilderProps } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
import { LibraryBuilder } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
Expand Down Expand Up @@ -48,8 +48,6 @@ export class LogsDeliveryBuilder extends LibraryBuilder<LogsDeliveryBuilderServi
submodule.registerResource(`${resource.cloudFormationType}VendedLogs`, vendedLogsMixin.mixin);

vendedLogsMixin.build();

submodule.registerSelectiveImports(...vendedLogsMixin.imports);
}
}

Expand All @@ -72,7 +70,7 @@ export class LogsDeliveryBuilder extends LibraryBuilder<LogsDeliveryBuilderServi
submodule.registerModule({ module, filePath });

CDK_CORE.import(module, 'cdk');
REF_INTERFACES.import(module, 'interfaces');
CDK_INTERFACES.import(module, 'interfaces');
CONSTRUCTS.import(module, 'constructs');
CDK_AWS_LOGS.import(module, 'logs');
MIXINS_CORE.import(module, 'core', { fromLocation: relativeImportPath(filePath, '../core') });
Expand All @@ -85,7 +83,6 @@ export class LogsDeliveryBuilder extends LibraryBuilder<LogsDeliveryBuilderServi

class LogsDelivery {
public scope: Module;
public readonly imports = new Array<SelectiveImport>();
public readonly mixin: LogsMixin;
private readonly helpers: LogsHelper[] = [];

Expand Down Expand Up @@ -157,7 +154,7 @@ class LogsHelper extends ClassType {

const paramS3 = toS3.addParameter({
name: 'bucket',
type: REF_INTERFACES.IBucketRef,
type: CDK_INTERFACES.IBucketRef,
});

const permissions = this.resource.vendedLogs!.permissionsVersion === 'V2' ? MIXINS_LOGS_DELIVERY.S3LogsDeliveryPermissionsVersion.V2 : MIXINS_LOGS_DELIVERY.S3LogsDeliveryPermissionsVersion.V1;
Expand All @@ -179,7 +176,7 @@ class LogsHelper extends ClassType {

const paramCWL = toCWL.addParameter({
name: 'logGroup',
type: REF_INTERFACES.ILogGroupRef,
type: CDK_INTERFACES.ILogGroupRef,
});

toCWL.addBody(stmt.block(
Expand All @@ -199,7 +196,7 @@ class LogsHelper extends ClassType {

const paramFH = toFH.addParameter({
name: 'deliveryStream',
type: REF_INTERFACES.IDeliveryStreamRef,
type: CDK_INTERFACES.IDeliveryStreamRef,
});

toFH.addBody(stmt.block(
Expand Down Expand Up @@ -238,7 +235,6 @@ class LogsHelper extends ClassType {
}

class LogsMixin extends ClassType {
public readonly imports = new Array<SelectiveImport>();
private readonly resourceType: Type;

constructor(
Expand Down
7 changes: 0 additions & 7 deletions packages/@aws-cdk/mixins-preview/scripts/spec2logs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@ class MixinsLogsDelivery extends ExternalModule {
public readonly S3LogsDeliveryPermissionsVersion = $T(Type.fromName(this, 'S3LogsDeliveryPermissionsVersion'));
}

class CdkRefInterfaces extends ExternalModule {
public readonly IBucketRef = Type.fromName(this, 'aws_s3.IBucketRef');
public readonly ILogGroupRef = Type.fromName(this, 'aws_logs.ILogGroupRef');
public readonly IDeliveryStreamRef = Type.fromName(this, 'aws_kinesisfirehose.IDeliveryStreamRef');
}

class CdkAwsLogs extends ExternalModule {
public readonly CfnDeliverySource = Type.fromName(this, 'CfnDeliverySource');
}

export const MIXINS_LOGS_DELIVERY = new MixinsLogsDelivery('@aws-cdk/mixins-preview/services/aws-logs');
export const REF_INTERFACES = new CdkRefInterfaces('aws-cdk-lib/interfaces');
export const CDK_AWS_LOGS = new CdkAwsLogs('aws-cdk-lib/aws-logs');
12 changes: 6 additions & 6 deletions packages/@aws-cdk/mixins-preview/scripts/spec2mixins/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ExternalModule, Module, ClassType, Stability, StructType, Type, expr, s
import { MIXINS_COMMON, MIXINS_CORE, MIXINS_UTILS } from './helpers';
import type { AddServiceProps, LibraryBuilderProps } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
import { LibraryBuilder } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
import type { LocatedModule, SelectiveImport, ServiceSubmoduleProps } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
import type { LocatedModule, ServiceSubmoduleProps } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
import { BaseServiceSubmodule, relativeImportPath } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';

class MixinsServiceModule extends BaseServiceSubmodule {
Expand Down Expand Up @@ -47,8 +47,6 @@ export class MixinsBuilder extends LibraryBuilder<MixinsServiceModule> {
submodule.registerResource(resource.cloudFormationType, l1PropsMixin);

l1PropsMixin.build();

submodule.registerSelectiveImports(...l1PropsMixin.imports);
}

private createMixinsModule(submodule: MixinsServiceModule, service: Service): LocatedModule<Module> {
Expand Down Expand Up @@ -86,7 +84,6 @@ class L1PropsMixin extends ClassType {
private readonly decider: ResourceDecider;
private readonly relationshipDecider: RelationshipDecider;
private readonly converter: TypeConverter;
public readonly imports = new Array<SelectiveImport>();

constructor(
scope: Module,
Expand Down Expand Up @@ -126,14 +123,17 @@ class L1PropsMixin extends ClassType {
},
});

this.relationshipDecider = new RelationshipDecider(this.resource, db, false);
this.relationshipDecider = new RelationshipDecider(this.resource, db, {
enableRelationships: true,
enableNestedRelationships: true,
refsImportLocation: 'aws-cdk-lib/interfaces'
});
this.converter = TypeConverter.forMixin({
db: db,
resource: this.resource,
resourceClass: this,
relationshipDecider: this.relationshipDecider,
});
this.imports = this.relationshipDecider.imports;
this.decider = new ResourceDecider(this.resource, this.converter, this.relationshipDecider);
}

Expand Down
29 changes: 13 additions & 16 deletions tools/@aws-cdk/spec2cdk/lib/cdk/aws-cdk-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
const resourceClass = new ResourceClass(resourceModule, this.db, resource, {
suffix: props?.nameSuffix,
deprecated: props?.deprecated,
interfacesModule: submodule.interfaces ? {
module: submodule.interfaces?.module,
importPaths: this.resolveImportPaths(submodule.resourcesMod.filePath),
interfacesModule: {
module: submodule.interfaces.module,
importLocation: relativeImportPath(submodule.resourcesMod, submodule.interfaces),
} : undefined,
},
});

resourceClass.build();

submodule.registerResource(resource.cloudFormationType, resourceClass);
submodule.registerSelectiveImports(...resourceClass.imports);
submodule.augmentations?.module.augmentResource(resource, resourceClass);
}

Expand Down Expand Up @@ -259,18 +259,8 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
grantModule.build(Object.fromEntries(submodule.resources), props?.nameSuffix);
}

// Apply selective imports only to resources module
for (const selectiveImport of submodule.imports) {
const sourceModule = new Module(selectiveImport.moduleName);
sourceModule.importSelective(
submodule.resourcesMod.module,
selectiveImport.types.map((t) => `${t.originalType} as ${t.aliasedType}`),
{ fromLocation: relativeImportPath(submodule.resourcesMod, sourceModule.name) },
);
}

// Add an import for the interfaces file to the entry point file (make sure not to do it twice)
if (!submodule.interfaces?.module.isEmpty() && this.interfacesEntry && submodule.didCreateInterfaceModule) {
if (!submodule.interfaces.module.isEmpty() && this.interfacesEntry && submodule.didCreateInterfaceModule) {
const exportName = submoduleSymbolFromName(submodule.service.name);
const importLocation = relativeImportPath(this.interfacesEntry, submodule.interfaces);

Expand All @@ -284,7 +274,8 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>
if (!this.inCdkLib) {
return {
core: 'aws-cdk-lib/core',
interfacesEnvironmentAware: 'aws-cdk-lib/interfaces',
interfaces: 'aws-cdk-lib/interfaces',
interfacesEnvironmentAware: 'aws-cdk-lib/interfaces/environment-aware',
coreHelpers: 'aws-cdk-lib/core/lib/helpers-internal',
coreErrors: 'aws-cdk-lib/core/lib/errors',
cloudwatch: 'aws-cdk-lib/aws-cloudwatch',
Expand All @@ -294,6 +285,7 @@ export class AwsCdkLibBuilder extends LibraryBuilder<AwsCdkLibServiceSubmodule>

return {
core: relativeImportPath(sourceModule, 'core/lib'),
interfaces: relativeImportPath(sourceModule, 'interfaces'),
interfacesEnvironmentAware: relativeImportPath(sourceModule, 'interfaces/environment-aware'),
coreHelpers: relativeImportPath(sourceModule, 'core/lib/helpers-internal'),
coreErrors: relativeImportPath(sourceModule, 'core/lib/errors'),
Expand Down Expand Up @@ -321,6 +313,11 @@ export interface ImportPaths {
*/
readonly core: string;

/**
* The import name used import the `interfaces` module
*/
readonly interfaces: string;

/**
* The import name used import a specific interface from the `interfaces` module
*
Expand Down
5 changes: 5 additions & 0 deletions tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export class CdkCore extends ExternalModule {

export class Interfaces extends ExternalModule {
public readonly IEnvironmentAware = Type.fromName(this, 'IEnvironmentAware');

public readonly IBucketRef = Type.fromName(this, 'aws_s3.IBucketRef');
public readonly ILogGroupRef = Type.fromName(this, 'aws_logs.ILogGroupRef');
public readonly IDeliveryStreamRef = Type.fromName(this, 'aws_kinesisfirehose.IDeliveryStreamRef');
}

export class CdkInternalHelpers extends ExternalModule {
Expand Down Expand Up @@ -121,6 +125,7 @@ export class CdkCloudWatch extends ExternalModule {
public readonly MetricOptions = Type.fromName(this, 'MetricOptions');
}

export const CDK_INTERFACES = new Interfaces('aws-cdk-lib/interfaces');
export const CDK_INTERFACES_ENVIRONMENT_AWARE = new Interfaces('aws-cdk-lib/interfaces/environment-aware');
export const CDK_CORE = new CdkCore('aws-cdk-lib/core');
export const CDK_CLOUDWATCH = new CdkCloudWatch('aws-cdk-lib/aws-cloudwatch');
Expand Down
14 changes: 3 additions & 11 deletions tools/@aws-cdk/spec2cdk/lib/cdk/library-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { SpecDatabase, Resource, Service } from '@aws-cdk/service-spec-types';
import { Module } from '@cdklabs/typewriter';
import { IWriter, substituteFilePattern } from '../util';
import { BaseServiceSubmodule, LocatedModule, relativeImportPath } from './service-submodule';
import { BaseServiceSubmodule, LocatedModule } from './service-submodule';

export interface AddServiceProps {
/**
Expand Down Expand Up @@ -142,16 +142,8 @@ export abstract class LibraryBuilder<ServiceSubmodule extends BaseServiceSubmodu
/**
* Do whatever we need to do after a service has been rendered to a submodule
*/
protected postprocessSubmodule(submodule: ServiceSubmodule, _props?: AddServiceProps) {
// Selective imports from constructor
for (const selectiveImport of submodule.imports) {
const sourceModule = new Module(selectiveImport.moduleName);
for (const mod of submodule.locatedModules) {
sourceModule.importSelective(mod.module, selectiveImport.types.map((t) => `${t.originalType} as ${t.aliasedType}`), {
fromLocation: relativeImportPath(mod.filePath, sourceModule.name),
});
}
}
protected postprocessSubmodule(_submodule: ServiceSubmodule, _props?: AddServiceProps): void {
// does nothing, this is a hook for implementations
}

private obtainServiceSubmodule(service: Service, targetSubmodule?: string, grantsConfig?: string): ServiceSubmodule {
Expand Down
Loading
Loading