UNPKG

5.05 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.accountIfDifferentFromStack = exports.regionIfDifferentFromStack = void 0;
4const cdk = require("@aws-cdk/core");
5/**
6 * Make a Token that renders to given region if used in a different stack, otherwise undefined
7 */
8function regionIfDifferentFromStack(region) {
9 return cdk.Token.asString(new StackDependentToken(region, stack => stack.region));
10}
11exports.regionIfDifferentFromStack = regionIfDifferentFromStack;
12/**
13 * Make a Token that renders to given account if used in a different stack, otherwise undefined
14 */
15function accountIfDifferentFromStack(account) {
16 return cdk.Token.asString(new StackDependentToken(account, stack => stack.account));
17}
18exports.accountIfDifferentFromStack = accountIfDifferentFromStack;
19/**
20 * A lazy token that requires an instance of Stack to evaluate
21 */
22class StackDependentToken {
23 constructor(originalValue, fn) {
24 this.originalValue = originalValue;
25 this.fn = fn;
26 this.creationStack = cdk.captureStackTrace();
27 }
28 resolve(context) {
29 const stackValue = this.fn(cdk.Stack.of(context.scope));
30 // Don't render if the values are definitely the same. If the stack
31 // is unresolved we don't know, better output the value.
32 if (!cdk.Token.isUnresolved(stackValue) && stackValue === this.originalValue) {
33 return undefined;
34 }
35 return this.originalValue;
36 }
37 toString() {
38 return cdk.Token.asString(this);
39 }
40 toJSON() {
41 return this.originalValue;
42 }
43}
44//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52LXRva2Vucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImVudi10b2tlbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEscUNBQXFDO0FBRXJDOztHQUVHO0FBQ0gsU0FBZ0IsMEJBQTBCLENBQUMsTUFBYztJQUN2RCxPQUFPLEdBQUcsQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDLElBQUksbUJBQW1CLENBQUMsTUFBTSxFQUFFLEtBQUssQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLE1BQ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