codify-plugin-lib 1.0.46 → 1.0.47
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.
|
@@ -20,7 +20,7 @@ export declare abstract class Resource<T extends StringIndexedObject> {
|
|
|
20
20
|
private validateResourceConfiguration;
|
|
21
21
|
private validateRefreshResults;
|
|
22
22
|
abstract validate(parameters: unknown): Promise<ValidationResult>;
|
|
23
|
-
abstract refresh(keys:
|
|
23
|
+
abstract refresh(keys: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
|
|
24
24
|
abstract applyCreate(plan: Plan<T>): Promise<void>;
|
|
25
25
|
applyModify(parameterName: keyof T, newValue: unknown, previousValue: unknown, allowDeletes: boolean, plan: Plan<T>): Promise<void>;
|
|
26
26
|
abstract applyDestroy(plan: Plan<T>): Promise<void>;
|
|
@@ -27,15 +27,15 @@ export class Resource {
|
|
|
27
27
|
]);
|
|
28
28
|
const statefulParameters = [...this.statefulParameters.values()]
|
|
29
29
|
.filter((sp) => desiredParameters[sp.name] !== undefined);
|
|
30
|
-
const
|
|
31
|
-
const currentParameters = await this.refresh(
|
|
30
|
+
const entriesToRefresh = new Map(Object.entries(resourceParameters));
|
|
31
|
+
const currentParameters = await this.refresh(entriesToRefresh);
|
|
32
32
|
if (currentParameters == null) {
|
|
33
33
|
return Plan.create(desiredParameters, null, resourceMetadata, planConfiguration);
|
|
34
34
|
}
|
|
35
|
-
this.validateRefreshResults(currentParameters,
|
|
35
|
+
this.validateRefreshResults(currentParameters, entriesToRefresh);
|
|
36
36
|
for (const statefulParameter of statefulParameters) {
|
|
37
37
|
const desiredValue = desiredParameters[statefulParameter.name];
|
|
38
|
-
let currentValue = await statefulParameter.refresh() ?? undefined;
|
|
38
|
+
let currentValue = await statefulParameter.refresh(desiredValue ?? null) ?? undefined;
|
|
39
39
|
if (Array.isArray(currentValue)
|
|
40
40
|
&& Array.isArray(desiredValue)
|
|
41
41
|
&& !planConfiguration.statefulMode
|
|
@@ -150,10 +150,11 @@ export class Resource {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
validateRefreshResults(refresh,
|
|
153
|
+
validateRefreshResults(refresh, desiredMap) {
|
|
154
154
|
if (!refresh) {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
+
const desiredKeys = new Set(desiredMap.keys());
|
|
157
158
|
const refreshKeys = new Set(Object.keys(refresh));
|
|
158
159
|
if (!setsEqual(desiredKeys, refreshKeys)) {
|
|
159
160
|
throw new Error(`Resource ${this.configuration.type}
|
|
@@ -13,7 +13,7 @@ export declare abstract class StatefulParameter<T extends StringIndexedObject, V
|
|
|
13
13
|
readonly name: keyof T;
|
|
14
14
|
readonly configuration: StatefulParameterConfiguration<T>;
|
|
15
15
|
protected constructor(configuration: StatefulParameterConfiguration<T>);
|
|
16
|
-
abstract refresh(): Promise<V | null>;
|
|
16
|
+
abstract refresh(desired: V | null): Promise<V | null>;
|
|
17
17
|
abstract applyAdd(valueToAdd: V, plan: Plan<T>): Promise<void>;
|
|
18
18
|
abstract applyModify(newValue: V, previousValue: V, allowDeletes: boolean, plan: Plan<T>): Promise<void>;
|
|
19
19
|
abstract applyRemove(valueToRemove: V, plan: Plan<T>): Promise<void>;
|
|
@@ -24,7 +24,7 @@ export declare abstract class ArrayStatefulParameter<T extends StringIndexedObje
|
|
|
24
24
|
applyAdd(valuesToAdd: V[], plan: Plan<T>): Promise<void>;
|
|
25
25
|
applyModify(newValues: V[], previousValues: V[], allowDeletes: boolean, plan: Plan<T>): Promise<void>;
|
|
26
26
|
applyRemove(valuesToRemove: V[], plan: Plan<T>): Promise<void>;
|
|
27
|
-
abstract refresh(): Promise<V[] | null>;
|
|
27
|
+
abstract refresh(desired: V[] | null): Promise<V[] | null>;
|
|
28
28
|
abstract applyAddItem(item: V, plan: Plan<T>): Promise<void>;
|
|
29
29
|
abstract applyRemoveItem(item: V, plan: Plan<T>): Promise<void>;
|
|
30
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
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.33",
|
|
18
18
|
"@npmcli/promise-spawn": "^7.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
package/src/entities/resource.ts
CHANGED
|
@@ -56,22 +56,22 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
56
56
|
|
|
57
57
|
// Refresh resource parameters
|
|
58
58
|
// This refreshes the parameters that configure the resource itself
|
|
59
|
-
const
|
|
60
|
-
const currentParameters = await this.refresh(
|
|
59
|
+
const entriesToRefresh = new Map(Object.entries(resourceParameters));
|
|
60
|
+
const currentParameters = await this.refresh(entriesToRefresh);
|
|
61
61
|
|
|
62
62
|
// Short circuit here. If resource is non-existent, then there's no point checking stateful parameters
|
|
63
63
|
if (currentParameters == null) {
|
|
64
64
|
return Plan.create(desiredParameters, null, resourceMetadata, planConfiguration);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
this.validateRefreshResults(currentParameters,
|
|
67
|
+
this.validateRefreshResults(currentParameters, entriesToRefresh);
|
|
68
68
|
|
|
69
69
|
// Refresh stateful parameters
|
|
70
70
|
// This refreshes parameters that are stateful (they can be added, deleted separately from the resource)
|
|
71
71
|
for(const statefulParameter of statefulParameters) {
|
|
72
72
|
const desiredValue = desiredParameters[statefulParameter.name];
|
|
73
73
|
|
|
74
|
-
let currentValue = await statefulParameter.refresh() ?? undefined;
|
|
74
|
+
let currentValue = await statefulParameter.refresh(desiredValue ?? null) ?? undefined;
|
|
75
75
|
|
|
76
76
|
// In stateless mode, filter the refreshed parameters by the desired to ensure that no deletes happen
|
|
77
77
|
if (Array.isArray(currentValue)
|
|
@@ -224,11 +224,12 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
224
224
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
private validateRefreshResults(refresh: Partial<T> | null,
|
|
227
|
+
private validateRefreshResults(refresh: Partial<T> | null, desiredMap: Map<keyof T, T[keyof T]>) {
|
|
228
228
|
if (!refresh) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
const desiredKeys = new Set<keyof T>(desiredMap.keys());
|
|
232
233
|
const refreshKeys = new Set(Object.keys(refresh)) as Set<keyof T>;
|
|
233
234
|
|
|
234
235
|
if (!setsEqual(desiredKeys, refreshKeys)) {
|
|
@@ -243,7 +244,7 @@ Additional: ${[...refreshKeys].filter(k => !desiredKeys.has(k))};`
|
|
|
243
244
|
|
|
244
245
|
abstract validate(parameters: unknown): Promise<ValidationResult>;
|
|
245
246
|
|
|
246
|
-
abstract refresh(keys:
|
|
247
|
+
abstract refresh(keys: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
|
|
247
248
|
|
|
248
249
|
abstract applyCreate(plan: Plan<T>): Promise<void>;
|
|
249
250
|
|
|
@@ -32,7 +32,7 @@ export abstract class StatefulParameter<T extends StringIndexedObject, V extends
|
|
|
32
32
|
this.configuration = configuration
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
abstract refresh(): Promise<V | null>;
|
|
35
|
+
abstract refresh(desired: V | null): Promise<V | null>;
|
|
36
36
|
|
|
37
37
|
// TODO: Add an additional parameter here for what has actually changed.
|
|
38
38
|
abstract applyAdd(valueToAdd: V, plan: Plan<T>): Promise<void>;
|
|
@@ -88,7 +88,7 @@ export abstract class ArrayStatefulParameter<T extends StringIndexedObject, V> e
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
abstract refresh(): Promise<V[] | null>;
|
|
91
|
+
abstract refresh(desired: V[] | null): Promise<V[] | null>;
|
|
92
92
|
abstract applyAddItem(item: V, plan: Plan<T>): Promise<void>;
|
|
93
93
|
abstract applyRemoveItem(item: V, plan: Plan<T>): Promise<void>;
|
|
94
94
|
}
|