1- import { PlanResponseData , ResourceOperation , ValidateResponseData } from 'codify-schemas' ;
1+ import { ResourceOperation , ValidateResponseData } from 'codify-schemas' ;
22
3+ import { Plan , ResourcePlan } from '../entities/plan.js' ;
34import { Project } from '../entities/project.js' ;
45import { ResourceConfig } from '../entities/resource-config.js' ;
5- import { ctx , SubProcessName } from '../events/context.js' ;
6+ import { SubProcessName , ctx } from '../events/context.js' ;
7+ import { prettyFormatResourcePlan } from '../ui/plan-pretty-printer.js' ;
68import { groupBy } from '../utils/index.js' ;
79import { Plugin } from './plugin.js' ;
810import { PluginResolver } from './resolver.js' ;
9- import { prettyFormatPlan } from '../ui/plan-pretty-printer.js' ;
1011
1112type PluginName = string ;
1213type ResourceTypeId = string ;
@@ -47,8 +48,8 @@ export class PluginManager {
4748 ) ;
4849 }
4950
50- async getPlan ( project : Project ) : Promise < PlanResponseData [ ] > {
51- const result = new Array < PlanResponseData > ( ) ;
51+ async getPlan ( project : Project ) : Promise < Plan > {
52+ const result = new Array < ResourcePlan > ( ) ;
5253 for ( const config of project . evaluationOrder ) {
5354 const pluginName = this . resourceToPluginMapping . get ( config . type ) ;
5455 if ( ! pluginName ) {
@@ -60,29 +61,27 @@ export class PluginManager {
6061 result . push ( planResult ) ;
6162 }
6263
63- return result ;
64+ return new Plan ( result ) ;
6465 }
6566
66- async apply ( project : Project , planResponseData : PlanResponseData [ ] ) : Promise < void > {
67- for ( const plan of planResponseData ) {
68- const { resourceType } = plan ;
67+ async apply ( project : Project , plan : Plan ) : Promise < void > {
68+ for ( const resourcePlan of plan ) {
69+ ctx . subprocessStarted ( SubProcessName . APPLYING_RESOURCE , resourcePlan . id ) ;
6970
70- ctx . subprocessStarted ( SubProcessName . APPLYING_RESOURCE , resourceType ) ;
71-
72- const config = project . evaluationOrder . find ( ( r ) => r . type === resourceType ) ;
71+ const config = project . evaluationOrder . find ( ( r ) => r . id === resourcePlan . id ) ;
7372 if ( ! config ) {
74- throw new Error ( `Could not find plan ${ resourceType } ` )
73+ throw new Error ( `Could not find plan ${ resourcePlan . id } ` )
7574 }
7675
77- const pluginName = this . resourceToPluginMapping . get ( resourceType ) ;
76+ const pluginName = this . resourceToPluginMapping . get ( resourcePlan . resourceType ) ;
7877 if ( ! pluginName ) {
79- throw new Error ( `Internal error: unable to determine plugin for apply: ${ resourceType } ` ) ;
78+ throw new Error ( `Internal error: unable to determine plugin for apply: ${ resourcePlan . resourceType } ` ) ;
8079 }
8180
82- await this . plugins . get ( pluginName ) ! . apply ( plan ) ;
81+ await this . plugins . get ( pluginName ) ! . apply ( resourcePlan ) ;
8382 await this . validateApply ( pluginName , config ) ;
8483
85- ctx . subprocessFinished ( SubProcessName . APPLYING_RESOURCE , resourceType ) ;
84+ ctx . subprocessFinished ( SubProcessName . APPLYING_RESOURCE , resourcePlan . id ) ;
8685 }
8786 }
8887
@@ -145,7 +144,7 @@ export class PluginManager {
145144 throw new Error ( `Plugin: '${ pluginName } '. Resource: '${ desired . type } '. Additional changes are needed to match the desired plan.
146145
147146Validation returned: "${ validationPlan . operation } " instead of "${ ResourceOperation . NOOP } ". These changes are remaining.
148- ${ prettyFormatPlan ( validationPlan ) }
147+ ${ prettyFormatResourcePlan ( validationPlan ) }
149148 ` )
150149 }
151150 }
0 commit comments