Skip to content

Commit 1605052

Browse files
committed
Added desired values to the refresh methods. This allows plugins to refresh the current value instead of returning everything on the system.
1 parent 7133ded commit 1605052

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.46",
3+
"version": "1.0.47",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"ajv": "^8.12.0",
1616
"ajv-formats": "^2.1.1",
17-
"codify-schemas": "1.0.32",
17+
"codify-schemas": "1.0.33",
1818
"@npmcli/promise-spawn": "^7.0.1"
1919
},
2020
"devDependencies": {

src/entities/resource.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ export abstract class Resource<T extends StringIndexedObject> {
5656

5757
// Refresh resource parameters
5858
// This refreshes the parameters that configure the resource itself
59-
const keysToRefresh = new Set(Object.keys(resourceParameters));
60-
const currentParameters = await this.refresh(keysToRefresh);
59+
const entriesToRefresh = new Map(Object.entries(resourceParameters));
60+
const currentParameters = await this.refresh(entriesToRefresh);
6161

6262
// Short circuit here. If resource is non-existent, then there's no point checking stateful parameters
6363
if (currentParameters == null) {
6464
return Plan.create(desiredParameters, null, resourceMetadata, planConfiguration);
6565
}
6666

67-
this.validateRefreshResults(currentParameters, keysToRefresh);
67+
this.validateRefreshResults(currentParameters, entriesToRefresh);
6868

6969
// Refresh stateful parameters
7070
// This refreshes parameters that are stateful (they can be added, deleted separately from the resource)
7171
for(const statefulParameter of statefulParameters) {
7272
const desiredValue = desiredParameters[statefulParameter.name];
7373

74-
let currentValue = await statefulParameter.refresh() ?? undefined;
74+
let currentValue = await statefulParameter.refresh(desiredValue ?? null) ?? undefined;
7575

7676
// In stateless mode, filter the refreshed parameters by the desired to ensure that no deletes happen
7777
if (Array.isArray(currentValue)
@@ -224,11 +224,12 @@ export abstract class Resource<T extends StringIndexedObject> {
224224

225225
}
226226

227-
private validateRefreshResults(refresh: Partial<T> | null, desiredKeys: Set<keyof T>) {
227+
private validateRefreshResults(refresh: Partial<T> | null, desiredMap: Map<keyof T, T[keyof T]>) {
228228
if (!refresh) {
229229
return;
230230
}
231231

232+
const desiredKeys = new Set<keyof T>(desiredMap.keys());
232233
const refreshKeys = new Set(Object.keys(refresh)) as Set<keyof T>;
233234

234235
if (!setsEqual(desiredKeys, refreshKeys)) {
@@ -243,7 +244,7 @@ Additional: ${[...refreshKeys].filter(k => !desiredKeys.has(k))};`
243244

244245
abstract validate(parameters: unknown): Promise<ValidationResult>;
245246

246-
abstract refresh(keys: Set<keyof T>): Promise<Partial<T> | null>;
247+
abstract refresh(keys: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
247248

248249
abstract applyCreate(plan: Plan<T>): Promise<void>;
249250

src/entities/stateful-parameter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export abstract class StatefulParameter<T extends StringIndexedObject, V extends
3232
this.configuration = configuration
3333
}
3434

35-
abstract refresh(): Promise<V | null>;
35+
abstract refresh(desired: V | null): Promise<V | null>;
3636

3737
// TODO: Add an additional parameter here for what has actually changed.
3838
abstract applyAdd(valueToAdd: V, plan: Plan<T>): Promise<void>;
@@ -88,7 +88,7 @@ export abstract class ArrayStatefulParameter<T extends StringIndexedObject, V> e
8888
}
8989
}
9090

91-
abstract refresh(): Promise<V[] | null>;
91+
abstract refresh(desired: V[] | null): Promise<V[] | null>;
9292
abstract applyAddItem(item: V, plan: Plan<T>): Promise<void>;
9393
abstract applyRemoveItem(item: V, plan: Plan<T>): Promise<void>;
9494
}

0 commit comments

Comments
 (0)