codify-plugin-lib 1.0.15 → 1.0.16
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.
|
@@ -12,4 +12,5 @@ export declare class ChangeSet {
|
|
|
12
12
|
static createForNullCurrentConfig(desiredConfig: ResourceConfig): ChangeSet;
|
|
13
13
|
static calculateParameterChangeSet(prev: ResourceConfig, next: ResourceConfig): ParameterChange[];
|
|
14
14
|
static combineResourceOperations(prev: ResourceOperation, next: ResourceOperation): ResourceOperation;
|
|
15
|
+
static isSame(a: unknown, b: unknown): boolean;
|
|
15
16
|
}
|
|
@@ -39,7 +39,7 @@ class ChangeSet {
|
|
|
39
39
|
delete filteredPrev[k];
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
if (filteredPrev[k]
|
|
42
|
+
if (!ChangeSet.isSame(filteredPrev[k], filteredNext[k])) {
|
|
43
43
|
parameterChangeSet.push({
|
|
44
44
|
name: k,
|
|
45
45
|
previousValue: v,
|
|
@@ -84,5 +84,13 @@ class ChangeSet {
|
|
|
84
84
|
const indexNext = orderOfOperations.indexOf(next);
|
|
85
85
|
return orderOfOperations[Math.max(indexPrev, indexNext)];
|
|
86
86
|
}
|
|
87
|
+
static isSame(a, b) {
|
|
88
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
89
|
+
const sortedPrev = a.map((x) => x).sort();
|
|
90
|
+
const sortedNext = b.map((x) => x).sort();
|
|
91
|
+
return JSON.stringify(sortedPrev) === JSON.stringify(sortedNext);
|
|
92
|
+
}
|
|
93
|
+
return a === b;
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
exports.ChangeSet = ChangeSet;
|
package/package.json
CHANGED
|
@@ -74,6 +74,38 @@ describe('Change set tests', () => {
|
|
|
74
74
|
expect(cs[0].operation).to.eq(ParameterOperation.NOOP);
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
+
it ('handles simple arrays', () => {
|
|
78
|
+
const before = {
|
|
79
|
+
type: 'config',
|
|
80
|
+
propA: ['a', 'b', 'c'],
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const after = {
|
|
84
|
+
type: 'config',
|
|
85
|
+
propA: ['b', 'a', 'c'],
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const cs = ChangeSet.calculateParameterChangeSet(before, after);
|
|
89
|
+
expect(cs.length).to.eq(1);
|
|
90
|
+
expect(cs[0].operation).to.eq(ParameterOperation.NOOP);
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it ('handles simple arrays', () => {
|
|
94
|
+
const before = {
|
|
95
|
+
type: 'config',
|
|
96
|
+
propA: ['a', 'b'],
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const after = {
|
|
100
|
+
type: 'config',
|
|
101
|
+
propA: ['b', 'a', 'c'],
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const cs = ChangeSet.calculateParameterChangeSet(before, after);
|
|
105
|
+
expect(cs.length).to.eq(1);
|
|
106
|
+
expect(cs[0].operation).to.eq(ParameterOperation.MODIFY);
|
|
107
|
+
})
|
|
108
|
+
|
|
77
109
|
it ('determines the order of operations 1', () => {
|
|
78
110
|
const op1 = ResourceOperation.MODIFY;
|
|
79
111
|
const op2 = ResourceOperation.CREATE
|
|
@@ -97,4 +129,39 @@ describe('Change set tests', () => {
|
|
|
97
129
|
const opResult = ChangeSet.combineResourceOperations(op1, op2);
|
|
98
130
|
expect(opResult).to.eq(ResourceOperation.MODIFY);
|
|
99
131
|
})
|
|
132
|
+
|
|
133
|
+
it('correctly determines array equality', () => {
|
|
134
|
+
const arrA = ['a', 'b', 'd'];
|
|
135
|
+
const arrB = ['a', 'b', 'd'];
|
|
136
|
+
|
|
137
|
+
expect(ChangeSet.isSame(arrA, arrB)).to.be.true;
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('correctly determines array equality 2', () => {
|
|
141
|
+
const arrA = ['a', 'b'];
|
|
142
|
+
const arrB = ['a', 'b', 'd'];
|
|
143
|
+
|
|
144
|
+
expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('correctly determines array equality 3', () => {
|
|
148
|
+
const arrA = ['b', 'a', 'd'];
|
|
149
|
+
const arrB = ['a', 'b', 'd'];
|
|
150
|
+
|
|
151
|
+
expect(ChangeSet.isSame(arrA, arrB)).to.be.true;
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('correctly determines array equality 4', () => {
|
|
155
|
+
const arrA = [{ key1: 'a' }, { key1: 'a' }, { key1: 'a' }];
|
|
156
|
+
const arrB = [{ key1: 'a' }, { key1: 'a' }, { key1: 'b' }];
|
|
157
|
+
|
|
158
|
+
expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('correctly determines array equality 5', () => {
|
|
162
|
+
const arrA = [{ key1: 'b' }, { key1: 'a' }, { key1: 'a' }];
|
|
163
|
+
const arrB = [{ key1: 'a' }, { key1: 'a' }, { key1: 'b' }];
|
|
164
|
+
|
|
165
|
+
expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
|
|
166
|
+
})
|
|
100
167
|
})
|
|
@@ -60,7 +60,7 @@ export class ChangeSet {
|
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (filteredPrev[k]
|
|
63
|
+
if (!ChangeSet.isSame(filteredPrev[k], filteredNext[k])) {
|
|
64
64
|
parameterChangeSet.push({
|
|
65
65
|
name: k,
|
|
66
66
|
previousValue: v,
|
|
@@ -114,4 +114,15 @@ export class ChangeSet {
|
|
|
114
114
|
|
|
115
115
|
return orderOfOperations[Math.max(indexPrev, indexNext)];
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
static isSame(a: unknown, b: unknown): boolean {
|
|
119
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
120
|
+
const sortedPrev = a.map((x) => x).sort();
|
|
121
|
+
const sortedNext = b.map((x) => x).sort();
|
|
122
|
+
|
|
123
|
+
return JSON.stringify(sortedPrev) === JSON.stringify(sortedNext);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return a === b;
|
|
127
|
+
}
|
|
117
128
|
}
|