codify-plugin-lib 1.0.84 → 1.0.86

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.
@@ -22,6 +22,7 @@ export class ResourceController {
22
22
  allErrors: true,
23
23
  strict: true,
24
24
  strictRequired: false,
25
+ allowUnionTypes: true
25
26
  });
26
27
  this.schemaValidator = this.ajv.compile(this.settings.schema);
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -11,7 +11,6 @@ import {
11
11
  import { Plan } from '../plan/plan.js';
12
12
  import { Resource } from '../resource/resource.js';
13
13
  import { ResourceController } from '../resource/resource-controller.js';
14
- import { splitUserConfig } from '../utils/utils.js';
15
14
 
16
15
  export class Plugin {
17
16
  planStorage: Map<string, Plan<any>>;
@@ -55,10 +54,9 @@ export class Plugin {
55
54
  throw new Error(`Resource type not found: ${config.type}`);
56
55
  }
57
56
 
58
- const { parameters, coreParameters } = splitUserConfig(config);
59
57
  const validation = await this.resourceControllers
60
58
  .get(config.type)!
61
- .validate(parameters, coreParameters);
59
+ .validate(config);
62
60
 
63
61
  validationResults.push(validation);
64
62
  }
@@ -7,9 +7,38 @@ import { CreatePlan, DestroyPlan, ModifyPlan } from '../plan/plan-types.js';
7
7
  import { ParameterChange } from '../plan/change-set.js';
8
8
  import { ResourceController } from './resource-controller.js';
9
9
  import { TestConfig, testPlan, TestResource, TestStatefulParameter } from '../utils/test-utils.test.js';
10
+ import { untildify } from '../utils/utils.js';
10
11
 
11
12
  describe('Resource tests', () => {
12
13
 
14
+ it('Validate applies transformations before validating', async () => {
15
+ const resource = new class extends TestResource {
16
+ getSettings(): ResourceSettings<TestConfig> {
17
+ return {
18
+ id: 'type',
19
+ dependencies: ['homebrew', 'python'],
20
+ parameterSettings: {
21
+ propA: { canModify: true, inputTransformation: (input) => untildify(input) },
22
+ },
23
+ inputTransformation: (config) => ({ propA: config.propA, propC: config.propB }),
24
+ }
25
+ }
26
+
27
+ async validate(parameters: Partial<TestConfig>): Promise<void> {
28
+ expect(parameters.propA).to.not.include('~');
29
+ expect(parameters.propB).to.not.exist;
30
+ expect(parameters.propC).to.equal(10);
31
+ }
32
+ }
33
+
34
+ const controller = new ResourceController(resource);
35
+ await controller.validate({
36
+ type: 'type',
37
+ propA: '~/.tool_versions',
38
+ propB: 10,
39
+ })
40
+ })
41
+
13
42
  it('Plans successfully', async () => {
14
43
  const resource = new class extends TestResource {
15
44
 
@@ -41,6 +41,7 @@ export class ResourceController<T extends StringIndexedObject> {
41
41
  allErrors: true,
42
42
  strict: true,
43
43
  strictRequired: false,
44
+ allowUnionTypes: true
44
45
  })
45
46
  this.schemaValidator = this.ajv.compile(this.settings.schema);
46
47
  }
@@ -53,17 +54,22 @@ export class ResourceController<T extends StringIndexedObject> {
53
54
  }
54
55
 
55
56
  async validate(
56
- parameters: Partial<T>,
57
- resourceMetaData: ResourceConfig
57
+ desiredConfig: Partial<T> & ResourceConfig,
58
58
  ): Promise<ValidateResponseData['resourceValidations'][0]> {
59
+ const configToValidate = { ...desiredConfig };
60
+ const { parameters, coreParameters } = splitUserConfig(configToValidate);
61
+
62
+ this.addDefaultValues(parameters);
63
+ await this.applyTransformParameters(configToValidate);
64
+
59
65
  if (this.schemaValidator) {
60
66
  const isValid = this.schemaValidator(parameters);
61
67
 
62
68
  if (!isValid) {
63
69
  return {
64
70
  isValid: false,
65
- resourceName: resourceMetaData.name,
66
- resourceType: resourceMetaData.type,
71
+ resourceName: coreParameters.name,
72
+ resourceType: coreParameters.type,
67
73
  schemaValidationErrors: this.schemaValidator?.errors ?? [],
68
74
  }
69
75
  }
@@ -82,16 +88,16 @@ export class ResourceController<T extends StringIndexedObject> {
82
88
  return {
83
89
  customValidationErrorMessage,
84
90
  isValid: false,
85
- resourceName: resourceMetaData.name,
86
- resourceType: resourceMetaData.type,
91
+ resourceName: coreParameters.name,
92
+ resourceType: coreParameters.type,
87
93
  schemaValidationErrors: this.schemaValidator?.errors ?? [],
88
94
  }
89
95
  }
90
96
 
91
97
  return {
92
98
  isValid: true,
93
- resourceName: resourceMetaData.name,
94
- resourceType: resourceMetaData.type,
99
+ resourceName: coreParameters.name,
100
+ resourceType: coreParameters.type,
95
101
  schemaValidationErrors: [],
96
102
  }
97
103
  }