UNPKG

19.6 kBJavaScriptView Raw
1"use strict";
2var _a, _b;
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.CfnRefElement = exports.CfnElement = void 0;
5const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
6const cxschema = require("@aws-cdk/cloud-assembly-schema");
7const cxapi = require("@aws-cdk/cx-api");
8const constructs_1 = require("constructs");
9// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
10// eslint-disable-next-line
11const construct_compat_1 = require("./construct-compat");
12const lazy_1 = require("./lazy");
13const CFN_ELEMENT_SYMBOL = Symbol.for('@aws-cdk/core.CfnElement');
14/**
15 * An element of a CloudFormation stack.
16 */
17class CfnElement extends construct_compat_1.Construct {
18 /**
19 * Creates an entity and binds it to a tree.
20 * Note that the root of the tree must be a Stack object (not just any Root).
21 *
22 * @param scope The parent construct
23 * @param props Construct properties
24 */
25 constructor(scope, id) {
26 super(scope, id);
27 Object.defineProperty(this, CFN_ELEMENT_SYMBOL, { value: true });
28 this.stack = stack_1.Stack.of(this);
29 this.logicalId = lazy_1.Lazy.uncachedString({ produce: () => this.synthesizeLogicalId() }, {
30 displayHint: `${notTooLong(constructs_1.Node.of(this).path)}.LogicalID`,
31 });
32 if (!this.node.tryGetContext(cxapi.DISABLE_LOGICAL_ID_METADATA)) {
33 constructs_1.Node.of(this).addMetadata(cxschema.ArtifactMetadataEntryType.LOGICAL_ID, this.logicalId, this.constructor);
34 }
35 }
36 /**
37 * Returns `true` if a construct is a stack element (i.e. part of the
38 * synthesized cloudformation template).
39 *
40 * Uses duck-typing instead of `instanceof` to allow stack elements from different
41 * versions of this library to be included in the same stack.
42 *
43 * @returns The construct as a stack element or undefined if it is not a stack element.
44 */
45 static isCfnElement(x) {
46 return CFN_ELEMENT_SYMBOL in x;
47 }
48 /**
49 * Overrides the auto-generated logical ID with a specific ID.
50 * @param newLogicalId The new logical ID to use for this stack element.
51 */
52 overrideLogicalId(newLogicalId) {
53 if (this._logicalIdLocked) {
54 throw new Error(`The logicalId for resource at path ${constructs_1.Node.of(this).path} has been locked and cannot be overridden\n` +
55 'Make sure you are calling "overrideLogicalId" before Stack.exportValue');
56 }
57 else {
58 this._logicalIdOverride = newLogicalId;
59 }
60 }
61 /**
62 * Lock the logicalId of the element and do not allow
63 * any updates (e.g. via overrideLogicalId)
64 *
65 * This is needed in cases where you are consuming the LogicalID
66 * of an element prior to synthesis and you need to not allow future
67 * changes to the id since doing so would cause the value you just
68 * consumed to differ from the synth time value of the logicalId.
69 *
70 * For example:
71 *
72 * const bucket = new Bucket(stack, 'Bucket');
73 * stack.exportValue(bucket.bucketArn) <--- consuming the logicalId
74 * bucket.overrideLogicalId('NewLogicalId') <--- updating logicalId
75 *
76 * You should most likely never need to use this method, and if
77 * you are implementing a feature that requires this, make sure
78 * you actually require it.
79 *
80 * @internal
81 */
82 _lockLogicalId() {
83 this._logicalIdLocked = true;
84 }
85 /**
86 * @returns the stack trace of the point where this Resource was created from, sourced
87 * from the +metadata+ entry typed +aws:cdk:logicalId+, and with the bottom-most
88 * node +internal+ entries filtered.
89 */
90 get creationStack() {
91 const trace = constructs_1.Node.of(this).metadata.find(md => md.type === cxschema.ArtifactMetadataEntryType.LOGICAL_ID).trace;
92 if (!trace) {
93 return [];
94 }
95 return filterStackTrace(trace);
96 function filterStackTrace(stack) {
97 const result = Array.of(...stack);
98 while (result.length > 0 && shouldFilter(result[result.length - 1])) {
99 result.pop();
100 }
101 // It's weird if we filtered everything, so return the whole stack...
102 return result.length === 0 ? stack : result;
103 }
104 function shouldFilter(str) {
105 return str.match(/[^(]+\(internal\/.*/) !== null;
106 }
107 }
108 /**
109 * Called during synthesize to render the logical ID of this element. If
110 * `overrideLogicalId` was it will be used, otherwise, we will allocate the
111 * logical ID through the stack.
112 */
113 synthesizeLogicalId() {
114 if (this._logicalIdOverride) {
115 return this._logicalIdOverride;
116 }
117 else {
118 return this.stack.getLogicalId(this);
119 }
120 }
121}
122exports.CfnElement = CfnElement;
123_a = JSII_RTTI_SYMBOL_1;
124CfnElement[_a] = { fqn: "@aws-cdk/core.CfnElement", version: "1.204.0" };
125/**
126 * Base class for referenceable CloudFormation constructs which are not Resources
127 *
128 * These constructs are things like Conditions and Parameters, can be
129 * referenced by taking the `.ref` attribute.
130 *
131 * Resource constructs do not inherit from CfnRefElement because they have their
132 * own, more specific types returned from the .ref attribute. Also, some
133 * resources aren't referenceable at all (such as BucketPolicies or GatewayAttachments).
134 */
135class CfnRefElement extends CfnElement {
136 /**
137 * Return a string that will be resolved to a CloudFormation `{ Ref }` for this element.
138 *
139 * If, by any chance, the intrinsic reference of a resource is not a string, you could
140 * coerce it to an IResolvable through `Lazy.any({ produce: resource.ref })`.
141 */
142 get ref() {
143 return token_1.Token.asString(cfn_reference_1.CfnReference.for(this, 'Ref'));
144 }
145}
146exports.CfnRefElement = CfnRefElement;
147_b = JSII_RTTI_SYMBOL_1;
148CfnRefElement[_b] = { fqn: "@aws-cdk/core.CfnRefElement", version: "1.204.0" };
149function notTooLong(x) {
150 if (x.length < 100) {
151 return x;
152 }
153 return x.slice(0, 47) + '...' + x.slice(-47);
154}
155const cfn_reference_1 = require("./private/cfn-reference");
156const stack_1 = require("./stack");
157const token_1 = require("./token");
158//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZuLWVsZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjZm4tZWxlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDJEQUEyRDtBQUMzRCx5Q0FBeUM7QUFDekMsMkNBQTZDO0FBRTdDLGdIQUFnSDtBQUNoSCwyQkFBMkI7QUFDM0IseURBQWdFO0FBQ2hFLGlDQUE4QjtBQUU5QixNQUFNLGtCQUFrQixHQUFHLE1BQU0sQ0FBQyxHQUFHLENBQUMsMEJBQTBCLENBQUMsQ0FBQztBQUVsRTs7R0FFRztBQUNILE1BQXNCLFVBQVcsU0FBU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