UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 2.83 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Dashboard=exports.PeriodOverride=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),cloudwatch_generated_1=require("./cloudwatch.generated"),layout_1=require("./layout");var PeriodOverride;(function(PeriodOverride2){PeriodOverride2.AUTO="auto",PeriodOverride2.INHERIT="inherit"})(PeriodOverride=exports.PeriodOverride||(exports.PeriodOverride={}));class Dashboard extends core_1.Resource{constructor(scope,id,props={}){super(scope,id,{physicalName:props.dashboardName}),this.rows=[];try{jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudwatch_DashboardProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Dashboard),error}{const{dashboardName}=props;if(dashboardName&&!core_1.Token.isUnresolved(dashboardName)&&!dashboardName.match(/^[\w-]+$/))throw new Error([`The value ${dashboardName} for field dashboardName contains invalid characters.`,"It can only contain alphanumerics, dash (-) and underscore (_)."].join(" "))}if(props.start!==void 0&&props.defaultInterval!==void 0)throw"both properties defaultInterval and start cannot be set at once";const dashboard=new cloudwatch_generated_1.CfnDashboard(this,"Resource",{dashboardName:this.physicalName,dashboardBody:core_1.Lazy.string({produce:()=>{const column=new layout_1.Column(...this.rows);return column.position(0,0),core_1.Stack.of(this).toJsonString({start:props.defaultInterval!==void 0?`-${props.defaultInterval?.toIsoString()}`:props.start,end:props.defaultInterval!==void 0?void 0:props.end,periodOverride:props.periodOverride,widgets:column.toJson()})}})});this.dashboardName=this.getResourceNameAttribute(dashboard.ref),(props.widgets||[]).forEach(row=>{this.addWidgets(...row)}),this.dashboardArn=core_1.Stack.of(this).formatArn({service:"cloudwatch",resource:"dashboard",region:"",resourceName:this.physicalName})}addWidgets(...widgets){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_cloudwatch_IWidget(widgets)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addWidgets),error}if(widgets.length===0)return;const warnings=allWidgetsDeep(widgets).flatMap(w2=>w2.warnings??[]);for(const w2 of warnings)core_1.Annotations.of(this).addWarning(w2);const w=widgets.length>1?new layout_1.Row(...widgets):widgets[0];this.rows.push(w)}}exports.Dashboard=Dashboard,_a=JSII_RTTI_SYMBOL_1,Dashboard[_a]={fqn:"aws-cdk-lib.aws_cloudwatch.Dashboard",version:"2.70.0"};function allWidgetsDeep(ws){const ret=new Array;return ws.forEach(recurse),ret;function recurse(w){ret.push(w),hasSubWidgets(w)&&w.widgets.forEach(recurse)}}function hasSubWidgets(w){return"widgets"in w}