Skip to content

Commit

Permalink
better way to resolve cicrular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii committed Jan 24, 2025
1 parent c3a9601 commit f5ddf8b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/aspects/unique-lambda-app-region-stack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { IAspect, Stack } from "aws-cdk-lib";
import type { IConstruct } from "constructs";
import type { GuLambdaFunction } from "../constructs/lambda";

const isGuLambdaFunction = (node: IConstruct): node is GuLambdaFunction => {
return node.constructor.name === "GuLambdaFunction";
};
import { GuLambdaFunction } from "../constructs/lambda";

export class UniqueLambdaAppRegionStackAspect implements IAspect {
readonly stack: Stack;
Expand All @@ -16,8 +12,7 @@ export class UniqueLambdaAppRegionStackAspect implements IAspect {
}

public visit(node: IConstruct): void {
// using a type guard instead of instanceof to avoid circular dependencies
if (isGuLambdaFunction(node)) {
if (node instanceof GuLambdaFunction) {
const combination = `${this.stack.region}:${this.stack.stackName}:${node.app}`;

if (this.seenCombinations.has(combination)) {
Expand Down
7 changes: 4 additions & 3 deletions src/constructs/lambda/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { Bucket } from "aws-cdk-lib/aws-s3";
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import { GuDistributable } from "../../types";
import type { GuLambdaErrorPercentageMonitoringProps, GuLambdaThrottlingMonitoringProps } from "../cloudwatch";
import { GuLambdaErrorPercentageAlarm, GuLambdaThrottlingAlarm } from "../cloudwatch";
import { GuLambdaErrorPercentageAlarm, GuLambdaThrottlingAlarm } from "../cloudwatch/lambda-alarms";
import type { GuStack } from "../core";
import { AppIdentity, GuDistributionBucketParameter } from "../core";
import { ReadParametersByName, ReadParametersByPath } from "../iam";
import { AppIdentity } from "../core/identity";
import { GuDistributionBucketParameter } from "../core/parameters/s3";
import { ReadParametersByName, ReadParametersByPath } from "../iam/policies/parameter-store-read";

export interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, "code">, AppIdentity {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mixin/app-aware-construct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from "constructs";
import { AppIdentity } from "../../constructs/core";
import { AppIdentity } from "../../constructs/core/identity";
import type { AnyConstructor } from "./types";

export function GuAppAwareConstruct<TBase extends AnyConstructor>(BaseClass: TBase) {
Expand Down

0 comments on commit f5ddf8b

Please sign in to comment.