import { Construct , TagManager } from '@aws-cdk/core' ; import { snakeCase } from "./_util" ; /**
 * Metadata associated with this object.
 */ export interface ResourceObjectMetadata { default readonly name ? : string ; /**
     * Arbitrary key/value metadata.
     */ readonly [ key ] : any ; } export enum TerraformSchemaType { PROVIDER = 'provider' , RESOURCE = 'resource' , DATA = 'data' } export interface TerraformMetadata { readonly name : string ; readonly schemaType : TerraformSchemaType ; readonly providerVersion : string ; readonly providerName : string ; readonly rawSchema : string ; } export interface IReferencableResource { logicalId ( ) : string ; } /**
 * Options for defining API objects.
 */ export interface ResourceObjectProps { /**
     * Data associated with the resource.
     */ readonly data ? : any ; /**
     * Object metadata.
     *
     * If `name` is not specified, an app-unique name will be allocated by the
     * framework based on the path of the construct within thes construct tree.
     */ readonly metadata ? : ResourceObjectMetadata ; /**
     * Additional attributes for this API object.
     */ readonly [ key ] : any ; } interface TerraformMeta { readonly terraform : TerraformMetadata ; } export class ResourceObject extends Construct implements TerraformMeta , IReferencableResource { internal public readonly _name : string ; param scope param ns param props constructor ( scope , ns , private readonly props , readonly terraform ) { super ( scope , ns ) ; this . _name = ns ; } public logicalId ( ) { if ( this . terraform . schemaType === TerraformSchemaType . DATA ) { return `data.${ snakeCase ( this . terraform . name ) }.${ snakeCase ( this . _name ) }` ; } else { return `${ snakeCase ( this . terraform . name ) }.${ snakeCase ( this . _name ) }` ; } } protected get tfProperties ( ) : { [ key ] : any ; } { const props = this . props || { } ; if ( TagManager . isTaggable ( this ) ) { const tagsProp = { } ; tagsProp [ this . tags . tagPropertyName ] = this . tags . renderTags ( ) ; return deepMerge ( props , tagsProp ) ; } return props ; } internal public _render ( ) { const obj = { } ; obj [ this . _name ] = this . tfProperties ; return obj ; } } /**
 * Merges `source` into `target`, overriding any existing values.
 * `null`s will cause a value to be deleted.
 */ function deepMerge ( target , ... sources ) { for ( const source of sources ) { if ( typeof ( source ) !== 'object' || typeof ( target ) !== 'object' ) { throw new Error ( `Invalid usage. Both source (${ JSON . stringify ( source ) }) and target (${ JSON . stringify ( target ) }) must be objects` ) ; } for ( const key of Object . keys ( source ) ) { const value = source [ key ] ; if ( typeof ( value ) === 'object' && value != null && ! Array . isArray ( value ) ) { if ( typeof ( target [ key ] ) !== 'object' ) { target [ key ] = { } ; } deepMerge ( target [ key ] , value ) ; const output = target [ key ] ; if ( typeof ( output ) === 'object' && Object . keys ( output ) . length === 0 ) { delete target [ key ] ; } } else if ( value === undefined ) { delete target [ key ] ; } else { target [ key ] = value ; } } } return target ; }