UNPKG

@aws-cdk/aws-cloudwatch

Version:

The CDK Construct Library for AWS::CloudWatch

44 lines 5.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accountIfDifferentFromStack = exports.regionIfDifferentFromStack = void 0; const cdk = require("@aws-cdk/core"); /** * Make a Token that renders to given region if used in a different stack, otherwise undefined */ function regionIfDifferentFromStack(region) { return cdk.Token.asString(new StackDependentToken(region, stack => stack.region)); } exports.regionIfDifferentFromStack = regionIfDifferentFromStack; /** * Make a Token that renders to given account if used in a different stack, otherwise undefined */ function accountIfDifferentFromStack(account) { return cdk.Token.asString(new StackDependentToken(account, stack => stack.account)); } exports.accountIfDifferentFromStack = accountIfDifferentFromStack; /** * A lazy token that requires an instance of Stack to evaluate */ class StackDependentToken { constructor(originalValue, fn) { this.originalValue = originalValue; this.fn = fn; this.creationStack = cdk.captureStackTrace(); } resolve(context) { const stackValue = this.fn(cdk.Stack.of(context.scope)); // Don't render if the values are definitely the same. If the stack // is unresolved we don't know, better output the value. if (!cdk.Token.isUnresolved(stackValue) && stackValue === this.originalValue) { return undefined; } return this.originalValue; } toString() { return cdk.Token.asString(this); } toJSON() { return this.originalValue; } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52LXRva2Vucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImVudi10b2tlbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEscUNBQXFDO0FBRXJDOztHQUVHO0FBQ0gsU0FBZ0IsMEJBQTBCLENBQUMsTUFBYztJQUN2RCxPQUFPLEdBQUcsQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDLElBQUksbUJBQW1CLENBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7QUFDcEYsQ0FBQztBQUZELGdFQUVDO0FBRUQ7O0dBRUc7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