aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 6.98 kB
JavaScript
;var __createBinding=exports&&exports.__createBinding||(Object.create?(function(o,m,k,k2){k2===void 0&&(k2=k);var desc=Object.getOwnPropertyDescriptor(m,k);(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable))&&(desc={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){k2===void 0&&(k2=k),o[k2]=m[k]})),__setModuleDefault=exports&&exports.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}):function(o,v){o.default=v}),__importStar=exports&&exports.__importStar||(function(){var ownKeys=function(o){return ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)Object.prototype.hasOwnProperty.call(o2,k)&&(ar[ar.length]=k);return ar},ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null)for(var k=ownKeys(mod),i=0;i<k.length;i++)k[i]!=="default"&&__createBinding(result,mod,k[i]);return __setModuleDefault(result,mod),result}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.StateGraph=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var distributed_map_1=()=>{var tmp=require("./states/distributed-map");return distributed_map_1=()=>tmp,tmp},iam=()=>{var tmp=__importStar(require("../../aws-iam"));return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};class StateGraph{startState;graphDescription;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_stepfunctions.StateGraph",version:"2.260.0"};timeout;policyStatements=new Array;allStates=new Set;allContainedStates=new Map;superGraph;constructor(startState,graphDescription){this.startState=startState,this.graphDescription=graphDescription;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_State(startState)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,StateGraph),error}this.allStates.add(startState),startState.bindToGraph(this)}registerState(state){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_State(state)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.registerState),error}this.registerContainedState(state.stateId,this),this.allStates.add(state)}registerPolicyStatement(statement){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_PolicyStatement(statement)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.registerPolicyStatement),error}this.superGraph?this.superGraph.registerPolicyStatement(statement):this.policyStatements.push(statement)}registerSuperGraph(graph){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateGraph(graph)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.registerSuperGraph),error}if(this.superGraph!==graph){if(this.superGraph)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`StateGraphAlreadyRegistered`,"Every StateGraph can only be registered into one other StateGraph");this.superGraph=graph,this.pushContainedStatesUp(graph),this.pushPolicyStatementsUp(graph)}}toGraphJson(queryLanguage){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_QueryLanguage(queryLanguage)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.toGraphJson),error}const states={};for(const state of this.allStates)states[state.stateId]=state.toStateJson(queryLanguage);return{StartAt:this.startState.stateId,States:states,TimeoutSeconds:this.timeout&&this.timeout.toSeconds()}}toString(){const someNodes=Array.from(this.allStates).slice(0,3).map(x=>x.stateId);return this.allStates.size>3&&someNodes.push("..."),`${this.graphDescription} (${someNodes.join(", ")})`}registerContainedState(stateId,graph){if(this.superGraph)this.superGraph.registerContainedState(stateId,graph);else{const existingGraph=this.allContainedStates.get(stateId);if(existingGraph)throw new(core_1()).UnscopedValidationError((0,literal_string_1().lit)`DuplicateStateId`,`State with name '${stateId}' occurs in both ${graph} and ${existingGraph}. All states must have unique names.`);this.allContainedStates.set(stateId,graph)}}pushContainedStatesUp(superGraph){for(const[stateId,graph]of this.allContainedStates)superGraph.registerContainedState(stateId,graph)}pushPolicyStatementsUp(superGraph){for(const policyStatement of this.policyStatements)superGraph.registerPolicyStatement(policyStatement)}bind(stateMachine){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_stepfunctions_StateMachine(stateMachine)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const distributedMapStates=this.getAllStatesInThisAndChildStateGraphs().filter(state=>distributed_map_1().DistributedMap.isDistributedMap(state)).map(state=>state.toStateJson());if(distributedMapStates.length===0)return;const distributedMapPolicy=new(iam()).Policy(stateMachine,"DistributedMapPolicy");if(stateMachine.role.attachInlinePolicy(distributedMapPolicy),stateMachine.grantStartExecution(distributedMapPolicy),stateMachine.grantExecution(distributedMapPolicy,"states:DescribeExecution","states:StopExecution"),distributedMapStates.find(stateJson=>stateJson.Label===void 0)){iam().Grant.addToPrincipal({grantee:distributedMapPolicy,actions:["states:RedriveExecution"],resourceArns:[this.getStateMachineExecutionArnWithLabel(stateMachine,"*")]});return}const distributedMapLabeledExecutionArns=distributedMapStates.map(stateJson=>this.getStateMachineExecutionArnWithLabel(stateMachine,stateJson.Label));iam().Grant.addToPrincipal({grantee:distributedMapPolicy,actions:["states:RedriveExecution"],resourceArns:distributedMapLabeledExecutionArns})}getStateMachineExecutionArnWithLabel(stateMachine,mapRunLabel){return core_1().Stack.of(stateMachine).formatArn({resource:"execution",service:"states",resourceName:`${core_1().Arn.split(stateMachine.stateMachineArn,core_1().ArnFormat.COLON_RESOURCE_NAME).resourceName}/${mapRunLabel}:*`,arnFormat:core_1().ArnFormat.COLON_RESOURCE_NAME})}getAllStatesInThisAndChildStateGraphs(){const discoveredStateGraphs=new Set,stateGraphsToSearch=[this];for(;stateGraphsToSearch.length>0;){const stateGraph=stateGraphsToSearch.pop();discoveredStateGraphs.add(stateGraph),Array.from(stateGraph.allContainedStates.values()).filter(subGraph=>!discoveredStateGraphs.has(subGraph)).forEach(subGraph=>stateGraphsToSearch.push(subGraph))}return Array.from(discoveredStateGraphs).flatMap(stateGraph=>Array.from(stateGraph.allStates))}}exports.StateGraph=StateGraph;