aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 5.04 kB
JavaScript
var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Resource=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var arn_1=()=>{var tmp=require("./arn");return arn_1=()=>tmp,tmp},cfn_resource_1=()=>{var tmp=require("./cfn-resource");return cfn_resource_1=()=>tmp,tmp},constants_1=()=>{var tmp=require("./constants");return constants_1=()=>tmp,tmp},lazy_1=()=>{var tmp=require("./lazy");return lazy_1=()=>tmp,tmp},physical_name_generator_1=()=>{var tmp=require("./private/physical-name-generator");return physical_name_generator_1=()=>tmp,tmp},reference_1=()=>{var tmp=require("./reference");return reference_1=()=>tmp,tmp},stack_1=()=>{var tmp=require("./stack");return stack_1=()=>tmp,tmp},token_1=()=>{var tmp=require("./token");return token_1=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp};class Resource extends constructs_1().Construct{static isResource(construct){return construct!==null&&typeof construct=="object"&&constants_1().RESOURCE_SYMBOL in construct}static isOwnedResource(construct){return construct.node.defaultChild?cfn_resource_1().CfnResource.isCfnResource(construct.node.defaultChild):!1}constructor(scope,id,props={}){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_ResourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Resource),error}if((props.account!==void 0||props.region!==void 0)&&props.environmentFromArn!==void 0)throw new Error(`Supply at most one of 'account'/'region' (${props.account}/${props.region}) and 'environmentFromArn' (${props.environmentFromArn})`);Object.defineProperty(this,constants_1().RESOURCE_SYMBOL,{value:!0}),this.stack=stack_1().Stack.of(this);const parsedArn=props.environmentFromArn?this.stack.splitArn(props.environmentFromArn,arn_1().ArnFormat.NO_RESOURCE_NAME):void 0;this.env={account:props.account??parsedArn?.account??this.stack.account,region:props.region??parsedArn?.region??this.stack.region};let physicalName=props.physicalName;props.physicalName&&(0,physical_name_generator_1().isGeneratedWhenNeededMarker)(props.physicalName)?(this._physicalName=void 0,this._allowCrossEnvironment=!0,physicalName=lazy_1().Lazy.string({produce:()=>this._physicalName})):props.physicalName&&!token_1().Token.isUnresolved(props.physicalName)?(this._physicalName=props.physicalName,this._allowCrossEnvironment=!0):(this._physicalName=props.physicalName,this._allowCrossEnvironment=!1),physicalName===void 0&&(physicalName=token_1().Token.asString(void 0)),this.physicalName=physicalName}_enableCrossEnvironment(){if(!this._allowCrossEnvironment)throw new Error(`Cannot use resource '${this.node.path}' in a cross-environment fashion, the resource's physical name must be explicit set or use \`PhysicalName.GENERATE_IF_NEEDED\``);this._physicalName||(this._physicalName=this.generatePhysicalName())}applyRemovalPolicy(policy){try{jsiiDeprecationWarnings().aws_cdk_lib_RemovalPolicy(policy)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.applyRemovalPolicy),error}const child=this.node.defaultChild;if(!child||!cfn_resource_1().CfnResource.isCfnResource(child))throw new Error("Cannot apply RemovalPolicy: no child or not a CfnResource. Apply the removal policy on the CfnResource directly.");child.applyRemovalPolicy(policy)}generatePhysicalName(){return(0,physical_name_generator_1().generatePhysicalName)(this)}getResourceNameAttribute(nameAttr){return mimicReference(nameAttr,{produce:context=>{const consumingStack=stack_1().Stack.of(context.scope);return this.stack.account!==consumingStack.account||this.stack.region!==consumingStack.region&&!consumingStack._crossRegionReferences?(this._enableCrossEnvironment(),this.physicalName):nameAttr}})}getResourceArnAttribute(arnAttr,arnComponents){try{jsiiDeprecationWarnings().aws_cdk_lib_ArnComponents(arnComponents)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.getResourceArnAttribute),error}return mimicReference(arnAttr,{produce:context=>{const consumingStack=stack_1().Stack.of(context.scope);return this.stack.account!==consumingStack.account||this.stack.region!==consumingStack.region&&!consumingStack._crossRegionReferences?(this._enableCrossEnvironment(),this.stack.formatArn(arnComponents)):arnAttr}})}}exports.Resource=Resource,_a=JSII_RTTI_SYMBOL_1,Resource[_a]={fqn:"aws-cdk-lib.Resource",version:"2.185.0"};function mimicReference(refSource,producer){const reference=token_1().Tokenization.reverse(refSource,{failConcat:!1});return reference_1().Reference.isReference(reference)?token_1().Token.asString(new class extends reference_1().Reference{resolve(context){return producer.produce(context)}}(reference,reference.target,reference.displayName)):lazy_1().Lazy.uncachedString(producer)}
;