UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 2.27 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Names=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},encoding_1=()=>{var tmp=require("./private/encoding");return encoding_1=()=>tmp,tmp},unique_resource_name_1=()=>{var tmp=require("./private/unique-resource-name");return unique_resource_name_1=()=>tmp,tmp},uniqueid_1=()=>{var tmp=require("./private/uniqueid");return uniqueid_1=()=>tmp,tmp},stack_1=()=>{var tmp=require("./stack");return stack_1=()=>tmp,tmp};class Names{static uniqueId(construct){const components=constructs_1().Node.of(construct).scopes.slice(1).map(c=>constructs_1().Node.of(c).id);return components.length>0?(0,uniqueid_1().makeUniqueId)(components):""}static nodeUniqueId(node){const components=node.scopes.slice(1).map(c=>constructs_1().Node.of(c).id);return components.length>0?(0,uniqueid_1().makeUniqueId)(components):""}static uniqueResourceName(construct,options){try{jsiiDeprecationWarnings().aws_cdk_lib_UniqueResourceNameOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.uniqueResourceName),error}const node=constructs_1().Node.of(construct),isStack=node.scopes.map(isTopLevelStack),lastStackIndex=Math.max(findLastIndex(isStack,x=>x),0),componentsPath=node.scopes.slice(lastStackIndex).map(component=>isTopLevelStack(component)?component.stackName:constructs_1().Node.of(component).id);return(0,unique_resource_name_1().makeUniqueResourceName)(componentsPath,options)}static stackRelativeConstructPath(construct){const scopes=construct.node.scopes,isStack=scopes.map(isTopLevelStack),lastStackIndex=findLastIndex(isStack,x=>x);return scopes.slice(lastStackIndex+1).map(x=>x.node.id).join("/")}constructor(){}}exports.Names=Names,_a=JSII_RTTI_SYMBOL_1,Names[_a]={fqn:"aws-cdk-lib.Names",version:"2.202.0"};function isTopLevelStack(x){return stack_1().Stack.isStack(x)&&!(0,encoding_1().unresolved)(x.stackName)}function findLastIndex(xs,pred){for(let i=xs.length-1;i>=0;i--)if(pred(xs[i]))return i;return-1}