UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

3 lines (2 loc) 5.98 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Template=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},fs=()=>{var tmp=require("fs-extra");return fs=()=>tmp,tmp},match_1=()=>{var tmp=require("./match");return match_1=()=>tmp,tmp},matcher_1=()=>{var tmp=require("./matcher");return matcher_1=()=>tmp,tmp},conditions_1=()=>{var tmp=require("./private/conditions");return conditions_1=()=>tmp,tmp},cyclic_1=()=>{var tmp=require("./private/cyclic");return cyclic_1=()=>tmp,tmp},mappings_1=()=>{var tmp=require("./private/mappings");return mappings_1=()=>tmp,tmp},outputs_1=()=>{var tmp=require("./private/outputs");return outputs_1=()=>tmp,tmp},parameters_1=()=>{var tmp=require("./private/parameters");return parameters_1=()=>tmp,tmp},resources_1=()=>{var tmp=require("./private/resources");return resources_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},error_1=()=>{var tmp=require("./private/error");return error_1=()=>tmp,tmp};class Template{static fromStack(stack,templateParsingOptions){try{jsiiDeprecationWarnings().aws_cdk_lib_Stack(stack),jsiiDeprecationWarnings().aws_cdk_lib_assertions_TemplateParsingOptions(templateParsingOptions)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromStack),error}return new Template(toTemplate(stack),templateParsingOptions)}static fromJSON(template,templateParsingOptions){try{jsiiDeprecationWarnings().aws_cdk_lib_assertions_TemplateParsingOptions(templateParsingOptions)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromJSON),error}return new Template(template,templateParsingOptions)}static fromString(template,templateParsingOptions){try{jsiiDeprecationWarnings().aws_cdk_lib_assertions_TemplateParsingOptions(templateParsingOptions)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromString),error}return new Template(JSON.parse(template),templateParsingOptions)}constructor(template,templateParsingOptions={}){this.template=template,templateParsingOptions.skipCyclicalDependenciesCheck||(0,cyclic_1().checkTemplateForCyclicDependencies)(this.template)}toJSON(){return this.template}resourceCountIs(type,count){const counted=(0,resources_1().countResources)(this.template,type);if(counted!==count)throw new(error_1()).AssertionError(`Expected ${count} resources of type ${type} but found ${counted}`)}resourcePropertiesCountIs(type,props,count){const counted=(0,resources_1().countResourcesProperties)(this.template,type,props);if(counted!==count)throw new(error_1()).AssertionError(`Expected ${count} resources of type ${type} but found ${counted}`)}hasResourceProperties(type,props){const matchError=(0,resources_1().hasResourceProperties)(this.template,type,props);if(matchError)throw new(error_1()).AssertionError(matchError)}hasResource(type,props){const matchError=(0,resources_1().hasResource)(this.template,type,props);if(matchError)throw new(error_1()).AssertionError(matchError)}findResources(type,props={}){return(0,resources_1().findResources)(this.template,type,props)}getResourceId(type,props={}){const{resourceId,matchError}=(0,resources_1().getResourceId)(this.template,type,props);if(matchError)throw new(error_1()).AssertionError(matchError);if(!resourceId)throw new(error_1()).AssertionError("unexpected: resourceId was undefined");return resourceId}allResources(type,props){const matchError=(0,resources_1().allResources)(this.template,type,props);if(matchError)throw new(error_1()).AssertionError(matchError)}allResourcesProperties(type,props){const matchError=(0,resources_1().allResourcesProperties)(this.template,type,props);if(matchError)throw new(error_1()).AssertionError(matchError)}hasParameter(logicalId,props){const matchError=(0,parameters_1().hasParameter)(this.template,logicalId,props);if(matchError)throw new(error_1()).AssertionError(matchError)}findParameters(logicalId,props={}){return(0,parameters_1().findParameters)(this.template,logicalId,props)}hasOutput(logicalId,props){const matchError=(0,outputs_1().hasOutput)(this.template,logicalId,props);if(matchError)throw new(error_1()).AssertionError(matchError)}findOutputs(logicalId,props={}){return(0,outputs_1().findOutputs)(this.template,logicalId,props)}hasMapping(logicalId,props){const matchError=(0,mappings_1().hasMapping)(this.template,logicalId,props);if(matchError)throw new(error_1()).AssertionError(matchError)}findMappings(logicalId,props={}){return(0,mappings_1().findMappings)(this.template,logicalId,props)}hasCondition(logicalId,props){const matchError=(0,conditions_1().hasCondition)(this.template,logicalId,props);if(matchError)throw new(error_1()).AssertionError(matchError)}findConditions(logicalId,props={}){return(0,conditions_1().findConditions)(this.template,logicalId,props)}templateMatches(expected){const result=(matcher_1().Matcher.isMatcher(expected)?expected:match_1().Match.objectLike(expected)).test(this.template);if(result.hasFailed())throw new(error_1()).AssertionError(["Template did not match as expected. The following mismatches were found:",...result.toHumanStrings().map(s=>` ${s}`)].join(` `))}}exports.Template=Template,_a=JSII_RTTI_SYMBOL_1,Template[_a]={fqn:"aws-cdk-lib.assertions.Template",version:"2.185.0"};function toTemplate(stack){const stage=core_1().Stage.of(stack);if(!core_1().Stage.isStage(stage))throw new(error_1()).AssertionError("unexpected: all stacks must be part of a Stage or an App");const assembly=stage.synth();return stack.nestedStackParent?JSON.parse(fs().readFileSync(path().join(assembly.directory,stack.templateFile)).toString("utf-8")):assembly.getStackArtifact(stack.artifactId).template}