codify-plugin-lib 1.0.12 → 1.0.14
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/dist/entities/plan.d.ts +4 -4
- package/dist/entities/plugin.d.ts +1 -1
- package/dist/entities/resource.d.ts +7 -7
- package/dist/entities/resource.js +4 -5
- package/package.json +1 -1
- package/src/entities/plan.ts +4 -4
- package/src/entities/plugin.ts +1 -1
- package/src/entities/resource.test.ts +4 -4
- package/src/entities/resource.ts +10 -11
package/dist/entities/plan.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ChangeSet } from './change-set';
|
|
2
2
|
import { PlanResponseData, ResourceConfig } from 'codify-schemas';
|
|
3
|
-
export declare class Plan {
|
|
3
|
+
export declare class Plan<T extends ResourceConfig> {
|
|
4
4
|
id: string;
|
|
5
5
|
changeSet: ChangeSet;
|
|
6
|
-
resourceConfig:
|
|
7
|
-
constructor(id: string, changeSet: ChangeSet, resourceConfig:
|
|
8
|
-
static create(changeSet: ChangeSet, resourceConfig:
|
|
6
|
+
resourceConfig: T;
|
|
7
|
+
constructor(id: string, changeSet: ChangeSet, resourceConfig: T);
|
|
8
|
+
static create<T extends ResourceConfig>(changeSet: ChangeSet, resourceConfig: T): Plan<T>;
|
|
9
9
|
getResourceType(): string;
|
|
10
10
|
toResponse(): PlanResponseData;
|
|
11
11
|
}
|
|
@@ -3,7 +3,7 @@ import { ApplyRequestData, PlanRequestData, PlanResponseData, ResourceConfig, Va
|
|
|
3
3
|
import { Plan } from './plan';
|
|
4
4
|
export declare class Plugin {
|
|
5
5
|
resources: Map<string, Resource<ResourceConfig>>;
|
|
6
|
-
planStorage: Map<string, Plan
|
|
6
|
+
planStorage: Map<string, Plan<ResourceConfig>>;
|
|
7
7
|
constructor(resources: Map<string, Resource<ResourceConfig>>);
|
|
8
8
|
onInitialize(): Promise<void>;
|
|
9
9
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { ResourceConfig, ResourceOperation } from 'codify-schemas';
|
|
2
|
-
import {
|
|
2
|
+
import { ParameterChange } from './change-set';
|
|
3
3
|
import { Plan } from './plan';
|
|
4
4
|
export declare abstract class Resource<T extends ResourceConfig> {
|
|
5
5
|
private dependencies;
|
|
6
6
|
constructor(dependencies?: Resource<any>[]);
|
|
7
7
|
abstract getTypeId(): string;
|
|
8
8
|
onInitialize(): Promise<void>;
|
|
9
|
-
plan(desiredConfig: T): Promise<Plan
|
|
10
|
-
apply(plan: Plan): Promise<void>;
|
|
9
|
+
plan(desiredConfig: T): Promise<Plan<T>>;
|
|
10
|
+
apply(plan: Plan<T>): Promise<void>;
|
|
11
11
|
abstract validate(config: ResourceConfig): Promise<boolean>;
|
|
12
12
|
abstract getCurrentConfig(): Promise<T | null>;
|
|
13
13
|
abstract calculateOperation(change: ParameterChange): ResourceOperation.MODIFY | ResourceOperation.RECREATE;
|
|
14
|
-
abstract applyCreate(
|
|
15
|
-
abstract applyModify(
|
|
16
|
-
abstract applyRecreate(
|
|
17
|
-
abstract applyDestroy(
|
|
14
|
+
abstract applyCreate(plan: Plan<T>): Promise<void>;
|
|
15
|
+
abstract applyModify(plan: Plan<T>): Promise<void>;
|
|
16
|
+
abstract applyRecreate(plan: Plan<T>): Promise<void>;
|
|
17
|
+
abstract applyDestroy(plan: Plan<T>): Promise<void>;
|
|
18
18
|
}
|
|
@@ -29,12 +29,11 @@ class Resource {
|
|
|
29
29
|
if (plan.getResourceType() !== this.getTypeId()) {
|
|
30
30
|
throw new Error(`Internal error: Plan set to wrong resource during apply. Expected ${this.getTypeId()} but got: ${plan.getResourceType()}`);
|
|
31
31
|
}
|
|
32
|
-
const changeSet = plan.changeSet;
|
|
33
32
|
switch (plan.changeSet.operation) {
|
|
34
|
-
case codify_schemas_1.ResourceOperation.CREATE: return this.applyCreate(
|
|
35
|
-
case codify_schemas_1.ResourceOperation.MODIFY: return this.applyModify(
|
|
36
|
-
case codify_schemas_1.ResourceOperation.RECREATE: return this.applyRecreate(
|
|
37
|
-
case codify_schemas_1.ResourceOperation.DESTROY: return this.applyDestroy(
|
|
33
|
+
case codify_schemas_1.ResourceOperation.CREATE: return this.applyCreate(plan);
|
|
34
|
+
case codify_schemas_1.ResourceOperation.MODIFY: return this.applyModify(plan);
|
|
35
|
+
case codify_schemas_1.ResourceOperation.RECREATE: return this.applyRecreate(plan);
|
|
36
|
+
case codify_schemas_1.ResourceOperation.DESTROY: return this.applyDestroy(plan);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
}
|
package/package.json
CHANGED
package/src/entities/plan.ts
CHANGED
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
} from 'codify-schemas';
|
|
6
6
|
import { randomUUID } from 'crypto';
|
|
7
7
|
|
|
8
|
-
export class Plan {
|
|
8
|
+
export class Plan<T extends ResourceConfig> {
|
|
9
9
|
id: string;
|
|
10
10
|
changeSet: ChangeSet;
|
|
11
|
-
resourceConfig:
|
|
11
|
+
resourceConfig: T
|
|
12
12
|
|
|
13
|
-
constructor(id: string, changeSet: ChangeSet, resourceConfig:
|
|
13
|
+
constructor(id: string, changeSet: ChangeSet, resourceConfig: T) {
|
|
14
14
|
this.id = id;
|
|
15
15
|
this.changeSet = changeSet;
|
|
16
16
|
this.resourceConfig = resourceConfig;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
static create(changeSet: ChangeSet, resourceConfig:
|
|
19
|
+
static create<T extends ResourceConfig>(changeSet: ChangeSet, resourceConfig: T): Plan<T> {
|
|
20
20
|
return new Plan(
|
|
21
21
|
randomUUID(),
|
|
22
22
|
changeSet,
|
package/src/entities/plugin.ts
CHANGED
|
@@ -7,19 +7,19 @@ import { expect } from 'chai';
|
|
|
7
7
|
import { Plan } from './plan';
|
|
8
8
|
|
|
9
9
|
class TestResource extends Resource<TestConfig> {
|
|
10
|
-
applyCreate(
|
|
10
|
+
applyCreate(plan: Plan): Promise<void> {
|
|
11
11
|
return Promise.resolve(undefined);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
applyDestroy(
|
|
14
|
+
applyDestroy(plan: Plan): Promise<void> {
|
|
15
15
|
return Promise.resolve(undefined);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
applyModify(
|
|
18
|
+
applyModify(plan: Plan): Promise<void> {
|
|
19
19
|
return Promise.resolve(undefined);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
applyRecreate(
|
|
22
|
+
applyRecreate(plan: Plan): Promise<void> {
|
|
23
23
|
return Promise.resolve(undefined);
|
|
24
24
|
}
|
|
25
25
|
|
package/src/entities/resource.ts
CHANGED
|
@@ -14,7 +14,7 @@ export abstract class Resource<T extends ResourceConfig> {
|
|
|
14
14
|
|
|
15
15
|
// TODO: Add state in later.
|
|
16
16
|
// Calculate change set from current config -> state -> desired in the future
|
|
17
|
-
async plan(desiredConfig: T): Promise<Plan
|
|
17
|
+
async plan(desiredConfig: T): Promise<Plan<T>> {
|
|
18
18
|
await this.validate(desiredConfig);
|
|
19
19
|
|
|
20
20
|
const currentConfig = await this.getCurrentConfig();
|
|
@@ -42,17 +42,16 @@ export abstract class Resource<T extends ResourceConfig> {
|
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async apply(plan: Plan): Promise<void> {
|
|
45
|
+
async apply(plan: Plan<T>): Promise<void> {
|
|
46
46
|
if (plan.getResourceType() !== this.getTypeId()) {
|
|
47
47
|
throw new Error(`Internal error: Plan set to wrong resource during apply. Expected ${this.getTypeId()} but got: ${plan.getResourceType()}`);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const changeSet = plan.changeSet;
|
|
51
50
|
switch (plan.changeSet.operation) {
|
|
52
|
-
case ResourceOperation.CREATE: return this.applyCreate(
|
|
53
|
-
case ResourceOperation.MODIFY: return this.applyModify(
|
|
54
|
-
case ResourceOperation.RECREATE: return this.applyRecreate(
|
|
55
|
-
case ResourceOperation.DESTROY: return this.applyDestroy(
|
|
51
|
+
case ResourceOperation.CREATE: return this.applyCreate(plan);
|
|
52
|
+
case ResourceOperation.MODIFY: return this.applyModify(plan);
|
|
53
|
+
case ResourceOperation.RECREATE: return this.applyRecreate(plan);
|
|
54
|
+
case ResourceOperation.DESTROY: return this.applyDestroy(plan);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|
|
@@ -62,11 +61,11 @@ export abstract class Resource<T extends ResourceConfig> {
|
|
|
62
61
|
|
|
63
62
|
abstract calculateOperation(change: ParameterChange): ResourceOperation.MODIFY | ResourceOperation.RECREATE;
|
|
64
63
|
|
|
65
|
-
abstract applyCreate(
|
|
64
|
+
abstract applyCreate(plan: Plan<T>): Promise<void>;
|
|
66
65
|
|
|
67
|
-
abstract applyModify(
|
|
66
|
+
abstract applyModify(plan: Plan<T>): Promise<void>;
|
|
68
67
|
|
|
69
|
-
abstract applyRecreate(
|
|
68
|
+
abstract applyRecreate(plan: Plan<T>): Promise<void>;
|
|
70
69
|
|
|
71
|
-
abstract applyDestroy(
|
|
70
|
+
abstract applyDestroy(plan:Plan<T>): Promise<void>;
|
|
72
71
|
}
|