import { Relation , Project , Schema , GeneratorProps , RuntimeAdapterProps , RuntimeAdapter , RuntimeProxy , Runtime , ComposeWithOptions , PrettifyOptions , } from "@codotype/core" ; /**
 * RuntimeProxyAdapter
 * CHORE - this MUST be renamed from RuntimeProxyAdaptor to SOMETHING ELSE
 * Creates an interface between a Generator and Runtime configured to work around that Generator's module location on the file system
 * This layer of abstraction allows easy-to-use relative path declarations for source templates + file destinations,
 * without the burden of needing to pass around references to the current directory in the Generator definitions
 */ export class RuntimeProxyAdapter implements RuntimeAdapter { private runtime : Runtime ; runtimeProxy : RuntimeProxy ; renderInPlace : string [ ] ; props : RuntimeAdapterProps ; generatorResolvedPath : string ; /**
     * constructor
     * Handles build options
     */ constructor ( generatorProps , props ) { if ( ! props . runtime ) { throw Error ( "CodotypeGenerator options requires props.runtime" ) ; return ; } if ( ! props . generatorResolvedPath ) { throw Error ( "CodotypeGenerator options requires props.generatorResolvedPath" ) ; } if ( ! generatorProps . write && ! generatorProps . renderInPlace && ! generatorProps . forEachSchema && ! generatorProps . forEachRelation && ! generatorProps . forEachReferencedBy ) { throw Error ( "GeneratorProps requires either write, forEachSchema, forEachRelation, forEachReferencedBy, or renderInPlace properties" ) ; } this . runtime = props . runtime ; this . write = generatorProps . write || this . write ; this . forEachSchema = generatorProps . forEachSchema || this . forEachSchema ; this . forEachRelation = generatorProps . forEachRelation || this . forEachRelation ; this . forEachReferencedBy = generatorProps . forEachReferencedBy || this . forEachReferencedBy ; this . renderInPlace = generatorProps . renderInPlace || [ ] ; this . props = props ; this . generatorResolvedPath = this . props . generatorResolvedPath ; this . runtimeProxy = { ensureDir : this . ensureDir , writeFile : this . writeFile , copyDir : this . copyDir , copyFile : this . copyFile , renderTemplate : this . renderTemplate , composeWith : this . composeWith , } ; return this ; } see WriteFunction async write ( params ) { return Promise . resolve ( ) ; } see ForEachSchemaFunction async forEachSchema ( params ) { return Promise . resolve ( ) ; } see ForEachRelationFunction async forEachRelation ( params ) { return Promise . resolve ( ) ; } see ForEachReferencedByFunction async forEachReferencedBy ( params ) { return Promise . resolve ( ) ; } see WriteFileFunction writeFile ( destinationPath , compiledTemplate , options ? ) { return this . runtime . writeFile ( this . runtime . getDestinationPath ( this . props . destinationPath , destinationPath ) , compiledTemplate , options ) ; } see EnsureDirFunction ensureDir ( dir ) { return this . runtime . ensureDir ( this . runtime . getDestinationPath ( this . props . destinationPath , dir ) ) ; } see CopyDirFunction copyDir ( params ) { const { src , dest } = params ; return this . runtime . copyDir ( { src : this . runtime . getTemplatePath ( this . generatorResolvedPath , src ) , dest : this . runtime . getDestinationPath ( this . props . destinationPath , dest ) , } ) ; } see CopyFileFunction copyFile ( param ) { let src = "" ; let dest = "" ; if ( typeof param === "string" ) { src = param ; dest = param ; } else { src = param . src ; dest = param . dest ; } return this . runtime . copyFile ( { src : this . runtime . getTemplatePath ( this . generatorResolvedPath , src ) , dest : this . runtime . getDestinationPath ( this . props . destinationPath , dest ) , } ) ; } see GeneratorProps . renderInPlace compileTemplatesInPlace ( ) { return Promise . all ( this . renderInPlace . map ( ( template ) => { return this . runtime . writeTemplateToFile ( this , this . runtime . getTemplatePath ( this . generatorResolvedPath , template ) , this . runtime . getDestinationPath ( this . props . destinationPath , template ) , { } , { } ) ; } ) ) ; } see RenderTemplateFunction renderTemplate ( { src , dest , data = { } , options , } ) { return this . runtime . writeTemplateToFile ( this , this . runtime . getTemplatePath ( this . generatorResolvedPath , src ) , this . runtime . getDestinationPath ( this . props . destinationPath , dest ) , data , options ) ; } see ComposeWithFunction composeWith ( generatorModulePath , composeWithOptions ? ) { return this . runtime . composeWith ( this , generatorModulePath , composeWithOptions || { } ) ; } }