codify-plugin-lib 1.0.56 → 1.0.57

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.
@@ -1,6 +1,5 @@
1
- import { ResourceOperation } from 'codify-schemas';
2
1
  export interface ParameterOptions {
3
- planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
2
+ canModify?: boolean;
4
3
  isEqual?: (desired: any, current: any) => boolean;
5
4
  isElementEqual?: (desired: any, current: any) => boolean;
6
5
  default?: unknown;
@@ -31,8 +31,8 @@ export class Plan {
31
31
  if (statefulParameterNames.has(curr.name)) {
32
32
  newOperation = ResourceOperation.MODIFY;
33
33
  }
34
- else if (parameterOptions[curr.name]?.planOperation) {
35
- newOperation = parameterOptions[curr.name].planOperation;
34
+ else if (parameterOptions[curr.name]?.canModify) {
35
+ newOperation = parameterOptions[curr.name].canModify ? ResourceOperation.MODIFY : ResourceOperation.RECREATE;
36
36
  }
37
37
  else {
38
38
  newOperation = ResourceOperation.RECREATE;
@@ -1,7 +1,6 @@
1
- import { ResourceOperation } from 'codify-schemas';
2
1
  export type ErrorMessage = string;
3
2
  export interface ResourceParameterOptions {
4
- planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
3
+ canModify?: boolean;
5
4
  isEqual?: (desired: any, current: any) => boolean;
6
5
  default?: unknown;
7
6
  }
@@ -1,4 +1,5 @@
1
1
  import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
2
+ import { ParameterChange } from './change-set.js';
2
3
  import { Plan } from './plan.js';
3
4
  import { StatefulParameter } from './stateful-parameter.js';
4
5
  import { ResourceParameterOptions, ValidationResult } from './resource-types.js';
@@ -36,6 +37,6 @@ export declare abstract class Resource<T extends StringIndexedObject> {
36
37
  validate(parameters: unknown): Promise<ValidationResult>;
37
38
  abstract refresh(keys: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
38
39
  abstract applyCreate(plan: Plan<T>): Promise<void>;
39
- applyModify(parameterName: keyof T, newValue: unknown, previousValue: unknown, allowDeletes: boolean, plan: Plan<T>): Promise<void>;
40
+ applyModify(pc: ParameterChange<T>, plan: Plan<T>): Promise<void>;
40
41
  abstract applyDestroy(plan: Plan<T>): Promise<void>;
41
42
  }
@@ -103,7 +103,7 @@ export class Resource {
103
103
  const statelessParameterChanges = parameterChanges
104
104
  .filter((pc) => !this.statefulParameters.has(pc.name));
105
105
  for (const pc of statelessParameterChanges) {
106
- await this.applyModify(pc.name, pc.newValue, pc.previousValue, false, plan);
106
+ await this.applyModify(pc, plan);
107
107
  }
108
108
  const statefulParameterChanges = parameterChanges
109
109
  .filter((pc) => this.statefulParameters.has(pc.name))
@@ -210,7 +210,7 @@ Additional: ${[...refreshKeys].filter(k => !desiredKeys.has(k))};`);
210
210
  };
211
211
  }
212
212
  ;
213
- async applyModify(parameterName, newValue, previousValue, allowDeletes, plan) { }
213
+ async applyModify(pc, plan) { }
214
214
  ;
215
215
  }
216
216
  class ConfigParser {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.56",
3
+ "version": "1.0.57",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,13 +1,11 @@
1
- import { ResourceOperation } from 'codify-schemas';
2
-
3
1
  /**
4
2
  * Customize properties for specific parameters. This will alter the way the library process changes to the parameter.
5
3
  */
6
4
  export interface ParameterOptions {
7
5
  /**
8
- * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to re-create.
6
+ * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to false (re-creates resource on change).
9
7
  */
10
- planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
8
+ canModify?: boolean;
11
9
  /**
12
10
  * Customize the equality comparison for a parameter.
13
11
  * @param a
@@ -55,8 +55,8 @@ export class Plan<T extends StringIndexedObject> {
55
55
  let newOperation: ResourceOperation;
56
56
  if (statefulParameterNames.has(curr.name)) {
57
57
  newOperation = ResourceOperation.MODIFY // All stateful parameters are modify only
58
- } else if (parameterOptions[curr.name]?.planOperation) {
59
- newOperation = parameterOptions[curr.name].planOperation!;
58
+ } else if (parameterOptions[curr.name]?.canModify) {
59
+ newOperation = parameterOptions[curr.name].canModify ? ResourceOperation.MODIFY : ResourceOperation.RECREATE;
60
60
  } else {
61
61
  newOperation = ResourceOperation.RECREATE; // Default to Re-create. Should handle the majority of use cases
62
62
  }
@@ -80,7 +80,7 @@ describe('Resource parameter tests', () => {
80
80
  type: 'resource',
81
81
  parameterOptions: {
82
82
  propA: { statefulParameter: statefulParameterSpy },
83
- propB: { planOperation: ResourceOperation.MODIFY },
83
+ propB: { canModify: true },
84
84
  }
85
85
  });
86
86
  }
@@ -1,5 +1,3 @@
1
- import { ResourceOperation } from 'codify-schemas';
2
-
3
1
  export type ErrorMessage = string;
4
2
 
5
3
  /**
@@ -7,9 +5,9 @@ export type ErrorMessage = string;
7
5
  */
8
6
  export interface ResourceParameterOptions {
9
7
  /**
10
- * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to re-create.
8
+ * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to false (re-create).
11
9
  */
12
- planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
10
+ canModify?: boolean;
13
11
  /**
14
12
  * Customize the equality comparison for a parameter.
15
13
  * @param desired
@@ -19,7 +17,7 @@ export interface ResourceParameterOptions {
19
17
  /**
20
18
  * Default value for the parameter. If a value is not provided in the config, the library will use this value.
21
19
  */
22
- default?: unknown,
20
+ default?: unknown;
23
21
  }
24
22
 
25
23
  /**
@@ -195,8 +195,8 @@ describe('Resource tests', () => {
195
195
  super({
196
196
  type: 'resource',
197
197
  parameterOptions: {
198
- propA: { planOperation: ResourceOperation.MODIFY },
199
- propB: { planOperation: ResourceOperation.MODIFY },
198
+ propA: { canModify: true },
199
+ propB: { canModify: true },
200
200
  }
201
201
  });
202
202
  }
@@ -244,7 +244,7 @@ describe('Resource tests', () => {
244
244
  type: 'type',
245
245
  dependencies: ['homebrew', 'python'],
246
246
  parameterOptions: {
247
- propA: { planOperation: ResourceOperation.MODIFY },
247
+ propA: { canModify: true },
248
248
  propB: { statefulParameter },
249
249
  propC: { isEqual: (a, b) => true },
250
250
  }
@@ -281,7 +281,7 @@ describe('Resource tests', () => {
281
281
  type: 'type',
282
282
  dependencies: ['homebrew', 'python'],
283
283
  parameterOptions: {
284
- propA: { planOperation: ResourceOperation.MODIFY },
284
+ propA: { canModify: true },
285
285
  propB: { statefulParameter },
286
286
  propC: { isEqual: (a, b) => true },
287
287
  }
@@ -161,7 +161,7 @@ export abstract class Resource<T extends StringIndexedObject> {
161
161
 
162
162
  for (const pc of statelessParameterChanges) {
163
163
  // TODO: When stateful mode is added in the future. Dynamically choose if deletes are allowed
164
- await this.applyModify(pc.name, pc.newValue, pc.previousValue, false, plan);
164
+ await this.applyModify(pc, plan);
165
165
  }
166
166
 
167
167
  const statefulParameterChanges = parameterChanges
@@ -310,7 +310,7 @@ Additional: ${[...refreshKeys].filter(k => !desiredKeys.has(k))};`
310
310
 
311
311
  abstract applyCreate(plan: Plan<T>): Promise<void>;
312
312
 
313
- async applyModify(parameterName: keyof T, newValue: unknown, previousValue: unknown, allowDeletes: boolean, plan: Plan<T>): Promise<void> {};
313
+ async applyModify(pc: ParameterChange<T>, plan: Plan<T>): Promise<void> {};
314
314
 
315
315
  abstract applyDestroy(plan: Plan<T>): Promise<void>;
316
316
  }