codify-plugin-lib 1.0.13 → 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.
@@ -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: ResourceConfig;
7
- constructor(id: string, changeSet: ChangeSet, resourceConfig: ResourceConfig);
8
- static create(changeSet: ChangeSet, resourceConfig: ResourceConfig): Plan;
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>;
@@ -6,13 +6,13 @@ export declare abstract class Resource<T extends ResourceConfig> {
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(plan: Plan): Promise<void>;
15
- abstract applyModify(plan: Plan): Promise<void>;
16
- abstract applyRecreate(plan: Plan): Promise<void>;
17
- abstract applyDestroy(plan: Plan): Promise<void>;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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: ResourceConfig
11
+ resourceConfig: T
12
12
 
13
- constructor(id: string, changeSet: ChangeSet, resourceConfig: 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: ResourceConfig) {
19
+ static create<T extends ResourceConfig>(changeSet: ChangeSet, resourceConfig: T): Plan<T> {
20
20
  return new Plan(
21
21
  randomUUID(),
22
22
  changeSet,
@@ -10,7 +10,7 @@ import {
10
10
  import { Plan } from './plan';
11
11
 
12
12
  export class Plugin {
13
- planStorage: Map<string, Plan>;
13
+ planStorage: Map<string, Plan<ResourceConfig>>;
14
14
 
15
15
  constructor(
16
16
  public resources: Map<string, Resource<ResourceConfig>>
@@ -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,7 +42,7 @@ 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
  }
@@ -61,11 +61,11 @@ export abstract class Resource<T extends ResourceConfig> {
61
61
 
62
62
  abstract calculateOperation(change: ParameterChange): ResourceOperation.MODIFY | ResourceOperation.RECREATE;
63
63
 
64
- abstract applyCreate(plan: Plan): Promise<void>;
64
+ abstract applyCreate(plan: Plan<T>): Promise<void>;
65
65
 
66
- abstract applyModify(plan: Plan): Promise<void>;
66
+ abstract applyModify(plan: Plan<T>): Promise<void>;
67
67
 
68
- abstract applyRecreate(plan: Plan): Promise<void>;
68
+ abstract applyRecreate(plan: Plan<T>): Promise<void>;
69
69
 
70
- abstract applyDestroy(plan:Plan): Promise<void>;
70
+ abstract applyDestroy(plan:Plan<T>): Promise<void>;
71
71
  }