codify-plugin-lib 1.0.41 → 1.0.42
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/change-set.d.ts +1 -1
- package/dist/entities/change-set.js +16 -10
- package/dist/entities/plan-types.d.ts +1 -0
- package/dist/entities/stateful-parameter.d.ts +6 -2
- package/package.json +1 -1
- package/src/entities/change-set.ts +22 -12
- package/src/entities/plan-types.ts +2 -0
- package/src/entities/stateful-parameter.ts +9 -2
|
@@ -18,7 +18,7 @@ export declare class ChangeSet<T extends StringIndexedObject> {
|
|
|
18
18
|
parameterConfigurations?: Record<keyof T, ParameterConfiguration>;
|
|
19
19
|
}): ParameterChange<T>[];
|
|
20
20
|
static combineResourceOperations(prev: ResourceOperation, next: ResourceOperation): ResourceOperation;
|
|
21
|
-
static isSame(
|
|
21
|
+
static isSame(desired: unknown, current: unknown, configuration?: ParameterConfiguration): boolean;
|
|
22
22
|
private static calculateStatefulModeChangeSet;
|
|
23
23
|
private static calculateStatelessModeChangeSet;
|
|
24
24
|
}
|
|
@@ -53,16 +53,22 @@ export class ChangeSet {
|
|
|
53
53
|
const indexNext = orderOfOperations.indexOf(next);
|
|
54
54
|
return orderOfOperations[Math.max(indexPrev, indexNext)];
|
|
55
55
|
}
|
|
56
|
-
static isSame(
|
|
57
|
-
if (isEqual) {
|
|
58
|
-
return isEqual(
|
|
56
|
+
static isSame(desired, current, configuration) {
|
|
57
|
+
if (configuration?.isEqual) {
|
|
58
|
+
return configuration.isEqual(desired, current);
|
|
59
59
|
}
|
|
60
|
-
if (Array.isArray(
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
60
|
+
if (Array.isArray(desired) && Array.isArray(current)) {
|
|
61
|
+
const sortedDesired = desired.map((x) => x).sort();
|
|
62
|
+
const sortedCurrent = current.map((x) => x).sort();
|
|
63
|
+
if (sortedDesired.length !== sortedCurrent.length) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (configuration?.isElementEqual) {
|
|
67
|
+
return sortedDesired.every((value, index) => configuration.isElementEqual(value, sortedCurrent[index]));
|
|
68
|
+
}
|
|
69
|
+
return JSON.stringify(sortedDesired) === JSON.stringify(sortedCurrent);
|
|
64
70
|
}
|
|
65
|
-
return
|
|
71
|
+
return desired === current;
|
|
66
72
|
}
|
|
67
73
|
static calculateStatefulModeChangeSet(desired, current, parameterConfigurations) {
|
|
68
74
|
const parameterChangeSet = new Array();
|
|
@@ -79,7 +85,7 @@ export class ChangeSet {
|
|
|
79
85
|
delete _current[k];
|
|
80
86
|
continue;
|
|
81
87
|
}
|
|
82
|
-
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]
|
|
88
|
+
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k])) {
|
|
83
89
|
parameterChangeSet.push({
|
|
84
90
|
name: k,
|
|
85
91
|
previousValue: v,
|
|
@@ -126,7 +132,7 @@ export class ChangeSet {
|
|
|
126
132
|
});
|
|
127
133
|
continue;
|
|
128
134
|
}
|
|
129
|
-
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]
|
|
135
|
+
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k])) {
|
|
130
136
|
parameterChangeSet.push({
|
|
131
137
|
name: k,
|
|
132
138
|
previousValue: _current[k],
|
|
@@ -2,6 +2,7 @@ import { ResourceOperation } from 'codify-schemas';
|
|
|
2
2
|
export interface ParameterConfiguration {
|
|
3
3
|
planOperation?: ResourceOperation.MODIFY | ResourceOperation.RECREATE;
|
|
4
4
|
isEqual?: (desired: any, current: any) => boolean;
|
|
5
|
+
isElementEqual?: (desired: any, current: any) => boolean;
|
|
5
6
|
isStatefulParameter?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export interface PlanConfiguration<T> {
|
|
@@ -2,7 +2,11 @@ import { Plan } from './plan.js';
|
|
|
2
2
|
import { StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
export interface StatefulParameterConfiguration<T> {
|
|
4
4
|
name: keyof T;
|
|
5
|
-
isEqual?: (
|
|
5
|
+
isEqual?: (desired: any, current: any) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ArrayStatefulParameterConfiguration<T> extends StatefulParameterConfiguration<T> {
|
|
8
|
+
isEqual?: (desired: any[], current: any[]) => boolean;
|
|
9
|
+
isElementEqual?: (desired: any, current: any) => boolean;
|
|
6
10
|
}
|
|
7
11
|
export declare abstract class StatefulParameter<T extends StringIndexedObject, V extends T[keyof T]> {
|
|
8
12
|
readonly name: keyof T;
|
|
@@ -14,7 +18,7 @@ export declare abstract class StatefulParameter<T extends StringIndexedObject, V
|
|
|
14
18
|
abstract applyRemove(valueToRemove: V, plan: Plan<T>): Promise<void>;
|
|
15
19
|
}
|
|
16
20
|
export declare abstract class ArrayStatefulParameter<T extends StringIndexedObject, V> extends StatefulParameter<T, any> {
|
|
17
|
-
|
|
21
|
+
constructor(configuration: ArrayStatefulParameterConfiguration<T>);
|
|
18
22
|
applyAdd(valuesToAdd: V[], plan: Plan<T>): Promise<void>;
|
|
19
23
|
applyModify(newValues: V[], previousValues: V[], allowDeletes: boolean, plan: Plan<T>): Promise<void>;
|
|
20
24
|
applyRemove(valuesToRemove: V[], plan: Plan<T>): Promise<void>;
|
package/package.json
CHANGED
|
@@ -86,22 +86,32 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
static isSame(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
desired: unknown,
|
|
90
|
+
current: unknown,
|
|
91
|
+
configuration?: ParameterConfiguration,
|
|
92
92
|
): boolean {
|
|
93
|
-
if (isEqual) {
|
|
94
|
-
return isEqual(
|
|
93
|
+
if (configuration?.isEqual) {
|
|
94
|
+
return configuration.isEqual(desired, current);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
if (Array.isArray(
|
|
98
|
-
const
|
|
99
|
-
const
|
|
97
|
+
if (Array.isArray(desired) && Array.isArray(current)) {
|
|
98
|
+
const sortedDesired = desired.map((x) => x).sort();
|
|
99
|
+
const sortedCurrent = current.map((x) => x).sort();
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
if (sortedDesired.length !== sortedCurrent.length) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (configuration?.isElementEqual) {
|
|
106
|
+
return sortedDesired.every((value, index) =>
|
|
107
|
+
configuration.isElementEqual!(value, sortedCurrent[index])
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return JSON.stringify(sortedDesired) === JSON.stringify(sortedCurrent);
|
|
102
112
|
}
|
|
103
113
|
|
|
104
|
-
return
|
|
114
|
+
return desired === current;
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
// Explanation: Stateful mode means that codify maintains a stateful to keep track of resources it has added.
|
|
@@ -130,7 +140,7 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
130
140
|
continue;
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]
|
|
143
|
+
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k])) {
|
|
134
144
|
parameterChangeSet.push({
|
|
135
145
|
name: k,
|
|
136
146
|
previousValue: v,
|
|
@@ -194,7 +204,7 @@ export class ChangeSet<T extends StringIndexedObject> {
|
|
|
194
204
|
continue;
|
|
195
205
|
}
|
|
196
206
|
|
|
197
|
-
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k]
|
|
207
|
+
if (!ChangeSet.isSame(_desired[k], _current[k], parameterConfigurations?.[k])) {
|
|
198
208
|
parameterChangeSet.push({
|
|
199
209
|
name: k,
|
|
200
210
|
previousValue: _current[k],
|
|
@@ -3,9 +3,15 @@ import { StringIndexedObject } from 'codify-schemas';
|
|
|
3
3
|
|
|
4
4
|
export interface StatefulParameterConfiguration<T> {
|
|
5
5
|
name: keyof T;
|
|
6
|
-
isEqual?: (
|
|
6
|
+
isEqual?: (desired: any, current: any) => boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export interface ArrayStatefulParameterConfiguration<T> extends StatefulParameterConfiguration<T> {
|
|
10
|
+
isEqual?: (desired: any[], current: any[]) => boolean;
|
|
11
|
+
isElementEqual?: (desired: any, current: any) => boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
9
15
|
export abstract class StatefulParameter<T extends StringIndexedObject, V extends T[keyof T]> {
|
|
10
16
|
readonly name: keyof T;
|
|
11
17
|
readonly configuration: StatefulParameterConfiguration<T>;
|
|
@@ -24,7 +30,8 @@ export abstract class StatefulParameter<T extends StringIndexedObject, V extends
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export abstract class ArrayStatefulParameter<T extends StringIndexedObject, V> extends StatefulParameter<T, any>{
|
|
27
|
-
|
|
33
|
+
|
|
34
|
+
constructor(configuration: ArrayStatefulParameterConfiguration<T>) {
|
|
28
35
|
super(configuration);
|
|
29
36
|
}
|
|
30
37
|
|