UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 4.17 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Stage=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},feature_flags_1=()=>{var tmp=require("./feature-flags");return feature_flags_1=()=>tmp,tmp},synthesis_1=()=>{var tmp=require("./private/synthesis");return synthesis_1=()=>tmp,tmp},cxapi=()=>{var tmp=require("../../cx-api");return cxapi=()=>tmp,tmp};const STAGE_SYMBOL=Symbol.for("@aws-cdk/core.Stage");class Stage extends constructs_1().Construct{static of(construct){return constructs_1().Node.of(construct).scopes.reverse().slice(1).find(Stage.isStage)}static isStage(x){return x!==null&&typeof x=="object"&&STAGE_SYMBOL in x}constructor(scope,id,props={}){super(scope,id),this.policyValidationBeta1=[];try{jsiiDeprecationWarnings().aws_cdk_lib_StageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Stage),error}if(id!==""&&!/^[a-z][a-z0-9\-\_\.]+$/i.test(id))throw new Error(`invalid stage name "${id}". Stage name must start with a letter and contain only alphanumeric characters, hypens ('-'), underscores ('_') and periods ('.')`);Object.defineProperty(this,STAGE_SYMBOL,{value:!0}),this.constructPathsCache=new Set,this.parentStage=Stage.of(this),this.region=props.env?.region??this.parentStage?.region,this.account=props.env?.account??this.parentStage?.account,props.permissionsBoundary?._bind(this),this._assemblyBuilder=this.createBuilder(props.outdir),this.stageName=[this.parentStage?.stageName,props.stageName??id].filter(x=>x).join("-"),props.policyValidationBeta1&&(this.policyValidationBeta1=props.policyValidationBeta1)}get outdir(){return this._assemblyBuilder.outdir}get assetOutdir(){return this._assemblyBuilder.assetOutdir}get artifactId(){return this.node.path?`assembly-${this.node.path.replace(/\//g,"-").replace(/^-+|-+$/g,"")}`:""}synth(options={}){try{jsiiDeprecationWarnings().aws_cdk_lib_StageSynthesisOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.synth),error}let newConstructPaths=this.listAllConstructPaths(this);if((this.constructPathsCache.size==0||!this.assembly||options.force)&&(this.assembly=(0,synthesis_1().synthesize)(this,{skipValidation:options.skipValidation,validateOnSynthesis:options.validateOnSynthesis,aspectStabilization:options.aspectStabilization??feature_flags_1().FeatureFlags.of(this).isEnabled(cxapi().ASPECT_STABILIZATION)??!1}),newConstructPaths=this.listAllConstructPaths(this),this.constructPathsCache=newConstructPaths),!this.constructPathSetsAreEqual(this.constructPathsCache,newConstructPaths)){const errorMessage="Synthesis has been called multiple times and the construct tree was modified after the first synthesis.";if(options.errorOnDuplicateSynth??!0)throw new Error(errorMessage+" This is not allowed. Remove multple synth() calls and do not modify the construct tree after the first synth().");console.error(errorMessage+" Only the results of the first synth() call are used, and modifications done after it are ignored. Avoid construct tree mutations after synth() has been called unless this is intentional.")}return this.constructPathsCache=newConstructPaths,this.assembly}listAllConstructPaths(construct){const paths=new Set;function recurse(root){paths.add(root.node.path);for(const child of root.node.children)Stage.isStage(child)||recurse(child)}return recurse(construct),paths}constructPathSetsAreEqual(set1,set2){if(set1.size!==set2.size)return!1;for(const id of set1)if(!set2.has(id))return!1;return!0}createBuilder(outdir){if(this.parentStage&&outdir)throw new Error('"outdir" cannot be specified for nested stages');return this.parentStage?this.parentStage._assemblyBuilder.createNestedAssembly(this.artifactId,this.node.path):new(cxapi()).CloudAssemblyBuilder(outdir)}}exports.Stage=Stage,_a=JSII_RTTI_SYMBOL_1,Stage[_a]={fqn:"aws-cdk-lib.Stage",version:"2.185.0"};