import * as crypto from 'crypto' ; import { CfnLintFileSchema } from './_private_schema/cfn-lint' ; import * as schema from './schema' ; export { schema } ; export * from './canned-metrics' ; /**
 * The complete AWS CloudFormation Resource specification, having any CDK patches and enhancements included in it.
 */ export function specification ( ) { return require ( '../spec/specification.json' ) ; } /**
 * The complete AWS CloudFormation Resource specification, having any CDK patches and enhancements included in it.
 */ export function docs ( ) { return require ( '../spec/cfn-docs.json' ) ; } /**
 * Return the resource specification for the given typename
 *
 * Validates that the resource exists. If you don't want this validating behavior, read from
 * specification() directly.
 */ export function resourceSpecification ( typeName ) { const ret = specification ( ) . ResourceTypes [ typeName ] ; if ( ! ret ) { throw new Error ( `No such resource type: ${ typeName }` ) ; } return ret ; } /**
 * Return documentation for the given type
 */ export function typeDocs ( resourceName , propertyTypeName ? ) { const key = propertyTypeName ? `${ resourceName }.${ propertyTypeName }` : resourceName ; const ret = docs ( ) . Types [ key ] ; if ( ! ret ) { return { description : '' , properties : { } , } ; } return ret ; } /**
 * Get the resource augmentations for a given type
 */ export function resourceAugmentation ( typeName ) { const fileName = typeName . replace ( /::/g , '_' ) ; try { return require ( `./augmentations/${ fileName }.json` ) ; } catch ( e ) { return { } ; } } /**
 * Get the resource augmentations for a given type
 */ export function cfnLintAnnotations ( typeName ) { const allAnnotations = require ( '../spec/cfn-lint.json' ) ; return { stateful : ! ! allAnnotations . StatefulResources . ResourceTypes [ typeName ] , mustBeEmptyToDelete : allAnnotations . StatefulResources . ResourceTypes [ typeName ] ?. DeleteRequiresEmptyResource ?? false , } ; } /**
 * Return the property specification for the given resource's property
 */ export function propertySpecification ( typeName , propertyName ) { const ret = resourceSpecification ( typeName ) . Properties ! [ propertyName ] ; if ( ! ret ) { throw new Error ( `Resource ${ typeName } has no property: ${ propertyName }` ) ; } return ret ; } /**
 * The list of resource type names defined in the ``specification``.
 */ export function resourceTypes ( ) { return Object . keys ( specification ( ) . ResourceTypes ) ; } /**
 * The list of namespaces defined in the ``specification``, that is resource name prefixes down to the second ``::``.
 */ export function namespaces ( ) { return Array . from ( new Set ( resourceTypes ( ) . map ( n => n . split ( '::' , 2 ) . join ( '::' ) ) ) ) ; } param filter return export function filteredSpecification ( filter ) { const spec = specification ( ) ; const result = { ResourceTypes : { } , PropertyTypes : { } , Fingerprint : spec . Fingerprint } ; const predicate = makePredicate ( filter ) ; for ( const type of resourceTypes ( ) ) { if ( ! predicate ( type ) ) { continue ; } result . ResourceTypes [ type ] = spec . ResourceTypes [ type ] ; const prefix = `${ type }.` ; for ( const propType of Object . keys ( spec . PropertyTypes ! ) . filter ( n => n . startsWith ( prefix ) ) ) { result . PropertyTypes [ propType ] = spec . PropertyTypes ! [ propType ] ; } } result . Fingerprint = crypto . createHash ( 'sha256' ) . update ( JSON . stringify ( result ) ) . digest ( 'base64' ) ; return result ; } export type Filter = ( name : string ) => boolean ; param filter returns function makePredicate ( filter ) { if ( typeof filter === 'string' ) { return s => s === filter ; } else if ( typeof filter === 'function' ) { return filter as Filter ; } else { return s => s . match ( filter ) != null ; } } /**
 * Return the properties of the given type that require the given scrutiny type
 */ export function scrutinizablePropertyNames ( resourceType , scrutinyTypes ) { const impl = specification ( ) . ResourceTypes [ resourceType ] ; if ( ! impl ) { return [ ] ; } const ret = new Array < string > ( ) ; for ( const [ propertyName , propertySpec ] of Object . entries ( impl . Properties || { } ) ) { if ( scrutinyTypes . includes ( propertySpec . ScrutinyType || schema . PropertyScrutinyType . None ) ) { ret . push ( propertyName ) ; } } return ret ; } /**
 * Return the names of the resource types that need to be subjected to additional scrutiny
 */ export function scrutinizableResourceTypes ( scrutinyTypes ) { const ret = new Array < string > ( ) ; for ( const [ resourceType , resourceSpec ] of Object . entries ( specification ( ) . ResourceTypes ) ) { if ( scrutinyTypes . includes ( resourceSpec . ScrutinyType || schema . ResourceScrutinyType . None ) ) { ret . push ( resourceType ) ; } } return ret ; }