codify-plugin-lib 1.0.85 → 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.
package/package.json
CHANGED
package/src/plugin/plugin.ts
CHANGED
|
@@ -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(
|
|
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
|
|
|
@@ -54,17 +54,22 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async validate(
|
|
57
|
-
|
|
58
|
-
resourceMetaData: ResourceConfig
|
|
57
|
+
desiredConfig: Partial<T> & ResourceConfig,
|
|
59
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
|
+
|
|
60
65
|
if (this.schemaValidator) {
|
|
61
66
|
const isValid = this.schemaValidator(parameters);
|
|
62
67
|
|
|
63
68
|
if (!isValid) {
|
|
64
69
|
return {
|
|
65
70
|
isValid: false,
|
|
66
|
-
resourceName:
|
|
67
|
-
resourceType:
|
|
71
|
+
resourceName: coreParameters.name,
|
|
72
|
+
resourceType: coreParameters.type,
|
|
68
73
|
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
69
74
|
}
|
|
70
75
|
}
|
|
@@ -83,16 +88,16 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
83
88
|
return {
|
|
84
89
|
customValidationErrorMessage,
|
|
85
90
|
isValid: false,
|
|
86
|
-
resourceName:
|
|
87
|
-
resourceType:
|
|
91
|
+
resourceName: coreParameters.name,
|
|
92
|
+
resourceType: coreParameters.type,
|
|
88
93
|
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
return {
|
|
93
98
|
isValid: true,
|
|
94
|
-
resourceName:
|
|
95
|
-
resourceType:
|
|
99
|
+
resourceName: coreParameters.name,
|
|
100
|
+
resourceType: coreParameters.type,
|
|
96
101
|
schemaValidationErrors: [],
|
|
97
102
|
}
|
|
98
103
|
}
|