codify-plugin-lib 1.0.72 → 1.0.74

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.
package/.eslintignore CHANGED
@@ -1 +1,2 @@
1
1
  /dist
2
+ /node_modules
@@ -43,10 +43,11 @@ export class Plugin {
43
43
  };
44
44
  }
45
45
  async plan(data) {
46
- if (!this.resources.has(data.type)) {
47
- throw new Error(`Resource type not found: ${data.type}`);
46
+ const type = data.desired?.type ?? data.state?.type;
47
+ if (!type || !this.resources.has(type)) {
48
+ throw new Error(`Resource type not found: ${type}`);
48
49
  }
49
- const plan = await this.resources.get(data.type).plan(data);
50
+ const plan = await this.resources.get(type).plan(data.desired ?? null, data.state ?? null, data.isStateful);
50
51
  this.planStorage.set(plan.id, plan);
51
52
  return plan.toResponse();
52
53
  }
@@ -1,8 +1,8 @@
1
1
  export type ErrorMessage = string;
2
2
  export interface ResourceParameterOptions {
3
- modifyOnChange?: boolean;
4
- isEqual?: (desired: any, current: any) => boolean;
5
3
  default?: unknown;
4
+ isEqual?: (desired: any, current: any) => boolean;
5
+ modifyOnChange?: boolean;
6
6
  }
7
7
  export interface ResourceDefinition {
8
8
  [x: string]: {
@@ -22,6 +22,7 @@ export class Resource {
22
22
  this.options = options;
23
23
  if (this.options.schema) {
24
24
  this.ajv = new Ajv2020.default({
25
+ allErrors: true,
25
26
  strict: true,
26
27
  strictRequired: false,
27
28
  });
@@ -42,36 +43,36 @@ export class Resource {
42
43
  const isValid = this.schemaValidator(parameters);
43
44
  if (!isValid) {
44
45
  return {
45
- resourceType: resourceMetaData.type,
46
+ isValid: false,
46
47
  resourceName: resourceMetaData.name,
48
+ resourceType: resourceMetaData.type,
47
49
  schemaValidationErrors: this.schemaValidator?.errors ?? [],
48
- isValid: false,
49
50
  };
50
51
  }
51
52
  }
52
53
  let isValid = true;
53
- let customValidationErrorMessage = undefined;
54
+ let customValidationErrorMessage;
54
55
  try {
55
56
  await this.customValidation(parameters);
56
57
  }
57
- catch (err) {
58
+ catch (error) {
58
59
  isValid = false;
59
- customValidationErrorMessage = err.message;
60
+ customValidationErrorMessage = error.message;
60
61
  }
61
62
  if (!isValid) {
62
63
  return {
63
- resourceType: resourceMetaData.type,
64
- resourceName: resourceMetaData.name,
65
- schemaValidationErrors: this.schemaValidator?.errors ?? [],
66
64
  customValidationErrorMessage,
67
65
  isValid: false,
66
+ resourceName: resourceMetaData.name,
67
+ resourceType: resourceMetaData.type,
68
+ schemaValidationErrors: this.schemaValidator?.errors ?? [],
68
69
  };
69
70
  }
70
71
  return {
71
- resourceType: resourceMetaData.type,
72
+ isValid: true,
72
73
  resourceName: resourceMetaData.name,
74
+ resourceType: resourceMetaData.type,
73
75
  schemaValidationErrors: [],
74
- isValid: true,
75
76
  };
76
77
  }
77
78
  async plan(desiredConfig, currentConfig = null, statefulMode = false) {
@@ -85,7 +86,7 @@ export class Resource {
85
86
  const parsedConfig = new ConfigParser(desiredConfig, currentConfig, this.statefulParameters, this.transformParameters);
86
87
  const { desiredParameters, nonStatefulParameters, resourceMetadata, statefulParameters, } = parsedConfig;
87
88
  const currentParameters = await this.refreshNonStatefulParameters(nonStatefulParameters);
88
- if (currentParameters == null) {
89
+ if (currentParameters === null || currentParameters === undefined) {
89
90
  return Plan.create(desiredParameters, null, resourceMetadata, planOptions);
90
91
  }
91
92
  const statefulCurrentParameters = await this.refreshStatefulParameters(statefulParameters, planOptions.statefulMode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.72",
3
+ "version": "1.0.74",
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.42",
17
+ "codify-schemas": "1.0.44",
18
18
  "@npmcli/promise-spawn": "^7.0.1"
19
19
  },
20
20
  "devDependencies": {
@@ -65,11 +65,17 @@ export class Plugin {
65
65
  }
66
66
 
67
67
  async plan(data: PlanRequestData): Promise<PlanResponseData> {
68
- if (!this.resources.has(data.type)) {
69
- throw new Error(`Resource type not found: ${data.type}`);
68
+ const type = data.desired?.type ?? data.state?.type
69
+
70
+ if (!type || !this.resources.has(type)) {
71
+ throw new Error(`Resource type not found: ${type}`);
70
72
  }
71
73
 
72
- const plan = await this.resources.get(data.type)!.plan(data);
74
+ const plan = await this.resources.get(type)!.plan(
75
+ data.desired ?? null,
76
+ data.state ?? null,
77
+ data.isStateful
78
+ );
73
79
  this.planStorage.set(plan.id, plan);
74
80
 
75
81
  return plan.toResponse();
@@ -5,9 +5,9 @@ export type ErrorMessage = string;
5
5
  */
6
6
  export interface ResourceParameterOptions {
7
7
  /**
8
- * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to false (re-create).
8
+ * Default value for the parameter. If a value is not provided in the config, the library will use this value.
9
9
  */
10
- modifyOnChange?: boolean;
10
+ default?: unknown;
11
11
  /**
12
12
  * Customize the equality comparison for a parameter.
13
13
  * @param desired
@@ -15,9 +15,9 @@ export interface ResourceParameterOptions {
15
15
  */
16
16
  isEqual?: (desired: any, current: any) => boolean;
17
17
  /**
18
- * Default value for the parameter. If a value is not provided in the config, the library will use this value.
18
+ * Chose if the resource should be re-created or modified if this parameter is changed. Defaults to false (re-create).
19
19
  */
20
- default?: unknown;
20
+ modifyOnChange?: boolean;
21
21
  }
22
22
 
23
23
  /**
@@ -48,6 +48,7 @@ export abstract class Resource<T extends StringIndexedObject> {
48
48
 
49
49
  if (this.options.schema) {
50
50
  this.ajv = new Ajv2020.default({
51
+ allErrors: true,
51
52
  strict: true,
52
53
  strictRequired: false,
53
54
  })
@@ -75,38 +76,38 @@ export abstract class Resource<T extends StringIndexedObject> {
75
76
 
76
77
  if (!isValid) {
77
78
  return {
78
- resourceType: resourceMetaData.type,
79
+ isValid: false,
79
80
  resourceName: resourceMetaData.name,
81
+ resourceType: resourceMetaData.type,
80
82
  schemaValidationErrors: this.schemaValidator?.errors ?? [],
81
- isValid: false,
82
83
  }
83
84
  }
84
85
  }
85
86
 
86
87
  let isValid = true;
87
- let customValidationErrorMessage = undefined;
88
+ let customValidationErrorMessage;
88
89
  try {
89
90
  await this.customValidation(parameters);
90
- } catch (err) {
91
+ } catch (error) {
91
92
  isValid = false;
92
- customValidationErrorMessage = (err as Error).message;
93
+ customValidationErrorMessage = (error as Error).message;
93
94
  }
94
95
 
95
96
  if (!isValid) {
96
97
  return {
97
- resourceType: resourceMetaData.type,
98
- resourceName: resourceMetaData.name,
99
- schemaValidationErrors: this.schemaValidator?.errors ?? [],
100
98
  customValidationErrorMessage,
101
99
  isValid: false,
100
+ resourceName: resourceMetaData.name,
101
+ resourceType: resourceMetaData.type,
102
+ schemaValidationErrors: this.schemaValidator?.errors ?? [],
102
103
  }
103
104
  }
104
105
 
105
106
  return {
106
- resourceType: resourceMetaData.type,
107
+ isValid: true,
107
108
  resourceName: resourceMetaData.name,
109
+ resourceType: resourceMetaData.type,
108
110
  schemaValidationErrors: [],
109
- isValid: true,
110
111
  }
111
112
  }
112
113
 
@@ -140,7 +141,7 @@ export abstract class Resource<T extends StringIndexedObject> {
140
141
  const currentParameters = await this.refreshNonStatefulParameters(nonStatefulParameters);
141
142
 
142
143
  // Short circuit here. If the resource is non-existent, there's no point checking stateful parameters
143
- if (currentParameters == null) {
144
+ if (currentParameters === null || currentParameters === undefined) {
144
145
  return Plan.create(
145
146
  desiredParameters,
146
147
  null,