codify-plugin-lib 1.0.39 → 1.0.41

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.
@@ -79,7 +79,7 @@ export class ChangeSet {
79
79
  delete _current[k];
80
80
  continue;
81
81
  }
82
- if (!ChangeSet.isSame(_current[k], _desired[k], parameterConfigurations?.[k]?.isEqual)) {
82
+ if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]?.isEqual)) {
83
83
  parameterChangeSet.push({
84
84
  name: k,
85
85
  previousValue: v,
@@ -126,7 +126,7 @@ export class ChangeSet {
126
126
  });
127
127
  continue;
128
128
  }
129
- if (!ChangeSet.isSame(_current[k], _desired[k], parameterConfigurations?.[k]?.isEqual)) {
129
+ if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]?.isEqual)) {
130
130
  parameterChangeSet.push({
131
131
  name: k,
132
132
  previousValue: _current[k],
@@ -1,8 +1,7 @@
1
1
  import { ResourceOperation } from 'codify-schemas';
2
2
  export interface ParameterConfiguration {
3
3
  planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
4
- isEqual?: (a: any, b: any) => boolean;
5
- isArrayElementEqual?: (a: any, b: any) => boolean;
4
+ isEqual?: (desired: any, current: any) => boolean;
6
5
  isStatefulParameter?: boolean;
7
6
  }
8
7
  export interface PlanConfiguration<T> {
@@ -4,7 +4,7 @@ import { Resource } from './resource.js';
4
4
  export type ErrorMessage = string;
5
5
  export interface ResourceParameterConfiguration {
6
6
  planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
7
- isEqual?: (a: any, b: any) => boolean;
7
+ isEqual?: (desired: any, current: any) => boolean;
8
8
  }
9
9
  export interface ResourceConfiguration<T extends StringIndexedObject> {
10
10
  type: string;
@@ -32,20 +32,19 @@ export class Resource {
32
32
  .filter((sp) => desiredParameters[sp.name] !== undefined);
33
33
  const keysToRefresh = new Set(Object.keys(resourceParameters));
34
34
  const currentParameters = await this.refresh(keysToRefresh);
35
- if (currentParameters == null && statefulParameters.length === 0) {
35
+ if (currentParameters == null) {
36
36
  return Plan.create(desiredConfig, null, planConfiguration);
37
37
  }
38
38
  this.validateRefreshResults(currentParameters, keysToRefresh);
39
- const currentStatefulParameters = {};
40
39
  for (const statefulParameter of statefulParameters) {
41
40
  const desiredValue = desiredParameters[statefulParameter.name];
42
41
  let currentValue = await statefulParameter.refresh(desiredValue ?? null) ?? undefined;
43
42
  if (Array.isArray(currentValue) && Array.isArray(desiredValue) && !planConfiguration.statefulMode) {
44
43
  currentValue = currentValue.filter((p) => desiredValue?.includes(p));
45
44
  }
46
- currentStatefulParameters[statefulParameter.name] = currentValue;
45
+ currentParameters[statefulParameter.name] = currentValue;
47
46
  }
48
- return Plan.create(desiredConfig, { ...currentParameters, ...currentStatefulParameters, ...resourceMetadata }, planConfiguration);
47
+ return Plan.create(desiredConfig, { ...currentParameters, ...resourceMetadata }, planConfiguration);
49
48
  }
50
49
  async apply(plan) {
51
50
  if (plan.getResourceType() !== this.typeId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -130,7 +130,7 @@ export class ChangeSet<T extends StringIndexedObject> {
130
130
  continue;
131
131
  }
132
132
 
133
- if (!ChangeSet.isSame(_current[k], _desired[k], parameterConfigurations?.[k]?.isEqual)) {
133
+ if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]?.isEqual)) {
134
134
  parameterChangeSet.push({
135
135
  name: k,
136
136
  previousValue: v,
@@ -194,7 +194,7 @@ export class ChangeSet<T extends StringIndexedObject> {
194
194
  continue;
195
195
  }
196
196
 
197
- if (!ChangeSet.isSame(_current[k], _desired[k], parameterConfigurations?.[k]?.isEqual)) {
197
+ if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]?.isEqual)) {
198
198
  parameterChangeSet.push({
199
199
  name: k,
200
200
  previousValue: _current[k],
@@ -13,9 +13,7 @@ export interface ParameterConfiguration {
13
13
  * @param a
14
14
  * @param b
15
15
  */
16
- isEqual?: (a: any, b: any) => boolean;
17
-
18
- isArrayElementEqual?: (a: any, b: any) => boolean;
16
+ isEqual?: (desired: any, current: any) => boolean;
19
17
 
20
18
  isStatefulParameter?: boolean;
21
19
  }
@@ -113,7 +113,7 @@ describe('Resource parameters tests', () => {
113
113
  }
114
114
 
115
115
  async refresh(): Promise<Partial<TestConfig> | null> {
116
- return null;
116
+ return {};
117
117
  }
118
118
  }
119
119
 
@@ -144,7 +144,7 @@ describe('Resource parameters tests', () => {
144
144
  }
145
145
 
146
146
  async refresh(): Promise<Partial<TestConfig> | null> {
147
- return null;
147
+ return {};
148
148
  }
149
149
  }
150
150
 
@@ -14,10 +14,10 @@ export interface ResourceParameterConfiguration {
14
14
  planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
15
15
  /**
16
16
  * Customize the equality comparison for a parameter.
17
- * @param a
18
- * @param b
17
+ * @param desired
18
+ * @param current
19
19
  */
20
- isEqual?: (a: any, b: any) => boolean;
20
+ isEqual?: (desired: any, current: any) => boolean;
21
21
  }
22
22
 
23
23
  /**
@@ -64,7 +64,8 @@ export abstract class Resource<T extends StringIndexedObject> {
64
64
  const keysToRefresh = new Set(Object.keys(resourceParameters));
65
65
  const currentParameters = await this.refresh(keysToRefresh);
66
66
 
67
- if (currentParameters == null && statefulParameters.length === 0) {
67
+ // Short circuit here. If resource is non-existent, then there's no point checking stateful parameters
68
+ if (currentParameters == null) {
68
69
  return Plan.create(desiredConfig, null, planConfiguration);
69
70
  }
70
71
 
@@ -72,8 +73,6 @@ export abstract class Resource<T extends StringIndexedObject> {
72
73
 
73
74
  // Refresh stateful parameters
74
75
  // This refreshes parameters that are stateful (they can be added, deleted separately from the resource)
75
- const currentStatefulParameters = {} as Partial<T>;
76
-
77
76
  for(const statefulParameter of statefulParameters) {
78
77
  const desiredValue = desiredParameters[statefulParameter.name];
79
78
 
@@ -84,12 +83,12 @@ export abstract class Resource<T extends StringIndexedObject> {
84
83
  currentValue = currentValue.filter((p) => desiredValue?.includes(p)) as any;
85
84
  }
86
85
 
87
- currentStatefulParameters[statefulParameter.name] = currentValue;
86
+ currentParameters[statefulParameter.name] = currentValue;
88
87
  }
89
88
 
90
89
  return Plan.create(
91
90
  desiredConfig,
92
- { ...currentParameters, ...currentStatefulParameters, ...resourceMetadata } as Partial<T> & ResourceConfig,
91
+ { ...currentParameters, ...resourceMetadata } as Partial<T> & ResourceConfig,
93
92
  planConfiguration,
94
93
  )
95
94
  }