UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 3.39 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.constructAnalyticsFromScope=constructAnalyticsFromScope;var stack_1=()=>{var tmp=require("../stack");return stack_1=()=>tmp,tmp},runtime_info_1=()=>{var tmp=require("./runtime-info");return runtime_info_1=()=>tmp,tmp},app_1=()=>{var tmp=require("../app");return app_1=()=>tmp,tmp},constants_1=()=>{var tmp=require("../constants");return constants_1=()=>tmp,tmp},metadata_type_1=()=>{var tmp=require("../metadata-type");return metadata_type_1=()=>tmp,tmp},stage_1=()=>{var tmp=require("../stage");return stage_1=()=>tmp,tmp},constants_2=()=>{var tmp=require("./constants");return constants_2=()=>tmp,tmp};const ALLOWED_METADATA_TYPES=new Set([metadata_type_1().MetadataType.MIXIN]),ADDITIONAL_TELEMETRY_METADATA_TYPES=new Set([metadata_type_1().MetadataType.CONSTRUCT,metadata_type_1().MetadataType.METHOD,metadata_type_1().MetadataType.FEATURE_FLAG]);function constructAnalyticsFromScope(scope){const isDefined=value=>value!==void 0,allConstructInfos=constructsInScope(scope).map(construct=>[construct,(0,runtime_info_1().constructInfoFromConstruct)(construct)]).filter(c=>{const[_,info]=c;return isDefined(info)&&constants_2().ALLOWED_FQN_PREFIXES.find(prefix=>info.fqn.startsWith(prefix))!=null}).map(([construct,info])=>injectAnalytics(construct,info));allConstructInfos.push({fqn:"jsii-runtime.Runtime",version:getJsiiAgentVersion()}),addValidationPluginInfo(scope,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.additionalTelemetry&&info.additionalTelemetry&&existingInfo.additionalTelemetry.push(...info.additionalTelemetry),existingInfo&&existingInfo.metadata&&info.metadata&&existingInfo.metadata.push(...info.metadata)}else uniqueMap.set(key,info)}),Array.from(uniqueMap.values())}function injectAnalytics(construct,info){const metadata=new Array,additionalTelemetry=new Array;for(const entry of construct.node.metadata)isResource(construct)&&ADDITIONAL_TELEMETRY_METADATA_TYPES.has(entry.type)?additionalTelemetry.push(entry.data):ALLOWED_METADATA_TYPES.has(entry.type)&&metadata.push(entry.data);return{...info,metadata:metadata.length?metadata:void 0,additionalTelemetry:additionalTelemetry.length?additionalTelemetry:void 0}}function constructsInScope(construct){const constructs=[construct];return construct.node.children.filter(child=>!stage_1().Stage.isStage(child)&&!stack_1().Stack.isStack(child)).forEach(child=>constructs.push(...constructsInScope(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}function addValidationPluginInfo(scope,allConstructInfos){let stage=stage_1().Stage.of(scope),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 isResource(construct){return construct!==null&&typeof construct=="object"&&constants_1().RESOURCE_SYMBOL in construct}