aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 3.21 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.constructInfoFromConstruct=constructInfoFromConstruct,exports.filterMetadataType=filterMetadataType,exports.constructInfoFromStack=constructInfoFromStack;var app_1=()=>{var tmp=require("../app");return app_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../metadata-resource");return metadata_resource_1=()=>tmp,tmp},stack_1=()=>{var tmp=require("../stack");return stack_1=()=>tmp,tmp},stage_1=()=>{var tmp=require("../stage");return stage_1=()=>tmp,tmp};const ALLOWED_FQN_PREFIXES=["@aws-cdk/","@aws-cdk-containers/","@aws-solutions-konstruk/","@aws-solutions-constructs/","@amzn/","@cdklabs/","aws-rfdk.","aws-cdk-lib.","cdk8s."],JSII_RUNTIME_SYMBOL=Symbol.for("jsii.rtti");function constructInfoFromConstruct(construct){const jsiiRuntimeInfo=Object.getPrototypeOf(construct).constructor[JSII_RUNTIME_SYMBOL];if(typeof jsiiRuntimeInfo=="object"&&jsiiRuntimeInfo!==null&&typeof jsiiRuntimeInfo.fqn=="string"&&typeof jsiiRuntimeInfo.version=="string")return{fqn:jsiiRuntimeInfo.fqn,version:jsiiRuntimeInfo.version,metadata:(0,metadata_resource_1().isResource)(construct)?filterMetadataType(construct.node.metadata):void 0};if(jsiiRuntimeInfo)throw new Error(`malformed jsii runtime info for construct: '${construct.node.path}'`)}function filterMetadataType(metadata){const validTypes=new Set([metadata_resource_1().MetadataType.CONSTRUCT,metadata_resource_1().MetadataType.METHOD,metadata_resource_1().MetadataType.FEATURE_FLAG]);return metadata.filter(entry=>validTypes.has(entry.type)).map(entry=>entry.data)}function addValidationPluginInfo(stack,allConstructInfos){let stage=stage_1().Stage.of(stack),done=!1;do app_1().App.isApp(stage)&&(done=!0),stage&&(allConstructInfos.push(...stage.policyValidationBeta1.map(plugin=>({fqn:pluginFqn(plugin),version:plugin.version??"0.0.0"}))),stage=stage_1().Stage.of(stage));while(!done&&stage)}function pluginFqn(plugin){return["policyValidation",plugin.name,plugin.ruleIds?.join("|")].filter(x=>x!=null).join(".")}function constructInfoFromStack(stack){const isDefined=value=>value!==void 0,allConstructInfos=constructsInStack(stack).map(construct=>constructInfoFromConstruct(construct)).filter(isDefined).filter(info=>ALLOWED_FQN_PREFIXES.find(prefix=>info.fqn.startsWith(prefix)));allConstructInfos.push({fqn:"jsii-runtime.Runtime",version:getJsiiAgentVersion()}),addValidationPluginInfo(stack,allConstructInfos);const uniqueMap=new Map;return allConstructInfos.forEach(info=>{const key=`${info.fqn}@${info.version}`;if(uniqueMap.has(key)){const existingInfo=uniqueMap.get(key);existingInfo&&existingInfo.metadata&&info.metadata&&existingInfo.metadata.push(...info.metadata)}else uniqueMap.set(key,info)}),Array.from(uniqueMap.values())}function constructsInStack(construct){const constructs=[construct];return construct.node.children.filter(child=>!stage_1().Stage.isStage(child)&&!stack_1().Stack.isStack(child)).forEach(child=>constructs.push(...constructsInStack(child))),constructs}function getJsiiAgentVersion(){let jsiiAgent=process.env.JSII_AGENT;return jsiiAgent||(jsiiAgent=`node.js/${process.version}`),jsiiAgent=jsiiAgent.replace(/[^a-z0-9.-/=_]/gi,"-"),jsiiAgent}
;