@featurevisor/core 1.13.0 → 1.14.0
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/.eslintcache +1 -1
- package/CHANGELOG.md +22 -0
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
- package/coverage/lcov-report/lib/builder/index.html +1 -1
- package/coverage/lcov-report/lib/builder/revision.js.html +1 -1
- package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
- package/coverage/lcov-report/lib/tester/checkIfObjectsAreEqual.js.html +1 -1
- package/coverage/lcov-report/lib/tester/index.html +1 -1
- package/coverage/lcov-report/lib/tester/matrix.js.html +1 -1
- package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
- package/coverage/lcov-report/src/builder/index.html +1 -1
- package/coverage/lcov-report/src/builder/revision.ts.html +1 -1
- package/coverage/lcov-report/src/builder/traffic.ts.html +1 -1
- package/coverage/lcov-report/src/tester/checkIfObjectsAreEqual.ts.html +1 -1
- package/coverage/lcov-report/src/tester/index.html +1 -1
- package/coverage/lcov-report/src/tester/matrix.ts.html +1 -1
- package/lib/benchmark/index.d.ts +18 -0
- package/lib/benchmark/index.js +139 -0
- package/lib/benchmark/index.js.map +1 -0
- package/lib/find-usage/index.d.ts +14 -0
- package/lib/find-usage/index.js +164 -136
- package/lib/find-usage/index.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/benchmark/index.ts +150 -0
- package/src/find-usage/index.ts +131 -76
- package/src/index.ts +1 -0
package/lib/find-usage/index.js
CHANGED
|
@@ -36,27 +36,54 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.findUsageInProject = exports.findUnusedAttributes = exports.findUnusedSegments = exports.findAttributeUsage = exports.findSegmentUsage = void 0;
|
|
39
|
+
exports.findUsageInProject = exports.findUnusedAttributes = exports.findUnusedSegments = exports.findAttributeUsage = exports.findSegmentUsage = exports.findAllUsageInSegments = exports.findAllUsageInFeatures = void 0;
|
|
40
40
|
var extractKeys_1 = require("../utils/extractKeys");
|
|
41
|
-
function
|
|
41
|
+
function findAllUsageInFeatures(deps) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var datasource, projectConfig,
|
|
43
|
+
var datasource, projectConfig, usageInFeatures, featureKeys, _loop_1, _i, featureKeys_1, featureKey;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
45
|
switch (_a.label) {
|
|
46
46
|
case 0:
|
|
47
47
|
datasource = deps.datasource, projectConfig = deps.projectConfig;
|
|
48
|
+
usageInFeatures = {};
|
|
48
49
|
return [4 /*yield*/, datasource.listFeatures()];
|
|
49
50
|
case 1:
|
|
50
51
|
featureKeys = _a.sent();
|
|
51
|
-
usedInFeatures = new Set();
|
|
52
52
|
_loop_1 = function (featureKey) {
|
|
53
|
-
var feature
|
|
53
|
+
var feature;
|
|
54
54
|
return __generator(this, function (_b) {
|
|
55
55
|
switch (_b.label) {
|
|
56
56
|
case 0: return [4 /*yield*/, datasource.readFeature(featureKey)];
|
|
57
57
|
case 1:
|
|
58
58
|
feature = _b.sent();
|
|
59
|
-
|
|
59
|
+
usageInFeatures[featureKey] = {
|
|
60
|
+
features: new Set(),
|
|
61
|
+
segments: new Set(),
|
|
62
|
+
attributes: new Set(),
|
|
63
|
+
};
|
|
64
|
+
// required
|
|
65
|
+
if (feature.required) {
|
|
66
|
+
feature.required.forEach(function (required) {
|
|
67
|
+
if (typeof required === "string") {
|
|
68
|
+
usageInFeatures[featureKey].features.add(required);
|
|
69
|
+
}
|
|
70
|
+
else if (typeof required === "object" && required.key) {
|
|
71
|
+
usageInFeatures[featureKey].features.add(required.key);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// bucketBy
|
|
76
|
+
if (feature.bucketBy) {
|
|
77
|
+
if (typeof feature.bucketBy === "string") {
|
|
78
|
+
usageInFeatures[featureKey].attributes.add(feature.bucketBy);
|
|
79
|
+
}
|
|
80
|
+
else if (Array.isArray(feature.bucketBy)) {
|
|
81
|
+
feature.bucketBy.forEach(function (b) { return usageInFeatures[featureKey].attributes.add(b); });
|
|
82
|
+
}
|
|
83
|
+
else if (typeof feature.bucketBy === "object" && feature.bucketBy.or) {
|
|
84
|
+
feature.bucketBy.or.forEach(function (b) { return usageInFeatures[featureKey].attributes.add(b); });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
60
87
|
// variable overrides inside variations
|
|
61
88
|
projectConfig.environments.forEach(function (environment) {
|
|
62
89
|
var _a, _b;
|
|
@@ -68,9 +95,12 @@ function findSegmentUsage(deps, segmentKey) {
|
|
|
68
95
|
variable.overrides.forEach(function (override) {
|
|
69
96
|
if (override.segments) {
|
|
70
97
|
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(override.segments).forEach(function (segmentKey) {
|
|
71
|
-
return
|
|
98
|
+
return usageInFeatures[featureKey].segments.add(segmentKey);
|
|
72
99
|
});
|
|
73
100
|
}
|
|
101
|
+
if (override.conditions) {
|
|
102
|
+
(0, extractKeys_1.extractAttributeKeysFromConditions)(override.conditions).forEach(function (attributeKey) { return usageInFeatures[featureKey].attributes.add(attributeKey); });
|
|
103
|
+
}
|
|
74
104
|
});
|
|
75
105
|
}
|
|
76
106
|
});
|
|
@@ -82,7 +112,12 @@ function findSegmentUsage(deps, segmentKey) {
|
|
|
82
112
|
(_a = feature.environments[environment].force) === null || _a === void 0 ? void 0 : _a.forEach(function (force) {
|
|
83
113
|
if (force.segments) {
|
|
84
114
|
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(force.segments).forEach(function (segmentKey) {
|
|
85
|
-
return
|
|
115
|
+
return usageInFeatures[featureKey].segments.add(segmentKey);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (force.conditions) {
|
|
119
|
+
(0, extractKeys_1.extractAttributeKeysFromConditions)(force.conditions).forEach(function (attributeKey) {
|
|
120
|
+
return usageInFeatures[featureKey].attributes.add(attributeKey);
|
|
86
121
|
});
|
|
87
122
|
}
|
|
88
123
|
});
|
|
@@ -91,14 +126,11 @@ function findSegmentUsage(deps, segmentKey) {
|
|
|
91
126
|
if (feature.environments[environment].rules) {
|
|
92
127
|
(_b = feature.environments[environment].rules) === null || _b === void 0 ? void 0 : _b.forEach(function (rule) {
|
|
93
128
|
(0, extractKeys_1.extractSegmentKeysFromGroupSegments)(rule.segments).forEach(function (segmentKey) {
|
|
94
|
-
return
|
|
129
|
+
return usageInFeatures[featureKey].segments.add(segmentKey);
|
|
95
130
|
});
|
|
96
131
|
});
|
|
97
132
|
}
|
|
98
133
|
});
|
|
99
|
-
if (segmentKeys.has(segmentKey)) {
|
|
100
|
-
usedInFeatures.add(featureKey);
|
|
101
|
-
}
|
|
102
134
|
return [2 /*return*/];
|
|
103
135
|
}
|
|
104
136
|
});
|
|
@@ -115,116 +147,106 @@ function findSegmentUsage(deps, segmentKey) {
|
|
|
115
147
|
case 4:
|
|
116
148
|
_i++;
|
|
117
149
|
return [3 /*break*/, 2];
|
|
118
|
-
case 5: return [2 /*return*/,
|
|
150
|
+
case 5: return [2 /*return*/, usageInFeatures];
|
|
119
151
|
}
|
|
120
152
|
});
|
|
121
153
|
});
|
|
122
154
|
}
|
|
123
|
-
exports.
|
|
124
|
-
function
|
|
155
|
+
exports.findAllUsageInFeatures = findAllUsageInFeatures;
|
|
156
|
+
function findAllUsageInSegments(deps) {
|
|
125
157
|
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
-
var datasource,
|
|
127
|
-
return __generator(this, function (
|
|
128
|
-
switch (
|
|
158
|
+
var datasource, usageInSegments, segmentKeys, _loop_2, _i, segmentKeys_1, segmentKey;
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
|
+
switch (_a.label) {
|
|
129
161
|
case 0:
|
|
130
|
-
datasource = deps.datasource
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
segments: new Set(),
|
|
134
|
-
};
|
|
135
|
-
return [4 /*yield*/, datasource.listFeatures()];
|
|
162
|
+
datasource = deps.datasource;
|
|
163
|
+
usageInSegments = {};
|
|
164
|
+
return [4 /*yield*/, datasource.listSegments()];
|
|
136
165
|
case 1:
|
|
137
|
-
|
|
138
|
-
_loop_2 = function (
|
|
139
|
-
var
|
|
140
|
-
return __generator(this, function (
|
|
141
|
-
switch (
|
|
142
|
-
case 0: return [4 /*yield*/, datasource.
|
|
166
|
+
segmentKeys = _a.sent();
|
|
167
|
+
_loop_2 = function (segmentKey) {
|
|
168
|
+
var segment;
|
|
169
|
+
return __generator(this, function (_b) {
|
|
170
|
+
switch (_b.label) {
|
|
171
|
+
case 0: return [4 /*yield*/, datasource.readSegment(segmentKey)];
|
|
143
172
|
case 1:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
feature.variations.forEach(function (variation) {
|
|
151
|
-
if (variation.variables) {
|
|
152
|
-
variation.variables.forEach(function (variable) {
|
|
153
|
-
if (variable.overrides) {
|
|
154
|
-
variable.overrides.forEach(function (override) {
|
|
155
|
-
if (override.conditions) {
|
|
156
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(override.conditions).forEach(function (attributeKey) { return attributeKeys.add(attributeKey); });
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
// force
|
|
165
|
-
if (feature.environments[environment].force) {
|
|
166
|
-
(_a = feature.environments[environment].force) === null || _a === void 0 ? void 0 : _a.forEach(function (force) {
|
|
167
|
-
if (force.conditions) {
|
|
168
|
-
(0, extractKeys_1.extractAttributeKeysFromConditions)(force.conditions).forEach(function (attributeKey) {
|
|
169
|
-
return attributeKeys.add(attributeKey);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
173
|
+
segment = _b.sent();
|
|
174
|
+
usageInSegments[segmentKey] = {
|
|
175
|
+
attributes: new Set(),
|
|
176
|
+
};
|
|
177
|
+
(0, extractKeys_1.extractAttributeKeysFromConditions)(segment.conditions).forEach(function (attributeKey) {
|
|
178
|
+
usageInSegments[segmentKey].attributes.add(attributeKey);
|
|
174
179
|
});
|
|
175
|
-
if (attributeKeys.has(attributeKey)) {
|
|
176
|
-
usedIn.features.add(featureKey);
|
|
177
|
-
}
|
|
178
180
|
return [2 /*return*/];
|
|
179
181
|
}
|
|
180
182
|
});
|
|
181
183
|
};
|
|
182
|
-
_i = 0,
|
|
183
|
-
|
|
184
|
+
_i = 0, segmentKeys_1 = segmentKeys;
|
|
185
|
+
_a.label = 2;
|
|
184
186
|
case 2:
|
|
185
|
-
if (!(_i <
|
|
186
|
-
|
|
187
|
-
return [5 /*yield**/, _loop_2(
|
|
187
|
+
if (!(_i < segmentKeys_1.length)) return [3 /*break*/, 5];
|
|
188
|
+
segmentKey = segmentKeys_1[_i];
|
|
189
|
+
return [5 /*yield**/, _loop_2(segmentKey)];
|
|
188
190
|
case 3:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
_a.sent();
|
|
192
|
+
_a.label = 4;
|
|
191
193
|
case 4:
|
|
192
194
|
_i++;
|
|
193
195
|
return [3 /*break*/, 2];
|
|
194
|
-
case 5: return [
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
196
|
+
case 5: return [2 /*return*/, usageInSegments];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.findAllUsageInSegments = findAllUsageInSegments;
|
|
202
|
+
function findSegmentUsage(deps, segmentKey) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
204
|
+
var usedInFeatures, usageInFeatures, featureKey;
|
|
205
|
+
return __generator(this, function (_a) {
|
|
206
|
+
switch (_a.label) {
|
|
207
|
+
case 0:
|
|
208
|
+
usedInFeatures = new Set();
|
|
209
|
+
return [4 /*yield*/, findAllUsageInFeatures(deps)];
|
|
210
|
+
case 1:
|
|
211
|
+
usageInFeatures = _a.sent();
|
|
212
|
+
for (featureKey in usageInFeatures) {
|
|
213
|
+
if (usageInFeatures[featureKey].segments.has(segmentKey)) {
|
|
214
|
+
usedInFeatures.add(featureKey);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return [2 /*return*/, usedInFeatures];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
exports.findSegmentUsage = findSegmentUsage;
|
|
223
|
+
function findAttributeUsage(deps, attributeKey) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
var usedIn, usageInFeatures, usageInSegments, featureKey, segmentKey;
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
usedIn = {
|
|
230
|
+
features: new Set(),
|
|
231
|
+
segments: new Set(),
|
|
214
232
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
233
|
+
return [4 /*yield*/, findAllUsageInFeatures(deps)];
|
|
234
|
+
case 1:
|
|
235
|
+
usageInFeatures = _a.sent();
|
|
236
|
+
return [4 /*yield*/, findAllUsageInSegments(deps)];
|
|
237
|
+
case 2:
|
|
238
|
+
usageInSegments = _a.sent();
|
|
239
|
+
for (featureKey in usageInFeatures) {
|
|
240
|
+
if (usageInFeatures[featureKey].attributes.has(attributeKey)) {
|
|
241
|
+
usedIn.features.add(featureKey);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
for (segmentKey in usageInSegments) {
|
|
245
|
+
if (usageInSegments[segmentKey].attributes.has(attributeKey)) {
|
|
246
|
+
usedIn.segments.add(segmentKey);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return [2 /*return*/, usedIn];
|
|
228
250
|
}
|
|
229
251
|
});
|
|
230
252
|
});
|
|
@@ -232,31 +254,30 @@ function findAttributeUsage(deps, attributeKey) {
|
|
|
232
254
|
exports.findAttributeUsage = findAttributeUsage;
|
|
233
255
|
function findUnusedSegments(deps) {
|
|
234
256
|
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
-
var datasource,
|
|
257
|
+
var datasource, unusedSegments, allSegmentKeys, usageInFeatures, usedSegmentKeys, featureKey;
|
|
236
258
|
return __generator(this, function (_a) {
|
|
237
259
|
switch (_a.label) {
|
|
238
260
|
case 0:
|
|
239
261
|
datasource = deps.datasource;
|
|
262
|
+
unusedSegments = new Set();
|
|
240
263
|
return [4 /*yield*/, datasource.listSegments()];
|
|
241
264
|
case 1:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
_i = 0, segmentKeys_2 = segmentKeys;
|
|
245
|
-
_a.label = 2;
|
|
265
|
+
allSegmentKeys = _a.sent();
|
|
266
|
+
return [4 /*yield*/, findAllUsageInFeatures(deps)];
|
|
246
267
|
case 2:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
unusedSegments.add(segmentKey);
|
|
268
|
+
usageInFeatures = _a.sent();
|
|
269
|
+
usedSegmentKeys = new Set();
|
|
270
|
+
for (featureKey in usageInFeatures) {
|
|
271
|
+
usageInFeatures[featureKey].segments.forEach(function (segmentKey) {
|
|
272
|
+
usedSegmentKeys.add(segmentKey);
|
|
273
|
+
});
|
|
254
274
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
275
|
+
allSegmentKeys.forEach(function (segmentKey) {
|
|
276
|
+
if (!usedSegmentKeys.has(segmentKey)) {
|
|
277
|
+
unusedSegments.add(segmentKey);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return [2 /*return*/, unusedSegments];
|
|
260
281
|
}
|
|
261
282
|
});
|
|
262
283
|
});
|
|
@@ -264,31 +285,38 @@ function findUnusedSegments(deps) {
|
|
|
264
285
|
exports.findUnusedSegments = findUnusedSegments;
|
|
265
286
|
function findUnusedAttributes(deps) {
|
|
266
287
|
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
-
var datasource,
|
|
288
|
+
var datasource, unusedAttributes, allAttributeKeys, usageInFeatures, usageInSegments, usedAttributeKeys, featureKey, segmentKey;
|
|
268
289
|
return __generator(this, function (_a) {
|
|
269
290
|
switch (_a.label) {
|
|
270
291
|
case 0:
|
|
271
292
|
datasource = deps.datasource;
|
|
293
|
+
unusedAttributes = new Set();
|
|
272
294
|
return [4 /*yield*/, datasource.listAttributes()];
|
|
273
295
|
case 1:
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
_i = 0, attributeKeys_1 = attributeKeys;
|
|
277
|
-
_a.label = 2;
|
|
296
|
+
allAttributeKeys = _a.sent();
|
|
297
|
+
return [4 /*yield*/, findAllUsageInFeatures(deps)];
|
|
278
298
|
case 2:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return [4 /*yield*/, findAttributeUsage(deps, attributeKey)];
|
|
299
|
+
usageInFeatures = _a.sent();
|
|
300
|
+
return [4 /*yield*/, findAllUsageInSegments(deps)];
|
|
282
301
|
case 3:
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
302
|
+
usageInSegments = _a.sent();
|
|
303
|
+
usedAttributeKeys = new Set();
|
|
304
|
+
for (featureKey in usageInFeatures) {
|
|
305
|
+
usageInFeatures[featureKey].attributes.forEach(function (attributeKey) {
|
|
306
|
+
usedAttributeKeys.add(attributeKey);
|
|
307
|
+
});
|
|
286
308
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
309
|
+
for (segmentKey in usageInSegments) {
|
|
310
|
+
usageInSegments[segmentKey].attributes.forEach(function (attributeKey) {
|
|
311
|
+
usedAttributeKeys.add(attributeKey);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
allAttributeKeys.forEach(function (attributeKey) {
|
|
315
|
+
if (!usedAttributeKeys.has(attributeKey)) {
|
|
316
|
+
unusedAttributes.add(attributeKey);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return [2 /*return*/, unusedAttributes];
|
|
292
320
|
}
|
|
293
321
|
});
|
|
294
322
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/find-usage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,oDAG8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/find-usage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,oDAG8B;AAU9B,SAAsB,sBAAsB,CAAC,IAAkB;;;;;;oBACrD,UAAU,GAAoB,IAAI,WAAxB,EAAE,aAAa,GAAK,IAAI,cAAT,CAAU;oBACrC,eAAe,GAAoB,EAAE,CAAC;oBAExB,qBAAM,UAAU,CAAC,YAAY,EAAE,EAAA;;oBAA7C,WAAW,GAAG,SAA+B;wCAExC,UAAU;;;;wCACH,qBAAM,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,EAAA;;oCAAlD,OAAO,GAAG,SAAwC;oCACxD,eAAe,CAAC,UAAU,CAAC,GAAG;wCAC5B,QAA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CAAC,UAAC,UAAU;4BACjC,OAAO,CAAC,GAAG,CAAC,cAAO,UAAU,CAAE,CAAC,CAAC;wBACnC,CAAC,CAAC,CAAC;qBACJ;oBAED,sBAAO;;yBAIL,OAAO,CAAC,cAAc,EAAtB,wBAAsB;oBACD,qBAAM,kBAAkB,CAAC,IAAI,CAAC,EAAA;;oBAA/C,cAAc,GAAG,SAA8B;oBAErD,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,EAAE;wBAC7B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;qBAC1C;yBAAM;wBACL,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;wBAElC,cAAc,CAAC,OAAO,CAAC,UAAC,UAAU;4BAChC,OAAO,CAAC,GAAG,CAAC,cAAO,UAAU,CAAE,CAAC,CAAC;wBACnC,CAAC,CAAC,CAAC;qBACJ;oBAED,sBAAO;;yBAIL,OAAO,CAAC,gBAAgB,EAAxB,wBAAwB;oBACD,qBAAM,oBAAoB,CAAC,IAAI,CAAC,EAAA;;oBAAnD,gBAAgB,GAAG,SAAgC;oBAEzD,IAAI,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAE;wBAC/B,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;qBAC5C;yBAAM;wBACL,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;wBAEpC,gBAAgB,CAAC,OAAO,CAAC,UAAC,YAAY;4BACpC,OAAO,CAAC,GAAG,CAAC,cAAO,YAAY,CAAE,CAAC,CAAC;wBACrC,CAAC,CAAC,CAAC;qBACJ;oBAED,sBAAO;;oBAGT,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;;;;;CACvD;AAtFD,gDAsFC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -26,4 +26,5 @@ __exportStar(require("./find-duplicate-segments"), exports);
|
|
|
26
26
|
__exportStar(require("./find-usage"), exports);
|
|
27
27
|
__exportStar(require("./dependencies"), exports);
|
|
28
28
|
__exportStar(require("./datasource"), exports);
|
|
29
|
+
__exportStar(require("./benchmark"), exports);
|
|
29
30
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB;AACvB,kDAAgC;AAChC,4CAA0B;AAC1B,4DAA0C;AAC1C,+CAA6B;AAC7B,iDAA+B;AAC/B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB;AACvB,kDAAgC;AAChC,4CAA0B;AAC1B,4DAA0C;AAC1C,+CAA6B;AAC7B,iDAA+B;AAC/B,+CAA6B;AAC7B,8CAA4B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@featurevisor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Core package of Featurevisor for Node.js usage",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"@types/js-yaml": "^4.0.5",
|
|
58
58
|
"@types/tar": "^6.1.4"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "22d022a6f9b05f3b70ffcd95cab1779bd74292f2"
|
|
61
61
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Context } from "@featurevisor/types";
|
|
2
|
+
import { FeaturevisorInstance, createInstance } from "@featurevisor/sdk";
|
|
3
|
+
|
|
4
|
+
import { SCHEMA_VERSION } from "../config";
|
|
5
|
+
import { buildDatafile } from "../builder";
|
|
6
|
+
import { Dependencies } from "../dependencies";
|
|
7
|
+
import { prettyDuration } from "../tester/prettyDuration";
|
|
8
|
+
|
|
9
|
+
export interface BenchmarkOutput {
|
|
10
|
+
value: any;
|
|
11
|
+
duration: number; // ms
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function benchmarkFeatureFlag(
|
|
15
|
+
f: FeaturevisorInstance,
|
|
16
|
+
featureKey: string,
|
|
17
|
+
context: Record<string, unknown>,
|
|
18
|
+
n: number,
|
|
19
|
+
): BenchmarkOutput {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
let value: any;
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < n; i++) {
|
|
24
|
+
value = f.isEnabled(featureKey, context as Context);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const duration = Date.now() - start;
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
value,
|
|
31
|
+
duration,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function benchmarkFeatureVariation(
|
|
36
|
+
f: FeaturevisorInstance,
|
|
37
|
+
featureKey: string,
|
|
38
|
+
context: Record<string, unknown>,
|
|
39
|
+
n: number,
|
|
40
|
+
): BenchmarkOutput {
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
let value: any;
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < n; i++) {
|
|
45
|
+
value = f.getVariation(featureKey, context as Context);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const duration = Date.now() - start;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
value,
|
|
52
|
+
duration,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function benchmarkFeatureVariable(
|
|
57
|
+
f: FeaturevisorInstance,
|
|
58
|
+
featureKey: string,
|
|
59
|
+
variableKey: string,
|
|
60
|
+
context: Record<string, unknown>,
|
|
61
|
+
n: number,
|
|
62
|
+
): BenchmarkOutput {
|
|
63
|
+
const start = Date.now();
|
|
64
|
+
let value: any;
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < n; i++) {
|
|
67
|
+
value = f.getVariable(featureKey, variableKey, context as Context);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const duration = Date.now() - start;
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
value,
|
|
74
|
+
duration,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface BenchmarkOptions {
|
|
79
|
+
environment: string;
|
|
80
|
+
feature: string;
|
|
81
|
+
n: number;
|
|
82
|
+
context: Record<string, unknown>;
|
|
83
|
+
variation?: boolean;
|
|
84
|
+
variable?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function benchmarkFeature(
|
|
88
|
+
deps: Dependencies,
|
|
89
|
+
options: BenchmarkOptions,
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
const { datasource, projectConfig } = deps;
|
|
92
|
+
|
|
93
|
+
console.log("");
|
|
94
|
+
console.log(`Running benchmark for feature "${options.feature}"...`);
|
|
95
|
+
|
|
96
|
+
console.log("");
|
|
97
|
+
|
|
98
|
+
console.log(`Building datafile containing all features for "${options.environment}"...`);
|
|
99
|
+
const datafileBuildStart = Date.now();
|
|
100
|
+
const existingState = await datasource.readState(options.environment);
|
|
101
|
+
const datafileContent = await buildDatafile(
|
|
102
|
+
projectConfig,
|
|
103
|
+
datasource,
|
|
104
|
+
{
|
|
105
|
+
schemaVersion: SCHEMA_VERSION,
|
|
106
|
+
revision: "include-all-features",
|
|
107
|
+
environment: options.environment,
|
|
108
|
+
},
|
|
109
|
+
existingState,
|
|
110
|
+
);
|
|
111
|
+
const datafileBuildDuration = Date.now() - datafileBuildStart;
|
|
112
|
+
console.log(`Datafile build duration: ${datafileBuildDuration}ms`);
|
|
113
|
+
|
|
114
|
+
console.log("");
|
|
115
|
+
|
|
116
|
+
const f = createInstance({
|
|
117
|
+
datafile: datafileContent,
|
|
118
|
+
});
|
|
119
|
+
console.log("...SDK initialized");
|
|
120
|
+
|
|
121
|
+
console.log("");
|
|
122
|
+
console.log(`Against context: ${JSON.stringify(options.context)}`);
|
|
123
|
+
|
|
124
|
+
let output: BenchmarkOutput;
|
|
125
|
+
if (options.variable) {
|
|
126
|
+
// variable
|
|
127
|
+
console.log(`Evaluating variable "${options.variable}" ${options.n} times...`);
|
|
128
|
+
output = benchmarkFeatureVariable(
|
|
129
|
+
f,
|
|
130
|
+
options.feature,
|
|
131
|
+
options.variable,
|
|
132
|
+
options.context,
|
|
133
|
+
options.n,
|
|
134
|
+
);
|
|
135
|
+
} else if (options.variation) {
|
|
136
|
+
// variation
|
|
137
|
+
console.log(`Evaluating variation ${options.n} times...`);
|
|
138
|
+
output = benchmarkFeatureVariation(f, options.feature, options.context, options.n);
|
|
139
|
+
} else {
|
|
140
|
+
// flag
|
|
141
|
+
console.log(`Evaluating flag ${options.n} times...`);
|
|
142
|
+
output = benchmarkFeatureFlag(f, options.feature, options.context, options.n);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
console.log("");
|
|
146
|
+
|
|
147
|
+
console.log(`Evaluated value : ${JSON.stringify(output.value)}`);
|
|
148
|
+
console.log(`Total duration : ${prettyDuration(output.duration)}`);
|
|
149
|
+
console.log(`Average duration: ${prettyDuration(output.duration / options.n)}`);
|
|
150
|
+
}
|