@featurevisor/core 2.5.0 → 2.6.7
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/CHANGELOG.md +59 -0
- package/LICENSE +1 -1
- package/coverage/clover.xml +444 -78
- package/coverage/coverage-final.json +9 -3
- package/coverage/lcov-report/index.html +42 -42
- package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
- package/coverage/lcov-report/lib/builder/buildScopedConditions.js.html +373 -0
- package/coverage/lcov-report/lib/builder/buildScopedDatafile.js.html +403 -0
- package/coverage/lcov-report/lib/builder/buildScopedSegments.js.html +379 -0
- package/coverage/lcov-report/lib/builder/index.html +53 -8
- 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/list/index.html +14 -14
- package/coverage/lcov-report/lib/list/matrix.js.html +23 -8
- package/coverage/lcov-report/lib/tester/helpers.js.html +1 -1
- package/coverage/lcov-report/lib/tester/index.html +1 -1
- package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
- package/coverage/lcov-report/src/builder/buildScopedConditions.ts.html +487 -0
- package/coverage/lcov-report/src/builder/buildScopedDatafile.ts.html +604 -0
- package/coverage/lcov-report/src/builder/buildScopedSegments.ts.html +544 -0
- package/coverage/lcov-report/src/builder/index.html +55 -10
- package/coverage/lcov-report/src/builder/revision.ts.html +1 -1
- package/coverage/lcov-report/src/builder/traffic.ts.html +3 -3
- package/coverage/lcov-report/src/list/index.html +14 -14
- package/coverage/lcov-report/src/list/matrix.ts.html +33 -12
- package/coverage/lcov-report/src/tester/helpers.ts.html +1 -1
- package/coverage/lcov-report/src/tester/index.html +1 -1
- package/coverage/lcov.info +810 -129
- package/jest.config.js +8 -0
- package/lib/builder/buildDatafile.d.ts +10 -0
- package/lib/builder/buildDatafile.js +27 -0
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/builder/buildProject.d.ts +2 -0
- package/lib/builder/buildProject.js +38 -4
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/buildScopedConditions.d.ts +5 -0
- package/lib/builder/buildScopedConditions.js +97 -0
- package/lib/builder/buildScopedConditions.js.map +1 -0
- package/lib/builder/buildScopedConditions.spec.d.ts +1 -0
- package/lib/builder/buildScopedConditions.spec.js +2167 -0
- package/lib/builder/buildScopedConditions.spec.js.map +1 -0
- package/lib/builder/buildScopedDatafile.d.ts +2 -0
- package/lib/builder/buildScopedDatafile.js +107 -0
- package/lib/builder/buildScopedDatafile.js.map +1 -0
- package/lib/builder/buildScopedDatafile.spec.d.ts +1 -0
- package/lib/builder/buildScopedDatafile.spec.js +1988 -0
- package/lib/builder/buildScopedDatafile.spec.js.map +1 -0
- package/lib/builder/buildScopedSegments.d.ts +5 -0
- package/lib/builder/buildScopedSegments.js +99 -0
- package/lib/builder/buildScopedSegments.js.map +1 -0
- package/lib/builder/buildScopedSegments.spec.d.ts +1 -0
- package/lib/builder/buildScopedSegments.spec.js +1062 -0
- package/lib/builder/buildScopedSegments.spec.js.map +1 -0
- package/lib/builder/index.d.ts +1 -0
- package/lib/builder/index.js +1 -0
- package/lib/builder/index.js.map +1 -1
- package/lib/config/projectConfig.d.ts +9 -1
- package/lib/config/projectConfig.js +1 -0
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/datasource/adapter.d.ts +3 -1
- package/lib/datasource/adapter.js.map +1 -1
- package/lib/datasource/filesystemAdapter.js +3 -1
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/linter/testSchema.d.ts +5 -0
- package/lib/linter/testSchema.js +8 -0
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/list/matrix.js +5 -0
- package/lib/list/matrix.js.map +1 -1
- package/lib/tester/testFeature.d.ts +5 -3
- package/lib/tester/testFeature.js +34 -9
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +3 -2
- package/lib/tester/testProject.js +40 -6
- package/lib/tester/testProject.js.map +1 -1
- package/package.json +5 -5
- package/src/builder/buildDatafile.ts +47 -0
- package/src/builder/buildProject.ts +58 -3
- package/src/builder/buildScopedConditions.spec.ts +2659 -0
- package/src/builder/buildScopedConditions.ts +134 -0
- package/src/builder/buildScopedDatafile.spec.ts +2236 -0
- package/src/builder/buildScopedDatafile.ts +173 -0
- package/src/builder/buildScopedSegments.spec.ts +1573 -0
- package/src/builder/buildScopedSegments.ts +153 -0
- package/src/builder/index.ts +1 -0
- package/src/config/projectConfig.ts +11 -1
- package/src/datasource/adapter.ts +4 -1
- package/src/datasource/filesystemAdapter.ts +4 -1
- package/src/linter/testSchema.ts +12 -0
- package/src/list/matrix.ts +7 -0
- package/src/tester/testFeature.ts +50 -16
- package/src/tester/testProject.ts +68 -8
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { DatafileContent, Context, Traffic } from "@featurevisor/types";
|
|
2
|
+
import { DatafileReader, createLogger } from "@featurevisor/sdk";
|
|
3
|
+
|
|
4
|
+
import { buildScopedConditions } from "./buildScopedConditions";
|
|
5
|
+
import { buildScopedSegments } from "./buildScopedSegments";
|
|
6
|
+
|
|
7
|
+
export function buildScopedDatafile(
|
|
8
|
+
originalDatafileContent: DatafileContent,
|
|
9
|
+
context: Context,
|
|
10
|
+
): DatafileContent {
|
|
11
|
+
const originalDatafileReader = new DatafileReader({
|
|
12
|
+
datafile: originalDatafileContent,
|
|
13
|
+
logger: createLogger({ level: "fatal" }),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const scopedDatafileContent: DatafileContent = JSON.parse(
|
|
17
|
+
JSON.stringify(originalDatafileContent),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const removeSegments: string[] = [];
|
|
21
|
+
|
|
22
|
+
// segments
|
|
23
|
+
for (const segmentKey in scopedDatafileContent.segments) {
|
|
24
|
+
const segment = scopedDatafileContent.segments[segmentKey];
|
|
25
|
+
const originalConditions = segment.conditions;
|
|
26
|
+
const scopedConditions = buildScopedConditions(
|
|
27
|
+
originalDatafileReader,
|
|
28
|
+
originalConditions,
|
|
29
|
+
context,
|
|
30
|
+
);
|
|
31
|
+
scopedDatafileContent.segments[segmentKey].conditions = scopedConditions;
|
|
32
|
+
|
|
33
|
+
if (scopedConditions === "*") {
|
|
34
|
+
removeSegments.push(segmentKey);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// features
|
|
39
|
+
for (const featureKey in scopedDatafileContent.features) {
|
|
40
|
+
const feature = scopedDatafileContent.features[featureKey];
|
|
41
|
+
|
|
42
|
+
// force
|
|
43
|
+
if (feature.force) {
|
|
44
|
+
for (let forceI = 0; forceI < feature.force.length; forceI++) {
|
|
45
|
+
const force = feature.force[forceI];
|
|
46
|
+
|
|
47
|
+
// segments
|
|
48
|
+
if (force.segments) {
|
|
49
|
+
feature.force[forceI].segments = buildScopedSegments(
|
|
50
|
+
originalDatafileReader,
|
|
51
|
+
force.segments,
|
|
52
|
+
context,
|
|
53
|
+
removeSegments,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// conditions
|
|
58
|
+
if (force.conditions) {
|
|
59
|
+
feature.force[forceI].conditions = buildScopedConditions(
|
|
60
|
+
originalDatafileReader,
|
|
61
|
+
force.conditions,
|
|
62
|
+
context,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// traffic
|
|
69
|
+
const originalTrafficSegments: (string | string[] | object | undefined)[] = [];
|
|
70
|
+
if (feature.traffic) {
|
|
71
|
+
for (let trafficI = 0; trafficI < feature.traffic.length; trafficI++) {
|
|
72
|
+
const traffic = feature.traffic[trafficI];
|
|
73
|
+
|
|
74
|
+
// Store original segments before scoping
|
|
75
|
+
originalTrafficSegments[trafficI] = traffic.segments;
|
|
76
|
+
|
|
77
|
+
// segments
|
|
78
|
+
if (traffic.segments) {
|
|
79
|
+
feature.traffic[trafficI].segments = buildScopedSegments(
|
|
80
|
+
originalDatafileReader,
|
|
81
|
+
traffic.segments,
|
|
82
|
+
context,
|
|
83
|
+
removeSegments,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// variation
|
|
90
|
+
if (feature.variations) {
|
|
91
|
+
const variations = feature.variations;
|
|
92
|
+
|
|
93
|
+
for (let variationI = 0; variationI < variations.length; variationI++) {
|
|
94
|
+
const variation = variations[variationI];
|
|
95
|
+
|
|
96
|
+
// variable overrides
|
|
97
|
+
if (variation.variableOverrides) {
|
|
98
|
+
for (const variableKey in variation.variableOverrides) {
|
|
99
|
+
const variableOverrides = variation.variableOverrides[variableKey];
|
|
100
|
+
|
|
101
|
+
for (
|
|
102
|
+
let variableOverrideI = 0;
|
|
103
|
+
variableOverrideI < variableOverrides.length;
|
|
104
|
+
variableOverrideI++
|
|
105
|
+
) {
|
|
106
|
+
const variableOverride = variableOverrides[variableOverrideI];
|
|
107
|
+
|
|
108
|
+
// segments
|
|
109
|
+
if (variableOverride.segments) {
|
|
110
|
+
variableOverride.segments = buildScopedSegments(
|
|
111
|
+
originalDatafileReader,
|
|
112
|
+
variableOverride.segments,
|
|
113
|
+
context,
|
|
114
|
+
removeSegments,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// conditions
|
|
119
|
+
if (variableOverride.conditions) {
|
|
120
|
+
variableOverride.conditions = buildScopedConditions(
|
|
121
|
+
originalDatafileReader,
|
|
122
|
+
variableOverride.conditions,
|
|
123
|
+
context,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
variableOverrides[variableOverrideI] = variableOverride;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
feature.variations[variationI] = variation;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// feature traffic consecutive segments with `*` removal
|
|
137
|
+
if (feature.traffic) {
|
|
138
|
+
const newTrafficArray: Traffic[] = [];
|
|
139
|
+
|
|
140
|
+
let lastAddedTraffic: Traffic | undefined;
|
|
141
|
+
|
|
142
|
+
for (let i = 0; i < feature.traffic.length; i++) {
|
|
143
|
+
let shouldAdd = true;
|
|
144
|
+
const currentTraffic = feature.traffic[i];
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
lastAddedTraffic &&
|
|
148
|
+
lastAddedTraffic.segments === "*" &&
|
|
149
|
+
currentTraffic.segments === "*"
|
|
150
|
+
) {
|
|
151
|
+
shouldAdd = false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (shouldAdd) {
|
|
155
|
+
newTrafficArray.push(currentTraffic);
|
|
156
|
+
|
|
157
|
+
lastAddedTraffic = currentTraffic;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
feature.traffic = newTrafficArray;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
scopedDatafileContent.features[featureKey] = feature;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// remove segments
|
|
168
|
+
for (const removeSegment of removeSegments) {
|
|
169
|
+
delete scopedDatafileContent.segments[removeSegment];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return scopedDatafileContent;
|
|
173
|
+
}
|