codify-plugin-lib 1.0.66 → 1.0.68
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Plan } from './plan.js';
|
|
2
|
+
import { StringIndexedObject } from 'codify-schemas';
|
|
1
3
|
export interface ParameterOptions {
|
|
2
4
|
modifyOnChange?: boolean;
|
|
3
5
|
isEqual?: (desired: any, current: any) => boolean;
|
|
@@ -9,3 +11,15 @@ export interface PlanOptions<T> {
|
|
|
9
11
|
statefulMode: boolean;
|
|
10
12
|
parameterOptions?: Record<keyof T, ParameterOptions>;
|
|
11
13
|
}
|
|
14
|
+
export interface CreatePlan<T extends StringIndexedObject> extends Plan<T> {
|
|
15
|
+
desiredConfig: T;
|
|
16
|
+
currentConfig: null;
|
|
17
|
+
}
|
|
18
|
+
export interface DestroyPlan<T extends StringIndexedObject> extends Plan<T> {
|
|
19
|
+
desiredConfig: null;
|
|
20
|
+
currentConfig: T;
|
|
21
|
+
}
|
|
22
|
+
export interface ModifyPlan<T extends StringIndexedObject> extends Plan<T> {
|
|
23
|
+
desiredConfig: T;
|
|
24
|
+
currentConfig: T;
|
|
25
|
+
}
|
|
@@ -3,7 +3,7 @@ import { ParameterChange } from './change-set.js';
|
|
|
3
3
|
import { Plan } from './plan.js';
|
|
4
4
|
import { StatefulParameter } from './stateful-parameter.js';
|
|
5
5
|
import { ResourceParameterOptions, ValidationResult } from './resource-types.js';
|
|
6
|
-
import { ParameterOptions } from './plan-types.js';
|
|
6
|
+
import { CreatePlan, DestroyPlan, ModifyPlan, ParameterOptions } from './plan-types.js';
|
|
7
7
|
import { TransformParameter } from './transform-parameter.js';
|
|
8
8
|
import { ResourceOptions } from './resource-options.js';
|
|
9
9
|
import Ajv from 'ajv';
|
|
@@ -36,8 +36,8 @@ export declare abstract class Resource<T extends StringIndexedObject> {
|
|
|
36
36
|
private refreshStatefulParameters;
|
|
37
37
|
private validatePlanInputs;
|
|
38
38
|
validate(parameters: unknown): Promise<ValidationResult>;
|
|
39
|
-
abstract refresh(
|
|
40
|
-
abstract applyCreate(plan:
|
|
41
|
-
applyModify(pc: ParameterChange<T>, plan:
|
|
42
|
-
abstract applyDestroy(plan:
|
|
39
|
+
abstract refresh(values: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
|
|
40
|
+
abstract applyCreate(plan: CreatePlan<T>): Promise<void>;
|
|
41
|
+
applyModify(pc: ParameterChange<T>, plan: ModifyPlan<T>): Promise<void>;
|
|
42
|
+
abstract applyDestroy(plan: DestroyPlan<T>): Promise<void>;
|
|
43
43
|
}
|
package/package.json
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Plan } from './plan.js';
|
|
2
|
+
import { StringIndexedObject } from 'codify-schemas';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Customize properties for specific parameters. This will alter the way the library process changes to the parameter.
|
|
3
6
|
*/
|
|
@@ -24,3 +27,18 @@ export interface PlanOptions<T> {
|
|
|
24
27
|
statefulMode: boolean;
|
|
25
28
|
parameterOptions?: Record<keyof T, ParameterOptions>;
|
|
26
29
|
}
|
|
30
|
+
|
|
31
|
+
export interface CreatePlan<T extends StringIndexedObject> extends Plan<T> {
|
|
32
|
+
desiredConfig: T;
|
|
33
|
+
currentConfig: null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DestroyPlan<T extends StringIndexedObject> extends Plan<T> {
|
|
37
|
+
desiredConfig: null;
|
|
38
|
+
currentConfig: T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ModifyPlan<T extends StringIndexedObject> extends Plan<T> {
|
|
42
|
+
desiredConfig: T;
|
|
43
|
+
currentConfig: T;
|
|
44
|
+
}
|
|
@@ -6,6 +6,8 @@ import { describe, expect, it } from 'vitest'
|
|
|
6
6
|
import { ValidationResult } from './resource-types.js';
|
|
7
7
|
import { StatefulParameter } from './stateful-parameter.js';
|
|
8
8
|
import { ResourceOptions } from './resource-options.js';
|
|
9
|
+
import { CreatePlan, DestroyPlan, ModifyPlan } from './plan-types.js';
|
|
10
|
+
import { ParameterChange } from './change-set.js';
|
|
9
11
|
|
|
10
12
|
export interface TestConfig extends StringIndexedObject {
|
|
11
13
|
propA: string;
|
|
@@ -221,12 +223,15 @@ describe('Resource tests', () => {
|
|
|
221
223
|
async refresh(): Promise<string | null> {
|
|
222
224
|
return null;
|
|
223
225
|
}
|
|
226
|
+
|
|
224
227
|
applyAdd(valueToAdd: string, plan: Plan<TestConfig>): Promise<void> {
|
|
225
228
|
throw new Error('Method not implemented.');
|
|
226
229
|
}
|
|
230
|
+
|
|
227
231
|
applyModify(newValue: string, previousValue: string, allowDeletes: boolean, plan: Plan<TestConfig>): Promise<void> {
|
|
228
232
|
throw new Error('Method not implemented.');
|
|
229
233
|
}
|
|
234
|
+
|
|
230
235
|
applyRemove(valueToRemove: string, plan: Plan<TestConfig>): Promise<void> {
|
|
231
236
|
throw new Error('Method not implemented.');
|
|
232
237
|
}
|
|
@@ -252,12 +257,15 @@ describe('Resource tests', () => {
|
|
|
252
257
|
async refresh(): Promise<string | null> {
|
|
253
258
|
return null;
|
|
254
259
|
}
|
|
260
|
+
|
|
255
261
|
applyAdd(valueToAdd: string, plan: Plan<TestConfig>): Promise<void> {
|
|
256
262
|
throw new Error('Method not implemented.');
|
|
257
263
|
}
|
|
264
|
+
|
|
258
265
|
applyModify(newValue: string, previousValue: string, allowDeletes: boolean, plan: Plan<TestConfig>): Promise<void> {
|
|
259
266
|
throw new Error('Method not implemented.');
|
|
260
267
|
}
|
|
268
|
+
|
|
261
269
|
applyRemove(valueToRemove: string, plan: Plan<TestConfig>): Promise<void> {
|
|
262
270
|
throw new Error('Method not implemented.');
|
|
263
271
|
}
|
|
@@ -300,7 +308,7 @@ describe('Resource tests', () => {
|
|
|
300
308
|
}
|
|
301
309
|
}
|
|
302
310
|
|
|
303
|
-
const plan = await resource.plan({ type: 'resource'})
|
|
311
|
+
const plan = await resource.plan({ type: 'resource' })
|
|
304
312
|
expect(plan.currentConfig?.propA).to.eq('propAAfter');
|
|
305
313
|
expect(plan.desiredConfig?.propA).to.eq('propADefault');
|
|
306
314
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.RECREATE);
|
|
@@ -326,7 +334,7 @@ describe('Resource tests', () => {
|
|
|
326
334
|
}
|
|
327
335
|
}
|
|
328
336
|
|
|
329
|
-
const plan = await resource.plan({ type: 'resource'})
|
|
337
|
+
const plan = await resource.plan({ type: 'resource' })
|
|
330
338
|
expect(plan.currentConfig?.propE).to.eq('propEDefault');
|
|
331
339
|
expect(plan.desiredConfig?.propE).to.eq('propEDefault');
|
|
332
340
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
@@ -348,7 +356,7 @@ describe('Resource tests', () => {
|
|
|
348
356
|
}
|
|
349
357
|
}
|
|
350
358
|
|
|
351
|
-
const plan = await resource.plan({ type: 'resource'})
|
|
359
|
+
const plan = await resource.plan({ type: 'resource' })
|
|
352
360
|
expect(plan.currentConfig).to.be.null
|
|
353
361
|
expect(plan.desiredConfig!.propE).to.eq('propEDefault');
|
|
354
362
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.CREATE);
|
|
@@ -376,7 +384,7 @@ describe('Resource tests', () => {
|
|
|
376
384
|
}
|
|
377
385
|
}
|
|
378
386
|
|
|
379
|
-
const plan = await resource.plan({ type: 'resource', propA: 'propA'})
|
|
387
|
+
const plan = await resource.plan({ type: 'resource', propA: 'propA' })
|
|
380
388
|
expect(plan.currentConfig?.propA).to.eq('propAAfter');
|
|
381
389
|
expect(plan.desiredConfig?.propA).to.eq('propA');
|
|
382
390
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.RECREATE);
|
|
@@ -398,4 +406,29 @@ describe('Resource tests', () => {
|
|
|
398
406
|
propA: 'propADefault',
|
|
399
407
|
})
|
|
400
408
|
})
|
|
409
|
+
|
|
410
|
+
it('Has the correct typing for applys', () => {
|
|
411
|
+
const resource = new class extends Resource<TestConfig> {
|
|
412
|
+
constructor() {
|
|
413
|
+
super({ type: 'type' });
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async refresh(values: Map<keyof TestConfig, unknown>): Promise<Partial<TestConfig> | null> {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async applyCreate(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
421
|
+
plan.desiredConfig.propA
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
async applyDestroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
425
|
+
plan.currentConfig.propB
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async applyModify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
|
|
429
|
+
plan.desiredConfig.propA
|
|
430
|
+
plan.currentConfig.propB
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
})
|
|
401
434
|
});
|
package/src/entities/resource.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Plan } from './plan.js';
|
|
|
4
4
|
import { StatefulParameter } from './stateful-parameter.js';
|
|
5
5
|
import { ResourceParameterOptions, ValidationResult } from './resource-types.js';
|
|
6
6
|
import { setsEqual, splitUserConfig } from '../utils/utils.js';
|
|
7
|
-
import { ParameterOptions, PlanOptions } from './plan-types.js';
|
|
7
|
+
import { CreatePlan, DestroyPlan, ModifyPlan, ParameterOptions, PlanOptions } from './plan-types.js';
|
|
8
8
|
import { TransformParameter } from './transform-parameter.js';
|
|
9
9
|
import { ResourceOptions, ResourceOptionsParser } from './resource-options.js';
|
|
10
10
|
import Ajv from 'ajv';
|
|
@@ -147,7 +147,7 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
private async _applyCreate(plan: Plan<T>): Promise<void> {
|
|
150
|
-
await this.applyCreate(plan);
|
|
150
|
+
await this.applyCreate(plan as CreatePlan<T>);
|
|
151
151
|
|
|
152
152
|
const statefulParameterChanges = plan.changeSet.parameterChanges
|
|
153
153
|
.filter((pc: ParameterChange<T>) => this.statefulParameters.has(pc.name))
|
|
@@ -170,7 +170,7 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
170
170
|
|
|
171
171
|
for (const pc of statelessParameterChanges) {
|
|
172
172
|
// TODO: When stateful mode is added in the future. Dynamically choose if deletes are allowed
|
|
173
|
-
await this.applyModify(pc, plan);
|
|
173
|
+
await this.applyModify(pc, plan as ModifyPlan<T>);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
const statefulParameterChanges = parameterChanges
|
|
@@ -212,7 +212,7 @@ export abstract class Resource<T extends StringIndexedObject> {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
await this.applyDestroy(plan);
|
|
215
|
+
await this.applyDestroy(plan as DestroyPlan<T>);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
private validateRefreshResults(refresh: Partial<T> | null, desiredMap: Map<keyof T, T[keyof T]>) {
|
|
@@ -346,13 +346,13 @@ Additional: ${[...refreshKeys].filter(k => !desiredKeys.has(k))};`
|
|
|
346
346
|
}
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
-
abstract refresh(
|
|
349
|
+
abstract refresh(values: Map<keyof T, T[keyof T]>): Promise<Partial<T> | null>;
|
|
350
350
|
|
|
351
|
-
abstract applyCreate(plan:
|
|
351
|
+
abstract applyCreate(plan: CreatePlan<T>): Promise<void>;
|
|
352
352
|
|
|
353
|
-
async applyModify(pc: ParameterChange<T>, plan:
|
|
353
|
+
async applyModify(pc: ParameterChange<T>, plan: ModifyPlan<T>): Promise<void> {};
|
|
354
354
|
|
|
355
|
-
abstract applyDestroy(plan:
|
|
355
|
+
abstract applyDestroy(plan: DestroyPlan<T>): Promise<void>;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
class ConfigParser<T extends StringIndexedObject> {
|