import { Argument , Attribute } from '../arguments' ; import { Map } from '../types' ; import { Block , Data , Provisioner } from '.' ; category export interface ResourceToDataOptions { /**
     * New type of the data source.
     */ type ? : string ; /**
     * New name of the data source.
     */ name ? : string ; } category export class Resource extends Block { readonly type : string ; readonly name : string ; param type param name param args param provisioners constructor ( type , name , args ? , provisioners ? ) { super ( 'resource' , [ type , name ] , args , provisioners ) ; this . type = type ; this . name = name ; } override asArgument ( ) { return new Argument ( `${ this . type }.${ this . name }` ) ; } override attr ( name ) { return new Attribute ( this , name ) ; } /**
     * Get provisioners.
     */ getProvisioners ( ) { return this . getInnerBlocks ( ) as Provisioner [ ] ; } /**
     * Set provisioners.
     */ setProvisioners ( provisioners ) { this . setInnerBlocks ( provisioners ) ; return this ; } param options param argNames param args toData ( options , argNames , args ? ) { const type = options ?. type ?? this . type ; const name = options ?. name ?? this . name ; if ( ! args ) { args = { } ; } if ( ! args [ 'filter' ] ) { args [ 'filter' ] = [ ] ; } else if ( ! Array . isArray ( args [ 'filter' ] ) ) { throw new Error ( 'Filter is not an array.' ) ; } for ( const argName of argNames ) { let actualArgName ; let newArgName ; if ( typeof argName === 'string' ) { actualArgName = argName ; newArgName = argName ; } else { actualArgName = argName [ 0 ] ; newArgName = argName [ 1 ] ; } const arg = this . getArgument ( actualArgName ) ; if ( arg instanceof Map ) { for ( const mapArgName in arg . arguments ) { args [ 'filter' ] . push ( { name : `${ newArgName }:${ mapArgName }` , values : [ arg . arguments [ mapArgName ] ] } ) ; } } else if ( ! args [ newArgName ] ) { args [ newArgName ] = arg ; } } return new Data ( type , name , args ) ; } }