codify-plugin-lib 1.0.73 → 1.0.75
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 +1 -0
- package/dist/entities/plugin.js +4 -3
- package/dist/entities/resource-types.d.ts +2 -2
- package/dist/entities/resource.js +12 -12
- package/dist/messages/handlers.js +1 -1
- package/package.json +2 -2
- package/src/entities/plugin.ts +9 -3
- package/src/entities/resource-types.ts +4 -4
- package/src/entities/resource.ts +12 -12
- package/src/messages/handlers.ts +1 -1
package/.eslintignore
CHANGED
package/dist/entities/plugin.js
CHANGED
|
@@ -43,10 +43,11 @@ export class Plugin {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
async plan(data) {
|
|
46
|
-
|
|
47
|
-
|
|
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(
|
|
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,9 +22,9 @@ 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
|
-
allErrors: true,
|
|
28
28
|
});
|
|
29
29
|
this.schemaValidator = this.ajv.compile(this.options.schema);
|
|
30
30
|
}
|
|
@@ -43,36 +43,36 @@ export class Resource {
|
|
|
43
43
|
const isValid = this.schemaValidator(parameters);
|
|
44
44
|
if (!isValid) {
|
|
45
45
|
return {
|
|
46
|
-
|
|
46
|
+
isValid: false,
|
|
47
47
|
resourceName: resourceMetaData.name,
|
|
48
|
+
resourceType: resourceMetaData.type,
|
|
48
49
|
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
49
|
-
isValid: false,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
let isValid = true;
|
|
54
|
-
let customValidationErrorMessage
|
|
54
|
+
let customValidationErrorMessage;
|
|
55
55
|
try {
|
|
56
56
|
await this.customValidation(parameters);
|
|
57
57
|
}
|
|
58
|
-
catch (
|
|
58
|
+
catch (error) {
|
|
59
59
|
isValid = false;
|
|
60
|
-
customValidationErrorMessage =
|
|
60
|
+
customValidationErrorMessage = error.message;
|
|
61
61
|
}
|
|
62
62
|
if (!isValid) {
|
|
63
63
|
return {
|
|
64
|
-
resourceType: resourceMetaData.type,
|
|
65
|
-
resourceName: resourceMetaData.name,
|
|
66
|
-
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
67
64
|
customValidationErrorMessage,
|
|
68
65
|
isValid: false,
|
|
66
|
+
resourceName: resourceMetaData.name,
|
|
67
|
+
resourceType: resourceMetaData.type,
|
|
68
|
+
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
return {
|
|
72
|
-
|
|
72
|
+
isValid: true,
|
|
73
73
|
resourceName: resourceMetaData.name,
|
|
74
|
+
resourceType: resourceMetaData.type,
|
|
74
75
|
schemaValidationErrors: [],
|
|
75
|
-
isValid: true,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
async plan(desiredConfig, currentConfig = null, statefulMode = false) {
|
|
@@ -86,7 +86,7 @@ export class Resource {
|
|
|
86
86
|
const parsedConfig = new ConfigParser(desiredConfig, currentConfig, this.statefulParameters, this.transformParameters);
|
|
87
87
|
const { desiredParameters, nonStatefulParameters, resourceMetadata, statefulParameters, } = parsedConfig;
|
|
88
88
|
const currentParameters = await this.refreshNonStatefulParameters(nonStatefulParameters);
|
|
89
|
-
if (currentParameters
|
|
89
|
+
if (currentParameters === null || currentParameters === undefined) {
|
|
90
90
|
return Plan.create(desiredParameters, null, resourceMetadata, planOptions);
|
|
91
91
|
}
|
|
92
92
|
const statefulCurrentParameters = await this.refreshStatefulParameters(statefulParameters, planOptions.statefulMode);
|
|
@@ -34,7 +34,7 @@ export class MessageHandler {
|
|
|
34
34
|
requestValidators;
|
|
35
35
|
responseValidators;
|
|
36
36
|
constructor(plugin) {
|
|
37
|
-
this.ajv = new Ajv2020.default({ strict: true });
|
|
37
|
+
this.ajv = new Ajv2020.default({ strict: true, strictRequired: false });
|
|
38
38
|
addFormats.default(this.ajv);
|
|
39
39
|
this.ajv.addSchema(ResourceSchema);
|
|
40
40
|
this.plugin = plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.75",
|
|
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.
|
|
17
|
+
"codify-schemas": "1.0.44",
|
|
18
18
|
"@npmcli/promise-spawn": "^7.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
package/src/entities/plugin.ts
CHANGED
|
@@ -65,11 +65,17 @@ export class Plugin {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
async plan(data: PlanRequestData): Promise<PlanResponseData> {
|
|
68
|
-
|
|
69
|
-
|
|
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(
|
|
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
|
-
*
|
|
8
|
+
* Default value for the parameter. If a value is not provided in the config, the library will use this value.
|
|
9
9
|
*/
|
|
10
|
-
|
|
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
|
-
*
|
|
18
|
+
* Chose if the resource should be re-created or modified if this parameter is changed. Defaults to false (re-create).
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
modifyOnChange?: boolean;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
package/src/entities/resource.ts
CHANGED
|
@@ -48,9 +48,9 @@ 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
|
-
allErrors: true,
|
|
54
54
|
})
|
|
55
55
|
this.schemaValidator = this.ajv.compile(this.options.schema);
|
|
56
56
|
}
|
|
@@ -76,38 +76,38 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
76
76
|
|
|
77
77
|
if (!isValid) {
|
|
78
78
|
return {
|
|
79
|
-
|
|
79
|
+
isValid: false,
|
|
80
80
|
resourceName: resourceMetaData.name,
|
|
81
|
+
resourceType: resourceMetaData.type,
|
|
81
82
|
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
82
|
-
isValid: false,
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
let isValid = true;
|
|
88
|
-
let customValidationErrorMessage
|
|
88
|
+
let customValidationErrorMessage;
|
|
89
89
|
try {
|
|
90
90
|
await this.customValidation(parameters);
|
|
91
|
-
} catch (
|
|
91
|
+
} catch (error) {
|
|
92
92
|
isValid = false;
|
|
93
|
-
customValidationErrorMessage = (
|
|
93
|
+
customValidationErrorMessage = (error as Error).message;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
if (!isValid) {
|
|
97
97
|
return {
|
|
98
|
-
resourceType: resourceMetaData.type,
|
|
99
|
-
resourceName: resourceMetaData.name,
|
|
100
|
-
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
101
98
|
customValidationErrorMessage,
|
|
102
99
|
isValid: false,
|
|
100
|
+
resourceName: resourceMetaData.name,
|
|
101
|
+
resourceType: resourceMetaData.type,
|
|
102
|
+
schemaValidationErrors: this.schemaValidator?.errors ?? [],
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
return {
|
|
107
|
-
|
|
107
|
+
isValid: true,
|
|
108
108
|
resourceName: resourceMetaData.name,
|
|
109
|
+
resourceType: resourceMetaData.type,
|
|
109
110
|
schemaValidationErrors: [],
|
|
110
|
-
isValid: true,
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -141,7 +141,7 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
141
141
|
const currentParameters = await this.refreshNonStatefulParameters(nonStatefulParameters);
|
|
142
142
|
|
|
143
143
|
// Short circuit here. If the resource is non-existent, there's no point checking stateful parameters
|
|
144
|
-
if (currentParameters
|
|
144
|
+
if (currentParameters === null || currentParameters === undefined) {
|
|
145
145
|
return Plan.create(
|
|
146
146
|
desiredParameters,
|
|
147
147
|
null,
|
package/src/messages/handlers.ts
CHANGED
|
@@ -51,7 +51,7 @@ export class MessageHandler {
|
|
|
51
51
|
private responseValidators: Map<string, ValidateFunction>;
|
|
52
52
|
|
|
53
53
|
constructor(plugin: Plugin) {
|
|
54
|
-
this.ajv = new Ajv2020.default({ strict: true });
|
|
54
|
+
this.ajv = new Ajv2020.default({ strict: true, strictRequired: false });
|
|
55
55
|
addFormats.default(this.ajv);
|
|
56
56
|
this.ajv.addSchema(ResourceSchema);
|
|
57
57
|
this.plugin = plugin;
|