codify-plugin-lib 1.0.19 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@ import { ParameterOperation, ResourceConfig, ResourceOperation } from 'codify-sc
2
2
  export interface ParameterChange {
3
3
  name: string;
4
4
  operation: ParameterOperation;
5
- previousValue: string | null;
6
- newValue: string | null;
5
+ previousValue: unknown | null;
6
+ newValue: unknown | null;
7
7
  }
8
8
  export declare class ChangeSet {
9
9
  operation: ResourceOperation;
@@ -12,7 +12,7 @@ export declare abstract class Resource<T extends ResourceConfig> {
12
12
  abstract getCurrentConfig(desiredConfig: T): Promise<T | null>;
13
13
  abstract calculateOperation(change: ParameterChange): ResourceOperation.MODIFY | ResourceOperation.RECREATE;
14
14
  abstract applyCreate(plan: Plan<T>): Promise<void>;
15
- abstract applyModify(plan: Plan<T>): Promise<void>;
15
+ abstract applyModifyParameter(parameterChange: ParameterChange, plan: Plan<T>): Promise<void>;
16
16
  abstract applyRecreate(plan: Plan<T>): Promise<void>;
17
17
  abstract applyDestroy(plan: Plan<T>): Promise<void>;
18
18
  }
@@ -30,8 +30,15 @@ class Resource {
30
30
  throw new Error(`Internal error: Plan set to wrong resource during apply. Expected ${this.getTypeId()} but got: ${plan.getResourceType()}`);
31
31
  }
32
32
  switch (plan.changeSet.operation) {
33
+ case codify_schemas_1.ResourceOperation.MODIFY: {
34
+ const parameterChanges = plan.changeSet.parameterChanges
35
+ .filter((c) => c.operation !== codify_schemas_1.ParameterOperation.NOOP);
36
+ for (const parameterChange of parameterChanges) {
37
+ await this.applyModifyParameter(parameterChange, plan);
38
+ }
39
+ return;
40
+ }
33
41
  case codify_schemas_1.ResourceOperation.CREATE: return this.applyCreate(plan);
34
- case codify_schemas_1.ResourceOperation.MODIFY: return this.applyModify(plan);
35
42
  case codify_schemas_1.ResourceOperation.RECREATE: return this.applyRecreate(plan);
36
43
  case codify_schemas_1.ResourceOperation.DESTROY: return this.applyDestroy(plan);
37
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "ajv": "^8.12.0",
16
16
  "ajv-formats": "^2.1.1",
17
- "codify-schemas": "1.0.7",
17
+ "codify-schemas": "1.0.8",
18
18
  "@npmcli/promise-spawn": "^7.0.1"
19
19
  },
20
20
  "devDependencies": {
@@ -3,8 +3,8 @@ import { ParameterOperation, ResourceConfig, ResourceOperation } from 'codify-sc
3
3
  export interface ParameterChange {
4
4
  name: string;
5
5
  operation: ParameterOperation;
6
- previousValue: string | null;
7
- newValue: string | null;
6
+ previousValue: unknown | null;
7
+ newValue: unknown | null;
8
8
  }
9
9
 
10
10
  export class ChangeSet {
@@ -1,6 +1,6 @@
1
1
  import { describe } from 'mocha';
2
2
  import { Resource } from './resource';
3
- import { ResourceConfig, ResourceOperation } from 'codify-schemas';
3
+ import { ParameterOperation, ResourceConfig, ResourceOperation } from 'codify-schemas';
4
4
  import { ChangeSet, ParameterChange } from './change-set';
5
5
  import { spy } from 'sinon';
6
6
  import { expect } from 'chai';
@@ -15,7 +15,7 @@ class TestResource extends Resource<TestConfig> {
15
15
  return Promise.resolve(undefined);
16
16
  }
17
17
 
18
- applyModify(plan: Plan<TestConfig>): Promise<void> {
18
+ applyModifyParameter(parameterChange: ParameterChange, plan: Plan<TestConfig>): Promise<void> {
19
19
  return Promise.resolve(undefined);
20
20
  }
21
21
 
@@ -180,4 +180,35 @@ describe('Resource tests', () => {
180
180
 
181
181
  expect(resourceSpy.applyDestroy.calledOnce).to.be.true;
182
182
  })
183
+
184
+ it('calls modify the correct number of times', async () => {
185
+ const resource = new class extends TestResource {
186
+ getTypeId(): string {
187
+ return 'resource'
188
+ }
189
+ }
190
+
191
+ const resourceSpy = spy(resource);
192
+ const result = await resourceSpy.apply(
193
+ Plan.create(
194
+ new ChangeSet(ResourceOperation.MODIFY, [
195
+ {
196
+ name: 'propA',
197
+ newValue: 'a',
198
+ previousValue: 'b',
199
+ operation: ParameterOperation.ADD,
200
+ },
201
+ {
202
+ name: 'propB',
203
+ newValue: 0,
204
+ previousValue: -1,
205
+ operation: ParameterOperation.ADD,
206
+ },
207
+ ]),
208
+ { type: 'resource', propA: 'a', propB: 0 }
209
+ )
210
+ );
211
+
212
+ expect(resourceSpy.applyModifyParameter.calledTwice).to.be.true;
213
+ })
183
214
  })
@@ -48,8 +48,17 @@ export abstract class Resource<T extends ResourceConfig> {
48
48
  }
49
49
 
50
50
  switch (plan.changeSet.operation) {
51
+ case ResourceOperation.MODIFY: {
52
+ const parameterChanges = plan.changeSet.parameterChanges
53
+ .filter((c) => c.operation !== ParameterOperation.NOOP);
54
+
55
+ for (const parameterChange of parameterChanges) {
56
+ await this.applyModifyParameter(parameterChange, plan);
57
+ }
58
+
59
+ return;
60
+ }
51
61
  case ResourceOperation.CREATE: return this.applyCreate(plan);
52
- case ResourceOperation.MODIFY: return this.applyModify(plan);
53
62
  case ResourceOperation.RECREATE: return this.applyRecreate(plan);
54
63
  case ResourceOperation.DESTROY: return this.applyDestroy(plan);
55
64
  }
@@ -63,7 +72,7 @@ export abstract class Resource<T extends ResourceConfig> {
63
72
 
64
73
  abstract applyCreate(plan: Plan<T>): Promise<void>;
65
74
 
66
- abstract applyModify(plan: Plan<T>): Promise<void>;
75
+ abstract applyModifyParameter(parameterChange: ParameterChange, plan: Plan<T>): Promise<void>;
67
76
 
68
77
  abstract applyRecreate(plan: Plan<T>): Promise<void>;
69
78