UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 8.76 kB
"use strict";var __runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};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 constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},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},errors_1=()=>{var tmp=require("./errors");return errors_1=()=>tmp,tmp},memoize_1=()=>{var tmp=require("./helpers-internal/memoize");return memoize_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},mixin_metadata_1=()=>{var tmp=require("./mixins/private/mixin-metadata");return mixin_metadata_1=()=>tmp,tmp};let Resource=(()=>{let _classSuper=constructs_1().Construct,_instanceExtraInitializers=[],_get_stack_decorators,_get_env_decorators,_get_physicalName_decorators;return class Resource2 extends _classSuper{static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_get_stack_decorators=[memoize_1().memoizedGetter],_get_env_decorators=[memoize_1().memoizedGetter],_get_physicalName_decorators=[memoize_1().memoizedGetter],__esDecorate(this,null,_get_stack_decorators,{kind:"getter",name:"stack",static:!1,private:!1,access:{has:obj=>"stack"in obj,get:obj=>obj.stack},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,_get_env_decorators,{kind:"getter",name:"env",static:!1,private:!1,access:{has:obj=>"env"in obj,get:obj=>obj.env},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,_get_physicalName_decorators,{kind:"getter",name:"physicalName",static:!1,private:!1,access:{has:obj=>"physicalName"in obj,get:obj=>obj.physicalName},metadata:_metadata},null,_instanceExtraInitializers),_metadata&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.Resource",version:"2.246.0"};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}_allowCrossEnvironment=__runInitializers(this,_instanceExtraInitializers);_customAccount;_customRegion;_physicalNameMode;_givenPhysicalName;_generatedPhysicalName;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,Resource2),error}if((props.account!==void 0||props.region!==void 0)&&props.environmentFromArn!==void 0)throw new(errors_1()).ValidationError("ConflictingEnvironmentOptions",`Supply at most one of 'account'/'region' (${props.account}/${props.region}) and 'environmentFromArn' (${props.environmentFromArn})`,this);Object.defineProperty(this,constants_1().RESOURCE_SYMBOL,{value:!0});const parsedArn=props.environmentFromArn?arn_1().Arn.split(props.environmentFromArn,arn_1().ArnFormat.NO_RESOURCE_NAME):void 0;this._customAccount=props.account??parsedArn?.account,this._customRegion=props.region??parsedArn?.region,this._givenPhysicalName=props.physicalName,props.physicalName&&(0,physical_name_generator_1().isGeneratedWhenNeededMarker)(props.physicalName)?(this._physicalNameMode="generate",this._allowCrossEnvironment=!0):props.physicalName&&!token_1().Token.isUnresolved(props.physicalName)?(this._physicalNameMode="given-resolved",this._allowCrossEnvironment=!0):(this._physicalNameMode="deploy-time",this._allowCrossEnvironment=!1)}get stack(){return stack_1().Stack.of(this)}get env(){return{account:this._customAccount??this.stack.account,region:this._customRegion??this.stack.region}}with(...mixins){return(0,mixin_metadata_1().withMixins)(this,...mixins)}get physicalName(){switch(this._physicalNameMode){case"generate":return lazy_1().Lazy.string({produce:()=>this._generatedPhysicalName});case"given-resolved":return this._givenPhysicalName;case"deploy-time":return this._givenPhysicalName??token_1().Token.asString(void 0)}}_enableCrossEnvironment(){if(!this._allowCrossEnvironment)throw new(errors_1()).ValidationError("CannotUseCrossEnvironment",`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);this._physicalNameMode==="generate"&&!this._generatedPhysicalName&&(this._generatedPhysicalName=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(errors_1()).ValidationError("CannotApplyRemovalPolicy","Cannot apply RemovalPolicy: no child or not a CfnResource. Apply the removal policy on the CfnResource directly.",this);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;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)}